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