Lag War Day 4: Under Pressure, High Voltage (#21878)

Replace /datum/gas_mixture/proc/return_pressure with XGM_PRESSURE(xgm)
macro. Having such a relatively simple statement contributing proc
overhead to procs called millions of times is ridiculous

Rename /datum/gas_mixture/proc/zburn to react, deleting the old react
which was just an alias for it. Free proc overhead

Turn check_combustibility into a macro CHECK_COMBUSTIBLE(is_cmb, xgm).
also rewrite it slightly so that it only needs to do one pass. Its a bit
nasty so I apologize for that, but speeeeed.

Delete most powernet and obj/machinery/power procs for handling power,
replacing them with macros. The fact that we were unironically calling a
draw_power() on APCs to call draw_power() on their terminals to call
draw_power() on their powernet every single process tick was insane.

Turn `between` into a macro alias for clamp() since the param order is
different

turn `Percent` into a macro AS_PCT

Rewrite significant chunks of update_canmove so its not quite as
horrifying of a proc and hopefully doesn't eat the entire mob subsystem
every movement now
This commit is contained in:
Wildkins
2026-02-27 00:35:41 +00:00
committed by GitHub
parent 52e1a34575
commit e1770df81e
131 changed files with 676 additions and 736 deletions
+4 -3
View File
@@ -27,14 +27,15 @@
min_broken_damage = 10
/obj/item/organ/internal/Destroy()
if(owner)
if(owner && owner.internal_organs)
owner.internal_organs.Remove(src)
owner.internal_organs_by_name[organ_tag] = null
owner.internal_organs_by_name -= organ_tag
while(null in owner.internal_organs)
owner.internal_organs -= null
var/obj/item/organ/external/E = owner.organs_by_name[parent_organ]
if(istype(E)) E.internal_organs -= src
if(parent_organ in owner.organs_by_name)
var/obj/item/organ/external/E = astype(owner.organs_by_name[parent_organ])
E?.internal_organs -= src
return ..()
/// Sets the internal organ as belonging to the targeted external organ, and matches the target's species/robotness. Also updates all organ lists belonging to the owner.
+1 -1
View File
@@ -247,7 +247,7 @@
var/list/do_spray = list()
for(var/obj/item/organ/external/temp in owner.bad_external_organs)
if((temp.status & ORGAN_BLEEDING) && !BP_IS_ROBOTIC(temp))
for(var/datum/wound/W in temp.wounds)
for(var/datum/wound/W as anything in temp.wounds)
if(W.bleeding())
open_wound = TRUE
if(temp.applied_pressure)
@@ -147,7 +147,7 @@
temperature_change *= 0.5
// Check if there is somehow no air, or if we are in an ambient without enough air to properly cool us.
if((!ambient || (ambient && owner.calculate_affecting_pressure(ambient.return_pressure()) < owner.species.warning_low_pressure)))
if((!ambient || (ambient && owner.calculate_affecting_pressure(XGM_PRESSURE(ambient)) < owner.species.warning_low_pressure)))
if(!spaceproof)
temperature_change *= 0
else
+47 -50
View File
@@ -248,9 +248,8 @@
cached_markings = null
mob_icon = null
for(var/datum/wound/wound in wounds)
qdel(wound)
if(wounds)
QDEL_NULL_LIST(wounds)
QDEL_LIST(children)
QDEL_LIST(internal_organs)
QDEL_LIST(implants)
@@ -605,7 +604,7 @@
return
//Heal damage on the individual wounds
for(var/datum/wound/W in wounds)
for(var/datum/wound/W as anything in wounds)
if(brute == 0 && burn == 0)
break
@@ -695,7 +694,7 @@ This function completely restores a damaged organ to perfect condition.
if((type == INJURY_TYPE_CUT || type == INJURY_TYPE_BRUISE) && damage >= 5)
//we need to make sure that the wound we are going to worsen is compatible with the type of damage...
var/list/compatible_wounds = list()
for (var/datum/wound/W in wounds)
for (var/datum/wound/W as anything in wounds)
if (W.can_worsen(type, damage))
compatible_wounds += W
@@ -730,14 +729,17 @@ This function completely restores a damaged organ to perfect condition.
for(var/datum/wound/other in wounds)
if(other.can_merge(W))
other.merge_wound(W)
W = null // to signify that the wound was added
W = other
break
LAZYADD(wounds, W)
if(bandage_level)
owner.visible_message(SPAN_WARNING("The bandages on [owner.name]'s [name] gets [is_burn_type_damage ? "burnt" : "ripped"] off!"), SPAN_WARNING("The bandages on your [name] gets [is_burn_type_damage ? "burnt" : "ripped"] off!"))
bandage_level = BANDAGE_LEVEL_NONE
owner.update_bandages()
if(!QDELETED(W))
if(!LAZYISIN(wounds, W))
LAZYADD(wounds, W)
if(bandage_level)
owner.visible_message(SPAN_WARNING("The bandages on [owner.name]'s [name] gets [is_burn_type_damage ? "burnt" : "ripped"] off!"), SPAN_WARNING("The bandages on your [name] gets [is_burn_type_damage ? "burnt" : "ripped"] off!"))
bandage_level = BANDAGE_LEVEL_NONE
owner.update_bandages()
return W
/****************************************************
@@ -888,24 +890,21 @@ Note that amputating the affected organ does in fact remove the infection from t
var/antibiotics = 0
if(CE_ANTIBIOTIC in owner.chem_effects)
antibiotics = owner.chem_effects[CE_ANTIBIOTIC]
for(var/datum/wound/W in wounds)
var/increased_own_germs = FALSE
for(var/datum/wound/W as anything in wounds)
//Open wounds can become infected
if (owner.germ_level > W.germ_level && W.infection_check())
W.germ_level++
if(antibiotics < 5)
for(var/datum/wound/W in wounds)
//Infected wounds raise the organ's germ level
if (W.germ_level > germ_level && W.infection_check())
if(!increased_own_germs && antibiotics < 5 && W.germ_level > germ_level)
germ_level++
break //limit increase to a maximum of one per second
increased_own_germs = TRUE // limit increase to 1/tick
/obj/item/organ/external/proc/get_infect_target(var/list/infect_candidates = list())
var/obj/item/organ/temp_target
shuffle(infect_candidates) //Slightly randomizes since if all germ levels are zero, it'll always be the first pick of the list
//figure out which organs we can spread germs to
for (var/obj/item/organ/I in infect_candidates)
for (var/obj/item/organ/I as anything in infect_candidates)
if(I.germ_level < min(germ_level, INFECTION_LEVEL_TWO)) //Only choose organs that have less germs than us AND are below level two
//The below will always be the organ with the highest germ level. It picks a temp_target first then cycles through to find which, if any, has more germs.
if(!temp_target || I.germ_level > temp_target.germ_level)
@@ -977,11 +976,12 @@ Note that amputating the affected organ does in fact remove the infection from t
//Updating wounds. Handles wound natural I had some free spachealing, internal bleedings and infections
/obj/item/organ/external/proc/update_wounds()
if(status & (ORGAN_ROBOT|ORGAN_ADV_ROBOT|ORGAN_PLANT))
return //Robotic limbs don't heal or get worse. Diona limbs heal using their own mechanic
if((status & ORGAN_ROBOT) || (status & ORGAN_ADV_ROBOT) || (status & ORGAN_PLANT)) //Robotic limbs don't heal or get worse. Diona limbs heal using their own mechanic
return
var/updatehud
for(var/datum/wound/W in wounds)
var/num_total_wounds = LAZYLEN(wounds)
for(var/datum/wound/W as anything in wounds)
// wounds can disappear after 10 minutes at the earliest
if(W.damage <= 0 && W.created + (10 MINUTES) <= world.time)
qdel(W)
@@ -995,22 +995,20 @@ Note that amputating the affected organ does in fact remove the infection from t
var/heal_amt = 0
// if damage >= 50 AFTER treatment then it's probably too severe to heal within the timeframe of a round.
if (W.can_autoheal() && W.wound_damage() && brute_ratio < 50 && burn_ratio < 50)
if (updatehud && brute_ratio < 50 && burn_ratio < 50 && W.can_autoheal())
heal_amt += 0.5
//we only update wounds once in [wound_update_accuracy] ticks so have to emulate realtime
heal_amt = heal_amt * wound_update_accuracy
heal_amt *= wound_update_accuracy
//configurable regen speed woo, no-regen hardcore or instaheal hugbox, choose your destiny
heal_amt = heal_amt * GLOB.config.organ_regeneration_multiplier
heal_amt *= GLOB.config.organ_regeneration_multiplier
// amount of healing is spread over all the wounds
heal_amt = heal_amt / (LAZYLEN(wounds) + 1)
heal_amt /= ((number_wounds / num_total_wounds) + 1)
// making it look prettier on scanners
heal_amt = round(heal_amt,0.1)
var/dam_type = DAMAGE_BRUTE
if (W.damage_type == INJURY_TYPE_BURN)
dam_type = DAMAGE_BURN
heal_amt = round(heal_amt, 0.1)
var/dam_type = W.damage_type == INJURY_TYPE_BURN ? DAMAGE_BURN : DAMAGE_BRUTE
if(owner.can_autoheal(dam_type) && (heal_amt > 0))
if((heal_amt > 0) && owner.can_autoheal(dam_type))
W.heal_damage(heal_amt)
// Salving also helps against infection
@@ -1037,12 +1035,11 @@ Note that amputating the affected organ does in fact remove the infection from t
status &= ~ORGAN_BLEEDING
var/clamped = 0
var/mob/living/carbon/human/H
if(istype(owner,/mob/living/carbon/human))
H = owner
var/mob/living/carbon/human/H = astype(owner)
var/can_bleed = !BP_IS_ROBOTIC(src) && (H && !(H.species.flags & NO_BLOOD))
//update damage counts
for(var/datum/wound/W in wounds)
for(var/datum/wound/W as anything in wounds)
if(W.damage <= 0)
qdel(W)
@@ -1055,7 +1052,7 @@ Note that amputating the affected organ does in fact remove the infection from t
if(W.damage_type == INJURY_TYPE_CUT)
cut_dam += W.damage
if(!(status & ORGAN_ROBOT) && W.bleeding() && (H && !(H.species.flags & NO_BLOOD)))
if(can_bleed && W.bleeding())
W.handle_bleeding(H, src)
clamped |= W.clamped
@@ -1063,18 +1060,18 @@ Note that amputating the affected organ does in fact remove the infection from t
number_wounds += W.amount
//things tend to bleed if they are CUT OPEN
if (open && !clamped && (H && !(H.species.flags & NO_BLOOD) && !(status & ORGAN_ROBOT)))
if (open && !clamped && can_bleed)
status |= ORGAN_BLEEDING
if (istype(tendon))
if (tendon)
tendon.update_damage(cut_dam - min_broken_damage)
update_damage_ratios()
/obj/item/organ/external/proc/update_damage_ratios()
var/limb_loss_threshold = max_damage * 2
brute_ratio = Percent(brute_dam, limb_loss_threshold)
burn_ratio = Percent(burn_dam, limb_loss_threshold)
brute_ratio = AS_PCT(brute_dam, limb_loss_threshold)
burn_ratio = AS_PCT(burn_dam, limb_loss_threshold)
// new damage icon system
// returns just the brute/burn damage code
@@ -1231,21 +1228,21 @@ Note that amputating the affected organ does in fact remove the infection from t
// checks if all wounds on the organ are bandaged
/obj/item/organ/external/proc/is_bandaged()
for(var/datum/wound/W in wounds)
for(var/datum/wound/W as anything in wounds)
if(!W.bandaged)
return 0
return 1
// checks if all wounds on the organ are salved
/obj/item/organ/external/proc/is_salved()
for(var/datum/wound/W in wounds)
for(var/datum/wound/W as anything in wounds)
if(!W.salved)
return 0
return 1
// checks if all wounds on the organ are disinfected
/obj/item/organ/external/proc/is_disinfected()
for(var/datum/wound/W in wounds)
for(var/datum/wound/W as anything in wounds)
if(!W.disinfected)
return 0
return 1
@@ -1253,21 +1250,21 @@ Note that amputating the affected organ does in fact remove the infection from t
/obj/item/organ/external/proc/bandage()
var/rval = 0
status &= ~ORGAN_BLEEDING
for(var/datum/wound/W in wounds)
for(var/datum/wound/W as anything in wounds)
rval |= !W.bandaged
W.bandage()
return rval
/obj/item/organ/external/proc/salve()
var/rval = 0
for(var/datum/wound/W in wounds)
for(var/datum/wound/W as anything in wounds)
rval |= !W.salved
W.salve()
return rval
/obj/item/organ/external/proc/disinfect()
var/rval = 0
for(var/datum/wound/W in wounds)
for(var/datum/wound/W as anything in wounds)
rval |= !W.disinfected
W.disinfect()
W.germ_level = 0
@@ -1276,7 +1273,7 @@ Note that amputating the affected organ does in fact remove the infection from t
/obj/item/organ/external/proc/clamp_organ()
var/rval = 0
src.status &= ~ORGAN_BLEEDING
for(var/datum/wound/W in wounds)
for(var/datum/wound/W as anything in wounds)
rval |= !W.clamped
W.clamped = 1
return rval
@@ -1396,7 +1393,7 @@ Note that amputating the affected organ does in fact remove the infection from t
return max(brute_dam + burn_dam - perma_injury, perma_injury) //could use max_damage?
/obj/item/organ/external/proc/has_infected_wound()
for(var/datum/wound/W in wounds)
for(var/datum/wound/W as anything in wounds)
if(W.germ_level > INFECTION_LEVEL_ONE)
return 1
return 0
@@ -1443,7 +1440,7 @@ Note that amputating the affected organ does in fact remove the infection from t
SPAN_DANGER("\The [W] sticks in your wound!"))
if(supplied_wound)
for(var/datum/wound/wound in wounds)
for(var/datum/wound/wound as anything in wounds)
if ((wound.damage_type == INJURY_TYPE_CUT || wound.damage_type == INJURY_TYPE_PIERCE) && wound.damage >= W.w_class * 5)
supplied_wound = wound
break
@@ -1570,7 +1567,7 @@ Note that amputating the affected organ does in fact remove the infection from t
wound_descriptors["an open incision"] = 1
else if (open)
wound_descriptors["an incision"] = 1
for(var/datum/wound/W in wounds)
for(var/datum/wound/W as anything in wounds)
var/this_wound_desc = W.desc
if(W.damage_type == DAMAGE_BURN && W.salved)
this_wound_desc = "salved [this_wound_desc]"
+5 -5
View File
@@ -375,7 +375,7 @@
if ((istype(attacking_item, /obj/item/analyzer)) && get_dist(user, src) <= 1)
user.visible_message(SPAN_WARNING("[user] has used [attacking_item] on [icon2html(icon, viewers(get_turf(user)))] [src]."))
var/pressure = air_contents.return_pressure()
var/pressure = XGM_PRESSURE(air_contents)
manipulated_by = user.real_name //This person is aware of the contents of the tank.
var/total_moles = air_contents.total_moles
@@ -409,7 +409,7 @@
// this is the data which will be sent to the ui
var/data[0]
data["tankPressure"] = round(air_contents.return_pressure() ? air_contents.return_pressure() : 0)
data["tankPressure"] = round(SAFE_XGM_PRESSURE(air_contents))
data["releasePressure"] = round(distribute_pressure ? distribute_pressure : 0)
data["defaultReleasePressure"] = round(TANK_DEFAULT_RELEASE_PRESSURE)
data["maxReleasePressure"] = round(TANK_MAX_RELEASE_PRESSURE)
@@ -513,7 +513,7 @@
if(!air_contents)
return null
var/tank_pressure = air_contents.return_pressure()
var/tank_pressure = XGM_PRESSURE(air_contents)
if((tank_pressure < distribute_pressure) && prob(5))
to_chat(owner, SPAN_WARNING("There is a buzzing in your [parent_organ]."))
@@ -534,7 +534,7 @@
if(!air_contents)
return 0
var/pressure = air_contents.return_pressure()
var/pressure = XGM_PRESSURE(air_contents)
if(pressure > TANK_FRAGMENT_PRESSURE)
if(!istype(src.loc,/obj/item/transfer_valve))
message_admins("Explosive tank rupture! last key to touch the tank was [src.fingerprintslast].")
@@ -545,7 +545,7 @@
air_contents.react()
air_contents.react()
pressure = air_contents.return_pressure()
pressure = XGM_PRESSURE(air_contents)
var/range = (pressure-TANK_FRAGMENT_PRESSURE)/TANK_FRAGMENT_SCALE
explosion(
+9 -11
View File
@@ -104,16 +104,14 @@
if(LAZYLEN(embedded_objects))
return FALSE
return (wound_damage() <= autoheal_cutoff) ? TRUE : is_treated()
return ((src.damage / src.amount) <= autoheal_cutoff) ? TRUE : is_treated()
/// Checks whether the wound has been appropriately treated
/datum/wound/proc/is_treated()
if(!LAZYLEN(embedded_objects))
switch(damage_type)
if(INJURY_TYPE_BRUISE, INJURY_TYPE_CUT, INJURY_TYPE_PIERCE)
return bandaged
if(INJURY_TYPE_BURN)
return salved
if(LAZYLEN(embedded_objects))
return FALSE
return damage_type == INJURY_TYPE_BURN ? salved : bandaged
/// Checks whether other other can be merged into src.
/datum/wound/proc/can_merge(datum/wound/other)
@@ -144,7 +142,7 @@
/datum/wound/proc/infection_check()
if (damage < 10) //small cuts, tiny bruises, and moderate burns shouldn't be infectable.
return FALSE
if (is_treated() && damage < 25) //anything less than a flesh wound (or equivalent) isn't infectable if treated properly
if (damage < 25 && is_treated()) //anything less than a flesh wound (or equivalent) isn't infectable if treated properly
return FALSE
if (disinfected)
germ_level = 0 //reset this, just in case
@@ -186,7 +184,7 @@
amount -= healed_damage
src.damage -= healed_damage
while(src.wound_damage() < damage_list[current_stage] && current_stage < length(src.desc_list))
while((src.damage / src.amount) < damage_list[current_stage] && current_stage < length(src.desc_list))
current_stage++
desc = desc_list[current_stage]
src.min_damage = damage_list[current_stage]
@@ -226,14 +224,14 @@
return TRUE
/datum/wound/proc/bleeding()
for(var/obj/item/thing in embedded_objects)
for(var/obj/item/thing as anything in embedded_objects)
if(thing.w_class > WEIGHT_CLASS_SMALL)
return FALSE
if (bandaged||clamped)
return FALSE
return ((bleed_timer > 0 || wound_damage() > bleed_threshold) && current_stage <= max_bleeding_stage)
return ((bleed_timer > 0 || (src.damage / src.amount) > bleed_threshold) && current_stage <= max_bleeding_stage)
/// Called in organ_external.dm update_damages, this will update the limb's status to bleeding, and lowers the bleed_timer if applicable
/datum/wound/proc/handle_bleeding(var/mob/victim, var/obj/item/organ/external/limb)