/
game_update_board.c
1715 lines (1503 loc) · 47.4 KB
/
game_update_board.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* MegaZeux
*
* Copyright (C) 1996 Greg Janson
* Copyright (C) 2004 Gilead Kutnick <exophase@adelphia.net>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <stdlib.h>
#include <string.h>
#include "const.h"
#include "core.h"
#include "counter.h"
#include "data.h"
#include "game_ops.h"
#include "game_player.h"
#include "game_update.h"
#include "idarray.h"
#include "idput.h"
#include "robot.h"
#include "util.h"
#include "audio/sfx.h"
// For missile turning (directions)
static const int cwturndir[4] = { 2, 3, 1, 0 };
static const int ccwturndir[4] = { 3, 2, 0, 1 };
// OPEN DOOR movement directions, use bits 1,2,4,8,16 to index it.
// 0ffh=no movement.
static const char open_door_movement[] =
{
3 , 0 , 2 , 0 , 3 , 1 , 2 , 1 ,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
2 , 1 , 3 , 1 , 2 , 0 , 3 , 0 ,
1 , 2 , 1 , 3 , 0 , 2 , 0 , 3
};
// Bits for WAIT, in proper bit form, for opening doors. Use bits 1-16.
static const char open_door_max_wait[] =
{
32 , 32 , 32 , 32 , 32 , 32 , 32 , 32 ,
224, 224, 224, 224, 224, 224, 224, 224,
224, 224, 224, 224, 224, 224, 224, 224,
32 , 32 , 32 , 32 , 32 , 32 , 32 , 32
};
// Increases current parameter and stores
static int inc_param(int param, int max)
{
if(param == max)
{
return 0;
}
else
{
return param + 1;
}
}
// This is the big one. Update all of the stuff on the screen..
void update_board(context *ctx)
{
struct world *mzx_world = ctx->world;
int i;
int x, y;
int level_offset;
struct board *src_board = mzx_world->current_board;
struct robot *cur_robot;
char *level_id = src_board->level_id;
char *level_param = src_board->level_param;
char *level_color = src_board->level_color;
char *level_under_id = src_board->level_under_id;
char *level_under_color = src_board->level_under_color;
int board_width = src_board->board_width;
int board_height = src_board->board_height;
boolean slow_down;
enum thing current_id;
char current_param;
char current_color;
enum thing current_under_id;
char *update_done = mzx_world->update_done;
// NOTE: already toggled.
slow_down = mzx_world->current_cycle_odd;
// Clear the status code of all robots
for(i = 0; i < src_board->num_robots_active; i++)
{
cur_robot = src_board->robot_list_name_sorted[i];
cur_robot->status = 0;
}
memset(update_done, 0, board_width * board_height);
// The big update loop
for(y = 0, level_offset = 0; y < board_height; y++)
{
for(x = 0; x < board_width; x++, level_offset++)
{
current_id = (enum thing)level_id[level_offset];
// If the char's update done value is set or the id is < 25
// (space trough W water) then there's nothing to do here;
// go to the next one.
if((update_done[level_offset] & 1) || (current_id < 25) ||
!(flags[(int)current_id] & A_UPDATE))
{
continue;
}
current_param = level_param[level_offset];
switch(current_id)
{
case ROBOT:
case ROBOT_PUSHABLE:
{
run_robot(ctx, current_param, x, y);
// On a game state change, we need to return to the main game loop.
if(mzx_world->change_game_state)
return;
break;
}
case ICE:
{
// Start ice animation
if(current_param == 0)
{
int rval = Random(256);
if(rval == 0)
{
// Start anim at 1
level_param[level_offset] = 1;
}
}
else
// End ice animation
if(current_param == 3)
{
// Reset animation
level_param[level_offset] = 0;
}
else
{
// Increase animation
level_param[level_offset] = current_param + 1;
}
break;
}
case LAVA:
{
int r_val;
if(slow_down) break;
r_val = Random(256);
if(r_val >= 20)
{
if(current_param == 2)
{
level_param[level_offset] = 0;
}
else
{
level_param[level_offset] = current_param + 1;
}
}
break;
}
case FIRE:
{
// Get a random number
int rval = Random(256);
int new_x, new_y;
// If it's less than 20, don't animate
if(rval >= 20)
{
// If not at the end of the animation, increment it
if(current_param != 5)
{
level_param[level_offset] = current_param + 1;
}
else
{
// Reset the animation
level_param[level_offset] = 0;
}
}
// Check under for water, ice, or lava; these all kill the fire.
current_under_id = (enum thing)level_under_id[level_offset];
if((current_under_id >= STILL_WATER) &&
(current_under_id <= LAVA))
{
// Ice also melts into stillwater
if(current_under_id == ICE)
{
level_under_id[level_offset] = (char)STILL_WATER;
level_under_color[level_offset] = 25;
}
id_remove_top(mzx_world, x, y);
break;
}
// Otherwise the fire hurts and spreads and stuff, maybe dies
// Random number says it might die or spread
rval = Random(256);
// No spread here
if(rval > 8) break;
// If it's 1, it should die, if fire doesn't burn forever
// You would think dead fire can't spread, but in MZX it can!
// Makes you wonder what the point of "fire burns forever" is.
// This should possibly be changed later.
if((rval == 1) && (src_board->fire_burns != FIRE_BURNS_FOREVER))
{
// Fire turns into dark grey ash
level_id[level_offset] = (char)FLOOR;
level_color[level_offset] = 8;
}
// Put fire all around
for(i = 3; i >= 0; i--)
{
if(!xy_shift_dir(src_board, x, y, &new_x, &new_y, i))
{
// Get offset
int offset = xy_to_offset(src_board, new_x, new_y);
int place = 0;
// Save ID and param there
enum thing new_id = (enum thing)level_id[offset];
char new_color = level_color[offset];
// Fire does things to certain ID's
if((new_id == SPACE) &&
(src_board->fire_burn_space == 1))
{
place = 1;
}
// Fake
if((new_id >= FAKE) && (new_id <= THICK_WEB) &&
(src_board->fire_burn_fakes == 1))
{
place = 1;
}
if((new_id == TREE) &&
(src_board->fire_burn_trees == 1))
{
place = 1;
}
// Brown stuff
// Don't burn scrolls, signs, sensors, robots, or the player
if((new_color == 6) &&
(src_board->fire_burn_brown == 1) && (new_id < SENSOR))
{
place = 1;
}
// Player
if(new_id == PLAYER)
{
// Make sure player can't.. walk on fire.
if(mzx_world->firewalker_dur == 0)
{
hurt_player(mzx_world, FIRE);
}
}
if(place == 1)
{
// Place a new fire
id_place(mzx_world, new_x, new_y, FIRE, 0, 0);
}
}
}
break;
}
case BULLET:
{
int bullettype = current_param >> 2;
int direction = current_param & 0x03;
// Erase at the current position
id_remove_top(mzx_world, x, y);
// Place a new one
shoot(mzx_world, x, y, direction, bullettype);
break;
}
case EXPLOSION:
{
int stage = current_param & 0x0F;
// Stage zero means climb outwards
if(!stage)
{
// Move the explosion outward if it has any more to go.
if(current_param & 0xF0)
{
int new_x, new_y;
// Decrease stage
current_param -= 0x10;
level_param[level_offset] = current_param;
// Put explosion at each direction
for(i = 3; i >= 0; i--)
{
if(!xy_shift_dir(src_board, x, y, &new_x, &new_y, i))
{
// Get offset
int offset = xy_to_offset(src_board, new_x, new_y);
// Save ID and param there
enum thing new_id = (enum thing)level_id[offset];
char new_param = level_param[offset];
// Get the flags for that ID
int flag = flags[(int)new_id];
// Should a new explosion be placed here?
// Also, some further things can happen.
// Does what's there..
// Blow up (removed by explosion)?
// Slimes, ghosts, and dragons might also die if the
// bit isn't set
if((flag & A_BLOW_UP) ||
((new_id == SLIMEBLOB) && !(new_param & 0x80)) ||
((new_id == GHOST) && !(new_param & 0x08)) ||
((new_id == DRAGON) && !(new_param & 0xE0)))
{
// Remove what's there
id_remove_top(mzx_world, new_x, new_y);
// Place a new explosion (one level down)
id_place(mzx_world, new_x, new_y, EXPLOSION,
0, current_param);
continue;
}
// Explode? (create a new explosion)
if(flag & A_EXPLODE)
{
// Remove what's there
id_remove_top(mzx_world, new_x, new_y);
// Place a fresh new explosion
id_place(mzx_world, new_x, new_y, EXPLOSION, 0, 64);
continue;
}
// If it can be pushed under, place an explosion over it
if(flag & A_UNDER)
{
// Place a new explosion over it.
id_place(mzx_world, new_x, new_y, EXPLOSION,
0, current_param);
continue;
}
// Now, see if it's something that reacts to explosions
// Player takes damage
if(new_id == PLAYER)
{
hurt_player(mzx_world, EXPLOSION);
continue;
}
// Mine explodes
if(new_id == MINE)
{
// Take explosion radius from param
// Remove what's there
id_remove_top(mzx_world, new_x, new_y);
// Place a fresh new explosion
id_place(mzx_world, new_x, new_y, EXPLOSION,
0, new_param & 0xF0);
continue;
}
// Robot gets sent a label
if(is_robot(new_id))
{
// Send bombed label
send_robot_def(mzx_world, new_param, LABEL_BOMBED);
continue;
}
// Dragon takes damage, if it wasn't already killed
if(new_id == DRAGON)
{
// Decrease HP
level_param[offset] = new_param - 0x20;
continue;
}
}
}
}
}
// See if it's at stage 3, if so it's done
if(stage == 3)
{
// Get what's underneath it
current_under_id =
(enum thing)level_under_id[level_offset];
// Leave space if over goop, water, lava, or ice
if((current_under_id == GOOP) ||
((current_under_id >= STILL_WATER) &&
(current_under_id <= LAVA)))
{
// Leave space
id_remove_top(mzx_world, x, y);
break;
}
// Is under an entrance? Explosion leaves space? Leave space.
if((flags[(int)current_under_id] & A_ENTRANCE)
|| src_board->explosions_leave == EXPL_LEAVE_SPACE)
{
// Leave space
id_remove_top(mzx_world, x, y);
break;
}
// Leave ash?
if(src_board->explosions_leave == EXPL_LEAVE_ASH)
{
// Leave ash if the params say so
level_id[level_offset] = (char)FLOOR;
level_color[level_offset] = 8;
break;
}
// Otherwise leave fire
level_id[level_offset] = (char)FIRE;
level_param[level_offset] = 0;
}
else
{
// Otherwise go to the next stage
level_param[level_offset] = current_param + 1;
}
break;
}
// Cw/Ccw
case CW_ROTATE:
case CCW_ROTATE:
{
if(slow_down)
break;
level_param[level_offset] = inc_param(current_param, 3);
rotate(mzx_world, x, y, current_id - CW_ROTATE);
break;
}
case TRANSPORT:
{
if(slow_down)
break;
// Is it still animating?
if((current_param & 0x18) != 0x18)
{
// Increase animation
level_param[level_offset] = current_param + 0x08;
}
else
{
// Otherwise, erase anim bits
level_param[level_offset] = current_param & 0xE7;
}
break;
}
case SHOOTING_FIRE:
{
enum move_status status;
// Get direction
enum dir direction = (enum dir)(current_param >> 1);
// Flip animation and store
current_param ^= 1;
level_param[level_offset] = current_param;
// Try moving
status = move(mzx_world, x, y, direction,
CAN_LAVAWALK | CAN_FIREWALK | CAN_WATERWALK |
REACT_PLAYER | CAN_GOOPWALK | SPITFIRE);
if(status == HIT_PLAYER)
{
// Hit player; hurt the player and die
hurt_player(mzx_world, SHOOTING_FIRE);
id_remove_top(mzx_world, x, y);
}
else
{
if(status != NO_HIT)
{
// Didn't hit the player.. check stuff
current_under_id =
(enum thing)level_under_id[level_offset];
// See if it hit an entrance
if((current_under_id == STAIRS) ||
(current_under_id == CAVE) ||
((current_under_id >= WHIRLPOOL_1) &&
(current_under_id <= WHIRLPOOL_4)))
{
id_remove_top(mzx_world, x, y);
}
else
{
// Put fire
level_id[level_offset] = (char)FIRE;
level_param[level_offset] = 0;
}
}
}
break;
}
case MISSILE:
{
int move_params =
CAN_LAVAWALK | CAN_FIREWALK | CAN_WATERWALK |
REACT_PLAYER | CAN_GOOPWALK;
// Param is the direction
enum move_status status = move(mzx_world, x, y,
current_param, move_params);
// Did it hit something that's not the player?
if((status == HIT) || (status == HIT_EDGE))
{
// Otherwise change direction; try cw then ccw
int new_direction = cwturndir[(int)current_param];
level_param[level_offset] = new_direction;
status = move(mzx_world, x, y, new_direction,
move_params);
// Did it hit something that's not the player? Try ccw.
if((status == HIT) || (status == HIT_EDGE))
{
new_direction = ccwturndir[(int)current_param];
level_param[level_offset] = new_direction;
status = move(mzx_world, x, y, new_direction, move_params);
if(status)
status = HIT_PLAYER;
}
}
// Did it hit the player?
if(status == HIT_PLAYER)
{
// If so, leave explosion
level_id[level_offset] = (char)EXPLOSION;
level_param[level_offset] = 48;
play_sfx(mzx_world, SFX_EXPLOSION);
}
break;
}
case SEEKER:
{
int seek_dir;
if(slow_down) break;
if(current_param == 0)
{
id_remove_top(mzx_world, x, y);
}
else
{
level_param[level_offset] = current_param - 1;
seek_dir = find_seek(mzx_world, x, y);
if(move(mzx_world, x, y, seek_dir,
CAN_PUSH | CAN_LAVAWALK | CAN_FIREWALK |
CAN_WATERWALK | REACT_PLAYER | CAN_GOOPWALK) ==
HIT_PLAYER)
{
hurt_player(mzx_world, SEEKER);
id_remove_top(mzx_world, x, y);
}
}
break;
}
case LAZER:
{
// Decrease time until death
// If it's less than 8, kill it
current_param -= 8;
if(current_param < 8)
{
id_remove_top(mzx_world, x, y);
}
else
{
if(slow_down) break;
// Animate every other cycle
if((current_param & 0x06) == 0x06)
{
// Otherwise, erase anim bits
level_param[level_offset] = current_param & 0xF9;
}
else
{
// Increase animation
level_param[level_offset] = current_param + 2;
}
}
break;
}
case PUSHER:
{
if(!slow_down)
move(mzx_world, x, y, current_param, CAN_PUSH);
break;
}
case SNAKE:
{
enum move_status status;
// Flip count and store
current_param ^= 8;
level_param[level_offset] = current_param;
// If the flipflop or fast-movement is set, move
if((current_param & 0x08) || !(current_param & 0x04))
{
// Try move
status = move(mzx_world, x, y, current_param & 0x03,
REACT_PLAYER);
// See if it hit the player
if(status == HIT_PLAYER)
{
// If so, take damage and die
hurt_player(mzx_world, SNAKE);
id_remove_top(mzx_world, x, y);
break;
}
// Otherwise, if it didn't move, get a new direction
if(status != NO_HIT)
{
int intelligence = (current_param & 0x70) >> 4;
int rval = Random(8);
int m_dir;
// Mask out direction
current_param &= 0xFC;
// If it's less than intelligence, make a "smart" move
if(rval < intelligence)
{
m_dir = find_seek(mzx_world, x, y);
}
else
{
// Get a number between 0 and 3
m_dir = Random(4);
}
// Set direction
current_param |= m_dir;
level_param[level_offset] = current_param;
}
}
break;
}
case EYE:
{
// Flip count and store
current_param ^= 0x80;
level_param[level_offset] = current_param;
// If the flipflop or fast-movement is set, move
if((current_param & 0x80) || !(current_param & 0x40))
{
int intelligence = current_param & 7;
int rval = Random(8);
int m_dir;
if(rval < intelligence)
{
m_dir = find_seek(mzx_world, x, y);
}
else
{
// Get a number between 0 and 3
m_dir = Random(4);
}
if(move(mzx_world, x, y, m_dir,
CAN_LAVAWALK | CAN_FIREWALK | CAN_WATERWALK | REACT_PLAYER |
CAN_GOOPWALK) == HIT_PLAYER)
{
// Hit the player. Get the blast radius.
int radius = (current_param & 0x38) << 1;
// Explode (place explosion)
level_id[level_offset] = EXPLOSION;
level_param[level_offset] = radius;
play_sfx(mzx_world, SFX_EXPLOSION);
}
}
break;
}
case THIEF:
{
// Movement rate, 1-4
int move_speed = current_param & 0x18;
// Movement counter
int move_cycle = (current_param & 0x60) >> 2;
// Should the thief move?
if(move_cycle == move_speed)
{
int intelligence = current_param & 0x07;
int rval = Random(8);
int m_dir;
// Zero out move cycle
level_param[level_offset] = current_param & 0x9F;
// See if a "smart move" should be made
if(rval < intelligence)
{
m_dir = find_seek(mzx_world, x, y);
}
else
{
m_dir = Random(4);
}
// Move and see if it hit the player
if(move(mzx_world, x, y, m_dir, REACT_PLAYER) == HIT_PLAYER)
{
// Get amount of gems to take
int gems_take = ((current_param & 0x80) >> 7) + 1;
// Take them
dec_counter(mzx_world, "GEMS", gems_take, 0);
play_sfx(mzx_world, SFX_STOLEN_GEM);
}
}
else
{
// Increment move cycle
level_param[level_offset] = current_param + 0x20;
}
break;
}
case SLIMEBLOB:
{
if(!slow_down)
{
// This is pretty weird, but I have to go by the ASM for now
int spread_speed = current_param & 0x03;
int current_cycle = (current_param & 0x3C) >> 2;
spread_speed |= spread_speed << 1;
if(spread_speed == current_cycle)
{
int new_x, new_y;
current_color = level_color[level_offset];
// Clear cycle
// BUG: This leaves the lowest cycle count bit set, which can't
// be fixed right now (compatibility). Seems like Alexis planned
// to extend the speed range in 2.00 but didn't fully implement
// it; the param dialog previously had the wrong bound too...
current_param &= 0xC7;
// Put slimes all around
for(i = 3; i >= 0; i--)
{
if(!xy_shift_dir(src_board, x, y, &new_x, &new_y, i))
{
// Get offset
int offset = xy_to_offset(src_board, new_x, new_y);
// Save ID and param there
enum thing new_id = (enum thing)level_id[offset];
// See if it hits a fake
if(is_fake(new_id))
{
// Put a slime
id_place(mzx_world, new_x, new_y, SLIMEBLOB,
current_color, current_param);
}
else
{
// See if it hits the player and hurts the player
if((new_id == PLAYER) && (current_param & 0x40))
{
// Take damage
hurt_player(mzx_world, SLIMEBLOB);
}
}
// Put a breakaway
id_place(mzx_world, x, y, BREAKAWAY, current_color, 0);
}
}
}
else
{
// Increase cycle
level_param[level_offset] = current_param + 4;
}
}
break;
}
case RUNNER:
{
int speed = current_param & 0x0C;
int cycle = (current_param & 0x30) >> 2;
if(cycle == speed)
{
// Get direction
int direction = current_param & 0x03;
enum move_status status;
// Clear cycle
level_param[level_offset] = current_param & 0xCF;
status = move(mzx_world, x, y, direction,
CAN_PUSH | CAN_TRANSPORT | REACT_PLAYER);
// Did the move not go through?
if(status != NO_HIT)
{
// Did it hit the player?
if(status == HIT_PLAYER)
{
// Hurt the player and die
hurt_player(mzx_world, RUNNER);
id_remove_top(mzx_world, x, y);
break;
}
else
{
// Change direction
level_param[level_offset] = current_param ^ 1;
}
}
}
else
{
// Increase cycle
level_param[level_offset] = current_param + 0x10;
}
break;
}
case GHOST:
{
int speed = current_param & 0x30;
int cycle = (current_param & 0xC0) >> 2;
if(speed == cycle)
{
// Get intelligence
int intelligence = current_param & 0x07;
int rval = Random(8);
int m_dir;
// Clear cycle
level_param[level_offset] = current_param & 0x3F;
if(rval < intelligence)
{
// Smart move
m_dir = find_seek(mzx_world, x, y);
}
else
{
m_dir = Random(4);
}
// Try move, did it hit the player?
if(move(mzx_world, x, y, m_dir,
CAN_LAVAWALK | CAN_FIREWALK | CAN_WATERWALK |
REACT_PLAYER | CAN_GOOPWALK) == HIT_PLAYER)
{
// Take damage
hurt_player(mzx_world, GHOST);
// Only die if not invincible
if(!(current_param & 0x08))
{
id_remove_top(mzx_world, x, y);
break;
}
}
}
else
{
// Increase cycle
level_param[level_offset] = current_param + 0x40;
}
break;
}
case DRAGON:
{
int fire_rate;
int rval = -1;
// Can it move?
if(current_param & 0x04)
{
int cycle = current_param & 0x18;
if(cycle == 0x18)
{
int m_dir;
enum move_status status;
// Zero out movement
level_param[level_offset] = current_param & 0xE7;
// One out of 8 moves is random
if(!(rval & 0x07))
{
m_dir = Random(4);
}
else
{
// Otherwise make a smart move
m_dir = find_seek(mzx_world, x, y);
}
status = move(mzx_world, x, y, m_dir,
CAN_LAVAWALK | CAN_FIREWALK | REACT_PLAYER);
// Is it blocked?
if(status != NO_HIT)
{
// Did it hit the player?
if(status == HIT_PLAYER)
{
// Dragons don't die when hit by the player
hurt_player(mzx_world, DRAGON);
}
// Can't shoot, so get out of here
break;
}
}
else
{
level_param[level_offset] = current_param + 8;
}
}
// Shoot; get the fire rate
fire_rate = current_param & 0x03;
rval = Random(16);
// Should it fire?
if(rval < fire_rate)
{
// Shoot in the direction of the player
int fire_dir = find_seek(mzx_world, x, y);
shoot_fire(mzx_world, x, y, fire_dir);
play_sfx(mzx_world, SFX_DRAGON_FIRE);
}