Plot Capacity | Unit limit on Plot

J AV F, you know that you can play with the tags and numbers in XML <iUnitPlotCost> in the file CIV4UnitInfos.xml or <iUnitPlotSupport> in the files CIV4TerrainInfos.xml or CIV4FeatureInfos.xml or <City_Unit_Capacity> in the file GlobalDefines.xml.

That's about all you can do actually. When the AI will get stuck, you will be lost in an infinite loop (because basically it doesn't understand those rules - the AI should be taught how to behave properly about this in the SDK).

So far, the only way around this is then to zero the <iUnitPlotCost> in the file CIV4UnitInfos.xml and to continue your game without this component. :sad:
 
J AV F, you know that you can play with the tags and numbers in XML <iUnitPlotCost> in the file CIV4UnitInfos.xml or <iUnitPlotSupport> in the files CIV4TerrainInfos.xml or CIV4FeatureInfos.xml or <City_Unit_Capacity> in the file GlobalDefines.xml.

That's about all you can do actually. When the AI will get stuck, you will be lost in an infinite loop (because basically it doesn't understand those rules - the AI should be taught how to behave properly about this in the SDK).

So far, the only way around this is then to zero the <iUnitPlotCost> in the file CIV4UnitInfos.xml and to continue your game without this component. :sad:

isenchine, I thought the AI could handle smaller stacks instead (between 8 and 80, 44, d'you know), but you are probably right.

Thank you.
 
J AV F, you have to understand that this Mod component only limits units per tile. But it doesn't teach the AI to have smaller stacks. So when the AI comes with a big stack of units and limitations in tiles are all over the place, it doesn't know where to move its stack! Then it tries again... and again... and again... infinite loop!

To limit stacks, you have to limit units per Player/Team in the CIV4UnitClassInfos.xml or to use Python coding to limit the training of units.

But ultimately, it won't match the math of the unit limit on plots.
 
J AV F, you have to understand that this Mod component only limits units per tile. But it doesn't teach the AI to have smaller stacks. So when the AI comes with a big stack of units and limitations in tiles are all over the place, it doesn't know where to move its stack! Then it tries again... and again... and again... infinite loop!

To limit stacks, you have to limit units per Player/Team in the CIV4UnitClassInfos.xml or to use Python coding to limit the training of units.

But ultimately, it won't match the math of the unit limit on plots.

You are definitely right, I can se the infinite loop happening.

And after I pondered about the CIV4UnitClassInfos.xml possibilities, the problem is that even with limits to build units, AI would stack all they have.

It is just a shame, because the 44 I mentioned could enhance the battles a little, taking it to the terrain, once not even the defense could stack infinitely inside its own city.

But it is exactly what you have said, the AI would have huge problems: new units could have no place to be, islands and small cities would be very buggy, then, and the AI would not be able to play correctly.
 
To do this with python, it should be done using unitCannotMoveInto rather than cannotTrain.
The former will restrict units moving into a tile, thus limiting the number of units on that tile, whereas the later will just restrict how many you can build.

However, neither is a good solution as there will definitely be performance issues.
SDK is the only real solution, but without proper AI coding, it will just be dumb.
 
To do this with python, it should be done using unitCannotMoveInto rather than cannotTrain.
The former will restrict units moving into a tile, thus limiting the number of units on that tile, whereas the later will just restrict how many you can build.

However, neither is a good solution as there will definitely be performance issues.
SDK is the only real solution, but without proper AI coding, it will just be dumb.

Very advanced info, thank you. It is a shame that such thing is so hard to be done. It could take advantage of one of the best things in Civ5.

I have a question, then: how stacks are formed? I mean: is it influeced by code or does it happen as the AI tries to make the best use of its units?

When I play Civ3 for the first time, I did not know that I needed to stack units, I learned it from the AI, by the worst mean. :lol:
 
um can someone tell me exactly where to drop it, because I downloaded this I dropped it in the Civ 4 folder it replaced some thigns but still I can put 8 units in a single tile. So... not sure what I did wrong.
 
um can someone tell me exactly where to drop it, because I downloaded this I dropped it in the Civ 4 folder it replaced some thigns but still I can put 8 units in a single tile. So... not sure what I did wrong.

You should have installed it to the mods folder; and maybe you should reinstall your game if you replaced files.
 
Is there a way to use this mod with a .dll file that allows more than 18 civs?

Also, would there be a way to use this mod for buildings and railroads etc instead of for terrain features?

Ex:

Barracks allows 10 extra land units in a city
Harbor allows 10 extra sea units in a city

Roads allow 5 extra units on a tile
Railroads allow 10 extra units on a tile

I know that an airport provides a similiar bonus (allowing 4 extra air units in a city) so I thought maybe these other modifications could be done as well..
 
50caliber:

1) No. To allow more Civs, you would have to recompile this specific dll after having done a small modification in one .cpp file.

2) Only with some important C++ coding in cpp/h files and again a recompiled dll.
 
J AV F, you have to understand that this Mod component only limits units per tile. But it doesn't teach the AI to have smaller stacks. So when the AI comes with a big stack of units and limitations in tiles are all over the place, it doesn't know where to move its stack! Then it tries again... and again... and again... infinite loop!

To limit stacks, you have to limit units per Player/Team in the CIV4UnitClassInfos.xml or to use Python coding to limit the training of units.

But ultimately, it won't match the math of the unit limit on plots.

How well does the limiting of units per player/team work in game? Looks pretty easy to mod.

Do you know of any other modders that have had any success with the plot capacity concept?

The only possible solution to the SOD that I can think of would be to raise the unit costs of certain units (ex: 3x or even 5x) and then disabling the hurry production functions of slavery and gold....
 
I forgot to mention, when I played this mod it froze for me too, that's why I was asking if there were any other modders out there that may have had any success with the concept of plot capacity..
 
I forgot to mention, when I played this mod it froze for me too, that's why I was asking if there were any other modders out there that may have had any success with the concept of plot capacity..

None that I know.

But limiting the number of units is relatively easy. The XML solution is pretty straightforward.

Here is a Python solution: http://forums.civfanatics.com/showthread.php?t=407896
 
How well does the limiting of units per player/team work in game? Looks pretty easy to mod.

Do you know of any other modders that have had any success with the plot capacity concept?

The only possible solution to the SOD that I can think of would be to raise the unit costs of certain units (ex: 3x or even 5x) and then disabling the hurry production functions of slavery and gold....

the best way to deal with SOD's is a minigun! For every problem there is a solution... Miniguns!
 
It has been tried in Caveman2Cosmos (inherited from RoM:AND) but every now and they it stops with 'waiting for civs" because iirc the ai is trying to move a unit into or through a plot which already has the maximum number of units on it.

The suggested workaround in c2c is to load a save from before the problem and adjust the number of units per plot up by 10 for a few turns and then put it back down to the original number of units per plot. Yes we have an option screen that allows it to be changed. It is not a very satisfactory solution.
 
I thought about two ways to avoid infinite loops. It might not be possible to code, i can't say as i'm not a coder.

The infinite loop seems to be created when an AI try to recruit an unit and it cannot move this unit anywhere, and the tile is already at the limit.
Two solutions might solve this case:
- What if the unit is moved x tiles away, independently of the move capacity ? For ex: All the tiles around a city are to the limit, so the unit is "pushed" two tiles away. If two tiles away isn't possible, then it would be pushed further (even if it is through the ocean). This is not idealistic and can be exploited but it is far better than a game freeze.
- The other way is simply to kill the unit if it cannot be pushed on a tile around the city. This is more direct and can disadvantage the AI which don&#8217;t know how to handle that, but at least it won&#8217;t crash.

What do you think about that ? Would it be simple to code ? It might not need to put the hands on the dll code this way.
 
It's not just about a unit created, it's really about moving units around. The game freezes even if you have unlimited space in the city.

The "push unit" was tried by some people before with no success. The "kill unit" is indeed harsh for the AI as it can involve dozens of units at the same time. Anyway, both of these methods require dll coding.
 
Ok, thanks you for your answer !
 
[VK], i modified your CvUnits.cpp to fix that issue with the city not showing up as full when it is.

Basically needed to check to see if it was "attacking" that if it's a friendly city to the check. The Civ4 canMoveInto is called with bAttack set to both true and false, so the original 1.3 code would not execute when bAttack is set to true.

Spoiler :

/*
###########################################################
# VKs Plot Capacity - Start
###########################################################
*/
if ( (pPlot->getNumUnits() > 0) && !pPlot->isWater() ) //only go through when there is a Unit on the Plot, and it's not attackable.
//Plot have to be Land, because of Transporters.
{

if( !bAttack )
{
if( hasMaxUnitPerTile(pPlot) == true )
{
return false;
}
}

else
{
if( pPlot->isFriendlyCity(*this, true) )
{
if( hasMaxUnitPerTile(pPlot) == true )
{
return false;
}
}
}

}
/*
###########################################################
# VKs Plot Capacity - End
###########################################################
*/



I also added a new TAG into the GlobalDefinesAlt.xml to make it so Hills have can have an effect too.

Spoiler :
bool CvUnit::hasMaxUnitPerTile(const CvPlot* pPlot) const
{
int iMaxUnit = GC.getTerrainInfo( pPlot->getTerrainType()).getUnitPlotSupport();
if ( pPlot->getFeatureType() != NO_FEATURE ){
iMaxUnit += GC.getFeatureInfo( pPlot->getFeatureType()).getUnitPlotSupport();
}
if ( pPlot->getImprovementType() != NO_IMPROVEMENT ){
iMaxUnit += GC.getImprovementInfo( pPlot->getImprovementType()).getUnitPlotSupport();
}

if( pPlot->isHills() )
{
iMaxUnit += GC.getDefineINT("HIILS_CAPACITY_MODIFIER");
}


int iActualUnit = UnitPlotCost();

for ( int iNumberOfUnit = 0 ; iNumberOfUnit < pPlot->getNumUnits(); iNumberOfUnit++ ) { //Got through all units on plot and add the UnitPlotCost
CvUnit* unitOnPlot = pPlot->getUnitByIndex(iNumberOfUnit);
// iActualUnit += unitOnPlot->m_iUnitPlotCost;
iActualUnit += GC.getUnitInfo(unitOnPlot->getUnitType()).getUnitPlotCost(); // Get the UnitPlotcost from the Unit the pointer shows
}

if(!pPlot->isCity())
{ //Is Plot not a city
if( iActualUnit > iMaxUnit ){
return true;
}
}
else
{
if (GC.getDefineINT("City_Unit_Capacity") < 0 )
{
}
else if( iActualUnit > GC.getDefineINT("City_Unit_Capacity") )
{ //
return true;
}
}

return false;
}
 
Top Bottom