Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 10439 was 10439, checked in by snellen, 17 years ago

npc is now trackable

File size: 6.2 KB
Line 
1
2
3/*
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.
12
13   ### File Specific:
14   main-programmer: Patrick Boenzli
15   co-programmer:
16*/
17#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WORLD_ENTITY
18
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#include "track/track.h"
37
38
39#include "npc.h"
40
41ObjectListDefinition(NPC);
42CREATE_FACTORY(NPC);
43
44
45#include "script_class.h"
46CREATE_SCRIPTABLE_CLASS(NPC,
47                        addMethod("getAbsCoorX", Executor0ret<PNode, lua_State*, float>(&PNode::getAbsCoorX))
48                        ->addMethod("getAbsCoorY", Executor0ret<PNode, lua_State*, float>(&PNode::getAbsCoorY))
49                        ->addMethod("getAbsCoorZ", Executor0ret<PNode, lua_State*, float>(&PNode::getAbsCoorZ))
50                        ->addMethod("setAbsCoor", Executor3<PNode, lua_State*,float,float,float>(&PNode::setAbsCoor))
51                        ->addMethod("setAbsDir", Executor4<PNode, lua_State*,float,float,float,float>(&PNode::setAbsDir))
52                       );
53
54NPC::NPC(const TiXmlElement* root)
55  : weaponMan(this)
56{
57  this->registerObject(this, NPC::_objectList);
58
59  this->toList(OM_GROUP_01);
60
61  if( root != NULL)
62          this->loadParams(root);
63
64  std::cout << "Team Number: " << teamNumber << "\n";
65  std::cout << "Swarm Number:" << swarmNumber << "\n";
66
67//add to track
68  if(this->entityTrack)
69    this->setParent(this->entityTrack->getTrackNode());
70  else
71  AIEngine::getInstance()->addAI(teamNumber,swarmNumber,(WorldEntity*)this,maxSpeed,attackDistance);
72
73  this->bFire = false;
74
75
76    // create the weapons and their manager
77
78
79  this->getWeaponManager().changeWeaponConfig(1);
80//   Weapon* wpRight = new TestGun(0);
81//   wpRight->setName("testGun Right");
82//   Weapon* wpLeft = new TestGun(1);
83//   wpLeft->setName("testGun Left");
84//
85//   wpRight->toList( this->getOMListNumber());
86//   wpLeft->toList( this->getOMListNumber());
87//
88//
89//   this->addWeapon(wpLeft, 1, 0);
90//   this->addWeapon(wpRight,1 ,1);
91//
92//   wpLeft->increaseEnergy( 100);
93//   wpRight->increaseEnergy( 100);
94
95  this->setHealthMax(100);
96  this->setHealth(80);
97
98//   this->getWeaponManager().setSlotCount(7);
99//
100//   this->getWeaponManager().setSlotPosition(0, Vector(-2.6, .1, -3.0));
101//   this->getWeaponManager().setSlotCapability(0, WTYPE_ALLDIRS | WTYPE_DIRECTIONAL);
102//
103//   this->getWeaponManager().setSlotPosition(1, Vector(-2.6, .1, 3.0));
104//   this->getWeaponManager().setSlotCapability(1, WTYPE_ALLDIRS | WTYPE_DIRECTIONAL);
105//
106//   this->getWeaponManager().setSlotPosition(2, Vector(-1.5, .5, -.5));
107//   this->getWeaponManager().setSlotDirection(2, Quaternion(-M_PI_4*.5, Vector(1,0,0)));
108//
109//   this->getWeaponManager().setSlotPosition(3, Vector(-1.5, .5, .5));
110//   this->getWeaponManager().setSlotDirection(3, Quaternion(M_PI_4*.5, Vector(1,0,0)));
111//
112//   this->getWeaponManager().setSlotPosition(4, Vector(-1.5, -.5, .5));
113//   this->getWeaponManager().setSlotDirection(4, Quaternion(-M_PI_4*.5+M_PI, Vector(1,0,0)));
114//
115//   this->getWeaponManager().setSlotPosition(5, Vector(-1.5, -.5, -.5));
116//   this->getWeaponManager().setSlotDirection(5, Quaternion(+M_PI_4*.5-M_PI, Vector(1,0,0)));
117//
118//   this->getWeaponManager().setSlotPosition(6, Vector(-1, 0.0, 0));
119//   this->getWeaponManager().setSlotCapability(6, WTYPE_ALLDIRS | WTYPE_DIRECTIONAL);
120//
121//   this->getWeaponManager().getFixedTarget()->setParent(this);
122//   this->getWeaponManager().getFixedTarget()->setRelCoor(100000,0,0);
123
124
125 
126
127}
128
129
130NPC::~NPC ()
131{
132 if(! this->entityTrack)
133  AIEngine::getInstance()->removeAI(teamNumber,swarmNumber,(WorldEntity*)this);
134}
135
136
137
138/**
139 * loads the xml tags
140 * @param root: root xml tag for this element
141 */
142void NPC::loadParams(const TiXmlElement* root)
143{
144   WorldEntity::loadParams(root);
145
146  LoadParam(root, "team", this, NPC, setTeamNumber)
147  .describe("this sets the team number")
148  .defaultValues(0);
149
150  LoadParam(root, "swarm", this, NPC, setSwarmNumber)
151  .describe("this sets the swarm number")
152  .defaultValues(0);
153
154  LoadParam(root, "maxSpeed", this, NPC, setMaxSpeed)
155  .describe("this sets the NPC max Speed")
156  .defaultValues(0);
157
158  LoadParam(root, "attackDistance", this, NPC, setAttackDistance)
159  .describe("this sets the NPC distance to target")
160  .defaultValues(0);
161}
162
163
164/**
165 * @brief adds a Weapon to the NPC.
166 * @param weapon the Weapon to add.
167 * @param configID the Configuration ID to add this weapon to.
168 * @param slotID the slotID to add the Weapon to.
169 */
170bool NPC::addWeapon(Weapon* weapon, int configID, int slotID)
171{
172  weapon->setOwner(this->getOwner());
173
174
175  if(this->weaponMan.addWeapon(weapon, configID, slotID))
176  {
177    return true;
178  }
179  else
180  {
181    if (weapon != NULL)
182      PRINTF(2)("Unable to add Weapon (%s::%s) to %s::%s\n",
183                weapon->getClassCName(), weapon->getCName(), this->getClassCName(), this->getCName());
184    else
185      PRINTF(2)("No weapon defined\n");
186    return false;
187
188  }
189}
190
191/**
192 * @brief removes a Weapon.
193 * @param weapon the Weapon to remove.
194 */
195void NPC::removeWeapon(Weapon* weapon)
196{
197  this->weaponMan.removeWeapon(weapon);
198
199}
200
201/**
202 * @brief jumps to the next WeaponConfiguration
203 */
204void NPC::nextWeaponConfig()
205{
206  this->weaponMan.nextWeaponConfig();
207}
208
209/**
210 * @brief moves to the last WeaponConfiguration
211 */
212void NPC::previousWeaponConfig()
213{
214  this->weaponMan.previousWeaponConfig();
215}
216
217
218
219
220/**
221 * ticking
222 * @param dt  time since last tick
223 */
224void NPC::tick(float dt)
225{
226        //std::cout << "fire..\n";
227  this->weaponMan.tick(dt);
228  if (this->bFire)
229    weaponMan.fire();
230  this->bFire = false;
231
232 if(this->entityTrack)
233    this->entityTrack->tick(dt);
234
235}
Note: See TracBrowser for help on using the repository browser.