[Patch] Aircraft strafing

[Patch] Aircraft strafing

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
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

[Patch] Aircraft strafing

Post by AF »

This patch adds a new tag called HoverAttackStrafe, which defaults to 1.

If HoverAttack=1 and AirStrafe=1, then gunships will behave as they do at the moment. They're strafe in a circle around the target.

However, if HoverAttack=1 and AirStrafe=0, they will not strafe, and they will sit stationary in the air firing their weapons.

The same applies for other strafing. A construction aircraft with AirStrafe=0 will not move in a circle around a construction project, fature being reclaimed, or ressurecting feature.

Tested and verified using the EE bumblebee and the XTA arm construction plane to test if it works. Other planes without the tag showed no changes in behaviour.

Also I believe this does not affect fighters (hawk style), which use a different movement model, aka units with HoverAttack=0; who cant build, and genreally fall into the class of hawks and vamps. This shouldnt be a problem though.

Code: Select all

Index: Sim/MoveTypes/TAAirMoveType.cpp
===================================================================
--- Sim/MoveTypes/TAAirMoveType.cpp	(revision 3269)
+++ Sim/MoveTypes/TAAirMoveType.cpp	(working copy)
@@ -343,43 +343,48 @@
 				//logOutput.Print("In position, landing");
 				return;
 			case FLY_CIRCLING:
+				// break;
 				waitCounter++;
 				if (waitCounter > 100) {
 					//logOutput.Print("moving circlepos");
+					if(owner->unitDef->AirStrafe){
+						float3 relPos = pos - circlingPos;
+						if(relPos.x<0.0001f && relPos.x>-0.0001f)
+							relPos.x=0.0001f;
+						relPos.y = 0;
+						relPos.Normalize();
+						CMatrix44f rot;
+						rot.RotateY(1.0f);
+						float3 newPos = rot.Mul(relPos);
+
+						//Make sure the point is on the circle
+						newPos = newPos.Normalize() * goalDistance;
+
+						//Go there in a straight line
+						goalPos = circlingPos + newPos;
+					}
+					waitCounter = 0;
+				}
+				break;
+			case FLY_ATTACKING:{
+				//logOutput.Print("wait is %d", waitCounter);
+				if(owner->unitDef->AirStrafe){
 					float3 relPos = pos - circlingPos;
 					if(relPos.x<0.0001f && relPos.x>-0.0001f)
 						relPos.x=0.0001f;
 					relPos.y = 0;
 					relPos.Normalize();
 					CMatrix44f rot;
-					rot.RotateY(1.0f);
+					if (gs->randFloat()>0.5f)
+						rot.RotateY(0.6f+gs->randFloat()*0.6f);
+					else
+						rot.RotateY(-(0.6f+gs->randFloat()*0.6f));
 					float3 newPos = rot.Mul(relPos);
-
-					//Make sure the point is on the circle
 					newPos = newPos.Normalize() * goalDistance;
 
 					//Go there in a straight line
 					goalPos = circlingPos + newPos;
-					waitCounter = 0;
 				}
-				break;
-			case FLY_ATTACKING:{
-				//logOutput.Print("wait is %d", waitCounter);
-				float3 relPos = pos - circlingPos;
-				if(relPos.x<0.0001f && relPos.x>-0.0001f)
-					relPos.x=0.0001f;
-				relPos.y = 0;
-				relPos.Normalize();
-				CMatrix44f rot;
-				if (gs->randFloat()>0.5f)
-					rot.RotateY(0.6f+gs->randFloat()*0.6f);
-				else
-					rot.RotateY(-(0.6f+gs->randFloat()*0.6f));
-				float3 newPos = rot.Mul(relPos);
-				newPos = newPos.Normalize() * goalDistance;
-
-				//Go there in a straight line
-				goalPos = circlingPos + newPos;
 //				logOutput.Print("Changed circle pos");
 				break;}
 			case FLY_LANDING:{
Index: Sim/Units/UnitDef.h
===================================================================
--- Sim/Units/UnitDef.h	(revision 3269)
+++ Sim/Units/UnitDef.h	(working copy)
@@ -177,6 +177,7 @@
 	float turnRadius;
 	float wantedHeight;
 	bool hoverAttack;
+	bool AirStrafe;
 	float dlHoverFactor; // < 0 means it can land, >= 0 indicates how much the unit will move during hovering on the spot
 	bool DontLand () { return dlHoverFactor >= 0.0f; }
 
Index: Sim/Units/UnitDefHandler.cpp
===================================================================
--- Sim/Units/UnitDefHandler.cpp	(revision 3269)
+++ Sim/Units/UnitDefHandler.cpp	(working copy)
@@ -352,8 +352,9 @@
 	if(ud.builder && !ud.buildSpeed)		//core anti is flagged as builder for some reason
 		ud.builder=false;
 
-	ud.wantedHeight=atof(tdfparser.SGetValueDef("0", "UNITINFO\\cruisealt").c_str());;
-	ud.hoverAttack = !!atoi(tdfparser.SGetValueDef("0", "UNITINFO\\hoverattack").c_str());
+	ud.wantedHeight=atof(tdfparser.SGetValueDef("0", "UNITINFO\\cruisealt").c_str());
+	tdfparser.GetDef(ud.hoverAttack,"0", "UNITINFO\\hoverattack");
+	tdfparser.GetDef(ud.AirStrafe,"1", "UNITINFO\\AirStrafe");
 	ud.dlHoverFactor = atof(tdfparser.SGetValueDef("-1", "UNITINFO\\airhoverfactor").c_str());
 
 	tdfparser.GetDef(ud.transportSize, "0", "UNITINFO\\transportsize");
User avatar
REVENGE
Posts: 2382
Joined: 24 Aug 2006, 06:13

Post by REVENGE »

Good stuff. I've seen similar behavior in OTA with the TLL's sub hunting copter [not stationary, but it barely strafes], and helicopters [same look and feel as the sub hunter]. Having this on con air would be great, so that they don't accidentally move into enemy los and get blown up.
User avatar
Forboding Angel
Evolution RTS Developer
Posts: 14673
Joined: 17 Nov 2005, 02:43

Post by Forboding Angel »

not to mention it would help pathfinding greatly when there are a lot of them in game.
User avatar
KDR_11k
Game Developer
Posts: 8293
Joined: 25 Jun 2006, 08:44

Post by KDR_11k »

It'd be useful for implementing pseudo ground units that are in fact low flying airplanes that hover.
Tobi
Spring Developer
Posts: 4598
Joined: 01 Jun 2005, 11:36

Post by Tobi »

Looks ok, just AirStrafe should be airStrafe TBH...

Could you link to a copy of the patch / attach it to a mantis entry, because copy-pasting from code blocks in the forum messes up formatting etc. so it can't be applied easily.
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Post by AF »

I thought I did put it in mantis?

http://spring.clan-sy.com/mantis/view.php?id=402
Tobi
Spring Developer
Posts: 4598
Joined: 01 Jun 2005, 11:36

Post by Tobi »

Ah, hadn't seen it yet.
Tobi
Spring Developer
Posts: 4598
Joined: 01 Jun 2005, 11:36

Post by Tobi »

Committed (after s/AirStrafe/airStrafe/ as variables should start with a lowercase letter).
User avatar
jcnossen
Former Engine Dev
Posts: 2440
Joined: 05 Jun 2005, 19:13

Post by jcnossen »

s/AirStrafe/airStrafe/
Not everyone can speak sedish you know ...
Tobi
Spring Developer
Posts: 4598
Joined: 01 Jun 2005, 11:36

Post by Tobi »

It is often used as shortcut for "(I have) replace(d)" (on IRC for example), you don't have to know sed for that (heck, I already knew s/blah/foo/ ment replacement long before I learned about sed's existance).

Anyway, people can ask if they don't understand stuff, I don't feel obliged to explain everything to everyone :-)
Post Reply

Return to “Engine”