[Freeciv-Dev] Gold upkeep
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
This patch fixes the gold upkeep for units.
I don't know if the ai will cope with it and I don't know of to test that.
Remi
diff -u -r server.orig/cityturn.c server/cityturn.c
--- server.orig/cityturn.c 2003-06-01 06:57:59.000000000 +0200
+++ server/cityturn.c 2003-06-16 18:11:35.000000000 +0200
@@ -413,7 +413,9 @@
update_city_activity(pplayer, pcity);
city_list_iterate_end;
pplayer->ai.prev_gold = gold;
- if (gold-(gold-pplayer->economic.gold)*3<0) {
+ /* This test include the cost of the units because pay_for_units is called
+ * in update_city_activity */
+ if (gold-(gold-pplayer->economic.gold)*3<0) {
notify_player_ex(pplayer, -1, -1, E_LOW_ON_FUNDS,
_("Game: WARNING, we're LOW on FUNDS sire."));
}
@@ -1326,6 +1328,7 @@
pcity->airlift=FALSE;
update_tech(pplayer, pcity->science_total);
pplayer->economic.gold+=pcity->tax_total;
+ pay_for_units(pplayer, pcity);
pay_for_buildings(pplayer, pcity);
if(city_unhappy(pcity)) {
Seulement dans server: .deps
Seulement dans server: Makefile
Seulement dans server: Makefile.in
Seulement dans server: #unittools.c#
diff -u -r server.orig/unittools.c server/unittools.c
--- server.orig/unittools.c 2003-06-05 06:58:14.000000000 +0200
+++ server/unittools.c 2003-06-16 18:00:42.000000000 +0200
@@ -306,6 +306,49 @@
}
/***************************************************************************
+ Pay the cost of units of city pcity
+***************************************************************************/
+void pay_for_units(struct player *pplayer, struct city *pcity)
+{
+ struct government *pgov = get_gov_pplayer(pplayer);
+ int potential_gold = 0;
+ int free_pool, upkeep;
+
+ built_impr_iterate(pcity, pimpr) {
+ potential_gold += get_improvement_type(pimpr)->build_cost;
+ } built_impr_iterate_end;
+
+ free_pool = citygov_free_gold(pcity, pgov);
+
+ unit_list_iterate(pcity->units_supported, punit) {
+ upkeep = utype_gold_cost(unit_type(punit), pgov);
+
+ if (pplayer->economic.gold + potential_gold + free_pool < upkeep) {
+ /* We have really no gold more, even with selling improvements
+ * But normally, if we sell evrithing and disband units, that
+ * should (must) be ok */
+ assert(pplayer->economic.gold + potential_gold + free_pool >= 0);
+
+ notify_player_ex(pplayer, -1, -1, E_UNIT_LOST,
+ _("Not enough gold. %s disbanded"),
+ unit_type(punit)->name);
+ wipe_unit_safe(punit, &myiter);
+ }
+ else {
+ /* Gold can be negative but improvement will be sell after
+ * That's better to sell improvements than units because impr gives
+ * gold whereas units give only shields. Or should units with gold
+ * upkeep give gold when disbanded? */
+ free_pool -= upkeep;
+ }
+ } unit_list_iterate_end;
+
+ if (free_pool < 0) {
+ pplayer->economic.gold += free_pool;
+ }
+}
+
+/***************************************************************************
...
****************************************************************************/
static void refuel_air_units_from_carriers(struct player *pplayer)
diff -u -r server.orig/unittools.h server/unittools.h
--- server.orig/unittools.h 2003-06-05 06:58:14.000000000 +0200
+++ server/unittools.h 2003-06-16 18:21:58.000000000 +0200
@@ -47,7 +47,7 @@
void disband_stack_conflict_unit(struct unit *punit, bool verbose);
int get_watchtower_vision(struct unit *punit);
bool unit_profits_of_watchtower(struct unit *punit);
-
+void pay_for_units(struct player *pplayer, struct city *pcity);
/* creation/deletion/upgrading */
void upgrade_unit(struct unit *punit, Unit_Type_id to_unit);
Seulement dans common/aicore: .deps
Seulement dans common/aicore: Makefile
Seulement dans common/aicore: Makefile.in
diff -u -r common.orig/city.c common/city.c
--- common.orig/city.c 2003-05-14 06:58:01.000000000 +0200
+++ common/city.c 2003-06-16 18:55:17.000000000 +0200
@@ -906,17 +906,30 @@
}
/*************************************************************************
-Calculate amount of gold remaining in city after paying for buildings
+Calculate amount of gold remaining in city after paying for buildings and
+units
*************************************************************************/
int city_gold_surplus(struct city *pcity)
{
bool asmiths = city_affected_by_wonder(pcity, B_ASMITHS);
int cost=0;
+ struct government *gov = get_gov_pplayer(city_owner(pcity));
+ int free_pool;
+
+ free_pool = citygov_free_gold(pcity, gov);
built_impr_iterate(pcity, i) {
cost += improvement_upkeep_asmiths(pcity, i, asmiths);
} built_impr_iterate_end;
+ unit_list_iterate(pcity->units_supported, punit) {
+ free_pool -= utype_gold_cost(unit_type(punit), gov);
+ } unit_list_iterate_end;
+
+ if (free_pool < 0) {
+ cost -= free_pool;
+ }
+
return pcity->tax_total-cost;
}
@@ -1138,7 +1151,7 @@
/**************************************************************************
...
**************************************************************************/
-static int citygov_free_gold(struct city *pcity, struct government *gov)
+int citygov_free_gold(struct city *pcity, struct government *gov)
{
if (gov->free_gold == G_CITY_SIZE_FREE) {
return pcity->size;
diff -u -r common.orig/city.h common/city.h
--- common.orig/city.h 2003-05-14 06:58:01.000000000 +0200
+++ common/city.h 2003-06-15 20:26:19.000000000 +0200
@@ -410,6 +410,7 @@
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_gold(struct city *pcity, struct government *gov);
/* city style functions */
int get_city_style(struct city *pcity);
Seulement dans common: .deps
Seulement dans common: Makefile
Seulement dans common: Makefile.in
diff -u -r common.orig/unittype.h common/unittype.h
--- common.orig/unittype.h 2003-02-01 06:57:19.000000000 +0100
+++ common/unittype.h 2003-06-14 21:51:48.000000000 +0200
@@ -181,7 +181,7 @@
int happy_cost; /* unhappy people in home city */
int shield_cost; /* normal upkeep cost */
int food_cost; /* settler food cost */
- int gold_cost; /* gold upkeep (n/a now, maybe later) */
+ int gold_cost; /* gold upkeep (available now) */
int paratroopers_range; /* only valid for F_PARATROOPERS */
int paratroopers_mr_req;
- [Freeciv-Dev] Gold upkeep,
Remi <=
|
|