本文整理汇总了C++中Species::AddHomeworld方法的典型用法代码示例。如果您正苦于以下问题:C++ Species::AddHomeworld方法的具体用法?C++ Species::AddHomeworld怎么用?C++ Species::AddHomeworld使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Species
的用法示例。
在下文中一共展示了Species::AddHomeworld方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: SetEmpireHomeworld
bool SetEmpireHomeworld(Empire* empire, int planet_id, std::string species_name) {
// get home planet and system, check if they exist
TemporaryPtr<Planet> home_planet = GetPlanet(planet_id);
TemporaryPtr<System> home_system;
if (home_planet)
home_system = GetSystem(home_planet->SystemID());
if (!home_planet || !home_system) {
ErrorLogger() << "SetEmpireHomeworld: couldn't get homeworld or system for empire" << empire->EmpireID();
return false;
}
DebugLogger() << "SetEmpireHomeworld: setting system " << home_system->ID()
<< " (planet " << home_planet->ID() << ") to be home system for empire " << empire->EmpireID();
// get species, check if it exists
Species* species = GetSpeciesManager().GetSpecies(species_name);
if (!species) {
ErrorLogger() << "SetEmpireHomeworld: couldn't get species \""
<< species_name << "\" to set with homeworld id " << home_planet->ID();
return false;
}
// set homeword's planet type to the preferred type for this species
const std::map<PlanetType, PlanetEnvironment>& spte = species->PlanetEnvironments();
if (!spte.empty()) {
// invert map from planet type to environments to map from
// environments to type, sorted by environment
std::map<PlanetEnvironment, PlanetType> sept;
for (std::map<PlanetType, PlanetEnvironment>::const_iterator it = spte.begin(); it != spte.end(); ++it)
sept[it->second] = it->first;
// assuming enum values are ordered in increasing goodness...
PlanetType preferred_planet_type = sept.rbegin()->second;
// both the current as well as the original type need to be set to the preferred type
home_planet->SetType(preferred_planet_type);
home_planet->SetOriginalType(preferred_planet_type);
// set planet size according to planet type
if (preferred_planet_type == PT_ASTEROIDS)
home_planet->SetSize(SZ_ASTEROIDS);
else if (preferred_planet_type == PT_GASGIANT)
home_planet->SetSize(SZ_GASGIANT);
else
home_planet->SetSize(SZ_MEDIUM);
}
home_planet->Colonize(empire->EmpireID(), species_name, Meter::LARGE_VALUE);
species->AddHomeworld(home_planet->ID());
empire->SetCapitalID(home_planet->ID());
empire->AddExploredSystem(home_planet->SystemID());
return true;
}