[SDK] How to explain to AI that an improvement makes terrain impassable ?

Fabrysse

Charming-snake learner
Joined
Sep 11, 2006
Messages
430
Location
Toulouse - France
SDK MASTERS, PLEASE HELP ME !!!

In my Mod "Spain 1936", I've added an entanglement improvement (that graphic elements come from the mod "WWII 1939").

I've done (via python) that if a tile has this improvement, the land units can't walk on it, except the workers.
It runs, but the AI never construct this improvement because he doesn't know what it is (the XML description is totally empty).

Where and how could I explain to the AI what this improvement does ?
 
Intercept the canMoveInto() method. Would you prefer SDK or python code? Jeckels modcomp for tile limits used to use that in python exclusively but I think he now uses the SDK, I've done something similar in my mod entirely within the SDK but it's very possible in Python and not terribly complex.
 
Intercept the canMoveInto() method. Would you prefer SDK or python code? Jeckels modcomp for tile limits used to use that in python exclusively but I think he now uses the SDK, I've done something similar in my mod entirely within the SDK but it's very possible in Python and not terribly complex.

I've modified the method connot MoveInto() (looking what Jeckel did for his Mod. It works with no problem.
That's not my problem.
My problem is that the AI never builds this improvement.
I want the AI to build this improvement. So I'd like to explain where to build it, and why : what it will do when it'll be done...
I suppose it's somewhere in the SDK. But where ? How will I explain that a tile with this improvement becomes impassable ? How will I explain why it's interesting to build this ?
 
Ah, sorry :)

It would be tough to get the AI to understand when that would be helpful, in what cases would you like the to buld those improvements? If you know that then you can go into CvUnitAI.cpp, find either the AI_improveLocalPlot, AI_improvePlot or AI_improveCity method and add your rules there. The local plot one has some good examples of how to define the best build for the plot.
 
Ah, sorry :)

It would be tough to get the AI to understand when that would be helpful, in what cases would you like the to buld those improvements? If you know that then you can go into CvUnitAI.cpp, find either the AI_improveLocalPlot, AI_improvePlot or AI_improveCity method and add your rules there. The local plot one has some good examples of how to define the best build for the plot.

Oh, thanks !!!
What I want is to use trenches (replaces fort improvement) and entanglements, so that trenches are fortified, with some units in it, and entanglements (armies can't walk on it) force the attacker to attack the trenche to be able to go to a city, or have to use a much longer road.
I'd like the AI to build that near the frontiers with hostile civs to protect the first cities...

I'll have a look to these functions.
 
That should be doable :)

Most of the code for workers has them checking for nearby danger, you can use that to encourage them to build your new improvements and it's an easy check to see if the enemy border is close. You should also be able to get them to build outside of the fat cross, or at least prefer building outside the fat cross. The hardest part will be getting them to understand how to use both improvements together, you'll have to evaluate the area a little yourself and try to define some sort of strategy. Once I'm not burried in my own work on the AI and trying to get them to understand my changes I'll see if I can give you a hand.
 
C++ is much easier than Python, I have modified two python components in my mod and that's two too many :)

The isActionRecommended method is used to put the blue outline on the action buttons in the interface, it has no effect on the AI. You need to provide it with the action (integer, not enum) and it returns true or false.

The canBuild is a good way to disallow something from being built but it has no direct impact on the AI aside from not letting them build something. An example of using this method would be changing mines so that they could only be built if the closest city had the mining inc corporation building in it.

If you want to stick to python you can just force the unit to build it. perhaps checking every worker in their onTurn (or is it doTurn) event, if they're controlled by the AI call your own python code to evaluate the plot. It'll slow the game down noticeably when you have a lot of workers though. You'd get better results adding support for the new improvement directly to the AI in the SDK, that way you could have the AI evaluate the improvement definition itself which in turn would support the addition of similar improvements in the future and not forcibly override the AI's own priorities like connecting resources or cities.
 
Back
Top Bottom