Author: boucman
Date: Mon Jul 7 20:48:42 2008
New Revision: 27826
URL: http://svn.gna.org/viewcvs/wesnoth?rev=27826&view=rev
Log:
take into account lvl up heal when estimating attack prediction, patch by
roger_wilco
Modified:
trunk/data/core/about.cfg
trunk/src/actions.cpp
trunk/src/actions.hpp
trunk/src/attack_prediction.cpp
trunk/src/attack_prediction.hpp
Modified: trunk/data/core/about.cfg
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/data/core/about.cfg?rev=27826&r1=27825&r2=27826&view=diff
==============================================================================
--- trunk/data/core/about.cfg (original)
+++ trunk/data/core/about.cfg Mon Jul 7 20:48:42 2008
@@ -40,6 +40,9 @@
email = "bruno_AT_wolff.to"
[/entry]
[entry]
+ name = "Cameron Morland"
+ [/entry]
+ [entry]
name = "Cédric Duval"
comment = "coder, internationalization manager"
[/entry]
Modified: trunk/src/actions.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/actions.cpp?rev=27826&r1=27825&r2=27826&view=diff
==============================================================================
--- trunk/src/actions.cpp (original)
+++ trunk/src/actions.cpp Mon Jul 7 20:48:42 2008
@@ -624,6 +624,11 @@
aloc = &opp_loc;
dloc = &u_loc;
}
+
+ // these can matter, even if we can't hit back!
+ experience = u.experience();
+ max_experience = u.max_experience();
+ level = u.level();
// Get the weapon characteristics, if any.
if (weapon) {
Modified: trunk/src/actions.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/actions.hpp?rev=27826&r1=27825&r2=27826&view=diff
==============================================================================
--- trunk/src/actions.hpp (original)
+++ trunk/src/actions.hpp Mon Jul 7 20:48:42 2008
@@ -88,6 +88,8 @@
*/
bool swarm; /**< Attack has swarm
special. */
bool firststrike; /**< Attack has firststrike
special. */
+ unsigned int experience, max_experience;
+ unsigned int level;
unsigned int rounds; /**< Berserk special can force us to
fight more than one round. */
unsigned int hp; /**< Hitpoints of the unit at
the beginning of the battle. */
Modified: trunk/src/attack_prediction.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/attack_prediction.cpp?rev=27826&r1=27825&r2=27826&view=diff
==============================================================================
--- trunk/src/attack_prediction.cpp (original)
+++ trunk/src/attack_prediction.cpp Mon Jul 7 20:48:42 2008
@@ -494,10 +494,8 @@
}
// If this unit drains, HP can increase, so alloc full array.
- if (u.drains) {
- return u.max_hp + 1;
- }
- return u.hp+1;
+ // Do this anyway in case we level up.
+ return u.max_hp + 1;
}
combatant::combatant(const battle_context::unit_stats &u, const combatant
*prev)
@@ -587,7 +585,7 @@
{
if (summary[0].empty()) {
// Starts with a known HP, so Pascal's triangle.
- summary[0] = std::vector<double>(u_.hp+1);
+ summary[0] = std::vector<double>(u_.max_hp+1);
summary[0][u_.hp] = 1.0;
for (unsigned int i = 0; i < opp.hit_chances_.size(); i++) {
for (int j = i; j >= 0; j--) {
@@ -609,7 +607,7 @@
if (opp.summary[0].empty()) {
// Starts with a known HP, so Pascal's triangle.
- opp.summary[0] = std::vector<double>(opp.u_.hp+1);
+ opp.summary[0] = std::vector<double>(opp.u_.max_hp+1);
opp.summary[0][opp.u_.hp] = 1.0;
for (unsigned int i = 0; i < hit_chances_.size(); i++) {
for (int j = i; j >= 0; j--) {
@@ -634,7 +632,7 @@
void combatant::one_strike_fight(combatant &opp)
{
if (opp.summary[0].empty()) {
- opp.summary[0] = std::vector<double>(opp.u_.hp+1);
+ opp.summary[0] = std::vector<double>(opp.u_.max_hp+1);
if (hit_chances_.size() == 1) {
opp.summary[0][opp.u_.hp] = 1.0 - hit_chances_[0];
opp.summary[0][maximum<int>(opp.u_.hp - u_.damage, 0)]
= hit_chances_[0];
@@ -655,7 +653,7 @@
// If we killed opponent, it won't attack us.
double opp_alive_prob = 1.0 - opp.summary[0][0];
if (summary[0].empty()) {
- summary[0] = std::vector<double>(u_.hp+1);
+ summary[0] = std::vector<double>(u_.max_hp+1);
if (opp.hit_chances_.size() == 1) {
summary[0][u_.hp] = 1.0 - opp.hit_chances_[0] *
opp_alive_prob;
summary[0][maximum<int>(u_.hp - opp.u_.damage, 0)] =
opp.hit_chances_[0] * opp_alive_prob;
@@ -721,6 +719,48 @@
// We extract results separately, then combine.
m.extract_results(summary, opp.summary);
+}
+
+void combatant::consider_levelup(combatant &opp) {
+ // adjust the probabilities to take into consideration the
+ // probability of us levelling up, and hence healing.
+ // We do not currently estimate how many HP we will have.
+
+ if (u_.experience + opp.u_.level >= u_.max_experience) {
+ // if we survive the combat, we will level up. So the
probability
+ // of death is unchanged, but all other cases get merged into
+ // the fully healed case.
+ std::vector<double>::iterator i;
+ i = hp_dist.begin();
+ i++; // skip to the second value
+ for ( ; i != hp_dist.end(); i++) {
+ *i = 0;
+ }
+ // fully healed unless dead
+ hp_dist.back() = 1 - hp_dist.front();
+
+
+
+ } else if (u_.experience + ((opp.u_.level == 0) ? 4 : opp.u_.level * 8)
+ >= u_.max_experience) {
+ // if we kill, we will level up. So then the damage we had
+ // becomes less probable since it's now conditional on us not
+ // levelling up. This doesn't apply to the probability of us
+ // dying, of course.
+ float scalefactor =
+ (1 - hp_dist.front() - opp.hp_dist.front()) / (1 -
hp_dist.front());
+ std::vector<double>::iterator i;
+ i = hp_dist.begin();
+ i++; // skip to the second value
+ for( ; i != hp_dist.end(); i++) {
+ *i *= scalefactor;
+ }
+
+ // if we level up, we get fully healed. (FIXME: actually more
so; we
+ // need to calculate how many HP we will gain)
+ hp_dist.back() += opp.hp_dist.front();
+ }
+
}
// Two man enter. One man leave!
@@ -803,6 +843,9 @@
for (unsigned int i = 0; i < opp.hp_dist.size(); i++)
opp.hp_dist[i] = opp.summary[0][i] + opp.summary[1][i];
}
+
+ consider_levelup(opp);
+ opp.consider_levelup(*this);
// Make sure we don't try to access the vectors out of bounds,
// drain increases HPs so we determine the number of HP here
Modified: trunk/src/attack_prediction.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/attack_prediction.hpp?rev=27826&r1=27825&r2=27826&view=diff
==============================================================================
--- trunk/src/attack_prediction.hpp (original)
+++ trunk/src/attack_prediction.hpp Mon Jul 7 20:48:42 2008
@@ -34,6 +34,9 @@
/** Simulate a fight! Can be called multiple times for cumulative
calculations. */
void fight(combatant &opponent);
+
+ /** takes into account level up when calculating resulting HP after a
fight */
+ void consider_levelup(combatant &opponent);
/** Resulting probability distribution (may NOT be as large as max_hp)
*/
std::vector<double> hp_dist;
_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits