Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Apr 18, 2009, 6:14:52 PM (16 years ago)
Author:
landauf
Message:

Added many new features in the Munition class:

  • there are now 3 modes: a) every weapon has it's own magazine b) all weapons use the same magazin c) no magazines, just a big munition pool
  • the Munition class handles the reloading of the magazine

Split the Weapon class into Weapon and WeaponMode. WeaponMode creates the fire of the Weapon. A weapon can own several WeaponModes (for example primary and secondary fire). But it's also possible to have a weapon with several muzzles which all fire at the same time (there's a WeaponMode for each muzzle).

Renamed LaserGun to LaserFire and Fusion to FusionFire. They inherit now from WeaponMode.

Changed the code in the Weapon class to use the new Munition functionality.

Added ReplenishingMunition, a subclass of Munition that replenishes itself (used for LaserGunMunition).

Added a reload command to reload magazines.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/weapons/src/orxonox/objects/weaponSystem/WeaponSystem.cc

    r2915 r2918  
    3737#include "WeaponSet.h"
    3838#include "Weapon.h"
     39#include "Munition.h"
    3940
    4041/* WeaponSystem
     
    6364                this->pawn_->setWeaponSystem(0);
    6465
    65 //            for (std::map<unsigned int, WeaponSet*>::iterator it = this->weaponSets_.begin(); it != this->weaponSets_.end(); )
    66 //                delete (it++)->second;
    6766            while (!this->weaponSets_.empty())
    6867                delete (this->weaponSets_.begin()->second);
    6968
    70 //            for (std::set<WeaponPack*>::iterator it = this->weaponPacks_.begin(); it != this->weaponPacks_.end(); )
    71 //                delete (*(it++));
    7269            while (!this->weaponPacks_.empty())
    7370                delete (*this->weaponPacks_.begin());
    7471
    75 //            for (std::vector<WeaponSlot*>::iterator it = this->weaponSlots_.begin(); it != this->weaponSlots_.end(); )
    76 //                delete (*(it++));
    7772            while (!this->weaponSlots_.empty())
    7873                delete (*this->weaponSlots_.begin());
     74
     75            while (!this->munitions_.empty())
     76                { delete (this->munitions_.begin()->second); this->munitions_.erase(this->munitions_.begin()); }
    7977        }
    8078    }
     
    284282    }
    285283
    286     void WeaponSystem::setNewMunition(const std::string& munitionType, Munition * munitionToAdd)
    287     {
    288         this->munitionSet_[munitionType] = munitionToAdd;
    289     }
    290 
    291 
    292     //returns the Pointer to the munitionType, if this munitionType doesn't exist returns 0, see Weapon::attachNeededMunition
    293     Munition * WeaponSystem::getMunitionType(const std::string& munitionType) const
    294     {
    295         std::map<std::string, Munition *>::const_iterator it = this->munitionSet_.find(munitionType);
    296         if (it != this->munitionSet_.end())
    297             return it->second;
    298         else
    299             return 0;
    300     }
    301 
    302284    void WeaponSystem::fire(unsigned int firemode)
    303285    {
     
    306288            it->second->fire();
    307289    }
     290
     291    void WeaponSystem::reload()
     292    {
     293        for (std::map<unsigned int, WeaponSet *>::iterator it = this->weaponSets_.begin(); it != this->weaponSets_.end(); ++it)
     294            it->second->reload();
     295    }
     296
     297    Munition * WeaponSystem::getMunition(SubclassIdentifier<Munition> * identifier)
     298    {
     299        if (!identifier || !identifier->getIdentifier())
     300            return 0;
     301
     302        std::map<Identifier *, Munition *>::iterator it = this->munitions_.find(identifier->getIdentifier());
     303        if (it != this->munitions_.end())
     304        {
     305            return it->second;
     306        }
     307        else if (identifier->getIdentifier()->isA(Class(Munition)))
     308        {
     309            Munition* munition = identifier->fabricate(this);
     310            this->munitions_[identifier->getIdentifier()] = munition;
     311            return munition;
     312        }
     313        else
     314        {
     315            return 0;
     316        }
     317    }
    308318}
Note: See TracChangeset for help on using the changeset viewer.