|
|
1 | |
1 | /* |
2 | /* |
2 | * static char *rcsid_move_c = |
3 | * static char *rcsid_move_c = |
3 | * "$Id: move.C,v 1.5 2006/08/29 17:32:19 root Exp $"; |
4 | * "$Id: move.C,v 1.7 2006/09/10 15:59:57 root Exp $"; |
4 | */ |
5 | */ |
5 | |
6 | |
6 | /* |
7 | /* |
7 | CrossFire, A Multiplayer game for X-windows |
8 | CrossFire, A Multiplayer game for X-windows |
8 | |
9 | |
… | |
… | |
26 | The author can be reached via e-mail to crossfire-devel@real-time.com |
27 | The author can be reached via e-mail to crossfire-devel@real-time.com |
27 | */ |
28 | */ |
28 | |
29 | |
29 | #include <global.h> |
30 | #include <global.h> |
30 | #ifndef __CEXTRACT__ |
31 | #ifndef __CEXTRACT__ |
31 | #include <sproto.h> |
32 | # include <sproto.h> |
32 | #endif |
33 | #endif |
33 | |
34 | |
34 | #ifdef COZY_SERVER |
35 | #ifdef COZY_SERVER |
35 | // use a ptotoype |
36 | // use a ptotoype |
36 | extern int same_party (partylist *a, partylist *b); |
37 | extern int same_party (partylist *a, partylist *b); |
… | |
… | |
42 | * otherwise 1. |
43 | * otherwise 1. |
43 | * This is an improvement from the previous move_ob(), which |
44 | * This is an improvement from the previous move_ob(), which |
44 | * removed and inserted objects even if they were unable to move. |
45 | * removed and inserted objects even if they were unable to move. |
45 | */ |
46 | */ |
46 | |
47 | |
|
|
48 | int |
47 | int move_object(object *op, int dir) { |
49 | move_object (object *op, int dir) |
|
|
50 | { |
48 | return move_ob(op, dir, op); |
51 | return move_ob (op, dir, op); |
49 | } |
52 | } |
50 | |
53 | |
51 | |
54 | |
52 | /* object op is trying to move in direction dir. |
55 | /* object op is trying to move in direction dir. |
53 | * originator is typically the same as op, but |
56 | * originator is typically the same as op, but |
… | |
… | |
56 | * returns 0 if the object is not able to move to the |
59 | * returns 0 if the object is not able to move to the |
57 | * desired space, 1 otherwise (in which case we also |
60 | * desired space, 1 otherwise (in which case we also |
58 | * move the object accordingly. This function is |
61 | * move the object accordingly. This function is |
59 | * very similiar to move_object. |
62 | * very similiar to move_object. |
60 | */ |
63 | */ |
|
|
64 | int |
61 | int move_ob (object *op, int dir, object *originator) |
65 | move_ob (object *op, int dir, object *originator) |
62 | { |
66 | { |
63 | sint16 newx = op->x+freearr_x[dir]; |
67 | sint16 newx = op->x + freearr_x[dir]; |
64 | sint16 newy = op->y+freearr_y[dir]; |
68 | sint16 newy = op->y + freearr_y[dir]; |
65 | object *tmp; |
69 | object *tmp; |
66 | mapstruct *m; |
70 | mapstruct *m; |
67 | int mflags; |
71 | int mflags; |
68 | |
72 | |
69 | if(op==NULL) { |
73 | if (op == NULL) |
|
|
74 | { |
70 | LOG(llevError,"Trying to move NULL.\n"); |
75 | LOG (llevError, "Trying to move NULL.\n"); |
71 | return 0; |
76 | return 0; |
72 | } |
77 | } |
73 | |
78 | |
74 | m = op->map; |
79 | m = op->map; |
75 | mflags = get_map_flags(m, &m, newx, newy, &newx, &newy); |
80 | mflags = get_map_flags (m, &m, newx, newy, &newx, &newy); |
76 | |
81 | |
77 | /* If the space the player is trying to is out of the map, |
82 | /* If the space the player is trying to is out of the map, |
78 | * bail now - we know it can't work. |
83 | * bail now - we know it can't work. |
79 | */ |
84 | */ |
80 | if (mflags & P_OUT_OF_MAP) return 0; |
85 | if (mflags & P_OUT_OF_MAP) |
|
|
86 | return 0; |
81 | |
87 | |
82 | |
88 | |
83 | /* Is this space blocked? Players with wizpass are immune to |
89 | /* Is this space blocked? Players with wizpass are immune to |
84 | * this condition. |
90 | * this condition. |
85 | */ |
91 | */ |
86 | if(blocked_link(op, m, newx, newy) && |
92 | if (blocked_link (op, m, newx, newy) && !QUERY_FLAG (op, FLAG_WIZPASS)) |
87 | !QUERY_FLAG(op, FLAG_WIZPASS)) |
|
|
88 | return 0; |
93 | return 0; |
89 | |
94 | |
90 | /* 0.94.2 - we need to set the direction for the new animation code. |
95 | /* 0.94.2 - we need to set the direction for the new animation code. |
91 | * it uses it to figure out face to use - I can't see it |
96 | * it uses it to figure out face to use - I can't see it |
92 | * breaking anything, but it might. |
97 | * breaking anything, but it might. |
93 | */ |
98 | */ |
94 | if(op->more != NULL && !move_ob(op->more, dir, op->more->head)) |
99 | if (op->more != NULL && !move_ob (op->more, dir, op->more->head)) |
95 | return 0; |
100 | return 0; |
96 | |
101 | |
97 | op->direction = dir; |
102 | op->direction = dir; |
98 | |
103 | |
99 | if(op->will_apply&4) |
104 | if (op->will_apply & 4) |
100 | check_earthwalls(op,m, newx,newy); |
105 | check_earthwalls (op, m, newx, newy); |
101 | if(op->will_apply&8) |
106 | if (op->will_apply & 8) |
102 | check_doors(op,m, newx,newy); |
107 | check_doors (op, m, newx, newy); |
103 | |
108 | |
104 | /* 0.94.1 - I got a stack trace that showed it crash with remove_ob trying |
109 | /* 0.94.1 - I got a stack trace that showed it crash with remove_ob trying |
105 | * to remove a removed object, and this function was the culprit. A possible |
110 | * to remove a removed object, and this function was the culprit. A possible |
106 | * guess I have is that check_doors above ran into a trap, killing the |
111 | * guess I have is that check_doors above ran into a trap, killing the |
107 | * monster. |
112 | * monster. |
108 | * |
113 | * |
109 | * Unfortunately, it doesn't appear that the calling functions of move_object |
114 | * Unfortunately, it doesn't appear that the calling functions of move_object |
110 | * deal very well with op being killed, so all this might do is just |
115 | * deal very well with op being killed, so all this might do is just |
111 | * migrate the problem someplace else. |
116 | * migrate the problem someplace else. |
112 | */ |
117 | */ |
113 | |
118 | |
114 | if (QUERY_FLAG(op, FLAG_REMOVED)) { |
119 | if (QUERY_FLAG (op, FLAG_REMOVED)) |
|
|
120 | { |
115 | LOG(llevDebug,"move_object: monster has been removed - will not process further\n"); |
121 | LOG (llevDebug, "move_object: monster has been removed - will not process further\n"); |
116 | /* Was not successful, but don't want to try and move again */ |
122 | /* Was not successful, but don't want to try and move again */ |
117 | return 1; |
123 | return 1; |
118 | } |
124 | } |
119 | |
125 | |
120 | /* If this is a tail portion, just want to tell caller that move is |
126 | /* If this is a tail portion, just want to tell caller that move is |
121 | * ok - the caller will deal with actual object removal/insertion |
127 | * ok - the caller will deal with actual object removal/insertion |
122 | */ |
128 | */ |
123 | if(op->head) |
129 | if (op->head) |
124 | return 1; |
|
|
125 | |
|
|
126 | remove_ob(op); |
|
|
127 | |
|
|
128 | /* we already have newx, newy, and m, so lets use them. |
|
|
129 | * In addition, this fixes potential crashes, because multipart object was |
|
|
130 | * on edge of map, +=x, +=y doesn't make correct coordinates. |
|
|
131 | */ |
|
|
132 | for(tmp = op; tmp != NULL; tmp = tmp->more) { |
|
|
133 | tmp->x += freearr_x[dir]; |
|
|
134 | tmp->y += freearr_y[dir]; |
|
|
135 | tmp->map = get_map_from_coord(tmp->map, &tmp->x, &tmp->y); |
|
|
136 | } |
|
|
137 | |
|
|
138 | /* insert_ob_in_map will deal with any tiling issues */ |
|
|
139 | insert_ob_in_map(op, m, originator,0); |
|
|
140 | |
|
|
141 | return 1; |
130 | return 1; |
|
|
131 | |
|
|
132 | remove_ob (op); |
|
|
133 | |
|
|
134 | /* we already have newx, newy, and m, so lets use them. |
|
|
135 | * In addition, this fixes potential crashes, because multipart object was |
|
|
136 | * on edge of map, +=x, +=y doesn't make correct coordinates. |
|
|
137 | */ |
|
|
138 | for (tmp = op; tmp != NULL; tmp = tmp->more) |
|
|
139 | { |
|
|
140 | tmp->x += freearr_x[dir]; |
|
|
141 | tmp->y += freearr_y[dir]; |
|
|
142 | tmp->map = get_map_from_coord (tmp->map, &tmp->x, &tmp->y); |
|
|
143 | } |
|
|
144 | |
|
|
145 | /* insert_ob_in_map will deal with any tiling issues */ |
|
|
146 | insert_ob_in_map (op, m, originator, 0); |
|
|
147 | |
|
|
148 | return 1; |
142 | } |
149 | } |
143 | |
150 | |
144 | |
151 | |
145 | /* |
152 | /* |
146 | * transfer_ob(): Move an object (even linked objects) to another spot |
153 | * transfer_ob(): Move an object (even linked objects) to another spot |
… | |
… | |
152 | * use find_first_free_spot(). |
159 | * use find_first_free_spot(). |
153 | * |
160 | * |
154 | * Return value: 1 if object was destroyed, 0 otherwise. |
161 | * Return value: 1 if object was destroyed, 0 otherwise. |
155 | */ |
162 | */ |
156 | |
163 | |
|
|
164 | int |
157 | int transfer_ob (object *op, int x, int y, int randomly, object *originator) |
165 | transfer_ob (object *op, int x, int y, int randomly, object *originator) |
158 | { |
166 | { |
159 | int i; |
167 | int i; |
160 | object *tmp; |
168 | object *tmp; |
161 | |
169 | |
162 | if (randomly) |
170 | if (randomly) |
163 | i = find_free_spot (op,op->map,x,y,0,SIZEOFFREE); |
171 | i = find_free_spot (op, op->map, x, y, 0, SIZEOFFREE); |
164 | else |
172 | else |
165 | i = find_first_free_spot(op,op->map,x,y); |
173 | i = find_first_free_spot (op, op->map, x, y); |
166 | |
174 | |
167 | if (i==-1) |
175 | if (i == -1) |
168 | return 0; /* No free spot */ |
176 | return 0; /* No free spot */ |
169 | |
177 | |
170 | if(op->head!=NULL) |
178 | if (op->head != NULL) |
171 | op=op->head; |
179 | op = op->head; |
172 | remove_ob(op); |
180 | remove_ob (op); |
173 | for(tmp=op;tmp!=NULL;tmp=tmp->more) |
181 | for (tmp = op; tmp != NULL; tmp = tmp->more) |
174 | tmp->x=x+freearr_x[i]+(tmp->arch==NULL?0:tmp->arch->clone.x), |
182 | tmp->x = x + freearr_x[i] + (tmp->arch == NULL ? 0 : tmp->arch->clone.x), |
175 | tmp->y=y+freearr_y[i]+(tmp->arch==NULL?0:tmp->arch->clone.y); |
183 | tmp->y = y + freearr_y[i] + (tmp->arch == NULL ? 0 : tmp->arch->clone.y); |
176 | |
184 | |
177 | tmp = insert_ob_in_map(op,op->map,originator,0); |
185 | tmp = insert_ob_in_map (op, op->map, originator, 0); |
178 | if (tmp) return 0; |
186 | if (tmp) |
|
|
187 | return 0; |
|
|
188 | else |
179 | else return 1; |
189 | return 1; |
180 | } |
190 | } |
181 | |
191 | |
182 | /* |
192 | /* |
183 | * Return value: 1 if object was destroyed, 0 otherwise. |
193 | * Return value: 1 if object was destroyed, 0 otherwise. |
184 | * Modified so that instead of passing the 'originator' that had no |
194 | * Modified so that instead of passing the 'originator' that had no |
… | |
… | |
189 | * currently, this is either set to SHOP_MAT or TELEPORTER. |
199 | * currently, this is either set to SHOP_MAT or TELEPORTER. |
190 | * It is basically used so that shop_mats and normal teleporters can |
200 | * It is basically used so that shop_mats and normal teleporters can |
191 | * be used close to each other and not have the player put to the |
201 | * be used close to each other and not have the player put to the |
192 | * one of another type. |
202 | * one of another type. |
193 | */ |
203 | */ |
|
|
204 | int |
194 | int teleport (object *teleporter, uint8 tele_type, object *user) |
205 | teleport (object *teleporter, uint8 tele_type, object *user) |
195 | { |
206 | { |
196 | object *altern; |
207 | object *altern; |
197 | int i,j,k,nrofalt=0; |
208 | int i, j, k, nrofalt = 0; |
198 | object *other_teleporter, *tmp; |
209 | object *other_teleporter, *tmp; |
199 | mapstruct *m; |
210 | mapstruct *m; |
200 | sint16 sx, sy; |
211 | sint16 sx, sy; |
201 | |
212 | |
202 | if(user==NULL) return 0; |
213 | if (user == NULL) |
|
|
214 | return 0; |
203 | if(user->head!=NULL) |
215 | if (user->head != NULL) |
204 | user=user->head; |
216 | user = user->head; |
205 | |
217 | |
206 | /* Find all other teleporters within range. This range |
218 | /* Find all other teleporters within range. This range |
207 | * should really be setable by some object attribute instead of |
219 | * should really be setable by some object attribute instead of |
208 | * using hard coded values. |
220 | * using hard coded values. |
209 | */ |
221 | */ |
210 | for(i= -5;i<6;i++) |
222 | for (i = -5; i < 6; i++) |
211 | for(j= -5;j<6;j++) { |
223 | for (j = -5; j < 6; j++) |
|
|
224 | { |
212 | if(i==0&&j==0) |
225 | if (i == 0 && j == 0) |
|
|
226 | continue; |
|
|
227 | /* Perhaps this should be extended to support tiled maps */ |
|
|
228 | if (OUT_OF_REAL_MAP (teleporter->map, teleporter->x + i, teleporter->y + j)) |
|
|
229 | continue; |
|
|
230 | other_teleporter = get_map_ob (teleporter->map, teleporter->x + i, teleporter->y + j); |
|
|
231 | |
|
|
232 | while (other_teleporter) |
|
|
233 | { |
|
|
234 | if (other_teleporter->type == tele_type) |
|
|
235 | break; |
|
|
236 | other_teleporter = other_teleporter->above; |
|
|
237 | } |
|
|
238 | if (other_teleporter && !(RANDOM () % ++nrofalt)) |
|
|
239 | altern = other_teleporter; |
|
|
240 | } |
|
|
241 | |
|
|
242 | if (!nrofalt) |
|
|
243 | { |
|
|
244 | LOG (llevError, "No alternative teleporters around!\n"); |
|
|
245 | return 0; |
|
|
246 | } |
|
|
247 | |
|
|
248 | other_teleporter = altern; |
|
|
249 | k = find_free_spot (user, other_teleporter->map, other_teleporter->x, other_teleporter->y, 1, 9); |
|
|
250 | |
|
|
251 | /* if k==-1, unable to find a free spot. If this is shop |
|
|
252 | * mat that the player is using, find someplace to move |
|
|
253 | * the player - otherwise, player can get trapped in the shops |
|
|
254 | * that appear in random dungeons. We basically just make |
|
|
255 | * sure the space isn't no pass (eg wall), and don't care |
|
|
256 | * about is alive. |
|
|
257 | */ |
|
|
258 | if (k == -1) |
|
|
259 | { |
|
|
260 | if (tele_type == SHOP_MAT && user->type == PLAYER) |
|
|
261 | { |
|
|
262 | for (k = 1; k < 9; k++) |
|
|
263 | { |
|
|
264 | if (get_map_flags (other_teleporter->map, &m, |
|
|
265 | other_teleporter->x + freearr_x[k], other_teleporter->y + freearr_y[k], &sx, &sy) & P_OUT_OF_MAP) |
213 | continue; |
266 | continue; |
214 | /* Perhaps this should be extended to support tiled maps */ |
267 | |
215 | if(OUT_OF_REAL_MAP(teleporter->map,teleporter->x+i,teleporter->y+j)) |
268 | if (!OB_TYPE_MOVE_BLOCK (user, GET_MAP_MOVE_BLOCK (m, sx, sy))) |
216 | continue; |
269 | break; |
217 | other_teleporter=get_map_ob(teleporter->map, |
|
|
218 | teleporter->x+i,teleporter->y+j); |
|
|
219 | |
270 | |
220 | while (other_teleporter) { |
|
|
221 | if (other_teleporter->type == tele_type) break; |
|
|
222 | other_teleporter = other_teleporter->above; |
|
|
223 | } |
271 | } |
224 | if (other_teleporter && !(RANDOM() % ++nrofalt)) |
272 | if (k == 9) |
225 | altern = other_teleporter; |
|
|
226 | } |
|
|
227 | |
|
|
228 | if(!nrofalt) { |
|
|
229 | LOG(llevError,"No alternative teleporters around!\n"); |
|
|
230 | return 0; |
|
|
231 | } |
|
|
232 | |
|
|
233 | other_teleporter=altern; |
|
|
234 | k=find_free_spot(user,other_teleporter->map, |
|
|
235 | other_teleporter->x,other_teleporter->y,1,9); |
|
|
236 | |
|
|
237 | /* if k==-1, unable to find a free spot. If this is shop |
|
|
238 | * mat that the player is using, find someplace to move |
|
|
239 | * the player - otherwise, player can get trapped in the shops |
|
|
240 | * that appear in random dungeons. We basically just make |
|
|
241 | * sure the space isn't no pass (eg wall), and don't care |
|
|
242 | * about is alive. |
|
|
243 | */ |
|
|
244 | if (k==-1) { |
|
|
245 | if (tele_type == SHOP_MAT && user->type == PLAYER) { |
|
|
246 | for (k=1; k<9; k++) { |
|
|
247 | if (get_map_flags(other_teleporter->map, &m, |
|
|
248 | other_teleporter->x + freearr_x[k], |
|
|
249 | other_teleporter->y + freearr_y[k], &sx,&sy) & |
|
|
250 | P_OUT_OF_MAP) continue; |
|
|
251 | |
|
|
252 | if (!OB_TYPE_MOVE_BLOCK(user, GET_MAP_MOVE_BLOCK(m, sx, sy))) break; |
|
|
253 | |
|
|
254 | } |
273 | { |
255 | if (k==9) { |
|
|
256 | LOG(llevError,"Shop mat %s (%d, %d) is in solid rock?\n", |
274 | LOG (llevError, "Shop mat %s (%d, %d) is in solid rock?\n", |
257 | other_teleporter->name, other_teleporter->x, other_teleporter->y); |
275 | &other_teleporter->name, other_teleporter->x, other_teleporter->y); |
258 | return 0; |
276 | return 0; |
259 | } |
277 | } |
260 | } |
278 | } |
|
|
279 | else |
261 | else return 0; |
280 | return 0; |
262 | } |
281 | } |
263 | |
282 | |
264 | remove_ob(user); |
283 | remove_ob (user); |
265 | |
284 | |
266 | /* Update location for the object */ |
285 | /* Update location for the object */ |
267 | for(tmp=user;tmp!=NULL;tmp=tmp->more) { |
286 | for (tmp = user; tmp != NULL; tmp = tmp->more) |
268 | tmp->x=other_teleporter->x+freearr_x[k]+ |
|
|
269 | (tmp->arch==NULL?0:tmp->arch->clone.x); |
|
|
270 | tmp->y=other_teleporter->y+freearr_y[k]+ |
|
|
271 | (tmp->arch==NULL?0:tmp->arch->clone.y); |
|
|
272 | } |
287 | { |
|
|
288 | tmp->x = other_teleporter->x + freearr_x[k] + (tmp->arch == NULL ? 0 : tmp->arch->clone.x); |
|
|
289 | tmp->y = other_teleporter->y + freearr_y[k] + (tmp->arch == NULL ? 0 : tmp->arch->clone.y); |
|
|
290 | } |
273 | tmp = insert_ob_in_map(user,other_teleporter->map,NULL,0); |
291 | tmp = insert_ob_in_map (user, other_teleporter->map, NULL, 0); |
274 | return (tmp == NULL); |
292 | return (tmp == NULL); |
275 | } |
293 | } |
276 | |
294 | |
|
|
295 | void |
277 | void recursive_roll(object *op,int dir,object *pusher) { |
296 | recursive_roll (object *op, int dir, object *pusher) |
|
|
297 | { |
278 | if(!roll_ob(op,dir,pusher)) { |
298 | if (!roll_ob (op, dir, pusher)) |
279 | new_draw_info_format(NDI_UNIQUE, 0, pusher, |
299 | { |
280 | "You fail to push the %s.",query_name(op)); |
300 | new_draw_info_format (NDI_UNIQUE, 0, pusher, "You fail to push the %s.", query_name (op)); |
281 | return; |
301 | return; |
282 | } |
302 | } |
283 | (void) move_ob(pusher,dir,pusher); |
303 | (void) move_ob (pusher, dir, pusher); |
284 | new_draw_info_format(NDI_BLACK, 0, pusher, |
304 | new_draw_info_format (NDI_BLACK, 0, pusher, "You move the %s.", query_name (op)); |
285 | "You move the %s.",query_name(op)); |
|
|
286 | return; |
305 | return; |
287 | } |
306 | } |
288 | |
307 | |
289 | /* |
308 | /* |
290 | * This is a new version of blocked, this one handles objects |
309 | * This is a new version of blocked, this one handles objects |
… | |
… | |
293 | * very new version handles also multipart objects |
312 | * very new version handles also multipart objects |
294 | * This is currently only used for the boulder roll code. |
313 | * This is currently only used for the boulder roll code. |
295 | * Returns 1 if object does not fit, 0 if it does. |
314 | * Returns 1 if object does not fit, 0 if it does. |
296 | */ |
315 | */ |
297 | |
316 | |
|
|
317 | int |
298 | int try_fit (object *op, mapstruct *m, int x, int y) |
318 | try_fit (object *op, mapstruct *m, int x, int y) |
299 | { |
319 | { |
300 | object *tmp, *more; |
320 | object *tmp, *more; |
301 | sint16 tx, ty; |
321 | sint16 tx, ty; |
302 | int mflags; |
322 | int mflags; |
303 | mapstruct *m2; |
323 | mapstruct *m2; |
304 | |
324 | |
305 | if (op->head) |
325 | if (op->head) |
306 | op = op->head; |
326 | op = op->head; |
307 | |
327 | |
308 | for (more = op; more ; more = more->more) { |
328 | for (more = op; more; more = more->more) |
|
|
329 | { |
309 | tx = x + more->x - op->x; |
330 | tx = x + more->x - op->x; |
310 | ty = y + more->y - op->y; |
331 | ty = y + more->y - op->y; |
311 | |
332 | |
312 | mflags = get_map_flags(m, &m2, tx, ty, &tx, &ty); |
333 | mflags = get_map_flags (m, &m2, tx, ty, &tx, &ty); |
313 | |
334 | |
314 | if (mflags & P_OUT_OF_MAP) |
335 | if (mflags & P_OUT_OF_MAP) |
|
|
336 | return 1; |
|
|
337 | |
|
|
338 | for (tmp = get_map_ob (m2, tx, ty); tmp; tmp = tmp->above) |
|
|
339 | { |
|
|
340 | if (tmp->head == op || tmp == op) |
|
|
341 | continue; |
|
|
342 | |
|
|
343 | if ((QUERY_FLAG (tmp, FLAG_ALIVE) && tmp->type != DOOR)) |
315 | return 1; |
344 | return 1; |
316 | |
345 | |
317 | for (tmp = get_map_ob (m2, tx, ty); tmp; tmp=tmp->above) { |
346 | if (OB_MOVE_BLOCK (op, tmp)) |
318 | if (tmp->head == op || tmp == op) |
|
|
319 | continue; |
|
|
320 | |
|
|
321 | if ((QUERY_FLAG(tmp,FLAG_ALIVE) && tmp->type!=DOOR)) |
|
|
322 | return 1; |
347 | return 1; |
323 | |
|
|
324 | if (OB_MOVE_BLOCK(op, tmp)) return 1; |
|
|
325 | |
348 | |
326 | } |
349 | } |
327 | } |
350 | } |
328 | return 0; |
351 | return 0; |
329 | } |
352 | } |
330 | |
353 | |
331 | /* |
354 | /* |
332 | * this is not perfect yet. |
355 | * this is not perfect yet. |
333 | * it does not roll objects behind multipart objects properly. |
356 | * it does not roll objects behind multipart objects properly. |
334 | * Support for rolling multipart objects is questionable. |
357 | * Support for rolling multipart objects is questionable. |
335 | */ |
358 | */ |
336 | |
359 | |
|
|
360 | int |
337 | int roll_ob(object *op,int dir, object *pusher) { |
361 | roll_ob (object *op, int dir, object *pusher) |
|
|
362 | { |
338 | object *tmp; |
363 | object *tmp; |
339 | sint16 x, y; |
364 | sint16 x, y; |
340 | int flags; |
365 | int flags; |
341 | mapstruct *m; |
366 | mapstruct *m; |
342 | MoveType move_block; |
367 | MoveType move_block; |
343 | |
368 | |
344 | if (op->head) |
369 | if (op->head) |
345 | op = op->head; |
370 | op = op->head; |
346 | |
371 | |
347 | x=op->x+freearr_x[dir]; |
372 | x = op->x + freearr_x[dir]; |
348 | y=op->y+freearr_y[dir]; |
373 | y = op->y + freearr_y[dir]; |
349 | |
374 | |
350 | if(!QUERY_FLAG(op,FLAG_CAN_ROLL) || |
375 | if (!QUERY_FLAG (op, FLAG_CAN_ROLL) || (op->weight && random_roll (0, op->weight / 50000 - 1, pusher, PREFER_LOW) > pusher->stats.Str)) |
351 | (op->weight && |
|
|
352 | random_roll(0, op->weight/50000-1, pusher, PREFER_LOW) > pusher->stats.Str)) |
|
|
353 | return 0; |
376 | return 0; |
354 | |
377 | |
355 | m = op->map; |
378 | m = op->map; |
356 | flags = get_map_flags(m, &m, x, y, &x, &y); |
379 | flags = get_map_flags (m, &m, x, y, &x, &y); |
357 | |
380 | |
358 | if (flags & (P_OUT_OF_MAP | P_IS_ALIVE)) |
381 | if (flags & (P_OUT_OF_MAP | P_IS_ALIVE)) |
359 | return 0; |
382 | return 0; |
360 | |
383 | |
361 | move_block = GET_MAP_MOVE_BLOCK(m, x, y); |
384 | move_block = GET_MAP_MOVE_BLOCK (m, x, y); |
362 | |
385 | |
363 | /* If the target space is not blocked, no need to look at the objects on it */ |
386 | /* If the target space is not blocked, no need to look at the objects on it */ |
364 | if ((op->move_type & move_block) == op->move_type) { |
387 | if ((op->move_type & move_block) == op->move_type) |
|
|
388 | { |
365 | for (tmp=get_map_ob(m, x, y); tmp!=NULL; tmp=tmp->above) { |
389 | for (tmp = get_map_ob (m, x, y); tmp != NULL; tmp = tmp->above) |
|
|
390 | { |
366 | if (tmp->head == op) |
391 | if (tmp->head == op) |
367 | continue; |
392 | continue; |
368 | if (OB_MOVE_BLOCK(op, tmp) && !roll_ob(tmp,dir,pusher)) |
393 | if (OB_MOVE_BLOCK (op, tmp) && !roll_ob (tmp, dir, pusher)) |
369 | return 0; |
394 | return 0; |
370 | } |
395 | } |
371 | } |
396 | } |
372 | if (try_fit (op, m, x, y)) |
397 | if (try_fit (op, m, x, y)) |
373 | return 0; |
398 | return 0; |
374 | |
399 | |
375 | remove_ob(op); |
400 | remove_ob (op); |
376 | for(tmp=op; tmp!=NULL; tmp=tmp->more) |
401 | for (tmp = op; tmp != NULL; tmp = tmp->more) |
377 | tmp->x+=freearr_x[dir],tmp->y+=freearr_y[dir]; |
402 | tmp->x += freearr_x[dir], tmp->y += freearr_y[dir]; |
378 | insert_ob_in_map(op,op->map,pusher,0); |
403 | insert_ob_in_map (op, op->map, pusher, 0); |
379 | return 1; |
404 | return 1; |
380 | } |
405 | } |
381 | |
406 | |
382 | /* returns 1 if pushing invokes a attack, 0 when not */ |
407 | /* returns 1 if pushing invokes a attack, 0 when not */ |
|
|
408 | int |
383 | int push_ob(object *who, int dir, object *pusher) { |
409 | push_ob (object *who, int dir, object *pusher) |
|
|
410 | { |
384 | int str1, str2; |
411 | int str1, str2; |
385 | object *owner; |
412 | object *owner; |
386 | |
413 | |
387 | if (who->head != NULL) |
414 | if (who->head != NULL) |
388 | who = who->head; |
415 | who = who->head; |
389 | owner = get_owner(who); |
416 | owner = get_owner (who); |
390 | |
417 | |
391 | /* Wake up sleeping monsters that may be pushed */ |
418 | /* Wake up sleeping monsters that may be pushed */ |
392 | CLEAR_FLAG(who,FLAG_SLEEP); |
419 | CLEAR_FLAG (who, FLAG_SLEEP); |
393 | |
420 | |
394 | /* player change place with his pets or summoned creature */ |
421 | /* player change place with his pets or summoned creature */ |
395 | /* TODO: allow multi arch pushing. Can't be very difficult */ |
422 | /* TODO: allow multi arch pushing. Can't be very difficult */ |
396 | if (who->more == NULL |
423 | if (who->more == NULL |
397 | #ifdef COZY_SERVER |
424 | #ifdef COZY_SERVER |
398 | && |
425 | && ((owner && owner->contr && pusher->contr && same_party (owner->contr->party, pusher->contr->party)) || owner == pusher) |
399 | ( |
|
|
400 | (owner && owner->contr && pusher->contr |
|
|
401 | && same_party (owner->contr->party, pusher->contr->party)) |
|
|
402 | || owner == pusher |
|
|
403 | ) |
|
|
404 | #else |
426 | #else |
405 | && owner == pusher |
427 | && owner == pusher |
406 | #endif |
428 | #endif |
407 | ) { |
429 | ) |
|
|
430 | { |
408 | int temp; |
431 | int temp; |
409 | mapstruct *m; |
432 | mapstruct *m; |
410 | |
433 | |
411 | remove_ob(who); |
434 | remove_ob (who); |
412 | remove_ob(pusher); |
435 | remove_ob (pusher); |
413 | temp = pusher->x; |
436 | temp = pusher->x; |
414 | pusher->x = who->x; |
437 | pusher->x = who->x; |
415 | who->x = temp; |
438 | who->x = temp; |
416 | |
439 | |
417 | temp = pusher->y; |
440 | temp = pusher->y; |
418 | pusher->y = who->y; |
441 | pusher->y = who->y; |
419 | who->y = temp; |
442 | who->y = temp; |
420 | |
443 | |
421 | m = pusher->map; |
444 | m = pusher->map; |
422 | pusher->map = who->map; |
445 | pusher->map = who->map; |
423 | who->map = m; |
446 | who->map = m; |
424 | |
447 | |
425 | insert_ob_in_map (who,who->map,pusher,0); |
448 | insert_ob_in_map (who, who->map, pusher, 0); |
426 | insert_ob_in_map (pusher,pusher->map,pusher,0); |
449 | insert_ob_in_map (pusher, pusher->map, pusher, 0); |
427 | return 0; |
450 | return 0; |
428 | } |
451 | } |
429 | |
452 | |
430 | |
453 | |
431 | /* We want ONLY become enemy of evil, unaggressive monster. We must RUN in them */ |
454 | /* We want ONLY become enemy of evil, unaggressive monster. We must RUN in them */ |
432 | /* In original we have here a unaggressive check only - that was the reason why */ |
455 | /* In original we have here a unaggressive check only - that was the reason why */ |
433 | /* we so often become an enemy of friendly monsters... */ |
456 | /* we so often become an enemy of friendly monsters... */ |
434 | /* funny: was they set to unaggressive 0 (= not so nice) they don't attack */ |
457 | /* funny: was they set to unaggressive 0 (= not so nice) they don't attack */ |
435 | |
458 | |
436 | if(owner != pusher && pusher->type == PLAYER && who->type != PLAYER && |
459 | if (owner != pusher && pusher->type == PLAYER && who->type != PLAYER && |
437 | !QUERY_FLAG(who,FLAG_FRIENDLY)&& !QUERY_FLAG(who,FLAG_NEUTRAL)) { |
460 | !QUERY_FLAG (who, FLAG_FRIENDLY) && !QUERY_FLAG (who, FLAG_NEUTRAL)) |
|
|
461 | { |
438 | if(pusher->contr->run_on) /* only when we run */ { |
462 | if (pusher->contr->run_on) /* only when we run */ |
439 | new_draw_info_format(NDI_UNIQUE, 0, pusher, |
463 | { |
440 | "You start to attack %s !!",who->name); |
464 | new_draw_info_format (NDI_UNIQUE, 0, pusher, "You start to attack %s !!", &who->name); |
441 | CLEAR_FLAG(who,FLAG_UNAGGRESSIVE); /* the sucker don't like you anymore */ |
465 | CLEAR_FLAG (who, FLAG_UNAGGRESSIVE); /* the sucker don't like you anymore */ |
442 | who->enemy = pusher; |
466 | who->enemy = pusher; |
443 | return 1; |
467 | return 1; |
444 | } |
468 | } |
445 | else |
469 | else |
446 | { |
470 | { |
447 | new_draw_info_format(NDI_UNIQUE, 0, pusher, |
471 | new_draw_info_format (NDI_UNIQUE, 0, pusher, "You avoid attacking %s.", &who->name); |
448 | "You avoid attacking %s .",who->name); |
|
|
449 | } |
472 | } |
450 | } |
473 | } |
451 | |
474 | |
452 | /* now, lets test stand still. we NEVER can push stand_still monsters. */ |
475 | /* now, lets test stand still. we NEVER can push stand_still monsters. */ |
453 | if(QUERY_FLAG(who,FLAG_STAND_STILL)) |
476 | if (QUERY_FLAG (who, FLAG_STAND_STILL)) |
454 | { |
477 | { |
455 | new_draw_info_format(NDI_UNIQUE, 0, pusher, |
478 | new_draw_info_format (NDI_UNIQUE, 0, pusher, "You can't push %s.", &who->name); |
456 | "You can't push %s.",who->name); |
|
|
457 | return 0; |
479 | return 0; |
458 | } |
480 | } |
459 | |
481 | |
460 | /* This block is basically if you are pushing friendly but |
482 | /* This block is basically if you are pushing friendly but |
461 | * non pet creaturs. |
483 | * non pet creaturs. |
462 | * It basically does a random strength comparision to |
484 | * It basically does a random strength comparision to |
463 | * determine if you can push someone around. Note that |
485 | * determine if you can push someone around. Note that |
464 | * this pushes the other person away - its not a swap. |
486 | * this pushes the other person away - its not a swap. |
465 | */ |
487 | */ |
466 | |
488 | |
467 | str1 = (who->stats.Str>0?who->stats.Str:who->level); |
489 | str1 = (who->stats.Str > 0 ? who->stats.Str : who->level); |
468 | str2 = (pusher->stats.Str>0?pusher->stats.Str:pusher->level); |
490 | str2 = (pusher->stats.Str > 0 ? pusher->stats.Str : pusher->level); |
469 | if(QUERY_FLAG(who,FLAG_WIZ) || |
491 | if (QUERY_FLAG (who, FLAG_WIZ) || |
470 | random_roll(str1, str1/2+str1*2, who, PREFER_HIGH) >= |
492 | random_roll (str1, str1 / 2 + str1 * 2, who, PREFER_HIGH) >= |
471 | random_roll(str2, str2/2+str2*2, pusher, PREFER_HIGH) || |
493 | random_roll (str2, str2 / 2 + str2 * 2, pusher, PREFER_HIGH) || !move_object (who, dir)) |
472 | !move_object(who,dir)) |
|
|
473 | { |
494 | { |
474 | if (who ->type == PLAYER) { |
495 | if (who->type == PLAYER) |
475 | new_draw_info_format(NDI_UNIQUE, 0, who, |
496 | { |
476 | "%s tried to push you.",pusher->name); |
497 | new_draw_info_format (NDI_UNIQUE, 0, who, "%s tried to push you.", &pusher->name); |
477 | } |
498 | } |
478 | return 0; |
499 | return 0; |
479 | } |
500 | } |
480 | |
501 | |
481 | /* If we get here, the push succeeded. |
502 | /* If we get here, the push succeeded. |
482 | * Let everyone know the status. |
503 | * Let everyone know the status. |
483 | */ |
504 | */ |
484 | if (who->type == PLAYER) { |
505 | if (who->type == PLAYER) |
485 | new_draw_info_format(NDI_UNIQUE, 0, who, |
|
|
486 | "%s pushed you.",pusher->name); |
|
|
487 | } |
506 | { |
|
|
507 | new_draw_info_format (NDI_UNIQUE, 0, who, "%s pushed you.", &pusher->name); |
|
|
508 | } |
488 | if (pusher->type == PLAYER) { |
509 | if (pusher->type == PLAYER) |
489 | new_draw_info_format(NDI_UNIQUE, 0, pusher, |
|
|
490 | "You pushed %s back.", who->name); |
|
|
491 | } |
510 | { |
492 | |
511 | new_draw_info_format (NDI_UNIQUE, 0, pusher, "You pushed %s back.", &who->name); |
|
|
512 | } |
|
|
513 | |
493 | return 1; |
514 | return 1; |
494 | } |
515 | } |