/tg/'s solar code with a fix for the solar control computer not refreshing on user input.

This commit is contained in:
PsiOmega
2014-10-13 17:32:36 +02:00
parent a1ee4e766b
commit f190acf7c5
3 changed files with 240 additions and 227 deletions

View File

@@ -385,11 +385,4 @@
charge = 5000000
..()
/proc/rate_control(var/S, var/V, var/C, var/Min=1, var/Max=5, var/Limit=null)
var/href = "<A href='?src=\ref[S];rate control=1;[V]"
var/rate = "[href]=-[Max]'>-</A>[href]=-[Min]'>-</A> [(C?C : 0)] [href]=[Min]'>+</A>[href]=[Max]'>+</A>"
if(Limit) return "[href]=-[Limit]'>-</A>"+rate+"[href]=[Limit]'>+</A>"
return rate
#undef SMESRATE

View File

@@ -1,20 +1,8 @@
//This file was auto-corrected by findeclaration.exe on 25.5.2012 20:42:33
#define SOLAR_MAX_DIST 40
#define SOLARGENRATE 1500
var/list/solars_list = list()
// This will choose whether to get the solar list from the powernet or the powernet nodes,
// depending on the size of the nodes.
/obj/machinery/power/proc/get_solars_powernet()
if(!powernet)
return list()
if(solars_list.len < powernet.nodes)
return solars_list
else
return powernet.nodes
/obj/machinery/power/solar
name = "solar panel"
desc = "A solar electrical generator."
@@ -29,26 +17,32 @@ var/list/solars_list = list()
var/health = 10
var/obscured = 0
var/sunfrac = 0
var/adir = SOUTH
var/ndir = SOUTH
var/adir = SOUTH // actual dir
var/ndir = SOUTH // target dir
var/turn_angle = 0
var/obj/machinery/power/solar_control/control = null
/obj/machinery/power/solar/New(var/turf/loc, var/obj/item/solar_assembly/S, var/process = 1)
/obj/machinery/power/solar/New(var/turf/loc, var/obj/item/solar_assembly/S)
..(loc)
Make(S)
connect_to_network(process)
connect_to_network()
/obj/machinery/power/solar/disconnect_from_network()
/obj/machinery/power/solar/Del()
unset_control() //remove from control computer
..()
solars_list.Remove(src)
/obj/machinery/power/solar/connect_to_network(var/process)
..()
if(process)
solars_list.Add(src)
//set the control of the panel to a given computer if closer than SOLAR_MAX_DIST
/obj/machinery/power/solar/proc/set_control(var/obj/machinery/power/solar_control/SC)
if(SC && (get_dist(src, SC) > SOLAR_MAX_DIST))
return 0
control = SC
return 1
//set the control of the panel to null and removes it from the control list of the previous control computer if needed
/obj/machinery/power/solar/proc/unset_control()
if(control)
control.connected_panels.Remove(src)
control = null
/obj/machinery/power/solar/proc/Make(var/obj/item/solar_assembly/S)
if(!S)
@@ -56,14 +50,17 @@ var/list/solars_list = list()
S.glass_type = /obj/item/stack/sheet/glass
S.anchored = 1
S.loc = src
if(S.glass_type == /obj/item/stack/sheet/rglass) //if the panel is in reinforced glass
health *= 2 //this need to be placed here, because panels already on the map don't have an assembly linked to
update_icon()
/obj/machinery/power/solar/attackby(obj/item/weapon/W, mob/user)
if(iscrowbar(W))
if(istype(W, /obj/item/weapon/crowbar))
playsound(src.loc, 'sound/machines/click.ogg', 50, 1)
user.visible_message("<span class='notice'>[user] begins to take the glass off the solar panel.</span>")
if(do_after(user, 50))
var/obj/item/solar_assembly/S = locate() in src
if(S)
@@ -71,7 +68,7 @@ var/list/solars_list = list()
S.give_glass()
playsound(src.loc, 'sound/items/Deconstruct.ogg', 50, 1)
user.visible_message("<span class='notice'>[user] takes the glass off the solar panel.</span>")
del(src)
del(src) // qdel
return
else if (W)
src.add_fingerprint(user)
@@ -93,7 +90,7 @@ var/list/solars_list = list()
else
new /obj/item/weapon/shard(src.loc)
new /obj/item/weapon/shard(src.loc)
del(src)
del(src) // qdel
return
return
@@ -108,65 +105,64 @@ var/list/solars_list = list()
src.dir = angle2dir(adir)
return
//calculates the fraction of the sunlight that the panel recieves
/obj/machinery/power/solar/proc/update_solar_exposure()
if(!sun)
return
if(obscured)
sunfrac = 0
return
var/p_angle = abs((360+adir)%360 - (360+sun.angle)%360)
//find the smaller angle between the direction the panel is facing and the direction of the sun (the sign is not important here)
var/p_angle = min(abs(adir - sun.angle), 360 - abs(adir - sun.angle))
if(p_angle > 90) // if facing more than 90deg from sun, zero output
sunfrac = 0
return
sunfrac = cos(p_angle) ** 2
sunfrac = cos(p_angle) ** 2
//isn't the power recieved from the incoming light proportionnal to cos(p_angle) (Lambert's cosine law) rather than cos(p_angle)^2 ?
/obj/machinery/power/solar/process()//TODO: remove/add this from machines to save on processing as needed ~Carn PRIORITY
if(stat & BROKEN) return
if(!control) return
if(stat & BROKEN)
return
if(!sun || !control) //if there's no sun or the panel is not linked to a solar control computer, no need to proceed
return
if(adir != ndir)
adir = (360+adir+dd_range(-10,10,ndir-adir))%360
update_icon()
update_solar_exposure()
if(obscured) return
var/sgen = SOLARGENRATE * sunfrac
add_avail(sgen)
if(powernet && control)
if(powernet.nodes[control])
if(powernet)
if(powernet == control.powernet)//check if the panel is still connected to the computer
if(obscured) //get no light from the sun, so don't generate power
return
var/sgen = SOLARGENRATE * sunfrac
add_avail(sgen)
control.gen += sgen
else //if we're no longer on the same powernet, remove from control computer
unset_control()
/obj/machinery/power/solar/proc/broken()
stat |= BROKEN
unset_control()
update_icon()
return
/obj/machinery/power/solar/meteorhit()
if(stat & !BROKEN)
broken()
else
del(src)
/obj/machinery/power/solar/ex_act(severity)
switch(severity)
if(1.0)
del(src)
if(prob(15))
new /obj/item/weapon/shard( src.loc )
del(src) // qdel
return
if(2.0)
if (prob(25))
new /obj/item/weapon/shard( src.loc )
del(src)
del(src) // qdel
return
if (prob(50))
broken()
if(3.0)
if (prob(25))
broken()
@@ -186,6 +182,29 @@ var/list/solars_list = list()
. = PROCESS_KILL
return
//trace towards sun to see if we're in shadow
/obj/machinery/power/solar/proc/occlusion()
var/ax = x // start at the solar panel
var/ay = y
var/turf/T = null
for(var/i = 1 to 20) // 20 steps is enough
ax += sun.dx // do step
ay += sun.dy
T = locate( round(ax,0.5),round(ay,0.5),z)
if(T.x == 1 || T.x==world.maxx || T.y==1 || T.y==world.maxy) // not obscured if we reach the edge
break
if(T.density) // if we hit a solid turf, panel is obscured
obscured = 1
return
obscured = 0 // if hit the edge or stepped 20 times, not obscured
update_solar_exposure()
//
// Solar Assembly - For construction of solar arrays.
@@ -217,13 +236,13 @@ var/list/solars_list = list()
/obj/item/solar_assembly/attackby(var/obj/item/weapon/W, var/mob/user)
if(!anchored && isturf(loc))
if(iswrench(W))
if(istype(W, /obj/item/weapon/wrench))
anchored = 1
user.visible_message("<span class='notice'>[user] wrenches the solar assembly into place.</span>")
playsound(src.loc, 'sound/items/Ratchet.ogg', 75, 1)
return 1
else
if(iswrench(W))
if(istype(W, /obj/item/weapon/wrench))
anchored = 0
user.visible_message("<span class='notice'>[user] unwrenches the solar assembly from it's place.</span>")
playsound(src.loc, 'sound/items/Ratchet.ogg', 75, 1)
@@ -240,18 +259,19 @@ var/list/solars_list = list()
else
new /obj/machinery/power/solar(get_turf(src), src)
else
user << "<span class='warning'>You need two sheets of glass to put them on the solar assembly.</span>"
user << "<span class='warning'>You need two sheets of glass to put them into a solar panel.</span>"
return
return 1
if(!tracker)
if(istype(W, /obj/item/weapon/tracker_electronics))
tracker = 1
user.drop_item()
del(W)
del(W) // qdel
user.visible_message("<span class='notice'>[user] inserts the electronics into the solar assembly.</span>")
return 1
else
if(iscrowbar(W))
if(istype(W, /obj/item/weapon/crowbar))
new /obj/item/weapon/tracker_electronics(src.loc)
tracker = 0
user.visible_message("<span class='notice'>[user] takes out the electronics from the solar assembly.</span>")
@@ -269,16 +289,18 @@ var/list/solars_list = list()
icon_state = "solar"
anchored = 1
density = 1
idle_power_usage = 5
active_power_usage = 20
use_power = 1
idle_power_usage = 250
var/id = 0
var/cdir = 0
var/targetdir = 0 // target angle in manual tracking (since it updates every game minute)
var/gen = 0
var/lastgen = 0
var/track = 0 // 0=off 1=manual 2=automatic
var/trackrate = 60 // Measured in tenths of degree per minute (i.e. defaults to 6.0 deg/min)
var/trackdir = 1 // -1=CCW, 1=CW
var/nexttime = 0 // Next clock time that manual tracking will move the array
var/track = 0 // 0= off 1=timed 2=auto (tracker)
var/trackrate = 600 // 300-900 seconds
var/nexttime = 0 // time for a panel to rotate of 1<> in manual tracking
var/obj/machinery/power/tracker/connected_tracker = null
var/list/connected_panels = list()
/obj/machinery/power/solar_control/New()
@@ -287,14 +309,55 @@ var/list/solars_list = list()
initialize()
connect_to_network()
/obj/machinery/power/solar_control/Del()
for(var/obj/machinery/power/solar/M in connected_panels)
M.unset_control()
if(connected_tracker)
connected_tracker.unset_control()
..()
/obj/machinery/power/solar_control/disconnect_from_network()
..()
solars_list.Remove(src)
/obj/machinery/power/solar_control/connect_to_network()
..()
var/to_return = ..()
if(powernet) //if connected and not already in solar_list...
solars_list |= src //... add it
return to_return
//search for unconnected panels and trackers in the computer powernet and connect them
/obj/machinery/power/solar_control/proc/search_for_connected()
if(powernet)
solars_list.Add(src)
for(var/obj/machinery/power/M in powernet.nodes)
if(istype(M, /obj/machinery/power/solar))
var/obj/machinery/power/solar/S = M
if(!S.control) //i.e unconnected
S.set_control(src)
connected_panels |= S
else if(istype(M, /obj/machinery/power/tracker))
if(!connected_tracker) //if there's already a tracker connected to the computer don't add another
var/obj/machinery/power/tracker/T = M
if(!T.control) //i.e unconnected
connected_tracker = T
T.set_control(src)
//called by the sun controller, update the facing angle (either manually or via tracking) and rotates the panels accordingly
/obj/machinery/power/solar_control/proc/update()
if(stat & (NOPOWER | BROKEN))
return
switch(track)
if(1)
if(trackrate) //we're manual tracking. If we set a rotation speed...
cdir = targetdir //...the current direction is the targetted one (and rotates panels to it)
if(2) // auto-tracking
if(connected_tracker)
connected_tracker.set_angle(sun.angle)
set_panels(cdir)
updateDialog()
/obj/machinery/power/solar_control/initialize()
..()
@@ -312,22 +375,42 @@ var/list/solars_list = list()
return
icon_state = "solar"
overlays.Cut()
if(cdir > 0)
if(cdir > -1)
overlays += image('icons/obj/computer.dmi', "solcon-o", FLY_LAYER, angle2dir(cdir))
return
/obj/machinery/power/solar_control/attack_ai(mob/user)
add_fingerprint(user)
if(stat & (BROKEN | NOPOWER)) return
interact(user)
/obj/machinery/power/solar_control/attack_hand(mob/user)
add_fingerprint(user)
if(stat & (BROKEN | NOPOWER)) return
interact(user)
if(!..())
interact(user)
/obj/machinery/power/solar_control/interact(mob/user)
var/t = "<B><span class='highlight'>Generated power</span></B> : [round(lastgen)] W<BR>"
t += "<B><span class='highlight'>Orientation</span></B>: [rate_control(src,"cdir","[cdir]&deg",1,15)] ([angle2text(cdir)])<BR>"
t += "<B><span class='highlight'>Tracking:</B><div class='statusDisplay'>"
switch(track)
if(0)
t += "<span class='linkOn'>Off</span> <A href='?src=\ref[src];track=1'>Timed</A> <A href='?src=\ref[src];track=2'>Auto</A><BR>"
if(1)
t += "<A href='?src=\ref[src];track=0'>Off</A> <span class='linkOn'>Timed</span> <A href='?src=\ref[src];track=2'>Auto</A><BR>"
if(2)
t += "<A href='?src=\ref[src];track=0'>Off</A> <A href='?src=\ref[src];track=1'>Timed</A> <span class='linkOn'>Auto</span><BR>"
t += "Tracking Rate: [rate_control(src,"tdir","[trackrate] deg/h ([trackrate<0 ? "CCW" : "CW"])",1,30,180)]</div><BR>"
t += "<B><span class='highlight'>Connected devices:</span></B><div class='statusDisplay'>"
t += "<A href='?src=\ref[src];search_connected=1'>Search for devices</A><BR>"
t += "Solar panels : [connected_panels.len] connected<BR>"
t += "Solar tracker : [connected_tracker ? "<span class='good'>Found</span>" : "<span class='bad'>Not found</span>"]</div><BR>"
t += "<A href='?src=\ref[src];close=1'>Close</A>"
var/datum/browser/popup = new(user, "solar", name)
popup.set_content(t)
popup.open()
return
/obj/machinery/power/solar_control/attackby(I as obj, user as mob)
if(istype(I, /obj/item/weapon/screwdriver))
@@ -344,7 +427,7 @@ var/list/solars_list = list()
A.state = 3
A.icon_state = "3"
A.anchored = 1
del(src)
del(src) // qdel
else
user << "\blue You disconnect the monitor."
var/obj/structure/computerframe/A = new /obj/structure/computerframe( src.loc )
@@ -355,12 +438,11 @@ var/list/solars_list = list()
A.state = 4
A.icon_state = "4"
A.anchored = 1
del(src)
del(src) // qdel
else
src.attack_hand(user)
return
/obj/machinery/power/solar_control/process()
lastgen = gen
gen = 0
@@ -368,130 +450,73 @@ var/list/solars_list = list()
if(stat & (NOPOWER | BROKEN))
return
//use_power(250)
if(track==1 && nexttime < world.time && trackdir*trackrate)
// Increments nexttime using itself and not world.time to prevent drift
nexttime = nexttime + 6000/trackrate
// Nudges array 1 degree in desired direction
cdir = (cdir+trackdir+360)%360
set_panels(cdir)
update_icon()
if(connected_tracker) //NOTE : handled here so that we don't add trackers to the processing list
if(connected_tracker.powernet != powernet)
connected_tracker.unset_control()
src.updateDialog()
// called by solar tracker when sun position changes
/obj/machinery/power/solar_control/proc/tracker_update(var/angle)
if(track != 2 || stat & (NOPOWER | BROKEN))
return
cdir = angle
set_panels(cdir)
update_icon()
src.updateDialog()
/obj/machinery/power/solar_control/interact(mob/user)
if(stat & (BROKEN | NOPOWER)) return
if ( (get_dist(src, user) > 1 ))
if (!istype(user, /mob/living/silicon))
user.unset_machine()
user << browse(null, "window=solcon")
return
add_fingerprint(user)
user.set_machine(src)
var/t = "<TT><B>Solar Generator Control</B><HR><PRE>"
t += "<B>Generated power</B> : [round(lastgen)] W<BR>"
t += "Station Rotational Period: [60/abs(sun.rate)] minutes<BR>"
t += "Station Rotational Direction: [sun.rate<0 ? "CCW" : "CW"]<BR>"
t += "Star Orientation: [sun.angle]&deg ([angle2text(sun.angle)])<BR>"
t += "Array Orientation: [rate_control(src,"cdir","[cdir]&deg",1,10,60)] ([angle2text(cdir)])<BR>"
t += "<BR><HR><BR>"
t += "Tracking: "
switch(track)
if(0)
t += "<B>Off</B> <A href='?src=\ref[src];track=1'>Manual</A> <A href='?src=\ref[src];track=2'>Automatic</A><BR>"
if(1)
t += "<A href='?src=\ref[src];track=0'>Off</A> <B>Manual</B> <A href='?src=\ref[src];track=2'>Automatic</A><BR>"
if(2)
t += "<A href='?src=\ref[src];track=0'>Off</A> <A href='?src=\ref[src];track=1'>Manual</A> <B>Automatic</B><BR>"
t += "Manual Tracking Rate: [rate_control(src,"tdir","[trackrate/10]&deg/min ([trackdir<0 ? "CCW" : "CW"])",1,10)]<BR>"
t += "Manual Tracking Direction: "
switch(trackdir)
if(-1)
t += "<A href='?src=\ref[src];trackdir=1'>CW</A> <B>CCW</B><BR>"
if(1)
t += "<B>CW</B> <A href='?src=\ref[src];trackdir=-1'>CCW</A><BR>"
t += "<A href='?src=\ref[src];close=1'>Close</A></TT>"
user << browse(t, "window=solcon")
onclose(user, "solcon")
return
if(track==1 && trackrate) //manual tracking and set a rotation speed
if(nexttime <= world.time) //every time we need to increase/decrease the angle by 1<>...
targetdir = (targetdir + trackrate/abs(trackrate) + 360) % 360 //... do it
nexttime += 36000/abs(trackrate) //reset the counter for the next 1<>
updateDialog()
/obj/machinery/power/solar_control/Topic(href, href_list)
if(..())
usr << browse(null, "window=solcon")
usr.unset_machine()
return
return 0
if(href_list["close"] )
usr << browse(null, "window=solcon")
usr.unset_machine()
return
if(href_list["dir"])
cdir = text2num(href_list["dir"])
set_panels(cdir)
update_icon()
return 0
if(href_list["rate control"])
if(href_list["cdir"])
src.cdir = dd_range(0,359,(360+src.cdir+text2num(href_list["cdir"]))%360)
src.targetdir = src.cdir
if(track == 2) //manual update, so losing auto-tracking
track = 0
spawn(1)
set_panels(cdir)
update_icon()
if(href_list["tdir"])
src.trackrate = dd_range(0,360,src.trackrate+text2num(href_list["tdir"]))
if(src.trackrate) nexttime = world.time + 6000/trackrate
src.trackrate = dd_range(-7200,7200,src.trackrate+text2num(href_list["tdir"]))
if(src.trackrate) nexttime = world.time + 36000/abs(trackrate)
if(href_list["track"])
if(src.trackrate) nexttime = world.time + 6000/trackrate
track = text2num(href_list["track"])
if(powernet && (track == 2))
if(!solars_list.Find(src,1,0))
solars_list.Add(src)
for(var/obj/machinery/power/tracker/T in get_solars_powernet())
if(powernet.nodes[T])
cdir = T.sun_angle
break
if(track == 2)
if(connected_tracker)
connected_tracker.set_angle(sun.angle)
set_panels(cdir)
else if (track == 1) //begin manual tracking
src.targetdir = src.cdir
if(src.trackrate) nexttime = world.time + 36000/abs(trackrate)
set_panels(targetdir)
if(href_list["trackdir"])
trackdir = text2num(href_list["trackdir"])
set_panels(cdir)
update_icon()
src.updateUsrDialog()
return
if(href_list["search_connected"])
src.search_for_connected()
if(connected_tracker && track == 2)
connected_tracker.set_angle(sun.angle)
src.set_panels(cdir)
interact(usr)
return 1
//rotates the panel to the passed angle
/obj/machinery/power/solar_control/proc/set_panels(var/cdir)
if(!powernet) return
for(var/obj/machinery/power/solar/S in get_solars_powernet())
if(powernet.nodes[S])
if(get_dist(S, src) < SOLAR_MAX_DIST)
if(!S.control)
S.control = src
S.ndir = cdir
for(var/obj/machinery/power/solar/S in connected_panels)
S.adir = cdir //instantly rotates the panel
S.occlusion()//and
S.update_icon() //update it
update_icon()
/obj/machinery/power/solar_control/power_change()
..()
if(!(stat & NOPOWER))
update_icon()
else
spawn(rand(0, 15))
update_icon()
update_icon()
/obj/machinery/power/solar_control/proc/broken()
@@ -499,16 +524,11 @@ var/list/solars_list = list()
update_icon()
/obj/machinery/power/solar_control/meteorhit()
broken()
return
/obj/machinery/power/solar_control/ex_act(severity)
switch(severity)
if(1.0)
//SN src = null
del(src)
del(src) // qdel
return
if(2.0)
if (prob(50))
@@ -531,4 +551,10 @@ var/list/solars_list = list()
/obj/item/weapon/paper/solar
name = "paper- 'Going green! Setup your own solar array instructions.'"
info = "<h1>Welcome</h1><p>At greencorps we love the environment, and space. With this package you are able to help mother nature and produce energy without any usage of fossil fuel or phoron! Singularity energy is dangerous while solar energy is safe, which is why it's better. Now here is how you setup your own solar array.</p><p>You can make a solar panel by wrenching the solar assembly onto a cable node. Adding a glass panel, reinforced or regular glass will do, will finish the construction of your solar panel. It is that easy!.</p><p>Now after setting up 19 more of these solar panels you will want to create a solar tracker to keep track of our mother nature's gift, the sun. These are the same steps as before except you insert the tracker equipment circuit into the assembly before performing the final step of adding the glass. You now have a tracker! Now the last step is to add a computer to calculate the sun's movements and to send commands to the solar panels to change direction with the sun. Setting up the solar computer is the same as setting up any computer, so you should have no trouble in doing that. You do need to put a wire node under the computer, and the wire needs to be connected to the tracker.</p><p>Congratulations, you should have a working solar array. If you are having trouble, here are some tips. Make sure all solar equipment are on a cable node, even the computer. You can always deconstruct your creations if you make a mistake.</p><p>That's all to it, be safe, be green!</p>"
info = "<h1>Welcome</h1><p>At greencorps we love the environment, and space. With this package you are able to help mother nature and produce energy without any usage of fossil fuel or plasma! Singularity energy is dangerous while solar energy is safe, which is why it's better. Now here is how you setup your own solar array.</p><p>You can make a solar panel by wrenching the solar assembly onto a cable node. Adding a glass panel, reinforced or regular glass will do, will finish the construction of your solar panel. It is that easy!.</p><p>Now after setting up 19 more of these solar panels you will want to create a solar tracker to keep track of our mother nature's gift, the sun. These are the same steps as before except you insert the tracker equipment circuit into the assembly before performing the final step of adding the glass. You now have a tracker! Now the last step is to add a computer to calculate the sun's movements and to send commands to the solar panels to change direction with the sun. Setting up the solar computer is the same as setting up any computer, so you should have no trouble in doing that. You do need to put a wire node under the computer, and the wire needs to be connected to the tracker.</p><p>Congratulations, you should have a working solar array. If you are having trouble, here are some tips. Make sure all solar equipment are on a cable node, even the computer. You can always deconstruct your creations if you make a mistake.</p><p>That's all to it, be safe, be green!</p>"
/proc/rate_control(var/S, var/V, var/C, var/Min=1, var/Max=5, var/Limit=null) //How not to name vars
var/href = "<A href='?src=\ref[S];rate control=1;[V]"
var/rate = "[href]=-[Max]'>-</A>[href]=-[Min]'>-</A> [(C?C : 0)] [href]=[Min]'>+</A>[href]=[Max]'>+</A>"
if(Limit) return "[href]=-[Limit]'>-</A>"+rate+"[href]=[Limit]'>+</A>"
return rate

View File

@@ -10,54 +10,58 @@
icon_state = "tracker"
anchored = 1
density = 1
use_power = 0 // doesn't use APC power
var/power_usage = 500 //W
use_power = 0
var/id = 0
var/sun_angle = 0 // sun angle as set by sun datum
var/obj/machinery/power/solar_control/control = null
/obj/machinery/power/tracker/New(var/turf/loc, var/obj/item/solar_assembly/S)
..(loc)
Make(S)
connect_to_network()
/obj/machinery/power/tracker/Del()
unset_control() //remove from control computer
..()
//set the control of the tracker to a given computer if closer than SOLAR_MAX_DIST
/obj/machinery/power/tracker/proc/set_control(var/obj/machinery/power/solar_control/SC)
if(SC && (get_dist(src, SC) > SOLAR_MAX_DIST))
return 0
control = SC
return 1
//set the control of the tracker to null and removes it from the previous control computer if needed
/obj/machinery/power/tracker/proc/unset_control()
if(control)
control.connected_tracker = null
control = null
/obj/machinery/power/tracker/proc/Make(var/obj/item/solar_assembly/S)
if(!S)
S = new /obj/item/solar_assembly(src)
S.glass_type = /obj/item/stack/sheet/glass
S.tracker = 1
S.anchored = 1
S.loc = src
connect_to_network()
update_icon()
/obj/machinery/power/tracker/disconnect_from_network()
..()
solars_list.Remove(src)
/obj/machinery/power/tracker/connect_to_network()
..()
solars_list.Add(src)
// called by datum/sun/calc_position() as sun's angle changes
//updates the tracker icon and the facing angle for the control computer
/obj/machinery/power/tracker/proc/set_angle(var/angle)
sun_angle = angle
//set icon dir to show sun illumination
dir = turn(NORTH, -angle - 22.5) // 22.5 deg bias ensures, e.g. 67.5-112.5 is EAST
// check we can draw power
if(stat & NOPOWER)
return
// find all solar controls and update them
// currently, just update all controllers in world
// ***TODO: better communication system using network
if(powernet)
for(var/obj/machinery/power/solar_control/C in get_solars_powernet())
if(powernet.nodes[C])
if(get_dist(C, src) < SOLAR_MAX_DIST)
C.tracker_update(angle)
if(powernet && (powernet == control.powernet)) //update if we're still in the same powernet
control.cdir = angle
/obj/machinery/power/tracker/attackby(var/obj/item/weapon/W, var/mob/user)
if(iscrowbar(W))
if(istype(W, /obj/item/weapon/crowbar))
playsound(src.loc, 'sound/machines/click.ogg', 50, 1)
user.visible_message("<span class='notice'>[user] begins to take the glass off the solar tracker.</span>")
if(do_after(user, 50))
var/obj/item/solar_assembly/S = locate() in src
if(S)
@@ -65,20 +69,10 @@
S.give_glass()
playsound(src.loc, 'sound/items/Deconstruct.ogg', 50, 1)
user.visible_message("<span class='notice'>[user] takes the glass off the tracker.</span>")
del(src)
del(src) // qdel
return
..()
// timed process
// make sure we can draw power from the powernet
/obj/machinery/power/tracker/process()
if(surplus() >= power_usage && add_load(power_usage) >= power_usage)
stat &= ~NOPOWER
else
stat |= NOPOWER
// Tracker Electronic
/obj/item/weapon/tracker_electronics
@@ -86,4 +80,4 @@
name = "tracker electronics"
icon = 'icons/obj/doors/door_assembly.dmi'
icon_state = "door_electronics"
w_class = 2.0
w_class = 2.0