[Freeciv-Dev] Migrants
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
This is a funny patch! ;-)
It implements the migration of population between cities that overlap.
Thanks
PS: I'm posting this also on the forum.
diff -u -r -b -Xfreeciv-2.0.6/diff_ignore freeciv-2.0.6/server/cityturn.c
freeciv-2.0.6-migrate/server/cityturn.c
--- freeciv-2.0.6/server/cityturn.c 2005-08-31 22:29:16.000000000 +0200
+++ freeciv-2.0.6-migrate/server/cityturn.c 2005-10-24 18:06:00.000000000
+0200
@@ -1431,3 +1431,129 @@
remove_city(pcity);
return TRUE;
}
+
+/**************************************************************************
+ Helpful function to make a score of a city.
+
+ It computes the trade of the city, the production and the tiles of the city.
+**************************************************************************/
+static int city_score(struct city *pcity)
+{ int score = 0;
+
+ score = pcity->trade_prod + pcity->shield_prod;
+ score += 10 * pcity->size;
+ square_iterate(pcity->tile, 2, ptile) {
+ if (is_ocean(ptile->terrain)) {
+ score += 2;
+ }
+ } square_iterate_end;
+
+ built_impr_iterate(pcity, i) {
+ score += impr_build_shield_cost(i) * 2;
+ } built_impr_iterate_end;
+
+ if (find_palace(city_owner(pcity)) == pcity) {
+ score += score;
+ }
+
+ return score;
+}
+
+/**************************************************************************
+ Make the migrations between the cities that overlap.
+
+ Migrants go to the better city of both involved, the giver and the receiver.
+**************************************************************************/
+void make_city_migrations(struct player *pplayer)
+{ char city_name[100];
+
+ if ((game.turn % 5) > 0) {
+ return;
+ }
+
+ /* first we search for cities that overlap */
+ city_list_iterate(pplayer->cities, pcity) {
+ struct city *best_city = NULL;
+ int score_1 = city_score(pcity);
+ int best_score = 0;
+
+ square_iterate(pcity->tile, 2, ptile) {
+ struct city *acity = map_get_city(ptile);
+ if (acity) {
+ /* here we have two cities that overlap... */
+ int score_2 = city_score(acity);
+
+ /* inmigrate in cities of the same owner */
+ if (city_owner(acity) != pplayer) {
+ continue;
+ }
+
+ /* inmigrate in cities that can grow */
+ if (!city_can_grow_to(acity, acity->size + 1)) {
+ score_2 /= 4;
+ }
+
+ if ((score_2 > score_1) && (score_2 > best_score)) {
+ /* select the best! */
+ best_score = score_2;
+ best_city = acity;
+ }
+ }
+ } square_iterate_end;
+
+ /* do the migration */
+ if (best_score > 0) {
+ /* we copy the city name, maybe we disband it! */
+ sz_strlcpy(city_name, pcity->name);
+ if (city_can_grow_to(best_city, best_city->size + 1)) {
+ /* reduce size of giver */
+ if (pcity->size == 1) {
+ struct city *rcity = NULL;
+ /* find closest city other than pcity */
+ rcity = find_closest_owned_city(pplayer, best_city->tile, FALSE,
pcity);
+
+ if (rcity) {
+ transfer_city_units(pplayer, pplayer, &pcity->units_supported,
rcity, pcity, -1, TRUE);
+ remove_city(pcity);
+ } else {
+ notify_player(pplayer, _("Game: Migrants of %s cannot integrate in
%s "
+ "because you don't have another city around!"),
+ city_name, best_city->name);
+ notify_player_ex(pplayer, pcity->tile, E_NOEVENT,
+ _("Game: Migrants of %s cannot integrate
in %s "
+ "because you don't have another city
around!"),
+ city_name, best_city->name);
+ return;
+ }
+ } else {
+ city_reduce_size(pcity, 1);
+ city_refresh(pcity);
+ }
+ /* raise size of receiver city */
+ city_increase_size(best_city);
+ city_refresh(best_city);
+ /* message to the player */
+ notify_player(pplayer, _("Game: Migrants of %s integrated in %s "
+ "in search for a better life."),
+ city_name, best_city->name);
+ notify_player_ex(pplayer, best_city->tile, E_NOEVENT,
+ _("Game: Migrants of %s integrated in %s "
+ "in search for a better life."),
+ city_name, best_city->name);
+ } else {
+ /* protest! */
+ notify_player(pplayer, _("Game: Migrants of %s can't go to %s "
+ "because it needs an improvement to grow! "
+ "You are responsible for her poverty!"),
+ city_name, best_city->name);
+ notify_player_ex(pplayer, best_city->tile, E_NOEVENT,
+ _("Game: Migrants of %s can't go to %s "
+ "because it needs an improvement to grow! "
+ "You are responsible for her poverty!"),
+ city_name, best_city->name);
+ }
+ }
+
+ } city_list_iterate_end;
+
+}
diff -u -r -b -Xfreeciv-2.0.6/diff_ignore freeciv-2.0.6/server/cityturn.h
freeciv-2.0.6-migrate/server/cityturn.h
--- freeciv-2.0.6/server/cityturn.h 2004-09-03 06:22:37.000000000 +0200
+++ freeciv-2.0.6-migrate/server/cityturn.h 2005-10-24 13:30:27.000000000
+0200
@@ -38,4 +38,7 @@
void advisor_choose_build(struct player *pplayer, struct city *pcity);
void nullify_prechange_production(struct city *pcity);
+
+void make_city_migrations(struct player *pplayer);
+
#endif /* FC__CITYTURN_H */
Sólo en freeciv-2.0.6-migrate/server: .kdbgrc.civserver
diff -u -r -b -Xfreeciv-2.0.6/diff_ignore freeciv-2.0.6/server/srv_main.c
freeciv-2.0.6-migrate/server/srv_main.c
--- freeciv-2.0.6/server/srv_main.c 2005-09-20 20:10:11.000000000 +0200
+++ freeciv-2.0.6-migrate/server/srv_main.c 2005-10-24 12:19:11.000000000
+0200
@@ -633,6 +633,11 @@
summon_barbarians(); /* wild guess really, no idea where to put it, but
I want to give them chance to move their units */
+ freelog(LOG_DEBUG, "Season of migrations");
+ players_iterate(pplayer) {
+ make_city_migrations(pplayer);
+ } players_iterate_end;
+
update_environmental_upset(S_POLLUTION, &game.heating,
&game.globalwarming, &game.warminglevel,
global_warming);
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Freeciv-Dev] Migrants,
Jordi Negrevernis i Font <=
|
|