Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/world_entities/npcs/npc.cc @ 10383

Last change on this file since 10383 was 10376, checked in by patrick, 18 years ago

merged branche ai to trunk

File size: 5.0 KB
RevLine 
[1853]1
2
[4597]3/*
[1853]4   orxonox - the future of 3D-vertical-scrollers
5
6   Copyright (C) 2004 orx
7
8   This program is free software; you can redistribute it and/or modify
9   it under the terms of the GNU General Public License as published by
10   the Free Software Foundation; either version 2, or (at your option)
11   any later version.
[1855]12
13   ### File Specific:
14   main-programmer: Patrick Boenzli
15   co-programmer:
[1853]16*/
[5357]17#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WORLD_ENTITY
[1853]18
19
[10376]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
[1853]38#include "npc.h"
39
[9869]40ObjectListDefinition(NPC);
[10376]41CREATE_FACTORY(NPC);
[4984]42
[10376]43
[8724]44NPC::NPC(const TiXmlElement* root)
[10376]45  : weaponMan(this)
[1931]46{
[9869]47  this->registerObject(this, NPC::_objectList);
[8724]48
[10376]49  this->toList(OM_GROUP_01);
[9003]50
[10376]51  if( root != NULL)
52          this->loadParams(root);
[1853]53
[10376]54  std::cout << "Team Number: " << teamNumber << "\n";
55  std::cout << "Swarm Number:" << swarmNumber << "\n";
[5034]56
[10376]57  AIEngine::getInstance()->addAI(teamNumber,swarmNumber,(WorldEntity*)this,maxSpeed,attackDistance);
[1853]58
[10376]59  this->bFire = false;
[1853]60
[7076]61
[10376]62    // create the weapons and their manager
[7076]63
[5451]64
[10376]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");
[7076]70
[10376]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}
117
118
119
[8724]120/**
121 * loads the xml tags
122 * @param root: root xml tag for this element
123 */
124void NPC::loadParams(const TiXmlElement* root)
125{
[8894]126   WorldEntity::loadParams(root);
[10376]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);
[1931]143}
[8724]144
[10376]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}
Note: See TracBrowser for help on using the repository browser.