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