1
2 #include "../stdai.h"
3 #include "maze.fdh"
4
INITFUNC(AIRoutines)5 INITFUNC(AIRoutines)
6 {
7 ONTICK(OBJ_BLOCK_MOVEH, ai_block_moveh);
8 ONTICK(OBJ_BLOCK_MOVEV, ai_block_movev);
9
10 ONTICK(OBJ_BOULDER, ai_boulder);
11
12 GENERIC_NPC_NOFACEPLAYER(OBJ_GAUDI_SHOPKEEP);
13 }
14
15 /*
16 void c------------------------------() {}
17 */
18
ai_block_moveh(Object * o)19 void ai_block_moveh(Object *o)
20 {
21 int px = player->CenterX();
22 int objx = o->CenterX();
23
24 switch(o->state)
25 {
26 case 0:
27 NX_LOG("ai_block_moveh - state 0.\n");
28 o->flags |= FLAG_SOLID_BRICK;
29 o->smushdamage = 100;
30 o->state = (o->dir == LEFT) ? 10:20;
31 break;
32
33 case 10: // at right edge, ready to travel left
34 NX_LOG("ai_block_moveh - state 10.\n");
35 if (((px > objx) && (px - objx) < 0x3200) || \
36 ((px < objx) && (objx - px) < 0x32000))
37 {
38 if (pdistly(0x3200))
39 {
40 o->state = 30;
41 o->timer = 0;
42 }
43 }
44 break;
45
46 case 20: // at left edge, ready to travel right
47 NX_LOG("ai_block_moveh - state 20.\n");
48 if (((px > objx) && (px - objx) < 0x32000) || \
49 ((px < objx) && (objx - px) < 0x3200))
50 {
51 if (pdistly(0x3200))
52 {
53 o->state = 30;
54 o->timer = 0;
55 }
56 }
57 break;
58
59 case 30: // traveling
60 {
61 NX_LOG("ai_block_moveh - state 30.\n");
62 XACCEL(0x20);
63 LIMITX(0x200);
64
65 // hit edge
66 if ((o->dir == RIGHT && o->blockr) || (o->dir == LEFT && o->blockl))
67 {
68 SmokeSide(o, 4, o->dir);
69 quake(10);
70
71 o->xinertia = 0;
72 o->dir ^= 1;
73 o->state = (o->dir==LEFT) ? 10 : 20;
74 }
75
76 if ((++o->timer % 10) == 6)
77 sound(SND_BLOCK_MOVE);
78 }
79 break;
80 }
81 }
82
ai_block_movev(Object * o)83 void ai_block_movev(Object *o)
84 {
85 int py = player->CenterY();
86 int objy = o->CenterY();
87
88 switch(o->state)
89 {
90 case 0:
91 NX_LOG("ai_block_movev - state 0.\n");
92 o->flags |= FLAG_SOLID_BRICK;
93 o->smushdamage = 100;
94 o->dir = (o->dir == LEFT) ? UP : DOWN;
95 o->state = (o->dir == DOWN) ? 10 : 20;
96 break;
97
98 case 10: // at top edge, ready to travel down
99 NX_LOG("ai_block_movev - state 10.\n");
100 if (((py > objy) && (py - objy) < 0x32000) || \
101 ((py < objy) && (objy - py) < 0x3200))
102 {
103 if (pdistlx(0x3200))
104 {
105 o->state = 30;
106 o->timer = 0;
107 }
108 }
109 break;
110
111 case 20: // at bottom edge, ready to travel up
112 NX_LOG("ai_block_movev - state 20.\n");
113 if (((py > objy) && (py - objy) < 0x3200) || \
114 ((py < objy) && (objy - py) < 0x32000))
115 {
116 if (pdistlx(0x3200))
117 {
118 o->state = 30;
119 o->timer = 0;
120 }
121 }
122 break;
123
124 case 30: // traveling
125 NX_LOG("ai_block_movev - state 30.\n");
126 {
127 YACCEL(0x20);
128 LIMITY(0x200);
129
130 // hit edge
131 if ((o->dir == DOWN && o->blockd) || (o->dir == UP && o->blocku))
132 {
133 SmokeSide(o, 4, o->dir);
134 quake(10);
135
136 o->yinertia = 0;
137 o->dir ^= 1;
138 o->state = (o->dir==DOWN) ? 10 : 20;
139 }
140
141 if ((++o->timer % 10) == 6)
142 sound(SND_BLOCK_MOVE);
143 }
144 break;
145 }
146 }
147
148 /*
149 void c------------------------------() {}
150 */
151
ai_boulder(Object * o)152 void ai_boulder(Object *o)
153 {
154 switch(o->state)
155 {
156 // shaking
157 case 10:
158 {
159 NX_LOG("ai_boulder - state 10.\n");
160 o->state = 11;
161 o->timer = 0;
162 o->xmark = o->x;
163 }
164 case 11:
165 {
166 NX_LOG("ai_boulder - state 11.\n");
167 if ((++o->timer % 3) != 0)
168 o->x = o->xmark + (1 << CSF);
169 else
170 o->x = o->xmark;
171 }
172 break;
173
174 // thrown away by Balrog
175 case 20:
176 {
177 NX_LOG("ai_boulder - state 20.\n");
178 o->yinertia = -0x400;
179 o->xinertia = 0x100;
180 sound(SND_FUNNY_EXPLODE);
181
182 o->state = 21;
183 o->timer = 0;
184 }
185 case 21:
186 {
187 NX_LOG("ai_boulder - state 21.\n");
188 o->yinertia += 0x10;
189
190 if (o->blockd && o->yinertia >= 0)
191 {
192 sound(SND_EXPLOSION1);
193 game.quaketime = 40;
194
195 o->xinertia = 0;
196 o->yinertia = 0;
197 o->state = 0;
198 }
199 }
200 break;
201 }
202 }
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218