[Freeciv-Dev] (PR#8982) City.c cleanup
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: |
undisclosed-recipients: ; |
Subject: |
[Freeciv-Dev] (PR#8982) City.c cleanup |
From: |
"Per Inge Mathisen" <pim@xxxxxxxxxxxx> |
Date: |
Mon, 14 Jun 2004 03:07:19 -0700 |
Reply-to: |
rt@xxxxxxxxxxx |
<URL: http://rt.freeciv.org/Ticket/Display.html?id=8982 >
This patch makes some static to static inline, makes most struct city into
consts, cleans up some style issues and adds some comments. The primary
reason for the patch is to document what functions that change city
contents and which do not.
The aim is to eventually separate out the calculation parts from the
modify-city code, so that the former can be used in AI code without
actually altering any city state.
- Per
Index: common/city.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/city.c,v
retrieving revision 1.218
diff -u -r1.218 city.c
--- common/city.c 13 Jun 2004 03:57:04 -0000 1.218
+++ common/city.c 14 Jun 2004 10:00:37 -0000
@@ -30,28 +30,6 @@
#include "city.h"
-/* start helper functions for generic_city_refresh */
-static int content_citizens(struct player *pplayer);
-static void set_tax_income(struct city *pcity);
-static void add_buildings_effect(struct city *pcity);
-static void happy_copy(struct city *pcity, int i);
-static void citizen_happy_size(struct city *pcity);
-static void citizen_happy_luxury(struct city *pcity);
-static void citizen_happy_units(struct city *pcity, int unhap);
-static void citizen_happy_buildings(struct city *pcity);
-static void citizen_happy_wonders(struct city *pcity);
-static void unhappy_city_check(struct city *pcity);
-static void set_pollution(struct city *pcity);
-static void set_food_trade_shields(struct city *pcity);
-static int citygov_free_gold(struct city *pcity, struct government *gov);
-static void city_support(struct city *pcity,
- void (*send_unit_info) (struct player * pplayer,
- struct unit * punit));
-/* end helper functions for generic_city_refresh */
-
-static int improvement_upkeep_asmiths(struct city *pcity, Impr_Type_id i,
- bool asmiths);
-
/* Iterate a city map, from the center (the city) outwards */
struct iter_index *city_map_iterate_outwards_indices;
@@ -103,9 +81,9 @@
Finds the city map coordinate for a given map position and a city
center. Returns whether the map position is inside of the city map.
**************************************************************************/
-static bool base_map_to_city_map(int *city_map_x, int *city_map_y,
- int city_center_x, int city_center_y,
- int map_x, int map_y)
+static inline bool base_map_to_city_map(int *city_map_x, int *city_map_y,
+ int city_center_x, int city_center_y,
+ int map_x, int map_y)
{
map_distance_vector(city_map_x, city_map_y,
city_center_x, city_center_y, map_x, map_y);
@@ -229,7 +207,7 @@
qsort(array, CITY_TILES, sizeof(*array), compare_index);
-#ifdef DEBUG
+#ifdef REALLY_DEBUG_THIS
for (i = 0; i < CITY_TILES; i++) {
freelog(LOG_DEBUG, "%2d : (%2d,%2d) : %d", i,
array[i].dx + CITY_MAP_RADIUS, array[i].dy + CITY_MAP_RADIUS,
@@ -252,11 +230,13 @@
struct tile *ptile = map_get_tile(map_x, map_y);
if (pcity->city_map[city_x][city_y] == C_TILE_WORKER
- && ptile->worked == pcity)
+ && ptile->worked == pcity) {
ptile->worked = NULL;
+ }
pcity->city_map[city_x][city_y] = type;
- if (type == C_TILE_WORKER)
+ if (type == C_TILE_WORKER) {
ptile->worked = pcity;
+ }
} else {
assert(type == C_TILE_UNAVAILABLE);
pcity->city_map[city_x][city_y] = type;
@@ -266,17 +246,19 @@
/**************************************************************************
...
**************************************************************************/
-enum city_tile_type get_worker_city(struct city *pcity, int city_x, int city_y)
+enum city_tile_type get_worker_city(const struct city *pcity,
+ int city_x, int city_y)
{
- if (!is_valid_city_coords(city_x, city_y))
+ if (!is_valid_city_coords(city_x, city_y)) {
return C_TILE_UNAVAILABLE;
+ }
return pcity->city_map[city_x][city_y];
}
/**************************************************************************
...
**************************************************************************/
-bool is_worker_here(struct city *pcity, int city_x, int city_y)
+bool is_worker_here(const struct city *pcity, int city_x, int city_y)
{
if (!is_valid_city_coords(city_x, city_y)) {
return FALSE;
@@ -289,7 +271,7 @@
FIXME: This should be replaced in the near future with
improvment_redundant()
**************************************************************************/
-bool wonder_replacement(struct city *pcity, Impr_Type_id id)
+bool wonder_replacement(const struct city *pcity, Impr_Type_id id)
{
if(is_wonder(id)) return FALSE;
switch (id) {
@@ -336,7 +318,7 @@
/**************************************************************************
...
**************************************************************************/
-const char *get_impr_name_ex(struct city *pcity, Impr_Type_id id)
+const char *get_impr_name_ex(const struct city *pcity, Impr_Type_id id)
{
static char buffer[256];
const char *state = NULL;
@@ -367,7 +349,7 @@
/**************************************************************************
...
**************************************************************************/
-int city_buy_cost(struct city *pcity)
+int city_buy_cost(const struct city *pcity)
{
int cost, build = pcity->shield_stock;
@@ -385,7 +367,7 @@
/**************************************************************************
...
**************************************************************************/
-struct player *city_owner(struct city *pcity)
+struct player *city_owner(const struct city *pcity)
{
return (&game.players[pcity->owner]);
}
@@ -395,7 +377,7 @@
terr_gate (terrain) or spec_gate (specials), or if the building has no
terrain/special requirements.
**************************************************************************/
-bool city_has_terr_spec_gate(struct city *pcity, Impr_Type_id id)
+bool city_has_terr_spec_gate(const struct city *pcity, Impr_Type_id id)
{
struct impr_type *impr;
enum tile_terrain_type *terr_gate;
@@ -424,17 +406,20 @@
Will this city ever be able to build this improvement?
Doesn't check for building prereqs
**************************************************************************/
-bool can_eventually_build_improvement(struct city *pcity, Impr_Type_id id)
+bool can_eventually_build_improvement(const struct city *pcity, Impr_Type_id
id)
{
/* also does an improvement_exists() */
- if (!could_player_eventually_build_improvement(city_owner(pcity),id))
+ if (!could_player_eventually_build_improvement(city_owner(pcity),id)) {
return FALSE;
+ }
- if (city_got_building(pcity, id))
+ if (city_got_building(pcity, id)) {
return FALSE;
+ }
- if (!city_has_terr_spec_gate(pcity,id))
+ if (!city_has_terr_spec_gate(pcity,id)) {
return FALSE;
+ }
return !improvement_redundant(city_owner(pcity),pcity, id, TRUE);
}
@@ -444,42 +429,48 @@
owner has the required tech, but if all other pre reqs are fulfiled?
modularized so the AI can choose the tech it wants -- Syela
**************************************************************************/
-static bool could_build_improvement(struct city *pcity, Impr_Type_id id)
+static inline bool could_build_improvement(const struct city *pcity,
+ Impr_Type_id id)
{
struct impr_type *impr;
- if (!can_eventually_build_improvement(pcity, id))
+ if (!can_eventually_build_improvement(pcity, id)) {
return FALSE;
+ }
impr = get_improvement_type(id);
/* The building pre req */
- if (impr->bldg_req != B_LAST)
- if (!city_got_building(pcity,impr->bldg_req))
+ if (impr->bldg_req != B_LAST) {
+ if (!city_got_building(pcity,impr->bldg_req)) {
return FALSE;
+ }
+ }
return TRUE;
}
/**************************************************************************
-Can this improvement get built in this city, by the player
-who owns the city?
+ Can this improvement get built in this city by the player who owns it?
**************************************************************************/
-bool can_build_improvement(struct city *pcity, Impr_Type_id id)
+bool can_build_improvement(const struct city *pcity, Impr_Type_id id)
{
- struct player *p=city_owner(pcity);
- if (!improvement_exists(id))
+ struct player *p = city_owner(pcity);
+
+ if (!improvement_exists(id)) {
return FALSE;
- if (!player_knows_improvement_tech(p,id))
+ }
+ if (!player_knows_improvement_tech(p, id)) {
return FALSE;
- return(could_build_improvement(pcity, id));
+ }
+ return could_build_improvement(pcity, id);
}
/**************************************************************************
-Whether given city can build given unit,
-ignoring whether unit is obsolete.
+ Return whether given city can build given unit, ignoring whether unit
+ is obsolete.
**************************************************************************/
-bool can_build_unit_direct(struct city *pcity, Unit_Type_id id)
+bool can_build_unit_direct(const struct city *pcity, Unit_Type_id id)
{
Impr_Type_id impr_req;
@@ -502,28 +493,32 @@
}
/**************************************************************************
-Whether given city can build given unit;
-returns 0 if unit is obsolete.
+ Return whether given city can build given unit; returns 0 if unit is
+ obsolete.
**************************************************************************/
-bool can_build_unit(struct city *pcity, Unit_Type_id id)
+bool can_build_unit(const struct city *pcity, Unit_Type_id id)
{
- if (!can_build_unit_direct(pcity, id))
+ if (!can_build_unit_direct(pcity, id)) {
return FALSE;
- while(unit_type_exists((id = unit_types[id].obsoleted_by)))
- if (can_player_build_unit_direct(city_owner(pcity), id))
+ }
+ while (unit_type_exists((id = unit_types[id].obsoleted_by))) {
+ if (can_player_build_unit_direct(city_owner(pcity), id)) {
return FALSE;
+ }
+ }
return TRUE;
}
/**************************************************************************
-Whether player can eventually build given unit in the city;
-returns 0 if unit can never possibily be built in this city.
+ Return whether player can eventually build given unit in the city;
+ returns 0 if unit can never possibly be built in this city.
**************************************************************************/
-bool can_eventually_build_unit(struct city *pcity, Unit_Type_id id)
+bool can_eventually_build_unit(const struct city *pcity, Unit_Type_id id)
{
/* Can the _player_ ever build this unit? */
- if (!can_player_eventually_build_unit(city_owner(pcity), id))
+ if (!can_player_eventually_build_unit(city_owner(pcity), id)) {
return FALSE;
+ }
/* Some units can be built only in certain cities -- for instance,
ships may be built only in cities adjacent to ocean. */
@@ -537,7 +532,7 @@
/****************************************************************************
Returns TRUE iff if the given city can use this kind of specialist.
****************************************************************************/
-bool city_can_use_specialist(struct city *pcity,
+bool city_can_use_specialist(const struct city *pcity,
enum specialist_type type)
{
return pcity->size >= game.rgame.specialists[type].min_size;
@@ -546,7 +541,7 @@
/**************************************************************************
Returns how many thousand citizen live in this city.
**************************************************************************/
-int city_population(struct city *pcity)
+int city_population(const struct city *pcity)
{
/* Sum_{i=1}^{n} i == n*(n+1)/2 */
return pcity->size * (pcity->size + 1) * 5;
@@ -555,18 +550,19 @@
/**************************************************************************
...
**************************************************************************/
-bool city_got_building(struct city *pcity, Impr_Type_id id)
+bool city_got_building(const struct city *pcity, Impr_Type_id id)
{
- if (!improvement_exists(id))
+ if (!improvement_exists(id)) {
return FALSE;
- else
+ } else {
return (pcity->improvements[id] != I_NONE);
+ }
}
/**************************************************************************
...
**************************************************************************/
-int improvement_upkeep(struct city *pcity, Impr_Type_id i)
+int improvement_upkeep(const struct city *pcity, Impr_Type_id i)
{
if (!improvement_exists(i))
return 0;
@@ -586,8 +582,8 @@
/**************************************************************************
Caller to pass asmiths = city_affected_by_wonder(pcity, B_ASMITHS)
**************************************************************************/
-static int improvement_upkeep_asmiths(struct city *pcity, Impr_Type_id i,
- bool asmiths)
+static inline int improvement_upkeep_asmiths(const struct city *pcity,
Impr_Type_id i,
+ bool asmiths)
{
if (!improvement_exists(i))
return 0;
@@ -607,7 +603,7 @@
(city_x, city_y) must be valid city coordinates and is_celebrating tells
whether the city is celebrating.
**************************************************************************/
-static int base_get_shields_tile(int map_x, int map_y, struct city *pcity,
+static int base_get_shields_tile(int map_x, int map_y, const struct city
*pcity,
int city_x, int city_y, bool is_celebrating)
{
enum tile_special_type spec_t = map_get_special(map_x, map_y);
@@ -680,7 +676,7 @@
Calculate the shields the given tile is capable of producing for the
city.
**************************************************************************/
-int city_get_shields_tile(int city_x, int city_y, struct city *pcity)
+int city_get_shields_tile(int city_x, int city_y, const struct city *pcity)
{
return base_city_get_shields_tile(city_x, city_y, pcity,
city_celebrating(pcity));
@@ -692,7 +688,7 @@
This can be used to calculate the benefits celebration would give.
**************************************************************************/
-int base_city_get_shields_tile(int city_x, int city_y, struct city *pcity,
+int base_city_get_shields_tile(int city_x, int city_y, const struct city
*pcity,
bool is_celebrating)
{
int map_x, map_y;
@@ -711,7 +707,7 @@
(city_x, city_y) must be valid city coordinates and is_celebrating tells
whether the city is celebrating.
**************************************************************************/
-static int base_get_trade_tile(int map_x, int map_y, struct city *pcity,
+static int base_get_trade_tile(int map_x, int map_y, const struct city *pcity,
int city_x, int city_y, bool is_celebrating)
{
enum tile_special_type spec_t = map_get_special(map_x, map_y);
@@ -793,7 +789,7 @@
Calculate the trade the given tile is capable of producing for the
city.
**************************************************************************/
-int city_get_trade_tile(int city_x, int city_y, struct city *pcity)
+int city_get_trade_tile(int city_x, int city_y, const struct city *pcity)
{
return base_city_get_trade_tile(city_x, city_y,
pcity, city_celebrating(pcity));
@@ -806,7 +802,7 @@
This can be used to calculate the benefits celebration would give.
**************************************************************************/
int base_city_get_trade_tile(int city_x, int city_y,
- struct city *pcity, bool is_celebrating)
+ const struct city *pcity, bool is_celebrating)
{
int map_x, map_y;
@@ -824,7 +820,7 @@
(city_x, city_y) must be valid city coordinates and is_celebrating tells
whether the city is celebrating.
**************************************************************************/
-static int base_get_food_tile(int map_x, int map_y, struct city *pcity,
+static int base_get_food_tile(int map_x, int map_y, const struct city *pcity,
int city_x, int city_y, bool is_celebrating)
{
const enum tile_special_type spec_t = map_get_special(map_x, map_y);
@@ -908,7 +904,7 @@
Calculate the food the given tile is capable of producing for the
city.
**************************************************************************/
-int city_get_food_tile(int city_x, int city_y, struct city *pcity)
+int city_get_food_tile(int city_x, int city_y, const struct city *pcity)
{
return base_city_get_food_tile(city_x, city_y, pcity,
city_celebrating(pcity));
@@ -920,7 +916,7 @@
This can be used to calculate the benefits celebration would give.
**************************************************************************/
-int base_city_get_food_tile(int city_x, int city_y, struct city *pcity,
+int base_city_get_food_tile(int city_x, int city_y, const struct city *pcity,
bool is_celebrating)
{
int map_x, map_y;
@@ -968,7 +964,7 @@
See also can_establish_trade_route().
**************************************************************************/
-bool can_cities_trade(struct city *pc1, struct city *pc2)
+bool can_cities_trade(const struct city *pc1, const struct city *pc2)
{
return (pc1 && pc2 && pc1 != pc2
&& (pc1->owner != pc2->owner
@@ -980,7 +976,7 @@
trade route is returned and its position (slot) is put into the slot
variable.
**************************************************************************/
-int get_city_min_trade_route(struct city *pcity, int *slot)
+int get_city_min_trade_route(const struct city *pcity, int *slot)
{
int i, value = pcity->trade_value[0];
@@ -1006,7 +1002,7 @@
trade routes. Should only be called if you already know that
can_cities_trade().
**************************************************************************/
-bool can_establish_trade_route(struct city *pc1, struct city *pc2)
+bool can_establish_trade_route(const struct city *pc1, const struct city *pc2)
{
int trade = -1;
@@ -1041,7 +1037,7 @@
/**************************************************************************
...
**************************************************************************/
-int trade_between_cities(struct city *pc1, struct city *pc2)
+int trade_between_cities(const struct city *pc1, const struct city *pc2)
{
int bonus = 0;
@@ -1064,7 +1060,7 @@
/**************************************************************************
Return number of trade route city has
**************************************************************************/
-int city_num_trade_routes(struct city *pcity)
+int city_num_trade_routes(const struct city *pcity)
{
int i, n = 0;
@@ -1082,7 +1078,8 @@
Note if you trade with a city you already have a trade route with,
you'll only get 1/3 of this value.
**************************************************************************/
-int get_caravan_enter_city_trade_bonus(struct city *pc1, struct city *pc2)
+int get_caravan_enter_city_trade_bonus(const struct city *pc1,
+ const struct city *pc2)
{
int i, tb;
@@ -1106,7 +1103,7 @@
/**************************************************************************
Check if cities have an established trade route.
**************************************************************************/
-bool have_cities_trade_route(struct city *pc1, struct city *pc2)
+bool have_cities_trade_route(const struct city *pc1, const struct city *pc2)
{
int i;
@@ -1123,7 +1120,7 @@
Calculate amount of gold remaining in city after paying for buildings
and units.
*************************************************************************/
-int city_gold_surplus(struct city *pcity)
+int city_gold_surplus(const struct city *pcity)
{
bool asmiths = city_affected_by_wonder(pcity, B_ASMITHS);
int cost = 0;
@@ -1144,7 +1141,7 @@
(The Impr_Type_id should be an improvement, not a wonder.)
Note also: city_got_citywalls(), and server/citytools:city_got_barracks()
**************************************************************************/
-bool city_got_effect(struct city *pcity, Impr_Type_id id)
+bool city_got_effect(const struct city *pcity, Impr_Type_id id)
{
return city_got_building(pcity, id) || wonder_replacement(pcity, id);
}
@@ -1152,7 +1149,7 @@
/**************************************************************************
Whether a city has its own City Walls, or the same effect via a wonder.
**************************************************************************/
-bool city_got_citywalls(struct city *pcity)
+bool city_got_citywalls(const struct city *pcity)
{
if (city_got_building(pcity, B_CITY))
return TRUE;
@@ -1162,7 +1159,7 @@
/**************************************************************************
...
**************************************************************************/
-bool city_affected_by_wonder(struct city *pcity, Impr_Type_id id)
+bool city_affected_by_wonder(const struct city *pcity, Impr_Type_id id)
{
struct city *tmp;
if (!improvement_exists(id))
@@ -1232,7 +1229,7 @@
/**************************************************************************
...
**************************************************************************/
-bool city_happy(struct city *pcity)
+bool city_happy(const struct city *pcity)
{
return (pcity->ppl_happy[4] >= (pcity->size + 1) / 2 &&
pcity->ppl_unhappy[4] == 0 && pcity->ppl_angry[4] == 0);
@@ -1241,7 +1238,7 @@
/**************************************************************************
...
**************************************************************************/
-bool city_unhappy(struct city *pcity)
+bool city_unhappy(const struct city *pcity)
{
return (pcity->ppl_happy[4] <
pcity->ppl_unhappy[4] + 2 * pcity->ppl_angry[4]);
@@ -1250,7 +1247,7 @@
/**************************************************************************
...
**************************************************************************/
-bool base_city_celebrating(struct city *pcity)
+bool base_city_celebrating(const struct city *pcity)
{
return (pcity->size >= get_gov_pcity(pcity)->rapture_size
&& pcity->was_happy);
@@ -1259,7 +1256,7 @@
/**************************************************************************
cities celebrate only after consecutive happy turns
**************************************************************************/
-bool city_celebrating(struct city *pcity)
+bool city_celebrating(const struct city *pcity)
{
return base_city_celebrating(pcity) && city_happy(pcity);
}
@@ -1268,7 +1265,7 @@
.rapture is checked instead of city_celebrating() because this function is
called after .was_happy was updated.
**************************************************************************/
-bool city_rapture_grow(struct city *pcity)
+bool city_rapture_grow(const struct city *pcity)
{
struct government *g = get_gov_pcity(pcity);
@@ -1321,7 +1318,7 @@
/**************************************************************************
...
**************************************************************************/
-int citygov_free_shield(struct city *pcity, struct government *gov)
+int citygov_free_shield(const struct city *pcity, struct government *gov)
{
if (gov->free_shield == G_CITY_SIZE_FREE) {
return pcity->size;
@@ -1333,7 +1330,7 @@
/**************************************************************************
...
**************************************************************************/
-int citygov_free_happy(struct city *pcity, struct government *gov)
+int citygov_free_happy(const struct city *pcity, struct government *gov)
{
if (gov->free_happy == G_CITY_SIZE_FREE) {
return pcity->size;
@@ -1345,7 +1342,7 @@
/**************************************************************************
...
**************************************************************************/
-int citygov_free_food(struct city *pcity, struct government *gov)
+int citygov_free_food(const struct city *pcity, struct government *gov)
{
if (gov->free_food == G_CITY_SIZE_FREE) {
return pcity->size;
@@ -1357,7 +1354,8 @@
/**************************************************************************
...
**************************************************************************/
-static int citygov_free_gold(struct city *pcity, struct government *gov)
+static int inline citygov_free_gold(const struct city *pcity,
+ struct government *gov)
{
if (gov->free_gold == G_CITY_SIZE_FREE) {
return pcity->size;
@@ -1369,7 +1367,7 @@
/**************************************************************************
Evaluate which style should be used to draw a city.
**************************************************************************/
-int get_city_style(struct city *pcity)
+int get_city_style(const struct city *pcity)
{
return get_player_city_style(city_owner(pcity));
}
@@ -1458,8 +1456,8 @@
But only on the first switch that turn. Also, if ever change back to
original improvement class of this turn, restore lost production.
**************************************************************************/
-int city_change_production_penalty(struct city *pcity,
- int target, bool is_unit, bool apply_it)
+int city_change_production_penalty(const struct city *pcity,
+ int target, bool is_unit)
{
int shield_stock_after_adjustment;
enum production_class_type orig_class;
@@ -1510,9 +1508,6 @@
shield_stock_after_adjustment =
unpenalized_shields + penalized_shields / 2;
- if (apply_it) {
- pcity->shield_stock = shield_stock_after_adjustment;
- }
return shield_stock_after_adjustment;
}
@@ -1521,12 +1516,12 @@
Calculates the turns which are needed to build the requested
improvement in the city. GUI Independent.
**************************************************************************/
-int city_turns_to_build(struct city *pcity, int id, bool id_is_unit,
+int city_turns_to_build(const struct city *pcity, int id, bool id_is_unit,
bool include_shield_stock)
{
int city_shield_surplus = pcity->shield_surplus;
int city_shield_stock = include_shield_stock ?
- city_change_production_penalty(pcity, id, id_is_unit, FALSE) : 0;
+ city_change_production_penalty(pcity, id, id_is_unit) : 0;
int improvement_cost = id_is_unit ?
unit_build_shield_cost(id) : impr_build_shield_cost(id);
@@ -1548,7 +1543,7 @@
shrink in x turns. A positive value of x means the city will grow in
x turns.
**************************************************************************/
-int city_turns_to_grow(struct city *pcity)
+int city_turns_to_grow(const struct city *pcity)
{
if (pcity->food_surplus > 0) {
return (city_granary_size(pcity->size) - pcity->food_stock +
@@ -1639,8 +1634,8 @@
}
/**************************************************************************
-Return true iff a city exists within a city radius of the given location.
-may_be_on_center determines if a city at x,y counts
+ Return true iff a city exists within a city radius of the given
+ location. may_be_on_center determines if a city at x,y counts.
**************************************************************************/
bool city_exists_within_city_radius(int x, int y, bool may_be_on_center)
{
@@ -1676,9 +1671,9 @@
}
/**************************************************************************
-v 1.0j code was too rash, only first penalty now!
+ Give base number of content citizens in any city owner by pplayer.
**************************************************************************/
-static int content_citizens(struct player *pplayer)
+static inline int content_citizens(struct player *pplayer)
{
int cities = city_list_size(&pplayer->cities);
int content = game.unhappysize;
@@ -1687,10 +1682,11 @@
if (cities > basis) {
content--;
- if (step != 0)
+ if (step != 0) {
+ /* the first penalty is at (basis + 1) cities;
+ the next is at (basis + step + 1), _not_ (basis + step) */
content -= (cities - basis - 1) / step;
- /* the first penalty is at (basis + 1) cities;
- the next is at (basis + step + 1), _not_ (basis + step) */
+ }
}
return content;
}
@@ -1698,7 +1694,7 @@
/**************************************************************************
Return the factor (in %) by which the shield should be multiplied.
**************************************************************************/
-int get_city_shield_bonus(struct city *pcity)
+int get_city_shield_bonus(const struct city *pcity)
{
int shield_bonus = 100;
@@ -1723,7 +1719,7 @@
Return the factor (in %) by which the tax and luxury should be
multiplied.
**************************************************************************/
-int get_city_tax_bonus(struct city *pcity)
+int get_city_tax_bonus(const struct city *pcity)
{
int tax_bonus = 100;
@@ -1741,14 +1737,15 @@
}
/**************************************************************************
-...
+ Give the number of gold generated by buildings under "tithe" attribute
+ governments.
**************************************************************************/
-static int get_city_tithes_bonus(struct city *pcity)
+static inline int get_city_tithes_bonus(const struct city *pcity)
{
int tithes_bonus = 0;
- if (!government_has_flag
- (get_gov_pcity(pcity), G_CONVERT_TITHES_TO_MONEY)) {
+ if (!government_has_flag(get_gov_pcity(pcity),
+ G_CONVERT_TITHES_TO_MONEY)) {
return 0;
}
@@ -1769,7 +1766,7 @@
/**************************************************************************
Return the factor (in %) by which the science should be multiplied.
**************************************************************************/
-int get_city_science_bonus(struct city *pcity)
+int get_city_science_bonus(const struct city *pcity)
{
int science_bonus = 100;
@@ -1796,9 +1793,9 @@
}
/**************************************************************************
-calculate the incomes according to the taxrates and # of specialists.
+ Modify the incomes according to the taxrates and # of specialists.
**************************************************************************/
-static void set_tax_income(struct city *pcity)
+static inline void set_tax_income(struct city *pcity)
{
int sci, tax, lux, rate = pcity->trade_prod;
int sci_rest, tax_rest, lux_rest;
@@ -1912,9 +1909,9 @@
}
/**************************************************************************
-Modify the incomes according to various buildings.
+ Modify the incomes according to various buildings.
**************************************************************************/
-static void add_buildings_effect(struct city *pcity)
+static inline void add_buildings_effect(struct city *pcity)
{
/* this is the place to set them */
pcity->tax_bonus = get_city_tax_bonus(pcity);
@@ -1929,9 +1926,9 @@
}
/**************************************************************************
-...
+ ...
**************************************************************************/
-static void happy_copy(struct city *pcity, int i)
+static inline void happy_copy(struct city *pcity, int i)
{
pcity->ppl_angry[i + 1] = pcity->ppl_angry[i];
pcity->ppl_unhappy[i + 1] = pcity->ppl_unhappy[i];
@@ -1942,7 +1939,7 @@
/**************************************************************************
Create content, unhappy and angry citizens.
**************************************************************************/
-static void citizen_happy_size(struct city *pcity)
+static inline void citizen_happy_size(struct city *pcity)
{
/* Number of specialists in city */
int specialists = city_specialists(pcity);
@@ -1976,9 +1973,9 @@
}
/**************************************************************************
-...
+ Make citizens happy due to luxury.
**************************************************************************/
-static void citizen_happy_luxury(struct city *pcity)
+static inline void citizen_happy_luxury(struct city *pcity)
{
int x = pcity->luxury_total;
@@ -2011,10 +2008,9 @@
}
/**************************************************************************
-...
- Note Suffrage/Police is always dealt with elsewhere now --dwp
+ Make given number of citizens unhappy due to units in the field.
**************************************************************************/
-static void citizen_happy_units(struct city *pcity, int unhap)
+static inline void citizen_unhappy_units(struct city *pcity, int unhap)
{
while (unhap > 0 && pcity->ppl_content[3] > 0) {
pcity->ppl_content[3]--;
@@ -2037,9 +2033,9 @@
}
/**************************************************************************
-...
+ Make citizens content due to city improvements.
**************************************************************************/
-static void citizen_happy_buildings(struct city *pcity)
+static inline void citizen_content_buildings(struct city *pcity)
{
struct government *g = get_gov_pcity(pcity);
int faces = 0;
@@ -2068,22 +2064,12 @@
pcity->ppl_content[2]++;
faces--;
}
-/* no longer hijacking ppl_content[0]; seems no longer to be helpful -- Syela
*/
- /* TV doesn't make people happy just content...
-
- while (faces && pcity->ppl_content[2]) {
- pcity->ppl_content[2]--;
- pcity->ppl_happy[2]++;
- faces--;
- }
-
- */
}
/**************************************************************************
-...
+ Make citizens happy due to wonders.
**************************************************************************/
-static void citizen_happy_wonders(struct city *pcity)
+static inline void citizen_happy_wonders(struct city *pcity)
{
int bonus = 0;
@@ -2130,9 +2116,10 @@
}
/**************************************************************************
-...
+ Set food, tax, science and shields production to zero if city is in
+ revolt.
**************************************************************************/
-static void unhappy_city_check(struct city *pcity)
+static inline void unhappy_city_check(struct city *pcity)
{
if (city_unhappy(pcity)) {
pcity->food_surplus = MIN(0, pcity->food_surplus);
@@ -2142,22 +2129,21 @@
}
}
-
-
/**************************************************************************
-...
+ Calculate pollution.
**************************************************************************/
-static void set_pollution(struct city *pcity)
+static inline void set_pollution(struct city *pcity)
{
struct player *pplayer = city_owner(pcity);
pcity->pollution = pcity->shield_prod;
- if (city_got_building(pcity, B_RECYCLING))
+ if (city_got_building(pcity, B_RECYCLING)) {
pcity->pollution /= 3;
- else if (city_got_building(pcity, B_HYDRO) ||
- city_affected_by_wonder(pcity, B_HOOVER) ||
- city_got_building(pcity, B_NUCLEAR))
+ } else if (city_got_building(pcity, B_HYDRO) ||
+ city_affected_by_wonder(pcity, B_HOOVER) ||
+ city_got_building(pcity, B_NUCLEAR)) {
pcity->pollution /= 2;
+ }
if (!city_got_building(pcity, B_MASS)) {
pcity->pollution += (pcity->size *
@@ -2169,9 +2155,10 @@
}
/**************************************************************************
-...
+ Calculate food, trade and shields generated by a city, and set
+ associated variables.
**************************************************************************/
-static void set_food_trade_shields(struct city *pcity)
+static inline void set_food_trade_shields(struct city *pcity)
{
int i;
bool is_celebrating = base_city_celebrating(pcity);
@@ -2213,11 +2200,11 @@
}
/**************************************************************************
-...
+ Calculate upkeep costs.
**************************************************************************/
-static void city_support(struct city *pcity,
- void (*send_unit_info) (struct player *pplayer,
- struct unit *punit))
+static inline void city_support(struct city *pcity,
+ void (*send_unit_info) (struct player *pplayer,
+ struct unit *punit))
{
struct government *g = get_gov_pcity(pcity);
@@ -2312,7 +2299,7 @@
if (happy_cost > 0) {
adjust_city_free_cost(&free_happy, &happy_cost);
if (happy_cost > 0) {
- citizen_happy_units(pcity, happy_cost);
+ citizen_unhappy_units(pcity, happy_cost);
this_unit->unhappiness = happy_cost;
}
}
@@ -2366,7 +2353,7 @@
add_buildings_effect(pcity); /* marketplace, library wonders.. */
set_pollution(pcity);
citizen_happy_luxury(pcity); /* with our new found luxuries */
- citizen_happy_buildings(pcity); /* temple cathedral colosseum */
+ citizen_content_buildings(pcity); /* temple cathedral colosseum */
city_support(pcity, send_unit_info); /* manage settlers, and units */
citizen_happy_wonders(pcity); /* happy wonders & fundamentalism */
unhappy_city_check(pcity);
@@ -2408,9 +2395,10 @@
}
/**************************************************************************
- Corruption is halved during love the XXX days.
+ Give corruption generated by city. Corruption is halved during love
+ the XXX days.
**************************************************************************/
-int city_corruption(struct city *pcity, int trade)
+int city_corruption(const struct city *pcity, int trade)
{
struct government *g = get_gov_pcity(pcity);
struct city *capital;
@@ -2457,9 +2445,9 @@
}
/**************************************************************************
- Waste is corruption for shields
+ Give amount of waste generated by city. Waste is corruption for shields.
**************************************************************************/
-int city_waste(struct city *pcity, int shields)
+int city_waste(const struct city *pcity, int shields)
{
struct government *g = get_gov_pcity(pcity);
struct city *capital;
@@ -2496,9 +2484,9 @@
}
/**************************************************************************
-...
+ Give the number of specialists in a city.
**************************************************************************/
-int city_specialists(struct city *pcity)
+int city_specialists(const struct city *pcity)
{
int count = 0, i;
@@ -2512,7 +2500,7 @@
/**************************************************************************
...
**************************************************************************/
-int get_temple_power(struct city *pcity)
+int get_temple_power(const struct city *pcity)
{
struct player *p = city_owner(pcity);
int power = 1;
@@ -2526,7 +2514,7 @@
/**************************************************************************
...
**************************************************************************/
-int get_cathedral_power(struct city *pcity)
+int get_cathedral_power(const struct city *pcity)
{
struct player *p = city_owner(pcity);
int power = 3;
@@ -2543,7 +2531,7 @@
/**************************************************************************
...
**************************************************************************/
-int get_colosseum_power(struct city *pcity)
+int get_colosseum_power(const struct city *pcity)
{
struct player *p = city_owner(pcity);
int power = 3;
@@ -2614,7 +2602,7 @@
/**************************************************************************
Returns TRUE iff the city has set the given option.
**************************************************************************/
-bool is_city_option_set(struct city *pcity, enum city_options option)
+bool is_city_option_set(const struct city *pcity, enum city_options option)
{
return TEST_BIT(pcity->city_options, option);
}
Index: common/city.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/city.h,v
retrieving revision 1.148
diff -u -r1.148 city.h
--- common/city.h 13 Jun 2004 03:57:05 -0000 1.148
+++ common/city.h 14 Jun 2004 10:00:37 -0000
@@ -344,40 +344,40 @@
/* properties */
-struct player *city_owner(struct city *pcity);
-int city_population(struct city *pcity);
-int city_gold_surplus(struct city *pcity);
-int city_buy_cost(struct city *pcity);
-bool city_happy(struct city *pcity); /* generally use celebrating instead */
-bool city_unhappy(struct city *pcity); /* anarchy??? */
-bool base_city_celebrating(struct city *pcity);
-bool city_celebrating(struct city *pcity); /* love the king ??? */
-bool city_rapture_grow(struct city *pcity);
+struct player *city_owner(const struct city *pcity);
+int city_population(const struct city *pcity);
+int city_gold_surplus(const struct city *pcity);
+int city_buy_cost(const struct city *pcity);
+bool city_happy(const struct city *pcity); /* generally use celebrating
instead */
+bool city_unhappy(const struct city *pcity); /* anarchy??? */
+bool base_city_celebrating(const struct city *pcity);
+bool city_celebrating(const struct city *pcity); /* love the king
??? */
+bool city_rapture_grow(const struct city *pcity);
/* city related improvement and unit functions */
-bool city_has_terr_spec_gate(struct city *pcity, Impr_Type_id id);
-int improvement_upkeep(struct city *pcity, Impr_Type_id i);
-bool can_build_improvement(struct city *pcity, Impr_Type_id id);
-bool can_eventually_build_improvement(struct city *pcity, Impr_Type_id id);
-bool can_build_unit(struct city *pcity, Unit_Type_id id);
-bool can_build_unit_direct(struct city *pcity, Unit_Type_id id);
-bool can_eventually_build_unit(struct city *pcity, Unit_Type_id id);
-bool city_can_use_specialist(struct city *pcity, enum specialist_type type);
-bool city_got_building(struct city *pcity, Impr_Type_id id);
-bool city_affected_by_wonder(struct city *pcity, Impr_Type_id id);
-bool city_got_effect(struct city *pcity, Impr_Type_id id);
-bool city_got_citywalls(struct city *pcity);
-bool wonder_replacement(struct city *pcity, Impr_Type_id id);
-int city_change_production_penalty(struct city *pcity,
- int target, bool is_unit, bool apply_it);
-int city_turns_to_build(struct city *pcity, int id, bool id_is_unit,
+bool city_has_terr_spec_gate(const struct city *pcity, Impr_Type_id id);
+int improvement_upkeep(const struct city *pcity, Impr_Type_id i);
+bool can_build_improvement(const struct city *pcity, Impr_Type_id id);
+bool can_eventually_build_improvement(const struct city *pcity, Impr_Type_id
id);
+bool can_build_unit(const struct city *pcity, Unit_Type_id id);
+bool can_build_unit_direct(const struct city *pcity, Unit_Type_id id);
+bool can_eventually_build_unit(const struct city *pcity, Unit_Type_id id);
+bool city_can_use_specialist(const struct city *pcity, enum specialist_type
type);
+bool city_got_building(const struct city *pcity, Impr_Type_id id);
+bool city_affected_by_wonder(const struct city *pcity, Impr_Type_id id);
+bool city_got_effect(const struct city *pcity, Impr_Type_id id);
+bool city_got_citywalls(const struct city *pcity);
+bool wonder_replacement(const struct city *pcity, Impr_Type_id id);
+int city_change_production_penalty(const struct city *pcity,
+ int target, bool is_unit);
+int city_turns_to_build(const struct city *pcity, int id, bool id_is_unit,
bool include_shield_stock );
-int city_turns_to_grow(struct city *pcity);
+int city_turns_to_grow(const struct city *pcity);
/* textual representation of buildings */
-const char *get_impr_name_ex(struct city *pcity, Impr_Type_id id);
+const char *get_impr_name_ex(const struct city *pcity, Impr_Type_id id);
/* tile production functions */
@@ -400,37 +400,38 @@
void generate_city_map_indices(void);
/* shield on spot */
-int city_get_shields_tile(int city_x, int city_y, struct city *pcity);
+int city_get_shields_tile(int city_x, int city_y, const struct city *pcity);
int base_city_get_shields_tile(int city_x, int city_y,
- struct city *pcity, bool is_celebrating);
+ const struct city *pcity, bool is_celebrating);
/* trade on spot */
-int city_get_trade_tile(int city_x, int city_y, struct city *pcity);
+int city_get_trade_tile(int city_x, int city_y, const struct city *pcity);
int base_city_get_trade_tile(int city_x, int city_y,
- struct city *pcity, bool is_celebrating);
+ const struct city *pcity, bool is_celebrating);
/* food on spot */
-int city_get_food_tile(int city_x, int city_y, struct city *pcity);
+int city_get_food_tile(int city_x, int city_y, const struct city *pcity);
int base_city_get_food_tile(int city_x, int city_y,
- struct city *pcity, bool is_celebrating);
+ const struct city *pcity, bool is_celebrating);
void set_worker_city(struct city *pcity, int city_x, int city_y,
enum city_tile_type type);
-enum city_tile_type get_worker_city(struct city *pcity, int city_x,
+enum city_tile_type get_worker_city(const struct city *pcity, int city_x,
int city_y);
void get_worker_on_map_position(int map_x, int map_y,
enum city_tile_type *result_city_tile_type,
struct city **result_pcity);
-bool is_worker_here(struct city *pcity, int city_x, int city_y);
+bool is_worker_here(const struct city *pcity, int city_x, int city_y);
bool city_can_be_built_here(int x, int y, struct unit *punit);
/* trade functions */
-bool can_cities_trade(struct city *pc1, struct city *pc2);
-bool can_establish_trade_route(struct city *pc1, struct city *pc2);
-bool have_cities_trade_route(struct city *pc1, struct city *pc2);
-int trade_between_cities(struct city *pc1, struct city *pc2);
-int city_num_trade_routes(struct city *pcity);
-int get_caravan_enter_city_trade_bonus(struct city *pc1, struct city *pc2);
-int get_city_min_trade_route(struct city *pcity, int *slot);
+bool can_cities_trade(const struct city *pc1, const struct city *pc2);
+bool can_establish_trade_route(const struct city *pc1, const struct city *pc2);
+bool have_cities_trade_route(const struct city *pc1, const struct city *pc2);
+int trade_between_cities(const struct city *pc1, const struct city *pc2);
+int city_num_trade_routes(const struct city *pcity);
+int get_caravan_enter_city_trade_bonus(const struct city *pc1,
+ const struct city *pc2);
+int get_city_min_trade_route(const struct city *pcity, int *slot);
/* list functions */
struct city *city_list_find_id(struct city_list *This, int id);
@@ -439,12 +440,12 @@
int city_name_compare(const void *p1, const void *p2);
/* city free cost values depending on government: */
-int citygov_free_shield(struct city *pcity, struct government *gov);
-int citygov_free_happy(struct city *pcity, struct government *gov);
-int citygov_free_food(struct city *pcity, struct government *gov);
+int citygov_free_shield(const struct city *pcity, struct government *gov);
+int citygov_free_happy(const struct city *pcity, struct government *gov);
+int citygov_free_food(const struct city *pcity, struct government *gov);
/* city style functions */
-int get_city_style(struct city *pcity);
+int get_city_style(const struct city *pcity);
int get_player_city_style(struct player *plr);
int get_style_by_name(const char *);
int get_style_by_name_orig(const char *);
@@ -475,15 +476,15 @@
void (*send_unit_info) (struct player * pplayer,
struct unit * punit));
void adjust_city_free_cost(int *num_free, int *this_cost);
-int city_corruption(struct city *pcity, int trade);
-int city_waste(struct city *pcity, int shields);
-int city_specialists(struct city *pcity); /* elv+tax+scie */
-int get_temple_power(struct city *pcity);
-int get_cathedral_power(struct city *pcity);
-int get_colosseum_power(struct city *pcity);
-int get_city_tax_bonus(struct city *pcity);
-int get_city_shield_bonus(struct city *pcity);
-int get_city_science_bonus(struct city *pcity);
+int city_corruption(const struct city *pcity, int trade);
+int city_waste(const struct city *pcity, int shields);
+int city_specialists(const struct city *pcity); /*
elv+tax+scie */
+int get_temple_power(const struct city *pcity);
+int get_cathedral_power(const struct city *pcity);
+int get_colosseum_power(const struct city *pcity);
+int get_city_tax_bonus(const struct city *pcity);
+int get_city_shield_bonus(const struct city *pcity);
+int get_city_science_bonus(const struct city *pcity);
/* city creation / destruction */
struct city *create_city_virtual(struct player *pplayer, const int x,
@@ -491,7 +492,7 @@
void remove_city_virtual(struct city *pcity);
/* misc */
-bool is_city_option_set(struct city *pcity, enum city_options option);
+bool is_city_option_set(const struct city *pcity, enum city_options option);
void city_styles_alloc(int num);
void city_styles_free(void);
Index: common/government.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/government.c,v
retrieving revision 1.41
diff -u -r1.41 government.c
--- common/government.c 30 Jun 2003 20:53:24 -0000 1.41
+++ common/government.c 14 Jun 2004 10:00:38 -0000
@@ -165,7 +165,7 @@
/***************************************************************
...
***************************************************************/
-struct government *get_gov_pcity(struct city *pcity)
+struct government *get_gov_pcity(const struct city *pcity)
{
assert(pcity != NULL);
return get_gov_pplayer(city_owner(pcity));
Index: common/government.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/government.h,v
retrieving revision 1.27
diff -u -r1.27 government.h
--- common/government.h 25 May 2004 15:29:59 -0000 1.27
+++ common/government.h 14 Jun 2004 10:00:38 -0000
@@ -174,7 +174,7 @@
struct government *get_government(int gov);
struct government *get_gov_pplayer(struct player *pplayer);
-struct government *get_gov_pcity(struct city *pcity);
+struct government *get_gov_pcity(const struct city *pcity);
struct government *find_government_by_name(const char *name);
Index: common/improvement.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/improvement.c,v
retrieving revision 1.36
diff -u -r1.36 improvement.c
--- common/improvement.c 25 Feb 2004 20:23:49 -0000 1.36
+++ common/improvement.c 14 Jun 2004 10:00:38 -0000
@@ -241,9 +241,9 @@
Fills in lists of improvements at all impr_ranges that might affect the
given city (owned by the given player)
**************************************************************************/
-static void fill_ranges_improv_lists(Impr_Status *equiv_list[IR_LAST],
- struct city *pcity,
- struct player *pplayer)
+static inline void fill_ranges_improv_lists(Impr_Status *equiv_list[IR_LAST],
+ struct city *pcity,
+ struct player *pplayer)
{
int cont = 0;
enum impr_range i;
@@ -273,7 +273,7 @@
Checks whether the building is within the equiv_range of a building that
replaces it
**************************************************************************/
-bool improvement_redundant(struct player *pplayer,struct city *pcity,
+bool improvement_redundant(struct player *pplayer, const struct city *pcity,
Impr_Type_id id, bool want_to_build)
{
enum impr_range i;
@@ -281,7 +281,7 @@
Impr_Type_id *ept;
/* Make lists of improvements that affect this city */
- fill_ranges_improv_lists(equiv_list, pcity, pplayer);
+ fill_ranges_improv_lists(equiv_list, (struct city*)pcity, pplayer);
/* For every improvement named in equiv_dupl or equiv_repl, check for
its presence in any of the lists (we check only for its presence, and
Index: common/improvement.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/improvement.h,v
retrieving revision 1.23
diff -u -r1.23 improvement.h
--- common/improvement.h 25 Feb 2004 20:23:49 -0000 1.23
+++ common/improvement.h 14 Jun 2004 10:00:38 -0000
@@ -144,7 +144,7 @@
int improvement_variant(Impr_Type_id id);
bool improvement_obsolete(struct player *pplayer, Impr_Type_id id);
-bool improvement_redundant(struct player *pplayer,struct city *pcity,
+bool improvement_redundant(struct player *pplayer, const struct city *pcity,
Impr_Type_id id, bool want_to_build);
bool wonder_obsolete(Impr_Type_id id);
bool is_wonder_useful(Impr_Type_id id);
Index: server/citytools.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/citytools.c,v
retrieving revision 1.260
diff -u -r1.260 citytools.c
--- server/citytools.c 2 Jun 2004 19:47:42 -0000 1.260
+++ server/citytools.c 14 Jun 2004 10:00:38 -0000
@@ -1943,7 +1943,7 @@
/* Manage the city change-production penalty.
(May penalize, restore or do nothing to the shield_stock.) */
- city_change_production_penalty(pcity, target, is_unit, TRUE);
+ pcity->shield_stock = city_change_production_penalty(pcity, target, is_unit);
/* Change build target. */
pcity->currently_building = target;
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Freeciv-Dev] (PR#8982) City.c cleanup,
Per Inge Mathisen <=
|
|