Author: suokko
Date: Thu Sep 11 14:34:01 2008
New Revision: 29390

URL: http://svn.gna.org/viewcvs/wesnoth?rev=29390&view=rev
Log:
Fixed crash if trying to watch campaign replay

Modified:
    trunk/src/team.cpp
    trunk/src/team.hpp
    trunk/src/unit.cpp
    trunk/src/unit.hpp

Modified: trunk/src/team.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/team.cpp?rev=29390&r1=29389&r2=29390&view=diff
==============================================================================
--- trunk/src/team.cpp (original)
+++ trunk/src/team.cpp Thu Sep 11 14:34:01 2008
@@ -43,12 +43,19 @@
 
 teams_manager::teams_manager(std::vector<team>& teams_list)
 {
+       assert(!teams);
        teams = &teams_list;
 }
 
 teams_manager::~teams_manager()
 {
        teams = NULL;
+}
+
+const std::vector<team>& teams_manager::get_teams()
+{
+       assert(teams);
+       return *teams;
 }
 
 bool teams_manager::is_observer()

Modified: trunk/src/team.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/team.hpp?rev=29390&r1=29389&r2=29390&view=diff
==============================================================================
--- trunk/src/team.hpp (original)
+++ trunk/src/team.hpp Thu Sep 11 14:34:01 2008
@@ -331,6 +331,7 @@
        ~teams_manager();
 
        bool is_observer();
+       static const std::vector<team>& get_teams();
 };
 
 namespace player_teams {

Modified: trunk/src/unit.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/unit.cpp?rev=29390&r1=29389&r2=29390&view=diff
==============================================================================
--- trunk/src/unit.cpp (original)
+++ trunk/src/unit.cpp Thu Sep 11 14:34:01 2008
@@ -168,13 +168,12 @@
            units_(o.units_),
            map_(o.map_),
            gamestatus_(o.gamestatus_),
-           teams_(o.teams_),
                   invisibility_cache_()
 {
 }
 
 unit::unit(unit_map* unitmap, const gamemap* map, const gamestatus* 
game_status,
-               const std::vector<team>* teams,const config& cfg,
+               const std::vector<team>* /*teams*/,const config& cfg,
                bool use_traits, game_state* state) :
        cfg_(),
        advances_to_(),
@@ -241,7 +240,6 @@
        units_(unitmap),
        map_(map),
        gamestatus_(game_status),
-       teams_(teams),
        invisibility_cache_()
 {
        read(cfg, use_traits, state);
@@ -319,7 +317,6 @@
        units_(NULL),
        map_(NULL),
        gamestatus_(NULL),
-       teams_(NULL),
        invisibility_cache_()
 {
        read(cfg,use_traits);
@@ -358,7 +355,7 @@
 }
 
 unit::unit(unit_map* unitmap, const gamemap* map, const gamestatus* 
game_status,
-               const std::vector<team>* teams, const unit_type* t, int side,
+               const std::vector<team>* /*teams*/, const unit_type* t, int 
side,
                bool use_traits, bool dummy_unit, unit_race::GENDER gender, 
std::string variation) :
        cfg_(),
        advances_to_(),
@@ -425,7 +422,6 @@
        units_(unitmap),
        map_(map),
        gamestatus_(game_status),
-       teams_(teams),
        invisibility_cache_()
 {
        cfg_["upkeep"]="full";
@@ -524,7 +520,6 @@
        units_(NULL),
        map_(NULL),
        gamestatus_(NULL),
-       teams_(NULL),
        invisibility_cache_()
 {
        cfg_["upkeep"]="full";
@@ -583,12 +578,11 @@
 
 
 
-void unit::set_game_context(unit_map* unitmap, const gamemap* map, const 
gamestatus* game_status, const std::vector<team>* teams)
+void unit::set_game_context(unit_map* unitmap, const gamemap* map, const 
gamestatus* game_status, const std::vector<team>* /*teams*/)
 {
        units_ = unitmap;
        map_ = map;
        gamestatus_ = game_status;
-       teams_ = teams;
 
        // In case the unit carries EventWML, apply it now
        game_events::add_events(cfg_.get_children("event"),type_);
@@ -1288,15 +1282,15 @@
                                std::vector<std::pair<int,int> 
>::const_iterator range, range_end = ranges.end();
                                for (range = ranges.begin(); range != 
range_end; ++range) {
                                        for (int i=range->first; 
i<=range->second; ++i) {
-                                               if (i > 0 && 
static_cast<size_t>(i) <= teams_->size()) {
+                                               if (i > 0 && 
static_cast<size_t>(i) <= teams_manager::get_teams().size()) {
                                                        viewers.insert(i);
                                                }
                                        }
                                }
                        } else {
                                //if viewing_side is not defined, default to 
all enemies
-                               const team& my_team = (*teams_)[this->side()-1];
-                               for (size_t i = 1; i <= teams_->size(); ++i) {
+                               const team& my_team = 
teams_manager::get_teams()[this->side()-1];
+                               for (size_t i = 1; i <= 
teams_manager::get_teams().size(); ++i) {
                                        if (my_team.is_enemy(i)) {
                                                viewers.insert(i);
                                        }
@@ -1307,8 +1301,8 @@
                        }
                        std::set<int>::const_iterator viewer, viewer_end = 
viewers.end();
                        for (viewer = viewers.begin(); viewer != viewer_end; 
++viewer) {
-                               bool not_fogged = !(*teams_)[*viewer - 
1].fogged(loc);
-                               bool not_hiding = !this->invisible(loc, 
*units_, *teams_ /*, false(?) */);
+                               bool not_fogged = 
!teams_manager::get_teams()[*viewer - 1].fogged(loc);
+                               bool not_hiding = !this->invisible(loc, 
*units_, teams_manager::get_teams()/*, false(?) */);
                                if (visible != not_fogged && not_hiding) {
                                        return false;
                                }
@@ -1336,7 +1330,7 @@
                                        continue;
                                }
                                if (!(*i).has_attribute("is_enemy")
-                               || utils::string_bool((*i)["is_enemy"]) == 
(*teams_)[this->side()-1].is_enemy(unit_itor->second.side())) {
+                               || utils::string_bool((*i)["is_enemy"]) == 
teams_manager::get_teams()[this->side()-1].is_enemy(unit_itor->second.side())) {
                                        ++match_count;
                                }
                        }

Modified: trunk/src/unit.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/unit.hpp?rev=29390&r1=29389&r2=29390&view=diff
==============================================================================
--- trunk/src/unit.hpp (original)
+++ trunk/src/unit.hpp Thu Sep 11 14:34:01 2008
@@ -119,7 +119,7 @@
        /** Set to true for some scenario-specific units which should not be 
renamed */
        bool unrenamable() const { return unrenamable_; }
        unsigned int side() const { return side_; }
-       std::string side_id() const {return (*teams_)[side()-1].save_id(); }
+       std::string side_id() const {return 
teams_manager::get_teams()[side()-1].save_id(); }
        Uint32 team_rgb() const { return(team::get_side_rgb(side())); }
        const std::string& team_color() const { return flag_rgb_; }
        unit_race::GENDER gender() const { return gender_; }
@@ -425,7 +425,6 @@
        const unit_map* units_;
        const gamemap* map_;
        const gamestatus* gamestatus_;
-       const std::vector<team>* teams_;
 
        /** Hold the visibility status cache for a unit, mutable since it's a 
cache. */
        mutable std::map<gamemap::location, bool> invisibility_cache_;


_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits

Reply via email to