any coding idea how to limit units on a tile

betto212

Chieftain
Joined
Apr 14, 2006
Messages
30
im tired of simple wars of 2 big stacks of 50 or bigger...well im trying to find a way to limit to 7 units on a tile for get more fun .
ANY IDEA WHERE encode that?
 
Lots of people have asked for something similar, but I don't know if anything has been done yet. You'd need to have a play in the SDK to get it working properly I believe - though you may be able to do it in python.

It'll probably mess up the AI pathfinding if you set the limit too low.
 
The Great Apple said:
Lots of people have asked for something similar, but I don't know if anything has been done yet. You'd need to have a play in the SDK to get it working properly I believe - though you may be able to do it in python.

It'll probably mess up the AI pathfinding if you set the limit too low.

the main trouble is not how ...the code to is simple ,a simple counter. the main trouble is where
... the ai is another problem but if something working is easier find how help to trick the ai

ok...about 10 will be fine in late game but in the start...is easy increase the amount of units alawed in a tile by the turns of the game but the first problem is where impose the limit...
 
Easy. See here, I limit stacks to 10:

Code:
bool CvUnit::canJoinGroup(const CvPlot* pPlot, CvSelectionGroup* pSelectionGroup) const
{
	CvUnit* pHeadUnit;

	if (pSelectionGroup->getOwnerINLINE() == NO_PLAYER)
	{
		pHeadUnit = pSelectionGroup->getHeadUnit();

		if (pHeadUnit != NULL)
		{
			if (pHeadUnit->getOwnerINLINE() != getOwnerINLINE())
			{
				return false;
			}
		}
	}
	else
	{
		if (pSelectionGroup->getOwnerINLINE() != getOwnerINLINE())
		{
			return false;
		}
	}

	if (pSelectionGroup->getNumUnits() > 0)
	{
		if (!(pSelectionGroup->atPlot(pPlot)))
		{
			return false;
		}

		if (pSelectionGroup->getDomainType() != getDomainType())
		{
			return false;
		}
		if(pSelectionGroup->getNumUnits() >= 10)	// Dale: Max of 10 units per stack
		{
			return false;
		}
	}

	return true;
}
 
Another idea would be to change the canMoveInto method in the CvSelectionGroup and CvUnit classes in the SDK. This way the AI wouldn't have any problems using it.
For CvSelectionGroup it would look like, changed code is in bold:
Code:
bool CvSelectionGroup::canMoveInto(CvPlot* pPlot, bool bAttack)
{
	CLLNode<IDInfo>* pUnitNode;
	CvUnit* pLoopUnit;

	[B]if (pPlot->getNumUnits() > 10)
	{
		return false;[/B]
	}

	if (getNumUnits() > 0)
	{
		pUnitNode = headUnitNode();

		while (pUnitNode != NULL)
		{
			pLoopUnit = ::getUnit(pUnitNode->m_data);
			pUnitNode = nextUnitNode(pUnitNode);

			if (!(pLoopUnit->canMoveInto(pPlot, bAttack)))
			{
				return false;
			}
		}

		return true;
	}

	return false;
}

For CvUnit it would look like:
Code:
bool CvUnit::canMoveInto(const CvPlot* pPlot, bool bAttack, bool bDeclareWar, bool bIgnoreLoad) const
{
	TeamTypes ePlotTeam;

	FAssertMsg(pPlot != NULL, "Plot is not assigned a valid value");

	if (atPlot(pPlot))
	{
		return false;
	}

	if (pPlot->isImpassable())
	{
		if (!canMoveImpassable())
		{
			return false;
		}
	}

	[B]if (pPlot->getNumUnits() > 10)
	{
		return false;[/B]
	}
...
...

I didn't include the rest of the CvUnit canMoveInto method since the change is only in the first part of the method.
While you could follow Dale's idea, personally I don't feel it is the right place to put the check to limit the number of units.
 
Agree there - the unit movement controls should be in a function called "canMoveInto", although I think Dale's method may only take into account friendly units. I think you may have to use the bAttack flag:
Code:
	if (!bAttack)
	{
		if (pPlot->getNumUnits() > 10)	
		{
			return false;
		}
	}
*mutters something rude about TheLopez not following Firaxis coding style and missing out curly brackets*

The AI issues I envisage aren't due to the fact that the AI couldn't work out it wasn't allowed to move there, but due to the fact that you (or it) could completely block off sections of the map, and cause the pathfinding to go crazy, especially if the number was set too low. This is why you might want to check whether the unit is the same team as the moving unit or not.
 
It would also make cities impossible to defend. Attackers would be gauranteed that there would be no more than X defenders possible, which would make it easy to plan for overwhelming attacks. It would also drastically decrease the value of artillery and air power.
 
Zurai said:
It would also make cities impossible to defend. Attackers would be gauranteed that there would be no more than X defenders possible, which would make it easy to plan for overwhelming attacks. It would also drastically decrease the value of artillery and air power.
Very good point... although again you could make exceptions in the code for this.
 
The Great Apple said:
*mutters something rude about TheLopez not following Firaxis coding style and missing out curly brackets*


I don't know what you are talking about...:mischief:
 
You can create some python loopbacks (or pre-events) into both functions (canJoinGroup and canMoveInto). Then you are able to control the complete topic via python in CvGameUtils. I put it onto my todo list for the first relaese of the civ4ccp.

12m
 
TheLopez's code while neat does not cover all situations. There are many situations where canMoveInto is not called, thus the check placed there is useless. City builds, air rebasing, combat (uses "canAdvance" not "canMoveInto"), etc. Also, canMoveInto does not take into account cargo on ships etc.

My example covers all the points raised above by the others. By limiting the stack it leaves the tile open to other players, it is not affected by combat and covers situations where canMoveInto is not called. The AI also uses "canJoinGroup" so it covers the AI as well.

To be honest, I don't see the point of limiting the total number of units in a tile. You block the tile off for non-enemy players, as mentioned it stuffs up city defense, and I bet it'd play havac on auto-workers. Also, what happens in a city if the max units is there and then you build another? Are fighters on a carrier included in the limit? Or units on a transport? Makes naval invasions useless. Also, allies units on the tile too. Another thing that the human can use as a MASSIVE exploit, in canMoveInto it includes stealth units, so if there is 5 units in a tile and you can only move another 4 in, someone has a stealth unit there. Not a good situation at all.

Thus I gave the example of limiting a stack. A neater method for sure without the debilitating effects of limiting the actual tile itself.

Dale
 
Zurai said:
It would also make cities impossible to defend. Attackers would be gauranteed that there would be no more than X defenders possible, which would make it easy to plan for overwhelming attacks. It would also drastically decrease the value of artillery and air power.
the point is a fight of two stacks of 50 is boring...force fights of armies of 10 moving in fronts will be nice
and about artillery...just increasing the range for 2 or 3 then positioning in back of the infantary
 
Dale said:
TheLopez's code while neat does not cover all situations. There are many situations where canMoveInto is not called, thus the check placed there is useless. City builds, air rebasing, combat (uses "canAdvance" not "canMoveInto"), etc. Also, canMoveInto does not take into account cargo on ships etc.

My example covers all the points raised above by the others. By limiting the stack it leaves the tile open to other players, it is not affected by combat and covers situations where canMoveInto is not called. The AI also uses "canJoinGroup" so it covers the AI as well.

To be honest, I don't see the point of limiting the total number of units in a tile. You block the tile off for non-enemy players, as mentioned it stuffs up city defense, and I bet it'd play havac on auto-workers. Also, what happens in a city if the max units is there and then you build another? Are fighters on a carrier included in the limit? Or units on a transport? Makes naval invasions useless. Also, allies units on the tile too. Another thing that the human can use as a MASSIVE exploit, in canMoveInto it includes stealth units, so if there is 5 units in a tile and you can only move another 4 in, someone has a stealth unit there. Not a good situation at all.

Thus I gave the example of limiting a stack. A neater method for sure without the debilitating effects of limiting the actual tile itself.

Dale
the point is that a fight of two stacks of 50 is boring... and will force a more complex battles
 
betto212 said:
the point is that a fight of two stacks of 50 is boring... and will force a more complex battles

Hence why I said limit the stack, not the tile. :)
 
" To be honest, I don't see the point of limiting the total number of units in a tile."
how is the best way of crush an enemy city ? you take a big stack of units in a single tile and move to... how is the best way to counter take a big number of units and place on the city...the bigger and stroger ever win .no strategy on this, its like chess of 2 pieces
thats somewhat boring ... do you agree ?
limiting the number of units in a tile solve this, i think
 
Dale said:
Hence why I said limit the stack, not the tile. :)
Couldn't you then just have 5 stacks of 10?
 
Shqype said:
Couldn't you then just have 5 stacks of 10?
my idea is 5 stacks of 10 but in diferent tiles... the main idea is force tatical moves like protect artilery ou make a barrier for stop enemy advance ...with a unlimited number of unit in a tile the big attaks are unstopable...
 
Well, for my Eastern European Battles mod, I planned on implementing a tile limit for all tiles EXCEPT cities. The goal is to diversify city attacks and to prevent super-large stacks of 20 and above. The 10 limit would have been ideal for me. This means that the absolute maximum number of units that could attack a city per turn is 80.

12Monkeys, I have a request for you for CIV4CCP!

Could you implement such a system that limits the amount of units on a non-city tile? I believe the way would be like this:

Allow an option (preferably in GlobalDefines.xml) for each terrain type that has a "space amount," or the amount of space available on each tile for that terrain. By default, you might want to set it to -1 so that there is no limit unless someone actually wants one.

Then, in the CIV4UnitInfos.xml allow a new XML tag <i[TERRAIN]Space> which will define the amount of space the unit takes up. For example, let's say that each plot of land has a maximum of 10 space, then the "space values" of all the units on that plot of land are added up and allowed so long as the number does not exceed the limit (10).

So, regular army units could take up 1 space, for instance, but then you could get heavy artillery which takes up 2 spaces, etc, etc. Maybe later on a tank could take up 3 space.

You could set the default value to 1 so that it wouldn't break any mods already out there; coupled with the -1 default value for the terrain limit this wouldn't hurt at all.

But, it would add a greater depth to the game as far as strategy is concerned. If you made the space limits by terrain type and not domain type, then you could fit much more units in open space (plains) than you can in hills or forest, for instance. This would really protect civilizations with their cities deep in forests or hills because less enemy military units will be able to attack them per turn (because of the terrain tile limit), instead of the way it currently is in CIV 4: if enemy units are on a jungle tile outside of your city, they actually get a defense bonus which only aids their conquest against you, not hinders it!
 
Shqype said:
Well, for my Eastern European Battles mod, I planned on implementing a tile limit for all tiles EXCEPT cities. The goal is to diversify city attacks and to prevent super-large stacks of 20 and above. The 10 limit would have been ideal for me. This means that the absolute maximum number of units that could attack a city per turn is 80.

12Monkeys, I have a request for you for CIV4CCP!

Could you implement such a system that limits the amount of units on a non-city tile? I believe the way would be like this:

Allow an option (preferably in GlobalDefines.xml) for each terrain type that has a "space amount," or the amount of space available on each tile for that terrain. By default, you might want to set it to -1 so that there is no limit unless someone actually wants one.

Then, in the CIV4UnitInfos.xml allow a new XML tag <i[TERRAIN]Space> which will define the amount of space the unit takes up. For example, let's say that each plot of land has a maximum of 10 space, then the "space values" of all the units on that plot of land are added up and allowed so long as the number does not exceed the limit (10).

So, regular army units could take up 1 space, for instance, but then you could get heavy artillery which takes up 2 spaces, etc, etc. Maybe later on a tank could take up 3 space.

You could set the default value to 1 so that it wouldn't break any mods already out there; coupled with the -1 default value for the terrain limit this wouldn't hurt at all.

But, it would add a greater depth to the game as far as strategy is concerned. If you made the space limits by terrain type and not domain type, then you could fit much more units in open space (plains) than you can in hills or forest, for instance. This would really protect civilizations with their cities deep in forests or hills because less enemy military units will be able to attack them per turn (because of the terrain tile limit), instead of the way it currently is in CIV 4: if enemy units are on a jungle tile outside of your city, they actually get a defense bonus which only aids their conquest against you, not hinders it!
yeah the limiting of units force strategy like defend your cite before the invaders be near the city center ,in real world if the invaders hit the doors of the city center that means that invading squad is winning
 
Shqype said:
Well, for my Eastern European Battles mod, I planned on implementing a tile limit for all tiles EXCEPT cities. The goal is to diversify city attacks and to prevent super-large stacks of 20 and above. The 10 limit would have been ideal for me. This means that the absolute maximum number of units that could attack a city per turn is 80.

12Monkeys, I have a request for you for CIV4CCP!

Could you implement such a system that limits the amount of units on a non-city tile? I believe the way would be like this:

Allow an option (preferably in GlobalDefines.xml) for each terrain type that has a "space amount," or the amount of space available on each tile for that terrain. By default, you might want to set it to -1 so that there is no limit unless someone actually wants one.

Then, in the CIV4UnitInfos.xml allow a new XML tag <i[TERRAIN]Space> which will define the amount of space the unit takes up. For example, let's say that each plot of land has a maximum of 10 space, then the "space values" of all the units on that plot of land are added up and allowed so long as the number does not exceed the limit (10).

So, regular army units could take up 1 space, for instance, but then you could get heavy artillery which takes up 2 spaces, etc, etc. Maybe later on a tank could take up 3 space.

You could set the default value to 1 so that it wouldn't break any mods already out there; coupled with the -1 default value for the terrain limit this wouldn't hurt at all.

But, it would add a greater depth to the game as far as strategy is concerned. If you made the space limits by terrain type and not domain type, then you could fit much more units in open space (plains) than you can in hills or forest, for instance. This would really protect civilizations with their cities deep in forests or hills because less enemy military units will be able to attack them per turn (because of the terrain tile limit), instead of the way it currently is in CIV 4: if enemy units are on a jungle tile outside of your city, they actually get a defense bonus which only aids their conquest against you, not hinders it!

What I plan to do is to create the basics that you can do it yourself easily in Python. I will add some Python Loopbacks in the SDK, which results in a new function in the CvGameUtils.py. There you can easily add some Python code to restrict stack size or number of units per tile as you like. You also can make exceptions for cities.
 
Back
Top Bottom