How to get the AI to build walls

You can talk about anything here

Moderator: Global Moderator

Post Reply
User avatar
murdilator
N3O Member
N3O Member
Posts: 249
Joined: Sat Sep 20, 2008 10:29 pm
Location: Norway

How to get the AI to build walls

Post by murdilator »

Basically, I wrote this up for somebody on HG.

DISCLAIMER: I only put this up for people who wanted to add walls to their AI without changing it, and to help them modify their AIs and stuff. I put it up here so that people who want to play AOE3 can make their computer more challenging and more NR material. Of course, I will always have the opinion that my works constitutes the best yet depiction of NR :), but there is always room for being disproved.

------------------------------

It is possible to get the AI to build walls, almost always.


An answer to your question about Asian AIs, and Aztecs for that matter - the reason they don't build gates is because Gates aren't enabled for these civs in the techtreey + techtreex; they merely have the "transform gate" option available to them. Thus though humans can use this ability, computer players cannot, because they are based on scripting, not on clicking any special abilities.

So, in order to get them to build gates, you have to add Gates to their Age0Tech. The needed Age0Techs are Age0XPAztec, ypAge0IndiansBuildings, ypAge0JapaneseBuildings, and ypAge0ChineseBuildings. Here is some added stuff the the Age0XPAztec tech:

Code: Select all

			<Effect type ='Data' amount ='1.00' subtype ='Enable' relativity ='Absolute'>
				<Target type ='ProtoUnit'>WallStraight2</Target></Effect>
			<Effect type ='Data' amount ='1.00' subtype ='Enable' relativity ='Absolute'>
				<Target type ='ProtoUnit'>Plantation</Target></Effect>
			<Effect type ='Data' amount ='1.00' subtype ='Enable' relativity ='Absolute'>
				<Target type ='ProtoUnit'>CWallGate</Target></Effect>
			<Effect type ='Data' amount ='1.00' subtype ='Enable' relativity ='Absolute'>
				<Target type ='ProtoUnit'>WallConnector</Target></Effect>
			<Effect type ='Data' amount ='1.00' subtype ='Enable' relativity ='Absolute'>
				<Target type ='ProtoUnit'>WallStraight5</Target></Effect>

Now to the ypAge0IndianBuildings:

Code: Select all

	<Tech name ='ypAge0IndiansBuildings' type ='Normal'>
		<DBID>5173</DBID>
		<Effects>
			<Effect type ='Data' amount ='1.00' subtype ='Enable' relativity ='Absolute'>
				<Target type ='ProtoUnit'>YPBarracksIndian</Target></Effect>
			<Effect type ='Data' amount ='1.00' subtype ='Enable' relativity ='Absolute'>
				<Target type ='ProtoUnit'>ypBerryBuilding</Target></Effect>
			<Effect type ='Data' amount ='1.00' subtype ='Enable' relativity ='Absolute'>
				<Target type ='ProtoUnit'>ypCaravanserai</Target></Effect>
			<Effect type ='Data' amount ='1.00' subtype ='Enable' relativity ='Absolute'>
				<Target type ='ProtoUnit'>ypCastle</Target></Effect>
			<Effect type ='Data' amount ='1.00' subtype ='Enable' relativity ='Absolute'>
				<Target type ='ProtoUnit'>ypConsulate</Target></Effect>
			<Effect type ='Data' amount ='1.00' subtype ='Enable' relativity ='Absolute'>
				<Target type ='ProtoUnit'>YPDockAsian</Target></Effect>
			<Effect type ='Data' amount ='1.00' subtype ='Enable' relativity ='Absolute'>
				<Target type ='ProtoUnit'>ypSacredField</Target></Effect>
			<Effect type ='Data' amount ='1.00' subtype ='Enable' relativity ='Absolute'>
				<Target type ='ProtoUnit'>ypRicePaddy</Target></Effect>
			<Effect type ='Data' amount ='1.00' subtype ='Enable' relativity ='Absolute'>
				<Target type ='ProtoUnit'>ypMonastery</Target></Effect>
			<Effect type ='Data' amount ='1.00' subtype ='Enable' relativity ='Absolute'>
				<Target type ='ProtoUnit'>ypTradeMarketAsian</Target></Effect>
			<Effect type ='Data' amount ='1.00' subtype ='Enable' relativity ='Absolute'>
				<Target type ='ProtoUnit'>ypHouseIndian</Target></Effect>
			<Effect type ='Data' amount ='1.00' subtype ='Enable' relativity ='Absolute'>
				<Target type ='ProtoUnit'>ypGroveBuilding</Target></Effect>
			<Effect type ='Data' amount ='1.00' subtype ='Enable' relativity ='Absolute'>
				<Target type ='ProtoUnit'>CWallGate</Target></Effect>
			<Effect type ='Data' amount ='1.00' subtype ='Enable' relativity ='Absolute'>
				<Target type ='ProtoUnit'>WallConnector</Target></Effect>
			<Effect type ='Data' amount ='1.00' subtype ='Enable' relativity ='Absolute'>
				<Target type ='ProtoUnit'>WallStraight2</Target></Effect>
			<Effect type ='Data' amount ='1.00' subtype ='Enable' relativity ='Absolute'>
				<Target type ='ProtoUnit'>WallStraight5</Target></Effect>
			<Effect type ='Data' amount ='1.00' subtype ='Enable' relativity ='Absolute'>
				<Target type ='ProtoUnit'>TradingPost</Target></Effect>
			<Effect type ='Data' amount ='1.00' subtype ='Enable' relativity ='Absolute'>
				<Target type ='ProtoUnit'>TownCenter</Target></Effect>
			<Effect type ='Data' amount ='1.00' subtype ='Enable' relativity ='Absolute'>
				<Target type ='ProtoUnit'>FieldHospital</Target></Effect>
		</Effects>
	</Tech>



In hindsight, I hypothesize that this is the same for the Asian Wonder powers. The AI should research them almost as techs, or as command abilities. In fact, Minutemen are at this moment unusable by known commands, because they are "command" at the town center, thereby every town center, not a standard "techrow" upgrade.


As we come back to walls, you need to add this code to the bottom of the AImain.xs: (or just press the edit button on my post here and copy and paste the information onto a notepad document, then open the AImain.xs found in Program Files and upgrade this).

Note: AI3 is for The Asian Dynasties, AI2 is for The Warchiefs, AI is for Age of Empires III Vanilla (original game without expansion packs). The same for Protoy/Techtreey (The Asian Dynasties), Protox/Techtreex (The Warchiefs), Proto/Techtree (Vanilla).


rule delayWallsAggressive
active
minInterval 10
{
  if ( (kbGetPopCap()-kbGetPop()) < 80 )
      return;  // Don't start walls until we have pop room
  int wallPlanID=aiPlanCreate("WallInBase", cPlanBuildWall);
  if (wallPlanID != -1)
  {
      aiPlanSetVariableInt(wallPlanID, cBuildWallPlanWallType, 0, cBuildWallPlanWallTypeRing);
      aiPlanAddUnitType(wallPlanID, gEconUnit, 0, 1, 2);
      aiPlanSetVariableVector(wallPlanID, cBuildWallPlanWallRingCenterPoint, 0, kbBaseGetLocation(cMyID, kbBaseGetMainID(cMyID)));
      aiPlanSetVariableFloat(wallPlanID, cBuildWallPlanWallRingRadius, 0.0, 89.0);
      aiPlanSetVariableInt(wallPlanID, cBuildWallPlanNumberOfGates, 0, 20);
      aiPlanSetBaseID(wallPlanID, kbBaseGetMainID(cMyID));
      aiPlanSetEscrowID(wallPlanID, cEconomyEscrowID);
      aiPlanSetDesiredPriority(wallPlanID, 80);
      aiPlanSetActive(wallPlanID, true);
      //Enable our wall gap rule, too.
      xsEnableRule("fillInWallGapsAggressive");
      aiEcho("Enabling Wall Plan for Base ID: "+kbBaseGetMainID(cMyID));
  } 
  xsDisableSelf();
}


//==============================================================================
// RULE fillInWallGapsAggressive
//==============================================================================
rule fillInWallGapsAggressive
  minInterval 31
  inactive
{
  //If we're not building walls, then start.
  if (gBuildWalls == false)
  {
      xsEnableRule("turtleUp");
      return;
  }

  //If we already have a build wall plan, don't make another one. (We try to build a second aggressive wall after our first preliminary one now)
  if(aiPlanGetIDByTypeAndVariableType(cPlanBuildWall, cBuildWallPlanWallType, cBuildWallPlanWallTypeRing, true) >= 1)
      return;

  int wallPlanID=aiPlanCreate("FillInWallGapsAggressive", cPlanBuildWall);
  if (wallPlanID != -1)
  {
        aiPlanSetVariableInt(wallPlanID, cBuildWallPlanWallType, 0, cBuildWallPlanWallTypeRing);
        aiPlanAddUnitType(wallPlanID, gEconUnit, 1, 1, 2);
        aiPlanSetVariableVector(wallPlanID, cBuildWallPlanWallRingCenterPoint, 0, kbBaseGetLocation(cMyID, kbBaseGetMainID(cMyID)));
        aiPlanSetVariableFloat(wallPlanID, cBuildWallPlanWallRingRadius, 0.0, 89.0);
        aiPlanSetVariableInt(wallPlanID, cBuildWallPlanNumberOfGates, 0, 20);
        aiPlanSetBaseID(wallPlanID, kbBaseGetMainID(cMyID));
        aiPlanSetEscrowID(wallPlanID, cEconomyEscrowID);
        aiPlanSetDesiredPriority(wallPlanID,80);
        aiPlanSetActive(wallPlanID, true);
  }
}


Copy and paste this to the end of your AI file. By itself, it makes the AI build walls in Deathmatch games, and occasionally in supremacy. As a reference, I will explain what some things do, especially for the second one.

gEconunit, 1, 1, 2,); - the first "1", or "true", makes it "true" to build these walls, the 2nd is the amount, or layers of wall to be build, and the 3rd is the number of workers. If you want more layers, however, you have to add something like 1, 3i+3, 2,); so as to make the second wall 3 game meters out farther than the previous one. Wall plans set too close to each other will make the AI build them over each other.

BuildWallPlanWallRingRadius, 0.0, 89.0); - Sets the radius of the computer building walls around their base. The maximum base limit is 55 game meters around their base, so 59.0-62.0 meters is generally the ideal distance for the AI main defensive wall. 59.0 Allows them to build walls that don't interfere with their allies' walls, but may leave a small gap due to a plantation sticking out of the wall gap, thus allowing for easier raiding. 60.0-62.0 meters only works on larger maps for their build radius.

cBuildWallPlanNumberOfGates, 0, 20); - self explanitory, 20 gates for the whole radius, if possible (note that on ordinary maps only 12 gates will be built, because the wall is usually a semicircle; for 59.0 radius, you need 15 gates to make the AI to pass effectively through their walls).

  if (wallPlanID != -1) - this makes this wall build plan infinite - thus the computer will use it quite often, and send people to rebuild their walls. Also, "0" here means a type of randomizer, and works infinitely. So its not always defined how the AI will build walls, but they build them back slightly randomized pattern - though close enough to their previous wall that it doesn't affect their building too much.

  minInterval 31 - the minimum interval in game seconds the computer will choose to send villagers to build walls.

        aiPlanSetDesiredPriority(wallPlanID,80); - priority, 99-100 being the highest, 50 being medium-low, anything <50 being very low or not at all.


Of course, if you build walls, you 1) need them upgraded, and 2) need them built always from a certain age onward. So, I have these solutions.


To make them always build walls from Industrial onwards, add this:

      xsEnableRule("fillInWallGapsAggressive");

to this:

rule age4Monitor
inactive
minInterval 10
{
  if (kbGetAge() >= cAge4)
  {
      aiEcho("*** We're in age 4.");

(Insert Enable rule HERE, then press "enter" to get a space)
      // Bump up settler train plan
      updateSettlerCounts();



Then, add this rule to the bottom of your AImain.xs file:

rule BastionUpgradeMonitor
inactive
minInterval 90
{
  int upgradePlanID = -1;

  // Disable rule for native or Asian civs
  if ((civIsNative() == true) TT (civIsAsian() == true))
  {
      xsDisableSelf();
      return;
  }

  if ((kbTechGetStatus(cTechBastion) == cTechStatusObtainable) && (kbUnitCount(cMyID, cUnitTypeAbstractWall, cUnitStateAlive) >= 20))
  {
      upgradePlanID = aiPlanGetIDByTypeAndVariableType(cPlanResearch, cResearchPlanTechID, cTechBastion);
      if (upgradePlanID >= 0)
        aiPlanDestroy(upgradePlanID);
      createSimpleResearchPlan(cTechBastion, getUnit(cUnitTypeChurch), cMilitaryEscrowID, 50);
      return;
  }
}


And, again, then add it to be enabled from Industrial onwards:

rule age4Monitor
inactive
minInterval 10
{
  if (kbGetAge() >= cAge4)
  {
      aiEcho("*** We're in age 4.");

      xsEnableRule("fillInWallGapsAggressive");
      xsEnableRule("BastionUpgradeMonitor");

      // Bump up settler train plan
      updateSettlerCounts();



If you want to build a second layer of walls, then copy and paste the rules I gave you, make them a different distance other than 89.0, and rename them something other than delayWallsAggressive, and fillInWallGapsAggressive. Then enable them from the Age4Monitor and enjoy :).



regards,



murdilator
"Feel the Might of the Sioux!" - Gall, when fighting and defeating your army at his own base.

---------------

Scenario Design Competition Participant 2009:

3v3 WildernessRoad: https://aoe3.heavengames.com/downloads/ ... ileid=2521
User avatar
Soccerman771
N3O Officer
N3O Officer
Posts: 2874
Joined: Fri Jan 18, 2008 7:25 am
Location: Sachse, Texas (near Dallas)
Contact:

Re: How to get the AI to build walls

Post by Soccerman771 »

You're too smart for your own good.  You should work at a place you can do this for a living if you aren't already..
jtackel@hotmail.com

"Do you know how difficult it is to micro Napalm?" - Lazy_Tuga

"This isn't going to work. I've picked a water deck and there isn't even a pond on this map." - Blackadderthe4th
User avatar
LaZy
Honorary Officer
Posts: 2444
Joined: Sat Jan 12, 2008 3:44 am
Location: Ferragudo Portugal
Contact:

Re: How to get the AI to build walls

Post by LaZy »

Funny how just yesterday, whilst reading this post, I was thinking the exact same thing.

Murdilator is truly keeping the AI under wraps and doing so representin´ N3O in style.

Keep up the good work bro.

out
User avatar
Aaryn_GenD
Global Moderator
Global Moderator
Posts: 3555
Joined: Fri Nov 21, 2008 9:59 pm
Location: Germany

Re: How to get the AI to build walls

Post by Aaryn_GenD »

the most ironic thing is that he doesn't even enjoy doing it. he only likes the end result
Image
User avatar
jerom
N3O Officer
N3O Officer
Posts: 1555
Joined: Thu Mar 04, 2010 1:48 am
Location: Netherlands, Utrecht
Contact:

Re: How to get the AI to build walls

Post by jerom »

Just hope when they start making aoe4, that they actually will let you do the AI :-)
Soccerman771 wrote:Just make sure you do keep some blood in your alcohol system, ok.
User avatar
murdilator
N3O Member
N3O Member
Posts: 249
Joined: Sat Sep 20, 2008 10:29 pm
Location: Norway

Re: How to get the AI to build walls

Post by murdilator »

About Wall Building: the Computers do actually for some reason play mysteriously more defensive after they build walls. I'm not sure why they do that, and I would like to sort of force their strategies to be more like an aggressive boom.


Well guys I have to admit I do enjoy it somewhat, I mean I can tolerate doing it, and I don't hate it. Over time I got used to it. I really enjoy a lot more playing the mod though, and with other people. It's more based on I want to prove one of my bro's wrong because he always used to win with Russia and I used to play India/Sioux/Ports and lose. I also thought AOE3 wasn't historically accurate enough, and it was easy to add techs after I knew how. I got the first ideas of the Observatory in late March, they solidified in May.

But I happened to have an answer for somebody about walls, and as I probably won't be around to look at it in the future I wanted just to allow others to easily copy and paste some things to modify there own game, especially as ESO is going down.

If were talking about anyone who would waste time it would be the guy who makes Darthmod Total War. I don't believe he even gets payed, but he has over 50,000 to 250,000+ downloads or more for his mods for the Total War series. If he does it for a job, its different. I would just make a simple mod for Napoleon to make more men in battalions, slightly higher morale, and make warships a bit more affordable and build faster. I mean if you had the programs that could be done in 1-4 days and Napoleon Total War is quite fixed. But man I think he spends hours on end, but I could be wrong. Now that is a waste of time.

So I thought, why not give this away. People are frightful when even copying and pasting in files into their program files. It's almost impossible to convince them to copy over new files if they have never opened one of their own.

I read up on the AOE1 AI two to three years back, so that's when the spark probably got started. There I learned about their micro, simple and yet complex strategy, and I played AOE1 again, and really loved it. Without mods, its my favorite version of AOE, beating AOE2 a little bit just because of its time era, the ancient age. I felt like AOE had so much missing because I mean I would never ever play Napoleonic Era vs. the computer if it didn't try to build walls or upgrade the units. Right now they've gotten a new AI, so it works fine, but their download sights seem a bit messy.

Roger_Black, a modder, is currently working a "mod launcher" that works on steam and on CD for AOE3. There you can just click on a mod, without changing any of your game files, and play the Greatest modifications of AOE3: Napoleonic Era, Knights and Barbarians, The Triple Alliance Mod, The Forgotton Empires Mod (a project from all Age of Empires series, I and II), and a few others. I haven't gotten his latest version to work, because he uses some never software, but he's making it better and better, iirc.

However, if MN_Bob is out there still, it would be interesting if, and only if, it is easy to make the TAD Patch Launcher recognize the DataPY.bar file in Steam as well as the ordinary game, or has a separate patch launcher that this form might actually be better for people. As it is, it works for the CD install, but not for Steam.
"Feel the Might of the Sioux!" - Gall, when fighting and defeating your army at his own base.

---------------

Scenario Design Competition Participant 2009:

3v3 WildernessRoad: https://aoe3.heavengames.com/downloads/ ... ileid=2521
emperoral
N3O Officer
N3O Officer
Posts: 569
Joined: Wed Nov 14, 2007 11:36 pm
Location: Lincoln, Uk

Re: How to get the AI to build walls

Post by emperoral »

Funny that I was thinking the same thing how to get AI to build walls...ok ok spot the lie.. Anyway somebody is clever and its not me!
User avatar
murdilator
N3O Member
N3O Member
Posts: 249
Joined: Sat Sep 20, 2008 10:29 pm
Location: Norway

Re: How to get the AI to build walls

Post by murdilator »

Now don't say that Emperoral.

I've based my AI on somebody's previous work, Felix Hermasson's Draugur AI, which is already a very known modification. He added in the counter system, some new card handling, different computer strategy, and made the computer upgrade ships and randomize their strategy.

All in all, he did a fantastic job. Then there was a guy named Netherc_Y or something at heavengames.com who made the Draugur AI build walls. I downloaded his version, tested it, was was impressed, but began to modify it myself.

What I've added is specific civ cards, different rules to make the AI for instance build Settler Wagons after Sending German Town Farmers, Fencing School and Riding School cards, Military Improvment Cards, Refrigeration, Royal Mint, Exotic Hardwoods and have forbidden them to build most mercenaries (which works as a pro and a con; they don't always attack as early, mercs help them, but I've made them more steady throughout the game), namely because I wanted a more booming AI.

They'll build Mamelukes and Elmeti if available, and I've forced them to build their "civ's" units, and also forbidden all outlaw units (which were definately a problem for the Draugur AI). Also, I have of recent begun to add to them many techs and understand deeper the AI.


We started the Better AI project about a year ago publically, where we wanted to actually improve the gameplay for the general community, especially since most people play offline and online is soon to go down. Plus folks want a decently competitive comp stomp, in my opinion.

http://aoe3.heavengames.com/cgi-bin/for ... ,38842,,10


So its more like I got a lot of help, and later discovered how to always get the AI build walls. Several people have known about this and have discovered it about the same time that I have. I am not a lone soul in the modding community. We have many others.


Anyways, that's to be a disclaimer


regards,


murd
"Feel the Might of the Sioux!" - Gall, when fighting and defeating your army at his own base.

---------------

Scenario Design Competition Participant 2009:

3v3 WildernessRoad: https://aoe3.heavengames.com/downloads/ ... ileid=2521
Post Reply