Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/resources/src/world_entities/npcs/ground_turret.cc @ 8538

Last change on this file since 8538 was 7193, checked in by bensch, 19 years ago

orxonox/trunk: new style for resources (prework/movement)

File size: 4.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{
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}
182
183/**
184 * Writes data from network containing information about the state
185 * @param data pointer to data
186 * @param length length of data
187 * @param sender hostID of sender
188 */
189int GroundTurret::writeBytes( const byte * data, int length, int sender )
190{
191  setRequestedSync( false );
192  setIsOutOfSync( false );
193
194  SYNCHELP_READ_BEGIN();
195
196  SYNCHELP_READ_FKT( WorldEntity::writeState, NWT_GT_WE_STATE );
197
198  return SYNCHELP_READ_N;
199}
200
201/**
202 * data copied in data will bee sent to another host
203 * @param data pointer to data
204 * @param maxLength max length of data
205 * @return the number of bytes writen
206 */
207int GroundTurret::readBytes( byte * data, int maxLength, int * reciever )
208{
209  SYNCHELP_WRITE_BEGIN();
210
211  if ( isOutOfSync() && !requestedSync() && this->getHostID()!=this->getOwner() )
212  {
213    (NetworkGameManager::getInstance())->sync( this->getUniqueID(), this->getOwner() );
214    setRequestedSync( true );
215  }
216
217  int rec = this->getRequestSync();
218  if ( rec > 0 )
219  {
220    *reciever = rec;
221
222    SYNCHELP_WRITE_FKT( WorldEntity::readState, NWT_GT_WE_STATE );
223
224  }
225
226  *reciever = 0;
227  return SYNCHELP_WRITE_N;
228}
Note: See TracBrowser for help on using the repository browser.