Skip to content
This repository was archived by the owner on May 22, 2025. It is now read-only.
36 changes: 25 additions & 11 deletions code/modules/power/generator.dm
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
var/lastgen = 0
var/lastgenlev = -1

var/internal_heat_cap = 1000 //needs experimantal data
var/internal_temp = T0C

/obj/machinery/power/generator/Initialize(mapload)
. = ..()
find_circs()
Expand Down Expand Up @@ -45,6 +48,8 @@
add_overlay("teg-panel")
return

if(!powernet)
add_overlay("teg-nogrid")
if(stat & (NOPOWER))
return
else
Expand All @@ -60,27 +65,36 @@
return

if(powernet)
var/datum/gas_mixture/cold_air = cold_circ.return_transfer_air()
var/datum/gas_mixture/cold_air = cold_circ.return_transfer_air() //circulators give us air that is moving through
var/datum/gas_mixture/hot_air = hot_circ.return_transfer_air()

if(cold_air && hot_air)

var/cold_air_heat_capacity = cold_air.heat_capacity()
var/hot_air_heat_capacity = hot_air.heat_capacity()
var/cold_air_heat_cap = cold_air.heat_capacity() // not sure if this isnt pointless
var/hot_air_heat_cap = hot_air.heat_capacity()

var/cold_temp = cold_air.return_temperature()
var/hot_temp = hot_air.return_temperature()

var/delta_temperature = hot_air.return_temperature() - cold_air.return_temperature()
if((hot_temp - cold_temp) > 0 && cold_air_heat_cap > 0 && hot_air_heat_cap > 0)

//air moving trough equalises temperature with it subsection
var/cold_subsection_temp = (cold_air_heat_cap * cold_temp + internal_heat_cap * internal_temp) / (internal_heat_cap + cold_air_heat_cap)
var/hot_subsection_temp = (hot_air_heat_cap * hot_temp + internal_heat_cap * internal_temp) / (internal_heat_cap + hot_air_heat_cap)

hot_air.set_temperature(hot_subsection_temp) // cooled / heated air gets spit back out
cold_air.set_temperature(cold_subsection_temp)

if(delta_temperature > 0 && cold_air_heat_capacity > 0 && hot_air_heat_capacity > 0)
var/efficiency = 0.65

var/energy_transfer = delta_temperature*hot_air_heat_capacity*cold_air_heat_capacity/(hot_air_heat_capacity+cold_air_heat_capacity)
//how much energy do we have stored in temperature differetial
var/energy_transfer = (hot_subsection_temp - cold_subsection_temp)*internal_heat_cap

var/heat = energy_transfer*(1-efficiency)
//produce electricity
lastgen += energy_transfer*efficiency

hot_air.set_temperature(hot_air.return_temperature() - energy_transfer/hot_air_heat_capacity)
cold_air.set_temperature(cold_air.return_temperature() + heat/cold_air_heat_capacity)
//transfer rest of energy into waste heat/chill
internal_temp = cold_subsection_temp + energy_transfer * (1 - efficiency) / (internal_heat_cap * 2)

//add_avail(lastgen) This is done in process now
// update icon overlays only if displayed level has changed
Expand All @@ -93,7 +107,7 @@
var/datum/gas_mixture/cold_circ_air1 = cold_circ.airs[1]
cold_circ_air1.merge(cold_air)

update_icon()
update_icon()

src.updateDialog()

Expand Down Expand Up @@ -279,4 +293,4 @@
/obj/machinery/power/generator/obj_break(damage_flag)
kill_circs()
..()


Binary file modified icons/obj/machines/thermoelectric.dmi
Binary file not shown.