[Freeciv-Dev] Re: (PR#13642) New behaviour of upgrade
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: |
[Freeciv-Dev] Re: (PR#13642) New behaviour of upgrade |
From: |
"Alexander Sayenko" <sayenko@xxxxxxxxx> |
Date: |
Fri, 12 Aug 2005 05:24:13 -0700 |
Reply-to: |
bugs@xxxxxxxxxxx |
<URL: http://bugs.freeciv.org/Ticket/Display.html?id=13642 >
It seems that the patch has been finished. I have tested it with the
following clients: Xaw/Gtk/Gtk2. I have also made appropriate changes for
the Win32 client, but have not tested it.
Final summary:
- to upgrade a land unit, a city must have Barracks(II/III)
- to upgrade a sea unit, a city must have Port facility (Shipyard will
have the same effect)
- to upgrade a water unit, a city must have Airport
It is also reflected in the help text for these buildings.
TODO:
- if a unit cannot be upgraded due to the absence of some building, the
test_unit_upgrade() function returns UR_NO_TYPE; so, it can be changed to
a new constant UR_NO_BUILDING so that a server can send a correct message
to a client
Sincerely,
Sayenko Alexander
diff -ur -x '*.Po' -x Makefile -x 'config*' freeciv-2.0.4/ai/aicity.c
freeciv-2.0.4-upgrade/ai/aicity.c
--- freeciv-2.0.4/ai/aicity.c 2005-07-18 20:41:55.000000000 +0300
+++ freeciv-2.0.4-upgrade/ai/aicity.c 2005-08-11 13:17:53.000000000 +0300
@@ -770,7 +770,7 @@
{
struct player *pplayer = city_owner(pcity);
unit_list_iterate(pcity->tile->units, punit) {
- int id = can_upgrade_unittype(pplayer, punit->type);
+ int id = can_upgrade_unit(pplayer, punit, pcity);
if (military && (!is_military_unit(punit) || !is_ground_unit(punit))) {
/* Only upgrade military units this round */
continue;
diff -ur -x '*.Po' -x Makefile -x 'config*'
freeciv-2.0.4/client/gui-gtk/citydlg.c
freeciv-2.0.4-upgrade/client/gui-gtk/citydlg.c
--- freeciv-2.0.4/client/gui-gtk/citydlg.c 2004-09-29 05:24:19.000000000
+0300
+++ freeciv-2.0.4-upgrade/client/gui-gtk/citydlg.c 2005-08-12
14:24:55.000000000 +0300
@@ -2429,7 +2429,7 @@
if (punit->homecity == pcity->id) {
message_dialog_button_set_sensitive(wd, "button5", FALSE);
}
- if (can_upgrade_unittype(game.player_ptr, punit->type) == -1) {
+ if (can_upgrade_unit(game.player_ptr, punit, pcity) == -1) {
message_dialog_button_set_sensitive(wd, "button6", FALSE);
}
}
Only in freeciv-2.0.4-upgrade/client/gui-gtk: libguiclient.a
diff -ur -x '*.Po' -x Makefile -x 'config*'
freeciv-2.0.4/client/gui-gtk-2.0/citydlg.c
freeciv-2.0.4-upgrade/client/gui-gtk-2.0/citydlg.c
--- freeciv-2.0.4/client/gui-gtk-2.0/citydlg.c 2005-07-23 10:04:38.000000000
+0300
+++ freeciv-2.0.4-upgrade/client/gui-gtk-2.0/citydlg.c 2005-08-11
13:25:53.000000000 +0300
@@ -2012,7 +2012,7 @@
GINT_TO_POINTER(punit->id));
gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
- if (can_upgrade_unittype(game.player_ptr, punit->type) == -1) {
+ if (can_upgrade_unit(game.player_ptr, punit, pcity) == -1) {
gtk_widget_set_sensitive(item, FALSE);
}
diff -ur -x '*.Po' -x Makefile -x 'config*'
freeciv-2.0.4/client/gui-win32/citydlg.c
freeciv-2.0.4-upgrade/client/gui-win32/citydlg.c
--- freeciv-2.0.4/client/gui-win32/citydlg.c 2005-04-01 07:10:23.000000000
+0300
+++ freeciv-2.0.4-upgrade/client/gui-win32/citydlg.c 2005-08-12
14:26:18.000000000 +0300
@@ -1557,7 +1557,7 @@
if (punit->homecity == pcity->id) {
message_dialog_button_set_sensitive(wd,5, FALSE);
}
- if (can_upgrade_unittype(game.player_ptr,punit->type) == -1) {
+ if (can_upgrade_unit(game.player_ptr,punit,pcity) == -1) {
message_dialog_button_set_sensitive(wd,6, FALSE);
}
}
Only in freeciv-2.0.4-upgrade/client/gui-win32: citydlg.c~
diff -ur -x '*.Po' -x Makefile -x 'config*'
freeciv-2.0.4/client/gui-xaw/citydlg.c
freeciv-2.0.4-upgrade/client/gui-xaw/citydlg.c
--- freeciv-2.0.4/client/gui-xaw/citydlg.c 2005-04-01 07:10:24.000000000
+0300
+++ freeciv-2.0.4-upgrade/client/gui-xaw/citydlg.c 2005-08-12
14:25:39.000000000 +0300
@@ -1348,7 +1348,7 @@
if (punit->homecity == pcity->id) {
XtSetSensitive(XtNameToWidget(wd, "*button5"), FALSE);
}
- if (can_upgrade_unittype(game.player_ptr,punit->type) == -1) {
+ if (can_upgrade_unit(game.player_ptr,punit,pcity) == -1) {
XtSetSensitive(XtNameToWidget(wd, "*button6"), FALSE);
}
}
Only in freeciv-2.0.4/client/gui-xaw: Freeciv.h
diff -ur -x '*.Po' -x Makefile -x 'config*' freeciv-2.0.4/common/unit.c
freeciv-2.0.4-upgrade/common/unit.c
--- freeciv-2.0.4/common/unit.c 2005-06-18 01:09:44.000000000 +0300
+++ freeciv-2.0.4-upgrade/common/unit.c 2005-08-11 13:16:27.000000000 +0300
@@ -1817,24 +1817,37 @@
enum unit_upgrade_result test_unit_upgrade(struct unit *punit, bool is_free)
{
struct player *pplayer = unit_owner(punit);
- Unit_Type_id to_unittype = can_upgrade_unittype(pplayer, punit->type);
+ Unit_Type_id to_unittype = -1;
struct city *pcity;
int cost;
- if (to_unittype == -1) {
- return UR_NO_UNITTYPE;
+ if (is_free) {
+ if (can_upgrade_unittype (pplayer,punit->type) == -1)
+ return UR_NO_UNITTYPE;
}
+ /***************************************************************************
+ So, there is no Leonardo Workshop, we have to check that:
+ - a unit is in a city
+ - a city really can upgrade a unit, i.e. it has all the required buildings
+ - we have enough money
+ ***************************************************************************/
if (!is_free) {
+ pcity = map_get_city(punit->tile);
+ if (!pcity) {
+ return UR_NOT_IN_CITY;
+ }
+
+ to_unittype = can_upgrade_unit (pplayer,punit,pcity);
+ if (to_unittype == -1) {
+ return UR_NO_UNITTYPE;
+ }
+
cost = unit_upgrade_price(pplayer, punit->type, to_unittype);
if (pplayer->economic.gold < cost) {
return UR_NO_MONEY;
}
- pcity = map_get_city(punit->tile);
- if (!pcity) {
- return UR_NOT_IN_CITY;
- }
if (city_owner(pcity) != pplayer) {
/* TODO: should upgrades in allied cities be possible? */
return UR_NOT_CITY_OWNER;
diff -ur -x '*.Po' -x Makefile -x 'config*' freeciv-2.0.4/common/unittype.c
freeciv-2.0.4-upgrade/common/unittype.c
--- freeciv-2.0.4/common/unittype.c 2005-04-01 07:10:32.000000000 +0300
+++ freeciv-2.0.4-upgrade/common/unittype.c 2005-08-12 14:15:25.000000000
+0300
@@ -331,6 +331,49 @@
return NULL;
}
+
+int can_upgrade_unit (struct player *pplayer, struct unit *punit, struct city*
pcity)
+{
+ Unit_Type_id upgrade_id;
+
+ /* First, check that a player can really upgrade a unit*/
+ upgrade_id = can_upgrade_unittype (pplayer,punit->type);
+ if (upgrade_id == -1)
+ return -1;
+
+ if (pcity) {
+
+ /**************************************************************************
+ So, we determine the unit type and based on this we check whether a city
+ has the required buildings. It is done by using effects that the buildings
+ provide:
+ Ground unit: EFT_LAND_REGEN (Barracks, Barracks II, Barracks III)
+ Water unit: EFT_SEA_REGEN (Port Facility)
+ Air units: EFT_WATER_REGEN (Airport)
+
+ At the moment, we do not consider helicopters as they are not obsoleted by
+ any unit
+ **************************************************************************/
+ if (is_ground_unittype (punit->type)) {
+ if (!get_city_bonus (pcity,EFT_LAND_REGEN))
+ return -1;
+ }
+ else if (is_water_unit (punit->type)) {
+ if (!get_city_bonus (pcity,EFT_SEA_REGEN))
+ return -1;
+ }
+ else if (is_air_unittype(punit->type)) {
+ if (!get_city_bonus (pcity,EFT_AIR_REGEN))
+ return -1;
+ }
+ /* Unknown unit type, return the negative result */
+ else return -1;
+
+ }
+
+ return upgrade_id;
+}
+
/**************************************************************************
...
**************************************************************************/
Only in freeciv-2.0.4-upgrade/common: unittype.c~
diff -ur -x '*.Po' -x Makefile -x 'config*' freeciv-2.0.4/common/unittype.h
freeciv-2.0.4-upgrade/common/unittype.h
--- freeciv-2.0.4/common/unittype.h 2005-04-01 07:10:32.000000000 +0300
+++ freeciv-2.0.4-upgrade/common/unittype.h 2005-08-11 13:00:51.000000000
+0300
@@ -252,6 +252,7 @@
int utype_happy_cost(struct unit_type *ut, struct government *g);
int utype_gold_cost(struct unit_type *ut, struct government *g);
+int can_upgrade_unit (struct player *pplayer, struct unit *punit, struct city
*pcity);
int can_upgrade_unittype(struct player *pplayer, Unit_Type_id id);
int unit_upgrade_price(const struct player * const pplayer,
const Unit_Type_id from, const Unit_Type_id to);
diff -ur -x '*.Po' -x Makefile -x 'config*'
freeciv-2.0.4/data/default/buildings.ruleset
freeciv-2.0.4-upgrade/data/default/buildings.ruleset
--- freeciv-2.0.4/data/default/buildings.ruleset 2005-07-23
10:28:18.000000000 +0300
+++ freeciv-2.0.4-upgrade/data/default/buildings.ruleset 2005-08-12
14:56:23.000000000 +0300
@@ -169,7 +169,8 @@
sound = "b_airport"
sound_alt = "b_generic"
helptext = _("\
-Allows a city to produce veteran air units. Also, damaged air units\
+Allows a city to produce veteran air units and to upgrade units.\
+Also, damaged air units\
which stay in town for one full turn without moving are completely\
restored.\
\n\n\
@@ -265,6 +266,7 @@
defence strengths are increased by 50%. Also, damaged land units\
which stay in town for one full turn without moving are completely\
restored.\
+ Barracks also allows to upgrade a unit.
")
[building_barracks_ii]
@@ -297,6 +299,7 @@
defence strengths are increased by 50%. Also, damaged land units\
which stay in town for one full turn without moving are completely\
restored.\
+ Barracks II also allows to upgrade a unit.
")
[building_barracks_iii]
@@ -328,6 +331,7 @@
defence strengths are increased by 50%. Also, damaged land units\
which stay in town for one full turn without moving are completely\
restored.\
+ Barracks III also allows to upgrade a unit.
")
[building_cathedral]
@@ -888,7 +892,8 @@
sound = "b_port_facility"
sound_alt = "b_generic"
helptext = _("\
-Allows a city to build veteran sea units. Also, damaged sea units\
+Allows a city to build veteran sea units and to upgrade units.\
+Also, damaged sea units\
which stay in town for one full turn without moving are completely\
restored.\
")
Only in freeciv-2.0.4-upgrade/data/default: buildings.ruleset~
diff -ur -x '*.Po' -x Makefile -x 'config*' freeciv-2.0.4/server/unithand.c
freeciv-2.0.4-upgrade/server/unithand.c
--- freeciv-2.0.4/server/unithand.c 2005-04-01 07:19:35.000000000 +0300
+++ freeciv-2.0.4-upgrade/server/unithand.c 2005-08-11 13:22:18.000000000
+0300
@@ -165,7 +165,7 @@
if (get_unit_upgrade_info(buf, sizeof(buf), punit) == UR_OK) {
Unit_Type_id from_unit = punit->type;
- Unit_Type_id to_unit = can_upgrade_unittype(pplayer, punit->type);
+ Unit_Type_id to_unit = can_upgrade_unit(pplayer, punit,
map_get_city(punit->tile));
int cost = unit_upgrade_price(pplayer, punit->type, to_unit);
upgrade_unit(punit, to_unit, FALSE);
|
|