• We are currently performing site maintenance, parts of civfanatics are currently offline, but will come back online in the coming days. For more updates please see here.

Enticing the AI to build forts

Craig_Sutter

Deity
Joined
Aug 13, 2002
Messages
2,773
Location
Calgary, Canada
In my mod, I have given the Normans the Motte and Bailey improvement as their UA.

Problem, the AI does not build them.

Solutions:

1) Is there any combination of improved terrain Yeilds I can add to the fort/Motte and Bailey to encourage the AI building these (both forts and M&Bs)? Has anyone been successful in getting the AI to do this.

2) I'm thinking of a new resource that can only be improved with a fort/M&B. Call it "Strong Point". Perhaps I would even use the fort graphic for the resource (if that is possible). It might give a higher defense value even when unimproved. Perhaps it would give +gold, +culture or +production if worked by a fort/M&B. Granted, the placement would be random, but as a bonus resource, it could be fairly evenly distributed.

Any other suggestions to get this UA working properly would be very welcome.
 
I've never seen the AI build a fort, or encountered an AI fort. It could be something in the hard(ish) coded, I'll poke around a bit if someone doesn't come along who knows. If the AI can build forts but just doesn't, a lua fix will probably work, maybe even an xml yields fix (like you where suggesting I believe). If the AI simply won't build anything that is ImprovementType.IMPROVEMENT_FORT it would not be xml fixable. You need lua code to force the build, tricky code possibly too, considering the variables involved in when and where to build a fort.

Hmmm.... am I sure I've never seen an AI fort? Pretty sure, but lets make that a 99% sure.
 
Here is a quote from the DLL source code (CvBuilderTaskingAI.cpp):

Code:
		// if this improvement has a defense modifier, ignore it for now
		CvImprovementEntry* pImprovement = GC.getImprovementInfo(eImprovement);
		if(pImprovement->GetDefenseModifier() > 0)
		{
			continue;
		}

This means that the AI will never build any improvements with a defensive bonus (with the exception of Citadels built by Great Generals, which is done elsewhere in the code).

So you need to modify the DLL to change this.
 
Here is a quote from the DLL source code (CvBuilderTaskingAI.cpp):

Code:
		// if this improvement has a defense modifier, ignore it for now
		CvImprovementEntry* pImprovement = GC.getImprovementInfo(eImprovement);
		if(pImprovement->GetDefenseModifier() > 0)
		{
			continue;
		}

This means that the AI will never build any improvements with a defensive bonus (with the exception of Citadels built by Great Generals, which is done elsewhere in the code).

So you need to modify the DLL to change this.

That seems weird. Maybe the developers viewed forts as a waste of a tile and it would overall hurt the AI's performance if they used them?
 
That seems weird. Maybe the developers viewed forts as a waste of a tile and it would overall hurt the AI's performance if they used them?
Yeah, I think that screws us. Most likely the developers didn't have time or desire to work out the logic of what and when is a good time to build a fort. The thing is, that looks like a pinch point - meaning we can use push mission all we want to tell the AI to build a fort, or try some other clever method, but it won't work because the AI simply doesn't know how.

Even a DLL fix would be somewhat of a nightmare IMHO as there is no logic at all at the moment. So an entire AI around when and where to build forts would have to be written.
 
Even a DLL fix would be somewhat of a nightmare IMHO as there is no logic at all at the moment. So an entire AI around when and where to build forts would have to be written.

That's the fun of modding. :) Adding your own logic in there.

Now that I see this is an issue, I might add it in to my mod.
 
Yeah, I think that screws us. Most likely the developers didn't have time or desire to work out the logic of what and when is a good time to build a fort. The thing is, that looks like a pinch point - meaning we can use push mission all we want to tell the AI to build a fort, or try some other clever method, but it won't work because the AI simply doesn't know how.

Have we actually tried using PlayerDoTurn and in that PushMission with an AI worker? While it's far from automatic, I am not sure digging into the DLL is required (although it might be better). To me I'd think that'd work the same as any player pushing that mission to a unit, a non-automated order.
 
You might be right. You'd have to also be able to stop automation on AI workers (assuming they are even considered automated which would be another issue) in order to take manual control. Then, you'd have to do all the manual control (which is harder - especially from lua - then you might realize as I am doing something similar right now for Follow and Cover). Then you'd have to return automation when done. Plus all the logic surrounding when to do that and where for a fort.

Edit: Hmmm... not so sure now that I think about it more. I guess the only thing to do is try it.
 
Hmm, considering we know the Feitora gives some sort of defense modifier, it may be possible that the code no longer ignores improvements with a defense modifier in BNW.
 
Has the hardcoding for this been changed in the patch? Several unique improvements have defense... chateau, fetoria...

Don't have access to source.
 
Back
Top Bottom