Skip to content

Commit

Permalink
Merge pull request #9 from SupSuper/master
Browse files Browse the repository at this point in the history
sync
  • Loading branch information
GixG committed Oct 14, 2013
2 parents c717382 + 67fced7 commit 467ce74
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 4 deletions.
12 changes: 11 additions & 1 deletion src/Battlescape/ProjectileFlyBState.cpp
Expand Up @@ -32,6 +32,7 @@
#include "../Savegame/Tile.h"
#include "../Resource/ResourcePack.h"
#include "../Engine/Sound.h"
#include "../Ruleset/Armor.h"
#include "../Ruleset/RuleItem.h"
#include "../Engine/Options.h"
#include "AlienBAIState.h"
Expand Down Expand Up @@ -297,7 +298,16 @@ void ProjectileFlyBState::think()
/* TODO refactoring : store the projectile in this state, instead of getting it from the map each time? */
if (_parent->getMap()->getProjectile() == 0)
{
if (_action.type == BA_AUTOSHOT && _action.autoShotCounter < _action.weapon->getRules()->getAutoShots() && !_action.actor->isOut() && _ammo->getAmmoQuantity() != 0)
Tile *t = _parent->getSave()->getTile(_action.actor->getPosition());
Tile *bt = _parent->getSave()->getTile(_action.actor->getPosition() + Position(0,0,-1));
bool hasFloor = t && !t->hasNoFloor(bt);
bool unitCanFly = _action.actor->getArmor()->getMovementType() == MT_FLY;

if (_action.type == BA_AUTOSHOT
&& _action.autoShotCounter < _action.weapon->getRules()->getAutoShots()
&& !_action.actor->isOut()
&& _ammo->getAmmoQuantity() != 0
&& (hasFloor || unitCanFly))
{
createNewProjectile();
}
Expand Down
32 changes: 31 additions & 1 deletion src/Ruleset/Armor.cpp
Expand Up @@ -30,10 +30,21 @@ namespace OpenXcom
* @param movementType The movement type for this armor (walk, fly or slide).
* @param size The size of the armor. Normally this is 1 (small) or 2 (big).
*/
Armor::Armor(const std::string &type, std::string spriteSheet, int drawingRoutine, MovementType movementType, int size) : _type(type), _spriteSheet(spriteSheet), _spriteInv(""), _corpseItem(""), _storeItem(""), _frontArmor(0), _sideArmor(0), _rearArmor(0), _underArmor(0), _drawingRoutine(drawingRoutine), _movementType(movementType), _size(size)
Armor::Armor(const std::string &type, std::string spriteSheet, int drawingRoutine, MovementType movementType, int size) : _type(type), _spriteSheet(spriteSheet), _spriteInv(""), _corpseItem(""), _storeItem(""), _frontArmor(0), _sideArmor(0), _rearArmor(0), _underArmor(0), _drawingRoutine(drawingRoutine), _movementType(movementType), _size(size), _weight(6)
{
for (int i=0; i < DAMAGE_TYPES; i++)
_damageModifier[i] = 1.0;
_stats.bravery = 0;
_stats.firing = 0;
_stats.health = 0;
_stats.melee = 0;
_stats.psiSkill = 0;
_stats.psiStrength = 0;
_stats.reactions = 0;
_stats.stamina = 0;
_stats.strength = 0;
_stats.tu = 0;
_stats.throwing = 0;
}

/**
Expand Down Expand Up @@ -62,6 +73,8 @@ void Armor::load(const YAML::Node &node)
_drawingRoutine = node["drawingRoutine"].as<int>(_drawingRoutine);
_movementType = (MovementType)node["movementType"].as<int>(_movementType);
_size = node["size"].as<int>(_size);
_weight = node["weight"].as<int>(_weight);
_stats = node["stats"].as<UnitStats>(_stats);
if (const YAML::Node &dmg = node["damageModifier"])
{
for (size_t i = 0; i < dmg.size() && i < DAMAGE_TYPES; ++i)
Expand Down Expand Up @@ -203,4 +216,21 @@ std::vector<int> Armor::getLoftempsSet() const
return _loftempsSet;
}

/**
* Gets pointer to the armor's stats.
* @return stats Pointer to the armor's stats.
*/
UnitStats *Armor::getStats()
{
return &_stats;
}

/**
* Gets the armor's weight.
* @return the weight of the armor.
*/
int Armor::getWeight()
{
return _weight;
}
}
8 changes: 7 additions & 1 deletion src/Ruleset/Armor.h
Expand Up @@ -22,6 +22,7 @@
#include <string>
#include <yaml-cpp/yaml.h>
#include "MapData.h"
#include "Unit.h"

namespace OpenXcom
{
Expand All @@ -38,9 +39,10 @@ class Armor
std::string _type, _spriteSheet, _spriteInv, _corpseItem, _storeItem;
int _frontArmor, _sideArmor, _rearArmor, _underArmor, _drawingRoutine;
MovementType _movementType;
int _size;
int _size, _weight;
float _damageModifier[DAMAGE_TYPES];
std::vector<int> _loftempsSet;
UnitStats _stats;
public:
/// Creates a blank armor ruleset.
Armor(const std::string &type, std::string spriteSheet, int drawingRoutine, MovementType _movementType = MT_WALK, int size = 1);
Expand Down Expand Up @@ -76,6 +78,10 @@ class Armor
float getDamageModifier(ItemDamageType dt);
/// Gets loftempSet
std::vector<int> getLoftempsSet() const;
/// Gets the armor's stats.
UnitStats *getStats();
/// Gets the armor's weight.
int getWeight();
};

}
Expand Down
2 changes: 2 additions & 0 deletions src/Ruleset/Unit.h
Expand Up @@ -32,6 +32,8 @@ enum SpecialAbility { SPECAB_NONE = 0, SPECAB_EXPLODEONDEATH, SPECAB_BURNFLOOR,
struct UnitStats
{
int tu, stamina, health, bravery, reactions, firing, throwing, strength, psiStrength, psiSkill, melee;
public:
UnitStats& operator+=(const UnitStats& stats) { tu+=stats.tu; stamina+=stats.stamina; health+=stats.health; bravery+=stats.bravery; reactions+=stats.reactions; firing+=stats.firing; throwing+=stats.throwing; strength+=stats.strength; psiStrength+=stats.psiStrength; psiSkill+=stats.psiSkill; melee+=stats.melee; return *this; }
};

/**
Expand Down
4 changes: 3 additions & 1 deletion src/Savegame/BattleUnit.cpp
Expand Up @@ -68,6 +68,7 @@ BattleUnit::BattleUnit(Soldier *soldier, UnitFaction faction) : _faction(faction
_aggression = 1;
_specab = SPECAB_NONE;
_armor = soldier->getArmor();
_stats += *_armor->getStats(); // armors may modify effective stats
_loftempsSet = _armor->getLoftempsSet();
_gender = soldier->getGender();
_faceDirection = -1;
Expand Down Expand Up @@ -144,6 +145,7 @@ BattleUnit::BattleUnit(Unit *unit, UnitFaction faction, int id, Armor *armor, in
_value = unit->getValue();
_gender = GENDER_MALE;
_faceDirection = -1;
_stats += *_armor->getStats(); // armors may modify effective stats

_tu = _stats.tu;
_energy = _stats.stamina;
Expand Down Expand Up @@ -2324,7 +2326,7 @@ BattleUnit *BattleUnit::getCharging()
*/
int BattleUnit::getCarriedWeight(BattleItem *draggingItem) const
{
int weight = 6;
int weight = _armor->getWeight();
for (std::vector<BattleItem*>::const_iterator i = _inventory.begin(); i != _inventory.end(); ++i)
{
if ((*i) == draggingItem) continue;
Expand Down

0 comments on commit 467ce74

Please sign in to comment.