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_ACCESSORYSTORE_H__6A964E56_3784_42FA_A900_2AB4B98F99A8__INCLUDED_)
22 #define AFX_ACCESSORYSTORE_H__6A964E56_3784_42FA_A900_2AB4B98F99A8__INCLUDED_
23 
24 #include <list>
25 #include <vector>
26 #include <map>
27 #include <set>
28 #include <weapons/Weapon.h>
29 #include <weapons/Accessory.h>
30 #include <weapons/AccessoryCreateContext.h>
31 #include <common/ProgressCounter.h>
32 
33 class XMLNode;
34 class NamedNetBuffer;
35 class AccessoryStore
36 {
37 public:
38 
39 	// This is mirrored by accessorySortKeyEnum in client/graph/OptionsDisplay.cpp.
40 
41 	enum SortKey
42 	{
43 		SortNothing = 0,
44 		SortName = 1,
45 		SortPrice = 2
46 	};
47 
48 	AccessoryStore();
49 	virtual ~AccessoryStore();
50 
51 	bool parseFile(ScorchedContext &context, ProgressCounter *counter = 0);
52 	void clearAccessories();
53 
54 	Accessory *findByAccessoryId(unsigned int id);
55 	Accessory *findByPrimaryAccessoryName(const char *name); // **careful there**
56 	AccessoryPart *findAccessoryPartByAccessoryId(unsigned int id, const char *type);
57 	AccessoryPart *createAccessoryPart(AccessoryCreateContext &context,
58 		Accessory *parent, XMLNode *currentNode);
59 	AccessoryPart *findByAccessoryPartId(unsigned int id);
60 
61 	Weapon *getDeathAnimation();
62 	Weapon *getMuzzelFlash();
63 
64 	std::list<Accessory *> getAllAccessories(int sortKey=SortNothing);
65 	std::list<Accessory *> getAllAccessoriesByTabGroup(const char *tabgroup, int sortKey=SortNothing);
getParsingNodes()66 	std::map<std::string, XMLNode *> &getParsingNodes() { return parsingNodes_; }
getTabGroupNames()67 	std::set<std::string> &getTabGroupNames() { return tabGroups_; }
68 
69 	bool writeWeapon(NamedNetBuffer &buffer, Weapon *weapon);
70 	bool readWeapon(NetBufferReader &reader, Weapon *&weapon);
71 	bool writeAccessoryPart(NamedNetBuffer &buffer, AccessoryPart *weapon);
72 	bool readAccessoryPart(NetBufferReader &reader, AccessoryPart *&part);
73 
74 	bool writeEconomyToBuffer(NetBuffer &buffer);
75 	bool readEconomyFromBuffer(NetBufferReader &reader);
76 
77 	void sortList(std::list<Accessory *> &accList, int sortKey=SortNothing);
78 
79 protected:
80 	std::set<std::string> tabGroups_;
81 	std::list<Accessory *> accessories_;
82 	std::list<AccessoryPart *> accessoryParts_;
83 	std::map<std::string, XMLNode *> parsingNodes_;
84 	Weapon *muzzleFlash_;
85 	Weapon *deathAnimation_;
86 
87 };
88 
89 #endif // !defined(AFX_ACCESSORYSTORE_H__6A964E56_3784_42FA_A900_2AB4B98F99A8__INCLUDED_)
90