| [3580] | 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 |  | 
|---|
|  | 23 |  | 
|---|
| [9406] | 24 |  | 
|---|
| [3580] | 25 | /** | 
|---|
| [4836] | 26 | *  standard constructor | 
|---|
|  | 27 | @todo this constructor is not jet implemented - do it | 
|---|
| [3580] | 28 | */ | 
|---|
|  | 29 | CharacterAttributes::CharacterAttributes () | 
|---|
|  | 30 | { | 
|---|
| [4320] | 31 | this->setClassID(CL_CHARACTER_ATTRIBUTES, "CharacterAttributes"); | 
|---|
| [3580] | 32 | } | 
|---|
|  | 33 |  | 
|---|
|  | 34 |  | 
|---|
|  | 35 | /** | 
|---|
| [4836] | 36 | *  standard deconstructor | 
|---|
| [3580] | 37 |  | 
|---|
|  | 38 | */ | 
|---|
|  | 39 | CharacterAttributes::~CharacterAttributes () | 
|---|
|  | 40 | { | 
|---|
|  | 41 | } | 
|---|
| [3582] | 42 |  | 
|---|
|  | 43 |  | 
|---|
|  | 44 | /*=====================health=====================*/ | 
|---|
|  | 45 |  | 
|---|
|  | 46 | /** | 
|---|
| [4836] | 47 | *  sets the health of the character | 
|---|
|  | 48 | * @param helath | 
|---|
| [3582] | 49 | */ | 
|---|
|  | 50 | void CharacterAttributes::setHealth(int health) | 
|---|
| [3583] | 51 | { | 
|---|
|  | 52 | this->health = health; | 
|---|
|  | 53 | } | 
|---|
| [3582] | 54 |  | 
|---|
|  | 55 | /** | 
|---|
| [4836] | 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 | 
|---|
| [3582] | 59 | */ | 
|---|
|  | 60 | int CharacterAttributes::addHealth(int health) | 
|---|
| [3583] | 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 | } | 
|---|
| [3582] | 71 |  | 
|---|
|  | 72 | /** | 
|---|
| [4836] | 73 | *  remove health due to damager for example | 
|---|
|  | 74 | * @param amount of health | 
|---|
|  | 75 | * @returns false if health is zero -> dead | 
|---|
| [3582] | 76 | */ | 
|---|
|  | 77 | bool CharacterAttributes::substractHealth(int health) | 
|---|
| [3583] | 78 | { | 
|---|
|  | 79 | this->health -= health; | 
|---|
|  | 80 | if( this->health < 0) | 
|---|
|  | 81 | { | 
|---|
|  | 82 | this->health = 0; | 
|---|
|  | 83 | return false; | 
|---|
|  | 84 | } | 
|---|
|  | 85 | return true; | 
|---|
|  | 86 | } | 
|---|
| [3582] | 87 |  | 
|---|
|  | 88 | /** | 
|---|
| [4836] | 89 | *  gets the current amount of health | 
|---|
|  | 90 | * @returns health | 
|---|
| [3582] | 91 | */ | 
|---|
|  | 92 | int CharacterAttributes::getHealth() | 
|---|
| [3583] | 93 | { | 
|---|
|  | 94 | return this->health; | 
|---|
|  | 95 | } | 
|---|
| [3582] | 96 |  | 
|---|
|  | 97 |  | 
|---|
|  | 98 | /** | 
|---|
| [4836] | 99 | *  sets maximum health | 
|---|
|  | 100 | * @param health | 
|---|
| [3582] | 101 |  | 
|---|
|  | 102 | if healthMax = 0 -> unlimited | 
|---|
|  | 103 | */ | 
|---|
|  | 104 | void CharacterAttributes::setHealthMax(int healthMax) | 
|---|
| [3583] | 105 | { | 
|---|
|  | 106 | this->healthMax = healthMax; | 
|---|
|  | 107 | } | 
|---|
| [3582] | 108 |  | 
|---|
|  | 109 | /** | 
|---|
| [4836] | 110 | *  gets health maximium | 
|---|
|  | 111 | * @returns the health maximum | 
|---|
| [3582] | 112 | */ | 
|---|
|  | 113 | int CharacterAttributes::getHealthMax() | 
|---|
| [3583] | 114 | { | 
|---|
|  | 115 | return this->healthMax; | 
|---|
|  | 116 | } | 
|---|
| [3582] | 117 |  | 
|---|
|  | 118 |  | 
|---|
|  | 119 | /*======================armor/ shields===================== */ | 
|---|
|  | 120 | /** | 
|---|
| [4836] | 121 | *  sets the shild strength | 
|---|
|  | 122 | * @param strength | 
|---|
| [3582] | 123 | */ | 
|---|
|  | 124 | void CharacterAttributes::setShieldStrength(int shieldStrength) | 
|---|
| [3583] | 125 | { | 
|---|
|  | 126 | this->shieldStrength = shieldStrength; | 
|---|
|  | 127 | } | 
|---|
| [3582] | 128 |  | 
|---|
|  | 129 | /** | 
|---|
| [4836] | 130 | *  adds shield strength | 
|---|
|  | 131 | * @param strength | 
|---|
| [3583] | 132 |  | 
|---|
|  | 133 | there is currently no limit to shieldstrength | 
|---|
| [3582] | 134 | */ | 
|---|
|  | 135 | void CharacterAttributes::addShieldStrength(int shiledStrength) | 
|---|
| [3583] | 136 | { | 
|---|
|  | 137 | this->shieldStrength += shieldStrength; | 
|---|
|  | 138 | } | 
|---|
| [3582] | 139 |  | 
|---|
|  | 140 | /** | 
|---|
| [4836] | 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 | 
|---|
| [3582] | 144 | */ | 
|---|
|  | 145 | int CharacterAttributes::substractShieldStrength(int shieldStrength) | 
|---|
| [3583] | 146 | { | 
|---|
|  | 147 | int rest = this->shieldStrength -= shieldStrength; | 
|---|
|  | 148 | if( rest < 0) | 
|---|
|  | 149 | { | 
|---|
|  | 150 | this->shieldStrength = 0; | 
|---|
|  | 151 | return -rest; | 
|---|
|  | 152 | } | 
|---|
|  | 153 | return 0; | 
|---|
|  | 154 | } | 
|---|
| [3582] | 155 |  | 
|---|
|  | 156 | /** | 
|---|
| [4836] | 157 | *  gets shield strength | 
|---|
|  | 158 | * @returns the shield strength | 
|---|
| [3582] | 159 | */ | 
|---|
|  | 160 | int CharacterAttributes::getShieldStrength() | 
|---|
| [3583] | 161 | { | 
|---|
|  | 162 | return this->shieldStrength; | 
|---|
|  | 163 | } | 
|---|
| [3582] | 164 |  | 
|---|
|  | 165 |  | 
|---|
|  | 166 | /*=====================damage=====================*/ | 
|---|
|  | 167 | /** | 
|---|
| [4836] | 168 | *  sets the amount of base damage dealt to all aircrafts | 
|---|
|  | 169 | * @param damage | 
|---|
| [3583] | 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) | 
|---|
| [3582] | 174 | */ | 
|---|
|  | 175 | void CharacterAttributes::setDamageToAirCraft(int damage) | 
|---|
| [3583] | 176 | { | 
|---|
|  | 177 | this->damageToAirCraft = damage; | 
|---|
|  | 178 | } | 
|---|
| [3582] | 179 |  | 
|---|
|  | 180 | /** | 
|---|
| [4836] | 181 | *  gets the amount of base damage | 
|---|
|  | 182 | * @returns base damage to aircrafts | 
|---|
| [3583] | 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) | 
|---|
| [3582] | 187 | */ | 
|---|
|  | 188 | int CharacterAttributes::getDamageToAirCraft() | 
|---|
| [3583] | 189 | { | 
|---|
|  | 190 | return this->damageToAirCraft; | 
|---|
|  | 191 | } | 
|---|
| [3582] | 192 |  | 
|---|
|  | 193 |  | 
|---|
|  | 194 | /** | 
|---|
| [4836] | 195 | *  sets the amount of base damage dealt to all groundcrafts | 
|---|
|  | 196 | * @param damage | 
|---|
| [3583] | 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) | 
|---|
| [3582] | 201 | */ | 
|---|
|  | 202 | void CharacterAttributes::setDamageToGroundCraft(int damage) | 
|---|
| [3583] | 203 | { | 
|---|
|  | 204 | this->damageToGroundCraft = damage; | 
|---|
|  | 205 | } | 
|---|
| [3582] | 206 |  | 
|---|
|  | 207 | /** | 
|---|
| [4836] | 208 | * gets the amount of base damage | 
|---|
|  | 209 | * @returns base damage to groundcrafts | 
|---|
| [3583] | 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) | 
|---|
| [3582] | 214 | */ | 
|---|
|  | 215 | int CharacterAttributes::getDamageToGroundCraft() | 
|---|
| [3583] | 216 | { | 
|---|
|  | 217 | return this->damageToGroundCraft; | 
|---|
|  | 218 | } | 
|---|
| [3582] | 219 |  | 
|---|
|  | 220 |  | 
|---|
|  | 221 | /** | 
|---|
| [4836] | 222 | *  sets the damage modifier to the damage that is dealed via laser weapons | 
|---|
|  | 223 | * @param modifier [0..1] | 
|---|
| [3582] | 224 |  | 
|---|
|  | 225 | eg. the damage is calculated after: damage = modifier * damageToGroundCraft | 
|---|
|  | 226 | */ | 
|---|
|  | 227 | void CharacterAttributes::setDamageLaserModifier(float modifier) | 
|---|
| [3583] | 228 | { | 
|---|
|  | 229 | this->damageLaserModifier = modifier; | 
|---|
|  | 230 | } | 
|---|
| [3582] | 231 |  | 
|---|
|  | 232 | /** | 
|---|
| [4836] | 233 | *  gets the damage modifier to the damage that is dealed via laser weapons | 
|---|
|  | 234 | * @returns damage modifier | 
|---|
| [3582] | 235 |  | 
|---|
|  | 236 | eg. the damage is calculated after: damage = modifier * damageToGroundCraft | 
|---|
|  | 237 | */ | 
|---|
|  | 238 | float CharacterAttributes::getDamageLaserModifier() | 
|---|
| [3583] | 239 | { | 
|---|
|  | 240 | return this->damageLaserModifier; | 
|---|
|  | 241 | } | 
|---|
| [3582] | 242 |  | 
|---|
|  | 243 |  | 
|---|
|  | 244 | /** | 
|---|
| [4836] | 245 | *  sets the damage modifier to the damage that is dealed via plasma weapons | 
|---|
|  | 246 | * @param damage modifier | 
|---|
| [3582] | 247 |  | 
|---|
|  | 248 | eg. the damage is calculated after: damage = modifier * damageToGroundCraft | 
|---|
|  | 249 | */ | 
|---|
|  | 250 | void CharacterAttributes::setDamagePlasmaModifier(float modifier) | 
|---|
| [3583] | 251 | { | 
|---|
|  | 252 | this->damagePlasmaModifier = modifier; | 
|---|
|  | 253 | } | 
|---|
| [3582] | 254 |  | 
|---|
|  | 255 | /** | 
|---|
| [4836] | 256 | *  gets the damage modifier to the damage that is dealed plasma weapons | 
|---|
|  | 257 | * @returns damage modifier | 
|---|
| [3582] | 258 |  | 
|---|
|  | 259 | eg. the damage is calculated after: damage = modifier * damageToGroundCraft | 
|---|
|  | 260 | */ | 
|---|
|  | 261 | float CharacterAttributes::getDamagePlasmaModifier() | 
|---|
| [3583] | 262 | { | 
|---|
|  | 263 | return this->damagePlasmaModifier; | 
|---|
|  | 264 | } | 
|---|
| [3582] | 265 |  | 
|---|
|  | 266 |  | 
|---|
|  | 267 | /** | 
|---|
| [4836] | 268 | *  sets the damage modifier to the damage that is dealed via explosives | 
|---|
|  | 269 | * @param damage modifier | 
|---|
| [3582] | 270 |  | 
|---|
|  | 271 | eg. the damage is calculated after: damage = modifier * damageToGroundCraft | 
|---|
|  | 272 | */ | 
|---|
|  | 273 | void CharacterAttributes::setDamageExplosiveModifier(float modifier) | 
|---|
| [3583] | 274 | { | 
|---|
|  | 275 | this->damageExplosiveModifier = modifier; | 
|---|
|  | 276 | } | 
|---|
| [3582] | 277 |  | 
|---|
|  | 278 | /** | 
|---|
| [4836] | 279 | *  sets the damage modifier to the damage that is dealed via explosives | 
|---|
|  | 280 | * @returns damage modifier | 
|---|
| [3582] | 281 |  | 
|---|
|  | 282 | eg. the damage is calculated after: damage = modifier * damageToGroundCraft | 
|---|
|  | 283 | */ | 
|---|
|  | 284 | float CharacterAttributes::getDamageExplosiveModifier() | 
|---|
| [3583] | 285 | { | 
|---|
|  | 286 | return this->damageExplosiveModifier; | 
|---|
|  | 287 | } | 
|---|
| [3582] | 288 |  | 
|---|
|  | 289 |  | 
|---|
|  | 290 | /*=====================energy=====================*/ | 
|---|
|  | 291 | /** | 
|---|
| [4836] | 292 | *  sets the amount of energy | 
|---|
|  | 293 | * @param energy | 
|---|
| [3582] | 294 | */ | 
|---|
|  | 295 | void CharacterAttributes::setEnergy(int energy) | 
|---|
| [3583] | 296 | { | 
|---|
|  | 297 | this->energy = energy; | 
|---|
|  | 298 | } | 
|---|
| [3582] | 299 |  | 
|---|
|  | 300 | /** | 
|---|
| [4836] | 301 | *  adds energy to the system | 
|---|
|  | 302 | * @param amount of energy | 
|---|
|  | 303 | * @returns amount of energy that is too much due to energy limit | 
|---|
| [3582] | 304 | */ | 
|---|
|  | 305 | int CharacterAttributes::addEnergy(int addEnergy) | 
|---|
| [3583] | 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 | } | 
|---|
| [3582] | 316 |  | 
|---|
|  | 317 | /** | 
|---|
| [4836] | 318 | *  substracts energy from a system | 
|---|
|  | 319 | * @param amount of energy | 
|---|
|  | 320 | * @returns false if there is no energy anymore | 
|---|
| [3582] | 321 | */ | 
|---|
|  | 322 | bool CharacterAttributes::substractEnergy(int subEnergy) | 
|---|
| [3583] | 323 | { | 
|---|
|  | 324 | this->energy -= subEnergy; | 
|---|
|  | 325 | if(this->energy < 0) | 
|---|
|  | 326 | { | 
|---|
|  | 327 | this->energy = 0; | 
|---|
|  | 328 | return false; | 
|---|
|  | 329 | } | 
|---|
|  | 330 | return true; | 
|---|
|  | 331 | } | 
|---|
| [3582] | 332 |  | 
|---|
|  | 333 | /** | 
|---|
| [4836] | 334 | *  gets the amount of energy | 
|---|
|  | 335 | * @returns energy | 
|---|
| [3582] | 336 | */ | 
|---|
|  | 337 | int CharacterAttributes::getEnergy() | 
|---|
| [3583] | 338 | { | 
|---|
|  | 339 | return this->energy; | 
|---|
|  | 340 | } | 
|---|
| [3582] | 341 |  | 
|---|
|  | 342 |  | 
|---|
|  | 343 | /** | 
|---|
| [4836] | 344 | *  sets the energy consumption | 
|---|
|  | 345 | * @param amount of energy | 
|---|
| [3582] | 346 | */ | 
|---|
| [3583] | 347 | void CharacterAttributes::setEnergyConsumption(int energy) | 
|---|
|  | 348 | { | 
|---|
|  | 349 | this->energyConsumption = energy; | 
|---|
|  | 350 | } | 
|---|
| [3582] | 351 |  | 
|---|
|  | 352 | /** | 
|---|
| [4836] | 353 | *  gets the energy consumption | 
|---|
|  | 354 | * @returns amount of energy | 
|---|
| [3582] | 355 | */ | 
|---|
| [3583] | 356 | int CharacterAttributes::getEnergyConsumption() | 
|---|
|  | 357 | { | 
|---|
|  | 358 | return this->energyConsumption; | 
|---|
|  | 359 | } | 
|---|
| [3582] | 360 |  | 
|---|
|  | 361 |  | 
|---|
|  | 362 | /** | 
|---|
| [4836] | 363 | *  sets the maximum energy level | 
|---|
|  | 364 | * @param amount of energy | 
|---|
| [3582] | 365 | */ | 
|---|
| [3583] | 366 | void CharacterAttributes::setEnergyMax(int energy) | 
|---|
|  | 367 | { | 
|---|
|  | 368 | this->energyMax = energy; | 
|---|
|  | 369 | } | 
|---|
| [3582] | 370 |  | 
|---|
|  | 371 | /** | 
|---|
| [4836] | 372 | *  gets the max energy level | 
|---|
|  | 373 | * @returns amount of energy | 
|---|
| [3582] | 374 | */ | 
|---|
| [3583] | 375 | int CharacterAttributes::getEnergyMax() | 
|---|
|  | 376 | { | 
|---|
|  | 377 | return this->energyMax; | 
|---|
|  | 378 | } | 
|---|