VehicleTileInfo ControlGenerator::createVehicleInfo(GameState &state, sp<Vehicle> v) { VehicleTileInfo t; t.vehicle = v; t.selected = UnitSelectionState::Unselected; for (auto &veh : state.current_city->cityViewSelectedVehicles) { if (veh == v) { t.selected = (veh == state.current_city->cityViewSelectedVehicles.front()) ? UnitSelectionState::FirstSelected : UnitSelectionState::Selected; break; } } float maxHealth; float currentHealth; if (v->getShield() != 0) { maxHealth = v->getMaxShield(); currentHealth = v->getShield(); t.shield = true; } else { maxHealth = v->getMaxHealth(); currentHealth = v->getHealth(); t.shield = false; } t.healthProportion = currentHealth / maxHealth; // Clamp passengers to 13 as anything beyond that gets the same icon t.passengers = std::min(13, v->getPassengers()); // Faded if in other dimension or if haven't left dimension gate yet t.faded = v->city != state.current_city || (!v->tileObject && !v->currentBuilding); auto b = v->currentBuilding; if (b) { if (b == v->homeBuilding) { t.state = CityUnitState::InBase; } else { t.state = CityUnitState::InBuilding; } } else { t.state = CityUnitState::InMotion; } return t; }
AgentInfo ControlGenerator::createAgentInfo(GameState &state, sp<Agent> a, UnitSelectionState forcedSelectionState, bool forceFade) { AgentInfo i; i.agent = a; i.selected = UnitSelectionState::Unselected; i.useRank = false; i.state = CityUnitState::InMotion; i.useState = false; i.faded = false; i.fatal = false; i.psiIn = false; i.psiOut = false; i.stunProportion = 0.0f; i.healthProportion = 0.0f; i.shield = false; if (!a) { return i; } // Rank only displayed on soldiers if (a->type->role == AgentType::Role::Soldier) { i.useRank = true; i.rank = a->rank; } // Check if this is not an special screen like AEquip if (forcedSelectionState == UnitSelectionState::NA) { // Select according to battle state if (a->unit) { for (auto &u : state.current_battle->battleViewSelectedUnits) { if (u->agent == a) { i.selected = (u == state.current_battle->battleViewSelectedUnits.front()) ? UnitSelectionState::FirstSelected : UnitSelectionState::Selected; break; } } } // Select according to city state else { for (auto &ag : state.current_city->cityViewSelectedAgents) { if (ag == a) { i.selected = (ag == state.current_city->cityViewSelectedAgents.front()) ? UnitSelectionState::FirstSelected : UnitSelectionState::Selected; break; } } } } else // This is a special screen { i.selected = forcedSelectionState; if (!a->unit) { i.faded = forceFade; } } // Set common agent state i.shield = a->getMaxShield(state) > 0; float maxHealth; float currentHealth; if (i.shield) { currentHealth = a->getShield(state); maxHealth = a->getMaxShield(state); } else { currentHealth = a->getHealth(); maxHealth = a->getMaxHealth(); } i.healthProportion = maxHealth == 0.0f ? 0.0f : currentHealth / maxHealth; // Set state that is used in battle if (a->unit) { // Stunned health if (!i.shield) { float stunHealth = a->unit->stunDamage; i.stunProportion = stunHealth / maxHealth; i.stunProportion = clamp(i.stunProportion, 0.0f, i.healthProportion); } // Fatal wounds i.fatal = a->unit->isFatallyWounded(); // Psi state i.psiOut = a->unit->psiTarget != nullptr; i.psiIn = !a->unit->psiAttackers.empty(); } // Set state that is used in city else { // City state icon i.useState = true; i.state = getCityUnitState(a); } return i; }