コード例 #1
0
ファイル: BattleUnit.cpp プロジェクト: ben0x539/OpenXcom
/**
* 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;
	}
}
コード例 #2
0
ファイル: InventoryState.cpp プロジェクト: Xracer/OXCHD
/**
 * Updates all soldier stats when the soldier changes.
 */
void InventoryState::init()
{
	State::init();
	BattleUnit *unit = _battleGame->getSelectedUnit();

	// no selected unit, close inventory
	if (unit == 0)
	{
		btnOkClick(0);
		return;
	}
	// skip to the first unit with inventory
	if (!unit->hasInventory())
	{
		if (_parent)
		{
			_parent->selectNextPlayerUnit(false, false, true);
		}
		else
		{
			_battleGame->selectNextPlayerUnit(false, false, true);
		}
		// no available unit, close inventory
		if (_battleGame->getSelectedUnit() == 0 || !_battleGame->getSelectedUnit()->hasInventory())
		{
			// starting a mission with just vehicles
			btnOkClick(0);
			return;
		}
		else
		{
			unit = _battleGame->getSelectedUnit();
		}
	}

	unit->setCache(0);
	_soldier->clear();
	_rank->clear();

	_txtName->setBig();
	_txtName->setText(unit->getName(_game->getLanguage()));
	_inv->setSelectedUnit(unit);
	Soldier *s = unit->getGeoscapeSoldier();
	if (s)
	{
		SurfaceSet *texture = _game->getMod()->getSurfaceSet("SMOKE.PCK");
		texture->getFrame(20 + s->getRank())->setX(0);
		texture->getFrame(20 + s->getRank())->setY(0);
		texture->getFrame(20 + s->getRank())->blit(_rank);

		std::string look = s->getArmor()->getSpriteInventory();
		if (s->getGender() == GENDER_MALE)
			look += "M";
		else
			look += "F";
		if (s->getLook() == LOOK_BLONDE)
			look += "0";
		if (s->getLook() == LOOK_BROWNHAIR)
			look += "1";
		if (s->getLook() == LOOK_ORIENTAL)
			look += "2";
		if (s->getLook() == LOOK_AFRICAN)
			look += "3";
		look += ".SPK";
		const std::set<std::string> &ufographContents = FileMap::getVFolderContents("UFOGRAPH");
		std::string lcaseLook = look;
		std::transform(lcaseLook.begin(), lcaseLook.end(), lcaseLook.begin(), tolower);
		if (ufographContents.find("lcaseLook") == ufographContents.end() && !_game->getMod()->getSurface(look))
		{
			look = s->getArmor()->getSpriteInventory() + ".SPK";
		}
		_game->getMod()->getSurface(look)->blit(_soldier);
	}
	else
	{
		Surface *armorSurface = _game->getMod()->getSurface(unit->getArmor()->getSpriteInventory());
		if (armorSurface)
		{
			armorSurface->blit(_soldier);
		}
	}

	updateStats();
	_refreshMouse();
}
コード例 #3
0
ファイル: BattleUnit.cpp プロジェクト: Munkeylord/OpenXcom
/**
* 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;
	}
}