[6113] | 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 "weapon_power_up.h" |
---|
[7193] | 19 | #include "util/loading/factory.h" |
---|
[6113] | 20 | #include "state.h" |
---|
[6424] | 21 | #include "network_game_manager.h" |
---|
[6113] | 22 | |
---|
| 23 | #include "primitive_model.h" |
---|
| 24 | |
---|
[7193] | 25 | #include "util/loading/factory.h" |
---|
| 26 | #include "util/loading/load_param.h" |
---|
[6113] | 27 | |
---|
| 28 | |
---|
[9406] | 29 | |
---|
[6113] | 30 | CREATE_FACTORY(WeaponPowerUp, CL_WEAPON_POWER_UP); |
---|
| 31 | |
---|
| 32 | WeaponPowerUp::WeaponPowerUp(const TiXmlElement* root) : PowerUp(1.0, 1.0, 0.0) |
---|
| 33 | { |
---|
| 34 | this->init(); |
---|
[6695] | 35 | if( root != NULL) |
---|
| 36 | this->loadParams(root); |
---|
[6113] | 37 | } |
---|
| 38 | |
---|
| 39 | |
---|
| 40 | WeaponPowerUp::~WeaponPowerUp () |
---|
| 41 | { |
---|
| 42 | } |
---|
| 43 | |
---|
| 44 | |
---|
| 45 | void WeaponPowerUp::init() |
---|
| 46 | { |
---|
[6547] | 47 | this->setClassID(CL_WEAPON_POWER_UP, "WeaponPowerUp"); |
---|
[7077] | 48 | this->loadPickupSound("sound/powerups/whats this2.wav"); |
---|
| 49 | |
---|
[6547] | 50 | this->weaponXML = NULL; |
---|
| 51 | this->weapon = NULL; |
---|
[6113] | 52 | } |
---|
| 53 | |
---|
| 54 | |
---|
| 55 | void WeaponPowerUp::loadParams(const TiXmlElement* root) |
---|
| 56 | { |
---|
[6512] | 57 | PowerUp::loadParams(root); |
---|
[6113] | 58 | const TiXmlElement* elem = root->FirstChildElement("weapon"); |
---|
| 59 | if(elem != NULL && (elem = elem->FirstChildElement()) != NULL) |
---|
| 60 | { |
---|
| 61 | this->weaponXML = elem; |
---|
[6973] | 62 | newWeapon(); |
---|
[6113] | 63 | } |
---|
| 64 | else |
---|
| 65 | { |
---|
| 66 | LoadParam(root, "weaponID", this, WeaponPowerUp, setWeaponClass); |
---|
| 67 | } |
---|
| 68 | } |
---|
| 69 | |
---|
| 70 | Weapon* WeaponPowerUp::getWeapon() |
---|
| 71 | { |
---|
| 72 | return this->weapon; |
---|
| 73 | } |
---|
| 74 | |
---|
[6973] | 75 | bool WeaponPowerUp::process(WeaponManager* manager) |
---|
[6113] | 76 | { |
---|
[6973] | 77 | if(manager->addWeapon(this->weapon)) { |
---|
| 78 | newWeapon(); |
---|
| 79 | } |
---|
| 80 | else { |
---|
| 81 | manager->increaseAmmunition(this->weapon->getProjectileType(), this->weapon->getEnergy()); |
---|
| 82 | } |
---|
| 83 | return true; |
---|
| 84 | } |
---|
| 85 | |
---|
| 86 | void WeaponPowerUp::newWeapon() |
---|
| 87 | { |
---|
[6113] | 88 | this->weapon = dynamic_cast<Weapon*>((weaponXML == NULL) |
---|
[6973] | 89 | ? Factory::fabricate(static_cast<ClassID>(this->weapon->getLeafClassID())) |
---|
[7370] | 90 | : Factory::fabricate((const TiXmlElement*)this->getXmlElem()->FirstChildElement("weapon"))); |
---|
[6710] | 91 | this->model = this->weapon->getModel(0); |
---|
[6113] | 92 | } |
---|
| 93 | |
---|
[7221] | 94 | void WeaponPowerUp::setWeaponClass(const std::string& name) |
---|
[6113] | 95 | { |
---|
| 96 | this->weapon = dynamic_cast<Weapon*>(Factory::fabricate(name)); |
---|
[7077] | 97 | if (this->weapon == NULL) |
---|
| 98 | { |
---|
[7221] | 99 | PRINTF(1)("Unable to load Weapon. %s\n", name.c_str()); |
---|
[7077] | 100 | this->weapon = dynamic_cast<Weapon*>(Factory::fabricate("Turret")); |
---|
| 101 | } |
---|
[6710] | 102 | this->model = this->weapon->getModel(0); |
---|
[6113] | 103 | } |
---|
[6424] | 104 | |
---|