[Orxonox-commit 263] r2915 - in branches/weapons/src/orxonox: . objects/weaponSystem
landauf at orxonox.net
landauf at orxonox.net
Sun Apr 12 00:34:55 CEST 2009
Author: landauf
Date: 2009-04-12 00:34:55 +0200 (Sun, 12 Apr 2009)
New Revision: 2915
Added:
branches/weapons/src/orxonox/objects/weaponSystem/DefaultWeaponmodeLink.cc
branches/weapons/src/orxonox/objects/weaponSystem/DefaultWeaponmodeLink.h
Modified:
branches/weapons/src/orxonox/OrxonoxPrereqs.h
branches/weapons/src/orxonox/objects/weaponSystem/CMakeLists.txt
branches/weapons/src/orxonox/objects/weaponSystem/Weapon.cc
branches/weapons/src/orxonox/objects/weaponSystem/WeaponPack.cc
branches/weapons/src/orxonox/objects/weaponSystem/WeaponPack.h
branches/weapons/src/orxonox/objects/weaponSystem/WeaponSet.cc
branches/weapons/src/orxonox/objects/weaponSystem/WeaponSystem.cc
branches/weapons/src/orxonox/objects/weaponSystem/WeaponSystem.h
Log:
- switched back to std::vector for the WeaponSlots to keep them in the same order as in the XML file
- added DefaultWeaponmodeLink, a class which links weaponmodes (a property of a Weapon or a WeaponPack) with firemodes (one firemode corresponds to one WeaponSet). This can be changed later (for example in a nice GUI), but DefaultWeaponmodeLink defines the default value.
Modified: branches/weapons/src/orxonox/OrxonoxPrereqs.h
===================================================================
--- branches/weapons/src/orxonox/OrxonoxPrereqs.h 2009-04-09 22:05:01 UTC (rev 2914)
+++ branches/weapons/src/orxonox/OrxonoxPrereqs.h 2009-04-11 22:34:55 UTC (rev 2915)
@@ -156,6 +156,7 @@
class WeaponSlot;
class WeaponPack;
class Weapon;
+ class DefaultWeaponmodeLink;
class Munition;
class LaserGun;
class LaserGunMunition;
Modified: branches/weapons/src/orxonox/objects/weaponSystem/CMakeLists.txt
===================================================================
--- branches/weapons/src/orxonox/objects/weaponSystem/CMakeLists.txt 2009-04-09 22:05:01 UTC (rev 2914)
+++ branches/weapons/src/orxonox/objects/weaponSystem/CMakeLists.txt 2009-04-11 22:34:55 UTC (rev 2915)
@@ -5,6 +5,7 @@
WeaponSet.cc
WeaponSlot.cc
WeaponSystem.cc
+ DefaultWeaponmodeLink.cc
)
ADD_SUBDIRECTORY(munitions)
Added: branches/weapons/src/orxonox/objects/weaponSystem/DefaultWeaponmodeLink.cc
===================================================================
--- branches/weapons/src/orxonox/objects/weaponSystem/DefaultWeaponmodeLink.cc (rev 0)
+++ branches/weapons/src/orxonox/objects/weaponSystem/DefaultWeaponmodeLink.cc 2009-04-11 22:34:55 UTC (rev 2915)
@@ -0,0 +1,63 @@
+/*
+ * ORXONOX - the hottest 3D action shooter ever to exist
+ * > www.orxonox.net <
+ *
+ *
+ * License notice:
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Author:
+ * Fabian 'x3n' Landau
+ * Co-authors:
+ * ...
+ *
+ */
+
+#include "OrxonoxStableHeaders.h"
+#include "DefaultWeaponmodeLink.h"
+
+#include "core/CoreIncludes.h"
+#include "core/XMLPort.h"
+
+#include "WeaponSystem.h"
+
+namespace orxonox
+{
+ CreateFactory(DefaultWeaponmodeLink);
+
+ DefaultWeaponmodeLink::DefaultWeaponmodeLink(BaseObject* creator) : BaseObject(creator)
+ {
+ RegisterObject(DefaultWeaponmodeLink);
+
+ this->firemode_ = WeaponSystem::FIRE_MODE_UNASSIGNED;
+ this->weaponmode_ = WeaponSystem::WEAPON_MODE_UNASSIGNED;
+
+COUT(0) << "+DefaultWeaponmodeLink" << std::endl;
+ }
+
+ DefaultWeaponmodeLink::~DefaultWeaponmodeLink()
+ {
+COUT(0) << "~DefaultWeaponmodeLink" << std::endl;
+ }
+
+ void DefaultWeaponmodeLink::XMLPort(Element& xmlelement, XMLPort::Mode mode)
+ {
+ SUPER(DefaultWeaponmodeLink, XMLPort, xmlelement, mode);
+
+ XMLPortParam(DefaultWeaponmodeLink, "firemode", setFiremode, getFiremode, xmlelement, mode);
+ XMLPortParam(DefaultWeaponmodeLink, "weaponmode", setWeaponmode, getWeaponmode, xmlelement, mode);
+ }
+}
Property changes on: branches/weapons/src/orxonox/objects/weaponSystem/DefaultWeaponmodeLink.cc
___________________________________________________________________
Added: svn:eol-style
+ native
Added: branches/weapons/src/orxonox/objects/weaponSystem/DefaultWeaponmodeLink.h
===================================================================
--- branches/weapons/src/orxonox/objects/weaponSystem/DefaultWeaponmodeLink.h (rev 0)
+++ branches/weapons/src/orxonox/objects/weaponSystem/DefaultWeaponmodeLink.h 2009-04-11 22:34:55 UTC (rev 2915)
@@ -0,0 +1,62 @@
+/*
+ * ORXONOX - the hottest 3D action shooter ever to exist
+ * > www.orxonox.net <
+ *
+ *
+ * License notice:
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Author:
+ * Fabian 'x3n' Landau
+ * Co-authors:
+ * ...
+ *
+ */
+
+
+#ifndef _DefaultWeaponmodeLink_H__
+#define _DefaultWeaponmodeLink_H__
+
+#include "OrxonoxPrereqs.h"
+#include "core/BaseObject.h"
+
+namespace orxonox
+{
+ class _OrxonoxExport DefaultWeaponmodeLink : public BaseObject
+ {
+ public:
+ DefaultWeaponmodeLink(BaseObject* creator);
+ virtual ~DefaultWeaponmodeLink();
+
+ virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
+
+ inline void setFiremode(const unsigned int firemode)
+ { this->firemode_ = firemode; }
+ inline unsigned int getFiremode() const
+ { return this->firemode_; }
+
+ inline void setWeaponmode(const unsigned int weaponmode)
+ { this->weaponmode_ = weaponmode; }
+ inline unsigned int getWeaponmode() const
+ { return this->weaponmode_; }
+
+ private:
+ unsigned int firemode_;
+ unsigned int weaponmode_;
+ };
+}
+
+#endif /* _DefaultWeaponmodeLink_H__ */
Property changes on: branches/weapons/src/orxonox/objects/weaponSystem/DefaultWeaponmodeLink.h
___________________________________________________________________
Added: svn:eol-style
+ native
Modified: branches/weapons/src/orxonox/objects/weaponSystem/Weapon.cc
===================================================================
--- branches/weapons/src/orxonox/objects/weaponSystem/Weapon.cc 2009-04-09 22:05:01 UTC (rev 2914)
+++ branches/weapons/src/orxonox/objects/weaponSystem/Weapon.cc 2009-04-11 22:34:55 UTC (rev 2915)
@@ -33,6 +33,7 @@
#include "core/XMLPort.h"
#include "Munition.h"
+#include "WeaponPack.h"
#include "WeaponSystem.h"
namespace orxonox
@@ -63,11 +64,14 @@
Weapon::~Weapon()
{
COUT(0) << "~Weapon" << std::endl;
+ if (this->isInitialized() && this->weaponPack_)
+ this->weaponPack_->removeWeapon(this);
}
void Weapon::XMLPort(Element& xmlelement, XMLPort::Mode mode)
{
SUPER(Weapon, XMLPort, xmlelement, mode);
+
XMLPortParam(Weapon, "munitionType", setMunitionType, getMunitionType, xmlelement, mode);
XMLPortParam(Weapon, "bulletLoadingTime", setBulletLoadingTime, getBulletLoadingTime, xmlelement, mode);
XMLPortParam(Weapon, "magazineLoadingTime", setMagazineLoadingTime, getMagazineLoadingTime, xmlelement, mode);
Modified: branches/weapons/src/orxonox/objects/weaponSystem/WeaponPack.cc
===================================================================
--- branches/weapons/src/orxonox/objects/weaponSystem/WeaponPack.cc 2009-04-09 22:05:01 UTC (rev 2914)
+++ branches/weapons/src/orxonox/objects/weaponSystem/WeaponPack.cc 2009-04-11 22:34:55 UTC (rev 2915)
@@ -22,7 +22,8 @@
* Author:
* Martin Polak
* Co-authors:
- * ... *
+ * ...
+ *
*/
#include "OrxonoxStableHeaders.h"
@@ -35,6 +36,7 @@
#include "Weapon.h"
#include "WeaponSlot.h"
#include "WeaponSystem.h"
+#include "DefaultWeaponmodeLink.h"
namespace orxonox
{
@@ -54,7 +56,15 @@
COUT(0) << "~WeaponPack" << std::endl;
if (this->isInitialized() && this->weaponSystem_)
+ {
this->weaponSystem_->removeWeaponPack(this);
+
+ while (!this->weapons_.empty())
+ delete (*this->weapons_.begin());
+
+ for (std::set<DefaultWeaponmodeLink*>::iterator it = this->links_.begin(); it != this->links_.end(); )
+ delete (*(it++));
+ }
}
void WeaponPack::XMLPort(Element& xmlelement, XMLPort::Mode mode)
@@ -62,6 +72,7 @@
SUPER(WeaponPack, XMLPort, xmlelement, mode);
XMLPortObject(WeaponPack, Weapon, "", addWeapon, getWeapon, xmlelement, mode);
+ XMLPortObject(WeaponPack, DefaultWeaponmodeLink, "links", addDefaultWeaponmodeLink, getDefaultWeaponmodeLink, xmlelement, mode);
}
void WeaponPack::fire(unsigned int weaponmode)
@@ -79,6 +90,15 @@
weapon->setWeaponPack(this);
}
+ void WeaponPack::removeWeapon(Weapon * weapon)
+ {
+ if (!weapon)
+ return;
+
+ this->weapons_.erase(weapon);
+ weapon->setWeaponPack(0);
+ }
+
Weapon * WeaponPack::getWeapon(unsigned int index) const
{
unsigned int i = 0;
@@ -93,10 +113,10 @@
return 0;
}
- void WeaponPack::setWeaponSystemToAllWeapons(WeaponSystem * weaponSystem)
+ void WeaponPack::setWeaponSystemToAllWeapons()
{
for (std::set<Weapon *>::const_iterator it = this->weapons_.begin(); it != this->weapons_.end(); ++it)
- (*it)->setWeaponSystem(weaponSystem);
+ (*it)->setWeaponSystem(this->weaponSystem_);
}
void WeaponPack::attachNeededMunitionToAllWeapons()
@@ -107,4 +127,31 @@
(*it)->setWeapon();
}
}
+
+ void WeaponPack::addDefaultWeaponmodeLink(DefaultWeaponmodeLink* link)
+ {
+ this->links_.insert(link);
+ }
+
+ DefaultWeaponmodeLink* WeaponPack::getDefaultWeaponmodeLink(unsigned int index) const
+ {
+ unsigned int i = 0;
+ for (std::set<DefaultWeaponmodeLink*>::const_iterator it = this->links_.begin(); it != this->links_.end(); ++it)
+ {
+ if (i == index)
+ return (*it);
+
+ ++i;
+ }
+ return 0;
+ }
+
+ unsigned int WeaponPack::getDesiredWeaponmode(unsigned int firemode) const
+ {
+ for (std::set<DefaultWeaponmodeLink*>::const_iterator it = this->links_.begin(); it != this->links_.end(); ++it)
+ if ((*it)->getFiremode() == firemode)
+ return (*it)->getWeaponmode();
+
+ return WeaponSystem::WEAPON_MODE_UNASSIGNED;
+ }
}
Modified: branches/weapons/src/orxonox/objects/weaponSystem/WeaponPack.h
===================================================================
--- branches/weapons/src/orxonox/objects/weaponSystem/WeaponPack.h 2009-04-09 22:05:01 UTC (rev 2914)
+++ branches/weapons/src/orxonox/objects/weaponSystem/WeaponPack.h 2009-04-11 22:34:55 UTC (rev 2915)
@@ -49,24 +49,32 @@
void fire(unsigned int weaponmode);
void addWeapon(Weapon * weapon);
+ void removeWeapon(Weapon * weapon);
Weapon * getWeapon(unsigned int index) const;
inline size_t getNumWeapons() const
{ return this->weapons_.size(); }
- unsigned int getDesiredWeaponmode(unsigned int firemode) { return 0; } // TODO
+ void addDefaultWeaponmodeLink(DefaultWeaponmodeLink* link);
+ DefaultWeaponmodeLink* getDefaultWeaponmodeLink(unsigned int index) const;
- void attachNeededMunitionToAllWeapons();
+ unsigned int getDesiredWeaponmode(unsigned int firemode) const;
inline void setWeaponSystem(WeaponSystem *weaponSystem)
- { this->weaponSystem_ = weaponSystem; this->setWeaponSystemToAllWeapons(weaponSystem); }
+ {
+ this->weaponSystem_ = weaponSystem;
+ this->setWeaponSystemToAllWeapons();
+ this->attachNeededMunitionToAllWeapons();
+ }
inline WeaponSystem * getWeaponSystem() const
{ return this->weaponSystem_; }
private:
- void setWeaponSystemToAllWeapons(WeaponSystem * weaponSystem);
+ void setWeaponSystemToAllWeapons();
+ void attachNeededMunitionToAllWeapons();
std::set<Weapon *> weapons_;
+ std::set<DefaultWeaponmodeLink *> links_;
WeaponSystem * weaponSystem_;
};
}
Modified: branches/weapons/src/orxonox/objects/weaponSystem/WeaponSet.cc
===================================================================
--- branches/weapons/src/orxonox/objects/weaponSystem/WeaponSet.cc 2009-04-09 22:05:01 UTC (rev 2914)
+++ branches/weapons/src/orxonox/objects/weaponSystem/WeaponSet.cc 2009-04-11 22:34:55 UTC (rev 2915)
@@ -22,7 +22,8 @@
* Author:
* Martin Polak
* Co-authors:
- * ... *
+ * ...
+ *
*/
#include "OrxonoxStableHeaders.h"
Modified: branches/weapons/src/orxonox/objects/weaponSystem/WeaponSystem.cc
===================================================================
--- branches/weapons/src/orxonox/objects/weaponSystem/WeaponSystem.cc 2009-04-09 22:05:01 UTC (rev 2914)
+++ branches/weapons/src/orxonox/objects/weaponSystem/WeaponSystem.cc 2009-04-11 22:34:55 UTC (rev 2915)
@@ -62,14 +62,20 @@
if (this->pawn_)
this->pawn_->setWeaponSystem(0);
- for (std::map<unsigned int, WeaponSet*>::iterator it = this->weaponSets_.begin(); it != this->weaponSets_.end(); )
- delete (it++)->second;
+// for (std::map<unsigned int, WeaponSet*>::iterator it = this->weaponSets_.begin(); it != this->weaponSets_.end(); )
+// delete (it++)->second;
+ while (!this->weaponSets_.empty())
+ delete (this->weaponSets_.begin()->second);
- for (std::set<WeaponPack*>::iterator it = this->weaponPacks_.begin(); it != this->weaponPacks_.end(); )
- delete (*(it++));
+// for (std::set<WeaponPack*>::iterator it = this->weaponPacks_.begin(); it != this->weaponPacks_.end(); )
+// delete (*(it++));
+ while (!this->weaponPacks_.empty())
+ delete (*this->weaponPacks_.begin());
- for (std::set<WeaponSlot*>::iterator it = this->weaponSlots_.begin(); it != this->weaponSlots_.end(); )
- delete (*(it++));
+// for (std::vector<WeaponSlot*>::iterator it = this->weaponSlots_.begin(); it != this->weaponSlots_.end(); )
+// delete (*(it++));
+ while (!this->weaponSlots_.empty())
+ delete (*this->weaponSlots_.begin());
}
}
@@ -78,7 +84,7 @@
if (!wSlot)
return;
- this->weaponSlots_.insert(wSlot);
+ this->weaponSlots_.push_back(wSlot);
wSlot->setWeaponSystem(this);
}
@@ -90,13 +96,20 @@
if (wSlot->getWeapon())
this->removeWeaponPack(wSlot->getWeapon()->getWeaponPack());
- this->weaponSlots_.erase(wSlot);
+ for (std::vector<WeaponSlot*>::iterator it = this->weaponSlots_.begin(); it != this->weaponSlots_.end(); ++it)
+ {
+ if ((*it) == wSlot)
+ {
+ this->weaponSlots_.erase(it);
+ break;
+ }
+ }
}
WeaponSlot * WeaponSystem::getWeaponSlot(unsigned int index) const
{
unsigned int i = 0;
- for (std::set<WeaponSlot*>::iterator it = this->weaponSlots_.begin(); it != this->weaponSlots_.end(); ++it)
+ for (std::vector<WeaponSlot*>::const_iterator it = this->weaponSlots_.begin(); it != this->weaponSlots_.end(); ++it)
{
++i;
if (i > index)
@@ -158,7 +171,7 @@
return false;
unsigned int freeSlots = 0;
- for (std::set<WeaponSlot*>::iterator it = this->weaponSlots_.begin(); it != this->weaponSlots_.end(); ++it)
+ for (std::vector<WeaponSlot*>::iterator it = this->weaponSlots_.begin(); it != this->weaponSlots_.end(); ++it)
{
if (!(*it)->isOccupied())
++freeSlots;
@@ -174,7 +187,7 @@
// Attach all weapons to the first free slots (and to the Pawn)
unsigned int i = 0;
- for (std::set<WeaponSlot*>::iterator it = this->weaponSlots_.begin(); it != this->weaponSlots_.end(); ++it)
+ for (std::vector<WeaponSlot*>::iterator it = this->weaponSlots_.begin(); it != this->weaponSlots_.end(); ++it)
{
if (!(*it)->isOccupied() && i < wPack->getNumWeapons())
{
@@ -195,7 +208,6 @@
this->weaponPacks_.insert(wPack);
wPack->setWeaponSystem(this);
- wPack->attachNeededMunitionToAllWeapons(); // TODO - what is this?
return true;
}
@@ -230,7 +242,18 @@
bool WeaponSystem::swapWeaponSlots(WeaponSlot * wSlot1, WeaponSlot * wSlot2)
{
- // TODO
+ if (!wSlot1 || !wSlot2)
+ return false;
+
+ Weapon* weapon1 = wSlot1->getWeapon();
+ Weapon* weapon2 = wSlot2->getWeapon();
+
+ wSlot1->attachWeapon(weapon2);
+ wSlot2->attachWeapon(weapon1);
+
+ return true;
+ // In the future, certain weapons might not fit to some slots. Swapping would then be
+ // impossible and the returnvalue would be false.
}
void WeaponSystem::changeWeaponmode(WeaponPack * wPack, WeaponSet * wSet, unsigned int weaponmode)
Modified: branches/weapons/src/orxonox/objects/weaponSystem/WeaponSystem.h
===================================================================
--- branches/weapons/src/orxonox/objects/weaponSystem/WeaponSystem.h 2009-04-09 22:05:01 UTC (rev 2914)
+++ branches/weapons/src/orxonox/objects/weaponSystem/WeaponSystem.h 2009-04-11 22:34:55 UTC (rev 2915)
@@ -34,6 +34,7 @@
#include <set>
#include <map>
+#include <vector>
#include "core/BaseObject.h"
@@ -92,7 +93,7 @@
private:
std::map<unsigned int, WeaponSet *> weaponSets_;
- std::set<WeaponSlot *> weaponSlots_;
+ std::vector<WeaponSlot *> weaponSlots_;
std::set<WeaponPack *> weaponPacks_;
std::map<std::string, Munition *> munitionSet_;
Pawn * pawn_;
More information about the Orxonox-commit
mailing list