[Freeciv-Dev] Re: (PR#6305) New server command: debug
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: |
undisclosed-recipients: ; |
Subject: |
[Freeciv-Dev] Re: (PR#6305) New server command: debug |
From: |
"Per I. Mathisen" <per@xxxxxxxxxxx> |
Date: |
Sat, 27 Sep 2003 17:09:31 -0700 |
Reply-to: |
rt@xxxxxxxxxxxxxx |
New version of the base patch. Added new command on Greg's request, which
is 'debug unit <id>'.
- Per
Index: ai/ailog.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/ailog.c,v
retrieving revision 1.7
diff -u -r1.7 ailog.c
--- ai/ailog.c 17 Jul 2003 18:56:50 -0000 1.7
+++ ai/ailog.c 28 Sep 2003 00:07:18 -0000
@@ -40,7 +40,9 @@
va_list ap;
int minlevel = MIN(LOGLEVEL_CITY, level);
- if (minlevel > fc_log_level) {
+ if (pcity->debug) {
+ minlevel = LOG_NORMAL;
+ } else if (minlevel > fc_log_level) {
return;
}
@@ -70,7 +72,9 @@
int minlevel = MIN(LOGLEVEL_UNIT, level);
int gx, gy;
- if (minlevel > fc_log_level) {
+ if (punit->debug) {
+ minlevel = LOG_NORMAL;
+ } else if (minlevel > fc_log_level) {
return;
}
@@ -147,7 +151,9 @@
int x = -1, y = -1, id = -1;
const char *s = "none";
- if (minlevel > fc_log_level) {
+ if (punit->debug) {
+ minlevel = LOG_NORMAL;
+ } else if (minlevel > fc_log_level) {
return;
}
Index: common/city.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/city.c,v
retrieving revision 1.197
diff -u -r1.197 city.c
--- common/city.c 21 Sep 2003 08:49:40 -0000 1.197
+++ common/city.c 28 Sep 2003 00:07:19 -0000
@@ -2544,6 +2544,7 @@
pcity->science_bonus = 100;
unit_list_init(&pcity->units_supported);
+ pcity->debug = FALSE;
return pcity;
}
Index: common/city.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/city.h,v
retrieving revision 1.135
diff -u -r1.135 city.h
--- common/city.h 14 Aug 2003 21:34:43 -0000 1.135
+++ common/city.h 28 Sep 2003 00:07:19 -0000
@@ -287,6 +287,7 @@
struct unit_list info_units_present;
struct ai_city ai;
+ bool debug;
};
/* city drawing styles */
Index: common/player.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/player.c,v
retrieving revision 1.126
diff -u -r1.126 player.c
--- common/player.c 22 Sep 2003 16:54:09 -0000 1.126
+++ common/player.c 28 Sep 2003 00:07:19 -0000
@@ -148,6 +148,7 @@
plr->attribute_block.data = NULL;
plr->attribute_block.length = 0;
+ plr->debug = FALSE;
}
/***************************************************************
Index: common/player.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/player.h,v
retrieving revision 1.106
diff -u -r1.106 player.h
--- common/player.h 19 Aug 2003 16:33:19 -0000 1.106
+++ common/player.h 28 Sep 2003 00:07:19 -0000
@@ -212,6 +212,7 @@
int length;
void *data;
} attribute_block;
+ bool debug;
};
void player_init(struct player *plr);
Index: common/unit.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/unit.c,v
retrieving revision 1.183
diff -u -r1.183 unit.c
--- common/unit.c 22 Sep 2003 16:54:09 -0000 1.183
+++ common/unit.c 28 Sep 2003 00:07:19 -0000
@@ -1459,6 +1459,7 @@
punit->unhappiness = 0;
/* A unit new and fresh ... */
punit->foul = FALSE;
+ punit->debug = FALSE;
punit->fuel = unit_type(punit)->fuel;
punit->hp = unit_type(punit)->hp;
punit->moves_left = unit_move_rate(punit);
Index: common/unit.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/unit.h,v
retrieving revision 1.100
diff -u -r1.100 unit.h
--- common/unit.h 22 Sep 2003 16:54:09 -0000 1.100
+++ common/unit.h 28 Sep 2003 00:07:19 -0000
@@ -133,6 +133,7 @@
/* ord_map and ord_city are the order index of this unit in tile.units
and city.units_supported; they are only used for save/reload */
bool foul;
+ bool debug;
bool moved;
bool paradropped;
bool connecting;
Index: server/stdinhand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/stdinhand.c,v
retrieving revision 1.294
diff -u -r1.294 stdinhand.c
--- server/stdinhand.c 23 Sep 2003 22:01:41 -0000 1.294
+++ server/stdinhand.c 28 Sep 2003 00:07:20 -0000
@@ -985,6 +985,7 @@
CMD_WALL,
/* mostly non-harmful: */
+ CMD_DEBUG,
CMD_SET,
CMD_TEAM,
CMD_FIX,
@@ -1114,6 +1115,12 @@
N_("For each connected client, pops up a window showing the message "
"entered.")
},
+ {"debug", ALLOW_HACK,
+ N_("debug <player <player> | city <x> <y> | units <x> <y>>"),
+ N_("Turn on or off AI debugging of given entity."),
+ N_("Print AI debug information about given entity and turn continous "
+ "debugging output for this entity on or off."),
+ },
{"set", ALLOW_CTRL,
N_("set <option-name> <value>"),
N_("Set server option."), NULL
@@ -2877,6 +2884,144 @@
/******************************************************************
...
******************************************************************/
+static void debug_command(struct connection *caller, char *str)
+{
+ char buf[MAX_LEN_CONSOLE_LINE];
+ char *arg[3];
+ int ntokens = 0;
+
+ if (server_state != RUN_GAME_STATE) {
+ cmd_reply(CMD_DEBUG, caller, C_SYNTAX,
+ _("Can only use this command once game has begun."));
+ return;
+ }
+
+ if (str != NULL || strlen(str) > 0) {
+ sz_strlcpy(buf, str);
+ ntokens = get_tokens(buf, arg, 3, TOKEN_DELIMITERS);
+ }
+
+ if (strcmp(arg[0], "player") == 0) {
+ struct player *pplayer;
+ enum m_pre_result match_result;
+
+ if (ntokens != 2) {
+ cmd_reply(CMD_DEBUG, caller, C_SYNTAX,
+ _("Undefined arguments for units. Usage: debug <player "
+ "<player> | city <x> <y> | units <x> <y> | unit <id>>."));
+ return;
+ }
+ pplayer = find_player_by_name_prefix(arg[1], &match_result);
+ if (pplayer == NULL) {
+ cmd_reply_no_such_player(CMD_TEAM, caller, arg[1], match_result);
+ return;
+ }
+ if (pplayer->debug) {
+ pplayer->debug = FALSE;
+ cmd_reply(CMD_DEBUG, caller, C_OK, _("%s no longer debugged"),
+ pplayer->name);
+ } else {
+ pplayer->debug = TRUE;
+ cmd_reply(CMD_DEBUG, caller, C_OK, _("%s debugged"), pplayer->name);
+ /* TODO: print some info about the player here */
+ }
+ } else if (strcmp(arg[0], "city") == 0) {
+ int x, y;
+ struct city *pcity;
+
+ if (ntokens != 3) {
+ cmd_reply(CMD_DEBUG, caller, C_SYNTAX,
+ _("Undefined arguments for city. Usage: debug < player "
+ "<player> | city <x> <y> | units <x> <y> >. (%d)"), ntokens);
+ return;
+ }
+ if (sscanf(arg[1], "%d", &x) != 1 || sscanf(arg[2], "%d", &y) != 1) {
+ cmd_reply(CMD_DEBUG, caller, C_SYNTAX, _("Value 2 & 3 must be
integer."));
+ return;
+ }
+ if (!is_normal_map_pos(x, y)) {
+ cmd_reply(CMD_DEBUG, caller, C_SYNTAX, _("Bad map coordinates."));
+ return;
+ }
+ pcity = map_get_city(x, y);
+ if (!pcity) {
+ cmd_reply(CMD_DEBUG, caller, C_SYNTAX, _("No city at this coordinate."));
+ return;
+ }
+ if (pcity->debug) {
+ pcity->debug = FALSE;
+ cmd_reply(CMD_DEBUG, caller, C_OK, _("%s no longer debugged"),
+ pcity->name);
+ } else {
+ pcity->debug = TRUE;
+ cmd_reply(CMD_DEBUG, caller, C_OK, _("%s debugged"), pcity->name);
+ /* TODO: Print some city info here */
+ }
+ } else if (strcmp(arg[0], "units") == 0) {
+ int x, y;
+
+ if (ntokens != 3) {
+ cmd_reply(CMD_DEBUG, caller, C_SYNTAX,
+ _("Undefined arguments for units. Usage: debug <player "
+ "<player> | city <x> <y> | units <x> <y> | unit <id>>."));
+ return;
+ }
+ if (sscanf(arg[1], "%d", &x) != 1 || sscanf(arg[2], "%d", &y) != 1) {
+ cmd_reply(CMD_DEBUG, caller, C_SYNTAX, _("Value 2 & 3 must be
integer."));
+ return;
+ }
+ if (!is_normal_map_pos(x, y)) {
+ cmd_reply(CMD_DEBUG, caller, C_SYNTAX, _("Bad map coordinates."));
+ return;
+ }
+ unit_list_iterate(map_get_tile(x, y)->units, punit) {
+ if (punit->debug) {
+ punit->debug = FALSE;
+ cmd_reply(CMD_DEBUG, caller, C_OK, _("%s's %s no longer debugged."),
+ unit_owner(punit)->name, unit_name(punit->type));
+ } else {
+ punit->debug = TRUE;
+ cmd_reply(CMD_DEBUG, caller, C_OK, _("%s's %s debugged."),
+ unit_owner(punit)->name, unit_name(punit->type));
+ }
+ } unit_list_iterate_end;
+ } else if (strcmp(arg[0], "unit") == 0) {
+ int id;
+ struct unit *punit;
+
+ if (ntokens != 2) {
+ cmd_reply(CMD_DEBUG, caller, C_SYNTAX,
+ _("Undefined arguments for units. Usage: debug <player "
+ "<player> | city <x> <y> | units <x> <y> | unit <id>>."));
+ return;
+ }
+ if (sscanf(arg[1], "%d", &id) != 1) {
+ cmd_reply(CMD_DEBUG, caller, C_SYNTAX, _("Value 2 must be integer."));
+ return;
+ }
+ if (!(punit = find_unit_by_id(id))) {
+ cmd_reply(CMD_DEBUG, caller, C_SYNTAX, _("Unit %d does not exist."), id);
+ return;
+ }
+ if (punit->debug) {
+ punit->debug = FALSE;
+ cmd_reply(CMD_DEBUG, caller, C_OK, _("%s's %s no longer debugged."),
+ unit_owner(punit)->name, unit_name(punit->type));
+ } else {
+ punit->debug = TRUE;
+ cmd_reply(CMD_DEBUG, caller, C_OK, _("%s's %s debugged."),
+ unit_owner(punit)->name, unit_name(punit->type));
+ }
+ } else {
+ cmd_reply(CMD_DEBUG, caller, C_SYNTAX,
+ _("Undefined arguments for units. Usage: debug <player "
+ "<player> | city <x> <y> | units <x> <y> | unit <id>>."));
+ }
+}
+
+/******************************************************************
+ ...
+******************************************************************/
static void set_command(struct connection *caller, char *str)
{
char command[MAX_LEN_CONSOLE_LINE], arg[MAX_LEN_CONSOLE_LINE], *cptr_s,
*cptr_d;
@@ -3861,6 +4006,9 @@
break;
case CMD_EXPLAIN:
explain_option(caller,arg);
+ break;
+ case CMD_DEBUG:
+ debug_command(caller,arg);
break;
case CMD_SET:
set_command(caller,arg);
|
|