ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/server/move.C
Revision: 1.50
Committed: Sat Nov 17 23:40:04 2018 UTC (5 years, 5 months ago) by root
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD
Changes since 1.49: +1 -0 lines
Log Message:
copyright update 2018

File Contents

# Content
1 /*
2 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 *
4 * Copyright (©) 2017,2018 Marc Alexander Lehmann / 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
6 * Copyright (©) 2002 Mark Wedel & Crossfire Development Team
7 * Copyright (©) 1992 Frank Tore Johansen
8 *
9 * Deliantra is free software: you can redistribute it and/or modify it under
10 * the terms of the Affero GNU General Public License as published by the
11 * Free Software Foundation, either version 3 of the License, or (at your
12 * option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the Affero GNU General Public License
20 * and the GNU General Public License along with this program. If not, see
21 * <http://www.gnu.org/licenses/>.
22 *
23 * The authors can be reached via e-mail to <support@deliantra.net>
24 */
25
26 #include <global.h>
27 #ifndef __CEXTRACT__
28 # include <sproto.h>
29 #endif
30
31 int
32 object::move (int dir, object *originator)
33 {
34 sint16 newx = x + DIRX (dir);
35 sint16 newy = y + DIRY (dir);
36
37 mapxy pos (this);
38 pos.move (dir);
39
40 /* If the space the object is moving to is out of the map,
41 * bail now - we know it can't work.
42 */
43 if (!pos.normalise ())
44 return 0;
45
46 /* Is this space blocked? Players with wizpass are immune to
47 * this condition.
48 */
49 if (blocked_link (this, pos.m, pos.x, pos.y) && !flag [FLAG_WIZPASS])
50 return 0;
51
52 // check tail movability
53 if (more && !more->move (dir, more->head))
54 return 0;
55
56 /* we need to set the direction for the new animation code.
57 * it uses it to figure out face to use - I can't see it
58 * breaking anything, but it might.
59 */
60 direction = dir;
61
62 if (will_apply & 4)
63 check_earthwalls (this, pos.m, pos.x, pos.y);
64
65 if (will_apply & 8)
66 check_doors (this, pos.m, pos.x, pos.y);
67
68 /* If this is a tail portion, just want to tell caller that move is
69 * ok - the caller will deal with actual object removal/insertion
70 */
71 if (head)
72 return 1;
73
74 if (pos.m != map && contr)
75 {
76 if (INVOKE_MAP (LEAVE, map, ARG_PLAYER (contr)))
77 return 0;
78
79 remove ();
80
81 pos.m->activate ();
82
83 if (INVOKE_PLAYER (MAP_CHANGE, contr, ARG_MAP (pos.m), ARG_INT (pos.x), ARG_INT (pos.y)))
84 return 0;
85
86 if (INVOKE_MAP (ENTER, pos.m, ARG_PLAYER (contr), ARG_INT (pos.x), ARG_INT (pos.y)))
87 return 0;
88 }
89
90 /* insert_ob_in_map will deal with any tiling issues */
91 pos.insert (this, originator);
92
93 return 1;
94 }
95
96 /*
97 * transfer_ob(): Move an object (even linked objects) to another spot
98 * on the same map.
99 *
100 * Does nothing if there is no free spot.
101 *
102 * randomly: If true, use find_free_spot() to find the destination, otherwise
103 * use find_first_free_spot().
104 *
105 * Return value: 1 if object was destroyed, 0 otherwise.
106 */
107
108 int
109 transfer_ob (object *op, int x, int y, int randomly, object *originator)
110 {
111 int i;
112
113 if (randomly)
114 i = find_free_spot (op, op->map, x, y, 0, SIZEOFFREE);
115 else
116 i = find_first_free_spot (op, op->map, x, y);
117
118 if (i == -1)
119 return 0; /* No free spot */
120
121 op = op->head_ ();
122 op->remove ();
123
124 for (object *tmp = op; tmp; tmp = tmp->more)
125 {
126 tmp->x = x + DIRX (i) + tmp->arch->x;
127 tmp->y = y + DIRY (i) + tmp->arch->y;
128 }
129
130 op = insert_ob_in_map (op, op->map, originator, 0);
131
132 return !op;
133 }
134
135 /*
136 * Return value: 1 if object was destroyed, 0 otherwise.
137 * Modified so that instead of passing the 'originator' that had no
138 * real use, instead we pass the 'user' of the teleporter. All the
139 * callers know what they wanted to teleporter (move_teleporter or
140 * shop map code)
141 * tele_type is the type of teleporter we want to match against -
142 * currently, this is either set to SHOP_MAT or TELEPORTER.
143 * It is basically used so that shop_mats and normal teleporters can
144 * be used close to each other and not have the player put to the
145 * one of another type.
146 */
147 int
148 teleport (object *teleporter, uint8 tele_type, object *user)
149 {
150 if (!user)
151 return 0;
152
153 object *other_teleporter = 0;
154 int nrofalt = 0;
155
156 user = user->head_ ();
157
158 /* Find all other teleporters within range. This range
159 * should really be setable by some object attribute instead of
160 * using hard coded values.
161 */
162 unordered_mapwalk (mapwalk_buf, teleporter, -5, -5, 5, 5)
163 {
164 mapspace &ms = m->at (nx, ny);
165
166 for (object *tmp = ms.top; tmp; tmp = tmp->below)
167 if (tmp->type == tele_type)
168 {
169 if ((dx || dy) && !rndm (++nrofalt))
170 other_teleporter = tmp;
171
172 break;
173 }
174 }
175
176 if (!nrofalt)
177 {
178 LOG (llevError, "%s: no alternative teleporters around (user %s).\n",
179 teleporter->debug_desc (), user->debug_desc ());
180 return 0;
181 }
182
183 int k = find_free_spot (user, other_teleporter->map, other_teleporter->x, other_teleporter->y, 1, SIZEOFFREE1 + 1);
184
185 /* if k==-1, unable to find a free spot. If this is shop
186 * mat that the player is using, find someplace to move
187 * the player - otherwise, player can get trapped in the shops
188 * that appear in random dungeons. We basically just make
189 * sure the space isn't no pass (eg wall), and don't care
190 * about is alive.
191 */
192 if (k == -1)
193 {
194 if (tele_type == SHOP_MAT && user->is_player ())
195 {
196 for (k = 1; k < 9; k++)
197 {
198 maptile *m;
199 sint16 sx, sy;
200
201 if (get_map_flags (other_teleporter->map, &m,
202 other_teleporter->x + DIRX (k), other_teleporter->y + DIRY (k), &sx, &sy) & P_OUT_OF_MAP)
203 continue;
204
205 if (!OB_TYPE_MOVE_BLOCK (user, GET_MAP_MOVE_BLOCK (m, sx, sy)))
206 break;
207 }
208
209 if (k == 9)
210 {
211 LOG (llevError, "Shop mat %s (%d, %d) is in solid rock?\n",
212 &other_teleporter->name, other_teleporter->x, other_teleporter->y);
213 return 0;
214 }
215 }
216 else
217 return 0;
218 }
219
220 return !other_teleporter->map->insert (
221 user, other_teleporter->x + DIRX (k), other_teleporter->y + DIRY (k)
222 );
223 }
224
225 /*
226 * This is a new version of blocked, this one handles objects
227 * that can be passed through by monsters with the CAN_PASS_THRU defined.
228 *
229 * very new version handles also multipart objects
230 * This is currently only used for the boulder roll code.
231 * Returns 1 if object does not fit, 0 if it does.
232 */
233 static int
234 try_fit (object *op, maptile *m, int x, int y)
235 {
236 object *tmp, *more;
237 sint16 tx, ty;
238 int mflags;
239 maptile *m2;
240
241 if (op->head)
242 op = op->head;
243
244 for (more = op; more; more = more->more)
245 {
246 tx = x + more->x - op->x;
247 ty = y + more->y - op->y;
248
249 mflags = get_map_flags (m, &m2, tx, ty, &tx, &ty);
250
251 if (mflags & P_OUT_OF_MAP)
252 return 1;
253
254 for (tmp = GET_MAP_OB (m2, tx, ty); tmp; tmp = tmp->above)
255 {
256 if (tmp->head == op || tmp == op)
257 continue;
258
259 if ((tmp->flag [FLAG_ALIVE] && tmp->type != DOOR))
260 return 1;
261
262 if (OB_MOVE_BLOCK (op, tmp))
263 return 1;
264
265 }
266 }
267 return 0;
268 }
269
270 /*
271 * this is not perfect yet.
272 * it does not roll objects behind multipart objects properly.
273 * Support for rolling multipart objects is questionable.
274 */
275 static int
276 roll_ob (object *op, int dir, object *pusher)
277 {
278 sint16 x, y;
279 int flags;
280 maptile *m;
281 MoveType move_block;
282
283 if (op->head)
284 op = op->head;
285
286 x = op->x + DIRX (dir);
287 y = op->y + DIRY (dir);
288
289 if (!op->flag [FLAG_CAN_ROLL]
290 || (op->weight && random_roll (0, op->weight / 50000 - 1, pusher, PREFER_LOW)
291 > pusher->stats.Str))
292 return 0;
293
294 m = op->map;
295 flags = get_map_flags (m, &m, x, y, &x, &y);
296
297 if (flags & (P_OUT_OF_MAP | P_IS_ALIVE))
298 return 0;
299
300 move_block = GET_MAP_MOVE_BLOCK (m, x, y);
301
302 /* If the target space is not blocked, no need to look at the objects on it */
303 if ((op->move_type & move_block) == op->move_type)
304 {
305 for (object *tmp = GET_MAP_OB (m, x, y); tmp; tmp = tmp->above)
306 {
307 if (tmp->head == op)
308 continue;
309
310 if (OB_MOVE_BLOCK (op, tmp) && !roll_ob (tmp, dir, pusher))
311 return 0;
312 }
313 }
314
315 if (try_fit (op, m, x, y))
316 return 0;
317
318 op->move (dir);
319
320 return 1;
321 }
322
323 void
324 recursive_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
337 /* returns 1 if pushing invokes a attack, 0 when not */
338 int
339 push_ob (object *who, int dir, object *pusher)
340 {
341 int str1, str2;
342 object *owner;
343
344 if (who->head != NULL)
345 who = who->head;
346 owner = who->owner;
347
348 /* Wake up sleeping monsters that may be pushed */
349 who->clr_flag (FLAG_SLEEP);
350
351 /* player change place with his pets or summoned creature */
352 /* TODO: allow multi arch pushing. Can't be very difficult */
353 if (who->more == NULL
354 && ((owner && owner->contr && pusher->contr && same_party (owner->contr->party, pusher->contr->party))
355 || owner == pusher)
356 )
357 {
358 int temp;
359 maptile *m;
360
361 who->remove ();
362 pusher->remove ();
363 temp = pusher->x;
364 pusher->x = who->x;
365 who->x = temp;
366
367 temp = pusher->y;
368 pusher->y = who->y;
369 who->y = temp;
370
371 m = pusher->map;
372 pusher->map = who->map;
373 who->map = m;
374
375 insert_ob_in_map (who, who->map, pusher, 0);
376 insert_ob_in_map (pusher, pusher->map, pusher, 0);
377
378 return 0;
379 }
380
381 /* We want ONLY become enemy of evil, unaggressive monster. We must RUN in them */
382 /* In original we have here a unaggressive check only - that was the reason why */
383 /* we so often become an enemy of friendly monsters... */
384 /* funny: was they set to unaggressive 0 (= not so nice) they don't attack */
385 if (owner != pusher && pusher->type == PLAYER && who->type != PLAYER &&
386 !who->flag [FLAG_FRIENDLY] && !who->flag [FLAG_NEUTRAL])
387 {
388 if (pusher->contr->run_on) /* only when we run */
389 {
390 new_draw_info_format (NDI_UNIQUE, 0, pusher, "You start to attack %s!!", &who->name);
391 who->clr_flag (FLAG_UNAGGRESSIVE); /* the sucker don't like you anymore */
392 who->enemy = pusher;
393 return 1;
394 }
395 else
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);
397 }
398
399 /* now, let's test stand still. we NEVER can push stand_still monsters. */
400 if (who->flag [FLAG_STAND_STILL])
401 {
402 new_draw_info_format (NDI_UNIQUE, 0, pusher, "You can't push %s. H<You simply can't.>", &who->name);
403 return 0;
404 }
405
406 /* This block is basically if you are pushing friendly but
407 * non pet creaturs.
408 * It basically does a random strength comparision to
409 * determine if you can push someone around. Note that
410 * this pushes the other person away - its not a swap.
411 */
412
413 str1 = (who->stats.Str > 0 ? who->stats.Str : who->level);
414 str2 = (pusher->stats.Str > 0 ? pusher->stats.Str : pusher->level);
415 if (who->flag [FLAG_WIZ] ||
416 random_roll (str1, str1 * 5 / 2, who, PREFER_HIGH) >=
417 random_roll (str2, str2 * 5 / 2, pusher, PREFER_HIGH) || !who->move (dir))
418 {
419 if (who->type == PLAYER)
420 new_draw_info_format (NDI_UNIQUE, 0, who, "%s tried to push you.", &pusher->name);
421
422 return 0;
423 }
424
425 /* If we get here, the push succeeded.
426 * Let everyone know the status.
427 */
428 if (who->type == PLAYER)
429 new_draw_info_format (NDI_UNIQUE, 0, who, "%s pushed you.", &pusher->name);
430
431 if (pusher->type == PLAYER)
432 new_draw_info_format (NDI_UNIQUE, 0, pusher, "You pushed %s back.", &who->name);
433
434 return 1;
435 }