1 | /* |
---|
2 | orxonox - the future of 3D-vertical-scrollers |
---|
3 | |
---|
4 | Copyright (C) 2004 orx |
---|
5 | |
---|
6 | This program 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, or (at your option) |
---|
9 | any later version. |
---|
10 | |
---|
11 | ### File Specific |
---|
12 | main-programmer: Patrick Boenzli, patrick@orxonox.net |
---|
13 | co-programmer: |
---|
14 | */ |
---|
15 | #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WORLD_ENTITY |
---|
16 | |
---|
17 | |
---|
18 | #include "executor/executor.h" |
---|
19 | #include "util/loading/factory.h" |
---|
20 | #include "util/loading/load_param.h" |
---|
21 | #include "util/loading/load_param_xml.h" |
---|
22 | |
---|
23 | #include "weapons/weapon_slot.h" |
---|
24 | |
---|
25 | #include "mount_point.h" |
---|
26 | #include "debug.h" |
---|
27 | #include "state.h" |
---|
28 | |
---|
29 | |
---|
30 | ObjectListDefinition(MountPoint); |
---|
31 | |
---|
32 | |
---|
33 | /** |
---|
34 | * construct |
---|
35 | */ |
---|
36 | MountPoint::MountPoint (const Vector& up, const Vector& forward, const Vector& center, const std::string& name) |
---|
37 | { |
---|
38 | PRINTF(0)("Created mount point %s\n", name.c_str()); |
---|
39 | this->registerObject(this, MountPoint::_objectList); |
---|
40 | |
---|
41 | this->_name = name; |
---|
42 | this->setAbsCoor( center); |
---|
43 | this->setAbsDir( Quaternion(forward, up)); |
---|
44 | |
---|
45 | this->init(); |
---|
46 | } |
---|
47 | |
---|
48 | |
---|
49 | |
---|
50 | /** |
---|
51 | * deconstructor |
---|
52 | */ |
---|
53 | MountPoint::~MountPoint () |
---|
54 | {} |
---|
55 | |
---|
56 | |
---|
57 | /** |
---|
58 | * initializing function |
---|
59 | */ |
---|
60 | void MountPoint::init() |
---|
61 | { |
---|
62 | this->registerObject(this, MountPoint::_objectList); |
---|
63 | this->toList(OM_GROUP_00); |
---|
64 | |
---|
65 | this->_mount = NULL; |
---|
66 | } |
---|
67 | |
---|
68 | |
---|
69 | /** |
---|
70 | * loads the Settings of a MD2Creature from an XML-element. |
---|
71 | * @param root the XML-element to load the MD2Creature's properties from |
---|
72 | */ |
---|
73 | void MountPoint::initMountPoint(const TiXmlElement* root) |
---|
74 | { |
---|
75 | if( root == NULL) |
---|
76 | { |
---|
77 | PRINTF(1)("MountPoint - initialization failed, since I got no valid xml element\n"); |
---|
78 | return; |
---|
79 | } |
---|
80 | // now get the first element |
---|
81 | const TiXmlElement* element = root->FirstChildElement("MountPoints"); |
---|
82 | if( element == NULL) |
---|
83 | { |
---|
84 | PRINTF(1)("I am in section: %s, Object Information file is missing a proper 'MountPoints' section\n", root->Value()); |
---|
85 | // element = root->FirstChildElement( ); |
---|
86 | // PRINTF(0)("first child: %s\n", element->Value()); |
---|
87 | } |
---|
88 | else |
---|
89 | { |
---|
90 | element = element->FirstChildElement(); |
---|
91 | // parse the information for this mount point |
---|
92 | |
---|
93 | PRINTF(4)("Loading WorldEntities\n"); |
---|
94 | while( element != NULL) |
---|
95 | { |
---|
96 | std::string name = element->Value(); |
---|
97 | |
---|
98 | PRINTF(5)("checking %s against local %s\n", name.c_str(), this->_name.c_str()); |
---|
99 | // check if we got the right mount point |
---|
100 | if( this->_name.find(name, 0) != std::string::npos) |
---|
101 | { |
---|
102 | PRINTF(5)("found mount point %s\n", this->_name.c_str()); |
---|
103 | // load it |
---|
104 | this->loadParam(element); |
---|
105 | } |
---|
106 | |
---|
107 | element = element->NextSiblingElement(); |
---|
108 | } |
---|
109 | } |
---|
110 | } |
---|
111 | |
---|
112 | |
---|
113 | |
---|
114 | /** |
---|
115 | * load the parameters from the xml section |
---|
116 | * @param root the root element of this xml branche |
---|
117 | */ |
---|
118 | void MountPoint::loadParam(const TiXmlElement* root) |
---|
119 | { |
---|
120 | // first check for the description |
---|
121 | LoadParam(root, "Description", this, MountPoint, setDescription) |
---|
122 | .describe("Sets this mount point a description"); |
---|
123 | |
---|
124 | // now check for the orx class to create |
---|
125 | LoadParam(root, "OrxClass", this, MountPoint, setOrxClass) |
---|
126 | .describe("Sets the class this mount points should host"); |
---|
127 | |
---|
128 | LoadParamXML(root, "Details", this, MountPoint, loadDetails); |
---|
129 | } |
---|
130 | |
---|
131 | |
---|
132 | /** |
---|
133 | * load the parameters from the world entity |
---|
134 | * @param root the root element of this xml branche |
---|
135 | */ |
---|
136 | void MountPoint::loadDetails(const TiXmlElement* root) |
---|
137 | { |
---|
138 | if( this->_mount != NULL) |
---|
139 | { |
---|
140 | PRINTF(0)("Got detail informations\n"); |
---|
141 | this->_mount->loadParams( root); |
---|
142 | } |
---|
143 | } |
---|
144 | |
---|
145 | |
---|
146 | /** |
---|
147 | * setst the description (optional) via xml tag |
---|
148 | * @param description string containing the description |
---|
149 | */ |
---|
150 | void MountPoint::setDescription(const std::string& description) |
---|
151 | { |
---|
152 | this->_description = description; |
---|
153 | } |
---|
154 | |
---|
155 | |
---|
156 | |
---|
157 | /** |
---|
158 | * sets the class of this mount point |
---|
159 | * @param orxClass class |
---|
160 | */ |
---|
161 | void MountPoint::setOrxClass(const std::string& orxClass) |
---|
162 | { |
---|
163 | // create the object for this mount point |
---|
164 | BaseObject* obj = Factory::fabricate(orxClass); |
---|
165 | // check if the object is created correctly |
---|
166 | if( obj != NULL) |
---|
167 | { |
---|
168 | if( obj->isA( WorldEntity::staticClassID())) |
---|
169 | { |
---|
170 | // cast down the object to WE |
---|
171 | this->_mount = dynamic_cast<WorldEntity*>(obj); |
---|
172 | |
---|
173 | // now set the position, direction and reparent it to this node |
---|
174 | this->_mount->setAbsCoor( this->getAbsCoor()); |
---|
175 | this->_mount->setAbsDir( this->getAbsDir()); |
---|
176 | this->_mount->setParent( this); |
---|
177 | |
---|
178 | this->_mount->toList((OM_LIST)(this->getOMListNumber())); |
---|
179 | } |
---|
180 | else if( obj->isA( WeaponSlot::staticClassID())) |
---|
181 | { |
---|
182 | PRINTF(0)("=========+>we got a weapon slot\n"); |
---|
183 | } |
---|
184 | } |
---|
185 | else |
---|
186 | PRINTF(1)("Couldn't create %s for this mount point (%s)\n", orxClass.c_str(), this->_name.c_str()); |
---|
187 | } |
---|
188 | |
---|
189 | |
---|
190 | |
---|
191 | /** |
---|
192 | * tick |
---|
193 | * @param time time passed since the last tick |
---|
194 | */ |
---|
195 | void MountPoint::tick (float time) |
---|
196 | { |
---|
197 | |
---|
198 | } |
---|
199 | |
---|
200 | |
---|
201 | /** |
---|
202 | * draw this entity |
---|
203 | */ |
---|
204 | void MountPoint::draw() const |
---|
205 | { |
---|
206 | } |
---|
207 | |
---|
208 | |
---|
209 | |
---|
210 | /** |
---|
211 | * function called to draw the mount point itself for debug purposes only |
---|
212 | */ |
---|
213 | void MountPoint::debugDraw() const |
---|
214 | { |
---|
215 | // invoke the underlying pnode debug draw |
---|
216 | this->debugDraw(); |
---|
217 | } |
---|
218 | |
---|
219 | |
---|
220 | /** |
---|
221 | * adds an entity to this mount point |
---|
222 | * @param entity entity to be added |
---|
223 | */ |
---|
224 | void MountPoint::mount(WorldEntity* entity) |
---|
225 | { |
---|
226 | this->_mount = entity; |
---|
227 | } |
---|
228 | |
---|
229 | |
---|
230 | /** |
---|
231 | * removes an entity from this mount point |
---|
232 | */ |
---|
233 | void MountPoint::unmount() |
---|
234 | { |
---|
235 | this->_mount = NULL; |
---|
236 | } |
---|
237 | |
---|