Stop sharing requirement_unit_state_ereq().
[freeciv.git] / common / borders.c
blob8987b0b9612c7ef1b884646a32ebe1ce0942239f
1 /****************************************************************************
2 Freeciv - Copyright (C) 2004 - The Freeciv Team
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; either version 2, or (at your option)
6 any later version.
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12 ****************************************************************************/
14 #ifdef HAVE_CONFIG_H
15 #include <fc_config.h>
16 #endif
18 /* utility */
19 #include "fcintl.h"
20 #include "log.h"
22 /* common */
23 #include "game.h"
24 #include "map.h"
25 #include "tile.h"
26 #include "unit.h"
28 #include "borders.h"
30 /*************************************************************************
31 Border radius sq from given border source tile.
32 *************************************************************************/
33 int tile_border_source_radius_sq(struct tile *ptile)
35 struct city *pcity;
36 int radius_sq = 0;
38 if (BORDERS_DISABLED == game.info.borders) {
39 return 0;
42 pcity = tile_city(ptile);
44 if (pcity) {
45 radius_sq = game.info.border_city_radius_sq;
46 /* Limit the addition due to the city size. A city size of 60 or more is
47 * possible with a city radius of 5 (radius_sq = 26). */
48 radius_sq += MIN(city_size_get(pcity), CITY_MAP_MAX_RADIUS_SQ)
49 * game.info.border_size_effect;
50 } else {
51 extra_type_by_cause_iterate(EC_BASE, pextra) {
52 struct base_type *pbase = extra_base_get(pextra);
54 if (tile_has_extra(ptile, pextra) && territory_claiming_base(pbase)) {
55 radius_sq = pbase->border_sq;
56 break;
58 } extra_type_by_cause_iterate_end;
61 return radius_sq;
64 /*************************************************************************
65 Border source strength
66 *************************************************************************/
67 int tile_border_source_strength(struct tile *ptile)
69 struct city *pcity;
70 int strength = 0;
72 if (BORDERS_DISABLED == game.info.borders) {
73 return 0;
76 pcity = tile_city(ptile);
78 if (pcity) {
79 strength = city_size_get(pcity) + 2;
80 } else {
81 extra_type_by_cause_iterate(EC_BASE, pextra) {
82 struct base_type *pbase = extra_base_get(pextra);
84 if (tile_has_extra(ptile, pextra) && territory_claiming_base(pbase)) {
85 strength = 1;
86 break;
88 } extra_type_by_cause_iterate_end;
91 return strength;
94 /*************************************************************************
95 Border source strength at tile
96 *************************************************************************/
97 int tile_border_strength(struct tile *ptile, struct tile *source)
99 int full_strength = tile_border_source_strength(source);
100 int sq_dist = sq_map_distance(ptile, source);
102 if (sq_dist > 0) {
103 return full_strength * full_strength / sq_dist;
104 } else {
105 return FC_INFINITY;
109 /*************************************************************************
110 Is given tile source to borders.
111 *************************************************************************/
112 bool is_border_source(struct tile *ptile)
114 if (tile_city(ptile)) {
115 return TRUE;
118 if (extra_owner(ptile) != NULL) {
119 extra_type_by_cause_iterate(EC_BASE, pextra) {
120 struct base_type *pbase = extra_base_get(pextra);
122 if (tile_has_extra(ptile, pextra) && territory_claiming_base(pbase)) {
123 return TRUE;
125 } extra_type_by_cause_iterate_end;
128 return FALSE;