Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

power ups can only be picked up once

File size: 4.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 "factory.h"
26#include "network_game_manager.h"
27#include "load_param.h"
28
29CREATE_FACTORY(GroundTurret, CL_GROUND_TURRET);
30
31using namespace std;
32
33
34/**
35 * constructs and loads a GroundTurret from a XML-element
36 * @param root the XML-element to load from
37 */
38GroundTurret::GroundTurret(const TiXmlElement* root)
39{
40  this->init();
41  if (root != NULL)
42    this->loadParams(root);
43}
44
45
46/**
47 * standard deconstructor
48 */
49GroundTurret::~GroundTurret ()
50{
51
52}
53
54
55/**
56 * initializes the GroundTurret
57 * @todo change this to what you wish
58 */
59void GroundTurret::init()
60{
61  this->setClassID(CL_GROUND_TURRET, "GroundTurret");
62  this->loadModel("models/ground_turret.obj", 5);
63  this->left = NULL;
64  this->right = NULL;
65
66  this->setHealthMax(300);
67  this->setHealth(300);
68
69  this->weaponHolder[0].addNodeFlags(PNODE_PROHIBIT_DELETE_WITH_PARENT);
70  this->weaponHolder[1].addNodeFlags(PNODE_PROHIBIT_DELETE_WITH_PARENT);
71
72  this->weaponHolder[0].setRelCoor(0,25,0);
73  this->weaponHolder[0].setParent(this);
74  this->weaponHolder[1].setParent(this);
75}
76
77
78/**
79 * loads a GroundTurret from a XML-element
80 * @param root the XML-element to load from
81 * @todo make the class Loadable
82 */
83void GroundTurret::loadParams(const TiXmlElement* root)
84{
85  // all the clases this Entity is directly derived from must be called in this way, to load all settings.
86  NPC::loadParams(root);
87
88
89  /**
90   * @todo: make the class Loadable
91   */
92  const TiXmlElement* element;
93
94  element = root->FirstChildElement("weapon-left");
95  if (element != NULL) element = element->FirstChildElement();
96  this->left = dynamic_cast<Weapon*>( Factory::fabricate( element) );
97  if (this->left)
98  {
99    this->left->setParent(this);
100    this->left->toList(this->getOMListNumber());
101    this->left->setRelCoor(0,10,-5);
102    this->left->requestAction( WA_ACTIVATE);
103    this->left->setParent(&this->weaponHolder[0]);
104  }
105
106  element = root->FirstChildElement("weapon-right");
107  if (element != NULL)  if (element != NULL) element = element->FirstChildElement();
108  this->right = dynamic_cast<Weapon*>( Factory::fabricate( element) );
109  if (this->right)
110  {
111    this->right->setParent(this);
112    this->right->toList(this->getOMListNumber());
113    this->right->setRelCoor(0,10,5);
114    this->left->requestAction( WA_ACTIVATE);
115    this->right->setParent(&this->weaponHolder[0]);
116  }
117}
118
119/**
120 * advances the GroundTurret about time seconds
121 * @param time the Time to step
122 */
123void GroundTurret::tick(float dt)
124{
125  if(this->getHealth() > 0.0f && State::getPlayer() &&
126     State::getPlayer()->getPlayable() &&
127     State::getPlayer()->getPlayable()->distance(this) < 150) // HACK
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 *
169 */
170void GroundTurret::leftWorld ()
171{
172
173}
174
175void GroundTurret::destroy()
176{
177  this->setAbsDirSoft(Quaternion(-90, Vector(0,0,1)), 90);
178}
179
180/**
181 * Writes data from network containing information about the state
182 * @param data pointer to data
183 * @param length length of data
184 * @param sender hostID of sender
185 */
186int GroundTurret::writeBytes( const byte * data, int length, int sender )
187{
188  setRequestedSync( false );
189  setIsOutOfSync( false );
190
191  SYNCHELP_READ_BEGIN();
192
193  SYNCHELP_READ_FKT( WorldEntity::writeState, NWT_GT_WE_STATE );
194
195  return SYNCHELP_READ_N;
196}
197
198/**
199 * data copied in data will bee sent to another host
200 * @param data pointer to data
201 * @param maxLength max length of data
202 * @return the number of bytes writen
203 */
204int GroundTurret::readBytes( byte * data, int maxLength, int * reciever )
205{
206  SYNCHELP_WRITE_BEGIN();
207
208  if ( isOutOfSync() && !requestedSync() && this->getHostID()!=this->getOwner() )
209  {
210    (NetworkGameManager::getInstance())->sync( this->getUniqueID(), this->getOwner() );
211    setRequestedSync( true );
212  }
213
214  int rec = this->getRequestSync();
215  if ( rec > 0 )
216  {
217    *reciever = rec;
218
219    SYNCHELP_WRITE_FKT( WorldEntity::readState, NWT_GT_WE_STATE );
220
221  }
222
223  *reciever = 0;
224  return SYNCHELP_WRITE_N;
225}
Note: See TracBrowser for help on using the repository browser.