building/improvement to generate water?

davidlallen

Deity
Joined
Apr 28, 2008
Messages
4,743
Location
California
We have been working on a Dune mod, but it doesn't do anything special for water. Water should be scarce, and irrigation should also be scarce. We have a mapscript which generates no ocean, oasis, lakes or rivers, but it generates an occasional water improvement. We have buildings like windtraps (which collect water) and reservoirs.

In vanilla civ, improvements can spread irrigation (farms with civil service tech). So you can chain farms away from the terrain water sources. But I cannot find a way that an improvement or building can act as a source for this water.

Does anybody know if there is a tag or existing mod which lets buildings and improvements generate water for irrigation? If not, is there a python hook that would let us do anything? There are python calls to check if a plot is a lake or has irrigation, but nothing to set that. It might be possible to copy each related terrain type and make a variant which has the xml tag bFreshWater set. Then when the improvement is created/destroyed, python could change the terrain type of the plot so it becomes the variant with/without fresh water. That makes a lot of extra terrain types.

I am sure it is possible in the sdk, but I would prefer to leave that as a last resort. If anybody has specifics on that, it would help a little.
 
I've also thought about that, because i have the same problem.

First thought, without any coding:
I have 2 farms, farm V1 upgrades to farm V2. Give the V1 no foodbonus, and only V2 +1:food:. This would simulate the problem a bit.

Second thought: Features have the fresh water tag, so you could create an improvement, which sets that feature.
No idea about the AI :(.


No real further ideas atm :(.
 
Couldn't you just clone the "provides water" (or whatever it is called) tag from terrain infos into improvement infos? Assuming it is that easy, teaching the AI to use it is going to be the most difficult step.
 
Couldn't you just clone the "provides water" (or whatever it is called) tag from terrain infos into improvement infos?

I will add "just" in quotation marks :-). (a) I was hoping there was a python solution (thank you again for the encouragement to learn the sdk, but that is not in the cards for me right now). (b) I would think that some parts of the sdk call something like PlotGetHasFreshWater, so adding a bit to the improvement data structure to store HasFreshWater is only a start. Each time an improvement is created or destroyed, it needs to set or clear the HasFreshWater on the plot. Maybe it is not much code, and maybe we can try that out.

If we did this, let us explore what the AI would have to do. Maybe there is a way to fake it. There are a few ways in which a plot can get water, and the AI presumably makes some use of that. For example, plots which are next to oases should be more attractive to put farms, compared to an otherwise identical tile which is not next to an oasis. Assuming that is not hardcoded, then as long as the plot reacts just like an oasis, we should not have to do much to encourage building next to these improvements/buildings.

Another question is how to encourage the AI to research the tech. The techs in question (in the Dune Wars tech tree) are low level fundamental ones. If we need to we can increase the AIWeight, but these are already popular. A third question is how to encourage the AI to build the improvement. The reservoir (wonder/building) can be given a high AIWeight; no problem. I do not see offhand how to encourage selection of an improvement; maybe that is a problem.

So it seems the only trick for the AI is selecting an improvement. Maybe we can brainstorm a solution to that.
 
OK, I have something working in python. It is a hack, but it works. An oasis is a feature with the flag bAddsFreshWater set. I made a copy of this feature with an artdef that has fScale 0.001 so the graphic is tiny, basically invisible. Then in python, I add code to onImprovementBuilt which says, if a windtrap is built, set the feature of this plot to my new feature. Similarly, onBuildingBuilt says, if a reservoir is built, set the feature of this plot to my new feature. Finally, set the feature to -1 in onImprovementDestroyed.
That's it!

When the feature appears, the engine sets the fresh water flag on all the adjacent squares. Now I can build a farm, where I could not before. The standard irrigation propagation rules will apply. In vanilla, there could be a case where I have a chain of farms propagating irrigation, and one farm in the middle is pillaged. In this case the farm at the end no longer has fresh water, and it stops providing a bonus. If you build back the destroyed farm then the farm at the end goes back to providing a bonus. The same thing works with this improvement. There is no onBuildingDestroyed, so I can't get rid of it if the reservoir is destroyed, but that's not my fault :-)

We can give the building a high AIWeight and put it low in the tech tree. The AI will be likely to build the building even if it doesn't know why, and then it will be pleasantly surprised when fresh water appears.

There is no good way for the AI to know about the improvement. This is the only loose end. I do not know of anything like AIWeight for improvements, so there is no good way to fake it.

Can anybody suggest another approach, which would work for the AI? Or a way to encourage the AI to build a particular improvement?
 
Cool. One problem which may occur is that when you hack things in like this with Python, the AI often isn't aware it exists. So definatly check and make sure the AI realizes it can build farms off the feature.
 
Well, it is working, and not working. It works in vanilla but the underlying feature is deleted by the Dune Wars sdk for an unknown reason. Details at this link.

I have made the windtrap improvement available on hills and peaks only, giving +2 food, and this makes the AI very interested in using it. Once it is tricked into building this unit, that should put fresh water around, which makes the other farm improvements buildable, and then the irrigation chaining should work from that.

But I cannot see it working because the feature is deleted. Hopefully we can figure that out.
 
Good to know. Could you say a little about how? If you recall, and have a minute to write, it will save me some time in poking around.
 
Update: this happens in vanilla revdcm, outside the dune mod. I have posted on the revdcm bug thread.

Later update: solved in this post. RevDCM makes some strong assumptions about your features.
 
Back
Top Bottom