[Orxonox-commit 79] r2778 - branches/weaponsystem/src/orxonox/objects/weaponSystem
polakma at orxonox.net
polakma at orxonox.net
Thu Mar 12 17:05:18 CET 2009
Author: polakma
Date: 2009-03-12 16:05:18 +0000 (Thu, 12 Mar 2009)
New Revision: 2778
Modified:
branches/weaponsystem/src/orxonox/objects/weaponSystem/Weapon.cc
branches/weaponsystem/src/orxonox/objects/weaponSystem/Weapon.h
branches/weaponsystem/src/orxonox/objects/weaponSystem/WeaponSet.cc
branches/weaponsystem/src/orxonox/objects/weaponSystem/WeaponSystem.cc
branches/weaponsystem/src/orxonox/objects/weaponSystem/WeaponSystem.h
Log:
now you can choose between shared munition and normal munition
Modified: branches/weaponsystem/src/orxonox/objects/weaponSystem/Weapon.cc
===================================================================
--- branches/weaponsystem/src/orxonox/objects/weaponSystem/Weapon.cc 2009-03-12 15:19:43 UTC (rev 2777)
+++ branches/weaponsystem/src/orxonox/objects/weaponSystem/Weapon.cc 2009-03-12 16:05:18 UTC (rev 2778)
@@ -64,6 +64,7 @@
XMLPortParam(Weapon, "munitionType", setMunitionType, getMunitionType, xmlelement, mode);
XMLPortParam(Weapon, "bulletLoadingTime", setBulletLoadingTime, getBulletLoadingTime, xmlelement, mode);
XMLPortParam(Weapon, "magazineLoadingTime", setMagazineLoadingTime, getMagazineLoadingTime, xmlelement, mode);
+ XMLPortParam(Weapon, "bSharedMunition", setSharedMunition, getSharedMunition, xmlelement, mode);
}
void Weapon::setWeapon()
@@ -96,13 +97,13 @@
else
{
//COUT(0) << "LaserGun::fire - no magazines" << std::endl;
- //actions
+ //no magazines
}
}
else
{
//COUT(0) << "LaserGun::fire - weapon not reloaded - bullets remaining:" << this->munition_->bullets() << std::endl;
- //actions
+ //weapon not reloaded
}
}
@@ -140,20 +141,32 @@
{
//COUT(0) << "Weapon::attachNeededMunition, parentWeaponSystem=" << this->parentWeaponSystem_ << std::endl;
//if munition type already exists attach it, else create a new one of this type and attach it to the weapon and to the WeaponSystem
+ //if the weapon shares one munitionType put it into sharedMunitionSet
+ //else to munitionSet
if (this->parentWeaponSystem_)
{
-//COUT(0) << "Weapon::attachNeededMunition " << munitionName << std::endl;
- Munition* munition = this->parentWeaponSystem_->getMunitionType(munitionName);
- if ( munition )
- this->munition_ = munition;
- else
+ if (this->bSharedMunition_ == false)
{
- //create new munition with identifier
-//COUT(0) << "Weapon::attachNeededMunition, create new Munition of Type " << munitionName << std::endl;
this->munitionIdentifier_ = ClassByString(munitionName);
this->munition_ = this->munitionIdentifier_.fabricate(this);
this->parentWeaponSystem_->setNewMunition(munitionName, this->munition_);
}
+ else
+ {
+//COUT(0) << "Weapon::attachNeededMunition " << munitionName << std::endl;
+ //getMunitionType returns 0 if there is no such munitionType
+ Munition* munition = this->parentWeaponSystem_->getMunitionType(munitionName);
+ if ( munition )
+ this->munition_ = munition;
+ else
+ {
+ //create new munition with identifier because there is no such munitionType
+//COUT(0) << "Weapon::attachNeededMunition, create new Munition of Type " << munitionName << std::endl;
+ this->munitionIdentifier_ = ClassByString(munitionName);
+ this->munition_ = this->munitionIdentifier_.fabricate(this);
+ this->parentWeaponSystem_->setNewSharedMunition(munitionName, this->munition_);
+ }
+ }
}
}
@@ -180,7 +193,13 @@
const float Weapon::getMagazineLoadingTime()
{ return this->magazineLoadingTime_; }
+ void Weapon::setSharedMunition(bool bSharedMunition)
+ { this->bSharedMunition_ = bSharedMunition; }
+ const bool Weapon::getSharedMunition()
+ { return this->bSharedMunition_; }
+
+
Munition * Weapon::getAttachedMunition(std::string munitionType)
{
//COUT(0) << "Weapon::getAttachedMunition, parentWeaponSystem_="<< this->parentWeaponSystem_ << std::endl;
Modified: branches/weaponsystem/src/orxonox/objects/weaponSystem/Weapon.h
===================================================================
--- branches/weaponsystem/src/orxonox/objects/weaponSystem/Weapon.h 2009-03-12 15:19:43 UTC (rev 2777)
+++ branches/weaponsystem/src/orxonox/objects/weaponSystem/Weapon.h 2009-03-12 16:05:18 UTC (rev 2778)
@@ -67,6 +67,8 @@
virtual const float getBulletLoadingTime();
virtual void setMagazineLoadingTime(float loadingTime);
virtual const float getMagazineLoadingTime();
+ virtual void setSharedMunition(bool bSharedMunition);
+ virtual const bool getSharedMunition();
virtual void takeBullets();
virtual void takeMagazines();
@@ -90,6 +92,7 @@
bool bReloading_;
bool bulletReadyToShoot_;
bool magazineReadyToShoot_;
+ bool bSharedMunition_;
float bulletLoadingTime_;
float magazineLoadingTime_;
std::string munitionType_;
Modified: branches/weaponsystem/src/orxonox/objects/weaponSystem/WeaponSet.cc
===================================================================
--- branches/weaponsystem/src/orxonox/objects/weaponSystem/WeaponSet.cc 2009-03-12 15:19:43 UTC (rev 2777)
+++ branches/weaponsystem/src/orxonox/objects/weaponSystem/WeaponSet.cc 2009-03-12 16:05:18 UTC (rev 2778)
@@ -55,22 +55,19 @@
void WeaponSet::attachWeaponPack(WeaponPack *wPack)
{
-//COUT(0) << "WeaponSet::attachWeaponPack" << std::endl;
-//COUT(0) << "........ parentWeaponSystem_=" << this->parentWeaponSystem_ << std::endl;
-//COUT(0) << "........ this->parentWeaponSystem_->getWeaponSlotSize()" << this->parentWeaponSystem_->getWeaponSlotSize() << std::endl;
-//COUT(0) << "........ wPack->getSize()" << wPack->getSize() << std::endl;
if ( this->parentWeaponSystem_->getWeaponSlotSize()>0 && wPack->getSize()>0 && ( wPack->getSize() <= this->parentWeaponSystem_->getWeaponSlotSize() ) )
{
-//COUT(0) << "WeaponSet::attachWeaponPack after if" << std::endl;
this->attachedWeaponPack_ = wPack;
int wPackWeapon = 0; //WeaponCounter for Attaching
//should be possible to choose which slot to use
+
+ //attach every weapon of the weaponPack to a weaponSlot
for ( int i=0; i < wPack->getSize() ; i++ )
{
//at the moment this function only works for one weaponPack in the entire WeaponSystem...
+ //it also takes the first free weaponSlot...
if ( this->parentWeaponSystem_->getWeaponSlotPointer(i)->getAttachedWeapon() == 0 && this->parentWeaponSystem_->getWeaponSlotPointer(i) != 0) //if slot not full
{
-//COUT(0) << "WeaponSet::attachWeaponPack attaching Weapon" << std::endl;
this->setWeaponSlots_.push_back( this->parentWeaponSystem_->getWeaponSlotPointer(i) );
this->parentWeaponSystem_->getWeaponSlotPointer(i)->attachWeapon( wPack->getWeaponPointer(wPackWeapon) );
this->parentWeaponSystem_->getParentPawn()->attach( wPack->getWeaponPointer(wPackWeapon) );
Modified: branches/weaponsystem/src/orxonox/objects/weaponSystem/WeaponSystem.cc
===================================================================
--- branches/weaponsystem/src/orxonox/objects/weaponSystem/WeaponSystem.cc 2009-03-12 15:19:43 UTC (rev 2777)
+++ branches/weaponsystem/src/orxonox/objects/weaponSystem/WeaponSystem.cc 2009-03-12 16:05:18 UTC (rev 2778)
@@ -37,10 +37,9 @@
#include "WeaponSystem.h"
-/* WEAPONSYSTEM
- * creates the WeaponSystem and the ability to use weapons and munition
- * loads the weapon the whole weaponSystem setting from an xml file
+/* WeaponSystem
*
+ * www.orxonox.net/wiki/WeaponSystem
*/
namespace orxonox
@@ -83,32 +82,28 @@
this->munitionSet_[munitionType] = munitionToAdd;
}
- //returns the Pointer to the munitionType
+ void WeaponSystem::setNewSharedMunition(std::string munitionType, Munition * munitionToAdd)
+ {
+ this->munitionSharedSet_[munitionType] = munitionToAdd;
+ }
+
+ //returns the Pointer to the munitionType, if this munitionType doesn't exist returns 0, see Weapon::attachNeededMunition
Munition * WeaponSystem::getMunitionType(std::string munitionType)
{
//COUT(0) << "WeaponSystem::getMunitionType " << munitionType << std::endl;
- std::map<std::string, Munition *>::const_iterator it = this->munitionSet_.find(munitionType);
- if (it != this->munitionSet_.end())
+ std::map<std::string, Munition *>::const_iterator it = this->munitionSharedSet_.find(munitionType);
+ if (it != this->munitionSharedSet_.end())
return it->second;
else
return 0;
}
-/*
- //the first weaponSet is at n=0
- void WeaponSystem::setActiveWeaponSet(unsigned int n)
- {
- if (n < this->weaponSets_.size())
- this->activeWeaponSet_ = this->weaponSets_[n];
- else
- this->activeWeaponSet_ = this->weaponSets_[0];
- }
-*/
+
//n is the n'th weaponSet, starting with zero
- //SpaceShip.cc only needs to have the keybinding to a specific Set-number n
+ //SpaceShip.cc only needs to have the keybinding to a specific Set-number n (=firemode)
void WeaponSystem::fire(WeaponMode::Enum n)
{
int set = 0;
Modified: branches/weaponsystem/src/orxonox/objects/weaponSystem/WeaponSystem.h
===================================================================
--- branches/weaponsystem/src/orxonox/objects/weaponSystem/WeaponSystem.h 2009-03-12 15:19:43 UTC (rev 2777)
+++ branches/weaponsystem/src/orxonox/objects/weaponSystem/WeaponSystem.h 2009-03-12 16:05:18 UTC (rev 2778)
@@ -52,12 +52,12 @@
void attachWeaponSet(WeaponSet *wSet);
//void fire();
void fire(WeaponMode::Enum fireMode);
- //void setActiveWeaponSet(unsigned int n);
void attachWeaponPack(WeaponPack * wPack, unsigned int firemode);
WeaponSet * getWeaponSetPointer(unsigned int n);
WeaponSlot * getWeaponSlotPointer(unsigned int n);
WeaponPack * getWeaponPackPointer(unsigned int n);
void setNewMunition(std::string munitionType, Munition * munitionToAdd);
+ void setNewSharedMunition(std::string munitionType, Munition * munitionToAdd);
Munition * getMunitionType(std::string munitionType);
inline void setParentPawn(Pawn *parentPawn)
@@ -72,6 +72,7 @@
std::vector<WeaponSet *> weaponSets_;
std::vector<WeaponSlot *> weaponSlots_;
std::vector<WeaponPack *> weaponPacks_;
+ std::map<std::string, Munition *> munitionSharedSet_;
std::map<std::string, Munition *> munitionSet_;
WeaponSet *activeWeaponSet_;
Pawn *parentPawn_;
More information about the Orxonox-commit
mailing list