Skip to content

Commit

Permalink
Collect atmosphere-shieldable ships only once
Browse files Browse the repository at this point in the history
  • Loading branch information
kko committed Jul 5, 2012
1 parent 7cdb151 commit 36e02eb
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 14 deletions.
16 changes: 2 additions & 14 deletions src/ShipFlavour.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,20 +64,8 @@ void ShipFlavour::MakeTrulyRandom(ShipFlavour &v, bool atmospheric)
{
// only allow ships that can fit an atmospheric shield
if (atmospheric) {
std::vector<ShipType::Type> ships;
for (std::vector<ShipType::Type>::const_iterator it = ShipType::player_ships.begin();
it != ShipType::player_ships.end(); ++it) {
const ShipType &ship = ShipType::types[*it];
if (ship.equipSlotCapacity[Equip::SLOT_ATMOSHIELD] != 0)
ships.push_back(*it);
}
if (!ships.empty()) {
v = ShipFlavour(ships[Pi::rng.Int32(ships.size())]);
} else {
// Game should have at least some matching ships...
assert(false);
v = ShipFlavour(ShipType::player_ships.front());
}
const std::vector<ShipType::Type> &ships = ShipType::playable_atmospheric_ships;
v = ShipFlavour(ships[Pi::rng.Int32(ships.size())]);
} else {
const std::vector<ShipType::Type> &ships = ShipType::player_ships;
v = ShipFlavour(ships[Pi::rng.Int32(ships.size())]);
Expand Down
13 changes: 13 additions & 0 deletions src/ShipType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ std::vector<ShipType::Type> ShipType::player_ships;
std::vector<ShipType::Type> ShipType::static_ships;
std::vector<ShipType::Type> ShipType::missile_ships;

std::vector<ShipType::Type> ShipType::playable_atmospheric_ships;

std::string ShipType::LADYBIRD = "Ladybird Starfighter";
std::string ShipType::SIRIUS_INTERDICTOR = "Sirius Interdictor";
std::string ShipType::EAGLE_LRF = "Eagle Long Range Fighter";
Expand Down Expand Up @@ -243,5 +245,16 @@ void ShipType::Init()

if (ShipType::player_ships.empty())
Error("No playable ships have been defined! The game cannot run.");

//collect ships that can fit atmospheric shields
for (std::vector<ShipType::Type>::const_iterator it = ShipType::player_ships.begin();
it != ShipType::player_ships.end(); ++it) {
const ShipType &ship = ShipType::types[*it];
if (ship.equipSlotCapacity[Equip::SLOT_ATMOSHIELD] != 0)
ShipType::playable_atmospheric_ships.push_back(*it);
}

if (ShipType::playable_atmospheric_ships.empty())
Error("No ships can fit atmospheric shields! The game cannot run.");
}

2 changes: 2 additions & 0 deletions src/ShipType.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ struct ShipType {
static std::vector<Type> static_ships;
static std::vector<Type> missile_ships;

static std::vector<Type> playable_atmospheric_ships;

static const char *gunmountNames[GUNMOUNT_MAX];
static void Init();
static const ShipType *Get(const char *name) {
Expand Down

0 comments on commit 36e02eb

Please sign in to comment.