Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/network/src/world_entities/weapons/ground_turret.cc @ 6331

Last change on this file since 6331 was 6331, checked in by rennerc, 18 years ago

synchronizeable: writeBytes now returns int
converter: converts now 0.0f without endless loop :D

File size: 4.4 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 "turret.h"
19
20#include "factory.h"
21#include "network_game_manager.h"
22#include "load_param.h"
23
24CREATE_FACTORY(GroundTurret, CL_GROUND_TURRET);
25
26using namespace std;
27
28
29/**
30 * constructs and loads a GroundTurret from a XML-element
31 * @param root the XML-element to load from
32 */
33GroundTurret::GroundTurret(const TiXmlElement* root)
34{
35  this->init();
36  if (root != NULL)
37    this->loadParams(root);
38}
39
40
41/**
42 * standard deconstructor
43 */
44GroundTurret::~GroundTurret ()
45{
46
47}
48
49
50/**
51 * initializes the GroundTurret
52 * @todo change this to what you wish
53 */
54void GroundTurret::init()
55{
56  this->setClassID(CL_GROUND_TURRET, "GroundTurret");
57  this->loadModel("models/ground_turret.obj", 5);
58  this->left = NULL;
59  this->right = NULL;
60
61  /*  left = new Turret();
62  left->setParent(this);
63  left->setRelCoor(0,10,0);
64  right = new Turret();
65  right->setParent(this);
66  right->setRelCoor(0,10,0);*/
67}
68
69
70/**
71 * loads a GroundTurret from a XML-element
72 * @param root the XML-element to load from
73 * @todo make the class Loadable
74 */
75void GroundTurret::loadParams(const TiXmlElement* root)
76{
77  // all the clases this Entity is directly derived from must be called in this way, to load all settings.
78  static_cast<NPC*>(this)->loadParams(root);
79
80
81  /**
82   * @todo: make the class Loadable
83   */
84  const TiXmlElement* element;
85
86  element = root->FirstChildElement("weapon-left");
87  if (element != NULL) element = element->FirstChildElement();
88  this->left = dynamic_cast<Weapon*>( Factory::fabricate( element) );
89  if (this->left)
90  {
91    this->left->setParent(this);
92    this->left->toList(this->getOMListNumber());
93    this->left->setRelCoor(0,10,-5);
94  }
95
96  element = root->FirstChildElement("weapon-right");
97  if (element != NULL)  if (element != NULL) element = element->FirstChildElement();
98  this->right = dynamic_cast<Weapon*>( Factory::fabricate( element) );
99  if (this->right)
100  {
101    this->right->setParent(this);
102    this->right->toList(this->getOMListNumber());
103    this->right->setRelCoor(0,10,5);
104  }
105}
106
107/**
108 * advances the GroundTurret about time seconds
109 * @param time the Time to step
110 */
111void GroundTurret::tick(float time)
112{
113
114}
115
116/**
117 * draws this worldEntity
118 */
119void GroundTurret::draw () const
120{
121  glMatrixMode(GL_MODELVIEW);
122  glPushMatrix();
123  float matrix[4][4];
124
125  /* translate */
126  glTranslatef (this->getAbsCoor ().x,
127                this->getAbsCoor ().y,
128                this->getAbsCoor ().z);
129  /* rotate */
130  this->getAbsDir().matrix(matrix);
131  glMultMatrixf((float*)matrix);
132
133  if (this->getModel())
134    this->getModel()->draw();
135
136  glPopMatrix();
137  if (this->left != NULL)
138    this->left->draw();
139  if (this->right != NULL)
140    this->right->draw();
141}
142
143
144/**
145 *
146 *
147 */
148void GroundTurret::collidesWith (WorldEntity* entity, const Vector& location)
149{
150  if (entity->isA(CL_PROJECTILE))
151    this->setAbsDirSoft(Quaternion(-90, Vector(0,0,1)), 90);
152}
153
154/**
155 *
156 *
157 */
158void GroundTurret::postSpawn ()
159{
160
161}
162
163/**
164 *
165 *
166 */
167void GroundTurret::leftWorld ()
168{
169
170}
171
172/**
173 * Writes data from network containing information about the state
174 * @param data pointer to data
175 * @param length length of data
176 * @param sender hostID of sender
177 */
178int GroundTurret::writeBytes( const byte * data, int length, int sender )
179{
180  setRequestedSync( false );
181  setIsOutOfSync( false );
182
183  SYNCHELP_READ_BEGIN();
184
185  SYNCHELP_READ_FKT( WorldEntity::writeState );
186
187  return SYNCHELP_READ_N;
188}
189
190/**
191 * data copied in data will bee sent to another host
192 * @param data pointer to data
193 * @param maxLength max length of data
194 * @return the number of bytes writen
195 */
196int GroundTurret::readBytes( byte * data, int maxLength, int * reciever )
197{
198  SYNCHELP_WRITE_BEGIN();
199
200  if ( isOutOfSync() && !requestedSync() && this->getHostID()!=this->getOwner() )
201  {
202    (NetworkGameManager::getInstance())->sync( this->getUniqueID(), this->getOwner() );
203    setRequestedSync( true );
204  }
205
206  int rec = this->getRequestSync();
207  if ( rec > 0 )
208  {
209    *reciever = rec;
210
211    SYNCHELP_WRITE_FKT( WorldEntity::readState );
212
213  }
214
215  *reciever = 0;
216  return SYNCHELP_WRITE_N;
217}
Note: See TracBrowser for help on using the repository browser.