Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/powerups/src/world_entities/power_ups/param_power_up.cc @ 6487

Last change on this file since 6487 was 6487, checked in by manuel, 18 years ago

moved pickup from spaceship to playable. playable can now pickup health and max-health powerups

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  static_cast<PowerUp*>(this)->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  }
144
145  return SYNCHELP_READ_N;
146}
147
148
149
150int ParamPowerUp::readBytes( byte * data, int maxLength, int * reciever )
151{
152  if ( isOutOfSync() && !requestedSync() && this->getHostID()!=this->getOwner() )
153  {
154    (NetworkGameManager::getInstance())->sync( this->getUniqueID(), this->getOwner() );
155    setRequestedSync( true );
156  }
157
158  int rec = this->getRequestSync();
159  if ( rec > 0 )
160  {
161    *reciever = rec;
162
163    SYNCHELP_WRITE_BEGIN();
164
165    SYNCHELP_WRITE_FKT( PowerUp::readState );
166
167    int i = this->type;
168    SYNCHELP_WRITE_INT( i );
169    SYNCHELP_WRITE_FLOAT( this->value );
170
171    if ( this->value != 0 )
172    {
173      SYNCHELP_WRITE_FLOAT( this->min_value );
174      SYNCHELP_WRITE_FLOAT( this->max_value );
175    }
176
177    return SYNCHELP_WRITE_N;
178  }
179
180  *reciever = 0;
181  return 0;
182}
183
Note: See TracBrowser for help on using the repository browser.