Skip to content
This repository was archived by the owner on May 22, 2025. It is now read-only.

Commit 44196c8

Browse files
committed
Update monstermos.cpp
1 parent 967775d commit 44196c8

File tree

1 file changed

+35
-28
lines changed

1 file changed

+35
-28
lines changed

byond-extools/src/monstermos/monstermos.cpp

Lines changed: 35 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ int gas_mixture_count = 0;
2626
float gas_moles_visible[TOTAL_NUM_GASES];
2727
std::vector<Value> gas_overlays[TOTAL_NUM_GASES];
2828

29-
std::shared_ptr<GasMixture> &get_gas_mixture(Value val)
29+
std::shared_ptr<GasMixture>& get_gas_mixture(Value val)
3030
{
3131
uint32_t v = val.get_by_id(str_id_extools_pointer).value;
3232
if (v == 0) Runtime("Gas mixture has null extools pointer");
@@ -37,7 +37,7 @@ int str_id_volume;
3737
trvh gasmixture_register(unsigned int args_len, Value* args, Value src)
3838
{
3939
//gas_mixtures[src.value] = std::make_shared<GasMixture>(src.get_by_id(str_id_volume).valuef);
40-
std::shared_ptr<GasMixture> *ptr = new std::shared_ptr<GasMixture>;
40+
std::shared_ptr<GasMixture>* ptr = new std::shared_ptr<GasMixture>;
4141
*ptr = std::make_shared<GasMixture>(src.get_by_id(str_id_volume).valuef);
4242
SetVariable(src.type, src.value, str_id_extools_pointer, Value(NUMBER, (int)ptr));
4343
gas_mixture_count++;
@@ -48,7 +48,7 @@ trvh gasmixture_unregister(unsigned int args_len, Value* args, Value src)
4848
{
4949
uint32_t v = src.get_by_id(str_id_extools_pointer).value;
5050
if (v != 0) {
51-
std::shared_ptr<GasMixture> *gm = (std::shared_ptr<GasMixture> *)v;
51+
std::shared_ptr<GasMixture>* gm = (std::shared_ptr<GasMixture> *)v;
5252
delete gm;
5353
gas_mixture_count--;
5454
SetVariable(src.type, src.value, str_id_extools_pointer, Value::Null());
@@ -58,9 +58,9 @@ trvh gasmixture_unregister(unsigned int args_len, Value* args, Value src)
5858

5959
DelDatumPtr oDelDatum;
6060
void hDelDatum(unsigned int datum_id) {
61-
RawDatum *datum = Core::GetDatumPointerById(datum_id);
61+
RawDatum* datum = Core::GetDatumPointerById(datum_id);
6262
if (datum != nullptr) {
63-
std::shared_ptr<GasMixture> *gm = nullptr;
63+
std::shared_ptr<GasMixture>* gm = nullptr;
6464
if (datum->len_vars < 10) { // if it has a whole bunch of vars it's probably not a gas mixture. Please don't add a whole bunch of vars to gas mixtures.
6565
for (int i = 0; i < datum->len_vars; i++) {
6666
if (datum->vars[i].id == str_id_extools_pointer) {
@@ -168,7 +168,7 @@ trvh gasmixture_get_last_share(unsigned int args_len, Value* args, Value src)
168168
trvh gasmixture_get_gases(unsigned int args_len, Value* args, Value src)
169169
{
170170
List l(CreateList(0));
171-
GasMixture &gm = *get_gas_mixture(src);
171+
GasMixture& gm = *get_gas_mixture(src);
172172
for (int i = 0; i < TOTAL_NUM_GASES; i++) {
173173
if (gm.get_moles(i) >= GAS_MIN_MOLES) {
174174
l.append(gas_id_to_type[i]);
@@ -183,10 +183,12 @@ trvh gasmixture_set_temperature(unsigned int args_len, Value* args, Value src)
183183
if (std::isnan(vf) || std::isinf(vf)) {
184184
get_gas_mixture(src)->set_temperature(0);
185185
Runtime("Attempt to set temperature to NaN or Infinity");
186-
} else if(vf < 0) {
186+
}
187+
else if (vf < 0) {
187188
get_gas_mixture(src)->set_temperature(0);
188189
Runtime("Attempt to set temperature to negative number");
189-
} else {
190+
}
191+
else {
190192
get_gas_mixture(src)->set_temperature(vf);
191193
}
192194
return Value::Null();
@@ -215,10 +217,12 @@ trvh gasmixture_set_moles(unsigned int args_len, Value* args, Value src)
215217
if (std::isnan(vf) || std::isinf(vf)) {
216218
get_gas_mixture(src)->set_moles(index, 0);
217219
Runtime("Attempt to set moles to NaN or Infinity");
218-
} else if(vf < 0) {
220+
}
221+
else if (vf < 0) {
219222
get_gas_mixture(src)->set_moles(index, 0);
220223
Runtime("Attempt to set moles to negative number");
221-
} else {
224+
}
225+
else {
222226
get_gas_mixture(src)->set_moles(index, vf);
223227
}
224228
return Value::Null();
@@ -228,8 +232,8 @@ trvh gasmixture_scrub_into(unsigned int args_len, Value* args, Value src)
228232
{
229233
if (args_len < 2)
230234
return Value::Null();
231-
GasMixture &src_gas = *get_gas_mixture(src);
232-
GasMixture &dest_gas = *get_gas_mixture(args[0]);
235+
GasMixture& src_gas = *get_gas_mixture(src);
236+
GasMixture& dest_gas = *get_gas_mixture(args[0]);
233237
Container gases_to_scrub = args[1];
234238
int num_gases = gases_to_scrub.length();
235239
GasMixture buffer(CELL_VOLUME);
@@ -268,7 +272,8 @@ trvh gasmixture_compare(unsigned int args_len, Value* args, Value src)
268272
}
269273
else if (result == -2) {
270274
return Value("");
271-
} else{
275+
}
276+
else {
272277
return gas_id_to_type[result];
273278
}
274279
}
@@ -282,7 +287,7 @@ trvh gasmixture_multiply(unsigned int args_len, Value* args, Value src)
282287
trvh turf_update_adjacent(unsigned int args_len, Value* args, Value src)
283288
{
284289
if (src.type != TURF) { return Value::Null(); }
285-
Tile *tile = all_turfs.get(src.value);
290+
Tile* tile = all_turfs.get(src.value);
286291
if (tile != nullptr) {
287292
tile->update_adjacent(all_turfs);
288293
}
@@ -292,7 +297,7 @@ trvh turf_update_adjacent(unsigned int args_len, Value* args, Value src)
292297
trvh turf_update_air_ref(unsigned int args_len, Value* args, Value src)
293298
{
294299
if (src.type != TURF) { return Value::Null(); }
295-
Tile *tile = all_turfs.get(src.value);
300+
Tile* tile = all_turfs.get(src.value);
296301
if (tile != nullptr) {
297302
tile->update_air_ref();
298303
}
@@ -302,7 +307,7 @@ trvh turf_update_air_ref(unsigned int args_len, Value* args, Value src)
302307
trvh turf_eg_reset_cooldowns(unsigned int args_len, Value* args, Value src)
303308
{
304309
if (src.type != TURF) { return Value::Null(); }
305-
Tile *tile = all_turfs.get(src.value);
310+
Tile* tile = all_turfs.get(src.value);
306311
if (tile != nullptr) {
307312
if (tile->excited_group) {
308313
tile->excited_group->reset_cooldowns();
@@ -314,7 +319,7 @@ trvh turf_eg_reset_cooldowns(unsigned int args_len, Value* args, Value src)
314319
trvh turf_eg_garbage_collect(unsigned int args_len, Value* args, Value src)
315320
{
316321
if (src.type != TURF) { return Value::Null(); }
317-
Tile *tile = all_turfs.get(src.value);
322+
Tile* tile = all_turfs.get(src.value);
318323
if (tile != nullptr) {
319324
if (tile->excited_group) {
320325
// store to local variable to prevent it from being destructed while we're still using it because that causes segfaults.
@@ -328,7 +333,7 @@ trvh turf_eg_garbage_collect(unsigned int args_len, Value* args, Value src)
328333
trvh turf_get_excited(unsigned int args_len, Value* args, Value src)
329334
{
330335
if (src.type != TURF) { return Value::Null(); }
331-
Tile *tile = all_turfs.get(src.value);
336+
Tile* tile = all_turfs.get(src.value);
332337
if (tile != nullptr) {
333338
return Value(tile->excited ? 1.0 : 0.0);
334339
}
@@ -337,7 +342,7 @@ trvh turf_get_excited(unsigned int args_len, Value* args, Value src)
337342
trvh turf_set_excited(unsigned int args_len, Value* args, Value src)
338343
{
339344
if (src.type != TURF) { return Value::Null(); }
340-
Tile *tile = all_turfs.get(src.value);
345+
Tile* tile = all_turfs.get(src.value);
341346
if (tile != nullptr) {
342347
tile->excited = args_len > 0 ? (bool)args[0] : false;
343348
}
@@ -347,7 +352,7 @@ trvh turf_set_excited(unsigned int args_len, Value* args, Value src)
347352
trvh turf_process_cell(unsigned int args_len, Value* args, Value src)
348353
{
349354
if (src.type != TURF || args_len < 1) { return Value::Null(); }
350-
Tile *tile = all_turfs.get(src.value);
355+
Tile* tile = all_turfs.get(src.value);
351356
if (tile != nullptr) {
352357
tile->process_cell(args[0]);
353358
}
@@ -356,7 +361,7 @@ trvh turf_process_cell(unsigned int args_len, Value* args, Value src)
356361

357362
trvh turf_eq(unsigned int args_len, Value* args, Value src) {
358363
if (src.type != TURF || args_len < 1) { return Value::Null(); }
359-
Tile *tile = all_turfs.get(src.value);
364+
Tile* tile = all_turfs.get(src.value);
360365
if (tile != nullptr) {
361366
tile->equalize_pressure_in_zone(args[0]);
362367
}
@@ -377,7 +382,7 @@ trvh turf_update_visuals(unsigned int args_len, Value* args, Value src) {
377382
if (gm.get_moles(i) > gas_moles_visible[i]) {
378383
// you know whats fun?
379384
// getting cucked by BYOND arrays starting at 1. How did this not segfault before? Beats me! I love undefined behavior! Bandaid: VV
380-
overlay_types.push_back(gas_overlays[i][std::fmin(FACTOR_GAS_VISIBLE_MAX, (int)std::ceil(gm.get_moles(i) / MOLES_GAS_VISIBLE_STEP))-1]);
385+
overlay_types.push_back(gas_overlays[i][std::fmin(FACTOR_GAS_VISIBLE_MAX, (int)std::ceil(gm.get_moles(i) / MOLES_GAS_VISIBLE_STEP)) - 1]);
381386
}
382387
}
383388

@@ -396,12 +401,12 @@ trvh turf_update_visuals(unsigned int args_len, Value* args, Value src) {
396401
}
397402
}
398403
}
399-
404+
400405
List l(CreateList(0));
401406
for (int i = 0; i < overlay_types.size(); i++) {
402407
l.append(overlay_types[i]);
403408
}
404-
src.invoke("set_visuals", { Value(l) } );
409+
src.invoke("set_visuals", { Value(l) });
405410
return Value::Null();
406411
}
407412

@@ -442,7 +447,9 @@ trvh refresh_atmos_grid(unsigned int args_len, Value* args, Value src)
442447
}
443448

444449
void initialize_gas_overlays() {
445-
Container meta_gas_info = Value(GetAssocElement(0x52, 0, STRING, Core::GetStringId("meta_gas_info")));
450+
Value GLOB = Value::Global().get("GLOB");
451+
if (!GLOB) return;
452+
Container meta_gas_info = GLOB.get("meta_gas_info");
446453
if (!meta_gas_info.type) return;
447454
for (int i = 0; i < TOTAL_NUM_GASES; ++i)
448455
{
@@ -497,11 +504,11 @@ const char* enable_monstermos()
497504
str_id_floor_rip = Core::GetStringId("handle decompression floor rip", true);
498505
str_id_extools_pointer = Core::GetStringId("_extools_pointer_gasmixture", true);
499506

500-
SSair = Value(GetAssocElement(0x52, 0, STRING, Core::GetStringId("SSair")));
507+
SSair = Value::Global().get("SSair");
501508
//Set up gas types map
502509
std::vector<Value> nullvector = { Value(0.0f) };
503510
Container gas_types_list = Core::get_proc("/proc/gas_types").call(nullvector);
504-
Container meta_gas_info = Value(GetAssocElement(0x52, 0, STRING, Core::GetStringId("meta_gas_info")));
511+
Container meta_gas_info = Value::Global().get("meta_gas_info");
505512
int gaslen = gas_types_list.length();
506513
if (gaslen != TOTAL_NUM_GASES) {
507514
return "TOTAL_NUM_GASES does not match the number of /datum/gas subtypes!!";
@@ -558,4 +565,4 @@ const char* enable_monstermos()
558565

559566
all_turfs.refresh();
560567
return "ok";
561-
}
568+
}

0 commit comments

Comments
 (0)