From dcf7801daff4c7c76e461c5ad08749394e64466b Mon Sep 17 00:00:00 2001 From: zelgadis Date: Sun, 16 Sep 2007 03:39:41 +0000 Subject: Add dump sections for branch/area details for turns and experience/kills, with the section names being turns_by_place and kills_by_place. Also includes a "visits" dump section (included in the "misc" section") a brief description of the number of branches/levels/areas/etc you visited. Breaks savefile compatibility. git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@2102 c06c8d41-db1a-0410-9941-cceddc491573 --- crawl-ref/source/player.cc | 242 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 241 insertions(+), 1 deletion(-) (limited to 'crawl-ref/source/player.cc') diff --git a/crawl-ref/source/player.cc b/crawl-ref/source/player.cc index 6ac2ef50c9..49c0b2abc4 100644 --- a/crawl-ref/source/player.cc +++ b/crawl-ref/source/player.cc @@ -32,6 +32,7 @@ #include "externs.h" +#include "branch.h" #include "clua.h" #include "delay.h" #include "dgnevent.h" @@ -2444,11 +2445,15 @@ void forget_map(unsigned char chance_forgotten) } } // end forget_map() -void gain_exp( unsigned int exp_gained ) +void gain_exp( unsigned int exp_gained, unsigned int* actual_gain, + unsigned int* actual_avail_gain) { if (player_equip_ego_type( EQ_BODY_ARMOUR, SPARM_ARCHMAGI )) exp_gained = div_rand_round( exp_gained, 4 ); + unsigned long old_exp = you.experience; + int old_avail = you.exp_available; + #if DEBUG_DIAGNOSTICS mprf(MSGCH_DIAGNOSTICS, "gain_exp: %d", exp_gained ); #endif @@ -2468,6 +2473,12 @@ void gain_exp( unsigned int exp_gained ) // become useful for a longer time if (Options.tutorial_left && you.experience_level == 7) tutorial_finished(); + + if (actual_gain != NULL) + *actual_gain = you.experience - old_exp; + + if (actual_avail_gain != NULL) + *actual_avail_gain = you.exp_available - old_avail; } // end gain_exp() void level_change(bool skip_ability_increase) @@ -5064,6 +5075,23 @@ void player::init() duration.init(0); exp_available = 25; + + global_info.make_global(); + global_info.assert_validity(); + + for (int i = 0; i < NUM_BRANCHES; i++) + { + branch_info[i].level_type = LEVEL_DUNGEON; + branch_info[i].branch = i; + branch_info[i].assert_validity(); + } + + for (int i = 0; i < (NUM_LEVEL_AREA_TYPES - 1); i++) + { + non_branch_info[i].level_type = i + 1; + non_branch_info[i].branch = -1; + non_branch_info[i].assert_validity(); + } } player::~player() @@ -5777,3 +5805,215 @@ void player::moveto(const coord_def &c) if (real_move) dungeon_events.fire_position_event(DET_PLAYER_MOVED, c); } + +//////////////////////////////////////////////////////////////////////////// + +PlaceInfo::PlaceInfo() + : level_type(-2), branch(-2), num_visits(0), + levels_seen(0), mon_kill_exp(0), mon_kill_exp_avail(0), + turns_total(0), turns_explore(0), turns_travel(0), turns_interlevel(0), + turns_resting(0), turns_other(0), elapsed_total(0.0), + elapsed_explore(0.0), elapsed_travel(0.0), elapsed_interlevel(0.0), + elapsed_resting(0.0), elapsed_other(0.0) +{ + for (int i = 0; i < KC_NCATEGORIES; i++) + mon_kill_num[i] = 0; +} + +bool PlaceInfo::is_global() const +{ + return (level_type == -1 && branch == -1); +} + +void PlaceInfo::make_global() +{ + level_type = -1; + branch = -1; +} + +void PlaceInfo::assert_validity() const +{ + // Check that level_type and branch match up + ASSERT(is_global() || + (level_type == LEVEL_DUNGEON && branch >= BRANCH_MAIN_DUNGEON && + branch < NUM_BRANCHES) || + (level_type > LEVEL_DUNGEON && level_type < NUM_LEVEL_AREA_TYPES && + branch == -1)); + + // Can't have visited a place without seeing any of its levels, and + // visa versa + ASSERT((num_visits == 0 && levels_seen == 0) || + (num_visits > 0 && levels_seen > 0)); + + if (level_type == LEVEL_LABYRINTH || level_type == LEVEL_ABYSS) + ASSERT(num_visits == levels_seen); + else if (level_type == LEVEL_PANDEMONIUM) + ASSERT(num_visits <= levels_seen); + else if (level_type == LEVEL_DUNGEON && branches[branch].depth > 0) + ASSERT(levels_seen <= (unsigned long) branches[branch].depth); + + ASSERT(turns_total == (turns_explore + turns_travel + turns_interlevel + + turns_resting + turns_other)); + + ASSERT(elapsed_total == (elapsed_explore + elapsed_travel + + elapsed_interlevel + elapsed_resting + + elapsed_other)); +} + +const std::string PlaceInfo::short_name() const +{ + if (level_type == LEVEL_DUNGEON) + return branches[branch].shortname; + else + { + switch (level_type) + { + case LEVEL_ABYSS: + return "Abyss"; + + case LEVEL_PANDEMONIUM: + return "Pandemonium"; + + case LEVEL_LABYRINTH: + return "Labyrinth"; + + default: + return "Bug"; + } + } +} + +const PlaceInfo &PlaceInfo::operator += (const PlaceInfo &other) +{ + num_visits += other.num_visits; + levels_seen += other.levels_seen; + + mon_kill_exp += other.mon_kill_exp; + mon_kill_exp_avail += other.mon_kill_exp_avail; + + for (int i = 0; i < KC_NCATEGORIES; i++) + mon_kill_num[i] += other.mon_kill_num[i]; + + turns_total += other.turns_total; + turns_explore += other.turns_explore; + turns_travel += other.turns_travel; + turns_interlevel += other.turns_interlevel; + turns_resting += other.turns_resting; + turns_other += other.turns_other; + + elapsed_total += other.elapsed_total; + elapsed_explore += other.elapsed_explore; + elapsed_travel += other.elapsed_travel; + elapsed_interlevel += other.elapsed_interlevel; + elapsed_resting += other.elapsed_resting; + elapsed_other += other.elapsed_other; + + return (*this); +} + +const PlaceInfo &PlaceInfo::operator -= (const PlaceInfo &other) +{ + num_visits -= other.num_visits; + levels_seen -= other.levels_seen; + + mon_kill_exp -= other.mon_kill_exp; + mon_kill_exp_avail -= other.mon_kill_exp_avail; + + for (int i = 0; i < KC_NCATEGORIES; i++) + mon_kill_num[i] -= other.mon_kill_num[i]; + + turns_total -= other.turns_total; + turns_explore -= other.turns_explore; + turns_travel -= other.turns_travel; + turns_interlevel -= other.turns_interlevel; + turns_resting -= other.turns_resting; + turns_other -= other.turns_other; + + elapsed_total -= other.elapsed_total; + elapsed_explore -= other.elapsed_explore; + elapsed_travel -= other.elapsed_travel; + elapsed_interlevel -= other.elapsed_interlevel; + elapsed_resting -= other.elapsed_resting; + elapsed_other -= other.elapsed_other; + + return (*this); +} + +PlaceInfo PlaceInfo::operator + (const PlaceInfo &other) const +{ + PlaceInfo copy = *this; + copy += other; + return copy; +} + +PlaceInfo PlaceInfo::operator - (const PlaceInfo &other) const +{ + PlaceInfo copy = *this; + copy -= other; + return copy; +} + + +PlaceInfo& player::get_place_info() const +{ + return get_place_info(where_are_you, level_type); +} + +PlaceInfo& player::get_place_info(branch_type branch) const +{ + return get_place_info(branch, LEVEL_DUNGEON); +} + +PlaceInfo& player::get_place_info(level_area_type level_type2) const +{ + return get_place_info(NUM_BRANCHES, level_type2); +} + +PlaceInfo& player::get_place_info(branch_type branch, + level_area_type level_type2) const +{ + ASSERT((level_type2 == LEVEL_DUNGEON && branch >= BRANCH_MAIN_DUNGEON && + branch < NUM_BRANCHES) || + (level_type2 > LEVEL_DUNGEON && level_type < NUM_LEVEL_AREA_TYPES)); + + if (level_type2 == LEVEL_DUNGEON) + return (PlaceInfo&) branch_info[branch]; + else + return (PlaceInfo&) non_branch_info[level_type2 - 1]; +} + +void player::set_place_info(PlaceInfo place_info) +{ + place_info.assert_validity(); + + if (place_info.is_global()) + global_info = place_info; + else if (place_info.level_type == LEVEL_DUNGEON) + branch_info[place_info.branch] = place_info; + else + non_branch_info[place_info.level_type - 1] = place_info; +} + +std::vector player::get_all_place_info(bool visited_only, + bool dungeon_only) const +{ + std::vector list; + + for (int i = 0; i < NUM_BRANCHES; i++) + { + if ((visited_only && branch_info[i].num_visits == 0) || + (dungeon_only && branch_info[i].level_type != LEVEL_DUNGEON)) + continue; + list.push_back(branch_info[i]); + } + + for (int i = 0; i < (NUM_LEVEL_AREA_TYPES - 1); i++) + { + if ((visited_only && non_branch_info[i].num_visits == 0) || + (dungeon_only && non_branch_info[i].level_type != LEVEL_DUNGEON)) + continue; + list.push_back(non_branch_info[i]); + } + + return list; +} -- cgit v1.2.3-54-g00ecf