2502
|
1 #define _CRTDBG_MAP_ALLOC
|
|
2 #include <stdlib.h>
|
|
3 #include <crtdbg.h>
|
|
4
|
|
5 #define _CRT_SECURE_NO_WARNINGS
|
2541
|
6
|
|
7 #include "Engine/Engine.h"
|
|
8
|
2502
|
9 #include "Keyboard.h"
|
|
10 #include "GUI/GUIWindow.h"
|
|
11
|
|
12 #include "Engine/Graphics/Vis.h"
|
|
13 #include "Engine/Objects/Actor.h"
|
|
14 #include "Engine/Party.h"
|
|
15 #include "Engine/Timer.h"
|
|
16 #include "Engine/TurnEngine/TurnEngine.h"
|
|
17 #include "Engine/Graphics/Weather.h"
|
|
18 #include "Engine/Spells/CastSpellInfo.h"
|
|
19 #include "Engine/Graphics/Indoor.h"
|
|
20 #include "Engine/Registry.h"
|
|
21
|
|
22 #include <tuple>
|
|
23 #include <vector>
|
|
24 #include <string>
|
|
25
|
|
26 struct KeyboardActionMapping *pKeyActionMap;
|
|
27
|
|
28
|
|
29 class CKeyListElement
|
|
30 {
|
|
31 public:
|
|
32 std::string m_keyName;
|
|
33 unsigned char m_keyDefaultCode;
|
|
34 unsigned short m_cmdId;
|
|
35 KeyToggleType m_toggType;
|
|
36 CKeyListElement(std::string keyName, unsigned char keyDefaultCode, unsigned short cmdId, KeyToggleType toggType):
|
|
37 m_keyName(keyName),
|
|
38 m_keyDefaultCode(keyDefaultCode),
|
|
39 m_cmdId(cmdId),
|
|
40 m_toggType(toggType)
|
|
41 {
|
|
42
|
|
43 }
|
|
44 };
|
|
45
|
|
46 std::array<CKeyListElement, 30>keyMappingParams = {
|
|
47 CKeyListElement("KEY_FORWARD", VK_UP, INPUT_MoveForward, TOGGLE_Continuously),
|
|
48 CKeyListElement("KEY_BACKWARD", VK_DOWN, INPUT_MoveBackwards, TOGGLE_Continuously),
|
|
49 CKeyListElement("KEY_LEFT", VK_LEFT, INPUT_TurnLeft, TOGGLE_Continuously),
|
|
50 CKeyListElement("KEY_RIGHT", VK_RIGHT, INPUT_TurnRight, TOGGLE_Continuously),
|
|
51 CKeyListElement("KEY_ATTACK", 'A', INPUT_Attack, TOGGLE_OneTimePress),
|
|
52 CKeyListElement("KEY_CASTREADY", 'S', INPUT_CastReady, TOGGLE_OneTimePress),
|
|
53 CKeyListElement("KEY_YELL", 'Y', INPUT_Yell, TOGGLE_OneTimePress),
|
|
54 CKeyListElement("KEY_JUMP", 'X', INPUT_Jump, TOGGLE_OneTimePress),
|
|
55 CKeyListElement("KEY_COMBAT", VK_RETURN, INPUT_Combat, TOGGLE_OneTimePress),
|
|
56 CKeyListElement("KEY_EVENTTRIGGER", VK_SPACE, INPUT_EventTrigger, TOGGLE_OneTimePress),
|
|
57 CKeyListElement("KEY_CAST", 'C', INPUT_Cast, TOGGLE_OneTimePress),
|
|
58 CKeyListElement("KEY_PASS", 'B', INPUT_Pass, TOGGLE_OneTimePress),
|
|
59 CKeyListElement("KEY_CHARCYCLE", VK_TAB, INPUT_CharCycle, TOGGLE_OneTimePress),
|
|
60 CKeyListElement("KEY_QUEST", 'Q', INPUT_Quest, TOGGLE_OneTimePress),
|
|
61 CKeyListElement("KEY_QUICKREF", 'Z', INPUT_QuickRef, TOGGLE_OneTimePress),
|
|
62 CKeyListElement("KEY_REST", 'R', INPUT_Rest, TOGGLE_OneTimePress),
|
|
63 CKeyListElement("KEY_TIMECAL", 'T', INPUT_TimeCal, TOGGLE_OneTimePress),
|
|
64 CKeyListElement("KEY_AUTONOTES", 'N', INPUT_Autonotes, TOGGLE_OneTimePress),
|
|
65 CKeyListElement("KEY_MAPBOOK", 'M', INPUT_Mapbook, TOGGLE_OneTimePress),
|
|
66 CKeyListElement("KEY_LOOKUP", VK_NEXT, INPUT_LookUp, TOGGLE_OneTimePress),
|
|
67 CKeyListElement("KEY_LOOKDOWN", VK_DELETE, INPUT_LookDown, TOGGLE_OneTimePress),
|
|
68 CKeyListElement("KEY_CENTERVIEWPT", VK_END, INPUT_CenterView, TOGGLE_OneTimePress),
|
|
69 CKeyListElement("KEY_ZOOMIN", VK_ADD, INPUT_ZoomIn, TOGGLE_OneTimePress),
|
|
70 CKeyListElement("KEY_ZOOMOUT", VK_SUBTRACT, INPUT_ZoomOut, TOGGLE_OneTimePress),
|
|
71 CKeyListElement("KEY_FLYUP", VK_PRIOR, INPUT_FlyUp, TOGGLE_Continuously),
|
|
72 CKeyListElement("KEY_FLYDOWN", VK_INSERT, INPUT_FlyDown, TOGGLE_Continuously),
|
|
73 CKeyListElement("KEY_LAND", VK_HOME, INPUT_Land, TOGGLE_OneTimePress),
|
|
74 CKeyListElement("KEY_ALWAYSRUN", 'U', INPUT_AlwaysRun, TOGGLE_OneTimePress),
|
|
75 CKeyListElement("KEY_STEPLEFT", VK_OEM_4, INPUT_StrafeLeft, TOGGLE_Continuously),
|
|
76 CKeyListElement("KEY_STEPRIGHT", VK_OEM_6, INPUT_StrafeRight, TOGGLE_Continuously)
|
|
77 };
|
|
78
|
|
79 std::array<std::tuple<const char*, const unsigned __int8>, 26> keyNameToCodeTranslationMap =
|
|
80 {
|
|
81 std::tuple<const char*, const unsigned __int8>("UP", VK_UP),
|
|
82 std::tuple<const char*, const unsigned __int8>("DOWN", VK_DOWN),
|
|
83 std::tuple<const char*, const unsigned __int8>("LEFT", VK_LEFT),
|
|
84 std::tuple<const char*, const unsigned __int8>("бкебн", VK_LEFT),
|
|
85 std::tuple<const char*, const unsigned __int8>("RIGHT", VK_RIGHT),
|
|
86 std::tuple<const char*, const unsigned __int8>("бопюбн", VK_RIGHT),
|
|
87 std::tuple<const char*, const unsigned __int8>("RETURN", VK_RETURN),
|
|
88 std::tuple<const char*, const unsigned __int8>("SPACE", VK_SPACE),
|
|
89 std::tuple<const char*, const unsigned __int8>("PAGE_DOWN", VK_NEXT),
|
|
90 std::tuple<const char*, const unsigned __int8>("PAGE_UP", VK_PRIOR),
|
|
91 std::tuple<const char*, const unsigned __int8>("TAB", VK_TAB),
|
|
92 std::tuple<const char*, const unsigned __int8>("SUBTRACT", VK_SUBTRACT),
|
|
93 std::tuple<const char*, const unsigned __int8>("ADD", VK_ADD),
|
|
94 std::tuple<const char*, const unsigned __int8>("END", VK_END),
|
|
95 std::tuple<const char*, const unsigned __int8>("DELETE", VK_DELETE),
|
|
96 std::tuple<const char*, const unsigned __int8>("HOME", VK_HOME),
|
|
97 std::tuple<const char*, const unsigned __int8>("INSERT", VK_INSERT),
|
|
98 std::tuple<const char*, const unsigned __int8>("COMMA", VK_OEM_COMMA),
|
|
99 std::tuple<const char*, const unsigned __int8>("DECIMAL", VK_DECIMAL),
|
|
100 std::tuple<const char*, const unsigned __int8>("SEMICOLON", VK_OEM_1),
|
|
101 std::tuple<const char*, const unsigned __int8>("PERIOD", VK_OEM_PERIOD),
|
|
102 std::tuple<const char*, const unsigned __int8>("SLASH", VK_OEM_2),
|
|
103 std::tuple<const char*, const unsigned __int8>("SQUOTE", VK_OEM_7),
|
|
104 std::tuple<const char*, const unsigned __int8>("BACKSLASH", VK_OEM_5),
|
|
105 std::tuple<const char*, const unsigned __int8>("BACKSPACE", VK_BACK),
|
|
106 std::tuple<const char*, const unsigned __int8>("CONTROL", VK_CONTROL),
|
|
107 };
|
|
108
|
|
109 //----- (00459C68) --------------------------------------------------------
|
|
110 void KeyboardActionMapping::SetKeyMapping(int uAction, int vKey, KeyToggleType type)
|
|
111 {
|
|
112 pVirtualKeyCodesMapping[uAction] = vKey;
|
|
113 pToggleTypes[uAction] = type;
|
|
114 }
|
|
115
|
|
116 //----- (00459C82) --------------------------------------------------------
|
|
117 unsigned int KeyboardActionMapping::GetActionVKey(enum InputAction eAction)
|
|
118 {
|
|
119 return this->pVirtualKeyCodesMapping[eAction];
|
|
120 }
|
|
121
|
|
122 //----- (00459C8D) --------------------------------------------------------
|
|
123 KeyboardActionMapping::KeyboardActionMapping()
|
|
124 {
|
|
125 uLastKeyPressed = 0;
|
|
126 field_204 = 0;
|
|
127 pWindow = nullptr;
|
|
128
|
|
129 SetDefaultMapping();
|
|
130 ReadMappings();
|
|
131
|
|
132 ResetKeys();
|
|
133
|
|
134 uNumKeysPressed = 0;
|
|
135
|
|
136 uGameMenuUI_CurentlySelectedKeyIdx = -1;
|
|
137 }
|
|
138 // 506E68: using guessed type int uGameMenuUI_CurentlySelectedKeyIdx;
|
|
139
|
|
140 //----- (00459CC4) --------------------------------------------------------
|
|
141 void KeyboardActionMapping::SetDefaultMapping()
|
|
142 {
|
|
143 for ( size_t i = 0; i < keyMappingParams.size(); i++)
|
|
144 {
|
|
145 SetKeyMapping(keyMappingParams[i].m_cmdId, keyMappingParams[i].m_keyDefaultCode, keyMappingParams[i].m_toggType);
|
|
146 }
|
|
147 }
|
|
148
|
|
149 //----- (00459E3F) --------------------------------------------------------
|
|
150 void KeyboardActionMapping::ResetKeys()
|
|
151 {
|
|
152 for (uint i = 0; i < 30; ++i)
|
|
153 GetAsyncKeyState(pVirtualKeyCodesMapping[i]);
|
|
154 }
|
|
155
|
|
156 //----- (00459E5A) --------------------------------------------------------
|
|
157 void KeyboardActionMapping::EnterText(int a2, int max_string_len, GUIWindow *pWindow)
|
|
158 {
|
|
159 memset(this->pPressedKeysBuffer, 0, 0x101u);
|
|
160 this->uNumKeysPressed = 0;
|
|
161 if ( a2 )
|
|
162 this->field_204 = 2;
|
|
163 else
|
|
164 this->field_204 = 1;
|
|
165 this->max_input_string_len = max_string_len;
|
|
166 this->pWindow = pWindow;
|
|
167 pWindow->receives_keyboard_input_2 = WINDOW_INPUT_IN_PROGRESS;
|
|
168 }
|
|
169
|
|
170 //----- (00459ED1) --------------------------------------------------------
|
|
171 void KeyboardActionMapping::SetWindowInputStatus(int a2)
|
|
172 {
|
|
173 field_204 = 0;
|
|
174 if ( pWindow )
|
|
175 pWindow->receives_keyboard_input_2 = a2;
|
|
176 }
|
|
177
|
|
178 //----- (00459F10) --------------------------------------------------------
|
|
179 bool KeyboardActionMapping::ProcessTextInput(unsigned int a2)
|
|
180 {
|
|
181 pKeyActionMap->uLastKeyPressed = a2;
|
|
182 if ( uGameMenuUI_CurentlySelectedKeyIdx == -1 )
|
|
183 {
|
|
184 if ( pKeyActionMap->field_204 != 1 && pKeyActionMap->field_204 != 2 )
|
|
185 return 0;
|
|
186 if ( a2 == VK_BACK)
|
|
187 {
|
|
188 if (pKeyActionMap->uNumKeysPressed > 0)
|
|
189 {
|
|
190 --pKeyActionMap->uNumKeysPressed;
|
|
191 pKeyActionMap->pPressedKeysBuffer[pKeyActionMap->uNumKeysPressed] = 0;
|
|
192 }
|
|
193 }
|
|
194 else if ( a2 == VK_RETURN )
|
|
195 pKeyActionMap->SetWindowInputStatus(WINDOW_INPUT_CONFIRMED);
|
|
196 else if ( a2 == VK_ESCAPE )
|
|
197 pKeyActionMap->SetWindowInputStatus(WINDOW_INPUT_CANCELLED);
|
|
198 else if (this->uNumKeysPressed < this->max_input_string_len)
|
|
199 {
|
|
200 if ( pKeyActionMap->field_204 == 1 )
|
|
201 {
|
|
202 if ( a2 != VK_TAB )
|
|
203 {
|
|
204 pKeyActionMap->pPressedKeysBuffer[pKeyActionMap->uNumKeysPressed] = a2;
|
|
205 ++pKeyActionMap->uNumKeysPressed;
|
|
206 pKeyActionMap->pPressedKeysBuffer[pKeyActionMap->uNumKeysPressed] = 0;
|
|
207 }
|
|
208 }
|
|
209 else if (pKeyActionMap->field_204 == 2)
|
|
210 {
|
|
211 if ( isdigit(a2))
|
|
212 {
|
|
213 pKeyActionMap->pPressedKeysBuffer[pKeyActionMap->uNumKeysPressed] = a2;
|
|
214 ++pKeyActionMap->uNumKeysPressed;
|
|
215 }
|
|
216 }
|
|
217 }
|
|
218 }
|
|
219 else
|
|
220 {
|
|
221 pKeyActionMap->pPressedKeysBuffer[pKeyActionMap->uNumKeysPressed] = a2;
|
|
222 ++pKeyActionMap->uNumKeysPressed;
|
|
223 pKeyActionMap->pPressedKeysBuffer[pKeyActionMap->uNumKeysPressed] = 0;
|
|
224 pKeyActionMap->SetWindowInputStatus(WINDOW_INPUT_CONFIRMED);
|
|
225 }
|
|
226 return 1;
|
|
227 }
|
|
228 // 506E68: using guessed type int uGameMenuUI_CurentlySelectedKeyIdx;
|
|
229
|
|
230 //----- (00459FFC) --------------------------------------------------------
|
|
231 void KeyboardActionMapping::ReadMappings()
|
|
232 {
|
|
233 char str[32];
|
|
234
|
|
235 for (size_t i = 0; i < keyMappingParams.size(); i++)
|
|
236 {
|
|
237 const char* keyName = keyMappingParams[i].m_keyName.c_str();
|
|
238 short commandDefaultKeyCode = keyMappingParams[i].m_keyDefaultCode;
|
|
239 short commandId = keyMappingParams[i].m_cmdId;
|
|
240 KeyToggleType toggType = keyMappingParams[i].m_toggType;
|
|
241
|
|
242 ReadWindowsRegistryString(keyName, str, 32, "DEFAULT");
|
|
243 if ( strcmp(str, "DEFAULT") && ( TranslateKeyNameToKeyCode(str) != -1) )
|
|
244 pVirtualKeyCodesMapping[commandId] = TranslateKeyNameToKeyCode(str);
|
|
245 else
|
|
246 pVirtualKeyCodesMapping[commandId] = commandDefaultKeyCode;
|
|
247 pToggleTypes[commandId] = toggType;
|
|
248 }
|
|
249
|
|
250 bAlwaysRun = ReadWindowsRegistryInt("valAlwaysRun", 0) != 0;
|
|
251 bFlipOnExit = ReadWindowsRegistryInt("FlipOnExit", 0) != 0;
|
|
252 }
|
|
253
|
|
254 //----- (0045A960) --------------------------------------------------------
|
|
255 void KeyboardActionMapping::StoreMappings()
|
|
256 {
|
|
257
|
|
258 const char *v2; // eax@1
|
|
259
|
|
260 for ( size_t i = 0; i < keyMappingParams.size(); i++)
|
|
261 {
|
|
262 v2 = GetVKeyDisplayName(pVirtualKeyCodesMapping[keyMappingParams[i].m_cmdId]);
|
|
263 WriteWindowsRegistryString(keyMappingParams[i].m_keyName.c_str(), v2);
|
|
264 }
|
|
265 }
|
|
266
|
|
267 //----- (0045ABCA) --------------------------------------------------------
|
|
268 const unsigned __int8 KeyboardActionMapping::TranslateKeyNameToKeyCode(const char *Str)
|
|
269 {
|
|
270 if (strlen(Str) == 1)
|
|
271 {
|
|
272 if( Str[0] >= 65 && Str[0] <= 90 )
|
|
273 return *Str;
|
|
274 else
|
|
275 return 0xFF;
|
|
276 }
|
|
277
|
|
278 for ( size_t i = 0; i < keyNameToCodeTranslationMap.size(); i++)
|
|
279 {
|
|
280 if (!strcmp(Str, std::get<0>(keyNameToCodeTranslationMap[i])))
|
|
281 return std::get<1>(keyNameToCodeTranslationMap[i]);
|
|
282 }
|
|
283 return 0xFF;
|
|
284 }
|
|
285
|
|
286 //----- (0045AE2C) --------------------------------------------------------
|
|
287 const char * KeyboardActionMapping::GetVKeyDisplayName(unsigned char a1)
|
|
288 {
|
|
289 static char static_sub_45AE2C_string_69ADE0_keyName[32];
|
|
290
|
|
291 if ( a1 >= 65 && a1 <= 90 )
|
|
292 {
|
|
293 static_sub_45AE2C_string_69ADE0_keyName[0] = a1;
|
|
294 static_sub_45AE2C_string_69ADE0_keyName[1] = '\0';
|
|
295 return static_sub_45AE2C_string_69ADE0_keyName;
|
|
296 }
|
|
297
|
|
298 for ( size_t i = 0; i < keyNameToCodeTranslationMap.size(); i++)
|
|
299 {
|
|
300 if ( a1 == std::get<1>(keyNameToCodeTranslationMap[i]))
|
|
301 {
|
|
302 const char* keyName = std::get<0>(keyNameToCodeTranslationMap[i]);
|
|
303 strcpy_s(static_sub_45AE2C_string_69ADE0_keyName, keyName);
|
|
304 return static_sub_45AE2C_string_69ADE0_keyName;
|
|
305 }
|
|
306 }
|
|
307
|
|
308 strcpy_s(static_sub_45AE2C_string_69ADE0_keyName, "-мер -");
|
|
309 return static_sub_45AE2C_string_69ADE0_keyName;
|
|
310 }
|
|
311
|
|
312
|
|
313 //----- (0045B019) --------------------------------------------------------
|
|
314 void Keyboard::EnterCriticalSection()
|
|
315 {
|
|
316 }
|
|
317
|
|
318 //----- (0045B06E) --------------------------------------------------------
|
|
319 bool Keyboard::IsShiftHeld()
|
|
320 {
|
|
321 return (GetAsyncKeyState(VK_SHIFT) & 0x8001) != 0;
|
|
322 }
|
|
323
|
|
324 //----- (0045B0A9) --------------------------------------------------------
|
|
325 bool Keyboard::IsKeyBeingHeld(int vKey)
|
|
326 {
|
|
327 return (GetAsyncKeyState(vKey) & 0x8001) != 0;
|
|
328 }
|
|
329
|
|
330 //----- (0045B0CE) --------------------------------------------------------
|
|
331 bool Keyboard::WasKeyPressed(int vKey)
|
|
332 {
|
|
333 return (GetAsyncKeyState(vKey) & 1) != 0;
|
|
334 }
|
|
335 //----- (0046A14B) --------------------------------------------------------
|
|
336 void OnPressSpace()
|
|
337 {
|
|
338
|
|
339 //if ( pRenderer->pRenderD3D )
|
|
340 {
|
2541
|
341 pEngine->PickKeyboard(Keyboard::IsKeyBeingHeld(VK_CONTROL), &vis_sprite_filter_3, &vis_door_filter);
|
|
342 int pid = pEngine->pVisInstance->get_picked_object_zbuf_val();
|
2502
|
343 if ( pid != -1 )
|
|
344 DoInteractionWithTopmostZObject(pid & 0xFFFF, PID_ID(pid));
|
|
345 return;
|
|
346 }
|
|
347
|
|
348
|
|
349 // software render stuff following
|
|
350 /*
|
|
351 static int dword_720660[100]; // 720660
|
|
352 static int dword_7207F0[100]; // 7207F0
|
|
353
|
|
354 v22 = 0;
|
|
355 v1 = (int *)((signed int)(viewparams->uScreen_BttmR_X + viewparams->uScreen_topL_X) >> 1);//wrong pointer
|
|
356 if ( (signed int)viewparams->uScreen_topL_Y < (signed int)viewparams->uScreen_BttmR_Y )
|
|
357 {
|
|
358 v2 = (char *)v1 - 50;
|
|
359 v1 = (int *)((char *)v1 + 50);
|
|
360 v3 = 640 * viewparams->uScreen_topL_Y;
|
|
361 v17 = v2;
|
|
362 v20 = v1;
|
|
363 v18 = ((viewparams->uScreen_BttmR_Y - viewparams->uScreen_topL_Y - 1) >> 1) + 1;
|
|
364 do
|
|
365 {
|
|
366 if ( (signed int)v2 < (signed int)v20 )
|
|
367 {
|
|
368 v1 = &pRenderer->pActiveZBuffer[(int)&v2[v3]];
|
|
369 v21 = &pRenderer->pActiveZBuffer[(int)&v2[v3]];
|
|
370 v4 = v22;
|
|
371 v5 = (((char *)v20 - v2 - 1) >> 1) + 1;
|
|
372 do
|
|
373 {
|
|
374 v6 = 0;
|
|
375 v7 = *v1 & 0xFFFF;
|
|
376 v19 = 0;
|
|
377 if ( v4 > 0 )
|
|
378 {
|
|
379 do
|
|
380 {
|
|
381 if ( dword_7207F0[v6] == v7 )
|
|
382 break;
|
|
383 ++v6;
|
|
384 v19 = v6;
|
|
385 }
|
|
386 while ( v6 < v22 );
|
|
387 }
|
|
388 if ( PID_TYPE(v7) == OBJECT_Decoration)
|
|
389 {
|
|
390 v16 = (unsigned int)PID_ID(v7);
|
|
391 if ( (signed int)(((unsigned int)*v21 >> 16)
|
|
392 - pDecorationList->pDecorations[pLevelDecorations[(unsigned int)PID_ID(v7)].uDecorationDescID].uRadius) <= 512 )
|
|
393 if ( v19 == v22 && v4 < 100 )
|
|
394 {
|
|
395 ++v22;
|
|
396 ++v4;
|
|
397 v8 = *v21;
|
|
398 dword_7207F0[v4 - 1] = v7;
|
|
399 dword_720660[v4 - 1] = v8;
|
|
400 }
|
|
401 }
|
|
402 else if ( (unsigned int)*v21 <= 0x2000000 )
|
|
403 {
|
|
404 if ( v19 == v22 && v4 < 100 )
|
|
405 {
|
|
406 ++v22;
|
|
407 ++v4;
|
|
408 v8 = *v21;
|
|
409 dword_7207F0[v4 - 1] = v7;
|
|
410 dword_720660[v4 - 1] = v8;
|
|
411 }
|
|
412 }
|
|
413 v1 = v21 + 2;
|
|
414 --v5;
|
|
415 v21 += 2;
|
|
416 }
|
|
417 while ( v5 );
|
|
418 v2 = v17;
|
|
419 }
|
|
420 v3 += 1280;
|
|
421 --v18;
|
|
422 }
|
|
423 while ( v18 );
|
|
424 }
|
|
425 if ( v22 > 0 )
|
|
426 {
|
|
427 v9 = dword_720660;
|
|
428 v10 = 1;
|
|
429 do
|
|
430 {
|
|
431 for ( i = v10; i < v22; ++i )
|
|
432 {
|
|
433 v12 = *v9;
|
|
434 v13 = dword_720660[i];
|
|
435 if ( v13 < *v9 )
|
|
436 {
|
|
437 *v9 = v13;
|
|
438 dword_720660[i] = v12;
|
|
439 }
|
|
440 }
|
|
441 ++v10;
|
|
442 ++v9;
|
|
443 LOBYTE(v1) = v10 - 1;
|
|
444 }
|
|
445 while ( v10 - 1 < v22 );
|
|
446 }
|
|
447 for ( j = 0; j < v22; ++j )
|
|
448 {
|
|
449 LOBYTE(v1) = DoInteractionWithTopmostZObject(dword_720660[j] & 0xFFFF, v16);
|
|
450 if ( !(char)v1 )
|
|
451 break;
|
|
452 }*/
|
|
453 }
|
|
454
|
|
455
|
|
456 //----- (0042FC4E) --------------------------------------------------------
|
|
457 void Keyboard::ProcessInputActions()
|
|
458 {
|
|
459 char v4; // al@9
|
|
460 unsigned __int16 v9; // ax@102
|
|
461 int spell_price; // eax@103
|
|
462 PartyAction partyAction; // [sp-14h] [bp-1Ch]@20
|
|
463 InputAction inputAction; // [sp+0h] [bp-8h]@7
|
|
464
|
2541
|
465 pEngine->pKeyboardInstance->EnterCriticalSection();
|
|
466 Keyboard* pKeyboard = pEngine->pKeyboardInstance;
|
2502
|
467 if (!bAlwaysRun)
|
|
468 {
|
|
469 if (pKeyboard->IsShiftHeld())
|
|
470 pParty->uFlags2 |= PARTY_FLAGS_2_RUNNING;
|
|
471 else
|
|
472 pParty->uFlags2 &= ~PARTY_FLAGS_2_RUNNING;
|
|
473 }
|
|
474 else
|
|
475 {
|
|
476 if (pKeyboard->IsShiftHeld())
|
|
477 pParty->uFlags2 &= ~PARTY_FLAGS_2_RUNNING;
|
|
478 else
|
|
479 pParty->uFlags2 |= PARTY_FLAGS_2_RUNNING;
|
|
480 }
|
|
481
|
|
482 //pParty->uFlags2 |= PARTY_FLAGS_2_RUNNING;
|
|
483
|
|
484
|
|
485 // WUT? double event trigger
|
|
486 /*for ( uint i = 0; i < 30; ++i )
|
|
487 {
|
|
488 if ( pKeyActionMap->pToggleTypes[i] )
|
2541
|
489 v14 = pEngine->pKeyboardInstance->WasKeyPressed(pKeyActionMap->pVirtualKeyCodesMapping[i]);
|
2502
|
490 else
|
2541
|
491 v14 = pEngine->pKeyboardInstance->IsKeyBeingHeld(pKeyActionMap->pVirtualKeyCodesMapping[i]);
|
2502
|
492 if ( v14 )
|
|
493 {
|
2541
|
494 if (current_screen_type == SCREEN_GAME)
|
2502
|
495 {
|
|
496 pMessageQueue_50CBD0->AddGUIMessage(UIMSG_Game_Action, 0, 0);
|
|
497 continue;
|
|
498 }
|
2541
|
499 if ( current_screen_type == SCREEN_NPC_DIALOGUE || current_screen_type == SCREEN_BRANCHLESS_NPC_DIALOG )
|
2502
|
500 {
|
|
501 v15 = pMessageQueue_50CBD0->uNumMessages;
|
|
502 if ( pMessageQueue_50CBD0->uNumMessages )
|
|
503 {
|
|
504 v15 = 0;
|
|
505 if ( pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].field_8 )
|
|
506 {
|
|
507 v15 = 1;
|
|
508 pMessageQueue_50CBD0->uNumMessages = 0;
|
|
509 pMessageQueue_50CBD0->pMessages[v15].eType = UIMSG_Escape;
|
|
510 pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = 0;
|
|
511 *(&pMessageQueue_50CBD0->uNumMessages + 3 * pMessageQueue_50CBD0->uNumMessages + 3) = 0;
|
|
512 ++pMessageQueue_50CBD0->uNumMessages;
|
|
513 continue;
|
|
514 }
|
|
515 pMessageQueue_50CBD0->uNumMessages = 0;
|
|
516 }
|
|
517 //pMessageQueue_50CBD0->AddGUIMessage(UIMSG_Escape, 0, 0);
|
|
518 }
|
|
519 }
|
|
520 }*/
|
|
521 if ( !pEventTimer->bPaused )
|
|
522 {
|
|
523 for ( uint i = 0; i < 30; ++i )
|
|
524 {
|
|
525 inputAction = (InputAction)i;
|
|
526 if ( pKeyActionMap->pToggleTypes[inputAction] )
|
|
527 v4 = pKeyboard->WasKeyPressed(pKeyActionMap->pVirtualKeyCodesMapping[inputAction]);
|
|
528 else
|
|
529 v4 = pKeyboard->IsKeyBeingHeld(pKeyActionMap->pVirtualKeyCodesMapping[inputAction]);
|
|
530 if ( v4 )
|
|
531 {
|
|
532 switch ( inputAction )
|
|
533 {
|
|
534 case INPUT_MoveForward:
|
2541
|
535 if (current_screen_type != SCREEN_GAME)
|
2502
|
536 break;
|
|
537 if (!pParty->bTurnBasedModeOn)
|
|
538 {
|
|
539 if ( pParty->uFlags2 & PARTY_FLAGS_2_RUNNING)
|
|
540 partyAction = PARTY_RunForward;
|
|
541 else
|
|
542 partyAction = PARTY_WalkForward;
|
|
543 pPartyActionQueue->Add(partyAction);
|
|
544 break;
|
|
545 }
|
|
546 if (pTurnEngine->turn_stage != TE_WAIT && pTurnEngine->turn_stage != TE_ATTACK && pTurnEngine->uActionPointsLeft > 0 )
|
|
547 {
|
|
548 pTurnEngine->uActionPointsLeft -= 26;
|
|
549 if ( pParty->uFlags2 & PARTY_FLAGS_2_RUNNING)
|
|
550 partyAction = PARTY_RunForward;
|
|
551 else
|
|
552 partyAction = PARTY_WalkForward;
|
|
553 pPartyActionQueue->Add(partyAction);
|
|
554 break;
|
|
555 }
|
|
556 break;
|
|
557 case INPUT_MoveBackwards:
|
2541
|
558 if (current_screen_type != SCREEN_GAME)
|
2502
|
559 break;
|
|
560 if (!pParty->bTurnBasedModeOn)
|
|
561 {
|
|
562 if ( pParty->uFlags2 & 2 )
|
|
563 partyAction = PARTY_RunBackward;
|
|
564 else
|
|
565 partyAction = PARTY_WalkBackward;
|
|
566 pPartyActionQueue->Add(partyAction);
|
|
567 break;
|
|
568 }
|
|
569 if ( pTurnEngine->turn_stage != TE_WAIT && pTurnEngine->turn_stage != TE_ATTACK && pTurnEngine->uActionPointsLeft > 0 )
|
|
570 {
|
|
571 pTurnEngine->uActionPointsLeft -= 26;
|
|
572 if ( pParty->uFlags2 & 2 )
|
|
573 partyAction = PARTY_RunBackward;
|
|
574 else
|
|
575 partyAction = PARTY_WalkBackward;
|
|
576 pPartyActionQueue->Add(partyAction);
|
|
577 break;
|
|
578 }
|
|
579 break;
|
|
580 case INPUT_StrafeLeft:
|
2541
|
581 if (current_screen_type != SCREEN_GAME)
|
2502
|
582 break;
|
|
583 if (!pParty->bTurnBasedModeOn)
|
|
584 {
|
|
585 partyAction = PARTY_StrafeLeft;
|
|
586 pPartyActionQueue->Add(partyAction);
|
|
587 break;
|
|
588 }
|
|
589 if ( pTurnEngine->turn_stage == TE_WAIT || pTurnEngine->turn_stage == TE_ATTACK || pTurnEngine->uActionPointsLeft <= 0 )
|
|
590 break;
|
|
591 pTurnEngine->uActionPointsLeft -= 26;
|
|
592 partyAction = PARTY_StrafeLeft;
|
|
593 pPartyActionQueue->Add(partyAction);
|
|
594 break;
|
|
595 case INPUT_StrafeRight:
|
2541
|
596 if (current_screen_type != SCREEN_GAME)
|
2502
|
597 break;
|
|
598 if (!pParty->bTurnBasedModeOn)
|
|
599 {
|
|
600 partyAction = PARTY_StrafeRight;
|
|
601 pPartyActionQueue->Add(partyAction);
|
|
602 break;
|
|
603 }
|
|
604 if ( pTurnEngine->turn_stage == TE_WAIT || pTurnEngine->turn_stage == TE_ATTACK || pTurnEngine->uActionPointsLeft <= 0 )
|
|
605 break;
|
|
606 pTurnEngine->uActionPointsLeft -= 26;
|
|
607 partyAction = PARTY_StrafeRight;
|
|
608 pPartyActionQueue->Add(partyAction);
|
|
609 break;
|
|
610 case INPUT_TurnLeft:
|
2541
|
611 if (current_screen_type != SCREEN_GAME)
|
2502
|
612 break;
|
|
613 if ( GetAsyncKeyState(VK_CONTROL) ) // strafing
|
|
614 {
|
|
615 if (pParty->bTurnBasedModeOn)
|
|
616 {
|
|
617 if ( pTurnEngine->turn_stage == TE_WAIT || pTurnEngine->turn_stage == TE_ATTACK || pTurnEngine->uActionPointsLeft <= 0 )
|
|
618 break;
|
|
619 pTurnEngine->uActionPointsLeft -= 26;
|
|
620 }
|
|
621 partyAction = PARTY_StrafeLeft;
|
|
622 }
|
|
623 else
|
|
624 {
|
|
625 if ( pParty->uFlags2 & 2 )
|
|
626 partyAction = PARTY_FastTurnLeft;
|
|
627 else
|
|
628 partyAction = PARTY_TurnLeft;
|
|
629 }
|
|
630 pPartyActionQueue->Add(partyAction);
|
|
631 if (uCurrentlyLoadedLevelType == LEVEL_Outdoor && pWeather->bRenderSnow)
|
|
632 pWeather->OnPlayerTurn(10);
|
|
633 break;
|
|
634 case INPUT_TurnRight:
|
2541
|
635 if (current_screen_type != SCREEN_GAME)
|
2502
|
636 break;
|
|
637 if ( GetAsyncKeyState(VK_CONTROL) ) // strafing
|
|
638 {
|
|
639 if (pParty->bTurnBasedModeOn)
|
|
640 {
|
|
641 if ( pTurnEngine->turn_stage == TE_WAIT || pTurnEngine->turn_stage == TE_ATTACK || pTurnEngine->uActionPointsLeft <= 0 )
|
|
642 break;
|
|
643 pTurnEngine->uActionPointsLeft -= 26;
|
|
644 }
|
|
645 partyAction = PARTY_StrafeRight;
|
|
646 }
|
|
647 else
|
|
648 {
|
|
649 if ( pParty->uFlags2 & 2 )
|
|
650 partyAction = PARTY_FastTurnRight;
|
|
651 else
|
|
652 partyAction = PARTY_TurnRight;
|
|
653 }
|
|
654 pPartyActionQueue->Add(partyAction);
|
|
655 if (uCurrentlyLoadedLevelType == LEVEL_Outdoor && pWeather->bRenderSnow)
|
|
656 pWeather->OnPlayerTurn(-10);
|
|
657 break;
|
|
658 case INPUT_Jump:
|
2541
|
659 if (current_screen_type != SCREEN_GAME || pParty->bTurnBasedModeOn)
|
2502
|
660 break;
|
|
661 partyAction = (PartyAction)12;
|
|
662 pPartyActionQueue->Add(partyAction);
|
|
663 break;
|
|
664 case INPUT_Yell:
|
2541
|
665 if (!current_screen_type && uActiveCharacter)
|
2502
|
666 {
|
|
667 pParty->Yell();
|
|
668 pPlayers[uActiveCharacter]->PlaySound(SPEECH_Yell, 0);
|
|
669 }
|
|
670 break;
|
|
671 case INPUT_Pass:
|
2541
|
672 if ( current_screen_type )
|
2502
|
673 break;
|
|
674 if (pParty->bTurnBasedModeOn && pTurnEngine->turn_stage == TE_MOVEMENT)
|
|
675 {
|
|
676 pTurnEngine->field_18 |= TE_FLAG_8;
|
|
677 break;
|
|
678 }
|
|
679 if ( uActiveCharacter )
|
|
680 {
|
|
681 if ( !pPlayers[uActiveCharacter]->uTimeToRecovery )
|
|
682 {
|
|
683 if ( !pParty->bTurnBasedModeOn )
|
|
684 pPlayers[uActiveCharacter]->SetRecoveryTime((signed __int64)(flt_6BE3A4_debug_recmod1 * (double)pPlayers[uActiveCharacter]->GetAttackRecoveryTime(false) * 2.133333333333333));
|
|
685 CastSpellInfoHelpers::_427D48();
|
|
686 pTurnEngine->ApplyPlayerAction();
|
|
687 }
|
|
688 }
|
|
689 break;
|
|
690 case INPUT_Combat://if press ENTER
|
2541
|
691 if (current_screen_type == SCREEN_GAME)
|
2502
|
692 {
|
|
693 if (pParty->bTurnBasedModeOn)
|
|
694 {
|
|
695 if (pTurnEngine->turn_stage == TE_MOVEMENT || PID_TYPE(pTurnEngine->pQueue[0].uPackedID) == OBJECT_Player)
|
|
696 {
|
|
697 pParty->bTurnBasedModeOn = 0;
|
|
698 pTurnEngine->End(true);
|
|
699 }
|
|
700 }
|
|
701 else
|
|
702 {
|
|
703 pTurnEngine->Start();
|
|
704 pParty->bTurnBasedModeOn = true;
|
|
705 }
|
|
706 }
|
|
707 break;
|
|
708 case INPUT_CastReady:
|
|
709 {
|
2541
|
710 if (current_screen_type != SCREEN_GAME)
|
2502
|
711 break;
|
|
712 if (pParty->bTurnBasedModeOn && pTurnEngine->turn_stage == TE_MOVEMENT)
|
|
713 {
|
|
714 pTurnEngine->field_18 |= TE_FLAG_8;
|
|
715 break;
|
|
716 }
|
|
717 if ( !uActiveCharacter )
|
|
718 break;
|
|
719 uchar quickSpellNumber = pPlayers[uActiveCharacter]->uQuickSpell;
|
|
720 v9 = pPlayers[uActiveCharacter]->pActiveSkills[quickSpellNumber / 11 + 12];
|
|
721 bool enoughMana = false;
|
|
722 if ((v9 & 0x100) != 0)
|
|
723 {
|
|
724 enoughMana = pSpellDatas[quickSpellNumber].uMagisterLevelMana < pPlayers[uActiveCharacter]->sMana;
|
|
725 }
|
|
726 else if ((v9 & 0x80) != 0)
|
|
727 {
|
|
728 enoughMana = pSpellDatas[quickSpellNumber].uMasterLevelMana < pPlayers[uActiveCharacter]->sMana;
|
|
729 }
|
|
730 else if ((v9 & 0x40) != 0)
|
|
731 {
|
|
732 enoughMana = pSpellDatas[quickSpellNumber].uExpertLevelMana < pPlayers[uActiveCharacter]->sMana;
|
|
733 }
|
|
734 else
|
|
735 {
|
|
736 enoughMana = pSpellDatas[quickSpellNumber].uNormalLevelMana < pPlayers[uActiveCharacter]->sMana;
|
|
737 }
|
|
738 if ( !pPlayers[uActiveCharacter]->uQuickSpell || bUnderwater || !enoughMana)
|
|
739 {
|
|
740 pPartyActionQueue = pPartyActionQueue;
|
|
741 pMessageQueue_50CBD0->AddGUIMessage(UIMSG_Attack, 0, 0);
|
|
742 break;
|
|
743 }
|
|
744 else
|
|
745 pMessageQueue_50C9E8->AddGUIMessage(UIMSG_CastQuickSpell, 0, 0);
|
|
746 }
|
|
747 break;
|
|
748 case INPUT_Attack:
|
2541
|
749 if (current_screen_type != SCREEN_GAME)
|
2502
|
750 break;
|
|
751 if (pParty->bTurnBasedModeOn == true && pTurnEngine->turn_stage == TE_MOVEMENT)
|
|
752 {
|
|
753 pTurnEngine->field_18 |= TE_FLAG_8;
|
|
754 break;
|
|
755 }
|
|
756 pMessageQueue_50CBD0->AddGUIMessage(UIMSG_Attack, 0, 0);
|
|
757 break;
|
|
758 case INPUT_EventTrigger:
|
2541
|
759 if (current_screen_type == SCREEN_GAME)
|
2502
|
760 {
|
|
761 pMessageQueue_50CBD0->AddGUIMessage(UIMSG_Game_Action, 0, 0);
|
|
762 break;
|
|
763 }
|
2541
|
764 if ( current_screen_type == SCREEN_NPC_DIALOGUE )
|
2502
|
765 {
|
|
766 if ( pMessageQueue_50CBD0->uNumMessages )
|
|
767 {
|
|
768 pMessageQueue_50CBD0->uNumMessages = 0;
|
|
769 if ( pMessageQueue_50CBD0->pMessages[0].field_8 )
|
|
770 {
|
|
771 pMessageQueue_50CBD0->uNumMessages = 1;
|
|
772 pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].eType = UIMSG_Escape;
|
|
773 pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].param = 0;
|
|
774 pMessageQueue_50CBD0->pMessages[pMessageQueue_50CBD0->uNumMessages].field_8 = 0;
|
|
775 ++pMessageQueue_50CBD0->uNumMessages;
|
|
776 break;
|
|
777 }
|
|
778 break;
|
|
779 }
|
|
780 pMessageQueue_50CBD0->AddGUIMessage(UIMSG_Escape, 0, 0);
|
|
781 }
|
|
782 break;
|
|
783 case INPUT_CharCycle:
|
2541
|
784 if ( current_screen_type == SCREEN_SPELL_BOOK )
|
2502
|
785 break;
|
|
786
|
|
787 pMessageQueue_50C9E8->AddGUIMessage(UIMSG_CycleCharacters, 0, 0);
|
|
788 break;
|
|
789 case INPUT_LookUp:
|
|
790 if ( pEventTimer->bPaused )
|
|
791 break;
|
|
792 partyAction = (PartyAction)7;
|
|
793 pPartyActionQueue->Add(partyAction);
|
|
794 break;
|
|
795 case INPUT_CenterView:
|
|
796 if ( pEventTimer->bPaused )
|
|
797 break;
|
|
798 partyAction = (PartyAction)9;
|
|
799 pPartyActionQueue->Add(partyAction);
|
|
800 break;
|
|
801 case INPUT_LookDown:
|
|
802 if ( pEventTimer->bPaused )
|
|
803 break;
|
|
804 partyAction = (PartyAction)8;
|
|
805 pPartyActionQueue->Add(partyAction);
|
|
806 break;
|
|
807 case INPUT_FlyUp:
|
2541
|
808 if ( current_screen_type || pEventTimer->bPaused )
|
2502
|
809 break;
|
|
810 partyAction = (PartyAction)13;
|
|
811 pPartyActionQueue->Add(partyAction);
|
|
812 break;
|
|
813 case INPUT_Land:
|
2541
|
814 if ( current_screen_type || pEventTimer->bPaused )
|
2502
|
815 break;
|
|
816 partyAction = (PartyAction)15;
|
|
817 pPartyActionQueue->Add(partyAction);
|
|
818 break;
|
|
819 case INPUT_FlyDown:
|
2541
|
820 if ( !current_screen_type && !pEventTimer->bPaused )
|
2502
|
821 {
|
|
822 partyAction = (PartyAction)14;
|
|
823 pPartyActionQueue->Add(partyAction);
|
|
824 }
|
|
825 break;
|
|
826 case INPUT_ZoomIn:
|
|
827 pMessageQueue_50C9E8->AddGUIMessage(UIMSG_ClickZoomOutBtn, 0, 0);
|
|
828 break;
|
|
829 case INPUT_ZoomOut:
|
|
830 pMessageQueue_50C9E8->AddGUIMessage(UIMSG_ClickZoomInBtn, 0, 0);
|
|
831 break;
|
|
832 case INPUT_AlwaysRun:
|
|
833 bAlwaysRun = bAlwaysRun == 0;
|
|
834 break;
|
|
835 default:
|
|
836 break;
|
|
837 }
|
|
838 }
|
|
839 }
|
|
840 }
|
|
841 }
|