[Freeciv-Dev] (PR#14763) Forward port smaller changes from govt patch
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: |
[Freeciv-Dev] (PR#14763) Forward port smaller changes from govt patch |
From: |
"Per I. Mathisen" <per@xxxxxxxxxxx> |
Date: |
Mon, 16 Jan 2006 12:42:19 -0800 |
Reply-to: |
bugs@xxxxxxxxxxx |
<URL: http://bugs.freeciv.org/Ticket/Display.html?id=14763 >
I have split out what can easily be split out, and here is the patch. What
it does:
- Remove unnecessary gov parameters
- Fix comments
- Style stuff
- Add upkeep free feature of Anarchy to ruleset instead of code
- Remove hardcoded Anarchy penalty to incite cost
- Generalize the celebration message
- Add new event type "player settings"
- No longer require specialist req to be lowercase in ruleset
- Martial law each zero disables martial law, not martial law max zero
- Fix crashes in effects code if called in some functions before it is
initialized
I wish to commit this very soon.
- Per
Index: server/srv_main.c
===================================================================
--- server/srv_main.c (revision 11458)
+++ server/srv_main.c (working copy)
@@ -1916,7 +1917,7 @@
} players_iterate_end;
} else {
players_iterate(pplayer) {
- ai_data_init(pplayer); /* Initialize this at last moment */
+ ai_data_init(pplayer); /* Initialize this again to be sure */
} players_iterate_end;
}
Index: server/settlers.c
===================================================================
--- server/settlers.c (revision 11458)
+++ server/settlers.c (working copy)
@@ -790,8 +790,7 @@
static int unit_food_upkeep(struct unit *punit)
{
struct player *pplayer = unit_owner(punit);
- int upkeep = utype_upkeep_cost(unit_type(punit), pplayer,
- get_gov_pplayer(pplayer), O_FOOD);
+ int upkeep = utype_upkeep_cost(unit_type(punit), pplayer, O_FOOD);
if (punit->id != 0 && punit->homecity == 0)
upkeep = 0; /* thanks, Peter */
Index: server/cityturn.c
===================================================================
--- server/cityturn.c (revision 11458)
+++ server/cityturn.c (working copy)
@@ -990,11 +990,9 @@
static bool city_distribute_surplus_shields(struct player *pplayer,
struct city *pcity)
{
- struct government *g = get_gov_pplayer(pplayer);
-
if (pcity->surplus[O_SHIELD] < 0) {
unit_list_iterate_safe(pcity->units_supported, punit) {
- if (utype_upkeep_cost(unit_type(punit), pplayer, g, O_SHIELD) > 0
+ if (utype_upkeep_cost(unit_type(punit), pplayer, O_SHIELD) > 0
&& pcity->surplus[O_SHIELD] < 0
&& !unit_flag(punit, F_UNDISBANDABLE)) {
notify_player(pplayer, pcity->tile, E_UNIT_LOST,
@@ -1012,7 +1010,7 @@
* it! If we make it here all normal units are already disbanded, so only
* undisbandable ones remain. */
unit_list_iterate_safe(pcity->units_supported, punit) {
- int upkeep = utype_upkeep_cost(unit_type(punit), pplayer, g, O_SHIELD);
+ int upkeep = utype_upkeep_cost(unit_type(punit), pplayer, O_SHIELD);
if (upkeep > 0 && pcity->surplus[O_SHIELD] < 0) {
assert(unit_flag(punit, F_UNDISBANDABLE));
@@ -1261,14 +1259,15 @@
}
/**************************************************************************
-...
+ Pay for upkeep costs for all buildings, or sell them.
**************************************************************************/
static void pay_for_buildings(struct player *pplayer, struct city *pcity)
{
built_impr_iterate(pcity, i) {
- if (can_city_sell_building(pcity, i)
- && pplayer->government != game.government_when_anarchy) {
- if (pplayer->economic.gold - improvement_upkeep(pcity, i) < 0) {
+ if (can_city_sell_building(pcity, i)) {
+ int upkeep = improvement_upkeep(pcity, i);
+
+ if (pplayer->economic.gold - upkeep < 0) {
notify_player(pplayer, pcity->tile, E_IMP_AUCTIONED,
_("Can't afford to maintain %s in %s, "
"building sold!"),
@@ -1276,7 +1275,7 @@
do_sell_building(pplayer, pcity, i);
city_refresh(pcity);
} else
- pplayer->economic.gold -= improvement_upkeep(pcity, i);
+ pplayer->economic.gold -= upkeep;
}
} built_impr_iterate_end;
}
@@ -1323,7 +1322,6 @@
**************************************************************************/
int city_incite_cost(struct player *pplayer, struct city *pcity)
{
- struct government *g = get_gov_pcity(pcity);
struct city *capital;
int dist, size, cost;
@@ -1345,14 +1343,12 @@
} built_impr_iterate_end;
/* Stability bonuses */
- if (g != game.government_when_anarchy) {
- if (!city_unhappy(pcity)) {
- cost *= 2;
- }
- if (city_celebrating(pcity)) {
- cost *= 2;
- }
+ if (!city_unhappy(pcity)) {
+ cost *= 2;
}
+ if (city_celebrating(pcity)) {
+ cost *= 2;
+ }
/* City is empty */
if (unit_list_size(pcity->tile->units) == 0) {
@@ -1450,20 +1444,16 @@
if (city_build_stuff(pplayer, pcity)) {
if (city_celebrating(pcity)) {
pcity->rapture++;
- if (pcity->rapture == 1)
- notify_player(pplayer, pcity->tile, E_CITY_LOVE,
- _("We Love The %s Day celebrated in %s."),
- get_ruler_title(pplayer->government, pplayer->is_male,
- pplayer->nation),
- pcity->name);
- }
- else {
- if (pcity->rapture != 0)
- notify_player(pplayer, pcity->tile, E_CITY_NORMAL,
- _("We Love The %s Day canceled in %s."),
- get_ruler_title(pplayer->government, pplayer->is_male,
- pplayer->nation),
- pcity->name);
+ if (pcity->rapture == 1) {
+ notify_player(pplayer, pcity->tile, E_CITY_LOVE,
+ _("Wild celebrations in your honour in %s."),
+ pcity->name);
+ }
+ } else {
+ if (pcity->rapture != 0) {
+ notify_player(pplayer, pcity->tile, E_CITY_NORMAL,
+ _("Celebrations cancelled in %s."), pcity->name);
+ }
pcity->rapture=0;
}
pcity->was_happy=city_happy(pcity);
Index: server/plrhand.c
===================================================================
--- server/plrhand.c (revision 11458)
+++ server/plrhand.c (working copy)
@@ -122,7 +122,8 @@
/**************************************************************************
Murder a player in cold blood.
**************************************************************************/
-void kill_player(struct player *pplayer) {
+void kill_player(struct player *pplayer)
+{
bool palace;
pplayer->is_dying = FALSE; /* Can't get more dead than this. */
@@ -1468,7 +1469,6 @@
game.info.max_players = game.info.nplayers;
/* Split the resources */
-
cplayer->economic.gold = pplayer->economic.gold;
cplayer->economic.gold /= 2;
pplayer->economic.gold -= cplayer->economic.gold;
Index: data/stdsounds.soundspec
===================================================================
--- data/stdsounds.soundspec (revision 11458)
+++ data/stdsounds.soundspec (working copy)
@@ -258,5 +258,6 @@
;e_wonder_started = ""
;e_wonder_stopped = ""
;e_worklist = ""
+;e_player_settings = ""
;music_start = ""
Index: data/default/effects.ruleset
===================================================================
--- data/default/effects.ruleset (revision 11458)
+++ data/default/effects.ruleset (working copy)
@@ -93,6 +93,14 @@
"UnitClass", "Sea", "Local"
}
+[effect_anarchy_upkeep]
+name = "Upkeep_Free"
+value = 99
+reqs =
+ { "type", "name", "range"
+ "Gov", "Anarchy", "Player"
+ }
+
[effect_republic]
name = "Make_Content_Mil"
value = 1
Index: common/specialist.c
===================================================================
--- common/specialist.c (revision 11458)
+++ common/specialist.c (working copy)
@@ -68,7 +68,7 @@
Specialist_type_id find_specialist_by_name(const char *name)
{
specialist_type_iterate(sp) {
- if (strcmp(specialists[sp].name, name) == 0) {
+ if (mystrcasecmp(specialists[sp].name, name) == 0) {
return sp;
}
} specialist_type_iterate_end;
Index: common/unittype.c
===================================================================
--- common/unittype.c (revision 11458)
+++ common/unittype.c (working copy)
@@ -101,7 +101,7 @@
Returns the upkeep of a unit of this type under the given government.
**************************************************************************/
int utype_upkeep_cost(const struct unit_type *ut, struct player *pplayer,
- const struct government *g, Output_type_id otype)
+ Output_type_id otype)
{
int val = ut->upkeep[otype];
Index: common/unittype.h
===================================================================
--- common/unittype.h (revision 11458)
+++ common/unittype.h (working copy)
@@ -219,7 +219,7 @@
const char *get_units_with_flag_string(int flag);
int utype_upkeep_cost(const struct unit_type *ut, struct player *pplayer,
- const struct government *g, Output_type_id otype);
+ Output_type_id otype);
int utype_happy_cost(const struct unit_type *ut, const struct player *pplayer);
struct unit_type *can_upgrade_unittype(const struct player *pplayer,
Index: common/events.c
===================================================================
--- common/events.c (revision 11458)
+++ common/events.c (working copy)
@@ -139,6 +139,7 @@
GEN_EV(N_("Chat error messages"), E_CHAT_ERROR),
GEN_EV(N_("Connect/disconnect messages"), E_CONNECTION),
GEN_EV(N_("AI Debug messages"), E_AI_DEBUG),
+ GEN_EV(N_("Player settings"), E_PLAYER_SETTINGS),
GEN_EV_TERMINATOR
};
Index: common/city.c
===================================================================
--- common/city.c (revision 11458)
+++ common/city.c (working copy)
@@ -1953,7 +1946,6 @@
struct unit *punit))
{
struct player *plr = city_owner(pcity);
- struct government *g = get_gov_pcity(pcity);
int free_upkeep[O_COUNT];
int free_happy = get_city_bonus(pcity, EFT_MAKE_CONTENT_MIL);
@@ -1983,9 +1975,11 @@
/* military units in this city (need _not_ be home city) can make
unhappy citizens content
*/
- if (get_city_bonus(pcity, EFT_MARTIAL_LAW_MAX) > 0) {
+ if (get_city_bonus(pcity, EFT_MARTIAL_LAW_EACH) > 0) {
+ int max = get_city_bonus(pcity, EFT_MARTIAL_LAW_MAX);
+
unit_list_iterate(pcity->tile->units, punit) {
- if (pcity->martial_law < get_city_bonus(pcity, EFT_MARTIAL_LAW_MAX)
+ if ((pcity->martial_law < max || max == 0)
&& is_military_unit(punit)
&& punit->owner == pcity->owner) {
pcity->martial_law++;
@@ -2006,7 +2000,7 @@
int old_unhappiness = this_unit->unhappiness;
output_type_iterate(o) {
- upkeep_cost[o] = utype_upkeep_cost(ut, plr, g, o);
+ upkeep_cost[o] = utype_upkeep_cost(ut, plr, o);
old_upkeep[o] = this_unit->upkeep[o];
} output_type_iterate_end;
Index: common/events.h
===================================================================
--- common/events.h (revision 11458)
+++ common/events.h (working copy)
@@ -116,9 +116,10 @@
E_CHAT_ERROR, /* Chatline errors (bad syntax, etc.) */
E_CONNECTION, /* Messages about acquired or lost connections */
E_AI_DEBUG, /* AI debugging messages */
+ E_PLAYER_SETTINGS, /* taxes etc */
/*
* Note: If you add a new event, make sure you make a similar change
- * to the events array in client/options.c using GEN_EV and to
+ * to the events array in common/events.c using GEN_EV and to
* data/stdsounds.spec.
*/
E_LAST
Index: common/effects.c
===================================================================
--- common/effects.c (revision 11458)
+++ common/effects.c (working copy)
@@ -844,6 +844,10 @@
const struct output_type *poutput,
enum effect_type effect_type)
{
+ if (!initialized) {
+ return 0;
+ }
+
assert(pplayer != NULL);
assert(poutput != NULL);
assert(effect_type != EFT_LAST);
@@ -858,6 +862,10 @@
const struct output_type *poutput,
enum effect_type effect_type)
{
+ if (!initialized) {
+ return 0;
+ }
+
assert(pcity != NULL);
assert(poutput != NULL);
assert(effect_type != EFT_LAST);
@@ -871,6 +879,10 @@
int get_building_bonus(const struct city *pcity, Impr_type_id id,
enum effect_type effect_type)
{
+ if (!initialized) {
+ return 0;
+ }
+
assert(pcity != NULL && id != B_LAST);
return get_target_bonus_effects(NULL,
city_owner(pcity), pcity,
@@ -892,6 +904,10 @@
const struct unit_type *punittype,
enum effect_type effect_type)
{
+ if (!initialized) {
+ return 0;
+ }
+
assert(pplayer != NULL && ptile != NULL && punittype != NULL);
return get_target_bonus_effects(NULL,
pplayer, ptile->city, NULL, ptile,
@@ -903,6 +919,10 @@
**************************************************************************/
int get_unit_bonus(const struct unit *punit, enum effect_type effect_type)
{
+ if (!initialized) {
+ return 0;
+ }
+
assert(punit != NULL);
return get_target_bonus_effects(NULL,
unit_owner(punit),
@@ -922,6 +942,10 @@
const struct player *pplayer,
enum effect_type effect_type)
{
+ if (!initialized) {
+ return 0;
+ }
+
assert(pplayer != NULL);
return get_target_bonus_effects(plist,
pplayer, NULL, NULL,
@@ -940,6 +964,10 @@
const struct output_type *poutput,
enum effect_type effect_type)
{
+ if (!initialized) {
+ return 0;
+ }
+
assert(pcity != NULL);
return get_target_bonus_effects(plist,
city_owner(pcity), pcity, NULL,
@@ -956,6 +984,10 @@
int get_current_construction_bonus(const struct city *pcity,
enum effect_type effect_type)
{
+ if (!initialized) {
+ return 0;
+ }
+
if (!pcity->production.is_unit) {
Impr_type_id id = pcity->production.value;
int power = 0;
Index: ai/advdomestic.c
===================================================================
--- ai/advdomestic.c (revision 11458)
+++ ai/advdomestic.c (working copy)
@@ -139,8 +139,6 @@
struct ai_choice *choice)
{
struct ai_data *ai = ai_data_get(pplayer);
- /* Government of the player */
- struct government *gov = get_gov_pplayer(pplayer);
/* Unit type with certain role */
struct unit_type *unit_type;
@@ -152,7 +150,7 @@
if (unit_type
&& (pcity->id != ai->wonder_city || unit_type->pop_cost == 0)
&& pcity->surplus[O_FOOD] > utype_upkeep_cost(unit_type,
- pplayer, gov, O_FOOD)) {
+ pplayer, O_FOOD)) {
/* The worker want is calculated in settlers.c called from
* ai_manage_cities. The expand value is the % that the AI should
* value expansion (basically to handicap easier difficutly levels)
@@ -181,7 +179,7 @@
&& (pcity->id != ai->wonder_city
|| unit_type->pop_cost == 0)
&& pcity->surplus[O_FOOD] >= utype_upkeep_cost(unit_type,
- pplayer, gov, O_FOOD)) {
+ pplayer, O_FOOD)) {
/* founder_want calculated in aisettlers.c */
int want = pcity->ai.founder_want;
Index: ai/aitools.c
===================================================================
--- ai/aitools.c (revision 11458)
+++ ai/aitools.c (working copy)
@@ -1205,8 +1205,7 @@
sure whether it is fully general for all possible parameters/
combinations." --dwp
**********************************************************************/
-bool ai_assess_military_unhappiness(struct city *pcity,
- struct government *g)
+bool ai_assess_military_unhappiness(struct city *pcity)
{
int free_happy;
int unhap = 0;
Index: ai/aitools.h
===================================================================
--- ai/aitools.h (revision 11458)
+++ ai/aitools.h (working copy)
@@ -96,7 +96,7 @@
void ai_choose_role_unit(struct player *pplayer, struct city *pcity,
struct ai_choice *choice, int role, int want);
void ai_advisor_choose_building(struct city *pcity, struct ai_choice *choice);
-bool ai_assess_military_unhappiness(struct city *pcity, struct government *g);
+bool ai_assess_military_unhappiness(struct city *pcity);
bool ai_wants_no_science(struct player *pplayer);
Index: ai/advmilitary.c
===================================================================
--- ai/advmilitary.c (revision 11458)
+++ ai/advmilitary.c (working copy)
@@ -801,8 +801,7 @@
int orig_move_type = get_unit_type(best_choice->choice)->move_type;
int victim_count = 1;
int needferry = 0;
- bool unhap = ai_assess_military_unhappiness(pcity,
- get_gov_pplayer(pplayer));
+ bool unhap = ai_assess_military_unhappiness(pcity);
assert(orig_move_type == SEA_MOVING || orig_move_type == LAND_MOVING);
Index: ai/aiunit.c
===================================================================
--- ai/aiunit.c (revision 11458)
+++ ai/aiunit.c (working copy)
@@ -1298,7 +1298,7 @@
if (pcity && (punit->id == 0 || pcity->id == punit->homecity)) {
/* I would have thought unhappiness should be taken into account
* irrespectfully the city in which it will surface... GB */
- unhap = ai_assess_military_unhappiness(pcity, get_gov_pplayer(pplayer));
+ unhap = ai_assess_military_unhappiness(pcity);
}
move_rate = unit_move_rate(punit);
Index: client/repodlgs_common.c
===================================================================
--- client/repodlgs_common.c (revision 11458)
+++ client/repodlgs_common.c (working copy)
@@ -111,8 +111,7 @@
}
unit_type_iterate(unittype) {
- cost = utype_upkeep_cost(unittype, game.player_ptr,
- get_gov_pplayer(game.player_ptr), O_GOLD);
+ cost = utype_upkeep_cost(unittype, game.player_ptr, O_GOLD);
if (cost == 0) {
/* Short-circuit all of the following checks. */
|
|