Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/world_entities/power_ups/weapon_power_up.cc @ 6815

Last change on this file since 6815 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: 2.9 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: Benjamin Grauer
13   co-programmer: ...
14*/
15
16#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WORLD_ENTITY
17
18#include "weapon_power_up.h"
19#include "factory.h"
20#include "state.h"
21#include "list.h"
22#include "network_game_manager.h"
23
24#include "primitive_model.h"
25
26#include "factory.h"
27#include "load_param.h"
28
29using namespace std;
30
31CREATE_FACTORY(WeaponPowerUp, CL_WEAPON_POWER_UP);
32
33WeaponPowerUp::WeaponPowerUp () : PowerUp(1.0, 1.0, 0.0)
34{
35  this->init();
36}
37
38WeaponPowerUp::WeaponPowerUp(const TiXmlElement* root) : PowerUp(1.0, 1.0, 0.0)
39{
40  this->init();
41  if( root != NULL)
42    this->loadParams(root);
43}
44
45
46WeaponPowerUp::~WeaponPowerUp ()
47{
48}
49
50
51void WeaponPowerUp::init()
52{
53  this->setClassID(CL_WEAPON_POWER_UP, "WeaponPowerUp");
54  this->weaponXML = NULL;
55  this->weaponID = CL_NULL;
56  this->weapon = NULL;
57}
58
59
60void WeaponPowerUp::loadParams(const TiXmlElement* root)
61{
62  PowerUp::loadParams(root);
63  const TiXmlElement* elem = root->FirstChildElement("weapon");
64  if(elem != NULL && (elem = elem->FirstChildElement()) != NULL)
65  {
66    this->weaponXML = elem;
67    respawn();
68  }
69  else
70  {
71    LoadParam(root, "weaponID", this, WeaponPowerUp, setWeaponClass);
72  }
73}
74
75Weapon* WeaponPowerUp::getWeapon()
76{
77  return this->weapon;
78}
79
80void WeaponPowerUp::respawn()
81{
82  this->weapon = dynamic_cast<Weapon*>((weaponXML == NULL)
83      ? Factory::fabricate(static_cast<ClassID>(weaponID))
84      : Factory::fabricate((TiXmlElement*)this->getXmlElem()->FirstChildElement("weapon")));
85  this->model = this->weapon->getModel(0);
86}
87
88void WeaponPowerUp::setWeaponClass(const char* name)
89{
90  this->weapon = dynamic_cast<Weapon*>(Factory::fabricate(name));
91  this->weaponID = (ClassID)this->weapon->getLeafClassID();
92  this->model = this->weapon->getModel(0);
93}
94
95int WeaponPowerUp::writeBytes( const byte * data, int length, int sender )
96{
97  setRequestedSync( false );
98  setIsOutOfSync( false );
99
100  SYNCHELP_READ_BEGIN();
101
102  SYNCHELP_READ_FKT( PowerUp::writeState, NWT_WPU_WE_STATE );
103
104  //TODO: sync weapon class ( see loadParams )
105
106  return SYNCHELP_READ_N;
107}
108
109
110
111int WeaponPowerUp::readBytes( byte * data, int maxLength, int * reciever )
112{
113  if ( isOutOfSync() && !requestedSync() && this->getHostID()!=this->getOwner() )
114  {
115    (NetworkGameManager::getInstance())->sync( this->getUniqueID(), this->getOwner() );
116    setRequestedSync( true );
117  }
118
119  int rec = this->getRequestSync();
120  if ( rec > 0 )
121  {
122    *reciever = rec;
123
124    SYNCHELP_WRITE_BEGIN();
125
126    SYNCHELP_WRITE_FKT( PowerUp::readState, NWT_WPU_WE_STATE );
127
128    //TODO: sync weapon class ( see loadParams )
129
130    return SYNCHELP_WRITE_N;
131  }
132
133  *reciever = 0;
134  return 0;
135}
Note: See TracBrowser for help on using the repository browser.