Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/world_entities/power_ups/weapon_power_up.cc @ 9869

Last change on this file since 9869 was 9869, checked in by bensch, 18 years ago

orxonox/trunk: merged the new_class_id branche back to the trunk.
merged with command:
svn merge https://svn.orxonox.net/orxonox/branches/new_class_id trunk -r9683:HEAD
no conflicts… puh..

File size: 2.5 KB
Line 
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#include "debug.h"
28
29#include "class_id_DEPRECATED.h"
30ObjectListDefinitionID(WeaponPowerUp, CL_WEAPON_POWER_UP);
31CREATE_FACTORY(WeaponPowerUp);
32
33WeaponPowerUp::WeaponPowerUp(const TiXmlElement* root) : PowerUp(1.0, 1.0, 0.0)
34{
35  this->init();
36  if( root != NULL)
37    this->loadParams(root);
38}
39
40
41WeaponPowerUp::~WeaponPowerUp ()
42{
43}
44
45
46void WeaponPowerUp::init()
47{
48  this->registerObject(this, WeaponPowerUp::_objectList);
49  this->loadPickupSound("sound/powerups/whats this2.wav");
50
51  this->weaponXML = NULL;
52  this->weapon = NULL;
53}
54
55
56void WeaponPowerUp::loadParams(const TiXmlElement* root)
57{
58  PowerUp::loadParams(root);
59  const TiXmlElement* elem = root->FirstChildElement("weapon");
60  if(elem != NULL && (elem = elem->FirstChildElement()) != NULL)
61  {
62    this->weaponXML = elem;
63    newWeapon();
64  }
65  else
66  {
67    LoadParam(root, "weaponID", this, WeaponPowerUp, setWeaponClass);
68  }
69}
70
71Weapon* WeaponPowerUp::getWeapon()
72{
73  return this->weapon;
74}
75
76bool WeaponPowerUp::process(WeaponManager* manager)
77{
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
87void WeaponPowerUp::newWeapon()
88{
89  this->weapon = dynamic_cast<Weapon*>((weaponXML == NULL)
90      ? Factory::fabricate((this->weapon->getClassID()))
91      : Factory::fabricate((const TiXmlElement*)this->getXmlElem()->FirstChildElement("weapon")));
92  this->model = this->weapon->getModel(0);
93}
94
95void WeaponPowerUp::setWeaponClass(const std::string& name)
96{
97  this->weapon = dynamic_cast<Weapon*>(Factory::fabricate(name));
98  if (this->weapon == NULL)
99  {
100    PRINTF(1)("Unable to load Weapon. %s\n", name.c_str());
101    this->weapon = dynamic_cast<Weapon*>(Factory::fabricate("Turret"));
102  }
103  this->model = this->weapon->getModel(0);
104}
105
Note: See TracBrowser for help on using the repository browser.