Rise
The Vieneo Province
keyboard.cpp
Go to the documentation of this file.
1 #include "keyboard.h"
2 #include "Viewscreen.h"
3 #include "../Dialogs/InformationDialog.h"
4 #include "../MathUtilities.h"
5 
7 {
8  viewscreen = ptr;
9  logger = ptr->logger;
10 }
11 
13 {
14  g_pKeyboard->Unacquire();
15  SAFE_RELEASE(g_pKeyboard);
16 }
17 
18 HRESULT keyboard::Initialize(HWND hDlg)
19 {
20  // no way to configure it so it doesn't ever need to be released
21  if (g_pKeyboard)
22  return S_OK;
23 
24  logger->Log("KEYBOARD::Initialize() called...");
25 
26  HRESULT hr;
27 
28  // Obtain an interface to the system keyboard device.
29  if (FAILED(hr = viewscreen->g_pDI->CreateDevice(GUID_SysKeyboard, &g_pKeyboard, NULL)))
30  {
31  logger->Log("CreateDevice() failed!", Logger::Level::Warn);
32  return hr;
33  }
34 
35  // Set the data format to "keyboard format" - a predefined data format
36  //
37  // A data format specifies which controls on a device we
38  // are interested in, and how they should be reported.
39  //
40  // This tells DirectInput that we will be passing an array
41  // of 256 bytes to IDirectInputDevice::GetDeviceState.
42  if (FAILED(hr = g_pKeyboard->SetDataFormat(&c_dfDIKeyboard)))
43  {
44  if (hr == DIERR_ACQUIRED)
45  logger->Log("SetDataFormat() failed: DIERR_ACQUIRED", Logger::Level::Warn); // The operation cannot be performed while the device is acquired.
46  else if (hr == DIERR_INVALIDPARAM)
47  logger->Log("SetDataFormat() failed: DIERR_INVALIDPARAM", Logger::Level::Warn); // An invalid parameter was passed to the returning function, or the object was not in a state that permitted the function to be called. This value is equal to the E_INVALIDARG standard COM return value.
48  else if (hr == DIERR_NOTINITIALIZED)
49  logger->Log("SetDataFormat() failed: DIERR_NOTINITIALIZED", Logger::Level::Warn); // This object has not been initialized.
50  else
51  logger->Log("SetDataFormat() failed: DIERR_UNKNOWN", Logger::Level::Warn);
52  return hr;
53  }
54 
55  // Set the cooperativity level to let DirectInput know how
56  // this device should interact with the system and with other
57  // DirectInput applications.
58  if (FAILED(hr = g_pKeyboard->SetCooperativeLevel(hDlg,
59  DISCL_NONEXCLUSIVE |
60  DISCL_FOREGROUND |
61  DISCL_NOWINKEY)))
62  {
63  logger->Log("SetCooperativeLevel() failed!", Logger::Level::Warn);
64  return hr;
65  }
66 
67  return S_OK;
68 }
69 
71 {
72  ourcockpit.moving = 1.0f; // walk forward (1-5 reserved)
75 }
76 
77 void keyboard::Brake(float f_temp) const
78 {
81  {
84  for (int i = 0; i < MAX_ENGINES; i++)
85  {
86  viewscreen->gameclass->bus->EngineThrustLever[i] -= f_temp;
87  if (viewscreen->gameclass->bus->EngineThrustLever[i] < 0.1f) // engine can't reverse on gv
89  }
90  }
91 }
92 
93 void keyboard::TurnLeft(float f_temp) const
94 {
95  if (viewscreen->gameclass->GUI->player[ourcockpit.ourplyrC].frame) // interior
96  {
97  ourcockpit.turnin = -1.0f; // turn left
100  }
101  else if (playerships[0].reference == REF_ONGROUND)
102  {
103  // * 10 at 0 and * 0 at 200
104  // speed sensitive steering
105  const float mod = powf(1.0f - viewscreen->gameclass->bus->GroundSpeedKms / 0.3f, 2.0f) * 10.0f;
107  viewscreen->yawInput += f_temp * mod;
108  else
109  viewscreen->yawInput -= f_temp * mod;
110  viewscreen->yawInput = Clamp(viewscreen->yawInput, -1.0f, 1.0f);
111 
114  }
115  else
116  {
118  viewscreen->rollInput += f_temp;
119  else
120  viewscreen->rollInput -= f_temp;
121  viewscreen->rollInput = Clamp(viewscreen->rollInput, -1.0f, 1.0f);
122  }
123 }
124 
125 void keyboard::TurnRight(float f_temp) const
126 {
127  if (viewscreen->gameclass->GUI->player[ourcockpit.ourplyrC].frame) // interior
128  {
129  ourcockpit.turnin = 1.0f; // turn right
132  }
133  else if (playerships[0].reference == REF_ONGROUND)
134  {
135  // speed sensitive steering
136  const float mod = powf(1.0f - viewscreen->gameclass->bus->GroundSpeedKms / 0.3f, 2.0f) * 10.0f;
138  viewscreen->yawInput -= f_temp * mod;
139  else
140  viewscreen->yawInput += f_temp * mod;
141  viewscreen->yawInput = Clamp(viewscreen->yawInput, -1.0f, 1.0f);
142 
145  }
146  else
147  {
149  viewscreen->rollInput -= f_temp;
150  else
151  viewscreen->rollInput += f_temp;
152  viewscreen->rollInput = Clamp(viewscreen->rollInput, -1.0f, 1.0f);
153  }
154 }
155 
156 void keyboard::Update(float fElapsedTime)
157 {
159 
161  SetScrollLock(fmodf(static_cast<float>(viewscreen->gameclass->bus->ProgramTime), 2.0f) > 1.0f);
162  else
163  SetScrollLock(false);
164 
166  return;
167 
168  bool lateralmod = false, verticalmod = false; // these ramp up the speed of adjustment the longer you hold it down
169 
170  unsigned char diks[256]; // DirectInput keyboard state buffer
171  // Get the input's device state, and put the state in dims
172  if (FAILED(g_pKeyboard->GetDeviceState(256, diks)))
173  g_pKeyboard->Acquire();
174  else
175  {
176  // Read the string of the index values of the keys that are down
178  {
179  const float f_temp = 0.2f * fElapsedTime;
180 
181  g_bShift = diks[42] || diks[54];
182  g_bControl = diks[29] || diks[157];
183 
184  for (short t = 0; t < 256; t++)
185  {
186  if (diks[t] & 0x80)
187  {
188  // let the display system have first dibs
190  continue;
191 
192  // ReSharper disable once CppDefaultCaseNotHandledInSwitchStatement
193  switch (t)
194  {
195  case DIK_1: // left engine
196  if (!olddiks[t] && ourcockpit.power > 0.5f && !g_bShift)
197  {
198  if (ourcockpit.vdat.leftengine > -1)
199  {
200  if (ourcockpit.vdat.leftengine >= 64)
201  ourcockpit.vdat.leftengine = 0;
202  else
203  ourcockpit.vdat.leftengine = 127;
204  }
205  }
206  break;
207  case DIK_2: // center or right engine
208  if (!olddiks[t] && ourcockpit.power > 0.5f && !g_bShift)
209  {
210  if (ourcockpit.engines == 2)
211  {
212  if (ourcockpit.vdat.rightengine > -1)
213  {
214  if (ourcockpit.vdat.rightengine >= 64)
215  ourcockpit.vdat.rightengine = 0;
216  else
217  ourcockpit.vdat.rightengine = 127;
218  }
219  }
220  else if (ourcockpit.engines == 3)
221  {
222  if (ourcockpit.vdat.clengine > -1)
223  {
224  if (ourcockpit.vdat.clengine >= 64)
225  ourcockpit.vdat.clengine = 0;
226  else
227  ourcockpit.vdat.clengine = 127;
228  }
229  }
230  }
231  break;
232  case DIK_3: // right engine
233  if (!olddiks[t] && ourcockpit.power > 0.5f && !g_bShift && ourcockpit.engines == 3)
234  {
235  if (ourcockpit.vdat.rightengine > -1)
236  {
237  if (ourcockpit.vdat.rightengine >= 64)
238  ourcockpit.vdat.rightengine = 0;
239  else
240  ourcockpit.vdat.rightengine = 127;
241  }
242  }
243  break;
244 
245  case DIK_EQUALS: // zoom in
246  if (!olddiks[t] && ourcockpit.power > 0.5f && !g_bShift)
247  {
248  // ReSharper disable once CppDefaultCaseNotHandledInSwitchStatement
249  switch (static_cast<int>(viewscreen->gameclass->bus->MapScaleInnerRingKm))
250  {
251  case 10: viewscreen->gameclass->bus->MapScaleInnerRingKm = 5; break;
252  case 25: viewscreen->gameclass->bus->MapScaleInnerRingKm = 10; break;
253  case 50: viewscreen->gameclass->bus->MapScaleInnerRingKm = 25; break;
254  case 100: viewscreen->gameclass->bus->MapScaleInnerRingKm = 50; break;
255  case 250: viewscreen->gameclass->bus->MapScaleInnerRingKm = 100; break;
256  }
260  }
261  break;
262  case DIK_MINUS: // zoom out
263  if (!olddiks[t] && ourcockpit.power > 0.5f && !g_bShift)
264  {
265  // ReSharper disable once CppDefaultCaseNotHandledInSwitchStatement
266  switch (static_cast<int>(viewscreen->gameclass->bus->MapScaleInnerRingKm))
267  {
268  case 5: viewscreen->gameclass->bus->MapScaleInnerRingKm = 10; break;
269  case 10: viewscreen->gameclass->bus->MapScaleInnerRingKm = 25; break;
270  case 25: viewscreen->gameclass->bus->MapScaleInnerRingKm = 50; break;
271  case 50: viewscreen->gameclass->bus->MapScaleInnerRingKm = 100; break;
272  case 100: viewscreen->gameclass->bus->MapScaleInnerRingKm = 250; break;
273  }
277  }
278  break;
279 
280  case DIK_GRAVE: // reversers NO SHIFT CHECK
281  if (!olddiks[t] && !ourcockpit.gndvehicle)
282  {
283  const bool newStatus = !viewscreen->gameclass->bus->ThrustReverserCommand[0];
284  for (int i = 0; i < MAX_ENGINES; i++)
285  {
286  viewscreen->gameclass->bus->ThrustReverserCommand[i] = newStatus;
287  }
289  }
290  break;
291 
292  case DIK_NUMPAD4: // NO NUMLOCK CHECK
293  case DIK_LEFT: // arrow left, this is roll for aircraft in TO/TO mode
294  if (!g_bShift)
295  {
296  TurnLeft(f_temp);
297  }
298  break;
299 
300  case DIK_NUMPAD6: // NO NUMLOCK CHECK
301  case DIK_RIGHT: // arrow right
302  if (!g_bShift)
303  {
304  TurnRight(f_temp);
305  }
306  break;
307 
308  case DIK_NUMPAD1: // NO NUMLOCK CHECK
309  if (!g_bShift)
310  {
312  viewscreen->yawInput += f_temp;
313  else
314  viewscreen->yawInput -= f_temp;
315  viewscreen->yawInput = Clamp(viewscreen->yawInput, -1.0f, 1.0f);
316  }
317  break;
318 
319  case DIK_NUMPAD3: // NO NUMLOCK CHECK
320  if (!g_bShift)
321  {
323  viewscreen->yawInput -= f_temp;
324  else
325  viewscreen->yawInput += f_temp;
326  viewscreen->yawInput = Clamp(viewscreen->yawInput, -1.0f, 1.0f);
327  }
328  break;
329 
330  case DIK_NUMPAD8: // NO NUMLOCK CHECK
331  case DIK_UP: // arrow up
332  case DIK_W:
334  {
335  ourcockpit.cockpitArmKm.z += 0.0001f;
336  }
337  else if (!g_bShift)
338  {
339  if (!viewscreen->outside && viewscreen->gameclass->GUI->player[ourcockpit.ourplyrC].frame) // interior
340  {
341  WalkForward();
342  }
343  else if (!ourcockpit.gndvehicle)
344  {
346  viewscreen->pitchInput += f_temp;
347  else
348  viewscreen->pitchInput -= f_temp;
349  viewscreen->pitchInput = Clamp(viewscreen->pitchInput, -1.0f, 1.0f);
350  }
351  else
352  {
353  for (int i = 0; i < MAX_ENGINES; i++)
354  {
355  viewscreen->gameclass->bus->EngineThrustLever[i] += f_temp;
356  if (viewscreen->gameclass->bus->EngineThrustLever[i] > 1.0f)
358  if (i == 0 && viewscreen->gameclass->bus->EngineThrustLever[i] > 0.4f)
359  {
362  }
363  }
364 
365  }
366  }
367  break;
368  case DIK_NUMPAD2: // NO NUMLOCK CHECK
369  case DIK_DOWN: // arrow down
370  if (!g_bShift)
371  {
372  // if (!g_bOutside && game->gameclass->GUI->player[ourcockpit.ourplyrC].frame) // interior
373  // {
374  // ourcockpit.moving = 2; // walk backward (1-5 reserved)
375  // static float footstep = 0.0f;
376  // footstep += fElapsedTime * 6.0f;
377  // if (footstep >= 1.0f)
378  // {
379  // footstep = 0.0f;
380  // game->gameclass->sound->Play(SOUND_COCKPITLAND);
381  // }
382  // }
383  // else
384  if (!ourcockpit.gndvehicle)
385  {
387  viewscreen->pitchInput -= f_temp;
388  else
389  viewscreen->pitchInput += f_temp;
390  viewscreen->pitchInput = Clamp(viewscreen->pitchInput, -1.0f, 1.0f);
391  }
392  else
393  {
394  for (int i = 0; i < MAX_ENGINES; i++)
395  {
396  viewscreen->gameclass->bus->EngineThrustLever[i] -= f_temp;
397  if (viewscreen->gameclass->bus->EngineThrustLever[i] < 0.1f) // engine can't reverse on gv
399  }
400  }
401  }
402  break;
403 
404  case DIK_NUMPAD7: // lateral thrust // NO NUMLOCK CHECK
406  break;
407 
408  case DIK_NUMPAD9: // lateral thrust // NO NUMLOCK CHECK
410  break;
411 
412  case DIK_SPACE: // brakes
413  if (!g_bShift)
414  {
415  Brake(f_temp);
416  }
417  else if (!olddiks[t] && ourcockpit.wheeled && !ourcockpit.gndvehicle && ourcockpit.vdat.parkingBrake > 0)
418  {
422  }
423  break;
424 
425  case DIK_J:
426  {
427  if (!olddiks[t] && !viewscreen->gameclass->TurnOffDOR())
428  {
430  {
431  viewscreen->gameclass->bus->AFCS.DorOn = true;
432  viewscreen->gameclass->bus->AFCS.DesiredClosingSpeed = 0.0f; // reset
433  viewscreen->gameclass->bus->AFCS.TvmOn = false; // switching modes, no cavalry
434 
435  viewscreen->gameclass->bus->AFCS.CurrentLateralMode = Bus::Afcs::LateralModes::LateralMode_Off;
436  viewscreen->gameclass->bus->AFCS.CurrentVerticalMode = Bus::Afcs::VerticalModes::VerticalMode_Off;
437 
439  }
440  }
441  }
442  break;
443 
444  case DIK_K:
445  {
446  if (!olddiks[t] && !viewscreen->gameclass->TurnOffTVM())
447  {
448  if (!ourcockpit.gndvehicle)
449  {
450  viewscreen->gameclass->bus->AFCS.TvmOn = true;
451  viewscreen->gameclass->bus->AFCS.DesiredClosingSpeed = 0.0f; // reset
452  viewscreen->gameclass->bus->AFCS.DorOn = false; // switching modes, no cavalry
453  viewscreen->gameclass->bus->AFCS.CurrentLateralMode = Bus::Afcs::LateralModes::LateralMode_Off;
454  viewscreen->gameclass->bus->AFCS.CurrentVerticalMode = Bus::Afcs::VerticalModes::VerticalMode_Off;
455  viewscreen->gameclass->bus->AFCS.AutopilotEngaged = false; // no cavalry because we are engaging
456  }
457  }
458  }
459  break;
460 
461  case DIK_F1:
462  {
463  if (!g_bShift)
464  {
467  }
468  }
469  break;
470 
471  case DIK_F9:
472  {
473  if (!g_bShift)
474  {
475  // vertical thrust
477  }
478  else if (!olddiks[t] && ourcockpit.power > 0.5f && (ourcockpit.vdat.flapsTE > 0 || ourcockpit.vdat.flapsLE > 0))
479  {
481  {
483  const float extent = static_cast<float>(ourcockpit.flapSettings.at(viewscreen->gameclass->bus->flapSettingTE)) / static_cast<float>(ourcockpit.flapMaxDegrees);
484  playerships[0].flapdown = extent;
487  }
488  }
489  }
490  break;
491 
492  case DIK_F8:
493  if (!g_bShift)
494  {
495  // vertical thrust
497  }
498  else if (!olddiks[t] && !ourcockpit.flapSettings.empty() && ourcockpit.power > 0.5f && (ourcockpit.vdat.flapsTE > 0 || ourcockpit.vdat.flapsLE > 0))
499  {
501  {
503  const float extent = static_cast<float>(ourcockpit.flapSettings.at(viewscreen->gameclass->bus->flapSettingTE)) / static_cast<float>(ourcockpit.flapMaxDegrees);
504  playerships[0].flapdown = extent;
507  }
508  }
509  break;
510 
511  case DIK_F6: // Fire weapon
512  if (!g_bShift)
513  {
515  }
516  break;
517  case DIK_F7: // Fire weapon
518  if (!g_bShift)
519  {
521  }
522  break;
523 
524  case DIK_NUMPAD5: // Null rates NO NUMLOCK CHECK
525  if (!olddiks[t] && ourcockpit.power > 0.5f)
526  {
527  if (g_bShift)
528  {
531  }
533  {
535  }
536  }
537  break;
538 
539  case DIK_L: // Landing Light or Load into bay
540  if (!olddiks[t])
541  {
542  if (!g_bShift)
543  {
544  if (ourcockpit.power > 0.5f)
545  {
547 
548  DXUTGetD3D9Device()->LightEnable(1, playerships[0].headlight);
549 
550  Command command;
551  command.name = playerships[0].headlight ? "AuralLightOn" : "AuralLightOff";
552  viewscreen->gameclass->bus->commandStream.emplace_back(command);
553 
555 
557  }
558  }
559  else if (!playerships[0].simulator)
560  {
561  if (!ourcockpit.bays)
562  {
564  break;
565  }
566 
567  if (!playerships[0].baydoor)
568  {
570  break;
571  }
572 
573  if (viewscreen->gameclass->bus->targetC < 0)
574  {
576  break;
577  }
578 
580  if (playership.reference == REF_INANOTHER && playership.inarray == 0)
581  {
583  break;
584  }
585 
586  if (playership.type != VehicleType::DIHV)
587  {
588  SClientPacket outpacket; // NOLINT
589  outpacket.type = 18; // cargo ops
590  outpacket.f_x = 1.0f; // load request
591  outpacket.f_y = 0.0f; // NULL
592  outpacket.f_z = 0.0f; // NULL
593  // @todo this may not even be needed now since we send the targetVehicleId when we change targets
594  outpacket.f_w = static_cast<float>(playership.vehicleId);
595  viewscreen->gameclass->networking->SendToServer(&outpacket, sizeof(SClientPacket), true);
596 
597  // switch to Scan page on MFD
598  viewscreen->gameclass->displays->ChangePage("MFD", "Cargo Manifest");
599  }
600  else
601  {
603  }
604  }
605  }
606  break;
607 
608  case DIK_LBRACKET:
609  if (ourcockpit.power > 0.5f && !g_bShift)
610  {
611  if (viewscreen->gameclass->bus->AFCS.CurrentLateralMode == Bus::Afcs::LateralModes::Navigation)
612  {
613  lateralmod = true;
614  viewscreen->gameclass->bus->AFCS.DesiredCourseRadians -= D3DXToRadian(fElapsedTime * 10.0f * lateralincr);
617  viewscreen->lateraltime = 4.0f;
618  }
619  else if (viewscreen->gameclass->bus->AFCS.CurrentLateralMode == Bus::Afcs::LateralModes::Heading)
620  {
621  lateralmod = true;
622  viewscreen->gameclass->bus->AFCS.DesiredHeadingRadians -= D3DXToRadian(fElapsedTime * 20.0f * lateralincr);
625  viewscreen->lateraltime = 4.0f;
626  }
627  else if (viewscreen->gameclass->bus->AFCS.CurrentLateralMode == Bus::Afcs::LateralModes::Roll)
628  {
629  lateralmod = true;
630  viewscreen->gameclass->bus->AFCS.DesiredRollRadians -= 0.1f * fElapsedTime * lateralincr;
631  if (viewscreen->gameclass->bus->AFCS.DesiredRollRadians < -0.52359877559829887307710723054658f)
632  viewscreen->gameclass->bus->AFCS.DesiredRollRadians = -0.52359877559829887307710723054658f;
633  }
634  }
635  break;
636 
637  case DIK_RBRACKET:
638  if (ourcockpit.power > 0.5f && !g_bShift)
639  {
640  if (viewscreen->gameclass->bus->AFCS.CurrentLateralMode == Bus::Afcs::LateralModes::Navigation)
641  {
642  lateralmod = true;
643  viewscreen->gameclass->bus->AFCS.DesiredCourseRadians += D3DXToRadian(fElapsedTime * 10.0f * lateralincr);
646  viewscreen->lateraltime = 4.0f;
647  }
648  else if (viewscreen->gameclass->bus->AFCS.CurrentLateralMode == Bus::Afcs::LateralModes::Heading)
649  {
650  lateralmod = true;
651  viewscreen->gameclass->bus->AFCS.DesiredHeadingRadians += D3DXToRadian(fElapsedTime * 20.0f * lateralincr);
654  viewscreen->lateraltime = 4.0f;
655  }
656  else if (viewscreen->gameclass->bus->AFCS.CurrentLateralMode == Bus::Afcs::LateralModes::Roll)
657  {
658  lateralmod = true;
659  viewscreen->gameclass->bus->AFCS.DesiredRollRadians += 0.1f * fElapsedTime * lateralincr;
660  if (viewscreen->gameclass->bus->AFCS.DesiredRollRadians > 0.52359877559829887307710723054658f)
661  viewscreen->gameclass->bus->AFCS.DesiredRollRadians = 0.52359877559829887307710723054658f;
662  }
663  }
664  break;
665 
666  case DIK_SEMICOLON: // trim nose up or AP vertical mode target
667  if (ourcockpit.power > 0.5f)
668  {
670  {
673  viewscreen->gameclass->bus->PitchTrimScalar += fElapsedTime * 0.03f * trimlimiterC;
674  else
675  viewscreen->gameclass->bus->PitchTrimScalar -= fElapsedTime * 0.03f * trimlimiterC;
677  }
678  else
679  {
680  if (viewscreen->gameclass->bus->AFCS.CurrentVerticalMode == Bus::Afcs::VerticalModes::Pitch)
681  {
682  verticalmod = true;
683  viewscreen->gameclass->bus->AFCS.DesiredPitchRadians += 0.0087266462599716478846184538424431f * fElapsedTime * 3.0f * verticalincr; // 0.5 deg
684  if (viewscreen->gameclass->bus->AFCS.DesiredPitchRadians > 0.34906585039886591538473815369772f) // nose up 20
685  viewscreen->gameclass->bus->AFCS.DesiredPitchRadians = 0.34906585039886591538473815369772f;
686  }
687  else if (viewscreen->gameclass->bus->AFCS.CurrentVerticalMode == Bus::Afcs::VerticalModes::VerticalSpeed)
688  {
689  verticalmod = true;
690  viewscreen->gameclass->bus->AFCS.DesiredVsiKms += 0.05f * fElapsedTime * verticalincr;
691  }
692  else if (viewscreen->gameclass->bus->AFCS.CurrentVerticalMode == Bus::Afcs::VerticalModes::SpeedPitch)
693  {
694  verticalmod = true;
695  viewscreen->gameclass->bus->AFCS.DesiredIasKms += 0.01f * fElapsedTime * verticalincr;
696  }
697  else if (viewscreen->gameclass->bus->AFCS.CurrentVerticalMode == Bus::Afcs::VerticalModes::AltitudeMsl ||
698  viewscreen->gameclass->bus->AFCS.CurrentVerticalMode == Bus::Afcs::VerticalModes::AltitudeAgl)
699  {
700  verticalmod = true;
701  viewscreen->gameclass->bus->AFCS.DesiredAltitudeKm += 0.25f * fElapsedTime * verticalincr;
702  }
703  viewscreen->verticaltime = 4.0f;
704  }
705  }
706  break;
707 
708  case DIK_APOSTROPHE: // trim nose dn or AP vertical mode target
709  case 0xC0: // UK keyboard has a different scan code
710  if (ourcockpit.power > 0.5f)
711  {
713  {
716  viewscreen->gameclass->bus->PitchTrimScalar -= fElapsedTime * 0.03f * trimlimiterC;
717  else
718  viewscreen->gameclass->bus->PitchTrimScalar += fElapsedTime * 0.03f * trimlimiterC;
720  }
721  else
722  {
723  if (viewscreen->gameclass->bus->AFCS.CurrentVerticalMode == Bus::Afcs::VerticalModes::Pitch)
724  {
725  verticalmod = true;
726  viewscreen->gameclass->bus->AFCS.DesiredPitchRadians -= 0.0087266462599716478846184538424431f * fElapsedTime * 3.0f * verticalincr; // 0.5 deg
727  if (viewscreen->gameclass->bus->AFCS.DesiredPitchRadians < -0.26179938779914943653855361527329f) // nose down 15
728  viewscreen->gameclass->bus->AFCS.DesiredPitchRadians = -0.26179938779914943653855361527329f;
729  }
730  else if (viewscreen->gameclass->bus->AFCS.CurrentVerticalMode == Bus::Afcs::VerticalModes::VerticalSpeed)
731  {
732  verticalmod = true;
733  viewscreen->gameclass->bus->AFCS.DesiredVsiKms -= 0.05f * fElapsedTime * verticalincr;
734  }
735  else if (viewscreen->gameclass->bus->AFCS.CurrentVerticalMode == Bus::Afcs::VerticalModes::SpeedPitch)
736  {
737  verticalmod = true;
738  viewscreen->gameclass->bus->AFCS.DesiredIasKms -= 0.01f * fElapsedTime * verticalincr;
739  if (viewscreen->gameclass->bus->AFCS.DesiredIasKms < 0.0f)
741  }
742  else if (viewscreen->gameclass->bus->AFCS.CurrentVerticalMode == Bus::Afcs::VerticalModes::AltitudeMsl ||
743  viewscreen->gameclass->bus->AFCS.CurrentVerticalMode == Bus::Afcs::VerticalModes::AltitudeAgl)
744  {
745  verticalmod = true;
746  viewscreen->gameclass->bus->AFCS.DesiredAltitudeKm -= 0.25f * fElapsedTime * verticalincr;
747  if (viewscreen->gameclass->bus->AFCS.CurrentVerticalMode == Bus::Afcs::VerticalModes::AltitudeAgl && viewscreen->gameclass->bus->AFCS.DesiredAltitudeKm < 0.0f)
749  }
750  viewscreen->verticaltime = 4.0f;
751  }
752  }
753  break;
754 
755  case DIK_HOME: // NO SHIFT CHECK
757  {
758  viewscreen->rcsThrustRequestZ = -0.002f;
759  }
760  break;
761 
762  case DIK_END: // NO SHIFT CHECK
764  {
765  viewscreen->rcsThrustRequestZ = 0.002f;
766  }
767  break;
768 
769  case DIK_G: // Landing gear // extended w=6, retracted w=5
770  if (!olddiks[t] && !g_bShift)
771  {
772  if (ourcockpit.power > 0.0f && ourcockpit.vdat.struts > 0)
773  {
774  ourcockpit.sentgearvoice = false;
775  if (playerships[0].geardown && viewscreen->gameclass->bus->LandingGearExtended == 1.0f)
776  playerships[0].geardown = false;
777  else if (!playerships[0].geardown && viewscreen->gameclass->bus->LandingGearExtended == 0.0f)
778  playerships[0].geardown = true;
779 
781 
783  }
784  }
785  break;
786 
787  case DIK_COMMA: // '<' (Chair rev)
788  if (!g_bShift)
789  {
790  ourcockpit.chairfwd -= fElapsedTime * 0.2f; // 5 seconds
791  if (ourcockpit.chairfwd < 0.0f)
792  ourcockpit.chairfwd = 0.0f;
793  }
794  break;
795 
796  case DIK_PERIOD: // '>' (Chair fwd)
797  if (!g_bShift)
798  {
799  ourcockpit.chairfwd += fElapsedTime * 0.2f; // 5 seconds
800  if (ourcockpit.chairfwd > 1.0f)
801  ourcockpit.chairfwd = 1.0f;
802  }
803  break;
804 
805  case DIK_X:
806  if (!olddiks[t])
807  {
809  {
810  if (viewscreen->gameclass->bus->targetC >= 0)
811  {
812  if (!playerships[0].simulator)
813  {
814  SClientPacket outpacket{};
815  outpacket.type = 17; // change ships
816  outpacket.f_x = 0.0f; // move us to target
817  outpacket.f_y = 0.0f; // NULL
818  outpacket.f_z = 0.0f; // NULL
819  // @todo this may not even be needed now since we send the targetVehicleId when we change targets
820  outpacket.f_w = static_cast<float>(playerships[viewscreen->scanslot[viewscreen->gameclass->bus->targetC]].vehicleId);
821  viewscreen->gameclass->networking->SendToServer(&outpacket, sizeof(SClientPacket), true);
822  }
823  }
824  else
825  {
827  }
828  }
829  else if (viewscreen->gameclass->GUI->IsAdmin)
830  {
831  playerships[0].precisionx -= 0.001f;
832  }
833  }
834  break;
835 
836  case DIK_Z:
837  if (!olddiks[t])
838  {
840  {
841  if (viewscreen->gameclass->bus->targetC >= 0)
842  {
843  if (!playerships[0].simulator)
844  {
845  SClientPacket outpacket{};
846  outpacket.type = 17; // change ships (displace?)
847  outpacket.f_x = 1.0f; // move target to lineinput dest
848  outpacket.f_y = 0.0f; // NULL
849  outpacket.f_z = 0.0f; // NULL
850  // @todo this may not even be needed now since we send the targetVehicleId when we change targets
851  outpacket.f_w = static_cast<float>(playerships[viewscreen->scanslot[viewscreen->gameclass->bus->targetC]].vehicleId);
852  viewscreen->gameclass->networking->SendToServer(&outpacket, sizeof(SClientPacket), true);
853  }
854  }
855  else
856  {
858  }
859  }
860  else if (viewscreen->gameclass->GUI->IsAdmin)
861  {
862  playerships[0].precisionz += 0.001f;
863  }
864  }
865  break;
866 
867  case DIK_V:
868  if (!olddiks[t] && !g_bShift)
869  {
871  {
872  if (viewscreen->gameclass->bus->AFCS.CurrentLateralMode == Bus::Afcs::LateralModes::LateralMode_TakeOff)
873  {
874  viewscreen->gameclass->bus->AFCS.CurrentLateralMode = Bus::Afcs::LateralModes::LateralMode_Off;
875  viewscreen->gameclass->bus->AFCS.CurrentVerticalMode = Bus::Afcs::VerticalModes::VerticalMode_Off;
876  }
878  if (viewscreen->gameclass->bus->AFCS.CurrentVerticalMode == Bus::Afcs::VerticalModes::Pitch)
880  else if (viewscreen->gameclass->bus->AFCS.CurrentVerticalMode == Bus::Afcs::VerticalModes::VerticalSpeed)
882  else if (viewscreen->gameclass->bus->AFCS.CurrentVerticalMode == Bus::Afcs::VerticalModes::SpeedPitch)
884  else if (viewscreen->gameclass->bus->AFCS.CurrentVerticalMode == Bus::Afcs::VerticalModes::AltitudeMsl)
886  else if (viewscreen->gameclass->bus->AFCS.CurrentVerticalMode == Bus::Afcs::VerticalModes::AltitudeAgl)
887  {
888  if (f_AGL <= 10.0f) // @ref https://jira.risetvp.com/view.php?id=1645 skip this mode and GS mode if we are above 10
890  else
891  viewscreen->gameclass->bus->AFCS.CurrentVerticalMode = Bus::Afcs::VerticalModes::Pitch;
892  }
893 
894  if (viewscreen->gameclass->bus->AFCS.CurrentVerticalMode == Bus::Afcs::VerticalModes::GlideSlope) // was AGL now G/S so cycle to PIT
895  viewscreen->gameclass->bus->AFCS.CurrentVerticalMode = Bus::Afcs::VerticalModes::Pitch;
896  else if (viewscreen->gameclass->bus->AFCS.CurrentVerticalMode == Bus::Afcs::VerticalModes::VerticalMode_Enum) // was GS now ENUM so cycle to ROLL/PIT
897  {
898  viewscreen->gameclass->bus->AFCS.CurrentLateralMode = Bus::Afcs::LateralModes::Roll;
899  viewscreen->gameclass->bus->AFCS.CurrentVerticalMode = Bus::Afcs::VerticalModes::Pitch;
900  }
901  else
902  viewscreen->verticaltime = 4.0f;
904  {
905  viewscreen->gameclass->bus->AFCS.CurrentLateralMode = Bus::Afcs::LateralModes::Roll;
906  if (fabsf(viewscreen->gameclass->bus->RollAttitudeRadians) < 0.087266462599716478846184538424431f) // 5°
908  else
910  }
911  }
912  else
913  {
915  }
916  }
917  break;
918 
919  case DIK_E:
920  if (!olddiks[t] && !g_bShift)
921  {
922  const std::string newPage = viewscreen->gameclass->displays->TogglePageReverse("MFD");
923  if (viewscreen->leftright > 0.55f &&
924  viewscreen->updown < -0.045f && viewscreen->updown > -0.74f &&
927  if (newPage == "Cargo Manifest" && viewscreen->gameclass->GUI->informationDialog->DismissHelp(ActiveHelp::TaxiService55))
928  {
931  }
932  }
933  break;
934 
935  case DIK_M:
936  if (!olddiks[t] && !g_bShift)
937  {
938  const std::string newPage = viewscreen->gameclass->displays->TogglePage("MFD");
939  if (viewscreen->leftright > 0.55f &&
940  viewscreen->updown < -0.045f && viewscreen->updown > -0.74f &&
943  if (newPage == "Cargo Manifest" && viewscreen->gameclass->GUI->informationDialog->DismissHelp(ActiveHelp::TaxiService55))
944  {
947  }
948  }
949  break;
950 
951  case DIK_I:
952  if (!olddiks[t] && ourcockpit.vdat.antiIce != -1)
953  {
956  }
957  break;
958 
959  case DIK_C:
960  case DIK_INSERT:
961  if (!olddiks[t])
962  {
963  // trying to copy to clipboard
964  if (g_bControl)
965  {
966  if (DialogBase::dialogs[D_COMMUNICATIONS]->linecursel != -1)
967  {
968  const int chatline = DialogBase::dialogs[D_COMMUNICATIONS]->linecursel;
969  const wchar_t* str = viewscreen->gameclass->GUI->chatchannel[DialogBase::dialogs[D_COMMUNICATIONS]->activetab].formatchatline.at(chatline).c_str();
970 
971  const HGLOBAL hMem = GlobalAlloc(GMEM_MOVEABLE, wcslen(str) * 2 + 2);
972  memcpy(GlobalLock(hMem), str, wcslen(str) * 2 + 2);
973  GlobalUnlock(hMem);
974 
975  OpenClipboard(nullptr);
976  EmptyClipboard();
977  SetClipboardData(CF_UNICODETEXT, hMem);
978  CloseClipboard();
979 
982  }
983  }
984  else if (t == DIK_C)
985  {
986  if (!g_bShift)
987  {
989  {
990  if (viewscreen->gameclass->bus->AFCS.CurrentLateralMode == Bus::Afcs::LateralModes::LateralMode_TakeOff)
991  {
992  viewscreen->gameclass->bus->AFCS.CurrentLateralMode = Bus::Afcs::LateralModes::LateralMode_Off;
993  viewscreen->gameclass->bus->AFCS.CurrentVerticalMode = Bus::Afcs::VerticalModes::VerticalMode_Off;
994  }
996  if (viewscreen->gameclass->bus->AFCS.CurrentLateralMode == Bus::Afcs::LateralModes::Roll)
997  {
998  if (fabsf(viewscreen->gameclass->bus->RollAttitudeRadians) < 0.087266462599716478846184538424431f) // 5°
1000  else
1002  }
1003  if (viewscreen->gameclass->bus->AFCS.CurrentLateralMode == Bus::Afcs::LateralModes::Heading)
1005  if (viewscreen->gameclass->bus->AFCS.CurrentLateralMode == Bus::Afcs::LateralModes::Navigation)
1006  {
1008  if (viewscreen->gameclass->bus->AFCS.DesiredCourseRadians > D3DX_TAU)
1010  else if (viewscreen->gameclass->bus->AFCS.DesiredCourseRadians <= 0.0f)
1012  //char msg[99];
1013  //sprintf_s(msg, sizeof(msg), "LOOK HERE, we were %.1f he was bear %.1f so course is %.1f", viewscreen->insthdgDegrees, bear, desiredcrs);
1014  //logger->Log(msg);
1015  }
1016  if (viewscreen->gameclass->bus->AFCS.CurrentLateralMode == Bus::Afcs::LateralModes::Localizer)
1017  viewscreen->gameclass->bus->AFCS.CurrentLateralMode = Bus::Afcs::LateralModes::Roll;
1018  else if (viewscreen->gameclass->bus->AFCS.CurrentLateralMode == Bus::Afcs::LateralModes::LateralMode_Enum)
1019  {
1020  viewscreen->gameclass->bus->AFCS.CurrentLateralMode = Bus::Afcs::LateralModes::Roll;
1021  viewscreen->gameclass->bus->AFCS.CurrentVerticalMode = Bus::Afcs::VerticalModes::Pitch;
1022  }
1023  else
1024  viewscreen->lateraltime = 4.0f;
1026  {
1027  viewscreen->gameclass->bus->AFCS.CurrentVerticalMode = Bus::Afcs::VerticalModes::Pitch;
1029  }
1030  }
1031  else
1032  {
1034  }
1035  }
1036  else if (viewscreen->gameclass->GUI->IsAdmin)
1037  {
1038  playerships[0].precisionx += 0.001f;
1039  }
1040  }
1041  }
1042  break;
1043 
1044  case DIK_F:
1045  if (!olddiks[t])
1046  {
1047  if (!g_bShift)
1048  {
1049  if ((viewscreen->gameclass->bus->AFCS.CurrentLateralMode || viewscreen->gameclass->bus->AFCS.CurrentVerticalMode) && ourcockpit.power > 0.5f) // FD engaged and has power
1050  {
1051  viewscreen->gameclass->bus->AFCS.CurrentLateralMode = Bus::Afcs::LateralModes::LateralMode_Off;
1052  viewscreen->gameclass->bus->AFCS.CurrentVerticalMode = Bus::Afcs::VerticalModes::VerticalMode_Off;
1054  }
1055  else
1056  {
1058  }
1059  }
1060  else if (playerships[0].simulator)
1061  {
1064  }
1065  break;
1066  }
1067  break;
1068 
1069  case DIK_S: // brake, shallow scan VPT mode S
1070  {
1072  {
1073  ourcockpit.cockpitArmKm.z -= 0.0001f;
1074  }
1075  else if (!g_bShift)
1076  {
1077  Brake(f_temp);
1078  }
1079  else if (!olddiks[t])
1080  {
1081  if (ourcockpit.power > 0.5f && viewscreen->gameclass->GUI->player[viewscreen->gameclass->GUI->ourplayerC].frame == 0)
1082  {
1083  if (viewscreen->gameclass->bus->targetC >= 0)
1084  {
1086 
1087  if (network_objects.type != VehicleType::DIHV)
1088  {
1089  SClientPacket outpacket = SClientPacket();
1090  outpacket.type = 36; // scan
1091  outpacket.f_x = 0.0f; // shallow VPT mode S
1092  outpacket.f_y = 0.0f; // NULL
1093  outpacket.f_z = 0.0f; // NULL
1094  // @todo this may not even be needed now since we send the targetVehicleId when we change targets
1095  outpacket.f_w = static_cast<float>(network_objects.vehicleId);
1096  viewscreen->gameclass->networking->SendToServer(&outpacket, sizeof(SClientPacket), true);
1098 
1099  // store what we know in the scan database - we don't need to send it to the server because they already know!
1100  SmodeAC modeAC;
1101  strcpy_s(modeAC.hullname, 23, network_objects.hullname);
1102  strcpy_s(modeAC.IVR, 6, network_objects.IVR);
1103  strcpy_s(modeAC.owner, 13, network_objects.owner);
1104  modeAC.ownerId = network_objects.ownerId;
1105  modeAC.allegiance = network_objects.allegiance;
1106  modeAC.location = network_objects.position;
1107  modeAC.reference = network_objects.reference;
1108  modeAC.reposess = network_objects.reposess;
1109  modeAC.stolen = network_objects.stolen;
1110  modeAC.tow = network_objects.tow;
1111  modeAC.type = network_objects.type;
1112  modeAC.vehicleId = network_objects.vehicleId;
1114 
1115  // clear out vehicles that we know used to point to this parent vehicle
1116  viewscreen->gameclass->bus->Scanner.ClearChildren(network_objects.vehicleId);
1117 
1118  // switch to Scan page on MFD
1119  viewscreen->gameclass->displays->ChangePage("MFD", "Scanner");
1120 
1121  // update bus with target vehicle ID
1123 
1124  // update alignment colorize based on owner
1125  network_objects.align = viewscreen->gameclass->GUI->people.GetAlignment(modeAC.ownerId);
1126  }
1127  else
1128  {
1130  }
1131  }
1132  else
1133  {
1135  }
1136  }
1137  }
1138  }
1139  break;
1140 
1141  case DIK_NEXT:
1142  {
1144  {
1145  ourcockpit.cockpitArmKm.y -= 0.0001f;
1146  }
1147  else if (!olddiks[t])
1148  {
1149  scanscroll++;
1150  if (scanscroll > topscroll)
1152  }
1153  }
1154  break;
1155 
1156  case DIK_PRIOR:
1157  {
1159  {
1160  ourcockpit.cockpitArmKm.y += 0.0001f;
1161  }
1162  else if (!olddiks[t])
1163  {
1164  scanscroll--;
1165  if (scanscroll < 0)
1166  scanscroll = 0;
1167  }
1168  }
1169  break;
1170 
1171  case DIK_F3:
1172  {
1173  if (!olddiks[t] && !g_bShift && fabsf(viewscreen->gameclass->bus->RollAttitudeRadians) > 1.5708f && playerships[0].reference == REF_ONGROUND)
1174  {
1175  D3DXQUATERNION quaternionTemp;
1176  D3DXQuaternionRotationYawPitchRoll(&quaternionTemp, 0.0f, 0.0f, D3DX_PI);
1177  D3DXQuaternionMultiply(&playerships[0].orientation, &playerships[0].orientation, &quaternionTemp);
1179  }
1180  }
1181  break;
1182 
1183  case DIK_F10:
1184  {
1185  if (!olddiks[t] && !g_bShift && ourcockpit.power > 0.5f)
1186  {
1188  {
1189  // ReSharper disable once CppExpressionWithoutSideEffects
1191  // ReSharper disable once CppExpressionWithoutSideEffects
1194  }
1195  else if (!ourcockpit.gndvehicle)
1196  {
1198  {
1199  if (playerships[0].reference != REF_ONGROUND)
1200  {
1201  viewscreen->gameclass->bus->AFCS.CurrentLateralMode = Bus::Afcs::LateralModes::Roll;
1202  if (fabsf(viewscreen->gameclass->bus->RollAttitudeRadians) < 0.087266462599716478846184538424431f) // 5°
1204  else if (fabsf(viewscreen->gameclass->bus->RollAttitudeRadians) >= D3DX_PI)
1206  else
1208  }
1209  else
1210  {
1211  viewscreen->gameclass->bus->AFCS.CurrentLateralMode = Bus::Afcs::LateralModes::LateralMode_TakeOff;
1213  }
1214  }
1216  {
1217  if (playerships[0].reference != REF_ONGROUND)
1218  viewscreen->gameclass->bus->AFCS.CurrentVerticalMode = Bus::Afcs::VerticalModes::Pitch;
1219  else
1220  viewscreen->gameclass->bus->AFCS.CurrentVerticalMode = Bus::Afcs::VerticalModes::VerticalMode_TakeOff;
1221  }
1224  }
1225  }
1226  }
1227  break;
1228 
1229  case DIK_TAB:
1230  {
1231  if (!olddiks[t] && !g_bShift)
1232  {
1233  viewscreen->gameclass->bus->targetC++; // was -1 now 0
1234 
1235  bool flag = true;
1236  while (flag)
1237  {
1239  {
1243  {
1244  flag = false;
1245  }
1246  else
1247  {
1249  }
1250  }
1251  else
1252  flag = false;
1253  }
1254 
1256  viewscreen->gameclass->bus->targetC = -4;
1258  viewscreen->gameclass->bus->targetC = static_cast<short>(scanscroll);
1259 
1260  if (viewscreen->gameclass->bus->AFCS.CurrentLateralMode == Bus::Afcs::LateralModes::Localizer)
1261  {
1262  viewscreen->gameclass->bus->AFCS.CurrentLateralMode = Bus::Afcs::LateralModes::Navigation;
1263  viewscreen->gameclass->bus->AFCS.CurrentVerticalMode = Bus::Afcs::VerticalModes::Pitch;
1264  }
1265 
1266  if (ourcockpit.power > 0.5f)
1267  {
1271  }
1272 
1273  // need to find which ship that is
1274  if (viewscreen->gameclass->bus->targetC >= 0)
1275  {
1278  }
1279  else
1280  {
1283  }
1284  }
1285  }
1286  break;
1287 
1288  //case DIK_T: // special task ticketing
1289  //{
1290  // if (!olddiks[t] && !g_bShift)
1291  // {
1292  // if (playerships[0].police)
1293  // {
1294  // if (!playerships[0].specialight)
1295  // {
1296  // viewscreen->gameclass->networking->RequestVerbiage(ActiveHelp::FirstTurnOnLightBar);
1297  // }
1298  // else if (targetC >= 0)
1299  // {
1300  // SClientPacket outpacket;
1301  // outpacket.type = 26; // ticketing
1302  // outpacket.f_x = 0.0f; // NULL
1303  // outpacket.f_y = 0.0f; // NULL
1304  // outpacket.f_z = 0.0f; // NULL
1305  // outpacket.f_w = static_cast<float>(playerships[viewscreen->scanslot[targetC]].vehicleId);
1306  // viewscreen->gameclass->networking->SendToServer(&outpacket, sizeof(SClientPacket), true);
1307  // }
1308  // else
1309  // {
1310  // viewscreen->gameclass->networking->RequestVerbiage(ActiveHelp::FirstSelectVehicleOrContainer);
1311  // }
1312  // }
1313  // }
1314  //}
1315  //break;
1316 
1317  case DIK_H: // horn and police light and clear throat
1318  {
1319  if (!olddiks[t])
1320  {
1321  if (!g_bShift)
1322  {
1323  bool honk = false;
1324  if (playerships[0].police)
1325  {
1326  if (playerships[0].specialight)
1327  {
1328  playerships[0].specialight = false;
1330  }
1331  else
1332  {
1333  playerships[0].specialight = honk = true;
1335  }
1336  }
1337  else if (ourcockpit.gndvehicle)
1338  {
1339  honk = true;
1340  }
1341  if (honk)
1342  {
1343  // honk horn
1344  if (!playerships[0].simulator)
1345  {
1346  SClientPacket outpacket{};
1347  outpacket.type = 23; // Sound Effect in universe
1348  outpacket.f_x = 0.0f; // car noise
1349  outpacket.f_y = 0.0f; // horn honk
1350  outpacket.f_z = 0.0f; // NULL
1351  outpacket.f_w = 0.0f; // NULL
1352  viewscreen->gameclass->networking->SendToServer(&outpacket, sizeof(SClientPacket), true);
1353 
1354  if (playerships[0].police)
1356  else if (ourcockpit.texturelib == T120 || ourcockpit.texturelib == T121)
1358  else if (ourcockpit.texturelib == T27)
1360  else if (_strcmpi(playerships[0].hullname, "ECTO 1") == 0)
1362  else
1364  }
1365  }
1366  }
1367  else if (viewscreen->gameclass->GUI->IsAdmin)
1368  {
1369  playerships[0].precisiony -= 0.001f;
1370  }
1371  }
1372  }
1373  break;
1374 
1375  case DIK_A: // thrust augmentation, turn left
1376  {
1378  {
1379  ourcockpit.cockpitArmKm.x -= 0.0001f;
1380  }
1381  else if (!g_bShift)
1382  {
1383  TurnLeft(f_temp);
1384  }
1385  else if (!olddiks[t])
1386  {
1388  }
1389  }
1390  break;
1391 
1392  case DIK_R: // repair
1393  {
1394  if (!olddiks[t] && g_bShift && !viewscreen->gameclass->GUI->player[ourcockpit.ourplyrC].frame)
1395  {
1397 
1398  ourcockpit.hitpoints = 255;
1399 
1401  {
1403  }
1404  else if (!ourcockpit.gndvehicle && viewscreen->ptrPropulsion->GetTotalThrust() > 0.0005f) // 0.05G (.49 m/s2) is perceptible
1405  {
1407  }
1408  else
1409  {
1412  }
1413  }
1414  }
1415  break;
1416 
1417  case DIK_SCROLL: // clear cas messages
1418  {
1419  if (!olddiks[t])
1420  {
1421  Command command;
1422  if (!g_bShift)
1423  command.name = "AcknowledgeAllMessages";
1424  else
1425  command.name = "VMUTest";
1426  viewscreen->gameclass->bus->commandStream.emplace_back(command);
1427  }
1428  }
1429  break;
1430 
1431  case DIK_Y: // yaw damper
1432  if (!olddiks[t])
1433  {
1434  if (!g_bShift)
1435  {
1438  }
1439  else if (viewscreen->gameclass->GUI->IsAdmin)
1440  {
1441  playerships[0].precisiony += 0.001f;
1442  }
1443  }
1444  break;
1445 
1446  case DIK_P:
1447  if (!olddiks[t] && !g_bShift && fuel > 0.0f && playerships[0].reference != REF_BUILDING && playerships[0].reference != REF_SIMBAY)
1448  {
1449  if (ourcockpit.startcycle == 0) // shut down
1450  {
1451  ourcockpit.startcycle = 1; // starting
1452 
1453  playerships[0].logolight = true;
1455 
1460 
1461  viewscreen->gameclass->displays->ChangePage("MFD", 0);
1466  }
1467  if (ourcockpit.startcycle == 2) // running
1468  {
1469  ourcockpit.startcycle = 3; // shutting down
1470  playerships[0].logolight = false;
1471 
1473  if (!playerships[0].simulator)
1474  {
1475  //if (playerships[0].reference != REF_BUILDING)
1476  {
1478  }
1479  }
1480  }
1481  }
1482  break;
1483 
1484  case DIK_O:
1485  if (!olddiks[t] && !g_bShift)
1486  {
1490  }
1491  break;
1492 
1493  case DIK_U:
1495  {
1496  playerships[MAX_SCAN - 1].logolight = false;
1497  playerships[MAX_SCAN - 1].active = true;
1498  playerships[MAX_SCAN - 1].visible = true;
1499  //playerships[MAX_SCAN - 1].clientinit = true;
1500  playerships[MAX_SCAN - 1].reference = REF_ONGROUND;
1501  playerships[MAX_SCAN - 1].align = 1;
1502  playerships[MAX_SCAN - 1].type = BeishtKione;
1503  viewscreen->LoadVehicleProfile(MAX_SCAN - 1);
1504  playerships[MAX_SCAN - 1].acc = playerships[MAX_SCAN - 1].acciter = playerships[MAX_SCAN - 1].accleft = centerC;
1505  playerships[MAX_SCAN - 1].positer = playerships[MAX_SCAN - 1].posleft = centerC;
1506  playerships[MAX_SCAN - 1].position = D3DXVECTOR3(-1274.755f, -2639.425f, 226.8252f);
1507  playerships[MAX_SCAN - 1].precisionx = static_cast<double>(playerships[MAX_SCAN - 1].position.x);
1508  playerships[MAX_SCAN - 1].precisiony = static_cast<double>(playerships[MAX_SCAN - 1].position.y);
1509  playerships[MAX_SCAN - 1].precisionz = static_cast<double>(playerships[MAX_SCAN - 1].position.z);
1510  D3DXVECTOR3 gthrust;
1511  float radius;
1512  playerships[MAX_SCAN - 1].velocity = playerships[MAX_SCAN - 1].barycentric = Viewscreen::CalculateBarycentric(&playerships[MAX_SCAN - 1].position, &gthrust, &radius);
1513  playerships[MAX_SCAN - 1].veliter = playerships[MAX_SCAN - 1].velleft = centerC;
1514  playerships[MAX_SCAN - 1].orientation = D3DXQUATERNION(-0.3331781f, 0.1119807f, 0.9148517f, -0.1987435f);
1515  D3DXQuaternionIdentity(&playerships[MAX_SCAN - 1].orientiter);
1516  D3DXQuaternionIdentity(&playerships[MAX_SCAN - 1].orientleft);
1517  }
1518  break;
1519 
1520  case DIK_B: // bay door
1521  {
1522  if (!olddiks[t] && g_bShift && ourcockpit.power > 0.5f && ourcockpit.vdat.baydoor > 0)
1523  {
1527  }
1528  }
1529  break;
1530 
1531  case DIK_D: // docking/undocking and turning right
1532  {
1534  {
1535  ourcockpit.cockpitArmKm.x += 0.0001f;
1536  }
1537  else if (!g_bShift) // interior
1538  {
1539  TurnRight(f_temp);
1540  }
1541  else if (!olddiks[t])
1542  {
1543  if (!playerships[0].docked && playerships[0].portassigned != -1)
1544  {
1545  if (D3DXVec3Length(&playerships[0].dockingvel) > 0.010f)
1546  {
1548  }
1549  else
1550  {
1551  D3DXVECTOR3 result = playerships[0].dockoffset - dockMarker;
1552  if (D3DXVec3Length(&result) < 0.1f) // within 100m
1553  {
1554  playerships[0].docked = true;
1555  dockprogress = 0.0f;
1556  viewscreen->gameclass->bus->AFCS.DesiredClosingSpeed = 0.0f; // reset
1557  }
1558  else
1559  {
1561  }
1562  }
1563  }
1564  else if (playerships[0].docked)
1565  {
1566  viewscreen->Undock();
1567  }
1568  }
1569  }
1570  break;
1571 
1572  case DIK_PAUSE:
1573  {
1574  if (!olddiks[t] && playerships[0].simulator)
1575  {
1578  }
1579  }
1580  break;
1581 
1582  case DIK_F5:
1583  {
1584  if (!olddiks[t] && viewscreen->gameclass->GUI->player[ourcockpit.ourplyrC].frame == REF_INANOTHER && !playerships[0].simulator)
1586  }
1587  break;
1588 
1589  case DIK_SUBTRACT:
1590  {
1591  if (!olddiks[t] && !ourcockpit.gndvehicle)
1592  {
1594  {
1595  for (int i = 0; i < MAX_ENGINES; i++)
1596  {
1597  viewscreen->gameclass->bus->EngineThrustLever[i] -= 0.1f;
1598  if (viewscreen->gameclass->bus->EngineThrustLever[i] < 0.0f)
1600  }
1601  }
1602  else
1603  {
1605  }
1606  }
1607  }
1608  break;
1609  case DIK_ADD:
1610  {
1611  if (!olddiks[t] && !ourcockpit.gndvehicle)
1612  {
1614  {
1615  for (int i = 0; i < MAX_ENGINES; i++)
1616  {
1617  viewscreen->gameclass->bus->EngineThrustLever[i] += 0.1f;
1618  if (viewscreen->gameclass->bus->EngineThrustLever[i] > 1.0f)
1620  }
1621  }
1622  else
1623  {
1625  }
1626  }
1627  }
1628  break;
1629 
1630  }
1631  }
1632  }
1633  }
1634  memcpy_s(olddiks, 256, diks, 256);
1635  }
1636 
1637  if (lateralmod)
1638  {
1639  lateralincr += 0.1f * fElapsedTime;
1640  if (lateralincr > 1.0f)
1641  lateralincr = 1.0f;
1642  }
1643  else
1644  lateralincr = 0.1f;
1645  if (verticalmod)
1646  {
1647  verticalincr += 0.1f * fElapsedTime;
1648  if (verticalincr > 1.0f)
1649  verticalincr = 1.0f;
1650  }
1651  else
1652  verticalincr = 0.1f;
1653 }
1654 
1655 void keyboard::SetScrollLock(bool setState)
1656 {
1657  const bool curState = LOWORD(GetKeyState(VK_SCROLL)) != 0;
1658  if (curState != setState)
1659  {
1660  // Simulate a key press
1661  keybd_event(VK_SCROLL, DIK_SCROLL, KEYEVENTF_EXTENDEDKEY | 0, 0);
1662 
1663  // Simulate a key release
1664  keybd_event(VK_SCROLL, DIK_SCROLL, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0);
1665  }
1666 }
void Undock() const
unsigned char olddiks[256]
Definition: keyboard.h:24
std::vector< std::wstring > formatchatline
Definition: chat.h:55
bool DismissHelp(int helpId, int nControlID=GUI_UNDERSTOOD)
Scockpit ourcockpit
Definition: globals.cpp:176
float yawInput
Definition: Viewscreen.h:237
float PitchTrimScalar
Definition: Bus.h:316
bool AntiIce
Definition: Bus.h:296
bool TurnOffTVM() const
Definition: GameClass.cpp:2243
#define MAX_ENGINES
Definition: Bus.h:14
bool Edited
Definition: gui.h:778
bool g_bAugment
Definition: globals.cpp:63
D3DXVECTOR3 cockpitArmKm
Definition: globals.h:620
double ProgramTime
Definition: Bus.h:373
UINT flapSettingTE
Definition: Bus.h:56
char IVR[6]
Definition: scanDb.h:16
D3DXVECTOR3 acc
Definition: globals.h:542
D3DXVECTOR3 acciter
Definition: globals.h:542
float power
Definition: globals.h:608
virtual void UpdateMenu(short tab)
float LandingGearExtended
Definition: Bus.h:224
bool stolen
Definition: scanDb.h:26
unsigned char type
Definition: scanDb.h:17
float fuel
Definition: globals.cpp:143
float DesiredVsiKms
Definition: Bus.h:113
struct Bus::Afcs AFCS
float RightBrake
Definition: Bus.h:289
Config config
Definition: GameClass.h:102
void WalkForward() const
Definition: keyboard.cpp:70
Logger * logger
Definition: keyboard.h:19
LPDIRECTINPUTDEVICE8 g_pKeyboard
Definition: keyboard.h:25
std::vector< Command > commandStream
Definition: Bus.h:342
D3DXVECTOR3 position
Definition: globals.h:549
GameClass * gameclass
Definition: Viewscreen.h:292
short scanDisplayVesselLimit
Definition: globals.h:702
std::vector< int > flapSettings
Definition: globals.h:656
int allegiance
Definition: scanDb.h:23
D3DXQUATERNION orientation
Definition: globals.h:558
D3DXVECTOR3 location
Definition: scanDb.h:20
enum Bus::Afcs::LateralModes CurrentLateralMode
void SendToServer(void *pData, DWORD dwSize, bool bGuaranteed, PacketOrdering order=ORDERING_NONE) const
Definition: Networking.cpp:59
char startcycle
Definition: globals.h:608
char bays
Definition: globals.h:627
int flapMaxDegrees
Definition: globals.h:692
long topscroll
Definition: globals.cpp:94
bool wheeled
Definition: globals.h:605
float verticalincr
Definition: keyboard.h:22
scanDb Scanner
Definition: Bus.h:379
InformationDialog * informationDialog
Definition: gui.h:789
void AutopilotDisconnect() const
Definition: GameClass.cpp:2233
unsigned short vehicleId
Definition: globals.h:570
char owner[13]
Definition: scanDb.h:21
double precisiony
Definition: globals.h:550
keyboard(Viewscreen *ptr)
Definition: keyboard.cpp:6
s_network_objects playerships[MAX_SCAN]
Definition: globals.cpp:174
short texturelib
Definition: globals.h:612
~keyboard()
Definition: keyboard.cpp:12
bool DorOn
Definition: Bus.h:130
float leftright
Definition: Viewscreen.h:311
float VerticalSpeedKms
Definition: Bus.h:351
float rollInput
Definition: Viewscreen.h:237
float RollAttitudeRadians
Definition: Bus.h:37
weapon * ptrWeapon
Definition: Viewscreen.h:280
float updown
Definition: Viewscreen.h:312
float DesiredCourseRadians
Definition: Bus.h:115
float rcsThrustRequestY
Definition: Viewscreen.h:239
InputConfig inputConfigRoll
Definition: config.h:27
short scanslot[MAX_SCAN]
Definition: Viewscreen.h:276
void SendEvent(EventType eventType, float extent=0.0f) const
Definition: Networking.cpp:111
void ChangePage(std::string screenName, std::string pageName)
Definition: Displays.cpp:491
bool sentgearvoice
Definition: globals.h:623
float DesiredRollRadians
Definition: Bus.h:116
float turnin
Definition: globals.h:661
float DesiredIasKms
Definition: Bus.h:120
char g_bTextInput
Definition: globals.cpp:108
int linecursel
Definition: DialogBase.h:73
void Update(float fElapsedTime)
Definition: keyboard.cpp:156
short activetab
Definition: DialogBase.h:62
char reference
Definition: scanDb.h:19
bool showKeymapOverlay
Definition: GameClass.h:131
float moving
Definition: globals.h:660
unsigned short vehicleId
Definition: scanDb.h:15
D3DXVECTOR3 veliter
Definition: globals.h:541
std::string name
Definition: Command.h:11
float DesiredClosingSpeed
Definition: Bus.h:127
bool ThrustReverserCommand[MAX_ENGINES]
Definition: Bus.h:61
void TurnLeft(float f_temp) const
Definition: keyboard.cpp:93
static DialogBase * dialogs[D_ENUMERATION]
Definition: DialogBase.h:39
bool reposess
Definition: scanDb.h:25
propulsion * ptrPropulsion
Definition: Viewscreen.h:285
bool TurnOffDOR() const
Definition: GameClass.cpp:2262
void InsertUpdateModeAC(USHORT vehicleId, SmodeAC modeAC)
Definition: scanDb.cpp:23
float DesiredPitchRadians
Definition: Bus.h:117
std::string TogglePage(std::string screenName)
Definition: Displays.cpp:532
InputConfig inputConfigPitchTrim
Definition: config.h:39
Viewscreen * viewscreen
Definition: keyboard.h:18
bool IsAdmin
Definition: gui.h:777
float IndicatedAirspeedKms
Definition: Bus.h:27
Viewscreen * viewscreen
Definition: GameClass.h:111
D3DXVECTOR3 posleft
Definition: globals.h:541
bool HandleKeyPress(short key, bool shift)
Definition: Displays.cpp:462
void ClearChildren(unsigned short parentId)
Definition: scanDb.cpp:14
unsigned char ourplayerC
Definition: gui.h:766
Networking * networking
Definition: GameClass.h:107
bool PopUpHelp(short helpId, bool allowDismiss=true, bool isLearnMore=false)
float f_MSL
Definition: globals.cpp:36
bool outside
Definition: Viewscreen.h:272
double precisionx
Definition: globals.h:550
SPlayerData player[MAX_ONLINEPLAYERS]
Definition: gui.h:765
float Clamp(float val, float min, float max)
Definition: MathUtilities.h:3
void ChangeCockpit()
Definition: Displays.cpp:318
void RepairVehicle() const
Definition: GameClass.cpp:168
float bear
Definition: globals.cpp:58
float MapScaleInnerRingKm
Definition: Bus.h:381
InputConfig inputConfigPitch
Definition: config.h:26
bool Editing
Definition: gui.h:778
bool FlightFreeze
Definition: Bus.h:374
LateralModes
Definition: Bus.h:94
char engines
Definition: globals.h:627
float pitchInput
Definition: Viewscreen.h:237
float verticaltime
Definition: Viewscreen.h:243
bool spaceCapable
Definition: globals.h:605
Definition: Command.h:5
short targetC
Definition: Bus.h:378
bool MasterWarning
Definition: Bus.h:148
static void SetScrollLock(bool setState)
Definition: keyboard.cpp:1655
HRESULT Initialize(HWND hDlg)
Definition: keyboard.cpp:18
char hullname[23]
Definition: globals.h:535
float chairfwd
Definition: globals.h:616
enum Bus::Afcs::VerticalModes CurrentVerticalMode
float uptranslimit
Definition: globals.h:610
float lrtranslimit
Definition: globals.h:610
const D3DXVECTOR3 centerC
void FlightDirectorOn() const
Definition: GameClass.cpp:1660
std::string TogglePageReverse(std::string screenName)
Definition: Displays.cpp:555
D3DXVECTOR3 velocity
Definition: globals.h:540
Sound * sound
Definition: GameClass.h:108
float GetAttenuation(bool applyDensity) const
Definition: Sound.cpp:1062
void LoadVehicleProfile(short t, bool forceCockpitTextures=false)
static D3DXVECTOR3 CalculateBarycentric(D3DXVECTOR3 *position, D3DXVECTOR3 *gthrust, float *radius)
CHATCHANNEL chatchannel[MAX_TAB]
Definition: gui.h:768
D3DXVECTOR3 velleft
Definition: globals.h:541
void Log(const char *msg, Level level=Info, int errorCode=0)
Definition: Logger.cpp:11
void OutsideView(bool outside)
Definition: framemove.cpp:254
Definition: scanDb.h:13
char hullname[23]
Definition: scanDb.h:18
LPDIRECTINPUT8 g_pDI
Definition: Viewscreen.h:96
float DesiredAltitudeKm
Definition: Bus.h:118
unsigned char hitpoints
Definition: globals.h:663
bool MasterCaution
Definition: Bus.h:375
bool turnByTurnDirty
Definition: Bus.h:398
D3DXVECTOR3 dockMarker
Definition: globals.cpp:46
float rcsThrustRequestX
Definition: Viewscreen.h:239
PEOPLE people
Definition: gui.h:769
bool TvmOn
Definition: Bus.h:126
int CurrentScanTarget
Definition: scanDb.h:66
float Play(int soundEnum)
Definition: Sound.cpp:577
unsigned char type
Definition: globals.h:532
bool YawDamperStatus
Definition: Bus.h:333
int ownerId
Definition: scanDb.h:22
float DesiredHeadingRadians
Definition: Bus.h:114
char GetAlignment(int ownerId) const
Definition: people.h:196
HMI * GUI
Definition: GameClass.h:110
D3DXVECTOR3 positer
Definition: globals.h:541
short ourplyrC
Definition: globals.h:659
float GroundSpeedKms
Definition: Bus.h:156
float dockprogress
Definition: globals.cpp:44
char dead
Definition: globals.cpp:49
#define trimlimiterC
Definition: globals.h:33
D3DXVECTOR3 accleft
Definition: globals.h:542
bool AutopilotEngaged
Definition: Bus.h:74
void TurnRight(float f_temp) const
Definition: keyboard.cpp:125
float GetTotalThrust() const
void Stop(int soundEnum)
Definition: Sound.cpp:1946
D3DXVECTOR3 barycentric
Definition: globals.h:540
float rcsThrustRequestZ
Definition: Viewscreen.h:239
bool tow
Definition: scanDb.h:24
float lampTest
Definition: Viewscreen.h:271
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
bool parkingBrake
Definition: globals.h:685
VerticalModes
so I guess we allow them to fly until they get to x degrees off
Definition: Bus.h:80
float LeftBrake
Definition: Bus.h:289
char owner[13]
Definition: globals.h:585
bool gndvehicle
Definition: globals.h:604
InputConfig inputConfigYaw
Definition: config.h:28
bool g_bShift
Definition: globals.cpp:126
Bus * bus
Definition: GameClass.h:112
void FireWeapon(unsigned char bay) const
Definition: weapon.cpp:599
long scanscroll
Definition: globals.cpp:93
float lateraltime
Definition: Viewscreen.h:243
void RequestVerbiage(int helpId) const
Definition: Networking.cpp:168
float insthdgDegrees
Definition: Viewscreen.h:234
char gearshift
Definition: globals.h:652
float dntranslimit
Definition: globals.h:610
Logger * logger
Definition: Viewscreen.h:293
double precisionz
Definition: globals.h:550
Displays * displays
Definition: GameClass.h:114
float lateralincr
Definition: keyboard.h:21
void Brake(float f_temp) const
Definition: keyboard.cpp:77
bool g_bControl
Definition: globals.cpp:127
float PitchAttitudeRadians
Definition: Bus.h:36
D3DXVECTOR3 dockoffset
Definition: globals.h:549
float f_AGL
Definition: globals.cpp:14
float EngineThrustLever[MAX_ENGINES]
Definition: Bus.h:264
SVesselDC vdat
Definition: globals.h:669