mail[Wesnoth-commits] r43512 - in /trunk/src: unit.cpp unit.hpp unit_abilities.cpp


Others Months | Index by Date | Thread Index
>>   [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Header


Content

Posted by alinktomine on June 16, 2010 - 22:41:
Author: alink
Date: Wed Jun 16 22:41:54 2010
New Revision: 43512

URL: http://svn.gna.org/viewcvs/wesnoth?rev=43512&view=rev
Log:
Remove units_ from unit class, and always use resources::units instead.
(some polishing are still needed)

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

Modified: trunk/src/unit.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/unit.cpp?rev=43512&r1=43511&r2=43512&view=diff
==============================================================================
--- trunk/src/unit.cpp (original)
+++ trunk/src/unit.cpp Wed Jun 16 22:41:54 2010
@@ -200,7 +200,6 @@
            draw_bars_(o.draw_bars_),
 
            modifications_(o.modifications_),
-           units_(o.units_),
                   invisibility_cache_()
 {
 }
@@ -273,7 +272,6 @@
        hidden_(false),
        draw_bars_(false),
        modifications_(),
-       units_(resources::units),
        invisibility_cache_()
 {
        if (type_.empty()) {
@@ -621,7 +619,6 @@
        hidden_(false),
        draw_bars_(false),
        modifications_(),
-       units_(resources::units),
        invisibility_cache_()
 {
 
@@ -681,10 +678,8 @@
 
 
 
-void unit::set_game_context(unit_map *unitmap)
-{
-       units_ = unitmap;
-
+void unit::set_game_context(unit_map* /*unitmap*/)
+{
        // In case the unit carries EventWML, apply it now
        game_events::add_events(cfg_.child_range("event"), type_);
        cfg_.clear_children("event");
@@ -1209,8 +1204,8 @@
        bool matches = true;
 
        if(loc.valid()) {
-               assert(units_ != NULL);
-               scoped_xy_unit auto_store("this_unit", loc.x, loc.y, *units_);
+               assert(resources::units != NULL);
+               scoped_xy_unit auto_store("this_unit", loc.x, loc.y, 
*resources::units);
                matches = internal_matches_filter(cfg, loc, use_flat_tod);
        } else {
                // If loc is invalid, then this is a recall list unit 
(already been scoped)
@@ -1263,9 +1258,9 @@
                assert(resources::game_map != NULL);
                assert(resources::teams != NULL);
                assert(resources::tod_manager != NULL);
-               assert(units_ != NULL);
+               assert(resources::units != NULL);
                const vconfig& t_cfg = cfg.child("filter_location");
-               terrain_filter t_filter(t_cfg, *units_, use_flat_tod);
+               terrain_filter t_filter(t_cfg, *resources::units, 
use_flat_tod);
                if(!t_filter.match(loc)) {
                        return false;
                }
@@ -1447,7 +1442,7 @@
                        std::set<int>::const_iterator viewer, viewer_end = 
viewers.end();
                        for (viewer = viewers.begin(); viewer != viewer_end; 
++viewer) {
                                bool not_fogged = 
!teams_manager::get_teams()[*viewer - 1].fogged(loc);
-                               bool not_hiding = !this->invisible(loc, 
*units_, teams_manager::get_teams()/*, false(?) */);
+                               bool not_hiding = !this->invisible(loc, 
*resources::units, teams_manager::get_teams()/*, false(?) */);
                                if (visible != not_fogged && not_hiding) {
                                        return false;
                                }
@@ -1456,7 +1451,8 @@
        }
 
        if (cfg.has_child("filter_adjacent")) {
-               assert(units_ && resources::game_map);
+               assert(resources::units && resources::game_map);
+               const unit_map& units = *resources::units;
                map_location adjacent[6];
                get_adjacent_tiles(loc, adjacent);
                vconfig::child_list::const_iterator i, i_end;
@@ -1469,8 +1465,8 @@
                                ? 
map_location::parse_directions((*i)["adjacent"]) : default_dirs;
                        std::vector<map_location::DIRECTION>::const_iterator 
j, j_end = dirs.end();
                        for (j = dirs.begin(); j != j_end; ++j) {
-                               unit_map::const_iterator unit_itor = 
units_->find(adjacent[*j]);
-                               if (unit_itor == units_->end()
+                               unit_map::const_iterator unit_itor = 
units.find(adjacent[*j]);
+                               if (unit_itor == units.end()
                                || !unit_itor->matches_filter(*i, 
unit_itor->get_location(), use_flat_tod)) {
                                        continue;
                                }

Modified: trunk/src/unit.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/unit.hpp?rev=43512&r1=43511&r2=43512&view=diff
==============================================================================
--- trunk/src/unit.hpp (original)
+++ trunk/src/unit.hpp Wed Jun 16 22:41:54 2010
@@ -441,7 +441,6 @@
        config modifications_;
 
        friend void attack_type::set_specials_context(const map_location& 
loc, const map_location&, const unit& un, bool) const;
-       const unit_map* units_;
 
        /** Hold the visibility status cache for a unit, mutable since it's a 
cache. */
        mutable std::map<map_location, bool> invisibility_cache_;

Modified: trunk/src/unit_abilities.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/unit_abilities.cpp?rev=43512&r1=43511&r2=43512&view=diff
==============================================================================
--- trunk/src/unit_abilities.cpp (original)
+++ trunk/src/unit_abilities.cpp Wed Jun 16 22:41:54 2010
@@ -126,12 +126,12 @@
                }
        }
 
-       assert(units_);
+       const unit_map& units = *resources::units;
        map_location adjacent[6];
        get_adjacent_tiles(loc,adjacent);
        for(int i = 0; i != 6; ++i) {
-               const unit_map::const_iterator it = units_->find(adjacent[i]);
-               if (it == units_->end() || it->incapacitated())
+               const unit_map::const_iterator it = units.find(adjacent[i]);
+               if (it == units.end() || it->incapacitated())
                        continue;
                const config &adj_abilities = it->cfg_.child("abilities");
                if (!adj_abilities)
@@ -160,12 +160,12 @@
                }
        }
 
-       assert(units_ != NULL);
+       const unit_map& units = *resources::units;
        map_location adjacent[6];
        get_adjacent_tiles(loc,adjacent);
        for(int i = 0; i != 6; ++i) {
-               const unit_map::const_iterator it = units_->find(adjacent[i]);
-               if (it == units_->end() || it->incapacitated())
+               const unit_map::const_iterator it = units.find(adjacent[i]);
+               if (it == units.end() || it->incapacitated())
                        continue;
                const config &adj_abilities = it->cfg_.child("abilities");
                if (!adj_abilities)
@@ -246,7 +246,7 @@
 bool unit::ability_active(const std::string& ability,const config& cfg,const 
map_location& loc) const
 {
        int illuminates = -1;
-       assert(units_ && resources::game_map && resources::teams && 
resources::tod_manager);
+       assert(resources::units && resources::game_map && resources::teams && 
resources::tod_manager);
 
        if (const config &afilter = cfg.child("filter"))
                if (!matches_filter(vconfig(afilter), loc, 
cache_illuminates(illuminates, ability)))
@@ -254,6 +254,7 @@
 
        map_location adjacent[6];
        get_adjacent_tiles(loc,adjacent);
+       const unit_map& units = *resources::units;
 
        foreach (const config &i, cfg.child_range("filter_adjacent"))
        {
@@ -263,8 +264,8 @@
                                map_location::parse_direction(j);
                        if (index == map_location::NDIRECTIONS)
                                continue;
-                       unit_map::const_iterator unit = 
units_->find(adjacent[index]);
-                       if (unit == units_->end())
+                       unit_map::const_iterator unit = 
units.find(adjacent[index]);
+                       if (unit == units.end())
                                return false;
                        if (!unit->matches_filter(vconfig(i), 
unit->get_location(),
                                cache_illuminates(illuminates, ability)))
@@ -280,7 +281,7 @@
                        if (index == map_location::NDIRECTIONS) {
                                continue;
                        }
-                       terrain_filter adj_filter(vconfig(i), *units_);
+                       terrain_filter adj_filter(vconfig(i), units);
                        adj_filter.flatten(cache_illuminates(illuminates, 
ability));
                        if(!adj_filter.match(adjacent[index])) {
                                return false;
@@ -752,11 +753,11 @@
        other_attack_ = other_attack;
 }
 
-void attack_type::set_specials_context(const map_location& loc, const 
map_location& dloc, const unit& un, bool attacker) const
+void attack_type::set_specials_context(const map_location& loc, const 
map_location& dloc, const unit& /*un*/, bool attacker) const
 {
        aloc_ = loc;
        dloc_ = dloc;
-       unitmap_ = un.units_;
+       unitmap_ = resources::units;
        attacker_ = attacker;
        other_attack_ = NULL;
 }




Related Messages


Powered by MHonArc, Updated Thu Jun 17 01:00:14 2010