## About The Pull Request We accidentally lost this behaviour when we converted goats to basic mobs. _Formerly_ (and now again) goats had a 0.5% chance per second to simply decide to attack you for no reason at all. While attacking you they also have a 10% chance per second to get bored of doing that and stop. Additionally, we were outputting a fluff message every time you attacked a goat which would spam chat if you were trying to fist fight each other. I added a 20 second cooldown onto it. As is often the case, implementing this led me down a bit of a rabbit hole. We were previously bypassing faction checks via a mixture of flags on AI behaviours and blackboard keys. I have moved this _entirely_ to the blackboard now, rather than making targetting subtypes just to skip faction checks. This entails having one blackboard key which is "by default do we care about factions?" and another which is "are we currently ignoring factions for some other reason?" Retaliatory AI will generally enable the second flag, so you can get pissed off at someone you would usually not mind hanging out with if they start something with you. Certain mobs which want to hunt other mobs but not be hunted in return just ignore factions entirely all the time and use the former. The upshot of this is that the default behaviour for expected default retaliatory AI shouldn't require you to set any specific kind of targetting datum and will Just Work. In a similar vein because I was touching largely the same mobs I made the "flee when injured" component apply its "don't flee because not injured" flag instantly upon application rather than needing to manually set it in the blackboard definition, so that also Just Works. ## Changelog 🆑 fix: Pete's anger management training has worn off, and he will once again sometimes pick a fight with you for absolutely no reason. qol: Attacking a goat will not spam messages so frequently. /🆑 --------- Co-authored-by: san7890 <the@san7890.com>
AI controllers
Introduction
Our AI controller system is an attempt at making it possible to create modularized AI that stores its behavior in datums, while keeping state and decision making in a controller. This allows a more versatile way of creating AI that doesn't rely on OOP as much, and doesn't clutter up the Life() code in Mobs.
AI Controllers
A datum that can be added to any atom in the game. Similarly to components, they might only support a given subtype (e.g. /mob/living), but the idea is that theoretically, you could apply a specific AI controller to a big a group of different types as possible and it would still work.
These datums handle both the normal movement of mobs, but also their decision making, deciding which actions they will take based on the checks you put into their SelectBehaviors proc.
If behaviors are selected, and the AI is in range, it will try to perform them. It runs all the behaviors it currently has in parallel; allowing for it to for example screech at someone while trying to attack them. As long as it has behaviors running, it will not try to generate new plans, making it not waste CPU when it already has an active goal.
They also hold data for any of the actions they might need to use, such as cooldowns, whether or not they're currently fighting, etcetera this is stored in the blackboard, more information on that below.
Blackboard
The blackboard is an associated list keyed with strings and with values of whatever you want. These store information the mob has such as "Am I attacking someone", "Do I have a weapon". By using an associated list like this, no data needs to be stored on the actions themselves, and you could make actions that work on multiple ai controllers if you so pleased by making the key to use a variable.
AI Behavior
AI behaviors are the actions an AI can take. These can range from "Do an emote" to "Attack this target until he is dead". They are singletons and should contain nothing but static data. Any dynamic data should be stored in the blackboard, to allow different controllers to use the same behaviors.
Guides:
Making Your AI: Quickly runs through how to make an ai controller for anything with a step by step development of one.