Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/world_entities/npcs/ground_turret.cc @ 9331

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

merged the presentation back

File size: 3.9 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 "ground_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(GroundTurret, CL_GROUND_TURRET);
32
33using namespace std;
34
35
36/**
37 * constructs and loads a GroundTurret from a XML-element
38 * @param root the XML-element to load from
39 */
40GroundTurret::GroundTurret(const TiXmlElement* root)
41  : NPC(root)
42{
43  this->init();
44  if (root != NULL)
45    this->loadParams(root);
46}
47
48
49/**
50 * standard deconstructor
51 */
52GroundTurret::~GroundTurret ()
53{
54
55}
56
57
58/**
59 * initializes the GroundTurret
60 * @todo change this to what you wish
61 */
62void GroundTurret::init()
63{
64  this->setClassID(CL_GROUND_TURRET, "GroundTurret");
65  this->loadModel("models/ground_turret_#.obj", 5);
66  this->left = NULL;
67  this->right = NULL;
68
69  this->setHealthMax(300);
70  this->setHealth(300);
71
72  this->weaponHolder[0].addNodeFlags(PNODE_PROHIBIT_DELETE_WITH_PARENT);
73  this->weaponHolder[1].addNodeFlags(PNODE_PROHIBIT_DELETE_WITH_PARENT);
74
75  this->weaponHolder[0].setRelCoor(0,25,0);
76  this->weaponHolder[0].setParent(this);
77  this->weaponHolder[1].setParent(this);
78}
79
80
81/**
82 * loads a GroundTurret from a XML-element
83 * @param root the XML-element to load from
84 * @todo make the class Loadable
85 */
86void GroundTurret::loadParams(const TiXmlElement* root)
87{
88  // all the clases this Entity is directly derived from must be called in this way, to load all settings.
89  NPC::loadParams(root);
90
91
92  /**
93   * @todo: make the class Loadable
94   */
95  const TiXmlElement* element;
96
97  element = root->FirstChildElement("weapon-left");
98  if (element != NULL) element = element->FirstChildElement();
99  this->left = dynamic_cast<Weapon*>( Factory::fabricate( element) );
100  if (this->left)
101  {
102    this->left->setParent(this);
103    this->left->toList(this->getOMListNumber());
104    this->left->setRelCoor(0,10,-5);
105    this->left->requestAction( WA_ACTIVATE);
106    this->left->setParent(&this->weaponHolder[0]);
107  }
108
109  element = root->FirstChildElement("weapon-right");
110  if (element != NULL)  if (element != NULL) element = element->FirstChildElement();
111  this->right = dynamic_cast<Weapon*>( Factory::fabricate( element) );
112  if (this->right)
113  {
114    this->right->setParent(this);
115    this->right->toList(this->getOMListNumber());
116    this->right->setRelCoor(0,10,5);
117    this->left->requestAction( WA_ACTIVATE);
118    this->right->setParent(&this->weaponHolder[0]);
119  }
120}
121
122/**
123 * advances the GroundTurret about time seconds
124 * @param time the Time to step
125 */
126void GroundTurret::tick(float dt)
127{
128  if(this->getHealth() > 0.0f && State::getPlayer() &&
129     State::getPlayer()->getPlayable() &&
130     State::getPlayer()->getPlayable()->distance(this) < 120) // HACK
131  {
132  if (likely(this->left != NULL))
133  {
134//    this->left->tickW(dt);
135    this->left->requestAction(WA_SHOOT);
136  }
137  if (likely(this->right != NULL))
138  {
139//    this->right->tickW(dt);
140    this->right->requestAction(WA_SHOOT);
141  }
142  }
143}
144
145/**
146 * draws this worldEntity
147 */
148void GroundTurret::draw () const
149{
150  WorldEntity::draw();
151
152  if (this->left != NULL)
153    this->left->draw();
154  if (this->right != NULL)
155    this->right->draw();
156}
157
158
159
160/**
161 *
162 *
163 */
164void GroundTurret::postSpawn ()
165{
166
167}
168
169/**
170 *
171 *
172 */
173void GroundTurret::leftWorld ()
174{
175
176}
177
178void GroundTurret::destroy(WorldEntity* killer)
179{
180  this->setAbsDirSoft(Quaternion(-90, Vector(0,0,1)), 90);
181  Explosion::explode(this, Vector(10,10,10));
182
183  this->toList(OM_DEAD);
184}
Note: See TracBrowser for help on using the repository browser.