Beispiel #1
0
void SUnitStats::AddUnit(const CUnit* unit, bool enemy)
{
	const UnitDef* decoyDef = enemy ? unit->unitDef->decoyDef : nullptr;

	++count;

	if (!decoyDef) {
		health           += unit->health;
		maxHealth        += unit->maxHealth;
		experience        = (experience * (count - 1) + unit->experience) / count; // average xp
		cost             += unit->cost.metal + (unit->cost.energy / 60.0f);
		maxRange          = std::max(maxRange, unit->maxRange);
		metalMake        += unit->resourcesMake.metal;
		metalUse         += unit->resourcesUse.metal;
		energyMake       += unit->resourcesMake.energy;
		energyUse        += unit->resourcesUse.energy;
		harvestMetal     += unit->harvested.metal;
		harvestMetalMax  += unit->harvestStorage.metal;
		harvestEnergy    += unit->harvested.energy;
		harvestEnergyMax += unit->harvestStorage.energy;
	} else {
		// display adjusted decoy stats
		const float healthScale = (decoyDef->health / unit->unitDef->health);

		float metalMake_, metalUse_, energyMake_, energyUse_;
		GetDecoyResources(unit, metalMake_, metalUse_, energyMake_, energyUse_);

		health           += unit->health * healthScale;
		maxHealth        += unit->maxHealth * healthScale;
		experience        = (experience * (count - 1) + unit->experience) / count;
		cost             += decoyDef->metal + (decoyDef->energy / 60.0f);
		maxRange          = std::max(maxRange, decoyDef->maxWeaponRange);
		metalMake        += metalMake_;
		metalUse         += metalUse_;
		energyMake       += energyMake_;
		energyUse        += energyUse_;
		//harvestMetal     += unit->harvested.metal;
		//harvestMetalMax  += unit->harvestStorage.metal;
		//harvestEnergy    += unit->harvested.energy;
		//harvestEnergyMax += unit->harvestStorage.energy;
	}
}
Beispiel #2
0
std::string CTooltipConsole::MakeUnitString(const CUnit* unit)
{
	string custom = eventHandler.WorldTooltip(unit, NULL, NULL);
	if (!custom.empty()) {
		return custom;
	}

	std::string s;

	const bool enemyUnit = (teamHandler->AllyTeam(unit->team) != gu->myAllyTeam) &&
	                       !gu->spectatingFullView;

	const UnitDef* unitDef = unit->unitDef;
	const UnitDef* decoyDef = enemyUnit ? unitDef->decoyDef : NULL;
	const UnitDef* effectiveDef =
		!enemyUnit ? unitDef : (decoyDef ? decoyDef : unitDef);

	// don't show the unit type if it is not known
	const unsigned short losStatus = unit->losStatus[gu->myAllyTeam];
	const unsigned short prevMask = (LOS_PREVLOS | LOS_CONTRADAR);
	if (enemyUnit &&
	    !(losStatus & LOS_INLOS) &&
	    ((losStatus & prevMask) != prevMask)) {
		return "Enemy unit";
	}

	// show the player name instead of unit name if it has FBI tag showPlayerName
	if (effectiveDef->showPlayerName) {
		if (teamHandler->Team(unit->team)->leader >= 0) {
			s = playerHandler->Player(teamHandler->Team(unit->team)->leader)->name.c_str();
		} else {
			s = "Uncontrolled";
		}
	} else {
		if (!decoyDef) {
			s = unit->tooltip;
		} else {
			s = decoyDef->humanName + " - " + decoyDef->tooltip;
		}
	}

	// don't show the unit health and other info if it has
	// the FBI tag hideDamage and is not on our ally team or
	// is not in LOS
	if (!enemyUnit || (!effectiveDef->hideDamage && (losStatus & LOS_INLOS))) {
		if (!decoyDef) {
			const float cost = unit->metalCost + (unit->energyCost / 60.0f);
			s += MakeUnitStatsString(
						 unit->health, unit->maxHealth,
						 unit->currentFuel, unitDef->maxFuel,
						 unit->experience, cost, unit->maxRange,
						 unit->metalMake,  unit->metalUse,
						 unit->energyMake, unit->energyUse);
		} else {
			// display adjusted decoy stats
			const float cost = decoyDef->metalCost + (decoyDef->energyCost / 60.0f);
			const float healthScale = (decoyDef->health / unitDef->health);
			float fuelScale;
			if (unitDef->maxFuel > 0.0f) {
				fuelScale = (decoyDef->maxFuel / unitDef->maxFuel);
			} else {
				fuelScale = 0.0f;
			}

			// get the adjusted resource stats
			float metalMake, energyMake, metalUse, energyUse;
			GetDecoyResources(unit, metalMake, metalUse, energyMake, energyUse);

			s += MakeUnitStatsString(
						 unit->health * healthScale, unit->maxHealth * healthScale,
						 unit->currentFuel * fuelScale, decoyDef->maxFuel,
						 unit->experience, cost, decoyDef->maxWeaponRange,
						 metalMake,  metalUse,
						 energyMake, energyUse);
		}
	}

	if (gs->cheatEnabled) {
		char buf[32];
		SNPRINTF(buf, 32, DARKBLUE "  [TechLevel %i]", unit->unitDef->techLevel);
		s += buf;
	}

	return s;
}
std::string CTooltipConsole::MakeUnitString(const CUnit* unit)
{
	std::string s;

	const bool enemyUnit = (gs->AllyTeam(unit->team) != gu->myAllyTeam) &&
	                       !gu->spectatingFullView;

	const UnitDef* unitDef = unit->unitDef;
	const UnitDef* decoyDef = enemyUnit ? unitDef->decoyDef : NULL;
	const UnitDef* effectiveDef =
		!enemyUnit ? unitDef : (decoyDef ? decoyDef : unitDef);

	// don't show the tooltip if it's a radar dot
	if (enemyUnit && !loshandler->InLos(unit, gu->myAllyTeam)) {
		return "Enemy unit";
	}

	// show the player name instead of unit name if it has FBI tag showPlayerName
	if (effectiveDef->showPlayerName) {
		s = gs->players[gs->Team(unit->team)->leader]->playerName.c_str();
	} else {
		if (!decoyDef) {
			s = unit->tooltip;
		} else {
			s = decoyDef->humanName + " - " + decoyDef->tooltip;
		}
	}

	// don't show the unit health and other info if it has
	// the FBI tag hideDamage and is not on our ally team
	if (!enemyUnit || !effectiveDef->hideDamage) {
		if (!decoyDef) {
			const float cost = unit->metalCost + (unit->energyCost / 60.0f);
			s += MakeUnitStatsString(
						 unit->health, unit->maxHealth,
						 unit->currentFuel, unitDef->maxFuel,
						 unit->experience, cost, unit->maxRange,
						 unit->metalMake,  unit->metalUse,
						 unit->energyMake, unit->energyUse);
		} else {
			// display adjusted decoy stats
			const float cost = decoyDef->metalCost + (decoyDef->energyCost / 60.0f);
			const float healthScale = (decoyDef->health / unitDef->health);
			float fuelScale;
			if (unitDef->maxFuel > 0.0f) {
				fuelScale = (decoyDef->maxFuel / unitDef->maxFuel);
			} else {
				fuelScale = 0.0f;
			}

			// get the adjusted resource stats
			float metalMake, energyMake, metalUse, energyUse;
			GetDecoyResources(unit, metalMake, metalUse, energyMake, energyUse);

			s += MakeUnitStatsString(
						 unit->health * healthScale, unit->maxHealth * healthScale,
						 unit->currentFuel * fuelScale, decoyDef->maxFuel,
						 unit->experience, cost, decoyDef->maxWeaponRange,
						 metalMake,  metalUse,
						 energyMake, energyUse);
		}
	}

	if (gs->cheatEnabled) {
		char buf[32];
		SNPRINTF(buf, 32, DARKBLUE "  [TechLevel %i]", unit->unitDef->techLevel);
		s += buf;
	}

	return s;
}