void PlanetWars::EditFleet(uint16 id, uint16 iShipCount, sint16 iStartTurn) { FleetMap::iterator it = m_aFleets.find(id); ASSERT(it != m_aFleets.end()); Fleet& oFleet = it->second; CHECK_RETURN(oFleet.GetStartTurn() >= 0, "Error : try to edit an flying Fleet\n"); Planet& SrcPlanet = GetPlanet(oFleet.GetSourcePlanet()); Planet& DstPlanet = GetPlanet(oFleet.GetDestinationPlanet()); if (iStartTurn == 0) RemoveInfluence(SrcPlanet); SrcPlanet.RemoveFleet(oFleet); DstPlanet.RemoveFleet(oFleet); oFleet.m_iShipsCount = iShipCount; oFleet.m_iStartTurn = iStartTurn; SrcPlanet.AddFleet(oFleet); DstPlanet.AddFleet(oFleet); SrcPlanet.Compute(); DstPlanet.Compute(); if (iStartTurn == 0) ApplyInfluence(SrcPlanet); }
void PlanetWars::IssueOrder(int source_planet, int destination_planet, int num_ships) const { LOG("IssueOrder : (%3d -> %3d) [%3d]\n", source_planet, destination_planet, num_ships); CHECK_RETURN(GetPlanet(source_planet).GetOwner() == 1, "Error : Bad Source Planet\n"); CHECK_RETURN(source_planet != destination_planet, "Error : Same Planet\n"); CHECK_RETURN(GetPlanet(source_planet).GetRealShipsCount() >= num_ships, "Error : Too many Ship (%d pour %d)\n", num_ships, GetPlanet(source_planet).GetRealShipsCount()); CHECK_RETURN(num_ships > 0, "Error : Negative ship count\n"); cout << source_planet << " " << destination_planet << " " << num_ships << endl; cout.flush(); }
bool ColonizeOrder::UndoImpl() const { TemporaryPtr<Planet> planet = GetPlanet(m_planet); if (!planet) { ErrorLogger() << "ColonizeOrder::UndoImpl couldn't get planet with id " << m_planet; return false; } if (!planet->IsAboutToBeColonized()) { ErrorLogger() << "ColonizeOrder::UndoImpl planet is not about to be colonized..."; return false; } TemporaryPtr<Ship> ship = GetShip(m_ship); if (!ship) { ErrorLogger() << "ColonizeOrder::UndoImpl couldn't get ship with id " << m_ship; return false; } if (ship->OrderedColonizePlanet() != m_planet) { ErrorLogger() << "ColonizeOrder::UndoImpl ship is not about to colonize planet"; return false; } planet->SetIsAboutToBeColonized(false); ship->ClearColonizePlanet(); if (TemporaryPtr<Fleet> fleet = GetFleet(ship->FleetID())) fleet->StateChangedSignal(); return true; }
bool BombardOrder::UndoImpl() const { TemporaryPtr<Planet> planet = GetPlanet(m_planet); if (!planet) { ErrorLogger() << "BombardOrder::UndoImpl couldn't get planet with id " << m_planet; return false; } TemporaryPtr<Ship> ship = GetShip(m_ship); if (!ship) { ErrorLogger() << "BombardOrder::UndoImpl couldn't get ship with id " << m_ship; return false; } if (ship->OrderedBombardPlanet() != m_planet) { ErrorLogger() << "BombardOrder::UndoImpl ship is not about to bombard planet"; return false; } planet->SetIsAboutToBeBombarded(false); ship->ClearBombardPlanet(); if (TemporaryPtr<Fleet> fleet = GetFleet(ship->FleetID())) fleet->StateChangedSignal(); return true; }
std::vector<Planet> Game::NotMyPlanets() const { std::vector<Planet> r; for (size_t i = 0; i < NumPlanets(); ++i) { if (state.planets[i].owner != 1) r.push_back(GetPlanet(i)); } return r; }
void BombardOrder::ExecuteImpl() const { ValidateEmpireID(); int empire_id = EmpireID(); TemporaryPtr<Ship> ship = GetShip(m_ship); if (!ship) { ErrorLogger() << "BombardOrder::ExecuteImpl couldn't get ship with id " << m_ship; return; } if (!ship->CanBombard()) { ErrorLogger() << "BombardOrder::ExecuteImpl got ship that can't bombard"; return; } if (!ship->OwnedBy(empire_id)) { ErrorLogger() << "BombardOrder::ExecuteImpl got ship that isn't owned by the order-issuing empire"; return; } TemporaryPtr<Planet> planet = GetPlanet(m_planet); if (!planet) { ErrorLogger() << "BombardOrder::ExecuteImpl couldn't get planet with id " << m_planet; return; } if (planet->OwnedBy(empire_id)) { ErrorLogger() << "BombardOrder::ExecuteImpl given planet that is already owned by the order-issuing empire"; return; } if (!planet->Unowned() && Empires().GetDiplomaticStatus(planet->Owner(), empire_id) != DIPLO_WAR) { ErrorLogger() << "BombardOrder::ExecuteImpl given planet owned by an empire not at war with order-issuing empire"; return; } if (GetUniverse().GetObjectVisibilityByEmpire(m_planet, empire_id) < VIS_BASIC_VISIBILITY) { ErrorLogger() << "BombardOrder::ExecuteImpl given planet that empire reportedly has insufficient visibility of, but will be allowed to proceed pending investigation"; //return; } int ship_system_id = ship->SystemID(); if (ship_system_id == INVALID_OBJECT_ID) { ErrorLogger() << "BombardOrder::ExecuteImpl given id of ship not in a system"; return; } int planet_system_id = planet->SystemID(); if (ship_system_id != planet_system_id) { ErrorLogger() << "BombardOrder::ExecuteImpl given ids of ship and planet not in the same system"; return; } // note: multiple ships, from same or different empires, can invade the same planet on the same turn DebugLogger() << "BombardOrder::ExecuteImpl set for ship " << m_ship << " " << ship->Name() << " to bombard planet " << m_planet << " " << planet->Name(); planet->SetIsAboutToBeBombarded(true); ship->SetBombardPlanet(m_planet); if (TemporaryPtr<Fleet> fleet = GetFleet(ship->FleetID())) fleet->StateChangedSignal(); }
int IssueBombardOrder(int ship_id, int planet_id) { int empire_id = AIClientApp::GetApp()->EmpireID(); // make sure ship_id is a ship... TemporaryPtr<const Ship> ship = GetShip(ship_id); if (!ship) { Logger().errorStream() << "AIInterface::IssueBombardOrder : passed an invalid ship_id"; return 0; } if (ship->TotalWeaponsDamage() <= 0) { Logger().errorStream() << "AIInterface::IssueBombardOrder : ship can't attack / bombard"; return 0; } if (!ship->OwnedBy(empire_id)) { Logger().errorStream() << "AIInterface::IssueBombardOrder : ship isn't owned by the order-issuing empire"; return 0; } // verify that planet exists and is occupied by another empire TemporaryPtr<const Planet> planet = GetPlanet(planet_id); if (!planet) { Logger().errorStream() << "AIInterface::IssueBombardOrder : no planet with passed planet_id"; return 0; } if (planet->OwnedBy(empire_id)) { Logger().errorStream() << "AIInterface::IssueBombardOrder : planet is already owned by the order-issuing empire"; return 0; } if (!planet->Unowned() && Empires().GetDiplomaticStatus(planet->Owner(), empire_id) != DIPLO_WAR) { Logger().errorStream() << "AIInterface::IssueBombardOrder : planet owned by an empire not at war with order-issuing empire"; return 0; } if (GetUniverse().GetObjectVisibilityByEmpire(planet_id, empire_id) < VIS_BASIC_VISIBILITY) { Logger().errorStream() << "AIInterface::IssueBombardOrder : planet that empire reportedly has insufficient visibility of, but will be allowed to proceed pending investigation"; //return; } int ship_system_id = ship->SystemID(); if (ship_system_id == INVALID_OBJECT_ID) { Logger().errorStream() << "AIInterface::IssueBombardOrder : given id of ship not in a system"; return 0; } int planet_system_id = planet->SystemID(); if (ship_system_id != planet_system_id) { Logger().errorStream() << "AIInterface::IssueBombardOrder : given ids of ship and planet not in the same system"; return 0; } AIClientApp::GetApp()->Orders().IssueOrder(OrderPtr(new BombardOrder(empire_id, ship_id, planet_id))); return 1; }
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; }
void PlanetWars::AddFleet(uint16 iOwner, uint16 iShipCount, uint16 iSourcePlanet, uint16 iDestinationPlanet, uint16 iTotalTripLength, uint16 iTurnsRemaining) { uint16 Id = m_iFleetCounter++; sint16 iStartTurn = iTurnsRemaining - iTotalTripLength; Fleet oFleet(Id, iOwner, iShipCount, iSourcePlanet, iDestinationPlanet, iStartTurn, iTotalTripLength, iTurnsRemaining); m_aFleets.insert(FleetPair(Id, oFleet)); Planet& SrcPlanet = GetPlanet(oFleet.GetSourcePlanet()); SrcPlanet.AddFleet(oFleet); Planet& DstPlanet = GetPlanet(oFleet.GetDestinationPlanet()); DstPlanet.AddFleet(oFleet); switch (iOwner) { case 1: m_iTotalOwnedShipCount += iShipCount; break; case 2: m_iTotalEnemyShipCount += iShipCount; break; } }
uint16 PlanetWars::CreateFleet(uint16 iOwner, uint16 iShipCount, uint16 iSourcePlanet, uint16 iDestinationPlanet, sint16 iStartTurn) { uint16 Id = m_iFleetCounter++; uint16 iTotalTripLength = GetDistance(iSourcePlanet, iDestinationPlanet); uint16 iTurnsRemaining = iTotalTripLength; Fleet oFleet(Id, iOwner, iShipCount, iSourcePlanet, iDestinationPlanet, iStartTurn, iTotalTripLength, iTurnsRemaining); m_aFleets.insert(FleetPair(Id, oFleet)); Planet& SrcPlanet = GetPlanet(oFleet.GetSourcePlanet()); if (iStartTurn == 0) { RemoveInfluence(SrcPlanet); switch (iOwner) { case 1: m_iTotalOwnedPlanetCount -= iShipCount; break; case 2: m_iTotalEnemyPlanetCount -= iShipCount; break; default: break; } } SrcPlanet.AddFleet(oFleet); SrcPlanet.Compute(); if (iStartTurn == 0) ApplyInfluence(SrcPlanet); Planet& DstPlanet = GetPlanet(oFleet.GetDestinationPlanet()); //DstPlanet.RemoveMyInfluence(); inutile puisque au dela du tour 0 DstPlanet.AddFleet(oFleet); DstPlanet.Compute(); //DstPlanet.ApplyMyInfluence(); switch (iOwner) { case 1: m_iTotalOwnedShipCount += iShipCount; break; case 2: m_iTotalEnemyShipCount += iShipCount; break; } return oFleet.GetID(); }
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; }
int IssueColonizeOrder(int ship_id, int planet_id) { int empire_id = AIClientApp::GetApp()->EmpireID(); // make sure ship_id is a ship... TemporaryPtr<const Ship> ship = GetShip(ship_id); if (!ship) { Logger().errorStream() << "AIInterface::IssueColonizeOrder : passed an invalid ship_id"; return 0; } // get fleet of ship TemporaryPtr<const Fleet> fleet = GetFleet(ship->FleetID()); if (!fleet) { Logger().errorStream() << "AIInterface::IssueColonizeOrder : ship with passed ship_id has invalid fleet_id"; return 0; } // make sure player owns ship and its fleet if (!fleet->OwnedBy(empire_id)) { Logger().errorStream() << "AIInterface::IssueColonizeOrder : empire does not own fleet of passed ship"; return 0; } if (!ship->OwnedBy(empire_id)) { Logger().errorStream() << "AIInterface::IssueColonizeOrder : empire does not own passed ship"; return 0; } // verify that planet exists and is un-occupied. TemporaryPtr<const Planet> planet = GetPlanet(planet_id); if (!planet) { Logger().errorStream() << "AIInterface::IssueColonizeOrder : no planet with passed planet_id"; return 0; } if ((!planet->Unowned()) && !( planet->OwnedBy(empire_id) && planet->CurrentMeterValue(METER_POPULATION)==0)) { Logger().errorStream() << "AIInterface::IssueColonizeOrder : planet with passed planet_id "<<planet_id<<" is already owned, or colonized by own empire"; return 0; } // verify that planet is in same system as the fleet if (planet->SystemID() != fleet->SystemID()) { Logger().errorStream() << "AIInterface::IssueColonizeOrder : fleet and planet are not in the same system"; return 0; } if (ship->SystemID() == INVALID_OBJECT_ID) { Logger().errorStream() << "AIInterface::IssueColonizeOrder : ship is not in a system"; return 0; } AIClientApp::GetApp()->Orders().IssueOrder(OrderPtr(new ColonizeOrder(empire_id, ship_id, planet_id))); return 1; }
void PlanetWars::RemoveFleet(uint16 id) { //LOG("Suppression du Fleet %d\n", id); FleetMap::iterator it = m_aFleets.find(id); ASSERT(it != m_aFleets.end()); Fleet& oFleet = it->second; Planet& SrcPlanet = GetPlanet(oFleet.GetSourcePlanet()); if (oFleet.GetStartTurn() == 0) RemoveInfluence(SrcPlanet); SrcPlanet.RemoveFleet(oFleet); SrcPlanet.Compute(); if (oFleet.GetStartTurn() == 0) ApplyInfluence(SrcPlanet); Planet& DstPlanet = GetPlanet(oFleet.GetDestinationPlanet()); DstPlanet.RemoveFleet(oFleet); DstPlanet.Compute(); m_aFleets.erase(it); }
void GiveObjectToEmpireOrder::ExecuteImpl() const { ValidateEmpireID(); int empire_id = EmpireID(); if (TemporaryPtr<Fleet> fleet = GetFleet(m_object_id)) { if (fleet->OwnedBy(empire_id)) fleet->SetGiveToEmpire(m_recipient_empire_id); } else if (TemporaryPtr<Planet> planet = GetPlanet(m_object_id)) { if (planet->OwnedBy(empire_id)) planet->SetGiveToEmpire(m_recipient_empire_id); } }
void PlanetWars::ExecuteOrders() { FleetMap::const_iterator begin = m_aFleets.begin(); FleetMap::const_iterator end = m_aFleets.end(); FleetMap::const_iterator it; for (it = begin ; it != end ; ++it) { if (it->second.GetStartTurn() == 0) { IssueOrder(it->second.GetSourcePlanet(), it->second.GetDestinationPlanet(), it->second.GetShipsCount()); GetPlanet(it->second.GetSourcePlanet()).RemoveRealShips(it->second.GetShipsCount()); } } }
bool GiveObjectToEmpireOrder::UndoImpl() const { ValidateEmpireID(); int empire_id = EmpireID(); if (TemporaryPtr<Fleet> fleet = GetFleet(m_object_id)) { if (fleet->OwnedBy(empire_id)) { fleet->ClearGiveToEmpire(); return true; } } else if (TemporaryPtr<Planet> planet = GetPlanet(m_object_id)) { if (planet->OwnedBy(empire_id)) { planet->ClearGiveToEmpire(); return true; } } return false; }
void ChangeFocusOrder::ExecuteImpl() const { ValidateEmpireID(); TemporaryPtr<Planet> planet = GetPlanet(PlanetID()); if (!planet) { ErrorLogger() << "Illegal planet id specified in change planet focus order."; return; } if (!planet->OwnedBy(EmpireID())) { ErrorLogger() << "Empire attempted to issue change planet focus to another's planet."; return; } planet->SetFocus(m_focus); }
void ScrapOrder::ExecuteImpl() const { ValidateEmpireID(); int empire_id = EmpireID(); if (TemporaryPtr<Ship> ship = GetShip(m_object_id)) { if (ship->SystemID() != INVALID_OBJECT_ID && ship->OwnedBy(empire_id)) { ship->SetOrderedScrapped(true); //DebugLogger() << "ScrapOrder::ExecuteImpl empire: " << empire_id // << " on ship: " << ship->ID() << " at system: " << ship->SystemID() // << " ... ordered scrapped?: " << ship->OrderedScrapped(); } } else if (TemporaryPtr<Building> building = GetBuilding(m_object_id)) { int planet_id = building->PlanetID(); if (TemporaryPtr<const Planet> planet = GetPlanet(planet_id)) { if (building->OwnedBy(empire_id) && planet->OwnedBy(empire_id)) building->SetOrderedScrapped(true); } } }
MilitaryPanel::MilitaryPanel(GG::X w, int planet_id) : AccordionPanel(w, GG::Y(ClientUI::Pts()*2)), m_planet_id(planet_id), m_meter_stats(), m_multi_icon_value_indicator(0), m_multi_meter_status_bar(0) { SetName("MilitaryPanel"); TemporaryPtr<const Planet> planet = GetPlanet(); if (!planet) throw std::invalid_argument("Attempted to construct a MilitaryPanel with an object id is not a Planet"); GG::Connect(m_expand_button->LeftClickedSignal, &MilitaryPanel::ExpandCollapseButtonPressed, this); // small meter indicators - for use when panel is collapsed m_meter_stats.push_back(std::make_pair(METER_SHIELD, new StatisticIcon(ClientUI::MeterIcon(METER_SHIELD), 0, 3, false))); m_meter_stats.push_back(std::make_pair(METER_DEFENSE, new StatisticIcon(ClientUI::MeterIcon(METER_DEFENSE), 0, 3, false))); m_meter_stats.push_back(std::make_pair(METER_TROOPS, new StatisticIcon(ClientUI::MeterIcon(METER_TROOPS), 0, 3, false))); m_meter_stats.push_back(std::make_pair(METER_DETECTION, new StatisticIcon(ClientUI::MeterIcon(METER_DETECTION), 0, 3, false))); m_meter_stats.push_back(std::make_pair(METER_STEALTH, new StatisticIcon(ClientUI::MeterIcon(METER_STEALTH), 0, 3, false))); // meter and production indicators std::vector<std::pair<MeterType, MeterType> > meters; for (std::vector<std::pair<MeterType, StatisticIcon*> >::iterator it = m_meter_stats.begin(); it != m_meter_stats.end(); ++it) { AttachChild(it->second); meters.push_back(std::make_pair(it->first, AssociatedMeterType(it->first))); } // attach and show meter bars and large resource indicators m_multi_meter_status_bar = new MultiMeterStatusBar(Width() - 2*EDGE_PAD, m_planet_id, meters); m_multi_icon_value_indicator = new MultiIconValueIndicator(Width() - 2*EDGE_PAD, m_planet_id, meters); // determine if this panel has been created yet. std::map<int, bool>::iterator it = s_expanded_map.find(m_planet_id); if (it == s_expanded_map.end()) s_expanded_map[m_planet_id] = false; // if not, default to collapsed state Refresh(); }
int IssueChangeFocusOrder(int planet_id, const std::string& focus) { int empire_id = AIClientApp::GetApp()->EmpireID(); TemporaryPtr<const Planet> planet = GetPlanet(planet_id); if (!planet) { Logger().errorStream() << "AIInterface::IssueChangeFocusOrder : no planet with passed planet_id "<<planet_id; return 0; } if (!planet->OwnedBy(empire_id)) { Logger().errorStream() << "AIInterface::IssueChangeFocusOrder : empire does not own planet with passed planet_id"; return 0; } if (false) { // todo: verify that focus is valid for specified planet Logger().errorStream() << "AIInterface::IssueChangeFocusOrder : invalid focus specified"; return 0; } AIClientApp::GetApp()->Orders().IssueOrder(OrderPtr( new ChangeFocusOrder(empire_id, planet_id, focus))); return 1; }
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; }
CombatInfo::CombatInfo(int system_id_) : system_id(system_id_) { const Universe& universe = GetUniverse(); const ObjectMap& universe_objects = universe.Objects(); const System* system = universe_objects.Object<System>(system_id); if (!system) { Logger().errorStream() << "CombatInfo constructed with invalid system id: " << system_id; return; } // add copy of system to full / complete objects in combat System* copy_system = system->Clone(); objects.Insert(system_id, copy_system); // find ships and their owners in system std::vector<int> ship_ids = system->FindObjectIDs<Ship>(); for (std::vector<int>::const_iterator it = ship_ids.begin(); it != ship_ids.end(); ++it) { int ship_id = *it; const Ship* ship = GetShip(ship_id); if (!ship) { Logger().errorStream() << "CombatInfo::CombatInfo couldn't get ship with id " << ship_id << " in system " << system->Name() << " (" << system_id << ")"; continue; } // add owner to empires that have assets in this battle empire_ids.insert(ship->Owner()); // add copy of ship to full / complete copy of objects in system Ship* copy = ship->Clone(); objects.Insert(ship_id, copy); } // find planets and their owners in system std::vector<int> planet_ids = system->FindObjectIDs<Planet>(); for (std::vector<int>::const_iterator it = planet_ids.begin(); it != planet_ids.end(); ++it) { int planet_id = *it; const Planet* planet = GetPlanet(planet_id); if (!planet) { Logger().errorStream() << "CombatInfo::CombatInfo couldn't get planet with id " << planet_id << " in system " << system->Name() << " (" << system_id << ")"; continue; } // if planet is populated, add owner to empires that have assets in this battle if (planet->CurrentMeterValue(METER_POPULATION) > 0.0) empire_ids.insert(planet->Owner()); // add copy of ship to full / complete copy of objects in system Planet* copy = planet->Clone(); objects.Insert(planet_id, copy); } // TODO: should buildings be considered separately? // now that all participants in the battle have been found, loop through // objects again to assemble each participant empire's latest // known information about all objects in this battle // system for (std::set<int>::const_iterator empire_it = empire_ids.begin(); empire_it != empire_ids.end(); ++empire_it) { int empire_id = *empire_it; if (empire_id == ALL_EMPIRES) continue; System* visibility_limited_copy = system->Clone(empire_id); empire_known_objects[empire_id].Insert(system_id, visibility_limited_copy); } // ships for (std::vector<int>::const_iterator it = ship_ids.begin(); it != ship_ids.end(); ++it) { int ship_id = *it; const Ship* ship = GetShip(ship_id); if (!ship) { Logger().errorStream() << "CombatInfo::CombatInfo couldn't get ship with id " << ship_id << " in system " << system->Name() << " (" << system_id << ")"; continue; } const Fleet* fleet = GetFleet(ship->FleetID()); if (!fleet) { Logger().errorStream() << "CombatInfo::CombatInfo couldn't get fleet with id " << ship->FleetID() << " in system " << system->Name() << " (" << system_id << ")"; continue; } for (std::set<int>::const_iterator empire_it = empire_ids.begin(); empire_it != empire_ids.end(); ++empire_it) { int empire_id = *empire_it; if (empire_id == ALL_EMPIRES) continue; if (universe.GetObjectVisibilityByEmpire(ship_id, empire_id) >= VIS_BASIC_VISIBILITY || (fleet->Aggressive() && (empire_id == ALL_EMPIRES || fleet->Unowned() || Empires().GetDiplomaticStatus(empire_id, fleet->Owner()) == DIPLO_WAR))) { Ship* visibility_limited_copy = ship->Clone(empire_id); empire_known_objects[empire_id].Insert(ship_id, visibility_limited_copy); } } } // planets for (std::vector<int>::const_iterator it = planet_ids.begin(); it != planet_ids.end(); ++it) { int planet_id = *it; const Planet* planet = GetPlanet(planet_id); if (!planet) { Logger().errorStream() << "CombatInfo::CombatInfo couldn't get planet with id " << planet_id << " in system " << system->Name() << " (" << system_id << ")"; continue; } for (std::set<int>::const_iterator empire_it = empire_ids.begin(); empire_it != empire_ids.end(); ++empire_it) { int empire_id = *empire_it; if (empire_id == ALL_EMPIRES) continue; if (universe.GetObjectVisibilityByEmpire(planet_id, empire_id) >= VIS_BASIC_VISIBILITY) { Planet* visibility_limited_copy = planet->Clone(empire_id); empire_known_objects[empire_id].Insert(planet_id, visibility_limited_copy); } } } // after battle is simulated, any changes to latest known or actual objects // will be copied back to the main Universe's ObjectMap and the Universe's // empire latest known objects ObjectMap }
void GameEngineClient::PlanetUpdate(const Vertex& dst, const Planet& planet) { GetPlanet(dst)=planet; };
void ColonizeOrder::ExecuteImpl() const { ValidateEmpireID(); int empire_id = EmpireID(); TemporaryPtr<Ship> ship = GetShip(m_ship); if (!ship) { ErrorLogger() << "ColonizeOrder::ExecuteImpl couldn't get ship with id " << m_ship; return; } if (!ship->CanColonize()) { // verifies that species exists and can colonize and that ship can colonize ErrorLogger() << "ColonizeOrder::ExecuteImpl got ship that can't colonize"; return; } if (!ship->OwnedBy(empire_id)) { ErrorLogger() << "ColonizeOrder::ExecuteImpl got ship that isn't owned by the order-issuing empire"; return; } float colonist_capacity = ship->ColonyCapacity(); TemporaryPtr<Planet> planet = GetPlanet(m_planet); if (!planet) { ErrorLogger() << "ColonizeOrder::ExecuteImpl couldn't get planet with id " << m_planet; return; } if (planet->CurrentMeterValue(METER_POPULATION) > 0.0f) { ErrorLogger() << "ColonizeOrder::ExecuteImpl given planet that already has population"; return; } if (!planet->Unowned() && planet->Owner() != empire_id) { ErrorLogger() << "ColonizeOrder::ExecuteImpl given planet that owned by another empire"; return; } if (planet->OwnedBy(empire_id) && colonist_capacity == 0.0f) { ErrorLogger() << "ColonizeOrder::ExecuteImpl given planet that is already owned by empire and colony ship with zero capcity"; return; } if (GetUniverse().GetObjectVisibilityByEmpire(m_planet, empire_id) < VIS_PARTIAL_VISIBILITY) { ErrorLogger() << "ColonizeOrder::ExecuteImpl given planet that empire has insufficient visibility of"; return; } if (colonist_capacity > 0.0f && planet->EnvironmentForSpecies(ship->SpeciesName()) < PE_HOSTILE) { ErrorLogger() << "ColonizeOrder::ExecuteImpl nonzero colonist capacity and planet that ship's species can't colonize"; return; } int ship_system_id = ship->SystemID(); if (ship_system_id == INVALID_OBJECT_ID) { ErrorLogger() << "ColonizeOrder::ExecuteImpl given id of ship not in a system"; return; } int planet_system_id = planet->SystemID(); if (ship_system_id != planet_system_id) { ErrorLogger() << "ColonizeOrder::ExecuteImpl given ids of ship and planet not in the same system"; return; } if (planet->IsAboutToBeColonized()) { ErrorLogger() << "ColonizeOrder::ExecuteImpl given id planet that is already being colonized"; return; } planet->SetIsAboutToBeColonized(true); ship->SetColonizePlanet(m_planet); if (TemporaryPtr<Fleet> fleet = GetFleet(ship->FleetID())) fleet->StateChangedSignal(); }
std::vector<Planet> Game::Planets() const { std::vector<Planet> r; for (size_t i = 0; i < NumPlanets(); ++i) r.push_back(GetPlanet(i)); return r; }
void BuildingsPanel::Update() { //std::cout << "BuildingsPanel::Update" << std::endl; // remove old indicators for (std::vector<BuildingIndicator*>::iterator it = m_building_indicators.begin(); it != m_building_indicators.end(); ++it) { DetachChild(*it); delete (*it); } m_building_indicators.clear(); TemporaryPtr<const Planet> planet = GetPlanet(m_planet_id); if (!planet) { ErrorLogger() << "BuildingsPanel::Update couldn't get planet with id " << m_planet_id; return; } const std::set<int>& buildings = planet->BuildingIDs(); int system_id = planet->SystemID(); const int indicator_size = static_cast<int>(Value(Width() * 1.0 / m_columns)); int this_client_empire_id = HumanClientApp::GetApp()->EmpireID(); const std::set<int>& this_client_known_destroyed_objects = GetUniverse().EmpireKnownDestroyedObjectIDs(this_client_empire_id); const std::set<int>& this_client_stale_object_info = GetUniverse().EmpireStaleKnowledgeObjectIDs(this_client_empire_id); // get existing / finished buildings and use them to create building indicators for (std::set<int>::const_iterator it = buildings.begin(); it != buildings.end(); ++it) { int object_id = *it; // skip known destroyed and stale info objects if (this_client_known_destroyed_objects.find(object_id) != this_client_known_destroyed_objects.end()) continue; if (this_client_stale_object_info.find(object_id) != this_client_stale_object_info.end()) continue; TemporaryPtr<const Building> building = GetBuilding(object_id); if (!building) { ErrorLogger() << "BuildingsPanel::Update couldn't get building with id: " << object_id << " on planet " << planet->Name(); continue; } if (building->SystemID() != system_id || building->PlanetID() != m_planet_id) continue; BuildingIndicator* ind = new BuildingIndicator(GG::X(indicator_size), object_id); m_building_indicators.push_back(ind); GG::Connect(ind->RightClickedSignal, BuildingRightClickedSignal); } // get in-progress buildings const Empire* empire = GetEmpire(planet->Owner()); if (!empire) return; const ProductionQueue& queue = empire->GetProductionQueue(); int queue_index = 0; for (ProductionQueue::const_iterator queue_it = queue.begin(); queue_it != queue.end(); ++queue_it, ++queue_index) { const ProductionQueue::Element elem = *queue_it; if (elem.item.build_type != BT_BUILDING) continue; // don't show in-progress ships in BuildingsPanel... if (elem.location != m_planet_id) continue; // don't show buildings located elsewhere double total_cost; int total_turns; boost::tie(total_cost, total_turns) = empire->ProductionCostAndTime(elem); double progress = std::max(0.0f, empire->ProductionStatus(queue_index)); double turns_completed = total_turns * std::min<double>(1.0, progress / total_cost); BuildingIndicator* ind = new BuildingIndicator(GG::X(indicator_size), elem.item.name, turns_completed, total_turns); m_building_indicators.push_back(ind); } }
int IssueInvadeOrder(int ship_id, int planet_id) { int empire_id = AIClientApp::GetApp()->EmpireID(); // make sure ship_id is a ship... TemporaryPtr<const Ship> ship = GetShip(ship_id); if (!ship) { Logger().errorStream() << "AIInterface::IssueInvadeOrder : passed an invalid ship_id"; return 0; } // get fleet of ship TemporaryPtr<const Fleet> fleet = GetFleet(ship->FleetID()); if (!fleet) { Logger().errorStream() << "AIInterface::IssueInvadeOrder : ship with passed ship_id has invalid fleet_id"; return 0; } // make sure player owns ship and its fleet if (!fleet->OwnedBy(empire_id)) { Logger().errorStream() << "AIInterface::IssueInvadeOrder : empire does not own fleet of passed ship"; return 0; } if (!ship->OwnedBy(empire_id)) { Logger().errorStream() << "AIInterface::IssueInvadeOrder : empire does not own passed ship"; return 0; } // verify that planet exists and is occupied by another empire TemporaryPtr<const Planet> planet = GetPlanet(planet_id); if (!planet) { Logger().errorStream() << "AIInterface::IssueInvadeOrder : no planet with passed planet_id"; return 0; } bool owned_by_invader = planet->OwnedBy(empire_id); bool unowned = planet->Unowned(); bool populated = planet->CurrentMeterValue(METER_POPULATION) > 0.; bool visible = GetUniverse().GetObjectVisibilityByEmpire(planet_id, empire_id) >= VIS_PARTIAL_VISIBILITY; bool vulnerable = planet->CurrentMeterValue(METER_SHIELD) <= 0.; float shields = planet->CurrentMeterValue(METER_SHIELD); std::string thisSpecies = planet->SpeciesName(); //bool being_invaded = planet->IsAboutToBeInvaded(); bool invadable = !owned_by_invader && vulnerable && (populated || !unowned) && visible ;// && !being_invaded; a 'being_invaded' check prevents AI from invading with multiple ships at once, which is important if (!invadable) { Logger().errorStream() << "AIInterface::IssueInvadeOrder : planet with passed planet_id "<< planet_id <<" and species "<<thisSpecies<<" is " << "not invadable due to one or more of: owned by invader empire, " << "not visible to invader empire, has shields above zero, " << "or is already being invaded."; if (!unowned) Logger().errorStream() << "AIInterface::IssueInvadeOrder : planet (id " << planet_id << ") is not unowned"; if (!visible) Logger().errorStream() << "AIInterface::IssueInvadeOrder : planet (id " << planet_id << ") is not visible"; if (!vulnerable) Logger().errorStream() << "AIInterface::IssueInvadeOrder : planet (id " << planet_id << ") is not vulnerable, shields at "<<shields; return 0; } // verify that planet is in same system as the fleet if (planet->SystemID() != fleet->SystemID()) { Logger().errorStream() << "AIInterface::IssueInvadeOrder : fleet and planet are not in the same system"; return 0; } if (ship->SystemID() == INVALID_OBJECT_ID) { Logger().errorStream() << "AIInterface::IssueInvadeOrder : ship is not in a system"; return 0; } AIClientApp::GetApp()->Orders().IssueOrder(OrderPtr(new InvadeOrder(empire_id, ship_id, planet_id))); return 1; }