[MIRROR] Minor refactor to space dragon code to fix various bugs and issues (#988)

* Minor refactor to space dragon code to fix various bugs and issues (#53944)

* Minor refactor to space dragon code to fix various bugs and issues

Co-authored-by: Timberpoes <silent_insomnia_pp@hotmail.co.uk>
This commit is contained in:
SkyratBot
2020-09-26 10:41:41 +02:00
committed by GitHub
co-authored by Timberpoes
parent 53887b51f6
commit 4e683e25a2
@@ -1,3 +1,10 @@
/// The carp rift is currently charging.
#define CHARGE_ONGOING 0
/// The carp rift is currently charging and has output a final warning.
#define CHARGE_FINALWARNING 1
/// The carp rift is now fully charged.
#define CHARGE_COMPLETED 2
/**
* # Space Dragon
*
@@ -419,27 +426,39 @@
armor = list(MELEE = 0, BULLET = 0, LASER = 0, ENERGY = 100, BOMB = 50, BIO = 100, RAD = 100, FIRE = 100, ACID = 100)
max_integrity = 300
icon = 'icons/obj/carp_rift.dmi'
icon_state = "carp_rift"
light_color = LIGHT_COLOR_BLUE
icon_state = "carp_rift_carpspawn"
light_color = LIGHT_COLOR_PURPLE
light_range = 10
anchored = TRUE
density = FALSE
layer = MASSIVE_OBJ_LAYER
/// The amount of time the rift has charged for.
var/time_charged = 0
/// The maximum charge the rift can have. It actually goes to max_charge + 1, as to prevent constantly retriggering the effects on full charge.
/// The maximum charge the rift can have.
var/max_charge = 480
/// How many carp spawns it has available.
var/carp_stored = 0
var/carp_stored = 1
/// A reference to the Space Dragon that created it.
var/mob/living/simple_animal/hostile/space_dragon/dragon
/// Current charge state of the rift.
var/charge_state = CHARGE_ONGOING
/// The time since an extra carp was added to the ghost role spawning pool.
var/last_carp_inc = 0
/obj/structure/carp_rift/Initialize(mapload)
. = ..()
carp_stored = 1
time_charged = 1
START_PROCESSING(SSobj, src)
/obj/structure/carp_rift/examine(mob/user)
. = ..()
if(time_charged < max_charge)
. += "<span class='notice'>It seems to be [(time_charged / max_charge) * 100]% charged.</span>"
else
. += "<span class='warning'>This one is fully charged, and is capable of bringing many carp to the station's location.</span>"
if(isobserver(user))
. += "<span class='notice'>It has [carp_stored] carp available to spawn as.</span>"
/obj/structure/carp_rift/play_attack_sound(damage_amount, damage_type = BRUTE, damage_flag = 0)
playsound(src, 'sound/magic/lightningshock.ogg', 50, TRUE)
@@ -454,24 +473,22 @@
return ..()
/obj/structure/carp_rift/process(delta_time)
time_charged = min(time_charged + delta_time, max_charge + 1)
update_check()
// Heal carp on our loc.
for(var/mob/living/simple_animal/hostile/hostilehere in loc)
if("carp" in hostilehere.faction)
hostilehere.adjustHealth(-5 * delta_time)
var/obj/effect/temp_visual/heal/H = new /obj/effect/temp_visual/heal(get_turf(hostilehere))
H.color = "#0000FF"
if(time_charged < max_charge)
desc = "A rift akin to the ones space carp use to travel long distances. It seems to be [(time_charged / max_charge) * 100]% charged."
if(carp_stored == 0)
icon_state = "carp_rift"
light_color = LIGHT_COLOR_BLUE
else
icon_state = "carp_rift_carpspawn"
light_color = LIGHT_COLOR_PURPLE
else
if(DT_PROB(1.25, delta_time))
new /mob/living/simple_animal/hostile/carp(loc)
// If we're fully charged, just start mass spawning carp.
if(charge_state == CHARGE_COMPLETED && DT_PROB(1.25, delta_time))
new /mob/living/simple_animal/hostile/carp(loc)
return
// Increase time trackers and check for any updated states.
time_charged = min(time_charged + delta_time, max_charge)
last_carp_inc += delta_time
update_check()
/obj/structure/carp_rift/attack_ghost(mob/user)
. = ..()
@@ -486,19 +503,29 @@
* If we're fully charged, tell the crew we are, change our color to yellow, become invulnerable, and give Space Dragon the ability to make another rift, if he hasn't summoned 3 total.
*/
/obj/structure/carp_rift/proc/update_check()
if(time_charged % 40 == 0 && time_charged != max_charge)
// If the rift is fully charged, there's nothing to do here anymore.
if(charge_state == CHARGE_COMPLETED)
return
// Can we increase the carp spawn pool size?
if(last_carp_inc >= 40)
carp_stored++
icon_state = "carp_rift_carpspawn"
if(light_color != LIGHT_COLOR_PURPLE)
set_light_color(LIGHT_COLOR_PURPLE)
update_light()
notify_ghosts("The carp rift can summon an additional carp!", source = src, action = NOTIFY_ORBIT, flashwindow = FALSE, header = "Carp Spawn Available")
if(time_charged == (max_charge - 120))
var/area/A = get_area(src)
priority_announce("A rift is causing an unnaturally large energy flux in [initial(A.name)]. Stop it at all costs!", "Central Command Spatial Corps", 'sound/ai/spanomalies.ogg')
if(time_charged == max_charge)
last_carp_inc -= 40
// Is the rift now fully charged?
if(time_charged >= max_charge)
charge_state = CHARGE_COMPLETED
var/area/A = get_area(src)
priority_announce("Spatial object has reached peak energy charge in [initial(A.name)], please stand-by.", "Central Command Spatial Corps")
obj_integrity = INFINITY
desc = "A rift akin to the ones space carp use to travel long distances. This one is fully charged, and is capable of bringing many carp to the station's location."
icon_state = "carp_rift_charged"
light_color = LIGHT_COLOR_YELLOW
set_light_color(LIGHT_COLOR_YELLOW)
update_light()
armor = list(MELEE = 100, BULLET = 100, LASER = 100, ENERGY = 100, BOMB = 100, BIO = 100, RAD = 100, FIRE = 100, ACID = 100)
resistance_flags = INDESTRUCTIBLE
dragon.rifts_charged += 1
@@ -507,6 +534,14 @@
dragon.rift.Grant(dragon)
dragon.riftTimer = 0
dragon.rift_empower(TRUE)
// Early return, nothing to do after this point.
return
// Do we need to give a final warning to the station at the halfway mark?
if(charge_state < CHARGE_FINALWARNING && time_charged >= (max_charge * 0.5))
charge_state = CHARGE_FINALWARNING
var/area/A = get_area(src)
priority_announce("A rift is causing an unnaturally large energy flux in [initial(A.name)]. Stop it at all costs!", "Central Command Spatial Corps", 'sound/ai/spanomalies.ogg')
/**
* Used to create carp controlled by ghosts when the option is available.
@@ -518,12 +553,12 @@
* * mob/user - The ghost which will take control of the carp.
*/
/obj/structure/carp_rift/proc/summon_carp(mob/user)
if(carp_stored == 0)//Not enough carp points
if(carp_stored <= 0)//Not enough carp points
return FALSE
var/carp_ask = alert("Become a carp?", "Help bring forth the horde?", "Yes", "No")
if(carp_ask == "No" || !src || QDELETED(src) || QDELETED(user))
return FALSE
if(carp_stored == 0)
if(carp_stored <= 0)
to_chat(user, "<span class='warning'>The rift already summoned enough carp!</span>")
return FALSE
var/mob/living/simple_animal/hostile/carp/newcarp = new /mob/living/simple_animal/hostile/carp(loc)
@@ -532,5 +567,13 @@
if(S)
S.carp += newcarp.mind
to_chat(newcarp, "<span class='boldwarning'>You have arrived in order to assist the space dragon with securing the rift. Do not jeopardize the mission, and protect the rift at all costs!</span>")
carp_stored -= 1
carp_stored--
if(carp_stored <= 0 && charge_state < CHARGE_COMPLETED)
icon_state = "carp_rift"
set_light_color(LIGHT_COLOR_BLUE)
update_light()
return TRUE
#undef CHARGE_ONGOING
#undef CHARGE_FINALWARNING
#undef CHARGE_COMPLETED