Files
Bubberstation/code/datums/ai/objects/mod.dm
Stonetear 4756a44141 MODSuit procs now pass who clicked the UI button + misc code cleanup (#92424)
## About The Pull Request

Most of these changes are centered around removing `mod.wearer`
references in module function bubble alerts. However, I cleaned up a few
other things that I thought were easy fixes. ~~This PR should be
testmerged~~ nah send it. I think I did a pretty good job testing, but
there might be a bug or two I missed. (debug modsuit should allow
conflicting modules and have unlimited complexity btw)

### Track who clicks the activate button
* Adds `mob/activator` to `on_select()`, `activate()`, `deactivate()`,
`used()`, `on_activation()`, `on_deactivation()` and `on_use()`
* `mod_ui` now passes `ui.user`, which is who actually clicked the
button in the UI.1
* module action proc now passes the person clicking.
* **Alert bubbles:** Modifies many module code bubbles to pass the
activation bubble text to `mob/activator` instead of `mob.wearer` so
that pAIs get feedback on why clicking the button isn't working.

### Cargo clamp
* **Clamp code cleanup:** The cargo clamp now has a variable for the max
creature weight it can support, and the logic is changed around a bit to
support this.
* The cargo clamp uses an `accepted_items` typecache.

### Code cleanup
* **Button malfunction chance** is controlled by a
`MOD_MALFUNCTION_PROB` define.
* **Pathfinder runtime:** `mod_control`'s `GetAccess()` now checks if
there is an access before returning it. (This previously caused runtimes
when using the pathfinder module if you didn't swipe your ID)
* **Pathfinder code tweaks:** Reworks the code for the pathfinder module
a bit. Activation logic is now stored in the module instead of the
implant. The suit is prevented from being recalled by pAIs, which is
controlled by a variable.
* Adds `MODULE_ALLOW_UNWORN`, which lets you activate modules in suits
that aren't currently being worn. Module activation code now smoothly
supports modules being activated while not worn.
* Chameleon module now works when unworn.

This will probably be a Part 1, with a Part 2 to follow. Actions are
kinda funky and could probably be cleaned up a little better. Plus, I
want to make selectable modules theoretically usable by the AI, even if
I leave it disabled.

## Why It's Good For The Game

This PR doesn't contain any balance changes, and I manually disabled any
new serious functionality that pAIs might gain. (Such as being able to
activate the pathfinder implant) They *can* use the chameleon module
with no wearer- but I'm going to consider this a bug that they couldn't
before.

Paves the way for more pAI modsuit nonsense I'm doing downsteam.

## Changelog
🆑 Stonetear
refactor: MODsuit module code now knows who clicked the activation
button.
/🆑

---------

Co-authored-by: Ghom <42542238+Ghommie@users.noreply.github.com>
2025-09-07 10:27:38 +00:00

49 lines
1.9 KiB
Plaintext

/// An AI controller for the MODsuit pathfinder module. It's activated by module and attaches itself to the user.
/datum/ai_controller/mod
blackboard = list(
BB_MOD_TARGET,
BB_MOD_MODULE,
)
can_idle = FALSE
max_target_distance = MOD_AI_RANGE //a little spicy but its one specific item that summons it, and it doesn't run otherwise
ai_movement = /datum/ai_movement/jps/modsuit
///ID card generated from the suit's required access. Used for pathing.
var/obj/item/card/id/advanced/id_card
/datum/ai_controller/mod/TryPossessPawn(atom/new_pawn)
if(!istype(new_pawn, /obj/item/mod/control))
return AI_CONTROLLER_INCOMPATIBLE
var/obj/item/mod/control/mod = new_pawn
id_card = new /obj/item/card/id/advanced/simple_bot()
if(length(mod.req_access))
id_card.set_access(mod.req_access)
return ..() //Run parent at end
/datum/ai_controller/mod/UnpossessPawn(destroy)
QDEL_NULL(id_card)
return ..() //Run parent at end
/datum/ai_controller/mod/SelectBehaviors(seconds_per_tick)
current_behaviors = list()
if(blackboard[BB_MOD_TARGET] && blackboard[BB_MOD_MODULE])
queue_behavior(/datum/ai_behavior/mod_attach)
/datum/ai_controller/mod/get_access()
return id_card.GetAccess()
/datum/ai_behavior/mod_attach
behavior_flags = AI_BEHAVIOR_REQUIRE_MOVEMENT|AI_BEHAVIOR_MOVE_AND_PERFORM
/datum/ai_behavior/mod_attach/perform(seconds_per_tick, datum/ai_controller/controller)
if(!controller.pawn.Adjacent(controller.blackboard[BB_MOD_TARGET]))
return AI_BEHAVIOR_DELAY
var/obj/item/mod/module/pathfinder/module = controller.blackboard[BB_MOD_MODULE]
module.attach(controller.blackboard[BB_MOD_TARGET])
return AI_BEHAVIOR_DELAY | AI_BEHAVIOR_SUCCEEDED
/datum/ai_behavior/mod_attach/finish_action(datum/ai_controller/controller, succeeded)
. = ..()
controller.clear_blackboard_key(BB_MOD_TARGET)
var/obj/item/mod/module/pathfinder/module = controller.blackboard[BB_MOD_MODULE]
module.end_recall(succeeded)