Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/powerups/src/world_entities/power_ups/weapon_power_up.cc @ 6535

Last change on this file since 6535 was 6535, checked in by manuel, 18 years ago

param- and weaponpowerup debugged and working

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