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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines