/** * This function is called when one of the mission's UFOs has finished it's time on the ground. * It takes care of sending the UFO to the next waypoint and marking them for removal as required. * It must set the game data in a way that the rest of the code understands what to do. * @param ufo The UFO that reached it's waypoint. * @param game The saved game information. * @param globe The earth globe, required to get access to land checks. */ void AlienMission::ufoLifting(Ufo &ufo, SavedGame &game, const Globe &globe) { switch (ufo.getStatus()) { case Ufo::FLYING: assert(0 && "Ufo is already on the air!"); break; case Ufo::LANDED: { // base missions only get points when they are completed. if (_rule.getPoints() > 0 && _rule.getObjective() != OBJECTIVE_BASE) { addScore(ufo.getLongitude(), ufo.getLatitude(), game); } ufo.setAltitude("STR_VERY_LOW"); ufo.setSpeed((int)(ufo.getRules()->getMaxSpeed() * ufo.getTrajectory().getSpeedPercentage(ufo.getTrajectoryPoint()))); } break; case Ufo::CRASHED: // Mission expired ufo.setDetected(false); ufo.setStatus(Ufo::DESTROYED); break; case Ufo::DESTROYED: assert(0 && "UFO can't fly!"); break; } }
/** * Enters the mission. * @param action Pointer to an action. */ void ConfirmLandingState::btnYesClick(Action *action) { _game->popState(); Ufo* u = dynamic_cast<Ufo*>(_craft->getDestination()); TerrorSite* t = dynamic_cast<TerrorSite*>(_craft->getDestination()); AlienBase* b = dynamic_cast<AlienBase*>(_craft->getDestination()); if (u != 0) { SavedBattleGame *bgame = new SavedBattleGame(); _game->getSavedGame()->setBattleGame(bgame); if(u->getStatus() == Ufo::CRASHED) bgame->setMissionType("STR_UFO_CRASH_RECOVERY"); else bgame->setMissionType("STR_UFO_GROUND_ASSAULT"); BattlescapeGenerator bgen = BattlescapeGenerator(_game); bgen.setWorldTexture(_texture); bgen.setWorldShade(_shade); bgen.setCraft(_craft); bgen.setUfo(u); bgen.setAlienRace(u->getAlienRace()); bgen.setAlienItemlevel(0); bgen.run(); _game->pushState(new BriefingState(_game, _craft)); } else if (t != 0) { SavedBattleGame *bgame = new SavedBattleGame(); _game->getSavedGame()->setBattleGame(bgame); bgame->setMissionType("STR_TERROR_MISSION"); BattlescapeGenerator bgen = BattlescapeGenerator(_game); bgen.setWorldTexture(_texture); bgen.setWorldShade(_shade); bgen.setCraft(_craft); bgen.setTerrorSite(t); bgen.setAlienRace(t->getAlienRace()); bgen.setAlienItemlevel(0); bgen.run(); _game->pushState(new BriefingState(_game, _craft)); } else if (b != 0) { SavedBattleGame *bgame = new SavedBattleGame(); _game->getSavedGame()->setBattleGame(bgame); bgame->setMissionType("STR_ALIEN_BASE_ASSAULT"); BattlescapeGenerator bgen = BattlescapeGenerator(_game); bgen.setWorldTexture(_texture); bgen.setWorldShade(_shade); bgen.setCraft(_craft); bgen.setAlienBase(b); bgen.setAlienRace(b->getAlienRace()); bgen.setAlienItemlevel(0); bgen.run(); _game->pushState(new BriefingState(_game, _craft)); } }
/** * This function is called when one of the mission's UFOs has finished it's time on the ground. * It takes care of sending the UFO to the next waypoint and marking them for removal as required. * It must set the game data in a way that the rest of the code understands what to do. * @param ufo The UFO that reached it's waypoint. * @param engine The game engine, required to get access to game data and game rules. * @param globe The earth globe, required to get access to land checks. */ void AlienMission::ufoLifting(Ufo &ufo, Game &engine, const Globe &globe) { const Ruleset &rules = *engine.getRuleset(); switch (ufo.getStatus()) { case Ufo::FLYING: assert(0 && "Ufo is already on the air!"); break; case Ufo::LANDED: { if ((ufo.getRules()->getType() == "STR_HARVESTER" && _rule.getType() == "STR_ALIEN_HARVEST") || (ufo.getRules()->getType() == "STR_ABDUCTOR" && _rule.getType() == "STR_ALIEN_ABDUCTION")) { addScore(ufo.getLongitude(), ufo.getLatitude(), engine); } assert(ufo.getTrajectoryPoint() != ufo.getTrajectory().getWaypointCount() - 1); ufo.setSpeed((int)(ufo.getRules()->getMaxSpeed() * ufo.getTrajectory().getSpeedPercentage(ufo.getTrajectoryPoint()))); ufo.setAltitude("STR_VERY_LOW"); // Set next waypoint. Waypoint *wp = new Waypoint(); RuleRegion *region = rules.getRegion(_region); std::pair<double, double> pos; if (ufo.getTrajectory().getAltitude(ufo.getTrajectoryPoint() + 1) == "STR_GROUND") { pos = getLandPoint(globe, *region, ufo.getTrajectory().getZone(ufo.getTrajectoryPoint() + 1)); } else { pos = region->getRandomPoint(ufo.getTrajectory().getZone(ufo.getTrajectoryPoint() + 1)); } wp->setLongitude(pos.first); wp->setLatitude(pos.second); ufo.setDestination(wp); ufo.setTrajectoryPoint(ufo.getTrajectoryPoint() + 1); } break; case Ufo::CRASHED: // Mission expired ufo.setDetected(false); ufo.setStatus(Ufo::DESTROYED); break; case Ufo::DESTROYED: assert(0 && "UFO can't fly!"); break; } }
/** * Enters the mission. * @param action Pointer to an action. */ void ConfirmLandingState::btnYesClick(Action *) { _game->popState(); _state->musicStop(); Ufo* u = dynamic_cast<Ufo*>(_craft->getDestination()); TerrorSite* t = dynamic_cast<TerrorSite*>(_craft->getDestination()); AlienBase* b = dynamic_cast<AlienBase*>(_craft->getDestination()); size_t month = _game->getSavedGame()->getMonthsPassed(); if (month > _game->getRuleset()->getAlienItemLevels().size()-1) month = _game->getRuleset()->getAlienItemLevels().size()-1; SavedBattleGame *bgame = new SavedBattleGame(); _game->getSavedGame()->setBattleGame(bgame); BattlescapeGenerator bgen = BattlescapeGenerator(_game); bgen.setWorldTexture(_texture); bgen.setWorldShade(_shade); bgen.setCraft(_craft); if (u != 0) { if(u->getStatus() == Ufo::CRASHED) bgame->setMissionType("STR_UFO_CRASH_RECOVERY"); else bgame->setMissionType("STR_UFO_GROUND_ASSAULT"); bgen.setUfo(u); bgen.setAlienRace(u->getAlienRace()); } else if (t != 0) { bgame->setMissionType("STR_TERROR_MISSION"); bgen.setTerrorSite(t); bgen.setAlienRace(t->getAlienRace()); } else if (b != 0) { bgame->setMissionType("STR_ALIEN_BASE_ASSAULT"); bgen.setAlienBase(b); bgen.setAlienRace(b->getAlienRace()); } else { throw Exception("No mission available!"); } bgen.setAlienItemlevel(_game->getRuleset()->getAlienItemLevels().at(month).at(RNG::generate(0,9))); bgen.run(); _game->pushState(new BriefingState(_game, _craft)); }
/** * This function is called when one of the mission's UFOs is shot down (crashed or destroyed). * Currently the only thing that happens is delaying the next UFO in the mission sequence. * @param ufo The UFO that was shot down. * @param engine The game engine, unused for now. * @param globe The earth globe, unused for now. */ void AlienMission::ufoShotDown(Ufo &ufo, Game &, const Globe &) { switch (ufo.getStatus()) { case Ufo::FLYING: case Ufo::LANDED: assert(0 && "Ufo seems ok!"); break; case Ufo::CRASHED: case Ufo::DESTROYED: if (_nextWave != _rule.getWaveCount()) { // Delay next wave _spawnCountdown += 30 * (RNG::generate(0, 48) + 400); } break; } }
/** * Enters the mission. * @param action Pointer to an action. */ void ConfirmLandingState::btnYesClick(Action *) { _game->popState(); Ufo* u = dynamic_cast<Ufo*>(_craft->getDestination()); MissionSite* m = dynamic_cast<MissionSite*>(_craft->getDestination()); AlienBase* b = dynamic_cast<AlienBase*>(_craft->getDestination()); SavedBattleGame *bgame = new SavedBattleGame(); _game->getSavedGame()->setBattleGame(bgame); BattlescapeGenerator bgen(_game); bgen.setWorldTexture(_texture); bgen.setWorldShade(_shade); bgen.setCraft(_craft); if (u != 0) { if (u->getStatus() == Ufo::CRASHED) bgame->setMissionType("STR_UFO_CRASH_RECOVERY"); else bgame->setMissionType("STR_UFO_GROUND_ASSAULT"); bgen.setUfo(u); bgen.setAlienRace(u->getAlienRace()); } else if (m != 0) { bgame->setMissionType(m->getDeployment()->getType()); bgen.setMissionSite(m); bgen.setAlienRace(m->getAlienRace()); } else if (b != 0) { bgame->setMissionType(b->getDeployment()->getType()); bgen.setAlienBase(b); bgen.setAlienRace(b->getAlienRace()); bgen.setWorldTexture(0); } else { throw Exception("No mission available!"); } bgen.run(); _game->pushState(new BriefingState(_craft)); }
/** * Initializes all the elements in the Geoscape Craft window. * @param game Pointer to the core game. * @param craft Pointer to the craft to display. * @param globe Pointer to the Geoscape globe. * @param waypoint Pointer to the last UFO position (if redirecting the craft). */ GeoscapeCraftState::GeoscapeCraftState(Game *game, Craft *craft, Globe *globe, Waypoint *waypoint) : State(game), _craft(craft), _globe(globe), _waypoint(waypoint) { _screen = false; // Create objects _window = new Window(this, 240, 184, 8, 8, POPUP_BOTH); _btnBase = new TextButton(192, 12, 32, 124); _btnTarget = new TextButton(192, 12, 32, 140); _btnPatrol = new TextButton(192, 12, 32, 156); _btnCancel = new TextButton(192, 12, 32, 172); _txtTitle = new Text(200, 17, 32, 20); _txtStatus = new Text(210, 17, 32, 36); _txtBase = new Text(200, 9, 32, 52); _txtSpeed = new Text(200, 9, 32, 60); _txtMaxSpeed = new Text(200, 9, 32, 68); _txtAltitude = new Text(200, 9, 32, 76); _txtFuel = new Text(120, 9, 32, 84); _txtDamage = new Text(75, 9, 164, 84); _txtW1Name = new Text(120, 9, 32, 92); _txtW1Ammo = new Text(80, 9, 164, 92); _txtW2Name = new Text(120, 9, 32, 100); _txtW2Ammo = new Text(80, 9, 164, 100); _txtRedirect = new Text(230, 17, 13, 108); _txtSoldier = new Text(60, 9, 164, 68); _txtHWP = new Text(80, 9, 164, 76); // Set palette _game->setPalette(_game->getResourcePack()->getPalette("BACKPALS.DAT")->getColors(Palette::blockOffset(4)), Palette::backPos, 16); add(_window); add(_btnBase); add(_btnTarget); add(_btnPatrol); add(_btnCancel); add(_txtTitle); add(_txtStatus); add(_txtBase); add(_txtSpeed); add(_txtMaxSpeed); add(_txtAltitude); add(_txtFuel); add(_txtDamage); add(_txtW1Name); add(_txtW1Ammo); add(_txtW2Name); add(_txtW2Ammo); add(_txtRedirect); add(_txtSoldier); add(_txtHWP); centerAllSurfaces(); // Set up objects _window->setColor(Palette::blockOffset(15)-1); _window->setBackground(_game->getResourcePack()->getSurface("BACK12.SCR")); _btnBase->setColor(Palette::blockOffset(8)+5); _btnBase->setText(tr("STR_RETURN_TO_BASE")); _btnBase->onMouseClick((ActionHandler)&GeoscapeCraftState::btnBaseClick); _btnTarget->setColor(Palette::blockOffset(8)+5); _btnTarget->setText(tr("STR_SELECT_NEW_TARGET")); _btnTarget->onMouseClick((ActionHandler)&GeoscapeCraftState::btnTargetClick); _btnPatrol->setColor(Palette::blockOffset(8)+5); _btnPatrol->setText(tr("STR_PATROL")); _btnPatrol->onMouseClick((ActionHandler)&GeoscapeCraftState::btnPatrolClick); _btnCancel->setColor(Palette::blockOffset(8)+5); _btnCancel->setText(tr("STR_CANCEL_UC")); _btnCancel->onMouseClick((ActionHandler)&GeoscapeCraftState::btnCancelClick); _btnCancel->onKeyboardPress((ActionHandler)&GeoscapeCraftState::btnCancelClick, (SDLKey)Options::getInt("keyCancel")); _txtTitle->setColor(Palette::blockOffset(15)-1); _txtTitle->setBig(); _txtTitle->setText(_craft->getName(_game->getLanguage())); _txtStatus->setColor(Palette::blockOffset(15)-1); _txtStatus->setSecondaryColor(Palette::blockOffset(8)+10); _txtStatus->setWordWrap(true); std::wstring status; if (_waypoint != 0) { status = tr("STR_INTERCEPTING_UFO").arg(_waypoint->getId()); } else if (_craft->getLowFuel()) { status = tr("STR_LOW_FUEL_RETURNING_TO_BASE"); } else if (_craft->getDestination() == 0) { status = tr("STR_PATROLLING"); } else if (_craft->getDestination() == (Target*)_craft->getBase()) { status = tr("STR_RETURNING_TO_BASE"); } else { Ufo *u = dynamic_cast<Ufo*>(_craft->getDestination()); if (u != 0) { if (_craft->isInDogfight()) { status = tr("STR_TAILING_UFO"); } else if (u->getStatus() == Ufo::FLYING) { status = tr("STR_INTERCEPTING_UFO").arg(u->getId()); } else { status = tr("STR_DESTINATION_UC_").arg(u->getName(_game->getLanguage())); } } else { status = tr("STR_DESTINATION_UC_").arg(_craft->getDestination()->getName(_game->getLanguage())); } } _txtStatus->setText(tr("STR_STATUS_").arg(status)); _txtBase->setColor(Palette::blockOffset(15)-1); _txtBase->setSecondaryColor(Palette::blockOffset(8)+5); _txtBase->setText(tr("STR_BASE_UC").arg(_craft->getBase()->getName())); _txtSpeed->setColor(Palette::blockOffset(15)-1); _txtSpeed->setSecondaryColor(Palette::blockOffset(8)+5); _txtSpeed->setText(tr("STR_SPEED_").arg(Text::formatNumber(_craft->getSpeed()))); _txtMaxSpeed->setColor(Palette::blockOffset(15)-1); _txtMaxSpeed->setSecondaryColor(Palette::blockOffset(8)+5); _txtMaxSpeed->setText(tr("STR_MAXIMUM_SPEED_UC").arg(Text::formatNumber(_craft->getRules()->getMaxSpeed()))); _txtAltitude->setColor(Palette::blockOffset(15)-1); _txtAltitude->setSecondaryColor(Palette::blockOffset(8)+5); std::string altitude = _craft->getAltitude() == "STR_GROUND" ? "STR_GROUNDED" : _craft->getAltitude(); _txtAltitude->setText(tr("STR_ALTITUDE_").arg(tr(altitude))); _txtFuel->setColor(Palette::blockOffset(15)-1); _txtFuel->setSecondaryColor(Palette::blockOffset(8)+5); _txtFuel->setText(tr("STR_FUEL").arg(Text::formatPercentage(_craft->getFuelPercentage()))); _txtDamage->setColor(Palette::blockOffset(15)-1); _txtDamage->setSecondaryColor(Palette::blockOffset(8)+5); _txtDamage->setText(tr("STR_DAMAGE_UC_").arg(Text::formatPercentage(_craft->getDamagePercentage()))); _txtW1Name->setColor(Palette::blockOffset(15)-1); _txtW1Name->setSecondaryColor(Palette::blockOffset(8)+5); _txtW1Ammo->setColor(Palette::blockOffset(15)-1); _txtW1Ammo->setSecondaryColor(Palette::blockOffset(8)+5); if (_craft->getRules()->getWeapons() > 0 && _craft->getWeapons()->at(0) != 0) { CraftWeapon *w1 = _craft->getWeapons()->at(0); _txtW1Name->setText(tr("STR_WEAPON_ONE").arg(tr(w1->getRules()->getType()))); _txtW1Ammo->setText(tr("STR_ROUNDS_").arg(w1->getAmmo())); } else { _txtW1Name->setText(tr("STR_WEAPON_ONE").arg(tr("STR_NONE_UC"))); _txtW1Ammo->setVisible(false); } _txtW2Name->setColor(Palette::blockOffset(15)-1); _txtW2Name->setSecondaryColor(Palette::blockOffset(8)+5); _txtW2Ammo->setColor(Palette::blockOffset(15)-1); _txtW2Ammo->setSecondaryColor(Palette::blockOffset(8)+5); if (_craft->getRules()->getWeapons() > 1 && _craft->getWeapons()->at(1) != 0) { CraftWeapon *w2 = _craft->getWeapons()->at(1); _txtW2Name->setText(tr("STR_WEAPON_TWO").arg(tr(w2->getRules()->getType()))); _txtW2Ammo->setText(tr("STR_ROUNDS_").arg(w2->getAmmo())); } else { _txtW2Name->setText(tr("STR_WEAPON_TWO").arg(tr("STR_NONE_UC"))); _txtW2Ammo->setVisible(false); } _txtRedirect->setColor(Palette::blockOffset(15)-1); _txtRedirect->setBig(); _txtRedirect->setAlign(ALIGN_CENTER); _txtRedirect->setText(tr("STR_REDIRECT_CRAFT")); _txtSoldier->setColor(Palette::blockOffset(15)-1); _txtSoldier->setSecondaryColor(Palette::blockOffset(8)+5); std::wstringstream ss11; ss11 << tr("STR_SOLDIERS_UC") << ">" << L'\x01' << _craft->getNumSoldiers(); _txtSoldier->setText(ss11.str()); _txtHWP->setColor(Palette::blockOffset(15)-1); _txtHWP->setSecondaryColor(Palette::blockOffset(8)+5); std::wstringstream ss12; ss12 << tr("STR_HWPS") << ">" << L'\x01' << _craft->getNumVehicles(); _txtHWP->setText(ss12.str()); if (_waypoint == 0) { _txtRedirect->setVisible(false); } else { _btnCancel->setText(tr("STR_GO_TO_LAST_KNOWN_UFO_POSITION")); } if (_craft->getLowFuel()) { _btnBase->setVisible(false); _btnTarget->setVisible(false); _btnPatrol->setVisible(false); } if (_craft->getRules()->getSoldiers() == 0) _txtSoldier->setVisible(false); if (_craft->getRules()->getVehicles() == 0) _txtHWP->setVisible(false); }
/** * Initializes all the elements in the Geoscape Craft window. * @param game Pointer to the core game. * @param craft Pointer to the craft to display. * @param globe Pointer to the Geoscape globe. * @param waypoint Pointer to the last UFO position (if redirecting the craft). */ GeoscapeCraftState::GeoscapeCraftState(Craft *craft, Globe *globe, Waypoint *waypoint) : _craft(craft), _globe(globe), _waypoint(waypoint) { _screen = false; // Create objects _window = new Window(this, 240, 184, 8, 8, POPUP_BOTH); _btnBase = new TextButton(212, 12, 22, 124); _btnTarget = new TextButton(212, 12, 22, 140); _btnPatrol = new TextButton(212, 12, 22, 156); _btnCancel = new TextButton(212, 12, 22, 172); _txtTitle = new Text(210, 17, 32, 20); _txtStatus = new Text(210, 17, 32, 36); _txtBase = new Text(210, 9, 32, 52); _txtSpeed = new Text(210, 9, 32, 60); _txtMaxSpeed = new Text(210, 9, 32, 68); _txtAltitude = new Text(210, 9, 32, 76); _txtFuel = new Text(130, 9, 32, 84); _txtDamage = new Text(80, 9, 164, 84); _txtW1Name = new Text(130, 9, 32, 92); _txtW1Ammo = new Text(80, 9, 164, 92); _txtW2Name = new Text(130, 9, 32, 100); _txtW2Ammo = new Text(80, 9, 164, 100); _txtRedirect = new Text(230, 17, 13, 108); _txtSoldier = new Text(60, 9, 164, 68); _txtHWP = new Text(80, 9, 164, 76); // Set palette setInterface("geoCraft"); add(_window, "window", "geoCraft"); add(_btnBase, "button", "geoCraft"); add(_btnTarget, "button", "geoCraft"); add(_btnPatrol, "button", "geoCraft"); add(_btnCancel, "button", "geoCraft"); add(_txtTitle, "text1", "geoCraft"); add(_txtStatus, "text1", "geoCraft"); add(_txtBase, "text3", "geoCraft"); add(_txtSpeed, "text3", "geoCraft"); add(_txtMaxSpeed, "text3", "geoCraft"); add(_txtAltitude, "text3", "geoCraft"); add(_txtFuel, "text3", "geoCraft"); add(_txtDamage, "text3", "geoCraft"); add(_txtW1Name, "text3", "geoCraft"); add(_txtW1Ammo, "text3", "geoCraft"); add(_txtW2Name, "text3", "geoCraft"); add(_txtW2Ammo, "text3", "geoCraft"); add(_txtRedirect, "text3", "geoCraft"); add(_txtSoldier, "text3", "geoCraft"); add(_txtHWP, "text3", "geoCraft"); centerAllSurfaces(); // Set up objects _window->setBackground(_game->getMod()->getSurface("BACK12.SCR")); _btnBase->setText(tr("STR_RETURN_TO_BASE")); _btnBase->onMouseClick((ActionHandler)&GeoscapeCraftState::btnBaseClick); _btnTarget->setText(tr("STR_SELECT_NEW_TARGET")); _btnTarget->onMouseClick((ActionHandler)&GeoscapeCraftState::btnTargetClick); _btnPatrol->setText(tr("STR_PATROL")); _btnPatrol->onMouseClick((ActionHandler)&GeoscapeCraftState::btnPatrolClick); _btnCancel->setText(tr("STR_CANCEL_UC")); _btnCancel->onMouseClick((ActionHandler)&GeoscapeCraftState::btnCancelClick); _btnCancel->onKeyboardPress((ActionHandler)&GeoscapeCraftState::btnCancelClick, Options::keyCancel); _txtTitle->setBig(); _txtTitle->setText(_craft->getName(_game->getLanguage())); _txtStatus->setWordWrap(true); std::wstring status; if (_waypoint != 0) { status = tr("STR_INTERCEPTING_UFO").arg(_waypoint->getId()); } else if (_craft->getLowFuel()) { status = tr("STR_LOW_FUEL_RETURNING_TO_BASE"); } else if (_craft->getMissionComplete()) { status = tr("STR_MISSION_COMPLETE_RETURNING_TO_BASE"); } else if (_craft->getDestination() == 0) { status = tr("STR_PATROLLING"); } else if (_craft->getDestination() == (Target*)_craft->getBase()) { status = tr("STR_RETURNING_TO_BASE"); } else { Ufo *u = dynamic_cast<Ufo*>(_craft->getDestination()); if (u != 0) { if (_craft->isInDogfight()) { status = tr("STR_TAILING_UFO"); } else if (u->getStatus() == Ufo::FLYING) { status = tr("STR_INTERCEPTING_UFO").arg(u->getId()); } else { status = tr("STR_DESTINATION_UC_").arg(u->getName(_game->getLanguage())); } } else { status = tr("STR_DESTINATION_UC_").arg(_craft->getDestination()->getName(_game->getLanguage())); } } _txtStatus->setText(tr("STR_STATUS_").arg(status)); _txtBase->setText(tr("STR_BASE_UC").arg(_craft->getBase()->getName())); int speed = _craft->getSpeed(); if (_craft->isInDogfight()) { Ufo *ufo = dynamic_cast<Ufo*>(_craft->getDestination()); if (ufo) { speed = ufo->getSpeed(); } } _txtSpeed->setText(tr("STR_SPEED_").arg(Text::formatNumber(speed))); _txtMaxSpeed->setText(tr("STR_MAXIMUM_SPEED_UC").arg(Text::formatNumber(_craft->getRules()->getMaxSpeed()))); std::string altitude = _craft->getAltitude() == "STR_GROUND" ? "STR_GROUNDED" : _craft->getAltitude(); if (_craft->getRules()->isWaterOnly() && !_globe->insideLand(_craft->getLongitude(), _craft->getLatitude())) { altitude = "STR_AIRBORNE"; } _txtAltitude->setText(tr("STR_ALTITUDE_").arg(tr(altitude))); _txtFuel->setText(tr("STR_FUEL").arg(Text::formatPercentage(_craft->getFuelPercentage()))); _txtDamage->setText(tr("STR_DAMAGE_UC_").arg(Text::formatPercentage(_craft->getDamagePercentage()))); if (_craft->getRules()->getWeapons() > 0 && _craft->getWeapons()->at(0) != 0) { CraftWeapon *w1 = _craft->getWeapons()->at(0); _txtW1Name->setText(tr("STR_WEAPON_ONE").arg(tr(w1->getRules()->getType()))); _txtW1Ammo->setText(tr("STR_ROUNDS_").arg(w1->getAmmo())); } else { _txtW1Name->setText(tr("STR_WEAPON_ONE").arg(tr("STR_NONE_UC"))); _txtW1Ammo->setVisible(false); } if (_craft->getRules()->getWeapons() > 1 && _craft->getWeapons()->at(1) != 0) { CraftWeapon *w2 = _craft->getWeapons()->at(1); _txtW2Name->setText(tr("STR_WEAPON_TWO").arg(tr(w2->getRules()->getType()))); _txtW2Ammo->setText(tr("STR_ROUNDS_").arg(w2->getAmmo())); } else { _txtW2Name->setText(tr("STR_WEAPON_TWO").arg(tr("STR_NONE_UC"))); _txtW2Ammo->setVisible(false); } _txtRedirect->setBig(); _txtRedirect->setAlign(ALIGN_CENTER); _txtRedirect->setText(tr("STR_REDIRECT_CRAFT")); std::wostringstream ss11; ss11 << tr("STR_SOLDIERS_UC") << ">" << L'\x01' << _craft->getNumSoldiers(); _txtSoldier->setText(ss11.str()); std::wostringstream ss12; ss12 << tr("STR_HWPS") << ">" << L'\x01' << _craft->getNumVehicles(); _txtHWP->setText(ss12.str()); if (_waypoint == 0) { _txtRedirect->setVisible(false); } else { _btnCancel->setText(tr("STR_GO_TO_LAST_KNOWN_UFO_POSITION")); } if (_craft->getLowFuel() || _craft->getMissionComplete()) { _btnBase->setVisible(false); _btnTarget->setVisible(false); _btnPatrol->setVisible(false); } if (_craft->getRules()->getSoldiers() == 0) _txtSoldier->setVisible(false); if (_craft->getRules()->getVehicles() == 0) _txtHWP->setVisible(false); }
/** * Initializes all the elements in the Geoscape Craft window. * @param game Pointer to the core game. * @param craft Pointer to the craft to display. * @param globe Pointer to the Geoscape globe. * @param waypoint Pointer to the last UFO position (if redirecting the craft). */ GeoscapeCraftState::GeoscapeCraftState(Game *game, Craft *craft, Globe *globe, Waypoint *waypoint) : State(game), _craft(craft), _globe(globe), _waypoint(waypoint) { _screen = false; // Create objects _window = new Window(this, 240, 184, 8, 8, POPUP_BOTH); _btnBase = new TextButton(192, 12, 32, 124); _btnTarget = new TextButton(192, 12, 32, 140); _btnPatrol = new TextButton(192, 12, 32, 156); _btnCancel = new TextButton(192, 12, 32, 172); _txtTitle = new Text(200, 16, 32, 20); _txtStatus = new Text(200, 9, 32, 36); _txtBase = new Text(200, 9, 32, 52); _txtSpeed = new Text(200, 9, 32, 60); _txtMaxSpeed = new Text(200, 9, 32, 68); _txtAltitude = new Text(200, 9, 32, 76); _txtFuel = new Text(120, 9, 32, 84); _txtDamage = new Text(75, 9, 164, 84); _txtW1Name = new Text(120, 9, 32, 92); _txtW1Ammo = new Text(60, 9, 164, 92); _txtW2Name = new Text(120, 9, 32, 100); _txtW2Ammo = new Text(60, 9, 164, 100); _txtRedirect = new Text(230, 16, 13, 108); // Set palette _game->setPalette(_game->getResourcePack()->getPalette("BACKPALS.DAT")->getColors(Palette::blockOffset(4)), Palette::backPos, 16); add(_window); add(_btnBase); add(_btnTarget); add(_btnPatrol); add(_btnCancel); add(_txtTitle); add(_txtStatus); add(_txtBase); add(_txtSpeed); add(_txtMaxSpeed); add(_txtAltitude); add(_txtFuel); add(_txtDamage); add(_txtW1Name); add(_txtW1Ammo); add(_txtW2Name); add(_txtW2Ammo); add(_txtRedirect); // Set up objects _window->setColor(Palette::blockOffset(15)-1); _window->setBackground(_game->getResourcePack()->getSurface("BACK12.SCR")); _btnBase->setColor(Palette::blockOffset(8)+5); _btnBase->setText(_game->getLanguage()->getString("STR_RETURN_TO_BASE")); _btnBase->onMouseClick((ActionHandler)&GeoscapeCraftState::btnBaseClick); _btnTarget->setColor(Palette::blockOffset(8)+5); _btnTarget->setText(_game->getLanguage()->getString("STR_SELECT_NEW_TARGET")); _btnTarget->onMouseClick((ActionHandler)&GeoscapeCraftState::btnTargetClick); _btnPatrol->setColor(Palette::blockOffset(8)+5); _btnPatrol->setText(_game->getLanguage()->getString("STR_PATROL")); _btnPatrol->onMouseClick((ActionHandler)&GeoscapeCraftState::btnPatrolClick); _btnCancel->setColor(Palette::blockOffset(8)+5); _btnCancel->setText(_game->getLanguage()->getString("STR_CANCEL_UC")); _btnCancel->onMouseClick((ActionHandler)&GeoscapeCraftState::btnCancelClick); _txtTitle->setColor(Palette::blockOffset(15)-1); _txtTitle->setBig(); _txtTitle->setText(_craft->getName(_game->getLanguage())); _txtStatus->setColor(Palette::blockOffset(15)-1); _txtStatus->setSecondaryColor(Palette::blockOffset(8)+10); std::wstringstream ss; ss << _game->getLanguage()->getString("STR_STATUS_") << L'\x01'; if (_waypoint != 0) { ss << _game->getLanguage()->getString("STR_INTERCEPTING_UFO") << _waypoint->getId(); } else if (_craft->getLowFuel()) { ss << _game->getLanguage()->getString("STR_LOW_FUEL_RETURNING_TO_BASE"); } else if (_craft->getDestination() == 0) { ss << _game->getLanguage()->getString("STR_PATROLLING"); } else if (_craft->getDestination() == (Target*)_craft->getBase()) { ss << _game->getLanguage()->getString("STR_RETURNING_TO_BASE"); } else { Ufo *u = dynamic_cast<Ufo*>(_craft->getDestination()); if (u != 0) { if (u->getStatus() == Ufo::FLYING) { ss << _game->getLanguage()->getString("STR_INTERCEPTING_UFO") << u->getId(); } else { ss << _game->getLanguage()->getString("STR_DESTINATION_UC_") << u->getName(_game->getLanguage()); } } else { ss << _game->getLanguage()->getString("STR_DESTINATION_UC_") << _craft->getDestination()->getName(_game->getLanguage()); } } _txtStatus->setText(ss.str()); _txtBase->setColor(Palette::blockOffset(15)-1); _txtBase->setSecondaryColor(Palette::blockOffset(8)+5); std::wstringstream ss2; ss2 << _game->getLanguage()->getString("STR_BASE_UC_") << L'\x01' << _craft->getBase()->getName(); _txtBase->setText(ss2.str()); _txtSpeed->setColor(Palette::blockOffset(15)-1); _txtSpeed->setSecondaryColor(Palette::blockOffset(8)+5); std::wstringstream ss3; ss3 << _game->getLanguage()->getString("STR_SPEED_") << L'\x01' << _craft->getSpeed(); _txtSpeed->setText(ss3.str()); _txtMaxSpeed->setColor(Palette::blockOffset(15)-1); _txtMaxSpeed->setSecondaryColor(Palette::blockOffset(8)+5); std::wstringstream ss4; ss4 << _game->getLanguage()->getString("STR_MAXIMUM_SPEED_UC") << L'\x01' << _craft->getRules()->getMaxSpeed(); _txtMaxSpeed->setText(ss4.str()); _txtAltitude->setColor(Palette::blockOffset(15)-1); _txtAltitude->setSecondaryColor(Palette::blockOffset(8)+5); std::wstringstream ss5; ss5 << _game->getLanguage()->getString("STR_ALTITUDE_") << L'\x01' << _game->getLanguage()->getString(_craft->getAltitude()); _txtAltitude->setText(ss5.str()); _txtFuel->setColor(Palette::blockOffset(15)-1); _txtFuel->setSecondaryColor(Palette::blockOffset(8)+5); std::wstringstream ss6; ss6 << _game->getLanguage()->getString("STR_FUEL") << L'\x01' << _craft->getFuelPercentage() << "%"; _txtFuel->setText(ss6.str()); _txtDamage->setColor(Palette::blockOffset(15)-1); _txtDamage->setSecondaryColor(Palette::blockOffset(8)+5); std::wstringstream ss62; ss62 << _game->getLanguage()->getString("STR_DAMAGE_UC_") << L'\x01' << _craft->getDamagePercentage() << "%"; _txtDamage->setText(ss62.str()); _txtW1Name->setColor(Palette::blockOffset(15)-1); _txtW1Name->setSecondaryColor(Palette::blockOffset(8)+5); std::wstringstream ss7; ss7 << _game->getLanguage()->getString("STR_WEAPON_1") << L'\x01'; _txtW1Ammo->setColor(Palette::blockOffset(15)-1); _txtW1Ammo->setSecondaryColor(Palette::blockOffset(8)+5); std::wstringstream ss8; ss8 << _game->getLanguage()->getString("STR_ROUNDS_") << L'\x01'; if (_craft->getRules()->getWeapons() > 0 && _craft->getWeapons()->at(0) != 0) { CraftWeapon *w1 = _craft->getWeapons()->at(0); ss7 << _game->getLanguage()->getString(w1->getRules()->getType()); _txtW1Name->setText(ss7.str()); ss8 << w1->getAmmo(); _txtW1Ammo->setText(ss8.str()); } else { ss7 << _game->getLanguage()->getString("STR_NONE_UC"); _txtW1Name->setText(ss7.str()); _txtW1Ammo->setVisible(false); } _txtW2Name->setColor(Palette::blockOffset(15)-1); _txtW2Name->setSecondaryColor(Palette::blockOffset(8)+5); std::wstringstream ss9; ss9 << _game->getLanguage()->getString("STR_WEAPON_2") << L'\x01'; _txtW2Ammo->setColor(Palette::blockOffset(15)-1); _txtW2Ammo->setSecondaryColor(Palette::blockOffset(8)+5); std::wstringstream ss10; ss10 << _game->getLanguage()->getString("STR_ROUNDS_") << L'\x01'; if (_craft->getRules()->getWeapons() > 1 && _craft->getWeapons()->at(1) != 0) { CraftWeapon *w2 = _craft->getWeapons()->at(1); ss9 << _game->getLanguage()->getString(w2->getRules()->getType()); _txtW2Name->setText(ss9.str()); ss10 << w2->getAmmo(); _txtW2Ammo->setText(ss10.str()); } else { ss9 << _game->getLanguage()->getString("STR_NONE_UC"); _txtW2Name->setText(ss9.str()); _txtW2Ammo->setVisible(false); } _txtRedirect->setColor(Palette::blockOffset(15)-1); _txtRedirect->setBig(); _txtRedirect->setAlign(ALIGN_CENTER); _txtRedirect->setText(_game->getLanguage()->getString("STR_REDIRECT_CRAFT")); if (_waypoint == 0) { _txtRedirect->setVisible(false); } else { _btnCancel->setText(_game->getLanguage()->getString("STR_GO_TO_LAST_KNOWN_UFO_POSITION")); } if (_craft->getLowFuel()) { _btnBase->setVisible(false); _btnTarget->setVisible(false); _btnPatrol->setVisible(false); } }