| 1 | /*************************************************************************** |
| 2 | submarine.cpp - description |
| 3 | ------------------- |
| 4 | begin : Sat Mar 16 2002 |
| 5 | copyright : (C) 2002 by Michael Bridak |
| 6 | email : [email protected] |
| 7 | $Id: submarine.cpp,v 1.6 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 | #include <iostream> |
| 20 | #include <fstream> |
| 21 | #include <math.h> |
| 22 | #include <limits.h> |
| 23 | #include <stdlib.h> |
| 24 | #include <string.h> |
| 25 | #include "submarine.h"cxx . . $ `<file>/src/submarine.h`/ |
| 26 | #include "files.h"cxx . . $ `<file>/src/files.h`/ |
| 27 | #include "sound.h"cxx . . $ `<file>/src/sound.h`/ |
| 28 | #include "map.h"cxx . . $ `<file>/src/map.h`/ |
| 29 | |
| 30 | using namespace std; |
| 31 | |
| 32 | Submarinecxx . . $ Submarine#::Submarinecxx . . $ Submarine#Submarine(49f6e7a06ebc5aa8).() |
| 33 | { |
| 34 | Initcxx . . $ Submarine#Init(49f6e7a06ebc5aa8).(); |
| 35 | } |
| 36 | |
| 37 | Submarinecxx . . $ Submarine#::~cxx . . $ Submarine#`~Submarine`(ced63f7c635d850d).Submarinecxx . . $ Submarine#() |
| 38 | { |
| 39 | } |
| 40 | |
| 41 | |
| 42 | |
| 43 | void Submarinecxx . . $ Submarine#::Initcxx . . $ Submarine#Init(49f6e7a06ebc5aa8).() |
| 44 | { |
| 45 | int index; |
| 46 | |
| 47 | //Passive Sonar Cross Section |
| 48 | //in future make different pscs's |
| 49 | //based on angle of view, front |
| 50 | //side and rear. |
| 51 | |
| 52 | PSCScxx . . $ Submarine#PSCS.=83.0; |
| 53 | Activecxx . . $ Submarine#Active. = FALSEcxx . . $ `src/map.h:13:9`!; |
| 54 | CavitationFlagcxx . . $ Submarine#CavitationFlag.=0; |
| 55 | Depthcxx . . $ Submarine#Depth.=0; |
| 56 | MaxDepthcxx . . $ Submarine#MaxDepth.=999; |
| 57 | Speedcxx . . $ Coord#Speed.=5.0; |
| 58 | MaxSpeedcxx . . $ Submarine#MaxSpeed.=32; |
| 59 | MinSpeedcxx . . $ Submarine#MinSpeed.=-12; |
| 60 | DesiredSpeedcxx . . $ Submarine#DesiredSpeed.=0; |
| 61 | Ruddercxx . . $ Submarine#Rudder.=10; |
| 62 | TorpedosOnBoardcxx . . $ Submarine#TorpedosOnBoard.=24; |
| 63 | NoiseMakerscxx . . $ Submarine#NoiseMakers. = 12; |
| 64 | ShipClasscxx . . $ Submarine#ShipClass. = CLASS_MERCHANTcxx . . $ `src/submarine.h:57:9`!; |
| 65 | // clear targets |
| 66 | targetscxx . . $ Submarine#targets. = NULLcxx . . $ `<external>/15298297234472979974/stddef.h:416:9`!; |
| 67 | last_targetcxx . . $ Submarine#last_target. = NULLcxx . . $ `<external>/15298297234472979974/stddef.h:416:9`!; |
| 68 | current_targetcxx . . $ Submarine#current_target. = -1; |
| 69 | for (index = 0; index < MAX_TUBEScxx . . $ `src/submarine.h:68:9`!; index++) |
| 70 | torpedo_tubecxx . . $ Submarine#torpedo_tube.[index] = TUBE_EMPTYcxx . . $ `src/submarine.h:69:9`!; |
| 71 | nextcxx . . $ Submarine#next. = NULLcxx . . $ `<external>/15298297234472979974/stddef.h:416:9`!; |
| 72 | targetcxx . . $ Submarine#target. = NULLcxx . . $ `<external>/15298297234472979974/stddef.h:416:9`!; |
| 73 | ownercxx . . $ Submarine#owner. = NULLcxx . . $ `<external>/15298297234472979974/stddef.h:416:9`!; |
| 74 | fuel_remainingcxx . . $ Submarine#fuel_remaining. = INT_MAXcxx . . $ `<external>/67164224788392828/limits.h:120:9`!; |
| 75 | hull_strengthcxx . . $ Submarine#hull_strength. = 1; |
| 76 | has_sonarcxx . . $ Submarine#has_sonar. = TRUEcxx . . $ `src/map.h:10:9`!; |
| 77 | mission_statuscxx . . $ Submarine#mission_status. = MISSION_NONEcxx . . $ `src/submarine.h:108:9`!; |
| 78 | mission_timercxx . . $ Submarine#mission_timer. = 0; |
| 79 | moodcxx . . $ Submarine#mood. = MOOD_PASSIVEcxx . . $ `src/submarine.h:128:9`!; |
| 80 | convoy_course_changecxx . . $ Submarine#convoy_course_change. = CONVOY_CHANGE_COURSEcxx . . $ `src/submarine.h:131:9`!; |
| 81 | radio_messagecxx . . $ Submarine#radio_message. = RADIO_NONEcxx . . $ `src/submarine.h:134:9`!; |
| 82 | pingingcxx . . $ Submarine#pinging. = FALSEcxx . . $ `src/map.h:13:9`!; |
| 83 | using_radarcxx . . $ Submarine#using_radar. = FALSEcxx . . $ `src/map.h:13:9`!; |
| 84 | mapcxx . . $ Submarine#map. = NULLcxx . . $ `<external>/15298297234472979974/stddef.h:416:9`!; |
| 85 | ClassNamecxx . . $ Submarine#ClassName.[0] = '\0'; |
| 86 | ClassTypecxx . . $ Submarine#ClassType.[0] = '\0'; |
| 87 | } |
| 88 | |
| 89 | |
| 90 | |
| 91 | float Submarinecxx . . $ Submarine#::RadiatedNoisecxx . . $ Submarine#RadiatedNoise(9b8c9e39889c762c).(){ |
| 92 | //This will return how noisey you are |
| 93 | |
| 94 | float unit=40; |
| 95 | float multiplier=4.2; |
| 96 | float value=0; |
| 97 | |
| 98 | CheckForCavitationcxx . . $ Submarine#CheckForCavitation(49f6e7a06ebc5aa8).(); |
| 99 | value = PSCScxx . . $ Submarine#PSCS. + (unit * CavitationFlagcxx . . $ Submarine#CavitationFlag.) + (((CheckNegSpeedcxx . . $ Submarine#CheckNegSpeed(fbcf3211dfe1bfd1).(Speedcxx . . $ Coord#Speed.)>4.9)*multiplier) * CheckNegSpeedcxx . . $ Submarine#CheckNegSpeed(fbcf3211dfe1bfd1).(Speedcxx . . $ Coord#Speed.)); |
| 100 | if (pingingcxx . . $ Submarine#pinging.) |
| 101 | value += PING_NOISEcxx . . $ `src/submarine.h:50:9`!; |
| 102 | return value; |
| 103 | } |
| 104 | |
| 105 | float Submarinecxx . . $ Submarine#::CheckNegSpeedcxx . . $ Submarine#CheckNegSpeed(fbcf3211dfe1bfd1).(float value){ |
| 106 | if(value < 0){ |
| 107 | return 100.0 - (100.0 + value); |
| 108 | }else{ |
| 109 | return value; |
| 110 | } |
| 111 | } |
| 112 | void Submarinecxx . . $ Submarine#::CheckForCavitationcxx . . $ Submarine#CheckForCavitation(49f6e7a06ebc5aa8).(){ |
| 113 | |
| 114 | //Check to see if we are cavitating... |
| 115 | // 4-5kts @ 0-100ft. |
| 116 | // 5-14kts @ 100-150ft |
| 117 | // 14-35kts @ 150-600ft |
| 118 | |
| 119 | CavitationFlagcxx . . $ Submarine#CavitationFlag. = 0; |
| 120 | |
| 121 | if ((Depthcxx . . $ Submarine#Depth. <100) && (CheckNegSpeedcxx . . $ Submarine#CheckNegSpeed(fbcf3211dfe1bfd1).(Speedcxx . . $ Coord#Speed.) > 4.0)){ |
| 122 | if ((CheckNegSpeedcxx . . $ Submarine#CheckNegSpeed(fbcf3211dfe1bfd1).(Speedcxx . . $ Coord#Speed.) - 4.0) > (float) Depthcxx . . $ Submarine#Depth. / 100.0){ |
| 123 | CavitationFlagcxx . . $ Submarine#CavitationFlag. = 1; |
| 124 | } |
| 125 | return; |
| 126 | } |
| 127 | |
| 128 | if ((Depthcxx . . $ Submarine#Depth. < 150) && (CheckNegSpeedcxx . . $ Submarine#CheckNegSpeed(fbcf3211dfe1bfd1).(Speedcxx . . $ Coord#Speed.) > 5.0)){ |
| 129 | if (((CheckNegSpeedcxx . . $ Submarine#CheckNegSpeed(fbcf3211dfe1bfd1).(Speedcxx . . $ Coord#Speed.) - 5.0) * 5.555) > (Depthcxx . . $ Submarine#Depth. -100)){ |
| 130 | CavitationFlagcxx . . $ Submarine#CavitationFlag. = 1; |
| 131 | } |
| 132 | return; |
| 133 | } |
| 134 | |
| 135 | if ((Depthcxx . . $ Submarine#Depth. < 600) && (CheckNegSpeedcxx . . $ Submarine#CheckNegSpeed(fbcf3211dfe1bfd1).(Speedcxx . . $ Coord#Speed.) > 14.0)){ |
| 136 | if (((CheckNegSpeedcxx . . $ Submarine#CheckNegSpeed(fbcf3211dfe1bfd1).(Speedcxx . . $ Coord#Speed.) - 14.0) * 21.428) > (Depthcxx . . $ Submarine#Depth. - 150)){ |
| 137 | CavitationFlagcxx . . $ Submarine#CavitationFlag. = 1; |
| 138 | } |
| 139 | return; |
| 140 | } |
| 141 | } |
| 142 | double Submarinecxx . . $ Submarine#::BearingToTargetcxx . . $ Submarine#BearingToTarget(2de0d0e522051339).(Submarinecxx . . $ Submarine# *Target){ |
| 143 | double latdif=0, londif=0, bearing = 0; //atan() needs doubles |
| 144 | //LatLonDifference(observer, target, &latdif, &londif); |
| 145 | |
| 146 | if (! Target) |
| 147 | return 0; |
| 148 | if (Lat_TotalYardscxx . . $ Coord#Lat_TotalYards. > Target->Lat_TotalYardscxx . . $ Coord#Lat_TotalYards.){ |
| 149 | latdif = Lat_TotalYardscxx . . $ Coord#Lat_TotalYards. - Target->Lat_TotalYardscxx . . $ Coord#Lat_TotalYards.; |
| 150 | } |
| 151 | else{ |
| 152 | latdif = Target->Lat_TotalYardscxx . . $ Coord#Lat_TotalYards. - Lat_TotalYardscxx . . $ Coord#Lat_TotalYards.; |
| 153 | } |
| 154 | |
| 155 | if (Lon_TotalYardscxx . . $ Coord#Lon_TotalYards. > Target->Lon_TotalYardscxx . . $ Coord#Lon_TotalYards.){ |
| 156 | londif = Lon_TotalYardscxx . . $ Coord#Lon_TotalYards. - Target->Lon_TotalYardscxx . . $ Coord#Lon_TotalYards.; |
| 157 | } |
| 158 | else{ |
| 159 | londif = Target->Lon_TotalYardscxx . . $ Coord#Lon_TotalYards. - Lon_TotalYardscxx . . $ Coord#Lon_TotalYards.; |
| 160 | } |
| 161 | |
| 162 | if ((Lon_TotalYardscxx . . $ Coord#Lon_TotalYards. < Target->Lon_TotalYardscxx . . $ Coord#Lon_TotalYards.) && |
| 163 | (Lat_TotalYardscxx . . $ Coord#Lat_TotalYards. < Target->Lat_TotalYardscxx . . $ Coord#Lat_TotalYards.)){ |
| 164 | bearing = (360 - ((atancxx . . $ atan(fee4f1d22bc8e617).(latdif / londif) * 360) / 6.28318530717958647692)); |
| 165 | } |
| 166 | else if ((Lon_TotalYardscxx . . $ Coord#Lon_TotalYards. < Target->Lon_TotalYardscxx . . $ Coord#Lon_TotalYards.) && |
| 167 | (Lat_TotalYardscxx . . $ Coord#Lat_TotalYards. > Target->Lat_TotalYardscxx . . $ Coord#Lat_TotalYards.)){ |
| 168 | bearing = (0 + ((atancxx . . $ atan(fee4f1d22bc8e617).(latdif / londif) * 360) / 6.28318530717958647692)); |
| 169 | } |
| 170 | else if ((Lon_TotalYardscxx . . $ Coord#Lon_TotalYards. > Target->Lon_TotalYardscxx . . $ Coord#Lon_TotalYards.) && |
| 171 | (Lat_TotalYardscxx . . $ Coord#Lat_TotalYards. < Target->Lat_TotalYardscxx . . $ Coord#Lat_TotalYards.)){ |
| 172 | bearing = (180 + ((atancxx . . $ atan(fee4f1d22bc8e617).(latdif / londif) * 360) / 6.28318530717958647692)); |
| 173 | } |
| 174 | else if ((Lon_TotalYardscxx . . $ Coord#Lon_TotalYards. > Target->Lon_TotalYardscxx . . $ Coord#Lon_TotalYards.) && |
| 175 | (Lat_TotalYardscxx . . $ Coord#Lat_TotalYards. > Target->Lat_TotalYardscxx . . $ Coord#Lat_TotalYards.)){ |
| 176 | bearing = (180 - ((atancxx . . $ atan(fee4f1d22bc8e617).(latdif / londif) * 360) / 6.28318530717958647692)); |
| 177 | } |
| 178 | if (londif == 0){ |
| 179 | if (Lat_TotalYardscxx . . $ Coord#Lat_TotalYards. > Target->Lat_TotalYardscxx . . $ Coord#Lat_TotalYards.){ |
| 180 | bearing = 90; |
| 181 | }else{ |
| 182 | bearing = 270; |
| 183 | } |
| 184 | } |
| 185 | if (latdif == 0){ |
| 186 | if (Lon_TotalYardscxx . . $ Coord#Lon_TotalYards. > Target->Lon_TotalYardscxx . . $ Coord#Lon_TotalYards.){ |
| 187 | bearing = 180; |
| 188 | }else{ |
| 189 | bearing = 0; |
| 190 | } |
| 191 | } |
| 192 | return bearing; |
| 193 | } |
| 194 | |
| 195 | |
| 196 | double Submarinecxx . . $ Submarine#::BearingToOrigincxx . . $ Submarine#BearingToOrigin(2de0d0e522051339).(Submarinecxx . . $ Submarine# *Target) |
| 197 | { |
| 198 | double latdif=0, londif=0, bearing = 0; //atan() needs doubles |
| 199 | //LatLonDifference(observer, target, &latdif, &londif); |
| 200 | |
| 201 | if (! Target) |
| 202 | return 0; |
| 203 | if (Lat_TotalYardscxx . . $ Coord#Lat_TotalYards. > Target->origin_xcxx . . $ Submarine#origin_x.){ |
| 204 | latdif = Lat_TotalYardscxx . . $ Coord#Lat_TotalYards. - Target->origin_xcxx . . $ Submarine#origin_x.; |
| 205 | } |
| 206 | else{ |
| 207 | latdif = Target->origin_xcxx . . $ Submarine#origin_x. - Lat_TotalYardscxx . . $ Coord#Lat_TotalYards.; |
| 208 | } |
| 209 | |
| 210 | if (Lon_TotalYardscxx . . $ Coord#Lon_TotalYards. > Target->origin_ycxx . . $ Submarine#origin_y.){ |
| 211 | londif = Lon_TotalYardscxx . . $ Coord#Lon_TotalYards. - Target->origin_ycxx . . $ Submarine#origin_y.; |
| 212 | } |
| 213 | else{ |
| 214 | londif = Target->origin_ycxx . . $ Submarine#origin_y. - Lon_TotalYardscxx . . $ Coord#Lon_TotalYards.; |
| 215 | } |
| 216 | |
| 217 | if ((Lon_TotalYardscxx . . $ Coord#Lon_TotalYards. < Target->origin_ycxx . . $ Submarine#origin_y.) && |
| 218 | (Lat_TotalYardscxx . . $ Coord#Lat_TotalYards. < Target->origin_xcxx . . $ Submarine#origin_x.)){ |
| 219 | bearing = (360 - ((atancxx . . $ atan(fee4f1d22bc8e617).(latdif / londif) * 360) / 6.28318530717958647692)); |
| 220 | } |
| 221 | if ((Lon_TotalYardscxx . . $ Coord#Lon_TotalYards. < Target->origin_ycxx . . $ Submarine#origin_y.) && |
| 222 | (Lat_TotalYardscxx . . $ Coord#Lat_TotalYards. > Target->origin_xcxx . . $ Submarine#origin_x.)){ |
| 223 | bearing = (0 + ((atancxx . . $ atan(fee4f1d22bc8e617).(latdif / londif) * 360) / 6.28318530717958647692)); |
| 224 | } |
| 225 | if ((Lon_TotalYardscxx . . $ Coord#Lon_TotalYards. > Target->origin_ycxx . . $ Submarine#origin_y.) && |
| 226 | (Lat_TotalYardscxx . . $ Coord#Lat_TotalYards. < Target->origin_xcxx . . $ Submarine#origin_x.)){ |
| 227 | bearing = (180 + ((atancxx . . $ atan(fee4f1d22bc8e617).(latdif / londif) * 360) / 6.28318530717958647692)); |
| 228 | } |
| 229 | if ((Lon_TotalYardscxx . . $ Coord#Lon_TotalYards. > Target->origin_ycxx . . $ Submarine#origin_y.) && |
| 230 | (Lat_TotalYardscxx . . $ Coord#Lat_TotalYards. > Target->origin_xcxx . . $ Submarine#origin_x.)){ |
| 231 | bearing = (180 - ((atancxx . . $ atan(fee4f1d22bc8e617).(latdif / londif) * 360) / 6.28318530717958647692)); |
| 232 | } |
| 233 | |
| 234 | if (londif == 0){ |
| 235 | if (Lat_TotalYardscxx . . $ Coord#Lat_TotalYards. > Target->origin_xcxx . . $ Submarine#origin_x.){ |
| 236 | bearing = 90; |
| 237 | }else{ |
| 238 | bearing = 270; |
| 239 | } |
| 240 | } |
| 241 | if (latdif == 0){ |
| 242 | if (Lon_TotalYardscxx . . $ Coord#Lon_TotalYards. > Target->origin_ycxx . . $ Submarine#origin_y.){ |
| 243 | bearing = 180; |
| 244 | }else{ |
| 245 | bearing = 0; |
| 246 | } |
| 247 | } |
| 248 | return bearing; |
| 249 | |
| 250 | } |
| 251 | |
| 252 | |
| 253 | |
| 254 | double Submarinecxx . . $ Submarine#::DistanceToTargetcxx . . $ Submarine#DistanceToTarget(2de0d0e522051339).(Submarinecxx . . $ Submarine# *Target){ |
| 255 | double latdif = 0, londif = 0; //sqrt needs doubles |
| 256 | //LatLonDifference( observer, target, &latdif, &londif ); |
| 257 | |
| 258 | if (! Target) |
| 259 | return 0; |
| 260 | |
| 261 | if (Lat_TotalYardscxx . . $ Coord#Lat_TotalYards. > Target->Lat_TotalYardscxx . . $ Coord#Lat_TotalYards.){ |
| 262 | latdif = Lat_TotalYardscxx . . $ Coord#Lat_TotalYards. - Target->Lat_TotalYardscxx . . $ Coord#Lat_TotalYards.; |
| 263 | } |
| 264 | else{ |
| 265 | latdif = Target->Lat_TotalYardscxx . . $ Coord#Lat_TotalYards. - Lat_TotalYardscxx . . $ Coord#Lat_TotalYards.; |
| 266 | } |
| 267 | |
| 268 | if (Lon_TotalYardscxx . . $ Coord#Lon_TotalYards. > Target->Lon_TotalYardscxx . . $ Coord#Lon_TotalYards.){ |
| 269 | londif = Lon_TotalYardscxx . . $ Coord#Lon_TotalYards. - Target->Lon_TotalYardscxx . . $ Coord#Lon_TotalYards.; |
| 270 | } |
| 271 | else{ |
| 272 | londif = Target->Lon_TotalYardscxx . . $ Coord#Lon_TotalYards. - Lon_TotalYardscxx . . $ Coord#Lon_TotalYards.; |
| 273 | } |
| 274 | return sqrtcxx . . $ sqrt(fee4f1d22bc8e617).((latdif * latdif) + (londif * londif)); |
| 275 | } |
| 276 | |
| 277 | float Submarinecxx . . $ Submarine#::DEAnglecxx . . $ Submarine#DEAngle(9d7e1bc3065e2a78).(Submarinecxx . . $ Submarine# *Target){ |
| 278 | double distance = 0.0; |
| 279 | int depthDifference = 0; |
| 280 | double deang = 0.0; |
| 281 | |
| 282 | distance = DistanceToTargetcxx . . $ Submarine#DistanceToTarget(2de0d0e522051339).(Target); |
| 283 | |
| 284 | if (Depthcxx . . $ Submarine#Depth. < Target->Depthcxx . . $ Submarine#Depth.){ |
| 285 | depthDifference = (int)(Target->Depthcxx . . $ Submarine#Depth. - Depthcxx . . $ Submarine#Depth.); |
| 286 | }else{ |
| 287 | depthDifference = (int)(Depthcxx . . $ Submarine#Depth. - Target->Depthcxx . . $ Submarine#Depth.); |
| 288 | } |
| 289 | |
| 290 | if (depthDifference != 0) depthDifference = depthDifference * 3; |
| 291 | |
| 292 | if (distance > depthDifference){ |
| 293 | deang = (atancxx . . $ atan(fee4f1d22bc8e617).(distance / depthDifference) * 360) / 6.283185307179; |
| 294 | }else{ |
| 295 | deang = (atancxx . . $ atan(fee4f1d22bc8e617).(depthDifference / distance) * 360) / 6.283185307179; |
| 296 | } |
| 297 | |
| 298 | if (Depthcxx . . $ Submarine#Depth. > Target->Depthcxx . . $ Submarine#Depth.){ |
| 299 | deang = 90.0 - deang; |
| 300 | }else{ |
| 301 | deang = deang - 90.0; |
| 302 | } |
| 303 | |
| 304 | return (float)deang; |
| 305 | |
| 306 | } |
| 307 | |
| 308 | |
| 309 | |
| 310 | void Submarinecxx . . $ Submarine#::Handelingcxx . . $ Submarine#Handeling(49f6e7a06ebc5aa8).(){ |
| 311 | |
| 312 | // This is where we change the ships characteristics |
| 313 | // based on the desired variables |
| 314 | // First we'll do depth |
| 315 | |
| 316 | // float UpBubble; //The greater the amount the faster the change. |
| 317 | // float DownBubble; |
| 318 | float AmountOfChange; //How much to turn the boat. |
| 319 | float temp_speed = Speedcxx . . $ Coord#Speed.; |
| 320 | float delta_depth = 0.0; |
| 321 | |
| 322 | if (temp_speed < 0) |
| 323 | temp_speed = -temp_speed; |
| 324 | // keep desired depth sane |
| 325 | if (DesiredDepthcxx . . $ Submarine#DesiredDepth. < 0) |
| 326 | DesiredDepthcxx . . $ Submarine#DesiredDepth. = 0; |
| 327 | else if (DesiredDepthcxx . . $ Submarine#DesiredDepth. > MaxDepthcxx . . $ Submarine#MaxDepth.) |
| 328 | DesiredDepthcxx . . $ Submarine#DesiredDepth. = MaxDepthcxx . . $ Submarine#MaxDepth.; |
| 329 | |
| 330 | delta_depth = temp_speed * PLANES_CHANGEcxx . . $ `src/submarine.h:106:9`!; |
| 331 | if (delta_depth < 1.0) |
| 332 | delta_depth = 1.0; |
| 333 | else if (delta_depth > 5.0) |
| 334 | delta_depth = 5.0; |
| 335 | if (ShipTypecxx . . $ Submarine#ShipType. == TYPE_TORPEDOcxx . . $ `src/submarine.h:38:9`!) |
| 336 | delta_depth *= 2.0; |
| 337 | |
| 338 | if (DesiredDepthcxx . . $ Submarine#DesiredDepth. > Depthcxx . . $ Submarine#Depth.){ //Do we need to go up? |
| 339 | // UpBubble = 0.05; //5% up bubble if we're close |
| 340 | // if ((DesiredDepth - Depth) > 20){ |
| 341 | // UpBubble = 0.1; //10% Up Bubble |
| 342 | // } |
| 343 | // UpBubble *= 4; |
| 344 | // Depth += ((temp_speed * PLANES_CHANGE) * UpBubble); //feet per second @ 1kt = 0.185 |
| 345 | Depthcxx . . $ Submarine#Depth. += delta_depth; |
| 346 | if (Depthcxx . . $ Submarine#Depth. > DesiredDepthcxx . . $ Submarine#DesiredDepth.){ //if we have risen past the desired depth |
| 347 | Depthcxx . . $ Submarine#Depth. = DesiredDepthcxx . . $ Submarine#DesiredDepth.; //Flatten us out |
| 348 | } |
| 349 | } |
| 350 | |
| 351 | if (DesiredDepthcxx . . $ Submarine#DesiredDepth. < Depthcxx . . $ Submarine#Depth.){ //Do we need to go down? |
| 352 | // DownBubble= 0.05; //5% Down Bubble if we're close |
| 353 | // if ((Depth - DesiredDepth) >20){ |
| 354 | // DownBubble = 0.1; //10% down bubble |
| 355 | // } |
| 356 | // UpBubble *= 4; |
| 357 | // Depth -= ((temp_speed * PLANES_CHANGE) * DownBubble); |
| 358 | Depthcxx . . $ Submarine#Depth. -= delta_depth; |
| 359 | if (Depthcxx . . $ Submarine#Depth. < DesiredDepthcxx . . $ Submarine#DesiredDepth.){ |
| 360 | Depthcxx . . $ Submarine#Depth. = DesiredDepthcxx . . $ Submarine#DesiredDepth.; |
| 361 | } |
| 362 | } |
| 363 | |
| 364 | //Change Heading |
| 365 | |
| 366 | // AmountOfChange = (Rudder * Speed) * 0.012; |
| 367 | AmountOfChange = (Ruddercxx . . $ Submarine#Rudder. * temp_speed) * RUDDER_CHANGEcxx . . $ `src/submarine.h:105:9`!; |
| 368 | #ifdef DEBUG |
| 369 | printf("Rudder change %f\n", AmountOfChange); |
| 370 | #endif |
| 371 | if (Headingcxx . . $ Coord#Heading. > DesiredHeadingcxx . . $ Submarine#DesiredHeading.){ |
| 372 | if ((Headingcxx . . $ Coord#Heading. - DesiredHeadingcxx . . $ Submarine#DesiredHeading.) < 180){ |
| 373 | Headingcxx . . $ Coord#Heading. = Headingcxx . . $ Coord#Heading. - AmountOfChange; |
| 374 | if ((Headingcxx . . $ Coord#Heading. < DesiredHeadingcxx . . $ Submarine#DesiredHeading.) && |
| 375 | ((DesiredHeadingcxx . . $ Submarine#DesiredHeading. - Headingcxx . . $ Coord#Heading.) < AmountOfChange)){ |
| 376 | Headingcxx . . $ Coord#Heading. = (float)DesiredHeadingcxx . . $ Submarine#DesiredHeading.; |
| 377 | } |
| 378 | } |
| 379 | else{ |
| 380 | Headingcxx . . $ Coord#Heading. = Headingcxx . . $ Coord#Heading. + AmountOfChange; |
| 381 | if ((Headingcxx . . $ Coord#Heading. > DesiredHeadingcxx . . $ Submarine#DesiredHeading.) && |
| 382 | ((Headingcxx . . $ Coord#Heading. - DesiredHeadingcxx . . $ Submarine#DesiredHeading.) < AmountOfChange)){ |
| 383 | Headingcxx . . $ Coord#Heading. = (float)DesiredHeadingcxx . . $ Submarine#DesiredHeading.; |
| 384 | } |
| 385 | } |
| 386 | } |
| 387 | else{ |
| 388 | if (Headingcxx . . $ Coord#Heading. < DesiredHeadingcxx . . $ Submarine#DesiredHeading.){ |
| 389 | if ((DesiredHeadingcxx . . $ Submarine#DesiredHeading. - Headingcxx . . $ Coord#Heading.) < 180){ |
| 390 | Headingcxx . . $ Coord#Heading. += AmountOfChange; |
| 391 | if ((Headingcxx . . $ Coord#Heading. > DesiredHeadingcxx . . $ Submarine#DesiredHeading.) && |
| 392 | ((Headingcxx . . $ Coord#Heading. - DesiredHeadingcxx . . $ Submarine#DesiredHeading.) < AmountOfChange)){ |
| 393 | Headingcxx . . $ Coord#Heading. = (float)DesiredHeadingcxx . . $ Submarine#DesiredHeading.; |
| 394 | } |
| 395 | } |
| 396 | else{ |
| 397 | Headingcxx . . $ Coord#Heading. = Headingcxx . . $ Coord#Heading. - AmountOfChange; |
| 398 | if ((Headingcxx . . $ Coord#Heading. < DesiredHeadingcxx . . $ Submarine#DesiredHeading.) && |
| 399 | ((DesiredHeadingcxx . . $ Submarine#DesiredHeading. - Headingcxx . . $ Coord#Heading.) < AmountOfChange)){ |
| 400 | Headingcxx . . $ Coord#Heading. = (float)DesiredHeadingcxx . . $ Submarine#DesiredHeading.; |
| 401 | } |
| 402 | } |
| 403 | } |
| 404 | } |
| 405 | |
| 406 | if (Headingcxx . . $ Coord#Heading. > 360){ |
| 407 | Headingcxx . . $ Coord#Heading. = Headingcxx . . $ Coord#Heading. - 360.0; |
| 408 | } |
| 409 | else{ |
| 410 | if (Headingcxx . . $ Coord#Heading. < 0){ |
| 411 | Headingcxx . . $ Coord#Heading. = Headingcxx . . $ Coord#Heading. + 360.0; |
| 412 | } |
| 413 | } |
| 414 | |
| 415 | // Change Speed |
| 416 | |
| 417 | if(DesiredSpeedcxx . . $ Submarine#DesiredSpeed. > MaxSpeedcxx . . $ Submarine#MaxSpeed.) DesiredSpeedcxx . . $ Submarine#DesiredSpeed. = MaxSpeedcxx . . $ Submarine#MaxSpeed.; |
| 418 | if(DesiredSpeedcxx . . $ Submarine#DesiredSpeed. < MinSpeedcxx . . $ Submarine#MinSpeed.) DesiredSpeedcxx . . $ Submarine#DesiredSpeed. = MinSpeedcxx . . $ Submarine#MinSpeed.; |
| 419 | if (DesiredSpeedcxx . . $ Submarine#DesiredSpeed. > Speedcxx . . $ Coord#Speed.){ //Speed Up |
| 420 | Speedcxx . . $ Coord#Speed. += 0.45; //a little less than 1/2 a knot per second.. |
| 421 | if (Speedcxx . . $ Coord#Speed. > DesiredSpeedcxx . . $ Submarine#DesiredSpeed.) Speedcxx . . $ Coord#Speed. = DesiredSpeedcxx . . $ Submarine#DesiredSpeed.; // Did we go past target speed? |
| 422 | } |
| 423 | |
| 424 | if (Speedcxx . . $ Coord#Speed. > DesiredSpeedcxx . . $ Submarine#DesiredSpeed.){ //Slow Down |
| 425 | Speedcxx . . $ Coord#Speed. -= 0.45; |
| 426 | if (Speedcxx . . $ Coord#Speed. < DesiredSpeedcxx . . $ Submarine#DesiredSpeed.) Speedcxx . . $ Coord#Speed.=DesiredSpeedcxx . . $ Submarine#DesiredSpeed.; // Did we slow too much? |
| 427 | } |
| 428 | |
| 429 | } |
| 430 | |
| 431 | |
| 432 | |
| 433 | // We can detect a new target |
| 434 | // Make sure it is on the list. |
| 435 | // Function returns TRUE on success or FALSE on error |
| 436 | int Submarinecxx . . $ Submarine#::Add_Targetcxx . . $ Submarine#Add_Target(fc20a4b472e56652).(Submarinecxx . . $ Submarine# *new_sub, float signal_strength) |
| 437 | { |
| 438 | int add_contact, found = FALSEcxx . . $ `src/map.h:13:9`!; |
| 439 | Targetcxx . . $ Target# *my_target, *new_target, *last_target = NULLcxx . . $ `<external>/15298297234472979974/stddef.h:416:9`!; |
| 440 | |
| 441 | if (signal_strength == 2.0) |
| 442 | add_contact = CONTACT_WEAKcxx . . $ `src/submarine.h:48:9`!; |
| 443 | else if (signal_strength == 1.0) |
| 444 | add_contact = CONTACT_WEAKcxx . . $ `src/submarine.h:48:9`!; |
| 445 | else if (signal_strength == CONTACT_PINGcxx . . $ `src/submarine.h:49:9`!) |
| 446 | add_contact = CONTACT_WEAKcxx . . $ `src/submarine.h:48:9`!; |
| 447 | else |
| 448 | add_contact = 1; |
| 449 | |
| 450 | // check to see if target is already in the list |
| 451 | my_target = targetscxx . . $ Submarine#targets.; |
| 452 | while ( (my_target) && (! found) ) |
| 453 | { |
| 454 | if (my_target->subcxx . . $ $anonymous_type_8e0798e5786ef39c_0#sub. == new_sub) |
| 455 | found = TRUEcxx . . $ `src/map.h:10:9`!; |
| 456 | else |
| 457 | { |
| 458 | last_target = my_target; |
| 459 | my_target = (Targetcxx . . $ Target# *) my_target->nextcxx . . $ $anonymous_type_8e0798e5786ef39c_0#next.; |
| 460 | } |
| 461 | } // end of looking for existing target |
| 462 | |
| 463 | if (found) |
| 464 | { |
| 465 | if ( (signal_strength == CONTACT_PINGcxx . . $ `src/submarine.h:49:9`!) && |
| 466 | (my_target->contact_strengthcxx . . $ $anonymous_type_8e0798e5786ef39c_0#contact_strength. < CONTACT_WEAKcxx . . $ `src/submarine.h:48:9`!) ) |
| 467 | my_target->contact_strengthcxx . . $ $anonymous_type_8e0798e5786ef39c_0#contact_strength. = CONTACT_WEAKcxx . . $ `src/submarine.h:48:9`! + 2; |
| 468 | else if (signal_strength == CONTACT_PINGcxx . . $ `src/submarine.h:49:9`!) |
| 469 | my_target->contact_strengthcxx . . $ $anonymous_type_8e0798e5786ef39c_0#contact_strength. = my_target->contact_strengthcxx . . $ $anonymous_type_8e0798e5786ef39c_0#contact_strength.; |
| 470 | else if ( (add_contact == CONTACT_WEAKcxx . . $ `src/submarine.h:48:9`!) && |
| 471 | (my_target->contact_strengthcxx . . $ $anonymous_type_8e0798e5786ef39c_0#contact_strength. >= CONTACT_WEAKcxx . . $ `src/submarine.h:48:9`!) ) |
| 472 | my_target->contact_strengthcxx . . $ $anonymous_type_8e0798e5786ef39c_0#contact_strength. = my_target->contact_strengthcxx . . $ $anonymous_type_8e0798e5786ef39c_0#contact_strength.; |
| 473 | else |
| 474 | my_target->contact_strengthcxx . . $ $anonymous_type_8e0798e5786ef39c_0#contact_strength. += add_contact; |
| 475 | |
| 476 | if (my_target->contact_strengthcxx . . $ $anonymous_type_8e0798e5786ef39c_0#contact_strength. > CONTACT_SOLIDcxx . . $ `src/submarine.h:47:9`!) |
| 477 | my_target->contact_strengthcxx . . $ $anonymous_type_8e0798e5786ef39c_0#contact_strength. = CONTACT_SOLIDcxx . . $ `src/submarine.h:47:9`!; |
| 478 | return TRUEcxx . . $ `src/map.h:10:9`!; |
| 479 | } |
| 480 | else // need new contact |
| 481 | { |
| 482 | #ifdef DEBUG |
| 483 | printf("Adding new target\n"); |
| 484 | #endif |
| 485 | new_target = (Targetcxx . . $ Target# *) calloc( 1, sizeof(Targetcxx . . $ Target#) ); |
| 486 | if (! new_target) |
| 487 | return FALSEcxx . . $ `src/map.h:13:9`!; |
| 488 | new_target->subcxx . . $ $anonymous_type_8e0798e5786ef39c_0#sub. = new_sub; |
| 489 | new_target->contact_strengthcxx . . $ $anonymous_type_8e0798e5786ef39c_0#contact_strength. = add_contact; |
| 490 | new_target->nextcxx . . $ $anonymous_type_8e0798e5786ef39c_0#next. = NULLcxx . . $ `<external>/15298297234472979974/stddef.h:416:9`!; // not needed, but let's be careful |
| 491 | if (last_target) |
| 492 | last_target->nextcxx . . $ $anonymous_type_8e0798e5786ef39c_0#next. = new_target; |
| 493 | else |
| 494 | targetscxx . . $ Submarine#targets. = new_target; |
| 495 | } |
| 496 | return TRUEcxx . . $ `src/map.h:10:9`!; |
| 497 | } |
| 498 | |
| 499 | |
| 500 | |
| 501 | // Find and reduce a target from the list |
| 502 | void Submarinecxx . . $ Submarine#::Remove_Targetcxx . . $ Submarine#Remove_Target(a9ab5cc9dc811b12).(Submarinecxx . . $ Submarine# *old_sub) |
| 503 | { |
| 504 | int found = FALSEcxx . . $ `src/map.h:13:9`!; |
| 505 | Targetcxx . . $ Target# *my_target; |
| 506 | |
| 507 | my_target = targetscxx . . $ Submarine#targets.; |
| 508 | while ( (! found) && (my_target) ) |
| 509 | { |
| 510 | if (my_target->subcxx . . $ $anonymous_type_8e0798e5786ef39c_0#sub. == old_sub) |
| 511 | { |
| 512 | if (my_target->contact_strengthcxx . . $ $anonymous_type_8e0798e5786ef39c_0#contact_strength. < 1) |
| 513 | Cancel_Targetcxx . . $ Submarine#Cancel_Target(a9ab5cc9dc811b12).(old_sub); |
| 514 | else |
| 515 | my_target->contact_strengthcxx . . $ $anonymous_type_8e0798e5786ef39c_0#contact_strength. -= 2; |
| 516 | found = TRUEcxx . . $ `src/map.h:10:9`!; |
| 517 | } |
| 518 | else |
| 519 | my_target = (Targetcxx . . $ Target# *)my_target->nextcxx . . $ $anonymous_type_8e0798e5786ef39c_0#next.; |
| 520 | } |
| 521 | } |
| 522 | |
| 523 | // Find and completely remove a target from the list |
| 524 | void Submarinecxx . . $ Submarine#::Cancel_Targetcxx . . $ Submarine#Cancel_Target(a9ab5cc9dc811b12).(Submarinecxx . . $ Submarine# *old_sub) |
| 525 | { |
| 526 | int found = FALSEcxx . . $ `src/map.h:13:9`!; |
| 527 | Targetcxx . . $ Target# *my_target, *previous = NULLcxx . . $ `<external>/15298297234472979974/stddef.h:416:9`!; |
| 528 | |
| 529 | #ifdef DEBUG |
| 530 | printf("Removing target we can't hear.\n"); |
| 531 | #endif |
| 532 | my_target = targetscxx . . $ Submarine#targets.; |
| 533 | while ( (!found) && (my_target) ) |
| 534 | { |
| 535 | if (my_target->subcxx . . $ $anonymous_type_8e0798e5786ef39c_0#sub. == old_sub) |
| 536 | { |
| 537 | if (previous) |
| 538 | previous->nextcxx . . $ $anonymous_type_8e0798e5786ef39c_0#next. = my_target->nextcxx . . $ $anonymous_type_8e0798e5786ef39c_0#next.; |
| 539 | else // first item in the list |
| 540 | targetscxx . . $ Submarine#targets. = (Targetcxx . . $ Target# *) my_target->nextcxx . . $ $anonymous_type_8e0798e5786ef39c_0#next.; |
| 541 | |
| 542 | my_target->nextcxx . . $ $anonymous_type_8e0798e5786ef39c_0#next. = NULLcxx . . $ `<external>/15298297234472979974/stddef.h:416:9`!; |
| 543 | if (my_target == last_targetcxx . . $ Submarine#last_target.) |
| 544 | last_targetcxx . . $ Submarine#last_target. = NULLcxx . . $ `<external>/15298297234472979974/stddef.h:416:9`!; |
| 545 | free(my_target); |
| 546 | found = TRUEcxx . . $ `src/map.h:10:9`!; |
| 547 | } |
| 548 | else |
| 549 | { |
| 550 | previous = my_target; |
| 551 | my_target = (Targetcxx . . $ Target# *)my_target->nextcxx . . $ $anonymous_type_8e0798e5786ef39c_0#next.; |
| 552 | } |
| 553 | } |
| 554 | } |
| 555 | |
| 556 | |
| 557 | |
| 558 | |
| 559 | // This function will let us know if a ship is on our target list |
| 560 | // Returns the signal strength if the ship exists or FALSE if it does not. |
| 561 | int Submarinecxx . . $ Submarine#::Can_Detectcxx . . $ Submarine#Can_Detect(e898ed6f8282e8).(Submarinecxx . . $ Submarine# *a_sub) |
| 562 | { |
| 563 | int found = FALSEcxx . . $ `src/map.h:13:9`!; |
| 564 | Targetcxx . . $ Target# *my_target; |
| 565 | |
| 566 | my_target = (Targetcxx . . $ Target# *)targetscxx . . $ Submarine#targets.; |
| 567 | while ( (my_target) && (! found) ) |
| 568 | { |
| 569 | if (my_target->subcxx . . $ $anonymous_type_8e0798e5786ef39c_0#sub. == a_sub) |
| 570 | found = TRUEcxx . . $ `src/map.h:10:9`!; |
| 571 | else |
| 572 | my_target = (Targetcxx . . $ Target# *)my_target->nextcxx . . $ $anonymous_type_8e0798e5786ef39c_0#next.; |
| 573 | } |
| 574 | if (found) |
| 575 | return my_target->contact_strengthcxx . . $ $anonymous_type_8e0798e5786ef39c_0#contact_strength.; |
| 576 | else |
| 577 | return FALSEcxx . . $ `src/map.h:13:9`!; |
| 578 | } |
| 579 | |
| 580 | |
| 581 | |
| 582 | |
| 583 | // Find the next available target. Return the target |
| 584 | // pointer or NULL if no target is found |
| 585 | /* |
| 586 | Submarine *Submarine::Next_Target() |
| 587 | { |
| 588 | Target *original = last_target; |
| 589 | Target *my_target; |
| 590 | |
| 591 | if (! targets) |
| 592 | { |
| 593 | last_target = NULL; |
| 594 | return NULL; // no possible targets |
| 595 | } |
| 596 | if (! original) // nothing selected before, return first item |
| 597 | { |
| 598 | last_target = targets; |
| 599 | return (Submarine *)last_target->sub; |
| 600 | } |
| 601 | |
| 602 | my_target = (Target *) original->next; |
| 603 | if (my_target) |
| 604 | { |
| 605 | last_target = my_target; |
| 606 | return (Submarine *)last_target->sub; |
| 607 | } |
| 608 | else |
| 609 | { |
| 610 | last_target = targets; |
| 611 | return (Submarine *)last_target->sub; |
| 612 | } |
| 613 | } |
| 614 | */ |
| 615 | Submarinecxx . . $ Submarine# *Submarinecxx . . $ Submarine#::Next_Targetcxx . . $ Submarine#Next_Target(5a8a75acd7038d8b).() |
| 616 | { |
| 617 | Targetcxx . . $ Target# *original = NULLcxx . . $ `<external>/15298297234472979974/stddef.h:416:9`!; |
| 618 | Targetcxx . . $ Target# *my_target; |
| 619 | int found = FALSEcxx . . $ `src/map.h:13:9`!; |
| 620 | |
| 621 | // no possible targets to return |
| 622 | if (! targetscxx . . $ Submarine#targets.) |
| 623 | { |
| 624 | last_targetcxx . . $ Submarine#last_target. = NULLcxx . . $ `<external>/15298297234472979974/stddef.h:416:9`!; |
| 625 | return NULLcxx . . $ `<external>/15298297234472979974/stddef.h:416:9`!; |
| 626 | } |
| 627 | |
| 628 | if (! last_targetcxx . . $ Submarine#last_target.) |
| 629 | { |
| 630 | last_targetcxx . . $ Submarine#last_target. = targetscxx . . $ Submarine#targets.; |
| 631 | my_target = last_targetcxx . . $ Submarine#last_target.; |
| 632 | } |
| 633 | else // we used to have a target |
| 634 | { |
| 635 | my_target = (Targetcxx . . $ Target# *) last_targetcxx . . $ Submarine#last_target.->nextcxx . . $ $anonymous_type_8e0798e5786ef39c_0#next.; |
| 636 | if (! my_target) |
| 637 | my_target = targetscxx . . $ Submarine#targets.; |
| 638 | } |
| 639 | |
| 640 | // starting from the last target, try to find something |
| 641 | // we can use |
| 642 | while ( (! found) && (my_target != original) ) |
| 643 | { |
| 644 | #ifdef DEBUG |
| 645 | printf("Testing signal strength: %d\n", my_target->contact_strength); |
| 646 | #endif |
| 647 | if (my_target->contact_strengthcxx . . $ $anonymous_type_8e0798e5786ef39c_0#contact_strength. >= CONTACT_WEAKcxx . . $ `src/submarine.h:48:9`!) |
| 648 | found = TRUEcxx . . $ `src/map.h:10:9`!; |
| 649 | else |
| 650 | { |
| 651 | if (! original) |
| 652 | original = my_target; |
| 653 | my_target = (Targetcxx . . $ Target# *) my_target->nextcxx . . $ $anonymous_type_8e0798e5786ef39c_0#next.; |
| 654 | if (! my_target) |
| 655 | my_target = targetscxx . . $ Submarine#targets.; |
| 656 | } |
| 657 | |
| 658 | } |
| 659 | |
| 660 | if (found) |
| 661 | { |
| 662 | #ifdef DEBUG |
| 663 | printf("Returning new target.\n"); |
| 664 | #endif |
| 665 | last_targetcxx . . $ Submarine#last_target. = my_target; |
| 666 | return (Submarinecxx . . $ Submarine# *) my_target->subcxx . . $ $anonymous_type_8e0798e5786ef39c_0#sub.; |
| 667 | } |
| 668 | else |
| 669 | { |
| 670 | #ifdef DEBUG |
| 671 | printf("No target found.\n"); |
| 672 | #endif |
| 673 | last_targetcxx . . $ Submarine#last_target. = targetscxx . . $ Submarine#targets.; |
| 674 | return NULLcxx . . $ `<external>/15298297234472979974/stddef.h:416:9`!; |
| 675 | } |
| 676 | } |
| 677 | |
| 678 | |
| 679 | |
| 680 | // This function should be called right after the ship is created. It |
| 681 | // will load the ship's class specific information from the appropriate |
| 682 | // data file. |
| 683 | // The data file's format will be |
| 684 | // maxspeed maxdepth name rudder torpedoes-carried hull_strength has_sonar, PSCS class-name class-type |
| 685 | int Submarinecxx . . $ Submarine#::Load_Classcxx . . $ Submarine#Load_Class(1ef8e6ec083aabb9).(char *my_file) |
| 686 | { |
| 687 | // confirm file exists |
| 688 | if (! my_file) |
| 689 | return FALSEcxx . . $ `src/map.h:13:9`!; |
| 690 | ifstreamcxx . . $ std/ifstream# infilecxx . . $ std/basic_ifstream#basic_ifstream(b8cd37071ce335df).(my_file, ioscxx . . $ std/ios#::incxx . . $ std/ios_base#in.); |
| 691 | if (!cxx . . $ std/basic_ios#`operator!`(50ce9a9e25b4a850). infile) |
| 692 | return FALSEcxx . . $ `src/map.h:13:9`!; |
| 693 | |
| 694 | // load data |
| 695 | infile >>cxx . . $ std/basic_istream#`operator>>`(c6dc588c561376de). MaxSpeedcxx . . $ Submarine#MaxSpeed. >>cxx . . $ std/basic_istream#`operator>>`(c6dc588c561376de). MaxDepthcxx . . $ Submarine#MaxDepth. >>cxx . . $ std/basic_istream#`operator>>`(c6dc588c561376de). Ruddercxx . . $ Submarine#Rudder. >>cxx . . $ std/basic_istream#`operator>>`(c6dc588c561376de). TorpedosOnBoardcxx . . $ Submarine#TorpedosOnBoard. >>cxx . . $ std/basic_istream#`operator>>`(c6dc588c561376de). hull_strengthcxx . . $ Submarine#hull_strength. >>cxx . . $ std/basic_istream#`operator>>`(c6dc588c561376de). has_sonarcxx . . $ Submarine#has_sonar. >>cxx . . $ std/basic_istream#`operator>>`(fd405bafd6c8cbb1). PSCScxx . . $ Submarine#PSCS. >>cxx . . $ std/`operator>>`(253f7f7fc5afae9f). ClassNamecxx . . $ Submarine#ClassName. >>cxx . . $ std/`operator>>`(253f7f7fc5afae9f). ClassTypecxx . . $ Submarine#ClassType.; |
| 696 | infile.closecxx . . $ std/basic_ifstream#close(49f6e7a06ebc5aa8).(); |
| 697 | // if we carry torpedoes, we also carry noisemakers |
| 698 | NoiseMakerscxx . . $ Submarine#NoiseMakers. = TorpedosOnBoardcxx . . $ Submarine#TorpedosOnBoard. / 2; |
| 699 | return TRUEcxx . . $ `src/map.h:10:9`!; |
| 700 | } |
| 701 | |
| 702 | |
| 703 | // This function tries to load a single line from the passed file |
| 704 | // and translates the contents to the ship's mission. |
| 705 | // The function returns TRUE on success and FALSE if an |
| 706 | // error occurs. |
| 707 | int Submarinecxx . . $ Submarine#::Load_Missioncxx . . $ Submarine#Load_Mission(89bc1efcdac0ca22).(FILEcxx . . $ FILE# *from_file) |
| 708 | { |
| 709 | char line[256]; |
| 710 | char *status; |
| 711 | |
| 712 | if (! from_file) |
| 713 | return FALSEcxx . . $ `src/map.h:13:9`!; |
| 714 | |
| 715 | memset(line, '\0', 256); |
| 716 | status = fgets(line, 256, from_file); |
| 717 | if (status) |
| 718 | { |
| 719 | #ifndef WIN32 |
| 720 | if (! strncasecmp(line, "sink", 4) ) |
| 721 | mission_statuscxx . . $ Submarine#mission_status. = MISSION_SINKcxx . . $ `src/submarine.h:109:9`!; |
| 722 | else if (! strncasecmp(line, "find", 4) ) |
| 723 | mission_statuscxx . . $ Submarine#mission_status. = MISSION_FINDcxx . . $ `src/submarine.h:110:9`!; |
| 724 | else if (! strncasecmp(line, "alive", 5) ) |
| 725 | mission_statuscxx . . $ Submarine#mission_status. = MISSION_ALIVEcxx . . $ `src/submarine.h:111:9`!; |
| 726 | else |
| 727 | mission_statuscxx . . $ Submarine#mission_status. = MISSION_NONEcxx . . $ `src/submarine.h:108:9`!; |
| 728 | #else |
| 729 | if (! my_strncasecmp(line, "sink", 4) ) |
| 730 | mission_status = MISSION_SINK; |
| 731 | else if (! my_strncasecmp(line, "find", 4) ) |
| 732 | mission_status = MISSION_FIND; |
| 733 | else if (! my_strncasecmp(line, "alive", 5) ) |
| 734 | mission_status = MISSION_ALIVE; |
| 735 | else |
| 736 | mission_status = MISSION_NONE; |
| 737 | #endif |
| 738 | |
| 739 | if (mission_statuscxx . . $ Submarine#mission_status. == MISSION_ALIVEcxx . . $ `src/submarine.h:111:9`!) |
| 740 | sscanf( &(line[6]), "%d", &mission_timercxx . . $ Submarine#mission_timer.); |
| 741 | } |
| 742 | else // could not read line, default to none |
| 743 | mission_statuscxx . . $ Submarine#mission_status. = MISSION_NONEcxx . . $ `src/submarine.h:108:9`!; |
| 744 | |
| 745 | return TRUEcxx . . $ `src/map.h:10:9`!; |
| 746 | } |
| 747 | |
| 748 | |
| 749 | |
| 750 | |
| 751 | // This function will attempt to manipulate a torpedo tube. We can |
| 752 | // load a torpedo into a tube, load a noisemaker, empty a tube or |
| 753 | // fire the contents of the tube. |
| 754 | // The function returns a status number based on what happened or |
| 755 | // did not happen. |
| 756 | int Submarinecxx . . $ Submarine#::Use_Tubecxx . . $ Submarine#Use_Tube(9b79fb6aee4c0440).(int action, int tube_number) |
| 757 | { |
| 758 | if ( (tube_number < 0) || (tube_number >= MAX_TUBEScxx . . $ `src/submarine.h:68:9`!) ) |
| 759 | return TUBE_ERROR_NUMBERcxx . . $ `src/submarine.h:82:9`!; |
| 760 | |
| 761 | switch (action) |
| 762 | { |
| 763 | case LOAD_TORPEDOcxx . . $ `src/submarine.h:76:17`!: |
| 764 | if (TorpedosOnBoardcxx . . $ Submarine#TorpedosOnBoard. <= 0) |
| 765 | return TUBE_ERROR_NO_TORPEDOcxx . . $ `src/submarine.h:85:9`!; |
| 766 | |
| 767 | if (torpedo_tubecxx . . $ Submarine#torpedo_tube.[tube_number] == TUBE_EMPTYcxx . . $ `src/submarine.h:69:9`!) |
| 768 | { |
| 769 | torpedo_tubecxx . . $ Submarine#torpedo_tube.[tube_number] = TUBE_TORPEDOcxx . . $ `src/submarine.h:70:9`!; |
| 770 | TorpedosOnBoardcxx . . $ Submarine#TorpedosOnBoard.--; |
| 771 | return TUBE_ERROR_TORPEDO_SUCCESScxx . . $ `src/submarine.h:87:9`!; |
| 772 | } |
| 773 | else |
| 774 | return TUBE_ERROR_FULLcxx . . $ `src/submarine.h:83:9`!; |
| 775 | break; |
| 776 | case LOAD_NOISEMAKERcxx . . $ `src/submarine.h:77:17`!: |
| 777 | if (NoiseMakerscxx . . $ Submarine#NoiseMakers. <= 0) |
| 778 | return TUBE_ERROR_NO_NOISEcxx . . $ `src/submarine.h:86:9`!; |
| 779 | if (torpedo_tubecxx . . $ Submarine#torpedo_tube.[tube_number] == TUBE_EMPTYcxx . . $ `src/submarine.h:69:9`!) |
| 780 | { |
| 781 | torpedo_tubecxx . . $ Submarine#torpedo_tube.[tube_number] = TUBE_NOISEMAKERcxx . . $ `src/submarine.h:71:9`!; |
| 782 | NoiseMakerscxx . . $ Submarine#NoiseMakers.--; |
| 783 | return TUBE_ERROR_NOISEMAKER_SUCCESScxx . . $ `src/submarine.h:88:9`!; |
| 784 | } |
| 785 | else |
| 786 | return TUBE_ERROR_FULLcxx . . $ `src/submarine.h:83:9`!; |
| 787 | break; |
| 788 | case UNLOAD_TUBEcxx . . $ `src/submarine.h:78:17`!: |
| 789 | if (torpedo_tubecxx . . $ Submarine#torpedo_tube.[tube_number] == TUBE_TORPEDOcxx . . $ `src/submarine.h:70:9`!) |
| 790 | TorpedosOnBoardcxx . . $ Submarine#TorpedosOnBoard.++; |
| 791 | else if (torpedo_tubecxx . . $ Submarine#torpedo_tube.[tube_number] == TUBE_NOISEMAKERcxx . . $ `src/submarine.h:71:9`!) |
| 792 | NoiseMakerscxx . . $ Submarine#NoiseMakers.++; |
| 793 | torpedo_tubecxx . . $ Submarine#torpedo_tube.[tube_number] = TUBE_EMPTYcxx . . $ `src/submarine.h:69:9`!; |
| 794 | return TUBE_ERROR_UNLOAD_SUCCESScxx . . $ `src/submarine.h:89:9`!; |
| 795 | case FIRE_TUBEcxx . . $ `src/submarine.h:79:17`!: |
| 796 | if (torpedo_tubecxx . . $ Submarine#torpedo_tube.[tube_number] == TUBE_EMPTYcxx . . $ `src/submarine.h:69:9`!) |
| 797 | return TUBE_ERROR_FIRE_FAILcxx . . $ `src/submarine.h:90:9`!; |
| 798 | else if (torpedo_tubecxx . . $ Submarine#torpedo_tube.[tube_number] == TUBE_TORPEDOcxx . . $ `src/submarine.h:70:9`!) |
| 799 | { |
| 800 | torpedo_tubecxx . . $ Submarine#torpedo_tube.[tube_number] = TUBE_EMPTYcxx . . $ `src/submarine.h:69:9`!; |
| 801 | return TUBE_ERROR_FIRE_SUCCESScxx . . $ `src/submarine.h:91:9`!; |
| 802 | } |
| 803 | else if (torpedo_tubecxx . . $ Submarine#torpedo_tube.[tube_number] == TUBE_NOISEMAKERcxx . . $ `src/submarine.h:71:9`!) |
| 804 | { |
| 805 | torpedo_tubecxx . . $ Submarine#torpedo_tube.[tube_number] = TUBE_EMPTYcxx . . $ `src/submarine.h:69:9`!; |
| 806 | return TUBE_ERROR_FIRE_NOISEMAKERcxx . . $ `src/submarine.h:92:9`!; |
| 807 | } |
| 808 | break; |
| 809 | |
| 810 | default: |
| 811 | return TUBE_ERROR_ACTIONcxx . . $ `src/submarine.h:84:9`!; |
| 812 | } |
| 813 | |
| 814 | return TRUEcxx . . $ `src/map.h:10:9`!; // this shouldn't happen, but just in case |
| 815 | } |
| 816 | |
| 817 | |
| 818 | |
| 819 | |
| 820 | // This function launches a torpedo or noise maker. If the |
| 821 | // passed target is NULL, the new torp/noisemaker is given a |
| 822 | // random course and no target, leaving it to run in a striaght line. |
| 823 | // On success the function passes back a pointer to the new torpedo |
| 824 | // and on failure NULL is returned. |
| 825 | Submarinecxx . . $ Submarine# *Submarinecxx . . $ Submarine#::Fire_Tubecxx . . $ Submarine#Fire_Tube(7e9c5f383c561fca).(Submarinecxx . . $ Submarine# *target, char *ship_file) |
| 826 | { |
| 827 | Submarinecxx . . $ Submarine# *my_torp; |
| 828 | my_torp = new Submarinecxx . . $ Submarine#(); |
| 829 | if (! my_torp) |
| 830 | return NULLcxx . . $ `<external>/15298297234472979974/stddef.h:416:9`!; |
| 831 | |
| 832 | my_torp->Load_Classcxx . . $ Submarine#Load_Class(1ef8e6ec083aabb9).(ship_file); |
| 833 | if (target) |
| 834 | { |
| 835 | my_torp->targetcxx . . $ Submarine#target. = target; |
| 836 | // set heading and desired depth |
| 837 | my_torp->DesiredHeadingcxx . . $ Submarine#DesiredHeading. = my_torp->Headingcxx . . $ Coord#Heading. = BearingToTargetcxx . . $ Submarine#BearingToTarget(2de0d0e522051339).(target); |
| 838 | my_torp->DesiredDepthcxx . . $ Submarine#DesiredDepth. = target->Depthcxx . . $ Submarine#Depth.; |
| 839 | my_torp->ShipTypecxx . . $ Submarine#ShipType. = TYPE_TORPEDOcxx . . $ `src/submarine.h:38:9`!; |
| 840 | } |
| 841 | else // no target, noisemaker |
| 842 | { |
| 843 | my_torp->targetcxx . . $ Submarine#target. = NULLcxx . . $ `<external>/15298297234472979974/stddef.h:416:9`!; |
| 844 | // set random heading |
| 845 | my_torp->Headingcxx . . $ Coord#Heading. = rand() % 360; |
| 846 | my_torp->DesiredHeadingcxx . . $ Submarine#DesiredHeading. = my_torp->Headingcxx . . $ Coord#Heading.; |
| 847 | my_torp->ShipTypecxx . . $ Submarine#ShipType. = TYPE_NOISEMAKERcxx . . $ `src/submarine.h:39:9`!; |
| 848 | } |
| 849 | // set current position |
| 850 | my_torp->Lat_TotalYardscxx . . $ Coord#Lat_TotalYards. = Lat_TotalYardscxx . . $ Coord#Lat_TotalYards.; |
| 851 | my_torp->Lon_TotalYardscxx . . $ Coord#Lon_TotalYards. = Lon_TotalYardscxx . . $ Coord#Lon_TotalYards.; |
| 852 | // set fuel |
| 853 | my_torp->fuel_remainingcxx . . $ Submarine#fuel_remaining. = TORPEDO_FUELcxx . . $ `src/submarine.h:94:9`!; |
| 854 | // set depth |
| 855 | my_torp->Depthcxx . . $ Submarine#Depth. = Depthcxx . . $ Submarine#Depth.; |
| 856 | // set speed and desired speed |
| 857 | my_torp->Speedcxx . . $ Coord#Speed. = Speedcxx . . $ Coord#Speed.; |
| 858 | my_torp->DesiredSpeedcxx . . $ Submarine#DesiredSpeed. = my_torp->MaxSpeedcxx . . $ Submarine#MaxSpeed.; |
| 859 | // my_torp->ShipType = TYPE_TORPEDO; |
| 860 | // my_torp->Friend = FOE; |
| 861 | my_torp->Friendcxx . . $ Submarine#Friend. = Friendcxx . . $ Submarine#Friend.; |
| 862 | my_torp->origin_xcxx . . $ Submarine#origin_x. = Lat_TotalYardscxx . . $ Coord#Lat_TotalYards.; |
| 863 | my_torp->origin_ycxx . . $ Submarine#origin_y. = Lon_TotalYardscxx . . $ Coord#Lon_TotalYards.; |
| 864 | return my_torp; |
| 865 | } |
| 866 | |
| 867 | |
| 868 | |
| 869 | // This function lets us know if we can hear another ship/sub/ |
| 870 | // It returns TRUE if we can hear it and FALSE if we can not. |
| 871 | int Submarinecxx . . $ Submarine#::Can_Hearcxx . . $ Submarine#Can_Hear(e898ed6f8282e8).(Submarinecxx . . $ Submarine# *target) |
| 872 | { |
| 873 | float Range = DistanceToTargetcxx . . $ Submarine#DistanceToTarget(2de0d0e522051339).(target); |
| 874 | float NauticalMiles = (float)Range / 2000.0; |
| 875 | float HisPassiveSonarCrosssection = target->PSCScxx . . $ Submarine#PSCS.; |
| 876 | float EffectiveTargetSpeed; |
| 877 | float AmbientNoise; |
| 878 | float OwnShipNoise; |
| 879 | float TotalNoise; |
| 880 | float TargetNoise; |
| 881 | float Gb; |
| 882 | float Lbp; |
| 883 | float NoiseFromSpeed; |
| 884 | float BasisNoiseLevel; |
| 885 | float value; |
| 886 | float SeaState = 3.0; // Anyone want to model the weather. |
| 887 | float minimum_sound = -45.0; |
| 888 | int thermal_layers = 0; |
| 889 | |
| 890 | // sanity check |
| 891 | if (! target) |
| 892 | return FALSEcxx . . $ `src/map.h:13:9`!; |
| 893 | |
| 894 | /* There is a special case here. If the listener is a surface |
| 895 | ship then they have radar. Thus the listener can always |
| 896 | detect anything on or above the surface. |
| 897 | */ |
| 898 | if (ShipTypecxx . . $ Submarine#ShipType. == TYPE_SHIPcxx . . $ `src/submarine.h:36:9`!) |
| 899 | { |
| 900 | if (target->Depthcxx . . $ Submarine#Depth. <= 0) |
| 901 | return TRUEcxx . . $ `src/map.h:10:9`!; |
| 902 | if (target->using_radarcxx . . $ Submarine#using_radar.) |
| 903 | return TRUEcxx . . $ `src/map.h:10:9`!; |
| 904 | } |
| 905 | |
| 906 | if (ShipTypecxx . . $ Submarine#ShipType. == TYPE_TORPEDOcxx . . $ `src/submarine.h:38:9`!) |
| 907 | minimum_sound *= 2.5; |
| 908 | else if (ShipTypecxx . . $ Submarine#ShipType. == TYPE_SHIPcxx . . $ `src/submarine.h:36:9`!) |
| 909 | minimum_sound *= 1.75; |
| 910 | |
| 911 | if (target->Speedcxx . . $ Coord#Speed. <= 5.0){ |
| 912 | EffectiveTargetSpeed = 0.0; |
| 913 | }else{ |
| 914 | EffectiveTargetSpeed = target->Speedcxx . . $ Coord#Speed. - 5.0; |
| 915 | } |
| 916 | |
| 917 | if (target->Speedcxx . . $ Coord#Speed. < 20.0){ |
| 918 | NoiseFromSpeed = 1.30; |
| 919 | BasisNoiseLevel = 0.0; |
| 920 | }else{ |
| 921 | NoiseFromSpeed = 0.65; |
| 922 | BasisNoiseLevel = 9.75; |
| 923 | } |
| 924 | // check just in case we didn't set the map variable |
| 925 | if (mapcxx . . $ Submarine#map.) |
| 926 | { |
| 927 | thermal_layers = mapcxx . . $ Submarine#map.->Thermals_Betweencxx . . $ MAP#Thermals_Between(9b79fb6aee4c0440).(Depthcxx . . $ Submarine#Depth., target->Depthcxx . . $ Submarine#Depth.); |
| 928 | #ifdef DEBUGMAP |
| 929 | printf("%d thermals between ship and target\n", thermal_layers); |
| 930 | #endif |
| 931 | } |
| 932 | AmbientNoise = 89.0 + (5.0 * SeaState); |
| 933 | OwnShipNoise = RadiatedNoisecxx . . $ Submarine#RadiatedNoise(9b8c9e39889c762c).(); |
| 934 | TotalNoise = 10.0 * log10cxx . . $ log10(fee4f1d22bc8e617).(powcxx . . $ pow(b71928d39fde4295).(10.0,OwnShipNoise/10.0) + powcxx . . $ pow(b71928d39fde4295).(10.0,AmbientNoise/10.0)); |
| 935 | Gb = (TotalNoise - AmbientNoise) / 2.9; |
| 936 | Lbp = AmbientNoise + Gb; |
| 937 | TargetNoise = HisPassiveSonarCrosssection + |
| 938 | ((NoiseFromSpeed * EffectiveTargetSpeed) + BasisNoiseLevel); |
| 939 | if (target->pingingcxx . . $ Submarine#pinging.) |
| 940 | TargetNoise += PING_NOISEcxx . . $ `src/submarine.h:50:9`!; |
| 941 | if (thermal_layers) |
| 942 | TargetNoise -= TargetNoise * (thermal_layers * THERMAL_FILTERcxx . . $ `src/map.h:20:9`!); |
| 943 | value = TargetNoise - (20.0 * log10cxx . . $ log10(fbcf3211dfe1bfd1).(NauticalMiles) + 1.1 * NauticalMiles) - Lbp; |
| 944 | // if (!observer) |
| 945 | // SonarStation.flowandambientnoise = (Lbp - 34); |
| 946 | if (value > minimum_sound){ |
| 947 | return TRUEcxx . . $ `src/map.h:10:9`!; |
| 948 | }else{ |
| 949 | return FALSEcxx . . $ `src/map.h:13:9`!; |
| 950 | } |
| 951 | |
| 952 | } |
| 953 | |
| 954 | |
| 955 | |
| 956 | |
| 957 | // This function will simply return if we do not have a target. |
| 958 | // If we do have a target, and we can hear it, this will adjust the |
| 959 | // torpedo's desired heading and desired depth to match the target. |
| 960 | // The function returns TRUE. |
| 961 | int Submarinecxx . . $ Submarine#::Torpedo_AIcxx . . $ Submarine#Torpedo_AI(e898ed6f8282e8).(Submarinecxx . . $ Submarine# *all_subs) |
| 962 | { |
| 963 | int can_hear_target = FALSEcxx . . $ `src/map.h:13:9`!; |
| 964 | Submarinecxx . . $ Submarine# *my_sub; |
| 965 | |
| 966 | // if (! target) |
| 967 | // return TRUE; |
| 968 | // Noisemakers should run at full speed in a straight line |
| 969 | if (ShipTypecxx . . $ Submarine#ShipType. == TYPE_NOISEMAKERcxx . . $ `src/submarine.h:39:9`!) |
| 970 | return TRUEcxx . . $ `src/map.h:10:9`!; |
| 971 | |
| 972 | // check to see if we can hear the target |
| 973 | if (targetcxx . . $ Submarine#target.) |
| 974 | can_hear_target = Can_Hearcxx . . $ Submarine#Can_Hear(e898ed6f8282e8).(targetcxx . . $ Submarine#target.); |
| 975 | // aim for our target if we have one |
| 976 | if (can_hear_target) |
| 977 | { |
| 978 | DesiredHeadingcxx . . $ Submarine#DesiredHeading. = BearingToTargetcxx . . $ Submarine#BearingToTarget(2de0d0e522051339).(targetcxx . . $ Submarine#target.); |
| 979 | DesiredDepthcxx . . $ Submarine#DesiredDepth. = targetcxx . . $ Submarine#target.->Depthcxx . . $ Submarine#Depth.; |
| 980 | DesiredSpeedcxx . . $ Submarine#DesiredSpeed. = MaxSpeedcxx . . $ Submarine#MaxSpeed.; |
| 981 | return TRUEcxx . . $ `src/map.h:10:9`!; |
| 982 | } |
| 983 | |
| 984 | // when we delevop active sonar, that should go here |
| 985 | // as a backup to passive sonar |
| 986 | |
| 987 | // we cannot hear our target, see if we can detect a new one |
| 988 | targetcxx . . $ Submarine#target. = NULLcxx . . $ `<external>/15298297234472979974/stddef.h:416:9`!; |
| 989 | my_sub = all_subs; |
| 990 | while ( (my_sub) && (! targetcxx . . $ Submarine#target.) ) |
| 991 | { |
| 992 | // aim for the first thing we hear |
| 993 | if ( (my_sub->Friendcxx . . $ Submarine#Friend. != Friendcxx . . $ Submarine#Friend.) && ( Can_Hearcxx . . $ Submarine#Can_Hear(e898ed6f8282e8).(my_sub) ) ) |
| 994 | targetcxx . . $ Submarine#target. = my_sub; |
| 995 | else |
| 996 | my_sub = my_sub->nextcxx . . $ Submarine#next.; |
| 997 | } |
| 998 | |
| 999 | // what if we can't hear any target, go into search mode |
| 1000 | if (! targetcxx . . $ Submarine#target.) |
| 1001 | { |
| 1002 | DesiredHeadingcxx . . $ Submarine#DesiredHeading. = Headingcxx . . $ Coord#Heading. + 90; |
| 1003 | DesiredSpeedcxx . . $ Submarine#DesiredSpeed. = MaxSpeedcxx . . $ Submarine#MaxSpeed. / 2; |
| 1004 | } |
| 1005 | return TRUEcxx . . $ `src/map.h:10:9`!; |
| 1006 | } |
| 1007 | |
| 1008 | |
| 1009 | |
| 1010 | // This function tells us what AI ships and submarines will do. |
| 1011 | // This function returns a link to all torpedoes. |
| 1012 | Submarinecxx . . $ Submarine# *Submarinecxx . . $ Submarine#::Sub_AIcxx . . $ Submarine#Sub_AI(3be2d61bc00ebf6b).(Submarinecxx . . $ Submarine# *all_ships, Submarinecxx . . $ Submarine# *all_torpedoes, void *helicopters) |
| 1013 | { |
| 1014 | int change; |
| 1015 | Submarinecxx . . $ Submarine# *torpedo; |
| 1016 | int can_hear_torpedo; |
| 1017 | double distance; |
| 1018 | int bearing; |
| 1019 | Submarinecxx . . $ Submarine# *target = NULLcxx . . $ `<external>/15298297234472979974/stddef.h:416:9`!, *my_torpedoes; |
| 1020 | int status, found; |
| 1021 | int action = 0; // 1 = running, 2 = chasing |
| 1022 | Submarinecxx . . $ Submarine# *track_torpedo = NULLcxx . . $ `<external>/15298297234472979974/stddef.h:416:9`!; |
| 1023 | |
| 1024 | // most important thing we can do is run away from torpedoes |
| 1025 | if (has_sonarcxx . . $ Submarine#has_sonar.) |
| 1026 | { |
| 1027 | #ifdef AIDEBUG |
| 1028 | printf("We have sonar.\n"); |
| 1029 | #endif |
| 1030 | // go through all torpedoes and see if any of them |
| 1031 | // chasing us |
| 1032 | torpedo = all_torpedoes; |
| 1033 | status = FALSEcxx . . $ `src/map.h:13:9`!; // make sure we only run away form one torpedo |
| 1034 | while ( (torpedo) && (! status) ) |
| 1035 | { |
| 1036 | if (torpedo->ShipTypecxx . . $ Submarine#ShipType. == TYPE_TORPEDOcxx . . $ `src/submarine.h:38:9`!) |
| 1037 | { |
| 1038 | can_hear_torpedo = Can_Hearcxx . . $ Submarine#Can_Hear(e898ed6f8282e8).(torpedo); |
| 1039 | distance = DistanceToTargetcxx . . $ Submarine#DistanceToTarget(2de0d0e522051339).(torpedo); |
| 1040 | // if we can hear a torpedo, it is close and it is aimed at us |
| 1041 | // then we run |
| 1042 | if ( (can_hear_torpedo) && (torpedo->targetcxx . . $ Submarine#target. == this) && |
| 1043 | (distance < (MAX_TORPEDO_RANGEcxx . . $ `src/submarine.h:120:9`! * MILES_TO_YARDScxx . . $ `src/submarine.h:114:9`!) ) ) |
| 1044 | { |
| 1045 | // status = (DesiredSpeed == MaxSpeed); |
| 1046 | all_torpedoes = Launch_Noisemakercxx . . $ Submarine#Launch_Noisemaker(d62bab4205bed956).(all_torpedoes, torpedo); |
| 1047 | bearing = (int) BearingToTargetcxx . . $ Submarine#BearingToTarget(2de0d0e522051339).(torpedo); |
| 1048 | bearing += 180; |
| 1049 | if (bearing >= 360) |
| 1050 | bearing = bearing % 360; |
| 1051 | DesiredHeadingcxx . . $ Submarine#DesiredHeading. = bearing; |
| 1052 | DesiredSpeedcxx . . $ Submarine#DesiredSpeed. = MaxSpeedcxx . . $ Submarine#MaxSpeed.; |
| 1053 | // subs can dive too |
| 1054 | if (ShipTypecxx . . $ Submarine#ShipType. == TYPE_SUBcxx . . $ `src/submarine.h:35:9`!) |
| 1055 | { |
| 1056 | if (torpedo->Depthcxx . . $ Submarine#Depth. <= Depthcxx . . $ Submarine#Depth.) // it is above us |
| 1057 | DesiredDepthcxx . . $ Submarine#DesiredDepth. = MaxDepthcxx . . $ Submarine#MaxDepth.; |
| 1058 | else if (torpedo->Depthcxx . . $ Submarine#Depth. > Depthcxx . . $ Submarine#Depth.) // below us |
| 1059 | DesiredDepthcxx . . $ Submarine#DesiredDepth. = PERISCOPE_DEPTHcxx . . $ `src/submarine.h:115:9`!; |
| 1060 | } |
| 1061 | if (moodcxx . . $ Submarine#mood. == MOOD_CONVOYcxx . . $ `src/submarine.h:129:9`!) |
| 1062 | moodcxx . . $ Submarine#mood. = MOOD_PASSIVEcxx . . $ `src/submarine.h:128:9`!; |
| 1063 | // if (! status) |
| 1064 | // return all_torpedoes; |
| 1065 | action = 1; // running |
| 1066 | status = TRUEcxx . . $ `src/map.h:10:9`!; |
| 1067 | } |
| 1068 | // we hear a torpedo but it is not coming after us |
| 1069 | else if ( (can_hear_torpedo) && (TorpedosOnBoardcxx . . $ Submarine#TorpedosOnBoard.) ) |
| 1070 | { |
| 1071 | if (ShipTypecxx . . $ Submarine#ShipType. == TYPE_SHIPcxx . . $ `src/submarine.h:36:9`!) |
| 1072 | moodcxx . . $ Submarine#mood. = MOOD_ATTACKcxx . . $ `src/submarine.h:127:9`!; |
| 1073 | // if we are not tracking anything, check out the torp |
| 1074 | if ( (! track_torpedo) && (torpedo->Friendcxx . . $ Submarine#Friend. != Friendcxx . . $ Submarine#Friend.) ) |
| 1075 | { |
| 1076 | #ifdef AIDEBUG |
| 1077 | printf("Found torpedo to track.\n"); |
| 1078 | #endif |
| 1079 | track_torpedo = torpedo; |
| 1080 | } |
| 1081 | } |
| 1082 | |
| 1083 | if ( (can_hear_torpedo) && (ShipTypecxx . . $ Submarine#ShipType. == TYPE_SHIPcxx . . $ `src/submarine.h:36:9`!) ) |
| 1084 | Radio_Signalcxx . . $ Submarine#Radio_Signal(8e102eb2bbf433ac).(all_ships, RADIO_HEAR_TORPEDOcxx . . $ `src/submarine.h:136:9`!); |
| 1085 | |
| 1086 | } // end of this is a torpedo |
| 1087 | torpedo = torpedo->nextcxx . . $ Submarine#next.; |
| 1088 | } // end of checking out torpedoes in the water |
| 1089 | |
| 1090 | #ifdef AIDEBUG |
| 1091 | printf("Checking for targets.\n"); |
| 1092 | #endif |
| 1093 | // see if we can hear a nearby enemy to shoot at |
| 1094 | target = Have_Enemy_Targetcxx . . $ Submarine#Have_Enemy_Target(9c4f5e11a658b20d).(all_ships); |
| 1095 | #ifdef AIDEBUG |
| 1096 | if (target) printf("Found enemy.\n"); |
| 1097 | #endif |
| 1098 | int count = Count_Torpedoescxx . . $ Submarine#Count_Torpedoes(e898ed6f8282e8).(all_torpedoes); |
| 1099 | if ( (target) && (TorpedosOnBoardcxx . . $ Submarine#TorpedosOnBoard. > 0) ) |
| 1100 | // (count < MAX_TORPEDOES_FIRED) ) |
| 1101 | { |
| 1102 | int target_range = DistanceToTargetcxx . . $ Submarine#DistanceToTarget(2de0d0e522051339).(target); |
| 1103 | int shooting_range; |
| 1104 | // we shoot at different distances, depending on mood |
| 1105 | if (moodcxx . . $ Submarine#mood. == MOOD_ATTACKcxx . . $ `src/submarine.h:127:9`!) |
| 1106 | shooting_range = TORPEDO_RANGE_ATTACKcxx . . $ `src/submarine.h:121:9`!; |
| 1107 | else |
| 1108 | shooting_range = TORPEDO_RANGE_PASSIVEcxx . . $ `src/submarine.h:122:9`!; |
| 1109 | shooting_range += (rand() % 3) - 2; // add some randomness |
| 1110 | target_range *= YARDS_TO_MILEScxx . . $ `src/submarine.h:113:9`!; |
| 1111 | #ifdef AIDEBUG |
| 1112 | printf("Checking range %d\n", target_range); |
| 1113 | #endif |
| 1114 | if ( (count < MAX_TORPEDOES_FIREDcxx . . $ `src/submarine.h:117:9`!) && |
| 1115 | (target_range < shooting_range) ) |
| 1116 | { |
| 1117 | #ifdef AIDEBUG |
| 1118 | printf("Firing with %d torpedoes.\n", count); |
| 1119 | #endif |
| 1120 | torpedo_tubecxx . . $ Submarine#torpedo_tube.[0] = TUBE_TORPEDOcxx . . $ `src/submarine.h:70:9`!; |
| 1121 | status = Use_Tubecxx . . $ Submarine#Use_Tube(9b79fb6aee4c0440).(FIRE_TUBEcxx . . $ `src/submarine.h:79:17`!, 0); |
| 1122 | if (status == TUBE_ERROR_FIRE_SUCCESScxx . . $ `src/submarine.h:91:9`!) |
| 1123 | { |
| 1124 | char *ship_file, filename[] = "ships/class5.shp"; |
| 1125 | ship_file = Find_Data_Filecxx . . $ Find_Data_File(7a9722d75b371431).(filename); |
| 1126 | torpedo = Fire_Tubecxx . . $ Submarine#Fire_Tube(7e9c5f383c561fca).(target, ship_file ); |
| 1127 | if ( (ship_file) && (ship_file != filename) ) |
| 1128 | free(ship_file); |
| 1129 | if (torpedo) |
| 1130 | { |
| 1131 | #ifdef AIDEBUG |
| 1132 | printf("Successfully fired torpedo.\n"); |
| 1133 | #endif |
| 1134 | torpedo->Friendcxx . . $ Submarine#Friend. = Friendcxx . . $ Submarine#Friend.; |
| 1135 | torpedo->ownercxx . . $ Submarine#owner. = this; |
| 1136 | // all_torpedoes = Add_Ship(all_torpedoes, torpedo); |
| 1137 | // add torpedo to linked list |
| 1138 | if (! all_torpedoes) |
| 1139 | all_torpedoes = torpedo; |
| 1140 | else |
| 1141 | { |
| 1142 | my_torpedoes = all_torpedoes; |
| 1143 | found = FALSEcxx . . $ `src/map.h:13:9`!; |
| 1144 | while ( (! found) && (my_torpedoes) ) |
| 1145 | { |
| 1146 | if (my_torpedoes->nextcxx . . $ Submarine#next.) |
| 1147 | my_torpedoes = my_torpedoes->nextcxx . . $ Submarine#next.; |
| 1148 | else |
| 1149 | { |
| 1150 | my_torpedoes->nextcxx . . $ Submarine#next. = torpedo; |
| 1151 | found = TRUEcxx . . $ `src/map.h:10:9`!; |
| 1152 | // return all_torpedoes; |
| 1153 | } |
| 1154 | } |
| 1155 | } // add torpedo to list |
| 1156 | } |
| 1157 | TorpedosOnBoardcxx . . $ Submarine#TorpedosOnBoard.--; |
| 1158 | #ifdef AIDEBUG |
| 1159 | printf("I have %d torpedoes left.\n", TorpedosOnBoard); |
| 1160 | #endif |
| 1161 | return all_torpedoes; |
| 1162 | } // torpedo firing was successful |
| 1163 | } // can fire torpedo at target in range |
| 1164 | |
| 1165 | // we hear an enemy, but can't fire yet |
| 1166 | else if ( (moodcxx . . $ Submarine#mood. == MOOD_ATTACKcxx . . $ `src/submarine.h:127:9`!) && (! action) ) |
| 1167 | { |
| 1168 | DesiredHeadingcxx . . $ Submarine#DesiredHeading. = BearingToTargetcxx . . $ Submarine#BearingToTarget(2de0d0e522051339).(target); |
| 1169 | if (ShipTypecxx . . $ Submarine#ShipType. == TYPE_SHIPcxx . . $ `src/submarine.h:36:9`!) |
| 1170 | DesiredSpeedcxx . . $ Submarine#DesiredSpeed. = (MaxSpeedcxx . . $ Submarine#MaxSpeed. / 2) + (rand() % 5) - 2; |
| 1171 | else // sub |
| 1172 | DesiredSpeedcxx . . $ Submarine#DesiredSpeed. = (MaxSpeedcxx . . $ Submarine#MaxSpeed. / 3) + (rand() % 3) + 1; |
| 1173 | if (ShipTypecxx . . $ Submarine#ShipType. == TYPE_SUBcxx . . $ `src/submarine.h:35:9`!) |
| 1174 | { |
| 1175 | DesiredDepthcxx . . $ Submarine#DesiredDepth. = target->Depthcxx . . $ Submarine#Depth.; |
| 1176 | if (DesiredDepthcxx . . $ Submarine#DesiredDepth. < PERISCOPE_DEPTHcxx . . $ `src/submarine.h:115:9`!) |
| 1177 | DesiredDepthcxx . . $ Submarine#DesiredDepth. = PERISCOPE_DEPTHcxx . . $ `src/submarine.h:115:9`!; |
| 1178 | } |
| 1179 | action = 2; |
| 1180 | } |
| 1181 | } // end of we have a target and we have torpedoes on board |
| 1182 | |
| 1183 | // we are not tracking anything, but we have torpedoes |
| 1184 | // and we can hear a torpedo |
| 1185 | // move toward the origin of the torpedo we hear |
| 1186 | else if ( (TorpedosOnBoardcxx . . $ Submarine#TorpedosOnBoard. > 0) && (track_torpedo) && (!action) ) |
| 1187 | { |
| 1188 | #ifdef AIDEBUG |
| 1189 | printf("We hear a torpedo, tracking it.\n"); |
| 1190 | printf("We should probably only chase torpedoes if in attack mood\n"); |
| 1191 | #endif |
| 1192 | DesiredHeadingcxx . . $ Submarine#DesiredHeading. = BearingToOrigincxx . . $ Submarine#BearingToOrigin(2de0d0e522051339).(track_torpedo); |
| 1193 | if (ShipTypecxx . . $ Submarine#ShipType. == TYPE_SUBcxx . . $ `src/submarine.h:35:9`!) |
| 1194 | DesiredDepthcxx . . $ Submarine#DesiredDepth. = track_torpedo->Depthcxx . . $ Submarine#Depth.; |
| 1195 | } |
| 1196 | // We have no target and no torpedo to follow |
| 1197 | // if we are in attack mood we should slow down |
| 1198 | // so we can hear better |
| 1199 | else if ( (! action) && (!target) && (moodcxx . . $ Submarine#mood. == MOOD_ATTACKcxx . . $ `src/submarine.h:127:9`!) ) |
| 1200 | { |
| 1201 | DesiredSpeedcxx . . $ Submarine#DesiredSpeed. = (MaxSpeedcxx . . $ Submarine#MaxSpeed. / 3) + ( ( rand() % 5 ) - 3 ); |
| 1202 | } |
| 1203 | |
| 1204 | |
| 1205 | // if we got this far we cannot hear a torpedo coming at us |
| 1206 | if ( (Speedcxx . . $ Coord#Speed. == MaxSpeedcxx . . $ Submarine#MaxSpeed.) && (! action) ) |
| 1207 | DesiredSpeedcxx . . $ Submarine#DesiredSpeed. = MaxSpeedcxx . . $ Submarine#MaxSpeed. / 3; |
| 1208 | } // I think this is the end of "we have sonar" section |
| 1209 | |
| 1210 | // helicopters should go low if there are helicopters |
| 1211 | if ( (ShipTypecxx . . $ Submarine#ShipType. == TYPE_SUBcxx . . $ `src/submarine.h:35:9`!) && (helicopters) ) |
| 1212 | { |
| 1213 | if (Depthcxx . . $ Submarine#Depth. < mapcxx . . $ Submarine#map.->thermalscxx . . $ MAP#thermals.[0]) |
| 1214 | DesiredDepthcxx . . $ Submarine#DesiredDepth. = mapcxx . . $ Submarine#map.->thermalscxx . . $ MAP#thermals.[0] + 25; |
| 1215 | } |
| 1216 | |
| 1217 | // when traveling in convoy, we change course once every |
| 1218 | // ... twenty minutes? |
| 1219 | if (moodcxx . . $ Submarine#mood. == MOOD_CONVOYcxx . . $ `src/submarine.h:129:9`!) |
| 1220 | { |
| 1221 | convoy_course_changecxx . . $ Submarine#convoy_course_change.--; |
| 1222 | if (! convoy_course_changecxx . . $ Submarine#convoy_course_change.) |
| 1223 | { |
| 1224 | convoy_course_changecxx . . $ Submarine#convoy_course_change. = CONVOY_CHANGE_COURSEcxx . . $ `src/submarine.h:131:9`!; |
| 1225 | DesiredHeadingcxx . . $ Submarine#DesiredHeading. += 90; |
| 1226 | if (DesiredHeadingcxx . . $ Submarine#DesiredHeading. >= 360) |
| 1227 | DesiredHeadingcxx . . $ Submarine#DesiredHeading. = DesiredHeadingcxx . . $ Submarine#DesiredHeading. % 360; |
| 1228 | } |
| 1229 | } |
| 1230 | else // got nothing to do, but perhaps change course |
| 1231 | { |
| 1232 | change = rand() % CHANCE_COURSEcxx . . $ `src/submarine.h:104:9`!; |
| 1233 | if (! change) |
| 1234 | { |
| 1235 | DesiredHeadingcxx . . $ Submarine#DesiredHeading. = Headingcxx . . $ Coord#Heading. + ( (rand() % 100) - 90); |
| 1236 | if (DesiredHeadingcxx . . $ Submarine#DesiredHeading. >= 360) |
| 1237 | DesiredHeadingcxx . . $ Submarine#DesiredHeading. = DesiredHeadingcxx . . $ Submarine#DesiredHeading. % 360; |
| 1238 | DesiredSpeedcxx . . $ Submarine#DesiredSpeed. = MaxSpeedcxx . . $ Submarine#MaxSpeed. / 3; |
| 1239 | // submarines should change depth too |
| 1240 | if (ShipTypecxx . . $ Submarine#ShipType. == TYPE_SUBcxx . . $ `src/submarine.h:35:9`!) |
| 1241 | { |
| 1242 | DesiredDepthcxx . . $ Submarine#DesiredDepth. =+ rand() % 200; |
| 1243 | DesiredDepthcxx . . $ Submarine#DesiredDepth. /= 2; |
| 1244 | DesiredDepthcxx . . $ Submarine#DesiredDepth. += PERISCOPE_DEPTHcxx . . $ `src/submarine.h:115:9`!; |
| 1245 | // DesiredDepth = ( (rand() % MaxDepth) / 2 ) + 50; |
| 1246 | } |
| 1247 | } |
| 1248 | } |
| 1249 | |
| 1250 | // check for radio message |
| 1251 | if ( (ShipTypecxx . . $ Submarine#ShipType. == TYPE_SHIPcxx . . $ `src/submarine.h:36:9`!) && (radio_messagecxx . . $ Submarine#radio_message.) ) |
| 1252 | { |
| 1253 | if ( (radio_messagecxx . . $ Submarine#radio_message. == RADIO_UNDER_ATTACKcxx . . $ `src/submarine.h:135:9`!) && (moodcxx . . $ Submarine#mood. == MOOD_CONVOYcxx . . $ `src/submarine.h:129:9`!) ) |
| 1254 | { |
| 1255 | if (TorpedosOnBoardcxx . . $ Submarine#TorpedosOnBoard.) |
| 1256 | moodcxx . . $ Submarine#mood. = MOOD_ATTACKcxx . . $ `src/submarine.h:127:9`!; |
| 1257 | else |
| 1258 | { |
| 1259 | moodcxx . . $ Submarine#mood. = MOOD_PASSIVEcxx . . $ `src/submarine.h:128:9`!; |
| 1260 | DesiredHeadingcxx . . $ Submarine#DesiredHeading. = rand() % 360; |
| 1261 | } |
| 1262 | DesiredSpeedcxx . . $ Submarine#DesiredSpeed. = MaxSpeedcxx . . $ Submarine#MaxSpeed.; |
| 1263 | } |
| 1264 | else if ( (radio_messagecxx . . $ Submarine#radio_message. == RADIO_HEAR_TORPEDOcxx . . $ `src/submarine.h:136:9`!) && (moodcxx . . $ Submarine#mood. == MOOD_CONVOYcxx . . $ `src/submarine.h:129:9`!) ) |
| 1265 | { |
| 1266 | if (TorpedosOnBoardcxx . . $ Submarine#TorpedosOnBoard.) |
| 1267 | moodcxx . . $ Submarine#mood. = MOOD_ATTACKcxx . . $ `src/submarine.h:127:9`!; |
| 1268 | else |
| 1269 | moodcxx . . $ Submarine#mood. = MOOD_PASSIVEcxx . . $ `src/submarine.h:128:9`!; |
| 1270 | } |
| 1271 | } |
| 1272 | radio_messagecxx . . $ Submarine#radio_message. = RADIO_NONEcxx . . $ `src/submarine.h:134:9`!; |
| 1273 | if ( (ShipTypecxx . . $ Submarine#ShipType. == TYPE_SUBcxx . . $ `src/submarine.h:35:9`!) && (Depthcxx . . $ Submarine#Depth. < PERISCOPE_DEPTHcxx . . $ `src/submarine.h:115:9`!) ) |
| 1274 | DesiredDepthcxx . . $ Submarine#DesiredDepth. = PERISCOPE_DEPTHcxx . . $ `src/submarine.h:115:9`!; |
| 1275 | return all_torpedoes; |
| 1276 | } // end of Sub_AI |
| 1277 | |
| 1278 | |
| 1279 | |
| 1280 | |
| 1281 | // This function checks on our torpedo to see how it |
| 1282 | // is doing. If it has hit its target, we return HIT_TARGET. |
| 1283 | // If we run out of fuel, we return OUT_OF_FUEL. Otherwise |
| 1284 | // we return STATUS_OK. |
| 1285 | // This function just checks status changes, it doesn't do |
| 1286 | // anything about them. |
| 1287 | int Submarinecxx . . $ Submarine#::Check_Statuscxx . . $ Submarine#Check_Status(b126dc7c1de90089).() |
| 1288 | { |
| 1289 | double range; |
| 1290 | double delta_depth; |
| 1291 | |
| 1292 | // first see if we ran out of fuel |
| 1293 | fuel_remainingcxx . . $ Submarine#fuel_remaining.--; |
| 1294 | if (fuel_remainingcxx . . $ Submarine#fuel_remaining. < 1) |
| 1295 | return OUT_OF_FUELcxx . . $ `src/submarine.h:97:9`!; |
| 1296 | |
| 1297 | if (targetcxx . . $ Submarine#target.) |
| 1298 | { |
| 1299 | range = DistanceToTargetcxx . . $ Submarine#DistanceToTarget(2de0d0e522051339).(targetcxx . . $ Submarine#target.); |
| 1300 | delta_depth = fabscxx . . $ fabs(fbcf3211dfe1bfd1).(targetcxx . . $ Submarine#target.->Depthcxx . . $ Submarine#Depth. - Depthcxx . . $ Submarine#Depth.); |
| 1301 | if ( (range < HITTING_RANGEcxx . . $ `src/submarine.h:95:9`!) && (delta_depth < HITTING_DEPTHcxx . . $ `src/submarine.h:96:9`!) ) |
| 1302 | { |
| 1303 | char *full_path, *explosion = "sounds/explosion.ogg"; |
| 1304 | full_path = Find_Data_Filecxx . . $ Find_Data_File(7a9722d75b371431).(explosion); |
| 1305 | Play_Soundcxx . . $ Play_Sound(1ef8e6ec083aabb9).(full_path); |
| 1306 | if ( (full_path) && (explosion) ) |
| 1307 | free(full_path); |
| 1308 | |
| 1309 | return HIT_TARGETcxx . . $ `src/submarine.h:98:9`!; |
| 1310 | } |
| 1311 | } |
| 1312 | |
| 1313 | return STATUS_OKcxx . . $ `src/submarine.h:99:9`!; |
| 1314 | } |
| 1315 | |
| 1316 | |
| 1317 | |
| 1318 | // This function reduces the remaining strength of the ship's hull. |
| 1319 | // If the ship/sub can still float, we return DAMAGE_OK, but if |
| 1320 | // the ship is sinking, we return DAMAGE_SINK. |
| 1321 | // If the ship sinks, we set Active to FALSE. |
| 1322 | int Submarinecxx . . $ Submarine#::Take_Damagecxx . . $ Submarine#Take_Damage(b126dc7c1de90089).() |
| 1323 | { |
| 1324 | hull_strengthcxx . . $ Submarine#hull_strength.--; |
| 1325 | if (hull_strengthcxx . . $ Submarine#hull_strength. < 1) |
| 1326 | { |
| 1327 | Activecxx . . $ Submarine#Active. = FALSEcxx . . $ `src/map.h:13:9`!; |
| 1328 | return DAMAGE_SINKcxx . . $ `src/submarine.h:102:9`!; |
| 1329 | } |
| 1330 | else |
| 1331 | return DAMAGE_OKcxx . . $ `src/submarine.h:101:9`!; |
| 1332 | } |
| 1333 | |
| 1334 | |
| 1335 | |
| 1336 | // This function counts how many torpedoes we have active |
| 1337 | // in the water (that we fired). |
| 1338 | int Submarinecxx . . $ Submarine#::Count_Torpedoescxx . . $ Submarine#Count_Torpedoes(e898ed6f8282e8).(Submarinecxx . . $ Submarine# *all_torp) |
| 1339 | { |
| 1340 | int count = 0; |
| 1341 | Submarinecxx . . $ Submarine# *torp = all_torp; |
| 1342 | |
| 1343 | while (torp) |
| 1344 | { |
| 1345 | if ( (torp->ownercxx . . $ Submarine#owner. == this) && (torp->ShipTypecxx . . $ Submarine#ShipType. == TYPE_TORPEDOcxx . . $ `src/submarine.h:38:9`!) ) |
| 1346 | count++; |
| 1347 | torp = torp->nextcxx . . $ Submarine#next.; |
| 1348 | } |
| 1349 | #ifdef DEBUG |
| 1350 | printf("We have %d TORPEDOES in the water\n", count); |
| 1351 | #endif |
| 1352 | return count; |
| 1353 | } |
| 1354 | |
| 1355 | |
| 1356 | // This function counts how many noisemakers we have in the water |
| 1357 | int Submarinecxx . . $ Submarine#::Count_Noisemakerscxx . . $ Submarine#Count_Noisemakers(e898ed6f8282e8).(Submarinecxx . . $ Submarine# *all_noise) |
| 1358 | { |
| 1359 | int count = 0; |
| 1360 | Submarinecxx . . $ Submarine# *noise = all_noise; |
| 1361 | |
| 1362 | while (noise) |
| 1363 | { |
| 1364 | if ( (noise->ownercxx . . $ Submarine#owner. == this) && (noise->ShipTypecxx . . $ Submarine#ShipType. == TYPE_NOISEMAKERcxx . . $ `src/submarine.h:39:9`!) ) |
| 1365 | count++; |
| 1366 | noise = noise->nextcxx . . $ Submarine#next.; |
| 1367 | } |
| 1368 | #ifdef DEBUG |
| 1369 | printf("We have %d NOISEMAKERS in the water\n", count); |
| 1370 | #endif |
| 1371 | return count; |
| 1372 | } |
| 1373 | |
| 1374 | |
| 1375 | |
| 1376 | // This function checks the list of ships to see if we have any enemies |
| 1377 | // to shoot at. |
| 1378 | // To get results, we must have torpedoes on board, |
| 1379 | // We must be able to hear them clearly. |
| 1380 | // They must be an enemy (Friend must be opposite of our FOE or FRIEND). |
| 1381 | // In the case of multiple matches, the closest target is returned. |
| 1382 | Submarinecxx . . $ Submarine# *Submarinecxx . . $ Submarine#::Have_Enemy_Targetcxx . . $ Submarine#Have_Enemy_Target(9c4f5e11a658b20d).(Submarinecxx . . $ Submarine# *all_ships) |
| 1383 | { |
| 1384 | Submarinecxx . . $ Submarine# *current, *min = NULLcxx . . $ `<external>/15298297234472979974/stddef.h:416:9`!; |
| 1385 | int current_distance, min_distance = INT_MAXcxx . . $ `<external>/67164224788392828/limits.h:120:9`!; |
| 1386 | int making_noise; |
| 1387 | |
| 1388 | // can we shoot? |
| 1389 | if (TorpedosOnBoardcxx . . $ Submarine#TorpedosOnBoard. < 1) |
| 1390 | return NULLcxx . . $ `<external>/15298297234472979974/stddef.h:416:9`!; |
| 1391 | // do we even have enemies? |
| 1392 | if ( (Friendcxx . . $ Submarine#Friend. != FRIENDcxx . . $ `src/submarine.h:42:9`!) && (Friendcxx . . $ Submarine#Friend. != FOEcxx . . $ `src/submarine.h:43:9`!) ) |
| 1393 | return NULLcxx . . $ `<external>/15298297234472979974/stddef.h:416:9`!; |
| 1394 | |
| 1395 | current = all_ships; |
| 1396 | while (current) |
| 1397 | { |
| 1398 | if ( ( (current->Friendcxx . . $ Submarine#Friend. == FOEcxx . . $ `src/submarine.h:43:9`!) && (Friendcxx . . $ Submarine#Friend. == FRIENDcxx . . $ `src/submarine.h:42:9`!) ) || |
| 1399 | ( (current->Friendcxx . . $ Submarine#Friend. == FRIENDcxx . . $ `src/submarine.h:42:9`!) && (Friendcxx . . $ Submarine#Friend. == FOEcxx . . $ `src/submarine.h:43:9`!) ) ) |
| 1400 | { |
| 1401 | #ifdef AIDEBUG |
| 1402 | printf("Examining enemy ship.\n"); |
| 1403 | #endif |
| 1404 | // we do not like this ship, are they closer than our current min? |
| 1405 | current_distance = DistanceToTargetcxx . . $ Submarine#DistanceToTarget(2de0d0e522051339).(current); |
| 1406 | if (current_distance < min_distance) |
| 1407 | { |
| 1408 | #ifdef AIDEBUG |
| 1409 | printf("Within range to become target.\n"); |
| 1410 | #endif |
| 1411 | // they are close, can we hear them? |
| 1412 | making_noise = Can_Hearcxx . . $ Submarine#Can_Hear(e898ed6f8282e8).(current); |
| 1413 | if (making_noise) |
| 1414 | { |
| 1415 | #ifdef AIDEBUG |
| 1416 | printf("We can hear this ship. Make it the target.\n"); |
| 1417 | #endif |
| 1418 | min = current; |
| 1419 | min_distance = current_distance; |
| 1420 | // if the target is hostile and pinging, and |
| 1421 | // we are in a convoy, switch to attack mood |
| 1422 | if ( (current->pingingcxx . . $ Submarine#pinging.) && (moodcxx . . $ Submarine#mood. == MOOD_CONVOYcxx . . $ `src/submarine.h:129:9`!) ) |
| 1423 | moodcxx . . $ Submarine#mood. = MOOD_ATTACKcxx . . $ `src/submarine.h:127:9`!; |
| 1424 | |
| 1425 | } |
| 1426 | } |
| 1427 | } |
| 1428 | current = current->nextcxx . . $ Submarine#next.; |
| 1429 | } |
| 1430 | return min; |
| 1431 | } |
| 1432 | |
| 1433 | |
| 1434 | |
| 1435 | |
| 1436 | // This function is only to be used by the AI. Here we assume |
| 1437 | // we are being chased by a torpedo. We check to see how many |
| 1438 | // noisemakers we have in the water. If it is less than the max |
| 1439 | // number, we launch a noisemaker. |
| 1440 | // This function returns a pointer to all torpedoes/noisemakers |
| 1441 | Submarinecxx . . $ Submarine# *Submarinecxx . . $ Submarine#::Launch_Noisemakercxx . . $ Submarine#Launch_Noisemaker(d62bab4205bed956).(Submarinecxx . . $ Submarine# *all_noisemakers, Submarinecxx . . $ Submarine# *chased_by) |
| 1442 | { |
| 1443 | int existing_noisemakers; |
| 1444 | Submarinecxx . . $ Submarine# *new_noisemaker = NULLcxx . . $ `<external>/15298297234472979974/stddef.h:416:9`!, *my_noise; |
| 1445 | int status, found; |
| 1446 | |
| 1447 | if ( (! chased_by) || (! all_noisemakers) ) |
| 1448 | return NULLcxx . . $ `<external>/15298297234472979974/stddef.h:416:9`!; // shouldn't happen, but just in case |
| 1449 | |
| 1450 | // do we have a noisemaker? |
| 1451 | if (NoiseMakerscxx . . $ Submarine#NoiseMakers. < 1) |
| 1452 | return all_noisemakers; |
| 1453 | |
| 1454 | // see if we are allowed to fire any more |
| 1455 | existing_noisemakers = Count_Noisemakerscxx . . $ Submarine#Count_Noisemakers(e898ed6f8282e8).(all_noisemakers); |
| 1456 | if (existing_noisemakers >= MAX_NOISEMAKERS_FIREDcxx . . $ `src/submarine.h:118:9`!) |
| 1457 | return all_noisemakers; |
| 1458 | |
| 1459 | // we are allowd to launch one |
| 1460 | torpedo_tubecxx . . $ Submarine#torpedo_tube.[0] = TUBE_NOISEMAKERcxx . . $ `src/submarine.h:71:9`!; |
| 1461 | status = Use_Tubecxx . . $ Submarine#Use_Tube(9b79fb6aee4c0440).(FIRE_TUBEcxx . . $ `src/submarine.h:79:17`!, 0); |
| 1462 | if (status == TUBE_ERROR_FIRE_NOISEMAKERcxx . . $ `src/submarine.h:92:9`!) |
| 1463 | { |
| 1464 | char *ship_file, filename[] = "ships/class6.shp"; |
| 1465 | ship_file = Find_Data_Filecxx . . $ Find_Data_File(7a9722d75b371431).(filename); |
| 1466 | new_noisemaker = Fire_Tubecxx . . $ Submarine#Fire_Tube(7e9c5f383c561fca).(NULLcxx . . $ `<external>/15298297234472979974/stddef.h:416:9`!, ship_file ); |
| 1467 | if ( (ship_file) && (ship_file != filename) ) |
| 1468 | free(ship_file); |
| 1469 | if (new_noisemaker) |
| 1470 | { |
| 1471 | new_noisemaker->Friendcxx . . $ Submarine#Friend. = Friendcxx . . $ Submarine#Friend.; |
| 1472 | new_noisemaker->ownercxx . . $ Submarine#owner. = this; |
| 1473 | if (! all_noisemakers) |
| 1474 | all_noisemakers = new_noisemaker; |
| 1475 | else |
| 1476 | { |
| 1477 | my_noise = all_noisemakers; |
| 1478 | found = FALSEcxx . . $ `src/map.h:13:9`!; |
| 1479 | while ( (!found) && (my_noise) ) |
| 1480 | { |
| 1481 | if (my_noise->nextcxx . . $ Submarine#next.) |
| 1482 | my_noise = my_noise->nextcxx . . $ Submarine#next.; |
| 1483 | else |
| 1484 | { |
| 1485 | my_noise->nextcxx . . $ Submarine#next. = new_noisemaker; |
| 1486 | found = TRUEcxx . . $ `src/map.h:10:9`!; |
| 1487 | // return all_noisemakers; |
| 1488 | } |
| 1489 | } |
| 1490 | } // end of add noisemaker to list |
| 1491 | } // created new noisemaker |
| 1492 | } // status |
| 1493 | NoiseMakerscxx . . $ Submarine#NoiseMakers.--; |
| 1494 | if (new_noisemaker) |
| 1495 | { |
| 1496 | new_noisemaker->DesiredHeadingcxx . . $ Submarine#DesiredHeading. = chased_by->DesiredHeadingcxx . . $ Submarine#DesiredHeading.; |
| 1497 | chased_by->Is_Distracted_By_Noisemakercxx . . $ Submarine#Is_Distracted_By_Noisemaker(e898ed6f8282e8).(new_noisemaker); |
| 1498 | } |
| 1499 | return all_noisemakers; |
| 1500 | } |
| 1501 | |
| 1502 | |
| 1503 | |
| 1504 | |
| 1505 | // This function checks to see if the torpedo will get distracted |
| 1506 | // by a given noisemaker |
| 1507 | // Returns TRUE if distracted and FALSE if not. In the case where |
| 1508 | // the torpedo is distracted, its target variable is reset |
| 1509 | // to chase the noisemaker |
| 1510 | int Submarinecxx . . $ Submarine#::Is_Distracted_By_Noisemakercxx . . $ Submarine#Is_Distracted_By_Noisemaker(e898ed6f8282e8).(Submarinecxx . . $ Submarine# *noisemaker) |
| 1511 | { |
| 1512 | int chance; |
| 1513 | |
| 1514 | if (! noisemaker) // this should not happen, but just in case |
| 1515 | return FALSEcxx . . $ `src/map.h:13:9`!; |
| 1516 | |
| 1517 | chance = rand() % DISTRACTED_CHANCEcxx . . $ `src/submarine.h:124:9`!; |
| 1518 | if (! chance) |
| 1519 | { |
| 1520 | targetcxx . . $ Submarine#target. = noisemaker; |
| 1521 | return TRUEcxx . . $ `src/map.h:10:9`!; |
| 1522 | #ifdef DEBUG |
| 1523 | printf("Torpedo going off course to chase noisemaker.\n"); |
| 1524 | #endif |
| 1525 | } |
| 1526 | |
| 1527 | #ifdef DEBUG |
| 1528 | printf("Torpedo was not distracted by noisemaker.\n"); |
| 1529 | #endif |
| 1530 | return FALSEcxx . . $ `src/map.h:13:9`!; |
| 1531 | } |
| 1532 | |
| 1533 | |
| 1534 | |
| 1535 | // This function sends a radio signal to all other ships of the same |
| 1536 | // nationality. |
| 1537 | // The function returns TRUE |
| 1538 | int Submarinecxx . . $ Submarine#::Radio_Signalcxx . . $ Submarine#Radio_Signal(8e102eb2bbf433ac).(Submarinecxx . . $ Submarine# *all_ships, int my_signal) |
| 1539 | { |
| 1540 | Submarinecxx . . $ Submarine# *current_ship; |
| 1541 | |
| 1542 | current_ship = all_ships; |
| 1543 | while (current_ship) |
| 1544 | { |
| 1545 | if ( (current_ship->Friendcxx . . $ Submarine#Friend. == Friendcxx . . $ Submarine#Friend.) && |
| 1546 | (current_ship->ShipTypecxx . . $ Submarine#ShipType. == TYPE_SHIPcxx . . $ `src/submarine.h:36:9`!) ) |
| 1547 | current_ship->radio_messagecxx . . $ Submarine#radio_message. = my_signal; |
| 1548 | |
| 1549 | current_ship = current_ship->nextcxx . . $ Submarine#next.; |
| 1550 | } |
| 1551 | |
| 1552 | return TRUEcxx . . $ `src/map.h:10:9`!; |
| 1553 | } |
| 1554 | |
| 1555 | |
| 1556 | // This function sends out a ping signal. We should then be |
| 1557 | // able to "see" any ships/subs in front of us. |
| 1558 | // This function does not detect aircraft (for obvious reasons) |
| 1559 | // and sets "pinging" to true, which means we will be very |
| 1560 | // noisy for a while. |
| 1561 | int Submarinecxx . . $ Submarine#::Send_Pingcxx . . $ Submarine#Send_Ping(e898ed6f8282e8).(Submarinecxx . . $ Submarine# *all_ships) |
| 1562 | { |
| 1563 | Submarinecxx . . $ Submarine# *current; |
| 1564 | int status; |
| 1565 | char *full_path, *ping_file = "sounds/sonar-ping.ogg"; |
| 1566 | // some craft do not have sonar |
| 1567 | if (! has_sonarcxx . . $ Submarine#has_sonar.) |
| 1568 | return FALSEcxx . . $ `src/map.h:13:9`!; |
| 1569 | |
| 1570 | full_path = Find_Data_Filecxx . . $ Find_Data_File(7a9722d75b371431).(ping_file); |
| 1571 | Play_Soundcxx . . $ Play_Sound(1ef8e6ec083aabb9).(full_path); |
| 1572 | if ( (full_path) && (full_path != ping_file) ) |
| 1573 | free(full_path); |
| 1574 | |
| 1575 | pingingcxx . . $ Submarine#pinging. = 2; |
| 1576 | current = all_ships; |
| 1577 | while (current) |
| 1578 | { |
| 1579 | if (current != this) |
| 1580 | { |
| 1581 | status = ! ( InBafflescxx . . $ Submarine#InBaffles(9887e4a8163b3a3f).(current, 1, NULLcxx . . $ `<external>/15298297234472979974/stddef.h:416:9`!) ); |
| 1582 | if (status) |
| 1583 | { |
| 1584 | // got return signal from ping |
| 1585 | Add_Targetcxx . . $ Submarine#Add_Target(fc20a4b472e56652).(current, CONTACT_PINGcxx . . $ `src/submarine.h:49:9`!); |
| 1586 | |
| 1587 | } |
| 1588 | } |
| 1589 | current = current->nextcxx . . $ Submarine#next.; |
| 1590 | } |
| 1591 | |
| 1592 | return TRUEcxx . . $ `src/map.h:10:9`!; |
| 1593 | } |
| 1594 | |
| 1595 | |
| 1596 | |
| 1597 | /********************************************* |
| 1598 | This function will return if a target is in |
| 1599 | the observers Baffles and therefore not |
| 1600 | detectable. Values for 'int sensor' are 1 for |
| 1601 | spherical array, 2 for towed array, 3 for port |
| 1602 | hull array and 4 for starboard hull array. |
| 1603 | |
| 1604 | Might want to move the calculations of the |
| 1605 | baffle angles to the Coord class so they don't |
| 1606 | have to be calculated all the time. |
| 1607 | *********************************************/ |
| 1608 | int Submarinecxx . . $ Submarine#::InBafflescxx . . $ Submarine#InBaffles(9887e4a8163b3a3f).(Submarinecxx . . $ Submarine# *target, int sensor, TowedArraycxx . . $ TowedArray# *TB16) |
| 1609 | { |
| 1610 | int array_heading; |
| 1611 | int relative_bearing; |
| 1612 | int sensordeaf=1; |
| 1613 | int bearing_to_target; |
| 1614 | |
| 1615 | switch(sensor){ |
| 1616 | case 1: //Spherical |
| 1617 | sensordeaf = 0; |
| 1618 | array_heading = (int)Headingcxx . . $ Coord#Heading.; |
| 1619 | bearing_to_target = (int)BearingToTargetcxx . . $ Submarine#BearingToTarget(2de0d0e522051339).( target); |
| 1620 | if(array_heading > bearing_to_target) bearing_to_target += 360; |
| 1621 | relative_bearing = bearing_to_target - array_heading; |
| 1622 | if(relative_bearing > 150 && relative_bearing < 210) sensordeaf = 1; |
| 1623 | if (target == this) sensordeaf = 1; |
| 1624 | break; |
| 1625 | case 2: //Towed |
| 1626 | if (! TB16) |
| 1627 | sensordeaf = TRUEcxx . . $ `src/map.h:10:9`!; |
| 1628 | else |
| 1629 | { |
| 1630 | sensordeaf = 0; |
| 1631 | array_heading = (int)TB16->ReturnHeadingcxx . . $ TowedArray#ReturnHeading(9b8c9e39889c762c).(); |
| 1632 | bearing_to_target = (int)TB16->BearingToTargetcxx . . $ TowedArray#BearingToTarget(b7af2f536204233).(target->Lat_TotalYardscxx . . $ Coord#Lat_TotalYards., target->Lon_TotalYardscxx . . $ Coord#Lon_TotalYards.); |
| 1633 | if(array_heading > bearing_to_target) bearing_to_target += 360; |
| 1634 | relative_bearing = bearing_to_target - array_heading; |
| 1635 | if(relative_bearing < 30 || relative_bearing > 330) sensordeaf = 1; |
| 1636 | } |
| 1637 | break; |
| 1638 | |
| 1639 | case 3: //port hull |
| 1640 | case 4: //sb hull |
| 1641 | default: |
| 1642 | break; |
| 1643 | } |
| 1644 | return sensordeaf; |
| 1645 | } |
| 1646 |