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