[Freeciv-Dev] (PR#3402) away mode
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
This introduces a new AI difficulty mode: "Away". A player can only set
this for himself from the client prompt. It only needs CTRL_INFO to use.
The AI will not move any of your sentried or fortified units, change any
existing productions unless your city is seriously endangered, nor change
your government. Later, it will not allow you autoattack, and you will not
change diplomatic relations.
So after this, if you see a player changing to AI mode for a turn, and
_coincidentially_ in that turn govt is changed to Republic, you know that
player is up to no good.
This patch is needed for AI diplomacy patch.
- Per
Index: ai/aicity.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/aicity.c,v
retrieving revision 1.137
diff -u -r1.137 aicity.c
--- ai/aicity.c 27 Jan 2003 19:30:32 -0000 1.137
+++ ai/aicity.c 12 Feb 2003 20:55:11 -0000
@@ -176,6 +176,13 @@
init_choice(&bestchoice);
init_choice(&curchoice);
+ if (ai_handicap(pplayer, H_AWAY)
+ && game_next_year(pcity->turn_last_built) != game.year
+ && pcity->ai.urgency == 0) {
+ /* Don't change existing productions unless we have to. */
+ return;
+ }
+
if( is_barbarian(pplayer) ) { /* always build best attack unit */
Unit_Type_id i, iunit, bestunit = -1;
int bestattack = 0;
Index: ai/aihand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/aihand.c,v
retrieving revision 1.75
diff -u -r1.75 aihand.c
--- ai/aihand.c 29 Jan 2003 05:10:48 -0000 1.75
+++ ai/aihand.c 12 Feb 2003 20:55:11 -0000
@@ -320,6 +320,10 @@
int bonus = 0; /* in percentage */
int current_gov = pplayer->government;
+ if (ai_handicap(pplayer, H_AWAY)) {
+ return;
+ }
+
for (i = 0; i < game.government_count; i++) {
struct government *gov = &governments[i];
int val = 0;
Index: ai/aiunit.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/aiunit.c,v
retrieving revision 1.262
diff -u -r1.262 aiunit.c
--- ai/aiunit.c 10 Feb 2003 21:43:40 -0000 1.262
+++ ai/aiunit.c 12 Feb 2003 20:55:12 -0000
@@ -2664,6 +2664,14 @@
CHECK_UNIT(punit);
+ if ((punit->activity == ACTIVITY_SENTRY
+ || punit->activity == ACTIVITY_FORTIFIED)
+ && ai_handicap(pplayer, H_AWAY)) {
+ /* Don't move sentried or fortified units controlled by a player
+ * in away mode. */
+ return;
+ }
+
/* was getting a bad bug where a settlers caused a defender to leave home */
/* and then all other supported units went on DEFEND_HOME/goto */
ai_military_findjob(pplayer, punit);
Index: common/player.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/player.h,v
retrieving revision 1.93
diff -u -r1.93 player.h
--- common/player.h 10 Feb 2003 21:43:42 -0000 1.93
+++ common/player.h 12 Feb 2003 20:55:12 -0000
@@ -39,21 +39,18 @@
};
enum handicap_type {
- H_NONE=0, /* no handicaps */
- H_DIPLOMAT=1, /* can't build offensive diplomats */
- H_MAP=2, /* only knows map_get_known tiles */
- H_LIMITEDHUTS=4, /* Can get only 25 gold and barbs from huts */
- H_CITYBUILDINGS=8, /* doesn't know what buildings are in enemy cities */
- H_CITYUNITS=16, /* doesn't know what units are in enemy cities */
- H_DEFENSIVE=32, /* builds lots of defensive buildings without calculating
need */
- H_EXPERIMENTAL=64, /* enable experimental AI features (for testing) */
- H_SUB=128, /* doesn't know where subs may be lurking */
-/* below this point are milder handicaps that I can actually implement --
Syela */
- H_RATES=256, /* can't set its rates beyond government limits */
- H_TARGETS=512, /* can't target anything it doesn't know exists */
- H_HUTS=1024, /* doesn't know which unseen tiles have huts on them */
- H_FOG=2048, /* can't see through fog of war */
- H_NOPLANES=4096, /* doesn't build planes */
+ H_NONE = 0, /* No handicaps */
+ H_DIPLOMAT = 1, /* Can't build offensive diplomats */
+ H_AWAY = 2, /* Away mode */
+ H_LIMITEDHUTS = 4, /* Can get only 25 gold and barbs from huts */
+ H_DEFENSIVE = 8, /* Build defensive buildings without calculating need */
+ H_EXPERIMENTAL = 16,/* Enable experimental AI features (for testing) */
+ H_RATES = 32, /* Can't set its rates beyond government limits */
+ H_TARGETS = 64, /* Can't target anything it doesn't know exists */
+ H_HUTS = 128, /* Doesn't know which unseen tiles have huts on them */
+ H_FOG = 256, /* Can't see through fog of war */
+ H_NOPLANES = 512, /* Doesn't build air units */
+ H_MAP = 1024 /* Only knows map_get_known tiles */
};
struct player_economic {
Index: server/stdinhand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/stdinhand.c,v
retrieving revision 1.270
diff -u -r1.270 stdinhand.c
--- server/stdinhand.c 20 Jan 2003 15:44:28 -0000 1.270
+++ server/stdinhand.c 12 Feb 2003 20:55:13 -0000
@@ -70,6 +70,7 @@
static void show_list(struct connection *caller, char *arg);
static void show_connections(struct connection *caller);
static void set_ai_level(struct connection *caller, char *name, int level);
+static void set_away(struct connection *caller, char *name);
static void fix_command(struct connection *caller, char *str, int cmd_enum);
@@ -961,6 +962,7 @@
CMD_METASERVER,
CMD_AITOGGLE,
CMD_CREATE,
+ CMD_AWAY,
CMD_EASY,
CMD_NORMAL,
CMD_HARD,
@@ -1136,6 +1138,13 @@
N_("The 'create' command is only available before the game has "
"been started.")
},
+ {"away", ALLOW_INFO,
+ /* TRANS: translate text between <> only */
+ N_("away\n"
+ "away"),
+ N_("Set yourself in away mode. The AI will watch your back."),
+ N_("The AI will govern your nation but do minimal changes."),
+ },
{"easy", ALLOW_CTRL,
/* TRANS: translate text between <> only */
N_("easy\n"
@@ -1611,7 +1620,7 @@
***************************************************************/
static const char *name_of_skill_level(int level)
{
- const char *nm[11] = { "UNUSED", "UNKNOWN", "UNKNOWN", "easy",
+ const char *nm[11] = { "UNUSED", "away", "UNKNOWN", "easy",
"UNKNOWN", "normal", "UNKNOWN", "hard",
"UNKNOWN", "UNKNOWN", "experimental" };
@@ -1625,7 +1634,7 @@
static int handicap_of_skill_level(int level)
{
int h[11] = { -1,
- H_NONE,
+ H_AWAY,
H_NONE,
/* easy */ H_RATES | H_TARGETS | H_HUTS | H_NOPLANES
| H_DIPLOMAT | H_LIMITEDHUTS | H_DEFENSIVE,
@@ -2471,6 +2480,7 @@
static enum command_id cmd_of_level(int level)
{
switch(level) {
+ case 1 : return CMD_AWAY;
case 3 : return CMD_EASY;
case 5 : return CMD_NORMAL;
case 7 : return CMD_HARD;
@@ -2535,6 +2545,27 @@
}
/******************************************************************
+ Set user to away mode.
+******************************************************************/
+static void set_away(struct connection *caller, char *name)
+{
+ if (caller == NULL) {
+ cmd_reply(CMD_AWAY, caller, C_FAIL, _("This command is client only."));
+ } else if (name && strlen(name) > 0) {
+ notify_conn(&caller->self, _("Usage: away"));
+ } else if (!caller->player->ai.control) {
+ notify_conn(&game.est_connections, _("%s set to away mode."),
+ caller->player->name);
+ set_ai_level_directer(caller->player, 1);
+ caller->player->ai.control = TRUE;
+ } else {
+ notify_conn(&game.est_connections, _("%s returned to game."),
+ caller->player->name);
+ caller->player->ai.control = FALSE;
+ }
+}
+
+/******************************************************************
Print a summary of the settings and their values.
Note that most values are at most 4 digits, except seeds,
which we let overflow their columns, plus a sign character.
@@ -3201,6 +3232,9 @@
break;
case CMD_CREATE:
create_ai_player(caller,arg);
+ break;
+ case CMD_AWAY:
+ set_away(caller, arg);
break;
case CMD_EASY:
set_ai_level(caller, arg, 3);
- [Freeciv-Dev] (PR#3402) away mode,
Per I. Mathisen <=
|
|