summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/monstuff.cc
diff options
context:
space:
mode:
authordshaligram <dshaligram@c06c8d41-db1a-0410-9941-cceddc491573>2007-10-26 08:33:37 +0000
committerdshaligram <dshaligram@c06c8d41-db1a-0410-9941-cceddc491573>2007-10-26 08:33:37 +0000
commit66f022fd710eeb3d62cdd6094e80ca231d3a1263 (patch)
tree6a7e15131a30fd7a51d91c29a04aac611674eae7 /crawl-ref/source/monstuff.cc
parent57f4a1b1382e1c4204cd0991eb3f574420184b83 (diff)
downloadcrawl-ref-66f022fd710eeb3d62cdd6094e80ca231d3a1263.tar.gz
crawl-ref-66f022fd710eeb3d62cdd6094e80ca231d3a1263.zip
Monsters can gain experience and level-up. Breaks saves.
git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@2584 c06c8d41-db1a-0410-9941-cceddc491573
Diffstat (limited to 'crawl-ref/source/monstuff.cc')
-rw-r--r--crawl-ref/source/monstuff.cc50
1 files changed, 30 insertions, 20 deletions
diff --git a/crawl-ref/source/monstuff.cc b/crawl-ref/source/monstuff.cc
index fdf88457fc..aee12608a2 100644
--- a/crawl-ref/source/monstuff.cc
+++ b/crawl-ref/source/monstuff.cc
@@ -375,17 +375,35 @@ static void check_kill_milestone(const monsters *mons,
}
#endif // DGL_MILESTONES
+static void give_monster_experience( int killer_index, int experience,
+ bool victim_was_born_friendly )
+{
+ if (killer_index < 0 || killer_index >= MAX_MONSTERS)
+ return;
+ monsters *mons = &menv[killer_index];
+ if (!mons->alive())
+ return;
+
+ if (mons_friendly(mons) != victim_was_born_friendly)
+ mons->gain_exp(experience);
+}
+
static void give_adjusted_experience(monsters *monster, killer_type killer,
- bool pet_kill, unsigned int *exp_gain,
+ bool pet_kill, int killer_index,
+ unsigned int *exp_gain,
unsigned int *avail_gain)
{
- if (testbits(monster->flags, MF_CREATED_FRIENDLY))
+ const int experience = exper_value(monster);
+ const bool created_friendly = testbits(monster->flags, MF_CREATED_FRIENDLY);
+ if (created_friendly)
; // No experience if monster was created friendly
else if (YOU_KILL(killer))
- gain_exp( exper_value( monster ), exp_gain, avail_gain );
+ gain_exp( experience, exp_gain, avail_gain );
else if (pet_kill)
- gain_exp( exper_value( monster ) / 2 + 1,
- exp_gain, avail_gain );
+ gain_exp( experience / 2 + 1, exp_gain, avail_gain );
+
+ if (MON_KILL(killer))
+ give_monster_experience( killer_index, experience, created_friendly );
}
static bool is_pet_kill(killer_type killer, int i)
@@ -580,12 +598,12 @@ void monster_die(monsters *monster, killer_type killer, int i, bool silent)
did_god_conduct(DID_KILL_DEMON,
monster->hit_dice);
- //jmf: Trog hates wizards
+ // jmf: Trog hates wizards
if (mons_is_magic_user(monster))
did_god_conduct(DID_KILL_WIZARD,
monster->hit_dice);
- //Beogh hates priests
+ // Beogh hates priests of other gods.
if (mons_class_flag(monster->type, M_PRIEST))
did_god_conduct(DID_KILL_PRIEST,
monster->hit_dice);
@@ -825,7 +843,7 @@ void monster_die(monsters *monster, killer_type killer, int i, bool silent)
KC_OTHER;
unsigned int exp_gain = 0, avail_gain = 0;
- give_adjusted_experience(monster, killer, pet_kill,
+ give_adjusted_experience(monster, killer, pet_kill, i,
&exp_gain, &avail_gain);
PlaceInfo& curr_PlaceInfo = you.get_place_info();
@@ -954,23 +972,15 @@ static bool jelly_divide(monsters * parent)
if (parent->hit_points > parent->max_hit_points)
parent->hit_points = parent->max_hit_points;
+ parent->init_experience();
+ parent->experience = parent->experience * 3 / 5 + 1;
+
// create child {dlb}:
// this is terribly partial and really requires
// more thought as to generation ... {dlb}
- child->type = parent->type;
- child->hit_dice = parent->hit_dice;
- child->hit_points = parent->hit_points;
+ *child = *parent;
child->max_hit_points = child->hit_points;
- child->ac = parent->ac;
- child->ev = parent->ev;
- child->speed = parent->speed;
child->speed_increment = 70 + random2(5);
- child->behaviour = parent->behaviour; /* Look at this! */
- child->foe = parent->foe;
- child->attitude = parent->attitude;
- child->colour = parent->colour;
- child->enchantments = parent->enchantments;
- child->ench_countdown = parent->ench_countdown;
child->x = parent->x + jex;
child->y = parent->y + jey;