Changeset 10376 in orxonox.OLD for trunk/src/world_entities/npcs/npc.cc
- Timestamp:
- Jan 26, 2007, 12:17:26 AM (17 years ago)
- File:
-
- 1 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 }
Note: See TracChangeset
for help on using the changeset viewer.