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

#include <pilot.h>

Public Types

typedef vsUMap< const void
*, float
relationmap
 

Public Member Functions

 Pilot (int faction)
 
virtual ~Pilot ()
 
void SetComm (Unit *comm_unit)
 
AnimationgetCommFace (Unit *parent, float moon, unsigned char &gender)
 
float getReactionTime ()
 
unsigned char getGender ()
 
float getRank ()
 
float getAnger (const Unit *parent, const Unit *un) const
 
std::vector< Animation * > * getCommFaces (unsigned char &sex)
 
float GetEffectiveRelationship (const Unit *parent, const Unit *target) const
 
float adjustSpecificRelationship (Unit *parent, void *aggressor, float value, int guessedFaction)
 
void DoHit (Unit *parent, void *aggressor, int guessedFaction)
 

Public Attributes

relationmap effective_relationship
 
std::vector< Animation * > * comm_face
 

Detailed Description

Definition at line 7 of file pilot.h.

Member Typedef Documentation

typedef vsUMap< const void*, float > Pilot::relationmap

Definition at line 30 of file pilot.h.

Constructor & Destructor Documentation

Pilot::Pilot ( int  faction)
explicit

Definition at line 10 of file pilot.cpp.

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

11 {
12  static float reaction = XMLSupport::parse_float( vs_config->getVariable( "AI", "Firing", "ReactionTime", ".2" ) );
13  static float ran = XMLSupport::parse_float( vs_config->getVariable( "AI", "DefaultRank", ".01" ) );
14  this->rank = ran;
15 
16  this->reaction_time = reaction;
17  this->faction = faction;
18  comm_face = NULL;
19  gender = 0;
20 }
virtual Pilot::~Pilot ( )
inlinevirtual

Definition at line 15 of file pilot.h.

15 {}

Member Function Documentation

float Pilot::adjustSpecificRelationship ( Unit parent,
void *  aggressor,
float  value,
int  guessedFaction 
)

Definition at line 29 of file pilot.cpp.

References Unit::aistate, Order::ChooseTarget(), effective_relationship, FactionUtil::GetNeutralFaction(), UnitUtil::getRelationToFaction(), VegaConfig::getVariable(), i, XMLSupport::parse_float(), Unit::Target(), and vs_config.

Referenced by CommunicatingAI::AdjustRelationTo(), and DoHit().

30 {
31  relationmap::iterator i = effective_relationship.insert( std::pair< const void*, float > ( aggressor, 0 ) ).first;
33  float rel = UnitUtil::getRelationToFaction( parent, faction ); /* What the bloody hell? */
34  bool abovezero = (*i).second+rel < 0;
35  if (!abovezero) {
36  static float slowrel = XMLSupport::parse_float( vs_config->getVariable( "AI", "SlowDiplomacyForEnemies", ".25" ) );
37  factor *= slowrel;
38  }
39  (*i).second += factor;
40  if (rel+factor < 0 && parent->Target() == NULL && parent->aistate)
41  parent->aistate->ChooseTarget();
42  } else {
43  static float lessrel = XMLSupport::parse_float( vs_config->getVariable( "AI", "UnknownRelationEnemy", "-.05" ) );
44  bool abovezero = (*i).second < lessrel;
45  if (!abovezero) {
46  static float slowrel = XMLSupport::parse_float( vs_config->getVariable( "AI", "SlowDiplomacyForEnemies", ".25" ) );
47  factor *= slowrel;
48  }
49  (*i).second += factor;
50  if ( (*i).second < lessrel && parent->Target() == NULL && parent->aistate )
51  parent->aistate->ChooseTarget();
52  }
53  return (*i).second;
54 }
void Pilot::DoHit ( Unit parent,
void *  aggressor,
int  guessedFaction 
)

Definition at line 55 of file pilot.cpp.

References _Universe, UniverseUtil::adjustFGRelationModifier(), UniverseUtil::adjustRelationModifierInt(), adjustSpecificRelationship(), Unit::faction, Unit::getFlightgroup(), getRank(), VegaConfig::getVariable(), Flightgroup::name, XMLSupport::parse_float(), vs_config, and Universe::whichPlayerStarship().

56 {
57  static float hitcost = XMLSupport::parse_float( vs_config->getVariable( "AI", "UnknownRelationHitCost", ".01" ) );
58  if (hitcost) {
59  adjustSpecificRelationship( parent, aggressor, hitcost, faction );
60  int whichCp = _Universe->whichPlayerStarship( parent );
61  if (whichCp != -1 && faction != parent->faction) {
63  } else {
64  /* Instead use the Aggressor's cockpit? */
65  whichCp = _Universe->whichPlayerStarship( (const Unit*) aggressor );
66  if (whichCp != -1) {
67  Flightgroup *fg = parent->getFlightgroup();
68  if (parent->faction != faction)
69  UniverseUtil::adjustRelationModifierInt( whichCp, parent->faction, hitcost*getRank() );
70  if (fg)
71  UniverseUtil::adjustFGRelationModifier( whichCp, fg->name, hitcost*getRank() );
72  }
73  }
74  }
75 }
float Pilot::getAnger ( const Unit parent,
const Unit un 
) const

Definition at line 76 of file pilot.cpp.

References _Universe, c, UnitImages< BOGUS >::cargo, effective_relationship, factions, Cargo::GetCategory(), FactionUtil::GetFactionName(), UniverseUtil::getFGRelationModifier(), Unit::getFlightgroup(), VegaConfig::getVariable(), i, Universe::isPlayerStarship(), Flightgroup::name, Unit::name, Unit::numCargo(), XMLSupport::parse_float(), Unit::pImage, Cargo::quantity, vs_config, and Universe::whichPlayerStarship().

Referenced by GetEffectiveRelationship(), and CommunicatingAI::selectCommunicationMessage().

77 {
78  relationmap::const_iterator iter = effective_relationship.find( target );
79  float rel = 0;
80  if ( iter != effective_relationship.end() )
81  rel = iter->second;
82  if ( _Universe->isPlayerStarship( target ) ) {
83  if (FactionUtil::GetFactionName( faction ).find( "pirates" ) != std::string::npos) {
84  static unsigned int cachedCargoNum = 0;
85  static bool good = true;
86  if ( cachedCargoNum != target->numCargo() ) {
87  cachedCargoNum = target->numCargo();
88  good = true;
89  for (unsigned int i = 0; i < cachedCargoNum; ++i) {
90  Cargo *c = &target->pImage->cargo[i];
91  if (c->quantity != 0 && c->GetCategory().find( "upgrades" ) == string::npos) {
92  good = false;
93  break;
94  }
95  }
96  }
97  if (good) {
98  static float goodness_for_nocargo =
99  XMLSupport::parse_float( vs_config->getVariable( "AI", "pirate_bonus_for_empty_hold", ".75" ) );
100  rel += goodness_for_nocargo;
101  }
102  }
103  }
104  {
105  int fac = faction;
106  MapStringFloat::iterator mapiter = factions[fac]->ship_relation_modifier.find( target->name );
107  if ( mapiter != factions[fac]->ship_relation_modifier.end() )
108  rel += (*mapiter).second;
109  }
110  {
111  int parent_cp = _Universe->whichPlayerStarship( parent );
112  int target_cp = _Universe->whichPlayerStarship( target );
113  if (parent_cp != -1) {
114  Flightgroup *fg = target->getFlightgroup();
115  if (fg)
116  rel += UniverseUtil::getFGRelationModifier( parent_cp, fg->name );
117  }
118  if (target_cp != -1) {
119  //... do we count it both ways? else?
120  Flightgroup *fg = parent->getFlightgroup();
121  if (fg)
122  rel += UniverseUtil::getFGRelationModifier( target_cp, fg->name );
123  }
124  }
125 
126  return rel;
127 }
Animation * Pilot::getCommFace ( Unit parent,
float  moon,
unsigned char &  gender 
)

Definition at line 136 of file pilot.cpp.

References Unit::faction, getCommFaces(), FactionUtil::GetRandCommAnimation(), index, int, and myroundclamp().

Referenced by UnitUtil::communicateTo().

137 {
138  vector< Animation* > *ani = getCommFaces( sex );
139  if (ani == NULL) {
140  ani = FactionUtil::GetRandCommAnimation( parent->faction, parent, sex );
141  if (ani == NULL)
142  return NULL;
143  }
144  if (ani->size() == 0)
145  return NULL;
146  mood += .1;
147  mood *= ( ani->size() )/.2;
148  unsigned int index = (unsigned int) myroundclamp( floor( mood ) );
149  if ( index >= ani->size() )
150  index = ani->size()-1;
151  return (*ani)[index];
152 }
float Pilot::GetEffectiveRelationship ( const Unit parent,
const Unit target 
) const

Definition at line 129 of file pilot.cpp.

References getAnger(), and UnitUtil::getFactionRelation().

Referenced by CommunicatingAI::selectCommunicationMessageMood().

130 {
131  return getAnger( parent, target )+UnitUtil::getFactionRelation( parent, target );
132 }
unsigned char Pilot::getGender ( )
inline

Definition at line 22 of file pilot.h.

Referenced by CommunicatingAI::Destroy(), and FireKeyboard::Execute().

23  {
24  return gender;
25  }
float Pilot::getRank ( )
inline

Definition at line 26 of file pilot.h.

Referenced by CommunicatingAI::AdjustRelationTo(), and DoHit().

27  {
28  return rank;
29  } //man it's rank in here
float Pilot::getReactionTime ( )
inline

Definition at line 18 of file pilot.h.

19  {
20  return reaction_time;
21  }
void Pilot::SetComm ( Unit comm_unit)

Definition at line 22 of file pilot.cpp.

References comm_face, Unit::faction, and FactionUtil::GetRandCommAnimation().

Referenced by Unit::Unit().

23 {
24  this->faction = parent->faction;
25  //GET BETTER REACTION TIME AND RANK HERE
27 }

Member Data Documentation

std::vector< Animation* >* Pilot::comm_face

Definition at line 32 of file pilot.h.

Referenced by getCommFaces(), Pilot(), and SetComm().

relationmap Pilot::effective_relationship

Definition at line 31 of file pilot.h.

Referenced by adjustSpecificRelationship(), getAnger(), and NetServer::sendCommunication().


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