Brad Wardell's site for talking about the customization of Windows.
Published on April 26, 2015 By Frogboy In GalCiv III Dev Journals

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

image

What’s happening?

image

When you add an item to the trade screen, the game appraises the value of it.

image

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?

  1. Who started the war.  Which it does (the grudge factor).
  2. 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.
  3. How long they’ve been at war.
  4. The personalities at war (are you their primary enemy? if so, they are a lot less likely to want peace).
  5. 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:

image

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.

image

So let’s make these changes…

 

image

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.

image

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.

image

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.

image

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:

image

We include that .xsd file in the game directory to help modders.

Anywhoo…

Let’s make this text even better.

image

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.


Comments
on Apr 26, 2015

Very good stuff all along !


So what kinds of things should the AI take into account?

  1. Who started the war.  Which it does (the grudge factor).
  2. 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.
  3. How long they’ve been at war.
  4. The personalities at war (are you their primary enemy? if so, they are a lot less likely to want peace).
  5. 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.

Maybe the AI should also take into account other wars/alliances I'm engaged in. That way, they could maintain coalitions against a more powerful common enemy.

on Apr 26, 2015

Crocell44

Maybe the AI should also take into account other wars/alliances I'm engaged in. That way, they could maintain coalitions against a more powerful common enemy.

 

The AI should also take into account other wars that THEY are fighting. If they are also fighting another war against someone they hate more than you and it's not going well, they should be more prepared to offer you peace so that they can concentrate on their other war.

on Apr 26, 2015

I request that change to the Drengin dialogue be permanent.

on Apr 26, 2015

Regarding creating a “MyOwnFlavors.xml”. You do have to have the correct hierarchy though yes? You can't just make a file and put this at the top

Code: xml
  1. <FlavorTextDefs
  2. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3. xsi:noNamespaceSchemaLocation="../Schema/FlavorText.xsd">

Its still got to have the FlavorTextDef parent & internal name for each particular scenario like "First contact, Peace, War and etc." doesn't it?

Code: xml
  1. <FlavorTextDefs
  2. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3. xsi:noNamespaceSchemaLocation="../Schema/FlavorText.xsd">
  4.    <FlavorTextDef>
  5.        <FlavorTextOption>
  6.           <Requirements>
  7.              <ListenerHasUniversalTranslator>false</ListenerHasUniversalTranslator>
  8.           </Requirements>
  9.           <Text>Huh?</Text>
  10.           <PreferenceWeight>1</PreferenceWeight>
  11.        </FlavorTextOption>
  12.    </FlavorTextDef>
  13. </FlavorTextDefs>

I'm having trouble with this file and the StarSystemDefs.xml and have to overwrite them to get them to work.

Edit ; InternalName shouldn't be in there.? Internalname duplication error if it is.

And if I remove that line, then I keep getting this error;

C:\Users\Test\Documents\My Games\GalCiv3\Mods\Klhadrevlec\Game\FlavorText_Klhad.xml(149,19): error:
element 'FlavorTextOption' is not allowed for content model '(InternalName,FlavorTextOption+)'

Could you please explain a bit more of what to do here with these files.

Thanks

on Apr 26, 2015

Is it possible to include Win loss ratio in calculations.  I know in Gal Civ 2 often i had more powerful ships that would mop the floor with say Drengin fleet spam but they would be considered higher military value buy often a lot in some cases dew to sheer numbers. of for example one of use found a precursor ship early one.  Assuming were both occupied with war elsewhere in addition we ether come into little or no conflict or come into lots of conflict.  If i were to win 4 out of 5 battles it might be a good idea to have the AI value peace treaty even if there power is considered higher.  Visa versa as well if they win more often making me wanting peace less interesting and costly. This could help alleviate the issue of the player manipulating the AI into buying peace when were on the loosing side. 

on Apr 26, 2015

I hate games that doesn't let you be stupid.

Me: Hey mister AI, I want to give you my home planet, what you say?

AI: No, thanks.

Me: Are you stupid or what???

on Apr 27, 2015

Very nice! Please Show us more of it!

on Apr 27, 2015

zmarcos

I hate games that doesn't let you be stupid.

Me: Hey mister AI, I want to give you my home planet, what you say?

AI: No, thanks.

Me: Are you stupid or what???

Unfortunately that is a typical AI flaw, until we can get AI to process like a human they'll be controlled strictly by numerical calculations. Processing like a human will make AI coding significantly more complicated and at far greater risk of coding failures. So until coding language has developed significantly enough to condense the requirements down this is pretty much the limits of what AI can do. 

on Apr 30, 2015

In_stasis

Regarding creating a “MyOwnFlavors.xml”. You do have to have the correct hierarchy though yes? You can't just make a file and put this at the top

Code: xml

    1. <FlavorTextDefs

    1. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

  1. xsi:noNamespaceSchemaLocation="../Schema/FlavorText.xsd">


Its still got to have the FlavorTextDef parent & internal name for each particular scenario like "First contact, Peace, War and etc." doesn't it?

Code: xml

    1. <FlavorTextDefs

    1. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

    1. xsi:noNamespaceSchemaLocation="../Schema/FlavorText.xsd">

    1.    <FlavorTextDef>

    1.        <FlavorTextOption>

    1.           <Requirements>

    1.              <ListenerHasUniversalTranslator>false</ListenerHasUniversalTranslator>

    1.           </Requirements>

    1.           <Text>Huh?</Text>

    1.           <PreferenceWeight>1</PreferenceWeight>

    1.        </FlavorTextOption>

    1.    </FlavorTextDef>

  1. </FlavorTextDefs>


I'm having trouble with this file and the StarSystemDefs.xml and have to overwrite them to get them to work.

Edit ; InternalName shouldn't be in there.? Internalname duplication error if it is.

And if I remove that line, then I keep getting this error;

C:\Users\Test\Documents\My Games\GalCiv3\Mods\Klhadrevlec\Game\FlavorText_Klhad.xml(149,19): error:
element 'FlavorTextOption' is not allowed for content model '(InternalName,FlavorTextOption+)'

Could you please explain a bit more of what to do here with these files.

Thanks

I agree that this is confusing and would love some input from Frogboy or anyone else, if you know how to add new flavor text without overriding the FlavorText.xml file.

I know this wasn't the main intent of your post, Frogboy, but some clarification here would be nice. As In_stasis mentioned in the quoted post, if you include the needed InternalName, you get an error... if you exclude it, you get an error (and there would be no way for the ConversationDefs.xml file to know where the flavor text belongs)...

on Apr 30, 2015

on Apr 30, 2015

That Yor response is reminds me of HK-47 from KOTOR

on Apr 30, 2015

The issue, I believe, is the same one that arises with StarSystems: The game uses a specific InternalName for some things, and you can't append to that in a mod without replacing the whole file

For example: I want to have a new StarSystem selectable when creating a custom race. The only way to do this is either to have it under the InternalName 'FactionStart', (or change what label GalCiv3GlobalDefs points to, which would require replacing that file instead.). If we tried to have a mod (appending, not replacing) with InternalName 'FactionStart', then it just comes up with "Duplicate InternalName found in type StarSystemGroupDef: FactionStart"

on Apr 30, 2015

Frogboy, In copying your Yor example as a Mod with a different file name (append method, not replace), the following error occurs upon game startup:

Duplicate InternalName found in type FlavorTextDef: GENERAL_CONVERSATION_MAIN.

Is there some way to add flavor text without getting the duplicate InternalName error (other than overriding the FlavorText file as a whole)?

on Apr 30, 2015

I'm seeing that too.

 

Lemme think about it a bit more.   It's not being additive.

on Apr 30, 2015

Frogboy

I'm seeing that too.

 

Lemme think about it a bit more.   It's not being additive.

Thanks for looking into it!