Changeset 10376 in orxonox.OLD for trunk/src/world_entities
- Timestamp:
- Jan 26, 2007, 12:17:26 AM (18 years ago)
- Location:
- trunk/src/world_entities/npcs
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/world_entities/npcs/npc.cc
r9869 r10376 18 18 19 19 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 20 38 #include "npc.h" 21 39 22 40 ObjectListDefinition(NPC); 41 CREATE_FACTORY(NPC); 42 23 43 24 44 NPC::NPC(const TiXmlElement* root) 45 : weaponMan(this) 25 46 { 26 47 this->registerObject(this, NPC::_objectList); 27 48 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 113 NPC::~NPC () 114 { 115 AIEngine::getInstance()->removeAI(teamNumber,swarmNumber,(WorldEntity*)this); 116 } 42 117 43 118 … … 50 125 { 51 126 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 */ 152 bool 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 */ 177 void NPC::removeWeapon(Weapon* weapon) 178 { 179 this->weaponMan.removeWeapon(weapon); 180 181 } 182 183 /** 184 * @brief jumps to the next WeaponConfiguration 185 */ 186 void NPC::nextWeaponConfig() 187 { 188 this->weaponMan.nextWeaponConfig(); 189 } 190 191 /** 192 * @brief moves to the last WeaponConfiguration 193 */ 194 void NPC::previousWeaponConfig() 195 { 196 this->weaponMan.previousWeaponConfig(); 197 } 198 199 200 201 202 /** 203 * ticking 204 * @param dt time since last tick 205 */ 206 void 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 4 4 5 5 #include "world_entity.h" 6 #include "ai_module.h" 7 #include "world_entities/weapons/weapon_manager.h" 6 8 7 9 class AI; 8 10 9 class NPC : public WorldEntity { 11 class NPC : public WorldEntity 12 { 10 13 ObjectListDeclaration(NPC); 11 public: 12 NPC (const TiXmlElement* root); 14 15 public: 16 NPC(const TiXmlElement* root = NULL); 13 17 virtual ~NPC (); 14 18 15 virtual void loadParams(const TiXmlElement* root = NULL);19 virtual void loadParams(const TiXmlElement* root); 16 20 17 void addAI(AI* ai);18 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 29 virtual void tick(float dt); 30 inline int getTeam() { return teamNumber; } 31 inline void fire(){ this->bFire=true;} 32 33 34 35 private: 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; } 19 40 20 41 private: 21 42 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; 22 53 }; 23 54 -
trunk/src/world_entities/npcs/npc_test.cc
r10147 r10376 19 19 20 20 #include "npc_test.h" 21 #include "obb_tree.h"21 #include <stdio.h> 22 22 23 #include "shader.h"24 23 #include "state.h" 25 24 #include "debug.h" … … 28 27 #include "loading/load_param.h" 29 28 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" 31 36 32 37 … … 34 39 CREATE_FACTORY(NPC2); 35 40 41 36 42 NPC2::NPC2(const TiXmlElement* root) 37 : NPC(NULL)38 43 { 39 44 this->registerObject(this, NPC2::_objectList); 40 45 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); 45 48 46 49 50 // create the weapons and their manager 47 51 48 52 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"); 52 58 53 this->randomRotAxis = VECTOR_RAND(1); 59 this->addWeapon(wpLeft, 1, 0); 60 this->addWeapon(wpRight,1 ,1); 54 61 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 57 91 } 58 92 59 60 NPC2::~NPC2 () 61 {} 62 93 NPC2::~NPC2() 94 { 95 } 63 96 64 97 void NPC2::loadParams(const TiXmlElement* root) … … 69 102 70 103 71 void NPC2::destroy(WorldEntity* killer) 104 105 void NPC2::tick(float dt) 72 106 { 73 Explosion::explode(this, Vector(10,10,10));74 this->toList(OM_DEAD);75 107 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); 76 114 } 77 115 78 116 79 117 80 /**81 * the entity is drawn onto the screen with this function82 *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() const87 // {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 5 5 #include "npc.h" 6 6 7 8 7 9 class AI; 8 10 class Shader; 11 class AIModule; 9 12 10 class NPC2 : public NPC { 13 class NPC2 : public NPC 14 { 11 15 ObjectListDeclaration(NPC2); 12 16 13 17 public: 14 18 NPC2 (const TiXmlElement* root); 15 19 virtual ~NPC2 (); 20 virtual void loadParams(const TiXmlElement* root); 21 virtual void tick(float dt); 16 22 17 virtual void loadParams(const TiXmlElement* root);18 23 19 void addAI(AI* ai);20 24 21 virtual void destroy(WorldEntity* killer);22 25 23 virtual void tick(float dt); 24 // virtual void draw() const; 26 private: 25 27 26 private:27 Vector randomRotAxis;28 Shader* shader;29 28 }; 30 29
Note: See TracChangeset
for help on using the changeset viewer.