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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines