Skip to content

Commit

Permalink
Merge pull request #5835 from Trilbyspaceclone/more_anti_lag
Browse files Browse the repository at this point in the history
Simplified and fixed atmos for bugs [Exclusive for Superior Animal]
  • Loading branch information
Trilbyspaceclone authored Nov 19, 2024
2 parents ab4e1c9 + 3009dd5 commit cb27a7d
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 38 deletions.
89 changes: 89 additions & 0 deletions code/modules/mob/living/carbon/superior_animal/sa_breath.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
//SOJ's attempt to fix and optimize npcs atmos intractions
//First optimization is to stop having mobs eat air and less new gas mixtures
/mob/living/carbon/superior_animal/proc/sa_handle_breath()
var/datum/gas_mixture/environment = loc.return_air_for_internal_lifeform()
handle_breath(environment)
handle_environment(environment) //it should be pretty safe to move this out of ai inactive if this causes problems.
if(can_burrow && bad_environment)
evacuate()

// massively reduces code to a be bare minium
/mob/living/carbon/superior_animal/handle_breath(datum/gas_mixture/environment as anything)
var/damage = 0
if(breath_required_type)
if(environment.gas[breath_required_type] < min_breath_required_type)
damage = min_breath_required_type - environment.gas[breath_required_type]
adjustOxyLoss(damage)

if(breath_poison_type)
if(environment.gas[breath_poison_type] > min_breath_poison_type)
damage = environment.gas[breath_poison_type] * (min_breath_poison_type + 1)
adjustOxyLoss(damage)

if(damage)
bad_environment = TRUE
else
bad_environment = FALSE

return

/mob/living/carbon/superior_animal/handle_environment(datum/gas_mixture/environment as anything)
var/pressure = environment.return_pressure()
var/damage = 0
// message_admins("pressure = [pressure] temp = [environment.temperature]")

if(pressure < min_air_pressure)
damage = min_air_pressure - pressure
adjustBruteLoss(damage)
if(pressure > max_air_pressure)
damage = pressure - max_air_pressure
adjustBruteLoss(damage)

// message_admins("environment.temperature [environment.temperature] < [min_bodytemperature] min_bodytemperature")

if(environment.temperature < min_bodytemperature)
damage = min_bodytemperature - environment.temperature
// message_admins("i did cold run and delt [damage]")

if(cold_protection)
if(cold_protection >= 1)
damage = 0
var/cold_protected = damage * cold_protection
damage = damage - cold_protected

adjustFireLoss(damage)

// message_admins("environment.temperature [environment.temperature] > [max_bodytemperature] max_bodytemperature")


if(environment.temperature > max_bodytemperature)
damage = environment.temperature - max_bodytemperature
// message_admins("i did run hot and delt [damage]")
if(heat_protection)
if(heat_protection >= 1)
damage = 0
var/heat_protected = damage * heat_protection
damage = damage - heat_protected
adjustFireLoss(damage)

//Pasma in the air is bad
if(!contaminant_immunity)
if(environment.gas["plasma"] > 25)
damage = environment.gas["plasma"] * 0.1 //This can get to crazy high damage
adjustToxLoss(damage)


if(damage)
bad_environment = TRUE
else
bad_environment = FALSE

return








42 changes: 4 additions & 38 deletions code/modules/mob/living/carbon/superior_animal/superior_animal.dm
Original file line number Diff line number Diff line change
Expand Up @@ -176,36 +176,6 @@

return safepick(possible_locations) //return one at random

// Same as breath but with innecesarry code removed and damage tripled. Environment pressure damage moved here since we handle moles.

/mob/living/carbon/superior_animal/handle_breath(datum/gas_mixture/breath as anything)
var/breath_pressure = (breath.total_moles*R_IDEAL_GAS_EQUATION*breath.temperature)/BREATH_VOLUME
var/breath_required = breath_pressure > 15 && (breath_required_type || breath_poison_type)
if(!breath_required) // 15 KPA Minimum
return FALSE
adjustOxyLoss(breath.gas[breath_required_type] ? 0 : ((((breath.gas[breath_required_type] / breath.total_moles) * breath_pressure) < min_breath_required_type) ? 0 : 6))
adjustToxLoss(breath.gas[breath_poison_type] ? 0 : ((((breath.gas[breath_poison_type] / breath.total_moles) * breath_pressure) < min_breath_poison_type) ? 0 : 6))

/mob/living/carbon/superior_animal/handle_environment(datum/gas_mixture/environment as anything)
var/pressure = environment.return_pressure()
var/enviro_damage = (bodytemperature < min_bodytemperature) || (pressure < min_air_pressure) || (pressure > max_air_pressure)
if(enviro_damage) // its like this to avoid extra processing further below without using goto
bodytemperature += (bodytemperature - environment.temperature) * (environment.total_moles / MOLES_CELLSTANDARD) * (bodytemperature < min_bodytemperature ? 1 - heat_protection : -1 + cold_protection)
adjustFireLoss(bodytemperature < min_bodytemperature ? 0 : 15)
adjustBruteLoss((pressure < min_air_pressure || pressure > max_air_pressure) ? 0 : 6)
bad_environment = TRUE
return FALSE
bad_environment = FALSE
if (!contaminant_immunity)
for(var/g in environment.gas)
if(gas_data.flags[g] & XGM_GAS_CONTAMINANT && environment.gas[g] > gas_data.overlay_limit[g] + 1)
pl_effects()
break

if (overkill_dust && (getFireLoss() >= maxHealth*2))
dust()
return FALSE

// branchless isincapacited check made for roaches.
/mob/living/carbon/superior_animal/proc/cheap_incapacitation_check() // This works based off constants ,override it if you want it to be dynamic . Based off isincapacited
return stunned > 0 || weakened > 0 || resting || pinned.len > 0 || stat || paralysis || sleeping || (status_flags & FAKEDEATH) || buckled() > 0
Expand Down Expand Up @@ -585,14 +555,10 @@
if (!AI_inactive)
handle_status_effects()
update_lying_buckled_and_verb_status()
if(!never_stimulate_air)
var/datum/gas_mixture/environment = loc.return_air_for_internal_lifeform()
var/datum/gas_mixture/breath = environment.remove_volume(BREATH_VOLUME)
handle_breath(breath)
handle_environment(environment) //it should be pretty safe to move this out of ai inactive if this causes problems.
if (can_burrow && bad_environment)
evacuate()
//Fire handling , not passing the whole list because thats unefficient.
if(!never_stimulate_air && stat != DEAD)//Dead things dont breath
sa_handle_breath()
//Fire handling , not passing the whole list because thats unefficient.
if(on_fire)
handle_fire()
// this one in particular im very unhappy about. every 3 ticks, if a superior mob is dead to something that doesnt directly apply damage, it dies. i hate this.
handle_regular_status_updates() // we should probably still do this even if we're dead or something
Expand Down
1 change: 1 addition & 0 deletions sojourn-station.dme
Original file line number Diff line number Diff line change
Expand Up @@ -2341,6 +2341,7 @@
#include "code\modules\mob\living\carbon\superior_animal\attack.dm"
#include "code\modules\mob\living\carbon\superior_animal\defense.dm"
#include "code\modules\mob\living\carbon\superior_animal\life.dm"
#include "code\modules\mob\living\carbon\superior_animal\sa_breath.dm"
#include "code\modules\mob\living\carbon\superior_animal\superior_animal.dm"
#include "code\modules\mob\living\carbon\superior_animal\superior_defines.dm"
#include "code\modules\mob\living\carbon\superior_animal\ameridian\ameridian_behemoth.dm"
Expand Down

0 comments on commit cb27a7d

Please sign in to comment.