Freeciv-3.2: /fast/freeciv/nightly/S3_2/common/borders.c Source File

Freeciv-3.2

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/*********************************************************************/
33 int tile_border_source_radius_sq(struct tile *ptile)
34{
35 struct city *pcity;
36 int radius_sq = 0;
37
38 if (BORDERS_DISABLED == game.info.borders) {
39 return 0;
40 }
41
42 pcity = tile_city(ptile);
43
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 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 }
60 } extra_type_list_iterate_end;
61 }
62
63 return radius_sq;
64}
65
66/*********************************************************************/
69 int tile_border_source_strength(struct tile *ptile)
70{
71 struct city *pcity;
72 int strength = 0;
73
74 if (BORDERS_DISABLED == game.info.borders) {
75 return 0;
76 }
77
78 pcity = tile_city(ptile);
79
80 if (pcity) {
81 strength = (city_size_get(pcity) + 2)
82 * (100 + get_city_bonus(pcity, EFT_BORDER_STRENGTH_PCT)) / 100;
83 } else {
84 struct extra_type_list *terr_claimers = extra_type_list_of_terr_claimers();
85
86 extra_type_list_iterate(terr_claimers, pextra) {
87 if (tile_has_extra(ptile, pextra)) {
88 /* Base strength 100 / 100 = 1 */
89 strength = (100 + get_tile_bonus(ptile, EFT_BORDER_STRENGTH_PCT)) / 100;
90 break;
91 }
92 } extra_type_list_iterate_end;
93 }
94
95 return strength;
96}
97
98/*********************************************************************/
101 int tile_border_strength(struct tile *ptile, struct tile *source)
102{
103 int full_strength = tile_border_source_strength(source);
104 int sq_dist = sq_map_distance(ptile, source);
105
106 if (sq_dist > 0) {
107 return full_strength * full_strength / sq_dist;
108 } else {
109 return FC_INFINITY;
110 }
111}
112
113/*********************************************************************/
116 bool is_border_source(struct tile *ptile)
117{
118 if (tile_city(ptile)) {
119 return TRUE;
120 }
121
122 if (extra_owner(ptile) != NULL) {
123 struct extra_type_list *terr_claimers = extra_type_list_of_terr_claimers();
124
125 extra_type_list_iterate(terr_claimers, pextra) {
126 if (tile_has_extra(ptile, pextra)) {
127 return TRUE;
128 }
129 } extra_type_list_iterate_end;
130 }
131
132 return FALSE;
133}
tile_border_source_radius_sq
int tile_border_source_radius_sq(struct tile *ptile)
Definition borders.c:33
is_border_source
bool is_border_source(struct tile *ptile)
Definition borders.c:116
tile_border_strength
int tile_border_strength(struct tile *ptile, struct tile *source)
Definition borders.c:101
tile_border_source_strength
int tile_border_source_strength(struct tile *ptile)
Definition borders.c:69
borders.h
CITY_MAP_MAX_RADIUS_SQ
#define CITY_MAP_MAX_RADIUS_SQ
Definition city.h:86
city_size_get
static citizens city_size_get(const struct city *pcity)
Definition city.h:569
incite_cost
char * incite_cost
Definition comments.c:74
get_city_bonus
int get_city_bonus(const struct city *pcity, enum effect_type effect_type)
Definition effects.c:846
get_tile_bonus
int get_tile_bonus(const struct tile *ptile, enum effect_type effect_type)
Definition effects.c:866
extra_owner
struct player * extra_owner(const struct tile *ptile)
Definition extras.c:1114
extra_type_list_of_terr_claimers
struct extra_type_list * extra_type_list_of_terr_claimers(void)
Definition extras.c:275
extra_type_list_iterate
#define extra_type_list_iterate(extralist, pextra)
Definition extras.h:165
extra_type_list_iterate_end
#define extra_type_list_iterate_end
Definition extras.h:167
extra_base_get
#define extra_base_get(_e_)
Definition extras.h:190
BORDERS_DISABLED
@ BORDERS_DISABLED
Definition fc_types.h:1038
fcintl.h
game
struct civ_game game
Definition game.c:62
game.h
source
static GtkWidget * source
Definition gotodlg.c:58
log.h
sq_map_distance
int sq_map_distance(const struct tile *tile0, const struct tile *tile1)
Definition map.c:641
map.h
MIN
#define MIN(x, y)
Definition shared.h:55
FC_INFINITY
#define FC_INFINITY
Definition shared.h:36
base_type
Definition base.h:41
city
Definition city.h:320
civ_game::info
struct packet_game_info info
Definition game.h:89
packet_game_info::borders
enum borders_mode borders
Definition packets_gen.h:130
packet_game_info::border_size_effect
int border_size_effect
Definition packets_gen.h:128
packet_game_info::border_city_radius_sq
int border_city_radius_sq
Definition packets_gen.h:127
tile
Definition tile.h:50
TRUE
#define TRUE
Definition support.h:46
FALSE
#define FALSE
Definition support.h:47
tile_city
struct city * tile_city(const struct tile *ptile)
Definition tile.c:83
tile.h
tile_has_extra
#define tile_has_extra(ptile, pextra)
Definition tile.h:147
unit.h