Debian Codegraph @

src/brain_keyboard.cpp

raw
1
2 #ifdef HAVE_CONFIG_H
3 #include <config.h>
4 #endif
5
6 #include "brain.h"
7
8 #include <gettext.h>
9 #define _(String) gettext(String)
10
11 #include "game_engine.h"
12 #include "freedink.h"
13 #include "game_engine.h"
14 #include "input.h"
15 #include "live_sprites_manager.h"
16 #include "sfx.h"
17 #include "game_choice.h"
18 #include "gfx_sprites.h"
19 #include "text.h"
20 #include "bgm.h"
21 #include "live_screen.h"
22
23 /**
24 * Check whether planned new position (x1,y1) is solid
25 *
26 * If hard value is > 100, warp using info from editor sprite #(100-value)
27 *
28 * TODO: factor out with 'get_hard'; beware of 'return' semantic
29 */
30 unsigned char get_hard_play(int x1, int y1)
31 {
32 x1 -= 20;
33
34 if (screenlock)
35 {
36 if (x1 < 0) x1 = 0;
37 else if (x1 > 599) x1 = 599;
38
39 if (y1 < 0) y1 = 0;
40 else if (y1 > 399) y1 = 399;
41 }
42 if ((x1 < 0) || (y1 < 0) || (x1 > 599) || (y1 > 399))
43 return 0;
44
45 int value = screen_hitmap[x1][y1];
46 if (value > 100 && cur_ed_screen.sprite[value-100].is_warp != 0)
47 {
48 warp_editor_sprite = value;
49 value = 0;
50 }
51 return(value);
52 }
53
54 void run_through_tag_list_push(int h)
55 {
56 rect box;
57 int i;
58
59 for (i = 1; i <= last_sprite_created; i++)
60 {
61 if (spr[i].active) if (i != h) if
62 ((spr[i].script != 0) )
63 {
64
65 rect_copy(&box, &k[getpic(i)].hardbox);
66 rect_offset(&box, spr[i].x, spr[i].y);
67
68 //InflateRect(&box, 10,10);
69
70 box.right += 2;
71 box.left -= 2;
72 box.top -= 2;
73 box.bottom += 2;
74 //draw_box(box, 33);
75
76 if (inside_box(spr[h].x, spr[h].y, box))
77 {
78 if (locate(spr[i].script, "PUSH")) run_script(spr[i].script);
79 }
80
81 }
82
83 }
84
85 }
86
87 void process_bow( int h)
88 {
89 int timetowait = 100;
90
91
92 if (bow.wait < thisTickCount)
93 {
94 if (sjoy.right) spr[h].dir = 6;
95 if (sjoy.left) spr[h].dir = 4;
96 if (sjoy.up) spr[h].dir = 8;
97 if (sjoy.down) spr[h].dir = 2;
98 }
99
100
101
102 if (sjoy.right) if (sjoy.up)
103 {
104 spr[h].dir = 9;
105 bow.wait = thisTickCount + timetowait;
106 }
107 if (sjoy.left) if (sjoy.up)
108 {
109 spr[h].dir = 7;
110 bow.wait = thisTickCount + timetowait;
111 }
112 if (sjoy.right) if (sjoy.down)
113 {
114 spr[h].dir = 3;
115 bow.wait = thisTickCount + timetowait;
116
117 }
118 if (sjoy.left) if (sjoy.down)
119 {
120 spr[h].dir = 1;
121 bow.wait = thisTickCount + timetowait;
122
123 }
124 spr[h].pseq = 100+spr[h].dir;
125
126
127 if (bow.pull_wait < thisTickCount)
128 {
129 bow.pull_wait = thisTickCount + 10;
130 if (bow.hitme) bow.time += 7;
131
132
133 // bowsound->SetFrequency(22050+(bow.time*10));
134
135 if (bow.time > 500) bow.time = 500;
136 spr[h].pframe = (bow.time / 100)+1;
137 }
138
139
140 if (!sjoy.joybitold[ACTION_ATTACK])
141 {
142 bow.active = /*false*/0;
143 bow.last_power = bow.time;
144 run_script(bow.script);
145 // bowsound->Stop();
146 return;
147 }
148
149 }
150
151
152 /**
153 * Player
154 */
155 void human_brain(int h)
156 {
157 int diag;
158 int crap;
159 /*BOOL*/int bad;
160
161 if (mode == 0)
162 goto b1end;
163
164 if (spr[h].move_active)
165 {
166 process_move(h);
167 return;
168 }
169
170 if (spr[h].damage > 0)
171 {
172 draw_damage(h);
173
174 *plife -= spr[h].damage;
175
176 spr[h].damage = 0;
177 if (*plife < 0)
178 *plife = 0;
179
180 int hurt = (rand() % 2)+1;
181
182 if (hurt == 1)
183 SoundPlayEffect(15, 25050, 2000, 0,0);
184 if (hurt == 2)
185 SoundPlayEffect(16, 25050, 2000, 0,0);
186
187 //draw blood
188 }
189
190 if (play.push_active)
191 {
192 if (play.push_dir == 2 && !sjoy.down)
193 {
194 spr[h].nocontrol = /*false*/0;
195 play.push_active = false;
196 }
197
198 if (play.push_dir == 4 && !sjoy.left)
199 {
200 spr[h].nocontrol = /*false*/0;
201 play.push_active = false;
202 }
203 if (play.push_dir == 6 && !sjoy.right)
204 {
205 spr[h].nocontrol = /*false*/0;
206 play.push_active = false;
207 }
208
209 if (play.push_dir == 8 && !sjoy.up)
210 {
211 spr[h].nocontrol = /*false*/0;
212 play.push_active = false;
213 }
214 }
215
216 if (spr[h].nocontrol)
217 return;
218
219 if (game_choice.active)
220 goto freeze;
221
222 if (spr[h].freeze)
223 {
224 //they are frozen
225 if (sjoy.button[ACTION_TALK] == 1)
226 {
227 //they hit the talk button while frozen, lets hurry up the process
228 int jj;
229 for (jj = 1; jj <= last_sprite_created; jj++)
230 {
231 // Msg("Checking %d, brain %d, script %d, my freeze is %d",jj, spr[jj].brain, spr[jj].script, spr[h].freeze);
232 if (spr[jj].brain == 8 && spr[jj].script == play.last_talk)
233 {
234 //this sprite owns its freeze
235 spr[jj].kill_ttl = 1;
236 //force the message to be over
237 }
238 }
239 }
240 goto freeze;
241 }
242
243
244 //****************************** KEYS THAT CAN BE PRESSED AT ANY TIME **************
245
246 if (bow.active)
247 {
248 //bow is active!!
249 process_bow(h);
250 return;
251 }
252
253 if (play.push_active && thisTickCount > play.push_timer + 600)
254 {
255 spr[h].seq = dink_base_push + spr[h].dir;
256 spr[h].frame = 1;
257 spr[h].nocontrol = /*true*/1;
258 //play.push_active = /*false*/0;
259 run_through_tag_list_push(h);
260
261 return;
262 }
263
264 if ((sjoy.button[ACTION_TALK] == 1))
265 {
266 if (!run_through_tag_list_talk(h))
267 {
268 int did_dnotalk = 0;
269 if (dversion >= 108)
270 {
271 // addition of 'not talking to anything' script
272 int sc = load_script ("dnotalk", 0);
273 if (sc != 0 && locate (sc, "MAIN"))
274 {
275 run_script (sc);
276 did_dnotalk = 1;
277 }
278 }
279
280 if (did_dnotalk == 0)
281 {
282 kill_text_owned_by(h);
283 int randy = (rand() % 6)+1;
284 if (randy == 1) say_text(_("`$I don't see anything here."), h, 0);
285 if (randy == 2) say_text(_("`$Huh?"), h, 0);
286 if (randy == 3) say_text(_("`$I'm fairly sure I can't talk to or use that."), h, 0);
287 if (randy == 4) say_text(_("`$What?"), h, 0);
288 if (randy == 5) say_text(_("`$I'm bored."), h, 0);
289 if (randy == 6) say_text(_("`$Not much happening here."), h, 0);
290 }
291 }
292 }
293
294 if ((sjoy.button[ACTION_ATTACK] == 1) && (weapon_script != 0))
295 {
296 if (spr[h].base_hit > 0)
297 {
298 if (locate(weapon_script, "USE"))
299 run_script(weapon_script);
300 goto b1end;
301 }
302 }
303
304 //added AGAIN 10-19-99
305 //Let's check keys for getting hit
306 if (thisTickCount > but_timer)
307 {
308 int scancode;
309 for (scancode = 0; scancode < SDL_NUM_SCANCODES; scancode++)
310 {
311 if (scancode == SDL_SCANCODE_SPACE
312 || scancode == SDL_SCANCODE_6
313 || scancode == SDL_SCANCODE_7
314 || scancode == SDL_SCANCODE_LEFT
315 || scancode == SDL_SCANCODE_UP
316 || scancode == SDL_SCANCODE_RIGHT
317 || scancode == SDL_SCANCODE_DOWN
318 || scancode == SDL_SCANCODE_RETURN
319 || scancode == SDL_SCANCODE_TAB
320 || scancode == SDL_SCANCODE_ESCAPE
321 || scancode == SDL_SCANCODE_LCTRL
322 || scancode == SDL_SCANCODE_RCTRL
323 || scancode == SDL_SCANCODE_LSHIFT
324 || scancode == SDL_SCANCODE_RSHIFT
325 || scancode == SDL_SCANCODE_LALT
326 || scancode == SDL_SCANCODE_RALT
327 || SDL_GetKeyFromScancode((SDL_Scancode)scancode) == SDLK_m)
328 continue;
329
330 char scriptname[30];
331 if (input_getscancodestate((SDL_Scancode)scancode))
332 {
333 /* Get the same keycodes than the original Dink engines
334 for letters, that is, uppercase ascii rather than
335 lowercase ascii */
336 int code;
337 int keycode = SDL_GetKeyFromScancode((SDL_Scancode)scancode);
338 if (keycode >= SDLK_a && keycode <= SDLK_z)
339 code = 'A' + (keycode - SDLK_a);
340 else
341 code = scancode;
342
343 sprintf(scriptname, "key-%d", code);
344 but_timer = thisTickCount+200;
345
346 int script = load_script(scriptname, 1);
347 if (locate(script, "MAIN"))
348 {
349 run_script(script);
350 goto b1end;
351 }
352 }
353 }
354 }
355
356 {
357 enum buttons_actions actions[5];
358 int actions_script[5];
359 int nb_actions = 1;
360 actions[0] = ACTION_MAP;
361 actions_script[0] = 6;
362 if (dversion >= 108)
363 {
364 nb_actions = 5;
365 actions[1] = ACTION_BUTTON7;
366 actions_script[1] = 7;
367 actions[2] = ACTION_BUTTON8;
368 actions_script[2] = 8;
369 actions[3] = ACTION_BUTTON9;
370 actions_script[3] = 9;
371 actions[4] = ACTION_BUTTON10;
372 actions_script[4] = 10;
373 }
374 for (int i = 0; i < nb_actions; i++)
375 {
376 // button6.c, button7.c, ..., button10.c
377 if (sjoy.button[actions[i]] == 1)
378 {
379 char script_filename[6+2+1]; // 'button' + '7'..'10' + '\0' (no '.c')
380 sprintf(script_filename, "button%d", actions_script[i]);
381 int mycrap = load_script(script_filename, 1);
382 if (locate(mycrap, "MAIN"))
383 run_script(mycrap);
384 goto b1end;
385 }
386 }
387 }
388
389 if (magic_script != 0 && sjoy.joybit[ACTION_MAGIC])
390 goto shootm;
391
392 if (sjoy.button[ACTION_MAGIC] == 1)
393 {
394 if (magic_script == 0)
395 {
396 if (dversion >= 108)
397 {
398 // addition of 'no magic' script
399 int sc = load_script ("dnomagic", 0);
400 if (sc != 0 && locate (sc, "MAIN"))
401 {
402 run_script (sc);
403 goto b1end;
404 }
405 }
406
407 int randy = (rand() % 6)+1;
408 kill_text_owned_by(h);
409 if (randy == 1) say_text(_("`$I don't know any magic."), h, 0);
410 if (randy == 2) say_text(_("`$I'm no wizard!"), h, 0);
411 if (randy == 3) say_text(_("`$I need to learn magic before trying this."), h, 0);
412 if (randy == 4) say_text(_("`$I'm gesturing wildly to no avail!"), h, 0);
413 if (randy == 5) say_text(_("`$Nothing happened."), h, 0);
414 if (randy == 6) say_text(_("`$Hocus pocus!"), h, 0);
415 goto b1end;
416 }
417
418 //player pressed 1
419 //lets magiced something
420 shootm:
421 if (*pmagic_level >= *pmagic_cost)
422 {
423 if (locate(magic_script, "USE"))
424 run_script(magic_script);
425 goto b1end;
426 }
427 }
428
429 if (sjoy.button[ACTION_INVENTORY])
430 {
431 if (dversion >= 108)
432 {
433 // addition of 'enter key/inventory' script
434 int sc = load_script ("button4", 0);
435 if (sc != 0 && locate (sc, "MAIN"))
436 {
437 run_script (sc);
438 return;
439 }
440 }
441
442 show_inventory = 1;
443 SoundPlayEffect(18, 22050,0,0,0);
444 return;
445 }
446
447 if (sjoy.button[ACTION_MENU] == 1)
448 {
449 if (!showb.active && !bow.active && !game_choice.active)
450 {
451 int sc = load_script("escape", 1000);
452 if (sc != 0 && locate(sc, "MAIN"))
453 run_script(sc);
454 return;
455 }
456 }
457
458 if (input_getcharstate(SDLK_b))
459 ResumeMidi();
460 if (input_getcharstate(SDLK_n))
461 PauseMidi();
462
463 if (spr[h].skip > 0
464 && spr[h].skip <= spr[h].skiptimer)
465 {
466 spr[h].skiptimer = 0;
467 goto b1end;
468 }
469
470
471 diag = 0;
472 if (sjoy.right) diag++;
473 if (sjoy.left) diag++;
474 if (sjoy.down) diag++;
475 if (sjoy.up) diag++;
476
477
478 //*********************************PROCESS MOVEMENT
479
480 if (diag == 1)
481 {
482 if (sjoy.right)
483 {
484 move(h,spr[h].speed,'+','0');
485 changedir(6,h,spr[h].base_walk);
486 }
487
488 if (sjoy.left)
489 {
490 move(h,spr[h].speed,'-','0');
491 changedir(4,h,spr[h].base_walk);
492 }
493
494 if (sjoy.down)
495 {
496 move(h,spr[h].speed,'0','+');
497 changedir(2,h,spr[h].base_walk);
498 }
499
500 if (sjoy.up)
501 {
502 move(h,spr[h].speed,'0','-');
503 changedir(8,h,spr[h].base_walk);
504 }
505 }
506
507 // ***************** DIAGONAL!!!!
508 if (diag > 1 && diag < 3)
509 {
510 if (sjoy.up && sjoy.left)
511 {
512 changedir(7,h,spr[h].base_walk);
513 move(h,spr[h].speed - (spr[h].speed / 3),'-','-');
514 }
515
516 if (sjoy.down && sjoy.left)
517 {
518 changedir(1,h,spr[h].base_walk);
519 move(h,spr[h].speed - (spr[h].speed / 3),'-','+');
520 }
521
522 if (sjoy.down && sjoy.right)
523 {
524 changedir(3,h,spr[h].base_walk);
525 move(h,spr[h].speed - (spr[h].speed / 3),'+','+');
526 }
527
528 if (sjoy.up && sjoy.right)
529 {
530 changedir(9,h,spr[h].base_walk);
531 move(h,spr[h].speed - (spr[h].speed / 3),'+','-');
532 }
533 }
534
535 bad = 0;
536 if (sjoy.right) bad = 1;
537 if (sjoy.left) bad = 1;
538 if (sjoy.up) bad = 1;
539 if (sjoy.down) bad = 1;
540
541 if (bad)
542 {
543 if (spr[h].idle)
544 {
545 spr[h].frame = 1;
546 spr[h].idle = /*FALSE*/0;
547 }
548 goto badboy;
549 }
550
551 if (not_in_this_base(spr[h].seq, spr[h].base_idle)) //unccoment to allow walk anim to end before idle anim to start
552 {
553 freeze:
554 if (spr[h].dir == 1) spr[h].dir = 2;
555 if (spr[h].dir == 3) spr[h].dir = 2;
556 if (spr[h].dir == 7) spr[h].dir = 8;
557 if (spr[h].dir == 9) spr[h].dir = 8;
558
559 if (spr[h].base_idle != 0)
560 changedir(spr[h].dir,h,spr[h].base_idle);
561 spr[h].idle = /*TRUE*/1;
562 }
563
564 badboy:
565 b1end:
566
567 if (spr[h].dir == 2 || spr[h].dir == 4 || spr[h].dir == 6 || spr[h].dir == 8)
568 goto smoothend;
569
570 crap = check_if_move_is_legal(h);
571 if (crap != 0)
572 {
573 if (crap > 100 && cur_ed_screen.sprite[crap-100].is_warp != 0)
574 warp_editor_sprite = crap;
575
576 //hit something, can we move around it?
577
578 if (spr[h].seq == spr[h].base_walk + 4
579 || spr[h].seq == spr[h].base_walk + 6)
580 {
581 int hardm = get_hard_play(spr[h].x, spr[h].y-1);
582 if (hardm == 0)
583 spr[h].y -= 1;
584 }
585
586 if (spr[h].seq == spr[h].base_walk + 8
587 || spr[h].seq == spr[h].base_walk + 2)
588 {
589 int hardm = get_hard_play(spr[h].x-1, spr[h].y);
590 if (hardm == 0)
591 spr[h].x -= 1;
592 }
593
594
595 if (spr[h].seq == spr[h].base_walk + 9)
596 {
597 int hardm = get_hard_play(spr[h].x+1, spr[h].y);
598 if (hardm == 0)
599 {
600 spr[h].x += 1;
601
602 }
603 else
604 {
605 int hardm = get_hard_play(spr[h].x+1, spr[h].y+1);
606 if (hardm == 0)
607 {
608 spr[h].x += 1;
609 spr[h].y += 1;
610 }
611 else
612 {
613 int hardm = get_hard_play(spr[h].x+1, spr[h].y+2);
614 if (hardm == 0)
615 {
616 spr[h].x += 1;
617 spr[h].y += 2;
618 }
619 else
620 {
621 int hardm = get_hard_play(spr[h].x, spr[h].y-1);
622 if (hardm == 0)
623 {
624 spr[h].y -= 1;
625
626 }
627 else
628 {
629 int hardm = get_hard_play(spr[h].x-1, spr[h].y-1);
630 if (hardm == 0)
631 {
632 spr[h].x -= 1;
633 spr[h].y -= 1;
634 }
635 }
636 }
637 }
638 }
639 }
640
641 if (spr[h].seq == spr[h].base_walk + 7)
642 {
643 int hardm = get_hard_play(spr[h].x-1, spr[h].y);
644 if (hardm == 0)
645 {
646 spr[h].x -= 1;
647 }
648 else
649 {
650 int hardm = get_hard_play(spr[h].x-1, spr[h].y+1);
651 if (hardm == 0)
652 {
653 spr[h].x -= 1;
654 spr[h].y += 1;
655 }
656 else
657 {
658 int hardm = get_hard_play(spr[h].x-1, spr[h].y+2);
659 if (hardm == 0)
660 {
661 spr[h].x -= 1;
662 spr[h].y += 2;
663 }
664 else
665 {
666 int hardm = get_hard_play(spr[h].x, spr[h].y-1);
667 if (hardm == 0)
668 {
669 spr[h].y -= 1;
670 }
671 else
672 {
673 int hardm = get_hard_play(spr[h].x+1, spr[h].y-1);
674 if (hardm == 0)
675 {
676 spr[h].x += 1;
677 spr[h].y -= 1;
678 }
679 }
680 }
681 }
682 }
683 }
684
685 if (spr[h].seq == spr[h].base_walk + 1)
686 {
687 int hardm = get_hard_play(spr[h].x-1, spr[h].y);
688 if (hardm == 0)
689 {
690 spr[h].x -= 1;
691 }
692 else
693 {
694 int hardm = get_hard_play(spr[h].x-1, spr[h].y-1);
695 if (hardm == 0)
696 {
697 spr[h].x -= 1;
698 spr[h].y -= 1;
699 }
700 else
701 {
702 int hardm = get_hard_play(spr[h].x-1, spr[h].y-2);
703 if (hardm == 0)
704 {
705 spr[h].x -= 1;
706 spr[h].y -= 2;
707 }
708 else
709 {
710 int hardm = get_hard_play(spr[h].x, spr[h].y+1);
711 if (hardm == 0)
712 {
713 spr[h].y += 1;
714 }
715 else
716 {
717 int hardm = get_hard_play(spr[h].x+1, spr[h].y+1);
718 if (hardm == 0)
719 {
720 spr[h].x += 1;
721 spr[h].y += 1;
722 }
723 }
724 }
725 }
726 }
727 }
728
729 if (spr[h].seq == spr[h].base_walk + 3)
730 {
731 int hardm = get_hard_play(spr[h].x+1, spr[h].y);
732 if (hardm == 0)
733 {
734 spr[h].x += 1;
735 }
736 else
737 {
738 int hardm = get_hard_play(spr[h].x+1, spr[h].y-1);
739 if (hardm == 0)
740 {
741 spr[h].x += 1;
742 spr[h].y -= 1;
743 }
744 else
745 {
746 int hardm = get_hard_play(spr[h].x+1, spr[h].y-2);
747 if (hardm == 0)
748 {
749 spr[h].x += 1;
750 spr[h].y -= 2;
751 }
752 else
753 {
754 int hardm = get_hard_play(spr[h].x, spr[h].y+1);
755 if (hardm == 0)
756 {
757 spr[h].y += 1;
758 }
759 else
760 {
761 int hardm = get_hard_play(spr[h].x-1, spr[h].y+1);
762 if (hardm == 0)
763 {
764 spr[h].x -= 1;
765 spr[h].y += 1;
766 }
767 }
768 }
769 }
770 }
771 }
772 }
773
774 smoothend:
775 ;
776 }