Author: soliton
Date: Tue May 19 00:15:37 2009
New Revision: 35745

URL: http://svn.gna.org/viewcvs/wesnoth?rev=35745&view=rev
Log:
always default to 0% defense on errors

Modified:
    trunk/src/unit.cpp

Modified: trunk/src/unit.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/unit.cpp?rev=35745&r1=35744&r2=35745&view=diff
==============================================================================
--- trunk/src/unit.cpp (original)
+++ trunk/src/unit.cpp Tue May 19 00:15:37 2009
@@ -2193,6 +2193,8 @@
        }
 
        assert(map_ != NULL);
+       int res = 100;
+
        // If this is an alias, then select the best of all underlying terrains
        const t_translation::t_list& underlying = 
map_->underlying_def_terrain(terrain);
        assert(underlying.size() > 0);
@@ -2202,10 +2204,10 @@
                        ERR_CONFIG << "infinite defense_modifier recursion: " 
<< t_translation::write_terrain_code(terrain) << " depth " << recurse_count << 
"\n";
                }
                if(recurse_count >= 100) {
-                       return 100;
-               }
-
-               int ret_value = revert?0:100;
+                       return res;
+               }
+
+               res = revert ? 0 : 100;
                t_translation::t_list::const_iterator i = underlying.begin();
                for(; i != underlying.end(); ++i) {
                        if(*i == t_translation::PLUS) {
@@ -2216,25 +2218,23 @@
                                continue;
                        }
                        const int value = defense_modifier(*i,recurse_count+1);
-                       if(value < ret_value && !revert) {
-                               ret_value = value;
-                       } else if(value > ret_value && revert) {
-                               ret_value = value;
-                       }
-               }
-
-               
defense_mods_.insert(std::pair<t_translation::t_terrain,int>(terrain,ret_value));
-               return ret_value;
-       }
-
-       int res = -1;
+                       if (value < res && !revert) {
+                               res = value;
+                       } else if (value > res && revert) {
+                               res = value;
+                       }
+               }
+
+               
defense_mods_.insert(std::pair<t_translation::t_terrain,int>(terrain, res));
+               return res;
+       }
 
        if (const config &defense = cfg_.child("defense"))
        {
                if(underlying.size() != 1) {
                        ERR_CONFIG << "terrain '" << terrain << "' has "
                                << underlying.size() << " underlying names - 0 
expected\n";
-                       return 100;
+                       return res;
                }
 
                const std::string& id = 
map_->get_terrain_info(underlying.front()).id();


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

Reply via email to