Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/terrain.older/src/world_entities/power_ups/param_power_up.cc

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

trunk: merged the network branche back to trunk.

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 "param_power_up.h"
19#include "util/loading/factory.h"
20#include "state.h"
21
22#include "primitive_model.h"
23
24#include "util/loading/factory.h"
25#include "util/loading/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  registerVar( new SynchronizeableInt( (int*)&type, (int*)&type, "type" ) );
47  registerVar( new SynchronizeableFloat( &value, &value, "value" ) );
48  registerVar( new SynchronizeableFloat( &max_value, &max_value, "max_value" ) );
49  registerVar( new SynchronizeableFloat( &min_value, &min_value, "min_value" ) );
50}
51
52
53ParamPowerUp::~ParamPowerUp ()
54{
55}
56
57
58void ParamPowerUp::init()
59{
60  this->setClassID(CL_PARAM_POWER_UP, "ParamPowerUp");
61  this->value = 0;
62  this->max_value = 0;
63  this->min_value = 0;
64}
65
66
67void ParamPowerUp::loadParams(const TiXmlElement* root)
68{
69  PowerUp::loadParams(root);
70  LoadParam(root, "type", this, ParamPowerUp, setType);
71
72  if( root != NULL && root->FirstChildElement("value") != NULL) {
73
74    LoadParam(root, "value", this, ParamPowerUp, setValue);
75  }
76  else {
77    LoadParam(root, "max-value", this, ParamPowerUp, setMaxValue);
78    LoadParam(root, "min-value", this, ParamPowerUp, setMinValue);
79    respawn();
80  }
81}
82
83void ParamPowerUp::setValue(float value)
84{
85  this->value = value;
86}
87
88void ParamPowerUp::setType(const std::string& type)
89{
90  for(int i = 0; i < POWERUP_PARAM_size; ++i) {
91    if(type == paramTypes[i]) {
92      this->type = (EnumParamPowerUpType)i;
93      break;
94    }
95  }
96}
97
98void ParamPowerUp::setMaxValue(float value)
99{
100  this->max_value = value;
101}
102
103void ParamPowerUp::setMinValue(float value)
104{
105  this->min_value = value;
106}
107
108float ParamPowerUp::getValue()
109{
110  return this->value;
111}
112
113EnumParamPowerUpType ParamPowerUp::getType()
114{
115  return this->type;
116}
117
118void ParamPowerUp::respawn()
119{
120  if(this->min_value != this->max_value)
121  {
122    this->value = this->min_value + rand() * (this->max_value - this->min_value);
123  }
124}
125
Note: See TracBrowser for help on using the repository browser.