Kick Naval Unit Out of City

OrionVeteran

Deity
Joined
Dec 25, 2003
Messages
2,443
Location
Newport News VA
I'm trying to kick a naval unit out of a city to a qualified water plot, using SDK. The following code successfully gets to the execution line "setXY", but fails to move the unit! :crazyeye: This is my attempt to covert a python function to SDK.

I have tried for hours trying to get this line work, but have failed. Any ideas on how to get the "setXY" line to work? The line is highlighted in Red.

Spoiler :

Code:
void CvUnit::kickNavalUnitOutOfCity()
{
	// Force Naval Unit out of City to an adjacent water plot
	// Note:  Unit must be on a water plot for the calculatePathDistance command to work
	// Assumes the unit owner is an AI Player 
	CvCity* pUnitCity;
	CvPlot* pCityPlot;
	CvPlot* AdjacentPlotToCity;
	CvPlot* pDeployPlot;
	PlayerTypes eOwner;
	CvWString szBufferB;
	int iI;
	bool FoundAdjacentPlot = false;
	pCityPlot = plot();
	pUnitCity = pCityPlot->getPlotCity();
	eOwner = getOwnerINLINE();
	UnitCombatTypes eMineWarfareUnits = (UnitCombatTypes)GC.getInfoTypeForString("UNITCOMBAT_MINE_WARFARE");
	
	for (iI = 0; iI < NUM_DIRECTION_TYPES; iI++)
	{
		AdjacentPlotToCity = plotDirection(pCityPlot->getX_INLINE(), pCityPlot->getY_INLINE(), ((DirectionTypes)iI));
		
		if (AdjacentPlotToCity != NULL)
		{
			// Make sure this is a water plot
			if (AdjacentPlotToCity->isWater())
			{
				// Make Sure the plot is not a fresh water lake
				if (!AdjacentPlotToCity->isLake())
				{
					// Make sure plot is not impassable
					//if (!AdjacentPlotToCity->isImpassable())
					if (canMoveInto(AdjacentPlotToCity))
					{
						// LoopPlot must be unowned or owned by the AI Player
						if ((!AdjacentPlotToCity->isOwned()) || (AdjacentPlotToCity->getOwner() == eOwner))
						{
							{
								//pDeployPlot = AdjacentPlotToCity;
								pDeployPlot = AdjacentPlotToCity;
								FoundAdjacentPlot = true;
								break;
							}
						}
					}
				}
			}
		}
	}
	
	if (FoundAdjacentPlot)
	{
		[COLOR="Red"][B]setXY(pDeployPlot->getX_INLINE(), pDeployPlot->getY_INLINE(), false, true, false);[/B][/COLOR]		setMoves(getMoves() -1);
	}
	else if (getUnitCombatType() == eMineWarfareUnits)
	{
		doMineRedeployment(true);
	}
}
 
The fix for this issue was to move the execution line from one function and put it in another. Both of these functions ran before. So, I can't explain why the code suddenly worked after moving the execution line to another python function. :confused:

The good news is that this SDK function, with a minor change to verify the plot is in fact a city, now kicks the mines out of the city, as it is intended to do. :whew:

I can see the light at the end of the tunnel for the SDK version of Mine Warfare. I am now working on a function to improve the distribution of Naval mines, so that one coastal city does not get surrounded by a bunch of mines, while the other coastal cities have none.
 
Back
Top Bottom