Anyway, currently I have it set up so that get SEEK_LANDING_PAD returns 1 or 0. 1 if the unit is seeking to land on (and already has reserved) or is landed on a landing pad. 0 if it isn't, or isn't an air unit (as trying to run these functions on something that doens't have AirUnitType would be bad, very bad unless... but I'll get back to that). set SEEK_LANDING_PAD just tells the unit to find an available landing pad, doesn't take any arguments currently (I have this feeling scriptor might require them for some reason, throwing in a number to make it happy wouldn't do anything).
How it is now, you can keep tabs on if a unit has a landing pad reserved, which means it either is on its way or landed on it. It would be important to keep track of this for as long as you are expecting your unit to land. You can also tell a unit to land whenever you want (like for me, telling some aerotech that fired all its lrm's to go land for reloading), but if no pads are available at the time you tell it to find a pad, it won't keep trying to find one on its own. Thus it is important to monitor it with the get SEEK_LANDING_PAD and retry making it land if necessary. If the unit is hurt, the game won't let it take off until it is fully repaired (because that is what repair pads do, and I'm unsure I'd want to try to abstract that out as well, it could easily break stuff). You can get and set unit health already, so you can watch that while your unit is landed (or skip repair time and just insta boost it up to 100%). Also, you can use the fact that the engine sends a deactivate command when an aircraft starts to land combined with get SEEK_LANDING_PAD returning a 1 to tell when the unit has actually begun landing on the pad (meh, but what if it gets blown up before it finishes landing? oh dear...).
And now, I'm posting the code changes for discussion. Why? Because 1. I want some input before I submit it and 2. I need someone who actually knows C++ syntax to tell me if I didn't do anything impossible/stupid (I have Java and C experience, but its been a while; and very small C++ experience, but its been AEONS).

Code: Select all
Changes to AirMoveType.ccp:
(changed)
void CAirMoveType::SlowUpdate(void)
{
...
if(!reservedPad && aircraftState==AIRCRAFT_FLYING && owner->health<owner->maxHealth*repairBelowHealth){
FindLandingPad();
/* Moved to new function: FindLandingPad
CAirBaseHandler::LandingPad* lp=airBaseHandler->FindAirBase(owner,8000,owner->unitDef->minAirBasePower);
if(lp){
AddDeathDependence(lp);
reservedPad=lp;
padStatus=0;
oldGoalPos=goalPos; */
}
}
...
}
(added)
void CAirMoveType::FindLandingPad(void)
{
CAirBaseHandler::LandingPad* lp=airBaseHandler->FindAirBase(owner,8000,owner->unitDef->minAirBasePower);
if(lp){
AddDeathDependence(lp);
reservedPad=lp;
padStatus=0;
oldGoalPos=goalPos;
}
}
Changes to AirMoveType.h
(added to public)
void FindLandingPad(void);
Code: Select all
Changes to Cobinstance.ccp
(added)
#define SEEK_LANDING_PAD 75 // set or get (get returns 1 or 0, yes or no. set makes the unit seek a landing pad)
(changed)
int CCobInstance::GetUnitVal(int val, int p1, int p2, int p3, int p4)
{
#ifndef _CONSOLE
switch(val)
{
...
case SEEK_LANDING_PAD:
if (unitDef->canfly!=1) // Don't let non flying units call this. Unless ability to seek a pad gets moved into movetype.
return 0;
else if (CAirMoveType->reservedPad > 0) // If we have a pad reserved, we just say yes.
return 1;
else
return 0; // Otherwise the unit obviously does not have/is not going to a pad.
break;
}
#endif
return 0;
}
(changed)
void CCobInstance::SetUnitVal(int val, int param)
{
#ifndef _CONSOLE
switch(val)
{
...
case SEEK_LANDING_PAD:
if (CAirMoveType->reservedPad == 0){ // Only try to find a landing pad if we don't alreayd have one.
CAirMoveType->FindLandingPad();
}
break;
}
#endif
}