1 #ifndef __UNIT_DAMAGE_CPP__
2 #define __UNIT_DAMAGE_CPP__
34 extern vector< Mesh* >
MakeMesh(
unsigned int mysize );
36 template <
class UnitType >
41 for (
un_iter su = this->getSubUnits(); *su; ++su)
42 (*su)->Split( level );
45 for (
int i = 0;
i < nummesh();) {
46 if (this->meshdata[
i]) {
47 if (this->meshdata[i]->getBlendDst() ==
ONE) {
48 delete this->meshdata[i];
49 this->meshdata.erase( this->meshdata.begin()+i );
50 }
else {i++; }}
else {this->meshdata.erase( this->meshdata.begin()+i ); }}
51 int nm = this->nummesh();
55 unsigned int num_chunks = unit_stats.
success() ? atoi( unit_stats[
"Num_Chunks"].c_str() ) : 0;
56 if (nm <= 0 && num_chunks == 0)
58 vector< Mesh* >old = this->meshdata;
59 Mesh *shield = old.back();
62 vector< unsigned int >meshsizes;
63 if ( num_chunks && unit_stats.
success() ) {
66 unsigned int which_chunk = rand()%num_chunks;
72 float randomstartframe = 0;
73 float randomstartseconds = 0;
75 int scale = atoi( scalestr.c_str() );
76 if (scale == 0) scale = 1;
77 AddMeshes( nw, randomstartframe, randomstartseconds, scale, chunkname, this->
faction,
78 this->getFlightgroup(), &meshsizes );
82 for (i = 0; i < old.size(); ++i)
89 size_t oldsize = old.size();
90 for (
size_t i = 0;
i < oldsize;
i++) {
91 PlaneNorm.Set( rand()-RAND_MAX/2, rand()-RAND_MAX/2, rand()-RAND_MAX/2+.5 );
92 PlaneNorm.Normalize();
95 old[
i]->Fork( nw[nw.size()-2], nw.back(), PlaneNorm.i, PlaneNorm.j, PlaneNorm.k,
96 -PlaneNorm.Dot( old[
i]->Position() ) );
99 if (nw[nw.size()-2] == NULL) {
100 nw[nw.size()-2] = nw.back();
103 if (nw.back() == NULL)
108 meshsizes.reserve( old.size() );
109 for (
size_t i = 0;
i < old.size(); ++
i)
110 meshsizes.push_back( 1 );
112 old.push_back( NULL );
117 vector< Mesh* >tempmeshes;
118 for (vector<Mesh *>::size_type
i=0;
i<meshsizes.size();
i++) {
121 tempmeshes.reserve( meshsizes[
i] );
122 for (
unsigned int j = 0;
j < meshsizes[i] && k < old.size(); ++
j, ++k)
123 tempmeshes.push_back( old[k] );
125 splitsub->
hull = 1000;
126 splitsub->
name =
"debris";
132 float locm = loc.Magnitude();
136 loc.Set( rand(), rand(), rand()+.1 );
138 static float explosion_torque =
144 this->meshdata.clear();
145 this->meshdata.push_back( NULL );
146 this->Mass *= debrismassmult;
151 template <
class UnitType >
159 AUDPlay( this->sound->armor, this->ToWorldCoordinates(
160 pnt ).Cast()+this->cumulative_transformation.position, this->Velocity, 1 );
162 static int playerarmorsound =
164 int sound = playerarmorsound != -1 ? playerarmorsound : this->sound->armor;
167 AUDPlay( sound, this->ToWorldCoordinates(
168 pnt ).Cast()+this->cumulative_transformation.position, this->Velocity, 1 );
172 template <
class UnitType >
180 AUDPlay( this->sound->hull, this->ToWorldCoordinates(
181 pnt ).Cast()+this->cumulative_transformation.position, this->Velocity, 1 );
184 int sound = playerhullsound != -1 ? playerhullsound : this->sound->hull;
187 AUDPlay( sound, this->ToWorldCoordinates(
188 pnt ).Cast()+this->cumulative_transformation.position, this->Velocity, 1 );
192 template <
class UnitType >
195 float percent = UnitType::DealDamageToShield( pnt, damage );
202 AUDPlay( this->sound->shield, this->ToWorldCoordinates(
203 pnt ).Cast()+this->cumulative_transformation.position, this->Velocity, 1 );
206 static int playerhullsound =
208 int sound = playerhullsound != -1 ? playerhullsound : this->sound->hull;
212 AUDPlay( sound, this->ToWorldCoordinates(
213 pnt ).Cast()+this->cumulative_transformation.position, this->Velocity, 1 );
220 extern unsigned int AddAnimation(
const QVector&,
const float,
bool,
const string&,
float percentgrow );
226 template <
class UnitType >
229 if (this->pImage->pExplosion == NULL && this->pImage->timeexplode == 0) {
235 this->pImage->timeexplode = 0;
236 static string expani =
vs_config->
getVariable(
"graphics",
"explosion_animation",
"explosion_orange.ani" );
241 if ( bleh.empty() ) {
244 if (bleh.size() == 0)
247 static bool explosion_face_player =
249 this->pImage->pExplosion =
new Animation( bleh.c_str(), explosion_face_player, .1,
BILINEAR, true );
250 this->pImage->pExplosion->
SetDimensions( this->ExplosionRadius(), this->ExplosionRadius() );
252 this->GetOrientation( p, q, r );
253 this->pImage->pExplosion->SetOrientation( p, q, r );
255 static float expdamagecenter =
257 static float damageedge =
260 0, this->ExplosionRadius()*expdamagecenter,
261 this->ExplosionRadius()*expdamagecenter
262 *damageedge, NULL ) );
264 QVector exploc = this->cumulative_transformation.position;
265 bool sub = this->isSubUnit();
269 static float explosion_closeness =
271 exploc = un->
Position()*explosion_closeness+exploc*(1-explosion_closeness);
273 AUDPlay( this->sound->explode, exploc, this->Velocity, 1 );
276 if (this->isUnit() ==
UNITPTR) {
277 static float percentage_shock =
279 if ( rand() < RAND_MAX*percentage_shock && ( !this->isSubUnit() ) ) {
280 static float shockwavegrowth =
282 static string shockani(
vs_config->
getVariable(
"graphics",
"shockwave_animation",
"explosion_wave.ani" ) );
287 this->ExplosionRadius(),
true, shockani, shockwavegrowth );
292 this->GetOrientation( p, q, r );
294 if (tmp < RAND_MAX/24)
296 else if (tmp < RAND_MAX/16)
298 else if (tmp < RAND_MAX/8)
306 static float badrel =
308 static float goodrel =
310 static float timelapse =
316 if ( newtime-lasttime > timelapse
318 != upgradesfaction) ) {
323 }
else if (rel < badrel) {
335 ( this->pImage->timeexplode > timebeforeexplodedone || this->isUnit() ==
MISSILEPTR
337 if (this->pImage->pExplosion) {
338 this->pImage->timeexplode += timeit;
339 this->pImage->pExplosion->SetPosition( this->Position() );
341 this->GetOrientation( p, q, r );
342 this->pImage->pExplosion->SetOrientation( p, q, r );
343 if (this->pImage->pExplosion->Done() && timealldone) {
344 delete this->pImage->pExplosion;
345 this->pImage->pExplosion = NULL;
347 if (drawit && this->pImage->pExplosion)
348 this->pImage->pExplosion->Draw();
350 bool alldone = this->pImage->pExplosion ? !this->pImage->pExplosion->Done() :
false;
351 if ( !this->SubUnits.empty() ) {
353 for (
un_iter ui = this->getSubUnits(); (su = *ui); ++ui) {
354 bool temp = su->
Explode( drawit, timeit );
360 if ( (phatloot > 0) && (this->numCargo() > 0) ) {
361 size_t dropcount = (size_t) floor( this->numCargo()/phatloot )+1;
362 if ( dropcount > this->numCargo() ) dropcount = this->numCargo();
363 for (
size_t i = 0;
i < dropcount;
i++)
364 this->EjectCargo( this->numCargo()-1 );
366 return alldone || (!timealldone);