New cob get/set: SEEK_LANDING_PAD ( A thread for scriptors )

New cob get/set: SEEK_LANDING_PAD ( A thread for scriptors )

Discuss the source code and development of Spring Engine in general from a technical point of view. Patches go here too.

Moderator: Moderators

Post Reply
Archangel of Death
Posts: 854
Joined: 28 Jan 2005, 18:15

New cob get/set: SEEK_LANDING_PAD ( A thread for scriptors )

Post by Archangel of Death »

So basically I had this crazy ideas to be able to make planes decide to land on an airbase from the script. Well, I looked into. Just had to find what function triggered all that! Well, after while searching, some headaches, and a bit of random luck, I managed to track it down, inbedded in AirMoveType->SlowUpdate.

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). :wink:

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
}
So, most importantly, will that work? (Before I submit it, I'm almost as loath to try to get Dev-C++ [what I have, or anything else for that matter] to compile the spring source as I am to go into the gui code again). Second most important, as a scriptor, what changes would you like to see? I can return the id of the pad it has chosen with the get, but those aren't unit id's, so would it have any use? Etc, etc. Discuss!
User avatar
bobthedinosaur
Blood & Steel Developer
Posts: 2702
Joined: 25 Aug 2004, 13:31

Post by bobthedinosaur »

if i understood that... it sounds good to me
Fnordia
Former Engine Dev
Posts: 425
Joined: 13 Aug 2004, 16:11

Post by Fnordia »

Except that the code wont work since it doesnt take any consideration of taairmovetype being able to fly.
Archangel of Death
Posts: 854
Joined: 28 Jan 2005, 18:15

Post by Archangel of Death »

Hmm? What what? Perhaps I should not have assumed that the only way things can fall into the a flying unit category is if they have canfly in their fbi?
I'll look into it, and see if maybe I can figure out what your getting at :P
Archangel of Death
Posts: 854
Joined: 28 Jan 2005, 18:15

Post by Archangel of Death »

Haha! Ok, thats what I get for doing that when I should be sleeping, I didn't even notice that one. I'll have to seek out a direct way to figure out which of the MoveTypes a unit is using. What fun...
Post Reply

Return to “Engine”