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