Apply the new ground_level method.
[crawl.git] / crawl-ref / source / kills.h
blob6d68dd52cd6b958b694283ce44d348641f92b9c9
1 /*
2 * File: kills.h
3 * Summary: Tracks monsters the player has killed.
4 * Written by: Darshan Shaligram
5 */
7 #ifndef KILLS_H
8 #define KILLS_H
10 #include <vector>
11 #include <string>
12 #include <map>
13 #include <stdio.h>
14 #include "enum.h"
16 class monster;
17 class reader;
18 class writer;
20 // Not intended for external use!
21 struct kill_monster_desc
23 kill_monster_desc(const monster*);
24 kill_monster_desc() { }
26 void save(writer&) const;
27 void load(reader&);
29 enum name_modifier
31 M_NORMAL, M_ZOMBIE, M_SKELETON, M_SIMULACRUM, M_SPECTRE,
32 M_SHAPESHIFTER, // A shapeshifter pretending to be 'monnum'
35 int monnum; // Number of the beast
36 name_modifier modifier; // Nature of the beast
38 struct less_than
40 bool operator () (const kill_monster_desc &m1,
41 const kill_monster_desc &m2) const
43 return (m1.monnum < m2.monnum
44 || (m1.monnum == m2.monnum && m1.modifier < m2.modifier));
49 #define PLACE_LIMIT 5 // How many unique kill places we're prepared to track
50 class kill_def
52 public:
53 kill_def(const monster* mon);
54 kill_def() : kills(0), exp(0)
56 // This object just says to the world that it's uninitialised
59 void save(writer&) const;
60 void load(reader&);
62 void add_kill(const monster* mon, unsigned short place);
63 void add_place(unsigned short place, bool force = false);
65 void merge(const kill_def &k, bool unique_monster);
67 std::string info(const kill_monster_desc &md) const;
68 std::string base_name(const kill_monster_desc &md) const;
70 unsigned short kills; // How many kills does the player have?
71 int exp; // Experience gained for slaying the beast.
72 // Only set *once*, even for shapeshifters.
74 std::vector<unsigned short> places; // Places where we've killed the beast.
75 private:
76 std::string append_places(const kill_monster_desc &md,
77 const std::string &name) const;
80 // Ghosts and random Pandemonium demons.
81 class kill_ghost
83 public:
84 kill_ghost(const monster* mon);
85 kill_ghost() { }
87 void save(writer&) const;
88 void load(reader&);
90 std::string info() const;
92 std::string ghost_name;
93 int exp;
94 unsigned short place;
97 // This is the structure that Lua sees.
98 struct kill_exp
100 int nkills;
101 int exp;
102 std::string base_name;
103 std::string desc;
105 int monnum; // Number of the beast
106 int modifier; // Nature of the beast
108 std::vector<unsigned short> places;
110 kill_exp(const kill_def &k, const kill_monster_desc &md)
111 : nkills(k.kills), exp(k.exp), base_name(k.base_name(md)),
112 desc(k.info(md)),
113 monnum(md.monnum), modifier(md.modifier)
115 places = k.places;
118 kill_exp(const kill_ghost &kg)
119 : nkills(1), exp(kg.exp), base_name(), desc(kg.info()),
120 monnum(-1), modifier(0)
122 places.push_back(kg.place);
125 // operator< is implemented for a descending sort.
126 bool operator < (const kill_exp &b) const
128 return exp == b.exp? (base_name < b.base_name) : (exp > b.exp);
132 class Kills
134 public:
135 void record_kill(const monster* mon);
136 void merge(const Kills &k);
138 bool empty() const;
139 void save(writer&) const;
140 void load(reader&);
142 int get_kills(std::vector<kill_exp> &v) const;
143 int num_kills(const monster* mon) const;
144 private:
145 typedef std::map<kill_monster_desc,
146 kill_def,
147 kill_monster_desc::less_than> kill_map;
148 typedef std::vector<kill_ghost> ghost_vec;
150 kill_map kills;
151 ghost_vec ghosts;
153 void record_ghost_kill(const monster* mon);
156 class KillMaster
158 public:
159 KillMaster();
160 KillMaster(const KillMaster& other);
161 ~KillMaster();
163 void record_kill(const monster* mon, int killer, bool ispet);
165 bool empty() const;
166 void save(writer&) const;
167 void load(reader&);
169 // Number of kills, by category.
170 int num_kills(const monster* mon, kill_category cat) const;
171 // Number of kills, any category.
172 int num_kills(const monster* mon) const;
174 int total_kills() const;
176 std::string kill_info() const;
177 private:
178 const char *category_name(kill_category kc) const;
180 Kills categorized_kills[KC_NCATEGORIES];
181 private:
182 void add_kill_info(std::string &, std::vector<kill_exp> &,
183 int count, const char *c, bool separator)
184 const;
187 enum KILL_DUMP_OPTIONS
189 KDO_NO_PLACES, // Don't dump places at all
190 KDO_ONE_PLACE, // Show places only for single kills and uniques.
191 KDO_ALL_PLACES, // Show all available place information
194 #endif