Complete.Org: Mailing Lists: Archives: freeciv-dev: December 2004:
[Freeciv-Dev] (PR#11353) make some player functions const
Home

[Freeciv-Dev] (PR#11353) make some player functions const

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] (PR#11353) make some player functions const
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Sun, 5 Dec 2004 11:39:46 -0800
Reply-to: rt@xxxxxxxxxxx

<URL: http://rt.freeciv.org/Ticket/Display.html?id=11353 >

This transaction appears to have no content
Index: client/climisc.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/climisc.c,v
retrieving revision 1.143
diff -u -r1.143 climisc.c
--- client/climisc.c    20 Oct 2004 04:34:27 -0000      1.143
+++ client/climisc.c    5 Dec 2004 19:38:37 -0000
@@ -959,7 +959,7 @@
 ...
 *************************************************************************/
 enum known_type map_get_known(const struct tile *ptile,
-                             struct player *pplayer)
+                             const struct player *pplayer)
 {
   assert(pplayer == game.player_ptr);
   return tile_get_known(ptile);
Index: common/map.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/map.h,v
retrieving revision 1.229
diff -u -r1.229 map.h
--- common/map.h        30 Nov 2004 05:39:12 -0000      1.229
+++ common/map.h        5 Dec 2004 19:38:37 -0000
@@ -350,7 +350,7 @@
 
 /* implemented in server/maphand.c and client/climisc.c */
 enum known_type map_get_known(const struct tile *ptile,
-                             struct player *pplayer);
+                             const struct player *pplayer);
 
 /* special testing */
 bool map_has_special(const struct tile *ptile,
Index: common/player.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/player.c,v
retrieving revision 1.161
diff -u -r1.161 player.c
--- common/player.c     30 Nov 2004 08:37:03 -0000      1.161
+++ common/player.c     5 Dec 2004 19:38:38 -0000
@@ -42,7 +42,7 @@
   triad, in which p1 is allied to p2 is allied to p3 is at
   war with p1. These lead to strange situations.
 ***************************************************************/
-bool pplayer_can_ally(struct player *p1, struct player *p2)
+bool pplayer_can_ally(const struct player *p1, const struct player *p2)
 {
   players_iterate(pplayer) {
     enum diplstate_type ds = pplayer_get_diplstate(p1, pplayer)->type;
@@ -73,7 +73,7 @@
 /****************************************************************
 ...
 *****************************************************************/
-bool player_owns_city(struct player *pplayer, struct city *pcity)
+bool player_owns_city(const struct player *pplayer, const struct city *pcity)
 {
   if (!pcity || !pplayer)
     return FALSE;                      /* better safe than sorry */
@@ -227,8 +227,9 @@
   (d) the unit isn't in a transporter, or we are allied AND
   (e) the unit isn't in a transporter, or we can see the transporter
 ****************************************************************************/
-bool can_player_see_unit_at(struct player *pplayer, struct unit *punit,
-                           struct tile *ptile)
+bool can_player_see_unit_at(const struct player *pplayer,
+                           const struct unit *punit,
+                           const struct tile *ptile)
 {
   struct city *pcity;
 
@@ -280,7 +281,8 @@
 
   See can_player_see_unit_at.
 ****************************************************************************/
-bool can_player_see_unit(struct player *pplayer, struct unit *punit)
+bool can_player_see_unit(const struct player *pplayer,
+                        const struct unit *punit)
 {
   return can_player_see_unit_at(pplayer, punit, punit->tile);
 }
@@ -304,8 +306,8 @@
   Otherwise the player would not know anything about the city's units at
   all, since the full city packet has no "occupied" flag.
 ****************************************************************************/
-bool can_player_see_units_in_city(struct player *pplayer,
-                                 struct city *pcity)
+bool can_player_see_units_in_city(const struct player *pplayer,
+                                 const struct city *pcity)
 {
   return (can_player_see_city_internals(pplayer, pcity)
          || pplayers_allied(pplayer, city_owner(pcity)));
@@ -316,8 +318,8 @@
   full city packet is sent to the client, who should then be able to popup
   a dialog for it.
 ****************************************************************************/
-bool can_player_see_city_internals(struct player *pplayer,
-                                  struct city *pcity)
+bool can_player_see_city_internals(const struct player *pplayer,
+                                  const struct city *pcity)
 {
   return (pplayer == city_owner(pcity));
 }
@@ -359,7 +361,8 @@
 /*************************************************************************
 Return 1 if x,y is inside any of the player's city radii.
 **************************************************************************/
-bool player_in_city_radius(struct player *pplayer, struct tile *ptile)
+bool player_in_city_radius(const struct player *pplayer,
+                          const struct tile *ptile)
 {
   struct city *pcity;
   map_city_radius_iterate(ptile, ptile1) {
@@ -375,7 +378,8 @@
  flag. Needs to be optimized later (e.g. int tech_flags[TF_LAST] in
  struct player)
 **************************************************************************/
-int num_known_tech_with_flag(struct player *pplayer, enum tech_flag_id flag)
+int num_known_tech_with_flag(const struct player *pplayer,
+                            enum tech_flag_id flag)
 {
   return pplayer->research.num_known_tech_with_flag[flag];
 }
@@ -387,7 +391,7 @@
   This function depends on pcity->tax_total being set for all cities, so
   make sure the player's cities have been refreshed.
 **************************************************************************/
-int player_get_expected_income(struct player *pplayer)
+int player_get_expected_income(const struct player *pplayer)
 {
   int income = 0;
 
@@ -409,8 +413,8 @@
  Returns TRUE iff the player knows at least one tech which has the
  given flag.
 **************************************************************************/
-bool player_knows_techs_with_flag(struct player *pplayer,
-                                enum tech_flag_id flag)
+bool player_knows_techs_with_flag(const struct player *pplayer,
+                                 enum tech_flag_id flag)
 {
   return num_known_tech_with_flag(pplayer, flag) > 0;
 }
@@ -466,7 +470,7 @@
 /**************************************************************************
 Locate the city where the players palace is located, (NULL Otherwise) 
 **************************************************************************/
-struct city *find_palace(struct player *pplayer)
+struct city *find_palace(const struct player *pplayer)
 {
   city_list_iterate(pplayer->cities, pcity) {
     if (is_capital(pcity)) {
@@ -479,7 +483,7 @@
 /**************************************************************************
 ...
 **************************************************************************/
-bool player_knows_improvement_tech(struct player *pplayer,
+bool player_knows_improvement_tech(const struct player *pplayer,
                                   Impr_Type_id id)
 {
   int t;
@@ -491,7 +495,7 @@
 /**************************************************************************
 ...
 **************************************************************************/
-bool ai_handicap(struct player *pplayer, enum handicap_type htype)
+bool ai_handicap(const struct player *pplayer, enum handicap_type htype)
 {
   if (!pplayer->ai.control) {
     return TRUE;
@@ -515,7 +519,7 @@
     if (condition && 1) { action }
 --dwp
 **************************************************************************/
-bool ai_fuzzy(struct player *pplayer, bool normal_decision)
+bool ai_fuzzy(const struct player *pplayer, bool normal_decision)
 {
   if (!pplayer->ai.control || pplayer->ai.fuzzy == 0) return normal_decision;
   if (myrand(1000) >= pplayer->ai.fuzzy) return normal_decision;
@@ -700,7 +704,7 @@
 /**************************************************************************
   Return TRUE iff the player me gives shared vision to player them.
 **************************************************************************/
-bool gives_shared_vision(struct player *me, struct player *them)
+bool gives_shared_vision(const struct player *me, const struct player *them)
 {
   return TEST_BIT(me->gives_shared_vision, them->player_no);
 }
@@ -720,7 +724,8 @@
   from the point of view of pplayer.  Units that cannot be seen by pplayer
   will not be found (this function doesn't cheat).
 ***************************************************************************/
-int player_in_territory(struct player *pplayer, struct player *pplayer2)
+int player_in_territory(const struct player *pplayer,
+                       const struct player *pplayer2)
 {
   int in_territory = 0;
 
Index: common/player.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/player.h,v
retrieving revision 1.133
diff -u -r1.133 player.h
--- common/player.h     30 Nov 2004 00:36:08 -0000      1.133
+++ common/player.h     5 Dec 2004 19:38:38 -0000
@@ -233,36 +233,41 @@
 bool player_has_embassy(const struct player *pplayer,
                        const struct player *pplayer2);
 
-bool can_player_see_unit(struct player *pplayer, struct unit *punit);
-bool can_player_see_unit_at(struct player *pplayer, struct unit *punit,
-                           struct tile *ptile);
-
-bool can_player_see_units_in_city(struct player *pplayer,
-                                 struct city *pcity);
-bool can_player_see_city_internals(struct player *pplayer,
-                                  struct city *pcity);
+bool can_player_see_unit(const struct player *pplayer,
+                        const struct unit *punit);
+bool can_player_see_unit_at(const struct player *pplayer,
+                           const struct unit *punit,
+                           const struct tile *ptile);
+
+bool can_player_see_units_in_city(const struct player *pplayer,
+                                 const struct city *pcity);
+bool can_player_see_city_internals(const struct player *pplayer,
+                                  const struct city *pcity);
 
-bool player_owns_city(struct player *pplayer, struct city *pcity);
+bool player_owns_city(const struct player *pplayer,
+                     const struct city *pcity);
 
 struct city *player_find_city_by_id(const struct player *pplayer,
                                    int city_id);
 struct unit *player_find_unit_by_id(const struct player *pplayer,
                                    int unit_id);
 
-bool player_in_city_radius(struct player *pplayer, struct tile *ptile);
-bool player_knows_improvement_tech(struct player *pplayer,
+bool player_in_city_radius(const struct player *pplayer,
+                          const struct tile *ptile);
+bool player_knows_improvement_tech(const struct player *pplayer,
                                   Impr_Type_id id);
-bool player_knows_techs_with_flag(struct player *pplayer,
-                                enum tech_flag_id flag);
-int num_known_tech_with_flag(struct player *pplayer, enum tech_flag_id flag);
-int player_get_expected_income(struct player *pplayer);
+bool player_knows_techs_with_flag(const struct player *pplayer,
+                                 enum tech_flag_id flag);
+int num_known_tech_with_flag(const struct player *pplayer,
+                            enum tech_flag_id flag);
+int player_get_expected_income(const struct player *pplayer);
 
 void player_limit_to_government_rates(struct player *pplayer);
 
-struct city *find_palace(struct player *pplayer);
+struct city *find_palace(const struct player *pplayer);
 
-bool ai_handicap(struct player *pplayer, enum handicap_type htype);
-bool ai_fuzzy(struct player *pplayer, bool normal_decision);
+bool ai_handicap(const struct player *pplayer, enum handicap_type htype);
+bool ai_fuzzy(const struct player *pplayer, bool normal_decision);
 
 const char *reputation_text(const int rep);
 const char *diplstate_text(const enum diplstate_type type);
@@ -274,7 +279,7 @@
                                                     *pplayer2);
 bool are_diplstates_equal(const struct player_diplstate *pds1,
                          const struct player_diplstate *pds2);
-bool pplayer_can_ally(struct player *p1, struct player *p2);
+bool pplayer_can_ally(const struct player *p1, const struct player *p2);
 bool pplayers_at_war(const struct player *pplayer,
                    const struct player *pplayer2);
 bool pplayers_allied(const struct player *pplayer,
@@ -285,11 +290,12 @@
                        const struct player *pplayer2);
 bool players_on_same_team(const struct player *pplayer1,
                           const struct player *pplayer2);
-int player_in_territory(struct player *pplayer, struct player *pplayer2);
+int player_in_territory(const struct player *pplayer,
+                       const struct player *pplayer2);
 
 bool is_barbarian(const struct player *pplayer);
 
-bool gives_shared_vision(struct player *me, struct player *them);
+bool gives_shared_vision(const struct player *me, const struct player *them);
 
 #define players_iterate(PI_player)                                            \
 {                                                                             \
Index: common/unit.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/unit.c,v
retrieving revision 1.221
diff -u -r1.221 unit.c
--- common/unit.c       25 Nov 2004 06:37:30 -0000      1.221
+++ common/unit.c       5 Dec 2004 19:38:38 -0000
@@ -418,7 +418,7 @@
   it has the F_PARTIAL_INVIS flag or if it transported by a unit with
   this flag.
 **************************************************************************/
-bool is_hiding_unit(struct unit *punit)
+bool is_hiding_unit(const struct unit *punit)
 {
   struct unit *transporter = find_unit_by_id(punit->transported_by);
 
@@ -1189,7 +1189,7 @@
 /**************************************************************************
 ...
 **************************************************************************/
-struct player *unit_owner(struct unit *punit)
+struct player *unit_owner(const struct unit *punit)
 {
   return (&game.players[punit->owner]);
 }
Index: common/unit.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/unit.h,v
retrieving revision 1.129
diff -u -r1.129 unit.h
--- common/unit.h       20 Oct 2004 18:20:53 -0000      1.129
+++ common/unit.h       5 Dec 2004 19:38:38 -0000
@@ -263,7 +263,7 @@
 bool is_diplomat_unit(struct unit *punit);
 bool is_square_threatened(struct player *pplayer, const struct tile *ptile);
 bool is_field_unit(struct unit *punit);              /* ships+aero */
-bool is_hiding_unit(struct unit *punit);
+bool is_hiding_unit(const struct unit *punit);
 bool is_sailing_unit(struct unit *punit);
 bool is_air_unit(struct unit *punit);
 bool is_heli_unit(struct unit *punit);
@@ -289,7 +289,7 @@
                             struct player *pplayer,
                             bool count_units_with_extra_fuel);
 
-struct player *unit_owner(struct unit *punit);
+struct player *unit_owner(const struct unit *punit);
 
 struct unit *is_allied_unit_tile(const struct tile *ptile,
                                 struct player *pplayer);
Index: common/unittype.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/unittype.c,v
retrieving revision 1.43
diff -u -r1.43 unittype.c
--- common/unittype.c   5 Dec 2004 09:08:19 -0000       1.43
+++ common/unittype.c   5 Dec 2004 19:38:38 -0000
@@ -163,7 +163,7 @@
 /**************************************************************************
 ...
 **************************************************************************/
-bool unit_flag(struct unit *punit, enum unit_flag_id flag)
+bool unit_flag(const struct unit *punit, enum unit_flag_id flag)
 {
   return unit_type_flag(punit->type, flag);
 }
Index: common/unittype.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/unittype.h,v
retrieving revision 1.35
diff -u -r1.35 unittype.h
--- common/unittype.h   5 Dec 2004 09:08:19 -0000       1.35
+++ common/unittype.h   5 Dec 2004 19:38:38 -0000
@@ -226,7 +226,7 @@
 struct unit_type *unit_type(struct unit *punit);
 
 bool unit_type_flag(Unit_Type_id id, int flag);
-bool unit_flag(struct unit *punit, enum unit_flag_id flag);
+bool unit_flag(const struct unit *punit, enum unit_flag_id flag);
 bool unit_has_role(Unit_Type_id id, int role);
 
 bool is_water_unit(Unit_Type_id id);
Index: server/maphand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/maphand.c,v
retrieving revision 1.151
diff -u -r1.151 maphand.c
--- server/maphand.c    22 Nov 2004 19:14:42 -0000      1.151
+++ server/maphand.c    5 Dec 2004 19:38:38 -0000
@@ -184,7 +184,8 @@
 static void send_tile_info_always(struct player *pplayer,
                                  struct conn_list *dest, struct tile *ptile);
 static void shared_vision_change_seen(struct tile *ptile, struct player 
*pplayer, int change);
-static int map_get_seen(const struct tile *ptile, struct player *pplayer);
+static int map_get_seen(const struct tile *ptile,
+                       const struct player *pplayer);
 static void map_change_own_seen(struct tile *ptile, struct player *pplayer,
                                int change);
 
@@ -910,7 +911,7 @@
 /***************************************************************
 ...
 ***************************************************************/
-bool map_is_known(const struct tile *ptile, struct player *pplayer)
+bool map_is_known(const struct tile *ptile, const struct player *pplayer)
 {
   return TEST_BIT(ptile->known, pplayer->player_no);
 }
@@ -927,7 +928,8 @@
 /***************************************************************
 Watch out - this can be true even if the tile is not known.
 ***************************************************************/
-static int map_get_seen(const struct tile *ptile, struct player *pplayer)
+static int map_get_seen(const struct tile *ptile,
+                       const struct player *pplayer)
 {
   return map_get_player_tile(ptile, pplayer)->seen;
 }
@@ -1075,7 +1077,7 @@
 ...
 ***************************************************************/
 struct player_tile *map_get_player_tile(const struct tile *ptile,
-                                       struct player *pplayer)
+                                       const struct player *pplayer)
 {
   return pplayer->private_map + ptile->index;
 }
@@ -1359,7 +1361,7 @@
 ...
 *************************************************************************/
 enum known_type map_get_known(const struct tile *ptile,
-                             struct player *pplayer)
+                             const struct player *pplayer)
 {
   if (map_is_known(ptile, pplayer)) {
     if (map_get_seen(ptile, pplayer) > 0) {
Index: server/maphand.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/maphand.h,v
retrieving revision 1.50
diff -u -r1.50 maphand.h
--- server/maphand.h    11 Nov 2004 16:50:54 -0000      1.50
+++ server/maphand.h    5 Dec 2004 19:38:38 -0000
@@ -76,7 +76,7 @@
 
 bool map_is_known_and_seen(const struct tile *ptile, struct player *pplayer);
 void map_change_seen(struct tile *ptile, struct player *pplayer, int change);
-bool map_is_known(const struct tile *ptile, struct player *pplayer);
+bool map_is_known(const struct tile *ptile, const struct player *pplayer);
 void map_set_known(struct tile *ptile, struct player *pplayer);
 void map_clear_known(struct tile *ptile, struct player *pplayer);
 void map_know_all(struct player *pplayer);
@@ -86,7 +86,7 @@
 void player_map_allocate(struct player *pplayer);
 void player_map_free(struct player *pplayer);
 struct player_tile *map_get_player_tile(const struct tile *ptile,
-                                       struct player *pplayer);
+                                       const struct player *pplayer);
 bool update_player_tile_knowledge(struct player *pplayer,struct tile *ptile);
 void update_tile_knowledge(struct tile *ptile);
 void update_player_tile_last_seen(struct player *pplayer, struct tile *ptile);

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