Starshatter_Open
Open source Starshatter engine
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
HardPoint.cpp
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: HardPoint.cpp
7  AUTHOR: John DiCamillo
8 
9 
10  OVERVIEW
11  ========
12  HardPoint class
13 */
14 
15 #include "MemDebug.h"
16 #include "HardPoint.h"
17 #include "Weapon.h"
18 #include "WeaponDesign.h"
19 #include "Shot.h"
20 #include "Ship.h"
21 #include "Sim.h"
22 
23 // +----------------------------------------------------------------------+
24 
25 HardPoint::HardPoint(Vec3 muzzle_loc, double az, double el)
26 : aim_azimuth((float) az), aim_elevation((float) el), muzzle(muzzle_loc)
27 {
28  ZeroMemory(designs, sizeof(designs));
29 }
30 
31 // +----------------------------------------------------------------------+
32 
34 : aim_azimuth(h.aim_azimuth), aim_elevation(h.aim_elevation), muzzle(h.muzzle),
35 mount_rel(h.mount_rel), radius(h.radius), hull_factor(h.hull_factor)
36 {
37  CopyMemory(designs, h.designs, sizeof(designs));
38 }
39 
40 // +--------------------------------------------------------------------+
41 
43 {
44 }
45 
46 // +--------------------------------------------------------------------+
47 
48 void
49 HardPoint::Mount(Point loc, float rad, float hull)
50 {
51  mount_rel = loc;
52  radius = rad;
53  hull_factor = hull;
54 }
55 
56 // +--------------------------------------------------------------------+
57 
58 void
60 {
61  for (int i = 0; i < MAX_DESIGNS; i++) {
62  if (!designs[i]) {
63  designs[i] = d;
64  return;
65  }
66  }
67 }
68 
69 // +--------------------------------------------------------------------+
70 
71 Weapon*
72 HardPoint::CreateWeapon(int type_index)
73 {
74  if (type_index >= 0 && type_index < MAX_DESIGNS && designs[type_index]) {
75  Vec3 zero_pt = Vec3(0.0f, 0.0f, 0.0f);
76  Vec3* muzzle_pt = &zero_pt;
77 
78  if (designs[type_index]->turret.length() == 0)
79  muzzle_pt = &muzzle;
80 
81  Weapon* missile = new(__FILE__,__LINE__) Weapon(designs[type_index],
82  1,
83  muzzle_pt,
86  missile->SetAbbreviation(GetAbbreviation());
87  missile->Mount(mount_rel, radius, hull_factor);
88  return missile;
89  }
90 
91  return 0;
92 }
93 
94 // +--------------------------------------------------------------------+
95 
96 double
97 HardPoint::GetCarryMass(int type_index)
98 {
99  if (type_index >= 0 && type_index < MAX_DESIGNS && designs[type_index])
100  return designs[type_index]->carry_mass;
101 
102  return 0;
103 }
104