Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: merged branches/network back to the trunk.
merged with command:
svn merge https://svn.orxonox.net/orxonox/branches/network . -r6774:HEAD

no conflicts…
thats what i call orthogonal work

File size: 4.4 KB
RevLine 
[5596]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"
[5739]17#include "model.h"
[6432]18#include "world_entities/weapons/turret.h"
[5596]19
[5795]20#include "factory.h"
[6341]21#include "network_game_manager.h"
[5795]22#include "load_param.h"
23
[5739]24CREATE_FACTORY(GroundTurret, CL_GROUND_TURRET);
25
[5596]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{
[5679]56  this->setClassID(CL_GROUND_TURRET, "GroundTurret");
[5739]57  this->loadModel("models/ground_turret.obj", 5);
[5795]58  this->left = NULL;
59  this->right = NULL;
60
61  /*  left = new Turret();
[5740]62  left->setParent(this);
63  left->setRelCoor(0,10,0);
64  right = new Turret();
65  right->setParent(this);
[5795]66  right->setRelCoor(0,10,0);*/
[5596]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.
[6512]78  NPC::loadParams(root);
[5596]79
80
81  /**
82   * @todo: make the class Loadable
83   */
[5819]84  const TiXmlElement* element;
85
86  element = root->FirstChildElement("weapon-left");
87  if (element != NULL) element = element->FirstChildElement();
[5982]88  this->left = dynamic_cast<Weapon*>( Factory::fabricate( element) );
[5819]89  if (this->left)
90  {
91    this->left->setParent(this);
[6142]92    this->left->toList(this->getOMListNumber());
[5819]93    this->left->setRelCoor(0,10,-5);
[6433]94    this->left->requestAction( WA_ACTIVATE);
[5819]95  }
96
97  element = root->FirstChildElement("weapon-right");
98  if (element != NULL)  if (element != NULL) element = element->FirstChildElement();
[5982]99  this->right = dynamic_cast<Weapon*>( Factory::fabricate( element) );
[5819]100  if (this->right)
101  {
102    this->right->setParent(this);
[6142]103    this->right->toList(this->getOMListNumber());
[5819]104    this->right->setRelCoor(0,10,5);
[6433]105    this->left->requestAction( WA_ACTIVATE);
[5819]106  }
[5596]107}
108
109/**
110 * advances the GroundTurret about time seconds
111 * @param time the Time to step
112 */
[6433]113void GroundTurret::tick(float dt)
[5739]114{
[6433]115  if (likely(this->left != NULL))
116  {
[6736]117//    this->left->tickW(dt);
[6433]118    this->left->requestAction(WA_SHOOT);
119  }
120  if (likely(this->right != NULL))
121  {
[6736]122//    this->right->tickW(dt);
[6433]123    this->right->requestAction(WA_SHOOT);
124  }
[5596]125
[5739]126}
127
[5596]128/**
129 * draws this worldEntity
130 */
131void GroundTurret::draw () const
132{
[6424]133  WorldEntity::draw();
[5596]134
[5819]135  if (this->left != NULL)
[5795]136    this->left->draw();
137  if (this->right != NULL)
138    this->right->draw();
[5596]139}
140
141
142/**
143 *
144 *
145 */
146void GroundTurret::collidesWith (WorldEntity* entity, const Vector& location)
147{
[5915]148  if (entity->isA(CL_PROJECTILE))
149    this->setAbsDirSoft(Quaternion(-90, Vector(0,0,1)), 90);
[5596]150}
[5680]151
152/**
153 *
154 *
155 */
156void GroundTurret::postSpawn ()
157{
[5795]158
[5680]159}
160
161/**
162 *
163 *
164 */
165void GroundTurret::leftWorld ()
166{
[5795]167
[5680]168}
[6341]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
[6815]183  SYNCHELP_READ_FKT( WorldEntity::writeState, NWT_GT_WE_STATE );
[6341]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
[6815]209    SYNCHELP_WRITE_FKT( WorldEntity::readState, NWT_GT_WE_STATE );
[6341]210
211  }
212
213  *reciever = 0;
214  return SYNCHELP_WRITE_N;
215}
Note: See TracBrowser for help on using the repository browser.