mirror of
https://github.com/cybergirlvannie/OpenSS13.git
synced 2026-06-17 20:12:29 +01:00
295 lines
6.9 KiB
Plaintext
295 lines
6.9 KiB
Plaintext
/*
|
|
* Solar_control -- A machine that controls solar panels (/obj/machinery/power/solar)
|
|
*
|
|
* The controller must be on the same powernet and have the same id value as the solar panel
|
|
*/
|
|
|
|
|
|
obj/machinery/power/solar_control
|
|
name = "solar panel control"
|
|
desc = "A controller for solar panel arrays."
|
|
icon = 'enginecomputer.dmi'
|
|
icon_state = "solar_con"
|
|
anchored = 1
|
|
density = 1
|
|
directwired = 1
|
|
var
|
|
id = 1 // must match that of the solar panels to control
|
|
cdir = 0 // the current direction of the controlled solar panels
|
|
gen = 0 // the current power generation by the controlled panels
|
|
lastgen = 0 // the last power generation value from the previous cycle
|
|
track = 0 // direction tracking on/off
|
|
trackrate = 600 // time between tracking turns, 300-900 seconds
|
|
trackdir = 1 // direction to turn when tracking, 0 =CCW, 1=CW
|
|
nexttime = 0 // timeofday until next tracking turn
|
|
|
|
|
|
// Create a new solar controller.
|
|
|
|
New()
|
|
..()
|
|
|
|
spawn(15) // wait for powernets to be built after map load
|
|
|
|
if(powernet)
|
|
for(var/obj/machinery/power/solar/S in powernet.nodes)
|
|
if(S.id == id)
|
|
cdir = S.dir // find the contorlled solar panels and set the current direction to match
|
|
updateicon() // also update the icon overlay
|
|
|
|
|
|
// Update the icon_state
|
|
// If broken or unpowered, set those states
|
|
// Otherwise, add an overlay showing the current panel direction
|
|
|
|
proc/updateicon()
|
|
if(stat & BROKEN)
|
|
icon_state = "broken"
|
|
overlays = null
|
|
return
|
|
if(stat & NOPOWER)
|
|
icon_state = "c_unpowered"
|
|
overlays = null
|
|
return
|
|
|
|
icon_state = "solar_con"
|
|
overlays = null
|
|
if(cdir > 0)
|
|
overlays += image('enginecomputer.dmi', "solcon-o[cdir]", FLY_LAYER)
|
|
|
|
// Attack by AI, open interaction window
|
|
|
|
attack_ai(mob/user)
|
|
|
|
add_fingerprint(user)
|
|
|
|
if(stat & (BROKEN | NOPOWER)) return
|
|
|
|
interact(user)
|
|
|
|
// Attack by hand, open interaction window
|
|
|
|
attack_hand(mob/user)
|
|
add_fingerprint(user)
|
|
|
|
if(stat & (BROKEN | NOPOWER)) return
|
|
|
|
interact(user)
|
|
|
|
|
|
// Timed process
|
|
// Update lastgen so it has the value of total power generated by panels last cycle
|
|
// Reset the current generation value to zero (to be added to in each /solar/process() proc)
|
|
// If tracking, rotate the panels if next tracking turn timer has expired
|
|
|
|
process()
|
|
lastgen = gen
|
|
gen = 0
|
|
|
|
if(stat & (NOPOWER | BROKEN))
|
|
return
|
|
|
|
use_power(250)
|
|
|
|
if(track && nexttime < world.timeofday)
|
|
if(trackdir)
|
|
cdir = turn(cdir, -45)
|
|
else
|
|
cdir = turn(cdir, 45)
|
|
set_panels(cdir)
|
|
|
|
nexttime = world.timeofday + 10*trackrate
|
|
updateicon()
|
|
|
|
|
|
// Update all players view interaction window
|
|
|
|
src.updateDialog()
|
|
|
|
|
|
// Display the interaction window
|
|
|
|
proc/interact(mob/user)
|
|
|
|
if ( (get_dist(src, user) > 1 ))
|
|
if (!istype(user, /mob/ai))
|
|
user.machine = null
|
|
user.client_mob() << browse(null, "window=solcon")
|
|
return
|
|
|
|
user.machine = src
|
|
|
|
var/t = "<TT><B>Solar Generator Control</B><HR><PRE>"
|
|
|
|
t += "Generated power : [round(lastgen)] W<BR><BR>"
|
|
|
|
t += "Current panel orientation: <B>[uppertext(dir2text(cdir))]</B><BR>"
|
|
|
|
t += "<HR>Set orientation:<BR>"
|
|
|
|
var/list/D = list(-1, NORTHWEST, NORTH, NORTHEAST, -1, WEST, 0, EAST, -1, SOUTHWEST, SOUTH, SOUTHEAST)
|
|
var/list/disp = list("|", "|", "", "-", "/", "\\", "", "-", "\\", "/")
|
|
|
|
for(var/d in D)
|
|
if(d == 0)
|
|
t += " "
|
|
continue
|
|
if(d == -1)
|
|
t += "<BR> "
|
|
continue
|
|
|
|
if(d==cdir)
|
|
t +=" [disp[d]]"
|
|
else
|
|
t +=" <A href='?src=\ref[src];dir=[d]'>O</A>"
|
|
|
|
|
|
t += "<HR><BR><BR>"
|
|
|
|
t += "Tracking: [ track ? "<A href='?src=\ref[src];track=1'>Off</A> <B>On</B>" : "<B>Off</B> <A href='?src=\ref[src];track=1'>On</A>"]"
|
|
|
|
t += " [trackdir ? "<A href='?src=\ref[src];tdir=1'>CCW</A> <B>CW</B>" : "<B>CCW</B> <A href='?src=\ref[src];tdir=1'>CW</A>"]<BR>"
|
|
|
|
t += "Rate: <A href='?src=\ref[src];trk=-3'>-</A> <A href='?src=\ref[src];trk=-2'>-</A> <A href='?src=\ref[src];trk=-1'>-</A> [trackrate] <A href='?src=\ref[src];trk=1'>+</A> <A href='?src=\ref[src];trk=2'>+</A> <A href='?src=\ref[src];trk=3'>+</A> (seconds per turn)<BR>"
|
|
|
|
t += "</PRE><HR><A href='?src=\ref[src];close=1'>Close</A>"
|
|
|
|
t += "</TT>"
|
|
user.client_mob() << browse(t, "window=solcon")
|
|
|
|
return
|
|
|
|
|
|
// Handle topic links from the interaction window
|
|
|
|
Topic(href, href_list)
|
|
..()
|
|
|
|
if (usr.stat || usr.restrained() )
|
|
return
|
|
if ((!( istype(usr, /mob/human) ) && (!( ticker ) || (ticker && ticker.mode != "monkey"))))
|
|
if (!istype(usr, /mob/ai))
|
|
if (!istype(usr, /mob/drone))
|
|
usr.client_mob() << "\red You don't have the dexterity to do this!"
|
|
return
|
|
|
|
//world << "[href] ; [href_list[href]]"
|
|
|
|
if (( usr.machine==src && (get_dist(src, usr) <= 1 && istype(src.loc, /turf))) || (istype(usr, /mob/ai)))
|
|
|
|
|
|
if( href_list["close"] )
|
|
usr.client_mob() << browse(null, "window=solcon")
|
|
usr.machine = null
|
|
return
|
|
|
|
else if( href_list["dir"] )
|
|
cdir = text2num(href_list["dir"])
|
|
|
|
spawn(1)
|
|
set_panels(cdir)
|
|
|
|
updateicon()
|
|
else if( href_list["tdir"] )
|
|
trackdir = !trackdir
|
|
|
|
else if( href_list["track"] )
|
|
track = !track
|
|
nexttime = world.timeofday + 10*trackrate
|
|
|
|
else if( href_list["trk"] )
|
|
var/inc = text2num(href_list["trk"])
|
|
|
|
switch(inc)
|
|
if(1, -1)
|
|
trackrate += inc
|
|
if(2,-2)
|
|
trackrate += 10*inc/abs(inc)
|
|
if(3,-3)
|
|
trackrate += 100*inc/abs(inc)
|
|
|
|
trackrate = min( max(trackrate, 10), 900)
|
|
nexttime = world.timeofday + 10*trackrate
|
|
|
|
spawn(0)
|
|
src.updateDialog()
|
|
|
|
else
|
|
usr.client_mob() << browse(null, "window=solcon")
|
|
usr.machine = null
|
|
|
|
return
|
|
|
|
|
|
// Set a new set direction for all panels controlled by this controller
|
|
|
|
proc/set_panels(var/cdir)
|
|
if(powernet)
|
|
for(var/obj/machinery/power/solar/S in powernet.nodes)
|
|
if(S.id == id)
|
|
S.control = src
|
|
|
|
var/delta = dir2angle(S.dir) - dir2angle(cdir)
|
|
|
|
delta = (delta+360)%360
|
|
|
|
if(delta>180)
|
|
S.turn_angle = -45
|
|
else
|
|
S.turn_angle = 45
|
|
|
|
S.ndir = cdir
|
|
|
|
|
|
// Called when area power changes; update icons and stat to reflect state of equipment channel power
|
|
|
|
power_change()
|
|
|
|
if( powered() )
|
|
stat &= ~NOPOWER
|
|
updateicon()
|
|
else
|
|
spawn(rand(0, 15))
|
|
stat |= NOPOWER
|
|
updateicon()
|
|
|
|
|
|
// Set the solar_control as broken
|
|
|
|
proc/broken()
|
|
stat |= BROKEN
|
|
updateicon()
|
|
|
|
|
|
// If hit by a meteor, break
|
|
|
|
meteorhit()
|
|
|
|
broken()
|
|
return
|
|
|
|
|
|
// If in an explosion, delete or chance to break depending on severity
|
|
|
|
ex_act(severity)
|
|
|
|
switch(severity)
|
|
if(1.0)
|
|
del(src)
|
|
return
|
|
if(2.0)
|
|
if (prob(50))
|
|
broken()
|
|
if(3.0)
|
|
if (prob(25))
|
|
broken()
|
|
return
|
|
|
|
// Attack by blob, chance to break
|
|
|
|
blob_act()
|
|
if (prob(50))
|
|
broken()
|
|
src.density = 0
|
|
|