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
Beam Class Reference

#include <beam.h>

Public Member Functions

void ListenToOwner (bool listen)
 
 Beam (const Transformation &trans, const weapon_info &clne, void *own, Unit *firer, int sound)
 
void Init (const Transformation &trans, const weapon_info &clne, void *own, Unit *firer)
 
 ~Beam ()
 
void RemoveFromSystem (bool eradicate)
 
float refireTime ()
 
QVector GetPosition () const
 
void SetPosition (const QVector &)
 
void SetOrientation (const Vector &p, const Vector &q, const Vector &r)
 
void UpdatePhysics (const Transformation &, const Matrix &, class Unit *target, float trackingcone, Unit *targetToCollideWith, float HeatSink, Unit *firer, Unit *superunit)
 
void Draw (const Transformation &, const Matrix &, class Unit *target, float trackingcone)
 
void Destabilize ()
 
bool Dissolved ()
 
bool Ready ()
 
bool Collide (class Unit *target, Unit *firer, Unit *superunit)
 

Static Public Member Functions

static void ProcessDrawQueue ()
 

Detailed Description

Definition at line 14 of file beam.h.

Constructor & Destructor Documentation

Beam::Beam ( const Transformation trans,
const weapon_info clne,
void *  own,
Unit firer,
int  sound 
)

Definition at line 26 of file beam.cpp.

References DecalQueue::AddTexture(), AUDCreateSound(), beamdrawqueue, weapon_info::file, g, Init(), weapon_info::sound, TRILINEAR, and VSCONSTRUCT2.

26  : vlist( NULL )
27  , Col( clne.r, clne.g, clne.b, clne.a )
28 {
29  VSCONSTRUCT2( 'B' )
30  listen_to_owner = false; //warning this line of code is also present in beam_server.cpp change one, change ALL
31 #ifdef PERBOLTSOUND
32  sound = AUDCreateSound( clne.sound, true );
33 #else
34  this->sound = sound;
35 #endif
36  decal = beamdecals.AddTexture( clne.file.c_str(), TRILINEAR );
37  if ( decal >= beamdrawqueue.size() )
38  beamdrawqueue.push_back( vector< BeamDrawContext > () );
39  Init( trans, clne, own, firer );
40  impact = UNSTABLE;
41 }
Beam::~Beam ( )

Definition at line 43 of file beam.cpp.

References AUDDeleteSound(), DecalQueue::DelTexture(), RemoveFromSystem(), and VSDESTRUCT2.

44 {
46 #ifdef PERBOLTSOUND
47  AUDDeleteSound( sound );
48 #endif
49 #ifdef BEAMCOLQ
50  RemoveFromSystem( true );
51 #endif
52  //DO NOT DELETE - shared vlist
53  //delete vlist;
54  beamdecals.DelTexture( decal );
55 }

Member Function Documentation

bool Beam::Collide ( class Unit target,
Unit firer,
Unit superunit 
)

Definition at line 358 of file beam_generic.cpp.

References _Universe, Universe::AccessCockpit(), Unit::AddCargo(), Unit::ApplyDamage(), Unit::ApplyForce(), ASTEROIDPTR, AUDCreateSoundWAV(), AUDPlay(), c, Unit::CanAddCargo(), Cargo::content, UniverseUtil::cos(), Unit::faction, float, Unit::getAIState(), Cargo::GetCategory(), Unit::GetDestinations(), FactionUtil::GetFactionIndex(), Unit::GetMass(), GetMasterPartList(), Cockpit::GetParent(), FactionUtil::GetUpgradeFaction(), VegaConfig::getVariable(), Unit::GetVelocity(), Universe::isPlayerStarship(), Unit::isTractorable(), Unit::isUnit(), Unit::Kill(), Magnitude(), mymin, Unit::name, NEBULAPTR, Unit::owner, XMLSupport::parse_bool(), XMLSupport::parse_float(), PLANETPTR, Unit::Position(), Cargo::quantity, QVector, Unit::rayCollide(), Unit::rSize(), Unit::sim_atom_multiplier, SIMULATION_ATOM, UniverseUtil::sqrt(), Unit::tractorIn, Unit::tractorPush, Vector, vs_config, and VSFileSystem::vs_fprintf().

359 {
360  if (this == NULL || target == NULL) {
361  VSFileSystem::vs_fprintf( stderr, "Recovering from nonfatal beam error when beam inactive\n" );
362  return false;
363  }
364  float distance;
365  Vector normal; //apply shields
366 
367  QVector direction( this->direction.Cast() );
368  QVector end( center+direction.Scale( curlength ) );
369  enum clsptr type = target->isUnit();
370  if (target == owner || type == NEBULAPTR || type == ASTEROIDPTR) {
371  static bool collideroids =
372  XMLSupport::parse_bool( vs_config->getVariable( "physics", "AsteroidWeaponCollision", "false" ) );
373  if ( type != ASTEROIDPTR || (!collideroids) )
374  return false;
375  }
376  static bool collidejump = XMLSupport::parse_bool( vs_config->getVariable( "physics", "JumpWeaponCollision", "false" ) );
377  if ( type == PLANETPTR && (!collidejump) && !target->GetDestinations().empty() )
378  return false;
379  //A bunch of needed config variables - its best to have them here, so that they're loaded the
380  //very first time Collide() is called. That way, we avoid hiccups.
381  static float nbig = XMLSupport::parse_float( vs_config->getVariable( "physics", "percent_to_tractor", ".1" ) );
382  int upgradesfaction = FactionUtil::GetUpgradeFaction();
383  static int cargofaction = FactionUtil::GetFactionIndex( "cargo" );
384  static bool c_fp = XMLSupport::parse_bool( vs_config->getVariable( "physics", "tractor.cargo.force_push", "true" ) );
385  static bool c_fi = XMLSupport::parse_bool( vs_config->getVariable( "physics", "tractor.cargo.force_in", "true" ) );
386  static bool u_fp = XMLSupport::parse_bool( vs_config->getVariable( "physics", "tractor.upgrade.force_push", "true" ) );
387  static bool u_fi = XMLSupport::parse_bool( vs_config->getVariable( "physics", "tractor.upgrade.force_in", "true" ) );
388  static bool f_fp = XMLSupport::parse_bool( vs_config->getVariable( "physics", "tractor.faction.force_push", "true" ) );
389  static bool f_fi = XMLSupport::parse_bool( vs_config->getVariable( "physics", "tractor.faction.force_in", "true" ) );
390  static bool d_fp = XMLSupport::parse_bool( vs_config->getVariable( "physics", "tractor.disabled.force_push", "true" ) );
391  static bool d_fi = XMLSupport::parse_bool( vs_config->getVariable( "physics", "tractor.disabled.force_in", "true" ) );
392  static bool o_fp = XMLSupport::parse_bool( vs_config->getVariable( "physics", "tractor.others.force_push", "false" ) );
393  static bool o_fi = XMLSupport::parse_bool( vs_config->getVariable( "physics", "tractor.others.force_in", "false" ) );
394  static bool scoop = XMLSupport::parse_bool( vs_config->getVariable( "physics", "tractor.scoop", "true" ) );
395  static float scoopangle = XMLSupport::parse_float( vs_config->getVariable( "physics", "tractor.scoop_angle", "0.5" ) ); //In radians
396  static float scoopcosangle = (float) cos( scoopangle );
397  static float maxrelspeed =
398  XMLSupport::parse_float( vs_config->getVariable( "physics", "tractor.max_relative_speed", "150" ) );
399  static float c_lighting =
400  XMLSupport::parse_float( vs_config->getVariable( "physics", "tractor.cargo.light_shields_on_push", "1" ) );
401  static float u_lighting =
402  XMLSupport::parse_float( vs_config->getVariable( "physics", "tractor.upgrade.light_shields_on_push", "1" ) );
403  static float f_lighting =
404  XMLSupport::parse_float( vs_config->getVariable( "physics", "tractor.faction.light_shields_on_push", "1" ) );
405  static float d_lighting =
406  XMLSupport::parse_float( vs_config->getVariable( "physics", "tractor.disabled.light_shields_on_push", "0" ) );
407  static float o_lighting =
408  XMLSupport::parse_float( vs_config->getVariable( "physics", "tractor.others.light_shields_on_push", "1" ) );
409  static float c_ors_m =
410  XMLSupport::parse_float( vs_config->getVariable( "physics", "tractor.cargo.distance_own_rsize", "1.5" ) );
411  static float c_trs_m =
412  XMLSupport::parse_float( vs_config->getVariable( "physics", "tractor.cargo.distance_tgt_rsize", "1.1" ) );
413  static float c_o = XMLSupport::parse_float( vs_config->getVariable( "physics", "tractor.cargo.distance", "0" ) );
414  static float u_ors_m =
415  XMLSupport::parse_float( vs_config->getVariable( "physics", "tractor.ugprade.distance_own_rsize", "1.5" ) );
416  static float u_trs_m =
417  XMLSupport::parse_float( vs_config->getVariable( "physics", "tractor.upgrade.distance_tgt_rsize", "1.1" ) );
418  static float u_o = XMLSupport::parse_float( vs_config->getVariable( "physics", "tractor.upgrade.distance", "0" ) );
419  static float f_ors_m =
420  XMLSupport::parse_float( vs_config->getVariable( "physics", "tractor.faction.distance_own_rsize", "2.2" ) );
421  static float f_trs_m =
422  XMLSupport::parse_float( vs_config->getVariable( "physics", "tractor.faction.distance_tgt_rsize", "2.2" ) );
423  static float f_o = XMLSupport::parse_float( vs_config->getVariable( "physics", "tractor.faction.distance", "0" ) );
424  static float o_ors_m =
425  XMLSupport::parse_float( vs_config->getVariable( "physics", "tractor.others.distance_own_rsize", "1.1" ) );
426  static float o_trs_m =
427  XMLSupport::parse_float( vs_config->getVariable( "physics", "tractor.others.distance_tgt_rsize", "1.1" ) );
428  static float o_o = XMLSupport::parse_float( vs_config->getVariable( "physics", "tractor.others.distance", "0" ) );
429  bool tractor = (damagerate < 0 && phasedamage > 0);
430  bool repulsor = (damagerate > 0 && phasedamage < 0);
431  if ( scoop && (tractor || repulsor) ) {
432  QVector d2( target->Position()-center );
433  d2.Normalize();
434  float angle = this->direction*d2;
435  if (angle > scoopcosangle) {
436  end = center+d2*curlength;
437  direction = end-center;
438  direction.Normalize();
439  }
440  }
441  Unit *colidee;
442  if ( ( colidee = target->rayCollide( center, end, normal, distance ) ) ) {
443  if ( !( scoop && (tractor || repulsor) ) ){
444  this->curlength = distance;
445  }
446  float curlength = distance;
447  impact |= IMPACT;
448  GFXColor coltmp( Col );
449  float tmp = (curlength/range);
450  float appldam = (damagerate*SIMULATION_ATOM*curthick/thickness)*( (1-tmp)+tmp*rangepenalty );
451  float phasdam = (phasedamage*SIMULATION_ATOM*curthick/thickness)*( (1-tmp)+tmp*rangepenalty );
452  float owner_rsize = superunit->rSize();
453  int owner_faction = superunit->faction;
454  if (tractor || repulsor) {
455  bool fp = o_fp, fi = o_fi;
456  if (target->faction == owner_faction)
457  fp = f_fp, fi = f_fi;
458 
459  else if (target->faction == upgradesfaction)
460  fp = u_fp, fi = u_fi;
461 
462  else if (target->faction == cargofaction)
463  fp = c_fp, fi = c_fi;
464 
465  else if (target->getAIState() == NULL)
466  fp = d_fp, fi = d_fi;
467  //tractor/repulsor beam!
468  if ( fp || target->isTractorable( Unit::tractorPush ) ) {
469  float lighting = o_lighting;
470  if (target->faction == owner_faction)
471  lighting = f_lighting;
472 
473  else if (target->faction == upgradesfaction)
474  lighting = u_lighting;
475 
476  else if (target->faction == cargofaction)
477  lighting = c_lighting;
478 
479  else if (target->getAIState() == NULL)
480  lighting = d_lighting;
481  //Compute relative speed - if it's higher than the maximum, don't accelerate it anymore
482  //FIXME: Should predict the resulting velocity after applying the force,
483  //and adjust the force to match the maximum relative velocity - but the
484  //heterogeneous physics granularity makes it quite hard (it's not owr
485  //own priority the one counting, but the target's).
486  //The current hack - using the target's sim_atom_multiplier, only prevents
487  //aberrations from becoming obvious, but it's not entirely correct.
488  float relspeed = target->GetVelocity()*direction.Cast();
489  if (relspeed < maxrelspeed) {
490  //Modulate force on little mass objects, so they don't slingshot right past you
491  target->ApplyForce( direction
492  *( appldam
493  /sqrt( (target->sim_atom_multiplier
494  > 0) ? target->sim_atom_multiplier : 1.0 )*mymin( 1, target->GetMass() ) ) );
495  }
496  }
497  float ors_m = o_ors_m, trs_m = o_trs_m, ofs = o_o;
498  if (target->faction == owner_faction)
499  ors_m = f_ors_m, trs_m = f_trs_m, ofs = f_o;
500 
501  else if (target->faction == upgradesfaction)
502  ors_m = u_ors_m, trs_m = u_trs_m, ofs = u_o;
503 
504  else if (target->faction == cargofaction)
505  ors_m = c_ors_m, trs_m = c_trs_m, ofs = c_o;
506  if ( ( fi
507  || target->isTractorable( Unit::tractorIn ) )
508  && ( ( center-target->Position() ).Magnitude() < (ors_m*owner_rsize+trs_m*target->rSize()+ofs) ) ) {
509  Unit *un = superunit;
510  if ( target->faction == upgradesfaction || owner_rsize*nbig > target->rSize() ) {
511  //we have our man!
512  //lets add our cargo to him
513  Cargo *c = GetMasterPartList( target->name.get().c_str() );
514  Cargo tmp;
515  bool isnotcargo = (c == NULL);
516  if (!isnotcargo)
517  if (c->GetCategory().find( "upgrades" ) == 0)
518  isnotcargo = true;
519  //add upgrades as space junk
520  if (isnotcargo) {
521  c = &tmp;
522  tmp.content = "Space_Salvage";
523  tmp.category = "Uncategorized_Cargo";
524  static float spacejunk = parse_float( vs_config->getVariable( "cargo", "space_junk_price", "10" ) );
525  tmp.price = spacejunk;
526  tmp.quantity = 1;
527  tmp.mass = .001;
528  tmp.volume = 1;
529  if (target->faction != upgradesfaction) {
530  tmp.content = target->name;
531  tmp.category = "starships";
532  static float starshipprice =
533  XMLSupport::parse_float( vs_config->getVariable( "cargo", "junk_starship_price", "100000" ) );
534  static float starshipmass =
535  XMLSupport::parse_float( vs_config->getVariable( "cargo", "junk_starship_mass", "50" ) );
536  static float starshipvolume =
537  XMLSupport::parse_float( vs_config->getVariable( "cargo", "junk_starship_volume", "1500" ) );
538  tmp.price = starshipprice;
539  tmp.quantity = 1;
540  tmp.mass = starshipmass;
541  tmp.volume = starshipvolume;
542  }
543  }
544  if (c != NULL) {
545  Cargo adder = *c;
546  adder.quantity = 1;
547  if ( un->CanAddCargo( adder ) ) {
548  un->AddCargo( adder );
549  if ( _Universe->isPlayerStarship( un ) ) {
550  static int tractor_onboard =
551  AUDCreateSoundWAV( vs_config->getVariable( "unitaudio", "player_tractor_cargo",
552  "tractor_onboard.wav" ) );
553  AUDPlay( tractor_onboard, QVector( 0, 0, 0 ), Vector( 0, 0, 0 ), 1 );
554  } else {
555  Unit *tmp = _Universe->AccessCockpit()->GetParent();
556  if (tmp && tmp->owner == un) {
557  //Subunit of player (a turret)
558  static int tractor_onboard_fromturret =
559  AUDCreateSoundWAV( vs_config->getVariable( "unitaudio",
560  "player_tractor_cargo_fromturret",
561  "tractor_onboard.wav" ) );
562  AUDPlay( tractor_onboard_fromturret, QVector( 0, 0, 0 ), Vector( 0, 0, 0 ), 1 );
563  }
564  }
565  target->Kill();
566  }
567  }
568  }
569  }
570  } else {
571  target->ApplyDamage( center.Cast()+direction*curlength, normal, appldam, colidee, coltmp, owner, phasdam );
572  }
573  return true;
574  }
575  return false;
576 }
void Beam::Destabilize ( )
inline

Definition at line 81 of file beam.h.

Referenced by Mount::UnFire(), and UpdatePhysics().

82  {
83  impact = UNSTABLE;
84  }
bool Beam::Dissolved ( )
inline

Definition at line 85 of file beam.h.

Referenced by Unit::Fire().

86  {
87  return curthick == 0;
88  }
void Beam::Draw ( const Transformation trans,
const Matrix m,
class Unit target,
float  trackingcone 
)

Definition at line 59 of file beam.cpp.

References AdjustMatrixToTrackTarget(), AUDAdjustSound(), AUDSoundGain(), beamdrawqueue, Transformation::Compose(), Transformation::position, speed, Transformation::to_matrix(), and Vector.

60 {
61  //hope that the correct transformation is on teh stack
62  if (curthick == 0)
63  return;
64  Matrix cumulative_transformation_matrix;
65  local_transformation.to_matrix( cumulative_transformation_matrix );
66  Transformation cumulative_transformation = local_transformation;
67  cumulative_transformation.Compose( trans, m );
68  cumulative_transformation.to_matrix( cumulative_transformation_matrix );
69  AdjustMatrixToTrackTarget( cumulative_transformation_matrix, Vector( 0, 0, 0 ), targ, speed, false, tracking_cone );
70 #ifdef PERFRAMESOUND
71  AUDAdjustSound( sound, cumulative_transformation.position, speed
72  *Vector( cumulative_transformation_matrix[8], cumulative_transformation_matrix[9],
73  cumulative_transformation_matrix[10] ) );
74 #endif
75  AUDSoundGain( sound, curthick*curthick/(thickness*thickness) );
76 
77  beamdrawqueue[decal].push_back( BeamDrawContext( cumulative_transformation_matrix, vlist, this ) );
78 }
QVector Beam::GetPosition ( ) const
inline

Definition at line 66 of file beam.h.

References Transformation::position.

67  {
68  return local_transformation.position;
69  }
void Beam::Init ( const Transformation trans,
const weapon_info clne,
void *  own,
Unit firer 
)

Definition at line 52 of file beam_generic.cpp.

References weapon_info::a, GFXColor::a, AUDStartPlaying(), weapon_info::b, GFXColor::b, LineCollide::BEAM, weapon_info::Damage, float_to_int(), weapon_info::g, GFXColor::g, VegaConfig::getVariable(), GFXQUAD, weapon_info::Longrange, mymax(), LineCollide::object, XMLSupport::parse_int(), weapon_info::PhaseDamage, weapon_info::PulseSpeed, weapon_info::r, GFXColor::r, weapon_info::RadialSpeed, weapon_info::Radius, weapon_info::Range, weapon_info::Refire(), SIMULATION_ATOM, weapon_info::Speed, weapon_info::Stability, weapon_info::TextureStretch, LineCollide::type, and vs_config.

Referenced by Beam(), and Mount::PhysicsAlignedFire().

53 {
54  //Matrix m;
55  CollideInfo.object.b = NULL;
56  CollideInfo.type = LineCollide::BEAM;
57  //DO NOT DELETE - shared vlist
58  //if (vlist)
59  //delete vlist;
60  local_transformation = trans; //location on ship
61  //cumalative_transformation =trans;
62  //trans.to_matrix (cumalative_transformation_matrix);
63  speed = cln.Speed;
64  texturespeed = cln.PulseSpeed;
65  range = cln.Range;
66  radialspeed = cln.RadialSpeed;
67  thickness = cln.Radius;
68  stability = cln.Stability;
69  rangepenalty = cln.Longrange;
70  damagerate = cln.Damage;
71  phasedamage = cln.PhaseDamage;
72  texturestretch = cln.TextureStretch;
73  refiretime = 0;
74  refire = cln.Refire();
75  Col.r = cln.r;
76  Col.g = cln.g;
77  Col.b = cln.b;
78  Col.a = cln.a;
79  impact = ALIVE;
80  owner = own;
81  numframes = 0;
82  static int radslices = XMLSupport::parse_int( vs_config->getVariable( "graphics", "tractor.scoop_rad_slices", "10" ) )|1; //Must be odd
83  static int longslices = XMLSupport::parse_int( vs_config->getVariable( "graphics", "tractor.scoop_long_slices", "10" ) );
84  lastlength = 0;
85  curlength = SIMULATION_ATOM*speed;
86  lastthick = 0;
87  curthick = SIMULATION_ATOM*radialspeed;
88  if (curthick > thickness) //clamp to max thickness - needed for large simulation atoms
89  curthick = thickness;
90  static GFXVertexList *_vlist = 0;
91  if (!_vlist) {
92  int numvertex = float_to_int( mymax( 48, ( (4*radslices)+1 )*longslices*4 ) );
93  GFXColorVertex *beam = new GFXColorVertex[numvertex]; //regretably necessary: radslices and longslices come from the config file... so it's at runtime.
94  memset( beam, 0, sizeof (*beam)*numvertex );
95  _vlist = new GFXVertexList( GFXQUAD, numvertex, beam, numvertex, true ); //mutable color contained list
96  delete[] beam;
97  }
98  //Shared vlist - we recalculate it every time, so no loss
99  vlist = _vlist;
100 #ifdef PERBOLTSOUND
101  AUDStartPlaying( sound );
102 #endif
103 }
void Beam::ListenToOwner ( bool  listen)
inline

Definition at line 57 of file beam.h.

Referenced by Mount::Fire().

58  {
59  listen_to_owner = listen;
60  }
void Beam::ProcessDrawQueue ( )
static

Definition at line 80 of file beam.cpp.

References BeamDrawContext::beam, beamdrawqueue, c, CULLFACE, DEPTHWRITE, GFXVertexList::DrawOnce(), DecalQueue::GetTexture(), VegaConfig::getVariable(), GFXBlendMode(), GFXDisable(), GFXEnable(), GFXLoadMatrixModel(), GFXMODULATETEXTURE, GFXPopBlendMode(), GFXPushBlendMode(), GFXTextureEnv(), GFXToggleTexture(), LIGHTING, BeamDrawContext::m, Texture::MakeActive(), ONE, XMLSupport::parse_bool(), size, TEXTURE0, TEXTURE1, BeamDrawContext::vlist, vs_config, and ZERO.

Referenced by GameStarSystem::Draw().

81 {
83  GFXDisable( CULLFACE ); //don't want lighting on this baby
86  static bool blendbeams = XMLSupport::parse_bool( vs_config->getVariable( "graphics", "BlendGuns", "true" ) );
87  GFXBlendMode( ONE, blendbeams ? ONE : ZERO );
88 
92  for (unsigned int decal = 0; decal < beamdrawqueue.size(); decal++) {
93  Texture *tex = beamdecals.GetTexture( decal );
94  if (tex) {
95  tex->MakeActive( 0 );
97  GFXToggleTexture( true, 0 );
98  if ( beamdrawqueue[decal].size() ) {
99  while ( beamdrawqueue[decal].size() ) {
100  c = beamdrawqueue[decal].back();
101  beamdrawqueue[decal].pop_back();
102 
103  c.beam->RecalculateVertices( c.m );
104  GFXLoadMatrixModel( c.m );
105  c.vlist->DrawOnce();
106  }
107  }
108  }
109  }
111  GFXEnable( CULLFACE );
112  GFXDisable( LIGHTING );
113  GFXPopBlendMode();
114 }
bool Beam::Ready ( )
inline

Definition at line 89 of file beam.h.

Referenced by Mount::ComputeAnimatedFrame(), Mount::Fire(), and Unit::Fire().

90  {
91  return curthick == 0 && refiretime > refire;
92  }
float Beam::refireTime ( )

Definition at line 28 of file beam_generic.cpp.

Referenced by Mount::ComputeAnimatedFrame(), and MountColor().

29 {
30  return refiretime;
31 }
void Beam::RemoveFromSystem ( bool  eradicate)

Definition at line 271 of file beam_generic.cpp.

Referenced by UpdatePhysics(), and ~Beam().

272 {}
void Beam::SetOrientation ( const Vector p,
const Vector q,
const Vector r 
)

Definition at line 38 of file beam_generic.cpp.

References Quaternion::from_vectors(), and Transformation::orientation.

39 {
40  local_transformation.orientation = Quaternion::from_vectors( p, q, r );
41 }
void Beam::SetPosition ( const QVector k)

Definition at line 33 of file beam_generic.cpp.

References Transformation::position.

34 {
35  local_transformation.position = k;
36 }
void Beam::UpdatePhysics ( const Transformation trans,
const Matrix m,
class Unit target,
float  trackingcone,
Unit targetToCollideWith,
float  HeatSink,
Unit firer,
Unit superunit 
)

Definition at line 274 of file beam_generic.cpp.

References AddCollideQueue(), AdjustMatrix(), AUDAdjustSound(), AUDIsPlaying(), AUDStopPlaying(), coltableacc, Transformation::Compose(), Destabilize(), Matrix::getR(), VegaConfig::getVariable(), LineCollide::hhuge, LineCollide::Maxi, LineCollide::Mini, LineCollide::object, XMLSupport::parse_bool(), Transformation::position, QVector, RemoveFromSystem(), SIMULATION_ATOM, tablehuge, TableLocationChanged(), Transformation::to_matrix(), TransformNormal(), Vector, and vs_config.

282 {
283  curlength += SIMULATION_ATOM*speed;
284  if (curlength < 0)
285  curlength = 0;
286  if (curlength > range)
287  curlength = range;
288  if (curthick == 0) {
289  if (AUDIsPlaying( sound ) && refiretime >= SIMULATION_ATOM)
290  AUDStopPlaying( sound );
291  refiretime += SIMULATION_ATOM*HeatSink;
292  return;
293  }
294  if (stability && numframes*SIMULATION_ATOM > stability)
295  impact |= UNSTABLE;
296  numframes++;
297  Matrix cumulative_transformation_matrix;
298  Transformation cumulative_transformation = local_transformation;
299  cumulative_transformation.Compose( trans, m );
300  cumulative_transformation.to_matrix( cumulative_transformation_matrix );
301  bool possible = AdjustMatrix( cumulative_transformation_matrix, Vector( 0, 0, 0 ), targ, speed, false, tracking_cone );
302  static bool firemissingautotrackers =
303  XMLSupport::parse_bool( vs_config->getVariable( "physics", "fire_missing_autotrackers", "true" ) );
304  if (targ && possible == false && !firemissingautotrackers)
305  Destabilize();
306  //to help check for crashing.
307  center = cumulative_transformation.position;
308  direction = TransformNormal( cumulative_transformation_matrix, Vector( 0, 0, 1 ) );
309 #ifndef PERFRAMESOUND
310  AUDAdjustSound( sound, cumulative_transformation.position, speed*cumulative_transformation_matrix.getR() );
311 #endif
312  curthick += (impact&UNSTABLE) ? -radialspeed*SIMULATION_ATOM : radialspeed*SIMULATION_ATOM;
313  if (curthick > thickness)
314  curthick = thickness;
315  if (curthick <= 0) {
316  curthick = 0; //die die die
317 #ifdef BEAMCOLQ
318  RemoveFromSystem( false );
319 #endif
320  } else {
321  CollideHuge( CollideInfo, listen_to_owner ? targetToCollideWith : NULL, firer, superunit );
322  if ( !(curlength <= range && curlength > 0) ) {
323  //if curlength just happens to be nan --FIXME THIS MAKES NO SENSE AT ALL --chuck_starchaser
324  if (curlength > range)
325  curlength = range;
326  else
327  curlength = 0;
328  }
329  QVector tmpvec( center+direction.Cast().Scale( curlength ) );
330  QVector tmpMini = center.Min( tmpvec );
331  tmpvec = center.Max( tmpvec );
332 #ifdef BEAMCOLQ
333  if ( TableLocationChanged( CollideInfo, tmpMini, tmpvec ) || (curthick > 0 && CollideInfo.object.b == NULL) ) {
334  RemoveFromSystem( false );
335 #endif
336  CollideInfo.object.b = this;
337  CollideInfo.hhuge =
338  ( ( (CollideInfo.Maxi.i
339  -CollideInfo.Mini.i)
340  /coltableacc )
341  *( (CollideInfo.Maxi.j-CollideInfo.Mini.j)/coltableacc )*(CollideInfo.Maxi.k-CollideInfo.Mini.k)/coltableacc
342  > tablehuge );
343  CollideInfo.Mini = tmpMini;
344  CollideInfo.Maxi = tmpvec;
345 #ifdef BEAMCOLQ
346  AddCollideQueue( CollideInfo );
347  } else {
348  CollideInfo.Mini = tmpMini;
349  CollideInfo.Maxi = tmpvec;
350  }
351 #endif
352  }
353  //Check if collide...that'll change max beam length REAL quick
354 }

The documentation for this class was generated from the following files: