Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 4953 in orxonox.OLD


Ignore:
Timestamp:
Jul 25, 2005, 12:22:24 AM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: Slots are now PNodes

Location:
orxonox/trunk/src/world_entities
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • orxonox/trunk/src/world_entities/player.cc

    r4952 r4953  
    4646
    4747  //weapons:
    48   Weapon* wpRight = new TestGun(this, Vector(-2.6, 0.1, 3.0), Quaternion(), 0);
    49   Weapon* wpLeft = new TestGun(this, Vector(-2.6, 0.1, -3.0), Quaternion(), 1);
     48  Weapon* wpRight = new TestGun(0);
     49  Weapon* wpLeft = new TestGun(1);
    5050
    5151  this->weaponMan->addWeapon(wpRight);
     
    8080
    8181  //weapons:
    82   Weapon* wpRight = new TestGun(this, Vector(-2.6, 0.1, 3.0), Quaternion(), 0);
    83   Weapon* wpLeft = new TestGun(this, Vector(-2.6, 0.1, -3.0), Quaternion(), 1);
    84 
    85   this->weaponMan->addWeapon(wpRight, 0,0);
    86   this->weaponMan->addWeapon(wpLeft, 0, 1);
    87   this->weaponMan->addWeapon(wpLeft, 1, 1);
    88   this->weaponMan->addWeapon(wpRight, 2, 0);
    89 /*  this->weaponMan->addWeapon(wpRight, WM_CONFIG2);
    90   this->weaponMan->addWeapon(wpLeft, WM_CONFIG2);*/
     82  Weapon* wpRight = new TestGun(0);
     83  wpRight->setName("testGun Right");
     84  Weapon* wpLeft = new TestGun(1);
     85  wpLeft->setName("testGun Left");
     86
     87  this->weaponMan->addWeapon(wpLeft, 1, 0);
     88  this->weaponMan->addWeapon(wpRight,1 ,1);
     89  this->weaponMan->addWeapon(wpLeft, 3, 1);
     90
     91  this->weaponMan->changeWeaponConfig(0);
    9192}
    9293
     
    107108
    108109
    109   this->weaponMan = new WeaponManager(2);
     110  this->weaponMan = new WeaponManager(this);
     111  this->weaponMan->setSlotPosition(0, Vector(-2.6, .1, -3.0));
     112  this->weaponMan->setSlotPosition(1, Vector(-2.6, .1, 3.0));
     113
    110114}
    111115
  • orxonox/trunk/src/world_entities/weapons/test_gun.cc

    r4948 r4953  
    4444   creates a new weapon
    4545*/
    46 TestGun::TestGun (PNode* parent, const Vector& coordinate,
    47                   const Quaternion& direction, int leftRight)
    48   :  Weapon (parent, coordinate, direction)
     46TestGun::TestGun (int leftRight)
    4947{
    5048  this->setClassID(CL_TEST_GUN, "TestGun");
     
    7169      animation1->addKeyFrame(Vector(0, 0, 0), Quaternion(), 0.0, ANIM_LINEAR, ANIM_CONSTANT);
    7270
    73       animation2->addKeyFrame(Vector(-2.6, 0.1, 2.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT);
    74       animation2->addKeyFrame(Vector(-2.6, 0.1, 3.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT);
    75 
    76       animation3->addKeyFrame(Vector(-2.6, 0.1, 3.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT);
    77       animation3->addKeyFrame(Vector(-2.6, 0.1, 2.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT);
     71      animation2->addKeyFrame(Vector(0.0, 0.0, -1.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT);
     72      animation2->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT);
     73
     74      animation3->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT);
     75      animation3->addKeyFrame(Vector(0.0, 0.0, -1.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT);
    7876    }
    7977  else if( this->leftRight == W_RIGHT)
     
    8684      animation1->addKeyFrame(Vector(0, 0, .5), Quaternion(), 0.0, ANIM_LINEAR, ANIM_CONSTANT);
    8785
    88       animation2->addKeyFrame(Vector(-2.6, 0.1, -2.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT);
    89       animation2->addKeyFrame(Vector(-2.6, 0.1, -3.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT);
    90 
    91       animation3->addKeyFrame(Vector(-2.6, 0.1, -3.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT);
    92       animation3->addKeyFrame(Vector(-2.6, 0.1, -2.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT);
     86      animation2->addKeyFrame(Vector(.0, .0, 1.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT);
     87      animation2->addKeyFrame(Vector(.0, .0, .0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT);
     88
     89      animation3->addKeyFrame(Vector(.0, .0, 0.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT);
     90      animation3->addKeyFrame(Vector(.0, .0, 1.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT);
    9391    }
    9492/*
  • orxonox/trunk/src/world_entities/weapons/test_gun.h

    r4949 r4953  
    2929  {
    3030  public:
    31     TestGun (PNode* parent, const Vector& coordinate, const Quaternion& direction, int leftRight);
     31    TestGun (int leftRight);
    3232    virtual ~TestGun ();
    3333
  • orxonox/trunk/src/world_entities/weapons/weapon.cc

    r4950 r4953  
    3939 * creates a new weapon
    4040*/
    41 Weapon::Weapon (PNode* parent, const Vector& coordinate, const Quaternion& direction)
     41Weapon::Weapon ()
    4242{
    4343  this->init();
    44   parent->addChild(this, PNODE_ALL);
    45   this->setRelCoor(coordinate);
    46   this->setRelDir(direction);
    4744}
    4845
  • orxonox/trunk/src/world_entities/weapons/weapon.h

    r4950 r4953  
    7272  public:
    7373    // INITIALISATION //
    74     Weapon (PNode* parent, const Vector& coordinate, const Quaternion& direction);
     74    Weapon ();
    7575    Weapon(const TiXmlElement* root);
    7676    virtual ~Weapon ();
  • orxonox/trunk/src/world_entities/weapons/weapon_manager.cc

    r4952 r4953  
    2828#include "list.h"
    2929#include "t_animation.h"
     30#include "null_parent.h"
    3031
    3132using namespace std;
     
    3637 * @param number of weapon slots of the model/ship <= 8 (limitied)
    3738 */
    38 WeaponManager::WeaponManager(unsigned int slotCount)
     39WeaponManager::WeaponManager(PNode* parent)
    3940{
    4041  this->init();
    41   this->setSlotCount(slotCount);
     42  this->setParent(parent);
    4243}
    4344
     
    130131}
    131132
     133void WeaponManager::setParent(PNode* parent)
     134{
     135  if (parent == NULL)
     136    parent = NullParent::getInstance();
     137  this->parent = parent;
     138  if (this->parent != NULL)
     139  {
     140    for (int i = 0; i < WM_MAX_SLOTS; i++)
     141      this->parent->addChild(&this->currentSlotConfig[i].position);
     142  }
     143
     144}
    132145
    133146/**
     
    141154  else
    142155    this->slotCount = WM_MAX_SLOTS;
     156}
     157
     158void WeaponManager::setSlotPosition(int slot, const Vector& position)
     159{
     160  if (slot < this->slotCount)
     161    this->currentSlotConfig[slot].position.setRelCoor(position);
    143162}
    144163
     
    174193    }
    175194  }
     195
     196  //! @todo check if the weapon is already assigned to another config in another slot
     197
    176198  this->configs[configID][slotID] = weapon;
     199  if (this->parent != NULL)
     200    weapon->setParent(parent);
    177201  PRINTF(3)("Added a new Weapon to the WeaponManager: config %i/ slot %i\n", configID, slotID);
    178202}
     
    189213/**
    190214 * changes to the next weapon configuration
    191  *
    192  * if there are multiple weapon configurations defined by the manager, use this to switch between them
    193  * this function will deactivate the weapons first, change the config and reactivate them later
    194215 */
    195216void WeaponManager::nextWeaponConf()
     
    199220    this->currentConfigID = 0;
    200221  this->changeWeaponConfig(this->currentConfigID);
    201   this->debug();
    202 }
    203 
     222}
     223
     224/**
     225 * changes to the previous configuration
     226 */
    204227void WeaponManager::previousWeaponConfig()
    205228{
     
    208231    this->currentConfigID = WM_MAX_CONFIGS -1;
    209232  this->changeWeaponConfig(this->currentConfigID);
    210   this->debug();
    211 
    212 
    213 }
    214 
     233}
     234
     235/**
     236 * change to a desired configuration
     237 * @param weaponConfig the configuration to jump to.
     238 */
    215239void WeaponManager::changeWeaponConfig(int weaponConfig)
    216240{
     
    220244  {
    221245    this->currentSlotConfig[i].nextWeapon = this->configs[currentConfigID][i];
    222     if (this->currentSlotConfig[i].currentWeapon != NULL && this->currentSlotConfig[i].currentWeapon != this->currentSlotConfig[i].nextWeapon)
    223       (this->currentSlotConfig[i].currentWeapon->requestAction(WA_DEACTIVATE));
     246    if (this->currentSlotConfig[i].currentWeapon != this->currentSlotConfig[i].nextWeapon)
     247    {
     248      if (this->currentSlotConfig[i].currentWeapon != NULL)
     249        (this->currentSlotConfig[i].currentWeapon->requestAction(WA_DEACTIVATE));
     250      if (this->currentSlotConfig[i].nextWeapon != NULL && this->currentSlotConfig[i].nextWeapon->isActive())
     251        this->currentSlotConfig[i].nextWeapon = NULL;
     252    }
    224253  }
    225254}
     
    265294        tickWeapon = this->currentSlotConfig[i].currentWeapon = this->currentSlotConfig[i].nextWeapon;
    266295        if (tickWeapon != NULL)
     296        {
    267297          tickWeapon->requestAction(WA_ACTIVATE);
     298          tickWeapon->setParent(&this->currentSlotConfig[i].position);
     299        }
    268300      }
    269301    }
     
    308340
    309341
     342/**
     343 * outputs some nice debug information about the WeaponManager
     344 */
    310345void WeaponManager::debug() const
    311346{
  • orxonox/trunk/src/world_entities/weapons/weapon_manager.h

    r4952 r4953  
    2929#include "base_object.h"
    3030
    31 #include "vector.h"
     31#include "p_node.h"
    3232
    3333// FORWARD DECLARATION
     
    6161typedef struct
    6262{
    63   Vector        position;               //!< the relative Position to the position of the carrying entity. (const PNode* parent; of WeaponManager)
     63  PNode         position;               //!< the relative Position to the position of the carrying entity. (const PNode* parent; of WeaponManager)
    6464  long          capability;             //!< the capabilities of the Slot @see WM_SlotCapability.
    6565
     
    6868} WM_Slot;
    6969
     70//! This is a special class, that can handle many different Weapons of a ship/man/whatever.
     71/**
     72 * this class is designed to interactively changeing multiple weapons (or just one),
     73 * and to allow the Weapon itself to enable/disable itself.
     74 *
     75 * How to configure
     76 * 1. set the default values.
     77 * 2. define weapons. connect them to the WeaponManager's configurations
     78 * 3. go on and run :)....
     79 */
    7080class WeaponManager : public BaseObject {
    7181  public:
    72     WeaponManager(unsigned int slotCount);
     82    WeaponManager(PNode* parent);
    7383    WeaponManager(const TiXmlElement* root);
    7484    ~WeaponManager();
     
    8191    void setSlotPosition(int slot, const Vector& position);
    8292    void setSlotCapability(long slotCapability);
     93    void setParent(PNode* parent);
    8394
    8495    void addWeapon(Weapon* weapon, int configID = -1, int slotID = -1);
Note: See TracChangeset for help on using the changeset viewer.