Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/network/src/world_entities/power_ups/weapon_power_up.cc @ 6419

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

some more entities should sync now

File size: 2.6 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  this->loadParams(root);
42}
43
44
45WeaponPowerUp::~WeaponPowerUp ()
46{
47}
48
49
50void WeaponPowerUp::init()
51{
52  weaponXML = NULL;
53  weapon = NULL;
54}
55
56
57void WeaponPowerUp::loadParams(const TiXmlElement* root)
58{
59  static_cast<PowerUp*>(this)->loadParams(root);
60  const TiXmlElement* elem = root->FirstChildElement("weapon");
61  if(elem != NULL && (elem = elem->FirstChildElement()) != NULL)
62  {
63    this->weaponXML = elem;
64    respawn();
65  }
66  else
67  {
68    LoadParam(root, "weaponID", this, WeaponPowerUp, setWeaponClass);
69  }
70}
71
72Weapon* WeaponPowerUp::getWeapon()
73{
74  return this->weapon;
75}
76
77void WeaponPowerUp::respawn()
78{
79  this->weapon = dynamic_cast<Weapon*>((weaponXML == NULL)
80      ? Factory::fabricate(static_cast<ClassID>(this->weapon->getClassID()))
81      : Factory::fabricate(weaponXML));
82}
83
84void WeaponPowerUp::setWeaponClass(const char* name)
85{
86  this->weapon = dynamic_cast<Weapon*>(Factory::fabricate(name));
87}
88
89int WeaponPowerUp::writeBytes( const byte * data, int length, int sender )
90{
91  setRequestedSync( false );
92  setIsOutOfSync( false );
93
94  SYNCHELP_READ_BEGIN();
95
96  SYNCHELP_READ_FKT( PowerUp::writeState );
97
98  //TODO: sync weapon class ( see loadParams )
99
100  return SYNCHELP_READ_N;
101}
102
103
104
105int WeaponPowerUp::readBytes( byte * data, int maxLength, int * reciever )
106{
107  if ( isOutOfSync() && !requestedSync() && this->getHostID()!=this->getOwner() )
108  {
109    (NetworkGameManager::getInstance())->sync( this->getUniqueID(), this->getOwner() );
110    setRequestedSync( true );
111  }
112
113  int rec = this->getRequestSync();
114  if ( rec > 0 )
115  {
116    *reciever = rec;
117
118    SYNCHELP_WRITE_BEGIN();
119
120    SYNCHELP_WRITE_FKT( PowerUp::readState );
121
122    //TODO: sync weapon class ( see loadParams )
123
124    return SYNCHELP_WRITE_N;
125  }
126
127  *reciever = 0;
128  return 0;
129}
Note: See TracBrowser for help on using the repository browser.