Index: ai/aiunit.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/ai/aiunit.c,v retrieving revision 1.221 diff -u -r1.221 aiunit.c --- ai/aiunit.c 2002/09/28 21:58:15 1.221 +++ ai/aiunit.c 2002/09/30 16:01:25 @@ -2593,10 +2593,8 @@ city_list_iterate(aplayer->cities, acity) if (handicap && !map_get_known(acity->x, acity->y, pplayer)) continue; if (continent != map_get_continent(acity->x, acity->y)) continue; - city_incite_cost(acity); /* figure our incite cost */ - oic = acity->incite_revolt_cost; - if (pplayer->player_no == acity->original) oic = oic / 2; + oic = city_incite_cost(pplayer, acity); rmd=real_map_distance(pdiplomat->x, pdiplomat->y, acity->x, acity->y); if (!ctarget || (dist > rmd)) { if (!has_emb || acity->steal == 0 || (oic < Index: server/citytools.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/server/citytools.c,v retrieving revision 1.190 diff -u -r1.190 citytools.c --- server/citytools.c 2002/09/23 15:00:56 1.190 +++ server/citytools.c 2002/09/30 16:01:26 @@ -1058,8 +1058,6 @@ city_refresh(pcity); - city_incite_cost(pcity); - /* Put vision back to normal, if fortress acted as a watchtower */ if (player_knows_techs_with_flag(pplayer, TF_WATCHTOWER) && map_has_special(x, y, S_FORTRESS)) { Index: server/cityturn.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/server/cityturn.c,v retrieving revision 1.196 diff -u -r1.196 cityturn.c --- server/cityturn.c 2002/09/27 12:32:45 1.196 +++ server/cityturn.c 2002/09/30 16:01:26 @@ -1179,18 +1179,19 @@ } /************************************************************************** - Sets the incite_revolt_cost field in the given city. + REMOVE ME **************************************************************************/ -void city_incite_cost(struct city *pcity) +static int city_incite_cost_old(struct city *pcity) { struct government *g = get_gov_pcity(pcity); struct city *capital; int dist; - + int incite_revolt_cost; + if (city_got_building(pcity, B_PALACE)) { - pcity->incite_revolt_cost = INCITE_IMPOSSIBLE_COST; + incite_revolt_cost = INCITE_IMPOSSIBLE_COST; } else { - pcity->incite_revolt_cost = city_owner(pcity)->economic.gold + 1000; + incite_revolt_cost = city_owner(pcity)->economic.gold + 1000; capital = find_palace(city_owner(pcity)); if (capital) { int tmp = map_distance(capital->x, capital->y, pcity->x, pcity->y); @@ -1205,15 +1206,109 @@ if (g->fixed_corruption_distance != 0) { dist = MIN(g->fixed_corruption_distance, dist); } - pcity->incite_revolt_cost /= (dist + 3); - pcity->incite_revolt_cost *= pcity->size; + incite_revolt_cost /= (dist + 3); + incite_revolt_cost *= pcity->size; if (city_unhappy(pcity)) { - pcity->incite_revolt_cost /= 2; + incite_revolt_cost /= 2; } if (unit_list_size(&map_get_tile(pcity->x,pcity->y)->units)==0) { - pcity->incite_revolt_cost /= 2; + incite_revolt_cost /= 2; } } + return incite_revolt_cost; +} + +/************************************************************************** + Returns the cost to incite a city. This depends on the size of the city, + the number of happy, unhappy and angry citizens, whether it is + celebrating, how close it is to the capital, how many units it has and + upkeeps, presence of courthouse and its buildings and wonders. +**************************************************************************/ +int city_incite_cost(struct player *pplayer, struct city *pcity) +{ + struct government *g = get_gov_pcity(pcity); + struct city *capital; + int dist, size, cost; + +int b = 0, u = 0, nod, gold; + + if (city_got_building(pcity, B_PALACE) + || city_celebrating(pcity)) { + return INCITE_IMPOSSIBLE_COST; + } + + /* Gold factor */ + cost = city_owner(pcity)->economic.gold + 1000; +gold = cost; + + unit_list_iterate(map_get_tile(pcity->x,pcity->y)->units, punit) { +u += unit_type(punit)->build_cost; + cost += unit_type(punit)->build_cost; + } unit_list_iterate_end; + + /* Buildings */ + built_impr_iterate(pcity, i) { + if (!is_wonder(i)) { +b += improvement_value(i); + cost += improvement_value(i); + } else { +b += improvement_value(i) * 2; + cost += improvement_value(i) * 2; + } + } built_impr_iterate_end; + + /* Stability bonuses */ + if (!city_unhappy(pcity) + && g->index != game.government_when_anarchy) { + cost *= 2; + } + + /* City is empty */ + if (unit_list_size(&map_get_tile(pcity->x,pcity->y)->units) == 0) { + cost /= 2; + } + + /* Buy back is cheap, conquered cities are also cheap */ + if (pcity->owner != pcity->original) { + if (pplayer->player_no == pcity->original) { + cost /= 2; /* 50% price reduction */ + } else { + cost = cost * 2 / 3; /* 33% price reduction */ + } + } + + /* Distance from capital */ + capital = find_palace(city_owner(pcity)); + if (capital) { + int tmp = map_distance(capital->x, capital->y, pcity->x, pcity->y); + dist = MIN(32, tmp); + } else { + /* No capital? Take max penalty! */ + dist = 32; + } + if (city_got_building(pcity, B_COURTHOUSE)) { + dist /= 4; + } + if (g->fixed_corruption_distance != 0) { + dist = MIN(g->fixed_corruption_distance, dist); + } + +nod = cost; + size = MAX(1, pcity->size + + pcity->ppl_happy[4] + - pcity->ppl_unhappy[4] + - pcity->ppl_angry[4] * 3); + cost *= size; + cost = cost / (dist + 3); + + freelog(LOG_NORMAL, "Cost to buy %s is %d (was %d) (dist %d) %s%s%s (%d, %d, %d, %d, %d)", + pcity->name, cost, city_incite_cost_old(pcity), dist, + city_unhappy(pcity) ? "unhappy, " : "", + pcity->original == pcity->owner ? "original owner, " : "conquered, ", + pcity->original == pplayer->player_no ? "was once ours, " : "", + gold, u, b, nod, size); + + return cost; } /************************************************************************** @@ -1329,7 +1424,6 @@ pcity->anarchy=0; } check_pollution(pcity); - city_incite_cost(pcity); send_city_info(NULL, pcity); if (pcity->anarchy>2 && government_has_flag(g, G_REVOLUTION_WHEN_UNHAPPY)) { Index: server/cityturn.h =================================================================== RCS file: /home/freeciv/CVS/freeciv/server/cityturn.h,v retrieving revision 1.26 diff -u -r1.26 cityturn.h --- server/cityturn.h 2002/04/12 13:50:57 1.26 +++ server/cityturn.h 2002/09/30 16:01:26 @@ -33,7 +33,7 @@ void send_city_turn_notifications(struct conn_list *dest, struct city *pcity); void begin_cities_turn(struct player *pplayer); void update_city_activities(struct player *pplayer); -void city_incite_cost(struct city *pcity); +int city_incite_cost(struct player *pplayer, struct city *pcity); void remove_obsolete_buildings_city(struct city *pcity, bool refresh); void remove_obsolete_buildings(struct player *pplayer); Index: server/diplomats.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/server/diplomats.c,v retrieving revision 1.30 diff -u -r1.30 diplomats.c --- server/diplomats.c 2002/08/07 11:21:51 1.30 +++ server/diplomats.c 2002/09/30 16:01:26 @@ -737,16 +737,8 @@ return; } - /* Update incite cost. */ - if (pcity->incite_revolt_cost == -1) { - freelog (LOG_ERROR, "Incite cost -1 in diplomat_incite by %s for %s", - pplayer->name, pcity->name); - city_incite_cost (pcity); - } - revolt_cost = pcity->incite_revolt_cost; - - /* Special deal for former owners! */ - if (pplayer->player_no == pcity->original) revolt_cost /= 2; + /* Get incite cost. */ + revolt_cost = city_incite_cost(pplayer, pcity); /* If player doesn't have enough gold, can't incite a revolt. */ if (pplayer->economic.gold < revolt_cost) { @@ -1117,6 +1109,9 @@ _("Game: Your %s has been eliminated defending" " against a %s in %s."), unit_name(punit->type), unit_name(pdiplomat->type), pcity->name); + notify_player_ex(pplayer, pcity->x, pcity->y, E_ENEMY_DIPLOMAT_FAILED, + _("Game: An enemy %s has been eliminated defending" + " %s."), unit_name(punit->type), pcity->name); wipe_unit_safe(punit, &myiter); } else { Index: server/savegame.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/server/savegame.c,v retrieving revision 1.92 diff -u -r1.92 savegame.c --- server/savegame.c 2002/09/27 12:32:47 1.92 +++ server/savegame.c 2002/09/30 16:01:27 @@ -878,8 +878,6 @@ map_set_city(pcity->x, pcity->y, pcity); - pcity->incite_revolt_cost = -1; /* flag value */ - city_list_insert_back(&plr->cities, pcity); } Index: server/unithand.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/server/unithand.c,v retrieving revision 1.234 diff -u -r1.234 unithand.c --- server/unithand.c 2002/09/27 12:32:48 1.234 +++ server/unithand.c 2002/09/30 16:01:27 @@ -235,8 +235,8 @@ struct packet_generic_integer *packet) { struct player *pplayer = pconn->player; - struct city *pcity=find_city_by_id(packet->value); - struct unit *punit=find_unit_by_id(packet->value); + struct city *pcity = find_city_by_id(packet->value); + struct unit *punit = find_unit_by_id(packet->value); struct packet_generic_values req; if (!pplayer) { @@ -244,18 +244,16 @@ conn_description(pconn)); return; } - if(pcity) { - city_incite_cost(pcity); - req.id=packet->value; - req.value1=pcity->incite_revolt_cost; - if(pplayer->player_no == pcity->original) req.value1/=2; + if (pcity) { + req.value1 = city_incite_cost(pplayer, pcity); + req.id = packet->value; send_packet_generic_values(pconn, PACKET_INCITE_COST, &req); return; } - if(punit) { + if (punit) { punit->bribe_cost = unit_bribe_cost(punit); - req.id=packet->value; - req.value1=punit->bribe_cost; + req.id = packet->value; + req.value1 = punit->bribe_cost; send_packet_generic_values(pconn, PACKET_INCITE_COST, &req); } }