1. We have added a Gift Upgrades feature that allows you to gift an account upgrade to another member, just in time for the holiday season. You can see the gift option when going to the Account Upgrades screen, or on any user profile screen.
    Dismiss Notice

Creating culture and/or ownership

Discussion in 'Civ4 - SDK/Python' started by TC01, Jun 24, 2012.

  1. TC01

    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?
     
  2. The_J

    The_J Say No 2 Net Validations Retired Moderator Supporter

    Joined:
    Oct 22, 2008
    Messages:
    31,408
    Location:
    DE/NL/FR
    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.
     
  3. Tholal

    Tholal Emperor

    Joined:
    May 19, 2009
    Messages:
    1,676
    Try setting culture rather than ownership. IE,

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

    TC01 Deity

    Joined:
    Jun 28, 2009
    Messages:
    2,216
    Location:
    Irregularly Online
    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. :(

    If I replace the setOwner with that, nothing happens at all, no culture is created.
     
  5. embryodead

    embryodead Caliph

    Joined:
    Jan 1, 2003
    Messages:
    5,179
    Location:
    basement
    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().
     
  6. TC01

    TC01 Deity

    Joined:
    Jun 28, 2009
    Messages:
    2,216
    Location:
    Irregularly Online
    Thanks!

    I haven't finished implementing this yet, but I believe I now understand how to do so. :)
     
  7. Red Key

    Red Key Modder

    Joined:
    Sep 24, 2011
    Messages:
    407
    Gender:
    Male
    Location:
    USA
    embryodead has pointed you in the right direction. I had to modify doCulture() and calculateCulturalOwner() to make forts create culture borders in my mod.
     

Share This Page