Complete.Org: Mailing Lists: Archives: freeciv-dev: July 2004:
[Freeciv-Dev] (PR#9399) make tech functions const
Home

[Freeciv-Dev] (PR#9399) make tech functions const

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients: ;
Subject: [Freeciv-Dev] (PR#9399) make tech functions const
From: "Jason Dorje Short" <jdorje@xxxxxxxxxxx>
Date: Thu, 15 Jul 2004 20:46:35 -0700
Reply-to: rt@xxxxxxxxxxx

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

This patch makes the query functions in tech.h const.  It is in the 
spirit of Per's city-const patch, although probably it causes more harm 
(wasted time) than good (saved time).

jason

? diff
Index: common/player.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/player.c,v
retrieving revision 1.141
diff -u -r1.141 player.c
--- common/player.c     13 Jul 2004 21:54:17 -0000      1.141
+++ common/player.c     16 Jul 2004 03:45:26 -0000
@@ -61,7 +61,8 @@
   Check if pplayer has an embassy with pplayer2. We always have
   an embassy with ourselves.
 ***************************************************************/
-bool player_has_embassy(struct player *pplayer, struct player *pplayer2)
+bool player_has_embassy(const struct player *pplayer,
+                       const struct player *pplayer2)
 {
   return (TEST_BIT(pplayer->embassy, pplayer2->player_no)
           || (pplayer == pplayer2)
@@ -324,7 +325,8 @@
  return pointer to the city struct.  Else return NULL.
  Now always uses fast idex_lookup_city.
 ***************************************************************/
-struct city *player_find_city_by_id(struct player *pplayer, int city_id)
+struct city *player_find_city_by_id(const struct player *pplayer,
+                                   int city_id)
 {
   struct city *pcity = idex_lookup_city(city_id);
   
@@ -369,8 +371,8 @@
  Return 1 if one of the player's cities has the specified wonder,
  and it is not obsolete.
 **************************************************************************/
-bool player_owns_active_wonder(struct player *pplayer,
-                             Impr_Type_id id)
+bool player_owns_active_wonder(const struct player *pplayer,
+                              Impr_Type_id id)
 {
   return (improvement_exists(id)
          && is_wonder(id)
Index: common/player.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/player.h,v
retrieving revision 1.115
diff -u -r1.115 player.h
--- common/player.h     23 Apr 2004 22:58:06 -0000      1.115
+++ common/player.h     16 Jul 2004 03:45:26 -0000
@@ -225,7 +225,8 @@
                                          enum m_pre_result *result);
 struct player *find_player_by_user(const char *name);
 void player_set_unit_focus_status(struct player *pplayer);
-bool player_has_embassy(struct player *pplayer, struct player *pplayer2);
+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,
@@ -238,12 +239,13 @@
 
 bool player_owns_city(struct player *pplayer, struct city *pcity);
 
-struct city *player_find_city_by_id(struct player *pplayer, int city_id);
+struct city *player_find_city_by_id(const struct player *pplayer,
+                                   int city_id);
 struct unit *player_find_unit_by_id(struct player *pplayer, int unit_id);
 
 bool player_in_city_radius(struct player *pplayer, int x, int y);
-bool player_owns_active_wonder(struct player *pplayer,
-                             Impr_Type_id id);
+bool player_owns_active_wonder(const struct player *pplayer,
+                              Impr_Type_id id);
 bool player_owns_active_govchange_wonder(struct player *pplayer);
 bool player_knows_improvement_tech(struct player *pplayer,
                                   Impr_Type_id id);
Index: common/tech.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/tech.c,v
retrieving revision 1.72
diff -u -r1.72 tech.c
--- common/tech.c       12 Jul 2004 17:22:03 -0000      1.72
+++ common/tech.c       16 Jul 2004 03:45:26 -0000
@@ -46,7 +46,8 @@
 /**************************************************************************
 ...
 **************************************************************************/
-enum tech_state get_invention(struct player *pplayer, Tech_Type_id tech)
+enum tech_state get_invention(const struct player *pplayer,
+                             Tech_Type_id tech)
 {
   assert(tech >= 0 || tech < game.num_tech_types);
 
@@ -75,7 +76,7 @@
   Returns if the given tech has to be researched to reach the
   goal. The goal itself isn't a requirement of itself.
 **************************************************************************/
-bool is_tech_a_req_for_goal(struct player *pplayer, Tech_Type_id tech,
+bool is_tech_a_req_for_goal(const struct player *pplayer, Tech_Type_id tech,
                            Tech_Type_id goal)
 {
   if (tech == goal) {
@@ -165,7 +166,7 @@
   Returns TRUE iff the given tech is ever reachable by the given player
   by checking tech tree limitations.
 **************************************************************************/
-bool tech_is_available(struct player *pplayer, Tech_Type_id id)
+bool tech_is_available(const struct player *pplayer, Tech_Type_id id)
 {
   if (!tech_exists(id)) {
     return FALSE;
@@ -223,7 +224,7 @@
 /**************************************************************************
 ...don't use this function directly, call get_next_tech instead.
 **************************************************************************/
-static Tech_Type_id get_next_tech_rec(struct player *pplayer,
+static Tech_Type_id get_next_tech_rec(const struct player *pplayer,
                                      Tech_Type_id goal)
 {
   Tech_Type_id sub_goal;
@@ -249,7 +250,7 @@
     if return value > A_LAST then we have a bug
     caller should do something in that case.
 **************************************************************************/
-Tech_Type_id get_next_tech(struct player *pplayer, Tech_Type_id goal)
+Tech_Type_id get_next_tech(const struct player *pplayer, Tech_Type_id goal)
 {
   if (!tech_is_available(pplayer, goal)
       || get_invention(pplayer, goal) == TECH_KNOWN) {
@@ -336,7 +337,7 @@
   "total_bulbs_required(pplayer) - pplayer->research.bulbs_researched"
   if you want this.
 **************************************************************************/
-int total_bulbs_required(struct player *pplayer)
+int total_bulbs_required(const struct player *pplayer)
 {
   return base_total_bulbs_required(pplayer, pplayer->research.researching);
 }
@@ -362,7 +363,8 @@
  3 - Technology cost is reduced depending on the number of normal
      players (human and AI) which already know the tech.
 **************************************************************************/
-int base_total_bulbs_required(struct player *pplayer, Tech_Type_id tech)
+int base_total_bulbs_required(const struct player *pplayer,
+                             Tech_Type_id tech)
 {
   int cost, tech_cost_style = game.rgame.tech_cost_style;
 
@@ -486,7 +488,8 @@
  the goal technology. This includes the goal technology. Technologies
  are only counted once.
 **************************************************************************/
-int num_unknown_techs_for_goal(struct player *pplayer, Tech_Type_id goal)
+int num_unknown_techs_for_goal(const struct player *pplayer,
+                              Tech_Type_id goal)
 {
   return pplayer->research.inventions[goal].num_required_techs;
 }
@@ -496,7 +499,7 @@
  technology. These costs _include_ the cost for researching the goal
  technology itself.
 **************************************************************************/
-int total_bulbs_required_for_goal(struct player *pplayer,
+int total_bulbs_required_for_goal(const struct player *pplayer,
                                  Tech_Type_id goal)
 {
   return pplayer->research.inventions[goal].bulbs_required;
@@ -544,7 +547,7 @@
  Return the name of the given tech. You don't have to free the return
  pointer.
 **************************************************************************/
-const char *get_tech_name(struct player *pplayer, Tech_Type_id tech)
+const char *get_tech_name(const struct player *pplayer, Tech_Type_id tech)
 {
   static char buffer[200];
 
Index: common/tech.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/tech.h,v
retrieving revision 1.43
diff -u -r1.43 tech.h
--- common/tech.h       31 Jan 2004 17:52:41 -0000      1.43
+++ common/tech.h       16 Jul 2004 03:45:26 -0000
@@ -107,13 +107,14 @@
 
 BV_DEFINE(tech_vector, A_LAST);
 
-enum tech_state get_invention(struct player *pplayer, Tech_Type_id tech);
+enum tech_state get_invention(const struct player *pplayer,
+                             Tech_Type_id tech);
 void set_invention(struct player *pplayer, Tech_Type_id tech,
                   enum tech_state value);
 void update_research(struct player *pplayer);
-Tech_Type_id get_next_tech(struct player *pplayer, Tech_Type_id goal);
+Tech_Type_id get_next_tech(const struct player *pplayer, Tech_Type_id goal);
 
-bool tech_is_available(struct player *pplayer, Tech_Type_id id);
+bool tech_is_available(const struct player *pplayer, Tech_Type_id id);
 bool tech_exists(Tech_Type_id id);
 Tech_Type_id find_tech_by_name(const char *s);
 
@@ -121,16 +122,19 @@
 enum tech_flag_id tech_flag_from_str(const char *s);
 Tech_Type_id find_tech_by_flag(int index, enum tech_flag_id flag);
 
-int total_bulbs_required(struct player *pplayer);
-int base_total_bulbs_required(struct player *pplayer,Tech_Type_id tech);
+int total_bulbs_required(const struct player *pplayer);
+int base_total_bulbs_required(const struct player *pplayer,
+                             Tech_Type_id tech);
 bool techs_have_fixed_costs(void);
 
-int num_unknown_techs_for_goal(struct player *pplayer, Tech_Type_id goal);
-int total_bulbs_required_for_goal(struct player *pplayer, Tech_Type_id goal);
-bool is_tech_a_req_for_goal(struct player *pplayer, Tech_Type_id tech,
-                          Tech_Type_id goal);
+int num_unknown_techs_for_goal(const struct player *pplayer,
+                              Tech_Type_id goal);
+int total_bulbs_required_for_goal(const struct player *pplayer,
+                                 Tech_Type_id goal);
+bool is_tech_a_req_for_goal(const struct player *pplayer, Tech_Type_id tech,
+                           Tech_Type_id goal);
 bool is_future_tech(Tech_Type_id tech);
-const char *get_tech_name(struct player *pplayer, Tech_Type_id tech);
+const char *get_tech_name(const struct player *pplayer, Tech_Type_id tech);
 
 void precalc_tech_data(void);
 

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#9399) make tech functions const, Jason Dorje Short <=