Complete.Org: Mailing Lists: Archives: freeciv-dev: December 2004:
[Freeciv-Dev] (PR#11723) Constifying common/combat
Home

[Freeciv-Dev] (PR#11723) Constifying common/combat

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] (PR#11723) Constifying common/combat
From: "Frédéric Brière" <fbriere@xxxxxxxxxxx>
Date: Wed, 29 Dec 2004 17:02:15 -0800
Reply-to: bugs@xxxxxxxxxxx

<URL: http://bugs.freeciv.org/Ticket/Display.html?id=11723 >

This patch adds a couple of consts to common/combat.[ch].


-- 
             Frédéric Brière    <*>    fbriere@xxxxxxxxxxx

 =>  <fbriere@xxxxxxxxxx> IS NO MORE:  <http://www.abacomsucks.com>  <=

Index: common/combat.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/combat.c,v
retrieving revision 1.48
diff -u -r1.48 combat.c
--- common/combat.c     17 Nov 2004 19:21:14 -0000      1.48
+++ common/combat.c     29 Dec 2004 20:19:57 -0000
@@ -32,7 +32,8 @@
   2) the tile contains a non-enemy city or
   3) the tile contains a non-enemy unit
 ***********************************************************************/
-bool can_player_attack_tile(struct player *pplayer, const struct tile *ptile)
+bool can_player_attack_tile(const struct player *pplayer,
+                           const struct tile *ptile)
 {
   struct city *pcity = ptile->city;
   
@@ -74,7 +75,8 @@
   2) Adjacency
   3) Diplomatic status
 ***********************************************************************/
-bool can_unit_attack_unit_at_tile(struct unit *punit, struct unit *pdefender,
+bool can_unit_attack_unit_at_tile(const struct unit *punit,
+                                 const struct unit *pdefender,
                                   const struct tile *dest_tile)
 {
   Terrain_type_id fromtile = punit->tile->terrain;
@@ -115,7 +117,7 @@
 /***********************************************************************
   To attack a stack, unit must be able to attack every unit there
 ************************************************************************/
-bool can_unit_attack_all_at_tile(struct unit *punit,
+bool can_unit_attack_all_at_tile(const struct unit *punit,
                                 const struct tile *ptile)
 {
   unit_list_iterate(ptile->units, aunit) {
@@ -131,7 +133,8 @@
   Is unit (1) diplomatically allowed to attack and (2) physically able
   to do so?
 ***********************************************************************/
-bool can_unit_attack_tile(struct unit *punit, const struct tile *dest_tile)
+bool can_unit_attack_tile(const struct unit *punit,
+                         const struct tile *dest_tile)
 {
   if (!can_player_attack_tile(unit_owner(punit), dest_tile)) {
     return FALSE;
@@ -229,7 +232,8 @@
 /**************************************************************************
 A unit's effective firepower depend on the situation.
 **************************************************************************/
-void get_modified_firepower(struct unit *attacker, struct unit *defender,
+void get_modified_firepower(const struct unit *attacker,
+                           const struct unit *defender,
                            int *att_fp, int *def_fp)
 {
   *att_fp = unit_type(attacker)->firepower;
@@ -269,7 +273,8 @@
 Returns a double in the range [0;1] indicating the attackers chance of
 winning. The calculation takes all factors into account.
 **************************************************************************/
-double unit_win_chance(struct unit *attacker, struct unit *defender)
+double unit_win_chance(const struct unit *attacker,
+                      const struct unit *defender)
 {
   int def_power = get_total_defense_power(attacker, defender);
   int att_power = get_total_attack_power(attacker, defender);
@@ -288,7 +293,7 @@
 /**************************************************************************
   a wrapper that returns whether or not a unit ignores citywalls
 **************************************************************************/
-static bool unit_ignores_citywalls(struct unit *punit)
+static bool unit_ignores_citywalls(const struct unit *punit)
 {
   return (unit_flag(punit, F_IGWALL));
 }
@@ -296,7 +301,7 @@
 /**************************************************************************
   Takes into account unit move_type as well, and Walls variant.
 **************************************************************************/
-bool unit_really_ignores_citywalls(struct unit *punit)
+bool unit_really_ignores_citywalls(const struct unit *punit)
 {
   return (unit_ignores_citywalls(punit)
          || is_air_unit(punit)
@@ -306,7 +311,7 @@
 /**************************************************************************
  a wrapper function returns 1 if the unit is on a square with fortress
 **************************************************************************/
-bool unit_on_fortress(struct unit *punit)
+bool unit_on_fortress(const struct unit *punit)
 {
   return map_has_special(punit->tile, S_FORTRESS);
 }
@@ -314,7 +319,7 @@
 /**************************************************************************
   a wrapper function returns 1 if there is a sdi-defense close to the square
 **************************************************************************/
-struct city *sdi_defense_close(struct player *owner,
+struct city *sdi_defense_close(const struct player *owner,
                               const struct tile *ptile)
 {
   square_iterate(ptile, 2, ptile1) {
@@ -331,7 +336,7 @@
 /**************************************************************************
  Convenience wrapper for base_get_attack_power.
 **************************************************************************/
-int get_attack_power(struct unit *punit)
+int get_attack_power(const struct unit *punit)
 {
   return base_get_attack_power(punit->type, punit->veteran,
                               punit->moves_left);
@@ -358,7 +363,7 @@
 /**************************************************************************
   Returns the defense power, modified by veteran status.
 **************************************************************************/
-int base_get_defense_power(struct unit *punit)
+int base_get_defense_power(const struct unit *punit)
 {
   return unit_type(punit)->defense_strength * POWER_FACTOR
        * unit_type(punit)->veteran[punit->veteran].power_fact;
@@ -367,7 +372,7 @@
 /**************************************************************************
   Returns the defense power, modified by terrain and veteran status.
 **************************************************************************/
-int get_defense_power(struct unit *punit)
+int get_defense_power(const struct unit *punit)
 {
   int db, power = base_get_defense_power(punit);
 
@@ -384,7 +389,8 @@
  return the modified attack power of a unit.  Currently they aren't any
  modifications...
 ***************************************************************************/
-int get_total_attack_power(struct unit *attacker, struct unit *defender)
+int get_total_attack_power(const struct unit *attacker,
+                          const struct unit *defender)
 {
   int attackpower = get_attack_power(attacker);
 
@@ -494,7 +500,8 @@
  An veteran aegis cruiser in a mountain city with SAM and SDI defense 
  being attacked by a missile gets defense 288.
 ***************************************************************************/
-int get_total_defense_power(struct unit *attacker, struct unit *defender)
+int get_total_defense_power(const struct unit *attacker,
+                           const struct unit *defender)
 {
   return defense_multiplication(attacker->type, defender->type,
                                defender->tile,
@@ -507,7 +514,8 @@
 Unlike the one got from win chance this doesn't potentially get insanely
 small if the units are unevenly matched, unlike win_chance.
 **************************************************************************/
-static int get_defense_rating(struct unit *attacker, struct unit *defender)
+static int get_defense_rating(const struct unit *attacker,
+                             const struct unit *defender)
 {
   int afp, dfp;
 
@@ -527,7 +535,7 @@
   relationship of attacker and defender is ignored; the caller should check
   this.
 **************************************************************************/
-struct unit *get_defender(struct unit *attacker, const struct tile *ptile)
+struct unit *get_defender(const struct unit *attacker, const struct tile 
*ptile)
 {
   struct unit *bestdef = NULL;
   int bestvalue = -1, best_cost = 0, rating_of_best = 0;
@@ -594,7 +602,7 @@
 Works like get_defender; see comment there.
 This function is mostly used by the AI.
 **************************************************************************/
-struct unit *get_attacker(struct unit *defender, const struct tile *ptile)
+struct unit *get_attacker(const struct unit *defender, const struct tile 
*ptile)
 {
   struct unit *bestatt = 0;
   int bestvalue = -1, unit_a, best_cost = 0;
Index: common/combat.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/combat.h,v
retrieving revision 1.14
diff -u -r1.14 combat.h
--- common/combat.h     29 Sep 2004 02:24:22 -0000      1.14
+++ common/combat.h     29 Dec 2004 20:19:57 -0000
@@ -24,37 +24,44 @@
  */
 #define POWER_FACTOR   10
 
-bool can_player_attack_tile(struct player *pplayer,
+bool can_player_attack_tile(const struct player *pplayer,
                            const struct tile *ptile);
-bool can_unit_attack_unit_at_tile(struct unit *punit, struct unit *pdefender,
+bool can_unit_attack_unit_at_tile(const struct unit *punit,
+                                 const struct unit *pdefender,
                                  const struct tile *dest_tile);
-bool can_unit_attack_all_at_tile(struct unit *punit,
+bool can_unit_attack_all_at_tile(const struct unit *punit,
                                 const struct tile *ptile);
-bool can_unit_attack_tile(struct unit *punit, const struct tile *ptile);
+bool can_unit_attack_tile(const struct unit *punit, const struct tile *ptile);
 
 double win_chance(int as, int ahp, int afp, int ds, int dhp, int dfp);
 
-void get_modified_firepower(struct unit *attacker, struct unit *defender,
+void get_modified_firepower(const struct unit *attacker,
+                           const struct unit *defender,
                            int *att_fp, int *def_fp);
-double unit_win_chance(struct unit *attacker, struct unit *defender);
+double unit_win_chance(const struct unit *attacker,
+                      const struct unit *defender);
 
-bool unit_really_ignores_citywalls(struct unit *punit);
-bool unit_on_fortress(struct unit *punit);
-struct city *sdi_defense_close(struct player *owner,
+bool unit_really_ignores_citywalls(const struct unit *punit);
+bool unit_on_fortress(const struct unit *punit);
+struct city *sdi_defense_close(const struct player *owner,
                               const struct tile *ptile);
 
-int get_attack_power(struct unit *punit);
+int get_attack_power(const struct unit *punit);
 int base_get_attack_power(Unit_Type_id type, int veteran, int moves_left);
-int base_get_defense_power(struct unit *punit);
-int get_defense_power(struct unit *punit);
-int get_total_defense_power(struct unit *attacker, struct unit *defender);
+int base_get_defense_power(const struct unit *punit);
+int get_defense_power(const struct unit *punit);
+int get_total_defense_power(const struct unit *attacker,
+                           const struct unit *defender);
 int get_virtual_defense_power(Unit_Type_id att_type, Unit_Type_id def_type,
                              const struct tile *ptile,
                              bool fortified, int veteran);
-int get_total_attack_power(struct unit *attacker, struct unit *defender);
+int get_total_attack_power(const struct unit *attacker,
+                          const struct unit *defender);
 
-struct unit *get_defender(struct unit *attacker, const struct tile *ptile);
-struct unit *get_attacker(struct unit *defender, const struct tile *ptile);
+struct unit *get_defender(const struct unit *attacker,
+                         const struct tile *ptile);
+struct unit *get_attacker(const struct unit *defender,
+                         const struct tile *ptile);
 
 bool is_stack_vulnerable(const struct tile *ptile);
 #endif /* FC__COMBAT_H */

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#11723) Constifying common/combat, Frédéric Brière <=