Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 10376 in orxonox.OLD for trunk/src/world_entities/npcs


Ignore:
Timestamp:
Jan 26, 2007, 12:17:26 AM (18 years ago)
Author:
patrick
Message:

merged branche ai to trunk

Location:
trunk/src/world_entities/npcs
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/world_entities/npcs/npc.cc

    r9869 r10376  
    1818
    1919
     20#include "movement_module.h"
     21#include "ai_module.h"
     22#include "ai_team.h"
     23#include "ai_swarm.h"
     24#include "ai_engine.h"
     25
     26#include "player.h"
     27#include "playable.h"
     28
     29#include "weapons/test_gun.h"
     30#include "weapons/turret.h"
     31#include "weapons/cannon.h"
     32
     33#include "loading/factory.h"
     34#include "debug.h"
     35#include "loading/load_param.h"
     36
     37
    2038#include "npc.h"
    2139
    2240ObjectListDefinition(NPC);
     41CREATE_FACTORY(NPC);
     42
    2343
    2444NPC::NPC(const TiXmlElement* root)
     45  : weaponMan(this)
    2546{
    2647  this->registerObject(this, NPC::_objectList);
    2748
    28   this->toList(OM_GROUP_00);
    29 
    30 }
    31 
    32 
    33 NPC::~NPC () {}
    34 
    35 
    36 
    37 /**
    38  * adds an AI to this NPC
    39  */
    40 void NPC::addAI(AI* ai)
    41 {}
     49  this->toList(OM_GROUP_01);
     50
     51  if( root != NULL)
     52          this->loadParams(root);
     53
     54  std::cout << "Team Number: " << teamNumber << "\n";
     55  std::cout << "Swarm Number:" << swarmNumber << "\n";
     56
     57  AIEngine::getInstance()->addAI(teamNumber,swarmNumber,(WorldEntity*)this,maxSpeed,attackDistance);
     58
     59  this->bFire = false;
     60
     61
     62    // create the weapons and their manager
     63
     64
     65  this->getWeaponManager().changeWeaponConfig(1);
     66  Weapon* wpRight = new TestGun(0);
     67  wpRight->setName("testGun Right");
     68  Weapon* wpLeft = new TestGun(1);
     69  wpLeft->setName("testGun Left");
     70
     71  wpRight->toList( this->getOMListNumber());
     72  wpLeft->toList( this->getOMListNumber());
     73
     74
     75  this->addWeapon(wpLeft, 1, 0);
     76  this->addWeapon(wpRight,1 ,1);
     77
     78  wpLeft->increaseEnergy( 100);
     79  wpRight->increaseEnergy( 100);
     80
     81  this->setHealthMax(100);
     82  this->setHealth(80);
     83
     84  this->getWeaponManager().setSlotCount(7);
     85
     86  this->getWeaponManager().setSlotPosition(0, Vector(-2.6, .1, -3.0));
     87  this->getWeaponManager().setSlotCapability(0, WTYPE_ALLDIRS | WTYPE_DIRECTIONAL);
     88
     89  this->getWeaponManager().setSlotPosition(1, Vector(-2.6, .1, 3.0));
     90  this->getWeaponManager().setSlotCapability(1, WTYPE_ALLDIRS | WTYPE_DIRECTIONAL);
     91
     92  this->getWeaponManager().setSlotPosition(2, Vector(-1.5, .5, -.5));
     93  this->getWeaponManager().setSlotDirection(2, Quaternion(-M_PI_4*.5, Vector(1,0,0)));
     94
     95  this->getWeaponManager().setSlotPosition(3, Vector(-1.5, .5, .5));
     96  this->getWeaponManager().setSlotDirection(3, Quaternion(M_PI_4*.5, Vector(1,0,0)));
     97
     98  this->getWeaponManager().setSlotPosition(4, Vector(-1.5, -.5, .5));
     99  this->getWeaponManager().setSlotDirection(4, Quaternion(-M_PI_4*.5+M_PI, Vector(1,0,0)));
     100
     101  this->getWeaponManager().setSlotPosition(5, Vector(-1.5, -.5, -.5));
     102  this->getWeaponManager().setSlotDirection(5, Quaternion(+M_PI_4*.5-M_PI, Vector(1,0,0)));
     103
     104  this->getWeaponManager().setSlotPosition(6, Vector(-1, 0.0, 0));
     105  this->getWeaponManager().setSlotCapability(6, WTYPE_ALLDIRS | WTYPE_DIRECTIONAL);
     106
     107  this->getWeaponManager().getFixedTarget()->setParent(this);
     108  this->getWeaponManager().getFixedTarget()->setRelCoor(100000,0,0);
     109
     110}
     111
     112
     113NPC::~NPC ()
     114{
     115  AIEngine::getInstance()->removeAI(teamNumber,swarmNumber,(WorldEntity*)this);
     116}
    42117
    43118
     
    50125{
    51126   WorldEntity::loadParams(root);
    52 }
    53 
     127
     128  LoadParam(root, "team", this, NPC, setTeamNumber)
     129  .describe("this sets the team number")
     130  .defaultValues(0);
     131
     132  LoadParam(root, "swarm", this, NPC, setSwarmNumber)
     133  .describe("this sets the swarm number")
     134  .defaultValues(0);
     135
     136  LoadParam(root, "maxSpeed", this, NPC, setMaxSpeed)
     137  .describe("this sets the NPC max Speed")
     138  .defaultValues(0);
     139
     140  LoadParam(root, "attackDistance", this, NPC, setAttackDistance)
     141  .describe("this sets the NPC distance to target")
     142  .defaultValues(0);
     143}
     144
     145
     146/**
     147 * @brief adds a Weapon to the NPC.
     148 * @param weapon the Weapon to add.
     149 * @param configID the Configuration ID to add this weapon to.
     150 * @param slotID the slotID to add the Weapon to.
     151 */
     152bool NPC::addWeapon(Weapon* weapon, int configID, int slotID)
     153{
     154  weapon->setOwner(this->getOwner());
     155
     156
     157  if(this->weaponMan.addWeapon(weapon, configID, slotID))
     158  {
     159    return true;
     160  }
     161  else
     162  {
     163    if (weapon != NULL)
     164      PRINTF(2)("Unable to add Weapon (%s::%s) to %s::%s\n",
     165                weapon->getClassCName(), weapon->getCName(), this->getClassCName(), this->getCName());
     166    else
     167      PRINTF(2)("No weapon defined\n");
     168    return false;
     169
     170  }
     171}
     172
     173/**
     174 * @brief removes a Weapon.
     175 * @param weapon the Weapon to remove.
     176 */
     177void NPC::removeWeapon(Weapon* weapon)
     178{
     179  this->weaponMan.removeWeapon(weapon);
     180
     181}
     182
     183/**
     184 * @brief jumps to the next WeaponConfiguration
     185 */
     186void NPC::nextWeaponConfig()
     187{
     188  this->weaponMan.nextWeaponConfig();
     189}
     190
     191/**
     192 * @brief moves to the last WeaponConfiguration
     193 */
     194void NPC::previousWeaponConfig()
     195{
     196  this->weaponMan.previousWeaponConfig();
     197}
     198
     199
     200
     201
     202/**
     203 * ticking
     204 * @param dt  time since last tick
     205 */
     206void NPC::tick(float dt)
     207{
     208        //std::cout << "fire..\n";
     209  this->weaponMan.tick(dt);
     210  if (this->bFire)
     211    weaponMan.fire();
     212  this->bFire = false;
     213}
  • trunk/src/world_entities/npcs/npc.h

    r9869 r10376  
    44
    55#include "world_entity.h"
     6#include "ai_module.h"
     7#include "world_entities/weapons/weapon_manager.h"
    68
    79class AI;
    810
    9 class NPC : public WorldEntity {
     11class NPC : public WorldEntity
     12{
    1013  ObjectListDeclaration(NPC);
    11  public:
    12    NPC (const TiXmlElement* root);
     14
     15public:
     16  NPC(const TiXmlElement* root = NULL);
    1317  virtual ~NPC ();
    1418
    15   virtual void loadParams(const TiXmlElement* root = NULL);
     19  virtual void loadParams(const TiXmlElement* root);
    1620
    17   void addAI(AI* ai);
    1821
     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
     29  virtual void tick(float dt);
     30  inline int getTeam()  { return teamNumber; }
     31  inline void fire(){ this->bFire=true;}
     32
     33
     34
     35private:
     36  inline void setTeamNumber(int number) { teamNumber=number; }
     37  inline void setSwarmNumber(int number) { swarmNumber=number; }
     38  inline void setMaxSpeed(float number) { maxSpeed=number; }
     39  inline void setAttackDistance(float number) { attackDistance=number; }
    1940
    2041 private:
    2142
     43  int                   teamNumber;   //!< number of the team
     44  int                   swarmNumber;  //!< number of the swarm
     45  int                   difficulty;   //!< difficulty
     46  float                                         maxSpeed;
     47  float                                         attackDistance;
     48
     49  WeaponManager         weaponMan;    //!< weapon manager
     50  bool                  bFire;        //!< fire
     51
     52  AIModule*             aiModule;
    2253};
    2354
  • trunk/src/world_entities/npcs/npc_test.cc

    r10147 r10376  
    1919
    2020#include "npc_test.h"
    21 #include "obb_tree.h"
     21#include <stdio.h>
    2222
    23 #include "shader.h"
    2423#include "state.h"
    2524#include "debug.h"
     
    2827#include "loading/load_param.h"
    2928
    30 #include "effects/explosion.h"
     29#include "md2/md2Model.h"
     30#include "player.h"
     31#include "playable.h"
     32
     33#include "weapons/test_gun.h"
     34#include "weapons/turret.h"
     35#include "weapons/cannon.h"
    3136
    3237
     
    3439CREATE_FACTORY(NPC2);
    3540
     41
    3642NPC2::NPC2(const TiXmlElement* root)
    37   : NPC(NULL)
    3843{
    3944  this->registerObject(this, NPC2::_objectList);
    4045
    41 //   if ((float)rand()/RAND_MAX > .5f)
    42 //     this->loadModel("models/ships/bolido.obj", 6);
    43 //   else
    44 //     this->loadModel("models/ships/gobblin.obj", 6);
     46  if (root != NULL)
     47    this->loadParams(root);
    4548
    4649
     50  // create the weapons and their manager
    4751
    4852
    49   this->shader = NULL;
    50 //  if (likely(Shader::checkShaderAbility()))
    51     //this->shader = Shader::getShader("shaders/toon.vert", "shaders/toon.frag");
     53  this->getWeaponManager().changeWeaponConfig(1);
     54  Weapon* wpRight = new TestGun(0);
     55  wpRight->setName("testGun Right");
     56  Weapon* wpLeft = new TestGun(1);
     57  wpLeft->setName("testGun Left");
    5258
    53   this->randomRotAxis = VECTOR_RAND(1);
     59  this->addWeapon(wpLeft, 1, 0);
     60  this->addWeapon(wpRight,1 ,1);
    5461
    55   if (root != NULL)
    56     this->loadParams(root);
     62  this->setHealthMax(100);
     63  this->setHealth(80);
     64
     65  this->getWeaponManager().setSlotCount(7);
     66
     67  this->getWeaponManager().setSlotPosition(0, Vector(-2.6, .1, -3.0));
     68  this->getWeaponManager().setSlotCapability(0, WTYPE_ALLDIRS | WTYPE_DIRECTIONAL);
     69
     70  this->getWeaponManager().setSlotPosition(1, Vector(-2.6, .1, 3.0));
     71  this->getWeaponManager().setSlotCapability(1, WTYPE_ALLDIRS | WTYPE_DIRECTIONAL);
     72
     73  this->getWeaponManager().setSlotPosition(2, Vector(-1.5, .5, -.5));
     74  this->getWeaponManager().setSlotDirection(2, Quaternion(-M_PI_4*.5, Vector(1,0,0)));
     75
     76  this->getWeaponManager().setSlotPosition(3, Vector(-1.5, .5, .5));
     77  this->getWeaponManager().setSlotDirection(3, Quaternion(M_PI_4*.5, Vector(1,0,0)));
     78
     79  this->getWeaponManager().setSlotPosition(4, Vector(-1.5, -.5, .5));
     80  this->getWeaponManager().setSlotDirection(4, Quaternion(-M_PI_4*.5+M_PI, Vector(1,0,0)));
     81
     82  this->getWeaponManager().setSlotPosition(5, Vector(-1.5, -.5, -.5));
     83  this->getWeaponManager().setSlotDirection(5, Quaternion(+M_PI_4*.5-M_PI, Vector(1,0,0)));
     84
     85  this->getWeaponManager().setSlotPosition(6, Vector(-1, 0.0, 0));
     86  this->getWeaponManager().setSlotCapability(6, WTYPE_ALLDIRS | WTYPE_DIRECTIONAL);
     87
     88  this->getWeaponManager().getFixedTarget()->setParent(this);
     89  this->getWeaponManager().getFixedTarget()->setRelCoor(100000,0,0);
     90
    5791}
    5892
    59 
    60 NPC2::~NPC2 ()
    61 {}
    62 
     93NPC2::~NPC2()
     94{
     95}
    6396
    6497void NPC2::loadParams(const TiXmlElement* root)
     
    69102
    70103
    71 void NPC2::destroy(WorldEntity* killer)
     104
     105void NPC2::tick(float dt)
    72106{
    73   Explosion::explode(this, Vector(10,10,10));
    74   this->toList(OM_DEAD);
    75107
     108
     109
     110
     111  // animating the md2 model
     112  if( likely(this->getModel(0) != NULL) && this->getModel(0)->isA(MD2Model::staticClassID()))
     113    ((MD2Model*)this->getModel(0))->tick(dt);
    76114}
    77115
    78116
    79117
    80 /**
    81  *  the entity is drawn onto the screen with this function
    82  *
    83  * This is a central function of an entity: call it to let the entity painted to the screen.
    84  * Just override this function with whatever you want to be drawn.
    85  */
    86 // void NPC2::draw() const
    87 // {
    88 //   glMatrixMode(GL_MODELVIEW);
    89 //   glPushMatrix();
    90 //   float matrix[4][4];
    91 //
    92 //   /* translate */
    93 //   glTranslatef (this->getAbsCoor ().x,
    94 //                 this->getAbsCoor ().y,
    95 //                 this->getAbsCoor ().z);
    96 //   /* rotate */
    97 //   this->getAbsDir ().matrix (matrix);
    98 //   glMultMatrixf((float*)matrix);
    99 //
    100 // //   if (this->shader != NULL && this->shader != Shader::getActiveShader())
    101 // //     shader->activateShader();
    102 //
    103 //   if( this->getModel())
    104 //     this->getModel()->draw();
    105 // //   shader->deactivateShader();
    106 //
    107 //
    108 // /*  if (this->model)
    109 //     this->model->draw();*/
    110 //   glPopMatrix();
    111 // }
    112 
    113 
    114 void NPC2::tick(float dt)
    115 {
    116 //  Vector direction = (State::getCameraTarget()->getAbsCoor() - this->getAbsCoor());
    117 
    118   //if (directin.len() < 100)
    119 //  this->shiftCoor(direction *dt * 5 * exp(-direction.len() / 30.0));
    120 //  this->shiftDir(Quaternion(dt, this->randomRotAxis));
    121 
    122 }
    123 
    124 
    125 
  • trunk/src/world_entities/npcs/npc_test.h

    r10147 r10376  
    55#include "npc.h"
    66
     7
     8
    79class AI;
    810class Shader;
     11class AIModule;
    912
    10 class NPC2 : public NPC {
     13class NPC2 : public NPC
     14{
    1115  ObjectListDeclaration(NPC2);
    1216
    13  public:
     17public:
    1418  NPC2 (const TiXmlElement* root);
    1519  virtual ~NPC2 ();
     20  virtual void loadParams(const TiXmlElement* root);
     21  virtual void tick(float dt);
    1622
    17   virtual void loadParams(const TiXmlElement* root);
    1823
    19   void addAI(AI* ai);
    2024
    21   virtual void destroy(WorldEntity* killer);
    2225
    23   virtual void tick(float dt);
    24 //   virtual void draw() const;
     26private:
    2527
    26  private:
    27    Vector   randomRotAxis;
    28    Shader*  shader;
    2928};
    3029
Note: See TracChangeset for help on using the changeset viewer.