Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/ai/src/world_entities/npcs/npc.cc @ 10279

Last change on this file since 10279 was 10275, checked in by tfahrni, 19 years ago

npc can shoot

File size: 4.7 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
37
38#include "npc.h"
39
40ObjectListDefinition(NPC);
41CREATE_FACTORY(NPC);
42
43
44NPC::NPC(const TiXmlElement* root)
45  : weaponMan(this)
46{
47  this->registerObject(this, NPC::_objectList);
48
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);
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
113NPC::~NPC ()
114{
115  AIEngine::getInstance()->removeAI(teamNumber,swarmNumber,(WorldEntity*)this);
116}
117
118
119
120/**
121 * loads the xml tags
122 * @param root: root xml tag for this element
123 */
124void NPC::loadParams(const TiXmlElement* root)
125{
126   WorldEntity::loadParams(root);
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
137
138/**
139 * @brief adds a Weapon to the NPC.
140 * @param weapon the Weapon to add.
141 * @param configID the Configuration ID to add this weapon to.
142 * @param slotID the slotID to add the Weapon to.
143 */
144bool NPC::addWeapon(Weapon* weapon, int configID, int slotID)
145{
146  weapon->setOwner(this->getOwner());
147
148
149  if(this->weaponMan.addWeapon(weapon, configID, slotID))
150  {
151    return true;
152  }
153  else
154  {
155    if (weapon != NULL)
156      PRINTF(2)("Unable to add Weapon (%s::%s) to %s::%s\n",
157                weapon->getClassCName(), weapon->getCName(), this->getClassCName(), this->getCName());
158    else
159      PRINTF(2)("No weapon defined\n");
160    return false;
161
162  }
163}
164
165/**
166 * @brief removes a Weapon.
167 * @param weapon the Weapon to remove.
168 */
169void NPC::removeWeapon(Weapon* weapon)
170{
171  this->weaponMan.removeWeapon(weapon);
172
173}
174
175/**
176 * @brief jumps to the next WeaponConfiguration
177 */
178void NPC::nextWeaponConfig()
179{
180  this->weaponMan.nextWeaponConfig();
181}
182
183/**
184 * @brief moves to the last WeaponConfiguration
185 */
186void NPC::previousWeaponConfig()
187{
188  this->weaponMan.previousWeaponConfig();
189}
190
191
192
193
194/**
195 * ticking
196 * @param dt  time since last tick
197 */
198void NPC::tick(float dt)
199{
200        //std::cout << "fire..\n";
201  this->weaponMan.tick(dt);
202  if (this->bFire)
203    weaponMan.fire();
204  this->bFire = false;
205}
Note: See TracBrowser for help on using the repository browser.