mirror of
https://github.com/CHOMPStation2/CHOMPStation2.git
synced 2025-12-10 10:12:45 +00:00
- Added ground code for logic elements. Currently supports sensors, indicators, negators, two input and gates, or gates, xor gates, xnor (equivalence) gates and a relay, with one control input that works by logic laws and another input and output that work by powernet laws.
git-svn-id: http://tgstation13.googlecode.com/svn/trunk@4849 316c924e-a436-60f5-8080-3fe189b3f50e
This commit is contained in:
@@ -87,38 +87,37 @@
|
|||||||
var/d1 = 0
|
var/d1 = 0
|
||||||
var/d2 = 1
|
var/d2 = 1
|
||||||
layer = 2.44 //Just below unary stuff, which is at 2.45 and above pipes, which are at 2.4
|
layer = 2.44 //Just below unary stuff, which is at 2.45 and above pipes, which are at 2.4
|
||||||
var/color="red"
|
var/color = "red"
|
||||||
var/obj/structure/powerswitch/power_switch
|
var/obj/structure/powerswitch/power_switch
|
||||||
|
|
||||||
/obj/structure/cable/yellow
|
/obj/structure/cable/yellow
|
||||||
color="yellow"
|
color = "yellow"
|
||||||
icon = 'icons/obj/power_cond_yellow.dmi'
|
icon = 'icons/obj/power_cond_yellow.dmi'
|
||||||
|
|
||||||
/obj/structure/cable/green
|
/obj/structure/cable/green
|
||||||
color="green"
|
color = "green"
|
||||||
icon = 'icons/obj/power_cond_green.dmi'
|
icon = 'icons/obj/power_cond_green.dmi'
|
||||||
|
|
||||||
/obj/structure/cable/blue
|
/obj/structure/cable/blue
|
||||||
color="blue"
|
color = "blue"
|
||||||
icon = 'icons/obj/power_cond_blue.dmi'
|
icon = 'icons/obj/power_cond_blue.dmi'
|
||||||
|
|
||||||
/obj/structure/cable/pink
|
/obj/structure/cable/pink
|
||||||
color="pink"
|
color = "pink"
|
||||||
icon = 'icons/obj/power_cond_pink.dmi'
|
icon = 'icons/obj/power_cond_pink.dmi'
|
||||||
|
|
||||||
/obj/structure/cable/orange
|
/obj/structure/cable/orange
|
||||||
color="orange"
|
color = "orange"
|
||||||
icon = 'icons/obj/power_cond_orange.dmi'
|
icon = 'icons/obj/power_cond_orange.dmi'
|
||||||
|
|
||||||
/obj/structure/cable/cyan
|
/obj/structure/cable/cyan
|
||||||
color="cyan"
|
color = "cyan"
|
||||||
icon = 'icons/obj/power_cond_cyan.dmi'
|
icon = 'icons/obj/power_cond_cyan.dmi'
|
||||||
|
|
||||||
/obj/structure/cable/white
|
/obj/structure/cable/white
|
||||||
color="white"
|
color = "white"
|
||||||
icon = 'icons/obj/power_cond_white.dmi'
|
icon = 'icons/obj/power_cond_white.dmi'
|
||||||
|
|
||||||
|
|
||||||
/obj/effect/projection
|
/obj/effect/projection
|
||||||
name = "Projection"
|
name = "Projection"
|
||||||
desc = "This looks like a projection of something."
|
desc = "This looks like a projection of something."
|
||||||
|
|||||||
@@ -35,7 +35,7 @@
|
|||||||
|
|
||||||
NC.mergeConnectedNetworks(NC.d2)
|
NC.mergeConnectedNetworks(NC.d2)
|
||||||
NC.mergeConnectedNetworksOnTurf()
|
NC.mergeConnectedNetworksOnTurf()
|
||||||
if(powernet==null)
|
if(powernet == null)
|
||||||
if(NC.powernet == null)
|
if(NC.powernet == null)
|
||||||
NC.powernet = new()
|
NC.powernet = new()
|
||||||
powernets += NC.powernet
|
powernets += NC.powernet
|
||||||
|
|||||||
292
code/modules/power/cable_logic.dm
Normal file
292
code/modules/power/cable_logic.dm
Normal file
@@ -0,0 +1,292 @@
|
|||||||
|
#define LOGIC_HIGH 5
|
||||||
|
|
||||||
|
//Indicators only have one input and no outputs
|
||||||
|
/obj/machinery/logic/indicator
|
||||||
|
//Input is searched from the 'dir' direction
|
||||||
|
var/obj/structure/cable/input
|
||||||
|
|
||||||
|
/obj/machinery/logic/indicator/process()
|
||||||
|
if(input)
|
||||||
|
return 1
|
||||||
|
|
||||||
|
|
||||||
|
if(!input)
|
||||||
|
var/turf/T = get_step(src, dir)
|
||||||
|
if(T)
|
||||||
|
var/inv_dir = turn(dir, 180)
|
||||||
|
for(var/obj/structure/cable/C in T)
|
||||||
|
if(C.d1 == inv_dir || C.d2 == inv_dir)
|
||||||
|
input = C
|
||||||
|
return 1
|
||||||
|
|
||||||
|
return 0 //If it gets to here, it means no suitable wire to link to was found.
|
||||||
|
|
||||||
|
/obj/machinery/logic/indicator/bulb
|
||||||
|
icon = 'icons/obj/lighting.dmi'
|
||||||
|
icon_state = "bulb0"
|
||||||
|
|
||||||
|
/obj/machinery/logic/indicator/bulb/process()
|
||||||
|
if(!..()) //Parent proc checks if input1 exists.
|
||||||
|
return
|
||||||
|
|
||||||
|
var/datum/powernet/pn_input = input.powernet
|
||||||
|
if(!pn_input)
|
||||||
|
return
|
||||||
|
|
||||||
|
if(pn_input.avail >= LOGIC_HIGH)
|
||||||
|
icon_state = "bulb1"
|
||||||
|
else
|
||||||
|
icon_state = "bulb0"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//Sensors only have one output and no inputs
|
||||||
|
/obj/machinery/logic/sensor
|
||||||
|
//Output is searched from the 'dir' direction
|
||||||
|
var/obj/structure/cable/output
|
||||||
|
|
||||||
|
/obj/machinery/logic/sensor/process()
|
||||||
|
if(output)
|
||||||
|
return 1
|
||||||
|
|
||||||
|
if(!output)
|
||||||
|
var/turf/T = get_step(src, dir)
|
||||||
|
if(T)
|
||||||
|
var/inv_dir = turn(dir, 180)
|
||||||
|
for(var/obj/structure/cable/C in T)
|
||||||
|
if(C.d1 == inv_dir || C.d2 == inv_dir)
|
||||||
|
output = C
|
||||||
|
return 1
|
||||||
|
|
||||||
|
return 0 //If it gets to here, it means no suitable wire to link to was found.
|
||||||
|
|
||||||
|
//Constant high generator. This will continue to send a signal of LOGIC_HIGH as long as it exists.
|
||||||
|
/obj/machinery/logic/sensor/constant_high
|
||||||
|
icon = 'icons/obj/atmospherics/outlet_injector.dmi'
|
||||||
|
icon_state = "off"
|
||||||
|
|
||||||
|
/obj/machinery/logic/sensor/constant_high/process()
|
||||||
|
if(!..()) //Parent proc checks if input1 exists.
|
||||||
|
return
|
||||||
|
|
||||||
|
var/datum/powernet/pn_output = output.powernet
|
||||||
|
if(!pn_output)
|
||||||
|
return
|
||||||
|
|
||||||
|
pn_output.newavail = max(pn_output.avail, LOGIC_HIGH)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//ONE INPUT logic elements have one input and one output
|
||||||
|
/obj/machinery/logic/oneinput
|
||||||
|
var/dir_input = 2
|
||||||
|
var/dir_output = 1
|
||||||
|
var/obj/structure/cable/input
|
||||||
|
var/obj/structure/cable/output
|
||||||
|
icon = 'icons/obj/pipes/heat.dmi'
|
||||||
|
icon_state = "intact"
|
||||||
|
|
||||||
|
/obj/machinery/logic/oneinput/process()
|
||||||
|
if(input && output)
|
||||||
|
return 1
|
||||||
|
|
||||||
|
if(!dir_input || !dir_output)
|
||||||
|
return 0
|
||||||
|
|
||||||
|
if(!input)
|
||||||
|
var/turf/T = get_step(src, dir_input)
|
||||||
|
if(T)
|
||||||
|
var/inv_dir = turn(dir_input, 180)
|
||||||
|
for(var/obj/structure/cable/C in T)
|
||||||
|
if(C.d1 == inv_dir || C.d2 == inv_dir)
|
||||||
|
input = C
|
||||||
|
|
||||||
|
if(!output)
|
||||||
|
var/turf/T = get_step(src, dir_output)
|
||||||
|
if(T)
|
||||||
|
var/inv_dir = turn(dir_output, 180)
|
||||||
|
for(var/obj/structure/cable/C in T)
|
||||||
|
if(C.d1 == inv_dir || C.d2 == inv_dir)
|
||||||
|
output = C
|
||||||
|
|
||||||
|
return 0 //On the process() call, where everything is still being searched for, it returns 0. It will return 1 on the next process() call.
|
||||||
|
|
||||||
|
//NOT GATE
|
||||||
|
/obj/machinery/logic/oneinput/not/process()
|
||||||
|
if(!..()) //Parent proc checks if input1, input2 and output exist.
|
||||||
|
return
|
||||||
|
|
||||||
|
var/datum/powernet/pn_input = input.powernet
|
||||||
|
|
||||||
|
if(!pn_input)
|
||||||
|
return
|
||||||
|
|
||||||
|
var/datum/powernet/pn_output = output.powernet
|
||||||
|
if(!pn_output)
|
||||||
|
return
|
||||||
|
|
||||||
|
if( !(pn_input.avail >= LOGIC_HIGH))
|
||||||
|
pn_output.newavail = max(pn_output.avail, LOGIC_HIGH) //Set the output avilable power to 5 or whatever it was before.
|
||||||
|
else
|
||||||
|
pn_output.newload += LOGIC_HIGH //Otherwise increase the load to 5
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//TWO INPUT logic elements have two inputs and one output
|
||||||
|
/obj/machinery/logic/twoinput
|
||||||
|
var/dir_input1 = 2
|
||||||
|
var/dir_input2 = 8
|
||||||
|
var/dir_output = 1
|
||||||
|
var/obj/structure/cable/input1
|
||||||
|
var/obj/structure/cable/input2
|
||||||
|
var/obj/structure/cable/output
|
||||||
|
icon = 'icons/obj/atmospherics/mixer.dmi'
|
||||||
|
icon_state = "intact_off"
|
||||||
|
|
||||||
|
/obj/machinery/logic/twoinput/process()
|
||||||
|
if(input1 && input2 && output)
|
||||||
|
return 1
|
||||||
|
|
||||||
|
if(!dir_input1 || !dir_input2 || !dir_output)
|
||||||
|
return 0
|
||||||
|
|
||||||
|
if(!input1)
|
||||||
|
var/turf/T = get_step(src, dir_input1)
|
||||||
|
if(T)
|
||||||
|
var/inv_dir = turn(dir_input1, 180)
|
||||||
|
for(var/obj/structure/cable/C in T)
|
||||||
|
if(C.d1 == inv_dir || C.d2 == inv_dir)
|
||||||
|
input1 = C
|
||||||
|
|
||||||
|
if(!input2)
|
||||||
|
var/turf/T = get_step(src, dir_input2)
|
||||||
|
if(T)
|
||||||
|
var/inv_dir = turn(dir_input2, 180)
|
||||||
|
for(var/obj/structure/cable/C in T)
|
||||||
|
if(C.d1 == inv_dir || C.d2 == inv_dir)
|
||||||
|
input2 = C
|
||||||
|
|
||||||
|
if(!output)
|
||||||
|
var/turf/T = get_step(src, dir_output)
|
||||||
|
if(T)
|
||||||
|
var/inv_dir = turn(dir_output, 180)
|
||||||
|
for(var/obj/structure/cable/C in T)
|
||||||
|
if(C.d1 == inv_dir || C.d2 == inv_dir)
|
||||||
|
output = C
|
||||||
|
|
||||||
|
return 0 //On the process() call, where everything is still being searched for, it returns 0. It will return 1 on the next process() call.
|
||||||
|
|
||||||
|
//AND GATE
|
||||||
|
/obj/machinery/logic/twoinput/and/process()
|
||||||
|
if(!..()) //Parent proc checks if input1, input2 and output exist.
|
||||||
|
return
|
||||||
|
|
||||||
|
var/datum/powernet/pn_input1 = input1.powernet
|
||||||
|
var/datum/powernet/pn_input2 = input2.powernet
|
||||||
|
|
||||||
|
if(!pn_input1 || !pn_input2)
|
||||||
|
return
|
||||||
|
|
||||||
|
var/datum/powernet/pn_output = output.powernet
|
||||||
|
if(!pn_output)
|
||||||
|
return
|
||||||
|
|
||||||
|
if( (pn_input1.avail >= LOGIC_HIGH) && (pn_input2.avail >= LOGIC_HIGH) )
|
||||||
|
pn_output.newavail = max(pn_output.avail, LOGIC_HIGH) //Set the output avilable power to 5 or whatever it was before.
|
||||||
|
else
|
||||||
|
pn_output.newload += LOGIC_HIGH //Otherwise increase the load to 5
|
||||||
|
|
||||||
|
//OR GATE
|
||||||
|
/obj/machinery/logic/twoinput/or/process()
|
||||||
|
if(!..()) //Parent proc checks if input1, input2 and output exist.
|
||||||
|
return
|
||||||
|
|
||||||
|
var/datum/powernet/pn_input1 = input1.powernet
|
||||||
|
var/datum/powernet/pn_input2 = input2.powernet
|
||||||
|
|
||||||
|
if(!pn_input1 || !pn_input2)
|
||||||
|
return
|
||||||
|
|
||||||
|
var/datum/powernet/pn_output = output.powernet
|
||||||
|
if(!pn_output)
|
||||||
|
return
|
||||||
|
|
||||||
|
if( (pn_input1.avail >= LOGIC_HIGH) || (pn_input2.avail >= LOGIC_HIGH) )
|
||||||
|
pn_output.newavail = max(pn_output.avail, LOGIC_HIGH) //Set the output avilable power to 5 or whatever it was before.
|
||||||
|
else
|
||||||
|
pn_output.newload += LOGIC_HIGH //Otherwise increase the load to 5
|
||||||
|
|
||||||
|
//XOR GATE
|
||||||
|
/obj/machinery/logic/twoinput/xor/process()
|
||||||
|
if(!..()) //Parent proc checks if input1, input2 and output exist.
|
||||||
|
return
|
||||||
|
|
||||||
|
var/datum/powernet/pn_input1 = input1.powernet
|
||||||
|
var/datum/powernet/pn_input2 = input2.powernet
|
||||||
|
|
||||||
|
if(!pn_input1 || !pn_input2)
|
||||||
|
return
|
||||||
|
|
||||||
|
var/datum/powernet/pn_output = output.powernet
|
||||||
|
if(!pn_output)
|
||||||
|
return
|
||||||
|
|
||||||
|
if( (pn_input1.avail >= LOGIC_HIGH) != (pn_input2.avail >= LOGIC_HIGH) )
|
||||||
|
pn_output.newavail = max(pn_output.avail, LOGIC_HIGH) //Set the output avilable power to 5 or whatever it was before.
|
||||||
|
else
|
||||||
|
pn_output.newload += LOGIC_HIGH //Otherwise increase the load to 5
|
||||||
|
|
||||||
|
//XNOR GATE (EQUIVALENCE)
|
||||||
|
/obj/machinery/logic/twoinput/xnor/process()
|
||||||
|
if(!..()) //Parent proc checks if input1, input2 and output exist.
|
||||||
|
return
|
||||||
|
|
||||||
|
var/datum/powernet/pn_input1 = input1.powernet
|
||||||
|
var/datum/powernet/pn_input2 = input2.powernet
|
||||||
|
|
||||||
|
if(!pn_input1 || !pn_input2)
|
||||||
|
return
|
||||||
|
|
||||||
|
var/datum/powernet/pn_output = output.powernet
|
||||||
|
if(!pn_output)
|
||||||
|
return
|
||||||
|
|
||||||
|
if( (pn_input1.avail >= LOGIC_HIGH) == (pn_input2.avail >= LOGIC_HIGH) )
|
||||||
|
pn_output.newavail = max(pn_output.avail, LOGIC_HIGH) //Set the output avilable power to 5 or whatever it was before.
|
||||||
|
else
|
||||||
|
pn_output.newload += LOGIC_HIGH //Otherwise increase the load to 5
|
||||||
|
|
||||||
|
#define RELAY_POWER_TRANSFER 2000 //How much power a relay transfers through.
|
||||||
|
|
||||||
|
//RELAY - input1 governs the flow from input2 to output
|
||||||
|
/obj/machinery/logic/twoinput/relay/process()
|
||||||
|
if(!..()) //Parent proc checks if input1, input2 and output exist.
|
||||||
|
return
|
||||||
|
|
||||||
|
var/datum/powernet/pn_input1 = input1.powernet
|
||||||
|
|
||||||
|
if(!pn_input1)
|
||||||
|
return
|
||||||
|
|
||||||
|
if( pn_input1.avail >= LOGIC_HIGH )
|
||||||
|
var/datum/powernet/pn_input2 = input2.powernet
|
||||||
|
var/datum/powernet/pn_output = output.powernet
|
||||||
|
|
||||||
|
if(!pn_output)
|
||||||
|
return
|
||||||
|
|
||||||
|
if(pn_input2.avail >= RELAY_POWER_TRANSFER)
|
||||||
|
pn_input2.newload += RELAY_POWER_TRANSFER
|
||||||
|
pn_output.newavail += RELAY_POWER_TRANSFER
|
||||||
|
|
||||||
|
|
||||||
|
#undef RELAY_POWER_TRANSFER
|
||||||
|
#undef LOGIC_HIGH
|
||||||
@@ -59,6 +59,10 @@
|
|||||||
#define FILE_DIR "code/game/mecha/medical"
|
#define FILE_DIR "code/game/mecha/medical"
|
||||||
#define FILE_DIR "code/game/mecha/working"
|
#define FILE_DIR "code/game/mecha/working"
|
||||||
#define FILE_DIR "code/game/objects"
|
#define FILE_DIR "code/game/objects"
|
||||||
|
#define FILE_DIR "code/game/objects/alien"
|
||||||
|
#define FILE_DIR "code/game/objects/closets"
|
||||||
|
#define FILE_DIR "code/game/objects/devices"
|
||||||
|
#define FILE_DIR "code/game/objects/devices/PDA"
|
||||||
#define FILE_DIR "code/game/objects/effects"
|
#define FILE_DIR "code/game/objects/effects"
|
||||||
#define FILE_DIR "code/game/objects/effects/decals"
|
#define FILE_DIR "code/game/objects/effects/decals"
|
||||||
#define FILE_DIR "code/game/objects/effects/decals/Cleanable"
|
#define FILE_DIR "code/game/objects/effects/decals/Cleanable"
|
||||||
@@ -77,6 +81,7 @@
|
|||||||
#define FILE_DIR "code/game/objects/items/weapons/secstorage"
|
#define FILE_DIR "code/game/objects/items/weapons/secstorage"
|
||||||
#define FILE_DIR "code/game/objects/items/weapons/storage"
|
#define FILE_DIR "code/game/objects/items/weapons/storage"
|
||||||
#define FILE_DIR "code/game/objects/items/weapons/tanks"
|
#define FILE_DIR "code/game/objects/items/weapons/tanks"
|
||||||
|
#define FILE_DIR "code/game/objects/storage"
|
||||||
#define FILE_DIR "code/game/objects/structures"
|
#define FILE_DIR "code/game/objects/structures"
|
||||||
#define FILE_DIR "code/game/objects/structures/crates_lockers"
|
#define FILE_DIR "code/game/objects/structures/crates_lockers"
|
||||||
#define FILE_DIR "code/game/objects/structures/crates_lockers/closets"
|
#define FILE_DIR "code/game/objects/structures/crates_lockers/closets"
|
||||||
@@ -1125,6 +1130,7 @@
|
|||||||
#include "code\modules\power\apc.dm"
|
#include "code\modules\power\apc.dm"
|
||||||
#include "code\modules\power\cable.dm"
|
#include "code\modules\power\cable.dm"
|
||||||
#include "code\modules\power\cable_heavyduty.dm"
|
#include "code\modules\power\cable_heavyduty.dm"
|
||||||
|
#include "code\modules\power\cable_logic.dm"
|
||||||
#include "code\modules\power\cell.dm"
|
#include "code\modules\power\cell.dm"
|
||||||
#include "code\modules\power\engine.dm"
|
#include "code\modules\power\engine.dm"
|
||||||
#include "code\modules\power\generator.dm"
|
#include "code\modules\power\generator.dm"
|
||||||
|
|||||||
Reference in New Issue
Block a user