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