Complete.Org: Mailing Lists: Archives: freeciv-dev: July 2003:
[Freeciv-Dev] Re: (PR#4639) units get more MP than max MP
Home

[Freeciv-Dev] Re: (PR#4639) units get more MP than max MP

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients: ;
Subject: [Freeciv-Dev] Re: (PR#4639) units get more MP than max MP
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Tue, 22 Jul 2003 20:15:44 -0700
Reply-to: rt@xxxxxxxxxxxxxx

ue80@xxxxxxxxxxxxxxxxxxxxx wrote:

> Think you don't scale the HP now because to_unit == punit->id 
> 
> You should move the punit->type = to_unit; under that.
> Or to make cleaner code use the same construction for the HP too. (First
> save the old maxima and then scale)

Gee, that was dumb of me.  Looks like I messed up the math, too.

Perhaps this one is better...still untested.

jason

Index: server/unittools.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/unittools.c,v
retrieving revision 1.235
diff -u -r1.235 unittools.c
--- server/unittools.c  2003/07/21 01:19:36     1.235
+++ server/unittools.c  2003/07/23 03:13:26
@@ -1420,6 +1420,7 @@
 {
   struct player *pplayer = unit_owner(punit);
   int range;
+  int old_mr = unit_move_rate(punit), old_hp = unit_type(punit)->hp;
 
   /* save old vision range */
   if (map_has_special(punit->x, punit->y, S_FORTRESS)
@@ -1428,15 +1429,15 @@
   else
     range = unit_type(punit)->vision_range;
 
+  punit->type = to_unit;
+
   /* Scale HP and MP, rounding down.  Be careful with integer arithmetic,
-   * and don't kill the unit. */
-  punit->hp = MAX(punit->hp * get_unit_type(to_unit)->hp
-                 / unit_type(punit)->hp, 1);
-  punit->moves_left = (punit->moves_left * get_unit_type(to_unit)->move_rate
-                      / unit_type(punit)->move_rate);
+   * and don't kill the unit.  unit_move_rate is used to take into account
+   * global effects like Magellan's Expedition. */
+  punit->hp = MAX(punit->hp * unit_type(punit)->hp / old_hp, 1);
+  punit->moves_left = punit->moves_left * unit_move_rate(punit) / old_mr;
 
   conn_list_do_buffer(&pplayer->connections);
-  punit->type = to_unit;
 
   /* apply new vision range */
   if (map_has_special(punit->x, punit->y, S_FORTRESS)

[Prev in Thread] Current Thread [Next in Thread]