Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/network/src/world_entities/power_ups/param_power_up.cc @ 6419

Last change on this file since 6419 was 6419, checked in by rennerc, 18 years ago

some more entities should sync now

File size: 2.3 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
28using namespace std;
29
30CREATE_FACTORY(ParamPowerUp, CL_PARAM_POWER_UP);
31
32const char* ParamPowerUp::paramTypes[] = {
33  "shield"
34};
35
36ParamPowerUp::ParamPowerUp () : PowerUp(0.0, 1.0, 0.0)
37{
38  this->init();
39}
40
41ParamPowerUp::ParamPowerUp(const TiXmlElement* root) : PowerUp(0.0, 1.0, 0.0)
42{
43  this->init();
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  static_cast<PowerUp*>(this)->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(int value)
79{
80  this->value = value;
81}
82
83void ParamPowerUp::setType(const char* type)
84{
85  for(int i = 0; i < PARAM_size; ++i) {
86    if(strcmp(type, paramTypes[i]) == 0) {
87      this->type = (EnumParamPowerUpType)i;
88      break;
89    }
90  }
91}
92
93void ParamPowerUp::setMaxValue(int value)
94{
95  this->max_value = value;
96}
97
98void ParamPowerUp::setMinValue(int value)
99{
100  this->min_value = value;
101}
102
103int 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    value = this->min_value + (int)(rand() * (this->max_value - this->min_value));
118  }
119}
120
121
Note: See TracBrowser for help on using the repository browser.