… | |
… | |
3 | * |
3 | * |
4 | * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
4 | * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team |
5 | * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team |
6 | * Copyright (©) 1992,2007 Frank Tore Johansen |
6 | * Copyright (©) 1992,2007 Frank Tore Johansen |
7 | * |
7 | * |
8 | * Deliantra is free software: you can redistribute it and/or modify |
8 | * Deliantra is free software: you can redistribute it and/or modify it under |
9 | * it under the terms of the GNU General Public License as published by |
9 | * the terms of the Affero GNU General Public License as published by the |
10 | * the Free Software Foundation, either version 3 of the License, or |
10 | * Free Software Foundation, either version 3 of the License, or (at your |
11 | * (at your option) any later version. |
11 | * option) any later version. |
12 | * |
12 | * |
13 | * This program is distributed in the hope that it will be useful, |
13 | * This program is distributed in the hope that it will be useful, |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | * GNU General Public License for more details. |
16 | * GNU General Public License for more details. |
17 | * |
17 | * |
18 | * You should have received a copy of the GNU General Public License |
18 | * You should have received a copy of the Affero GNU General Public License |
19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
19 | * and the GNU General Public License along with this program. If not, see |
|
|
20 | * <http://www.gnu.org/licenses/>. |
20 | * |
21 | * |
21 | * The authors can be reached via e-mail to <support@deliantra.net> |
22 | * The authors can be reached via e-mail to <support@deliantra.net> |
22 | */ |
23 | */ |
23 | |
24 | |
24 | #include <global.h> |
25 | #include <global.h> |
25 | #ifndef __CEXTRACT__ |
26 | #ifndef __CEXTRACT__ |
26 | # include <sproto.h> |
27 | # include <sproto.h> |
27 | #endif |
28 | #endif |
28 | |
|
|
29 | /* |
|
|
30 | * move_object() tries to move object op in the direction "dir". |
|
|
31 | * If it fails (something blocks the passage), it returns 0, |
|
|
32 | * otherwise 1. |
|
|
33 | * This is an improvement from the previous move_ob(), which |
|
|
34 | * removed and inserted objects even if they were unable to move. |
|
|
35 | */ |
|
|
36 | int |
|
|
37 | move_object (object *op, int dir) |
|
|
38 | { |
|
|
39 | return op->move (dir); |
|
|
40 | } |
|
|
41 | |
|
|
42 | /* object op is trying to move in direction dir. |
|
|
43 | * originator is typically the same as op, but |
|
|
44 | * can be different if originator is causing op to |
|
|
45 | * move (originator is pushing op) |
|
|
46 | * returns 0 if the object is not able to move to the |
|
|
47 | * desired space, 1 otherwise (in which case we also |
|
|
48 | * move the object accordingly. This function is |
|
|
49 | * very similiar to move_object. |
|
|
50 | */ |
|
|
51 | int |
|
|
52 | move_ob (object *op, int dir, object *originator) |
|
|
53 | { |
|
|
54 | return op->move (dir, originator); |
|
|
55 | } |
|
|
56 | |
29 | |
57 | int |
30 | int |
58 | object::move (int dir, object *originator) |
31 | object::move (int dir, object *originator) |
59 | { |
32 | { |
60 | sint16 newx = x + freearr_x[dir]; |
33 | sint16 newx = x + freearr_x[dir]; |
… | |
… | |
182 | |
155 | |
183 | /* Find all other teleporters within range. This range |
156 | /* Find all other teleporters within range. This range |
184 | * should really be setable by some object attribute instead of |
157 | * should really be setable by some object attribute instead of |
185 | * using hard coded values. |
158 | * using hard coded values. |
186 | */ |
159 | */ |
187 | unordered_mapwalk (teleporter, -5, -5, 5, 5) |
160 | unordered_mapwalk (mapwalk_buf, teleporter, -5, -5, 5, 5) |
188 | { |
161 | { |
189 | mapspace &ms = m->at (nx, ny); |
162 | mapspace &ms = m->at (nx, ny); |
190 | |
163 | |
191 | for (object *tmp = ms.top; tmp; tmp = tmp->below) |
164 | for (object *tmp = ms.top; tmp; tmp = tmp->below) |
192 | if (tmp->type == tele_type) |
165 | if (tmp->type == tele_type) |
… | |
… | |
245 | return !other_teleporter->map->insert ( |
218 | return !other_teleporter->map->insert ( |
246 | 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] |
247 | ); |
220 | ); |
248 | } |
221 | } |
249 | |
222 | |
250 | void |
|
|
251 | recursive_roll (object *op, int dir, object *pusher) |
|
|
252 | { |
|
|
253 | if (!roll_ob (op, dir, pusher)) |
|
|
254 | { |
|
|
255 | new_draw_info_format (NDI_UNIQUE, 0, pusher, "You fail to push the %s.", query_name (op)); |
|
|
256 | return; |
|
|
257 | } |
|
|
258 | |
|
|
259 | move_ob (pusher, dir, pusher); |
|
|
260 | new_draw_info_format (NDI_BLACK, 0, pusher, "You move the %s.", query_name (op)); |
|
|
261 | return; |
|
|
262 | } |
|
|
263 | |
|
|
264 | /* |
223 | /* |
265 | * This is a new version of blocked, this one handles objects |
224 | * This is a new version of blocked, this one handles objects |
266 | * 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. |
267 | * |
226 | * |
268 | * very new version handles also multipart objects |
227 | * very new version handles also multipart objects |
269 | * This is currently only used for the boulder roll code. |
228 | * This is currently only used for the boulder roll code. |
270 | * Returns 1 if object does not fit, 0 if it does. |
229 | * Returns 1 if object does not fit, 0 if it does. |
271 | */ |
230 | */ |
272 | |
231 | static int |
273 | int |
|
|
274 | try_fit (object *op, maptile *m, int x, int y) |
232 | try_fit (object *op, maptile *m, int x, int y) |
275 | { |
233 | { |
276 | object *tmp, *more; |
234 | object *tmp, *more; |
277 | sint16 tx, ty; |
235 | sint16 tx, ty; |
278 | int mflags; |
236 | int mflags; |
… | |
… | |
310 | /* |
268 | /* |
311 | * this is not perfect yet. |
269 | * this is not perfect yet. |
312 | * it does not roll objects behind multipart objects properly. |
270 | * it does not roll objects behind multipart objects properly. |
313 | * Support for rolling multipart objects is questionable. |
271 | * Support for rolling multipart objects is questionable. |
314 | */ |
272 | */ |
315 | int |
273 | static int |
316 | roll_ob (object *op, int dir, object *pusher) |
274 | roll_ob (object *op, int dir, object *pusher) |
317 | { |
275 | { |
318 | sint16 x, y; |
276 | sint16 x, y; |
319 | int flags; |
277 | int flags; |
320 | maptile *m; |
278 | maptile *m; |
… | |
… | |
356 | return 0; |
314 | return 0; |
357 | |
315 | |
358 | op->move (dir); |
316 | op->move (dir); |
359 | |
317 | |
360 | 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; |
361 | } |
333 | } |
362 | |
334 | |
363 | /* returns 1 if pushing invokes a attack, 0 when not */ |
335 | /* returns 1 if pushing invokes a attack, 0 when not */ |
364 | int |
336 | int |
365 | push_ob (object *who, int dir, object *pusher) |
337 | push_ob (object *who, int dir, object *pusher) |
… | |
… | |
417 | 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 */ |
418 | who->enemy = pusher; |
390 | who->enemy = pusher; |
419 | return 1; |
391 | return 1; |
420 | } |
392 | } |
421 | else |
393 | else |
422 | 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); |
423 | } |
395 | } |
424 | |
396 | |
425 | /* 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. */ |
426 | if (QUERY_FLAG (who, FLAG_STAND_STILL)) |
398 | if (QUERY_FLAG (who, FLAG_STAND_STILL)) |
427 | { |
399 | { |
428 | 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); |
429 | return 0; |
401 | return 0; |
430 | } |
402 | } |
431 | |
403 | |
432 | /* This block is basically if you are pushing friendly but |
404 | /* This block is basically if you are pushing friendly but |
433 | * non pet creaturs. |
405 | * non pet creaturs. |
… | |
… | |
438 | |
410 | |
439 | str1 = (who->stats.Str > 0 ? who->stats.Str : who->level); |
411 | str1 = (who->stats.Str > 0 ? who->stats.Str : who->level); |
440 | str2 = (pusher->stats.Str > 0 ? pusher->stats.Str : pusher->level); |
412 | str2 = (pusher->stats.Str > 0 ? pusher->stats.Str : pusher->level); |
441 | if (QUERY_FLAG (who, FLAG_WIZ) || |
413 | if (QUERY_FLAG (who, FLAG_WIZ) || |
442 | random_roll (str1, str1 * 5 / 2, who, PREFER_HIGH) >= |
414 | random_roll (str1, str1 * 5 / 2, who, PREFER_HIGH) >= |
443 | 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)) |
444 | { |
416 | { |
445 | if (who->type == PLAYER) |
417 | if (who->type == PLAYER) |
446 | 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); |
447 | |
419 | |
448 | return 0; |
420 | return 0; |
… | |
… | |
450 | |
422 | |
451 | /* If we get here, the push succeeded. |
423 | /* If we get here, the push succeeded. |
452 | * Let everyone know the status. |
424 | * Let everyone know the status. |
453 | */ |
425 | */ |
454 | if (who->type == PLAYER) |
426 | if (who->type == PLAYER) |
455 | { |
|
|
456 | 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); |
457 | } |
428 | |
458 | if (pusher->type == PLAYER) |
429 | if (pusher->type == PLAYER) |
459 | { |
|
|
460 | 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); |
461 | } |
|
|
462 | |
431 | |
463 | return 1; |
432 | return 1; |
464 | } |
433 | } |