Problems with GameOptions and Globals.cpp

Afforess

The White Wizard
Joined
Jul 31, 2007
Messages
12,239
Location
Austin, Texas
I'm trying to turn the larger radius cities code that a modder for RoM made into a game option, but the Globals.cpp refuses to cooperate, despite by best efforts. Here's the section I'm changing.

Normal BTS Code:


Spoiler :
Code:
    int aiCityPlotX[NUM_CITY_PLOTS] =
    {
        0,
        0, 1, 1, 1, 0,-1,-1,-1,
        0, 1, 2, 2, 2, 1, 0,-1,-2,-2,-2,-1,
    };

    int aiCityPlotY[NUM_CITY_PLOTS] =
    {
        0,
        1, 1, 0,-1,-1,-1, 0, 1,
        2, 2, 1, 0,-1,-2,-2,-2,-1, 0, 1, 2,
    };

    int aiCityPlotPriority[NUM_CITY_PLOTS] =
    {
        0,
        1, 2, 1, 2, 1, 2, 1, 2,
        3, 4, 4, 3, 4, 4, 3, 4, 4, 3, 4, 4,
    };

    int aaiXYCityPlot[CITY_PLOTS_DIAMETER][CITY_PLOTS_DIAMETER] =
    {
        {-1, 17, 18, 19, -1,},

        {16, 6, 7, 8, 20,},

        {15, 5, 0, 1, 9,},

        {14, 4, 3, 2, 10,},

        {-1, 13, 12, 11, -1,}
    };

My Code:
Spoiler :
Code:
    if (GC.getGameINLINE().isOption(GAMEOPTION_LARGER_CITIES))
    {
        int aiCityPlotX[NUM_CITY_PLOTS] =
        {
            0,
            0, 1, 1, 1, 0,-1,-1,-1,
            0, 1, 2, 2, 2, 1, 0,-1,-2,-2,-2,-1,
    /*************************************************************************************************/
    /** JOOYO_ADDON, Added by Jooyo, 06/17/09                                                        */
    /**                                                                                              */
    /**                                                                                              */
    /*************************************************************************************************/
            0, 1, 2, 3, 3, 3, 2, 1, 0, -1, -2, -3, -3, -3, -2, -1,
    /*************************************************************************************************/
    /** JOOYO_ADDON                          END                                                     */
    /*************************************************************************************************/
        }'
    }
    else
    {
        int aiCityPlotX[NUM_CITY_PLOTS] =
        {
            0,
            0, 1, 1, 1, 0,-1,-1,-1,
            0, 1, 2, 2, 2, 1, 0,-1,-2,-2,-2,-1,
        };
    }

    if (GC.getGameINLINE().isOption(GAMEOPTION_LARGER_CITIES))    
    {
        int aiCityPlotY[NUM_CITY_PLOTS] =
        {
            0,
            1, 1, 0,-1,-1,-1, 0, 1,
            2, 2, 1, 0,-1,-2,-2,-2,-1, 0, 1, 2,
    /*************************************************************************************************/
    /** JOOYO_ADDON, Added by Jooyo, 06/17/09                                                        */
    /**                                                                                              */
    /**                                                                                              */
    /*************************************************************************************************/
            3, 3, 2, 1, 0, -1, -2, -3, -3, -3, -2, -1, 0, 1, 2, 3,
    /*************************************************************************************************/
    /** JOOYO_ADDON                          END                                                     */
    /*************************************************************************************************/
        };
    }
    else
    {
        int aiCityPlotY[NUM_CITY_PLOTS] =
        {
            0,
            1, 1, 0,-1,-1,-1, 0, 1,
            2, 2, 1, 0,-1,-2,-2,-2,-1, 0, 1, 2,
        };
    }

    if (GC.getGameINLINE().isOption(GAMEOPTION_LARGER_CITIES))    
    {
        int aiCityPlotPriority[NUM_CITY_PLOTS] =
        {
            0,
            1, 2, 1, 2, 1, 2, 1, 2,
            3, 4, 4, 3, 4, 4, 3, 4, 4, 3, 4, 4,
    /*************************************************************************************************/
    /** JOOYO_ADDON, Added by Jooyo, 06/17/09                                                        */
    /**                                                                                              */
    /**                                                                                              */
    /*************************************************************************************************/
            5, 6, 7, 6, 5, 6, 7, 6, 5, 6, 7, 6, 5, 6, 7, 6,
    /*************************************************************************************************/
    /** JOOYO_ADDON                          END                                                     */
    /*************************************************************************************************/
        };
    }
    else
    {
        int aiCityPlotPriority[NUM_CITY_PLOTS] =
        {
            0,
            1, 2, 1, 2, 1, 2, 1, 2,
            3, 4, 4, 3, 4, 4, 3, 4, 4, 3, 4, 4,
        };
    }

    if (GC.getGameINLINE().isOption(GAMEOPTION_LARGER_CITIES))    
    {
        int aaiXYCityPlot[CITY_PLOTS_DIAMETER][CITY_PLOTS_DIAMETER] =
        {
    /*************************************************************************************************/
    /** JOOYO_ADDON, Added by Jooyo, 06/17/09                                                        */
    /**                                                                                              */
    /**                                                                                              */
    /*************************************************************************************************/
            {-1, -1, 32, 33, 34, -1, -1},
            {-1, 31, 17, 18, 19, 35, -1},
            {30, 16, 6,   7,  8, 20, 36},
            {29, 15, 5,   0,  1,  9, 21},
            {28, 14, 4,   3,  2, 10, 22},
            {-1, 27, 13, 12, 11, 23, -1},
            {-1, -1, 26, 25, 24, -1, -1},
    /*************************************************************************************************/
    /** JOOYO_ADDON                          END                                                     */
    /*************************************************************************************************/
        };
    }
    else
    {
        int aaiXYCityPlot[CITY_PLOTS_DIAMETER][CITY_PLOTS_DIAMETER] =
        {
            {-1, 17, 18, 19, -1,},

            {16, 6, 7, 8, 20,},

            {15, 5, 0, 1, 9,},

            {14, 4, 3, 2, 10,},

            {-1, 13, 12, 11, -1,}
        };
    }

Needless to say, I'm getting compiler errors, and I'm not sure what else to do...
Spoiler :
CvGlobals.cpp
CvGlobals.cpp(545) : error C2065: 'aiCityPlotX' : undeclared identifier
CvGlobals.cpp(545) : error C2070: ''unknown-type'': illegal sizeof operand
CvGlobals.cpp(545) : error C3861: 'aiCityPlotX': identifier not found, even with argument-dependent lookup
CvGlobals.cpp(546) : error C2065: 'aiCityPlotY' : undeclared identifier
CvGlobals.cpp(546) : error C2070: ''unknown-type'': illegal sizeof operand
CvGlobals.cpp(546) : error C3861: 'aiCityPlotY': identifier not found, even with argument-dependent lookup
CvGlobals.cpp(547) : error C2065: 'aiCityPlotPriority' : undeclared identifier
CvGlobals.cpp(547) : error C2070: ''unknown-type'': illegal sizeof operand
CvGlobals.cpp(547) : error C3861: 'aiCityPlotPriority': identifier not found, even with argument-dependent lookup
CvGlobals.cpp(550) : error C2065: 'aaiXYCityPlot' : undeclared identifier
 
You have to declare the variable outside the IF statement, then set it up inside the IF. If it only exists within the IF statement, it stops existing when you leave the IF statement. Well, to be honest I only know that this is true for a FOR loop, I am not quite accustomed to it happening in IF statements, but a sub-section is a subsection.

That or your issue is the global definitions which set the size of the arrays.
 
I've tried it the other way too. See?

Spoiler :

Code:
	int aiCityPlotX[NUM_CITY_PLOTS] =
	if (GC.getGameINLINE().isOption(GAMEOPTION_LARGER_CITIES))
	{
		0,
		0, 1, 1, 1, 0,-1,-1,-1,
		0, 1, 2, 2, 2, 1, 0,-1,-2,-2,-2,-1,
/*************************************************************************************************/
/** JOOYO_ADDON, Added by Jooyo, 06/17/09                                                        */
/**                                                                                              */
/**                                                                                              */
/*************************************************************************************************/
		0, 1, 2, 3, 3, 3, 2, 1, 0, -1, -2, -3, -3, -3, -2, -1,
/*************************************************************************************************/
/** JOOYO_ADDON                          END                                                     */
/*************************************************************************************************/
	}
	else
	{
		0,
		0, 1, 1, 1, 0,-1,-1,-1,
		0, 1, 2, 2, 2, 1, 0,-1,-2,-2,-2,-1,
	};

	int aiCityPlotY[NUM_CITY_PLOTS] =
	if (GC.getGameINLINE().isOption(GAMEOPTION_LARGER_CITIES))	
	{
		0,
		1, 1, 0,-1,-1,-1, 0, 1,
		2, 2, 1, 0,-1,-2,-2,-2,-1, 0, 1, 2,
/*************************************************************************************************/
/** JOOYO_ADDON, Added by Jooyo, 06/17/09                                                        */
/**                                                                                              */
/**                                                                                              */
/*************************************************************************************************/
		3, 3, 2, 1, 0, -1, -2, -3, -3, -3, -2, -1, 0, 1, 2, 3,
/*************************************************************************************************/
/** JOOYO_ADDON                          END                                                     */
/*************************************************************************************************/
	}
	else
	{
		0,
		1, 1, 0,-1,-1,-1, 0, 1,
		2, 2, 1, 0,-1,-2,-2,-2,-1, 0, 1, 2,
	};
	
	int aiCityPlotPriority[NUM_CITY_PLOTS] =
	if (GC.getGameINLINE().isOption(GAMEOPTION_LARGER_CITIES))	
	{
		0,
		1, 2, 1, 2, 1, 2, 1, 2,
		3, 4, 4, 3, 4, 4, 3, 4, 4, 3, 4, 4,
/*************************************************************************************************/
/** JOOYO_ADDON, Added by Jooyo, 06/17/09                                                        */
/**                                                                                              */
/**                                                                                              */
/*************************************************************************************************/
		5, 6, 7, 6, 5, 6, 7, 6, 5, 6, 7, 6, 5, 6, 7, 6,
/*************************************************************************************************/
/** JOOYO_ADDON                          END                                                     */
/*************************************************************************************************/
	}
	else
	{
		0,
		1, 2, 1, 2, 1, 2, 1, 2,
		3, 4, 4, 3, 4, 4, 3, 4, 4, 3, 4, 4,
	};
	
	int aaiXYCityPlot[CITY_PLOTS_DIAMETER][CITY_PLOTS_DIAMETER] =
	if (GC.getGameINLINE().isOption(GAMEOPTION_LARGER_CITIES))	
	{

/*************************************************************************************************/
/** JOOYO_ADDON, Added by Jooyo, 06/17/09                                                        */
/**                                                                                              */
/**                                                                                              */
/*************************************************************************************************/
		{-1, -1, 32, 33, 34, -1, -1},
		{-1, 31, 17, 18, 19, 35, -1},
		{30, 16, 6,   7,  8, 20, 36},
		{29, 15, 5,   0,  1,  9, 21},
		{28, 14, 4,   3,  2, 10, 22},
		{-1, 27, 13, 12, 11, 23, -1},
		{-1, -1, 26, 25, 24, -1, -1},
	/*************************************************************************************************/
	/** JOOYO_ADDON                          END                                                     */
	/*************************************************************************************************/
	}
	else
	{
		{-1, 17, 18, 19, -1,},

		{16, 6, 7, 8, 20,},

		{15, 5, 0, 1, 9,},

		{14, 4, 3, 2, 10,},

		{-1, 13, 12, 11, -1,}
	};


I get these errors:
Spoiler :

CvGlobals.cpp(372) : error C2059: syntax error : 'if'
CvGlobals.cpp(373) : error C2143: syntax error : missing ';' before '{'
CvGlobals.cpp(386) : error C2059: syntax error : '}'
CvGlobals.cpp(387) : error C2181: illegal else without matching if
CvGlobals.cpp(392) : error C2059: syntax error : '}'
CvGlobals.cpp(395) : error C2059: syntax error : 'if'
CvGlobals.cpp(396) : error C2143: syntax error : missing ';' before '{'
CvGlobals.cpp(409) : error C2059: syntax error : '}'
CvGlobals.cpp(410) : error C2181: illegal else without matching if
CvGlobals.cpp(415) : error C2059: syntax error : '}'
CvGlobals.cpp(418) : error C2059: syntax error : 'if'
CvGlobals.cpp(419) : error C2143: syntax error : missing ';' before '{'
CvGlobals.cpp(432) : error C2059: syntax error : '}'
CvGlobals.cpp(433) : error C2181: illegal else without matching if
CvGlobals.cpp(438) : error C2059: syntax error : '}'
CvGlobals.cpp(441) : error C2059: syntax error : 'if'
CvGlobals.cpp(442) : error C2143: syntax error : missing ';' before '{'
CvGlobals.cpp(449) : error C2143: syntax error : missing ';' before '}'
CvGlobals.cpp(449) : error C2143: syntax error : missing ';' before ','
CvGlobals.cpp(450) : error C2143: syntax error : missing ';' before '{'
CvGlobals.cpp(450) : error C2143: syntax error : missing ';' before '}'
CvGlobals.cpp(450) : error C2143: syntax error : missing ';' before ','
CvGlobals.cpp(451) : error C2143: syntax error : missing ';' before '{'
CvGlobals.cpp(451) : error C2143: syntax error : missing ';' before '}'
CvGlobals.cpp(451) : error C2143: syntax error : missing ';' before ','
CvGlobals.cpp(452) : error C2143: syntax error : missing ';' before '{'
CvGlobals.cpp(452) : error C2143: syntax error : missing ';' before '}'
CvGlobals.cpp(452) : error C2143: syntax error : missing ';' before ','
CvGlobals.cpp(453) : error C2143: syntax error : missing ';' before '{'
CvGlobals.cpp(453) : error C2143: syntax error : missing ';' before '}'
CvGlobals.cpp(453) : error C2143: syntax error : missing ';' before ','
CvGlobals.cpp(454) : error C2143: syntax error : missing ';' before '{'
CvGlobals.cpp(454) : error C2143: syntax error : missing ';' before '}'
CvGlobals.cpp(454) : error C2143: syntax error : missing ';' before ','
CvGlobals.cpp(455) : error C2143: syntax error : missing ';' before '{'
CvGlobals.cpp(455) : error C2143: syntax error : missing ';' before '}'
CvGlobals.cpp(455) : error C2143: syntax error : missing ';' before ','
CvGlobals.cpp(460) : error C2181: illegal else without matching if
CvGlobals.cpp(462) : error C2059: syntax error : '}'
CvGlobals.cpp(462) : error C2143: syntax error : missing ';' before ','
CvGlobals.cpp(464) : error C2143: syntax error : missing ';' before '{'
CvGlobals.cpp(464) : error C2059: syntax error : '}'
CvGlobals.cpp(464) : error C2143: syntax error : missing ';' before ','
CvGlobals.cpp(466) : error C2143: syntax error : missing ';' before '{'
CvGlobals.cpp(466) : error C2059: syntax error : '}'
CvGlobals.cpp(466) : error C2143: syntax error : missing ';' before ','
CvGlobals.cpp(468) : error C2143: syntax error : missing ';' before '{'
CvGlobals.cpp(468) : error C2059: syntax error : '}'
CvGlobals.cpp(468) : error C2143: syntax error : missing ';' before ','
CvGlobals.cpp(470) : error C2143: syntax error : missing ';' before '{'
 
You can't have an if after an = like that. I meant more like:

Spoiler :

Code:
    int aiCityPlotX[NUM_CITY_PLOTS];
    if (GC.getGameINLINE().isOption(GAMEOPTION_LARGER_CITIES))
{
    aiCityPlotX[NUM_CITY_PLOTS] = 
    {
        0,
        0, 1, 1, 1, 0,-1,-1,-1,
        0, 1, 2, 2, 2, 1, 0,-1,-2,-2,-2,-1,
/*************************************************************************************************/
/** JOOYO_ADDON, Added by Jooyo, 06/17/09                                                        */
/**                                                                                              */
/**                                                                                              */
/*************************************************************************************************/
        0, 1, 2, 3, 3, 3, 2, 1, 0, -1, -2, -3, -3, -3, -2, -1,
/*************************************************************************************************/
/** JOOYO_ADDON                          END                                                     */
/*************************************************************************************************/
    }
}
    else
{
    aiCityPlotX[NUM_CITY_PLOTS] = 
     {
        0,
        0, 1, 1, 1, 0,-1,-1,-1,
        0, 1, 2, 2, 2, 1, 0,-1,-2,-2,-2,-1,
    };
}

for example.

But thinking about it more, your biggest issue is that NUM_CITY_PLOTS needs to have a different value if this gameoption is selected than it does if this gameoption is not selected.
 
Hmm. I understand what you did, (And can't believe I forgot that), but I still am getting lots of syntax errors...
 
I don't deal with the initializing of variables, let alone arrays, too terribly often, so there are numerous syntax issues which I can't really prepare you for better than a random tutorial found with a net search. It could be you need to use an "int* variable = new int[size]" type of declaration instead of just "int variable[size]" like is here presently.
 
Code:
    int aiCityPlotX[NUM_CITY_PLOTS];
    if (GC.getGameINLINE().isOption(GAMEOPTION_LARGER_CITIES))
{
    aiCityPlotX[NUM_CITY_PLOTS] = 
    {
        0,
 etc...

This has a lot of problems.

One problem is that aiCityPlotX[NUM_CITY_PLOTS] is trying to reference a specific element in the array via the index value of NUM_CITY_PLOTS. This is not an array of arrays, each element is an int. (A second, essentially irrelevant, problem is that the element is actually one past the end of the array, which has NUM_CITY_PLOTS elements numbered from 0 to NUM_CITY_PLOTS -1.)

In C++ there is no built-in syntax for assigning a set of values to an array all at once, like "foo[] = {1,2,3}", except in the initial declaration where you do an initialization.

One solution is just a long list of assignments in each of the two branches of the if statment (this is pretty much the classic way to do it):
Code:
aiCityPlotX[0] = 0;
aiCityPlotX[1] = 0;
aiCityPlotX[2] = 1;
etc...

My suggestion is to use a pointer and two arrays initialized to the two sets of values. Then use the setting to decide which array to point the pointer at. This is probably relatively easy to do. There may be some confusion involved in various points in the code, but I like this method. Something like:
Code:
        int big_aiCityPlotX[NUM_CITY_PLOTS_BIG] =
        {
            0,
            0, 1, 1, 1, 0,-1,-1,-1,
            0, 1, 2, 2, 2, 1, 0,-1,-2,-2,-2,-1,
    /*************************************************************************************************/
    /** JOOYO_ADDON, Added by Jooyo, 06/17/09                                                        */
    /**                                                                                              */
    /**                                                                                              */
    /*************************************************************************************************/
            0, 1, 2, 3, 3, 3, 2, 1, 0, -1, -2, -3, -3, -3, -2, -1,
    /*************************************************************************************************/
    /** JOOYO_ADDON                          END                                                     */
    /*************************************************************************************************/
        };
        int normal_aiCityPlotX[NUM_CITY_PLOTS_NORMAL] =
        {
            0,
            0, 1, 1, 1, 0,-1,-1,-1,
            0, 1, 2, 2, 2, 1, 0,-1,-2,-2,-2,-1,
        };
        int *aiCityPlotX;

        if (GC.getGameINLINE().isOption(GAMEOPTION_LARGER_CITIES)) {
          NUM_CITY_PLOTS = NUM_CITY_PLOTS_BIG;
          aiCityPlotX = big_aiCityPlotX;
        }
        else {
          NUM_CITY_PLOTS = NUM_CITY_PLOTS_NORMAL;
          aiCityPlotX = normal_aiCityPlotX;
        }
Or something more or less along those lines, for each of the arrays. (You can put all assignmens for the other pointers into the same if/else, picking between two CITY_PLOTS_DIAMETER_x values as well.)
 
I may be a bit rusty on this, but I don't think you can use the { ... } syntax on an array that's already been initialised.
 
You're definitely going to have issues with NUM_CITY_PLOTS and CITY_PLOTS_DIAMETER being constants. If you define BIG and NORMAL constants, you still need to choose between the two. If you turn them into variables, you'll add a slight performance penalty to their use.

One solution is to use the larger of the two values for each and make sure the code can handle this. For the normal aaiXYCityPlot array, just add a square of -1s around the current values. For the normal aiCityPlotX/Y arrays, hopefully you can add MIN_INTs onto the end and modify existing code to skip them. The aiCityPlotPriority array could get -1s added to it, again with code changes to skip them.

Start by finding all places where those constants are used. If that number is small, it shouldn't be too bad. If not, you'll have your work cut out for you. If you're lucky, most code goes through the CvCity functions to iterate over a city's plots.
 
One solution is to use the larger of the two values for each and make sure the code can handle this. For the normal aaiXYCityPlot array, just add a square of -1s around the current values. For the normal aiCityPlotX/Y arrays, hopefully you can add MIN_INTs onto the end and modify existing code to skip them. The aiCityPlotPriority array could get -1s added to it, again with code changes to skip them.

Dang. Well, I don't think you all quite understand. Jooyo already has larger cities radius working, but the implementation is leaves something to be desired, so I wanted to make larger cities a game option.

I'm just going to give up and strip it out. Larger cities unbalance the game too much anyways.
 
No, we do understand, but the issue is that there is a very fundamental change made by increasing this radius.

This constant NUM_CITY_PLOTS is changed, and that constant is used by many AI processes and other functions, plus it defines precisely how big these arrays are going to be. You absolutely MUST have 24 numbers in this array if NUM_CITY_PLOTS = 24, and you absolutely MUST have 36 numbers if NUM_CITY_PLOTS = 36. So the gameoption has to also change this constant value globally. It is one issue which I hadn't recalled until just recently which Fall from Heaven still hasn't completely sorted out, though it has made quite a bit of progress and might be worth looking at. Basically you have to ask CvCity if it works 2 plots or 3, and then calculate based on the appropriate number, isntead of jumping to NUM_CITY_PLOTS instantly (otherwise the AI will place a city thinking that working the third ring makes it a nice city, when with just 2 rings it is a HORRIBLE city, because every AI thinks every city can ALWAYS work the third ring)

Some things are hard to make into options, even if they are easy to do individually.
 
I assure you, the misunderstanding lies not with us. ;) In C++ things defined using #define are called compile-time constants because the compiler replaces all occurrences with the actual value. When you write this

Code:
#define NUM_CITY_PLOTS    21

...

for (int iI = 0; iI < NUM_CITY_PLOTS; iI++)
{
    ...
}

the compiler turns it into this

Code:
for (int iI = 0; iI < 21; iI++)
{
    ...
}

NUM_CITY_PLOTS is not a variable; you cannot change its value because it doesn't exist in the compiled code. Game options affect the game at runtime--after compilation. There's no way to go through the code at runtime and change all those 21s to 33s to add a 3rd ring.

The easiest option is to turn those constants into variables. There would be a mild performance penalty, but you'd have to do some testing to get a feel for it. The more complicated option I tried to explain is to make the game always use a 3rd ring, but use the game option to make the 3rd ring full of ignored tiles when the option is off.
 
[/code]NUM_CITY_PLOTS is not a variable; you cannot change its value because it doesn't exist in the compiled code. Game options affect the game at runtime--after compilation. There's no way to go through the code at runtime and change all those 21s to 33s to add a 3rd ring.

The easiest option is to turn those constants into variables. There would be a mild performance penalty, but you'd have to do some testing to get a feel for it. The more complicated option I tried to explain is to make the game always use a 3rd ring, but use the game option to make the 3rd ring full of ignored tiles when the option is off.

Maybe I should have told you, but NUM_CITY_PLOTS has already been changed to 33. I suppose that's why it's been giving errors, as it expected 33 and only got 21...

Before I begin tearing the code out, or messing with constants and variables, maybe I could just solve the root problem. The only reason I don't like the larger cities sizes (aside from the unbalanced gameplay) is that it causes resources, when maps are generated, to be placed farther away then normal. This is not problematic, except with oceans, where resources are now being constantly placed out of reach of cities, and can not be reached until after Astronomy is researched. Is there any way to avoid the map generator problems?
 
Maybe I should have told you, but NUM_CITY_PLOTS has already been changed to 33. I suppose that's why it's been giving errors, as it expected 33 and only got 21...

Yes, if you declare an array to have 33 elements, it must have 33 elements.

Is there any way to avoid the map generator problems?

Somewhere in the map generation code must be a function that places resources. You could search it for the part that uses the city radius and limit it to 2 max.
 
Somewhere in the map generation code must be a function that places resources. You could search it for the part that uses the city radius and limit it to 2 max.

Hmm. I can't seem to find anywhere where cvmapgenerator calls the city radius, plots, or anything of the like.
 
Have you found where it places the bonuses?

I think the two important functions are "void CvMapGenerator::addNonUniqueBonusType(BonusTypes eBonusType)" and 'void CvMapGenerator::addUniqueBonusType(BonusTypes eBonusType)"
 
The first function calls CvPlot::canHaveBonus() which checks if the plot is within a city radius as the last step of the function:

Code:
if (!isPotentialCityWork())
{
	return false;
}

CvPlot::isPotentialCityWork() returns m_bPotentialCityWork which gets updated in CvPlot::updatePotentialCityWork() by looping over all nearby plots using NUM_CITY_PLOTS and CvPlot::plotCity() which calls CvGlobals::getCityPlotX() and CvGlobals::getCityPlotY() which use the arrays you are modifying.

Try this:

1. Define a new constant NUM_WATER_CITY_PLOTS.

Code:
#define NUM_WATER_CITY_PLOTS     21

2. Make sure you have the city center and first two rings in the X and Y arrays, which I think you do.

Code:
int aiCityPlotX[NUM_CITY_PLOTS] = {
    0,  // center
    1, 1, 0, -1, -1, -1, 0, 1,  // first ring
    2, 2, 1, ...,  // second ring
    3, 3, ...  // third ring
};

3. Use this new constant as the loop range to check in CvPlot::updatePotentialCityWork().

Code:
void CvPlot::updatePotentialCityWork()
{
	...
	for (iI = 0; iI < [B]NUM_WATER_CITY_PLOTS[/B]; ++iI)
	...
}

Hopefully it's this easy. :)
 
The first function calls CvPlot::canHaveBonus() which checks if the plot is within a city radius as the last step of the function:

Code:
if (!isPotentialCityWork())
{
    return false;
}
CvPlot::isPotentialCityWork() returns m_bPotentialCityWork which gets updated in CvPlot::updatePotentialCityWork() by looping over all nearby plots using NUM_CITY_PLOTS and CvPlot::plotCity() which calls CvGlobals::getCityPlotX() and CvGlobals::getCityPlotY() which use the arrays you are modifying.

Try this:

1. Define a new constant NUM_WATER_CITY_PLOTS.

Code:
#define NUM_WATER_CITY_PLOTS     21
2. Make sure you have the city center and first two rings in the X and Y arrays, which I think you do.

Code:
int aiCityPlotX[NUM_CITY_PLOTS] = {
    0,  // center
    1, 1, 0, -1, -1, -1, 0, 1,  // first ring
    2, 2, 1, ...,  // second ring
    3, 3, ...  // third ring
};
3. Use this new constant as the loop range to check in CvPlot::updatePotentialCityWork().

Code:
void CvPlot::updatePotentialCityWork()
{
    ...
    for (iI = 0; iI < [B]NUM_WATER_CITY_PLOTS[/B]; ++iI)
    ...
}
Hopefully it's this easy. :)

Actually, there is already a define that Jooyo added called "#define NUM_CITY_PLOTS_2 (21)", So I'll just use that. I hope it works.
 
Top Bottom