[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Wesnoth-cvs-commits] wesnoth/src actions.cpp
From: |
Guillaume Melquiond |
Subject: |
[Wesnoth-cvs-commits] wesnoth/src actions.cpp |
Date: |
Sun, 02 Jan 2005 17:31:40 -0500 |
CVSROOT: /cvsroot/wesnoth
Module name: wesnoth
Branch:
Changes by: Guillaume Melquiond <address@hidden> 05/01/02 22:09:24
Modified files:
src : actions.cpp
Log message:
Negative division is implementation-defined (may cause OoS), don't use
it; positive division is perfectly defined though, use it to simplify the code.
CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/actions.cpp.diff?tr1=1.179&tr2=1.180&r1=text&r2=text
Patches:
Index: wesnoth/src/actions.cpp
diff -u wesnoth/src/actions.cpp:1.179 wesnoth/src/actions.cpp:1.180
--- wesnoth/src/actions.cpp:1.179 Fri Dec 31 21:01:37 2004
+++ wesnoth/src/actions.cpp Sun Jan 2 22:09:24 2005
@@ -1,4 +1,4 @@
-/* $Id: actions.cpp,v 1.179 2004/12/31 21:01:37 isaaccp Exp $ */
+/* $Id: actions.cpp,v 1.180 2005/01/02 22:09:24 silene Exp $ */
/*
Copyright (C) 2003 by David White <address@hidden>
Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
@@ -367,26 +367,14 @@
//we want to round the absolute value of the difference down
//at 0.5 and below
- const int is_negative = percent < 0 ? -1 : 1;
-
- if(percent < 0) {
- percent *= -1;
- }
-
- int difference = percent*base_damage;
-
- //round up if greater than half
- if((difference%100) > 50) {
- difference += 50;
- }
-
- difference /= 100*is_negative;
+ bool const is_negative = percent < 0;
+ int difference = is_negative ? -percent : percent;
+ difference = (difference * base_damage + 49) / 100;
+ if (is_negative) difference = -difference;
res.damage_attacker_takes = maximum<int>(1,base_damage +
difference);
if (strings) {
- percent *= is_negative;
-
std::stringstream str;
str << _("total damage") << COLUMN_SEPARATOR <<
res.damage_attacker_takes
<< COLUMN_SEPARATOR << (percent >= 0 ? "+" : "") <<
percent
@@ -502,25 +490,13 @@
//we want to round the absolute value of the difference down
//at 0.5 and below
- const int is_negative = percent < 0 ? -1 : 1;
-
- if(percent < 0) {
- percent *= -1;
- }
-
- int difference = percent*base_damage;
-
- //round up if greater than half
- if((difference%100) > 50) {
- difference += 50;
- }
-
- difference /= 100*is_negative;
+ bool const is_negative = percent < 0;
+ int difference = is_negative ? -percent : percent;
+ difference = (difference * base_damage + 49) / 100;
+ if (is_negative) difference = -difference;
res.damage_defender_takes = maximum<int>(1,base_damage + difference);
if (strings) {
- percent *= is_negative;
-
std::stringstream str;
str << _("total damage") << COLUMN_SEPARATOR <<
res.damage_defender_takes
<< COLUMN_SEPARATOR << (percent >= 0 ? "+" : "") << percent
- [Wesnoth-cvs-commits] wesnoth/src actions.cpp,
Guillaume Melquiond <=