Airdrop mission

Chazcon

Prince
Joined
Feb 16, 2006
Messages
476
Location
Left Coast
Well the more I delve into C++ the more I realize I DON'T know...but I'm learning, albeit slowly.

I've added this Airdrop mission, that allows an Air Transport to load and drop a Paratroop unit. I've got it working, but I'm missing a few things and after spending countless hours trying to figure out the SDK code I'm stuck. Admittedly I'm learning C++ as I go too, not the reccomended method I'm sure but there you go.

What this needs to do, in order to be complete, is:

1) Fly the recon mission animation BEFORE the unit is dropped.
2) Reset the unit's formation after it's dropped, rather than using the default 'ring' formation.
3) Do a 'declare war' check & popup option screen after you select the plot, but before actually dropping the unit.
4) Check all units loaded on the air transport to ensure at least one of them has the SPECIALUNIT_AIRBORNE special unit type.
5) Drop all units loaded on the air transport with the above special unit type.

You can see my comments on where I'm stuck. Any guidance at all would be most helpful!

Code:
// Chazcon Airdrop -start-

 bool CvUnit::canAirdrop(const CvPlot* pPlot) const
{

	//CvUnit* pLoopUnit;
	//CLLNode<IDInfo>* pUnitNode;
	
	if (getDomainType() != DOMAIN_AIR)
	{
		return false;
	}

    // check to see if the air transport has cargo
	if (!hasCargo())
    {
        return false;
    }

    // ensure there is at least one cargo unit that is SPECIALUNIT_AIRBORNE or _COVERT
	/*while (pUnitNode != NULL)
	{
		pLoopUnit = ::getUnit(pUnitNode->m_data);
		pUnitNode = pPlot->nextUnitNode(pUnitNode);

		if (pLoopUnit->getTransportUnit() == this)
		{
			if ((getSpecialUnitType() == SPECIALUNIT_AIRBORNE))
			{
				return true;
				break;
			}

		}

	}*/

	if (isMadeAttack())
	{
		return false;
	}

	return true;
}


bool CvUnit::canAirdropAt(const CvPlot* pPlot, int iX, int iY) const
{
	CvPlot* pTargetPlot;
	CvUnit* pLoopUnit;
	CLLNode<IDInfo>* pUnitNode;

	if (!canAirdrop(pPlot))
	{
		return false;
	}

	pTargetPlot = GC.getMapINLINE().plotINLINE(iX, iY);

	if (plotDistance(pPlot->getX_INLINE(), pPlot->getY_INLINE(), pTargetPlot->getX_INLINE(), pTargetPlot->getY_INLINE()) > airRange())
	{
		return false;
	}

    // ensure the target plot does not contain an enemy unit
	if (pPlot->getNumVisibleEnemyDefenders(getOwnerINLINE()) > 0)
	{
       return false;
	}

    // ensure the target plot is a valid plot that the cargo unit can normally enter
	pPlot = plot();

	pUnitNode = pPlot->headUnitNode();

	while (pUnitNode != NULL)
	{
		pLoopUnit = ::getUnit(pUnitNode->m_data);
		pUnitNode = pPlot->nextUnitNode(pUnitNode);

		if (pLoopUnit->getTransportUnit() == this)
		{
			if (!(pLoopUnit->canMoveOrAttackInto(pTargetPlot, true)))
			{
				return false;
			}
		}
	}

	return true;
}


bool CvUnit::airdrop(int iX, int iY)
{
	CvPlot* pPlot;
	CvPlot* pStartPlot;
	CvPlot* pTargetPlot;

	if (!canAirdropAt(plot(), iX, iY))
	{
		return false;
	}

	pPlot = GC.getMapINLINE().plotINLINE(iX, iY);

	if (interceptTest(pPlot))
	{
		return true;
	}

	// the beef
	pStartPlot = plot();

	pTargetPlot = GC.getMapINLINE().plotINLINE(iX, iY);

	setXY(pTargetPlot->getX_INLINE(), pTargetPlot->getY_INLINE());

	unloadAll();

        // drop all SPECIALUNIT_AIRBORNE units

	// check for declare war here?

	// why is cargo unit using default (ring) formation?

	// how to run recon animation BEFORE unit drops?

	setXY(pStartPlot->getX_INLINE(), pStartPlot->getY_INLINE());

	finishMoves();

	if (pPlot->isActiveVisible(false))
	{
		CvAirMissionDefinition kAirMission;
		kAirMission.eMissionType = MISSION_RECON;
		kAirMission.pkUnits[BDU_ATTACKER] = this;
		kAirMission.pkUnits[BDU_DEFENDER] = NULL;
		kAirMission.iDamage[BDU_DEFENDER] = 0;
		kAirMission.iDamage[BDU_ATTACKER] = 0;
		kAirMission.pkPlot = pPlot;
		kAirMission.fMissionTime = (GC.getMissionInfo((MissionTypes)MISSION_RECON).getTime() * gDLL->getSecsPerTurn());
		gDLL->getEntityIFace()->AddMission(kAirMission);
	}

	return true;
}
// Chazcon Airdrop -end-
 
If you could provide the code as a modcomp i could help you with paratrooper unit model ;)
 
Back
Top Bottom