Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 6675 was 6675, checked in by patrick, 18 years ago

network: the net code works again

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