1 | /* |
1 | /* |
2 | * This file is part of Crossfire TRT, the Roguelike Realtime MORPG. |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
3 | * |
3 | * |
4 | * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Crossfire TRT team |
4 | * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team |
5 | * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team |
6 | * Copyright (©) 1992,2007 Frank Tore Johansen |
6 | * Copyright (©) 1992,2007 Frank Tore Johansen |
7 | * |
7 | * |
8 | * Crossfire TRT is free software: you can redistribute it and/or modify |
8 | * Deliantra is free software: you can redistribute it and/or modify |
9 | * it under the terms of the GNU General Public License as published by |
9 | * it under the terms of the GNU General Public License as published by |
10 | * the Free Software Foundation, either version 3 of the License, or |
10 | * the Free Software Foundation, either version 3 of the License, or |
11 | * (at your option) any later version. |
11 | * (at your option) any later version. |
12 | * |
12 | * |
13 | * This program is distributed in the hope that it will be useful, |
13 | * This program is distributed in the hope that it will be useful, |
… | |
… | |
16 | * GNU General Public License for more details. |
16 | * GNU General Public License for more details. |
17 | * |
17 | * |
18 | * You should have received a copy of the GNU General Public License |
18 | * You should have received a copy of the GNU General Public License |
19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
20 | * |
20 | * |
21 | * The authors can be reached via e-mail to <crossfire@schmorp.de> |
21 | * The authors can be reached via e-mail to <support@deliantra.net> |
22 | */ |
22 | */ |
23 | |
23 | |
24 | #include <global.h> |
24 | #include <global.h> |
25 | #ifndef __CEXTRACT__ |
25 | #ifndef __CEXTRACT__ |
26 | # include <sproto.h> |
26 | # include <sproto.h> |
… | |
… | |
35 | */ |
35 | */ |
36 | |
36 | |
37 | int |
37 | int |
38 | move_object (object *op, int dir) |
38 | move_object (object *op, int dir) |
39 | { |
39 | { |
40 | return move_ob (op, dir, op); |
40 | return op->move (dir); |
41 | } |
41 | } |
42 | |
42 | |
43 | /* object op is trying to move in direction dir. |
43 | /* object op is trying to move in direction dir. |
44 | * originator is typically the same as op, but |
44 | * originator is typically the same as op, but |
45 | * can be different if originator is causing op to |
45 | * can be different if originator is causing op to |
… | |
… | |
50 | * very similiar to move_object. |
50 | * very similiar to move_object. |
51 | */ |
51 | */ |
52 | int |
52 | int |
53 | move_ob (object *op, int dir, object *originator) |
53 | move_ob (object *op, int dir, object *originator) |
54 | { |
54 | { |
|
|
55 | return op->move (dir, originator); |
|
|
56 | } |
|
|
57 | |
|
|
58 | int |
|
|
59 | object::move (int dir, object *originator) |
|
|
60 | { |
55 | sint16 newx = op->x + freearr_x[dir]; |
61 | sint16 newx = x + freearr_x[dir]; |
56 | sint16 newy = op->y + freearr_y[dir]; |
62 | sint16 newy = y + freearr_y[dir]; |
57 | object *tmp; |
63 | object *tmp; |
58 | maptile *m; |
64 | maptile *m; |
59 | int mflags; |
65 | int mflags; |
60 | |
66 | |
61 | if (op == NULL) |
|
|
62 | { |
|
|
63 | LOG (llevError, "Trying to move NULL.\n"); |
|
|
64 | return 0; |
|
|
65 | } |
|
|
66 | |
|
|
67 | m = op->map; |
67 | m = map; |
68 | mflags = get_map_flags (m, &m, newx, newy, &newx, &newy); |
68 | mflags = get_map_flags (m, &m, newx, newy, &newx, &newy); |
69 | |
69 | |
70 | /* If the space the player is trying to is out of the map, |
70 | /* If the space the player is trying to is out of the map, |
71 | * bail now - we know it can't work. |
71 | * bail now - we know it can't work. |
72 | */ |
72 | */ |
… | |
… | |
74 | return 0; |
74 | return 0; |
75 | |
75 | |
76 | /* Is this space blocked? Players with wizpass are immune to |
76 | /* Is this space blocked? Players with wizpass are immune to |
77 | * this condition. |
77 | * this condition. |
78 | */ |
78 | */ |
79 | if (blocked_link (op, m, newx, newy) && !QUERY_FLAG (op, FLAG_WIZPASS)) |
79 | if (blocked_link (this, m, newx, newy) && !flag [FLAG_WIZPASS]) |
80 | return 0; |
80 | return 0; |
81 | |
81 | |
82 | /* 0.94.2 - we need to set the direction for the new animation code. |
82 | /* 0.94.2 - we need to set the direction for the new animation code. |
83 | * it uses it to figure out face to use - I can't see it |
83 | * it uses it to figure out face to use - I can't see it |
84 | * breaking anything, but it might. |
84 | * breaking anything, but it might. |
85 | */ |
85 | */ |
86 | if (op->more && !move_ob (op->more, dir, op->more->head)) |
86 | if (more && !more->move (dir, more->head)) |
87 | return 0; |
87 | return 0; |
88 | |
88 | |
89 | op->direction = dir; |
89 | direction = dir; |
90 | |
90 | |
91 | if (op->will_apply & 4) |
91 | if (will_apply & 4) |
92 | check_earthwalls (op, m, newx, newy); |
92 | check_earthwalls (this, m, newx, newy); |
93 | |
93 | |
94 | if (op->will_apply & 8) |
94 | if (will_apply & 8) |
95 | check_doors (op, m, newx, newy); |
95 | check_doors (this, m, newx, newy); |
96 | |
96 | |
97 | /* 0.94.1 - I got a stack trace that showed it crash with remove_ob trying |
97 | /* 0.94.1 - I got a stack trace that showed it crash with remove_ob trying |
98 | * to remove a removed object, and this function was the culprit. A possible |
98 | * to remove a removed object, and this function was the culprit. A possible |
99 | * guess I have is that check_doors above ran into a trap, killing the |
99 | * guess I have is that check_doors above ran into a trap, killing the |
100 | * monster. |
100 | * monster. |
101 | * |
101 | * |
102 | * Unfortunately, it doesn't appear that the calling functions of move_object |
102 | * Unfortunately, it doesn't appear that the calling functions of move_object |
103 | * deal very well with op being killed, so all this might do is just |
103 | * deal very well with op being killed, so all this might do is just |
104 | * migrate the problem someplace else. |
104 | * migrate the problem someplace else. |
105 | */ |
105 | */ |
106 | |
106 | if (flag [FLAG_REMOVED])//D remove or fix? |
107 | if (QUERY_FLAG (op, FLAG_REMOVED)) |
|
|
108 | { |
107 | { |
109 | LOG (llevDebug, "move_object: monster has been removed - will not process further\n"); |
108 | LOG (llevDebug, "move_object: monster has been removed - will not process further\n"); |
110 | /* Was not successful, but don't want to try and move again */ |
109 | /* Was not successful, but don't want to try and move again */ |
111 | return 1; |
110 | return 1; |
112 | } |
111 | } |
113 | |
112 | |
114 | /* If this is a tail portion, just want to tell caller that move is |
113 | /* If this is a tail portion, just want to tell caller that move is |
115 | * ok - the caller will deal with actual object removal/insertion |
114 | * ok - the caller will deal with actual object removal/insertion |
116 | */ |
115 | */ |
117 | if (op->head) |
116 | if (head) |
118 | return 1; |
117 | return 1; |
119 | |
118 | |
120 | if (m != op->map && op->contr) |
119 | if (m != map && contr) |
121 | { |
120 | { |
122 | if (INVOKE_MAP (LEAVE, op->map, ARG_PLAYER (op->contr))) |
121 | if (INVOKE_MAP (LEAVE, map, ARG_PLAYER (contr))) |
123 | return 0; |
122 | return 0; |
124 | |
123 | |
125 | op->remove (); |
124 | remove (); |
126 | |
125 | |
127 | if (INVOKE_PLAYER (MAP_CHANGE, op->contr, ARG_MAP (m), ARG_INT (newx), ARG_INT (newy))) |
126 | if (INVOKE_PLAYER (MAP_CHANGE, contr, ARG_MAP (m), ARG_INT (newx), ARG_INT (newy))) |
128 | return 0; |
127 | return 0; |
129 | |
128 | |
130 | if (INVOKE_MAP (ENTER, m, ARG_PLAYER (op->contr), ARG_INT (newx), ARG_INT (newy))) |
129 | if (INVOKE_MAP (ENTER, m, ARG_PLAYER (contr), ARG_INT (newx), ARG_INT (newy))) |
131 | return 0; |
130 | return 0; |
132 | } |
131 | } |
133 | else |
132 | else |
134 | op->remove (); |
133 | remove (); |
135 | |
134 | |
136 | /* we already have newx, newy, and m, so lets use them. |
|
|
137 | * In addition, this fixes potential crashes, because multipart object was |
|
|
138 | * on edge of map, +=x, +=y doesn't make correct coordinates. |
|
|
139 | */ |
|
|
140 | for (tmp = op; tmp != NULL; tmp = tmp->more) |
135 | for (tmp = this; tmp; tmp = tmp->more) |
141 | { |
136 | { |
142 | tmp->x += freearr_x[dir]; |
137 | tmp->x += freearr_x[dir]; |
143 | tmp->y += freearr_y[dir]; |
138 | tmp->y += freearr_y[dir]; |
144 | tmp->map = get_map_from_coord (tmp->map, &tmp->x, &tmp->y); |
139 | xy_normalise (tmp->map, tmp->x, tmp->y); |
145 | } |
140 | } |
146 | |
141 | |
147 | /* insert_ob_in_map will deal with any tiling issues */ |
142 | /* insert_ob_in_map will deal with any tiling issues */ |
148 | insert_ob_in_map (op, m, originator, 0); |
143 | insert_ob_in_map (this, map, originator, 0); |
149 | |
144 | |
150 | return 1; |
145 | return 1; |
151 | } |
146 | } |
152 | |
147 | |
153 | |
148 | |
… | |
… | |
175 | i = find_first_free_spot (op, op->map, x, y); |
170 | i = find_first_free_spot (op, op->map, x, y); |
176 | |
171 | |
177 | if (i == -1) |
172 | if (i == -1) |
178 | return 0; /* No free spot */ |
173 | return 0; /* No free spot */ |
179 | |
174 | |
180 | if (op->head != NULL) |
|
|
181 | op = op->head; |
175 | op = op->head_ (); |
182 | op->remove (); |
176 | op->remove (); |
|
|
177 | |
183 | for (tmp = op; tmp != NULL; tmp = tmp->more) |
178 | for (object *tmp = op; tmp; tmp = tmp->more) |
|
|
179 | { |
184 | tmp->x = x + freearr_x[i] + (tmp->arch == NULL ? 0 : tmp->arch->x), |
180 | tmp->x = x + freearr_x[i] + (!tmp->arch ? 0 : tmp->arch->x); |
185 | tmp->y = y + freearr_y[i] + (tmp->arch == NULL ? 0 : tmp->arch->y); |
181 | tmp->y = y + freearr_y[i] + (!tmp->arch ? 0 : tmp->arch->y); |
|
|
182 | } |
186 | |
183 | |
187 | tmp = insert_ob_in_map (op, op->map, originator, 0); |
184 | op = insert_ob_in_map (op, op->map, originator, 0); |
188 | if (tmp) |
185 | |
189 | return 0; |
186 | return !op; |
190 | else |
|
|
191 | return 1; |
|
|
192 | } |
187 | } |
193 | |
188 | |
194 | /* |
189 | /* |
195 | * Return value: 1 if object was destroyed, 0 otherwise. |
190 | * Return value: 1 if object was destroyed, 0 otherwise. |
196 | * Modified so that instead of passing the 'originator' that had no |
191 | * Modified so that instead of passing the 'originator' that had no |
… | |
… | |
224 | for (i = -5; i < 6; i++) |
219 | for (i = -5; i < 6; i++) |
225 | for (j = -5; j < 6; j++) |
220 | for (j = -5; j < 6; j++) |
226 | { |
221 | { |
227 | if (i == 0 && j == 0) |
222 | if (i == 0 && j == 0) |
228 | continue; |
223 | continue; |
|
|
224 | |
229 | /* Perhaps this should be extended to support tiled maps */ |
225 | /* Perhaps this should be extended to support tiled maps */ |
230 | if (OUT_OF_REAL_MAP (teleporter->map, teleporter->x + i, teleporter->y + j)) |
226 | if (OUT_OF_REAL_MAP (teleporter->map, teleporter->x + i, teleporter->y + j)) |
231 | continue; |
227 | continue; |
|
|
228 | |
232 | other_teleporter = GET_MAP_OB (teleporter->map, teleporter->x + i, teleporter->y + j); |
229 | other_teleporter = GET_MAP_OB (teleporter->map, teleporter->x + i, teleporter->y + j); |
233 | |
230 | |
234 | while (other_teleporter) |
231 | while (other_teleporter) |
235 | { |
232 | { |
236 | if (other_teleporter->type == tele_type) |
233 | if (other_teleporter->type == tele_type) |
237 | break; |
234 | break; |
238 | other_teleporter = other_teleporter->above; |
235 | other_teleporter = other_teleporter->above; |
239 | } |
236 | } |
|
|
237 | |
240 | if (other_teleporter && !(RANDOM () % ++nrofalt)) |
238 | if (other_teleporter && !rndm (++nrofalt)) |
241 | altern = other_teleporter; |
239 | altern = other_teleporter; |
242 | } |
240 | } |
243 | |
241 | |
244 | if (!nrofalt) |
242 | if (!nrofalt) |
245 | { |
243 | { |
246 | LOG (llevError, "No alternative teleporters around!\n"); |
244 | LOG (llevError, "%s: no alternative teleporters around (user %s).\n", |
|
|
245 | teleporter->debug_desc (), user->debug_desc ()); |
247 | return 0; |
246 | return 0; |
248 | } |
247 | } |
249 | |
248 | |
250 | other_teleporter = altern; |
249 | other_teleporter = altern; |
251 | k = find_free_spot (user, other_teleporter->map, other_teleporter->x, other_teleporter->y, 1, 9); |
250 | k = find_free_spot (user, other_teleporter->map, other_teleporter->x, other_teleporter->y, 1, 9); |
… | |
… | |
283 | } |
282 | } |
284 | |
283 | |
285 | user->remove (); |
284 | user->remove (); |
286 | |
285 | |
287 | /* Update location for the object */ |
286 | /* Update location for the object */ |
288 | for (tmp = user; tmp != NULL; tmp = tmp->more) |
287 | for (tmp = user; tmp; tmp = tmp->more) |
289 | { |
288 | { |
290 | tmp->x = other_teleporter->x + freearr_x[k] + (tmp->arch == NULL ? 0 : tmp->arch->x); |
289 | tmp->x = other_teleporter->x + freearr_x[k] + (tmp->arch ? tmp->arch->x : 0); |
291 | tmp->y = other_teleporter->y + freearr_y[k] + (tmp->arch == NULL ? 0 : tmp->arch->y); |
290 | tmp->y = other_teleporter->y + freearr_y[k] + (tmp->arch ? tmp->arch->y : 0); |
292 | } |
291 | } |
|
|
292 | |
293 | tmp = insert_ob_in_map (user, other_teleporter->map, NULL, 0); |
293 | tmp = insert_ob_in_map (user, other_teleporter->map, NULL, 0); |
294 | return (tmp == NULL); |
294 | return !tmp; |
295 | } |
295 | } |
296 | |
296 | |
297 | void |
297 | void |
298 | recursive_roll (object *op, int dir, object *pusher) |
298 | recursive_roll (object *op, int dir, object *pusher) |
299 | { |
299 | { |
… | |
… | |
372 | op = op->head; |
372 | op = op->head; |
373 | |
373 | |
374 | x = op->x + freearr_x[dir]; |
374 | x = op->x + freearr_x[dir]; |
375 | y = op->y + freearr_y[dir]; |
375 | y = op->y + freearr_y[dir]; |
376 | |
376 | |
377 | if (!QUERY_FLAG (op, FLAG_CAN_ROLL) || (op->weight && random_roll (0, op->weight / 50000 - 1, pusher, PREFER_LOW) > pusher->stats.Str)) |
377 | if (!QUERY_FLAG (op, FLAG_CAN_ROLL) |
|
|
378 | || (op->weight && random_roll (0, op->weight / 50000 - 1, pusher, PREFER_LOW) |
|
|
379 | > pusher->stats.Str)) |
378 | return 0; |
380 | return 0; |
379 | |
381 | |
380 | m = op->map; |
382 | m = op->map; |
381 | flags = get_map_flags (m, &m, x, y, &x, &y); |
383 | flags = get_map_flags (m, &m, x, y, &x, &y); |
382 | |
384 | |