From f13dd0695d97cd0394dfea6f9c69b8d543ad7fa7 Mon Sep 17 00:00:00 2001 From: Mothblocks <35135081+Mothblocks@users.noreply.github.com> Date: Thu, 23 Sep 2021 20:07:03 -0700 Subject: [PATCH] Spiders/carp will now pull/move water/welding fuel tanks/canisters slower and won't be able to attack stationary atmospherics equipment (#61616) Adds 2 new elements, one for slowing down pulling of dangerous objects (dispenser tanks and canisters), and one for preventing hostile attacking of elements in a typecache. Also updates the obj_flags bitfield 'cause I thought I was gonna use that, but I didn't. Adds these elements to spiders and space carp (from space dragon) --- code/__DEFINES/dcs/signals.dm | 5 ++ code/_globalvars/bitfields.dm | 5 ++ code/_globalvars/lists/typecache.dm | 13 +++++ code/datums/elements/nerfed_pulling.dm | 53 +++++++++++++++++++ .../elements/prevent_attacking_of_types.dm | 38 +++++++++++++ code/modules/mob/living/living.dm | 1 + code/modules/mob/living/living_movement.dm | 2 + .../simple_animal/hostile/giant_spider.dm | 2 + .../simple_animal/hostile/space_dragon.dm | 4 ++ tgstation.dme | 2 + 10 files changed, 125 insertions(+) create mode 100644 code/datums/elements/nerfed_pulling.dm create mode 100644 code/datums/elements/prevent_attacking_of_types.dm diff --git a/code/__DEFINES/dcs/signals.dm b/code/__DEFINES/dcs/signals.dm index 98f4f744024..2b66a46e389 100644 --- a/code/__DEFINES/dcs/signals.dm +++ b/code/__DEFINES/dcs/signals.dm @@ -345,6 +345,11 @@ ///called on /living, when pull is attempted, but before it completes, from base of [/mob/living/start_pulling]: (atom/movable/thing, force) #define COMSIG_LIVING_TRY_PULL "living_try_pull" #define COMSIG_LIVING_CANCEL_PULL (1 << 0) +/// Called from /mob/living/update_pull_movespeed +#define COMSIG_LIVING_UPDATING_PULL_MOVESPEED "living_updating_pull_movespeed" +/// Called from /mob/living/PushAM -- Called when this mob is about to push a movable, but before it moves +/// (aotm/movable/being_pushed) +#define COMSIG_LIVING_PUSHING_MOVABLE "living_pushing_movable" ///from base of [/atom/proc/interact]: (mob/user) #define COMSIG_ATOM_UI_INTERACT "atom_ui_interact" ///called on /living when attempting to pick up an item, from base of /mob/living/put_in_hand_check(): (obj/item/I) diff --git a/code/_globalvars/bitfields.dm b/code/_globalvars/bitfields.dm index 0e3c059946a..c7096411907 100644 --- a/code/_globalvars/bitfields.dm +++ b/code/_globalvars/bitfields.dm @@ -250,11 +250,16 @@ DEFINE_BITFIELD(movement_type, list( DEFINE_BITFIELD(obj_flags, list( "BEING_SHOCKED" = BEING_SHOCKED, + "BLOCK_Z_IN_DOWN" = BLOCK_Z_IN_DOWN, + "BLOCK_Z_IN_UP" = BLOCK_Z_IN_UP, + "BLOCK_Z_OUT_DOWN" = BLOCK_Z_OUT_DOWN, + "BLOCK_Z_OUT_UP" = BLOCK_Z_OUT_UP, "CAN_BE_HIT" = CAN_BE_HIT, "DANGEROUS_POSSESSION" = DANGEROUS_POSSESSION, "EMAGGED" = EMAGGED, "FROZEN" = FROZEN, "IN_USE" = IN_USE, + "NO_BUILD" = NO_BUILD, "ON_BLUEPRINTS" = ON_BLUEPRINTS, "UNIQUE_RENAME" = UNIQUE_RENAME, "USES_TGUI" = USES_TGUI, diff --git a/code/_globalvars/lists/typecache.dm b/code/_globalvars/lists/typecache.dm index 11641d5c614..606543ffb5c 100644 --- a/code/_globalvars/lists/typecache.dm +++ b/code/_globalvars/lists/typecache.dm @@ -13,3 +13,16 @@ GLOBAL_LIST_INIT(typecache_machine_or_structure, typecacheof(list(/obj/machinery /// A typecache listing structures that are considered to have surfaces that you can place items on that are higher than the floor. This, of course, should be restricted to /atom/movables. This is primarily used for food decomposition code. GLOBAL_LIST_INIT(typecache_elevated_structures, typecacheof(list(/obj/structure/table,/obj/structure/rack,/obj/machinery/conveyor,/obj/structure/closet))) + +/// A typecache of objects that player controlled, easily accessible, hostile mobs should not be able to attack +GLOBAL_LIST_INIT(typecache_general_bad_hostile_attack_targets, typecacheof(list( + /obj/machinery/airalarm, + /obj/machinery/atmospherics, + /obj/machinery/power/apc, +))) + +/// A typecache of objects that player controlled, easily accessible, hostile mobs should not be able to move around easily +GLOBAL_LIST_INIT(typecache_general_bad_things_to_easily_move, typecacheof(list( + /obj/machinery/portable_atmospherics/canister, + /obj/structure/reagent_dispensers, +))) diff --git a/code/datums/elements/nerfed_pulling.dm b/code/datums/elements/nerfed_pulling.dm new file mode 100644 index 00000000000..b01ada506c3 --- /dev/null +++ b/code/datums/elements/nerfed_pulling.dm @@ -0,0 +1,53 @@ +/// This living will be slower when pulling/moving anything in the given typecache +/datum/element/nerfed_pulling + element_flags = ELEMENT_BESPOKE | ELEMENT_DETACH + id_arg_index = 2 + + /// The typecache of things that shouldn't be easily movable + var/list/typecache + +/datum/element/nerfed_pulling/Attach(datum/target, list/typecache) + . = ..() + + if (!isliving(target)) + return ELEMENT_INCOMPATIBLE + + src.typecache = typecache + + RegisterSignal(target, COMSIG_LIVING_PUSHING_MOVABLE, .proc/on_push_movable) + RegisterSignal(target, COMSIG_LIVING_UPDATING_PULL_MOVESPEED, .proc/on_updating_pull_movespeed) + +/datum/element/nerfed_pulling/Detach(mob/living/source) + source.remove_movespeed_modifier(/datum/movespeed_modifier/nerfed_bump) + source.remove_movespeed_modifier(/datum/movespeed_modifier/nerfed_pull) + + UnregisterSignal(source, list(COMSIG_LIVING_PUSHING_MOVABLE, COMSIG_LIVING_UPDATING_PULL_MOVESPEED)) + + return ..() + +/datum/element/nerfed_pulling/proc/on_push_movable(mob/living/source, atom/movable/being_pushed) + SIGNAL_HANDLER + + if (!will_slow_down(being_pushed)) + return + + source.add_movespeed_modifier(/datum/movespeed_modifier/nerfed_bump) + addtimer(CALLBACK(source, /mob/proc/remove_movespeed_modifier, /datum/movespeed_modifier/nerfed_bump), 1 SECONDS, TIMER_OVERRIDE | TIMER_UNIQUE) + +/datum/element/nerfed_pulling/proc/on_updating_pull_movespeed(mob/living/source) + SIGNAL_HANDLER + + if (!will_slow_down(source.pulling)) + source.remove_movespeed_modifier(/datum/movespeed_modifier/nerfed_pull) + return + + source.add_movespeed_modifier(/datum/movespeed_modifier/nerfed_pull) + +/datum/element/nerfed_pulling/proc/will_slow_down(datum/input) + return !isnull(input) && typecache[input.type] + +/datum/movespeed_modifier/nerfed_pull + multiplicative_slowdown = 5.5 + +/datum/movespeed_modifier/nerfed_bump + multiplicative_slowdown = 5.5 diff --git a/code/datums/elements/prevent_attacking_of_types.dm b/code/datums/elements/prevent_attacking_of_types.dm new file mode 100644 index 00000000000..cc7939a7602 --- /dev/null +++ b/code/datums/elements/prevent_attacking_of_types.dm @@ -0,0 +1,38 @@ +/// This hostile will not be able to attack a given typecache, and will receive +/// a balloon alert when it tries to. +/datum/element/prevent_attacking_of_types + element_flags = ELEMENT_BESPOKE | ELEMENT_DETACH + id_arg_index = 2 + + /// The typecache of things this hostile can't attack + var/list/typecache + + /// The message to send to the hostile mob when they try to attack something they can't + var/alert_message + +/datum/element/prevent_attacking_of_types/Attach(datum/target, list/typecache, alert_message) + . = ..() + + if (!ishostile(target)) + return ELEMENT_INCOMPATIBLE + + src.alert_message = alert_message + src.typecache = typecache + + RegisterSignal(target, COMSIG_HOSTILE_PRE_ATTACKINGTARGET, .proc/on_pre_attacking_target) + +/datum/element/prevent_attacking_of_types/Detach(datum/source, ...) + UnregisterSignal(source, COMSIG_HOSTILE_PRE_ATTACKINGTARGET) + return ..() + +/datum/element/prevent_attacking_of_types/proc/on_pre_attacking_target(mob/source, atom/target) + SIGNAL_HANDLER + + if (!typecache[target.type]) + return + + target.balloon_alert(source, alert_message) + + return COMPONENT_HOSTILE_NO_ATTACK + + diff --git a/code/modules/mob/living/living.dm b/code/modules/mob/living/living.dm index 8fd55d0fd68..99e9bcc2dd3 100644 --- a/code/modules/mob/living/living.dm +++ b/code/modules/mob/living/living.dm @@ -216,6 +216,7 @@ if(!client && (mob_size < MOB_SIZE_SMALL)) return now_pushing = TRUE + SEND_SIGNAL(src, COMSIG_LIVING_PUSHING_MOVABLE, AM) var/dir_to_target = get_dir(src, AM) // If there's no dir_to_target then the player is on the same turf as the atom they're trying to push. diff --git a/code/modules/mob/living/living_movement.dm b/code/modules/mob/living/living_movement.dm index 5a5e98665d0..13d334ffc5f 100644 --- a/code/modules/mob/living/living_movement.dm +++ b/code/modules/mob/living/living_movement.dm @@ -34,6 +34,8 @@ /mob/living/proc/update_pull_movespeed() + SEND_SIGNAL(src, COMSIG_LIVING_UPDATING_PULL_MOVESPEED) + if(pulling) if(isliving(pulling)) var/mob/living/L = pulling diff --git a/code/modules/mob/living/simple_animal/hostile/giant_spider.dm b/code/modules/mob/living/simple_animal/hostile/giant_spider.dm index db2a279fbe5..eafe6e858f6 100644 --- a/code/modules/mob/living/simple_animal/hostile/giant_spider.dm +++ b/code/modules/mob/living/simple_animal/hostile/giant_spider.dm @@ -69,6 +69,8 @@ lay_web.Grant(src) if(poison_per_bite) AddElement(/datum/element/venomous, poison_type, poison_per_bite) + AddElement(/datum/element/nerfed_pulling, GLOB.typecache_general_bad_things_to_easily_move) + AddElement(/datum/element/prevent_attacking_of_types, GLOB.typecache_general_bad_hostile_attack_targets, "this tastes awful!") /mob/living/simple_animal/hostile/giant_spider/Login() . = ..() diff --git a/code/modules/mob/living/simple_animal/hostile/space_dragon.dm b/code/modules/mob/living/simple_animal/hostile/space_dragon.dm index acf39b8280f..37d451cf136 100644 --- a/code/modules/mob/living/simple_animal/hostile/space_dragon.dm +++ b/code/modules/mob/living/simple_animal/hostile/space_dragon.dm @@ -696,7 +696,11 @@ if(carp_stored <= 0) to_chat(user, span_warning("The rift already summoned enough carp!")) return FALSE + var/mob/living/simple_animal/hostile/carp/newcarp = new /mob/living/simple_animal/hostile/carp(loc) + newcarp.AddElement(/datum/element/nerfed_pulling, GLOB.typecache_general_bad_things_to_easily_move) + newcarp.AddElement(/datum/element/prevent_attacking_of_types, GLOB.typecache_general_bad_hostile_attack_targets, "this tastes awful!") + if(!is_listed) ckey_list += user.ckey newcarp.key = user.key diff --git a/tgstation.dme b/tgstation.dme index 85aa3c09e3d..10ae939e231 100644 --- a/tgstation.dme +++ b/tgstation.dme @@ -779,11 +779,13 @@ #include "code\datums\elements\light_eater.dm" #include "code\datums\elements\movement_turf_changer.dm" #include "code\datums\elements\movetype_handler.dm" +#include "code\datums\elements\nerfed_pulling.dm" #include "code\datums\elements\obj_regen.dm" #include "code\datums\elements\openspace_item_click_handler.dm" #include "code\datums\elements\pet_bonus.dm" #include "code\datums\elements\plant_backfire.dm" #include "code\datums\elements\point_of_interest.dm" +#include "code\datums\elements\prevent_attacking_of_types.dm" #include "code\datums\elements\rad_insulation.dm" #include "code\datums\elements\ranged_attacks.dm" #include "code\datums\elements\ridable.dm"