void Planet::Reset() { // remove owner SetOwner(ALL_EMPIRES); // reset popcenter meters PopCenter::Reset(); // reset resourcecenter meters ResourceCenter::Reset(); // reset planet meters GetMeter(METER_SUPPLY)->Reset(); GetMeter(METER_SHIELD)->Reset(); GetMeter(METER_MAX_SHIELD)->Reset(); GetMeter(METER_DEFENSE)->Reset(); GetMeter(METER_MAX_DEFENSE)->Reset(); GetMeter(METER_DETECTION)->Reset(); GetMeter(METER_REBEL_TROOPS)->Reset(); // reset buildings for (std::set<int>::const_iterator it = m_buildings.begin(); it != m_buildings.end(); ++it) if (Building* building = GetBuilding(*it)) building->Reset(); // reset other state m_available_trade = 0.0; m_just_conquered = false; m_is_about_to_be_colonized = false; m_is_about_to_be_invaded = false; }
void Planet::Reset() { PopCenter::Reset(); ResourceCenter::Reset(); GetMeter(METER_SUPPLY)->Reset(); GetMeter(METER_MAX_SUPPLY)->Reset(); GetMeter(METER_SHIELD)->Reset(); GetMeter(METER_MAX_SHIELD)->Reset(); GetMeter(METER_DEFENSE)->Reset(); GetMeter(METER_MAX_DEFENSE)->Reset(); GetMeter(METER_DETECTION)->Reset(); GetMeter(METER_REBEL_TROOPS)->Reset(); if (m_is_about_to_be_colonized && !OwnedBy(ALL_EMPIRES)) { for (int building_id : m_buildings) if (auto building = GetBuilding(building_id)) building->Reset(); } m_just_conquered = false; m_is_about_to_be_colonized = false; m_is_about_to_be_invaded = false; m_is_about_to_be_bombarded = false; SetOwner(ALL_EMPIRES); }
void Planet::Reset() { PopCenter::Reset(); ResourceCenter::Reset(); GetMeter(METER_SUPPLY)->Reset(); GetMeter(METER_MAX_SUPPLY)->Reset(); GetMeter(METER_SHIELD)->Reset(); GetMeter(METER_MAX_SHIELD)->Reset(); GetMeter(METER_DEFENSE)->Reset(); GetMeter(METER_MAX_DEFENSE)->Reset(); GetMeter(METER_DETECTION)->Reset(); GetMeter(METER_REBEL_TROOPS)->Reset(); if (m_is_about_to_be_colonized && !OwnedBy(ALL_EMPIRES)) { for (std::set<int>::const_iterator it = m_buildings.begin(); it != m_buildings.end(); ++it) if (TemporaryPtr<Building> building = GetBuilding(*it)) building->Reset(); } m_just_conquered = false; m_is_about_to_be_colonized = false; m_is_about_to_be_invaded = false; m_is_about_to_be_bombarded = false; SetOwner(ALL_EMPIRES); }
bool Map::IsEmpty(int x, int y) { Building *bd = GetBuilding(x, y); if (bd->GetType() == NONE) return true; else return false; }
void Map::DestroyBuilding(int x, int y) { Building *bd = GetBuilding(x, y); if (bd->GetType() != NONE) { bd->Destroy(); std::cout << "Building destroyed.\n"; } }
BuildingIndicator::BuildingIndicator(GG::X w, int building_id) : GG::Wnd(GG::X0, GG::Y0, w, GG::Y(Value(w)), GG::INTERACTIVE), m_graphic(0), m_scrap_indicator(0), m_progress_bar(0), m_building_id(building_id), m_order_issuing_enabled(true) { if (TemporaryPtr<const Building> building = GetBuilding(m_building_id)) GG::Connect(building->StateChangedSignal, &BuildingIndicator::Refresh, this); Refresh(); }
int8_t PlayerCity::AddToBarracksQueue(int8_t position, int16_t troopid, int32_t count, bool isshare, bool isidle) { stTroopQueue * queue = GetBarracksQueue(position); stBuilding * bldg = GetBuilding(position); if (queue->queue.size() >= bldg->level) { return -1; } stBuildingConfig * conf = &m_client->m_main->m_troopconfig[troopid]; stTroopTrain troops; troops.troopid = troopid; troops.count = count; double costtime = conf->time; double mayorinf = 1; if (position == -2) { if (m_mayor) mayorinf = pow(0.995, m_mayor->GetManagement()); costtime = ( costtime ) * ( mayorinf ) * ( pow(0.9, m_client->GetResearchLevel(T_CONSTRUCTION)) ); } else { if (m_mayor) mayorinf = pow(0.995, m_mayor->GetPower()); switch (troopid) { case TR_CATAPULT: case TR_RAM: case TR_TRANSPORTER: case TR_BALLISTA: costtime = ( costtime ) * ( mayorinf ) * ( pow(0.9, m_client->GetResearchLevel(T_METALCASTING)) ); default: costtime = ( costtime ) * ( mayorinf ) * ( pow(0.9, m_client->GetResearchLevel(T_MILITARYSCIENCE)) ); } } troops.costtime = floor(costtime) * count * 1000; troops.starttime = unixtime(); troops.queueid = queue->nextqueueid++; if (queue->queue.size() > 0) troops.endtime = 0; else troops.endtime = unixtime() + troops.costtime; queue->queue.push_back(troops); return 1; }
void BuildingIndicator::Refresh() { if (!s_scanline_shader && GetOptionsDB().Get<bool>("UI.system-fog-of-war")) { boost::filesystem::path shader_path = GetRootDataDir() / "default" / "shaders" / "scanlines.frag"; std::string shader_text; ReadFile(shader_path, shader_text); s_scanline_shader = boost::shared_ptr<ShaderProgram>( ShaderProgram::shaderProgramFactory("", shader_text)); } SetBrowseModeTime(GetOptionsDB().Get<int>("UI.tooltip-delay")); TemporaryPtr<const Building> building = GetBuilding(m_building_id); if (!building) return; ClearBrowseInfoWnd(); if (m_graphic) { delete m_graphic; m_graphic = 0; } if (m_scrap_indicator) { delete m_scrap_indicator; m_scrap_indicator = 0; } if (const BuildingType* type = GetBuildingType(building->BuildingTypeName())) { boost::shared_ptr<GG::Texture> texture = ClientUI::BuildingIcon(type->Name()); m_graphic = new GG::StaticGraphic(texture, GG::GRAPHIC_FITGRAPHIC | GG::GRAPHIC_PROPSCALE); AttachChild(m_graphic); std::string desc = UserString(type->Description()); if (building->GetMeter(METER_STEALTH)) desc = UserString("METER_STEALTH") + boost::io::str(boost::format(": %3.1f\n\n") % building->GetMeter(METER_STEALTH)->Current()) + desc; if (GetOptionsDB().Get<bool>("UI.autogenerated-effects-descriptions") && !type->Effects().empty()) desc += boost::io::str(FlexibleFormat(UserString("ENC_EFFECTS_STR")) % AutoGeneratedDescription(type->Effects())); SetBrowseInfoWnd(boost::shared_ptr<GG::BrowseInfoWnd>( new IconTextBrowseWnd(texture, UserString(type->Name()), desc))); } if (building && building->OrderedScrapped()) { boost::shared_ptr<GG::Texture> scrap_texture = ClientUI::GetTexture(ClientUI::ArtDir() / "misc" / "scrapped.png", true); m_scrap_indicator = new GG::StaticGraphic(scrap_texture, GG::GRAPHIC_FITGRAPHIC | GG::GRAPHIC_PROPSCALE); AttachChild(m_scrap_indicator); } DoLayout(); }
int Map::CreateBuilding(int x, int y, BUILDINGTYPE type, OWNER owner) { Building *bd = GetBuilding(x, y); if (bd->GetType() == NONE) { bd->Create(type, owner); std::cout << "Building created.\n"; return 1; } else { /*std::cout << "Cannot build.\n";*/ return 0; } }
bool ScrapOrder::UndoImpl() const { ValidateEmpireID(); int empire_id = EmpireID(); if (TemporaryPtr<Ship> ship = GetShip(m_object_id)) { if (ship->OwnedBy(empire_id)) ship->SetOrderedScrapped(false); } else if (TemporaryPtr<Building> building = GetBuilding(m_object_id)) { if (building->OwnedBy(empire_id)) building->SetOrderedScrapped(false); } else { return false; } return true; }
void Map::Init(libconfig::Config *conf) { // Clear map for (int x = 0; x < TILES_X; x++) { for (int y = 0; y < TILES_Y; y++) { m_buildings[x][y] = new Building(); } } // Create core Building *bd = GetBuilding(1, 1); bd->Create(CORE, PLR1); m_conf = conf; std::cout << "Map Init done.\n"; }
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); } } }
void Planet::AddBuilding(int building_id) { if (this->Contains(building_id)) { Logger().debugStream() << "Planet::AddBuilding this planet " << this->Name() << " already contained building " << building_id; return; } //Logger().debugStream() << "Planet::AddBuilding " << this->Name() << " adding building: " << building_id; if (Building* building = GetBuilding(building_id)) { if (System* system = GetSystem(this->SystemID())) { system->Insert(building); } else { Logger().errorStream() << "... planet is not located in a system?!?!"; building->MoveTo(X(), Y()); building->SetSystem(SystemID()); } building->SetPlanetID(ID()); m_buildings.insert(building_id); } else { Logger().errorStream() << "Planet::AddBuilding() : Attempted to add an id of a non-building object to a planet."; } StateChangedSignal(); }
bool Planet::Colonize(int empire_id, const std::string& species_name, double population) { const Species* species = nullptr; // if desired pop > 0, we want a colony, not an outpost, so we need to do some checks if (population > 0.0) { // check if specified species exists and get reference species = GetSpecies(species_name); if (!species) { ErrorLogger() << "Planet::Colonize couldn't get species already on planet with name: " << species_name; return false; } // check if specified species can colonize this planet if (EnvironmentForSpecies(species_name) < PE_HOSTILE) { ErrorLogger() << "Planet::Colonize: can't colonize planet already populated by species " << species_name; return false; } } // reset the planet to unowned/unpopulated if (!OwnedBy(empire_id)) { Reset(); } else { PopCenter::Reset(); for (int building_id : m_buildings) if (auto building = GetBuilding(building_id)) building->Reset(); m_just_conquered = false; m_is_about_to_be_colonized = false; m_is_about_to_be_invaded = false; m_is_about_to_be_bombarded = false; SetOwner(ALL_EMPIRES); } // if desired pop > 0, we want a colony, not an outpost, so we have to set the colony species if (population > 0.0) SetSpecies(species_name); // find a default focus. use first defined available focus. // AvailableFoci function should return a vector of all names of // available foci. std::vector<std::string> available_foci = AvailableFoci(); if (species && !available_foci.empty()) { bool found_preference = false; for (const std::string& focus : available_foci) { if (!focus.empty() && focus == species->PreferredFocus()) { SetFocus(focus); found_preference = true; break; } } if (!found_preference) SetFocus(*available_foci.begin()); } else { DebugLogger() << "Planet::Colonize unable to find a focus to set for species " << species_name; } // set colony population GetMeter(METER_POPULATION)->SetCurrent(population); GetMeter(METER_TARGET_POPULATION)->SetCurrent(population); BackPropagateMeters(); // set specified empire as owner SetOwner(empire_id); // if there are buildings on the planet, set the specified empire as their owner too for (auto& building : Objects().FindObjects<Building>(BuildingIDs())) { building->SetOwner(empire_id); } return true; }
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); } }
void BuildingIndicator::RClick(const GG::Pt& pt, GG::Flags<GG::ModKey> mod_keys) { // verify that this indicator represents an existing building, and not a // queued production item, and that the owner of the building is this // client's player's empire int empire_id = HumanClientApp::GetApp()->EmpireID(); TemporaryPtr<Building> building = GetBuilding(m_building_id); if (!building) return; const MapWnd* map_wnd = ClientUI::GetClientUI()->GetMapWnd(); if (ClientPlayerIsModerator() && map_wnd->GetModeratorActionSetting() != MAS_NoAction) { RightClickedSignal(m_building_id); // response handled in MapWnd return; } GG::MenuItem menu_contents; if (!building->OrderedScrapped()) { // create popup menu with "Scrap" option menu_contents.next_level.push_back(GG::MenuItem(UserString("ORDER_BUIDLING_SCRAP"), 3, false, false)); } else { // create popup menu with "Cancel Scrap" option menu_contents.next_level.push_back(GG::MenuItem(UserString("ORDER_CANCEL_BUIDLING_SCRAP"), 4, false, false)); } const std::string& building_type = building->BuildingTypeName(); const BuildingType* bt = GetBuildingType(building_type); if (bt) { std::string popup_label = boost::io::str(FlexibleFormat(UserString("ENC_LOOKUP")) % UserString(building_type)); menu_contents.next_level.push_back(GG::MenuItem(popup_label, 5, false, false)); } GG::PopupMenu popup(pt.x, pt.y, ClientUI::GetFont(), menu_contents, ClientUI::TextColor(), ClientUI::WndOuterBorderColor(), ClientUI::WndColor(), ClientUI::EditHiliteColor()); if (popup.Run()) { switch (popup.MenuID()) { case 3: { // scrap building if (m_order_issuing_enabled) HumanClientApp::GetApp()->Orders().IssueOrder( OrderPtr(new ScrapOrder(empire_id, m_building_id))); break; } case 4: { // un-scrap building if (!m_order_issuing_enabled) break; // find order to scrap this building, and recind it std::map<int, int> pending_scrap_orders = PendingScrapOrders(); std::map<int, int>::const_iterator it = pending_scrap_orders.find(building->ID()); if (it != pending_scrap_orders.end()) { HumanClientApp::GetApp()->Orders().RecindOrder(it->second); break; } } case 5: { // pedia lookup building type ClientUI::GetClientUI()->ZoomToBuildingType(building_type); break; } default: break; } } }