… | |
… | |
25 | #include <global.h> |
25 | #include <global.h> |
26 | #ifndef __CEXTRACT__ |
26 | #ifndef __CEXTRACT__ |
27 | # include <sproto.h> |
27 | # include <sproto.h> |
28 | #endif |
28 | #endif |
29 | |
29 | |
30 | /* |
|
|
31 | * move_object() tries to move object op in the direction "dir". |
|
|
32 | * If it fails (something blocks the passage), it returns 0, |
|
|
33 | * otherwise 1. |
|
|
34 | * This is an improvement from the previous move_ob(), which |
|
|
35 | * removed and inserted objects even if they were unable to move. |
|
|
36 | */ |
|
|
37 | int |
|
|
38 | move_object (object *op, int dir) |
|
|
39 | { |
|
|
40 | return op->move (dir); |
|
|
41 | } |
|
|
42 | |
|
|
43 | /* object op is trying to move in direction dir. |
|
|
44 | * originator is typically the same as op, but |
|
|
45 | * can be different if originator is causing op to |
|
|
46 | * move (originator is pushing op) |
|
|
47 | * returns 0 if the object is not able to move to the |
|
|
48 | * desired space, 1 otherwise (in which case we also |
|
|
49 | * move the object accordingly. This function is |
|
|
50 | * very similiar to move_object. |
|
|
51 | */ |
|
|
52 | int |
|
|
53 | move_ob (object *op, int dir, object *originator) |
|
|
54 | { |
|
|
55 | return op->move (dir, originator); |
|
|
56 | } |
|
|
57 | |
|
|
58 | int |
30 | int |
59 | object::move (int dir, object *originator) |
31 | object::move (int dir, object *originator) |
60 | { |
32 | { |
61 | sint16 newx = x + freearr_x[dir]; |
33 | sint16 newx = x + freearr_x[dir]; |
62 | sint16 newy = y + freearr_y[dir]; |
34 | sint16 newy = y + freearr_y[dir]; |
… | |
… | |
183 | |
155 | |
184 | /* Find all other teleporters within range. This range |
156 | /* Find all other teleporters within range. This range |
185 | * should really be setable by some object attribute instead of |
157 | * should really be setable by some object attribute instead of |
186 | * using hard coded values. |
158 | * using hard coded values. |
187 | */ |
159 | */ |
188 | unordered_mapwalk (teleporter, -5, -5, 5, 5) |
160 | unordered_mapwalk (mapwalk_buf, teleporter, -5, -5, 5, 5) |
189 | { |
161 | { |
190 | mapspace &ms = m->at (nx, ny); |
162 | mapspace &ms = m->at (nx, ny); |
191 | |
163 | |
192 | for (object *tmp = ms.top; tmp; tmp = tmp->below) |
164 | for (object *tmp = ms.top; tmp; tmp = tmp->below) |
193 | if (tmp->type == tele_type) |
165 | if (tmp->type == tele_type) |
… | |
… | |
246 | return !other_teleporter->map->insert ( |
218 | return !other_teleporter->map->insert ( |
247 | user, other_teleporter->x + freearr_x[k], other_teleporter->y + freearr_y[k] |
219 | user, other_teleporter->x + freearr_x[k], other_teleporter->y + freearr_y[k] |
248 | ); |
220 | ); |
249 | } |
221 | } |
250 | |
222 | |
251 | void |
|
|
252 | recursive_roll (object *op, int dir, object *pusher) |
|
|
253 | { |
|
|
254 | if (!roll_ob (op, dir, pusher)) |
|
|
255 | { |
|
|
256 | new_draw_info_format (NDI_UNIQUE, 0, pusher, "You fail to push the %s.", query_name (op)); |
|
|
257 | return; |
|
|
258 | } |
|
|
259 | |
|
|
260 | move_ob (pusher, dir, pusher); |
|
|
261 | new_draw_info_format (NDI_BLACK, 0, pusher, "You move the %s.", query_name (op)); |
|
|
262 | return; |
|
|
263 | } |
|
|
264 | |
|
|
265 | /* |
223 | /* |
266 | * This is a new version of blocked, this one handles objects |
224 | * This is a new version of blocked, this one handles objects |
267 | * that can be passed through by monsters with the CAN_PASS_THRU defined. |
225 | * that can be passed through by monsters with the CAN_PASS_THRU defined. |
268 | * |
226 | * |
269 | * very new version handles also multipart objects |
227 | * very new version handles also multipart objects |
270 | * This is currently only used for the boulder roll code. |
228 | * This is currently only used for the boulder roll code. |
271 | * Returns 1 if object does not fit, 0 if it does. |
229 | * Returns 1 if object does not fit, 0 if it does. |
272 | */ |
230 | */ |
273 | |
231 | static int |
274 | int |
|
|
275 | try_fit (object *op, maptile *m, int x, int y) |
232 | try_fit (object *op, maptile *m, int x, int y) |
276 | { |
233 | { |
277 | object *tmp, *more; |
234 | object *tmp, *more; |
278 | sint16 tx, ty; |
235 | sint16 tx, ty; |
279 | int mflags; |
236 | int mflags; |
… | |
… | |
311 | /* |
268 | /* |
312 | * this is not perfect yet. |
269 | * this is not perfect yet. |
313 | * it does not roll objects behind multipart objects properly. |
270 | * it does not roll objects behind multipart objects properly. |
314 | * Support for rolling multipart objects is questionable. |
271 | * Support for rolling multipart objects is questionable. |
315 | */ |
272 | */ |
316 | int |
273 | static int |
317 | roll_ob (object *op, int dir, object *pusher) |
274 | roll_ob (object *op, int dir, object *pusher) |
318 | { |
275 | { |
319 | sint16 x, y; |
276 | sint16 x, y; |
320 | int flags; |
277 | int flags; |
321 | maptile *m; |
278 | maptile *m; |
… | |
… | |
357 | return 0; |
314 | return 0; |
358 | |
315 | |
359 | op->move (dir); |
316 | op->move (dir); |
360 | |
317 | |
361 | return 1; |
318 | return 1; |
|
|
319 | } |
|
|
320 | |
|
|
321 | void |
|
|
322 | recursive_roll (object *op, int dir, object *pusher) |
|
|
323 | { |
|
|
324 | if (!roll_ob (op, dir, pusher)) |
|
|
325 | { |
|
|
326 | new_draw_info_format (NDI_UNIQUE, 0, pusher, "You fail to push the %s.", query_name (op)); |
|
|
327 | return; |
|
|
328 | } |
|
|
329 | |
|
|
330 | pusher->move (dir); |
|
|
331 | new_draw_info_format (NDI_BLACK, 0, pusher, "You move the %s.", query_name (op)); |
|
|
332 | return; |
362 | } |
333 | } |
363 | |
334 | |
364 | /* returns 1 if pushing invokes a attack, 0 when not */ |
335 | /* returns 1 if pushing invokes a attack, 0 when not */ |
365 | int |
336 | int |
366 | push_ob (object *who, int dir, object *pusher) |
337 | push_ob (object *who, int dir, object *pusher) |
… | |
… | |
418 | CLEAR_FLAG (who, FLAG_UNAGGRESSIVE); /* the sucker don't like you anymore */ |
389 | CLEAR_FLAG (who, FLAG_UNAGGRESSIVE); /* the sucker don't like you anymore */ |
419 | who->enemy = pusher; |
390 | who->enemy = pusher; |
420 | return 1; |
391 | return 1; |
421 | } |
392 | } |
422 | else |
393 | else |
423 | new_draw_info_format (NDI_UNIQUE, 0, pusher, "You avoid attacking %s.", &who->name); |
394 | new_draw_info_format (NDI_UNIQUE, 0, pusher, "You avoid attacking %s. H<You have to run if you wish to attack unnagressive NPCs.>", &who->name); |
424 | } |
395 | } |
425 | |
396 | |
426 | /* now, lets test stand still. we NEVER can push stand_still monsters. */ |
397 | /* now, let's test stand still. we NEVER can push stand_still monsters. */ |
427 | if (QUERY_FLAG (who, FLAG_STAND_STILL)) |
398 | if (QUERY_FLAG (who, FLAG_STAND_STILL)) |
428 | { |
399 | { |
429 | new_draw_info_format (NDI_UNIQUE, 0, pusher, "You can't push %s.", &who->name); |
400 | new_draw_info_format (NDI_UNIQUE, 0, pusher, "You can't push %s. H<You simply can't.>", &who->name); |
430 | return 0; |
401 | return 0; |
431 | } |
402 | } |
432 | |
403 | |
433 | /* This block is basically if you are pushing friendly but |
404 | /* This block is basically if you are pushing friendly but |
434 | * non pet creaturs. |
405 | * non pet creaturs. |
… | |
… | |
439 | |
410 | |
440 | str1 = (who->stats.Str > 0 ? who->stats.Str : who->level); |
411 | str1 = (who->stats.Str > 0 ? who->stats.Str : who->level); |
441 | str2 = (pusher->stats.Str > 0 ? pusher->stats.Str : pusher->level); |
412 | str2 = (pusher->stats.Str > 0 ? pusher->stats.Str : pusher->level); |
442 | if (QUERY_FLAG (who, FLAG_WIZ) || |
413 | if (QUERY_FLAG (who, FLAG_WIZ) || |
443 | random_roll (str1, str1 * 5 / 2, who, PREFER_HIGH) >= |
414 | random_roll (str1, str1 * 5 / 2, who, PREFER_HIGH) >= |
444 | random_roll (str2, str2 * 5 / 2, pusher, PREFER_HIGH) || !move_object (who, dir)) |
415 | random_roll (str2, str2 * 5 / 2, pusher, PREFER_HIGH) || !who->move (dir)) |
445 | { |
416 | { |
446 | if (who->type == PLAYER) |
417 | if (who->type == PLAYER) |
447 | new_draw_info_format (NDI_UNIQUE, 0, who, "%s tried to push you.", &pusher->name); |
418 | new_draw_info_format (NDI_UNIQUE, 0, who, "%s tried to push you.", &pusher->name); |
448 | |
419 | |
449 | return 0; |
420 | return 0; |
… | |
… | |
451 | |
422 | |
452 | /* If we get here, the push succeeded. |
423 | /* If we get here, the push succeeded. |
453 | * Let everyone know the status. |
424 | * Let everyone know the status. |
454 | */ |
425 | */ |
455 | if (who->type == PLAYER) |
426 | if (who->type == PLAYER) |
456 | { |
|
|
457 | new_draw_info_format (NDI_UNIQUE, 0, who, "%s pushed you.", &pusher->name); |
427 | new_draw_info_format (NDI_UNIQUE, 0, who, "%s pushed you.", &pusher->name); |
458 | } |
428 | |
459 | if (pusher->type == PLAYER) |
429 | if (pusher->type == PLAYER) |
460 | { |
|
|
461 | new_draw_info_format (NDI_UNIQUE, 0, pusher, "You pushed %s back.", &who->name); |
430 | new_draw_info_format (NDI_UNIQUE, 0, pusher, "You pushed %s back.", &who->name); |
462 | } |
|
|
463 | |
431 | |
464 | return 1; |
432 | return 1; |
465 | } |
433 | } |