1 | |
---|
2 | /* ORXONOX - the hottest 3D action shooter ever to exist |
---|
3 | * > www.orxonox.net < |
---|
4 | * |
---|
5 | * |
---|
6 | * License notice: |
---|
7 | * |
---|
8 | * This program is free software; you can redistribute it and/or |
---|
9 | * modify it under the terms of the GNU General Public License |
---|
10 | * as published by the Free Software Foundation; either version 2 |
---|
11 | * of the License, or (at your option) any later version. |
---|
12 | * |
---|
13 | * This program is distributed in the hope that it will be useful, |
---|
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
16 | * GNU General Public License for more details. |
---|
17 | * |
---|
18 | * You should have received a copy of the GNU General Public License |
---|
19 | * along with this program; if not, write to the Free Software |
---|
20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
---|
21 | * |
---|
22 | * Author: |
---|
23 | * Fabian 'x3n' Landau |
---|
24 | * Co-authors: |
---|
25 | * Simon Miescher |
---|
26 | * |
---|
27 | */ |
---|
28 | |
---|
29 | /* |
---|
30 | |
---|
31 | * |
---|
32 | * |
---|
33 | * An asteroid which can be destroyed. Some smaller asteroids are created and a pickup |
---|
34 | * spawns. |
---|
35 | * |
---|
36 | * |
---|
37 | * |
---|
38 | |
---|
39 | */ |
---|
40 | |
---|
41 | /* |
---|
42 | Veraenderungstagebuch |
---|
43 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
---|
44 | |
---|
45 | FRAGEN: |
---|
46 | * Zeilen-Loeschung beim output |
---|
47 | * orxout()-Problem |
---|
48 | * dokumentieren mit @brief? |
---|
49 | * Warnumg aus Asteroidenzerstoerung |
---|
50 | |
---|
51 | |
---|
52 | KNACKPUNKTE: |
---|
53 | |
---|
54 | |
---|
55 | OFFEN: |
---|
56 | |
---|
57 | o Mass distribution -> weird for bigger asteroids |
---|
58 | --> more testing |
---|
59 | |
---|
60 | o SpicedAsteroidField fertigstellen, Mineraldichten-Parameter |
---|
61 | |
---|
62 | o Add custom pickup 'resources'. Weird template stuff -> Problems setting 'size' and other properties? setNumber of Resources. |
---|
63 | --> PickupTemplateName_ in PickupSpawner ist ein string. Wird via getBaseClassIdentifier ausgelesen, daraus wird ein Pickupable fabriziert. |
---|
64 | --> MunitionPickup erbt von Pickup erbt von collectiblePickup erbt von Pickupable |
---|
65 | ----> im MineralsPickup die isPickedUp()-Methode überschreiben? |
---|
66 | --> data_extern/images/effects: PNG's für die Pickups und GUI-Dinger. |
---|
67 | |
---|
68 | o inherit parent velocity |
---|
69 | o set collisionDamage? Just for static entities? |
---|
70 | o Dokumentieren mit @brief? |
---|
71 | |
---|
72 | o Explosion parts |
---|
73 | o custom HUD |
---|
74 | |
---|
75 | HANDBUCH: |
---|
76 | o im Level-File includes/pickups.oxi importieren. |
---|
77 | o Bei der XML-Variante wird beim ersten Aufruf der Tick-Methode ein neuer Asteroid generiert, |
---|
78 | damit die Groesse der Collision Shape korrekt initialisiert wird. |
---|
79 | |
---|
80 | FREMDANPASSUNGEN: |
---|
81 | Pickup-Zeug: |
---|
82 | o Pickup.h: Zugriffsänderung createSpawner |
---|
83 | o PickupSpawner.h: Zugriffsrechte setPickupTemplateName() und setMaxSpawnedItems() |
---|
84 | o PickupSpawner.h: In Tick() zwei Testbedingungen eingefuegt. |
---|
85 | o Pawn.h: Attribut acceptsPickups_ inklusive get/set. |
---|
86 | |
---|
87 | ERLEGT: |
---|
88 | o Rand() geht bis zu riesigen Nummern! |
---|
89 | o Pickupgenerierung: vgl. Fremdanpassungen. |
---|
90 | o Minimalbegrenzung fuer Masse vergessen. |
---|
91 | o Dynamische Definition -> putStuff-Methode, Werte noch nicht durchgesickert. |
---|
92 | o Error-Nachricht: Einfach Argumente leer lassen. |
---|
93 | o Pickups: setMaxSpawned funktioniert nicht -> Bastelloesung: Auf 2 statt eins setzen, erstes wird wohl direkt zerstoert. |
---|
94 | o setHealth: Wird mit Max verwurstelt, war 0. |
---|
95 | o Position nicht gesetzt -> alles im Ursprung, Kollision -> fliegt davon. |
---|
96 | o nimmt zuviel Schaden. -> wird mit maxHealth verwurstelt -> einfach auch setzen. |
---|
97 | |
---|
98 | o Groessenabhaengige Collison shape: Umweg ueber zweiten Konstruktor. |
---|
99 | o Absturz beim Asteroidengenerieren: Health war auf 0 gesetzt! Wurde nur bei der xml-Variante definiert. |
---|
100 | o Asteroiden fressen Pickups: Argument in Pawn, Test darauf in Tick() von PickupSpawner. |
---|
101 | o Man kann keine Arrays der Groesse 0 initialisieren, aber auch nicht per IF 2x definieren. |
---|
102 | o i++ einfach ganz verhindern, ++i stattdessen. |
---|
103 | o Discusting mixup with array length, accessing element a[len]... |
---|
104 | o unitialised mass value -> obese asteroid, physics bug. |
---|
105 | |
---|
106 | |
---|
107 | NOTIZEN: |
---|
108 | o SUPER entspricht ueberladen, andere Argumente der Methode. |
---|
109 | o Warnungsverhinderung anderswo: (void)pickedUp; // To avoid compiler warning. |
---|
110 | |
---|
111 | Was ist das? friend class Pickupable; |
---|
112 | |
---|
113 | |
---|
114 | |
---|
115 | */ |
---|
116 | |
---|
117 | |
---|
118 | #include "../../orxonox/worldentities/pawns/Pawn.h" |
---|
119 | #include "../../orxonox/worldentities/WorldEntity.h" |
---|
120 | |
---|
121 | #include "AsteroidMinable.h" |
---|
122 | |
---|
123 | #include <algorithm> |
---|
124 | |
---|
125 | #include "core/CoreIncludes.h" |
---|
126 | #include "core/GameMode.h" |
---|
127 | #include "core/XMLPort.h" |
---|
128 | #include "core/EventIncludes.h" |
---|
129 | #include "network/NetworkFunction.h" |
---|
130 | #include "util/Math.h" |
---|
131 | |
---|
132 | |
---|
133 | // #include "infos/PlayerInfo.h" |
---|
134 | // #include "controllers/Controller.h" |
---|
135 | // #include "gametypes/Gametype.h" |
---|
136 | // #include "graphics/ParticleSpawner.h" |
---|
137 | // #include "worldentities/ExplosionChunk.h" |
---|
138 | // #include "worldentities/ExplosionPart.h" |
---|
139 | |
---|
140 | // #include "core/object/ObjectListIterator.h" |
---|
141 | // #include "controllers/FormationController.h" |
---|
142 | |
---|
143 | #include "../pickup/items/HealthPickup.h" |
---|
144 | #include "../pickup/PickupSpawner.h" |
---|
145 | #include "../pickup/Pickup.h" |
---|
146 | //#include "../pickup/pickup ..... pickupable |
---|
147 | #include "../objects/collisionshapes/SphereCollisionShape.h" |
---|
148 | #include "../../orxonox/graphics/Model.h" |
---|
149 | |
---|
150 | |
---|
151 | |
---|
152 | |
---|
153 | |
---|
154 | |
---|
155 | |
---|
156 | namespace orxonox |
---|
157 | { |
---|
158 | RegisterClass(AsteroidMinable); |
---|
159 | |
---|
160 | |
---|
161 | // This constructor is for XML access only. |
---|
162 | AsteroidMinable::AsteroidMinable(Context* context) : Pawn(context){ |
---|
163 | |
---|
164 | // Da auch noetig? Wegen set in XML-Code? |
---|
165 | RegisterObject(AsteroidMinable); |
---|
166 | |
---|
167 | this->context = context; |
---|
168 | this->initialised = false; |
---|
169 | |
---|
170 | //Noetig, damit nicht sofort zerstoert? |
---|
171 | this->setCollisionType(WorldEntity::CollisionType::Dynamic); |
---|
172 | |
---|
173 | // Old from Pawn |
---|
174 | this->registerVariables(); |
---|
175 | |
---|
176 | //orxout() << "AsteroidMining:: Pseudo-Konstruktor passiert!" << endl; |
---|
177 | |
---|
178 | } |
---|
179 | |
---|
180 | // Call this one from other C-files. Takes arguments. |
---|
181 | AsteroidMinable::AsteroidMinable(Context* c, float size, Vector3 position) : Pawn(c){ |
---|
182 | |
---|
183 | RegisterObject(AsteroidMinable); |
---|
184 | |
---|
185 | // Old stuff from pawn |
---|
186 | this->setRadarObjectColour(ColourValue(1.0f, 1.0f, 0.0f, 1.0f)); |
---|
187 | this->setRadarObjectShape(RadarViewable::Shape::Dot); |
---|
188 | this->setCollisionType(WorldEntity::CollisionType::Dynamic); |
---|
189 | |
---|
190 | this->enableCollisionCallback(); |
---|
191 | |
---|
192 | // Default Values |
---|
193 | this->generateSmaller = true; |
---|
194 | this->context = c; |
---|
195 | this->size = size; |
---|
196 | this->health_ = 15*size; |
---|
197 | this->maxHealth_ = this->health_; |
---|
198 | this->acceptsPickups_ = false; |
---|
199 | |
---|
200 | this->setPosition(position); |
---|
201 | //this->roll = rand()*5; //etwas Drehung. richtige Variable |
---|
202 | |
---|
203 | |
---|
204 | // Add Model //<Model position="0,-40,40" yaw="90" pitch="-90" roll="0" scale="4" mesh="ast6.mesh" /> |
---|
205 | Model* hull = new Model(this->context); |
---|
206 | // random one of the 6 shapes |
---|
207 | char meshThingy[] = ""; |
---|
208 | sprintf(meshThingy, "ast%.0f.mesh", round(5*rnd())+1); // sprintf(str, "Value of Pi = %f", M_PI); |
---|
209 | hull->setMeshSource(meshThingy); |
---|
210 | hull->setScale(this->size); |
---|
211 | this->attach(hull); |
---|
212 | |
---|
213 | // Collision shape |
---|
214 | SphereCollisionShape* cs = new SphereCollisionShape(this->context); |
---|
215 | cs->setRadius((this->size)*2); //OFFEN: Feinabstimmung der Radien. 2.5 in AsteroidField.lua |
---|
216 | this->attachCollisionShape(cs); |
---|
217 | |
---|
218 | // Old from Pawn |
---|
219 | this->registerVariables(); |
---|
220 | |
---|
221 | this->initialised=true; |
---|
222 | |
---|
223 | //orxout() << "AsteroidMining:: Initialisierung Zweitkonstruktor abgeschlosssssen." << endl; |
---|
224 | |
---|
225 | } |
---|
226 | |
---|
227 | AsteroidMinable::~AsteroidMinable(){ |
---|
228 | |
---|
229 | } |
---|
230 | |
---|
231 | void AsteroidMinable::putStuff(){ |
---|
232 | |
---|
233 | // Just create a new asteroid to avoid Collision shape scale problems etc. |
---|
234 | AsteroidMinable* reborn = new AsteroidMinable(this->context, this->size, this->getPosition()); |
---|
235 | reborn->toggleShattering(true); // mainly here to avoid 'unused' warning. |
---|
236 | this->~AsteroidMinable(); // seems dangerous, yields warning. Necessary for efficiency? |
---|
237 | |
---|
238 | } |
---|
239 | |
---|
240 | void AsteroidMinable::XMLPort(Element& xmlelement, XMLPort::Mode mode) |
---|
241 | { |
---|
242 | SUPER(AsteroidMinable, XMLPort, xmlelement, mode); |
---|
243 | // XMLPortParam(PickupSpawner, "pickup", setPickupTemplateName, getPickupTemplateName, xmlelement, mode); |
---|
244 | XMLPortParam(AsteroidMinable, "size", setSize, getSize, xmlelement, mode); |
---|
245 | |
---|
246 | } |
---|
247 | |
---|
248 | void AsteroidMinable::XMLEventPort(Element& xmlelement, XMLPort::Mode mode) |
---|
249 | { |
---|
250 | SUPER(AsteroidMinable, XMLEventPort, xmlelement, mode); |
---|
251 | |
---|
252 | XMLPortEventState(AsteroidMinable, BaseObject, "vulnerability", setVulnerable, xmlelement, mode); |
---|
253 | } |
---|
254 | |
---|
255 | void AsteroidMinable::registerVariables() |
---|
256 | { |
---|
257 | |
---|
258 | registerVariable(this->size, VariableDirection::ToClient); |
---|
259 | registerVariable(this->generateSmaller, VariableDirection::ToClient); |
---|
260 | |
---|
261 | registerVariable(this->initialised, VariableDirection::ToClient); |
---|
262 | |
---|
263 | // float size; |
---|
264 | // bool generateSmaller; |
---|
265 | // bool initialised; |
---|
266 | |
---|
267 | // Context* context; |
---|
268 | } |
---|
269 | |
---|
270 | void AsteroidMinable::tick(float dt) |
---|
271 | { |
---|
272 | if(!(this->initialised)){this->putStuff();} |
---|
273 | |
---|
274 | if(this->health_ <=0){this->death();} |
---|
275 | |
---|
276 | } |
---|
277 | |
---|
278 | void AsteroidMinable::setSize(float s){ |
---|
279 | this->size = s; |
---|
280 | } |
---|
281 | |
---|
282 | float AsteroidMinable::getSize(){ |
---|
283 | return this->size; |
---|
284 | } |
---|
285 | |
---|
286 | void AsteroidMinable::toggleShattering(bool b){ |
---|
287 | this->generateSmaller = b; |
---|
288 | } |
---|
289 | |
---|
290 | |
---|
291 | void AsteroidMinable::death() //ueberschreiben |
---|
292 | { |
---|
293 | |
---|
294 | // orxout() << "AsteroidMinable::Death() aufgerufen." << endl; |
---|
295 | |
---|
296 | // OFFEN: Sauber kapputten |
---|
297 | // just copied other stuff: |
---|
298 | // this->setHealth(1); |
---|
299 | this->bAlive_ = false; |
---|
300 | this->destroyLater(); |
---|
301 | this->setDestroyWhenPlayerLeft(false); |
---|
302 | // pawn -> addExplosionPart |
---|
303 | // this->goWithStyle(); |
---|
304 | |
---|
305 | |
---|
306 | // Stuff that can be harvested. |
---|
307 | PickupSpawner* thingy = new PickupSpawner(this->context); |
---|
308 | // OFFEN: more precise size relation in custom resource pickup. |
---|
309 | char tname[] = ""; // can-t overwrite strings easily in C (strcat etc.) |
---|
310 | if(this->size <= 5){ |
---|
311 | strcat(tname, "smallmunitionpickup"); |
---|
312 | }else if(this->size <= 20){ |
---|
313 | strcat(tname, "mediummunitionpickup"); |
---|
314 | }else{ |
---|
315 | strcat(tname, "hugemunitionpickup"); |
---|
316 | } |
---|
317 | thingy->setPickupTemplateName(tname); |
---|
318 | thingy->setPosition(this->getPosition()); |
---|
319 | thingy->setMaxSpawnedItems(1); // Would be default anyways |
---|
320 | thingy->setRespawnTime(0.2f); |
---|
321 | |
---|
322 | // orxout() << "AsteroidMining::Death(): Passed Pickup stuff!" << endl; |
---|
323 | |
---|
324 | // Smaller Parts = 'Children' |
---|
325 | if(this->generateSmaller){this->spawnChildren();} |
---|
326 | |
---|
327 | // orxout() << "Wieder retour in death() geschafft. " << endl; |
---|
328 | |
---|
329 | } |
---|
330 | |
---|
331 | |
---|
332 | void AsteroidMinable::spawnChildren(){// Spawn smaller Children |
---|
333 | |
---|
334 | |
---|
335 | if (this->size <=1){return;} // Absicherung trivialer Fall |
---|
336 | |
---|
337 | int massRem = this->size-1; //some mass is lost |
---|
338 | int num = round(rnd()*(massRem-1)) + 1; // random number of children, at least one |
---|
339 | if(num > 10){num = 10;} // no max function in C! |
---|
340 | int masses[num]; // Masses of the asteroids, at least one. |
---|
341 | orxout() << "SpawnChildren(): Passed basic stuff. num = " << num << "; massRem(total) = "<< massRem << endl; |
---|
342 | |
---|
343 | massRem = massRem-num; // mass is at least one, add again below. |
---|
344 | |
---|
345 | // Randomnised spawning points for the new asteroids |
---|
346 | float phi[num] = {0.0}; // assuming that it gets initialised to 0. Add (= {0.0})? |
---|
347 | float theta[num] = {0.0}; |
---|
348 | float piG = pi; // ist statisch oder so. |
---|
349 | |
---|
350 | float d_p = 2*piG/num; |
---|
351 | float d_t = piG/num; |
---|
352 | float p = d_p/2.0; |
---|
353 | float t = d_t/2.0; |
---|
354 | // float phiOffset = rnd()*2*pi; // Added everywhere to become independent of the coordinate system? |
---|
355 | // float thetaOffset = rnd()*pi; |
---|
356 | float rScaling; // scale radius to prevent asteroids from touching. (distance=AsteroidRadius/tan(sector/2)) |
---|
357 | if(num == 1 ){ |
---|
358 | rScaling = 1; // avoid tan(90). Unused. |
---|
359 | }else{ |
---|
360 | |
---|
361 | rScaling = tan(t); |
---|
362 | |
---|
363 | int pos; // insert at random position (linear probing) in array, to get some randomness. |
---|
364 | for(int it = 0; it<num; ++it){ |
---|
365 | |
---|
366 | pos = mod((int)(rnd()*num),num); |
---|
367 | while(phi[pos] != 0.0){// find empty spot in array |
---|
368 | pos = (int)mod(++pos, num); |
---|
369 | } |
---|
370 | phi[pos] = p + it*d_p;// set angle there |
---|
371 | |
---|
372 | pos = mod((int)(rnd()*num),num); |
---|
373 | while(theta[pos] != 0.0){ |
---|
374 | pos = (int)mod(++pos, num); |
---|
375 | } |
---|
376 | theta[pos] = t + it*d_t; |
---|
377 | } |
---|
378 | } |
---|
379 | |
---|
380 | //orxout() << "SpawnChildren(): Phi: "; printArrayString(phi); |
---|
381 | //orxout() << "SpawnChildren(): Theta: "; printArrayString(theta); |
---|
382 | orxout() << "SpawnChildren(): Passed angle stuff. " << endl; |
---|
383 | |
---|
384 | // 'Triangular', discrete probability density with max at the expected value massRem/num at a. a+b = c |
---|
385 | if(massRem>0){ // Required to avoid array of size 0 or access problems |
---|
386 | int c = massRem; |
---|
387 | float probDensity[c] = {0.0}; |
---|
388 | |
---|
389 | int a = round(massRem/num); |
---|
390 | int b = c-a; |
---|
391 | |
---|
392 | int z = 0; |
---|
393 | float dProbA = 1.0/(a*a + 3.0*a + 2.0); // one 'probability unit' for discrete ramp function. Gauss stuff. |
---|
394 | for(z = 0; z<=a; ++z){probDensity[z] = (z+1)*dProbA; } // rising part |
---|
395 | |
---|
396 | float dProbB = 1.0/(b*b +3.0*b + 2.0); |
---|
397 | for(z = 0; z<b; ++z){probDensity[c-z] = (z+1)*dProbB;} // falling part |
---|
398 | |
---|
399 | // Testing |
---|
400 | for(int globi = 0; globi<c; ++globi){ |
---|
401 | orxout() << "pDensity at [" << globi << "] is: " << probDensity[globi] << endl; |
---|
402 | } |
---|
403 | |
---|
404 | // Distributing the mass to individual asteroids |
---|
405 | int result; |
---|
406 | float rVal;// between 0 and 1 |
---|
407 | float probSum; |
---|
408 | for(int trav = 0; trav<num; ++trav){ |
---|
409 | result = 0;// reset |
---|
410 | rVal = rnd();// between 0 and 1 |
---|
411 | orxout() << "Random Value picked: " << rVal << endl; |
---|
412 | probSum = probDensity[0]; |
---|
413 | //orxout() << "Sum at start: " << probSum << endl; |
---|
414 | |
---|
415 | while(rVal>probSum && result<massRem){// Not yet found && there-s smth to distribute (Incrementing once inside!) |
---|
416 | if(result<(num-2)){probSum = probSum+probDensity[result+1];} // avoid logical/acess error |
---|
417 | ++result; |
---|
418 | //orxout() << "Sum so far: " << probSum << endl; |
---|
419 | } |
---|
420 | |
---|
421 | massRem = massRem-result; |
---|
422 | masses[trav] = 1 +result; // at least one |
---|
423 | orxout() << "Mass chosen for child " << trav << " is: " << masses[trav] << endl; |
---|
424 | |
---|
425 | } |
---|
426 | }else{// Everyone has mass 1. Initialising the array to 1 doesn-t seem to work. Hideous C language! |
---|
427 | for(int schnaegg = 0; schnaegg<num; ++schnaegg){ |
---|
428 | masses[schnaegg] = 1; |
---|
429 | } |
---|
430 | } |
---|
431 | |
---|
432 | //orxout() << "SpawnChildren(): Masses: "; printArrayString(masses); |
---|
433 | orxout() << "SpawnChildren(): Passed mass stuff. " << endl; |
---|
434 | |
---|
435 | // Creating the 'chlidren': |
---|
436 | for(int fisch = 0; fisch<num; ++fisch){ |
---|
437 | |
---|
438 | Vector3* pos = new Vector3(0,0,0); // Position offset |
---|
439 | if(num > 1){// not required if there-s just one child |
---|
440 | float r = masses[fisch]/rScaling; |
---|
441 | pos = new Vector3(r*sin(theta[fisch])*cos(phi[fisch]), r*sin(theta[fisch])*sin(phi[fisch]), r*cos(theta[fisch])); // convert spheric coordinates to vector |
---|
442 | } |
---|
443 | |
---|
444 | //orxout() << "Creating asteroid with mass " << masses[fisch] << " at relative postition " << *pos << endl; |
---|
445 | AsteroidMinable* child = new AsteroidMinable(this->context, masses[fisch], this->getPosition() + *pos); |
---|
446 | |
---|
447 | if(child == nullptr){ |
---|
448 | orxout(internal_error, context::pickups) << "Weird, can't create new AsteroidMinable." << endl; |
---|
449 | } |
---|
450 | |
---|
451 | } |
---|
452 | orxout() << "Leaving spawnChildren() method. " << endl; |
---|
453 | } |
---|
454 | |
---|
455 | |
---|
456 | void AsteroidMinable::hit(Pawn* originator, const Vector3& force, const btCollisionShape* cs, float damage, float healthdamage, float shielddamage){ |
---|
457 | |
---|
458 | orxout() << "AsteroidMining::Hit(Variante 1) Dings aufgerufen. " << endl; |
---|
459 | |
---|
460 | // Kollision mit anderem Asteroid oder Pickup (OFFEN: evtl. Spawner oder irgendwas?) verhindern. In diesem Fall einfach nichts tun. |
---|
461 | // Wird staending aufgerufen -> Rechenleistung? |
---|
462 | if(orxonox_cast<AsteroidMinable*>(originator) || orxonox_cast<Pickup*>(originator)){return;} |
---|
463 | this->damage(damage, healthdamage, shielddamage, originator, cs); |
---|
464 | this->setVelocity(this->getVelocity() + force); |
---|
465 | |
---|
466 | |
---|
467 | |
---|
468 | // if (this->getGametype() && this->getGametype()->allowPawnHit(this, originator))// && (!this->getController() || !this->getController()->getGodMode()) ) |
---|
469 | // { |
---|
470 | // this->damage(damage, healthdamage, shielddamage, originator, cs); |
---|
471 | // this->setVelocity(this->getVelocity() + force); |
---|
472 | // } |
---|
473 | } |
---|
474 | |
---|
475 | void AsteroidMinable::hit(Pawn* originator, btManifoldPoint& contactpoint, const btCollisionShape* cs, float damage, float healthdamage, float shielddamage){ |
---|
476 | |
---|
477 | //orxout() << "AsteroidMining::Hit(Variante 2) Dings aufgerufen. " << endl; |
---|
478 | // Kollision mit anderem Asteroid oder Pickup (OFFEN: evtl. Spawner oder irgendwas?) verhindern. In diesem Fall einfach nichts tun. |
---|
479 | // Wird staending aufgerufen -> Rechenleistung? |
---|
480 | if(orxonox_cast<AsteroidMinable*>(originator) || orxonox_cast<Pickup*>(originator)){return;} |
---|
481 | |
---|
482 | //orxout() << "Schaden. HP: " << this->health_ << " Dmg: " << damage << " hDmg: " << healthdamage << " sDmg: " << shielddamage << endl; |
---|
483 | |
---|
484 | this->damage(damage, healthdamage, shielddamage, originator, cs); |
---|
485 | |
---|
486 | |
---|
487 | |
---|
488 | |
---|
489 | // if (this->getGametype() && this->getGametype()->allowPawnHit(this, originator))// && (!this->getController() || !this->getController()->getGodMode()) ) |
---|
490 | // { |
---|
491 | // this->damage(damage, healthdamage, shielddamage, originator, cs); |
---|
492 | |
---|
493 | // //if ( this->getController() ) |
---|
494 | // // this->getController()->hit(originator, contactpoint, damage); // changed to damage, why shielddamage? |
---|
495 | // } |
---|
496 | } |
---|
497 | |
---|
498 | void AsteroidMinable::printArrayString(float thingy[]){ // Don-t work! |
---|
499 | |
---|
500 | orxout() << "[" ; //<< endl; |
---|
501 | char frag[] = ""; |
---|
502 | int len = (int)(sizeof(thingy)/sizeof(thingy[0])); |
---|
503 | for(int m = 0; m< (len-2); ++m){ |
---|
504 | sprintf(frag, "%.5f, ", thingy[m]); |
---|
505 | orxout() << frag << endl;//std::flush; |
---|
506 | } |
---|
507 | sprintf(frag, "%.5f]", thingy[len-1]); |
---|
508 | orxout() << frag << endl; // Just print it here! No ugly passing. |
---|
509 | } |
---|
510 | |
---|
511 | void AsteroidMinable::printArrayString(int thingy[]){ |
---|
512 | |
---|
513 | orxout() << "[" ; //<< endl; |
---|
514 | char frag[] = ""; |
---|
515 | int len = (int)(sizeof(thingy)/sizeof(thingy[0])); |
---|
516 | for(int m = 0; m< (len-2); ++m){ |
---|
517 | sprintf(frag, "%.0i, ", thingy[m]); |
---|
518 | orxout() << frag << endl;//std::flush; |
---|
519 | printf("TEst"); |
---|
520 | } |
---|
521 | |
---|
522 | sprintf(frag, "%.0i]", thingy[len-1]); // last element |
---|
523 | orxout() << frag << endl; // Just print it here! No ugly passing. |
---|
524 | } |
---|
525 | |
---|
526 | |
---|
527 | // void AsteroidMinable::printArrayString(int thingy[]){ |
---|
528 | |
---|
529 | // char res[] = "["; |
---|
530 | // //strcat(res, "["); |
---|
531 | // char frag[] = ""; |
---|
532 | |
---|
533 | // int len = (int)(sizeof(thingy)/sizeof(thingy[0])); |
---|
534 | // for(int m = 0; m< (len-1); ++m){ |
---|
535 | // sprintf(frag, "%.0i, ", thingy[m]); |
---|
536 | // strcat(res, frag); |
---|
537 | // } |
---|
538 | // sprintf(frag, "%.0i]", thingy[len]); |
---|
539 | // strcat(res, frag); // last element |
---|
540 | |
---|
541 | // orxout() << res << endl; // Just print it here! No ugly passing. |
---|
542 | |
---|
543 | // // static char result[(sizeof(res)/sizeof("")] = res; // define as static, would get deleted otherwise. |
---|
544 | // // char *result = malloc(sizeof(res)/sizeof("") + 1); |
---|
545 | // // *result = res; |
---|
546 | // // return result; |
---|
547 | // } |
---|
548 | |
---|
549 | |
---|
550 | |
---|
551 | //Pawn: |
---|
552 | // void Pawn::hit(Pawn* originator, const Vector3& force, const btCollisionShape* cs, float damage, float healthdamage, float shielddamage) |
---|
553 | // { |
---|
554 | // if (this->getGametype() && this->getGametype()->allowPawnHit(this, originator) && (!this->getController() || !this->getController()->getGodMode()) ) |
---|
555 | // { |
---|
556 | // this->damage(damage, healthdamage, shielddamage, originator, cs); |
---|
557 | // this->setVelocity(this->getVelocity() + force); |
---|
558 | // } |
---|
559 | // } |
---|
560 | |
---|
561 | // void Pawn::hit(Pawn* originator, btManifoldPoint& contactpoint, const btCollisionShape* cs, float damage, float healthdamage, float shielddamage) |
---|
562 | // { |
---|
563 | // if (this->getGametype() && this->getGametype()->allowPawnHit(this, originator) && (!this->getController() || !this->getController()->getGodMode()) ) |
---|
564 | // { |
---|
565 | // this->damage(damage, healthdamage, shielddamage, originator, cs); |
---|
566 | |
---|
567 | // if ( this->getController() ) |
---|
568 | // this->getController()->hit(originator, contactpoint, damage); // changed to damage, why shielddamage? |
---|
569 | // } |
---|
570 | // } |
---|
571 | |
---|
572 | |
---|
573 | |
---|
574 | |
---|
575 | // /** |
---|
576 | // @brief |
---|
577 | // Virtual function that gets called when this object collides with another. |
---|
578 | // @param otherObject |
---|
579 | // The object this one has collided into. |
---|
580 | // @param ownCollisionShape |
---|
581 | // The collision shape of the other object |
---|
582 | // @param contactPoint |
---|
583 | // Contact point provided by Bullet. Holds more information and can me modified. See return value. |
---|
584 | // @return |
---|
585 | // Returning false means that no modification to the contactPoint has been made. Return true otherwise! |
---|
586 | // @note |
---|
587 | // Condition is that enableCollisionCallback() was called. |
---|
588 | // */ |
---|
589 | // virtual inline bool collidesAgainst(WorldEntity* otherObject, const btCollisionShape* ownCollisionShape, btManifoldPoint& contactPoint) |
---|
590 | // { return false; } /* With false, Bullet assumes no modification to the collision objects. */ |
---|
591 | |
---|
592 | // //! Enables the collidesAgainst(.) function. The object doesn't respond to collision otherwise! |
---|
593 | // inline void enableCollisionCallback() |
---|
594 | // { this->bCollisionCallbackActive_ = true; this->collisionCallbackActivityChanged(); } |
---|
595 | |
---|
596 | |
---|
597 | |
---|
598 | // //! Disables the collidesAgainst(.) function. @see enableCollisionCallback() |
---|
599 | // inline void disableCollisionCallback() |
---|
600 | // { this->bCollisionCallbackActive_ = false; this->collisionCallbackActivityChanged(); } |
---|
601 | |
---|
602 | |
---|
603 | // //! Tells whether there could be a collision callback via collidesAgainst(.) |
---|
604 | // inline bool isCollisionCallbackActive() const |
---|
605 | // { return this->bCollisionCallbackActive_; } |
---|
606 | |
---|
607 | // //! Enables or disables collision response (default is of course on) |
---|
608 | // inline void setCollisionResponse(bool value) |
---|
609 | // { this->bCollisionResponseActive_ = value; this->collisionResponseActivityChanged(); } |
---|
610 | |
---|
611 | |
---|
612 | // //! Tells whether there could be a collision response |
---|
613 | // inline bool hasCollisionResponse() |
---|
614 | // { return this->bCollisionResponseActive_; } |
---|
615 | |
---|
616 | |
---|
617 | } |
---|
618 | |
---|
619 | |
---|
620 | |
---|
621 | |
---|
622 | |
---|
623 | /* |
---|
624 | void DronePickup::changedUsed(void) |
---|
625 | { |
---|
626 | SUPER(DronePickup, changedUsed); |
---|
627 | |
---|
628 | // If the pickup has transited to used. |
---|
629 | if(this->isUsed()) |
---|
630 | { |
---|
631 | |
---|
632 | Pawn* pawn = this->carrierToPawnHelper(); |
---|
633 | if(pawn == nullptr) // If the PickupCarrier is no Pawn, then this pickup is useless and therefore is destroyed. |
---|
634 | this->Pickupable::destroy(); |
---|
635 | |
---|
636 | //Attach to pawn |
---|
637 | Drone* drone = new Drone(pawn->getContext()); // this is neccessary because the projectiles fired need a valid creator for the particlespawner (when colliding against something) |
---|
638 | drone->addTemplate(this->getDroneTemplate()); |
---|
639 | |
---|
640 | Controller* controller = drone->getController(); |
---|
641 | DroneController* droneController = orxonox_cast<DroneController*>(controller); |
---|
642 | if(droneController != nullptr) |
---|
643 | { |
---|
644 | droneController->setOwner(pawn); |
---|
645 | } |
---|
646 | |
---|
647 | Vector3 spawnPosition = pawn->getWorldPosition() + Vector3(30,0,-30); |
---|
648 | drone->setPosition(spawnPosition); |
---|
649 | |
---|
650 | // The pickup has been used up. |
---|
651 | this->setUsed(false); |
---|
652 | } |
---|
653 | else |
---|
654 | { |
---|
655 | // If either the pickup can only be used once or it is continuous and used up, it is destroyed upon setting it to unused. |
---|
656 | if(this->isOnce() || (this->isContinuous() )) |
---|
657 | { |
---|
658 | this->Pickupable::destroy(); |
---|
659 | } |
---|
660 | } |
---|
661 | } |
---|
662 | */ |
---|