ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/server/move.C
(Generate patch)

Comparing deliantra/server/server/move.C (file contents):
Revision 1.1 by elmex, Sun Aug 13 17:16:04 2006 UTC vs.
Revision 1.26 by root, Tue Aug 26 02:35:05 2008 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines