Fixed and cleaned up ZAS. Added some better sanity to explosion locations.

ZAS procs are now more standardized, needs more comments though.
Connections between zones now self-manage themselves, adjusting things if/when the turfs they are on change zones. (The check for this is very efficient and fast, but a bit hard to read codewise)
Zone share percent set to 4.  Seems to work well.
This commit is contained in:
SkyMarshal
2012-06-04 14:56:28 -07:00
parent 81efb76970
commit bfa48835f9
22 changed files with 538 additions and 332 deletions
+110 -110
View File
@@ -1,117 +1,118 @@
#define QUANTIZE(variable) (round(variable,0.0001))
var/explosion_halt = 0
var/zone_share_percent = 1
zone
proc/process()
//Does rebuilding stuff. Not sure if used.
if(rebuild)
//Deletes zone if empty.
if(!contents.len)
del src
return 0
var/zone_share_percent = 4
zone/proc/process()
//Does rebuilding stuff. Not sure if used.
if(rebuild)
//Deletes zone if empty.
if(!contents.len)
del src
return 0
//Choose a random turf and regenerate the zone from it.
var
turf/sample = pick(contents)
list/new_contents = FloodFill(sample)
problem = 0
//Choose a random turf and regenerate the zone from it.
var
turf/sample = pick(contents)
list/new_contents = FloodFill(sample)
problem = 0
//If something isn't carried over, there was a complication.
for(var/turf/T in contents)
if(!(T in new_contents))
problem = 1
//If something isn't carried over, there was a complication.
for(var/turf/T in contents)
if(!(T in new_contents))
problem = 1
if(problem)
//Build some new zones for stuff that wasn't included.
var/list/rebuild_turfs = list()
for(var/turf/T in contents - new_contents)
contents -= T
rebuild_turfs += T
T.zone = null
for(var/turf/T in rebuild_turfs)
if(!T.zone)
var/zone/Z = new/zone(T)
Z.air.copy_from(air)
rebuild = 0
if(problem)
//Build some new zones for stuff that wasn't included.
var/list/rebuild_turfs = list()
for(var/turf/T in contents - new_contents)
contents -= T
rebuild_turfs += T
T.zone = null
for(var/turf/T in rebuild_turfs)
if(!T.zone)
var/zone/Z = new/zone(T)
Z.air.copy_from(air)
//Sometimes explosions will cause the air to be deleted for some reason.
if(!air)
air = new()
air.adjustGases(MOLES_O2STANDARD, 0, MOLES_N2STANDARD, 0, list())
world.log << "Air object lost in zone. Regenerating."
rebuild = 0
//Counting up space.
var/total_space = 0
//Sometimes explosions will cause the air to be deleted for some reason.
if(!air)
air = new()
air.adjust(MOLES_O2STANDARD, 0, MOLES_N2STANDARD, 0, list())
world.log << "Air object lost in zone. Regenerating."
if(space_tiles)
for(var/T in space_tiles)
if(!istype(T,/turf/space)) space_tiles -= T
total_space++
//Counting up space.
var/total_space = 0
//Add checks to ensure that we're not sucking air out of an empty room.
if(total_space && air.total_moles > 0.1 && air.temperature > TCMB+0.5)
//If there is space, air should flow out of the zone.
//if(abs(air.pressure) > vsc.airflow_lightest_pressure)
// AirflowSpace(src)
ShareSpace(air,total_space*(zone_share_percent/100))
if(space_tiles)
for(var/T in space_tiles)
if(!istype(T,/turf/space))
space_tiles -= T
continue
total_space++
//React the air here.
//air.react(null,0)
//Add checks to ensure that we're not sucking air out of an empty room.
if(total_space && air.total_moles > 0.1 && air.temperature > TCMB+0.5)
//If there is space, air should flow out of the zone.
//if(abs(air.pressure) > vsc.airflow_lightest_pressure)
// AirflowSpace(src)
ShareSpace(air,total_space*(zone_share_percent/100))
//Check the graphic.
//React the air here.
//air.react(null,0)
air.graphic = 0
if(air.toxins > MOLES_PLASMA_VISIBLE)
air.graphic = 1
else if(air.trace_gases.len)
var/datum/gas/sleeping_agent = locate(/datum/gas/sleeping_agent) in air.trace_gases
if(sleeping_agent && (sleeping_agent.moles > 1))
air.graphic = 2
else
air.graphic = 0
//Check the graphic.
//Only run through the individual turfs if there's reason to.
if(air.graphic != air.graphic_archived || air.temperature > FIRE_MINIMUM_TEMPERATURE_TO_EXIST)
air.graphic = 0
if(air.toxins > MOLES_PLASMA_VISIBLE)
air.graphic = 1
else if(air.trace_gases.len)
var/datum/gas/sleeping_agent = locate(/datum/gas/sleeping_agent) in air.trace_gases
if(sleeping_agent && (sleeping_agent.moles > 1))
air.graphic = 2
for(var/turf/simulated/S in contents)
//Update overlays.
if(air.graphic != air.graphic_archived)
if(S.HasDoor(1))
S.update_visuals()
else
S.update_visuals(air)
//Only run through the individual turfs if there's reason to.
if(air.graphic != air.graphic_archived || air.temperature > FIRE_MINIMUM_TEMPERATURE_TO_EXIST)
//Expose stuff to extreme heat.
if(air.temperature > FIRE_MINIMUM_TEMPERATURE_TO_EXIST)
for(var/atom/movable/item in S)
item.temperature_expose(air, air.temperature, CELL_VOLUME)
S.temperature_expose(air, air.temperature, CELL_VOLUME)
for(var/turf/simulated/S in contents)
//Update overlays.
if(air.graphic != air.graphic_archived)
if(S.HasDoor(1))
S.update_visuals()
else
S.update_visuals(air)
//Archive graphic so we can know if it's different.
air.graphic_archived = air.graphic
//Expose stuff to extreme heat.
if(air.temperature > FIRE_MINIMUM_TEMPERATURE_TO_EXIST)
for(var/atom/movable/item in S)
item.temperature_expose(air, air.temperature, CELL_VOLUME)
S.temperature_expose(air, air.temperature, CELL_VOLUME)
//Ensure temperature does not reach absolute zero.
air.temperature = max(TCMB,air.temperature)
//Archive graphic so we can know if it's different.
air.graphic_archived = air.graphic
//Handle connections to other zones.
if(length(connections))
for(var/connection/C in connections)
//Check if the connection is valid first.
C.Cleanup()
//Do merging if conditions are met. Specifically, if there's a non-door connection
//to somewhere with space, the zones are merged regardless of equilibrium, to speed
//up spacing in areas with double-plated windows.
if(C && !C.indirect && C.A.zone && C.B.zone)
if(C.A.zone.air.compare(C.B.zone.air) || total_space)
ZMerge(C.A.zone,C.B.zone)
//Ensure temperature does not reach absolute zero.
air.temperature = max(TCMB,air.temperature)
//Share some
for(var/zone/Z in connected_zones)
//Ensure we're not doing pointless calculations on equilibrium zones.
if(abs(air.total_moles - Z.air.total_moles) > 0.1 || abs(air.temperature - Z.air.temperature) > 0.1)
//if(abs(Z.air.pressure - air.pressure) > vsc.airflow_lightest_pressure)
// Airflow(src,Z)
ShareRatio(air,Z.air,connected_zones[Z]*(zone_share_percent/100))
//Handle connections to other zones.
if(length(connections))
for(var/connection/C in connections)
//Check if the connection is valid first.
if(!C.Cleanup())
continue
//Do merging if conditions are met. Specifically, if there's a non-door connection
//to somewhere with space, the zones are merged regardless of equilibrium, to speed
//up spacing in areas with double-plated windows.
if(C && !C.indirect && C.A.zone && C.B.zone)
if(C.A.zone.air.compare(C.B.zone.air) || total_space)
ZMerge(C.A.zone,C.B.zone)
//Share some
for(var/zone/Z in connected_zones)
//Ensure we're not doing pointless calculations on equilibrium zones.
if(abs(air.total_moles - Z.air.total_moles) > 0.1 || abs(air.temperature - Z.air.temperature) > 0.1)
//if(abs(Z.air.pressure - air.pressure) > vsc.airflow_lightest_pressure)
// Airflow(src,Z)
ShareRatio(air,Z.air,connected_zones[Z]*(zone_share_percent/100))
proc/ShareRatio(datum/gas_mixture/A, datum/gas_mixture/B, ratio)
//Shares a specific ratio of gas between mixtures using simple weighted averages.
@@ -215,19 +216,18 @@ proc/ShareSpace(datum/gas_mixture/A, ratio)
return 1
zone/proc
connected_zones()
//A legacy proc for getting connected zones.
. = list()
for(var/connection/C in connections)
var/zone/Z
if(C.A.zone == src)
Z = C.B.zone
else
Z = C.A.zone
zone/proc/connected_zones()
//A legacy proc for getting connected zones.
. = list()
for(var/connection/C in connections)
var/zone/Z
if(C.A.zone == src)
Z = C.B.zone
else
Z = C.A.zone
if(Z in .)
.[Z]++
else
. += Z
.[Z] = 1
if(Z in .)
.[Z]++
else
. += Z
.[Z] = 1