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
warpto.cpp File Reference
#include "cmd/unit_generic.h"
#include "cmd/unit_util.h"
#include "universe_util.h"
#include "config_xml.h"

Go to the source code of this file.

Functions

float max_allowable_travel_time ()
 
bool DistanceWarrantsWarpTo (Unit *parent, float dist, bool following)
 
bool DistanceWarrantsTravelTo (Unit *parent, float dist, bool following)
 
bool TargetWorthPursuing (Unit *parent, Unit *target)
 
static void ActuallyWarpTo (Unit *parent, const QVector &tarpos, Vector tarvel, Unit *MatchSpeed=NULL)
 
void WarpToP (Unit *parent, Unit *target, bool following)
 
void WarpToP (Unit *parent, const QVector &target, float radius, bool following)
 

Function Documentation

static void ActuallyWarpTo ( Unit parent,
const QVector tarpos,
Vector  tarvel,
Unit MatchSpeed = NULL 
)
static

Definition at line 57 of file warpto.cpp.

References Unit::computer, Unit::cumulative_transformation_matrix, Matrix::getR(), VegaConfig::getVariable(), Unit::GetVelocity(), Unit::graphicOptions, Unit::graphic_options::InWarp, XMLSupport::parse_bool(), XMLSupport::parse_float(), Unit::Position(), UnitContainer::SetUnit(), Vector, Unit::Computer::velocity_ref, vs_config, Unit::WarpEnergyData(), and Unit::graphic_options::WarpRamping.

Referenced by WarpToP().

58 {
59  Vector vel = parent->GetVelocity();
60  static float mindirveldot = XMLSupport::parse_float( vs_config->getVariable( "AI", "warp_cone", ".8" ) );
61  static float mintarveldot = XMLSupport::parse_float( vs_config->getVariable( "AI", "match_velocity_cone", "-.8" ) );
62  tarvel.Normalize();
63  vel.Normalize();
64  Vector dir = tarpos-parent->Position();
65  dir.Normalize();
66  float dirveldot = dir.Dot( parent->cumulative_transformation_matrix.getR() );
67  dir *= -1;
68  float chasedot = dir.Dot( tarvel );
69  if (dirveldot > mindirveldot) {
70  static float min_energy_to_enter_warp =
71  XMLSupport::parse_float( vs_config->getVariable( "AI", "min_energy_to_enter_warp", ".33" ) );
72  if (parent->WarpEnergyData() > min_energy_to_enter_warp) {
73  if (parent->graphicOptions.InWarp == 0) {
74  parent->graphicOptions.InWarp = 1; //don't want the AI thrashing
75  parent->graphicOptions.WarpRamping = 1; //don't want the AI thrashing
76  }
77  }
78  } else {
79  parent->graphicOptions.InWarp = 0;
80  }
81  static bool domatch = XMLSupport::parse_bool( vs_config->getVariable( "AI", "match_velocity_of_pursuant", "false" ) );
82  if (chasedot > mintarveldot || !domatch)
83  parent->computer.velocity_ref.SetUnit( NULL );
84  else
85  parent->computer.velocity_ref.SetUnit( MatchSpeed );
86 }
bool DistanceWarrantsTravelTo ( Unit parent,
float  dist,
bool  following 
)

Definition at line 41 of file warpto.cpp.

References Unit::GetComputerData(), Unit::GetVelocityDifficultyMult(), max_allowable_travel_time(), and Unit::Computer::max_combat_speed.

Referenced by Orders::DockingOps::Movement().

42 {
43  //first let us decide whether the target is far enough to warrant using warp
44  float diff = 1;
45  parent->GetVelocityDifficultyMult( diff );
46  float timetolive = dist/(diff*parent->GetComputerData().max_combat_speed);
47  if ( timetolive > max_allowable_travel_time() )
48  return true;
49  return false;
50 }
bool DistanceWarrantsWarpTo ( Unit parent,
float  dist,
bool  following 
)

Definition at line 12 of file warpto.cpp.

References Unit::GetComputerData(), VegaConfig::getVariable(), Unit::GetVelocityDifficultyMult(), Unit::GetWarpVelocity(), max_allowable_travel_time(), Unit::Computer::max_combat_speed, XMLSupport::parse_bool(), XMLSupport::parse_float(), SIMULATION_ATOM, and vs_config.

Referenced by Orders::AutoLongHaul::Execute(), and WarpToP().

13 {
14  //first let us decide whether the target is far enough to warrant using warp
15  //double dist =UnitUtil::getSignificantDistance(parent,target);
16  static float tooclose = XMLSupport::parse_float( vs_config->getVariable( "AI", "too_close_for_warp_tactic", "13000" ) );
17  static float tooclosefollowing =
18  XMLSupport::parse_float( vs_config->getVariable( "AI", "too_close_for_warp_in_formation", "1500" ) );
19  float toodamnclose = following ? tooclosefollowing : tooclose;
20  float diff = 1;
21  parent->GetVelocityDifficultyMult( diff );
22  float timetolive = dist/(diff*parent->GetComputerData().max_combat_speed);
23  if ( timetolive > ( 5*max_allowable_travel_time() ) ) {
24  return true;
25  } else if ( timetolive > ( max_allowable_travel_time() ) ) {
26  float mytime = SIMULATION_ATOM*1.5;
27  static bool rampdown = XMLSupport::parse_bool( vs_config->getVariable( "physics", "autopilot_ramp_warp_down", "true" ) );
28  if (rampdown == false) {
29  static float warprampdowntime =
30  XMLSupport::parse_float( vs_config->getVariable( "physics", "warprampdowntime", "0.5" ) );
31  mytime = warprampdowntime;
32  }
33  if (dist-parent->GetWarpVelocity().Magnitude()*mytime < toodamnclose)
34  return false; //avoid nasty jitter-jumping behavior should eventually have "running away check"
35 
36  return true;
37  }
38  return false;
39 }
float max_allowable_travel_time ( )

Definition at line 6 of file warpto.cpp.

References VegaConfig::getVariable(), XMLSupport::parse_float(), and vs_config.

Referenced by DistanceWarrantsTravelTo(), and DistanceWarrantsWarpTo().

7 {
8  static float mat = XMLSupport::parse_float( vs_config->getVariable( "AI", "max_allowable_travel_time", "15" ) );
9  return mat;
10 }
bool TargetWorthPursuing ( Unit parent,
Unit target 
)

Definition at line 52 of file warpto.cpp.

Referenced by WarpToP().

53 {
54  return true;
55 }
void WarpToP ( Unit parent,
Unit target,
bool  following 
)

Definition at line 88 of file warpto.cpp.

References ActuallyWarpTo(), Unit::AutoPilotTo(), DistanceWarrantsWarpTo(), UnitUtil::getSignificantDistance(), VegaConfig::getVariable(), Unit::GetVelocity(), Unit::graphicOptions, Unit::graphic_options::InWarp, XMLSupport::parse_bool(), Unit::Position(), TargetWorthPursuing(), and vs_config.

Referenced by Orders::AggressiveAI::Execute(), Orders::FormUp::Execute(), Orders::FormUpToOwner::Execute(), FlyTo::Execute(), Orders::AggressiveAI::ExecuteNoEnemies(), and Orders::DockingOps::Movement().

89 {
90  float dist = UnitUtil::getSignificantDistance( parent, target );
91  if ( DistanceWarrantsWarpTo( parent, dist, following ) ) {
92  if ( TargetWorthPursuing( parent, target ) ) {
93  static bool auto_valid =
94  XMLSupport::parse_bool( vs_config->getVariable( "physics", "insystem_jump_or_timeless_auto-pilot", "false" ) );
95  if (auto_valid) {
96  std::string tmp;
97  parent->AutoPilotTo( target, false );
98  } else {
99  ActuallyWarpTo( parent, target->Position(), target->GetVelocity(), target );
100  }
101  }
102  } else {
103  parent->graphicOptions.InWarp = 0;
104  }
105 }
void WarpToP ( Unit parent,
const QVector target,
float  radius,
bool  following 
)

Definition at line 107 of file warpto.cpp.

References ActuallyWarpTo(), DistanceWarrantsWarpTo(), VegaConfig::getVariable(), Unit::graphicOptions, Unit::graphic_options::InWarp, Magnitude(), XMLSupport::parse_bool(), Unit::Position(), QVector, Unit::rSize(), and vs_config.

108 {
109  float dist = (parent->Position()-target).Magnitude()-radius-parent->rSize();
110  if ( DistanceWarrantsWarpTo( parent, dist, following ) ) {
111  static bool auto_valid =
112  XMLSupport::parse_bool( vs_config->getVariable( "physics", "insystem_jump_or_timeless_auto-pilot", "false" ) );
113  if (!auto_valid)
114  ActuallyWarpTo( parent, target, QVector( 0, 0, .00001 ) );
115  } else {
116  parent->graphicOptions.InWarp = 0;
117  }
118 }