? ai/aidiplomat.c ? ai/aidiplomat.h Index: ai/Makefile.am =================================================================== RCS file: /home/freeciv/CVS/freeciv/ai/Makefile.am,v retrieving revision 1.11 diff -u -r1.11 Makefile.am --- ai/Makefile.am 2002/11/01 17:40:45 1.11 +++ ai/Makefile.am 2002/11/16 15:34:11 @@ -40,4 +40,6 @@ aitools.c \ aitools.h \ aiunit.c \ - aiunit.h + aiunit.h \ + aidiplomat.c \ + aidiplomat.h Index: ai/advmilitary.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/ai/advmilitary.c,v retrieving revision 1.120 diff -u -r1.120 advmilitary.c --- ai/advmilitary.c 2002/11/14 09:14:49 1.120 +++ ai/advmilitary.c 2002/11/16 15:34:12 @@ -31,6 +31,7 @@ #include "aiair.h" #include "aicity.h" +#include "aidiplomat.h" #include "aihand.h" #include "ailog.h" #include "aitools.h" @@ -1328,6 +1329,9 @@ freelog(LOG_DEBUG, "Assessed danger for %s = %d, Def = %d", pcity->name, danger, def); + ai_choose_diplomat_defensive(pplayer, pcity, choice, def); + + if (danger != 0) { /* otherwise might be able to wait a little longer to defend */ if (danger >= def) { if (urgency == 0) danger = 100; /* don't waste money otherwise */ @@ -1392,6 +1396,9 @@ choice->want); return; } + + /* Consider making an offensive diplomat */ + ai_choose_diplomat_offensive(pplayer, pcity, choice); /* Consider making a sea bodyguard */ unit_type = ai_choose_bodyguard(pcity, SEA_MOVING, L_DEFEND_GOOD); Index: ai/aiunit.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/ai/aiunit.c,v retrieving revision 1.229 diff -u -r1.229 aiunit.c --- ai/aiunit.c 2002/11/14 09:14:50 1.229 +++ ai/aiunit.c 2002/11/16 15:34:12 @@ -47,6 +47,7 @@ #include "advmilitary.h" #include "aiair.h" #include "aicity.h" +#include "aidiplomat.h" #include "aihand.h" #include "aitools.h" #include "aidata.h" @@ -54,7 +55,6 @@ #include "aiunit.h" -static void ai_manage_diplomat(struct player *pplayer, struct unit *pdiplomat); static void ai_manage_military(struct player *pplayer,struct unit *punit); static void ai_manage_caravan(struct player *pplayer, struct unit *punit); static void ai_manage_barbarian_leader(struct player *pplayer, @@ -2369,11 +2369,6 @@ if ((unit_flag(punit, F_DIPLOMAT)) || (unit_flag(punit, F_SPY))) { ai_manage_diplomat(pplayer, punit); - /* the right test if the unit is in a city and - there is no other diplomat it musn't move. - This unit is a bodyguard against enemy diplomats. - Right now I don't know how to use bodyguards! (17/12/98) (--NB) - */ return; } else if (unit_flag(punit, F_SETTLERS) ||unit_flag(punit, F_CITIES)) { @@ -2513,146 +2508,6 @@ } } while (base != -1); return FALSE; -} - -/************************************************************************** - If we are the only diplomat in a city, defend against enemy actions. - The passive defense is set by game.diplchance. The active defense is - to bribe units which end their move nearby. - Our next trick is to look for enemy units and cities on our continent. - If we find a city, we look first to establish an embassy. The - information gained this way is assumed to be more useful than anything - else we could do. Making this come true is for future code. -AJS -**************************************************************************/ -static void ai_manage_diplomat(struct player *pplayer, struct unit *pdiplomat) -{ - bool handicap, has_emb; - int continent, dist, rmd, oic, did; - struct packet_unit_request req; - struct packet_diplomat_action dact; - struct city *pcity, *ctarget; - struct tile *ptile; - struct unit *ptres; - - if (pdiplomat->activity != ACTIVITY_IDLE) - handle_unit_activity_request(pdiplomat, ACTIVITY_IDLE); - - pcity = map_get_city(pdiplomat->x, pdiplomat->y); - - if (pcity && count_diplomats_on_tile(pdiplomat->x, pdiplomat->y) == 1) { - /* We're the only diplomat in a city. Defend it. */ - if (pdiplomat->homecity != pcity->id) { - /* this may be superfluous, but I like it. -AJS */ - req.unit_id=pdiplomat->id; - req.city_id=pcity->id; - req.name[0]='\0'; - handle_unit_change_homecity(pplayer, &req); - } - } else { - if (pcity) { - /* - * More than one diplomat in a city: may try to bribe trespassers. - * We may want this to be a city_map_iterate, or a warmap distance - * check, but this will suffice for now. -AJS - */ - adjc_iterate(pcity->x, pcity->y, x, y) { - if (diplomat_can_do_action(pdiplomat, DIPLOMAT_BRIBE, x, y)) { - /* A lone trespasser! Seize him! -AJS */ - ptile = map_get_tile(x, y); - ptres = unit_list_get(&ptile->units, 0); - ptres->bribe_cost = unit_bribe_cost(ptres); - if (ptres->bribe_cost < - (pplayer->economic.gold - pplayer->ai.est_upkeep)) { - dact.diplomat_id = pdiplomat->id; - dact.target_id = ptres->id; - dact.action_type = DIPLOMAT_BRIBE; - handle_diplomat_action(pplayer, &dact); - return; - } - } - } - adjc_iterate_end; - } - /* - * We're wandering in the desert, or there is more than one diplomat - * here. Go elsewhere. - * First, we look for an embassy, to steal a tech, or for a city to - * subvert. Then we look for a city of our own without a defending - * diplomat. This may not prove to work so very well, but it's - * possible otherwise that all diplomats we ever produce are home - * guard, and that's kind of silly. -AJS, 20000130 - */ - ctarget = NULL; - dist=MAX(map.xsize, map.ysize); - continent=map_get_continent(pdiplomat->x, pdiplomat->y); - handicap = ai_handicap(pplayer, H_TARGETS); - players_iterate(aplayer) { - /* don't target ourselves or friendly players that we already - have embassies with */ - if ((!pplayers_at_war(pplayer, aplayer)) - && (player_has_embassy(pplayer, aplayer))) continue; - /* sneaky way of avoiding foul diplomat capture -AJS */ - has_emb=player_has_embassy(pplayer, aplayer) || pdiplomat->foul; - 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; - /* figure our incite cost */ - 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 < - pplayer->economic.gold - pplayer->ai.est_upkeep)) { - /* We have the closest enemy city so far on the same continent */ - ctarget = acity; - dist = rmd; - } - } - city_list_iterate_end; - } players_iterate_end; - - if (!ctarget) { - /* No enemy cities are useful. Check our own. -AJS */ - city_list_iterate(pplayer->cities, acy) - if (continent != map_get_continent(acy->x, acy->y)) continue; - if (count_diplomats_on_tile(acy->x, acy->y) == 0) { - ctarget=acy; - dist=real_map_distance(pdiplomat->x, pdiplomat->y, acy->x, acy->y); - /* keep dist's integrity, and we can use it later. -AJS */ - } - city_list_iterate_end; - } - if (ctarget) { - /* Otherwise, we just kinda sit here. -AJS */ - did = -1; - if ((dist == 1) && (pplayer->player_no != ctarget->owner)) { - dact.diplomat_id=pdiplomat->id; - dact.target_id=ctarget->id; - if (!pdiplomat->foul && diplomat_can_do_action(pdiplomat, - DIPLOMAT_EMBASSY, ctarget->x, ctarget->y)) { - did=pdiplomat->id; - dact.action_type=DIPLOMAT_EMBASSY; - handle_diplomat_action(pplayer, &dact); - } else if (ctarget->steal == 0 && diplomat_can_do_action(pdiplomat, - DIPLOMAT_STEAL, ctarget->x, ctarget->y)) { - did=pdiplomat->id; - dact.action_type=DIPLOMAT_STEAL; - handle_diplomat_action(pplayer, &dact); - } else if (diplomat_can_do_action(pdiplomat, DIPLOMAT_INCITE, - ctarget->x, ctarget->y)) { - did=pdiplomat->id; - dact.action_type=DIPLOMAT_INCITE; - handle_diplomat_action(pplayer, &dact); - } - } - if ((did < 0) || find_unit_by_id(did)) { - pdiplomat->goto_dest_x=ctarget->x; - pdiplomat->goto_dest_y=ctarget->y; - set_unit_activity(pdiplomat, ACTIVITY_GOTO); - (void) do_unit_goto(pdiplomat, GOTO_MOVE_ANY, FALSE); - } - } - } - return; } /************************************************************************* Index: ai/aiunit.h =================================================================== RCS file: /home/freeciv/CVS/freeciv/ai/aiunit.h,v retrieving revision 1.34 diff -u -r1.34 aiunit.h --- ai/aiunit.h 2002/03/21 20:57:29 1.34 +++ ai/aiunit.h 2002/11/16 15:34:12 @@ -24,6 +24,17 @@ */ #define POWER_DIVIDER (POWER_FACTOR * 3) +/* Simple military power macros */ +#define DEFENCE_POWER(punit) \ + (unit_type(punit)->defense_strength * unit_type(punit)->hp \ + * unit_type(punit)->firepower) +#define ATTACK_POWER(punit) \ + (unit_type(punit)->attack_strength * unit_type(punit)->hp \ + * unit_type(punit)->firepower) +#define IS_ATTACKER(punit) \ + (unit_type(aunit)->attack_strength > \ + unit_type(aunit)->transport_capacity) + struct player; struct city; struct unit; Index: common/city.h =================================================================== RCS file: /home/freeciv/CVS/freeciv/common/city.h,v retrieving revision 1.116 diff -u -r1.116 city.h --- common/city.h 2002/11/15 21:24:30 1.116 +++ common/city.h 2002/11/16 15:34:14 @@ -215,6 +215,9 @@ int invasion; /* who's coming to kill us, for attack co-ordination */ int attack, bcost; /* This is also for invasion - total power and value of * all units coming to kill us. */ + + /* Used by _other_ cities temporarily while assigning diplomat targets */ + bool already_considered_for_diplomat; }; struct city { Index: common/player.h =================================================================== RCS file: /home/freeciv/CVS/freeciv/common/player.h,v retrieving revision 1.85 diff -u -r1.85 player.h --- common/player.h 2002/11/07 18:55:25 1.85 +++ common/player.h 2002/11/16 15:34:14 @@ -40,7 +40,7 @@ enum handicap_type { H_NONE=0, /* no handicaps */ - H_RIGIDPROD=1, /* can't switch to/from building_unit without penalty */ + H_DIPLOMAT=1, /* can't build offensive diplomats */ H_MAP=2, /* only knows map_get_known tiles */ H_TECH=4, /* doesn't know what enemies have researched */ H_CITYBUILDINGS=8, /* doesn't know what buildings are in enemy cities */ Index: server/srv_main.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/server/srv_main.c,v retrieving revision 1.106 diff -u -r1.106 srv_main.c --- server/srv_main.c 2002/11/14 09:15:05 1.106 +++ server/srv_main.c 2002/11/16 15:34:14 @@ -2112,7 +2112,7 @@ send_all_info(&game.game_connections); lsend_packet_generic_empty(&game.est_connections, PACKET_THAW_HINT); - if(game.is_new_game) { + if (game.is_new_game) { init_new_game(); } Index: server/stdinhand.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/server/stdinhand.c,v retrieving revision 1.264 diff -u -r1.264 stdinhand.c --- server/stdinhand.c 2002/11/14 09:15:05 1.264 +++ server/stdinhand.c 2002/11/16 15:34:15 @@ -1627,9 +1627,10 @@ int h[11] = { -1, H_NONE, H_NONE, - H_RATES | H_TARGETS | H_HUTS | H_NOPLANES | H_DEFENSIVE, + H_RATES | H_TARGETS | H_HUTS | H_NOPLANES | H_DEFENSIVE + | H_DIPLOMAT, H_NONE, - H_RATES | H_TARGETS | H_HUTS, + H_RATES | H_TARGETS | H_HUTS | H_DIPLOMAT, H_NONE, H_NONE, H_NONE,