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" |
---|
19 | #include "util/loading/factory.h" |
---|
20 | #include "state.h" |
---|
21 | #include "network_game_manager.h" |
---|
22 | |
---|
23 | #include "primitive_model.h" |
---|
24 | |
---|
25 | #include "util/loading/factory.h" |
---|
26 | #include "util/loading/load_param.h" |
---|
27 | |
---|
28 | |
---|
29 | |
---|
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(); |
---|
35 | if( root != NULL) |
---|
36 | this->loadParams(root); |
---|
37 | } |
---|
38 | |
---|
39 | |
---|
40 | WeaponPowerUp::~WeaponPowerUp () |
---|
41 | { |
---|
42 | } |
---|
43 | |
---|
44 | |
---|
45 | void WeaponPowerUp::init() |
---|
46 | { |
---|
47 | this->setClassID(CL_WEAPON_POWER_UP, "WeaponPowerUp"); |
---|
48 | this->loadPickupSound("sound/powerups/whats this2.wav"); |
---|
49 | |
---|
50 | this->weaponXML = NULL; |
---|
51 | this->weapon = NULL; |
---|
52 | } |
---|
53 | |
---|
54 | |
---|
55 | void WeaponPowerUp::loadParams(const TiXmlElement* root) |
---|
56 | { |
---|
57 | PowerUp::loadParams(root); |
---|
58 | const TiXmlElement* elem = root->FirstChildElement("weapon"); |
---|
59 | if(elem != NULL && (elem = elem->FirstChildElement()) != NULL) |
---|
60 | { |
---|
61 | this->weaponXML = elem; |
---|
62 | newWeapon(); |
---|
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 | |
---|
75 | bool WeaponPowerUp::process(WeaponManager* manager) |
---|
76 | { |
---|
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 | { |
---|
88 | this->weapon = dynamic_cast<Weapon*>((weaponXML == NULL) |
---|
89 | ? Factory::fabricate(static_cast<ClassID>(this->weapon->getLeafClassID())) |
---|
90 | : Factory::fabricate((const TiXmlElement*)this->getXmlElem()->FirstChildElement("weapon"))); |
---|
91 | this->model = this->weapon->getModel(0); |
---|
92 | } |
---|
93 | |
---|
94 | void WeaponPowerUp::setWeaponClass(const std::string& name) |
---|
95 | { |
---|
96 | this->weapon = dynamic_cast<Weapon*>(Factory::fabricate(name)); |
---|
97 | if (this->weapon == NULL) |
---|
98 | { |
---|
99 | PRINTF(1)("Unable to load Weapon. %s\n", name.c_str()); |
---|
100 | this->weapon = dynamic_cast<Weapon*>(Factory::fabricate("Turret")); |
---|
101 | } |
---|
102 | this->model = this->weapon->getModel(0); |
---|
103 | } |
---|
104 | |
---|