From: <geo...@us...> - 2008-08-13 11:04:01
|
Revision: 2663 http://freeorion.svn.sourceforge.net/freeorion/revision/?rev=2663&view=rev Author: geoffthemedio Date: 2008-08-13 11:04:10 +0000 (Wed, 13 Aug 2008) Log Message: ----------- Fixed [ 2010995 ] Lockup if more players than star systems, by making the universe have a minimum number of systems (currently 3) per player in the game. Safety factor ensures random variations in number of stars won't be an issue, and that there are a few empty systems in the galaxy. Modified Paths: -------------- trunk/FreeOrion/universe/Universe.cpp Modified: trunk/FreeOrion/universe/Universe.cpp =================================================================== --- trunk/FreeOrion/universe/Universe.cpp 2008-08-13 08:07:30 UTC (rev 2662) +++ trunk/FreeOrion/universe/Universe.cpp 2008-08-13 11:04:10 UTC (rev 2663) @@ -2066,8 +2066,8 @@ } // end function } // end namespace #endif -void Universe::CreateUniverse(int size, Shape shape, Age age, StarlaneFrequency starlane_freq, PlanetDensity planet_density, - SpecialsFrequency specials_freq, int players, int ai_players, +void Universe::CreateUniverse(int size, Shape shape, Age age, StarlaneFrequency starlane_freq, PlanetDensity planet_density, + SpecialsFrequency specials_freq, int players, int ai_players, const std::map<int, PlayerSetupData>& player_setup_data) { #ifdef FREEORION_BUILD_SERVER @@ -2083,6 +2083,14 @@ m_last_allocated_object_id = -1; m_last_allocated_design_id = -1; + // ensure there are enough systems to give all players homeworlds + int total_players = players + ai_players; + const int MIN_SYSTEMS_PER_PLAYER = 3; + if (size < total_players*MIN_SYSTEMS_PER_PLAYER) { + Logger().debugStream() << "Universe creation requested with " << size << " systems, but this is too few for " << total_players << " players. Creating a universe with " << total_players*MIN_SYSTEMS_PER_PLAYER << " systems instead"; + size = total_players*MIN_SYSTEMS_PER_PLAYER; + } + Logger().debugStream() << "Creating universe with " << size << " stars and " << players << " players."; std::vector<int> homeworlds; |
From: <tz...@us...> - 2009-01-02 05:57:50
|
Revision: 2711 http://freeorion.svn.sourceforge.net/freeorion/revision/?rev=2711&view=rev Author: tzlaine Date: 2009-01-02 05:57:47 +0000 (Fri, 02 Jan 2009) Log Message: ----------- Switched Universe::ALL_OBJECTS_VISIBLE back to false. Tsk, tsk, Geoff. ;) Modified Paths: -------------- trunk/FreeOrion/universe/Universe.cpp Modified: trunk/FreeOrion/universe/Universe.cpp =================================================================== --- trunk/FreeOrion/universe/Universe.cpp 2009-01-01 22:30:15 UTC (rev 2710) +++ trunk/FreeOrion/universe/Universe.cpp 2009-01-02 05:57:47 UTC (rev 2711) @@ -340,7 +340,7 @@ // class Universe ///////////////////////////////////////////// // static(s) -const bool Universe::ALL_OBJECTS_VISIBLE = true; +const bool Universe::ALL_OBJECTS_VISIBLE = false; double Universe::s_universe_width = 1000.0; bool Universe::s_inhibit_universe_object_signals = false; int Universe::s_encoding_empire = ALL_EMPIRES; |
From: <geo...@us...> - 2009-05-20 02:23:02
|
Revision: 3063 http://freeorion.svn.sourceforge.net/freeorion/revision/?rev=3063&view=rev Author: geoffthemedio Date: 2009-05-20 01:48:51 +0000 (Wed, 20 May 2009) Log Message: ----------- Gave homeworlds an Orbital Drydock so that colony ships can be built from the start of the game. Modified Paths: -------------- trunk/FreeOrion/universe/Universe.cpp Modified: trunk/FreeOrion/universe/Universe.cpp =================================================================== --- trunk/FreeOrion/universe/Universe.cpp 2009-05-20 00:37:12 UTC (rev 3062) +++ trunk/FreeOrion/universe/Universe.cpp 2009-05-20 01:48:51 UTC (rev 3063) @@ -2649,7 +2649,7 @@ // pass systems to Delauney Triangulation routine, getting array of triangles back std::list<Delauney::DTTriangle>* triList = Delauney::DelauneyTriangulate(sys_vec); - if (NULL == triList) return; + if (0 == triList) return; if (triList->empty()) throw std::runtime_error("Got blank list of triangles from Triangulation."); @@ -3399,12 +3399,16 @@ home_system->AddOwner(empire_id); - // give homeworlds a shipyard so players can build ships immediately - Building* shipyard = new Building(empire_id, "BLD_SHIPYARD_BASE", UniverseObject::INVALID_OBJECT_ID); - int shipyard_id = Insert(shipyard); - home_planet->AddBuilding(shipyard_id); + // give homeworlds a shipyard and drydock so players can build scouts, colony ships and basic attack ships immediately + Building* building = new Building(empire_id, "BLD_SHIPYARD_BASE", UniverseObject::INVALID_OBJECT_ID); + int building_id = Insert(building); + home_planet->AddBuilding(building_id); + building = new Building(empire_id, "BLD_SHIPYARD_ORBITAL_DRYDOCK", UniverseObject::INVALID_OBJECT_ID); + building_id = Insert(building); + home_planet->AddBuilding(building_id); + // add homeworld special and set double balanced default focus home_planet->AddSpecial("HOMEWORLD_SPECIAL"); home_planet->SetPrimaryFocus(FOCUS_BALANCED); |
From: <geo...@us...> - 2009-09-13 00:52:34
|
Revision: 3163 http://freeorion.svn.sourceforge.net/freeorion/revision/?rev=3163&view=rev Author: geoffthemedio Date: 2009-09-13 00:52:21 +0000 (Sun, 13 Sep 2009) Log Message: ----------- Made Universe::GetEffectsAndTargets skip a tech, building, special, etc. and output error to the log file when it or its effectsgroups can't be gotten, rather than crashing. Modified Paths: -------------- trunk/FreeOrion/universe/Universe.cpp Modified: trunk/FreeOrion/universe/Universe.cpp =================================================================== --- trunk/FreeOrion/universe/Universe.cpp 2009-09-12 22:10:32 UTC (rev 3162) +++ trunk/FreeOrion/universe/Universe.cpp 2009-09-13 00:52:21 UTC (rev 3163) @@ -924,7 +924,10 @@ const std::set<std::string>& specials = it->second->Specials(); for (std::set<std::string>::const_iterator special_it = specials.begin(); special_it != specials.end(); ++special_it) { const Special* special = GetSpecial(*special_it); - assert(special); + if (!special) { + Logger().errorStream() << "GetEffectsAndTargets couldn't get Special " << *special_it; + continue; + } StoreTargetsAndCausesOfEffectsGroups(special->Effects(), source_object_id, ECT_SPECIAL, special->Name(), target_objects, targets_causes_map); @@ -936,7 +939,7 @@ const Empire* empire = it->second; for (Empire::TechItr tech_it = empire->TechBegin(); tech_it != empire->TechEnd(); ++tech_it) { const Tech* tech = GetTech(*tech_it); - assert(tech); + if (!tech) continue; StoreTargetsAndCausesOfEffectsGroups(tech->Effects(), empire->CapitolID(), ECT_TECH, tech->Name(), target_objects, targets_causes_map); @@ -947,8 +950,15 @@ std::vector<Building*> buildings = FindObjects<Building>(); for (std::vector<Building*>::const_iterator building_it = buildings.begin(); building_it != buildings.end(); ++building_it) { const Building* building = *building_it; + if (!building) { + Logger().errorStream() << "GetEffectsAndTargets couldn't get Building"; + continue; + } const BuildingType* building_type = building->GetBuildingType(); - assert(building_type); + if (!building_type) { + Logger().errorStream() << "GetEffectsAndTargets couldn't get BuildingType " << building->BuildingTypeName(); + continue; + } StoreTargetsAndCausesOfEffectsGroups(building_type->Effects(), building->ID(), ECT_BUILDING, building_type->Name(), target_objects, targets_causes_map); @@ -958,11 +968,20 @@ std::vector<Ship*> ships = FindObjects<Ship>(); for (std::vector<Ship*>::const_iterator ship_it = ships.begin(); ship_it != ships.end(); ++ship_it) { const Ship* ship = *ship_it; - assert(ship); + if (!ship) { + Logger().errorStream() << "GetEffectsAndTargets couldn't get Ship"; + continue; + } const ShipDesign* ship_design = ship->Design(); - assert(ship_design); + if (!ship_design) { + Logger().errorStream() << "GetEffectsAndTargets couldn't get ShipDesign"; + continue; + } const HullType* hull_type = ship_design->GetHull(); - assert(hull_type); + if (!hull_type) { + Logger().errorStream() << "GetEffectsAndTargets couldn't get HullType"; + continue; + } StoreTargetsAndCausesOfEffectsGroups(hull_type->Effects(), ship->ID(), ECT_SHIP_HULL, hull_type->Name(), target_objects, targets_causes_map); @@ -973,8 +992,10 @@ if (part.empty()) continue; const PartType* part_type = GetPartType(*part_it); - assert(part_type); - + if (!part_type) { + Logger().errorStream() << "GetEffectsAndTargets couldn't get PartType"; + continue; + } StoreTargetsAndCausesOfEffectsGroups(part_type->Effects(), ship->ID(), ECT_SHIP_PART, part_type->Name(), target_objects, targets_causes_map); } |
From: <geo...@us...> - 2009-12-26 00:50:42
|
Revision: 3297 http://freeorion.svn.sourceforge.net/freeorion/revision/?rev=3297&view=rev Author: geoffthemedio Date: 2009-12-26 00:50:35 +0000 (Sat, 26 Dec 2009) Log Message: ----------- Made internal updates of empire visibility also update the record of turns on which empires saw objects at various visibilities, so that ships arriving at a system on the same turn they're destroyed give (non-current) visibility of the contents of that system, and so that sitreps about fleets (that are subsequently destroyed) arriving in a system display the system name instead of "ERROR". Modified Paths: -------------- trunk/FreeOrion/universe/Universe.cpp Modified: trunk/FreeOrion/universe/Universe.cpp =================================================================== --- trunk/FreeOrion/universe/Universe.cpp 2009-12-25 19:39:09 UTC (rev 3296) +++ trunk/FreeOrion/universe/Universe.cpp 2009-12-26 00:50:35 UTC (rev 3297) @@ -1739,6 +1739,8 @@ } } } + + UpdateEmpireLatestKnownObjectsAndVisibilityTurns(); } void Universe::UpdateEmpireLatestKnownObjectsAndVisibilityTurns() |
From: <geo...@us...> - 2010-01-26 19:59:24
|
Revision: 3333 http://freeorion.svn.sourceforge.net/freeorion/revision/?rev=3333&view=rev Author: geoffthemedio Date: 2010-01-26 19:59:16 +0000 (Tue, 26 Jan 2010) Log Message: ----------- Changes to Universe.cpp missed from previous commit. Modified Paths: -------------- trunk/FreeOrion/universe/Universe.cpp Modified: trunk/FreeOrion/universe/Universe.cpp =================================================================== --- trunk/FreeOrion/universe/Universe.cpp 2010-01-26 11:29:19 UTC (rev 3332) +++ trunk/FreeOrion/universe/Universe.cpp 2010-01-26 19:59:16 UTC (rev 3333) @@ -354,7 +354,8 @@ UniverseObject* clone = copy_from_object->Clone(ALL_EMPIRES); // this object is not yet present in this ObjectMap, so add a new UniverseObject object for it this->Insert(object_id, clone); } - }} + } +} ObjectMap* ObjectMap::Clone(int empire_id) const { @@ -363,6 +364,16 @@ return retval; } +int ObjectMap::NumObjects() const +{ + return static_cast<int>(m_objects.size()); +} + +bool ObjectMap::Empty() const +{ + return m_objects.empty(); +} + const UniverseObject* ObjectMap::Object(int id) const { const_iterator it = m_const_objects.find(id); @@ -481,12 +492,10 @@ void ObjectMap::Clear() { - std::cout << "ObjectMap::Clear() initial size of objects: " << m_objects.size() << std::endl; for (iterator it = m_objects.begin(); it != m_objects.end(); ++it) delete it->second; m_objects.clear(); m_const_objects.clear(); - std::cout << "ObjectMap::Clear() final size of objects: " << m_objects.size() << std::endl; } void ObjectMap::CopyObjectsToConstObjects() @@ -1850,23 +1859,39 @@ } } -void Universe::Destroy(int id) +void Universe::SetEmpireKnowledgeOfDestroyedObject(int object_id, int empire_id) { + if (object_id == UniverseObject::INVALID_OBJECT_ID) { + Logger().errorStream() << "SetEmpireKnowledgeOfDestroyedObject called with INVALID_OBJECT_ID"; + return; + } + + const Empire* empire = Empires().Lookup(empire_id); + if (!empire) { + Logger().errorStream() << "SetEmpireKnowledgeOfDestroyedObject called for invalid empire id: " << empire_id; + } + m_empire_known_destroyed_object_ids[empire_id].insert(object_id); +} + +void Universe::Destroy(int object_id, bool update_destroyed_object_knowers/* = true*/) +{ // remove object from any containing UniverseObject - UniverseObject* obj = m_objects.Object(id); + UniverseObject* obj = m_objects.Object(object_id); if (!obj) { - Logger().errorStream() << "Universe::Destroy called for nonexistant object with id: " << id; + Logger().errorStream() << "Universe::Destroy called for nonexistant object with id: " << object_id; return; } //Logger().debugStream() << "Destroying object : " << id << " : " << obj->Name(); - // record empires that know this object has been destroyed - for (EmpireManager::iterator emp_it = Empires().begin(); emp_it != Empires().end(); ++emp_it) { - int empire_id = emp_it->first; - if (obj->GetVisibility(empire_id) >= VIS_BASIC_VISIBILITY) { - m_empire_known_destroyed_object_ids[empire_id].insert(id); + if (update_destroyed_object_knowers) { + // record empires that know this object has been destroyed + for (EmpireManager::iterator emp_it = Empires().begin(); emp_it != Empires().end(); ++emp_it) { + int empire_id = emp_it->first; + if (obj->GetVisibility(empire_id) >= VIS_BASIC_VISIBILITY) { + m_empire_known_destroyed_object_ids[empire_id].insert(object_id); - // TODO: Update m_empire_latest_known_objects somehow? + // TODO: Update m_empire_latest_known_objects somehow? + } } } @@ -1878,16 +1903,16 @@ // remove from existing objects set and insert into destroyed objects set UniverseObjectDeleteSignal(obj); - delete m_objects.Remove(id); + delete m_objects.Remove(object_id); } -bool Universe::Delete(int id) +bool Universe::Delete(int object_id) { // find object amongst existing objects and delete directly, without storing any info // about the previous object (as is done for destroying an object) - UniverseObject* obj = m_objects.Object(id); + UniverseObject* obj = m_objects.Object(object_id); if (!obj) { - Logger().errorStream() << "Tried to delete a nonexistant object with id: " << id; + Logger().errorStream() << "Tried to delete a nonexistant object with id: " << object_id; return false; } @@ -1896,14 +1921,16 @@ obj->MoveTo(UniverseObject::INVALID_POSITION, UniverseObject::INVALID_POSITION); // remove from existing objects set - delete m_objects.Remove(id); + delete m_objects.Remove(object_id); + // TODO: Should this not also remove the object from the latest known objects and known destroyed objects for each empire? + return true; } -void Universe::EffectDestroy(int id) +void Universe::EffectDestroy(int object_id) { - m_marked_destroyed.insert(id); + m_marked_destroyed.insert(object_id); } void Universe::EffectVictory(int object_id, const std::string& reason_string) @@ -4193,6 +4220,7 @@ Logger().errorStream() << "unable to create new fleet!"; break; } + fleet->GetMeter(METER_STEALTH)->SetCurrent(Meter::METER_MAX); Insert(fleet); home_system->Insert(fleet); @@ -4218,6 +4246,12 @@ Logger().errorStream() << "unable to create new ship!"; break; } + ship->GetMeter(METER_FUEL)->SetCurrent(Meter::METER_MAX); + ship->GetMeter(METER_SHIELD)->SetCurrent(Meter::METER_MAX); + ship->GetMeter(METER_DETECTION)->SetCurrent(Meter::METER_MAX); + ship->GetMeter(METER_STEALTH)->SetCurrent(Meter::METER_MAX); + ship->GetMeter(METER_HEALTH)->SetCurrent(Meter::METER_MAX); + ship->Rename(empire->NewShipName()); int ship_id = Insert(ship); |
From: <geo...@us...> - 2010-05-17 08:29:24
|
Revision: 3597 http://freeorion.svn.sourceforge.net/freeorion/revision/?rev=3597&view=rev Author: geoffthemedio Date: 2010-05-17 08:29:18 +0000 (Mon, 17 May 2010) Log Message: ----------- Fixed more first vs. second turn meter discrepancies seen in client by adding full loop backpropegation to universe creation, instead of the previously-present selective backpropegation that was in SetActiveMetersToTargetMaxCurrentValues Modified Paths: -------------- trunk/FreeOrion/universe/Universe.cpp Modified: trunk/FreeOrion/universe/Universe.cpp =================================================================== --- trunk/FreeOrion/universe/Universe.cpp 2010-05-17 07:04:28 UTC (rev 3596) +++ trunk/FreeOrion/universe/Universe.cpp 2010-05-17 08:29:18 UTC (rev 3597) @@ -3664,17 +3664,11 @@ for (ObjectMap::iterator it = object_map.begin(); it != object_map.end(); ++it) { UniverseObject* obj = it->second; - for (std::map<MeterType, MeterType>::const_iterator meter_it = meters.begin(); meter_it != meters.end(); ++meter_it) { - if (!obj->Owners().empty()) { - if (Meter* meter = obj->GetMeter(meter_it->first)) { - if (Meter* targetmax_meter = obj->GetMeter(meter_it->second)) { + for (std::map<MeterType, MeterType>::const_iterator meter_it = meters.begin(); meter_it != meters.end(); ++meter_it) + if (!obj->Owners().empty()) + if (Meter* meter = obj->GetMeter(meter_it->first)) + if (Meter* targetmax_meter = obj->GetMeter(meter_it->second)) meter->SetCurrent(targetmax_meter->Current()); - targetmax_meter->BackPropegate(); - } - meter->BackPropegate(); - } - } - } } } } @@ -3760,6 +3754,15 @@ SetActiveMetersToTargetMaxCurrentValues(m_objects); + // copy latest updated current meter values to initial current values, and + // initial current values to previous values + for (ObjectMap::iterator it = m_objects.begin(); it != m_objects.end(); ++it) { + if (UniverseObject* obj = it->second) + for (MeterType i = MeterType(0); i != NUM_METER_TYPES; i = MeterType(i + 1)) + if (Meter* meter = obj->GetMeter(i)) + meter->BackPropegate(); + } + Logger().debugStream() << "!!!!!!!!!!!!!!!!!!! Populationg systems after setting active meters to targes!"; m_objects.Dump(); |
From: <geo...@us...> - 2010-07-21 03:19:39
|
Revision: 3690 http://freeorion.svn.sourceforge.net/freeorion/revision/?rev=3690&view=rev Author: geoffthemedio Date: 2010-07-21 03:19:32 +0000 (Wed, 21 Jul 2010) Log Message: ----------- Fixed the ability to set Universe::ALL_OBJECTS_VISIBLE to true to make all objects visible by adding a special case to SetEmpireObjectVisibility. Modified Paths: -------------- trunk/FreeOrion/universe/Universe.cpp Modified: trunk/FreeOrion/universe/Universe.cpp =================================================================== --- trunk/FreeOrion/universe/Universe.cpp 2010-07-20 07:18:29 UTC (rev 3689) +++ trunk/FreeOrion/universe/Universe.cpp 2010-07-21 03:19:32 UTC (rev 3690) @@ -1504,7 +1504,12 @@ namespace { /** Sets visibilities for indicated \a empires of object with \a object_id * in the passed-in \a empire_vis_map to \a vis */ - void SetEmpireObjectVisibility(Universe::EmpireObjectVisibilityMap& empire_vis_map, std::map<int, std::set<int> >& empire_known_design_ids, const std::set<int>& empires, int object_id, Visibility vis) { + void SetEmpireObjectVisibility(Universe::EmpireObjectVisibilityMap& empire_vis_map, + std::map<int, std::set<int> >& empire_known_design_ids, + const std::set<int>& empires, + int object_id, + Visibility vis) + { for (std::set<int>::const_iterator empire_it = empires.begin(); empire_it != empires.end(); ++empire_it) { int empire_id = *empire_it; @@ -1544,6 +1549,16 @@ //Logger().debugStream() << "Universe::UpdateEmpireObjectVisibilities()"; m_empire_object_visibility.clear(); + if (ALL_OBJECTS_VISIBLE) { + // set every object visible to all empires + std::set<int> all_empire_ids; + for (EmpireManager::iterator empire_it = Empires().begin(); empire_it != Empires().end(); ++empire_it) + all_empire_ids.insert(empire_it->first); + for (ObjectMap::const_iterator obj_it = m_objects.const_begin(); obj_it != m_objects.const_end(); ++obj_it) + SetEmpireObjectVisibility(m_empire_object_visibility, m_empire_known_ship_design_ids, all_empire_ids, obj_it->first, VIS_FULL_VISIBILITY); + return; + } + // for each detecting object for (ObjectMap::const_iterator detector_it = m_objects.const_begin(); detector_it != m_objects.const_end(); ++detector_it) { // get detector object |
From: <geo...@us...> - 2010-08-17 22:09:06
|
Revision: 3736 http://freeorion.svn.sourceforge.net/freeorion/revision/?rev=3736&view=rev Author: geoffthemedio Date: 2010-08-17 22:09:00 +0000 (Tue, 17 Aug 2010) Log Message: ----------- Fixed issue with Universe::ApplyAllEffectsAndUpdateMeters where meters were clamped on the list of objects to apply effects on, but some of those objects may have been deleted, leaving an invalid pointer in the temporary list of objects, which caused ClampMeters to be called on one of those invalid pointers, leading to a crash. Modified Paths: -------------- trunk/FreeOrion/universe/Universe.cpp Modified: trunk/FreeOrion/universe/Universe.cpp =================================================================== --- trunk/FreeOrion/universe/Universe.cpp 2010-08-17 21:16:39 UTC (rev 3735) +++ trunk/FreeOrion/universe/Universe.cpp 2010-08-17 22:09:00 UTC (rev 3736) @@ -979,6 +979,10 @@ ExecuteEffects(targets_causes_map); + + // re-get objects vector so that any destroyed objects won't still be in the list + objects = m_objects.FindObjects(object_ids); + // clamp max meters to [DEFAULT_VALUE, LARGE_VALUE] and current meters to [DEFAULT_VALUE, max] // clamp max and target meters to [DEFAULT_VALUE, LARGE_VALUE] and current meters to [DEFAULT_VALUE, max] for (std::vector<UniverseObject*>::iterator it = objects.begin(); it != objects.end(); ++it) { @@ -1468,6 +1472,10 @@ } } + // actually do destroy effect action. Executing the effect just marks + // objects to be destroyed, but doesn't actually do so in order to ensure + // no interaction in order of effects and source or target objects being + // destroyed / deleted between determining target sets and executing effects for (std::set<int>::iterator it = m_marked_destroyed.begin(); it != m_marked_destroyed.end(); ++it) { RecursiveDestroy(*it); } |
From: <geo...@us...> - 2011-01-07 05:48:06
|
Revision: 3952 http://freeorion.svn.sourceforge.net/freeorion/revision/?rev=3952&view=rev Author: geoffthemedio Date: 2011-01-07 05:47:59 +0000 (Fri, 07 Jan 2011) Log Message: ----------- Universe.cpp grooming: comment tweaking, removing unused typedefs, renaming some variables. Modified Paths: -------------- trunk/FreeOrion/universe/Universe.cpp Modified: trunk/FreeOrion/universe/Universe.cpp =================================================================== --- trunk/FreeOrion/universe/Universe.cpp 2011-01-07 05:43:12 UTC (rev 3951) +++ trunk/FreeOrion/universe/Universe.cpp 2011-01-07 05:47:59 UTC (rev 3952) @@ -38,8 +38,6 @@ } namespace { - struct vertex_system_id_t {typedef boost::vertex_property_tag kind;}; ///< a system graph property map type - const double OFFROAD_SLOWDOWN_FACTOR = 1000000000.0; // the factor by which non-starlane travel is slower than starlane travel DataTableMap& UniverseDataTables() @@ -50,7 +48,9 @@ return map; } - // used to short-circuit the use of BFS (breadth-first search) or Dijkstra's algorithm for pathfinding when it finds the desired destination system + /** Used to short-circuit the use of BFS (breadth-first search) or + * Dijkstra's algorithm for pathfinding when it finds the desired + * destination system. */ struct PathFindingShortCircuitingVisitor : public boost::base_visitor<PathFindingShortCircuitingVisitor> { typedef boost::on_finish_vertex event_filter; @@ -94,6 +94,7 @@ //////////////////////////////////////////////////////////////// // templated implementations of Universe graph search methods // //////////////////////////////////////////////////////////////// + struct vertex_system_id_t {typedef boost::vertex_property_tag kind;}; ///< a system graph property map type // returns the \a graph index for system with \a system_id template <class Graph> @@ -112,10 +113,12 @@ return -1; } - /* returns the path between vertices \a system1_id and \a system2_id of \a graph that travels the shorest - distance on starlanes, and the path length. If system1_id is the same vertex as system2_id, the path - has just that system in it, and the path lenth is 0. If there is no path between the two vertices, then - the list is empty and the path length is -1.0 */ + /** Returns the path between vertices \a system1_id and \a system2_id of + * \a graph that travels the shorest distance on starlanes, and the path + * length. If system1_id is the same vertex as system2_id, the path has + * just that system in it, and the path lenth is 0. If there is no path + * between the two vertices, then the list is empty and the path length + * is -1.0 */ template <class Graph> std::pair<std::list<int>, double> ShortestPathImpl(const Graph& graph, int system1_id, int system2_id, double linear_distance) { @@ -185,10 +188,12 @@ return retval; } - /* returns the path between vertices \a system1_id and \a system2_id of \a graph that takes the fewest - number of jumps (edge traversals), and the number of jumps this path takes. If system1_id is the same - vertex as system2_id, the path has just that system in it, and the path lenth is 0. If there is no - path between the two vertices, then the list is empty and the path length is -1 */ + /** Returns the path between vertices \a system1_id and \a system2_id of + * \a graph that takes the fewest number of jumps (edge traversals), and + * the number of jumps this path takes. If system1_id is the same vertex + * as system2_id, the path has just that system in it, and the path lenth + * is 0. If there is no path between the two vertices, then the list is + * empty and the path length is -1 */ template <class Graph> std::pair<std::list<int>, int> LeastJumpsPathImpl(const Graph& graph, int system1_id, int system2_id) { @@ -547,10 +552,6 @@ typedef boost::adjacency_list<boost::vecS, boost::vecS, boost::undirectedS, vertex_property_t, edge_property_t> SystemGraph; - // declare types for iteration over graph - typedef SystemGraph::vertex_iterator VertexIterator; - typedef SystemGraph::out_edge_iterator OutEdgeIterator; - struct EdgeVisibilityFilter { EdgeVisibilityFilter() : @@ -607,8 +608,8 @@ typedef boost::property_map<SystemGraph, boost::edge_weight_t>::const_type ConstEdgeWeightPropertyMap; typedef boost::property_map<SystemGraph, boost::edge_weight_t>::type EdgeWeightPropertyMap; - SystemGraph m_system_graph; ///< a graph in which the systems are vertices and the starlanes are edges - EmpireViewSystemGraphMap m_empire_system_graph_views; ///< a map of empire IDs to the views of the system graph by those empires + SystemGraph system_graph; ///< a graph in which the systems are vertices and the starlanes are edges + EmpireViewSystemGraphMap empire_system_graph_views; ///< a map of empire IDs to the views of the system graph by those empires }; @@ -845,8 +846,8 @@ double Universe::LinearDistance(int system1_id, int system2_id) const { //Logger().debugStream() << "LinearDistance(" << system1_id << ", " << system2_id << ")"; - int system1_index = SystemGraphIndex(m_graph_impl->m_system_graph, system1_id); - int system2_index = SystemGraphIndex(m_graph_impl->m_system_graph, system2_id); + int system1_index = SystemGraphIndex(m_graph_impl->system_graph, system1_id); + int system2_index = SystemGraphIndex(m_graph_impl->system_graph, system2_id); return m_system_distances.at(std::max(system1_index, system2_index)).at(std::min(system1_index, system2_index)); } @@ -854,10 +855,10 @@ { double linear_distance = LinearDistance(system1_id, system2_id); if (empire_id == ALL_EMPIRES) { - return ShortestPathImpl(m_graph_impl->m_system_graph, system1_id, system2_id, linear_distance); + return ShortestPathImpl(m_graph_impl->system_graph, system1_id, system2_id, linear_distance); } else { - GraphImpl::EmpireViewSystemGraphMap::const_iterator graph_it = m_graph_impl->m_empire_system_graph_views.find(empire_id); - if (graph_it != m_graph_impl->m_empire_system_graph_views.end()) + GraphImpl::EmpireViewSystemGraphMap::const_iterator graph_it = m_graph_impl->empire_system_graph_views.find(empire_id); + if (graph_it != m_graph_impl->empire_system_graph_views.end()) return ShortestPathImpl(*graph_it->second, system1_id, system2_id, linear_distance); } return std::pair<std::list<int>, double>(); @@ -866,10 +867,10 @@ std::pair<std::list<int>, int> Universe::LeastJumpsPath(int system1_id, int system2_id, int empire_id/* = ALL_EMPIRES*/) const { if (empire_id == ALL_EMPIRES) { - return LeastJumpsPathImpl(m_graph_impl->m_system_graph, system1_id, system2_id); + return LeastJumpsPathImpl(m_graph_impl->system_graph, system1_id, system2_id); } else { - GraphImpl::EmpireViewSystemGraphMap::const_iterator graph_it = m_graph_impl->m_empire_system_graph_views.find(empire_id); - if (graph_it != m_graph_impl->m_empire_system_graph_views.end()) + GraphImpl::EmpireViewSystemGraphMap::const_iterator graph_it = m_graph_impl->empire_system_graph_views.find(empire_id); + if (graph_it != m_graph_impl->empire_system_graph_views.end()) return LeastJumpsPathImpl(*graph_it->second, system1_id, system2_id); } return std::pair<std::list<int>, int>(); @@ -892,10 +893,10 @@ std::map<double, int> Universe::ImmediateNeighbors(int system_id, int empire_id/* = ALL_EMPIRES*/) const { if (empire_id == ALL_EMPIRES) { - return ImmediateNeighborsImpl(m_graph_impl->m_system_graph, system_id); + return ImmediateNeighborsImpl(m_graph_impl->system_graph, system_id); } else { - GraphImpl::EmpireViewSystemGraphMap::const_iterator graph_it = m_graph_impl->m_empire_system_graph_views.find(empire_id); - if (graph_it != m_graph_impl->m_empire_system_graph_views.end()) + GraphImpl::EmpireViewSystemGraphMap::const_iterator graph_it = m_graph_impl->empire_system_graph_views.find(empire_id); + if (graph_it != m_graph_impl->empire_system_graph_views.end()) return ImmediateNeighborsImpl(*graph_it->second, system_id); } return std::map<double, int>(); @@ -2154,9 +2155,9 @@ { const ObjectMap& objects = EmpireKnownObjects(for_empire_id); - for (int i = static_cast<int>(boost::num_vertices(m_graph_impl->m_system_graph)) - 1; i >= 0; --i) { - boost::clear_vertex(i, m_graph_impl->m_system_graph); - boost::remove_vertex(i, m_graph_impl->m_system_graph); + for (int i = static_cast<int>(boost::num_vertices(m_graph_impl->system_graph)) - 1; i >= 0; --i) { + boost::clear_vertex(i, m_graph_impl->system_graph); + boost::remove_vertex(i, m_graph_impl->system_graph); } std::vector<int> system_ids = objects.FindObjectIDs<System>(); @@ -2164,20 +2165,20 @@ //for (std::vector<int>::const_iterator it = system_ids.begin(); it != system_ids.end(); ++it) // Logger().debugStream() << " ... " << *it; - m_system_distances.resize(system_ids.size()); - GraphImpl::SystemIDPropertyMap sys_id_property_map = boost::get(vertex_system_id_t(), m_graph_impl->m_system_graph); + GraphImpl::SystemIDPropertyMap sys_id_property_map = + boost::get(vertex_system_id_t(), m_graph_impl->system_graph); - GraphImpl::EdgeWeightPropertyMap edge_weight_map = boost::get(boost::edge_weight, m_graph_impl->m_system_graph); - typedef boost::graph_traits<GraphImpl::SystemGraph>::edge_descriptor EdgeDescriptor; + GraphImpl::EdgeWeightPropertyMap edge_weight_map = + boost::get(boost::edge_weight, m_graph_impl->system_graph); - std::map<int, int> system_id_graph_index_reverse_lookup_map; // key is system ID, value is index in m_graph_impl->m_system_graph of system's vertex + std::map<int, int> system_id_graph_index_reverse_lookup_map; // key is system ID, value is index in m_graph_impl->system_graph of system's vertex for (int i = 0; i < static_cast<int>(system_ids.size()); ++i) { // add a vertex to the graph for this system, and assign it the system's universe ID as a property - boost::add_vertex(m_graph_impl->m_system_graph); + boost::add_vertex(m_graph_impl->system_graph); int system_id = system_ids[i]; sys_id_property_map[i] = system_id; - // add record of index in m_graph_impl->m_system_graph of this system + // add record of index in m_graph_impl->system_graph of this system system_id_graph_index_reverse_lookup_map[system_id] = i; } @@ -2188,18 +2189,20 @@ // add edges and edge weights for (System::const_lane_iterator it = system1->begin_lanes(); it != system1->end_lanes(); ++it) { // get id in universe of system at other end of lane - int lane_dest_id = it->first; + const int lane_dest_id = it->first; // skip null lanes if (lane_dest_id == system1_id) continue; - // get m_graph_impl->m_system_graph index for this system + // get m_graph_impl->system_graph index for this system std::map<int, int>::iterator reverse_lookup_map_it = system_id_graph_index_reverse_lookup_map.find(lane_dest_id); if (reverse_lookup_map_it == system_id_graph_index_reverse_lookup_map.end()) continue; // couldn't find destination system id in reverse lookup map; don't add to graph int lane_dest_graph_index = reverse_lookup_map_it->second; - std::pair<EdgeDescriptor, bool> add_edge_result = boost::add_edge(i, lane_dest_graph_index, m_graph_impl->m_system_graph); + typedef boost::graph_traits<GraphImpl::SystemGraph>::edge_descriptor EdgeDescriptor; + std::pair<EdgeDescriptor, bool> add_edge_result = + boost::add_edge(i, lane_dest_graph_index, m_graph_impl->system_graph); if (add_edge_result.second) { // if this is a non-duplicate starlane or wormhole if (it->second) { // if this is a wormhole @@ -2215,6 +2218,7 @@ } // define the straight-line system distances for this system + m_system_distances.resize(system_ids.size()); m_system_distances[i].clear(); for (int j = 0; j < i; ++j) { int system2_id = system_ids[j]; @@ -2232,7 +2236,7 @@ void Universe::RebuildEmpireViewSystemGraphs(int for_empire_id) { - m_graph_impl->m_empire_system_graph_views.clear(); + m_graph_impl->empire_system_graph_views.clear(); // if building system graph views for all empires, then each empire's graph // should accurately filter for that empire's visibility. if building @@ -2247,19 +2251,19 @@ // all empires get their own, accurately filtered graph for (EmpireManager::const_iterator it = Empires().begin(); it != Empires().end(); ++it) { int empire_id = it->first; - GraphImpl::EdgeVisibilityFilter filter(&m_graph_impl->m_system_graph, empire_id); - boost::shared_ptr<GraphImpl::EmpireViewSystemGraph> filtered_graph_ptr(new GraphImpl::EmpireViewSystemGraph(m_graph_impl->m_system_graph, filter)); - m_graph_impl->m_empire_system_graph_views[empire_id] = filtered_graph_ptr; + GraphImpl::EdgeVisibilityFilter filter(&m_graph_impl->system_graph, empire_id); + boost::shared_ptr<GraphImpl::EmpireViewSystemGraph> filtered_graph_ptr(new GraphImpl::EmpireViewSystemGraph(m_graph_impl->system_graph, filter)); + m_graph_impl->empire_system_graph_views[empire_id] = filtered_graph_ptr; } } else { // all empires share a single filtered graph, filtered by the for_empire_id - GraphImpl::EdgeVisibilityFilter filter(&m_graph_impl->m_system_graph, for_empire_id); - boost::shared_ptr<GraphImpl::EmpireViewSystemGraph> filtered_graph_ptr(new GraphImpl::EmpireViewSystemGraph(m_graph_impl->m_system_graph, filter)); + GraphImpl::EdgeVisibilityFilter filter(&m_graph_impl->system_graph, for_empire_id); + boost::shared_ptr<GraphImpl::EmpireViewSystemGraph> filtered_graph_ptr(new GraphImpl::EmpireViewSystemGraph(m_graph_impl->system_graph, filter)); for (EmpireManager::const_iterator it = Empires().begin(); it != Empires().end(); ++it) { int empire_id = it->first; - m_graph_impl->m_empire_system_graph_views[empire_id] = filtered_graph_ptr; + m_graph_impl->empire_system_graph_views[empire_id] = filtered_graph_ptr; } } } |
From: <geo...@us...> - 2011-06-17 07:25:04
|
Revision: 3998 http://freeorion.svn.sourceforge.net/freeorion/revision/?rev=3998&view=rev Author: geoffthemedio Date: 2011-06-17 07:24:57 +0000 (Fri, 17 Jun 2011) Log Message: ----------- Put some boost::graph related code in Universe.cpp into a named namespace (instead of an anonymous one) to fix some compile errors unique to particular GCC versions (4.2, possibly others) on OSX. Modified Paths: -------------- trunk/FreeOrion/universe/Universe.cpp Modified: trunk/FreeOrion/universe/Universe.cpp =================================================================== --- trunk/FreeOrion/universe/Universe.cpp 2011-06-13 13:02:23 UTC (rev 3997) +++ trunk/FreeOrion/universe/Universe.cpp 2011-06-17 07:24:57 UTC (rev 3998) @@ -48,25 +48,6 @@ return map; } - /** Used to short-circuit the use of BFS (breadth-first search) or - * Dijkstra's algorithm for pathfinding when it finds the desired - * destination system. */ - struct PathFindingShortCircuitingVisitor : public boost::base_visitor<PathFindingShortCircuitingVisitor> - { - typedef boost::on_finish_vertex event_filter; - - struct FoundDestination {}; // exception type thrown when destination is found - - PathFindingShortCircuitingVisitor(int dest_system) : destination_system(dest_system) {} - template <class Vertex, class Graph> - void operator()(Vertex u, Graph& g) - { - if (static_cast<int>(u) == destination_system) - throw FoundDestination(); - } - const int destination_system; - }; - void LoadSystemNames(std::list<std::string>& names) { boost::filesystem::ifstream ifs(GetResourceDir() / "starnames.txt"); @@ -90,7 +71,28 @@ } } } +} +namespace SystemPathing { + /** Used to short-circuit the use of BFS (breadth-first search) or + * Dijkstra's algorithm for pathfinding when it finds the desired + * destination system. */ + struct PathFindingShortCircuitingVisitor : public boost::base_visitor<PathFindingShortCircuitingVisitor> + { + typedef boost::on_finish_vertex event_filter; + + struct FoundDestination {}; // exception type thrown when destination is found + + PathFindingShortCircuitingVisitor(int dest_system) : destination_system(dest_system) {} + template <class Vertex, class Graph> + void operator()(Vertex u, Graph& g) + { + if (static_cast<int>(u) == destination_system) + throw FoundDestination(); + } + const int destination_system; + }; + //////////////////////////////////////////////////////////////// // templated implementations of Universe graph search methods // //////////////////////////////////////////////////////////////// @@ -271,6 +273,7 @@ return retval; } } +using namespace SystemPathing; // to keep GCC 4.2 on OSX happy const int ALL_EMPIRES = -1; |
From: <geo...@us...> - 2011-08-13 05:44:45
|
Revision: 4126 http://freeorion.svn.sourceforge.net/freeorion/revision/?rev=4126&view=rev Author: geoffthemedio Date: 2011-08-13 05:44:39 +0000 (Sat, 13 Aug 2011) Log Message: ----------- Made empire random species selection for AIs in single player and native planet populating consider whether species are playable or not, where playable means can colonize and can produce ships. Modified Paths: -------------- trunk/FreeOrion/universe/Universe.cpp Modified: trunk/FreeOrion/universe/Universe.cpp =================================================================== --- trunk/FreeOrion/universe/Universe.cpp 2011-08-13 05:43:15 UTC (rev 4125) +++ trunk/FreeOrion/universe/Universe.cpp 2011-08-13 05:44:39 UTC (rev 4126) @@ -4116,9 +4116,16 @@ // find species that like this planet type std::vector<std::string> suitable_species; - for (SpeciesManager::iterator species_it = species_manager.begin(); species_it != species_manager.end(); ++species_it) - if (species_it->second->GetPlanetEnvironment(planet_type) == PE_GOOD) + for (SpeciesManager::iterator species_it = species_manager.begin(); + species_it != species_manager.end(); ++species_it) + { + const Species* species = species_it->second; + if (!species->CanColonize() && !species->CanProduceShips() && + species->GetPlanetEnvironment(planet_type) == PE_GOOD) + { suitable_species.push_back(species_it->first); + } + } if (suitable_species.empty()) continue; Logger().debugStream() << " ... " << suitable_species.size() << " species are appropriate for this planet"; @@ -4142,6 +4149,7 @@ Logger().debugStream() << "GenerateSpaceMonsters"; int inverse_monster_chance = UniverseDataTables()["LifeFormFrequency"][0][freq]; + Logger().debugStream() << "Universe::GenerateSpaceMonsters(" << boost::lexical_cast<std::string>(freq) << ") inverse monster chance: " << inverse_monster_chance; double monster_chance(0.0); if (inverse_monster_chance > 0) monster_chance = 1.0 / static_cast<double>(inverse_monster_chance); @@ -4579,9 +4587,9 @@ Logger().errorStream() << "Universe::GenerateEmpires found an empty species manager! Can't assign species to empires."; } else { int species_name_idx = 0; - if (species_manager.NumSpecies() > 1) + if (species_manager.NumPlayableSpecies() > 1) species_name_idx = RandSmallInt(0, species_manager.NumSpecies() - 1); - SpeciesManager::iterator it = species_manager.begin(); + SpeciesManager::playable_iterator it = species_manager.playable_begin(); std::advance(it, species_name_idx); empire_starting_species = it->first; } |
From: <geo...@us...> - 2011-08-13 07:17:01
|
Revision: 4130 http://freeorion.svn.sourceforge.net/freeorion/revision/?rev=4130&view=rev Author: geoffthemedio Date: 2011-08-13 07:16:55 +0000 (Sat, 13 Aug 2011) Log Message: ----------- Fixed criteria for considering a species as non-playable for purposes of populating as natives during universe generation. Modified Paths: -------------- trunk/FreeOrion/universe/Universe.cpp Modified: trunk/FreeOrion/universe/Universe.cpp =================================================================== --- trunk/FreeOrion/universe/Universe.cpp 2011-08-13 06:49:56 UTC (rev 4129) +++ trunk/FreeOrion/universe/Universe.cpp 2011-08-13 07:16:55 UTC (rev 4130) @@ -4120,7 +4120,7 @@ species_it != species_manager.end(); ++species_it) { const Species* species = species_it->second; - if (!species->CanColonize() && !species->CanProduceShips() && + if ((!species->CanColonize() || !species->CanProduceShips()) && species->GetPlanetEnvironment(planet_type) == PE_GOOD) { suitable_species.push_back(species_it->first); |
From: <geo...@us...> - 2011-08-13 18:21:39
|
Revision: 4134 http://freeorion.svn.sourceforge.net/freeorion/revision/?rev=4134&view=rev Author: geoffthemedio Date: 2011-08-13 18:21:33 +0000 (Sat, 13 Aug 2011) Log Message: ----------- Fixed bug with stealth vs. detection and range checking that was treating any case where stealth was greater than detection for a pair of objects as though stealth equalled detection, which was allowing very stealthy objects to be detected when at 0 distance (same location). Modified Paths: -------------- trunk/FreeOrion/universe/Universe.cpp Modified: trunk/FreeOrion/universe/Universe.cpp =================================================================== --- trunk/FreeOrion/universe/Universe.cpp 2011-08-13 14:49:50 UTC (rev 4133) +++ trunk/FreeOrion/universe/Universe.cpp 2011-08-13 18:21:33 UTC (rev 4134) @@ -354,7 +354,9 @@ continue; // if object is at all visible, copy all information, not just info - // appropriate for the actual visibility level. + // appropriate for the actual visibility level. this ensures that any + // details previously learned about object will still be recorded in + // copied-to ObjectMap this->Copy(it->second, ALL_EMPIRES); } } @@ -1757,12 +1759,16 @@ // is compared to the distance between them. If the distance is // less than 10*(detector_detection - target_stealth), then the // target is seen by the detector with partial visibility. - double detect_range = std::max(0.0, 10.0*(detection - stealth)); + double detect_range = 10.0*(detection - stealth); + if (detect_range < 0.0) + continue; // can't see object no matter where it is + + //Logger().debugStream() << "dist2: " << dist2 << " detect range: " << detect_range; + if (dist2 <= detect_range * detect_range) target_visibility_to_detector = VIS_PARTIAL_VISIBILITY; - if (target_visibility_to_detector <= VIS_NO_VISIBILITY) continue; |
From: <geo...@us...> - 2011-08-14 03:43:10
|
Revision: 4136 http://freeorion.svn.sourceforge.net/freeorion/revision/?rev=4136&view=rev Author: geoffthemedio Date: 2011-08-14 03:43:03 +0000 (Sun, 14 Aug 2011) Log Message: ----------- Fixed crash when randomly selecting playable species for AI empires in single player games. Modified Paths: -------------- trunk/FreeOrion/universe/Universe.cpp Modified: trunk/FreeOrion/universe/Universe.cpp =================================================================== --- trunk/FreeOrion/universe/Universe.cpp 2011-08-13 18:47:55 UTC (rev 4135) +++ trunk/FreeOrion/universe/Universe.cpp 2011-08-14 03:43:03 UTC (rev 4136) @@ -4607,7 +4607,7 @@ } else { int species_name_idx = 0; if (species_manager.NumPlayableSpecies() > 1) - species_name_idx = RandSmallInt(0, species_manager.NumSpecies() - 1); + species_name_idx = RandSmallInt(0, species_manager.NumPlayableSpecies() - 1); SpeciesManager::playable_iterator it = species_manager.playable_begin(); std::advance(it, species_name_idx); empire_starting_species = it->first; |
From: <geo...@us...> - 2011-08-19 05:24:00
|
Revision: 4172 http://freeorion.svn.sourceforge.net/freeorion/revision/?rev=4172&view=rev Author: geoffthemedio Date: 2011-08-19 03:51:12 +0000 (Fri, 19 Aug 2011) Log Message: ----------- -Included troops meter in function that sets active meters to maxes / targets, so that planets start with troops equal to their max troops. -More grooming. Modified Paths: -------------- trunk/FreeOrion/universe/Universe.cpp Modified: trunk/FreeOrion/universe/Universe.cpp =================================================================== --- trunk/FreeOrion/universe/Universe.cpp 2011-08-19 03:49:31 UTC (rev 4171) +++ trunk/FreeOrion/universe/Universe.cpp 2011-08-19 03:51:12 UTC (rev 4172) @@ -3864,24 +3864,24 @@ * values. Useful when creating new object after applying effects. */ void SetActiveMetersToTargetMaxCurrentValues(ObjectMap& object_map) { std::map<MeterType, MeterType> meters; - meters[METER_POPULATION] = METER_TARGET_POPULATION; - meters[METER_HEALTH] = METER_TARGET_HEALTH; - meters[METER_FARMING] = METER_TARGET_FARMING; - meters[METER_INDUSTRY] = METER_TARGET_INDUSTRY; - meters[METER_RESEARCH] = METER_TARGET_RESEARCH; - meters[METER_TRADE] = METER_TARGET_TRADE; - meters[METER_MINING] = METER_TARGET_MINING; - meters[METER_CONSTRUCTION] = METER_TARGET_CONSTRUCTION; - meters[METER_FUEL] = METER_MAX_FUEL; - meters[METER_SHIELD] = METER_MAX_SHIELD; - meters[METER_STRUCTURE] = METER_MAX_STRUCTURE; - meters[METER_DEFENSE] = METER_MAX_DEFENSE; + meters[METER_POPULATION] = METER_TARGET_POPULATION; + meters[METER_HEALTH] = METER_TARGET_HEALTH; + meters[METER_FARMING] = METER_TARGET_FARMING; + meters[METER_INDUSTRY] = METER_TARGET_INDUSTRY; + meters[METER_RESEARCH] = METER_TARGET_RESEARCH; + meters[METER_TRADE] = METER_TARGET_TRADE; + meters[METER_MINING] = METER_TARGET_MINING; + meters[METER_CONSTRUCTION] =METER_TARGET_CONSTRUCTION; + meters[METER_FUEL] = METER_MAX_FUEL; + meters[METER_SHIELD] = METER_MAX_SHIELD; + meters[METER_STRUCTURE] = METER_MAX_STRUCTURE; + meters[METER_DEFENSE] = METER_MAX_DEFENSE; + meters[METER_TROOPS] = METER_MAX_TROOPS; // check for each pair of meter types. if both exist, set active // meter current value equal to target meter current value. for (ObjectMap::iterator it = object_map.begin(); it != object_map.end(); ++it) { UniverseObject* obj = it->second; - for (std::map<MeterType, MeterType>::const_iterator meter_it = meters.begin(); meter_it != meters.end(); ++meter_it) if (Meter* meter = obj->GetMeter(meter_it->first)) if (Meter* targetmax_meter = obj->GetMeter(meter_it->second)) |
From: <geo...@us...> - 2011-08-24 22:29:54
|
Revision: 4184 http://freeorion.svn.sourceforge.net/freeorion/revision/?rev=4184&view=rev Author: geoffthemedio Date: 2011-08-24 22:29:48 +0000 (Wed, 24 Aug 2011) Log Message: ----------- Made planets always at least basically visible to empires with any object in the same systme. Modified Paths: -------------- trunk/FreeOrion/universe/Universe.cpp Modified: trunk/FreeOrion/universe/Universe.cpp =================================================================== --- trunk/FreeOrion/universe/Universe.cpp 2011-08-24 22:25:49 UTC (rev 4183) +++ trunk/FreeOrion/universe/Universe.cpp 2011-08-24 22:29:48 UTC (rev 4184) @@ -1682,18 +1682,18 @@ // get detector object const UniverseObject* detector = detector_it->second; if (!detector) continue; + // unowned detectors can't contribute to empires' visibility + if (detector->Unowned()) + continue; int detector_id = detector->ID(); - // get owners of detector - if (detector->Unowned()) - continue; + // owner of an object gets full visibility of it + SetEmpireObjectVisibility(m_empire_object_visibility, m_empire_known_ship_design_ids, + detector->Owner(), detector_id, VIS_FULL_VISIBILITY); - // owners of an object get full visibility of it - SetEmpireObjectVisibility(m_empire_object_visibility, m_empire_known_ship_design_ids, detector->Owner(), detector_id, VIS_FULL_VISIBILITY); - // don't allow moving fleets or ships to provide detection const Fleet* fleet = universe_object_cast<const Fleet*>(detector); if (!fleet) @@ -1752,10 +1752,12 @@ Visibility target_visibility_to_detector = VIS_NO_VISIBILITY; // zero-stealth objects are always at least basic-level visible - if (stealth <= 0) + if (stealth <= 0 && + target_visibility_to_detector < VIS_BASIC_VISIBILITY) + { target_visibility_to_detector = VIS_BASIC_VISIBILITY; + } - // compare stealth, detection ability and distance between // detector and target to find visibility level @@ -1766,6 +1768,12 @@ // distance squared double dist2 = (xt-xd)*(xt-xd) + (yt-yd)*(yt-yd); + // planets can always be seen if they are at the same location + if (dist2 == 0.0 && + target_visibility_to_detector < VIS_BASIC_VISIBILITY) + { + target_visibility_to_detector = VIS_BASIC_VISIBILITY; + } // To determine if a detector can detect a target, the target's // stealth is subtracted from the detector's range, and the result @@ -1773,26 +1781,20 @@ // less than 10*(detector_detection - target_stealth), then the // target is seen by the detector with partial visibility. double detect_range = 10.0*(detection - stealth); - - if (detect_range < 0.0) - continue; // can't see object no matter where it is - //Logger().debugStream() << "dist2: " << dist2 << " detect range: " << detect_range; - - if (dist2 <= detect_range * detect_range) + if (detect_range >= 0.0 && + dist2 <= detect_range*detect_range && + target_visibility_to_detector < VIS_PARTIAL_VISIBILITY) + { target_visibility_to_detector = VIS_PARTIAL_VISIBILITY; + } if (target_visibility_to_detector <= VIS_NO_VISIBILITY) continue; - - // Note that owning an object grants FULL visibility in the containing loop - - - int target_id = target->ID(); - - // if target visible to detector, update visibility of target for all empires that own detector - SetEmpireObjectVisibility(m_empire_object_visibility, m_empire_known_ship_design_ids, detector->Owner(), target_id, target_visibility_to_detector); + // if target visible to detector, update visibility of target for detector's owner empire + SetEmpireObjectVisibility(m_empire_object_visibility, m_empire_known_ship_design_ids, + detector->Owner(), target->ID(), target_visibility_to_detector); } } |
From: <geo...@us...> - 2011-09-09 17:46:22
|
Revision: 4241 http://freeorion.svn.sourceforge.net/freeorion/revision/?rev=4241&view=rev Author: geoffthemedio Date: 2011-09-09 17:46:16 +0000 (Fri, 09 Sep 2011) Log Message: ----------- Hopefully worked around / fixed a crash during effects processing where an effectsgroup had no valid source object. Why this situation arose, I'm not sure, however... Modified Paths: -------------- trunk/FreeOrion/universe/Universe.cpp Modified: trunk/FreeOrion/universe/Universe.cpp =================================================================== --- trunk/FreeOrion/universe/Universe.cpp 2011-09-09 17:06:35 UTC (rev 4240) +++ trunk/FreeOrion/universe/Universe.cpp 2011-09-09 17:46:16 UTC (rev 4241) @@ -1477,8 +1477,9 @@ std::map<std::string, Effect::TargetSet> executed_nonstacking_effects; for (EffectsTargetsCausesMap::const_iterator targets_it = targets_causes_map.begin(); targets_it != targets_causes_map.end(); ++targets_it) { + const UniverseObject* source = GetObject(targets_it->first.source_object_id); ScopedTimer update_timer("Universe::ExecuteEffects execute one effects group (source " + - GetObject(targets_it->first.source_object_id)->Name() + + (source ? source->Name() : "No Source!") + ") on " + boost::lexical_cast<std::string>(targets_it->second.target_set.size()) + " objects"); // if other EffectsGroups with the same stacking group have affected some of the targets in |
From: <geo...@us...> - 2011-09-13 04:12:34
|
Revision: 4255 http://freeorion.svn.sourceforge.net/freeorion/revision/?rev=4255&view=rev Author: geoffthemedio Date: 2011-09-13 04:12:28 +0000 (Tue, 13 Sep 2011) Log Message: ----------- Compiling but untested code to set planet size appropriately for asteroids or gas giants when those are also the best planet type for a species during universe generation. Modified Paths: -------------- trunk/FreeOrion/universe/Universe.cpp Modified: trunk/FreeOrion/universe/Universe.cpp =================================================================== --- trunk/FreeOrion/universe/Universe.cpp 2011-09-13 02:09:50 UTC (rev 4254) +++ trunk/FreeOrion/universe/Universe.cpp 2011-09-13 04:12:28 UTC (rev 4255) @@ -4875,6 +4875,10 @@ PlanetType preferred_planet_type = sept.rbegin()->second; home_planet->SetType(preferred_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 { |
From: <geo...@us...> - 2011-10-01 05:01:12
|
Revision: 4307 http://freeorion.svn.sourceforge.net/freeorion/revision/?rev=4307&view=rev Author: geoffthemedio Date: 2011-10-01 05:01:05 +0000 (Sat, 01 Oct 2011) Log Message: ----------- Tweak to fix MSVC 2010 compile error in Boost graph header. Modified Paths: -------------- trunk/FreeOrion/universe/Universe.cpp Modified: trunk/FreeOrion/universe/Universe.cpp =================================================================== --- trunk/FreeOrion/universe/Universe.cpp 2011-09-30 04:43:17 UTC (rev 4306) +++ trunk/FreeOrion/universe/Universe.cpp 2011-10-01 05:01:05 UTC (rev 4307) @@ -98,8 +98,7 @@ short m_value; }; - short get(const constant_property& pmap, const boost::detail::edge_desc_impl<boost::undirected_tag, unsigned long>&) { return pmap.m_value; } - + short get(const constant_property& pmap, const boost::detail::edge_desc_impl<boost::undirected_tag, unsigned int>&) { return pmap.m_value; } } namespace boost { @@ -109,7 +108,6 @@ typedef boost::detail::edge_desc_impl<boost::undirected_tag, unsigned long> key_type; typedef readable_property_map_tag category; }; - } namespace SystemPathing { @@ -131,7 +129,7 @@ } const int destination_system; }; - + /** Complete BFS visitor implementing: * - predecessor recording * - short-circuit exit on found match |
From: <geo...@us...> - 2011-10-03 07:10:12
|
Revision: 4343 http://freeorion.svn.sourceforge.net/freeorion/revision/?rev=4343&view=rev Author: geoffthemedio Date: 2011-10-03 07:10:06 +0000 (Mon, 03 Oct 2011) Log Message: ----------- Made AI automatic colour picking use the order the colours are specified, rather than a random order. Modified Paths: -------------- trunk/FreeOrion/universe/Universe.cpp Modified: trunk/FreeOrion/universe/Universe.cpp =================================================================== --- trunk/FreeOrion/universe/Universe.cpp 2011-10-03 06:46:39 UTC (rev 4342) +++ trunk/FreeOrion/universe/Universe.cpp 2011-10-03 07:10:06 UTC (rev 4343) @@ -4911,10 +4911,9 @@ // if no colour already set, do so automatically if (empire_colour == GG::Clr(0, 0, 0, 0)) { if (!colors.empty()) { - // a list of colours is available. pick a colour - int color_idx = RandInt(0, colors.size() - 1); - empire_colour = colors[color_idx]; - colors.erase(colors.begin() + color_idx); + // take next colour from list + empire_colour = colors[0]; + colors.erase(colors.begin()); } else { // as a last resort, make up a colour empire_colour = GG::FloatClr(static_cast<float>(RandZeroToOne()), static_cast<float>(RandZeroToOne()), |
From: <geo...@us...> - 2011-10-07 18:47:40
|
Revision: 4352 http://freeorion.svn.sourceforge.net/freeorion/revision/?rev=4352&view=rev Author: geoffthemedio Date: 2011-10-07 18:47:34 +0000 (Fri, 07 Oct 2011) Log Message: ----------- Removed -1 from Universe::JumpDistance which seems to be breaking it. Modified Paths: -------------- trunk/FreeOrion/universe/Universe.cpp Modified: trunk/FreeOrion/universe/Universe.cpp =================================================================== --- trunk/FreeOrion/universe/Universe.cpp 2011-10-07 18:44:08 UTC (rev 4351) +++ trunk/FreeOrion/universe/Universe.cpp 2011-10-07 18:47:34 UTC (rev 4352) @@ -924,7 +924,7 @@ { return m_system_distances[m_system_id_to_graph_index.at(system1_id)][m_system_id_to_graph_index.at(system2_id)]; } short Universe::JumpDistance(int system1_id, int system2_id) const -{ return m_system_jumps[m_system_id_to_graph_index.at(system1_id)][m_system_id_to_graph_index.at(system2_id)] - 1; } +{ return m_system_jumps[m_system_id_to_graph_index.at(system1_id)][m_system_id_to_graph_index.at(system2_id)]; } std::pair<std::list<int>, double> Universe::ShortestPath(int system1_id, int system2_id, int empire_id/* = ALL_EMPIRES*/) const { @@ -1522,7 +1522,7 @@ // store effect cause and targets info in map, indexed by sourced effects group targets_causes_map.insert(std::make_pair(sourced_effects_group, target_and_cause)); - + // restore target_objects by moving objects back from targets to target_objects // this should be cheaper than doing a full copy because target_set is usually small target_objects.insert(target_set.begin(), target_set.end()); |
From: <geo...@us...> - 2011-10-10 17:13:29
|
Revision: 4377 http://freeorion.svn.sourceforge.net/freeorion/revision/?rev=4377&view=rev Author: geoffthemedio Date: 2011-10-10 17:13:23 +0000 (Mon, 10 Oct 2011) Log Message: ----------- Applied cami's Generic constant_property implementation patch for system jump distance calculation, which is reported by night to fix compile errors on OSX / GCC. Modified Paths: -------------- trunk/FreeOrion/universe/Universe.cpp Modified: trunk/FreeOrion/universe/Universe.cpp =================================================================== --- trunk/FreeOrion/universe/Universe.cpp 2011-10-10 16:55:12 UTC (rev 4376) +++ trunk/FreeOrion/universe/Universe.cpp 2011-10-10 17:13:23 UTC (rev 4377) @@ -93,21 +93,20 @@ } } - struct constant_property + template <class Key, class Value> struct constant_property { - short m_value; + Value m_value; }; - short get(const constant_property& pmap, const boost::detail::edge_desc_impl<boost::undirected_tag, unsigned int>&) { return pmap.m_value; } } namespace boost { - template <> - struct property_traits<constant_property> { - typedef short value_type; - typedef boost::detail::edge_desc_impl<boost::undirected_tag, unsigned long> key_type; + template <class Key, class Value> struct property_traits<constant_property<Key, Value> > { + typedef Value value_type; + typedef Key key_type; typedef readable_property_map_tag category; }; + template <class Key, class Value> const Value& get(const constant_property<Key, Value>& pmap, const Key&) { return pmap.m_value; } } namespace SystemPathing { @@ -2245,6 +2244,7 @@ void Universe::InitializeSystemGraph(int for_empire_id) { + typedef boost::graph_traits<GraphImpl::SystemGraph>::edge_descriptor EdgeDescriptor; const ObjectMap& objects = EmpireKnownObjects(for_empire_id); for (int i = static_cast<int>(boost::num_vertices(m_graph_impl->system_graph)) - 1; i >= 0; --i) { @@ -2295,7 +2295,6 @@ continue; // couldn't find destination system id in reverse lookup map; don't add to graph int lane_dest_graph_index = reverse_lookup_map_it->second; - typedef boost::graph_traits<GraphImpl::SystemGraph>::edge_descriptor EdgeDescriptor; std::pair<EdgeDescriptor, bool> add_edge_result = boost::add_edge(i, lane_dest_graph_index, m_graph_impl->system_graph); @@ -2324,7 +2323,7 @@ } m_system_jumps.resize(system_ids.size(), system_ids.size()); - constant_property jump_weight = { 1 }; + constant_property<EdgeDescriptor, short> jump_weight = { 1 }; boost::johnson_all_pairs_shortest_paths(m_graph_impl->system_graph, m_system_jumps, boost::weight_map(jump_weight)); RebuildEmpireViewSystemGraphs(for_empire_id); |
From: <geo...@us...> - 2011-10-14 07:39:15
|
Revision: 4387 http://freeorion.svn.sourceforge.net/freeorion/revision/?rev=4387&view=rev Author: geoffthemedio Date: 2011-10-14 07:39:09 +0000 (Fri, 14 Oct 2011) Log Message: ----------- Changed detection range from 10*(detection - stealth) to just (detection - stealth). Modified Paths: -------------- trunk/FreeOrion/universe/Universe.cpp Modified: trunk/FreeOrion/universe/Universe.cpp =================================================================== --- trunk/FreeOrion/universe/Universe.cpp 2011-10-13 00:57:34 UTC (rev 4386) +++ trunk/FreeOrion/universe/Universe.cpp 2011-10-14 07:39:09 UTC (rev 4387) @@ -1838,9 +1838,9 @@ // To determine if a detector can detect a target, the target's // stealth is subtracted from the detector's range, and the result // is compared to the distance between them. If the distance is - // less than 10*(detector_detection - target_stealth), then the + // less than (detector_detection - target_stealth), then the // target is seen by the detector with partial visibility. - double detect_range = 10.0*(detection - stealth); + double detect_range = detection - stealth; //Logger().debugStream() << "dist2: " << dist2 << " detect range: " << detect_range; if (detect_range >= 0.0 && dist2 <= detect_range*detect_range && |
From: <geo...@us...> - 2011-10-21 05:52:23
|
Revision: 4424 http://freeorion.svn.sourceforge.net/freeorion/revision/?rev=4424&view=rev Author: geoffthemedio Date: 2011-10-21 05:52:17 +0000 (Fri, 21 Oct 2011) Log Message: ----------- Added line to initialize player homeworlds with a large food allocation, so that first-turn meter setting doesn't produce a weird one-turn apparent large health bonus due to a quirk in the relevant effects when using the new / experimental lack of food reducing health scripts in humans. Modified Paths: -------------- trunk/FreeOrion/universe/Universe.cpp Modified: trunk/FreeOrion/universe/Universe.cpp =================================================================== --- trunk/FreeOrion/universe/Universe.cpp 2011-10-21 02:49:44 UTC (rev 4423) +++ trunk/FreeOrion/universe/Universe.cpp 2011-10-21 05:52:17 UTC (rev 4424) @@ -4416,6 +4416,7 @@ Planet* planet = new Planet(PT_TERRAN, SZ_MEDIUM); planet_id = Insert(planet); planet->Rename(planet_name); + planet->SetAllocatedFood(Meter::LARGE_VALUE); system->Insert(planet, home_orbit); homeworld_planet_ids.push_back(planet_id); |