1 #ifndef _Supply_h_ 2 #define _Supply_h_ 3 4 #include "../util/Export.h" 5 6 #include <boost/serialization/access.hpp> 7 8 #include <map> 9 #include <set> 10 #include <string> 11 12 FO_COMMON_API extern const int ALL_EMPIRES; 13 14 /** Used to calcuate all empires' supply distributions. */ 15 class FO_COMMON_API SupplyManager { 16 public: 17 /** \name Structors */ //@{ 18 SupplyManager(); 19 SupplyManager& operator=(const SupplyManager& rhs); 20 //@} 21 22 /** \name Accessors */ //@{ 23 /** Returns set of directed starlane traversals along which supply can flow. 24 * Results are pairs of system ids of start and end system of traversal. */ 25 const std::map<int, std::set<std::pair<int, int>>>& SupplyStarlaneTraversals() const; 26 const std::set<std::pair<int, int>>& SupplyStarlaneTraversals(int empire_id) const; 27 28 /** Returns set of directed starlane traversals along which supply could 29 * flow for this empire, but which can't due to some obstruction in one 30 * of the systems. */ 31 const std::map<int, std::set<std::pair<int, int>>>& SupplyObstructedStarlaneTraversals() const; 32 const std::set<std::pair<int, int>>& SupplyObstructedStarlaneTraversals(int empire_id) const; 33 34 /** Returns set of system ids where fleets can be supplied by this empire 35 * (as determined by object supply meters and rules of supply propagation 36 * and blockade). */ 37 const std::map<int, std::set<int>>& FleetSupplyableSystemIDs() const; 38 const std::set<int>& FleetSupplyableSystemIDs(int empire_id) const; 39 std::set<int> FleetSupplyableSystemIDs(int empire_id, bool include_allies) const; 40 int EmpireThatCanSupplyAt(int system_id) const; 41 42 /** Returns set of sets of systems that can share industry (systems in 43 * separate groups are blockaded or otherwise separated). */ 44 const std::map<int, std::set<std::set<int>>>& ResourceSupplyGroups() const; 45 const std::set<std::set<int>>& ResourceSupplyGroups(int empire_id) const; 46 47 /** Returns the range from each system some empire can propagate supply.*/ 48 const std::map<int, float>& PropagatedSupplyRanges() const; 49 /** Returns the range from each system that the empire with id \a empire_id 50 * can propagate supply.*/ 51 const std::map<int, float>& PropagatedSupplyRanges(int empire_id) const; 52 53 /** Returns the distance from each system some empire is away 54 * from its closest source of supply without passing 55 * through obstructed systems for that empire. */ 56 const std::map<int, float>& PropagatedSupplyDistances() const; 57 /** Returns the distance from each system for the empire with id 58 * \a empire_id to the closest source of supply without passing 59 * through obstructed systems for that empire. */ 60 const std::map<int, float>& PropagatedSupplyDistances(int empire_id) const; 61 62 /** Returns true if system with id \a system_id is fleet supplyable or in 63 * one of the resource supply groups for empire with id \a empire_id */ 64 bool SystemHasFleetSupply(int system_id, int empire_id) const; 65 bool SystemHasFleetSupply(int system_id, int empire_id, bool include_allies) const; 66 67 std::string Dump(int empire_id = ALL_EMPIRES) const; 68 //@} 69 70 /** \name Mutators */ //@{ 71 /** Calculates systems at which fleets of empires can be supplied, and 72 * groups of systems that can exchange resources, and the starlane 73 * traversals used to do so. */ 74 void Update(); 75 //@} 76 77 private: 78 /** ordered pairs of system ids between which a starlane runs that can be 79 used to convey resources between systems. indexed first by empire id. */ 80 std::map<int, std::set<std::pair<int, int>>> m_supply_starlane_traversals; 81 82 /** ordered pairs of system ids between which a starlane could be used to 83 convey resources between system, but is not because something is 84 obstructing the resource flow. That is, the resource flow isn't limited 85 by range, but by something blocking its flow. */ 86 std::map<int, std::set<std::pair<int, int>>> m_supply_starlane_obstructed_traversals; 87 88 /** ids of systems where fleets can be resupplied. indexed by empire id. */ 89 std::map<int, std::set<int>> m_fleet_supplyable_system_ids; 90 91 /** sets of system ids that are connected by supply lines and are able to 92 share resources between systems or between objects in systems. indexed 93 by empire id. */ 94 std::map<int, std::set<std::set<int>>> m_resource_supply_groups; 95 96 /** for whichever empire can propagate supply into this system, what is the 97 additional range from this system that empire can propagate supply */ 98 std::map<int, float> m_propagated_supply_ranges; 99 100 /** for each empire, what systems it can propagate supply into, and how many 101 * further supply jumps it could propagate past this system, if not blocked 102 * from doing so by supply obstructions. */ 103 std::map<int, std::map<int, float>> m_empire_propagated_supply_ranges; 104 105 /** for whichever empire can propagate supply into this system, how far 106 * that system is from the closest source of supply for that empire, along 107 * possible supply propgation connections (ie. not though a supply 108 * obstructed system for that empire) */ 109 std::map<int, float> m_propagated_supply_distances; 110 111 /** for each empire, what systems it can propagate supply into, and how far 112 * that system is from the closest source of supply for that empire, along 113 * possible supply propgation connections (ie. not though a supply 114 * obstructed system) */ 115 std::map<int, std::map<int, float>> m_empire_propagated_supply_distances; 116 117 118 friend class boost::serialization::access; 119 template <typename Archive> 120 void serialize(Archive& ar, const unsigned int version); 121 }; 122 123 #endif // _Supply_h_ 124