[SDK] Founding Cities on the Water

Afforess

The White Wizard
Joined
Jul 31, 2007
Messages
12,239
Location
Austin, Texas
I was bored, and looking in the SDK to see where exactly I would need to change it to found cities on water. Well, apparently, Firaxis beat me to it. However, I'm not sure about the way they implemented it, and if it is ever used.

Here's the code I discovered:

Code:
bool CvPlayer::canFound(int iX, int iY, bool bTestVisible) const
{...

    if(GC.getUSE_CAN_FOUND_CITIES_ON_WATER_CALLBACK())
    {
        CyArgsList argsList2;
        argsList2.add(iX);
        argsList2.add(iY);
        lResult=0;
        gDLL->getPythonIFace()->callFunction(PYGameModule, "canFoundCitiesOnWater", argsList2.makeFunctionArgs(), &lResult);
    }

    if (lResult == 1)
    {
        bValid = true;
    }
    else
    {
        if (pPlot->isWater())
        {
            return false;
        }
    }
...
}

So, is it referencing a python callback? Are there any mods that use this?
 
Yes, there's a python callback in CvGameUtils.py (canFoundCitiesOnWater), and it has to be activated in the PythonCallbackDefines.xml.

I guess, that DuneWars uses this ability, and i'll use it in the next version of my mod (if i don't get any problem with it).
 
Yes, there's a python callback in CvGameUtils.py (canFoundCitiesOnWater), and it has to be activated in the PythonCallbackDefines.xml.

I guess, that DuneWars uses this ability, and i'll use it in the next version of my mod (if i don't get any problem with it).

What exactly does it do? Literally founding a city on water? And how would I achieve this, by making a special settler ship?
 
No idea :D.
I guess, it just "activates" the build city button on water squares, so that you also could build a city with a settler in a transporter.

Hmm, really? That's strange. I would rather there was a "settler-ship."

Also, since it's a callback, will it decrease turn times much? Cybah's got me completely paranoid about python callbacks.
 
One way to address the performance hit (yes there will be one but it should be minor) is to call the callback only if the plot is water! How ridiculous that it asks if you can found on water only to find the plot is land. In fact, looking at the full function, if you use that callback there is a major bug. If your callback returns true--it's okay to found on water--you can found on all sorts of invalid plots. :(

This should fix both the bug and the unnecessary performance penalty.

Code:
	if (!bValid)
	{
		if (pPlot->isWater())
		{
			if(GC.getUSE_CAN_FOUND_CITIES_ON_WATER_CALLBACK())
			{
				CyArgsList argsList2;
				argsList2.add(iX);
				argsList2.add(iY);
				lResult=0;
				gDLL->getPythonIFace()->callFunction(PYGameModule, "canFoundCitiesOnWater", argsList2.makeFunctionArgs(), &lResult);
			}

			if (lResult == 1)
			{
				bValid = true;
			}
		}
	}

There is at least one other place you'd need to make changes. In the code that tests for valid places to put resources, I think it checks if the plot is land as opposed to a possible city site (I forget). It's the function I mentioned in the city radius thread.
 
You should submit that to the UP fix page. This function is in vanilla BTS, so that would qualify...
 
Top Bottom