1 /* $Id: silver-chimera.c,v 1.172 2005/06/24 14:42:42 oohara Exp $ */
2 /* [hard] Silver Chimera */
3 
4 #include <stdio.h>
5 /* malloc, rand */
6 #include <stdlib.h>
7 /* strlen, strcmp */
8 #include <string.h>
9 
10 #include "const.h"
11 #include "tenm_object.h"
12 #include "tenm_graphic.h"
13 #include "tenm_primitive.h"
14 #include "util.h"
15 #include "player-shot.h"
16 #include "tenm_table.h"
17 #include "background.h"
18 #include "chain.h"
19 #include "laser.h"
20 #include "normal-shot.h"
21 #include "tenm_math.h"
22 #include "fragment.h"
23 #include "explosion.h"
24 #include "stage-clear.h"
25 #include "score.h"
26 
27 #include "silver-chimera.h"
28 
29 static int silver_chimera_move(tenm_object *my, double turn_per_frame);
30 static int silver_chimera_hit(tenm_object *my, tenm_object *your);
31 static void silver_chimera_explode(tenm_object *my);
32 static int silver_chimera_act(tenm_object *my, const tenm_object *player);
33 static int silver_chimera_draw(tenm_object *my, int priority);
34 static int silver_chimera_green(const tenm_object *my);
35 
36 static tenm_object *silver_chimera_spread_new(double x, double y,
37                                               double speed_x, double speed_y,
38                                               int t_spread);
39 static int silver_chimera_spread_move(tenm_object *my, double turn_per_frame);
40 static int silver_chimera_spread_hit(tenm_object *my, tenm_object *your);
41 static int silver_chimera_spread_act(tenm_object *my,
42                                      const tenm_object *player);
43 static int silver_chimera_spread_draw(tenm_object *my, int priority);
44 
45 static tenm_object *silver_chimera_lock_on_new(double x, double y);
46 static int silver_chimera_lock_on_act(tenm_object *my,
47                                       const tenm_object *player);
48 static int silver_chimera_lock_on_draw(tenm_object *my, int priority);
49 static int silver_chimera_lock_on_draw_square(int x, int y, int length,
50                                               tenm_color color);
51 
52 static tenm_object *silver_chimera_bit_new(int table_index, int n);
53 static int silver_chimera_bit_move(tenm_object *my, double turn_per_frame);
54 static int silver_chimera_bit_hit(tenm_object *my, tenm_object *your);
55 static int silver_chimera_bit_signal(tenm_object *my, int n);
56 static int silver_chimera_bit_act(tenm_object *my, const tenm_object *player);
57 static int silver_chimera_bit_draw(tenm_object *my, int priority);
58 static int silver_chimera_bit_green(const tenm_object *my);
59 
60 tenm_object *
silver_chimera_new(void)61 silver_chimera_new(void)
62 {
63   int i;
64   tenm_primitive **p = NULL;
65   tenm_object *new = NULL;
66   int *count = NULL;
67   double *count_d = NULL;
68   double x = (double) (WINDOW_WIDTH / 2);
69   double y = -53.0;
70 
71   p = (tenm_primitive **) malloc(sizeof(tenm_primitive *) * 2);
72   if (p == NULL)
73   {
74     fprintf(stderr, "silver_chimera_new: malloc(p) failed\n");
75     return NULL;
76   }
77 
78   p[0] = (tenm_primitive *) tenm_polygon_new(4,
79                                              x + 96.0, y - 54.0,
80                                              x - 48.0, y + 54.0,
81                                              x - 65.28, y + 30.96,
82                                              x + 78.72, y - 77.04);
83   if (p[0] == NULL)
84   {
85     fprintf(stderr, "silver_chimera_new: cannot set p[0]\n");
86     free(p);
87     return NULL;
88   }
89   p[1] = (tenm_primitive *) tenm_polygon_new(4,
90                                              x - 96.0, y - 54.0,
91                                              x + 48.0, y + 54.0,
92                                              x + 65.28, y + 30.96,
93                                              x - 78.72, y - 77.04);
94   if (p[1] == NULL)
95   {
96     fprintf(stderr, "silver_chimera_new: cannot set p[1]\n");
97     (p[0])->delete(p[0]);
98     free(p);
99     return NULL;
100   }
101 
102   count = (int *) malloc(sizeof(int) * 6);
103   if (count == NULL)
104   {
105     fprintf(stderr, "silver_chimera_new: malloc(count) failed\n");
106     for (i = 0; i < 2; i++)
107       (p[i])->delete(p[i]);
108     free(p);
109     return NULL;
110   }
111   count_d = (double *) malloc(sizeof(double) * 2);
112   if (count_d == NULL)
113   {
114     fprintf(stderr, "silver_chimera_new: malloc(count_d) failed\n");
115     free(count);
116     for (i = 0; i < 2; i++)
117       (p[i])->delete(p[i]);
118     free(p);
119     return NULL;
120   }
121 
122   /* list of count
123    * [0] for deal_damage
124    * [1] "damaged" timer
125    * [2] move mode
126    * [3] move timer
127    * [4] number of bits dead
128    * [5] "was green when killed" flag
129    */
130   /* list of count_d
131    * [0] speed x
132    * [1] speed y
133    */
134 
135   count[0] = 0;
136   count[1] = 0;
137   count[2] = 0;
138   count[3] = 0;
139   count[4] = 0;
140   count[5] = 0;
141 
142   count_d[0] = 0.0;
143   count_d[1] = (((double) (WINDOW_HEIGHT / 4)) - y) / 120.0;
144 
145   new = tenm_object_new("Silver Chimera", ATTR_BOSS, ATTR_PLAYER_SHOT,
146                         1000, x, y,
147                         6, count, 2, count_d, 2, p,
148                         (int (*)(tenm_object *, double))
149                         (&silver_chimera_move),
150                         (int (*)(tenm_object *, tenm_object *))
151                         (&silver_chimera_hit),
152                         (int (*)(tenm_object *, const tenm_object *))
153                         (&silver_chimera_act),
154                         (int (*)(tenm_object *, int))
155                         (&silver_chimera_draw));
156   if (new == NULL)
157   {
158     fprintf(stderr, "silver_chimera_new: tenm_object_new failed\n");
159     if (count_d != NULL)
160       free(count_d);
161     if (count != NULL)
162       free(count);
163     for (i = 0; i < 2; i++)
164       (p[i])->delete(p[i]);
165     free(p);
166     return NULL;
167   }
168 
169   return new;
170 }
171 
172 static int
silver_chimera_move(tenm_object * my,double turn_per_frame)173 silver_chimera_move(tenm_object *my, double turn_per_frame)
174 {
175   double dx_temp;
176   double dy_temp;
177 
178   /* sanity check */
179   if (my == NULL)
180   {
181     fprintf(stderr, "silver_chimera_move: my is NULL\n");
182     return 0;
183   }
184   if (turn_per_frame <= 0.5)
185   {
186     fprintf(stderr, "silver_chimera_move: strange turn_per_frame (%f)\n",
187             turn_per_frame);
188     return 0;
189   }
190 
191   dx_temp = my->count_d[0] / turn_per_frame;
192   dy_temp = my->count_d[1] / turn_per_frame;
193   my->x += dx_temp;
194   my->y += dy_temp;
195   if (my->mass != NULL)
196     tenm_move_mass(my->mass, dx_temp, dy_temp);
197 
198   return 0;
199 }
200 
201 static int
silver_chimera_hit(tenm_object * my,tenm_object * your)202 silver_chimera_hit(tenm_object *my, tenm_object *your)
203 {
204   /* sanity check */
205   if (my == NULL)
206   {
207     fprintf(stderr, "silver_chimera_hit: my is NULL\n");
208     return 0;
209   }
210   if (your == NULL)
211   {
212     fprintf(stderr, "silver_chimera_hit: your is NULL\n");
213     return 0;
214   }
215 
216   if (!(your->attr & ATTR_PLAYER_SHOT))
217     return 0;
218   if (my->count[2] != 1)
219     return 0;
220 
221   deal_damage(my, your, 0);
222   if (silver_chimera_green(my))
223     add_chain(my, your);
224   my->count[1] = 2;
225 
226   if (my->hit_point <= 0)
227   {
228     set_background(1);
229     silver_chimera_explode(my);
230     add_score(30000);
231     return 0;
232   }
233 
234   return 0;
235 }
236 
237 static void
silver_chimera_explode(tenm_object * my)238 silver_chimera_explode(tenm_object *my)
239 {
240   int n;
241 
242   if (my == NULL)
243   {
244     fprintf(stderr, "silver_chimera_explode: my is NULL\n");
245     return;
246   }
247 
248   tenm_table_apply_all((int (*)(tenm_object *, int)) (&delete_enemy_shot), 0);
249   tenm_table_apply_all((int (*)(tenm_object *, int)) (&delete_enemy), 0);
250 
251   /* set "was green" flag before we change the life mode */
252   if (silver_chimera_green(my))
253   {
254     my->count[5] = 1;
255     n = 8;
256   }
257   else
258   {
259     my->count[5] = 0;
260     n = 7;
261   }
262 
263   my->count[2] = 2;
264   my->count[3] = 0;
265   my->count[1] = 0;
266 
267   my->count_d[0] = 0.0;
268   my->count_d[1] = 0.5;
269 
270   tenm_table_add(explosion_new(my->x, my->y, 0.0, 0.0,
271                                1, 5000, n, 10.0, 6));
272 
273   /* don't modify my->attr or my->hit_mask here, or the player shot
274    * may fly through the enemy */
275   tenm_mass_delete(my->mass);
276   my->mass = NULL;
277 }
278 
279 static int
silver_chimera_act(tenm_object * my,const tenm_object * player)280 silver_chimera_act(tenm_object *my, const tenm_object *player)
281 {
282   int i;
283   int theta;
284   int t_spread;
285   double x;
286   double y;
287 
288   /* sanity check */
289   if (my == NULL)
290   {
291     fprintf(stderr, "silver_chimera_act: my is NULL\n");
292     return 0;
293   }
294   if (player == NULL)
295     return 0;
296 
297   /* for deal_damage */
298   my->count[0] = 0;
299 
300   /* "damaged" count down */
301   if (my->count[1] > 0)
302     (my->count[1])--;
303 
304   (my->count[3])++;
305 
306   /* encounter */
307   if (my->count[2] == 0)
308   {
309     if (my->count[3] == 60)
310     {
311       for (i = 0; i < 2; i++)
312         tenm_table_add(silver_chimera_bit_new(my->table_index, i));
313       return 0;
314     }
315 
316     if (my->count[3] >= 120)
317     {
318       my->count[2] = 1;
319       my->count[3] = 0;
320 
321       my->count_d[0] = 0.0;
322       my->count_d[1] = 0.0;
323 
324       return 0;
325     }
326     return 0;
327   }
328 
329   /* dead */
330   if (my->count[2] == 2)
331   {
332     if (silver_chimera_green(my))
333       i = 8;
334     else
335       i = 7;
336 
337     if ((my->count[3] >= 30) && (my->count[3] <= 75)
338         && (my->count[3] % 15 == 0))
339     {
340       theta = rand() % 360;
341       tenm_table_add(explosion_new(my->x + 30.0 * tenm_cos(theta),
342                                    my->y + 30.0 * tenm_sin(theta),
343                                    0.0, 0.0,
344                                    2, 300, i, 5.0, 8));
345     }
346 
347     if (my->count[3] > 120)
348     {
349       tenm_table_add(explosion_new(my->x, my->y,
350                                    0.0, 0.0,
351                                    1, 5000, i, 10.0, 8));
352       tenm_table_add(explosion_new(my->x, my->y, 0.0, 0.0,
353                                    2, 1000, i, 7.5, 12));
354 
355       tenm_table_add(fragment_new(my->x + 48.0, my->y - 36.0, 2.8, -2.1,
356                                   30.0, 30, i, 5.0, 0.0, 16));
357       tenm_table_add(fragment_new(my->x + 48.0, my->y + 36.0, 2.8, 2.1,
358                                   30.0, 30, i, 5.0, 0.0, 16));
359       tenm_table_add(fragment_new(my->x - 48.0, my->y - 36.0, -2.8, -2.1,
360                                   30.0, 30, i, 5.0, 0.0, 16));
361       tenm_table_add(fragment_new(my->x - 48.0, my->y + 36.0, -2.8, 2.1,
362                                   30.0, 30, i, 5.0, 0.0, 16));
363 
364       tenm_table_add(stage_clear_new(100));
365       return 1;
366     }
367 
368     return 0;
369   }
370 
371   /* self-destruction */
372   if ((my->count[2] == 1) && (my->count[3] >= 5610))
373   {
374     set_background(2);
375     clear_chain();
376     silver_chimera_explode(my);
377     return 0;
378   }
379 
380   /* speed change */
381   if (my->count[3] < 180)
382   {
383     my->count_d[0] = 0.0;
384     my->count_d[1] = 0.0;
385   }
386   if ((my->count[3] == 180) || (my->count[3] == 2880))
387   {
388     my->count_d[0] = (((double) (WINDOW_WIDTH / 2)) - my->x) / 90.0;
389     my->count_d[1] = (20.0 - my->y) / 90.0;
390   }
391   if (((my->count[3] > 180) && (my->count[3] < 270))
392       || ((my->count[3] > 2880) && (my->count[3] < 2970)))
393   {
394     ;
395   }
396   if (((my->count[3] >= 270) && (my->count[3] < 990))
397       || ((my->count[3] >= 2970) && (my->count[3] < 3690)))
398   {
399     x = (double) (WINDOW_WIDTH / 2);
400     x += ((double) (WINDOW_WIDTH / 2))
401       * tenm_cos(my->count[3] * 2) * tenm_cos(my->count[3]);
402     my->count_d[0] = x - my->x;
403     my->count_d[1] = 0.0;
404   }
405   if (((my->count[3] >= 990) && (my->count[3] < 1080))
406       || ((my->count[3] >= 3690) && (my->count[3] < 3780)))
407   {
408     my->count_d[0] = 0.0;
409     my->count_d[1] = 0.0;
410   }
411   if ((my->count[3] == 1080) || (my->count[3] == 4680))
412   {
413     my->count_d[0] = (((double) (WINDOW_WIDTH / 2)) - my->x) / 90.0;
414     my->count_d[1] = (((double) (WINDOW_HEIGHT / 2)) - my->y) / 90.0;
415   }
416   if (((my->count[3] > 1080) && (my->count[3] < 1170))
417       || ((my->count[3] > 4680) && (my->count[3] < 4770)))
418   {
419     ;
420   }
421   if (((my->count[3] >= 1170) && (my->count[3] < 1890))
422       || (my->count[3] >= 4770))
423   {
424     x = (double) (WINDOW_WIDTH / 2);
425     x += ((double) (WINDOW_WIDTH / 2))
426       * tenm_cos(my->count[3] * 2) * tenm_cos(my->count[3]);
427     y = (double) (WINDOW_HEIGHT / 4);
428     y += ((double) (WINDOW_HEIGHT / 4))
429       * tenm_sin(my->count[3]);
430     my->count_d[0] = x - my->x;
431     my->count_d[1] = y - my->y;
432   }
433   if ((my->count[3] >= 1890) && (my->count[3] < 1980))
434   {
435     my->count_d[0] = 0.0;
436     my->count_d[1] = 0.0;
437   }
438   if ((my->count[3] == 1980) || (my->count[3] == 3780))
439   {
440     my->count_d[0] = (((double) (WINDOW_WIDTH / 2)) - my->x) / 90.0;
441     my->count_d[1] = (((double) (WINDOW_HEIGHT / 4)) - my->y) / 90.0;
442   }
443   if (((my->count[3] > 1980) && (my->count[3] < 2070))
444       || ((my->count[3] > 3780) && (my->count[3] < 3870)))
445   {
446     ;
447   }
448   if (((my->count[3] >= 2070) && (my->count[3] < 2880))
449       || ((my->count[3] >= 3870) && (my->count[3] < 4680)))
450   {
451     my->count_d[0] = 0.0;
452     my->count_d[1] = 0.0;
453   }
454 
455   if (my->count[2] != 1)
456     return 0;
457 
458   /* shoot */
459   if (((my->count[3] >= 360) && (my->count[3] < 990))
460       || ((my->count[3] >= 2970) && (my->count[3] < 3690)))
461   {
462     if (my->count[3] % 7 == 0)
463     {
464       if ((my->count[3] + 90) % 360 < 180)
465         theta = 80;
466       else
467         theta = 100;
468 
469       if (my->count[4] >= 2)
470       {
471         tenm_table_add(laser_angle_new(my->x, my->y + 18.0,
472                                        12.0, theta,
473                                        30.0, 1));
474         tenm_table_add(laser_angle_new(my->x + 9.0, my->y + 18.0,
475                                        9.0, theta,
476                                        30.0, 1));
477         tenm_table_add(laser_angle_new(my->x - 9.0, my->y + 18.0,
478                                        9.0, theta,
479                                        30.0, 1));
480         tenm_table_add(laser_angle_new(my->x + 27.0, my->y + 18.0,
481                                        7.0, theta,
482                                        30.0, 1));
483         tenm_table_add(laser_angle_new(my->x - 27.0, my->y + 18.0,
484                                        7.0, theta,
485                                        30.0, 1));
486         tenm_table_add(laser_angle_new(my->x + 45.0, my->y + 18.0,
487                                        5.0, theta,
488                                        30.0, 1));
489         tenm_table_add(laser_angle_new(my->x - 45.0, my->y + 18.0,
490                                        5.0, theta,
491                                        30.0, 1));
492       }
493       else
494       {
495         tenm_table_add(laser_angle_new(my->x, my->y + 18.0,
496                                        8.0, theta,
497                                        30.0, 1));
498         if (my->count[4] >= 1)
499         {
500           tenm_table_add(laser_angle_new(my->x + 15.0, my->y + 18.0,
501                                          6.5, theta,
502                                          30.0, 1));
503           tenm_table_add(laser_angle_new(my->x - 15.0, my->y + 18.0,
504                                          6.5, theta,
505                                          30.0, 1));
506         }
507         tenm_table_add(laser_angle_new(my->x + 45.0, my->y + 18.0,
508                                        5.0, theta,
509                                        30.0, 1));
510         tenm_table_add(laser_angle_new(my->x - 45.0, my->y + 18.0,
511                                        5.0, theta,
512                                        30.0, 1));
513       }
514     }
515   }
516 
517   if (((my->count[3] >= 1170) && (my->count[3] < 1890))
518       || ((my->count[3] >= 4770) && (my->count[3] < 5490)))
519   {
520     if (my->count[3] % 46 == 0)
521     {
522       if (my->count[4] >= 2)
523         t_spread = 20;
524       else if (my->count[4] == 1)
525         t_spread = 55;
526       else
527         t_spread = 70;
528       tenm_table_add(silver_chimera_spread_new(my->x + 36.0, my->y + 30.96,
529                                                -6.0, 2.5,
530                                                t_spread + rand() % 31));
531       tenm_table_add(silver_chimera_spread_new(my->x - 36.0, my->y + 30.96,
532                                                6.0, 2.5,
533                                                t_spread + rand() % 31));
534     }
535     if (my->count[3] % 46 == 23)
536     {
537       if (my->count[4] >= 2)
538         t_spread = 20;
539       else if (my->count[4] == 1)
540         t_spread = 50;
541       else
542         t_spread = 80;
543       tenm_table_add(silver_chimera_spread_new(my->x, my->y,
544                                                0.0, 6.5,
545                                                t_spread + rand() % 31));
546     }
547   }
548 
549   if (((my->count[3] >= 2070) && (my->count[3] < 2790))
550       || ((my->count[3] >= 3840) && (my->count[3] < 4590)))
551   {
552     if ((my->count[3] % 37 == 0)
553         && ((my->count[4] >= 2)
554             || ((my->count[4] >= 1) && (my->count[3] % 148 < 74))
555             || (my->count[3] % 148 == 0)))
556     {
557       tenm_table_add(silver_chimera_lock_on_new(player->x, player->y));
558     }
559   }
560 
561   return 0;
562 }
563 
564 static int
silver_chimera_draw(tenm_object * my,int priority)565 silver_chimera_draw(tenm_object *my, int priority)
566 {
567   int status = 0;
568   tenm_color color;
569   char temp[32];
570 
571   /* sanity check */
572   if (my == NULL)
573   {
574     fprintf(stderr, "silver_chimera_draw: my is NULL\n");
575     return 0;
576   }
577 
578   /* body */
579   if (priority == 0)
580   {
581     if (silver_chimera_green(my))
582     {
583       if (my->count[1] >= 1)
584         color = tenm_map_color(109, 125, 9);
585       else
586         color = tenm_map_color(61, 95, 13);
587     }
588     else
589     {
590       if (my->count[1] >= 1)
591         color = tenm_map_color(135, 89, 9);
592       else
593         color = tenm_map_color(95, 47, 13);
594     }
595 
596     if (tenm_draw_line((int) (my->x), (int) (my->y - 18.0),
597                        (int) (my->x + 78.72), (int) (my->y - 77.04),
598                        3, color))
599       status = 1;
600     if (tenm_draw_line((int) (my->x + 78.72), (int) (my->y - 77.04),
601                        (int) (my->x + 96.0), (int) (my->y - 54.0),
602                        3, color))
603       status = 1;
604     if (tenm_draw_line((int) (my->x + 96.0), (int) (my->y - 54.0),
605                        (int) (my->x + 24.0), (int) (my->y),
606                        3, color))
607       status = 1;
608     if (tenm_draw_line((int) (my->x + 24.0), (int) (my->y),
609                        (int) (my->x + 65.28), (int) (my->y + 30.96),
610                        3, color))
611       status = 1;
612     if (tenm_draw_line((int) (my->x + 65.28), (int) (my->y + 30.96),
613                        (int) (my->x + 48.0), (int) (my->y + 54.0),
614                        3, color))
615       status = 1;
616     if (tenm_draw_line((int) (my->x + 48.0), (int) (my->y + 54.0),
617                        (int) (my->x), (int) (my->y + 18.0),
618                        3, color))
619       status = 1;
620 
621     if (tenm_draw_line((int) (my->x), (int) (my->y - 18.0),
622                        (int) (my->x - 78.72), (int) (my->y - 77.04),
623                        3, color))
624       status = 1;
625     if (tenm_draw_line((int) (my->x - 78.72), (int) (my->y - 77.04),
626                        (int) (my->x - 96.0), (int) (my->y - 54.0),
627                        3, color))
628       status = 1;
629     if (tenm_draw_line((int) (my->x - 96.0), (int) (my->y - 54.0),
630                        (int) (my->x - 24.0), (int) (my->y),
631                        3, color))
632       status = 1;
633     if (tenm_draw_line((int) (my->x - 24.0), (int) (my->y),
634                        (int) (my->x - 65.28), (int) (my->y + 30.96),
635                        3, color))
636       status = 1;
637     if (tenm_draw_line((int) (my->x - 65.28), (int) (my->y + 30.96),
638                        (int) (my->x - 48.0), (int) (my->y + 54.0),
639                        3, color))
640       status = 1;
641     if (tenm_draw_line((int) (my->x - 48.0), (int) (my->y + 54.0),
642                        (int) (my->x), (int) (my->y + 18.0),
643                        3, color))
644       status = 1;
645   }
646 
647   /* hit point stat */
648   if ((priority == 0) && (my->count[2] == 1))
649   {
650     sprintf(temp, "%d", my->hit_point);
651     if (draw_string(((int) my->x) - 10, (int) my->y,
652                     temp, (int) strlen(temp)) != 0)
653     {
654       fprintf(stderr, "silver_chimera_draw: draw_string failed\n");
655       status = 1;
656     }
657   }
658 
659   return status;
660 }
661 
662 /* return 1 (true) or 0 (false) */
663 static int
silver_chimera_green(const tenm_object * my)664 silver_chimera_green(const tenm_object *my)
665 {
666   /* sanity check */
667   if (my == NULL)
668     return 0;
669 
670   if ((my->count[2] == 1)
671       && (my->count[3] >= 270) && (my->count[3] < 5580))
672     return 1;
673 
674   if ((my->count[2] == 2) && (my->count[5] != 0))
675     return 1;
676 
677   return 0;
678 }
679 
680 static tenm_object *
silver_chimera_spread_new(double x,double y,double speed_x,double speed_y,int t_spread)681 silver_chimera_spread_new(double x, double y, double speed_x, double speed_y,
682                           int t_spread)
683 {
684   tenm_primitive **p = NULL;
685   tenm_object *new = NULL;
686   int *count = NULL;
687   double *count_d = NULL;
688 
689   /* sanity check */
690   if (t_spread <= 0)
691   {
692     fprintf(stderr, "silver_chimera_spread_new: t_spread is non-positive "
693             "(%d)\n", t_spread);
694     return NULL;
695   }
696 
697   p = (tenm_primitive **) malloc(sizeof(tenm_primitive *) * 1);
698   if (p == NULL)
699   {
700     fprintf(stderr, "silver_chimera_spread_new: malloc(p) failed\n");
701     return NULL;
702   }
703 
704   p[0] = (tenm_primitive *) tenm_circle_new(x, y, 10.0);
705   if (p[0] == NULL)
706   {
707     fprintf(stderr, "silver_chimera_spread_new: cannot set p[0]\n");
708     free(p);
709     return NULL;
710   }
711 
712   count = (int *) malloc(sizeof(int) * 3);
713   if (count == NULL)
714   {
715     fprintf(stderr, "silver_chimera_spread_new: malloc(count) failed\n");
716     (p[0])->delete(p[0]);
717     free(p);
718     return NULL;
719   }
720   count_d = (double *) malloc(sizeof(double) * 2);
721   if (count_d == NULL)
722   {
723     fprintf(stderr, "silver_chimera_spread_new: malloc(count_d) failed\n");
724     free(count);
725     (p[0])->delete(p[0]);
726     free(p);
727     return NULL;
728   }
729 
730   /* list of count
731    * [0] color (for delete_enemy_shot)
732    * [1] spread mode
733    * [2] spread timer
734    */
735   /* list of count_d
736    * [0] speed x
737    * [1] speed y
738    */
739   count[0] = 2;
740   count[1] = 0;
741   count[2] = -t_spread;
742 
743   count_d[0] = speed_x;
744   count_d[1] = speed_y;
745 
746   new = tenm_object_new("Silver Chimera spread", ATTR_ENEMY_SHOT, ATTR_OPAQUE,
747                         1, x, y,
748                         3, count, 2, count_d, 1, p,
749                         (int (*)(tenm_object *, double))
750                         (&silver_chimera_spread_move),
751                         (int (*)(tenm_object *, tenm_object *))
752                         (&silver_chimera_spread_hit),
753                         (int (*)(tenm_object *, const tenm_object *))
754                         (&silver_chimera_spread_act),
755                         (int (*)(tenm_object *, int))
756                         (&silver_chimera_spread_draw));
757   if (new == NULL)
758   {
759     fprintf(stderr, "silver_chimera_spread_new: tenm_object_new failed\n");
760     if (count_d != NULL)
761       free(count_d);
762     if (count != NULL)
763       free(count);
764     (p[0])->delete(p[0]);
765     free(p);
766     return NULL;
767   }
768 
769   return new;
770 }
771 
772 static int
silver_chimera_spread_move(tenm_object * my,double turn_per_frame)773 silver_chimera_spread_move(tenm_object *my, double turn_per_frame)
774 {
775   double dx_temp;
776   double dy_temp;
777 
778   /* sanity check */
779   if (my == NULL)
780   {
781     fprintf(stderr, "silver_chimera_spread_move: my is NULL\n");
782     return 0;
783   }
784   if (turn_per_frame <= 0.5)
785   {
786     fprintf(stderr, "silver_chimera_spread_move: "
787             "strange turn_per_frame (%f)\n",
788             turn_per_frame);
789     return 0;
790   }
791 
792   dx_temp = my->count_d[0] / turn_per_frame;
793   dy_temp = my->count_d[1] / turn_per_frame;
794   my->x += dx_temp;
795   my->y += dy_temp;
796   if (my->mass != NULL)
797     tenm_move_mass(my->mass, dx_temp, dy_temp);
798 
799   /* shape change */
800   if ((my->count[1] == 1) && (my->mass != NULL))
801     ((tenm_circle *)(my->mass->p[0]))->r += 2.0 / turn_per_frame;
802 
803   if (!in_window_object(my))
804     return 1;
805 
806   return 0;
807 }
808 
809 static int
silver_chimera_spread_hit(tenm_object * my,tenm_object * your)810 silver_chimera_spread_hit(tenm_object *my, tenm_object *your)
811 {
812   /* sanity check */
813   if (my == NULL)
814   {
815     fprintf(stderr, "silver_chimera_spread_hit: my is NULL\n");
816     return 0;
817   }
818   if (your == NULL)
819   {
820     fprintf(stderr, "silver_chimera_spread_hit: your is NULL\n");
821     return 0;
822   }
823 
824   if (your->attr & ATTR_OPAQUE)
825     return 1;
826 
827   return 0;
828 }
829 
830 static int
silver_chimera_spread_act(tenm_object * my,const tenm_object * player)831 silver_chimera_spread_act(tenm_object *my, const tenm_object *player)
832 {
833   int i;
834   int theta;
835 
836   /* sanity check */
837   if (my == NULL)
838   {
839     fprintf(stderr, "silver_chimera_spread_act: my is NULL\n");
840     return 0;
841   }
842   if (player == NULL)
843     return 0;
844 
845   (my->count[2])++;
846   switch (my->count[1])
847   {
848   case 0:
849     if (my->count[2] >= 0)
850     {
851       my->count[1] = 1;
852       my->count[2] = 0;
853       my->count_d[0] = 0.0;
854       my->count_d[1] = 0.0;
855     }
856     break;
857   case 1:
858     if (my->count[2] == 10)
859     {
860       tenm_table_add(laser_point_new(my->x, my->y, 5.0,
861                                      player->x, player->y, 25.0, 2));
862     }
863     if (my->count[2] >= 20)
864     {
865       my->count[0] = 3;
866       my->count[1] = 2;
867       my->count[2] = 0;
868     }
869     break;
870   case 2:
871     if (my->count[2] % 5 == 0)
872     {
873       theta = rand() % 360;
874       for (i = 0; i < 360; i += 120)
875         tenm_table_add(laser_angle_new(my->x, my->y, 7.0,
876                                        theta + i, 25.0, 3));
877     }
878     if (my->count[2] >= 20)
879     {
880       return 1;
881     }
882     break;
883   default:
884     fprintf(stderr, "silver_chimera_spread_act: strange my->count[1] (%d)\n",
885             my->count[1]);
886     break;
887   }
888 
889   return 0;
890 }
891 
892 static int
silver_chimera_spread_draw(tenm_object * my,int priority)893 silver_chimera_spread_draw(tenm_object *my, int priority)
894 {
895   int status = 0;
896   tenm_color color;
897   int r = 1;
898 
899   /* sanity check */
900   if (my == NULL)
901   {
902     fprintf(stderr, "silver_chimera_spread_draw: my is NULL\n");
903     return 0;
904   }
905 
906   if ((priority == 0) && (my->count[1] == 0))
907   {
908     color = tenm_map_color(99, 143, 158);
909     color = tenm_map_color(0, 167, 223);
910     color = tenm_map_color(167, 196, 206);
911     if (tenm_draw_line((int) (my->x), (int) (my->y),
912                        (int) (my->x + my->count_d[0] * (double)(my->count[2])),
913                        (int) (my->y + my->count_d[1] * (double)(my->count[2])),
914                        1, color))
915       status = 1;
916   }
917   if (priority == 1)
918   {
919     switch (my->count[1])
920     {
921     case 0:
922       r = 10;
923       color = tenm_map_color(0, 167, 223);
924       break;
925     case 1:
926       r = 10 + my->count[2] * 2;
927       color = tenm_map_color(0, 167, 223);
928       break;
929     case 2:
930       r = 50;
931       color = tenm_map_color(0, 111, 223);
932       break;
933     default:
934       fprintf(stderr, "silver_chimera_spread_draw: strange my->count[1] "
935               "(%d)\n",
936               my->count[1]);
937       r = 1;
938       color = tenm_map_color(0, 0, 0);
939       break;
940     }
941     if (tenm_draw_circle((int) (my->x), (int) (my->y), r, 3, color) != 0)
942       status = 1;
943   }
944 
945   return status;
946 }
947 
948 static tenm_object *
silver_chimera_lock_on_new(double x,double y)949 silver_chimera_lock_on_new(double x, double y)
950 {
951   tenm_object *new = NULL;
952   int *count = NULL;
953 
954   count = (int *) malloc(sizeof(int) * 4);
955   if (count == NULL)
956   {
957     fprintf(stderr, "silver_chimera_spread_new: malloc(count) failed\n");
958     return NULL;
959   }
960 
961   /* list of count
962    * [0] color (for delete_enemy_shot)
963    * [1] shoot mode
964    * [2] shoot timer
965    * [3] shoot direction
966    */
967   count[0] = 6;
968   count[1] = 0;
969   count[2] = 1;
970   count[3] = rand() % 2;
971 
972   /* ATTR_ENEMY_SHOT is only to clear it when the player is killed */
973   new = tenm_object_new("Silver Chimera lock on", ATTR_ENEMY_SHOT, 0,
974                         1, x, y,
975                         4, count, 0, NULL, 0, NULL,
976                         (int (*)(tenm_object *, double)) NULL,
977                         (int (*)(tenm_object *, tenm_object *)) NULL,
978                         (int (*)(tenm_object *, const tenm_object *))
979                         (&silver_chimera_lock_on_act),
980                         (int (*)(tenm_object *, int))
981                         (&silver_chimera_lock_on_draw));
982   if (new == NULL)
983   {
984     fprintf(stderr, "silver_chimera_lock_on_new: tenm_object_new failed\n");
985     if (count != NULL)
986       free(count);
987     return NULL;
988   }
989 
990   return new;
991 }
992 
993 static int
silver_chimera_lock_on_act(tenm_object * my,const tenm_object * player)994 silver_chimera_lock_on_act(tenm_object *my, const tenm_object *player)
995 {
996   double length;
997 
998   /* sanity check */
999   if (my == NULL)
1000   {
1001     fprintf(stderr, "silver_chimera_lock_on_act: my is NULL\n");
1002     return 0;
1003   }
1004   if (player == NULL)
1005     return 0;
1006 
1007   (my->count[2])++;
1008   switch (my->count[1])
1009   {
1010   case 0:
1011     if (my->count[2] >= 20)
1012     {
1013       my->count[1] = 1;
1014       my->count[2] = 0;
1015     }
1016     break;
1017   case 1:
1018     length = 5.0 * (double) (140 - my->count[2]);
1019     if (my->count[2] % 10 == 0)
1020     {
1021       if (my->count[2] % 20 == 10 * my->count[3])
1022       {
1023         tenm_table_add(laser_angle_new(my->x + length, my->y + length, 9.0,
1024                                        180, 25.0, 0));
1025         tenm_table_add(laser_angle_new(my->x + length, my->y + length, 9.0,
1026                                        -90, 25.0, 0));
1027         tenm_table_add(laser_angle_new(my->x - length, my->y - length, 9.0,
1028                                        0, 25.0, 0));
1029         tenm_table_add(laser_angle_new(my->x - length, my->y - length, 9.0,
1030                                        90, 25.0, 0));
1031       }
1032       else
1033       {
1034         tenm_table_add(laser_angle_new(my->x + length, my->y - length, 9.0,
1035                                        180, 25.0, 0));
1036         tenm_table_add(laser_angle_new(my->x + length, my->y - length, 9.0,
1037                                        90, 25.0, 0));
1038         tenm_table_add(laser_angle_new(my->x - length, my->y + length, 9.0,
1039                                        0, 25.0, 0));
1040         tenm_table_add(laser_angle_new(my->x - length, my->y + length, 9.0,
1041                                        -90, 25.0, 0));
1042       }
1043     }
1044     if (my->count[2] >= 140)
1045     {
1046       return 1;
1047     }
1048     break;
1049   default:
1050     fprintf(stderr, "silver_chimera_lock_on_act: strange my->count[1] (%d)\n",
1051             my->count[1]);
1052     break;
1053   }
1054 
1055   return 0;
1056 }
1057 
1058 static int
silver_chimera_lock_on_draw(tenm_object * my,int priority)1059 silver_chimera_lock_on_draw(tenm_object *my, int priority)
1060 {
1061   int status = 0;
1062 
1063   /* sanity check */
1064   if (my == NULL)
1065   {
1066     fprintf(stderr, "silver_chimera_lock_on_draw: my is NULL\n");
1067     return 0;
1068   }
1069 
1070   if (priority != 0)
1071     return 0;
1072 
1073   switch (my->count[1])
1074   {
1075   case 0:
1076     if (silver_chimera_lock_on_draw_square((int) my->x, (int) my->y,
1077                                            200 + 25 * my->count[2],
1078                                            tenm_map_color(158, 158, 158)) != 0)
1079       status = 1;
1080     if (silver_chimera_lock_on_draw_square((int) my->x, (int) my->y,
1081                                            200 - 10 * my->count[2],
1082                                            tenm_map_color(158, 158, 158)) != 0)
1083       status = 1;
1084     break;
1085   case 1:
1086     if (silver_chimera_lock_on_draw_square((int) my->x, (int) my->y,
1087                                            5 * (140 - my->count[2]),
1088                                            tenm_map_color(99, 158, 114)) != 0)
1089       status = 1;
1090 
1091     if (tenm_draw_line(((int) (my->x)) - 25, ((int) (my->y)),
1092                        ((int) (my->x)) + 25, ((int) (my->y)),
1093                        1, tenm_map_color(158, 158, 158)) != 0)
1094       status = 1;
1095     if (tenm_draw_line(((int) (my->x)), ((int) (my->y)) - 25,
1096                        ((int) (my->x)), ((int) (my->y)) + 25,
1097                        1, tenm_map_color(158, 158, 158)) != 0)
1098       status = 1;
1099 
1100     break;
1101   default:
1102     fprintf(stderr, "silver_chimera_lock_on_draw: strange my->count[1] "
1103             "(%d)\n",
1104             my->count[1]);
1105     break;
1106   }
1107 
1108   return status;
1109 }
1110 
1111 static int
silver_chimera_lock_on_draw_square(int x,int y,int length,tenm_color color)1112 silver_chimera_lock_on_draw_square(int x, int y, int length,
1113                                    tenm_color color)
1114 {
1115   int status = 0;
1116 
1117   /* sanity check */
1118   if (length <= 0)
1119   {
1120     fprintf(stderr, "silver_chimera_lock_on_draw_square: length is "
1121             "non-positive (%d)\n", length);
1122     return 1;
1123   }
1124 
1125   if (tenm_draw_line(x + length, y + length,
1126                      x - length, y + length,
1127                      1, color) != 0)
1128     status = 1;
1129   if (tenm_draw_line(x - length, y + length,
1130                      x - length, y - length,
1131                      1, color) != 0)
1132     status = 1;
1133   if (tenm_draw_line(x - length, y - length,
1134                      x + length, y - length,
1135                      1, color) != 0)
1136     status = 1;
1137   if (tenm_draw_line(x + length, y - length,
1138                      x + length, y + length,
1139                      1, color) != 0)
1140     status = 1;
1141 
1142   return status;
1143 }
1144 
1145 static tenm_object *
silver_chimera_bit_new(int table_index,int n)1146 silver_chimera_bit_new(int table_index, int n)
1147 {
1148   tenm_primitive **p = NULL;
1149   tenm_object *new = NULL;
1150   int *count = NULL;
1151   double *count_d = NULL;
1152   double x;
1153   double y;
1154 
1155   /* sanity check */
1156   if ((n < 0) || (n > 1))
1157   {
1158     fprintf(stderr, "silver_chimera_bit_new: strange n (%d)\n", n);
1159     return NULL;
1160   }
1161 
1162   if (n == 0)
1163     x = (double) (WINDOW_WIDTH / 8);
1164   else
1165     x = (double) (WINDOW_WIDTH * 7 / 8);
1166   y = -19.0;
1167 
1168   p = (tenm_primitive **) malloc(sizeof(tenm_primitive *) * 1);
1169   if (p == NULL)
1170   {
1171     fprintf(stderr, "silver_chimera_bit_new: malloc(p) failed\n");
1172     return NULL;
1173   }
1174 
1175   p[0] = (tenm_primitive *) tenm_polygon_new(4,
1176                                              x + 20.0, y + 20.0,
1177                                              x - 20.0, y + 20.0,
1178                                              x - 20.0, y - 20.0,
1179                                              x + 20.0, y - 20.0);
1180   if (p[0] == NULL)
1181   {
1182     fprintf(stderr, "silver_chimera_bit_new: cannot set p[0]\n");
1183     free(p);
1184     return NULL;
1185   }
1186 
1187   count = (int *) malloc(sizeof(int) * 6);
1188   if (count == NULL)
1189   {
1190     fprintf(stderr, "silver_chimera_bit_new: malloc(count) failed\n");
1191     (p[0])->delete(p[0]);
1192     free(p);
1193     return NULL;
1194   }
1195   count_d = (double *) malloc(sizeof(double) * 2);
1196   if (count_d == NULL)
1197   {
1198     fprintf(stderr, "silver_chimera_bit_new: malloc(count_d) failed\n");
1199     free(count);
1200     (p[0])->delete(p[0]);
1201     free(p);
1202     return NULL;
1203   }
1204 
1205   /* list of count
1206    * [0] for deal_damage
1207    * [1] "damaged" timer
1208    * [2] move mode
1209    * [3] move timer
1210    * [4] n
1211    * [5] core index
1212    */
1213   /* list of count_d
1214    * [0] speed x
1215    * [1] speed y
1216    */
1217 
1218   count[0] = 0;
1219   count[1] = 0;
1220   count[2] = 0;
1221   count[3] = 60;
1222   count[4] = n;
1223   count[5] = table_index;
1224 
1225   count_d[0] = 0.0;
1226   count_d[1] = (((double) (WINDOW_HEIGHT / 4)) - y) / 60.0;
1227 
1228   new = tenm_object_new("Silver Chimera bit", ATTR_ENEMY, ATTR_PLAYER_SHOT,
1229                         750, x, y,
1230                         6, count, 2, count_d, 1, p,
1231                         (int (*)(tenm_object *, double))
1232                         (&silver_chimera_bit_move),
1233                         (int (*)(tenm_object *, tenm_object *))
1234                         (&silver_chimera_bit_hit),
1235                         (int (*)(tenm_object *, const tenm_object *))
1236                         (&silver_chimera_bit_act),
1237                         (int (*)(tenm_object *, int))
1238                         (&silver_chimera_bit_draw));
1239   if (new == NULL)
1240   {
1241     fprintf(stderr, "silver_chimera_bit_new: tenm_object_new failed\n");
1242     if (count_d != NULL)
1243       free(count_d);
1244     if (count != NULL)
1245       free(count);
1246     (p[0])->delete(p[0]);
1247     free(p);
1248     return NULL;
1249   }
1250 
1251   return new;
1252 }
1253 
1254 static int
silver_chimera_bit_move(tenm_object * my,double turn_per_frame)1255 silver_chimera_bit_move(tenm_object *my, double turn_per_frame)
1256 {
1257   double dx_temp;
1258   double dy_temp;
1259 
1260   /* sanity check */
1261   if (my == NULL)
1262   {
1263     fprintf(stderr, "silver_chimera_bit_move: my is NULL\n");
1264     return 0;
1265   }
1266   if (turn_per_frame <= 0.5)
1267   {
1268     fprintf(stderr, "silver_chimera_bit_move: strange turn_per_frame (%f)\n",
1269             turn_per_frame);
1270     return 0;
1271   }
1272 
1273   dx_temp = my->count_d[0] / turn_per_frame;
1274   dy_temp = my->count_d[1] / turn_per_frame;
1275   my->x += dx_temp;
1276   my->y += dy_temp;
1277   if (my->mass != NULL)
1278     tenm_move_mass(my->mass, dx_temp, dy_temp);
1279 
1280   return 0;
1281 }
1282 
1283 static int
silver_chimera_bit_hit(tenm_object * my,tenm_object * your)1284 silver_chimera_bit_hit(tenm_object *my, tenm_object *your)
1285 {
1286   int n;
1287 
1288   /* sanity check */
1289   if (my == NULL)
1290   {
1291     fprintf(stderr, "silver_chimera_bit_hit: my is NULL\n");
1292     return 0;
1293   }
1294   if (your == NULL)
1295   {
1296     fprintf(stderr, "silver_chimera_bit_hit: your is NULL\n");
1297     return 0;
1298   }
1299 
1300   if (!(your->attr & ATTR_PLAYER_SHOT))
1301     return 0;
1302   if (my->count[2] != 1)
1303     return 0;
1304 
1305   deal_damage(my, your, 0);
1306   if (silver_chimera_bit_green(my))
1307     add_chain(my, your);
1308   my->count[1] = 41;
1309 
1310   if (my->hit_point <= 0)
1311   {
1312     add_score(20000);
1313     tenm_table_apply(my->count[5],
1314                      (int (*)(tenm_object *, int))
1315                      (&silver_chimera_bit_signal),
1316                      0);
1317 
1318     if (silver_chimera_bit_green(my))
1319       n = 8;
1320     else
1321       n = 7;
1322     tenm_table_add(explosion_new(my->x, my->y,
1323                                  my->count_d[0] * 0.5,
1324                                  my->count_d[1] * 0.5,
1325                                  1, 1000, n, 8.0, 6));
1326     tenm_table_add(fragment_new(my->x, my->y,
1327                                 my->count_d[0] * 0.5, my->count_d[1] * 0.5,
1328                                 30.0, 30, n, 5.0, 0.0, 20));
1329     return 1;
1330   }
1331 
1332   return 0;
1333 }
1334 
1335 static int
silver_chimera_bit_signal(tenm_object * my,int n)1336 silver_chimera_bit_signal(tenm_object *my, int n)
1337 {
1338   /* sanity check */
1339   if (my == NULL)
1340     return 0;
1341   if (strcmp(my->name, "Silver Chimera") != 0)
1342     return 0;
1343 
1344   (my->count[4])++;
1345 
1346   return 0;
1347 }
1348 
1349 static int
silver_chimera_bit_act(tenm_object * my,const tenm_object * player)1350 silver_chimera_bit_act(tenm_object *my, const tenm_object *player)
1351 {
1352   double x;
1353   double y;
1354 
1355   /* sanity check */
1356   if (my == NULL)
1357   {
1358     fprintf(stderr, "silver_chimera_bit_act: my is NULL\n");
1359     return 0;
1360   }
1361   if (player == NULL)
1362     return 0;
1363 
1364   /* for deal_damage */
1365   my->count[0] = 0;
1366 
1367   /* "damaged" count down */
1368   if (my->count[1] > 0)
1369     (my->count[1])--;
1370 
1371   (my->count[3])++;
1372 
1373   /* encounter */
1374   if (my->count[2] == 0)
1375   {
1376     if (my->count[3] >= 120)
1377     {
1378       my->count[2] = 1;
1379       my->count[3] = 0;
1380 
1381       my->count_d[0] = 0.0;
1382       my->count_d[1] = 0.0;
1383 
1384       return 0;
1385     }
1386     return 0;
1387   }
1388 
1389   /* speed change */
1390   if ((my->count[3] == 1080) || (my->count[3] == 4680))
1391   {
1392     x = (double) (WINDOW_WIDTH / 2);
1393     if (my->count[4] == 0)
1394       x -= 96.0;
1395     else
1396       x += 96.0;
1397     my->count_d[0] = (x - my->x) / 90.0;
1398     my->count_d[1] = (((double) (WINDOW_HEIGHT / 2)) - my->y) / 90.0;
1399   }
1400   if (((my->count[3] > 1080) && (my->count[3] < 1170))
1401       || ((my->count[3] > 4680) && (my->count[3] < 4770)))
1402   {
1403     ;
1404   }
1405   if (((my->count[3] >= 1170) && (my->count[3] < 1890))
1406       || (my->count[3] >= 4770))
1407   {
1408     x = (double) (WINDOW_WIDTH / 2);
1409     x += ((double) (WINDOW_WIDTH / 2))
1410       * tenm_cos(my->count[3] * 2) * tenm_cos(my->count[3]);
1411     if (my->count[4] == 0)
1412       x -= 96.0;
1413     else
1414       x += 96.0;
1415     y = (double) (WINDOW_HEIGHT / 4);
1416     y += ((double) (WINDOW_HEIGHT / 4))
1417       * tenm_sin(my->count[3]);
1418     my->count_d[0] = x - my->x;
1419     my->count_d[1] = y - my->y;
1420   }
1421   if (my->count[3] == 1890)
1422   {
1423     my->count_d[0] = 0.0;
1424     my->count_d[1] = 0.0;
1425   }
1426   if (my->count[3] == 1980)
1427   {
1428     if (my->count[4] == 0)
1429       x = (double) (WINDOW_WIDTH / 8);
1430     else
1431       x = (double) (WINDOW_WIDTH * 7 / 8);
1432     my->count_d[0] = (x - my->x) / 90.0;
1433     my->count_d[1] = (((double) (WINDOW_HEIGHT / 4)) - my->y) / 90.0;
1434   }
1435   if (my->count[3] == 2070)
1436   {
1437     my->count_d[0] = 0.0;
1438     my->count_d[1] = 0.0;
1439   }
1440 
1441   if (my->count[2] != 1)
1442     return 0;
1443 
1444   /* shoot */
1445   if ((my->count[3] >= 35) && (my->count[3] < 5490)
1446       && (my->count[3] % 14 == my->count[4] * 7))
1447     tenm_table_add(normal_shot_point_new(my->x, my->y, 7.0,
1448                                          player->x
1449                                          +((double)(rand()%101))-50.0,
1450                                          player->y
1451                                          +((double)(rand()%101))-50.0,
1452                                          4));
1453 
1454   return 0;
1455 }
1456 
1457 static int
silver_chimera_bit_draw(tenm_object * my,int priority)1458 silver_chimera_bit_draw(tenm_object *my, int priority)
1459 {
1460   int status = 0;
1461   tenm_color color;
1462   char temp[32];
1463 
1464   /* sanity check */
1465   if (my == NULL)
1466   {
1467     fprintf(stderr, "silver_chimera_bit_draw: my is NULL\n");
1468     return 0;
1469   }
1470 
1471   if (priority != 0)
1472     return 0;
1473 
1474   /* decoration */
1475   if (silver_chimera_bit_green(my))
1476   {
1477     if (my->count[1] >= 40)
1478       color = tenm_map_color(109, 125, 9);
1479     else
1480       color = tenm_map_color(61, 95, 13);
1481   }
1482   else
1483   {
1484     if (my->count[1] >= 40)
1485       color = tenm_map_color(135, 89, 9);
1486     else
1487       color = tenm_map_color(95, 47, 13);
1488   }
1489   if (tenm_draw_line((int) (my->x + 10.0), (int) (my->y - 20.0),
1490                      (int) (my->x + 20.0), (int) (my->y - 30.0),
1491                      1, color))
1492     status = 1;
1493   if (tenm_draw_line((int) (my->x + 20.0), (int) (my->y - 30.0),
1494                      (int) (my->x - 20.0), (int) (my->y - 30.0),
1495                      1, color))
1496     status = 1;
1497   if (tenm_draw_line((int) (my->x - 20.0), (int) (my->y - 30.0),
1498                      (int) (my->x - 10.0), (int) (my->y - 20.0),
1499                      1, color))
1500     status = 1;
1501 
1502   /* body */
1503   /*
1504   if (tenm_draw_mass(my->mass, tenm_map_color(0, 0, 0)) != 0)
1505     status = 1;
1506   */
1507   if (silver_chimera_bit_green(my))
1508   {
1509     if (my->count[1] >= 40)
1510       color = tenm_map_color(109, 125, 9);
1511     else
1512       color = tenm_map_color(61, 95, 13);
1513   }
1514   else
1515   {
1516     if (my->count[1] >= 40)
1517       color = tenm_map_color(135, 89, 9);
1518     else
1519       color = tenm_map_color(95, 47, 13);
1520   }
1521 
1522   if (tenm_draw_line((int) (my->x + 20.0), (int) (my->y + 20.0),
1523                      (int) (my->x - 20.0), (int) (my->y + 20.0),
1524                      2, color))
1525     status = 1;
1526   if (tenm_draw_line((int) (my->x - 20.0), (int) (my->y + 20.0),
1527                      (int) (my->x - 20.0), (int) (my->y - 20.0),
1528                      2, color))
1529     status = 1;
1530   if (tenm_draw_line((int) (my->x - 20.0), (int) (my->y - 20.0),
1531                        (int) (my->x + 20.0), (int) (my->y - 20.0),
1532                      2, color))
1533     status = 1;
1534   if (tenm_draw_line((int) (my->x + 20.0), (int) (my->y - 20.0),
1535                      (int) (my->x + 20.0), (int) (my->y + 20.0),
1536                      2, color))
1537     status = 1;
1538 
1539   /* hit point stat */
1540   if ((my->count[2] == 1) && (my->count[1] >= 1))
1541   {
1542     sprintf(temp, "%d", my->hit_point);
1543     if (draw_string(((int) my->x) - 5, (int) my->y,
1544                     temp, (int) strlen(temp)) != 0)
1545     {
1546       fprintf(stderr, "silver_chimera_draw: draw_string failed\n");
1547       status = 1;
1548     }
1549   }
1550 
1551   return status;
1552 }
1553 
1554 /* return 1 (true) or 0 (false) */
1555 static int
silver_chimera_bit_green(const tenm_object * my)1556 silver_chimera_bit_green(const tenm_object *my)
1557 {
1558   /* sanity check */
1559   if (my == NULL)
1560     return 0;
1561 
1562   if ((my->count[2] == 1)
1563       && (my->count[3] >= 35) && (my->count[3] < 5580))
1564     return 1;
1565 
1566   return 0;
1567 }
1568