From 7c6b9c70e049c9413046a0f4ded90f67b7c71234 Mon Sep 17 00:00:00 2001 From: zelgadis Date: Wed, 28 Jan 2009 08:38:42 +0000 Subject: Move the monster dumping code from state.cc to debug.cc, and dump to stderr to reduce the need to pass a file pointer all over the place. git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@8837 c06c8d41-db1a-0410-9941-cceddc491573 --- crawl-ref/source/state.cc | 278 ++++++---------------------------------------- 1 file changed, 36 insertions(+), 242 deletions(-) (limited to 'crawl-ref/source/state.cc') 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) ? " " : ""); -} - -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, ""); - - 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()); } } -- cgit v1.2.3-54-g00ecf