Spring + C++ question
Moderator: Moderators
- PauloMorfeo
- Posts: 2004
- Joined: 15 Dec 2004, 20:53
Spring + C++ question
Any specific reason why Spring uses Pointers all over the place as oposed to References?
- PauloMorfeo
- Posts: 2004
- Joined: 15 Dec 2004, 20:53
- PauloMorfeo
- Posts: 2004
- Joined: 15 Dec 2004, 20:53
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").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").
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;
}
Code: Select all
[damage]
{
Default=100;
Vehicles=10;
Buldog=1000;
}
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:
Then, my Armor.txt has entries that look like this:
Finally, my weapons' damage properties look like this:
... 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?
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;
}
Code: Select all
[REFLEC]
{
REFLEC=99;
Knight=99;
Strider=99;
}
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?
Rubbish. Sorry, but I've been doing that since armor.txt was introduced and it works fine.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.
e.g.
armor.txt
Code: Select all
[ARMBULL]
{
ARMBULL=99;
}
Code: Select all
[DAMAGE]
default=10;
ARMBULL=1000;

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

@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

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.
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.
- PauloMorfeo
- Posts: 2004
- Joined: 15 Dec 2004, 20:53
/trunk/rts/Sim/Units/Unit.h
/trunk/rts/Sim/Units/Unit.cpp
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...
Code: Select all
class CUnit : public CSolidObject
{
...
int armorType;
...
}
Code: Select all
void CUnit::DoDamage(const DamageArray& damages, ...)
{
...
float damage=damages[armorType];
}
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...
- PauloMorfeo
- Posts: 2004
- Joined: 15 Dec 2004, 20:53
... can't figure it out entirely how it loads. I have absolutely no idea what the function:
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:
Weapons must have:
Units must have:
When assigning damage, it needs this algorithm:
//Unit.cpp
//CUnit::DoDamage
I think that's it. In pseudo c++/c# code.
Code: Select all
int CDamageArrayHandler::GetTypeFromName(std::string name)
{
}
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;
Code: Select all
struct specificDamage
{
string armorClassName; //the name of the armor class
float damage;
}
float defaultDamage;
vector<specificDamage> specificDamages;
Code: Select all
vector<string> armorClasses;
//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;
}
}
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/
http://taspring.clan-sy.com/mantis/
- PauloMorfeo
- Posts: 2004
- Joined: 15 Dec 2004, 20:53
Well, i can't figure out how it loads the info from armor.txt.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/
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