diff -Nur -Xfreecivdiff.ignore freeciv-cvs/ai/advdomestic.c freeciv-patched/ai/advdomestic.c --- freeciv-cvs/ai/advdomestic.c 2003-07-10 11:53:38.000000000 +0100 +++ freeciv-patched/ai/advdomestic.c 2003-07-24 17:01:11.000000000 +0100 @@ -711,7 +711,7 @@ break; case B_LEONARDO: unit_list_iterate(pcity->units_supported, punit) { - Unit_Type_id unit_id = can_upgrade_unittype(pplayer, punit->type); + Unit_Type_id unit_id = can_upgrade_unittype(pplayer, punit->type, TRUE); if (unit_id >= 0) { /* this is probably wrong -- Syela */ j = 8 * unit_upgrade_price(pplayer, punit->type, unit_id); diff -Nur -Xfreecivdiff.ignore freeciv-cvs/ai/aicity.c freeciv-patched/ai/aicity.c --- freeciv-cvs/ai/aicity.c 2003-07-18 13:39:54.000000000 +0100 +++ freeciv-patched/ai/aicity.c 2003-07-24 17:01:11.000000000 +0100 @@ -321,7 +321,7 @@ { struct player *pplayer = city_owner(pcity); unit_list_iterate(map_get_tile(pcity->x, pcity->y)->units, punit) { - int id = can_upgrade_unittype(pplayer, punit->type); + int id = can_upgrade_unittype(pplayer, punit->type, TRUE); if (military && (!is_military_unit(punit) || !is_ground_unit(punit))) { /* Only upgrade military units this round */ continue; diff -Nur -Xfreecivdiff.ignore freeciv-cvs/client/gui-gtk/citydlg.c freeciv-patched/client/gui-gtk/citydlg.c --- freeciv-cvs/client/gui-gtk/citydlg.c 2003-07-10 11:53:38.000000000 +0100 +++ freeciv-patched/client/gui-gtk/citydlg.c 2003-07-24 17:01:11.000000000 +0100 @@ -2525,7 +2525,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_unittype(game.player_ptr, punit->type, TRUE) == -1) { message_dialog_button_set_sensitive(wd, "button6", FALSE); } } @@ -2679,7 +2679,7 @@ if ((punit = player_find_unit_by_id(game.player_ptr, (size_t) data))) { ut1 = punit->type; - ut2 = can_upgrade_unittype(game.player_ptr, ut1); + ut2 = can_upgrade_unittype(game.player_ptr, ut1, TRUE); if (ut2 == -1) { /* this shouldn't generally happen, but it is conceivable */ diff -Nur -Xfreecivdiff.ignore freeciv-cvs/client/gui-gtk/repodlgs.c freeciv-patched/client/gui-gtk/repodlgs.c --- freeciv-cvs/client/gui-gtk/repodlgs.c 2003-07-10 11:53:38.000000000 +0100 +++ freeciv-patched/client/gui-gtk/repodlgs.c 2003-07-24 17:01:11.000000000 +0100 @@ -891,7 +891,8 @@ void activeunits_list_callback(GtkWidget *w, gint row, gint column) { if ((unit_type_exists(activeunits_type[row])) && - (can_upgrade_unittype(game.player_ptr, activeunits_type[row]) != -1)) + (can_upgrade_unittype(game.player_ptr, + activeunits_type[row], TRUE) != -1)) gtk_widget_set_sensitive(upgrade_command, can_client_issue_orders()); } @@ -932,7 +933,7 @@ return; /* puts(unit_types[ut1].name); */ - ut2 = can_upgrade_unittype(game.player_ptr, activeunits_type[row]); + ut2 = can_upgrade_unittype(game.player_ptr, activeunits_type[row], TRUE); my_snprintf(buf, sizeof(buf), _("Upgrade as many %s to %s as possible for %d gold each?\n" @@ -1014,7 +1015,7 @@ memset(&unittotals, '\0', sizeof(unittotals)); unit_type_iterate(i) { if ((unitarray[i].active_count > 0) || (unitarray[i].building_count > 0)) { - can = (can_upgrade_unittype(game.player_ptr, i) != -1); + can = (can_upgrade_unittype(game.player_ptr, i, TRUE) != -1); my_snprintf(buf[0], sizeof(buf[0]), "%-27s", unit_name(i)); my_snprintf(buf[1], sizeof(buf[1]), "%c", can ? '*': '-'); my_snprintf(buf[2], sizeof(buf[2]), "%9d", unitarray[i].building_count); diff -Nur -Xfreecivdiff.ignore freeciv-cvs/client/gui-gtk-2.0/citydlg.c freeciv-patched/client/gui-gtk-2.0/citydlg.c --- freeciv-cvs/client/gui-gtk-2.0/citydlg.c 2003-07-10 11:53:38.000000000 +0100 +++ freeciv-patched/client/gui-gtk-2.0/citydlg.c 2003-07-24 17:01:11.000000000 +0100 @@ -2043,7 +2043,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_unittype(game.player_ptr, punit->type, TRUE) == -1) { gtk_widget_set_sensitive(item, FALSE); } @@ -2221,7 +2221,7 @@ if ((punit = player_find_unit_by_id(game.player_ptr, (size_t) data))) { ut1 = punit->type; - ut2 = can_upgrade_unittype(game.player_ptr, ut1); + ut2 = can_upgrade_unittype(game.player_ptr, ut1, TRUE); if (ut2 == -1) { /* this shouldn't generally happen, but it is conceivable */ diff -Nur -Xfreecivdiff.ignore freeciv-cvs/client/gui-gtk-2.0/repodlgs.c freeciv-patched/client/gui-gtk-2.0/repodlgs.c --- freeciv-cvs/client/gui-gtk-2.0/repodlgs.c 2003-07-10 11:53:38.000000000 +0100 +++ freeciv-patched/client/gui-gtk-2.0/repodlgs.c 2003-07-24 17:01:11.000000000 +0100 @@ -1001,7 +1001,8 @@ if (row < n-2 && unit_type_exists(activeunits_type[row]) && - can_upgrade_unittype(game.player_ptr, activeunits_type[row]) != -1) { + can_upgrade_unittype(game.player_ptr, + activeunits_type[row], TRUE) != -1) { gtk_widget_set_sensitive(upgrade_command, can_client_issue_orders()); } else { gtk_widget_set_sensitive(upgrade_command, FALSE); @@ -1030,7 +1031,7 @@ if (!unit_type_exists(ut1)) return; - ut2 = can_upgrade_unittype(game.player_ptr, activeunits_type[row]); + ut2 = can_upgrade_unittype(game.player_ptr, activeunits_type[row], TRUE); shell = gtk_message_dialog_new( GTK_WINDOW(activeunits_dialog_shell), @@ -1096,7 +1097,7 @@ unit_type_iterate(i) { if ((unitarray[i].active_count > 0) || (unitarray[i].building_count > 0)) { - can = (can_upgrade_unittype(game.player_ptr, i) != -1); + can = (can_upgrade_unittype(game.player_ptr, i, TRUE) != -1); gtk_list_store_append(activeunits_store, &it); gtk_list_store_set(activeunits_store, &it, diff -Nur -Xfreecivdiff.ignore freeciv-cvs/client/gui-mui/dialogs.c freeciv-patched/client/gui-mui/dialogs.c --- freeciv-cvs/client/gui-mui/dialogs.c 2003-07-21 13:58:23.000000000 +0100 +++ freeciv-patched/client/gui-mui/dialogs.c 2003-07-24 17:01:11.000000000 +0100 @@ -1794,7 +1794,7 @@ int value; ut1 = punit->type; - ut2 = can_upgrade_unittype(game.player_ptr,ut1); + ut2 = can_upgrade_unittype(game.player_ptr, ut1, TRUE); if (ut2 == -1) { diff -Nur -Xfreecivdiff.ignore freeciv-cvs/client/gui-mui/mapclass.c freeciv-patched/client/gui-mui/mapclass.c --- freeciv-cvs/client/gui-mui/mapclass.c 2003-07-10 11:53:38.000000000 +0100 +++ freeciv-patched/client/gui-mui/mapclass.c 2003-07-24 17:01:11.000000000 +0100 @@ -2962,7 +2962,7 @@ } } - if (can_upgrade_unittype(game.player_ptr,punit->type) != -1) + if (can_upgrade_unittype(game.player_ptr, punit->type, TRUE) != -1) { if ((entry = MUI_MakeObject(MUIO_Menuitem, _("Upgrade"), NULL, MUIO_Menuitem_CopyStrings, 0))) { diff -Nur -Xfreecivdiff.ignore freeciv-cvs/client/gui-mui/repodlgs.c freeciv-patched/client/gui-mui/repodlgs.c --- freeciv-cvs/client/gui-mui/repodlgs.c 2003-07-10 11:53:38.000000000 +0100 +++ freeciv-patched/client/gui-mui/repodlgs.c 2003-07-24 17:01:11.000000000 +0100 @@ -702,7 +702,7 @@ my_snprintf(building_count, sizeof(building_count), "%5d", entry->building_count); *array++ = unit_name(i); - *array++ = can_upgrade_unittype(game.player_ptr, i) != -1 ? "*" : "-"; + *array++ = can_upgrade_unittype(game.player_ptr, i, TRUE) != -1 ? "*" : "-"; *array++ = building_count; *array++ = active_count; *array++ = upkeep_shield; @@ -729,7 +729,7 @@ DoMethod(actunit_units_listview, MUIM_NList_GetEntry, *newval, &entry); if (entry) { - if (can_upgrade_unittype(game.player_ptr, entry->type) != -1) + if (can_upgrade_unittype(game.player_ptr, entry->type, TRUE) != -1) set(actunit_upgrade_button, MUIA_Disabled, FALSE); else set(actunit_upgrade_button, MUIA_Disabled, TRUE); @@ -758,7 +758,7 @@ int ut1, ut2; ut1 = entry->type; - ut2 = can_upgrade_unittype(game.player_ptr, entry->type); + ut2 = can_upgrade_unittype(game.player_ptr, entry->type, TRUE); if (ut2 != -1) { diff -Nur -Xfreecivdiff.ignore freeciv-cvs/client/gui-sdl/repodlgs.c freeciv-patched/client/gui-sdl/repodlgs.c --- freeciv-cvs/client/gui-sdl/repodlgs.c 2003-07-21 13:58:26.000000000 +0100 +++ freeciv-patched/client/gui-sdl/repodlgs.c 2003-07-24 17:01:11.000000000 +0100 @@ -194,7 +194,7 @@ pUnits_Upg_Dlg = MALLOC(sizeof(struct SMALL_DLG)); - ut2 = can_upgrade_unittype(game.player_ptr, ut1); + ut2 = can_upgrade_unittype(game.player_ptr, ut1, TRUE); value = unit_upgrade_price(game.player_ptr, ut1, ut2); my_snprintf(cBuf, sizeof(cBuf), @@ -453,7 +453,7 @@ count = 0; unit_type_iterate(i) { if ((units[i].active_count > 0) || (units[i].building_count > 0)) { - upgrade = (can_upgrade_unittype(game.player_ptr, i) != -1); + upgrade = (can_upgrade_unittype(game.player_ptr, i, TRUE) != -1); pUnit = get_unit_type(i); /* ----------- */ @@ -844,7 +844,7 @@ pBuf = pWidget; if ((units[i].active_count > 0) || (units[i].building_count > 0)) { if (i == MAX_ID - pBuf->ID) { -UPD: upgrade = (can_upgrade_unittype(game.player_ptr, i) != -1); +UPD: upgrade = (can_upgrade_unittype(game.player_ptr, i, TRUE) != -1); pBuf = pBuf->prev; if(upgrade) { pBuf->string16->forecol = sellect; diff -Nur -Xfreecivdiff.ignore freeciv-cvs/client/gui-win32/citydlg.c freeciv-patched/client/gui-win32/citydlg.c --- freeciv-cvs/client/gui-win32/citydlg.c 2003-07-10 11:53:39.000000000 +0100 +++ freeciv-patched/client/gui-win32/citydlg.c 2003-07-24 17:01:11.000000000 +0100 @@ -1559,7 +1559,7 @@ ut1=punit->type; /* printf("upgrade_callback for %s\n", unit_types[ut1].name); */ - ut2=can_upgrade_unittype(game.player_ptr,ut1); + ut2 = can_upgrade_unittype(game.player_ptr, ut1, TRUE); if (ut2==-1) { /* this shouldn't generally happen, but it is conceivable */ @@ -1669,7 +1669,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_unittype(game.player_ptr, punit->type, TRUE) == -1) { message_dialog_button_set_sensitive(wd,6, FALSE); } } diff -Nur -Xfreecivdiff.ignore freeciv-cvs/client/gui-win32/repodlgs.c freeciv-patched/client/gui-win32/repodlgs.c --- freeciv-cvs/client/gui-win32/repodlgs.c 2003-07-10 11:53:39.000000000 +0100 +++ freeciv-patched/client/gui-win32/repodlgs.c 2003-07-24 17:01:11.000000000 +0100 @@ -544,7 +544,7 @@ if (sel>=0) { if ((unit_type_exists(activeunits_type[sel])) && (can_upgrade_unittype(game.player_ptr, - activeunits_type[sel]) != -1)) + activeunits_type[sel], TRUE) != -1)) EnableWindow(GetDlgItem(activeunits_dlg,ID_MILITARY_UPGRADE), TRUE); else @@ -570,7 +570,8 @@ ut1 = activeunits_type[sel]; if (!(unit_type_exists (ut1))) break; - ut2=can_upgrade_unittype(game.player_ptr,activeunits_type[sel]); + ut2 = can_upgrade_unittype(game.player_ptr, + activeunits_type[sel], TRUE); my_snprintf(buf, sizeof(buf), _("Upgrade as many %s to %s as possible for %d gold each?\n" "Treasury contains %d gold."), @@ -649,7 +650,7 @@ unit_type_iterate(i) { if ((unitarray[i].active_count > 0) || (unitarray[i].building_count > 0)) { - can = (can_upgrade_unittype(game.player_ptr, i) != -1); + can = (can_upgrade_unittype(game.player_ptr, i, TRUE) != -1); my_snprintf(buf[0], sizeof(buf[0]), "%s", unit_name(i)); my_snprintf(buf[1], sizeof(buf[1]), "%c", can ? '*': '-'); my_snprintf(buf[2], sizeof(buf[2]), "%3d", unitarray[i].building_count); diff -Nur -Xfreecivdiff.ignore freeciv-cvs/client/gui-xaw/citydlg.c freeciv-patched/client/gui-xaw/citydlg.c --- freeciv-cvs/client/gui-xaw/citydlg.c 2003-07-18 13:40:03.000000000 +0100 +++ freeciv-patched/client/gui-xaw/citydlg.c 2003-07-24 17:01:11.000000000 +0100 @@ -1334,7 +1334,7 @@ if (punit->homecity == pcity->id) { XtSetSensitive(XtNameToWidget(wd, "*button5"), FALSE); } - if (can_upgrade_unittype(game.player_ptr,punit->type) == -1) { + if (can_upgrade_unittype(game.player_ptr, punit->type, TRUE) == -1) { XtSetSensitive(XtNameToWidget(wd, "*button6"), FALSE); } } @@ -2039,7 +2039,7 @@ ut1 = punit->type; /* printf("upgrade_callback for %s\n", unit_types[ut1].name); */ - ut2 = can_upgrade_unittype(game.player_ptr,ut1); + ut2 = can_upgrade_unittype(game.player_ptr, ut1, TRUE); if ( ut2 == -1 ) { /* this shouldn't generally happen, but it is conceivable */ diff -Nur -Xfreecivdiff.ignore freeciv-cvs/client/gui-xaw/repodlgs.c freeciv-patched/client/gui-xaw/repodlgs.c --- freeciv-cvs/client/gui-xaw/repodlgs.c 2003-07-10 11:53:39.000000000 +0100 +++ freeciv-patched/client/gui-xaw/repodlgs.c 2003-07-24 17:01:11.000000000 +0100 @@ -970,7 +970,8 @@ may_upgrade = ((inx != XAW_LIST_NONE) && (unit_type_exists (activeunits_type[inx])) && - (can_upgrade_unittype (game.player_ptr, activeunits_type[inx]) != -1)); + (can_upgrade_unittype (game.player_ptr, + activeunits_type[inx], TRUE) != -1)); XtSetSensitive (upgrade_command, may_upgrade); } @@ -1015,7 +1016,7 @@ /* puts(unit_types[ut1].name); */ ut2 = can_upgrade_unittype(game.player_ptr, - activeunits_type[ret->list_index]); + activeunits_type[ret->list_index], TRUE); my_snprintf(buf, sizeof(buf), _("Upgrade as many %s to %s as possible for %d gold each?\n" @@ -1110,7 +1111,7 @@ sizeof(activeunits_list_names[k]), "%-27s%c%9d%9d%9d%9d", unit_name(i), - can_upgrade_unittype(game.player_ptr, i) != -1 ? '*': '-', + can_upgrade_unittype(game.player_ptr, i, TRUE) != -1 ? '*': '-', unitarray[i].building_count, unitarray[i].active_count, unitarray[i].upkeep_shield, diff -Nur -Xfreecivdiff.ignore freeciv-cvs/common/unittype.c freeciv-patched/common/unittype.c --- freeciv-cvs/common/unittype.c 2003-07-24 16:58:28.000000000 +0100 +++ freeciv-patched/common/unittype.c 2003-07-24 17:01:11.000000000 +0100 @@ -321,15 +321,22 @@ /************************************************************************** ... **************************************************************************/ -int can_upgrade_unittype(struct player *pplayer, Unit_Type_id id) +int can_upgrade_unittype(struct player *pplayer, Unit_Type_id id, bool leap) { Unit_Type_id best_upgrade = -1; if (!can_player_build_unit_direct(pplayer, id)) return -1; - while (unit_type_exists(id = unit_types[id].obsoleted_by)) + + if (leap) { + while (unit_type_exists(id = unit_types[id].obsoleted_by)) + if (can_player_build_unit_direct(pplayer, id)) + best_upgrade = id; + } else { + id = unit_types[id].obsoleted_by; if (can_player_build_unit_direct(pplayer, id)) best_upgrade = id; + } return best_upgrade; } diff -Nur -Xfreecivdiff.ignore freeciv-cvs/common/unittype.h freeciv-patched/common/unittype.h --- freeciv-cvs/common/unittype.h 2003-07-24 16:58:28.000000000 +0100 +++ freeciv-patched/common/unittype.h 2003-07-24 17:01:11.000000000 +0100 @@ -221,7 +221,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_unittype(struct player *pplayer, Unit_Type_id id); +int can_upgrade_unittype(struct player *pplayer, Unit_Type_id id, bool leap); int unit_upgrade_price(const struct player * const pplayer, const Unit_Type_id from, const Unit_Type_id to); diff -Nur -Xfreecivdiff.ignore freeciv-cvs/server/unithand.c freeciv-patched/server/unithand.c --- freeciv-cvs/server/unithand.c 2003-07-21 13:58:28.000000000 +0100 +++ freeciv-patched/server/unithand.c 2003-07-24 17:01:11.000000000 +0100 @@ -158,7 +158,7 @@ { const Unit_Type_id from_unittype = packet->type; const Unit_Type_id to_unittype = can_upgrade_unittype(pplayer, - from_unittype); + from_unittype, TRUE); if (to_unittype == -1) { notify_player(pplayer, @@ -226,7 +226,7 @@ return; } from_unit = punit->type; - if((to_unit=can_upgrade_unittype(pplayer, punit->type)) == -1) { + if((to_unit=can_upgrade_unittype(pplayer, punit->type, TRUE)) == -1) { notify_player(pplayer, _("Game: Illegal package, can't upgrade %s (yet)."), unit_type(punit)->name); return; diff -Nur -Xfreecivdiff.ignore freeciv-cvs/server/unittools.c freeciv-patched/server/unittools.c --- freeciv-cvs/server/unittools.c 2003-07-24 17:00:39.000000000 +0100 +++ freeciv-patched/server/unittools.c 2003-07-24 17:01:11.000000000 +0100 @@ -217,42 +217,64 @@ } /*************************************************************************** -Do Leonardo's Workshop upgrade(s). Select unit to upgrade by random. --Zamar -Now be careful not to strand units at sea with the Workshop. --dwp + Possibly upgrade units belonging to the given player (restricted to the + given continent or city, if not -1 and NULL respectively) by applying the + effect pointed to by "iter" ****************************************************************************/ -static void handle_leonardo(struct player *pplayer) +static void handle_unit_upgrades(struct player *pplayer, int continent, + struct city *pcity, struct eff_iter *iter) { - int upgrade_type; - int leonardo_variant; - + enum effect_type eff_type; + Impr_Type_id impr; struct unit_list candidates; - int candidate_to_upgrade=-1; - - int i; - - leonardo_variant = improvement_variant(B_LEONARDO); - + int upgrade_all, upgrade_leap, i, candidate_to_upgrade = -1; + int upgrade_type; + Unit_Class_id uclass; + enum tile_special_type spec_t; + enum tile_terrain_type tile_t; + + assert(iter != NULL); + eff_type = iter->imeff->type; + impr = eff_iterator_get_improvement(iter); + + upgrade_all = (eff_type == EFT_UPGRADE_ALL_STEP + || eff_type == EFT_UPGRADE_ALL_LEAP); + upgrade_leap = (eff_type == EFT_UPGRADE_ONE_LEAP + || eff_type == EFT_UPGRADE_ALL_LEAP); + unit_list_init(&candidates); unit_list_iterate(pplayer->units, punit) { - if ((upgrade_type=can_upgrade_unittype(pplayer, punit->type))!=-1 && - !upgrade_would_strand(punit, upgrade_type)) + uclass = get_unit_class(punit); + tile_t = map_get_terrain(punit->x, punit->y); + spec_t = map_get_special(punit->x, punit->y); + + if (is_unit_terrain_affected(iter->imeff, uclass, tile_t, spec_t) && + (continent == -1 || + continent == map_get_continent(punit->x, punit->y)) && + (!pcity || pcity == map_get_city(punit->x, punit->y)) && + (upgrade_type = can_upgrade_unittype(pplayer, punit->type, + upgrade_leap)) != -1 && + !upgrade_would_strand(punit, upgrade_type)) { unit_list_insert(&candidates, punit); /* Potential candidate :) */ + } } unit_list_iterate_end; - + if (unit_list_size(&candidates) == 0) return; /* We have Leonardo, but nothing to upgrade! */ - - if (leonardo_variant == 0) + + if (!upgrade_all) { candidate_to_upgrade=myrand(unit_list_size(&candidates)); + } - i=0; + i=0; unit_list_iterate(candidates, punit) { - if (leonardo_variant != 0 || i == candidate_to_upgrade) { - upgrade_type=can_upgrade_unittype(pplayer, punit->type); + if ((upgrade_all || i == candidate_to_upgrade) && + myrand(100) < iter->imeff->amount) { + upgrade_type = can_upgrade_unittype(pplayer, punit->type, upgrade_leap); notify_player(pplayer, _("Game: %s has upgraded %s to %s%s."), - improvement_types[B_LEONARDO].name, + get_improvement_name(impr), unit_type(punit)->name, get_unit_type(upgrade_type)->name, get_location_str_in(pplayer, punit->x, punit->y)); @@ -261,11 +283,72 @@ } i++; } unit_list_iterate_end; - + unit_list_unlink_all(&candidates); } /*************************************************************************** +Do Leonardo's Workshop upgrade(s). Select unit to upgrade by random. --Zamar +Now be careful not to strand units at sea with the Workshop. --dwp +Use any active effects from rulesets. --bmw +****************************************************************************/ +static void handle_leonardo(struct player *pplayer) +{ + struct eff_iter iter; + bool *cont_done; + bool player_done = FALSE; + int this_cont; + + /* Since the effect may be restricted to a city, iterate over all cities + to find all such effect instances. Keep track of which Island- and + Player- range effects we pick up, though, so that we don't apply them + multiple times (these effects are shared by multiple cities) */ + cont_done = fc_calloc(map.num_continents + 1, sizeof(bool)); + city_list_iterate(pplayer->cities, pcity) { + + /* Don't mark the player/island as "done" until we've looked at all + effects (as multiple effects at each range are possible) */ + bool this_playerdone = FALSE, this_contdone = FALSE; + + this_cont = map_get_continent(pcity->x, pcity->y); + eff_iterator_impr_init(&iter, B_LAST, pcity, + (player_done && cont_done[this_cont]) ? NULL : pplayer); + while (eff_iterator_next(&iter)) { + switch(iter.imeff->type) { + case EFT_UPGRADE_ONE_STEP: case EFT_UPGRADE_ONE_LEAP: + case EFT_UPGRADE_ALL_STEP: case EFT_UPGRADE_ALL_LEAP: + switch(iter.imeff->range) { + case EFR_PLAYER: case EFR_WORLD: + if (!player_done) { + handle_unit_upgrades(pplayer, -1, NULL, &iter); + } + this_playerdone = TRUE; + break; + case EFR_ISLAND: + if (!cont_done[this_cont]) { + handle_unit_upgrades(pplayer, this_cont, NULL, &iter); + } + this_contdone = TRUE; + break; + case EFR_CITY: + handle_unit_upgrades(pplayer, -1, pcity, &iter); + break; + default: + break; + } + break; + default: + break; + } + } + player_done |= this_playerdone; + cont_done[this_cont] |= this_contdone; + } city_list_iterate_end; + + free(cont_done); +} + +/*************************************************************************** Select which unit is more important to refuel: It's more important to refuel plane which has less fuel. If those are equal then we refuel more valuable unit. @@ -421,8 +504,7 @@ void player_restore_units(struct player *pplayer) { /* 1) get Leonardo out of the way first: */ - if (player_owns_active_wonder(pplayer, B_LEONARDO)) - handle_leonardo(pplayer); + handle_leonardo(pplayer); unit_list_iterate(pplayer->units, punit) {