Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 10268 was 10268, checked in by patrick, 17 years ago

now npcs should be able to shoot

File size: 2.8 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 "debug.h"
27
28#include "loading/load_param.h"
29
30
31#include "npc.h"
32
33ObjectListDefinition(NPC);
34
35NPC::NPC(const TiXmlElement* root)
36  : weaponMan(this)
37{
38  this->registerObject(this, NPC::_objectList);
39
40  this->toList(OM_GROUP_00);
41
42  std::cout << "Team Number: " << teamNumber << "\n";
43  std::cout << "Swarm Number:" << swarmNumber << "\n";
44  //aiModule=new MovementModule(this);
45  //AIEngine::getInstance()->addAI(teamNumber,swarmNumber,aiModule);
46  AIEngine::getInstance()->addAI(teamNumber,swarmNumber,(WorldEntity*)this);
47
48  this->bFire = false;
49
50}
51
52
53NPC::~NPC ()
54{
55  AIEngine::getInstance()->removeAI(teamNumber,swarmNumber,(WorldEntity*)this);
56}
57
58
59
60/**
61 * loads the xml tags
62 * @param root: root xml tag for this element
63 */
64void NPC::loadParams(const TiXmlElement* root)
65{
66   WorldEntity::loadParams(root);
67
68  LoadParam(root, "team", this, NPC, setTeamNumber)
69  .describe("this sets the team number")
70  .defaultValues(0);
71
72  LoadParam(root, "swarm", this, NPC, setSwarmNumber)
73  .describe("this sets the swarm number")
74  .defaultValues(0);
75}
76
77
78/**
79 * @brief adds a Weapon to the NPC.
80 * @param weapon the Weapon to add.
81 * @param configID the Configuration ID to add this weapon to.
82 * @param slotID the slotID to add the Weapon to.
83 */
84bool NPC::addWeapon(Weapon* weapon, int configID, int slotID)
85{
86  weapon->setOwner(this->getOwner());
87
88
89  if(this->weaponMan.addWeapon(weapon, configID, slotID))
90  {
91    return true;
92  }
93  else
94  {
95    if (weapon != NULL)
96      PRINTF(2)("Unable to add Weapon (%s::%s) to %s::%s\n",
97                weapon->getClassCName(), weapon->getCName(), this->getClassCName(), this->getCName());
98    else
99      PRINTF(2)("No weapon defined\n");
100    return false;
101
102  }
103}
104
105/**
106 * @brief removes a Weapon.
107 * @param weapon the Weapon to remove.
108 */
109void NPC::removeWeapon(Weapon* weapon)
110{
111  this->weaponMan.removeWeapon(weapon);
112
113}
114
115/**
116 * @brief jumps to the next WeaponConfiguration
117 */
118void NPC::nextWeaponConfig()
119{
120  this->weaponMan.nextWeaponConfig();
121}
122
123/**
124 * @brief moves to the last WeaponConfiguration
125 */
126void NPC::previousWeaponConfig()
127{
128  this->weaponMan.previousWeaponConfig();
129}
130
131
132
133
134/**
135 * ticking
136 * @param dt  time since last tick
137 */
138void NPC::tick(float dt)
139{
140  this->weaponMan.tick(dt);
141  if (this->bFire)
142    weaponMan.fire();
143  this->bFire = false;
144}
Note: See TracBrowser for help on using the repository browser.