From: <geo...@us...> - 2009-09-12 18:23:25
|
Revision: 3160 http://freeorion.svn.sourceforge.net/freeorion/revision/?rev=3160&view=rev Author: geoffthemedio Date: 2009-09-12 18:23:19 +0000 (Sat, 12 Sep 2009) Log Message: ----------- -Made ships only regenerate fuel when stationary, instead of whenever starting a turn in a system -Made fleet data panels show fuel regeneration meter changes and refresh tooltips of meter icons when fleets are ordered to move or to remain stationary -Made UniverseObject::ProjectedMeterPoints call ProjectedCurrentMeter so that derived objects only need to override the latter to override both -A few code cleanup or refactoring tweaks arising from recent simplifications or for convenience during the above changes -Added Bigjoe5 to credits Modified Paths: -------------- trunk/FreeOrion/Empire/Empire.cpp trunk/FreeOrion/Empire/Empire.h trunk/FreeOrion/UI/FleetWnd.cpp trunk/FreeOrion/UI/MapWnd.cpp trunk/FreeOrion/default/credits.xml trunk/FreeOrion/server/ServerApp.cpp trunk/FreeOrion/universe/Fleet.cpp trunk/FreeOrion/universe/ResourceCenter.cpp trunk/FreeOrion/universe/Ship.cpp trunk/FreeOrion/universe/UniverseObject.cpp Modified: trunk/FreeOrion/Empire/Empire.cpp =================================================================== --- trunk/FreeOrion/Empire/Empire.cpp 2009-09-11 07:31:57 UTC (rev 3159) +++ trunk/FreeOrion/Empire/Empire.cpp 2009-09-12 18:23:19 UTC (rev 3160) @@ -1661,6 +1661,24 @@ return m_supply_unobstructed_systems; } +bool Empire::FleetOrResourceSupplyableAtSystem(int system_id) const +{ + if (system_id == UniverseObject::INVALID_OBJECT_ID) + return false; + + // check fleet supplyable systems + if (m_fleet_supplyable_system_ids.find(system_id) != m_fleet_supplyable_system_ids.end()) + return true; + + // check all resource supply groups + for (std::set<std::set<int> >::const_iterator groups_it = m_resource_supply_groups.begin(); groups_it != m_resource_supply_groups.end(); ++groups_it) + if (groups_it->find(system_id) != groups_it->end()) + return true; + + // couldn't find any reason to supply specified system. default to false + return false; +} + Empire::TechItr Empire::TechBegin() const { return m_techs.begin(); Modified: trunk/FreeOrion/Empire/Empire.h =================================================================== --- trunk/FreeOrion/Empire/Empire.h 2009-09-11 07:31:57 UTC (rev 3159) +++ trunk/FreeOrion/Empire/Empire.h 2009-09-12 18:23:19 UTC (rev 3160) @@ -311,9 +311,11 @@ const std::set<std::set<int> >& ResourceSupplyGroups() const; ///< returns set of sets of systems that can share food, industry and minerals (systems in separate groups are blockaded or otherwise separated) const std::set<std::pair<int, int> >& ResourceSupplyStarlaneTraversals() const; ///< returns set of directed starlane traversals along which system resource exchange (food, industry, minerals) can flow. results are pairs of system ids of start and end of traversal - const std::set<std::pair<int, int> >& ResourceSupplyOstructedStarlaneTraversals() const; ///< returns set of directed starlane traversals along which system resources could flow for this empire, but which can't due to some obstruction in the destination system + const std::set<std::pair<int, int> >& ResourceSupplyOstructedStarlaneTraversals() const; ///< returns set of directed starlane traversals along which system resources could flow for this empire, but which can't due to some obstruction in the destination system const std::map<int, int>& ResourceSupplyRanges() const; ///< returns map from system id to number of starlane jumps away the system can exchange resources + bool FleetOrResourceSupplyableAtSystem(int system_id) const; ///< returns true if system with id \a system_id is fleet supplyable or in one of the resource supply groups of this empire. + const std::set<int>& SupplyUnobstructedSystems() const; ///< returns set of system ids that are able to propagate supply from one system to the next, or at which supply can be delivered to fleets if supply can reach the system from elsewhere /** modifies passed parameter, which is a map from system id to the range, in starlane jumps that the Modified: trunk/FreeOrion/UI/FleetWnd.cpp =================================================================== --- trunk/FreeOrion/UI/FleetWnd.cpp 2009-09-11 07:31:57 UTC (rev 3159) +++ trunk/FreeOrion/UI/FleetWnd.cpp 2009-09-12 18:23:19 UTC (rev 3160) @@ -455,7 +455,7 @@ int tooltip_delay = GetOptionsDB().Get<int>("UI.tooltip-delay"); - // meter stat icon tooltips + // meter stat icons std::vector<MeterType> meters; meters.push_back(METER_HEALTH); meters.push_back(METER_FUEL); meters.push_back(METER_DETECTION); meters.push_back(METER_STEALTH); meters.push_back(METER_SHIELD); @@ -465,31 +465,24 @@ ClientUI::MeterIcon(*it), 0, 0, false); m_stat_icons.push_back(std::make_pair(MeterStatString(*it), icon)); AttachChild(icon); - - // create tooltip explaining effects on meter if such info is available icon->SetBrowseModeTime(tooltip_delay); - boost::shared_ptr<GG::BrowseInfoWnd> browse_wnd(new MeterBrowseWnd(*it, m_ship_id)); - icon->SetBrowseInfoWnd(browse_wnd); } - // speed stat icon tooltip + // speed stat icon StatisticIcon* icon = new StatisticIcon(GG::X0, GG::Y0, StatIconWidth(), StatIconHeight(), SpeedIcon(), 0, 0, false); m_stat_icons.push_back(std::make_pair(SPEED_STAT_STRING, icon)); AttachChild(icon); - - // create tooltip explaining effects on meter if such info is available icon->SetBrowseModeTime(tooltip_delay); - const std::string speed_stat_title = UserString("SHIP_SPEED_STAT_TITLE"); - const std::string speed_stat_main = UserString("SHIP_SPEED_STAT_MAIN"); - boost::shared_ptr<GG::BrowseInfoWnd> browse_wnd(new IconTextBrowseWnd(SpeedIcon(), speed_stat_title, speed_stat_main)); - icon->SetBrowseInfoWnd(browse_wnd); // bookkeeping m_ship_connection = GG::Connect(ship->StateChangedSignal, &ShipDataPanel::Refresh, this); + if (Fleet* fleet = ship->GetFleet()) + m_fleet_connection = GG::Connect(fleet->StateChangedSignal, &ShipDataPanel::Refresh, this); + Refresh(); } } @@ -497,6 +490,7 @@ ~ShipDataPanel() { delete m_ship_icon; m_ship_connection.disconnect(); + m_fleet_connection.disconnect(); } virtual void Render() { @@ -595,19 +589,30 @@ } - // update stat icon values. browse wnds should refresh themselves every time they're shown, so don't need to be reset here + // update stat icon values and browse wnds GG::Pt icon_ul(GG::X(ICON_SIZE) + GG::X(PAD), LabelHeight()); for (std::vector<std::pair<std::string, StatisticIcon*> >::const_iterator it = m_stat_icons.begin(); it != m_stat_icons.end(); ++it) { //std::cout << "setting ship stat " << it->first << " to value: " << StatValue(it->first) << std::endl; it->second->SetValue(StatValue(it->first)); + + it->second->ClearBrowseInfoWnd(); + if (it->first == SPEED_STAT_STRING) { + const std::string speed_stat_title = UserString("SHIP_SPEED_STAT_TITLE"); + const std::string speed_stat_main = UserString("SHIP_SPEED_STAT_MAIN"); + boost::shared_ptr<GG::BrowseInfoWnd> browse_wnd(new IconTextBrowseWnd(SpeedIcon(), speed_stat_title, speed_stat_main)); + it->second->SetBrowseInfoWnd(browse_wnd); + } else { + MeterType meter_type = MeterTypeFromStatString(it->first); + boost::shared_ptr<GG::BrowseInfoWnd> browse_wnd(new MeterBrowseWnd(meter_type, m_ship_id)); + it->second->SetBrowseInfoWnd(browse_wnd); + } } DoLayout(); } - double StatValue(const std::string& stat_name) const - { + double StatValue(const std::string& stat_name) const { if (const Ship* ship = GetUniverse().Object<Ship>(m_ship_id)) { if (stat_name == SPEED_STAT_STRING) { return ship->Speed(); @@ -659,6 +664,7 @@ bool m_selected; boost::signals::connection m_ship_connection; + boost::signals::connection m_fleet_connection; }; Modified: trunk/FreeOrion/UI/MapWnd.cpp =================================================================== --- trunk/FreeOrion/UI/MapWnd.cpp 2009-09-11 07:31:57 UTC (rev 3159) +++ trunk/FreeOrion/UI/MapWnd.cpp 2009-09-12 18:23:19 UTC (rev 3160) @@ -957,6 +957,15 @@ } + //// re-update meter estimates of ships after resource pools and fleet supply + //// have been updated, so that resupply can be taken into account when + //// predicting meter values on ships + //std::vector<int> ship_ids = universe.FindObjectIDs<Ship>(); + //UpdateMeterEstimates(ship_ids); + // (Apparently not needed?) + + + // set up system icons, starlanes, galaxy gas rendering InitTurnRendering(); @@ -3718,8 +3727,9 @@ return; } - // collect objects to update meter for. this may be a single object, a group of related objects, or all objects - // in the (known) universe. also clear effect accounting for meters that are to be updated. + // collect objects to update meters of. this may be a single object, a + // group of related objects, or all objects in the (known) universe. + // also clear effect accounting for meters that are to be updated. std::set<int> objects_set; std::list<int> objects_list; objects_list.push_back(object_id); @@ -3750,12 +3760,14 @@ } void MapWnd::UpdateMeterEstimates(const std::vector<int>& objects_vec) { - // add this player ownership to all planets in the objects_vec that aren't currently colonized. - // this way, any effects the player knows about that would act on those planets if the player colonized them - // include those planets in their scope. This lets effects from techs the player knows alter the max - // population of planet that is displayed to the player, even if those effects have a condition that causes - // them to only act on planets the player owns (so as to not improve enemy planets if a player reseraches a - // tech that should only benefit him/herself) + // add this player ownership to all planets in the objects_vec that aren't + // currently colonized. this way, any effects the player knows about that + // would act on those planets if the player colonized them include those + // planets in their scope. This lets effects from techs the player knows + // alter the max population of planet that is displayed to the player, even + // if those effects have a condition that causes them to only act on + // planets the player owns (so as to not improve enemy planets if a player + // reseraches a tech that should only benefit him/herself) int player_id = HumanClientApp::GetApp()->PlayerID(); Modified: trunk/FreeOrion/default/credits.xml =================================================================== --- trunk/FreeOrion/default/credits.xml 2009-09-11 07:31:57 UTC (rev 3159) +++ trunk/FreeOrion/default/credits.xml 2009-09-12 18:23:19 UTC (rev 3160) @@ -43,6 +43,7 @@ <PERSON name="Bryan Patterson" nick="PowerCrazy" task="Game Design"/> <PERSON name="Andrew Hull" nick="moxy" task="Game Design"/> <PERSON name="Benjamin Confino" nick="Tortanick" task="Game Design"/> + <PERSON name="Isaac Supeene" nick="Bigjoe5" task="Game Design"/> </GROUP> <GROUP name ="GRAPHICS"> <PERSON name="Mathias Köhler" nick="pd" task="Graphics Lead"/> Modified: trunk/FreeOrion/server/ServerApp.cpp =================================================================== --- trunk/FreeOrion/server/ServerApp.cpp 2009-09-11 07:31:57 UTC (rev 3159) +++ trunk/FreeOrion/server/ServerApp.cpp 2009-09-12 18:23:19 UTC (rev 3160) @@ -502,8 +502,9 @@ } namespace { - /** returns true if \a empire has been eliminated by the applicable definition of elimination. As of this writing, - elimination means having no ships and no fleets. */ + /** returns true if \a empire has been eliminated by the applicable + * definition of elimination. As of this writing, elimination means + * having no ships and no fleets. */ bool EmpireEliminated(const Empire* empire, const Universe& universe) { if (!empire) return false; Modified: trunk/FreeOrion/universe/Fleet.cpp =================================================================== --- trunk/FreeOrion/universe/Fleet.cpp 2009-09-11 07:31:57 UTC (rev 3159) +++ trunk/FreeOrion/universe/Fleet.cpp 2009-09-12 18:23:19 UTC (rev 3160) @@ -19,6 +19,18 @@ return !GetUniverse().SystemReachable(system->ID(), empire_id); } + /** returns true iff one of the empires with the indiated ids can provide + * fleet supply directly or has resource connections to the system with + * the id \a system_id + * in short: decides whether a fleet gets resupplied at the indicated + * system*/ + bool FleetOrResourceSupplyableAtSystemByAnyOfEmpiresWithIDs(int system_id, const std::set<int>& owner_ids) { + for (std::set<int>::const_iterator it = owner_ids.begin(); it != owner_ids.end(); ++it) + if (const Empire* empire = Empires().Lookup(*it)) + if (empire->FleetOrResourceSupplyableAtSystem(system_id)) + return true; + return false; + } } // static(s) @@ -685,47 +697,20 @@ void Fleet::MovementPhase() { //Logger().debugStream() << "Fleet::MovementPhase this: " << this->Name() << " id: " << this->ID(); - - std::list<MovePathNode> move_path = this->MovePath(); - - System* current_system = GetSystem(); Universe& universe = GetUniverse(); - - // get systems at which this fleet can be resupplied - std::set<int> fleet_supplied_systems; - const std::set<int>& owners = Owners(); - for (std::set<int>::const_iterator it = owners.begin(); it != owners.end(); ++it) { - if (const Empire* empire = Empires().Lookup(*it)) { - // add systems that receive fleet supply - const std::set<int>& empire_fleet_supplied_systems = empire->FleetSupplyableSystemIDs(); - fleet_supplied_systems.insert(empire_fleet_supplied_systems.begin(), empire_fleet_supplied_systems.end()); - - // also add any system that is connected to a planet for resource sharing purposes - const std::set<std::set<int> >& empire_resource_supply_groups = empire->ResourceSupplyGroups(); - for (std::set<std::set<int> >::const_iterator set_set_it = empire_resource_supply_groups.begin(); set_set_it != empire_resource_supply_groups.end(); ++set_set_it) - fleet_supplied_systems.insert(set_set_it->begin(), set_set_it->end()); + // find if any of owners of fleet can resupply ships at the location of this fleet + if (FleetOrResourceSupplyableAtSystemByAnyOfEmpiresWithIDs(this->SystemID(), this->Owners())) { + // resupply all ships + for (Fleet::const_iterator ship_it = this->begin(); ship_it != this->end(); ++ship_it) { + Ship* ship = universe.Object<Ship>(*ship_it); + assert(ship); + ship->Resupply(); } } - //Logger().debugStream() << "Fleet Supplied Systems:"; - //for (std::set<int>::const_iterator it = fleet_supplied_systems.begin(); it != fleet_supplied_systems.end(); ++it) - // Logger().debugStream() << " ... " << *it << " is supplied"; + std::list<MovePathNode> move_path = this->MovePath(); - // resupply fleet if possible - if (current_system) { - //Logger().debugStream() << "Fleet current system: " << current_system->Name() << " id: " << current_system->ID(); - // resupply ships, if fleet is supplyable at this location - if (fleet_supplied_systems.find(current_system->ID()) != fleet_supplied_systems.end()) { - for (Fleet::const_iterator ship_it = this->begin(); ship_it != this->end(); ++ship_it) { - Ship* ship = universe.Object<Ship>(*ship_it); - assert(ship); - ship->Resupply(); - } - } - } - - if (move_path.empty() || move_path.size() == 1) { //Logger().debugStream() << "Fleet::MovementPhase: Fleet move path is empty or has only one entry. doing nothing"; return; @@ -735,6 +720,8 @@ //for (std::list<MovePathNode>::const_iterator it = move_path.begin(); it != move_path.end(); ++it) // Logger().debugStream() << "... (" << it->x << ", " << it->y << ") at object id: " << it->object_id << " eta: " << it->eta << (it->turn_end ? " (end of turn)" : " (during turn)"); + System* current_system = GetSystem(); + const std::set<int>& owners = this->Owners(); std::list<MovePathNode>::const_iterator it = move_path.begin(); @@ -777,7 +764,7 @@ m_prev_system = system->ID(); // passing a system, so update previous system of this fleet - bool resupply_here = (fleet_supplied_systems.find(system->ID()) != fleet_supplied_systems.end()); + bool resupply_here = FleetOrResourceSupplyableAtSystemByAnyOfEmpiresWithIDs(system->ID(), this->Owners()); // if this system can provide supplies, reset consumed fuel and refuel ships if (resupply_here) { Modified: trunk/FreeOrion/universe/ResourceCenter.cpp =================================================================== --- trunk/FreeOrion/universe/ResourceCenter.cpp 2009-09-11 07:31:57 UTC (rev 3159) +++ trunk/FreeOrion/universe/ResourceCenter.cpp 2009-09-12 18:23:19 UTC (rev 3160) @@ -53,21 +53,16 @@ return retval; } - void GrowResourceMeter(Meter* resource_meter, double updated_current_construction) + void GrowResourceMeter(Meter* resource_meter) { assert(resource_meter); - double initial_current = resource_meter->InitialCurrent(); - double delta = 1.0; resource_meter->AdjustCurrent(delta); } - void GrowConstructionMeter(Meter* construction_meter, double updated_current_population) + void GrowConstructionMeter(Meter* construction_meter) { assert(construction_meter); - double initial_current = construction_meter->InitialCurrent(); - double initial_max = construction_meter->InitialMax(); - double delta = 1.0; construction_meter->AdjustCurrent(delta); } @@ -103,14 +98,14 @@ case METER_INDUSTRY: case METER_RESEARCH: case METER_TRADE: - GrowConstructionMeter(&construction, GetPopMeter()->Current()); + GrowConstructionMeter(&construction); construction.Clamp(); - GrowResourceMeter(&meter, construction.Current()); + GrowResourceMeter(&meter); meter.Clamp(); return meter.Current(); break; case METER_CONSTRUCTION: - GrowConstructionMeter(&construction, GetPopMeter()->Current()); + GrowConstructionMeter(&construction); construction.Clamp(); return construction.Current(); break; @@ -226,13 +221,13 @@ void ResourceCenter::PopGrowthProductionResearchPhase() { - GrowConstructionMeter(GetMeter(METER_CONSTRUCTION), GetPopMeter()->Current()); + GrowConstructionMeter(GetMeter(METER_CONSTRUCTION)); double new_current_construction = GetMeter(METER_CONSTRUCTION)->Current(); - GrowResourceMeter(GetMeter(METER_FARMING), new_current_construction); - GrowResourceMeter(GetMeter(METER_INDUSTRY), new_current_construction); - GrowResourceMeter(GetMeter(METER_MINING), new_current_construction); - GrowResourceMeter(GetMeter(METER_RESEARCH), new_current_construction); - GrowResourceMeter(GetMeter(METER_TRADE), new_current_construction); + GrowResourceMeter(GetMeter(METER_FARMING)); + GrowResourceMeter(GetMeter(METER_INDUSTRY)); + GrowResourceMeter(GetMeter(METER_MINING)); + GrowResourceMeter(GetMeter(METER_RESEARCH)); + GrowResourceMeter(GetMeter(METER_TRADE)); } void ResourceCenter::Reset() Modified: trunk/FreeOrion/universe/Ship.cpp =================================================================== --- trunk/FreeOrion/universe/Ship.cpp 2009-09-11 07:31:57 UTC (rev 3159) +++ trunk/FreeOrion/universe/Ship.cpp 2009-09-12 18:23:19 UTC (rev 3160) @@ -1,16 +1,31 @@ #include "Ship.h" #include "../util/AppInterface.h" +#include "../util/MultiplayerCommon.h" #include "Fleet.h" -#include "../util/MultiplayerCommon.h" #include "Predicates.h" #include "ShipDesign.h" +#include "../Empire/Empire.h" +#include "../Empire/EmpireManager.h" namespace { void GrowFuelMeter(Meter* fuel_meter) { assert(fuel_meter); - fuel_meter->AdjustCurrent(0.1); + fuel_meter->AdjustCurrent(0.1001); } + + /** returns true iff one of the empires with the indiated ids can provide + * fleet supply directly or has resource connections to the system with + * the id \a system_id + * in short: decides whether a fleet gets resupplied at the indicated + * system*/ + bool FleetOrResourceSupplyableAtSystemByAnyOfEmpiresWithIDs(int system_id, const std::set<int>& owner_ids) { + for (std::set<int>::const_iterator it = owner_ids.begin(); it != owner_ids.end(); ++it) + if (const Empire* empire = Empires().Lookup(*it)) + if (empire->FleetOrResourceSupplyableAtSystem(system_id)) + return true; + return false; + } } Ship::Ship() : @@ -114,7 +129,29 @@ } double Ship::ProjectedCurrentMeter(MeterType type) const { - return UniverseObject::ProjectedCurrentMeter(type); + const Meter* original_meter = GetMeter(type); + assert(original_meter); + Meter meter = Meter(*original_meter); + const Fleet* fleet = this->GetFleet(); + assert(fleet); + + switch (type) { + case METER_FUEL: + if (FleetOrResourceSupplyableAtSystemByAnyOfEmpiresWithIDs(fleet->SystemID(), fleet->Owners())) { + // fleets at systems where they can be supplied are fully resupplied + meter.SetCurrent(meter.Max()); + } else if (fleet->FinalDestinationID() == UniverseObject::INVALID_OBJECT_ID || + fleet->FinalDestinationID() == fleet->SystemID()) + { + // fleets that are stationary regenerate fuel slowly + GrowFuelMeter(&meter); + } + meter.Clamp(); + return meter.Current(); + break; + default: + return UniverseObject::ProjectedCurrentMeter(type); + } } void Ship::SetFleetID(int fleet_id) @@ -182,5 +219,12 @@ } void Ship::PopGrowthProductionResearchPhase() { - GrowFuelMeter(GetMeter(METER_FUEL)); + // fuel regeneration if stationary + if (Fleet* fleet = this->GetFleet()) { + if (fleet->FinalDestinationID() == UniverseObject::INVALID_OBJECT_ID || + fleet->FinalDestinationID() == fleet->SystemID()) + { + GrowFuelMeter(GetMeter(METER_FUEL)); + } + } } Modified: trunk/FreeOrion/universe/UniverseObject.cpp =================================================================== --- trunk/FreeOrion/universe/UniverseObject.cpp 2009-09-11 07:31:57 UTC (rev 3159) +++ trunk/FreeOrion/universe/UniverseObject.cpp 2009-09-12 18:23:19 UTC (rev 3160) @@ -154,11 +154,7 @@ double UniverseObject::ProjectedMeterPoints(MeterType type) const { - // Note that this is the default implementation. Derived classes might do something different. - std::map<MeterType, Meter>::const_iterator it = m_meters.find(type); - if (it == m_meters.end()) - throw std::invalid_argument("UniverseObject::ProjectedMeterPoints was passed a MeterType that this UniverseObject does not have"); - return it->second.Current(); + return ProjectedCurrentMeter(type); } void UniverseObject::InsertMeter(MeterType meter_type, const Meter& meter) |