@EvilleJedi wrote:
I needed to fix some AI issues I was having and I still haven’t located some of the issues, but I did make a map of the existing AI files
a few notes
I don’t know why there is a default.lua and cpuresource.lua in the AI folder and then a copy in the ai/default folder, it seems like they are just overwritten
also it is key to note that there are a lot of included files across the whole file structure, which makes it a pain to cross reference, my suggestion isa text editor that can have multiple tabs and view panes.
the prefix K refers to specific ships
the prefix E refers to classes of ships in ai/classdef.luaships need to be in the races build.lua and then in the ai/classdef.lua to be found by the AI
another very confusing thing is that any function prefeced with PROC_ is used to overwrite the function with the race specific version in scripts/races/XXXX/scripts
important files in the races scripts are the following
ai_build.lua
ai_upgrades.lua
def_research.lua
def_build.lua
research/default.lua
research/ai_properties.luahere is the pseudo code map with comments, start with AI/default/default.lua
ONINIT() --called at game start { CLASSINITIALIZE() --loads ships into classes based on classdef.lua SUPER IMPORTANT to put ships in these lists!!!! CPUBUILDINIT() --gets unit caps and sets difficulty scaling CPUBUILDSS_INIT() --allows for race specific overrides CPURESOURCE_INIT() --sets number of resourcers per path and latch and the min and max resourcers to build OVERRIDE_RESOURCEINIT() --if you provide your own in a mission it will allow you to overwrite the default AI CPUPERSONALITYDEMAND() --based on race sets the mix of FIghter, corvette, frigate OVERRIDE_BUILDDEMANDINIT() --if you provide your own in a mission it will allow you to overwrite the default AI CPURESEARCHINIT() --sets dificulty level timings for researching OVERRIDE_RESEARCHINIT() --if you provide your own in a mission it will allow you to overwrite the default AI CPUMILITARYINIT()--based on difficulty set parameters DOAI() -- call this every 2 seconds } DOAI() --executed every 2 seconds { CACHECURRENTSTATE() --determine avaialble production queues, player military value and enemy military value CALCOPENBUILDCHANNELS() --based on number of ships with build capability, resourcers and rus determine how many channels you can support to build SPENDMONEY() --based on difficulty level delay and available resources execute multiple times, essentially like the player clicking multiple ships CPU_BUILDPROCESS() --main build function SHIPDEMANDCLEAR() --Call to core game function CPUBUILD_REMOVEBUILDITEMS() --just calls REMOVESTALLEDBUILDITEMS() REMOVESTALLEDBUILDITEMS() --Call to core game function OVERRIDE_SHIPDEMAND() --if you provide your own in a mission it will allow you to overwrite the default AI CPUBUILD_DEFAULTSHIPDEMANDRULES() -- based on difficulty this will get reassigned by the race specific version in //scripts/races CALCULATEMILITARYVALUEGOAL() --based on the difficulty sets how much ship value you should have for specific points in the game 1800 seconds is max size, hard/expert is uncapped, tables are in CPU_BUILDDEFAULTSHIPDEMANDRULES_XXXX() DETERMINECLASSDEMAND() --iterate through class list SHIPDEMANDSETBYCLASS()--provide a race specific base level for class demands SHIPDEMANDSETBYCLASS(euselessships) -- forces the AI to ignore these ships, make sure they aren't in other eclasses DETERMINECOUNTERDEMAND() --basically if the enemy has at least three ships find a counter DETERMINECHASSISDEMAND() --compare the enemies antifighter, anticorvette and antifrigate power to a race specific threshold SHIPDEMANDADDBYCLASS(efighter) -- based on enemy antifighter power add a demand for fighters SHIPDEMANDADDBYCLASS(ecorvette) -- based on enemy anticorvette power add a demand for corvettes SHIPDEMANDADDBYCLASS(efrigate) -- based on enemy antifrigate power add a demand for frigates DETERMINEANTICHASSISDEMAND() --compare the enemies fighter,corvette and frigate power to current player fleet SHIPDEMANDADDBYCLASS(efighter) -- based on enemy fighter power add a demand for antifighters SHIPDEMANDADDBYCLASS(ecorvette) -- based on enemy corvette power add a demand for anticorvettes SHIPDEMANDADDBYCLASS(efrigate) -- based on enemy frigate power add a demand for antifrigates DETERMINEDEMANDWITHNOCOUNTERINFO() -- essentially just randomly select a ship PROC_DETERMINEDEMANDWITHNOCOUNTERINFO() --this provides the override function to use the race specific version of the file SHIPDEMANDADDBYCLASS(eantifrigate) -- boost anti frigate if more than 5 ships DETERMINESPECIALDEMAND() --this is the pain in the ass function, specific rules SHIPDEMANDGET() -- used to determine if a specific ship has been ordered DETERMINESCOUTDEMAND() --based on rush timer, resources, underattack and enemeies build a number of scouts SHIPDEMANDADDBYCLASS(escout) --add demand for a scout class ship SHIPDEMANDADD(Kscout) --provision to randomly demand a specific scout DETERMINEBUILDERCLASSDEMAND() --determine how many builders now and queued and based on difficulty and if we are struggling militarily, also has provisions for how many resources and resourers to have before constructing a new builder SHIPDEMANDADDBYCLASS(ebuilder) -- add or reduce demand for a builder DORESOURCEBUILD() --if we have resource demand and negtive military demand CALCDESIREDNUMCOLLECTORS() -- based on difficulty and population build set number of resources to build BUILD(kcollector) -- build a set amount of resourcers and then scale SHIPDEMANDADDBYCLASS(erefinery) -- add refineries based on resourcers SHIPDEMANDADDBYCLASS(esalvage) -- add salvage drop offs based on resources being salvage DOMILITARYBUILD() --really just determines if we should build the ship or a subsystem FINDHIGHDEMANDSHIP() -- Call to core game function HIGHESTPRIORITYSHIP() -- Call to core game function UNDERATTACKTHREAT() -- Call to core game function BUILD(SHIPID) -- build a ship!!!!! CPUBUILDSS_DOBUILDSUBSYSTEM() CPURESEARCHPROCESS() CPUMILITARYPROCESS() --based on game option delay execution, default 60 seconds, determine enemies and ally counts and if outnumbered LOGIC_MILITARY_GROUPVARS() --determine the number and value of squads, if outnumbered, double up LOGIC_MILITARY_ATTACKRULES() --only on easy, if outnumbered, stop attacking until built up LOGIC_MILITARY_SETATTACKTIMER() -- based on AI option in game rules, delay 1x, if defense delay 4x, if aggessive delay 0.5x and if dynamic randomly delay ATTACK_NOW_TIMER()--call based on AI and game mode setting ATTACKNOW() -- Call to core game function }
Posts: 3
Participants: 3