Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/world_entities/npcs/space_turret.cc @ 9704

Last change on this file since 9704 was 9656, checked in by bensch, 18 years ago

orxonox/trunk: merged the proxy bache back with no conflicts

File size: 5.4 KB
Line 
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: Manuel Leuenberger
13   co-programmer: ...
14*/
15
16#include "space_turret.h"
17#include "model.h"
18#include "world_entities/weapons/turret.h"
19
20#include "state.h"
21#include "playable.h"
22#include "player.h"
23
24
25#include "util/loading/factory.h"
26#include "network_game_manager.h"
27#include "util/loading/load_param.h"
28
29#include "effects/explosion.h"
30
31CREATE_FACTORY(SpaceTurret, CL_SPACE_TURRET);
32
33/**
34 * constructs and loads a SpaceTurret from a XML-element
35 * @param root the XML-element to load from
36 */
37SpaceTurret::SpaceTurret(const TiXmlElement* root)
38  : NPC(root)
39{
40  this->init();
41  if (root != NULL)
42    this->loadParams(root);
43}
44
45
46/**
47 * standard deconstructor
48 */
49SpaceTurret::~SpaceTurret ()
50{
51
52}
53
54
55/**
56 * initializes the SpaceTurret
57 * @todo change this to what you wish
58 */
59void SpaceTurret::init()
60{
61  this->setClassID(CL_SPACE_TURRET, "SpaceTurret");
62  this->loadModel("models/ground_turret_#.obj", 7.5);
63  this->loadModel("models/comet.obj", 1.0f, 3);
64  this->left = NULL;
65  this->right = NULL;
66
67  this->setHealthMax(100);
68  this->setHealth(30);
69
70  this->weaponHolder[0].addNodeFlags(PNODE_PROHIBIT_DELETE_WITH_PARENT);
71  this->weaponHolder[1].addNodeFlags(PNODE_PROHIBIT_DELETE_WITH_PARENT);
72
73  this->weaponHolder[0].setRelCoor(0,25,0);
74  this->weaponHolder[0].setParent(this);
75  this->weaponHolder[1].setParent(this);
76
77  this->wLeftHandle = registerVarId( new SynchronizeableString( &this->wLeft, &this->wLeft, "weapon-left", PERMISSION_MASTER_SERVER ) );
78  this->wRightHandle = registerVarId( new SynchronizeableString( &this->wRight, &this->wRight, "weapon-right", PERMISSION_MASTER_SERVER ) );
79
80}
81
82
83/**
84 * loads a SpaceTurret from a XML-element
85 * @param root the XML-element to load from
86 * @todo make the class Loadable
87 */
88void SpaceTurret::loadParams(const TiXmlElement* root)
89{
90  // all the clases this Entity is directly derived from must be called in this way, to load all settings.
91  NPC::loadParams(root);
92
93
94  /**
95   * @todo: make the class Loadable
96   */
97  const TiXmlElement* element;
98
99  element = root->FirstChildElement("weapon-left");
100  if (element != NULL) element = element->FirstChildElement();
101  this->left = dynamic_cast<Weapon*>( Factory::fabricate( element) );
102  if (this->left)
103  {
104    this->wLeft = element->Value();
105
106    this->left->setParent(this);
107    this->left->toList(this->getOMListNumber());
108    this->left->setRelCoor(0,15,-7.5);
109    this->left->requestAction( WA_ACTIVATE);
110    this->left->setParent(&this->weaponHolder[0]);
111  }
112
113  element = root->FirstChildElement("weapon-right");
114  if (element != NULL)  if (element != NULL) element = element->FirstChildElement();
115  this->right = dynamic_cast<Weapon*>( Factory::fabricate( element) );
116  if (this->right)
117  {
118    this->wRight = element->Value();
119
120    this->right->setParent(this);
121    this->right->toList(this->getOMListNumber());
122    this->right->setRelCoor(0,15,7.5);
123    this->left->requestAction( WA_ACTIVATE);
124    this->right->setParent(&this->weaponHolder[0]);
125  }
126}
127
128
129/**
130 * sets the left weapon called from net sync
131 * @param wLeft the left weapon string
132 */
133void SpaceTurret::setWeaponLeft(const std::string& wLeft)
134{
135
136}
137
138/**
139 * sets the left weapon called from net sync
140 * @param wRught the right weapon string
141 */
142void SpaceTurret::setWeaponRight(const std::string& wRight)
143{}
144
145/**
146 * advances the SpaceTurret about time seconds
147 * @param time the Time to step
148 */
149void SpaceTurret::tick(float dt)
150{
151  if(this->getHealth() > 0.0f && State::getPlayer() &&
152     State::getPlayer()->getPlayable() &&
153     State::getPlayer()->getPlayable()->distance(this) < 300) // HACK
154  {
155  if (likely(this->left != NULL))
156  {
157//    this->left->tickW(dt);
158    this->left->requestAction(WA_SHOOT);
159  }
160  if (likely(this->right != NULL))
161  {
162//    this->right->tickW(dt);
163    this->right->requestAction(WA_SHOOT);
164  }
165  }
166}
167
168/**
169 * draws this worldEntity
170 */
171void SpaceTurret::draw () const
172{
173  glPushMatrix();
174  glTranslatef (this->getAbsCoor ().x,
175                this->getAbsCoor ().y,
176                this->getAbsCoor ().z);
177
178  Vector tmpRot = this->getAbsDir().getSpacialAxis();
179  glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z );
180
181  this->getModel()->draw();
182  if (this->getModel() != NULL)
183    this->getModel(3)->draw();
184  glPopMatrix();
185/*
186  if (this->left != NULL)
187    this->left->draw();
188  if (this->right != NULL)
189    this->right->draw();*/
190}
191
192
193
194/**
195 *
196 *
197 */
198void SpaceTurret::postSpawn ()
199{
200
201}
202
203/**
204 *
205 *
206 */
207void SpaceTurret::leftWorld ()
208{
209
210}
211
212void SpaceTurret::destroy(WorldEntity* killer)
213{
214  this->setAbsDirSoft(Quaternion(-90, Vector(0,0,1)), 90);
215  Explosion::explode(this, Vector(10,10,10));
216
217  this->toList(OM_DEAD);
218
219  if (this->left)
220    this->left->toList(OM_DEAD);
221  if (this->right)
222    this->right->toList(OM_DEAD);
223
224}
225
226
227
228/**
229 * handler for changes on registred vars
230 * @param id id's which changed
231 */
232void SpaceTurret::varChangeHandler( std::list< int > & id )
233{
234  if ( std::find( id.begin(), id.end(), this->wLeftHandle ) != id.end())
235  {
236    this->setWeaponLeft(this->wLeft);
237  }
238
239  if ( std::find( id.begin(), id.end(), this->wRightHandle ) != id.end() )
240  {
241    this->setWeaponRight(this->wRight);
242  }
243
244
245  WorldEntity::varChangeHandler( id );
246}
247
Note: See TracBrowser for help on using the repository browser.