Index: common/game.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/common/game.c,v retrieving revision 1.152 diff -u -r1.152 game.c --- common/game.c 14 Nov 2002 09:15:01 -0000 1.152 +++ common/game.c 25 Nov 2002 18:13:08 -0000 @@ -697,6 +697,7 @@ game.onsetbarbarian = GAME_DEFAULT_ONSETBARBARIAN; game.nbarbarians = 0; game.occupychance= GAME_DEFAULT_OCCUPYCHANCE; + game.autoattack = GAME_DEFAULT_AUTOATTACK; geff_vector_init(&game.effects); ceff_vector_init(&game.destroyed_effects); Index: common/game.h =================================================================== RCS file: /home/freeciv/CVS/freeciv/common/game.h,v retrieving revision 1.116 diff -u -r1.116 game.h --- common/game.h 11 Nov 2002 10:00:47 -0000 1.116 +++ common/game.h 25 Nov 2002 18:13:08 -0000 @@ -91,6 +91,7 @@ int onsetbarbarian; int nbarbarians; int occupychance; + bool autoattack; int unhappysize; bool angrycitizen; char *startmessage; @@ -428,6 +429,8 @@ #define GAME_DEFAULT_OCCUPYCHANCE 0 #define GAME_MIN_OCCUPYCHANCE 0 #define GAME_MAX_OCCUPYCHANCE 100 + +#define GAME_DEFAULT_AUTOATTACK FALSE #define GAME_DEFAULT_RULESETDIR "default" Index: server/stdinhand.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/server/stdinhand.c,v retrieving revision 1.265 diff -u -r1.265 stdinhand.c --- server/stdinhand.c 22 Nov 2002 17:44:45 -0000 1.265 +++ server/stdinhand.c 25 Nov 2002 18:13:09 -0000 @@ -513,6 +513,12 @@ GAME_MIN_OCCUPYCHANCE, GAME_MAX_OCCUPYCHANCE, GAME_DEFAULT_OCCUPYCHANCE) + GEN_BOOL("autoattack", game.autoattack, SSET_RULES_FLEXIBLE, SSET_TO_CLIENT, + N_("Turn on/off server-side autoattack"), + N_("If set to on, units with move left will automatically " + "attack enemy units that move adjacent to them."), NULL, + GAME_DEFAULT_AUTOATTACK) + GEN_INT("killcitizen", game.killcitizen, SSET_RULES, SSET_TO_CLIENT, N_("Reduce city population after attack"), N_("This flag indicates if city population is reduced " Index: server/unittools.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/server/unittools.c,v retrieving revision 1.197 diff -u -r1.197 unittools.c --- server/unittools.c 22 Nov 2002 17:44:45 -0000 1.197 +++ server/unittools.c 25 Nov 2002 18:13:10 -0000 @@ -2806,7 +2806,8 @@ } /***************************************************************** -Will wake up any neighboring enemy sentry units or patrolling units + Will wake up any neighboring enemy sentry units or patrolling + units or autoattacking units. *****************************************************************/ static void wakeup_neighbor_sentries(struct unit *punit) { @@ -2846,6 +2847,50 @@ (void) maybe_cancel_patrol_due_to_enemy(ppatrol); } } unit_list_iterate_end; + } square_iterate_end; + + /* Do server-side autoattack */ + square_iterate(punit->x, punit->y, 1, x, y) { + unit_list_iterate_safe(map_get_tile(x, y)->units, penemy) { + if (game.autoattack + && penemy->moves_left > 0 + && pplayers_at_war(unit_owner(punit), unit_owner(penemy)) + && map_get_known_and_seen(punit->x, punit->y, unit_owner(penemy)) + && player_can_see_unit(unit_owner(penemy), punit) + && can_unit_attack_unit_at_tile(penemy, punit, punit->x, punit->y)) { + int sanity1 = punit->id, sanity2 = penemy->id; + int move1 = punit->moves_left, move2 = penemy->moves_left; + double punitwin, penemywin; + + /* kludge to prevent attack power from dropping to zero during calc */ + punit->moves_left = 1; + penemy->moves_left = 1; + + punitwin = unit_win_chance(punit, penemy); + penemywin = unit_win_chance(penemy, punit); + punit->moves_left = move1; + penemy->moves_left = move2; + + freelog(LOG_DEBUG, "autoattack if %f < %f with %s -> %s at (%d, %d)", + punitwin, penemywin, unit_type(penemy)->name, + unit_type(punit)->name, punit->x, punit->y); + + if (penemywin > 1.0 - punitwin || unit_flag(punit, F_DIPLOMAT)) { + /* Yep, that's all there is to it! */ + (void) handle_unit_move_request(penemy, punit->x, + punit->y, FALSE, FALSE); + } + + if (find_unit_by_id(sanity2)) { + send_unit_info(NULL, penemy); + } + if (find_unit_by_id(sanity1)) { + send_unit_info(NULL, punit); + } else { + return; /* done, gone */ + } + } + } unit_list_iterate_safe_end; } square_iterate_end; }