Files
Bubberstation/code/datums/ai/basic_mobs/basic_subtrees/flee_target.dm
SkyratBot 80d1906bd1 [MIRROR] Basic Mobs can run away [MDB IGNORE] (#18196)
* Basic Mobs can run away (#71963)

## About The Pull Request

That's right I'm still atomising #71421, some day I might even post
something related to carp.
This PR adds various behaviours to basic mobs allowing them to run away,
in a couple of variations.

Mice will flee from anyone who doesn't share their factions, at all
times (so they will scatter from most humans, but not regal rats).
Rabbits and Sheep will flee from anyone who has attacked them.
Pigs will run away from people who have attacked them, but only if
they're below half health.

https://user-images.githubusercontent.com/7483112/207127135-d1737f91-d3f7-468a-ac60-7c7ae5d6623d.mp4

Mice are still plenty catchable because they don't run _very far_ (or
very fast) but I think the chase will be good enrichment.

To achieve this I had to change the signal COMSIG_CARBON_HEALTH_UPDATE
into COMSIG_LIVING_HEALTH_UPDATE but frankly the latter seems more
sensible anyway.

## Why It's Good For The Game

More behaviours to use later when designing mobs, gradually gives mobs
more things to do rather than just sort of moving aimlessly around the
area you left them in.
It'll give people hunting rats in maintenance some exercise.

## Changelog

🆑
add: Mice will now run away from you, you have to catch them if you want
to eat them. Use those traps!
add: Rabbits, Sheep, and Pigs likewise won't just sit there and let you
pulverise them if they can see an escape route.
/🆑

* Basic Mobs can run away

* Modular!

Co-authored-by: Jacquerel <hnevard@gmail.com>
Co-authored-by: Funce <funce.973@gmail.com>
2023-01-07 23:51:47 +13:00

16 lines
748 B
Plaintext

/// Try to escape from your current target, without performing any other actions.
/datum/ai_planning_subtree/flee_target
/// Behaviour to execute in order to flee
var/flee_behaviour = /datum/ai_behavior/run_away_from_target
/datum/ai_planning_subtree/flee_target/SelectBehaviors(datum/ai_controller/controller, delta_time)
. = ..()
if (!controller.blackboard[BB_BASIC_MOB_FLEEING])
return
var/datum/weakref/weak_target = controller.blackboard[BB_BASIC_MOB_CURRENT_TARGET]
var/atom/target = weak_target?.resolve()
if(!target || QDELETED(target))
return
controller.queue_behavior(flee_behaviour, BB_BASIC_MOB_CURRENT_TARGET, BB_BASIC_MOB_CURRENT_TARGET_HIDING_LOCATION)
return SUBTREE_RETURN_FINISH_PLANNING //we gotta get out of here.