本文整理汇总了C++中Ufo类的典型用法代码示例。如果您正苦于以下问题:C++ Ufo类的具体用法?C++ Ufo怎么用?C++ Ufo使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Ufo类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: switch
/**
* 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;
}
}
示例2: getAltitude
/**
* Returns the current altitude of the craft.
* @return Altitude.
*/
std::string Craft::getAltitude() const
{
Ufo *u = dynamic_cast<Ufo*>(_dest);
if (u && u->getAltitude() != "STR_GROUND")
{
return u->getAltitude();
}
else
{
return "STR_VERY_LOW";
}
}
示例3: detect
/**
* Returns if a certain target is detected by the craft's
* radar, taking in account the range and chance.
* @param target Pointer to target to compare.
* @return True if it's detected, False otherwise.
*/
bool Craft::detect(Target *target) const
{
if (_rules->getRadarRange() == 0 || !insideRadarRange(target))
return false;
// backward compatibility with vanilla
if (_rules->getRadarChance() == 100)
return true;
Ufo *u = dynamic_cast<Ufo*>(target);
int chance = _rules->getRadarChance() * (100 + u->getVisibility()) / 100;
return RNG::percent(chance);
}
示例4: SavedBattleGame
/**
* 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));
}
示例5: SavedBattleGame
/**
* 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));
}
示例6: switch
/**
* 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;
}
}
示例7: Waypoint
/**
* This function is called when one of the mission's UFOs arrives at it's current destination.
* It takes care of sending the UFO to the next waypoint, landing UFOs 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::ufoReachedWaypoint(Ufo &ufo, Game &engine, const Globe &globe)
{
const Ruleset &rules = *engine.getRuleset();
SavedGame &game = *engine.getSavedGame();
if (ufo.getTrajectoryPoint() == ufo.getTrajectory().getWaypointCount() - 1)
{
ufo.setDetected(false);
ufo.setStatus(Ufo::DESTROYED);
return;
}
ufo.setAltitude(ufo.getTrajectory().getAltitude(ufo.getTrajectoryPoint() + 1));
if (ufo.getAltitude() != "STR_GROUND")
{
if (ufo.getLandId() != 0)
{
ufo.setLandId(0);
}
ufo.setTrajectoryPoint(ufo.getTrajectoryPoint() + 1);
// Set next waypoint.
Waypoint *wp = new Waypoint();
RuleRegion *region = rules.getRegion(_region);
ufo.setSpeed((int)(ufo.getRules()->getMaxSpeed() * ufo.getTrajectory().getSpeedPercentage(ufo.getTrajectoryPoint())));
std::pair<double, double> pos;
if (ufo.getTrajectory().getAltitude(ufo.getTrajectoryPoint()) == "STR_GROUND")
{
pos = getLandPoint(globe, *region, ufo.getTrajectory().getZone(ufo.getTrajectoryPoint()));
}
else
{
pos = region->getRandomPoint(ufo.getTrajectory().getZone(ufo.getTrajectoryPoint()));
}
wp->setLongitude(pos.first);
wp->setLatitude(pos.second);
ufo.setDestination(wp);
}
else
{
// UFO landed.
if (ufo.getRules()->getType() == "STR_TERROR_SHIP" && _rule.getType() == "STR_ALIEN_TERROR" && ufo.getTrajectory().getZone(ufo.getTrajectoryPoint()) == 0)
{
// Specialized: STR_ALIEN_TERROR
// Remove UFO, replace with TerrorSite.
addScore(ufo.getLongitude(), ufo.getLatitude(), engine);
ufo.setStatus(Ufo::DESTROYED);
TerrorSite *terrorSite = new TerrorSite();
terrorSite->setLongitude(ufo.getLongitude());
terrorSite->setLatitude(ufo.getLatitude());
terrorSite->setId(game.getId("STR_TERROR_SITE"));
terrorSite->setSecondsRemaining(4 * 3600 + RNG::generate(0, 6) * 3600);
terrorSite->setAlienRace(_race);
const City *city = rules.locateCity(ufo.getLongitude(), ufo.getLatitude());
assert(city);
game.getTerrorSites()->push_back(terrorSite);
for (std::vector<Target*>::iterator t = ufo.getFollowers()->begin(); t != ufo.getFollowers()->end();)
{
Craft* c = dynamic_cast<Craft*>(*t);
if (c && c->getNumSoldiers() != 0)
{
c->setDestination(terrorSite);
t = ufo.getFollowers()->begin();
}
else
{
++t;
}
}
}
else if (_rule.getType() == "STR_ALIEN_RETALIATION" && ufo.getTrajectory().getID() == "__RETALIATION_ASSAULT_RUN")
{
// Ignore what the trajectory might say, this is a base assault.
// Remove UFO, replace with Base defense.
ufo.setDetected(false);
std::vector<Base *>::const_iterator found =
std::find_if(game.getBases()->begin(), game.getBases()->end(),
MatchBaseCoordinates(ufo.getLongitude(), ufo.getLatitude()));
if (found == game.getBases()->end())
{
ufo.setStatus(Ufo::DESTROYED);
// Only spawn mission if the base is still there.
return;
}
ufo.setDestination(*found);
}
else
{
// Set timer for UFO on the ground.
ufo.setSecondsRemaining(ufo.getTrajectory().groundTimer());
if (ufo.getDetected() && ufo.getLandId() == 0)
{
ufo.setLandId(engine.getSavedGame()->getId("STR_LANDING_SITE"));
//.........这里部分代码省略.........
示例8: FindMarkedXCOMBase
/**
* This function will spawn a UFO according the the mission rules.
* Some code is duplicated between cases, that's ok for now. It's on different
* code paths and the function is MUCH easier to read written this way.
* @param game The saved game information.
* @param ruleset The ruleset.
* @param globe The globe, for land checks.
* @param ufoRule The rule for the desired UFO.
* @param trajectory The rule for the desired trajectory.
* @return Pointer to the spawned UFO. If the mission does not desire to spawn a UFO, 0 is returned.
*/
Ufo *AlienMission::spawnUfo(const SavedGame &game, const Ruleset &ruleset, const Globe &globe, const RuleUfo &ufoRule, const UfoTrajectory &trajectory)
{
if (_rule.getType() == "STR_ALIEN_RETALIATION")
{
const RuleRegion ®ionRules = *ruleset.getRegion(_region);
std::vector<Base *>::const_iterator found =
std::find_if(game.getBases()->begin(), game.getBases()->end(),
FindMarkedXCOMBase(regionRules));
if (found != game.getBases()->end())
{
// Spawn a battleship straight for the XCOM base.
const RuleUfo &battleshipRule = *ruleset.getUfo("STR_BATTLESHIP");
const UfoTrajectory &assaultTrajectory = *ruleset.getUfoTrajectory("__RETALIATION_ASSAULT_RUN");
Ufo *ufo = new Ufo(const_cast<RuleUfo*>(&battleshipRule));
ufo->setMissionInfo(this, &assaultTrajectory);
std::pair<double, double> pos;
if (trajectory.getAltitude(0) == "STR_GROUND")
{
pos = getLandPoint(globe, regionRules, trajectory.getZone(0));
}
else
{
pos = regionRules.getRandomPoint(trajectory.getZone(0));
}
ufo->setAltitude(assaultTrajectory.getAltitude(0));
ufo->setSpeed(assaultTrajectory.getSpeedPercentage(0) * ufoRule.getMaxSpeed());
ufo->setLongitude(pos.first);
ufo->setLatitude(pos.second);
Waypoint *wp = new Waypoint();
wp->setLongitude((*found)->getLongitude());
wp->setLatitude((*found)->getLatitude());
ufo->setDestination(wp);
return ufo;
}
}
else if (_rule.getType() == "STR_ALIEN_SUPPLY")
{
Log(LOG_DEBUG) << __FILE__ << ':' << __LINE__ << ' ' << _base;
if (ufoRule.getType() == "STR_SUPPLY_SHIP" && !_base)
{
// No base to supply!
return 0;
}
// Our destination is always an alien base.
Ufo *ufo = new Ufo(const_cast<RuleUfo*>(&ufoRule));
ufo->setMissionInfo(this, &trajectory);
const RuleRegion ®ionRules = *ruleset.getRegion(_region);
std::pair<double, double> pos;
if (trajectory.getAltitude(0) == "STR_GROUND")
{
pos = getLandPoint(globe, regionRules, trajectory.getZone(0));
}
else
{
pos = regionRules.getRandomPoint(trajectory.getZone(0));
}
ufo->setAltitude(trajectory.getAltitude(0));
ufo->setSpeed(trajectory.getSpeedPercentage(0) * ufoRule.getMaxSpeed());
ufo->setLongitude(pos.first);
ufo->setLatitude(pos.second);
Waypoint *wp = new Waypoint();
if (trajectory.getAltitude(1) == "STR_GROUND")
{
if (ufoRule.getType() == "STR_SUPPLY_SHIP")
{
// Supply ships on supply missions land on bases, ignore trajectory zone.
pos.first = _base->getLongitude();
pos.second = _base->getLatitude();
}
else
{
// Other ships can land where they want.
pos = getLandPoint(globe, regionRules, trajectory.getZone(1));
}
}
else
{
pos = regionRules.getRandomPoint(trajectory.getZone(1));
}
wp->setLongitude(pos.first);
wp->setLatitude(pos.second);
ufo->setDestination(wp);
return ufo;
}
// Spawn according to sequence.
Ufo *ufo = new Ufo(const_cast<RuleUfo*>(&ufoRule));
ufo->setMissionInfo(this, &trajectory);
const RuleRegion ®ionRules = *ruleset.getRegion(_region);
std::pair<double, double> pos;
//.........这里部分代码省略.........
示例9: fin
/**
* Loads a saved game's contents from a YAML file.
* @note Assumes the saved game is blank.
* @param filename YAML filename.
* @param rule Ruleset for the saved game.
*/
void SavedGame::load(const std::string &filename, Ruleset *rule)
{
std::string s = Options::getUserFolder() + filename + ".sav";
std::ifstream fin(s.c_str());
if (!fin)
{
throw Exception("Failed to load savegame");
}
YAML::Parser parser(fin);
YAML::Node doc;
// Get brief save info
parser.GetNextDocument(doc);
std::string v;
doc["version"] >> v;
if (v != Options::getVersion())
{
throw Exception("Version mismatch");
}
_time->load(doc["time"]);
// Get full save data
parser.GetNextDocument(doc);
int a = 0;
doc["difficulty"] >> a;
_difficulty = (GameDifficulty)a;
doc["funds"] >> _funds;
for (YAML::Iterator i = doc["countries"].begin(); i != doc["countries"].end(); ++i)
{
std::string type;
(*i)["type"] >> type;
Country *c = new Country(rule->getCountry(type), false);
c->load(*i);
_countries.push_back(c);
}
for (YAML::Iterator i = doc["regions"].begin(); i != doc["regions"].end(); ++i)
{
std::string type;
(*i)["type"] >> type;
Region *r = new Region(rule->getRegion(type));
r->load(*i);
_regions.push_back(r);
}
for (YAML::Iterator i = doc["ufos"].begin(); i != doc["ufos"].end(); ++i)
{
std::string type;
(*i)["type"] >> type;
Ufo *u = new Ufo(rule->getUfo(type));
u->load(*i);
_ufos.push_back(u);
}
doc["craftId"] >> _craftId;
for (YAML::Iterator i = doc["waypoints"].begin(); i != doc["waypoints"].end(); ++i)
{
Waypoint *w = new Waypoint();
w->load(*i);
_waypoints.push_back(w);
}
doc["ufoId"] >> _ufoId;
doc["waypointId"] >> _waypointId;
doc["soldierId"] >> _soldierId;
for (YAML::Iterator i = doc["bases"].begin(); i != doc["bases"].end(); ++i)
{
Base *b = new Base(rule);
b->load(*i, this);
_bases.push_back(b);
}
for(YAML::Iterator it=doc["discovered"].begin();it!=doc["discovered"].end();++it)
{
std::string research;
*it >> research;
_discovered.push_back(rule->getResearchProject(research));
}
if (const YAML::Node *pName = doc.FindValue("battleGame"))
{
_battleGame = new SavedBattleGame();
_battleGame->load(*pName, rule, this);
}
fin.close();
}
示例10: State
/**
* 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(200, 9, 32, 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(_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)
{
//.........这里部分代码省略.........
示例11: save
/**
* Starts the battle.
* @param action Pointer to an action.
*/
void NewBattleState::btnOkClick(Action *)
{
save();
if (_missionTypes[_cbxMission->getSelected()] != "STR_BASE_DEFENSE" && _craft->getNumSoldiers() == 0 && _craft->getNumVehicles() == 0)
{
return;
}
SavedBattleGame *bgame = new SavedBattleGame();
_game->getSavedGame()->setBattleGame(bgame);
bgame->setMissionType(_missionTypes[_cbxMission->getSelected()]);
BattlescapeGenerator bgen = BattlescapeGenerator(_game);
Base *base = 0;
bgen.setTerrain(_game->getMod()->getTerrain(_terrainTypes[_cbxTerrain->getSelected()]));
// base defense
if (_missionTypes[_cbxMission->getSelected()] == "STR_BASE_DEFENSE")
{
base = _craft->getBase();
bgen.setBase(base);
_craft = 0;
}
// alien base
else if (_game->getMod()->getDeployment(bgame->getMissionType())->isAlienBase())
{
AlienBase *b = new AlienBase(_game->getMod()->getDeployment(bgame->getMissionType()));
b->setId(1);
b->setAlienRace(_alienRaces[_cbxAlienRace->getSelected()]);
_craft->setDestination(b);
bgen.setAlienBase(b);
_game->getSavedGame()->getAlienBases()->push_back(b);
}
// ufo assault
else if (_craft && _game->getMod()->getUfo(_missionTypes[_cbxMission->getSelected()]))
{
Ufo *u = new Ufo(_game->getMod()->getUfo(_missionTypes[_cbxMission->getSelected()]));
u->setId(1);
_craft->setDestination(u);
bgen.setUfo(u);
// either ground assault or ufo crash
if (RNG::generate(0,1) == 1)
{
u->setStatus(Ufo::LANDED);
bgame->setMissionType("STR_UFO_GROUND_ASSAULT");
}
else
{
u->setStatus(Ufo::CRASHED);
bgame->setMissionType("STR_UFO_CRASH_RECOVERY");
}
_game->getSavedGame()->getUfos()->push_back(u);
}
// mission site
else
{
const AlienDeployment *deployment = _game->getMod()->getDeployment(bgame->getMissionType());
const RuleAlienMission *mission = _game->getMod()->getAlienMission(_game->getMod()->getAlienMissionList().front()); // doesn't matter
MissionSite *m = new MissionSite(mission, deployment);
m->setId(1);
m->setAlienRace(_alienRaces[_cbxAlienRace->getSelected()]);
_craft->setDestination(m);
bgen.setMissionSite(m);
_game->getSavedGame()->getMissionSites()->push_back(m);
}
if (_craft)
{
_craft->setSpeed(0);
bgen.setCraft(_craft);
}
_game->getSavedGame()->setDifficulty((GameDifficulty)_cbxDifficulty->getSelected());
bgen.setWorldShade(_slrDarkness->getValue());
bgen.setAlienRace(_alienRaces[_cbxAlienRace->getSelected()]);
bgen.setAlienItemlevel(_slrAlienTech->getValue());
bgame->setDepth(_slrDepth->getValue());
bgen.run();
_game->popState();
_game->popState();
_game->pushState(new BriefingState(_craft, base));
_craft = 0;
}
示例12: State
//.........这里部分代码省略.........
_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);
示例13: _craft
//.........这里部分代码省略.........
_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();
}
示例14: getWaypoint
/**
* This function is called when one of the mission's UFOs arrives at it's current destination.
* It takes care of sending the UFO to the next waypoint, landing UFOs 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::ufoReachedWaypoint(Ufo &ufo, Game &engine, const Globe &globe)
{
const Ruleset &rules = *engine.getRuleset();
SavedGame &game = *engine.getSavedGame();
const size_t curWaypoint = ufo.getTrajectoryPoint();
const size_t nextWaypoint = curWaypoint + 1;
const UfoTrajectory &trajectory = ufo.getTrajectory();
int waveNumber = _nextWave - 1;
if (waveNumber < 0)
{
waveNumber = _rule.getWaveCount() - 1;
}
const MissionWave &wave = _rule.getWave(waveNumber);
if (nextWaypoint >= trajectory.getWaypointCount())
{
ufo.setDetected(false);
ufo.setStatus(Ufo::DESTROYED);
return;
}
ufo.setAltitude(trajectory.getAltitude(nextWaypoint));
ufo.setTrajectoryPoint(nextWaypoint);
const RuleRegion ®ionRules = *rules.getRegion(_region);
std::pair<double, double> pos = getWaypoint(trajectory, nextWaypoint, globe, regionRules);
Waypoint *wp = new Waypoint();
wp->setLongitude(pos.first);
wp->setLatitude(pos.second);
ufo.setDestination(wp);
if (ufo.getAltitude() != "STR_GROUND")
{
if (ufo.getLandId() != 0)
{
ufo.setLandId(0);
}
// Set next waypoint.
ufo.setSpeed((int)(ufo.getRules()->getMaxSpeed() * trajectory.getSpeedPercentage(nextWaypoint)));
}
else
{
// UFO landed.
if (wave.objective && trajectory.getZone(curWaypoint) == (size_t)(_rule.getSpawnZone()))
{
// Remove UFO, replace with MissionSite.
addScore(ufo.getLongitude(), ufo.getLatitude(), game);
ufo.setStatus(Ufo::DESTROYED);
MissionArea area = regionRules.getMissionPoint(trajectory.getZone(curWaypoint), &ufo);
Texture *texture = rules.getGlobe()->getTexture(area.texture);
AlienDeployment *deployment = rules.getDeployment(texture->getDeployment());
MissionSite *missionSite = new MissionSite(&_rule, deployment);
missionSite->setLongitude(ufo.getLongitude());
missionSite->setLatitude(ufo.getLatitude());
missionSite->setId(game.getId(deployment->getMarkerName()));
missionSite->setSecondsRemaining(RNG::generate(deployment->getDurationMin(), deployment->getDurationMax()) * 3600);
missionSite->setAlienRace(_race);
missionSite->setTexture(area.texture);
missionSite->setCity(area.name);
game.getMissionSites()->push_back(missionSite);
for (std::vector<Target*>::iterator t = ufo.getFollowers()->begin(); t != ufo.getFollowers()->end();)
{
Craft* c = dynamic_cast<Craft*>(*t);
if (c && c->getNumSoldiers() != 0)
{
c->setDestination(missionSite);
t = ufo.getFollowers()->begin();
}
else
{
++t;
}
}
}
else if (trajectory.getID() == "__RETALIATION_ASSAULT_RUN")
{
// Ignore what the trajectory might say, this is a base assault.
// Remove UFO, replace with Base defense.
ufo.setDetected(false);
std::vector<Base *>::const_iterator found =
std::find_if (game.getBases()->begin(), game.getBases()->end(),
MatchBaseCoordinates(ufo.getLongitude(), ufo.getLatitude()));
if (found == game.getBases()->end())
{
ufo.setStatus(Ufo::DESTROYED);
// Only spawn mission if the base is still there.
return;
}
ufo.setDestination(*found);
}
else
//.........这里部分代码省略.........
示例15: FindMarkedXCOMBase
/**
* This function will spawn a UFO according the the mission rules.
* Some code is duplicated between cases, that's ok for now. It's on different
* code paths and the function is MUCH easier to read written this way.
* @param game The saved game information.
* @param ruleset The ruleset.
* @param globe The globe, for land checks.
* @param wave The wave for the desired UFO.
* @param trajectory The rule for the desired trajectory.
* @return Pointer to the spawned UFO. If the mission does not desire to spawn a UFO, 0 is returned.
*/
Ufo *AlienMission::spawnUfo(const SavedGame &game, const Ruleset &ruleset, const Globe &globe, const MissionWave &wave, const UfoTrajectory &trajectory)
{
RuleUfo &ufoRule = *ruleset.getUfo(wave.ufoType);
if (_rule.getObjective() == OBJECTIVE_RETALIATION)
{
const RuleRegion ®ionRules = *ruleset.getRegion(_region);
std::vector<Base *>::const_iterator found =
std::find_if (game.getBases()->begin(), game.getBases()->end(),
FindMarkedXCOMBase(regionRules));
if (found != game.getBases()->end())
{
// Spawn a battleship straight for the XCOM base.
const RuleUfo &battleshipRule = *ruleset.getUfo(_rule.getSpawnUfo());
const UfoTrajectory &assaultTrajectory = *ruleset.getUfoTrajectory("__RETALIATION_ASSAULT_RUN");
Ufo *ufo = new Ufo(&battleshipRule);
ufo->setMissionInfo(this, &assaultTrajectory);
std::pair<double, double> pos;
if (trajectory.getAltitude(0) == "STR_GROUND")
{
pos = getLandPoint(globe, regionRules, trajectory.getZone(0));
}
else
{
pos = regionRules.getRandomPoint(trajectory.getZone(0));
}
ufo->setAltitude(assaultTrajectory.getAltitude(0));
ufo->setSpeed(assaultTrajectory.getSpeedPercentage(0) * battleshipRule.getMaxSpeed());
ufo->setLongitude(pos.first);
ufo->setLatitude(pos.second);
Waypoint *wp = new Waypoint();
wp->setLongitude((*found)->getLongitude());
wp->setLatitude((*found)->getLatitude());
ufo->setDestination(wp);
return ufo;
}
}
else if (_rule.getObjective() == OBJECTIVE_SUPPLY)
{
if (wave.objective && !_base)
{
// No base to supply!
return 0;
}
// Our destination is always an alien base.
Ufo *ufo = new Ufo(&ufoRule);
ufo->setMissionInfo(this, &trajectory);
const RuleRegion ®ionRules = *ruleset.getRegion(_region);
std::pair<double, double> pos;
if (trajectory.getAltitude(0) == "STR_GROUND")
{
pos = getLandPoint(globe, regionRules, trajectory.getZone(0));
}
else
{
pos = regionRules.getRandomPoint(trajectory.getZone(0));
}
ufo->setAltitude(trajectory.getAltitude(0));
ufo->setSpeed(trajectory.getSpeedPercentage(0) * ufoRule.getMaxSpeed());
ufo->setLongitude(pos.first);
ufo->setLatitude(pos.second);
Waypoint *wp = new Waypoint();
if (trajectory.getAltitude(1) == "STR_GROUND")
{
if (wave.objective)
{
// Supply ships on supply missions land on bases, ignore trajectory zone.
pos.first = _base->getLongitude();
pos.second = _base->getLatitude();
}
else
{
// Other ships can land where they want.
pos = getLandPoint(globe, regionRules, trajectory.getZone(1));
}
}
else
{
pos = regionRules.getRandomPoint(trajectory.getZone(1));
}
wp->setLongitude(pos.first);
wp->setLatitude(pos.second);
ufo->setDestination(wp);
return ufo;
}
// Spawn according to sequence.
Ufo *ufo = new Ufo(&ufoRule);
ufo->setMissionInfo(this, &trajectory);
const RuleRegion ®ionRules = *ruleset.getRegion(_region);
std::pair<double, double> pos = getWaypoint(trajectory, 0, globe, regionRules);
//.........这里部分代码省略.........