Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 10268 in orxonox.OLD for branches/ai/src


Ignore:
Timestamp:
Jan 17, 2007, 5:15:00 PM (18 years ago)
Author:
patrick
Message:

now npcs should be able to shoot

Location:
branches/ai/src/world_entities/npcs
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/ai/src/world_entities/npcs/npc.cc

    r10263 r10268  
    2323#include "ai_swarm.h"
    2424#include "ai_engine.h"
     25
     26#include "debug.h"
    2527
    2628#include "loading/load_param.h"
     
    7476
    7577
     78/**
     79 * @brief adds a Weapon to the NPC.
     80 * @param weapon the Weapon to add.
     81 * @param configID the Configuration ID to add this weapon to.
     82 * @param slotID the slotID to add the Weapon to.
     83 */
     84bool NPC::addWeapon(Weapon* weapon, int configID, int slotID)
     85{
     86  weapon->setOwner(this->getOwner());
     87
     88
     89  if(this->weaponMan.addWeapon(weapon, configID, slotID))
     90  {
     91    return true;
     92  }
     93  else
     94  {
     95    if (weapon != NULL)
     96      PRINTF(2)("Unable to add Weapon (%s::%s) to %s::%s\n",
     97                weapon->getClassCName(), weapon->getCName(), this->getClassCName(), this->getCName());
     98    else
     99      PRINTF(2)("No weapon defined\n");
     100    return false;
     101
     102  }
     103}
     104
     105/**
     106 * @brief removes a Weapon.
     107 * @param weapon the Weapon to remove.
     108 */
     109void NPC::removeWeapon(Weapon* weapon)
     110{
     111  this->weaponMan.removeWeapon(weapon);
     112
     113}
     114
     115/**
     116 * @brief jumps to the next WeaponConfiguration
     117 */
     118void NPC::nextWeaponConfig()
     119{
     120  this->weaponMan.nextWeaponConfig();
     121}
     122
     123/**
     124 * @brief moves to the last WeaponConfiguration
     125 */
     126void NPC::previousWeaponConfig()
     127{
     128  this->weaponMan.previousWeaponConfig();
     129}
     130
     131
     132
     133
     134/**
     135 * ticking
     136 * @param dt  time since last tick
     137 */
    76138void NPC::tick(float dt)
    77139{
     
    79141  if (this->bFire)
    80142    weaponMan.fire();
     143  this->bFire = false;
    81144}
  • branches/ai/src/world_entities/npcs/npc.h

    r10263 r10268  
    1919  virtual void loadParams(const TiXmlElement* root = NULL);
    2020
     21
     22  bool addWeapon(Weapon* weapon, int configID = -1, int slotID = -1);
     23  void removeWeapon(Weapon* weapon);
     24  void nextWeaponConfig();
     25  void previousWeaponConfig();
     26  inline WeaponManager& getWeaponManager() { return this->weaponMan; };
     27
     28
    2129  virtual void tick(float dt);
    2230  inline int getTeam()  { return teamNumber; }
     31
     32  inline void fire() { this->bFire = true; }
    2333
    2434
  • branches/ai/src/world_entities/npcs/npc_test.cc

    r10263 r10268  
    3131#include "playable.h"
    3232
     33#include "weapons/test_gun.h"
     34#include "weapons/turret.h"
     35#include "weapons/cannon.h"
     36
     37
    3338#include "class_id_DEPRECATED.h"
    3439
     
    4550    this->loadParams(root);
    4651
     52  Weapon* wpRight = new TestGun(0);
     53  wpRight->setName("testGun Right");
     54  Weapon* wpLeft = new TestGun(1);
     55  wpLeft->setName("testGun Left");
     56  //Weapon* cannon = dynamic_cast<Weapon*>(Factory::fabricate(CL_CANNON));
    4757
     58  //cannon->setName("BFG");
     59
     60  this->addWeapon(wpLeft, 1, 0);
     61  this->addWeapon(wpRight,1 ,1);
     62  //this->addWeapon(cannon, 0, 6);
     63
     64  this->getWeaponManager().changeWeaponConfig(1);
    4865  // create the weapons and their manager
     66
     67  this->setHealthMax(100);
     68  this->setHealth(80);
     69
     70  this->getWeaponManager().setSlotCount(7);
     71
     72  this->getWeaponManager().setSlotPosition(0, Vector(-2.6, .1, -3.0));
     73  this->getWeaponManager().setSlotCapability(0, WTYPE_ALLDIRS | WTYPE_DIRECTIONAL);
     74
     75  this->getWeaponManager().setSlotPosition(1, Vector(-2.6, .1, 3.0));
     76  this->getWeaponManager().setSlotCapability(1, WTYPE_ALLDIRS | WTYPE_DIRECTIONAL);
     77
     78  this->getWeaponManager().setSlotPosition(2, Vector(-1.5, .5, -.5));
     79  this->getWeaponManager().setSlotDirection(2, Quaternion(-M_PI_4*.5, Vector(1,0,0)));
     80
     81  this->getWeaponManager().setSlotPosition(3, Vector(-1.5, .5, .5));
     82  this->getWeaponManager().setSlotDirection(3, Quaternion(M_PI_4*.5, Vector(1,0,0)));
     83
     84  this->getWeaponManager().setSlotPosition(4, Vector(-1.5, -.5, .5));
     85  this->getWeaponManager().setSlotDirection(4, Quaternion(-M_PI_4*.5+M_PI, Vector(1,0,0)));
     86
     87  this->getWeaponManager().setSlotPosition(5, Vector(-1.5, -.5, -.5));
     88  this->getWeaponManager().setSlotDirection(5, Quaternion(+M_PI_4*.5-M_PI, Vector(1,0,0)));
     89  //
     90  this->getWeaponManager().setSlotPosition(6, Vector(-1, 0.0, 0));
     91  this->getWeaponManager().setSlotCapability(6, WTYPE_ALLDIRS | WTYPE_DIRECTIONAL);
     92  //
     93  //   this->getWeaponManager().setSlotPosition(8, Vector(-2.5, -0.3, -2.0));
     94  //   this->getWeaponManager().setSlotDirection(8, Quaternion(-M_PI, Vector(1,0,0)));
     95  //
     96  //   this->getWeaponManager().setSlotPosition(9, Vector(-2.5, -0.3, 2.0));
     97  //   this->getWeaponManager().setSlotDirection(9, Quaternion(+M_PI, Vector(1,0,0)));:
     98
     99  this->getWeaponManager().getFixedTarget()->setParent(this);
     100  this->getWeaponManager().getFixedTarget()->setRelCoor(100000,0,0);
    49101
    50102}
Note: See TracChangeset for help on using the changeset viewer.