[Orxonox-commit 109] r2804 - in branches/weaponsystem/src/orxonox/objects: weaponSystem weaponSystem/weapons worldentities/pawns
polakma at orxonox.net
polakma at orxonox.net
Thu Mar 19 16:55:08 CET 2009
Author: polakma
Date: 2009-03-19 15:55:08 +0000 (Thu, 19 Mar 2009)
New Revision: 2804
Modified:
branches/weaponsystem/src/orxonox/objects/weaponSystem/Munition.cc
branches/weaponsystem/src/orxonox/objects/weaponSystem/Weapon.cc
branches/weaponsystem/src/orxonox/objects/weaponSystem/Weapon.h
branches/weaponsystem/src/orxonox/objects/weaponSystem/WeaponPack.cc
branches/weaponsystem/src/orxonox/objects/weaponSystem/WeaponPack.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
branches/weaponsystem/src/orxonox/objects/weaponSystem/weapons/LaserGun.cc
branches/weaponsystem/src/orxonox/objects/weaponSystem/weapons/LaserGun.h
branches/weaponsystem/src/orxonox/objects/worldentities/pawns/Pawn.cc
Log:
some enhancements, but not working...
Modified: branches/weaponsystem/src/orxonox/objects/weaponSystem/Munition.cc
===================================================================
--- branches/weaponsystem/src/orxonox/objects/weaponSystem/Munition.cc 2009-03-19 13:17:01 UTC (rev 2803)
+++ branches/weaponsystem/src/orxonox/objects/weaponSystem/Munition.cc 2009-03-19 15:55:08 UTC (rev 2804)
@@ -104,7 +104,6 @@
void Munition::fillBullets()
{
-//COUT(0) << "Munition::fillBullets maxBullets_=" << this->maxBullets_ << std::endl;
this->bullets_ = this->maxBullets_;
}
Modified: branches/weaponsystem/src/orxonox/objects/weaponSystem/Weapon.cc
===================================================================
--- branches/weaponsystem/src/orxonox/objects/weaponSystem/Weapon.cc 2009-03-19 13:17:01 UTC (rev 2803)
+++ branches/weaponsystem/src/orxonox/objects/weaponSystem/Weapon.cc 2009-03-19 15:55:08 UTC (rev 2804)
@@ -41,15 +41,18 @@
Weapon::Weapon(BaseObject* creator) : StaticEntity(creator)
{
RegisterObject(Weapon);
+
this->bulletReadyToShoot_ = true;
this->magazineReadyToShoot_ = true;
this->parentWeaponSystem_ = 0;
this->attachedToWeaponSlot_ = 0;
- this->munition_ = 0;
this->bulletLoadingTime_ = 0;
this->magazineLoadingTime_ = 0;
this->bReloading_ = false;
-
+ this->bulletAmount_= 0;
+ this->magazineAmount_ = 0;
+ this->munition_ = 0;
+ this->unlimitedMunition_ = false;
this->setObjectMode(0x0);
}
@@ -65,6 +68,9 @@
XMLPortParam(Weapon, "bulletLoadingTime", setBulletLoadingTime, getBulletLoadingTime, xmlelement, mode);
XMLPortParam(Weapon, "magazineLoadingTime", setMagazineLoadingTime, getMagazineLoadingTime, xmlelement, mode);
XMLPortParam(Weapon, "bSharedMunition", setSharedMunition, getSharedMunition, xmlelement, mode);
+ XMLPortParam(Weapon, "bullets", setBulletAmount, getBulletAmount, xmlelement, mode);
+ XMLPortParam(Weapon, "magazines", setMagazineAmount, getMagazineAmount, xmlelement, mode);
+ XMLPortParam(Weapon, "unlimitedMunition", setUnlimitedMunition, getUnlimitedMunition, xmlelement, mode);
}
void Weapon::setWeapon()
@@ -73,51 +79,68 @@
this->munition_->fillMagazines();
}
+ void Weapon::setMunition()
+ {
+ this->munition_->setMaxBullets(this->bulletAmount_);
+ this->munition_->setMaxMagazines(this->magazineAmount_);
+ }
void Weapon::fire()
{
-//COUT(0) << "LaserGun::fire, this=" << this << std::endl;
+COUT(0) << "Weapon::fire" << std::endl;
if ( this->bulletReadyToShoot_ && this->magazineReadyToShoot_ && !this->bReloading_)
{
-//COUT(0) << "LaserGun::fire - ready to shoot" << std::endl;
-//COUT(0) << "LaserGun::fire - bullets" << this->munition_->bullets() << std::endl;
+COUT(0) << "Weapon::fire 2" << std::endl;
this->bulletReadyToShoot_ = false;
- if ( this->munition_->bullets() > 0)
+ if ( this->unlimitedMunition_== true )
{
+COUT(0) << "Weapon::fire 3" << std::endl;
//shoot
- this->takeBullets();
+ this->reloadBullet();
this->createProjectile();
}
- //if there are no bullets, but magazines
- else if ( this->munition_->magazines() > 0 && this->munition_->bullets() == 0 )
- {
-//COUT(0) << "LaserGun::fire - no bullets" << std::endl;
- this->takeMagazines();
- }
else
{
-//COUT(0) << "LaserGun::fire - no magazines" << std::endl;
- //no magazines
+COUT(0) << "Weapon::fire 4" << std::endl;
+ if ( this->munition_->bullets() > 0)
+ {
+COUT(0) << "Weapon::fire 5" << std::endl;
+ //shoot
+ this->takeBullets();
+ this->reloadBullet();
+ this->createProjectile();
+ }
+ //if there are no bullets, but magazines
+ else if ( this->munition_->magazines() > 0 && this->munition_->bullets() == 0 )
+ {
+COUT(0) << "Weapon::fire 6" << std::endl;
+ this->takeMagazines();
+ this->reloadMagazine();
+ }
+ else
+ {
+ //no magazines
+ }
}
}
else
{
-//COUT(0) << "LaserGun::fire - weapon not reloaded - bullets remaining:" << this->munition_->bullets() << std::endl;
+COUT(0) << "Weapon::fire not reloaded" << std::endl;
//weapon not reloaded
}
}
-
+ /*
+ * weapon reloading
+ */
void Weapon::bulletTimer(float bulletLoadingTime)
{
-//COUT(0) << "Weapon::bulletTimer started" << std::endl;
this->bReloading_ = true;
this->bulletReloadTimer_.setTimer( bulletLoadingTime , false , this , createExecutor(createFunctor(&Weapon::bulletReloaded)));
}
void Weapon::magazineTimer(float magazineLoadingTime)
{
-//COUT(0) << "Weapon::magazineTimer started" << std::endl;
this->bReloading_ = true;
this->magazineReloadTimer_.setTimer( magazineLoadingTime , false , this , createExecutor(createFunctor(&Weapon::magazineReloaded)));
}
@@ -139,10 +162,9 @@
void Weapon::attachNeededMunition(std::string munitionName)
{
-//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 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_)
{
if (this->bSharedMunition_ == false)
@@ -153,7 +175,6 @@
}
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 )
@@ -161,20 +182,34 @@
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_);
}
}
+ this->setMunition();
}
}
+ Munition * Weapon::getAttachedMunition(std::string munitionType)
+ {
+ this->munition_ = this->parentWeaponSystem_->getMunitionType(munitionType);
+ return this->munition_;
+ }
+
+
+ //these function are defined in the weapon classes
+ void Weapon::takeBullets() { };
+ void Weapon::createProjectile() { };
+ void Weapon::takeMagazines() { };
+ void Weapon::reloadBullet() { };
+ void Weapon::reloadMagazine() { };
+
+
/*get and set functions
*
*/
-
void Weapon::setMunitionType(std::string munitionType)
{ this->munitionType_ = munitionType; }
@@ -199,17 +234,22 @@
const bool Weapon::getSharedMunition()
{ return this->bSharedMunition_; }
+ void Weapon::setBulletAmount(unsigned int amount)
+ { this->bulletAmount_ = amount; }
- Munition * Weapon::getAttachedMunition(std::string munitionType)
- {
-//COUT(0) << "Weapon::getAttachedMunition, parentWeaponSystem_="<< this->parentWeaponSystem_ << std::endl;
- this->munition_ = this->parentWeaponSystem_->getMunitionType(munitionType);
-//COUT(0) << "Weapon::getAttachedMunition, munition_="<< this->munition_ << std::endl;
- return this->munition_;
- }
+ const unsigned int Weapon::getBulletAmount()
+ { return this->bulletAmount_; }
- void Weapon::takeBullets() { };
- void Weapon::createProjectile() { };
- void Weapon::takeMagazines() { };
+ void Weapon::setMagazineAmount(unsigned int amount)
+ { this->magazineAmount_ = amount; }
+ const unsigned int Weapon::getMagazineAmount()
+ { return this->magazineAmount_; }
+
+ void Weapon::setUnlimitedMunition(bool unlimitedMunition)
+ { this->unlimitedMunition_ = unlimitedMunition; }
+
+ const bool Weapon::getUnlimitedMunition()
+ { return this->unlimitedMunition_; }
+
}
Modified: branches/weaponsystem/src/orxonox/objects/weaponSystem/Weapon.h
===================================================================
--- branches/weaponsystem/src/orxonox/objects/weaponSystem/Weapon.h 2009-03-19 13:17:01 UTC (rev 2803)
+++ branches/weaponsystem/src/orxonox/objects/weaponSystem/Weapon.h 2009-03-19 15:55:08 UTC (rev 2804)
@@ -61,6 +61,7 @@
void bulletReloaded();
void magazineReloaded();
+ //XMLPort functions
virtual void setMunitionType(std::string munitionType);
virtual const std::string getMunitionType();
virtual void setBulletLoadingTime(float loadingTime);
@@ -69,11 +70,24 @@
virtual const float getMagazineLoadingTime();
virtual void setSharedMunition(bool bSharedMunition);
virtual const bool getSharedMunition();
+ virtual void setBulletAmount(unsigned int amount);
+ virtual const unsigned int getBulletAmount();
+ virtual void setMagazineAmount(unsigned int amount);
+ virtual const unsigned int getMagazineAmount();
+ virtual void setUnlimitedMunition(bool unlimitedMunition);
+ virtual const bool getUnlimitedMunition();
+ //weapon actions
virtual void takeBullets();
virtual void takeMagazines();
virtual void createProjectile();
+ virtual void reloadBullet();
+ virtual void reloadMagazine();
+ //manually set or reset
+ virtual void setWeapon();
+ virtual void setMunition();
+
inline void setParentWeaponSystem(WeaponSystem *parentWeaponSystem)
{ this->parentWeaponSystem_=parentWeaponSystem; };
inline WeaponSystem * getParentWeaponSystem()
@@ -84,7 +98,6 @@
inline WeaponSlot * getAttachedToWeaponSlot()
{ return this->attachedToWeaponSlot_; }
- virtual void setWeapon();
private:
@@ -93,8 +106,11 @@
bool bulletReadyToShoot_;
bool magazineReadyToShoot_;
bool bSharedMunition_;
+ bool unlimitedMunition_;
float bulletLoadingTime_;
float magazineLoadingTime_;
+ unsigned int bulletAmount_;
+ unsigned int magazineAmount_;
std::string munitionType_;
WeaponSlot * attachedToWeaponSlot_;
Modified: branches/weaponsystem/src/orxonox/objects/weaponSystem/WeaponPack.cc
===================================================================
--- branches/weaponsystem/src/orxonox/objects/weaponSystem/WeaponPack.cc 2009-03-19 13:17:01 UTC (rev 2803)
+++ branches/weaponsystem/src/orxonox/objects/weaponSystem/WeaponPack.cc 2009-03-19 15:55:08 UTC (rev 2804)
@@ -62,7 +62,6 @@
{
for (int i=0; i < (int) this->weapons_.size(); i++)
{
-//COUT(0) << "WeaponPack::fire (attached from WeaponSet) from Weapon: "<< i << std::endl;
this->weapons_[i]->getAttachedToWeaponSlot()->fire();
}
}
@@ -82,7 +81,6 @@
void WeaponPack::setFireMode(unsigned int firemode)
{
-//COUT(0) << "WeaponPack::setFireMode " << std::endl;
this->firemode_ = firemode;
}
@@ -93,7 +91,6 @@
void WeaponPack::addWeapon(Weapon * weapon)
{
-//COUT(0) << "WeaponPack::addWeapon:" << weapon << " munition " << weapon->getMunitionType() << std::endl;
this->weapons_.push_back(weapon);
}
@@ -116,7 +113,6 @@
for (int i=0; i < (int) this->weapons_.size(); i++)
{
this->weapons_[i]->attachNeededMunition(weapons_[i]->getMunitionType());
- //hack!
this->weapons_[i]->setWeapon();
}
Modified: branches/weaponsystem/src/orxonox/objects/weaponSystem/WeaponPack.h
===================================================================
--- branches/weaponsystem/src/orxonox/objects/weaponSystem/WeaponPack.h 2009-03-19 13:17:01 UTC (rev 2803)
+++ branches/weaponsystem/src/orxonox/objects/weaponSystem/WeaponPack.h 2009-03-19 15:55:08 UTC (rev 2804)
@@ -58,6 +58,7 @@
void addWeapon(Weapon * weapon);
const Weapon * getWeapon(unsigned int index);
+ //functions with effect to all weapons of the weaponPack
//functions needed for creating Pointer to the right objects (-->Pawn.cc)
void setParentWeaponSystemToAllWeapons(WeaponSystem * weaponSystem);
void attachNeededMunitionToAllWeapons();
Modified: branches/weaponsystem/src/orxonox/objects/weaponSystem/WeaponSet.cc
===================================================================
--- branches/weaponsystem/src/orxonox/objects/weaponSystem/WeaponSet.cc 2009-03-19 13:17:01 UTC (rev 2803)
+++ branches/weaponsystem/src/orxonox/objects/weaponSystem/WeaponSet.cc 2009-03-19 15:55:08 UTC (rev 2804)
@@ -59,8 +59,8 @@
{
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++ )
{
@@ -79,7 +79,6 @@
{
if ( this->parentWeaponSystem_->getWeaponSlotPointer(k)->getAttachedWeapon() == 0 )
{
-//COUT(0) << "WeaponSet::attachWeaponPack mode 2 k="<< k << std::endl;
this->setWeaponSlots_.push_back( this->parentWeaponSystem_->getWeaponSlotPointer(k) );
this->parentWeaponSystem_->getWeaponSlotPointer(k)->attachWeapon( wPack->getWeaponPointer(wPackWeapon) );
this->parentWeaponSystem_->getParentPawn()->attach( wPack->getWeaponPointer(wPackWeapon) );
@@ -95,7 +94,6 @@
void WeaponSet::fire()
{
//fires all WeaponSlots available for this weaponSet attached from the WeaponPack
-//COUT(0) << "WeaponSet::fire from Pack: " << this->attachedWeaponPack_ << std::endl;
if (this->attachedWeaponPack_)
this->attachedWeaponPack_->fire();
}
Modified: branches/weaponsystem/src/orxonox/objects/weaponSystem/WeaponSystem.cc
===================================================================
--- branches/weaponsystem/src/orxonox/objects/weaponSystem/WeaponSystem.cc 2009-03-19 13:17:01 UTC (rev 2803)
+++ branches/weaponsystem/src/orxonox/objects/weaponSystem/WeaponSystem.cc 2009-03-19 15:55:08 UTC (rev 2804)
@@ -50,7 +50,6 @@
{
RegisterObject(WeaponSystem);
- this->activeWeaponSet_ = 0;
this->parentPawn_ = 0;
}
@@ -90,7 +89,6 @@
//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->munitionSharedSet_.find(munitionType);
if (it != this->munitionSharedSet_.end())
return it->second;
@@ -104,6 +102,7 @@
//n is the n'th weaponSet, starting with zero
//SpaceShip.cc only needs to have the keybinding to a specific Set-number n (=firemode)
+ //in future this could be well defined and not only for 3 different WeaponModes
void WeaponSystem::fire(WeaponMode::Enum n)
{
int set = 0;
@@ -119,9 +118,7 @@
set = 2;
break;
}
-//COUT(0) << "WeaponSystem::fire" << std::endl;
if (set < (int)this->weaponSets_.size())
-//COUT(0) << "WeaponSystem::fire - after if" << std::endl;
this->weaponSets_[set]->fire();
}
Modified: branches/weaponsystem/src/orxonox/objects/weaponSystem/WeaponSystem.h
===================================================================
--- branches/weaponsystem/src/orxonox/objects/weaponSystem/WeaponSystem.h 2009-03-19 13:17:01 UTC (rev 2803)
+++ branches/weaponsystem/src/orxonox/objects/weaponSystem/WeaponSystem.h 2009-03-19 15:55:08 UTC (rev 2804)
@@ -74,7 +74,6 @@
std::vector<WeaponPack *> weaponPacks_;
std::map<std::string, Munition *> munitionSharedSet_;
std::map<std::string, Munition *> munitionSet_;
- WeaponSet *activeWeaponSet_;
Pawn *parentPawn_;
};
}
Modified: branches/weaponsystem/src/orxonox/objects/weaponSystem/weapons/LaserGun.cc
===================================================================
--- branches/weaponsystem/src/orxonox/objects/weaponSystem/weapons/LaserGun.cc 2009-03-19 13:17:01 UTC (rev 2803)
+++ branches/weaponsystem/src/orxonox/objects/weaponSystem/weapons/LaserGun.cc 2009-03-19 15:55:08 UTC (rev 2804)
@@ -52,22 +52,28 @@
{
}
+ void LaserGun::reloadBullet()
+ {
+ this->bulletTimer(this->bulletLoadingTime_);
+ }
+
+ void LaserGun::reloadMagazine()
+ {
+ this->magazineTimer(this->magazineLoadingTime_);
+ }
+
void LaserGun::takeBullets()
{
-//COUT(0) << "LaserGun::takeBullets" << std::endl;
this->munition_->removeBullets(1);
- this->bulletTimer(this->bulletLoadingTime_);
}
void LaserGun::takeMagazines()
{
this->munition_->removeMagazines(1);
- this->magazineTimer(this->magazineLoadingTime_);
}
void LaserGun::createProjectile()
{
-//COUT(0) << "LaserGun::createProjectile" << std::endl;
BillboardProjectile* projectile = new ParticleProjectile(this);
projectile->setOrientation(this->getWorldOrientation());
projectile->setPosition(this->getWorldPosition());
Modified: branches/weaponsystem/src/orxonox/objects/weaponSystem/weapons/LaserGun.h
===================================================================
--- branches/weaponsystem/src/orxonox/objects/weaponSystem/weapons/LaserGun.h 2009-03-19 13:17:01 UTC (rev 2803)
+++ branches/weaponsystem/src/orxonox/objects/weaponSystem/weapons/LaserGun.h 2009-03-19 15:55:08 UTC (rev 2804)
@@ -50,6 +50,8 @@
virtual void takeBullets();
virtual void takeMagazines();
virtual void createProjectile();
+ virtual void reloadBullet();
+ virtual void reloadMagazine();
private:
float speed_;
Modified: branches/weaponsystem/src/orxonox/objects/worldentities/pawns/Pawn.cc
===================================================================
--- branches/weaponsystem/src/orxonox/objects/worldentities/pawns/Pawn.cc 2009-03-19 13:17:01 UTC (rev 2803)
+++ branches/weaponsystem/src/orxonox/objects/worldentities/pawns/Pawn.cc 2009-03-19 15:55:08 UTC (rev 2804)
@@ -221,7 +221,6 @@
{
ExplosionChunk* chunk = new ExplosionChunk(this->getCreator());
chunk->setPosition(this->getPosition());
-
}
}
@@ -242,6 +241,12 @@
pickUp.eraseAll();
}
+
+ /* WeaponSystem:
+ * functions load Slot, Set, Pack from XML and make sure all parent-pointers are set.
+ * with setWeaponPack you can not just load a Pack from XML but if a Pack already exists anywhere, you can attach it.
+ * --> e.g. Pickup-Items
+ */
void Pawn::setWeaponSlot(WeaponSlot * wSlot)
{
this->attach(wSlot);
More information about the Orxonox-commit
mailing list