Starshatter_Open
Open source Starshatter engine
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Drone.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: Drone.cpp
7  AUTHOR: John DiCamillo
8 
9 
10  OVERVIEW
11  ========
12  Laser and Missile class
13 */
14 
15 #include "MemDebug.h"
16 #include "Drone.h"
17 #include "Weapon.h"
18 #include "Ship.h"
19 #include "Sim.h"
20 #include "Explosion.h"
21 
22 #include "Game.h"
23 #include "Bolt.h"
24 #include "Sprite.h"
25 #include "Solid.h"
26 #include "Light.h"
27 #include "Bitmap.h"
28 #include "DataLoader.h"
29 #include "Sound.h"
30 
31 // +--------------------------------------------------------------------+
32 
33 Drone::Drone(const Point& pos, const Camera& shot_cam, WeaponDesign* dsn, const Ship* ship)
34 : Shot(pos, shot_cam, dsn, ship),
35 decoy_type(0), iff_code(0)
36 {
38 
39  if (dsn) {
40  decoy_type = dsn->decoy_type;
41  probe = dsn->probe;
42  integrity = dsn->integrity;
43  sprintf_s(name, "Drone %04d", Identity());
44  }
45 }
46 
47 // +--------------------------------------------------------------------+
48 
50 {
51 }
52 
53 // +--------------------------------------------------------------------+
54 
55 void
57 {
58  if (!probe)
59  Shot::SeekTarget(target, sub);
60 }
61 
62 // +--------------------------------------------------------------------+
63 
64 void
65 Drone::ExecFrame(double seconds)
66 {
67  Shot::ExecFrame(seconds);
68 }
69 
70 // +--------------------------------------------------------------------+
71 
72 void
74 {
75  Shot::Disarm();
76 }
77 
78 // +--------------------------------------------------------------------+
79 
80 void
82 {
83  Shot::Destroy();
84 }
85 
86 // +--------------------------------------------------------------------+
87 
88 double
89 Drone::PCS() const
90 {
91  if (decoy_type == 0 && !probe)
92  return 10e3;
93 
94  return 0;
95 }
96 
97 double
98 Drone::ACS() const
99 {
100  if (decoy_type == 0 && !probe)
101  return 1e3;
102 
103  return 0;
104 }
105 
106 // +--------------------------------------------------------------------+
107 
108 const char*
110 {
111  return Ship::ClassName(decoy_type);
112 }
113 
114 int
116 {
117  return decoy_type;
118 }
119 
120 // +--------------------------------------------------------------------+
121 
122 int
123 Drone::HitBy(Shot* shot, Point& impact)
124 {
125  if (life == 0 || !shot->IsArmed()) return 0;
126 
127  const int HIT_NOTHING = 0;
128  const int HIT_HULL = 1;
129 
130  Point hull_impact;
131  int hit_type = HIT_NOTHING;
132  Point shot_loc = shot->Location();
133  Point shot_org = shot->Origin();
134  Point delta = shot_loc - Location();
135  double dlen = delta.length();
136  double dscale = 1;
137  float scale = design->explosion_scale;
138  Sim* sim = Sim::GetSim();
139 
140  if (scale <= 0)
141  scale = design->scale;
142 
143  // MISSILE PROCESSING ------------------------------------------------
144 
145  if (shot->IsMissile()) {
146  if (dlen < 10 * Radius()) {
147  hull_impact = impact = shot_loc;
148  sim->CreateExplosion(impact, Velocity(), Explosion::HULL_FLASH, 0.3f * scale, scale, region);
149  sim->CreateExplosion(impact, Point(), Explosion::SHOT_BLAST, 2.0f, scale, region);
150  hit_type = HIT_HULL;
151  }
152  }
153 
154  // ENERGY WEP PROCESSING ---------------------------------------------
155 
156  else {
157  if (shot->IsBeam()) {
158  // check right angle spherical distance:
159  Point d0 = Location() - shot_org;
160  Point w = shot_loc - shot_org; w.Normalize();
161  Point test = shot_org + w * (d0 * w);
162  Point d1 = test - Location();
163  double dlen = d1.length(); // distance of point from line
164 
165  if (dlen < 2*Radius()) {
166  hull_impact = impact = test;
167  shot->SetBeamPoints(shot_org, impact);
168  sim->CreateExplosion(impact, Velocity(), Explosion::BEAM_FLASH, 0.30f * scale, scale, region);
169  hit_type = HIT_HULL;
170  }
171  }
172  else if (dlen < 2*Radius()) {
173  hull_impact = impact = shot_loc;
174  sim->CreateExplosion(impact, Velocity(), Explosion::HULL_FLASH, 0.30f * scale, scale, region);
175  hit_type = HIT_HULL;
176  }
177  }
178 
179  // DAMAGE RESOLUTION -------------------------------------------------
180 
181  if (hit_type != HIT_NOTHING) {
182  double effective_damage = shot->Damage() * dscale;
183 
184  if (shot->IsBeam()) {
185  effective_damage *= Game::FrameTime();
186  }
187  else {
188  ApplyTorque(shot->Velocity() * (float) effective_damage * 1e-6f);
189  }
190 
191  if (effective_damage > 0)
192  Physical::InflictDamage(effective_damage);
193  }
194 
195  return hit_type;
196 }