Complete.Org: Mailing Lists: Archives: freeciv-dev: December 2001:
[Freeciv-Dev] small GUI unification: decrease_unit_hp_smooth (PR#1099)
Home

[Freeciv-Dev] small GUI unification: decrease_unit_hp_smooth (PR#1099)

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: freeciv-dev@xxxxxxxxxxx
Cc: bugs@xxxxxxxxxxxxxxxxxxx
Subject: [Freeciv-Dev] small GUI unification: decrease_unit_hp_smooth (PR#1099)
From: jdorje@xxxxxxxxxxxxxxxxxxxxx
Date: Fri, 7 Dec 2001 11:36:31 -0800 (PST)

This small unification cuts off part of decrease_unit_hp_smooth (a gui-specific function). It creates a new function, decrease_unit_hp, that takes care of the common case where do_combat_animation is turned off, and only calls decrease_unit_hp_smooth if combat animation is enable.

It also adds comments for all these functions - including the GUI stub function. I think having comments for the GUI stub functions is important, since most of the GUI's just seem to have cut-and-pasted these functions (thus having to write comments themselves or go without - usually the latter).

It's small, but not really related to anything else so here it is all alone.

jason
? old
? topology
? client/diff
? client/gui-gtk/diff
Index: client/packhand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/packhand.c,v
retrieving revision 1.196
diff -u -r1.196 packhand.c
--- client/packhand.c   2001/10/18 16:45:31     1.196
+++ client/packhand.c   2001/12/07 19:13:41
@@ -66,6 +66,8 @@
 
 #include "packhand.h"
 
+static void decrease_unit_hp(struct unit *punit0, int hp0,
+                            struct unit *punit1, int hp1);
 static void handle_city_packet_common(struct city *pcity, int is_new,
                                       int popup, int investigate);
 
@@ -217,6 +219,25 @@
 }
 
 /**************************************************************************
+ Decreases a unit's HP.  If combat animation is turned on, it'll call
+ decrease_unit_hp_smooth.
+**************************************************************************/
+static void decrease_unit_hp(struct unit *punit0, int hp0,
+                            struct unit *punit1, int hp1)
+{
+  if (do_combat_animation) {
+    decrease_unit_hp_smooth(punit0, hp0, punit1, hp1);
+  } else {
+    punit0->hp = hp0;
+    punit1->hp = hp1;
+
+    set_units_in_combat(NULL, NULL);
+    refresh_tile_mapcanvas(punit0->x, punit0->y, 1);
+    refresh_tile_mapcanvas(punit1->x, punit1->y, 1);
+  }
+}
+
+/**************************************************************************
 ...
 **************************************************************************/
 void handle_unit_combat(struct packet_unit_combat *packet)
@@ -238,7 +259,7 @@
     }
 
     if (show_combat) {
-      decrease_unit_hp_smooth(punit0, packet->attacker_hp,
+      decrease_unit_hp(punit0, packet->attacker_hp,
                              punit1, packet->defender_hp);
     }
   }
Index: client/gui-beos/mapview.cpp
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-beos/mapview.cpp,v
retrieving revision 1.2
diff -u -r1.2 mapview.cpp
--- client/gui-beos/mapview.cpp 2000/07/04 23:29:39     1.2
+++ client/gui-beos/mapview.cpp 2001/12/07 19:13:41
@@ -205,6 +205,10 @@
 }
 
 
+/**************************************************************************
+ This function is called to decrease a unit's HP smoothly in battle when
+ combat_animation is turned on.
+**************************************************************************/
 void
 decrease_unit_hp_smooth(struct unit *punit0, int hp0,
                              struct unit *punit1, int hp1)     // HOOK
Index: client/gui-gtk/mapview.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/mapview.c,v
retrieving revision 1.108
diff -u -r1.108 mapview.c
--- client/gui-gtk/mapview.c    2001/11/27 20:11:29     1.108
+++ client/gui-gtk/mapview.c    2001/12/07 19:13:43
@@ -259,7 +259,8 @@
 }
 
 /**************************************************************************
-...
+ This function is called to decrease a unit's HP smoothly in battle when
+ combat_animation is turned on.
 **************************************************************************/
 void decrease_unit_hp_smooth(struct unit *punit0, int hp0, 
                             struct unit *punit1, int hp1)
@@ -267,17 +268,6 @@
   static struct timer *anim_timer = NULL; 
   struct unit *losing_unit = (hp0 == 0 ? punit0 : punit1);
   int i;
-
-  if (!do_combat_animation) {
-    punit0->hp = hp0;
-    punit1->hp = hp1;
-
-    set_units_in_combat(NULL, NULL);
-    refresh_tile_mapcanvas(punit0->x, punit0->y, 1);
-    refresh_tile_mapcanvas(punit1->x, punit1->y, 1);
-
-    return;
-  }
 
   set_units_in_combat(punit0, punit1);
 
Index: client/gui-mui/mapview.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-mui/mapview.c,v
retrieving revision 1.35
diff -u -r1.35 mapview.c
--- client/gui-mui/mapview.c    2001/11/27 20:11:29     1.35
+++ client/gui-mui/mapview.c    2001/12/07 19:13:43
@@ -78,23 +78,14 @@
 }
 
 /**************************************************************************
- ...
+ This function is called to decrease a unit's HP smoothly in battle when
+ combat_animation is turned on.
 **************************************************************************/
 void decrease_unit_hp_smooth(struct unit *punit0, int hp0,
                             struct unit *punit1, int hp1)
 {
   static struct timer *anim_timer = NULL; 
   struct unit *losing_unit = (hp0 == 0 ? punit0 : punit1);
-
-  if (!do_combat_animation) {
-    punit0->hp = hp0;
-    punit1->hp = hp1;
-
-    refresh_tile_mapcanvas(punit0->x, punit0->y, 1);
-    refresh_tile_mapcanvas(punit1->x, punit1->y, 1);
-
-    return;
-  }
 
   set_units_in_combat(punit0, punit1);
 
Index: client/gui-stub/mapview.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-stub/mapview.c,v
retrieving revision 1.8
diff -u -r1.8 mapview.c
--- client/gui-stub/mapview.c   2001/10/30 12:11:45     1.8
+++ client/gui-stub/mapview.c   2001/12/07 19:13:44
@@ -128,6 +128,10 @@
        /* PORTME */
 }
 
+/**************************************************************************
+ This function is called to decrease a unit's HP smoothly in battle when
+ combat_animation is turned on.
+**************************************************************************/
 void
 decrease_unit_hp_smooth(struct unit *punit0, int hp0,
                              struct unit *punit1, int hp1)
Index: client/gui-win32/mapview.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-win32/mapview.c,v
retrieving revision 1.13
diff -u -r1.13 mapview.c
--- client/gui-win32/mapview.c  2001/11/27 20:11:30     1.13
+++ client/gui-win32/mapview.c  2001/12/07 19:13:45
@@ -1139,7 +1139,8 @@
 }
 
 /**************************************************************************
-
+ This function is called to decrease a unit's HP smoothly in battle when
+ combat_animation is turned on.
 **************************************************************************/
 void
 decrease_unit_hp_smooth(struct unit *punit0, int hp0,
@@ -1150,17 +1151,6 @@
   static struct timer *anim_timer = NULL; 
   struct unit *losing_unit = (hp0 == 0 ? punit0 : punit1);
   int i;
-  
-  if (!do_combat_animation) {
-    punit0->hp = hp0;
-    punit1->hp = hp1;
-
-    set_units_in_combat(NULL, NULL);
-    refresh_tile_mapcanvas(punit0->x, punit0->y, 1);
-    refresh_tile_mapcanvas(punit1->x, punit1->y, 1);
-
-    return;
-  }
   
   set_units_in_combat(punit0, punit1);
 
Index: client/gui-xaw/mapview.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-xaw/mapview.c,v
retrieving revision 1.88
diff -u -r1.88 mapview.c
--- client/gui-xaw/mapview.c    2001/11/27 20:11:31     1.88
+++ client/gui-xaw/mapview.c    2001/12/07 19:13:45
@@ -94,7 +94,8 @@
 }
 
 /**************************************************************************
-...
+ This function is called to decrease a unit's HP smoothly in battle when
+ combat_animation is turned on.
 **************************************************************************/
 void decrease_unit_hp_smooth(struct unit *punit0, int hp0, 
                             struct unit *punit1, int hp1)
@@ -103,17 +104,6 @@
   struct unit *losing_unit = (hp0 == 0 ? punit0 : punit1);
   int i;
   int canvas_x, canvas_y;
-
-  if (!do_combat_animation) {
-    punit0->hp = hp0;
-    punit1->hp = hp1;
-
-    set_units_in_combat(NULL, NULL);
-    refresh_tile_mapcanvas(punit0->x, punit0->y, 1);
-    refresh_tile_mapcanvas(punit1->x, punit1->y, 1);
-
-    return;
-  }
 
   set_units_in_combat(punit0, punit1);
 

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