Weapon data in XML Files?
Posted: Mon Jul 19, 2010 4:28 pm
For a while, I've wanted to create a weapon system using XML files but I'm not sure how to do so. So instead of that, for now, I've decided to just keep doing things the way I have been by hardcoding all the weapon data. What I'd like to know is which way is better to go:
Have a weapon class and have derived classes like (Glock, M16 and etc) from it and create all the data by making instances like
Now, if I do this I'm not sure how I'd connect another class like Loadouts with weapons. In my game I have loadouts which are basically like classes in RPGs. Loadouts have their own specialities, weapons and abilities. Each loadout has 3 types of weapons that can be equipped: Primary, Secondary and Projectile.
Or I could create instances of the weapon class like such:
Instead of doing this, I wanted all the information to already been stored in XML files rather than me having to do this for ever weapon.
What i was thinking is that I can set each loadout with default weapons for each type like:
RESULT:
Current Weapon: M16
Bullet Damage: 4
So the in the player class, the player doesn't necessarily have the weapon but instead the Loadout class handles that. So whatever loadout the player has, the weapons he'll have is whatever weapons are in that loadout. Problem is that Loadouts are not gonna always have default weapons. In game, the player can change his weapon by picking up weapons or switching them. Loadouts can also be customized to fit the players wants.
Other notes:
The system runs like this. The player chooses their loadout and based on the pick, the player's primary, secondary and projectile weapons are chosen. In the beginning of the game, each loadout already has the defaults set.
If someone can help me figure out how to work with XML files or provide some links than it would be much appreciated and I'd scrap this way. Otherwise, any other ways of doing this would also be appreciated.
Have a weapon class and have derived classes like (Glock, M16 and etc) from it and create all the data by making instances like
Code: Select all
class Glock : public Weapon
{
private:
public:
}
Glock glock;
Or I could create instances of the weapon class like such:
Code: Select all
Weapon M16(32,4,2,9) //In parameters: Magsize, bulletdmg, X, Y)
Weapon Glock(17,2,8,9)
What i was thinking is that I can set each loadout with default weapons for each type like:
Code: Select all
Loadout Assault;
Assault->Primary.SetDefaultPrimary(&M16); //the assault loadout's primary weapon is the M16
Assault->Primary.SetDefaultSecondary(&Glock);
Assault->Primary.SetDefaultProjectile(&RPG);
cout << "Current Weapon:" << Assault->Primary.Name << endl;
cout << "Bullet Dmg:" << Assault->Primary.BulletDmg << endl; //for test
Current Weapon: M16
Bullet Damage: 4
So the in the player class, the player doesn't necessarily have the weapon but instead the Loadout class handles that. So whatever loadout the player has, the weapons he'll have is whatever weapons are in that loadout. Problem is that Loadouts are not gonna always have default weapons. In game, the player can change his weapon by picking up weapons or switching them. Loadouts can also be customized to fit the players wants.
Other notes:
The system runs like this. The player chooses their loadout and based on the pick, the player's primary, secondary and projectile weapons are chosen. In the beginning of the game, each loadout already has the defaults set.
Code: Select all
Player -----> Loadout ----> Weapon