Water-based improvements

PawelS

Ancient Druid
Joined
Dec 11, 2003
Messages
2,811
Location
Poland
I'm going to add an improvement type that can be built on water tiles without resources (coast only, no two adjacent.) I can allow workboats or embarked workers to build it and it should work fine for the human player, but (when I look at the DLL code) it seems the AI won't build them. Is there an easy way to "convince" it to build such improvements? (other than direct Lua control over AI units, which would be too complicated for me)

Does the VMC DLL or CP DLL change the way the AI works in this regard, so it considers building improvements on non-resource water tiles? If so, I think I will add this feature in a future version of the mod, after I switch to one of these DLLs.
 
Its probably not what you are after but what about a lua script that generate a dummy recourse on non-resourced, coast only and no two adjacent tiles within a cities borders?
 
Does the VMC DLL or CP DLL change the way the AI works in this regard, so it considers building improvements on non-resource water tiles? If so, I think I will add this feature in a future version of the mod, after I switch to one of these DLLs.

Well, the VMC and CP DLL are essentially the same since the CP DLL was based off the VMC DLL.

I believe whoward talked about bug fixes where the AIs would build improvements where they wouldn't do so in vanilla (Ex. Legions finally have an idea to build roads and forts)
 
Does the VMC DLL or CP DLL change the way the AI works in this regard

Yes - they both do. I fixed the AI logic such that Samurai's will (eventually) embark and build fishing boats.

(Also Legions will build Forts and Roads and the Spanish unit will occasionally found a foreign city)

HTH

W
 
Will they also build improvements on non-resource water tiles, if such improvement type is present in the mod? Also, is there an event that can be used to control where an improvement can be built? (for example if I want to allow it on coastal sea tiles, but not on lake tiles, or vice versa)

@Wolfdog: a dummy resource is an interesting solution too, I will consider it as an alternative.
 
Will they also build improvements on non-resource water tiles, if such improvement type is present in the mod?
Good question. There's nothing in the fix that says "on resources only" - the fix says "if I'm a combat unit that is currently doing nothing but wandering around aimlessly (aka "homeland defence"), and I can build an improvement, and a target tile for such an improvement is within reasonable range (ie do NOT walk half way around the planet!), then goto that plot (embarking if necessary) and build it".

Also, is there an event that can be used to control where an improvement can be built?
Code:
    <!-- Events sent by plots (v30) -->
    <!--   GameEvents.PlayerCanBuild.Add(function(iPlayer, iUnit, iX, iY, iBuild) return true end) -->
    <!--   GameEvents.PlotCanImprove.Add(function(iX, iY, iImprovement) return true end) -->
    <!--   GameEvents.PlayerBuilding.Add(function(iPlayer, iUnit, iX, iY, iBuild, bStarting) end) (v46) -->
    <!--   GameEvents.PlayerBuilt.Add(function(iPlayer, iUnit, iX, iY, iBuild) end) (v46) -->
    <!-- See also: "Improvement - Pontoon Bridge" -->
    <Row Class="3" Name="EVENTS_PLOT" Value="0"/>
 
Good question. There's nothing in the fix that says "on resources only" - the fix says "if I'm a combat unit that is currently doing nothing but wandering around aimlessly (aka "homeland defence"), and I can build an improvement, and a target tile for such an improvement is within reasonable range (ie do NOT walk half way around the planet!), then goto that plot (embarking if necessary) and build it".

Does it also apply to non-combat units? Actually I'm going to make these improvements buildable by embarked workers, not by combat units. In the standard DLL, CvBuilderTaskingAI.cpp, function CvBuilderTaskingAI::ShouldBuilderConsiderPlot, there is code that prevents it:

Code:
	// workers should not be able to work in plots that do not match their default domain
	switch(pUnit->getDomainType())
	{
	case DOMAIN_LAND:
		if(pPlot->isWater())
		{
			return false;
		}
		break;
	case DOMAIN_SEA:
		if(!pPlot->isWater())
		{
			return false;
		}
		break;
	default:
		break;
	}

Does it still apply in your DLL?

Code:
    <!-- Events sent by plots (v30) -->
    <!--   GameEvents.PlayerCanBuild.Add(function(iPlayer, iUnit, iX, iY, iBuild) return true end) -->
    <!--   GameEvents.PlotCanImprove.Add(function(iX, iY, iImprovement) return true end) -->
    <!--   GameEvents.PlayerBuilding.Add(function(iPlayer, iUnit, iX, iY, iBuild, bStarting) end) (v46) -->
    <!--   GameEvents.PlayerBuilt.Add(function(iPlayer, iUnit, iX, iY, iBuild) end) (v46) -->
    <!-- See also: "Improvement - Pontoon Bridge" -->
    <Row Class="3" Name="EVENTS_PLOT" Value="0"/>

I like these events :)
 
Does it also apply to non-combat units?
No. It was a fix for the AI never using combat units as workers. The base restrictions of workers building on land and workboats building on water still apply.

If you remove those, and then use non-instantaneous builds, you may find that the graphics engine throws a fit trying to animate an embarked worker.
 
Perhaps you're right... Generally the problem is more complicated than I thought, so I won't make such improvements in the first version of the mod, and leave them for a later version. Thanks to all for explanations and suggestions, I will consider all these options when adding this feature.
 
Yes - they both do. I fixed the AI logic such that Samurai's will (eventually) embark and build fishing boats.

(Also Legions will build Forts and Roads and the Spanish unit will occasionally found a foreign city)

HTH

W

One point I should note, Whoward, is that I've encountered some bugs with the fishing boats hack that Firaxis employed. In short, units may grab the first improvement that is valid instead of the right improvement, and will fail on their improvement task later in the homeland AI. In any case, Iamblichos rewrote this in the CP DLL so that the AI grabs the right improvement for the right task, and actually passes the correct improvement to the builder later on.

G
 
Iamblichos rewrote this in the CP DLL so that the AI grabs the right improvement for the right task

Which macro tag?
 
Which macro tag?

I don't think he tagged it, now that I look. :( :(

I'll ask him to do so.

Meanwhile, it is in void CvHomelandAI::FindHomelandTargets(), first segment (the sea resources). You can then follow m_TargetedNavalResources down the rabbit hole.
 
Back
Top Bottom