Files
Bubberstation/code/datums/ai/monkey/monkey_subtrees.dm
SkyratBot e6f66d3a4a [MIRROR] Experiment with replacing weakrefs in AI blackboard with deleting signals, ideally making it easier to work with and harder to cause hard deletes [MDB IGNORE] (#20719)
* Experiment with replacing weakrefs in AI blackboard with deleting signals, ideally making it easier to work with and harder to cause hard deletes (#74791)

## About The Pull Request

Replaces weakref usage in AI blackboards with deleting signals

All blackboard var setting must go through setters rather than directly

## Why It's Good For The Game

This both makes it a ton easier to develop AI for, and also makes it
harder for hard deletes to sneak in, as has been seen with recent 515
prs showing hard deletes in AI blackboards

(To quantify "making it easier to develop AI", I found multiple bugs in
existing AI code due to the usage of weakrefs.)

I'm looking for `@ Jacquerel` `@ tralezab` 's opinions on the matter, also
maybe `@ LemonInTheDark` if they're interested

## Changelog

🆑 Melbert
refactor: Mob ai refactored once again
/🆑

* Experiment with replacing weakrefs in AI blackboard with deleting signals, ideally making it easier to work with and harder to cause hard deletes

---------

Co-authored-by: MrMelbert <51863163+MrMelbert@users.noreply.github.com>
2023-04-26 21:17:15 +01:00

70 lines
3.0 KiB
Plaintext

/datum/ai_planning_subtree/monkey_shenanigans/SelectBehaviors(datum/ai_controller/monkey/controller, seconds_per_tick)
if(prob(5))
controller.queue_behavior(/datum/ai_behavior/use_in_hand)
if(!SPT_PROB(MONKEY_SHENANIGAN_PROB, seconds_per_tick))
return
if(!controller.blackboard[BB_MONKEY_CURRENT_PRESS_TARGET])
controller.queue_behavior(/datum/ai_behavior/find_nearby, BB_MONKEY_CURRENT_PRESS_TARGET)
return
if(prob(50))
controller.queue_behavior(/datum/ai_behavior/use_on_object, BB_MONKEY_CURRENT_PRESS_TARGET)
return SUBTREE_RETURN_FINISH_PLANNING
if(!controller.blackboard[BB_MONKEY_CURRENT_GIVE_TARGET])
controller.queue_behavior(/datum/ai_behavior/find_and_set/pawn_must_hold_item, BB_MONKEY_CURRENT_GIVE_TARGET, /mob/living, 2)
else
if(prob(5))
controller.queue_behavior(/datum/ai_behavior/give, BB_MONKEY_CURRENT_GIVE_TARGET)
return SUBTREE_RETURN_FINISH_PLANNING
controller.TryFindWeapon()
///monkey combat subtree.
/datum/ai_planning_subtree/monkey_combat/SelectBehaviors(datum/ai_controller/monkey/controller, seconds_per_tick)
var/mob/living/living_pawn = controller.pawn
var/list/enemies = controller.blackboard[BB_MONKEY_ENEMIES]
if((HAS_TRAIT(controller.pawn, TRAIT_PACIFISM)) || (!length(enemies) && !controller.blackboard[BB_MONKEY_AGGRESSIVE])) //Pacifist, or we have no enemies and we're not pissed
living_pawn.set_combat_mode(FALSE)
return
if(!controller.blackboard[BB_MONKEY_CURRENT_ATTACK_TARGET])
controller.queue_behavior(/datum/ai_behavior/monkey_set_combat_target, BB_MONKEY_CURRENT_ATTACK_TARGET, BB_MONKEY_ENEMIES)
living_pawn.set_combat_mode(FALSE)
return SUBTREE_RETURN_FINISH_PLANNING
var/mob/living/selected_enemy = controller.blackboard[BB_MONKEY_CURRENT_ATTACK_TARGET]
if(QDELETED(selected_enemy))
living_pawn.set_combat_mode(FALSE)
return
if(!selected_enemy.stat) //He's up, get him!
if(living_pawn.health < MONKEY_FLEE_HEALTH) //Time to skeddadle
controller.queue_behavior(/datum/ai_behavior/monkey_flee)
return SUBTREE_RETURN_FINISH_PLANNING //I'm running fuck you guys
if(controller.TryFindWeapon()) //Getting a weapon is higher priority if im not fleeing.
return SUBTREE_RETURN_FINISH_PLANNING
if(controller.blackboard[BB_MONKEY_RECRUIT_COOLDOWN] < world.time)
controller.queue_behavior(/datum/ai_behavior/recruit_monkeys, BB_MONKEY_CURRENT_ATTACK_TARGET)
controller.queue_behavior(/datum/ai_behavior/battle_screech/monkey)
controller.queue_behavior(/datum/ai_behavior/monkey_attack_mob, BB_MONKEY_CURRENT_ATTACK_TARGET)
return SUBTREE_RETURN_FINISH_PLANNING
//by this point we have a target but they're down, let's try dumpstering this loser
living_pawn.set_combat_mode(FALSE)
if(!controller.blackboard[BB_MONKEY_TARGET_DISPOSAL])
controller.queue_behavior(/datum/ai_behavior/find_and_set, BB_MONKEY_TARGET_DISPOSAL, /obj/machinery/disposal, MONKEY_ENEMY_VISION)
return
controller.queue_behavior(/datum/ai_behavior/disposal_mob, BB_MONKEY_CURRENT_ATTACK_TARGET, BB_MONKEY_TARGET_DISPOSAL)
return SUBTREE_RETURN_FINISH_PLANNING