Skip to content

Commit

Permalink
Fixing issues with robot movement.
Browse files Browse the repository at this point in the history
  • Loading branch information
MistakeNot4892 committed Jan 23, 2025
1 parent e4c46d6 commit 0e44754
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 40 deletions.
7 changes: 5 additions & 2 deletions code/datums/movement/robot.dm
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@
// Use power while moving.
/datum/movement_handler/robot/use_power/DoMove(direction, mob/mover, is_external)
var/datum/robot_component/actuator/A = robot.get_component("actuator")
if(!robot.cell_use_power(A.active_usage * robot.power_efficiency))
if(!is_external && !robot.cell_use_power(A.active_usage * robot.power_efficiency))
return MOVEMENT_HANDLED
return MOVEMENT_PROCEED

/datum/movement_handler/robot/use_power/MayMove(mob/mover, is_external)
return (!robot.lockcharge && robot.is_component_functioning("actuator")) ? MOVEMENT_PROCEED : MOVEMENT_STOP
if(is_external || (!robot.incapacitated() && !robot.lockcharge && robot.is_component_functioning("actuator")))
return MOVEMENT_PROCEED
return MOVEMENT_STOP
2 changes: 1 addition & 1 deletion code/modules/mob/living/silicon/robot/analyzer.dm
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
user.show_message(text("<span class='notice'>\t []: [][] - [] - [] - []</span>", \
capitalize(org.name), \
(org.installed == -1) ? "<font color='red'><b>DESTROYED</b></font> " :"",\
(org.electronics_damage > 0) ? "<font color='#ffa500'>[org.electronics_damage]</font>" :0, \
(org.burn_damage > 0) ? "<font color='#ffa500'>[org.burn_damage]</font>" :0, \
(org.brute_damage > 0) ? "<font color='red'>[org.brute_damage]</font>" :0, \
(org.toggled) ? "Toggled ON" : "<font color='red'>Toggled OFF</font>",\
(org.powered) ? "Power ON" : "<font color='red'>Power OFF</font>"),1)
Expand Down
46 changes: 24 additions & 22 deletions code/modules/mob/living/silicon/robot/component.dm
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
// TODO: remove the robot.central_processor and robot.cell variables and completely rely on the robot component system

/datum/robot_component/var/name
/datum/robot_component/var/installed = 0
/datum/robot_component/var/powered = 0
/datum/robot_component/var/toggled = 1
/datum/robot_component/var/brute_damage = 0
/datum/robot_component/var/electronics_damage = 0
/datum/robot_component/var/idle_usage = 0 // Amount of power used every MC tick. In joules.
/datum/robot_component/var/active_usage = 0 // Amount of power used for every action. Actions are module-specific. Actuator for each tile moved, etc.
/datum/robot_component/var/max_damage = 30 // HP of this component.
/datum/robot_component/var/mob/living/silicon/robot/owner

// The actual device object that has to be installed for this.
/datum/robot_component/var/external_type = null

// The wrapped device(e.g. radio), only set if external_type isn't null
/datum/robot_component/var/obj/item/wrapped = null
/datum/robot_component
var/name
/// Installation status; not a bool, may be -1, 0 or 1.
var/installed = 0
var/powered = FALSE
var/toggled = TRUE
var/brute_damage = 0
var/burn_damage = 0
/// Amount of power used every MC tick. In joules.
var/idle_usage = 0
/// Amount of power used for every action. Actions are module-specific. Actuator for each tile moved, etc.
var/active_usage = 0
/// HP of this component.
var/max_damage = 30
var/mob/living/silicon/robot/owner
/// The actual device object that has to be installed for this.
var/external_type
/// The wrapped device(e.g. radio), only set if external_type isn't null
var/obj/item/wrapped

/datum/robot_component/New(mob/living/silicon/robot/R)
src.owner = R
Expand Down Expand Up @@ -56,20 +58,20 @@
if(installed != 1) return

brute_damage += brute
electronics_damage += electronics
burn_damage += electronics

if(brute_damage + electronics_damage >= max_damage) destroy()
if(brute_damage + burn_damage >= max_damage) destroy()

/datum/robot_component/proc/heal_damage(brute, electronics)
if(installed != 1)
// If it's not installed, can't repair it.
return 0

brute_damage = max(0, brute_damage - brute)
electronics_damage = max(0, electronics_damage - electronics)
burn_damage = max(0, burn_damage - electronics)

/datum/robot_component/proc/is_powered()
return (installed == 1) && (brute_damage + electronics_damage < max_damage) && (!idle_usage || powered)
return (installed == 1) && (brute_damage + burn_damage < max_damage) && (!idle_usage || powered)

/datum/robot_component/proc/update_power_state()
if(toggled == 0)
Expand Down Expand Up @@ -111,7 +113,7 @@

//A fixed and much cleaner implementation of /tg/'s special snowflake code.
/datum/robot_component/actuator/is_powered()
return (installed == 1) && (brute_damage + electronics_damage < max_damage)
return (installed == 1) && (brute_damage + burn_damage < max_damage)


// POWER CELL
Expand Down
8 changes: 4 additions & 4 deletions code/modules/mob/living/silicon/robot/robot.dm
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@
var/dat = "<HEAD><TITLE>[src.name] Self-Diagnosis Report</TITLE></HEAD><BODY>\n"
for (var/V in components)
var/datum/robot_component/C = components[V]
dat += "<b>[C.name]</b><br><table><tr><td>Brute Damage:</td><td>[C.brute_damage]</td></tr><tr><td>Electronics Damage:</td><td>[C.electronics_damage]</td></tr><tr><td>Powered:</td><td>[(!C.idle_usage || C.is_powered()) ? "Yes" : "No"]</td></tr><tr><td>Toggled:</td><td>[ C.toggled ? "Yes" : "No"]</td></table><br>"
dat += "<b>[C.name]</b><br><table><tr><td>Brute Damage:</td><td>[C.brute_damage]</td></tr><tr><td>Electronics Damage:</td><td>[C.burn_damage]</td></tr><tr><td>Powered:</td><td>[(!C.idle_usage || C.is_powered()) ? "Yes" : "No"]</td></tr><tr><td>Toggled:</td><td>[ C.toggled ? "Yes" : "No"]</td></table><br>"

return dat

Expand Down Expand Up @@ -460,7 +460,7 @@
var/obj/item/robot_parts/robot_component/WC = W
if(istype(WC))
C.brute_damage = WC.brute_damage
C.electronics_damage = WC.burn_damage
C.burn_damage = WC.burn_damage

to_chat(user, "<span class='notice'>You install the [W.name].</span>")
return TRUE
Expand Down Expand Up @@ -538,7 +538,7 @@
var/obj/item/robot_parts/robot_component/I = C.wrapped
if(istype(I))
I.set_bruteloss(C.brute_damage)
I.set_burnloss(C.electronics_damage)
I.set_burnloss(C.burn_damage)

removed_item = I
if(C.installed == 1)
Expand Down Expand Up @@ -577,7 +577,7 @@
C.install()
// This means that removing and replacing a power cell will repair the mount.
C.brute_damage = 0
C.electronics_damage = 0
C.burn_damage = 0
return TRUE
else if(IS_WIRECUTTER(W) || IS_MULTITOOL(W))
if (wiresexposed)
Expand Down
12 changes: 6 additions & 6 deletions code/modules/mob/living/silicon/robot/robot_damage.dm
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
var/amount = 0
for(var/V in components)
var/datum/robot_component/C = components[V]
if(C.installed != 0) amount += C.electronics_damage
if(C.installed != 0) amount += C.burn_damage
return amount

/mob/living/silicon/robot/adjustBruteLoss(var/amount, var/do_update_health = TRUE)
Expand All @@ -30,7 +30,7 @@
for(var/V in components)
var/datum/robot_component/C = components[V]
if(C.installed == 1 || (C.installed == -1 && destroyed))
if((brute && C.brute_damage) || (burn && C.electronics_damage) || (!C.toggled) || (!C.powered && C.toggled))
if((brute && C.brute_damage) || (burn && C.burn_damage) || (!C.toggled) || (!C.powered && C.toggled))
parts += C
return parts

Expand Down Expand Up @@ -93,12 +93,12 @@
var/datum/robot_component/picked = pick(parts)

var/brute_was = picked.brute_damage
var/burn_was = picked.electronics_damage
var/burn_was = picked.burn_damage

picked.heal_damage(brute,burn)

brute -= (brute_was-picked.brute_damage)
burn -= (burn_was-picked.electronics_damage)
burn -= (burn_was-picked.burn_damage)

parts -= picked

Expand Down Expand Up @@ -130,10 +130,10 @@
while(parts.len && (brute>0 || burn>0) )
var/datum/robot_component/picked = pick(parts)
var/brute_was = picked.brute_damage
var/burn_was = picked.electronics_damage
var/burn_was = picked.burn_damage
picked.take_component_damage(brute,burn)
brute -= (picked.brute_damage - brute_was)
burn -= (picked.electronics_damage - burn_was)
burn -= (picked.burn_damage - burn_was)
parts -= picked
update_health()

Expand Down
5 changes: 0 additions & 5 deletions code/modules/mob/living/silicon/silicon.dm
Original file line number Diff line number Diff line change
Expand Up @@ -459,8 +459,3 @@
stance_damage = 0
return

/mob/living/silicon/MayMove(mob/mover, is_external)
// Disable crawling for robots, as they don't implement prone states/slowdown.
if(!is_external && incapacitated())
return FALSE
return ..()

0 comments on commit 0e44754

Please sign in to comment.