ID:156191
 
The following code identifies and defines rooms (groups of adjacent /turf/floor), and save those rooms as a datum/airgrid. Those air_grids are saved in a global list called, air_grids = list().

var/list/air_grids = list()     // This is where the air_grids are saved.
air_grid
var
list/contents = list() // The list of /turf/floor that are within this air_grid
air = 0 // Total amount of air in the room. It is the sum of each /turf/floor.air in its contents.
vacuum = 0 // Whenever the room is in contact with /turf/space, it creates a vacuum, thus losing all its air.
turf
floor
var
air = 0
air_grid/air_grid = null
New()
..()
Air_grid(src)
Del() // Explanation on this piece of code is found below this <dm> block.
var/air_grid/old_grid = air_grid
for(var/turf/floor/a in old_grid.contents)
if(a==src) continue
a.air += air
break
for(var/turf/floor/a in old_grid.contents)
a.air_grid = null
old_grid.contents -= src
spawn(1)
for(var/turf/floor/b in old_grid.contents)
Air_grid(b)
air_grids -= old_grid

air = 0
..()
proc
Air_grid(turf/floor/base) // This is the proc that creates/deletes air_grids. It it needs to be commented, please mention it in your reply.
if(!base.air_grid)
var/air_grid/new_base = new()
base.air_grid = new_base
base.air_grid.contents += base
air_grids += base.air_grid
for(var/turf/floor/surround in range(base,1))
if(surround==base) continue
if(surround.air_grid)
if(surround.air_grid==base.air_grid) continue
var/air_grid/new_grid = new()
for(var/a in surround.air_grid.contents)
if(!(a in new_grid.contents)) new_grid.contents += a
for(var/a in base.air_grid.contents)
if(!(a in new_grid.contents)) new_grid.contents += a
new_grid.air = base.air_grid.air+surround.air_grid.air
air_grids += new_grid
air_grids -= base.air_grid
air_grids -= surround.air_grid
for(var/turf/floor/a in new_grid.contents) a.air_grid = new_grid
else
surround.air_grid = base.air_grid
base.air_grid.contents += surround
base.air_grid.air += surround.air
if(!(base.air_grid in air_grids)) air_grids += base.air_grid
for(var/turf/space/found in range(base,1))
base.air_grid.vacuum = 1
break
Air(base.air_grid) // Distribute the room's air among all of the /turf/floor in its contents.
Air(air_grid/base)
base.air = 0
if(base.vacuum) // If it's a vacuum, then just prive the entire room of air.
for(var/turf/floor/found in base.contents)
found.air = 0
else // Distribute the air evenly!
for(var/turf/floor/found in base.contents) base.air += found.air
var/distributed = round(base.air/length(base.contents),0.1)
for(var/turf/floor/found in base.contents) found.air = distributed


1) The gibberish under turf/floor/Del() was coded that way because I did not find a better way of dividing an air grid into 2 air grids, in case a 'choke point' got deleted. Explanation follows:


2) How can I implement doors effectively? What I have at the moment is: create a /turf/floor when opened, and create a /turf/wall when closed. Is this really how this should work?

3) Also, with my current "air_grid splitting" code, every time I close/open the choke point the total amount of air in both rooms increase; as if turf/floor/New() or turf/floor/Del() "created" air whenever they are called.

4)..how can I improve the code, overall?

Thanks for reading!
Just once, I promise.


Any help? Any ideas?

Should I rewrite the whole thing? :P