Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 10280 was 10114, checked in by patrick, 18 years ago

merged network back to trunk

File size: 5.5 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
31
32ObjectListDefinition(SpaceTurret);
33CREATE_FACTORY(SpaceTurret);
34
35/**
36 * constructs and loads a SpaceTurret from a XML-element
37 * @param root the XML-element to load from
38 */
39SpaceTurret::SpaceTurret(const TiXmlElement* root)
40    : NPC(root)
41{
42  this->init();
43  if (root != NULL)
44    this->loadParams(root);
45}
46
47
48/**
49 * standard deconstructor
50 */
51SpaceTurret::~SpaceTurret ()
52{}
53
54
55/**
56 * initializes the SpaceTurret
57 * @todo change this to what you wish
58 */
59void SpaceTurret::init()
60{
61  this->registerObject(this, SpaceTurret::_objectList);
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)
101    element = element->FirstChildElement();
102  if (element != NULL)
103    this->left = dynamic_cast<Weapon*>( Factory::fabricate( element) );
104  if (this->left)
105  {
106    this->wLeft = element->Value();
107
108    this->left->setParent(this);
109    this->left->toList(this->getOMListNumber());
110    this->left->setRelCoor(0,15,-7.5);
111    this->left->requestAction( WA_ACTIVATE);
112    this->left->setParent(&this->weaponHolder[0]);
113  }
114
115  element = root->FirstChildElement("weapon-right");
116  if (element != NULL)
117    element = element->FirstChildElement();
118  if (element != NULL)
119    this->right = dynamic_cast<Weapon*>( Factory::fabricate( element) );
120  if (this->right)
121  {
122    this->wRight = element->Value();
123
124    this->right->setParent(this);
125    this->right->toList(this->getOMListNumber());
126    this->right->setRelCoor(0,15,7.5);
127    this->left->requestAction( WA_ACTIVATE);
128    this->right->setParent(&this->weaponHolder[0]);
129  }
130}
131
132
133/**
134 * sets the left weapon called from net sync
135 * @param wLeft the left weapon string
136 */
137void SpaceTurret::setWeaponLeft(const std::string& wLeft)
138{}
139
140/**
141 * sets the left weapon called from net sync
142 * @param wRught the right weapon string
143 */
144void SpaceTurret::setWeaponRight(const std::string& wRight)
145{}
146
147/**
148 * advances the SpaceTurret about time seconds
149 * @param time the Time to step
150 */
151void SpaceTurret::tick(float dt)
152{
153  if(this->getHealth() > 0.0f && State::getPlayer() &&
154      State::getPlayer()->getPlayable() &&
155      State::getPlayer()->getPlayable()->distance(this) < 300) // HACK
156  {
157    if (likely(this->left != NULL))
158    {
159      //    this->left->tickW(dt);
160      this->left->requestAction(WA_SHOOT);
161    }
162    if (likely(this->right != NULL))
163    {
164      //    this->right->tickW(dt);
165      this->right->requestAction(WA_SHOOT);
166    }
167  }
168}
169
170/**
171 * draws this worldEntity
172 */
173void SpaceTurret::draw () const
174{
175  glPushMatrix();
176  glTranslatef (this->getAbsCoor ().x,
177                this->getAbsCoor ().y,
178                this->getAbsCoor ().z);
179
180  Vector tmpRot = this->getAbsDir().getSpacialAxis();
181  glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z );
182
183  this->getModel()->draw();
184  if (this->getModel() != NULL)
185    this->getModel(3)->draw();
186  glPopMatrix();
187  /*
188    if (this->left != NULL)
189      this->left->draw();
190    if (this->right != NULL)
191      this->right->draw();*/
192}
193
194
195
196/**
197 *
198 *
199 */
200void SpaceTurret::postSpawn ()
201{}
202
203/**
204 *
205 *
206 */
207void SpaceTurret::leftWorld ()
208{}
209
210void SpaceTurret::destroy(WorldEntity* killer)
211{
212  this->setAbsDirSoft(Quaternion(-90, Vector(0,0,1)), 90);
213  Explosion::explode(this, Vector(10,10,10));
214
215  this->toList(OM_DEAD);
216
217  if (this->left)
218    this->left->toList(OM_DEAD);
219  if (this->right)
220    this->right->toList(OM_DEAD);
221
222}
223
224
225
226/**
227 * handler for changes on registred vars
228 * @param id id's which changed
229 */
230void SpaceTurret::varChangeHandler( std::list< int > & id )
231{
232  if ( std::find( id.begin(), id.end(), this->wLeftHandle ) != id.end())
233  {
234    this->setWeaponLeft(this->wLeft);
235  }
236
237  if ( std::find( id.begin(), id.end(), this->wRightHandle ) != id.end() )
238  {
239    this->setWeaponRight(this->wRight);
240  }
241
242
243  WorldEntity::varChangeHandler( id );
244}
245
Note: See TracBrowser for help on using the repository browser.