From 3c56d0f4f3a29d698d89b538aad7de07fd5ffb9b Mon Sep 17 00:00:00 2001 From: Jordan Brown Date: Wed, 9 Aug 2017 10:06:15 -0400 Subject: [PATCH] Ports duplicated slipping code to a component (#29628) * Ports duplicated slipping code to a component * Makes metal not slippery * asdf * Instead of cherry picking like an idiot I could just copy paster * OOP * And blood, don't forget Fry's blood! * Further fixes * A more generic fashion * Use the new system * Fixes * Fix cartridge type * Remove inertia --- code/__DEFINES/components.dm | 2 ++ code/datums/components/README.md | 2 ++ code/datums/components/component.dm | 4 +++ code/datums/components/slippery.dm | 22 ++++++++++++++++ code/game/atoms.dm | 3 +++ code/game/atoms_movable.dm | 2 +- .../effects/effect_system/effects_foam.dm | 20 +++++++------- .../objects/items/devices/PDA/PDA_types.dm | 22 +++++++++------- .../game/objects/items/weapons/clown_items.dm | 9 +++---- code/game/turfs/open.dm | 26 +++++++++++++++++++ code/game/turfs/turf.dm | 18 ------------- code/modules/hydroponics/grown/banana.dm | 8 +++--- tgstation.dme | 1 + 13 files changed, 90 insertions(+), 49 deletions(-) create mode 100644 code/datums/components/slippery.dm diff --git a/code/__DEFINES/components.dm b/code/__DEFINES/components.dm index eb6826d67b7..0225dad6692 100644 --- a/code/__DEFINES/components.dm +++ b/code/__DEFINES/components.dm @@ -14,3 +14,5 @@ #define COMSIG_COMPONENT_ADDED "component_added" //when a component is added to a datum: (datum/component) #define COMSIG_COMPONENT_REMOVING "component_removing" //before a component is removed from a datum because of RemoveComponent: (datum/component) #define COMSIG_PARENT_QDELETED "parent_qdeleted" //before a datum's Destroy() is called: () +#define COMSIG_ATOM_ENTERED "atom_entered" //from base of atom/Entered(): (atom/movable, atom) +#define COMSIG_MOVABLE_CROSSED "movable_crossed" //from base of atom/movable/Crossed(): (atom/movable) diff --git a/code/datums/components/README.md b/code/datums/components/README.md index 84fa900764b..b76736debb8 100644 --- a/code/datums/components/README.md +++ b/code/datums/components/README.md @@ -75,6 +75,8 @@ Stands have a lot of procs which mimic mob procs. Rather than inserting hooks fo * Called on a component when a component of the same type was added to the same parent * See `/datum/component/var/dupe_mode` * `C`'s type will always be the same of the called component +1. `/datum/component/proc/AfterComponentActivated()` (abstract) + * Called on a component that was activated after it's `parent`'s `ComponentActivated()` is called 1. `/datum/component/proc/OnTransfer(datum/new_parent)` (abstract) * Called before the new `parent` is assigned in `TakeComponent()`, after the remove signal, before the added signal * Allows the component to react to ownership transfers diff --git a/code/datums/components/component.dm b/code/datums/components/component.dm index 719445fbacb..9ff9cc592f9 100644 --- a/code/datums/components/component.dm +++ b/code/datums/components/component.dm @@ -110,6 +110,9 @@ /datum/component/proc/OnTransfer(datum/new_parent) return +/datum/component/proc/AfterComponentActivated() + return + /datum/component/proc/_GetInverseTypeList(current_type) . = list(current_type) while (current_type != /datum/component) @@ -126,6 +129,7 @@ var/datum/component/C = target if(C.enabled && C.ReceiveSignal(arglist(args))) ComponentActivated(C) + C.AfterComponentActivated() return TRUE else for(var/I in target) diff --git a/code/datums/components/slippery.dm b/code/datums/components/slippery.dm new file mode 100644 index 00000000000..d445febeb5e --- /dev/null +++ b/code/datums/components/slippery.dm @@ -0,0 +1,22 @@ +/datum/component/slippery + var/intensity + var/lube_flags + var/mob/slip_victim + +/datum/component/slippery/New(datum/P, _intensity, _lube_flags = NONE) + ..() + intensity = max(_intensity, 0) + lube_flags = _lube_flags + if(ismovableatom(P)) + RegisterSignal(COMSIG_MOVABLE_CROSSED, .proc/Slip) + else + RegisterSignal(COMSIG_ATOM_ENTERED, .proc/Slip) + +/datum/component/slippery/proc/Slip(atom/movable/AM) + var/mob/victim = AM + if(istype(victim) && !victim.is_flying() && victim.slip(intensity, parent, lube_flags)) + slip_victim = victim + return TRUE + +/datum/component/slippery/AfterComponentActivated() + slip_victim = null diff --git a/code/game/atoms.dm b/code/game/atoms.dm index 6a00f26ffcf..09d08131794 100644 --- a/code/game/atoms.dm +++ b/code/game/atoms.dm @@ -610,3 +610,6 @@ GLOBAL_LIST_EMPTY(blood_splatter_icons) .["Add reagent"] = "?_src_=vars;addreagent=\ref[src]" .["Trigger EM pulse"] = "?_src_=vars;emp=\ref[src]" .["Trigger explosion"] = "?_src_=vars;explode=\ref[src]" + +/atom/Entered(atom/movable/AM, atom/oldLoc) + SendSignal(COMSIG_ATOM_ENTERED, AM, oldLoc) diff --git a/code/game/atoms_movable.dm b/code/game/atoms_movable.dm index 1edca6d632d..2686b08f54c 100644 --- a/code/game/atoms_movable.dm +++ b/code/game/atoms_movable.dm @@ -215,7 +215,7 @@ // This is automatically called when something enters your square //oldloc = old location on atom, inserted when forceMove is called and ONLY when forceMove is called! /atom/movable/Crossed(atom/movable/AM, oldloc) - return + SendSignal(COMSIG_MOVABLE_CROSSED, AM) //This is tg's equivalent to the byond bump, it used to be called bump with a second arg diff --git a/code/game/objects/effects/effect_system/effects_foam.dm b/code/game/objects/effects/effect_system/effects_foam.dm index 48260e02e1b..4dbb4c19ba2 100644 --- a/code/game/objects/effects/effect_system/effects_foam.dm +++ b/code/game/objects/effects/effect_system/effects_foam.dm @@ -29,6 +29,9 @@ metal = ALUMINUM_FOAM icon_state = "mfoam" +/obj/effect/particle_effect/foam/metal/MakeSlippery() + return + /obj/effect/particle_effect/foam/metal/iron name = "iron foam" metal = IRON_FOAM @@ -38,12 +41,16 @@ metal = RESIN_FOAM -/obj/effect/particle_effect/foam/New(loc) - ..(loc) +/obj/effect/particle_effect/foam/Initialize() + . = ..() + MakeSlippery() create_reagents(1000) //limited by the size of the reagent holder anyway. START_PROCESSING(SSfastprocess, src) playsound(src, 'sound/effects/bubbles2.ogg', 80, 1, -3) +/obj/effect/particle_effect/foam/proc/MakeSlippery() + AddComponent(/datum/component/slippery, 100) + /obj/effect/particle_effect/foam/Destroy() STOP_PROCESSING(SSfastprocess, src) return ..() @@ -101,15 +108,6 @@ lifetime-- return 1 -/obj/effect/particle_effect/foam/Crossed(atom/movable/AM) - if(istype(AM, /mob/living/carbon)) - var/mob/living/carbon/M = AM - M.slip(100, src) - -/obj/effect/particle_effect/foam/metal/Crossed(atom/movable/AM) - return - - /obj/effect/particle_effect/foam/proc/spread_foam() var/turf/t_loc = get_turf(src) for(var/turf/T in t_loc.GetAtmosAdjacentTurfs()) diff --git a/code/game/objects/items/devices/PDA/PDA_types.dm b/code/game/objects/items/devices/PDA/PDA_types.dm index 65e452b882e..7bc3a6d7048 100644 --- a/code/game/objects/items/devices/PDA/PDA_types.dm +++ b/code/game/objects/items/devices/PDA/PDA_types.dm @@ -7,16 +7,20 @@ desc = "A portable microcomputer by Thinktronic Systems, LTD. The surface is coated with polytetrafluoroethylene and banana drippings." ttone = "honk" -/obj/item/device/pda/clown/Crossed(AM as mob|obj) - if (istype(AM, /mob/living/carbon)) - var/mob/living/carbon/M = AM - if(M.slip(120, src, NO_SLIP_WHEN_WALKING)) - if (ishuman(M) && (M.real_name != src.owner)) - if (istype(src.cartridge, /obj/item/weapon/cartridge/virus/clown)) - var/obj/item/weapon/cartridge/virus/cart = src.cartridge - if(cart.charges < 5) - cart.charges++ +/obj/item/device/pda/clown/Initialize() + . = ..() + AddComponent(/datum/component/slippery, 120, NO_SLIP_WHEN_WALKING) +/obj/item/device/pda/clown/ComponentActivated(datum/component/C) + ..() + var/datum/component/slippery/S = C + if(!istype(S)) + return + var/mob/living/carbon/human/M = S.slip_victim + if (istype(M) && (M.real_name != src.owner)) + var/obj/item/weapon/cartridge/virus/clown/cart = cartridge + if(istype(cart) && cart.charges < 5) + cart.charges++ // Special AI/pAI PDAs that cannot explode. /obj/item/device/pda/ai diff --git a/code/game/objects/items/weapons/clown_items.dm b/code/game/objects/items/weapons/clown_items.dm index 567ac3672a4..8e5a3f1947a 100644 --- a/code/game/objects/items/weapons/clown_items.dm +++ b/code/game/objects/items/weapons/clown_items.dm @@ -23,6 +23,10 @@ var/cleanspeed = 50 //slower than mop force_string = "robust... against germs" +/obj/item/weapon/soap/Initialize() + . = ..() + AddComponent(/datum/component/slippery, 80) + /obj/item/weapon/soap/nanotrasen desc = "A Nanotrasen brand bar of soap. Smells of plasma." icon_state = "soapnt" @@ -48,11 +52,6 @@ new /obj/effect/particle_effect/foam(loc) return (TOXLOSS) -/obj/item/weapon/soap/Crossed(AM as mob|obj) - if (istype(AM, /mob/living/carbon)) - var/mob/living/carbon/M = AM - M.slip(80, src) - /obj/item/weapon/soap/afterattack(atom/target, mob/user, proximity) if(!proximity || !check_allowed_items(target)) return diff --git a/code/game/turfs/open.dm b/code/game/turfs/open.dm index 82ff907a045..494ea675a2b 100644 --- a/code/game/turfs/open.dm +++ b/code/game/turfs/open.dm @@ -194,6 +194,7 @@ if(wet >= wet_setting) return wet = wet_setting + UpdateSlip() if(wet_setting != TURF_DRY) if(wet_overlay) cut_overlay(wet_overlay) @@ -216,6 +217,30 @@ add_overlay(wet_overlay) HandleWet() +/turf/open/proc/UpdateSlip() + switch(wet) + if(TURF_WET_WATER) + AddComponent(/datum/component/slippery, 60, NO_SLIP_WHEN_WALKING) + if(TURF_WET_LUBE) + AddComponent(/datum/component/slippery, 80, SLIDE | GALOSHES_DONT_HELP) + if(TURF_WET_ICE) + AddComponent(/datum/component/slippery, 120, SLIDE | GALOSHES_DONT_HELP) + if(TURF_WET_PERMAFROST) + AddComponent(/datum/component/slippery, 120, SLIDE_ICE | GALOSHES_DONT_HELP) + if(TURF_WET_SLIDE) + AddComponent(/datum/component/slippery, 80, SLIDE | GALOSHES_DONT_HELP) + else + qdel(GetComponent(/datum/component/slippery)) + +/turf/open/ComponentActivated(datum/component/C) + ..() + var/datum/component/slippery/S = C + if(!istype(S)) + return + if(wet == TURF_WET_LUBE) + var/mob/living/L = S.slip_victim + L.confused = max(L.confused, 8) + /turf/open/proc/MakeDry(wet_setting = TURF_WET_WATER) if(wet > wet_setting || !wet) return @@ -228,6 +253,7 @@ wet = TURF_DRY if(wet_overlay) cut_overlay(wet_overlay) + UpdateSlip() /turf/open/proc/HandleWet() if(!wet) diff --git a/code/game/turfs/turf.dm b/code/game/turfs/turf.dm index b204406d058..e6147a3e452 100644 --- a/code/game/turfs/turf.dm +++ b/code/game/turfs/turf.dm @@ -165,24 +165,6 @@ /turf/open/Entered(atom/movable/AM) ..() - //slipping - if (istype(AM, /mob/living/carbon)) - var/mob/living/carbon/M = AM - if(M.movement_type & FLYING) - return - switch(wet) - if(TURF_WET_WATER) - if(!M.slip(60, null, NO_SLIP_WHEN_WALKING)) - M.inertia_dir = 0 - if(TURF_WET_LUBE) - if(M.slip(80, null, (SLIDE|GALOSHES_DONT_HELP))) - M.confused = max(M.confused, 8) - if(TURF_WET_ICE) - M.slip(120, null, (SLIDE|GALOSHES_DONT_HELP)) - if(TURF_WET_PERMAFROST) - M.slip(120, null, (SLIDE_ICE|GALOSHES_DONT_HELP)) - if(TURF_WET_SLIDE) - M.slip(80, null, (SLIDE|GALOSHES_DONT_HELP)) //melting if(isobj(AM) && air && air.temperature > T0C) var/obj/O = AM diff --git a/code/modules/hydroponics/grown/banana.dm b/code/modules/hydroponics/grown/banana.dm index e2dce252e75..5c7ee500521 100644 --- a/code/modules/hydroponics/grown/banana.dm +++ b/code/modules/hydroponics/grown/banana.dm @@ -115,8 +115,6 @@ name = "synthesized banana peel" desc = "A synthetic banana peel." -/obj/item/weapon/grown/bananapeel/specialpeel/Crossed(AM) - if(iscarbon(AM)) - var/mob/living/carbon/carbon = AM - if(carbon.slip(40, src, FALSE)) - qdel(src) +/obj/item/weapon/grown/bananapeel/specialpeel/Initialize(AM) + . = ..() + AddComponent(/datum/component/slippery, 40) diff --git a/tgstation.dme b/tgstation.dme index 202000a7627..f65c289bd39 100644 --- a/tgstation.dme +++ b/tgstation.dme @@ -250,6 +250,7 @@ #include "code\datums\antagonists\devil.dm" #include "code\datums\antagonists\ninja.dm" #include "code\datums\components\component.dm" +#include "code\datums\components\slippery.dm" #include "code\datums\diseases\_disease.dm" #include "code\datums\diseases\_MobProcs.dm" #include "code\datums\diseases\anxiety.dm"