1 /*************************************************************************** 2 main.h - description 3 ------------------- 4 begin : Tue Sep 19 2000 5 copyright : (C) 2000 by Michael Bridak 6 email : michael.bridak@verizon.net 7 $Id: main.h,v 1.11 2003/07/18 03:50:00 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 #ifndef MAIN_H 20 #define MAIN_H 21 22 #ifndef VERSION 23 #define VERSION 1.4 24 #endif 25 26 #include "helicopter.h" 27 28 // delay between game loops 29 #define GAME_DELAY 10 30 #define MAP_FACTOR 20 31 #define MAX_MAP_SCALE 500 32 33 #define PERISCOPE_DEPTH 50 34 #define MAX_SUBS 20 35 36 #define DEFAULT_SEA_STATE 3 37 #define SHIP_HEIGHT 100 38 39 40 /** Our main program and control loop 41 *@author Michael Bridak 42 */ 43 // Some defs for easy living. 44 #define SONAR 1 45 #define NAVMAP 2 46 #define TMA 3 47 #define QUIT 4 48 #define COMPRESSTIME 5 49 #define UNCOMPRESSTIME 6 50 #define INCREASESPEED 7 51 #define DECREASESPEED 8 52 #define DUMPSCREEN 9 53 #define TURNPORT 10 54 #define TURNSTARBOARD 11 55 #define INCREASEDEPTH 12 56 #define DECREASEDEPTH 13 57 #define INCREASEMAPSCALE 14 58 #define DECREASEMAPSCALE 15 59 #define CENTERDISPLAY 16 60 #define EXTENDARRAY 17 61 #define RETRACTARRAY 18 62 #define STOPWINCH 19 63 #define PAUSEGAME 20 64 #define SHIPCONTROL 21 65 #define SCROLLMAPUP 22 66 #define SCROLLMAPDOWN 23 67 #define SCROLLMAPLEFT 24 68 #define SCROLLMAPRIGHT 25 69 #define TOGGLESPHERICALTOWED 26 70 #define TOGGLETRUERELATIVE 27 71 #define UPPERCRTBUTTON 28 72 #define LOWERCRTBUTTON 29 73 #define ASSIGNTRACKER 30 74 #define TRACKER1 31 75 #define TRACKER2 32 76 #define TRACKER3 33 77 #define TRACKER4 34 78 #define ESM 35 79 #define RADAR 36 80 81 // Radar Event Updates 82 #define TOGGLER10 37 83 #define TOGGLER20 38 84 #define TOGGLER30 39 85 #define TOGGLER40 40 86 #define TOGGLER50 41 87 #define TOGGLER60 42 88 #define RADARDOWN 43 89 #define RADARUP 44 90 #define RING0 45 91 #define RING5 46 92 #define RING10 47 93 #define RING15 48 94 #define RING20 49 95 #define RING25 50 96 97 // Esm Event Updates 98 #define ESMDOWN 51 99 #define ESMUP 52 100 101 // Control Station Updates 102 #define ASTOP 53 103 #define A13 54 104 #define A23 55 105 #define ASTD 56 106 #define AFULL 57 107 #define AFLK 58 108 #define B13 59 109 #define B23 60 110 #define BSTD 61 111 #define BEMER 62 112 #define DESIGNATECONTACT 63 113 #define SWITCHTARGET 64 114 #define WEAPONS 65 115 #define LOAD_TORPEDO 66 116 #define LOAD_NOISEMAKER 67 117 #define UNLOAD_TUBE 68 118 #define FIRE_TUBE 69 119 #define WHICHTUBE 70 120 #define USE_TUBE 71 121 #define CUTARRAY 72 122 #define SEND_PING 73 123 #define UP_THERMAL 74 124 #define HOLD_DEPTH 75 125 #define DOWN_THERMAL 76 126 #define GO_PERISCOPE_DEPTH 77 127 #define GO_SURFACE 78 128 129 130 //globals 131 132 // int ships = 19; // why does ships equal 19, isn't this set in CreateShips? 133 float flowandambientnoise; 134 SDL_Surface *screen=NULL; //The screen we are goin to be looking at 135 SDL_Surface *towedarrayscreen=NULL; //scratch blit surface 136 137 // rdm 138 SDL_Surface *radarscreen=NULL; //scratch blit surface 139 SDL_Surface *esmscreen=NULL; //scratch blit surface 140 SDL_Surface *controlscreen=NULL; 141 142 143 144 SDL_Surface *tempscreen=NULL; //scratch screen 145 SDL_Surface *sonarbuttonup=NULL; //button element 146 SDL_Surface *sonarbuttondown=NULL; //button element 147 SDL_Surface *navbuttonup=NULL; //button element 148 SDL_Surface *navbuttondown=NULL; //button element 149 SDL_Surface *tmabuttonup=NULL; //button element 150 SDL_Surface *tmabuttondown=NULL; //button element 151 SDL_Surface *shipcontrolbuttonup=NULL;//button element 152 SDL_Surface *shipcontrolbuttondown=NULL;//button element 153 SDL_Surface *esmbuttonup=NULL;//button element 154 SDL_Surface *esmbuttondown=NULL;//button element 155 SDL_Surface *radarbuttonup=NULL;//button element 156 SDL_Surface *radarbuttondown=NULL;//button element 157 SDL_Surface *quitbuttonup=NULL; //button element 158 SDL_Surface *quitbuttondown=NULL; //button element 159 SDL_Surface *plusbuttonup=NULL; //button element 160 SDL_Surface *plusbuttondown=NULL; //button element 161 SDL_Surface *centerbuttonup=NULL; //button element 162 SDL_Surface *centerbuttondown=NULL; //button element 163 SDL_Surface *leftbuttonup=NULL; //button element 164 SDL_Surface *leftbuttondown=NULL; //button element 165 SDL_Surface *rightbuttonup=NULL; //button element 166 SDL_Surface *rightbuttondown=NULL; //button element 167 SDL_Surface *upbuttonup=NULL; //button element 168 SDL_Surface *upbuttondown=NULL; //button element 169 SDL_Surface *downbuttonup=NULL; //button element 170 SDL_Surface *downbuttondown=NULL; //button element 171 SDL_Surface *minusbuttonup=NULL; //button element 172 SDL_Surface *minusbuttondown=NULL; //button element 173 SDL_Surface *ncscale=NULL; 174 SDL_Surface *scscale=NULL; 175 SDL_Surface *truerel[2]={NULL, NULL}; 176 SDL_Surface *sphertowed[2]={NULL, NULL}; 177 SDL_Surface *tb16winchon=NULL; 178 SDL_Surface *tb16winchoff=NULL; 179 SDL_Surface *extendtb16[2]={NULL, NULL}; 180 SDL_Surface *retracttb16[2]={NULL, NULL}; 181 SDL_Surface *uppercrtoff=NULL; 182 SDL_Surface *uppercrton=NULL; 183 SDL_Surface *lowercrtoff=NULL; 184 SDL_Surface *lowercrton=NULL; 185 SDL_Surface *assigntrackerwidget[2]={NULL, NULL}; 186 SDL_Surface *tracker1[2]={NULL, NULL}; 187 SDL_Surface *tracker2[2]={NULL, NULL}; 188 SDL_Surface *tracker3[2]={NULL, NULL}; 189 SDL_Surface *tracker4[2]={NULL, NULL}; 190 SDL_Surface *noisemaker_image = NULL; 191 SDL_Surface *torpedo_image = NULL; 192 193 194 //a mutex so we don't crash and burn 195 //when accessing the same globals 196 //in a callback function. 197 SDL_mutex *tmamutex; 198 199 SDL_Rect destination_rectangle; //rectangle structure for blitting 200 201 DFont fnt(const char*, const char *); 202 DFont fnt2(const char*, const char *); 203 204 int tube_action = 0; // what are we doing with a torpedo tube 205 int tube_to_use = -1; // the tube to perform this action on 206 207 int drawsonar; //flags for UpdateDisplay() 208 int drawmap; //flags for UpdateDisplay() 209 int drawtma; //flags for UpdateDisplay() 210 //rdm 211 int drawweapons; // display weapons screen 212 int drawradar; //flags for UpdateDisplay() 213 int drawesm; //flags for UpdateDisplay() 214 int drawcontrol; //flags for UpdateDisplay 215 216 int mapscale = 25; 217 int mapcenter = 1; // by default, center the map on our ship 218 int timecompression; 219 int sonarwidget, navwidget, quitwidget, tmawidget; //button pressed flags 220 int shipcontrolwidget, esmwidget, radarwidget; //shouldn't these be bools? 221 Uint32 textcolor, black, white, red, green, yellow, grey, mapcolor;//Place to hold color info 222 Uint32 dark_green, dark_red, brown, dark_grey; 223 bool show_spherical_traces = true, northcenter = true, pause_game = false; 224 bool assigntracker = false; 225 Submarine *current_target = NULL; 226 int update_weapons_screen = TRUE; 227 int my_mission_status; 228 int should_update_everything = TRUE; 229 230 GameClock Clock; 231 // Submarine Subs[MAX_SUBS]; //Somewhere to put our little floating buddies. 232 Submarine *Subs = NULL; // all subs, ships 233 Submarine *player = NULL; 234 Contact Contacts[MAX_SUBS]; //Workable contacts. 235 Submarine *torpedoes; // a linked-list of torpedoes 236 Helicopter *helicopters; // a linked-list of helicopters 237 TowedArray TB16; 238 TargetMotionAnalysis Tma; 239 msg Message; 240 AnBqq5 SonarStation(Subs, TB16, Tma, Message); 241 242 243 Radar RadarStation(Subs); 244 Esm EsmStation(Subs); 245 Control ControlStation(Subs); 246 247 248 //Danger I don't know what I'm doing here 249 struct position { 250 float lat; 251 float lon; 252 }; 253 std::list<position> SubPosLog; //STL incompetence DANGER! 254 //End Danger 255 256 257 //declarations 258 void SetupScreen(bool); 259 void CreateShips(int mission_number, MAP *map); 260 void UpdateSensors(void); 261 void UpdateDisplay(void); 262 void TakeCommands(void); 263 double RelativeBearing(Submarine *observer, Submarine *target); 264 int ReciprocalBearing(int bearing); 265 double AngleOnBow(Submarine *observer, Submarine *target); 266 int maximize360 ( int course ); 267 int minimize360 ( int course ); 268 double CalculateRange(Submarine *observer, Submarine *target); 269 void LatLonDifference(Submarine *observer, Submarine *target, double *platdif, double *plondif); 270 void PositionCursor(int, int); 271 void ClearScreen(void); 272 void Display_Target(void); 273 void DrawMap(void); 274 void Draw_Depth_Meter(Submarine *my_sub, int which_screen); 275 /* 276 void DrawPixel(SDL_Surface *screen, int x, int y, Uint32 Color); 277 void DrawLine(SDL_Surface *screen, int X1, int Y1, int X2, int Y2, Uint32 Color); 278 void DrawArc(SDL_Surface *screen, int X1, int Y1, int Radius, int Theta1, int Theta2, Uint32 Color); 279 void DrawCircle(SDL_Surface *screen, int X1, int Y1, int Radius, Uint32 Color); 280 void DrawDiamond(SDL_Surface *screen, int X1, int Y1, int Size, char Direction, Uint32 Color); 281 void DrawBox(SDL_Surface *screen, int X1, int Y1, int Size, char Direction, Uint32 Color); 282 void DrawRectangle(SDL_Surface *screen, int x1, int y1, int x2, int y2, Uint32 Color); 283 void DrawCross(SDL_Surface *screen, int X1, int Y1, int Size, char Direction, Uint32 Color); 284 */ 285 void PlaceShips(int, int = 0, int = 0, Submarine *target=NULL); // the int = 0's are default values 286 // inline void DrawPixel(SDL_Surface *screen, int x, int y, Uint32 Color); 287 // inline void DrawLine(SDL_Surface *screen, int X1, int Y1, int X2, int Y2, Uint32 Color); 288 void LoadScreen(int screen_to_load); 289 void ShowStation(int station); 290 void DisplaySonar(); 291 void DisplayTMA(int xoffset=0, int yoffset=0); 292 void DisplayWeapons(void); 293 void LoadWidgets(void); 294 void UnLoadWidgets(void); 295 void DisplayWidgets(void); 296 void DisplayNavigationWidgets(); 297 void DisplayTMAWidgets(); 298 void DisplayESMWidgets(); 299 void DisplayRADARWidgets(); 300 void ResetWidgetFlags(void); 301 inline int RandInt(int to); 302 void MapIcon(int x, int y, int ShipType, int Friend, Uint32 color); 303 void DirectionalPointer(int X, int Y, int Heading, int speed, Uint32 Color); 304 int InBaffles(Submarine *observer, Submarine *target, int sensor); 305 void SoundEnvironment(void); 306 float Any_Detection(double Range, Submarine *observer, Submarine *target); 307 float Radar_Detection(double Range, Submarine *observer, Submarine *target); 308 float Esm_Detection(double Range, Submarine *observer, Submarine *target); 309 // float Sonar_Detection(double Range, int ObserverShipId, int TargetShipId); 310 float Sonar_Detection_New(double Range, Submarine *observer, Submarine *target); 311 inline int Clamp(int); 312 inline double Clamp(double); 313 Uint32 TmaTimer(Uint32 interval, void *param); 314 Uint32 timerfunc(Uint32 interval, void *param); 315 316 Submarine *Add_Ship(Submarine *all_torpedoes, Submarine *new_torpedo); 317 Submarine *Remove_Ship(Submarine *all_torpedoes, Submarine *old_torpedo); 318 void Remove_Inactive_Ship(Submarine *victim); // find and remove inactive ship 319 Helicopter *Add_Helicopter(Helicopter *all_helicopters, Helicopter *new_helicopter); 320 Helicopter *Remove_Helicopter(Helicopter *all_helicopters, Helicopter*old_helicopter); 321 322 #endif 323 324