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.34 by root, Sun Nov 15 19:13:01 2009 UTC vs.
Revision 1.44 by root, Tue Jan 3 11:25:36 2012 UTC

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 it under 8 * Deliantra is free software: you can redistribute it and/or modify it under
9 * the terms of the Affero GNU General Public License as published by the 9 * the terms of the Affero GNU General Public License as published by the
10 * Free Software Foundation, either version 3 of the License, or (at your 10 * Free Software Foundation, either version 3 of the License, or (at your
11 * option) any later version. 11 * option) any later version.
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 */
37int
38move_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 */
52int
53move_ob (object *op, int dir, object *originator)
54{
55 return op->move (dir, originator);
56}
57
58int 30int
59object::move (int dir, object *originator) 31object::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];
102 { 74 {
103 if (INVOKE_MAP (LEAVE, map, ARG_PLAYER (contr))) 75 if (INVOKE_MAP (LEAVE, map, ARG_PLAYER (contr)))
104 return 0; 76 return 0;
105 77
106 remove (); 78 remove ();
79
80 pos.m->activate ();
107 81
108 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)))
109 return 0; 83 return 0;
110 84
111 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)))
183 157
184 /* Find all other teleporters within range. This range 158 /* Find all other teleporters within range. This range
185 * should really be setable by some object attribute instead of 159 * should really be setable by some object attribute instead of
186 * using hard coded values. 160 * using hard coded values.
187 */ 161 */
188 unordered_mapwalk (teleporter, -5, -5, 5, 5) 162 unordered_mapwalk (mapwalk_buf, teleporter, -5, -5, 5, 5)
189 { 163 {
190 mapspace &ms = m->at (nx, ny); 164 mapspace &ms = m->at (nx, ny);
191 165
192 for (object *tmp = ms.top; tmp; tmp = tmp->below) 166 for (object *tmp = ms.top; tmp; tmp = tmp->below)
193 if (tmp->type == tele_type) 167 if (tmp->type == tele_type)
204 LOG (llevError, "%s: no alternative teleporters around (user %s).\n", 178 LOG (llevError, "%s: no alternative teleporters around (user %s).\n",
205 teleporter->debug_desc (), user->debug_desc ()); 179 teleporter->debug_desc (), user->debug_desc ());
206 return 0; 180 return 0;
207 } 181 }
208 182
209 int k = find_free_spot (user, other_teleporter->map, other_teleporter->x, other_teleporter->y, 1, 9); 183 int k = find_free_spot (user, other_teleporter->map, other_teleporter->x, other_teleporter->y, 1, SIZEOFFREE1 + 1);
210 184
211 /* if k==-1, unable to find a free spot. If this is shop 185 /* if k==-1, unable to find a free spot. If this is shop
212 * mat that the player is using, find someplace to move 186 * mat that the player is using, find someplace to move
213 * the player - otherwise, player can get trapped in the shops 187 * the player - otherwise, player can get trapped in the shops
214 * that appear in random dungeons. We basically just make 188 * that appear in random dungeons. We basically just make
280 for (tmp = GET_MAP_OB (m2, tx, ty); tmp; tmp = tmp->above) 254 for (tmp = GET_MAP_OB (m2, tx, ty); tmp; tmp = tmp->above)
281 { 255 {
282 if (tmp->head == op || tmp == op) 256 if (tmp->head == op || tmp == op)
283 continue; 257 continue;
284 258
285 if ((QUERY_FLAG (tmp, FLAG_ALIVE) && tmp->type != DOOR)) 259 if ((tmp->flag [FLAG_ALIVE] && tmp->type != DOOR))
286 return 1; 260 return 1;
287 261
288 if (OB_MOVE_BLOCK (op, tmp)) 262 if (OB_MOVE_BLOCK (op, tmp))
289 return 1; 263 return 1;
290 264
310 op = op->head; 284 op = op->head;
311 285
312 x = op->x + freearr_x[dir]; 286 x = op->x + freearr_x[dir];
313 y = op->y + freearr_y[dir]; 287 y = op->y + freearr_y[dir];
314 288
315 if (!QUERY_FLAG (op, FLAG_CAN_ROLL) 289 if (!op->flag [FLAG_CAN_ROLL]
316 || (op->weight && random_roll (0, op->weight / 50000 - 1, pusher, PREFER_LOW) 290 || (op->weight && random_roll (0, op->weight / 50000 - 1, pusher, PREFER_LOW)
317 > pusher->stats.Str)) 291 > pusher->stats.Str))
318 return 0; 292 return 0;
319 293
320 m = op->map; 294 m = op->map;
353 { 327 {
354 new_draw_info_format (NDI_UNIQUE, 0, pusher, "You fail to push the %s.", query_name (op)); 328 new_draw_info_format (NDI_UNIQUE, 0, pusher, "You fail to push the %s.", query_name (op));
355 return; 329 return;
356 } 330 }
357 331
358 move_ob (pusher, dir, pusher); 332 pusher->move (dir);
359 new_draw_info_format (NDI_BLACK, 0, pusher, "You move the %s.", query_name (op)); 333 new_draw_info_format (NDI_BLACK, 0, pusher, "You move the %s.", query_name (op));
360 return; 334 return;
361} 335}
362 336
363/* returns 1 if pushing invokes a attack, 0 when not */ 337/* returns 1 if pushing invokes a attack, 0 when not */
370 if (who->head != NULL) 344 if (who->head != NULL)
371 who = who->head; 345 who = who->head;
372 owner = who->owner; 346 owner = who->owner;
373 347
374 /* Wake up sleeping monsters that may be pushed */ 348 /* Wake up sleeping monsters that may be pushed */
375 CLEAR_FLAG (who, FLAG_SLEEP); 349 who->clr_flag (FLAG_SLEEP);
376 350
377 /* player change place with his pets or summoned creature */ 351 /* player change place with his pets or summoned creature */
378 /* TODO: allow multi arch pushing. Can't be very difficult */ 352 /* TODO: allow multi arch pushing. Can't be very difficult */
379 if (who->more == NULL 353 if (who->more == NULL
380 && ((owner && owner->contr && pusher->contr && same_party (owner->contr->party, pusher->contr->party)) 354 && ((owner && owner->contr && pusher->contr && same_party (owner->contr->party, pusher->contr->party))
407 /* We want ONLY become enemy of evil, unaggressive monster. We must RUN in them */ 381 /* We want ONLY become enemy of evil, unaggressive monster. We must RUN in them */
408 /* In original we have here a unaggressive check only - that was the reason why */ 382 /* In original we have here a unaggressive check only - that was the reason why */
409 /* we so often become an enemy of friendly monsters... */ 383 /* we so often become an enemy of friendly monsters... */
410 /* funny: was they set to unaggressive 0 (= not so nice) they don't attack */ 384 /* funny: was they set to unaggressive 0 (= not so nice) they don't attack */
411 if (owner != pusher && pusher->type == PLAYER && who->type != PLAYER && 385 if (owner != pusher && pusher->type == PLAYER && who->type != PLAYER &&
412 !QUERY_FLAG (who, FLAG_FRIENDLY) && !QUERY_FLAG (who, FLAG_NEUTRAL)) 386 !who->flag [FLAG_FRIENDLY] && !who->flag [FLAG_NEUTRAL])
413 { 387 {
414 if (pusher->contr->run_on) /* only when we run */ 388 if (pusher->contr->run_on) /* only when we run */
415 { 389 {
416 new_draw_info_format (NDI_UNIQUE, 0, pusher, "You start to attack %s!!", &who->name); 390 new_draw_info_format (NDI_UNIQUE, 0, pusher, "You start to attack %s!!", &who->name);
417 CLEAR_FLAG (who, FLAG_UNAGGRESSIVE); /* the sucker don't like you anymore */ 391 who->clr_flag (FLAG_UNAGGRESSIVE); /* the sucker don't like you anymore */
418 who->enemy = pusher; 392 who->enemy = pusher;
419 return 1; 393 return 1;
420 } 394 }
421 else 395 else
422 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); 396 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 } 397 }
424 398
425 /* now, let's test stand still. we NEVER can push stand_still monsters. */ 399 /* now, let's test stand still. we NEVER can push stand_still monsters. */
426 if (QUERY_FLAG (who, FLAG_STAND_STILL)) 400 if (who->flag [FLAG_STAND_STILL])
427 { 401 {
428 new_draw_info_format (NDI_UNIQUE, 0, pusher, "You can't push %s. H<You simply can't.>", &who->name); 402 new_draw_info_format (NDI_UNIQUE, 0, pusher, "You can't push %s. H<You simply can't.>", &who->name);
429 return 0; 403 return 0;
430 } 404 }
431 405
436 * this pushes the other person away - its not a swap. 410 * this pushes the other person away - its not a swap.
437 */ 411 */
438 412
439 str1 = (who->stats.Str > 0 ? who->stats.Str : who->level); 413 str1 = (who->stats.Str > 0 ? who->stats.Str : who->level);
440 str2 = (pusher->stats.Str > 0 ? pusher->stats.Str : pusher->level); 414 str2 = (pusher->stats.Str > 0 ? pusher->stats.Str : pusher->level);
441 if (QUERY_FLAG (who, FLAG_WIZ) || 415 if (who->flag [FLAG_WIZ] ||
442 random_roll (str1, str1 * 5 / 2, who, PREFER_HIGH) >= 416 random_roll (str1, str1 * 5 / 2, who, PREFER_HIGH) >=
443 random_roll (str2, str2 * 5 / 2, pusher, PREFER_HIGH) || !move_object (who, dir)) 417 random_roll (str2, str2 * 5 / 2, pusher, PREFER_HIGH) || !who->move (dir))
444 { 418 {
445 if (who->type == PLAYER) 419 if (who->type == PLAYER)
446 new_draw_info_format (NDI_UNIQUE, 0, who, "%s tried to push you.", &pusher->name); 420 new_draw_info_format (NDI_UNIQUE, 0, who, "%s tried to push you.", &pusher->name);
447 421
448 return 0; 422 return 0;
450 424
451 /* If we get here, the push succeeded. 425 /* If we get here, the push succeeded.
452 * Let everyone know the status. 426 * Let everyone know the status.
453 */ 427 */
454 if (who->type == PLAYER) 428 if (who->type == PLAYER)
455 {
456 new_draw_info_format (NDI_UNIQUE, 0, who, "%s pushed you.", &pusher->name); 429 new_draw_info_format (NDI_UNIQUE, 0, who, "%s pushed you.", &pusher->name);
457 } 430
458 if (pusher->type == PLAYER) 431 if (pusher->type == PLAYER)
459 {
460 new_draw_info_format (NDI_UNIQUE, 0, pusher, "You pushed %s back.", &who->name); 432 new_draw_info_format (NDI_UNIQUE, 0, pusher, "You pushed %s back.", &who->name);
461 }
462 433
463 return 1; 434 return 1;
464} 435}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines