| 1 |  | 
|---|
| 2 |  | 
|---|
| 3 | /* | 
|---|
| 4 |    orxonox - the future of 3D-vertical-scrollers | 
|---|
| 5 |  | 
|---|
| 6 |    Copyright (C) 2004 orx | 
|---|
| 7 |  | 
|---|
| 8 |    This program is free software; you can redistribute it and/or modify | 
|---|
| 9 |    it under the terms of the GNU General Public License as published by | 
|---|
| 10 |    the Free Software Foundation; either version 2, or (at your option) | 
|---|
| 11 |    any later version. | 
|---|
| 12 |  | 
|---|
| 13 |    ### File Specific: | 
|---|
| 14 |    main-programmer: Patrick Boenzli | 
|---|
| 15 |    co-programmer: ... | 
|---|
| 16 | */ | 
|---|
| 17 |  | 
|---|
| 18 |  | 
|---|
| 19 | #include "base_object.h" | 
|---|
| 20 | #include "load_param.h" | 
|---|
| 21 | #include "compiler.h" | 
|---|
| 22 |  | 
|---|
| 23 | using namespace std; | 
|---|
| 24 |  | 
|---|
| 25 |  | 
|---|
| 26 | /** | 
|---|
| 27 |    \brief sets the name from a LoadXML-Element | 
|---|
| 28 |    \param root the element to load from | 
|---|
| 29 | */ | 
|---|
| 30 | BaseObject::BaseObject(const TiXmlElement* root) | 
|---|
| 31 | { | 
|---|
| 32 |   this->className = NULL; | 
|---|
| 33 |   this->classID = CL_BASE_OBJECT; | 
|---|
| 34 |   this->finalized = false; | 
|---|
| 35 |  | 
|---|
| 36 |   this->objectName = NULL; | 
|---|
| 37 |  | 
|---|
| 38 |   if (root) | 
|---|
| 39 |     this->loadParams(root); | 
|---|
| 40 | } | 
|---|
| 41 |  | 
|---|
| 42 | /** | 
|---|
| 43 |    \brief standard deconstructor | 
|---|
| 44 | */ | 
|---|
| 45 | BaseObject::~BaseObject () | 
|---|
| 46 | { | 
|---|
| 47 |   //  delete []this->className; | 
|---|
| 48 |   if (this->objectName) | 
|---|
| 49 |     delete []this->objectName; | 
|---|
| 50 | } | 
|---|
| 51 |  | 
|---|
| 52 | /** | 
|---|
| 53 |    \brief loads parameters | 
|---|
| 54 |    \param root the element to load from | 
|---|
| 55 | */ | 
|---|
| 56 | void BaseObject::loadParams(const TiXmlElement* root) | 
|---|
| 57 | { | 
|---|
| 58 |   // name setup | 
|---|
| 59 |   LoadParam<BaseObject>(root, "name", this, &BaseObject::setName) | 
|---|
| 60 |   .describe("the name of the Object at hand"); | 
|---|
| 61 | } | 
|---|
| 62 |  | 
|---|
| 63 | /** | 
|---|
| 64 |    \brief sets the class identifiers | 
|---|
| 65 |    \param id a number for the class from class_list.h enumeration | 
|---|
| 66 |    \param className the class name | 
|---|
| 67 | */ | 
|---|
| 68 | void BaseObject::setClassID(long classID, const char* className) | 
|---|
| 69 | { | 
|---|
| 70 |   this->setClassID(classID); | 
|---|
| 71 |   this->setClassName(className); | 
|---|
| 72 | } | 
|---|
| 73 |  | 
|---|
| 74 |  | 
|---|
| 75 | /** | 
|---|
| 76 |    \brief sets the class identifier | 
|---|
| 77 |    \param id a number for the class from class_list.h enumeration | 
|---|
| 78 | */ | 
|---|
| 79 | void BaseObject::setClassID (long classID) | 
|---|
| 80 | { | 
|---|
| 81 |   this->classID |= classID; | 
|---|
| 82 | } | 
|---|
| 83 |  | 
|---|
| 84 |  | 
|---|
| 85 | /** | 
|---|
| 86 |    \brief sets the class identifiers | 
|---|
| 87 |    \param className the class name | 
|---|
| 88 | */ | 
|---|
| 89 | void BaseObject::setClassName(const char* className) | 
|---|
| 90 | { | 
|---|
| 91 |   this->className = className; | 
|---|
| 92 | } | 
|---|
| 93 |  | 
|---|
| 94 | /** | 
|---|
| 95 |   \brief set the name of the Object | 
|---|
| 96 |  */ | 
|---|
| 97 |              void BaseObject::setName (const char* objectName) | 
|---|
| 98 | { | 
|---|
| 99 |   if (this->objectName) | 
|---|
| 100 |     delete []this->objectName; | 
|---|
| 101 |   if (objectName) | 
|---|
| 102 |   { | 
|---|
| 103 |     this->objectName = new char[strlen(objectName)+1]; | 
|---|
| 104 |     strcpy(this->objectName, objectName); | 
|---|
| 105 |   } | 
|---|
| 106 |   else | 
|---|
| 107 |     this->objectName = NULL; | 
|---|
| 108 | } | 
|---|
| 109 |  | 
|---|
| 110 |  | 
|---|
| 111 | /** | 
|---|
| 112 |    \brief checks if the class is a classID | 
|---|
| 113 |    \param classID the Identifier to check for | 
|---|
| 114 |    \returns true if it is, false otherwise | 
|---|
| 115 | */ | 
|---|
| 116 | bool BaseObject::isA (ClassID classID) const | 
|---|
| 117 | { | 
|---|
| 118 |   // if classID is a derivable object | 
|---|
| 119 |   if (likely(classID & CL_MASK_SUPER_CLASS || classID & CL_MASK_SUBSUPER_CLASS)) | 
|---|
| 120 |   { | 
|---|
| 121 |     if( this->classID & classID) | 
|---|
| 122 |       return true; | 
|---|
| 123 |   } | 
|---|
| 124 |   // if classID is a LOWLEVEL-class | 
|---|
| 125 |   else | 
|---|
| 126 |   { | 
|---|
| 127 |     if ((this->classID & CL_MASK_LOWLEVEL_CLASS) == classID) | 
|---|
| 128 |       return true; | 
|---|
| 129 |   } | 
|---|
| 130 |   return false; | 
|---|
| 131 | } | 
|---|
| 132 |  | 
|---|
| 133 | /** | 
|---|
| 134 |  * @brief displays everything this class is | 
|---|
| 135 |  */ | 
|---|
| 136 | void BaseObject::whatIs(void) const | 
|---|
| 137 | { | 
|---|
| 138 |   PRINT(0)("object %s of class %s: ", this->getName(), this->getClassName()); | 
|---|
| 139 |   if ((this->classID & CL_MASK_SINGLETON) == CL_MASK_SINGLETON) | 
|---|
| 140 |     PRINT(0)("is a Singleton-Class "); | 
|---|
| 141 |   if (this->classID & CL_MASK_SUPER_CLASS) | 
|---|
| 142 |   { | 
|---|
| 143 |     PRINT(0)(" ->is a derived from the following superclasses:"); | 
|---|
| 144 |     if (this->isA(CL_BASE_OBJECT)) | 
|---|
| 145 |       PRINT(0)(" =BaseObject="); | 
|---|
| 146 |     if (this->isA(CL_PARENT_NODE)) | 
|---|
| 147 |       PRINT(0)(" =PNode="); | 
|---|
| 148 |     if (this->isA(CL_WORLD_ENTITY)) | 
|---|
| 149 |       PRINT(0)(" =WorldEntity="); | 
|---|
| 150 |     if (this->isA(CL_PHYSICS_INTERFACE)) | 
|---|
| 151 |       PRINT(0)(" =PhysicsInterface="); | 
|---|
| 152 |     if (this->isA(CL_EVENT_LISTENER)) | 
|---|
| 153 |       PRINT(0)(" =EventListener="); | 
|---|
| 154 |     if (this->isA(CL_STORY_ENTITY)) | 
|---|
| 155 |       PRINT(0)(" =StoryEntity="); | 
|---|
| 156 |     PRINT(0)("\n"); | 
|---|
| 157 |   } | 
|---|
| 158 |   // subsuper-classes | 
|---|
| 159 |   if (this->classID & CL_MASK_SUBSUPER_CLASS) | 
|---|
| 160 |   { | 
|---|
| 161 |     PRINT(0)(" ->further derivations: "); | 
|---|
| 162 |     if (this->isA(CL_PLAYER)) | 
|---|
| 163 |       PRINT(0)(" -Player-"); | 
|---|
| 164 |     if (this->isA(CL_NPC)) | 
|---|
| 165 |       PRINT(0)(" -NPC-"); | 
|---|
| 166 |     if (this->isA(CL_POWER_UP)) | 
|---|
| 167 |       PRINT(0)(" -PowerUp-"); | 
|---|
| 168 |     if (this->isA(CL_FIELD)) | 
|---|
| 169 |       PRINT(0)(" -Field-"); | 
|---|
| 170 |     if (this->isA(CL_PROJECTILE)) | 
|---|
| 171 |       PRINT(0)(" -Projectile-"); | 
|---|
| 172 |     if (this->isA(CL_WEAPON)) | 
|---|
| 173 |       PRINT(0)(" -Weapon-"); | 
|---|
| 174 |     PRINT(0)("\n"); | 
|---|
| 175 |   } | 
|---|
| 176 | } | 
|---|