1
2 #include "../stdai.h"
3 #include "almond.h"
4 #include "almond.fdh"
5
INITFUNC(AIRoutines)6 INITFUNC(AIRoutines)
7 {
8 ONTICK(OBJ_WATERLEVEL, ai_waterlevel);
9
10 ONTICK(OBJ_SHUTTER, ai_shutter);
11 ONTICK(OBJ_SHUTTER_BIG, ai_shutter);
12 ONTICK(OBJ_ALMOND_LIFT, ai_shutter);
13
14 ONTICK(OBJ_SHUTTER_STUCK, ai_shutter_stuck);
15 ONTICK(OBJ_ALMOND_ROBOT, ai_almond_robot);
16 }
17
18 /*
19 void c------------------------------() {}
20 */
21
ai_waterlevel(Object * o)22 void ai_waterlevel(Object *o)
23 {
24 /* debug("WL State: %d", o->state);
25 debug("WL Y: %d", o->y>>CSF);
26 debug("WL Timer: %d", o->timer);
27 debug("WLForceUp: %d", map.wlforceup);*/
28
29 if (map.wlforcestate)
30 {
31 NX_LOG("Forced WL state to %d\n", map.wlforcestate);
32 o->state = map.wlforcestate;
33 map.wlforcestate = 0;
34 }
35
36 switch(o->state)
37 {
38 case 0:
39 map.waterlevelobject = o;
40 o->state = WL_CALM;
41 o->y += (8<<CSF);
42 o->ymark = o->y;
43 o->yinertia = 0x200;
44 case WL_CALM: // calm waves around set point
45 o->yinertia += (o->y < o->ymark) ? 4 : -4;
46 LIMITY(0x100);
47 break;
48
49 case WL_CYCLE: // wait 1000 ticks, then rise all the way to top come down and repeat
50 o->state = WL_DOWN; o->timer = 0;
51 case WL_DOWN:
52 o->yinertia += (o->y < o->ymark) ? 4 : -4;
53 LIMITY(0x200);
54 if (++o->timer > 1000)
55 {
56 o->state = WL_UP;
57 }
58 break;
59 case WL_UP: // rise all the way to top then come back down
60 o->yinertia += (o->y > 0) ? -4 : 4;
61 LIMITY(0x200);
62
63 // when we reach the top return to normal level
64 if (o->y < (64<<CSF))
65 {
66 o->state = WL_CYCLE;
67 }
68 break;
69
70 case WL_STAY_UP: // rise quickly all the way to top and stay there
71 o->yinertia += (o->y > 0) ? -4 : 4;
72 if (o->yinertia < -0x200) o->yinertia = -0x200;
73 if (o->yinertia > 0x100) o->yinertia = 0x100;
74 break;
75 }
76
77 map.wlstate = o->state;
78 }
79
80
81 /// common code to both Shutter AND Lift
ai_shutter(Object * o)82 void ai_shutter(Object *o)
83 {
84 if (o->state == 10)
85 {
86 // allow hitting the stuck shutter no. 4
87 o->flags &= ~(FLAG_SHOOTABLE | FLAG_INVULNERABLE);
88
89 switch(o->dir)
90 {
91 case LEFT: o->x -= 0x80; break;
92 case RIGHT: o->x += 0x80; break;
93 case UP: o->y -= 0x80; break;
94 case DOWN: o->y += 0x80; break;
95 }
96
97 // animate Almond_Lift
98 if (o->type==OBJ_ALMOND_LIFT)
99 {
100 ai_animate3(o);
101 }
102 else if (o->type==OBJ_SHUTTER_BIG)
103 {
104 if (!o->timer)
105 {
106 game.quaketime = 20;
107 sound(SND_QUAKE);
108
109 o->timer = 6;
110 } else o->timer--;
111 }
112 }
113 else if (o->state == 20) // tripped by script when Shutter_Big closes fully
114 {
115 SmokeSide(o, 4, DOWN);
116 o->state = 21;
117 }
118
119 if (o->type == OBJ_SHUTTER_BIG)
120 {
121 ANIMATE(10, 0, 3);
122 }
123 }
124
ai_shutter_stuck(Object * o)125 void ai_shutter_stuck(Object *o)
126 {
127 // when you shoot shutter 4, you're actually shooting us, but we want them
128 // to think they're shooting the regular shutter object, so go invisible
129 o->invisible = 1;
130 }
131
132 /*
133 void c------------------------------() {}
134 */
135
136 // the damaged robot which wakes up right before the Almond battle
ai_almond_robot(Object * o)137 void ai_almond_robot(Object *o)
138 {
139 switch(o->state)
140 {
141 case 0:
142 o->frame = 0;
143 break;
144
145 case 10: // blows up
146 sound(SND_BIG_CRASH);
147 SmokeClouds(o, 8, 3, 3);
148 o->Delete();
149 break;
150
151 case 20: // flashes
152 ANIMATE(10, 0, 1);
153 break;
154 }
155 }
156
157
158
159
160
161