Rise
The Vieneo Province
Scanner.cpp
Go to the documentation of this file.
1 #include "../Instrument.h"
2 #include "../../Bus.h"
3 
4 Scanner::Scanner(int prmX, int prmY, float prmXScale, float prmYScale, Bus* prmBus, Logger* prmLogger, DeviceObject* prmDevice, std::vector<Font*> prmFonts) :
5  Instrument(prmX, prmY, prmXScale, prmYScale, prmBus, prmLogger, prmDevice, prmFonts)
6 {
7  logger->AddToCallStack("Scanner::ctor");
8  defaultFont = 0;
9 }
10 
12 {
13  logger->AddToCallStack("Scanner::Render");
14  if (bus->Scanner.CurrentScanTarget == 0)
15  {
16  DrawTextW(L"NO DATA IN BUFFER - USE \"SHIFT+S\" TO SCAN", 0, 0, 0, DT_NOCLIP, 0xFFA0A0A0);
17  return;
18  }
19 
21  if (!scan.initialized)
22  {
23  DrawTextW(L"SCAN IN PROGRESS", 0, 0, 0, DT_NOCLIP, 0xFFA0A0A0);
24  return;
25  }
26 
27  int x = 196;
28  WCHAR str[99];
29  if (scan.scandata.modeAC.type >= VehicleType::PODS_PAX && scan.scandata.modeAC.type < VehicleType::PODS_ENUM)
30  swprintf_s(str, 99, L"PODS%S", scan.scandata.modeAC.IVR);
31  else
32  swprintf_s(str, 99, L"IVR %S", scan.scandata.modeAC.IVR);
33  DrawTextW(str, x, 00, 0, DT_NOCLIP, D3DCOLOR_ARGB(255, 255, 255, 255), 2);
34 
35  if (scan.scandata.modeAC.hullname[0])
36  {
37  if (scan.scandata.modeAC.type == VehicleType::E10 ||
38  scan.scandata.modeAC.type == VehicleType::P13 ||
39  scan.scandata.modeAC.type == VehicleType::A4 ||
40  scan.scandata.modeAC.type == VehicleType::E11 ||
41  scan.scandata.modeAC.type == VehicleType::T19 ||
42  scan.scandata.modeAC.type == VehicleType::W6Manx)
43  swprintf_s(str, 99, L"USV %S", scan.scandata.modeAC.hullname);
44  else
45  swprintf_s(str, 99, L"%S", scan.scandata.modeAC.hullname);
46  DrawTextW(str, x, 30, 0, DT_NOCLIP, D3DCOLOR_ARGB(255, 255, 255, 255), 0);
47  }
48 
49  WCHAR column[99];
50  switch (scan.scandata.modeAC.type)
51  {
52  case VehicleType::C98: swprintf_s(column, 99, L"C-98 MuVER"); break;
53  case VehicleType::E10: swprintf_s(column, 99, L"E-10 Saint"); break;
54  case VehicleType::P13: swprintf_s(column, 99, L"P-13 Prowler"); break;
55  case VehicleType::A4: swprintf_s(column, 99, L"A-4 Wanderer"); break;
56  case VehicleType::C2: swprintf_s(column, 99, L"C-2 Dasher"); break;
57  case VehicleType::T120: swprintf_s(column, 99, L"T-120 Steerhead"); break;
58  case VehicleType::T121: swprintf_s(column, 99, L"T-121 Steerhead"); break;
59  case VehicleType::E11: swprintf_s(column, 99, L"E-11 Saint"); break;
60  case VehicleType::PODS_PAX: swprintf_s(column, 99, L"Passenger"); break;
61  case VehicleType::PODS_CNST: swprintf_s(column, 99, L"Construction"); break;
62  case VehicleType::PODS_CARGOAFT: swprintf_s(column, 99, L"Cargo AFT"); break;
63  case VehicleType::PODS_FUEL: swprintf_s(column, 99, L"Auxiliary Fuel"); break;
64  case VehicleType::PODS_CARGOTOP: swprintf_s(column, 99, L"Cargo TOP"); break;
65  case VehicleType::PODS_MUNITIONS: swprintf_s(column, 99, L"Munitions"); break;
66  case VehicleType::T27: swprintf_s(column, 99, L"T-27 Mammoth"); break;
67  case VehicleType::C2A: swprintf_s(column, 99, L"C-2A Dasher"); break;
68  case VehicleType::W6Manx: swprintf_s(column, 99, L"W-6 Manx"); break;
69  case VehicleType::T19: swprintf_s(column, 99, L"T-19 Stratomaster"); break;
70  default: swprintf_s(column, 99, L"UNKNOWN "); break;
71  }
72  swprintf_s(str, 99, L" Type: %s", column);
73  DrawTextW(str, x, 60, 0, DT_NOCLIP, D3DCOLOR_ARGB(255, 255, 255, 255), 1);
74  swprintf_s(str, 99, L"Registered to: %S", scan.scandata.modeAC.owner);
75  DrawTextW(str, x, 70, 0, DT_NOCLIP, D3DCOLOR_ARGB(255, 255, 255, 255), 1);
76 
77  x = 0;
78  int y = 90;
79  //if (targetC >= 0 && scan.scandata.modeAC.vehicleId == playerships[viewscreen->scanslot[targetC]].vehicleId)
80  {
81  // Don't have to worry about the DIHV
82  // Cash is to anything that can have a player
83  if (scan.scandata.modeAC.type < VehicleType::PODS_PAX || scan.scandata.modeAC.type > VehicleType::PODS_ENUM)
84  DrawTextW(L"Shift+C Cash", x, y += 15, 0, DT_NOCLIP, 0xFF00A0A0, 0);
85  // Fuel is any vehicle or fuel-type-PODS
86  if (scan.scandata.modeAC.type < VehicleType::PODS_PAX || scan.scandata.modeAC.type > VehicleType::PODS_ENUM ||
87  scan.scandata.modeAC.type == VehicleType::PODS_FUEL)
88  DrawTextW(L"Shift+F Fuel", x, y += 15, 0, DT_NOCLIP, 0xFF00A0A0, 0);
89  // Weapons is any vehicle or munitions-type-PODS
90  if (scan.scandata.modeAC.type < VehicleType::PODS_PAX || scan.scandata.modeAC.type > VehicleType::PODS_ENUM ||
91  scan.scandata.modeAC.type == VehicleType::PODS_MUNITIONS)
92  DrawTextW(L"Shift+W Weapon", x, y += 15, 0, DT_NOCLIP, 0xFF00A0A0, 0);
93  if ((scan.scandata.modeAC.type >= VehicleType::PODS_PAX && scan.scandata.modeAC.type < VehicleType::PODS_ENUM) ||
94  scan.scandata.modeAC.type == VehicleType::C2 || scan.scandata.modeAC.type == VehicleType::C2A || scan.scandata.modeAC.type == VehicleType::C98)
95  DrawTextW(L"Shift+L Load", x, y += 15, 0, DT_NOCLIP, 0xFF00A0A0, 0);
96  }
97 
98  // next is picture and mode S data!
99  y = 170;
100  for (UINT i = 0; i < scan.children.size(); i++)
101  {
102  const Sscandata child = scan.children.at(i);
103 
104  if (child.modeAC.type >= 10 && child.modeAC.type < 19)
105  swprintf_s(column, 99, L"PODS%S ", child.modeAC.IVR);
106  else
107  swprintf_s(column, 99, L"IVR %S ", child.modeAC.IVR);
108 
109  DrawTextW(column, x, y, 0, DT_NOCLIP, D3DCOLOR_ARGB(255, 255, 255, 255), 0);
110 
111  if (i == 8)
112  {
113  x = 100; y = 170;
114  }
115  else
116  {
117  y += 15;
118  }
119  }
120 
121  // extended data
122  x = 196;
123  y = 170;
124  if (scan.scandata.modeX.weightLbs.is_set())
125  {
126  swprintf_s(str, 99, L" Weight: %.0f kg", scan.scandata.modeX.weightLbs.get() / Kg2Lbs);
127  DrawTextW(str, 200, y += 10, 0, DT_NOCLIP, D3DCOLOR_ARGB(255, 255, 255, 255), 1);
128  }
129 
130  if (scan.scandata.modeX.fuel_tank.is_set())
131  {
132  swprintf_s(str, 99, L" Fuel Tank: %.0f kg", scan.scandata.modeX.fuel_tank.get());
133  DrawTextW(str, 200, y += 10, 0, DT_NOCLIP, D3DCOLOR_ARGB(255, 255, 255, 255), 1);
134  }
135 
136  if (scan.scandata.modeX.load_type.is_set())
137  {
138  switch (scan.scandata.modeX.load_type.get())
139  {
140  case CargoLoadType::None: swprintf_s(column, 99, L"None"); break;
141  case CargoLoadType::CargoRare: swprintf_s(column, 99, L"Rare"); break;
142  case CargoLoadType::CargoFood: swprintf_s(column, 99, L"Foodstuffs"); break;
143  case CargoLoadType::CargoCommon: swprintf_s(column, 99, L"Common"); break;
144  case CargoLoadType::CargoFuelOre: swprintf_s(column, 99, L"Fuel Ore"); break;
145  case CargoLoadType::CargoGoods: swprintf_s(column, 99, L"Consumer"); break;
146  case CargoLoadType::CargoFab: swprintf_s(column, 99, L"Fabricated"); break;
147  case CargoLoadType::CargoEnum: swprintf_s(column, 99, L"Fuel"); break;
148  case CargoLoadType::Passengers: swprintf_s(column, 99, L"Ticketed"); break;
149  case CargoLoadType::Colonists: swprintf_s(column, 99, L"Laborers"); break;
150  case CargoLoadType::Prisoners: swprintf_s(column, 99, L"Prisoners"); break;
151  case CargoLoadType::Residential: swprintf_s(column, 99, L"Estate"); break;
152  case CargoLoadType::Mining: swprintf_s(column, 99, L"Mine"); break;
153  case CargoLoadType::Farmstead: swprintf_s(column, 99, L"Farmstead"); break;
154  case CargoLoadType::Township: swprintf_s(column, 99, L"Township"); break;
155  case CargoLoadType::Airfield: swprintf_s(column, 99, L"Airfield"); break;
156  case CargoLoadType::WeaponLongarms: swprintf_s(column, 99, L"Longarms"); break;
157  default: swprintf_s(column, 99, L"UNKNOWN"); break;
158  }
159  swprintf_s(str, 99, L" Load Type: %s", column);
160  DrawTextW(str, 200, y += 10, 0, DT_NOCLIP, D3DCOLOR_ARGB(255, 255, 255, 255), 1);
161  }
162 
163  if (scan.scandata.modeX.load_quantity.is_set())
164  {
165  switch (scan.scandata.modeAC.type)
166  {
167  case VehicleType::PODS_CARGOAFT: swprintf_s(column, 99, L"%i MT", scan.scandata.modeX.load_quantity.get()); break;
168  case VehicleType::PODS_CARGOTOP: swprintf_s(column, 99, L"%i MT", scan.scandata.modeX.load_quantity.get()); break;
169  case VehicleType::PODS_FUEL: swprintf_s(column, 99, L"%i kg", scan.scandata.modeX.load_quantity.get()); break;
170  default: swprintf_s(column, 99, L"%i", scan.scandata.modeX.load_quantity.get()); break;
171  }
172  swprintf_s(str, 99, L"Load Quantity: %s", column);
173  DrawTextW(str, 200, y += 10, 0, DT_NOCLIP, D3DCOLOR_ARGB(255, 255, 255, 255), 1);
174  }
175 
176  if (scan.scandata.modeX.load_dest.is_set())
177  {
178  switch (scan.scandata.modeX.load_dest.get())
179  {
180  case 0: swprintf_s(column, 99, L"Undeclared"); break;
181  case 1: swprintf_s(column, 99, L"Deois Transit"); break;
182  case 8: swprintf_s(column, 99, L"CPOC"); break;
183  case 9: swprintf_s(column, 99, L"Easydock"); break;
184  default: swprintf_s(column, 99, L"UNKNOWN"); break;
185  }
186  swprintf_s(str, 99, L" Destination: %s", column);
187  DrawTextW(str, 200, y += 10, 0, DT_NOCLIP, D3DCOLOR_ARGB(255, 255, 255, 255), 1);
188  }
189 }
190 
191 bool Scanner::HandleKeyPress(short key, bool shift)
192 {
193  logger->AddToCallStack("Scanner::HandleKeyPress");
194  if (!shift) return false;
195  if (!bus->Scanner.CurrentScanTarget) return false;
196 
197  switch (key)
198  {
199  case 203:
200  case 75: // arrow left
201  {
202  Command command;
203  command.name = "RestorePage";
204  command.sValue = "MFD";
205  bus->commandStream.emplace_back(command);
206  return true;
207  }
208  //case 200:
209  //case 72: // arrow up
210  // uiRow--;
211  // if (uiRow < 0)
212  // uiRow = 0;
213  // return true;
214  //case 22: // u
215  // /// @todo need to make sure bay doors are open
216  // if (uiRow >= 0 && uiRow < ourcockpit.bays && bus->CargoBays[uiRow] != 0)
217  // {
218  // Command command;
219  // command.name = "UnloadCargoBay";
220  // command.ivalues[0] = uiRow; // bay number starting with 0
221  // command.ivalues[1] = bus->CargoBays[uiRow]; // vehicle ID
222  // bus->commandStream.emplace_back(command);
223  // }
224  // return true;
225  case 33: // f
226  {
227  temptarget = bus->Scanner.CurrentScanTarget; // vehicle ID
228  g_bTextInput = 6;
229  outgoing[0] = 0; // clear buffer
230  sprintf_s(prompt, sizeof(prompt), "[±kg]");
231  return true;
232  }
233  case 46: // c
234  {
235  temptarget = bus->Scanner.CurrentScanTarget; // vehicle ID
236  g_bTextInput = 5;
237  outgoing[0] = 0; // clear buffer
238  sprintf_s(prompt, sizeof(prompt), "[CR]");
239  return true;
240  }
241  case 17: // w
242  {
243  Command command;
244  command.name = "TransferWeapon";
245  command.ivalues[0] = bus->Scanner.CurrentScanTarget; // vehicle ID
246  bus->commandStream.emplace_back(command);
247  return true;
248  }
249  }
250  return false;
251 }
void Render() override
Definition: Scanner.cpp:11
Scanner(int prmX, int prmY, float prmXScale, float prmYScale, Bus *prmBus, Logger *prmLogger, DeviceObject *prmDevice, std::vector< Font *> prmFonts)
Definition: Scanner.cpp:4
Nullable< float > fuel_tank
Definition: scanDb.h:35
char IVR[6]
Definition: scanDb.h:16
unsigned char type
Definition: scanDb.h:17
std::vector< Sscandata > children
Definition: scanDb.h:50
int ivalues[2]
Definition: Command.h:21
std::vector< Command > commandStream
Definition: Bus.h:342
Nullable< float > weightLbs
Definition: scanDb.h:34
Definition: Logger.h:9
scanDb Scanner
Definition: Bus.h:379
char owner[13]
Definition: scanDb.h:21
char g_bTextInput
Definition: globals.cpp:108
Nullable< unsigned short > load_quantity
Definition: scanDb.h:32
Definition: Bus.h:16
std::string name
Definition: Command.h:11
#define Kg2Lbs
Definition: globals.h:31
Bus * bus
Definition: Instrument.h:18
Nullable< short > load_dest
Definition: scanDb.h:33
UINT defaultFont
Definition: Instrument.h:20
char outgoing[80]
Definition: globals.cpp:107
unsigned short temptarget
Definition: globals.cpp:119
Definition: Command.h:5
std::string sValue
Definition: Command.h:20
char hullname[23]
Definition: scanDb.h:18
Logger * logger
Definition: Instrument.h:19
SmodeX modeX
Definition: scanDb.h:43
Sscandata scandata
Definition: scanDb.h:49
int CurrentScanTarget
Definition: scanDb.h:66
bool is_set() const
Definition: Nullable.h:87
SmodeAC modeAC
Definition: scanDb.h:41
Definition: scanDb.h:46
char prompt[80]
Definition: globals.cpp:109
Sscan Get(USHORT vehicleId) const
Definition: scanDb.cpp:87
Nullable< unsigned char > load_type
Definition: scanDb.h:31
void AddToCallStack(const char *msg)
Definition: Logger.cpp:86
bool HandleKeyPress(short key, bool shift) override
Definition: Scanner.cpp:191
bool initialized
Definition: scanDb.h:48
T get() const
Definition: Nullable.h:80