Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/spaceshipcontrol/src/world_entities/weapons/ground_turret.cc @ 6429

Last change on this file since 6429 was 6424, checked in by bensch, 19 years ago

orxonox/trunk: merged the branche network back to the trunk
merged with command:
svn merge https://svn.orxonox.net/orxonox/branches/network . -r 6351:HEAD
no conflicts

File size: 4.1 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  WorldEntity::draw();
122
123  if (this->left != NULL)
124    this->left->draw();
125  if (this->right != NULL)
126    this->right->draw();
127}
128
129
130/**
131 *
132 *
133 */
134void GroundTurret::collidesWith (WorldEntity* entity, const Vector& location)
135{
136  if (entity->isA(CL_PROJECTILE))
137    this->setAbsDirSoft(Quaternion(-90, Vector(0,0,1)), 90);
138}
139
140/**
141 *
142 *
143 */
144void GroundTurret::postSpawn ()
145{
146
147}
148
149/**
150 *
151 *
152 */
153void GroundTurret::leftWorld ()
154{
155
156}
157
158/**
159 * Writes data from network containing information about the state
160 * @param data pointer to data
161 * @param length length of data
162 * @param sender hostID of sender
163 */
164int GroundTurret::writeBytes( const byte * data, int length, int sender )
165{
166  setRequestedSync( false );
167  setIsOutOfSync( false );
168
169  SYNCHELP_READ_BEGIN();
170
171  SYNCHELP_READ_FKT( WorldEntity::writeState );
172
173  return SYNCHELP_READ_N;
174}
175
176/**
177 * data copied in data will bee sent to another host
178 * @param data pointer to data
179 * @param maxLength max length of data
180 * @return the number of bytes writen
181 */
182int GroundTurret::readBytes( byte * data, int maxLength, int * reciever )
183{
184  SYNCHELP_WRITE_BEGIN();
185
186  if ( isOutOfSync() && !requestedSync() && this->getHostID()!=this->getOwner() )
187  {
188    (NetworkGameManager::getInstance())->sync( this->getUniqueID(), this->getOwner() );
189    setRequestedSync( true );
190  }
191
192  int rec = this->getRequestSync();
193  if ( rec > 0 )
194  {
195    *reciever = rec;
196
197    SYNCHELP_WRITE_FKT( WorldEntity::readState );
198
199  }
200
201  *reciever = 0;
202  return SYNCHELP_WRITE_N;
203}
Note: See TracBrowser for help on using the repository browser.