I18n markup: TRANS comments and missing no-c-format.
[freeciv.git] / common / borders.c
blobb54ade289308e553b4e99473cdda0e8c5b3a3bf4
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 "tile.h"
25 #include "unit.h"
27 #include "borders.h"
29 /*************************************************************************
30 Border radius sq from given border source tile.
31 *************************************************************************/
32 int tile_border_source_radius_sq(struct tile *ptile)
34 struct city *pcity;
35 int radius_sq = 0;
37 if (BORDERS_DISABLED == game.info.borders) {
38 return 0;
41 pcity = tile_city(ptile);
43 if (pcity) {
44 radius_sq = game.info.border_city_radius_sq;
45 /* Limit the addition due to the city size. A city size of 60 or more is
46 * possible with a city radius of 5 (radius_sq = 26). */
47 radius_sq += MIN(city_size_get(pcity), CITY_MAP_MAX_RADIUS_SQ)
48 * game.info.border_size_effect;
49 } else {
50 base_type_iterate(pbase) {
51 if (tile_has_base(ptile, pbase) && territory_claiming_base(pbase)) {
52 radius_sq = pbase->border_sq;
53 break;
55 } base_type_iterate_end;
58 return radius_sq;
61 /*************************************************************************
62 Border source strength
63 *************************************************************************/
64 int tile_border_source_strength(struct tile *ptile)
66 struct city *pcity;
67 int strength = 0;
69 if (BORDERS_DISABLED == game.info.borders) {
70 return 0;
73 pcity = tile_city(ptile);
75 if (pcity) {
76 strength = city_size_get(pcity) + 2;
77 } else {
78 base_type_iterate(pbase) {
79 if (tile_has_base(ptile, pbase) && territory_claiming_base(pbase)) {
80 strength = 1;
81 break;
83 } base_type_iterate_end;
86 return strength;
89 /*************************************************************************
90 Border source strength at tile
91 *************************************************************************/
92 int tile_border_strength(struct tile *ptile, struct tile *source)
94 int full_strength = tile_border_source_strength(source);
95 int sq_dist = sq_map_distance(ptile, source);
97 if (sq_dist > 0) {
98 return full_strength * full_strength / sq_dist;
99 } else {
100 return FC_INFINITY;
104 /*************************************************************************
105 Is given tile source to borders.
106 *************************************************************************/
107 bool is_border_source(struct tile *ptile)
109 if (tile_city(ptile)) {
110 return TRUE;
113 if (tile_owner(ptile) != NULL) {
114 base_type_iterate(pbase) {
115 if (tile_has_base(ptile, pbase) && territory_claiming_base(pbase)) {
116 return TRUE;
118 } base_type_iterate_end;
121 return FALSE;