I am creating a nuclear war simulation game a bit like Defcon if any of you have played that. In the game you can chose one of several regions to play as and in my game I want each region to have different stats for their weapons and I want these stats to be changeable throughout the game if a region decides to develop a particular weapon for instance.
So I have a generic Weapon class that has a damage, a cost, a range etc. I then have different types of Weapon all stored in a WeaponArsenal class (ICBM, MRBM etc). Each region has different values for each of these and it needs to be possible to change them when the player or AI decides to upgrade a weapon.
Of course I can't predict which region the player will pick and therefore can't determine which regions will be AI controlled and which will be the player region. At the moment each available region is a class which has its own values for its weapons through an object but I don't know how I can chose which class to use for the player at run time without very repetitive if statements.
How can I therefore allow the player to upgrade their selected region's weapons without knowing their chosen region and calling a function explicitly?
Should I make a pointer to an object and point it to a different class's object depending on input at the start and then use this object pointer to change a region's variables throughout the game, and is having each region be its own class the best way of setting the game up? I have heard that making each region a map might make things easier but do not now how I would implement this. Which data structure should I use and how should I implement it?
The weapon class:
class Weapon
{
private:
int count;
int damage;
float cost;
int range;
public:
void upgradeRange(Weapon wep, float p) {
float percentDecimal = p / 100;
float modifier = percentDecimal + 1;
wep.range * modifier;
}
// more functions for upgrading each stat
// more functions for setting and getting each stat
}
The WeaponArsenal class:
class WeaponArsenal
{ /* Weapon Types */
public:
Weapon icbm;
Weapon mrbm;
Weapon srbm;
Weapon bomb;
WeaponArsenal() {
// DEFAULT ICBM VALUES
icbm.setCount(0);
icbm.setCost(120);
icbm.setRange(8000);
icbm.setDamage(80);
// DEFAULT MRBM VALUES
mrbm.setCount(0);
mrbm.setCost(100);
mrbm.setRange(2000);
mrbm.setDamage(70);
// DEFAULT SRBM VALUES
srbm.setCount(0);
srbm.setCost(80);
srbm.setRange(800);
srbm.setDamage(55);
}
};
A region class:
class Europe
{
private:
WeaponArsenal arsenal;
public:
Europe() {
}
};
Full main.cpp file so far is on Github: