Starshatter_Open
Open source Starshatter engine
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Ship.h
Go to the documentation of this file.
1 /* Project Starshatter 4.5
2  Destroyer Studios LLC
3  Copyright © 1997-2004. All Rights Reserved.
4 
5  SUBSYSTEM: Stars.exe
6  FILE: Ship.h
7  AUTHOR: John DiCamillo
8 
9 
10  OVERVIEW
11  ========
12  Starship (or space/ground station) class
13 */
14 
15 #ifndef Ship_h
16 #define Ship_h
17 
18 #include "Types.h"
19 #include "SimObject.h"
20 #include "DetailSet.h"
21 #include "Director.h"
22 #include "Geometry.h"
23 #include "List.h"
24 
25 // +--------------------------------------------------------------------+
26 
27 class Ship;
28 class Shot;
29 class Drone;
30 
31 class Bitmap;
32 class CombatUnit;
33 class Computer;
34 class Contact;
35 class Drive;
36 class Element;
37 class Farcaster;
38 class FlightComp;
39 class FlightDeck;
40 class Hangar;
41 class InboundSlot;
42 class Instruction;
43 class LandingGear;
44 class MotionController;
45 class NavLight;
46 class NavSystem;
47 class PowerSource;
48 class QuantumDrive;
49 class RadioMessage;
50 class Shield;
51 class ShieldRep;
52 class ShipDesign;
53 class ShipKiller;
54 class Solid;
55 class Skin;
56 class Sound;
57 class Sensor;
58 class System;
59 class Thruster;
60 class Weapon;
61 class WeaponDesign;
62 class WeaponGroup;
63 
64 // +--------------------------------------------------------------------+
65 
66 class Ship : public SimObject,
67 public SimObserver
68 {
69 public:
70  static const char* TYPENAME() { return "Ship"; }
71 
73  DRONE = 0x0001,
74  FIGHTER = 0x0002,
75  ATTACK = 0x0004,
76  LCA = 0x0008,
77  COURIER = 0x0010,
78  CARGO = 0x0020,
79  CORVETTE = 0x0040,
80  FREIGHTER = 0x0080,
81  FRIGATE = 0x0100,
82  DESTROYER = 0x0200,
83  CRUISER = 0x0400,
84  BATTLESHIP = 0x0800,
85  CARRIER = 0x1000,
86  DREADNAUGHT = 0x2000,
87 
88  STATION = 0x4000,
89  FARCASTER = 0x8000,
90 
91  MINE = 0x00010000,
92  COMSAT = 0x00020000,
93  DEFSAT = 0x00040000,
94  SWACS = 0x00080000,
95 
96  BUILDING = 0x00100000,
97  FACTORY = 0x00200000,
98  SAM = 0x00400000,
99  EWR = 0x00800000,
100  C3I = 0x01000000,
101  STARBASE = 0x02000000,
102 
103  DROPSHIPS = 0x0000000f,
104  STARSHIPS = 0x0000fff0,
105  SPACE_UNITS = 0x000f0000,
106  GROUND_UNITS = 0xfff00000
107  };
108 
118 
121 
122  // CONSTRUCTORS:
123  Ship(const char* ship_name, const char* reg_num, ShipDesign* design, int IFF=0, int cmd_ai=0, const int* loadout=0);
124  virtual ~Ship();
125 
126  int operator == (const Ship& s) const { return id == s.id; }
127 
128  static void Initialize();
129  static void Close();
130 
131  virtual void ExecFrame(double seconds);
132  virtual void AeroFrame(double seconds);
133  virtual void StatFrame(double seconds);
134  virtual void DockFrame(double seconds);
135  virtual void LinearFrame(double seconds);
136  virtual void ExecSensors(double seconds);
137 
138  void ExecNavFrame(double seconds);
139  void ExecPhysics(double seconds);
140  void ExecThrottle(double seconds);
141  void ExecSystems(double seconds);
142 
143  virtual void Activate(Scene& scene);
144  virtual void Deactivate(Scene& scene);
145  virtual void SelectDetail(double seconds);
146  virtual void SetRegion(SimRegion* rgn);
147  virtual int GetTextureList(List<Bitmap>& textures);
148 
149  // DIRECTION:
150  virtual void SetControls(MotionController* m);
151  virtual void SetNetworkControl(Director* net_ctrl=0);
152  void SetDirectorInfo(const char* msg) { director_info = msg; }
153  const char* GetDirectorInfo() const { return director_info; }
154  void SetAIMode(int n) { ai_mode = (BYTE) n; }
155  int GetAIMode() const { return (int) ai_mode; }
156  void SetCommandAILevel(int n) { command_ai_level = (BYTE) n; }
157  int GetCommandAILevel() const { return command_ai_level; }
158  virtual int GetFlightPhase() const { return flight_phase; }
159  virtual void SetFlightPhase(OP_MODE phase);
160  bool IsNetObserver() const { return net_observer_mode; }
161  void SetNetObserver(bool n) { net_observer_mode = n; }
162 
163  bool IsInvulnerable() const { return invulnerable; }
164  void SetInvulnerable(bool n) { invulnerable = n; }
165 
166  double GetHelmHeading() const { return helm_heading; }
167  double GetHelmPitch() const { return helm_pitch; }
168  void SetHelmHeading(double h);
169  void SetHelmPitch(double p);
170  virtual void ApplyHelmYaw(double y);
171  virtual void ApplyHelmPitch(double p);
172  virtual void ApplyPitch(double pitch_acc); // override for G limiter
173 
174  void ArcadeStop() { arcade_velocity *= 0; }
175 
176  // CAMERA:
177  Point BridgeLocation() const { return bridge_vec; }
178  Point ChaseLocation() const { return chase_vec; }
180 
181  // FLIGHT DECK:
182  Ship* GetController() const;
183  int NumInbound() const;
184  int NumFlightDecks() const;
185  FlightDeck* GetFlightDeck(int i=0) const;
186  Ship* GetCarrier() const { return carrier; }
187  FlightDeck* GetDock() const { return dock; }
188  void SetCarrier(Ship* c, FlightDeck* d);
189  void Stow();
190  InboundSlot* GetInbound() const { return inbound; }
191  void SetInbound(InboundSlot* s);
192 
193  // DRIVE SYSTEMS:
194  int GetFuelLevel() const; // (0-100) percent of full tank
195  void SetThrottle(double percent);
196  void SetAugmenter(bool enable);
197  double Thrust(double seconds) const;
198  double VelocityLimit() const { return vlimit; }
199  Drive* GetDrive() const { return main_drive; }
200  double Throttle() const { return throttle; }
201  bool Augmenter() const { return augmenter; }
203  Farcaster* GetFarcaster() const { return farcaster; }
204 
205  bool IsAirborne() const;
206  bool IsDropCam() const { return transition_type == TRANSITION_DROP_CAM; }
209  bool IsSkipping() const { return transition_type == TRANSITION_TIME_SKIP; }
210  bool IsDying() const { return transition_type == TRANSITION_DEATH_SPIRAL; }
211  bool IsDead() const { return transition_type == TRANSITION_DEAD; }
212  bool InTransition() const { return transition_type != TRANSITION_NONE; }
213  void DropOrbit();
214  void MakeOrbit();
215  bool CanTimeSkip();
216  bool IsInCombat();
217  void TimeSkip();
218  void DropCam(double time=10, double range=0);
219  void DeathSpiral();
220  void CompleteTransition();
221  void SetTransition(double trans_time, int trans_type, const Point& trans_loc);
222 
223  double CompassHeading() const;
224  double CompassPitch() const;
225  double AltitudeMSL() const;
226  double AltitudeAGL() const;
227  double GForce() const;
228 
229  virtual void SetupAgility();
230 
231  // FLIGHT CONTROL SYSTEM (FLCS):
232  void ExecFLCSFrame();
233  void CycleFLCSMode();
234  void SetFLCSMode(int mode);
235  int GetFLCSMode() const;
236  void SetTransX(double t);
237  void SetTransY(double t);
238  void SetTransZ(double t);
239 
240  bool IsGearDown();
241  void LowerGear();
242  void RaiseGear();
243  void ToggleGear();
244  void ToggleNavlights();
245 
246  // WEAPON SYSTEMS:
247  virtual void CheckFriendlyFire();
248  virtual void CheckFire(bool c) { check_fire = c; }
249  virtual bool CheckFire() const { return (check_fire||net_observer_mode)?true:false; }
250  virtual void SelectWeapon(int n, int w);
251  virtual bool FireWeapon(int n);
252  virtual bool FirePrimary() { return FireWeapon(primary); }
253  virtual bool FireSecondary() { return FireWeapon(secondary); }
254  virtual bool FireDecoy();
255  virtual void CyclePrimary();
256  virtual void CycleSecondary();
257  virtual Weapon* GetPrimary() const;
258  virtual Weapon* GetSecondary() const;
259  virtual Weapon* GetWeaponByIndex(int n);
260  virtual WeaponGroup* GetPrimaryGroup() const;
261  virtual WeaponGroup* GetSecondaryGroup() const;
262  virtual Weapon* GetDecoy() const;
263  virtual List<Shot>& GetActiveDecoys();
264  virtual void AddActiveDecoy(Drone* d);
265  virtual int* GetLoadout() { return loadout; }
266 
268  void AddThreat(Shot* s);
269  void DropThreat(Shot* s);
270 
271  virtual bool Update(SimObject* obj);
272  virtual const char* GetObserverName() const { return name; }
273 
274  virtual int GetMissileEta(int index) const;
275  virtual void SetMissileEta(int id, int eta);
276 
277  virtual WeaponDesign* GetPrimaryDesign() const;
278  virtual WeaponDesign* GetSecondaryDesign() const;
279 
280  virtual void SetTarget(SimObject* t, System* sub=0, bool from_net=false);
281  virtual SimObject* GetTarget() const { return target; }
282  virtual System* GetSubTarget() const { return subtarget; }
283  virtual void CycleSubTarget(int dir=1);
284  virtual void DropTarget();
285  virtual void LockTarget(int type=SimObject::SIM_SHIP,
286  bool closest=false,
287  bool hostile=false);
288  virtual void LockTarget(SimObject* candidate);
289  virtual bool IsTracking(SimObject* tgt);
290  virtual bool GetTrigger(int i) const;
291  virtual void SetTrigger(int i);
292 
293  Ship* GetWard() const { return ward; }
294  void SetWard(Ship* s);
295 
296  // SHIELD SYSTEMS:
297  virtual double InflictDamage(double damage,
298  Shot* shot = 0,
299  int hit_type = 3,
300  Point hull_impact = Point(0,0,0));
301 
302  virtual double InflictSystemDamage(double damage, Shot* shot, Point impact);
303 
304  virtual void InflictNetDamage(double damage, Shot* shot=0);
305  virtual void InflictNetSystemDamage(System* system, double damage, BYTE type);
306  virtual void SetNetSystemStatus(System* system, int status, int power, int reactor, double avail);
307  virtual void SetIntegrity(float n) { integrity = n; }
308 
309  virtual void Destroy();
310  virtual int ShieldStrength() const;
311  virtual int HullStrength() const;
312  virtual int HitBy(Shot* shot, Point& impact);
313  virtual int CollidesWith(Physical& o);
314 
315  // SENSORS AND VISIBILITY:
316  virtual int GetContactID() const { return contact_id; }
317  virtual int GetIFF() const { return IFF_code; }
318  virtual void SetIFF(int iff);
319  virtual Color MarkerColor() const;
320  static Color IFFColor(int iff);
321  virtual void DoEMCON();
322  virtual double PCS() const;
323  virtual double ACS() const;
324  int NumContacts() const; // actual sensor contacts
326  virtual int GetSensorMode() const;
327  virtual void SetSensorMode(int mode);
328  virtual void LaunchProbe();
329  virtual Weapon* GetProbeLauncher() const { return probe; }
330  virtual Drone* GetProbe() const { return sensor_drone; }
331  virtual void SetProbe(Drone* d);
332  virtual int GetEMCON() const { return emcon; }
333  virtual void SetEMCON(int e, bool from_net=false);
334  virtual Contact* FindContact(SimObject* s) const;
335  virtual bool IsHostileTo(const SimObject* o) const;
336 
337  // GENERAL ACCESSORS:
338  const char* Registry() const { return regnum; }
339  void SetName(const char* ident) { strcpy_s(name, ident); }
340  const ShipDesign* Design() const { return design; }
341  const char* Abbreviation() const;
342  const char* DesignName() const;
343  const char* DesignFileName() const;
344  static const char* ClassName(int c);
345  static int ClassForName(const char* name);
346  const char* ClassName() const;
347  CLASSIFICATION Class() const;
348  bool IsGroundUnit() const;
349  bool IsStarship() const;
350  bool IsDropship() const;
351  bool IsStatic() const;
352  bool IsRogue() const;
353  void SetRogue(bool r=true);
354  int GetFriendlyFire() const { return ff_count; }
355  void SetFriendlyFire(int f);
356  void IncFriendlyFire(int f=1);
357  double Agility() const { return agility; }
358  DWORD MissionClock() const;
359  Graphic* Cockpit() const;
360  void ShowCockpit();
361  void HideCockpit();
362  int Value() const;
363  double AIValue() const;
364  static int Value(int type);
365 
366  const Skin* GetSkin() const { return skin; }
367  void UseSkin(const Skin* s) { skin = s; }
368  void ShowRep();
369  void HideRep();
370  void EnableShadows(bool enable);
371 
372  int RespawnCount() const { return respawns; }
373  void SetRespawnCount(int r) { respawns = r; }
374  const Point& RespawnLoc() const { return respawn_loc; }
375  void SetRespawnLoc(const Point& rl)
376  { respawn_loc = rl; }
377 
378  double WarpFactor() const { return warp_fov; }
379  void SetWarp(double w) { warp_fov = (float) w; }
380 
381  void MatchOrientation(const Ship& s);
382 
383  // ORDERS AND NAVIGATION:
384  void ExecEvalFrame(double seconds);
385  void SetLaunchPoint(Instruction* pt);
386  void AddNavPoint(Instruction* pt, Instruction* afterPoint=0);
387  void DelNavPoint(Instruction* pt);
388  void ClearFlightPlan();
390  int GetNavIndex(const Instruction* n);
391  double RangeToNavPoint(const Instruction* n);
392  void SetNavptStatus(Instruction* n, int status);
394  int FlightPlanLength();
395  CombatUnit* GetCombatUnit() const { return combat_unit; }
396  Element* GetElement() const { return element; }
397  Ship* GetLeader() const;
398  int GetElementIndex() const;
399  int GetOrigElementIndex() const;
400  void SetElement(Element* e);
401 
402  Instruction* GetRadioOrders() const;
403  void ClearRadioOrders();
404  void HandleRadioMessage(RadioMessage* msg);
405  bool IsAutoNavEngaged();
406  void SetAutoNav(bool engage=true);
407  void CommandMode();
408 
409  void ClearTrack();
410  void UpdateTrack();
411  int TrackLength() const { return ntrack; }
412  Point TrackPoint(int i) const;
413 
414  // DAMAGE CONTROL AND ENGINEERING:
416  double RepairSpeed() const;
417  int RepairTeams() const;
418  void RepairSystem(System* sys);
419  void IncreaseRepairPriority(int task_index);
420  void DecreaseRepairPriority(int task_index);
421  void ExecMaintFrame(double seconds);
422  bool AutoRepair() const { return auto_repair; }
423  void EnableRepair(bool e) { auto_repair = e; }
424  bool MasterCaution() const { return master_caution; }
425  void ClearCaution() { master_caution = 0; }
426 
427  // SYSTEM ACCESSORS:
428  List<System>& Systems() { return systems; }
430  List<Drive>& Drives() { return drives; }
435  Shield* GetShield() { return shield; }
436  Solid* GetShieldRep() { return (Solid*) shieldRep; }
437  Sensor* GetSensor() { return sensor; }
439  FlightComp* GetFLCS() { return flcs; }
441  Hangar* GetHangar() { return hangar; }
442  LandingGear* GetGear() { return gear; }
443 
444  System* GetSystem(int sys_id);
445 
446  static int GetControlModel() { return control_model; }
447  static void SetControlModel(int n) { control_model = n; }
448  static int GetFlightModel() { return flight_model; }
449  static void SetFlightModel(int f) { flight_model = f; }
450  static int GetLandingModel() { return landing_model; }
451  static void SetLandingModel(int f) { landing_model = f; }
452  static double GetFriendlyFireLevel() { return friendly_fire_level; }
453  static void SetFriendlyFireLevel(double f)
454  { friendly_fire_level = f; }
455 
456 protected:
457  int CheckShotIntersection(Shot* shot, Point& ipt, Point& hpt, Weapon** wep=0);
458  WeaponGroup* FindWeaponGroup(const char* name);
459 
460  char regnum[16];
466  double vlimit;
467  double agility;
468  double throttle;
470  bool augmenter;
471  float wep_mass;
472  float wep_resist;
473 
474  int IFF_code;
476  int ff_count;
478 
483  int primary;
485 
486  const Skin* skin;
504 
513 
519 
522 
523  const char* director_info;
524  BYTE ai_mode;
526  BYTE flcs_mode;
528 
529  float pcs; // passive sensor cross section
530  float acs; // active sensor cross section
531  BYTE emcon;
532  BYTE old_emcon;
534 
535  DWORD launch_time;
537 
541 
543 
545  int ntrack;
546  DWORD track_time;
547 
549  float helm_pitch;
550 
552  float g_force;
553 
554  float warp_fov;
555 
560  int respawns;
561 
568 
569  int missile_id[4];
570  BYTE missile_eta[4];
571  bool trigger[4];
572  int* loadout;
573 
575 
576  static int control_model;
577  static int flight_model;
578  static int landing_model;
579  static double friendly_fire_level;
580 };
581 
582 #endif Ship_h
583