summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--crawl-ref/source/debug.cc205
-rw-r--r--crawl-ref/source/debug.h5
-rw-r--r--crawl-ref/source/state.cc278
-rw-r--r--crawl-ref/source/state.h3
4 files changed, 246 insertions, 245 deletions
diff --git a/crawl-ref/source/debug.cc b/crawl-ref/source/debug.cc
index bf493533ca..5b97d4ae92 100644
--- a/crawl-ref/source/debug.cc
+++ b/crawl-ref/source/debug.cc
@@ -5654,7 +5654,7 @@ void do_crash_dump()
// Dumping the crawl state is next least likely to cause another crash,
// so do that next.
- crawl_state.dump(file);
+ crawl_state.dump();
// Dump current messages.
if (file != stderr)
@@ -5681,6 +5681,209 @@ void do_crash_dump()
fclose(file);
}
+std::string debug_coord_str(const coord_def &pos)
+{
+ return make_stringf("(%d, %d)%s", pos.x, pos.y,
+ !in_bounds(pos) ? " <OoB>" : "");
+}
+
+std::string debug_mon_str(const monsters* mon)
+{
+ const int midx = monster_index(mon);
+ if (invalid_monster_index(midx))
+ return make_stringf("Invalid monster index %d", midx);
+
+ std::string out = "Monster '" + mon->full_name(DESC_PLAIN, true) + "' ";
+ out += make_stringf("%s [midx = %d]", debug_coord_str(mon->pos()).c_str(),
+ midx);
+
+ return (out);
+}
+
+void debug_dump_mon(const monsters* mon, bool recurse)
+{
+ const int midx = monster_index(mon);
+ if (invalid_monster_index(midx) || invalid_monster_class(mon->type))
+ return;
+
+ fprintf(stderr, "<<<<<<<<<" EOL);
+
+ fprintf(stderr, "Name: %s" EOL, mon->name(DESC_PLAIN, true).c_str());
+ fprintf(stderr, "Base name: %s" EOL,
+ mon->base_name(DESC_PLAIN, true).c_str());
+ fprintf(stderr, "Full name: %s" EOL EOL,
+ mon->full_name(DESC_PLAIN, true).c_str());
+
+ if (in_bounds(mon->pos()))
+ {
+ std::string feat =
+ raw_feature_description(grd(mon->pos()), NUM_TRAPS, true);
+ fprintf(stderr, "On/in/over feature: %s" EOL EOL, feat.c_str());
+ }
+
+ fprintf(stderr, "Foe: ");
+ if (mon->foe == MHITNOT)
+ fprintf(stderr, "none");
+ else if (mon->foe == MHITYOU)
+ fprintf(stderr, "player");
+ else if (invalid_monster_index(mon->foe))
+ fprintf(stderr, "invalid monster index %d", mon->foe);
+ else if (mon->foe == midx)
+ fprintf(stderr, "self");
+ else
+ fprintf(stderr, "%s", debug_mon_str(&menv[mon->foe]).c_str());
+
+ fprintf(stderr, EOL);
+
+ fprintf(stderr, "Target: ");
+ if (mon->target.origin())
+ fprintf(stderr, "none" EOL);
+ else
+ fprintf(stderr, "%s" EOL, debug_coord_str(mon->target).c_str());
+
+ int target = MHITNOT;
+ fprintf(stderr, "At target: ");
+ if (mon->target.origin())
+ fprintf(stderr, "N/A");
+ else if (mon->target == you.pos())
+ {
+ fprintf(stderr, "player");
+ target = MHITYOU;
+ }
+ else if (mon->target == mon->pos())
+ {
+ fprintf(stderr, "self");
+ target = midx;
+ }
+ else if (in_bounds(mon->target))
+ {
+ target = mgrd(mon->target);
+
+ if (target == NON_MONSTER)
+ fprintf(stderr, "nothing");
+ else if (target == midx)
+ fprintf(stderr, "improperly linked self");
+ else if (target == mon->foe)
+ fprintf(stderr, "same as foe");
+ else if (invalid_monster_index(target))
+ fprintf(stderr, "invalid monster index %d", target);
+ else
+ fprintf(stderr, "%s", debug_mon_str(&menv[target]).c_str());
+ }
+ else
+ fprintf(stderr, "<OoB>");
+
+ fprintf(stderr, EOL);
+
+ if (mon->is_patrolling())
+ fprintf(stderr, "Patrolling: %s" EOL EOL,
+ debug_coord_str(mon->patrol_point).c_str());
+
+ if (mon->travel_target != MTRAV_NONE)
+ {
+ fprintf(stderr, EOL "Travelling:" EOL);
+ fprintf(stderr, " travel_target = %d" EOL, mon->travel_target);
+ fprintf(stderr, " travel_path.size() = %lu" EOL,
+ (long unsigned int) mon->travel_path.size());
+ if (mon->travel_path.size() > 0)
+ {
+ fprintf(stderr, " next travel step: %s" EOL,
+ debug_coord_str(mon->travel_path.back()).c_str());
+ fprintf(stderr, " last travel step: %s" EOL,
+ debug_coord_str(mon->travel_path.front()).c_str());
+ }
+ }
+ fprintf(stderr, EOL);
+
+ fprintf(stderr, "Inventory:" EOL);
+ for (int i = 0; i < NUM_MONSTER_SLOTS; i++)
+ {
+ const int idx = mon->inv[i];
+
+ if (idx == NON_ITEM)
+ continue;
+
+ fprintf(stderr, " slot #%d: ", i);
+
+ if (idx < 0 || idx > MAX_ITEMS)
+ {
+ fprintf(stderr, "invalid item index %d" EOL, idx);
+ continue;
+ }
+ const item_def &item(mitm[idx]);
+
+ if (!is_valid_item(item))
+ {
+ fprintf(stderr, "invalid item" EOL);
+ continue;
+ }
+
+ fprintf(stderr, "%s", item.name(DESC_PLAIN, false, true).c_str());
+
+ if (!held_by_monster(item))
+ fprintf(stderr, " [not held by monster, pos = %s]",
+ debug_coord_str(item.pos).c_str());
+ else if (holding_monster(item) != mon)
+ fprintf(stderr, " [held by other monster: %s]",
+ debug_mon_str(holding_monster(item)).c_str());
+
+ fprintf(stderr, EOL);
+ }
+ fprintf(stderr, EOL);
+
+ if (mons_class_flag(mon->type, M_SPELLCASTER))
+ {
+ fprintf(stderr, "Spells:" EOL);
+
+ for (int i = 0; i < NUM_MONSTER_SPELL_SLOTS; i++)
+ {
+ spell_type spell = mon->spells[i];
+
+ if (spell == SPELL_NO_SPELL)
+ continue;
+
+ fprintf(stderr, " slot #%d: ", i);
+ if (!is_valid_spell(spell))
+ fprintf(stderr, "Invalid spell #%d" EOL, (int) spell);
+ else
+ fprintf(stderr, "%s" EOL, spell_title(spell));
+ }
+ fprintf(stderr, EOL);
+ }
+
+ fprintf(stderr, "attitude: %d, behaviour: %d, number: %d, flags: 0x%lx" EOL,
+ mon->attitude, mon->behaviour, mon->number, mon->flags);
+
+ fprintf(stderr, "colour: %d, foe_memory: %d, shield_blocks:%d, "
+ "experience: %lu" EOL,
+ mon->colour, mon->foe_memory, mon->shield_blocks,
+ mon->experience);
+
+ fprintf(stderr, "god: %s, seen_context: %s" EOL,
+ god_name(mon->god).c_str(), mon->seen_context.c_str());
+
+ fprintf(stderr, ">>>>>>>>>" EOL EOL);
+
+ if (!recurse)
+ return;
+
+ if (!invalid_monster_index(mon->foe) && mon->foe != midx
+ && !invalid_monster_class(menv[mon->foe].type))
+ {
+ fprintf(stderr, "Foe:" EOL);
+ debug_dump_mon(&menv[mon->foe], false);
+ }
+
+ if (!invalid_monster_index(target) && target != midx
+ && target != mon->foe
+ && !invalid_monster_class(menv[target].type))
+ {
+ fprintf(stderr, "Target:" EOL);
+ debug_dump_mon(&menv[target], false);
+ }
+}
+
+
#ifdef DEBUG_DIAGNOSTICS
// Map statistics generation.
diff --git a/crawl-ref/source/debug.h b/crawl-ref/source/debug.h
index 1e23f14eb9..acf3dd1f27 100644
--- a/crawl-ref/source/debug.h
+++ b/crawl-ref/source/debug.h
@@ -145,4 +145,9 @@ bool get_item_by_name(item_def *item, char* specs,
bool create_for_real = false);
void do_crash_dump();
+
+std::string debug_coord_str(const coord_def &pos);
+std::string debug_mon_str(const monsters* mon);
+void debug_dump_mon(const monsters* mon, bool recurse);
+
#endif
diff --git a/crawl-ref/source/state.cc b/crawl-ref/source/state.cc
index 88ae49aca7..6d04364a87 100644
--- a/crawl-ref/source/state.cc
+++ b/crawl-ref/source/state.cc
@@ -13,18 +13,14 @@ REVISION("$Rev$");
#include "delay.h"
#include "directn.h"
-#include "items.h"
#include "macro.h"
#include "menu.h" // For print_formatted_paragraph()
#include "message.h"
-#include "monstuff.h"
#include "mon-util.h"
#include "output.h"
#include "player.h"
#include "religion.h"
-#include "spl-util.h"
#include "state.h"
-#include "stuff.h"
#include "tutorial.h"
#include "view.h"
@@ -435,295 +431,93 @@ void game_state::mon_gone(monsters* mon)
dec_mon_acting(mon);
}
-static std::string _coord_str(const coord_def &pos)
+void game_state::dump()
{
- return make_stringf("(%d, %d)%s", pos.x, pos.y,
- !in_bounds(pos) ? " <OoB>" : "");
-}
-
-static std::string _dump_mon_short(monsters* mon)
-{
- const int midx = monster_index(mon);
- if (invalid_monster_index(midx))
- return make_stringf("Invalid monster index %d", midx);
-
- std::string out = "Monster '" + mon->full_name(DESC_PLAIN, true) + "' ";
- out += make_stringf("%s [midx = %d]", _coord_str(mon->pos()).c_str(),
- midx);
-
- return (out);
-}
-
-static void _dump_mon_full(FILE* file, monsters* mon, bool recurse)
-{
- const int midx = monster_index(mon);
- if (invalid_monster_index(midx) || invalid_monster_class(mon->type))
- return;
-
- fprintf(file, "<<<<<<<<<" EOL);
-
- fprintf(file, "Name: %s" EOL, mon->name(DESC_PLAIN, true).c_str());
- fprintf(file, "Base name: %s" EOL,
- mon->base_name(DESC_PLAIN, true).c_str());
- fprintf(file, "Full name: %s" EOL EOL,
- mon->full_name(DESC_PLAIN, true).c_str());
-
- if (in_bounds(mon->pos()))
- {
- std::string feat =
- raw_feature_description(grd(mon->pos()), NUM_TRAPS, true);
- fprintf(file, "On/in/over feature: %s" EOL EOL, feat.c_str());
- }
-
- fprintf(file, "Foe: ");
- if (mon->foe == MHITNOT)
- fprintf(file, "none");
- else if (mon->foe == MHITYOU)
- fprintf(file, "player");
- else if (invalid_monster_index(mon->foe))
- fprintf(file, "invalid monster index %d", mon->foe);
- else if (mon->foe == midx)
- fprintf(file, "self");
- else
- fprintf(file, "%s", _dump_mon_short(&menv[mon->foe]).c_str());
-
- fprintf(file, EOL);
-
- fprintf(file, "Target: ");
- if (mon->target.origin())
- fprintf(file, "none" EOL);
- else
- fprintf(file, "%s" EOL, _coord_str(mon->target).c_str());
-
- int target = MHITNOT;
- fprintf(file, "At target: ");
- if (mon->target.origin())
- fprintf(file, "N/A");
- else if (mon->target == you.pos())
- {
- fprintf(file, "player");
- target = MHITYOU;
- }
- else if (mon->target == mon->pos())
- {
- fprintf(file, "self");
- target = midx;
- }
- else if (in_bounds(mon->target))
- {
- target = mgrd(mon->target);
-
- if (target == NON_MONSTER)
- fprintf(file, "nothing");
- else if (target == midx)
- fprintf(file, "improperly linked self");
- else if (target == mon->foe)
- fprintf(file, "same as foe");
- else if (invalid_monster_index(target))
- fprintf(file, "invalid monster index %d", target);
- else
- fprintf(file, "%s", _dump_mon_short(&menv[target]).c_str());
- }
- else
- fprintf(file, "<OoB>");
-
- fprintf(file, EOL);
-
- if (mon->is_patrolling())
- fprintf(file, "Patrolling: %s" EOL EOL,
- _coord_str(mon->patrol_point).c_str());
-
- if (mon->travel_target != MTRAV_NONE)
- {
- fprintf(file, EOL "Travelling:" EOL);
- fprintf(file, " travel_target = %d" EOL, mon->travel_target);
- fprintf(file, " travel_path.size() = %lu" EOL,
- (long unsigned int) mon->travel_path.size());
- if (mon->travel_path.size() > 0)
- {
- fprintf(file, " next travel step: %s" EOL,
- _coord_str(mon->travel_path.back()).c_str());
- fprintf(file, " last travel step: %s" EOL,
- _coord_str(mon->travel_path.front()).c_str());
- }
- }
- fprintf(file, EOL);
-
- fprintf(file, "Inventory:" EOL);
- for (int i = 0; i < NUM_MONSTER_SLOTS; i++)
- {
- const int idx = mon->inv[i];
-
- if (idx == NON_ITEM)
- continue;
-
- fprintf(file, " slot #%d: ", i);
-
- if (idx < 0 || idx > MAX_ITEMS)
- {
- fprintf(file, "invalid item index %d" EOL, idx);
- continue;
- }
- const item_def &item(mitm[idx]);
-
- if (!is_valid_item(item))
- {
- fprintf(file, "invalid item" EOL);
- continue;
- }
-
- fprintf(file, "%s", item.name(DESC_PLAIN, false, true).c_str());
-
- if (!held_by_monster(item))
- fprintf(file, " [not held by monster, pos = %s]",
- _coord_str(item.pos).c_str());
- else if (holding_monster(item) != mon)
- fprintf(file, " [held by other monster: %s]",
- _dump_mon_short(holding_monster(item)).c_str());
-
- fprintf(file, EOL);
- }
- fprintf(file, EOL);
-
- if (mons_class_flag(mon->type, M_SPELLCASTER))
- {
- fprintf(file, "Spells:" EOL);
-
- for (int i = 0; i < NUM_MONSTER_SPELL_SLOTS; i++)
- {
- spell_type spell = mon->spells[i];
-
- if (spell == SPELL_NO_SPELL)
- continue;
-
- fprintf(file, " slot #%d: ", i);
- if (!is_valid_spell(spell))
- fprintf(file, "Invalid spell #%d" EOL, (int) spell);
- else
- fprintf(file, "%s" EOL, spell_title(spell));
- }
- fprintf(file, EOL);
- }
-
- fprintf(file, "attitude: %d, behaviour: %d, number: %d, flags: 0x%lx" EOL,
- mon->attitude, mon->behaviour, mon->number, mon->flags);
-
- fprintf(file, "colour: %d, foe_memory: %d, shield_blocks:%d, "
- "experience: %lu" EOL,
- mon->colour, mon->foe_memory, mon->shield_blocks,
- mon->experience);
-
- fprintf(file, "god: %s, seen_context: %s" EOL,
- god_name(mon->god).c_str(), mon->seen_context.c_str());
-
- fprintf(file, ">>>>>>>>>" EOL EOL);
-
- if (!recurse)
- return;
-
- if (!invalid_monster_index(mon->foe) && mon->foe != midx
- && !invalid_monster_class(menv[mon->foe].type))
- {
- fprintf(file, "Foe:" EOL);
- _dump_mon_full(file, &menv[mon->foe], false);
- }
-
- if (!invalid_monster_index(target) && target != midx
- && target != mon->foe
- && !invalid_monster_class(menv[target].type))
- {
- fprintf(file, "Target:" EOL);
- _dump_mon_full(file, &menv[target], false);
- }
-}
-
-void game_state::dump(FILE* file)
-{
- fprintf(file, EOL "Game state:" EOL EOL);
+ fprintf(stderr, EOL "Game state:" EOL EOL);
- fprintf(file, "mouse_enabled: %d, waiting_for_command: %d, "
+ fprintf(stderr, "mouse_enabled: %d, waiting_for_command: %d, "
"terminal_resized: %d" EOL,
mouse_enabled, waiting_for_command, terminal_resized);
- fprintf(file, "io_inited: %d, need_save: %d, saving_game: %d, "
+ fprintf(stderr, "io_inited: %d, need_save: %d, saving_game: %d, "
"updating_scores: %d:" EOL,
io_inited, need_save, saving_game, updating_scores);
- fprintf(file, "seen_hups: %d, map_stat_gen: %d, arena: %d, "
+ fprintf(stderr, "seen_hups: %d, map_stat_gen: %d, arena: %d, "
"arena_suspended: %d, unicode_ok: %d" EOL,
seen_hups, map_stat_gen, arena, arena_suspended, unicode_ok);
- fprintf(file, EOL);
+ fprintf(stderr, EOL);
if (!startup_errors.empty())
{
- fprintf(file, "Startup errors:" EOL);
+ fprintf(stderr, "Startup errors:" EOL);
for (unsigned int i = 0; i < startup_errors.size(); i++)
- fprintf(file, "%s" EOL, startup_errors[i].c_str());
- fprintf(file, EOL);
+ fprintf(stderr, "%s" EOL, startup_errors[i].c_str());
+ fprintf(stderr, EOL);
}
- fprintf(file, "prev_cmd = %s" EOL, command_to_name(prev_cmd).c_str());
+ fprintf(stderr, "prev_cmd = %s" EOL, command_to_name(prev_cmd).c_str());
if (doing_prev_cmd_again)
{
- fprintf(file, "Doing prev_cmd again with keys: ");
+ fprintf(stderr, "Doing prev_cmd again with keys: ");
for (unsigned int i = 0; i < prev_cmd_keys.size(); i++)
- fprintf(file, "%d, ", prev_cmd_keys[i]);
- fprintf(file, EOL);
- fprintf(file, "As ASCII keys: ");
+ fprintf(stderr, "%d, ", prev_cmd_keys[i]);
+ fprintf(stderr, EOL);
+ fprintf(stderr, "As ASCII keys: ");
for (unsigned int i = 0; i < prev_cmd_keys.size(); i++)
- fprintf(file, "%c", (char) prev_cmd_keys[i]);
- fprintf(file, EOL EOL);
+ fprintf(stderr, "%c", (char) prev_cmd_keys[i]);
+ fprintf(stderr, EOL EOL);
}
- fprintf(file, "repeat_cmd = %s" EOL, command_to_name(repeat_cmd).c_str());
+ fprintf(stderr, "repeat_cmd = %s" EOL, command_to_name(repeat_cmd).c_str());
if (cmd_repeat_count > 0 || cmd_repeat_goal > 0)
{
- fprintf(file, "Doing command repetition:" EOL);
- fprintf(file, "cmd_repeat_start:%d, cmd_repeat_count: %d, "
+ fprintf(stderr, "Doing command repetition:" EOL);
+ fprintf(stderr, "cmd_repeat_start:%d, cmd_repeat_count: %d, "
"cmd_repeat_goal:%d" EOL
"prev_cmd_repeat_goal: %d" EOL,
cmd_repeat_start, cmd_repeat_count, cmd_repeat_goal,
prev_cmd_repeat_goal);
- fprintf(file, "Keys being repeated: ");
+ fprintf(stderr, "Keys being repeated: ");
for (unsigned int i = 0; i < repeat_cmd_keys.size(); i++)
- fprintf(file, "%d, ", repeat_cmd_keys[i]);
- fprintf(file, EOL);
- fprintf(file, "As ASCII keys: ");
+ fprintf(stderr, "%d, ", repeat_cmd_keys[i]);
+ fprintf(stderr, EOL);
+ fprintf(stderr, "As ASCII keys: ");
for (unsigned int i = 0; i < repeat_cmd_keys.size(); i++)
- fprintf(file, "%c", (char) repeat_cmd_keys[i]);
- fprintf(file, EOL);
+ fprintf(stderr, "%c", (char) repeat_cmd_keys[i]);
+ fprintf(stderr, EOL);
}
- fprintf(file, EOL);
+ fprintf(stderr, EOL);
if (god_act.which_god != GOD_NO_GOD || god_act.depth != 0)
{
- fprintf(file, "God %s currently acting with depth %d" EOL EOL,
+ fprintf(stderr, "God %s currently acting with depth %d" EOL EOL,
god_name(god_act.which_god).c_str(), god_act.depth);
}
if (god_act_stack.size() != 0)
{
- fprintf(file, "Other gods acting:" EOL);
+ fprintf(stderr, "Other gods acting:" EOL);
for (unsigned int i = 0; i < god_act_stack.size(); i++)
- fprintf(file, "God %s with depth %d" EOL,
+ fprintf(stderr, "God %s with depth %d" EOL,
god_name(god_act_stack[i].which_god).c_str(),
god_act_stack[i].depth);
- fprintf(file, EOL EOL);
+ fprintf(stderr, EOL EOL);
}
if (mon_act != NULL)
{
- fprintf(file, "%s currently acting:" EOL EOL,
- _dump_mon_short(mon_act).c_str());
- _dump_mon_full(file, mon_act, true);
+ fprintf(stderr, "%s currently acting:" EOL EOL,
+ debug_mon_str(mon_act).c_str());
+ debug_dump_mon(mon_act, true);
}
if (mon_act_stack.size() != 0)
{
- fprintf(file, "Others monsters acting:" EOL);
+ fprintf(stderr, "Others monsters acting:" EOL);
for (unsigned int i = 0; i < mon_act_stack.size(); i++)
- fprintf(file, " %s" EOL,
- _dump_mon_short(mon_act_stack[i]).c_str());
+ fprintf(stderr, " %s" EOL,
+ debug_mon_str(mon_act_stack[i]).c_str());
}
}
diff --git a/crawl-ref/source/state.h b/crawl-ref/source/state.h
index 58bfa30090..ddfc73b969 100644
--- a/crawl-ref/source/state.h
+++ b/crawl-ref/source/state.h
@@ -11,7 +11,6 @@
#include "enum.h"
#include <vector>
-#include <stdio.h>
class monsters;
class mon_acting;
@@ -133,7 +132,7 @@ public:
void clear_mon_acting();
void mon_gone(monsters* mon);
- void dump(FILE* file);
+ void dump();
friend class mon_acting;
};