Horizontal takeoff

Horizontal takeoff

Requests for features in the spring code.

Moderator: Moderators

User avatar
Pressure Line
Posts: 2283
Joined: 21 May 2007, 02:09

Horizontal takeoff

Post by Pressure Line »

ok, heres the deal, im sick of my planes using the TA takeoff behavior. can we get a 'htol' tag?

if the unit has the tag = 1 it would begin its forward acceleration immediately, smoothly rising to its cruisealt.

if the tag = 0, the current behaviour. plane rises to its cruisealt then begins its forward acceleration.

thoughts, suggestions, comments?
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: Horizontal takeoff

Post by Argh »

+1000, MTR, and I don't think that the current code starts actually handling aircraft with aircraft behavior until they finish the VTOL, which is the real problem.

Got a crazy idea, though. I think that this would best be solved by having two values for height- takeOffHeight, the goal for VTOL (set to 1 for behavior much like a real aircraft) and then good ol' CruiseAlt.
Warlord Zsinj
Imperial Winter Developer
Posts: 3742
Joined: 24 Aug 2004, 08:59

Re: Horizontal takeoff

Post by Warlord Zsinj »

User avatar
Pressure Line
Posts: 2283
Joined: 21 May 2007, 02:09

Re: Horizontal takeoff

Post by Pressure Line »

im aware of that lua. but imo you shouldnt have to hack the engine to get such a simple behaviour
Warlord Zsinj
Imperial Winter Developer
Posts: 3742
Joined: 24 Aug 2004, 08:59

Re: Horizontal takeoff

Post by Warlord Zsinj »

I don't think it'd be exactly simple... VTOL, that's simple. Getting a plane to taxi, making sure there's enough area for it to land on, etc, it'd be pretty difficult I think - but I'm no coder.
User avatar
Pressure Line
Posts: 2283
Joined: 21 May 2007, 02:09

Re: Horizontal takeoff

Post by Pressure Line »

im not asking for anything that complicated, all I'm really after is for it to begin its forward acceleration immediately, instead of after its completed its vertical climb. same applies for landing, planes will often overshoot their last move waypoint anyway, so all thats needed there is for the plane to begin dropping as soon as it hits the waypoint, rather than waiting to stop then dropping.

fair enough, taxiing and all that stuff in the S44 lua looks hella tricky, theres working lua for it so may as well use that if thats what you are after, but for simple behaviour to make planes look a bit better... no need to go super-complicated for it.
User avatar
Pressure Line
Posts: 2283
Joined: 21 May 2007, 02:09

Re: Horizontal takeoff

Post by Pressure Line »

Current AirMoveType.cpp section

Code: Select all

void CAirMoveType::UpdateTakeOff(float wantedHeight)
{
	float3& pos = owner->pos;
	float3& speed = owner->speed;

	float h = 0.0f;
	if (owner->unitDef->canSubmerge)
		h = pos.y - ground->GetApproximateHeight(pos.x, pos.z);
	else
		h = pos.y - ground->GetHeight(pos.x,pos.z);

	if (h > wantedHeight) {
		SetState(AIRCRAFT_FLYING);
	}

	if ((h + speed.y * 20) < (wantedHeight * 1.02f))
		speed.y += maxAcc;
	else
		speed.y -= maxAcc;

	if (h > wantedHeight * 0.4f)
		speed += owner->frontdir * maxAcc;

	speed *= invDrag;

	owner->frontdir.Normalize();
	owner->rightdir = owner->frontdir.cross(owner->updir);
	owner->rightdir.Normalize();
	owner->updir = owner->rightdir.cross(owner->frontdir);

	pos += speed;
	owner->UpdateMidPos();
Amended AirMoveType.cpp section
void CAirMoveType::UpdateTakeOff(float wantedHeight)
{
float3& pos = owner->pos;
float3& speed = owner->speed;

float h = 0.0f;
if (owner->unitDef->canSubmerge)
h = pos.y - ground->GetApproximateHeight(pos.x, pos.z);
else
h = pos.y - ground->GetHeight(pos.x,pos.z);

if (owner->unitDef->htol) {
SetState(AIRCRAFT_FLYING);
}


if (h > wantedHeight) {
SetState(AIRCRAFT_FLYING);
}

if ((h + speed.y * 20) < (wantedHeight * 1.02f))
speed.y += maxAcc;
else
speed.y -= maxAcc;

if (h > wantedHeight * 0.4f)
speed += owner->frontdir * maxAcc;

speed *= invDrag;

owner->frontdir.Normalize();
owner->rightdir = owner->frontdir.cross(owner->updir);
owner->rightdir.Normalize();
owner->updir = owner->rightdir.cross(owner->frontdir);

pos += speed;
owner->UpdateMidPos();
}
Would just need the tag adding in the appropriate parts of the UnitDefHandler(s)

NB this would only affect takeoff, not landing
User avatar
yuritch
Spring 1944 Developer
Posts: 1018
Joined: 11 Oct 2005, 07:18

Re: Horizontal takeoff

Post by yuritch »

Something like this will be better imo:

Code: Select all

Index: rts/Sim/MoveTypes/AirMoveType.cpp
===================================================================
--- rts/Sim/MoveTypes/AirMoveType.cpp	(revision 7135)
+++ rts/Sim/MoveTypes/AirMoveType.cpp	(working copy)
@@ -856,6 +856,9 @@
 	else
 		h = pos.y - ground->GetHeight(pos.x,pos.z);
 
+	if (owner->unitDef->htol)  {
+		SetState(AIRCRAFT_FLYING);
+	}
 	if (h > wantedHeight) {
 		SetState(AIRCRAFT_FLYING);
 	}
Index: rts/Sim/Units/UnitDef.h
===================================================================
--- rts/Sim/Units/UnitDef.h	(revision 7135)
+++ rts/Sim/Units/UnitDef.h	(working copy)
@@ -248,6 +248,7 @@
 
 	bool canSubmerge;
 	bool canfly;
+	bool htol;		// fake HTOL takeoff behaviour
 	bool canmove;
 	bool canhover;
 	bool floater;
Index: rts/Sim/Units/UnitDefHandler.cpp
===================================================================
--- rts/Sim/Units/UnitDefHandler.cpp	(revision 7135)
+++ rts/Sim/Units/UnitDefHandler.cpp	(working copy)
@@ -324,6 +324,7 @@
 
 	ud.canSubmerge = udTable.GetBool("canSubmerge", false);
 	ud.canfly      = udTable.GetBool("canFly",      false);
+	ud.htol        = udTable.GetBool("htol",        false);
 	ud.canmove     = udTable.GetBool("canMove",     false);
 	ud.reclaimable = udTable.GetBool("reclaimable", true);
 	ud.capturable  = udTable.GetBool("capturable",  true);

I can't test that though, gcc 4.3 refuses to build Spring for me (it errors on the linking phase).
Attachments
htol.zip
htol patch file
(578 Bytes) Downloaded 13 times
User avatar
yuritch
Spring 1944 Developer
Posts: 1018
Joined: 11 Oct 2005, 07:18

Re: Horizontal takeoff

Post by yuritch »

Ok, I've got Spring to build on my machine (looks like MSYS is a very important part of the build environment, MinGW itself doesn't contain such tools as touch for ex. which is needed by scons). Now the tests show that this simple htol implementation isn't quite workable.
The planes behave like this: when sitting on the ground and given a move order, they start to move in whatever direction their nose is pointing at the moment and move in a straight line that way until they reach some bump in the ground (ie on a flat map they will move right to the map edge and beyond). When they do reach some place with a ground height difference, they start to take off slowly (which looks about right) and while doing that slowly turn to their destination (as if they received a new move order in flight). If they are given a stop order, they quickly ascend to the cruiseAlt if they haven't yet achieved it and then land in an old vtol fashion. Not exactly what I had in mind.
User avatar
Pressure Line
Posts: 2283
Joined: 21 May 2007, 02:09

Re: Horizontal takeoff

Post by Pressure Line »

perhaps make it do a short lift vtol style first, but only to 1/10 of the unit's cruisealt.

afaik that error is occuring because the plane is colliding with the ground, and doesnt have enough room to pitch up
if (owner->unitDef->htol) {
wantedheight = owner->unitDef->cruisealt / 10;
}
or sth like that in the correct syntax
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: Horizontal takeoff

Post by Argh »

Took a look at the code... there are a couple of things I'd like to point out:

1. StartMoving() isn't being called until after the TAKEOFF state reaches completion. This should probably be changed, although I'm not sure if it's going to cause backwards-compatibility issues. We may need a specific new COB function, like "StartFlying()" to get called instead.

2. If COB could change the current state of the aircraft, and pass that to CAirMoveType, then this is relatively straightforward. Simply declare that the Unit is flying immediately, or trigger some LuaMoveCtrl to make it move upwards with a bit of acceleration, then after X time change the state via COB. Basically, let COB take control, and then it's possible. So far as I can tell, the states are arbitrary, and changing the state won't cause serious problems.
User avatar
Pressure Line
Posts: 2283
Joined: 21 May 2007, 02:09

Re: Horizontal takeoff

Post by Pressure Line »

it depends on the type of plane. brawler type aircraft do it differently to fighters/bombers iirc.

but thats not the issue here Argh. you could do a simple if GET CURRENT_SPEED to do any flying animations for an htol aircraft, since it woould begin moving immediately.
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: Horizontal takeoff

Post by Argh »

What I'm saying here is that:

A. COB doesn't know that an aircraft is flying until the MoveAI tells it that it is. If we're going to manipulate things, then that's probably the best way to signal to the Unit. After all, different game designers will want to solve this in various ways, for specific cases- everything from realistic STOL to traditional airliner-style takeoff.

B. Nothing- neither Lua nor COB- is able to set the current state of the MoveAI. Until that happens, you can MoveCtrl the aircraft if given a move command, but you can't just give up direct control and tell it to start flying normally. It's a chicken-and-egg issue, basically- you can very well use MoveCtrl to get it off the ground, but if you release it, it won't know that it's in the air, and the resulting behavior won't be what we want.
User avatar
Pressure Line
Posts: 2283
Joined: 21 May 2007, 02:09

Re: Horizontal takeoff

Post by Pressure Line »

i think you are misunderstanding what is happening here?

what happens now:
current.JPG
current.JPG (3.25 KiB) Viewed 5548 times
what my changes were supposed to do:
desired.JPG
desired.JPG (3.87 KiB) Viewed 5548 times
what my changes actually did:
whathappens.JPG
whathappens.JPG (2.94 KiB) Viewed 5549 times
User avatar
Pressure Line
Posts: 2283
Joined: 21 May 2007, 02:09

Re: Horizontal takeoff

Post by Pressure Line »

possible way to fix this:
possiblefix.JPG
possiblefix.JPG (4.16 KiB) Viewed 5542 times
im not 100% sure what you are on about tbfh. this is all engine side, not lua. this is not complicated stuff, if you want complicated takeoff/land behaviour like in s44, use the s44 lua (or something like it).
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: Horizontal takeoff

Post by Argh »

I'm saying, "quit trying to do this engine-side and provide the information and control to COB and Lua".

Think outside the box here- the behavior doesn't need to be engine-side. You don't need a tag and yet-another hard-coded case. That MoveType is bad enough already.

You just need a function call to COB, and allow COB and / or Lua to set the current state of the AI, and you're done, because at that point, the AI will work properly, because it'll be at or near CruiseAlt, and can fly up/down to get there. Heck, at that point, we can follow the vector along the length of the line that it will take during the time it accelerates, and auto-adjust the angle of takeoff, to avoid hills, etc.
User avatar
Pressure Line
Posts: 2283
Joined: 21 May 2007, 02:09

Re: Horizontal takeoff

Post by Pressure Line »

Pressure Line wrote:im not asking for anything that complicated, all I'm really after is for it to begin its forward acceleration immediately, instead of after its completed its vertical climb. same applies for landing, planes will often overshoot their last move waypoint anyway, so all thats needed there is for the plane to begin dropping as soon as it hits the waypoint, rather than waiting to stop then dropping.

fair enough, taxiing and all that stuff in the S44 lua looks hella tricky, theres working lua for it so may as well use that if thats what you are after, but for simple behaviour to make planes look a bit better... no need to go super-complicated for it.
if you want that kind of thing, guess what, already exists. trouble is most mods/games dont want/need that level of complexity or have someone who understands that level of code well enough to adapt it to suit their needs.

we are talking about FIVE LINES OF ENGINE CODE to make a minor cosmetic change to aircraft takeoff behaviour, not a massive re-write of the way aircraft are handled.
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: Horizontal takeoff

Post by Argh »

I really don't think what I'm saying is more complicated that what you're trying to do, which isn't going work unless you deal with nearby heights during takeoff no matter how you go about it, but meh, good luck with the patch.
User avatar
Pressure Line
Posts: 2283
Joined: 21 May 2007, 02:09

Re: Horizontal takeoff

Post by Pressure Line »

Argh wrote:I really don't think what I'm saying is more complicated that what you're trying to do, which isn't going work unless you deal with nearby heights during takeoff no matter how you go about it, but meh, good luck with the patch.
no more trouble than a *A fighter type plane has while making an attack run on a unit that is next to a hill. obviously tall, steep hills right next takeoff point and on the takeoff vector are going to pose a problem, but its not possible to code for every possible situation.
User avatar
lurker
Posts: 3842
Joined: 08 Jan 2007, 06:13

Re: Horizontal takeoff

Post by lurker »

Pressure Line wrote:but its not possible to code for every possible situation.
Flawed argument. It's one situation that will happen a lot.
And read what argh's saying! He wants a single get/set call to the move state. It wouldn't be any longer than the patch you have right now to put calls into cob and lua (your patch won't be 5 lines because you have to add code to load unitdefs and show them to lua). Then, instead of adding one line to the fbi, you add 1 or 2 lines to the bos.
Post Reply

Return to “Feature Requests”