Creating culture and/or ownership

TC01

Deity
Joined
Jun 28, 2009
Messages
2,216
Location
Irregularly Online
I've added a tag to the XML called "iCultureRange"- it is meant to be a range of culture/ownership that gets created around a unit when that unit is created.

What I thought I would do is, in CvUnit::doTurn, loop around the unit and set ownership on all plots that are within iCultureRange.

Like this:

Code:
	int iCultureX;
	int iCultureY;
	int iDX;
	int iDY;
	int iCultureRange = getUnitInfo().getCultureRange();
	if (iCultureRange > 0)
	{
		for (iCultureX = -iCultureRange; iCultureX <= iCultureRange; iCultureX++)
		{
			for (iCultureY = -iCultureRange; iCultureY <= iCultureRange; iCultureY++)
			{
				iDX = iCultureX;
				iDY = iCultureY;
				if (GC.getMap().isWrapX())
				{
					if (iDX < 0)
						iDX = GC.getMap().getGridWidth() + iDX;
				}
				if (GC.getMap().isWrapY())
				{
					if (iDY < 0)
						iDY = GC.getMap().getGridHeight() + iDY;
				}
				CvPlot* pCulturePlot = plotXY(getX_INLINE(), getY_INLINE(), iCultureX, iCultureY);
				if (NULL != pCulturePlot)
				{
					if (pCulturePlot->getOwner() == NO_PLAYER)
					{
						pCulturePlot->setOwner(getOwner(), false, true);
					}
				}
			}
		}
	}

However, this only seems to work for the human player.

If I give the AI a unit through worldbuilder with the iCultureRange tag set, I will see their culture pop up briefly during their turn, but go away immediately afterwards. So by my turn, the culture is gone.

The culture/ownership created around my units, however, persists throughout the AI's turn. (Or at least, it appears to).

So, any idea on what am I doing wrong?

I know that I'm not actually creating "culture" (the game tells me that the plots have 0% of my culture, even though I do own them), but should I be? Should I be using setCulture or changeCulture or a function like that instead? Or is CvUnit::doTurn simply the wrong place for this code?
 
mmhh...I remember from the WB, that setting an owner for a tile does only really work via cities, means if it's in the range of a city/if the city has enough culture to own that tile. Has also the effect, that if you place culture tiles via the WB in an arbitrary area, that it then will vanish the next turn.
-> where were your units, where were the AI units?

Might be that the problem is in the setOwner function, and not in your code.
 
mmhh...I remember from the WB, that setting an owner for a tile does only really work via cities, means if it's in the range of a city/if the city has enough culture to own that tile. Has also the effect, that if you place culture tiles via the WB in an arbitrary area, that it then will vanish the next turn.
-> where were your units, where were the AI units?

Might be that the problem is in the setOwner function, and not in your code.

The units were on otherwise cultureless plots.

I do know about it vanishing on the next turn- I thought maybe I could avoid such issues by creating the culture in CvUnit::doTurn. Maybe not. :(

Try setting culture rather than ownership. IE,

Code:
pCulturePlot->changeCulture(getOwner(), 10, true);

If I replace the setOwner with that, nothing happens at all, no culture is created.
 
Plot ownership is set at the end of every game turn (not player turn) in CvPlot::doCulture() (called from doTurn()). This happens after all players have finished their moves.

I don't think it's human vs AI thing... I'm fairly sure that what you did persists for the duration of AI turns only because you are the first player (on random games, human is always first). When the game turn is finished, plot ownership is updated, and then your turn starts again. If you create a scenario where you are the last player, you should see the difference.

You can keep your CvUnit::doTurn thing so that it works instantly, but you'll also have to modify CvPlot::doCulture() and/or CvPlot:calculateCulturalOwner() so that it takes these special units into consideration. Don't bother with culture as such, just add a rule to override current rules for plot ownership.

EDIT: updated functions again: plot ownership is set in doCulture() but owner is determined in calculateCulturalOwner().
 
Plot ownership is set at the end of every game turn (not player turn) in CvPlot::doCulture() (called from doTurn()). This happens after all players have finished their moves.

I don't think it's human vs AI thing... I'm fairly sure that what you did persists for the duration of AI turns only because you are the first player (on random games, human is always first). When the game turn is finished, plot ownership is updated, and then your turn starts again. If you create a scenario where you are the last player, you should see the difference.

You can keep your CvUnit::doTurn thing so that it works instantly, but you'll also have to modify CvPlot::doCulture() and/or CvPlot:calculateCulturalOwner() so that it takes these special units into consideration. Don't bother with culture as such, just add a rule to override current rules for plot ownership.

EDIT: updated functions again: plot ownership is set in doCulture() but owner is determined in calculateCulturalOwner().

Thanks!

I haven't finished implementing this yet, but I believe I now understand how to do so. :)
 
embryodead has pointed you in the right direction. I had to modify doCulture() and calculateCulturalOwner() to make forts create culture borders in my mod.
 
Back
Top Bottom