Debian Codegraph @

src/esm.cpp

raw symbols SCIP
1 /***************************************************************************
2 esm.cpp - description
3 -------------------
4 begin : Wed August 15 2001
5 copyright : (C) 2001 by Rick McDaniel
6 email : [email protected]
7 $Id: esm.cpp,v 1.5 2003/04/14 05:51:03 mbridak Exp $
8 ***************************************************************************/
9
10 /***************************************************************************
11 * *
12 * This program is free software; you can redistribute it and/or modify *
13 * it under the terms of the GNU General Public License as published by *
14 * the Free Software Foundation; either version 2 of the License. *
15 * . *
16 * *
17 ***************************************************************************/
18 #include <string>
19 #include "SDL/SDL.h"
20 #include "SDL/SDL_image.h"
21 #include "SDL/SDL_thread.h"
22 #include "dfont.h"cxx . . $ `<file>/src/dfont.h`/
23 #include "files.h"cxx . . $ `<file>/src/files.h`/
24 #include "submarine.h"cxx . . $ `<file>/src/submarine.h`/
25
26 #include "esm.h"cxx . . $ `<file>/src/esm.h`/
27 #include "dstack.h"cxx . . $ `<file>/src/dstack.h`/
28 #include <cmath>
29 #include <cstdlib>
30
31 // rdm windows
32 #include <iostream>
33 using namespace std;
34
35 DStackcxx . . $ DStack# EsmStackcxx . . $ EsmStack.;
36
37
38 Esmcxx . . $ Esm#::Esmcxx . . $ Esm#Esm(a9ab5cc9dc811b12).(Submarinecxx . . $ Submarine# *temp):Subscxx . . $ Esm#Subs.(temp)
39 {
40 // Default values: mast down, power off
41 MastHeightcxx . . $ Esm#MastHeight. = 68; // Max height of esm mast
42 Mastcxx . . $ Esm#Mast. = false;
43 }
44 Esmcxx . . $ Esm#::~cxx . . $ Esm#`~Esm`(ced63f7c635d850d).Esmcxx . . $ Esm#(){
45 }
46
47 void Esmcxx . . $ Esm#::InitGraphicscxx . . $ Esm#InitGraphics(fac4f6e207c3be86).(SDL_Surface *temp, SDL_Surface *tempesmscreen)
48 {
49 screencxx . . $ Esm#screen.=temp;
50 esmscreencxx . . $ Esm#esmscreen.=tempesmscreen;
51
52 temp = SDL_CreateRGBSurface(SDL_SWSURFACEcxx . . $ `<external>/3508485105195885937/SDL_video.h:229:9`!, 420, 490, 16,
53 screencxx . . $ Esm#screen.->format->Rmask,
54 screencxx . . $ Esm#screen.->format->Gmask,
55 screencxx . . $ Esm#screen.->format->Bmask,
56 screencxx . . $ Esm#screen.->format->Amask);
57 tempscreencxx . . $ Esm#tempscreen.=SDL_DisplayFormat(temp);
58 SDL_FreeSurface(temp);
59
60 LoadWidgetscxx . . $ Esm#LoadWidgets(49f6e7a06ebc5aa8).();
61 DisplayWidgetscxx . . $ Esm#DisplayWidgets(49f6e7a06ebc5aa8).();
62 orangecxx . . $ Esm#orange. = SDL_MapRGB(screencxx . . $ Esm#screen.->format, 238, 118, 0);
63 blackcxx . . $ Esm#black. = SDL_MapRGB(screencxx . . $ Esm#screen.->format, 0, 0, 0);
64 }
65
66 void Esmcxx . . $ Esm#::LoadWidgetscxx . . $ Esm#LoadWidgets(49f6e7a06ebc5aa8).(){
67
68 SDL_Surface *temp;
69
70 temp = Load_Imagecxx . . $ Load_Image(ad2755de9658a3fe).("images/mastdownoff.png");
71 if(temp != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!) mastdownoffcxx . . $ Esm#mastdownoff. = SDL_DisplayFormat(temp);
72 if ( mastdownoffcxx . . $ Esm#mastdownoff. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`! ) {
73 cerrcxx . . $ cerr.<<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7)."Function LoadWidgets()" <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). endlcxx . . $ std/endl(345bf97a19cc83a9).
74 <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). SDL_GetError() <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). endlcxx . . $ std/endl(345bf97a19cc83a9).;
75 SDL_Quit();
76 exit(0);
77 }
78 SDL_FreeSurface(temp);
79
80
81 temp = Load_Imagecxx . . $ Load_Image(ad2755de9658a3fe).("images/mastdownon.png");
82 if(temp != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!) mastdownoncxx . . $ Esm#mastdownon. = SDL_DisplayFormat(temp);
83 if ( mastdownoncxx . . $ Esm#mastdownon. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`! ) {
84 cerrcxx . . $ cerr.<<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7)."Function LoadWidgets()" <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). endlcxx . . $ std/endl(345bf97a19cc83a9).
85 <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). SDL_GetError() <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). endlcxx . . $ std/endl(345bf97a19cc83a9).;
86 SDL_Quit();
87 exit(0);
88 }
89 SDL_FreeSurface(temp);
90
91 temp = Load_Imagecxx . . $ Load_Image(ad2755de9658a3fe).("images/mastupoff.png");
92 if(temp != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!) mastupoffcxx . . $ Esm#mastupoff. = SDL_DisplayFormat(temp);
93 if ( mastupoffcxx . . $ Esm#mastupoff.== NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`! ) {
94 cerrcxx . . $ cerr.<<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7)."Function LoadWidgets()" <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). endlcxx . . $ std/endl(345bf97a19cc83a9).
95 <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). SDL_GetError() <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). endlcxx . . $ std/endl(345bf97a19cc83a9).;
96 SDL_Quit();
97 exit(0);
98 }
99 SDL_FreeSurface(temp);
100
101
102 temp = Load_Imagecxx . . $ Load_Image(ad2755de9658a3fe).("images/mastupon.png");
103 if(temp != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!) mastuponcxx . . $ Esm#mastupon. = SDL_DisplayFormat(temp);
104 if ( mastuponcxx . . $ Esm#mastupon. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`! ) {
105 cerrcxx . . $ cerr.<<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7)."Function LoadWidgets()" <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). endlcxx . . $ std/endl(345bf97a19cc83a9).
106 <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). SDL_GetError() <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). endlcxx . . $ std/endl(345bf97a19cc83a9).;
107 SDL_Quit();
108 exit(0);
109 }
110 SDL_FreeSurface(temp);
111
112 temp = Load_Imagecxx . . $ Load_Image(ad2755de9658a3fe).("images/styllus.png");
113 if(temp != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!) stylluscxx . . $ Esm#styllus. = SDL_DisplayFormat(temp);
114 if ( stylluscxx . . $ Esm#styllus. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`! ) {
115 cerrcxx . . $ cerr.<<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7)."Function LoadWidgets()" <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). endlcxx . . $ std/endl(345bf97a19cc83a9).
116 <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). SDL_GetError() <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). endlcxx . . $ std/endl(345bf97a19cc83a9).;
117 SDL_Quit();
118 exit(0);
119 }
120 SDL_FreeSurface(temp);
121
122 }
123
124 void Esmcxx . . $ Esm#::DisplayWidgetscxx . . $ Esm#DisplayWidgets(49f6e7a06ebc5aa8).(){
125
126 // Center of ESM screen at (316,325)
127 // dest.x = 316;
128 // dest.y = 325;
129 // dest.h = styllus->h;
130 // dest.w = styllus->w;
131 // SDL_BlitSurface(styllus, NULL, screen, &dest);
132 // SDL_UpdateRects(screen, 1, &dest);
133
134 if(Mastcxx . . $ Esm#Mast.)
135 {
136 destcxx . . $ Esm#dest..x = 845;
137 destcxx . . $ Esm#dest..y = 187;
138 destcxx . . $ Esm#dest..h = mastuponcxx . . $ Esm#mastupon.->h;
139 destcxx . . $ Esm#dest..w = mastuponcxx . . $ Esm#mastupon.->w;
140 SDL_BlitSurfacecxx . . $ `<external>/3508485105195885937/SDL_video.h:262:9`!(mastuponcxx . . $ Esm#mastupon., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!, screencxx . . $ Esm#screen., &destcxx . . $ Esm#dest.);
141 SDL_UpdateRects(screencxx . . $ Esm#screen., 1, &destcxx . . $ Esm#dest.);
142
143 destcxx . . $ Esm#dest..x = 740;
144 destcxx . . $ Esm#dest..y = 187;
145 destcxx . . $ Esm#dest..h = mastdownoffcxx . . $ Esm#mastdownoff.->h;
146 destcxx . . $ Esm#dest..w = mastdownoffcxx . . $ Esm#mastdownoff.->w;
147 SDL_BlitSurfacecxx . . $ `<external>/3508485105195885937/SDL_video.h:262:9`!(mastdownoffcxx . . $ Esm#mastdownoff., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!, screencxx . . $ Esm#screen., &destcxx . . $ Esm#dest.);
148 SDL_UpdateRects(screencxx . . $ Esm#screen., 1, &destcxx . . $ Esm#dest.);
149 }
150 else
151 {
152 destcxx . . $ Esm#dest..x = 845;
153 destcxx . . $ Esm#dest..y = 187;
154 destcxx . . $ Esm#dest..h = mastupoffcxx . . $ Esm#mastupoff.->h;
155 destcxx . . $ Esm#dest..w = mastupoffcxx . . $ Esm#mastupoff.->w;
156 SDL_BlitSurfacecxx . . $ `<external>/3508485105195885937/SDL_video.h:262:9`!(mastupoffcxx . . $ Esm#mastupoff., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!, screencxx . . $ Esm#screen., &destcxx . . $ Esm#dest.);
157 SDL_UpdateRects(screencxx . . $ Esm#screen., 1, &destcxx . . $ Esm#dest.);
158
159 destcxx . . $ Esm#dest..x = 740;
160 destcxx . . $ Esm#dest..y = 187;
161 destcxx . . $ Esm#dest..h = mastdownoncxx . . $ Esm#mastdownon.->h;
162 destcxx . . $ Esm#dest..w = mastdownoncxx . . $ Esm#mastdownon.->w;
163 SDL_BlitSurfacecxx . . $ `<external>/3508485105195885937/SDL_video.h:262:9`!(mastdownoncxx . . $ Esm#mastdownon., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!, screencxx . . $ Esm#screen., &destcxx . . $ Esm#dest.);
164 SDL_UpdateRects(screencxx . . $ Esm#screen., 1, &destcxx . . $ Esm#dest.);
165 }
166
167 // Need this for the time compression??
168 // SDL_UpdateRect(screen,0, 0, 0, 0);
169
170 }
171
172 void Esmcxx . . $ Esm#::ClearScreencxx . . $ Esm#ClearScreen(49f6e7a06ebc5aa8).(){
173 // Clear the screen
174 SDL_Surface *temp;
175 temp = Load_Imagecxx . . $ Load_Image(ad2755de9658a3fe).("images/ClearEsm.png");
176 if(temp != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!) ClearEsmcxx . . $ Esm#ClearEsm. = SDL_DisplayFormat(temp);
177 if ( ClearEsmcxx . . $ Esm#ClearEsm. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`! ) {
178 cerrcxx . . $ cerr.<<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7)."Function LoadWidgets()" <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). endlcxx . . $ std/endl(345bf97a19cc83a9).
179 <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). SDL_GetError() <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). endlcxx . . $ std/endl(345bf97a19cc83a9).;
180 SDL_Quit();
181 exit(0);
182 }
183
184 SDL_FreeSurface(temp);
185
186 temp = Load_Imagecxx . . $ Load_Image(ad2755de9658a3fe).("images/ClearEsm2.png");
187 if(temp != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!) ClearEsm2cxx . . $ Esm#ClearEsm2. = SDL_DisplayFormat(temp);
188 if ( ClearEsm2cxx . . $ Esm#ClearEsm2. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`! ) {
189 cerrcxx . . $ cerr.<<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7)."Function LoadWidgets()" <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). endlcxx . . $ std/endl(345bf97a19cc83a9).
190 <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). SDL_GetError() <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). endlcxx . . $ std/endl(345bf97a19cc83a9).;
191 SDL_Quit();
192 exit(0);
193 }
194
195 SDL_FreeSurface(temp);
196
197 srccxx . . $ Esm#src..x = 0;
198 srccxx . . $ Esm#src..y = 0;
199 srccxx . . $ Esm#src..w = ClearEsmcxx . . $ Esm#ClearEsm.->w;
200 srccxx . . $ Esm#src..h = ClearEsmcxx . . $ Esm#ClearEsm.->h;
201
202 destcxx . . $ Esm#dest..x = 105; // Blit destination x&y to the upper left
203 destcxx . . $ Esm#dest..y = 169;
204 destcxx . . $ Esm#dest..w = ClearEsmcxx . . $ Esm#ClearEsm.->w; // Height and width equal to the
205 destcxx . . $ Esm#dest..h = ClearEsmcxx . . $ Esm#ClearEsm.->h; // source images....
206 SDL_BlitSurfacecxx . . $ `<external>/3508485105195885937/SDL_video.h:262:9`!(ClearEsmcxx . . $ Esm#ClearEsm., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!, screencxx . . $ Esm#screen., &destcxx . . $ Esm#dest.); // Do the actual Blit
207 SDL_UpdateRects(screencxx . . $ Esm#screen., 1, &destcxx . . $ Esm#dest.); //Show the screen...
208 SDL_FreeSurface(ClearEsmcxx . . $ Esm#ClearEsm.); //Free up the surface memory.
209
210 srccxx . . $ Esm#src..x = 0;
211 srccxx . . $ Esm#src..y = 0;
212 srccxx . . $ Esm#src..w = ClearEsm2cxx . . $ Esm#ClearEsm2.->w;
213 srccxx . . $ Esm#src..h = ClearEsm2cxx . . $ Esm#ClearEsm2.->h;
214
215 destcxx . . $ Esm#dest..x = 693; // Blit destination x&y to the upper left
216 destcxx . . $ Esm#dest..y = 308;
217 destcxx . . $ Esm#dest..w = ClearEsm2cxx . . $ Esm#ClearEsm2.->w; // Height and width equal to the
218 destcxx . . $ Esm#dest..h = ClearEsm2cxx . . $ Esm#ClearEsm2.->h; // source images....
219 SDL_BlitSurfacecxx . . $ `<external>/3508485105195885937/SDL_video.h:262:9`!(ClearEsm2cxx . . $ Esm#ClearEsm2., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!, screencxx . . $ Esm#screen., &destcxx . . $ Esm#dest.); // Do the actual Blit
220 SDL_UpdateRects(screencxx . . $ Esm#screen., 1, &destcxx . . $ Esm#dest.); //Show the screen...
221 SDL_FreeSurface(ClearEsm2cxx . . $ Esm#ClearEsm2.); //Free up the surface memory.
222
223 }
224
225 void Esmcxx . . $ Esm#::LowerMastcxx . . $ Esm#LowerMast(49f6e7a06ebc5aa8).()
226 {
227 Mastcxx . . $ Esm#Mast. = false;
228 }
229
230 void Esmcxx . . $ Esm#::RaiseMastcxx . . $ Esm#RaiseMast(49f6e7a06ebc5aa8).()
231 {
232 Mastcxx . . $ Esm#Mast. = true;
233 }
234
235 void Esmcxx . . $ Esm#::ToggleMastcxx . . $ Esm#ToggleMast(49f6e7a06ebc5aa8).()
236 {
237 Mastcxx . . $ Esm#Mast. = !Mastcxx . . $ Esm#Mast.;
238 }
239
240 bool Esmcxx . . $ Esm#::getMastStatuscxx . . $ Esm#getMastStatus(50ce9a9e25b4a850).()const
241 {
242 return Mastcxx . . $ Esm#Mast.;
243 }
244
245 int Esmcxx . . $ Esm#::getAntennaHeightcxx . . $ Esm#getAntennaHeight(adc74905ab378dc7).(int Depth,int SeaState) const
246 {
247 // Effective Height of esm mast above water.
248 switch (SeaState)
249 {
250 case 0: // case 0 and case 1 are same
251 case 1: return(MastHeightcxx . . $ Esm#MastHeight. - Depth);
252 case 2: return(MastHeightcxx . . $ Esm#MastHeight. - Depth - 1);
253 case 3: return(MastHeightcxx . . $ Esm#MastHeight. - Depth - 3);
254 case 4: return(MastHeightcxx . . $ Esm#MastHeight. - Depth - 5);
255 case 5: return(MastHeightcxx . . $ Esm#MastHeight. - Depth - 8);
256 default: return(MastHeightcxx . . $ Esm#MastHeight. - Depth - 67);
257 }
258 }
259 bool Esmcxx . . $ Esm#::isTargetVisiblecxx . . $ Esm#isTargetVisible(196be57137963973).(Submarinecxx . . $ Submarine# *target, int TargetRange, int ObserverDepth,
260 int TargetHeight, bool TargetRadar, int SeaState)
261 {
262 // Determines if observer's esm can detect target radar.
263 // Returns a 1 if true or a 0 if false.
264
265 // TargetRange is the true range to the target.
266
267 // TargetHeight is the height of the tallest mast on a surface ship
268 // (usually 50 ft - 175 ft), height of conning tower for a submarine
269 // (usually 40-50 ft), or altitude for airplane.
270
271 /* To see Target, Range < EsmHorizon, Targets radar must be on.
272
273 Esm horizon is the earliest posssible target detection due to
274 the Earth-Curvature. Esm horizon = 3600(sqrt(ha)+ sqrt(ht))
275 ha = antenna height(ft), ht = target height(ft), EsmHorizon(yds)
276
277 Note: ESM horizon > Radar Horizon since can detect targets radar
278 long before he can detect esm mast.
279 */
280
281 bool boolean = false;
282 // we cannot detect subs on esm
283 if (target->Depthcxx . . $ Submarine#Depth. > 0.0)
284 return false;
285
286 CurrentAntennaHeightcxx . . $ Esm#CurrentAntennaHeight. = getAntennaHeightcxx . . $ Esm#getAntennaHeight(adc74905ab378dc7).(ObserverDepth,SeaState);
287 if(CurrentAntennaHeightcxx . . $ Esm#CurrentAntennaHeight. <= 0) return boolean; // Mast is below water!
288
289 if(TargetRadar == 1 && getMastStatuscxx . . $ Esm#getMastStatus(50ce9a9e25b4a850).() == 1
290 && TargetRange <= getEsmHorizoncxx . . $ Esm#getEsmHorizon(2326284602b0bb2d).(ObserverDepth, TargetHeight, SeaState))
291 boolean = true;
292 return boolean;
293 }
294 int Esmcxx . . $ Esm#::getBearingcxx . . $ Esm#getBearing(d4c1ccc1fe1a56c0).(int TargetBearing, int ObserverDepth,
295 int TargetHeight, int SeaState)
296 {
297 // Returns the bearing to the target based on accuracy of
298 // esm mast.
299
300 // The greater the EsmHorizon, the greater the error.
301
302 EsmHorizoncxx . . $ Esm#EsmHorizon. = getEsmHorizoncxx . . $ Esm#getEsmHorizon(2326284602b0bb2d).(ObserverDepth, TargetHeight, SeaState);
303
304 if (EsmHorizoncxx . . $ Esm#EsmHorizon. > 30000)
305 bearingcxx . . $ Esm#bearing. = TargetBearing - 5 + rand()%10;
306 else if (EsmHorizoncxx . . $ Esm#EsmHorizon. > 20000 && EsmHorizoncxx . . $ Esm#EsmHorizon. < 30000)
307 bearingcxx . . $ Esm#bearing. = TargetBearing - 3 + rand()%6;
308 else if (EsmHorizoncxx . . $ Esm#EsmHorizon. > 15000 && EsmHorizoncxx . . $ Esm#EsmHorizon. < 20000)
309 bearingcxx . . $ Esm#bearing. = TargetBearing - 2 + rand()%4;
310 else
311 bearingcxx . . $ Esm#bearing. = TargetBearing - 1 + rand()%2;
312
313 return bearingcxx . . $ Esm#bearing.;
314 }
315 int Esmcxx . . $ Esm#::getSignalStrengthcxx . . $ Esm#getSignalStrength(6d2a54b2a492188d).(Submarinecxx . . $ Submarine# *Target, int TargetRange, int ObserverDepth,
316 int TargetHeight, bool TargetRadar,int SeaState)
317 {
318 // Returns the signal strength of the target radar.
319 // The signal strength is determined by the Detection Probability.
320
321 // The detection probability is a function of Target Range, Antenna
322 // Height, and TargetHeight
323
324
325 if(isTargetVisiblecxx . . $ Esm#isTargetVisible(196be57137963973).(Target, TargetRange, ObserverDepth, TargetHeight,
326 TargetRadar, SeaState) == 0)
327 {
328 SignalStrengthcxx . . $ Esm#SignalStrength. = 0;
329 return SignalStrengthcxx . . $ Esm#SignalStrength.;
330 }
331 else
332 {
333 DetectProbcxx . . $ Esm#DetectProb. = TargetRange - 600*getAntennaHeightcxx . . $ Esm#getAntennaHeight(adc74905ab378dc7).(ObserverDepth,SeaState)
334 - 20*TargetHeight;
335 if (DetectProbcxx . . $ Esm#DetectProb. > 35000)
336 SignalStrengthcxx . . $ Esm#SignalStrength. = 1;
337 else if (DetectProbcxx . . $ Esm#DetectProb. > 25000 && DetectProbcxx . . $ Esm#DetectProb. < 35000)
338 SignalStrengthcxx . . $ Esm#SignalStrength. = 2;
339 else if (DetectProbcxx . . $ Esm#DetectProb. > 18000 && DetectProbcxx . . $ Esm#DetectProb. < 25000)
340 SignalStrengthcxx . . $ Esm#SignalStrength. = 3;
341 else if (DetectProbcxx . . $ Esm#DetectProb. > 14000 && DetectProbcxx . . $ Esm#DetectProb. < 18000)
342 SignalStrengthcxx . . $ Esm#SignalStrength. = 4;
343 else
344 SignalStrengthcxx . . $ Esm#SignalStrength. = 5;
345 }
346 return SignalStrengthcxx . . $ Esm#SignalStrength.;
347 }
348
349 int Esmcxx . . $ Esm#::getEsmHorizoncxx . . $ Esm#getEsmHorizon(2326284602b0bb2d).(int ObserverDepth, int TargetHeight, int SeaState)
350 {
351 CurrentAntennaHeightcxx . . $ Esm#CurrentAntennaHeight. = getAntennaHeightcxx . . $ Esm#getAntennaHeight(adc74905ab378dc7).(ObserverDepth,SeaState);
352 if(CurrentAntennaHeightcxx . . $ Esm#CurrentAntennaHeight. <= 0) return 0; // Mast is below water!
353
354 EsmHorizoncxx . . $ Esm#EsmHorizon. = 3600*(int)(sqrt(float(CurrentAntennaHeightcxx . . $ Esm#CurrentAntennaHeight.)) +
355 sqrt(float(TargetHeight)));
356
357 return EsmHorizoncxx . . $ Esm#EsmHorizon.;
358 }
359
360 void Esmcxx . . $ Esm#::DisplayContactscxx . . $ Esm#DisplayContacts(49f6e7a06ebc5aa8).(){
361 static char text[120];
362 char file1[] = "images/font.png";
363 char file2[] = "images/font.dat";
364 DFontcxx . . $ DFont# fntcxx . . $ DFont#DFont(d0489a02ea06dfc6).(file1, file2);
365 // static DFont largeFont(filename.c_str(), filename2.c_str());
366 float radians;
367 float radians_old;
368 int bearing, range, depth;
369 Submarinecxx . . $ Submarine# *target;
370 int count;
371
372 // Note: Center of radar screen at (x,y) = (323,330)
373 // set dx = 144 dy = 144
374
375 srccxx . . $ Esm#src..x=695;
376 srccxx . . $ Esm#src..y=417; //define a rectangle on the screen and make it black
377 srccxx . . $ Esm#src..h=50;
378 srccxx . . $ Esm#src..w=174;
379
380 /*
381 if (!EsmStack.empty()) // Is there is data on the stack?
382 {
383 // TODO: FIX THIS
384 for(count=1; count<8;count++)
385 {
386 radians_old[count] = EsmStack.pop();
387
388 // Clear Old Data from Heading Compass
389 x = int(326.0 + (460.0 - 326.0)*cos(1.57-radians_old[count]));
390 y = int(383.0 - (460.0 - 326.0)*sin(1.57-radians_old[count]));
391 DLine(screen, 326, 383, x, y, black);
392 }
393 }
394 */
395 while (! EsmStackcxx . . $ EsmStack..emptycxx . . $ DStack#empty(b126dc7c1de90089).() )
396 {
397 radians_old = EsmStackcxx . . $ EsmStack..popcxx . . $ DStack#pop(9b8c9e39889c762c).();
398 xcxx . . $ Esm#x. = int(326.0 + (460.0 - 326.0)*cos(1.57-radians_old));
399 ycxx . . $ Esm#y. = int(383.0 - (460.0 - 326.0)*sin(1.57-radians_old));
400 DLinecxx . . $ Esm#DLine(1738f3ac1892ed0c).(screencxx . . $ Esm#screen., 326, 383, xcxx . . $ Esm#x., ycxx . . $ Esm#y., blackcxx . . $ Esm#black.);
401 }
402
403 target = Subscxx . . $ Esm#Subs.->nextcxx . . $ Submarine#next.;
404 count = 0;
405 while (target)
406 {
407 bearing = (int)Subscxx . . $ Esm#Subs.->BearingToTargetcxx . . $ Submarine#BearingToTarget(2de0d0e522051339).(target);
408 range = (int)Subscxx . . $ Esm#Subs.->DistanceToTargetcxx . . $ Submarine#DistanceToTarget(2de0d0e522051339).(target);
409 depth = (int)Subscxx . . $ Esm#Subs.->Depthcxx . . $ Submarine#Depth.;
410
411 // bearing = getBearing((int)Subs[0].BearingToTarget(Subs[target]), depth, 100, 3);
412
413 radians = float(bearing) *(3.14/180.0); // degrees to radians
414
415 if(isTargetVisiblecxx . . $ Esm#isTargetVisible(196be57137963973).(target, range, depth,100, true, 3))
416 {
417 count++;
418 // Plot a line at the correct bearing
419 xcxx . . $ Esm#x. = int(326.0 + (460.0 - 326.0)*cos(1.57-radians));
420 ycxx . . $ Esm#y. = int(383.0 - (460.0 - 326.0)*sin(1.57-radians));
421 DLinecxx . . $ Esm#DLine(1738f3ac1892ed0c).(screencxx . . $ Esm#screen., 326, 383, xcxx . . $ Esm#x., ycxx . . $ Esm#y., orangecxx . . $ Esm#orange.);
422
423 sprintf(text, "BEARING %i SS %i", bearing,
424 getSignalStrengthcxx . . $ Esm#getSignalStrength(6d2a54b2a492188d).(target, range,60,100,true,3));
425 fnt.PutStringcxx . . $ DFont#PutString(dae77c54ebf0dad5).(screencxx . . $ Esm#screen., 698, 300 + 11*count, text);
426 // Push the data on the stack
427 EsmStackcxx . . $ EsmStack..pushcxx . . $ DStack#push(1bb0578f3efdc255).(radians);
428
429 }
430
431 target = target->nextcxx . . $ Submarine#next.;
432 }
433 SDL_UpdateRect(screencxx . . $ Esm#screen.,0, 0, 0, 0);
434 }
435
436 void Esmcxx . . $ Esm#::DLinecxx . . $ Esm#DLine(1738f3ac1892ed0c).(SDL_Surface *screen, int X1, int Y1, int X2, int Y2, Uint32cxx . . $ Uint32# Color)
437 {
438
439 int dx,dy,sdx,sdy,py,px,x,y;
440 dx = X2 - X1;
441 dy = Y2 - Y1;
442 if (dx < 0) sdx = -1;
443 else sdx = 1;
444 if (dy < 0) sdy = -1;
445 else sdy = 1;
446 dx = sdx * dx + 1;
447 dy = sdy * dy + 1;
448 x = 0;
449 y = 0;
450 px = X1;
451 py = Y1;
452 if (dx >= dy){
453 for (int x = 0; x < dx; x++){
454 DPixelcxx . . $ Esm#DPixel(6f3c846de5417090).(screen, px, py, Color);
455 y = y + dy;
456 if (y >= dx){
457 y = y - dx;
458 py = py + sdy;
459 }
460 px = px + sdx;
461 }
462 }else{
463 for (int y = 0; y < dy; y++){
464 DPixelcxx . . $ Esm#DPixel(6f3c846de5417090).(screen, px, py, Color);
465 x = x + dx;
466 if (x >= dy){
467 x = x - dy;
468 px = px + sdx;
469 }
470 py = py + sdy;
471 }
472 }
473 }
474
475 void Esmcxx . . $ Esm#::DPixelcxx . . $ Esm#DPixel(6f3c846de5417090).(SDL_Surface *screen, int x, int y, Uint32cxx . . $ Uint32# color)
476 {
477 //this only works for 16bpp screens
478 //are we outside the screen?????
479 //If we are bail out now before it's too late!
480
481 //cerr << ".";
482 if (x > 1023 || x < 0 || y > 759 || y < 0) {
483 return;
484 }
485
486 //place the pixel on the screen
487 Uint16cxx . . $ Uint16# *pixel_location;
488 pixel_location = (Uint16cxx . . $ Uint16# *)screen->pixels + y*screen->pitch/2 + x;
489 *pixel_location = color;
490 }