Labyrinth
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends
sw.hpp
1 //////////////////////////////
2 //
3 // File: swrs/sw.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_H_
15 #define __SW_H_
16 #include "swrs/traitmap.hpp"
17 #include "swrs/edgemap.hpp"
18 #include "swrs/racemap.hpp"
19 #include "swrs/powermap.hpp"
20 #include "swrs/hindrancemap.hpp"
21 //!@brief Savage Worlds rules system (really a flexible rules engine able to implement any SW-dereived rules set)
22 namespace SWRS
23 {
24  class Character;
25  //! Main class (serving also as a factory class for characters) of a savage worlds rules system implementation
27  {
28  RaceMap global_race_map;
29  TraitMap global_trait_map;
30  HindranceMap global_hindrance_map;
31  EdgeMap global_edge_map;
32  PowerMap global_power_map;
33  static int trait_representation;
34  public:
35  //! when traits are represented in stringified format
36  enum
37  {
38  //! "d4" "d6" "d8"
39  SW,
40  //! "strong" "weak"
42  //! "**" "****"
44  };
45  //! SW, Verbal, Pips
46  static void SetTraitRepresentation(int f) {trait_representation=f;}
47  //! SW, Verbal, Pips
48  static int GetTraitRepresentation() {return trait_representation;}
49 
50  //! initialize with given path to config file
51  void Initialize(const std::string & path);
52  //! Generate new character with blank character sheet
54  //! Load from file
55  Character LoadCharacterFromFile(const std::string & path) const;
56  //! Load character from file using openat (2)
57  Character LoadCharacterFromFileAt(int fd, const std::string & path) const;
58  //! Load character from memory string (must be null terminated)
59  Character LoadCharacterFromMemory(const char * data) const;
60  //! Serialize character; returned character is null terminated string that is
61  //! malloc(3) allocated and needs to be freed after using
62  const char * SerializeCharacter(const Character&) const;
63 
64  //! store character in file (0 returned upon success)
65  int SaveCharacter(const Character&, const std::string & path) const;
66  //! store character in file using openat (0 returned upon success)
67  int SaveCharacterAt(const Character&, int fd, const std::string & path) const;
68 
69  //! return map of traits loaded from config (and available to characters)
70  const TraitMap & GetTraitMap() const
71  {
72  return global_trait_map;
73  }
74  //! return map of hindrances loaded from config (and available to characters)
75  const HindranceMap & GetHindranceMap() const
76  {
77  return global_hindrance_map;
78  }
79  //! return map of edges loaded from config (and available to characters)
80  const EdgeMap & GetEdgeMap() const
81  {
82  return global_edge_map;
83  }
84  //! return map of powers loaded from config (and available to characters)
85  const PowerMap & GetPowerMap()const
86  {
87  return global_power_map;
88  }
89  };
90 }
91 #endif