Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 2203


Ignore:
Timestamp:
Nov 12, 2008, 4:45:50 PM (16 years ago)
Author:
polakma
Message:

added munition, fixed reloadTimer_

Location:
code/branches/weapon2/src/orxonox
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • code/branches/weapon2/src/orxonox/CMakeLists.txt

    r2186 r2203  
    9292  objects/weaponSystem/weapons/LaserGun.cc
    9393  objects/weaponSystem/munitions/LaserGunMunition.cc
    94   objects/weaponSystem/projectiles/BillboardProjectile.cc
    95   objects/weaponSystem/projectiles/ParticleProjectile.cc
    96   objects/weaponSystem/projectiles/Projectile.cc
     94#  objects/weaponSystem/projectiles/BillboardProjectile.cc
     95#  objects/weaponSystem/projectiles/ParticleProjectile.cc
     96#  objects/weaponSystem/projectiles/Projectile.cc
    9797
    9898  objects/worldentities/triggers/Trigger.cc
  • code/branches/weapon2/src/orxonox/OrxonoxPrereqs.h

    r2186 r2203  
    7373    }
    7474
     75    //put here all existing munitionTypes
     76    namespace MunitionType
     77    {
     78
     79
     80
     81        enum Enum
     82        { laserGunMunition };
     83    }
     84
     85    //put here all weapon fire modes.
     86    //they have to be added to Pawn and HumanController, too.
     87    namespace WeaponMode
     88    {
     89        enum Enum
     90        {
     91            fire,
     92            altFire,
     93            altFire2
     94        };
     95    }
     96
     97
    7598    class GraphicsEngine;
    7699    class Settings;
  • code/branches/weapon2/src/orxonox/objects/weaponSystem/Munition.cc

    r2097 r2203  
    4646    }
    4747
     48
     49    void Munition::decrementBullets()
     50    {
     51        this->bullets--;
     52    }
     53    void Munition::decrementMagazines()
     54    {
     55        this->magazines--;
     56    }
     57    void Munition::incrementBullets()
     58    {
     59        this->bullets++;
     60    }
     61    void Munition::incrementMagazines()
     62    {
     63        this->magazines++;
     64    }
     65
     66
    4867    void Munition::XMLPort(Element& xmlelement, XMLPort::Mode mode)
    4968    {
  • code/branches/weapon2/src/orxonox/objects/weaponSystem/Munition.h

    r2106 r2203  
    4545            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    4646
     47            void decrementBullets();
     48            void decrementMagazines();
     49            void incrementBullets();
     50            void incrementMagazines();
    4751
    4852        private:
    49 
    50 
     53            int bullets;
     54            int magazines;
    5155    };
    5256}
  • code/branches/weapon2/src/orxonox/objects/weaponSystem/Weapon.cc

    r2186 r2203  
    3535#include "Weapon.h"
    3636
    37 
    3837namespace orxonox
    3938{
     
    4342        this->weaponReadyToShoot_ = true;
    4443        this->setParentWeaponSystem();
    45         this->pointerToMunition_ = this->parentWeaponSystem_->getAttachedMunitionPointer;
    46         this->attachNeededMunition(this->pointerToMunition_);
    47 
    4844    }
    4945
     
    6258
    6359    }
     60    void Weapon::timer()
     61    {
     62        this->reloadTimer_.setTimer( this->loadingTime_ , false , this , createExecutor(createFunctor(&Weapon::reloaded)));
     63    }
    6464
    6565    void Weapon::reloaded()
    6666    {
     67
    6768        this->weaponReadyToShoot_ = true;
    6869    }
    6970
    70     void attachNeededMunition(Munition *pointerToMunition)
     71    void Weapon::attachNeededMunition(std::string munitionName)
    7172    {
    7273        //if munition type already exist attach it, else create a new one of this type and attach it to the weapon and to the WeaponSystem
    73         if ( this->parentWeaponSystem_->munitionSet_[laserGunMunition] )
    74             this->pointerToMunition_ = pointerToMunition;
     74        if ( this->parentWeaponSystem_->getMunitionType(munitionName) )
     75            this->munition_ = this->parentWeaponSystem_->getMunitionType(munitionName);
    7576        else
    7677        {
    77             this->pointerToMunition_ = new LaserGunMunition;
    78             this->parentWeaponSystem_->munitionSet_[laserGunMunition] = this->pointerToMunition_;
    79 
     78            //create new munition with identifier
     79            this->munitionIdentifier_ = ClassByString(munitionName);
     80            this->munition_ = this->munitionIdentifier_.fabricate(this);
     81            this->parentWeaponSystem_->setNewMunition(munitionName, this->munition_);
    8082        }
    8183    }
    8284
    83 /*
     85
     86    /*get and set functions
     87     *
     88     */
    8489    void Weapon::setParentWeaponSystem()
    85     {
    86         this->parentWeaponSystem_ = this->parentWeaponSlot_->parentWeaponSet_->parentWeaponSystem_;
    87     }
    88 */
     90    {   this->parentWeaponSystem_ = this->parentWeaponSlot_->getParentWeaponSet()->getParentWeaponSystem(); }
    8991
     92    Munition * Weapon::getAttachedMunition()
     93    {   return this->munition_; }
     94
     95    void Weapon::setLoadingTime(float loadingTime)
     96    {   this->loadingTime_ = loadingTime;   }
     97
     98    float Weapon::getLoadingTime()
     99    {   return this->loadingTime_;  }
     100
     101    void Weapon::setWeaponReadyToShoot(bool b)
     102    {   this->weaponReadyToShoot_ = b;   }
     103
     104    bool Weapon::getWeaponReadyToShoot()
     105    {   return this->weaponReadyToShoot_;    }
     106    Timer<Weapon> * Weapon::getTimer()
     107    {   return &this->reloadTimer_;   }
    90108}
  • code/branches/weapon2/src/orxonox/objects/weaponSystem/Weapon.h

    r2186 r2203  
    3535#include "tools/BillboardSet.h"
    3636#include "tools/Timer.h"
     37#include "core/Identifier.h"
     38
     39#include "WeaponSystem.h"
     40#include "Munition.h"
    3741
    3842namespace orxonox
     
    4751
    4852            virtual void fire();
     53            void timer();
    4954            void reloaded();
     55            void attachNeededMunition(std::string munitionType);
     56
     57            //get and set functions
    5058            virtual void setParentWeaponSystem();
    51             void attachNeededMunition(Munition *munitionPointer);
     59            Munition * getAttachedMunition();
     60            void setLoadingTime(float loadingTime);
     61            float getLoadingTime();
     62            void setWeaponReadyToShoot(bool b);
     63            bool getWeaponReadyToShoot();
     64            Timer<Weapon> *getTimer();
    5265
    5366            inline void setParentWeaponSlot(WeaponSlot *parentWeaponSlot)
     
    5669                { return parentWeaponSlot_; };
    5770
    58 
    59 
    60 
    6171        private:
    6272            bool weaponReadyToShoot_;
    6373            float loadingTime_;
    64             Munition *pointerToMunition_;
     74            Munition *munition_;
     75
    6576            WeaponSlot *parentWeaponSlot_;
    6677            WeaponSystem *parentWeaponSystem_;
     78            SubclassIdentifier<Munition> munitionIdentifier_;
    6779            Timer<Weapon> reloadTimer_;
    68 
    69 
    7080    };
    7181}
  • code/branches/weapon2/src/orxonox/objects/weaponSystem/WeaponSlot.cc

    r2145 r2203  
    7474    void WeaponSlot::XMLPort(Element& xmlelement, XMLPort::Mode mode)
    7575    {
     76        SUPER(WeaponSlot, XMLPort, xmlelement, mode);
     77    }
    7678
    77     }
    7879}
  • code/branches/weapon2/src/orxonox/objects/weaponSystem/WeaponSlot.h

    r2186 r2203  
    3434#include "core/BaseObject.h"
    3535
    36 
    3736#include "Weapon.h"
    3837#include "../worldentities/PositionableEntity.h"
     
    6362
    6463            WeaponSet *parentWeaponSet_;
    65 
    66             //attached weapon orientation
    67             int yaw_ = 0;
    68             int pitch_ = 0;
    69             int roll_ = 0;
    7064    };
    7165}
  • code/branches/weapon2/src/orxonox/objects/weaponSystem/WeaponSystem.cc

    r2186 r2203  
    5252        this->activeWeaponSet_ = 0;
    5353        this->parentSpaceShip_ = 0;
    54         this->attachedMunition_ =0;
    5554    }
    5655
     
    6463        wSet->setParentWeaponSystem(this);
    6564    }
     65
     66    void WeaponSystem::setNewMunition(std::string munitionType, Munition * munitionToAdd)
     67    {
     68        this->munitionSet_[munitionType] = munitionToAdd;
     69    }
     70    Munition * WeaponSystem::getMunitionType(std::string munitionType)
     71    {
     72        return this->munitionSet_[munitionType];
     73    }
     74
    6675
    6776/*
     
    98107    }
    99108
    100     Munition * WeaponSystem::getAttachedMunitionPointer()
    101     {
    102         return this->attachedMunition_;
    103     }
    104 
    105     void WeaponSystem::addMunitionType(Munition *munitionPointer)
    106     {
    107 
    108 
    109         if (munitionPointer != NULL)  //gewährleiste, dass munitionPointer auf etwas sinnvolles zeigt
    110             this->attachedMunition_ = munitionPointer;
    111         else
    112             ;//was?
    113 
    114     }
    115 
    116 
    117109}
  • code/branches/weapon2/src/orxonox/objects/weaponSystem/WeaponSystem.h

    r2186 r2203  
    3939namespace orxonox
    4040{
    41     //put here all existing munitionTypes
    42     namespace MunitionType
    43     {
    44         enum Enum
    45         { laserGunMunition };
    46     }
    47 
    48     //put here all weapon fire modes.
    49     //they have to be added to Pawn and HumanController, too.
    50     namespace WeaponMode
    51     {
    52         enum Enum
    53         { fire, altFire, altFire2 };
    54     }
    5541
    5642    class _OrxonoxExport WeaponSystem : public BaseObject
     
    6349
    6450            void attachWeaponSet(WeaponSet *wSet);
    65             void addMunitionType(Munition *munitionPointer);
    6651            void fire();
    6752            void fire(WeaponMode::Enum fireMode);
    6853            //void setActiveWeaponSet(unsigned int n);
    6954            WeaponSet * getWeaponSetPointer(unsigned int n);
    70             Munition * getAttachedMunitionPointer();
     55
     56            void setNewMunition(std::string munitionType, Munition * munitionToAdd);
     57            Munition * getMunitionType(std::string munitionType);
    7158
    7259            inline void setParentSpaceShip(SpaceShip *parentSpaceShip)
     
    7865        private:
    7966            std::vector<WeaponSet *> weaponSets_;
    80             std::map<MunitionType::Enum,Munition *> munitionSet_;
     67            std::map<std::string, Munition *> munitionSet_;
    8168            WeaponSet *activeWeaponSet_;
    8269            SpaceShip *parentSpaceShip_;
    83             Munition * attachedMunition_;
    8470    };
    8571}
  • code/branches/weapon2/src/orxonox/objects/weaponSystem/weapons/LaserGun.cc

    r2186 r2203  
    4444
    4545        //set weapon properties here
    46         this->loadingTime_ = 0.5;
     46        this->setLoadingTime(0.5);
     47
     48        //Hack --> will be loaded by XML
     49        this->attachNeededMunition("LaserGunMunition");
    4750    }
    4851
     
    5154    }
    5255
    53     LaserGun::fire()
     56    void LaserGun::fire()
    5457    {
    55         if { this->weaponReadyToShoot_ }
     58        if ( this->getWeaponReadyToShoot() )
    5659        {
    57             this->weaponReadyToShoot_ = false;
     60            this->setWeaponReadyToShoot(false);
     61
     62            Weapon::timer();
     63
    5864            //take munition
    59             //this->pointerToMunition_->
     65            this->getAttachedMunition()->decrementBullets();
    6066
    61             this->reloadTimer_.setTimer( loadingTime_ , false , this , &this->reloaded );
    62 
    63             BillboardProjectile* projectile = new ParticleProjectile(this);
    64             projectile->setColour(this->getProjectileColour());
     67            //create projectile
     68            //BillboardProjectile* projectile = new ParticleProjectile(this);
     69            //projectile->setColour(this->getProjectileColour());
    6570        }
    6671        else
    6772        {
    68             //actions, when weapon is not reloaded
     73            //actions, when weapon is not reloaded if there are some
    6974        }
    7075    }
     
    7580    }
    7681
     82
     83
    7784}
  • code/branches/weapon2/src/orxonox/objects/weaponSystem/weapons/LaserGun.h

    r2186 r2203  
    3737#include "util/Math.h"
    3838#include "../Weapon.h"
     39#include "../projectiles/BillboardProjectile.h"
     40#include "../projectiles/ParticleProjectile.h"
    3941
    4042namespace orxonox
     
    5052            void fire();
    5153
    52 
    5354        private:
    5455
Note: See TracChangeset for help on using the changeset viewer.