1 /* $Id: insane-hand.c,v 1.211 2011/08/23 20:09:40 oohara Exp $ */
2 /* [normal] Hell Salvage */
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 "normal-enemy.h"
25 #include "stage-clear.h"
26 #include "score.h"
27 #include "ship.h"
28 
29 #include "insane-hand.h"
30 
31 #define NEAR_ZERO 0.0001
32 
33 static int insane_hand_move(tenm_object *my, double turn_per_frame);
34 static int insane_hand_hit(tenm_object *my, tenm_object *your);
35 static void insane_hand_next(tenm_object *my);
36 static int insane_hand_act(tenm_object *my, const tenm_object *player);
37 static int insane_hand_draw(tenm_object *my, int priority);
38 static int insane_hand_body_line(double a_x, double a_y,
39                                  double b_x, double b_y,
40                                  int width, tenm_color color, int theta);
41 static void insane_hand_body_rotate(double *result, const double *v,
42                                     int theta);
43 static int insane_hand_green(const tenm_object *my);
44 
45 static tenm_object *insane_hand_ship_new(double x, double y);
46 static int insane_hand_ship_move(tenm_object *my, double turn_per_frame);
47 static int insane_hand_ship_hit(tenm_object *my, tenm_object *your);
48 static int insane_hand_ship_signal_bit(tenm_object *my, int n);
49 static int insane_hand_ship_act(tenm_object *my, const tenm_object *player);
50 static int insane_hand_ship_draw(tenm_object *my, int priority);
51 static int insane_hand_ship_green(const tenm_object *my);
52 
53 static tenm_object *insane_hand_ship_bit_new(double x, double y);
54 static int insane_hand_ship_bit_move(tenm_object *my, double turn_per_frame);
55 static int insane_hand_ship_bit_act(tenm_object *my,
56                                     const tenm_object *player);
57 static int insane_hand_ship_bit_draw(tenm_object *my, int priority);
58 
59 static tenm_object *insane_hand_ship_shot_new(double x, double y,
60                                               double v_x, double v_y);
61 static int insane_hand_ship_shot_move(tenm_object *my, double turn_per_frame);
62 static int insane_hand_ship_shot_hit(tenm_object *my, tenm_object *your);
63 static int insane_hand_ship_shot_act(tenm_object *my,
64                                     const tenm_object *player);
65 static int insane_hand_ship_shot_draw(tenm_object *my, int priority);
66 
67 tenm_object *
insane_hand_new(void)68 insane_hand_new(void)
69 {
70   tenm_primitive **p = NULL;
71   tenm_object *new = NULL;
72   int *count = NULL;
73   double *count_d = NULL;
74   double x = (double) (WINDOW_WIDTH / 2);
75   double y = -75.0;
76 
77   p = (tenm_primitive **) malloc(sizeof(tenm_primitive *) * 1);
78   if (p == NULL)
79   {
80     fprintf(stderr, "insane_hand_new: malloc(p) failed\n");
81     return NULL;
82   }
83 
84   p[0] = (tenm_primitive *) tenm_polygon_new(4,
85                                              x + 50.0, y - 25.0,
86                                              x + 50.0, y + 25.0,
87                                              x - 50.0, y + 25.0,
88                                              x - 50.0, y - 25.0);
89   if (p[0] == NULL)
90   {
91     fprintf(stderr, "insane_hand_new: cannot set p[0]\n");
92     free(p);
93     return NULL;
94   }
95 
96   count = (int *) malloc(sizeof(int) * 8);
97   if (count == NULL)
98   {
99     fprintf(stderr, "insane_hand_new: malloc(count) failed\n");
100     (p[0])->delete(p[0]);
101     free(p);
102     return NULL;
103   }
104   count_d = (double *) malloc(sizeof(double) * 4);
105   if (count_d == NULL)
106   {
107     fprintf(stderr, "insane_hand_new: malloc(count_d) failed\n");
108     free(count);
109     (p[0])->delete(p[0]);
110     free(p);
111     return NULL;
112   }
113 
114   /* list of count
115    * [0] for deal_damage
116    * [1] "damaged" timer
117    * [2] life mode
118    * [3] life timer
119    * [4 -- 5] hand theta
120    * [6] shoot randomness
121    * [7] "was green when killed" flag
122    */
123   /* list of count_d
124    * [0] speed x
125    * [1] speed y
126    * [2 -- 3] shoot randomness
127    */
128 
129   count[0] = 0;
130   count[1] = 0;
131   count[2] = 0;
132   count[3] = 0;
133   count[4] = 75;
134   count[5] = 165;
135   count[6] = 0;
136 
137   count_d[0] = 0.0;
138   count_d[1] = (179.0 - y) / 90.0;
139   count_d[2] = 0.0;
140   count_d[3] = 0.0;
141 
142   new = tenm_object_new("Insane Hand", 0, 0,
143                         1000, x, y,
144                         8, count, 4, count_d, 1, p,
145                         (int (*)(tenm_object *, double))
146                         (&insane_hand_move),
147                         (int (*)(tenm_object *, tenm_object *))
148                         (&insane_hand_hit),
149                         (int (*)(tenm_object *, const tenm_object *))
150                         (&insane_hand_act),
151                         (int (*)(tenm_object *, int))
152                         (&insane_hand_draw));
153   if (new == NULL)
154   {
155     fprintf(stderr, "insane_hand_new: tenm_object_new failed\n");
156     if (count_d != NULL)
157       free(count_d);
158     if (count != NULL)
159       free(count);
160     (p[0])->delete(p[0]);
161     free(p);
162     return NULL;
163   }
164 
165   return new;
166 }
167 
168 static int
insane_hand_move(tenm_object * my,double turn_per_frame)169 insane_hand_move(tenm_object *my, double turn_per_frame)
170 {
171   double dx_temp;
172   double dy_temp;
173 
174   /* sanity check */
175   if (my == NULL)
176   {
177     fprintf(stderr, "insane_hand_move: my is NULL\n");
178     return 0;
179   }
180   if (turn_per_frame <= 0.5)
181   {
182     fprintf(stderr, "insane_hand_move: strange turn_per_frame (%f)\n",
183             turn_per_frame);
184     return 0;
185   }
186 
187   dx_temp = my->count_d[0] / turn_per_frame;
188   dy_temp = my->count_d[1] / turn_per_frame;
189   my->x += dx_temp;
190   my->y += dy_temp;
191   if (my->mass != NULL)
192     tenm_move_mass(my->mass, dx_temp, dy_temp);
193 
194   return 0;
195 }
196 
197 static int
insane_hand_hit(tenm_object * my,tenm_object * your)198 insane_hand_hit(tenm_object *my, tenm_object *your)
199 {
200   /* sanity check */
201   if (my == NULL)
202   {
203     fprintf(stderr, "insane_hand_hit: my is NULL\n");
204     return 0;
205   }
206   if (your == NULL)
207   {
208     fprintf(stderr, "insane_hand_hit: your is NULL\n");
209     return 0;
210   }
211 
212   if (!(your->attr & ATTR_PLAYER_SHOT))
213     return 0;
214   if ((my->count[2] != 1) && (my->count[2] != 3))
215     return 0;
216 
217   deal_damage(my, your, 0);
218   if (insane_hand_green(my))
219     add_chain(my, your);
220   my->count[1] = 2;
221 
222   if (my->hit_point <= 0)
223   {
224     if (my->count[2] == 1)
225       add_score(6250);
226     else if (my->count[2] == 3)
227       add_score(18750);
228     set_background(1);
229     insane_hand_next(my);
230     return 0;
231   }
232 
233   return 0;
234 }
235 
236 static void
insane_hand_next(tenm_object * my)237 insane_hand_next(tenm_object *my)
238 {
239   int n;
240 
241   /* sanity check */
242   if (my == NULL)
243   {
244     fprintf(stderr, "insane_hand_next: my is NULL\n");
245     return;
246   }
247 
248   if ((my->count[2] != 1) && (my->count[2] != 3))
249     return;
250 
251   tenm_table_apply_all((int (*)(tenm_object *, int)) (&delete_enemy_shot), 0);
252   tenm_table_apply_all((int (*)(tenm_object *, int)) (&delete_enemy), 0);
253 
254   /* set "was green" flag before we change the life mode */
255   if (insane_hand_green(my))
256   {
257     n = 8;
258     my->count[7] = 1;
259   }
260   else
261   {
262     n = 7;
263     my->count[7] = 0;
264   }
265 
266   if (my->count[2] == 1)
267   {
268     tenm_table_add(fragment_new(my->x, my->y, 0.0, 0.0,
269                                 50.0, 5, n, 2.0, 0.0, 16));
270     tenm_table_add(fragment_new(my->x, my->y - 80.0, 0.0, 0.0,
271                                 50.0, 5, n, 2.0, 0.0, 16));
272     tenm_table_add(fragment_new(my->x, my->y - 160.0, 0.0, 0.0,
273                                 50.0, 5, n, 2.0, 0.0, 16));
274 
275     my->hit_point = 500;
276     my->count[2] = 2;
277     my->count[3] = 0;
278     my->count[1] = 0;
279     my->count_d[0] = 0.0;
280     my->count_d[1] = 0.0;
281     return;
282   }
283   else if (my->count[2] == 3)
284   {
285     tenm_table_add(explosion_new(my->x, my->y, 0.0, 0.0,
286                                  1, 5000, n, 10.0, 6));
287     tenm_table_add(fragment_new(my->x + 50.0, my->y + 25.0, 0.0, 0.0,
288                                 30.0, 5, n, 5.0, 15.0, 16));
289     tenm_table_add(fragment_new(my->x - 50.0, my->y + 25.0, 0.0, 0.0,
290                                 30.0, 5, n, 5.0, 15.0, 16));
291 
292     my->count[2] = 4;
293     my->count[3] = 0;
294     my->count[1] = 0;
295     my->count_d[0] = 0.0;
296     my->count_d[1] = 0.5;
297 
298     /* don't modify my->attr or my->hit_mask here, or the player shot
299      * may fly through the enemy */
300     tenm_mass_delete(my->mass);
301     my->mass = NULL;
302 
303     return;
304   }
305 }
306 
307 static int
insane_hand_act(tenm_object * my,const tenm_object * player)308 insane_hand_act(tenm_object *my, const tenm_object *player)
309 {
310   int t;
311   int theta;
312   double x;
313   double y;
314   int i;
315   double speed;
316   double length;
317   double dx;
318   double dy;
319 
320   /* sanity check */
321   if (my == NULL)
322   {
323     fprintf(stderr, "insane_hand_act: my is NULL\n");
324     return 0;
325   }
326   if (player == NULL)
327     return 0;
328 
329   /* for deal_damage */
330   my->count[0] = 0;
331 
332   /* "damaged" count down */
333   if (my->count[1] > 0)
334     (my->count[1])--;
335 
336   (my->count[3])++;
337 
338   /* encounter */
339   if (my->count[2] == 0)
340   {
341     if (my->count[3] == 90)
342     {
343       my->count_d[0] = 0.0;
344       my->count_d[1] = 0.0;
345     }
346 
347     if (((my->count[3] >= 90) && (my->count[3] < 105))
348         || ((my->count[3] >= 120) && (my->count[3] < 135)))
349     {
350       my->count[4] -= 5;
351       my->count[5] -= 5;
352     }
353     if (((my->count[3] >= 105) && (my->count[3] < 120))
354         || ((my->count[3] >= 135) && (my->count[3] < 150)))
355     {
356       my->count[4] += 5;
357       my->count[5] += 5;
358     }
359 
360     if (my->count[3] >= 240)
361     {
362       my->count[2] = 1;
363       my->count[3] = 0;
364       my->attr = ATTR_BOSS;
365       my->hit_mask = ATTR_PLAYER_SHOT;
366       return 0;
367     }
368 
369     return 0;
370   }
371   if (my->count[2] == 2)
372   {
373     /* reset hand */
374     if (my->count[3] >= 30)
375     {
376       if ((my->count[4] + 5 >= 75) && (my->count[4] - 5 <= 75))
377         my->count[4] = 75;
378       else if (my->count[4] > 75)
379         my->count[4] -= 5;
380       else
381         my->count[4] += 5;
382       if ((my->count[5] + 5 >= 165) && (my->count[5] - 5 <= 165))
383         my->count[5] = 165;
384       else if (my->count[5] > 165)
385         my->count[5] -= 5;
386       else
387         my->count[5] += 5;
388     }
389 
390     if (my->count[3] == 30)
391     {
392       my->count_d[0] = (((double) (WINDOW_WIDTH / 2)) - my->x) / 90.0;
393       my->count_d[1] = (179.0 - my->y) / 90.0;
394       my->count[7] = 0;
395     }
396     if (my->count[3] == 120)
397     {
398       my->count_d[0] = 0.0;
399       my->count_d[1] = 0.0;
400       my->count[2] = 3;
401       my->count[3] = 0;
402       my->count[7] = 0;
403     }
404     return 0;
405   }
406 
407   /* dead */
408   if (my->count[2] == 4)
409   {
410     if (insane_hand_green(my))
411       i = 8;
412     else
413       i = 7;
414 
415     if ((my->count[3] >= 30) && (my->count[3] <= 75)
416         && (my->count[3] % 15 == 0))
417     {
418       theta = rand() % 360;
419       tenm_table_add(explosion_new(my->x + 30.0 * tenm_cos(theta),
420                                    my->y + 30.0 * tenm_sin(theta),
421                                    0.0, 0.0,
422                                    2, 300, i, 5.0, 8));
423     }
424 
425     if (my->count[3] > 120)
426     {
427       tenm_table_add(explosion_new(my->x, my->y,
428                                    0.0, 0.0,
429                                    1, 3000, i, 10.0, 8));
430       tenm_table_add(fragment_new(my->x, my->y, 0.0, 0.0,
431                                   30.0, 100, i, 4.0, 0.0, 16));
432       tenm_table_add(fragment_new(my->x, my->y, 0.0, 0.0,
433                                   50.0, 30, i, 2.5, 0.0, 12));
434 
435       tenm_table_add(stage_clear_new(100));
436       return 1;
437     }
438 
439     return 0;
440   }
441 
442   /* self-destruction */
443   if ((my->count[2] == 1) && (my->count[3] >= 4070))
444   {
445     set_background(2);
446     clear_chain();
447     insane_hand_next(my);
448     return 0;
449   }
450   if ((my->count[2] == 3) && (my->count[3] >= 3030))
451   {
452     set_background(2);
453     clear_chain();
454     insane_hand_next(my);
455     return 0;
456   }
457 
458   /* move hand */
459   if (my->count[2] == 1)
460   {
461     if ((my->count[3] >= 800) && (my->count[3] < 815))
462     {
463       my->count[4] -= 5;
464       my->count[5] -= 5;
465     }
466     if ((my->count[3] >= 890) && (my->count[3] < 905))
467     {
468       my->count[4] += 5;
469       my->count[5] += 5;
470     }
471     if ((my->count[3] >= 1380) && (my->count[3] < 1395))
472     {
473       my->count[4] -= 5;
474       my->count[5] -= 5;
475     }
476     if ((my->count[3] >= 1395) && (my->count[3] < 1410))
477     {
478       my->count[4] += 5;
479       my->count[5] += 5;
480     }
481     if ((my->count[3] >= 1880) && (my->count[3] < 1895))
482     {
483       my->count[4] -= 5;
484       my->count[5] -= 5;
485     }
486     if ((my->count[3] >= 1970) && (my->count[3] < 1985))
487     {
488       my->count[4] += 5;
489       my->count[5] += 5;
490     }
491     if ((my->count[3] >= 2460) && (my->count[3] < 2475))
492     {
493       my->count[4] -= 5;
494       my->count[5] -= 5;
495     }
496     if ((my->count[3] >= 2475) && (my->count[3] < 2490))
497     {
498       my->count[4] += 5;
499       my->count[5] += 5;
500     }
501     if ((my->count[3] >= 2675) && (my->count[3] < 2690))
502     {
503       my->count[4] -= 5;
504       my->count[5] -= 5;
505     }
506     if ((my->count[3] >= 2765) && (my->count[3] < 2780))
507     {
508       my->count[4] += 5;
509       my->count[5] += 5;
510     }
511     if ((my->count[3] >= 3975) && (my->count[3] < 3990))
512     {
513       my->count[4] -= 5;
514       my->count[5] -= 5;
515     }
516     if ((my->count[3] >= 3990) && (my->count[3] < 4005))
517     {
518       my->count[4] += 5;
519       my->count[5] += 5;
520     }
521   }
522   else if (my->count[2] == 3)
523   {
524     if (my->count[3] % 60 < 30)
525     {
526       my->count[4] -= 5;
527       my->count[5] -= 10;
528     }
529     else
530     {
531       my->count[4] += 5;
532       my->count[5] += 10;
533     }
534   }
535 
536   /* speed change */
537   if (my->count[2] == 1)
538   {
539     if (my->count[3] == 450)
540     {
541       my->count_d[0] = -6.0;
542       my->count_d[1] = 0.0;
543     }
544     if (my->count[3] == 495)
545     {
546       my->count_d[0] = 0.0;
547       my->count_d[1] = 0.0;
548     }
549     if (my->count[3] == 505)
550     {
551       my->count_d[0] = 6.0;
552       my->count_d[1] = 0.0;
553     }
554     if (my->count[3] == 595)
555     {
556       my->count_d[0] = 0.0;
557       my->count_d[1] = 0.0;
558     }
559     if (my->count[3] == 600)
560     {
561       my->count_d[0] = -6.0;
562       my->count_d[1] = 0.0;
563     }
564     if (my->count[3] == 690)
565     {
566       my->count_d[0] = 0.0;
567       my->count_d[1] = 0.0;
568     }
569     if (my->count[3] == 820)
570     {
571       my->count_d[0] = 0.0;
572       my->count_d[1] = 6.0;
573     }
574     if (my->count[3] == 890)
575     {
576       my->count_d[0] = 0.0;
577       my->count_d[1] = -6.0;
578     }
579     if (my->count[3] == 960)
580     {
581       my->count_d[0] = 0.0;
582       my->count_d[1] = 0.0;
583     }
584     if (my->count[3] == 1060)
585     {
586       my->count_d[0] = 6.0;
587       my->count_d[1] = 0.0;
588     }
589     if (my->count[3] == 1105)
590     {
591       my->count_d[0] = 0.0;
592       my->count_d[1] = 0.0;
593     }
594     if (my->count[3] == 1530)
595     {
596       my->count_d[0] = 6.0;
597       my->count_d[1] = 0.0;
598     }
599     if (my->count[3] == 1575)
600     {
601       my->count_d[0] = 0.0;
602       my->count_d[1] = 0.0;
603     }
604     if (my->count[3] == 1585)
605     {
606       my->count_d[0] = -6.0;
607       my->count_d[1] = 0.0;
608     }
609     if (my->count[3] == 1675)
610     {
611       my->count_d[0] = 0.0;
612       my->count_d[1] = 0.0;
613     }
614     if (my->count[3] == 1680)
615     {
616       my->count_d[0] = 6.0;
617       my->count_d[1] = 0.0;
618     }
619     if (my->count[3] == 1770)
620     {
621       my->count_d[0] = 0.0;
622       my->count_d[1] = 0.0;
623     }
624     if (my->count[3] == 1900)
625     {
626       my->count_d[0] = 0.0;
627       my->count_d[1] = 6.0;
628     }
629     if (my->count[3] == 1970)
630     {
631       my->count_d[0] = 0.0;
632       my->count_d[1] = -6.0;
633     }
634     if (my->count[3] == 2040)
635     {
636       my->count_d[0] = 0.0;
637       my->count_d[1] = 0.0;
638     }
639     if (my->count[3] == 2140)
640     {
641       my->count_d[0] = -6.0;
642       my->count_d[1] = 0.0;
643     }
644     if (my->count[3] == 2185)
645     {
646       my->count_d[0] = 0.0;
647       my->count_d[1] = 0.0;
648     }
649     if (my->count[3] == 2630)
650     {
651       my->count_d[0] = -6.0;
652       my->count_d[1] = 0.0;
653     }
654     if (my->count[3] == 2675)
655     {
656       my->count_d[0] = 0.0;
657       my->count_d[1] = 0.0;
658     }
659     if (my->count[3] == 2695)
660     {
661       my->count_d[0] = 0.0;
662       my->count_d[1] = 6.0;
663     }
664     if (my->count[3] == 2765)
665     {
666       my->count_d[0] = 0.0;
667       my->count_d[1] = -6.0;
668     }
669     if (my->count[3] == 2835)
670     {
671       my->count_d[0] = 0.0;
672       my->count_d[1] = 0.0;
673     }
674     if (my->count[3] == 3925)
675     {
676       my->count_d[0] = 6.0;
677       my->count_d[1] = 0.0;
678     }
679     if (my->count[3] == 3970)
680     {
681       my->count_d[0] = 0.0;
682       my->count_d[1] = 0.0;
683     }
684   }
685   else if (my->count[2] == 3)
686   {
687     if (my->count[3] < 480)
688     {
689       my->count_d[0] = 0.0;
690       my->count_d[1] = 0.0;
691     }
692     else
693     {
694       t = my->count[3] - 480;
695       my->count_d[0] = ((double) (WINDOW_WIDTH / 2))
696         + 200.0 * tenm_sin(t * 2) - my->x;
697       my->count_d[1] = 179.0 + 100.0 * tenm_sin(t * 3) - my->y;
698     }
699   }
700 
701   /* add normal enemy */
702   if (my->count[2] == 1)
703   {
704     if (my->count[3] == 890)
705     {
706       tenm_table_add(normal_enemy_new(my->x,
707                                       my->y + 25.0 + 50.0 * tenm_sin(60),
708                                       BALL_CAPTAIN, 0,
709                                       70, -1, 0, -1, 0, 5, 2,
710                                       /* move 0 */
711                                       70, 0.0, -6.0, 0.0, 0.0,
712                                       0.0, 0.0, 0.0, 0.0, 1,
713                                       /* move 1 */
714                                       100, 0.0, 0.0, 0.0, 0.0,
715                                       0.0, 0.0, 0.0, 0.0, 2,
716                                       /* move 2 */
717                                       45, 6.0, 0.0, 0.0, 0.0,
718                                       0.0, 0.0, 0.0, 0.0, 3,
719                                       /* move 3 */
720                                       275, 0.0, 0.0, 0.0, 0.0,
721                                       0.0, 0.0, 0.0, 0.0, 4,
722                                       /* move 4 */
723                                       9999, 0.0, 0.0, 0.0, 0.1,
724                                       0.0, 0.0, 0.0, 0.0, 4,
725                                       /* shoot 0 */
726                                       70, 10, 0, 0, 0, 1,
727                                       /* shoot 1 */
728                                       9999, 10, 0, 0, 1, 1));
729     }
730     if (my->count[3] == 1970)
731     {
732       tenm_table_add(normal_enemy_new(my->x,
733                                       my->y + 25.0 + 50.0 * tenm_sin(60),
734                                       BALL_CAPTAIN, 0,
735                                       70, -1, 0, -1, 0, 5, 2,
736                                       /* move 0 */
737                                       70, 0.0, -6.0, 0.0, 0.0,
738                                       0.0, 0.0, 0.0, 0.0, 1,
739                                       /* move 1 */
740                                       100, 0.0, 0.0, 0.0, 0.0,
741                                       0.0, 0.0, 0.0, 0.0, 2,
742                                       /* move 2 */
743                                       45, -6.0, 0.0, 0.0, 0.0,
744                                       0.0, 0.0, 0.0, 0.0, 3,
745                                       /* move 3 */
746                                       275, 0.0, 0.0, 0.0, 0.0,
747                                       0.0, 0.0, 0.0, 0.0, 4,
748                                       /* move 4 */
749                                       9999, 0.0, 0.0, 0.0, 0.1,
750                                       0.0, 0.0, 0.0, 0.0, 4,
751                                       /* shoot 0 */
752                                       70, 10, 0, 0, 0, 1,
753                                       /* shoot 1 */
754                                       9999, 10, 0, 0, 1, 1));
755     }
756     if (my->count[3] == 2765)
757       tenm_table_add(insane_hand_ship_new(my->x + 25.0,
758                                           my->y + 31.0 + 50.0 * tenm_sin(60)));
759   }
760 
761   /* shoot */
762   if (my->count[2] == 1)
763   {
764     if ((my->count[3] == 30) || (my->count[3] == 1110)
765         || (my->count[3] == 2190))
766     {
767       my->count[6] = rand() % 4;
768       my->count_d[2] = (double) (-5 + (rand() % 11));
769       my->count_d[3] = (double) (-5 + (rand() % 11));
770     }
771 
772     if ((((my->count[3] >= 30) && (my->count[3] <= 156))
773          || ((my->count[3] >= 216) && (my->count[3] <= 342))
774          || ((my->count[3] >= 1110) && (my->count[3] <= 1236))
775          || ((my->count[3] >= 1296) && (my->count[3] <= 1422))
776          || ((my->count[3] >= 2190) && (my->count[3] <= 2316))
777          || ((my->count[3] >= 2376) && (my->count[3] <= 2502)))
778         && (my->count[3] % 6 == 0))
779     {
780       if (my->count[3] <= 156)
781         t = my->count[3] - 30;
782       else if (my->count[3] <= 342)
783         t = my->count[3] - 216;
784       else if (my->count[3] <= 1236)
785         t = my->count[3] - 1110;
786       else if (my->count[3] <= 1422)
787         t = my->count[3] - 1296;
788       else if (my->count[3] <= 2316)
789         t = my->count[3] - 2190;
790       else
791         t = my->count[3] - 2376;
792 
793       theta = (t / 6) * (-17);
794       if (my->count[6] % 2 != 0)
795         theta = 180 - theta;
796       x = my->x;
797       y = my->y;
798       if (my->count[6] < 2)
799         x += 35.0;
800       else
801         x -= 35.0;
802       x += my->count_d[2];
803       y += my->count_d[3];
804       tenm_table_add(normal_shot_angle_new(x, y,
805                                            1.5 + 0.2 * ((double) (t / 5)),
806                                            theta, 4));
807       if (my->count[6] % 2 != 0)
808         theta += 178;
809       else
810         theta -= 178;
811       tenm_table_add(normal_shot_angle_new(x, y, 2.5, theta, 2));
812     }
813     if ((((my->count[3] >= 60) && (my->count[3] <= 186))
814          || ((my->count[3] >= 246) && (my->count[3] <= 372))
815          || ((my->count[3] >= 1140) && (my->count[3] <= 1266))
816          || ((my->count[3] >= 1326) && (my->count[3] <= 1452))
817          || ((my->count[3] >= 2220) && (my->count[3] <= 2346))
818          || ((my->count[3] >= 2406) && (my->count[3] <= 2532)))
819         && (my->count[3] % 6 == 0))
820     {
821       if (my->count[3] <= 186)
822         t = my->count[3] - 60;
823       else if (my->count[3] <= 372)
824         t = my->count[3] - 246;
825       else if (my->count[3] <= 1266)
826         t = my->count[3] - 1140;
827       else if (my->count[3] <= 1452)
828         t = my->count[3] - 1326;
829       else if (my->count[3] <= 2346)
830         t = my->count[3] - 2220;
831       else
832         t = my->count[3] - 2406;
833 
834       theta = (t / 6) * (-17);
835       if (my->count[6] % 2 == 0)
836         theta = 180 - theta;
837       x = my->x;
838       y = my->y;
839       if (my->count[6] < 2)
840         x -= 35.0;
841       else
842         x += 35.0;
843       x += my->count_d[2];
844       y += my->count_d[3];
845       tenm_table_add(normal_shot_angle_new(x, y,
846                                            1.5 + 0.2 * ((double) (t / 5)),
847                                            theta, 4));
848       if (my->count[6] % 2 == 0)
849         theta += 178;
850       else
851         theta -= 178;
852       tenm_table_add(normal_shot_angle_new(x, y, 2.5, theta, 2));
853     }
854 
855     if ((my->count[3] == 186) || (my->count[3] == 1266))
856     {
857       my->count[6] = (my->count[6] + 2) % 4;
858       my->count_d[2] = (double) (-5 + (rand() % 11));
859       my->count_d[3] = (double) (-5 + (rand() % 11));
860     }
861 
862     if (((my->count[3] >= 505) && (my->count[3] <= 595))
863         || ((my->count[3] >= 1585) && (my->count[3] <= 1675)))
864     {
865       if (my->count[3] <= 595)
866         t = my->count[3] - 505;
867       else
868         t = my->count[3] - 1585;
869       if (t % 30 == 0)
870         tenm_table_add(normal_shot_point_new(my->x, my->y, 4.0,
871                                              player->x, player->y, 2));
872       if ((t % 32 == 0) || (t % 32 == 12))
873       {
874         tenm_table_add(laser_angle_new(my->x - 48.0, my->y, 3.0,
875                                        70, 25.0, 3));
876         tenm_table_add(laser_angle_new(my->x + 48.0, my->y, 3.0,
877                                        70, 25.0, 3));
878         tenm_table_add(laser_angle_new(my->x - 48.0, my->y, 3.0,
879                                        -70, 25.0, 3));
880         tenm_table_add(laser_angle_new(my->x + 48.0, my->y, 3.0,
881                                        -70, 25.0, 3));
882         tenm_table_add(laser_angle_new(my->x - 48.0, my->y, 3.0,
883                                        110, 25.0, 3));
884         tenm_table_add(laser_angle_new(my->x + 48.0, my->y, 3.0,
885                                        110, 25.0, 3));
886         tenm_table_add(laser_angle_new(my->x - 48.0, my->y, 3.0,
887                                        -110, 25.0, 3));
888         tenm_table_add(laser_angle_new(my->x + 48.0, my->y, 3.0,
889                                        -110, 25.0, 3));
890       }
891       if ((t % 32 == 4) || (t % 32 == 24))
892       {
893         tenm_table_add(laser_angle_new(my->x - 48.0, my->y, 1.5,
894                                        70, 25.0, 3));
895         tenm_table_add(laser_angle_new(my->x + 48.0, my->y, 1.5,
896                                        70, 25.0, 3));
897         tenm_table_add(laser_angle_new(my->x - 48.0, my->y, 1.5,
898                                        -70, 25.0, 3));
899         tenm_table_add(laser_angle_new(my->x + 48.0, my->y, 1.5,
900                                        -70, 25.0, 3));
901         tenm_table_add(laser_angle_new(my->x - 48.0, my->y, 1.5,
902                                        110, 25.0, 3));
903         tenm_table_add(laser_angle_new(my->x + 48.0, my->y, 1.5,
904                                        110, 25.0, 3));
905         tenm_table_add(laser_angle_new(my->x - 48.0, my->y, 1.5,
906                                        -110, 25.0, 3));
907         tenm_table_add(laser_angle_new(my->x + 48.0, my->y, 1.5,
908                                        -110, 25.0, 3));
909       }
910     }
911 
912     if ((my->count[3] >= 600) && (my->count[3] <= 690)
913         && (my->count[3] % 15 == 0))
914     {
915       for (i = -2; i <= 2; i++)
916         tenm_table_add(normal_shot_new(my->x,
917                                        my->y - 80.0 + 40.0 * ((double) i),
918                                        1.5, 3.6 - 0.8 * ((double) i),
919                                        5, -2, 0));
920     }
921     if ((my->count[3] >= 1680) && (my->count[3] <= 1770)
922         && (my->count[3] % 15 == 0))
923     {
924       for (i = -2; i <= 2; i++)
925         tenm_table_add(normal_shot_new(my->x,
926                                        my->y - 80.0 + 40.0 * ((double) i),
927                                        -1.5, 3.6 - 0.8 * ((double) i),
928                                        5, -2, 0));
929     }
930 
931     if ((my->count[3] == 820) || (my->count[3] == 1900)
932         || (my->count[3] == 2695))
933     {
934       my->count_d[2] = (double) (-5 + (rand() % 11));
935       my->count_d[3] = (double) (-5 + (rand() % 11));
936     }
937     if (((my->count[3] >= 820) && (my->count[3] < 880))
938         || ((my->count[3] >= 2695) && (my->count[3] < 2755)))
939     {
940       if (my->count[3] < 880)
941         t = my->count[3] - 820;
942       else
943         t = my->count[3] - 2695;
944       tenm_table_add(laser_angle_new(my->x - 36.0 + my->count_d[2],
945                                      my->y + my->count_d[3], 2.0,
946                                      178 + 15 * (t % 10), 25.0, 2));
947       tenm_table_add(laser_angle_new(my->x + 36.0 + my->count_d[2],
948                                      my->y + my->count_d[3], 2.0,
949                                      88 - 15 * (t % 10), 25.0, 2));
950     }
951     if (((my->count[3] >= 820) && (my->count[3] < 876))
952         || ((my->count[3] >= 2695) && (my->count[3] < 2751)))
953     {
954       if (my->count[3] < 876)
955         t = my->count[3] - 820;
956       else
957         t = my->count[3] - 2695;
958       if (t % 2 == 0)
959         speed = 3.5;
960       else
961         speed = 4.5;
962       tenm_table_add(laser_angle_new(my->x - 36.0 + my->count_d[2],
963                                      my->y + my->count_d[3],
964                                      speed,
965                                      178 + 5 * (t % 28), 25.0, 2));
966       tenm_table_add(laser_angle_new(my->x + 36.0 + my->count_d[2],
967                                      my->y + my->count_d[3],
968                                      speed,
969                                      88 - 5 * (t % 28), 25.0, 2));
970     }
971     if ((my->count[3] >= 1900) && (my->count[3] < 1960))
972     {
973       t = my->count[3] - 1900;
974       tenm_table_add(laser_angle_new(my->x + 36.0 + my->count_d[2],
975                                      my->y + my->count_d[3], 2.0,
976                                      2 - 15 * (t % 10), 25.0, 2));
977       tenm_table_add(laser_angle_new(my->x - 36.0 + my->count_d[2],
978                                      my->y + my->count_d[3], 2.0,
979                                      92 + 15 * (t % 10), 25.0, 2));
980     }
981     if ((my->count[3] >= 1900) && (my->count[3] < 1956))
982     {
983       t = my->count[3] - 1900;
984       if (t % 2 == 0)
985         speed = 3.5;
986       else
987         speed = 4.5;
988       tenm_table_add(laser_angle_new(my->x + 36.0 + my->count_d[2],
989                                      my->y + my->count_d[3],
990                                      speed,
991                                      2 - 5 * (t % 28), 25.0, 2));
992       tenm_table_add(laser_angle_new(my->x - 36.0 + my->count_d[2],
993                                      my->y + my->count_d[3],
994                                      speed,
995                                      92 + 5 * (t % 28), 25.0, 2));
996     }
997 
998     if ((my->count[3] >= 2835) && (my->count[3] <= 3825)
999         && (my->count[3] % 30 == 15))
1000     {
1001       x = player->x - my->x;
1002       y = player->y - (my->y - 80.0);
1003       length = tenm_sqrt((int) (x * x + y * y));
1004       if (length < NEAR_ZERO)
1005         length = 1.0;
1006       for (i = -2; i <= 2; i++)
1007         tenm_table_add(normal_shot_new(my->x,
1008                                        my->y - 80.0 + 40.0 * ((double) i),
1009                                        4.0 * x / length,
1010                                        4.0 * y / length - 0.6 * ((double) i),
1011                                        5, -2, 0));
1012     }
1013   }
1014   else if (my->count[2] == 3)
1015   {
1016     /* hand */
1017     if (my->count[3] == 60)
1018     {
1019       my->count[6] = rand() % 2;
1020     }
1021     else if (my->count[3] % 420 == 60)
1022     {
1023       if (rand() % 3 != 0)
1024         my->count[6] = 1 - my->count[6];
1025     }
1026     if ((my->count[3] < 2940) && (my->count[3] % 420 >= 60))
1027     {
1028       t = (my->count[3] - 60) % 420;
1029 
1030       length = 50.0 / tenm_sqrt(2);
1031       x = 50.0;
1032       y = 25.0;
1033       for (i = 0; i < 2; i++)
1034       {
1035         dx = length * tenm_cos(my->count[4 + i]);
1036         dy = length * tenm_sin(my->count[4 + i]);
1037 
1038         switch (my->count[6])
1039         {
1040         case 0:
1041           if ((t % 5 == 0)
1042               || ((my->count[3] >= 900) && (t % 5 < 3)))
1043           {
1044             if (i == 1)
1045             {
1046               tenm_table_add(laser_angle_new(my->x + x + dx, my->y + y + dy,
1047                                              5.0, t * 11, 25.0, 2));
1048               tenm_table_add(laser_angle_new(my->x - x - dx, my->y + y + dy,
1049                                              5.0, 180 - t * 11, 25.0, 2));
1050             }
1051           }
1052           if (t % 13 == 0)
1053           {
1054             tenm_table_add(normal_shot_point_new(my->x, my->y, 4.0,
1055                                                  player->x, player->y, 4));
1056           }
1057           break;
1058         case 1:
1059           if (t % 19 == 0)
1060           {
1061             if (i == 0)
1062             {
1063               tenm_table_add(laser_point_new(my->x + x + dx, my->y + y + dy,
1064                                              5.5,
1065                                              player->x - 100.0, player->y,
1066                                              25.0, 0));
1067               tenm_table_add(laser_point_new(my->x - x - dx, my->y + y + dy,
1068                                              5.5,
1069                                              player->x + 100.0, player->y,
1070                                              25.0, 0));
1071               if (my->count[3] >= 900)
1072               {
1073                 tenm_table_add(laser_point_new(my->x + x + dx, my->y + y + dy,
1074                                                7.5,
1075                                                player->x + 100.0, player->y,
1076                                                25.0, 0));
1077                 tenm_table_add(laser_point_new(my->x - x - dx, my->y + y + dy,
1078                                                7.5,
1079                                                player->x - 100.0, player->y,
1080                                                25.0, 0));
1081               }
1082             }
1083             else if (i == 1)
1084             {
1085               tenm_table_add(laser_point_new(my->x + x + dx, my->y + y + dy,
1086                                              4.0,
1087                                              player->x, player->y, 25.0, 1));
1088               tenm_table_add(laser_point_new(my->x - x - dx, my->y + y + dy,
1089                                              4.0,
1090                                              player->x, player->y, 25.0, 1));
1091             }
1092           }
1093           break;
1094         default:
1095           fprintf(stderr, "insane_hand_draw: undefined shoot mode (%d)\n",
1096                   my->count[6]);
1097           break;
1098         }
1099         x += dx;
1100         y += dy;
1101       }
1102     }
1103 
1104   }
1105 
1106   return 0;
1107 }
1108 
1109 static int
insane_hand_draw(tenm_object * my,int priority)1110 insane_hand_draw(tenm_object *my, int priority)
1111 {
1112   int status = 0;
1113   tenm_color color;
1114   char temp[32];
1115   int theta_rotate;
1116   double length_hand;
1117   double x;
1118   double y;
1119   double dx;
1120   double dy;
1121   int i;
1122   int width;
1123 
1124   /* sanity check */
1125   if (my == NULL)
1126   {
1127     fprintf(stderr, "insane_hand_draw: my is NULL\n");
1128     return 0;
1129   }
1130 
1131   theta_rotate = 0;
1132   if (my->count[2] == 0)
1133   {
1134     if (my->count[3] >= 240)
1135       theta_rotate = 0;
1136     else if (my->count[3] < 150)
1137       theta_rotate = -180;
1138     else
1139       theta_rotate = -180 + (my->count[3] - 150) * 2;
1140   }
1141 
1142   /* decoration */
1143   if ((priority == 0) && (my->count[2] <= 1))
1144   {
1145     if (insane_hand_green(my))
1146     {
1147       if (my->count[1] >= 1)
1148         color = tenm_map_color(181, 190, 92);
1149       else
1150         color = tenm_map_color(157, 182, 123);
1151     }
1152     else
1153     {
1154       if (my->count[1] >= 1)
1155         color = tenm_map_color(200, 164, 92);
1156       else
1157         color = tenm_map_color(182, 147, 123);
1158     }
1159 
1160     /* shaft */
1161     if (insane_hand_body_line(my->x + 20.0, my->y - 25.0,
1162                               my->x + 20.0, my->y - 625.0,
1163                               1, color, theta_rotate) != 0)
1164       status = 1;
1165     if (insane_hand_body_line(my->x - 20.0, my->y - 25.0,
1166                               my->x - 20.0, my->y - 625.0,
1167                               1, color, theta_rotate) != 0)
1168       status = 1;
1169   }
1170 
1171   /* body */
1172   /* dead enemy has low priority */
1173   if (((my->count[2] <= 3) && (priority == 0))
1174       || ((my->count[2] > 3) && (priority == -1)))
1175   {
1176     if (insane_hand_green(my))
1177     {
1178       if (my->count[1] >= 1)
1179         color = tenm_map_color(109, 125, 9);
1180       else
1181         color = tenm_map_color(61, 95, 13);
1182     }
1183     else
1184     {
1185       if (my->count[1] >= 1)
1186         color = tenm_map_color(135, 89, 9);
1187       else
1188         color = tenm_map_color(95, 47, 13);
1189     }
1190 
1191     /* hand */
1192     if (my->count[2] <= 3)
1193     {
1194       length_hand = 50.0 / tenm_sqrt(2);
1195       x = 50.0;
1196       y = 25.0;
1197       for (i = 0; i < 2; i++)
1198       {
1199         dx = length_hand * tenm_cos(my->count[4 + i]);
1200         dy = length_hand * tenm_sin(my->count[4 + i]);
1201         if (insane_hand_body_line(my->x + x, my->y + y,
1202                                   my->x + x + dx, my->y + y + dy,
1203                                   1, color, theta_rotate) != 0)
1204           status = 1;
1205         if (insane_hand_body_line(my->x - x, my->y + y,
1206                                   my->x - x - dx, my->y + y + dy,
1207                                   1, color, theta_rotate) != 0)
1208           status = 1;
1209         x += dx;
1210         y += dy;
1211       }
1212     }
1213 
1214     /* core */
1215     if (my->count[2] == 0)
1216       width = 1;
1217     else
1218       width = 3;
1219     if (insane_hand_body_line(my->x + 50.0, my->y - 25.0,
1220                               my->x + 50.0, my->y + 25.0,
1221                               width, color, theta_rotate) != 0)
1222       status = 1;
1223     if (insane_hand_body_line(my->x + 50.0, my->y + 25.0,
1224                               my->x - 50.0, my->y + 25.0,
1225                               width, color, theta_rotate) != 0)
1226       status = 1;
1227     if (insane_hand_body_line(my->x - 50.0, my->y + 25.0,
1228                               my->x - 50.0, my->y - 25.0,
1229                               width, color, theta_rotate) != 0)
1230       status = 1;
1231     if (insane_hand_body_line(my->x - 50.0, my->y - 25.0,
1232                               my->x + 50.0, my->y - 25.0,
1233                               width, color, theta_rotate) != 0)
1234       status = 1;
1235   }
1236 
1237   /* hit point stat */
1238   if ((priority == 0)
1239       && ((my->count[2] == 1) || (my->count[2] == 3)))
1240   {
1241     sprintf(temp, "%d", my->hit_point);
1242     if (draw_string(((int) my->x) - 10, (int) my->y,
1243                     temp, (int) strlen(temp)) != 0)
1244     {
1245       fprintf(stderr, "insane_hand_draw: draw_string failed\n");
1246       status = 1;
1247     }
1248   }
1249 
1250   return status;
1251 }
1252 
insane_hand_body_line(double a_x,double a_y,double b_x,double b_y,int width,tenm_color color,int theta)1253 static int insane_hand_body_line(double a_x, double a_y,
1254                                  double b_x, double b_y,
1255                                  int width, tenm_color color, int theta)
1256 {
1257   double a_result[2];
1258   double a_v[2];
1259   double b_result[2];
1260   double b_v[2];
1261 
1262   a_v[0] = a_x;
1263   a_v[1] = a_y;
1264   a_result[0] = a_v[0];
1265   a_result[1] = a_v[1];
1266   insane_hand_body_rotate(a_result, a_v, theta);
1267 
1268   b_v[0] = b_x;
1269   b_v[1] = b_y;
1270   b_result[0] = b_v[0];
1271   b_result[1] = b_v[1];
1272   insane_hand_body_rotate(b_result, b_v, theta);
1273 
1274   return tenm_draw_line((int) (a_result[0]), (int) (a_result[1]),
1275                         (int) (b_result[0]), (int) (b_result[1]),
1276                         width, color);
1277 }
1278 
1279 /* rotate the point v (arg 2) which is a part of the boss
1280  * by theta (arg 3) degree
1281  * result (arg 1) and v (arg 2) must be double[2] (you must allocate enough
1282  * memory before calling this function)
1283  * the result is undefined if result (arg 1) and v (arg 2) overlap
1284  */
insane_hand_body_rotate(double * result,const double * v,int theta)1285 static void insane_hand_body_rotate(double *result, const double *v,
1286                                     int theta)
1287 {
1288   double temp_result[2];
1289   double temp_v[2];
1290   double center_x = (double) (WINDOW_WIDTH / 2);
1291   double center_y = (double) (WINDOW_HEIGHT / 2);
1292 
1293 
1294   /* sanity check */
1295   if (result == NULL)
1296   {
1297     fprintf(stderr, "insane_hand_body_rotate: result is NULL\n");
1298     return;
1299   }
1300   if (v == NULL)
1301   {
1302     fprintf(stderr, "insane_hand_body_rotate: v is NULL\n");
1303     return;
1304   }
1305 
1306   temp_v[0] = v[0] - center_x;
1307   temp_v[1] = v[1] - center_y;
1308   temp_result[0] = temp_v[0];
1309   temp_result[1] = temp_v[1];
1310   vector_rotate(temp_result, temp_v, theta);
1311   result[0] = temp_result[0] + center_x;
1312   result[1] = temp_result[1] + center_y;
1313 }
1314 
1315 /* return 1 (true) or 0 (false) */
1316 static int
insane_hand_green(const tenm_object * my)1317 insane_hand_green(const tenm_object *my)
1318 {
1319   /* sanity check */
1320   if (my == NULL)
1321     return 0;
1322 
1323   if ((my->count[2] == 1)
1324       && (my->count[3] >= 800) && (my->count[3] < 4040))
1325     return 1;
1326   if ((my->count[2] == 3)
1327       && (my->count[3] >= 900) && (my->count[3] < 3000))
1328     return 1;
1329 
1330   if (((my->count[2] == 2) || (my->count[2] == 4))
1331       && (my->count[7] != 0))
1332     return 1;
1333 
1334   return 0;
1335 }
1336 
1337 static tenm_object *
insane_hand_ship_new(double x,double y)1338 insane_hand_ship_new(double x, double y)
1339 {
1340   tenm_primitive **p = NULL;
1341   tenm_object *new = NULL;
1342   int *count = NULL;
1343   double *count_d = NULL;
1344   int i;
1345 
1346   p = (tenm_primitive **) malloc(sizeof(tenm_primitive *) * 2);
1347   if (p == NULL)
1348   {
1349     fprintf(stderr, "insane_hand_ship_new: malloc(p) failed\n");
1350     return NULL;
1351   }
1352 
1353   p[0] = (tenm_primitive *) tenm_polygon_new(4,
1354                                              x + 32.0, y + 18.0,
1355                                              x + 23.0, y + 30.0,
1356                                              x - 41.0, y - 18.0,
1357                                              x - 32.0, y - 30.0);
1358   if (p[0] == NULL)
1359   {
1360     fprintf(stderr, "insane_hand_ship_new: cannot set p[0]\n");
1361     free(p);
1362     return NULL;
1363   }
1364   p[1] = (tenm_primitive *) tenm_polygon_new(4,
1365                                              x + 9.0, y - 18.0,
1366                                              x - 18.0, y + 18.0,
1367                                              x - 50.0, y - 6.0,
1368                                              x - 23.0, y - 42.0);
1369   if (p[1] == NULL)
1370   {
1371     fprintf(stderr, "insane_hand_ship_new: cannot set p[0]\n");
1372     (p[0])->delete(p[0]);
1373     free(p);
1374     return NULL;
1375   }
1376 
1377   count = (int *) malloc(sizeof(int) * 5);
1378   if (count == NULL)
1379   {
1380     fprintf(stderr, "insane_hand_ship_new: malloc(count) failed\n");
1381     for (i = 0; i < 2; i++)
1382       (p[i])->delete(p[i]);
1383     free(p);
1384     return NULL;
1385   }
1386   count_d = (double *) malloc(sizeof(double) * 2);
1387   if (count_d == NULL)
1388   {
1389     fprintf(stderr, "insane_hand_ship_new: malloc(count_d) failed\n");
1390     free(count);
1391     for (i = 0; i < 2; i++)
1392       (p[i])->delete(p[i]);
1393     free(p);
1394     return NULL;
1395   }
1396 
1397   /* list of count
1398    * [0] for deal_damage
1399    * [1] "damaged" timer
1400    * [2] life timer
1401    * [3] shoot timer
1402    * [4] bit index
1403    */
1404   /* list of count_d
1405    * [0] speed x
1406    * [1] speed y
1407    */
1408 
1409   count[0] = 0;
1410   count[1] = 0;
1411   count[2] = -70;
1412   count[3] = 0;
1413   count[4] = -1;
1414 
1415   count_d[0] = 0.0;
1416   count_d[1] = -6.0;
1417 
1418   new = tenm_object_new("Insane Hand ship", ATTR_ENEMY, ATTR_PLAYER_SHOT,
1419                         400, x, y,
1420                         5, count, 2, count_d, 2, p,
1421                         (int (*)(tenm_object *, double))
1422                         (&insane_hand_ship_move),
1423                         (int (*)(tenm_object *, tenm_object *))
1424                         (&insane_hand_ship_hit),
1425                         (int (*)(tenm_object *, const tenm_object *))
1426                         (&insane_hand_ship_act),
1427                         (int (*)(tenm_object *, int))
1428                         (&insane_hand_ship_draw));
1429 
1430   if (new == NULL)
1431   {
1432     fprintf(stderr, "insane_hand_ship_new: tenm_object_new failed\n");
1433     if (count_d != NULL)
1434       free(count_d);
1435     if (count != NULL)
1436       free(count);
1437     for (i = 0; i < 2; i++)
1438       (p[i])->delete(p[i]);
1439     free(p);
1440     return NULL;
1441   }
1442 
1443   return new;
1444 }
1445 
1446 static int
insane_hand_ship_move(tenm_object * my,double turn_per_frame)1447 insane_hand_ship_move(tenm_object *my, double turn_per_frame)
1448 {
1449   double dx_temp;
1450   double dy_temp;
1451 
1452   /* sanity check */
1453   if (my == NULL)
1454   {
1455     fprintf(stderr, "insane_hand_ship_move: my is NULL\n");
1456     return 0;
1457   }
1458   if (turn_per_frame <= 0.5)
1459   {
1460     fprintf(stderr, "insane_hand_ship_move: strange turn_per_frame (%f)\n",
1461             turn_per_frame);
1462     return 0;
1463   }
1464 
1465   dx_temp = my->count_d[0] / turn_per_frame;
1466   dy_temp = my->count_d[1] / turn_per_frame;
1467   my->x += dx_temp;
1468   my->y += dy_temp;
1469   if (my->mass != NULL)
1470     tenm_move_mass(my->mass, dx_temp, dy_temp);
1471 
1472   if ((my->count[2] > 0) && (!in_window_object(my)))
1473     return 1;
1474 
1475   return 0;
1476 }
1477 
1478 static int
insane_hand_ship_hit(tenm_object * my,tenm_object * your)1479 insane_hand_ship_hit(tenm_object *my, tenm_object *your)
1480 {
1481   int n;
1482 
1483   /* sanity check */
1484   if (my == NULL)
1485   {
1486     fprintf(stderr, "insane_hand_ship_hit: my is NULL\n");
1487     return 0;
1488   }
1489   if (your == NULL)
1490   {
1491     fprintf(stderr, "insane_hand_ship_hit: your is NULL\n");
1492     return 0;
1493   }
1494 
1495   if (!(your->attr & ATTR_PLAYER_SHOT))
1496     return 0;
1497 
1498   deal_damage(my, your, 0);
1499   if (insane_hand_ship_green(my))
1500     add_chain(my, your);
1501   my->count[1] = 41;
1502 
1503   if (my->hit_point <= 0)
1504   {
1505     add_score(15000);
1506     if (my->count[4] >= 0)
1507       tenm_table_apply(my->count[4],
1508                        (int (*)(tenm_object *, int))
1509                        (&insane_hand_ship_signal_bit),
1510                        0);
1511     if (insane_hand_ship_green(my))
1512       n = 8;
1513     else
1514       n = 7;
1515     tenm_table_add(explosion_new(my->x, my->y, 0.0, 0.0,
1516                                  1, 1000, n, 8.0, 6));
1517     tenm_table_add(explosion_new(my->x, my->y, 0.0, 0.0,
1518                                  2, 300, n, 5.0, 8));
1519     return 1;
1520   }
1521 
1522   return 0;
1523 }
1524 
1525 static int
insane_hand_ship_signal_bit(tenm_object * my,int n)1526 insane_hand_ship_signal_bit(tenm_object *my, int n)
1527 {
1528   /* sanity check */
1529   if (my == NULL)
1530     return 0;
1531   if (strcmp(my->name, "Insane Hand ship bit") != 0)
1532     return 0;
1533 
1534   tenm_table_add(explosion_new(my->x, my->y, 0.0, 0.0,
1535                                1, 1000, 9, 8.0, 6));
1536   tenm_table_add(explosion_new(my->x, my->y, 0.0, 0.0,
1537                                2, 300, 9, 5.0, 8));
1538 
1539   return 1;
1540 }
1541 
1542 static int
insane_hand_ship_act(tenm_object * my,const tenm_object * player)1543 insane_hand_ship_act(tenm_object *my, const tenm_object *player)
1544 {
1545   int i;
1546 
1547   /* sanity check */
1548   if (my == NULL)
1549   {
1550     fprintf(stderr, "insane_hand_ship_act: my is NULL\n");
1551     return 0;
1552   }
1553   if (player == NULL)
1554     return 0;
1555 
1556   /* for deal_damage */
1557   my->count[0] = 0;
1558 
1559   /* "damaged" count down */
1560   if (my->count[1] > 0)
1561     (my->count[1])--;
1562 
1563   (my->count[2])++;
1564   if (my->count[2] == -69)
1565     my->count[4] = tenm_table_add(insane_hand_ship_bit_new(my->x + 52.0,
1566                                                            my->y + 39.0));
1567   if (my->count[2] == 0)
1568   {
1569     my->count_d[0] = 0.0;
1570     my->count_d[1] = 0.0;
1571   }
1572   if (my->count[2] == 1090)
1573   {
1574     my->count_d[0] = 6.0;
1575     my->count_d[1] = 0.0;
1576   }
1577   if (my->count[2] == 1135)
1578   {
1579     my->count_d[0] = 0.0;
1580     my->count_d[1] = 0.0;
1581   }
1582   if (my->count[2] >= 1140)
1583   {
1584     my->count_d[1] += 0.1;
1585   }
1586   if ((my->count[2] <= 90) || (my->count[2] >= 990))
1587     return 0;
1588 
1589   (my->count[3])++;
1590   if (my->count[3] % 100 == 0)
1591   {
1592     for (i = -4; i <= 4; i++)
1593     {
1594       tenm_table_add(insane_hand_ship_shot_new(my->x, my->y,
1595                                                7.0 * tenm_cos(15 * i),
1596                                                7.0 * tenm_sin(15 * i)));
1597     }
1598   }
1599 
1600   return 0;
1601 }
1602 
1603 static int
insane_hand_ship_draw(tenm_object * my,int priority)1604 insane_hand_ship_draw(tenm_object *my, int priority)
1605 {
1606   int status = 0;
1607   tenm_color color;
1608   char temp[32];
1609 
1610   /* sanity check */
1611   if (my == NULL)
1612   {
1613     fprintf(stderr, "insane_hand_ship_draw: my is NULL\n");
1614     return 0;
1615   }
1616 
1617   /* body */
1618   if (priority == 0)
1619   {
1620     if (insane_hand_ship_green(my))
1621     {
1622       if (my->count[1] >= 40)
1623         color = tenm_map_color(109, 125, 9);
1624       else
1625         color = tenm_map_color(61, 95, 13);
1626     }
1627     else
1628     {
1629       if (my->count[1] >= 40)
1630         color = tenm_map_color(135, 89, 9);
1631       else
1632         color = tenm_map_color(95, 47, 13);
1633     }
1634 
1635     if (tenm_draw_line((int) (my->x + 32.0), (int) (my->y + 18.0),
1636                        (int) (my->x + 23.0), (int) (my->y + 30.0),
1637                        3, color) != 0)
1638       status = 1;
1639     if (tenm_draw_line((int) (my->x + 23.0), (int) (my->y + 30.0),
1640                        (int) (my->x - 9.0), (int) (my->y + 6.0),
1641                        3, color) != 0)
1642       status = 1;
1643     if (tenm_draw_line((int) (my->x - 9.0), (int) (my->y + 6.0),
1644                        (int) (my->x - 18.0), (int) (my->y + 18.0),
1645                        3, color) != 0)
1646       status = 1;
1647     if (tenm_draw_line((int) (my->x - 18.0), (int) (my->y + 18.0),
1648                        (int) (my->x - 50.0), (int) (my->y - 6.0),
1649                        3, color) != 0)
1650       status = 1;
1651 
1652     if (tenm_draw_line((int) (my->x - 50.0), (int) (my->y - 6.0),
1653                        (int) (my->x - 23.0), (int) (my->y - 42.0),
1654                        3, color) != 0)
1655       status = 1;
1656     if (tenm_draw_line((int) (my->x - 23.0), (int) (my->y - 42.0),
1657                        (int) (my->x + 9.0), (int) (my->y - 18.0),
1658                        3, color) != 0)
1659       status = 1;
1660     if (tenm_draw_line((int) (my->x + 9.0), (int) (my->y - 18.0),
1661                        (int) (my->x), (int) (my->y - 6.0),
1662                        3, color) != 0)
1663       status = 1;
1664     if (tenm_draw_line((int) (my->x), (int) (my->y - 6.0),
1665                        (int) (my->x + 32.0), (int) (my->y + 18.0),
1666                        3, color) != 0)
1667       status = 1;
1668   }
1669 
1670   /* hit point stat */
1671   if ((priority == 0) && (my->count[1] > 0))
1672   {
1673     sprintf(temp, "%d", my->hit_point);
1674     if (draw_string(((int) my->x) - 33, ((int) (my->y)) - 10,
1675                     temp, (int) strlen(temp)) != 0)
1676     {
1677       fprintf(stderr, "insane_hand_ship_draw: draw_string failed\n");
1678       status = 1;
1679     }
1680   }
1681 
1682   return status;
1683 }
1684 
1685 /* return 1 (true) or 0 (false) */
1686 static int
insane_hand_ship_green(const tenm_object * my)1687 insane_hand_ship_green(const tenm_object *my)
1688 {
1689   /* sanity check */
1690   if (my == NULL)
1691     return 0;
1692 
1693   if ((my->count[2] > 90) && (my->count[2] < 1090))
1694     return 1;
1695 
1696   return 0;
1697 }
1698 
1699 static tenm_object *
insane_hand_ship_bit_new(double x,double y)1700 insane_hand_ship_bit_new(double x, double y)
1701 {
1702   tenm_primitive **p = NULL;
1703   tenm_object *new = NULL;
1704   int *count = NULL;
1705   double *count_d = NULL;
1706 
1707   p = (tenm_primitive **) malloc(sizeof(tenm_primitive *) * 1);
1708   if (p == NULL)
1709   {
1710     fprintf(stderr, "insane_hand_ship_bit_new: malloc(p) failed\n");
1711     return NULL;
1712   }
1713   p[0] = (tenm_primitive *) tenm_circle_new(x, y, 25.0);
1714   if (p[0] == NULL)
1715   {
1716     fprintf(stderr, "insane_hand_ship_bit_new: cannot set p[0]\n");
1717     free(p);
1718     return NULL;
1719   }
1720 
1721   count = (int *) malloc(sizeof(int) * 2);
1722   if (count == NULL)
1723   {
1724     fprintf(stderr, "insane_hand_ship_bit_new: malloc(count) failed\n");
1725     (p[0])->delete(p[0]);
1726     free(p);
1727     return NULL;
1728   }
1729   count_d = (double *) malloc(sizeof(double) * 4);
1730   if (count_d == NULL)
1731   {
1732     fprintf(stderr, "insane_hand_ship_bit_new: malloc(count_d) failed\n");
1733     free(count);
1734     (p[0])->delete(p[0]);
1735     free(p);
1736     return NULL;
1737   }
1738 
1739   /* list of count
1740    * [0] life timer
1741    * [1] shoot timer
1742    */
1743   /* list of count_d
1744    * [0] speed x
1745    * [1] speed y
1746    * [2] origin x
1747    * [3] origin y
1748    */
1749 
1750   count[0] = -69;
1751   count[1] = 0;
1752 
1753   count_d[0] = 0.0;
1754   count_d[1] = -6.0;
1755   count_d[2] = 0.0;
1756   count_d[3] = 0.0;
1757 
1758   new = tenm_object_new("Insane Hand ship bit", ATTR_ENEMY, 0,
1759                         1, x, y,
1760                         2, count, 4, count_d, 1, p,
1761                         (int (*)(tenm_object *, double))
1762                         (&insane_hand_ship_bit_move),
1763                         (int (*)(tenm_object *, tenm_object *))
1764                         NULL,
1765                         (int (*)(tenm_object *, const tenm_object *))
1766                         (&insane_hand_ship_bit_act),
1767                         (int (*)(tenm_object *, int))
1768                         (&insane_hand_ship_bit_draw));
1769 
1770   if (new == NULL)
1771   {
1772     fprintf(stderr, "insane_hand_ship_bit_new: tenm_object_new failed\n");
1773     if (count_d != NULL)
1774       free(count_d);
1775     if (count != NULL)
1776       free(count);
1777     (p[0])->delete(p[0]);
1778     free(p);
1779     return NULL;
1780   }
1781 
1782   return new;
1783 }
1784 
1785 static int
insane_hand_ship_bit_move(tenm_object * my,double turn_per_frame)1786 insane_hand_ship_bit_move(tenm_object *my, double turn_per_frame)
1787 {
1788   double dx_temp;
1789   double dy_temp;
1790 
1791   /* sanity check */
1792   if (my == NULL)
1793   {
1794     fprintf(stderr, "insane_hand_ship_bit_move: my is NULL\n");
1795     return 0;
1796   }
1797   if (turn_per_frame <= 0.5)
1798   {
1799     fprintf(stderr, "insane_hand_ship_bit_move: strange turn_per_frame (%f)\n",
1800             turn_per_frame);
1801     return 0;
1802   }
1803 
1804   dx_temp = my->count_d[0] / turn_per_frame;
1805   dy_temp = my->count_d[1] / turn_per_frame;
1806   my->x += dx_temp;
1807   my->y += dy_temp;
1808   if (my->mass != NULL)
1809     tenm_move_mass(my->mass, dx_temp, dy_temp);
1810 
1811   if ((my->count[0] > 0) && (!in_window_object(my)))
1812     return 1;
1813 
1814   return 0;
1815 }
1816 
1817 static int
insane_hand_ship_bit_act(tenm_object * my,const tenm_object * player)1818 insane_hand_ship_bit_act(tenm_object *my, const tenm_object *player)
1819 {
1820   double x;
1821   double y;
1822   double px;
1823   double py;
1824 
1825   /* sanity check */
1826   if (my == NULL)
1827   {
1828     fprintf(stderr, "insane_hand_ship_bit_act: my is NULL\n");
1829     return 0;
1830   }
1831   if (player == NULL)
1832     return 0;
1833 
1834   (my->count[0])++;
1835   if (my->count[0] == 0)
1836   {
1837     my->count_d[0] = 0.0;
1838     my->count_d[1] = 0.0;
1839     my->count_d[2] = my->x;
1840     my->count_d[3] = my->y;
1841   }
1842   if (my->count[0] == 990)
1843   {
1844     my->count_d[0] = (my->count_d[2] - my->x) / 100.0;
1845     my->count_d[1] = (my->count_d[3] - my->y) / 100.0;
1846   }
1847   if (my->count[0] == 1090)
1848   {
1849     my->count_d[0] = 6.0;
1850     my->count_d[1] = 0.0;
1851   }
1852   if (my->count[0] == 1135)
1853   {
1854     my->count_d[0] = 0.0;
1855     my->count_d[1] = 0.0;
1856   }
1857   if (my->count[0] >= 1140)
1858   {
1859     my->count_d[1] += 0.1;
1860   }
1861   if ((my->count[0] <= 30) || (my->count[0] >= 990))
1862     return 0;
1863 
1864   (my->count[1])++;
1865 
1866   /* speed change */
1867   x = my->x * 0.8 + my->y * 0.6;
1868   y = -(my->x) * 0.6 + my->y * 0.8;
1869   px = player->x * 0.8 + player->y * 0.6;
1870   py = -(player->x) * 0.6 + player->y * 0.8;
1871 
1872   my->count_d[0] = 0.0;
1873   my->count_d[1] = 0.0;
1874   /* don't chase if the player is immutable */
1875   if ((get_ship() < 0) || (player->count[1] > 0))
1876   {
1877     my->count_d[0] = 0.0;
1878     my->count_d[1] = 0.0;
1879   }
1880   else if (x - 25.0 > px)
1881   {
1882     my->count_d[0] = -3.2;
1883     my->count_d[1] = -2.4;
1884   }
1885   else if (x - 10.0 < px)
1886   {
1887     my->count_d[0] = 3.2;
1888     my->count_d[1] = 2.4;
1889   }
1890   else if (y - 5.0 > py)
1891   {
1892     my->count_d[0] = 1.2;
1893     my->count_d[1] = -1.6;
1894   }
1895   else if (y + 5.0 < py)
1896   {
1897     my->count_d[0] = -1.2;
1898     my->count_d[1] = 1.6;
1899   }
1900   if (my->x + my->count_d[0] < 0.0)
1901     my->count_d[0] = 0.0 - my->x;
1902   if (my->x + my->count_d[0] > ((double) WINDOW_WIDTH))
1903     my->count_d[0] = ((double) WINDOW_WIDTH) - my->x;
1904   if (my->y + my->count_d[1] < 0.0)
1905     my->count_d[1] = 0.0 - my->y;
1906   if (my->y + my->count_d[1] > ((double) WINDOW_HEIGHT))
1907     my->count_d[1] = ((double) WINDOW_HEIGHT) - my->y;
1908 
1909   /* shoot */
1910   if (my->count[1] % 30 == 0)
1911   {
1912     tenm_table_add(laser_new(my->x, my->y, 3.0, -4.0,
1913                              15.0, -20.0, 0, -2, 0));
1914     tenm_table_add(laser_new(my->x, my->y, -3.0, 4.0,
1915                              -15.0, 20.0, 0, -2, 0));
1916     tenm_table_add(laser_new(my->x, my->y,
1917                              -4.0 * tenm_cos(15) + (-3.0) * (-tenm_sin(15)),
1918                              -4.0 * tenm_sin(15) + (-3.0) * tenm_cos(15),
1919                              -20.0 * tenm_cos(15) + (-15.0) * (-tenm_sin(15)),
1920                              -20.0 * tenm_sin(15) + (-15.0) * tenm_cos(15),
1921                              0, -2, 0));
1922     tenm_table_add(laser_new(my->x, my->y,
1923                              -4.0 * tenm_cos(-15) + (-3.0) * (-tenm_sin(-15)),
1924                              -4.0 * tenm_sin(-15) + (-3.0) * tenm_cos(-15),
1925                              -20.0 * tenm_cos(-15) +(-15.0) * (-tenm_sin(-15)),
1926                              -20.0 * tenm_sin(-15) +(-15.0) * tenm_cos(-15),
1927                              0, -2, 0));
1928   }
1929 
1930   return 0;
1931 }
1932 
1933 static int
insane_hand_ship_bit_draw(tenm_object * my,int priority)1934 insane_hand_ship_bit_draw(tenm_object *my, int priority)
1935 {
1936   int status = 0;
1937   tenm_color color;
1938 
1939   /* sanity check */
1940   if (my == NULL)
1941     return 0;
1942 
1943   if (priority != 0)
1944     return 0;
1945 
1946   /* decoration */
1947   color = tenm_map_color(182, 123, 162);
1948   if (tenm_draw_line((int) (my->x + 15.0), (int) (my->y - 20.0),
1949                      (int) (my->x + 15.0
1950                             - 40.0 * tenm_cos(15)
1951                             - 30.0 * (-tenm_sin(15))),
1952                      (int) (my->y - 20.0
1953                             - 40.0 * tenm_sin(15)
1954                             - 30.0 * tenm_cos(15)),
1955                      1, color) != 0)
1956     status = 1;
1957   if (tenm_draw_line((int) (my->x - 15.0), (int) (my->y + 20.0),
1958                      (int) (my->x - 15.0
1959                             - 40.0 * tenm_cos(-15)
1960                             - 30.0 * (-tenm_sin(-15))),
1961                      (int) (my->y + 20.0
1962                             - 40.0 * tenm_sin(-15)
1963                             - 30.0 * tenm_cos(-15)),
1964                      1, color) != 0)
1965     status = 1;
1966 
1967   /* body */
1968   color = tenm_map_color(95, 13, 68);
1969   if (tenm_draw_circle((int) (my->x), (int) (my->y), 25, 3, color) != 0)
1970     status = 1;
1971 
1972   return status;
1973 }
1974 
1975 static tenm_object *
insane_hand_ship_shot_new(double x,double y,double v_x,double v_y)1976 insane_hand_ship_shot_new(double x, double y, double v_x, double v_y)
1977 {
1978   tenm_primitive **p = NULL;
1979   tenm_object *new = NULL;
1980   int *count = NULL;
1981   double *count_d = NULL;
1982 
1983   /* sanity check */
1984   if (v_x * v_x + v_y * v_y < NEAR_ZERO)
1985   {
1986     fprintf(stderr, "insane_hand_ship_shot_new: speed is too small "
1987             "(%f, %f)\n", v_x, v_y);
1988     return NULL;
1989   }
1990 
1991   p = (tenm_primitive **) malloc(sizeof(tenm_primitive *) * 1);
1992   if (p == NULL)
1993   {
1994     fprintf(stderr, "insane_hand_ship_shot_new: malloc(p) failed\n");
1995     return NULL;
1996   }
1997 
1998   p[0] = (tenm_primitive *) tenm_circle_new(x, y, 5.0);
1999   if (p[0] == NULL)
2000   {
2001     fprintf(stderr, "insane_hand_ship_shot_new: cannot set p[0]\n");
2002     free(p);
2003     return NULL;
2004   }
2005 
2006   count = (int *) malloc(sizeof(int) * 1);
2007   if (count == NULL)
2008   {
2009     fprintf(stderr, "insane_hand_ship_shot_new: malloc(count) failed\n");
2010     (p[0])->delete(p[0]);
2011     free(p);
2012     return NULL;
2013   }
2014   count_d = (double *) malloc(sizeof(double) * 4);
2015   if (count_d == NULL)
2016   {
2017     fprintf(stderr, "insane_hand_ship_shot_new: malloc(count_d) failed\n");
2018     free(count);
2019     (p[0])->delete(p[0]);
2020     free(p);
2021     return NULL;
2022   }
2023 
2024   if (v_y > 0.1)
2025   {
2026     count_d[2] = -(-0.25) * 0.6;
2027     count_d[3] = (-0.25) * 0.8;
2028   }
2029   else if (v_y < -0.1)
2030   {
2031     count_d[2] = -(0.25) * 0.6;
2032     count_d[3] = (0.25) * 0.8;
2033   }
2034   else
2035   {
2036     count_d[2] = 0.0;
2037     count_d[3] = 0.0;
2038   }
2039 
2040   /* list of count
2041    * [0] color (for delete_enemy_shot)
2042    */
2043   count[0] = 4;
2044 
2045   /* list of count_d
2046    * [0] dx
2047    * [1] dy
2048    * [2] ddx
2049    * [3] ddy
2050    */
2051   count_d[0] = v_x * 0.8 - v_y * 0.6;
2052   count_d[1] = v_x * 0.6 + v_y * 0.8;
2053 
2054   new = tenm_object_new("Insane Hand ship shot", ATTR_ENEMY_SHOT, ATTR_OPAQUE,
2055                         1, x, y,
2056                         1, count, 4, count_d, 1, p,
2057                         (int (*)(tenm_object *, double))
2058                         (&insane_hand_ship_shot_move),
2059                         (int (*)(tenm_object *, tenm_object *))
2060                         (&insane_hand_ship_shot_hit),
2061                         (int (*)(tenm_object *, const tenm_object *))
2062                         (&insane_hand_ship_shot_act),
2063                         (int (*)(tenm_object *, int))
2064                         (&insane_hand_ship_shot_draw));
2065 
2066   if (new == NULL)
2067   {
2068     fprintf(stderr, "insane_hand_ship_shot_new: tenm_object_new failed\n");
2069     if (count_d != NULL)
2070       free(count_d);
2071     if (count != NULL)
2072       free(count);
2073     (p[0])->delete(p[0]);
2074     free(p);
2075     return NULL;
2076   }
2077 
2078   return new;
2079 }
2080 
2081 static int
insane_hand_ship_shot_move(tenm_object * my,double turn_per_frame)2082 insane_hand_ship_shot_move(tenm_object *my, double turn_per_frame)
2083 {
2084   double dx_temp;
2085   double dy_temp;
2086 
2087   /* sanity check */
2088   if (my == NULL)
2089   {
2090     fprintf(stderr, "insane_hand_ship_shot_move: my is NULL\n");
2091     return 0;
2092   }
2093   if (turn_per_frame <= 0.5)
2094   {
2095     fprintf(stderr, "insane_hand_ship_shot_move: "
2096             "strange turn_per_frame (%f)\n",
2097             turn_per_frame);
2098     return 0;
2099   }
2100 
2101   dx_temp = my->count_d[0] / turn_per_frame;
2102   dy_temp = my->count_d[1] / turn_per_frame;
2103   my->x += dx_temp;
2104   my->y += dy_temp;
2105   tenm_move_mass(my->mass, dx_temp, dy_temp);
2106 
2107   if (!in_window_object(my))
2108     return 1;
2109 
2110   return 0;
2111 }
2112 
2113 static int
insane_hand_ship_shot_hit(tenm_object * my,tenm_object * your)2114 insane_hand_ship_shot_hit(tenm_object *my, tenm_object *your)
2115 {
2116   /* sanity check */
2117   if (my == NULL)
2118   {
2119     fprintf(stderr, "insane_hand_ship_shot_hit: my is NULL\n");
2120     return 0;
2121   }
2122   if (your == NULL)
2123   {
2124     fprintf(stderr, "insane_hand_ship_shot_hit: your is NULL\n");
2125     return 0;
2126   }
2127 
2128   if (your->attr & ATTR_OPAQUE)
2129     return 1;
2130 
2131   return 0;
2132 }
2133 
2134 static int
insane_hand_ship_shot_act(tenm_object * my,const tenm_object * player)2135 insane_hand_ship_shot_act(tenm_object *my, const tenm_object *player)
2136 {
2137   /* sanity check */
2138   if (my == NULL)
2139   {
2140     fprintf(stderr, "insane_hand_ship_shot_act: my is NULL\n");
2141     return 0;
2142   }
2143   if (player == NULL)
2144     return 0;
2145 
2146   my->count_d[0] += my->count_d[2];
2147   my->count_d[1] += my->count_d[3];
2148 
2149   return 0;
2150 }
2151 
2152 static int
insane_hand_ship_shot_draw(tenm_object * my,int priority)2153 insane_hand_ship_shot_draw(tenm_object *my, int priority)
2154 {
2155   int status = 0;
2156   tenm_color color;
2157 
2158   /* sanity check */
2159   if (my == NULL)
2160   {
2161     fprintf(stderr, "insane_hand_ship_shot_draw: my is NULL\n");
2162     return 0;
2163   }
2164 
2165   /* return if it is not my turn */
2166   if (priority != 1)
2167     return 0;
2168 
2169   color = tenm_map_color(75, 0, 239);
2170   if (tenm_draw_circle((int) (my->x), (int) (my->y), 5, 2, color) != 0)
2171     status = 1;
2172 
2173   return status;
2174 }
2175