2 Copyright (C) 2003, 2010 - Wolfire Games
4 This file is part of Lugaru.
6 Lugaru is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public License
8 as published by the Free Software Foundation; either version 2
9 of the License, or (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15 See the GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 /**> HEADER FILES <**/
33 extern bool keyboardfrozen;
34 extern bool buttons[3];
35 /********************> IsKeyDown() <*****/
36 Boolean IsKeyDown( unsigned char *keyMap, unsigned short theKey )
38 if(keyboardfrozen)return 0;
39 if(theKey< 0x80 /*1000*/){
40 static long keyMapIndex;
41 static Boolean isKeyDown;
42 static short bitToCheck;
44 // Calculate the key map index
45 keyMapIndex = keyMap[theKey/8];
47 // Calculate the individual bit to check
48 bitToCheck = theKey%8;
50 // Check the status of the key
51 isKeyDown = ( keyMapIndex >> bitToCheck ) & 0x01;
53 // Return the status of the key
56 else if(theKey==MAC_MOUSEBUTTON1)
58 else if(theKey==MAC_MOUSEBUTTON2)
65 unsigned short CharToKey(char* which)
68 if(!stricmp(which,"a")){
71 if(!stricmp(which,"b")){
74 if(!stricmp(which,"c")){
77 if(!stricmp(which,"d")){
80 if(!stricmp(which,"e")){
83 if(!stricmp(which,"f")){
86 if(!stricmp(which,"g")){
89 if(!stricmp(which,"h")){
92 if(!stricmp(which,"i")){
95 if(!stricmp(which,"j")){
98 if(!stricmp(which,"k")){
101 if(!stricmp(which,"l")){
104 if(!stricmp(which,"m")){
107 if(!stricmp(which,"n")){
110 if(!stricmp(which,"o")){
113 if(!stricmp(which,"p")){
116 if(!stricmp(which,"q")){
119 if(!stricmp(which,"r")){
122 if(!stricmp(which,"s")){
125 if(!stricmp(which,"t")){
128 if(!stricmp(which,"u")){
131 if(!stricmp(which,"v")){
134 if(!stricmp(which,"w")){
137 if(!stricmp(which,"x")){
140 if(!stricmp(which,"y")){
143 if(!stricmp(which,"z")){
148 if(!stricmp(which,"KP0")){
149 return MAC_NUMPAD_0_KEY;
151 if(!stricmp(which,"KP1")){
152 return MAC_NUMPAD_1_KEY;
154 if(!stricmp(which,"KP2")){
155 return MAC_NUMPAD_2_KEY;
157 if(!stricmp(which,"KP3")){
158 return MAC_NUMPAD_3_KEY;
160 if(!stricmp(which,"KP4")){
161 return MAC_NUMPAD_4_KEY;
163 if(!stricmp(which,"KP5")){
164 return MAC_NUMPAD_5_KEY;
166 if(!stricmp(which,"KP6")){
167 return MAC_NUMPAD_6_KEY;
169 if(!stricmp(which,"KP7")){
170 return MAC_NUMPAD_7_KEY;
172 if(!stricmp(which,"KP8")){
173 return MAC_NUMPAD_8_KEY;
175 if(!stricmp(which,"KP9")){
176 return MAC_NUMPAD_9_KEY;
180 if(!stricmp(which,"enter")){
181 return MAC_ENTER_KEY;
185 if(!stricmp(which,"0")){
188 if(!stricmp(which,"1")){
191 if(!stricmp(which,"2")){
194 if(!stricmp(which,"3")){
197 if(!stricmp(which,"4")){
200 if(!stricmp(which,"5")){
203 if(!stricmp(which,"6")){
206 if(!stricmp(which,"7")){
209 if(!stricmp(which,"8")){
212 if(!stricmp(which,"9")){
217 if(!stricmp(which,"F1")){
220 if(!stricmp(which,"F2")){
223 if(!stricmp(which,"F3")){
226 if(!stricmp(which,"F4")){
229 if(!stricmp(which,"F5")){
232 if(!stricmp(which,"F6")){
235 if(!stricmp(which,"F7")){
238 if(!stricmp(which,"F8")){
241 if(!stricmp(which,"F9")){
244 if(!stricmp(which,"F10")){
247 if(!stricmp(which,"F11")){
250 if(!stricmp(which,"F12")){
255 if(!stricmp(which,"escape")){
256 return MAC_ESCAPE_KEY;
258 if(!stricmp(which,"backspace")){
259 return MAC_DELETE_KEY;
261 if(!stricmp(which,"tab")){
264 if(!stricmp(which,"`")){
265 return MAC_TILDE_KEY;
267 if(!stricmp(which,"caps_lock")){
268 return MAC_CAPS_LOCK_KEY;
273 if(!stricmp(which,"command")){
274 return MAC_COMMAND_KEY;
276 if(!stricmp(which,"option")){
277 return MAC_OPTION_KEY;
279 if(!stricmp(which,"delete")){
282 if(!stricmp(which,"insert")){
283 return MAC_INSERT_KEY;
285 if(!stricmp(which,"home")){
288 if(!stricmp(which,"end")){
291 if(!stricmp(which,"page_up")){
292 return MAC_PAGE_UP_KEY;
294 if(!stricmp(which,"page_down")){
295 return MAC_PAGE_DOWN_KEY;
297 if(!stricmp(which,"clear")){
298 return MAC_NUMPAD_CLEAR_KEY;
301 if(!stricmp(which,"control")){
302 return MAC_CONTROL_KEY;
304 if(!stricmp(which,"return")){
305 return MAC_RETURN_KEY;
307 if(!stricmp(which,"space")){
308 return MAC_SPACE_KEY;
310 if(!stricmp(which,"shift")){
311 return MAC_SHIFT_KEY;
313 if(!stricmp(which,"uparrow")){
314 return MAC_ARROW_UP_KEY;
316 if(!stricmp(which,"downarrow")){
317 return MAC_ARROW_DOWN_KEY;
319 if(!stricmp(which,"leftarrow")){
320 return MAC_ARROW_LEFT_KEY;
322 if(!stricmp(which,"rightarrow")){
323 return MAC_ARROW_RIGHT_KEY;
325 if(!stricmp(which,"mouse1")){
326 return MAC_MOUSEBUTTON1;
328 if(!stricmp(which,"mouse2")){
329 return MAC_MOUSEBUTTON2;
331 if(!stricmp(which,"+")){
332 return MAC_NUMPAD_PLUS_KEY;
334 if(!stricmp(which,"*")){
335 return MAC_NUMPAD_ASTERISK_KEY;
337 if(!stricmp(which,"/")){
338 return MAC_SLASH_KEY;
340 if(!stricmp(which,"\\")){
341 return MAC_BACKSLASH_KEY;
343 if(!stricmp(which,"[")){
344 return MAC_LEFTBRACKET_KEY;
346 if(!stricmp(which,"]")){
347 return MAC_RIGHTBRACKET_KEY;
349 if(!stricmp(which,".")){
350 return MAC_PERIOD_KEY;
352 if(!stricmp(which,",")){
353 return MAC_COMMA_KEY;
355 if(!stricmp(which,"\"")){
356 return MAC_APOSTROPHE_KEY;
358 if(!stricmp(which,";")){
359 return MAC_SEMICOLON_KEY;
364 unsigned short CharToKey(char* which)
367 if(!strcasecmp(which,"a")){
370 if(!strcasecmp(which,"b")){
373 if(!strcasecmp(which,"c")){
376 if(!strcasecmp(which,"d")){
379 if(!strcasecmp(which,"e")){
382 if(!strcasecmp(which,"f")){
385 if(!strcasecmp(which,"g")){
388 if(!strcasecmp(which,"h")){
391 if(!strcasecmp(which,"i")){
394 if(!strcasecmp(which,"j")){
397 if(!strcasecmp(which,"k")){
400 if(!strcasecmp(which,"l")){
403 if(!strcasecmp(which,"m")){
406 if(!strcasecmp(which,"n")){
409 if(!strcasecmp(which,"o")){
412 if(!strcasecmp(which,"p")){
415 if(!strcasecmp(which,"q")){
418 if(!strcasecmp(which,"r")){
421 if(!strcasecmp(which,"s")){
424 if(!strcasecmp(which,"t")){
427 if(!strcasecmp(which,"u")){
430 if(!strcasecmp(which,"v")){
433 if(!strcasecmp(which,"w")){
436 if(!strcasecmp(which,"x")){
439 if(!strcasecmp(which,"y")){
442 if(!strcasecmp(which,"z")){
447 if(!strcasecmp(which,"KP0")){
448 return MAC_NUMPAD_0_KEY;
450 if(!strcasecmp(which,"KP1")){
451 return MAC_NUMPAD_1_KEY;
453 if(!strcasecmp(which,"KP2")){
454 return MAC_NUMPAD_2_KEY;
456 if(!strcasecmp(which,"KP3")){
457 return MAC_NUMPAD_3_KEY;
459 if(!strcasecmp(which,"KP4")){
460 return MAC_NUMPAD_4_KEY;
462 if(!strcasecmp(which,"KP5")){
463 return MAC_NUMPAD_5_KEY;
465 if(!strcasecmp(which,"KP6")){
466 return MAC_NUMPAD_6_KEY;
468 if(!strcasecmp(which,"KP7")){
469 return MAC_NUMPAD_7_KEY;
471 if(!strcasecmp(which,"KP8")){
472 return MAC_NUMPAD_8_KEY;
474 if(!strcasecmp(which,"KP9")){
475 return MAC_NUMPAD_9_KEY;
479 if(!strcasecmp(which,"enter")){
480 return MAC_ENTER_KEY;
484 if(!strcasecmp(which,"0")){
487 if(!strcasecmp(which,"1")){
490 if(!strcasecmp(which,"2")){
493 if(!strcasecmp(which,"3")){
496 if(!strcasecmp(which,"4")){
499 if(!strcasecmp(which,"5")){
502 if(!strcasecmp(which,"6")){
505 if(!strcasecmp(which,"7")){
508 if(!strcasecmp(which,"8")){
511 if(!strcasecmp(which,"9")){
516 if(!strcasecmp(which,"F1")){
519 if(!strcasecmp(which,"F2")){
522 if(!strcasecmp(which,"F3")){
525 if(!strcasecmp(which,"F4")){
528 if(!strcasecmp(which,"F5")){
531 if(!strcasecmp(which,"F6")){
534 if(!strcasecmp(which,"F7")){
537 if(!strcasecmp(which,"F8")){
540 if(!strcasecmp(which,"F9")){
543 if(!strcasecmp(which,"F10")){
546 if(!strcasecmp(which,"F11")){
549 if(!strcasecmp(which,"F12")){
554 if(!strcasecmp(which,"escape")){
555 return MAC_ESCAPE_KEY;
557 if(!strcasecmp(which,"backspace")){
558 return MAC_DELETE_KEY;
560 if(!strcasecmp(which,"tab")){
563 if(!strcasecmp(which,"`")){
564 return MAC_TILDE_KEY;
566 if(!strcasecmp(which,"caps_lock")){
567 return MAC_CAPS_LOCK_KEY;
572 if(!strcasecmp(which,"command")){
573 return MAC_COMMAND_KEY;
575 if(!strcasecmp(which,"option")){
576 return MAC_OPTION_KEY;
578 if(!strcasecmp(which,"delete")){
581 if(!strcasecmp(which,"insert")){
582 return MAC_INSERT_KEY;
584 if(!strcasecmp(which,"home")){
587 if(!strcasecmp(which,"end")){
590 if(!strcasecmp(which,"page_up")){
591 return MAC_PAGE_UP_KEY;
593 if(!strcasecmp(which,"page_down")){
594 return MAC_PAGE_DOWN_KEY;
596 if(!strcasecmp(which,"clear")){
597 return MAC_NUMPAD_CLEAR_KEY;
600 if(!strcasecmp(which,"control")){
601 return MAC_CONTROL_KEY;
603 if(!strcasecmp(which,"return")){
604 return MAC_RETURN_KEY;
606 if(!strcasecmp(which,"space")){
607 return MAC_SPACE_KEY;
609 if(!strcasecmp(which,"shift")){
610 return MAC_SHIFT_KEY;
612 if(!strcasecmp(which,"uparrow")){
613 return MAC_ARROW_UP_KEY;
615 if(!strcasecmp(which,"downarrow")){
616 return MAC_ARROW_DOWN_KEY;
618 if(!strcasecmp(which,"leftarrow")){
619 return MAC_ARROW_LEFT_KEY;
621 if(!strcasecmp(which,"rightarrow")){
622 return MAC_ARROW_RIGHT_KEY;
624 if(!strcasecmp(which,"mouse1")){
625 return MAC_MOUSEBUTTON1;
627 if(!strcasecmp(which,"mouse2")){
628 return MAC_MOUSEBUTTON2;
630 if(!strcasecmp(which,"+")){
631 return MAC_NUMPAD_PLUS_KEY;
633 if(!strcasecmp(which,"*")){
634 return MAC_NUMPAD_ASTERISK_KEY;
636 if(!strcasecmp(which,"/")){
637 return MAC_SLASH_KEY;
639 if(!strcasecmp(which,"\\")){
640 return MAC_BACKSLASH_KEY;
642 if(!strcasecmp(which,"[")){
643 return MAC_LEFTBRACKET_KEY;
645 if(!strcasecmp(which,"]")){
646 return MAC_RIGHTBRACKET_KEY;
648 if(!strcasecmp(which,".")){
649 return MAC_PERIOD_KEY;
651 if(!strcasecmp(which,",")){
652 return MAC_COMMA_KEY;
654 if(!strcasecmp(which,"\"")){
655 return MAC_APOSTROPHE_KEY;
657 if(!strcasecmp(which,";")){
658 return MAC_SEMICOLON_KEY;
664 char* KeyToChar(unsigned short which)
669 if(which==MAC_A_KEY){
672 if(which==MAC_B_KEY){
675 if(which==MAC_C_KEY){
678 if(which==MAC_D_KEY){
681 if(which==MAC_E_KEY){
684 if(which==MAC_F_KEY){
687 if(which==MAC_G_KEY){
690 if(which==MAC_H_KEY){
693 if(which==MAC_I_KEY){
696 if(which==MAC_J_KEY){
699 if(which==MAC_K_KEY){
702 if(which==MAC_L_KEY){
705 if(which==MAC_M_KEY){
708 if(which==MAC_N_KEY){
711 if(which==MAC_O_KEY){
714 if(which==MAC_P_KEY){
717 if(which==MAC_Q_KEY){
720 if(which==MAC_R_KEY){
723 if(which==MAC_S_KEY){
726 if(which==MAC_T_KEY){
729 if(which==MAC_U_KEY){
732 if(which==MAC_V_KEY){
735 if(which==MAC_W_KEY){
738 if(which==MAC_X_KEY){
741 if(which==MAC_Y_KEY){
744 if(which==MAC_Z_KEY){
749 if(which==MAC_NUMPAD_1_KEY){
752 if(which==MAC_NUMPAD_2_KEY){
755 if(which==MAC_NUMPAD_3_KEY){
758 if(which==MAC_NUMPAD_4_KEY){
761 if(which==MAC_NUMPAD_5_KEY){
764 if(which==MAC_NUMPAD_6_KEY){
767 if(which==MAC_NUMPAD_7_KEY){
770 if(which==MAC_NUMPAD_8_KEY){
773 if(which==MAC_NUMPAD_9_KEY){
776 if(which==MAC_NUMPAD_0_KEY){
781 if(which==MAC_ENTER_KEY){
786 if(which==MAC_1_KEY){
789 if(which==MAC_2_KEY){
792 if(which==MAC_3_KEY){
795 if(which==MAC_4_KEY){
798 if(which==MAC_5_KEY){
801 if(which==MAC_6_KEY){
804 if(which==MAC_7_KEY){
807 if(which==MAC_8_KEY){
810 if(which==MAC_9_KEY){
813 if(which==MAC_0_KEY){
818 if(which==MAC_F1_KEY){
821 if(which==MAC_F2_KEY){
824 if(which==MAC_F3_KEY){
827 if(which==MAC_F4_KEY){
830 if(which==MAC_F5_KEY){
833 if(which==MAC_F6_KEY){
836 if(which==MAC_F7_KEY){
839 if(which==MAC_F8_KEY){
842 if(which==MAC_F9_KEY){
845 if(which==MAC_F10_KEY){
848 if(which==MAC_F11_KEY){
851 if(which==MAC_F12_KEY){
856 if(which==MAC_ESCAPE_KEY){
859 if(which==MAC_DELETE_KEY){
862 if(which==MAC_TAB_KEY){
865 if(which==MAC_TILDE_KEY){
868 if(which==MAC_CAPS_LOCK_KEY){
871 if(which==MAC_COMMAND_KEY){
874 if(which==MAC_OPTION_KEY){
877 if(which==MAC_DEL_KEY){
880 if(which==MAC_INSERT_KEY){
883 if(which==MAC_HOME_KEY){
886 if(which==MAC_END_KEY){
889 if(which==MAC_PAGE_UP_KEY){
892 if(which==MAC_PAGE_DOWN_KEY){
895 if(which==MAC_NUMPAD_CLEAR_KEY){
898 if(which==MAC_CONTROL_KEY){
901 if(which==MAC_SPACE_KEY){
904 if(which==MAC_RETURN_KEY){
907 if(which==MAC_SHIFT_KEY){
910 if(which==MAC_ARROW_UP_KEY){
913 if(which==MAC_ARROW_DOWN_KEY){
916 if(which==MAC_ARROW_LEFT_KEY){
919 if(which==MAC_ARROW_RIGHT_KEY){
922 if(which==MAC_MOUSEBUTTON1){
925 if(which==MAC_MOUSEBUTTON2){
928 if(which==MAC_ARROW_RIGHT_KEY){
931 if(which==MAC_MINUS_KEY||which==MAC_NUMPAD_MINUS_KEY){
934 if(which==MAC_PLUS_KEY||which==MAC_NUMPAD_EQUALS_KEY){
937 if(which==MAC_NUMPAD_PLUS_KEY){
940 if(which==MAC_NUMPAD_ASTERISK_KEY){
943 if(which==MAC_SLASH_KEY||which==MAC_NUMPAD_SLASH_KEY){
946 if(which==MAC_BACKSLASH_KEY){
949 if(which==MAC_LEFTBRACKET_KEY){
952 if(which==MAC_RIGHTBRACKET_KEY){
955 if(which==MAC_PERIOD_KEY||which==MAC_NUMPAD_PERIOD_KEY){
958 if(which==MAC_COMMA_KEY){
961 if(which==MAC_APOSTROPHE_KEY){
964 if(which==MAC_SEMICOLON_KEY){
970 char KeyToSingleChar(unsigned short which)
974 if(which==MAC_A_KEY){
977 if(which==MAC_B_KEY){
980 if(which==MAC_C_KEY){
983 if(which==MAC_D_KEY){
986 if(which==MAC_E_KEY){
989 if(which==MAC_F_KEY){
992 if(which==MAC_G_KEY){
995 if(which==MAC_H_KEY){
998 if(which==MAC_I_KEY){
1001 if(which==MAC_J_KEY){
1004 if(which==MAC_K_KEY){
1007 if(which==MAC_L_KEY){
1010 if(which==MAC_M_KEY){
1013 if(which==MAC_N_KEY){
1016 if(which==MAC_O_KEY){
1019 if(which==MAC_P_KEY){
1022 if(which==MAC_Q_KEY){
1025 if(which==MAC_R_KEY){
1028 if(which==MAC_S_KEY){
1031 if(which==MAC_T_KEY){
1034 if(which==MAC_U_KEY){
1037 if(which==MAC_V_KEY){
1040 if(which==MAC_W_KEY){
1043 if(which==MAC_X_KEY){
1046 if(which==MAC_Y_KEY){
1049 if(which==MAC_Z_KEY){
1052 if(which==MAC_NUMPAD_1_KEY){
1055 if(which==MAC_NUMPAD_2_KEY){
1058 if(which==MAC_NUMPAD_3_KEY){
1061 if(which==MAC_NUMPAD_4_KEY){
1064 if(which==MAC_NUMPAD_5_KEY){
1067 if(which==MAC_NUMPAD_6_KEY){
1070 if(which==MAC_NUMPAD_7_KEY){
1073 if(which==MAC_NUMPAD_8_KEY){
1076 if(which==MAC_NUMPAD_9_KEY){
1079 if(which==MAC_NUMPAD_0_KEY){
1082 if(which==MAC_1_KEY){
1085 if(which==MAC_2_KEY){
1088 if(which==MAC_3_KEY){
1091 if(which==MAC_4_KEY){
1094 if(which==MAC_5_KEY){
1097 if(which==MAC_6_KEY){
1100 if(which==MAC_7_KEY){
1103 if(which==MAC_8_KEY){
1106 if(which==MAC_9_KEY){
1109 if(which==MAC_0_KEY){
1112 if(which==MAC_SPACE_KEY){
1115 if(which==MAC_MINUS_KEY||which==MAC_NUMPAD_MINUS_KEY){
1118 if(which==MAC_PLUS_KEY||which==MAC_NUMPAD_EQUALS_KEY){
1121 if(which==MAC_NUMPAD_PLUS_KEY){
1124 if(which==MAC_NUMPAD_ASTERISK_KEY){
1127 if(which==MAC_SLASH_KEY||which==MAC_NUMPAD_SLASH_KEY){
1130 if(which==MAC_BACKSLASH_KEY){
1133 if(which==MAC_LEFTBRACKET_KEY){
1136 if(which==MAC_RIGHTBRACKET_KEY){
1139 if(which==MAC_PERIOD_KEY||which==MAC_NUMPAD_PERIOD_KEY){
1142 if(which==MAC_COMMA_KEY){
1145 if(which==MAC_APOSTROPHE_KEY){
1148 if(which==MAC_SEMICOLON_KEY){
1154 char Shift(char which)
1311 bool Compare(char *thestring, char *tocompare, int start, int end)
1314 for(i=start;i<=end;i++){
1315 if(thestring[i]!=tocompare[i-start]&&thestring[i]!=tocompare[i-start]+'A'-'a')return 0;