… | |
… | |
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 | |
… | |
… | |
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 | { |
… | |
… | |
284 | } |
282 | } |
285 | |
283 | |
286 | user->remove (); |
284 | user->remove (); |
287 | |
285 | |
288 | /* Update location for the object */ |
286 | /* Update location for the object */ |
289 | for (tmp = user; tmp != NULL; tmp = tmp->more) |
287 | for (tmp = user; tmp; tmp = tmp->more) |
290 | { |
288 | { |
291 | 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); |
292 | 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); |
293 | } |
291 | } |
|
|
292 | |
294 | tmp = insert_ob_in_map (user, other_teleporter->map, NULL, 0); |
293 | tmp = insert_ob_in_map (user, other_teleporter->map, NULL, 0); |
295 | return (tmp == NULL); |
294 | return !tmp; |
296 | } |
295 | } |
297 | |
296 | |
298 | void |
297 | void |
299 | recursive_roll (object *op, int dir, object *pusher) |
298 | recursive_roll (object *op, int dir, object *pusher) |
300 | { |
299 | { |