From ded8e21c0fc08bc59f46d0f303fef3b8ca5be3b2 Mon Sep 17 00:00:00 2001 From: Atlantiscze Date: Wed, 17 Sep 2014 07:31:20 +0200 Subject: [PATCH] Cyborg Power Usage Overhaul - Adds new standardised proc for power usage as Cyborg - Each component now uses different amount of power. Some components use "idle" power (camera), which means constant load. Other components use "active" power, which is single-time burst load.. Example: Actuator. - Power usage is directly proportional to work done. Moving cyborg uses more power than still cyborg. - Information in Status tab changed. Now it only shows percentage of remaining charge, as well as cell rating and cell load (W) --- code/__HELPERS/game.dm | 13 +++- .../game/objects/items/devices/radio/radio.dm | 2 + .../mob/living/silicon/robot/component.dm | 78 +++++++++++++++---- code/modules/mob/living/silicon/robot/life.dm | 10 ++- .../modules/mob/living/silicon/robot/robot.dm | 29 ++++++- .../living/silicon/robot/robot_movement.dm | 8 +- code/modules/mob/living/silicon/say.dm | 15 +++- 7 files changed, 131 insertions(+), 24 deletions(-) diff --git a/code/__HELPERS/game.dm b/code/__HELPERS/game.dm index 77ed7f308e..b7e4f57deb 100644 --- a/code/__HELPERS/game.dm +++ b/code/__HELPERS/game.dm @@ -194,9 +194,18 @@ . = list() // Returns a list of mobs who can hear any of the radios given in @radios var/list/speaker_coverage = list() - for(var/i = 1; i <= radios.len; i++) - var/obj/item/device/radio/R = radios[i] + for(var/obj/item/device/radio/R in radios) if(R) + //Cyborg checks. Receiving message uses a bit of cyborg's charge. + var/obj/item/device/radio/borg/BR = R + if(istype(BR) && BR.myborg) + var/mob/living/silicon/robot/borg = BR.myborg + var/datum/robot_component/CO = borg.get_component("radio") + if(!CO) + continue //No radio component (Shouldn't happen) + if(!borg.is_component_functioning("radio") || !borg.cell_use_power(CO.active_usage)) + continue //No power. + var/turf/speaker = get_turf(R) if(speaker) for(var/turf/T in hear(R.canhear_range,speaker)) diff --git a/code/game/objects/items/devices/radio/radio.dm b/code/game/objects/items/devices/radio/radio.dm index f5da28d0bf..df03577757 100644 --- a/code/game/objects/items/devices/radio/radio.dm +++ b/code/game/objects/items/devices/radio/radio.dm @@ -703,9 +703,11 @@ var/GLOBAL_RADIO_TYPE = 1 // radio type to use //Giving borgs their own radio to have some more room to work with -Sieve /obj/item/device/radio/borg + var/mob/living/silicon/robot/myborg = null // Cyborg which owns this radio. Used for power checks var/obj/item/device/encryptionkey/keyslot = null//Borg radios can handle a single encryption key icon = 'icons/obj/robot_component.dmi' // Cyborgs radio icons should look like the component. icon_state = "radio" + canhear_range = 0 // Should prevent everyone around the cyborg hearing potentionally secret stuff from department channels (espicially sec) /obj/item/device/radio/borg/attackby(obj/item/weapon/W as obj, mob/user as mob) // ..() diff --git a/code/modules/mob/living/silicon/robot/component.dm b/code/modules/mob/living/silicon/robot/component.dm index 9993ca4f81..fdcbdcaa8a 100644 --- a/code/modules/mob/living/silicon/robot/component.dm +++ b/code/modules/mob/living/silicon/robot/component.dm @@ -6,8 +6,9 @@ /datum/robot_component/var/toggled = 1 /datum/robot_component/var/brute_damage = 0 /datum/robot_component/var/electronics_damage = 0 -/datum/robot_component/var/energy_consumption = 0 -/datum/robot_component/var/max_damage = 30 +/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. @@ -55,34 +56,47 @@ electronics_damage = max(0, electronics_damage - electronics) /datum/robot_component/proc/is_powered() - return (installed == 1) && (brute_damage + electronics_damage < max_damage) && (!energy_consumption || powered) + return (installed == 1) && (brute_damage + electronics_damage < max_damage) && (!idle_usage || powered) /datum/robot_component/proc/update_power_state() if(toggled == 0) powered = 0 return - if(owner.cell && owner.cell.charge >= energy_consumption) - owner.cell.use(energy_consumption) + if(owner.cell && owner.cell.charge >= idle_usage) + owner.cell_use_power(idle_usage) powered = 1 else powered = 0 + +// ARMOUR +// Protects the cyborg from damage. Usually first module to be hit +// No power usage /datum/robot_component/armour name = "armour plating" - energy_consumption = 0 external_type = /obj/item/robot_parts/robot_component/armour max_damage = 60 + +// ACTUATOR +// Enables movement. +// Uses no power when idle. Uses 50J for each tile the cyborg moves. /datum/robot_component/actuator name = "actuator" - energy_consumption = 2 + idle_usage = 0 + active_usage = 50 external_type = /obj/item/robot_parts/robot_component/actuator max_damage = 50 + //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) + +// POWER CELL +// Stores power (how unexpected..) +// No power usage /datum/robot_component/cell name = "power cell" max_damage = 50 @@ -91,33 +105,55 @@ ..() owner.cell = null + +// RADIO +// Enables radio communications +// Uses no power when idle. Uses 10J for each received radio message, 50 for each transmitted message. /datum/robot_component/radio name = "radio" external_type = /obj/item/robot_parts/robot_component/radio - energy_consumption = 1 + active_usage = 10 max_damage = 40 + +// BINARY RADIO +// Enables binary communications with other cyborgs/AIs +// Uses no power when idle. Uses 10J for each received radio message, 50 for each transmitted message /datum/robot_component/binary_communication name = "binary communication device" external_type = /obj/item/robot_parts/robot_component/binary_communication_device - energy_consumption = 0 + active_usage = 10 max_damage = 30 + +// CAMERA +// Enables cyborg vision. Can also be remotely accessed via consoles. +// Uses 10J constantly /datum/robot_component/camera name = "camera" external_type = /obj/item/robot_parts/robot_component/camera - energy_consumption = 1 + idle_usage = 10 max_damage = 40 + +// SELF DIAGNOSIS MODULE +// Analyses cyborg's modules, providing damage readouts and basic information +// Uses 1kJ burst when analysis is done /datum/robot_component/diagnosis_unit name = "self-diagnosis unit" - energy_consumption = 1 + active_usage = 1000 external_type = /obj/item/robot_parts/robot_component/diagnosis_unit max_damage = 30 -/mob/living/silicon/robot/proc/initialize_components() - // This only initializes the components, it doesn't set them to installed. + + +// HELPER STUFF + + + +// Initializes cyborg's components. Technically, adds default set of components to new borgs +/mob/living/silicon/robot/proc/initialize_components() components["actuator"] = new/datum/robot_component/actuator(src) components["radio"] = new/datum/robot_component/radio(src) components["power cell"] = new/datum/robot_component/cell(src) @@ -126,10 +162,25 @@ components["comms"] = new/datum/robot_component/binary_communication(src) components["armour"] = new/datum/robot_component/armour(src) +// Checks if component is functioning /mob/living/silicon/robot/proc/is_component_functioning(module_name) var/datum/robot_component/C = components[module_name] return C && C.installed == 1 && C.toggled && C.is_powered() +// Returns component by it's string name +/mob/living/silicon/robot/proc/get_component(var/component_name) + var/datum/robot_component/C = components[component_name] + return C + + + +// COMPONENT OBJECTS + + + +// Component Objects +// These objects are visual representation of modules + /obj/item/broken_device name = "broken component" icon = 'icons/obj/robot_component.dmi' @@ -144,7 +195,6 @@ var/burn = 0 var/icon_state_broken = "broken" -// TODO: actual icons ;) /obj/item/robot_parts/robot_component/binary_communication_device name = "binary communication device" icon_state = "binradio" diff --git a/code/modules/mob/living/silicon/robot/life.dm b/code/modules/mob/living/silicon/robot/life.dm index 1b547df49c..3f7ffa3f81 100644 --- a/code/modules/mob/living/silicon/robot/life.dm +++ b/code/modules/mob/living/silicon/robot/life.dm @@ -32,18 +32,20 @@ adjustFireLoss(0) /mob/living/silicon/robot/proc/use_power() - + // Debug only + // world << "DEBUG: life.dm line 35: cyborg use_power() called at tick [controller_iteration]" + used_power_this_tick = 0 for(var/V in components) var/datum/robot_component/C = components[V] C.update_power_state() if ( cell && is_component_functioning("power cell") && src.cell.charge > 0 ) if(src.module_state_1) - src.cell.use(3) + cell_use_power(50) // 50W load for every enabled tool TODO: tool-specific loads if(src.module_state_2) - src.cell.use(3) + cell_use_power(50) if(src.module_state_3) - src.cell.use(3) + cell_use_power(50) src.has_power = 1 else diff --git a/code/modules/mob/living/silicon/robot/robot.dm b/code/modules/mob/living/silicon/robot/robot.dm index 2c3c99f83b..226ecb5a06 100644 --- a/code/modules/mob/living/silicon/robot/robot.dm +++ b/code/modules/mob/living/silicon/robot/robot.dm @@ -2,6 +2,8 @@ var/list/robot_verbs_default = list( /mob/living/silicon/robot/proc/sensor_mode ) +#define CYBORG_POWER_USAGE_MULTIPLIER 2.5 // Multiplier for amount of power cyborgs use. + /mob/living/silicon/robot name = "Cyborg" real_name = "Cyborg" @@ -10,6 +12,7 @@ var/list/robot_verbs_default = list( maxHealth = 200 health = 200 + var/used_power_this_tick = 0 var/sight_mode = 0 var/custom_name = "" var/custom_sprite = 0 //Due to all the sprites involved, a var for our custom borgs may be best @@ -383,7 +386,7 @@ var/list/robot_verbs_default = list( var/dat = "[src.name] Self-Diagnosis Report\n" for (var/V in components) var/datum/robot_component/C = components[V] - dat += "[C.name]
Power consumption[C.energy_consumption]
Brute Damage:[C.brute_damage]
Electronics Damage:[C.electronics_damage]
Powered:[(!C.energy_consumption || C.is_powered()) ? "Yes" : "No"]
Toggled:[ C.toggled ? "Yes" : "No"]

" + dat += "[C.name]
Brute Damage:[C.brute_damage]
Electronics Damage:[C.electronics_damage]
Powered:[(!C.idle_usage || C.is_powered()) ? "Yes" : "No"]
Toggled:[ C.toggled ? "Yes" : "No"]

" return dat @@ -395,6 +398,9 @@ var/list/robot_verbs_default = list( if(!is_component_functioning("diagnosis unit")) src << "\red Your self-diagnosis component isn't functioning." + var/datum/robot_component/CO = get_component("diagnosis unit") + if (!cell_use_power(CO.active_usage)) + src << "\red Low Power." var/dat = self_diagnosis() src << browse(dat, "window=robotdiagnosis") @@ -464,7 +470,9 @@ var/list/robot_verbs_default = list( // this function displays the cyborgs current cell charge in the stat panel /mob/living/silicon/robot/proc/show_cell_power() if(cell) - stat(null, text("Charge Left: [cell.charge]/[cell.maxcharge]")) + stat(null, text("Charge Left: [round(cell.percent())]%")) + stat(null, text("Cell Rating: [round(cell.maxcharge)]")) // Round just in case we somehow get crazy values + stat(null, text("Power Cell Load: [round(used_power_this_tick)]W")) else stat(null, text("No Cell Inserted!")) @@ -1327,3 +1335,20 @@ var/list/robot_verbs_default = list( /mob/living/silicon/robot/proc/remove_robot_verbs() src.verbs -= robot_verbs_default + + +// Uses power from cyborg's cell. Returns 1 on success or 0 on failure. +// Properly converts using CELLRATE now! Amount is in Joules. +/mob/living/silicon/robot/proc/cell_use_power(var/amount = 0) + // No cell inserted + if(!cell) + return 0 + + // Power cell is empty. + if(cell.charge == 0) + return 0 + + if(cell.use(amount * CELLRATE * CYBORG_POWER_USAGE_MULTIPLIER)) + used_power_this_tick += amount * CYBORG_POWER_USAGE_MULTIPLIER + return 1 + return 0 \ No newline at end of file diff --git a/code/modules/mob/living/silicon/robot/robot_movement.dm b/code/modules/mob/living/silicon/robot/robot_movement.dm index c3b7d43c05..8cf0eae0c0 100644 --- a/code/modules/mob/living/silicon/robot/robot_movement.dm +++ b/code/modules/mob/living/silicon/robot/robot_movement.dm @@ -22,5 +22,11 @@ return tally+config.robot_delay +// NEW: Use power while moving. /mob/living/silicon/robot/Move() - ..() \ No newline at end of file + if (!is_component_functioning("actuator")) + return + + var/datum/robot_component/actuator/A = get_component("actuator") + if (cell_use_power(A.active_usage)) + ..() \ No newline at end of file diff --git a/code/modules/mob/living/silicon/say.dm b/code/modules/mob/living/silicon/say.dm index 0b971cfab1..c979eec0dc 100644 --- a/code/modules/mob/living/silicon/say.dm +++ b/code/modules/mob/living/silicon/say.dm @@ -72,7 +72,11 @@ if(message_mode && bot_type == IS_ROBOT && message_mode != "binary" && !R.is_component_functioning("radio")) src << "\red Your radio isn't functional at this time." return - + if(bot_type == IS_ROBOT && message_mode != "binary") + var/datum/robot_component/radio/RA = R.get_component("radio") + if (!R.cell_use_power(RA.active_usage)) + usr << "\red Not enough power to transmit message." + return //parse language key and consume it var/datum/language/speaking = parse_language(message) @@ -100,6 +104,10 @@ if(!R.is_component_functioning("comms")) src << "\red Your binary communications component isn't functional." return + var/datum/robot_component/binary_communication/B = R.get_component("comms") + if(!R.cell_use_power(B.active_usage)) + src << "\red Not enough power to transmit message." + return if(IS_PAI) src << "You do not appear to have that function" return @@ -197,6 +205,11 @@ var/renderedAI = "Robotic Talk, [name] [verb], \"[message]\"" S.show_message(renderedAI, 2) else + var/mob/living/silicon/robot/borg = S + if(istype(borg) && borg.is_component_functioning("comms")) + var/datum/robot_component/RC = borg.get_component("comms") + if(!borg.use_power(RC.active_usage)) + continue // No power. S.show_message(rendered, 2)