1 ////////////////////////////////////////////////////////////////////////////////
2 //    Scorched3D (c) 2000-2011
3 //
4 //    This file is part of Scorched3D.
5 //
6 //    Scorched3D is free software; you can redistribute it and/or modify
7 //    it under the terms of the GNU General Public License as published by
8 //    the Free Software Foundation; either version 2 of the License, or
9 //    (at your option) any later version.
10 //
11 //    Scorched3D is distributed in the hope that it will be useful,
12 //    but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 //    GNU General Public License for more details.
15 //
16 //    You should have received a copy of the GNU General Public License along
17 //    with this program; if not, write to the Free Software Foundation, Inc.,
18 //    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 ////////////////////////////////////////////////////////////////////////////////
20 
21 #if !defined(AFX_ACCESSORYPART_H__21765D5B_DB45_4275_AB63_BAD1E84C1790__INCLUDED_)
22 #define AFX_ACCESSORYPART_H__21765D5B_DB45_4275_AB63_BAD1E84C1790__INCLUDED_
23 
24 #include <XML/XMLFile.h>
25 #include <net/NetBuffer.h>
26 #include <map>
27 
28 #define REGISTER_ACCESSORY_HEADER(x, y) \
29 	virtual const char *getAccessoryTypeName() { return #x ; } \
30 	virtual AccessoryType getType() { return y ; } \
31 	virtual AccessoryPart *getAccessoryCopy() { return new x ; }
32 
33 #define REGISTER_ACCESSORY_SOURCE(x) \
34 	struct META_##x { META_##x() { AccessoryMetaRegistration::addMap(#x , new x ); } }; \
35 	static META_##x META_IMPL_##x ;
36 
37 class Accessory;
38 class AccessoryStore;
39 class AccessoryCreateContext;
40 class AccessoryPart
41 {
42 public:
43 	enum AccessoryType
44 	{
45 		AccessoryWeapon,
46 		AccessoryParachute,
47 		AccessoryShield,
48 		AccessoryAutoDefense,
49 		AccessoryBattery
50 	};
51 
52 	AccessoryPart();
53 	virtual ~AccessoryPart();
54 
setParent(Accessory * parent)55 	void setParent(Accessory *parent) { parent_ = parent; }
getParent()56 	Accessory *getParent() { return parent_; }
57 
getAccessoryPartId()58 	unsigned int getAccessoryPartId() { return accessoryPartId_; }
resetAccessoryPartIds()59 	static void resetAccessoryPartIds() { nextAccessoryPartId_ = 100000; }
60 
61 	virtual bool parseXML(AccessoryCreateContext &context, XMLNode *accessoryNode) = 0;
62 	virtual AccessoryType getType() = 0;
63 	virtual const char *getAccessoryTypeName() = 0;
64 	virtual AccessoryPart *getAccessoryCopy() = 0;
65 
66 protected:
67 	static unsigned int nextAccessoryPartId_;
68 	unsigned int accessoryPartId_;
69 	Accessory *parent_;
70 
71 };
72 
73 class AccessoryMetaRegistration
74 {
75 public:
76 	static void addMap(const char *name, AccessoryPart *action);
77 	static AccessoryPart *getNewAccessory(const char *name, AccessoryStore *store);
78 
79 private:
80 	static std::map<std::string, AccessoryPart *> *accessoryMap;
81 };
82 
83 #endif // !defined(AFX_ACCESSORYPART_H__21765D5B_DB45_4275_AB63_BAD1E84C1790__INCLUDED_)
84