Rise
The Vieneo Province
Viewscreen.cpp
Go to the documentation of this file.
1 #include "Viewscreen.h"
2 #include "../GameClass.h"
3 #include "../Dialogs/InformationDialog.h"
4 #include "../MathUtilities.h"
5 
7 {
8  gameclass = g;
9  logger = g->logger;
10  logger->AddToCallStack("Viewscreen::ctor");
11 
12 #ifdef _DEBUG
13  cityTimer = new CStopWatch(logger);
14  instrumentsFrameMoveTimer = new CStopWatch(logger);
15  cockpitFrameMoveTimer = new CStopWatch(logger);
16  weatherFrameMoveTimer = new CStopWatch(logger);
17  modulesFrameMoveTimer = new CStopWatch(logger);
18  displaysFrameMoveTimer = new CStopWatch(logger);
19  inputFrameMoveTimer = new CStopWatch(logger);
20  weaponsFrameMoveTimer = new CStopWatch(logger);
21  propulsionFrameMoveTimer = new CStopWatch(logger);
22  otherFrameMoveTimer = new CStopWatch(logger);
23  shipTimer = new CStopWatch(logger);
24  liteTimer = new CStopWatch(logger);
25 #endif
26 
27  ptrGrid = new grid(this);
28  ptrWeapon = new weapon(this);
29  ptrBuildings = new buildings(this);
30  ptrKeyboard = new keyboard(this);
31  ptrJoystick = new joystick(this);
32  ptrFreeTrack = new FreeTrack(this);
33  ptrPropulsion = new propulsion(this);
34  ptrRenderer = new renderer(this);
35  ptrWeather = new weather(this);
36  ptrCockpit = new cockpit(this);
37  ptrInstruments = new instruments(this);
39 
40  // lateraltime = 4.0f; //Do we need to set this to a constant or something ?
41 // verticaltime = 4.0f;
42 
43  lateralmod = false;
44  verticalmod = false;
45  yawmod = false;
46  //Initialize some variables
47  pitchInput = 0.0f; rollInput = 0.0f; yawInput = 0.0f;
48  cloudpos = centerC;
49  BCLoffsetu = BCLoffsetv = 0; // for cloud animation
50  H2Ooffsetu = 0.0f; // for water animation
51 
52  position = centerC; //centerC is defined in globals.h
53  posnorml = centerC;
54 
55  lateralincr = 0.0f;
56  verticalincr = 0.0f;
57 
58  //Here comes all the initializing that happened in WinMain first
59  short t;
60 
61  flicker = 0;
62  interlace = 0.0f;
64  ourcockpit.impatientime = 0.0f;
65 
66  //Initialize all vars
67  g_pDI = nullptr; // The DirectInput interface
68 
69  m_pFont = nullptr; // A font to output text
70  m_pFontLicense = nullptr;
71  m_pFont3 = nullptr;
72  m_pFontHull = nullptr;
73 
74  // Static VB, doesn't change every frame
75  m_avStaticStars = nullptr;
76  m_avCone = nullptr;
77  m_avSunVertices = nullptr;
78 #ifdef treetestC
79  m_avTree = NULL;
80 #endif
81  m_avRunningLights = nullptr; // For the running lights
82  m_aiCloudGrid = nullptr;
83  m_avCloudGrid = nullptr;
84  //m_aiLocalGrid = NULL;
85  m_avLocalGrid = nullptr;
86 
87  // Dynamic VB, changes every frame
88  m_avRainDrops = nullptr;
89  m_avSkyDome = nullptr;
90  m_avSkyRing = nullptr;
91  m_avScreen = nullptr; // Alpha blended viewscreen
92  m_avInstrument = nullptr; // Instrumentation
93  m_avLightning = nullptr;
94 
95  // Static Textures
96  //m_pddsDetail1 = NULL;
97  m_pddsWorld2a1 = nullptr; // Iomere
98  m_pddsCloudBaseMap = nullptr; // Clouds
99  m_pddsCloudDetailAbove = nullptr; // Clouds
100  m_pddsCloudDetailBelow = nullptr; // Clouds
101  m_pddsBinoculars = nullptr;
102  m_pddsBinocularsCompass = nullptr;
103  m_pddsBinocularsArrow = nullptr;
104  m_pddsSunglasses = nullptr;
105  m_pddsSunTexture = nullptr; // Yonmara
106  m_pddsStarTexture = nullptr;
107  m_pddsHolidayTexture = nullptr;
108 
109  // arrays
110  for (t = 0; t < weaponanimateC; t++)
111  m_pddsWeapon[t] = m_pddsSinker[t] = nullptr;;
112  m_pddsFuzerX = nullptr;
113  m_pddsSinkerX = nullptr;
114  m_pddsBlastX = nullptr;
115  for (t = 0; t < firework1C; t++)
116  m_pddsFirework1[t] = nullptr;
117  for (t = 0; t < firework2C; t++)
118  m_pddsFirework2[t] = nullptr;
119  for (t = 0; t < firework3C; t++)
120  m_pddsFirework3[t] = nullptr;
121  for (t = 0; t < elmoAnimateC; t++)
122  m_pddsElmo[t] = nullptr;
123 #ifdef smoketestC
124  for (t = 0; t < smoketrailC; t++)
125  m_pddsSmoke[t] = NULL;
126 #endif
127  for (t = 0; t < dihvanimateC; t++)
128  m_pddsDIHV[t] = nullptr;
129  for (t = 0; t < heartanimateC; t++)
130  m_pddsHeart[t] = nullptr;
131  m_pddsReentry = nullptr;
132 
133  // Cockpit dashes
134  m_pddsGVDialSmall = nullptr; // must be separate, rotates
135  m_pddsGVBackground = nullptr; // could be combined
136  m_pddsNamePlate = nullptr; // could be combined
137  m_pddsGVCompass = nullptr; // must be separate, wraps
138  m_pddsGVDirection = nullptr; // could be combined
139  m_pddsLightsCruiseIcons = nullptr; // could be combined
140  m_pddsFuelIcon = nullptr; // could be combined
141  for (t = 0; t < 3; t++)
142  m_pddsAOA[t] = nullptr;
143  for (t = 0; t < cockpittextureC; t++)
144  m_pddsCockpitTexture[t] = m_pddsCockpitLights[t] = nullptr;
145  //m_pddsVector = nullptr; // could be combined
146  //m_pddsAGLtape = nullptr; // could be combined
147  for (t = 0; t < 2; t++)
148  m_pddsInterlace[t] = nullptr;
149 
150  // Interface
151  // m_pddsCardioscan = NULL;
152  // m_pddsMenu = NULL;
153  // m_pddsHelp = NULL;
154  m_pddsLetters = nullptr;
155 
156  for (t = 0; t < 3; t++)
157  m_pddsLightningBelow[t] = m_pddsLightningAbove[t] = nullptr;
158  m_pddsAtmosphere = nullptr;
159 #ifdef treetestC
160  m_pddsTree = NULL;
161 #endif
162  for (t = 0; t < shiptextureC; t++)
163  m_pddsShipTexture[t] = m_pddsShipLights[t] = nullptr;
164  for (t = 0; t < docktextureC; t++)
165  m_pddsDockTexture[t] = m_pddsDockLights[t] = nullptr;
166  for (t = 0; t < RTStextureC; t++)
167  m_pddsRTSTexture[t] = m_pddsRTSLights[t] = nullptr;
168  for (t = 0; t < citytextureC; t++)
169  m_pddsCityTexture[t] = m_pddsCityLights[t] = nullptr;
170  for (t = 0; t < landformtextureC; t++)
171  m_pddsLandform[t] = nullptr;
172  for (t = 0; t < transitiontextureC; t++)
173  m_pddsTransition[t] = nullptr;
174  m_pddsWaterNormal = nullptr;
175  m_pddsMarston1 = nullptr;
176  m_pddsRunwayEdgeLight1 = nullptr;
177  m_pddsRoad = nullptr;
178  m_pddsIntersection = nullptr;
179 
180  // Dynamic Textures
181  m_pddsDynamicTexture = nullptr;
182  m_pddsDynamicSurface = nullptr;
183  m_pddsProjectionTexture = nullptr;
184  m_pddsProjectionSurface = nullptr;
185  m_pRenderToSurface = nullptr;
186  m_pRenderToSurfaceNextGen = nullptr;
187  m_pHullRender2Surface = nullptr;
188 
189  logger->Log("Viewscreen::ctor Initializing vehicles array!");
190 
191  for (t = 0; t < MAX_SCAN; t++)
192  {
193  // These guys were found not to be initialized in the legacy Viewscreen as part of the integration
194  scanslot[t] = t;
195  scandist[t] = 0.0f;
196 
197  playerships[t].active = false;
198  playerships[t].visible = false;
199  playerships[t].inhibitvisibility = false;
200  playerships[t].clientinit = true;
201  playerships[t].logolight = false;
202  playerships[t].docked = false;
203  playerships[t].vehicleId = 0;
204  playerships[t].headlight = false;
205  playerships[t].geardown = false;
206  playerships[t].domelight = false;
207  playerships[t].brakelight = false;
208  playerships[t].police = false;
209  playerships[t].specialight = false;
210  playerships[t].reference = -127;
211  playerships[t].inarray = -1;
214  playerships[t].cloaking = 1.0f;
215  playerships[t].speed = 0.0f;
216  playerships[t].type = 0; // unassigned
217  playerships[t].bound = 0.0f;
218  playerships[t].flapdown = 0.0f;
219  playerships[t].steerLimitRadian = 0.0f;
221  playerships[0].tireRotationRadians = RandomFloat() * D3DX_TAU;
222 
223  // all this in case we don't get a packet
227  playerships[t].precisionx = 0.0;
228  playerships[t].precisiony = 0.0;
229  playerships[t].precisionz = 0.0;
230  D3DXQuaternionIdentity(&playerships[t].orientation);
231  D3DXQuaternionIdentity(&playerships[t].orientiter);
232  D3DXQuaternionIdentity(&playerships[t].orientleft);
233  playerships[t].pitch = playerships[t].roll = playerships[t].yaw = 0.0f;
235  playerships[t].IVR[0] = playerships[t].hullname[0] = 0;
236  playerships[t].componentarray = nullptr;
237  playerships[t].components = 0;
238  D3DXMatrixTranslation(&playerships[t].matrixWorld, 500.0f, 0.0f, 0.0f);
239  D3DXMatrixIdentity(&playerships[t].matrixWorld);
240  D3DXMatrixIdentity(&playerships[t].matrixBase);
241  D3DXMatrixIdentity(&playerships[t].dor);
242  D3DXMatrixIdentity(&playerships[t].matrixInvOrientation);
243  }
244 
245  //for (t = 0; t < MAX_ONLINEPLAYERS; t++)
246  //{
247  // player[t].frame=-2;
248  // player[t].queueani=player[t].ani=7; // ready
249  // player[t].anitime=0.0f;
250  //}
251 
252  weapontimer[0] = weapontimer[1] = 0.0f;
253 
255 
257  for (t = 0; t < PlotType::PlotTypeEnum; t++)
258  {
259  citystuff.compare[t] = maxcompareC >> rand() % maxcomparebitC; // start somewhere in sequence at random
260  citystuff.timer[t] = RandomFloat(); // start somewhere within sequence at random
261 
262  // higher is slower
263  switch (t)
264  {
265  case 1: citystuff.speed[t] = 0.523832f; break;
266  case 4: citystuff.speed[t] = 0.364829f; break;
267  case 5: citystuff.speed[t] = 0.316228f; break;
268  case 6: citystuff.speed[t] = 0.270000f; break;
269  case 13: citystuff.speed[t] = 0.028284f; break;
270  case 14: citystuff.speed[t] = 0.5f; break;
271  default: citystuff.speed[t] = 0.0f; break;
272  }
273  }
274 
275  for (t = 0; t < fireworksC; t++)
276  fireworks[t].inuse = false;
277 
278  // These guys were found not to be initialized in the legacy Viewscreen as part of the integration
279  for (t = 0; t < MAX_SCAN; t++)
280  m_pddsHullDynamicTexture[t] = nullptr;
281 
282  lookhdg = 0.0f;
283  verticaltime = lateraltime = 0.0f;
284  deathinhibit = 0.0f;
285  //teleminhibit = 0.0f;
286  waterloop = heartloop = 0;
287 
288  gammascreen = D3DXVECTOR4(0, 12, 0, 0);
289 
290  //QueryPerformanceFrequency(&frequency);
291  //QueryPerformanceCounter(&oldTime);
292 }
293 
295 {
296  logger->AddToCallStack("Viewscreen::dtor");
297 
298  SAFE_DELETE(ptrGrid);
299  SAFE_DELETE(ptrWeapon);
300  SAFE_DELETE(ptrBuildings);
301  SAFE_DELETE(ptrKeyboard);
302  SAFE_DELETE(ptrJoystick);
303  SAFE_DELETE(ptrPropulsion);
304  SAFE_DELETE(ptrFreeTrack);
305  SAFE_DELETE(ptrRenderer);
306  SAFE_DELETE(ptrWeather);
307  SAFE_DELETE(ptrCockpit);
308  SAFE_DELETE(ptrInstruments);
309  SAFE_DELETE(ptrWaypoints);
310 
311  logger->AddToCallStack("Viewscreen::dtor DONE");
312 }
313 
315 {
316  logger->AddToCallStack("Viewscreen::Initialize");
317  logger->Log("Viewscreen Initialize() Called!");
318 
319  _controlfp_s(nullptr, _PC_64, MCW_PC);
320 
321  // -----------------------------------------------------------------------------------------
322  // ChangeCockpit the dynamic universe objects
323  // -----------------------------------------------------------------------------------------
324  int universe;
325  _sopen_s(&universe, "universe.dat", _O_RDONLY | _O_BINARY | _O_SEQUENTIAL, _SH_DENYWR, _S_IWRITE); // | _SH_DENYNO
326  if (universe == -1)
327  {
328  logger->Log("Viewscreen Initialize() failed to load \"universe.dat\"...", Logger::Level::Info);
329  char strerr[99];
330  strerror_s(strerr, 99, errno);
331  logger->Log(strerr, Logger::Level::Fatal);
332  }
333 
334  for (long t = 0; t < maxstarC; t++)
335  {
336  allobjects[t].componentarray = nullptr;
337  allobjects[t].components = 0;
338 
339  _lseek(universe, t * 1000 + 999 + 0, SEEK_SET); // To 0
340  _read(universe, &allobjects[t].type, 2);
341  _lseek(universe, t * 1000 + 999 + 2, SEEK_SET); // To 2
342  _read(universe, &allobjects[t].revoffset, 4);
343  _lseek(universe, t * 1000 + 999 + 6, SEEK_SET); // To 6
344  _read(universe, &allobjects[t].rotoffset, 4);
345  _lseek(universe, t * 1000 + 999 + 10, SEEK_SET); // To 10
346  _read(universe, &allobjects[t].inclination, 4);
347  _lseek(universe, t * 1000 + 999 + 14, SEEK_SET); // To 14
348  _read(universe, &allobjects[t].range, 4);
349  _lseek(universe, t * 1000 + 999 + 18, SEEK_SET); // To 18
350  _read(universe, &allobjects[t].rotation, 4);
351  _lseek(universe, t * 1000 + 999 + 22, SEEK_SET); // To 22
352  _read(universe, &allobjects[t].revolution, 4);
353  _lseek(universe, t * 1000 + 999 + 26, SEEK_SET); // To 26
354  _read(universe, &allobjects[t].scale, 4);
355  _lseek(universe, t * 1000 + 999 + 30, SEEK_SET); // To 30
356  _read(universe, &allobjects[t].tilt, 4);
357  _lseek(universe, t * 1000 + 999 + 64, SEEK_SET); // To 30
358  _read(universe, &allobjects[t].bound, 4);
359 
360  // if (allobjects[t].type==1) // dock
361  // {
362  // allobjects[t].scale=1.0f;
363  // allobjects[t].bound=0.139014f;
364  // }
365 
366  allobjects[t].compare = maxcompareC >> rand() % maxcomparebitC;
367  allobjects[t].speed = 0.09f + RandomFloat() * 0.02f; // 45-55
369  allobjects[t].powered = false;
370  }
371  _close(universe);
372 
373  // -----------------------------------------------------------------------------------------
374  // Sort the dynamic universe objects
375  // -----------------------------------------------------------------------------------------
376  bool swapflag;
377  s_universe_object tempobject;
378  do
379  {
380  swapflag = false;
381  for (short t = 0; t < maxstarC - 1; t++)
382  {
383  if (allobjects[t].type < allobjects[t + 1].type)
384  {
385  tempobject = allobjects[t];
386  allobjects[t] = allobjects[t + 1];
387  allobjects[t + 1] = tempobject;
388  swapflag = true;
389  }
390  }
391  } while (swapflag);
392 
393 
394  strcpy_s(msg, sizeof msg, "Types in sort order:");
395  for (short t = 0; t < maxstarC; t++)
396  {
397  sprintf_s(msg, sizeof msg, "%s %i", msg, allobjects[t].type);
398 
399  if (allobjects[t].type == -1) // Vieneo
400  ourmoonC = (unsigned char)t;
401  if (allobjects[t].type == -11) // Lower cloud layer
402  BCLobjC = (unsigned char)t;
403  if (allobjects[t].type == -2) // Upper cloud layer
404  {
405  UCLobjC = (unsigned char)t;
407  }
408  if (allobjects[t].type == -7) // Sun
409  ourstarC = (unsigned char)t;
410  if (allobjects[t].type == -3) // Iomere
411  ourplanetC = (unsigned char)t;
412  }
413  logger->Log(msg);
414 
415  logger->Log("Viewscreen Initialize() Done!");
416 }
417 
418 HRESULT Viewscreen::OnCreateDevice(IDirect3DDevice9* pd3dDevice)
419 {
420  logger->AddToCallStack("Viewscreen::OnCreateDevice");
421 
422  sprintf_s(msg, sizeof msg, "Viewscreen OnCreateDevice() DS %i", gameclass->displaystage);
423  logger->Log(msg);
424 
425  D3DXVECTOR3 tempnormal;
426 
427  sprintf_s(msg, sizeof msg, "Version: %i.%i.%i.%i Mode: %S", gameclass->GUI->major, gameclass->GUI->minor, gameclass->GUI->build, gameclass->GUI->revision, DXUTGetDeviceStats());
428  logger->Log(msg);
429 
430  HRESULT hr;
431 
432  // this is used on legacy cockpit monitors which don't vary DPI
433  // we are also using this now for the "loading" page WHICH IS A PROBLEM @bug https://jira.risetvp.com/view.php?id=1344
434  // also used for FLIGHT FREEZE on projection screen
435  // Courier New is a default Windows font
436  AddFontResourceEx(L"Fonts\\cour.ttf", FR_PRIVATE, nullptr);
437  int nHeight = -9 * 96 / 72;
438  if (FAILED(hr = D3DXCreateFontW(pd3dDevice, nHeight, 0, FW_MEDIUM, 1, false, DEFAULT_CHARSET,
439  OUT_TT_ONLY_PRECIS, ANTIALIASED_QUALITY, DEFAULT_PITCH | FF_DONTCARE,
440  TEXT("Courier New"), &m_pFont)))
441  {
442  logger->Log("Error creating font for monitors...", Logger::Level::Error);
443  return hr;
444  }
445  gameclass->AddTrackedResource("m_pFont", D3DPOOL_FORCE_DWORD); // really adds just 1, now 38
446 
447  // This is for the exterior name plate license plate font which as a render target doesn't vary DPI
448  // this is a built-in Windows font
449  AddFontResourceEx(L"Fonts\\LicensePlate.ttf", FR_PRIVATE, nullptr);
450  if (FAILED(hr = D3DXCreateFontW(pd3dDevice, 24, 0, FW_MEDIUM, 1, false, DEFAULT_CHARSET,
451  OUT_TT_ONLY_PRECIS, ANTIALIASED_QUALITY, DEFAULT_PITCH | FF_DONTCARE,
452  TEXT("License Plate"), &m_pFontLicense)))
453  {
454  logger->Log("Error creating font for exterior name plate license plate...", Logger::Level::Error);
455  return hr;
456  }
457  gameclass->AddTrackedResource("m_pFontLicense", D3DPOOL_FORCE_DWORD); // really adds just 1, now 39
458 
459  // This one is a render target only so no scaling based on desktop DPI, used for interior name plate and gear indication
460  // this is a built-in Windows font
461  AddFontResourceEx(L"Fonts\\pala.ttf", FR_PRIVATE, nullptr);
462  nHeight = -9 * 96 / 72;
463  if (FAILED(hr = D3DXCreateFontW(pd3dDevice, nHeight, 0, FW_SEMIBOLD, 1, false, DEFAULT_CHARSET,
464  OUT_TT_ONLY_PRECIS, ANTIALIASED_QUALITY, DEFAULT_PITCH | FF_DONTCARE,
465  TEXT("Palatino Linotype"), &m_pFont3)))
466  {
467  sprintf_s(msg, sizeof msg, "Error creating font for interior name plate: ");
468  if (hr == D3DERR_INVALIDCALL)
469  strcat_s(msg, sizeof msg, "D3DERR_INVALIDCALL");
470  else if (hr == D3DXERR_INVALIDDATA)
471  strcat_s(msg, sizeof msg, "D3DXERR_INVALIDDATA");
472  else if (hr == E_OUTOFMEMORY)
473  strcat_s(msg, sizeof msg, "E_OUTOFMEMORY");
474  else
475  sprintf_s(msg, sizeof msg, "UNKNOWN %x", hr);
476  logger->Log(msg, Logger::Level::Error);
477  return E_FAIL;
478  }
479  // This one is a render target only so no scaling based on desktop DPI, used for interior name plate and gear indication
480  gameclass->AddTrackedResource("m_pFont3", D3DPOOL_FORCE_DWORD); // really adds just 1, now 40
481 
482 
483 
484  // This is for the exterior name plate Manx font which as a render target doesn't vary DPI
485  // this is a built-in Windows font
486  AddFontResourceEx(L"Fonts\\rcaf6-GIMP.ttf", FR_PRIVATE, nullptr);
487  if (FAILED(hr = D3DXCreateFont(pd3dDevice, 9, 6, FW_SEMIBOLD, 1, false, DEFAULT_CHARSET,
488  OUT_TT_ONLY_PRECIS, ANTIALIASED_QUALITY, DEFAULT_PITCH | FF_DONTCARE,
489  TEXT("RCAF_60SQO_ATH_GIMP"), &m_pFontHull)))
490  {
491  sprintf_s(msg, sizeof(msg), "Error creating font for exterior name plate: ");
492  if (hr == D3DERR_INVALIDCALL)
493  strcat_s(msg, sizeof msg, "D3DERR_INVALIDCALL");
494  else if (hr == D3DXERR_INVALIDDATA)
495  strcat_s(msg, sizeof msg, "D3DXERR_INVALIDDATA");
496  else if (hr == E_OUTOFMEMORY)
497  strcat_s(msg, sizeof msg, "E_OUTOFMEMORY");
498  else
499  sprintf_s(msg, sizeof msg, "UNKNOWN %x", hr);
500  logger->Log(msg, Logger::Level::Error);
501  return E_FAIL;
502  }
503  gameclass->AddTrackedResource("m_pFontHull", D3DPOOL_FORCE_DWORD); // really adds just 1, now 41
504 
505 
506  D3DXCreateSprite(pd3dDevice, &m_spriteVector);
507  gameclass->AddTrackedResource("m_spriteVector", D3DPOOL_FORCE_DWORD); // actually adds 2, now 43
508 
509 
510  logger->Log("InitDeviceObjects() font for HUD loaded!");
511 
512 
513  logger->Log("Viewscreen::OnCreateDevice() creating vertex buffers...");
514 
515  if (FAILED(hr = pd3dDevice->CreateVertexBuffer(starsC * sizeof(D3DSTATICSTARS),
516  D3DUSAGE_WRITEONLY | D3DUSAGE_POINTS, D3DFVF_STATICSTARS,
517  D3DPOOL_MANAGED, &m_avStaticStars, NULL)))
518  {
519  logger->Log("CreateVertexBuffer m_avStaticStars failed!", Logger::Level::Error);
520  return hr;
521  }
522  gameclass->AddTrackedResource("m_avStaticStars"); // managed
523 
524  if (FAILED(hr = pd3dDevice->CreateVertexBuffer(72 * 3 * sizeof(D3DSKYDOME),
525  D3DUSAGE_WRITEONLY, D3DFVF_SKYDOME,
526  D3DPOOL_MANAGED, &m_avCone, NULL)))
527  {
528  logger->Log("CreateVertexBuffer m_avCone failed!", Logger::Level::Error);
529  return hr;
530  }
531  gameclass->AddTrackedResource("m_avCone"); // managed
532 
533  if (FAILED(hr = pd3dDevice->CreateVertexBuffer(4 * sizeof(D3DNONORMAL),
534  D3DUSAGE_WRITEONLY, D3DFVF_NONORMAL,
535  D3DPOOL_MANAGED, &m_avSunVertices, NULL)))
536  {
537  logger->Log("CreateVertexBuffer m_avSunVertices failed!", Logger::Level::Error);
538  return hr;
539  }
540  gameclass->AddTrackedResource("m_avSunVertices"); // managed
541 
542 #ifdef treetestC
543  if (FAILED(pd3dDevice->CreateVertexBuffer(3 * sizeof(D3DNONORMAL),
544  D3DUSAGE_WRITEONLY, D3DFVF_NONORMAL,
545  D3DPOOL_MANAGED, &m_avTree, NULL)))
546  {
547  logger->Log("CreateVertexBuffer m_avTree failed!", Logger::Level::Error);
548  return E_OUTOFMEMORY;
549  }
550  gameclass->AddTrackedResource("m_avTree"); // managed
551 #endif
552 
553  if (FAILED(hr = pd3dDevice->CreateVertexBuffer(runninglightsC * sizeof(D3DNOPSIZE),
554  D3DUSAGE_WRITEONLY | D3DUSAGE_POINTS, D3DFVF_NOPSIZE,
555  D3DPOOL_MANAGED, &m_avRunningLights, NULL)))
556  {
557  logger->Log("CreateVertexBuffer m_avRunningLights failed!", Logger::Level::Error);
558  return hr;
559  }
560  gameclass->AddTrackedResource("m_avRunningLights"); // managed
561 
562  if (FAILED(hr = pd3dDevice->CreateIndexBuffer(cloudindicesC * 2L, // 2 bytes per short
563  D3DUSAGE_WRITEONLY, D3DFMT_INDEX16,
564  D3DPOOL_MANAGED, &m_aiCloudGrid, NULL)))
565  {
566  logger->Log("CreateVertexBuffer m_aiCloudGrid failed!", Logger::Level::Error);
567  return hr;
568  }
569  gameclass->AddTrackedResource("m_aiCloudGrid"); // managed
570 
571  //if (FAILED(pd3dDevice->CreateIndexBuffer(35540L, // 2 bytes per short
572  // D3DUSAGE_WRITEONLY, D3DFMT_INDEX16,
573  // D3DPOOL_MANAGED, &game->m_aiLocalGrid, NULL)))
574  // return E_OUTOFMEMORY;
575 
576  if (FAILED(hr = pd3dDevice->CreateVertexBuffer(visiblevertC * sizeof(D3DLOCALGRID2),
577  D3DUSAGE_WRITEONLY, D3DFVF_LOCALGRID2,
578  D3DPOOL_MANAGED, &m_avLocalGrid, NULL)))
579  {
580  logger->Log("CreateVertexBuffer m_avLocalGrid failed!", Logger::Level::Error);
581  return hr;
582  }
583  gameclass->AddTrackedResource("m_avLocalGrid"); // managed
584 
585  if (FAILED(hr = pd3dDevice->CreateVertexBuffer(4096 * sizeof(D3DLOCALGRID),
586  D3DUSAGE_WRITEONLY, D3DFVF_LOCALGRID,
587  D3DPOOL_MANAGED, &m_avCloudGrid, NULL)))
588  {
589  logger->Log("CreateVertexBuffer m_avCloudGrid failed!", Logger::Level::Error);
590  return hr;
591  }
592  gameclass->AddTrackedResource("m_avCloudGrid"); // managed
593 
594  logger->Log("Viewscreen::OnCreateDevice() created all static vertex/index buffers!");
595 
596  // ChangeCockpit polyobjects *************************************************************************
597  int handle, t;
598  long s;
599  D3DVERTEX* vtx;
600 
601  D3DNOPSIZE* vtx2;
602  unsigned char offset = 0;
603  V(m_avRunningLights->Lock(0, 0, reinterpret_cast<void**>(&vtx2), 0));
604  int runningVerts = 0;
605 
606  (*vtx2).x = 0.0f;
607  (*vtx2).z = 0.0f;
608  (*vtx2).y = 0.0f;
609  (*vtx2).diffuse = 0xFFFFFFFF;
610  offset++;
611  vtx2++;
612  runningVerts++;
613 
614  for (t = 0; t < maxpolyC; t++)
615  {
616  bool skip = false;
617  handle = -1;
618  // ReSharper disable once CppDefaultCaseNotHandledInSwitchStatement
619  switch (t)
620  {
621  // Iomere
622  case 0: _sopen_s(&handle, "Meshes\\farspher.DAW", _O_RDONLY | _O_BINARY | _O_SEQUENTIAL, _SH_DENYWR, _S_IWRITE);
623  break;
624  // Docks
625  case 1:
626  skip = true;
627  break;
628  case 2: _sopen_s(&handle, "Meshes\\sphere.DAW", _O_RDONLY | _O_BINARY | _O_SEQUENTIAL, _SH_DENYWR, _S_IWRITE);
629  break;
630  case 3: _sopen_s(&handle, "Meshes\\E-10.DAW", _O_RDONLY | _O_BINARY | _O_SEQUENTIAL, _SH_DENYWR, _S_IWRITE);
631  break;
632  case 4: _sopen_s(&handle, "Meshes\\cargo-standard.daw", _O_RDONLY | _O_BINARY | _O_SEQUENTIAL, _SH_DENYWR, _S_IWRITE);
633  break;
634  // Cockpits and Interiors
635  case 5:
636  skip = true;
637  break;
638  case 6: _sopen_s(&handle, "Meshes\\T-8 Wanderer.daw", _O_RDONLY | _O_BINARY | _O_SEQUENTIAL, _SH_DENYWR, _S_IWRITE);
639  break;
640  case 7: _sopen_s(&handle, "Meshes\\dihv.DAW", _O_RDONLY | _O_BINARY | _O_SEQUENTIAL, _SH_DENYWR, _S_IWRITE);
641  break;
642  case 8: _sopen_s(&handle, "Meshes\\C-98 MuVER-construction.DAW", _O_RDONLY | _O_BINARY | _O_SEQUENTIAL, _SH_DENYWR, _S_IWRITE);
643  break;
644  case 9: _sopen_s(&handle, "Meshes\\p-13.DAW", _O_RDONLY | _O_BINARY | _O_SEQUENTIAL, _SH_DENYWR, _S_IWRITE);
645  break;
646  case 10: _sopen_s(&handle, "Meshes\\C-2 Dasher.DAW", _O_RDONLY | _O_BINARY | _O_SEQUENTIAL, _SH_DENYWR, _S_IWRITE);
647  break;
648  case 11: _sopen_s(&handle, "Meshes\\T-120 Steerhead-stock.DAW", _O_RDONLY | _O_BINARY | _O_SEQUENTIAL, _SH_DENYWR, _S_IWRITE);
649  break;
650  case 12: _sopen_s(&handle, "Meshes\\E-11.DAW", _O_RDONLY | _O_BINARY | _O_SEQUENTIAL, _SH_DENYWR, _S_IWRITE);
651  break;
652  case 13: _sopen_s(&handle, "Meshes\\WEP-WVM1-hornet.DAW", _O_RDONLY | _O_BINARY | _O_SEQUENTIAL, _SH_DENYWR, _S_IWRITE);
653  break;
654  case 14: _sopen_s(&handle, "Meshes\\C-2A Dasher.DAW", _O_RDONLY | _O_BINARY | _O_SEQUENTIAL, _SH_DENYWR, _S_IWRITE);
655  break;
656  case 15: _sopen_s(&handle, "Meshes\\2007 T-120 EXT.DAW", _O_RDONLY | _O_BINARY | _O_SEQUENTIAL, _SH_DENYWR, _S_IWRITE);
657  break;
658  case 16: _sopen_s(&handle, "Meshes\\manx-hex.DAW", _O_RDONLY | _O_BINARY | _O_SEQUENTIAL, _SH_DENYWR, _S_IWRITE);
659  break;
660  case 17: _sopen_s(&handle, "Meshes\\BeishtKione.DAW", _O_RDONLY | _O_BINARY | _O_SEQUENTIAL, _SH_DENYWR, _S_IWRITE);
661  break;
662  case 18: _sopen_s(&handle, "Meshes\\fuel-standard-ext.daw", _O_RDONLY | _O_BINARY | _O_SEQUENTIAL, _SH_DENYWR, _S_IWRITE);
663  break;
664  case 19: _sopen_s(&handle, "Meshes\\T-19 Stratomaster.DAW", _O_RDONLY | _O_BINARY | _O_SEQUENTIAL, _SH_DENYWR, _S_IWRITE);
665  break;
666  case 20: _sopen_s(&handle, "Meshes\\cargo-toploader.daw", _O_RDONLY | _O_BINARY | _O_SEQUENTIAL, _SH_DENYWR, _S_IWRITE);
667  break;
668  case 21: _sopen_s(&handle, "Meshes\\munitions-standard-ext.daw", _O_RDONLY | _O_BINARY | _O_SEQUENTIAL, _SH_DENYWR, _S_IWRITE);
669  break;
670  case 22: _sopen_s(&handle, "Meshes\\Holidays\\Spacesuit-Morholt-posed.daw", _O_RDONLY | _O_BINARY | _O_SEQUENTIAL, _SH_DENYWR, _S_IWRITE);
671  break;
672  case 23: _sopen_s(&handle, "Meshes\\pax-exterior-hex.daw", _O_RDONLY | _O_BINARY | _O_SEQUENTIAL, _SH_DENYWR, _S_IWRITE);
673  break;
674  case 24: _sopen_s(&handle, "Meshes\\cnst-exterior-hex.daw", _O_RDONLY | _O_BINARY | _O_SEQUENTIAL, _SH_DENYWR, _S_IWRITE);
675  break;
676  case 25: _sopen_s(&handle, "Meshes\\T-27 Mammoth.daw", _O_RDONLY | _O_BINARY | _O_SEQUENTIAL, _SH_DENYWR, _S_IWRITE);
677  break;
678  }
679  if (handle == -1 && !skip) // disregard cockpit and docks
680  {
681  char strerr[99];
682  strerror_s(strerr, 99, errno);
683  sprintf_s(msg, sizeof(msg), "Could not load polygon object (DAW file) number %i: %s", t, strerr);
684  logger->Log(msg, Logger::Level::Fatal);
685  }
686 
687 
688  // Vertices -----------------------------------------------------------------------------
689  if (!skip) // disregard cockpit and docks
690  {
691  _lseek(handle, 0L, SEEK_SET);
692  _read(handle, &polyobjects[t].vertices, 2);
693  sprintf_s(msg, sizeof(msg), "Loading file (%i vertices) for polygon object number %i...", polyobjects[t].vertices, t);
694  logger->Log(msg);
695  }
696  else
697  {
698  if (t == 5)
700  else if (t == 1)
702  else
703  polyobjects[t].vertices = 0;
704  }
706 
707 
708  if (t == 2) // Vieneo sphere is dynamic
710  else if (polyobjects[t].vertices)
711  {
712  // Create the vertex buffer
713  sprintf_s(msg, sizeof(msg), "Creating memory (%i vertices) for polygon object number %i...", polyobjects[t].vertices, t);
714  logger->Log(msg);
715 
716  if (FAILED(hr = pd3dDevice->CreateVertexBuffer((long)polyobjects[t].vertices * sizeof(D3DVERTEX),
717  D3DUSAGE_WRITEONLY, D3DFVF_VERTEX,
718  D3DPOOL_MANAGED, &polyobjects[t].VB, NULL)))
719  {
720  sprintf_s(msg, sizeof(msg), "Could not create memory (%i vertices) for polygon object number %i!", polyobjects[t].vertices, t);
721  logger->Log(msg);
722  return hr;
723  }
724  sprintf_s(msg, sizeof(msg), "polyobjects[%i].VB", t);
725  gameclass->AddTrackedResource(msg); // managed
726 
727  // Lock the vertex buffer
728  if (!skip) // disregard cockpit and docks
729  {
730  V(polyobjects[t].VB->Lock(0, 0, reinterpret_cast<void**>(&vtx), 0));
731  }
732  }
733 
734  if (!skip) // disregard cockpit and docks
735  {
736  for (s = 0; s < polyobjects[t].vertices; s++)
737  {
738  _lseek(handle, 2L + s * 32L + 0L, SEEK_SET);
739  _read(handle, &tempnormal, 12);
740  if (t == 2)
741  {
742  D3DXVec3Normalize(&tempnormal, &tempnormal);
743  polyextras2.vertexbackup[s].x = tempnormal.x / 0.99879f; // so that lowest point
744  polyextras2.vertexbackup[s].y = tempnormal.y / 0.99879f; // is equal to
745  polyextras2.vertexbackup[s].z = tempnormal.z / 0.99879f; // cloudtopsC
746  }
747  else
748  {
749  (*vtx).x = tempnormal.x;
750  (*vtx).y = tempnormal.y;
751  (*vtx).z = tempnormal.z;
752  }
753 
754  if (t == 2)
755  {
756  D3DXVec3Normalize(&tempnormal, &tempnormal); // this sphere is shaded specially
757  polyextras2.vertexbackup[s].nx = tempnormal.x;
758  polyextras2.vertexbackup[s].ny = tempnormal.y;
759  polyextras2.vertexbackup[s].nz = tempnormal.z;
760  _lseek(handle, 2L + s * 32L + 24L, SEEK_SET);
761  _read(handle, &polyextras2.vertexbackup[s].tu, 4);
762  _read(handle, &polyextras2.vertexbackup[s].tv, 4);
763  }
764  else
765  {
766  if (t == 0) // Iomere is spherically shaded
767  D3DXVec3Normalize(&tempnormal, &tempnormal);
768  else
769  {
770  _lseek(handle, 2L + s * 32L + 12L, SEEK_SET);
771  _read(handle, &tempnormal, 12);
772  }
773  (*vtx).nx = tempnormal.x;
774  (*vtx).ny = tempnormal.y;
775  (*vtx).nz = tempnormal.z;
776  _lseek(handle, 2L + s * 32L + 24L, SEEK_SET);
777  _read(handle, &tempnormal.x, 4);
778  _read(handle, &tempnormal.y, 4);
779  (*vtx).tu = tempnormal.x;
780  (*vtx).tv = tempnormal.y;
781  vtx++;
782  }
783  }
784 
785  if (t != 2)
786  {
787  if (polyobjects[t].VB)
788  {
789  V(polyobjects[t].VB->Unlock());
790  }
791  }
792  else
793  {
794  // For the upper cloud layer map
795  for (s = 0; s < polyobjects[t].polygons; s++)
796  {
797  polyextras2.center[s].x = polyextras2.vertexbackup[s * 3 + 0].x + polyextras2.vertexbackup[s * 3 + 1].x + polyextras2.vertexbackup[s * 3 + 2].x;
798  polyextras2.center[s].y = polyextras2.vertexbackup[s * 3 + 0].y + polyextras2.vertexbackup[s * 3 + 1].y + polyextras2.vertexbackup[s * 3 + 2].y;
799  polyextras2.center[s].z = polyextras2.vertexbackup[s * 3 + 0].z + polyextras2.vertexbackup[s * 3 + 1].z + polyextras2.vertexbackup[s * 3 + 2].z;
800  D3DXVec3Normalize(&polyextras2.center[s], &polyextras2.center[s]);
801  D3DXVec3Scale(&polyextras2.center[s], &polyextras2.center[s], cloudTopsRadiusC);
802  polyextras2.index[s] = static_cast<short>(s);
803  }
804  }
805 
806 
807 
808  polyobjects[t].effects.clear();
809  // Lighting Effects ---------------------------------------------------------------------
810  switch (t)
811  {
812  case 3: // E-10 Saint
813  case 6: // A-4
814  case 7: // DIHV
815  case 8: // MuVER C-98
816  case 9: // P-13 Prowler
817  case 10: // C-2 Dasher
818  case 11: // T-120 Steerhead
819  case 12: // E-11
820  case 14: // C-2A Dasher
821  case 15: // T-1 Stratoranger
822  case 16: // W-6 Manx
823  case 18: // Aux. Fuel Pods
824  case 19: // T-19 Stratomaster
825  case 25: // T-27 Mammoth
826  {
827  short numberOfEffects;
828  _read(handle, &numberOfEffects, 2);
829  sprintf_s(msg, sizeof(msg), "OnCreateDevice loading %i light(s) for polygon object number %i...", numberOfEffects, t);
830  logger->Log(msg);
831  for (s = 0; s < numberOfEffects; s++)
832  {
833  s_light_effect newEffect;
834  _read(handle, &(*vtx2).x, 4);
835  _read(handle, &(*vtx2).y, 4);
836  _read(handle, &(*vtx2).z, 4);
837  newEffect.position.x = (*vtx2).x;
838  newEffect.position.y = (*vtx2).y;
839  newEffect.position.z = (*vtx2).z;
840  _read(handle, &newEffect.normal, 12);
841  _read(handle, &(*vtx2).diffuse, 4);
842  newEffect.diffuse = (*vtx2).diffuse;
843  _read(handle, &newEffect.sequencing, 4);
844  _read(handle, &newEffect.speed, 4); // unused
845  _read(handle, &newEffect.power, 4);
846  _read(handle, &newEffect.attachto, 2);
847  newEffect.primitive = offset;
848  polyobjects[t].effects.emplace_back(newEffect);
849  offset++;
850  vtx2++;
851  runningVerts++;
852  }
853  }
854  break;
855  }
856 
857  if (handle != -1)
858  _close(handle); // close DAW file
859  }
860  }
861 
862  if (runningVerts > runninglightsC)
863  {
864  logger->Log("runningVerts > runninglightsC", Logger::Level::Fatal);
865  }
866 
867  V(m_avRunningLights->Unlock());
868 
869 
870  float f_temp;
871  short i_temp;
872  // SHOULD BE ABLE TO DUMP COMPONENTARRAY UNTIL THE DAW IS LOADED ON THESE FOR EXTRA MEMORY
873  for (t = 0; t < maxstarC; t++)
874  {
875  if (t < maxdockC)
876  {
877  if (t == 0)
878  {
879  _sopen_s(&handle, "Meshes\\cutters.dix", _O_RDONLY | _O_BINARY | _O_SEQUENTIAL, _SH_DENYWR, _S_IWRITE);
880  if (handle == -1)
881  {
882  logger->Log("Viewscreen::OnCreateDevice() failed to load \"Meshes\\cutters.dix\"!", Logger::Level::Error);
883  char strerr[99];
884  strerror_s(strerr, 99, errno);
885  logger->Log(strerr, Logger::Level::Error);
886  }
887  }
888  else if (t == 1)
889  {
890  _sopen_s(&handle, "Meshes\\easydock.dix", _O_RDONLY | _O_BINARY | _O_SEQUENTIAL, _SH_DENYWR, _S_IWRITE);
891  if (handle == -1)
892  {
893  logger->Log("Viewscreen::OnCreateDevice() failed to load \"Meshes\\easydock.dix\"!", Logger::Level::Error);
894  char strerr[99];
895  strerror_s(strerr, 99, errno);
896  logger->Log(strerr, Logger::Level::Error);
897  }
898  }
899  else if (t == 2)
900  {
901  _sopen_s(&handle, "Meshes\\sentry station 12.dix", _O_RDONLY | _O_BINARY | _O_SEQUENTIAL, _SH_DENYWR, _S_IWRITE);
902  if (handle == -1)
903  {
904  logger->Log("Viewscreen::OnCreateDevice() failed to load \"Meshes\\sentry station 12.dix\"!", Logger::Level::Error);
905  char strerr[99];
906  strerror_s(strerr, 99, errno);
907  logger->Log(strerr, Logger::Level::Error);
908  }
909  }
910 
911  _lseek(handle, 0, SEEK_SET);
912  _read(handle, &allobjects[t].components, 2);
913 
914 
915  sprintf_s(msg, sizeof msg, "allobjects[%i].componentarray", t);
916  if (allobjects[t].componentarray)
917  {
918  SAFE_DELETE(allobjects[t].componentarray);
920  }
922  if (allobjects[t].componentarray == nullptr)
923  {
924  sprintf_s(msg, sizeof(msg), "Failed to initialize %i components for dock mesh %i", allobjects[t].components, t);
925  logger->Log(msg);
926  return E_OUTOFMEMORY;
927  }
928  gameclass->AddTrackedResource(msg); // managed, memory only
929 
930 
931  sprintf_s(msg, sizeof(msg), "Initialized %i components for dock mesh %i", allobjects[t].components, t);
932  logger->Log(msg);
933 
934  for (s = 0; s < allobjects[t].components; s++)
935  {
936  _lseek(handle, s * 100L + 99L, SEEK_SET); // To 0
937  _read(handle, &i_temp, 2); // 2
938  allobjects[t].componentarray[s].startvertex = (UINT)i_temp;
939  _read(handle, &i_temp, 2); // 4
940  allobjects[t].componentarray[s].primitives = (UINT)i_temp;
941  _read(handle, &allobjects[t].componentarray[s].nominalxyz, 12); // 16
942  _read(handle, &allobjects[t].componentarray[s].nominalypr, 12); // 28
943  _read(handle, &allobjects[t].componentarray[s].boundsphere, 4); // 32
944  _read(handle, &allobjects[t].componentarray[s].extendby, 12); // 44
945  _read(handle, &allobjects[t].componentarray[s].texture, 2); // 46
946 
947  // 12 unused bytes
948 
949  _lseek(handle, 12, SEEK_CUR); // To 58
950  _read(handle, &allobjects[t].componentarray[s].type, 1); // 59
951 
952  allobjects[t].componentarray[s].extended = 0.0f; // Current extended %
953  }
954  _close(handle);
955  }
956  else
957  {
958  allobjects[t].components = 0;
959  }
960  }
961 
962 
963 
964 
965  // STATIC STARS STUFF
966  _sopen_s(&handle, "Meshes\\starlist.daw", _O_RDONLY | _O_BINARY | _O_SEQUENTIAL, _SH_DENYWR, _S_IWRITE);
967  if (handle == -1)
968  {
969  logger->Log("Viewscreen::OnCreateDevice() failed to load \"Meshes\\STARLIST.DAW\"!", Logger::Level::Error);
970  char strerr[99];
971  strerror_s(strerr, 99, errno);
972  logger->Log(strerr, Logger::Level::Error);
973  }
974 
975  D3DSTATICSTARS* vtxs;
976  D3DXVECTOR3 temp;
977  D3DXCOLOR tempcolor;
978  unsigned char chtemp;
979 
980  // Lock the vertex buffer
981  V(m_avStaticStars->Lock(0, 0, reinterpret_cast<void**>(&vtxs), 0));
982 
983  for (t = 0; t < starsC; t++)
984  {
985  _lseek(handle, static_cast<long>(t) * 19L, SEEK_SET); // To 28
986  _read(handle, &temp, 12);
987 
988  D3DXVec3Normalize(&temp, &temp);
989  (*vtxs).x = temp.x; (*vtxs).y = temp.y; (*vtxs).z = temp.z;
990 
991  _read(handle, &f_temp, 4);
992  (*vtxs).psize = powf(f_temp, 2.512f) * 4.0f; // 4 pixels across for smallest one
993 
994  _read(handle, &chtemp, 1); tempcolor.r = static_cast<float>(chtemp) / 255.0f;
995  _read(handle, &chtemp, 1); tempcolor.g = static_cast<float>(chtemp) / 255.0f;
996  _read(handle, &chtemp, 1); tempcolor.b = static_cast<float>(chtemp) / 255.0f;
997  (*vtxs++).diffuse = tempcolor;
998  }
999 
1000  V(m_avStaticStars->Unlock());
1001 
1002 
1003  D3DDISPLAYMODE mode;
1004  pd3dDevice->GetDisplayMode(0, &mode);
1005 
1006  if (FAILED(hr = D3DXCreateRenderToSurface(pd3dDevice, 907, 352, mode.Format, true, D3DFMT_D24S8, &m_pRenderToSurface)))
1007  {
1008  logger->Log("Could not CreateRenderToSurface for size 1", Logger::Level::Error);
1009  return hr;
1010  }
1011  gameclass->AddTrackedResource("m_pRenderToSurface", D3DPOOL_FORCE_DWORD);
1012 
1013  if (FAILED(hr = D3DXCreateRenderToSurface(pd3dDevice, 1135, 388, mode.Format, true, D3DFMT_D24S8, &m_pRenderToSurfaceNextGen)))
1014  {
1015  logger->Log("Could not CreateRenderToSurface for size NextGen", Logger::Level::Error);
1016  return hr;
1017  }
1018  gameclass->AddTrackedResource("m_pRenderToSurfaceNextGen", D3DPOOL_FORCE_DWORD);
1019 
1020  if (FAILED(hr = D3DXCreateRenderToSurface(pd3dDevice, 256, 128, mode.Format, false, D3DFMT_UNKNOWN, &m_pHullRender2Surface)))
1021  {
1022  logger->Log("Could not CreateRenderToSurface for size 2", Logger::Level::Error);
1023  return hr;
1024  }
1025  gameclass->AddTrackedResource("m_pHullRender2Surface", D3DPOOL_FORCE_DWORD);
1026 
1027 
1029 
1030 
1031  // Check to see if device supports visibility query
1032  m_bDeviceSupportsVizQuery = pd3dDevice->CreateQuery(D3DQUERYTYPE_OCCLUSION, nullptr) == D3D_OK;
1033 
1034  ptrInstruments->OnCreateDevice(pd3dDevice);
1035 
1036  logger->Log("Viewscreen::OnCreateDevice() exiting successfully!");
1037 
1038  return S_OK;
1039 }
1040 
1042 {
1043  logger->AddToCallStack("Viewscreen::SetProjectionMatrices");
1044 
1045  f_compareFOV = sqrtf(powf(g_fFOV * 0.5f, 2.0f) + powf(g_fFOV * 0.5f * fAspect, 2.0f));
1046  D3DXMatrixPerspectiveRH(&matrixProj, nearplaneC * tanf(g_fFOV * 0.5f), nearplaneC * tanf(g_fFOV * 0.5f) * fAspect, nearplaneC, farplaneC);
1047  D3DXMatrixPerspectiveRH(&matrixProjSim, nearplaneC * tanf(g_fFOV * 0.56f), nearplaneC * tanf(g_fFOV * 0.56f) * fAspect, nearplaneC, farplaneC);
1048  D3DXMatrixPerspectiveRH(&matrixProjnodistort, nearplaneC * tanf(D3DXToRadian(115.0f) * 0.5f), nearplaneC * tanf(D3DXToRadian(115.0f) * 0.5f) * fAspect, nearplaneC, farplaneC);
1049  D3DXMatrixPerspectiveRH(&matrixProjCock, cockplanenearC * tanf(g_fFOV * 0.5f), cockplanenearC * tanf(g_fFOV * 0.5f) * fAspect, cockplanenearC, cockplanefarC);
1050  D3DXMATRIX matrixTemp;
1051  D3DXMatrixRotationZ(&matrixTemp, D3DX_PI); // ANSI standard is upside-down
1052  D3DXMatrixMultiply(&matrixProj, &matrixTemp, &matrixProj);
1053  D3DXMatrixMultiply(&matrixProjSim, &matrixTemp, &matrixProjSim);
1054  // for velocity vector and other tactical displays
1055  D3DXMatrixMultiply(&matrixProjnodistort, &matrixTemp, &matrixProjnodistort);
1056  D3DXMatrixMultiply(&matrixProjCock, &matrixTemp, &matrixProjCock);
1057 }
1058 
1059 HRESULT Viewscreen::OnResetDevice(IDirect3DDevice9* pd3dDevice, const D3DSURFACE_DESC* pBackBufferSurfaceDesc)
1060 {
1061  logger->AddToCallStack("Viewscreen::OnResetDevice 1");
1062 
1063  if (m_pFont == nullptr) // Create Device wasn't called yet
1064  {
1065  logger->Log("OnResetDevice before OnCreateDevice?", Logger::Level::Debug);
1066  return S_OK;
1067  }
1068 
1069  logger->Log("Viewscreen::OnResetDevice() called!");
1070 
1071  logger->AddToCallStack("Viewscreen::OnResetDevice 2");
1072 
1073  HRESULT hr;
1074 
1075  m_pFont->OnResetDevice();
1076  gameclass->UpdateTrackedResource("m_pFont", 2);
1077 
1078  if (m_pFontLicense == nullptr)
1079  logger->Log("Viewscreen::OnResetDevice m_pFontLicense is nullptr!", Logger::Fatal);
1080  m_pFontLicense->OnResetDevice();
1081  gameclass->UpdateTrackedResource("m_pFontLicense", 2);
1082  if (m_pFont3 == nullptr)
1083  logger->Log("Viewscreen::OnResetDevice m_pFont3 is nullptr!", Logger::Fatal);
1084  m_pFont3->OnResetDevice();
1085  gameclass->UpdateTrackedResource("m_pFont3", 2);
1086  if (m_pFontHull == nullptr)
1087  logger->Log("Viewscreen::OnResetDevice m_pFontHull is nullptr!", Logger::Fatal);
1088  m_pFontHull->OnResetDevice();
1089  gameclass->UpdateTrackedResource("m_pFontHull", 2);
1090  if (m_spriteVector == nullptr)
1091  logger->Log("Viewscreen::OnResetDevice m_spriteVector is nullptr!", Logger::Fatal);
1092  m_spriteVector->OnResetDevice();
1093  gameclass->UpdateTrackedResource("m_spriteVector", 2);
1094  if (m_pRenderToSurface == nullptr)
1095  logger->Log("Viewscreen::OnResetDevice m_pRenderToSurface is nullptr!", Logger::Fatal);
1096  m_pRenderToSurface->OnResetDevice();
1097  gameclass->UpdateTrackedResource("m_pRenderToSurface", 2);
1098  if (m_pRenderToSurfaceNextGen == nullptr)
1099  logger->Log("Viewscreen::OnResetDevice m_pRenderToSurfaceNextGen is nullptr!", Logger::Fatal);
1100  m_pRenderToSurfaceNextGen->OnResetDevice();
1101  gameclass->UpdateTrackedResource("m_pRenderToSurfaceNextGen", 2);
1102  if (m_pHullRender2Surface == nullptr)
1103  logger->Log("Viewscreen::OnResetDevice m_pHullRender2Surface is nullptr!", Logger::Fatal);
1104  m_pHullRender2Surface->OnResetDevice();
1105  gameclass->UpdateTrackedResource("m_pHullRender2Surface", 2);
1106 
1107  logger->AddToCallStack("Viewscreen::OnResetDevice 3");
1108 
1109  // Set any appropriate state
1110 // pd3dDevice->SetRenderState( D3DRS_AMBIENT, 0L ); // 0L is default
1111  pd3dDevice->SetRenderState(D3DRS_ZENABLE, D3DZB_TRUE);//USEW ); // false is default with exceptions
1112 // pd3dDevice->SetRenderState( D3DRS_FILLMODE, D3DFILL_SOLID ); // SOLID is default
1113 // pd3dDevice->SetRenderState( D3DRS_SHADEMODE, D3DSHADE_GOURAUD ); // GOURAUD is default
1114 // pd3dDevice->SetRenderState( D3DRS_DITHERENABLE, false ); // false is default
1115 // pd3dDevice->SetRenderState( D3DRS_SPECULARENABLE, false ); // false is default
1116 // pd3dDevice->SetRenderState( D3DRS_LOCALVIEWER, true ); // true is default
1117 // pd3dDevice->SetRenderState( D3DRS_ANTIALIASEDLINEENABLE, true ); // false is default
1118  pd3dDevice->SetRenderState(D3DRS_STENCILENABLE, true); //g_bAboveClouds ); // false is default
1119 // pd3dDevice->SetRenderState( D3DRS_CLIPPING, true ); // true is default
1120 // pd3dDevice->SetRenderState( D3DRS_LIGHTING, true ); // true is default
1121  pd3dDevice->SetRenderState(D3DRS_NORMALIZENORMALS, true); // false is default
1122  pd3dDevice->SetRenderState(D3DRS_MULTISAMPLEANTIALIAS, true);
1123 
1124  // @todo get rid of this block when we switch BCL cloud bases to use shaders
1125  // pd3dDevice->SetRenderState(D3DRS_FOGENABLE, false); // false is default, only used for BCL cloud bases
1126  pd3dDevice->SetRenderState(D3DRS_FOGVERTEXMODE, D3DFOG_LINEAR);
1127  // pd3dDevice->SetRenderState( D3DRS_FOGSTART, 0.0f ); // 0.0f is default
1128  pd3dDevice->SetRenderState(D3DRS_RANGEFOGENABLE, true); // false is default
1129 
1130  pd3dDevice->SetRenderState(D3DRS_COLORWRITEENABLE, //D3DCOLORWRITEENABLE_ALPHA |
1131  D3DCOLORWRITEENABLE_BLUE |
1132  D3DCOLORWRITEENABLE_GREEN |
1133  D3DCOLORWRITEENABLE_RED);
1134 
1135  pd3dDevice->SetRenderState(D3DRS_POINTSPRITEENABLE, true); // false is default
1136 // pd3dDevice->SetRenderState( D3DRS_POINTSCALEENABLE, false ); // false is default
1137 
1138 // pd3dDevice->SetSamplerState( 0, D3DSAMP_BORDERCOLOR, 0L ); // 0L is default
1139 
1140  logger->AddToCallStack("Viewscreen::OnResetDevice 4");
1141 
1142  // pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE ); // TEXTURE is default
1143  // pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_MODULATE ); // MODULATE is default
1144  // pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE ); // TEXTURE is default
1145  pd3dDevice->SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE); // CURRENT is default
1146 
1147  logger->AddToCallStack("Viewscreen::OnResetDevice 5");
1148 
1149  // Get the aspect ratio
1150  fAspect = (float)pBackBufferSurfaceDesc->Height / (float)pBackBufferSurfaceDesc->Width;
1151 
1153 
1154  logger->AddToCallStack("Viewscreen::OnResetDevice 6");
1155 
1156  // Set up the material
1157  restore.Diffuse.r = 1.0f; restore.Diffuse.g = 1.0f; restore.Diffuse.b = 1.0f; restore.Diffuse.a = 0.0f;
1158  restore.Ambient = restore.Diffuse;
1159  restore.Emissive.r = 0.0f; restore.Emissive.g = 0.0f; restore.Emissive.b = 0.0f; restore.Emissive.a = 0.0f;
1160  restore.Specular = restore.Emissive;
1161  restore.Power = 0.0f;
1162  pd3dDevice->SetMaterial(&restore);
1163 
1164  logger->AddToCallStack("Viewscreen::OnResetDevice 7");
1165 
1166  // Set up the sunlight ----------------------------------------------------------------------
1167  ZeroMemory(&sunlight, sizeof D3DLIGHT9);
1168  sunlight.Type = D3DLIGHT_DIRECTIONAL;
1169  D3DCOLORVALUE h;
1170  h.r = sunrC; h.g = sungC; h.b = sunbC; h.a = 0.0f; // Based on middle radius sunmap.bmp
1171  sunlight.Diffuse = h;
1172  pd3dDevice->SetLight(0, &sunlight);
1173  pd3dDevice->LightEnable(0, true);
1174  // Set up the sunlight ----------------------------------------------------------------------
1175 
1176  logger->AddToCallStack("Viewscreen::OnResetDevice 8");
1177 
1178  // Set up the first-person headlight --------------------------------------------------------
1179  ZeroMemory(&headlight, sizeof D3DLIGHT9);
1180  headlight.Type = D3DLIGHT_SPOT;
1181  headlight.Range = 2.0f;
1182  headlight.Falloff = 1.0f;
1183  headlight.Attenuation0 = 0.0f;
1184  headlight.Attenuation1 = 15.0f;
1185  headlight.Attenuation2 = 0.0f;
1186  headlight.Theta = 0.1f;
1187  headlight.Phi = 0.2f;
1188  h.r = 1.0f; h.g = 1.0f; h.b = 0.75f; h.a = 0.0f;
1189  headlight.Diffuse = h;
1190  pd3dDevice->SetLight(1, &headlight);
1191  // Set up the first-person headlight --------------------------------------------------------
1192 
1193  logger->AddToCallStack("Viewscreen::OnResetDevice 9");
1194 
1195  logger->Log("Viewscreen::OnResetDevice creating vertex buffers...");
1196 
1197  if (!m_avSkyDome)
1198  {
1199  if (FAILED(hr = pd3dDevice->CreateVertexBuffer((skydomeC + 2) * sizeof(D3DSKYDOME),
1200  D3DUSAGE_WRITEONLY | D3DUSAGE_DYNAMIC, D3DFVF_SKYDOME,
1201  D3DPOOL_DEFAULT, &m_avSkyDome, NULL)))
1202  return hr;
1203  gameclass->AddTrackedResource("m_avSkyDome", D3DPOOL_DEFAULT);
1204  }
1205 
1206  if (!m_avSkyRing)
1207  {
1208  if (FAILED(hr = pd3dDevice->CreateVertexBuffer((skydomeC * 2 + 2) * sizeof(D3DSKYRING),
1209  D3DUSAGE_WRITEONLY | D3DUSAGE_DYNAMIC, D3DFVF_SKYRING,
1210  D3DPOOL_DEFAULT, &m_avSkyRing, NULL)))
1211  return hr;
1212  gameclass->AddTrackedResource("m_avSkyRing", D3DPOOL_DEFAULT);
1213  }
1214 
1215  if (!m_avScreen)
1216  {
1217  if (FAILED(hr = pd3dDevice->CreateVertexBuffer(4 * sizeof(D3DSCREEN),
1218  D3DUSAGE_WRITEONLY | D3DUSAGE_DYNAMIC, D3DFVF_SCREEN,
1219  D3DPOOL_DEFAULT, &m_avScreen, NULL)))
1220  return hr;
1221  gameclass->AddTrackedResource("m_avScreen", D3DPOOL_DEFAULT);
1222  }
1223 
1224  if (!m_avInstrument)
1225  {
1226  if (FAILED(hr = pd3dDevice->CreateVertexBuffer(12 * sizeof(D3DINSTRUMENT),
1227  D3DUSAGE_WRITEONLY | D3DUSAGE_DYNAMIC, D3DFVF_INSTRUMENT,
1228  D3DPOOL_DEFAULT, &m_avInstrument, NULL)))
1229  return hr;
1230  gameclass->AddTrackedResource("m_avInstrument", D3DPOOL_DEFAULT);
1231  }
1232 
1233  if (!m_avLightning)
1234  {
1235  if (FAILED(hr = pd3dDevice->CreateVertexBuffer(3L * ACLlightningC * sizeof(D3DSKYRING),
1236  D3DUSAGE_WRITEONLY | D3DUSAGE_DYNAMIC, D3DFVF_SKYRING,
1237  D3DPOOL_DEFAULT, &m_avLightning, NULL)))
1238  return hr;
1239  gameclass->AddTrackedResource("m_avLightning", D3DPOOL_DEFAULT);
1240  }
1241 
1242  if (!m_avRainDrops)
1243  {
1244  if (FAILED(hr = pd3dDevice->CreateVertexBuffer(MAX_RAINDROPS * sizeof(D3DRAINDROP) * 2L,
1245  D3DUSAGE_WRITEONLY | D3DUSAGE_DYNAMIC, D3DFVF_RAINDROP,
1246  D3DPOOL_DEFAULT, &m_avRainDrops, NULL)))
1247  {
1248  sprintf_s(msg, sizeof msg, "CreateVertexBuffer (m_avRainDrops) returned %x", hr);
1249  logger->Log(msg, Logger::Level::Fatal);
1250  }
1251  else
1252  {
1253  gameclass->AddTrackedResource("m_avRainDrops", D3DPOOL_DEFAULT);
1254  }
1255  }
1256 
1257  logger->Log("Viewscreen::OnResetDevice() created all dynamic vertex and index buffers!");
1258 
1259  logger->AddToCallStack("Viewscreen::OnResetDevice 10");
1260 
1262  {
1263  if (FAILED(hr = pd3dDevice->CreateQuery(D3DQUERYTYPE_OCCLUSION, &m_pLightSunVizQuery)))
1264  {
1265  logger->Log("Viewscreen::OnResetDevice() failed to CreateQuery even through device previously claimed to support it!", Logger::Fatal);
1266  return hr;
1267  }
1268  gameclass->AddTrackedResource("m_pLightSunVizQuery", D3DPOOL_FORCE_DWORD);
1269  }
1270 
1271  logger->AddToCallStack("Viewscreen::OnResetDevice 11");
1272 
1273  // Dynamic textures ------------------------------------------------------------------
1274  if (ourcockpit.texturelib)
1275  ptrCockpit->OnResetDevice(pd3dDevice);
1276 
1277  logger->AddToCallStack("Viewscreen::OnResetDevice 12");
1278 
1279  if (FAILED(hr = D3DXCreateTexture(pd3dDevice, 1135, 388, 1, D3DUSAGE_RENDERTARGET,
1280  D3DFMT_R8G8B8, D3DPOOL_DEFAULT, &m_pddsProjectionTexture)))
1281  {
1282  logger->Log("Viewscreen::OnResetDevice() failed to create projection texture!", Logger::Fatal);
1283  return hr;
1284  }
1285  gameclass->AddTrackedResource("m_pddsProjectionTexture", D3DPOOL_DEFAULT);
1286 
1287  if (FAILED(hr = m_pddsProjectionTexture->GetSurfaceLevel(0, &m_pddsProjectionSurface)))
1288  {
1289  logger->Log("Viewscreen::OnResetDevice() failed to get projection surface!", Logger::Fatal);
1290  return hr;
1291  }
1292  gameclass->AddTrackedResource("m_pddsProjectionSurface", D3DPOOL_DEFAULT);
1293 
1294  ptrInstruments->OnResetDevice(pd3dDevice, pBackBufferSurfaceDesc);
1295 
1296  logger->Log("Viewscreen::OnResetDevice() exited successfully!");
1297 
1298  logger->AddToCallStack("Viewscreen::OnResetDevice END");
1299 
1300  return S_OK;
1301 }
1302 
1304 {
1305  logger->AddToCallStack("Viewscreen::OnLostDevice");
1306  logger->Log("ViewScreen::OnLostDevice() called!");
1307 
1308 
1309  // pd3dDevice->SetTexture( 0, NULL );
1310  // pd3dDevice->SetTexture( 1, NULL );
1311  // pd3dDevice->SetTexture( 2, NULL );
1312  // pd3dDevice->SetTexture( 3, NULL );
1313  // pd3dDevice->SetTexture( 4, NULL );
1314  // pd3dDevice->SetStreamSource( 0, NULL, 0, 0 );
1315 
1316  //Throws exeption here because the stuff below is no longer set
1317 
1318 
1319  if (m_pFont)
1320  {
1321  m_pFont->OnLostDevice();
1322  gameclass->UpdateTrackedResource("m_pFont", 1);
1323  }
1324  if (m_pFontLicense)
1325  {
1326  m_pFontLicense->OnLostDevice();
1327  gameclass->UpdateTrackedResource("m_pFontLicense", 1);
1328  }
1329  if (m_pFont3)
1330  {
1331  m_pFont3->OnLostDevice();
1332  gameclass->UpdateTrackedResource("m_pFont3", 1);
1333  }
1334  if (m_pFontHull)
1335  {
1336  m_pFontHull->OnLostDevice();
1337  gameclass->UpdateTrackedResource("m_pFontHull", 1);
1338  }
1339 
1340  m_spriteVector->OnLostDevice();
1341  gameclass->UpdateTrackedResource("m_spriteVector", 1);
1342  m_pRenderToSurface->OnLostDevice();
1343  gameclass->UpdateTrackedResource("m_pRenderToSurface", 1);
1344  m_pRenderToSurfaceNextGen->OnLostDevice();
1345  gameclass->UpdateTrackedResource("m_pRenderToSurfaceNextGen", 1);
1346  m_pHullRender2Surface->OnLostDevice();
1347  gameclass->UpdateTrackedResource("m_pHullRender2Surface", 1);
1348 
1349 
1350  // Release dynamic vertex/index buffers
1351  if (m_avSkyDome)
1352  {
1353  SAFE_RELEASE(m_avSkyDome);
1354  gameclass->UpdateTrackedResource("m_avSkyDome", 1);
1355  }
1356  if (m_avSkyRing)
1357  {
1358  SAFE_RELEASE(m_avSkyRing);
1359  gameclass->UpdateTrackedResource("m_avSkyRing", 1);
1360  }
1361  if (m_avScreen)
1362  {
1363  SAFE_RELEASE(m_avScreen);
1364  gameclass->UpdateTrackedResource("m_avScreen", 1);
1365  }
1366  if (m_avInstrument)
1367  {
1368  SAFE_RELEASE(m_avInstrument);
1369  gameclass->UpdateTrackedResource("m_avInstrument", 1);
1370  }
1371  if (m_avLightning)
1372  {
1373  SAFE_RELEASE(m_avLightning);
1374  gameclass->UpdateTrackedResource("m_avLightning", 1);
1375  }
1376  if (m_avRainDrops)
1377  {
1378  SAFE_RELEASE(m_avRainDrops);
1379  gameclass->UpdateTrackedResource("m_avRainDrops", 1);
1380  }
1381  if (m_pLightSunVizQuery)
1382  {
1383  SAFE_RELEASE(m_pLightSunVizQuery);
1384  gameclass->UpdateTrackedResource("m_pLightSunVizQuery", 1);
1385  }
1386 
1388 
1390  {
1391  SAFE_RELEASE(m_pddsProjectionTexture);
1392  gameclass->UpdateTrackedResource("m_pddsProjectionTexture", 1);
1393  }
1395  {
1396  SAFE_RELEASE(m_pddsProjectionSurface);
1397  gameclass->UpdateTrackedResource("m_pddsProjectionSurface", 1);
1398  }
1399 
1400  for (short t = 0; t < MAX_SCAN; t++)
1401  {
1402  if (m_pddsHullDynamicTexture[t])
1403  {
1404  sprintf_s(msg, sizeof(msg), "Viewscreen::OnLostDevice released m_pddsHullDynamicTexture slot %i!", t);
1405  logger->Log(msg);
1406  SAFE_RELEASE(m_pddsHullDynamicTexture[t]);
1407  sprintf_s(msg, sizeof(msg), "m_pddsHullDynamicTexture[%i]", t);
1409  }
1410  }
1411 
1413 
1414  logger->Log("Viewscreen::OnLostDevice() exited successfully!");
1415 }
1416 
1418 {
1419  logger->AddToCallStack("Viewscreen::OnDestroyDevice");
1420  logger->Log("Viewscreen::OnDestroyDevice() called!");
1421 
1422  SAFE_RELEASE(m_pddsWorld2a1);
1423  gameclass->UpdateTrackedResource("m_pddsWorld2a1", 3);
1424  SAFE_RELEASE(m_pddsCloudBaseMap);
1425  gameclass->UpdateTrackedResource("m_pddsCloudBaseMap", 3);
1426  SAFE_RELEASE(m_pddsCloudDetailAbove);
1427  gameclass->UpdateTrackedResource("m_pddsCloudDetailAbove", 3);
1428  SAFE_RELEASE(m_pddsCloudDetailBelow);
1429  gameclass->UpdateTrackedResource("m_pddsCloudDetailBelow", 3);
1430  SAFE_RELEASE(m_pddsBinoculars);
1431  gameclass->UpdateTrackedResource("m_pddsBinoculars", 3);
1432  SAFE_RELEASE(m_pddsBinocularsCompass);
1433  gameclass->UpdateTrackedResource("m_pddsBinocularsCompass", 3);
1434  SAFE_RELEASE(m_pddsBinocularsArrow);
1435  gameclass->UpdateTrackedResource("m_pddsBinocularsArrow", 3);
1436  SAFE_RELEASE(m_pddsSunglasses);
1437  gameclass->UpdateTrackedResource("m_pddsSunglasses", 3);
1438  SAFE_RELEASE(m_pddsSunTexture);
1439  gameclass->UpdateTrackedResource("m_pddsSunTexture", 3);
1440  SAFE_RELEASE(m_pddsStarTexture);
1441  gameclass->UpdateTrackedResource("m_pddsStarTexture", 3);
1442  SAFE_RELEASE(m_pddsHolidayTexture);
1443  gameclass->UpdateTrackedResource("m_pddsHolidayTexture", 3);
1444 
1445  // Interface
1446  SAFE_RELEASE(m_pddsLetters);
1447  gameclass->UpdateTrackedResource("m_pddsLetters", 3);
1448 
1449  SAFE_RELEASE(m_pddsMarston1);
1450  gameclass->UpdateTrackedResource("m_pddsMarston1", 3);
1451  SAFE_RELEASE(m_pddsRunwayEdgeLight1);
1452  gameclass->UpdateTrackedResource("m_pddsRunwayEdgeLight1", 3);
1453  SAFE_RELEASE(m_pddsRoad);
1454  gameclass->UpdateTrackedResource("m_pddsRoad", 3);
1455  SAFE_RELEASE(m_pddsIntersection);
1456  gameclass->UpdateTrackedResource("m_pddsIntersection", 3);
1457 
1458  logger->AddToCallStack("Viewscreen::OnDestroyDevice1");
1459 
1460  short t;
1461  for (t = 1; t < shiptextureC; t++)
1462  {
1463  SAFE_RELEASE(m_pddsShipTexture[t]);
1464  sprintf_s(msg, 99, "m_pddsShipTexture[%i]", t);
1466  if (m_pddsShipLights[t])
1467  {
1468  SAFE_RELEASE(m_pddsShipLights[t]);
1469  sprintf_s(msg, 99, "m_pddsShipLights[%i]", t);
1471  }
1472  }
1473  for (t = 1; t < citytextureC; t++)
1474  {
1475  SAFE_RELEASE(m_pddsCityTexture[t]);
1476  sprintf_s(msg, 99, "m_pddsCityTexture[%i]", t);
1478  if (m_pddsCityLights[t])
1479  {
1480  SAFE_RELEASE(m_pddsCityLights[t]);
1481  sprintf_s(msg, 99, "m_pddsCityLights[%i]", t);
1483  }
1484  }
1485  for (t = 1; t < RTStextureC; t++)
1486  {
1487  if (m_pddsRTSTexture[t])
1488  {
1489  SAFE_RELEASE(m_pddsRTSTexture[t]);
1490  sprintf_s(msg, 99, "m_pddsRTSTexture[%i]", t);
1492  }
1493  if (m_pddsRTSLights[t])
1494  {
1495  SAFE_RELEASE(m_pddsRTSLights[t]);
1496  sprintf_s(msg, 99, "m_pddsRTSLights[%i]", t);
1498  }
1499  }
1500 
1501  for (t = 0; t < landformtextureC; t++)
1502  {
1503  SAFE_RELEASE(m_pddsLandform[t]);
1504  sprintf_s(msg, 99, "m_pddsLandform[%i]", t);
1506  }
1507 
1508  for (t = 0; t < transitiontextureC; t++)
1509  {
1510  SAFE_RELEASE(m_pddsTransition[t]);
1511  sprintf_s(msg, 99, "m_pddsTransition[%i]", t);
1513  }
1514 
1515  SAFE_RELEASE(m_pddsWaterNormal);
1516  gameclass->UpdateTrackedResource("m_pddsWaterNormal", 3);
1517 
1518 #ifndef skipAnimations
1519  for (t = 0; t < weaponanimateC; t++)
1520  {
1521  SAFE_RELEASE(m_pddsWeapon[t]);
1522  sprintf_s(msg, 99, "m_pddsWeapon[%i]", t);
1524  SAFE_RELEASE(m_pddsSinker[t]);
1525  sprintf_s(msg, 99, "m_pddsSinker[%i]", t);
1527  }
1528 
1529  SAFE_RELEASE(m_pddsFuzerX);
1530  gameclass->UpdateTrackedResource("m_pddsFuzerX", 3);
1531  SAFE_RELEASE(m_pddsSinkerX);
1532  gameclass->UpdateTrackedResource("m_pddsSinkerX", 3);
1533  SAFE_RELEASE(m_pddsBlastX);
1534  gameclass->UpdateTrackedResource("m_pddsBlastX", 3);
1535 
1536 #ifdef smoketestC
1537  for (t = 0; t < smoketrailC; t++)
1538  SAFE_RELEASE(m_pddsSmoke[t]);
1539 #endif
1540 
1541  for (t = 0; t < dihvanimateC; t++)
1542  {
1543  SAFE_RELEASE(m_pddsDIHV[t]);
1544  sprintf_s(msg, 99, "m_pddsDIHV[%i]", t);
1546  }
1547  for (t = 0; t < heartanimateC; t++)
1548  {
1549  SAFE_RELEASE(m_pddsHeart[t]);
1550  sprintf_s(msg, 99, "m_pddsHeart[%i]", t);
1552  }
1553  for (t = 0; t < firework1C; t++)
1554  {
1555  SAFE_RELEASE(m_pddsFirework1[t]);
1556  sprintf_s(msg, 99, "m_pddsFirework1[%i]", t);
1558  }
1559  for (t = 0; t < firework2C; t++)
1560  {
1561  SAFE_RELEASE(m_pddsFirework2[t]);
1562  sprintf_s(msg, 99, "m_pddsFirework2[%i]", t);
1564  }
1565  for (t = 0; t < firework3C; t++)
1566  {
1567  SAFE_RELEASE(m_pddsFirework3[t]);
1568  sprintf_s(msg, 99, "m_pddsFirework3[%i]", t);
1570  }
1571 
1572  SAFE_RELEASE(m_pddsReentry);
1573  gameclass->UpdateTrackedResource("m_pddsReentry", 3);
1574 #endif
1575 
1576  for (t = 0; t < elmoAnimateC; t++)
1577  {
1578  SAFE_RELEASE(m_pddsElmo[t]);
1579  sprintf_s(msg, 99, "m_pddsElmo[%i]", t);
1581  }
1582 
1583  //SAFE_RELEASE(m_pddsTempHuman);
1584  //gameclass->UpdateTrackedResource("m_pddsTempHuman");
1585  //SAFE_RELEASE(m_pddsTempHumanHead);
1586  //gameclass->UpdateTrackedResource("m_pddsTempHumanHead");
1587 
1588  for (t = 0; t < 3; t++)
1589  {
1590  SAFE_RELEASE(m_pddsLightningBelow[t]);
1591  sprintf_s(msg, 99, "m_pddsLightningBelow[%i]", t);
1593  SAFE_RELEASE(m_pddsLightningAbove[t]);
1594  sprintf_s(msg, 99, "m_pddsLightningAbove[%i]", t);
1596  }
1597 
1598  SAFE_RELEASE(m_pddsAtmosphere);
1599  gameclass->UpdateTrackedResource("m_pddsAtmosphere", 3);
1600 
1601 #ifdef treetestC
1602  SAFE_RELEASE(m_pddsTree);
1603  UpdateTrackedResource("m_pddsTree");
1604 #endif
1605 
1606  // THESE ARE FROM COCKPIT.CPP
1607  if (m_pddsNamePlate)
1608  {
1609  SAFE_RELEASE(m_pddsNamePlate);
1610  gameclass->UpdateTrackedResource("m_pddsNamePlate", 3);
1611  }
1612 
1613  if (m_pddsGVBackground)
1614  {
1615  SAFE_RELEASE(m_pddsGVBackground);
1616  gameclass->UpdateTrackedResource("m_pddsGVBackground", 3);
1617  }
1618  if (m_pddsGVDialSmall)
1619  {
1620  SAFE_RELEASE(m_pddsGVDialSmall);
1621  gameclass->UpdateTrackedResource("m_pddsGVDialSmall", 3);
1622  }
1623  if (m_pddsAOA[0])
1624  {
1625  SAFE_RELEASE(m_pddsAOA[0]);
1626  gameclass->UpdateTrackedResource("m_pddsAOA[0]", 3);
1627  }
1628  if (m_pddsAOA[1])
1629  {
1630  SAFE_RELEASE(m_pddsAOA[1]);
1631  gameclass->UpdateTrackedResource("m_pddsAOA[1]", 3);
1632  }
1633  if (m_pddsAOA[2])
1634  {
1635  SAFE_RELEASE(m_pddsAOA[2]);
1636  gameclass->UpdateTrackedResource("m_pddsAOA[2]", 3);
1637  }
1639  {
1640  SAFE_RELEASE(m_pddsLightsCruiseIcons);
1641  gameclass->UpdateTrackedResource("m_pddsLightsCruiseIcons", 3);
1642  }
1643  if (m_pddsFuelIcon)
1644  {
1645  SAFE_RELEASE(m_pddsFuelIcon);
1646  gameclass->UpdateTrackedResource("m_pddsFuelIcon", 3);
1647  }
1648  if (m_pddsGVCompass)
1649  {
1650  SAFE_RELEASE(m_pddsGVCompass);
1651  gameclass->UpdateTrackedResource("m_pddsGVCompass", 3);
1652  }
1653  if (m_pddsGVDirection)
1654  {
1655  SAFE_RELEASE(m_pddsGVDirection);
1656  gameclass->UpdateTrackedResource("m_pddsGVDirection", 3);
1657  }
1658 
1659  SAFE_RELEASE(m_pddsKeycard);
1660  gameclass->UpdateTrackedResource("m_pddsKeycard", 3);
1661 
1662  for (t = 1; t < cockpittextureC; t++)
1663  {
1664  if (m_pddsCockpitTexture[t])
1665  {
1666  SAFE_RELEASE(m_pddsCockpitTexture[t]);
1667  sprintf_s(msg, 99, "m_pddsCockpitTexture[%i]", t);
1669  }
1670  if (m_pddsCockpitLights[t])
1671  {
1672  SAFE_RELEASE(m_pddsCockpitLights[t]);
1673  sprintf_s(msg, 99, "m_pddsCockpitLights[%i]", t);
1675  }
1676  }
1677  // Not reloaded with different cockpits
1678  SAFE_RELEASE(m_pddsInterlace[0]);
1679  gameclass->UpdateTrackedResource("m_pddsInterlace[0]", 3);
1680  SAFE_RELEASE(m_pddsInterlace[1]);
1681  gameclass->UpdateTrackedResource("m_pddsInterlace[1]", 3);
1683  {
1684  gameclass->UpdateTrackedResource("ourcockpit.componentarray", 3);
1685  SAFE_DELETE(ourcockpit.componentarray);
1686  ourcockpit.components = 0;
1687  }
1688  // THUS ENDS THE ONES FROM COCKPIT.CPP
1689 
1690  // THESE ARE FROM RNDRDCKS.CPP
1691 #ifndef skipDocks
1692  for (t = 1; t < docktextureC; t++)
1693  {
1694  SAFE_RELEASE(m_pddsDockTexture[t]);
1695  sprintf_s(msg, 99, "m_pddsDockTexture[%i]", t);
1697  if (m_pddsDockLights[t])
1698  {
1699  SAFE_RELEASE(m_pddsDockLights[t]);
1700  sprintf_s(msg, 99, "m_pddsDockLights[%i]", t);
1702  }
1703  }
1704 #endif
1705 
1706  for (t = 0; t < maxdockC; t++)
1707  {
1708  if (allobjects[t].componentarray)
1709  {
1710  SAFE_DELETE(allobjects[t].componentarray);
1711  sprintf_s(msg, sizeof msg, "allobjects[%i].componentarray", t);
1713  }
1714  }
1715 
1716  logger->AddToCallStack("Viewscreen::OnDestroyDevice2");
1717  // THESE ARE EITHER RENDER TARGETS, RENDER SURFACES, SPRITES, FONTS, ETC
1718 
1719  for (t = 0; t < MAX_SCAN; t++)
1720  {
1721  if (m_pddsHullDynamicTexture[t])
1722  {
1723  sprintf_s(msg, sizeof(msg), "Viewscreen::OnDestroyDevice released m_pddsHullDynamicTexture slot %i!", t);
1724  logger->Log(msg);
1725  SAFE_RELEASE(m_pddsHullDynamicTexture[t]);
1726  sprintf_s(msg, 99, "m_pddsHullDynamicTexture[%i]", t);
1728  }
1729 
1730  if (playerships[t].componentarray)
1731  {
1732  SAFE_DELETE(playerships[t].componentarray);
1733  playerships[t].components = 0;
1734  sprintf_s(msg, 99, "playerships[%i].componentarray", t);
1736  }
1737  }
1738 
1739 
1740  SAFE_RELEASE(m_pFont);
1741  gameclass->UpdateTrackedResource("m_pFont", 3);
1742  SAFE_RELEASE(m_pFontLicense);
1743  gameclass->UpdateTrackedResource("m_pFontLicense", 3);
1744  SAFE_RELEASE(m_pFont3);
1745  gameclass->UpdateTrackedResource("m_pFont3", 3);
1746  SAFE_RELEASE(m_pFontHull);
1747  gameclass->UpdateTrackedResource("m_pFontHull", 3);
1748 
1749  SAFE_RELEASE(m_pRenderToSurface);
1750  gameclass->UpdateTrackedResource("m_pRenderToSurface", 3);
1751  SAFE_RELEASE(m_pRenderToSurfaceNextGen);
1752  gameclass->UpdateTrackedResource("m_pRenderToSurfaceNextGen", 3);
1753  SAFE_RELEASE(m_pHullRender2Surface);
1754  gameclass->UpdateTrackedResource("m_pHullRender2Surface", 3);
1755 
1756  SAFE_RELEASE(m_spriteVector);
1757  gameclass->UpdateTrackedResource("m_spriteVector", 3);
1758 
1759  SAFE_RELEASE(m_pddsDynamicTexture);
1760  gameclass->UpdateTrackedResource("m_pddsDynamicTexture", 3);
1761  SAFE_RELEASE(m_pddsDynamicSurface);
1762  gameclass->UpdateTrackedResource("m_pddsDynamicSurface", 3);
1763 
1764 
1765  // Release static vertex/index buffers
1766  SAFE_RELEASE(m_avStaticStars);
1767  gameclass->UpdateTrackedResource("m_avStaticStars", 3);
1768  SAFE_RELEASE(m_avCone);
1769  gameclass->UpdateTrackedResource("m_avCone", 3);
1770  SAFE_RELEASE(m_avSunVertices);
1771  gameclass->UpdateTrackedResource("m_avSunVertices", 3);
1772 
1773  SAFE_RELEASE(m_avSkyDome);
1774  gameclass->UpdateTrackedResource("m_avSkyDome", 3);
1775  SAFE_RELEASE(m_avSkyRing);
1776  gameclass->UpdateTrackedResource("m_avSkyRing", 3);
1777  SAFE_RELEASE(m_avScreen);
1778  gameclass->UpdateTrackedResource("m_avScreen", 3);
1779  SAFE_RELEASE(m_avInstrument);
1780  gameclass->UpdateTrackedResource("m_avInstrument", 3);
1781  SAFE_RELEASE(m_avLightning);
1782  gameclass->UpdateTrackedResource("m_avLightning", 3);
1783  SAFE_RELEASE(m_avRainDrops);
1784  gameclass->UpdateTrackedResource("m_avRainDrops", 3);
1785  SAFE_RELEASE(m_pLightSunVizQuery);
1786  gameclass->UpdateTrackedResource("m_pLightSunVizQuery", 3);
1787  SAFE_RELEASE(m_pddsProjectionTexture);
1788  gameclass->UpdateTrackedResource("m_pddsProjectionTexture", 3);
1789  SAFE_RELEASE(m_pddsProjectionSurface);
1790  gameclass->UpdateTrackedResource("m_pddsProjectionSurface", 3);
1791 
1792 #ifdef treetestC
1793  SAFE_RELEASE(m_avTree);
1794 #endif
1795 
1796  SAFE_RELEASE(m_avRunningLights);
1797  gameclass->UpdateTrackedResource("m_avRunningLights", 3);
1798  SAFE_RELEASE(m_aiCloudGrid);
1799  gameclass->UpdateTrackedResource("m_aiCloudGrid", 3);
1800  SAFE_RELEASE(m_avCloudGrid);
1801  gameclass->UpdateTrackedResource("m_avCloudGrid", 3);
1802  //SAFE_RELEASE(m_aiLocalGrid);
1803  //gameclass->UpdateTrackedResource("m_aiLocalGrid");
1804  SAFE_RELEASE(m_avLocalGrid);
1805  gameclass->UpdateTrackedResource("m_avLocalGrid", 3);
1806 
1807  for (t = 0; t < maxpolyC; t++)
1808  {
1809  if (polyobjects[t].VB)
1810  {
1811  SAFE_RELEASE(polyobjects[t].VB);
1812  sprintf_s(msg, sizeof(msg), "polyobjects[%i].VB", t);
1814  }
1815  }
1816 
1817  logger->AddToCallStack("Viewscreen::OnDestroyDevice3a");
1818 
1819  int count1 = 0, count2 = 0, count3 = 0;
1820  for (t = 0; t < 16384; t++)
1821  {
1822  if (buffer1[t]) count1++;
1823  if (buffer2[t]) count2++;
1824  if (buffer3[t]) count3++;
1825  }
1826  if (count1 || count2 || count3)
1827  {
1828  sprintf_s(msg, sizeof msg, "My suspicion was correct: %i %i %i", count1, count2, count3);
1829  logger->Log(msg, Logger::Level::Error);
1830  }
1831 
1832  logger->AddToCallStack("Viewscreen::OnDestroyDevice3b");
1833 
1834  ptrGrid->geometryReady = false;
1835  ptrGrid->makeBuildings = true;
1836  ptrGrid->makeClouds = true;
1837  for (short l = 0; l < 64; l++)
1838  {
1839  for (short m = 0; m < 64; m++)
1840  {
1841  const short buildZoneOrdinal = gridarray[l][m].buildzoneOrdinal;
1842  if (buildZoneOrdinal != -1)
1843  {
1844  sprintf_s(msg, sizeof(msg), "OnDestroyDevice HG2 released VB slot %i!", buildZoneOrdinal);
1845  logger->Log(msg);
1846 
1847  SAFE_RELEASE(buildzone[buildZoneOrdinal].VB);
1848  sprintf_s(msg, sizeof(msg), "buildzone[%i].VB", buildZoneOrdinal);
1850 
1851  if (buildzone[buildZoneOrdinal].RTSVB)
1852  {
1853  SAFE_RELEASE(buildzone[buildZoneOrdinal].RTSVB);
1854  sprintf_s(msg, sizeof(msg), "buildzone[%i].RTSVB", buildZoneOrdinal);
1856  }
1857 
1859  buildzone[buildZoneOrdinal].effects.clear();
1860 
1861  if (buildzone[buildZoneOrdinal].rts)
1862  {
1863  SAFE_DELETE(buildzone[buildZoneOrdinal].rts);
1864  sprintf_s(msg, sizeof msg, "buildzone[%i].rts", buildZoneOrdinal);
1866  }
1867 
1868  if (buildzone[buildZoneOrdinal].componentarray)
1869  {
1870  SAFE_DELETE(buildzone[buildZoneOrdinal].componentarray);
1871  sprintf_s(msg, sizeof(msg), "buildzone[%i].componentarray", buildZoneOrdinal);
1873  }
1874  buildzone[buildZoneOrdinal].components = 0;
1875 
1876  if (buildzone[buildZoneOrdinal].rtscomponentarray)
1877  {
1878  SAFE_DELETE(buildzone[buildZoneOrdinal].rtscomponentarray);
1879  sprintf_s(msg, sizeof(msg), "buildzone[%i].rtscomponentarray", buildZoneOrdinal);
1881  }
1882  buildzone[buildZoneOrdinal].rtscomponents = 0;
1883 
1884  gridarray[l][m].buildzoneOrdinal = -1;
1885  }
1886  }
1887  }
1888 
1889  logger->AddToCallStack("Viewscreen::OnDestroyDevice4");
1890 
1891  for (t = 0; t < maxstarC; t++)
1892  SAFE_DELETE(allobjects[t].componentarray);
1893 
1894  logger->AddToCallStack("Viewscreen::OnDestroyDevice5");
1895 
1896  SAFE_DELETE(polyextras2.vertexbackup);
1897 
1899 
1901 
1902  SAFE_RELEASE(g_pDI);
1903 
1904  logger->AddToCallStack("Viewscreen::OnDestroyDevice DONE");
1905  logger->Log("Viewscreen::OnDestroyDevice() exited successfully!");
1906 }
1907 
1909 {
1910  for (UINT i = 0; i < sofTracking.size(); i++)
1911  {
1912  std::string text = " --> " + sofTracking.at(i);
1913  logger->Log(text.c_str());
1914  }
1915  sprintf_s(msg, sizeof(msg), " === X%7.3f Y%7.3f Z%7.3f total", sumofforces.x, sumofforces.y, sumofforces.z);
1917 }
1918 
1920 {
1921  logger->AddToCallStack("Viewscreen::ApplyEnvironmentMap");
1922 
1923  D3DXMATRIX matrixTemp;
1924  HRESULT hr;
1925 
1926  for (short t = 0; t < maxstarC; t++)
1927  {
1928  D3DXMatrixIdentity(&allobjects[t].matrixWorld);
1929 
1930  if (allobjects[t].type == -5) // Static Stars
1931  {
1932  D3DXMatrixRotationX(&matrixTemp, D3DX_HALFPI); // Tilt the star field 90°
1933  D3DXMatrixMultiply(&allobjects[t].matrixWorld, &matrixTemp, &allobjects[t].matrixWorld);
1934  }
1935  else // not static stars
1936  {
1937  if (allobjects[t].type != -1) // Not Vieneo
1938  {
1939  if (allobjects[t].type != 1) // Not docks
1940  {
1941  D3DXMatrixScaling(&matrixTemp, allobjects[t].scale, allobjects[t].scale, allobjects[t].scale);
1942  D3DXMatrixMultiply(&allobjects[t].matrixWorld, &allobjects[t].matrixWorld, &matrixTemp);
1943  }
1944  }
1945  else // Vieneo scale is left at 1, tilt is barycentric
1946  {
1947  // Surface map must be rotated west 90°
1948  D3DXMatrixRotationZ(&matrixTemp, -D3DX_HALFPI);
1949  D3DXMatrixMultiply(&allobjects[t].matrixWorld, &matrixTemp, &allobjects[t].matrixWorld);
1950  }
1951 
1952 
1953 
1954  if (allobjects[t].type == -7) // yonmara
1955  D3DXMatrixTranslation(&matrixTemp, 0.0f, -allobjects[t].range, 0.0f);
1956  else
1957  D3DXMatrixTranslation(&matrixTemp, 0.0f, allobjects[t].range, 0.0f);
1958  D3DXMatrixMultiply(&allobjects[t].matrixWorld, &allobjects[t].matrixWorld, &matrixTemp);
1959 
1960  // Need to find the initial meridian of Vieneo since docks are framemoved first
1961  if (allobjects[t].type == -1)
1962  {
1963  float f_temp = D3DX_TAU / allobjects[t].rotation;
1965  allobjects[t].rotprog += f_Uphours * 3600.0f / f_temp;
1966  allobjects[t].rotprog -= floorf(allobjects[t].rotprog);
1967  allobjects[t].rotprog += g_UniverseTime / f_temp;
1968  allobjects[t].rotprog -= floorf(allobjects[t].rotprog);
1969  allobjects[t].rotprog *= D3DX_TAU;
1970  }
1971  } // End of not a static star part
1972 
1974  }
1975 
1976 
1977  D3DNONORMAL* vtxn;
1978 
1979  // Lock the vertex buffer
1980  V(m_avSunVertices->Lock(0, 0, reinterpret_cast<void**>(&vtxn), 0));
1981 
1982  // normal, -1, -2, 1, 2
1983  (*vtxn).x = 1.0f; (*vtxn).y = 0.0f; (*vtxn).z = 1.0f; // y's were -1
1984  (*vtxn).tu = 1.0f; (*vtxn).tv = 0.0f;
1985  vtxn++;
1986  (*vtxn).x = 1.0f; (*vtxn).y = 0.0f; (*vtxn).z = -1.0f;
1987  (*vtxn).tu = 0.0f; (*vtxn).tv = 0.0f;
1988  vtxn++;
1989  (*vtxn).x = -1.0f; (*vtxn).y = 0.0f; (*vtxn).z = 1.0f;
1990  (*vtxn).tu = 1.0f; (*vtxn).tv = 1.0f;
1991  vtxn++;
1992  (*vtxn).x = -1.0f; (*vtxn).y = 0.0f; (*vtxn).z = -1.0f;
1993  (*vtxn).tu = 0.0f; (*vtxn).tv = 1.0f;
1994  vtxn++;
1995 
1996  V(m_avSunVertices->Unlock());
1997 
1998 #ifdef treetestC
1999  V(m_avTree->Lock(0, 0, reinterpret_cast<void**>(&vtxn), 0));
2000 
2001  (*vtxn).x = 0.98f; (*vtxn).y = 0.0f; (*vtxn).z = 1.0f; // ur
2002  (*vtxn).tu = 1.0f; (*vtxn).tv = 0.0f;
2003  vtxn++;
2004  (*vtxn).x = 0.98f; (*vtxn).y = 0.0f; (*vtxn).z = -1.0f; // ul
2005  (*vtxn).tu = 0.0f; (*vtxn).tv = 0.0f;
2006  vtxn++;
2007  (*vtxn).x = -0.02f; (*vtxn).y = 0.0f; (*vtxn).z = 0.0f; // lc
2008  (*vtxn).tu = 0.5f; (*vtxn).tv = 1.0f;
2009 
2010  V(m_avTree->Unlock());
2011 #endif treetestC
2012 
2013 
2014 
2015  D3DSKYDOME* vtx;
2016 
2017  // Lock the vertex buffer
2018  V(m_avCone->Lock(0, 0, reinterpret_cast<void**>(&vtx), 0));
2019  // 5.4268124985728199351689323806177 degrees either side
2020  float f_temp;
2021  D3DXVECTOR2 current, nextone;
2022  for (short t = 0; t < 24; t++)
2023  {
2024  f_temp = D3DX_TAU / 24.0f * static_cast<float>(t);
2025  current.x = sinf(f_temp) * 0.00034822f;
2026  current.y = -cosf(f_temp) * 0.00034822f;
2027  f_temp = D3DX_TAU / 24.0f * static_cast<float>(t + 1);
2028  nextone.x = sinf(f_temp) * 0.00034822f;
2029  nextone.y = -cosf(f_temp) * 0.00034822f;
2030 
2031 
2032  (*vtx).y = current.x; (*vtx).z = current.y; (*vtx).x = 0.0f;
2033  (*vtx).diffuse = 0xFFFFFFFF;
2034  vtx++;
2035  (*vtx).y = nextone.x; (*vtx).z = nextone.y; (*vtx).x = 0.0f;
2036  (*vtx).diffuse = 0xFFFFFFFF;
2037  vtx++;
2038  (*vtx).y = 0.0f; (*vtx).z = 0.0f; (*vtx).x = 0.0f;
2039  (*vtx).diffuse = 0xFFFFFFFF;
2040  vtx++;
2041 
2042  (*vtx).y = current.x; (*vtx).z = current.y; (*vtx).x = 0.0f;
2043  (*vtx).diffuse = 0x40FFFFFF;
2044  vtx++;
2045  (*vtx).y = nextone.x; (*vtx).z = nextone.y; (*vtx).x = 0.0f;
2046  (*vtx).diffuse = 0x40FFFFFF;
2047  vtx++;
2048  (*vtx).y = current.x * 20.0f; (*vtx).z = current.y * 20.0f; (*vtx).x = -200.0f * 0.00034822f;
2049  (*vtx).diffuse = 0x00FFFFFF;
2050  vtx++;
2051  (*vtx).y = nextone.x; (*vtx).z = nextone.y; (*vtx).x = 0.0f;
2052  (*vtx).diffuse = 0x40FFFFFF;
2053  vtx++;
2054  (*vtx).y = nextone.x * 20.0f; (*vtx).z = nextone.y * 20.0f; (*vtx).x = -200.0f * 0.00034822f;
2055  (*vtx).diffuse = 0x00FFFFFF;
2056  vtx++;
2057  (*vtx).y = current.x * 20.0f; (*vtx).z = current.y * 20.0f; (*vtx).x = -200.0f * 0.00034822f;
2058  (*vtx).diffuse = 0x00FFFFFF;
2059  vtx++;
2060 
2061  }
2062  V(m_avCone->Unlock());
2063 
2064  // Rain initialize random drop locations
2065  for (short t = 0; t < MAX_RAINDROPS; t++)
2066  {
2067  // box that is 50m above/below,
2068  const float width = RandomFloat() * 0.2f - 0.1f; // wide-half; // 200m wide
2069  const float zdist = RandomFloat() * 0.4f - 0.2f; // percentage of 200m distance
2070  rainarray[t].x = width;
2071  rainarray[t].y = RandomFloat() * 0.05f - 0.025f; // vertically 50m above/below
2072  rainarray[t].z = zdist;
2073  }
2074 
2075 
2076 
2077  // Terrain visiblegrid, indexgrid, index buffers created
2078  ptrGrid->ClearGrid();
2079 
2080 
2081 
2082  short l, m, n = 0, o = 0;
2083  for (l = 0; l < 63; l++)
2084  {
2085  for (m = 0; m < 63; m++)
2086  {
2087  // Clear this so we don't bomb the card!
2088  insidearray[l][m][0] = insidearray[l][m][1] = insidearray[l][m][2] = centerC;
2089  // Make visiblegrid array
2090  if (sqrtf(powf(31.0f - static_cast<float>(l), 2.0f) + powf(31.0f - static_cast<float>(m), 2.0f)) <= 32.0f)
2091  {
2092  visiblegrid[l][m] = true;
2093  n++;
2094  if (l > 15 && l < 48 && m > 15 && m < 48)
2095  o++;
2096  }
2097  else
2098  visiblegrid[l][m] = false;
2099  }
2100  }
2101 
2102  ptrGrid->geometryReady = false; // VB not set, don't touch initialized which is for the data
2103 
2104  sprintf_s(msg, sizeof(msg), "ApplyEnvironmentMap() visible grid has %i/%i squares (%i are patched)!", n, drawlistC, o);
2105  logger->Log(msg);
2106 
2107  n = 0;
2108  for (l = 0; l < 63; l++)
2109  {
2110  const float f_l = static_cast<float>(l) - 31.0f;
2111  for (m = 0; m < 63; m++)
2112  {
2113  const float f_m = static_cast<float>(m) - 31.0f;
2114  // what is this, based on our field of view and how far south a piece is? yes, we later rotate when we render
2115  f_temp = fabsf(tanf(g_fFOV * 0.5f) * f_m);
2116  if (fabsf(f_l) < (f_temp + 6.25f) && m <= 31 && visiblegrid[l][m]) // 2 is min
2117  gridvisible[l][m] = true;
2118  // darren complained about these three squares on 03/17/06, was reinstated
2119  else if (sqrtf(powf(f_l, 2.0f) + powf(f_m, 2.0f)) < 2.0f) // area around our position
2120  gridvisible[l][m] = true;
2121  else
2122  gridvisible[l][m] = false;
2123  if (!gridvisible[l][m] && visiblegrid[l][m])
2124  n++;
2125  }
2126  }
2127  sprintf_s(msg, sizeof(msg), "ApplyEnvironmentMap() %i squares further eliminated in optimizations!", n);
2128  logger->Log(msg);
2129 
2130 #ifdef _DEBUG
2131  int gridvisiblefile;
2132  _sopen_s(&gridvisiblefile, "gridvisible.txt", _O_RDWR | _O_CREAT | _O_TRUNC | _O_TEXT | _O_SEQUENTIAL, SH_DENYWR, S_IWRITE);
2133  // draw grid in textfile
2134  for (l = 0; l < 63; l++)
2135  {
2136  for (m = 0; m < 63; m++)
2137  {
2138  sprintf_s(msg, sizeof msg, "%i ", gridvisible[m][l] ? 1 : 0);
2139  _write(gridvisiblefile, msg, strlen(msg));
2140  }
2141  sprintf_s(msg, sizeof msg, "\n");
2142  _write(gridvisiblefile, msg, strlen(msg));
2143  }
2144  _close(gridvisiblefile);
2145 
2146  int visiblegridfile;
2147  _sopen_s(&visiblegridfile, "visiblegrid.txt", _O_RDWR | _O_CREAT | _O_TRUNC | _O_TEXT | _O_SEQUENTIAL, SH_DENYWR, S_IWRITE);
2148  // draw grid in textfile
2149  for (l = 0; l < 63; l++)
2150  {
2151  for (m = 0; m < 63; m++)
2152  {
2153  sprintf_s(msg, sizeof msg, "%i ", visiblegrid[m][l] ? 1 : 0);
2154  _write(visiblegridfile, msg, strlen(msg));
2155  }
2156  sprintf_s(msg, sizeof msg, "\n");
2157  _write(visiblegridfile, msg, strlen(msg));
2158  }
2159  _close(visiblegridfile);
2160 #endif
2161 
2162  // indexgrid keeps track of linearly how far down each point is in the vertexbuffer
2163  short indexgrid[64][64]; // values 0 to visiblevertC (7168)
2164  n = 0;
2165  for (l = 0; l < 64; l++)
2166  {
2167  for (m = 0; m < 64; m++)
2168  {
2169  indexgrid[l][m] = n;
2170  n++;
2171  }
2172  }
2173  sprintf_s(msg, sizeof(msg), "ApplyEnvironmentMap() index grid for clouds has %i/%i indices!", n, 4096);
2174  logger->Log(msg);
2175 
2176 
2177  unsigned short* itxg;
2178  short s;
2179  n = 0;
2180  V(m_aiCloudGrid->Lock(0, 0, reinterpret_cast<void**>(&itxg), 0));
2181  for (short t = 0; t < 63; t++)
2182  {
2183  for (s = 0; s < 63; s++)
2184  {
2185  if (visiblegrid[t][s])
2186  {
2187  (*itxg++) = indexgrid[t][s];
2188  (*itxg++) = indexgrid[t + 1][s + 1];
2189  (*itxg++) = indexgrid[t][s + 1];
2190 
2191  (*itxg++) = indexgrid[t][s];
2192  (*itxg++) = indexgrid[t + 1][s];
2193  (*itxg++) = indexgrid[t + 1][s + 1];
2194  n += 6;
2195  }
2196  }
2197  }
2198  V(m_aiCloudGrid->Unlock());
2199  sprintf_s(msg, sizeof msg, "ApplyEnvironmentMap() cloud index buffer has %i/%i indices!", n, cloudindicesC);
2200  logger->Log(msg);
2201  assert(n <= cloudindicesC);
2202 
2203 
2204 
2205 
2206 
2207 
2208  n = 0;
2209  short leftup, rightdown = 32;
2210 
2211  // Immediate location
2212  unsigned short startindex = 0;
2213  drawlist[n].startindex = startindex;
2214  drawlist[n].primitives = 8;
2215  drawlist[n].u = 31;
2216  drawlist[n].v = 31;
2217  startindex += 24;
2218  n++;
2219 
2220  // Work from inside and out, counterclockwise order
2221  for (leftup = 30; leftup >= 0; leftup--) //30 29 ... 1 0
2222  {
2223  // Top and bottom rows
2224  for (short t = leftup; t <= rightdown; t++)
2225  {
2226  if (visiblegrid[t][leftup])// && t!=63 && leftup!=63)
2227  {
2228  if (t > 15 && t < 47 && leftup > 15 && leftup < 47) // has to be <47 because [48][48][2] is NAN
2229  {
2230  drawlist[n].startindex = startindex;
2231  startindex += 24;
2232  drawlist[n].primitives = 8;
2233  }
2234  else
2235  {
2236  drawlist[n].startindex = startindex;
2237  startindex += 6;
2238  drawlist[n].primitives = 2;
2239  }
2240 
2241  drawlist[n].u = (unsigned char)t;
2242  drawlist[n].v = (unsigned char)leftup;
2243  n++;
2244  }
2245 
2246  if (visiblegrid[t][rightdown])// && t != 63 && rightdown != 63)
2247  {
2248  if (t > 15 && t < 47 && rightdown > 15 && rightdown < 47)
2249  {
2250  drawlist[n].startindex = startindex;
2251  startindex += 24;
2252  drawlist[n].primitives = 8;
2253  }
2254  else
2255  {
2256  drawlist[n].startindex = startindex;
2257  startindex += 6;
2258  drawlist[n].primitives = 2;
2259  }
2260 
2261  drawlist[n].u = (unsigned char)t;
2262  drawlist[n].v = (unsigned char)rightdown;
2263  n++;
2264  }
2265  }
2266 
2267  // Left and right sides
2268  for (s = leftup + 1; s < rightdown; s++)
2269  {
2270  if (visiblegrid[rightdown][s])// && rightdown != 63 && s != 63)
2271  {
2272  if (s > 15 && s < 47 && rightdown > 15 && rightdown < 47)
2273  {
2274  drawlist[n].startindex = startindex;
2275  startindex += 24;
2276  drawlist[n].primitives = 8;
2277  }
2278  else
2279  {
2280  drawlist[n].startindex = startindex;
2281  startindex += 6;
2282  drawlist[n].primitives = 2;
2283  }
2284 
2285  drawlist[n].u = (unsigned char)rightdown;
2286  drawlist[n].v = (unsigned char)s;
2287  n++;
2288  }
2289 
2290  if (visiblegrid[leftup][s])// && leftup != 63 && s != 63)
2291  {
2292  if (s > 15 && s < 47 && leftup > 15 && leftup < 47)
2293  {
2294  drawlist[n].startindex = startindex;
2295  startindex += 24;
2296  drawlist[n].primitives = 8;
2297  }
2298  else
2299  {
2300  drawlist[n].startindex = startindex;
2301  startindex += 6;
2302  drawlist[n].primitives = 2;
2303  }
2304 
2305  drawlist[n].u = (unsigned char)leftup;
2306  drawlist[n].v = (unsigned char)s;
2307  n++;
2308  }
2309  }
2310  rightdown++;
2311  }
2312 
2313  sprintf_s(msg, sizeof(msg), "ApplyEnvironmentMap() terrain draw list, vertices %i, list length %i/%i", startindex, n, drawlistC);
2314  logger->Log(msg);
2315  assert(n <= drawlistC);
2316 }
2317 
2318 // Used in weapons, our movement (only if CalculateAGLd fails), and other vehicles (so we don't let them fall through the ground)
2319 float Viewscreen::CalculateAGL(short u, short v, D3DXVECTOR3 position, bool makeleveler)
2320 {
2321  logger->AddToCallStack("Viewscreen::CalculateAGL");
2322 
2323  D3DXVECTOR3 negposition = -position, temp0, temp1, temp2;//, tempcenter;
2324  float pu, pv, dist = -1.0f; // last if not overwritten
2325  D3DXVec3Normalize(&negposition, &negposition);
2326  // tempcenter=negposition*2934.6f; // bring it inside the planet a bit, 4.1km minimum is lowest point
2327  if (u > 15 && u < 48 && v > 15 && v < 48)
2328  {
2329  // first quad (zone 1)
2330  if (D3DXIntersectTri(&gridarray[u][v].position, &insidearray[u][v][0], &insidearray[u][v][1], &centerC, &negposition, &pu, &pv, &dist))
2331  {
2332  temp0 = gridarray[u][v].position; temp1 = insidearray[u][v][0]; temp2 = insidearray[u][v][1];
2333  }
2334  else if (D3DXIntersectTri(&insidearray[u][v][0], &insidearray[u][v][2], &insidearray[u][v][1], &centerC, &negposition, &pu, &pv, &dist))
2335  {
2336  temp0 = insidearray[u][v][0]; temp1 = insidearray[u][v][2]; temp2 = insidearray[u][v][1];
2337  }
2338 
2339  // second quad (zone 2)
2340  else if (D3DXIntersectTri(&insidearray[u][v][0], &gridarray[u + 1][v].position, &insidearray[u][v][2], &centerC, &negposition, &pu, &pv, &dist))
2341  {
2342  temp0 = insidearray[u][v][0]; temp1 = gridarray[u + 1][v].position; temp2 = insidearray[u][v][2];
2343  }
2344  else if (D3DXIntersectTri(&gridarray[u + 1][v].position, &insidearray[u + 1][v][1], &insidearray[u][v][2], &centerC, &negposition, &pu, &pv, &dist))
2345  {
2346  temp0 = gridarray[u + 1][v].position; temp1 = insidearray[u + 1][v][1]; temp2 = insidearray[u][v][2];
2347  }
2348 
2349  // third quad (zone 4)
2350  else if (D3DXIntersectTri(&insidearray[u][v][1], &insidearray[u][v][2], &gridarray[u][v + 1].position, &centerC, &negposition, &pu, &pv, &dist))
2351  {
2352  temp0 = insidearray[u][v][1]; temp1 = insidearray[u][v][2]; temp2 = gridarray[u][v + 1].position;
2353  }
2354  else if (D3DXIntersectTri(&insidearray[u][v][2], &insidearray[u][v + 1][0], &gridarray[u][v + 1].position, &centerC, &negposition, &pu, &pv, &dist))
2355  {
2356  temp0 = insidearray[u][v][2]; temp1 = insidearray[u][v + 1][0]; temp2 = gridarray[u][v + 1].position;
2357  }
2358 
2359  // fourth quad (zone 3)
2360  else if (D3DXIntersectTri(&insidearray[u][v][2], &insidearray[u + 1][v][1], &insidearray[u][v + 1][0], &centerC, &negposition, &pu, &pv, &dist))
2361  {
2362  temp0 = insidearray[u][v][2]; temp1 = insidearray[u + 1][v][1]; temp2 = insidearray[u][v + 1][0];
2363  }
2364  else if (D3DXIntersectTri(&insidearray[u + 1][v][1], &gridarray[u + 1][v + 1].position, &insidearray[u][v + 1][0], &centerC, &negposition, &pu, &pv, &dist))
2365  {
2366  temp0 = insidearray[u + 1][v][1]; temp1 = gridarray[u + 1][v + 1].position; temp2 = insidearray[u][v + 1][0];
2367  }
2368  else
2369  {
2370  sprintf_s(msg, sizeof msg, "*** CalculateAGL() u%i v%i x%.3f y%.3f z%.3f (%i) yielded no result, trying larger tessilation...", u, v, position.x, position.y, position.z, makeleveler);
2371  logger->Log(msg);
2372 
2373  if (D3DXIntersectTri(&gridarray[u][v].position, &gridarray[u + 1][v].position, &gridarray[u + 1][v + 1].position, &centerC, &negposition, &pu, &pv, &dist))
2374  {
2375  temp0 = gridarray[u][v].position; temp1 = gridarray[u + 1][v].position; temp2 = gridarray[u + 1][v + 1].position;
2376  }
2377  if (D3DXIntersectTri(&gridarray[u][v].position, &gridarray[u + 1][v + 1].position, &gridarray[u][v + 1].position, &centerC, &negposition, &pu, &pv, &dist))
2378  {
2379  temp0 = gridarray[u][v].position; temp1 = gridarray[u + 1][v + 1].position; temp2 = gridarray[u][v + 1].position;
2380  }
2381  else
2382  {
2383  sprintf_s(msg, sizeof msg, " CalculateAGL() u%i v%i is at x%.3f y%.3f z%.3f, still no result, returning %.3f (%.3f)", u, v, gridarray[u][v].position.x, gridarray[u][v].position.y, gridarray[u][v].position.z, dist, radiusC + f_MSL - dist);
2384  logger->Log(msg);
2385  }
2386  }
2387  }
2388  else if (D3DXIntersectTri(&gridarray[u][v].position, &gridarray[u + 1][v].position, &gridarray[u + 1][v + 1].position, &centerC, &negposition, &pu, &pv, &dist))
2389  {
2390  temp0 = gridarray[u][v].position; temp1 = gridarray[u + 1][v].position; temp2 = gridarray[u + 1][v + 1].position;
2391  }
2392  else if (D3DXIntersectTri(&gridarray[u][v].position, &gridarray[u + 1][v + 1].position, &gridarray[u][v + 1].position, &centerC, &negposition, &pu, &pv, &dist))
2393  {
2394  temp0 = gridarray[u][v].position; temp1 = gridarray[u + 1][v + 1].position; temp2 = gridarray[u][v + 1].position;
2395  }
2396  else
2397  {
2398  sprintf_s(msg, sizeof msg, "+++ CalculateAGL() u%i v%i x%.3f y%.3f z%.3f (%i) yielded no result, returning %.3f", u, v, position.x, position.y, position.z, makeleveler, dist);
2399  logger->Log(msg);
2400  }
2401 
2402  if (makeleveler)
2403  {
2404  D3DXVECTOR3 side1, side2;
2405  D3DXVec3Subtract(&side1, &temp0, &temp1);
2406  D3DXVec3Subtract(&side2, &temp0, &temp2);
2407  D3DXVec3Cross(&temp0, &side1, &side2);
2408  D3DXVec3Normalize(&leveler, &temp0);
2409  }
2410 
2411  return dist;
2412 }
2413 
2414 float Viewscreen::ProbeBoundSphere(D3DXVECTOR3* position, const D3DXVECTOR3* Xsunlight) const
2415 {
2416  logger->AddToCallStack("Viewscreen::ProbeBoundSphere");
2417  // Xsunlight is already normalized
2418  D3DXVECTOR3 result, vienohit;
2419  D3DXVec3Normalize(&result, position);
2420 
2421  if (D3DXVec3Dot(&result, Xsunlight) >= 0.0f)
2422  return 1.0f;
2423 
2424  D3DXVec3Subtract(&vienohit, position, &allobjects[ourstarC].position);
2425  D3DXVec3Normalize(&vienohit, &vienohit);
2426 
2427  const float angle2 = D3DXVec3Dot(&vienohit, &result);
2428  // angle2 is -1 when it is on the side of the object, 1 when it is not
2429 
2430  // Sun elevation (light level hitting flat plane)
2431  const float angle = D3DX_HALFPI - acosf(radiusC / D3DXVec3Length(position)); // one half view width on surface (1A)
2432 
2433  const float height = D3DXVec3Length(position) * tanf(acosf(angle2)) * cosf(angle);
2434  if (height < radiusC)
2435  return 0.0f;
2436  if (height > (radiusC + 63.0f)) // practical extent of the atmosphere
2437  return 1.0f;
2438 
2439  const float f_temp = (height - radiusC) / 63.0f; // 1 at top, 0 at bottom, .5 in middle
2440 
2441  return max(sqrtf(f_temp), 0); // .707 in middle
2442 }
2443 
2444 Sani Viewscreen::GetAni(float f_time, unsigned char ani) const
2445 {
2446  Sani returnani = Sani();
2447  const int steps = 10;
2448  // find where we are at
2449  for (int t = 0; t < steps; t++)
2450  {
2451  // first frame is 0, 0
2452  if ((f_time >= aniarray[ani][t].start || fabsf(aniarray[ani][t].start - f_time) < 0.05f) &&
2453  f_time < aniarray[ani][t].end)
2454  {
2455  float frametime = aniarray[ani][t].end - aniarray[ani][t].start; // 8-4=4
2456  float frameprog = f_time - aniarray[ani][t].start; // 6-4=2
2457  D3DXVec3Lerp(&returnani.xyz, &aniarray[ani][t].xyz, &aniarray[ani][t + 1].xyz, frameprog / frametime);
2458  for (short s = 0; s < 16; s++)
2459  D3DXVec3Lerp(&returnani.ypr[s], &aniarray[ani][t].ypr[s], &aniarray[ani][t + 1].ypr[s], frameprog / frametime);
2460 
2461  returnani.start = returnani.end = 0.0f;
2462 
2463  return returnani;
2464  }
2465  // last frame is x==x
2466  if ((f_time >= aniarray[ani][t].start || fabsf(aniarray[ani][t].start - f_time) < 0.05f) &&
2467  fabsf(aniarray[ani][t].start - aniarray[ani][t].end) < 0.05f)
2468  {
2469  returnani = aniarray[ani][t]; // this is to cover a problem with returning uninit blink out stuff and making her legs split in mid-air
2470  returnani.end = -353.0f; // signifies end
2471  return returnani;
2472  }
2473  }
2474  char sliderstr[499];
2475  sprintf_s(sliderstr, 499, "Could not find key frame that covers the time interval of %.1f seconds", f_time);
2476  logger->Log(sliderstr, Logger::Level::Error);
2477  return returnani;
2478 }
2479 
2480 D3DXVECTOR3 Viewscreen::CalculateBarycentric(D3DXVECTOR3* position, D3DXVECTOR3* gthrust, float* radius)
2481 {
2482  // Radius
2483  *radius = D3DXVec3Length(position);
2484 
2485  // Normalize a vector to ship
2486  D3DXVec3Normalize(gthrust, position);
2487 
2488  // Find barycentric velocity adjustment
2489  if (fabsf(gthrust->z) < 1.0f) // Can't be near poles or craps out on us
2490  {
2491  D3DXVECTOR3 cross;
2492  D3DXVec3Cross(&cross, &northpoleC, gthrust); // Find perpendicular vector
2493  D3DXVec3Normalize(&cross, &cross); // Shouldn't be necessary
2494  float lat = D3DXVec3Dot(gthrust, &northpoleC);
2495  if (lat >= 1.0f)
2496  lat = -D3DX_HALFPI; // 0-180
2497  else if (lat <= -1.0f)
2498  lat = 0.0f; // 180-180
2499  else
2500  lat = acosf(lat) - D3DX_HALFPI; // Find the angle and reduce by 90°
2501  // Update velocity to match planet rotation speed
2502  //*** changed this from -allobjects[ourmoonC].rotation
2503  const float f_temp = allobjects[ourmoonC].rotation * (*radius) * cosf(lat);
2504  return cross * f_temp;
2505  }
2506 
2507  return centerC;
2508 }
2509 
2510 bool Viewscreen::CheckPlotRoads(float f_tempu, float f_tempv)
2511 {
2512  if (gridarray[31][31].roads >= 8) // segment 0
2513  {
2514  if (f_tempu >= 0.4981712f && f_tempu <= 0.5018288f && f_tempv <= 0.4963424f) // north
2515  return true;
2516  }
2517  if ((gridarray[31][31].roads >= 4 && gridarray[31][31].roads <= 7) || gridarray[31][31].roads >= 12) // segment 1
2518  {
2519  if (f_tempu >= 0.4963424 && f_tempu <= 0.5036576 && f_tempv >= 0.5036576) // south
2520  return true;
2521  }
2522  if (gridarray[31][31].roads == 2 || gridarray[31][31].roads == 3 || gridarray[31][31].roads == 6 || gridarray[31][31].roads == 7 ||
2523  gridarray[31][31].roads == 10 || gridarray[31][31].roads == 11 || gridarray[31][31].roads >= 14) // segment 2
2524  {
2525  if (f_tempu <= 0.4963424 && f_tempv >= 0.4963424 && f_tempv <= 0.5036576) // west
2526  return true;
2527  }
2528  if (gridarray[31][31].roads % 2 == 1) // segment 3
2529  {
2530  if (f_tempu >= 0.5036576 && f_tempv >= 0.4963424 && f_tempv <= 0.5036576) // east
2531  return true;
2532  }
2533  if (f_tempu > 0.4963424 && f_tempu < 0.5036576 && f_tempv > 0.4963424 && f_tempv < 0.5036576)
2534  return true;
2535  return false;
2536 }
2537 
2538 void Viewscreen::Movement(short t, float ElapsedTime)
2539 {
2540  logger->AddToCallStack("Viewscreen::Movement");
2541 
2542 
2543  AssertTelemetry("Viewscreen::Movement1", t);
2544  //logger->AddToCallStack("Viewscreen::Movement Resumed");
2545 
2546 
2547  D3DXVECTOR3 proposed, gthrust, cross;
2548  double proposedx, proposedy, proposedz;
2549  float radius;
2550  HRESULT hr;
2551 
2552 
2553  // New velocity adjustment section
2554  if (playerships[t].reference >= REF_DOCKCPOC) // docks
2555  {
2556  //logger->AddToCallStack("Viewscreen::Movement Proposed Docks");
2557 
2558  proposed = playerships[t].dockoffset + playerships[t].dockingvel * ElapsedTime;
2559  proposedx = proposed.x; proposedy = proposed.y; proposedz = proposed.z;
2560  // need to do collision then can set to proposed and return
2561  }
2562  else if (playerships[t].reference < REF_INANOTHER)
2563  {
2564  //logger->AddToCallStack("Viewscreen::Movement Proposed ACL/BCL");
2565 
2566  playerships[t].barycentric = CalculateBarycentric(&playerships[t].position, &gthrust, &radius);
2567 
2568  if (t == 0)
2569  {
2570  // if (playerships[0].reference==REF_ONGROUND && deathinhibit>0.0f)
2571  // playerships[0].velocity=playerships[0].barycentric;
2572 
2573  float gravity = gravityC / powf(radius / radiusC, 2.0f) * ElapsedTime;
2574  D3DXVec3Scale(&gravityvec, &gthrust, gravity);
2575 
2576  D3DXMATRIX matrixInverse; // need to make new one because we have moved since
2577  D3DXQuaternionNormalize(&playerships[0].orientation, &playerships[0].orientation);
2578  D3DXMatrixRotationQuaternion(&matrixInverse, &playerships[0].orientation);
2579  D3DXVec3TransformNormal(&gravityacc, &gravityvec, &matrixInverse);
2580 
2581  sprintf_s(msg, sizeof msg, "X%7.3f Y%7.3f Z%7.3f gravity1", -gravityacc.x * oneOvergForceKmSSC / ElapsedTime, -gravityacc.y * oneOvergForceKmSSC / ElapsedTime, -gravityacc.z * oneOvergForceKmSSC / ElapsedTime);
2582  sofTracking.emplace_back(msg);
2583 
2585 
2586 #pragma region debug
2587  if (sumofforces.x > 100.0f || sumofforces.x < -100.0f || _isnan(sumofforces.x) || isinf(sumofforces.x) ||
2588  sumofforces.y > 100.0f || sumofforces.y < -100.0f || _isnan(sumofforces.y) || isinf(sumofforces.y) ||
2589  sumofforces.z > 100.0f || sumofforces.z < -100.0f || _isnan(sumofforces.z) || isinf(sumofforces.z))
2590  {
2591  sprintf_s(msg, sizeof(msg), "\tET: %f", ElapsedTime);
2592  logger->Log(msg, Logger::Level::Warn);
2593  sprintf_s(msg, sizeof(msg), "\treference: %i", playerships[0].reference);
2594  logger->Log(msg, Logger::Level::Warn);
2595  sprintf_s(msg, sizeof(msg), "\tsumofforces I: %f", sumofforces.x);
2596  logger->Log(msg, Logger::Level::Warn);
2597  sprintf_s(msg, sizeof(msg), "\tsumofforces J: %f", sumofforces.y);
2598  logger->Log(msg, Logger::Level::Warn);
2599  sprintf_s(msg, sizeof(msg), "\tsumofforces K: %f", sumofforces.z);
2600  logger->Log(msg, Logger::Level::Warn);
2601  sprintf_s(msg, sizeof(msg), "\tgravityvec X: %f", gravityvec.x);
2602  logger->Log(msg, Logger::Level::Warn);
2603  sprintf_s(msg, sizeof(msg), "\tgravityvec Y: %f", gravityvec.y);
2604  logger->Log(msg, Logger::Level::Warn);
2605  sprintf_s(msg, sizeof(msg), "\tgravityvec Z: %f", gravityvec.z);
2606  logger->Log(msg, Logger::Level::Warn);
2607  sprintf_s(msg, sizeof(msg), "\torientation X: %f", playerships[0].orientation.x);
2608  logger->Log(msg, Logger::Level::Warn);
2609  sprintf_s(msg, sizeof(msg), "\torientation Y: %f", playerships[0].orientation.y);
2610  logger->Log(msg, Logger::Level::Warn);
2611  sprintf_s(msg, sizeof(msg), "\torientation Z: %f", playerships[0].orientation.z);
2612  logger->Log(msg, Logger::Level::Warn);
2613  sprintf_s(msg, sizeof(msg), "\torientation W: %f", playerships[0].orientation.w);
2614  logger->Log(msg, Logger::Level::Warn);
2615  DumpSofTracking();
2616  sprintf_s(msg, sizeof(msg), "Trapped a violation after gravity adjusted...");
2617  logger->Log(msg, Logger::Level::Fatal);
2618  }
2619 #pragma endregion
2620 
2621 
2622 
2623  // this is amount our velocity would curve as we fly around planet
2624  // if this doesn't work we have to take barycentric off of dock velocities
2625  if (playerships[t].reference != REF_ONGROUND)
2626  {
2627  D3DXMATRIX matrixWorld;
2628  D3DXMatrixRotationZ(&matrixWorld, -allobjects[ourmoonC].rotation * ElapsedTime);
2629  D3DXVec3TransformNormal(&playerships[t].velocity, &playerships[t].velocity, &matrixWorld);
2630  }
2631 
2632  }
2633 
2634  // New proposed position section
2635  // Proposed position
2636  proposedx = playerships[t].precisionx + static_cast<double>((playerships[t].velocity.x - playerships[t].barycentric.x) * ElapsedTime);
2637  proposedy = playerships[t].precisiony + static_cast<double>((playerships[t].velocity.y - playerships[t].barycentric.y) * ElapsedTime);
2638  proposedz = playerships[t].precisionz + static_cast<double>((playerships[t].velocity.z - playerships[t].barycentric.z) * ElapsedTime);
2639 
2640  // For visuals
2641  proposed.x = static_cast<float>(proposedx);
2642  proposed.y = static_cast<float>(proposedy);
2643  proposed.z = static_cast<float>(proposedz);
2644 
2645  // @todo we tried this but on the same plot only seems to not even be worth it because the server is so fast now
2646  if (t != 0 && playerships[t].reference != REF_ONGROUND)
2647  {
2648  // limitations - seams between cube plates (assumed to be on the same plate)
2649  // - won't work with buildings yet
2650  // - assumed to be on the same plot (easy to compute though if they aren't)
2651  //VECTOR2SHORT tcp = CalculateCGC(proposed, ptrGrid->cube);
2652 
2653  const float agl = CalculateAGL(31, 31, proposed, false);
2654  if (agl != -1 && agl < -0.000025f)
2655  {
2656  sprintf_s(msg, sizeof msg, "Ship we were watching was going through the ground %f so we stopped them!", agl);
2657  logger->Log(msg, Logger::Level::Debug);
2658 
2659  float dist = D3DXVec3Length(&proposed);
2660  sprintf_s(msg, sizeof msg, "Distance from centerC: %f", dist);
2661  logger->Log(msg, Logger::Level::Debug);
2662 
2663  // depending on what happens to the distance we might need to do +=
2664  proposedx -= static_cast<double>(agl * gthrust.x);
2665  proposedy -= static_cast<double>(agl * gthrust.y);
2666  proposedz -= static_cast<double>(agl * gthrust.z);
2667 
2668  // For visuals
2669  proposed.x = static_cast<float>(proposedx);
2670  proposed.y = static_cast<float>(proposedy);
2671  proposed.z = static_cast<float>(proposedz);
2672 
2673  dist = D3DXVec3Length(&proposed);
2674  sprintf_s(msg, sizeof msg, "Distance from centerC: %f", dist);
2675  logger->Log(msg, Logger::Level::Debug);
2676 
2677  }
2678  }
2679 
2680  // WE TRIED THIS END OF 2019 AND IT CAUSED HOURS OF WASTED TIME TRYING TO FIGURE OUT WHY I WAS FALLING INTO THE GROUND
2681  //proposed = playerships[t].position + (playerships[t].velocity - playerships[t].barycentric) * ElapsedTime;
2682  }
2683  else if (playerships[t].reference == REF_INANOTHER)
2684  {
2685  //logger->AddToCallStack("Viewscreen::Movement Proposed Parent");
2686 
2687  float yaw = 0.0f;
2688 
2689  // Evaluated vehicle is in another vehicle
2692  playerships[t].yaw = playerships[t].pitch = playerships[t].roll = 0.0f;
2693 
2694  if (playerships[playerships[t].inarray].type == VehicleType::T120 ||
2695  playerships[playerships[t].inarray].type == VehicleType::T121) // parent is steerhead
2696  {
2697  if (playerships[t].type == VehicleType::C2 ||
2698  playerships[t].type == VehicleType::C2A)
2699  {
2700  playerships[t].dockoffset.y += 0.0009f;
2701  playerships[t].dockoffset.z -= 0.0019f; // fwd back
2702  }
2703  else if (playerships[t].type == VehicleType::C98)
2704  {
2705  playerships[t].dockoffset.y += 0.0008f;
2706  playerships[t].dockoffset.z -= 0.0015f; // fwd back
2707  }
2708  else
2709  {
2710  playerships[t].dockoffset.y += 0.000305f;
2711  playerships[t].dockoffset.z -= 0.0019f; // fwd back
2712  }
2713  if (playerships[playerships[t].inarray].type == VehicleType::T121)
2714  {
2715  playerships[t].dockoffset.y -= 0.0001f;
2716  playerships[t].dockoffset.z -= 0.00035f; // fwd back
2717  }
2718  }
2719  else if (playerships[playerships[t].inarray].type == VehicleType::T19) // parent is Stratomaster
2720  {
2721  if (playerships[t].type == VehicleType::C2 ||
2722  playerships[t].type == VehicleType::C2A)
2723  {
2724  playerships[t].dockoffset.y -= 0.0003f; // -down +up
2725  playerships[t].dockoffset.z -= 0.0018f; // +fwd -back
2726  }
2727  else if (playerships[t].type == VehicleType::C98)
2728  {
2729  playerships[t].dockoffset.y -= 0.0004f; // -down +up
2730  playerships[t].dockoffset.z -= 0.0014f; // +fwd -back
2731  }
2732  else
2733  {
2734  playerships[t].dockoffset.y -= 0.001f; // -down +up
2735  playerships[t].dockoffset.z -= 0.0018f; // +fwd -back
2736  }
2737  }
2738  else if (playerships[playerships[t].inarray].type == VehicleType::A4) // parent is A4
2739  {
2740  if (playerships[t].type == VehicleType::C2 ||
2741  playerships[t].type == VehicleType::C2A)
2742  {
2743  playerships[t].dockoffset.y += 0.0011f;
2744  playerships[t].dockoffset.z -= 0.0072f; // fwd back
2745  }
2746  else if (playerships[t].type == VehicleType::C98)
2747  {
2748  playerships[t].dockoffset.y += 0.0008f;
2749  playerships[t].dockoffset.z -= 0.0068f; // fwd back
2750  }
2751  else
2752  playerships[t].dockoffset.z -= 0.0072f; // fwd back
2753  }
2754  else if (playerships[playerships[t].inarray].type == VehicleType::E10 ||
2755  playerships[playerships[t].inarray].type == VehicleType::E11) // parent is a Saint class
2756  {
2757  if (playerships[t].bay % 2 == 0) // left side
2758  {
2759  yaw = -D3DX_HALFPI;
2760  float aft = 0.0025f * (playerships[t].bay / 2);
2761 
2762  if (playerships[t].type == VehicleType::C2 ||
2763  playerships[t].type == VehicleType::C2A)
2764  {
2765  float frontback = -0.003f - aft; // negative is back
2766  float updown = -0.0025f; // negative is down
2767  float leftright = -0.0030f; // positive is right
2768  playerships[t].dockoffset.x += leftright; // left right
2769  playerships[t].dockoffset.y += updown + 0.0007f; // up down
2770  playerships[t].dockoffset.z = frontback; // fwd back
2771  yaw += D3DX_PI;
2772  }
2773  else if (playerships[t].type == VehicleType::C98)
2774  {
2775  float frontback = -0.003f - aft; // negative is back
2776  float updown = -0.0025f; // negative is down
2777  float leftright = -0.0030f; // positive is right
2778  playerships[t].dockoffset.x += leftright; // left right
2779  playerships[t].dockoffset.y += updown + 0.0004f; // up down
2780  playerships[t].dockoffset.z = frontback; // fwd back
2781  yaw += D3DX_PI;
2782  }
2783  else // PODS
2784  {
2785  float frontback = -0.003f - aft; // negative is back
2786  float updown = -0.0025f; // negative is down
2787  float leftright = -0.0030f; // positive is right
2788  playerships[t].dockoffset.x += leftright; // left right
2789  playerships[t].dockoffset.y += updown; // up down
2790  playerships[t].dockoffset.z += frontback; // fwd back
2791  }
2792  }
2793  else // right side
2794  {
2795  yaw = D3DX_HALFPI;
2796  float aft = 0.0025f * ((playerships[t].bay - 1) / 2);
2797 
2798  if (playerships[t].type == VehicleType::C2 ||
2799  playerships[t].type == VehicleType::C2A)
2800  {
2801  float frontback = -0.003f - aft; // negative is back
2802  float updown = -0.0025f; // negative is down
2803  float leftright = 0.003f; // positive is right
2804  playerships[t].dockoffset.x += leftright; // left right
2805  playerships[t].dockoffset.y += updown + 0.0007f; // up down
2806  playerships[t].dockoffset.z += frontback; // fwd back
2807  yaw += D3DX_PI;
2808  }
2809  else if (playerships[t].type == VehicleType::C98)
2810  {
2811  float frontback = -0.003f - aft; // negative is back
2812  float updown = -0.0025f; // negative is down
2813  float leftright = 0.003f; // positive is right
2814  playerships[t].dockoffset.x += leftright; // left right
2815  playerships[t].dockoffset.y += updown + 0.0004f; // up down
2816  playerships[t].dockoffset.z += frontback; // fwd back
2817  yaw += D3DX_PI;
2818  }
2819  else // PODS
2820  {
2821  float frontback = -0.003f - aft; // negative is back
2822  float updown = -0.0025f; // negative is down
2823  float leftright = 0.003f; // positive is right
2824  playerships[t].dockoffset.x += leftright; // left right
2825  playerships[t].dockoffset.y += updown; // up down
2826  playerships[t].dockoffset.z += frontback; // fwd back
2827  }
2828  }
2829  }
2830  else if (playerships[playerships[t].inarray].type == VehicleType::W6Manx) // parent is Manx
2831  {
2832  if (playerships[t].type == VehicleType::C2 ||
2833  playerships[t].type == VehicleType::C2A)
2834  {
2835  playerships[t].dockoffset.y += 0.0006f;
2836  playerships[t].dockoffset.z -= 0.006f; // fwd+ back-
2837  }
2838  else if (playerships[t].type == VehicleType::C98)
2839  {
2840  playerships[t].dockoffset.y += 0.0005f;
2841  playerships[t].dockoffset.z -= 0.0056f; // fwd back
2842  }
2843  else
2844  playerships[t].dockoffset.z -= 0.006f; // fwd back
2845 
2846  playerships[t].dockoffset.y -= 0.0024f;
2847  playerships[t].dockoffset.z += (playerships[t].bay - 1.0f) * 0.005f + 0.0017f;
2848  }
2849  else if (playerships[playerships[t].inarray].type == VehicleType::T27) // parent is a Saint class
2850  {
2851  float updown = -0.0027f; // negative is down
2852  float aft = 0.005f * (playerships[t].bay / 3);
2853  if (playerships[t].bay >= 9)
2854  {
2855  updown += 0.0025f; // upper level
2856  aft -= 0.015f;
2857  }
2858  aft -= 0.007f;
2859 
2860  yaw = 0;// D3DX_PI;
2861 
2862  float leftright;
2863  if (playerships[t].bay % 3 == 0)
2864  leftright = -0.0025f;
2865  else if (playerships[t].bay % 3 == 1)
2866  leftright = 0.0f;
2867  else if (playerships[t].bay % 3 == 2)
2868  leftright = 0.0025f;
2869 
2870  if (playerships[t].bay % 3 == 0) // left side
2871  {
2872  if (playerships[t].type == VehicleType::C2 ||
2873  playerships[t].type == VehicleType::C2A)
2874  {
2875  float frontback = -0.003f - aft; // negative is back
2876  playerships[t].dockoffset.x += leftright; // left right
2877  playerships[t].dockoffset.y += updown + 0.0007f; // up down
2878  playerships[t].dockoffset.z = frontback; // fwd back
2879  yaw += D3DX_PI;
2880  }
2881  else if (playerships[t].type == VehicleType::C98)
2882  {
2883  float frontback = -0.003f - aft; // negative is back
2884  playerships[t].dockoffset.x += leftright; // left right
2885  playerships[t].dockoffset.y += updown + 0.0004f; // up down
2886  playerships[t].dockoffset.z = frontback; // fwd back
2887  yaw += D3DX_PI;
2888  }
2889  else // PODS
2890  {
2891  float frontback = -0.003f - aft; // negative is back
2892  playerships[t].dockoffset.x += leftright; // left right
2893  playerships[t].dockoffset.y += updown; // up down
2894  playerships[t].dockoffset.z += frontback; // fwd back
2895  }
2896  }
2897  else if (playerships[t].bay % 3 == 2) // right side
2898  {
2899  if (playerships[t].type == VehicleType::C2 ||
2900  playerships[t].type == VehicleType::C2A)
2901  {
2902  float frontback = -0.003f - aft; // negative is back
2903  playerships[t].dockoffset.x += leftright; // left right
2904  playerships[t].dockoffset.y += updown + 0.0007f; // up down
2905  playerships[t].dockoffset.z += frontback; // fwd back
2906  yaw += D3DX_PI;
2907  }
2908  else if (playerships[t].type == VehicleType::C98)
2909  {
2910  float frontback = -0.003f - aft; // negative is back
2911  playerships[t].dockoffset.x += leftright; // left right
2912  playerships[t].dockoffset.y += updown + 0.0004f; // up down
2913  playerships[t].dockoffset.z += frontback; // fwd back
2914  yaw += D3DX_PI;
2915  }
2916  else // PODS
2917  {
2918  float frontback = -0.003f - aft; // negative is back
2919  playerships[t].dockoffset.x += leftright; // left right
2920  playerships[t].dockoffset.y += updown; // up down
2921  playerships[t].dockoffset.z += frontback; // fwd back
2922  }
2923  }
2924  else if (playerships[t].bay % 3 == 1) // middle
2925  {
2926  if (playerships[t].type == VehicleType::C2 ||
2927  playerships[t].type == VehicleType::C2A)
2928  {
2929  float frontback = -0.003f - aft; // negative is back
2930  playerships[t].dockoffset.x += leftright; // left right
2931  playerships[t].dockoffset.y += updown + 0.0007f; // up down
2932  playerships[t].dockoffset.z += frontback; // fwd back
2933  yaw += D3DX_PI;
2934  }
2935  else if (playerships[t].type == VehicleType::C98)
2936  {
2937  float frontback = -0.003f - aft; // negative is back
2938  playerships[t].dockoffset.x += leftright; // left right
2939  playerships[t].dockoffset.y += updown + 0.0004f; // up down
2940  playerships[t].dockoffset.z += frontback; // fwd back
2941  yaw += D3DX_PI;
2942  }
2943  else // PODS
2944  {
2945  float frontback = -0.003f - aft; // negative is back
2946  playerships[t].dockoffset.x += leftright; // left right
2947  playerships[t].dockoffset.y += updown; // up down
2948  playerships[t].dockoffset.z += frontback; // fwd back
2949  }
2950  }
2951  }
2952 
2953  if (t == 0) // if it is us in someone else's bay then offset our cockpit arm
2955 
2956  D3DXQuaternionNormalize(&playerships[t].orientation, &playerships[playerships[t].inarray].orientation);
2957 
2958  D3DXMATRIX matrixInverse; // need to make new one because we have moved since
2959  D3DXMatrixRotationQuaternion(&matrixInverse, &playerships[playerships[t].inarray].orientation);
2960  D3DXMatrixInverse(&matrixInverse, nullptr, &matrixInverse);
2961  D3DXVec3TransformNormal(&cross, &playerships[t].dockoffset, &matrixInverse);
2962 
2963  D3DXQUATERNION quaternionTemp;
2964  D3DXQuaternionRotationYawPitchRoll(&quaternionTemp, yaw, 0, 0);
2965  D3DXQuaternionMultiply(&playerships[t].orientation, &playerships[t].orientation, &quaternionTemp);
2966 
2967  playerships[t].precisionx = playerships[playerships[t].inarray].precisionx + static_cast<double>(cross.x);
2968  playerships[t].precisiony = playerships[playerships[t].inarray].precisiony + static_cast<double>(cross.y);
2969  playerships[t].precisionz = playerships[playerships[t].inarray].precisionz + static_cast<double>(cross.z);
2970 
2971  D3DXVec3Add(&playerships[t].position, &cross, &playerships[playerships[t].inarray].position);
2972 
2973  D3DXVec3Add(&playerships[t].velocity, &playerships[t].dockingvel, &playerships[playerships[t].inarray].velocity);
2974 
2975  // NEED TO KEEP CALCULATING THIS SO WE DON"T GO FLYING OFF
2976  radius = D3DXVec3Length(&playerships[t].position);
2977 
2978  // Normalize a vector to ship
2979  D3DXVec3Normalize(&gthrust, &playerships[t].position);
2980 
2981  // Find barycentric velocity adjustment
2982  if (fabsf(gthrust.z) < 1.0f) // Can't be near poles or craps out on us
2983  {
2984  D3DXVec3Cross(&cross, &northpoleC, &gthrust); // Find perpendicular vector
2985  D3DXVec3Normalize(&cross, &cross); // Shouldn't be necessary
2986  float lat = D3DXVec3Dot(&gthrust, &northpoleC);
2987  if (lat >= 1.0f)
2988  lat = -D3DX_HALFPI; // 0-180
2989  else if (lat <= -1.0f)
2990  lat = 0.0f; // 180-180
2991  else
2992  lat = acosf(lat) - D3DX_HALFPI; // Find the angle and reduce by 90°
2993  // Update velocity to match planet rotation speed
2994  //*** changed this from -allobjects[ourmoonC].rotation
2995  float f_temp = allobjects[ourmoonC].rotation * radius * cosf(lat);
2996  D3DXVec3Scale(&playerships[t].barycentric, &cross, f_temp);
2997  }
2998  else
3000 
3001  // No collisions, proposed unused
3002  return;
3003  }
3004  else if (playerships[t].reference == REF_PROXIMITY)
3005  {
3006  //logger->AddToCallStack("Viewscreen::Movement Proposed Proximity");
3007 
3008  proposed = playerships[t].dockoffset + playerships[t].dockingvel * ElapsedTime;
3009  proposedx = proposed.x; proposedy = proposed.y; proposedz = proposed.z;
3010  // need to do collision then can set to proposed and return
3011  }
3012  else if (t == 0)
3013  {
3014  // No collisions, just return, no proposed
3015  return;
3016  }
3017  else
3018  {
3019  //logger->AddToCallStack("Viewscreen::Movement Proposed Undefined");
3020 
3021  proposed = D3DXVECTOR3(0, 0, 0);
3022  proposedx = proposed.x; proposedy = proposed.y; proposedz = proposed.z;
3023  logger->Log("Using an uninitialized proposed and/or precision proposed!", Logger::Level::Fatal);
3024  }
3025 
3026  // Collision detection vehicle to vehicle!
3027  if (t == 0)
3028  {
3029  //logger->AddToCallStack("Viewscreen::Movement Collision Detection");
3030 
3031  bool collision = false;
3032  short s;
3033  D3DXVECTOR3 result, target, source;
3034 
3035  // Disengaged because of docking procedures wreaks havoc
3036  // Check against docks
3037  if (playerships[0].reference >= REF_DOCKCPOC && dockprogress == 0.0f && !playerships[0].docked && deathinhibit == 0.0f)
3038  {
3039  s = playerships[0].reference - REF_DOCKCPOC;
3040  // proposed coord is 18 meters from centroid, 15 meter radius and our body is 5 meters ...
3041  // 18-15 < 5 ... that works
3042  if (D3DXVec3Length(&proposed) < (playerships[0].bound + allobjects[s].bound))
3043  {
3044  for (short r = 0; r < allobjects[s].components; r++)
3045  {
3046  // types to skip: no bounding sphere, interior of cargo bay
3047  if (allobjects[s].componentarray[r].type == 53 || allobjects[s].componentarray[r].type == 54)
3048  continue;
3049 
3050  // Extensions for each module of target (dock)
3051  D3DXVec3Scale(&result, &allobjects[s].componentarray[r].extendby, allobjects[s].componentarray[r].extended);
3052  D3DXVec3Add(&result, &allobjects[s].componentarray[r].nominalxyz, &result);
3053 
3054  target = result;
3055 
3056  for (short q = 0; q < playerships[0].components; q++)
3057  {
3058  // types to skip: no bounding sphere, interior of cargo bay
3059  if (playerships[0].componentarray[q].type == 53 || playerships[0].componentarray[q].type == 54)
3060  continue;
3061 
3062  // Extensions for our ship
3063  D3DXVec3Scale(&result, &playerships[0].componentarray[q].extendby, playerships[0].componentarray[q].extended);
3064  D3DXVec3Add(&result, &playerships[0].componentarray[q].nominalxyz, &result);
3065  // This adjusts for orientation, could do scale but there is none ... does NOT do location
3066  D3DXVec3TransformCoord(&source, &result, &playerships[0].matrixInvOrientation);
3067 
3068  if (playerships[0].reference >= REF_DOCKCPOC) // keep relative to our reference frame
3069  source -= playerships[0].dockoffset;
3070  else
3071  source -= playerships[0].position;
3072 
3073  result = source - target;
3074 
3076  float distCgtoCg = D3DXVec3Length(&result);
3077  if (distCgtoCg <= separateBy)
3078  {
3079  // how many units of overlap to seperate them by
3080  float f_temp = D3DXVec3Length(&result) - separateBy;
3081 
3082  // use vector from object to us
3083  if (D3DXVec3Length(&result) < FLT_EPSILON)
3084  {
3085  result.x = RandomFloat() - 0.5f;
3086  result.y = RandomFloat() - 0.5f;
3087  result.z = RandomFloat() - 0.5f;
3088  }
3089  D3DXVec3Normalize(&result, &result);
3090  D3DXVec3Scale(&result, &result, -f_temp);
3091 
3092  proposed -= result;
3093  proposedx -= (double)result.x;
3094  proposedy -= (double)result.y;
3095  proposedz -= (double)result.z;
3096 
3097  if (-f_temp > 0.001f)
3098  collision = true;
3099  causechain = 4;
3100 
3101  q = playerships[0].components;
3102  r = allobjects[s].components;
3103  }
3104  }
3105  }
3106  } // not within main bounding sphere
3107  } // object loop
3108 
3109 
3110  // Check against ships
3111  if (deathinhibit == 0.0f)
3112  {
3113  for (s = 1; s < MAX_SCAN; s++) // cycle through all other ships
3114  {
3115  if (playerships[s].active && playerships[s].visible && playerships[s].reference != REF_INANOTHER && // not in our bays, we should not have data on ones in interiors
3116  playerships[s].type != VehicleType::FloatingMan)
3117  {
3118  // Solve for distance from our CG to their CG
3119  if (playerships[0].reference >= REF_DOCKCPOC)
3120  {
3121  if (playerships[0].reference == playerships[s].reference)
3122  result = proposed - playerships[s].dockoffset; // apples to apples
3123  else
3124  result.x = result.y = result.z = 999.0f; // no chance
3125  }
3126  else
3127  result = proposed - playerships[s].position;
3128 
3129  float dist = D3DXVec3Length(&result);
3130 
3131  // Check against biggest bounding sphere first to see if we need delve deeper
3132  if (dist >= (playerships[0].bound + playerships[s].bound))
3133  continue;
3134 
3135  // Well, their big bounding spheres are interfering, check through components
3136  sprintf_s(msg, sizeof msg, "Major axis with IVR %s, separating %.3f %.3f %.3f dist %f", playerships[s].IVR, result.x, result.y, result.z, dist);
3137  logger->Log(msg);
3138  for (short r = 0; r < playerships[s].components; r++)
3139  {
3140  // types to skip: no bounding sphere, interior of cargo bay
3141  if (!playerships[s].componentarray[r].visible ||
3142  playerships[s].componentarray[r].type == 53 ||
3143  playerships[s].componentarray[r].type == 54)
3144  continue;
3145 
3146  for (short q = 0; q < playerships[0].components; q++)
3147  {
3148  // types to skip: no bounding sphere, interior of cargo bay
3149  if (!playerships[0].componentarray[q].visible ||
3150  playerships[0].componentarray[q].type == 53 ||
3151  playerships[0].componentarray[q].type == 54)
3152  continue;
3153 
3154  D3DXVECTOR3 ourComponentPosition = D3DXVECTOR3(0, 0, 0);
3155  D3DXVec3TransformCoord(&ourComponentPosition, &ourComponentPosition, &playerships[0].componentarray[q].matWorld);
3156  D3DXVECTOR3 theirComponentPosition = D3DXVECTOR3(0, 0, 0);
3157  D3DXVec3TransformCoord(&theirComponentPosition, &theirComponentPosition, &playerships[s].componentarray[r].matWorld);
3158  result = ourComponentPosition - theirComponentPosition;
3159  dist = D3DXVec3Length(&result);
3160  if (dist < (playerships[0].componentarray[q].boundsphere + playerships[s].componentarray[r].boundsphere))
3161  {
3162  sprintf_s(msg, sizeof(msg), "Minor axis with IVR %s, separating %.3f %.3f %.3f dist %f", playerships[s].IVR, result.x, result.y, result.z, dist);
3163  logger->Log(msg);
3164 
3165  // angle between the two CG's needs to be widened by the two spheres
3166  // how many units of overlap to separate them by (we are supposed to be 3 but are 2 then we have to sep by 1
3167  const float separation = (playerships[s].componentarray[r].boundsphere + playerships[0].componentarray[q].boundsphere) - dist;
3168  if (separation < 0.0001f) // 10th a meter
3169  continue;
3170 
3171  // use vector from object to us
3172  if (dist < FLT_EPSILON)
3173  {
3174  result.x = RandomFloat() - 0.5f;
3175  result.y = RandomFloat() - 0.5f;
3176  result.z = RandomFloat() - 0.5f;
3177  }
3178  D3DXVECTOR3 resnorm;
3179  D3DXVec3Normalize(&resnorm, &result);
3180  D3DXVec3Scale(&result, &resnorm, separation);
3181 
3183  float ourweight = playerships[0].bound;
3184  float hisweight = playerships[s].bound;
3185  const float mag = 1.0f / (ourweight + hisweight);
3186  ourweight *= mag;
3187  hisweight *= mag;
3188 
3189  D3DXVECTOR3 displacement = result * ourweight;
3190  collision = true;
3191  if (D3DXVec3Length(&displacement) >= 0.001f) // JIRA 1110 don't send if less than 1 meter
3192  {
3193  // send special packet for offline ships
3194  SClientPacket outpacket;
3195  outpacket.type = 5; // collision info
3196  outpacket.f_x = displacement.x;
3197  outpacket.f_y = displacement.y;
3198  outpacket.f_z = displacement.z;
3199  outpacket.f_w = static_cast<float>(playerships[s].vehicleId);
3200  gameclass->networking->SendToServer(&outpacket, sizeof(SClientPacket), true);
3201  }
3202  playerships[s].position += displacement;
3203  playerships[s].precisionx += (double)displacement.x;
3204  playerships[s].precisiony += (double)displacement.y;
3205  playerships[s].precisionz += (double)displacement.z;
3206 
3207  if (playerships[0].reference < REF_INANOTHER)
3208  cross = playerships[0].velocity - playerships[0].barycentric;
3209  else
3210  cross = playerships[0].dockingvel;
3211 
3212  D3DXMATRIX matrixInverse; // need to make new one because we have moved since
3213  D3DXQuaternionNormalize(&playerships[0].orientation, &playerships[0].orientation);
3214  D3DXMatrixRotationQuaternion(&matrixInverse, &playerships[0].orientation);
3215  D3DXVec3TransformNormal(&cross, &cross, &matrixInverse);
3216  sumofforces -= cross * hisweight;
3217 
3219  for (int i = 0; i < MAX_ENGINES; i++)
3220  {
3221  if (ourcockpit.gndvehicle)
3222  gameclass->bus->EngineThrustLever[i] = 0.1f; // idle
3223  else
3224  gameclass->bus->EngineThrustLever[i] = 0.0f; // idle
3225  }
3226 
3227  proposed -= result * hisweight;
3228  proposedx -= static_cast<double>(result.x) * static_cast<double>(hisweight);
3229  proposedy -= static_cast<double>(result.y) * static_cast<double>(hisweight);
3230  proposedz -= static_cast<double>(result.z) * static_cast<double>(hisweight);
3231 
3232 
3233  causechain = 6;
3235 
3236  sprintf_s(msg, sizeof msg, "Collided with IVR %s, separating %.3f %.3f %.3f dist %f", playerships[s].IVR, result.x, result.y, result.z, dist);
3237  logger->Log(msg);
3238  sprintf_s(msg, sizeof msg, "Sumofforces now %.3f %.3f %.3f", sumofforces.x, sumofforces.y, sumofforces.z);
3239  logger->Log(msg);
3240 
3242  q = playerships[0].components;
3243  r = playerships[s].components;
3244  }
3245  }
3246  }
3247  }
3248  }
3249  }
3250 
3251 
3252  // CITY BUILDING COLLISION DETECTION AND AGL OFFSET CALCULATION
3253  if (!collision && !g_bAboveClouds)
3254  {
3255  static VECTOR2SHORT olddepthpos, oldbump;
3256  float f_tempu, f_tempv, f_tempd;
3257  result = -proposed;
3258  D3DXVec3Normalize(&result, &result);
3259 
3260  if (gridarray[31][31].type > PlotType::NotZoned) // some building layout
3261  {
3262  const short VB = gridarray[31][31].buildzoneOrdinal;
3263  if (VB != -1)
3264  {
3265  if (D3DXIntersectTri(&gridarray[32][31].position, &gridarray[31][31].position, &gridarray[32][32].position, &centerC, &result, &f_tempu, &f_tempv, &f_tempd))
3266  {
3267  f_tempu = 1.0f - f_tempu;
3268 
3269  // BUMP
3270  f_tempd = roundf(f_tempu * 6656.0f); // V2-V1
3271  rts.u = static_cast<short>(floorf(f_tempd / 256.0f));
3272  bump.u = static_cast<short>(fmodf(f_tempd, 256.0f));
3273 
3274  f_tempd = roundf(f_tempv * 6656.0f); // V3-V1
3275  rts.v = static_cast<short>(floorf(f_tempd / 256.0f));
3276  bump.v = static_cast<short>(fmodf(f_tempd, 256.0f));
3277 
3278  rts.v = 25 - rts.v;
3279 
3280  f_tempd = f_tempu * static_cast<float>(depthFloorResolutionC); // V2-V1
3281  newdepthpos.u = static_cast<short>(roundf(f_tempd));
3282  f_tempd = f_tempv * static_cast<float>(depthFloorResolutionC); // V3-V1
3283  newdepthpos.v = static_cast<short>(roundf(f_tempd));
3284  }
3285  else if (D3DXIntersectTri(&gridarray[31][32].position, &gridarray[32][32].position, &gridarray[31][31].position, &centerC, &result, &f_tempu, &f_tempv, &f_tempd))
3286  {
3287  f_tempv = 1.0f - f_tempv;
3288 
3289  // BUMP
3290  f_tempd = roundf(f_tempu * 6656.0f); // V2-V1
3291  rts.u = static_cast<short>(floorf(f_tempd / 256.0f));
3292  bump.u = static_cast<short>(fmodf(f_tempd, 256.0f));
3293 
3294  f_tempd = roundf(f_tempv * 6656.0f); // V3-V1
3295  rts.v = static_cast<short>(floorf(f_tempd / 256.0f));
3296  bump.v = static_cast<short>(fmodf(f_tempd, 256.0f));
3297 
3298  rts.v = 25 - rts.v;
3299 
3300  f_tempd = f_tempu * static_cast<float>(depthFloorResolutionC); // V2-V1
3301  newdepthpos.u = static_cast<short>(roundf(f_tempd));
3302  f_tempd = f_tempv * static_cast<float>(depthFloorResolutionC); // V3-V1
3303  newdepthpos.v = static_cast<short>(roundf(f_tempd));
3304  }
3305  else
3306  {
3307  rts.u = rts.v = bump.u = bump.v = -2;
3308  newdepthpos.u = newdepthpos.v = -2;
3309  }
3310  }
3311  else
3312  {
3313  rts.u = rts.v = bump.u = bump.v = -3;
3314  newdepthpos.u = newdepthpos.v = -3;
3315  }
3316  }
3317  else
3318  {
3319  newdepthpos.u = newdepthpos.v = -1;
3320  rts.u = rts.v = bump.u = bump.v = -1;
3321  f_tempu = gameclass->bus->assayProgressU;
3322  f_tempv = gameclass->bus->assayProgressV;
3323  }
3324 
3325 
3326 
3327  float newcityelev, newflorelev;
3328  if (olddepthpos.u != newdepthpos.u || olddepthpos.v != newdepthpos.v)
3329  {
3330  olddepthpos = newdepthpos; // maybe use this to arrest the velocity correctly!!!
3331  newcityelev = CheckDepthMap(newdepthpos, 31, 31);
3334  gameclass->bus->Debug1Vec3.z = newcityelev;
3335  newflorelev = CheckFloorMap(newdepthpos, 31, 31);
3336  }
3337  else
3338  {
3339  newcityelev = citystuff.elevation;
3340  newflorelev = citystuff.floorelev;
3341  }
3342 
3343 
3344  float newcurbelev;
3345  if (oldbump.u != bump.u || oldbump.v != bump.v || (gridarray[31][31].roads && oldbump.u == bump.u && oldbump.v == bump.v))
3346  {
3347  g_bRoad = false;
3348  if (gridarray[31][31].type == PlotType::UserAirfield &&
3349  buildings::CheckLayout(98, gridarray[31][31]) && // runway is completed
3350  f_tempu > 0.73857f && f_tempu < 0.76143189f) // has to match the shader
3351  {
3352  g_bRoad = true;
3353  newcurbelev = 0.0f;
3354  }
3355  else if (gridarray[31][31].roads && CheckPlotRoads(f_tempu, f_tempv))
3356  {
3357  g_bRoad = true;
3358  newcurbelev = 0.0f;
3359  }
3360  else
3361  {
3362  newcurbelev = CheckRtsBumpMap(rts, bump, 31, 31);
3363  }
3364  }
3365  else
3366  {
3367  newcurbelev = citystuff.curbelev;
3368  }
3369 
3370  D3DXVECTOR3 ul = gridarray[31][31].position;
3371  D3DXVECTOR3 ll = gridarray[31][32].position;
3372  D3DXVECTOR3 ur = gridarray[32][31].position;
3373  D3DXVECTOR3 lr = gridarray[32][32].position;
3374  D3DXVECTOR3 plumb;
3375  D3DXVec3Normalize(&plumb, &buildzone[gridarray[31][31].buildzoneOrdinal].terpos);
3376 
3377 
3378  D3DXVECTOR3 leftvec, rightvec, northNormal, eastNormal;
3379  D3DXVec3Subtract(&leftvec, &ll, &ul);
3380  D3DXVec3Subtract(&rightvec, &lr, &ur);
3381  D3DXVec3Add(&northNormal, &leftvec, &rightvec);
3382  D3DXVec3Scale(&northNormal, &northNormal, 0.5f);
3383  D3DXVec3Normalize(&northNormal, &northNormal);
3384 
3385  D3DXVec3Cross(&eastNormal, &northNormal, &plumb);
3386  D3DXVec3Normalize(&eastNormal, &eastNormal);
3387 
3388 
3389  if (f_AGL < newflorelev && newflorelev != 255.0f) // so we can go under overhangs without movement.cpp repositioning us
3390  newcityelev = 0.0f;
3391 
3392  // hit the side
3393  if (f_AGL < newcityelev && newcityelev > 0.0f && deathinhibit == 0.0f)
3394  {
3395  cross = playerships[0].velocity - playerships[0].barycentric; // speed in which they hit the side
3396  D3DXMATRIX matrixInverse; // need to make new one because we have moved since
3397  D3DXQuaternionNormalize(&playerships[0].orientation, &playerships[0].orientation);
3398  D3DXMatrixRotationQuaternion(&matrixInverse, &playerships[0].orientation);
3399  D3DXVec3TransformNormal(&cross, &cross, &matrixInverse);
3400  sumofforces -= cross;
3401 
3402  sprintf_s(msg, sizeof msg, "X%7.3f Y%7.3f Z%7.3f collision side", -cross.x * oneOvergForceKmSSC / ElapsedTime, 0.0f, -cross.z * oneOvergForceKmSSC / ElapsedTime);
3403  sofTracking.emplace_back(msg);
3404 
3405  proposed = playerships[0].position;
3406  proposedx = playerships[0].precisionx;
3407  proposedy = playerships[0].precisiony;
3408  proposedz = playerships[0].precisionz;
3409 
3410  sprintf_s(msg, sizeof msg, "*** Hit side... floor %.3f us %.3f height %f (u%i v%i)", newflorelev, f_AGL, newcityelev, newdepthpos.u, newdepthpos.v);
3411  logger->Log(msg);
3412 
3413  for (int i = 0; i < MAX_ENGINES; i++)
3414  {
3415  if (ourcockpit.gndvehicle)
3416  gameclass->bus->EngineThrustLever[i] = 0.1f; // idle
3417  else
3418  gameclass->bus->EngineThrustLever[i] = 0.0f; // idle
3419  }
3420 
3421  collision = true;
3422  causechain = 4; // city
3423  }
3424  else
3425  {
3426  citystuff.elevation = newcityelev;
3427  citystuff.floorelev = newflorelev;
3428  }
3429 
3430 
3431  // Curbs on bumpmap from RTS
3432  if (playerships[0].reference == REF_ONGROUND && newcityelev == 0.0f && (bump.u != oldbump.u || bump.v != oldbump.v))
3433  {
3434  // sin of 0 is 0, 90 is 1 ... cos of 0 is 1, 90 is 0
3435  const float skiddiff = Clamp(newcurbelev - citystuff.curbelev, -0.0001524f, 0.0001524f); // since you can't see them lets not allow more than 6"
3436  float rolldiff = 1.0f;
3437  if (ourcockpit.tireRadiusKm != 0.0f)
3438  rolldiff = powf(skiddiff / ourcockpit.tireRadiusKm, 2.0f); // for rolling, tire radius
3439  if (rolldiff > 1.0f)
3440  rolldiff = 1.0f; // impassable, can't take more away than 100%
3441 
3442 
3443  if (newcurbelev != 0 || citystuff.curbelev != 0)
3444  {
3445  sprintf_s(msg, sizeof msg, "Bary U%i V%i RTS U%i V%i Bump U%i V%i newcurb %f oldcurb %f", newdepthpos.u, newdepthpos.v, rts.u, rts.v, bump.u, bump.v, newcurbelev, citystuff.curbelev);
3446  logger->Log(msg);
3447  }
3448 
3449  D3DXVECTOR3 overallVector = playerships[0].velocity - playerships[0].barycentric; // velocity across the ground in kms
3450  const float mag = D3DXVec3Length(&overallVector); // kms
3451  if (mag > 0)
3452  {
3453  D3DXVECTOR3 overallNormal = overallVector / mag;
3454 
3455  sprintf_s(msg, sizeof(msg), "-> Overall speed is %.3f", mag);
3456  //logger->Log(msg);
3457 
3458  if (skiddiff > FLT_EPSILON) // riding UP on curb
3459  {
3460  sprintf_s(msg, sizeof(msg), "-> Riding up a curb %.6f", skiddiff);
3461  logger->Log(msg);
3462 
3463  if (rolldiff < 1.0f) // not impassable
3464  {
3465  sprintf_s(msg, sizeof(msg), "-> Not impassable");
3466  logger->Log(msg);
3467 
3468  // if mag is greater than the curbdiff then we can jump the curb
3469  if (mag > rolldiff)
3470  {
3471  sumofforces.y -= skiddiff; // jump the curb
3472  sprintf_s(msg, sizeof(msg), "-> Jumped the curb %.3f, %.6f", rolldiff, skiddiff);
3473  logger->Log(msg);
3474  }
3475  else
3476  {
3477  sprintf_s(msg, sizeof(msg), "-> Hit the curb %.3f, %.6f", rolldiff, skiddiff);
3478  logger->Log(msg);
3479  }
3480  }
3481 
3482 
3483  if (bump.u > oldbump.u && abs(bump.u - oldbump.u) < 128) // traveling east on map into curb
3484  {
3485  float f_temp = D3DXVec3Dot(&overallNormal, &eastNormal); // east component
3486  D3DXVECTOR3 eastVector;
3487  D3DXVec3Scale(&eastVector, &eastNormal, f_temp * mag);
3488 
3489  sprintf_s(msg, sizeof(msg), "-> Was traveling east %.3f at %.3f", f_temp, f_temp * mag);
3490  logger->Log(msg);
3491 
3492  D3DXMATRIX matrixInverse; // need to make new one because we have moved since
3493  D3DXQuaternionNormalize(&playerships[0].orientation, &playerships[0].orientation);
3494  D3DXMatrixRotationQuaternion(&matrixInverse, &playerships[0].orientation);
3495  D3DXVec3TransformCoord(&cross, &eastVector, &matrixInverse);
3496 
3497  sumofforces.z -= cross.z * rolldiff;
3498 
3499  float lateral_x;
3500  if (cross.x > gravityC)
3501  {
3502  lateral_x = -0.0085f; // sliding friction is 75%?
3503  playerships[0].roll += (cross.x - 0.0085f) * 120000.0f / (ourcockpit.momentr * ptrPropulsion->totalWeightLbs) * ElapsedTime;
3504  }
3505  else if (cross.x < -gravityC)
3506  {
3507  lateral_x = 0.0085f;// sliding friction is 75%?
3508  playerships[0].roll += (cross.x + 0.0085f) * 120000.0f / (ourcockpit.momentr * ptrPropulsion->totalWeightLbs) * ElapsedTime;
3509  }
3510  else
3511  {
3512  lateral_x = -cross.x; // blocks 100%
3513  playerships[0].roll += cross.x * 120000.0f / (ourcockpit.momentr * ptrPropulsion->totalWeightLbs) * ElapsedTime;
3514  }
3515  sumofforces.x += lateral_x * ElapsedTime;
3516 
3517  sprintf_s(msg, sizeof msg, "X%7.3f Y%7.3f Z%7.3f collision east", lateral_x * oneOvergForceKmSSC / ElapsedTime, 0.0f, -cross.z * rolldiff * oneOvergForceKmSSC / ElapsedTime);
3518  sofTracking.emplace_back(msg);
3519 
3520  sprintf_s(msg, sizeof msg, "W2E skiddiff %f rolldiff %f cross.x %f cross.z %f cross.z*skiddiff*rolldiff %f ewmag %f", skiddiff, rolldiff, cross.x, cross.z, cross.z * skiddiff * rolldiff, fabsf(f_temp * mag));
3521  logger->Log(msg);
3522  }
3523  else if (bump.u < oldbump.u && abs(bump.u - oldbump.u) < 128) // traveling west on map into curb
3524  {
3525  float f_temp = D3DXVec3Dot(&overallNormal, &eastNormal);
3526  D3DXVECTOR3 eastVector;
3527  D3DXVec3Scale(&eastVector, &eastNormal, f_temp * mag);
3528 
3529  sprintf_s(msg, sizeof(msg), "-> Was traveling west %.3f at %.3f", f_temp, f_temp * mag);
3530  logger->Log(msg);
3531 
3532  D3DXMATRIX matrixInverse; // need to make new one because we have moved since
3533  D3DXQuaternionNormalize(&playerships[0].orientation, &playerships[0].orientation);
3534  D3DXMatrixRotationQuaternion(&matrixInverse, &playerships[0].orientation);
3535  D3DXVec3TransformCoord(&cross, &eastVector, &matrixInverse);
3536 
3537  sumofforces.z -= cross.z * rolldiff;
3538 
3539  float lateral_x;
3540  if (cross.x > gravityC)
3541  {
3542  lateral_x = -0.0085f;// .75 of gravity on this planet
3543  playerships[0].roll += (cross.x - 0.0085f) * 120000.0f / (ourcockpit.momentr * ptrPropulsion->totalWeightLbs) * ElapsedTime;
3544  }
3545  else if (cross.x < -gravityC)
3546  {
3547  lateral_x = 0.0085f;// .75 of gravity on this planet
3548  playerships[0].roll += (cross.x + 0.0085f) * 120000.0f / (ourcockpit.momentr * ptrPropulsion->totalWeightLbs) * ElapsedTime;
3549  }
3550  else
3551  {
3552  lateral_x = -cross.x; // blocks 100%
3553  playerships[0].roll += cross.x * 120000.0f / (ourcockpit.momentr * ptrPropulsion->totalWeightLbs) * ElapsedTime;
3554  }
3555  sumofforces.x += lateral_x * ElapsedTime;
3556 
3557  sprintf_s(msg, sizeof msg, "X%7.3f Y%7.3f Z%7.3f collision west", lateral_x * oneOvergForceKmSSC / ElapsedTime, 0.0f, -cross.z * rolldiff * oneOvergForceKmSSC / ElapsedTime);
3558  sofTracking.emplace_back(msg);
3559 
3560  sprintf_s(msg, sizeof msg, "E2W skiddiff %f rolldiff %f cross.x %f cross.z %f cross.z*skiddiff*rolldiff %f ewmag %f", skiddiff, rolldiff, cross.x, cross.z, cross.z * skiddiff * rolldiff, fabsf(f_temp * mag));
3561  logger->Log(msg);
3562  }
3563 
3564  if (bump.v < oldbump.v && abs(bump.v - oldbump.v) < 128) // traveling north on map into curb
3565  {
3566  float f_temp = D3DXVec3Dot(&overallNormal, &northNormal);
3567  D3DXVECTOR3 northVector;
3568  D3DXVec3Scale(&northVector, &northNormal, f_temp * mag);
3569 
3570  sprintf_s(msg, sizeof(msg), "-> Was traveling north %.3f at %.3f", f_temp, f_temp * mag);
3571  logger->Log(msg);
3572 
3573  D3DXMATRIX matrixInverse; // need to make new one because we have moved since
3574  D3DXQuaternionNormalize(&playerships[0].orientation, &playerships[0].orientation);
3575  D3DXMatrixRotationQuaternion(&matrixInverse, &playerships[0].orientation);
3576  D3DXVec3TransformNormal(&cross, &northVector, &matrixInverse);
3577 
3578  sumofforces.z -= cross.z * rolldiff;
3579 
3580  float lateral_x;
3581  if (cross.x > gravityC)
3582  {
3583  lateral_x = -0.0085f; // .75 of gravity on this planet
3584  playerships[0].roll += (cross.x - 0.0085f) * 120000.0f / (ourcockpit.momentr * ptrPropulsion->totalWeightLbs) * ElapsedTime;
3585  }
3586  else if (cross.x < -gravityC)
3587  {
3588  lateral_x = 0.0085f; // .75 of gravity on this planet
3589  playerships[0].roll += (cross.x + 0.0085f) * 120000.0f / (ourcockpit.momentr * ptrPropulsion->totalWeightLbs) * ElapsedTime;
3590  }
3591  else
3592  {
3593  lateral_x = -cross.x; // blocks 100%
3594  playerships[0].roll += cross.x * 120000.0f / (ourcockpit.momentr * ptrPropulsion->totalWeightLbs) * ElapsedTime;
3595  }
3596  sumofforces.x += lateral_x * ElapsedTime;
3597 
3598  sprintf_s(msg, sizeof msg, "X%7.3f Y%7.3f Z%7.3f collision north", lateral_x * oneOvergForceKmSSC / ElapsedTime, 0.0f, -cross.z * rolldiff * oneOvergForceKmSSC / ElapsedTime);
3599  sofTracking.emplace_back(msg);
3600 
3601  sprintf_s(msg, sizeof msg, "S2N skiddiff %f rolldiff %f cross.x %f cross.z %f cross.z*skiddiff*rolldiff %f nsmag %f", skiddiff, rolldiff, cross.x, cross.z, cross.z * skiddiff * rolldiff, fabsf(f_temp * mag));
3602  logger->Log(msg);
3603  }
3604  else if (bump.v > oldbump.v && abs(bump.v - oldbump.v) < 128) // traveling south on map into curb
3605  {
3606  float f_temp = D3DXVec3Dot(&overallNormal, &northNormal);
3607  D3DXVECTOR3 northVector;
3608  D3DXVec3Scale(&northVector, &northNormal, f_temp * mag);
3609 
3610  sprintf_s(msg, sizeof(msg), "-> Was traveling south %.3f at %.3f", f_temp, f_temp * mag);
3611  logger->Log(msg);
3612 
3613  D3DXMATRIX matrixInverse; // need to make new one because we have moved since
3614  D3DXQuaternionNormalize(&playerships[0].orientation, &playerships[0].orientation);
3615  D3DXMatrixRotationQuaternion(&matrixInverse, &playerships[0].orientation);
3616  D3DXVec3TransformNormal(&cross, &northVector, &matrixInverse);
3617 
3618  sumofforces.z -= cross.z * rolldiff;
3619 
3620  float lateral_x;
3621  if (cross.x > gravityC)
3622  {
3623  lateral_x = -0.0085f;// .75 of gravity on this planet
3624  playerships[0].roll += (cross.x - 0.0085f) * 120000.0f / (ourcockpit.momentr * ptrPropulsion->totalWeightLbs) * ElapsedTime;
3625  }
3626  else if (cross.x < -gravityC)
3627  {
3628  lateral_x = 0.0085f;// .75 of gravity on this planet
3629  playerships[0].roll += (cross.x + 0.0085f) * 120000.0f / (ourcockpit.momentr * ptrPropulsion->totalWeightLbs) * ElapsedTime;
3630  }
3631  else
3632  {
3633  lateral_x = -cross.x; // blocks 100%
3634  playerships[0].roll += cross.x * 120000.0f / (ourcockpit.momentr * ptrPropulsion->totalWeightLbs) * ElapsedTime;
3635  }
3636  sumofforces.x += lateral_x * ElapsedTime;
3637 
3638  sprintf_s(msg, sizeof msg, "X%7.3f Y%7.3f Z%7.3f collision south", lateral_x * oneOvergForceKmSSC / ElapsedTime, 0.0f, -cross.z * rolldiff * oneOvergForceKmSSC / ElapsedTime);
3639  sofTracking.emplace_back(msg);
3640 
3641  sprintf_s(msg, sizeof msg, "N2S skiddiff %f rolldiff %f cross.x %f cross.z %f cross.z*skiddiff*rolldiff %f nsmag %f", skiddiff, rolldiff, cross.x, cross.z, cross.z * skiddiff * rolldiff, fabsf(f_temp * mag));
3642  logger->Log(msg);
3643  }
3644  }
3645  else if (skiddiff < -FLT_EPSILON)
3646  {
3647  // airborne, do this way or gravityacc can be applied to sumofforces (global)
3648  playerships[0].reference = REF_APNMODE;
3649 
3650  sprintf_s(msg, sizeof(msg), "-> Riding down a curb %.6f", skiddiff);
3651  logger->Log(msg);
3652  }
3653  }
3654 
3655  oldbump = bump;
3656  citystuff.curbelev = newcurbelev;
3657  }
3658  }
3659  else
3660  {
3661  citystuff.elevation = 0.0f;
3662  citystuff.floorelev = 255.0f * cityscaleC;
3663  }
3664 
3666  if (!collision && !g_bAboveClouds)
3667  {
3668  if (gridarray[31][31].IsUserColony())
3669  {
3670  short buildZoneOrdinal = gridarray[31][31].buildzoneOrdinal;
3671  if (buildZoneOrdinal != -1)
3672  {
3673  D3DXVECTOR3 oldpos, result1, result2, result3;
3674  oldpos = -playerships[0].position - buildzone[buildZoneOrdinal].terpos;
3675  D3DXVECTOR3 newpos = -(playerships[0].velocity - playerships[0].barycentric);
3676  float magvel = D3DXVec3Length(&newpos);
3677  D3DXVec3Normalize(&newpos, &newpos);
3678  D3DVERTEX* dawverts;
3679  V(buildzone[buildZoneOrdinal].VB->Lock(0, 0, reinterpret_cast<void**>(&dawverts), D3DLOCK_READONLY));
3680 
3681  for (s = 0; s < buildzone[buildZoneOrdinal].components; s++)
3682  {
3683  // types to skip: field crops/algae fields, no bounding sphere, interior of cargo bay
3684  if (buildzone[buildZoneOrdinal].componentarray[s].type == 8 || buildzone[buildZoneOrdinal].componentarray[s].type == 53 || buildzone[buildZoneOrdinal].componentarray[s].type == 54)
3685  continue;
3686 
3687  for (unsigned short r = 0; r < buildzone[buildZoneOrdinal].componentarray[s].primitives; r++)
3688  {
3689  long offset = r * 3 + buildzone[buildZoneOrdinal].componentarray[s].startvertex;
3690  result1.x = (*(dawverts + offset)).x;
3691  result1.y = (*(dawverts + offset)).y;
3692  result1.z = (*(dawverts + offset)).z;
3693  offset++;
3694  result2.x = (*(dawverts + offset)).x;
3695  result2.y = (*(dawverts + offset)).y;
3696  result2.z = (*(dawverts + offset)).z;
3697  offset++;
3698  result3.x = (*(dawverts + offset)).x;
3699  result3.y = (*(dawverts + offset)).y;
3700  result3.z = (*(dawverts + offset)).z;
3701 
3702  float pu, pv, dist;
3703  // this is testing for polygon collision with buildings not the ground
3704  if (D3DXIntersectTri(&result1, &result2, &result3, &oldpos, &newpos, &pu, &pv, &dist))
3705  {
3706  float f_temp = dist - playerships[0].bound;
3707  if (f_temp < (magvel * ElapsedTime))
3708  {
3709  // find perpendicular to surface (normal)
3710  D3DXVECTOR3 side1 = result2 - result1, side2 = result3 - result2;
3711  D3DXVec3Normalize(&side1, &side1);
3712  D3DXVec3Normalize(&side2, &side2);
3713  D3DXVec3Cross(&cross, &side1, &side2);
3714  side1 = cross * f_temp; // distance on vector
3715 
3716  sprintf_s(msg, sizeof msg, "Vehicle %i hit colony polygon %i of module %i at %f %f (dist %f, magvel %f, bound %f)", t, r, s, pu, pv, dist, magvel, playerships[0].bound);
3717  logger->Log(msg);
3718  causechain = 4;
3719  //sumofforces+=playerships[0].velocity-playerships[0].barycentric;
3720  // result=playerships[0].velocity-playerships[0].barycentric;
3721  D3DXMATRIX matrixInverse; // need to make new one because we have moved since
3722  D3DXQuaternionNormalize(&playerships[0].orientation, &playerships[0].orientation);
3723  D3DXMatrixRotationQuaternion(&matrixInverse, &playerships[0].orientation);
3724  D3DXVec3TransformNormal(&cross, &side1, &matrixInverse);
3725 
3726  sprintf_s(msg, 199, "X%7.3f Y%7.3f Z%7.3f collision colony", cross.x * oneOvergForceKmSSC / ElapsedTime, cross.y * oneOvergForceKmSSC / ElapsedTime, cross.z * oneOvergForceKmSSC / ElapsedTime);
3727  sofTracking.emplace_back(msg);
3728 
3729  sumofforces.x += cross.x;//*ElapsedTime;
3730  sumofforces.y += cross.y;//*ElapsedTime;
3731  sumofforces.z += cross.z;//*ElapsedTime;
3732  // leave out y for fun, usually we hit them level
3733 
3734  for (int i = 0; i < MAX_ENGINES; i++)
3735  {
3736  if (ourcockpit.gndvehicle)
3737  gameclass->bus->EngineThrustLever[i] = 0.1f; // idle
3738  else
3739  gameclass->bus->EngineThrustLever[i] = 0.0f; // idle
3740  }
3741 
3742  // proposedx+=(double)side1.x;
3743  // proposedy+=(double)side1.y;
3744  // proposedz+=(double)side1.z;
3745  // proposed+=side1;
3746  // term=true;
3747  // r=buildzone[VB].componentarray[s].primitives;
3748  }
3749  }
3750  // if (term)
3751  // s=buildzone[VB].components;
3752  }
3753  }
3754  V(buildzone[buildZoneOrdinal].VB->Unlock());
3755  }
3756  /*
3757  if (VB!=-1)
3758  {
3759  // figure the ray from our real position to proposed position
3760  // use ray from our real position to CM of planet for f_AGL
3761  D3DXVECTOR3 ourpos=proposed+buildzone[VB].terpos;
3762 
3763  for (s=0; s<buildzone[VB].components; s++)
3764  {
3765  if (buildzone[VB].componentarray[s].attachto==checklayout)
3766  {
3767  sprintf_s(msg, sizeof(msg), "Vehicle checking module %i of structure %i", s, checklayout);
3768  _write(logfile, msg, strlen(msg));
3769 
3770  D3DXMatrixTranslation( &matrixTemp,
3771  buildzone[VB].componentarray[s].nominalxyz.x+buildzone[VB].componentarray[s].nominalCG.x,
3772  buildzone[VB].componentarray[s].nominalxyz.y+buildzone[VB].componentarray[s].nominalCG.y,
3773  buildzone[VB].componentarray[s].nominalxyz.z+buildzone[VB].componentarray[s].nominalCG.z );
3774  D3DXMatrixMultiply( &matrixTemp, &matrixTemp, &buildzone[VB].matrixBase );
3775 
3776  D3DXVec3TransformCoord( &result, &centerC, &matrixTemp );
3777 
3778  result=ourpos+result; // terpos is part of matrixBase
3779  float f_temp=D3DXVec3Length( &result )-buildzone[VB].componentarray[s].boundsphere;
3780  if (f_temp<=playerships[ourshipC].bound)
3781  {
3782  sprintf_s(msg, sizeof(msg), "Vehicle primary, checking secondary...");
3783  _write(logfile, msg, strlen(msg));
3784 
3785  for (short q=0; q<playerships[ourshipC].components; q++)
3786  {
3787  // Extensions for our ship
3788  // result is currently the vector between our CG and his bound
3789  D3DXVECTOR3 modloc=playerships[ourshipC].componentarray[q].nominalxyz;
3790  // This adjusts for orientation and scale, not CG
3791  D3DXVec3TransformCoord( &modloc, &modloc, &playerships[ourshipC].matrixWorld);
3792  //modloc+=playerships[ourshipC].position; // addition or subtraction from our CG
3793  // newresult is vector between module CG and his bound
3794  D3DXVECTOR3 newresult=result-modloc;
3795  float f_temp=D3DXVec3Length( &newresult );
3796 
3797  // sprintf_s(msg, sizeof(msg), "Checking module %i at %.3f %.3f %.3f from our CG (bound %.3f km) new vector %.3f %.3f %.3f (%.3f km)", q, modloc.x, modloc.y, modloc.z, playerships[ourshipC].componentarray[q].boundsphere, newresult.x, newresult.y, newresult.z, f_temp);
3798  // _write(logfile, msg, strlen(msg));
3799 
3800 
3801  if (f_temp<=(playerships[ourshipC].componentarray[q].boundsphere+buildzone[VB].componentarray[s].boundsphere))
3802  {
3803  // how many units of overlap to seperate them by
3804  f_temp-=playerships[ourshipC].componentarray[q].boundsphere+buildzone[VB].componentarray[s].boundsphere;
3805 
3806  // use vector from object to us
3807  if (D3DXVec3Length(&newresult)<FLT_EPSILON)
3808  {
3809  newresult.x=RandomFloat()-0.5f;
3810  newresult.y=RandomFloat()-0.5f;
3811  newresult.z=RandomFloat()-0.5f;
3812  }
3813  D3DXVec3Normalize( &newresult, &newresult );
3814  D3DXVec3Scale( &newresult, &newresult, -f_temp );
3815 
3816  proposed-=newresult;
3817  sumofforces-=newresult;
3818  proposedx-=(double)newresult.x;
3819  proposedy-=(double)newresult.y;
3820  proposedz-=(double)newresult.z;
3821 
3822  if (-f_temp>0.001f)
3823  collision=true;
3824  causechain=4;
3825  // DamageComponent(q);
3826 
3827  q=playerships[ourshipC].components;
3828  }
3829  }
3830  s=buildzone[VB].components;
3831  }
3832  else
3833  {
3834  sprintf_s(msg, sizeof(msg), "No hit, was %.3f km away from CG (boundsphere %.3f km)", D3DXVec3Length(&result), buildzone[VB].componentarray[s].boundsphere);
3835  _write(logfile, msg, strlen(msg));
3836  }
3837  }
3838  }
3839  }
3840  else
3841  {
3842  sprintf_s(msg, sizeof(msg), "Vehicle reports no buildings there!");
3843  _write(logfile, msg, strlen(msg));
3844  }
3845  */
3846  }
3847  }
3848 
3849 
3850 
3851  // It hit one of these objects! should depend on how HARD we hit it
3852  if (collision)
3853  {
3854  if (rand() < 4096 || dockprogress < 1.0f) // 12% chance
3855  {
3856  sprintf_s(msg, sizeof msg, "Collision calling Undock...");
3857  logger->Log(msg);
3858  Undock();
3859  rcsThrustOutputY -= 0.02f;
3860  }
3861  bool senddamage = false;
3862  if (rand() < 4096) // 12% chance
3863  {
3864  if (ourcockpit.vdat.thrustaug > 0)
3865  ourcockpit.vdat.thrustaug -= (char)(RandomFloat() * (float)(ourcockpit.vdat.thrustaug + 1.0f));
3866  senddamage = true;
3867  }
3868  if (rand() < 4096) // 12% chance
3869  {
3870  if (ourcockpit.vdat.yawdamper > 0)
3871  ourcockpit.vdat.yawdamper -= (char)(RandomFloat() * (float)(ourcockpit.vdat.yawdamper + 1.0f));
3872  senddamage = true;
3873  }
3874  if (rand() < 2048) // 6% chance on right engine
3875  {
3876  if (ourcockpit.vdat.rightengine > 0)
3877  ourcockpit.vdat.rightengine -= (char)(RandomFloat() * (float)(ourcockpit.vdat.rightengine + 1.0f));
3878  senddamage = true;
3879  }
3880  if (rand() < 2048) // 6% chance on left engine
3881  {
3882  if (ourcockpit.vdat.leftengine > 0)
3883  ourcockpit.vdat.leftengine -= (char)(RandomFloat() * (float)(ourcockpit.vdat.leftengine + 1.0f));
3884  senddamage = true;
3885  }
3886  if (rand() < 2048) // 6% chance on tail engine
3887  {
3888  if (ourcockpit.vdat.clengine > 0)
3889  ourcockpit.vdat.clengine -= (char)(RandomFloat() * (float)(ourcockpit.vdat.clengine + 1.0f));
3890  senddamage = true;
3891  }
3892  if (rand() < 1024) // 3% chance on vtail
3893  {
3894  if (ourcockpit.vdat.vtail > 0)
3895  ourcockpit.vdat.vtail -= (char)(RandomFloat() * (float)(ourcockpit.vdat.vtail + 1.0f));
3896  senddamage = true;
3897  }
3898  if (rand() < 1024) // 3% chance on htail
3899  {
3900  if (ourcockpit.vdat.htail > 0)
3901  ourcockpit.vdat.htail -= (char)(RandomFloat() * (float)(ourcockpit.vdat.htail + 1.0f));
3902  senddamage = true;
3903  }
3904  if (rand() < 1024) // 3% chance on right wing
3905  {
3906  if (ourcockpit.vdat.rightwing > 0)
3907  ourcockpit.vdat.rightwing -= (char)(RandomFloat() * (float)(ourcockpit.vdat.rightwing + 1.0f));
3908  senddamage = true;
3909  }
3910  if (rand() < 1024) // 3% chance on left wing
3911  {
3912  if (ourcockpit.vdat.leftwing > 0)
3913  ourcockpit.vdat.leftwing -= (char)(RandomFloat() * (float)(ourcockpit.vdat.leftwing + 1.0f));
3914  senddamage = true;
3915  }
3916  if (senddamage)
3917  ourcockpit.vdatChanged = true;
3918 
3919  if (rand() % 2 == 0)
3921  else
3923  }
3924  }
3925 
3926  // At a dock
3927  if (playerships[t].reference >= REF_DOCKCPOC)
3928  {
3929  //logger->AddToCallStack("Viewscreen::Movement Dock Reference");
3930 
3931  playerships[t].dockoffset = proposed; // double proposedxyz not used
3932  playerships[t].precisionx = static_cast<double>(allobjects[playerships[t].reference - REF_DOCKCPOC].position.x) + static_cast<double>(playerships[t].dockoffset.x);
3933  playerships[t].precisiony = static_cast<double>(allobjects[playerships[t].reference - REF_DOCKCPOC].position.y) + static_cast<double>(playerships[t].dockoffset.y);
3934  playerships[t].precisionz = static_cast<double>(allobjects[playerships[t].reference - REF_DOCKCPOC].position.z) + static_cast<double>(playerships[t].dockoffset.z);
3935 
3936  D3DXVec3Add(&playerships[t].position, &playerships[t].dockoffset, &allobjects[playerships[t].reference - REF_DOCKCPOC].position);
3937  D3DXVec3Add(&playerships[t].velocity, &playerships[t].dockingvel, &allobjects[playerships[t].reference - REF_DOCKCPOC].velocity);
3938 
3939  return;
3940  }
3941 
3942  if (playerships[t].reference == REF_PROXIMITY)
3943  {
3944  //logger->AddToCallStack("Viewscreen::Movement Proximity Reference");
3945 
3946  playerships[t].dockoffset = proposed; // double proposedxyz not used
3950 
3951  D3DXVec3Add(&playerships[t].position, &playerships[t].dockoffset, &playerships[playerships[t].inarray].position);
3952  D3DXVec3Add(&playerships[t].velocity, &playerships[t].dockingvel, &playerships[playerships[t].inarray].velocity);
3953 
3954  return;
3955  }
3956 
3957  // Always needed for our altitude BCL
3958  if (t == 0 && !g_bAboveClouds && ptrGrid->dataReady)
3959  {
3960  //logger->AddToCallStack("Viewscreen::Movement BCL");
3961 
3962  // this can't be using proposed position because the map may not have shifted yet
3963  // this one is smoother and supports remote assay
3964  float f_temp = CalculateAGLd(terpos, terprecisionx, terprecisiony, terprecisionz, playerships[0].precisionx, playerships[0].precisiony, playerships[0].precisionz, playerships[0].position, true);
3965  // over a seam, not shifted to next plate terpos yet?
3966  if (f_temp == -1.0f)
3967  {
3968  f_temp = CalculateAGL(31, 31, playerships[0].position, true);
3969  if (f_temp != -1.0f)
3970  {
3971  f_AGL = radiusC + f_MSL - f_temp;
3972  sprintf_s(msg, sizeof msg, "Using... %.3f", f_AGL);
3973  }
3974  else
3975  {
3976  sprintf_s(msg, sizeof msg, "Keeping... %.3f", f_AGL);
3977  }
3978  logger->Log(msg);
3979  }
3980  else
3981  f_AGL = f_temp;
3982 
3983  // f_AGL is the CG height ... if we get within bounding sphere of ground we can do additional checks
3984  float f_AGLeye = f_AGL;
3985  if (f_AGL < playerships[0].bound)
3986  {
3987  D3DXVECTOR3 eyeWorldPos;
3988  D3DXVec3TransformCoord(&eyeWorldPos, &ourcockpit.cockpitArmKm, &playerships[0].matrixWorld); // matrixWorld is just the inverse orientation
3989  const float eyeAGL = CalculateAGLd(terpos, terprecisionx, terprecisiony, terprecisionz, playerships[0].precisionx + eyeWorldPos.x, playerships[0].precisiony + eyeWorldPos.y, playerships[0].precisionz + eyeWorldPos.z, playerships[0].position + eyeWorldPos, false);
3990  if (eyeAGL != -1.0f)
3991  {
3992  f_AGLeye = eyeAGL - 0.0007f;
3993  gameclass->bus->Debug2Vec3.z = f_AGLeye;
3994  }
3995  else
3996  gameclass->bus->Debug2Vec3.z = eyeAGL;
3997  }
3998  else
3999  gameclass->bus->Debug2Vec3.z = 123.0f;
4000 
4001 
4002 
4003  // Things that use this like GPWS would be calibrated at ZERO when the struts are on the ground right-side up
4006 
4007 
4008 
4009  if (fabsf(leveler.x) > 0.0f || fabsf(leveler.y) > 0.0f || fabsf(leveler.z) > 0.0f)
4010  {
4011  D3DXMATRIX matrixInverse;
4012  D3DXMatrixInverse(&matrixInverse, nullptr, &playerships[0].matrixWorld);
4013  D3DXVec3TransformNormal(&cross, &leveler, &matrixInverse);
4014 
4015  if (fabsf(cross.y) > FLT_EPSILON)
4016  {
4017  if (cross.y > 0.0f) // Right-side up
4018  levelerroll = -atanf(cross.x / cross.y);
4019  else if (cross.x < 0.0f)
4020  levelerroll = D3DX_PI - atanf(cross.x / cross.y);
4021  else
4022  levelerroll = -D3DX_PI - atanf(cross.x / cross.y);
4023  levelerpitch = atanf(cross.z / sqrtf(cross.y * cross.y + cross.x * cross.x));
4024  }
4025  else
4026  levelerroll = levelerpitch = 0.0f;
4027  if (cross.y > 0.0f && (ourcockpit.texturelib == E10 || ourcockpit.texturelib == E11)) // right-side up
4028  levelerpitch -= 0.07148944f * ourcockpit.gearextent; // pitch up about 4 degrees
4029 // sprintf_s(msg, sizeof(msg), "-*- %f %f %f (%f %f)...", leveler.x, leveler.y, leveler.z, levelerroll, levelerpitch);
4030 // _write(logfile, msg, strlen(msg));
4031  }
4032  else
4033  {
4034  levelerroll = levelerpitch = 0.0f;
4035  // sprintf_s(msg, sizeof(msg), "-*- Trapped a leveler issue...");
4036  // _write(logfile, msg, strlen(msg));
4037  }
4038 
4039 
4040  // so our CG is 0.000535 above the grade
4041  // our struttoret is 0.000535
4042  // that means we are 0 above
4043 
4044  float f_AGLcg = f_AGL;
4045  if (fabsf(levelerroll) > 1.5708f) // upside down
4046  f_AGLcg -= ourcockpit.rooftoCG;
4047  else
4049 
4050  const float finalAglKm = min(f_AGLcg, f_AGLeye) - citystuff.elevation;
4051  // Touchdown ... say I am 50 feet off ground and structure is 50 feet tall then we are on structure
4052  // say I am 40 and structure is 50 then we will reposition to 50
4053  // so I am 50.0002 and structure is 50 ... 40-50 is <0 50.0002 - 50 is 0.0002
4055  if (finalAglKm < -0.000025f && playerships[0].reference < REF_INANOTHER)
4056  {
4057  sprintf_s(msg, sizeof msg, "Movement snapping us back to 0 as we were at %.4f,%.4f (%.4f) %.4f", f_AGLcg, f_AGLeye, citystuff.elevation, finalAglKm);
4058  logger->Log(msg);
4059  // interpolate to tempaltitude above radius
4060  const float target = -finalAglKm;
4061  double gx = proposedx;
4062  double gy = proposedy;
4063  double gz = proposedz;
4064  const double mag = 1.0 / sqrt(gx * gx + gy * gy + gz * gz);
4065  gx *= mag; gy *= mag; gz *= mag;
4066  gx *= static_cast<double>(target); gy *= static_cast<double>(target); gz *= static_cast<double>(target);
4067  proposedx += gx;
4068  proposedy += gy;
4069  proposedz += gz;
4070  proposed += gthrust * target;
4071 
4072  if (citystuff.elevation == 0.0f)
4073  {
4075  if (gridarray[31][31].pri_landform == 1) // water
4076  causechain = 9; // water
4077  else
4078  causechain = 1; // ground
4079  }
4080  else
4081  causechain = 4; // city
4082 
4083  if (playerships[0].reference != REF_ONGROUND && f_MSL != -1.0f)
4084  {
4085  playerships[0].reference = REF_ONGROUND;
4086 
4087  if (causechain == 9) // water
4088  {
4089  logger->Log("Viewscreen::Movement Splashdown!");
4090  if (rand() < 16384)
4092  else
4094  }
4095  else
4096  {
4097  logger->Log("Viewscreen::Movement Touchdown!");
4099  }
4100 
4101  // ReSharper disable once CppExpressionWithoutSideEffects
4102  gameclass->TurnOffDOR();
4103  // ReSharper disable once CppExpressionWithoutSideEffects
4104  gameclass->TurnOffTVM();
4105 
4106  gameclass->bus->AFCS.CurrentLateralMode = Bus::Afcs::LateralModes::LateralMode_TakeOff;
4107  gameclass->bus->AFCS.CurrentVerticalMode = Bus::Afcs::VerticalModes::VerticalMode_TakeOff;
4110  }
4111  }
4112  else if (finalAglKm > 0.000025f && playerships[0].reference == REF_ONGROUND) // i am 50 and structure is 40 then 10
4113  {
4114  // this is what should allow us to become airborne again if we roll of the top of a building
4115  // so say if it is within 0.000025 then we can snap otherwise we need to become airborne again
4116  // 0.0001524 is a standard curb
4117  if (finalAglKm > 0.0001524f)
4118  {
4119  sprintf_s(msg, sizeof msg, "Movement releasing us to APN mode... we were at %.4f,%.4f (%.4f) %.4f", f_AGLcg, f_AGLeye, citystuff.elevation, finalAglKm);
4120  logger->Log(msg);
4121 
4122  playerships[0].reference = REF_APNMODE;
4123  }
4124  else
4125  {
4126  // so this is the issue ... if we somehow diverge from the ground we need to be snapped back to the ground
4127  sprintf_s(msg, sizeof msg, "Movement snapping us back to 0 as we were at %.4f,%.4f (%.4f) %.4f", f_AGLcg, f_AGLeye, citystuff.elevation, finalAglKm);
4128  logger->Log(msg);
4129  // interpolate to tempaltitude above radius
4130  const float target = -finalAglKm;
4131  double gx = proposedx;
4132  double gy = proposedy;
4133  double gz = proposedz;
4134  const double mag = 1.0 / sqrt(gx * gx + gy * gy + gz * gz);
4135  gx *= mag; gy *= mag; gz *= mag;
4136  gx *= static_cast<double>(target); gy *= static_cast<double>(target); gz *= static_cast<double>(target);
4137  proposedx += gx;
4138  proposedy += gy;
4139  proposedz += gz;
4140  proposed += gthrust * target;
4141  }
4142  }
4143 
4144 
4145  if (playerships[0].reference == REF_ONGROUND && ptrPropulsion->totalWeightLbs > 0)
4146  {
4147  static float oldlevelerroll = 0.0f, oldlevelerpitch = 0.0f;
4148  f_temp = ElapsedTime * sqrtf(277581.7f / ptrPropulsion->totalWeightLbs) * 0.2f;
4149  if (levelerroll > 0.001f && levelerroll < (D3DX_HALFPI - 0.001f))
4150  {
4151  playerships[0].roll -= cosf(levelerroll) * f_temp;
4152  }
4153  else if (levelerroll<-0.001f && levelerroll>(-D3DX_HALFPI + 0.001f))
4154  {
4155  playerships[0].roll += cosf(levelerroll) * f_temp;
4156  }
4157  else if (levelerroll > (D3DX_HALFPI + 0.001f) && levelerroll < (D3DX_PI - 0.001f))
4158  {
4159  playerships[0].roll -= cosf(levelerroll) * f_temp;
4160  }
4161  else if (levelerroll<(-D3DX_HALFPI - 0.001f) && levelerroll>(-D3DX_PI + 0.001f))
4162  {
4163  playerships[0].roll += cosf(levelerroll) * f_temp;
4164  }
4165  else
4166  playerships[0].roll *= 0.6f * f_temp;
4167 
4168  f_temp = ElapsedTime * sqrtf(277581.7f / ptrPropulsion->totalWeightLbs) * 0.15f;
4169  if (fabsf(levelerroll) < D3DX_HALFPI)
4170  {
4171  if (levelerpitch > 0.001f && levelerpitch <= D3DX_HALFPI)
4172  {
4173  playerships[0].pitch -= cosf(levelerpitch) * f_temp;
4174  }
4175  else if (levelerpitch < -0.001f && levelerpitch >= -D3DX_HALFPI)
4176  {
4177  playerships[0].pitch += cosf(levelerpitch) * f_temp;
4178  }
4179  else
4180  playerships[0].pitch *= 0.5f * f_temp;
4182  }
4183  else // Upside-down
4184  {
4185  if (levelerpitch > 0.001f && levelerpitch <= D3DX_HALFPI)
4186  {
4187  playerships[0].pitch += cosf(levelerpitch) * f_temp;
4188  }
4189  else if (levelerpitch < -0.001f && levelerpitch >= -D3DX_HALFPI)
4190  {
4191  playerships[0].pitch -= cosf(levelerpitch) * f_temp;
4192  }
4193  else
4194  playerships[0].pitch *= 0.5f * f_temp;
4196  }
4197 
4198  if (fabsf(levelerroll) < D3DX_HALFPI)
4199  {
4200  if ((levelerroll > 0.001f && oldlevelerroll < 0.001f) ||
4201  (levelerroll < 0.001f && oldlevelerroll > 0.001f))
4202  {
4203  playerships[0].roll *= 0.6f * f_temp; // kill the momentum
4204  if (fabsf(playerships[0].roll) > FLT_EPSILON &&
4205  gridarray[31][31].pri_landform != 1 && gridarray[31][31].pri_landform != 2 && gridarray[31][31].pri_landform != 3) // not water
4206  {
4207  logger->Log("Viewscreen::Movement Leveling roll...");
4209  }
4210  }
4211  }
4212  else // upside down
4213  {
4214  if ((levelerroll < 0.0f && oldlevelerroll > 0.0f) || (levelerroll > 0.0f && oldlevelerroll < 0.0f))
4215  playerships[0].roll *= 0.6f * f_temp;
4216  }
4217 
4218  if ((levelerpitch > 0.0f && oldlevelerpitch < 0.0f) || (levelerpitch < 0.0f && oldlevelerpitch > 0.0f))
4219  {
4220  playerships[0].pitch *= 0.5f * f_temp;
4221 
4222  if (fabsf(playerships[0].pitch) > FLT_EPSILON &&
4223  gridarray[31][31].pri_landform != 1 && gridarray[31][31].pri_landform != 2 && gridarray[31][31].pri_landform != 3) // not water
4224  {
4225  logger->Log("Viewscreen::Movement Leveling pitch...");
4227  }
4228  }
4229  oldlevelerroll = levelerroll; oldlevelerpitch = levelerpitch;
4230 
4231 
4232  // not the steering but the arresting of yaw on the ground
4233  if (!(ourcockpit.gndvehicle || ourcockpit.wheeled) || fabsf(levelerroll) > 0.9f)
4234  playerships[0].yaw *= 0.001f * f_temp; // friction with the surface, not auto-centering because it doesn't touch viewscreen->yaw
4235  }
4236  }
4237 
4238  //logger->AddToCallStack("Viewscreen::Movement Copy Proposed");
4239 
4240  playerships[t].position = proposed;
4241  playerships[t].precisionx = proposedx;
4242  playerships[t].precisiony = proposedy;
4243  playerships[t].precisionz = proposedz;
4244 
4245 
4246  if (t == 0)
4247  {
4248  AssertTelemetry("Viewscreen::Movement2", t);
4249  }
4250 }
4251 
4252 char Viewscreen::CalculateCube(D3DXVECTOR3 position) const
4253 {
4254  logger->AddToCallStack("Viewscreen::CalculateCube");
4255 
4256  D3DXVECTOR3 posnorml;
4257  D3DXVec3Normalize(&posnorml, &position);
4258  posnorml = -posnorml;
4259 
4260  D3DXVECTOR3 cubeface[6];
4261  cubeface[0] = -meridian; //pm
4262  cubeface[1] = eastpole; //ep
4263  cubeface[2] = -eastpole; //wp
4264  cubeface[3] = meridian; //dl
4265  cubeface[4] = northpoleC; //np
4266  cubeface[5] = -northpoleC; // sp
4267 
4268  float f_temp = FLT_MAX, f_temp2;
4269  char cube = -1; // oldcube is the playerships[t].cube
4270  for (short s = 0; s < 6; s++)
4271  {
4272  D3DXVec3Subtract(&cubeface[s], &cubeface[s], &posnorml);
4273  f_temp2 = D3DXVec3Length(&cubeface[s]);
4274  if (f_temp2 < f_temp)
4275  {
4276  f_temp = f_temp2;
4277  cube = (char)s;
4278  }
4279  }
4280  return cube;
4281 }
4282 
4283 VECTOR2SHORT Viewscreen::CalculateCGC(D3DXVECTOR3 position, char cube) const
4284 {
4285  logger->AddToCallStack("Viewscreen::CalculateCGC");
4286 
4287  VECTOR2SHORT tcp = VECTOR2SHORT();
4288  // tcp.u=tcp.v=9999;
4289  // Determine the cubic grid coordinate for [31][31] (tcp)
4290  // ReSharper disable once CppDefaultCaseNotHandledInSwitchStatement
4291  switch (cube)
4292  {
4293  case 0: // pm
4294  {
4295  D3DXVECTOR3 ul, lr, ll;
4296  ul.x = -1.0f; ul.y = -1.0f; ul.z = 1.0f; //ul
4297  lr.x = 1.0f; lr.y = -1.0f; lr.z = -1.0f; //lr
4298  ll.x = -1.0f; ll.y = -1.0f; ll.z = -1.0f; //ll
4299  D3DXPLANE pm;
4300  D3DXPlaneFromPoints(&pm, &ul, &lr, &ll);
4301 
4302  D3DXVec3Normalize(&ul, &position);
4303  D3DXVec3Scale(&ll, &ul, 0.5f);
4304  D3DXVec3Scale(&lr, &ul, 1.5f);
4305  D3DXPlaneIntersectLine(&ul, &pm, &ll, &lr);
4306 
4307  // 0-2038 by 0-2038, but 0-2037 available on this bitmap
4308  tcp.u = (short)((ul.x + 1.0f) * 1019.0f); tcp.v = (short)((ul.z + 1.0f) * 1019.0f);
4309  }
4310  break;
4311  case 1: // ep
4312  {
4313  D3DXVECTOR3 ul, lr, ll;
4314  ul.x = 1.0f; ul.y = -1.0f; ul.z = 1.0f;
4315  lr.x = 1.0f; lr.y = 1.0f; lr.z = -1.0f;
4316  ll.x = 1.0f; ll.y = -1.0f; ll.z = -1.0f;
4317  D3DXPLANE pm;
4318  D3DXPlaneFromPoints(&pm, &ul, &lr, &ll);
4319  // D3DXPlaneNormalize( &pm, &pm );
4320 
4321  D3DXVec3Normalize(&ul, &position);
4322  D3DXVec3Scale(&ll, &ul, 0.5f);
4323  D3DXVec3Scale(&lr, &ul, 1.5f);
4324  D3DXPlaneIntersectLine(&ul, &pm, &ll, &lr);
4325 
4326  // 2038-4076 by 0-2038
4327  tcp.u = (short)((ul.y + 1.0f) * 1019.0f) + 2038; tcp.v = (short)((ul.z + 1.0f) * 1019.0f);
4328  }
4329  break;
4330  case 2: // wp
4331  {
4332  D3DXVECTOR3 ul, lr, ll;
4333  ul.x = -1.0f; ul.y = 1.0f; ul.z = 1.0f;
4334  lr.x = -1.0f; lr.y = -1.0f; lr.z = -1.0f;
4335  ll.x = -1.0f; ll.y = 1.0f; ll.z = -1.0f;
4336  D3DXPLANE pm;
4337  D3DXPlaneFromPoints(&pm, &ul, &lr, &ll);
4338  // D3DXPlaneNormalize( &pm, &pm );
4339 
4340  D3DXVec3Normalize(&ul, &position);
4341  D3DXVec3Scale(&ll, &ul, 0.5f);
4342  D3DXVec3Scale(&lr, &ul, 1.5f);
4343  D3DXPlaneIntersectLine(&ul, &pm, &ll, &lr);
4344 
4345  // -2038-0 by 0-2038
4346  tcp.u = (short)((-ul.y + 1.0f) * 1019.0f) - 2038; tcp.v = (short)((ul.z + 1.0f) * 1019.0f); // backwards
4347  }
4348  break;
4349  case 3: // dl
4350  {
4351  D3DXVECTOR3 ul, lr, ll;
4352  ul.x = 1.0f; ul.y = 1.0f; ul.z = 1.0f;
4353  lr.x = -1.0f; lr.y = 1.0f; lr.z = -1.0f;
4354  ll.x = 1.0f; ll.y = 1.0f; ll.z = -1.0f;
4355  D3DXPLANE pm;
4356  D3DXPlaneFromPoints(&pm, &ul, &lr, &ll);
4357  // D3DXPlaneNormalize( &pm, &pm );
4358 
4359  D3DXVec3Normalize(&ul, &position);
4360  D3DXVec3Scale(&ll, &ul, 0.5f);
4361  D3DXVec3Scale(&lr, &ul, 1.5f);
4362  D3DXPlaneIntersectLine(&ul, &pm, &ll, &lr);
4363 
4364  // 4076-6114 by 0-2038
4365  tcp.u = (short)((-ul.x + 1.0f) * 1019.0f) + 4076; tcp.v = (short)((ul.z + 1.0f) * 1019.0f); // backwards
4366  }
4367  break;
4368  case 4: // np
4369  {
4370  D3DXVECTOR3 ul, lr, ll;
4371  ul.x = -1.0f; ul.y = 1.0f; ul.z = -1.0f;
4372  lr.x = 1.0f; lr.y = -1.0f; lr.z = -1.0f;
4373  ll.x = -1.0f; ll.y = -1.0f; ll.z = -1.0f;
4374  D3DXPLANE pm;
4375  D3DXPlaneFromPoints(&pm, &ul, &lr, &ll);
4376  // D3DXPlaneNormalize( &pm, &pm );
4377 
4378  D3DXVec3Normalize(&ul, &position);
4379  D3DXVec3Scale(&ll, &ul, 0.5f);
4380  D3DXVec3Scale(&lr, &ul, 1.5f);
4381  D3DXPlaneIntersectLine(&ul, &pm, &ll, &lr);
4382 
4383  // 0-2038 by -2038-0
4384  tcp.u = (short)((ul.x + 1.0f) * 1019.0f);
4385  tcp.v = (short)((-ul.y + 1.0f) * 1019.0f) - 2038; // backwards
4386  }
4387  break;
4388  case 5: // sp
4389  {
4390  D3DXVECTOR3 ul, lr, ll;
4391  ul.x = -1.0f; ul.y = -1.0f; ul.z = 1.0f;
4392  lr.x = 1.0f; lr.y = 1.0f; lr.z = 1.0f;
4393  ll.x = -1.0f; ll.y = 1.0f; ll.z = 1.0f;
4394  D3DXPLANE pm;
4395  D3DXPlaneFromPoints(&pm, &ul, &lr, &ll);
4396  // D3DXPlaneNormalize( &pm, &pm );
4397 
4398  D3DXVec3Normalize(&ul, &position);
4399  D3DXVec3Scale(&ll, &ul, 0.5f);
4400  D3DXVec3Scale(&lr, &ul, 1.5f);
4401  D3DXPlaneIntersectLine(&ul, &pm, &ll, &lr);
4402 
4403  // 0-2038 by 2038-4076
4404  tcp.u = (short)((ul.x + 1.0f) * 1019.0f); tcp.v = (short)((ul.y + 1.0f) * 1019.0f) + 2038;
4405  }
4406  break;
4407  } // switch (cube)
4408  return tcp;
4409 }
4410 
4411 VECTOR2SHORT Viewscreen::CalculateWrap(short u, short v, char cube, char* rotate) const
4412 {
4413  logger->AddToCallStack("Viewscreen::CalculateWrap");
4414  // Checking for corners, wrapping, alignment issues, et al.
4415  // That is the correct information for the vertex color, elevation, position
4416  // However, the UL grid system and texel coordinates are botched
4417  *rotate = 0;
4418  // ReSharper disable once CppDefaultCaseNotHandledInSwitchStatement
4419  switch (cube)
4420  {
4421  case 0: // pm (no rotations required) (no wrapping required)
4422  {
4423  if (u == 2038 && v < 0) // need the adjacency data to RIGHT for VP to render it!
4424  {
4425  // come in top of EP so as 2038,-1 becomes 2039,0 and 2038,-2 is 2040,0
4426  u -= v;
4427  v = 0;
4428  // rotation doesn't matter because we won't really render it
4429  }
4430  else if ((u < 0 || u > 2037) && (v < 0 || v > 2037)) // in the ul or ur, ll or lr void
4431  {
4432  u = 30000;
4433  v = 30000; // set some sort of type to keep these from being drawn
4434  }
4435  break;
4436  }
4437  case 1: // ep
4438  {
4439  if (v < 0 && u == 2038) // this is the missing adjacency data bottom of NP
4440  {
4441  // should be top of PM
4442  // so 2038,-1 should be 2037,0
4443  // so 2038,-2 should be 2036,0
4444  u = (short)(2038 + v);
4445  v = 0;
4446  *rotate = 1; // right 90 don't think it matters though because it will never get rendered!
4447  }
4448  else if ((u < 2038 || u>4076) && (v < 0 || v>2038)) // in the ul, ll corner void, (ur and lr corner void added 10/30/05)
4449  {
4450  u = 30000;
4451  v = 30000; // set some sort of type to keep these from being drawn
4452  }
4453  else if (u == 2038 && v < 0) // np doesn't have a right seam
4454  {
4455  u = 30000;
4456  v = 30000; // set some sort of type to keep these from being drawn
4457  }
4458  else if (u > 2038 && u < 4076 && v < 0) // off top of ep come in right of np, flip axes
4459  {
4460  short vtemp = v;
4461  v = -u + 2038;
4462  u = 2038 + vtemp;
4463  *rotate = 1; // right 90
4464  }
4465  else if (u >= 2038 && u <= 4076 && v > 2037) // off bottom of ep come in right of sp, flip axes
4466  {
4467  // 2039 2039 - 2037 2039
4468  short vtemp = v;
4469  v = u;
4470  u = 2038 - (vtemp - 2038);
4471  *rotate = -1; // left 90
4472  }
4473  else if (u > 4076 && u < 6114 && v>2037) // off bottom of dl come in bottom of sp, flip u
4474  {
4475  u = 6114 - u;
4476  v = 4076 - (v - 2038);
4477  }
4478  break;
4479  }
4480  case 2: // wp
4481  {
4482  if (u >= 0 && (v < 0 || v > 2037)) // in the ur, lr corner void
4483  {
4484  u = 30000;
4485  v = 30000; // set some sort of type to keep these from being drawn
4486  }
4487  else if (v < 0 && u >= -2038 && u < 0) // off top of wp come in left of np but flip axes
4488  {
4489  // -1, 0 should be 0, -1
4490  // -1, -1 should be 1, -1
4491  short vtemp = v; // 0
4492  v = u; // from U -2038 through -1 to V -2038 through -1 ... -1
4493  u = (short)-vtemp; // from V -1 through -32 to U 1 to 32
4494  *rotate = -1; // left 90
4495  }
4496  else if (v >= 2038 && u >= -2038 && u <= 0) // off bottom of wp come in left of sp but flip axes
4497  {
4498  short vtemp = v;
4499  v = (short)(2038 - u);
4500  u = (short)(vtemp - 2038);
4501  *rotate = 1; // right 90
4502  }
4503  else if (u < -2038) // Easy to map from wp to dl
4504  {
4505  u += 8152;
4506  }
4507  break;
4508  }
4509  case 3: // dl
4510  {
4511  if ((u < 4076 || u>6114) && (v < 0 || v>2038)) // in the corner voids
4512  {
4513  u = 30000; v = 30000; // set some sort of type to keep these from being drawn
4514  }
4515  else if (u == 4076 && v < 0) // np doesn't have a right seam, replicate ep top seam
4516  {
4517  u = 4076 + v; v = 0;
4518  }
4519  else if (u == 6114 && v < 0) // np doesn't have a left seam, replicate wp top seam
4520  {
4521  u = 6114 - v - 8152; v = 0;
4522  }
4523  else if (u > 4076 && u < 6114 && v < 0) // off top of dl come in top of np, flip u
4524  {
4525  u = (short)abs(u - 6114);
4526  v = -2038 - v;
4527  }
4528  else if (u < 4076 && v == 2038) // ep doesn't have a bottom seam, replicate sp right seam
4529  {
4530  v = u; u = 2038;
4531  }
4532  else if (u > 6113 && v == 2038) // wp doesn't have a bottom seam, replicate sp left seam
4533  {
4534  v = 10190 - u; u = 0;
4535  }
4536  else if (u >= 4076 && u < 6114 && v >= 2038) // off bottom of dl come in bottom of sp, flip u
4537  {
4538  // 4076,2038 = 2038,4076
4539  // 4077,2039 =
4540  u = (short)abs(u - 6114);
4541  v = 4076 - (v - 2038);
4542  }
4543  else if (u >= 6114) // Easy to map from dl to wp
4544  {
4545  u -= 8152;
4546  }
4547  break;
4548  }
4549  case 4: // np
4550  {
4551  if (u == 2039 && v > 0) // right side of PM needs adjacency data in order to draw! 12/29/2017
4552  {
4553  }
4554  else if ((u < 0 || u>2038) && (v < -2038 || v>0)) // in the corner voids
4555  {
4556  u = 30000; v = 30000; // set some sort of type to keep these from being drawn
4557  }
4558  else if (u < 0 && v == 0) // wp doesn't have a right seam, replicate pm left seam
4559  {
4560  v = -u; u = 0; // This is done seperately because it is correctly oriented
4561  }
4562  else if (u < 1 && v >= -2038 && v < 0) // off left of np come in top of wp but flip axes
4563  {
4564  short vtemp = v;
4565  v = -u; // from U 0 through -31 to V 0 through 31
4566  u = vtemp; // from V -2317 through -1 to U -2318 to -2
4567  }
4568  else if (u > 2038 && v == -2038) // ep doesn't have a right seam, replicate dl left seam
4569  {
4570  v = u - 2038; u = 4076;
4571  }
4572  else if (u >= 2038 && v >= -2038 && v < 0) // off right of np come in top of ep but flip axes
4573  {
4574  short vtemp = v;
4575  v = u - 2038;
4576  u = 2038 - vtemp;
4577  }
4578  else if (u > 0 && u <= 2038 && v <= -2038) // off top of np, come in top of dl
4579  {
4580  u = 6114 - u;
4581  v = -v - 2038;
4582  }
4583  break;
4584  }
4585  case 5: // sp
4586  if ((u < 0 || u > 2038) && (v < 2038 || v >= 4076)) // in the ul, ur corner voids
4587  {
4588  u = 30000;
4589  v = 30000; // set some sort of type to keep these from being drawn
4590  }
4591  else if (u < 0 && v > 2038 && v < 4076) // off left of sp come in bottom of wp but flip axes
4592  {
4593  short vtemp = v;
4594  v = (short)(u + 2038);
4595  u = (short)(2038 - vtemp);
4596  }
4597  // This one doesn't need a "ep doesn't have a seam" because it will go to the dl automatically
4598  else if (u > 2038 && v >= 2038 && v < 4076) // off right of sp come in bottom of ep but flip axes
4599  {
4600  // corrected 6/1/2019 to be u > 2038 instead of u >= 2038
4601  short vtemp = v;
4602  v = (short)(2038 - (u - 2038));
4603  u = vtemp;
4604  }
4605  // Can't let this one go automatic because there is nothing to check the wrap from wp to dl
4606  else if (u == 0 && v >= 4076) // dl doesn't have a right seam, replicate wp left seam
4607  {
4608  u = -2038;
4609  v = (short)(6114 - v);
4610  }
4611  else if (u > 0 && u <= 2038 && v >= 4076) // off bottom of sp, come in bottom of dl, flip u & v
4612  {
4613  u = (short)(2038 - u + 4076);
4614  v = (short)(6114 - v);
4615  }
4616  break;
4617  } // switch (cube)
4618 
4619  VECTOR2SHORT tcp;
4620  tcp.u = u; tcp.v = v;
4621  return tcp;
4622 }
4623 
4624 LOCALGRID2 Viewscreen::CalculateSRV(short t, short s, VECTOR2SHORT tcp, char cube, SRenderVertex sourcedata)
4625 {
4626  logger->AddToCallStack("Viewscreen::CalculateSRV");
4627  // gridtemp.align=0; // No special orientation
4628 
4629  LOCALGRID2 gridtemp;
4630 
4631  char rotate;
4632  const VECTOR2SHORT temp = CalculateWrap(tcp.u + t - 31, tcp.v + s - 31, cube, &rotate);
4633  gridtemp.tcp = temp;
4634 
4635  if (temp.u == 30000 || temp.v == 30000 || sourcedata.pri_landform == 255)
4636  {
4637  gridtemp.pri_landform = 255; // set some sort of flag to keep these from being drawn
4638  gridtemp.pri_transition = 0;
4639  gridtemp.sec_landform = 0;
4640  gridtemp.sec_transition = 0;
4641  gridtemp.ter_landform = 0;
4642  gridtemp.type = PlotType::DoNotRender;
4643  gridtemp.position.x = static_cast<float>(tcp.u + t - 31);
4644  gridtemp.position.y = static_cast<float>(tcp.v + s - 31);
4645  gridtemp.position.z = 0.0f;
4646  gridtemp.cloudpos = -playerships[0].position * 2.0f;
4647  gridtemp.zone = 0;
4648  gridtemp.elevation = 0;
4649  gridtemp.raster = 0UL;
4650  gridtemp.powered = false;
4651  gridtemp.roads = 0;
4652  gridtemp.layout1 = gridtemp.layout2 = gridtemp.layout3 = gridtemp.layout4 = 0L;
4653  return gridtemp;
4654  }
4655 
4656 
4657  // these get zeroed out when released, overwritten with buildings
4658  gridtemp.buildzoneOrdinal = gridarray[t][s].buildzoneOrdinal;
4659  gridtemp.zone = gridarray[t][s].zone;
4660  gridtemp.layout1 = gridarray[t][s].layout1;
4661  gridtemp.layout2 = gridarray[t][s].layout2;
4662  gridtemp.layout3 = gridarray[t][s].layout3;
4663  gridtemp.layout4 = gridarray[t][s].layout4;
4664  gridtemp.powered = gridarray[t][s].powered;
4665  gridtemp.type = gridarray[t][s].type;
4666  gridtemp.specular = gridarray[t][s].specular;
4667 
4668 
4669  gridtemp.raster = sourcedata.color;
4670 
4671  if (sourcedata.pri_landform >= landformtextureC)
4672  {
4673  sprintf_s(msg, sizeof msg, "Got a pri_landform type %i that we don't recognize at %i %i!", sourcedata.pri_landform, gridtemp.tcp.u, gridtemp.tcp.v);
4675  }
4676  gridtemp.pri_landform = sourcedata.pri_landform;
4677 
4678  // transition can be 255 to signify that we don't know actually how to transition it
4679  if (sourcedata.pri_transition > transitiontextureC) // > because 15 is valid
4680  gridtemp.pri_transition = 0;
4681  gridtemp.pri_transition = sourcedata.pri_transition;
4682 
4683  if (sourcedata.sec_landform >= landformtextureC && sourcedata.pri_transition)
4684  logger->Log("Got a sec_landform type that we don't recognize!", Logger::Fatal);
4685  gridtemp.sec_landform = sourcedata.sec_landform;
4686 
4687  if (sourcedata.sec_transition > transitiontextureC) // > because 15 is valid
4688  gridtemp.sec_transition = 0;
4689  gridtemp.sec_transition = sourcedata.sec_transition;
4690 
4691  if (sourcedata.ter_landform >= landformtextureC && sourcedata.sec_transition)
4692  logger->Log("Got a ter_landform type that we don't recognize!", Logger::Fatal);
4693  gridtemp.ter_landform = sourcedata.ter_landform;
4694 
4695  //gridtemp.type = 0;
4696 
4697 
4698  //gridtemp.specular = 0UL;
4699 
4700  gridtemp.elevation = sourcedata.elevation;
4701 
4702  // 255*( 0.4 to 0.6 ) multiplied by 2X is .8 to 1.2 which means the highest color on the
4703  // texture map can be 212
4704  const unsigned char uc_temp = static_cast<unsigned char>(255.0f - RandomFloat() * 0.2f);
4705  gridtemp.clouddif = D3DCOLOR_XRGB(uc_temp, uc_temp, uc_temp);
4706 
4707  D3DXVECTOR3 planar = CalculatePlanar(temp.u, temp.v);
4708  if (planar.x == 0.0f && planar.y == 0.0f && planar.z == 0.0f)
4709  {
4710  gridtemp.position = gridtemp.cloudpos = planar;
4711  sprintf_s(msg, sizeof msg, "CalculateSRV found a renderable plot at u%i v%i but couldn't determine CalculatePlanar!", temp.u, temp.v);
4713  }
4714  else
4715  {
4716  const float elevation = static_cast<float>(gridtemp.elevation) * 0.001f;
4717  const float height = -(radiusC + elevation);
4718  D3DXVec3Scale(&gridtemp.position, &planar, height);
4719 
4720  // For clouds, fixed at ground and then elevated
4721  D3DXVec3Scale(&gridtemp.cloudpos, &planar, -radiusC);
4722  }
4723 
4724  gridtemp.roads = sourcedata.roads;
4725 
4726  return gridtemp;
4727 }
4728 
4729 D3DXVECTOR3 Viewscreen::D3DXVec3Qerp(D3DXVECTOR3* vel0, D3DXVECTOR3* vel1, D3DXVECTOR3* vel2, float t) const
4730 {
4731  logger->AddToCallStack("Viewscreen::D3DXVec3Qerp");
4732 
4733  const float t0 = 0.0f;
4734  const float t1 = 1.0f;
4735  const float t2 = 2.0f;
4736 
4737  const float scale0 = ((t - t1) / (t0 - t1)) * ((t - t2) / (t0 - t2));
4738  const float scale1 = ((t - t0) / (t1 - t0)) * ((t - t2) / (t1 - t2));
4739  const float scale2 = ((t - t0) / (t2 - t0)) * ((t - t1) / (t2 - t1));
4740 
4741  D3DXVECTOR3 newvel0, newvel1, newvel2;
4742  D3DXVec3Scale(&newvel0, vel0, scale0);
4743  D3DXVec3Scale(&newvel1, vel1, scale1);
4744  D3DXVec3Scale(&newvel2, vel2, scale2);
4745 
4746  return newvel0 + newvel1 + newvel2;
4747 }
4748 
4749 long Viewscreen::FontOffset(char letter) const
4750 {
4751  logger->AddToCallStack("Viewscreen::FontOffset");
4752  // skip space = 32
4753  // % = 33 $ = 34 # = 35 " = 36 ! = 37
4754  // & = 38 ' = 39 ( = 40 ) = 41 * = 42 + = 43 , = 44
4755  // - = 45 . = 46 / = 47
4756  // 0123456789 = 48 to 57
4757  // : = 58 ; = 59 < = 60 = = 61 > = 62 ? = 63 @ = 64
4758  // A-Z = 65 to 90
4759  // [ = 91 \ = 92 ] = 93 ^ = 94 _ = 95 ` = 96
4760  // { = 123 | = 124 } = 125 ~ = 126 ¦ = 127
4761  if (letter >= 65 && letter <= 90)
4762  return (long)(letter - 65) * 23;
4763  if (letter == 38)
4764  return 26 * 23;
4765  if (letter == 45)
4766  return 27 * 23;
4767  if (letter >= 48 && letter <= 57)
4768  return (long)(letter - 20) * 23;
4769 
4770  return 38 * 23; // blank space
4771 }
4772 
4773 float Viewscreen::CheckDepthMap(VECTOR2SHORT newdepthpos, short u, short v)
4774 {
4775  logger->AddToCallStack("Viewscreen::CheckDepthMap");
4776 
4777  int depthFile = -2;
4779  {
4780  // ReSharper disable once CppDefaultCaseNotHandledInSwitchStatement
4781  switch (gridarray[u][v].type)
4782  {
4783  case PlotType::DeoisFinancial: _sopen_s(&depthFile, "Textures\\Cities\\deoisdepth.bmp", _O_RDONLY | O_BINARY, _SH_DENYWR, _S_IWRITE);
4784  break;
4785  case PlotType::DeoisIndustrial: _sopen_s(&depthFile, "Textures\\Cities\\deoisdepth1.bmp", _O_RDONLY | O_BINARY, _SH_DENYWR, _S_IWRITE);
4786  break;
4787  case PlotType::DeoisCityCenter: _sopen_s(&depthFile, "Textures\\Cities\\deoisdepth2.bmp", _O_RDONLY | O_BINARY, _SH_DENYWR, _S_IWRITE);
4788  break;
4789  case PlotType::DeoisTransit: _sopen_s(&depthFile, "Textures\\Cities\\deoisdepth3.bmp", _O_RDONLY | O_BINARY, _SH_DENYWR, _S_IWRITE);
4790  break;
4791  case PlotType::DeoisPort: _sopen_s(&depthFile, "Textures\\Cities\\deoisdepth4.bmp", _O_RDONLY | O_BINARY, _SH_DENYWR, _S_IWRITE);
4792  break;
4793  case PlotType::Arcridge: _sopen_s(&depthFile, "Textures\\Cities\\arcridgedepth.bmp", _O_RDONLY | O_BINARY, _SH_DENYWR, _S_IWRITE);
4794  break;
4795  case PlotType::O4Ruin1: _sopen_s(&depthFile, "Textures\\Cities\\o4ruindepth1.bmp", _O_RDONLY | O_BINARY, _SH_DENYWR, _S_IWRITE);
4796  break;
4797  case PlotType::O4Ruin2: _sopen_s(&depthFile, "Textures\\Cities\\o4ruindepth2.bmp", _O_RDONLY | O_BINARY, _SH_DENYWR, _S_IWRITE);
4798  break;
4799  case PlotType::O4Ruin3: _sopen_s(&depthFile, "Textures\\Cities\\o4ruindepth3.bmp", _O_RDONLY | O_BINARY, _SH_DENYWR, _S_IWRITE);
4800  break;
4801  case PlotType::O4Ruin4: _sopen_s(&depthFile, "Textures\\Cities\\o4ruindepth4.bmp", _O_RDONLY | O_BINARY, _SH_DENYWR, _S_IWRITE);
4802  break;
4803  }
4804 
4805  if (depthFile != -2)
4806  {
4807  if (depthFile == -1)
4808  {
4809  sprintf_s(msg, sizeof(msg), "DEPTH Could not find depth file for type %i!", gridarray[u][v].type);
4810  logger->Log(msg, Logger::Level::Fatal);
4811  }
4812  unsigned char uch_temp;
4813  unsigned long bpr = depthFloorResolutionC; // VERIFIED WITH SPE greyscale 2039, 2039 has 1024 additional header
4814  unsigned long k = 54L + 1024L + newdepthpos.u + (bpr - newdepthpos.v - 1L) * bpr;
4815  _lseek(depthFile, k, SEEK_SET);
4816  _read(depthFile, &uch_temp, 1);
4817  _close(depthFile);
4818 
4819  return static_cast<float>(uch_temp) * cityscaleC;
4820  }
4821  }
4822 
4823  return 0.0f;
4824 }
4825 
4826 float Viewscreen::CheckFloorMap(VECTOR2SHORT newdepthpos, short u, short v)
4827 {
4828  logger->AddToCallStack("Viewscreen::CheckFloorMap");
4829  int floorFile = -2;
4831  {
4832  // ReSharper disable once CppDefaultCaseNotHandledInSwitchStatement
4833  switch (gridarray[u][v].type)
4834  {
4835  case PlotType::DeoisFinancial: _sopen_s(&floorFile, "Textures\\Cities\\deoisfloor.bmp", _O_RDONLY | O_BINARY, _SH_DENYWR, _S_IWRITE);
4836  break;
4837  case PlotType::DeoisIndustrial: _sopen_s(&floorFile, "Textures\\Cities\\deoisfloor1.bmp", _O_RDONLY | O_BINARY, _SH_DENYWR, _S_IWRITE);
4838  break;
4839  case PlotType::DeoisCityCenter: _sopen_s(&floorFile, "Textures\\Cities\\deoisfloor2.bmp", _O_RDONLY | O_BINARY, _SH_DENYWR, _S_IWRITE);
4840  break;
4841  case PlotType::DeoisTransit: _sopen_s(&floorFile, "Textures\\Cities\\deoisfloor3.bmp", _O_RDONLY | O_BINARY, _SH_DENYWR, _S_IWRITE);
4842  break;
4843  case PlotType::DeoisPort: _sopen_s(&floorFile, "Textures\\Cities\\deoisfloor4.bmp", _O_RDONLY | O_BINARY, _SH_DENYWR, _S_IWRITE);
4844  break;
4845  case PlotType::Arcridge: _sopen_s(&floorFile, "Textures\\Cities\\arcridgefloor.bmp", _O_RDONLY | O_BINARY, _SH_DENYWR, _S_IWRITE);
4846  break;
4847  case PlotType::O4Ruin1: _sopen_s(&floorFile, "Textures\\Cities\\o4ruinfloor1.bmp", _O_RDONLY | O_BINARY, _SH_DENYWR, _S_IWRITE);
4848  break;
4849  case PlotType::O4Ruin2: _sopen_s(&floorFile, "Textures\\Cities\\o4ruinfloor2.bmp", _O_RDONLY | O_BINARY, _SH_DENYWR, _S_IWRITE);
4850  break;
4851  case PlotType::O4Ruin3: _sopen_s(&floorFile, "Textures\\Cities\\o4ruinfloor3.bmp", _O_RDONLY | O_BINARY, _SH_DENYWR, _S_IWRITE);
4852  break;
4853  case PlotType::O4Ruin4: _sopen_s(&floorFile, "Textures\\Cities\\o4ruinfloor4.bmp", _O_RDONLY | O_BINARY, _SH_DENYWR, _S_IWRITE);
4854  break;
4855  }
4856 
4857  if (floorFile != -2)
4858  {
4859  if (floorFile == -1)
4860  {
4861  sprintf_s(msg, sizeof msg, "Could not find floor file %i!", gridarray[u][v].type);
4862  logger->Log(msg, Logger::Level::Fatal);
4863  }
4864  unsigned char uch_temp;
4865  unsigned long bpr = depthFloorResolutionC; // VERIFIED WITH SPE greyscale 2039, 2039 has 1024 additional header
4866  unsigned long k = 54L + 1024L + newdepthpos.u + (bpr - newdepthpos.v - 1L) * bpr;
4867  _lseek(floorFile, k, SEEK_SET);
4868  _read(floorFile, &uch_temp, 1);
4869  _close(floorFile);
4870  return static_cast<float>(uch_temp) * cityscaleC;
4871  }
4872  }
4873 
4874  return 255.0f;
4875 }
4876 
4877 float Viewscreen::CheckRtsBumpMap(VECTOR2SHORT rts, VECTOR2SHORT bump, short u, short v)
4878 {
4879  logger->AddToCallStack("Viewscreen::CheckRtsBumpMap");
4880 
4881  g_bRoad = false;
4882 
4883  if (!gridarray[u][v].UsesRts())
4884  return 0.0f;
4885 
4886  if (rts.u >= 0 && rts.u < 26 && rts.v >= 0 && rts.v < 26 &&
4887  bump.u >= 0 && bump.u < 256 && bump.v >= 0 && bump.v < 256 &&
4888  gridarray[u][v].buildzoneOrdinal != -1 &&
4890  {
4891  char file[MAX_PATH];
4892  switch (buildzone[gridarray[u][v].buildzoneOrdinal].rts[rts.u * 26 + rts.v].texture)
4893  {
4894  case 1: strcpy_s(file, MAX_PATH, "Textures\\RTS\\f1a_BUMP.bmp"); break;
4895  case 2: strcpy_s(file, MAX_PATH, "Textures\\RTS\\f1b_BUMP.bmp"); break;
4896  case 3: strcpy_s(file, MAX_PATH, "Textures\\RTS\\f1c_BUMP.bmp"); break;
4897  case 4: strcpy_s(file, MAX_PATH, "Textures\\RTS\\f2a_BUMP.bmp"); break;
4898  case 5: strcpy_s(file, MAX_PATH, "Textures\\RTS\\f2b_BUMP.bmp"); break;
4899  case 6: strcpy_s(file, MAX_PATH, "Textures\\RTS\\f2c_BUMP.bmp"); break;
4900  case 7: strcpy_s(file, MAX_PATH, "Textures\\RTS\\f3a_BUMP.bmp"); break;
4901  case 8: strcpy_s(file, MAX_PATH, "Textures\\RTS\\f3b_BUMP.bmp"); break;
4902  case 9: strcpy_s(file, MAX_PATH, "Textures\\RTS\\f4a_BUMP.bmp"); break;
4903  case 10: strcpy_s(file, MAX_PATH, "Textures\\RTS\\f4b_BUMP.bmp"); break;
4904  case 11: strcpy_s(file, MAX_PATH, "Textures\\RTS\\f5a_BUMP.bmp"); break;
4905  case 12: strcpy_s(file, MAX_PATH, "Textures\\RTS\\f6a_BUMP.bmp"); break;
4906  case 13: strcpy_s(file, MAX_PATH, "Textures\\RTS\\f6b_BUMP.bmp"); break;
4907  case 14: strcpy_s(file, MAX_PATH, "Textures\\RTS\\f6c_BUMP.bmp"); break;
4908  case 15: strcpy_s(file, MAX_PATH, "Textures\\RTS\\f6d_BUMP.bmp"); break;
4909  case 16: strcpy_s(file, MAX_PATH, "Textures\\RTS\\f6e_BUMP.bmp"); break;
4910  case 17: strcpy_s(file, MAX_PATH, "Textures\\RTS\\f7a_BUMP.bmp"); break;
4911  case 18: strcpy_s(file, MAX_PATH, "Textures\\RTS\\f7b_BUMP.bmp"); break;
4912  case 19: strcpy_s(file, MAX_PATH, "Textures\\RTS\\f7c_BUMP.bmp"); break;
4913  case 20: strcpy_s(file, MAX_PATH, "Textures\\RTS\\f8a_BUMP.bmp"); break;
4914  case 21: strcpy_s(file, MAX_PATH, "Textures\\RTS\\f8b_BUMP.bmp"); break;
4915  case 22: strcpy_s(file, MAX_PATH, "Textures\\RTS\\f8c_BUMP.bmp"); break;
4916  case 23: strcpy_s(file, MAX_PATH, "Textures\\RTS\\f9a_BUMP.bmp"); break;
4917  case 24: strcpy_s(file, MAX_PATH, "Textures\\RTS\\f9b_BUMP.bmp"); break;
4918  case 25: strcpy_s(file, MAX_PATH, "Textures\\RTS\\f10a_BUMP.bmp"); break;
4919  case 26: strcpy_s(file, MAX_PATH, "Textures\\RTS\\f10b_BUMP.bmp"); break;
4920  case 27: strcpy_s(file, MAX_PATH, "Textures\\RTS\\f10c_BUMP.bmp"); break;
4921  case 28: strcpy_s(file, MAX_PATH, "Textures\\RTS\\f10d_BUMP.bmp"); break;
4922  case 29: strcpy_s(file, MAX_PATH, "Textures\\RTS\\f11a_BUMP.bmp"); break;
4923  case 30: strcpy_s(file, MAX_PATH, "Textures\\RTS\\f33_Exit-above_BUMP.bmp"); break;
4924  case 31: strcpy_s(file, MAX_PATH, "Textures\\RTS\\f12b_BUMP.bmp"); break;
4925  case 32: strcpy_s(file, MAX_PATH, "Textures\\RTS\\f33_Exit-above_BUMP.bmp"); break;
4926  case 33: strcpy_s(file, MAX_PATH, "Textures\\RTS\\f13b_BUMP.bmp"); break;
4927  //case 34: strcpy_s(file, MAX_PATH, "Textures\\RTS\\f14a_BUMP.bmp"); break;
4928  case 35: strcpy_s(file, MAX_PATH, "Textures\\RTS\\f14b_BUMP.bmp"); break;
4929  case 36: strcpy_s(file, MAX_PATH, "Textures\\RTS\\f15a_BUMP.bmp"); break;
4930  case 37: strcpy_s(file, MAX_PATH, "Textures\\RTS\\f15b_BUMP.bmp"); break;
4931  case 38: strcpy_s(file, MAX_PATH, "Textures\\RTS\\f15c_BUMP.bmp"); break;
4932  case 39: //strcpy_s(file, MAX_PATH, "Textures\\RTS\\f15d_BUMP.bmp"); break;
4933  g_bRoad = true;
4934  return 0.0f;
4935  case 40: strcpy_s(file, MAX_PATH, "Textures\\RTS\\f15e_BUMP.bmp"); break;
4936  //case 41: strcpy_s(file, MAX_PATH, "Textures\\RTS\\f33_Exit-aboveBUMP.bmp"); break;
4937  case 42: //strcpy_s(file, MAX_PATH, "Textures\\RTS\\f17_BUMP.bmp"); break;
4938  return 0.00020312817392f; // 144
4939  case 43: strcpy_s(file, MAX_PATH, "Textures\\RTS\\f18_BUMP.bmp"); break;
4940  case 44: strcpy_s(file, MAX_PATH, "Textures\\RTS\\f19_BUMP.bmp"); break;
4941  case 45: strcpy_s(file, MAX_PATH, "Textures\\RTS\\f20_BUMP.bmp"); break;
4942  case 46: strcpy_s(file, MAX_PATH, "Textures\\RTS\\f21_BUMP.bmp"); break;
4943  case 47: strcpy_s(file, MAX_PATH, "Textures\\RTS\\f22_BUMP.bmp"); break;
4944  case 48: strcpy_s(file, MAX_PATH, "Textures\\RTS\\f23_BUMP.bmp"); break;
4945  case 49: strcpy_s(file, MAX_PATH, "Textures\\RTS\\f24_BUMP.bmp"); break;
4946  case 50: //strcpy_s(file, MAX_PATH, "Textures\\RTS\\f25_BUMP.bmp"); break;
4947  g_bRoad = true;
4948  return 0.0f;
4949  case 51: strcpy_s(file, MAX_PATH, "Textures\\RTS\\f26_BUMP.bmp"); break;
4950  case 52: strcpy_s(file, MAX_PATH, "Textures\\RTS\\f27_BUMP.bmp"); break;
4951  case 53: strcpy_s(file, MAX_PATH, "Textures\\RTS\\f28_BUMP.bmp"); break;
4952  case 54: strcpy_s(file, MAX_PATH, "Textures\\RTS\\f29_BUMP.bmp"); break;
4953  case 55: strcpy_s(file, MAX_PATH, "Textures\\RTS\\f30_BUMP.bmp"); break;
4954  case 56: strcpy_s(file, MAX_PATH, "Textures\\RTS\\f15f_BUMP.bmp"); break;
4955  case 57: strcpy_s(file, MAX_PATH, "Textures\\RTS\\f15g_BUMP.bmp"); break;
4956  case 58: //strcpy_s(file, MAX_PATH, "Textures\\RTS\\f31_BUMP.bmp"); break;
4957  case 59: //strcpy_s(file, MAX_PATH, "Textures\\RTS\\f32_BUMP.bmp"); break;
4958  case 60: strcpy_s(file, MAX_PATH, "Textures\\RTS\\f33_BUMP.bmp"); break;
4959  case 61: strcpy_s(file, MAX_PATH, "Textures\\RTS\\f34_BUMP.bmp"); break;
4960  case 62: strcpy_s(file, MAX_PATH, "Textures\\RTS\\city2playerN_BUMP.bmp"); break;
4961  case 63: strcpy_s(file, MAX_PATH, "Textures\\RTS\\city2playerS_BUMP.bmp"); break;
4962  case 64: //strcpy_s(file, MAX_PATH, "Textures\\RTS\\f32_BUMP.bmp"); break;
4963  case 65: //strcpy_s(file, MAX_PATH, "Textures\\RTS\\f32_BUMP.bmp"); break;
4964  case 66: //strcpy_s(file, MAX_PATH, "Textures\\RTS\\f31_BUMP.bmp"); break;
4965  case 67: //strcpy_s(file, MAX_PATH, "Textures\\RTS\\f31_BUMP.bmp"); break;
4966  case 68: //strcpy_s(file, MAX_PATH, "Textures\\RTS\\f31_BUMP.bmp"); break;
4967  case 69: //strcpy_s(file, MAX_PATH, "Textures\\RTS\\f31_BUMP.bmp"); break;
4968  g_bRoad = true;
4969  return 0.0f;
4970  case 70: strcpy_s(file, MAX_PATH, "Textures\\RTS\\f8bpark_BUMP.bmp"); break;
4971  case 71: strcpy_s(file, MAX_PATH, "Textures\\RTS\\f9bpark_BUMP.bmp"); break;
4972  default:
4973  return 0.0f;
4974  }
4975  //strcpy_s(gameclass->bus->DebugString, MAX_PATH, file);
4976  int deoisbump;
4977  _sopen_s(&deoisbump, file, _O_RDONLY | O_BINARY, _SH_DENYWR, _S_IWRITE);
4978  if (deoisbump == -1)
4979  {
4980  sprintf_s(msg, sizeof msg, "Could not find bump file %i for type %i!", buildzone[gridarray[u][v].buildzoneOrdinal].rts[rts.u * 26 + rts.v].texture, gridarray[u][v].type);
4981  logger->Log(msg, Logger::Level::Fatal);
4982  }
4983  const unsigned long bpr = 256L; // VERIFIED WITH SPE greyscale 2039, 2039 has 1024 additional header
4984 
4985  const unsigned char rotation = buildzone[gridarray[u][v].buildzoneOrdinal].rts[rts.u * 26 + rts.v].rotation;
4986  VECTOR2SHORT rotbump = VECTOR2SHORT();
4987  // this is because the textures are upside down in Makeship
4988  if (rotation == 2 || rotation == 6)
4989  {
4990  rotbump.u = bump.u;
4991  rotbump.v = bump.v;
4992  }
4993  else if (rotation == 1 || rotation == 5)
4994  {
4995  rotbump.v = bump.u;
4996  rotbump.u = 255 - bump.v;
4997  }
4998  else if (rotation == 0 || rotation == 4)
4999  {
5000  rotbump.u = 255 - bump.u;
5001  rotbump.v = 255 - bump.v;
5002  }
5003  else if (rotation == 3 || rotation == 7)
5004  {
5005  rotbump.v = 255 - bump.u;
5006  rotbump.u = bump.v;
5007  }
5008  if (rotation > 3)
5009  rotbump.u = 255 - rotbump.u;
5010 
5011  unsigned char uch_temp;
5012  unsigned long k = 54L + 1024L + rotbump.u + (bpr - rotbump.v - 1L) * bpr;
5013  _lseek(deoisbump, k, SEEK_SET);
5014  _read(deoisbump, &uch_temp, 1);
5015  _close(deoisbump);
5016  //gameclass->bus->DebugFloat = (float)uch_temp;
5017  //gameclass->bus->Debug2Vec3.x = rotbump.u;
5018  //gameclass->bus->Debug2Vec3.y = rotbump.v;
5019 
5020  if (uch_temp == 128)
5021  g_bRoad = true;
5022 
5023  return (static_cast<float>(uch_temp) - 128.0f) * 0.00001269551087f; // 0.5" per increment
5024  }
5025 
5026  return 0.0f;
5027 }
5028 
5030 {
5031  logger->AddToCallStack("Viewscreen::Undock");
5032  if (dockprogress < 1.0f)
5033  {
5034  if (playerships[0].docked)
5035  {
5036  playerships[0].docked = false;
5037  logger->Log("Tried to undock but was not finished docking...");
5038  }
5039  }
5040  else
5041  {
5042  // Undocking
5043  if (playerships[0].docked)
5044  {
5045  playerships[0].docked = false;
5046 
5047  if (!playerships[0].simulator)
5048  {
5049  SClientPacket outpacket;
5050  outpacket.type = 2; // Docking change
5051  outpacket.f_x = playerships[0].portassigned;
5052  outpacket.f_y = 0.0f; // undocked
5053  outpacket.f_z = 0.0f; // NULL
5054  outpacket.f_w = 0.0f; // NULL
5055  gameclass->networking->SendToServer(&outpacket, sizeof(SClientPacket), true);
5056  }
5057 
5058  logger->Log("Undocked...");
5059 
5060  short DOCKRAND = SOUND_DOCKEVAC - SOUND_DOCKANNOUNCE1;
5061  for (short t = 0; t < DOCKRAND; t++)
5063  DOCKRAND = SOUND_CPOCEVAC - SOUND_CPOCANNOUNCE1;
5064  for (short t = 0; t < DOCKRAND; t++)
5069 
5070  Command command;
5071  command.name = "AuralAllMooringsCleared";
5072  command.delay = 3.0f;
5073  gameclass->bus->commandStream.emplace_back(command);
5074  }
5075  else
5076  {
5077  logger->Log("Tried to undock but was not not docked...");
5078  }
5079  }
5080 }
5081 
5082 // This one is only used by us
5083 float Viewscreen::CalculateAGLd(D3DXVECTOR3 terpos, double terprecisionx, double terprecisiony, double terprecisionz, double proposedx, double proposedy, double proposedz, D3DXVECTOR3 proposed, bool makeleveler)
5084 {
5085  logger->AddToCallStack("Viewscreen::CalculateAGLd");
5086  D3DXVECTOR3 negposition, tempcenter;
5087  tempcenter.x = -(float)(proposedx + terprecisionx);
5088  tempcenter.y = -(float)(proposedy + terprecisiony);
5089  tempcenter.z = -(float)(proposedz + terprecisionz);
5090 
5091  negposition = proposed; // temppos makes the new origin...
5092  D3DXVec3Normalize(&negposition, &negposition);
5093 
5094  tempcenter -= negposition; // unit vector of 1
5095 
5096  D3DXVECTOR3 temp0, temp1, temp2;
5097  float pu = -1.0f, pv = -1.0f, dist = 0.0f; // last if not overwritten
5098 
5099  D3DXVECTOR3 grid3131 = gridarray[31][31].position - terpos;
5100  D3DXVECTOR3 ins03131 = insidearray[31][31][0] - terpos;
5101  D3DXVECTOR3 ins13131 = insidearray[31][31][1] - terpos;
5102  D3DXVECTOR3 ins23131 = insidearray[31][31][2] - terpos;
5103  D3DXVECTOR3 grid3231 = gridarray[32][31].position - terpos;
5104  D3DXVECTOR3 ins13231 = insidearray[32][31][1] - terpos;
5105  D3DXVECTOR3 grid3132 = gridarray[31][32].position - terpos;
5106  D3DXVECTOR3 ins03132 = insidearray[31][32][0] - terpos;
5107  D3DXVECTOR3 grid3232 = gridarray[32][32].position - terpos;
5108 
5109  gameclass->bus->Debug2Vec3.x = 0.0f;
5110  gameclass->bus->Debug2Vec3.y = 0.0f;
5111 
5112 
5113  // Upper left zone
5114  if (D3DXIntersectTri(&grid3131, &ins03131, &ins13131, &tempcenter, &negposition, &pu, &pv, &dist))
5115  {
5116  temp0 = gridarray[31][31].position; temp1 = insidearray[31][31][0]; temp2 = insidearray[31][31][1];
5117  pu *= 0.5f;
5118  pv *= 0.5f;
5119  strcpy_s(area, 3, "1a");
5120  }
5121  else if (D3DXIntersectTri(&ins23131, &ins13131, &ins03131, &tempcenter, &negposition, &pu, &pv, &dist))
5122  {
5123  temp0 = insidearray[31][31][0]; temp1 = insidearray[31][31][2]; temp2 = insidearray[31][31][1];
5124  pu *= 0.5f;
5125  pv *= 0.5f;
5126  strcpy_s(area, 3, "1b");
5127  pu = 0.5f - pu;
5128  pv = 0.5f - pv;
5129  }
5130 
5131  // Upper right zone
5132  else if (D3DXIntersectTri(&ins03131, &grid3231, &ins23131, &tempcenter, &negposition, &pu, &pv, &dist))
5133  {
5134  temp0 = insidearray[31][31][0]; temp1 = gridarray[32][31].position; temp2 = insidearray[31][31][2];
5135  pu *= 0.5f;
5136  pv *= 0.5f;
5137  strcpy_s(area, 3, "2a");
5138  pu += 0.5f;
5139  }
5140  else if (D3DXIntersectTri(&ins13231, &ins23131, &grid3231, &tempcenter, &negposition, &pu, &pv, &dist))
5141  {
5142  temp0 = gridarray[32][31].position; temp1 = insidearray[32][31][1]; temp2 = insidearray[31][31][2];
5143  pu *= 0.5f;
5144  pv *= 0.5f;
5145  strcpy_s(area, 3, "2b");
5146  pu = 0.5f - pu;
5147  pv = 0.5f - pv;
5148  pu += 0.5f;
5149  }
5150 
5151  // Lower left zone
5152  else if (D3DXIntersectTri(&ins13131, &ins23131, &grid3132, &tempcenter, &negposition, &pu, &pv, &dist))
5153  {
5154  temp0 = insidearray[31][31][1]; temp1 = insidearray[31][31][2]; temp2 = gridarray[31][32].position;
5155  pu *= 0.5f;
5156  pv *= 0.5f;
5157  strcpy_s(area, 3, "3a");
5158  pv += 0.5f;
5159  }
5160  else if (D3DXIntersectTri(&ins03132, &grid3132, &ins23131, &tempcenter, &negposition, &pu, &pv, &dist))
5161  {
5162  temp0 = insidearray[31][31][2]; temp1 = insidearray[31][32][0]; temp2 = gridarray[31][32].position;
5163  pu *= 0.5f;
5164  pv *= 0.5f;
5165  strcpy_s(area, 3, "3b");
5166  pu = 0.5f - pu;
5167  pv = 0.5f - pv;
5168  pv += 0.5f;
5169  }
5170 
5171  // Lower right zone
5172  else if (D3DXIntersectTri(&ins23131, &ins13231, &ins03132, &tempcenter, &negposition, &pu, &pv, &dist))
5173  {
5174  temp0 = insidearray[31][31][2]; temp1 = insidearray[32][31][1]; temp2 = insidearray[31][32][0];
5175  pu *= 0.5f;
5176  pv *= 0.5f;
5177  strcpy_s(area, 3, "4a");
5178  pu += 0.5f;
5179  pv += 0.5f;
5180  }
5181  else if (D3DXIntersectTri(&grid3232, &ins03132, &ins13231, &tempcenter, &negposition, &pu, &pv, &dist))
5182  {
5183  temp0 = insidearray[32][31][1]; temp1 = gridarray[32][32].position; temp2 = insidearray[31][32][0];
5184  pu *= 0.5f;
5185  pv *= 0.5f;
5186  strcpy_s(area, 3, "4b");
5187  pu = 0.5f - pu;
5188  pv = 0.5f - pv;
5189  pu += 0.5f;
5190  pv += 0.5f;
5191  }
5192  else
5193  {
5195  sprintf_s(msg, sizeof msg, "*** CalculateAGLd() yielded no result, returning %.3f", dist - 1.0f);
5196  logger->Log(msg, Logger::Level::Warn);
5197  }
5198 
5199  if (makeleveler)
5200  {
5201  D3DXVECTOR3 side1, side2;
5202  D3DXVec3Subtract(&side1, &temp0, &temp1);
5203  D3DXVec3Subtract(&side2, &temp0, &temp2);
5204  D3DXVec3Cross(&temp0, &side1, &side2);
5205  D3DXVec3Normalize(&leveler, &temp0);
5206  }
5207 
5208  if (pu != -1.0f && pv != -1.0f)
5209  {
5210  gameclass->bus->assayProgressU = pu;
5211  gameclass->bus->assayProgressV = pv;
5212  gameclass->bus->Debug2Vec3.x = pu;
5213  gameclass->bus->Debug2Vec3.y = pv;
5214  }
5215 
5216  return dist - 1.0f; // makes it -1 because it started at 0
5217 }
5218 
5219 D3DXVECTOR3 Viewscreen::CalculatePlanar(short u, short v)
5220 {
5221  logger->AddToCallStack("Viewscreen::CalculatePlanar");
5222  D3DXVECTOR3 planar;
5223  if (u >= -2038 && u < 0 && v >= 0 && v < 2038) // point is over wp grid
5224  {
5225  planar.x = -2038.0f;
5226  planar.y = -2.0f * (float)(u + 1019); // Backwards
5227  planar.z = 2.0f * (float)(v - 1019);
5228  }
5229  else if (u >= 0 && u < 2038 && v >= 0 && v < 2038) // point is over pm grid
5230  {
5231  planar.x = 2.0f * (float)(u - 1019);
5232  planar.y = -2038.0f;
5233  planar.z = 2.0f * (float)(v - 1019);
5234  }
5235  else if (u >= 2038 && u < 4076 && v >= 0 && v < 2038) // point is over ep grid
5236  {
5237  planar.x = 2038.0f;
5238  planar.y = 2.0f * (float)(u - 3057);
5239  planar.z = 2.0f * (float)(v - 1019);
5240  }
5241  else if (u >= 4076 && u < 6114 && v >= 0 && v < 2038) // point is over dl grid
5242  {
5243  planar.x = -2.0f * (float)(u - 5095); // Backwards
5244  planar.y = 2038.0f;
5245  planar.z = 2.0f * (float)(v - 1019);
5246  }
5247  else if (u > 0 && u < 2038 && v >= -2038 && v <= 0) // point is over np grid (no left or top row)
5248  {
5249  planar.x = 2.0f * (float)(u - 1019);
5250  planar.y = -2.0f * (float)(v + 1019); // Backwards
5251  planar.z = -2038.0f;
5252  }
5253  else if (u >= 0 && u <= 2038 && v >= 2038 && v <= 4076) // point is over sp grid
5254  {
5255  planar.x = 2.0f * (float)(u - 1019);
5256  planar.y = 2.0f * (float)(v - 3057);
5257  planar.z = 2038.0f;
5258  }
5259  else
5260  {
5261  sprintf_s(msg, sizeof msg, "u%i v%i was not on any face...", u, v);
5262  logger->Log(msg, Logger::Level::Warn);
5263  planar.x = planar.y = planar.z = 0.0f;
5264  return planar;
5265  }
5266 
5267  D3DXVec3Normalize(&planar, &planar);
5268 
5269  // Ian has this formula, secant case intersection
5270 // D3DXVec3Scale(&planar, &planar, 1.1949187320431308145240431795878f);
5271 
5272  return planar;
5273 }
5274 
5275 void Viewscreen::TriggerBCLLightning(float distanceScalar, float intensityScalar) const
5276 {
5277  logger->AddToCallStack("Viewscreen::TriggerBCLLightning");
5278  if (!lightningbelow.inuse)
5279  {
5280  lightningbelow.inuse = true;
5281  lightningbelow.distance = 1.0f - distanceScalar; // now 0 is very close
5282  lightningbelow.intensity = intensityScalar;
5283  lightningbelow.timeleft = RandomFloat() * 2.0f;
5284  lightningbelow.trend = true;
5285  lightningbelow.texture = static_cast<short>(rand()) % 3;
5286 
5287  short u = static_cast<short>(sinf(RandomFloat() * D3DX_TAU) * 31.0f * lightningbelow.
5288  distance + 31.0f);
5289  if (u > 62)
5290  u = 62;
5291  else if (u < 0)
5292  u = 0;
5293  short v = static_cast<short>(cosf(RandomFloat() * D3DX_TAU) * 31.0f * lightningbelow.
5294  distance + 31.0f);
5295  if (v > 62)
5296  v = 62;
5297  else if (v < 0)
5298  v = 0;
5299 
5301  D3DXVECTOR3 cloudposnormal;
5302  D3DXVec3Normalize(&cloudposnormal, &gridarray[u][v].cloudpos);
5303  D3DXVECTOR3 offsetClouds = cloudposnormal * min(ptrWeather->GetCloudCeilingMslKm(), cloudTopsMslC);
5304  offsetClouds += gridarray[u][v].cloudpos;
5305 
5306  lightningbelow.cloudpos = -offsetClouds;
5307  }
5308 }
5309 
5310 void Viewscreen::LoadVehicleProfile(short t, bool forceCockpitTextures)
5311 {
5312  logger->AddToCallStack("Viewscreen::LoadVehicleProfile");
5313 
5314  int handle = -1;
5315  HRESULT hr;
5316 
5318  if (playerships[t].componentarray)
5319  {
5320  SAFE_DELETE(playerships[t].componentarray);
5321  playerships[t].components = 0;
5322  sprintf_s(msg, sizeof(msg), "playerships[%i].componentarray", t);
5324  }
5325 
5326  // rotating nose to the right 90° from what we see in the makeship? and pointing the nose away?
5327  D3DXMATRIX matrixTemp;
5328  D3DXMatrixIdentity(&playerships[t].matrixBase);
5329  D3DXMatrixRotationX(&matrixTemp, D3DX_HALFPI); // pitch
5330  D3DXMatrixMultiply(&playerships[t].matrixBase, &playerships[t].matrixBase, &matrixTemp);
5331 
5332  // ReSharper disable once CppDefaultCaseNotHandledInSwitchStatement
5333  switch (playerships[t].type)
5334  {
5335  case C98:
5336  _sopen_s(&handle, "meshes\\C-98 MuVER-construction.dix", _O_RDONLY | _O_BINARY | _O_SEQUENTIAL, _SH_DENYWR, _S_IWRITE);
5337  playerships[t].speed = 0.045f + RandomFloat() * 0.01f; // 4.5-5.5
5338  playerships[t].bound = 0.004647f;
5339  playerships[t].steerLimitRadian = D3DXToRadian(45.0f); // if we change this here we have to change it in ourcockpit.steerLimitRadian too
5340  playerships[t].tireCircumferenceKm = 0.0004065f * D3DX_TAU; // this is based on the radius in ourcockpit.tireRadiusKm
5341  playerships[t].VB = 8;
5342  // haha we were actually rotating it to the right! So we don't have to do that anymore
5343  D3DXMatrixRotationY(&matrixTemp, -D3DX_HALFPI); // now yaw, was roll
5344  D3DXMatrixMultiply(&playerships[t].matrixBase, &playerships[t].matrixBase, &matrixTemp);
5345  break;
5346  case DIHV:
5347  _sopen_s(&handle, "meshes\\dihv.dix", _O_RDONLY | _O_BINARY | _O_SEQUENTIAL, _SH_DENYWR, _S_IWRITE);
5348  playerships[t].speed = 0.045f + RandomFloat() * 0.01f; // 4.5-5.5
5349  playerships[t].bound = 0.337061f;
5350  playerships[t].steerLimitRadian = 0; // if we change this here we have to change it in ourcockpit.steerLimitRadian too
5351  playerships[t].tireCircumferenceKm = 0; // this is based on the radius in ourcockpit.tireRadiusKm
5352  playerships[t].VB = 7;
5353  // haha we were actually rotating it to the right! So we don't have to do that anymore
5354  D3DXMatrixRotationY(&matrixTemp, -D3DX_HALFPI); // now yaw, was roll
5355  D3DXMatrixMultiply(&playerships[t].matrixBase, &playerships[t].matrixBase, &matrixTemp);
5356  break;
5357  case E10:
5358  _sopen_s(&handle, "meshes\\e-10.dix", _O_RDONLY | _O_BINARY | _O_SEQUENTIAL, _SH_DENYWR, _S_IWRITE);
5359  playerships[t].speed = 0.045f + RandomFloat() * 0.01f; // 4.5-5.5
5360  playerships[t].bound = 0.034726f;
5361  playerships[t].steerLimitRadian = 0; // if we change this here we have to change it in ourcockpit.steerLimitRadian too
5362  playerships[t].tireCircumferenceKm = 0; // this is based on the radius in ourcockpit.tireRadiusKm
5363  playerships[t].VB = 3;
5364  // haha we were actually rotating it to the right! So we don't have to do that anymore
5365  D3DXMatrixRotationY(&matrixTemp, -D3DX_HALFPI); // now yaw, was roll
5366  D3DXMatrixMultiply(&playerships[t].matrixBase, &playerships[t].matrixBase, &matrixTemp);
5367  break;
5368  case P13:
5369  _sopen_s(&handle, "meshes\\p-13.dix", _O_RDONLY | _O_BINARY | _O_SEQUENTIAL, _SH_DENYWR, _S_IWRITE);
5370  playerships[t].speed = 0.045f + RandomFloat() * 0.01f; // 4.5-5.5
5371  playerships[t].bound = 0.018931f;
5372  playerships[t].steerLimitRadian = 0; // if we change this here we have to change it in ourcockpit.steerLimitRadian too
5373  playerships[t].tireCircumferenceKm = 0; // this is based on the radius in ourcockpit.tireRadiusKm
5374  playerships[t].VB = 9;
5375  // haha we were actually rotating it to the right! So we don't have to do that anymore
5376  D3DXMatrixRotationY(&matrixTemp, -D3DX_HALFPI); // now yaw, was roll
5377  D3DXMatrixMultiply(&playerships[t].matrixBase, &playerships[t].matrixBase, &matrixTemp);
5378  break;
5379  case A4:
5380  _sopen_s(&handle, "meshes\\T-8 Wanderer.dix", _O_RDONLY | _O_BINARY | _O_SEQUENTIAL, _SH_DENYWR, _S_IWRITE);
5381  playerships[t].speed = 0.045f + RandomFloat() * 0.01f; // 4.5-5.5
5382  playerships[t].bound = 0.032570f;
5383  playerships[t].steerLimitRadian = 0; // if we change this here we have to change it in ourcockpit.steerLimitRadian too
5384  playerships[t].tireCircumferenceKm = 0; // this is based on the radius in ourcockpit.tireRadiusKm
5385  playerships[t].VB = 6;
5386  // haha we were actually rotating it to the right! So we don't have to do that anymore
5387  D3DXMatrixRotationY(&matrixTemp, -D3DX_HALFPI); // now yaw, was roll
5388  D3DXMatrixMultiply(&playerships[t].matrixBase, &playerships[t].matrixBase, &matrixTemp);
5389  break;
5390  case C2:
5391  _sopen_s(&handle, "meshes\\C-2 Dasher.dix", _O_RDONLY | _O_BINARY | _O_SEQUENTIAL, _SH_DENYWR, _S_IWRITE);
5392  playerships[t].speed = 0.045f + RandomFloat() * 0.01f; // 4.5-5.5
5393  playerships[t].bound = 0.003726f;
5394  playerships[t].steerLimitRadian = D3DXToRadian(45.0f); // if we change this here we have to change it in ourcockpit.steerLimitRadian too
5395  playerships[t].tireCircumferenceKm = 0.0002155f * D3DX_TAU; // this is based on the radius in ourcockpit.tireRadiusKm
5396  playerships[t].VB = 10;
5397  // haha we were actually rotating it to the right! So we don't have to do that anymore
5398  D3DXMatrixRotationY(&matrixTemp, -D3DX_HALFPI); // now yaw, was roll
5399  D3DXMatrixMultiply(&playerships[t].matrixBase, &playerships[t].matrixBase, &matrixTemp);
5400  break;
5401  case T120:
5402  _sopen_s(&handle, "meshes\\T-120 Steerhead-stock.dix", _O_RDONLY | _O_BINARY | _O_SEQUENTIAL, _SH_DENYWR, _S_IWRITE);
5403  playerships[t].speed = 0.045f + RandomFloat() * 0.01f; // 4.5-5.5
5404  playerships[t].bound = 0.005191f;
5405  playerships[t].steerLimitRadian = D3DXToRadian(45.0f); // if we change this here we have to change it in ourcockpit.steerLimitRadian too
5406  playerships[t].tireCircumferenceKm = 0.0004065f * D3DX_TAU; // this is based on the radius in ourcockpit.tireRadiusKm
5407  playerships[t].VB = 11;
5408  // haha we were actually rotating it to the right! So we don't have to do that anymore
5409  D3DXMatrixRotationY(&matrixTemp, -D3DX_HALFPI); // now yaw, was roll
5410  D3DXMatrixMultiply(&playerships[t].matrixBase, &playerships[t].matrixBase, &matrixTemp);
5411  break;
5412  case E11:
5413  _sopen_s(&handle, "meshes\\E-11.dix", _O_RDONLY | _O_BINARY | _O_SEQUENTIAL, _SH_DENYWR, _S_IWRITE);
5414  playerships[t].speed = 0.045f + RandomFloat() * 0.01f; // 4.5-5.5
5415  playerships[t].bound = 0.036348f;
5416  playerships[t].steerLimitRadian = 0; // if we change this here we have to change it in ourcockpit.steerLimitRadian too
5417  playerships[t].tireCircumferenceKm = 0; // this is based on the radius in ourcockpit.tireRadiusKm
5418  playerships[t].VB = 12;
5419  // so north oriented on the screen needs this rotation
5420  D3DXMatrixRotationY(&matrixTemp, -D3DX_PI); // now yaw, was roll
5421  D3DXMatrixMultiply(&playerships[t].matrixBase, &playerships[t].matrixBase, &matrixTemp);
5422  break;
5423  case PODS_PAX:
5424  _sopen_s(&handle, "meshes\\pax-exterior-hex.dix", _O_RDONLY | _O_BINARY | _O_SEQUENTIAL, _SH_DENYWR, _S_IWRITE);
5425  playerships[t].speed = 0.0f;
5426  playerships[t].bound = 0.003656f;
5427  playerships[t].steerLimitRadian = 0; // if we change this here we have to change it in ourcockpit.steerLimitRadian too
5428  playerships[t].tireCircumferenceKm = 0; // this is based on the radius in ourcockpit.tireRadiusKm
5429  playerships[t].VB = 23;
5430  // 180 degrees backwards
5431  D3DXMatrixRotationY(&matrixTemp, D3DX_PI); // now yaw, was roll
5432  D3DXMatrixMultiply(&playerships[t].matrixBase, &playerships[t].matrixBase, &matrixTemp);
5433  break;
5434  case PODS_CNST:
5435  _sopen_s(&handle, "meshes\\cnst-exterior-hex.dix", _O_RDONLY | _O_BINARY | _O_SEQUENTIAL, _SH_DENYWR, _S_IWRITE);
5436  playerships[t].speed = 0.0f;
5437  playerships[t].bound = 0.003656f;
5438  playerships[t].steerLimitRadian = 0; // if we change this here we have to change it in ourcockpit.steerLimitRadian too
5439  playerships[t].tireCircumferenceKm = 0; // this is based on the radius in ourcockpit.tireRadiusKm
5440  playerships[t].VB = 24;
5441  // 180 degrees backwards
5442  D3DXMatrixRotationY(&matrixTemp, D3DX_PI); // now yaw, was roll
5443  D3DXMatrixMultiply(&playerships[t].matrixBase, &playerships[t].matrixBase, &matrixTemp);
5444  break;
5445  case PODS_CARGOAFT:
5446  _sopen_s(&handle, "meshes\\cargo-standard.dix", _O_RDONLY | _O_BINARY | _O_SEQUENTIAL, _SH_DENYWR, _S_IWRITE);
5447  playerships[t].speed = 0.0f;
5448  playerships[t].bound = 0.003656f;
5449  playerships[t].steerLimitRadian = 0; // if we change this here we have to change it in ourcockpit.steerLimitRadian too
5450  playerships[t].tireCircumferenceKm = 0; // this is based on the radius in ourcockpit.tireRadiusKm
5451  playerships[t].VB = 4;
5452  // 180 degrees backwards
5453  D3DXMatrixRotationY(&matrixTemp, D3DX_PI); // now yaw, was roll
5454  D3DXMatrixMultiply(&playerships[t].matrixBase, &playerships[t].matrixBase, &matrixTemp);
5455  break;
5456  case PODS_FUEL:
5457  _sopen_s(&handle, "meshes\\fuel-standard-ext.dix", _O_RDONLY | _O_BINARY | _O_SEQUENTIAL, _SH_DENYWR, _S_IWRITE);
5458  playerships[t].speed = 0.0f;
5459  playerships[t].bound = 0.003656f;
5460  playerships[t].steerLimitRadian = 0; // if we change this here we have to change it in ourcockpit.steerLimitRadian too
5461  playerships[t].tireCircumferenceKm = 0; // this is based on the radius in ourcockpit.tireRadiusKm
5462  playerships[t].VB = 18;
5463  // 180 degrees backwards
5464  D3DXMatrixRotationY(&matrixTemp, D3DX_PI); // now yaw, was roll
5465  D3DXMatrixMultiply(&playerships[t].matrixBase, &playerships[t].matrixBase, &matrixTemp);
5466  break;
5467  case PODS_CARGOTOP:
5468  _sopen_s(&handle, "meshes\\cargo-toploader.dix", _O_RDONLY | _O_BINARY | _O_SEQUENTIAL, _SH_DENYWR, _S_IWRITE);
5469  playerships[t].speed = 0.0f;
5470  playerships[t].bound = 0.003656f;
5471  playerships[t].steerLimitRadian = 0; // if we change this here we have to change it in ourcockpit.steerLimitRadian too
5472  playerships[t].tireCircumferenceKm = 0; // this is based on the radius in ourcockpit.tireRadiusKm
5473  playerships[t].VB = 20;
5474  // 180 degrees backwards
5475  D3DXMatrixRotationY(&matrixTemp, D3DX_PI); // now yaw, was roll
5476  D3DXMatrixMultiply(&playerships[t].matrixBase, &playerships[t].matrixBase, &matrixTemp);
5477  break;
5478  case PODS_MUNITIONS:
5479  _sopen_s(&handle, "meshes\\munitions-standard-ext.dix", _O_RDONLY | _O_BINARY | _O_SEQUENTIAL, _SH_DENYWR, _S_IWRITE);
5480  playerships[t].speed = 0.0f;
5481  playerships[t].bound = 0.003656f;
5482  playerships[t].steerLimitRadian = 0; // if we change this here we have to change it in ourcockpit.steerLimitRadian too
5483  playerships[t].tireCircumferenceKm = 0; // this is based on the radius in ourcockpit.tireRadiusKm
5484  playerships[t].VB = 21;
5485  // 180 degrees backwards
5486  D3DXMatrixRotationY(&matrixTemp, D3DX_PI); // now yaw, was roll
5487  D3DXMatrixMultiply(&playerships[t].matrixBase, &playerships[t].matrixBase, &matrixTemp);
5488  break;
5489  case Apartment:
5490  case SimBay:
5491  case ControlTower:
5492  {
5493  // load animation ... we used to have a female1.ani but it was terrible
5494  int anihandle = -1;
5495  _sopen_s(&anihandle, "meshes\\Animations\\MALE1.ani", _O_RDONLY | _O_BINARY | _O_SEQUENTIAL, _SH_DENYWR, _S_IWRITE);
5496  if (anihandle == -1)
5497  {
5498  sprintf_s(msg, sizeof(msg), "InitApp() failed to load ANI for type %i!", playerships[t].type);
5499  logger->Log(msg, Logger::Level::Warn);
5500  }
5501  _read(anihandle, aniarray, sizeof(Sani) * MAX_ANI * MAX_STEPS);
5502  _close(anihandle);
5503  break;
5504  }
5505  case C2A:
5506  _sopen_s(&handle, "meshes\\C-2A Dasher.dix", _O_RDONLY | _O_BINARY | _O_SEQUENTIAL, _SH_DENYWR, _S_IWRITE);
5507  playerships[t].speed = 0.045f + RandomFloat() * 0.01f; // 4.5-5.5
5508  playerships[t].bound = 0.002675f;
5509  playerships[t].steerLimitRadian = D3DXToRadian(45.0f); // if we change this here we have to change it in ourcockpit.steerLimitRadian too
5510  playerships[t].tireCircumferenceKm = 0.001012f * D3DX_TAU; // this is based on the radius in ourcockpit.tireRadiusKm
5511  playerships[t].VB = 14;
5512  // so north oriented on the screen needs this rotation
5513  D3DXMatrixRotationY(&matrixTemp, -D3DX_PI); // now yaw, was roll
5514  D3DXMatrixMultiply(&playerships[t].matrixBase, &playerships[t].matrixBase, &matrixTemp);
5515  break;
5516  case T27: // Mammoth
5517  _sopen_s(&handle, "meshes\\T-27 Mammoth.dix", _O_RDONLY | _O_BINARY | _O_SEQUENTIAL, _SH_DENYWR, _S_IWRITE);
5518  playerships[t].speed = 0.045f + RandomFloat() * 0.01f; // 4.5-5.5
5519  playerships[t].bound = 0.030989f;
5520  playerships[t].steerLimitRadian = D3DXToRadian(45.0f); // if we change this here we have to change it in ourcockpit.steerLimitRadian too
5521  playerships[t].tireCircumferenceKm = 0.001619f * D3DX_TAU; // this is based on the radius in ourcockpit.tireRadiusKm
5522  playerships[t].VB = 25;
5523  // so north oriented on the screen needs this rotation
5524  D3DXMatrixRotationY(&matrixTemp, -D3DX_PI); // now yaw, was roll
5525  D3DXMatrixMultiply(&playerships[t].matrixBase, &playerships[t].matrixBase, &matrixTemp);
5526  break;
5527  case BeishtKione:
5528  _sopen_s(&handle, "meshes\\BeishtKione.dix", _O_RDONLY | _O_BINARY | _O_SEQUENTIAL, _SH_DENYWR, _S_IWRITE);
5529  playerships[t].speed = 0.045f + RandomFloat() * 0.01f; // 4.5-5.5
5530  playerships[t].bound = 0.014789f;
5531  playerships[t].steerLimitRadian = 0; // if we change this here we have to change it in ourcockpit.steerLimitRadian too
5532  playerships[t].tireCircumferenceKm = 0; // this is based on the radius in ourcockpit.tireRadiusKm
5533  playerships[t].VB = 17;
5534  // so north oriented on the screen needs this rotation
5535  D3DXMatrixRotationY(&matrixTemp, -D3DX_PI); // now yaw, was roll
5536  D3DXMatrixMultiply(&playerships[t].matrixBase, &playerships[t].matrixBase, &matrixTemp);
5537  break;
5538  case W6Manx:
5539  _sopen_s(&handle, "meshes\\manx-hex.dix", _O_RDONLY | _O_BINARY | _O_SEQUENTIAL, _SH_DENYWR, _S_IWRITE);
5540  playerships[t].speed = 0.045f + RandomFloat() * 0.01f; // 4.5-5.5
5541  playerships[t].bound = 0.037208f;
5542  playerships[t].steerLimitRadian = 1.22173f; // if we change this here we have to change it in ourcockpit.steerLimitRadian too
5543  playerships[t].tireCircumferenceKm = 0.00069f * D3DX_TAU; // this is based on the radius in ourcockpit.tireRadiusKm
5544  playerships[t].VB = 16;
5545  // so north oriented on the screen needs this rotation
5546  D3DXMatrixRotationY(&matrixTemp, -D3DX_PI); // now yaw, was roll
5547  D3DXMatrixMultiply(&playerships[t].matrixBase, &playerships[t].matrixBase, &matrixTemp);
5548  break;
5549  case T19:
5550  _sopen_s(&handle, "meshes\\T-19 Stratomaster.dix", _O_RDONLY | _O_BINARY | _O_SEQUENTIAL, _SH_DENYWR, _S_IWRITE);
5551  playerships[t].speed = 0.045f + RandomFloat() * 0.01f; // 4.5-5.5
5552  playerships[t].bound = 0.025446f;
5553  playerships[t].steerLimitRadian = 1.22173f; // if we change this here we have to change it in ourcockpit.steerLimitRadian too
5554  playerships[t].tireCircumferenceKm = 0.000406f * D3DX_TAU; // this is based on the radius in ourcockpit.tireRadiusKm
5555  playerships[t].VB = 19;
5556  // so north oriented on the screen needs this rotation
5557  D3DXMatrixRotationY(&matrixTemp, -D3DX_PI); // now yaw, was roll
5558  D3DXMatrixMultiply(&playerships[t].matrixBase, &playerships[t].matrixBase, &matrixTemp);
5559  break;
5560  case FloatingMan:
5561  _sopen_s(&handle, "meshes\\Holidays\\Spacesuit-Morholt-posed.dix", _O_RDONLY | _O_BINARY | _O_SEQUENTIAL, _SH_DENYWR, _S_IWRITE);
5562  playerships[t].speed = 0.045f + RandomFloat() * 0.01f; // 4.5-5.5
5563  playerships[t].bound = 0.001f;
5564  playerships[t].steerLimitRadian = 0; // if we change this here we have to change it in ourcockpit.steerLimitRadian too
5565  playerships[t].tireCircumferenceKm = 0; // this is based on the radius in ourcockpit.tireRadiusKm
5566  playerships[t].VB = 22;
5567  // so north oriented on the screen needs this rotation
5568  D3DXMatrixRotationY(&matrixTemp, -D3DX_PI); // now yaw, was roll
5569  D3DXMatrixMultiply(&playerships[t].matrixBase, &playerships[t].matrixBase, &matrixTemp);
5570  break;
5571  case T121:
5572  _sopen_s(&handle, "meshes\\2007 T-120 EXT.dix", _O_RDONLY | _O_BINARY | _O_SEQUENTIAL, _SH_DENYWR, _S_IWRITE);
5573  playerships[t].speed = 0.045f + RandomFloat() * 0.01f; // 4.5-5.5
5574  playerships[t].bound = 0.005864f;
5575  playerships[t].steerLimitRadian = D3DXToRadian(45.0f); // if we change this here we have to change it in ourcockpit.steerLimitRadian too
5576  playerships[t].tireCircumferenceKm = 0.0003555f * D3DX_TAU; // this is based on the radius in ourcockpit.tireRadiusKm
5577  playerships[t].VB = 15;
5578  // haha we were actually rotating it to the right! So we don't have to do that anymore
5579  D3DXMatrixRotationY(&matrixTemp, -D3DX_HALFPI); // now yaw, was roll
5580  D3DXMatrixMultiply(&playerships[t].matrixBase, &playerships[t].matrixBase, &matrixTemp);
5581  break;
5582 
5583  }
5584 
5585  if (handle == -1)
5586  {
5587  if (playerships[t].type != VehicleType::Apartment &&
5588  playerships[t].type != VehicleType::SimBay &&
5589  playerships[t].type != VehicleType::ControlTower)
5590  {
5591  sprintf_s(msg, sizeof(msg), "InitApp() failed to load DIX for type %i!", playerships[t].type);
5592  logger->Log(msg, Logger::Level::Fatal);
5593  }
5594  }
5595  else
5596  {
5597  _lseek(handle, 0, SEEK_SET);
5598  _read(handle, &playerships[t].components, 2);
5599 
5600  float version;
5601  _read(handle, &version, 4);
5602 
5603  sprintf_s(msg, sizeof msg, "playerships[%i].componentarray", t);
5604  if (playerships[t].componentarray)
5605  {
5606  SAFE_DELETE(playerships[t].componentarray);
5608  }
5610  if (playerships[t].componentarray == nullptr)
5611  {
5612  sprintf_s(msg, sizeof(msg), "LoadVehicleProfile() Failed to initialize %i component(s) for slot %i, type %i", playerships[t].components, t, playerships[t].type);
5613  logger->Log(msg, Logger::Level::Error);
5614  }
5615  else
5616  {
5617  gameclass->AddTrackedResource(msg); // managed, memory only
5618 
5619  sprintf_s(msg, sizeof(msg), "LoadVehicleProfile() Initialized %i component(s) for slot %i, type %i", playerships[t].components, t, playerships[t].type);
5620  logger->Log(msg);
5621  }
5622 
5623 
5624  short i_temp;
5625  for (short s = 0; s < playerships[t].components; s++)
5626  {
5627  _lseek(handle, (long)s * 100L + 99L, SEEK_SET); // To 0
5628  _read(handle, &i_temp, 2); // 0
5629  playerships[t].componentarray[s].startvertex = (UINT)i_temp;
5630  _read(handle, &i_temp, 2); // 2
5631  playerships[t].componentarray[s].primitives = (UINT)i_temp;
5632  _read(handle, &playerships[t].componentarray[s].nominalxyz, 12); // 4
5633  _read(handle, &playerships[t].componentarray[s].nominalypr, 12); // 16
5634  _read(handle, &playerships[t].componentarray[s].boundsphere, 4); // 28
5635  _read(handle, &playerships[t].componentarray[s].extendby, 12); // 32
5636  _read(handle, &playerships[t].componentarray[s].texture, 2); // 44
5637  if (playerships[t].componentarray[s].texture >= shiptextureC)
5638  {
5639  sprintf_s(msg, sizeof(msg), "Type %i Component %i Texture %i out-of-bounds", t, s, playerships[t].componentarray[s].texture);
5640  logger->Log(msg, Logger::Level::Warn);
5641  }
5642  _read(handle, &playerships[t].componentarray[s].nominalCG, 12); // 46
5643  _read(handle, &playerships[t].componentarray[s].type, 1); // 58
5644  _read(handle, &playerships[t].componentarray[s].speedExtend, 4); // 59
5645  _read(handle, &playerships[t].componentarray[s].hingeaxis, 12); // 63
5646  _read(handle, &playerships[t].componentarray[s].hingeCG, 12); // 75
5647  _read(handle, &playerships[t].componentarray[s].hingeextent, 4); // 87
5648  _read(handle, &playerships[t].componentarray[s].attachto, 2); // 91
5649 
5650  if (version == 2.44f)
5651  {
5652  _read(handle, &playerships[t].componentarray[s].useLightMap, 1); // 93
5653  _read(handle, &playerships[t].componentarray[s].speedRetract, 4); // 59
5654  }
5655  else
5656  {
5658  playerships[t].componentarray[s].useLightMap = true;
5659  }
5660 
5661  // Dynamic
5662  playerships[t].componentarray[s].extended = 0.0f; // these are initialized down below like ~6857
5663  }
5664  _close(handle);
5665  }
5666 
5667  sprintf_s(msg, sizeof(msg), "LoadVehicleProfile() finished component list");
5668  logger->Log(msg);
5669 
5670  if (t == 0)
5671  {
5672  sprintf_s(msg, sizeof(msg), "LoadVehicleProfile() slot %i is ours, type %i", t, playerships[t].type);
5673  logger->Log(msg);
5674 
5675  gameclass->bus->flapSettingTE = 0;
5676  ourcockpit.flapSettings.clear();
5677 
5678  g_bStrapon = true; // forced to stay in seat
5679 
5681 
5682  // this is going to have to be rethought, if you get in someone's vehicle that is aready powered up or from elevator
5683  // to subway it should be on already
5684  sprintf_s(msg, sizeof(msg), "LoadVehicleProfile() texturelib: %i, logolight %i", ourcockpit.texturelib, playerships[0].logolight);
5685  logger->Log(msg);
5686  if (playerships[0].type != VehicleType::Apartment &&
5687  playerships[0].type != VehicleType::SimBay &&
5688  playerships[0].type != VehicleType::ControlTower)
5689  {
5690  if (playerships[0].logolight)
5691  {
5692  ourcockpit.startcycle = 2;
5693  ourcockpit.startupextend = 1.0f;
5694  ourcockpit.power = 1.0f;
5695 
5697  Command command;
5698  command.name = "AuralScannerSync";
5699  command.delay = 2.0f;
5700  gameclass->bus->commandStream.emplace_back(command);
5701  }
5702  else
5703  {
5704  ourcockpit.startcycle = 0;
5705  ourcockpit.startupextend = 0.0f;
5706  ourcockpit.power = 0.0f;
5707  }
5708  targetLeftright = 0.0f; targetUpdown = -D3DXToRadian(10.0f); rolltilt = 0.0f;
5709  }
5710  else // interior lights are always on
5711  {
5712  playerships[0].logolight = false; // turn car off
5713  ourcockpit.power = 1.0f;
5714  playerships[0].headlight = false; // probably shouldn't be done like this
5715  targetLeftright = 0.0f; targetUpdown = 0.0f; rolltilt = 0.0f;
5716  }
5717 
5718 
5720  // ReSharper disable once CppExpressionWithoutSideEffects
5721  gameclass->TurnOffDOR();
5722  // ReSharper disable once CppExpressionWithoutSideEffects
5723  gameclass->TurnOffTVM();
5724 
5725  gameclass->bus->AFCS.CurrentLateralMode = Bus::Afcs::LateralModes::LateralMode_Off;
5726  gameclass->bus->AFCS.CurrentVerticalMode = Bus::Afcs::VerticalModes::VerticalMode_Off;
5727 
5730  ourcockpit.aileronAreaMod = 0.0f;
5731  ourcockpit.elevatorAreaMod = 0.0f;
5734  ourcockpit.scanDisplayVesselLimit = 9; // plus waypoint
5735  ourcockpit.Vne = 0.0f;
5736  ourcockpit.h9RudderSqFt = 0.0f; // rudder area
5737  ourcockpit.h6ElevatorSqFt = 0.0f; // elevator area
5738  ourcockpit.d16HTailWithElevatorSqFt = 0.0f; // hstab area
5739  ourcockpit.d17VTailWithRudderSqFt = 0.0f; // vstab area
5740  ourcockpit.h12 = 0.0f; // aileron area (one side)
5744  ourcockpit.b12WingRollArmM = 0.0f; // wing roll arm
5745  ourcockpit.b15WingPitchArmM = 0.0f; // wing pitch arm
5746  ourcockpit.c9WingYawArmM = 0.0f; // wing yaw arm
5747  ourcockpit.i48CriticalEngineYawArmM = 0.0f; // critical engine yaw arm (m)
5748  ourcockpit.l48AverageEnginePitchArmM = 0.0f; // critical engine pitch arm (m)
5749  ourcockpit.Vs1 = 0.0f;
5750  ourcockpit.Vs2 = 0.0f; // for thrust aug top speed
5751  ourcockpit.VcMSL = 0.0f;
5752  ourcockpit.Vr = FLT_MAX;
5753  ourcockpit.wingspanM = 0.0f;
5754  ourcockpit.rcsYParmM = 0.0f;
5755  ourcockpit.tireRadiusKm = 0.0f; // if we override this here we have to change it in playerships[t].tireCircumferenceKm
5757  ourcockpit.projecttexture = -1; // not supported yet
5758  ourcockpit.speedLimiterKph = 0.0f;
5760  ourcockpit.sonicBooms = 0;
5762 
5763  handle = -1;
5764  switch (playerships[0].type)
5765  {
5766  case C98:
5767  {
5768  _sopen_s(&handle, "meshes\\MuVERcockpit-construction.dix", _O_RDONLY | _O_BINARY | _O_SEQUENTIAL, _SH_DENYWR, _S_IWRITE);
5769  ourcockpit.headlight.x = 0.0f;
5770  ourcockpit.headlight.y = -0.00026364f; // down
5771  ourcockpit.headlight.z = 0.0167f; // fwd, at the nose because the point between the lights is inside the cockpit
5772  ourcockpit.uptranslimit = 0.0f;
5773  ourcockpit.dntranslimit = 0.0f;
5774  ourcockpit.lrtranslimit = 0.0f; // at max gross
5775  ourcockpit.fwdthrustlimit = 0.024f; // 140 hp?
5776  ourcockpit.spoolTime = 0.0f; // seconds
5777  ourcockpit.revthrustlimit = 0.0f; // unused
5778  ourcockpit.strutabsorb = 0.003f * 5.0f; // meter/s
5779  ourcockpit.gndvehicle = true;
5780  ourcockpit.spaceCapable = false;
5781  ourcockpit.wheeled = true;
5782  ourcockpit.tires = 4;
5783  ourcockpit.steerTires = 2;
5784  ourcockpit.noseWheelToCgKm = 0.0011175f;
5785  ourcockpit.steerLimitRadian = D3DXToRadian(45.0f); // if we change this here we have to change it in playerships[t].steerLimitRadian too
5786  ourcockpit.tireRadiusKm = 0.0004065f; // 0.000813f diameter or 32" if we change this here we have to change it in playerships[t].tireCircumferenceKm
5787  ourcockpit.clutchtime = 0.375f;
5788  ourcockpit.fwdgears = 5;
5789  // from F-150
5790  ourcockpit.ratios[0] = -0.4310344827586206896551724137931f;
5791  ourcockpit.ratios[1] = 0.25641025641025641025641025641026f; //.16
5792  ourcockpit.ratios[2] = 0.44444444444444444444444444444444f;//0.32f;
5793  ourcockpit.ratios[3] = 0.67114093959731543624161073825503f;
5794  ourcockpit.ratios[4] = 1.0f;
5795  ourcockpit.ratios[5] = 1.25f;
5796  // differential?
5797  ourcockpit.ratios[0] *= 2.0f;
5798  ourcockpit.ratios[1] *= 2.0f;
5799  ourcockpit.ratios[2] *= 2.0f;
5800  ourcockpit.ratios[3] *= 2.0f;
5801  ourcockpit.ratios[4] *= 2.0f;
5802  ourcockpit.ratios[5] *= 2.0f;
5803 
5805  ourcockpit.nextgen = false;
5806  ourcockpit.bays = 0;
5807  ourcockpit.engines = 1;
5808  ourcockpit.emptyWeightLbs = 5376.520f;
5809  ourcockpit.maxGrossLbs = 8016.800f;
5812  ourcockpit.ffmax = 0.003575f * 1.5f; // gndvehicles are in lbs per second
5813  ourcockpit.ffidle = ourcockpit.ffmax * 0.1f; // 52 lbs/hr
5814  ourcockpit.fuelmax = 80.0f;
5815  ourcockpit.cockpitArmKm.x = -0.0002539102f; // offset of center of cockpit
5816  ourcockpit.cockpitArmKm.y = 0.00040625634f;
5817  ourcockpit.cockpitArmKm.z = 0.0006093845f;
5818  ourcockpit.scanDisplayVesselLimit = 19; // plus waypt
5819  ourcockpit.exteriorInsulationHeatTransferCoefficient = 67.4f; // Intermediate British Steels, 1933 CS 81: 0.1% C, 0.34% Mn
5820 
5821  // Determined from new Intertial Moment routine
5822  ourcockpit.momentp = 13928.78125f / ourcockpit.emptyWeightLbs;//2.59611f;
5823  ourcockpit.momentr = 5015.320801f / ourcockpit.emptyWeightLbs;//0.934778f;
5824  ourcockpit.momenty = 18027.724609f / ourcockpit.emptyWeightLbs;//3.360088f; // at 60mph 96kmh 16mpg 8ppg
5825  ourcockpit.strutsrettoCG = 0.000508f; // so the bottom most polygon Z ... negated
5826  ourcockpit.strutlength = 0.0f;
5827  ourcockpit.rooftoCG = 0.001625f; // verified
5828 
5829  // All of these must go through the spreadsheet
5830  ourcockpit.f28 = 0.116172648f; // side drag coefficient
5831  ourcockpit.f20FrontBackDragCoeff = 0.056952f; // front/rear drag coefficient
5832  ourcockpit.f25 = 0.0f; // landing gear extended adjustment
5833  ourcockpit.f27 = 0.146740f; // top/bottom drag coefficient
5834  ourcockpit.d65wasd61 = 0.13600661f; // roll drag Cx
5835  ourcockpit.e65wase61 = 3.279168f; // roll drag arm
5836  ourcockpit.i66wasi62 = 0.0f; // ft² at m asym pitch body
5837  ourcockpit.k66wask62 = 0.0f; // ft² at m asym pitch htail
5838  ourcockpit.i65wasi61 = 0.0f; // ft² at m asym yaw body
5839  ourcockpit.k65wask61 = 0.0f; // ft² at m asym yaw vtail
5840  }
5841  break;
5842  case E10:
5843  {
5844  _sopen_s(&handle, "meshes\\e10cockpit1.dix", _O_RDONLY | _O_BINARY | _O_SEQUENTIAL, _SH_DENYWR, _S_IWRITE);
5845  ourcockpit.headlight.x = 0.0f;
5846  ourcockpit.headlight.y = -0.00026364f; // down
5847  ourcockpit.headlight.z = 0.02f; // fwd, at the nose because the point between the lights is inside the cockpit
5848  ourcockpit.uptranslimit = 0.00625f; // at max gross
5849  ourcockpit.dntranslimit = 0.0116f; // at max gross // 6550
5850  ourcockpit.lrtranslimit = 0.00625f; // at max gross
5851  ourcockpit.fwdthrustlimit = 0.0116f; // at max gross
5852  ourcockpit.spoolTime = 5.8f; // seconds
5853  ourcockpit.revthrustlimit = 0.0116f; // at max gross
5854  ourcockpit.strutabsorb = 0.002205393f * 5.0f; // meter/s
5855  ourcockpit.gndvehicle = false;
5856  ourcockpit.spaceCapable = true;
5857  ourcockpit.wheeled = false;
5858  ourcockpit.steerTires = 3;
5859  ourcockpit.noseWheelToCgKm = 0.0f;
5860  ourcockpit.steerLimitRadian = 0.0f; // if we change this here we have to change it in playerships[t].steerLimitRadian too
5861  ourcockpit.tires = 3;
5863  ourcockpit.nextgen = true;
5864  ourcockpit.bays = 6;
5865  ourcockpit.engines = 3;
5866  ourcockpit.emptyWeightLbs = 277581.7f;
5867  ourcockpit.maxGrossLbs = 525100.4f;
5870  ourcockpit.ffmax = 538.7927f; // at 0.0116 she burns 22500 lbs per hour 6.25 lbs per second
5871  ourcockpit.ffidle = 0.01448121f; // 52 lbs/hr
5872  ourcockpit.fuelmax = 60000.0f; // lbs
5873  ourcockpit.aoiWingRad = 0.0f;
5874  ourcockpit.cockpitArmKm.x = -0.0006964394f; // left offset of center of cockpit
5875  ourcockpit.cockpitArmKm.y = 0.00121876895f; // up
5876  ourcockpit.cockpitArmKm.z = 0.0184556441f; // fwd
5877  ourcockpit.appitagr = 3.5f; // agressiveness for pitch on autopilot (2 is standard)
5878  ourcockpit.aprolagr = 6.0f; // agressiveness for roll on autopilot
5879  ourcockpit.dockOffsetKmZ = 0.0027f;
5880  ourcockpit.dockOffsetKmY = 0.0f;
5881  ourcockpit.exteriorInsulationHeatTransferCoefficient = 0.063f; // calcium silicate
5882  ourcockpit.pitchLimitRadians = 0.78539816339744830961566084581988f; // 45° control deflection stop
5883  ourcockpit.machAngleDragScalar = sinf(atanf(1.320f));
5884  ourcockpit.sonicBooms = 2;
5885  ourcockpit.engineEfficiencyAtSeaLevelScalar = 0.921659f; // based on falcon 9 on earth which means this is 2.5x as efficient!
5886 
5887  // Determined from new Inertial Moment routine
5888  ourcockpit.momentp = 124.982147f;
5889  ourcockpit.momentr = 71.806427f;
5890  ourcockpit.momenty = 186.511765f;
5891  ourcockpit.strutsrettoCG = 0.003134f; // so the bottom most polygon Z ... negated
5892  ourcockpit.strutlength = 0.002438f;
5893  ourcockpit.rooftoCG = 0.002089f; // might need to be negative 0.0013928788f; // 4 units
5894  ourcockpit.wingspanM = 48.750797f;
5895  ourcockpit.rcsYParmM = 16.714558f;
5896 
5897  // All of these must go through the spreadsheet
5898  ourcockpit.f28 = 3.542405185f; // side drag coefficient
5899  ourcockpit.f20FrontBackDragCoeff = 2.568257887f; // front/rear drag coefficient
5900  ourcockpit.f27 = 14.53457189f; // top/bottom drag coefficient
5901  ourcockpit.f25 = 0.172558f; // landing gear extended adjustment
5902  ourcockpit.h9RudderSqFt = 125.3846f; // rudder area ft²
5903  ourcockpit.h6ElevatorSqFt = 240.8797f; // elevator area ft²
5904  ourcockpit.d16HTailWithElevatorSqFt = 1183.560f; // hstab area ft²
5905  ourcockpit.d17VTailWithRudderSqFt = 837.0745f; // vstab area ft²
5906  ourcockpit.h12 = 227.2816f; // aileron area (one side) ft²
5907  ourcockpit.d15TotalWingAreaSqFt = 4264.95f;
5908  ourcockpit.b9DistanceToVTailM = 24.325602f; // DV (m)
5909  ourcockpit.b6DistanceToHTailM = 26.479713f; // DH (m)
5910  ourcockpit.b12WingRollArmM = 18.137566f; // wing roll arm (m)
5911  ourcockpit.b15WingPitchArmM = 7.180880f; // wing pitch arm (m)
5912  ourcockpit.c9WingYawArmM = 19.151197f; // wing yaw arm (m)
5913  ourcockpit.i48CriticalEngineYawArmM = 18.804f; // critical engine yaw arm (m)
5914  ourcockpit.l48AverageEnginePitchArmM = -0.38014f; // critical engine pitch arm (m)
5915  ourcockpit.d65wasd61 = 14.44276701f; // roll drag Cx
5916  ourcockpit.e65wase61 = 7.755528f; // roll drag arm (m)
5917  ourcockpit.Vs1 = 0.079f;
5918  ourcockpit.Vs2 = 0.079f; // for thrust aug top speed, avionics setting not from spreadsheet
5919  ourcockpit.VcMSL = 0.145f;
5920  ourcockpit.i66wasi62 = 91.99259518f; // ft² at m asym pitch body
5921  ourcockpit.k66wask62 = 158.1099498f; // ft² at m asym pitch htail
5922  ourcockpit.i65wasi61 = 126.5371507f; // ft² at m asym yaw body
5923  ourcockpit.k65wask61 = 111.2692687f; // ft² at m asym yaw vtail
5924  }
5925  break;
5926  case P13:
5927  {
5928  _sopen_s(&handle, "meshes\\p13-cockpit1.dix", _O_RDONLY | _O_BINARY | _O_SEQUENTIAL, _SH_DENYWR, _S_IWRITE);
5929  ourcockpit.headlight.x = 0.0f;
5930  ourcockpit.headlight.y = -0.00026364f; // down
5931  ourcockpit.headlight.z = 0.0167f; // fwd, at the nose because the point between the lights is inside the cockpit
5932  ourcockpit.uptranslimit = 0.002f; // at max gross
5933  ourcockpit.dntranslimit = 0.02f; // at max gross
5934  ourcockpit.lrtranslimit = 0.02f; // at max gross
5935  ourcockpit.fwdthrustlimit = 0.02f; // 3600
5936  ourcockpit.spoolTime = 10.0f; // seconds
5937  ourcockpit.revthrustlimit = 0.02f;
5938  ourcockpit.strutabsorb = 0.001775581f * 5.0f; // meter/s
5939  ourcockpit.gndvehicle = false;
5940  ourcockpit.spaceCapable = true;
5941  ourcockpit.wheeled = false;
5942  ourcockpit.steerTires = 2;
5943  ourcockpit.noseWheelToCgKm = 0.0f;
5944  ourcockpit.steerLimitRadian = 0.0f; // if we change this here we have to change it in playerships[t].steerLimitRadian too
5945  ourcockpit.tires = 2;
5947  ourcockpit.nextgen = true;
5948  ourcockpit.bays = 0;
5949  ourcockpit.engines = 2;
5950  ourcockpit.emptyWeightLbs = 106639.568f;
5951  ourcockpit.maxGrossLbs = 180378.000f;
5954  ourcockpit.ffmax = 538.7927f; // at 0.0116 she burns 22500 lbs per hour 6.25 lbs per second
5955  ourcockpit.ffidle = 0.01448121f; // if we change this here, we have to change it on server
5956  ourcockpit.fuelmax = 40000.0f;
5957  ourcockpit.aoiWingRad = 0.0f;
5958  ourcockpit.cockpitArmKm.x = -0.0002539102f; // offset of center of cockpit
5959  ourcockpit.cockpitArmKm.y = 0.00040625634f;
5960  ourcockpit.cockpitArmKm.z = 0.0006093845f;
5961  ourcockpit.appitagr = 2.0f; // agressiveness for pitch on autopilot (2 is standard)
5962  ourcockpit.aprolagr = 1.0f; // agressiveness for roll on autopilot
5963  ourcockpit.dockOffsetKmZ = 0.002786f - 0.003482f; // negative moves the ship UP on the dock interface, 0.003482 aligns with the FRONT instead of the BOTTOM docking port on the dock interface
5964  ourcockpit.dockOffsetKmY = 0.016715f + 0.0013f; // 0.001393 aligns with the FRONT instead of the BOTTOM docking port on the dock interface
5965  ourcockpit.dockingOrientationZ = 1.0f; // backwards
5967  ourcockpit.exteriorInsulationHeatTransferCoefficient = 0.046f; // styrofoam-expanded polystyrene
5969  ourcockpit.machAngleDragScalar = sinf(atanf(1.309f));
5970  ourcockpit.sonicBooms = 2;
5971 
5972  // Determined from new Intertial Moment routine
5973  ourcockpit.momentp = 34.848396f;
5974  ourcockpit.momentr = 15.824283f;
5975  ourcockpit.momenty = 37.362788f;
5976  ourcockpit.strutsrettoCG = 0.004527f; // so the bottom most polygon Z ... negated
5977  ourcockpit.strutlength = 0.001741f;
5978  ourcockpit.rooftoCG = 0.004179f;
5979  ourcockpit.wingspanM = 30.643354f;
5980  ourcockpit.rcsYParmM = 9.750158f;
5981 
5982  // All of these must go through the spreadsheet
5983  ourcockpit.f28 = 2.11575258f; // side drag coefficient
5984  ourcockpit.f20FrontBackDragCoeff = 1.566484288f; // front/rear drag coefficient
5985  ourcockpit.f27 = 5.657307528f; // top/bottom drag coefficient
5986  ourcockpit.f25 = 0.045902f; // landing gear extended coefficient
5987  ourcockpit.h9RudderSqFt = 0.0f; // rudder area
5988  ourcockpit.h6ElevatorSqFt = 0.0f; // elevator area
5989  ourcockpit.d16HTailWithElevatorSqFt = 0.0f; // hstab area
5990  ourcockpit.d17VTailWithRudderSqFt = 0.0f; // vstab area
5991  ourcockpit.h12 = 146.9295f; // aileron area (one side)
5992  ourcockpit.d15TotalWingAreaSqFt = 1469.78f;
5993  ourcockpit.b9DistanceToVTailM = 0.0f; // DV (m)
5994  ourcockpit.b6DistanceToHTailM = 0.0f; // DH (m)
5995  ourcockpit.b12WingRollArmM = 7.377546f; // wing roll arm
5996  ourcockpit.b15WingPitchArmM = 2.651964f; // wing pitch arm
5997  ourcockpit.c9WingYawArmM = 7.040407f; // wing yaw arm
5998  ourcockpit.i48CriticalEngineYawArmM = 0.0f; // critical engine yaw arm (m)
5999  ourcockpit.l48AverageEnginePitchArmM = 0.0f; // critical engine pitch arm (m)
6000  ourcockpit.d65wasd61 = 5.89985235f; // roll drag Cx
6001  ourcockpit.e65wase61 = 4.569886f; // roll drag arm
6002  ourcockpit.Vs1 = 0.079f;
6003  ourcockpit.Vs2 = 0.189f; // for thrust aug top speed
6004  ourcockpit.VcMSL = 0.189f;
6005  ourcockpit.i66wasi62 = 37.96963685f; // ft² at m asym pitch body
6006  ourcockpit.k66wask62 = 0.0f; // ft² at m asym pitch htail
6007  ourcockpit.i65wasi61 = 28.30608656f; // ft² at m asym yaw body
6008  ourcockpit.k65wask61 = 0.0f; // ft² at m asym yaw vtail
6009  }
6010  break;
6011  case A4:
6012  {
6013  _sopen_s(&handle, "meshes\\T-8 Wanderer INT.dix", _O_RDONLY | _O_BINARY | _O_SEQUENTIAL, _SH_DENYWR, _S_IWRITE);
6014  ourcockpit.headlight.x = 0.0f;
6015  ourcockpit.headlight.y = -0.00026364f; // down
6016  ourcockpit.headlight.z = 0.0167f; // fwd, at the nose because the point between the lights is inside the cockpit
6017  ourcockpit.uptranslimit = 0.002f; // at max gross
6018  ourcockpit.dntranslimit = 0.02f; // at max gross
6019  ourcockpit.lrtranslimit = 0.02f; // at max gross
6020  ourcockpit.fwdthrustlimit = 0.0338f; // should be 30% faster than E-10 // 1791.4
6021  ourcockpit.spoolTime = 16.9f; // seconds
6022  ourcockpit.revthrustlimit = 0.0338f;
6023  ourcockpit.strutabsorb = 0.0017411f * 5.0f; // meter/s
6024  ourcockpit.gndvehicle = false;
6025  ourcockpit.spaceCapable = false;
6026  ourcockpit.wheeled = false;
6027  ourcockpit.steerTires = 3;
6028  ourcockpit.noseWheelToCgKm = 0.0f;
6029  ourcockpit.steerLimitRadian = 0.0f; // if we change this here we have to change it in playerships[t].steerLimitRadian too
6030  ourcockpit.tires = 3;
6032  ourcockpit.nextgen = true;
6033  ourcockpit.bays = 1;
6034  ourcockpit.engines = 2;
6035  ourcockpit.emptyWeightLbs = 37827.200f;
6036  ourcockpit.maxGrossLbs = 90537.660f; // in lbs
6037  ourcockpit.serviceCeilingKm = 23.14118437f; // max alt should be 60,000 feet
6039  ourcockpit.ffmax = 104.1665887f; // at 0.02 she burns 7500 lbs per hour 2.08 lbs per second
6040  ourcockpit.ffidle = 0.01448121f; // if we change this here, we have to change it on server
6041  ourcockpit.fuelmax = 20000.0f;
6042  ourcockpit.aoiWingRad = 0.0f;
6043  ourcockpit.cockpitArmKm.x = 0.0f; // left offset of center of cockpit
6044  ourcockpit.cockpitArmKm.y = 0.002396f; // up
6045  ourcockpit.cockpitArmKm.z = 0.007938f; // fwd (negative)
6046  ourcockpit.appitagr = 2.0f; // agressiveness for pitch on autopilot (2 is standard)
6047  ourcockpit.aprolagr = 1.0f; // agressiveness for roll on autopilot
6049  ourcockpit.pitchLimitRadians = 0.523599f; // 30° control deflection stop
6050  ourcockpit.machAngleDragScalar = sinf(atanf(0.943f));
6051  ourcockpit.sonicBooms = 2;
6052 
6053  // Determined from new Intertial Moment routine
6054  ourcockpit.momentp = 5653430.5f / ourcockpit.emptyWeightLbs;//151.411484f;
6055  ourcockpit.momentr = 1811122.625f / ourcockpit.emptyWeightLbs;//51.457165f;
6056  ourcockpit.momenty = 7240540.5f / ourcockpit.emptyWeightLbs;//189.930054f;
6057  ourcockpit.strutsrettoCG = 0.000348f; // so the bottom most polygon Z ... negated
6058  ourcockpit.strutlength = 0.001741f;
6059  ourcockpit.rooftoCG = 0.003482f;
6060  ourcockpit.wingspanM = 33.777336f;
6061  ourcockpit.rcsYParmM = 11.839479f;
6062 
6063  // All of these must go through the spreadsheet
6064  ourcockpit.f28 = 1.994480047f; // side drag coefficient
6065  ourcockpit.f20FrontBackDragCoeff = 0.666857339f; // front/rear drag coefficient
6066  ourcockpit.f27 = 5.328341544f; // top/bottom drag coefficient
6067  ourcockpit.f25 = 0.035702f; // landing gear extended coefficient
6068  ourcockpit.h9RudderSqFt = 72.5818f; // rudder area
6069  ourcockpit.h6ElevatorSqFt = 147.2827f; // elevator area
6070  ourcockpit.d16HTailWithElevatorSqFt = 437.963f; // hstab area
6071  ourcockpit.d17VTailWithRudderSqFt = 288.7377f; // vstab area
6072  ourcockpit.h12 = 300.3932f; // aileron area (one side)
6073  ourcockpit.d15TotalWingAreaSqFt = 1691.40f; // wing area
6074  ourcockpit.b9DistanceToVTailM = 20.544979f; // DV (m)
6075  ourcockpit.b6DistanceToHTailM = 20.782639f; // DH (m)
6076  ourcockpit.b12WingRollArmM = 10.67159f; // wing roll arm
6077  ourcockpit.b15WingPitchArmM = 7.398411f; // wing pitch arm
6078  ourcockpit.c9WingYawArmM = 12.322233f; // wing yaw arm
6079  ourcockpit.i48CriticalEngineYawArmM = 4.875f; // critical engine yaw arm (m)
6080  ourcockpit.l48AverageEnginePitchArmM = -1.71160f; // critical engine pitch arm (m)
6081  ourcockpit.d65wasd61 = 5.257788444f; // roll drag Cx
6082  ourcockpit.e65wase61 = 6.910923f; // roll drag arm
6083  ourcockpit.Vs1 = 0.040f;
6084  ourcockpit.Vs2 = 0.040f; // for thrust aug top speed
6085  ourcockpit.VcMSL = 0.286f;
6086  ourcockpit.i66wasi62 = 79.67890442f; // ft² at m asym pitch body
6087  ourcockpit.k66wask62 = 51.95791939f; // ft² at m asym pitch htail
6088  ourcockpit.i65wasi61 = 39.61589503f; // ft² at m asym yaw body
6089  ourcockpit.k65wask61 = 34.20395987f; // ft² at m asym yaw vtail
6090  }
6091  break;
6092  case C2:
6093  {
6094  _sopen_s(&handle, "meshes\\C-2 Dasher INT.dix", _O_RDONLY | _O_BINARY | _O_SEQUENTIAL, _SH_DENYWR, _S_IWRITE);
6095  ourcockpit.headlight.x = 0.0f;
6096  ourcockpit.headlight.y = -0.00009f; // down
6097  ourcockpit.headlight.z = 0.001472f; // fwd, at the nose because the point between the lights is inside the cockpit
6098  ourcockpit.uptranslimit = 0.0f;
6099  ourcockpit.dntranslimit = 0.0f;
6100  ourcockpit.lrtranslimit = 0.0f; // at max gross
6101  ourcockpit.fwdthrustlimit = 0.118f; // 70 hp? top speed was 82 should be 167 now now 103?
6102  ourcockpit.spoolTime = 0.0f; // seconds
6103  ourcockpit.strutabsorb = 0.015f; // meter/s
6104  ourcockpit.gndvehicle = true;
6105  ourcockpit.spaceCapable = false;
6106  ourcockpit.wheeled = true;
6107  ourcockpit.steerTires = 2;
6108  ourcockpit.noseWheelToCgKm = 0.0010155f;
6109  ourcockpit.steerLimitRadian = D3DXToRadian(45.0f); // if we change this here we have to change it in playerships[t].steerLimitRadian too
6110  ourcockpit.tires = 4;
6111  ourcockpit.tireRadiusKm = 0.0002155f; // 0.000431f diameter or 17" if we change this here we have to change it in playerships[t].tireCircumferenceKm
6112  ourcockpit.clutchtime = 0.25f;
6113  ourcockpit.fwdgears = 3;
6114  // from dodge dynasty (w/o o/d)
6115  ourcockpit.ratios[0] = -0.46948356807511737089201877934272f;
6116  ourcockpit.ratios[1] = 0.37174721189591078066914498141264f;
6117  ourcockpit.ratios[2] = 0.64516129032258064516129032258065f;
6118  ourcockpit.ratios[3] = 1.0f;
6119  // differential?
6120  ourcockpit.ratios[0] *= 2.0f;
6121  ourcockpit.ratios[1] *= 2.0f;
6122  ourcockpit.ratios[2] *= 2.0f;
6123  ourcockpit.ratios[3] *= 2.0f;
6124 
6126  ourcockpit.nextgen = false;
6127  ourcockpit.bays = 0;
6128  ourcockpit.engines = 1;
6129  ourcockpit.emptyWeightLbs = 2017.019f; // in lbs
6130  ourcockpit.maxGrossLbs = 2420.465f; // in lbs
6133  ourcockpit.ffmax = 0.015f; // gndvehicles are in lbs per second, 4.6 hours at full throttle! no ... now 66 minutes at full throttle
6134  ourcockpit.ffidle = ourcockpit.ffmax * 0.1f; // idle sucks fuel because RPM is 0.001f
6135  ourcockpit.fuelmax = 60.0f;
6136  ourcockpit.cockpitArmKm.x = -0.000399f; // left offset of center of cockpit
6137  ourcockpit.cockpitArmKm.y = 0.000468f; // up
6138  ourcockpit.cockpitArmKm.z = 0.000347f; // fwd
6139  ourcockpit.scanDisplayVesselLimit = 19; // plus waypt
6140  ourcockpit.exteriorInsulationHeatTransferCoefficient = 0.52f; // polymer, high-density
6141 
6142  // Determined from new Intertial Moment routine
6143  ourcockpit.momentp = 1179.111572f / ourcockpit.emptyWeightLbs;//2.59611f;
6144  ourcockpit.momentr = 233.144287f / ourcockpit.emptyWeightLbs;//0.934778f;
6145  ourcockpit.momenty = 1260.210083f / ourcockpit.emptyWeightLbs;//3.360088f; // at 60mph 96kmh 16mpg 8ppg
6146  ourcockpit.strutsrettoCG = 0.000609f; // so the bottom most polygon Z ... negated
6147  ourcockpit.strutlength = 0.0f;
6148  ourcockpit.rooftoCG = 0.000813f;//-ourcockpit.cockpitarm.y; // 4 units
6149 
6150  // All of these must go through the spreadsheet
6151  ourcockpit.f28 = 0.079903875f; // side drag coefficient
6152  ourcockpit.f20FrontBackDragCoeff = 0.07239518f; // front/rear drag coefficient
6153  ourcockpit.f25 = 0.0f; // landing gear extended adjustment
6154  ourcockpit.f27 = 0.14309f; // top/bottom drag coefficient
6155  ourcockpit.d65wasd61 = 0.157540994f; // roll drag Cx
6156  ourcockpit.e65wase61 = 2.026435f; // roll drag arm
6157  ourcockpit.i66wasi62 = 0.0f; // ft² at m asym pitch body
6158  ourcockpit.k66wask62 = 0.0f; // ft² at m asym pitch htail
6159  ourcockpit.i65wasi61 = 0.0f; // ft² at m asym yaw body
6160  ourcockpit.k65wask61 = 0.0f; // ft² at m asym yaw vtail
6161  }
6162  break;
6163  case C2A:
6164  {
6165  _sopen_s(&handle, "meshes\\C-2A Dasher INT.dix", _O_RDONLY | _O_BINARY | _O_SEQUENTIAL, _SH_DENYWR, _S_IWRITE);
6166  ourcockpit.headlight.x = 0.0f;
6167  ourcockpit.headlight.y = -0.00009f; // down
6168  ourcockpit.headlight.z = 0.001472f; // fwd, at the nose because the point between the lights is inside the cockpit
6169  ourcockpit.uptranslimit = 0.0f;
6170  ourcockpit.dntranslimit = 0.0f;
6171  ourcockpit.lrtranslimit = 0.0f; // at max gross
6172  ourcockpit.fwdthrustlimit = 0.118f; // 70 hp? top speed was 82 should be 167 now now 103?
6173  ourcockpit.spoolTime = 0.0f; // seconds
6174  ourcockpit.revthrustlimit = 0.0f; // unused
6175  ourcockpit.strutabsorb = 0.015f; // meter/s
6176  ourcockpit.gndvehicle = true;
6177  ourcockpit.spaceCapable = false;
6178  ourcockpit.wheeled = true;
6179  ourcockpit.steerTires = 2;
6180  ourcockpit.noseWheelToCgKm = 0.001012f; // if we change this here we have to change it in playerships[t].tireCircumferenceKm
6181  ourcockpit.steerLimitRadian = D3DXToRadian(45.0f); // if we change this here we have to change it in playerships[t].steerLimitRadian too
6182  ourcockpit.tires = 4;
6183  ourcockpit.tireRadiusKm = 0.000348f; // 0.000686f diameter or 27.4"
6184  ourcockpit.clutchtime = 0.25f;
6185  ourcockpit.fwdgears = 3;
6186  // gear ratios from 2004 Jeep Wrangler Sport
6187  ourcockpit.ratios[0] = -1.0f / 3.52f; // reverse gear (all models)
6188  ourcockpit.ratios[1] = 1.0f / 2.33f; // 2nd gear
6189  ourcockpit.ratios[2] = 1.0f / 1.38f; // 3rd gear
6190  ourcockpit.ratios[3] = 1.0f; // 4th gear
6191  // differential from 2004 Jeep Wrangler Sport
6192  ourcockpit.ratios[0] *= 3.07f; // (standard)
6193  ourcockpit.ratios[1] *= 3.07f; // (standard)
6194  ourcockpit.ratios[2] *= 3.07f; // (standard)
6195  ourcockpit.ratios[3] *= 3.07f; // (standard)
6196 
6198  ourcockpit.nextgen = false;
6199  ourcockpit.bays = 0;
6200  ourcockpit.engines = 1;
6201  ourcockpit.emptyWeightLbs = 3450.0f; // in lbs
6202  ourcockpit.maxGrossLbs = ourcockpit.emptyWeightLbs + 800.0f; // in lbs
6205  ourcockpit.ffmax = 0.015f; // gndvehicles are in lbs per second, 4.6 hours at full throttle! no ... now 66 minutes at full throttle
6206  ourcockpit.ffidle = ourcockpit.ffmax * 0.1f; // idle sucks fuel because RPM is 0.001f
6207  ourcockpit.fuelmax = 60.0f;
6208  ourcockpit.cockpitArmKm.x = -0.0002f; // left offset of center of cockpit
6209  ourcockpit.cockpitArmKm.y = 0.0002f; // up
6210  ourcockpit.cockpitArmKm.z = -0.0002f; // aft neg
6211  ourcockpit.scanDisplayVesselLimit = 19; // plus waypt
6212  ourcockpit.exteriorInsulationHeatTransferCoefficient = 1.06f; // Plastic, fiber-reinforced
6213 
6214  // Determined from new Inertial Moment routine
6215  ourcockpit.momentp = 1048.819580f / ourcockpit.emptyWeightLbs;
6216  ourcockpit.momentr = 396.376556f / ourcockpit.emptyWeightLbs;
6217  ourcockpit.momenty = 652.443054f / ourcockpit.emptyWeightLbs;
6218  ourcockpit.rooftoCG = 0.000813f;
6219  ourcockpit.strutsrettoCG = 0.000545f; // so the bottom most polygon Z ... negated
6220  ourcockpit.strutlength = 0.0f;
6221 
6222  // All of these must go through the spreadsheet
6223  ourcockpit.f28 = 0.061763652f; // side drag coefficient
6224  ourcockpit.f20FrontBackDragCoeff = 0.037093f; // front/rear drag coefficient
6225  ourcockpit.f25 = 0.0f; // landing gear extended adjustment
6226  ourcockpit.f27 = 0.1023068197f; // top/bottom drag coefficient
6227  ourcockpit.d65wasd61 = 0.0f; // roll drag Cx
6228  ourcockpit.e65wase61 = 0.0f; // roll drag arm
6229  ourcockpit.i66wasi62 = 0.0f; // ft² at m asym pitch body
6230  ourcockpit.k66wask62 = 0.0f; // ft² at m asym pitch htail
6231  ourcockpit.i65wasi61 = 0.0f; // ft² at m asym yaw body
6232  ourcockpit.k65wask61 = 0.0f; // ft² at m asym yaw vtail
6233  }
6234  break;
6235  case T120:
6236  {
6237  _sopen_s(&handle, "meshes\\T-120 Steerhead-stock INT.dix", _O_RDONLY | _O_BINARY | _O_SEQUENTIAL, _SH_DENYWR, _S_IWRITE);
6238  ourcockpit.headlight.x = 0.0f;
6239  ourcockpit.headlight.y = -0.00026364f; // down
6240  ourcockpit.headlight.z = 0.0167f; // fwd, at the nose because the point between the lights is inside the cockpit
6241  ourcockpit.uptranslimit = 0.0f;
6242  ourcockpit.dntranslimit = 0.0f;
6243  ourcockpit.lrtranslimit = 0.0f; // at max gross
6244  ourcockpit.fwdthrustlimit = 0.0091f; // Happy Birthday Bill
6245  ourcockpit.spoolTime = 0.0f; // seconds
6246  ourcockpit.revthrustlimit = 0.0f; // unused
6247  ourcockpit.strutabsorb = 0.015f; // meter/s
6248  ourcockpit.gndvehicle = true;
6249  ourcockpit.spaceCapable = false;
6250  ourcockpit.wheeled = true;
6251  ourcockpit.steerTires = 2;
6252  ourcockpit.noseWheelToCgKm = 0.002336f;
6253  ourcockpit.steerLimitRadian = D3DXToRadian(45.0f); // if we change this here we have to change it in playerships[t].steerLimitRadian too
6254  ourcockpit.tires = 10;
6255  ourcockpit.tireRadiusKm = 0.0004065f; // 0.000813 diameter or 32" if we change this here we have to change it in playerships[t].tireCircumferenceKm
6256  ourcockpit.clutchtime = 0.5f;
6257  ourcockpit.speedLimiterKph = 105.0f;
6258  ourcockpit.fwdgears = 6; // 7 speed is 6 fwd, 1 rev
6259  // 1/17.77 to 1/0.71 is 0.22536268067983968338260665097319 per gear
6260  ourcockpit.ratios[0] = -0.147275f; // REV-HI
6261  ourcockpit.ratios[1] = 0.091407f; // 1st-HI
6262  ourcockpit.ratios[2] = 0.152207f; // 2nd-HI
6263  ourcockpit.ratios[3] = 0.393700f; // 3rd
6264  ourcockpit.ratios[4] = 0.636942f; // 4th
6265  ourcockpit.ratios[5] = 1.0f; // 5th
6266  ourcockpit.ratios[6] = 1.408450f; // 6th
6267  // differential?
6268  ourcockpit.ratios[0] *= 1.35479f; // bigger number gives it less power, higher allowable speed
6269  ourcockpit.ratios[1] *= 1.35479f;
6270  ourcockpit.ratios[2] *= 1.35479f;
6271  ourcockpit.ratios[3] *= 1.35479f;
6272  ourcockpit.ratios[4] *= 1.35479f;
6273  ourcockpit.ratios[5] *= 1.35479f;
6274  ourcockpit.ratios[6] *= 1.35479f;
6275 
6277  ourcockpit.nextgen = false;
6278  ourcockpit.bays = 1;
6279  ourcockpit.engines = 1;
6280  ourcockpit.emptyWeightLbs = 15590.672f;
6281  ourcockpit.maxGrossLbs = 55073.412f;
6284  ourcockpit.ffmax = 0.251f; // gndvehicles are in lbs per second
6285  ourcockpit.ffidle = ourcockpit.ffmax * 0.1f; // idle sucks fuel because RPM is 0.001f
6286  ourcockpit.fuelmax = 1800.0f;
6287  ourcockpit.cockpitArmKm.x = -0.000424f; // left offset of center of cockpit
6288  ourcockpit.cockpitArmKm.y = 0.001683f; // up
6289  ourcockpit.cockpitArmKm.z = 0.001990f; // fwd
6290  ourcockpit.scanDisplayVesselLimit = 19; // plus waypt
6291  ourcockpit.exteriorInsulationHeatTransferCoefficient = 24.0f; // stainless steel
6292 
6293  // Determined from new Intertial Moment routine
6294  ourcockpit.momentp = 61169.5f / ourcockpit.emptyWeightLbs;//2.59611f;
6295  ourcockpit.momentr = 17747.185547f / ourcockpit.emptyWeightLbs;//0.934778f;
6296  ourcockpit.momenty = 78233.773438f / ourcockpit.emptyWeightLbs;//3.360088f; // at 60mph 96kmh 16mpg 8ppg
6297  ourcockpit.strutsrettoCG = 0.000813f; // so the bottom most polygon Z ... negated
6298  ourcockpit.strutlength = 0.0f;
6299  ourcockpit.rooftoCG = 0.002031f;//-ourcockpit.cockpitarm.y; // 4 units
6300 
6301  // All of these must go through the spreadsheet
6302  ourcockpit.f28 = 0.199476331f; // side drag coefficient
6303  ourcockpit.f20FrontBackDragCoeff = 0.194659f; // front/rear drag coefficient
6304  ourcockpit.f25 = 0.0f; // landing gear extended adjustment
6305  ourcockpit.f27 = 0.374018f; // top/bottom drag coefficient
6306  ourcockpit.d65wasd61 = 0.30034791f; // roll drag Cx
6307  ourcockpit.e65wase61 = 3.975927f; // roll drag arm
6308  ourcockpit.i66wasi62 = 0.0f; // ft² at m asym pitch body
6309  ourcockpit.k66wask62 = 0.0f; // ft² at m asym pitch htail
6310  ourcockpit.i65wasi61 = 0.0f; // ft² at m asym yaw body
6311  ourcockpit.k65wask61 = 0.0f; // ft² at m asym yaw vtail
6312  }
6313  break;
6314  case T121:
6315  {
6316  _sopen_s(&handle, "meshes\\T-120 Steerhead-stock INT.dix", _O_RDONLY | _O_BINARY | _O_SEQUENTIAL, _SH_DENYWR, _S_IWRITE);
6317  ourcockpit.headlight.x = 0.0f;
6318  ourcockpit.headlight.y = -0.00026364f; // down
6319  ourcockpit.headlight.z = 0.0167f; // fwd, at the nose because the point between the lights is inside the cockpit
6320  ourcockpit.uptranslimit = 0.0f;
6321  ourcockpit.dntranslimit = 0.0f;
6322  ourcockpit.lrtranslimit = 0.0f; // at max gross
6323  ourcockpit.fwdthrustlimit = 0.0091f; // Happy Birthday Bill
6324  ourcockpit.spoolTime = 0.0f; // seconds
6325  ourcockpit.revthrustlimit = 0.0f; // unused
6326  ourcockpit.strutabsorb = 0.015f; // meter/s
6327  ourcockpit.gndvehicle = true;
6328  ourcockpit.spaceCapable = false;
6329  ourcockpit.wheeled = true;
6330  ourcockpit.steerTires = 2;
6331  ourcockpit.noseWheelToCgKm = 0.002336f;
6332  ourcockpit.steerLimitRadian = D3DXToRadian(45.0f); // if we change this here we have to change it in playerships[t].steerLimitRadian too
6333  ourcockpit.tires = 14;
6334  ourcockpit.tireRadiusKm = 0.0004065f; // 0.000813 diameter or 32" if we change this here we have to change it in playerships[t].tireCircumferenceKm
6335  ourcockpit.clutchtime = 0.5f;
6336  ourcockpit.speedLimiterKph = 105.0f;
6337  ourcockpit.fwdgears = 6; // 7 speed is 6 fwd, 1 rev
6338  // 1/17.77 to 1/0.71 is 0.22536268067983968338260665097319 per gear
6339  ourcockpit.ratios[0] = -0.147275f; // REV-HI
6340  ourcockpit.ratios[1] = 0.091407f; // 1st-HI
6341  ourcockpit.ratios[2] = 0.152207f; // 2nd-HI
6342  ourcockpit.ratios[3] = 0.393700f; // 3rd
6343  ourcockpit.ratios[4] = 0.636942f; // 4th
6344  ourcockpit.ratios[5] = 1.0f; // 5th
6345  ourcockpit.ratios[6] = 1.408450f; // 6th
6346  // differential?
6347  ourcockpit.ratios[0] *= 1.35479f; // bigger number gives it less power, higher allowable speed
6348  ourcockpit.ratios[1] *= 1.35479f;
6349  ourcockpit.ratios[2] *= 1.35479f;
6350  ourcockpit.ratios[3] *= 1.35479f;
6351  ourcockpit.ratios[4] *= 1.35479f;
6352  ourcockpit.ratios[5] *= 1.35479f;
6353  ourcockpit.ratios[6] *= 1.35479f;
6354 
6356  ourcockpit.nextgen = false;
6357  ourcockpit.bays = 1;
6358  ourcockpit.engines = 1;
6359  ourcockpit.emptyWeightLbs = 15590.672f;
6360  ourcockpit.maxGrossLbs = 55073.412f;
6363  ourcockpit.ffmax = 0.251f; // gndvehicles are in lbs per second
6364  ourcockpit.ffidle = ourcockpit.ffmax * 0.1f; // idle sucks fuel because RPM is 0.001f
6365  ourcockpit.fuelmax = 1800.0f;
6366  ourcockpit.cockpitArmKm.x = -0.000424f; // left offset of center of cockpit
6367  ourcockpit.cockpitArmKm.y = 0.001683f; // up
6368  ourcockpit.cockpitArmKm.z = 0.001990f; // fwd
6369  ourcockpit.scanDisplayVesselLimit = 19; // plus waypt
6370  ourcockpit.exteriorInsulationHeatTransferCoefficient = 24.0f; // stainless steel
6371 
6372  // Determined from new Intertial Moment routine
6373  ourcockpit.momentp = 61169.5f / ourcockpit.emptyWeightLbs;//2.59611f;
6374  ourcockpit.momentr = 17747.185547f / ourcockpit.emptyWeightLbs;//0.934778f;
6375  ourcockpit.momenty = 78233.773438f / ourcockpit.emptyWeightLbs;//3.360088f; // at 60mph 96kmh 16mpg 8ppg
6376  ourcockpit.strutsrettoCG = 0.000813f; // so the bottom most polygon Z ... negated
6377  ourcockpit.strutlength = 0.0f;
6378  ourcockpit.rooftoCG = 0.002031f;//-ourcockpit.cockpitarm.y; // 4 units
6379 
6380  // All of these must go through the spreadsheet
6381  ourcockpit.f28 = 0.199476331f; // side drag coefficient
6382  ourcockpit.f20FrontBackDragCoeff = 0.194659f; // front/rear drag coefficient
6383  ourcockpit.f25 = 0.0f; // landing gear extended adjustment
6384  ourcockpit.f27 = 0.374018f; // top/bottom drag coefficient
6385  ourcockpit.d65wasd61 = 0.30034791f; // roll drag Cx
6386  ourcockpit.e65wase61 = 3.975927f; // roll drag arm
6387  ourcockpit.i66wasi62 = 0.0f; // ft² at m asym pitch body
6388  ourcockpit.k66wask62 = 0.0f; // ft² at m asym pitch htail
6389  ourcockpit.i65wasi61 = 0.0f; // ft² at m asym yaw body
6390  ourcockpit.k65wask61 = 0.0f; // ft² at m asym yaw vtail
6391  }
6392  break;
6393  case E11:
6394  {
6395  _sopen_s(&handle, "meshes\\e11cockpit1.dix", _O_RDONLY | _O_BINARY | _O_SEQUENTIAL, _SH_DENYWR, _S_IWRITE);
6396  ourcockpit.headlight.x = 0.0f;
6397  ourcockpit.headlight.y = -0.00026364f; // down
6398  ourcockpit.headlight.z = 0.02f; // fwd, at the nose because the point between the lights is inside the cockpit
6399  ourcockpit.uptranslimit = 0.006125f; // at max gross
6400  ourcockpit.dntranslimit = 0.01316f; // at max gross // 6550
6401  ourcockpit.lrtranslimit = 0.00625f; // at max gross
6402  ourcockpit.fwdthrustlimit = 0.01316f; // at max gross
6403  ourcockpit.spoolTime = 5.8f; // seconds (was 6.5 before we had spoolTime!)
6404  ourcockpit.revthrustlimit = 0.01316f; // at max gross
6405  ourcockpit.strutabsorb = 0.002205393f * 5.0f; // meter/s
6406  ourcockpit.gndvehicle = false;
6407  ourcockpit.spaceCapable = true;
6408  ourcockpit.wheeled = false;
6409  ourcockpit.steerTires = 3;
6410  ourcockpit.noseWheelToCgKm = 0.0f;
6411  ourcockpit.steerLimitRadian = 0.0f; // if we change this here we have to change it in playerships[t].steerLimitRadian too
6412  ourcockpit.tires = 3;
6414  ourcockpit.nextgen = true;
6415  ourcockpit.bays = 6;
6416  ourcockpit.engines = 3;
6417  ourcockpit.emptyWeightLbs = 251179.705f; // lbs
6418  ourcockpit.maxGrossLbs = 525100.400f;
6421  ourcockpit.ffmax = 419.0609889f; // at 0.01316 she burns 19854 lbs per hour 5.515 lbs per second
6422  ourcockpit.ffidle = 0.01448121f; // 52 lbs/hr
6423  ourcockpit.fuelmax = 60000.0f; // lbs
6424  ourcockpit.aoiWingRad = 0.0f;
6425  ourcockpit.cockpitArmKm.x = -0.0006964394f; // left offset of center of cockpit
6426  ourcockpit.cockpitArmKm.y = 0.00121876895f; // up
6427  ourcockpit.cockpitArmKm.z = 0.0184556441f; // fwd
6428  ourcockpit.appitagr = 3.5f; // agressiveness for pitch on autopilot (2 is standard)
6429  ourcockpit.aprolagr = 6.0f; // agressiveness for roll on autopilot
6430  ourcockpit.dockOffsetKmZ = 0.0027f;
6431  ourcockpit.dockOffsetKmY = 0.0f;
6432  ourcockpit.exteriorInsulationHeatTransferCoefficient = 0.045f; // fiberglass or foam-glass
6433  ourcockpit.pitchLimitRadians = 0.523599f; // 30° control deflection stop
6434  ourcockpit.machAngleDragScalar = sinf(atanf(1.320f));
6435  ourcockpit.sonicBooms = 2;
6436  ourcockpit.engineEfficiencyAtSeaLevelScalar = 0.93f; // based on falcon 9 on earth which means this is 2.5x as efficient!
6437 
6438  // Determined from new Intertial Moment routine
6439  ourcockpit.momentp = 124.982147f;
6440  ourcockpit.momentr = 71.806427f;
6441  ourcockpit.momenty = 186.511765f;
6442  ourcockpit.strutsrettoCG = 0.003134f; // so the bottom most polygon Z ... negated
6443  ourcockpit.strutlength = 0.002438f;
6444  ourcockpit.rooftoCG = 0.002089f; // might need to be negative 0.0013928788f; // 4 units
6445  ourcockpit.wingspanM = 48.750797f;
6446  ourcockpit.rcsYParmM = 16.714558f;
6447 
6448  // All of these must go through the spreadsheet
6449  ourcockpit.f28 = 4.961967f; // side drag coefficient
6450  ourcockpit.f20FrontBackDragCoeff = 2.696208f; // front/rear drag coefficient
6451  ourcockpit.f27 = 14.258089f; // top/bottom drag coefficient
6452 
6454  ourcockpit.f25 = 0.048997f; // landing gear extended adjustment
6455 
6456  ourcockpit.h9RudderSqFt = 131.1158f; // rudder area ft²
6457  ourcockpit.h6ElevatorSqFt = 236.8446f; // elevator area ft²
6458  ourcockpit.d16HTailWithElevatorSqFt = 1686.596f; // hstab area ft²
6459  ourcockpit.d17VTailWithRudderSqFt = 853.2926f; // vstab area ft²
6460  ourcockpit.h12 = 235.7941f; // aileron area (one side) ft²
6461  ourcockpit.d15TotalWingAreaSqFt = 4595.27f; // wing area ft²
6462  ourcockpit.b9DistanceToVTailM = 26.842907f; // DV (m)
6463  ourcockpit.b6DistanceToHTailM = 27.946484f; // DH (m)
6464  ourcockpit.b12WingRollArmM = 13.132276f; // wing roll arm (m)
6465  ourcockpit.b15WingPitchArmM = 6.826286f; // wing pitch arm (m)
6466  ourcockpit.c9WingYawArmM = 15.407158f; // wing yaw arm (m)
6467  ourcockpit.i48CriticalEngineYawArmM = 18.804f; // critical engine yaw arm (m)
6468  ourcockpit.l48AverageEnginePitchArmM = -0.38014f; // critical engine pitch arm (m)
6469  ourcockpit.d65wasd61 = 14.25808948f; // roll drag Cx
6470  ourcockpit.e65wase61 = 4.597237f; // roll drag arm (m)
6471  ourcockpit.Vs1 = 0.079f;
6472  ourcockpit.Vs2 = 0.168f; // for thrust aug top speed, avionics setting not from spreadsheet, use Vr
6473  ourcockpit.VcMSL = 0.146f;
6474  ourcockpit.i66wasi62 = 26.0577836f; // ft² at m asym pitch body
6475  ourcockpit.k66wask62 = 66.56828893f; // ft² at m asym pitch htail
6476  ourcockpit.i65wasi61 = 8.88199401f; // ft² at m asym yaw body
6477  ourcockpit.k65wask61 = 41.92212376f; // ft² at m asym yaw vtail
6478  }
6479  break;
6480  case T19:
6481  {
6482  _sopen_s(&handle, "meshes\\stratomaster_06-hex.dix", _O_RDONLY | _O_BINARY | _O_SEQUENTIAL, _SH_DENYWR, _S_IWRITE);
6483  ourcockpit.headlight.x = 0.0f;
6484  ourcockpit.headlight.y = -0.00026364f; // down
6485  ourcockpit.headlight.z = 0.0167f; // fwd, at the nose because the point between the lights is inside the cockpit
6486  ourcockpit.uptranslimit = 0.0f; // not installed on Stratoranger
6487  ourcockpit.dntranslimit = 0.0f; // not installed on Stratoranger
6488  ourcockpit.lrtranslimit = 0.0f; // not installed on Stratoranger
6489  ourcockpit.fwdthrustlimit = 0.005f * 1.25f; // T-1
6490  ourcockpit.spoolTime = 2.5f; // seconds
6491  ourcockpit.revthrustlimit = 0.005f * 0.3f * 1.25f; // at max gross // https://aviation.stackexchange.com/questions/14597/how-much-thrust-can-the-thrust-reversers-create
6492  ourcockpit.strutabsorb = 0.002438f * 5.0f; // meter/s
6493  ourcockpit.gndvehicle = false; // drivetrain
6494  ourcockpit.spaceCapable = false;
6495  ourcockpit.wheeled = true; // first one ever
6496  ourcockpit.steerTires = 1;
6497  ourcockpit.noseWheelToCgKm = 0.005049f;
6498  ourcockpit.steerLimitRadian = 1.22173f; // 70 degrees with tiller, if we change this here we have to change it in playerships[t].steerLimitRadian too
6499  ourcockpit.tires = 5;
6500  ourcockpit.tireRadiusKm = 0.000406f; // 0.000813f diameter same as T-1 if we change this here we have to change it in playerships[t].tireCircumferenceKm
6502  ourcockpit.nextgen = true;
6504  ourcockpit.flapSettings.emplace_back(0);
6505  ourcockpit.flapSettings.emplace_back(8);
6506  ourcockpit.flapSettings.emplace_back(20);
6507  ourcockpit.flapSettings.emplace_back(30);
6508  ourcockpit.flapSettings.emplace_back(40);
6509 
6510  ourcockpit.bays = 1; // T-1
6511  ourcockpit.engines = 2;
6512  ourcockpit.emptyWeightLbs = 27712.430f; // T-1
6513  ourcockpit.maxGrossLbs = 87054.186f; // T-1
6514  ourcockpit.serviceCeilingKm = 45.0f;
6517  //ourcockpit.bypassratio = 0.0f;
6518  ourcockpit.ffmax = 50.0f; // at 0.02 she burns 7500 lbs per hour 2.08 lbs per second
6519  ourcockpit.ffidle = 0.01448121f; // if we change this here, we have to change it on server
6520  ourcockpit.fuelmax = 20000.0f;
6521  ourcockpit.aoiWingRad = 0.05f; // went from 0 to 3 degrees 5/26/2019 ... GA aircraft are usually 6 degrees
6522  ourcockpit.cockpitArmKm.x = 0.0f; // left offset of center of cockpit
6523  ourcockpit.cockpitArmKm.y = 0.0f; // up
6524  ourcockpit.cockpitArmKm.z = 0.004179f; // fwd (negative)
6525  ourcockpit.appitagr = 0.6f; // agressiveness for pitch on autopilot (2 is standard), cut from 1.5 to 0.4 5/26/2019
6526  ourcockpit.aprolagr = 8.0f; // agressiveness for roll on autopilot (1 is standard) was 2
6527  ourcockpit.exteriorInsulationHeatTransferCoefficient = 56.1f; // aluminum alloy
6528  ourcockpit.pitchLimitRadians = 0.523599f; // 30° control deflection stop
6529  ourcockpit.machAngleDragScalar = sinf(atanf(1.315f));
6530  ourcockpit.sonicBooms = 2;
6531 
6532  // Determined from new Intertial Moment routine
6533  ourcockpit.momentp = 1560282.875f / ourcockpit.emptyWeightLbs; // T-1
6534  ourcockpit.momentr = 472888.09375f / ourcockpit.emptyWeightLbs; // T-1
6535  ourcockpit.momenty = 1761135.0f / ourcockpit.emptyWeightLbs; // T-1
6536  ourcockpit.strutsrettoCG = 0.001567f; // so the bottom most polygon Z ... negated
6537  ourcockpit.strutlength = 0.001346f;
6538  ourcockpit.rooftoCG = 0.009750f;
6539  ourcockpit.wingspanM = 29.923187f;
6540  ourcockpit.rcsYParmM = 9.750159f;
6541 
6542  // All of these must go through the spreadsheet
6543  ourcockpit.f28 = 1.37967567f; // side drag coefficient
6544  ourcockpit.f20FrontBackDragCoeff = 0.242184f; // frontal drag coefficient
6545  ourcockpit.f27 = 5.411909338f; // bottom drag coefficient
6546  ourcockpit.f25 = 0.084364f; // landing gear extended coefficient
6547  ourcockpit.h9RudderSqFt = 141.6129f; // rudder area
6548  ourcockpit.h6ElevatorSqFt = 189.6774f; // elevator area
6549  ourcockpit.d16HTailWithElevatorSqFt = 910.97f; // hstab area sq.ft.
6550  ourcockpit.d17VTailWithRudderSqFt = 399.35f; // vstab area sq.ft.
6551  ourcockpit.h12 = 76.7742f; // aileron area (one side)
6552  ourcockpit.d15TotalWingAreaSqFt = 2087.53f; // wing area
6553  ourcockpit.k12flapsAreaSqMTE = 14.265455f; // from windtunnel
6554  // in reality it looks like it is a SPAN ratio not an AREA ratio but we don't have SPAN data
6557  ourcockpit.b9DistanceToVTailM = 18.659472f; // DV (m)
6558  ourcockpit.b6DistanceToHTailM = 18.249069f; // DH (m)
6559  ourcockpit.b12WingRollArmM = 10.027168f; // wing roll arm
6560  ourcockpit.b15WingPitchArmM = 4.821502f; // wing pitch arm
6561  ourcockpit.c9WingYawArmM = 4.096533f; // wing yaw arm
6562  ourcockpit.i48CriticalEngineYawArmM = 2.53293f; // critical engine yaw arm (m)
6563  ourcockpit.l48AverageEnginePitchArmM = -0.63323f; // critical engine pitch arm (m)
6565  ourcockpit.d65wasd61 = 17.49138883f; // roll drag Cx
6566  ourcockpit.e65wase61 = 2.731821f; // roll drag arm
6567  ourcockpit.Vs1 = 0.047f;
6568  ourcockpit.Vs2 = 0.0f; // thrust aug not installed on Stratoranger
6569  ourcockpit.VcMSL = 0.130f;
6570  ourcockpit.Vr = 0.097f;
6571  ourcockpit.i65wasi61 = 3.749335354f; // ft² at m asym yaw body weathervaning
6572  ourcockpit.k65wask61 = 11.15689661f; // ft² at m asym yaw vtail weathervaning
6573  ourcockpit.i66wasi62 = 12.89188387f; // ft² at m asym pitch body weathervaning
6574  ourcockpit.k66wask62 = 16.83982348f; // ft² at m asym pitch htail weathervaning
6575  }
6576  break;
6577  case W6Manx:
6578  {
6579  _sopen_s(&handle, "meshes\\manx-int-hex.dix", _O_RDONLY | _O_BINARY | _O_SEQUENTIAL, _SH_DENYWR, _S_IWRITE);
6580  ourcockpit.headlight.x = 0.0f;
6581  ourcockpit.headlight.y = -0.00026364f; // down
6582  ourcockpit.headlight.z = 0.02f; // fwd, at the nose because the point between the lights is inside the cockpit
6583  ourcockpit.uptranslimit = 0.00625f; // at max gross
6584  ourcockpit.dntranslimit = 0.0116f * 0.5f; // at max gross // 6550
6585  ourcockpit.lrtranslimit = 0.00625f; // at max gross
6586  ourcockpit.fwdthrustlimit = 0.00980665f; // at max gross
6587  ourcockpit.spoolTime = 5.8f; // seconds, from E-10
6588  ourcockpit.revthrustlimit = 0.00980665f; // at max gross
6589  ourcockpit.strutabsorb = 0.002205393f * 5.0f; // meter/s
6590  ourcockpit.gndvehicle = false;
6591  ourcockpit.spaceCapable = true;
6592  ourcockpit.wheeled = true;
6593  ourcockpit.steerTires = 1;
6594  ourcockpit.steerLimitRadian = 1.22173f; // 70 degrees with tiller, if we change this here we have to change it in playerships[t].steerLimitRadian too
6595  ourcockpit.tires = 3;
6596  ourcockpit.tireRadiusKm = 0.00069f; // 0.00138 diameter 54.33 inches if we change this here we have to change it in playerships[t].tireCircumferenceKm
6598  ourcockpit.nextgen = true;
6600  ourcockpit.flapSettings.emplace_back(0);
6601  ourcockpit.flapSettings.emplace_back(8);
6602  ourcockpit.flapSettings.emplace_back(20);
6603  ourcockpit.flapSettings.emplace_back(30);
6604  ourcockpit.flapSettings.emplace_back(40);
6605 
6606  ourcockpit.bays = 3;
6607  ourcockpit.engines = 2;
6608  ourcockpit.emptyWeightLbs = 110231.0f;
6609  ourcockpit.maxGrossLbs = 231503.619f;
6612  ourcockpit.ffmax = 254.9199551f; // from Rise Vehicles AD10
6613  ourcockpit.ffidle = 0.01448121f; // 52 lbs/hr
6614  ourcockpit.fuelmax = 26455.0f; // lbs
6615  ourcockpit.aoiWingRad = 0.0f;
6616  ourcockpit.appitagr = 2.0f; // agressiveness for pitch on autopilot (2 is standard) was 3.5 now 2.0 on 5/26/2019
6617  ourcockpit.aprolagr = 6.0f; // agressiveness for roll on autopilot
6618  ourcockpit.dockOffsetKmZ = 0.002089f;
6619  ourcockpit.dockOffsetKmY = 0.008359f;
6621  ourcockpit.exteriorInsulationHeatTransferCoefficient = 0.039f; // extruded polystyrene XPS
6622  ourcockpit.pitchLimitRadians = 0.698131925192982f; // 40° control deflection stop
6623  ourcockpit.machAngleDragScalar = sinf(atanf(1.068f));
6624  ourcockpit.sonicBooms = 2;
6625  ourcockpit.engineEfficiencyAtSeaLevelScalar = 0.92f; // based on falcon 9 on earth which means this is 2.5x as efficient!
6626 
6627  // Determined from new Intertial Moment routine
6629  ourcockpit.momentr = 11062391.0f / ourcockpit.emptyWeightLbs;
6630  ourcockpit.momenty = 20177486.0f / ourcockpit.emptyWeightLbs;
6631  ourcockpit.cockpitArmKm.x = -0.0006964394f; // left offset of center of cockpit, T-1 E-10 E-11 all the same cockpit
6632  ourcockpit.cockpitArmKm.y = 0.000348f; // up, negate?
6633  ourcockpit.cockpitArmKm.z = 0.016715f; // fwd
6634  ourcockpit.noseWheelToCgKm = 0.013944f;
6635  ourcockpit.strutsrettoCG = 0.002089f; // so the bottom most polygon Z ... negated
6636  ourcockpit.rooftoCG = 0.002089f; // might need to be negative 0.0013928788f; // 4 units
6637  ourcockpit.wingspanM = 50.143673f;
6638  ourcockpit.rcsYParmM = 20.544979f;
6639 
6640  // All of these must go through the spreadsheet
6641  ourcockpit.f28 = 3.673211f; // side drag coefficient
6642  ourcockpit.f20FrontBackDragCoeff = 0.634544f; // front/rear drag coefficient
6643  ourcockpit.f27 = 15.957622f; // top/bottom drag coefficient
6644  ourcockpit.f25 = 0.060729f; // landing gear extended adjustment
6645  ourcockpit.h9RudderSqFt = 42.1505f; // rudder area ft²
6646  ourcockpit.h6ElevatorSqFt = 104.7312f; // elevator area ft²
6647  ourcockpit.d16HTailWithElevatorSqFt = 1880.86f; // hstab area ft²
6648  ourcockpit.d17VTailWithRudderSqFt = 854.62f; // vstab area ft²
6649  ourcockpit.h12 = 110.4301f; // aileron area (one side) ft²
6650  ourcockpit.d15TotalWingAreaSqFt = 6333.98f; // wing area ft²
6651  ourcockpit.j12flapsAreaSqMLE = 23.236309f;
6652  ourcockpit.k12flapsAreaSqMTE = 29.250177f;
6653  // in reality it looks like it is a SPAN ratio not an AREA ratio but we don't have SPAN data
6656  ourcockpit.b9DistanceToVTailM = 14.864624f; // DV (m)
6657  ourcockpit.b6DistanceToHTailM = -3.059761f; // DH (m)
6658  ourcockpit.b12WingRollArmM = 13.817475f; // wing roll arm (m)
6659  ourcockpit.b15WingPitchArmM = 11.523908f; // wing pitch arm (m)
6660  ourcockpit.c9WingYawArmM = 10.317929f; // wing yaw arm (m)
6661  ourcockpit.i48CriticalEngineYawArmM = 5.35354f; // critical engine yaw arm (m)
6662  ourcockpit.l48AverageEnginePitchArmM = 0.03426f; // critical engine pitch arm (m)
6663  ourcockpit.d65wasd61 = 15.9576218f; // roll drag Cx
6664  ourcockpit.e65wase61 = 8.1504f; // roll drag arm (m)
6665  ourcockpit.Vs1 = 0.043f;
6666  ourcockpit.Vs2 = 0.067f; // for thrust aug top speed, avionics setting not from spreadsheet, used Vr here
6667  ourcockpit.VcMSL = 0.184f;
6668  ourcockpit.Vne = 0.094f;
6669  ourcockpit.Vr = 0.067f;
6670  ourcockpit.i66wasi62 = 89.28477136f; // ft² at m asym pitch body
6671  ourcockpit.k66wask62 = 33.952204f; // ft² at m asym pitch htail
6672  ourcockpit.i65wasi61 = 16.9072212f; // ft² at m asym yaw body
6673  ourcockpit.k65wask61 = 14.25189783f; // ft² at m asym yaw vtail
6674  ourcockpit.strutlength = 0.002641f; // from wind tunnel directly
6675  }
6676  break;
6677  case T27:
6678  {
6679  _sopen_s(&handle, "meshes\\mammoth-int.dix", _O_RDONLY | _O_BINARY | _O_SEQUENTIAL, _SH_DENYWR, _S_IWRITE);
6680  ourcockpit.headlight.x = 0.0f;
6681  ourcockpit.headlight.y = -0.00026364f; // down
6682  ourcockpit.headlight.z = 0.0167f; // fwd, at the nose because the point between the lights is inside the cockpit
6683  ourcockpit.uptranslimit = 0.0f;
6684  ourcockpit.dntranslimit = 0.0f;
6685  ourcockpit.lrtranslimit = 0.0f; // at max gross
6686  ourcockpit.fwdthrustlimit = 0.008f;
6687  ourcockpit.spoolTime = 5.0f; // seconds
6688  ourcockpit.revthrustlimit = 0.0f; // unused
6690  ourcockpit.strutabsorb = 0.015f; // meter/s
6691  ourcockpit.gndvehicle = true;
6692  ourcockpit.spaceCapable = false;
6693  ourcockpit.wheeled = true;
6694  ourcockpit.steerTires = 2;
6695  ourcockpit.noseWheelToCgKm = 0.002336f;
6696  ourcockpit.steerLimitRadian = D3DXToRadian(45.0f);
6697  ourcockpit.tires = 8;
6698  ourcockpit.tireRadiusKm = 0.001619f; // 0.003238 diameter or 127" if we change this here we have to change it in playerships[t].tireCircumferenceKm
6699  ourcockpit.clutchtime = 0.5f;
6700  ourcockpit.fwdgears = 1;
6701  // bigger number gives it less power, higher allowable speed
6702  ourcockpit.ratios[0] = -0.665188f; // REV-HI
6703  ourcockpit.ratios[1] = 0.665188f; // 1st-HI
6704 
6706  ourcockpit.nextgen = true;
6707  ourcockpit.bays = 18;
6708  ourcockpit.engines = 2;
6709  ourcockpit.emptyWeightLbs = 509047.0f;
6710  ourcockpit.maxGrossLbs = 1183660.478f;
6711  ourcockpit.serviceCeilingKm = 8.0f;
6713  ourcockpit.ffmax = 0.2465f; // gndvehicles are in lbs per second, column AB
6714  ourcockpit.ffidle = ourcockpit.ffmax * 0.1f; // idle sucks fuel because RPM is 0.001f
6715  ourcockpit.fuelmax = 8955.0f; // column L
6717  ourcockpit.cockpitArmKm.x = -0.000424f; // left offset of center of cockpit
6718  ourcockpit.cockpitArmKm.y = 0.002961f; // up
6719  ourcockpit.cockpitArmKm.z = 0.006355f; // fwd
6720  ourcockpit.exteriorInsulationHeatTransferCoefficient = 24.0f; // stainless steel
6721 
6722  // Determined from new Intertial Moment routine
6723  ourcockpit.momentp = 22946042.0f / ourcockpit.emptyWeightLbs;//2.59611f;
6724  ourcockpit.momentr = 12107143.0f / ourcockpit.emptyWeightLbs;//0.934778f;
6725  ourcockpit.momenty = 32350316.0f / ourcockpit.emptyWeightLbs;//3.360088f; // at 60mph 96kmh 16mpg 8ppg
6726  ourcockpit.strutsrettoCG = 0.003839f; // so the bottom most polygon Z ... negated
6727  ourcockpit.rooftoCG = 0.005746f;
6728 
6729  // All of these must go through the spreadsheet
6730  ourcockpit.strutlength = 0.00193f;
6731  ourcockpit.f28 = 2.636859356f; // side drag coefficient
6732  ourcockpit.f20FrontBackDragCoeff = 1.536845f; // front/rear drag coefficient
6733  ourcockpit.f25 = 0.077463f; // landing gear extended adjustment
6734  ourcockpit.f27 = 9.021116422f; // top/bottom drag coefficient
6735  ourcockpit.d65wasd61 = 10.86400327f; // roll drag Cx
6736  ourcockpit.e65wase61 = 1.204286f; // roll drag arm
6737  ourcockpit.i66wasi62 = 0.0f; // ft² at m asym pitch body
6738  ourcockpit.k66wask62 = 0.0f; // ft² at m asym pitch htail
6739  ourcockpit.i65wasi61 = 0.0f; // ft² at m asym yaw body
6740  ourcockpit.k65wask61 = 0.0f; // ft² at m asym yaw vtail
6741  }
6742  break;
6743  case Apartment:
6744  {
6745  _sopen_s(&handle, "meshes\\INT-apartment1.dix", _O_RDONLY | _O_BINARY | _O_SEQUENTIAL, _SH_DENYWR, _S_IWRITE);
6746  g_bStrapon = false; // can move around freely
6748  ourcockpit.nextgen = true;
6749  ourcockpit.bays = 0;
6750  ourcockpit.engines = 0;
6751  ourcockpit.headlight = centerC; // NAN
6752  ourcockpit.uptranslimit = 0.006125f; // at max gross
6753  ourcockpit.dntranslimit = 0.0125f; // at max gross
6754  ourcockpit.lrtranslimit = 0.0125f; // at max gross
6755  ourcockpit.fwdthrustlimit = 0.0116f; // at max gross
6756  ourcockpit.spoolTime = 0.0f; // seconds
6757  ourcockpit.revthrustlimit = 0.0f; // at max gross
6758  ourcockpit.strutabsorb = 0.002205393f * 5.0f; // meter/s
6759  ourcockpit.gndvehicle = false;
6760  ourcockpit.spaceCapable = false;
6761  ourcockpit.wheeled = false;
6762  ourcockpit.steerTires = 0;
6763  ourcockpit.noseWheelToCgKm = 0.0f;
6764  ourcockpit.steerLimitRadian = 0.0f; // if we change this here we have to change it in playerships[t].steerLimitRadian too
6765  ourcockpit.tires = 0;
6766  ourcockpit.emptyWeightLbs = 277000.0f;
6767  ourcockpit.maxGrossLbs = 524000.0f;
6770  ourcockpit.momentp = 124.982147f;
6771  ourcockpit.momentr = 71.806427f;
6772  ourcockpit.momenty = 186.511765f;
6773  ourcockpit.ffmax = 0.0f; // at 0.0116 she burns 22500 lbs per hour 6.25 lbs per second
6774  ourcockpit.ffidle = 0.0f; // 52 lbs/hr
6775  ourcockpit.fuelmax = 0.0f;
6776  ourcockpit.cockpitArmKm.x = 0.0f; // left offset of center of cockpit
6777  ourcockpit.cockpitArmKm.y = 0.0f; // up
6778  ourcockpit.cockpitArmKm.z = 0.0f; // fwd
6779  ourcockpit.rooftoCG = 0.0f;
6780  ourcockpit.strutsrettoCG = 0.0f;
6781  ourcockpit.strutlength = 0.0f;
6782  // All of these must go through the spreadsheet
6783  ourcockpit.f28 = 3.542405185f; // side drag coefficient
6784  ourcockpit.f20FrontBackDragCoeff = 2.568257887f; // front/rear drag coefficient
6785  ourcockpit.f27 = 14.53457189f; // top/bottom drag coefficient
6786  ourcockpit.f25 = 0.172558f; // landing gear extended adjustment
6787  ourcockpit.d65wasd61 = 14.44276701f; // roll drag Cx
6788  ourcockpit.e65wase61 = 7.755528f; // roll drag arm (m)
6789  ourcockpit.i66wasi62 = 91.99259518f; // ft² at m asym pitch body
6790  ourcockpit.k66wask62 = 158.1099498f; // ft² at m asym pitch htail
6791  ourcockpit.i65wasi61 = 126.5371507f; // ft² at m asym yaw body
6792  ourcockpit.k65wask61 = 111.2692687f; // ft² at m asym yaw vtail
6793  OutsideView(false);
6794  }
6795  break;
6796  case SimBay:
6797  {
6798  _sopen_s(&handle, "meshes\\SimulatorBay.dix", _O_RDONLY | _O_BINARY | _O_SEQUENTIAL, _SH_DENYWR, _S_IWRITE);
6799  g_bStrapon = false; // can move around freely
6801  ourcockpit.nextgen = true;
6802  ourcockpit.bays = 0;
6803  ourcockpit.engines = 0;
6804  ourcockpit.headlight = centerC; // NAN
6805  ourcockpit.uptranslimit = 0.006125f; // at max gross
6806  ourcockpit.dntranslimit = 0.0125f; // at max gross
6807  ourcockpit.lrtranslimit = 0.0125f; // at max gross
6808  ourcockpit.fwdthrustlimit = 0.0116f; // at max gross
6809  ourcockpit.spoolTime = 0.0f; // seconds
6810  ourcockpit.revthrustlimit = 0.0f; // at max gross
6811  ourcockpit.strutabsorb = 0.002205393f * 5.0f; // meter/s
6812  ourcockpit.gndvehicle = false;
6813  ourcockpit.spaceCapable = false;
6814  ourcockpit.wheeled = false;
6815  ourcockpit.steerTires = 0;
6816  ourcockpit.noseWheelToCgKm = 0.0f;
6817  ourcockpit.steerLimitRadian = 0.0f; // if we change this here we have to change it in playerships[t].steerLimitRadian too
6818  ourcockpit.tires = 0;
6819  ourcockpit.emptyWeightLbs = 277000.0f;
6820  ourcockpit.maxGrossLbs = 524000.0f;
6823  ourcockpit.momentp = 124.982147f;
6824  ourcockpit.momentr = 71.806427f;
6825  ourcockpit.momenty = 186.511765f;
6826  ourcockpit.ffmax = 538.7927f; // at 0.0116 she burns 22500 lbs per hour 6.25 lbs per second
6827  ourcockpit.ffidle = 0.01448121f; // 52 lbs/hr
6828  ourcockpit.fuelmax = 60000.0f;
6829  ourcockpit.cockpitArmKm.x = 0.0f; // left offset of center of cockpit
6830  ourcockpit.cockpitArmKm.y = 0.0f; // up
6831  ourcockpit.cockpitArmKm.z = 0.0f; // fwd
6832  ourcockpit.rooftoCG = 0.0f;
6833  ourcockpit.strutsrettoCG = 0.0f;
6834  ourcockpit.strutlength = 0.0f;
6835  // All of these must go through the spreadsheet
6836  ourcockpit.f28 = 3.542405185f; // side drag coefficient
6837  ourcockpit.f20FrontBackDragCoeff = 2.568257887f; // front/rear drag coefficient
6838  ourcockpit.f27 = 14.53457189f; // top/bottom drag coefficient
6839  ourcockpit.f25 = 0.172558f; // landing gear extended adjustment
6840  ourcockpit.d65wasd61 = 14.44276701f; // roll drag Cx
6841  ourcockpit.e65wase61 = 7.755528f; // roll drag arm (m)
6842  ourcockpit.i66wasi62 = 91.99259518f; // ft² at m asym pitch body
6843  ourcockpit.k66wask62 = 158.1099498f; // ft² at m asym pitch htail
6844  ourcockpit.i65wasi61 = 126.5371507f; // ft² at m asym yaw body
6845  ourcockpit.k65wask61 = 111.2692687f; // ft² at m asym yaw vtail
6846  OutsideView(false);
6847  }
6848  break;
6849  case ControlTower:
6850  {
6851  _sopen_s(&handle, "meshes\\controltower.dix", _O_RDONLY | _O_BINARY | _O_SEQUENTIAL, _SH_DENYWR, _S_IWRITE);
6852  g_bStrapon = false; // can move around freely
6854  ourcockpit.nextgen = true;
6855  ourcockpit.bays = 0;
6856  ourcockpit.engines = 0;
6857  ourcockpit.headlight = centerC; // NAN
6858  ourcockpit.uptranslimit = 0.006125f; // at max gross
6859  ourcockpit.dntranslimit = 0.0125f; // at max gross
6860  ourcockpit.lrtranslimit = 0.0125f; // at max gross
6861  ourcockpit.fwdthrustlimit = 0.0116f; // at max gross
6862  ourcockpit.spoolTime = 0.0f; // seconds
6863  ourcockpit.revthrustlimit = 0.0f; // at max gross
6864  ourcockpit.strutabsorb = 0.002205393f * 5.0f; // meter/s
6865  ourcockpit.gndvehicle = false;
6866  ourcockpit.spaceCapable = false;
6867  ourcockpit.wheeled = false;
6868  ourcockpit.steerTires = 0;
6869  ourcockpit.noseWheelToCgKm = 0.0f;
6870  ourcockpit.steerLimitRadian = 0.0f; // if we change this here we have to change it in playerships[t].steerLimitRadian too
6871  ourcockpit.tires = 0;
6872  ourcockpit.emptyWeightLbs = 277000.0f;
6873  ourcockpit.maxGrossLbs = 524000.0f;
6876  ourcockpit.momentp = 124.982147f;
6877  ourcockpit.momentr = 71.806427f;
6878  ourcockpit.momenty = 186.511765f;
6879  ourcockpit.ffmax = 538.7927f; // at 0.0116 she burns 22500 lbs per hour 6.25 lbs per second
6880  ourcockpit.ffidle = 0.01448121f; // 52 lbs/hr
6881  ourcockpit.fuelmax = 60000.0f;
6882  ourcockpit.cockpitArmKm.x = 0.0f; // left offset of center of cockpit
6883  ourcockpit.cockpitArmKm.y = 0.0f; // up
6884  ourcockpit.cockpitArmKm.z = 0.0f; // fwd
6885  ourcockpit.rooftoCG = 0.0f;
6886  ourcockpit.strutsrettoCG = 0.0f;
6887  ourcockpit.strutlength = 0.0f;
6888  // All of these must go through the spreadsheet
6889  ourcockpit.f28 = 3.542405185f; // side drag coefficient
6890  ourcockpit.f20FrontBackDragCoeff = 2.568257887f; // front/rear drag coefficient
6891  ourcockpit.f27 = 14.53457189f; // top/bottom drag coefficient
6892  ourcockpit.f25 = 0.172558f; // landing gear extended adjustment
6893  ourcockpit.d65wasd61 = 14.44276701f; // roll drag Cx
6894  ourcockpit.e65wase61 = 7.755528f; // roll drag arm (m)
6895  ourcockpit.i66wasi62 = 91.99259518f; // ft² at m asym pitch body
6896  ourcockpit.k66wask62 = 158.1099498f; // ft² at m asym pitch htail
6897  ourcockpit.i65wasi61 = 126.5371507f; // ft² at m asym yaw body
6898  ourcockpit.k65wask61 = 111.2692687f; // ft² at m asym yaw vtail
6899  OutsideView(false);
6900  }
6901  break;
6902  // ourcockpit.exteriorInsulationHeatTransferCoefficient = 0.2f; // acrylic glass
6903  // ourcockpit.exteriorInsulationHeatTransferCoefficient = 0.33f; // polymer, low-density
6904  // ourcockpit.exteriorInsulationHeatTransferCoefficient = 0.51f; // Polyethylene, high-density
6905  default:
6906  logger->Log("Unrecognized cockpit type!", Logger::Level::Fatal);
6907  break;
6908  }
6909 
6910  ourcockpit.i12WingAreaOneSideSqFt = ourcockpit.d15TotalWingAreaSqFt * 0.5f; // wing area (one side) ft²
6911  ourcockpit.aileronAreaMod = ourcockpit.h12 / ourcockpit.i12WingAreaOneSideSqFt / 0.25f; // 20% to 30% of MAC
6913  ourcockpit.flapAreaModLE = ourcockpit.j12flapsAreaSqMLE * 10.764f / ourcockpit.d15TotalWingAreaSqFt / 0.25f; // 20% to 30% of MAC
6914  ourcockpit.flapAreaModTE = ourcockpit.k12flapsAreaSqMTE * 10.764f / ourcockpit.d15TotalWingAreaSqFt / 0.25f; // 20% to 30% of MAC
6915 
6917 
6918  if (ourcockpit.texturelib != playerships[0].type || forceCockpitTextures)
6919  {
6921  {
6924  }
6925  ptrCockpit->Load(DXUTGetD3D9Device());
6926  }
6927 
6928  if (ourcockpit.gndvehicle)
6929  {
6930  ourcockpit.gearshift = -2; // park
6932 
6933  for (int i = 0; i < MAX_ENGINES; i++)
6934  gameclass->bus->EngineThrustLever[i] = 0.1f; // idle
6935 
6936  ourcockpit.clutchhold = 0.0f;
6937  }
6938  else
6939  {
6940  for (int i = 0; i < MAX_ENGINES; i++)
6941  {
6942  // for aircraft, spacecraft https://jira.risetvp.com/view.php?id=236
6943  gameclass->bus->EngineThrustLever[i] = 0.0f;
6944  }
6945  }
6946 
6947 
6948  if (handle == -1)
6949  {
6950  sprintf_s(msg, sizeof(msg), "LoadVehicleProfile() failed to load cockpit DIX for type %i!", playerships[t].type);
6951  logger->Log(msg, Logger::Level::Fatal);
6952  }
6953 
6954  _lseek(handle, 0, SEEK_SET);
6955  _read(handle, &ourcockpit.components, 2);
6956 
6957 
6959  {
6960  SAFE_DELETE(ourcockpit.componentarray);
6961  gameclass->UpdateTrackedResource("ourcockpit.componentarray", 3);
6962  }
6963 
6966  {
6967  sprintf_s(msg, sizeof(msg), "LoadVehicleProfile() Failed to initialize %i component(s) for cockpit %i, type %i", ourcockpit.components, t, playerships[t].type);
6968  logger->Log(msg, Logger::Level::Fatal);
6969  }
6970  else
6971  {
6972  gameclass->AddTrackedResource("ourcockpit.componentarray"); // managed, memory only
6973 
6974  sprintf_s(msg, sizeof(msg), "LoadVehicleProfile() Initialized %i component(s) for cockpit %i, type %i", ourcockpit.components, t, playerships[t].type);
6975  logger->Log(msg);
6976  }
6977 
6978 
6979  short i_temp;
6980  for (short s = 0; s < ourcockpit.components; s++)
6981  {
6982  _lseek(handle, (long)s * 100L + 99L, SEEK_SET); // To 0
6983  _read(handle, &i_temp, 2); // 0
6984  ourcockpit.componentarray[s].startvertex = static_cast<UINT>(i_temp);
6985  _read(handle, &i_temp, 2); // 2
6986  ourcockpit.componentarray[s].primitives = static_cast<UINT>(i_temp);
6987  _read(handle, &ourcockpit.componentarray[s].nominalxyz, 12); // 4
6988  _read(handle, &ourcockpit.componentarray[s].nominalypr, 12); // 16
6989  _read(handle, &ourcockpit.componentarray[s].boundsphere, 4); // 28
6990  _read(handle, &ourcockpit.componentarray[s].extendby, 12); // 32
6991  _read(handle, &ourcockpit.componentarray[s].texture, 2); // 44
6993  {
6994  sprintf_s(msg, sizeof(msg), "Failure, out-of-bounds texture on component %i of cockpit %i: %i", s, ourcockpit.texturelib, ourcockpit.componentarray[s].texture);
6995  logger->Log(msg, Logger::Level::Warn);
6996  }
6997  _read(handle, &ourcockpit.componentarray[s].nominalCG, 12); // 46
6998  _read(handle, &ourcockpit.componentarray[s].type, 1); // 58
6999  _read(handle, &ourcockpit.componentarray[s].speedExtend, 4); // 59
7000  _read(handle, &ourcockpit.componentarray[s].hingeaxis, 12); // 63
7001  _read(handle, &ourcockpit.componentarray[s].hingeCG, 12); // 75
7002  _read(handle, &ourcockpit.componentarray[s].hingeextent, 4); // 87
7003  _read(handle, &ourcockpit.componentarray[s].attachto, 2); // 87
7004 
7005  // Dynamic
7007  }
7008 
7009  _close(handle);
7010  handle = -1;
7011 
7012  switch (playerships[t].type)
7013  {
7014  case VehicleType::C98: _sopen_s(&handle, "Meshes\\MuVERcockpit-construction.DAW", _O_RDONLY | _O_BINARY | _O_SEQUENTIAL, _SH_DENYWR, _S_IWRITE);
7015  break;
7016  case VehicleType::E10: _sopen_s(&handle, "Meshes\\e10cockpit1.DAW", _O_RDONLY | _O_BINARY | _O_SEQUENTIAL, _SH_DENYWR, _S_IWRITE);
7017  break;
7018  case VehicleType::E11: _sopen_s(&handle, "Meshes\\e11cockpit1.DAW", _O_RDONLY | _O_BINARY | _O_SEQUENTIAL, _SH_DENYWR, _S_IWRITE);
7019  break;
7020  case VehicleType::P13: _sopen_s(&handle, "Meshes\\p13-cockpit1.DAW", _O_RDONLY | _O_BINARY | _O_SEQUENTIAL, _SH_DENYWR, _S_IWRITE);
7021  break;
7022  case VehicleType::A4: _sopen_s(&handle, "Meshes\\T-8 Wanderer INT.DAW", _O_RDONLY | _O_BINARY | _O_SEQUENTIAL, _SH_DENYWR, _S_IWRITE);
7023  break;
7024  case VehicleType::C2: _sopen_s(&handle, "Meshes\\C-2 Dasher INT.DAW", _O_RDONLY | _O_BINARY | _O_SEQUENTIAL, _SH_DENYWR, _S_IWRITE);
7025  break;
7026  case VehicleType::T120:
7027  case VehicleType::T121:
7028  _sopen_s(&handle, "Meshes\\T-120 Steerhead-stock INT.DAW", _O_RDONLY | _O_BINARY | _O_SEQUENTIAL, _SH_DENYWR, _S_IWRITE);
7029  break;
7030  case VehicleType::T19: _sopen_s(&handle, "Meshes\\stratomaster_06-hex.DAW", _O_RDONLY | _O_BINARY | _O_SEQUENTIAL, _SH_DENYWR, _S_IWRITE);
7031  break;
7032  case VehicleType::W6Manx: _sopen_s(&handle, "Meshes\\manx-int-hex.DAW", _O_RDONLY | _O_BINARY | _O_SEQUENTIAL, _SH_DENYWR, _S_IWRITE);
7033  break;
7034  case VehicleType::T27: _sopen_s(&handle, "Meshes\\mammoth-int.DAW", _O_RDONLY | _O_BINARY | _O_SEQUENTIAL, _SH_DENYWR, _S_IWRITE);
7035  break;
7036  case VehicleType::Apartment: _sopen_s(&handle, "Meshes\\INT-apartment1.DAW", _O_RDONLY | _O_BINARY | _O_SEQUENTIAL, _SH_DENYWR, _S_IWRITE);
7037  break;
7038  case VehicleType::C2A: _sopen_s(&handle, "Meshes\\C-2A Dasher INT.DAW", _O_RDONLY | _O_BINARY | _O_SEQUENTIAL, _SH_DENYWR, _S_IWRITE);
7039  break;
7040  case VehicleType::SimBay: _sopen_s(&handle, "Meshes\\SimulatorBay.DAW", _O_RDONLY | _O_BINARY | _O_SEQUENTIAL, _SH_DENYWR, _S_IWRITE);
7041  break;
7042  case VehicleType::ControlTower: _sopen_s(&handle, "Meshes\\controltower.DAW", _O_RDONLY | _O_BINARY | _O_SEQUENTIAL, _SH_DENYWR, _S_IWRITE);
7043  break;
7044  default:
7045  logger->Log("Should not have gotten here, no valid LoadVehicleProfile type", Logger::Fatal);
7046  break;
7047  }
7048  if (handle == -1)
7049  {
7050  char strerr[99];
7051  strerror_s(strerr, 99, errno);
7052  sprintf_s(msg, sizeof(msg), "Could not load cockpit (DAW file %i) number %i: %s", playerships[t].type, 5, strerr);
7053  logger->Log(msg, Logger::Level::Fatal);
7054  }
7055 
7056  // Vertices -----------------------------------------------------------------------------
7057  _lseek(handle, 0L, SEEK_SET);
7058  _read(handle, &polyobjects[5].vertices, 2);
7060 
7061  sprintf_s(msg, sizeof(msg), "Loading file (%i vertices) for polygon object number %i...", polyobjects[5].vertices, 5);
7062  logger->Log(msg);
7063 
7064  if (polyobjects[5].vertices > cockpitvertC)
7065  {
7066  sprintf_s(msg, sizeof(msg), "Failure, out-of-bounds number of vertices %i/%i maximum", polyobjects[5].vertices, cockpitvertC);
7067  logger->Log(msg, Logger::Level::Fatal);
7068  }
7069 
7070  D3DVERTEX* vtx;
7071 
7072  // Lock the vertex buffer
7073  V(polyobjects[5].VB->Lock(0, 0, reinterpret_cast<void**>(&vtx), D3DLOCK_DISCARD));
7074 
7075  D3DXVECTOR3 tempnormal;
7076 
7077  for (short s = 0; s < polyobjects[5].vertices; s++)
7078  {
7079  _lseek(handle, 2L + s * 32L + 0L, SEEK_SET);
7080  _read(handle, &tempnormal, 12);
7081  (*vtx).x = tempnormal.x;
7082  (*vtx).y = tempnormal.y;
7083  (*vtx).z = tempnormal.z;
7084 
7085  _lseek(handle, 2L + s * 32L + 12L, SEEK_SET);
7086  _read(handle, &tempnormal, 12);
7087  (*vtx).nx = tempnormal.x;
7088  (*vtx).ny = tempnormal.y;
7089  (*vtx).nz = tempnormal.z;
7090  _lseek(handle, 2L + s * 32L + 24L, SEEK_SET);
7091  _read(handle, &tempnormal.x, 4);
7092  _read(handle, &tempnormal.y, 4);
7093  (*vtx).tu = tempnormal.x;
7094  (*vtx).tv = tempnormal.y;
7095  vtx++;
7096  }
7097 
7098  V(polyobjects[5].VB->Unlock());
7099 
7100  _close(handle);
7101  }
7102 
7103  for (unsigned short s = 0; s < playerships[t].components; s++)
7104  {
7105  // ReSharper disable once CppDefaultCaseNotHandledInSwitchStatement
7106  switch (playerships[t].componentarray[s].type)
7107  {
7108  case 1: // Main gear
7109  case 2: // Nose gear
7110  case 6: // Main wheel
7111  case 9: // Nose wheel
7112  {
7113  playerships[t].componentarray[s].extended = playerships[t].geardown ? 1.0f : 0.0f;
7114  if (t == 0)
7115  {
7116  ourcockpit.gearextent = playerships[t].geardown ? 1.0f : 0.0f;
7117  ourcockpit.sentgearvoice = true;
7118  }
7119  }
7120  break;
7121  case 16: // flaps (TE)
7122  case 68: // flaps (LE)
7123  {
7125  if (t == 0)
7126  {
7130  }
7131  }
7132  break;
7133  case 30: // Bay doors
7134  {
7135  playerships[t].componentarray[s].extended = playerships[t].baydoor ? 1.0f : 0.0f;
7137  }
7138  break;
7139  }
7140  }
7141 
7142  logger->Log("LoadVehicleProfile() done!");
7143 }
unsigned char v
Definition: globals.h:334
#define radiusC
Definition: globals.h:88
float rolltilt
Definition: Viewscreen.h:313
float baydoorextent
Definition: globals.h:572
LPDIRECT3DVERTEXBUFFER9 m_avCloudGrid
Definition: Viewscreen.h:109
#define MAX_RAINDROPS
Definition: globals.h:70
D3DXVECTOR3 position
Definition: globals.h:354
void Undock() const
float Vne
Definition: globals.h:636
float GetCloudCeilingMslKm() const
Definition: weather.cpp:945
#define cockpitvertC
Definition: globals.h:57
float LeadingEdgeFlapsPosition
Definition: Bus.h:326
float ratios[8]
Definition: globals.h:653
float timer[PlotType::PlotTypeEnum]
Definition: globals.h:524
#define firework3C
Definition: globals.h:51
float strutlength
Definition: globals.h:621
#define firework1C
Definition: globals.h:49
bool DismissHelp(int helpId, int nControlID=GUI_UNDERSTOOD)
Scockpit ourcockpit
Definition: globals.cpp:176
#define oneOvergForceKmSSC
Definition: globals.h:91
float yawInput
Definition: Viewscreen.h:237
D3DLIGHT9 sunlight
Definition: Viewscreen.h:217
LPDIRECT3DTEXTURE9 m_pddsWeapon[weaponanimateC]
Definition: Viewscreen.h:136
float dockOffsetKmY
Definition: globals.h:700
D3DXMATRIX matrixBase
Definition: globals.h:491
bool powered
Definition: globals.h:297
void DumpSofTracking()
#define sunbC
Definition: globals.h:99
D3DXVECTOR3 cloudpos
Definition: globals.h:741
short waterloop
Definition: Viewscreen.h:265
bool TurnOffTVM() const
Definition: GameClass.cpp:2243
#define MAX_ENGINES
Definition: Bus.h:14
s_mesh_component * componentarray
Definition: globals.h:497
D3DXVECTOR3 dockingvel
Definition: globals.h:540
D3DXVECTOR3 cockpitArmKm
Definition: globals.h:620
#define MAX_STEPS
Definition: globals.h:74
#define heartanimateC
Definition: globals.h:53
unsigned char primitive
Definition: globals.h:353
UINT flapSettingTE
Definition: Bus.h:56
LPDIRECT3DTEXTURE9 m_pddsKeycard
Definition: Viewscreen.h:168
#define D3DFVF_LOCALGRID2
Definition: globals.h:113
float aileronAreaMod
Definition: globals.h:696
LPDIRECT3DTEXTURE9 m_pddsTransition[transitiontextureC]
Definition: Viewscreen.h:192
LPD3DXFONT m_pFont
Definition: Viewscreen.h:46
float power
Definition: globals.h:608
float yawdeflect
Definition: globals.h:562
float aoiWingRad
Definition: globals.h:683
float steerLimitRadian
Definition: globals.h:563
#define nearplaneC
Definition: globals.h:20
struct Bus::Afcs AFCS
D3DXVECTOR3 D3DXVec3Qerp(D3DXVECTOR3 *vel0, D3DXVECTOR3 *vel1, D3DXVECTOR3 *vel2, float t) const
float targetLeftright
Definition: Viewscreen.h:311
char tires
Definition: globals.h:625
#define transitiontextureC
Definition: globals.h:37
float y
Definition: globals.h:208
#define farplaneC
Definition: globals.h:18
Definition: globals.h:782
LPD3DXRENDERTOSURFACE m_pRenderToSurfaceNextGen
Definition: Viewscreen.h:206
#define landformtextureC
Definition: globals.h:36
D3DXVECTOR3 gravityacc
Definition: globals.cpp:100
short heartloop
Definition: Viewscreen.h:265
float tv
Definition: globals.h:208
D3DXVECTOR3 posnorml
Definition: Viewscreen.h:248
bool g_bAboveClouds
Definition: globals.cpp:22
Sani aniarray[MAX_ANI][MAX_STEPS]
Definition: globals.cpp:187
D3DXVECTOR3 position
Definition: Viewscreen.h:247
std::vector< Command > commandStream
Definition: Bus.h:342
float e65wase61
Definition: globals.h:635
#define D3DFVF_LOCALGRID
Definition: globals.h:112
LPDIRECT3DTEXTURE9 m_pddsCityTexture[citytextureC]
Definition: Viewscreen.h:188
D3DXVECTOR3 position
Definition: globals.h:549
LPDIRECT3DTEXTURE9 m_pddsFirework1[firework1C]
Definition: Viewscreen.h:141
int revision
Definition: gui.h:788
#define cloudTopsMslC
Definition: globals.h:92
char causechain
Definition: Viewscreen.h:241
unsigned short rtscomponents
Definition: globals.h:456
void OnLostDevice()
LPDIRECT3DTEXTURE9 m_pddsDockTexture[docktextureC]
Definition: Viewscreen.h:184
LPDIRECT3DTEXTURE9 m_pddsCockpitTexture[cockpittextureC]
Definition: Viewscreen.h:162
#define citytextureC
Definition: globals.h:42
GameClass * gameclass
Definition: Viewscreen.h:292
unsigned char rotation
Definition: globals.h:435
GameState displaystage
Definition: GameClass.h:121
short scanDisplayVesselLimit
Definition: globals.h:702
unsigned char type
Definition: globals.h:406
float k65wask61
Definition: globals.h:635
float i65wasi61
Definition: globals.h:635
unsigned char roads
Definition: globals.h:291
std::vector< int > flapSettings
Definition: globals.h:656
unsigned char zone
Definition: globals.h:291
VECTOR2SHORT CalculateWrap(short u, short v, char cube, char *rotate) const
LPDIRECT3DTEXTURE9 m_pddsSinker[weaponanimateC]
Definition: Viewscreen.h:137
LPDIRECT3DTEXTURE9 m_pddsWorld2a1
Definition: Viewscreen.h:124
unsigned short startindex
Definition: globals.h:333
HRESULT OnCreateDevice(IDirect3DDevice9 *pd3dDevice)
Definition: Viewscreen.cpp:418
long layout2
Definition: globals.h:293
enum Bus::Afcs::LateralModes CurrentLateralMode
float h6ElevatorSqFt
Definition: globals.h:633
void SendToServer(void *pData, DWORD dwSize, bool bGuaranteed, PacketOrdering order=ORDERING_NONE) const
Definition: Networking.cpp:59
LPDIRECT3DTEXTURE9 m_pddsIntersection
Definition: Viewscreen.h:198
char startcycle
Definition: globals.h:608
short projecttexture
Definition: globals.h:612
float tireRotationRadians
Definition: globals.h:573
bool g_bRoad
Definition: globals.cpp:20
char bays
Definition: globals.h:627
unsigned char BCLobjC
Definition: globals.cpp:28
float serviceCeilingKm
Definition: globals.h:631
float i48CriticalEngineYawArmM
Definition: globals.h:639
float b15WingPitchArmM
Definition: globals.h:634
int flapMaxDegrees
Definition: globals.h:692
bool wheeled
Definition: globals.h:605
LPDIRECT3DTEXTURE9 m_pddsCloudBaseMap
Definition: Viewscreen.h:125
LPDIRECT3DTEXTURE9 m_pddsNamePlate
Definition: Viewscreen.h:156
D3DXVECTOR3 terpos
Definition: globals.h:449
float i12WingAreaOneSideSqFt
Definition: globals.h:633
renderer * ptrRenderer
Definition: Viewscreen.h:286
LPDIRECT3DTEXTURE9 m_pddsHolidayTexture
Definition: Viewscreen.h:134
LPD3DXFONT m_pFontHull
Definition: Viewscreen.h:49
LPDIRECT3DTEXTURE9 m_pddsCityLights[citytextureC]
Definition: Viewscreen.h:189
LPDIRECT3DTEXTURE9 m_pddsAOA[3]
Definition: Viewscreen.h:161
#define dockvertC
Definition: globals.h:58
#define D3DFVF_RAINDROP
Definition: globals.h:104
float f_Uphours
Definition: globals.cpp:25
VECTOR2SHORT CalculateCGC(D3DXVECTOR3 position, char cube) const
InformationDialog * informationDialog
Definition: gui.h:789
float x
Definition: globals.h:238
bool visiblegrid[63][63]
Definition: Viewscreen.h:263
void AutopilotDisconnect() const
Definition: GameClass.cpp:2233
VECTOR2SHORT bump
Definition: globals.cpp:140
LPDIRECT3DTEXTURE9 m_pddsGVDirection
Definition: Viewscreen.h:158
instruments * ptrInstruments
Definition: Viewscreen.h:289
void Movement(short t, float ElapsedTime)
unsigned long compare
Definition: globals.h:505
bool geometryReady
Definition: grid.h:30
unsigned short vehicleId
Definition: globals.h:570
double precisiony
Definition: globals.h:550
FIREWORKS fireworks[fireworksC]
Definition: globals.cpp:181
D3DXVECTOR3 position
Definition: globals.h:280
float c9WingYawArmM
Definition: globals.h:634
float verticalincr
Definition: Viewscreen.h:252
s_network_objects playerships[MAX_SCAN]
Definition: globals.cpp:174
LPD3DXRENDERTOSURFACE m_pHullRender2Surface
Definition: Viewscreen.h:207
waypoints * ptrWaypoints
Definition: Viewscreen.h:290
float speedRetract
Definition: globals.h:412
LPDIRECT3DVERTEXBUFFER9 m_avLocalGrid
Definition: Viewscreen.h:111
float tu
Definition: globals.h:208
float d16HTailWithElevatorSqFt
Definition: globals.h:634
short texturelib
Definition: globals.h:612
float f25
Definition: globals.h:633
unsigned char ourmoonC
Definition: globals.cpp:27
long FontOffset(char letter) const
float flapAreaModLE
Definition: globals.h:693
LPDIRECT3DTEXTURE9 m_pddsWaterNormal
Definition: Viewscreen.h:193
float ProbeBoundSphere(D3DXVECTOR3 *position, const D3DXVECTOR3 *Xsunlight) const
float RadioAltitudeKm
Definition: Bus.h:134
float leftright
Definition: Viewscreen.h:311
float rollInput
Definition: Viewscreen.h:237
#define shiptextureC
Definition: globals.h:38
float assayProgressU
Definition: Bus.h:387
const D3DXVECTOR3 meridian
float weapontimer[2]
Definition: globals.cpp:142
float EmptyWeightLbs
Definition: Bus.h:361
weapon * ptrWeapon
Definition: Viewscreen.h:280
#define starsC
Definition: globals.h:66
float Vs1
Definition: globals.h:636
float g_fFOV
Definition: globals.cpp:129
#define dihvanimateC
Definition: globals.h:52
void ClearGrid()
Definition: grid.cpp:59
float momentr
Definition: globals.h:632
float updown
Definition: Viewscreen.h:312
float lateralincr
Definition: Viewscreen.h:251
LPDIRECT3DTEXTURE9 m_pddsSunglasses
Definition: Viewscreen.h:131
float machAngleDragScalar
Definition: globals.h:713
float f_compareFOV
Definition: globals.cpp:130
#define runninglightsC
Definition: globals.h:41
float distance
Definition: globals.h:738
std::vector< s_light_effect > effects
Definition: globals.h:447
void OnCreateDevice(IDirect3DDevice9 *pd3dDevice)
float H2Ooffsetu
Definition: Viewscreen.h:267
float extended
Definition: globals.h:427
D3DVERTEX * vertexbackup
Definition: globals.h:345
bool m_bDeviceSupportsVizQuery
Definition: Viewscreen.h:224
int sonicBooms
Definition: globals.h:714
LPD3DXSPRITE m_spriteVector
Definition: Viewscreen.h:214
int major
Definition: gui.h:785
s_city_stuff citystuff
Definition: globals.cpp:172
LPDIRECT3DTEXTURE9 m_pddsMarston1
Definition: Viewscreen.h:195
float end
Definition: globals.h:785
D3DXMATRIX matrixProj
Definition: Viewscreen.h:219
float interlace
Definition: Viewscreen.h:270
LPDIRECT3DVERTEXBUFFER9 m_avLightning
Definition: Viewscreen.h:119
Definition: weapon.h:11
LPDIRECT3DTEXTURE9 m_pddsGVDialSmall
Definition: Viewscreen.h:154
Viewscreen(GameClass *)
Definition: Viewscreen.cpp:6
LPDIRECT3DTEXTURE9 m_pddsLightningAbove[3]
Definition: Viewscreen.h:177
LPDIRECT3DVERTEXBUFFER9 VB
Definition: globals.h:366
float levelerpitch
Definition: globals.cpp:12
#define weaponanimateC
Definition: globals.h:44
float ffmax
Definition: globals.h:637
float boundsphere
Definition: globals.h:413
float b9DistanceToVTailM
Definition: globals.h:634
short scanslot[MAX_SCAN]
Definition: Viewscreen.h:276
unsigned char pri_landform
Definition: globals.h:284
float f27
Definition: globals.h:633
s_mesh_component * componentarray
Definition: globals.h:678
weather * ptrWeather
Definition: Viewscreen.h:287
LPD3DXFONT m_pFont3
Definition: Viewscreen.h:48
void SendEvent(EventType eventType, float extent=0.0f) const
Definition: Networking.cpp:111
unsigned char u
Definition: globals.h:334
bool verticalmod
Definition: Viewscreen.h:244
#define sungC
Definition: globals.h:98
D3DXVECTOR3 nominalCG
Definition: globals.h:419
#define cityscaleC
Definition: globals.h:26
LPDIRECT3DVERTEXBUFFER9 m_avStaticStars
Definition: Viewscreen.h:101
LPDIRECT3DVOLUMETEXTURE9 m_pddsReentry
Definition: Viewscreen.h:150
bool sentgearvoice
Definition: globals.h:623
float DesiredRollRadians
Definition: Bus.h:116
float lookhdg
Definition: Viewscreen.h:234
float CheckRtsBumpMap(VECTOR2SHORT rts, VECTOR2SHORT bump, short u, short v)
void ApplyEnvironmentMap()
LPDIRECT3DTEXTURE9 m_pddsRunwayEdgeLight1
Definition: Viewscreen.h:196
float turnin
Definition: globals.h:661
float steerLimitRadian
Definition: globals.h:641
float curbelev
Definition: globals.h:518
float f28
Definition: globals.h:633
char buffer3[16384]
Definition: globals.cpp:168
float wingspanM
Definition: globals.h:635
Logger * logger
Definition: GameClass.h:113
unsigned char sec_landform
Definition: globals.h:286
Sani GetAni(float f_time, unsigned char ani) const
std::vector< s_light_effect > effects
Definition: globals.h:367
float VcMSL
Definition: globals.h:636
LPDIRECT3DTEXTURE9 m_pddsFirework2[firework2C]
Definition: Viewscreen.h:142
char area[3]
Definition: globals.cpp:139
joystick * ptrJoystick
Definition: Viewscreen.h:283
PlotType type
Definition: globals.h:282
void OnDestroyDevice()
double terprecisionx
Definition: Viewscreen.h:235
float d15TotalWingAreaSqFt
Definition: globals.h:695
unsigned char pri_transition
Definition: globals.h:285
D3DXVECTOR3 groundpos
Definition: globals.h:741
LPDIRECT3DTEXTURE9 m_pddsElmo[elmoAnimateC]
Definition: Viewscreen.h:144
float CheckDepthMap(VECTOR2SHORT newdepthpos, short u, short v)
D3DXVECTOR3 Debug2Vec3
Definition: Bus.h:418
float start
Definition: globals.h:784
unsigned long sequencing
Definition: globals.h:356
RTSGRID * rts
Definition: globals.h:459
float moving
Definition: globals.h:660
float d17VTailWithRudderSqFt
Definition: globals.h:633
#define drawlistC
Definition: globals.h:55
D3DXVECTOR3 veliter
Definition: globals.h:541
float engineCriticalAltitude
Definition: globals.h:690
std::string name
Definition: Command.h:11
D3DXVECTOR3 nominalypr
Definition: globals.h:417
float fuelmax
Definition: globals.h:637
const D3DXVECTOR3 northpoleC
float impatientime
Definition: globals.h:662
unsigned char UCLobjC
Definition: globals.cpp:29
#define gravityC
Definition: globals.h:89
float j12flapsAreaSqMLE
Definition: globals.h:709
float speedLimiterKph
Definition: globals.h:712
unsigned char primitives
Definition: globals.h:337
#define maxcomparebitC
Definition: globals.h:62
s_mesh_component * componentarray
Definition: globals.h:578
char fwdgears
Definition: globals.h:652
float nx
Definition: globals.h:208
double terprecisionz
Definition: Viewscreen.h:235
float h9RudderSqFt
Definition: globals.h:633
D3DXVECTOR3 terpos
Definition: Viewscreen.h:233
unsigned char bay
Definition: globals.h:548
#define fireworksC
Definition: globals.h:746
float targetUpdown
Definition: Viewscreen.h:312
unsigned char sec_transition
Definition: globals.h:287
propulsion * ptrPropulsion
Definition: Viewscreen.h:285
bool useLightMap
Definition: globals.h:411
short polygons
Definition: globals.h:365
Definition: grid.h:12
D3DXVECTOR3 ypr[16]
Definition: globals.h:786
void Initialize()
Definition: Viewscreen.cpp:314
LPDIRECT3DSURFACE9 m_pddsProjectionSurface
Definition: Viewscreen.h:204
D3DXCOLOR raster
Definition: globals.h:289
bool TurnOffDOR() const
Definition: GameClass.cpp:2262
float d65wasd61
Definition: globals.h:635
float startupextend
Definition: globals.h:608
float floorelev
Definition: globals.h:518
D3DMATERIAL9 restore
Definition: Viewscreen.h:216
LPDIRECT3DTEXTURE9 m_pddsLandform[landformtextureC]
Definition: Viewscreen.h:191
float momentp
Definition: globals.h:632
#define D3DFVF_NONORMAL
Definition: globals.h:108
float spoolTime
Definition: globals.h:610
bool lateralmod
Definition: Viewscreen.h:244
VECTOR2SHORT rts
Definition: globals.cpp:140
LPDIRECT3DTEXTURE9 m_pddsCloudDetailBelow
Definition: Viewscreen.h:127
float flapExtent
Definition: globals.h:655
s_universe_object allobjects[maxstarC]
Definition: globals.cpp:170
void RequestScannerData() const
Definition: GameClass.cpp:132
void OnLostDevice()
s_mesh_component * componentarray
Definition: globals.h:457
float CheckFloorMap(VECTOR2SHORT newdepthpos, short u, short v)
float elevation
Definition: globals.h:517
LPDIRECT3DTEXTURE9 m_pddsDockLights[docktextureC]
Definition: Viewscreen.h:185
D3DXCOLOR diffuse
Definition: globals.h:355
D3DXVECTOR3 leveler
Definition: globals.cpp:8
bool AssertTelemetry(const char *location, short id)
Definition: framemove.cpp:7
D3DXMATRIX matrixWorld
Definition: globals.h:491
short attachto
Definition: globals.h:358
D3DXVECTOR3 posleft
Definition: globals.h:541
float rolldeflect
Definition: globals.h:562
bool gridvisible[63][63]
Definition: Viewscreen.h:262
#define elmoAnimateC
Definition: globals.h:45
long layout4
Definition: globals.h:293
void TriggerBCLLightning(float distanceScalar, float intensityScalar) const
LPDIRECT3DVOLUMETEXTURE9 m_pddsFuzerX
Definition: Viewscreen.h:138
Networking * networking
Definition: GameClass.h:107
keyboard * ptrKeyboard
Definition: Viewscreen.h:282
bool PopUpHelp(short helpId, bool allowDismiss=true, bool isLearnMore=false)
#define D3DFVF_INSTRUMENT
Definition: globals.h:110
LPDIRECT3DVERTEXBUFFER9 m_avCone
Definition: Viewscreen.h:102
const D3DXVECTOR3 eastpole
buildings * ptrBuildings
Definition: Viewscreen.h:281
LIGHTNINGBELOW lightningbelow
Definition: globals.cpp:179
double terprecisiony
Definition: Viewscreen.h:235
float x
Definition: globals.h:208
float f_MSL
Definition: globals.cpp:36
D3DXVECTOR3 sumofforces
Definition: globals.cpp:103
double precisionx
Definition: globals.h:550
float Clamp(float val, float min, float max)
Definition: MathUtilities.h:3
D3DXVECTOR3 rainarray[MAX_RAINDROPS]
Definition: Viewscreen.h:259
float tireRadiusKm
Definition: globals.h:710
#define D3DFVF_SKYDOME
Definition: globals.h:103
std::vector< std::string > sofTracking
Definition: Viewscreen.h:51
D3DXVECTOR3 xyz
Definition: globals.h:787
D3DXVECTOR3 nominalxyz
Definition: globals.h:416
bool vdatChanged
Definition: globals.h:670
float appitagr
Definition: globals.h:638
short screentexture
Definition: globals.h:612
#define docktextureC
Definition: globals.h:40
float rcsThrustOutputY
Definition: Viewscreen.h:238
BATCHINDEX2 drawlist[drawlistC]
Definition: globals.cpp:156
LPDIRECT3DVERTEXBUFFER9 m_avScreen
Definition: Viewscreen.h:117
float speedExtend
Definition: globals.h:412
D3DXVECTOR3 CalculatePlanar(short u, short v)
float assayProgressV
Definition: Bus.h:387
LPDIRECT3DTEXTURE9 m_pddsLetters
Definition: Viewscreen.h:174
char engines
Definition: globals.h:627
float dockOffsetKmZ
Definition: globals.h:699
long layout1
Definition: globals.h:293
void KillScannerData() const
Definition: GameClass.cpp:125
float k66wask62
Definition: globals.h:635
float pitchInput
Definition: Viewscreen.h:237
float CalculateAGL(short u, short v, D3DXVECTOR3 position, bool makeleveler)
float engineEfficiencyAtSeaLevelScalar
Definition: globals.h:715
LPDIRECT3DVERTEXBUFFER9 m_avRainDrops
Definition: Viewscreen.h:114
unsigned long compare[PlotType::PlotTypeEnum]
Definition: globals.h:523
D3DXMATRIX matrixProjnodistort
Definition: Viewscreen.h:219
float verticaltime
Definition: Viewscreen.h:243
char msg[199]
Definition: Viewscreen.h:33
#define depthFloorResolutionC
Definition: Viewscreen.h:28
D3DXMATRIX matrixProjCock
Definition: Viewscreen.h:219
D3DXMATRIX matrixProjSim
Definition: Viewscreen.h:219
bool spaceCapable
Definition: globals.h:605
void OnLostDevice() const
Definition: cockpit.cpp:1104
BUILDZONE buildzone[buildingVBC]
Definition: globals.cpp:165
LPDIRECT3DTEXTURE9 m_pddsSunTexture
Definition: Viewscreen.h:132
float exteriorInsulationHeatTransferCoefficient
https://en.wikipedia.org/wiki/List_of_thermal_conductivities
Definition: globals.h:706
float dockingOrientationZ
Definition: globals.h:701
Definition: Command.h:5
void Load(IDirect3DDevice9 *pd3dDevice) const
Definition: cockpit.cpp:14
short attachto
Definition: globals.h:407
LPDIRECT3DVOLUMETEXTURE9 m_pddsSinkerX
Definition: Viewscreen.h:139
float noseWheelToCgKm
Definition: globals.h:640
float pitchdeflect
Definition: globals.h:562
VECTOR2SHORT newdepthpos
Definition: globals.cpp:140
float h12
Definition: globals.h:633
#define visiblevertC
Definition: globals.h:56
char hullname[23]
Definition: globals.h:535
unsigned short components
Definition: globals.h:624
float clutchtime
Definition: globals.h:651
enum Bus::Afcs::VerticalModes CurrentVerticalMode
D3DXCOLOR clouddif
Definition: globals.h:281
LPDIRECT3DTEXTURE9 m_pddsShipLights[shiptextureC]
Definition: Viewscreen.h:183
float uptranslimit
Definition: globals.h:610
float lrtranslimit
Definition: globals.h:610
D3DXVECTOR3 velocity
Definition: globals.cpp:9
float l48AverageEnginePitchArmM
Definition: globals.h:691
const D3DXVECTOR3 centerC
D3DXVECTOR3 insidearray[63][63][3]
Definition: globals.cpp:154
float rooftoCG
Definition: globals.h:622
LPDIRECT3DTEXTURE9 m_pddsDynamicTexture
Definition: Viewscreen.h:201
LOCALGRID2 CalculateSRV(short t, short s, VECTOR2SHORT tcp, char cube, SRenderVertex sourcedata)
float TrailingEdgeFlapsPosition
Definition: Bus.h:324
#define skydomeC
Definition: globals.h:77
D3DXVECTOR3 velocity
Definition: globals.h:540
Sound * sound
Definition: GameClass.h:108
float i66wasi62
Definition: globals.h:635
float nz
Definition: globals.h:208
#define RTStextureC
Definition: globals.h:43
float b6DistanceToHTailM
Definition: globals.h:634
D3DXMATRIX matrixWorld
Definition: globals.h:555
short buildzoneOrdinal
Definition: globals.h:292
float GetAttenuation(bool applyDensity) const
Definition: Sound.cpp:1062
float z
Definition: globals.h:208
float tireCircumferenceKm
Definition: globals.h:563
void LoadVehicleProfile(short t, bool forceCockpitTextures=false)
float timeleft
Definition: globals.h:737
static D3DXVECTOR3 CalculateBarycentric(D3DXVECTOR3 *position, D3DXVECTOR3 *gthrust, float *radius)
D3DXVECTOR3 extendby
Definition: globals.h:422
D3DXVECTOR3 velleft
Definition: globals.h:541
LPDIRECT3DTEXTURE9 m_pddsLightsCruiseIcons
Definition: Viewscreen.h:159
void Log(const char *msg, Level level=Info, int errorCode=0)
Definition: Logger.cpp:11
grid * ptrGrid
Definition: Viewscreen.h:279
void OutsideView(bool outside)
Definition: framemove.cpp:254
unsigned char ter_landform
Definition: globals.h:288
unsigned long compare
Definition: globals.h:552
s_polygon_object polyobjects[maxpolyC]
Definition: globals.cpp:160
D3DXVECTOR3 Debug1Vec3
Definition: Bus.h:417
LPDIRECTINPUT8 g_pDI
Definition: Viewscreen.h:96
short vertices
Definition: globals.h:365
#define D3DFVF_SCREEN
Definition: globals.h:109
float gearextent
Definition: globals.h:621
#define D3DFVF_STATICSTARS
Definition: globals.h:106
#define cockpittextureC
Definition: globals.h:39
LPDIRECT3DTEXTURE9 m_pddsBinoculars
Definition: Viewscreen.h:128
D3DXVECTOR3 dockMarker
Definition: globals.cpp:46
LPDIRECT3DTEXTURE9 m_pddsFuelIcon
Definition: Viewscreen.h:160
LPDIRECT3DVERTEXBUFFER9 m_avInstrument
Definition: Viewscreen.h:118
#define firework2C
Definition: globals.h:50
float strutsrettoCG
Definition: globals.h:622
LPDIRECT3DVERTEXBUFFER9 m_avSkyRing
Definition: Viewscreen.h:116
LPDIRECT3DTEXTURE9 m_pddsShipTexture[shiptextureC]
Definition: Viewscreen.h:182
#define D3DFVF_SKYRING
Definition: globals.h:105
D3DXVECTOR3 headlight
Definition: globals.h:613
#define maxstarC
Definition: globals.h:24
LPDIRECT3DTEXTURE9 m_pddsBinocularsCompass
Definition: Viewscreen.h:129
LPD3DXRENDERTOSURFACE m_pRenderToSurface
Definition: Viewscreen.h:205
float levelerroll
Definition: globals.cpp:13
float deathinhibit
Definition: globals.cpp:51
#define MAX_ANI
Definition: globals.h:73
int minor
Definition: gui.h:786
float aprolagr
Definition: globals.h:638
#define maxdockC
Definition: globals.h:25
bool yawmod
Definition: Viewscreen.h:244
float maxGrossLbs
Definition: globals.h:630
#define cockplanenearC
Definition: globals.h:21
unsigned char type
Definition: globals.h:532
float totalWeightLbs
Definition: propulsion.h:73
s_polygon_extras2 polyextras2
Definition: Viewscreen.h:255
LPDIRECT3DVOLUMETEXTURE9 m_pddsBlastX
Definition: Viewscreen.h:140
D3DXVECTOR3 cloudpos
Definition: globals.h:280
void OnDestroyDevice()
bool dataReady
Definition: grid.h:29
float elevatorAreaMod
Definition: globals.h:697
#define maxpolyC
Definition: globals.h:23
LPDIRECT3DTEXTURE9 m_pddsAtmosphere
Definition: Viewscreen.h:178
void SetProjectionMatrices()
LPDIRECT3DTEXTURE9 m_pddsRoad
Definition: Viewscreen.h:197
float Vs2
Definition: globals.h:636
float hingeextent
Definition: globals.h:424
LPDIRECT3DTEXTURE9 m_pddsCockpitLights[cockpittextureC]
Definition: Viewscreen.h:163
float g_UniverseTime
Definition: globals.cpp:24
float strutabsorb
Definition: globals.h:621
D3DXVECTOR3 gravityvec
Definition: globals.cpp:98
D3DXVECTOR3 cloudpos
Definition: Viewscreen.h:258
#define maxcompareC
Definition: globals.h:61
float x
Definition: globals.h:218
float CalculateAGLd(D3DXVECTOR3 terpos, double terprecisionx, double terprecisiony, double terprecisionz, double proposedx, double proposedy, double proposedz, D3DXVECTOR3 proposed, bool makeleveler)
HMI * GUI
Definition: GameClass.h:110
D3DXVECTOR3 positer
Definition: globals.h:541
D3DLIGHT9 headlight
Definition: Viewscreen.h:217
UINT startvertex
Definition: globals.h:408
char CalculateCube(D3DXVECTOR3 position) const
LPDIRECT3DSURFACE9 m_pddsDynamicSurface
Definition: Viewscreen.h:202
float intensity
Definition: globals.h:738
float fAspect
Definition: Viewscreen.h:218
float power
Definition: globals.h:357
bool makeClouds
Definition: grid.h:33
long layout3
Definition: globals.h:293
float dockprogress
Definition: globals.cpp:44
short elevation
Definition: globals.h:294
float revthrustlimit
Definition: globals.h:610
LPDIRECT3DQUERY9 m_pLightSunVizQuery
Definition: Viewscreen.h:225
bool g_bStrapon
Definition: globals.cpp:42
float speed
Definition: globals.h:357
void OnResetDevice(IDirect3DDevice9 *pd3dDevice, const D3DSURFACE_DESC *pBackBufferSurfaceDesc)
float scandist[MAX_SCAN]
Definition: Viewscreen.h:277
short index[4500]
Definition: globals.h:347
bool CheckPlotRoads(float f_tempu, float f_tempv)
void AddTrackedResource(const char *name, _D3DPOOL pool=D3DPOOL_MANAGED)
Definition: GameClass.cpp:2702
float ny
Definition: globals.h:208
unsigned short components
Definition: globals.h:496
short BCLoffsetu
Definition: Viewscreen.h:266
#define cockplanefarC
Definition: globals.h:22
LOCALGRID2 gridarray[64][64]
Definition: globals.cpp:153
float rcsYParmM
Definition: globals.h:635
#define ACLlightningC
Definition: globals.h:71
LPDIRECT3DTEXTURE9 m_pddsCloudDetailAbove
Definition: Viewscreen.h:126
FreeTrack * ptrFreeTrack
Definition: Viewscreen.h:284
int build
Definition: gui.h:787
cockpit * ptrCockpit
Definition: Viewscreen.h:288
LPDIRECT3DTEXTURE9 m_pddsRTSTexture[RTStextureC]
Definition: Viewscreen.h:186
LPDIRECT3DTEXTURE9 m_pddsLightningBelow[3]
Definition: Viewscreen.h:176
float Vr
Definition: globals.h:636
#define D3DFVF_VERTEX
Definition: globals.h:101
void Stop(int soundEnum)
Definition: Sound.cpp:1946
LPDIRECT3DTEXTURE9 m_pddsGVCompass
Definition: Viewscreen.h:157
D3DXVECTOR3 barycentric
Definition: globals.h:540
short BCLoffsetv
Definition: Viewscreen.h:266
static bool CheckLayout(unsigned i, LOCALGRID2 localgrid2)
Definition: buildings.cpp:16
#define cloudTopsRadiusC
Definition: globals.h:94
LPDIRECT3DTEXTURE9 m_pddsInterlace[2]
Definition: Viewscreen.h:167
float momenty
Definition: globals.h:632
LPDIRECT3DTEXTURE9 m_pddsDIHV[dihvanimateC]
Definition: Viewscreen.h:148
float x
Definition: globals.h:258
float delay
Definition: Command.h:8
LPDIRECT3DTEXTURE9 m_pddsHeart[heartanimateC]
Definition: Viewscreen.h:149
unsigned char ourstarC
Definition: globals.cpp:30
void PlayEx(int soundEnum, bool loop, float volume=1.0f, float frequencyMod=1.0f, float pan=0.0f, bool restart=true)
Definition: Sound.cpp:606
short texture
Definition: globals.h:740
unsigned short components
Definition: globals.h:456
D3DXVECTOR4 gammascreen
Definition: Viewscreen.h:232
bool gndvehicle
Definition: globals.h:604
float k12flapsAreaSqMTE
Definition: globals.h:708
void UpdateTrackedResource(const char *name, int status)
Definition: GameClass.cpp:2725
void AddToCallStack(const char *msg)
Definition: Logger.cpp:86
Bus * bus
Definition: GameClass.h:112
HRESULT OnResetDevice(IDirect3DDevice9 *pd3dDevice, const D3DSURFACE_DESC *pBackBufferSurfaceDesc)
bool nextgen
Definition: globals.h:680
LPDIRECT3DINDEXBUFFER9 m_aiCloudGrid
Definition: Viewscreen.h:108
VECTOR2SHORT tcp
Definition: globals.h:296
LPD3DXFONT m_pFontLicense
Definition: Viewscreen.h:47
unsigned short causearray
Definition: Viewscreen.h:242
D3DXVECTOR3 hingeCG
Definition: globals.h:423
float clutchhold
Definition: globals.h:651
float speed[PlotType::PlotTypeEnum]
Definition: globals.h:524
#define sunrC
Definition: globals.h:97
float pitchLimitRadians
Definition: globals.h:711
float lateraltime
Definition: Viewscreen.h:243
D3DXVECTOR3 normal
Definition: globals.h:354
float fwdthrustlimit
Definition: globals.h:610
bool makeBuildings
Definition: grid.h:32
float ffidle
Definition: globals.h:637
LPDIRECT3DTEXTURE9 m_pddsRTSLights[RTStextureC]
Definition: Viewscreen.h:187
float f20FrontBackDragCoeff
Definition: globals.h:633
D3DXVECTOR3 position
Definition: globals.h:493
LPDIRECT3DVERTEXBUFFER9 m_avRunningLights
Definition: Viewscreen.h:107
#define cloudindicesC
Definition: globals.h:59
char gearshift
Definition: globals.h:652
D3DXVECTOR3 hingeaxis
Definition: globals.h:423
float dntranslimit
Definition: globals.h:610
float RandomFloat()
Definition: MathUtilities.h:98
float emptyWeightLbs
Definition: globals.h:629
char buffer2[16384]
Definition: globals.cpp:162
Logger * logger
Definition: Viewscreen.h:293
double precisionz
Definition: globals.h:550
bool inhibitvisibility
Definition: globals.h:565
float flapAreaModTE
Definition: globals.h:694
float b12WingRollArmM
Definition: globals.h:634
D3DXCOLOR specular
Definition: globals.h:281
LPDIRECT3DTEXTURE9 m_pddsProjectionTexture
Definition: Viewscreen.h:203
char steerTires
Definition: globals.h:625
unsigned char ourplanetC
Definition: globals.cpp:31
LPDIRECT3DVERTEXBUFFER9 m_avSkyDome
Definition: Viewscreen.h:115
LPDIRECT3DTEXTURE9 m_pddsBinocularsArrow
Definition: Viewscreen.h:130
LPDIRECT3DTEXTURE9 m_pddsHullDynamicTexture[MAX_SCAN]
Definition: Viewscreen.h:209
LPDIRECT3DTEXTURE9 m_pddsFirework3[firework3C]
Definition: Viewscreen.h:143
#define D3DFVF_NOPSIZE
Definition: globals.h:107
char buffer1[16384]
Definition: globals.cpp:158
D3DXVECTOR3 center[4500]
Definition: globals.h:346
void OnResetDevice(IDirect3DDevice9 *pd3dDevice) const
Definition: cockpit.cpp:1197
D3DXVECTOR3 dockoffset
Definition: globals.h:549
unsigned short components
Definition: globals.h:577
float f_AGL
Definition: globals.cpp:14
float EngineThrustLever[MAX_ENGINES]
Definition: Bus.h:264
char flicker
Definition: Viewscreen.h:269
LPDIRECT3DVERTEXBUFFER9 m_avSunVertices
Definition: Viewscreen.h:103
SVesselDC vdat
Definition: globals.h:669
LPDIRECT3DTEXTURE9 m_pddsStarTexture
Definition: Viewscreen.h:133
LPDIRECT3DTEXTURE9 m_pddsGVBackground
Definition: Viewscreen.h:155