00001
00002
00003
00004
00005
00006
00007 #ifndef KILLS_H
00008 #define KILLS_H
00009
00010 #include <vector>
00011 #include <string>
00012 #include <map>
00013 #include <stdio.h>
00014 #include "enum.h"
00015
00016 class monster;
00017 class reader;
00018 class writer;
00019
00020
00021 struct kill_monster_desc
00022 {
00023 kill_monster_desc(const monster*);
00024 kill_monster_desc() { }
00025
00026 void save(writer&) const;
00027 void load(reader&);
00028
00029 enum name_modifier
00030 {
00031 M_NORMAL, M_ZOMBIE, M_SKELETON, M_SIMULACRUM, M_SPECTRE,
00032 M_SHAPESHIFTER,
00033 };
00034
00035 int monnum;
00036 name_modifier modifier;
00037
00038 struct less_than
00039 {
00040 bool operator () (const kill_monster_desc &m1,
00041 const kill_monster_desc &m2) const
00042 {
00043 return (m1.monnum < m2.monnum
00044 || (m1.monnum == m2.monnum && m1.modifier < m2.modifier));
00045 }
00046 };
00047 };
00048
00049 #define PLACE_LIMIT 5 // How many unique kill places we're prepared to track
00050 class kill_def
00051 {
00052 public:
00053 kill_def(const monster* mon);
00054 kill_def() : kills(0), exp(0)
00055 {
00056
00057 }
00058
00059 void save(writer&) const;
00060 void load(reader&);
00061
00062 void add_kill(const monster* mon, unsigned short place);
00063 void add_place(unsigned short place, bool force = false);
00064
00065 void merge(const kill_def &k, bool unique_monster);
00066
00067 std::string info(const kill_monster_desc &md) const;
00068 std::string base_name(const kill_monster_desc &md) const;
00069
00070 unsigned short kills;
00071 int exp;
00072
00073
00074 std::vector<unsigned short> places;
00075 private:
00076 std::string append_places(const kill_monster_desc &md,
00077 const std::string &name) const;
00078 };
00079
00080
00081 class kill_ghost
00082 {
00083 public:
00084 kill_ghost(const monster* mon);
00085 kill_ghost() { }
00086
00087 void save(writer&) const;
00088 void load(reader&);
00089
00090 std::string info() const;
00091
00092 std::string ghost_name;
00093 int exp;
00094 unsigned short place;
00095 };
00096
00097
00098 struct kill_exp
00099 {
00100 int nkills;
00101 int exp;
00102 std::string base_name;
00103 std::string desc;
00104
00105 int monnum;
00106 int modifier;
00107
00108 std::vector<unsigned short> places;
00109
00110 kill_exp(const kill_def &k, const kill_monster_desc &md)
00111 : nkills(k.kills), exp(k.exp), base_name(k.base_name(md)),
00112 desc(k.info(md)),
00113 monnum(md.monnum), modifier(md.modifier)
00114 {
00115 places = k.places;
00116 }
00117
00118 kill_exp(const kill_ghost &kg)
00119 : nkills(1), exp(kg.exp), base_name(), desc(kg.info()),
00120 monnum(-1), modifier(0)
00121 {
00122 places.push_back(kg.place);
00123 }
00124
00125
00126 bool operator < (const kill_exp &b) const
00127 {
00128 return exp == b.exp? (base_name < b.base_name) : (exp > b.exp);
00129 }
00130 };
00131
00132 class Kills
00133 {
00134 public:
00135 void record_kill(const monster* mon);
00136 void merge(const Kills &k);
00137
00138 bool empty() const;
00139 void save(writer&) const;
00140 void load(reader&);
00141
00142 int get_kills(std::vector<kill_exp> &v) const;
00143 int num_kills(const monster* mon) const;
00144 private:
00145 typedef std::map<kill_monster_desc,
00146 kill_def,
00147 kill_monster_desc::less_than> kill_map;
00148 typedef std::vector<kill_ghost> ghost_vec;
00149
00150 kill_map kills;
00151 ghost_vec ghosts;
00152
00153 void record_ghost_kill(const monster* mon);
00154 };
00155
00156 class KillMaster
00157 {
00158 public:
00159 KillMaster();
00160 KillMaster(const KillMaster& other);
00161 ~KillMaster();
00162
00163 void record_kill(const monster* mon, int killer, bool ispet);
00164
00165 bool empty() const;
00166 void save(writer&) const;
00167 void load(reader&);
00168
00169
00170 int num_kills(const monster* mon, kill_category cat) const;
00171
00172 int num_kills(const monster* mon) const;
00173
00174 int total_kills() const;
00175
00176 std::string kill_info() const;
00177 private:
00178 const char *category_name(kill_category kc) const;
00179
00180 Kills categorized_kills[KC_NCATEGORIES];
00181 private:
00182 void add_kill_info(std::string &, std::vector<kill_exp> &,
00183 int count, const char *c, bool separator)
00184 const;
00185 };
00186
00187 enum KILL_DUMP_OPTIONS
00188 {
00189 KDO_NO_PLACES,
00190 KDO_ONE_PLACE,
00191 KDO_ALL_PLACES,
00192 };
00193
00194 #endif