[Freeciv-Dev] PATCH: Fixing problems with traderoutes when a city chang
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: |
freeciv-dev@xxxxxxxxxxx |
Subject: |
[Freeciv-Dev] PATCH: Fixing problems with traderoutes when a city changes owner. |
From: |
Rizos Sakellariou <rizos@xxxxxxxxxxx> |
Date: |
Tue, 16 Feb 1999 19:29:12 -0600 (CST) |
The following patch fixes several problems with the traderoutes of
a city that changes owner. At the moment such a change is handled in
a way that leads to erroneous situations where other cities maintaining
a traderoute with this city may keep a traderoute with a non-existent
city or none at all (note that, in the change of conquest, the
conquered city will change its id number, but this is not updated in
the fields of cities having traderoutes with it), whereas the city
that changes owner will have its traderoutes reestablished properly.
In some other cases, the current code performs better than one
might expect because of the obvious mistake in remove_city():
for (o=0; o<4; o++)
remove_trade_route(pcity->trade[0], pcity->id);
--rizos
PS: Not sure how to handle the traderoutes in the case of cities
revolted in the civil war case... I'd suggest, in this case,
to remove all traderoutes of revolted cities... Any opinions?
----------------------------------------------------------------------
Files affected:
server/unithand.c
server/unitfunc.c
server/diplhand.c
server/cityhand.c
server/cityhand.h
#########################
--- unithand-orig.c Mon Feb 15 19:47:53 1999
+++ unithand.c Mon Feb 15 22:56:59 1999
@@ -1052,16 +1054,12 @@
make_partisans(pcity);
*pnewcity=*pcity;
remove_city(pcity);
- for (i=0;i<4;i++) {
- pc2=find_city_by_id(pnewcity->trade[i]);
- if (can_establish_trade_route(pnewcity, pc2))
- establish_trade_route(pnewcity, pc2);
- }
+
/* now set things up for the new owner */
-
- old_id = pnewcity->id;
+ old_id = pnewcity->id;
pnewcity->id=get_next_id_number();
+
add_city_to_cache(pnewcity);
for (i = 0; i < B_LAST; i++) {
if (is_wonder(i) && city_got_building(pnewcity, i))
@@ -1093,6 +1091,9 @@
}
}
}
+
+ if (city_num_trade_routes(pnewcity))
+ reestablish_city_trade_routes(pnewcity);
/* relocate workers of tiles occupied by enemy units */
city_check_workers(pplayer,pnewcity);
#########################
--- unitfunc-orig.c Sun Feb 14 05:31:53 1999
+++ unitfunc.c Mon Feb 15 23:30:30 1999
@@ -496,7 +496,11 @@
send_tile_info(0, pnewcity->x, pnewcity->y, TILE_KNOWN);
}
+ if (city_num_trade_routes(pnewcity))
+ reestablish_city_trade_routes(pnewcity);
+
city_check_workers(pplayer,pnewcity);
+ update_map_with_city_workers(pnewcity);
city_refresh(pnewcity);
initialize_infrastructure_cache(pnewcity);
send_city_info(0, pnewcity, 0);
#########################
--- diplhand-orig.c Thu Feb 11 03:13:31 1999
+++ diplhand.c Mon Feb 15 22:58:15 1999
@@ -192,6 +192,8 @@
remove_city(pcity); /* don't forget this! */
map_set_city(pnewcity->x, pnewcity->y, pnewcity);
+ if (city_num_trade_routes(pnewcity))
+ reestablish_city_trade_routes(pnewcity);
city_check_workers(pdest ,pnewcity);
update_map_with_city_workers(pnewcity);
city_refresh(pnewcity);
#########################
--- cityhand-orig.c Thu Feb 11 03:13:31 1999
+++ cityhand.c Tue Feb 16 01:05:20 1999
@@ -675,7 +675,7 @@
get_race_name_plural(game.players[pcity->owner].race),
pcity->name,pcity->x,pcity->y);
for (o=0; o<4; o++)
- remove_trade_route(pcity->trade[0], pcity->id);
+ remove_trade_route(pcity->trade[o], pcity->id);
packet.value=pcity->id;
for(o=0; o<game.nplayers; o++) /* dests */
send_packet_generic_integer(game.players[o].conn,
@@ -693,7 +693,8 @@
/**************************************************************************
-...
+The following has to be called every time a city, pcity, has changed
+owner to update the tile->worked pointer.
**************************************************************************/
void update_map_with_city_workers(struct city *pcity)
@@ -703,4 +704,22 @@
if (pcity->city_map[x][y] == C_TILE_WORKER)
set_worker_city(pcity, x, y, C_TILE_WORKER);
}
+}
+
+/**************************************************************************
+The following has to be called every time a city, pcity, has changed
+owner to update the city's traderoutes.
+**************************************************************************/
+
+void reestablish_city_trade_routes(struct city *pcity)
+{
+ int i;
+ struct city *oldtradecity;
+
+ for (i=0;i<4;i++) {
+ oldtradecity=find_city_by_id(pcity->trade[i]);
+ pcity->trade[i]=0;
+ if (can_establish_trade_route(pcity, oldtradecity))
+ establish_trade_route(pcity, oldtradecity);
+ }
}
#########################
--- cityhand-orig.h Tue Feb 16 04:50:27 1999
+++ cityhand.h Tue Feb 16 04:51:04 1999
@@ -45,7 +45,7 @@
void remove_trade_route(int c1, int c2);
void send_player_cities(struct player *pplayer);
void update_map_with_city_workers(struct city *pcity);
-
+void reestablish_city_trade_routes(struct city *pcity);
void handle_city_options(struct player *pplayer,
struct packet_generic_values *preq);
- [Freeciv-Dev] PATCH: Fixing problems with traderoutes when a city changes owner.,
Rizos Sakellariou <=
|
|