This is the official forum for the free, fan-made Age of Empires III modification, Wars of Liberty.

Welcome to the New Forum

We hope you enjoy the official new forum of the Wars of Liberty mod for Age of Empires III! Visit this thread to get acquainted with the new forum, and let us know if there's anything we can fix. Feel free to dismiss this message at any time by clicking the "X" in the top right corner.

Thanks!
The Wars of Liberty Team

Forum rules

  • Welcome to The Library! This forum is for asking questions about modding, and sharing maps, mods, and other creations.
  • The official language in this forum is English.
  • Be nice to other members, don't spam comments or smilies, and don't do anything illegal.
  • Posts that don't fit this forum will be moved or deleted.
 
Osiris
Topic Author
Volunteer
Volunteer
Posts: 44
Joined: Mon Nov 20, 2017 9:17 am

AI questions

Mon Nov 20, 2017 3:30 pm

Hello there! I'm new here.
I created a little mod for myself and my friends and family, with new mechanisms, new units and new techs. The problem is that the AI cannot understand the new mechanisms, and since none of us can play in multiplayer mode (with or without mods), I want to modify the AI. I know where the AI file is, but before modifying it, I must know how does it work. Is there anyone here that can explain how does the AI work? Strangely there are many tutorials for almost all moddable things like creating new units, new techs, new civs,... but I didn't find any tutorial on modifying the AI...
I'd be happy if anyone could help me. Thank you in advance!
 
User avatar
AlistairJah
Wars of Liberty Team
Wars of Liberty Team
Posts: 530
Joined: Wed Sep 06, 2017 10:10 am
Location: Madagascar
Favorite Civilization: French
Contact:

Re: AI questions

Mon Nov 20, 2017 4:05 pm

Hey! I'm happy to see someone who is interested in AI! Usually, people prefer to avoid it.
Now to answer your question... Independently of the scenario part of the script, the AI follows these steps :
[1] ECONOMY
Base preparing
Escrow setup
Gatherer allocation (Actual and Forecasts)
Villager training (also called Villager maintaining)

[2] BASE
Making buildings
Gather points (when military units are unused, they usually go to the gather point)

[3] MILITARY
Attack goal
Unit Pick
Opportunities
Forward bases
Defense

[4] MISCELLANEOUS
Decks (purchasing cards and building up deck)
Naval maps (training naval units, fishing...)
Scouting
Capturing herdables
Age ups
Researching techs
Chats and taunts
Game mode handling (KOTH, Trade monopoly, deathmatch...)
Tributes
And so on.

If you explore the file, you will certainly see that the AI does not follow these steps linearly.
If you got another question, do not hesitate to ask!
Mis band dondrna b at fa so gaga oe ts maay angle lery
 
Osiris
Topic Author
Volunteer
Volunteer
Posts: 44
Joined: Mon Nov 20, 2017 9:17 am

Re: AI questions

Mon Nov 20, 2017 4:30 pm

Alright, that was fast. Unfortunately, I'm just a noob. Could you please explain more?
 
User avatar
AlistairJah
Wars of Liberty Team
Wars of Liberty Team
Posts: 530
Joined: Wed Sep 06, 2017 10:10 am
Location: Madagascar
Favorite Civilization: French
Contact:

Re: AI questions

Mon Nov 20, 2017 4:34 pm

Well... Hum... Explaining all of these things would need a completely new topic, and honestly, I am a bit busy these days. Just ask what you want and I will try to answer your questions.
Mis band dondrna b at fa so gaga oe ts maay angle lery
 
Osiris
Topic Author
Volunteer
Volunteer
Posts: 44
Joined: Mon Nov 20, 2017 9:17 am

Re: AI questions

Mon Nov 20, 2017 4:39 pm

Yes, true. Well, basically I want my AI to build the new buildings I made, train the new units and research the new techs. How to do that?
 
User avatar
AlistairJah
Wars of Liberty Team
Wars of Liberty Team
Posts: 530
Joined: Wed Sep 06, 2017 10:10 am
Location: Madagascar
Favorite Civilization: French
Contact:

Re: AI questions

Mon Nov 20, 2017 5:05 pm

That's pretty easy. To make them build something, just search for rule buildingMonitor using your text editor, and copy-paste the codes there. A little example (I don't remember the exact codes) :

Code: Select all

planID = aiPlanGetIDByTypeAndVariableType(cPlanBuild, cBuildPlanBuildingTypeID, cUnitTypeYOURBUILDING);
if((planID < 0) && (kbUnitCount(cMyID, cUnitTypeYOURBUILDING, cUnitStateAlive) < 1))
createSimpleBuildPlan(cUnitTypeYOURBUILDING, 1, 50, true, cEconomyEscrowID, kbBaseGetMainID(cMyID), 1);

If your building is a military building, just replace true by false and cEconomyEscrowID by cMilitaryEscrowID.

To make them research a tech, search for rule age2Monitor (3 if the tech is available in age III, 4 if IV and 5 if V). Just above gAgeUpTime = xsGetTime();, put this:

Code: Select all

createSimpleResearchPlan(cTechYOURTECH, getUnit(cUnitTypeBUILDINGWHERETOGETIT), cEconomyEscrowID, 50);
If your tech is military, just replace cEconomyEscrowID by cMilitaryEscrowID.

To make them train units, just choose the age monitor you want, and put this just above gAgeUpTime = xsGetTime(); :

Code: Select all

 
createSimpleMaintainPlan(cUnitTypeYOURUNIT, [PUTTHEDESIREDNUMBERHERE], true, kbBaseGetMainID(cMyID), [PUTTHEDESIREDBATCHHERE]);
For example :
createSimpleMaintainPlan(cUnitTypeYOURUNIT, 30, true, kbBaseGetMainID(cMyID), 5);

Note that since you are just a beginner, I just gave you pre-made codes. When you make progress, you can learn how to make your own codes.
Mis band dondrna b at fa so gaga oe ts maay angle lery
 
Osiris
Topic Author
Volunteer
Volunteer
Posts: 44
Joined: Mon Nov 20, 2017 9:17 am

Re: AI questions

Mon Nov 20, 2017 5:39 pm

Thank you, it worked! Another question : is it possible for the AI to gather new resources apart from Food, Wood and Gold?
 
User avatar
AlistairJah
Wars of Liberty Team
Wars of Liberty Team
Posts: 530
Joined: Wed Sep 06, 2017 10:10 am
Location: Madagascar
Favorite Civilization: French
Contact:

Re: AI questions

Mon Nov 20, 2017 5:56 pm

Glad it helped you! Although I never tried making them gather the other resources, I think they can gather whatever resources there are on the map. For that, you need to code "gather plan". In short terms, a gather plan is a set of codes that make the AI to gather a certain resource (for example, food) from a certain unit type (for example, a sheep). However, the AI uses another feature called "Gatherer Allocation" (I wrote it on my first answer), which already "distribute" tasks for villagers - what resource to get, how many villagers per resource, what resource have the higher priority... So, I don't know which of these methods is good. Since I am not sure whether Fame, Trade and XP (these are the resources you're talking about, right?) have subtypes, I would prefer gather plans. To make a new one, you can create a new rule:

Code: Select all

rule THERULENAMEHERE
active
minInterval 30
{
if(xsGetTime()<600000)
return;

}
In this example, the gather plan will not start before 10 minutes.
Mis band dondrna b at fa so gaga oe ts maay angle lery
 
Osiris
Topic Author
Volunteer
Volunteer
Posts: 44
Joined: Mon Nov 20, 2017 9:17 am

Re: AI questions

Mon Nov 20, 2017 6:02 pm

10 minutes? So, this stuff is in milliseconds. It's cool that they can gather other resources! Yes I talked about Fame. I understand how to create a rule, but how do I do the gather plan? Sorry for my thousands of questions!
 
User avatar
AlistairJah
Wars of Liberty Team
Wars of Liberty Team
Posts: 530
Joined: Wed Sep 06, 2017 10:10 am
Location: Madagascar
Favorite Civilization: French
Contact:

Re: AI questions

Mon Nov 20, 2017 6:28 pm

Yeah, milliseconds. It's a bit longer than the previous examples. Inside the rule you created, you put the following codes.
First, you create the plan:
static int fameGatherPlanID = aiPlanCreate("NAMEHERE", cPlanGather);
Then you put parameters on it:
Resource to get (here, fame):
aiPlanSetVariableInt(fameGatherPlanID, cGatherPlanResourceType, 0, cResourceFame);
The stuff from where to get it:
aiPlanSetVariableInt(fameGatherPlanID, cGatherPlanResourceUnitTypeFilter, 0, cUnitTypeYOURUNIT);
Gather plan need base. Here we use main base:
aiPlanSetVariableInt(fameGatherPlanID, kbBaseGetMainID(cMyID));
Set the priority. Villagers often should do several stuff at the same time, so this priority determines if the fame gathering has priority over building a building, for example. Values range from 0 to 100.
aiPlanSetDesiredPriority(fameGatherPlanID, 80);
The units that should gather the resource:
aiPlanAddUnitType(fameGatherPlanID, cUnitTypeYOURUNIT, MINNUMBERHERE, NEEDNUMBERHERE, MAXNUMBERHERE);
For example
aiPlanAddUnitType(fameGatherPlanID, cUnitTypeYOURUNIT, 1, 20, 25);
Activate the plan:
aiPlanSetActive(fameGatherPlanID, true);

And that's it! To make your code safer, you can also make a check :
static int fameGatherPlanID = -1;
if(fameGatherPlanID < 0)
{
fameGatherPlanID = aiPlanCreate("NAMEHERE", cPlanGather);
// Paste here the previous examples without the explanations
}

It works even without the check, but sometimes plan creation fails, so it is safer to check whether the plan exists or not.
Mis band dondrna b at fa so gaga oe ts maay angle lery

Who is online

Users browsing this forum: No registered users and 0 guests