Debian Codegraph @

src/brain_missile.cpp

raw
1
2 #ifdef HAVE_CONFIG_H
3 #include <config.h>
4 #endif
5
6 #include "brain.h"
7 #include "live_sprites_manager.h"
8 #include "freedink.h"
9 #include "game_engine.h"
10 #include "gfx.h"
11 #include "gfx_sprites.h"
12 #include "sfx.h"
13 #include "log.h"
14
15 void make_missile(int x1, int y1, int dir, int speed, int seq, int frame, int strength)
16 {
17 int crap = add_sprite(x1,y1,11,seq,frame);
18 spr[crap].speed = speed;
19 spr[crap].seq = seq;
20 spr[crap].timing = 0;
21 spr[crap].strength = strength;
22 spr[crap].flying = /*true*/1;
23 changedir(dir, crap, 430);
24
25 }
26
27 void missile_brain(int h, /*bool*/int repeat)
28 {
29 rect box;
30 int j;
31 automove(h);
32
33 *pmissle_source = h;
34 int hard = check_if_move_is_legal(h);
35 if (repeat && spr[h].seq == 0)
36 spr[h].seq = spr[h].seq_orig;
37 spr[1].hitpoints = *plife;
38
39 if (hard > 0 && hard != 2)
40 {
41 //lets check to see if they hit a sprites hardness
42 if (hard > 100)
43 {
44 int ii;
45 for (ii = 1; ii < last_sprite_created; ii++)
46 {
47 if (spr[ii].sp_index == hard-100)
48 {
49 if (spr[ii].script > 0)
50 {
51 *pmissile_target = 1;
52 *penemy_sprite = 1;
53
54 if (locate(spr[ii].script, "HIT"))
55 {
56 kill_returning_stuff(spr[ii].script);
57 run_script(spr[ii].script);
58 }
59 }
60
61 if (spr[h].script > 0)
62 {
63 *pmissile_target = ii;
64 *penemy_sprite = 1;
65 if (locate(spr[h].script, "DAMAGE"))
66 {
67 kill_returning_stuff(spr[h].script);
68 run_script(spr[h].script);
69 }
70 }
71 else
72 {
73 if (spr[h].attack_hit_sound == 0)
74 SoundPlayEffect( 9,22050, 0 ,0,0);
75 else
76 SoundPlayEffect( spr[h].attack_hit_sound,spr[h].attack_hit_sound_speed, 0 ,0,0);
77
78 lsm_remove_sprite(h);
79 }
80
81 //run missile end
82 return;
83 }
84 }
85 }
86 //run missile end
87
88 if (spr[h].script > 0)
89 {
90 *pmissile_target = 0;
91 if (locate(spr[h].script, "DAMAGE"))
92 run_script(spr[h].script);
93 }
94 else
95 {
96 if (spr[h].attack_hit_sound == 0)
97 SoundPlayEffect(9, 22050, 0, 0, 0);
98 else
99 SoundPlayEffect(spr[h].attack_hit_sound,spr[h].attack_hit_sound_speed, 0, 0, 0);
100
101 lsm_remove_sprite(h);
102 return;
103 }
104 }
105
106 if (spr[h].x > 1000) lsm_remove_sprite(h);
107 if (spr[h].y > 700) lsm_remove_sprite(h);
108 if (spr[h].y < -500) lsm_remove_sprite(h);
109 if (spr[h].x < -500) lsm_remove_sprite(h);
110
111 //did we hit anything that can die?
112
113 for (j = 1; j <= last_sprite_created; j++)
114 {
115 if (spr[j].active && h != j && spr[j].nohit != 1 && spr[j].notouch == /*false*/0)
116 if (spr[h].brain_parm != j && spr[h].brain_parm2!= j)
117 //if (spr[j].brain != 15) if (spr[j].brain != 11)
118 {
119 rect_copy(&box, &k[getpic(j)].hardbox);
120 rect_offset(&box, spr[j].x, spr[j].y);
121
122 if (spr[h].range != 0)
123 rect_inflate(&box, spr[h].range,spr[h].range);
124
125 if (debug_mode) {
126 SDL_Rect r = {box.left, box.top, box.right-box.left, box.bottom-box.top};
127 IOGFX_backbuffer->fillRect(&r, 222, 173, 255);
128 }
129
130 if (inside_box(spr[h].x, spr[h].y, box))
131 {
132 spr[j].notouch = /*true*/1;
133 spr[j].notouch_timer = thisTickCount+100;
134 spr[j].target = 1;
135 *penemy_sprite = 1;
136 //change later to reflect REAL target
137 if (spr[h].script > 0)
138 {
139 *pmissile_target = j;
140 if (locate(spr[h].script, "DAMAGE"))
141 run_script(spr[h].script);
142 }
143 else
144 {
145 if (spr[h].attack_hit_sound == 0)
146 SoundPlayEffect(9, 22050, 0, 0, 0);
147 else
148 SoundPlayEffect(spr[h].attack_hit_sound,spr[h].attack_hit_sound_speed, 0, 0,0);
149 }
150
151 if (spr[j].hitpoints > 0 && spr[h].strength != 0)
152 {
153 int hit = 0;
154 if (spr[h].strength == 1)
155 hit = spr[h].strength - spr[j].defense;
156 else
157 hit = (spr[h].strength / 2)
158 + ((rand() % (spr[h].strength / 2)) + 1)
159 - spr[j].defense;
160
161 if (hit < 0)
162 hit = 0;
163 spr[j].damage += hit;
164 if (hit > 0)
165 random_blood(spr[j].x, spr[j].y-40, j);
166 spr[j].last_hit = 1;
167 //Msg("Damage done is %d..", spr[j].damage);
168 }
169
170 if (spr[j].script > 0)
171 {
172 //CHANGED did = h
173 *pmissile_target = 1;
174
175 if (locate(spr[j].script, "HIT"))
176 {
177 kill_returning_stuff(spr[j].script);
178 run_script(spr[j].script);
179 }
180 }
181 }
182 //run missile end
183
184 }
185 }
186 }
187
188
189 void missile_brain_expire(int h)
190 {
191 missile_brain(h, /*false*/0);
192 if (spr[h].seq == 0)
193 lsm_remove_sprite(h);
194
195 }