Labyrinth
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends
traitmap.hpp
1 //////////////////////////////
2 //
3 // File: swrs/traitmap.hpp
4 // Author: Maciej Kaminski
5 // E-mail: maciej.a.kaminski@gmail.com
6 // Website: maciejkaminski.pl
7 //
8 // File creation date: Oct 30 2012
9 // This file is part of Project Labyrinth
10 // This file is going to be released under terms of GNU GPL in near future
11 //
12 //////////////////////////////
13 
14 #ifndef __SW_TRAIT_MAP_H_
15 #define __SW_TRAIT_MAP_H_
16 #include <utility>
17 #include <vector>
18 #include <string>
19 #include <map>
20 #include "swrs/trait.hpp"
21 #include "swrs/character.hpp"
22 #include "swrs/optionsmap.hpp"
23 
24 namespace SWRS
25 {
26  class Character;
27  //! used for associating trait names with their logical representations
28  class TraitMap: public OptionsMap
29  {
30  friend class RulesSystem;
31  //typedef std::pair<std::string,int> TraitId;
32  // first is name; second is parent id; if id is 0, than it is name of an
33  // attribute; otherwise we have naame of skill and id of parent attribute
34  typedef std::vector<TraitRecord> TraitIdVector;
35  typedef std::map<std::string, int> StringMap;
36  TraitIdVector traits_vector;
37  StringMap trait_names_map;
38  //! initializer function
39  void ReadTraitMap(const char * filename);
40  //! print contents of map to standard output
41  void PrintSummary();
42  friend class CharacterImpl;
43  //! Return parent trait of trait given
44  //! \param id id of trait
45  //! \return -1 = attribute; 0-... = skill; -2= error!
46  int GetParentId(int id) const;
47  //! get highest valid trait id in the system
48  int GetMaxTraitId() const
49  {
50  return traits_vector.size()-1;
51  }
52  //! Return iterator to std::map<std::string, int> containing name and id of particular trait
53  StringMap::const_iterator GetTraitIdExt(const std::string & trait_name) const;
54  //! get id of trait given by name
55  int GetTraitId(const std::string & trait_name) const;
56  //! get name of trait given by ID
57  const std::string& GetTraitName(int trait_id) const
58  {
59  return traits_vector[trait_id].name;
60  }
61  public:
62  //! \brief generate trait object given by name for a character given
63  //!if appropriately
64  //! named trait is SKILL, SKILL is returned; attribute otherwise
65  Trait * GenerateTrait(const std::string & trait_name,
66  const ICharacter & chr)const;
67  };
68 }
69 #endif