1 | /* |
1 | /* |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
3 | * |
3 | * |
4 | * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
4 | * Copyright (©) 2005,2006,2007,2008,2009,2010,2011,2012 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team |
5 | * Copyright (©) 2002 Mark Wedel & Crossfire Development Team |
6 | * Copyright (©) 1992,2007 Frank Tore Johansen |
6 | * Copyright (©) 1992 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 | |
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 | |
|
|
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]; |
61 | sint16 newy = y + freearr_y[dir]; |
34 | sint16 newy = y + freearr_y[dir]; |
… | |
… | |
102 | if (INVOKE_MAP (LEAVE, map, ARG_PLAYER (contr))) |
75 | if (INVOKE_MAP (LEAVE, map, ARG_PLAYER (contr))) |
103 | return 0; |
76 | return 0; |
104 | |
77 | |
105 | remove (); |
78 | remove (); |
106 | |
79 | |
|
|
80 | pos.m->activate (); |
|
|
81 | |
107 | if (INVOKE_PLAYER (MAP_CHANGE, contr, ARG_MAP (pos.m), ARG_INT (pos.x), ARG_INT (pos.y))) |
82 | if (INVOKE_PLAYER (MAP_CHANGE, contr, ARG_MAP (pos.m), ARG_INT (pos.x), ARG_INT (pos.y))) |
108 | return 0; |
83 | return 0; |
109 | |
84 | |
110 | if (INVOKE_MAP (ENTER, pos.m, ARG_PLAYER (contr), ARG_INT (pos.x), ARG_INT (pos.y))) |
85 | if (INVOKE_MAP (ENTER, pos.m, ARG_PLAYER (contr), ARG_INT (pos.x), ARG_INT (pos.y))) |
111 | return 0; |
86 | return 0; |
… | |
… | |
131 | |
106 | |
132 | int |
107 | int |
133 | transfer_ob (object *op, int x, int y, int randomly, object *originator) |
108 | transfer_ob (object *op, int x, int y, int randomly, object *originator) |
134 | { |
109 | { |
135 | int i; |
110 | int i; |
136 | object *tmp; |
|
|
137 | |
111 | |
138 | if (randomly) |
112 | if (randomly) |
139 | i = find_free_spot (op, op->map, x, y, 0, SIZEOFFREE); |
113 | i = find_free_spot (op, op->map, x, y, 0, SIZEOFFREE); |
140 | else |
114 | else |
141 | i = find_first_free_spot (op, op->map, x, y); |
115 | i = find_first_free_spot (op, op->map, x, y); |
… | |
… | |
182 | |
156 | |
183 | /* Find all other teleporters within range. This range |
157 | /* Find all other teleporters within range. This range |
184 | * should really be setable by some object attribute instead of |
158 | * should really be setable by some object attribute instead of |
185 | * using hard coded values. |
159 | * using hard coded values. |
186 | */ |
160 | */ |
187 | unordered_mapwalk (teleporter, -5, -5, 5, 5) |
161 | unordered_mapwalk (mapwalk_buf, teleporter, -5, -5, 5, 5) |
188 | { |
162 | { |
189 | mapspace &ms = m->at (nx, ny); |
163 | mapspace &ms = m->at (nx, ny); |
190 | |
164 | |
191 | for (object *tmp = ms.top; tmp; tmp = tmp->below) |
165 | for (object *tmp = ms.top; tmp; tmp = tmp->below) |
192 | if (tmp->type == tele_type) |
166 | if (tmp->type == tele_type) |
… | |
… | |
203 | LOG (llevError, "%s: no alternative teleporters around (user %s).\n", |
177 | LOG (llevError, "%s: no alternative teleporters around (user %s).\n", |
204 | teleporter->debug_desc (), user->debug_desc ()); |
178 | teleporter->debug_desc (), user->debug_desc ()); |
205 | return 0; |
179 | return 0; |
206 | } |
180 | } |
207 | |
181 | |
208 | int k = find_free_spot (user, other_teleporter->map, other_teleporter->x, other_teleporter->y, 1, 9); |
182 | int k = find_free_spot (user, other_teleporter->map, other_teleporter->x, other_teleporter->y, 1, SIZEOFFREE1 + 1); |
209 | |
183 | |
210 | /* if k==-1, unable to find a free spot. If this is shop |
184 | /* if k==-1, unable to find a free spot. If this is shop |
211 | * mat that the player is using, find someplace to move |
185 | * mat that the player is using, find someplace to move |
212 | * the player - otherwise, player can get trapped in the shops |
186 | * the player - otherwise, player can get trapped in the shops |
213 | * that appear in random dungeons. We basically just make |
187 | * that appear in random dungeons. We basically just make |
… | |
… | |
245 | return !other_teleporter->map->insert ( |
219 | return !other_teleporter->map->insert ( |
246 | user, other_teleporter->x + freearr_x[k], other_teleporter->y + freearr_y[k] |
220 | user, other_teleporter->x + freearr_x[k], other_teleporter->y + freearr_y[k] |
247 | ); |
221 | ); |
248 | } |
222 | } |
249 | |
223 | |
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 | (void) move_ob (pusher, dir, pusher); |
|
|
259 | new_draw_info_format (NDI_BLACK, 0, pusher, "You move the %s.", query_name (op)); |
|
|
260 | return; |
|
|
261 | } |
|
|
262 | |
|
|
263 | /* |
224 | /* |
264 | * This is a new version of blocked, this one handles objects |
225 | * This is a new version of blocked, this one handles objects |
265 | * that can be passed through by monsters with the CAN_PASS_THRU defined. |
226 | * that can be passed through by monsters with the CAN_PASS_THRU defined. |
266 | * |
227 | * |
267 | * very new version handles also multipart objects |
228 | * very new version handles also multipart objects |
268 | * This is currently only used for the boulder roll code. |
229 | * This is currently only used for the boulder roll code. |
269 | * Returns 1 if object does not fit, 0 if it does. |
230 | * Returns 1 if object does not fit, 0 if it does. |
270 | */ |
231 | */ |
271 | |
232 | static int |
272 | int |
|
|
273 | try_fit (object *op, maptile *m, int x, int y) |
233 | try_fit (object *op, maptile *m, int x, int y) |
274 | { |
234 | { |
275 | object *tmp, *more; |
235 | object *tmp, *more; |
276 | sint16 tx, ty; |
236 | sint16 tx, ty; |
277 | int mflags; |
237 | int mflags; |
… | |
… | |
293 | for (tmp = GET_MAP_OB (m2, tx, ty); tmp; tmp = tmp->above) |
253 | for (tmp = GET_MAP_OB (m2, tx, ty); tmp; tmp = tmp->above) |
294 | { |
254 | { |
295 | if (tmp->head == op || tmp == op) |
255 | if (tmp->head == op || tmp == op) |
296 | continue; |
256 | continue; |
297 | |
257 | |
298 | if ((QUERY_FLAG (tmp, FLAG_ALIVE) && tmp->type != DOOR)) |
258 | if ((tmp->flag [FLAG_ALIVE] && tmp->type != DOOR)) |
299 | return 1; |
259 | return 1; |
300 | |
260 | |
301 | if (OB_MOVE_BLOCK (op, tmp)) |
261 | if (OB_MOVE_BLOCK (op, tmp)) |
302 | return 1; |
262 | return 1; |
303 | |
263 | |
… | |
… | |
309 | /* |
269 | /* |
310 | * this is not perfect yet. |
270 | * this is not perfect yet. |
311 | * it does not roll objects behind multipart objects properly. |
271 | * it does not roll objects behind multipart objects properly. |
312 | * Support for rolling multipart objects is questionable. |
272 | * Support for rolling multipart objects is questionable. |
313 | */ |
273 | */ |
314 | int |
274 | static int |
315 | roll_ob (object *op, int dir, object *pusher) |
275 | roll_ob (object *op, int dir, object *pusher) |
316 | { |
276 | { |
317 | sint16 x, y; |
277 | sint16 x, y; |
318 | int flags; |
278 | int flags; |
319 | maptile *m; |
279 | maptile *m; |
… | |
… | |
323 | op = op->head; |
283 | op = op->head; |
324 | |
284 | |
325 | x = op->x + freearr_x[dir]; |
285 | x = op->x + freearr_x[dir]; |
326 | y = op->y + freearr_y[dir]; |
286 | y = op->y + freearr_y[dir]; |
327 | |
287 | |
328 | if (!QUERY_FLAG (op, FLAG_CAN_ROLL) |
288 | if (!op->flag [FLAG_CAN_ROLL] |
329 | || (op->weight && random_roll (0, op->weight / 50000 - 1, pusher, PREFER_LOW) |
289 | || (op->weight && random_roll (0, op->weight / 50000 - 1, pusher, PREFER_LOW) |
330 | > pusher->stats.Str)) |
290 | > pusher->stats.Str)) |
331 | return 0; |
291 | return 0; |
332 | |
292 | |
333 | m = op->map; |
293 | m = op->map; |
… | |
… | |
357 | op->move (dir); |
317 | op->move (dir); |
358 | |
318 | |
359 | return 1; |
319 | return 1; |
360 | } |
320 | } |
361 | |
321 | |
|
|
322 | void |
|
|
323 | recursive_roll (object *op, int dir, object *pusher) |
|
|
324 | { |
|
|
325 | if (!roll_ob (op, dir, pusher)) |
|
|
326 | { |
|
|
327 | new_draw_info_format (NDI_UNIQUE, 0, pusher, "You fail to push the %s.", query_name (op)); |
|
|
328 | return; |
|
|
329 | } |
|
|
330 | |
|
|
331 | pusher->move (dir); |
|
|
332 | new_draw_info_format (NDI_BLACK, 0, pusher, "You move the %s.", query_name (op)); |
|
|
333 | return; |
|
|
334 | } |
|
|
335 | |
362 | /* returns 1 if pushing invokes a attack, 0 when not */ |
336 | /* returns 1 if pushing invokes a attack, 0 when not */ |
363 | int |
337 | int |
364 | push_ob (object *who, int dir, object *pusher) |
338 | push_ob (object *who, int dir, object *pusher) |
365 | { |
339 | { |
366 | int str1, str2; |
340 | int str1, str2; |
… | |
… | |
369 | if (who->head != NULL) |
343 | if (who->head != NULL) |
370 | who = who->head; |
344 | who = who->head; |
371 | owner = who->owner; |
345 | owner = who->owner; |
372 | |
346 | |
373 | /* Wake up sleeping monsters that may be pushed */ |
347 | /* Wake up sleeping monsters that may be pushed */ |
374 | CLEAR_FLAG (who, FLAG_SLEEP); |
348 | who->clr_flag (FLAG_SLEEP); |
375 | |
349 | |
376 | /* player change place with his pets or summoned creature */ |
350 | /* player change place with his pets or summoned creature */ |
377 | /* TODO: allow multi arch pushing. Can't be very difficult */ |
351 | /* TODO: allow multi arch pushing. Can't be very difficult */ |
378 | if (who->more == NULL |
352 | if (who->more == NULL |
379 | && ((owner && owner->contr && pusher->contr && same_party (owner->contr->party, pusher->contr->party)) |
353 | && ((owner && owner->contr && pusher->contr && same_party (owner->contr->party, pusher->contr->party)) |
… | |
… | |
406 | /* We want ONLY become enemy of evil, unaggressive monster. We must RUN in them */ |
380 | /* We want ONLY become enemy of evil, unaggressive monster. We must RUN in them */ |
407 | /* In original we have here a unaggressive check only - that was the reason why */ |
381 | /* In original we have here a unaggressive check only - that was the reason why */ |
408 | /* we so often become an enemy of friendly monsters... */ |
382 | /* we so often become an enemy of friendly monsters... */ |
409 | /* funny: was they set to unaggressive 0 (= not so nice) they don't attack */ |
383 | /* funny: was they set to unaggressive 0 (= not so nice) they don't attack */ |
410 | if (owner != pusher && pusher->type == PLAYER && who->type != PLAYER && |
384 | if (owner != pusher && pusher->type == PLAYER && who->type != PLAYER && |
411 | !QUERY_FLAG (who, FLAG_FRIENDLY) && !QUERY_FLAG (who, FLAG_NEUTRAL)) |
385 | !who->flag [FLAG_FRIENDLY] && !who->flag [FLAG_NEUTRAL]) |
412 | { |
386 | { |
413 | if (pusher->contr->run_on) /* only when we run */ |
387 | if (pusher->contr->run_on) /* only when we run */ |
414 | { |
388 | { |
415 | new_draw_info_format (NDI_UNIQUE, 0, pusher, "You start to attack %s!!", &who->name); |
389 | new_draw_info_format (NDI_UNIQUE, 0, pusher, "You start to attack %s!!", &who->name); |
416 | CLEAR_FLAG (who, FLAG_UNAGGRESSIVE); /* the sucker don't like you anymore */ |
390 | who->clr_flag (FLAG_UNAGGRESSIVE); /* the sucker don't like you anymore */ |
417 | who->enemy = pusher; |
391 | who->enemy = pusher; |
418 | return 1; |
392 | return 1; |
419 | } |
393 | } |
420 | else |
394 | else |
421 | new_draw_info_format (NDI_UNIQUE, 0, pusher, "You avoid attacking %s.", &who->name); |
395 | 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); |
422 | } |
396 | } |
423 | |
397 | |
424 | /* now, lets test stand still. we NEVER can push stand_still monsters. */ |
398 | /* now, let's test stand still. we NEVER can push stand_still monsters. */ |
425 | if (QUERY_FLAG (who, FLAG_STAND_STILL)) |
399 | if (who->flag [FLAG_STAND_STILL]) |
426 | { |
400 | { |
427 | new_draw_info_format (NDI_UNIQUE, 0, pusher, "You can't push %s.", &who->name); |
401 | new_draw_info_format (NDI_UNIQUE, 0, pusher, "You can't push %s. H<You simply can't.>", &who->name); |
428 | return 0; |
402 | return 0; |
429 | } |
403 | } |
430 | |
404 | |
431 | /* This block is basically if you are pushing friendly but |
405 | /* This block is basically if you are pushing friendly but |
432 | * non pet creaturs. |
406 | * non pet creaturs. |
… | |
… | |
435 | * this pushes the other person away - its not a swap. |
409 | * this pushes the other person away - its not a swap. |
436 | */ |
410 | */ |
437 | |
411 | |
438 | str1 = (who->stats.Str > 0 ? who->stats.Str : who->level); |
412 | str1 = (who->stats.Str > 0 ? who->stats.Str : who->level); |
439 | str2 = (pusher->stats.Str > 0 ? pusher->stats.Str : pusher->level); |
413 | str2 = (pusher->stats.Str > 0 ? pusher->stats.Str : pusher->level); |
440 | if (QUERY_FLAG (who, FLAG_WIZ) || |
414 | if (who->flag [FLAG_WIZ] || |
441 | random_roll (str1, str1 * 5 / 2, who, PREFER_HIGH) >= |
415 | random_roll (str1, str1 * 5 / 2, who, PREFER_HIGH) >= |
442 | random_roll (str2, str2 * 5 / 2, pusher, PREFER_HIGH) || !move_object (who, dir)) |
416 | random_roll (str2, str2 * 5 / 2, pusher, PREFER_HIGH) || !who->move (dir)) |
443 | { |
417 | { |
444 | if (who->type == PLAYER) |
418 | if (who->type == PLAYER) |
445 | new_draw_info_format (NDI_UNIQUE, 0, who, "%s tried to push you.", &pusher->name); |
419 | new_draw_info_format (NDI_UNIQUE, 0, who, "%s tried to push you.", &pusher->name); |
446 | |
420 | |
447 | return 0; |
421 | return 0; |
… | |
… | |
449 | |
423 | |
450 | /* If we get here, the push succeeded. |
424 | /* If we get here, the push succeeded. |
451 | * Let everyone know the status. |
425 | * Let everyone know the status. |
452 | */ |
426 | */ |
453 | if (who->type == PLAYER) |
427 | if (who->type == PLAYER) |
454 | { |
|
|
455 | new_draw_info_format (NDI_UNIQUE, 0, who, "%s pushed you.", &pusher->name); |
428 | new_draw_info_format (NDI_UNIQUE, 0, who, "%s pushed you.", &pusher->name); |
456 | } |
429 | |
457 | if (pusher->type == PLAYER) |
430 | if (pusher->type == PLAYER) |
458 | { |
|
|
459 | new_draw_info_format (NDI_UNIQUE, 0, pusher, "You pushed %s back.", &who->name); |
431 | new_draw_info_format (NDI_UNIQUE, 0, pusher, "You pushed %s back.", &who->name); |
460 | } |
|
|
461 | |
432 | |
462 | return 1; |
433 | return 1; |
463 | } |
434 | } |