FreeOrion

Forums for the FreeOrion project
It is currently Tue May 21, 2013 8:36 am

All times are UTC




Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: count supply map
PostPosted: Sun Jul 01, 2007 8:01 pm 
Offline
Space Krill

Joined: Sat Jun 23, 2007 1:55 pm
Posts: 8
Missing interupt for enemy colony. Also comparator can have better place.
Code:
Index: Empire.cpp
===================================================================
--- Empire.cpp  (revision 2106)
+++ Empire.cpp  (working copy)
@@ -878,7 +878,59 @@
     return m_sitrep_entries.size();
}

+const std::map<const System*,int>& Empire::GetSupplyableSystems()
+{
+       Universe::ObjectVec object_vec = GetUniverse().FindObjects(OwnedVisitor<UniverseObject>(m_id));
+       //erase previous result - TODO erase only after begin turn
+       m_sup_systems.clear();
+       std::multimap<const int,const System*,Empire::reverseComparator> sortedSystems;
+       //find all ResourceCenter and add it to pop_vec
+       for (unsigned i=0; i< object_vec.size();i++){
+               if (dynamic_cast<ResourceCenter*>(object_vec[i])){
+                       //TODO add supply rating information from system, when is implemented
+                       const System* sys = object_vec[i]->GetSystem();
+                       sortedSystems.insert(std::pair<const int,const System*>(3,sys));
+                       //TODO add real count
+                       m_sup_systems.insert(std::pair<const System*,int>(sys,1000));
+               }
+       }
+       //process wave until reach all systems
+       //TODO remove interupted supply route system - enemy fleet and colony
+       while (!sortedSystems.empty()){
+               std::multimap<const int, const System*, reverseComparator>::iterator it = sortedSystems.begin();
+               System::const_lane_iterator end = it->second->end_lanes();
+               for (System::const_lane_iterator csi = it->second->begin_lanes(); csi!= end;csi++){
+                       const System* system = dynamic_cast<const System*>(GetUniverse().Object(csi->first));
+                       bool add = HasExploredSystem(csi->first);
+                       if (add){
+                               System::ConstObjectVec fleets = system->FindObjects(StationaryFleetVisitor());
+                               System::ConstObjectVec::iterator end = fleets.end();
+                               for (System::ConstObjectVec::iterator it=fleets.begin();it!=end;it++){
+                                       //empire isn't beetween owner of fleet
+                                       if (!((*it)->Owners().count(m_id))){
+                                               add=false;
+                                               break;
+                                       }
+                               }
+                       }
+                       //test if system isn`t allready added or is end of wave or isn`t explored
+                       if (add && m_sup_systems.insert(std::pair<const System*,int>(system,1000)).second && it->first){
+                               //OK, new system, lets wave flow
+                               sortedSystems.insert(std::pair<const int, const System*>(it->first-1,system));
+                       } else if (add) {
+                               //TODO implements how many can system produce supply
+                               if (m_sup_systems[system]>1000){
+                               m_sup_systems[system]=1000;
+                               }
+                       }
+               }
+               sortedSystems.erase(it);
+       }
+       return m_sup_systems;
+}
+
+
/**************************************
(const) Iterators over our various lists
***************************************/
Index: Empire.h
===================================================================
--- Empire.h    (revision 2106)
+++ Empire.h    (working copy)
@@ -341,6 +341,14 @@
     /// Returns the number of entries in the SitRep.
     int NumSitRepEntries() const;

+               ///returns map of systems, where ship can be resupply and amoung of supply
+               const std::map<const System*,int>& GetSupplyableSystems();
+               struct reverseComparator{
+                       bool operator()(int a, int b){
+                       return a>b;
+                       }
+               };
+
     TechItr TechBegin() const;
     TechItr TechEnd() const;
     BuildingTypeItr AvailableBuildingTypeBegin() const;
@@ -568,6 +576,9 @@
     /// progress of partially-completed builds; completed items are removed
     std::vector<double> m_production_progress;

+               /// set of supplyable systems
+               std::map<const System*,int> m_sup_systems;
+
     /// list of acquired BuildingType.  These are string names referencing Buil
dingType objects
     std::set<std::string> m_available_building_types;



Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group