Author: cazfi Date: Sun Sep 25 08:25:58 2016 New Revision: 33881 URL: http://svn.gna.org/viewcvs/freeciv?rev=33881&view=rev Log: Added aicmd command.
Patch by Matthias Pfafferodt <syntron> and myself See patch #2969 Modified: trunk/common/ai.h trunk/doc/README.AI_modules trunk/server/commands.c trunk/server/commands.h trunk/server/stdinhand.c Modified: trunk/common/ai.h URL: http://svn.gna.org/viewcvs/freeciv/trunk/common/ai.h?rev=33881&r1=33880&r2=33881&view=diff ============================================================================== --- trunk/common/ai.h (original) +++ trunk/common/ai.h Sun Sep 25 08:25:58 2016 @@ -24,7 +24,7 @@ * structure below. When changing mandatory capability part, check that * there's enough reserved_xx pointers in the end of the structure for * taking to use without need to bump mandatory capability again. */ -#define FC_AI_MOD_CAPSTR "+Freeciv-3.0-ai-module-2016.Aug.05" +#define FC_AI_MOD_CAPSTR "+Freeciv-3.0-ai-module-2016.Sep.23" /* Timers for all AI activities. Define it to get statistics about the AI. */ #ifdef FREECIV_DEBUG @@ -89,6 +89,9 @@ * with each other player as parameter. */ void (*player_load_relations)(struct player *pplayer, struct player *other, const struct section_file *file, int plrno); + + /* AI console. */ + void (*player_console)(struct player *pplayer, const char *cmd); /* Called for AI type that gains control of player. */ void (*gained_control)(struct player *pplayer); Modified: trunk/doc/README.AI_modules URL: http://svn.gna.org/viewcvs/freeciv/trunk/doc/README.AI_modules?rev=33881&r1=33880&r2=33881&view=diff ============================================================================== --- trunk/doc/README.AI_modules (original) +++ trunk/doc/README.AI_modules Sun Sep 25 08:25:58 2016 @@ -119,6 +119,7 @@ New in Freeciv 3.0: ------------------- - Added 'private' pointer for ai module to store data of its own +- Added 'player_console', called when user enter aicmd New in Freeciv 2.6: Modified: trunk/server/commands.c URL: http://svn.gna.org/viewcvs/freeciv/trunk/server/commands.c?rev=33881&r1=33880&r2=33881&view=diff ============================================================================== --- trunk/server/commands.c (original) +++ trunk/server/commands.c Sun Sep 25 08:25:58 2016 @@ -660,6 +660,14 @@ "delegation status."), NULL, CMD_ECHO_NONE, VCF_NONE, 0 }, + {"aicmd", ALLOW_ADMIN, + /* TRANS: translate text between <> only */ + N_("aicmd <player> <command>"), + N_("Execute AI command"), + N_("Execute a command in the context of the AI for the given player"), + NULL, + CMD_ECHO_ADMINS, VCF_NONE, 0 + }, {"fcdb", ALLOW_ADMIN, /* TRANS: translate text between <> only */ N_("fcdb reload\n" Modified: trunk/server/commands.h URL: http://svn.gna.org/viewcvs/freeciv/trunk/server/commands.h?rev=33881&r1=33880&r2=33881&view=diff ============================================================================== --- trunk/server/commands.h (original) +++ trunk/server/commands.h Sun Sep 25 08:25:58 2016 @@ -92,6 +92,7 @@ CMD_LUA, CMD_KICK, CMD_DELEGATE, + CMD_AICMD, CMD_FCDB, CMD_MAPIMG, Modified: trunk/server/stdinhand.c URL: http://svn.gna.org/viewcvs/freeciv/trunk/server/stdinhand.c?rev=33881&r1=33880&r2=33881&view=diff ============================================================================== --- trunk/server/stdinhand.c (original) +++ trunk/server/stdinhand.c Sun Sep 25 08:25:58 2016 @@ -148,6 +148,7 @@ static bool delegate_command(struct connection *caller, char *arg, bool check); static const char *delegate_player_str(struct player *pplayer, bool observer); +static bool aicmd_command(struct connection *caller, char *arg, bool check); static bool fcdb_command(struct connection *caller, char *arg, bool check); static const char *fcdb_accessor(int i); static char setting_status(struct connection *caller, @@ -4365,6 +4366,8 @@ return kick_command(caller, arg, check); case CMD_DELEGATE: return delegate_command(caller, arg, check); + case CMD_AICMD: + return aicmd_command(caller, arg, check); case CMD_FCDB: return fcdb_command(caller, arg, check); case CMD_MAPIMG: @@ -5502,6 +5505,71 @@ free_tokens(token, ntokens); + return ret; +} + +/***************************************************************************** + Execute a command in the context of the AI of the player. +*****************************************************************************/ +static bool aicmd_command(struct connection *caller, char *arg, bool check) +{ + enum m_pre_result match_result; + struct player *pplayer; + char *tokens[1], *cmd = NULL; + int ntokens; + bool ret = FALSE; + + ntokens = get_tokens(arg, tokens, 1, TOKEN_DELIMITERS); + + if (ntokens < 1) { + cmd_reply(CMD_AICMD, caller, C_FAIL, + _("No player given for aicmd.")); + goto cleanup; + } + + pplayer = player_by_name_prefix(tokens[0], &match_result); + + if (NULL == pplayer) { + cmd_reply_no_such_player(CMD_AICMD, caller, tokens[0], match_result); + goto cleanup; + } + + /* We have a player - extract the command. */ + cmd = arg + strlen(tokens[0]); + cmd = skip_leading_spaces(cmd); + + if (strlen(cmd) == 0) { + cmd_reply(CMD_AICMD, caller, C_FAIL, + _("No command for the AI console defined.")); + goto cleanup; + } + + if (check) { + ret = TRUE; + goto cleanup; + } + + /* This check is needed to return a message if the function is not defined + * for the AI of the player. */ + if (pplayer && pplayer->ai) { + if (pplayer->ai->funcs.player_console) { + cmd_reply(CMD_AICMD, caller, C_OK, + _("AI console for player %s. Command: '%s'."), + player_name(pplayer), cmd); + CALL_PLR_AI_FUNC(player_console, pplayer, pplayer, cmd); + ret = TRUE; + } else { + cmd_reply(CMD_AICMD, caller, C_FAIL, + _("No AI console defined for the AI '%s' of player %s."), + ai_name(pplayer->ai), player_name(pplayer)); + } + } else { + cmd_reply(CMD_AICMD, caller, C_FAIL, _("No AI defined for player %s."), + player_name(pplayer)); + } + + cleanup: + free_tokens(tokens, ntokens); return ret; } _______________________________________________ Freeciv-commits mailing list Freeciv-commits@gna.org https://mail.gna.org/listinfo/freeciv-commits