Skip to content
Permalink
Browse files

Craft and UFO shields support (squash)

  • Loading branch information...
ohartenstein23 authored and MeridianOXC committed Dec 20, 2016
1 parent c4857aa commit 490ceffa7e8efc70bc6a8dbdd3bbb7ab9c1ebfdb
@@ -87,7 +87,15 @@ CraftInfoState::CraftInfoState(Base *base, size_t craftId) : _base(base), _craft
_btnArmor = new TextButton(64, 16, 16, bottom + 2 * bottom_row);
_btnPilots = new TextButton(64, 16, 16, bottom + 3 * bottom_row);
_edtCraft = new TextEdit(this, 140, 16, 80, 8);
_txtDamage = new Text(100, 17, 14, 24);
if (_craft->getShieldCapacity() != 0)
{
_txtDamage = new Text(100, 17, 14, 8);
}
else
{
_txtDamage = new Text(100, 17, 14, 24);
}
_txtShield = new Text(140, 17, 14, 24);
_txtFuel = new Text(82, 17, 228, 24);
for(int i = 0; i < _weaponNum; ++i)
{
@@ -122,6 +130,7 @@ CraftInfoState::CraftInfoState(Base *base, size_t craftId) : _base(base), _craft
add(_btnPilots, "button", "craftInfo");
add(_edtCraft, "text1", "craftInfo");
add(_txtDamage, "text1", "craftInfo");
add(_txtShield, "text1", "craftInfo");
add(_txtFuel, "text1", "craftInfo");
for(int i = 0; i < _weaponNum; ++i)
{
@@ -169,6 +178,9 @@ CraftInfoState::CraftInfoState(Base *base, size_t craftId) : _base(base), _craft
_txtDamage->setColor(Palette::blockOffset(13)+10);
_txtDamage->setSecondaryColor(Palette::blockOffset(13));

_txtShield->setColor(Palette::blockOffset(13)+10);
_txtShield->setSecondaryColor(Palette::blockOffset(13));

_txtFuel->setColor(Palette::blockOffset(13)+10);
_txtFuel->setSecondaryColor(Palette::blockOffset(13));

@@ -212,13 +224,29 @@ void CraftInfoState::init()
_txtDamage->setText(firlsLine.str());

std::wostringstream secondLine;
secondLine << tr("STR_FUEL").arg(Text::formatPercentage(_craft->getFuelPercentage()));
if (_craft->getShieldCapacity() != 0)
{
secondLine << tr("STR_SHIELD").arg(Text::formatPercentage(_craft->getShieldPercentage()));
if (_craft->getShield() < _craft->getShieldCapacity())
{
int shieldHours = (int)ceil((double)_craft->getShieldCapacity() / _craft->getRules()->getShieldRechargeAtBase());
secondLine << formatTime(shieldHours);
}
}
else
{
secondLine << "";
}
_txtShield->setText(secondLine.str());

std::wostringstream thirdLine;
thirdLine << tr("STR_FUEL").arg(Text::formatPercentage(_craft->getFuelPercentage()));
if (_craft->getStatus() == "STR_REFUELLING" && _craft->getFuelMax() - _craft->getFuel() > 0)
{
int fuelHours = (int)ceil((double)(_craft->getFuelMax() - _craft->getFuel()) / _craft->getRules()->getRefuelRate() / 2.0);
secondLine << formatTime(fuelHours);
thirdLine << formatTime(fuelHours);
}
_txtFuel->setText(secondLine.str());
_txtFuel->setText(thirdLine.str());

if (_craft->getRules()->getSoldiers() > 0)
{
@@ -46,7 +46,7 @@ class CraftInfoState : public State
TextButton *_btnOk, *_btnW[RuleCraft::WeaponMax], *_btnCrew, *_btnEquip, *_btnArmor, *_btnPilots;
Window *_window;
TextEdit *_edtCraft;
Text *_txtDamage, *_txtFuel;
Text *_txtDamage, *_txtShield, *_txtFuel;
Text *_txtWName[RuleCraft::WeaponMax], *_txtWAmmo[RuleCraft::WeaponMax];
Surface *_sprite, *_weapon[RuleCraft::WeaponMax], *_crew, *_equip;
/// Formats an amount of time.
@@ -152,6 +152,8 @@ void CraftWeaponsState::lstWeaponsClick(Action *)
_base->getStorageItems()->addItem(current->getRules()->getLauncherItem());
_base->getStorageItems()->addItem(current->getRules()->getClipItem(), current->getClipsLoaded(_game->getMod()));
_craft->addCraftStats(-current->getRules()->getBonusStats());
// Make sure craft removes bonus shields
_craft->setShield(_craft->getShield() -current->getRules()->getBonusStats().shieldCapacity);
delete current;
_craft->getWeapons()->at(_weapon) = 0;
}
@@ -203,7 +203,14 @@ void BaseDefenseState::nextStep()
_lstDefenses->setCellText(_row, 2, tr("STR_HIT"));
_game->getMod()->getSound("GEO.CAT", (def)->getRules()->getHitSound())->play();
int dmg = (def)->getRules()->getDefenseValue();
_ufo->setDamage(_ufo->getDamage() + (dmg / 2 + RNG::generate(0, dmg)));
dmg = dmg / 2 + RNG::generate(0, dmg);
if (_ufo->getShield() > 0)
{
int shieldDamage = dmg;
dmg = std::max(0, dmg - _ufo->getShield());
_ufo->setShield(_ufo->getShield() - shieldDamage);
}
_ufo->setDamage(_ufo->getDamage() + dmg);
}
if (_ufo->getStatus() == Ufo::DESTROYED)
_action = BDA_DESTROY;

0 comments on commit 490ceff

Please sign in to comment.
You can’t perform that action at this time.