[Orxonox-commit 6054] r10713 - in code/branches/fabienHS15/src: modules/weapons/munitions orxonox/weaponsystem
fvultier at orxonox.net
fvultier at orxonox.net
Mon Oct 26 23:34:23 CET 2015
Author: fvultier
Date: 2015-10-26 23:34:23 +0100 (Mon, 26 Oct 2015)
New Revision: 10713
Modified:
code/branches/fabienHS15/src/modules/weapons/munitions/FusionMunition.cc
code/branches/fabienHS15/src/modules/weapons/munitions/GravityBombMunition.cc
code/branches/fabienHS15/src/modules/weapons/munitions/IceMunition.cc
code/branches/fabienHS15/src/modules/weapons/munitions/LaserMunition.cc
code/branches/fabienHS15/src/modules/weapons/munitions/LightningMunition.cc
code/branches/fabienHS15/src/modules/weapons/munitions/RocketMunition.cc
code/branches/fabienHS15/src/modules/weapons/munitions/SplitMunition.cc
code/branches/fabienHS15/src/orxonox/weaponsystem/Munition.cc
code/branches/fabienHS15/src/orxonox/weaponsystem/Munition.h
Log:
Modified: code/branches/fabienHS15/src/modules/weapons/munitions/FusionMunition.cc
===================================================================
--- code/branches/fabienHS15/src/modules/weapons/munitions/FusionMunition.cc 2015-10-26 20:33:19 UTC (rev 10712)
+++ code/branches/fabienHS15/src/modules/weapons/munitions/FusionMunition.cc 2015-10-26 22:34:23 UTC (rev 10713)
@@ -46,7 +46,7 @@
this->maxMagazines_ = 10;
this->magazines_ = 10;
- this->deployment_ = DEPLOYMENT_SEPARATE;
+ this->deployment_ = MunitionDeployment::Separate;
this->reloadTime_ = 1.0f;
Modified: code/branches/fabienHS15/src/modules/weapons/munitions/GravityBombMunition.cc
===================================================================
--- code/branches/fabienHS15/src/modules/weapons/munitions/GravityBombMunition.cc 2015-10-26 20:33:19 UTC (rev 10712)
+++ code/branches/fabienHS15/src/modules/weapons/munitions/GravityBombMunition.cc 2015-10-26 22:34:23 UTC (rev 10713)
@@ -18,7 +18,7 @@
this->maxMagazines_ = 30;
this->magazines_ = 15;
- this->deployment_ = DEPLOYMENT_STACK;
+ this->deployment_ = MunitionDeployment::Stack;
this->bAllowMunitionRefilling_ = true;
this->bAllowMultiMunitionRemovementUnderflow_ = false;
Modified: code/branches/fabienHS15/src/modules/weapons/munitions/IceMunition.cc
===================================================================
--- code/branches/fabienHS15/src/modules/weapons/munitions/IceMunition.cc 2015-10-26 20:33:19 UTC (rev 10712)
+++ code/branches/fabienHS15/src/modules/weapons/munitions/IceMunition.cc 2015-10-26 22:34:23 UTC (rev 10713)
@@ -46,7 +46,7 @@
this->maxMagazines_ = 50;
this->magazines_ = 25;
- this->deployment_ = DEPLOYMENT_STACK;
+ this->deployment_ = MunitionDeployment::Stack;
this->bAllowMunitionRefilling_ = false;
this->bAllowMultiMunitionRemovementUnderflow_ = false;
Modified: code/branches/fabienHS15/src/modules/weapons/munitions/LaserMunition.cc
===================================================================
--- code/branches/fabienHS15/src/modules/weapons/munitions/LaserMunition.cc 2015-10-26 20:33:19 UTC (rev 10712)
+++ code/branches/fabienHS15/src/modules/weapons/munitions/LaserMunition.cc 2015-10-26 22:34:23 UTC (rev 10713)
@@ -46,7 +46,7 @@
this->maxMagazines_ = 10;
this->magazines_ = 10;
- this->deployment_ = DEPLOYMENT_SEPARATE;
+ this->deployment_ = MunitionDeployment::Separate;
this->bAllowMunitionRefilling_ = true;
this->bAllowMultiMunitionRemovementUnderflow_ = true;
Modified: code/branches/fabienHS15/src/modules/weapons/munitions/LightningMunition.cc
===================================================================
--- code/branches/fabienHS15/src/modules/weapons/munitions/LightningMunition.cc 2015-10-26 20:33:19 UTC (rev 10712)
+++ code/branches/fabienHS15/src/modules/weapons/munitions/LightningMunition.cc 2015-10-26 22:34:23 UTC (rev 10713)
@@ -46,7 +46,7 @@
this->maxMagazines_ = 1;
this->magazines_ = 1;
- this->deployment_ = DEPLOYMENT_SHARE;
+ this->deployment_ = MunitionDeployment::Share;
this->bAllowMunitionRefilling_ = true;
this->bAllowMultiMunitionRemovementUnderflow_ = true;
Modified: code/branches/fabienHS15/src/modules/weapons/munitions/RocketMunition.cc
===================================================================
--- code/branches/fabienHS15/src/modules/weapons/munitions/RocketMunition.cc 2015-10-26 20:33:19 UTC (rev 10712)
+++ code/branches/fabienHS15/src/modules/weapons/munitions/RocketMunition.cc 2015-10-26 22:34:23 UTC (rev 10713)
@@ -46,7 +46,7 @@
this->maxMagazines_ = 30;
this->magazines_ = 10;
- this->deployment_ = DEPLOYMENT_STACK;
+ this->deployment_ = MunitionDeployment::Stack;
this->bAllowMunitionRefilling_ = false;
this->bAllowMultiMunitionRemovementUnderflow_ = false;
Modified: code/branches/fabienHS15/src/modules/weapons/munitions/SplitMunition.cc
===================================================================
--- code/branches/fabienHS15/src/modules/weapons/munitions/SplitMunition.cc 2015-10-26 20:33:19 UTC (rev 10712)
+++ code/branches/fabienHS15/src/modules/weapons/munitions/SplitMunition.cc 2015-10-26 22:34:23 UTC (rev 10713)
@@ -46,7 +46,7 @@
this->maxMagazines_ = 100;
this->magazines_ = 25;
- this->deployment_ = DEPLOYMENT_STACK;
+ this->deployment_ = MunitionDeployment::Stack;
this->bAllowMunitionRefilling_ = true;
this->bAllowMultiMunitionRemovementUnderflow_ = false;
Modified: code/branches/fabienHS15/src/orxonox/weaponsystem/Munition.cc
===================================================================
--- code/branches/fabienHS15/src/orxonox/weaponsystem/Munition.cc 2015-10-26 20:33:19 UTC (rev 10712)
+++ code/branches/fabienHS15/src/orxonox/weaponsystem/Munition.cc 2015-10-26 22:34:23 UTC (rev 10713)
@@ -44,11 +44,13 @@
this->maxMagazines_ = 10;
this->magazines_ = 10;
- this->deployment_ = DEPLOYMENT_STACK;
+ this->deployment_ = MunitionDeployment::Stack;
this->bAllowMunitionRefilling_ = true;
this->bAllowMultiMunitionRemovementUnderflow_ = true;
this->reloadTime_ = 0.5f;
+
+ this->lastFilledWeaponMode_ = NULL;
}
Munition::~Munition()
@@ -59,7 +61,7 @@
Munition::Magazine* Munition::getMagazine(WeaponMode* user) const
{
- if (deployment_ == DEPLOYMENT_SEPARATE)
+ if (deployment_ == MunitionDeployment::Separate)
{
// For separated magazines we definitively need a given user
if (!user)
@@ -85,7 +87,7 @@
Magazine* magazine = this->getMagazine(user);
if (magazine)
{
- if (deployment_ == DEPLOYMENT_STACK)
+ if (deployment_ == MunitionDeployment::Stack)
// With stacked munition every magazine contributes to the total amount
return this->maxMunitionPerMagazine_ * this->magazines_ + magazine->munition_;
else
@@ -107,7 +109,7 @@
unsigned int Munition::getNumMagazines() const
{
- if (deployment_ == DEPLOYMENT_STACK)
+ if (deployment_ == MunitionDeployment::Stack)
{
// If we stack munition and the current magazine is still full, it counts too
Magazine* magazine = this->getMagazine(0);
@@ -120,7 +122,7 @@
unsigned int Munition::getMaxMunition() const
{
- if (deployment_ == DEPLOYMENT_STACK)
+ if (deployment_ == MunitionDeployment::Stack)
return this->maxMunitionPerMagazine_ * this->maxMagazines_;
else
return this->maxMunitionPerMagazine_;
@@ -134,7 +136,7 @@
unsigned int munition = magazine->munition_;
// If we stack munition, we don't care about the current magazine - we just need enough munition in total
- if (deployment_ == DEPLOYMENT_STACK)
+ if (deployment_ == MunitionDeployment::Stack)
munition += this->maxMunitionPerMagazine_ * this->magazines_;
if (munition == 0)
@@ -167,7 +169,7 @@
else
{
// Not enough munition
- if (deployment_ == DEPLOYMENT_STACK)
+ if (deployment_ == MunitionDeployment::Stack)
{
// We stack munition, so just take what we can and then load the next magazine
amount -= magazine->munition_;
@@ -197,7 +199,7 @@
bool Munition::canReload() const
{
// As long as we have enough magazines (and don't stack munition) we can reload
- return (this->magazines_ > 0 && !deployment_ == DEPLOYMENT_STACK);
+ return (this->magazines_ > 0 && !deployment_ == MunitionDeployment::Stack);
}
bool Munition::needReload(WeaponMode* user) const
@@ -205,7 +207,7 @@
Magazine* magazine = this->getMagazine(user);
if (magazine)
{
- if (deployment_ == DEPLOYMENT_STACK)
+ if (deployment_ == MunitionDeployment::Stack)
// With stacked munition, we never have to reload
return false;
else
@@ -229,17 +231,21 @@
return false;
// If we use separate magazines for each user, we definitively need a user given
- if (deployment_ == DEPLOYMENT_SEPARATE && !user)
+ if (deployment_ == MunitionDeployment::Separate && !user)
return false;
// If we don't use separate magazines, set user to 0
- if (!deployment_ == DEPLOYMENT_SEPARATE)
+ if (!deployment_ == MunitionDeployment::Separate)
user = 0;
// Remove the current magazine for the given user
std::map<WeaponMode*, Magazine*>::iterator it = this->currentMagazines_.find(user);
if (it != this->currentMagazines_.end())
{
+ if (it->first == lastFilledWeaponMode_)
+ {
+ lastFilledWeaponMode_ = NULL;
+ }
delete it->second;
this->currentMagazines_.erase(it);
}
@@ -258,7 +264,7 @@
if (!this->bAllowMunitionRefilling_)
return false;
- if (deployment_ == DEPLOYMENT_STACK)
+ if (deployment_ == MunitionDeployment::Stack)
{
// If we stack munition, we can always add munition until we reach the limit
return (this->getNumMunition(0) < this->getMaxMunition());
@@ -279,7 +285,7 @@
if (!this->canAddMunition(amount))
return false;
- if (deployment_ == DEPLOYMENT_STACK)
+ if (deployment_ == MunitionDeployment::Stack)
{
// Stacking munition means, if a magazine gets full, the munition adds to a new magazine
Magazine* magazine = this->getMagazine(0);
@@ -310,10 +316,61 @@
}
else
{
+ std::map<WeaponMode*, Magazine*>::iterator it;
+
+ // If the pointer to the weapon mode whose magazine got munition added to is NULL, then set the iterator to the beginning of the map
+ // Otherwise set it to the next weapon mode
+ if (lastFilledWeaponMode_ == NULL)
+ {
+ it = this->currentMagazines_.begin();
+ }
+ else
+ {
+ it = this->currentMagazines_.find(lastFilledWeaponMode_);
+ ++ it;
+ }
+
// Share the munition equally to the current magazines
+ bool firstLoop = true;
while (amount > 0)
{
bool change = false;
+ while (it != this->currentMagazines_.end())
+ {
+ // Add munition if the magazine isn't full (but only to loaded magazines)
+ if (amount > 0 && it->second->munition_ < this->maxMunitionPerMagazine_ && it->second->bLoaded_)
+ {
+ it->second->munition_++;
+ amount--;
+ lastFilledWeaponMode_ = it->first;
+ change = true;
+ }
+
+ ++it;
+ }
+
+ // If there was no change in a loop, all magazines are full (or locked due to loading)
+ // Because the first loop does not stat at the beginning of the map we have to treat is separately
+ if (!change && !firstLoop)
+ {
+ break;
+ }
+
+ it = this->currentMagazines_.begin();
+ firstLoop = false;
+ }
+
+ return true;
+
+
+
+
+
+ /*
+ // Share the munition equally to the current magazines
+ while (amount > 0)
+ {
+ bool change = false;
for (std::map<WeaponMode*, Magazine*>::iterator it = this->currentMagazines_.begin(); it != this->currentMagazines_.end(); ++it)
{
// Add munition if the magazine isn't full (but only to loaded magazines)
@@ -330,7 +387,7 @@
break;
}
- return true;
+ return true;*/
}
}
@@ -338,7 +395,7 @@
{
// TODO: 'amount' is not used
- if (deployment_ == DEPLOYMENT_STACK)
+ if (deployment_ == MunitionDeployment::Stack)
// If we stack munition, we can always add new magazines because they contribute directly to the munition
return (this->getNumMunition(0) < this->getMaxMunition());
else
@@ -355,7 +412,7 @@
int needed_magazines = this->maxMagazines_ - this->magazines_ - this->currentMagazines_.size();
// If zero or less magazines are needed, we definitively don't need more magazines (unless we stack munition - then a magazine contributes directly to the munition)
- if (needed_magazines <= 0 && !deployment_ == DEPLOYMENT_STACK)
+ if (needed_magazines <= 0 && !deployment_ == MunitionDeployment::Stack)
return false;
if (amount <= static_cast<unsigned int>(needed_magazines))
@@ -367,7 +424,7 @@
{
// We get more magazines than we need, so just add the needed amount
this->magazines_ += needed_magazines;
- if (deployment_ == DEPLOYMENT_STACK)
+ if (deployment_ == MunitionDeployment::Stack)
{
// We stack munition, so the additional amount contributes directly to the munition of the current magazine
Magazine* magazine = this->getMagazine(0);
@@ -381,7 +438,7 @@
bool Munition::canRemoveMagazines(unsigned int amount) const
{
- if (deployment_ == DEPLOYMENT_STACK)
+ if (deployment_ == MunitionDeployment::Stack)
{
if (this->magazines_ >= amount)
{
@@ -420,7 +477,7 @@
// We have enough magazines, just remove the amount
this->magazines_ -= amount;
}
- else if (deployment_ == DEPLOYMENT_STACK)
+ else if (deployment_ == MunitionDeployment::Stack)
{
// We don't have enough magazines, but we're stacking munition, so additionally remove the bullets from the current magazine
this->magazines_ = 0;
@@ -435,19 +492,23 @@
bool Munition::dropMagazine(WeaponMode* user)
{
// If we use separate magazines, we need a user
- if (deployment_ == DEPLOYMENT_SEPARATE && !user)
+ if (deployment_ == MunitionDeployment::Separate && !user)
return false;
// If we don't use separate magazines, set user to 0
- if (!deployment_ == DEPLOYMENT_SEPARATE)
+ if (!deployment_ == MunitionDeployment::Separate)
user = 0;
// Remove the current magazine for the given user
std::map<WeaponMode*, Magazine*>::iterator it = this->currentMagazines_.find(user);
if (it != this->currentMagazines_.end())
{
+ if (it->first == lastFilledWeaponMode_)
+ {
+ lastFilledWeaponMode_ = NULL;
+ }
delete it->second;
- this->currentMagazines_.erase(it);
+ this->currentMagazines_.erase(it);
return true;
}
@@ -463,7 +524,7 @@
this->munition_ = 0;
this->bLoaded_ = false;
- if (bUseReloadTime && munition->reloadTime_ > 0 && !munition->deployment_ == DEPLOYMENT_STACK)
+ if (bUseReloadTime && munition->reloadTime_ > 0 && !munition->deployment_ == MunitionDeployment::Stack)
{
const ExecutorPtr& executor = createExecutor(createFunctor(&Magazine::loaded, this));
executor->setDefaultValues(munition);
Modified: code/branches/fabienHS15/src/orxonox/weaponsystem/Munition.h
===================================================================
--- code/branches/fabienHS15/src/orxonox/weaponsystem/Munition.h 2015-10-26 20:33:19 UTC (rev 10712)
+++ code/branches/fabienHS15/src/orxonox/weaponsystem/Munition.h 2015-10-26 22:34:23 UTC (rev 10713)
@@ -38,14 +38,16 @@
namespace orxonox
{
- enum Deployment
+ namespace MunitionDeployment
{
- DEPLOYMENT_SHARE,
- DEPLOYMENT_STACK,
- DEPLOYMENT_SEPARATE
- };
+ enum Value
+ {
+ Share,
+ Stack,
+ Separate
+ };
+ }
-
class _OrxonoxExport Munition : public BaseObject
{
struct Magazine
@@ -76,9 +78,9 @@
inline unsigned int getMaxMunitionPerMagazine() const
{ return this->maxMunitionPerMagazine_; }
inline bool getUseSeparateMagazines() const
- { return deployment_ == DEPLOYMENT_SEPARATE; }
+ { return deployment_ == MunitionDeployment::Separate; }
inline bool getStackMunition() const
- { return deployment_ == DEPLOYMENT_STACK; }
+ { return deployment_ == MunitionDeployment::Stack; }
bool canTakeMunition(unsigned int amount, WeaponMode* user) const;
bool takeMunition(unsigned int amount, WeaponMode* user);
@@ -104,14 +106,15 @@
unsigned int maxMunitionPerMagazine_;
unsigned int maxMagazines_;
unsigned int magazines_;
- std::map<WeaponMode*, Magazine*> currentMagazines_;
+ std::map<WeaponMode*, Magazine*> currentMagazines_; // Maps weapon modes to magazines that are currently used.
- Deployment deployment_;
+ MunitionDeployment::Value deployment_; // Defines the behaviour how munition and magazines are distributed to the consuming weapon modes.
bool bAllowMunitionRefilling_;
bool bAllowMultiMunitionRemovementUnderflow_;
float reloadTime_;
+ WeaponMode* lastFilledWeaponMode_; // Pointer to the weapon mode that got the last munition during the last call of addMunition.
private:
Magazine* getMagazine(WeaponMode* user) const;
More information about the Orxonox-commit
mailing list