/* orxonox - the future of 3D-vertical-scrollers Copyright (C) 2004 orx This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. ### File Specific: main-programmer: Patrick Boenzli co-programmer: */ #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WORLD_ENTITY #include "movement_module.h" #include "ai_module.h" #include "ai_team.h" #include "ai_swarm.h" #include "ai_engine.h" #include "player.h" #include "playable.h" #include "weapons/test_gun.h" #include "weapons/turret.h" #include "weapons/cannon.h" #include "loading/factory.h" #include "debug.h" #include "loading/load_param.h" #include "npc.h" ObjectListDefinition(NPC); CREATE_FACTORY(NPC); NPC::NPC(const TiXmlElement* root) : weaponMan(this) { this->registerObject(this, NPC::_objectList); this->toList(OM_GROUP_01); if( root != NULL) this->loadParams(root); std::cout << "Team Number: " << teamNumber << "\n"; std::cout << "Swarm Number:" << swarmNumber << "\n"; AIEngine::getInstance()->addAI(teamNumber,swarmNumber,(WorldEntity*)this,maxSpeed,attackDistance); this->bFire = false; // create the weapons and their manager this->getWeaponManager().changeWeaponConfig(1); Weapon* wpRight = new TestGun(0); wpRight->setName("testGun Right"); Weapon* wpLeft = new TestGun(1); wpLeft->setName("testGun Left"); wpRight->toList( this->getOMListNumber()); wpLeft->toList( this->getOMListNumber()); this->addWeapon(wpLeft, 1, 0); this->addWeapon(wpRight,1 ,1); wpLeft->increaseEnergy( 100); wpRight->increaseEnergy( 100); this->setHealthMax(100); this->setHealth(80); this->getWeaponManager().setSlotCount(7); this->getWeaponManager().setSlotPosition(0, Vector(-2.6, .1, -3.0)); this->getWeaponManager().setSlotCapability(0, WTYPE_ALLDIRS | WTYPE_DIRECTIONAL); this->getWeaponManager().setSlotPosition(1, Vector(-2.6, .1, 3.0)); this->getWeaponManager().setSlotCapability(1, WTYPE_ALLDIRS | WTYPE_DIRECTIONAL); this->getWeaponManager().setSlotPosition(2, Vector(-1.5, .5, -.5)); this->getWeaponManager().setSlotDirection(2, Quaternion(-M_PI_4*.5, Vector(1,0,0))); this->getWeaponManager().setSlotPosition(3, Vector(-1.5, .5, .5)); this->getWeaponManager().setSlotDirection(3, Quaternion(M_PI_4*.5, Vector(1,0,0))); this->getWeaponManager().setSlotPosition(4, Vector(-1.5, -.5, .5)); this->getWeaponManager().setSlotDirection(4, Quaternion(-M_PI_4*.5+M_PI, Vector(1,0,0))); this->getWeaponManager().setSlotPosition(5, Vector(-1.5, -.5, -.5)); this->getWeaponManager().setSlotDirection(5, Quaternion(+M_PI_4*.5-M_PI, Vector(1,0,0))); this->getWeaponManager().setSlotPosition(6, Vector(-1, 0.0, 0)); this->getWeaponManager().setSlotCapability(6, WTYPE_ALLDIRS | WTYPE_DIRECTIONAL); this->getWeaponManager().getFixedTarget()->setParent(this); this->getWeaponManager().getFixedTarget()->setRelCoor(100000,0,0); } NPC::~NPC () { AIEngine::getInstance()->removeAI(teamNumber,swarmNumber,(WorldEntity*)this); } /** * loads the xml tags * @param root: root xml tag for this element */ void NPC::loadParams(const TiXmlElement* root) { WorldEntity::loadParams(root); LoadParam(root, "team", this, NPC, setTeamNumber) .describe("this sets the team number") .defaultValues(0); LoadParam(root, "swarm", this, NPC, setSwarmNumber) .describe("this sets the swarm number") .defaultValues(0); LoadParam(root, "maxSpeed", this, NPC, setMaxSpeed) .describe("this sets the NPC max Speed") .defaultValues(0); LoadParam(root, "attackDistance", this, NPC, setAttackDistance) .describe("this sets the NPC distance to target") .defaultValues(0); } /** * @brief adds a Weapon to the NPC. * @param weapon the Weapon to add. * @param configID the Configuration ID to add this weapon to. * @param slotID the slotID to add the Weapon to. */ bool NPC::addWeapon(Weapon* weapon, int configID, int slotID) { weapon->setOwner(this->getOwner()); if(this->weaponMan.addWeapon(weapon, configID, slotID)) { return true; } else { if (weapon != NULL) PRINTF(2)("Unable to add Weapon (%s::%s) to %s::%s\n", weapon->getClassCName(), weapon->getCName(), this->getClassCName(), this->getCName()); else PRINTF(2)("No weapon defined\n"); return false; } } /** * @brief removes a Weapon. * @param weapon the Weapon to remove. */ void NPC::removeWeapon(Weapon* weapon) { this->weaponMan.removeWeapon(weapon); } /** * @brief jumps to the next WeaponConfiguration */ void NPC::nextWeaponConfig() { this->weaponMan.nextWeaponConfig(); } /** * @brief moves to the last WeaponConfiguration */ void NPC::previousWeaponConfig() { this->weaponMan.previousWeaponConfig(); } /** * ticking * @param dt time since last tick */ void NPC::tick(float dt) { //std::cout << "fire..\n"; this->weaponMan.tick(dt); if (this->bFire) weaponMan.fire(); this->bFire = false; }