[Freeciv-Dev] Re: another vision range patch (PR#4674)
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Gregory Berkolaiko wrote:
> After a quick glance at get_unit_vision_range:
>
> 1. The function is wrong, you must check for the S_FORTRESS at the
> location.
Ugh. Fixed.
> 2. It is at the server, which means the human auto-explorer will be
> cheating: knowing where the watchtowers are in the unknown.
Ugh. This is hard to deal with, so I've just ignored it and reverted
the AI changes.
jason
Index: server/citytools.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/citytools.c,v
retrieving revision 1.226
diff -u -r1.226 citytools.c
--- server/citytools.c 2003/07/24 17:41:05 1.226
+++ server/citytools.c 2003/07/29 16:10:19
@@ -1018,17 +1018,20 @@
city_refresh(pcity);
- /* Put vision back to normal, if fortress acted as a watchtower */
- if (player_knows_techs_with_flag(pplayer, TF_WATCHTOWER)
- && map_has_special(x, y, S_FORTRESS)) {
+ /* Remove fortress & watchtower vision. */
+ if (map_has_special(x, y, S_FORTRESS)) {
unit_list_iterate(map_get_tile(x, y)->units, punit) {
- unfog_area(pplayer, punit->x, punit->y,
- unit_type(punit)->vision_range);
- fog_area(pplayer, punit->x, punit->y, get_watchtower_vision(punit));
- }
- unit_list_iterate_end;
+ fog_area(unit_owner(punit), punit->x, punit->y,
+ get_unit_vision_range(punit));
+ } unit_list_iterate_end;
+
+ map_clear_special(x, y, S_FORTRESS);
+
+ unit_list_iterate(map_get_tile(x, y)->units, punit) {
+ unfog_area(unit_owner(punit), punit->x, punit->y,
+ get_unit_vision_range(punit));
+ } unit_list_iterate_end;
}
- map_clear_special(x, y, S_FORTRESS);
send_tile_info(NULL, x, y);
initialize_infrastructure_cache(pcity);
Index: server/maphand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/maphand.c,v
retrieving revision 1.125
diff -u -r1.125 maphand.c
--- server/maphand.c 2003/07/23 13:46:04 1.125
+++ server/maphand.c 2003/07/29 16:10:19
@@ -686,17 +686,10 @@
**************************************************************************/
void remove_unit_sight_points(struct unit *punit)
{
- int x = punit->x, y = punit->y;
- struct player *pplayer = unit_owner(punit);
-
freelog(LOG_DEBUG, "Removing unit sight points at %i,%i", punit->x,
punit->y);
-
- if (map_has_special(punit->x, punit->y, S_FORTRESS)
- && unit_profits_of_watchtower(punit))
- fog_area(pplayer, x, y, get_watchtower_vision(punit));
- else
- fog_area(pplayer, x, y, unit_type(punit)->vision_range);
+ fog_area(unit_owner(punit), punit->x, punit->y,
+ get_unit_vision_range(punit));
}
/**************************************************************************
Index: server/plrhand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/plrhand.c,v
retrieving revision 1.281
diff -u -r1.281 plrhand.c
--- server/plrhand.c 2003/07/21 01:43:52 1.281
+++ server/plrhand.c 2003/07/29 16:10:19
@@ -255,6 +255,15 @@
bonus_tech_hack = TRUE;
}
+ /* Remove old vision range of units inside a fortress. */
+ if (tech_flag(tech_found, TF_WATCHTOWER)) {
+ unit_list_iterate(plr->units, punit) {
+ if (map_has_special(punit->x, punit->y, S_FORTRESS)) {
+ fog_area(plr, punit->x, punit->y, get_unit_vision_range(punit));
+ }
+ } unit_list_iterate_end;
+ }
+
set_invention(plr, tech_found, TECH_KNOWN);
update_research(plr);
remove_obsolete_buildings(plr);
@@ -262,14 +271,11 @@
upgrade_city_rails(plr, was_discovery);
}
- /* enhace vision of units inside a fortress */
+ /* Add new vision range of units inside a fortress. */
if (tech_flag(tech_found, TF_WATCHTOWER)) {
unit_list_iterate(plr->units, punit) {
- if (map_has_special(punit->x, punit->y, S_FORTRESS)
- && is_ground_unit(punit)) {
- unfog_area(plr, punit->x, punit->y, get_watchtower_vision(punit));
- fog_area(plr, punit->x, punit->y,
- unit_type(punit)->vision_range);
+ if (map_has_special(punit->x, punit->y, S_FORTRESS)) {
+ unfog_area(plr, punit->x, punit->y, get_unit_vision_range(punit));
}
}
unit_list_iterate_end;
Index: server/savegame.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/savegame.c,v
retrieving revision 1.127
diff -u -r1.127 savegame.c
--- server/savegame.c 2003/07/23 13:46:04 1.127
+++ server/savegame.c 2003/07/29 16:10:19
@@ -1111,20 +1111,16 @@
}
{
- int range = unit_type(punit)->vision_range;
+ /* This assumes the map has been loaded already. */
+ int range = get_unit_vision_range(punit);
+
square_iterate(punit->x, punit->y, range, x1, y1) {
map_set_known(x1, y1, plr);
} square_iterate_end;
- }
- /* allocate the unit's contribution to fog of war */
- if (unit_profits_of_watchtower(punit)
- && map_has_special(punit->x, punit->y, S_FORTRESS))
- unfog_area(unit_owner(punit), punit->x, punit->y,
- get_watchtower_vision(punit));
- else
- unfog_area(unit_owner(punit), punit->x, punit->y,
- unit_type(punit)->vision_range);
+ /* allocate the unit's contribution to fog of war */
+ unfog_area(unit_owner(punit), punit->x, punit->y, range);
+ }
unit_list_insert_back(&plr->units, punit);
Index: server/unittools.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/unittools.c,v
retrieving revision 1.236
diff -u -r1.236 unittools.c
--- server/unittools.c 2003/07/24 16:52:28 1.236
+++ server/unittools.c 2003/07/29 16:10:19
@@ -702,6 +702,15 @@
get_preferred_pillage(
get_tile_infrastructure_set(map_get_tile(punit->x, punit->y)));
+ if (what == S_FORTRESS) {
+ freelog(LOG_VERBOSE, "Watchtower pillaged!");
+ unit_list_iterate(map_get_tile(punit->x, punit->y)->units,
+ punit2) {
+ fog_area(unit_owner(punit2), punit2->x, punit2->y,
+ get_unit_vision_range(punit2));
+ } unit_list_iterate_end;
+ }
+
if (what != S_NO_SPECIAL) {
map_clear_special(punit->x, punit->y, what);
send_tile_info(NULL, punit->x, punit->y);
@@ -709,19 +718,12 @@
}
/* If a watchtower has been pillaged, reduce sight to normal */
- if (what == S_FORTRESS
- && player_knows_techs_with_flag(pplayer, TF_WATCHTOWER)) {
- freelog(LOG_VERBOSE, "Watchtower pillaged!");
+ if (what == S_FORTRESS) {
unit_list_iterate(map_get_tile(punit->x, punit->y)->units,
punit2) {
- if (is_ground_unit(punit2)) {
- unfog_area(pplayer, punit2->x, punit2->y,
- unit_type(punit2)->vision_range);
- fog_area(pplayer, punit2->x, punit2->y,
- get_watchtower_vision(punit2));
- }
- }
- unit_list_iterate_end;
+ unfog_area(unit_owner(punit2), punit2->x, punit2->y,
+ get_unit_vision_range(punit2));
+ } unit_list_iterate_end;
}
}
}
@@ -729,6 +731,14 @@
punit->activity_target) >= 1) {
enum tile_special_type what_pillaged = punit->activity_target;
+ if (what_pillaged == S_FORTRESS) {
+ freelog(LOG_VERBOSE, "Watchtower(2) pillaged!");
+ unit_list_iterate(map_get_tile(punit->x, punit->y)->units, punit2) {
+ fog_area(unit_owner(punit2), punit2->x, punit2->y,
+ get_unit_vision_range(punit2));
+ } unit_list_iterate_end;
+ }
+
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) &&
@@ -740,18 +750,13 @@
send_tile_info(NULL, punit->x, punit->y);
/* If a watchtower has been pillaged, reduce sight to normal */
- if (what_pillaged == S_FORTRESS
- && player_knows_techs_with_flag(pplayer, TF_WATCHTOWER)) {
- freelog(LOG_VERBOSE, "Watchtower(2) pillaged!");
+ if (what_pillaged == S_FORTRESS) {
unit_list_iterate(map_get_tile(punit->x, punit->y)->units, punit2) {
if (is_ground_unit(punit2)) {
- unfog_area(pplayer, punit2->x, punit2->y,
- unit_type(punit2)->vision_range);
- fog_area(pplayer, punit2->x, punit2->y,
- get_watchtower_vision(punit2));
+ unfog_area(unit_owner(punit2), punit2->x, punit2->y,
+ get_unit_vision_range(punit2));
}
- }
- unit_list_iterate_end;
+ } unit_list_iterate_end;
}
}
}
@@ -775,20 +780,19 @@
if (activity==ACTIVITY_FORTRESS) {
if (total_activity (punit->x, punit->y, ACTIVITY_FORTRESS)
>= map_build_fortress_time(punit->x, punit->y)) {
+ unit_list_iterate(ptile->units, punit) {
+ fog_area(unit_owner(punit), punit->x, punit->y,
+ get_unit_vision_range(punit));
+ } unit_list_iterate_end;
+
map_set_special(punit->x, punit->y, S_FORTRESS);
unit_activity_done = TRUE;
- /* watchtower becomes effective */
- if (player_knows_techs_with_flag(pplayer, TF_WATCHTOWER)) {
- unit_list_iterate(ptile->units, punit) {
- if (is_ground_unit(punit)) {
- fog_area(pplayer, punit->x, punit->y,
- unit_type(punit)->vision_range);
- unfog_area(pplayer, punit->x, punit->y,
- get_watchtower_vision(punit));
- }
- }
- unit_list_iterate_end;
- }
+
+ /* Update watchtower vision range. */
+ unit_list_iterate(ptile->units, punit) {
+ unfog_area(unit_owner(punit), punit->x, punit->y,
+ get_unit_vision_range(punit));
+ } unit_list_iterate_end;
}
}
@@ -1419,16 +1423,10 @@
void upgrade_unit(struct unit *punit, Unit_Type_id to_unit)
{
struct player *pplayer = unit_owner(punit);
- int range;
+ int range = get_unit_vision_range(punit);
int old_mr = unit_move_rate(punit), old_hp = unit_type(punit)->hp;
-
- /* save old vision range */
- if (map_has_special(punit->x, punit->y, S_FORTRESS)
- && unit_profits_of_watchtower(punit))
- range = get_watchtower_vision(punit);
- else
- range = unit_type(punit)->vision_range;
+ /* Upgrade unit. */
punit->type = to_unit;
/* Scale HP and MP, rounding down. Be careful with integer arithmetic,
@@ -1440,13 +1438,7 @@
conn_list_do_buffer(&pplayer->connections);
/* apply new vision range */
- if (map_has_special(punit->x, punit->y, S_FORTRESS)
- && unit_profits_of_watchtower(punit))
- unfog_area(pplayer, punit->x, punit->y, get_watchtower_vision(punit));
- else
- unfog_area(pplayer, punit->x, punit->y,
- get_unit_type(to_unit)->vision_range);
-
+ unfog_area(pplayer, punit->x, punit->y, get_unit_vision_range(punit));
fog_area(pplayer,punit->x,punit->y,range);
send_unit_info(NULL, punit);
@@ -1517,12 +1509,7 @@
send_city_info(pplayer, pcity);
}
- if (map_has_special(x, y, S_FORTRESS)
- && unit_profits_of_watchtower(punit)) {
- unfog_area(pplayer, punit->x, punit->y, get_watchtower_vision(punit));
- } else {
- unfog_area(pplayer, x, y, unit_type(punit)->vision_range);
- }
+ unfog_area(pplayer, punit->x, punit->y, get_unit_vision_range(punit));
send_unit_info(NULL, punit);
maybe_make_contact(x, y, unit_owner(punit));
@@ -2113,8 +2100,8 @@
if (is_ocean(map_get_terrain(dest_x, dest_y))
&& is_ground_unit(punit)) {
- int srange = unit_type(punit)->vision_range;
- show_area(pplayer, dest_x, dest_y, srange);
+ show_area(pplayer, dest_x, dest_y,
+ get_unit_vision_range_at(punit, dest_x, dest_y));
notify_player_ex(pplayer, dest_x, dest_y, E_UNIT_LOST,
_("Game: Your %s paradropped into the ocean "
@@ -2126,8 +2113,9 @@
if ((ptile->city && pplayers_non_attack(pplayer, city_owner(ptile->city)))
|| is_non_allied_unit_tile(ptile, pplayer)) {
- int srange = unit_type(punit)->vision_range;
- show_area(pplayer, dest_x, dest_y, srange);
+ show_area(pplayer, dest_x, dest_y,
+ get_unit_vision_range_at(punit, dest_x, dest_y));
+
maybe_make_contact(dest_x, dest_y, pplayer);
notify_player_ex(pplayer, dest_x, dest_y, E_UNIT_LOST_ATT,
_("Game: Your %s was killed by enemy units at the "
@@ -2611,16 +2599,10 @@
wake them up if the punit is farther away than 3. */
square_iterate(punit->x, punit->y, 3, x, y) {
unit_list_iterate(map_get_tile(x, y)->units, penemy) {
- int range;
+ int range = get_unit_vision_range(penemy);
enum unit_move_type move_type = unit_type(penemy)->move_type;
enum tile_terrain_type terrain = map_get_terrain(x, y);
- if (map_has_special(x, y, S_FORTRESS)
- && unit_profits_of_watchtower(penemy))
- range = get_watchtower_vision(penemy);
- else
- range = unit_type(penemy)->vision_range;
-
if (!pplayers_allied(unit_owner(punit), unit_owner(penemy))
&& penemy->activity == ACTIVITY_SENTRY
&& map_get_known_and_seen(punit->x, punit->y, unit_owner(penemy))
@@ -2832,7 +2814,8 @@
/* Insert them again. */
unit_list_iterate(cargo_units, pcargo) {
- unfog_area(unit_owner(pcargo), dest_x, dest_y,
unit_type(pcargo)->vision_range);
+ unfog_area(unit_owner(pcargo), dest_x, dest_y,
+ get_unit_vision_range_at(pcargo, dest_x, dest_y));
pcargo->x = dest_x;
pcargo->y = dest_y;
@@ -2846,7 +2829,8 @@
unit_list_insert(&pdesttile->units, pcargo);
check_unit_activity(pcargo);
send_unit_info_to_onlookers(NULL, pcargo, src_x, src_y, TRUE);
- fog_area(unit_owner(pcargo), src_x, src_y,
unit_type(pcargo)->vision_range);
+ fog_area(unit_owner(pcargo), src_x, src_y,
+ get_unit_vision_range_at(pcargo, src_x, src_y));
handle_unit_move_consequences(pcargo, src_x, src_y, dest_x, dest_y);
} unit_list_iterate_end;
unit_list_unlink_all(&cargo_units);
@@ -2859,12 +2843,8 @@
move */
/* Enhace vision if unit steps into a fortress */
- if (unit_profits_of_watchtower(punit)
- && tile_has_special(pdesttile, S_FORTRESS))
- unfog_area(pplayer, dest_x, dest_y, get_watchtower_vision(punit));
- else
- unfog_area(pplayer, dest_x, dest_y,
- unit_type(punit)->vision_range);
+ unfog_area(pplayer, dest_x, dest_y,
+ get_unit_vision_range_at(punit, dest_x, dest_y));
unit_list_unlink(&psrctile->units, punit);
punit->x = dest_x;
@@ -2904,12 +2884,8 @@
* at (src_x, src_y) */
reveal_hidden_units(pplayer, dest_x, dest_y);
- if (unit_profits_of_watchtower(punit)
- && tile_has_special(psrctile, S_FORTRESS))
- fog_area(pplayer, src_x, src_y, get_watchtower_vision(punit));
- else
- fog_area(pplayer, src_x, src_y,
- unit_type(punit)->vision_range);
+ fog_area(pplayer, src_x, src_y,
+ get_unit_vision_range_at(punit, src_x, src_y));
handle_unit_move_consequences(punit, src_x, src_y, dest_x, dest_y);
wakeup_neighbor_sentries(punit);
@@ -2932,14 +2908,8 @@
static bool maybe_cancel_patrol_due_to_enemy(struct unit *punit)
{
bool cancel = FALSE;
- int range;
+ int range = get_unit_vision_range(punit);
- if (map_has_special(punit->x, punit->y, S_FORTRESS)
- && unit_profits_of_watchtower(punit))
- range = get_watchtower_vision(punit);
- else
- range = unit_type(punit)->vision_range;
-
square_iterate(punit->x, punit->y, range, x, y) {
struct unit *penemy =
is_non_allied_unit_tile(map_get_tile(x, y), unit_owner(punit));
@@ -3053,27 +3023,34 @@
}
/**************************************************************************
-...
+ Get the real vision range the unit would have at the given position,
+ including any special effects from watchtowers, etc. Note that the unit
+ need not be physically located at the position; this function calculates
+ the vision it would have if it were.
**************************************************************************/
-int get_watchtower_vision(struct unit *punit)
+int get_unit_vision_range_at(struct unit *punit, int map_x, int map_y)
{
int base_vision = unit_type(punit)->vision_range;
- assert(base_vision > 0);
- assert(game.watchtower_vision > 0);
- assert(game.watchtower_extra_vision >= 0);
-
- return MAX(base_vision,
- MAX(game.watchtower_vision,
- base_vision + game.watchtower_extra_vision));
+ if (is_ground_unit(punit)
+ && player_knows_techs_with_flag(unit_owner(punit), TF_WATCHTOWER)
+ && map_has_special(map_x, map_y, S_FORTRESS)) {
+ assert(base_vision > 0);
+ assert(game.watchtower_vision > 0);
+ assert(game.watchtower_extra_vision >= 0);
+
+ return MAX(base_vision,
+ MAX(game.watchtower_vision,
+ base_vision + game.watchtower_extra_vision));
+ } else {
+ return base_vision;
+ }
}
/**************************************************************************
-...
+ Get the real vision range the unit has at its current location.
**************************************************************************/
-bool unit_profits_of_watchtower(struct unit *punit)
+int get_unit_vision_range(struct unit *punit)
{
- return (is_ground_unit(punit)
- && player_knows_techs_with_flag(unit_owner(punit),
- TF_WATCHTOWER));
+ return get_unit_vision_range_at(punit, punit->x, punit->y);
}
Index: server/unittools.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/unittools.h,v
retrieving revision 1.52
diff -u -r1.52 unittools.h
--- server/unittools.h 2003/07/02 19:32:47 1.52
+++ server/unittools.h 2003/07/29 16:10:19
@@ -45,8 +45,8 @@
void resolve_unit_stacks(struct player *pplayer, struct player *aplayer,
bool verbose);
void disband_stack_conflict_unit(struct unit *punit, bool verbose);
-int get_watchtower_vision(struct unit *punit);
-bool unit_profits_of_watchtower(struct unit *punit);
+int get_unit_vision_range_at(struct unit *punit, int map_x, int map_y);
+int get_unit_vision_range(struct unit *punit);
void pay_for_units(struct player *pplayer, struct city *pcity);
/* creation/deletion/upgrading */
|
|