Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/world_entities/npcs/ground_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: 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
33
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 * 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 * @brief 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   * @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,10,-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,10,5);
115    this->left->requestAction( WA_ACTIVATE);
116    this->right->setParent(&this->weaponHolder[0]);
117  }
118}
119
120/**
121 * advances the GroundTurret about time seconds
122 * @param time the Time to step
123 */
124void GroundTurret::tick(float dt)
125{
126  if(this->getHealth() > 0.0f
127    ) // HACK <--- YOU ARE THE MOTHERFUCKER
128  {
129    if (likely(this->left != NULL))
130    {
131      //    this->left->tickW(dt);
132      this->left->requestAction(WA_SHOOT);
133    }
134    if (likely(this->right != NULL))
135    {
136      //    this->right->tickW(dt);
137      this->right->requestAction(WA_SHOOT);
138    }
139  }
140}
141
142/**
143 * draws this worldEntity
144 */
145void GroundTurret::draw () const
146{
147  WorldEntity::draw();
148
149  if (this->left != NULL)
150    this->left->draw();
151  if (this->right != NULL)
152    this->right->draw();
153}
154
155
156
157/**
158 *
159 *
160 */
161void GroundTurret::postSpawn ()
162{
163}
164
165/**
166 *
167 *
168 */
169void GroundTurret::leftWorld ()
170{
171}
172
173void GroundTurret::destroy(WorldEntity* killer)
174{
175  this->setAbsDirSoft(Quaternion(-90, Vector(0,0,1)), 90);
176  Explosion::explode(this, Vector(10,10,10));
177
178  this->toList(OM_DEAD);
179}
Note: See TracBrowser for help on using the repository browser.