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.32 by root, Mon Oct 12 14:00:59 2009 UTC vs.
Revision 1.50 by root, Sat Nov 17 23:40:04 2018 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 (©) 2017,2018 Marc Alexander Lehmann / the Deliantra team
4 * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team 5 * Copyright (©) 2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team 6 * Copyright (©) 2002 Mark Wedel & Crossfire Development Team
6 * Copyright (©) 1992,2007 Frank Tore Johansen 7 * Copyright (©) 1992 Frank Tore Johansen
7 * 8 *
8 * Deliantra is free software: you can redistribute it and/or modify it under 9 * 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 10 * 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 11 * Free Software Foundation, either version 3 of the License, or (at your
11 * option) any later version. 12 * option) any later version.
12 * 13 *
13 * This program is distributed in the hope that it will be useful, 14 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details. 17 * GNU General Public License for more details.
17 * 18 *
18 * You should have received a copy of the Affero GNU General Public License 19 * You should have received a copy of the Affero GNU General Public License
19 * and the GNU General Public License along with this program. If not, see 20 * and the GNU General Public License along with this program. If not, see
20 * <http://www.gnu.org/licenses/>. 21 * <http://www.gnu.org/licenses/>.
21 * 22 *
22 * The authors can be reached via e-mail to <support@deliantra.net> 23 * The authors can be reached via e-mail to <support@deliantra.net>
23 */ 24 */
24 25
25#include <global.h> 26#include <global.h>
26#ifndef __CEXTRACT__ 27#ifndef __CEXTRACT__
27# include <sproto.h> 28# include <sproto.h>
28#endif 29#endif
29 30
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 31int
59object::move (int dir, object *originator) 32object::move (int dir, object *originator)
60{ 33{
61 sint16 newx = x + freearr_x[dir]; 34 sint16 newx = x + DIRX (dir);
62 sint16 newy = y + freearr_y[dir]; 35 sint16 newy = y + DIRY (dir);
63 36
64 mapxy pos (this); 37 mapxy pos (this);
65 pos.move (dir); 38 pos.move (dir);
66 39
67 /* If the space the object is moving to is out of the map, 40 /* If the space the object is moving to is out of the map,
103 if (INVOKE_MAP (LEAVE, map, ARG_PLAYER (contr))) 76 if (INVOKE_MAP (LEAVE, map, ARG_PLAYER (contr)))
104 return 0; 77 return 0;
105 78
106 remove (); 79 remove ();
107 80
81 pos.m->activate ();
82
108 if (INVOKE_PLAYER (MAP_CHANGE, contr, ARG_MAP (pos.m), ARG_INT (pos.x), ARG_INT (pos.y))) 83 if (INVOKE_PLAYER (MAP_CHANGE, contr, ARG_MAP (pos.m), ARG_INT (pos.x), ARG_INT (pos.y)))
109 return 0; 84 return 0;
110 85
111 if (INVOKE_MAP (ENTER, pos.m, ARG_PLAYER (contr), ARG_INT (pos.x), ARG_INT (pos.y))) 86 if (INVOKE_MAP (ENTER, pos.m, ARG_PLAYER (contr), ARG_INT (pos.x), ARG_INT (pos.y)))
112 return 0; 87 return 0;
132 107
133int 108int
134transfer_ob (object *op, int x, int y, int randomly, object *originator) 109transfer_ob (object *op, int x, int y, int randomly, object *originator)
135{ 110{
136 int i; 111 int i;
137 object *tmp;
138 112
139 if (randomly) 113 if (randomly)
140 i = find_free_spot (op, op->map, x, y, 0, SIZEOFFREE); 114 i = find_free_spot (op, op->map, x, y, 0, SIZEOFFREE);
141 else 115 else
142 i = find_first_free_spot (op, op->map, x, y); 116 i = find_first_free_spot (op, op->map, x, y);
147 op = op->head_ (); 121 op = op->head_ ();
148 op->remove (); 122 op->remove ();
149 123
150 for (object *tmp = op; tmp; tmp = tmp->more) 124 for (object *tmp = op; tmp; tmp = tmp->more)
151 { 125 {
152 tmp->x = x + freearr_x[i] + tmp->arch->x; 126 tmp->x = x + DIRX (i) + tmp->arch->x;
153 tmp->y = y + freearr_y[i] + tmp->arch->y; 127 tmp->y = y + DIRY (i) + tmp->arch->y;
154 } 128 }
155 129
156 op = insert_ob_in_map (op, op->map, originator, 0); 130 op = insert_ob_in_map (op, op->map, originator, 0);
157 131
158 return !op; 132 return !op;
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
223 { 197 {
224 maptile *m; 198 maptile *m;
225 sint16 sx, sy; 199 sint16 sx, sy;
226 200
227 if (get_map_flags (other_teleporter->map, &m, 201 if (get_map_flags (other_teleporter->map, &m,
228 other_teleporter->x + freearr_x[k], other_teleporter->y + freearr_y[k], &sx, &sy) & P_OUT_OF_MAP) 202 other_teleporter->x + DIRX (k), other_teleporter->y + DIRY (k), &sx, &sy) & P_OUT_OF_MAP)
229 continue; 203 continue;
230 204
231 if (!OB_TYPE_MOVE_BLOCK (user, GET_MAP_MOVE_BLOCK (m, sx, sy))) 205 if (!OB_TYPE_MOVE_BLOCK (user, GET_MAP_MOVE_BLOCK (m, sx, sy)))
232 break; 206 break;
233 } 207 }
242 else 216 else
243 return 0; 217 return 0;
244 } 218 }
245 219
246 return !other_teleporter->map->insert ( 220 return !other_teleporter->map->insert (
247 user, other_teleporter->x + freearr_x[k], other_teleporter->y + freearr_y[k] 221 user, other_teleporter->x + DIRX (k), other_teleporter->y + DIRY (k)
248 ); 222 );
249}
250
251void
252recursive_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} 223}
264 224
265/* 225/*
266 * This is a new version of blocked, this one handles objects 226 * 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. 227 * that can be passed through by monsters with the CAN_PASS_THRU defined.
268 * 228 *
269 * very new version handles also multipart objects 229 * very new version handles also multipart objects
270 * This is currently only used for the boulder roll code. 230 * This is currently only used for the boulder roll code.
271 * Returns 1 if object does not fit, 0 if it does. 231 * Returns 1 if object does not fit, 0 if it does.
272 */ 232 */
273 233static int
274int
275try_fit (object *op, maptile *m, int x, int y) 234try_fit (object *op, maptile *m, int x, int y)
276{ 235{
277 object *tmp, *more; 236 object *tmp, *more;
278 sint16 tx, ty; 237 sint16 tx, ty;
279 int mflags; 238 int mflags;
295 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)
296 { 255 {
297 if (tmp->head == op || tmp == op) 256 if (tmp->head == op || tmp == op)
298 continue; 257 continue;
299 258
300 if ((QUERY_FLAG (tmp, FLAG_ALIVE) && tmp->type != DOOR)) 259 if ((tmp->flag [FLAG_ALIVE] && tmp->type != DOOR))
301 return 1; 260 return 1;
302 261
303 if (OB_MOVE_BLOCK (op, tmp)) 262 if (OB_MOVE_BLOCK (op, tmp))
304 return 1; 263 return 1;
305 264
307 } 266 }
308 return 0; 267 return 0;
309} 268}
310 269
311/* 270/*
312 * this is not perfect yet. 271 * this is not perfect yet.
313 * it does not roll objects behind multipart objects properly. 272 * it does not roll objects behind multipart objects properly.
314 * Support for rolling multipart objects is questionable. 273 * Support for rolling multipart objects is questionable.
315 */ 274 */
316int 275static int
317roll_ob (object *op, int dir, object *pusher) 276roll_ob (object *op, int dir, object *pusher)
318{ 277{
319 sint16 x, y; 278 sint16 x, y;
320 int flags; 279 int flags;
321 maptile *m; 280 maptile *m;
322 MoveType move_block; 281 MoveType move_block;
323 282
324 if (op->head) 283 if (op->head)
325 op = op->head; 284 op = op->head;
326 285
327 x = op->x + freearr_x[dir]; 286 x = op->x + DIRX (dir);
328 y = op->y + freearr_y[dir]; 287 y = op->y + DIRY (dir);
329 288
330 if (!QUERY_FLAG (op, FLAG_CAN_ROLL) 289 if (!op->flag [FLAG_CAN_ROLL]
331 || (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)
332 > pusher->stats.Str)) 291 > pusher->stats.Str))
333 return 0; 292 return 0;
334 293
335 m = op->map; 294 m = op->map;
359 op->move (dir); 318 op->move (dir);
360 319
361 return 1; 320 return 1;
362} 321}
363 322
323void
324recursive_roll (object *op, int dir, object *pusher)
325{
326 if (!roll_ob (op, dir, pusher))
327 {
328 new_draw_info_format (NDI_UNIQUE, 0, pusher, "You fail to push the %s.", query_name (op));
329 return;
330 }
331
332 pusher->move (dir);
333 new_draw_info_format (NDI_BLACK, 0, pusher, "You move the %s.", query_name (op));
334 return;
335}
336
364/* returns 1 if pushing invokes a attack, 0 when not */ 337/* returns 1 if pushing invokes a attack, 0 when not */
365int 338int
366push_ob (object *who, int dir, object *pusher) 339push_ob (object *who, int dir, object *pusher)
367{ 340{
368 int str1, str2; 341 int str1, str2;
371 if (who->head != NULL) 344 if (who->head != NULL)
372 who = who->head; 345 who = who->head;
373 owner = who->owner; 346 owner = who->owner;
374 347
375 /* Wake up sleeping monsters that may be pushed */ 348 /* Wake up sleeping monsters that may be pushed */
376 CLEAR_FLAG (who, FLAG_SLEEP); 349 who->clr_flag (FLAG_SLEEP);
377 350
378 /* player change place with his pets or summoned creature */ 351 /* player change place with his pets or summoned creature */
379 /* TODO: allow multi arch pushing. Can't be very difficult */ 352 /* TODO: allow multi arch pushing. Can't be very difficult */
380 if (who->more == NULL 353 if (who->more == NULL
381 && ((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))
408 /* 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 */
409 /* 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 */
410 /* we so often become an enemy of friendly monsters... */ 383 /* we so often become an enemy of friendly monsters... */
411 /* 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 */
412 if (owner != pusher && pusher->type == PLAYER && who->type != PLAYER && 385 if (owner != pusher && pusher->type == PLAYER && who->type != PLAYER &&
413 !QUERY_FLAG (who, FLAG_FRIENDLY) && !QUERY_FLAG (who, FLAG_NEUTRAL)) 386 !who->flag [FLAG_FRIENDLY] && !who->flag [FLAG_NEUTRAL])
414 { 387 {
415 if (pusher->contr->run_on) /* only when we run */ 388 if (pusher->contr->run_on) /* only when we run */
416 { 389 {
417 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);
418 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 */
419 who->enemy = pusher; 392 who->enemy = pusher;
420 return 1; 393 return 1;
421 } 394 }
422 else 395 else
423 new_draw_info_format (NDI_UNIQUE, 0, pusher, "You avoid attacking %s.", &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);
424 } 397 }
425 398
426 /* now, lets test stand still. we NEVER can push stand_still monsters. */ 399 /* now, let's test stand still. we NEVER can push stand_still monsters. */
427 if (QUERY_FLAG (who, FLAG_STAND_STILL)) 400 if (who->flag [FLAG_STAND_STILL])
428 { 401 {
429 new_draw_info_format (NDI_UNIQUE, 0, pusher, "You can't push %s.", &who->name); 402 new_draw_info_format (NDI_UNIQUE, 0, pusher, "You can't push %s. H<You simply can't.>", &who->name);
430 return 0; 403 return 0;
431 } 404 }
432 405
433 /* This block is basically if you are pushing friendly but 406 /* This block is basically if you are pushing friendly but
434 * non pet creaturs. 407 * non pet creaturs.
437 * this pushes the other person away - its not a swap. 410 * this pushes the other person away - its not a swap.
438 */ 411 */
439 412
440 str1 = (who->stats.Str > 0 ? who->stats.Str : who->level); 413 str1 = (who->stats.Str > 0 ? who->stats.Str : who->level);
441 str2 = (pusher->stats.Str > 0 ? pusher->stats.Str : pusher->level); 414 str2 = (pusher->stats.Str > 0 ? pusher->stats.Str : pusher->level);
442 if (QUERY_FLAG (who, FLAG_WIZ) || 415 if (who->flag [FLAG_WIZ] ||
443 random_roll (str1, str1 * 5 / 2, who, PREFER_HIGH) >= 416 random_roll (str1, str1 * 5 / 2, who, PREFER_HIGH) >=
444 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))
445 { 418 {
446 if (who->type == PLAYER) 419 if (who->type == PLAYER)
447 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);
448 421
449 return 0; 422 return 0;
451 424
452 /* If we get here, the push succeeded. 425 /* If we get here, the push succeeded.
453 * Let everyone know the status. 426 * Let everyone know the status.
454 */ 427 */
455 if (who->type == PLAYER) 428 if (who->type == PLAYER)
456 {
457 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);
458 } 430
459 if (pusher->type == PLAYER) 431 if (pusher->type == PLAYER)
460 {
461 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);
462 }
463 433
464 return 1; 434 return 1;
465} 435}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines