Debian Codegraph @

src/brain_people.cpp

raw
1 #ifdef HAVE_CONFIG_H
2 #include <config.h>
3 #endif
4
5 #include "brain.h"
6 #include "freedink.h"
7 #include "live_sprites_manager.h"
8 #include "game_engine.h"
9 #include "live_screen.h"
10 #include "log.h"
11
12 void find_action(int h)
13 {
14
15 spr[h].action = (rand() % 2)+1;
16
17
18 if (spr[h].action == 1)
19 {
20 //sit and think
21 spr[h].move_wait = thisTickCount +((rand() % 3000)+400);
22 if (spr[h].base_walk != -1)
23 {
24 int dir = (rand() % 4)+1;
25
26 spr[h].pframe = 1;
27 if (dir == 1) spr[h].pseq = spr[h].base_walk+1;
28 if (dir == 2) spr[h].pseq = spr[h].base_walk+3;
29 if (dir == 3) spr[h].pseq = spr[h].base_walk+7;
30 if (dir == 4) spr[h].pseq = spr[h].base_walk+9;
31 }
32
33 return;
34 }
35
36 if (spr[h].action == 2)
37 {
38 //move
39 spr[h].move_wait = thisTickCount +((rand() % 3000)+500);
40 int dir = (rand() % 4)+1;
41 spr[h].pframe = 1;
42 if (dir == 1) changedir(1,h,spr[h].base_walk);
43 if (dir == 2) changedir(3,h,spr[h].base_walk);
44 if (dir == 3) changedir(7,h,spr[h].base_walk);
45 if (dir == 4) changedir(9,h,spr[h].base_walk);
46 return;
47 }
48
49
50 log_error("Internal error: Brain 16, unknown action.");
51 }
52
53
54 void people_brain(int h)
55 {
56 if (spr[h].damage > 0)
57 {
58 //got hit
59 //SoundPlayEffect( 1,3000, 800 );
60 if (spr[h].hitpoints > 0)
61 {
62 draw_damage(h);
63 if (spr[h].damage > spr[h].hitpoints) spr[h].damage = spr[h].hitpoints;
64 spr[h].hitpoints -= spr[h].damage;
65
66 if (spr[h].hitpoints < 1)
67 {
68 //they killed it
69 check_for_kill_script(h);
70
71 if (spr[h].brain == 16)
72 {
73 if (spr[h].dir == 0) spr[h].dir = 3;
74 spr[h].brain = 0;
75 change_dir_to_diag(&spr[h].dir);
76 add_kill_sprite(h);
77 lsm_remove_sprite(h);
78 }
79 return;
80
81 }
82 }
83 spr[h].damage = 0;
84
85 }
86
87 if (spr[h].move_active)
88 {
89 process_move(h);
90 return;
91 }
92
93
94
95
96 if (spr[h].freeze) return;
97
98 if (spr[h].follow > 0)
99 {
100 process_follow(h);
101 return;
102 }
103
104
105 if ((spr[h].move_wait < thisTickCount) && (spr[h].seq == 0))
106 {
107
108 spr[h].action = 0;
109 }
110
111
112
113 if (spr[h].action == 0) find_action(h);
114
115
116 if (spr[h].action != 2)
117 {
118 spr[h].seq = 0;
119 return;
120
121 }
122 if (spr[h].seq_orig != 0)
123 if (spr[h].seq == 0) spr[h].seq = spr[h].seq_orig;
124
125
126 if (spr[h].y > playy)
127
128 {
129
130 if ( ((rand() % 2)+1) == 1)
131 changedir(9,h,spr[h].base_walk);
132 else changedir(7,h,spr[h].base_walk);
133
134
135 }
136
137 if (spr[h].x > playx)
138
139 {
140 if ( ((rand() % 2)+1) == 1)
141 changedir(1,h,spr[h].base_walk);
142 else changedir(7,h,spr[h].base_walk);
143
144 }
145
146 if (spr[h].y < 20)
147 {
148 if ( ((rand() % 2)+1) == 1)
149 changedir(1,h,spr[h].base_walk);
150 else changedir(3,h,spr[h].base_walk);
151 }
152
153 if (spr[h].x < 30)
154 {
155 if ( ((rand() % 2)+1) == 1)
156 changedir(3,h,spr[h].base_walk);
157 else changedir(9,h,spr[h].base_walk);
158 }
159
160 automove(h);
161
162 if (check_if_move_is_legal(h) != 0)
163 {
164 if ((rand() % 3) == 2)
165 {
166 changedir(autoreverse_diag(h),h,spr[h].base_walk);
167
168 } else
169 {
170 spr[h].move_wait = 0;
171 spr[h].pframe = 1;
172 spr[h].seq = 0;
173 }
174 }
175
176
177 // changedir(hold,h,spr[h].base_walk);
178
179
180 }