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
unit.cpp File Reference
#include "unit.h"
#include "vsfilesystem.h"
#include "vs_globals.h"
#include "file_main.h"
#include "gfx/halo.h"
#include "gfx/halo_system.h"
#include "gfx/quaternion.h"
#include "gfx/matrix.h"
#include "gfx/technique.h"
#include "unit_factory.h"
#include "gfx/sprite.h"
#include "lin_time.h"
#include "gfx/vsbox.h"
#include "bolt.h"
#include "gfx/lerp.h"
#include "audiolib.h"
#include "gfx/cockpit.h"
#include "config_xml.h"
#include "images.h"
#include "main_loop.h"
#include "script/mission.h"
#include "script/flightgroup.h"
#include "savegame.h"
#include "xml_serializer.h"
#include "python/python_class.h"
#include "cmd/ai/missionscript.h"
#include "gfx/particle.h"
#include "cmd/ai/aggressive.h"
#include "cmd/base.h"
#include "gfx/point_to_cam.h"
#include "base_util.h"
#include "unit_jump.h"
#include "unit_customize.h"
#include "unit_damage.h"
#include "unit_physics.h"
#include "unit_click.h"
#include "beam.h"
#include "python/init.h"
#include "unit_const_cache.h"
#include "cmd/asteroid_generic.h"
#include "cmd/building_generic.h"
#include "cmd/planet_generic.h"
#include "cmd/unit_generic.h"
#include "cmd/missile_generic.h"
#include "cmd/nebula.h"
#include "cmd/enhancement.h"

Go to the source code of this file.

Macros

#define PARANOIA   .4
 

Functions

string getCargoUnitName (const char *name)
 
static float perspectiveFactor (float d)
 
bool flickerDamage (Unit *un, float hullpercent)
 
int cloakVal (int cloakint, int cloakminint, int cloakrateint, bool cloakglass)
 
double calc_blend_factor (double frac, int priority, int when_it_will_be_simulated, int cur_simulation_frame)
 
static float parseFloat (const std::string &s)
 
static void parseFloat4 (const std::string &s, float value[4])
 

Variables

double interpolation_blend_factor
 
double saved_interpolation_blend_factor
 
bool cam_setup_phase
 

Macro Definition Documentation

#define PARANOIA   .4

Definition at line 128 of file unit.cpp.

Function Documentation

double calc_blend_factor ( double  frac,
int  priority,
int  when_it_will_be_simulated,
int  cur_simulation_frame 
)
int cloakVal ( int  cloakint,
int  cloakminint,
int  cloakrateint,
bool  cloakglass 
)

Definition at line 23 of file unit_functions_generic.cpp.

Referenced by GameUnit< UnitType >::Draw(), and GameUnit< UnitType >::DrawNow().

24 {
25  //Short fix ?
26  if (cloak < 0 && cloakrate < 0)
27  cloak = -2147483647-1; //intended warning should be max neg :-) leave it be
28  if (cloak < cloakmin && cloakrate > 0)
29  cloak = cloakmin;
30  if ( (cloak&0x1) && !cloakglass )
31  cloak -= 1;
32  if ( (cloak&0x1) == 0 && cloakglass )
33  cloak += 1;
34  return cloak;
35 }
bool flickerDamage ( Unit un,
float  hullpercent 
)

Definition at line 317 of file unit_generic.cpp.

References damagelevel, flickertime, GetElapsedTime(), getNewTime(), VegaConfig::getVariable(), int, XMLSupport::parse_float(), and vs_config.

Referenced by GameUnit< UnitType >::Draw().

318 {
319 #define damagelevel hullpercent
320  static double counter = getNewTime();
321  static float flickertime = XMLSupport::parse_float( vs_config->getVariable( "graphics", "glowflicker", "time", "30" ) );
322  static float flickerofftime =
323  XMLSupport::parse_float( vs_config->getVariable( "graphics", "glowflicker", "off-time", "2" ) );
324  static float minflickercycle =
325  XMLSupport::parse_float( vs_config->getVariable( "graphics", "glowflicker", "min-cycle", "2" ) );
326  static float flickeronprob =
327  XMLSupport::parse_float( vs_config->getVariable( "graphics", "glowflicker", "num-times-per-second-on", ".66" ) );
328  static float hullfornoflicker =
329  XMLSupport::parse_float( vs_config->getVariable( "graphics", "glowflicker", "hull-for-total-dark", ".04" ) );
330  float diff = getNewTime()-counter;
331  if (diff > flickertime) {
332  counter = getNewTime();
333  diff = 0;
334  }
335  float tmpflicker = flickertime*damagelevel;
336  if (tmpflicker < minflickercycle)
337  tmpflicker = minflickercycle;
338  diff = fmod( diff, tmpflicker );
339  //we know counter is somewhere between 0 and damage level
340  //cast this to an int for fun!
341  unsigned int thus = ( (unsigned int) (size_t) un )>>2;
342  thus = thus%( (unsigned int) tmpflicker );
343  diff = fmod( diff+thus, tmpflicker );
344  if (flickerofftime > diff) {
345  if (damagelevel > hullfornoflicker)
346  return rand() > RAND_MAX * GetElapsedTime()*flickeronprob;
347  else
348  return true;
349  }
350  return false;
351 
352 #undef damagelevel
353 }
string getCargoUnitName ( const char *  name)

Definition at line 19 of file planet_generic.cpp.

References getnoslash(), and i.

Referenced by GameUnit< UnitType >::UpgradeInterface().

20 {
21  char *tmp2 = strdup( textname );
22  char *tmp = getnoslash( tmp2 );
23  unsigned int i;
24  for (i = 0; tmp[i] != '\0' && (isalpha( tmp[i] ) || tmp[i] == '_'); i++) {}
25  if (tmp[i] != '\0')
26  tmp[i] = '\0';
27  string retval( tmp );
28  free( tmp2 );
29  return retval;
30 }
static float parseFloat ( const std::string &  s)
static

Definition at line 594 of file unit.cpp.

References XMLSupport::parse_floatf(), and VSFileSystem::vs_dprintf().

Referenced by __impl::parseFloat4(), and parseFloat4().

595 {
596  if ( s.empty() ) {
597  VSFileSystem::vs_dprintf(1, "WARNING: invalid float: %s\n", s.c_str());
598  return 0.f;
599  } else {
600  return XMLSupport::parse_floatf( s );
601  }
602 }
static void parseFloat4 ( const std::string &  s,
float  value[4] 
)
static

Definition at line 604 of file unit.cpp.

References i, parseFloat(), and VSFileSystem::vs_dprintf().

Referenced by GameUnit< UnitType >::applyTechniqueOverrides().

605 {
606  string::size_type ini = 0, end;
607  int i = 0;
608  while (i < 4 && ini != string::npos) {
609  value[i++] = parseFloat( s.substr( ini, end = s.find_first_of( ',', ini ) ) );
610  ini = ( (end == string::npos) ? end : (end+1) );
611  }
612  if (i >= 4 && ini != string::npos)
613  VSFileSystem::vs_dprintf(1, "WARNING: invalid float4: %s\n", s.c_str());
614  while (i < 4)
615  value[i++] = 0;
616 }
static float perspectiveFactor ( float  d)
inlinestatic

Definition at line 130 of file unit.cpp.

References g_game, GFXGetZPerspective(), and game_data_t::x_resolution.

Referenced by GameUnit< UnitType >::Draw(), and GameUnit< UnitType >::DrawNow().

131 {
132  if (d > 0)
134  else
135  return 1.0f;
136 }

Variable Documentation

bool cam_setup_phase

Definition at line 21 of file unit_functions_generic.cpp.

Referenced by GameStarSystem::Draw(), and GameUnit< UnitType >::Draw().

double interpolation_blend_factor

Definition at line 20 of file unit_functions_generic.cpp.

double saved_interpolation_blend_factor