Pioneer
FixedGuns.h
Go to the documentation of this file.
1 // Copyright © 2008-2023 Pioneer Developers. See AUTHORS.txt for details
2 // Licensed under the terms of the GPL v3. See licenses/GPL-3.txt
3 
4 #ifndef FIXEDGUNS_H
5 #define FIXEDGUNS_H
6 
7 #include "Json.h"
8 #include "Projectile.h"
9 #include "scenegraph/Model.h"
10 #include "vector3.h"
11 
12 class DynamicBody;
13 class Space;
14 
15 enum Guns {
18  GUNMOUNT_MAX = 2
19 };
20 
21 class FixedGuns : public RefCounted {
22 public:
23  FixedGuns();
24  virtual ~FixedGuns();
25  void Init(DynamicBody *b);
26  void InitGuns(SceneGraph::Model *m);
27 
28  virtual void SaveToJson(Json &jsonObj, Space *space);
29  virtual void LoadFromJson(const Json &jsonObj, Space *space);
30 
31  void UpdateGuns(float timeStep);
32  void UpdateLead(float timeStep, int num, Body *ship, Body *target);
33  bool Fire(int num, Body *ship);
34  void SetGunFiringState(int idx, int s);
35  void SetShouldUseLeadCalc(bool enable) { m_shouldUseLeadCalc = enable; }
36 
37  bool IsFiring();
38  bool IsFiring(const int num);
39  bool IsBeam(const int num);
40  inline void IsDual(int idx, bool dual) { m_gun[idx].dual = dual; };
41 
42  void MountGun(const int num, const float recharge, const float lifespan, const float damage, const float length,
43  const float width, const bool mining, const Color &color, const float speed, const bool beam, const float heatrate, const float coolrate);
44  void UnMountGun(int num);
45 
46  float GetGunTemperature(int idx) const;
47  inline bool IsGunMounted(int idx) const { return m_gun_present[idx]; }
48  inline float GetGunRange(int idx) const { return m_gun[idx].projData.speed * m_gun[idx].projData.lifespan; };
49  inline float GetProjSpeed(int idx) const { return m_gun[idx].projData.speed; };
50  inline const vector3d &GetTargetLeadPos() const { return m_targetLeadPos; }
51  inline const vector3d &GetCurrentLeadDir() const { return m_currentLeadDir; }
52  inline bool IsFiringSolutionOk() const { return m_firingSolutionOk; }
53  inline void SetCoolingBoost(float cooler) { m_cooler_boost = cooler; };
54 
55 private:
56  struct GunData {
57  struct GunLoc {
60  };
61  std::vector<GunLoc> locs;
62  float recharge;
63  float temp_heat_rate;
64  float temp_cool_rate;
65  bool dual;
66  ProjectileData projData;
67  };
68 
69  bool m_is_firing[Guns::GUNMOUNT_MAX];
70  float m_recharge_stat[Guns::GUNMOUNT_MAX];
71  float m_temperature_stat[Guns::GUNMOUNT_MAX];
72  //TODO: Make it a vector and rework struct Gun to have bool dir={Forward,Backward}
73  bool m_gun_present[Guns::GUNMOUNT_MAX];
74  GunData m_gun[Guns::GUNMOUNT_MAX];
75  float m_cooler_boost;
76  bool m_shouldUseLeadCalc = false;
77  vector3d m_targetLeadPos;
78  vector3d m_currentLeadDir;
79  bool m_firingSolutionOk = false;
80 };
81 
82 #endif // FIXEDGUNS_H
Guns
Definition: FixedGuns.h:15
@ GUN_REAR
Definition: FixedGuns.h:17
@ GUNMOUNT_MAX
Definition: FixedGuns.h:18
@ GUN_FRONT
Definition: FixedGuns.h:16
nlohmann::json Json
Definition: Json.h:8
Definition: Body.h:57
Definition: DynamicBody.h:15
Definition: FixedGuns.h:21
void Init(DynamicBody *b)
Definition: FixedGuns.cpp:45
void UnMountGun(int num)
Definition: FixedGuns.cpp:157
bool IsGunMounted(int idx) const
Definition: FixedGuns.h:47
virtual ~FixedGuns()
Definition: FixedGuns.cpp:23
void SetGunFiringState(int idx, int s)
Definition: FixedGuns.cpp:177
bool Fire(int num, Body *ship)
Definition: FixedGuns.cpp:183
const vector3d & GetCurrentLeadDir() const
Definition: FixedGuns.h:51
void UpdateGuns(float timeStep)
Definition: FixedGuns.cpp:215
FixedGuns()
Definition: FixedGuns.cpp:19
float GetProjSpeed(int idx) const
Definition: FixedGuns.h:49
virtual void SaveToJson(Json &jsonObj, Space *space)
Definition: FixedGuns.cpp:67
void SetShouldUseLeadCalc(bool enable)
Definition: FixedGuns.h:35
void MountGun(const int num, const float recharge, const float lifespan, const float damage, const float length, const float width, const bool mining, const Color &color, const float speed, const bool beam, const float heatrate, const float coolrate)
Definition: FixedGuns.cpp:136
void IsDual(int idx, bool dual)
Definition: FixedGuns.h:40
virtual void LoadFromJson(const Json &jsonObj, Space *space)
Definition: FixedGuns.cpp:82
bool IsFiring()
Definition: FixedGuns.cpp:27
void InitGuns(SceneGraph::Model *m)
Definition: FixedGuns.cpp:100
const vector3d & GetTargetLeadPos() const
Definition: FixedGuns.h:50
bool IsBeam(const int num)
Definition: FixedGuns.cpp:40
float GetGunTemperature(int idx) const
Definition: FixedGuns.cpp:314
void SetCoolingBoost(float cooler)
Definition: FixedGuns.h:53
float GetGunRange(int idx) const
Definition: FixedGuns.h:48
bool IsFiringSolutionOk() const
Definition: FixedGuns.h:52
void UpdateLead(float timeStep, int num, Body *ship, Body *target)
Definition: FixedGuns.cpp:239
Definition: RefCounted.h:11
Definition: Model.h:88
Definition: Space.h:19
Definition: Color.h:66
Definition: FixedGuns.h:57
vector3d dir
Definition: FixedGuns.h:59
vector3d pos
Definition: FixedGuns.h:58
Definition: Projectile.h:9