JNR
rpgSheet.h
1 /*
2 
3 Jump'n'Run Engine
4 http://www.atanaslaskov.com/jnr/
5 
6 BSD LICENSE
7 Copyright (c) 2007-2013, Atanas Laskov
8 All rights reserved.
9 
10 Redistribution and use in source and binary forms, with or without
11 modification, are permitted provided that the following conditions are met:
12 1. Redistributions of source code must retain the above copyright notice,
13 this list of conditions and the following disclaimer.
14 2. Redistributions in binary form must reproduce the above copyright notice,
15 this list of conditions and the following disclaimer in the documentation
16 and/or other materials provided with the distribution.
17 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 DISCLAIMED. IN NO EVENT SHALL ATANAS LASKOV BE LIABLE FOR ANY
21 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 
28 */
29 #ifndef M_SHEET_H
30 #define M_SHEET_H
31 
33 
34 
43 #define M_SHEET_PROPS_COPY(class_name) \
44  virtual void copy_to(rpgSheet_Props* ptarget){ \
45  class_name *ps = (class_name*) ptarget; \
46  *ps = *this; \
47  }
48 
49 // Abstract properties sheet
50 //
51 class rpgSheet_Props: public laLoadableObj{
52 public:
53 
54  // Data members in derrived classes
55 
56  // Copy data members
57  virtual void copy_to(rpgSheet_Props* ptarget) = 0;
58 
59  // Load from TS
60  virtual void load(class laPropertyList* pElement) = 0;
61 
64  virtual void load(class laFileParser *fp) = 0;
65  virtual void save(class laFileParser *fp) { ASSERT(M_FALSE, "Not Implemented"); };
66 };
67 
68 // Abstract sheet modifiers
69 //
70 class rpgSheet_Mods{
71 public:
72 
73  // Reset to initial values
74  virtual void reset() = 0;
75 
76  // Apply to another modifier
77  virtual void apply(rpgSheet_Mods *pTarget) = 0;
78 
79  // NOTE: The modifiers object desn't need load/save from file,
80  // because this information will not be stored in savegames
81 
82  // Load modifers from TS
83  virtual void load(class laPropertyList* pElement) = 0;
84 };
85 
86 // This makes the access to sheet properties a bit more convenient
87 //
88 #define M_SHEET_BEGIN(class_name, class_base) \
89 class class_name: public class_base { \
90 public: \
91  \
92  inline class_name##_Props* properties() { return (class_name##_Props*)_pProperties; }; \
93  inline class_name##_Mods* modifiers() { return (class_name##_Mods*)_pActiveModifiers; }; \
94  \
95  class_name( \
96  rpgSheet_Props* pp = NULL, rpgSheet_Props *ppc = NULL, rpgSheet_Mods *pm = NULL) \
97  : class_base( \
98  pp? pp : new class_name##_Props(), \
99  ppc? ppc : new class_name##_Props(), \
100  pm? pm : new class_name##_Mods() ) \
101  { } \
102 
103 #define M_SHEET_END }
104 
105 // Abstract sheet
106 //
107 class rpgSheet: public laLoadableObj
108 {
109 protected:
110  rpgSheet_Props* _pProperties; // sheet RPG properties
111  rpgSheet_Props* _pPropUnchanged; // unchanged copy of the properties
112 
113  // Active modifiers
114  rpgSheet_Mods* _pActiveModifiers;
115 
116 public:
117 
118  M_BOOL bResetProperties;
119 
120  // Constructor/destr
121  //
122  rpgSheet(rpgSheet_Props* pp, rpgSheet_Props *ppc, rpgSheet_Mods *pm);
123  virtual ~rpgSheet();
124 
125  // Get props and mods
126  //
127  //inline rpgSheet_Props* getProperties() { return _pProperties; };
128  //inline rpgSheet_Mods* getModifiers() { return _pActiveModifiers; };
129 
130  // Reset sheet to unchanged copy
131  void reset();
132 
133  // Load from TS
134  virtual void load(class laPropertyList* pElement);
135 
140  virtual void load(class laFileParser *fp);
141  virtual void save(class laFileParser *fp);
142 };
144 #endif
Interface for loadable objects.
Definition: laLoadableObj.h:43
Abstract RPG Properties Sheet.
Definition: rpgSheet.h:107
File Parser.
Definition: laFileParser.h:41