[3302] | 1 | |
---|
| 2 | |
---|
[4591] | 3 | /* |
---|
[3302] | 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 | */ |
---|
[5439] | 17 | #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_BASE |
---|
[3302] | 18 | |
---|
| 19 | #include "base_object.h" |
---|
[4747] | 20 | |
---|
[4436] | 21 | #include "load_param.h" |
---|
[4595] | 22 | #include "compiler.h" |
---|
[4747] | 23 | #include "class_list.h" |
---|
[3302] | 24 | |
---|
| 25 | using namespace std; |
---|
| 26 | |
---|
| 27 | |
---|
| 28 | /** |
---|
[4836] | 29 | * sets the name from a LoadXML-Element |
---|
| 30 | * @param root the element to load from |
---|
[5439] | 31 | */ |
---|
[4436] | 32 | BaseObject::BaseObject(const TiXmlElement* root) |
---|
[3531] | 33 | { |
---|
| 34 | this->className = NULL; |
---|
[4591] | 35 | this->classID = CL_BASE_OBJECT; |
---|
[4435] | 36 | |
---|
| 37 | this->objectName = NULL; |
---|
[4436] | 38 | |
---|
| 39 | if (root) |
---|
| 40 | this->loadParams(root); |
---|
[4747] | 41 | |
---|
[4778] | 42 | // ClassList::addToClassList(this, this->classID, "BaseObject"); |
---|
[3531] | 43 | } |
---|
[3302] | 44 | |
---|
| 45 | /** |
---|
[4836] | 46 | * standard deconstructor |
---|
[3302] | 47 | */ |
---|
[4591] | 48 | BaseObject::~BaseObject () |
---|
[3531] | 49 | { |
---|
[4747] | 50 | ClassList::removeFromClassList(this); |
---|
| 51 | |
---|
[4261] | 52 | // delete []this->className; |
---|
[4435] | 53 | if (this->objectName) |
---|
[5447] | 54 | delete[] this->objectName; |
---|
| 55 | } |
---|
[3302] | 56 | |
---|
[4436] | 57 | /** |
---|
[4836] | 58 | * loads parameters |
---|
| 59 | * @param root the element to load from |
---|
[5439] | 60 | */ |
---|
[4436] | 61 | void BaseObject::loadParams(const TiXmlElement* root) |
---|
| 62 | { |
---|
| 63 | // name setup |
---|
[5646] | 64 | LoadParamNEW(root, "name", this, BaseObject, setName) |
---|
| 65 | //LoadParamBase(root, "name", this, ExecutorObjective<BaseObject>(&BaseObject::setName)) |
---|
[5645] | 66 | .describe("the Name of the Object."); |
---|
| 67 | // LoadParam<BaseObject>(root, "name", this, &BaseObject::setName) |
---|
| 68 | //.describe("the name of the Object at hand"); |
---|
[4436] | 69 | } |
---|
[4321] | 70 | |
---|
| 71 | /** |
---|
[4836] | 72 | * sets the class identifiers |
---|
| 73 | * @param id a number for the class from class_id.h enumeration |
---|
| 74 | * @param className the class name |
---|
[4321] | 75 | */ |
---|
[4591] | 76 | void BaseObject::setClassID(long classID, const char* className) |
---|
[4320] | 77 | { |
---|
[4592] | 78 | this->classID |= classID; |
---|
[4320] | 79 | this->className = className; |
---|
[4747] | 80 | |
---|
| 81 | ClassList::addToClassList(this, classID, className); |
---|
[4320] | 82 | } |
---|
[4318] | 83 | |
---|
[4435] | 84 | /** |
---|
[4591] | 85 | \brief set the name of the Object |
---|
| 86 | */ |
---|
[4742] | 87 | void BaseObject::setName (const char* objectName) |
---|
[4435] | 88 | { |
---|
| 89 | if (this->objectName) |
---|
[5113] | 90 | delete[] this->objectName; |
---|
[5645] | 91 | if (objectName != NULL) |
---|
[4592] | 92 | { |
---|
| 93 | this->objectName = new char[strlen(objectName)+1]; |
---|
| 94 | strcpy(this->objectName, objectName); |
---|
| 95 | } |
---|
[4591] | 96 | else |
---|
[4435] | 97 | this->objectName = NULL; |
---|
| 98 | } |
---|
[4592] | 99 | |
---|
| 100 | |
---|
| 101 | /** |
---|
[4836] | 102 | * checks if the class is a classID |
---|
| 103 | * @param classID the Identifier to check for |
---|
| 104 | * @returns true if it is, false otherwise |
---|
[4592] | 105 | */ |
---|
[4747] | 106 | bool BaseObject::isA (long classID) const |
---|
[4592] | 107 | { |
---|
[4837] | 108 | // if classID is a derivable object from a SUPERCLASS |
---|
| 109 | if (classID & CL_MASK_SUPER_CLASS) |
---|
[4594] | 110 | { |
---|
[4837] | 111 | if( likely(this->classID & classID)) |
---|
[4594] | 112 | return true; |
---|
[4837] | 113 | } |
---|
| 114 | // if classID is a SubSuperClass, and |
---|
| 115 | else if (classID & CL_MASK_SUBSUPER_CLASS) |
---|
| 116 | { |
---|
| 117 | if (likely(((this->classID & CL_MASK_SUBSUPER_CLASS_ID) == (this->classID & CL_MASK_SUBSUPER_CLASS_ID)) && |
---|
| 118 | this->classID & classID & CL_MASK_SUBSUPER_CLASS_ID2)) |
---|
| 119 | return true; |
---|
| 120 | } |
---|
| 121 | // if classID is a LOWLEVEL-class |
---|
[4594] | 122 | else |
---|
| 123 | { |
---|
[4837] | 124 | if( likely((this->classID & CL_MASK_LOWLEVEL_CLASS) == classID)) |
---|
[4594] | 125 | return true; |
---|
| 126 | } |
---|
[4592] | 127 | return false; |
---|
| 128 | } |
---|
| 129 | |
---|
| 130 | /** |
---|
[5513] | 131 | * checks if the class is a classID |
---|
| 132 | * @param classID the Identifier to check for |
---|
| 133 | * @returns true if it is, false otherwise |
---|
| 134 | */ |
---|
| 135 | bool BaseObject::isA (const char* className) const |
---|
| 136 | { |
---|
| 137 | long classID = ClassList::StringToID(className); |
---|
| 138 | if (classID != CL_NULL) |
---|
| 139 | return this->isA(classID); |
---|
| 140 | } |
---|
| 141 | |
---|
[5626] | 142 | /** |
---|
| 143 | * compares the ObjectName with an external name |
---|
| 144 | * @param objectName: the name to check. |
---|
| 145 | * @returns true on match, false otherwise. |
---|
| 146 | */ |
---|
| 147 | bool BaseObject::operator ==(const char* objectName) |
---|
| 148 | { |
---|
| 149 | if (likely(this->objectName != NULL && objectName != NULL)) |
---|
| 150 | return (strcmp(this->objectName, objectName)) ? false : true; |
---|
| 151 | } |
---|
[5513] | 152 | |
---|
[5626] | 153 | |
---|
[5513] | 154 | /** |
---|
[4836] | 155 | * displays everything this class is |
---|
[5642] | 156 | * @TODO REIMPLEMENT WITH SENSE. |
---|
[4592] | 157 | */ |
---|
[4746] | 158 | void BaseObject::whatIs() const |
---|
[4592] | 159 | { |
---|
[4595] | 160 | PRINT(0)("object %s of class %s: ", this->getName(), this->getClassName()); |
---|
[4596] | 161 | if ((this->classID & CL_MASK_SINGLETON) == CL_MASK_SINGLETON) |
---|
| 162 | PRINT(0)("is a Singleton-Class "); |
---|
[4594] | 163 | if (this->classID & CL_MASK_SUPER_CLASS) |
---|
[4592] | 164 | { |
---|
[4596] | 165 | PRINT(0)(" ->is a derived from the following superclasses:"); |
---|
[4595] | 166 | if (this->isA(CL_BASE_OBJECT)) |
---|
| 167 | PRINT(0)(" =BaseObject="); |
---|
| 168 | if (this->isA(CL_PARENT_NODE)) |
---|
| 169 | PRINT(0)(" =PNode="); |
---|
| 170 | if (this->isA(CL_WORLD_ENTITY)) |
---|
| 171 | PRINT(0)(" =WorldEntity="); |
---|
| 172 | if (this->isA(CL_PHYSICS_INTERFACE)) |
---|
| 173 | PRINT(0)(" =PhysicsInterface="); |
---|
| 174 | if (this->isA(CL_EVENT_LISTENER)) |
---|
| 175 | PRINT(0)(" =EventListener="); |
---|
| 176 | if (this->isA(CL_STORY_ENTITY)) |
---|
| 177 | PRINT(0)(" =StoryEntity="); |
---|
[4874] | 178 | if (this->isA(CL_ELEMENT_2D)) |
---|
| 179 | PRINT(0)(" =Element2D="); |
---|
[4595] | 180 | PRINT(0)("\n"); |
---|
[4592] | 181 | } |
---|
[4595] | 182 | // subsuper-classes |
---|
| 183 | if (this->classID & CL_MASK_SUBSUPER_CLASS) |
---|
| 184 | { |
---|
| 185 | PRINT(0)(" ->further derivations: "); |
---|
| 186 | if (this->isA(CL_PLAYER)) |
---|
| 187 | PRINT(0)(" -Player-"); |
---|
| 188 | if (this->isA(CL_NPC)) |
---|
| 189 | PRINT(0)(" -NPC-"); |
---|
| 190 | if (this->isA(CL_POWER_UP)) |
---|
| 191 | PRINT(0)(" -PowerUp-"); |
---|
| 192 | if (this->isA(CL_FIELD)) |
---|
| 193 | PRINT(0)(" -Field-"); |
---|
| 194 | if (this->isA(CL_PROJECTILE)) |
---|
| 195 | PRINT(0)(" -Projectile-"); |
---|
| 196 | if (this->isA(CL_WEAPON)) |
---|
| 197 | PRINT(0)(" -Weapon-"); |
---|
| 198 | PRINT(0)("\n"); |
---|
[4592] | 199 | } |
---|
[5642] | 200 | } |
---|