ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/server/move.C
Revision: 1.45
Committed: Fri Jan 27 22:00:40 2012 UTC (12 years, 3 months ago) by root
Content type: text/plain
Branch: MAIN
Changes since 1.44: +0 -1 lines
Log Message:
remove unused variables, kernel_panic

File Contents

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