Debian Codegraph @

src/brain_mouse.cpp

raw
1 #ifdef HAVE_CONFIG_H
2 #include <config.h>
3 #endif
4
5 #include "brain.h"
6 #include "live_sprites_manager.h"
7 #include "input.h"
8 #include "log.h"
9 #include "gfx_sprites.h"
10 #include "dinkc.h"
11 #include "sfx.h"
12
13 void run_through_mouse_list(int h, /*bool*/int special)
14 {
15 rect box;
16 int i;
17
18 for (i = 1; i <= last_sprite_created; i++)
19 {
20
21 if (spr[i].active) if (i != h) if
22 ((spr[i].touch_damage != 0) )
23 {
24
25 if (spr[i].touch_damage != -1) if (spr[h].notouch) return;
26 rect_copy(&box, &k[getpic(i)].hardbox);
27 rect_offset(&box, spr[i].x, spr[i].y);
28
29
30 if (inside_box(spr[h].x, spr[h].y, box))
31 {
32
33 if ((spr[i].touch_damage == -1) && (spr[i].script != 0))
34 {
35 log_info("running %d's script..", spr[i].script);
36 if (locate(spr[i].script, "CLICK")) run_script(spr[i].script);
37 }
38 else
39 {
40 if (spr[i].touch_damage == -1)
41 {
42 log_error("Sprites touch damage is set to -1 but there is no script set!");
43 } else
44 {
45 //lets hurt the guy
46 }
47
48 }
49
50 if (special) return;
51
52 }
53
54
55 }
56
57 }
58
59 if (special) SoundPlayEffect(19, 22050, 0, 0,0);
60
61 }
62
63 void mouse_brain(int h)
64 {
65
66 if (spr[h].move_active)
67 {
68 process_move(h);
69 return;
70 }
71
72
73 int diag = 0;
74
75 if (sjoy.right) diag++;
76 if (sjoy.left) diag++;
77 if (sjoy.down) diag++;
78 if (sjoy.up) diag++;
79
80
81 //*********************************PROCESS MOVEMENT
82
83 if (diag == 1)
84 {
85
86 if (sjoy.right)
87 {
88 move(h,spr[h].speed,'+','0');
89 changedir(6,h,spr[h].base_walk);
90 }
91
92
93 if (sjoy.left)
94 {
95 move(h,spr[h].speed,'-','0');
96 changedir(4,h,spr[h].base_walk);
97 }
98
99
100 if (sjoy.down)
101 {
102 move(h,spr[h].speed,'0','+');
103 changedir(2,h,spr[h].base_walk);
104 }
105
106
107 if (sjoy.up)
108 {
109 move(h,spr[h].speed,'0','-');
110 changedir(8,h,spr[h].base_walk);
111 }
112
113 }
114 // ***************** DIAGONAL!!!!
115
116 if (diag > 1)
117 {
118
119 if ( (sjoy.up) && (sjoy.left) )
120 {
121 changedir(7,h,spr[h].base_walk);
122 move(h,spr[h].speed - (spr[h].speed / 3),'-','-');
123
124 }
125
126 if ( (sjoy.down) && (sjoy.left))
127 {
128 changedir(1,h,spr[h].base_walk);
129 move(h,spr[h].speed - (spr[h].speed / 3),'-','+');
130
131 }
132
133 if ( (sjoy.down) && (sjoy.right))
134 {
135 changedir(3,h,spr[h].base_walk);
136 move(h,spr[h].speed - (spr[h].speed / 3),'+','+');
137 }
138
139
140 if ( (sjoy.up) && (sjoy.right))
141 {
142 changedir(9,h,spr[h].base_walk);
143 move(h,spr[h].speed - (spr[h].speed / 3),'+','-');
144 }
145
146 }
147
148
149
150
151 if ( (sjoy.button[ACTION_ATTACK] == /*TRUE*/1) | (mouse1) )
152 {
153
154 log_info("running through mouse list..");
155 run_through_mouse_list(h, /*true*/1);
156 sjoy.button[ACTION_ATTACK] = /*false*/0;
157 mouse1 = /*false*/0;
158
159 }
160
161 }