Water-based improvements

Discussion in 'Civ5 - Creation & Customization' started by PawelS, Apr 16, 2016.

  1. PawelS

    PawelS Ancient Druid

    Joined:
    Dec 11, 2003
    Messages:
    2,803
    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.
     
  2. Wolfdog

    Wolfdog Unit Butcher

    Joined:
    Jun 29, 2012
    Messages:
    660
    Location:
    Australia
    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?
     
  3. Enginseer

    Enginseer Salientia of the Community Patch Supporter

    Joined:
    Nov 7, 2012
    Messages:
    3,229
    Gender:
    Male
    Location:
    Somewhere in California
    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)
     
  4. whoward69

    whoward69 DLL Minion

    Joined:
    May 30, 2011
    Messages:
    8,581
    Location:
    Near Portsmouth, UK
    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
     
  5. PawelS

    PawelS Ancient Druid

    Joined:
    Dec 11, 2003
    Messages:
    2,803
    Location:
    Poland
    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.
     
  6. whoward69

    whoward69 DLL Minion

    Joined:
    May 30, 2011
    Messages:
    8,581
    Location:
    Near Portsmouth, UK
    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".

    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"/>
    
     
  7. PawelS

    PawelS Ancient Druid

    Joined:
    Dec 11, 2003
    Messages:
    2,803
    Location:
    Poland
    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?

    I like these events :)
     
  8. whoward69

    whoward69 DLL Minion

    Joined:
    May 30, 2011
    Messages:
    8,581
    Location:
    Near Portsmouth, UK
    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.
     
  9. bane_

    bane_ Howardianism High-Priest

    Joined:
    Nov 27, 2013
    Messages:
    1,559
    If you are already creating dummy resources, why don't you apply the improvement directly?
    Seems to go more smoothly.
     
  10. PawelS

    PawelS Ancient Druid

    Joined:
    Dec 11, 2003
    Messages:
    2,803
    Location:
    Poland
    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.
     
  11. Gazebo

    Gazebo Lord of the Community Patch Supporter

    Joined:
    Sep 26, 2010
    Messages:
    18,331
    Gender:
    Male
    Location:
    Little Rock
    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
     
  12. whoward69

    whoward69 DLL Minion

    Joined:
    May 30, 2011
    Messages:
    8,581
    Location:
    Near Portsmouth, UK
    Which macro tag?
     
  13. Gazebo

    Gazebo Lord of the Community Patch Supporter

    Joined:
    Sep 26, 2010
    Messages:
    18,331
    Gender:
    Male
    Location:
    Little Rock
    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.
     

Share This Page