std::string Planet::CardinalSuffix() const { std::string retval = ""; // Planets are grouped into asteroids, and non-asteroids // Asteroids receive a localized prefix if (Type() == PT_ASTEROIDS) retval.append(UserString("NEW_ASTEROIDS_SUFFIX") + " "); TemporaryPtr<System> cur_system = GetSystem(SystemID()); if (cur_system) { if (cur_system->OrbitOfPlanet(ID()) < 0) { ErrorLogger() << "Planet " << Name() << "(" << ID() << ") " << "has no current orbit"; retval.append(RomanNumber(1)); return retval; } int num_planets_lteq = 0; // number of planets at this orbit or smaller int num_planets_total = 0; bool prior_current_planet = true; const std::vector<int>& sys_orbits = cur_system->PlanetIDsByOrbit(); for (std::vector<int>::const_iterator it = sys_orbits.begin(); it != sys_orbits.end(); ++it) { if (*it == INVALID_OBJECT_ID) continue; PlanetType other_planet_type = GetPlanet(*it)->Type(); if (other_planet_type == INVALID_PLANET_TYPE) continue; if (Type() != PT_ASTEROIDS) { if (other_planet_type != PT_ASTEROIDS) { ++num_planets_total; if (prior_current_planet) ++num_planets_lteq; } } else { if (other_planet_type == PT_ASTEROIDS) { ++num_planets_total; if (prior_current_planet) ++num_planets_lteq; } } if (*it == ID()) prior_current_planet =false; } // For asteroids: If no other asteroids in this system, suffix does not receive a number if (Type() != PT_ASTEROIDS || (Type() == PT_ASTEROIDS && num_planets_total > 1)) retval.append(RomanNumber(num_planets_lteq)); } else { ErrorLogger() << "Planet " << Name() << "(" << ID() << ") not assigned to a system"; } return retval; }
//////////////////// // Free Functions // //////////////////// std::string NewMonsterName() { static std::vector<std::string> monster_names; static std::map<std::string, int> monster_names_used; if (monster_names.empty()) { // load monster names from stringtable std::list<std::string> monster_names_list; UserStringList("MONSTER_NAMES", monster_names_list); monster_names.reserve(monster_names_list.size()); std::copy(monster_names_list.begin(), monster_names_list.end(), std::back_inserter(monster_names)); if (monster_names.empty()) // safety check to ensure not leaving list empty in case of stringtable failure monster_names.push_back(UserString("MONSTER")); } // select name randomly from list int monster_name_index = RandSmallInt(0, static_cast<int>(monster_names.size()) - 1); std::string result = monster_names[monster_name_index]; if (monster_names_used[result]++) { result += " " + RomanNumber(monster_names_used[result]); } return result; }
std::string Planet::CardinalSuffix() const { std::string retval = ""; // Early return for invalid ID if (ID() == INVALID_OBJECT_ID) { WarnLogger() << "Planet " << Name() << " has invalid ID"; return retval; } auto cur_system = GetSystem(SystemID()); // Early return for no system if (!cur_system) { ErrorLogger() << "Planet " << Name() << "(" << ID() << ") not assigned to a system"; return retval; } // Early return for unknown orbit if (cur_system->OrbitOfPlanet(ID()) < 0) { WarnLogger() << "Planet " << Name() << "(" << ID() << ") " << "has no current orbit"; retval.append(RomanNumber(1)); return retval; } int num_planets_lteq = 0; // number of planets at this orbit or smaller int num_planets_total = 0; bool prior_current_planet = true; for (int sys_orbit : cur_system->PlanetIDsByOrbit()) { if (sys_orbit == INVALID_OBJECT_ID) continue; // all other planets are in further orbits if (sys_orbit == ID()) { prior_current_planet = false; ++num_planets_total; ++num_planets_lteq; continue; } PlanetType other_planet_type = GetPlanet(sys_orbit)->Type(); if (other_planet_type == INVALID_PLANET_TYPE) continue; // only increment suffix for non-asteroid planets if (Type() != PT_ASTEROIDS) { if (other_planet_type != PT_ASTEROIDS) { ++num_planets_total; if (prior_current_planet) ++num_planets_lteq; } } else { // unless the planet being named is an asteroid // then only increment suffix for asteroid planets if (other_planet_type == PT_ASTEROIDS) { ++num_planets_total; if (prior_current_planet) ++num_planets_lteq; } } } // Planets are grouped into asteroids, and non-asteroids if (Type() != PT_ASTEROIDS) { retval.append(RomanNumber(num_planets_lteq)); } else { // Asteroids receive a localized prefix retval.append(UserString("NEW_ASTEROIDS_SUFFIX")); // If no other asteroids in this system, do not append an ordinal if (num_planets_total > 1) retval.append(" " + RomanNumber(num_planets_lteq)); } return retval; }
//+---------------------------------------------------------------------- // // Function: NumberToRomanUpper( n, achBuffer[NUMCONV_STRLEN] ) // // Convert a long value to it's roman numeral equivalent. // The letters used here are in uppercase. // // Returns: Returns a roman number in achBuffer. // //----------------------------------------------------------------------- void NumberToRomanUpper(LONG n, TCHAR achBuffer[NUMCONV_STRLEN]) { RomanNumber(n, achBuffer, _T("M??CDMXLCIVX")); }
//+---------------------------------------------------------------------- // // Function: NumberToRomanUpper( n, achBuffer[NUMCONV_STRLEN] ) // // Convert a long value to it's roman numeral equivalent. // The letters used here are in lowercase. // // Returns: Returns a roman number in achBuffer. // //----------------------------------------------------------------------- void NumberToRomanLower(LONG n, TCHAR achBuffer[NUMCONV_STRLEN]) { RomanNumber(n, achBuffer, _T("m??cdmxlcivx")); }
RomanNumber romanNumberToPower(const RomanNumber &number, int power) { return RomanNumber(std::pow(number.toDecimal(), power)); }