Debian Codegraph @

src/brain_lateral.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 "game_engine.h"
8 #include "freedink.h"
9 #include "live_screen.h"
10 #include "gfx.h" /* GFX_RES_W -> a little off-screen ?? */
11 #include "log.h"
12
13 /**
14 * Enemy with lateral moves, e.g. dragon
15 */
16 void dragon_brain(int h)
17 {
18 int hold;
19
20
21 if (spr[h].damage > 0)
22 {
23 //got hit
24 //SoundPlayEffect( 1,3000, 800 );
25 if (spr[h].hitpoints > 0)
26 {
27 draw_damage(h);
28 if (spr[h].damage > spr[h].hitpoints) spr[h].damage = spr[h].hitpoints;
29 spr[h].hitpoints -= spr[h].damage;
30
31 if (spr[h].hitpoints < 1)
32 {
33 //they killed it
34
35 check_for_kill_script(h);
36 if (spr[h].brain == 10)
37 {
38 add_kill_sprite(h);
39 lsm_remove_sprite(h);
40
41 }
42
43 return;
44
45 }
46 }
47 spr[h].damage = 0;
48 }
49
50
51 if (spr[h].move_active)
52 {
53 process_move(h);
54 return;
55 }
56
57
58 if (spr[h].freeze) return;
59
60
61 if (spr[h].follow > 0)
62 {
63 process_follow(h);
64 return;
65 }
66
67 if (spr[h].target != 0)
68 if ((unsigned)spr[h].attack_wait < thisTickCount)
69 {
70 if (spr[h].script != 0)
71 {
72
73 if (locate(spr[h].script, "ATTACK")) run_script(spr[h].script);
74 }
75 }
76
77
78
79 if (spr[h].seq == 0)
80 {
81 recal:
82 if (((rand() % 12)+1) == 1 )
83 {
84 hold = ((rand() % 9)+1);
85 if ( (hold != 1) && (hold != 3) && (hold != 7) && (hold != 9) && (hold != 5))
86 {
87 changedir(hold,h,spr[h].base_walk);
88
89 }
90
91 } else
92 {
93 //keep going the same way
94 spr[h].seq = spr[h].seq_orig;
95 if (spr[h].seq_orig == 0) goto recal;
96 }
97
98 }
99
100
101 if (spr[h].y > playy)
102
103 {
104 changedir(8,h,spr[h].base_walk);
105 }
106
107 if (spr[h].x > GFX_RES_W)
108 {
109 changedir(4,h,spr[h].base_walk);
110 }
111
112 if (spr[h].y < 0)
113 {
114 changedir(2,h,spr[h].base_walk);
115 }
116
117 if (spr[h].x < 0)
118 {
119 changedir(6,h,spr[h].base_walk);
120 }
121
122 automove(h);
123
124 if (check_if_move_is_legal(h) != 0)
125
126 {
127
128 int mydir = autoreverse(h);
129
130 // Msg("Real dir now is %d, autoresver changed to %d.",spr[h].dir, mydir);
131
132 changedir(mydir,h,spr[h].base_walk);
133
134 log_debug("real dir changed to %d", spr[h].dir);
135 }
136
137 }