… | |
… | |
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 | |