| 1 |
#ifdef HAVE_CONFIG_H |
| 2 |
#include <config.h> |
| 3 |
#endif |
| 4 |
|
| 5 |
#include "brain.h" |
| 6 |
#include "game_engine.h" |
| 7 |
#include "live_sprites_manager.h" |
| 8 |
#include "freedink.h" |
| 9 |
#include "game_engine.h" |
| 10 |
#include "live_screen.h" |
| 11 |
#include "gfx_sprites.h" |
| 12 |
#include "sfx.h" |
| 13 |
#include "dinkc.h" |
| 14 |
|
| 15 |
/*bool*/int check_for_duck_script(int i) |
| 16 |
{ |
| 17 |
|
| 18 |
|
| 19 |
if (spr[i].script > 0) |
| 20 |
{ |
| 21 |
//if ( (spr[i].brain == 0) | (spr[i].brain == 5) | (spr[i].brain == 6) | (spr[i].brain == 7)) |
| 22 |
|
| 23 |
if (locate(spr[i].script, "DUCKDIE")) run_script(spr[i].script); |
| 24 |
|
| 25 |
return(/*true*/1); |
| 26 |
} |
| 27 |
|
| 28 |
return(/*false*/0); |
| 29 |
} |
| 30 |
|
| 31 |
void kill_sprite_all(int sprite) { |
| 32 |
lsm_remove_sprite(sprite); |
| 33 |
kill_text_owned_by(sprite); |
| 34 |
kill_scripts_owned_by(sprite); |
| 35 |
} |
| 36 |
|
| 37 |
void duck_brain(int h) |
| 38 |
{ |
| 39 |
int hold; |
| 40 |
|
| 41 |
|
| 42 |
if ( (spr[h].damage > 0) && (in_this_base(spr[h].pseq, 110) ) ) |
| 43 |
{ |
| 44 |
|
| 45 |
check_for_duck_script(h); |
| 46 |
|
| 47 |
//hit a dead duck |
| 48 |
int crap2 = add_sprite(spr[h].x,spr[h].y,7,164,1); |
| 49 |
/* TODO: add_sprite might return 0, and the following |
| 50 |
would trash spr[0] - cf. bugs.debian.org/688934 */ |
| 51 |
spr[crap2].speed = 0; |
| 52 |
spr[crap2].base_walk = 0; |
| 53 |
spr[crap2].seq = 164; |
| 54 |
draw_damage(h); |
| 55 |
spr[h].damage = 0; |
| 56 |
add_exp(spr[h].exp, h); |
| 57 |
|
| 58 |
kill_sprite_all(h); |
| 59 |
|
| 60 |
return; |
| 61 |
} |
| 62 |
|
| 63 |
|
| 64 |
if ( (spr[h].damage > 0) && (in_this_base(spr[h].pseq, spr[h].base_walk) ) ) |
| 65 |
{ |
| 66 |
//SoundPlayEffect( 1,3000, 800 ); |
| 67 |
draw_damage(h); |
| 68 |
add_exp(spr[h].exp, h); |
| 69 |
spr[h].damage = 0; |
| 70 |
|
| 71 |
//lets kill the duck here, ha. |
| 72 |
check_for_kill_script(h); |
| 73 |
spr[h].follow = 0; |
| 74 |
int crap = add_sprite(spr[h].x,spr[h].y,5,1,1); |
| 75 |
/* TODO: add_sprite might return 0, and the following |
| 76 |
would trash spr[0] - cf. bugs.debian.org/688934 */ |
| 77 |
spr[crap].speed = 0; |
| 78 |
spr[crap].base_walk = 0; |
| 79 |
spr[crap].size = spr[h].size; |
| 80 |
spr[crap].speed = ((rand() % 3)+1); |
| 81 |
|
| 82 |
|
| 83 |
spr[h].base_walk = 110; |
| 84 |
spr[h].speed = 1; |
| 85 |
spr[h].timing = 0; |
| 86 |
spr[h].wait = 0; |
| 87 |
spr[h].frame = 0; |
| 88 |
|
| 89 |
if (spr[h].dir == 0) spr[h].dir = 1; |
| 90 |
if (spr[h].dir == 4) spr[h].dir = 7; |
| 91 |
if (spr[h].dir == 6) spr[h].dir = 3; |
| 92 |
|
| 93 |
changedir(spr[h].dir,h,spr[h].base_walk); |
| 94 |
spr[crap].dir = spr[h].dir; |
| 95 |
spr[crap].base_walk = 120; |
| 96 |
changedir(spr[crap].dir,crap,spr[crap].base_walk); |
| 97 |
|
| 98 |
|
| 99 |
automove(h); |
| 100 |
return; |
| 101 |
} |
| 102 |
|
| 103 |
|
| 104 |
if (spr[h].move_active) |
| 105 |
{ |
| 106 |
process_move(h); |
| 107 |
return; |
| 108 |
} |
| 109 |
|
| 110 |
if (spr[h].freeze) |
| 111 |
{ |
| 112 |
return; |
| 113 |
} |
| 114 |
|
| 115 |
|
| 116 |
if (spr[h].follow > 0) |
| 117 |
{ |
| 118 |
process_follow(h); |
| 119 |
return; |
| 120 |
} |
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
if (spr[h].base_walk == 110) |
| 125 |
{ |
| 126 |
if ( (rand() % 100)+1 == 1) |
| 127 |
random_blood(spr[h].x, spr[h].y-18, h); |
| 128 |
goto walk; |
| 129 |
} |
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
if (spr[h].seq == 0 ) |
| 136 |
{ |
| 137 |
|
| 138 |
if (((rand() % 12)+1) == 1 ) |
| 139 |
{ |
| 140 |
hold = ((rand() % 9)+1); |
| 141 |
|
| 142 |
if ((hold != 2) && (hold != 8) && (hold != 5)) |
| 143 |
{ |
| 144 |
|
| 145 |
//Msg("random dir change started.. %d", hold); |
| 146 |
changedir(hold,h,spr[h].base_walk); |
| 147 |
|
| 148 |
} |
| 149 |
else |
| 150 |
{ |
| 151 |
int junk = spr[h].size; |
| 152 |
|
| 153 |
if (junk >= 100) |
| 154 |
junk = 18000 - (junk * 50); |
| 155 |
|
| 156 |
if (junk < 100) |
| 157 |
junk = 16000 + (junk * 100); |
| 158 |
|
| 159 |
SoundPlayEffect( 1,junk, 800,h ,0); |
| 160 |
spr[h].mx = 0; |
| 161 |
spr[h].my = 0; |
| 162 |
spr[h].wait = thisTickCount + (rand() % 300)+200; |
| 163 |
|
| 164 |
} |
| 165 |
return; |
| 166 |
} |
| 167 |
|
| 168 |
if ((spr[h].mx != 0) || (spr[h].my != 0)) |
| 169 |
|
| 170 |
{ |
| 171 |
spr[h].seq = spr[h].seq_orig; |
| 172 |
|
| 173 |
} |
| 174 |
|
| 175 |
} |
| 176 |
|
| 177 |
|
| 178 |
walk: |
| 179 |
if (spr[h].y > playy) |
| 180 |
|
| 181 |
{ |
| 182 |
changedir(9,h,spr[h].base_walk); |
| 183 |
} |
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
if (spr[h].x > playx-30) |
| 188 |
|
| 189 |
{ |
| 190 |
changedir(7,h,spr[h].base_walk); |
| 191 |
} |
| 192 |
|
| 193 |
if (spr[h].y < 10) |
| 194 |
{ |
| 195 |
changedir(1,h,spr[h].base_walk); |
| 196 |
} |
| 197 |
|
| 198 |
if (spr[h].x < 30) |
| 199 |
{ |
| 200 |
changedir(3,h,spr[h].base_walk); |
| 201 |
} |
| 202 |
|
| 203 |
// Msg("Duck dir is %d, seq is %d.", spr[h].dir, spr[h].seq); |
| 204 |
automove(h); |
| 205 |
|
| 206 |
if (check_if_move_is_legal(h) != 0) |
| 207 |
|
| 208 |
{ |
| 209 |
if (spr[h].dir != 0) |
| 210 |
changedir(autoreverse_diag(h),h,spr[h].base_walk); |
| 211 |
} |
| 212 |
|
| 213 |
} |