Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
5253 | mario79 | 1 | ;--------------------------------------------------------------------- |
2 | processing_npc_action: |
||
3 | ; DEBUGF 1, "processing_npc_action\n" |
||
4 | cmp dl,ROUTE_UP |
||
5 | je npc_route_up |
||
6 | |||
7 | cmp dl,ROUTE_DOWN |
||
8 | je npc_route_down |
||
9 | |||
10 | cmp dl,ROUTE_LEFT |
||
11 | je npc_route_left |
||
12 | |||
13 | cmp dl,ROUTE_RIGHT |
||
14 | je npc_route_right |
||
15 | |||
16 | ret |
||
17 | ;--------------------------------------------------------------------- |
||
18 | npc_route_up: |
||
19 | ; DEBUGF 1, "npc route_up\n" |
||
20 | cmp ebx,1 ; border of map? |
||
21 | jne @f |
||
22 | ;-------------------------------------- |
||
23 | .change_route: |
||
24 | ; DEBUGF 1, "npc .change_route_up\n" |
||
25 | mov dx,0x0100+ROUTE_RIGHT |
||
26 | call get_random_binary |
||
27 | test al,al |
||
28 | jz .save_new_route |
||
29 | |||
30 | mov dx,0x0100+ROUTE_DOWN |
||
31 | ;-------------------------------------- |
||
32 | .save_new_route: |
||
33 | rol edx,16 |
||
34 | mov [ecx],edx |
||
35 | ret |
||
36 | ;-------------------------------------- |
||
37 | @@: |
||
38 | ; DEBUGF 1, "npc up @@:\n" |
||
39 | call npc_search_target_up_left |
||
40 | cmp [target_detected],1 |
||
41 | jne @f |
||
42 | |||
43 | mov edi,TARGET_RANGE |
||
44 | sub edi,[target_action_cell_x] |
||
45 | |||
46 | mov ebx,TARGET_RANGE |
||
47 | sub ebx,[target_action_cell_y] |
||
48 | ; DEBUGF 1, "%x npc_route_up target_up_left X: %x Y: %x\n",[current_cell_NPC]:1,edi,ebx |
||
49 | cmp edi,ebx |
||
50 | jb .continue |
||
51 | |||
52 | mov si,0x0100+ROUTE_LEFT |
||
53 | jmp save_route_to_current_position |
||
54 | ;-------------------------------------- |
||
55 | @@: |
||
56 | call npc_search_target_up_right |
||
57 | cmp [target_detected],1 |
||
58 | jne @f |
||
59 | |||
60 | mov edi,[target_action_cell_x] |
||
61 | dec edi |
||
62 | |||
63 | mov ebx,TARGET_RANGE |
||
64 | sub ebx,[target_action_cell_y] |
||
65 | ; DEBUGF 1, "%x npc_route_up target_up_right X: %x Y: %x\n",[current_cell_NPC]:1,edi,ebx |
||
66 | cmp edi,ebx |
||
67 | jb .continue |
||
68 | |||
69 | mov si,0x0100+ROUTE_RIGHT |
||
70 | jmp save_route_to_current_position |
||
71 | ;-------------------------------------- |
||
72 | @@: |
||
73 | .continue: |
||
74 | mov eax,[ecx-LEVEL_MAP_SIZE_X*4] |
||
75 | |||
76 | cmp ah,OBJECT_PROTAGONIST |
||
77 | je .continue_1 |
||
78 | |||
79 | test ah,ah |
||
80 | jnz .change_route |
||
81 | ;-------------------------------------- |
||
82 | @@: |
||
83 | cmp al,BASE_WATER |
||
84 | jz .change_route |
||
85 | |||
86 | cmp al,BASE_LAVA |
||
87 | jz .change_route |
||
88 | ;-------------------------------------- |
||
89 | .continue_1: |
||
90 | ; DEBUGF 1, "npc good route up\n" |
||
91 | mov si,0x0100+ROUTE_UP |
||
92 | mov edi,ecx |
||
93 | sub edi,LEVEL_MAP_SIZE_X*4 |
||
94 | jmp save_new_and_clear_old_position |
||
95 | ;--------------------------------------------------------------------- |
||
96 | npc_route_down: |
||
97 | ; DEBUGF 1, "npc route_down\n" |
||
98 | cmp ebx,LEVEL_MAP_SIZE_Y ; border of map? |
||
99 | jne @f |
||
100 | ;-------------------------------------- |
||
101 | .change_route: |
||
102 | ; DEBUGF 1, "npc .change_route_down\n" |
||
103 | mov dx,0x0100+ROUTE_LEFT |
||
104 | call get_random_binary |
||
105 | test al,al |
||
106 | jz .save_new_route |
||
107 | |||
108 | mov dx,0x0100+ROUTE_UP |
||
109 | ;-------------------------------------- |
||
110 | .save_new_route: |
||
111 | rol edx,16 |
||
112 | mov [ecx],edx |
||
113 | ret |
||
114 | ;-------------------------------------- |
||
115 | @@: |
||
116 | ; DEBUGF 1, "npc down @@:\n" |
||
117 | call npc_search_target_down_left |
||
118 | cmp [target_detected],1 |
||
119 | jne @f |
||
120 | |||
121 | mov edi,TARGET_RANGE |
||
122 | sub edi,[target_action_cell_x] |
||
123 | |||
124 | mov ebx,[target_action_cell_y] |
||
125 | dec ebx |
||
126 | ; DEBUGF 1, "%x npc_route_down target_down_left X: %x Y: %x\n",[current_cell_NPC]:1,edi,ebx |
||
127 | cmp edi,ebx |
||
128 | jb .continue |
||
129 | |||
130 | mov si,0x0100+ROUTE_LEFT |
||
131 | jmp save_route_to_current_position |
||
132 | ;-------------------------------------- |
||
133 | @@: |
||
134 | call npc_search_target_down_right |
||
135 | cmp [target_detected],1 |
||
136 | jne @f |
||
137 | |||
138 | mov edi,[target_action_cell_x] |
||
139 | dec edi |
||
140 | |||
141 | mov ebx,[target_action_cell_y] |
||
142 | ; DEBUGF 1, "%x npc_route_down target_down_right X: %x Y: %x\n",[current_cell_NPC]:1,edi,ebx |
||
143 | cmp edi,ebx |
||
144 | jb .continue |
||
145 | |||
146 | mov si,0x0100+ROUTE_RIGHT |
||
147 | jmp save_route_to_current_position |
||
148 | ;-------------------------------------- |
||
149 | @@: |
||
150 | .continue: |
||
151 | mov eax,[ecx+LEVEL_MAP_SIZE_X*4] |
||
152 | |||
153 | cmp ah,OBJECT_PROTAGONIST |
||
154 | je .continue_1 |
||
155 | |||
156 | test ah,ah |
||
157 | jnz .change_route |
||
158 | ;-------------------------------------- |
||
159 | @@: |
||
160 | cmp al,BASE_WATER |
||
161 | jz .change_route |
||
162 | |||
163 | cmp al,BASE_LAVA |
||
164 | jz .change_route |
||
165 | ;-------------------------------------- |
||
166 | .continue_1: |
||
167 | ; DEBUGF 1, "npc good route down\n" |
||
168 | mov si,0x0100+ROUTE_DOWN |
||
169 | mov edi,ecx |
||
170 | add edi,LEVEL_MAP_SIZE_X*4 |
||
171 | jmp save_new_and_clear_old_position |
||
172 | ;--------------------------------------------------------------------- |
||
173 | npc_route_left: |
||
174 | ; DEBUGF 1, "npc route_left\n" |
||
175 | cmp eax,1 ; border of map? |
||
176 | jne @f |
||
177 | ;-------------------------------------- |
||
178 | .change_route: |
||
179 | ; DEBUGF 1, "npc .change_route_left\n" |
||
180 | mov dx,0x0100+ROUTE_UP |
||
181 | call get_random_binary |
||
182 | test al,al |
||
183 | jz .save_new_route |
||
184 | |||
185 | mov dx,0x0100+ROUTE_RIGHT |
||
186 | ;-------------------------------------- |
||
187 | .save_new_route: |
||
188 | rol edx,16 |
||
189 | mov [ecx],edx |
||
190 | ret |
||
191 | ;-------------------------------------- |
||
192 | @@: |
||
193 | ; DEBUGF 1, "npc left @@:\n" |
||
194 | call npc_search_target_up_left |
||
195 | cmp [target_detected],1 |
||
196 | jne @f |
||
197 | |||
198 | mov edi,TARGET_RANGE |
||
199 | sub edi,[target_action_cell_x] |
||
200 | |||
201 | mov ebx,TARGET_RANGE |
||
202 | sub ebx,[target_action_cell_y] |
||
203 | ; DEBUGF 1, "%x npc_route_left target_up_left X: %x Y: %x\n",[current_cell_NPC]:1,edi,ebx |
||
204 | cmp edi,ebx |
||
205 | jae .continue |
||
206 | |||
207 | mov si,0x0100+ROUTE_UP |
||
208 | jmp save_route_to_current_position |
||
209 | ;-------------------------------------- |
||
210 | @@: |
||
211 | call npc_search_target_down_left |
||
212 | cmp [target_detected],1 |
||
213 | jne @f |
||
214 | |||
215 | mov edi,TARGET_RANGE |
||
216 | sub edi,[target_action_cell_x] |
||
217 | |||
218 | mov ebx,[target_action_cell_y] |
||
219 | dec ebx |
||
220 | ; DEBUGF 1, "%x npc_route_left target_down_left X: %x Y: %x\n",[current_cell_NPC]:1,edi,ebx |
||
221 | cmp edi,ebx |
||
222 | jae .continue |
||
223 | |||
224 | mov si,0x0100+ROUTE_DOWN |
||
225 | jmp save_route_to_current_position |
||
226 | ;-------------------------------------- |
||
227 | @@: |
||
228 | .continue: |
||
229 | mov eax,[ecx-4] |
||
230 | |||
231 | cmp ah,OBJECT_PROTAGONIST |
||
232 | je .continue_1 |
||
233 | |||
234 | test ah,ah |
||
235 | jnz .change_route |
||
236 | ;-------------------------------------- |
||
237 | @@: |
||
238 | cmp al,BASE_WATER |
||
239 | jz .change_route |
||
240 | |||
241 | cmp al,BASE_LAVA |
||
242 | jz .change_route |
||
243 | ;-------------------------------------- |
||
244 | .continue_1: |
||
245 | ; DEBUGF 1, "npc good route left\n" |
||
246 | mov si,0x0100+ROUTE_LEFT |
||
247 | mov edi,ecx |
||
248 | sub edi,4 |
||
249 | jmp save_new_and_clear_old_position |
||
250 | ;--------------------------------------------------------------------- |
||
251 | npc_route_right: |
||
252 | ; DEBUGF 1, "npc route_right\n" |
||
253 | cmp eax,LEVEL_MAP_SIZE_X ; border of map? |
||
254 | jne @f |
||
255 | ;-------------------------------------- |
||
256 | .change_route: |
||
257 | ; DEBUGF 1, "npc .change_route_right\n" |
||
258 | mov dx,0x0100+ROUTE_DOWN |
||
259 | call get_random_binary |
||
260 | test al,al |
||
261 | jz .save_new_route |
||
262 | |||
263 | mov dx,0x0100+ROUTE_LEFT |
||
264 | ;-------------------------------------- |
||
265 | .save_new_route: |
||
266 | rol edx,16 |
||
267 | mov [ecx],edx |
||
268 | ret |
||
269 | ;-------------------------------------- |
||
270 | @@: |
||
271 | ; DEBUGF 1, "npc righ @@:\n" |
||
272 | call npc_search_target_up_right |
||
273 | cmp [target_detected],1 |
||
274 | jne @f |
||
275 | |||
276 | mov edi,[target_action_cell_x] |
||
277 | dec edi |
||
278 | |||
279 | mov ebx,TARGET_RANGE |
||
280 | sub ebx,[target_action_cell_y] |
||
281 | ; DEBUGF 1, "%x npc_route_right target_up_right X: %x Y: %x\n",[current_cell_NPC]:1,edi,ebx |
||
282 | cmp edi,ebx |
||
283 | jae .continue |
||
284 | |||
285 | mov si,0x0100+ROUTE_UP |
||
286 | jmp save_route_to_current_position |
||
287 | ;-------------------------------------- |
||
288 | @@: |
||
289 | call npc_search_target_down_right |
||
290 | cmp [target_detected],1 |
||
291 | jne @f |
||
292 | |||
293 | mov edi,[target_action_cell_x] |
||
294 | dec edi |
||
295 | |||
296 | mov ebx,[target_action_cell_y] |
||
297 | dec ebx |
||
298 | ; DEBUGF 1, "%x npc_route_right target_down_right X: %x Y: %x\n",[current_cell_NPC]:1,edi,ebx |
||
299 | cmp edi,ebx |
||
300 | jae .continue |
||
301 | |||
302 | mov si,0x0100+ROUTE_DOWN |
||
303 | jmp save_route_to_current_position |
||
304 | ;-------------------------------------- |
||
305 | @@: |
||
306 | .continue: |
||
307 | mov eax,[ecx+4] |
||
308 | |||
309 | cmp ah,OBJECT_PROTAGONIST |
||
310 | je .continue_1 |
||
311 | |||
312 | test ah,ah |
||
313 | jnz .change_route |
||
314 | ;-------------------------------------- |
||
315 | @@: |
||
316 | cmp al,BASE_WATER |
||
317 | jz .change_route |
||
318 | |||
319 | cmp al,BASE_LAVA |
||
320 | jz .change_route |
||
321 | ;-------------------------------------- |
||
322 | .continue_1: |
||
323 | ; DEBUGF 1, "npc good route righ\n" |
||
324 | mov si,0x0100+ROUTE_RIGHT |
||
325 | mov edi,ecx |
||
326 | add edi,4 |
||
327 | jmp save_new_and_clear_old_position |
||
328 | ;--------------------------------------------------------------------- |
||
329 | npc_search_target_up_left: |
||
330 | ; DEBUGF 1, "%x npc_search_target_up_left X: %x Y: %x\n",[current_cell_NPC]:1,[action_cell_x],[action_cell_y] |
||
331 | push ecx |
||
332 | sub ecx,TARGET_RANGE * 4 ; offset x |
||
333 | sub ecx,TARGET_RANGE * LEVEL_MAP_SIZE_X * 4 ; offset y |
||
334 | jmp npc_search_target |
||
335 | ;--------------------------------------------------------------------- |
||
336 | npc_search_target_up_right: |
||
337 | ; DEBUGF 1, "%x npc_search_target_up_right X: %x Y: %x\n",[current_cell_NPC]:1,[action_cell_x],[action_cell_y] |
||
338 | push ecx |
||
339 | sub ecx,TARGET_RANGE * LEVEL_MAP_SIZE_X * 4 ; offset y |
||
340 | sub ecx,4 ; offset x |
||
341 | jmp npc_search_target |
||
342 | ;--------------------------------------------------------------------- |
||
343 | npc_search_target_down_left: |
||
344 | ; DEBUGF 1, "%x npc_search_target_down_left X: %x Y: %x\n",[current_cell_NPC]:1,[action_cell_x],[action_cell_y] |
||
345 | push ecx |
||
346 | sub ecx,LEVEL_MAP_SIZE_X * 4 ; offset y |
||
347 | sub ecx,TARGET_RANGE * 4 ; offset x |
||
348 | jmp npc_search_target |
||
349 | ;--------------------------------------------------------------------- |
||
350 | npc_search_target_down_right: |
||
351 | ; DEBUGF 1, "%x npc_search_target_down_right X: %x Y: %x\n",[current_cell_NPC]:1,[action_cell_x],[action_cell_y] |
||
352 | push ecx |
||
353 | sub ecx,LEVEL_MAP_SIZE_X * 4 ; offset y |
||
354 | sub ecx,4 ; offset x |
||
355 | ;--------------------------------------------------------------------- |
||
356 | npc_search_target: |
||
357 | push eax |
||
358 | mov [target_detected],0 |
||
359 | mov ebx,TARGET_RANGE |
||
360 | ;-------------------------------------- |
||
361 | .y: |
||
362 | mov eax,TARGET_RANGE |
||
363 | ; DEBUGF 1, "current cell next y\n" |
||
364 | ;-------------------------------------- |
||
365 | .x: |
||
366 | push eax ebx ecx |
||
367 | mov [target_action_cell_x],eax |
||
368 | mov [target_action_cell_y],ebx |
||
369 | shl eax,2 |
||
370 | add ecx,eax |
||
371 | imul ebx,LEVEL_MAP_SIZE_X*4 |
||
372 | add ecx,ebx |
||
373 | |||
374 | cmp ecx,plan_level |
||
375 | jb @f |
||
376 | |||
377 | cmp ecx,plan_level+LEVEL_MAP_SIZE_X*LEVEL_MAP_SIZE_Y*4-4 |
||
378 | ja @f |
||
379 | |||
380 | mov eax,[ecx] |
||
381 | ; DEBUGF 1, "current cell %x\n",eax |
||
382 | cmp ah,OBJECT_PROTAGONIST |
||
383 | jne @f |
||
384 | |||
385 | pop ecx ebx eax |
||
386 | mov [target_detected],1 |
||
387 | ; DEBUGF 1, "%x target_detected X: %x Y: %x\n",[current_cell_NPC]:1,[target_action_cell_x],[target_action_cell_y] |
||
388 | jmp .exit |
||
389 | ;-------------------------------------- |
||
390 | @@: |
||
391 | pop ecx ebx eax |
||
392 | |||
393 | dec eax |
||
394 | jnz .x |
||
395 | |||
396 | dec ebx |
||
397 | jnz .y |
||
398 | .exit: |
||
399 | pop eax ecx |
||
400 | ret |
||
401 | ;--------------------------------------------------------------------- |