Detecting when a unit enters a plot.

OrionVeteran

Deity
Joined
Dec 25, 2003
Messages
2,443
Location
Newport News VA
I want to detect the movement of one or more units into a plot via SDK. In CvPlayer.cpp there is a function called:

void CvPlayer::doTurn()

In this function I believe I need the following:

Code:
	// OrionVeteran - Mine Warfare START
	CvUnit* pLoopUnit;
	if (GC.getGameINLINE().isOption(GAMEOPTION_MINE_WARFARE))
	{
		for (pLoopUnit = firstUnit(&iLoop); pLoopUnit != NULL; pLoopUnit = nextUnit(&iLoop))
		{
			pLoopUnit->doMineDetonation();
		}
	}
	// OrionVeteran - Mine Warfare END

My hope is that this checks to insure the game option for Mine Warfare is turned on and when a unit moves into a plot it triggers the doMineDetonation function, which would determine, whether or not to detonate a Mine, if one exists on the plot. Is my logic correct?
 
This will check at the beginning of each player's turn. If you want the mine to detonate when the unit enters the plot, I would suggest using CvSelectionGroup::groupAttack(), which is called each time a unit moves, even if it's not attacking.
 
I can write python with ease, but I'm pitiful with SDK development. I have a python function that determines if a plot has an enemy mine and need to covert it to a separate SDK function:

Code:
def hasEnemyMine(pPlot, iPlayer):
	# Orion's Minewarefare Mod
	EnemyMine = False
	iMineWarfareUnits = gc.getInfoTypeForString("UNITCOMBAT_MINE_WARFARE")
	
	for iUnitLoop in range (pPlot.getNumUnits()):
		xUnit = pPlot.getUnit(iUnitLoop)
		xUnitType = xUnit.getUnitType()
		# Is this a mine?
		if xUnit.getUnitCombatType() == iMineWarfareUnits:
			# Get the Owner of the Mine
			xUnitOwner = xUnit.getOwner()
			# Is this an enemy mine?
			if xUnitOwner != iPlayer:
				#CyInterface().addImmediateMessage("Found Enemy Mine", "")
				EnemyMine = True
				break
	
	return EnemyMine

This needs to be a determining factor to run a detonation function. Any help with the conversion would be most helpful.
 
Take a stab at making the function yourself and then let us know what's not working. If you can do python, then learning C should not be a big leap for you.
 
Take a stab at making the function yourself and then let us know what's not working. If you can do python, then learning C should not be a big leap for you.

...you mean C++, right? ;)

@OrionVeteran
You probably want something like this:

Code:
bool CvPlot::hasEnemyMine(PlayerTypes ePlayer)
{
	UnitCombatTypes eMineWarfareUnits = GC.getInfoTypeForString("UNITCOMBAT_MINE_WARFARE");
	CLLNode<IDInfo>* pUnitNode = headUnitNode();
	CvUnit* pLoopUnit;
	
	while (pUnitNode != NULL)
	{
		pLoopUnit = ::getUnit(pUnitNode->m_data);
		pUnitNode = nextUnitNode(pUnitNode);
		
		if (pLoopUnit->getUnitCombatType() == eMineWarfareUnits)
		{
			if (pLoopUnit->getOwner() != ePlayer)
			{
				return true;
			}
		}
	}
	return false;
}

Because the function is a member of CvPlot, you would call this function on what would have been pPlot in your python example.
 
No problem. :)

Anyway, I actually gave you partially unworking code. In the first line inside the while loop, I had mData instead of m_data. I changed that, so it should work fine now.
 
Back
Top Bottom