Spring + C++ question

Spring + C++ question

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
PauloMorfeo
Posts: 2004
Joined: 15 Dec 2004, 20:53

Spring + C++ question

Post by PauloMorfeo »

Any specific reason why Spring uses Pointers all over the place as oposed to References?
User avatar
jcnossen
Former Engine Dev
Posts: 2440
Joined: 05 Jun 2005, 19:13

Post by jcnossen »

because pointers can be 0 and references can't (well at least not in a non-hacked way). You'll find pointers in any medium-sized app written in C++
User avatar
PauloMorfeo
Posts: 2004
Joined: 15 Dec 2004, 20:53

Post by PauloMorfeo »

Ok. I've been trying to understand how Spring works, so i try to fix that armour.txt thing which is very broken and .. i can't read shit of Spring's code... Cheers! I love C++ so much!
Probably why it is broken in the first place... It's almost inpossible to read many C/C++ code.
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Post by Argh »

Why does everybody say that Armor.txt (not "Armour") is broken??? It works perfectly, so far as any of my experiments have been able to show. I strongly suspect that you're doing something wrong (like mis-spelling "Armor").
User avatar
Peet
Malcontent
Posts: 4384
Joined: 27 Feb 2006, 22:04

Post by Peet »

"Misspelling armor"...Says you, yank :lol:
User avatar
rattle
Damned Developer
Posts: 8278
Joined: 01 Jun 2006, 13:15

Post by rattle »

How about tags are kept in swedish in the future? :)
User avatar
PauloMorfeo
Posts: 2004
Joined: 15 Dec 2004, 20:53

Post by PauloMorfeo »

Argh wrote:Why does everybody say that Armor.txt (not "Armour") is broken??? It works perfectly, so far as any of my experiments have been able to show. I strongly suspect that you're doing something wrong (like mis-spelling "Armor").
First, in XTA, weapons have references to ARMBRAWL which is nowhere in armor.txt. Still, they, somehow, manage to aply to all planes (which are in armor class "LandAir").

Second, since cayrd was so sure of it not working well (beyond that i mentioned), i went for some further testings.
I tried to do this:
Armor.txt:

Code: Select all

[Buldog]
{
    ARMBULL=13;
}
[Vehicles]
{
    ARMBULL=13;
    ARMCROC=13;
}
Some weapon:

Code: Select all

[damage]
{
    Default=100;
    Vehicles=10;
    Buldog=1000;
}
That weapon deals 100 dmg as default and 10 to Bul and Croc. I tried switching orders in armor.txt and in the weapon definition. Still same result. Somehow, i can't managed to make it give 1000 dmg to bulldog.
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Post by Argh »

Here's how I did it. All of this stuff, btw, is right there in NanoBlobs 0.54b, for your reference.

First, I created some "minimal-class" Units:

Code: Select all

[UNITINFO]
{
//Internal settings 
Name=REFLEC;
UnitName=REFLEC;
ObjectName=Nullpoint.s3o;
Description=Null Object, used for Armor Table only.; 
Side=NANO;

//Unit limitations and properties 
BuildTime=10; 
MaxDamage=10; 
SoundCategory=NULL; 

//Energy and metal related 
BuildCostEnergy=100; 
BuildCostMetal=100; 

//Pathfinding and related 
FootprintX=2; 
FootprintZ=1; 
MaxSlope=15; 
MaxWaterDepth=20; 
MovementClass=DefaultMoveType; 

//Abilities new to Spring
ArmorType=REFLEC;
}
Then, my Armor.txt has entries that look like this:

Code: Select all

[REFLEC]
	{
	REFLEC=99;
	Knight=99;
	Strider=99;
	}
Finally, my weapons' damage properties look like this:

Code: Select all

	[DAMAGE]
		{
		default=0.000001;
		ULTRAHEAVY=750;
		REFLEC=200;
		HEAVY=600;
		LIGHT=500;
		}

... and it all works, perfectly. Striders and Knights take 200 damage per hit. Remember the rules, folks:

1. Armor creates a table that Spring checks a weapon against, when it registers a hit by a weapon.
2. If the unit is not listed specifically in Armor.txt, then the damage reverts to the default damage value of the weapon.
3. If the unit is listed more than once, then only the value that is assigned will apply.
4. If a weapon includes more than one applicable Armor listing for a given Unit, it picks the first one.
5. Lastly, if the unit is listed specifically anywhere in the Damage values for weapons, that will override the Armor value. Probably everywhere.


In short... never, ever EVER revert to old-style OTA Damage assignments! Do not use unit names for your Armor categories! Use generic "units" that are just there as placeholders, to prevent Spring from getting confused. Clear now?
User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6241
Joined: 29 Apr 2005, 01:14

Post by FLOZi »

In short... never, ever EVER revert to old-style OTA Damage assignments! Do not use unit names for your Armor categories! Use generic "units" that are just there as placeholders, to prevent Spring from getting confused.
Rubbish. Sorry, but I've been doing that since armor.txt was introduced and it works fine.

e.g.

armor.txt

Code: Select all

[ARMBULL]
{
ARMBULL=99;
}
some weapon.tdf

Code: Select all

[DAMAGE]
default=10;
ARMBULL=1000;
Has always worked fine for me. :| And your final point is incorrect unless someone has gone and finally given us back per-unit damages (90% sure they haven't)
User avatar
PauloMorfeo
Posts: 2004
Joined: 15 Dec 2004, 20:53

Post by PauloMorfeo »

FLOZi, i'm not sure i understood but .. what you have shown does not contradict Argh. The armor class you have has the same name of the unit and, theoretically, the weapon finds that armor class, not the unit.

Argh, i'm sorry but i'm still not convinced.
Let me explain one more time.
- XTA has no armour class named ARMBRAWL.
- It has a class named LandAir ( with all planes, which include the unit ARMBRAWL).
- Weapons have references to ARMBRAWL instead of LandAir.
And, still, they do that specific damage to all units inside the class LandAir. That should not work, as far as the theory of it's working goes.

About your example, i believe it works, for sure. The problem is when it doesn't work, not when it works. Mine example is not quite the same as your's. And it doesn't works... Something is wrong with the whole thing. I just don't know yet if it's to a leser degree or if it is major.

If only i could get into Spring's code. One thing is me having been working with C and C++ (in a ill-defined mixture that now is paying it's toll) for many years with my own ways of doing things. Another is messing around with code other people made with they're own *weird* ways...

NOTE:
You don't hapend to be using a devel version where the workings of armor classes have changed, are you?
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Post by Argh »

@FLOZi: I was just trying to be clear. I think that half the problem is people have been somewhat confused about how to procede. I agree, your way works just fine- I like mine, though, because it's completely crystal clear what is referring back to what. It's not a must, merely a good way to not be confused ;)

@PauloMorfeo: Well, if you do it the way I'm describing, it works. And FLOZi's method also works. I strongly suspect that if you search your Weapons for a reference to ARMBRAWL, you will find it somewhere. Which is probably what's going wrong.

As for reading Spring's code... well, it's not that easy at first, but you just have to sit with it for awhile. I use a grep parser a lot, to find the variables I want to manipulate, and then go from there :-)
User avatar
jcnossen
Former Engine Dev
Posts: 2440
Joined: 05 Jun 2005, 19:13

Post by jcnossen »

I don't even see the code anymore, all I see is blondes and brunettes... err, I mean peewee's and explosions ;)
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Post by Argh »

LOL... yeah... women... er... hey, I had a DATE today :-)


I mean... I wrote a lot've new explosion code today. And it's really awesome. Yeah.
SJ
Posts: 618
Joined: 13 Aug 2004, 17:13

Post by SJ »

Did anyone read the comments i put in the original armor.txt (and why did someone think it was important enough to save a few bytes and remove it at some point? )

You can refer damage to either the class name or one of the units that are part of the class. They are equivalent although I said that the class name should be the prefered method for new productions, the refering to unit name mostly being there for easier backward compatibility with TA mods.
User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6241
Joined: 29 Apr 2005, 01:14

Post by FLOZi »

If that means what I think it means I am slightly miffed that the point hadn't been clarified earlier.
User avatar
Pxtl
Posts: 6112
Joined: 23 Oct 2004, 01:43

Post by Pxtl »

While we're at it, can we have it renamed? WTF with the .txt? Every other config file is .TDF, except for the unit files (.fbi).
User avatar
PauloMorfeo
Posts: 2004
Joined: 15 Dec 2004, 20:53

Post by PauloMorfeo »

/trunk/rts/Sim/Units/Unit.h

Code: Select all

class CUnit : public CSolidObject  
{
	...
	int armorType;
	...
}
/trunk/rts/Sim/Units/Unit.cpp

Code: Select all

void CUnit::DoDamage(const DamageArray& damages, ...)
{
	...
	float damage=damages[armorType];
}
From what i could figure out of the code, a armorType is assigned to a unit which is then used to retreive a specific damage from the DamageArray array!?
I'm assuming that each weapon would have it's own DamageArray to hold a series of specific damages that it deals to each class?

That would mean that a unit can not belong, in practice, to more than one armor type. I suspect that a unit belonging to more than one armor class in Armor.txt would have it's type copied over the previous ones which would explain the behaviour i am getting.

But i ain't understanding much of the code. That DamageArray class is very weird. jcnossen puted it in a very funny way, i laughed my ass off. And it's true, i'm not used to looking at C/C++ anymore and that would help alot (2 years since i last messed with them). Still it's a bitch to read C/C++! Especially when most of it has no spaces...
User avatar
PauloMorfeo
Posts: 2004
Joined: 15 Dec 2004, 20:53

Post by PauloMorfeo »

... can't figure it out entirely how it loads. I have absolutely no idea what the function:

Code: Select all

int CDamageArrayHandler::GetTypeFromName(std::string name)
{
}
does. But i know that units are assigned one single class of armor.

It needs to be changed into this:
Armor.txt needs to be loaded into:

Code: Select all

struct armorClass
{
      string armorClassName; //the name of the armor class
      vector<string> units; //the name of the units in it
}
vector <armorClass> specificDamages;
Weapons must have:

Code: Select all

struct specificDamage
{
       string armorClassName; //the name of the armor class
       float damage;
}
float defaultDamage;
vector<specificDamage> specificDamages;
Units must have:

Code: Select all

vector<string> armorClasses;
When assigning damage, it needs this algorithm:
//Unit.cpp
//CUnit::DoDamage

Code: Select all

float damage=weapon.defaultDamage;
foreach (string armorClass in armorClasses) {
        foreach (specificDamage sd in weapon.specificDamages) {
                if (armorClass == sd.armorClassName) damage= sd.damage;
        }
}
I think that's it. In pseudo c++/c# code.
User avatar
rattle
Damned Developer
Posts: 8278
Joined: 01 Jun 2006, 13:15

Post by rattle »

Make a patch out of it but test it thoroughly and then try to get a dev to commit it.
http://taspring.clan-sy.com/mantis/
User avatar
PauloMorfeo
Posts: 2004
Joined: 15 Dec 2004, 20:53

Post by PauloMorfeo »

rattle wrote:Make a patch out of it but test it thoroughly and then try to get a dev to commit it.
http://taspring.clan-sy.com/mantis/
Well, i can't figure out how it loads the info from armor.txt.
I can't compile Spring (waiting for me to get the proper dvd of SuseELD10).
I could code it, in my own simple way and that is about it... The other 2 are missing.

Should i really add it to mantis? That thing is so slow and ircsome that i've grown to hate opening it.

I said the whole thing was broken :p
Post Reply

Return to “Engine”