Complete.Org: Mailing Lists: Archives: freeciv-dev: March 2002:
[Freeciv-Dev] [PATCH] use correct enums instead of ints (PR#1319)
Home

[Freeciv-Dev] [PATCH] use correct enums instead of ints (PR#1319)

[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] [PATCH] use correct enums instead of ints (PR#1319)
From: Markus Linnala <maage@xxxxxxxxx>
Date: Sun, 10 Mar 2002 08:54:01 -0800 (PST)

Cleanup, use correct enums instead of ints.

diff -ur -X freeciv/diff_ignore freeciv/ai/aiunit.c 
freeciv-use-enums.patch/ai/aiunit.c
--- freeciv/ai/aiunit.c Wed Mar  6 07:27:57 2002
+++ freeciv-use-enums.patch/ai/aiunit.c Sun Mar 10 18:51:44 2002
@@ -1009,7 +1009,8 @@
 **************************************************************************/
 int find_beachhead(struct unit *punit, int dest_x, int dest_y, int *x, int *y)
 {
-  int ok, t, best = 0;
+  int ok, best = 0;
+  enum tile_terrain_type t;
 
   adjc_iterate(dest_x, dest_y, x1, y1) {
     ok = 0;
diff -ur -X freeciv/diff_ignore freeciv/common/map.c 
freeciv-use-enums.patch/common/map.c
--- freeciv/common/map.c        Wed Feb 27 10:18:40 2002
+++ freeciv-use-enums.patch/common/map.c        Sun Mar 10 18:51:44 2002
@@ -639,7 +639,7 @@
 /***************************************************************
 ...
 ***************************************************************/
-int get_preferred_pillage(int pset)
+enum tile_special_type get_preferred_pillage(int pset)
 {
   if (contains_special(pset, S_FARMLAND))
     return S_FARMLAND;
diff -ur -X freeciv/diff_ignore freeciv/common/map.h 
freeciv-use-enums.patch/common/map.h
--- freeciv/common/map.h        Wed Feb 27 12:32:46 2002
+++ freeciv-use-enums.patch/common/map.h        Sun Mar 10 18:51:44 2002
@@ -328,7 +328,7 @@
 int get_tile_infrastructure_set(struct tile * ptile);
 char *map_get_infrastructure_text(int spe);
 int map_get_infrastructure_prerequisite(int spe);
-int get_preferred_pillage(int pset);
+enum tile_special_type get_preferred_pillage(int pset);
 
 void map_irrigate_tile(int x, int y);
 void map_mine_tile(int x, int y);
diff -ur -X freeciv/diff_ignore freeciv/common/unit.c 
freeciv-use-enums.patch/common/unit.c
--- freeciv/common/unit.c       Tue Feb 26 18:57:51 2002
+++ freeciv-use-enums.patch/common/unit.c       Sun Mar 10 18:51:44 2002
@@ -580,8 +580,8 @@
 bool can_unit_continue_current_activity(struct unit *punit)
 {
   enum unit_activity current = punit->activity;
-  int target = punit->activity_target;
-  int current2 = current == ACTIVITY_FORTIFIED ? ACTIVITY_FORTIFYING : current;
+  enum tile_special_type target = punit->activity_target;
+  enum unit_activity current2 = current == ACTIVITY_FORTIFIED ? 
ACTIVITY_FORTIFYING : current;
   bool result;
 
   if (punit->connecting)
@@ -612,7 +612,7 @@
 as it would be a ajor CPU hog.
 **************************************************************************/
 bool can_unit_do_activity_targeted(struct unit *punit,
-                                 enum unit_activity activity, int target)
+                                 enum unit_activity activity, enum 
tile_special_type target)
 {
   struct player *pplayer;
   struct tile *ptile;
@@ -786,7 +786,7 @@
   assign a new targeted task to a unit.
 **************************************************************************/
 void set_unit_activity_targeted(struct unit *punit,
-                               enum unit_activity new_activity, int new_target)
+                               enum unit_activity new_activity, enum 
tile_special_type new_target)
 {
   punit->activity=new_activity;
   punit->activity_count=0;
@@ -811,7 +811,7 @@
 **************************************************************************/
 int get_unit_tile_pillage_set(int x, int y)
 {
-  int tgt_ret = S_NO_SPECIAL;
+  enum tile_special_type tgt_ret = S_NO_SPECIAL;
   unit_list_iterate(map_get_tile(x, y)->units, punit)
     if(punit->activity==ACTIVITY_PILLAGE)
       tgt_ret |= punit->activity_target;
diff -ur -X freeciv/diff_ignore freeciv/common/unit.h 
freeciv-use-enums.patch/common/unit.h
--- freeciv/common/unit.h       Wed Feb 27 13:12:25 2002
+++ freeciv-use-enums.patch/common/unit.h       Sun Mar 10 18:51:44 2002
@@ -123,7 +123,7 @@
   enum unit_activity activity;
   int goto_dest_x, goto_dest_y;
   int activity_count;
-  int activity_target;
+  enum tile_special_type activity_target;
   enum unit_focus_status focus_status;
   int ord_map, ord_city;
   /* ord_map and ord_city are the order index of this unit in tile.units
@@ -196,10 +196,10 @@
 bool can_unit_continue_current_activity(struct unit *punit);
 bool can_unit_do_activity(struct unit *punit, enum unit_activity activity);
 bool can_unit_do_activity_targeted(struct unit *punit,
-                                 enum unit_activity activity, int target);
+                                 enum unit_activity activity, enum 
tile_special_type target);
 void set_unit_activity(struct unit *punit, enum unit_activity new_activity);
 void set_unit_activity_targeted(struct unit *punit,
-                               enum unit_activity new_activity, int 
new_target);
+                               enum unit_activity new_activity, enum 
tile_special_type new_target);
 bool can_unit_do_auto(struct unit *punit); 
 int is_unit_activity_on_tile(enum unit_activity activity, int x, int y);
 int get_unit_tile_pillage_set(int x, int y);
diff -ur -X freeciv/diff_ignore freeciv/server/ruleset.c 
freeciv-use-enums.patch/server/ruleset.c
--- freeciv/server/ruleset.c    Wed Mar  6 12:05:17 2002
+++ freeciv-use-enums.patch/server/ruleset.c    Sun Mar 10 18:51:44 2002
@@ -66,7 +66,7 @@
                            char *entry, const char *filename);
 static char *lookup_helptext(struct section_file *file, char *prefix);
 
-static enum tile_terrain_type lookup_terrain(char *name, int tthis);
+static enum tile_terrain_type lookup_terrain(char *name, enum 
tile_terrain_type tthis);
 
 static void load_tech_names(struct section_file *file);
 static void load_unit_names(struct section_file *file);
@@ -406,9 +406,9 @@
 /**************************************************************************
   Look up a terrain name in the tile_types array and return its index.
 **************************************************************************/
-static enum tile_terrain_type lookup_terrain(char *name, int tthis)
+static enum tile_terrain_type lookup_terrain(char *name, enum 
tile_terrain_type tthis)
 {
-  int i;
+  enum tile_terrain_type i;
 
   if (*name == '\0' || (0 == strcmp(name, "none")) || (0 == strcmp(name, 
"no")))
     {
diff -ur -X freeciv/diff_ignore freeciv/server/settlers.c 
freeciv-use-enums.patch/server/settlers.c
--- freeciv/server/settlers.c   Fri Mar  8 16:28:31 2002
+++ freeciv-use-enums.patch/server/settlers.c   Sun Mar 10 18:51:44 2002
@@ -506,7 +506,7 @@
   struct tile *ptile = map_get_tile(mx, my);
   enum tile_terrain_type t = ptile->terrain;
   struct tile_type *type = get_tile_type(t);
-  int s = ptile->special;
+  enum tile_special_type s = ptile->special;
 
   if (ptile->terrain != type->irrigation_result &&
       type->irrigation_result != T_LAST) { /* EXPERIMENTAL 980905 -- Syela */
@@ -583,7 +583,7 @@
   struct tile *ptile = map_get_tile(mx, my);
   enum tile_terrain_type t = ptile->terrain;
   struct tile_type *type = get_tile_type(t);
-  int s = ptile->special;
+  enum tile_special_type s = ptile->special;
   enum tile_terrain_type r = type->transform_result;
 
   if (t == T_OCEAN && !can_reclaim_ocean(mx, my))
@@ -617,7 +617,7 @@
 Calculate the attractiveness
 "spc" will be S_ROAD or S_RAILROAD for sane calls.
 **************************************************************************/
-static int road_bonus(int x, int y, int spc)
+static int road_bonus(int x, int y, enum tile_special_type spc)
 {
   int m = 0, k;
   bool rd[12], te[12];
@@ -695,6 +695,7 @@
   if (ptile->terrain != T_OCEAN &&
       player_knows_techs_with_flag(pplayer, TF_RAILROAD) &&
       !tile_has_special(ptile, S_RAILROAD)) {
+    /* Avoid reset movement cost */
     spe_sav = ptile->special;
     ptile->special|=(S_ROAD | S_RAILROAD);
     m = city_tile_value(pcity, cx, cy, 0, 0);
@@ -825,7 +826,7 @@
 static void consider_settler_action(struct player *pplayer, enum unit_activity 
act,
                                    int extra, int newv, int oldv, bool in_use,
                                    int d, int *best_newv, int *best_oldv,
-                                   int *best_act, int *gx, int *gy, int x, int 
y)
+                                   enum unit_activity *best_act, int *gx, int 
*gy, int x, int y)
 {
   int a, b=0;
   bool consider;
@@ -1041,7 +1042,7 @@
 tile it has chosen, and bestact indicates the activity it wants to do.
 **************************************************************************/
 static int evaluate_improvements(struct unit *punit,
-                                int *best_act, int *gx, int *gy)
+                                enum unit_activity *best_act, int *gx, int *gy)
 {
   struct city *mycity = map_get_city(punit->x, punit->y);
   struct player *pplayer = unit_owner(punit);
@@ -1241,7 +1242,7 @@
 {
   int gx = -1, gy = -1;                /* x,y of target (goto) square */
   int best_newv = 0;           /* newv of best target so far, all cities */
-  int best_act = 0;            /* ACTIVITY_ of best target so far */
+  enum unit_activity best_act = ACTIVITY_IDLE; /* ACTIVITY_ of best target so 
far */
   struct unit *ferryboat = NULL; /* if non-null, boatid boat at unit's x,y */
 
 #ifdef DEBUG
@@ -1252,7 +1253,7 @@
    * results in: gx, gy, best_newv, best_act
    */  
   if (unit_flag(punit, F_SETTLERS)) {
-    best_newv = evaluate_improvements(punit, &best_act,&gx, &gy);
+    best_newv = evaluate_improvements(punit, &best_act, &gx, &gy);
   }
 
   /* Found the best square to upgrade, have gx, gy, best_newv, best_act */
@@ -1560,7 +1561,8 @@
   struct player *pplayer = city_owner(pcity);
   struct unit virtualunit;
   int want;
-  int best_act, gx, gy; /* dummies */
+  enum unit_activity best_act;
+  int gx, gy; /* dummies */
 
   memset(&virtualunit, 0, sizeof(struct unit));
   virtualunit.id = 0;
diff -ur -X freeciv/diff_ignore freeciv/server/stdinhand.c 
freeciv-use-enums.patch/server/stdinhand.c
--- freeciv/server/stdinhand.c  Fri Mar  8 17:31:40 2002
+++ freeciv-use-enums.patch/server/stdinhand.c  Sun Mar 10 18:51:44 2002
@@ -1305,9 +1305,9 @@
                        mystrncasecmp, token, &ind);
 
   if (result < M_PRE_AMBIGUOUS) {
-    return ind;
+    return (enum command_id)ind;
   } else if (result == M_PRE_AMBIGUOUS) {
-    return accept_ambiguity ? ind : CMD_AMBIGUOUS;
+    return accept_ambiguity ? (enum command_id)ind : CMD_AMBIGUOUS;
   } else {
     return CMD_UNRECOGNIZED;
   }
diff -ur -X freeciv/diff_ignore freeciv/server/unittools.c 
freeciv-use-enums.patch/server/unittools.c
--- freeciv/server/unittools.c  Thu Mar  7 07:24:34 2002
+++ freeciv-use-enums.patch/server/unittools.c  Sun Mar 10 18:51:44 2002
@@ -775,7 +775,7 @@
   int id = punit->id;
   int mr = unit_type(punit)->move_rate;
   bool unit_activity_done = FALSE;
-  int activity = punit->activity;
+  enum unit_activity activity = punit->activity;
   enum ocean_land_change solvency = OLC_NONE;
   struct tile *ptile = map_get_tile(punit->x, punit->y);
 
@@ -813,7 +813,7 @@
   if (activity==ACTIVITY_PILLAGE) {
     if (punit->activity_target == 0) {     /* case for old save files */
       if (punit->activity_count >= 1) {
-       int what =
+       enum tile_special_type what =
          get_preferred_pillage(
            get_tile_infrastructure_set(
              map_get_tile(punit->x, punit->y)));
@@ -842,7 +842,7 @@
     }
     else if (total_activity_targeted (punit->x, punit->y,
                                      ACTIVITY_PILLAGE, punit->activity_target) 
>= 1) {
-      int what_pillaged = punit->activity_target;
+      enum tile_special_type what_pillaged = punit->activity_target;
       map_clear_special(punit->x, punit->y, what_pillaged);
       unit_list_iterate (map_get_tile(punit->x, punit->y)->units, punit2)
         if ((punit2->activity == ACTIVITY_PILLAGE) &&

-- 
//Markus



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