| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
#include <global.h> |
| 28 |
#include <sproto.h> |
| 29 |
#include <ob_methods.h> |
| 30 |
#include <ob_types.h> |
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
void stop_projectile(object *op) { |
| 37 |
|
| 38 |
object *event = op; |
| 39 |
tag_t tag; |
| 40 |
|
| 41 |
if (op->inv) |
| 42 |
event = op->inv; |
| 43 |
|
| 44 |
tag = event->count; |
| 45 |
execute_event(event, EVENT_STOP, NULL, NULL, NULL, SCRIPT_FIX_NOTHING); |
| 46 |
|
| 47 |
if (object_was_destroyed(event, tag)) { |
| 48 |
if (event != op) { |
| 49 |
object_remove(op); |
| 50 |
object_free(op, FREE_OBJ_FREE_INVENTORY); |
| 51 |
} |
| 52 |
return; |
| 53 |
} |
| 54 |
|
| 55 |
if (op->inv) { |
| 56 |
object *payload = op->inv; |
| 57 |
|
| 58 |
object_remove(payload); |
| 59 |
object_clear_owner(payload); |
| 60 |
object_insert_in_map_at(payload, op->map, payload, 0, op->x, op->y); |
| 61 |
object_remove(op); |
| 62 |
object_free_drop_inventory(op); |
| 63 |
} else { |
| 64 |
op = fix_stopped_arrow(op); |
| 65 |
if (op) |
| 66 |
object_merge(op, NULL); |
| 67 |
} |
| 68 |
} |
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
method_ret common_process_projectile(ob_methods *context, object *op) { |
| 79 |
object *tmp; |
| 80 |
int16_t new_x, new_y; |
| 81 |
int mflags; |
| 82 |
mapstruct *m; |
| 83 |
|
| 84 |
if (op->map == NULL) { |
| 85 |
LOG(llevError, "BUG: Projectile had no map.\n"); |
| 86 |
object_remove(op); |
| 87 |
object_free_drop_inventory(op); |
| 88 |
return METHOD_ERROR; |
| 89 |
} |
| 90 |
|
| 91 |
|
| 92 |
new_x = op->x+DIRX(op); |
| 93 |
new_y = op->y+DIRY(op); |
| 94 |
|
| 95 |
m = op->map; |
| 96 |
mflags = get_map_flags(m, &m, new_x, new_y, &new_x, &new_y); |
| 97 |
|
| 98 |
if (mflags&P_OUT_OF_MAP) { |
| 99 |
stop_projectile(op); |
| 100 |
return METHOD_OK; |
| 101 |
} |
| 102 |
|
| 103 |
|
| 104 |
if (mflags&P_IS_ALIVE) { |
| 105 |
tmp = map_find_by_flag(m, new_x, new_y, FLAG_ALIVE); |
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
if (tmp != NULL && tmp != object_get_owner(op)) { |
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
if (QUERY_FLAG(tmp, FLAG_REFL_MISSILE) |
| 117 |
&& (rndm(0, 99)) < (90-op->level/10)) { |
| 118 |
|
| 119 |
op->direction = absdir(op->direction+4); |
| 120 |
op->state = 0; |
| 121 |
if (GET_ANIM_ID(op)) { |
| 122 |
object_update_turn_face(op); |
| 123 |
} |
| 124 |
} else { |
| 125 |
|
| 126 |
op = hit_with_arrow(op, tmp); |
| 127 |
if (op == NULL) |
| 128 |
return METHOD_OK; |
| 129 |
} |
| 130 |
} |
| 131 |
} |
| 132 |
|
| 133 |
if (OB_TYPE_MOVE_BLOCK(op, GET_MAP_MOVE_BLOCK(m, new_x, new_y))) { |
| 134 |
int retry = 0; |
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
if (!QUERY_FLAG(op, FLAG_REFLECTING) || !(rndm(0, 19))) { |
| 143 |
stop_projectile(op); |
| 144 |
return METHOD_OK; |
| 145 |
} else { |
| 146 |
|
| 147 |
if (op->direction&1) { |
| 148 |
op->direction = absdir(op->direction+4); |
| 149 |
retry = 1; |
| 150 |
} |
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
while (retry < 2) { |
| 156 |
int left, right, mflags; |
| 157 |
mapstruct *m1; |
| 158 |
int16_t x1, y1; |
| 159 |
|
| 160 |
retry++; |
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
mflags = get_map_flags(op->map, &m1, op->x+freearr_x[absdir(op->direction-1)], op->y+freearr_y[absdir(op->direction-1)], &x1, &y1); |
| 168 |
left = (mflags&P_OUT_OF_MAP) ? 0 : OB_TYPE_MOVE_BLOCK(op, (GET_MAP_MOVE_BLOCK(m1, x1, y1))); |
| 169 |
|
| 170 |
mflags = get_map_flags(op->map, &m1, op->x+freearr_x[absdir(op->direction+1)], op->y+freearr_y[absdir(op->direction+1)], &x1, &y1); |
| 171 |
right = (mflags&P_OUT_OF_MAP) ? 0 : OB_TYPE_MOVE_BLOCK(op, (GET_MAP_MOVE_BLOCK(m1, x1, y1))); |
| 172 |
|
| 173 |
if (left == right) |
| 174 |
op->direction = absdir(op->direction+4); |
| 175 |
else if (left) |
| 176 |
op->direction = absdir(op->direction+2); |
| 177 |
else if (right) |
| 178 |
op->direction = absdir(op->direction-2); |
| 179 |
|
| 180 |
mflags = get_map_flags(op->map, &m1, op->x+DIRX(op), op->y+DIRY(op), &x1, &y1); |
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
if (!(mflags&P_OUT_OF_MAP) |
| 186 |
&& !OB_TYPE_MOVE_BLOCK(op, GET_MAP_MOVE_BLOCK(m1, x1, y1))) |
| 187 |
break; |
| 188 |
} |
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
if (retry == 2) { |
| 193 |
stop_projectile(op); |
| 194 |
return METHOD_OK; |
| 195 |
} |
| 196 |
|
| 197 |
|
| 198 |
if (GET_ANIM_ID(op)) |
| 199 |
object_update_turn_face(op); |
| 200 |
} |
| 201 |
} |
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
op->speed -= 0.05; |
| 207 |
if (op->speed < 0.05) { |
| 208 |
stop_projectile(op); |
| 209 |
return METHOD_OK; |
| 210 |
} |
| 211 |
|
| 212 |
|
| 213 |
object_remove(op); |
| 214 |
object_insert_in_map_at(op, m, op, 0, new_x, new_y); |
| 215 |
return METHOD_OK; |
| 216 |
} |
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
method_ret common_projectile_move_on(ob_methods *context, object *trap, object *victim, object *originator) { |
| 227 |
if (common_pre_ob_move_on(trap, victim, originator) == METHOD_ERROR) |
| 228 |
return METHOD_OK; |
| 229 |
if (trap->inv == NULL) { |
| 230 |
common_post_ob_move_on(trap, victim, originator); |
| 231 |
return METHOD_OK; |
| 232 |
} |
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
if ((QUERY_FLAG(victim, FLAG_ALIVE) && trap->speed) |
| 241 |
&& object_get_owner(trap) != victim) |
| 242 |
hit_with_arrow(trap, victim); |
| 243 |
common_post_ob_move_on(trap, victim, originator); |
| 244 |
return METHOD_OK; |
| 245 |
} |