Skip to content

Commit a88e35e

Browse files
committed
Convert Base Vehicles
not 100% sure this works as it should, but it should work.
1 parent 090c68d commit a88e35e

3 files changed

Lines changed: 43 additions & 1 deletion

File tree

src/Battlescape/BattlescapeGenerator.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,6 @@ void BattlescapeGenerator::run()
257257

258258
// add vehicles that are in the craft - a vehicle is actually an item, which you will never see as it is converted to a unit
259259
// however the item itself becomes the weapon it "holds".
260-
// TODO: Convert base vehicles
261260
if (_craft != 0)
262261
{
263262
for (std::vector<Vehicle*>::iterator i = _craft->getVehicles()->begin(); i != _craft->getVehicles()->end(); ++i)
@@ -274,6 +273,22 @@ void BattlescapeGenerator::run()
274273
unit->setTurretType((*i)->getRules()->getTurretType());
275274
}
276275
}
276+
else if (_base != 0)
277+
{
278+
for (std::vector<Vehicle*>::iterator i = _base->getVehicles()->begin(); i != _base->getVehicles()->end(); ++i)
279+
{
280+
std::string vehicle = (*i)->getRules()->getType();
281+
Unit *rule = _game->getRuleset()->getUnit(vehicle.substr(4));
282+
unit = addXCOMUnit(new BattleUnit(rule, FACTION_PLAYER, _unitSequence++, _game->getRuleset()->getArmor(rule->getArmor())));
283+
addItem(_game->getRuleset()->getItem(vehicle), unit);
284+
if((*i)->getRules()->getClipSize() != -1)
285+
{
286+
std::string ammo = (*i)->getRules()->getCompatibleAmmo()->front();
287+
addItem(_game->getRuleset()->getItem(ammo), unit)->setAmmoQuantity((*i)->getAmmo());
288+
}
289+
unit->setTurretType((*i)->getRules()->getTurretType());
290+
}
291+
}
277292

278293
// add soldiers that are in the craft or base
279294
for (std::vector<Soldier*>::iterator i = _base->getSoldiers()->begin(); i != _base->getSoldiers()->end(); ++i)

src/Savegame/Base.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1131,4 +1131,27 @@ std::vector<BaseFacility*> *Base::getDefenses()
11311131
}
11321132
return total;
11331133
}
1134+
1135+
/**
1136+
* Returns the list of vehicles currently equipped
1137+
* in the base.
1138+
* @return Pointer to vehicle list.
1139+
*/
1140+
std::vector<Vehicle*> *Base::getVehicles()
1141+
{
1142+
for (std::vector<Vehicle*>::iterator v = _vehicles.begin(); v < _vehicles.end(); ++v)
1143+
{
1144+
delete (*v);
1145+
}
1146+
for (std::map<std::string, int>::iterator i = _items->getContents()->begin(); i != _items->getContents()->end(); ++i)
1147+
{
1148+
if (_rule->getItem((i)->first)->isFixed())
1149+
{
1150+
std::string type = _rule->getItem((i)->first)->getType();
1151+
Vehicle *v = new Vehicle(_rule->getItem((i)->first), 0);
1152+
_vehicles.push_back(v);
1153+
}
1154+
}
1155+
return &_vehicles;
1156+
}
11341157
}

src/Savegame/Base.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class Ruleset;
3838
class SavedGame;
3939
class ResearchProject;
4040
class Production;
41+
class Vehicle;
4142

4243
/**
4344
* Represents a player base on the globe.
@@ -58,6 +59,7 @@ class Base : public Target
5859
std::vector<Production *> _productions;
5960
bool _inBattlescape;
6061
bool _retaliationTarget;
62+
std::vector<Vehicle*> _vehicles;
6163
public:
6264
/// Creates a new base.
6365
Base(const Ruleset *rule);
@@ -187,6 +189,8 @@ class Base : public Target
187189
int getGravShields() const;
188190
/// Get a list of Defensive Facilities
189191
std::vector<BaseFacility*> *getDefenses();
192+
/// Gets the base's vehicles.
193+
std::vector<Vehicle*> *getVehicles();
190194
};
191195

192196
}

0 commit comments

Comments
 (0)