Complete.Org: Mailing Lists: Archives: freeciv-dev: October 2005:
[Freeciv-Dev] (PR#14331) use effects for unit vision
Home

[Freeciv-Dev] (PR#14331) use effects for unit vision

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] (PR#14331) use effects for unit vision
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Fri, 14 Oct 2005 16:46:08 -0700
Reply-to: bugs@xxxxxxxxxxx

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

This patch changes the watchtower vision bonus for units to use effects. 
  The rulesets are updated to match.

This allows all sorts of crazy effects to modify unit vision.  Note that 
most changes will not take instant effect unless you call 
unit_vision_refresh() after the effect source is activated.

-jason

Index: server/ruleset.c
===================================================================
--- server/ruleset.c    (revision 11131)
+++ server/ruleset.c    (working copy)
@@ -1467,9 +1467,6 @@
   terrain_control.fortress_defense_bonus =
     secfile_lookup_int_default(file, 100, "parameters.fortress_defense_bonus");
 
-  terrain_control.watchtower_extra_vision_radius_sq
-    = secfile_lookup_int(file, "parameters.fortress_extra_vision_radius_sq");
-
   terrain_control.road_superhighway_trade_bonus =
     secfile_lookup_int_default(file, 50, 
"parameters.road_superhighway_trade_bonus");
   output_type_iterate(o) {
Index: server/unittools.c
===================================================================
--- server/unittools.c  (revision 11132)
+++ server/unittools.c  (working copy)
@@ -660,11 +660,8 @@
          check_adjacent_units = TRUE;
        }
 
-       /* If a watchtower has been pillaged, reduce sight to normal */
-       if (what == S_FORTRESS) {
-         freelog(LOG_VERBOSE, "Watchtower pillaged!");
-         unit_list_refresh_vision(ptile->units);
-       }
+       /* Change vision if effects have changed. */
+       unit_list_refresh_vision(ptile->units);
       }
     }
     else if (total_activity_targeted(ptile, ACTIVITY_PILLAGE, 
@@ -683,11 +680,8 @@
       
       ai_incident_pillage(unit_owner(punit), ptile->owner);
       
-      /* If a watchtower has been pillaged, reduce sight to normal */
-      if (what_pillaged == S_FORTRESS) {
-       freelog(LOG_VERBOSE, "Watchtower(2) pillaged!");
-       unit_list_refresh_vision(ptile->units);
-      }
+      /* Change vision if effects have changed. */
+      unit_list_refresh_vision(ptile->units);
     }
   }
 
@@ -712,7 +706,9 @@
        >= tile_activity_time(ACTIVITY_FORTRESS, ptile)) {
       tile_set_special(ptile, S_FORTRESS);
       unit_activity_done = TRUE;
-      /* watchtower becomes effective */
+
+      /* watchtower becomes effective
+       * FIXME: Reqs on other specials will not be updated immediately. */
       unit_list_refresh_vision(ptile->units);
     }
   }
@@ -3178,15 +3174,9 @@
 ****************************************************************************/
 int get_unit_vision_at(struct unit *punit, struct tile *ptile)
 {
-  int radius_sq = punit->type->vision_radius_sq;
-
-  if (is_ground_unit(punit)
-      && tile_has_special(ptile, S_FORTRESS)
-      && player_knows_techs_with_flag(unit_owner(punit), TF_WATCHTOWER)) {
-    radius_sq += terrain_control.watchtower_extra_vision_radius_sq;
-  }
-
-  return radius_sq;
+  return (punit->type->vision_radius_sq
+         + get_unittype_bonus(punit->owner, ptile, punit->type,
+                              EFT_UNIT_VISION_RADIUS_SQ));
 }
 
 /****************************************************************************
Index: server/techtools.c
===================================================================
--- server/techtools.c  (revision 11131)
+++ server/techtools.c  (working copy)
@@ -209,10 +209,9 @@
     upgrade_city_rails(plr, was_discovery);  
   }
   
-  /* Enhance vision of units inside a fortress */
-  if (tech_flag(tech_found, TF_WATCHTOWER)) {
-    unit_list_refresh_vision(plr->units);
-  }
+  /* Enhance vision of units if a player-ranged effect has changed.  Note
+   * that world-ranged effects will not be updated immediately. */
+  unit_list_refresh_vision(plr->units);
 
   /* Notify a player about new governments available */
   government_iterate(gov) {
Index: server/savegame.c
===================================================================
--- server/savegame.c   (revision 11131)
+++ server/savegame.c   (working copy)
@@ -184,7 +184,7 @@
    and rulesets */
 #define SAVEFILE_OPTIONS "startoptions spacerace2 rulesets" \
 " diplchance_percent map_editor known32fix turn " \
-"attributes watchtower rulesetdir client_worklists orders " \
+"attributes rulesetdir client_worklists orders " \
 "startunits turn_last_built improvement_order technology_order embassies " \
 "owner_player_map"
 
@@ -3843,12 +3843,6 @@
   secfile_insert_int(file, game.info.borders, "game.borders");
   secfile_insert_bool(file, game.info.happyborders, "game.happyborders");
   secfile_insert_int(file, game.info.diplomacy, "game.diplomacy");
-  /* watchtower_vision and watchtower_extra_vision are
-   * required by 2.0 servers. */
-  secfile_insert_int(file, 0, "game.watchtower_vision");
-  secfile_insert_int(file,
-       (int)(sqrt(terrain_control.watchtower_extra_vision_radius_sq) + 0.5),
-       "game.watchtower_extra_vision");
   secfile_insert_int(file, game.info.allowed_city_names, 
"game.allowed_city_names");
 
   /* old (1.14.1) servers need to have these server variables.  The values
Index: data/civ1/terrain.ruleset
===================================================================
--- data/civ1/terrain.ruleset   (revision 11131)
+++ data/civ1/terrain.ruleset   (working copy)
@@ -52,9 +52,6 @@
 ; percent added to defense if square has fortress
 fortress_defense_bonus=100
 
-; extra vision range given to units in a fortress
-fortress_extra_vision_radius_sq = 0
-
 ; percent added to trade production if road and city has superhighways
 road_superhighway_trade_bonus=0
 
Index: data/civ2/terrain.ruleset
===================================================================
--- data/civ2/terrain.ruleset   (revision 11131)
+++ data/civ2/terrain.ruleset   (working copy)
@@ -60,9 +60,6 @@
 ; percent added to defense if square has fortress
 fortress_defense_bonus=100
 
-; extra vision range given to units in a fortress
-fortress_extra_vision_radius_sq = 0
-
 ; percent added to trade production if road and city has superhighways
 road_superhighway_trade_bonus=50
 
Index: data/default/effects.ruleset
===================================================================
--- data/default/effects.ruleset        (revision 11131)
+++ data/default/effects.ruleset        (working copy)
@@ -56,6 +56,17 @@
     }
 
 
+; Vision benefit from fortress watchtowers
+[effect_fortress_vision]
+name    = "Unit_Vision_Radius_Sq"
+value   = 8
+reqs    =
+    { "type", "name", "range"
+      "Special", "Fortress", "tile"
+      "Tech", "Invention", "player"
+    }
+
+
 ; Base vision range - radius of vision is sqrt(5) = 2.24
 [effect_city_vision]
 name    = "City_Vision_Radius_Sq"
Index: data/default/terrain.ruleset
===================================================================
--- data/default/terrain.ruleset        (revision 11131)
+++ data/default/terrain.ruleset        (working copy)
@@ -60,9 +60,6 @@
 ; percent added to defense if square has fortress
 fortress_defense_bonus=100
 
-; extra vision range given to units in a fortress
-fortress_extra_vision_radius_sq = 8
-
 ; percent added to trade production if road and city has superhighways
 road_superhighway_trade_bonus=50
 
Index: data/default/techs.ruleset
===================================================================
--- data/default/techs.ruleset  (revision 11131)
+++ data/default/techs.ruleset  (working copy)
@@ -45,7 +45,6 @@
 ; "Railroad" = "Settler" unit types can build rail roads
 ; "Farmland" = "Settler" unit types can build farmland
 ; "Fortress" = "Settler" unit types can build fortress
-; "Watchtower" = Units get enhanced visionrange in a fortress
 ; "Population_Pollution_Inc" = Increase the pollution factor created by
 ;                              popultaion by one
 ; "Airbase" = "Airbase" unit types can build Airbases
@@ -353,7 +352,7 @@
 name     = _("Invention")
 req1     = "Engineering"
 req2     = "Literacy"
-flags    = "Watchtower"
+flags    = ""
 graphic     = "a.invention"
 graphic_alt = "-"
 
Index: data/history/effects.ruleset
===================================================================
--- data/history/effects.ruleset        (revision 11131)
+++ data/history/effects.ruleset        (working copy)
@@ -47,6 +47,17 @@
     }
 
 
+; Vision benefit from fortress watchtowers
+[effect_fortress_vision]
+name    = "Unit_Vision_Radius_Sq"
+value   = 8
+reqs    =
+    { "type", "name", "range"
+      "Special", "Fortress", "tile"
+      "Tech", "Invention", "player"
+    }
+
+
 ; Base vision range - radius of vision is sqrt(5) = 2.24
 [effect_city_vision]
 name    = "City_Vision_Radius_Sq"
Index: data/history/terrain.ruleset
===================================================================
--- data/history/terrain.ruleset        (revision 11131)
+++ data/history/terrain.ruleset        (working copy)
@@ -60,9 +60,6 @@
 ; percent added to defense if square has fortress
 fortress_defense_bonus=100
 
-; extra vision range given to units in a fortress
-fortress_extra_vision_radius_sq = 8
-
 ; percent added to trade production if road and city has superhighways
 road_superhighway_trade_bonus=50
 
Index: data/history/techs.ruleset
===================================================================
--- data/history/techs.ruleset  (revision 11131)
+++ data/history/techs.ruleset  (working copy)
@@ -266,7 +266,7 @@
 name     = _("Invention")
 req1     = "Milling"
 req2     = "Literacy"
-flags    = "Watchtower"
+flags    = ""
 
 [advance_iron_working]
 name     = _("Iron Working")
Index: common/tech.c
===================================================================
--- common/tech.c       (revision 11131)
+++ common/tech.c       (working copy)
@@ -41,7 +41,7 @@
 
 static const char *flag_names[] = {
   "Bonus_Tech", "Bridge", "Railroad", "Fortress",
-  "Watchtower", "Population_Pollution_Inc", 
+  "Population_Pollution_Inc", 
   "Airbase", "Farmland", "Reduce_Trireme_Loss1", "Reduce_Trireme_Loss2", 
   "Build_Airborne"
 };
Index: common/tech.h
===================================================================
--- common/tech.h       (revision 11131)
+++ common/tech.h       (working copy)
@@ -56,7 +56,6 @@
   TF_BRIDGE,    /* "Settler" unit types can build bridges over rivers */
   TF_RAILROAD,  /* "Settler" unit types can build rail roads */
   TF_FORTRESS,  /* "Settler" unit types can build fortress */
-  TF_WATCHTOWER, /* Units get enhanced visionrange in a fortress (=fortress 
acts also as a watchtower) */
   TF_POPULATION_POLLUTION_INC,  /* Increase the pollution factor created by 
popultaion by one */
   TF_AIRBASE,   /* "Airbase" unit types can build Airbases */
   TF_FARMLAND,  /* "Settler" unit types can build farmland */
Index: common/packets.def
===================================================================
--- common/packets.def  (revision 11131)
+++ common/packets.def  (working copy)
@@ -1157,8 +1157,6 @@
   UINT16 rail_tile_bonus[O_MAX];        /* % added to output if railroad */
   UINT8 pollution_tile_penalty[O_MAX]; /* % taken from output if polluted */
   UINT8 fallout_tile_penalty[O_MAX]; /* % taken from output if polluted */
-
-  UINT16 watchtower_extra_vision_radius_sq;
 end
 
 PACKET_RULESET_NATION=102;sc,lsend
Index: common/effects.c
===================================================================
--- common/effects.c    (revision 11131)
+++ common/effects.c    (working copy)
@@ -96,6 +96,7 @@
   "Sea_Regen",
   "Air_Regen",
   "City_Vision_Radius_Sq",
+  "Unit_Vision_Radius_Sq",
   "Land_Defend",
   "Sea_Defend",
   "Air_Defend",
@@ -830,6 +831,25 @@
 }
 
 /**************************************************************************
+  Returns the effect bonus that applies at a tile for a given unittype.
+
+  For instance with EFT_DEFEND_BONUS the attacker's unittype and the
+  defending tile should be passed in.  Slightly counter-intuitive!
+  See doc/README.effects to see how the unittype applies for each effect
+  here.
+**************************************************************************/
+int get_unittype_bonus(const struct player *pplayer,
+                      const struct tile *ptile,
+                      const struct unit_type *punittype,
+                      enum effect_type effect_type)
+{
+  assert(pplayer != NULL && ptile != NULL && punittype != NULL);
+  return get_target_bonus_effects(NULL,
+                                 pplayer, ptile->city, NULL, ptile,
+                                 punittype, NULL, NULL, effect_type);
+}
+
+/**************************************************************************
   Returns the effect bonus at a building.
 **************************************************************************/
 int get_unit_bonus(const struct unit *punit, enum effect_type effect_type)
Index: common/packets_gen.c
===================================================================
--- common/packets_gen.c        (revision 11131)
+++ common/packets_gen.c        (working copy)
@@ -23914,7 +23914,7 @@
 
 #define cmp_packet_ruleset_terrain_control_100 cmp_const
 
-BV_DEFINE(packet_ruleset_terrain_control_100_fields, 16);
+BV_DEFINE(packet_ruleset_terrain_control_100_fields, 15);
 
 static struct packet_ruleset_terrain_control 
*receive_packet_ruleset_terrain_control_100(struct connection *pc, enum 
packet_type type)
 {
@@ -24046,14 +24046,6 @@
       }
     }
   }
-  if (BV_ISSET(fields, 15)) {
-    {
-      int readin;
-    
-      dio_get_uint16(&din, &readin);
-      real_packet->watchtower_extra_vision_radius_sq = readin;
-    }
-  }
 
   clone = fc_malloc(sizeof(*clone));
   *clone = *real_packet;
@@ -24184,10 +24176,6 @@
   if(differ) {different++;}
   if(differ) {BV_SET(fields, 14);}
 
-  differ = (old->watchtower_extra_vision_radius_sq != 
real_packet->watchtower_extra_vision_radius_sq);
-  if(differ) {different++;}
-  if(differ) {BV_SET(fields, 15);}
-
   if (different == 0 && !force_send_of_unchanged) {
     return 0;
   }
@@ -24252,9 +24240,6 @@
       }
     } 
   }
-  if (BV_ISSET(fields, 15)) {
-    dio_put_uint16(&dout, real_packet->watchtower_extra_vision_radius_sq);
-  }
 
 
   if (old_from_hash) {
Index: common/effects.h
===================================================================
--- common/effects.h    (revision 11131)
+++ common/effects.h    (working copy)
@@ -84,6 +84,7 @@
   EFT_SEA_REGEN,
   EFT_AIR_REGEN,
   EFT_CITY_VISION_RADIUS_SQ,
+  EFT_UNIT_VISION_RADIUS_SQ,
   EFT_LAND_DEFEND,
   EFT_SEA_DEFEND,
   EFT_AIR_DEFEND,
@@ -183,6 +184,10 @@
                               enum effect_type effect_type);
 int get_building_bonus(const struct city *pcity, Impr_type_id building,
                       enum effect_type effect_type);
+int get_unittype_bonus(const struct player *pplayer,
+                      const struct tile *ptile, /* pcity is implied */
+                      const struct unit_type *punittype,
+                      enum effect_type effect_type);
 int get_unit_bonus(const struct unit *punit, enum effect_type effect_type);
 
 /* miscellaneous auxiliary effects functions */
Index: common/packets_gen.h
===================================================================
--- common/packets_gen.h        (revision 11131)
+++ common/packets_gen.h        (working copy)
@@ -870,7 +870,6 @@
   int rail_tile_bonus[O_MAX];
   int pollution_tile_penalty[O_MAX];
   int fallout_tile_penalty[O_MAX];
-  int watchtower_extra_vision_radius_sq;
 };
 
 struct packet_ruleset_nation {
Index: ai/aicity.c
===================================================================
--- ai/aicity.c (revision 11131)
+++ ai/aicity.c (working copy)
@@ -348,6 +348,7 @@
          break;
 
       case EFT_CITY_VISION_RADIUS_SQ:
+      case EFT_UNIT_VISION_RADIUS_SQ:
        /* Wild guess.  "Amount" is the number of tiles (on average) that
         * will be revealed by the effect.  Note that with an omniscient
         * AI this effect is actually not useful at all. */

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#14331) use effects for unit vision, Jason Short <=