New Weapon tdf tag

New Weapon tdf tag

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

Moderator: Moderators

User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6240
Joined: 29 Apr 2005, 01:14

New Weapon tdf tag

Post by FLOZi »

noGroundAttack=0/1;

If set to 1, the weapon will ignore commands to attack the ground. Other weapons on the unit are unaffected. The unit will not move into range if a shorter ranged weapon can attack the ground (this is the behaviour I (read: we at S44) desire).

Contents of the .diff:

Code: Select all

Index: Weapon.cpp

===================================================================

--- Weapon.cpp	(revision 3357)

+++ Weapon.cpp	(working copy)

@@ -16,6 +16,7 @@

 #include "WeaponDefHandler.h"
 #include "Sim/Projectiles/WeaponProjectile.h"
 #include "Sim/Misc/InterceptHandler.h"
+//#include "Sim/Misc/CategoryHandler.h"
 #include "Sim/Units/CommandAI/CommandAI.h"
 #include "Map/Ground.h"
 #include "Game/Camera.h"
@@ -342,7 +343,7 @@

 {
 	if((!userTarget && weaponDef->noAutoTarget))
 		return false;
-	if(weaponDef->interceptor || weaponDef->onlyTargetCategory!=0xffffffff)
+	if(weaponDef->interceptor || weaponDef->onlyTargetCategory!=0xffffffff || weaponDef->noGroundAttack)
 		return false;
 
 	if(!weaponDef->waterweapon && pos.y<1)
Index: WeaponDefHandler.cpp

===================================================================

--- WeaponDefHandler.cpp	(revision 3357)

+++ WeaponDefHandler.cpp	(working copy)

@@ -247,6 +247,7 @@

 	sunparser->GetDef(weaponDefs[id].energycost, "0", weaponname + "\\energypershot");
 	sunparser->GetDef(weaponDefs[id].selfExplode, "0", weaponname + "\\burnblow");
 	sunparser->GetDef(weaponDefs[id].sweepFire, "0", weaponname + "\\sweepfire");
+	sunparser->GetDef(weaponDefs[id].noGroundAttack, "0", weaponname + "\\nogroundattack");
 	weaponDefs[id].fireStarter=atof(sunparser->SGetValueDef("0", weaponname + "\\firestarter").c_str())*0.01f;
 	weaponDefs[id].paralyzer=!!atoi(sunparser->SGetValueDef("0", weaponname + "\\paralyzer").c_str());
 	if(weaponDefs[id].paralyzer)
Index: WeaponDefHandler.h

===================================================================

--- WeaponDefHandler.h	(revision 3357)

+++ WeaponDefHandler.h	(working copy)

@@ -172,6 +172,8 @@

 	CExplosionGenerator *explosionGenerator; // can be zero for default explosions
 
 	bool sweepFire;
+
+	bool noGroundAttack;
 };
 
 class CExplosionGeneratorHandler;
And the file itself:
http://flozi.pwp.blueyonder.co.uk/sprin ... ttack.diff


My first bit of Spring code, yay. :P
User avatar
ILMTitan
Spring Developer
Posts: 410
Joined: 13 Nov 2004, 08:35

Post by ILMTitan »

Looks good.
The one stylistic point I have, which you don't have to change here, is the variable name. It is generally a good to name booleans positively. So, instead of having noGroundAttack and not noGroundAttack, which takes an extra step to think about, you have not canGroundAttack and canGroundAttack. Fewer negations. It also puts the positive value in line with the positive result.
Tobi
Spring Developer
Posts: 4598
Joined: 01 Jun 2005, 11:36

Post by Tobi »

I agree with ILMTitan, just groundAttack or canGroundAttack would be better (also as tag, TBH). I'd actually prefer it if you could change that :-)
User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6240
Joined: 29 Apr 2005, 01:14

Post by FLOZi »

So the default value would be 1/true? That's generally not in line with other tags.

I prefer my way, as a modder, tbh. :? But I guess I'll change it.
User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6240
Joined: 29 Apr 2005, 01:14

Post by FLOZi »

Actually, it would be really nasty from the modder perspective to have the tag work that way (I can't think of a single example of a bool tag defaulting to 1?).

I understand where you are coming from with the internal variable name, but imo its less confusing to have it match the tdf tag and have to deal with double negations rather than have it be the opposite to the tdf tag which is something of a murky middleground of the worst of both worlds. :(
User avatar
KDR_11k
Game Developer
Posts: 8293
Joined: 25 Jun 2006, 08:44

Post by KDR_11k »

Tags like CanReclaim and CanRepair default to 1 for builders.
User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6240
Joined: 29 Apr 2005, 01:14

Post by FLOZi »

There's always one... :lol:

Fine. Any weapon tdfs tags that default to 1? :P
trepan
Former Engine Dev
Posts: 1200
Joined: 17 Nov 2005, 00:52

Post by trepan »

It would also be nice if ground attack commands were discarded
by the commandAI AllowedCommand() routine for invalid units.
trepan
Former Engine Dev
Posts: 1200
Joined: 17 Nov 2005, 00:52

Post by trepan »

FLOZI:

Code: Select all

sunparser->GetDef(collideFriendly, "1", weaponname + "\\CollideFriendly");
sunparser->GetDef(collideFeature, "1", weaponname + "\\CollideFeature");
User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6240
Joined: 29 Apr 2005, 01:14

Post by FLOZi »

trepan wrote:It would also be nice if ground attack commands were discarded
by the commandAI AllowedCommand() routine for invalid units.
You mean like builders and stuff? I thought they already were given a move command instead? Guess I'll look into it.




And BAH HUMBUG. :( :cry:
trepan
Former Engine Dev
Posts: 1200
Joined: 17 Nov 2005, 00:52

Post by trepan »

No, not just builders and stuff. When you issue a ground attack
order with your modified code, and the unit isn't allowed to attack
the ground, it gets stuck on that order (afaict).
User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6240
Joined: 29 Apr 2005, 01:14

Post by FLOZi »

Ah, you mean you have to manually remove them from the queue. Yes.

Though a unit would only be invalid if *all* its weapons used the tag, which should be a fairly special case anyway... Unless you want me to compare the target position with the unit position to determine the range and determine if the unit only has weapons which are unable to attack ground at that range... :|

Anyway, here's the modified diff for now:

[code]Index: Weapon.cpp

===================================================================

--- Weapon.cpp (revision 3357)

+++ Weapon.cpp (working copy)

@@ -342,7 +342,7 @@

{
if((!userTarget && weaponDef->noAutoTarget))
return false;
- if(weaponDef->interceptor || weaponDef->onlyTargetCategory!=0xffffffff)
+ if(weaponDef->interceptor || weaponDef->onlyTargetCategory!=0xffffffff || !weaponDef->canAttackGround)
return false;

if(!weaponDef->waterweapon && pos.y<1)
Index: WeaponDefHandler.cpp

===================================================================

--- WeaponDefHandler.cpp (revision 3357)

+++ WeaponDefHandler.cpp (working copy)

@@ -247,6 +247,8 @@

sunparser->GetDef(weaponDefs[id].energycost, "0", weaponname + "\\energypershot");
sunparser->GetDef(weaponDefs[id].selfExplode, "0", weaponname + "\\burnblow");
sunparser->GetDef(weaponDefs[id].sweepFire, "0", weaponname + "\\sweepfire");
+ sunparser->GetDef(weaponDefs[id].canAttackGround, "1", weaponname + "\\canattackground");
+
weaponDefs[id].fireStarter=atof(sunparser->SGetValueDef("0", weaponname + "\\firestarter").c_str())*0.01f;
weaponDefs[id].paralyzer=!!atoi(sunparser->SGetValueDef("0", weaponname + "\\paralyzer").c_str());
if(weaponDefs[id].paralyzer)
Index: WeaponDefHandler.h

===================================================================

--- WeaponDefHandler.h (revision 3357)

+++ WeaponDefHandler.h (working copy)

@@ -172,6 +172,8 @@

CExplosionGenerator *explosionGenerator; // can be zero for default explosions

bool sweepFire;
+
+ bool canAttackGround;
};

class CExplosionGeneratorHandler;
[/code]


http://flozi.pwp.blueyonder.co.uk/sprin ... round.diff

Now variable and tag are 'canAttackGround' default of 1.
User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6240
Joined: 29 Apr 2005, 01:14

Post by FLOZi »

trepan wrote:Ya, pre-computing a maxGroundAttackRange would be the right idea
(per UnitDef). This would also correct some of the current behaviour.
I'll look into doing that. No promises on delivery time though. :wink:

Only did this as we really need it for something we are doing in S44.


edit: reminder for myself, line 582 of CommandAI.cpp
Last edited by FLOZi on 31 Jan 2007, 01:01, edited 1 time in total.
trepan
Former Engine Dev
Posts: 1200
Joined: 17 Nov 2005, 00:52

Post by trepan »

Yes, pre-computing a canGroundAttack per UnitDef is the right idea.
Also, pre-computing a maxGroundAttackRange would help to fix the
current behaviour for immobile units (ex: orders asking guardians to
attack outside their range would be discarded).

P.S. You beat me to the punch before I'd finished this second draft ;)
User avatar
ILMTitan
Spring Developer
Posts: 410
Joined: 13 Nov 2004, 08:35

Post by ILMTitan »

FLOZi, what you said about the name of the tdf tag is valid. Perhaps the name of the tag should be noGroundAttack, while the boolean should be canAttackGround in the code? I believe destructible/indestructible already does that.
User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6240
Joined: 29 Apr 2005, 01:14

Post by FLOZi »

I did try it that way too - though it leads to the unintuitive situation of having to parse the value and then take the opposite, and of the internal var being opposite to the tdf value.

Tobi said he would prefer it this way, and Trepan has pointed out that there are (atleast a couple) of weapon tags that default to 1, so I'll leave it this way for now unless Tobi changes his mind. :-)
User avatar
Guessmyname
Posts: 3301
Joined: 28 Apr 2005, 21:07

Post by Guessmyname »

Just been testing this stuff with Flozi. This tag works perfectly at the moment
User avatar
Pxtl
Posts: 6112
Joined: 23 Oct 2004, 01:43

In a similar vein

Post by Pxtl »

There's a problem with OTA bombers that's been mentioned in BA - I'm not a modder, so this really isn't my business - but bombers need noautofire to prevent them from stupidly usign their primary attack at random targets. But that also means that bombers aremed with AA weapons don't fire those - could noautofire be made into a per-weapon tag?
Tobi
Spring Developer
Posts: 4598
Joined: 01 Jun 2005, 11:36

Post by Tobi »

Committed.
User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6240
Joined: 29 Apr 2005, 01:14

Re: In a similar vein

Post by FLOZi »

Pxtl wrote:There's a problem with OTA bombers that's been mentioned in BA - I'm not a modder, so this really isn't my business - but bombers need noautofire to prevent them from stupidly usign their primary attack at random targets. But that also means that bombers aremed with AA weapons don't fire those - could noautofire be made into a per-weapon tag?
commandfire=1;

?
Post Reply

Return to “Engine”