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_generic.h
Go to the documentation of this file.
1 // -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*-
2 
3 #ifndef __UNIT_GENERIC_H__
4 #define __UNIT_GENERIC_H__
5 
6 /*
7  * Vega Strike
8  * Copyright (C) 2001-2002 Daniel Horn
9  *
10  * http://vegastrike.sourceforge.net/
11  *
12  * This program is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU General Public License
14  * as published by the Free Software Foundation; either version 2
15  * of the License, or (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program; if not, write to the Free Software
24  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25  */
26 
27 /***** Unit is the Unit class without GFX/Sound with AI *****/
28 
29 #ifndef _UNIT_H_
30 #define _UNIT_H_
31 #ifdef VS_DEBUG
32 #define CONTAINER_DEBUG
33 #endif
34 #ifdef CONTAINER_DEBUG
35 #include "hashtable.h"
36 class Unit;
37 void CheckUnit( class Unit* );
38 void UncheckUnit( class Unit*un );
39 #endif
40 #include "vegastrike.h"
41 #include "vs_globals.h"
42 
43 #include <string>
44 #include <set>
45 #include <map>
46 #include "cmd/unit_armorshield.h"
47 #include "gfx/matrix.h"
48 #include "gfx/quaternion.h"
49 #include "gfxlib_struct.h"
50 #include "weapon_xml.h"
51 #include "xml_support.h"
52 #include "container.h"
53 #include "collection.h"
54 #include "script/flightgroup.h"
55 #include "faction_generic.h"
56 #include "star_system_generic.h"
57 #include "networking/const.h"
59 #include "gfx/cockpit_generic.h"
60 #include "vsfilesystem.h"
61 #include "collide_map.h"
62 #include "SharedPool.h"
63 
64 extern char * GetUnitDir( const char *filename );
65 extern float capship_size;
66 
67 //A stupid struct that is only for grouping 2 different types of variables together in one return value
69 {
70 public:
74  , color( 1, 1, 1, 1 ) {}
75 };
76 
77 class PlanetaryOrbit;
78 class UnitCollection;
79 
80 class Order;
81 class Beam;
82 class Animation;
83 class Nebula;
84 class Animation;
85 class VSSprite;
86 class Box;
87 class StarSystem;
88 struct colTrees;
89 class Pilot;
90 class MeshAnimation;
91 
97 enum clsptr
98 {
106 };
107 
108 class Mount
109 {
110 protected:
111 //Where is it
115  void ReplaceSound();
116 public:
117 //Serial used to store missiles serial id before they are really created
119 //for guns!
120  float xyscale;
121  float zscale;
122  float ComputeAnimatedFrame( Mesh *gun );
123 //pass inunit so it can update gunspeed
124  void ReplaceMounts( Unit *unit, const Mount *other );
125  double Percentage( const Mount *newammo ) const;
126 //Gotta look at that, if we can make Beam a string in AcctUnit and a Beam elsewhere
127  union REF
128  {
129  //only beams are actually coming out of the gun at all times...bolts, balls, etc aren't
131  //Other weapons must track refire times
132  float refire;
133  }
134  ref;
135 //the size that this mount can hold. May be any bitwise combination of weapon_info::MOUNT_SIZE
136  unsigned int size; //short fix
137 //-1 is infinite
138  int ammo; //short
139  int volume; //-1 is infinite //short fix
140 //The data behind this weapon. May be accordingly damaged as time goes on
142  processed;
143 //Status of the selection of this weapon. Does it fire when we hit space
145  status;
146  bool bank;
147 //bank implies whether the weapon is linked with the next mount (i.e. only one firing at a time)
151  int sound;
152 //The sound this mount makes when fired
154  Mount();
155 //short fix
156  Mount( const std::string &name,
157  int ammo,
158  int volume,
159  float xyscale,
160  float zscale,
161  float functionality,
162  float maxfunctionality,
163  bool banked );
164 
165  void Activate( bool Missile );
166  void DeActive( bool Missile );
167 //Sets this gun's position on the mesh
168  void SetMountPosition( const Vector& );
169  void SetMountOrientation( const Quaternion& );
170 //Gets the mount's position and transform
171  const Vector& GetMountLocation() const
172  {
173  return pos;
174  }
176  {
177  return orient;
178  }
179 //Turns off a firing beam (upon key release for example)
180  void UnFire();
186 //Uses Sound Forcefeedback and other stuff
187  void PhysicsAlignedUnfire();
188  bool PhysicsAlignedFire( Unit*caller,
189  const Transformation &Cumulative,
190  const Matrix &mat,
191  const Vector &Velocity,
192  void *owner,
193  Unit*target,
194  signed char autotrack,
195  float trackingcone,
196  CollideMap::iterator hint[] );
197  bool NextMountCloser( Mount *nextmount, Unit* );
198  bool Fire( Unit *firer, void *owner, bool Missile = false, bool collide_only_with_target = false );
199  bool IsEmpty() const
200  {
201  return !(status == ACTIVE || status == INACTIVE);
202  }
203 };
204 
205 class VDU;
206 struct UnitSounds;
207 //template
208 template < typename BOGUS >
209 struct UnitImages;
210 class Cargo;
211 class Mesh;
212 struct PlanetaryOrbitData;
213 
222 class Unit
223 {
224 protected:
225 //How many lists are referencing us
226  int ucref;
227  StringPool::Reference csvRow;
228 public:
230 
231 //The name (type) of this unit shouldn't be public
232  StringPool::Reference name;
233  StringPool::Reference filename;
234 
235 /*
236  **************************************************************************************
237  **** CONSTRUCTORS / DESCTRUCTOR ***
238  **************************************************************************************
239  */
240 
241 protected:
242 //forbidden
243  Unit( const Unit& );
244 
245 //forbidden
246  Unit& operator=( const Unit& );
247 
248 public: Unit();
249 
254  Unit( int dummy );
255 
259  Unit( std::vector< Mesh* > &meshes, bool Subunit, int faction );
260 
265 //Uses a lot of stuff that does not belong to here
266  Unit( const char *filename, bool SubUnit, int faction, std::string customizedUnit = std::string(
267  "" ), Flightgroup *flightgroup = NULL, int fg_subnumber = 0, std::string *netxml = NULL );
268 
269 private:
272  void ZeroAll();
273 
274 public:
275 //Initialize many of the defaults inherant to the constructor
276  void Init();
277  void Init( const char *filename, bool SubUnit, int faction, std::string customizedUnit = std::string(
278  "" ), Flightgroup *flightgroup = NULL, int fg_subnumber = 0, std::string *netxml = NULL );
279  friend class UnitFactory;
280 //table can be NULL, but setting it appropriately may increase performance
281  void LoadRow( class CSVRow&row, std::string unitMod, std::string*netxml = NULL );
282  virtual ~Unit();
283 
284 /*
285  **************************************************************************************
286  **** NETWORKING STUFF ***
287  **************************************************************************************
288  */
289 
290 protected:
291 //Tell if networked unit
292  bool networked;
295 public:
297  enum DAMAGES
298  {
301  };
302  unsigned short damages;
303 
304  void SetNetworkMode( bool mode = true );
306  {
307  return serial;
308  }
309  void SetSerial( ObjSerial );
310  void BackupState();
311 
312 /*
313  **************************************************************************************
314  **** UPGRADE/CUSTOMIZE STUFF ***
315  **************************************************************************************
316  */
317 
318 //Uses mmm... stuff not desired here ?
319  bool UpgradeSubUnitsWithFactory( const Unit*up, int subunitoffset, bool touchme, bool downgrade, int &numave,
320  double &percentage, Unit*(*createupgradesubunit)(std::string s,
321  int faction) );
322  virtual bool UpgradeSubUnits( const Unit *up,
323  int subunitoffset,
324  bool touchme,
325  bool downgrade,
326  int &numave,
327  double &percentage );
328  bool UpgradeMounts( const Unit *up,
329  int subunitoffset,
330  bool touchme,
331  bool downgrade,
332  int &numave,
333  const Unit *templ,
334  double &percentage );
335 //the turrets and spinning parts fun fun stuff
337 
345  un_kiter viewSubUnits() const;
346 #define NO_MOUNT_STAR
347  std::vector< Mount >mounts;
348  float gunspeed;
349  float gunrange;
355  {
356 public:
357  unsigned SubUnit : 1;
359  unsigned missilelock : 1;
360  unsigned FaceCamera : 1;
361  unsigned Animating : 1;
362  unsigned InWarp : 1;
363  unsigned WarpRamping : 1;
364  unsigned unused1 : 1;
365  unsigned NoDamageParticles : 1;
367  unsigned char NumAnimationPoints;
369  float RampCounter;
372  graphic_options();
373  }
375  bool isSubUnit() const
376  {
377  return graphicOptions.SubUnit ? true : false;
378  }
379  void setFaceCamera();
380  bool UpAndDownGrade( const Unit *up,
381  const Unit *templ,
382  int mountoffset,
383  int subunitoffset,
384  bool touchme,
385  bool downgrade,
386  int additive,
387  bool forcetransaction,
388  double &percentage,
389  const Unit *downgrade_min,
390  bool force_change_on_nothing,
391  bool gen_downgrade_list );
392  void ImportPartList( const std::string &category, float price, float pricedev, float quantity, float quantdev );
393  int GetNumMounts() const
394  {
395  return mounts.size();
396  }
397  void ClearMounts();
398 //Loads a user interface for the user to upgrade his ship
399 //Uses base stuff -> only in Unit
400  virtual void UpgradeInterface( Unit *base ) {}
401 
402  bool canUpgrade( const Unit *upgrador,
403  int mountoffset,
404  int subunitoffset,
405  int additive,
406  bool force,
407  double &percentage,
408  const Unit *templ = NULL,
409  bool force_change_on_nothing = false,
410  bool gen_downgrade_list = true );
411  bool Upgrade( const Unit *upgrador,
412  int mountoffset,
413  int subunitoffset,
414  int additive,
415  bool force,
416  double &percentage,
417  const Unit *templ = NULL,
418  bool force_change_on_nothing = false,
419  bool gen_downgrade_list = true );
420  int RepairCost(); //returns how many things need to be repaired--if nothing is damaged it will return 1 for labor. doesn't assume any given cost on such thigns.
421  int RepairUpgrade(); //returns how many things were repaired
422 //returns percentOperational,maxPercentOperational,and whether mount is damaged (1 is damaged, 0 is fine, -1 is invalid mount)
423  bool RepairUpgradeCargo( Cargo *item, Unit *baseUnit, float *credits ); //item must not be NULL but baseUnit/credits are only used for pricing.
424  Vector MountPercentOperational( int whichmount );
425  bool ReduceToTemplate();
426  virtual double Upgrade( const std::string &file, int mountoffset, int subunitoffset, bool force, bool loop_through_mounts );
427  bool canDowngrade( const Unit *downgradeor,
428  int mountoffset,
429  int subunitoffset,
430  double &percentage,
431  const Unit *downgradelimit,
432  bool gen_downgrade_list = true );
433  bool Downgrade( const Unit *downgradeor,
434  int mountoffset,
435  int subunitoffset,
436  double &percentage,
437  const Unit *downgradelimit,
438  bool gen_downgrade_list = true );
439 
440 protected:
441 //Mount may access unit
442  friend class Mount;
443 //no collision table presence.
444 
445 /*
446  **************************************************************************************
447  **** GFX/PLANET STUFF ***
448  **************************************************************************************
449  */
450 
451 public:
452 //number of meshes (each with separate texture) this unit has
453 
454  std::vector< Mesh* >meshdata;
455  unsigned attackPreference() const
456  {
457  return attack_preference;
458  }
459  void attackPreference( unsigned char );
460  unsigned unitRole() const
461  {
462  return unit_role;
463  }
464  void unitRole( unsigned char );
465 //following 2 are legacy functions for python export only
466  void setCombatRole( const std::string &s );
467  const std::string& getCombatRole() const;
468 //end legacy functions
469  const std::string& getUnitRole() const;
470  void setUnitRole( const std::string &s );
471  const std::string& getAttackPreference() const;
472  void setAttackPreference( const std::string &s );
473 protected:
474  unsigned char attack_preference;
475  unsigned char unit_role;
477 //The orbit needs to have access to the velocity directly to disobey physics laws to precalculate orbits
478  friend class PlanetaryOrbit;
479  friend class ContinuousTerrain;
480 //VDU needs mount data to draw weapon displays
481  friend class VDU;
482 //needed to actually upgrade unit through interface
483  friend class UpgradingInfo;
484 public:
485 //Have to pass the randnum and degrees in networking and client side since they must not be random in that case
486  void DamageRandSys( float dam, const Vector &vec, float randum = 1, float degrees = 1 );
487  void SetNebula( Nebula* );
488  inline Nebula * GetNebula() const
489  {
490  return nebula;
491  }
492 //Should draw selection box?
493 //Process all meshes to be deleted
494  static void ProcessDeleteQueue();
495 //Returns the cockpit name so that the controller may load a new cockpit
496  const std::string& getCockpit() const;
497 
498 //Shouldn't do anything here - but needed by Python
499  class Cockpit * GetVelocityDifficultyMult( float& ) const;
500 
501 //the star system I'm in
503 //Takes out of the collide table for this system.
504  void RemoveFromSystem();
505  void RequestPhysics(); //Requeues the unit so that it is simulated ASAP
507  virtual int nummesh() const
508  {
509  return ( (int) meshdata.size() )-1;
510  }
511 //Uses planet stuff
512 /* Updates the collide Queue with any possible change in sectors
513  * Split this mesh with into 2^level submeshes at arbitrary planes
514  * Uses Mesh so only in Unit and maybe in NetUnit */
515  virtual void Split( int level ) {}
516  virtual void addHalo( const char *filename,
517  const QVector &loc,
518  const Vector &size,
519  const GFXColor &col,
520  std::string halo_type,
521  float activation ) {}
522 
523 //Uses Mesh -> in NetUnit and Unit only
524  std::vector< Mesh* >StealMeshes();
525 /* Begin and continue explosion
526  * Uses GFX so only in Unit class
527  * But should always return true on server side = assuming explosion time=0 here */
528  virtual bool Explode( bool draw, float timeit );
529 //explodes then deletes
530  void Destroy();
531 
532 //Uses GFX so only in Unit class
533  virtual void Draw( const Transformation &quat = identity_transformation, const Matrix &m = identity_matrix ) {}
534  virtual void DrawNow( const Matrix &m = identity_matrix, float lod = 1000000000 ) {}
535 
536 //Sets the camera to be within this unit.
537 //Uses Universe & GFX so not needed here -> only in Unit class
538  virtual void UpdateHudMatrix( int whichcam ) {}
539 //What's the HudImage of this unit
540 //Uses GFX stuff so only in Unit class
541  virtual VSSprite * getHudImage() const
542  {
543  return NULL;
544  }
545 //Not needed just in Unit class
546 
547  // Uses GFX, so generic version is a no-op.
548  // GameUnit variants (clientside) would apply the overrides to their GFX techniques
549  virtual void applyTechniqueOverrides(const std::map<std::string, std::string> &overrides);
550 
551 /*
552  **************************************************************************************
553  **** NAVIGATION STUFF ***
554  **************************************************************************************
555  */
556 
557 public:
558  const std::vector< std::string >& GetDestinations() const;
559  void AddDestination( const std::string& );
569  class Computer
570  {
571  public:
572  class RADARLIM
573  {
574  public:
575  struct Brand
576  {
577  enum Value
578  {
579  SPHERE = 0,
580  BUBBLE = 1,
581  PLANE = 2
582  };
583  };
584  struct Capability
585  {
586  enum Value
587  {
588  // For internal use
592 
593  // The lower 16 bits
594  IFF_NONE = 0,
595  IFF_FRIEND_FOE = 1 << 0,
598 
599  // The upper 16 bits
603  };
604  };
605 //the max range the radar can handle
606  float maxrange;
607 //the dot with (0,0,1) indicating the farthest to the side the radar can handle.
608  float maxcone;
609  float lockcone;
611 //The minimum radius of the target
613  // What kind of type and capability the radar supports
615  bool locked;
616  bool canlock;
619  , maxcone( 0 )
620  , lockcone( 0 )
621  , trackingcone( 0 )
622  , mintargetsize( 0 )
624  , locked( false )
625  , canlock( false )
626  {}
627  Brand::Value GetBrand() const;
628  bool UseFriendFoe() const;
629  bool UseObjectRecognition() const;
630  bool UseThreatAssessment() const;
631  }
632  radar;
633  bool ecmactive;
634 //The nav point the unit may be heading for
636 //The target that the unit has in computer
638 //Any target that may be attacking and has set this threat
640 //Unit that it should match velocity with (not speed) if null, matches velocity with universe frame (star)
643 //The threat level that was calculated from attacking unit's threat
644  float threatlevel;
645 //The speed the flybywire system attempts to maintain
646  float set_speed;
647 //Computers limitation of speed
650  float max_speed() const;
651  float max_ab_speed() const;
652 //Computer's restrictions of YPR to limit space combat maneuvers
659 //Whether or not an 'lead' indicator appears in front of target
660  unsigned char slide_start;
661  unsigned char slide_end;
662  bool itts;
663 //tells whether the speed is clamped draconian-like or not
665  Computer() : NavPoint( 0, 0, 0 )
666  , threatlevel( 0 )
667  , set_speed( 0 )
668  , max_combat_speed( 0 )
669  , max_combat_ab_speed( 0 )
670  , max_yaw_left( 0 )
671  , max_yaw_right( 0 )
672  , max_pitch_down( 0 )
673  , max_pitch_up( 0 )
674  , max_roll_left( 0 )
675  , max_roll_right( 0 )
676  , slide_start( 0 )
677  , slide_end( 0 )
678  , itts( false )
679  , combat_mode( false ) {}
680  }
681  computer;
682  void SwitchCombatFlightMode();
683  bool CombatMode();
684 //SHOULD TRY TO COME BACK HERE
685  virtual bool TransferUnitToSystem( StarSystem *NewSystem );
686  virtual bool TransferUnitToSystem( unsigned int whichJumpQueue,
687  class StarSystem*&previouslyActiveStarSystem,
688  bool DoSightAndSound );
690  const StarSystem * getStarSystem() const;
691  struct UnitJump
692  {
694  float energy; //short fix
695  float insysenergy; //short fix
696  signed char drive;
697  unsigned char delay;
698  unsigned char damage;
699  //negative means fuel
700  }
701  jump;
703  bool selected;
704 
705  const UnitJump& GetJumpStatus() const
706  {
707  return jump;
708  }
709  float CourseDeviation( const Vector &OriginalCourse, const Vector &FinalCourse ) const;
711  const Computer& ViewComputerData() const
712  {
713  return computer;
714  }
715  void ActivateJumpDrive( int destination = 0 );
716  void DeactivateJumpDrive();
717 
718 /*
719  **************************************************************************************
720  **** XML STUFF ***
721  **************************************************************************************
722  */
723 
724 public:
725 //Unit XML Load information
726  struct XML;
727 //Loading information
728  XML *xml;
729 
730  static void beginElement( void *userData, const XML_Char *name, const XML_Char **atts );
731  static void endElement( void *userData, const XML_Char *name );
732 
733  void beginElement( const std::string &name, const XMLSupport::AttributeList &attributes );
734  void endElement( const std::string &name );
735 
736 protected:
737  static std::string massSerializer( const struct XMLType &input, void *mythis );
738  static std::string cargoSerializer( const struct XMLType &input, void *mythis );
739  static std::string mountSerializer( const struct XMLType &input, void *mythis );
740  static std::string shieldSerializer( const struct XMLType &input, void *mythis );
741  static std::string subunitSerializer( const struct XMLType &input, void *mythis );
742 
743 public:
744 //tries to warp as close to un as possible abiding by the distances of various enemy ships...it might not make it all the way
745  void WriteUnit( const char *modificationname = "" );
746  std::string WriteUnitString();
747 //Loads a unit from an xml file into a complete datastructure
748  void LoadXML( const char *filename, const char *unitModifications = "", std::string *xmlbuffer = NULL );
749  void LoadXML( VSFileSystem::VSFile &f, const char *unitModifications = "", std::string *xmlbuffer = NULL );
750 
751 /*
752  **************************************************************************************
753  **** PHYSICS STUFF ***
754  **************************************************************************************
755  */
756 
757 private:
758  void RechargeEnergy();
759 protected:
760  virtual float ExplosionRadius();
761 public:
762  bool AutoPilotToErrorMessage( Unit *un, bool automaticenergyrealloc, std::string &failuremessage, int recursive_level = 2 );
763  bool AutoPilotTo( Unit *un, bool automaticenergyrealloc );
764 //The owner of this unit. This may not collide with owner or units owned by owner. Do not dereference (may be dead pointer)
765  void *owner; //void ensures that it won't be referenced by accident
766 //The number of frames ahead this was put in the simulation queue
767  unsigned int sim_atom_multiplier;
768 //The number of frames ahead this is predicted to be scheduled in the next scheduling round
769  unsigned int predicted_priority;
770 //The previous state in last physics frame to interpolate within
772 //The state of the current physics frame to interpolate within
774 //When will physical simulation occur
775  unsigned int cur_sim_queue_slot;
776 //Used with subunit scheduling, to avoid the complex ickiness of having to synchronize scattered slots
777  unsigned int last_processed_sqs;
778 //Whether or not to schedule subunits for deferred physics processing - if not, they're processed at the same time the parent unit is being processed
780 //Does this unit require special scheduling?
783 //number of meshes (each with separate texture) this unit has
784 //The cumulative (incl subunits parents' transformation)
786 //The cumulative (incl subunits parents' transformation)
788 //The velocity this unit has in World Space
790 //The force applied from outside accrued over the whole physics frame
792 //The force applied by internal objects (thrusters)
794 //The torque applied from outside objects
796 //The torque applied from internal objects
798 //the current velocities in LOCAL space (not world space)
801 //The image that will appear on those screens of units targetting this unit
803 //positive for the multiplier applied to nearby spec starships (1 = planetary/inert effects) 0 is default (no effect), -X means 0 but able to be enabled
805 //mass of this unit (may change with cargo)
806  float Mass;
807  float HeatSink;
808 protected:
809 //are shields tight to the hull. zero means bubble
810  float shieldtight;
811 //fuel of this unit
812  float fuel;
813  float afterburnenergy; //short fix
814  int afterburntype; //0--energy, 1--fuel
815 //-1 means it is off. -2 means it doesn't exist. otherwise it's engaged to destination (positive number)
816 //Moment of intertia of this unit
819 
820 public:
821  class Limits
822  {
823 public:
824 //max ypr--both pos/neg are symmetrical
825  float yaw;
826  float pitch;
827  float roll;
828 //side-side engine thrust max
829  float lateral;
830 //vertical engine thrust max
831  float vertical;
832 //forward engine thrust max
833  float forward;
834 //reverse engine thrust max
835  float retro;
836 //after burner acceleration max
837  float afterburn;
838 //the vector denoting the "front" of the turret cone!
840 //the minimum dot that the current heading can have with the structurelimit
841  float limitmin;
842 
843  Limits() : yaw( 0 )
844  , pitch( 0 )
845  , roll( 0 )
846  , lateral( 0 )
847  , vertical( 0 )
848  , forward( 0 )
849  , retro( 0 )
850  , afterburn( 0 )
851  , structurelimits( 0, 0, 0 )
852  , limitmin( 0 ) {}
853  }
854  limits;
855 //-1 is not available... ranges between 0 32767 for "how invisible" unit currently is (32768... -32768) being visible)
856  int cloaking; //short fix
857 //the minimum cloaking value...
858  int cloakmin; //short fix
859 //How big is this unit
860  float radial_size;
861 protected:
862 //Is dead already?
863  bool killed;
864 //Should not be drawn
865  enum INVIS {DEFAULTVIS=0x0, INVISGLOW=0x1, INVISUNIT=0x2, INVISCAMERA=0x4};
866  unsigned char invisible; //1 means turn off glow, 2 means turn off ship
867 //corners of object
868 
869 public:
872  {
873  return ToLocalCoordinates( ( un->Position()-Position() ).Cast() );
874  }
875 //how visible the ship is from 0 to 1
876  float CloakVisible() const
877  {
878  if (cloaking < 0) return 1;
879  return ( (float) cloaking )/2147483647;
880  }
881 //cloaks or decloaks the starship depending on the bool
882  virtual void Cloak( bool cloak );
883 //deletes
884  void Kill( bool eraseFromSave = true, bool quitting = false );
885 //Is dead yet?
886  inline bool Killed() const
887  {
888  return killed;
889  }
890  bool IsExploding() const { return pImage->timeexplode > 0; }
891  // 0 = not stated, 1 = done
892  float ExplodingProgress() const;
893 
894 //returns the current ammt of armor left
895 //short fix
896  float AfterburnData() const
897  {
898  return afterburnenergy;
899  }
900  void SetAfterBurn( float aft );
901  float FuelData() const;
902  float WarpCapData() const;
903  void SetFuel( float f );
904 //Returns the current ammt of energy left
905  float EnergyRechargeData() const
906  {
907  return recharge;
908  }
909  void SetEnergyRecharge( float enrech );
910  void SetMaxEnergy( float maxen );
911  float MaxEnergyData() const
912  {
913  return maxenergy;
914  }
915  float ShieldRechargeData() const
916  {
917  return shield.recharge;
918  }
919  float EnergyData() const;
920  float WarpEnergyData() const;
921 //short fix
922  float GetWarpEnergy() const
923  {
924  return warpenergy;
925  }
926  void DecreaseWarpEnergy( bool insystem, float time = 1.0f );
927  void IncreaseWarpEnergy( bool insystem, float time = 1.0f );
928  bool RefillWarpEnergy();
929 //Should we resolve forces on this unit (is it free to fly or in orbit)
931 //What's the size of this unit
932  float rSize() const
933  {
934  return radial_size;
935  }
936 
937 //Returns the current world space position
939  {
941  }
942  const Matrix& GetTransformation() const
943  {
945  }
946 //Returns the unit-space position
948  {
950  }
951 //Sets the unit-space position
952  void SetPosition( const QVector &pos );
954  void SetCurPosition( const QVector &pos )
955  {
957  }
958  void SetPosAndCumPos( const QVector &pos )
959  {
960  SetPosition( pos );
963  }
964 //Sets the state of drawing
965  void SetVisible( bool isvis );
966  void SetAllVisible( bool isvis );
967  void SetGlowVisible( bool isvis );
968 
969 //Rotates about the axis
970  void Rotate( const Vector &axis );
975 /*unit vector... might default to "r"*/
976  void FireEngines( const Vector &Direction, float FuelSpeed, float FMass );
977 //applies a force for the whole gameturn upon the center of mass
978  void ApplyForce( const Vector &Vforce );
979 //applies a force for the whole gameturn upon the center of mass, using local coordinates
980  void ApplyLocalForce( const Vector &Vforce );
981 //applies a force that is multipled by the mass of the ship
982  void Accelerate( const Vector &Vforce );
983 //Apply a torque in world level coords
984  void ApplyTorque( const Vector &Vforce, const QVector &Location );
985 //Applies a torque in local level coordinates
986  void ApplyLocalTorque( const Vector &Vforce, const Vector &Location );
987 //usually from thrusters remember if I have 2 balanced thrusters I should multiply their effect by 2 :)
988  void ApplyBalancedLocalTorque( const Vector &Vforce, const Vector &Location );
989 
990 //convenient shortcut to applying torques with vector and position
991  void ApplyLocalTorque( const Vector &torque );
992 //Applies damage to the local area given by pnt
993  float ApplyLocalDamage( const Vector &pnt,
994  const Vector &normal,
995  float amt,
996  Unit *affectedSubUnit,
997  const GFXColor&,
998  float phasedamage = 0 );
999 //Applies damage from network data
1000  void ApplyNetDamage( Vector &pnt, Vector &normal, float amt, float ppercentage, float spercentage, GFXColor &color );
1001 //Applies damage to the pre-transformed area of the ship
1002  void ApplyDamage( const Vector &pnt,
1003  const Vector &normal,
1004  float amt,
1005  Unit *affectedSubUnit,
1006  const GFXColor&,
1007  void *ownerDoNotDereference,
1008  float phasedamage = 0 );
1009 //Lights the shields, without applying damage or making the AI mad - useful for special effects
1010  void LightShields( const Vector &pnt, const Vector &normal, float amt, const GFXColor &color );
1011 //Deals remaining damage to the hull at point and applies lighting effects
1012 //short fix
1013  float DealDamageToHullReturnArmor( const Vector &pnt, float Damage, float* &targ );
1014  virtual void ArmorDamageSound( const Vector &pnt ) {}
1015  virtual void HullDamageSound( const Vector &pnt ) {}
1016  float DealDamageToHull( const Vector &pnt, float Damage );
1017 //Clamps thrust to the limits struct
1018  Vector ClampThrust( const Vector &thrust, bool afterburn );
1019 //Takes a unit vector for direction of thrust and scales to limits
1020  Vector MaxThrust( const Vector &thrust );
1021 //Thrusts by ammt and clamps accordingly (afterburn or not)
1022  virtual void Thrust( const Vector &amt, bool afterburn = false );
1023 //Applies lateral thrust
1024  void LateralThrust( float amt );
1025 //Applies vertical thrust
1026  void VerticalThrust( float amt );
1027 //Applies forward thrust
1028  void LongitudinalThrust( float amt );
1029 //Clamps desired velocity to computer set limits
1030  Vector ClampVelocity( const Vector &velocity, const bool afterburn );
1031 //Clamps desired angular velocity to computer set limits
1032  Vector ClampAngVel( const Vector &vel );
1033 //Clamps desired torque to computer set limits of thrusters
1034  Vector ClampTorque( const Vector &torque );
1035 //scales unit size torque to limits in that direction
1036  Vector MaxTorque( const Vector &torque );
1037 //Applies a yaw of amt
1038  void YawTorque( float amt );
1039 //Applies a pitch of amt
1040  void PitchTorque( float amt );
1041 //Applies a roll of amt
1042  void RollTorque( float amt );
1043 //executes a repair if the repair bot is up to it
1044  void Repair();
1045 //Updates physics given unit space transformations and if this is the last physics frame in the current gfx frame
1046 //Not needed here, so only in NetUnit and Unit classes
1047  void UpdatePhysics( const Transformation &trans,
1048  const Matrix &transmat,
1049  const Vector &CumulativeVelocity,
1050  bool ResolveLast,
1051  UnitCollection *uc,
1052  Unit *superunit );
1053  virtual void UpdatePhysics2( const Transformation &trans,
1054  const Transformation &old_physical_state,
1055  const Vector &accel,
1056  float difficulty,
1057  const Matrix &transmat,
1058  const Vector &CumulativeVelocity,
1059  bool ResolveLast,
1060  UnitCollection *uc = NULL );
1061 //Useful if you want to override subunit processing, but not self-processing (Asteroids, people?)
1062  virtual void UpdateSubunitPhysics( const Transformation &trans,
1063  const Matrix &transmat,
1064  const Vector &CumulativeVelocity,
1065  bool ResolveLast,
1066  UnitCollection *uc,
1067  Unit *superunit );
1068 //A helper for those who override UpdateSubunitPhysics - Process one subunit (also, an easier way of overriding subunit processing uniformly)
1069  virtual void UpdateSubunitPhysics( Unit *subunit,
1070  const Transformation &trans,
1071  const Matrix &transmat,
1072  const Vector &CumulativeVelocity,
1073  bool ResolveLast,
1074  UnitCollection *uc,
1075  Unit *superunit );
1076  void AddVelocity( float difficulty );
1077 //Resolves forces of given unit on a physics frame
1078  virtual Vector ResolveForces( const Transformation&, const Matrix& );
1079 //Returns the pqr oritnattion of the unit in world space
1080  void SetOrientation( QVector q, QVector r );
1081  void SetOrientation( Quaternion Q );
1082  void SetOrientation( QVector p, QVector q, QVector r );
1083  void GetOrientation( Vector &p, Vector &q, Vector &r ) const;
1085 //acceleration, retrieved from NetForce - not stable (partial during simulation), use GetAcceleration()
1087  {
1088  return SavedAccel;
1089  }
1090 //acceleration, stable over the simulation
1091  float GetMaxAccelerationInDirectionOf( const Vector &ref, bool afterburn ) const;
1092 //Transforms a orientation vector Up a coordinate level. Does not take position into account
1093  Vector UpCoordinateLevel( const Vector &v ) const;
1094 //Transforms a orientation vector Down a coordinate level. Does not take position into account
1095  Vector DownCoordinateLevel( const Vector &v ) const;
1096 //Transforms a orientation vector from world space to local space. Does not take position into account
1097  Vector ToLocalCoordinates( const Vector &v ) const;
1098 //Transforms a orientation vector to world space. Does not take position into account
1099  Vector ToWorldCoordinates( const Vector &v ) const;
1100 //Returns unit-space ang velocity
1102  {
1103  return AngularVelocity;
1104  }
1105 //Return unit-space velocity
1106  const Vector& GetVelocity() const
1107  {
1108  return cumulative_velocity;
1109  }
1110  Vector GetWarpVelocity() const;
1111  void SetVelocity( const Vector& );
1112  void SetAngularVelocity( const Vector& );
1113  float GetMoment() const
1114  {
1115  return Momentofinertia+fuel;
1116  }
1117  float GetMass() const
1118  {
1119  return Mass+fuel;
1120  }
1121 //returns the ammt of elasticity of collisions with this unit
1122  float GetElasticity();
1123 //returns given limits (should not be necessary with clamping functions)
1124  const Limits& Limits() const
1125  {
1126  return limits;
1127  }
1128 //Sets if forces should resolve on this unit or not
1129  void SetResolveForces( bool );
1130 
1131 /*
1132  **************************************************************************************
1133  **** WEAPONS/SHIELD STUFF ***
1134  **************************************************************************************
1135  */
1136 public:
1137 //Armor and shield structures
1140 //The structual integ of the current unit
1141  float hull;
1142 //current energy
1143  float energy;
1144 protected:
1145 //Activates all guns of that size
1146  void ActivateGuns( const weapon_info*, bool Missile );
1147  float MaxShieldVal() const;
1148 //regenerates all 2,4, or 6 shields for 1 SIMULATION_ATOM
1149  void RegenShields();
1150 //Original hull
1151  float maxhull;
1152 //The radar limits (range, cone range, etc)
1153 //the current order
1154 //how much the energy recharges per second
1155  float recharge;
1156 
1157 //maximum energy
1158  float maxenergy;
1159 //maximum energy
1160  float maxwarpenergy; //short fix
1161 //current energy
1162  float warpenergy; //short fix
1163 //applies damage from the given pnt to the shield, and returns % damage applied and applies lighitn
1164  virtual float DealDamageToShield( const Vector &pnt, float &Damage );
1165 //If the shields are up from this position
1166  bool ShieldUp( const Vector& ) const;
1167 public:
1168 //resets average gun speed (in event of weapon change
1169  void setAverageGunSpeed();
1170  int LockMissile() const; //-1 is no lock necessary 1 is locked
1171  void LockTarget( bool myboo );
1172  bool TargetLocked() const
1173  {
1174  return computer.radar.locked;
1175  }
1176  float TrackingGuns( bool &missileLock );
1177 //Changes currently selected weapon
1178  void ToggleWeapon( bool Missile, bool forward = true );
1179 //Selects all weapons
1180  void SelectAllWeapon( bool Missile );
1181 //Gets the average gun speed of the unit::caution SLOW
1182  void getAverageGunSpeed( float &speed, float &grange, float &mrange ) const;
1183 
1184 //Finds the position from the local position if guns are aimed at it with speed
1185  QVector PositionITTS( const QVector &firingposit, Vector firingvelocity, float gunspeed, bool smooth_itts ) const;
1186 //returns percentage of course deviation for contraband searches. .5 causes error and 1 causes them to get mad
1187  float FShieldData() const;
1188  float RShieldData() const;
1189  float LShieldData() const;
1190  float BShieldData() const;
1191 //short fix
1192  void ArmorData( float armor[8] ) const;
1193 //Gets the current status of the hull
1194  float GetHull() const
1195  {
1196  return hull;
1197  }
1198  float GetHullPercent() const
1199  {
1200  return maxhull != 0 ? hull/maxhull : hull;
1201  }
1202 //Fires all active guns that are or arent Missiles
1203 //if bitmask is (1<<31) then fire off autotracking of that type;
1204  void Fire( unsigned int bitmask, bool beams_target_owner = false );
1205 //Stops all active guns from firing
1206  void UnFire();
1207 //reduces shields to X percentage and reduces shield recharge to Y percentage
1208  void leach( float XshieldPercent, float YrechargePercent, float ZenergyPercent );
1209 
1210 /*
1211  **************************************************************************************
1212  **** TARGETTING STUFF ***
1213  **************************************************************************************
1214  */
1215 
1216 protected:
1217 //not used yet
1218  StringPool::Reference target_fgid[3];
1219 public:
1220  bool InRange( Unit *target, bool cone = true, bool cap = true ) const
1221  {
1222  double mm;
1223  return InRange( target, mm, cone, cap, true );
1224  }
1225  bool InRange( Unit *target, double &mm, bool cone, bool cap, bool lock ) const;
1226  Unit * Target();
1227  Unit * VelocityReference();
1228  Unit * Threat();
1229 //Uses Universe stuff so only in Unit class
1230  void VelocityReference( Unit *targ );
1231  void TargetTurret( Unit *targ );
1232 //Threatens this unit with "targ" as aggressor. Danger should be cos angle to target
1233  void Threaten( Unit *targ, float danger );
1234 //Rekeys the threat level to zero for another turn of impending danger
1236  {
1237  computer.threatlevel = 0;
1239  }
1240 //The cosine of the angle to the target given passed in speed and range
1241  float cosAngleTo( Unit *target, float &distance, float speed = 0.001, float range = 0.001, bool turnmargin = true ) const;
1242 //Highest cosine from given mounts to target. Returns distance and cosine
1243  float cosAngleFromMountTo( Unit *target, float &distance ) const;
1244 //how locked are we
1245  float computeLockingPercent();
1246 //Turns on selection box
1247  void Select();
1248 //Turns off selection box
1249  void Deselect();
1250 
1251 //Shouldn't do anything here - but needed by Python
1252  void Target( Unit *targ );
1253 
1254 //not used yet
1255  void setTargetFg( std::string primary, std::string secondary = std::string(), std::string tertiary = std::string() );
1256 //not used yet
1257  void ReTargetFg( int which_target = 0 );
1258 //not used yet
1259 
1260 /*
1261  **************************************************************************************
1262  **** CARGO STUFF ***
1263  **************************************************************************************
1264  */
1265 
1266 protected:
1267  void SortCargo();
1268 public:
1269  static Unit * makeMasterPartList();
1270  bool CanAddCargo( const Cargo &carg ) const;
1271  void AddCargo( const Cargo &carg, bool sort = true );
1272  int RemoveCargo( unsigned int i, int quantity, bool eraseZero = true );
1273  float PriceCargo( const std::string &s );
1274  Cargo& GetCargo( unsigned int i );
1275  const Cargo& GetCargo( unsigned int i ) const;
1276  void GetSortedCargoCat( const std::string &category, size_t &catbegin, size_t &catend );
1277 //below function returns NULL if not found
1278  Cargo * GetCargo( const std::string &s, unsigned int &i );
1279  const Cargo * GetCargo( const std::string &s, unsigned int &i ) const;
1280  unsigned int numCargo() const;
1281  std::string GetManifest( unsigned int i, Unit *scanningUnit, const Vector &original_velocity ) const;
1282  bool SellCargo( unsigned int i, int quantity, float &creds, Cargo &carg, Unit *buyer );
1283  bool SellCargo( const std::string &s, int quantity, float &creds, Cargo &carg, Unit *buyer );
1284  bool BuyCargo( const Cargo &carg, float &creds );
1285  bool BuyCargo( unsigned int i, unsigned int quantity, Unit *buyer, float &creds );
1286  bool BuyCargo( const std::string &cargo, unsigned int quantity, Unit *buyer, float &creds );
1287  void EjectCargo( unsigned int index );
1288  float getEmptyCargoVolume( void ) const;
1289  float getCargoVolume( void ) const;
1290  float getEmptyUpgradeVolume( void ) const;
1291  float getUpgradeVolume( void ) const;
1292  float getHiddenCargoVolume( void ) const;
1293 
1294 /*
1295  **************************************************************************************
1296  **** AI STUFF ***
1297  **************************************************************************************
1298  */
1299 
1300 public:
1301  class csOPCODECollider * getCollideTree( const Vector &scale = Vector( 1,
1302  1,
1303  1 ), const std::vector< struct mesh_polygon >* = NULL );
1304 //Because accessing in daughter classes member function from Unit * instances
1306  Order * getAIState() const
1307  {
1308  return aistate;
1309  }
1310 //Sets up a null queue for orders
1311 //Uses AI so only in NetUnit and Unit classes
1312  void PrimeOrders();
1313  void PrimeOrdersLaunched();
1314  void PrimeOrders( Order *newAI );
1315 //Sets the AI to be a specific order
1316  void SetAI( Order *newAI );
1317 //Enqueues an order to the unit's order queue
1318  void EnqueueAI( Order *newAI );
1319 //EnqueuesAI first
1320  void EnqueueAIFirst( Order *newAI );
1321 //num subunits
1322  void LoadAIScript( const std::string &aiscript );
1323  bool LoadLastPythonAIScript();
1325 //Uses Order class but just a poiner so ok
1326 //Uses AI so only in NetUnit and Unit classes
1327 //for clicklist
1328  double getMinDis( const QVector &pnt );
1329 //Uses AI stuff so only in NetUnit and Unit classes
1330  void SetTurretAI();
1331  void DisableTurretAI();
1332 //AI so only in NetUnit and Unit classes
1333  std::string getFullAIDescription();
1334 //Erases all orders that bitwise OR with that type
1335 //Uses AI so only in NetUnit and Unit classes
1336  void eraseOrderType( unsigned int type );
1337 //Executes 1 frame of physics-based AI
1338  void ExecuteAI();
1339 
1340 /*
1341  **************************************************************************************
1342  **** COLLISION STUFF ***
1343  **************************************************************************************
1344  */
1345 
1346 public:
1347 //The information about the minimum and maximum ranges of this unit. Collide Tables point to this bit of information.
1349 //location[0] is for units only, location[1] is for units + bolts
1352 //Sets the parent to be this unit. Unit never dereferenced for this operation
1353  void SetCollisionParent( Unit *name );
1354 //won't collide with ownery
1355  void SetOwner( Unit *target );
1356  void SetRecursiveOwner( Unit *target );
1357 
1358 //Shouldn't do anything here - but needed by Python
1359 //Queries the ray collider with a world space st and end point. Returns the normal and distance on the line of the intersection
1360  Unit * rayCollide( const QVector &st, const QVector &end, Vector &normal, float &distance);
1361 
1362 //fils in corner_min,corner_max and radial_size
1363 //Uses Box stuff -> only in NetUnit and Unit
1364  void calculate_extent( bool update_collide_queue );
1365 
1366 //Uses mesh stuff (only rSize()) : I have to find something to do
1367  bool Inside( const QVector &position, const float radius, Vector &normal, float &dist );
1368 //Uses collide and Universe stuff -> put in NetUnit
1370 //Uses collision stuff so only in NetUnit and Unit classes
1371  bool querySphere( const QVector &pnt, float err ) const;
1372 //queries the sphere for beams (world space start,end) size is added to by my_unit_radius
1373  float querySphere( const QVector &start, const QVector &end, float my_unit_radius = 0 ) const;
1374  float querySphereNoRecurse( const QVector &start, const QVector &end, float my_unit_radius = 0 ) const;
1375 //queries the ship with a directed ray
1376 //for click list
1377  float querySphereClickList( const QVector &st, const QVector &dir, float err ) const;
1378 //Queries if this unit is within a given frustum
1379 //Uses GFX -> defined only Unit class
1380  bool queryFrustum( double frustum[6][4] ) const
1381  {
1382  return false;
1383  }
1384 
1391  virtual bool querySphereClickList( int, int, float err, Camera *activeCam )
1392  {
1393  return false;
1394  }
1395 
1396  bool InsideCollideTree( Unit *smaller,
1397  QVector &bigpos,
1398  Vector &bigNormal,
1399  QVector &smallpos,
1400  Vector &smallNormal,
1401  bool bigasteroid = false,
1402  bool smallasteroid = false );
1403  virtual void reactToCollision( Unit *smaller,
1404  const QVector &biglocation,
1405  const Vector &bignormal,
1406  const QVector &smalllocation,
1407  const Vector &smallnormal,
1408  float dist );
1409 //returns true if jump possible even if not taken
1410 //Uses Universe thing
1411  bool jumpReactToCollision( Unit *smaller );
1412 //Does a collision between this and another unit
1413  bool Collide( Unit *target );
1414 //checks for collisions with all beams and other units roughly and then more carefully
1415  void CollideAll();
1416 
1417 /*
1418  **************************************************************************************
1419  **** DOCKING STUFF ***
1420  **************************************************************************************
1421  */
1422 
1423 public:
1424  unsigned char docked;
1426 //returns -1 if unit cannot dock, otherwise returns which dock it can dock at
1427  int CanDockWithMe( Unit *dockingunit, bool forcedock = false );
1428  int ForceDock( Unit *utdw, unsigned int whichdockport );
1429  void PerformDockingOperations();
1430  void FreeDockingPort( unsigned int whichport );
1431  const std::vector< struct DockingPorts >& DockingPortLocations() const;
1432  char DockedOrDocking() const
1433  {
1434  return docked;
1435  }
1436  bool IsCleared( const Unit *dockignunit ) const;
1437  bool isDocked( const Unit *dockingUnit ) const;
1438  bool UnDock( Unit *unitToDockWith );
1439 //Use AI
1440  bool RequestClearance( Unit *dockingunit );
1441  bool EndRequestClearance( Unit *dockingunit );
1442  bool hasPendingClearanceRequests() const;
1443  int Dock( Unit *unitToDockWith );
1444  void RestoreGodliness();
1445 
1446 /*
1447  **************************************************************************************
1448  **** FACTION/FLIGHTGROUP STUFF ***
1449  **************************************************************************************
1450  */
1451 
1452 protected:
1453 //the flightgroup this ship is in
1455 //the flightgroup subnumber
1457 public:
1458  void SetFg( Flightgroup *fg, int fg_snumber );
1459 //The faction of this unit
1460  int faction;
1461  void SetFaction( int faction );
1462 //get the flightgroup description
1464  {
1465  return flightgroup;
1466  }
1467 //get the subnumber
1468  int getFgSubnumber() const
1469  {
1470  return flightgroup_subnumber;
1471  }
1472 //get the full flightgroup ID (i.e 'green-4')
1473  const std::string getFgID();
1474  // Changed next two lines from struct CargoColor to class CargoColor to fit line 70 declaration
1475  std::vector< class CargoColor >& FilterDowngradeList( std::vector< class CargoColor > &mylist, bool downgrade = true );
1476  std::vector< class CargoColor >& FilterUpgradeList( std::vector< class CargoColor > &mylist );
1477 
1478  bool IsBase() const;
1479 
1480 /*
1481  **************************************************************************************
1482  **** MISC STUFF ***
1483  **************************************************************************************
1484  */
1485 
1486 public:
1488  bool isTractorable( enum tractorHow how = tractorBoth ) const;
1489  void setTractorability( enum tractorHow how );
1490  enum tractorHow getTractorability() const;
1491 private:
1492  unsigned char tractorability_flags;
1493 
1494 protected:
1495 //if the unit is a planet, this contains the long-name 'mars-station'
1496  std::string fullname;
1497 public:
1498  void setFullname( std::string name )
1499  {
1500  fullname = name;
1501  }
1502  const string& getFullname() const
1503  {
1504  return fullname;
1505  }
1506 
1507  const string& getFilename() const
1508  {
1509  return filename.get();
1510  }
1511 
1512 //Is this class a unit
1513  virtual enum clsptr isUnit() const
1514  {
1515  return UNITPTR;
1516  }
1517  void Ref();
1518 //Low level list function to reference the unit as being the target of a UnitContainer or Colleciton
1519 //Releases the unit from this reference of UnitContainer or Collection
1520  void UnRef();
1521 //0 in additive is reaplce 1 is add 2 is mult
1522 //Put that in NetUnit & AcctUnit with string and with Unit
1524 
1525 //sets the full name/fgid for planets
1526  bool isStarShip() const
1527  {
1528  return isUnit() == UNITPTR;
1529  }
1530  bool isPlanet() const
1531  {
1532  return isUnit() == PLANETPTR;
1533  }
1534  bool isJumppoint() const
1535  {
1536  return GetDestinations().size() != 0;
1537  }
1538 
1539 //Uses Universe stuff -> maybe only needed in Unit class
1540  bool isEnemy( const Unit *other ) const
1541  {
1542  return getRelation( other ) < 0.0;
1543  }
1544  bool isFriend( const Unit *other ) const
1545  {
1546  return getRelation( other ) > 0.0;
1547  }
1548  bool isNeutral( const Unit *other ) const
1549  {
1550  return getRelation( other ) == 0.0;
1551  }
1552  float getRelation( const Unit *other ) const;
1553 
1554  void TurretFAW();
1555 
1556  /*
1557  **************************************************************************************
1558  **** ANIMATION STUFF ***
1559  **************************************************************************************
1560  */
1562 };
1563 
1564 Unit * findUnitInStarsystem( void *unitDoNotDereference );
1565 
1566 //Holds temporary values for inter-function XML communication Saves deprecated restr info
1568 {
1571  std::vector< Mount* >mountz;
1572  std::vector< Mesh* > meshes;
1573  std::vector< std::string >meshes_str;
1576  std::string shieldmesh_str;
1577  std::string rapidmesh_str;
1578  void *data;
1579  std::vector< Unit* >units;
1582  enum restr {YRESTR=1, PRESTR=2, RRESTR=4};
1583  const char *unitModifications;
1585  float unitscale;
1586  float ymin, ymax, ycur;
1587  float pmin, pmax, pcur;
1588  float rmin, rmax, rcur;
1589  std::string cargo_category;
1590  std::string hudimage;
1593 };
1594 
1596 {
1597  if (unit != NULL) {
1598 #ifdef CONTAINER_DEBUG
1599  CheckUnit( unit );
1600 #endif
1601  if ( unit->Killed() ) {
1602  unit->UnRef();
1603  unit = NULL;
1604  }
1605  }
1606  return unit;
1607 }
1608 
1609 #ifdef USE_OLD_COLLECTION
1610 inline void UnitCollection::UnitIterator::GetNextValidUnit()
1611 {
1612  while (pos->next->unit ? pos->next->unit->Killed() : false)
1613  remove();
1614 }
1615 #endif
1616 
1617 extern std::set< std::string >GetListOfDowngrades();
1618 extern void ClearDowngradeMap();
1619 #endif
1620 
1621 /*
1622  **************************************************************************************
1623  **** MESH ANIMATION STUFF ***
1624  **************************************************************************************
1625  */
1626 
1628 {
1629 protected:
1630  std::vector< std::vector<Mesh *> *> vecAnimations;
1631  std::vector< string > vecAnimationNames;
1632 
1634  unsigned int activeAnimation;
1636  bool done;
1637  unsigned int activeMesh;
1638  unsigned int nextactiveMesh;
1640  unsigned int loopCount;
1641 
1644 
1645 public:
1646  double curtime;
1647 
1648  static unsigned int unitCount;
1649 
1650  static std::map< string, Unit * > Units;
1651 
1652  MeshAnimation(Unit* _unitDst);
1653 
1654  bool Init(const char *filename, int faction, Flightgroup *flightgrp = NULL, const char *animationExt = NULL);
1655 
1656  static void UpdateFrames();
1657 
1658  void AnimationStep();
1659 
1660  void clear();
1661 
1662  ~MeshAnimation() { clear(); }
1663 
1664  string getAnimationName(unsigned int animationNumber) const;
1665 
1666  unsigned int getAnimationNumber(const char *name) const;
1667 
1668  void ChangeAnimation( const char *name );
1669 
1670  void ChangeAnimation( unsigned int AnimNumber );
1671 
1672  //set how_many_times to 0 for continuous loop animation
1673  void StartAnimation( unsigned int how_many_times = 0, int numAnimation = 0 );
1674 
1675  void StopAnimation();
1676 
1677  bool isAnimatedMesh() const;
1678 
1679  bool animationRuns() const;
1680 
1681  unsigned int numAnimations();
1682 
1683  bool isContinuousLoop() const;
1684 
1685  void addAnimation( std::vector<Mesh *> *meshes, const char* name );
1686 
1687  double framesPerSecond() const;
1688 
1689  double timePerFrame() const;
1690 
1691  void ToggleAnimatedMesh( bool on );
1692 
1693  void SetAniSpeed( float speed );
1694 };
1695 
1696 
1697 #endif
1698