Merge pull request #14306 from Putnam3145/supernova
Adds a supernova event, with tweaks to allow this
This commit is contained in:
+23
-37
@@ -1,5 +1,4 @@
|
||||
#define SOLAR_GEN_RATE 1500
|
||||
#define OCCLUSION_DISTANCE 20
|
||||
|
||||
/obj/machinery/power/solar
|
||||
name = "solar panel"
|
||||
@@ -14,8 +13,8 @@
|
||||
integrity_failure = 0.33
|
||||
|
||||
var/id
|
||||
var/obscured = FALSE
|
||||
var/sunfrac = 0 //[0-1] measure of obscuration -- multipllier against power generation
|
||||
var/list/obscured = list()
|
||||
var/total_flux = 0 // multipllier against power generation -- measured by obscuration of all suns
|
||||
var/azimuth_current = 0 //[0-360) degrees, which direction are we facing?
|
||||
var/azimuth_target = 0 //same but what way we're going to face next time we turn
|
||||
var/obj/machinery/power/solar_control/control
|
||||
@@ -133,40 +132,28 @@
|
||||
|
||||
///trace towards sun to see if we're in shadow
|
||||
/obj/machinery/power/solar/proc/occlusion_setup()
|
||||
obscured = TRUE
|
||||
|
||||
var/distance = OCCLUSION_DISTANCE
|
||||
var/target_x = round(sin(SSsun.azimuth), 0.01)
|
||||
var/target_y = round(cos(SSsun.azimuth), 0.01)
|
||||
var/x_hit = x
|
||||
var/y_hit = y
|
||||
var/turf/hit
|
||||
|
||||
for(var/run in 1 to distance)
|
||||
x_hit += target_x
|
||||
y_hit += target_y
|
||||
hit = locate(round(x_hit, 1), round(y_hit, 1), z)
|
||||
if(hit.opacity)
|
||||
return
|
||||
if(hit.x == 1 || hit.x == world.maxx || hit.y == 1 || hit.y == world.maxy) //edge of the map
|
||||
break
|
||||
obscured = FALSE
|
||||
obscured = list()
|
||||
for(var/S in SSsun.suns)
|
||||
if(check_obscured(S))
|
||||
obscured |= S
|
||||
|
||||
///calculates the fraction of the sunlight that the panel receives
|
||||
/obj/machinery/power/solar/proc/update_solar_exposure()
|
||||
needs_to_update_solar_exposure = FALSE
|
||||
sunfrac = 0
|
||||
if(obscured)
|
||||
return 0
|
||||
|
||||
var/sun_azimuth = SSsun.azimuth
|
||||
if(azimuth_current == sun_azimuth) //just a quick optimization for the most frequent case
|
||||
. = 1
|
||||
else
|
||||
//dot product of sun and panel -- Lambert's Cosine Law
|
||||
. = cos(azimuth_current - sun_azimuth)
|
||||
. = clamp(round(., 0.01), 0, 1)
|
||||
sunfrac = .
|
||||
total_flux = 0
|
||||
for(var/S in SSsun.suns)
|
||||
if(S in obscured)
|
||||
continue
|
||||
var/datum/sun/sun = S
|
||||
var/sun_azimuth = sun.azimuth
|
||||
var/cur_pow = 0
|
||||
if(azimuth_current == sun_azimuth) //just a quick optimization for the most frequent case
|
||||
cur_pow = sun.power_mod
|
||||
else
|
||||
//dot product of sun and panel -- Lambert's Cosine Law
|
||||
cur_pow = cos(azimuth_current - sun_azimuth) * sun.power_mod
|
||||
cur_pow = clamp(round(cur_pow, 0.01), 0, 1)
|
||||
total_flux += cur_pow
|
||||
|
||||
/obj/machinery/power/solar/process()
|
||||
if(stat & BROKEN)
|
||||
@@ -177,10 +164,10 @@
|
||||
update_turn()
|
||||
if(needs_to_update_solar_exposure)
|
||||
update_solar_exposure()
|
||||
if(sunfrac <= 0)
|
||||
if(total_flux <= 0)
|
||||
return
|
||||
|
||||
var/sgen = SOLAR_GEN_RATE * sunfrac * efficiency
|
||||
var/sgen = SOLAR_GEN_RATE * total_flux * efficiency
|
||||
add_avail(sgen)
|
||||
if(control)
|
||||
control.gen += sgen
|
||||
@@ -385,7 +372,7 @@
|
||||
track = mode
|
||||
if(mode == SOLAR_TRACK_AUTO)
|
||||
if(connected_tracker)
|
||||
connected_tracker.sun_update(SSsun, SSsun.azimuth)
|
||||
connected_tracker.sun_update(SSsun, SSsun.primary_sun, SSsun.suns)
|
||||
else
|
||||
track = SOLAR_TRACK_OFF
|
||||
return TRUE
|
||||
@@ -483,4 +470,3 @@ Congratulations, you should have a working solar array. If you are having troubl
|
||||
"}
|
||||
|
||||
#undef SOLAR_GEN_RATE
|
||||
#undef OCCLUSION_DISTANCE
|
||||
|
||||
@@ -41,10 +41,10 @@
|
||||
control = null
|
||||
|
||||
///Tell the controller to turn the solar panels
|
||||
/obj/machinery/power/tracker/proc/sun_update(datum/source, azimuth)
|
||||
setDir(angle2dir(azimuth))
|
||||
/obj/machinery/power/tracker/proc/sun_update(datum/source, datum/sun/primary_sun, list/datum/sun/suns)
|
||||
setDir(angle2dir(primary_sun.azimuth))
|
||||
if(control && control.track == SOLAR_TRACK_AUTO)
|
||||
control.set_panels(azimuth)
|
||||
control.set_panels(primary_sun.azimuth)
|
||||
|
||||
/obj/machinery/power/tracker/proc/Make(obj/item/solar_assembly/S)
|
||||
if(!S)
|
||||
|
||||
Reference in New Issue
Block a user