本文整理汇总了C++中Fleet::getDestinationId方法的典型用法代码示例。如果您正苦于以下问题:C++ Fleet::getDestinationId方法的具体用法?C++ Fleet::getDestinationId怎么用?C++ Fleet::getDestinationId使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Fleet
的用法示例。
在下文中一共展示了Fleet::getDestinationId方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: reset
//.........这里部分代码省略.........
break;
}
Fleet* fleet = new Fleet(this);
fleet->setOwner(this->getPlayer(atoi(tokens[1].c_str())));
fleet->setNumShips(atoi(tokens[2].c_str()));
fleet->setSourceId(atoi(tokens[3].c_str()));
fleet->setDestinationId(atoi(tokens[4].c_str()));
fleet->setTotalTripLength(atoi(tokens[5].c_str()));
fleet->setTurnsRemaining(atoi(tokens[6].c_str()));
fleets.push_back(fleet);
fleetLines.push_back(i);
} else {
std::stringstream message;
message << "Map file error [line " << i
<< "]: a non-empty line that does not contain a planet or a fleet.";
this->logError(message.str());
failed = true;
break;
}
}
const int numPlanets = static_cast<int>(planets.size());
//Resolve planet references inside fleets.
int fleetIndex = 0;
if (!failed) {
for (FleetList::iterator it = fleets.begin(); it != fleets.end(); ++it) {
Fleet* fleet = *it;
//Attempt to resolve the source planet.
const int sourceId = fleet->getSourceId();
if (sourceId < 0 || sourceId >= numPlanets) {
std::stringstream message;
message << "Map file error [line " << fleetLines[fleetIndex]
<< "]: fleet refers to an invalid planet with id=" << sourceId << ".";
this->logError(message.str());
failed = true;
break;
} else {
fleet->setSource(planets[sourceId]);
}
//Attempt to resolve the destination planet.
const int destinationId = fleet->getDestinationId();
if (destinationId < 0 || destinationId >= numPlanets) {
std::stringstream message;
message << "Map file error [line " << fleetLines[fleetIndex]
<< "]: fleet refers to an invalid planet with id=" << destinationId << ".";
this->logError(message.str());
failed = true;
break;
} else {
fleet->setDestination(planets[destinationId]);
}
//This will force recalculation of the current position.
fleet->setTurnsRemaining(fleet->getTurnsRemaining());
++fleetIndex;
}
}
if (failed) {
//Clean up.
for (int i = 0; i < numPlanets; ++i) delete planets[i];
for (FleetList::iterator it = fleets.begin(); it != fleets.end(); ++it) delete *it;
return;
}
//Parsed the map successfully. Reset the game.
//Stop any running processes.
this->stop();
this->stopPlayers();
//If didn't fail, replace the old planets and fleets with the new.
const int numOldPlanets = static_cast<int>(m_planets.size());
for (int i = 0; i < numOldPlanets; ++i) delete m_planets[i];
for (FleetList::iterator it = m_fleets.begin(); it != m_fleets.end(); ++it) delete (*it);
m_planets = planets;
m_fleets = fleets;
m_newFleets.insert(m_newFleets.end(), fleets.begin(), fleets.end());
//Reset all flags and counters.
m_state = RESET;
m_turn = 0;
//Notify everyone of the resetn
this->logMessage("================= Game reset. ==================");
emit wasReset();
}