Freeciv-3.1
Loading...
Searching...
No Matches
borders.c
Go to the documentation of this file.
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.
7
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****************************************************************************/
13
14#ifdef HAVE_CONFIG_H
15#include <fc_config.h>
16#endif
17
18/* utility */
19#include "fcintl.h"
20#include "log.h"
21
22/* common */
23#include "game.h"
24#include "map.h"
25#include "tile.h"
26#include "unit.h"
27
28#include "borders.h"
29
30/*********************************************************************/
34{
35 struct city *pcity;
36 int radius_sq = 0;
37
39 return 0;
40 }
41
42 pcity = tile_city(ptile);
43
44 if (pcity) {
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)
50 } else {
51 struct extra_type_list *terr_claimers = extra_type_list_of_terr_claimers();
52
53 extra_type_list_iterate(terr_claimers, pextra) {
54 if (tile_has_extra(ptile, pextra)) {
55 struct base_type *pbase = extra_base_get(pextra);
56
57 radius_sq = pbase->border_sq;
58 break;
59 }
61 }
62
63 return radius_sq;
64}
65
66/*********************************************************************/
70{
71 struct city *pcity;
72 int strength = 0;
73
75 return 0;
76 }
77
78 pcity = tile_city(ptile);
79
80 if (pcity) {
81 strength = city_size_get(pcity) + 2;
82 } else {
83 struct extra_type_list *terr_claimers = extra_type_list_of_terr_claimers();
84
85 extra_type_list_iterate(terr_claimers, pextra) {
86 if (tile_has_extra(ptile, pextra)) {
87 strength = 1;
88 break;
89 }
91 }
92
93 return strength;
94}
95
96/*********************************************************************/
99int tile_border_strength(struct tile *ptile, struct tile *source)
100{
101 int full_strength = tile_border_source_strength(source);
102 int sq_dist = sq_map_distance(ptile, source);
103
104 if (sq_dist > 0) {
105 return full_strength * full_strength / sq_dist;
106 } else {
107 return FC_INFINITY;
108 }
109}
110
111/*********************************************************************/
114bool is_border_source(struct tile *ptile)
115{
116 if (tile_city(ptile)) {
117 return TRUE;
118 }
119
120 if (extra_owner(ptile) != NULL) {
121 struct extra_type_list *terr_claimers = extra_type_list_of_terr_claimers();
122
123 extra_type_list_iterate(terr_claimers, pextra) {
124 if (tile_has_extra(ptile, pextra)) {
125 return TRUE;
126 }
128 }
129
130 return FALSE;
131}
int tile_border_source_radius_sq(struct tile *ptile)
Definition borders.c:33
bool is_border_source(struct tile *ptile)
Definition borders.c:114
int tile_border_strength(struct tile *ptile, struct tile *source)
Definition borders.c:99
int tile_border_source_strength(struct tile *ptile)
Definition borders.c:69
#define CITY_MAP_MAX_RADIUS_SQ
Definition city.h:78
static citizens city_size_get(const struct city *pcity)
Definition city.h:549
struct player * extra_owner(const struct tile *ptile)
Definition extras.c:1068
struct extra_type_list * extra_type_list_of_terr_claimers(void)
Definition extras.c:259
#define extra_type_list_iterate(extralist, pextra)
Definition extras.h:159
#define extra_type_list_iterate_end
Definition extras.h:161
#define extra_base_get(_e_)
Definition extras.h:184
@ BORDERS_DISABLED
Definition fc_types.h:891
struct civ_game game
Definition game.c:57
static GtkWidget * source
Definition gotodlg.c:58
int sq_map_distance(const struct tile *tile0, const struct tile *tile1)
Definition map.c:639
#define MIN(x, y)
Definition shared.h:55
#define FC_INFINITY
Definition shared.h:36
int border_sq
Definition base.h:44
Definition city.h:309
struct packet_game_info info
Definition game.h:89
enum borders_mode borders
Definition tile.h:49
#define TRUE
Definition support.h:46
#define FALSE
Definition support.h:47
struct city * tile_city(const struct tile *ptile)
Definition tile.c:83
#define tile_has_extra(ptile, pextra)
Definition tile.h:146