wesnoth-cvs-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Wesnoth-cvs-commits] wesnoth/src actions.cpp actions.hpp


From: Philippe Plantier
Subject: [Wesnoth-cvs-commits] wesnoth/src actions.cpp actions.hpp
Date: Mon, 12 Sep 2005 17:36:04 -0400

CVSROOT:        /cvsroot/wesnoth
Module name:    wesnoth
Branch:         
Changes by:     Philippe Plantier <address@hidden>      05/09/12 21:36:04

Modified files:
        src            : actions.cpp actions.hpp 

Log message:
        Using const_cast to modify a const variable is just wrong, even if the
        modification is temporary. Removing the const casts.

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/actions.cpp.diff?tr1=1.240&tr2=1.241&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/actions.hpp.diff?tr1=1.53&tr2=1.54&r1=text&r2=text

Patches:
Index: wesnoth/src/actions.cpp
diff -u wesnoth/src/actions.cpp:1.240 wesnoth/src/actions.cpp:1.241
--- wesnoth/src/actions.cpp:1.240       Tue Sep  6 13:53:14 2005
+++ wesnoth/src/actions.cpp     Mon Sep 12 21:36:04 2005
@@ -1,4 +1,4 @@
-/* $Id: actions.cpp,v 1.240 2005/09/06 13:53:14 ott Exp $ */
+/* $Id: actions.cpp,v 1.241 2005/09/12 21:36:04 gruikya Exp $ */
 /*
    Copyright (C) 2003 by David White <address@hidden>
    Part of the Battle for Wesnoth Project http://www.wesnoth.org/
@@ -1651,12 +1651,12 @@
 //seen_units will return new units that have been seen by this unit
 //if known_units is NULL, seen_units can be NULL and will not be changed
 bool clear_shroud_unit(const gamemap& map,
-                                const gamestatus& status,
-                                                         const game_data& 
gamedata,
-                       const unit_map& units, const gamemap::location& loc,
-                       std::vector<team>& teams, int team,
-                                          const std::set<gamemap::location>* 
known_units,
-                                          std::set<gamemap::location>* 
seen_units)
+               const gamestatus& status,
+               const game_data& gamedata,
+               const unit_map& units, const gamemap::location& loc,
+               std::vector<team>& teams, int team,
+               const std::set<gamemap::location>* known_units,
+               std::set<gamemap::location>* seen_units)
 {
        std::vector<gamemap::location> cleared_locations;
 
@@ -1699,18 +1699,14 @@
 }
 
 void recalculate_fog(const gamemap& map, const gamestatus& status,
-               const game_data& gamedata, const unit_map& units,
+               const game_data& gamedata, unit_map& units,
                std::vector<team>& teams, int team) {
 
        teams[team].refog();
 
-       for(unit_map::const_iterator i = units.begin(); i != units.end(); ++i) {
+       for(unit_map::iterator i = units.begin(); i != units.end(); ++i) {
                if(i->second.side() == team+1) {
-
-                       //we're not really going to mutate the unit, just 
temporarily
-                       //set its moves to maximum, but then switch them back
-                       unit& mutable_unit = const_cast<unit&>(i->second);
-                       const unit_movement_resetter 
move_resetter(mutable_unit);
+                       const unit_movement_resetter move_resetter(i->second);
 
                        
clear_shroud_unit(map,status,gamedata,units,i->first,teams,team,NULL,NULL);
                }
@@ -1718,22 +1714,18 @@
 }
 
 bool clear_shroud(display& disp, const gamestatus& status,
-                           const gamemap& map, const game_data& gamedata,
-                  const unit_map& units, std::vector<team>& teams, int team)
+               const gamemap& map, const game_data& gamedata,
+                  unit_map& units, std::vector<team>& teams, int team)
 {
        if(teams[team].uses_shroud() == false && teams[team].uses_fog() == 
false)
                return false;
 
        bool result = false;
 
-       unit_map::const_iterator i;
+       unit_map::iterator i;
        for(i = units.begin(); i != units.end(); ++i) {
                if(i->second.side() == team+1) {
-
-                       //we're not really going to mutate the unit, just 
temporarily
-                       //set its moves to maximum, but then switch them back
-                       unit& mutable_unit = const_cast<unit&>(i->second);
-                       const unit_movement_resetter 
move_resetter(mutable_unit);
+                       const unit_movement_resetter move_resetter(i->second);
 
                        result |= 
clear_shroud_unit(map,status,gamedata,units,i->first,teams,team,NULL,NULL);
                }
@@ -2055,11 +2047,12 @@
 }
 
 void apply_shroud_changes(undo_list& undos, display* disp, const gamestatus& 
status, const gamemap& map,
-       const game_data& gamedata, const unit_map& units, std::vector<team>& 
teams, int team)
+       const game_data& gamedata, unit_map& units, std::vector<team>& teams, 
int team)
 {
        // No need to do this if the team isn't using fog or shroud.
        if(!teams[team].uses_shroud() && !teams[team].uses_fog())
                return;
+
        /*
                This function works thusly:
                1. run through the list of undo_actions
@@ -2069,17 +2062,19 @@
                5. call clear_shroud to update the fog of war for each unit.
                6. fix up associated display stuff (done in a similar way to 
turn_info::undo())
        */
-       for(undo_list::const_iterator un = undos.begin(); un != undos.end(); 
++un) {
+       for(undo_list::iterator un = undos.begin(); un != undos.end(); ++un) {
+               std::cout << "Turning an undo...\n";
                if(un->is_recall()) continue;
                //we're not really going to mutate the unit, just temporarily
                //set its moves to maximum, but then switch them back
-               const unit_movement_resetter 
move_resetter(const_cast<unit&>(un->affected_unit));
+               const unit_movement_resetter move_resetter(un->affected_unit);
 
                std::vector<gamemap::location>::const_iterator step;
                for(step = un->route.begin(); step != un->route.end(); ++step) {
                        //we have to swap out any unit that is already in the 
hex, so we can put our
                        //unit there, then we'll swap back at the end.
-                       const temporary_unit_placer 
unit_placer(const_cast<unit_map&>(units),*step,un->affected_unit);
+                       const temporary_unit_placer 
unit_placer(units,*step,un->affected_unit);
+
                        
clear_shroud_unit(map,status,gamedata,units,*step,teams,team,NULL,NULL);
                }
        }
Index: wesnoth/src/actions.hpp
diff -u wesnoth/src/actions.hpp:1.53 wesnoth/src/actions.hpp:1.54
--- wesnoth/src/actions.hpp:1.53        Sat Aug 27 22:24:10 2005
+++ wesnoth/src/actions.hpp     Mon Sep 12 21:36:04 2005
@@ -1,4 +1,4 @@
-/* $Id: actions.hpp,v 1.53 2005/08/27 22:24:10 gruikya Exp $ */
+/* $Id: actions.hpp,v 1.54 2005/09/12 21:36:04 gruikya Exp $ */
 /*
    Copyright (C) 2003 by David White <address@hidden>
    Part of the Battle for Wesnoth Project http://www.wesnoth.org/
@@ -199,18 +199,18 @@
 //function which recalculates the fog
 void recalculate_fog(const gamemap& map, const gamestatus& status,
                      const game_data& gamedata,
-                     const unit_map& units, std::vector<team>& teams, int 
team);
+                     unit_map& units, std::vector<team>& teams, int team);
 
 //function which will clear shroud away for the given 0-based team based on
 //current unit positions. Returns true if some shroud is actually cleared away.
 bool clear_shroud(display& disp, const gamestatus& status,
-                           const gamemap& map, const game_data& gamedata,
-                  const unit_map& units, std::vector<team>& teams, int team);
+               const gamemap& map, const game_data& gamedata,
+               unit_map& units, std::vector<team>& teams, int team);
 
 //function to apply pending shroud changes in the undo stack.
 //it needs tons of parameters because it calls clear_shroud(...) (see above)
 void apply_shroud_changes(undo_list& undos, display* disp, const gamestatus& 
status, const gamemap& map,
-       const game_data& gamedata, const unit_map& units, std::vector<team>& 
teams, int team);
+       const game_data& gamedata, unit_map& units, std::vector<team>& teams, 
int team);
 
 //will return true iff the unit at 'loc' has any possible moves it can do
 //(including attacking etc).




reply via email to

[Prev in Thread] Current Thread [Next in Thread]