summaryrefslogtreecommitdiffstats
path: root/trunk/source/Kills.h
diff options
context:
space:
mode:
authordshaligram <dshaligram@c06c8d41-db1a-0410-9941-cceddc491573>2006-08-02 12:54:15 +0000
committerdshaligram <dshaligram@c06c8d41-db1a-0410-9941-cceddc491573>2006-08-02 12:54:15 +0000
commitd5e5340c3926d1cf97f6cba151ffaecb20bfb35f (patch)
treed1faf7d5b27df8f3c523a8dd33357804118e62b1 /trunk/source/Kills.h
parent7b2204d69f21d7075e4666ee032d7a129081bc4b (diff)
downloadcrawl-ref-d5e5340c3926d1cf97f6cba151ffaecb20bfb35f.tar.gz
crawl-ref-d5e5340c3926d1cf97f6cba151ffaecb20bfb35f.zip
Integrated travel patch as of 20060727
git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@7 c06c8d41-db1a-0410-9941-cceddc491573
Diffstat (limited to 'trunk/source/Kills.h')
-rw-r--r--trunk/source/Kills.h186
1 files changed, 186 insertions, 0 deletions
diff --git a/trunk/source/Kills.h b/trunk/source/Kills.h
new file mode 100644
index 0000000000..28c30a88c8
--- /dev/null
+++ b/trunk/source/Kills.h
@@ -0,0 +1,186 @@
+/*
+ * File: Kills.h
+ * Summary: Tracks monsters the player has killed.
+ * Written by: Darshan Shaligram
+ */
+#ifndef KILLS_H
+#define KILLS_H
+
+#include <vector>
+#include <string>
+#include <map>
+#include <stdio.h>
+#include "enum.h"
+
+struct monsters;
+
+// Not intended for external use!
+struct kill_monster_desc
+{
+ kill_monster_desc(const struct monsters *);
+ kill_monster_desc() { }
+
+ void save(FILE*) const;
+ void load(FILE*);
+
+ enum name_modifier
+ {
+ M_NORMAL, M_ZOMBIE, M_SKELETON, M_SIMULACRUM, M_SPECTRE,
+ M_SHAPESHIFTER // A shapeshifter pretending to be 'monnum'
+ };
+
+ int monnum; // Number of the beast
+ name_modifier modifier; // Nature of the beast
+
+ struct less_than
+ {
+ bool operator () ( const kill_monster_desc &m1,
+ const kill_monster_desc &m2) const
+ {
+ return m1.monnum < m2.monnum ||
+ (m1.monnum == m2.monnum && m1.modifier < m2.modifier);
+ }
+ };
+};
+
+#define PLACE_LIMIT 5 // How many unique kill places we're prepared to track
+class kill_def
+{
+public:
+ kill_def(const struct monsters *mon);
+ kill_def() : kills(0), exp(0)
+ {
+ // This object just says to the world that it's uninitialized
+ }
+
+ void save(FILE*) const;
+ void load(FILE*);
+
+ void add_kill(const struct monsters *mon, unsigned short place);
+ void add_place(unsigned short place, bool force = false);
+
+ void merge(const kill_def &k, bool unique_monster);
+
+ std::string info(const kill_monster_desc &md) const;
+ std::string base_name(const kill_monster_desc &md) const;
+
+ unsigned short kills; // How many kills does the player have?
+ int exp; // Experience gained for slaying the beast.
+ // Only set *once*, even for shapeshifters.
+
+ std::vector<unsigned short> places; // Places where we've killed the beast.
+private:
+ std::string append_places(const kill_monster_desc &md,
+ const std::string &name) const;
+};
+
+// Ghosts and random Pandemonium demons.
+class kill_ghost
+{
+public:
+ kill_ghost(const struct monsters *mon);
+ kill_ghost() { }
+
+ void save(FILE*) const;
+ void load(FILE*);
+
+ std::string info() const;
+
+ std::string ghost_name;
+ int exp;
+ unsigned short place;
+};
+
+// This is the structure that Lua sees.
+struct kill_exp
+{
+ int nkills;
+ int exp;
+ std::string base_name;
+ std::string desc;
+
+ int monnum; // Number of the beast
+ int modifier; // Nature of the beast
+
+ std::vector<unsigned short> places;
+
+ kill_exp(const kill_def &k, const kill_monster_desc &md)
+ : nkills(k.kills), exp(k.exp), base_name(k.base_name(md)),
+ desc(k.info(md)),
+ monnum(md.monnum), modifier(md.modifier)
+ {
+ places = k.places;
+ }
+
+ kill_exp(const kill_ghost &kg)
+ : nkills(1), exp(kg.exp), base_name(), desc(kg.info()),
+ monnum(-1), modifier(0)
+ {
+ places.push_back(kg.place);
+ }
+
+ // operator< is implemented for a descending sort.
+ bool operator < ( const kill_exp &b) const
+ {
+ return exp == b.exp? (base_name < b.base_name) : (exp > b.exp);
+ }
+};
+
+class Kills
+{
+public:
+ void record_kill(const monsters *mon);
+ void merge(const Kills &k);
+
+ bool empty() const;
+ void save(FILE*) const;
+ void load(FILE*);
+
+ long get_kills(std::vector<kill_exp> &v) const;
+private:
+ typedef std::map<kill_monster_desc,
+ kill_def,
+ kill_monster_desc::less_than> kill_map;
+ typedef std::vector<kill_ghost> ghost_vec;
+
+ kill_map kills;
+ ghost_vec ghosts;
+
+ void record_ghost_kill(const struct monsters *mon);
+};
+
+class KillMaster
+{
+public:
+ void record_kill(const monsters *mon, int killer, bool ispet);
+
+ bool empty() const;
+ void save(FILE*) const;
+ void load(FILE*);
+
+ std::string kill_info() const;
+private:
+ const char *category_name(KillCategory kc) const;
+
+ Kills categorized_kills[KC_NCATEGORIES];
+private:
+ void add_kill_info(std::string &, std::vector<kill_exp> &,
+ long count, const char *c, bool separator)
+ const;
+};
+
+unsigned short get_packed_place();
+
+unsigned short get_packed_place( unsigned char branch, int subdepth,
+ char level_type );
+
+std::string short_place_name(unsigned short place);
+
+enum KILL_DUMP_OPTIONS
+{
+ KDO_NO_PLACES, // Don't dump places at all
+ KDO_ONE_PLACE, // Show places only for single kills and uniques.
+ KDO_ALL_PLACES // Show all available place information
+};
+
+#endif