CVSROOT:        /cvsroot/wesnoth
Module name:    wesnoth
Branch:         
Changes by:     ott <[EMAIL PROTECTED]> 05/04/22 20:58:35

Modified files:
        src            : unit.cpp 

Log message:
        Be more careful in calculating negative % HP modifiers (eg. quick).

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/unit.cpp.diff?tr1=1.141&tr2=1.142&r1=text&r2=text

Patches:
Index: wesnoth/src/unit.cpp
diff -u wesnoth/src/unit.cpp:1.141 wesnoth/src/unit.cpp:1.142
--- wesnoth/src/unit.cpp:1.141  Thu Apr 21 20:49:16 2005
+++ wesnoth/src/unit.cpp        Fri Apr 22 20:58:35 2005
@@ -1,4 +1,4 @@
-/* $Id: unit.cpp,v 1.141 2005/04/21 20:49:16 gruikya Exp $ */
+/* $Id: unit.cpp,v 1.142 2005/04/22 20:58:35 ott Exp $ */
 /*
    Copyright (C) 2003 by David White <[EMAIL PROTECTED]>
    Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
@@ -1049,7 +1049,15 @@
                                //a percentage on the end means increase by 
that many percent
                                if(increase_total[increase_total.size()-1] == 
'%') {
                                        const std::string 
inc(increase_total.begin(),increase_total.end()-1);
-                                       maxHitpoints_ += 
(maxHitpoints_*atoi(inc.c_str()))/100;
+                                       //work around implementation-defined 
integer division
+                                       //involving negative numbers
+                                       int increment = atoi(inc.c_str());
+                                       int sign = 1;
+                                       if (increment < 0) {
+                                               increment = -increment;
+                                               sign = -1;
+                                       }
+                                       maxHitpoints_ += 
((maxHitpoints_*increment)/100) * sign;
                                } else {
                                        maxHitpoints_ += 
atoi(increase_total.c_str());
                                }


Reply via email to