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

#include <bolt.h>

Public Member Functions

bool Collide (Unit *target)
 
bool operator== (const Bolt &b) const
 
 Bolt (const weapon_info *type, const Matrix &orientationpos, const Vector &ShipSpeed, void *owner, CollideMap::iterator hint)
 
void Destroy (unsigned int index)
 
bool Update (Collidable::CollideRef index)
 
bool Collide (Collidable::CollideRef index)
 
void noop () const
 

Static Public Member Functions

static int AddTexture (bolt_draw *q, std::string filename)
 
static int AddAnimation (bolt_draw *q, std::string filename, QVector cur_position)
 
static bool CollideAnon (Collidable::CollideRef bolt_name, Unit *target)
 
static BoltBoltFromIndex (StarSystem *ss, Collidable::CollideRef bolt_name)
 
static Collidable::CollideRef BoltIndex (int index, int decal, bool isBall)
 
static void Draw ()
 
static void UpdatePhysics (StarSystem *ss)
 

Public Attributes

CollideMap::iterator location
 

Detailed Description

Definition at line 13 of file bolt.h.

Constructor & Destructor Documentation

Bolt::Bolt ( const weapon_info type,
const Matrix orientationpos,
const Vector ShipSpeed,
void *  owner,
CollideMap::iterator  hint 
)

Definition at line 17 of file bolt_generic.cpp.

References _Universe, Universe::activeStarSystem(), AddAnimation(), AddTexture(), bolt_draw::balls, weapon_info::BOLT, BoltIndex(), bolt_draw::bolts, StarSystem::bolts, StarSystem::collidemap, CopyMatrix(), weapon_info::file, Matrix::getR(), CollideArray::insert(), weapon_info::Length, location, Magnitude(), UnitUtil::owner(), q, weapon_info::Radius, ScaleMatrix(), SIMULATION_ATOM, size, weapon_info::Speed, weapon_info::type, Unit::UNIT_BOLT, Vector, and VSCONSTRUCT2.

21  : cur_position( orientationpos.p )
22  , ShipSpeed( shipspeed )
23 {
24  VSCONSTRUCT2( 't' )
25  bolt_draw*q = _Universe->activeStarSystem()->bolts;
26  prev_position = cur_position;
27  this->owner = owner;
28  this->type = typ;
29  curdist = 0;
30  CopyMatrix( drawmat, orientationpos );
31  Vector vel = shipspeed+orientationpos.getR()*typ->Speed;
32  if (typ->type == weapon_info::BOLT) {
33  ScaleMatrix( drawmat, Vector( typ->Radius, typ->Radius, typ->Length ) );
34  decal = Bolt::AddTexture( q, typ->file );
35  this->location =
37  size(),
38  decal,
39  false ).bolt_index,
40  (shipspeed+orientationpos.getR()
41  *typ->Speed).Magnitude()*.5,
42  cur_position+vel*SIMULATION_ATOM*.5 ),
43  hint );
44  q->bolts[decal].push_back( *this );
45  } else {
46  ScaleMatrix( drawmat, Vector( typ->Radius, typ->Radius, typ->Radius ) );
47  decal = Bolt::AddAnimation( q, typ->file, cur_position );
48 
49  this->location =
51  size(),
52  decal,
53  true ).bolt_index,
54  (shipspeed+orientationpos.getR()
55  *typ->Speed).Magnitude()*.5,
56  cur_position+vel*SIMULATION_ATOM*.5 ),
57  hint );
58  q->balls[decal].push_back( *this );
59  }
60 }

Member Function Documentation

int Bolt::AddAnimation ( bolt_draw q,
std::string  filename,
QVector  cur_position 
)
static

Definition at line 79 of file bolt.cpp.

References bolt_draw::animationname, bolt_draw::animations, bolt_draw::balls, i, and MIPMAP.

Referenced by Bolt().

80 {
81  int decal = -1;
82  for (unsigned int i = 0; i < q->animationname.size(); i++)
83  if (file == q->animationname[i])
84  decal = i;
85  if (decal == -1) {
86  decal = q->animations.size();
87  q->animationname.push_back( file );
88  q->animations.push_back( new Animation( file.c_str(), true, .1, MIPMAP, false ) ); //balls have their own orientation
89  q->animations.back()->SetPosition( cur_position );
90  q->balls.push_back( vector< Bolt > () );
91  }
92  return decal;
93 }
int Bolt::AddTexture ( bolt_draw q,
std::string  filename 
)
static

Definition at line 67 of file bolt.cpp.

References DecalQueue::AddTexture(), bolt_draw::boltdecals, bolt_draw::bolts, bolt_draw::cachedecals, and MIPMAP.

Referenced by Bolt().

68 {
69  int decal = q->boltdecals->AddTexture( file.c_str(), MIPMAP );
70  if ( decal >= (int) q->bolts.size() ) {
71  q->bolts.push_back( vector< Bolt > () );
72  int blargh = q->boltdecals->AddTexture( file.c_str(), MIPMAP );
73  if ( blargh >= (int) q->bolts.size() )
74  q->bolts.push_back( vector< Bolt > () );
75  q->cachedecals.push_back( blargh );
76  }
77  return decal;
78 }
Bolt * Bolt::BoltFromIndex ( StarSystem ss,
Collidable::CollideRef  bolt_name 
)
static

Definition at line 174 of file bolt_generic.cpp.

References bolt_draw::balls, Collidable::CollideRef::bolt_index, bolt_draw::bolts, StarSystem::bolts, and nondecal_index().

Referenced by CollideAnon(), UpdateBolt::operator()(), and UpdateBackpointers< Unit::UNIT_ONLY >::updateBackpointer().

175 {
176  size_t ind = nondecal_index( b );
177  if (b.bolt_index&128)
178  return &ss->bolts->balls[b.bolt_index&0x7f][ind];
179  else
180  return &ss->bolts->bolts[b.bolt_index&0x7f][ind];
181 }
Collidable::CollideRef Bolt::BoltIndex ( int  index,
int  decal,
bool  isBall 
)
static

Definition at line 193 of file bolt_generic.cpp.

References Collidable::CollideRef::bolt_index, and index.

Referenced by Bolt().

194 {
196  temp.bolt_index = index;
197  temp.bolt_index <<= 8;
198  temp.bolt_index |= decal;
199  temp.bolt_index |= isBall ? 128 : 0;
200  return temp;
201 }
bool Bolt::Collide ( Unit target)

Definition at line 140 of file bolt_generic.cpp.

References Unit::ApplyDamage(), ASTEROIDPTR, Unit::GetDestinations(), VegaConfig::getVariable(), Unit::isUnit(), NEBULAPTR, XMLSupport::parse_bool(), PLANETPTR, QVector, Unit::rayCollide(), Vector, and vs_config.

Referenced by CollideChecker< T, canbebolt >::CheckCollision(), and CollideAnon().

141 {
142  Vector normal;
143  float distance;
144  Unit *affectedSubUnit;
145  if ( ( affectedSubUnit = target->rayCollide( prev_position, cur_position, normal, distance ) ) ) {
146  //ignore return
147  if (target == owner) return false;
148  enum clsptr type = target->isUnit();
149  if (type == NEBULAPTR || type == ASTEROIDPTR) {
150  static bool collideroids =
151  XMLSupport::parse_bool( vs_config->getVariable( "physics", "AsteroidWeaponCollision", "false" ) );
152  if ( type != ASTEROIDPTR || (!collideroids) )
153  return false;
154  }
155  static bool collidejump = XMLSupport::parse_bool( vs_config->getVariable( "physics", "JumpWeaponCollision", "false" ) );
156  if ( type == PLANETPTR && (!collidejump) && !target->GetDestinations().empty() )
157  return false;
158  QVector tmp = (cur_position-prev_position).Normalize();
159  tmp = tmp.Scale( distance );
160  distance = curdist/this->type->Range;
161  GFXColor coltmp( this->type->r, this->type->g, this->type->b, this->type->a );
162  target->ApplyDamage( (prev_position+tmp).Cast(),
163  normal,
164  this->type->Damage*( (1-distance)+distance*this->type->Longrange ),
165  affectedSubUnit,
166  coltmp,
167  owner,
168  this->type->PhaseDamage*( (1-distance)+distance*this->type->Longrange ) );
169  return true;
170  }
171  return false;
172 }
bool Bolt::CollideAnon ( Collidable::CollideRef  bolt_name,
Unit target 
)
static

Definition at line 183 of file bolt_generic.cpp.

References _Universe, Universe::activeStarSystem(), b, BoltFromIndex(), Collide(), Destroy(), and nondecal_index().

Referenced by CollideChecker< T, canbebolt >::CheckCollision().

184 {
186  if ( tmp->Collide( un ) ) {
187  tmp->Destroy( nondecal_index( b ) );
188  return true;
189  }
190  return false;
191 }
void Bolt::Destroy ( unsigned int  index)

Definition at line 195 of file bolt.cpp.

References _Universe, Universe::activeStarSystem(), weapon_info::BOLT, bolt_draw::boltdecals, BoltDestroyGeneric(), StarSystem::bolts, DecalQueue::DelTexture(), q, weapon_info::type, and VSDESTRUCT2.

Referenced by CollideChecker< T, canbebolt >::CheckCollision(), CollideAnon(), and Update().

196 {
199  bool isBall = true;
200  if (type->type == weapon_info::BOLT) {
201  q->boltdecals->DelTexture( decal );
202  isBall = false;
203  } else {}
204  BoltDestroyGeneric( this, index, decal, isBall );
205 }
void Bolt::Draw ( )
static

Definition at line 95 of file bolt.cpp.

References _Universe, weapon_info::a, Universe::AccessCamera(), Universe::activeStarSystem(), ALWAYS, bolt_draw::animations, weapon_info::b, bolt_draw::balls, GFXVertexList::BeginDrawState(), BlendTrans(), bolt_draw::boltdecals, bolt_draw::boltmesh, bolt_draw::bolts, StarSystem::bolts, CULLFACE, DEPTHTEST, DEPTHWRITE, GFXVertexList::Draw(), Animation::DrawNoTransform(), GFXVertexList::EndDrawState(), game_data_t::fov, weapon_info::g, g_game, GetElapsedTime(), Camera::GetOrientation(), Camera::GetPosition(), DecalQueue::GetTexture(), VegaConfig::getVariable(), GFXAlphaTest(), GFXBlendMode(), GFXColor4f(), GFXDisable(), GFXEnable(), GFXLoadMatrixModel(), GFXToggleTexture(), GREATER, i, j, k, weapon_info::Length, LIGHTING, GFXVertexList::LoadDrawState(), M_PI, Texture::MakeActive(), ONE, Matrix::p, XMLSupport::parse_bool(), XMLSupport::parse_float(), q, QVector, weapon_info::r, weapon_info::Radius, ScaleMatrix(), Animation::SetDimensions(), UniverseUtil::sin(), weapon_info::Speed, TEXTURE0, TEXTURE1, Vector, VectorAndPositionToMatrix(), vs_config, wt, game_data_t::x_resolution, game_data_t::y_resolution, and ZERO.

Referenced by GameStarSystem::Draw().

96 {
100 
101  static bool blendbeams = XMLSupport::parse_bool( vs_config->getVariable( "graphics", "BlendGuns", "true" ) );
102  static float stretchbolts = XMLSupport::parse_float( vs_config->getVariable( "graphics", "StretchBolts", "0" ) ); //set DEFAULT TO BE ZERO--it was wrecking all the mods.
103 
104  GFXBlendMode( ONE, blendbeams ? ONE : ZERO );
105 
107  GFXDisable( TEXTURE1 );
108  GFXEnable( TEXTURE0 );
109  GFXAlphaTest( GREATER, .1 );
110  vector< vector< Bolt > >::iterator i;
111  vector< Bolt >::iterator j;
112  vector< Animation* >::iterator k = qq->animations.begin();
113  float etime = GetElapsedTime();
114  static float bolt_constant = XMLSupport::parse_float( vs_config->getVariable( "graphics", "bolt_pixel_size", ".5" ) );
115  float pixel_angle = 2
116  *sin( g_game.fov*M_PI/180.0
118  > g_game.x_resolution ? g_game.y_resolution : g_game.x_resolution) )*bolt_constant;
119  pixel_angle *= pixel_angle;
120  Vector p, q, r;
121  _Universe->AccessCamera()->GetOrientation( p, q, r );
122  QVector campos = _Universe->AccessCamera()->GetPosition();
123  for (i = qq->balls.begin(); i != qq->balls.end(); i++, k++) {
124  Animation *cur = *k;
125  if ( i->begin() != i->end() ) {
126  float bolt_size = 2*i->begin()->type->Radius*2;
127  bolt_size *= bolt_size;
128  //Matrix result;
129  //FIXME::MuST USE DRAWNO TRANSFORMNOW cur->CalculateOrientation (result);
130  for (j = i->begin(); j != i->end(); j++) {
131  //don't update time more than once
132  Bolt *bolt = &*j;
133  float distance = (bolt->cur_position-campos).MagnitudeSquared();
134  if (distance*pixel_angle < bolt_size) {
135  const weapon_info *type = bolt->type;
136  BlendTrans( bolt->drawmat, bolt->cur_position, bolt->prev_position );
137  Matrix tmp;
138  VectorAndPositionToMatrix( tmp, p, q, r, bolt->drawmat.p );
139  cur->SetDimensions( bolt->type->Radius, bolt->type->Radius );
140  GFXLoadMatrixModel( tmp );
141  GFXColor4f( type->r, type->g, type->b, type->a );
142  cur->DrawNoTransform( false, true );
143  }
144  }
145  }
146  }
147  GFXAlphaTest( ALWAYS, 0 );
149  GFXDisable( TEXTURE1 );
150  if (blendbeams == true)
151  GFXBlendMode( ONE, ONE );
152  else
153  GFXBlendMode( ONE, ZERO );
154  GFXVertexList *qmesh = qq->boltmesh;
155  if (qmesh) {
156  qmesh->LoadDrawState();
157  qmesh->BeginDrawState();
158  int decal = 0;
159  for (i = qq->bolts.begin(); i != qq->bolts.end(); decal++, i++) {
160  Texture *dec = qq->boltdecals->GetTexture( decal );
161  if ( dec && i->begin() != i->end() ) {
162  float bolt_size = 2*i->begin()->type->Radius+i->begin()->type->Length;
163  bolt_size *= bolt_size;
164  dec->MakeActive();
165  GFXToggleTexture( true, 0 );
166  for (j = i->begin(); j != i->end(); j++) {
167  Bolt &bolt = *j;
168  float distance = (bolt.cur_position-campos).MagnitudeSquared();
169  if (distance*pixel_angle < bolt_size) {
170  const weapon_info *wt = bolt.type;
171 
172  BlendTrans( bolt.drawmat, bolt.cur_position, bolt.prev_position );
173  Matrix drawmat( bolt.drawmat );
174  if (stretchbolts > 0)
175  ScaleMatrix( drawmat, Vector( 1, 1, bolt.type->Speed*etime*stretchbolts/bolt.type->Length ) );
176  GFXLoadMatrixModel( drawmat );
177  GFXColor4f( wt->r, wt->g, wt->b, wt->a );
178  qmesh->Draw();
179  }
180  }
181  }
182  }
183  qmesh->EndDrawState();
184  }
185  GFXEnable( LIGHTING );
186  GFXEnable( CULLFACE );
187  GFXBlendMode( ONE, ZERO );
188  GFXEnable( DEPTHTEST );
190  GFXEnable( TEXTURE0 );
191  GFXColor4f( 1, 1, 1, 1 );
192 }
void Bolt::noop ( ) const
inline

Definition at line 44 of file bolt.h.

44 {}
bool Bolt::operator== ( const Bolt b) const
inline

Definition at line 31 of file bolt.h.

31  {
32 
33  return owner==b.owner
34  &&curdist==b.curdist
35  &&cur_position==b.cur_position
36  &&prev_position==b.prev_position;
37  }
bool Bolt::Update ( Collidable::CollideRef  index)

Definition at line 67 of file bolt_generic.cpp.

References _Universe, Universe::activeStarSystem(), weapon_info::BALL, CollideArray::changeKey(), StarSystem::collidemap, Destroy(), Matrix::getR(), weapon_info::Length, location, nondecal_index(), weapon_info::Radius, weapon_info::Range, Collidable::SetPosition(), SIMULATION_ATOM, weapon_info::Speed, speed, weapon_info::type, and Unit::UNIT_BOLT.

Referenced by UpdateBolt::operator()().

68 {
69  const weapon_info *type = this->type;
70  float speed = type->Speed;
71  curdist += speed*SIMULATION_ATOM;
72  prev_position = cur_position;
73  cur_position +=
74  ( ( ShipSpeed+drawmat.getR()*speed
75  /( (type->type
76  == weapon_info::BALL)*type->Radius+(type->type != weapon_info::BALL)*type->Length ) ).Cast()*SIMULATION_ATOM );
77  if (curdist > type->Range) {
78  this->Destroy( nondecal_index( index ) ); //risky
79  return false;
80  }
81  Collidable updated( **location );
82  updated.SetPosition( .5*(prev_position+cur_position) );
84  return true;
85 }
void Bolt::UpdatePhysics ( StarSystem ss)
static

Definition at line 133 of file bolt_generic.cpp.

References StarSystem::collidemap, vsalg::for_each(), CollideArray::sorted, CollideArray::toflattenhints, and Unit::UNIT_BOLT.

Referenced by StarSystem::UpdateUnitPhysics().

134 {
136  vsalg::for_each( cm->sorted.begin(), cm->sorted.end(), UpdateBolt( ss, cm ) );
137  vsalg::for_each( cm->toflattenhints.begin(), cm->toflattenhints.end(), UpdateBolts( ss, cm ) );
138 }

Member Data Documentation


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