Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/world_entities/power_ups/param_power_up.cc @ 7130

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

orxonox/trunk: removed some std::list

File size: 3.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 "param_power_up.h"
19#include "factory.h"
20#include "state.h"
21
22#include "primitive_model.h"
23
24#include "factory.h"
25#include "load_param.h"
26#include "network_game_manager.h"
27
28using namespace std;
29
30CREATE_FACTORY(ParamPowerUp, CL_PARAM_POWER_UP);
31
32const char* ParamPowerUp::paramTypes[] = {
33  "shield",
34  "max-shield",
35  "health",
36  "max-health",
37};
38
39ParamPowerUp::ParamPowerUp(const TiXmlElement* root) : PowerUp(0.0, 1.0, 0.0)
40{
41  this->init();
42  this->loadPickupSound("sound/powerups/power_up_6.wav");
43  if( root != NULL)
44    this->loadParams(root);
45}
46
47
48ParamPowerUp::~ParamPowerUp ()
49{
50}
51
52
53void ParamPowerUp::init()
54{
55  this->setClassID(CL_PARAM_POWER_UP, "ParamPowerUp");
56  this->value = 0;
57  this->max_value = 0;
58  this->min_value = 0;
59}
60
61
62void ParamPowerUp::loadParams(const TiXmlElement* root)
63{
64  PowerUp::loadParams(root);
65  LoadParam(root, "type", this, ParamPowerUp, setType);
66
67  if( root != NULL && root->FirstChildElement("value") != NULL) {
68
69    LoadParam(root, "value", this, ParamPowerUp, setValue);
70  }
71  else {
72    LoadParam(root, "max-value", this, ParamPowerUp, setMaxValue);
73    LoadParam(root, "min-value", this, ParamPowerUp, setMinValue);
74    respawn();
75  }
76}
77
78void ParamPowerUp::setValue(float value)
79{
80  this->value = value;
81}
82
83void ParamPowerUp::setType(const char* type)
84{
85  for(int i = 0; i < POWERUP_PARAM_size; ++i) {
86    if(strcmp(type, paramTypes[i]) == 0) {
87      this->type = (EnumParamPowerUpType)i;
88      break;
89    }
90  }
91}
92
93void ParamPowerUp::setMaxValue(float value)
94{
95  this->max_value = value;
96}
97
98void ParamPowerUp::setMinValue(float value)
99{
100  this->min_value = value;
101}
102
103float ParamPowerUp::getValue()
104{
105  return this->value;
106}
107
108EnumParamPowerUpType ParamPowerUp::getType()
109{
110  return this->type;
111}
112
113void ParamPowerUp::respawn()
114{
115  if(this->min_value != this->max_value)
116  {
117    this->value = this->min_value + rand() * (this->max_value - this->min_value);
118  }
119}
120
121int ParamPowerUp::writeBytes( const byte * data, int length, int sender )
122{
123  setRequestedSync( false );
124  setIsOutOfSync( false );
125
126  SYNCHELP_READ_BEGIN();
127
128  SYNCHELP_READ_FKT( PowerUp::writeState, NWT_PPU_WE_STATE );
129
130  int i;
131  SYNCHELP_READ_INT( i, NWT_PPU_TYPE );
132  this->type = (EnumParamPowerUpType)i;
133  SYNCHELP_READ_FLOAT( this->value, NWT_PPU_VALUE );
134
135  if ( this->value != 0 )
136  {
137    SYNCHELP_READ_FLOAT( this->min_value, NWT_PPU_MINVALUE );
138    SYNCHELP_READ_FLOAT( this->max_value, NWT_PPU_MAXVALUE );
139    respawn();
140  }
141
142  return SYNCHELP_READ_N;
143}
144
145
146
147int ParamPowerUp::readBytes( byte * data, int maxLength, int * reciever )
148{
149  if ( isOutOfSync() && !requestedSync() && this->getHostID()!=this->getOwner() )
150  {
151    (NetworkGameManager::getInstance())->sync( this->getUniqueID(), this->getOwner() );
152    setRequestedSync( true );
153  }
154
155  int rec = this->getRequestSync();
156  if ( rec > 0 )
157  {
158    *reciever = rec;
159
160    SYNCHELP_WRITE_BEGIN();
161
162    SYNCHELP_WRITE_FKT( PowerUp::readState, NWT_PPU_WE_STATE );
163
164    int i = (int)this->type;
165    SYNCHELP_WRITE_INT( i, NWT_PPU_TYPE );
166    SYNCHELP_WRITE_FLOAT( this->value, NWT_PPU_VALUE );
167
168    if ( this->value != 0 )
169    {
170      SYNCHELP_WRITE_FLOAT( this->min_value, NWT_PPU_MINVALUE );
171      SYNCHELP_WRITE_FLOAT( this->max_value, NWT_PPU_MAXVALUE );
172    }
173
174    return SYNCHELP_WRITE_N;
175  }
176
177  *reciever = 0;
178  return 0;
179}
180
Note: See TracBrowser for help on using the repository browser.