How to change KI fight and how change needed XP

Serp

King
Joined
Apr 1, 2015
Messages
666
Hi :)

1) Is it possible to change the fighting behaviour of the AI with xml/sql or lua scripts? If not, whoward are you there? :D Is it possible to change it in your DLL with another mod?

I noticed that, at least barbarians melee units do not attack my range units, even if they stand next to them. Only Mounted and other range units do attack my range units.

I'm not sure, which restriction is forcing them to do this, but I guess it is something like "I'm only a warrior and this is a marksmen. Because marksmen is a heavy upgrade, I won't attack him". But of course this tactic is rubbish against range units.
So I would like to see the following changes:
  • AI melee units should attack range units regardless of the update level. Maybe it would be good, if in ~70% of the time they do attack. In 20% they do fortify and 10% they move away.
  • If the barbarian is in a camp, they also should attack range units standing next to them, without leaving the camp.


2) I would like to change the XP system a bit. As a base value, Archers get 2 XP per shot. Now you can add some promotions or other things, that gives a % bonus on the XP. But the problem ist, that it is round off. So a 40% more XP bouns, wuold result in 2,8 XP per shot, which is rounded to 2XP per shot.
Now I see two possibilities:
  • Make decimal numbers up to 2 decimal places possible.
  • Or multiply the total needed XP by 10 or 100, and of course also the XP per shot, so we don't have this rounding problem anymore.
Is this possible?
 
I just found the "GlobalAIDefines.xml".

I see there I can set different values for different behaviour, e.g:
Code:
<Row Name="AI_TACTICAL_BARBARIAN_PRIORITY_DESPERATE_ATTACK">
    <Value>0</Value>
</Row>
But what does the value mean? 0 of course means "never do that", but what does 10 or 30 mean? Will all values be added and calculated in %, to decide what to do?

And what is a "DESPERATE_ATTACK" ? Is this the reason, why a warrior does not attack a marksman? I won't call this a desperate_attack.
 
1) KI? I assume you mean the AI

Change it's combat behaviour via XML/SQL not really ... you could tweak a few parameters but not by enough to make any real difference.

Via Lua. Yes, you could take control of every unit at the start of every AI turn, work out where to send them (storing that info somehow to pre-load future turn decisions) and manually move them (part way) there. But that would be a metric s***-load of work!

Barb melee units do attack ranged units ... at least they do in my games!

Barb units will rarely leave their camp undefended (it's coded that way to stop the "lure them out with one unit then grab the gold from clearing the camp with another unit" tactic which is easy for human players to do)

All the AI_TACTICAL_BARBARIAN_PRIORITY values work together to determine what the barbies are going to do this turn. 0 means never consider this. 10 means consider this less than other priorities with a higher value. A random number (0 to AI_TACTICAL_MOVE_PRIORITY_RANDOMNESS) is added to each priority. The resultant values are sorted into order and then actioned by picking appropriate units for that action and giving them orders. This is why barbies will suddenly switch what they are doing - they are pretty much random from turn to turn.

To fully understand what a desperate attack and the other priorities are, you'll have to dig into the CvTacticalAI:: AssignBarbarianMoves() C++ code as it would require an essay to fully describe.
 
2) Why not just change the GlobalDefines.xml values

Code:
		<Row Name="EXPERIENCE_ATTACKING_UNIT_MELEE">
			<Value>5</Value>
		</Row>
		<Row Name="EXPERIENCE_DEFENDING_UNIT_MELEE">
			<Value>4</Value>
		</Row>
		<Row Name="EXPERIENCE_ATTACKING_UNIT_AIR">
			<Value>4</Value>
		</Row>
		<Row Name="EXPERIENCE_DEFENDING_UNIT_AIR">
			<Value>2</Value>
		</Row>
		<Row Name="EXPERIENCE_ATTACKING_UNIT_RANGED">
			<Value>2</Value>
		</Row>
		<Row Name="EXPERIENCE_DEFENDING_UNIT_RANGED">
			<Value>2</Value>
		</Row>
		<Row Name="EXPERIENCE_ATTACKING_AIR_SWEEP">
			<Value>5</Value>
		</Row>
		<Row Name="EXPERIENCE_DEFENDING_AIR_SWEEP_AIR">
			<Value>5</Value>
		</Row>
		<Row Name="EXPERIENCE_DEFENDING_AIR_SWEEP_GROUND">
			<Value>2</Value>
		</Row>
		<Row Name="EXPERIENCE_ATTACKING_CITY_MELEE">
			<Value>5</Value>
		</Row>
		<Row Name="EXPERIENCE_ATTACKING_CITY_RANGED">
			<Value>3</Value>
		</Row>
		<Row Name="EXPERIENCE_ATTACKING_CITY_AIR">
			<Value>4</Value>
		</Row>

Is this possible?
All things are possible. How good is your C++ and how much spare time do you have ;)
 
1) KI? I assume you mean the AI

Change it's combat behaviour via XML/SQL not really ... you could tweak a few parameters but not by enough to make any real difference.

Via Lua. Yes, you could take control of every unit at the start of every AI turn, work out where to send them (storing that info somehow to pre-load future turn decisions) and manually move them (part way) there. But that would be a metric s***-load of work!

Barb melee units do attack ranged units ... at least they do in my games!

Barb units will rarely leave their camp undefended (it's coded that way to stop the "lure them out with one unit then grab the gold from clearing the camp with another unit" tactic which is easy for human players to do)

All the AI_TACTICAL_BARBARIAN_PRIORITY values work together to determine what the barbies are going to do this turn. 0 means never consider this. 10 means consider this less than other priorities with a higher value. A random number (0 to AI_TACTICAL_MOVE_PRIORITY_RANDOMNESS) is added to each priority. The resultant values are sorted into order and then actioned by picking appropriate units for that action and giving them orders. This is why barbies will suddenly switch what they are doing - they are pretty much random from turn to turn.

To fully understand what a desperate attack and the other priorities are, you'll have to dig into the CvTacticalAI:: AssignBarbarianMoves() C++ code as it would require an essay to fully describe.

Thank you very much :)
Yes I mean AI (KI is german, sry :D)
Okay, sad =/ I hoped to make them a bit more dangerous. The Barbarian Immersion mod at least makes them stronger. But they are still just a way to farm XP, at least for ranged units.
As far as I know no mod in my modpack does change the behaviour of barbarians. So I was sure if they do not attack my range units in my modpack, they also won't attack them in the base game... but I will start a unmodded game to see if they attack my range untis.

2) Why not just change the GlobalDefines.xml values

Code:
		<Row Name="EXPERIENCE_ATTACKING_UNIT_MELEE">
			<Value>5</Value>
		</Row>
		<Row Name="EXPERIENCE_DEFENDING_UNIT_MELEE">
			<Value>4</Value>
		</Row>
		<Row Name="EXPERIENCE_ATTACKING_UNIT_AIR">
			<Value>4</Value>
		</Row>
		<Row Name="EXPERIENCE_DEFENDING_UNIT_AIR">
			<Value>2</Value>
		</Row>
		<Row Name="EXPERIENCE_ATTACKING_UNIT_RANGED">
			<Value>2</Value>
		</Row>
		<Row Name="EXPERIENCE_DEFENDING_UNIT_RANGED">
			<Value>2</Value>
		</Row>
		<Row Name="EXPERIENCE_ATTACKING_AIR_SWEEP">
			<Value>5</Value>
		</Row>
		<Row Name="EXPERIENCE_DEFENDING_AIR_SWEEP_AIR">
			<Value>5</Value>
		</Row>
		<Row Name="EXPERIENCE_DEFENDING_AIR_SWEEP_GROUND">
			<Value>2</Value>
		</Row>
		<Row Name="EXPERIENCE_ATTACKING_CITY_MELEE">
			<Value>5</Value>
		</Row>
		<Row Name="EXPERIENCE_ATTACKING_CITY_RANGED">
			<Value>3</Value>
		</Row>
		<Row Name="EXPERIENCE_ATTACKING_CITY_AIR">
			<Value>4</Value>
		</Row>


All things are possible. How good is your C++ and how much spare time do you have ;)
I don't have knowledge in C++, only lua and Python. =/
Thank you for the hint with the GlobalDefines.xml :) Is it also possible to change the XP needed for a level up ?

edit:
hm.. in GlobalDefines I see no "Experience for lvl up" or simular... But what does
<Row Name="EXPERIENCE_PER_LEVEL">
<Value>10</Value>
</Row>
mean?

A workaround would be to give one promotion every 5 levels. Is there a level cap?
 
XP per promotion is
10, 20, 30, 60, 100, 150, 210, etc

which is

previous xp + (level * EXPERIENCE_PER_LEVEL)

ie

0 + (1 * 10) = 10
10 + (2 * 10) = 30
30 + (3 * 10) = 60
60 + (4 * 10) = 100
100 + (5 * 10) = 150
150 + (6 * 10) = 210
etc
 
EXPERIENCE_PER_LEVEL = 10 means the 1st promotion comes at 10XP, the second at 30XP, third at 60XP, fourth at 100XP. On standard gamespeed. I don't play at other than standard so don't know if this is modified for other game speeds.

So the formula for XP needed is, uh, I just failed at math :cry:. Anyway, here is how it works if a unit is at Level #3 and accumulating XP towards Level #4:

NextLevel = 4
xp = (10 * 1) + (10 * 2) + (10 * 3) + (10 * 4)
xp = 100

edit: William, once again with the :ninja: powers
 
XP per promotion is
10, 20, 30, 60, 100, 150, 210, etc

which is

previous xp + (level * EXPERIENCE_PER_LEVEL)

ie

0 + (1 * 10) = 10
10 + (2 * 10) = 30
30 + (3 * 10) = 60
60 + (4 * 10) = 100
100 + (5 * 10) = 150
150 + (6 * 10) = 210
etc
excellent, thank you very much!! :) (also thank to LeeS)

About the AI barbarians:
I just test it again with and without my modpack.
If the barbarian is in a camp and my range unit stand next to him, the range unit can shoot until the barbarian is dead.

But if the unit is not in a camp, they will attack my range unit only, if they have a chance to win. So a low level warrior of the barbarian won't attack a marksmen. But a better barbarian unit will. So I think everything is fine, but I will change the desperate Attack to value 1 :)
 
Back
Top Bottom