mech equipment fix/cleanup (#64921)

mech equipment topic calls parent
autodoc
equip_ready renamed to activated as it is more fitting
removed salvagable as it was with one exception just doing what detachable did anyway
removed some stuff like src.vars
This commit is contained in:
TiviPlus
2022-03-12 11:18:24 +01:00
committed by GitHub
parent 952437a261
commit fbe88da912
7 changed files with 117 additions and 93 deletions
@@ -1,38 +1,47 @@
//DO NOT ADD MECHA PARTS TO THE GAME WITH THE DEFAULT "SPRITE ME" SPRITE!
//I'm annoyed I even have to tell you this! SPRITE FIRST, then commit.
/**
* Mecha Equipment
* All mech equippables are currently childs of this
*/
/obj/item/mecha_parts/mecha_equipment
name = "mecha equipment"
icon = 'icons/mecha/mecha_equipment.dmi'
icon_state = "mecha_equip"
force = 5
max_integrity = 300
///Cooldown in ticks required between activations of the equipment
var/equip_cooldown = 0
var/equip_ready = TRUE //whether the equipment is ready for use. (or deactivated/activated for static stuff)
///used for equipment that can be turned on/off, boolean
var/activated = TRUE
///Chassis power cell quantity used on activation
var/energy_drain = 0
var/obj/vehicle/sealed/mecha/chassis = null
///Reference to mecha that this equipment is currently attached to
var/obj/vehicle/sealed/mecha/chassis
///Bitflag. Determines the range of the equipment.
var/range = MECHA_MELEE
/// Bitflag. Used by exosuit fabricator to assign sub-categories based on which exosuits can equip this.
var/mech_flags = NONE
var/salvageable = 1
var/detachable = TRUE // Set to FALSE for built-in equipment that cannot be removed
var/selectable = 1 // Set to 0 for passive equipment such as mining scanner or armor plates
var/harmful = FALSE //Controls if equipment can be used to attack by a pacifist.
///boolean: FALSE if this equipment can not be removed/salvaged
var/detachable = TRUE
///Boolean: whether we can equip this equipment through the mech UI or the cycling ability
var/selectable = TRUE
///Boolean: whether a pacifist can use this equipment
var/harmful = FALSE
///Sound file: Sound to play when this equipment is destroyed while still attached to the mech
var/destroy_sound = 'sound/mecha/critdestr.ogg'
///Updates chassis equipment list html menu
/obj/item/mecha_parts/mecha_equipment/proc/update_chassis_page()
if(chassis)
send_byjax(chassis.occupants,"exosuit.browser","eq_list",chassis.get_equipment_list())
send_byjax(chassis.occupants,"exosuit.browser","equipment_menu",chassis.get_equipment_menu(),"dropdowns")
return TRUE
return
SHOULD_CALL_PARENT(TRUE)
send_byjax(chassis.occupants,"exosuit.browser","eq_list", chassis.get_equipment_list())
send_byjax(chassis.occupants,"exosuit.browser","equipment_menu", chassis.get_equipment_menu(),"dropdowns")
return TRUE
///Updates chassis equipment list html menu with custom data
/obj/item/mecha_parts/mecha_equipment/proc/update_equip_info()
if(chassis)
send_byjax(chassis.occupants,"exosuit.browser","[REF(src)]",get_equip_info())
return TRUE
return
if(!chassis)
return
send_byjax(chassis.occupants,"exosuit.browser","[REF(src)]",get_equip_info())
return TRUE
/obj/item/mecha_parts/mecha_equipment/Destroy()
if(chassis)
@@ -49,35 +58,42 @@
chassis = null
return ..()
/obj/item/mecha_parts/mecha_equipment/try_attach_part(mob/user, obj/vehicle/sealed/mecha/M)
if(can_attach(M))
if(!user.temporarilyRemoveItemFromInventory(src))
return FALSE
attach(M)
user.visible_message(span_notice("[user] attaches [src] to [M]."), span_notice("You attach [src] to [M]."))
return TRUE
to_chat(user, span_warning("You are unable to attach [src] to [M]!"))
return FALSE
/obj/item/mecha_parts/mecha_equipment/try_attach_part(mob/user, obj/vehicle/sealed/mecha/mech)
if(!can_attach(mech))
to_chat(user, span_warning("You are unable to attach [src] to [mech]!"))
return FALSE
if(!user.temporarilyRemoveItemFromInventory(src))
return FALSE
attach(mech)
user.visible_message(span_notice("[user] attaches [src] to [mech]."), span_notice("You attach [src] to [mech]."))
return TRUE
///fetches and returns a html formatted string with equippability status
/obj/item/mecha_parts/mecha_equipment/proc/get_equip_info()
if(!chassis)
return
var/txt = "<span style=\"color:[equip_ready?"#0f0":"#f00"];\">*</span>&nbsp;"
var/txt = "<span style=\"color:[activated?"#0f0":"#f00"];\">*</span>&nbsp;"
if(chassis.selected == src)
txt += "<b>[src.name]</b>"
txt += "<b>[src]</b>"
else if(selectable)
txt += "<a href='?src=[REF(chassis)];select_equip=[REF(src)]'>[src.name]</a>"
txt += "<a href='?src=[REF(chassis)];select_equip=[REF(src)]'>[src]</a>"
else
txt += "[src.name]"
txt += "[src]"
return txt
/**
* Checks whether this mecha equipment can be activated
* Returns a bool
* Arguments:
* * target: atom we are activating/clicked on
*/
/obj/item/mecha_parts/mecha_equipment/proc/action_checks(atom/target)
if(!target)
return FALSE
if(!chassis)
return FALSE
if(!equip_ready)
if(!activated)
return FALSE
if(energy_drain && !chassis.has_charge(energy_drain))
return FALSE
@@ -92,67 +108,78 @@
/obj/item/mecha_parts/mecha_equipment/proc/action(mob/source, atom/target, list/modifiers)
TIMER_COOLDOWN_START(chassis, COOLDOWN_MECHA_EQUIPMENT, equip_cooldown)//Cooldown is on the MECH so people dont bypass it by switching equipment
send_byjax(chassis.occupants,"exosuit.browser","[REF(src)]",src.get_equip_info())
send_byjax(chassis.occupants,"exosuit.browser","[REF(src)]", get_equip_info())
chassis.use_power(energy_drain)
return TRUE
/**
* Cooldown proc variant for using do_afters between activations instead of timers
* Example of usage is mech drills, rcds
* arguments:
* * target: targetted atom for action activation
* * user: occupant to display do after for
* * interaction_key: interaction key to pass to [/proc/do_after]
*/
/obj/item/mecha_parts/mecha_equipment/proc/do_after_cooldown(atom/target, mob/user, interaction_key)
if(!chassis)
return
var/C = chassis.loc
chassis.use_power(energy_drain)
. = do_after(user, equip_cooldown, target=target, interaction_key = interaction_key)
if(!chassis || chassis.loc != C || src != chassis.selected || !(get_dir(chassis, target)&chassis.dir))
if(!chassis || src != chassis.selected || !(get_dir(chassis, target) & chassis.dir))
return FALSE
///Do after wrapper for mecha equipment
/obj/item/mecha_parts/mecha_equipment/proc/do_after_mecha(atom/target, mob/user, delay)
if(!chassis)
return
var/C = chassis.loc
. = do_after(user, delay, target=target)
if(!chassis || chassis.loc != C || src != chassis.selected || !(get_dir(chassis, target)&chassis.dir))
if(!chassis || src != chassis.selected || !(get_dir(chassis, target) & chassis.dir))
return FALSE
///Returns TRUE if equipment should be allowed to attach to the targetted necha
/obj/item/mecha_parts/mecha_equipment/proc/can_attach(obj/vehicle/sealed/mecha/M)
if(LAZYLEN(M.equipment)<M.max_equip)
return TRUE
return FALSE
return LAZYLEN(M.equipment) < M.max_equip
///Attaches equipment and updates relevant equipment trackers
/obj/item/mecha_parts/mecha_equipment/proc/attach(obj/vehicle/sealed/mecha/M)
LAZYADD(M.equipment, src)
chassis = M
forceMove(M)
log_message("[src] initialized.", LOG_MECHA)
log_message("[src] attached.", LOG_MECHA)
update_chassis_page()
return
/obj/item/mecha_parts/mecha_equipment/proc/detach(atom/moveto=null)
///Detaches equipment and updates relevant equipment trackers. Optional argument of atom to forcemove to once detached
/obj/item/mecha_parts/mecha_equipment/proc/detach(atom/moveto)
SHOULD_CALL_PARENT(TRUE)
moveto = moveto || get_turf(chassis)
if(src.Move(moveto))
LAZYREMOVE(chassis.equipment, src)
if(chassis.selected == src)
chassis.selected = null
update_chassis_page()
log_message("[src] removed from equipment.", LOG_MECHA)
chassis = null
return
forceMove(moveto)
LAZYREMOVE(chassis.equipment, src)
if(chassis.selected == src)
chassis.selected = null
update_chassis_page()
log_message("[src] removed from equipment.", LOG_MECHA)
chassis = null
/obj/item/mecha_parts/mecha_equipment/Topic(href,href_list)
. = ..()
if(.)
return
if(href_list["detach"])
detach()
/obj/item/mecha_parts/mecha_equipment/log_message(message, message_type=LOG_GAME, color=null, log_globally)
if(chassis)
chassis.log_message("ATTACHMENT: [src] [message]", message_type, color)
else
..()
return chassis.log_message("ATTACHMENT: [src] [message]", message_type, color)
return ..()
//Used for reloading weapons/tools etc. that use some form of resource
/**
* Proc for reloading weapons from HTML UI or by AI
* note that this is old and likely broken code
*/
/obj/item/mecha_parts/mecha_equipment/proc/rearm()
return FALSE
/// AI mech pilot: returns TRUE if the Ai should try to reload the mecha
/obj/item/mecha_parts/mecha_equipment/proc/needs_rearm()
return FALSE
@@ -37,7 +37,6 @@
energy_drain = 20
range = MECHA_MELEE
equip_cooldown = 20
salvageable = FALSE
var/mob/living/carbon/patient = null
var/inject_amount = 10
@@ -219,25 +219,26 @@
return ..()
/obj/item/mecha_parts/mecha_equipment/repair_droid/get_equip_info()
return "<span style=\"color:[equip_ready?"#0f0":"#f00"];\">*</span>&nbsp; [name] - <a href='?src=[REF(src)];toggle_repairs=1'>[equip_ready?"Deactivate":"Activate"]</a>"
return "<span style=\"color:[activated?"#0f0":"#f00"];\">*</span>&nbsp; [src] - <a href='?src=[REF(src)];toggle_repairs=1'>[activated?"Deactivate":"Activate"]</a>"
/obj/item/mecha_parts/mecha_equipment/repair_droid/Topic(href, href_list)
..()
if(href_list["toggle_repairs"])
chassis.cut_overlay(droid_overlay)
equip_ready = !equip_ready //now set to FALSE and active, so update the UI
update_equip_info()
if(equip_ready)
START_PROCESSING(SSobj, src)
droid_overlay = new(src.icon, icon_state = "repair_droid_a")
log_message("Activated.", LOG_MECHA)
else
STOP_PROCESSING(SSobj, src)
droid_overlay = new(src.icon, icon_state = "repair_droid")
log_message("Deactivated.", LOG_MECHA)
chassis.add_overlay(droid_overlay)
send_byjax(chassis.occupants,"exosuit.browser", "[REF(src)]", get_equip_info())
if(!href_list["toggle_repairs"])
return
chassis.cut_overlay(droid_overlay)
activated = !activated //now set to FALSE and active, so update the UI
update_equip_info()
if(activated)
START_PROCESSING(SSobj, src)
droid_overlay = new(icon, icon_state = "repair_droid_a")
log_message("Activated.", LOG_MECHA)
else
STOP_PROCESSING(SSobj, src)
droid_overlay = new(icon, icon_state = "repair_droid")
log_message("Deactivated.", LOG_MECHA)
chassis.add_overlay(droid_overlay)
send_byjax(chassis.occupants,"exosuit.browser", "[REF(src)]", get_equip_info())
/obj/item/mecha_parts/mecha_equipment/repair_droid/process(delta_time)
@@ -290,7 +291,7 @@
return ..()
/obj/item/mecha_parts/mecha_equipment/tesla_energy_relay/proc/get_charge()
if(equip_ready) //disabled
if(activated) //disabled
return
var/pow_chan = get_chassis_area_power(get_area(chassis))
if(pow_chan)
@@ -311,9 +312,9 @@
/obj/item/mecha_parts/mecha_equipment/tesla_energy_relay/Topic(href, href_list)
..()
if(href_list["toggle_relay"])
equip_ready = !equip_ready //now set to FALSE and active, so update the UI
activated = !activated //now set to FALSE and active, so update the UI
update_equip_info()
if(equip_ready) //inactive
if(activated) //inactive
START_PROCESSING(SSobj, src)
log_message("Activated.", LOG_MECHA)
else
@@ -323,7 +324,7 @@
/obj/item/mecha_parts/mecha_equipment/tesla_energy_relay/get_equip_info()
if(!chassis)
return
return "<span style=\"color:[equip_ready?"#0f0":"#f00"];\">*</span>&nbsp; [src.name] - <a href='?src=[REF(src)];toggle_relay=1'>[equip_ready?"Deactivate":"Activate"]</a>"
return "<span style=\"color:[activated?"#0f0":"#f00"];\">*</span>&nbsp; [src.name] - <a href='?src=[REF(src)];toggle_relay=1'>[activated?"Deactivate":"Activate"]</a>"
/obj/item/mecha_parts/mecha_equipment/tesla_energy_relay/process(delta_time)
@@ -381,9 +382,9 @@
/obj/item/mecha_parts/mecha_equipment/generator/Topic(href, href_list)
..()
if(href_list["toggle"])
equip_ready = !equip_ready //now set to FALSE and active, so update the UI
activated = !activated //now set to FALSE and active, so update the UI
update_equip_info()
if(equip_ready) //inactive
if(activated) //inactive
START_PROCESSING(SSobj, src)
log_message("Activated.", LOG_MECHA)
else
@@ -393,7 +394,7 @@
/obj/item/mecha_parts/mecha_equipment/generator/get_equip_info()
var/output = ..()
if(output)
return "[output] \[[fuel]: [round(fuel.amount*MINERAL_MATERIAL_AMOUNT,0.1)] cm<sup>3</sup>\] - <a href='?src=[REF(src)];toggle=1'>[equip_ready?"Deactivate":"Activate"]</a>"
return "[output] \[[fuel]: [round(fuel.amount*MINERAL_MATERIAL_AMOUNT,0.1)] cm<sup>3</sup>\] - <a href='?src=[REF(src)];toggle=1'>[activated?"Deactivate":"Activate"]</a>"
/obj/item/mecha_parts/mecha_equipment/generator/action(mob/source, atom/movable/target, list/modifiers)
if(!chassis)
@@ -473,9 +474,9 @@
/obj/item/mecha_parts/mecha_equipment/thrusters/Topic(href,href_list)
..()
if(href_list["toggle"])
equip_ready = !equip_ready //now set to FALSE and active, so update the UI
activated = !activated //now set to FALSE and active, so update the UI
update_equip_info()
if(equip_ready) //inactive
if(activated) //inactive
START_PROCESSING(SSobj, src)
enable()
log_message("Activated.", LOG_MECHA)
@@ -499,7 +500,7 @@
/obj/item/mecha_parts/mecha_equipment/thrusters/get_equip_info()
var/output = ..()
if(output)
return "[output] <a href='?src=[REF(src)];toggle=1'>[equip_ready?"Deactivate":"Activate"]</a>"
return "[output] <a href='?src=[REF(src)];toggle=1'>[activated?"Deactivate":"Activate"]</a>"
/obj/item/mecha_parts/mecha_equipment/thrusters/proc/thrust(movement_dir)
if(!chassis)
@@ -544,7 +545,6 @@
name = "Ion thruster package"
desc = "A set of thrusters that allow for exosuit movement in zero-gravity environments."
detachable = FALSE
salvageable = FALSE
effect_type = /obj/effect/particle_effect/ion_trails
/obj/item/mecha_parts/mecha_equipment/thrusters/ion/thrust(movement_dir)
@@ -121,7 +121,7 @@
return
playsound(src, get_dismember_sound(), 80, TRUE)
target.visible_message(span_danger("[chassis] rips [target]'s arms off!"), \
span_userdanger("[chassis] rips your arms off!"))
span_userdanger("[chassis] rips your arms off!"))
log_combat(source, M, "removed both arms with a real clamp,", "[name]", "(COMBAT MODE: [uppertext(source.combat_mode)] (DAMTYPE: [uppertext(damtype)])")
return ..()
@@ -232,7 +232,7 @@
return TRUE
/obj/item/mecha_parts/mecha_equipment/weapon/ballistic/get_equip_info()
return "[..()] \[[src.projectiles][projectiles_cache_max &&!projectile_energy_cost?"/[projectiles_cache]":""]\][!disabledreload &&(src.projectiles < initial(src.projectiles))?" - <a href='?src=[REF(src)];rearm=1'>Rearm</a>":null]"
return "[..()] \[[projectiles][projectiles_cache_max &&!projectile_energy_cost?"/[projectiles_cache]":""]\][!disabledreload &&(src.projectiles < initial(src.projectiles))?" - <a href='?src=[REF(src)];rearm=1'>Rearm</a>":null]"
/obj/item/mecha_parts/mecha_equipment/weapon/ballistic/rearm()
@@ -256,20 +256,19 @@
projectiles_cache = 0
send_byjax(chassis.occupants,"exosuit.browser","[REF(src)]",src.get_equip_info())
log_message("Rearmed [src.name].", LOG_MECHA)
log_message("Rearmed [src].", LOG_MECHA)
return TRUE
/obj/item/mecha_parts/mecha_equipment/weapon/ballistic/needs_rearm()
. = !(projectiles > 0)
return projectiles <= 0
/obj/item/mecha_parts/mecha_equipment/weapon/ballistic/Topic(href, href_list)
..()
if (href_list["rearm"])
src.rearm()
return
rearm()
/obj/item/mecha_parts/mecha_equipment/weapon/ballistic/action(mob/source, atom/target, list/modifiers)
if(..())
+2 -2
View File
@@ -363,10 +363,10 @@
AI = crew
var/obj/structure/mecha_wreckage/WR = new wreckage(loc, AI)
for(var/obj/item/mecha_parts/mecha_equipment/E in equipment)
if(E.salvageable && prob(30))
if(E.detachable && prob(30))
WR.crowbar_salvage += E
E.detach(WR) //detaches from src into WR
E.equip_ready = 1
E.activated = TRUE
else
E.detach(loc)
qdel(E)
@@ -42,7 +42,6 @@
icon_state = "bin"
selectable = FALSE
detachable = FALSE
salvageable = FALSE
/// Var to avoid istype checking every time the topic button is pressed. This will only work inside Clarke mechs.
var/obj/vehicle/sealed/mecha/working/clarke/hostmech