Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: merged the WeaponManager back to the trunk

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