Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

weaponAdjustment

File size: 4.6 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  /*  left = new Turret();
70  left->setParent(this);
71  left->setRelCoor(0,10,0);
72  right = new Turret();
73  right->setParent(this);
74  right->setRelCoor(0,10,0);*/
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  }
104
105  element = root->FirstChildElement("weapon-right");
106  if (element != NULL)  if (element != NULL) element = element->FirstChildElement();
107  this->right = dynamic_cast<Weapon*>( Factory::fabricate( element) );
108  if (this->right)
109  {
110    this->right->setParent(this);
111    this->right->toList(this->getOMListNumber());
112    this->right->setRelCoor(0,10,5);
113    this->left->requestAction( WA_ACTIVATE);
114  }
115}
116
117/**
118 * advances the GroundTurret about time seconds
119 * @param time the Time to step
120 */
121void GroundTurret::tick(float dt)
122{
123  if(this->getHealth() > 0.0f && State::getPlayer() &&
124     State::getPlayer()->getPlayable() &&
125     State::getPlayer()->getPlayable()->distance(this) < 150) // HACK
126  {
127  if (likely(this->left != NULL))
128  {
129//    this->left->tickW(dt);
130    this->left->requestAction(WA_SHOOT);
131  }
132  if (likely(this->right != NULL))
133  {
134//    this->right->tickW(dt);
135    this->right->requestAction(WA_SHOOT);
136  }
137  }
138}
139
140/**
141 * draws this worldEntity
142 */
143void GroundTurret::draw () const
144{
145  WorldEntity::draw();
146
147  if (this->left != NULL)
148    this->left->draw();
149  if (this->right != NULL)
150    this->right->draw();
151}
152
153
154
155/**
156 *
157 *
158 */
159void GroundTurret::postSpawn ()
160{
161
162}
163
164/**
165 *
166 *
167 */
168void GroundTurret::leftWorld ()
169{
170
171}
172
173void GroundTurret::destroy()
174{
175  this->setAbsDirSoft(Quaternion(-90, Vector(0,0,1)), 90);
176}
177
178/**
179 * Writes data from network containing information about the state
180 * @param data pointer to data
181 * @param length length of data
182 * @param sender hostID of sender
183 */
184int GroundTurret::writeBytes( const byte * data, int length, int sender )
185{
186  setRequestedSync( false );
187  setIsOutOfSync( false );
188
189  SYNCHELP_READ_BEGIN();
190
191  SYNCHELP_READ_FKT( WorldEntity::writeState, NWT_GT_WE_STATE );
192
193  return SYNCHELP_READ_N;
194}
195
196/**
197 * data copied in data will bee sent to another host
198 * @param data pointer to data
199 * @param maxLength max length of data
200 * @return the number of bytes writen
201 */
202int GroundTurret::readBytes( byte * data, int maxLength, int * reciever )
203{
204  SYNCHELP_WRITE_BEGIN();
205
206  if ( isOutOfSync() && !requestedSync() && this->getHostID()!=this->getOwner() )
207  {
208    (NetworkGameManager::getInstance())->sync( this->getUniqueID(), this->getOwner() );
209    setRequestedSync( true );
210  }
211
212  int rec = this->getRequestSync();
213  if ( rec > 0 )
214  {
215    *reciever = rec;
216
217    SYNCHELP_WRITE_FKT( WorldEntity::readState, NWT_GT_WE_STATE );
218
219  }
220
221  *reciever = 0;
222  return SYNCHELP_WRITE_N;
223}
Note: See TracBrowser for help on using the repository browser.