Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 6603 was 6512, checked in by bensch, 19 years ago

orxonox/trunk: loadParams is now virtual.
ALL THE CLASSES HAVE TO CALL

SuperClass::loadParams(root);

isntead of:
static_cast<SuperClass*>(this)→loadParams(root);

which was quite stupid anyways

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