Debian Codegraph @

src/submarine.h

raw symbols SCIP
1 /***************************************************************************
2 submarine.h - description
3 -------------------
4 begin : Sat Mar 16 2002
5 copyright : (C) 2002 by Michael Bridak
6 email : [email protected]
7 $Id: submarine.h,v 1.5 2003/04/14 05:51:04 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 SUBMARINE_H
20 #define SUBMARINE_H
21
22 #include <stdio.h>
23 #include "coord.h"
24 #include "map.h"
25 #include "stack.h"
26 #include "towedarray.h"
27
28 #ifndef TRUE
29 #define TRUE 1
30 #endif
31 #ifndef FALSE
32 #define FALSE 0
33 #endif
34
35 #define TYPE_SUB 0
36 #define TYPE_SHIP 1
37 #define TYPE_AIR 2
38 #define TYPE_TORPEDO 3
39 #define TYPE_NOISEMAKER 4
40 #define TYPE_HELICOPTER 5
41
42 #define FRIEND 1
43 #define FOE 0
44 #define UNKNOWN 2
45 #define NEUTRAL 3
46
47 #define CONTACT_SOLID 100
48 #define CONTACT_WEAK 25
49 #define CONTACT_PING 5
50 #define PING_NOISE 200
51
52 #define CLASS_NAME_SIZE 32
53 #define CLASS_TYPE_SIZE 8
54 #define CLASS_LOSANGELES 1
55 #define CLASS_AKULA 2
56 #define CLASS_DESTROYER 3
57 #define CLASS_MERCHANT 4
58 #define CLASS_TORPEDO 5
59 #define CLASS_NOISEMAKER 6
60 #define CLASS_TYPHOON 7
61 #define CLASS_NIMITZ 8
62 #define CLASS_TBILISI 9
63 #define CLASS_ALPHA 10
64 #define CLASS_OHIO 11
65 #define CLASS_HELICOPTER 12
66
67 // status of tubes
68 #define MAX_TUBES 6
69 #define TUBE_EMPTY 0
70 #define TUBE_TORPEDO 1
71 #define TUBE_NOISEMAKER 2
72
73
74 // Actions to do with tubes
75 // these have weird nmbers for legacy reasons
76 #define LOAD_TORPEDO 66
77 #define LOAD_NOISEMAKER 67
78 #define UNLOAD_TUBE 68
79 #define FIRE_TUBE 69
80
81 // torpedo tube status codes
82 #define TUBE_ERROR_NUMBER 1 // we were passed an invalid tube number
83 #define TUBE_ERROR_FULL 2 // tube has something in it
84 #define TUBE_ERROR_ACTION 3 // we were passed an invalid action
85 #define TUBE_ERROR_NO_TORPEDO 4 // we are out of torpedos
86 #define TUBE_ERROR_NO_NOISE 5 // we are out of noise makers
87 #define TUBE_ERROR_TORPEDO_SUCCESS 6 // tube loaded successfully
88 #define TUBE_ERROR_NOISEMAKER_SUCCESS 7 // tube loaded successfully
89 #define TUBE_ERROR_UNLOAD_SUCCESS 8 // we cleared the tube ok
90 #define TUBE_ERROR_FIRE_FAIL 9 // could not fire torpedo
91 #define TUBE_ERROR_FIRE_SUCCESS 10 // we fired a torpedo
92 #define TUBE_ERROR_FIRE_NOISEMAKER 11 // we fired a noisemaker
93
94 #define TORPEDO_FUEL 600
95 #define HITTING_RANGE 50
96 #define HITTING_DEPTH 25
97 #define OUT_OF_FUEL 1
98 #define HIT_TARGET 2
99 #define STATUS_OK 3
100
101 #define DAMAGE_OK 1
102 #define DAMAGE_SINK 2
103
104 #define CHANCE_COURSE 1000
105 #define RUDDER_CHANGE 0.025
106 #define PLANES_CHANGE 0.2 // originally around 0.185
107
108 #define MISSION_NONE 0
109 #define MISSION_SINK 1
110 #define MISSION_FIND 2
111 #define MISSION_ALIVE 3
112
113 #define YARDS_TO_MILES 0.000568
114 #define MILES_TO_YARDS 1760
115 #define PERISCOPE_DEPTH 50
116
117 #define MAX_TORPEDOES_FIRED 1
118 #define MAX_NOISEMAKERS_FIRED 1
119 #define MAX_PLAYER_WEAPONS 6
120 #define MAX_TORPEDO_RANGE 8
121 #define TORPEDO_RANGE_ATTACK 4
122 #define TORPEDO_RANGE_PASSIVE 3
123
124 #define DISTRACTED_CHANCE 4 // 1 in 4 chance a torpedo will chase noisemaker
125
126 // types of behaviour
127 #define MOOD_ATTACK 1
128 #define MOOD_PASSIVE 2
129 #define MOOD_CONVOY 3
130
131 #define CONVOY_CHANGE_COURSE 1200
132
133 // radio messages for surface ships
134 #define RADIO_NONE 0
135 #define RADIO_UNDER_ATTACK 1
136 #define RADIO_HEAR_TORPEDO 2
137 // maybe add impending attack, detected sub, reform convoy...
138
139
140
141
142 /**
143 *@author Michael Bridak
144 */
145
146 typedef struct
147 {
148 void *sub;
149 void *next;
150 int contact_strength;
151 } Target;
152
153
154 class Submarine : public Coord, public Stack {
155 public:
156 float NauticalMiles;
157 float HisPassiveSonarCrosssection;
158 float EffectiveTargetSpeed;
159 float AmbientNoise;
160 float OwnShipNoise;
161 float flowandambientnoise;
162 float TotalNoise;
163 float TargetNoise;
164 float Gb;
165 float Lbp;
166 float NoiseFromSpeed;
167 float BasisNoiseLevel;
168 float value;
169 float SeaState; // Anyone want to model the weather.
170 int current_target; // who are we tracking?
171 int Active; /*Flag to see if ship is in the world.*/
172 int ShipType; /*SubSurface, Surface, Air */
173 int ShipClass; // specific type (Los Angels, Akula, etc)
174 char ClassName[CLASS_NAME_SIZE];
175 char ClassType[CLASS_TYPE_SIZE];
176 int Friend; /*Flag to mark if ship is a friend/foe/neither*/
177 float Depth; /*How deep are we?*/
178 int DesiredDepth; /*You want to go how deep!*/
179 int MaxDepth; /*Why is my hull crushing!*/
180 int DesiredSpeed; /*Scotty warp speed!*/
181 int MaxSpeed; /*Captin I've given her all she's got!*/
182 int MinSpeed; /*You want to go how fast in reverse!?*/
183 int DesiredHeading;
184 int Rudder; /*bend me and she will turn*/
185 int TorpedosOnBoard; /*Where are all the fish!*/
186 int NoiseMakers; // to destract the torpedos
187 int CavitationFlag;
188 int BaseNoise; /*how noisey are we just sittin' here*/
189 float PSCS; /*Passive Sonar Crosssection*/
190 float RadiatedNoise(); /*Tell 'em how loud we are.*/
191 void CheckForCavitation(); /*self explanitory */
192 void Handeling(); /*Turn Left/Right go Up/Down Etc...*/
193 float CheckNegSpeed(float); /*if Speed is negative return inverse value*/
194 double DistanceToTarget(Submarine *Target);
195 double BearingToTarget(Submarine *Target);
196 double BearingToOrigin(Submarine *Target);
197 float DEAngle(Submarine *Target);
198 int hull_strength;
199 int mission_status;
200 int mission_timer;
201 int has_sonar;
202 int mood;
203 int convoy_course_change;
204 int radio_message;
205 int torpedo_tube[MAX_TUBES];
206 int pinging; // are we using active sonar?
207 int using_radar;
208 MAP *map;
209
210 Submarine *next; // also for torpedos, though could be used
211 // later for ships
212 Submarine *target; // for torpedoes
213 Target *last_target;
214 Submarine *owner; // torpedoes are owned by ships/subs
215 int fuel_remaining; // mostly for torpedos,
216 // but maybe for electric subs later
217 int origin_x, origin_y; // where did this torp come from?
218
219 Submarine();
220 ~Submarine();
221 void Init();
222
223 // We should be able to track targets
224 Target *targets;
225 int Add_Target(Submarine *new_sub, float contact_strength);
226 void Remove_Target(Submarine *old_sub);
227 void Cancel_Target(Submarine *old_sub);
228 int Can_Detect(Submarine *a_sub);
229
230 // returns target index or -1 if none is available
231 Submarine *Next_Target();
232
233 // Load information on this type of ship/sub
234 int Load_Class(char *from_file);
235 int Load_Mission(FILE *from_file);
236 int Use_Tube(int action, int tube_number);
237
238 Submarine *Fire_Tube(Submarine *target, char *ship_file);
239 int Can_Hear(Submarine *target);
240 int Torpedo_AI(Submarine *all_subs);
241 // figure out what to do with surface ships
242 // Submarine *Ship_AI(Submarine *all_ships, Submarine *all_torpedoes);
243 // like ship AI in 3D
244 Submarine *Sub_AI(Submarine *all_ships, Submarine *all_torpedoes, void *helicopters);
245 int Check_Status(); // see if our torpedo is ok
246 int Take_Damage(); // we were hit!
247 int Count_Torpedoes(Submarine *all_torpedoes); // how many have I fired?
248 int Count_Noisemakers(Submarine *all_noise); // how many have I launched?
249 Submarine *Have_Enemy_Target(Submarine *all_ships);
250 Submarine *Launch_Noisemaker(Submarine *all_torpedoes, Submarine *chased_by); // AI function
251 int Is_Distracted_By_Noisemaker(Submarine *noisemaker); // is this torpedo distracted?
252 int Radio_Signal(Submarine *all_ships, int my_signal);
253 int Send_Ping(Submarine *all_ships);
254 int InBaffles(Submarine *target, int sensor, TowedArray *TB16);
255 };
256
257 #endif
258