| 1 |  | 
|---|
| 2 |  | 
|---|
| 3 | /*  | 
|---|
| 4 |    orxonox - the future of 3D-vertical-scrollers | 
|---|
| 5 |  | 
|---|
| 6 |    Copyright (C) 2004 orx | 
|---|
| 7 |  | 
|---|
| 8 |    This program is free software; you can redistribute it and/or modify | 
|---|
| 9 |    it under the terms of the GNU General Public License as published by | 
|---|
| 10 |    the Free Software Foundation; either version 2, or (at your option) | 
|---|
| 11 |    any later version. | 
|---|
| 12 |  | 
|---|
| 13 |    ### File Specific: | 
|---|
| 14 |    main-programmer: Patrick Boenzli | 
|---|
| 15 |    co-programmer: ... | 
|---|
| 16 | */ | 
|---|
| 17 |  | 
|---|
| 18 |  | 
|---|
| 19 | #include "character_attributes.h" | 
|---|
| 20 | #include "stdincl.h"  | 
|---|
| 21 |  | 
|---|
| 22 | using namespace std; | 
|---|
| 23 |  | 
|---|
| 24 |  | 
|---|
| 25 | /** | 
|---|
| 26 |  *  standard constructor | 
|---|
| 27 |    @todo this constructor is not jet implemented - do it | 
|---|
| 28 | */ | 
|---|
| 29 | CharacterAttributes::CharacterAttributes ()  | 
|---|
| 30 | { | 
|---|
| 31 |    this->setClassID(CL_CHARACTER_ATTRIBUTES, "CharacterAttributes"); | 
|---|
| 32 | } | 
|---|
| 33 |  | 
|---|
| 34 |  | 
|---|
| 35 | /** | 
|---|
| 36 |  *  standard deconstructor | 
|---|
| 37 |  | 
|---|
| 38 | */ | 
|---|
| 39 | CharacterAttributes::~CharacterAttributes ()  | 
|---|
| 40 | { | 
|---|
| 41 | } | 
|---|
| 42 |  | 
|---|
| 43 |  | 
|---|
| 44 | /*=====================health=====================*/ | 
|---|
| 45 |  | 
|---|
| 46 | /** | 
|---|
| 47 |  *  sets the health of the character | 
|---|
| 48 |  * @param helath | 
|---|
| 49 |  */ | 
|---|
| 50 | void CharacterAttributes::setHealth(int health) | 
|---|
| 51 | { | 
|---|
| 52 |   this->health = health; | 
|---|
| 53 | } | 
|---|
| 54 |  | 
|---|
| 55 | /** | 
|---|
| 56 |  *  adds health to the charater | 
|---|
| 57 |  * @param health | 
|---|
| 58 |  * @returns health that couldnt be added due to healt limit, 0 if everything worked as normal | 
|---|
| 59 |  */ | 
|---|
| 60 | int CharacterAttributes::addHealth(int health) | 
|---|
| 61 | { | 
|---|
| 62 |   this->health += health; | 
|---|
| 63 |   int rest = this->healthMax - this->health; | 
|---|
| 64 |   if( rest < 0) | 
|---|
| 65 |     { | 
|---|
| 66 |       this->health = this->healthMax; | 
|---|
| 67 |       return 0; | 
|---|
| 68 |     } | 
|---|
| 69 |   return rest; | 
|---|
| 70 | } | 
|---|
| 71 |  | 
|---|
| 72 | /** | 
|---|
| 73 |  *  remove health due to damager for example | 
|---|
| 74 |  * @param amount of health | 
|---|
| 75 |  * @returns false if health is zero -> dead | 
|---|
| 76 |  */ | 
|---|
| 77 | bool CharacterAttributes::substractHealth(int health) | 
|---|
| 78 | { | 
|---|
| 79 |   this->health -= health; | 
|---|
| 80 |   if( this->health < 0) | 
|---|
| 81 |     { | 
|---|
| 82 |       this->health = 0; | 
|---|
| 83 |       return false; | 
|---|
| 84 |     } | 
|---|
| 85 |   return true; | 
|---|
| 86 | } | 
|---|
| 87 |  | 
|---|
| 88 | /** | 
|---|
| 89 |  *  gets the current amount of health | 
|---|
| 90 |  * @returns health | 
|---|
| 91 |  */ | 
|---|
| 92 | int CharacterAttributes::getHealth() | 
|---|
| 93 | { | 
|---|
| 94 |   return this->health; | 
|---|
| 95 | } | 
|---|
| 96 |  | 
|---|
| 97 |  | 
|---|
| 98 | /** | 
|---|
| 99 |  *  sets maximum health  | 
|---|
| 100 |  * @param health | 
|---|
| 101 |  | 
|---|
| 102 |    if healthMax = 0 -> unlimited | 
|---|
| 103 |  */ | 
|---|
| 104 | void CharacterAttributes::setHealthMax(int healthMax) | 
|---|
| 105 | { | 
|---|
| 106 |   this->healthMax = healthMax; | 
|---|
| 107 | } | 
|---|
| 108 |  | 
|---|
| 109 | /** | 
|---|
| 110 |  *  gets health maximium | 
|---|
| 111 |  * @returns the health maximum | 
|---|
| 112 |  */ | 
|---|
| 113 | int CharacterAttributes::getHealthMax() | 
|---|
| 114 | { | 
|---|
| 115 |   return this->healthMax; | 
|---|
| 116 | } | 
|---|
| 117 |  | 
|---|
| 118 |  | 
|---|
| 119 | /*======================armor/ shields===================== */ | 
|---|
| 120 | /** | 
|---|
| 121 |  *  sets the shild strength | 
|---|
| 122 |  * @param strength | 
|---|
| 123 |  */ | 
|---|
| 124 | void CharacterAttributes::setShieldStrength(int shieldStrength) | 
|---|
| 125 | { | 
|---|
| 126 |   this->shieldStrength = shieldStrength; | 
|---|
| 127 | } | 
|---|
| 128 |  | 
|---|
| 129 | /** | 
|---|
| 130 |  *  adds shield strength | 
|---|
| 131 |  * @param strength | 
|---|
| 132 |     | 
|---|
| 133 |    there is currently no limit to shieldstrength | 
|---|
| 134 |  */ | 
|---|
| 135 | void CharacterAttributes::addShieldStrength(int shiledStrength) | 
|---|
| 136 | { | 
|---|
| 137 |   this->shieldStrength += shieldStrength; | 
|---|
| 138 | } | 
|---|
| 139 |  | 
|---|
| 140 | /** | 
|---|
| 141 |  *  substracts shield strength | 
|---|
| 142 |  * @param strength | 
|---|
| 143 |  * @returns amount of shield strength below zero after substraction. Magic: Troumble. if everything works allright, it returns 0 | 
|---|
| 144 |  */ | 
|---|
| 145 | int CharacterAttributes::substractShieldStrength(int shieldStrength) | 
|---|
| 146 | { | 
|---|
| 147 |   int rest = this->shieldStrength -= shieldStrength; | 
|---|
| 148 |   if( rest < 0) | 
|---|
| 149 |     { | 
|---|
| 150 |       this->shieldStrength = 0; | 
|---|
| 151 |       return -rest; | 
|---|
| 152 |     } | 
|---|
| 153 |   return 0; | 
|---|
| 154 | } | 
|---|
| 155 |  | 
|---|
| 156 | /** | 
|---|
| 157 |  *  gets shield strength | 
|---|
| 158 |  * @returns the shield strength | 
|---|
| 159 |  */ | 
|---|
| 160 | int CharacterAttributes::getShieldStrength() | 
|---|
| 161 | { | 
|---|
| 162 |   return this->shieldStrength; | 
|---|
| 163 | } | 
|---|
| 164 |  | 
|---|
| 165 |  | 
|---|
| 166 | /*=====================damage=====================*/ | 
|---|
| 167 | /** | 
|---|
| 168 |  *  sets the amount of base damage dealt to all aircrafts | 
|---|
| 169 |  * @param damage | 
|---|
| 170 |  | 
|---|
| 171 |    There can be a difference between arms that hit a ground/air craft. Eg. | 
|---|
| 172 |    a tank will react differently to explosives than something in the air | 
|---|
| 173 |    (think about physics) | 
|---|
| 174 |  */ | 
|---|
| 175 | void CharacterAttributes::setDamageToAirCraft(int damage) | 
|---|
| 176 | { | 
|---|
| 177 |   this->damageToAirCraft = damage; | 
|---|
| 178 | } | 
|---|
| 179 |  | 
|---|
| 180 | /** | 
|---|
| 181 |  *  gets the amount of base damage | 
|---|
| 182 |  * @returns base damage to aircrafts | 
|---|
| 183 |  | 
|---|
| 184 |    There can be a difference between arms that hit a ground/air craft. Eg. | 
|---|
| 185 |    a tank will react differently to explosives than something in the air | 
|---|
| 186 |    (think about physics) | 
|---|
| 187 |  */ | 
|---|
| 188 | int CharacterAttributes::getDamageToAirCraft() | 
|---|
| 189 | { | 
|---|
| 190 |   return this->damageToAirCraft; | 
|---|
| 191 | } | 
|---|
| 192 |  | 
|---|
| 193 |  | 
|---|
| 194 | /** | 
|---|
| 195 |  *  sets the amount of base damage dealt to all groundcrafts | 
|---|
| 196 |  * @param damage | 
|---|
| 197 |  | 
|---|
| 198 |    There can be a difference between arms that hit a ground/air craft. Eg. | 
|---|
| 199 |    a tank will react differently to explosives than something in the air | 
|---|
| 200 |    (think about physics) | 
|---|
| 201 |  */ | 
|---|
| 202 | void CharacterAttributes::setDamageToGroundCraft(int damage) | 
|---|
| 203 | { | 
|---|
| 204 |   this->damageToGroundCraft = damage; | 
|---|
| 205 | } | 
|---|
| 206 |  | 
|---|
| 207 | /** | 
|---|
| 208 |  * gets the amount of base damage | 
|---|
| 209 |  * @returns base damage to groundcrafts | 
|---|
| 210 |  | 
|---|
| 211 |    There can be a difference between arms that hit a ground/air craft. Eg. | 
|---|
| 212 |    a tank will react differently to explosives than something in the air | 
|---|
| 213 |    (think about physics) | 
|---|
| 214 |  */ | 
|---|
| 215 | int CharacterAttributes::getDamageToGroundCraft() | 
|---|
| 216 | { | 
|---|
| 217 |   return this->damageToGroundCraft; | 
|---|
| 218 | } | 
|---|
| 219 |  | 
|---|
| 220 |  | 
|---|
| 221 | /** | 
|---|
| 222 |  *  sets the damage modifier to the damage that is dealed via laser weapons | 
|---|
| 223 |  * @param modifier [0..1] | 
|---|
| 224 |  | 
|---|
| 225 |    eg. the damage is calculated after: damage = modifier * damageToGroundCraft | 
|---|
| 226 |  */ | 
|---|
| 227 | void CharacterAttributes::setDamageLaserModifier(float modifier) | 
|---|
| 228 | { | 
|---|
| 229 |   this->damageLaserModifier = modifier; | 
|---|
| 230 | } | 
|---|
| 231 |  | 
|---|
| 232 | /** | 
|---|
| 233 |  *  gets the damage modifier to the damage that is dealed via laser weapons | 
|---|
| 234 |  * @returns damage modifier | 
|---|
| 235 |  | 
|---|
| 236 |    eg. the damage is calculated after: damage = modifier * damageToGroundCraft | 
|---|
| 237 |  */ | 
|---|
| 238 | float CharacterAttributes::getDamageLaserModifier() | 
|---|
| 239 | { | 
|---|
| 240 |   return this->damageLaserModifier; | 
|---|
| 241 | } | 
|---|
| 242 |  | 
|---|
| 243 |  | 
|---|
| 244 | /** | 
|---|
| 245 |  *  sets the damage modifier to the damage that is dealed via plasma weapons | 
|---|
| 246 |  * @param damage modifier | 
|---|
| 247 |  | 
|---|
| 248 |    eg. the damage is calculated after: damage = modifier * damageToGroundCraft | 
|---|
| 249 |  */ | 
|---|
| 250 | void CharacterAttributes::setDamagePlasmaModifier(float modifier) | 
|---|
| 251 | { | 
|---|
| 252 |   this->damagePlasmaModifier = modifier; | 
|---|
| 253 | } | 
|---|
| 254 |  | 
|---|
| 255 | /** | 
|---|
| 256 |  *  gets the damage modifier to the damage that is dealed plasma weapons | 
|---|
| 257 |  * @returns damage modifier | 
|---|
| 258 |  | 
|---|
| 259 |    eg. the damage is calculated after: damage = modifier * damageToGroundCraft | 
|---|
| 260 |  */ | 
|---|
| 261 | float CharacterAttributes::getDamagePlasmaModifier() | 
|---|
| 262 | { | 
|---|
| 263 |   return this->damagePlasmaModifier; | 
|---|
| 264 | } | 
|---|
| 265 |  | 
|---|
| 266 |  | 
|---|
| 267 | /** | 
|---|
| 268 |  *  sets the damage modifier to the damage that is dealed via explosives | 
|---|
| 269 |  * @param damage modifier | 
|---|
| 270 |  | 
|---|
| 271 |    eg. the damage is calculated after: damage = modifier * damageToGroundCraft | 
|---|
| 272 |  */ | 
|---|
| 273 | void CharacterAttributes::setDamageExplosiveModifier(float modifier) | 
|---|
| 274 | { | 
|---|
| 275 |   this->damageExplosiveModifier = modifier; | 
|---|
| 276 | } | 
|---|
| 277 |  | 
|---|
| 278 | /** | 
|---|
| 279 |  *  sets the damage modifier to the damage that is dealed via explosives | 
|---|
| 280 |  * @returns damage modifier | 
|---|
| 281 |  | 
|---|
| 282 |    eg. the damage is calculated after: damage = modifier * damageToGroundCraft | 
|---|
| 283 |  */ | 
|---|
| 284 | float CharacterAttributes::getDamageExplosiveModifier() | 
|---|
| 285 | { | 
|---|
| 286 |   return this->damageExplosiveModifier; | 
|---|
| 287 | } | 
|---|
| 288 |  | 
|---|
| 289 |  | 
|---|
| 290 | /*=====================energy=====================*/ | 
|---|
| 291 | /** | 
|---|
| 292 |  *  sets the amount of energy  | 
|---|
| 293 |  * @param energy | 
|---|
| 294 |  */ | 
|---|
| 295 | void CharacterAttributes::setEnergy(int energy) | 
|---|
| 296 | { | 
|---|
| 297 |   this->energy = energy; | 
|---|
| 298 | } | 
|---|
| 299 |  | 
|---|
| 300 | /** | 
|---|
| 301 |  *  adds energy to the system | 
|---|
| 302 |  * @param amount of energy | 
|---|
| 303 |  * @returns amount of energy that is too much due to energy limit | 
|---|
| 304 |  */ | 
|---|
| 305 | int CharacterAttributes::addEnergy(int addEnergy) | 
|---|
| 306 | { | 
|---|
| 307 |   this->energy += addEnergy; | 
|---|
| 308 |   int rest = this->energyMax - this->energy; | 
|---|
| 309 |   if(rest < 0) | 
|---|
| 310 |     { | 
|---|
| 311 |       this->energy = 0; | 
|---|
| 312 |       return rest; | 
|---|
| 313 |     } | 
|---|
| 314 |   return 0; | 
|---|
| 315 | } | 
|---|
| 316 |  | 
|---|
| 317 | /** | 
|---|
| 318 |  *  substracts energy from a system | 
|---|
| 319 |  * @param amount of energy | 
|---|
| 320 |  * @returns false if there is no energy anymore | 
|---|
| 321 |  */ | 
|---|
| 322 | bool CharacterAttributes::substractEnergy(int subEnergy) | 
|---|
| 323 | { | 
|---|
| 324 |   this->energy -= subEnergy; | 
|---|
| 325 |   if(this->energy < 0) | 
|---|
| 326 |     { | 
|---|
| 327 |       this->energy = 0; | 
|---|
| 328 |       return false; | 
|---|
| 329 |     } | 
|---|
| 330 |   return true; | 
|---|
| 331 | } | 
|---|
| 332 |  | 
|---|
| 333 | /** | 
|---|
| 334 |  *  gets the amount of energy  | 
|---|
| 335 |  * @returns energy | 
|---|
| 336 |  */ | 
|---|
| 337 | int CharacterAttributes::getEnergy() | 
|---|
| 338 | { | 
|---|
| 339 |   return this->energy; | 
|---|
| 340 | } | 
|---|
| 341 |  | 
|---|
| 342 |  | 
|---|
| 343 | /** | 
|---|
| 344 |  *  sets the energy consumption | 
|---|
| 345 |  * @param amount of energy | 
|---|
| 346 | */ | 
|---|
| 347 | void CharacterAttributes::setEnergyConsumption(int energy) | 
|---|
| 348 | { | 
|---|
| 349 |   this->energyConsumption = energy; | 
|---|
| 350 | } | 
|---|
| 351 |  | 
|---|
| 352 | /** | 
|---|
| 353 |  *  gets the energy consumption | 
|---|
| 354 |  * @returns amount of energy | 
|---|
| 355 | */ | 
|---|
| 356 | int CharacterAttributes::getEnergyConsumption() | 
|---|
| 357 | { | 
|---|
| 358 |   return this->energyConsumption; | 
|---|
| 359 | } | 
|---|
| 360 |    | 
|---|
| 361 |  | 
|---|
| 362 | /** | 
|---|
| 363 |  *  sets the maximum energy level | 
|---|
| 364 |  * @param amount of energy | 
|---|
| 365 | */ | 
|---|
| 366 | void CharacterAttributes::setEnergyMax(int energy) | 
|---|
| 367 | { | 
|---|
| 368 |   this->energyMax = energy; | 
|---|
| 369 | } | 
|---|
| 370 |  | 
|---|
| 371 | /** | 
|---|
| 372 |  *  gets the max energy level | 
|---|
| 373 |  * @returns amount of energy | 
|---|
| 374 | */ | 
|---|
| 375 | int CharacterAttributes::getEnergyMax() | 
|---|
| 376 | { | 
|---|
| 377 |   return this->energyMax; | 
|---|
| 378 | } | 
|---|