On Sun, Jun 29, 2008 at 05:30:47PM +0200, jeremy rosen wrote:
>    this sounds like an interesting patch, could you submit it to
>    [1]patches.wesnoth.org ?

Yes, I will as soon as gna.org sends me an email with my account
verification. In the mean time, here's an improved patch.

>    it's easier for us to deal with it that way...
> 
>    a few comments while I'm at it so you can work on them right away...

[snip]

>    3) please use foreach.hpp instead of a C like "for" loop. You can also use
>    iterators if you want, but avoid the C style as much as possible

It's not clear to me how to use foreach.hpp, so I used iterators.

>    4)  hp_dist[hp_dist.size() - 1] = 1 - hp_dist[0]; better written with
>    hp_dist.back()
>         (I couldn't figure what that line was for, btw, but I did a quick
>    review, so i probably missed something)

It runs in a situation where if I engage in combat and don't die, I
will level up. (e.g. I'm 1 XP short, and fighting a level 1
creature.) It means "the probability of being fully healed is the
probability of not dying."

>      On Sun, Jun 29, 2008 at 10:46:47AM -0400, Cameron J. Morland wrote:
>      > - sometimes the experience level of the opponent is not correctly set
>      > in opp.u_
>      >
>      > - When the defendent can't hit back, both units show as being
>      > unharmed. I don't understand why this is.

I believe I have fixed both of these bugs, which were related.

-- 
+-----------------------------------------------------------------
| PGP http://www.cns.bu.edu/~cjmorlan/public-key.pgp
| Cameron Morland             ----             [EMAIL PROTECTED]
|
| The ink of a scholar is more sacred than the blood of the martyr.
|     --Mohammed
+-----------------------------------------------------------------
diff -ur -x '*.o' -x '*.png' -x '*.jpg' -x '*.gmo' -x Makefile 
wesnoth-1.5.1.orig/changelog wesnoth-1.5.1/changelog
--- wesnoth-1.5.1.orig/changelog        2008-06-20 23:15:46.000000000 +0200
+++ wesnoth-1.5.1/changelog     2008-06-29 20:14:44.000000000 +0200
@@ -174,6 +174,7 @@
    * fix a regression about missing default portrait in dialogs.
    * fix false move-cursor around enemies after some dialog events.
    * fix some unit decapitation when placed on a keep
+   * calculate hitpoints that will result if units level up
 
 Version 1.5.0:
  * campaigns:
Only in wesnoth-1.5.1/: changelog~
Only in wesnoth-1.5.1/: config.h
Only in wesnoth-1.5.1/: config.log
Only in wesnoth-1.5.1/: config.status
diff -ur -x '*.o' -x '*.png' -x '*.jpg' -x '*.gmo' -x Makefile 
wesnoth-1.5.1.orig/data/core/about.cfg wesnoth-1.5.1/data/core/about.cfg
--- wesnoth-1.5.1.orig/data/core/about.cfg      2008-06-13 22:20:22.000000000 
+0200
+++ wesnoth-1.5.1/data/core/about.cfg   2008-06-29 20:12:58.000000000 +0200
@@ -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]
Only in wesnoth-1.5.1/data/core: about.cfg~
Only in wesnoth-1.5.1/: po
diff -ur -x '*.o' -x '*.png' -x '*.jpg' -x '*.gmo' -x Makefile 
wesnoth-1.5.1.orig/src/actions.cpp wesnoth-1.5.1/src/actions.cpp
--- wesnoth-1.5.1.orig/src/actions.cpp  2008-06-18 22:16:34.000000000 +0200
+++ wesnoth-1.5.1/src/actions.cpp       2008-06-29 20:18:00.000000000 +0200
@@ -625,6 +625,11 @@
                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) {
                weapon->set_specials_context(*aloc, *dloc, &units, &map, 
&status, &teams, attacking, opp_weapon);
Only in wesnoth-1.5.1/src: actions.cpp~
diff -ur -x '*.o' -x '*.png' -x '*.jpg' -x '*.gmo' -x Makefile 
wesnoth-1.5.1.orig/src/actions.hpp wesnoth-1.5.1/src/actions.hpp
--- wesnoth-1.5.1.orig/src/actions.hpp  2008-06-18 22:16:34.000000000 +0200
+++ wesnoth-1.5.1/src/actions.hpp       2008-06-29 19:53:46.000000000 +0200
@@ -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. */
Only in wesnoth-1.5.1/src: actions.hpp~
Only in wesnoth-1.5.1/src: #attack_prediction.cpp#
diff -ur -x '*.o' -x '*.png' -x '*.jpg' -x '*.gmo' -x Makefile 
wesnoth-1.5.1.orig/src/attack_prediction.cpp 
wesnoth-1.5.1/src/attack_prediction.cpp
--- wesnoth-1.5.1.orig/src/attack_prediction.cpp        2008-03-19 
17:55:39.000000000 +0100
+++ wesnoth-1.5.1/src/attack_prediction.cpp     2008-06-29 21:00:22.000000000 
+0200
@@ -492,10 +492,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)
@@ -718,6 +716,45 @@
        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!
 // ... Or maybe two.  But definitely not three.
 // Of course, one could be a woman.  Or both.
@@ -799,6 +836,9 @@
                        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
        // and make sure it stays within bounds
Only in wesnoth-1.5.1/src: attack_prediction.cpp~
diff -ur -x '*.o' -x '*.png' -x '*.jpg' -x '*.gmo' -x Makefile 
wesnoth-1.5.1.orig/src/attack_prediction.hpp 
wesnoth-1.5.1/src/attack_prediction.hpp
--- wesnoth-1.5.1.orig/src/attack_prediction.hpp        2008-02-16 
09:47:16.000000000 +0100
+++ wesnoth-1.5.1/src/attack_prediction.hpp     2008-06-29 19:53:46.000000000 
+0200
@@ -36,6 +36,8 @@
        //! Simulate a fight!  Can be called multiple times for cumulative 
calculations.
        void fight(combatant &opponent);
 
+       void consider_levelup(combatant &opponent);
+
        //! Resulting probability distribution (may NOT be as large as max_hp)
        std::vector<double> hp_dist;
 
Only in wesnoth-1.5.1/src: attack_prediction.hpp~
Only in wesnoth-1.5.1/src/campaign_server: .deps
Only in wesnoth-1.5.1/src: .deps
Only in wesnoth-1.5.1/src/editor: .deps
Only in wesnoth-1.5.1/src/editor2: .deps
Only in wesnoth-1.5.1/src/gui/dialogs: .deps
Only in wesnoth-1.5.1/src/gui/dialogs: .dirstamp
Only in wesnoth-1.5.1/src/gui/widgets: .deps
Only in wesnoth-1.5.1/src/gui/widgets: .dirstamp
Only in wesnoth-1.5.1/src: libwesnoth.a
Only in wesnoth-1.5.1/src: libwesnoth-core.a
Only in wesnoth-1.5.1/src: Makefile~
Only in wesnoth-1.5.1/src: revision.hpp
Only in wesnoth-1.5.1/src/serialization: .deps
Only in wesnoth-1.5.1/src/serialization: .dirstamp
Only in wesnoth-1.5.1/src/server: .deps
Only in wesnoth-1.5.1/src: TAGS
Only in wesnoth-1.5.1/src/tests: .deps
Only in wesnoth-1.5.1/src/tools: .deps
Only in wesnoth-1.5.1/src: wesnoth
Only in wesnoth-1.5.1/src/widgets: .deps
Only in wesnoth-1.5.1/src/widgets: .dirstamp
Only in wesnoth-1.5.1/: stamp-h1
Only in wesnoth-1.5.1/: translations
_______________________________________________
Wesnoth-dev mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-dev

Reply via email to