| 1 | /*************************************************************************** |
| 2 | sonar.cpp - description |
| 3 | ------------------- |
| 4 | begin : Fri Apr 11 2002 |
| 5 | copyright : (C) 2002 by Michael Bridak |
| 6 | email : [email protected] |
| 7 | $Id: sonar.cpp,v 1.14 2003/09/21 21:52:40 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 | |
| 19 | |
| 20 | |
| 21 | #include <string> |
| 22 | #include "math.h" |
| 23 | #include "SDL/SDL.h" |
| 24 | #include "SDL/SDL_image.h" |
| 25 | #include "SDL/SDL_thread.h" |
| 26 | #include "dfont.h" |
| 27 | #include "files.h" |
| 28 | #include "message.h" |
| 29 | #include "submarine.h" |
| 30 | #include "towedarray.h" |
| 31 | #include "targetmotionanalysis.h" |
| 32 | #include "sonar.h" |
| 33 | |
| 34 | using namespace std; |
| 35 | |
| 36 | AnBqq5::AnBqq5(Submarine *temp, TowedArray &temp2, TargetMotionAnalysis &temp3, |
| 37 | msg &temp4): Subs(temp), TB16(temp2), Tma(temp3), Message(temp4) |
| 38 | { |
| 39 | northcenter = true; |
| 40 | arraychoice5by6 = true; |
| 41 | bearingdisplay5by6 = true; |
| 42 | sonarwidget = false; |
| 43 | cursorBearing = 0; |
| 44 | } |
| 45 | |
| 46 | AnBqq5::~AnBqq5(){} |
| 47 | |
| 48 | void AnBqq5::InitGraphics() |
| 49 | { |
| 50 | screen = SDL_GetVideoSurface(); |
| 51 | SDL_Surface *temp = SDL_CreateRGBSurface(SDL_SWSURFACE, 368, 280, 16, |
| 52 | screen->format->Rmask, |
| 53 | screen->format->Gmask, |
| 54 | screen->format->Bmask, |
| 55 | screen->format->Amask); |
| 56 | sonarscreen=SDL_DisplayFormat(temp); |
| 57 | towedarrayscreen=SDL_DisplayFormat(temp); |
| 58 | SDL_FreeSurface(temp); |
| 59 | uppersonarcrt=sonarscreen; |
| 60 | lowersonarcrt=towedarrayscreen; |
| 61 | if ( screen == NULL || sonarscreen == NULL || towedarrayscreen == NULL) { |
| 62 | cerr << "OOPS" << SDL_GetError() << endl; |
| 63 | exit(1); |
| 64 | } |
| 65 | string filename; |
| 66 | string filename2; |
| 67 | black = SDL_MapRGB(screen->format, 0, 0, 0); |
| 68 | white = SDL_MapRGB(screen->format, 255, 255, 255); |
| 69 | green = SDL_MapRGB(screen->format, 0,255,0); |
| 70 | // medium_green = SDL_MapRGB(screen->format, 0, 160, 0); |
| 71 | // dark_green = SDL_MapRGB(screen->format, 0, 100, 0); |
| 72 | } |
| 73 | |
| 74 | void AnBqq5::ClearSonarData(){ //when the display is switched from north centered |
| 75 | //to south centered, we must erase the old display data |
| 76 | SDL_Rect rectangle; |
| 77 | rectangle.x=0; |
| 78 | rectangle.y=0; |
| 79 | rectangle.h=200; |
| 80 | rectangle.w=368; |
| 81 | SDL_FillRect(sonarscreen, &rectangle, black); |
| 82 | SDL_FillRect(towedarrayscreen, &rectangle, black); |
| 83 | } |
| 84 | |
| 85 | inline void AnBqq5::DPixel(SDL_Surface *screen, int x, int y, Uint32 color) |
| 86 | { |
| 87 | //this only works for 16bpp screens |
| 88 | //place the pixel on the screen |
| 89 | Uint16 *pixel_location; |
| 90 | pixel_location = (Uint16 *)screen->pixels + y*screen->pitch/2 + x; |
| 91 | *pixel_location = color; |
| 92 | } |
| 93 | |
| 94 | |
| 95 | inline void AnBqq5::DLine(SDL_Surface *screen, int X1, int Y1, int X2, int Y2, Uint32 Color) |
| 96 | { |
| 97 | |
| 98 | //don't even ask me about this stuff All I know is it works |
| 99 | //and thats ALL I care about... |
| 100 | |
| 101 | int dx,dy,sdx,sdy,py,px,x,y; |
| 102 | dx = X2 - X1; |
| 103 | dy = Y2 - Y1; |
| 104 | if (dx < 0) sdx = -1; |
| 105 | else sdx = 1; |
| 106 | if (dy < 0) sdy = -1; |
| 107 | else sdy = 1; |
| 108 | dx = sdx * dx + 1; |
| 109 | dy = sdy * dy + 1; |
| 110 | x = 0; |
| 111 | y = 0; |
| 112 | px = X1; |
| 113 | py = Y1; |
| 114 | if (dx >= dy){ |
| 115 | for (int x = 0; x < dx; x++){ |
| 116 | DPixel(screen, px, py, Color); |
| 117 | y = y + dy; |
| 118 | if (y >= dx){ |
| 119 | y = y - dx; |
| 120 | py = py + sdy; |
| 121 | } |
| 122 | px = px + sdx; |
| 123 | } |
| 124 | }else{ |
| 125 | for (int y = 0; y < dy; y++){ |
| 126 | DPixel(screen, px, py, Color); |
| 127 | x = x + dx; |
| 128 | if (x >= dy){ |
| 129 | x = x - dy; |
| 130 | px = px + sdx; |
| 131 | } |
| 132 | py = py + sdy; |
| 133 | } |
| 134 | } |
| 135 | } |
| 136 | |
| 137 | void AnBqq5::Sonar(bool center) |
| 138 | |
| 139 | /******************************************** |
| 140 | This routine checks the sonar event queue |
| 141 | and if there is an event, plots the sound |
| 142 | source on the waterfall display. It's called |
| 143 | every 1/5 of a second. and in turn calls |
| 144 | AdvanceSonarScreen() every second. |
| 145 | *********************************************/ |
| 146 | |
| 147 | { |
| 148 | Uint32 tracecolor; //We have to put the color somewhere |
| 149 | int direction; |
| 150 | float signal; |
| 151 | int ship_type; |
| 152 | double combined_sound; |
| 153 | |
| 154 | if (Subs->GetCount()>0){ |
| 155 | //Are there any sound events at this time index to worry about? |
| 156 | for (int event=1; event<=Subs->GetCount(); event++){ |
| 157 | //If so step through the events. |
| 158 | Subs->GetEvent(event, &direction, &signal, &ship_type); |
| 159 | //TargetId not used now but maybe later in TMA |
| 160 | |
| 161 | //visable mono color from 70 - 255 |
| 162 | combined_sound = (signal * 4) + flowandambientnoise; |
| 163 | if (combined_sound > 255.0) |
| 164 | combined_sound = 255.0; |
| 165 | switch(ship_type) |
| 166 | { |
| 167 | case TYPE_SHIP: |
| 168 | tracecolor=SDL_MapRGB(sonarscreen->format, 0,(int) combined_sound, 0); break; |
| 169 | case TYPE_TORPEDO: |
| 170 | tracecolor=SDL_MapRGB(sonarscreen->format,(int) combined_sound, 0, 0); break; |
| 171 | case TYPE_SUB: |
| 172 | default: |
| 173 | tracecolor=SDL_MapRGB(sonarscreen->format, 0, 0, (int) combined_sound); break; |
| 174 | } |
| 175 | //Change brightness based on strength of signal |
| 176 | int tdirection = direction; |
| 177 | for(int xx = 1;xx < 6; xx++){ |
| 178 | direction = (-3+RandInt(6))+tdirection; |
| 179 | //throw some variances in the bearing nothing is perfekt!... |
| 180 | if (direction < 0) direction += 360; //Christ I hate roll overs in degrees |
| 181 | if (direction > 359) direction -= 360; |
| 182 | |
| 183 | if (!center){ //Do we want the sonar display to be North centered ? |
| 184 | DPixel(sonarscreen, direction, 0, tracecolor); //plots on 0-60 sec display |
| 185 | DPixel(sonarscreen, direction, 70, tracecolor); //plots on 0-30 min display |
| 186 | DPixel(sonarscreen, direction, 140, tracecolor); //plots on 0-2 hr display |
| 187 | } |
| 188 | else { //draw traces for south centered display |
| 189 | DPixel(sonarscreen, ReciprocalBearing(direction), |
| 190 | 0, tracecolor); //plots on 0-60 sec display |
| 191 | DPixel(sonarscreen, ReciprocalBearing(direction), |
| 192 | 70, tracecolor); //plots on 0-30 min display |
| 193 | DPixel(sonarscreen, ReciprocalBearing(direction), |
| 194 | 140, tracecolor); //plots on 0-2 hr display |
| 195 | } |
| 196 | } |
| 197 | } |
| 198 | } |
| 199 | if (!center){ |
| 200 | DPixel(sonarscreen, (int)Subs->Heading, 0, white); //plot our heading |
| 201 | }else{ |
| 202 | DPixel(sonarscreen, ReciprocalBearing((int)Subs->Heading), |
| 203 | 0, white); //plots our heading |
| 204 | } |
| 205 | AdvanceSonarDisplay(); //advance the screen. |
| 206 | UpdateCursor(); |
| 207 | } |
| 208 | |
| 209 | |
| 210 | |
| 211 | void AnBqq5::DisplaySonar(){ |
| 212 | SDL_Rect destination_rectangle; |
| 213 | SDL_Rect source_rectangle; |
| 214 | DisplayBearingScale(northcenter); |
| 215 | DisplayCursor(); |
| 216 | |
| 217 | if(uppersonarcrt != NULL){ |
| 218 | source_rectangle.x = 0; |
| 219 | source_rectangle.y = 0; |
| 220 | source_rectangle.w = 360; |
| 221 | source_rectangle.h = 200; |
| 222 | destination_rectangle.x = 52; |
| 223 | destination_rectangle.y = 150; |
| 224 | destination_rectangle.w = 360; |
| 225 | destination_rectangle.h = 200; |
| 226 | SDL_BlitSurface(uppersonarcrt, &source_rectangle, screen, &destination_rectangle); |
| 227 | SDL_UpdateRects(screen, 1, &destination_rectangle); |
| 228 | } |
| 229 | |
| 230 | |
| 231 | if(lowersonarcrt != NULL){ |
| 232 | source_rectangle.x = 0; |
| 233 | source_rectangle.y = 0; |
| 234 | source_rectangle.w = 360; |
| 235 | source_rectangle.h = 200; |
| 236 | destination_rectangle.x = 52; |
| 237 | destination_rectangle.y = 450; |
| 238 | destination_rectangle.w = 360; |
| 239 | destination_rectangle.h = 200; |
| 240 | SDL_BlitSurface(lowersonarcrt, &source_rectangle, screen, &destination_rectangle); |
| 241 | SDL_UpdateRects(screen, 1, &destination_rectangle); |
| 242 | } |
| 243 | |
| 244 | } |
| 245 | |
| 246 | void AnBqq5::UpdateDisplay(Submarine *current_target){ |
| 247 | SDL_Rect destination_rectangle; |
| 248 | static char text[120]; |
| 249 | char filename[] = "images/largefont.png"; |
| 250 | char filename2[] = "data/largefont.dat"; |
| 251 | static DFont largeFont(filename, filename2); |
| 252 | DisplaySonar(); //draw sonar screen |
| 253 | destination_rectangle.x=830; |
| 254 | destination_rectangle.y=410; //define a rectangle on the screen and make it black |
| 255 | destination_rectangle.h=30; |
| 256 | destination_rectangle.w=90; |
| 257 | SDL_FillRect(screen, &destination_rectangle, black); |
| 258 | SDL_UpdateRects(screen, 1, &destination_rectangle); |
| 259 | destination_rectangle.y=498; //define a rectangle on the screen and make it black |
| 260 | SDL_FillRect(screen, &destination_rectangle, black); |
| 261 | SDL_UpdateRects(screen, 1, &destination_rectangle); |
| 262 | if (current_target) |
| 263 | { |
| 264 | tempint = (int)Subs->BearingToTarget( current_target ); |
| 265 | sprintf(text, "%4i", tempint); |
| 266 | largeFont.PutString(screen, 840, 412, text); |
| 267 | Subs->DEAngle( current_target ); |
| 268 | if (deAngle > 0){ |
| 269 | sprintf(text,"+%3.1f",deAngle); |
| 270 | }else{ |
| 271 | sprintf(text,"%3.1f",deAngle); |
| 272 | } |
| 273 | largeFont.PutString(screen, 840, 498, text); |
| 274 | } |
| 275 | } |
| 276 | |
| 277 | void AnBqq5::TowedSonar(bool center) |
| 278 | |
| 279 | /******************************************** |
| 280 | This routine checks the sonar event queue |
| 281 | and if there is an event, plots the sound |
| 282 | source on the waterfall display. It's called |
| 283 | every 1/5 of a second. and in turn calls |
| 284 | AdvanceSonarScreen() every second. |
| 285 | *********************************************/ |
| 286 | |
| 287 | { |
| 288 | Uint32 tracecolor; //We have to put the color somewhere |
| 289 | int direction, ambiguous_direction, bearing, ambiguous_relative_bearing; |
| 290 | int ship_type; |
| 291 | float signal; |
| 292 | double combined_sound; |
| 293 | int TB16_Count = TB16.GetCount(); |
| 294 | if (TB16_Count > 0){ |
| 295 | //Are there any sound events at this time index to worry about? |
| 296 | for (int event=1; event<=TB16_Count; event++){ |
| 297 | //If so step through the events. |
| 298 | TB16.GetEvent(event, &bearing, &signal, &ship_type); |
| 299 | ambiguous_relative_bearing = (int)TB16.BearingAmbiguity((float)bearing); |
| 300 | //TargetId not used now but maybe later in TMA |
| 301 | //visable mono color from 70 - 255 |
| 302 | combined_sound = (signal * 4) + flowandambientnoise; |
| 303 | if (combined_sound > 255.0) |
| 304 | combined_sound = 255.0; |
| 305 | switch(ship_type) |
| 306 | { |
| 307 | case TYPE_SHIP: |
| 308 | tracecolor=SDL_MapRGB(sonarscreen->format, 0,(int) combined_sound, 0); break; |
| 309 | case TYPE_TORPEDO: |
| 310 | tracecolor=SDL_MapRGB(sonarscreen->format,(int) combined_sound, 0, 0); break; |
| 311 | case TYPE_SUB: |
| 312 | default: |
| 313 | tracecolor=SDL_MapRGB(sonarscreen->format, 0, 0, (int) combined_sound); break; |
| 314 | } |
| 315 | |
| 316 | //Change brightness based on strength of signal |
| 317 | for(int xx = 1;xx < 6; xx++){ |
| 318 | direction = bearing; |
| 319 | //if (direction >= 360) direction -= 360; |
| 320 | direction = (-3+RandInt(6))+direction; |
| 321 | //throw some variances in the bearing nothing is perfekt!... |
| 322 | if (direction < 0) direction += 360; |
| 323 | if (direction > 359) direction -= 360; |
| 324 | ambiguous_direction = ambiguous_relative_bearing; |
| 325 | //if (ambiguous_direction >= 360) ambiguous_direction -= 360; |
| 326 | ambiguous_direction = (-3+RandInt(6))+ambiguous_direction; |
| 327 | if (ambiguous_direction < 0) ambiguous_direction += 360; |
| 328 | if (ambiguous_direction > 359) ambiguous_direction -= 360; |
| 329 | if (!center){ //Do we want the sonar display to be North centered ? |
| 330 | DPixel(towedarrayscreen, direction, 0, tracecolor); //plots on 0-60 sec display |
| 331 | DPixel(towedarrayscreen, direction, 70, tracecolor); //plots on 0-30 min display |
| 332 | DPixel(towedarrayscreen, direction, 140, tracecolor); //plots on 0-2 hr display |
| 333 | DPixel(towedarrayscreen, ambiguous_direction, 0, tracecolor); //Do the same for the |
| 334 | DPixel(towedarrayscreen, ambiguous_direction, 70, tracecolor); //ambiguous bearing |
| 335 | DPixel(towedarrayscreen, ambiguous_direction, 140, tracecolor); //returned from towed array |
| 336 | }else { //draw traces for south centered display |
| 337 | DPixel(towedarrayscreen, ReciprocalBearing(direction), |
| 338 | 0, tracecolor); //plots on 0-60 sec display |
| 339 | DPixel(towedarrayscreen, ReciprocalBearing(direction), |
| 340 | 70, tracecolor); //plots on 0-30 min display |
| 341 | DPixel(towedarrayscreen, ReciprocalBearing(direction), |
| 342 | 140, tracecolor); //plots on 0-2 hr display |
| 343 | |
| 344 | DPixel(towedarrayscreen, ReciprocalBearing(ambiguous_direction), |
| 345 | 0, tracecolor); //plots on 0-60 sec display |
| 346 | DPixel(towedarrayscreen, ReciprocalBearing(ambiguous_direction), |
| 347 | 70, tracecolor); //plots on 0-30 min display |
| 348 | DPixel(towedarrayscreen, ReciprocalBearing(ambiguous_direction), |
| 349 | 140, tracecolor); //plots on 0-2 hr display |
| 350 | } |
| 351 | } |
| 352 | } |
| 353 | } |
| 354 | if (!center){ |
| 355 | DPixel(towedarrayscreen, (int)Subs->Heading, 0, white); //plot our heading |
| 356 | }else{ |
| 357 | DPixel(towedarrayscreen, ReciprocalBearing((int)Subs->Heading), |
| 358 | 0, white); //plots our heading |
| 359 | } |
| 360 | AdvanceTB16Screen(); //advance the screen. |
| 361 | } |
| 362 | |
| 363 | void AnBqq5::AdvanceSonarDisplay(){ |
| 364 | SDL_Rect destination_rectangle; |
| 365 | SDL_Rect source_rectangle; |
| 366 | static int count = 0; |
| 367 | static int count2 = 0; |
| 368 | int my_noise; |
| 369 | Uint32 noisecolor; |
| 370 | // move the minute display down |
| 371 | source_rectangle.x = 0; //sonar screen minus last line |
| 372 | source_rectangle.y = 0; |
| 373 | source_rectangle.w = 360; |
| 374 | source_rectangle.h = 59; |
| 375 | destination_rectangle.x = 0; |
| 376 | destination_rectangle.y = 1; |
| 377 | destination_rectangle.w = 360; |
| 378 | destination_rectangle.h = 59; |
| 379 | //cut sonarscreen and paste it back one line lower |
| 380 | SDL_BlitSurface(sonarscreen, &source_rectangle, sonarscreen, &destination_rectangle); |
| 381 | //Fill first line with background noise |
| 382 | for(int nbp = 0; nbp<360; nbp++){ |
| 383 | bool sensordeaf = false; |
| 384 | int array_heading; |
| 385 | if(northcenter){ |
| 386 | array_heading = (int)Subs->Heading; |
| 387 | }else{ |
| 388 | array_heading = ReciprocalBearing((int)Subs->Heading); |
| 389 | } |
| 390 | int recipbearing; |
| 391 | if (array_heading >= 180){ |
| 392 | recipbearing = array_heading - 180; |
| 393 | }else{ |
| 394 | recipbearing = array_heading + 180; |
| 395 | } |
| 396 | int bearing_to_target = nbp; |
| 397 | if(recipbearing > bearing_to_target) bearing_to_target += 360; |
| 398 | int relative_bearing = bearing_to_target - recipbearing; |
| 399 | if(relative_bearing > 150 && relative_bearing < 210) sensordeaf = true; |
| 400 | if (!sensordeaf){ |
| 401 | // noisecolor=SDL_MapRGB(sonarscreen->format, 0,(int) fabs((flowandambientnoise - RandInt(40))) , 0); |
| 402 | my_noise = (int) fabs( (flowandambientnoise - RandInt(40) ) ) / 2; |
| 403 | noisecolor=SDL_MapRGB(sonarscreen->format, my_noise, my_noise, my_noise); |
| 404 | DPixel(sonarscreen, nbp, 0, noisecolor); |
| 405 | } |
| 406 | else{ |
| 407 | DPixel(sonarscreen, nbp, 0, black); |
| 408 | } |
| 409 | } |
| 410 | |
| 411 | // move the 0-30 min display down |
| 412 | ++count; |
| 413 | if(count>29){ |
| 414 | count = 0; |
| 415 | source_rectangle.x = 0; //sonar screen minus last line |
| 416 | source_rectangle.y = 70; |
| 417 | source_rectangle.w = 360; |
| 418 | source_rectangle.h = 59; |
| 419 | destination_rectangle.x = 0; |
| 420 | destination_rectangle.y = 71; |
| 421 | destination_rectangle.w = 360; |
| 422 | destination_rectangle.h = 59; |
| 423 | //cut sonarscreen and paste it to buffer |
| 424 | SDL_BlitSurface(sonarscreen, &source_rectangle, sonarscreen, &destination_rectangle); |
| 425 | for(int nbp = 0; nbp<360; nbp++){ |
| 426 | bool sensordeaf = false; |
| 427 | int array_heading; |
| 428 | if(northcenter){ |
| 429 | array_heading = (int)Subs->Heading; |
| 430 | }else{ |
| 431 | array_heading = ReciprocalBearing((int)Subs->Heading); |
| 432 | } |
| 433 | int recipbearing; |
| 434 | if (array_heading >= 180){ |
| 435 | recipbearing = array_heading - 180; |
| 436 | }else{ |
| 437 | recipbearing = array_heading + 180; |
| 438 | } |
| 439 | int bearing_to_target = nbp; |
| 440 | if(recipbearing > bearing_to_target) bearing_to_target += 360; |
| 441 | int relative_bearing = bearing_to_target - recipbearing; |
| 442 | if(relative_bearing > 150 && relative_bearing < 210) sensordeaf = true; |
| 443 | if (!sensordeaf){ |
| 444 | // noisecolor=SDL_MapRGB(sonarscreen->format, 0,(int) fabs((flowandambientnoise - RandInt(40))) , 0); |
| 445 | my_noise = (int) fabs( (flowandambientnoise - RandInt(40) ) ) / 2; |
| 446 | noisecolor = SDL_MapRGB(sonarscreen->format, my_noise, my_noise, my_noise); |
| 447 | DPixel(sonarscreen, nbp, 70, noisecolor); |
| 448 | } |
| 449 | else{ |
| 450 | DPixel(sonarscreen, nbp, 70, black); |
| 451 | } |
| 452 | } |
| 453 | } |
| 454 | // move the 0-2 hour display down |
| 455 | ++count2; |
| 456 | if(count2 > 119){ |
| 457 | count2 = 0; |
| 458 | source_rectangle.x = 0; //sonar screen minus last line |
| 459 | source_rectangle.y = 140; |
| 460 | source_rectangle.w = 360; |
| 461 | source_rectangle.h = 59; |
| 462 | destination_rectangle.x = 0; |
| 463 | destination_rectangle.y = 141; |
| 464 | destination_rectangle.w = 360; |
| 465 | destination_rectangle.h = 59; |
| 466 | //cut sonarscreen and paste it to buffer |
| 467 | SDL_BlitSurface(sonarscreen, &source_rectangle, sonarscreen, &destination_rectangle); |
| 468 | for(int nbp = 0; nbp<360; nbp++){ |
| 469 | bool sensordeaf = false; |
| 470 | int array_heading; |
| 471 | if(northcenter){ |
| 472 | array_heading = (int)Subs->Heading; |
| 473 | }else{ |
| 474 | array_heading = ReciprocalBearing((int)Subs->Heading); |
| 475 | } |
| 476 | int recipbearing; |
| 477 | if (array_heading >= 180){ |
| 478 | recipbearing = array_heading - 180; |
| 479 | }else{ |
| 480 | recipbearing = array_heading + 180; |
| 481 | } |
| 482 | int bearing_to_target = nbp; |
| 483 | if(recipbearing > bearing_to_target) bearing_to_target += 360; |
| 484 | int relative_bearing = bearing_to_target - recipbearing; |
| 485 | if(relative_bearing > 150 && relative_bearing < 210) sensordeaf = true; |
| 486 | if (!sensordeaf){ |
| 487 | // noisecolor=SDL_MapRGB(sonarscreen->format, 0,(int) fabs((flowandambientnoise - RandInt(40))) , 0); |
| 488 | |
| 489 | my_noise = (int) fabs( (flowandambientnoise - RandInt(40) ) ) / 2; |
| 490 | noisecolor = SDL_MapRGB(sonarscreen->format, my_noise, my_noise, my_noise); |
| 491 | DPixel(sonarscreen, nbp, 140, noisecolor); |
| 492 | } |
| 493 | else{ |
| 494 | DPixel(sonarscreen, nbp, 140, black); |
| 495 | } |
| 496 | } |
| 497 | } |
| 498 | } |
| 499 | |
| 500 | |
| 501 | void AnBqq5::AdvanceTB16Screen() |
| 502 | |
| 503 | /****************************************** |
| 504 | This routine advances the waterfall display |
| 505 | on the TB16 towed array screen. |
| 506 | *******************************************/ |
| 507 | |
| 508 | { |
| 509 | |
| 510 | static int count = 0; |
| 511 | static int count2 = 0; |
| 512 | Uint32 noisecolor; |
| 513 | int my_noise; |
| 514 | |
| 515 | // move the minute display down |
| 516 | |
| 517 | SDL_Rect source, destination; |
| 518 | source.x = 0; //sonar screen minus last line |
| 519 | source.y = 0; |
| 520 | source.w = 360; |
| 521 | source.h = 59; |
| 522 | |
| 523 | destination.x = 0; |
| 524 | destination.y = 1; |
| 525 | destination.w = 360; |
| 526 | destination.h = 59; |
| 527 | |
| 528 | //cut towedarrayscreen and paste it to buffer |
| 529 | SDL_BlitSurface(towedarrayscreen, &source, towedarrayscreen, &destination); |
| 530 | |
| 531 | |
| 532 | |
| 533 | //erase portion of screen |
| 534 | DLine(towedarrayscreen, 0, 0, 360, 0, black); |
| 535 | if (TB16.GetLength() > 240){ |
| 536 | for(int nbp = 0; nbp<360; nbp++){ |
| 537 | |
| 538 | bool sensordeaf = false; |
| 539 | int array_heading; |
| 540 | if(northcenter){ |
| 541 | array_heading = (int)TB16.ReturnHeading(); |
| 542 | }else{ |
| 543 | array_heading = ReciprocalBearing((int)TB16.ReturnHeading()); |
| 544 | } |
| 545 | int bearing_to_target = nbp; |
| 546 | if(array_heading > bearing_to_target) bearing_to_target += 360; |
| 547 | int relative_bearing = bearing_to_target - array_heading; |
| 548 | if(relative_bearing > 150 && relative_bearing < 210) sensordeaf = true; |
| 549 | if(!sensordeaf){ |
| 550 | // noisecolor=SDL_MapRGB(towedarrayscreen->format, 0,(int) fabs((flowandambientnoise - RandInt(40))), 0); |
| 551 | my_noise = (int) fabs( (flowandambientnoise - RandInt(40) ) ) / 2; |
| 552 | noisecolor = SDL_MapRGB(towedarrayscreen->format, my_noise, my_noise, my_noise); |
| 553 | DPixel(towedarrayscreen, nbp, 0, noisecolor); |
| 554 | } |
| 555 | else{ |
| 556 | DPixel(towedarrayscreen, nbp, 0, black); |
| 557 | } |
| 558 | } |
| 559 | } |
| 560 | |
| 561 | |
| 562 | // move the 0-30 min display down |
| 563 | ++count; |
| 564 | if(count>29){ |
| 565 | count = 0; |
| 566 | |
| 567 | source.x = 0; //sonar screen minus last line |
| 568 | source.y = 70; |
| 569 | source.w = 360; |
| 570 | source.h = 59; |
| 571 | |
| 572 | destination.x = 0; |
| 573 | destination.y = 71; |
| 574 | destination.w = 360; |
| 575 | destination.h = 59; |
| 576 | |
| 577 | //cut towedarrayscreen and paste it to buffer |
| 578 | SDL_BlitSurface(towedarrayscreen, &source, towedarrayscreen, &destination); |
| 579 | if (TB16.GetLength() > 240){ |
| 580 | for(int nbp = 0; nbp<360; nbp++){ |
| 581 | |
| 582 | bool sensordeaf = false; |
| 583 | int array_heading; |
| 584 | if(northcenter){ |
| 585 | array_heading = (int)TB16.ReturnHeading(); |
| 586 | }else{ |
| 587 | array_heading = ReciprocalBearing((int)TB16.ReturnHeading()); |
| 588 | } |
| 589 | int bearing_to_target = nbp; |
| 590 | if(array_heading > bearing_to_target) bearing_to_target += 360; |
| 591 | int relative_bearing = bearing_to_target - array_heading; |
| 592 | if(relative_bearing > 150 && relative_bearing < 210) sensordeaf = true; |
| 593 | if(!sensordeaf){ |
| 594 | // noisecolor=SDL_MapRGB(towedarrayscreen->format, 0,(int) fabs((flowandambientnoise - RandInt(40))), 0); |
| 595 | my_noise = (int) fabs( (flowandambientnoise - RandInt(40) ) ) / 2; |
| 596 | noisecolor = SDL_MapRGB(towedarrayscreen->format, my_noise, my_noise, my_noise); |
| 597 | DPixel(towedarrayscreen, nbp, 70, noisecolor); |
| 598 | } |
| 599 | else{ |
| 600 | DPixel(towedarrayscreen, nbp, 70, black); |
| 601 | } |
| 602 | } |
| 603 | } |
| 604 | } |
| 605 | // move the 0-2 hour display down |
| 606 | ++count2; |
| 607 | if(count2 > 119){ |
| 608 | count2 = 0; |
| 609 | |
| 610 | source.x = 0; //sonar screen minus last line |
| 611 | source.y = 140; |
| 612 | source.w = 360; |
| 613 | source.h = 59; |
| 614 | |
| 615 | destination.x = 0; // temp buffer |
| 616 | destination.y = 141; |
| 617 | destination.w = 360; |
| 618 | destination.h = 59; |
| 619 | |
| 620 | //cut towedarrayscreen and paste it to buffer |
| 621 | SDL_BlitSurface(towedarrayscreen, &source, towedarrayscreen, &destination); |
| 622 | if (TB16.GetLength() > 240){ |
| 623 | for(int nbp = 0; nbp<360; nbp++){ |
| 624 | bool sensordeaf = false; |
| 625 | int array_heading; |
| 626 | if(northcenter){ |
| 627 | array_heading = (int)TB16.ReturnHeading(); |
| 628 | }else{ |
| 629 | array_heading = ReciprocalBearing((int)TB16.ReturnHeading()); |
| 630 | } |
| 631 | int bearing_to_target = nbp; |
| 632 | if(array_heading > bearing_to_target) bearing_to_target += 360; |
| 633 | int relative_bearing = bearing_to_target - array_heading; |
| 634 | if(relative_bearing > 150 && relative_bearing < 210) sensordeaf = true; |
| 635 | if(!sensordeaf){ |
| 636 | // noisecolor=SDL_MapRGB(towedarrayscreen->format, 0,(int) fabs((flowandambientnoise - RandInt(40))), 0); |
| 637 | my_noise = (int) fabs( (flowandambientnoise - RandInt(40) ) ) / 2; |
| 638 | noisecolor = SDL_MapRGB(towedarrayscreen->format, my_noise, my_noise, my_noise); |
| 639 | DPixel(towedarrayscreen, nbp, 140, noisecolor); |
| 640 | } |
| 641 | else{ |
| 642 | DPixel(towedarrayscreen, nbp, 140, black); |
| 643 | } |
| 644 | } |
| 645 | } |
| 646 | } |
| 647 | } |
| 648 | |
| 649 | |
| 650 | void AnBqq5::DisplayBearingScale(bool center){ |
| 651 | SDL_Rect destination_rectangle; |
| 652 | if(center){ |
| 653 | destination_rectangle.x = 50; //upper left corner to |
| 654 | destination_rectangle.y = 130; //place the scale |
| 655 | destination_rectangle.h = ncscale->h; //height & |
| 656 | destination_rectangle.w = ncscale->w;//width of button. |
| 657 | SDL_BlitSurface(ncscale, NULL, screen, &destination_rectangle); // Do the Blit. |
| 658 | SDL_UpdateRects(screen, 1, &destination_rectangle); |
| 659 | destination_rectangle.x = 50; //upper left corner to |
| 660 | destination_rectangle.y = 430; //place the scale |
| 661 | SDL_BlitSurface(ncscale, NULL, screen, &destination_rectangle); // Do the Blit. |
| 662 | SDL_UpdateRects(screen, 1, &destination_rectangle); |
| 663 | }else{ |
| 664 | destination_rectangle.x = 50; //upper left corner to |
| 665 | destination_rectangle.y = 130; //place the scale |
| 666 | destination_rectangle.h = scscale->h; //height & |
| 667 | destination_rectangle.w = scscale->w;//width of button. |
| 668 | SDL_BlitSurface(scscale, NULL, screen, &destination_rectangle); // Do the Blit. |
| 669 | SDL_UpdateRects(screen, 1, &destination_rectangle); |
| 670 | destination_rectangle.x = 50; //upper left corner to |
| 671 | destination_rectangle.y = 430; //place the scale |
| 672 | SDL_BlitSurface(scscale, NULL, screen, &destination_rectangle); // Do the Blit. |
| 673 | SDL_UpdateRects(screen, 1, &destination_rectangle); |
| 674 | } |
| 675 | } |
| 676 | |
| 677 | void AnBqq5::LoadWidgets(){ |
| 678 | //cerr << "LoadWidgets()" << endl; |
| 679 | SDL_Surface *temp; |
| 680 | |
| 681 | temp = Load_Image("images/nc_scale.png"); |
| 682 | if(temp != NULL) ncscale = SDL_DisplayFormat(temp); |
| 683 | if ( ncscale == NULL ) { // Are we screwed?? |
| 684 | cerr<<"Function LoadWidgets()" << endl |
| 685 | << SDL_GetError() << endl; |
| 686 | SDL_Quit(); |
| 687 | exit(0); |
| 688 | } |
| 689 | SDL_FreeSurface(temp); |
| 690 | |
| 691 | temp = Load_Image("images/sc_scale.png"); |
| 692 | if(temp != NULL) scscale = SDL_DisplayFormat(temp); |
| 693 | if ( scscale == NULL ) { // Are we screwed?? |
| 694 | cerr<<"Function LoadWidgets()" << endl |
| 695 | << SDL_GetError() << endl; |
| 696 | SDL_Quit(); |
| 697 | exit(0); |
| 698 | } |
| 699 | SDL_FreeSurface(temp); |
| 700 | temp = Load_Image("images/sonarup.png"); |
| 701 | if(temp != NULL) sonarbuttonup = SDL_DisplayFormat(temp); |
| 702 | if ( sonarbuttonup == NULL ) { // Are we screwed?? |
| 703 | cerr<<"Function LoadWidgets()" << endl |
| 704 | << SDL_GetError() << endl; |
| 705 | SDL_Quit(); |
| 706 | exit(0); |
| 707 | } |
| 708 | SDL_FreeSurface(temp); |
| 709 | temp = Load_Image("images/sonardown.png"); |
| 710 | if(temp != NULL) sonarbuttondown = SDL_DisplayFormat(temp); |
| 711 | if ( sonarbuttondown == NULL ) { // Are we screwed?? |
| 712 | cerr<<"Function LoadWidgets()" << endl |
| 713 | << SDL_GetError() << endl; |
| 714 | SDL_Quit(); |
| 715 | exit(0); |
| 716 | } |
| 717 | SDL_FreeSurface(temp); |
| 718 | temp = Load_Image("images/rel_true.png"); |
| 719 | if(temp != NULL) truerel[0] = SDL_DisplayFormat(temp); |
| 720 | if ( truerel[0] == NULL ) { // Are we screwed?? |
| 721 | cerr<<"Function LoadWidgets()" << endl |
| 722 | << SDL_GetError() << endl; |
| 723 | SDL_Quit(); |
| 724 | exit(0); |
| 725 | } |
| 726 | SDL_FreeSurface(temp); |
| 727 | |
| 728 | temp = Load_Image("images/true_rel.png"); |
| 729 | if(temp != NULL) truerel[1] = SDL_DisplayFormat(temp); |
| 730 | if ( truerel[1] == NULL ) { // Are we screwed?? |
| 731 | cerr<<"Function LoadWidgets()" << endl |
| 732 | << SDL_GetError() << endl; |
| 733 | SDL_Quit(); |
| 734 | exit(0); |
| 735 | } |
| 736 | SDL_FreeSurface(temp); |
| 737 | |
| 738 | temp = Load_Image("images/sphericaltowed.png"); |
| 739 | if(temp != NULL) sphertowed[1] = SDL_DisplayFormat(temp); |
| 740 | if ( sphertowed[1] == NULL ) { // Are we screwed?? |
| 741 | cerr<<"Function LoadWidgets()" << endl |
| 742 | << SDL_GetError() << endl; |
| 743 | SDL_Quit(); |
| 744 | exit(0); |
| 745 | } |
| 746 | SDL_FreeSurface(temp); |
| 747 | |
| 748 | temp = Load_Image("images/towedspherical.png"); |
| 749 | if(temp != NULL) sphertowed[0] = SDL_DisplayFormat(temp); |
| 750 | if ( sphertowed[0] == NULL ) { // Are we screwed?? |
| 751 | cerr<<"Function LoadWidgets()" << endl |
| 752 | << SDL_GetError() << endl; |
| 753 | SDL_Quit(); |
| 754 | exit(0); |
| 755 | } |
| 756 | SDL_FreeSurface(temp); |
| 757 | |
| 758 | temp = Load_Image("images/uppercrtoff.png"); |
| 759 | if(temp != NULL) uppercrtoff = SDL_DisplayFormat(temp); |
| 760 | if ( uppercrtoff == NULL ) { // Are we screwed?? |
| 761 | cerr<<"Function LoadWidgets()" << endl |
| 762 | << SDL_GetError() << endl; |
| 763 | SDL_Quit(); |
| 764 | exit(0); |
| 765 | } |
| 766 | SDL_FreeSurface(temp); |
| 767 | |
| 768 | temp = Load_Image("images/uppercrton.png"); |
| 769 | if(temp != NULL) uppercrton = SDL_DisplayFormat(temp); |
| 770 | if ( uppercrton == NULL ) { // Are we screwed?? |
| 771 | cerr<<"Function LoadWidgets()" << endl |
| 772 | << SDL_GetError() << endl; |
| 773 | SDL_Quit(); |
| 774 | exit(0); |
| 775 | } |
| 776 | SDL_FreeSurface(temp); |
| 777 | |
| 778 | temp = Load_Image("images/lowercrtoff.png"); |
| 779 | if(temp != NULL) lowercrtoff = SDL_DisplayFormat(temp); |
| 780 | if ( lowercrtoff == NULL ) { // Are we screwed?? |
| 781 | cerr<<"Function LoadWidgets()" << endl |
| 782 | << SDL_GetError() << endl; |
| 783 | SDL_Quit(); |
| 784 | exit(0); |
| 785 | } |
| 786 | SDL_FreeSurface(temp); |
| 787 | |
| 788 | temp = Load_Image("images/lowercrton.png"); |
| 789 | if(temp != NULL) lowercrton = SDL_DisplayFormat(temp); |
| 790 | if ( lowercrton == NULL ) { // Are we screwed?? |
| 791 | cerr<<"Function LoadWidgets()" << endl |
| 792 | << SDL_GetError() << endl; |
| 793 | SDL_Quit(); |
| 794 | exit(0); |
| 795 | } |
| 796 | SDL_FreeSurface(temp); |
| 797 | |
| 798 | temp = Load_Image("images/tb16winchon.png"); |
| 799 | if(temp != NULL) tb16winchon = SDL_DisplayFormat(temp); |
| 800 | if ( tb16winchon == NULL ) { // Are we screwed?? |
| 801 | cerr<<"Function LoadWidgets()" << endl |
| 802 | << SDL_GetError() << endl; |
| 803 | SDL_Quit(); |
| 804 | exit(0); |
| 805 | } |
| 806 | SDL_FreeSurface(temp); |
| 807 | |
| 808 | temp = Load_Image("images/tb16winchoff.png"); |
| 809 | if(temp != NULL) tb16winchoff = SDL_DisplayFormat(temp); |
| 810 | if ( tb16winchoff == NULL ) { // Are we screwed?? |
| 811 | cerr<<"Function LoadWidgets()" << endl |
| 812 | << SDL_GetError() << endl; |
| 813 | SDL_Quit(); |
| 814 | exit(0); |
| 815 | } |
| 816 | SDL_FreeSurface(temp); |
| 817 | |
| 818 | temp = Load_Image("images/extendtb16on.png"); |
| 819 | if(temp != NULL) extendtb16[1] = SDL_DisplayFormat(temp); |
| 820 | if ( extendtb16[1] == NULL ) { // Are we screwed?? |
| 821 | cerr<<"Function LoadWidgets()" << endl |
| 822 | << SDL_GetError() << endl; |
| 823 | SDL_Quit(); |
| 824 | exit(0); |
| 825 | } |
| 826 | SDL_FreeSurface(temp); |
| 827 | |
| 828 | temp = Load_Image("images/extendtb16off.png"); |
| 829 | if(temp != NULL) extendtb16[0] = SDL_DisplayFormat(temp); |
| 830 | if ( extendtb16[0] == NULL ) { // Are we screwed?? |
| 831 | cerr<<"Function LoadWidgets()" << endl |
| 832 | << SDL_GetError() << endl; |
| 833 | SDL_Quit(); |
| 834 | exit(0); |
| 835 | } |
| 836 | SDL_FreeSurface(temp); |
| 837 | |
| 838 | temp = Load_Image("images/retracttb16on.png"); |
| 839 | if(temp != NULL) retracttb16[1] = SDL_DisplayFormat(temp); |
| 840 | if ( retracttb16[1] == NULL ) { // Are we screwed?? |
| 841 | cerr<<"Function LoadWidgets()" << endl |
| 842 | << SDL_GetError() << endl; |
| 843 | SDL_Quit(); |
| 844 | exit(0); |
| 845 | } |
| 846 | SDL_FreeSurface(temp); |
| 847 | |
| 848 | temp = Load_Image("images/retracttb16off.png"); |
| 849 | if(temp != NULL) retracttb16[0] = SDL_DisplayFormat(temp); |
| 850 | if ( retracttb16[0] == NULL ) { // Are we screwed?? |
| 851 | cerr<<"Function LoadWidgets()" << endl |
| 852 | << SDL_GetError() << endl; |
| 853 | SDL_Quit(); |
| 854 | exit(0); |
| 855 | } |
| 856 | SDL_FreeSurface(temp); |
| 857 | |
| 858 | temp = Load_Image("images/cutarray.png"); |
| 859 | if (temp != NULL) |
| 860 | cutarray = SDL_DisplayFormat(temp); |
| 861 | if (! cutarray) |
| 862 | { |
| 863 | cerr << "Error loading cutarray.png in LoadWidgets()" << endl |
| 864 | << SDL_GetError() << endl; |
| 865 | SDL_Quit(); |
| 866 | exit(0); |
| 867 | } |
| 868 | |
| 869 | temp = Load_Image("images/ping_button.png"); |
| 870 | if (temp != NULL) |
| 871 | sendping = SDL_DisplayFormat(temp); |
| 872 | if (! sendping) |
| 873 | { |
| 874 | cerr << "Error loading ping_button.png in LoadWidgets()" << endl |
| 875 | << SDL_GetError() << endl; |
| 876 | SDL_Quit(); |
| 877 | exit(0); |
| 878 | } |
| 879 | |
| 880 | temp = Load_Image("images/assigntrackeroff.png"); |
| 881 | if(temp != NULL) assigntrackerwidget[0] = SDL_DisplayFormat(temp); |
| 882 | if ( assigntrackerwidget[0] == NULL ) { // Are we screwed?? |
| 883 | cerr<<"Function LoadWidgets()" << endl |
| 884 | << SDL_GetError() << endl; |
| 885 | SDL_Quit(); |
| 886 | exit(0); |
| 887 | } |
| 888 | SDL_FreeSurface(temp); |
| 889 | |
| 890 | temp = Load_Image("images/assigntrackeron.png"); |
| 891 | if(temp != NULL) assigntrackerwidget[1] = SDL_DisplayFormat(temp); |
| 892 | if ( assigntrackerwidget[1] == NULL ) { // Are we screwed?? |
| 893 | cerr<<"Function LoadWidgets()" << endl |
| 894 | << SDL_GetError() << endl; |
| 895 | SDL_Quit(); |
| 896 | exit(0); |
| 897 | } |
| 898 | SDL_FreeSurface(temp); |
| 899 | |
| 900 | temp = Load_Image("images/track1.png"); |
| 901 | if(temp != NULL) tracker1[0] = SDL_DisplayFormat(temp); |
| 902 | if ( tracker1[0] == NULL ) { // Are we screwed?? |
| 903 | cerr<<"Function LoadWidgets()" << endl |
| 904 | << SDL_GetError() << endl; |
| 905 | SDL_Quit(); |
| 906 | exit(0); |
| 907 | } |
| 908 | SDL_FreeSurface(temp); |
| 909 | |
| 910 | temp = Load_Image("images/track1assigned.png"); |
| 911 | if(temp != NULL) tracker1[1] = SDL_DisplayFormat(temp); |
| 912 | if ( tracker1[1] == NULL ) { // Are we screwed?? |
| 913 | cerr<<"Function LoadWidgets()" << endl |
| 914 | << SDL_GetError() << endl; |
| 915 | SDL_Quit(); |
| 916 | exit(0); |
| 917 | } |
| 918 | SDL_FreeSurface(temp); |
| 919 | |
| 920 | temp = Load_Image("images/track2.png"); |
| 921 | if(temp != NULL) tracker2[0] = SDL_DisplayFormat(temp); |
| 922 | if ( tracker2[0] == NULL ) { // Are we screwed?? |
| 923 | cerr<<"Function LoadWidgets()" << endl |
| 924 | << SDL_GetError() << endl; |
| 925 | SDL_Quit(); |
| 926 | exit(0); |
| 927 | } |
| 928 | SDL_FreeSurface(temp); |
| 929 | |
| 930 | temp = Load_Image("images/track2assigned.png"); |
| 931 | if(temp != NULL) tracker2[1] = SDL_DisplayFormat(temp); |
| 932 | if ( tracker2[1] == NULL ) { // Are we screwed?? |
| 933 | cerr<<"Function LoadWidgets()" << endl |
| 934 | << SDL_GetError() << endl; |
| 935 | SDL_Quit(); |
| 936 | exit(0); |
| 937 | } |
| 938 | SDL_FreeSurface(temp); |
| 939 | |
| 940 | temp = Load_Image("images/track3.png"); |
| 941 | if(temp != NULL) tracker3[0] = SDL_DisplayFormat(temp); |
| 942 | if ( tracker3[0] == NULL ) { // Are we screwed?? |
| 943 | cerr<<"Function LoadWidgets()" << endl |
| 944 | << SDL_GetError() << endl; |
| 945 | SDL_Quit(); |
| 946 | exit(0); |
| 947 | } |
| 948 | SDL_FreeSurface(temp); |
| 949 | |
| 950 | temp = Load_Image("images/track3assigned.png"); |
| 951 | if(temp != NULL) tracker3[1] = SDL_DisplayFormat(temp); |
| 952 | if ( tracker3[1] == NULL ) { // Are we screwed?? |
| 953 | cerr<<"Function LoadWidgets()" << endl |
| 954 | << SDL_GetError() << endl; |
| 955 | SDL_Quit(); |
| 956 | exit(0); |
| 957 | } |
| 958 | SDL_FreeSurface(temp); |
| 959 | |
| 960 | temp = Load_Image("images/track4.png"); |
| 961 | if(temp != NULL) tracker4[0] = SDL_DisplayFormat(temp); |
| 962 | if ( tracker4[0] == NULL ) { // Are we screwed?? |
| 963 | cerr<<"Function LoadWidgets()" << endl |
| 964 | << SDL_GetError() << endl; |
| 965 | SDL_Quit(); |
| 966 | exit(0); |
| 967 | } |
| 968 | SDL_FreeSurface(temp); |
| 969 | |
| 970 | temp = Load_Image("images/track4assigned.png"); |
| 971 | if(temp != NULL) tracker4[1] = SDL_DisplayFormat(temp); |
| 972 | if ( tracker4[1] == NULL ) { // Are we screwed?? |
| 973 | cerr<<"Function LoadWidgets()" << endl |
| 974 | << SDL_GetError() << endl; |
| 975 | SDL_Quit(); |
| 976 | exit(0); |
| 977 | } |
| 978 | SDL_FreeSurface(temp); |
| 979 | } |
| 980 | |
| 981 | void AnBqq5::DisplaySonarWidgets(){ |
| 982 | SDL_Rect destination_rectangle; |
| 983 | destination_rectangle.x = 180; //upper left corner to |
| 984 | destination_rectangle.y = 710; //place the button. |
| 985 | if (sonarwidget){ // Is our button down? |
| 986 | destination_rectangle.h = sonarbuttondown->h; //height & |
| 987 | destination_rectangle.w = sonarbuttondown->w;//width of button. |
| 988 | SDL_BlitSurface(sonarbuttondown, NULL, screen, &destination_rectangle); // Do the Blit. |
| 989 | SDL_UpdateRects(screen, 1, &destination_rectangle); //Show the screen... |
| 990 | destination_rectangle.x = 614; |
| 991 | destination_rectangle.y = 161; |
| 992 | destination_rectangle.h = truerel[bearingdisplay5by6]->h; //height & |
| 993 | destination_rectangle.w = truerel[bearingdisplay5by6]->w;//width of button |
| 994 | SDL_BlitSurface(truerel[bearingdisplay5by6], NULL, screen, &destination_rectangle); // Do the Blit.. |
| 995 | SDL_UpdateRects(screen, 1, &destination_rectangle); //Show the screen... |
| 996 | destination_rectangle.x = 614; |
| 997 | destination_rectangle.y = 215; |
| 998 | destination_rectangle.h = sphertowed[arraychoice5by6]->h; //height & |
| 999 | destination_rectangle.w = sphertowed[arraychoice5by6]->w;//width of button |
| 1000 | SDL_BlitSurface(sphertowed[arraychoice5by6], NULL, screen, &destination_rectangle); // Do the Blit.. |
| 1001 | SDL_UpdateRects(screen, 1, &destination_rectangle); //Show the screen... |
| 1002 | destination_rectangle.x = 661; |
| 1003 | destination_rectangle.y = 161; |
| 1004 | destination_rectangle.h = uppercrtoff->h; //height & |
| 1005 | destination_rectangle.w = uppercrtoff->w;//width of button |
| 1006 | SDL_BlitSurface(uppercrtoff, NULL, screen, &destination_rectangle); // Do the Blit.. |
| 1007 | SDL_UpdateRects(screen, 1, &destination_rectangle); //Show the screen... |
| 1008 | destination_rectangle.x = 661; |
| 1009 | destination_rectangle.y = 215; |
| 1010 | destination_rectangle.h = lowercrtoff->h; //height & |
| 1011 | destination_rectangle.w = lowercrtoff->w;//width of button |
| 1012 | SDL_BlitSurface(lowercrtoff, NULL, screen, &destination_rectangle); // Do the Blit.. |
| 1013 | SDL_UpdateRects(screen, 1, &destination_rectangle); //Show the screen... |
| 1014 | destination_rectangle.x = 520; |
| 1015 | destination_rectangle.y = 590; |
| 1016 | destination_rectangle.h = cutarray->h; |
| 1017 | destination_rectangle.w = cutarray->w; |
| 1018 | SDL_BlitSurface(cutarray, NULL, screen, &destination_rectangle); |
| 1019 | SDL_UpdateRects(screen, 1, &destination_rectangle); |
| 1020 | |
| 1021 | destination_rectangle.x = 472; |
| 1022 | destination_rectangle.y = 590; |
| 1023 | destination_rectangle.h = sendping->h; |
| 1024 | destination_rectangle.w = sendping->w; |
| 1025 | SDL_BlitSurface(sendping, NULL, screen, &destination_rectangle); |
| 1026 | SDL_UpdateRects(screen, 1, &destination_rectangle); |
| 1027 | |
| 1028 | destination_rectangle.x = 567; |
| 1029 | destination_rectangle.y = 590; |
| 1030 | destination_rectangle.h = tb16winchoff->h; //height & |
| 1031 | destination_rectangle.w = tb16winchoff->w;//width of button |
| 1032 | SDL_BlitSurface(tb16winchoff, NULL, screen, &destination_rectangle); // Do the Blit.. |
| 1033 | SDL_UpdateRects(screen, 1, &destination_rectangle); //Show the screen... |
| 1034 | destination_rectangle.x = 614; |
| 1035 | destination_rectangle.y = 590; |
| 1036 | destination_rectangle.h = extendtb16[TB16.winch==1]->h; //height & |
| 1037 | destination_rectangle.w = extendtb16[TB16.winch==1]->w;//width of button |
| 1038 | SDL_BlitSurface(extendtb16[TB16.winch==1], NULL, screen, &destination_rectangle); // Do the Blit.. |
| 1039 | SDL_UpdateRects(screen, 1, &destination_rectangle); //Show the screen... |
| 1040 | destination_rectangle.x = 661; |
| 1041 | destination_rectangle.y = 590; |
| 1042 | destination_rectangle.h = retracttb16[TB16.winch==2]->h; //height & |
| 1043 | destination_rectangle.w = retracttb16[TB16.winch==2]->w;//width of button |
| 1044 | SDL_BlitSurface(retracttb16[TB16.winch==2], NULL, screen, &destination_rectangle); // Do the Blit.. |
| 1045 | SDL_UpdateRects(screen, 1, &destination_rectangle); //Show the screen... |
| 1046 | destination_rectangle.x = 473; |
| 1047 | destination_rectangle.y = 403; |
| 1048 | destination_rectangle.h = assigntrackerwidget[0]->h; //height & |
| 1049 | destination_rectangle.w = assigntrackerwidget[0]->w;//width of button |
| 1050 | SDL_BlitSurface(assigntrackerwidget[assigntracker], NULL, screen, &destination_rectangle); // Do the Blit.. |
| 1051 | SDL_UpdateRects(screen, 1, &destination_rectangle); //Show the screen... |
| 1052 | destination_rectangle.x = 520; |
| 1053 | destination_rectangle.y = 403; |
| 1054 | destination_rectangle.h = tracker1[0]->h; //height & |
| 1055 | destination_rectangle.w = tracker1[0]->w;//width of button |
| 1056 | SDL_BlitSurface(tracker1[Tma.GetTrackerState(0)], NULL, screen, &destination_rectangle); // Do the Blit.. |
| 1057 | SDL_UpdateRects(screen, 1, &destination_rectangle); //Show the screen... |
| 1058 | destination_rectangle.x = 567; |
| 1059 | destination_rectangle.y = 403; |
| 1060 | destination_rectangle.h = tracker2[0]->h; //height & |
| 1061 | destination_rectangle.w = tracker2[0]->w;//width of button |
| 1062 | SDL_BlitSurface(tracker2[Tma.GetTrackerState(1)], NULL, screen, &destination_rectangle); // Do the Blit.. |
| 1063 | SDL_UpdateRects(screen, 1, &destination_rectangle); //Show the screen... |
| 1064 | destination_rectangle.x = 614; |
| 1065 | destination_rectangle.y = 403; |
| 1066 | destination_rectangle.h = tracker3[0]->h; //height & |
| 1067 | destination_rectangle.w = tracker3[0]->w;//width of button |
| 1068 | SDL_BlitSurface(tracker3[Tma.GetTrackerState(2)], NULL, screen, &destination_rectangle); // Do the Blit.. |
| 1069 | SDL_UpdateRects(screen, 1, &destination_rectangle); //Show the screen... |
| 1070 | destination_rectangle.x = 661; |
| 1071 | destination_rectangle.y = 403; |
| 1072 | destination_rectangle.h = tracker4[0]->h; //height & |
| 1073 | destination_rectangle.w = tracker4[0]->w;//width of button |
| 1074 | SDL_BlitSurface(tracker4[Tma.GetTrackerState(3)], NULL, screen, &destination_rectangle); // Do the Blit.. |
| 1075 | SDL_UpdateRects(screen, 1, &destination_rectangle); //Show the screen... |
| 1076 | }else{ // our button must be up... |
| 1077 | destination_rectangle.h = sonarbuttonup->h; //height & |
| 1078 | destination_rectangle.w = sonarbuttonup->w;//width of button. |
| 1079 | SDL_BlitSurface(sonarbuttonup, NULL, screen, &destination_rectangle); // Do the Blit. |
| 1080 | SDL_UpdateRects(screen, 1, &destination_rectangle); //Show the screen... |
| 1081 | } |
| 1082 | } |
| 1083 | |
| 1084 | |
| 1085 | void AnBqq5::UpperCRT_Spherical(){ |
| 1086 | uppersonarcrt = sonarscreen; |
| 1087 | } |
| 1088 | |
| 1089 | void AnBqq5::LowerCRT_Spherical(){ |
| 1090 | lowersonarcrt = sonarscreen; |
| 1091 | } |
| 1092 | |
| 1093 | void AnBqq5::UpperCRT_TowedArray(){ |
| 1094 | uppersonarcrt = towedarrayscreen; |
| 1095 | } |
| 1096 | |
| 1097 | void AnBqq5::LowerCRT_TowedArray(){ |
| 1098 | lowersonarcrt = towedarrayscreen; |
| 1099 | } |
| 1100 | |
| 1101 | void AnBqq5::ToggleArrayChoice(){ |
| 1102 | arraychoice5by6 = !arraychoice5by6; |
| 1103 | } |
| 1104 | |
| 1105 | void AnBqq5::ToggleTrueRel(){ |
| 1106 | bearingdisplay5by6 = !bearingdisplay5by6; |
| 1107 | } |
| 1108 | |
| 1109 | void AnBqq5::ToggleAssignTracker(){ |
| 1110 | assigntracker = !assigntracker; |
| 1111 | } |
| 1112 | |
| 1113 | bool AnBqq5::GetNorthCenterState(){ |
| 1114 | return northcenter; |
| 1115 | } |
| 1116 | |
| 1117 | void AnBqq5::ToggleNorthCenter(){ |
| 1118 | northcenter = !northcenter; |
| 1119 | } |
| 1120 | |
| 1121 | void AnBqq5::UpperCRT_Button(){ |
| 1122 | SDL_Rect destination_rectangle; |
| 1123 | destination_rectangle.x = 661; |
| 1124 | destination_rectangle.y = 161; |
| 1125 | destination_rectangle.h = uppercrton->h; //height & |
| 1126 | destination_rectangle.w = uppercrton->w;//width of button |
| 1127 | SDL_BlitSurface(uppercrton, NULL, screen, &destination_rectangle); // Do the Blit.. |
| 1128 | SDL_UpdateRects(screen, 1, &destination_rectangle); //Show the screen... |
| 1129 | SDL_Delay(200); |
| 1130 | if(arraychoice5by6){ |
| 1131 | UpperCRT_Spherical(); |
| 1132 | }else{ |
| 1133 | UpperCRT_TowedArray(); |
| 1134 | } |
| 1135 | DisplaySonarWidgets(); |
| 1136 | } |
| 1137 | |
| 1138 | void AnBqq5::LowerCRT_Button(){ |
| 1139 | SDL_Rect destination_rectangle; |
| 1140 | destination_rectangle.x = 661; |
| 1141 | destination_rectangle.y = 215; |
| 1142 | destination_rectangle.h = lowercrton->h; //height & |
| 1143 | destination_rectangle.w = lowercrton->w;//width of button |
| 1144 | SDL_BlitSurface(lowercrton, NULL, screen, &destination_rectangle); // Do the Blit.. |
| 1145 | SDL_UpdateRects(screen, 1, &destination_rectangle); //Show the screen... |
| 1146 | SDL_Delay(200); |
| 1147 | if(arraychoice5by6){ |
| 1148 | LowerCRT_Spherical(); |
| 1149 | }else{ |
| 1150 | LowerCRT_TowedArray(); |
| 1151 | } |
| 1152 | DisplaySonarWidgets(); |
| 1153 | } |
| 1154 | |
| 1155 | void AnBqq5::StopWinch(){ |
| 1156 | SDL_Rect destination_rectangle; |
| 1157 | destination_rectangle.x = 567; |
| 1158 | destination_rectangle.y = 590; |
| 1159 | destination_rectangle.h = tb16winchon->h; //height & |
| 1160 | destination_rectangle.w = tb16winchon->w;//width of button |
| 1161 | SDL_BlitSurface(tb16winchon, NULL, screen, &destination_rectangle); // Do the Blit.. |
| 1162 | SDL_UpdateRects(screen, 1, &destination_rectangle); //Show the screen... |
| 1163 | TB16.Stop(); |
| 1164 | SDL_Delay(200); |
| 1165 | DisplaySonarWidgets(); |
| 1166 | } |
| 1167 | |
| 1168 | int AnBqq5::RandInt(int TO) //Returns a random interger...TO is upper limit |
| 1169 | { |
| 1170 | return (rand()%TO); |
| 1171 | } |
| 1172 | |
| 1173 | int AnBqq5::ReciprocalBearing(int bearing) |
| 1174 | { |
| 1175 | // returns the 180 degree opposite of the bearing given to it.. |
| 1176 | int recipbearing; |
| 1177 | if (bearing >= 180){ |
| 1178 | recipbearing = bearing - 180; |
| 1179 | }else{ |
| 1180 | recipbearing = bearing + 180; |
| 1181 | } |
| 1182 | return recipbearing; |
| 1183 | } |
| 1184 | |
| 1185 | |
| 1186 | |
| 1187 | void AnBqq5::DisplayCursor() |
| 1188 | { |
| 1189 | SDL_Rect rectangle; |
| 1190 | //Draw Cursor |
| 1191 | if(!northcenter){ |
| 1192 | DLine(screen, 51+cursorBearing, 140, 51+cursorBearing, 147, green); |
| 1193 | rectangle.x=51+cursorBearing; |
| 1194 | }else{ |
| 1195 | int recipCursorBearing = ReciprocalBearing(cursorBearing); |
| 1196 | DLine(screen, 51+recipCursorBearing, 140, 51+recipCursorBearing, 147, green); |
| 1197 | rectangle.x=51+recipCursorBearing; |
| 1198 | } |
| 1199 | rectangle.y=140; |
| 1200 | rectangle.h=7; |
| 1201 | rectangle.w=1; |
| 1202 | SDL_UpdateRects(screen, 1, &rectangle); |
| 1203 | } |
| 1204 | void AnBqq5::UpdateCursor() |
| 1205 | { |
| 1206 | int direction, temp; |
| 1207 | int ship_type; |
| 1208 | float signal; |
| 1209 | if (Subs->GetCount()>0){ |
| 1210 | //Are there any sound events at this time index to worry about? |
| 1211 | for (int event=1; event<=Subs->GetCount(); event++){ |
| 1212 | //If so step through the events. |
| 1213 | Subs->GetEvent(event, &direction, &signal, &ship_type); |
| 1214 | //Okay this used to go through each bearing one by one and |
| 1215 | //check to see if there was a sonar contact. But this is slow.. |
| 1216 | //So we are now incrementing by 5 degrees to speed thing along |
| 1217 | //In doing so we now have to chech relative_bearings because |
| 1218 | //the contact might get passed by if it's on a 0/359 deg boundary. |
| 1219 | temp = direction; |
| 1220 | if(cursorBearing > temp) temp += 360; |
| 1221 | // relative_bearing = temp - cursorBearing; |
| 1222 | |
| 1223 | //if(relative_bearing < 3 || relative_bearing >357){ |
| 1224 | // cout << "TargetId: " << TargetId << " - Bearing: " << direction <<endl; |
| 1225 | /* |
| 1226 | static char text[120]; |
| 1227 | sprintf(text, "TARGET-ID %3i - BEARING %3i", TargetId, direction); |
| 1228 | string textline = text; |
| 1229 | Message.post_message(textline); |
| 1230 | Message.display_message(); |
| 1231 | */ |
| 1232 | //} |
| 1233 | } |
| 1234 | } |
| 1235 | //If cursor located on undesignated contact, Halt on contact. |
| 1236 | //else |
| 1237 | cursorBearing += 5; |
| 1238 | if(cursorBearing>360) cursorBearing -= 360; |
| 1239 | //Some debug crap |
| 1240 | /*if (cursorBearing > 360) cout << "cursor over " << cursorBearing <<endl; |
| 1241 | if (cursorBearing < 0) cout << "cursor under " << cursorBearing << endl;*/ |
| 1242 | } |