| 1 |
#ifdef HAVE_CONFIG_H |
| 2 |
#include <config.h> |
| 3 |
#endif |
| 4 |
|
| 5 |
#include "brain.h" |
| 6 |
#include "live_sprites_manager.h" |
| 7 |
#include "gfx_sprites.h" |
| 8 |
#include "log.h" |
| 9 |
#include "freedink.h" |
| 10 |
#include "game_engine.h" |
| 11 |
#include "live_screen.h" |
| 12 |
|
| 13 |
void process_target(int h) |
| 14 |
{ |
| 15 |
if (spr[h].target > 299) |
| 16 |
{ |
| 17 |
log_error("Sprite %d cannot 'target' sprite %d??",h,spr[h].follow); |
| 18 |
return; |
| 19 |
} |
| 20 |
|
| 21 |
if (!spr[spr[h].target].active) |
| 22 |
{ |
| 23 |
log_debug("Killing target"); |
| 24 |
spr[h].target = 0; |
| 25 |
return; |
| 26 |
} |
| 27 |
|
| 28 |
int dir; |
| 29 |
int distance = get_distance_and_dir(h, spr[h].target, &dir); |
| 30 |
|
| 31 |
if (distance < spr[h].distance) return; |
| 32 |
|
| 33 |
changedir(dir,h,spr[h].base_walk); |
| 34 |
|
| 35 |
automove(h); |
| 36 |
} |
| 37 |
|
| 38 |
/** |
| 39 |
* Enemy with diagonal moves, e.g. pillbug |
| 40 |
*/ |
| 41 |
void pill_brain(int h) |
| 42 |
{ |
| 43 |
int hold; |
| 44 |
|
| 45 |
if (spr[h].damage > 0) |
| 46 |
{ |
| 47 |
//got hit |
| 48 |
//SoundPlayEffect( 1,3000, 800 ); |
| 49 |
if (spr[h].hitpoints > 0) |
| 50 |
{ |
| 51 |
draw_damage(h); |
| 52 |
if (spr[h].damage > spr[h].hitpoints) spr[h].damage = spr[h].hitpoints; |
| 53 |
spr[h].hitpoints -= spr[h].damage; |
| 54 |
|
| 55 |
if (spr[h].hitpoints < 1) |
| 56 |
{ |
| 57 |
//they killed it |
| 58 |
check_for_kill_script(h); |
| 59 |
|
| 60 |
if (spr[h].brain == 9) // i.e. not overriden in sprite's die() |
| 61 |
{ |
| 62 |
if (spr[h].dir == 0) spr[h].dir = 3; |
| 63 |
change_dir_to_diag(&spr[h].dir); |
| 64 |
add_kill_sprite(h); |
| 65 |
lsm_remove_sprite(h); |
| 66 |
} |
| 67 |
return; |
| 68 |
|
| 69 |
} |
| 70 |
} |
| 71 |
spr[h].damage = 0; |
| 72 |
|
| 73 |
} |
| 74 |
|
| 75 |
if (spr[h].move_active) |
| 76 |
{ |
| 77 |
process_move(h); |
| 78 |
return; |
| 79 |
} |
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
if (spr[h].freeze) return; |
| 85 |
|
| 86 |
if (spr[h].follow > 0) |
| 87 |
{ |
| 88 |
process_follow(h); |
| 89 |
|
| 90 |
} |
| 91 |
|
| 92 |
|
| 93 |
if (spr[h].target != 0) |
| 94 |
{ |
| 95 |
|
| 96 |
if (in_this_base(spr[h].seq, spr[h].base_attack)) |
| 97 |
{ |
| 98 |
//still attacking |
| 99 |
return; |
| 100 |
} |
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
int dir; |
| 107 |
if (spr[h].distance == 0) spr[h].distance = 5; |
| 108 |
int distance = get_distance_and_dir(h, spr[h].target, &dir); |
| 109 |
|
| 110 |
if (distance < spr[h].distance) if ((unsigned)spr[h].attack_wait < thisTickCount) |
| 111 |
{ |
| 112 |
// Msg("base attack is %d.",spr[h].base_attack); |
| 113 |
if (spr[h].base_attack != -1) |
| 114 |
{ |
| 115 |
//Msg("attacking with %d..", spr[h].base_attack+dir); |
| 116 |
|
| 117 |
/* Enforce lateral (not diagonal) attack, |
| 118 |
even in smooth_follow mode */ |
| 119 |
int attackdir = 6; // arbitrary initialized default |
| 120 |
get_distance_and_dir_nosmooth(h, spr[h].target, &attackdir); |
| 121 |
spr[h].dir = attackdir; |
| 122 |
|
| 123 |
spr[h].seq = spr[h].base_attack+spr[h].dir; |
| 124 |
spr[h].frame = 0; |
| 125 |
|
| 126 |
if (spr[h].script != 0) |
| 127 |
{ |
| 128 |
if (locate(spr[h].script, "ATTACK")) |
| 129 |
run_script(spr[h].script); |
| 130 |
else |
| 131 |
spr[h].move_wait = thisTickCount + ((rand() % 300)+10); |
| 132 |
} |
| 133 |
return; |
| 134 |
|
| 135 |
} |
| 136 |
|
| 137 |
} |
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
if (spr[h].move_wait < thisTickCount) |
| 142 |
{ |
| 143 |
process_target(h); |
| 144 |
spr[h].move_wait = thisTickCount + 200; |
| 145 |
|
| 146 |
} |
| 147 |
else |
| 148 |
{ |
| 149 |
/* automove(h); |
| 150 |
|
| 151 |
if (check_if_move_is_legal(h) != 0) |
| 152 |
{ |
| 153 |
|
| 154 |
} |
| 155 |
*/ |
| 156 |
|
| 157 |
goto walk_normal; |
| 158 |
} |
| 159 |
|
| 160 |
return; |
| 161 |
} |
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
walk_normal: |
| 166 |
|
| 167 |
if (spr[h].base_walk != -1) |
| 168 |
{ |
| 169 |
if ( spr[h].seq == 0) goto recal; |
| 170 |
} |
| 171 |
|
| 172 |
if (( spr[h].seq == 0) && (spr[h].move_wait < thisTickCount)) |
| 173 |
{ |
| 174 |
recal: |
| 175 |
if (((rand() % 12)+1) == 1 ) |
| 176 |
{ |
| 177 |
hold = ((rand() % 9)+1); |
| 178 |
if ( (hold != 4) && (hold != 6) && (hold != 2) && (hold != 8) && (hold != 5)) |
| 179 |
{ |
| 180 |
changedir(hold,h,spr[h].base_walk); |
| 181 |
spr[h].move_wait = thisTickCount +((rand() % 2000)+200); |
| 182 |
|
| 183 |
} |
| 184 |
|
| 185 |
} else |
| 186 |
{ |
| 187 |
//keep going the same way |
| 188 |
if (in_this_base(spr[h].seq_orig, spr[h].base_attack)) goto recal; |
| 189 |
spr[h].seq = spr[h].seq_orig; |
| 190 |
if (spr[h].seq_orig == 0) goto recal; |
| 191 |
} |
| 192 |
|
| 193 |
} |
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
if (spr[h].y > (playy - 15)) |
| 198 |
|
| 199 |
{ |
| 200 |
changedir(9,h,spr[h].base_walk); |
| 201 |
} |
| 202 |
|
| 203 |
if (spr[h].x > (playx - 15)) |
| 204 |
|
| 205 |
{ |
| 206 |
changedir(1,h,spr[h].base_walk); |
| 207 |
} |
| 208 |
|
| 209 |
if (spr[h].y < 18) |
| 210 |
{ |
| 211 |
changedir(1,h,spr[h].base_walk); |
| 212 |
} |
| 213 |
|
| 214 |
if (spr[h].x < 18) |
| 215 |
{ |
| 216 |
changedir(3,h,spr[h].base_walk); |
| 217 |
} |
| 218 |
|
| 219 |
automove(h); |
| 220 |
|
| 221 |
if (check_if_move_is_legal(h) != 0) |
| 222 |
{ |
| 223 |
spr[h].move_wait = thisTickCount + 400; |
| 224 |
changedir(autoreverse_diag(h),h,spr[h].base_walk); |
| 225 |
} |
| 226 |
|
| 227 |
|
| 228 |
// changedir(hold,h,spr[h].base_walk); |
| 229 |
|
| 230 |
|
| 231 |
} |