Aggressive Ai Updated And My Experience Modding

tldr: new update to the AI in areas such as shrine placement, consulate and church upgrades, use of new cards by Africans and Inca such as houses gathering wood and age 2 neftenyas. improvements to dojo spawning by forcing yuumi so it doesnt constantly cancel production.

as always, anything I made or modified is free for anyone to use, no need to contact me. no credit is wanted or required, have fun with it.

                         Increasing Aggression

I actually reduced how aggressive the early ai can be by modifying the setMilPopLimit since I preferred a tech advantage over a larger military. it now maxes out at 50 units for each age under maximum to ensure speedy age ups, but if someone wants to massively increase aggression you can.

just change the limits to 160 for each age in setMilPopLimit, and reduce the priority in the ageUpgradeMonitor rule. expect a horde mode style relentless attack from the ai, but with significantly slower age up times.

notepad++ with language set to c++ makes reading and modifying it significantly easier. ctrl+f is your friend. ctrl-z to go back, ctrl+shift+z to go forward when troubleshooting mistakes.

                      Figuring Out Shrine Manager

I knew the forwardshrine manager was awful and that I could make something much better, but as I dug deeper into influenceposition and kbUnitQueryCreate I realized had I no idea how they worked. if anyone could explain them to me that would be great, because after hours of messing with them I’m still not certain on how they function.

I wanted the ai to check for viable hunts spreading outwards from the main base, with priority on those closer to main base and a preference for jap monks over villagers. this was harder than I realized and I’m still not satisfied completely with the result.

in the end in selectShrineBuildPlanPosition I made the search range into 1000 units, and made a linear falloff influence position of 1000 units as well with a 1000 point value. the results are significantly better than before, but I’m still not entirely happy with it.

I then thought of using a global bool to check if a jap monk was alive and if so use him, but again I wasn’t entirely sure how the kbUnitQueryCreate query worked or global bools for that matter.

so I went with a simpler solution of hacking repurposed tc code into the addbuilder section so that whenever an ai wanted to build a shrine, it would first look for a Japanese monk and if that failed a single villager. that solved the big issue of villagers walking halfway across the map to build a shrine.

I used that same code so that heroes are priority for trade posts.

                 Consulate Livestock Pen Issues

I found out while testing the ai that for some reason it liked to spam livestock pens after unlocking them at the consulate. this was unacceptable, and after failing to troubleshoot why this happened I resorted to addbuilder again.

whenever it wants to build a livestock pen it now checks if there is one already alive. if so, no builder is added to the livestock pen and none is built. hopefully this means the ai only loses 200 wood reserved for a new livestock pen, and it seems to work. whenever a livestock pen is destroyed the ai builds a single livestock pen to replace it.

                   Dojo And Plaza Spawning

ai just keeps switching dojo choices, resulting in lots of wasted seconds. I removed dojo switching in favor of just spamming Yumi. you can never go wrong with more Yumi.

also unit spawns from plaza are completely disabled except for warrior priests. they hurt the ai far more than they help, especially with the constant switching.

I also tried to get Inca to spawn priestess using Aztecs warrior priests as a basis, but that made the game crash. what’s up with that?

                   New Cards and Kancha Wood

thankfully most cards have the same techname as they are ingame, and that made them very easy to add, early kallanka being an exception. I wanted to do some more aggressive stuff, but as I am not entirely sure how influence manager functioned I held off on cards that buffed units like maigadi. early neftenyas are a compromise on that, though I’m not sure if this helps the ai enough to warrant its usage over a different card (probably not).

I knew as soon as I saw the patch notes that I wanted the ai to use wood gathering houses, and it was surprisingly easier than I expected. using factorytactic code as a basis and finding the inca house tactics file, inca houses now switch to wood when they have at least 1000 food in the bank and food is atleast 1/10 of the resources they own.

                              Going Forward

One of the things that I really wanted to implement was a chance for different individual ai strategies as well as teamwide fb aggression. having an ai execute a 5 hussar semi ff, a Spanish tower ff, a dutch pike flush, a German tower rush or an ottoman Fast revolt as well as a good human player, as well as a chance for a teamwide fb rush on a player would really put the ai in a place that i would say its nearly finished. but like unitquery I am not sure how ForwardBaseManager functions.

walls are a big issue and may need work from the devs for it to function optimally, but hey CWALLGATE IS HERE WE CAN START MODDING IT IN FOR EVERY CIV. its on the things I want to add to the ai for sure.

the Africans are a little strange and slow to age up, same for the Lakota. idk why, I haven’t touched their age up choices at all. but they fight very well.

overall the addition of an error message that explains the error when loading the map has made modding the ai much more fun, faster and less stressful, and I actually enjoyed messing around with it after this was implemented. major qol upgrade. the base ai is also so much better that i left most of it intact, mostly things like cards and unit compositions are modified. and that’s always a good sign, and hopefully an indicator of things to come.

thanks for reading, and gl hf.


Nice! I’d be sure to try it. One question, do Ijust need to enable it on the mods menu, or should I manually replace the AI file?

if you want to play online with others with the mod enabled and have steam, or want to make your own modifications(go crazy, have fun with it), rename the original to “main ai original” and drop in the file. just download the zip file from github and go to: Steam\steamapps\common\AoE3DE\Game\AI

otherwise mod manager is better since it auto updates and installs itself.

Thanks! I remember than in the old AOE3 you need to manually change them, I will use the mod manager.

I will try to tweak some things based on your files, fo you by any chance know what I can do to make ai revolt more often?

I made the ai choose to revolt based on game time, this is in: int chooseEuropeanPolitician()

the ai will always choose either merc contractor after 24 minutes, or between merc contractor and a revolution before that time. to change this remove the massive bonus merc contractor receives as well as the great penalties to revolutions after 24 minutes. simply add // to remove a line of code or /* */ to cover lots of code from being read by the ai, as well as adding an additional ) when needed to complete a sentence. if a sentence starts with more ( than it ends with ) or vice versa, it wont run. here is an example of me using // to remove the bonuses/penalties after 24 minutes and adding a ) to complete a sentence. also make sure every code under a sentance ends with ; (idk if they are called sentences in coder language, its just what I call them)

we use sentences to create a condition for the code to run, and can put multiple code under a condition through the use of { }, and then string multiple conditions with “else”

numChoices = position;
for (i = 0; < numChoices)
politician = xsArrayGetInt(gAgeUpPoliticians, i);
if ((politician == cTechDEPoliticianMercContractor)) //&& (xsGetTime() > 24 * 60 * 1000))
// xsArraySetInt(gPoliticianScores, i, xsArrayGetInt(gPoliticianScores, i) + 300);
if ((politician == cTechDEPoliticianMercContractor)) // && (xsGetTime() < 24 * 60 * 1000))
xsArraySetInt(gPoliticianScores, i, xsArrayGetInt(gPoliticianScores, i) + 20);

        if (politician == cTechDEPoliticianFederalNewYork || politician == cTechDEPoliticianFederalFlorida || politician == cTechDEPoliticianFederalIllinois)
				xsArraySetInt(gPoliticianScores, i, xsArrayGetInt(gPoliticianScores, i) + 5);
	if (gSPC == false)
		// Create array of revolutions to choose from
		for (i = 0; < xsArrayGetSize(gRevolutionList))
			politician = xsArrayGetInt(gRevolutionList, i);
			if (kbTechGetStatus(politician) == cTechStatusObtainable)
				xsArraySetInt(gAgeUpPoliticians, position, politician);
				position = position + 1;

		// Weight revolutions as appropriate
		for (i = numChoices; < position)
			politician = xsArrayGetInt(gAgeUpPoliticians, i);
			// Avoid revolting when we played more than 30 minutes or started to farm
				if (aiTreatyActive() == true)
				xsArraySetInt(gPoliticianScores, i, xsArrayGetInt(gPoliticianScores, i) - 900);
			//if (((xsGetTime() <= 24 * 60 * 1000 || gTimeToFarm == true || gTimeForPlantations == true)))
				xsArraySetInt(gPoliticianScores, i, xsArrayGetInt(gPoliticianScores, i) + 20);
			/*	else
				xsArraySetInt(gPoliticianScores, i, xsArrayGetInt(gPoliticianScores, i) + 10);
				if ((politician == cTechDERevolutionEgypt) && (kbGetCiv() == cCivOttomans))
				xsArraySetInt(gPoliticianScores, i, xsArrayGetInt(gPoliticianScores, i) + 5);*/

aiMain.txt (1.4 MB)

1 Like

there was an error in the original submission, just realized and fixed it. it should now be fully updated.

Very good explanation, I will try it with and without the change. Thanks for the mod!

fixed some major issues I overlooked, such as not actually fixing multiple tcs being queued, and bad age up logic that didn’t account for new African civs, as well as things like kallanka wagons not being used or towers in maximum age not being built.

also improved unit comps. china ai will steamroll you if your not careful.

Big update, fixing even more bugs I introduced to the code as well as enabling forts to be built by American generals, explorers and even Russian musketeers!

1 Like

I did noticed the AI building forts with this mod, it was good for helping them with defense. I had some feedback regarding some games I had with the mod but I’ll wait to see the updated version before I comment , hope you can upload it!

glad you liked it. I made some serious mistakes with the initial update, I fixed most of them and the ai should now attack constantly while guaranteed age 5 by 26 minutes on extreme.

that said I know there must still be plenty more issues with it and I would love a chance to fix them, don’t hesitate to tell me anything you don’t like about it.

the github has been updated if you want to try it now.

also if anyone can explain to me how forwardbasemanager works, I would really appreciate it. trying to make the Chinese AI build a forward base with its fort seems impossible to me, and could be bugged. here is the shoddy code I’ve been using meanwhile:
forwardbasemanager sample.txt (33.1 KB)

uploaded a patch that should fix the AI not attacking constantly, especially in the imperial age. ai should update counter units and build forward bases a little more as well.

many changes to the attack code, ai should now attack relentlessly and target units outside of bases. there are still flaws with it that I hope the devs will fix.

strongholds are now treated as forts by the inca ai, and use the same exact code. strongholdmonitor disabled in favor of using forwardbasemanager.

better default unit compositions and upgrade priority changes.

Hey man just wondering if you’re planning to update your AI mod? A lot of us are eagerly awaiting it.
Cheers, and thanks for your work!

sure, ive had the mexican patch version ready. default ai has advanced so much you will only see limited benefits though.

most of the change from my mod and default is army/deck comp, age up times/choices, consulate switching and max age ai auto feeding. getting shrines to build in a decent way is still beyond me however.

getting the ai to reliably research royal decree tehcnologies such as kalmucks, wild geese and rogers rangers seems impossible as well.

Any update with the new patch?

My friends and I use your mod to play Treaty 40mins vs 5 Expert AI and it’s a blast, the only drawback is that their decks are not great for treaty, but the nonstop aggression is fantastic, and makes for an enjoyable experience.

been busy with other games lately like Sifu, the old horizon game in preparation for the new one, and deserts of kharak.

I don’t think there would be many differences between the default ai and the mod in treaty. mostly things like army comp, focus on relevant unit cards and maxing town centers asap, and enforced quicker age ups in the mode. in all I think the recent improvements made by the default ai should cover some of those deficits.

ill release a new update by the weekend with some treaty focused changes though. removing age 2/3 unit shipments in favor of more eco upgrades and infinite natives when treaty is detected, along with walls (may not be optimally used).

1 Like

Thanks man, we are looking forward it!
Infact we would love the AI to be even more difficult if at all possible!



no walls, but it will play treaty better than default ai.

1 Like