AccessoryPart.h

Go to the documentation of this file.
00001 ////////////////////////////////////////////////////////////////////////////////
00002 //    Scorched3D (c) 2000-2009
00003 //
00004 //    This file is part of Scorched3D.
00005 //
00006 //    Scorched3D is free software; you can redistribute it and/or modify
00007 //    it under the terms of the GNU General Public License as published by
00008 //    the Free Software Foundation; either version 2 of the License, or
00009 //    (at your option) any later version.
00010 //
00011 //    Scorched3D is distributed in the hope that it will be useful,
00012 //    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 //    GNU General Public License for more details.
00015 //
00016 //    You should have received a copy of the GNU General Public License
00017 //    along with Scorched3D; if not, write to the Free Software
00018 //    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019 ////////////////////////////////////////////////////////////////////////////////
00020 
00021 #if !defined(AFX_ACCESSORYPART_H__21765D5B_DB45_4275_AB63_BAD1E84C1790__INCLUDED_)
00022 #define AFX_ACCESSORYPART_H__21765D5B_DB45_4275_AB63_BAD1E84C1790__INCLUDED_
00023 
00024 #include <XML/XMLFile.h>
00025 #include <net/NetBuffer.h>
00026 #include <map>
00027 
00028 #define REGISTER_ACCESSORY_HEADER(x, y) \
00029         virtual const char *getAccessoryTypeName() { return #x ; } \
00030         virtual AccessoryType getType() { return y ; } \
00031         virtual AccessoryPart *getAccessoryCopy() { return new x ; }
00032 
00033 #define REGISTER_ACCESSORY_SOURCE(x) \
00034         struct META_##x { META_##x() { AccessoryMetaRegistration::addMap(#x , new x ); } }; \
00035         static META_##x META_IMPL_##x ;
00036 
00037 class Accessory;
00038 class AccessoryStore;
00039 class AccessoryCreateContext;
00040 class AccessoryPart  
00041 {
00042 public:
00043         enum AccessoryType
00044         {
00045                 AccessoryWeapon,
00046                 AccessoryParachute,
00047                 AccessoryShield,
00048                 AccessoryAutoDefense,
00049                 AccessoryBattery
00050         };
00051 
00052         AccessoryPart();
00053         virtual ~AccessoryPart();
00054 
00055         void setParent(Accessory *parent) { parent_ = parent; }
00056         Accessory *getParent() { return parent_; }
00057 
00058         unsigned int getAccessoryPartId() { return accessoryPartId_; }
00059         static void resetAccessoryPartIds() { nextAccessoryPartId_ = 100000; }
00060 
00061         virtual bool parseXML(AccessoryCreateContext &context, XMLNode *accessoryNode) = 0;
00062         virtual AccessoryType getType() = 0;
00063         virtual const char *getAccessoryTypeName() = 0;
00064         virtual AccessoryPart *getAccessoryCopy() = 0;
00065 
00066 protected:
00067         static unsigned int nextAccessoryPartId_;
00068         unsigned int accessoryPartId_;
00069         Accessory *parent_;
00070 
00071 };
00072 
00073 class AccessoryMetaRegistration
00074 {
00075 public:
00076         static void addMap(const char *name, AccessoryPart *action);
00077         static AccessoryPart *getNewAccessory(const char *name, AccessoryStore *store);
00078 
00079 private:
00080         static std::map<std::string, AccessoryPart *> *accessoryMap;
00081 };
00082 
00083 #endif // !defined(AFX_ACCESSORYPART_H__21765D5B_DB45_4275_AB63_BAD1E84C1790__INCLUDED_)

Generated on Mon Feb 16 15:14:52 2009 for Scorched3D by  doxygen 1.5.3