Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

TRUNK: merged powerups back

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  PowerUp::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  this->model = this->weapon->getModel(0);
72}
73
74Weapon* WeaponPowerUp::getWeapon()
75{
76  return this->weapon;
77}
78
79void WeaponPowerUp::respawn()
80{
81  this->weapon = dynamic_cast<Weapon*>((weaponXML == NULL)
82      ? Factory::fabricate(static_cast<ClassID>(this->weapon->getClassID()))
83      : Factory::fabricate(weaponXML));
84}
85
86void WeaponPowerUp::setWeaponClass(const char* name)
87{
88  this->weapon = dynamic_cast<Weapon*>(Factory::fabricate(name));
89}
90
91int WeaponPowerUp::writeBytes( const byte * data, int length, int sender )
92{
93  setRequestedSync( false );
94  setIsOutOfSync( false );
95
96  SYNCHELP_READ_BEGIN();
97
98  SYNCHELP_READ_FKT( PowerUp::writeState );
99
100  //TODO: sync weapon class ( see loadParams )
101
102  return SYNCHELP_READ_N;
103}
104
105
106
107int WeaponPowerUp::readBytes( byte * data, int maxLength, int * reciever )
108{
109  if ( isOutOfSync() && !requestedSync() && this->getHostID()!=this->getOwner() )
110  {
111    (NetworkGameManager::getInstance())->sync( this->getUniqueID(), this->getOwner() );
112    setRequestedSync( true );
113  }
114
115  int rec = this->getRequestSync();
116  if ( rec > 0 )
117  {
118    *reciever = rec;
119
120    SYNCHELP_WRITE_BEGIN();
121
122    SYNCHELP_WRITE_FKT( PowerUp::readState );
123
124    //TODO: sync weapon class ( see loadParams )
125
126    return SYNCHELP_WRITE_N;
127  }
128
129  *reciever = 0;
130  return 0;
131}
Note: See TracBrowser for help on using the repository browser.