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