[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Wesnoth-cvs-commits] wesnoth/src actions.cpp
From: |
ott |
Subject: |
[Wesnoth-cvs-commits] wesnoth/src actions.cpp |
Date: |
Sun, 15 May 2005 12:02:30 -0400 |
CVSROOT: /cvsroot/wesnoth
Module name: wesnoth
Branch:
Changes by: ott <address@hidden> 05/05/15 16:02:30
Modified files:
src : actions.cpp
Log message:
tidy up %-to-kill, support firststrike
CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/actions.cpp.diff?tr1=1.221&tr2=1.222&r1=text&r2=text
Patches:
Index: wesnoth/src/actions.cpp
diff -u wesnoth/src/actions.cpp:1.221 wesnoth/src/actions.cpp:1.222
--- wesnoth/src/actions.cpp:1.221 Sat May 14 07:56:47 2005
+++ wesnoth/src/actions.cpp Sun May 15 16:02:29 2005
@@ -1,4 +1,4 @@
-/* $Id: actions.cpp,v 1.221 2005/05/14 07:56:47 ott Exp $ */
+/* $Id: actions.cpp,v 1.222 2005/05/15 16:02:29 ott Exp $ */
/*
Copyright (C) 2003 by David White <address@hidden>
Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
@@ -240,16 +240,13 @@
// p probability to hit, n swings, d damage/swing
double P = 0.0;
// 0 damage can happen when unit has no attack of this type
- if(d == 0) {
- if(m <= 0)
- P = 1.0;
- return P;
- }
+ if(d == 0)
+ return (m <= 0) ? 1.0 : P;
for(int k = (m + d - 1)/d; k <= n; ++k) {
double r = 1.0;
const int k2 = (k > n - k) ? (n - k) : k;
for(int i = 0; i < k2; ++i) { r *= (n-i); r /= (k2-i); }
- P += ((int)r) * pow(p, k) * pow(1-p, n-k);
+ P += r * pow(p, k) * pow(1-p, n-k);
}
return P;
}
@@ -281,7 +278,7 @@
const double t1 = pr_between(hpb - dmga, hpb, pa,
(swa<swb) ? reduce(n-1, swa, swb) : (n-1), dmga);
const int n2 = second ? n : (n - 1);
- const double t2 = 1 - pr_atleast(hpa, pb,
+ const double t2 = 1.0 - pr_atleast(hpa, pb,
(swa>swb) ? reduce(n2, swb, swa) : n2, dmgb);
return t1 * pa * t2;
}
@@ -621,10 +618,10 @@
if(d->second.has_flag(slowed_string) && res.ndefends > 1)
--res.ndefends;
- // FIXME: doesn't take into account berserk+slow, drain or firststrike
+ // FIXME: doesn't take into account berserk+slow or drain
if (strings && res.amount_attacker_drains == 0 &&
res.amount_defender_drains == 0 &&
- (!res.defender_strikes_first) && !(res.to_the_death &&
+ !(res.to_the_death &&
(res.attacker_slows || res.defender_slows)))
{
const int maxrounds = (res.to_the_death ? 30 : 1);
@@ -636,23 +633,21 @@
const double pb = res.chance_to_hit_attacker/100.0;
const int swa = res.nattacks;
const int swb = res.ndefends;
- double P1 = 0; double P2 = 0;
+ double P1 = 0;
- for(int n = 1; n <= maxrounds*maximum<int>(swa,swb); ++n) {
+ for(int n = 1; n <= maxrounds*maximum<int>(swa,swb); ++n)
P1 += pr_kills_during(hpa, dmga, pa, swa,
- hpb, dmgb, pb, swb, n, false);
- P2 += pr_kills_during(hpb, dmgb, pb, swb,
- hpa, dmga, pa, swa, n, true);
- }
-
+ hpb, dmgb, pb, swb, n, res.defender_strikes_first);
+ const double P3 = (1.0 - pr_atleast(hpb,pa,maxrounds*swa,dmga))
+ * (1.0 - pr_atleast(hpa,pb,maxrounds*swb,dmgb));
std::stringstream str;
- if (P1 < 0.005 && P2 < 0.005) {
+ if (P3 > 0.99) {
str << _("(both should survive)") << EMPTY_COLUMN;
} else {
str << _("% Pr[kills/killed by/both survive]")
<< EMPTY_COLUMN << (int)(P1*100+0.5)
- << '/' << (int)(P2*100+0.5)
- << '/' << (int)((1-P1-P2)*100+0.5);
+ << '/' << (int)((1-P1-P3)*100+0.5)
+ << '/' << (int)(P3*100+0.5);
}
strings->attack_calculations.push_back(str.str());
}
- [Wesnoth-cvs-commits] wesnoth/src actions.cpp, ott, 2005/05/10
- [Wesnoth-cvs-commits] wesnoth/src actions.cpp, John McNabb, 2005/05/13
- [Wesnoth-cvs-commits] wesnoth/src actions.cpp, ott, 2005/05/13
- [Wesnoth-cvs-commits] wesnoth/src actions.cpp, ott, 2005/05/13
- [Wesnoth-cvs-commits] wesnoth/src actions.cpp, ott, 2005/05/13
- [Wesnoth-cvs-commits] wesnoth/src actions.cpp, ott, 2005/05/14
- [Wesnoth-cvs-commits] wesnoth/src actions.cpp,
ott <=
- [Wesnoth-cvs-commits] wesnoth/src actions.cpp, David White, 2005/05/29
- [Wesnoth-cvs-commits] wesnoth/src actions.cpp, David White, 2005/05/29