Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/terrain/src/world_entities/npcs/space_turret.cc @ 9621

Last change on this file since 9621 was 9235, checked in by bensch, 18 years ago

merged the presentation back

File size: 4.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
78
79/**
80 * loads a SpaceTurret from a XML-element
81 * @param root the XML-element to load from
82 * @todo make the class Loadable
83 */
84void SpaceTurret::loadParams(const TiXmlElement* root)
85{
86  // all the clases this Entity is directly derived from must be called in this way, to load all settings.
87  NPC::loadParams(root);
88
89
90  /**
91   * @todo: make the class Loadable
92   */
93  const TiXmlElement* element;
94
95  element = root->FirstChildElement("weapon-left");
96  if (element != NULL) element = element->FirstChildElement();
97  this->left = dynamic_cast<Weapon*>( Factory::fabricate( element) );
98  if (this->left)
99  {
100    this->left->setParent(this);
101    this->left->toList(this->getOMListNumber());
102    this->left->setRelCoor(0,15,-7.5);
103    this->left->requestAction( WA_ACTIVATE);
104    this->left->setParent(&this->weaponHolder[0]);
105  }
106
107  element = root->FirstChildElement("weapon-right");
108  if (element != NULL)  if (element != NULL) element = element->FirstChildElement();
109  this->right = dynamic_cast<Weapon*>( Factory::fabricate( element) );
110  if (this->right)
111  {
112    this->right->setParent(this);
113    this->right->toList(this->getOMListNumber());
114    this->right->setRelCoor(0,15,7.5);
115    this->left->requestAction( WA_ACTIVATE);
116    this->right->setParent(&this->weaponHolder[0]);
117  }
118}
119
120/**
121 * advances the SpaceTurret about time seconds
122 * @param time the Time to step
123 */
124void SpaceTurret::tick(float dt)
125{
126  if(this->getHealth() > 0.0f && State::getPlayer() &&
127     State::getPlayer()->getPlayable() &&
128     State::getPlayer()->getPlayable()->distance(this) < 300) // HACK
129  {
130  if (likely(this->left != NULL))
131  {
132//    this->left->tickW(dt);
133    this->left->requestAction(WA_SHOOT);
134  }
135  if (likely(this->right != NULL))
136  {
137//    this->right->tickW(dt);
138    this->right->requestAction(WA_SHOOT);
139  }
140  }
141}
142
143/**
144 * draws this worldEntity
145 */
146void SpaceTurret::draw () const
147{
148  glPushMatrix();
149  glTranslatef (this->getAbsCoor ().x,
150                this->getAbsCoor ().y,
151                this->getAbsCoor ().z);
152
153  Vector tmpRot = this->getAbsDir().getSpacialAxis();
154  glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z );
155
156  this->getModel()->draw();
157  if (this->getModel() != NULL)
158    this->getModel(3)->draw();
159  glPopMatrix();
160/*
161  if (this->left != NULL)
162    this->left->draw();
163  if (this->right != NULL)
164    this->right->draw();*/
165}
166
167
168
169/**
170 *
171 *
172 */
173void SpaceTurret::postSpawn ()
174{
175
176}
177
178/**
179 *
180 *
181 */
182void SpaceTurret::leftWorld ()
183{
184
185}
186
187void SpaceTurret::destroy(WorldEntity* killer)
188{
189  this->setAbsDirSoft(Quaternion(-90, Vector(0,0,1)), 90);
190  Explosion::explode(this, Vector(10,10,10));
191
192  this->toList(OM_DEAD);
193
194  if (this->left)
195    this->left->toList(OM_DEAD);
196  if (this->right)
197    this->right->toList(OM_DEAD);
198
199}
Note: See TracBrowser for help on using the repository browser.