1 /* $Id: plan-9.c,v 1.49 2004/11/28 07:36:00 oohara Exp $ */
2 /* [hard] 0x82da3104 */
3 
4 #include <stdio.h>
5 /* malloc */
6 #include <stdlib.h>
7 
8 #include "scheduler.h"
9 #include "tenm_table.h"
10 #include "hatsuda.h"
11 #include "warning.h"
12 #include "stage-title.h"
13 #include "tenmado.h"
14 #include "const.h"
15 #include "tenm_object.h"
16 #include "normal-enemy.h"
17 
18 #include "plan-9.h"
19 
20 static tenm_object *plan_9_more_1_new(void);
21 static int plan_9_more_1_act(tenm_object *my, const tenm_object *player);
22 
23 int
plan_9(int t)24 plan_9(int t)
25 {
26   /* sanity check */
27   if (t < 0)
28     return SCHEDULER_ERROR;
29 
30   if (t == 30)
31     tenm_table_add(stage_title_new());
32 
33   if (t == 160)
34     tenm_table_add(plan_9_more_1_new());
35 
36   return SCHEDULER_SUCCESS;
37 }
38 
39 static tenm_object *
plan_9_more_1_new(void)40 plan_9_more_1_new(void)
41 {
42   tenm_object *new = NULL;
43   int *count = NULL;
44 
45   count = (int *) malloc(sizeof(int) * 6);
46   if (count == NULL)
47   {
48     fprintf(stderr, "plan_9_more_1_new: malloc(count) failed\n");
49     return NULL;
50   }
51 
52   /* list of count
53    * [0] total timer
54    * [1] number of tenmado created
55    * [2] number of tenmado killed
56    * [3] new enemy timer
57    * [4] new enemy direction
58    * [5] more end time
59    */
60   count[0] = -1;
61   count[1] = 0;
62   count[2] = 0;
63   count[3] = -1;
64   count[4] = -1;
65   count[5] = 1000;
66 
67   new = tenm_object_new("plan 9 more 1", 0, 0,
68                         1, 0.0, 0.0,
69                         6, count, 0, NULL, 0, NULL,
70                         (int (*)(tenm_object *, double))
71                         NULL,
72                         (int (*)(tenm_object *, tenm_object *))
73                         NULL,
74                         (int (*)(tenm_object *, const tenm_object *))
75                         (&plan_9_more_1_act),
76                         (int (*)(tenm_object *, int))
77                         NULL);
78 
79   if (new == NULL)
80   {
81     fprintf(stderr, "plan_9_more_1_new: tenm_object_new failed\n");
82     if (count != NULL)
83       free(count);
84     return NULL;
85   }
86 
87   return new;
88 }
89 
90 static int
plan_9_more_1_act(tenm_object * my,const tenm_object * player)91 plan_9_more_1_act(tenm_object *my, const tenm_object *player)
92 {
93   double x;
94   double dx;
95   int t_shoot;
96   int temp;
97 
98   /* sanity check */
99   if (my == NULL)
100   {
101     fprintf(stderr, "plan_9_more_1_act: my is NULL\n");
102     return 0;
103   }
104   if (player == NULL)
105     return 0;
106 
107   (my->count[0])++;
108 
109   if ((my->count[4] < 0) && (my->count[0] < my->count[5] - 100)
110       && (my->count[0] < 9999)
111       && (((my->count[2] < 3) && (my->count[1] < my->count[2] + 1))
112           || ((my->count[2] >= 3) && (my->count[1] < my->count[2] + 2))))
113   {
114     (my->count[1])++;
115     my->count[3] = -1;
116     if (player->x < ((double) (WINDOW_WIDTH / 2)))
117       my->count[4] = 0;
118     else
119       my->count[4] = 1;
120 
121     if (my->count[1] <= 1)
122     {
123       temp = 0;
124     }
125     else
126     {
127       if (my->count[1] <= 4)
128         temp = 68;
129       else
130         temp = 68 - (my->count[1] - 4) * 2;
131       if (temp < 49)
132         temp = 49;
133     }
134     my->count[5] += temp;
135   }
136 
137   if (my->count[4] >= 0)
138   {
139     (my->count[3])++;
140 
141     if ((my->count[1] > 1)  && (my->count[1] != 5)
142         && (my->count[3] == 0))
143     {
144       if (my->count[4] == 0)
145       {
146         x = ((double) WINDOW_WIDTH) - 44.0;
147       }
148       else
149       {
150         x = 44.0;
151       }
152       tenm_table_add(normal_enemy_new(x, -24.0,
153                                       BALL_CAPTAIN, 0,
154                                       0, -1, 0, -1, 0, 2, 2,
155                                       /* move 0 */
156                                       66,
157                                       0.0, 4.0, 0.0, 0.0,
158                                       0.0, 0.0, 0.0, 0.0, 1,
159                                       /* move 1 */
160                                       9999,
161                                       0.0, 7.0, 0.0, 0.0,
162                                       0.0, 0.0, 0.0, 0.0, 1,
163                                       /* shoot 0 */
164                                       51, 17, 0, 0, 1, 1,
165                                       /* shoot 1 */
166                                       9999, 9, 0, 0, 1, 1));
167     }
168     if ((my->count[1] > 1) && (my->count[1] != 5)
169         && ((my->count[3] == 22) || (my->count[3] == 36)
170             || (my->count[3] == 43) || (my->count[3] == 50)))
171     {
172       if (my->count[4] == 0)
173       {
174         x = ((double) WINDOW_WIDTH) - 50.0;
175       }
176       else
177       {
178         x = 50.0;
179       }
180       tenm_table_add(normal_enemy_new(x, -19.0,
181                                       BALL_SOLDIER, 0,
182                                       0, -1, 0, -1, 0, 2, 2,
183                                       /* move 0 */
184                                       66 - my->count[3],
185                                       0.0, 7.0, 0.0, 0.0,
186                                       0.0, 0.0, 0.0, 0.0, 1,
187                                       /* move 0 */
188                                       9999,
189                                       0.0, 10.0, 0.0, 0.0,
190                                       0.0, 0.0, 0.0, 0.0, 1,
191                                       /* shoot 0 */
192                                       64 - my->count[3], 9999, 0, 0, 0, 1,
193                                       /* shoot 1 */
194                                       9999, 9999, 0, 0, 1, 1));
195     }
196 
197     if (((my->count[1] <= 1) && (my->count[3] == 0))
198         || ((my->count[1] > 1) && (my->count[3] == 50)))
199     {
200       if (my->count[4] == 0)
201       {
202         x = 0.0;
203         dx = 6.0;
204       }
205       else
206       {
207         x = (double) WINDOW_WIDTH;
208         dx = -6.0;
209       }
210 
211       if (my->count[1] <= 4)
212         t_shoot = 13;
213       else
214         t_shoot = 13 - (my->count[1] - 4);
215       if (t_shoot < 7)
216         t_shoot = 7;
217       tenm_table_add(tenmado_new(x, -29.0, my->count[1] % 2, dx,
218                                  my->count[5] - my->count[0],
219                                  my->table_index, t_shoot));
220       my->count[3] = -1;
221       my->count[4] = -1;
222     }
223   }
224 
225   if (my->count[0] == my->count[5] + 130)
226   {
227     tenm_table_add(warning_new());
228   }
229 
230   if (my->count[0] == my->count[5] + 260)
231   {
232     tenm_table_add(hatsuda_new());
233     return 1;
234   }
235 
236   return 0;
237 }
238