Vegastrike 0.5.1 rc1  1.0
Original sources for Vegastrike Evolved
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
asteroid_generic.cpp
Go to the documentation of this file.
1 #include "cmd/asteroid_generic.h"
2 #include "cmd/collection.h"
3 #include "gfx/vec.h"
5 #include "cmd/unit_generic.h"
6 
7 static void RecursiveSetSchedule(Unit *un)
8 {
9  if (un) {
10  if (un->SubUnits.empty())
12  else {
14  un->do_subunit_scheduling = true;
15  for (un_iter it=un->getSubUnits(); it.notDone(); ++it)
17  }
18  }
19 }
20 
21 
22 void Asteroid::Init(float difficulty)
23 {
24  asteroid_physics_offset=0;
25  un_iter iter = getSubUnits();
26  while(*iter) {
27  float x=2*difficulty*((float)rand())/RAND_MAX-difficulty;
28  float y=2*difficulty*((float)rand())/RAND_MAX-difficulty;
29  float z=2*difficulty*((float)rand())/RAND_MAX-difficulty;
30  (*iter)->SetAngularVelocity(Vector(x,y,z));
31  ++iter;
32  }
34 }
35 
36 
37 void Asteroid::reactToCollision(Unit * smaller, const QVector& biglocation, const Vector& bignormal, const QVector& smalllocation, const Vector& smallnormal, float dist)
38 {
39  switch (smaller->isUnit()) {
40  case ASTEROIDPTR:
41  case ENHANCEMENTPTR:
42  break;
43  case NEBULAPTR:
44  smaller->reactToCollision(this,smalllocation,smallnormal,biglocation,bignormal,dist);
45  break;
46  default:
47  /***** DOES THAT STILL WORK WITH UNIT:: ?????????? *******/
48  Unit::reactToCollision (smaller,biglocation,bignormal,smalllocation,smallnormal,dist);
49  break;
50  }
51 }
52 
53 
54 Asteroid::Asteroid(const char * filename, int faction, Flightgroup* fg, int fg_snumber, float difficulty):Unit (filename,false, faction,string(""),fg,fg_snumber)
55 {
56  Init( difficulty);
57 }