From fbe88da9121dfee7e2704d9e997f2d0472bc3bcc Mon Sep 17 00:00:00 2001
From: TiviPlus <57223640+TiviPlus@users.noreply.github.com>
Date: Sat, 12 Mar 2022 11:18:24 +0100
Subject: [PATCH] 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
---
.../mecha/equipment/mecha_equipment.dm | 141 +++++++++++-------
.../mecha/equipment/tools/medical_tools.dm | 1 -
.../mecha/equipment/tools/other_tools.dm | 52 +++----
.../mecha/equipment/tools/work_tools.dm | 2 +-
.../mecha/equipment/weapons/weapons.dm | 9 +-
code/modules/vehicles/mecha/mecha_defense.dm | 4 +-
code/modules/vehicles/mecha/working/clarke.dm | 1 -
7 files changed, 117 insertions(+), 93 deletions(-)
diff --git a/code/modules/vehicles/mecha/equipment/mecha_equipment.dm b/code/modules/vehicles/mecha/equipment/mecha_equipment.dm
index 9566908301b..8da111ec7d1 100644
--- a/code/modules/vehicles/mecha/equipment/mecha_equipment.dm
+++ b/code/modules/vehicles/mecha/equipment/mecha_equipment.dm
@@ -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 = "* "
+ var/txt = "* "
if(chassis.selected == src)
- txt += "[src.name]"
+ txt += "[src]"
else if(selectable)
- txt += "[src.name]"
+ txt += "[src]"
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)* [name] - [equip_ready?"Deactivate":"Activate"]"
+ return "* [src] - [activated?"Deactivate":"Activate"]"
/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 "* [src.name] - [equip_ready?"Deactivate":"Activate"]"
+ return "* [src.name] - [activated?"Deactivate":"Activate"]"
/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)] cm3\] - [equip_ready?"Deactivate":"Activate"]"
+ return "[output] \[[fuel]: [round(fuel.amount*MINERAL_MATERIAL_AMOUNT,0.1)] cm3\] - [activated?"Deactivate":"Activate"]"
/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] [equip_ready?"Deactivate":"Activate"]"
+ return "[output] [activated?"Deactivate":"Activate"]"
/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)
diff --git a/code/modules/vehicles/mecha/equipment/tools/work_tools.dm b/code/modules/vehicles/mecha/equipment/tools/work_tools.dm
index 673f8eafed4..003c78d205d 100644
--- a/code/modules/vehicles/mecha/equipment/tools/work_tools.dm
+++ b/code/modules/vehicles/mecha/equipment/tools/work_tools.dm
@@ -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 ..()
diff --git a/code/modules/vehicles/mecha/equipment/weapons/weapons.dm b/code/modules/vehicles/mecha/equipment/weapons/weapons.dm
index b1d1bcb1ef8..5221b479266 100644
--- a/code/modules/vehicles/mecha/equipment/weapons/weapons.dm
+++ b/code/modules/vehicles/mecha/equipment/weapons/weapons.dm
@@ -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))?" - Rearm":null]"
+ return "[..()] \[[projectiles][projectiles_cache_max &&!projectile_energy_cost?"/[projectiles_cache]":""]\][!disabledreload &&(src.projectiles < initial(src.projectiles))?" - Rearm":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(..())
diff --git a/code/modules/vehicles/mecha/mecha_defense.dm b/code/modules/vehicles/mecha/mecha_defense.dm
index 518dc391d36..bb097afb7fb 100644
--- a/code/modules/vehicles/mecha/mecha_defense.dm
+++ b/code/modules/vehicles/mecha/mecha_defense.dm
@@ -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)
diff --git a/code/modules/vehicles/mecha/working/clarke.dm b/code/modules/vehicles/mecha/working/clarke.dm
index 6cd47265b38..ba901f0f2ed 100644
--- a/code/modules/vehicles/mecha/working/clarke.dm
+++ b/code/modules/vehicles/mecha/working/clarke.dm
@@ -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