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