Files
Bubberstation/code/modules/mining/minebot.dm
phil235 5f835bfc26 Obj damaging system, acid damage, and fire damage refactor (WIP) (#20793)
Please refer to #20867 and #20870 for a easier view of the changes. Those two PRs show all meaningful changes (hopefully) and doesn't show the files changed with just 3 lines changed.

This PR does three things:

    It makes all children of /obj/ use the same damage system.
    Previously to make your new machine/structure be destroyable you needed to give it a var/health, and its own version of many damage related proc such as bullet_act(), take_damage(), attacked_by(), attack_animal(), attack_hulk(), ex_act(), etc... But now, all /obj/ use the same version of those procs at the /obj/ level in code/game/obj_defense.dm. All these obj share the same necessary vars: obj_integrity (health), max_integrity, integrity_failure (optional, below that health level failure happens), and the armor list var which was previously only for items, as well as the resistance_flags bitfield. When you want your new object to be destroyable, you only have to give it a value for those vars and maybe override one proc if you want a special behavior but that's it. This reorganization removes a lot of copypasta (most bullet_act() version for each obj were nearly identical). Two new elements are added to the armor list var: fire and acid armor values.
    How much damage an obj take depends on the armor value for each damage category. But some objects are INDESTRUCTIBLE and simply never take any damage no matter the type.
    The armor categories are:
    -melee(punches, item attacks, xeno/animal/hulk attacks, blob attacks, thrown weapons)
    -bullet
    -laser
    -energy (used by projectiles like ionrifle, taser, and also by EMPs)
    -bio (unused for this, only here because clothes use them when worn)
    -rad (same)
    -bomb (self-explanatory)
    -fire (for fire damage, not for heat damage though)
    -acid
    For machines and structures, when their health reaches zero the object is not just deleted but gets somewhat forcedeconstructed (the proc used is shared with the actual deconstruction system) which can drops things. To not frustrates players most of these objects drop most of the elements necessary to rebuild them (think window dropping shards). Machines drop a machine frame and all components for example (but the frame can then be itself smashed to pieces).
    For clothes, when they are damaged, they get a "damaged" overlay, which can also be seen when worn, similar to the "bloody" overlay.

    It refactors acid. See #20537.
    Some objects are ACID_PROOF and take no damage from acid, while others take varying amounts
    of damage depending on their acid armor value. Some objects are even UNACIDABLE, no acid effect can even land on them. Acid on objects can be washed off using water.

    It changes some aspect of damage from fires.
    All /obj/ can now take fire damage and be flammable, instead of just items. And instead of having just FLAMMABLE objs that become ON_FIRE as soon as some fire touch them (paper), we now have objects that are non flammable but do take damage from fire and become ashes if their health reaches zero (only for items). The damage taken varies depending on the obj's fire armor value and total health. There's also still obj and items that are FIRE_PROOF (although some might still be melted by lava if they're not LAVA_PROOF).
    When a mob is on fire, its clothes now take fire damage and can turn to ashes. Similarly, when a mob takes melee damages, its clothes gets damaged a bit and can turn to shreds. You can repair clothes with cloth that is produceable by botany's biogenerator.

    It also does many minor things:
        Clicking a structure/machine with an item on help intent never results in an attack (so you don't destroy a structure while trying to figure out which tool to use).
        I moved a lot of objects away from /obj/effect, it should only be used for visual effects, decals and stuff, not for things you can hit and destroy.
        I tweaked a bit how clothes shredding from bombs work.
        I made a machine or structure un/anchorable with the wrench, I don't remember which object...
        Since I changed the meaning of the FIRE_PROOF bitflag to actually mean fire immune, I'm buffing the slime extract that you apply on items to make them fire proof. well now they're really 100% fire proof!
        animals with environment_smash = 1 no longer one-hit destroy tables and stuff, we give them a decent obj_damage value so they can destroy most obj relatively fast depending on the animal.
        Probably a million things I forgot.

If you want to know how the damage system works all you need is the three obj vars "obj_integrity", "max_integrity", "integrity_failure", as well as the armor list var and the resistance_flags bitfield, and read the file obj_defense.dm
2016-10-10 11:14:59 +13:00

285 lines
8.8 KiB
Plaintext

/**********************Mining drone**********************/
#define MINEDRONE_COLLECT 1
#define MINEDRONE_ATTACK 2
/mob/living/simple_animal/hostile/mining_drone
name = "nanotrasen minebot"
desc = "The instructions printed on the side read: This is a small robot used to support miners, can be set to search and collect loose ore, or to help fend off wildlife. A mining scanner can instruct it to drop loose ore. Field repairs can be done with a welder."
icon = 'icons/obj/aibots.dmi'
icon_state = "mining_drone"
icon_living = "mining_drone"
status_flags = CANSTUN|CANWEAKEN|CANPUSH
stop_automated_movement_when_pulled = 1
mouse_opacity = 1
faction = list("neutral")
a_intent = "harm"
atmos_requirements = list("min_oxy" = 0, "max_oxy" = 0, "min_tox" = 0, "max_tox" = 0, "min_co2" = 0, "max_co2" = 0, "min_n2" = 0, "max_n2" = 0)
minbodytemp = 0
wander = 0
idle_vision_range = 5
move_to_delay = 10
retreat_distance = 1
minimum_distance = 2
health = 125
maxHealth = 125
melee_damage_lower = 15
melee_damage_upper = 15
obj_damage = 0
environment_smash = 0
check_friendly_fire = 1
stop_automated_movement_when_pulled = 1
attacktext = "drills"
attack_sound = 'sound/weapons/circsawhit.ogg'
ranged = 1
sentience_type = SENTIENCE_MINEBOT
ranged_message = "shoots"
ranged_cooldown_time = 30
projectiletype = /obj/item/projectile/kinetic
projectilesound = 'sound/weapons/Gunshot4.ogg'
speak_emote = list("states")
wanted_objects = list(/obj/item/weapon/ore/diamond, /obj/item/weapon/ore/gold, /obj/item/weapon/ore/silver,
/obj/item/weapon/ore/plasma, /obj/item/weapon/ore/uranium, /obj/item/weapon/ore/iron,
/obj/item/weapon/ore/bananium, /obj/item/weapon/ore/titanium)
healable = 0
var/mode = MINEDRONE_COLLECT
var/light_on = 0
var/datum/action/innate/minedrone/toggle_light/toggle_light_action
var/datum/action/innate/minedrone/toggle_meson_vision/toggle_meson_vision_action
var/datum/action/innate/minedrone/toggle_mode/toggle_mode_action
var/datum/action/innate/minedrone/dump_ore/dump_ore_action
/mob/living/simple_animal/hostile/mining_drone/New()
..()
toggle_light_action = new()
toggle_light_action.Grant(src)
toggle_meson_vision_action = new()
toggle_meson_vision_action.Grant(src)
toggle_mode_action = new()
toggle_mode_action.Grant(src)
dump_ore_action = new()
dump_ore_action.Grant(src)
SetCollectBehavior()
/mob/living/simple_animal/hostile/mining_drone/sentience_act()
AIStatus = AI_OFF
check_friendly_fire = 0
/mob/living/simple_animal/hostile/mining_drone/attackby(obj/item/I, mob/user, params)
if(istype(I, /obj/item/weapon/weldingtool))
var/obj/item/weapon/weldingtool/W = I
if(W.welding && !stat)
if(AIStatus != AI_OFF && AIStatus != AI_IDLE)
user << "<span class='info'>[src] is moving around too much to repair!</span>"
return
if(maxHealth == health)
user << "<span class='info'>[src] is at full integrity.</span>"
else
adjustBruteLoss(-10)
user << "<span class='info'>You repair some of the armor on [src].</span>"
return
if(istype(I, /obj/item/device/mining_scanner) || istype(I, /obj/item/device/t_scanner/adv_mining_scanner))
user << "<span class='info'>You instruct [src] to drop any collected ore.</span>"
DropOre()
return
..()
/mob/living/simple_animal/hostile/mining_drone/death()
..()
visible_message("<span class='danger'>[src] is destroyed!</span>")
new /obj/effect/decal/cleanable/robot_debris(src.loc)
DropOre(0)
qdel(src)
return
/mob/living/simple_animal/hostile/mining_drone/attack_hand(mob/living/carbon/human/M)
if(M.a_intent == "help")
toggle_mode()
switch(mode)
if(MINEDRONE_COLLECT)
M << "<span class='info'>[src] has been set to search and store loose ore.</span>"
if(MINEDRONE_ATTACK)
M << "<span class='info'>[src] has been set to attack hostile wildlife.</span>"
return
..()
/mob/living/simple_animal/hostile/mining_drone/proc/SetCollectBehavior()
mode = MINEDRONE_COLLECT
idle_vision_range = 9
search_objects = 2
wander = 1
ranged = 0
minimum_distance = 1
retreat_distance = null
icon_state = "mining_drone"
src << "<span class='info'>You are set to collect mode. You can now collect loose ore.</span>"
/mob/living/simple_animal/hostile/mining_drone/proc/SetOffenseBehavior()
mode = MINEDRONE_ATTACK
idle_vision_range = 7
search_objects = 0
wander = 0
ranged = 1
retreat_distance = 1
minimum_distance = 2
icon_state = "mining_drone_offense"
src << "<span class='info'>You are set to attack mode. You can now attack from range.</span>"
/mob/living/simple_animal/hostile/mining_drone/AttackingTarget()
if(istype(target, /obj/item/weapon/ore) && mode == MINEDRONE_COLLECT)
CollectOre()
return
..()
/mob/living/simple_animal/hostile/mining_drone/proc/CollectOre()
var/obj/item/weapon/ore/O
for(O in src.loc)
O.loc = src
for(var/dir in alldirs)
var/turf/T = get_step(src,dir)
for(O in T)
O.loc = src
return
/mob/living/simple_animal/hostile/mining_drone/proc/DropOre(message = 1)
if(!contents.len)
if(message)
src << "<span class='notice'>You attempt to dump your stored ore, but you have none.</span>"
return
if(message)
src << "<span class='notice'>You dump your stored ore.</span>"
for(var/obj/item/weapon/ore/O in contents)
contents -= O
O.loc = src.loc
return
/mob/living/simple_animal/hostile/mining_drone/adjustHealth(amount)
if(mode != MINEDRONE_ATTACK && amount > 0)
SetOffenseBehavior()
. = ..()
/mob/living/simple_animal/hostile/mining_drone/proc/toggle_mode()
switch(mode)
if(MINEDRONE_COLLECT)
SetOffenseBehavior()
if(MINEDRONE_ATTACK)
SetCollectBehavior()
else //This should never happen.
mode = MINEDRONE_COLLECT
SetCollectBehavior()
//Actions for sentient minebots
/datum/action/innate/minedrone
check_flags = AB_CHECK_CONSCIOUS
background_icon_state = "bg_default"
/datum/action/innate/minedrone/toggle_light
name = "Toggle Light"
button_icon_state = "mech_lights_off"
/datum/action/innate/minedrone/toggle_light/Activate()
var/mob/living/simple_animal/hostile/mining_drone/user = owner
if(user.light_on)
user.AddLuminosity(-6)
else
user.AddLuminosity(6)
user.light_on = !user.light_on
user << "<span class='notice'>You toggle your light [user.light_on ? "on" : "off"].</span>"
/datum/action/innate/minedrone/toggle_meson_vision
name = "Toggle Meson Vision"
button_icon_state = "meson"
/datum/action/innate/minedrone/toggle_meson_vision/Activate()
var/mob/living/simple_animal/hostile/mining_drone/user = owner
if(user.sight & SEE_TURFS)
user.sight &= ~SEE_TURFS
user.see_invisible = SEE_INVISIBLE_LIVING
else
user.sight |= SEE_TURFS
user.see_invisible = SEE_INVISIBLE_MINIMUM
user << "<span class='notice'>You toggle your meson vision [(user.sight & SEE_TURFS) ? "on" : "off"].</span>"
/datum/action/innate/minedrone/toggle_mode
name = "Toggle Mode"
button_icon_state = "mech_cycle_equip_off"
/datum/action/innate/minedrone/toggle_mode/Activate()
var/mob/living/simple_animal/hostile/mining_drone/user = owner
user.toggle_mode()
/datum/action/innate/minedrone/dump_ore
name = "Dump Ore"
button_icon_state = "mech_eject"
/datum/action/innate/minedrone/dump_ore/Activate()
var/mob/living/simple_animal/hostile/mining_drone/user = owner
user.DropOre()
/**********************Minebot Upgrades**********************/
//Melee
/obj/item/device/mine_bot_ugprade
name = "minebot melee upgrade"
desc = "A minebot upgrade."
icon_state = "door_electronics"
icon = 'icons/obj/module.dmi'
/obj/item/device/mine_bot_ugprade/afterattack(mob/living/simple_animal/hostile/mining_drone/M, mob/user, proximity)
if(!istype(M) || !proximity)
return
upgrade_bot(M, user)
/obj/item/device/mine_bot_ugprade/proc/upgrade_bot(mob/living/simple_animal/hostile/mining_drone/M, mob/user)
if(M.melee_damage_upper != initial(M.melee_damage_upper))
user << "[src] already has a combat upgrade installed!"
return
M.melee_damage_lower = 22
M.melee_damage_upper = 22
qdel(src)
//Health
/obj/item/device/mine_bot_ugprade/health
name = "minebot chassis upgrade"
/obj/item/device/mine_bot_ugprade/health/upgrade_bot(mob/living/simple_animal/hostile/mining_drone/M, mob/user)
if(M.maxHealth != initial(M.maxHealth))
user << "[src] already has a reinforced chassis!"
return
M.maxHealth = 170
qdel(src)
//Cooldown
/obj/item/device/mine_bot_ugprade/cooldown
name = "minebot cooldown upgrade"
/obj/item/device/mine_bot_ugprade/cooldown/upgrade_bot(mob/living/simple_animal/hostile/mining_drone/M, mob/user)
name = "minebot cooldown upgrade"
if(M.ranged_cooldown_time != initial(M.ranged_cooldown_time))
user << "[src] already has a decreased weapon cooldown!"
return
M.ranged_cooldown_time = 10
qdel(src)
//AI
/obj/item/slimepotion/sentience/mining
name = "minebot AI upgrade"
desc = "Can be used to grant sentience to minebots."
icon_state = "door_electronics"
icon = 'icons/obj/module.dmi'
sentience_type = SENTIENCE_MINEBOT
origin_tech = "programming=6"
#undef MINEDRONE_COLLECT
#undef MINEDRONE_ATTACK