v47+ note - the page numbers for sections 4+ will be slightly different in the actual version (since I'm no longer showing the section 3 topics below I wont be updating the below listings often)
- Overview 35
1.1) AI goals 35
1.2) Background 36
1.3) Approach 36 - Setup and background 37
2.1) Lua editors and IDEs 37
2.1.1) Intellij IDEA 37
2.1.2) Visual Studio (VS) 38
2.2) Other guides which include a section on AI: 39
2.2.1) General information: 39
2.2.2) How AI in FAF works 39
2.2.3) AI markers and how AI uses them: 40
2.2.4) Hooking (e.g. replacing/appending existing game code) 40
2.2.5) Creating custom scripts for Sorian AI: 40
2.2.6) Pathfinding 40
2.2.7) How platoons work 40
2.2.8) AI Research (non-FAF related) 41
2.3) Lua coding 41
2.3.1) How to code in Lua 41
2.3.2) Stand alone Lua code testing 41
2.3.3) Lua optimisation 41
2.3.4) Common causes of errors for non-Lua coders 41
2.4) Debugging in FAF 42
2.4.1) Console 42
2.4.2) Cheats 42
2.4.3) Log window and error messages 42
2.4.4) Debug window and shortcuts 43
2.4.5) Platoon names for debugging 43
2.4.6) Function hooks and identifying infinite loops 43
2.4.7) Destroyed objects 44
2.4.8) Fast speed 44
2.4.9) In-game tools and information 44
2.4.10) Other shortcuts and game startup options 46
2.4.11) Suggested shortcut 47
2.4.12) Using FAF Develop 48
2.4.13) Error handling 49
2.4.14) Optimisation – benchmarks and monitoring 50
2.4.15) Debugging via replay 51
2.5) AI development discord 52
2.6) Core FAF Lua files 53
2.6.1) Accessing core Lua code 53
2.6.2) Other built in functions 53
2.6.3) Unit blueprints 53
2.7) Testing AI against other AI 54
2.7.1) Simple offline testing 54
2.7.2) Mass offline AI testing 55
2.8) Getting started – using a simple AI template as a starting point 56
2.9) Downloading and setting up MicroAI 56
2.10) Giving the AI mod your own name 56
2.11) General - Hooks, and getting the code to recognise if it’s running your AI 56
2.11.1) Hooking – Unit callbacks/events – applied example 57
2.12) Github 61
2.12.1) Github advantages and Github desktop 61
2.12.2) Linking Github with a local repo via creating your own init file 61
2.12.3) Pro Git ebook 61
2.12.4) Git commit messages 62
2.12.5) Own notes – contributing to FAF Git 62
2.13) Uploading your AI to FAF 62
2.13.1) Pre-upload checklist 62
2.13.2) FAF rules on uploading mods 62
2.13.3) Uploading to FAF 63
2.14) Other AI documentation 63 - AI changes 63
3.1) Build order - Changing the initial build order 63
3.1.1) Adding/removing buildings 63
3.1.2) Change build order based on map resource positions 64
3.1.3) Build order conditions 64
3.2) Build order – ACU builds without moving at start 65
3.2.1) BaseTemplate 65
3.3) Build factory and power to benefit from adjacency 66
3.3.1) Record all mexes on the map, and reference this information 66
3.3.2) Determine com start position 67
3.3.3) Identify mexes near to start 68
3.3.4) Hook onto the core code relating to building a structure at a location 68
3.3.5) Call build order from custom aiBrain function, to edit how things are built 69
3.3.6) Adjust build template based on mex location - conditions 70
3.3.7) Adjust build template based on mex location – build location adjustment 70
3.3.8) Build initial PGens by existing factory 71
3.3.9) Adjacency bonus where ACU is away from start location 73
3.3.10) Referencing unit blueprints for information such as unit size 75
3.4) Platoons and sending engineers to reclaim 77
3.4.1) How platoons work 77
3.4.2) Send the first engineer on reclaim duty 82
3.4.3) Determine where to send the engineer to reclaim 83
3.4.4) Identifying reclaim mass value 84
3.4.5) Find out if a location is accessible by ground: 84
3.4.6) Mapping reclaim locations and assigning preferred location to an engineer 86
3.4.7) Don’t send early reclaiming engi if there’s minimal starting reclaim 86
3.4.8) Issue new reclaim command if engineer becomes idle 87
3.4.9) Send more engineers to reclaim later (as lower priority) based on the reclaim currently on the map 87
3.4.10) Send 5 engineers at the start to reclaim and build mexes 88
3.4.11) Reclaiming trees when no main mass left 89
3.5) Building and assisting hydro 89
3.5.1) Check if hydro near start area and have engineer build hydro 89
3.5.2) Have ACU assist engineer with hydro 90
3.5.3) Get ACU to continue build order after hydro complete 90
3.5.4) Subsequent build order changes 92
3.6) Attack force composition changes and check of AI performance 92
3.6.1) Build Moar Tanks 92
3.7) Pre-v1: AI Progress check 92
3.7.1) Land factory buildings and other build order refinements 93
3.8) Raiding AI 95
3.8.1) Raiding behaviour - overview 95
3.8.2) Queue up move commands for mexes 95
3.8.3) Identify mexes to target 96
3.8.4) Locating mexes near to an existing pathing route 98
3.8.5) Determine when raiders need new targets 99
3.8.6) Handling complications (stuck units, move orders built on, platoon units dying) 99
3.8.7) Change factory rally point so units are assigned orders sooner 101
3.8.8) Making use of platoon names for debugging 103
3.8.9) Ensure 1 land scout included in each platoon 104
3.8.10) Use microbots before switching to tanks 104
3.8.11) Have scouts stay with the platoon 106
3.8.12) AI scouting, threat detection, and identifying nearby enemy units 107
3.8.13) Attack engineers en-route: Overview 110
3.8.14) Tracking when have reached movement points 110
3.8.15) Determining the platoon minimum range 110
3.8.16) Identifying nearby enemy units and assessing their threat 112
3.8.17) Actions based on enemy threat 114
3.8.18) Avoid attacking enemy mexes for small platoons 115
3.8.19) Other issues – cheating, walls and min range 116
3.8.20) Larger raiding platoons 117
3.9) Large attack wave 117
3.9.1) Checking when to form a large attack wave 117
3.9.2) Generalising raider AI 118
3.9.3) Creating separate platoon AI for the large attack force 118
3.9.4) Run nearer to base when outnumbered 119
3.9.5) Recalling nearby raiders to join attack force 119
3.9.6) Updating threat assessment for ACU health and upgrades 121
3.9.7) Don’t chase small numbers of faster units 122
3.9.8) Switch to hunt and kill enemies once reached destination 124
3.10) Pre-v1: AI Progress check 124
(3.11 onwards - left out due to post size limitations) - Future possible changes 512
- Index of useful functions 592
5.1) Map, game setup and general aiBrain information 594
5.1.1) aiBrain - general 594
5.1.2) AI Brain – Economy 595
5.1.3) Map Markers and start positions 596
5.1.4) Map size and playable area 597
5.1.5) Terrain info 597
5.2) Getting a list of units by category, location, or other method 598
5.2.1) All units that meet a particular category 598
5.2.2) Units at/near a location 599
5.3) Unit information 600
5.3.1) Units on radar 600
5.3.2) Blueprints and unit categories 600
5.3.3) Unit upgrades (enhancements) 602
5.3.4) See 5.4.10) Other unit commands 602
5.3.5) Location and pathfinding 602
5.3.6) Unit’s ai Brain owner 602
5.3.7) Unit’s current commands and whether it’s alive 603
5.3.8) Unit bones 603
5.3.9) Shields 603
5.3.10) Units with missiles/anti-nukes 603
5.3.11) Unit resource usage 604
5.4) Unit and platoon commands 604
5.4.1) Building 604
5.4.2) Assisting 605
5.4.3) Pausing 605
5.4.4) Reclaim 605
5.4.5) Factory specific commands 605
5.4.6) Movement and attack-move 606
5.4.7) Transport 606
5.4.8) Combat related 607
5.4.9) Stopping 607
5.4.10) Other unit commands 607
5.4.11) Upgrades and enhancements 607
5.4.12) Current commands and targets 608
5.4.13) Unit status 608
5.4.14) Change a unit’s name 610
5.5) Platoon additional functions 610
5.5.1) Units platoon handle 610
5.5.2) Get AIBrain 610
5.5.3) Get units in a platoon 610
5.5.4) Disband 610
5.5.5) Platoon exists 610
5.5.6) Platoon position 610
5.5.7) Get all platoons 611
5.5.8) Platoon ai plan name 611
5.5.9) Add units to a platoon 611
5.5.10) Army pool and removing units from a platoon 611
5.5.11) Create a platoon 611
5.5.12) Change or reset an AI plan 612
5.5.13) Platoon movement formation 612
5.6) Weapon information 612
5.6.1) Get a unit’s weapon 612
5.6.2) Get information on that weapon 612
5.7) Time and thread related 612
5.7.1) Game time 612
5.7.2) System time 613
5.7.3) Wait/delay the code 613
5.7.4) Fork thread (run independently) 613
5.8) Events 614
5.8.1) Creating custom events 616
5.9) Changing the game itself 616
5.9.1) Spawning units 616
5.10) Other 616
5.10.1) Visual changes – Draw Circles and Lines 616
5.10.2) On Intel Change 617
5.10.3) ScenarioInfo.Options 617