Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 8076 was 7954, checked in by patrick, 18 years ago

trunk: merged the network branche back to trunk.

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