Skip to content

Commit

Permalink
Merge pull request #33719 from vgstation-coders/revert-33153-miners2
Browse files Browse the repository at this point in the history
Revert "Scale miner output with power"
  • Loading branch information
d3athrow authored Nov 20, 2022
2 parents 83587ac + 8177d08 commit 79b8dc3
Show file tree
Hide file tree
Showing 2 changed files with 117 additions and 90 deletions.
2 changes: 1 addition & 1 deletion code/ZAS/_gas_mixture.dm
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

//Since gases not present in the mix are culled from the list, we use this to make sure a number is returned for any valid gas.
/datum/gas_mixture/proc/operator[](idx)
return gas[idx] || (XGM?.gases[idx] ? 0 : null)
return gas[idx] || (XGM.gases[idx] ? 0 : null)

//This just allows the [] operator to be used for writes as well as reads. The above proc means this WILL work with +=, etc., for any valid gas.
/datum/gas_mixture/proc/operator[]=(idx, val)
Expand Down
205 changes: 116 additions & 89 deletions code/game/machinery/atmoalter/gas_mine.dm
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#define KW_TO_KPA_COEFFICIENT 0.5

/obj/machinery/atmospherics/miner
name = "gas miner"
desc = "Gasses mined from the gas giant below (above?) flow out through this massive vent."
Expand All @@ -9,59 +7,28 @@

starting_materials = null
w_type = NOT_RECYCLABLE
var/datum/powernet/PN
var/power_priority = POWER_PRIORITY_EXCESS
var/power_load = 0
var/on = TRUE
var/datum/power_connection/consumer/cable/power_connection = null

var/datum/gas_mixture/air_contents
var/datum/gas_mixture/pumping //used in transfering air around
//var/max_external_pressure=10000 // 10,000kPa ought to do it.
var/list/gases = list()
var/datum/gas_mixture/pumping = new //used in transfering air around

var/on=1

var/max_external_pressure=10000 // 10,000kPa ought to do it.
var/internal_pressure=4500 // Bottleneck

var/overlay_color = "#FFFFFF"

machine_flags = WRENCHMOVE | FIXED2WORK

/obj/machinery/atmospherics/miner/New()
..()
power_connection = new(src)
power_connection.monitoring_enabled = TRUE
power_connection.idle_usage = idle_power_usage
power_connection.active_usage = power_load

pumping = new
air_contents = new
air_contents.volume = 1000
pumping.volume = 1000 //Same as above so copying works correctly
air_contents.temperature = T20C
update_powernet()
update_icon()

/obj/machinery/atmospherics/miner/Destroy()
if(power_connection)
qdel(power_connection)
power_connection = null
if(pumping)
qdel(pumping)
pumping = null
if(air_contents)
qdel(air_contents)
air_contents = null
..()

/obj/machinery/atmospherics/miner/proc/update_rate(var/internal_pressure)
//rate is in mols
var/rate = internal_pressure * air_contents.volume / (R_IDEAL_GAS_EQUATION * air_contents.temperature)
//this is ugly
if(length(gases) == 1)
air_contents.adjust_multi(gases[1], rate)
else if(length(gases) == 2)
air_contents.adjust_multi(gases[1], gases[gases[1]]*rate, gases[2], gases[gases[2]]*rate)
else if(length(gases) == 3)
air_contents.adjust_multi(gases[1], gases[gases[1]]*rate, gases[2], gases[gases[2]]*rate, gases[3], gases[gases[3]]*rate)
AddAir()
air_contents.update_values()
update_icon()

/obj/machinery/atmospherics/miner/examine(mob/user)
. = ..()
Expand All @@ -74,15 +41,14 @@
if(stat & BROKEN)
to_chat(user, "<span class='info'>\The [src]'s status terminal reads: Broken.</span>")
return
to_chat(user, "<span class='info'>\The [src]'s status terminal reads: Functional and operating at a rate of [Ceiling(KW_TO_KPA_COEFFICIENT * power_load)] kPa per cycle.</span>")
to_chat(user, "<span class='info'>\The [src]'s status terminal reads: Functional and operating.</span>")

/obj/machinery/atmospherics/miner/wrenchAnchor(var/mob/user, var/obj/item/I)
. = ..()
if(!.)
return
if(on)
on = 0
power_load = 0
update_icon()

// Critical equipment.
Expand All @@ -95,24 +61,8 @@

/obj/machinery/atmospherics/miner/power_change()
..()
power_load = 0
update_rate(0)
update_powernet()
update_icon()

/obj/machinery/atmospherics/miner/proc/update_powernet()
var/area/A = get_area(src)
var/obj/machinery/power/apc/area_apc
if(!A)
return
area_apc = A.areaapc
if(!area_apc)
return

PN = area_apc.terminal.powernet
PN.add_connection(src)
return TRUE

/obj/machinery/atmospherics/miner/attack_ghost(var/mob/user)
return

Expand All @@ -127,8 +77,12 @@
else
to_chat(user, "<span class='warning'>\The [src] needs to be bolted to the ground first.</span>")

// Add air here. DO NOT CALL UPDATE_VALUES OR UPDATE_ICON.
/obj/machinery/atmospherics/miner/proc/AddAir()
return

/obj/machinery/atmospherics/miner/update_icon()
overlays = 0
src.overlays = 0
if(stat & (FORCEDISABLE|NOPOWER))
return
if(on)
Expand All @@ -144,8 +98,7 @@
/obj/machinery/atmospherics/miner/process()
if(stat & (FORCEDISABLE|NOPOWER))
return
if(!on)
use_power = MACHINE_POWER_USE_IDLE
if (!on)
return

var/oldstat=stat
Expand All @@ -158,64 +111,138 @@
if(stat & BROKEN)
return

//scale based on powernet, otherwise constant 4500
if(PN)
var/power_surplus = PN.get_satisfaction(power_priority)
use_power = MACHINE_POWER_USE_ACTIVE
update_rate(Ceiling(KW_TO_KPA_COEFFICIENT * power_load)) //scale mol output by arbitrary power load
if(power_surplus > 0.55)
power_load += 1000
else if (power_surplus < 0.45 && power_load > 0)
power_load -= 1000
else
power_load = 0
else
power_load = 0
use_power = MACHINE_POWER_USE_IDLE
update_rate(4500)
active_power_usage = power_load
pumping.copy_from(air_contents)
/*
//gas-related
var/datum/gas_mixture/environment = loc.return_air()
var/environment_pressure = environment.return_pressure()

pumping.copy_from(air_contents)

var/pressure_delta = 10000

// External pressure bound
pressure_delta = min(pressure_delta, (max_external_pressure - environment_pressure))

// Internal pressure bound (screwed up calc, won't be used anyway)
//pressure_delta = min(pressure_delta, (internal_pressure - environment_pressure))

if(pressure_delta > 0.1)
var/transfer_moles = pressure_delta * CELL_VOLUME / (pumping.temperature * R_IDEAL_GAS_EQUATION)

var/datum/gas_mixture/removed = pumping.remove(transfer_moles)
loc.assume_air(removed)*/

loc.assume_air(removed)

//Controls how fast gas comes out (in total)
/obj/machinery/atmospherics/miner/proc/AirRate()
return internal_pressure * air_contents.volume / (R_IDEAL_GAS_EQUATION * air_contents.temperature)


/obj/machinery/atmospherics/miner/sleeping_agent
name = "\improper N2O Gas Miner"
overlay_color = "#FFCCCC"
gases = list(GAS_SLEEPING = 1)

/obj/machinery/atmospherics/miner/sleeping_agent/AddAir()
var/rate = AirRate()
air_contents.adjust_multi(GAS_SLEEPING, rate)


/obj/machinery/atmospherics/miner/nitrogen
name = "\improper N2 Gas Miner"
overlay_color = "#CCFFCC"
gases = list(GAS_NITROGEN = 1)

/obj/machinery/atmospherics/miner/nitrogen/AddAir()
var/rate = AirRate()
air_contents.adjust_multi(GAS_NITROGEN, rate)


/obj/machinery/atmospherics/miner/oxygen
name = "\improper O2 Gas Miner"
overlay_color = "#007FFF"
gases = list(GAS_OXYGEN = 1)

/obj/machinery/atmospherics/miner/oxygen/AddAir()
var/rate = AirRate()
air_contents.adjust_multi(GAS_OXYGEN, rate)


/obj/machinery/atmospherics/miner/toxins
name = "\improper Plasma Gas Miner"
overlay_color = "#FF0000"
gases = list(GAS_PLASMA = 1)

/obj/machinery/atmospherics/miner/toxins/AddAir()
var/rate = AirRate()
air_contents.adjust_multi(GAS_PLASMA, rate)


/obj/machinery/atmospherics/miner/carbon_dioxide
name = "\improper CO2 Gas Miner"
overlay_color = "#CDCDCD"
gases = list(GAS_CARBON = 1)

/obj/machinery/atmospherics/miner/carbon_dioxide/AddAir()
var/rate = AirRate()
air_contents.adjust_multi(GAS_CARBON, rate)


/obj/machinery/atmospherics/miner/air
name = "\improper Air Miner"
desc = "You fucking <em>cheater</em>."
overlay_color = "#70DBDB"
gases = list(GAS_OXYGEN = 0.2, GAS_NITROGEN = 0.8)
on = 0

on = 0

/obj/machinery/atmospherics/miner/air/AddAir()
var/rate = AirRate()
air_contents.adjust_multi(GAS_OXYGEN, 0.2*rate,
GAS_NITROGEN, 0.8*rate)


/obj/machinery/atmospherics/miner/gas_giant
name = "\improper Gas Miner"

/obj/machinery/atmospherics/miner/gas_giant/initialize()
..()
AddAir()

/obj/machinery/atmospherics/miner/gas_giant/AddAir()
if(ticker)
air_contents.copy_from(gas_giant.GM)


/obj/machinery/atmospherics/miner/mixed_nitrogen
name = "\improper Mixed Gas Miner"
desc = "Pumping nitrogen, carbon dioxide, and plasma."
overlay_color = "#FF80BD"

/obj/machinery/atmospherics/miner/mixed_nitrogen/AddAir()
var/rate = AirRate()
air_contents.adjust_multi(GAS_CARBON, 0.3*rate,
GAS_NITROGEN, 0.4*rate,
GAS_PLASMA, 0.3*rate)

/obj/machinery/atmospherics/miner/mixed_oxygen
name = "\improper Mixed Gas Miner"
desc = "Pumping oxygen and nitrous oxide."
overlay_color = "#7EA7E0"

/obj/machinery/atmospherics/miner/mixed_oxygen/AddAir()
var/rate = AirRate()
air_contents.adjust_multi(GAS_OXYGEN, 0.5*rate,
GAS_SLEEPING, 0.5*rate)

/obj/machinery/atmospherics/miner/gas_sink
name = "Graviton Gas Sink"
desc = "This is a piece of machinery that uses gravitons to draw in molecules of gas a ship passes while moving through space. Due to the nature of gas dispersal in a vacuum, it requires traveling at hyperspace speeds in order to collect substantial gas particles, and the intake is a mixed, requiring filtering."

/obj/machinery/atmospherics/miner/gas_sink/AddAir()
var/rate = AirRate()
if(!rate)
return
air_contents.adjust_multi(GAS_CARBON, 0.1*rand(1,2)*rate,
GAS_NITROGEN, 0.1*rand(2,3)*rate,
GAS_PLASMA, 0.1*rand(4,5)*rate,
GAS_OXYGEN, 0.1*rand(4,5)*rate,
GAS_SLEEPING, 0.1*rand(1,2)*rate)

/obj/machinery/atmospherics/miner/gas_sink/AirRate()
var/datum/zLevel/current_zlevel = get_z_level(src)
if(istype(current_zlevel,/datum/zLevel/hyperspace))
return ..()
return 0

0 comments on commit 79b8dc3

Please sign in to comment.