/** * Check if unit eligible for squaddie promotion. If yes, promote the unit. * Increase the mission counter. Calculate the experience increases. * @return True if the soldier was eligible for squaddie promotion. */ bool BattleUnit::postMissionProcedures() { Soldier *s = dynamic_cast<Soldier*>(_unit); if (s == 0) { return false; } s->addMissionCount(); UnitStats *stats = s->getCurrentStats(); if (_expBravery && stats->bravery < 100) { if (_expBravery > RNG::generate(0,10)) stats->bravery += 10; } if (_expReactions && stats->reactions < 100) { stats->reactions += improveStat(_expReactions); } if (_expFiring && stats->firing < 120) { stats->firing += improveStat(_expFiring); } if (_expMelee && stats->melee < 120) { stats->melee += improveStat(_expMelee); } if (_expThrowing && stats->throwing < 120) { stats->throwing += improveStat(_expThrowing); } if (_expPsiSkill && stats->psiSkill < 100) { stats->psiSkill += improveStat(_expPsiSkill); } /* TODO wound recovery : Soldier->Wound_Recovery_Days = v / 2 + randmod(v) (v = UnitRef->BaseHPs - UnitRef->CurHP) */ if (_expBravery || _expReactions || _expFiring || _expPsiSkill || _expMelee) { if (s->getRank() == RANK_ROOKIE) s->promoteRank(); int v; v = 80 - stats->tu; if (v > 0) stats->tu += RNG::generate(0, v/10 + 2); v = 60 - stats->health; if (v > 0) stats->health += RNG::generate(0, v/10 + 2); v = 70 - stats->strength; if (v > 0) stats->strength += RNG::generate(0, v/10 + 2); v = 100 - stats->stamina; if (v > 0) stats->stamina += RNG::generate(0, v/10 + 2); return true; } else { return false; } }
/** * Update soldier stats when * the soldier changes. */ void SoldierInfoState::init() { Soldier *s = _base->getSoldiers()->at(_soldier); _edtSoldier->setText(s->getName()); UnitStats *initial = s->getInitStats(); UnitStats *current = s->getCurrentStats(); SurfaceSet *texture = _game->getResourcePack()->getSurfaceSet("BASEBITS.PCK"); texture->getFrame(s->getRankSprite())->setX(0); texture->getFrame(s->getRankSprite())->setY(0); texture->getFrame(s->getRankSprite())->blit(_rank); std::wstringstream ss; ss << current->tu; _numTimeUnits->setText(ss.str()); _barTimeUnits->setMax(current->tu); _barTimeUnits->setValue(current->tu); _barTimeUnits->setValue2(initial->tu); std::wstringstream ss2; ss2 << current->stamina; _numStamina->setText(ss2.str()); _barStamina->setMax(current->stamina); _barStamina->setValue(current->stamina); _barStamina->setValue2(initial->stamina); std::wstringstream ss3; ss3 << current->health; _numHealth->setText(ss3.str()); _barHealth->setMax(current->health); _barHealth->setValue(current->health); _barHealth->setValue2(initial->health); std::wstringstream ss4; ss4 << current->bravery; _numBravery->setText(ss4.str()); _barBravery->setMax(current->bravery); _barBravery->setValue(current->bravery); _barBravery->setValue2(initial->bravery); std::wstringstream ss5; ss5 << current->reactions; _numReactions->setText(ss5.str()); _barReactions->setMax(current->reactions); _barReactions->setValue(current->reactions); _barReactions->setValue2(initial->reactions); std::wstringstream ss6; ss6 << current->firing; _numFiring->setText(ss6.str()); _barFiring->setMax(current->firing); _barFiring->setValue(current->firing); _barFiring->setValue2(initial->firing); std::wstringstream ss7; ss7 << current->throwing; _numThrowing->setText(ss7.str()); _barThrowing->setMax(current->throwing); _barThrowing->setValue(current->throwing); _barThrowing->setValue2(initial->throwing); std::wstringstream ss8; ss8 << current->strength; _numStrength->setText(ss8.str()); _barStrength->setMax(current->strength); _barStrength->setValue(current->strength); _barStrength->setValue2(initial->strength); _txtArmor->setText(_game->getLanguage()->getString(s->getArmor()->getType())); std::wstringstream ss9; ss9 << _game->getLanguage()->getString("STR_RANK_") << L'\x01' << _game->getLanguage()->getString(s->getRankString()); _txtRank->setText(ss9.str()); std::wstringstream ss10; ss10 << _game->getLanguage()->getString("STR_MISSIONS") << L'\x01' << s->getMissions(); _txtMissions->setText(ss10.str()); std::wstringstream ss11; ss11 << _game->getLanguage()->getString("STR_KILLS") << L'\x01' << s->getKills(); _txtKills->setText(ss11.str()); std::wstringstream ss12; ss12 << _game->getLanguage()->getString("STR_CRAFT_") << L'\x01'; if (s->getCraft() == 0) ss12 << _game->getLanguage()->getString("STR_NONE_UC"); else ss12 << s->getCraft()->getName(_game->getLanguage()); _txtCraft->setText(ss12.str()); if (s->getWoundRecovery() > 1) { std::wstringstream ss13; ss13 << _game->getLanguage()->getString("STR_WOUND_RECOVERY") << L'\x01' << s->getWoundRecovery(); if (s->getWoundRecovery() > 1) ss13 << _game->getLanguage()->getString("STR_DAYS"); else ss13 << _game->getLanguage()->getString("STR_DAY"); _txtRecovery->setText(ss13.str()); } else { _txtRecovery->setText(L""); } }
/** * Check if unit eligible for squaddie promotion. If yes, promote the unit. * Increase the mission counter. Calculate the experience increases. * @return True if the soldier was eligible for squaddie promotion. */ bool BattleUnit::postMissionProcedures(SavedGame *geoscape) { Soldier *s = geoscape->getSoldier(_id); if (s == 0) { return false; } s->addMissionCount(); s->addKillCount(_kills); UnitStats *stats = s->getCurrentStats(); int healthLoss = stats->health - _health; s->setWoundRecovery(RNG::generate((healthLoss*0.5),(healthLoss*1.5))); if (_expBravery && stats->bravery < 100) { if (_expBravery > RNG::generate(0,10)) stats->bravery += 10; } if (_expReactions && stats->reactions < 100) { stats->reactions += improveStat(_expReactions); } if (_expFiring && stats->firing < 120) { stats->firing += improveStat(_expFiring); } if (_expMelee && stats->melee < 120) { stats->melee += improveStat(_expMelee); } if (_expThrowing && stats->throwing < 120) { stats->throwing += improveStat(_expThrowing); } if (_expPsiSkill && stats->psiSkill < 100) { stats->psiSkill += improveStat(_expPsiSkill); } if (_expBravery || _expReactions || _expFiring || _expPsiSkill || _expMelee) { if (s->getRank() == RANK_ROOKIE) s->promoteRank(); int v; v = 80 - stats->tu; if (v > 0) stats->tu += RNG::generate(0, v/10 + 2); v = 60 - stats->health; if (v > 0) stats->health += RNG::generate(0, v/10 + 2); v = 70 - stats->strength; if (v > 0) stats->strength += RNG::generate(0, v/10 + 2); v = 100 - stats->stamina; if (v > 0) stats->stamina += RNG::generate(0, v/10 + 2); return true; } else { return false; } }
/** * Updates soldier stats when * the soldier changes. */ void SoldierInfoState::init() { if(_base->getSoldiers()->empty()) { _game->popState(); return; } if(_soldier == _base->getSoldiers()->size()) { _soldier = 0; } Soldier *s = _base->getSoldiers()->at(_soldier); _edtSoldier->setText(s->getName()); UnitStats *initial = s->getInitStats(); UnitStats *current = s->getCurrentStats(); SurfaceSet *texture = _game->getResourcePack()->getSurfaceSet("BASEBITS.PCK"); texture->getFrame(s->getRankSprite())->setX(0); texture->getFrame(s->getRankSprite())->setY(0); texture->getFrame(s->getRankSprite())->blit(_rank); std::wstringstream ss; ss << current->tu; _numTimeUnits->setText(ss.str()); _barTimeUnits->setMax(current->tu); _barTimeUnits->setValue(current->tu); _barTimeUnits->setValue2(initial->tu); std::wstringstream ss2; ss2 << current->stamina; _numStamina->setText(ss2.str()); _barStamina->setMax(current->stamina); _barStamina->setValue(current->stamina); _barStamina->setValue2(initial->stamina); std::wstringstream ss3; ss3 << current->health; _numHealth->setText(ss3.str()); _barHealth->setMax(current->health); _barHealth->setValue(current->health); _barHealth->setValue2(initial->health); std::wstringstream ss4; ss4 << current->bravery; _numBravery->setText(ss4.str()); _barBravery->setMax(current->bravery); _barBravery->setValue(current->bravery); _barBravery->setValue2(initial->bravery); std::wstringstream ss5; ss5 << current->reactions; _numReactions->setText(ss5.str()); _barReactions->setMax(current->reactions); _barReactions->setValue(current->reactions); _barReactions->setValue2(initial->reactions); std::wstringstream ss6; ss6 << current->firing; _numFiring->setText(ss6.str()); _barFiring->setMax(current->firing); _barFiring->setValue(current->firing); _barFiring->setValue2(initial->firing); std::wstringstream ss7; ss7 << current->throwing; _numThrowing->setText(ss7.str()); _barThrowing->setMax(current->throwing); _barThrowing->setValue(current->throwing); _barThrowing->setValue2(initial->throwing); std::wstringstream ss8; ss8 << current->strength; _numStrength->setText(ss8.str()); _barStrength->setMax(current->strength); _barStrength->setValue(current->strength); _barStrength->setValue2(initial->strength); std::wstring wsArmor; std::string armorType = s->getArmor()->getType(); if (armorType == "STR_NONE_UC") { wsArmor.reserve(15); wsArmor = tr("STR_ARMOR"); wsArmor += L"> "; wsArmor += tr(armorType); } else wsArmor = tr(armorType); _btnArmor->setText(wsArmor); // _txtArmor->setText(tr(s->getArmor()->getType())); _btnSack->setVisible(!(s->getCraft() && s->getCraft()->getStatus() == "STR_OUT")); std::wstringstream ss9; ss9 << tr("STR_RANK_") << L'\x01' << tr(s->getRankString()); _txtRank->setText(ss9.str()); std::wstringstream ss10; ss10 << tr("STR_MISSIONS") << L'\x01' << s->getMissions(); _txtMissions->setText(ss10.str()); std::wstringstream ss11; ss11 << tr("STR_KILLS") << L'\x01' << s->getKills(); _txtKills->setText(ss11.str()); std::wstringstream ss12; ss12 << tr("STR_CRAFT_") << L'\x01'; if (s->getCraft() == 0) ss12 << tr("STR_NONE_UC"); else ss12 << s->getCraft()->getName(_game->getLanguage()); _txtCraft->setText(ss12.str()); if (s->getWoundRecovery() > 0) { std::wstringstream ss13; ss13 << tr("STR_WOUND_RECOVERY") << L'\x01' << tr("STR_DAY", s->getWoundRecovery()); _txtRecovery->setText(ss13.str()); } else { _txtRecovery->setText(L""); } _txtPsionic->setVisible(s->isInPsiTraining()); if(current->psiSkill > 0) { std::wstringstream ss14; ss14 << current->psiStrength; _numPsiStrength->setText(ss14.str()); _barPsiStrength->setMax(current->psiStrength); _barPsiStrength->setValue(current->psiStrength); _barPsiStrength->setValue2(initial->psiStrength); std::wstringstream ss15; ss15 << current->psiSkill; _numPsiSkill->setText(ss15.str()); _barPsiSkill->setMax(current->psiSkill); _barPsiSkill->setValue(current->psiSkill); _barPsiSkill->setValue2(initial->psiSkill); _txtPsiStrength->setVisible(true); _numPsiStrength->setVisible(true); _barPsiStrength->setVisible(true); _txtPsiSkill->setVisible(true); _numPsiSkill->setVisible(true); _barPsiSkill->setVisible(true); } else { _txtPsiStrength->setVisible(false); _numPsiStrength->setVisible(false); _barPsiStrength->setVisible(false); _txtPsiSkill->setVisible(false); _numPsiSkill->setVisible(false); _barPsiSkill->setVisible(false); } }
/** * Initializes a new savegame with * everything available. */ void NewBattleState::initSave() { const Mod *mod = _game->getMod(); SavedGame *save = new SavedGame(); Base *base = new Base(mod); const YAML::Node &starter = _game->getMod()->getStartingBase(); base->load(starter, save, true, true); save->getBases()->push_back(base); // Kill everything we don't want in this base for (std::vector<Soldier*>::iterator i = base->getSoldiers()->begin(); i != base->getSoldiers()->end(); ++i) delete (*i); base->getSoldiers()->clear(); for (std::vector<Craft*>::iterator i = base->getCrafts()->begin(); i != base->getCrafts()->end(); ++i) delete (*i); base->getCrafts()->clear(); base->getStorageItems()->getContents()->clear(); _craft = new Craft(mod->getCraft(_crafts[_cbxCraft->getSelected()]), base, 1); base->getCrafts()->push_back(_craft); // Generate soldiers for (int i = 0; i < 30; ++i) { int randomType = RNG::generate(0, _game->getMod()->getSoldiersList().size() - 1); Soldier *soldier = mod->genSoldier(save, _game->getMod()->getSoldiersList().at(randomType)); for (int n = 0; n < 5; ++n) { if (RNG::percent(70)) continue; soldier->promoteRank(); UnitStats* stats = soldier->getCurrentStats(); stats->tu += RNG::generate(0, 5); stats->stamina += RNG::generate(0, 5); stats->health += RNG::generate(0, 5); stats->bravery += RNG::generate(0, 5); stats->reactions += RNG::generate(0, 5); stats->firing += RNG::generate(0, 5); stats->throwing += RNG::generate(0, 5); stats->strength += RNG::generate(0, 5); stats->psiStrength += RNG::generate(0, 5); stats->melee += RNG::generate(0, 5); stats->psiSkill += RNG::generate(0, 20); } UnitStats* stats = soldier->getCurrentStats(); stats->bravery = (int)ceil(stats->bravery / 10.0) * 10; // keep it a multiple of 10 base->getSoldiers()->push_back(soldier); if (i < _craft->getRules()->getSoldiers()) soldier->setCraft(_craft); } // Generate items const std::vector<std::string> &items = mod->getItemsList(); for (std::vector<std::string>::const_iterator i = items.begin(); i != items.end(); ++i) { RuleItem *rule = _game->getMod()->getItem(*i); if (rule->getBattleType() != BT_CORPSE && rule->isRecoverable()) { base->getStorageItems()->addItem(*i, 1); if (rule->getBattleType() != BT_NONE && !rule->isFixed() && rule->getBigSprite() > -1) { _craft->getItems()->addItem(*i, 1); } } } // Add research const std::vector<std::string> &research = mod->getResearchList(); for (std::vector<std::string>::const_iterator i = research.begin(); i != research.end(); ++i) { save->addFinishedResearchSimple(mod->getResearch(*i)); } _game->setSavedGame(save); cbxMissionChange(0); }