mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2026-08-22 12:41:09 +01:00
This PR replaces our current NPC AI with a [behavior tree system](https://en.wikipedia.org/wiki/Behavior_tree_(artificial_intelligence,_robotics_and_control)). Behavior trees are a common way of creating AI in which you place nodes in a tree structure to define what actions an AI should take. AI controllers defined a list of /datum/ai_planning_subtree types in behavior_nodes. Each subtree was a self-contained unit that could call queue_behavior() to fire off /datum/ai_behavior actions. The controller iterated subtrees in order, each one deciding independently whether to queue something and deciding whether the next subtree would run. This has a few issues: 1. There's no real structure; you are just defining a list of things to try in order. 2. There was a loooot of subtrees that were basically the same as another but with some slight modification 3. It was hard to understand. Controllers now define a single json file describing a tree of nodes. The tree is composed of structural composites: Sequence - do A, then B, then C (and so on) Selector - try A, if it fails try B, then C (and so on) Parallel - run A and B simultaneously, with configurable failure/success policies and or looping behavior Subplan - loop a child continiously Along that we also have "Decorators". These are nodes that basically check a condition (E.g.; do we have a combat target). These decorators can be used to gate behavior and are re-useable across behavior trees. They also have a concept known as "Observers". Which lets them cancel lower priority behavior in case their condition changes (Which we check whenever a signal fires that fits that specific decorator). This makes the AI much more responsive to change in environment. For behaviors, we still use the ai_behavior datums. These are the actual behaviors such as "Move to X", "Attack X". The only major change is that these can no longer sleep() since they now run in the ai_controller. Lastly, we now also have subtrees, except now they are essentially pieces of behavior tree that can be re-used, or even overriden at runtime or as a variable. Allowing for making modular AI made out of several smaller trees. You can set variables on these nodes directly via the extension (see below), which should reduce the need to make subtypes of behaviors by a lot. All of these vars are saved on the JSON and will be applied at runtime. If you are using subtrees, you can also assign "bindings" to these variables, which will allow instances of the subtree to override those variables. Since a tree structure with variables becomes hard to parse in a JSON, I've made a VSCode extension to edit these JSONs: https://marketplace.visualstudio.com/items?itemName=BehaviorTreeG.behaviortreeg https://github.com/CabinetOnFire/BehaviorTreeG <img width="1795" height="1268" alt="image" src="https://github.com/user-attachments/assets/56aa2f0b-3cf9-449f-bca4-8281fca82db6" /> This extension allows you to edit the behavior tree JSONs, and browse through all the behaviors/decorators/subtrees we have If you'd like more info on how to build these AI check out the learn_ai.md. I will also make a tutorial to go over more depth on what the system offers because I kind of suck at doing technical write-ups. Targetting has been changed to. I've made a new acquire_targets behavior that takes a target_source (what am I targetting) and targetting_strategy (what does the candidate need to fulfill to be considered a target). This allows us to make composites targetting combinations to reduce the amount of specific find_and_set esque behaviors we had before. Not everything is ported to this system but that would be a longer term goal. I've added a new build_bt script that converts all the behavior tree JSONs into compiled versions. Why is this needed? Because I wanted to keep using defines in behavior trees, so we need a way to convert this into literal values before we send it to DM. This script runs on compile and should also run in CI (If I didn't fuck that up!). This saves to a new build/ folder. I've ported every single AI in the game to this system (except raptors, Kobsa is working on those so should be in soon!), so I do expect some bugs to come out of this. But I also fixed some issues that have probably been in the game for a long time such as: - Fixed penguins being unable to fish - Fixed bileworms not being able to devour people - Fixes goldgrubs not grubbing gold (they could not mine!) - Lizards actually eat food they find Either way, I'd reccomend a long TM on this. 1. (Hopefully) a better development experience for making AI 2. Less copy-paste for behaviors, we should be able to re-use more pieces to make behavior 3. Behavior trees is a more common pattern in making AI, so it should be easier to find resources to find out how to do things. 🆑 CabinetOnFire, Iamgoofball, SmartKar, Ben10omintrix refactor: Replaces our AI system with behavior trees, porting all datum/ai to it /🆑 I will add this PR with more details down the line. I think I got the big picture but its a big PR, so sorry if I missed something important. --------- Co-authored-by: Iamgoofball <iamgoofball@gmail.com> Co-authored-by: SmArtKar <44720187+SmArtKar@users.noreply.github.com> Co-authored-by: Ghom <42542238+Ghommie@users.noreply.github.com> Co-authored-by: Ben10Omintrix <138636438+Ben10Omintrix@users.noreply.github.com> Co-authored-by: SyncIt21 <110812394+SyncIt21@users.noreply.github.com>
300 lines
9.7 KiB
Plaintext
300 lines
9.7 KiB
Plaintext
//! Defines for subsystems and overlays
|
|
//!
|
|
//! Lots of important stuff in here, make sure you have your brain switched on
|
|
//! when editing this file
|
|
|
|
//! ## DB defines
|
|
/**
|
|
* DB major schema version
|
|
*
|
|
* Update this whenever the db schema changes
|
|
*
|
|
* make sure you add an update to the schema_version stable in the db changelog
|
|
*/
|
|
#define DB_MAJOR_VERSION 5
|
|
|
|
/**
|
|
* DB minor schema version
|
|
*
|
|
* Update this whenever the db schema changes
|
|
*
|
|
* make sure you add an update to the schema_version stable in the db changelog
|
|
*/
|
|
#define DB_MINOR_VERSION 35 // BUBBER EDIT
|
|
|
|
|
|
//! ## Timing subsystem
|
|
/**
|
|
* Don't run if there is an identical unique timer active
|
|
*
|
|
* if the arguments to addtimer are the same as an existing timer, it doesn't create a new timer,
|
|
* and returns the id of the existing timer
|
|
*/
|
|
#define TIMER_UNIQUE (1<<0)
|
|
|
|
///For unique timers: Replace the old timer rather then not start this one
|
|
#define TIMER_OVERRIDE (1<<1)
|
|
|
|
/**
|
|
* Timing should be based on how timing progresses on clients, not the server.
|
|
*
|
|
* Tracking this is more expensive,
|
|
* should only be used in conjunction with things that have to progress client side, such as
|
|
* animate() or sound()
|
|
*/
|
|
#define TIMER_CLIENT_TIME (1<<2)
|
|
|
|
///Timer can be stopped using deltimer()
|
|
#define TIMER_STOPPABLE (1<<3)
|
|
|
|
///prevents distinguishing identical timers with the wait variable
|
|
///
|
|
///To be used with TIMER_UNIQUE
|
|
#define TIMER_NO_HASH_WAIT (1<<4)
|
|
|
|
///Loops the timer repeatedly until qdeleted
|
|
///
|
|
///In most cases you want a subsystem instead, so don't use this unless you have a good reason
|
|
#define TIMER_LOOP (1<<5)
|
|
|
|
///Delete the timer on parent datum Destroy() and when deltimer'd
|
|
#define TIMER_DELETE_ME (1<<6)
|
|
|
|
///Empty ID define
|
|
#define TIMER_ID_NULL -1
|
|
|
|
/// Used to trigger object removal from a processing list
|
|
#define PROCESS_KILL 26
|
|
|
|
|
|
//! ## Initialization subsystem
|
|
|
|
///New should not call Initialize
|
|
#define INITIALIZATION_INSSATOMS 0
|
|
///New should call Initialize(TRUE)
|
|
#define INITIALIZATION_INNEW_MAPLOAD 2
|
|
///New should call Initialize(FALSE)
|
|
#define INITIALIZATION_INNEW_REGULAR 1
|
|
|
|
//! ### Initialization hints
|
|
|
|
///Nothing happens
|
|
#define INITIALIZE_HINT_NORMAL 0
|
|
/**
|
|
* call LateInitialize at the end of all atom Initialization
|
|
*
|
|
* The item will be added to the late_loaders list, this is iterated over after
|
|
* initialization of subsystems is complete and calls LateInitalize on the atom
|
|
* see [this file for the LateIntialize proc](atom.html#proc/LateInitialize)
|
|
*/
|
|
#define INITIALIZE_HINT_LATELOAD 1
|
|
|
|
///Call qdel on the atom after initialization
|
|
#define INITIALIZE_HINT_QDEL 2
|
|
|
|
///type and all subtypes should always immediately call Initialize in New()
|
|
#define INITIALIZE_IMMEDIATE(X) ##X/New(loc, ...){\
|
|
..();\
|
|
if(!(flags_1 & INITIALIZED_1)) {\
|
|
var/previous_initialized_value = SSatoms.initialized;\
|
|
SSatoms.initialized = INITIALIZATION_INNEW_MAPLOAD;\
|
|
args[1] = TRUE;\
|
|
SSatoms.InitAtom(src, FALSE, args);\
|
|
SSatoms.initialized = previous_initialized_value;\
|
|
}\
|
|
}
|
|
|
|
//! ### SS initialization hints
|
|
/**
|
|
* Negative values indicate a failure or warning of some kind, positive are good.
|
|
* 0 and 1 are unused so that TRUE and FALSE are guaranteed to be invalid values.
|
|
*/
|
|
|
|
/// Subsystem failed to initialize entirely. Print a warning, log, and disable firing.
|
|
#define SS_INIT_FAILURE -2
|
|
|
|
/// The default return value which must be overridden. Will succeed with a warning.
|
|
#define SS_INIT_NONE -1
|
|
|
|
/// Subsystem initialized successfully.
|
|
#define SS_INIT_SUCCESS 2
|
|
|
|
/// If your system doesn't need to be initialized (by being disabled or something)
|
|
#define SS_INIT_NO_NEED 3
|
|
|
|
/// Successfully initialized, BUT do not announce it to players (generally to hide game mechanics it would otherwise spoil)
|
|
#define SS_INIT_NO_MESSAGE 4
|
|
|
|
// Subsystem fire priority, from lowest to highest priority
|
|
// If the subsystem isn't listed here it's either DEFAULT or PROCESS (if it's a processing subsystem child)
|
|
#define FIRE_PRIORITY_IDLE_NPC 5
|
|
#define FIRE_PRIORITY_PING 10
|
|
#define FIRE_PRIORITY_SERVER_MAINT 10
|
|
#define FIRE_PRIORITY_RESEARCH 10
|
|
#define FIRE_PRIORITY_VIS 10
|
|
#define FIRE_PRIORITY_AMBIENCE 10
|
|
#define FIRE_PRIORITY_BLOOD_DRYING 10
|
|
#define FIRE_PRIORITY_GARBAGE 15
|
|
#define FIRE_PRIORITY_DATABASE 16
|
|
#define FIRE_PRIORITY_NPC_LOW 19
|
|
#define FIRE_PRIORITY_WET_FLOORS 20
|
|
#define FIRE_PRIORITY_AIR 20
|
|
#define FIRE_PRIORITY_ASSETS 20
|
|
#define FIRE_PRIORITY_HYPERSPACE_DRIFT 20
|
|
#define FIRE_PRIORITY_NPC 21
|
|
#define FIRE_PRIORITY_NPC_MOVEMENT 22
|
|
#define FIRE_PRIORITY_PATHFINDING 23
|
|
#define FIRE_PRIORITY_CLIFF_FALLING 24
|
|
#define FIRE_PRIORITY_PROCESS 25
|
|
#define FIRE_PRIORITY_THROWING 25
|
|
#define FIRE_PRIORITY_REAGENTS 26
|
|
#define FIRE_PRIORITY_SPACEDRIFT 30
|
|
#define FIRE_PRIORITY_SMOOTHING 35
|
|
#define FIRE_PRIORITY_OBJ 40
|
|
#define FIRE_PRIORITY_ACID 40
|
|
#define FIRE_PRIORITY_BURNING 40
|
|
#define FIRE_PRIORITY_DEFAULT 50
|
|
#define FIRE_PRIORITY_PARALLAX 65
|
|
#define FIRE_PRIORITY_INSTRUMENTS 80
|
|
#define FIRE_PRIORITY_FLUIDS 80
|
|
#define FIRE_PRIORITY_CAMERAS 85
|
|
#define FIRE_PRIORITY_PRIORITY_EFFECTS 90
|
|
#define FIRE_PRIORITY_MOBS 100
|
|
#define FIRE_PRIORITY_TGUI 110
|
|
#define FIRE_PRIORITY_TICKER 200
|
|
#define FIRE_PRIORITY_SINGULO 350
|
|
#define FIRE_PRIORITY_STATPANEL 390
|
|
#define FIRE_PRIORITY_CHAT 400
|
|
#define FIRE_PRIORITY_RUNECHAT 410
|
|
#define FIRE_PRIORITY_TTS 425
|
|
#define FIRE_PRIORITY_MOUSE_ENTERED 450
|
|
#define FIRE_PRIORITY_OVERLAYS 500
|
|
#define FIRE_PRIORITY_EXPLOSIONS 666
|
|
#define FIRE_PRIORITY_TIMER 700
|
|
#define FIRE_PRIORITY_SOUND_LOOPS 800
|
|
#define FIRE_PRIORITY_SPEECH_CONTROLLER 900
|
|
#define FIRE_PRIORITY_DELAYED_VERBS 950
|
|
#define FIRE_PRIORITY_INPUT 1000 // This must always always be the max highest priority. Player input must never be lost.
|
|
|
|
|
|
// SS runlevels
|
|
|
|
#define RUNLEVEL_LOBBY (1<<0)
|
|
#define RUNLEVEL_SETUP (1<<1)
|
|
#define RUNLEVEL_GAME (1<<2)
|
|
#define RUNLEVEL_POSTGAME (1<<3)
|
|
|
|
#define RUNLEVELS_DEFAULT (RUNLEVEL_SETUP | RUNLEVEL_GAME | RUNLEVEL_POSTGAME)
|
|
|
|
//SSticker.current_state values
|
|
/// Game is loading
|
|
#define GAME_STATE_STARTUP 0
|
|
/// Game is loaded and in pregame lobby
|
|
#define GAME_STATE_PREGAME 1
|
|
/// Game is attempting to start the round
|
|
#define GAME_STATE_SETTING_UP 2
|
|
/// Game has round in progress
|
|
#define GAME_STATE_PLAYING 3
|
|
/// Game has round finished
|
|
#define GAME_STATE_FINISHED 4
|
|
|
|
// Used for SSticker.force_ending
|
|
/// Default, round is not being forced to end.
|
|
#define END_ROUND_AS_NORMAL 0
|
|
/// End the round now as normal
|
|
#define FORCE_END_ROUND 1
|
|
/// For admin forcing roundend, can be used to distinguish the two
|
|
#define ADMIN_FORCE_END_ROUND 2
|
|
|
|
/**
|
|
Create a new timer and add it to the queue.
|
|
* Arguments:
|
|
* * callback the callback to call on timer finish
|
|
* * wait deciseconds to run the timer for
|
|
* * flags flags for this timer, see: code\__DEFINES\subsystems.dm
|
|
* * timer_subsystem the subsystem to insert this timer into
|
|
*/
|
|
#define addtimer(args...) _addtimer(args, file = __FILE__, line = __LINE__)
|
|
|
|
// Air subsystem subtasks
|
|
#define SSAIR_PIPENETS 1
|
|
#define SSAIR_ATMOSMACHINERY 2
|
|
#define SSAIR_ACTIVETURFS 3
|
|
#define SSAIR_HOTSPOTS 4
|
|
#define SSAIR_EXCITEDGROUPS 5
|
|
#define SSAIR_HIGHPRESSURE 6
|
|
#define SSAIR_SUPERCONDUCTIVITY 7
|
|
#define SSAIR_PROCESS_ATOMS 8
|
|
|
|
// Pipeline rebuild helper defines, these suck but it'll do for now //Fools you actually merged it
|
|
#define SSAIR_REBUILD_PIPELINE 1
|
|
#define SSAIR_REBUILD_QUEUE 2
|
|
|
|
// Explosion Subsystem subtasks
|
|
#define SSEXPLOSIONS_TURFS 1
|
|
#define SSEXPLOSIONS_MOVABLES 2
|
|
#define SSEXPLOSIONS_THROWS 3
|
|
|
|
// Machines subsystem subtasks.
|
|
#define SSMACHINES_MACHINES_EARLY 1
|
|
#define SSMACHINES_APCS_EARLY 2
|
|
#define SSMACHINES_APCS_ENVIRONMENT 3
|
|
#define SSMACHINES_APCS_LIGHTS 4
|
|
#define SSMACHINES_APCS_EQUIPMENT 5
|
|
#define SSMACHINES_APCS_LATE 6
|
|
#define SSMACHINES_MACHINES 7
|
|
#define SSMACHINES_MACHINES_LATE 8
|
|
|
|
// Weather susbsytem tasks
|
|
#define SSWEATHER_MOBS 1
|
|
#define SSWEATHER_TURFS 2
|
|
#define SSWEATHER_THUNDER 3
|
|
|
|
// Wardrobe subsystem tasks
|
|
#define SSWARDROBE_STOCK 1
|
|
#define SSWARDROBE_INSPECT 2
|
|
|
|
// Wardrobe cache metadata indexes
|
|
#define WARDROBE_CACHE_COUNT 1
|
|
#define WARDROBE_CACHE_LAST_INSPECT 2
|
|
#define WARDROBE_CACHE_CALL_INSERT 3
|
|
#define WARDROBE_CACHE_CALL_REMOVAL 4
|
|
|
|
// Wardrobe preloaded stock indexes
|
|
#define WARDROBE_STOCK_CONTENTS 1
|
|
#define WARDROBE_STOCK_CALL_INSERT 2
|
|
#define WARDROBE_STOCK_CALL_REMOVAL 3
|
|
|
|
// Wardrobe callback master list indexes
|
|
#define WARDROBE_CALLBACK_INSERT 1
|
|
#define WARDROBE_CALLBACK_REMOVE 2
|
|
|
|
// Subsystem delta times or tickrates, in seconds. I.e, how many seconds in between each process() call for objects being processed by that subsystem.
|
|
// Only use these defines if you want to access some other objects processing seconds_per_tick, otherwise use the seconds_per_tick that is sent as a parameter to process()
|
|
#define SSFLUIDS_DT (SSplumbing.wait/10)
|
|
#define SSMACHINES_DT (SSmachines.wait/10)
|
|
#define SSMOBS_DT (SSmobs.wait/10)
|
|
#define SSOBJ_DT (SSobj.wait/10)
|
|
|
|
// The change in the world's time from the subsystem's last fire in seconds.
|
|
#define DELTA_WORLD_TIME(ss) ((world.time - ss.last_fire) * 0.1)
|
|
|
|
/// The timer key used to know how long subsystem initialization takes
|
|
#define SS_INIT_TIMER_KEY "ss_init"
|
|
|
|
// Vote subsystem counting methods
|
|
/// First past the post. One selection per person, and the selection with the most votes wins.
|
|
#define VOTE_COUNT_METHOD_SINGLE 1
|
|
/// Approval voting. Any number of selections per person, and the selection with the most votes wins.
|
|
#define VOTE_COUNT_METHOD_MULTI 2
|
|
|
|
/// The choice with the most votes wins. Ties are broken by the first choice to reach that number of votes.
|
|
#define VOTE_WINNER_METHOD_SIMPLE "Simple"
|
|
/// The winning choice is selected randomly based on the number of votes each choice has.
|
|
#define VOTE_WINNER_METHOD_WEIGHTED_RANDOM "Weighted Random"
|
|
/// There is no winner for this vote.
|
|
#define VOTE_WINNER_METHOD_NONE "None"
|
|
|
|
/// Returned by [/datum/vote/proc/can_be_initiated] to denote the vote is valid and can be initiated.
|
|
#define VOTE_AVAILABLE "Vote Available"
|