Pioneer
FixedGuns.h
Go to the documentation of this file.
1 // Copyright © 2008-2021 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 void SetCoolingBoost(float cooler) { m_cooler_boost = cooler; };
53 
54 private:
55  struct GunData {
56  struct GunLoc {
59  };
60  std::vector<GunLoc> locs;
61  float recharge;
62  float temp_heat_rate;
63  float temp_cool_rate;
64  bool dual;
65  ProjectileData projData;
66  };
67 
68  bool m_is_firing[Guns::GUNMOUNT_MAX];
69  float m_recharge_stat[Guns::GUNMOUNT_MAX];
70  float m_temperature_stat[Guns::GUNMOUNT_MAX];
71  //TODO: Make it a vector and rework struct Gun to have bool dir={Forward,Backward}
72  bool m_gun_present[Guns::GUNMOUNT_MAX];
73  GunData m_gun[Guns::GUNMOUNT_MAX];
74  float m_cooler_boost;
75  bool m_shouldUseLeadCalc = false;
76  vector3d m_targetLeadPos;
77  vector3d m_currentLeadDir;
78 };
79 
80 #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:54
Definition: DynamicBody.h:15
Definition: FixedGuns.h:21
void Init(DynamicBody *b)
Definition: FixedGuns.cpp:41
void UnMountGun(int num)
Definition: FixedGuns.cpp:154
bool IsGunMounted(int idx) const
Definition: FixedGuns.h:47
virtual ~FixedGuns()
Definition: FixedGuns.cpp:19
void SetGunFiringState(int idx, int s)
Definition: FixedGuns.cpp:174
bool Fire(int num, Body *ship)
Definition: FixedGuns.cpp:180
const vector3d & GetCurrentLeadDir() const
Definition: FixedGuns.h:51
void UpdateGuns(float timeStep)
Definition: FixedGuns.cpp:213
FixedGuns()
Definition: FixedGuns.cpp:15
float GetProjSpeed(int idx) const
Definition: FixedGuns.h:49
virtual void SaveToJson(Json &jsonObj, Space *space)
Definition: FixedGuns.cpp:64
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:133
void IsDual(int idx, bool dual)
Definition: FixedGuns.h:40
virtual void LoadFromJson(const Json &jsonObj, Space *space)
Definition: FixedGuns.cpp:79
bool IsFiring()
Definition: FixedGuns.cpp:23
void InitGuns(SceneGraph::Model *m)
Definition: FixedGuns.cpp:97
const vector3d & GetTargetLeadPos() const
Definition: FixedGuns.h:50
bool IsBeam(const int num)
Definition: FixedGuns.cpp:36
float GetGunTemperature(int idx) const
Definition: FixedGuns.cpp:272
void SetCoolingBoost(float cooler)
Definition: FixedGuns.h:52
float GetGunRange(int idx) const
Definition: FixedGuns.h:48
void UpdateLead(float timeStep, int num, Body *ship, Body *target)
Definition: FixedGuns.cpp:237
Definition: RefCounted.h:11
Definition: Model.h:94
Definition: Space.h:19
Definition: Color.h:66
Definition: FixedGuns.h:56
vector3d dir
Definition: FixedGuns.h:58
vector3d pos
Definition: FixedGuns.h:57
Definition: Projectile.h:9