[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: |
Thu, 11 Aug 2005 04:53:05 -0700 |
Reply-to: |
bugs@xxxxxxxxxxx |
<URL: http://bugs.freeciv.org/Ticket/Display.html?id=13642 >
Hi
Here is the corrected patch that uses effects EFT_AIR_REGEN,
EFT_SEA_REGEN, and EFT_WATER_REGEN. Besides, I have made a couple of minor
optimizations, so that the number of affected by the patch files is
significantly less (see my post to the ticket).
Sincerely,
Sayenko Alexander
>
> <URL: http://bugs.freeciv.org/Ticket/Display.html?id=13642 >
>
> This implementation (hard-coding the names of improvements) is
> unacceptable. You need to add a new improvement flag or effect.
>
> Aside from that I have no opinion on whether this rules change is good
> or not.
>
> -jason
>
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-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/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-11 14:38:30.000000000
+0300
@@ -331,6 +331,55 @@
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;
+
+ /**************************************************************************
+ Since there is Leonardo workshop, which allows to upgrade units regardless
+ of their location, check the value of pcity. If it is NULL, it means that
+ we have Leonardo Workshop and there is no need to check for the required
+ buildings.
+ **************************************************************************/
+ 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;
+}
+
/**************************************************************************
...
**************************************************************************/
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/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);
- [Freeciv-Dev] Re: (PR#13642) New behaviour of upgrade,
Alexander Sayenko <=
|
|