GameDev: Stupid AI tricks I
For those of you interested in game development, this will be part of a series of how we address “stupid” AI mistakes. What I’ll be showing in this series are AI mistakes along with what I did to address them. Feel free in the comment section to include saved games and other examples that you think are worthwhile.
Just to be sure, “stupid” means exactly that. Stupid != “non optimal” (“I can’t believe the AI chose a factory over a research building as their 5th improvement on Centi III” is not stupid. But “I can’t believe the AI gave me its home planet in exchange for some beads” would be).
Case #1: Space beads
What’s happening?
When you add an item to the trade screen, the game appraises the value of it.
In the case of a peace treaty, it simply looks at my power vs. their power. This is a good start but it needs much much more.
So what kinds of things should the AI take into account?
- Who started the war. Which it does (the grudge factor).
- The faction power difference. It does this but its weight isn’t related to the weights of things like tech. This is a very tricky balancing act of course.
- How long they’ve been at war.
- The personalities at war (are you their primary enemy? if so, they are a lot less likely to want peace).
- Do they currently have you by the throat? By that I mean, do they have transports and war ships in your territory? If so, that should matter.
This is, by no means, a complete list but a pretty decent start.
So my first change here is going to be that I don’t want to look at My power minus their power alone. I want to look at the RATIO. Even if I have 50 and they have 100, a 50 difference doesn’t seem like much. But it is a 2X difference.
However, you can’t go by ratios alone because early game, you can easily get “double” or more of someone else’s power just by building a couple impressive ships. So we need a combination.
We also need to look at relative costs too.
In this example: Me asking for peace is worth –180 points. That is meaningless without knowing how much other stuff is valued.
But the tech is valued at 750. WOW! The crappy ship is only 77.
The techs are probably pretty well balanced at this stage and crappy ships really aren’t worth very much. It’s the treaty that isn’t valued enough.
So let’s go look back at the treaty valuation.
First I’m going to add:
FixedDecimal primaryEnemy = m_primaryOpponentID;
This way, I can penalize the player if the AI has really dislikes them.
then:
In the file GalCiv3AIDefs.xml (anyone can monkey with this) I’m going to change the NegativePeaceTreatyRelation value from 12 to 120.
Why?
The Drengin’s power is 254. Mine is 193. That’s a difference of 60. Ultimately, the cost on this gets modified by a derivative of that value which ultimately comes out to 3 which is why it’s only –180. They declared war on us, they’re more powerful but they don’t really hate us. But given that a crappy tech is worth 750 we need to put these values into their place. Or in other words, –180 should really be more like –1800.
It also turns out that the Drengin don’t consider me their primary enemy (which is nice) so they should be willing to give me peace for a price. They just shouldn’t be willing to give me peace cheaply.
Moreover, peace treaties need to be weighted to be similar in value to other items as a starting basis:
So instead of the mod value being 1 I’m changing it to 10.
So let’s make these changes…
Ok. Better. We’ve been at war for 45 turns and I’m not their primary enemy. 3 techs should be enough to buy him off.
But..
but…
“Your gift will be gladly received.”
No.
The Drengin would never say that. This is where modders will have some fun because this is all data driven. So let’s go fix that.
Open up Flavortext.xml in an XML editor (I use visual studio). Find that corny text.
So that’s the generic response if I’m giving them stuff that is worth more than what they’re giving me in return.
Let’s add some new ones right now.
So if they’re stronger than I am, they’ll have a bit more arrogance.
But still, we’re at war and this is the Drengin we’re talking about. Let’s go further.
Okay, so now the speaker is stronger, and we’re at war so I’ll have them be a bit more cocky.
Still…
NOT Drengin-y enough. BTW, you can make your own flavor texts and share them. These fields that you see here auto fill.
Just create a file called say “MyOwnFlavors.xml” with this at the top:
We include that .xsd file in the game directory to help modders.
Anywhoo…
Let’s make this text even better.
There. And I even gave it 2 different text options to draw from. I could add more but I’m lazy. But modders can and I hope will go crazy with this stuff.