ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/server/move.C
(Generate patch)

Comparing deliantra/server/server/move.C (file contents):
Revision 1.7 by root, Sun Sep 10 15:59:57 2006 UTC vs.
Revision 1.19 by root, Mon May 28 21:28:36 2007 UTC

1
2/* 1/*
3 * static char *rcsid_move_c = 2 * This file is part of Crossfire TRT, the Roguelike Realtime MORPG.
4 * "$Id: move.C,v 1.7 2006/09/10 15:59:57 root Exp $"; 3 *
4 * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Crossfire TRT team
5 * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team
6 * Copyright (©) 1992,2007 Frank Tore Johansen
7 *
8 * Crossfire TRT is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the Free
10 * Software Foundation; either version 2 of the License, or (at your option)
11 * any later version.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 * for more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with Crossfire TRT; if not, write to the Free Software Foundation, Inc. 51
20 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 *
22 * The authors can be reached via e-mail to <crossfire@schmorp.de>
5 */ 23 */
6
7/*
8 CrossFire, A Multiplayer game for X-windows
9
10 Copyright (C) 2002 Mark Wedel & Crossfire Development Team
11 Copyright (C) 1992 Frank Tore Johansen
12
13 This program is free software; you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by
15 the Free Software Foundation; either version 2 of the License, or
16 (at your option) any later version.
17
18 This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software
25 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26
27 The author can be reached via e-mail to crossfire-devel@real-time.com
28*/
29 24
30#include <global.h> 25#include <global.h>
31#ifndef __CEXTRACT__ 26#ifndef __CEXTRACT__
32# include <sproto.h> 27# include <sproto.h>
33#endif
34
35#ifdef COZY_SERVER
36// use a ptotoype
37extern int same_party (partylist *a, partylist *b);
38#endif 28#endif
39 29
40/* 30/*
41 * move_object() tries to move object op in the direction "dir". 31 * move_object() tries to move object op in the direction "dir".
42 * If it fails (something blocks the passage), it returns 0, 32 * If it fails (something blocks the passage), it returns 0,
48int 38int
49move_object (object *op, int dir) 39move_object (object *op, int dir)
50{ 40{
51 return move_ob (op, dir, op); 41 return move_ob (op, dir, op);
52} 42}
53
54 43
55/* object op is trying to move in direction dir. 44/* object op is trying to move in direction dir.
56 * originator is typically the same as op, but 45 * originator is typically the same as op, but
57 * can be different if originator is causing op to 46 * can be different if originator is causing op to
58 * move (originator is pushing op) 47 * move (originator is pushing op)
65move_ob (object *op, int dir, object *originator) 54move_ob (object *op, int dir, object *originator)
66{ 55{
67 sint16 newx = op->x + freearr_x[dir]; 56 sint16 newx = op->x + freearr_x[dir];
68 sint16 newy = op->y + freearr_y[dir]; 57 sint16 newy = op->y + freearr_y[dir];
69 object *tmp; 58 object *tmp;
70 mapstruct *m; 59 maptile *m;
71 int mflags; 60 int mflags;
72 61
73 if (op == NULL) 62 if (op == NULL)
74 { 63 {
75 LOG (llevError, "Trying to move NULL.\n"); 64 LOG (llevError, "Trying to move NULL.\n");
82 /* If the space the player is trying to is out of the map, 71 /* If the space the player is trying to is out of the map,
83 * bail now - we know it can't work. 72 * bail now - we know it can't work.
84 */ 73 */
85 if (mflags & P_OUT_OF_MAP) 74 if (mflags & P_OUT_OF_MAP)
86 return 0; 75 return 0;
87
88 76
89 /* Is this space blocked? Players with wizpass are immune to 77 /* Is this space blocked? Players with wizpass are immune to
90 * this condition. 78 * this condition.
91 */ 79 */
92 if (blocked_link (op, m, newx, newy) && !QUERY_FLAG (op, FLAG_WIZPASS)) 80 if (blocked_link (op, m, newx, newy) && !QUERY_FLAG (op, FLAG_WIZPASS))
94 82
95 /* 0.94.2 - we need to set the direction for the new animation code. 83 /* 0.94.2 - we need to set the direction for the new animation code.
96 * it uses it to figure out face to use - I can't see it 84 * it uses it to figure out face to use - I can't see it
97 * breaking anything, but it might. 85 * breaking anything, but it might.
98 */ 86 */
99 if (op->more != NULL && !move_ob (op->more, dir, op->more->head)) 87 if (op->more && !move_ob (op->more, dir, op->more->head))
100 return 0; 88 return 0;
101 89
102 op->direction = dir; 90 op->direction = dir;
103 91
104 if (op->will_apply & 4) 92 if (op->will_apply & 4)
105 check_earthwalls (op, m, newx, newy); 93 check_earthwalls (op, m, newx, newy);
94
106 if (op->will_apply & 8) 95 if (op->will_apply & 8)
107 check_doors (op, m, newx, newy); 96 check_doors (op, m, newx, newy);
108 97
109 /* 0.94.1 - I got a stack trace that showed it crash with remove_ob trying 98 /* 0.94.1 - I got a stack trace that showed it crash with remove_ob trying
110 * to remove a removed object, and this function was the culprit. A possible 99 * to remove a removed object, and this function was the culprit. A possible
127 * ok - the caller will deal with actual object removal/insertion 116 * ok - the caller will deal with actual object removal/insertion
128 */ 117 */
129 if (op->head) 118 if (op->head)
130 return 1; 119 return 1;
131 120
132 remove_ob (op); 121 if (m != op->map && op->contr)
122 {
123 if (INVOKE_MAP (LEAVE, op->map, ARG_PLAYER (op->contr)))
124 return 0;
125
126 op->remove ();
127
128 if (INVOKE_PLAYER (MAP_CHANGE, op->contr, ARG_MAP (m), ARG_INT (newx), ARG_INT (newy)))
129 return 0;
130
131 if (INVOKE_MAP (ENTER, m, ARG_PLAYER (op->contr), ARG_INT (newx), ARG_INT (newy)))
132 return 0;
133 }
134 else
135 op->remove ();
133 136
134 /* we already have newx, newy, and m, so lets use them. 137 /* we already have newx, newy, and m, so lets use them.
135 * In addition, this fixes potential crashes, because multipart object was 138 * In addition, this fixes potential crashes, because multipart object was
136 * on edge of map, +=x, +=y doesn't make correct coordinates. 139 * on edge of map, +=x, +=y doesn't make correct coordinates.
137 */ 140 */
175 if (i == -1) 178 if (i == -1)
176 return 0; /* No free spot */ 179 return 0; /* No free spot */
177 180
178 if (op->head != NULL) 181 if (op->head != NULL)
179 op = op->head; 182 op = op->head;
180 remove_ob (op); 183 op->remove ();
181 for (tmp = op; tmp != NULL; tmp = tmp->more) 184 for (tmp = op; tmp != NULL; tmp = tmp->more)
182 tmp->x = x + freearr_x[i] + (tmp->arch == NULL ? 0 : tmp->arch->clone.x), 185 tmp->x = x + freearr_x[i] + (tmp->arch == NULL ? 0 : tmp->arch->clone.x),
183 tmp->y = y + freearr_y[i] + (tmp->arch == NULL ? 0 : tmp->arch->clone.y); 186 tmp->y = y + freearr_y[i] + (tmp->arch == NULL ? 0 : tmp->arch->clone.y);
184 187
185 tmp = insert_ob_in_map (op, op->map, originator, 0); 188 tmp = insert_ob_in_map (op, op->map, originator, 0);
205teleport (object *teleporter, uint8 tele_type, object *user) 208teleport (object *teleporter, uint8 tele_type, object *user)
206{ 209{
207 object *altern; 210 object *altern;
208 int i, j, k, nrofalt = 0; 211 int i, j, k, nrofalt = 0;
209 object *other_teleporter, *tmp; 212 object *other_teleporter, *tmp;
210 mapstruct *m; 213 maptile *m;
211 sint16 sx, sy; 214 sint16 sx, sy;
212 215
213 if (user == NULL) 216 if (user == NULL)
214 return 0; 217 return 0;
215 if (user->head != NULL) 218 if (user->head != NULL)
225 if (i == 0 && j == 0) 228 if (i == 0 && j == 0)
226 continue; 229 continue;
227 /* Perhaps this should be extended to support tiled maps */ 230 /* Perhaps this should be extended to support tiled maps */
228 if (OUT_OF_REAL_MAP (teleporter->map, teleporter->x + i, teleporter->y + j)) 231 if (OUT_OF_REAL_MAP (teleporter->map, teleporter->x + i, teleporter->y + j))
229 continue; 232 continue;
230 other_teleporter = get_map_ob (teleporter->map, teleporter->x + i, teleporter->y + j); 233 other_teleporter = GET_MAP_OB (teleporter->map, teleporter->x + i, teleporter->y + j);
231 234
232 while (other_teleporter) 235 while (other_teleporter)
233 { 236 {
234 if (other_teleporter->type == tele_type) 237 if (other_teleporter->type == tele_type)
235 break; 238 break;
278 } 281 }
279 else 282 else
280 return 0; 283 return 0;
281 } 284 }
282 285
283 remove_ob (user); 286 user->remove ();
284 287
285 /* Update location for the object */ 288 /* Update location for the object */
286 for (tmp = user; tmp != NULL; tmp = tmp->more) 289 for (tmp = user; tmp != NULL; tmp = tmp->more)
287 { 290 {
288 tmp->x = other_teleporter->x + freearr_x[k] + (tmp->arch == NULL ? 0 : tmp->arch->clone.x); 291 tmp->x = other_teleporter->x + freearr_x[k] + (tmp->arch == NULL ? 0 : tmp->arch->clone.x);
313 * This is currently only used for the boulder roll code. 316 * This is currently only used for the boulder roll code.
314 * Returns 1 if object does not fit, 0 if it does. 317 * Returns 1 if object does not fit, 0 if it does.
315 */ 318 */
316 319
317int 320int
318try_fit (object *op, mapstruct *m, int x, int y) 321try_fit (object *op, maptile *m, int x, int y)
319{ 322{
320 object *tmp, *more; 323 object *tmp, *more;
321 sint16 tx, ty; 324 sint16 tx, ty;
322 int mflags; 325 int mflags;
323 mapstruct *m2; 326 maptile *m2;
324 327
325 if (op->head) 328 if (op->head)
326 op = op->head; 329 op = op->head;
327 330
328 for (more = op; more; more = more->more) 331 for (more = op; more; more = more->more)
333 mflags = get_map_flags (m, &m2, tx, ty, &tx, &ty); 336 mflags = get_map_flags (m, &m2, tx, ty, &tx, &ty);
334 337
335 if (mflags & P_OUT_OF_MAP) 338 if (mflags & P_OUT_OF_MAP)
336 return 1; 339 return 1;
337 340
338 for (tmp = get_map_ob (m2, tx, ty); tmp; tmp = tmp->above) 341 for (tmp = GET_MAP_OB (m2, tx, ty); tmp; tmp = tmp->above)
339 { 342 {
340 if (tmp->head == op || tmp == op) 343 if (tmp->head == op || tmp == op)
341 continue; 344 continue;
342 345
343 if ((QUERY_FLAG (tmp, FLAG_ALIVE) && tmp->type != DOOR)) 346 if ((QUERY_FLAG (tmp, FLAG_ALIVE) && tmp->type != DOOR))
361roll_ob (object *op, int dir, object *pusher) 364roll_ob (object *op, int dir, object *pusher)
362{ 365{
363 object *tmp; 366 object *tmp;
364 sint16 x, y; 367 sint16 x, y;
365 int flags; 368 int flags;
366 mapstruct *m; 369 maptile *m;
367 MoveType move_block; 370 MoveType move_block;
368 371
369 if (op->head) 372 if (op->head)
370 op = op->head; 373 op = op->head;
371 374
384 move_block = GET_MAP_MOVE_BLOCK (m, x, y); 387 move_block = GET_MAP_MOVE_BLOCK (m, x, y);
385 388
386 /* If the target space is not blocked, no need to look at the objects on it */ 389 /* If the target space is not blocked, no need to look at the objects on it */
387 if ((op->move_type & move_block) == op->move_type) 390 if ((op->move_type & move_block) == op->move_type)
388 { 391 {
389 for (tmp = get_map_ob (m, x, y); tmp != NULL; tmp = tmp->above) 392 for (tmp = GET_MAP_OB (m, x, y); tmp != NULL; tmp = tmp->above)
390 { 393 {
391 if (tmp->head == op) 394 if (tmp->head == op)
392 continue; 395 continue;
393 if (OB_MOVE_BLOCK (op, tmp) && !roll_ob (tmp, dir, pusher)) 396 if (OB_MOVE_BLOCK (op, tmp) && !roll_ob (tmp, dir, pusher))
394 return 0; 397 return 0;
395 } 398 }
396 } 399 }
397 if (try_fit (op, m, x, y)) 400 if (try_fit (op, m, x, y))
398 return 0; 401 return 0;
399 402
400 remove_ob (op); 403 op->remove ();
401 for (tmp = op; tmp != NULL; tmp = tmp->more) 404 for (tmp = op; tmp != NULL; tmp = tmp->more)
402 tmp->x += freearr_x[dir], tmp->y += freearr_y[dir]; 405 tmp->x += freearr_x[dir], tmp->y += freearr_y[dir];
403 insert_ob_in_map (op, op->map, pusher, 0); 406 insert_ob_in_map (op, op->map, pusher, 0);
404 return 1; 407 return 1;
405} 408}
411 int str1, str2; 414 int str1, str2;
412 object *owner; 415 object *owner;
413 416
414 if (who->head != NULL) 417 if (who->head != NULL)
415 who = who->head; 418 who = who->head;
416 owner = get_owner (who); 419 owner = who->owner;
417 420
418 /* Wake up sleeping monsters that may be pushed */ 421 /* Wake up sleeping monsters that may be pushed */
419 CLEAR_FLAG (who, FLAG_SLEEP); 422 CLEAR_FLAG (who, FLAG_SLEEP);
420 423
421 /* player change place with his pets or summoned creature */ 424 /* player change place with his pets or summoned creature */
422 /* TODO: allow multi arch pushing. Can't be very difficult */ 425 /* TODO: allow multi arch pushing. Can't be very difficult */
423 if (who->more == NULL 426 if (who->more == NULL
424#ifdef COZY_SERVER
425 && ((owner && owner->contr && pusher->contr && same_party (owner->contr->party, pusher->contr->party)) || owner == pusher) 427 && ((owner && owner->contr && pusher->contr && same_party (owner->contr->party, pusher->contr->party))
426#else
427 && owner == pusher 428 || owner == pusher)
428#endif
429 ) 429 )
430 { 430 {
431 int temp; 431 int temp;
432 mapstruct *m; 432 maptile *m;
433 433
434 remove_ob (who); 434 who->remove ();
435 remove_ob (pusher); 435 pusher->remove ();
436 temp = pusher->x; 436 temp = pusher->x;
437 pusher->x = who->x; 437 pusher->x = who->x;
438 who->x = temp; 438 who->x = temp;
439 439
440 temp = pusher->y; 440 temp = pusher->y;
447 447
448 insert_ob_in_map (who, who->map, pusher, 0); 448 insert_ob_in_map (who, who->map, pusher, 0);
449 insert_ob_in_map (pusher, pusher->map, pusher, 0); 449 insert_ob_in_map (pusher, pusher->map, pusher, 0);
450 return 0; 450 return 0;
451 } 451 }
452
453 452
454 /* We want ONLY become enemy of evil, unaggressive monster. We must RUN in them */ 453 /* We want ONLY become enemy of evil, unaggressive monster. We must RUN in them */
455 /* In original we have here a unaggressive check only - that was the reason why */ 454 /* In original we have here a unaggressive check only - that was the reason why */
456 /* we so often become an enemy of friendly monsters... */ 455 /* we so often become an enemy of friendly monsters... */
457 /* funny: was they set to unaggressive 0 (= not so nice) they don't attack */ 456 /* funny: was they set to unaggressive 0 (= not so nice) they don't attack */
458
459 if (owner != pusher && pusher->type == PLAYER && who->type != PLAYER && 457 if (owner != pusher && pusher->type == PLAYER && who->type != PLAYER &&
460 !QUERY_FLAG (who, FLAG_FRIENDLY) && !QUERY_FLAG (who, FLAG_NEUTRAL)) 458 !QUERY_FLAG (who, FLAG_FRIENDLY) && !QUERY_FLAG (who, FLAG_NEUTRAL))
461 { 459 {
462 if (pusher->contr->run_on) /* only when we run */ 460 if (pusher->contr->run_on) /* only when we run */
463 { 461 {
464 new_draw_info_format (NDI_UNIQUE, 0, pusher, "You start to attack %s !!", &who->name); 462 new_draw_info_format (NDI_UNIQUE, 0, pusher, "You start to attack %s!!", &who->name);
465 CLEAR_FLAG (who, FLAG_UNAGGRESSIVE); /* the sucker don't like you anymore */ 463 CLEAR_FLAG (who, FLAG_UNAGGRESSIVE); /* the sucker don't like you anymore */
466 who->enemy = pusher; 464 who->enemy = pusher;
467 return 1; 465 return 1;
468 } 466 }
469 else 467 else
470 {
471 new_draw_info_format (NDI_UNIQUE, 0, pusher, "You avoid attacking %s.", &who->name); 468 new_draw_info_format (NDI_UNIQUE, 0, pusher, "You avoid attacking %s.", &who->name);
472 }
473 } 469 }
474 470
475 /* now, lets test stand still. we NEVER can push stand_still monsters. */ 471 /* now, lets test stand still. we NEVER can push stand_still monsters. */
476 if (QUERY_FLAG (who, FLAG_STAND_STILL)) 472 if (QUERY_FLAG (who, FLAG_STAND_STILL))
477 { 473 {
487 */ 483 */
488 484
489 str1 = (who->stats.Str > 0 ? who->stats.Str : who->level); 485 str1 = (who->stats.Str > 0 ? who->stats.Str : who->level);
490 str2 = (pusher->stats.Str > 0 ? pusher->stats.Str : pusher->level); 486 str2 = (pusher->stats.Str > 0 ? pusher->stats.Str : pusher->level);
491 if (QUERY_FLAG (who, FLAG_WIZ) || 487 if (QUERY_FLAG (who, FLAG_WIZ) ||
492 random_roll (str1, str1 / 2 + str1 * 2, who, PREFER_HIGH) >= 488 random_roll (str1, str1 * 5 / 2, who, PREFER_HIGH) >=
493 random_roll (str2, str2 / 2 + str2 * 2, pusher, PREFER_HIGH) || !move_object (who, dir)) 489 random_roll (str2, str2 * 5 / 2, pusher, PREFER_HIGH) || !move_object (who, dir))
494 { 490 {
495 if (who->type == PLAYER) 491 if (who->type == PLAYER)
496 {
497 new_draw_info_format (NDI_UNIQUE, 0, who, "%s tried to push you.", &pusher->name); 492 new_draw_info_format (NDI_UNIQUE, 0, who, "%s tried to push you.", &pusher->name);
498 } 493
499 return 0; 494 return 0;
500 } 495 }
501 496
502 /* If we get here, the push succeeded. 497 /* If we get here, the push succeeded.
503 * Let everyone know the status. 498 * Let everyone know the status.

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines