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.38 by root, Fri Mar 26 00:59:22 2010 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 Mark Wedel & Crossfire Development Team 6 * Copyright (©) 2002 Mark Wedel & Crossfire Development Team
6 * Copyright (©) 1992 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__
28#endif 29#endif
29 30
30int 31int
31object::move (int dir, object *originator) 32object::move (int dir, object *originator)
32{ 33{
33 sint16 newx = x + freearr_x[dir]; 34 sint16 newx = x + DIRX (dir);
34 sint16 newy = y + freearr_y[dir]; 35 sint16 newy = y + DIRY (dir);
35 36
36 mapxy pos (this); 37 mapxy pos (this);
37 pos.move (dir); 38 pos.move (dir);
38 39
39 /* 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,
75 if (INVOKE_MAP (LEAVE, map, ARG_PLAYER (contr))) 76 if (INVOKE_MAP (LEAVE, map, ARG_PLAYER (contr)))
76 return 0; 77 return 0;
77 78
78 remove (); 79 remove ();
79 80
81 pos.m->activate ();
82
80 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)))
81 return 0; 84 return 0;
82 85
83 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)))
84 return 0; 87 return 0;
104 107
105int 108int
106transfer_ob (object *op, int x, int y, int randomly, object *originator) 109transfer_ob (object *op, int x, int y, int randomly, object *originator)
107{ 110{
108 int i; 111 int i;
109 object *tmp;
110 112
111 if (randomly) 113 if (randomly)
112 i = find_free_spot (op, op->map, x, y, 0, SIZEOFFREE); 114 i = find_free_spot (op, op->map, x, y, 0, SIZEOFFREE);
113 else 115 else
114 i = find_first_free_spot (op, op->map, x, y); 116 i = find_first_free_spot (op, op->map, x, y);
119 op = op->head_ (); 121 op = op->head_ ();
120 op->remove (); 122 op->remove ();
121 123
122 for (object *tmp = op; tmp; tmp = tmp->more) 124 for (object *tmp = op; tmp; tmp = tmp->more)
123 { 125 {
124 tmp->x = x + freearr_x[i] + tmp->arch->x; 126 tmp->x = x + DIRX (i) + tmp->arch->x;
125 tmp->y = y + freearr_y[i] + tmp->arch->y; 127 tmp->y = y + DIRY (i) + tmp->arch->y;
126 } 128 }
127 129
128 op = insert_ob_in_map (op, op->map, originator, 0); 130 op = insert_ob_in_map (op, op->map, originator, 0);
129 131
130 return !op; 132 return !op;
176 LOG (llevError, "%s: no alternative teleporters around (user %s).\n", 178 LOG (llevError, "%s: no alternative teleporters around (user %s).\n",
177 teleporter->debug_desc (), user->debug_desc ()); 179 teleporter->debug_desc (), user->debug_desc ());
178 return 0; 180 return 0;
179 } 181 }
180 182
181 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);
182 184
183 /* 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
184 * mat that the player is using, find someplace to move 186 * mat that the player is using, find someplace to move
185 * the player - otherwise, player can get trapped in the shops 187 * the player - otherwise, player can get trapped in the shops
186 * that appear in random dungeons. We basically just make 188 * that appear in random dungeons. We basically just make
195 { 197 {
196 maptile *m; 198 maptile *m;
197 sint16 sx, sy; 199 sint16 sx, sy;
198 200
199 if (get_map_flags (other_teleporter->map, &m, 201 if (get_map_flags (other_teleporter->map, &m,
200 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)
201 continue; 203 continue;
202 204
203 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)))
204 break; 206 break;
205 } 207 }
214 else 216 else
215 return 0; 217 return 0;
216 } 218 }
217 219
218 return !other_teleporter->map->insert ( 220 return !other_teleporter->map->insert (
219 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)
220 ); 222 );
221} 223}
222 224
223/* 225/*
224 * This is a new version of blocked, this one handles objects 226 * This is a new version of blocked, this one handles objects
252 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)
253 { 255 {
254 if (tmp->head == op || tmp == op) 256 if (tmp->head == op || tmp == op)
255 continue; 257 continue;
256 258
257 if ((QUERY_FLAG (tmp, FLAG_ALIVE) && tmp->type != DOOR)) 259 if ((tmp->flag [FLAG_ALIVE] && tmp->type != DOOR))
258 return 1; 260 return 1;
259 261
260 if (OB_MOVE_BLOCK (op, tmp)) 262 if (OB_MOVE_BLOCK (op, tmp))
261 return 1; 263 return 1;
262 264
264 } 266 }
265 return 0; 267 return 0;
266} 268}
267 269
268/* 270/*
269 * this is not perfect yet. 271 * this is not perfect yet.
270 * it does not roll objects behind multipart objects properly. 272 * it does not roll objects behind multipart objects properly.
271 * Support for rolling multipart objects is questionable. 273 * Support for rolling multipart objects is questionable.
272 */ 274 */
273static int 275static int
274roll_ob (object *op, int dir, object *pusher) 276roll_ob (object *op, int dir, object *pusher)
279 MoveType move_block; 281 MoveType move_block;
280 282
281 if (op->head) 283 if (op->head)
282 op = op->head; 284 op = op->head;
283 285
284 x = op->x + freearr_x[dir]; 286 x = op->x + DIRX (dir);
285 y = op->y + freearr_y[dir]; 287 y = op->y + DIRY (dir);
286 288
287 if (!QUERY_FLAG (op, FLAG_CAN_ROLL) 289 if (!op->flag [FLAG_CAN_ROLL]
288 || (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)
289 > pusher->stats.Str)) 291 > pusher->stats.Str))
290 return 0; 292 return 0;
291 293
292 m = op->map; 294 m = op->map;
342 if (who->head != NULL) 344 if (who->head != NULL)
343 who = who->head; 345 who = who->head;
344 owner = who->owner; 346 owner = who->owner;
345 347
346 /* Wake up sleeping monsters that may be pushed */ 348 /* Wake up sleeping monsters that may be pushed */
347 CLEAR_FLAG (who, FLAG_SLEEP); 349 who->clr_flag (FLAG_SLEEP);
348 350
349 /* player change place with his pets or summoned creature */ 351 /* player change place with his pets or summoned creature */
350 /* TODO: allow multi arch pushing. Can't be very difficult */ 352 /* TODO: allow multi arch pushing. Can't be very difficult */
351 if (who->more == NULL 353 if (who->more == NULL
352 && ((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))
379 /* 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 */
380 /* 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 */
381 /* we so often become an enemy of friendly monsters... */ 383 /* we so often become an enemy of friendly monsters... */
382 /* 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 */
383 if (owner != pusher && pusher->type == PLAYER && who->type != PLAYER && 385 if (owner != pusher && pusher->type == PLAYER && who->type != PLAYER &&
384 !QUERY_FLAG (who, FLAG_FRIENDLY) && !QUERY_FLAG (who, FLAG_NEUTRAL)) 386 !who->flag [FLAG_FRIENDLY] && !who->flag [FLAG_NEUTRAL])
385 { 387 {
386 if (pusher->contr->run_on) /* only when we run */ 388 if (pusher->contr->run_on) /* only when we run */
387 { 389 {
388 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);
389 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 */
390 who->enemy = pusher; 392 who->enemy = pusher;
391 return 1; 393 return 1;
392 } 394 }
393 else 395 else
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); 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);
395 } 397 }
396 398
397 /* 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. */
398 if (QUERY_FLAG (who, FLAG_STAND_STILL)) 400 if (who->flag [FLAG_STAND_STILL])
399 { 401 {
400 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);
401 return 0; 403 return 0;
402 } 404 }
403 405
408 * this pushes the other person away - its not a swap. 410 * this pushes the other person away - its not a swap.
409 */ 411 */
410 412
411 str1 = (who->stats.Str > 0 ? who->stats.Str : who->level); 413 str1 = (who->stats.Str > 0 ? who->stats.Str : who->level);
412 str2 = (pusher->stats.Str > 0 ? pusher->stats.Str : pusher->level); 414 str2 = (pusher->stats.Str > 0 ? pusher->stats.Str : pusher->level);
413 if (QUERY_FLAG (who, FLAG_WIZ) || 415 if (who->flag [FLAG_WIZ] ||
414 random_roll (str1, str1 * 5 / 2, who, PREFER_HIGH) >= 416 random_roll (str1, str1 * 5 / 2, who, PREFER_HIGH) >=
415 random_roll (str2, str2 * 5 / 2, pusher, PREFER_HIGH) || !who->move (dir)) 417 random_roll (str2, str2 * 5 / 2, pusher, PREFER_HIGH) || !who->move (dir))
416 { 418 {
417 if (who->type == PLAYER) 419 if (who->type == PLAYER)
418 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);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines