Files
Bubberstation/code/datums/components/boomerang.dm
san7890 ccef887efe Lints Against Unmanaged Local Defines (#74333)
# MAINTAINER - USE THE BUTTON THAT SAYS "MERGE MASTER" THEN SET THE PR
TO AUTO-MERGE! IT'S MUCH EASIER FOR ME TO FIX THINGS BEFORE THEY SKEW
RATHER THAN AFTER THE FACT.

## About The Pull Request

Hey there,

This took a while to do, but here's the gist:

Python file now regexes every file in `/code` except for those that have
some valid reason to be tacking on more global defines. Some of those
reasons are simply just that I don't have the time right now (doing what
you see in this PR took a few hours) to refactor and parse what should
belong and what should be thrown out. For the time being though, this PR
will at least _halt_ people making the mistake of not `#undef`ing any
files they `#define` "locally", or within the scope of a file.

Most people forget to do this and this leads to a lot of mess later on
due to how many variables can be unmanaged on the global level. I've
made this mistake, you've made this mistake, it's a common thing. Let's
automatically check for it so it can be fixed no-stress.

Scenarios this PR corrects:

* Forgetting to undef a define but undeffing others.
* Not undeffing any defines in your file.
* Earmarking a define as a "file local" define, but not defining it.
* Having a define be a "file local" define, but having it be used
elsewhere.
* Having a "local" define not even be in the file that it only shows up
in.
* Having a completely unused define*

(* I kept some of these because they seemed important... Others were
junked.)
## Why It's Good For The Game

If you wanna use it across multiple files, no reason to not make it a
global define (maybe there's a few reasons but let's assume that this is
the 95% case).

Let me know if you don't like how I re-arranged some of the defines and
how you'd rather see it be implemented, and I'd be happy to do that.
This was mostly just "eh does it need it or not" sorta stuff.

I used a pretty cool way to detect if we should use the standardized
GitHub "error" output, you can see the results of that here
https://github.com/san7890/bruhstation/actions/runs/4549766579/jobs/8022186846#step:7:792
## Changelog
Nothing that really concerns players.

(I fixed up all this stuff using vscode, no regexes beyond what you see
in the python script. sorry downstreams)
2023-03-29 10:17:03 -07:00

88 lines
4.6 KiB
Plaintext

///The cooldown period between last_boomerang_throw and it's methods of implementing a rebound proc.
#define BOOMERANG_REBOUND_INTERVAL (1 SECONDS)
/**
* If an ojvect is given the boomerang component, it should be thrown back to the thrower after either hitting it's target, or landing on the thrown tile.
* Thrown objects should be thrown back to the original thrower with this component, a number of tiles defined by boomerang_throw_range.
*/
/datum/component/boomerang
///How far should the boomerang try to travel to return to the thrower?
var/boomerang_throw_range = 3
///If this boomerang is thrown, does it re-enable the throwers throw mode?
var/thrower_easy_catch_enabled = FALSE
///This cooldown prevents our 2 throwing signals from firing too often based on how we implement those signals within thrown impacts.
COOLDOWN_DECLARE(last_boomerang_throw)
/datum/component/boomerang/Initialize(boomerang_throw_range, thrower_easy_catch_enabled)
. = ..()
if(!isitem(parent)) //Only items support being thrown around like a boomerang, feel free to make this apply to humans later on.
return COMPONENT_INCOMPATIBLE
//Assignments
if(boomerang_throw_range)
src.boomerang_throw_range = boomerang_throw_range
if(thrower_easy_catch_enabled)
src.thrower_easy_catch_enabled = thrower_easy_catch_enabled
/datum/component/boomerang/RegisterWithParent()
RegisterSignal(parent, COMSIG_MOVABLE_POST_THROW, PROC_REF(prepare_throw)) //Collect data on current thrower and the throwing datum
RegisterSignal(parent, COMSIG_MOVABLE_THROW_LANDED, PROC_REF(return_missed_throw))
RegisterSignal(parent, COMSIG_MOVABLE_IMPACT, PROC_REF(return_hit_throw))
/datum/component/boomerang/UnregisterFromParent()
UnregisterSignal(parent, list(COMSIG_MOVABLE_POST_THROW, COMSIG_MOVABLE_THROW_LANDED, COMSIG_MOVABLE_IMPACT))
/**
* Proc'd before the first thrown is performed in order to gather information regarding each throw as well as handle throw_mode as necessary.
* * source: Datum src from original signal call.
* * thrown_thing: The thrownthing datum from the parent object's latest throw. Updates thrown_boomerang.
* * spin: Carry over from POST_THROW, the speed of rotation on the boomerang when thrown.
*/
/datum/component/boomerang/proc/prepare_throw(datum/source, datum/thrownthing/thrown_thing, spin)
SIGNAL_HANDLER
if(thrower_easy_catch_enabled && thrown_thing?.thrower)
if(iscarbon(thrown_thing.thrower))
var/mob/living/carbon/Carbon = thrown_thing.thrower
Carbon.throw_mode_on(THROW_MODE_TOGGLE)
return
/**
* Proc that triggers when the thrown boomerang hits an object.
* * source: Datum src from original signal call.
* * hit_atom: The atom that has been hit by the boomerang component.
* * init_throwing_datum: The thrownthing datum that originally impacted the object, that we use to build the new throwing datum for the rebound.
*/
/datum/component/boomerang/proc/return_hit_throw(datum/source, atom/hit_atom, datum/thrownthing/init_throwing_datum)
SIGNAL_HANDLER
if (!COOLDOWN_FINISHED(src, last_boomerang_throw))
return
var/obj/item/true_parent = parent
aerodynamic_swing(init_throwing_datum, true_parent)
/**
* Proc that triggers when the thrown boomerang does not hit a target.
* * source: Datum src from original signal call.
* * throwing_datum: The thrownthing datum that originally impacted the object, that we use to build the new throwing datum for the rebound.
*/
/datum/component/boomerang/proc/return_missed_throw(datum/source, datum/thrownthing/throwing_datum)
SIGNAL_HANDLER
if(!COOLDOWN_FINISHED(src, last_boomerang_throw))
return
var/obj/item/true_parent = parent
aerodynamic_swing(throwing_datum, true_parent)
/**
* Proc that triggers when the thrown boomerang has been fully thrown, rethrowing the boomerang back to the thrower, and producing visible feedback.
* * throwing_datum: The thrownthing datum that originally impacted the object, that we use to build the new throwing datum for the rebound.
* * hit_atom: The atom that has been hit by the boomerang'd object.
*/
/datum/component/boomerang/proc/aerodynamic_swing(datum/thrownthing/throwing_datum, obj/item/true_parent)
var/mob/thrown_by = true_parent.thrownby?.resolve()
if(thrown_by)
addtimer(CALLBACK(true_parent, TYPE_PROC_REF(/atom/movable, throw_at), thrown_by, boomerang_throw_range, throwing_datum.speed, null, TRUE), 1)
COOLDOWN_START(src, last_boomerang_throw, BOOMERANG_REBOUND_INTERVAL)
true_parent.visible_message(span_danger("[true_parent] is flying back at [throwing_datum.thrower]!"), \
span_danger("You see [true_parent] fly back at you!"), \
span_hear("You hear an aerodynamic woosh!"))
#undef BOOMERANG_REBOUND_INTERVAL