Skip to content

Commit

Permalink
Engine project (#1070)
Browse files Browse the repository at this point in the history
Tokamak/Fusion engine.
This contains:
Fusion engine, controller for the fusion engine, fusion ball and all the controller compo
  • Loading branch information
rjtwins authored Sep 13, 2016
1 parent c8270df commit ec9b956
Show file tree
Hide file tree
Showing 58 changed files with 3,640 additions and 28 deletions.
20 changes: 20 additions & 0 deletions apollo.dme
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@
#include "code\__HELPERS\type2type.dm"
#include "code\__HELPERS\unsorted.dm"
#include "code\_helpers\matrices.dm"
#include "code\_helpers\LightningLib\Bar.dm"
#include "code\_helpers\LightningLib\Beam.dm"
#include "code\_helpers\LightningLib\Bolt.dm"
#include "code\_helpers\LightningLib\BranchedBolt.dm"
#include "code\_helpers\LightningLib\Line.dm"
#include "code\_helpers\LightningLib\math.dm"
#include "code\_helpers\LightningLib\segment.dm"
#include "code\_helpers\LightningLib\Vector.dm"
#include "code\_onclick\adjacent.dm"
#include "code\_onclick\ai.dm"
#include "code\_onclick\click.dm"
Expand Down Expand Up @@ -104,6 +112,7 @@
#include "code\controllers\Processes\emergencyShuttle.dm"
#include "code\controllers\Processes\event.dm"
#include "code\controllers\Processes\factions.dm"
#include "code\controllers\Processes\fusion.dm"
#include "code\controllers\Processes\garbage.dm"
#include "code\controllers\Processes\hanger.dm"
#include "code\controllers\Processes\hanger_controller.dm"
Expand Down Expand Up @@ -199,6 +208,7 @@
#include "code\datums\wires\airlock.dm"
#include "code\datums\wires\alarm.dm"
#include "code\datums\wires\apc.dm"
#include "code\datums\wires\arc_emitter_wires.dm"
#include "code\datums\wires\autolathe.dm"
#include "code\datums\wires\breakerbox.dm"
#include "code\datums\wires\bubble_shield_gen_wires.dm"
Expand Down Expand Up @@ -1496,6 +1506,16 @@
#include "code\modules\power\antimatter\containment_jar.dm"
#include "code\modules\power\antimatter\control.dm"
#include "code\modules\power\antimatter\shielding.dm"
#include "code\modules\power\fusion\arc_emitter.dm"
#include "code\modules\power\fusion\base.dm"
#include "code\modules\power\fusion\computer.dm"
#include "code\modules\power\fusion\controller.dm"
#include "code\modules\power\fusion\core.dm"
#include "code\modules\power\fusion\fabricator.dm"
#include "code\modules\power\fusion\fusion_ball.dm"
#include "code\modules\power\fusion\plasma.dm"
#include "code\modules\power\fusion\ring.dm"
#include "code\modules\power\fusion\upgrades.dm"
#include "code\modules\power\rust\areas.dm"
#include "code\modules\power\rust\circuits_and_design.dm"
#include "code\modules\power\rust\core_control.dm"
Expand Down
2 changes: 0 additions & 2 deletions code/ATMOSPHERICS/components/binary_devices/pipeturbine.dm
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#define ADIABATIC_EXPONENT 0.667 //Actually adiabatic exponent - 1.

/obj/machinery/atmospherics/pipeturbine
name = "turbine"
desc = "A gas turbine. Converting pressure into energy since 1884."
Expand Down
30 changes: 19 additions & 11 deletions code/ATMOSPHERICS/components/unary/heat_exchanger.dm
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
desc = "Exchanges heat between two input gases. Setup for fast heat transfer"

var/obj/machinery/atmospherics/unary/heat_exchanger/partner = null
var/obj/machinery/power/fusion/plasma/plasma = null
var/update_cycle

update_icon()
Expand All @@ -27,41 +28,48 @@
partner = target
partner.partner = src
break

..()

process()
..()
if(!partner)
var/datum/gas_mixture/partner_air = null
if(!partner && !plasma)
return 0
else if(!isnull(partner))
partner_air = partner.air_contents
else if (plasma.transfering)
partner_air = plasma.air_contents

/* //I dont think the following is needed as non of the other gas heating/cooling machines use it. <rjtwins>
if(!air_master || air_master.current_cycle <= update_cycle)
return 0
update_cycle = air_master.current_cycle
partner.update_cycle = air_master.current_cycle

if(!isnull(partner))
partner.update_cycle = air_master.current_cycle
*/
var/air_heat_capacity = air_contents.heat_capacity()
var/other_air_heat_capacity = partner.air_contents.heat_capacity()
var/other_air_heat_capacity = partner_air.heat_capacity()
var/combined_heat_capacity = other_air_heat_capacity + air_heat_capacity

var/old_temperature = air_contents.temperature
var/other_old_temperature = partner.air_contents.temperature
var/other_old_temperature = partner_air.temperature

if(combined_heat_capacity > 0)
var/combined_energy = partner.air_contents.temperature*other_air_heat_capacity + air_heat_capacity*air_contents.temperature
var/combined_energy = partner_air.temperature*other_air_heat_capacity + air_heat_capacity*air_contents.temperature

var/new_temperature = combined_energy/combined_heat_capacity
air_contents.temperature = new_temperature
partner.air_contents.temperature = new_temperature
partner_air.temperature = new_temperature

if(network)
if(abs(old_temperature-air_contents.temperature) > 1)
network.update = 1

if(partner.network)
if(abs(other_old_temperature-partner.air_contents.temperature) > 1)
partner.network.update = 1
if(isnull(plasma))//Plasma had not variable called network this will cause erros otherwise
if(partner.network)
if(abs(other_old_temperature-partner_air.temperature) > 1)
partner.network.update = 1

return 1

Expand Down
7 changes: 7 additions & 0 deletions code/ZAS/Gas.dm
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@
specific_heat = 20 // J/(mol*K)
molar_mass = 0.028 // kg/mol

/xgm_gas/hydrogen
id = "hydrogen"
name = "Hydrogen"
specific_heat = 28 // J/(mol*K)
molar_mass = 0.020 // kg/mol
flags = XGM_GAS_FUEL

/xgm_gas/carbon_dioxide
id = "carbon_dioxide"
name = "Carbon Dioxide"
Expand Down
9 changes: 9 additions & 0 deletions code/ZAS/_gas_mixture_xgm.dm
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@
/datum/gas_mixture/proc/get_thermal_energy_change(var/new_temperature)
return heat_capacity()*(max(new_temperature, 0) - temperature)

//Returns the thermal energy stored in the gas, usefull for deviding energy between gas systems.
/datum/gas_mixture/proc/get_thermal_energy()
return heat_capacity()*temperature

//Technically vacuum doesn't have a specific entropy. Just use a really big number (infinity would be ideal) here so that it's easy to add gas to vacuum and hard to take gas out.
#define SPECIFIC_ENTROPY_VACUUM 150000
Expand Down Expand Up @@ -172,6 +175,12 @@
//group_multiplier gets divided out in volume/gas[gasid] - also, V/(m*T) = R/(partial pressure)
var/molar_mass = gas_data.molar_mass[gasid]
var/specific_heat = gas_data.specific_heat[gasid]
/* if(gasid == "hydrogen") //Hydrogen gass debug
world << "Molar mas of [gasid] = [molar_mass]"
world << "Specific heat of [gasid] = [specific_heat]"
world << "Temperature of [gasid] = [temperature]"
world << "gas\[gasid\] returns [gas[gasid]]"
*/
return R_IDEAL_GAS_EQUATION * ( log( (IDEAL_GAS_ENTROPY_CONSTANT*volume/(gas[gasid] * temperature)) * (molar_mass*specific_heat*temperature)**(2/3) + 1 ) + 15 )

//alternative, simpler equation
Expand Down
1 change: 0 additions & 1 deletion code/__HELPERS/datum_pool.dm
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

/*
/tg/station13 /atom/movable Pool:
---------------------------------
Expand Down
8 changes: 8 additions & 0 deletions code/__HELPERS/maths.dm
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ var/list/sqrtTable = list(1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4,
var/a = arccos(x / sqrt(x*x + y*y))
return y >= 0 ? a : -a

/proc/alt_atan2(x,y)
return (x||y)&&(y>=0 ? arccos(x/sqrt(x*x+y*y)) : 360-arccos(x/sqrt(x*x+y*y)))

/proc/alt_Rand(min, max, precision = 3)
var/d = 10 ** precision

return rand(min * d, max * d) / d

/proc/Ceiling(x)
return -round(-x)

Expand Down
2 changes: 1 addition & 1 deletion code/__HELPERS/unsorted.dm
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
return 1


/proc/Get_Angle(atom/movable/start,atom/movable/end)//For beams.
/proc/Get_Angle(atom/movable/start,atom/movable/end)//For beams. //Give agle in the x direction not from current dir.
if(!start || !end) return 0
var/dy
var/dx
Expand Down
48 changes: 48 additions & 0 deletions code/_helpers/LightningLib/Bar.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/**
* adjustable bar
*/

beam/bar

var/list/objects
var/index


/**
* Draws a adjustable bar of type with a color between two assigned vectors on z or client screen
*
* @param z the map z level to draw on, if z is client it will draw on client screen
* @param type basic segment to use when drawing
* @param color color of the segment
* @param thickness thickness of the segment
*/
Draw(z, type = /obj/segment, color = "#fff", thickness = 1)

objects = list()
for(var/line/segment in segments)
var/obj/o = segment.Draw(z, type, color, thickness)
objects += o

index = objects.len

proc
/**
* Adjusts the bar to a percent
*
* @param percent percent of bar filled
*/
Adjust(percent)
set waitfor = 0

var/newIndex = round((percent * objects.len) / 100)
var/s = newIndex > index ? 1 : -1

for(var/i = index to newIndex step s)
var/obj/o = objects[i]

o.invisibility = !o.invisibility

sleep(world.tick_lag)

index = newIndex

110 changes: 110 additions & 0 deletions code/_helpers/LightningLib/Beam.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
/**
* a line made of line segments, used to create a growing animated line (useful for beams, bars etc)
*/

beam
var
list/segments
fade

/**
* Constructs the beam, from vector source to vector dest
*
* @param source source vector, where the bolt starts
* @param dest destination vector, where the beam ends
* @param placement distance between every segment, lower means more segments, default of 32
* @param fade assigns fade out rate, default of 25
*/
New(vector/source, vector/dest, placement = 32, fade = 25)
..()

segments = createBeam(source, dest, placement)
src.fade = 25

proc
/**
* Draws a beam of type with a color between two assigned vectors on z or client screen
*
* @param z the map z level to draw on, if z is client it will draw on client screen
* @param type basic segment to use when drawing
* @param color color of the beam
* @param thickness thickness of the beam
*/
Draw(z, type = /obj/segment, color = "#fff", thickness = 1)
set waitfor = 0
var/pos = 1
for(var/line/segment in segments)
var/obj/o = segment.Draw(z, type, color, thickness)
Effect(o, pos++)
sleep(world.tick_lag)

/**
* Applys animation to beam segment
* this could be overriden by child types to allow different animations to beam
* by default, a beam will fully grow then begin to fade out
*
* @param o the object segment, each beam is made of several segments
* @param pos the position of the segment, this could be used to calculate the delay at which it is displayed to provide more control over animations
*/
Effect(obj/o, pos)
set waitfor = 0
sleep(world.tick_lag * (segments.len - pos))

animate(o, alpha = 0, time = 255 / fade, loop = 1)

sleep(255 / fade)
Dispose(o, pos)

/**
* Handles soft deletion of beam segments
* by default after a beam faded it will be disposed
*
* @param o the object segment to dispose
*/
Dispose(obj/o)
o.loc = null

/**
* Returns a list of segments from vector source to vector dest
*
* @param source source vector, where the beam starts
* @param dest destination vector, where the beam ends
* @return dest a list of line segments forming a beam
*/
createBeam(vector/source, vector/dest, placement = 32)
var/list/results = list()

var/vector/tangent = vectorSubtract(dest, source)
var/length = tangent.Length()

var/vector/prevPoint = source
for(var/i = 1 to length / placement)

var/pos = i / (length / placement)
var/vector/endPoint = new (source.X + (tangent.X * pos), source.Y + (tangent.Y * pos))

endPoint.Round()
var/line/l = new(prevPoint, endPoint)
results += l

prevPoint = endPoint

var/line/l = new(prevPoint, dest)
results += l

return results

/**
* Returns a list of turfs between the beam's starting vector to the beam's end vector
* It can return null if no turfs are found.
*
* @param z the map z level to search
* @param accurate controlls the accurecy of this function, lower number means more accurate results however it reduces performance
* 1 being the minimum
* @return a list of turfs the beam passes on
*/
GetTurfs(z, accurate = 16)
var/line/start = segments[1]
var/line/end = segments[segments.len]

return vectorGetTurfs(start.A, end.B, z, accurate)
Loading

0 comments on commit ec9b956

Please sign in to comment.