Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New way of transferring air between zones. #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion code/ZAS/Definition.dm
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ zone
list/connected_zones //Parallels connections, but lists zones to which this one is connected and the number
//of points they're connected at.
list/space_tiles // Any space tiles in this list will cause air to flow out.
last_update = 0
last_update = 0
ShareRequired = 0
4 changes: 4 additions & 0 deletions code/ZAS/FEA_system.dm
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,10 @@ datum
if(. && Z && !output)
. = 0

for(var/zone/Z in zones)
if(Z.ShareRequired)
Z.GroupShare()

for(var/obj/fire/F in active_hotspots)
var/output = F.process()
if(. && F && !output)
Expand Down
77 changes: 76 additions & 1 deletion code/ZAS/Processing.dm
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#define QUANTIZE(variable) (round(variable,0.0001))


zone/proc/process()
. = 1

Expand Down Expand Up @@ -82,16 +84,89 @@ zone/proc/process()
if(C.A.zone.air.compare(C.B.zone.air) || total_space)
ZMerge(C.A.zone,C.B.zone)

//Share some
ShareRequired = 0
//Share test
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)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Здесь происходит отсеивание ненужных вычислений. Если тебе кажется, что до разницы в 0.1 моделировать нет смысла, то можешь это число поднять.
PS Это уравнение неплохо бы дополнить || abs(air.oxygen - Z.air.oxygen) > 0.1 || abs(air.nitrogen - Z.air.nitrogen) > 0.1 || abs(air.carbon_dioxide -Z.air.carbon_dioxide) > 0.1

if(abs(Z.air.return_pressure() - air.return_pressure()) > vsc.airflow_lightest_pressure)
Airflow(src,Z)
ShareRatio( air , Z.air , connected_zones[Z]*vsc.zone_share_percent/200 )
ShareRequired = 1
//Divided by 200 since each zone is processed. Each connection is considered twice
//Space tiles force it to try and move twice as much air.

zone/proc/GroupShare()
var/list/Cluster = new/list()
ShareRequired = 0
Cluster += src
Cluster = JoinCluster(Cluster)

var/oxy = 0
var/nitro = 0
var/co2 = 0
var/plasma = 0
var/size = 0
var/heat = 0
var/heatcapacity = 0
var/list/traceavg = new/list()

for (var/zone/Z in Cluster)
var/zsize = max(1,Z.air.group_multiplier)
oxy += Z.air.oxygen*zsize
nitro += Z.air.nitrogen*zsize
co2 += Z.air.carbon_dioxide*zsize
plasma += Z.air.toxins*zsize
heat += Z.air.temperature*Z.air.heat_capacity()*zsize
heatcapacity += Z.air.heat_capacity()*zsize
size += zsize
for (var/datum/gas/G in Z.air.trace_gases)
var/datum/gas/avgG = locate(G.type) in traceavg
if (avgG)
avgG.moles += G.moles*zsize
else
avgG = new G.type
avgG.moles += G.moles*zsize
traceavg += avgG

oxy /= size
nitro /= size
plasma /= size
co2 /= size
heat /= heatcapacity //now it is actually an average temperature.
for (var/datum/gas/G in traceavg)
G.moles /= size

//Each 40 tiles of Cluster size increase the convection process length by 100%
var/ratio=vsc.zone_share_percent/(100+size*2.5)

for (var/zone/Z in Cluster)
Z.air.oxygen = (Z.air.oxygen - oxy) * (1-ratio) + oxy
Z.air.nitrogen = (Z.air.nitrogen - nitro) * (1-ratio) + nitro
Z.air.carbon_dioxide = (Z.air.carbon_dioxide - co2) * (1-ratio) + co2
Z.air.toxins = (Z.air.toxins - plasma) * (1-ratio) + plasma
Z.air.temperature = (Z.air.temperature - heat) * (1-ratio) + heat
for (var/datum/gas/G in Z.air.trace_gases)
var/datum/gas/avgG = locate(G.type) in traceavg
if (avgG)
G.moles = (G.moles - avgG.moles)*(1-ratio) + avgG.moles

for (var/zone/Z in Cluster)
ShareRequired = 0
Z.air.update_values()



//Iteratively get all connected zones
zone/proc/JoinCluster(var/list/Cluster)
for(var/zone/Z in connected_zones)
if (!(Z in Cluster))
Cluster += Z
Cluster = Z.JoinCluster(Cluster)
return Cluster
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

В этой функции каждая из зон пробегает по своему списку соединенных и добавляет в кластер те, которых там еще нет. После чего для добавленных вызывает себя рекурсивно.




proc/ShareRatio(datum/gas_mixture/A, datum/gas_mixture/B, ratio)
//Shares a specific ratio of gas between mixtures using simple weighted averages.
var
Expand Down