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

Comparing deliantra/server/server/time.C (file contents):
Revision 1.26 by root, Tue Dec 26 08:55:00 2006 UTC vs.
Revision 1.72 by root, Thu Nov 8 19:43:29 2007 UTC

1/* 1/*
2 CrossFire, A Multiplayer game for X-windows 2 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 3 *
4 * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
4 Copyright (C) 2002 Mark Wedel & Crossfire Development Team 5 * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team
5 Copyright (C) 1992 Frank Tore Johansen 6 * Copyright (©) 1992,2007 Frank Tore Johansen
6 7 *
7 This program is free software; you can redistribute it and/or modify 8 * Deliantra is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by 9 * it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or 10 * the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version. 11 * (at your option) any later version.
11 12 *
12 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,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details. 16 * GNU General Public License for more details.
16 17 *
17 You should have received a copy of the GNU General Public License 18 * You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software 19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20 *
20 21 * The authors can be reached via e-mail to <support@deliantra.net>
21 The authors can be reached via e-mail at <crossfire@schmorp.de>
22*/ 22 */
23 23
24/* 24/*
25 * Routines that is executed from objects based on their speed have been 25 * Routines that is executed from objects based on their speed have been
26 * collected in this file. 26 * collected in this file.
27 */ 27 */
28
29#include <global.h> 28#include <global.h>
30#include <spells.h> 29#include <spells.h>
31#ifndef __CEXTRACT__
32# include <sproto.h> 30#include <sproto.h>
33#endif
34 31
35/* The following removes doors. The functions check to see if similar 32/* The following removes doors. The functions check to see if similar
36 * doors are next to the one that is being removed, and if so, set it 33 * doors are next to the one that is being removed, and if so, set it
37 * so those will be removed shortly (in a cascade like fashion.) 34 * so those will be removed shortly (in a cascade like fashion.)
38 */ 35 */
39
40void 36void
41remove_door (object *op) 37remove_door (object *op)
38{
39 for (int i = 1; i < SIZEOFFREE1 + 1; i += 2)
40 {
41 object *tmp;
42 mapxy pos (op);
43 pos.move (i);
44 if (pos.normalise ()
45 && (tmp = present (DOOR, pos.m, pos.x, pos.y)))
46 {
47 tmp->set_speed (0.1f);
48 tmp->speed_left = -0.2f;
49 }
50 }
51
52 if (op->other_arch)
53 {
54 object *tmp = arch_to_object (op->other_arch);
55 tmp->x = op->x;
56 tmp->y = op->y;
57 tmp->map = op->map;
58 tmp->level = op->level;
59 insert_ob_in_map (tmp, op->map, op, 0);
60 }
61
62 op->destroy ();
63}
64
65void
66remove_door2 (object *op)
42{ 67{
43 int i; 68 int i;
44 object *tmp; 69 object *tmp;
45 70
46 for (i = 1; i < 9; i += 2) 71 for (i = 1; i < 9; i += 2)
72 {
47 if ((tmp = present (DOOR, op->map, op->x + freearr_x[i], op->y + freearr_y[i])) != NULL) 73 tmp = present (LOCKED_DOOR, op->map, op->x + freearr_x[i], op->y + freearr_y[i]);
48 { 74 if (tmp && tmp->slaying == op->slaying)
75 { /* same key both doors */
49 tmp->set_speed (0.1); 76 tmp->set_speed (0.1f);
50 tmp->speed_left = -0.2; 77 tmp->speed_left = -0.2f;
51 } 78 }
79 }
52 80
53 if (op->other_arch) 81 if (op->other_arch)
54 { 82 {
55 tmp = arch_to_object (op->other_arch); 83 tmp = arch_to_object (op->other_arch);
56 tmp->x = op->x; 84 tmp->x = op->x;
62 90
63 op->destroy (); 91 op->destroy ();
64} 92}
65 93
66void 94void
67remove_door2 (object *op)
68{
69 int i;
70 object *tmp;
71
72 for (i = 1; i < 9; i += 2)
73 {
74 tmp = present (LOCKED_DOOR, op->map, op->x + freearr_x[i], op->y + freearr_y[i]);
75 if (tmp && tmp->slaying == op->slaying)
76 { /* same key both doors */
77 tmp->set_speed (0.1);
78 tmp->speed_left = -0.2;
79 }
80 }
81 if (op->other_arch)
82 {
83 tmp = arch_to_object (op->other_arch);
84 tmp->x = op->x;
85 tmp->y = op->y;
86 tmp->map = op->map;
87 tmp->level = op->level;
88 insert_ob_in_map (tmp, op->map, op, 0);
89 }
90
91 op->destroy ();
92}
93
94/* Will generate a monster according to content
95 * of generator.
96 */
97void
98generate_monster_inv (object *gen) 95generate_monster (object *gen)
99{ 96{
100 int i;
101 object *op, *head = NULL;
102
103 int qty = 0;
104
105 /* Code below assumes the generator is on a map, as it tries
106 * to place the monster on the map. So if the generator
107 * isn't on a map, complain and exit.
108 */
109 if (gen->map == NULL)
110 {
111 //LOG(llevError,"Generator (%s) not on a map?\n", gen->name);
112 return;
113 }
114 /*First count numer of objects in inv */
115 for (op = gen->inv; op; op = op->below)
116 qty++;
117 if (!qty)
118 {
119 LOG (llevError, "Generator (%s) has no inventory in generate_monster_inv?\n", &gen->name);
120 return; /*No inventory */
121 }
122 qty = rndm (0, qty - 1);
123 for (op = gen->inv; qty; qty--)
124 op = op->below;
125 i = find_free_spot (op, gen->map, gen->x, gen->y, 1, 9);
126 if (i == -1)
127 return;
128 head = object_create_clone (op);
129 CLEAR_FLAG (head, FLAG_IS_A_TEMPLATE);
130 unflag_inv (head, FLAG_IS_A_TEMPLATE);
131 if (rndm (0, 9))
132 generate_artifact (head, gen->map->difficulty);
133 insert_ob_in_map_at (head, gen->map, gen, 0, gen->x + freearr_x[i], gen->y + freearr_y[i]);
134 if (QUERY_FLAG (head, FLAG_FREED))
135 return;
136 if (head->has_random_items ())
137 create_treasure (head->randomitems, head, GT_APPLY, gen->map->difficulty, 0);
138}
139
140void
141generate_monster_arch (object *gen)
142{
143 int i;
144 object *op, *head = NULL, *prev = NULL;
145 archetype *at = gen->other_arch;
146
147 if (!gen->other_arch)
148 return;
149
150 /* Code below assumes the generator is on a map, as it tries
151 * to place the monster on the map. So if the generator
152 * isn't on a map, complain and exit.
153 */
154 if (!gen->map) 97 if (!gen->map)
155 return; 98 return;
156 99
157 i = find_free_spot (&at->clone, gen->map, gen->x, gen->y, 1, 9); 100 if (GENERATE_SPEED (gen) && rndm (0, GENERATE_SPEED (gen) - 1))
158 if (i == -1)
159 return; 101 return;
160 102
161 while (at) 103 object *op;
104 int dir;
105
106 if (QUERY_FLAG (gen, FLAG_CONTENT_ON_GEN))
107 {
108 // either copy one item from the inventory...
109 if (!gen->inv)
110 return;
111
112 // first select one item from the inventory
113 int index = 0;
114 for (object *tmp = gen->inv; tmp; tmp = tmp->below)
115 if (!rndm (++index))
116 op = tmp;
117
118 dir = find_free_spot (op, gen->map, gen->x, gen->y, 1, SIZEOFFREE1 + 1);
119 if (dir < 0)
120 return;
121
122 op = object_create_clone (op);
123
124 CLEAR_FLAG (op, FLAG_IS_A_TEMPLATE);
125 unflag_inv (op, FLAG_IS_A_TEMPLATE);
162 { 126 }
127 else if (gen->other_arch)
128 {
129 // ...or use other_arch
130 dir = find_free_spot (gen->other_arch, gen->map, gen->x, gen->y, 1, SIZEOFFREE1 + 1);
131 if (dir < 0)
132 return;
133
163 op = arch_to_object (at); 134 op = arch_to_object (gen->other_arch);
164 op->x = gen->x + freearr_x[i] + at->clone.x; 135 }
165 op->y = gen->y + freearr_y[i] + at->clone.y; 136 else
137 return;
166 138
167 if (head) 139 op->expand_tail ();
168 op->head = head, prev->more = op;
169 140
141 mapxy pos (gen); pos.move (dir);
142
143 if (pos.insert (op, gen))
144 {
170 if (rndm (0, 9)) 145 if (rndm (0, 9))
171 generate_artifact (op, gen->map->difficulty); 146 generate_artifact (op, gen->map->difficulty);
172 147
173 insert_ob_in_map (op, gen->map, gen, 0);
174 if (QUERY_FLAG (op, FLAG_FREED))
175 return;
176
177 if (op->has_random_items ()) 148 if (op->has_random_items ())
178 create_treasure (op->randomitems, op, GT_APPLY, gen->map->difficulty, 0); 149 create_treasure (op->randomitems, op, GT_APPLY, gen->map->difficulty);
179 150
180 if (head == NULL)
181 head = op;
182
183 prev = op;
184 at = at->more;
185 }
186}
187
188void
189generate_monster (object *gen)
190{
191
192 if (GENERATE_SPEED (gen) && rndm (0, GENERATE_SPEED (gen) - 1))
193 return; 151 return;
152 }
194 153
195 if (QUERY_FLAG (gen, FLAG_CONTENT_ON_GEN)) 154 op->destroy ();
196 generate_monster_inv (gen);
197 else
198 generate_monster_arch (gen);
199
200} 155}
201 156
202void 157void
203remove_force (object *op) 158remove_force (object *op)
204{ 159{
227 if (--op->stats.food > 0) 182 if (--op->stats.food > 0)
228 return; 183 return;
229 184
230 CLEAR_FLAG (op, FLAG_APPLIED); 185 CLEAR_FLAG (op, FLAG_APPLIED);
231 186
232 if (op->env != NULL) 187 if (op->env)
233 { 188 {
234 change_abil (op->env, op); 189 change_abil (op->env, op);
235 op->env->update_stats (); 190 op->env->update_stats ();
236 } 191 }
237 192
247 return; 202 return;
248 } 203 }
249 204
250 if (op->stats.food == 1) 205 if (op->stats.food == 1)
251 { 206 {
252 /* need to remove the object before fix_player is called, else fix_player 207 /* need to unapply the object before update_stats is called, else fix_player
253 * will not do anything. 208 * will not do anything.
254 */ 209 */
255 if (op->env->type == PLAYER) 210 if (op->env->type == PLAYER)
256 { 211 {
257 CLEAR_FLAG (op, FLAG_APPLIED); 212 CLEAR_FLAG (op, FLAG_APPLIED);
266 if (op->env->type == PLAYER) 221 if (op->env->type == PLAYER)
267 { 222 {
268 op->env->stats.food--; 223 op->env->stats.food--;
269 new_draw_info (NDI_UNIQUE, 0, op->env, "You feel very sick..."); 224 new_draw_info (NDI_UNIQUE, 0, op->env, "You feel very sick...");
270 } 225 }
226
271 (void) hit_player (op->env, op->stats.dam, op, AT_INTERNAL, 1); 227 hit_player (op->env, op->stats.dam, op, AT_INTERNAL, 1);
272} 228}
273 229
274 230
275void 231void
276move_gate (object *op) 232move_gate (object *op)
277{ /* 1 = going down, 0 = goind up */ 233{ /* 1 = going down, 0 = going up */
278 object *tmp; 234 object *tmp;
279 235
280 if (op->stats.wc < 0 || (int) op->stats.wc >= NUM_ANIMATIONS (op)) 236 if (op->stats.wc < 0 || (int) op->stats.wc >= NUM_ANIMATIONS (op))
281 { 237 {
282 LOG (llevError, "Gate error: animation was %d, max=%d\n", op->stats.wc, NUM_ANIMATIONS (op)); 238 LOG (llevError, "Gate error: animation was %d, max=%d\n", op->stats.wc, NUM_ANIMATIONS (op));
287 if (op->value) 243 if (op->value)
288 { 244 {
289 if (--op->stats.wc <= 0) 245 if (--op->stats.wc <= 0)
290 { /* Reached bottom, let's stop */ 246 { /* Reached bottom, let's stop */
291 op->stats.wc = 0; 247 op->stats.wc = 0;
292 if (op->arch->clone.speed) 248 if (op->arch->speed)
293 op->value = 0; 249 op->value = 0;
294 else 250 else
295 op->set_speed (0); 251 op->set_speed (0);
296 } 252 }
297 253
317 * objects are above the gate. If so, we finish closing the gate, 273 * objects are above the gate. If so, we finish closing the gate,
318 * otherwise, we fall through to the code below which should lower 274 * otherwise, we fall through to the code below which should lower
319 * the gate slightly. 275 * the gate slightly.
320 */ 276 */
321 277
322 for (tmp = op->above; tmp != NULL; tmp = tmp->above) 278 for (tmp = op->above; tmp; tmp = tmp->above)
323 if (!QUERY_FLAG (tmp, FLAG_NO_PICK) || QUERY_FLAG (tmp, FLAG_CAN_ROLL) || QUERY_FLAG (tmp, FLAG_ALIVE)) 279 if (!QUERY_FLAG (tmp, FLAG_NO_PICK) || QUERY_FLAG (tmp, FLAG_CAN_ROLL) || QUERY_FLAG (tmp, FLAG_ALIVE))
324 break; 280 break;
325 281
326 if (tmp == NULL) 282 if (!tmp)
327 { 283 {
328 if (op->arch->clone.speed) 284 if (op->arch->speed)
329 op->value = 1; 285 op->value = 1;
330 else 286 else
331 op->set_speed (0); 287 op->set_speed (0);
332 288
333 return; 289 return;
344 } 300 }
345 else 301 else
346 { /* The gate is still going up */ 302 { /* The gate is still going up */
347 op->stats.wc++; 303 op->stats.wc++;
348 304
349 if ((int) op->stats.wc >= (NUM_ANIMATIONS (op))) 305 if (op->stats.wc >= NUM_ANIMATIONS (op))
350 op->stats.wc = (signed char) NUM_ANIMATIONS (op) - 1; 306 op->stats.wc = NUM_ANIMATIONS (op) - 1;
351 307
352 /* If there is something on top of the gate, we try to roll it off. 308 /* If there is something on top of the gate, we try to roll it off.
353 * If a player/monster, we don't roll, we just hit them with damage 309 * If a player/monster, we don't roll, we just hit them with damage
354 */ 310 */
355 if ((int) op->stats.wc >= NUM_ANIMATIONS (op) / 2) 311 if (op->stats.wc >= NUM_ANIMATIONS (op) / 2)
356 { 312 {
357 /* Halfway or further, check blocks */ 313 /* Halfway or further, check blocks */
358 /* First, get the top object on the square. */ 314 /* First, get the top object on the square. */
359 for (tmp = op->above; tmp != NULL && tmp->above != NULL; tmp = tmp->above); 315 for (tmp = op->above; tmp && tmp->above; tmp = tmp->above)
316 ;
360 317
361 if (tmp != NULL) 318 if (tmp)
362 { 319 {
363 if (QUERY_FLAG (tmp, FLAG_ALIVE)) 320 if (QUERY_FLAG (tmp, FLAG_ALIVE))
364 { 321 {
365 hit_player (tmp, random_roll (1, op->stats.dam, tmp, PREFER_LOW), op, AT_PHYSICAL, 1); 322 hit_player (tmp, random_roll (0, op->stats.dam, tmp, PREFER_LOW), op, AT_PHYSICAL, 1);
323 op->play_sound (sound_find ("blocked_gate"));
324
366 if (tmp->type == PLAYER) 325 if (tmp->type == PLAYER)
367 new_draw_info_format (NDI_UNIQUE, 0, tmp, "You are crushed by the %s!", &op->name); 326 new_draw_info_format (NDI_UNIQUE, 0, tmp, "You are crushed by the %s!", &op->name);
368 } 327 }
369 else
370 /* If the object is not alive, and the object either can 328 /* If the object is not alive, and the object either can
371 * be picked up or the object rolls, move the object 329 * be picked up or the object rolls, move the object
372 * off the gate. 330 * off the gate.
373 */ 331 */
374 if (!QUERY_FLAG (tmp, FLAG_ALIVE) && (!QUERY_FLAG (tmp, FLAG_NO_PICK) || QUERY_FLAG (tmp, FLAG_CAN_ROLL))) 332 else if (!QUERY_FLAG (tmp, FLAG_ALIVE) && (!QUERY_FLAG (tmp, FLAG_NO_PICK) || QUERY_FLAG (tmp, FLAG_CAN_ROLL)))
375 { 333 {
376 /* If it has speed, it should move itself, otherwise: */ 334 /* If it has speed, it should move itself, otherwise: */
377 int i = find_free_spot (tmp, op->map, op->x, op->y, 1, 9); 335 int i = find_free_spot (tmp, op->map, op->x, op->y, 1, SIZEOFFREE1 + 1);
378 336
379 /* If there is a free spot, move the object someplace */ 337 /* If there is a free spot, move the object someplace */
380 if (i != -1) 338 if (i > 0)
381 { 339 {
340 mapxy pos (tmp);
341 pos.move (i);
342 if (pos.normalise ())
382 tmp->remove (); 343 tmp->move_to (pos);
383 tmp->x += freearr_x[i], tmp->y += freearr_y[i];
384 insert_ob_in_map (tmp, op->map, op, 0);
385 } 344 }
386 } 345 }
387 } 346 }
388 347
389 /* See if there is still anything blocking the gate */ 348 /* See if there is still anything blocking the gate */
390 for (tmp = op->above; tmp != NULL; tmp = tmp->above) 349 for (tmp = op->above; tmp; tmp = tmp->above)
391 if (!QUERY_FLAG (tmp, FLAG_NO_PICK) || QUERY_FLAG (tmp, FLAG_CAN_ROLL) || QUERY_FLAG (tmp, FLAG_ALIVE)) 350 if (!QUERY_FLAG (tmp, FLAG_NO_PICK) || QUERY_FLAG (tmp, FLAG_CAN_ROLL) || QUERY_FLAG (tmp, FLAG_ALIVE))
392 break; 351 break;
393 352
394 /* IF there is, start putting the gate down */ 353 /* IF there is, start putting the gate down */
395 if (tmp) 354 if (tmp)
396 {
397 op->stats.food = 1; 355 op->stats.food = 1;
398 }
399 else 356 else
400 { 357 {
401 op->move_block = MOVE_ALL; 358 op->move_block = MOVE_ALL;
359
402 if (!op->arch->clone.stats.ac) 360 if (!op->arch->stats.ac)
403 SET_FLAG (op, FLAG_BLOCKSVIEW); 361 SET_FLAG (op, FLAG_BLOCKSVIEW);
404 update_all_los (op->map, op->x, op->y); 362 update_all_los (op->map, op->x, op->y);
405 } 363 }
406 } /* gate is halfway up */ 364 } /* gate is halfway up */
407 365
420 int v = op->value; 378 int v = op->value;
421 379
422 if (op->stats.sp) 380 if (op->stats.sp)
423 { 381 {
424 move_gate (op); 382 move_gate (op);
383
425 if (op->value != v) /* change direction ? */ 384 if (op->value != v) /* change direction ? */
426 op->stats.sp = 0; 385 op->stats.sp = 0;
427 return; 386 return;
428 } 387 }
388
429 if (--op->stats.hp <= 0) 389 if (--op->stats.hp <= 0)
430 { /* keep gate down */ 390 { /* keep gate down */
431 move_gate (op); 391 move_gate (op);
392
432 if (op->value != v) 393 if (op->value != v)
433 op->set_speed (0); 394 op->set_speed (0);
434 } 395 }
435} 396}
436 397
448 int last = op->value; 409 int last = op->value;
449 int detected; 410 int detected;
450 411
451 detected = 0; 412 detected = 0;
452 413
453 for (tmp = GET_MAP_OB (op->map, op->x, op->y); tmp != NULL && !detected; tmp = tmp->above) 414 for (tmp = op->ms ().bot; tmp && !detected; tmp = tmp->above)
454 { 415 {
455 object *tmp2; 416 object *tmp2;
456 417
457 if (op->stats.hp) 418 if (op->stats.hp)
458 { 419 {
459 for (tmp2 = tmp->inv; tmp2; tmp2 = tmp2->below) 420 for (tmp2 = tmp->inv; tmp2; tmp2 = tmp2->below)
460 { 421 {
461 if (op->slaying && !strcmp (op->slaying, tmp->name)) 422 if (op->slaying && op->slaying == tmp->name)
462 detected = 1; 423 detected = 1;
424
463 if (tmp2->type == FORCE && tmp2->slaying && !strcmp (tmp2->slaying, op->slaying)) 425 if (tmp2->type == FORCE && tmp2->slaying && tmp2->slaying == op->slaying)
464 detected = 1; 426 detected = 1;
465 } 427 }
466 } 428 }
429
467 if (op->slaying && !strcmp (op->slaying, tmp->name)) 430 if (op->slaying && op->slaying == tmp->name)
468 {
469 detected = 1; 431 detected = 1;
470 }
471 else if (tmp->type == SPECIAL_KEY && tmp->slaying == op->slaying) 432 else if (tmp->type == SPECIAL_KEY && tmp->slaying == op->slaying)
472 detected = 1; 433 detected = 1;
473 } 434 }
474 435
475 /* the detector sets the button if detection is found */ 436 /* the detector sets the button if detection is found */
478 if (detected && last == 0) 439 if (detected && last == 0)
479 { 440 {
480 op->value = 1; 441 op->value = 1;
481 push_button (op); 442 push_button (op);
482 } 443 }
444
483 if (!detected && last == 1) 445 if (!detected && last == 1)
484 { 446 {
485 op->value = 0; 447 op->value = 0;
486 push_button (op); 448 push_button (op);
487 } 449 }
491 if (detected && last == 1) 453 if (detected && last == 1)
492 { 454 {
493 op->value = 0; 455 op->value = 0;
494 push_button (op); 456 push_button (op);
495 } 457 }
458
496 if (!detected && last == 0) 459 if (!detected && last == 0)
497 { 460 {
498 op->value = 1; 461 op->value = 1;
499 push_button (op); 462 push_button (op);
500 } 463 }
501 } 464 }
502} 465}
503
504 466
505void 467void
506animate_trigger (object *op) 468animate_trigger (object *op)
507{ 469{
508 if ((unsigned char) ++op->stats.wc >= NUM_ANIMATIONS (op)) 470 if ((unsigned char) ++op->stats.wc >= NUM_ANIMATIONS (op))
540 502
541 SET_ANIMATION (op, op->stats.wc); 503 SET_ANIMATION (op, op->stats.wc);
542 update_object (op, UP_OBJ_FACE); 504 update_object (op, UP_OBJ_FACE);
543 return; 505 return;
544 } 506 }
507
545 /* We're closing */ 508 /* We're closing */
546 op->move_on = 0; 509 op->move_on = 0;
547 510
548 op->stats.wc++; 511 op->stats.wc++;
549 if ((int) op->stats.wc >= NUM_ANIMATIONS (op)) 512 if ((int) op->stats.wc >= NUM_ANIMATIONS (op))
586 op->destroy (); 549 op->destroy ();
587 return payload; 550 return payload;
588 } 551 }
589 552
590 case ARROW: 553 case ARROW:
591 if (op->speed >= MIN_ACTIVE_SPEED) 554 if (op->has_active_speed ())
592 op = fix_stopped_arrow (op); 555 op = fix_stopped_arrow (op);
593 return op; 556 return op;
594 557
595 default: 558 default:
596 return op; 559 return op;
605void 568void
606fix_stopped_item (object *op, maptile *map, object *originator) 569fix_stopped_item (object *op, maptile *map, object *originator)
607{ 570{
608 if (map == NULL) 571 if (map == NULL)
609 return; 572 return;
573
610 if (QUERY_FLAG (op, FLAG_REMOVED)) 574 if (QUERY_FLAG (op, FLAG_REMOVED))
611 insert_ob_in_map (op, map, originator, 0); 575 insert_ob_in_map (op, map, originator, 0);
612 else if (op->type == ARROW) 576 else if (op->type == ARROW)
613 merge_ob (op, NULL); /* only some arrows actually need this */ 577 merge_ob (op, NULL); /* only some arrows actually need this */
614} 578}
615 579
616
617object * 580object *
618fix_stopped_arrow (object *op) 581fix_stopped_arrow (object *op)
619{ 582{
620 if (rndm (0, 99) < op->stats.food) 583 if (rndm (0, 99) < op->stats.food)
621 { 584 {
624 return NULL; 587 return NULL;
625 } 588 }
626 589
627 op->set_speed (0); 590 op->set_speed (0);
628 op->direction = 0; 591 op->direction = 0;
629 op->move_on = 0; 592 op->move_on = 0;
630 op->move_type = 0; 593 op->move_type = 0;
594 op->skill = 0; // really?
595
596 // restore original wc, dam, attacktype and slaying
631 op->stats.wc = op->stats.sp; 597 op->stats.wc = op->stats.sp;
632 op->stats.dam = op->stats.hp; 598 op->stats.dam = op->stats.hp;
633 op->attacktype = op->stats.grace; 599 op->attacktype = op->stats.grace;
634 op->slaying = 0;
635 op->skill = 0;
636 600
637 if (op->spellarg != NULL) 601 if (op->spellarg)
638 { 602 {
639 op->slaying = op->spellarg; 603 op->slaying = op->spellarg;
640 free (op->spellarg); 604 free (op->spellarg);
641 op->spellarg = NULL; 605 op->spellarg = 0;
642 } 606 }
643 else 607 else
644 op->slaying = NULL; 608 op->slaying = 0;
645 609
646 /* Reset these to zero, so that object::can_merge will work properly */ 610 /* Reset these to zero, so that object::can_merge will work properly */
647 op->spellarg = NULL; 611 op->spellarg = NULL;
648 op->stats.sp = 0; 612 op->stats.sp = 0;
649 op->stats.hp = 0; 613 op->stats.hp = 0;
650 op->stats.grace = 0; 614 op->stats.grace = 0;
651 op->level = 0; 615 op->level = 0;
652 op->face = op->arch->clone.face; 616 op->face = op->arch->face;
653 op->owner = NULL; /* So that stopped arrows will be saved */ 617 op->owner = NULL; /* So that stopped arrows will be saved */
654 update_object (op, UP_OBJ_FACE); 618 update_object (op, UP_OBJ_CHANGE);
655 return op; 619 return op;
656} 620}
657 621
658/* stop_arrow() - what to do when a non-living flying object 622/* stop_arrow() - what to do when a non-living flying object
659 * has to stop. Sept 96 - I added in thrown object code in 623 * has to stop. Sept 96 - I added in thrown object code in
660 * here too. -b.t. 624 * here too. -b.t.
661 * 625 *
662 * Returns a pointer to the stopped object (which will have been removed 626 * Returns a pointer to the stopped object (which will have been removed
663 * from maps or inventories), or NULL if was destroyed. 627 * from maps or inventories), or NULL if was destroyed.
664 */ 628 */
665
666static void 629static void
667stop_arrow (object *op) 630stop_arrow (object *op)
668{ 631{
669 if (INVOKE_OBJECT (STOP, op)) 632 if (INVOKE_OBJECT (STOP, op))
670 return; 633 return;
679 op->destroy (); 642 op->destroy ();
680 } 643 }
681 else 644 else
682 { 645 {
683 op = fix_stopped_arrow (op); 646 op = fix_stopped_arrow (op);
647
684 if (op) 648 if (op)
685 merge_ob (op, NULL); 649 merge_ob (op, 0);
686 } 650 }
687} 651}
688 652
689/* Move an arrow along its course. op is the arrow or thrown object. 653/* Move an arrow along its course. op is the arrow or thrown object.
690 */ 654 */
691
692void 655void
693move_arrow (object *op) 656move_arrow (object *op)
694{ 657{
695 object *tmp;
696 sint16 new_x, new_y;
697 int was_reflected, mflags; 658 int was_reflected;
698 maptile *m;
699 659
700 if (op->map == NULL) 660 if (!op->map)
701 { 661 {
702 LOG (llevError, "BUG: Arrow had no map.\n"); 662 LOG (llevError, "BUG: Arrow had no map.\n");
703 op->destroy (); 663 op->destroy ();
704 return; 664 return;
705 } 665 }
735 stop_arrow (op); 695 stop_arrow (op);
736 return; 696 return;
737 } 697 }
738 698
739 /* Calculate target map square */ 699 /* Calculate target map square */
740 new_x = op->x + DIRX (op);
741 new_y = op->y + DIRY (op);
742 was_reflected = 0; 700 was_reflected = 0;
743 701
744 m = op->map; 702 mapxy pos (op); pos.move (op->direction);
745 mflags = get_map_flags (m, &m, new_x, new_y, &new_x, &new_y);
746 703
747 if (mflags & P_OUT_OF_MAP) 704 if (!pos.normalise ())
748 { 705 {
749 stop_arrow (op); 706 stop_arrow (op);
750 return; 707 return;
751 } 708 }
752 709
753 /* only need to look for living creatures if this flag is set */ 710 /* only need to look for living creatures if this flag is set */
754 if (mflags & P_IS_ALIVE) 711 if (pos->flags () & P_IS_ALIVE)
755 { 712 {
756 for (tmp = GET_MAP_OB (m, new_x, new_y); tmp != NULL; tmp = tmp->above) 713 object *tmp;
714
715 for (tmp = pos->bot; tmp; tmp = tmp->above)
757 if (QUERY_FLAG (tmp, FLAG_ALIVE)) 716 if (QUERY_FLAG (tmp, FLAG_ALIVE))
758 break; 717 break;
759 718
760 /* Not really fair, but don't let monsters hit themselves with 719 /* Not really fair, but don't let monsters hit themselves with
761 * their own arrow - this can be because they fire it then 720 * their own arrow - this can be because they fire it then
767 * as below. (Note that for living creatures there is a small 726 * as below. (Note that for living creatures there is a small
768 * chance that reflect_missile fails.) 727 * chance that reflect_missile fails.)
769 */ 728 */
770 if (QUERY_FLAG (tmp, FLAG_REFL_MISSILE) && (rndm (0, 99)) < (90 - op->level / 10)) 729 if (QUERY_FLAG (tmp, FLAG_REFL_MISSILE) && (rndm (0, 99)) < (90 - op->level / 10))
771 { 730 {
772 int number = op->face->number; 731 int number = op->face;
773 732
774 op->direction = absdir (op->direction + 4); 733 op->direction = absdir (op->direction + 4);
775 op->state = 0; 734 update_turn_face (op);
776
777 if (GET_ANIM_ID (op))
778 {
779 number += 4;
780
781 if (number > GET_ANIMATION (op, 8))
782 number -= 8;
783
784 op->face = &new_faces[number];
785 }
786
787 was_reflected = 1; /* skip normal movement calculations */ 735 was_reflected = 1; /* skip normal movement calculations */
788 } 736 }
789 else 737 else
790 { 738 {
791 /* Attack the object. */ 739 /* Attack the object. */
795 return; 743 return;
796 } 744 }
797 } /* if this is not hitting its owner */ 745 } /* if this is not hitting its owner */
798 } /* if there is something alive on this space */ 746 } /* if there is something alive on this space */
799 747
800 if (OB_TYPE_MOVE_BLOCK (op, GET_MAP_MOVE_BLOCK (m, new_x, new_y))) 748 if (OB_TYPE_MOVE_BLOCK (op, pos->move_block))
801 { 749 {
802 int retry = 0; 750 int retry = 0;
803 751
804 /* if the object doesn't reflect, stop the arrow from moving 752 /* if the object doesn't reflect, stop the arrow from moving
805 * note that this code will now catch cases where a monster is 753 * note that this code will now catch cases where a monster is
818 if (op->direction & 1) 766 if (op->direction & 1)
819 { 767 {
820 op->direction = absdir (op->direction + 4); 768 op->direction = absdir (op->direction + 4);
821 retry = 1; 769 retry = 1;
822 } 770 }
771
823 /* There were two blocks with identical code - 772 /* There were two blocks with identical code -
824 * use this retry here to make this one block 773 * use this retry here to make this one block
825 * that did the same thing. 774 * that did the same thing.
826 */ 775 */
827 while (retry < 2) 776 while (retry < 2)
828 { 777 {
829 int left, right, mflags;
830 maptile *m1;
831 sint16 x1, y1;
832
833 retry++; 778 retry++;
834 779
835 /* Need to check for P_OUT_OF_MAP: if the arrow is tavelling 780 /* Need to check for P_OUT_OF_MAP: if the arrow is travelling
836 * over a corner in a tiled map, it is possible that 781 * over a corner in a tiled map, it is possible that
837 * op->direction is within an adjacent map but either 782 * op->direction is within an adjacent map but either
838 * op->direction-1 or op->direction+1 does not exist. 783 * op->direction-1 or op->direction+1 does not exist.
839 */ 784 */
840 mflags = get_map_flags (op->map, &m1, op->x + freearr_x[absdir (op->direction - 1)], 785 mapxy pos1 (pos); pos1.move (absdir (op->direction - 1));
841 op->y + freearr_y[absdir (op->direction - 1)], &x1, &y1); 786 bool left = pos1.normalise () && OB_TYPE_MOVE_BLOCK (op, pos1->move_block);
842 left = (mflags & P_OUT_OF_MAP) ? 0 : OB_TYPE_MOVE_BLOCK (op, (GET_MAP_MOVE_BLOCK (m1, x1, y1)));
843 787
844 mflags = get_map_flags (op->map, &m1, op->x + freearr_x[absdir (op->direction + 1)], 788 mapxy pos2 (pos); pos2.move (absdir (op->direction + 1));
845 op->y + freearr_y[absdir (op->direction + 1)], &x1, &y1); 789 bool right = pos2.normalise () && OB_TYPE_MOVE_BLOCK (op, pos2->move_block);
846 right = (mflags & P_OUT_OF_MAP) ? 0 : OB_TYPE_MOVE_BLOCK (op, (GET_MAP_MOVE_BLOCK (m1, x1, y1)));
847 790
848 if (left == right) 791 if (left == right)
849 op->direction = absdir (op->direction + 4); 792 op->direction = absdir (op->direction + 4);
850 else if (left) 793 else if (left)
851 op->direction = absdir (op->direction + 2); 794 op->direction = absdir (op->direction + 2);
852 else if (right) 795 else if (right)
853 op->direction = absdir (op->direction - 2); 796 op->direction = absdir (op->direction - 2);
854 797
855 mflags = get_map_flags (op->map, &m1, op->x + DIRX (op), op->y + DIRY (op), &x1, &y1);
856
857 /* If this space is not out of the map and not blocked, valid space - 798 /* If this space is not out of the map and not blocked, valid space -
858 * don't need to retry again. 799 * don't need to retry again.
859 */ 800 */
860 if (!(mflags & P_OUT_OF_MAP) && !OB_TYPE_MOVE_BLOCK (op, GET_MAP_MOVE_BLOCK (m1, x1, y1))) 801 mapxy pos3 (pos); pos3.move (op->direction);
802 if (pos3.normalise () && !OB_TYPE_MOVE_BLOCK (op, pos3->move_block))
861 break; 803 break;
862
863 } 804 }
805
864 /* Couldn't find a direction to move the arrow to - just 806 /* Couldn't find a direction to move the arrow to - just
865 * top it from moving. 807 * stop it from moving.
866 */ 808 */
867 if (retry == 2) 809 if (retry == 2)
868 { 810 {
869 stop_arrow (op); 811 stop_arrow (op);
870 return; 812 return;
871 } 813 }
814
872 /* update object image for new facing */ 815 /* update object image for new facing */
873 /* many thrown objects *don't* have more than one face */ 816 /* many thrown objects *don't* have more than one face */
874 if (GET_ANIM_ID (op)) 817 if (GET_ANIM_ID (op))
875 SET_ANIMATION (op, op->direction); 818 SET_ANIMATION (op, op->direction);
876 } /* object is reflected */ 819 } /* object is reflected */
877 } /* object ran into a wall */ 820 } /* object ran into a wall */
878 821
879 /* Move the arrow. */
880 op->remove ();
881 op->x = new_x;
882 op->y = new_y;
883
884 /* decrease the speed as it flies. 0.05 means a standard bow will shoot 822 /* decrease the speed as it flies. 0.05 means a standard bow will shoot
885 * about 17 squares. Tune as needed. 823 * about 17 squares. Tune as needed.
886 */ 824 */
887 op->speed -= 0.05; 825 op->speed -= 0.05;
888 insert_ob_in_map (op, m, op, 0);
889}
890 826
891/* This routine doesnt seem to work for "inanimate" objects that 827 /* Move the arrow. */
892 * are being carried, ie a held torch leaps from your hands!. 828 op->move_to (pos);
893 * Modified this routine to allow held objects. b.t. */ 829}
894 830
895void 831void
896change_object (object *op) 832change_object (object *op)
897{ /* Doesn`t handle linked objs yet */ 833{ /* Doesn`t handle linked objs yet */
898 int i, j; 834 int i, j;
899 835
900 if (op->other_arch == NULL) 836 if (!op->other_arch)
901 { 837 {
902 LOG (llevError, "Change object (%s) without other_arch error.\n", &op->name); 838 LOG (llevError, "Change object (%s) without other_arch error.\n", op->debug_desc ());
903 return; 839 return;
904 } 840 }
905 841
906 /* In non-living items only change when food value is 0 */ 842 /* In non-living items only change when food value is 0 */
907 if (!QUERY_FLAG (op, FLAG_ALIVE)) 843 if (!QUERY_FLAG (op, FLAG_ALIVE))
908 { 844 {
909 if (op->stats.food-- > 0) 845 if (op->stats.food-- > 0)
910 return; 846 return;
911 else 847
912 op->stats.food = 1; /* so 1 other_arch is made */ 848 op->stats.food = 1; /* so 1 other_arch is made */
913 } 849 }
914 850
915 object *pl = op->in_player ();
916 object *env = op->env; 851 object *env = op->env;
917 852
918 op->remove (); 853 op->remove ();
919 for (i = 0; i < NROFNEWOBJS (op); i++) 854 for (i = 0; i < op->stats.food; i++)
920 { 855 {
921 object *tmp = arch_to_object (op->other_arch); 856 object *tmp = arch_to_object (op->other_arch);
922 857
923 if (op->type == LAMP) 858 if (op->type == LAMP)
924 tmp->stats.food = op->stats.food - 1; 859 tmp->stats.food = op->stats.food - 1;
925 860
926 tmp->stats.hp = op->stats.hp; /* The only variable it keeps. */ 861 tmp->stats.hp = op->stats.hp; /* The only variable it keeps. */
927 if (env) 862 if (env)
928 { 863 {
929 tmp->x = env->x, tmp->y = env->y;
930 tmp = insert_ob_in_ob (tmp, env); 864 tmp = env->insert (tmp);
931 865
932 /* If this object is the players inventory, we need to tell the 866 /* If this object is the players inventory, we need to tell the
933 * client of the change. Insert_ob_in_map takes care of the 867 * client of the change. Insert_ob_in_map takes care of the
934 * updating the client, so we don't need to do that below. 868 * updating the client, so we don't need to do that below.
935 */ 869 */
936 if (pl) 870 if (object *pl = op->in_player ())
937 { 871 {
938 esrv_del_item (pl->contr, op->count); 872 esrv_del_item (pl->contr, op->count);
939 esrv_send_item (pl, tmp); 873 esrv_send_item (pl, tmp);
940 } 874 }
941 } 875 }
942 else 876 else
943 { 877 {
944 j = find_first_free_spot (tmp, op->map, op->x, op->y); 878 j = find_first_free_spot (tmp, op->map, op->x, op->y);
945 if (j == -1) /* No free spot */ 879 if (j < 0) /* No free spot */
946 tmp->destroy (); 880 tmp->destroy ();
947 else 881 else
948 { 882 {
949 tmp->x = op->x + freearr_x[j], tmp->y = op->y + freearr_y[j]; 883 mapxy pos (op); pos.move (j);
950 insert_ob_in_map (tmp, op->map, op, 0); 884
885 if (pos.normalise ())
886 pos.insert (tmp, op);
951 } 887 }
952 } 888 }
953 } 889 }
954 890
955 op->destroy (); 891 op->destroy ();
965 * there is an old multipart teleporter in which the other parts 901 * there is an old multipart teleporter in which the other parts
966 * have speed, we don't really want to call it twice for the same 902 * have speed, we don't really want to call it twice for the same
967 * function - in fact, as written below, part N would get called 903 * function - in fact, as written below, part N would get called
968 * N times without the speed check. 904 * N times without the speed check.
969 */ 905 */
970 if (op->more && FABS (op->more->speed) < MIN_ACTIVE_SPEED) 906 if (op->more && !op->more->has_active_speed ())
971 move_teleporter (op->more); 907 move_teleporter (op->more);
972 908
973 if (op->head) 909 if (op->head)
974 head = op->head; 910 head = op->head;
975 911
976 for (tmp = op->above; tmp != NULL; tmp = tmp->above) 912 for (tmp = op->above; tmp; tmp = tmp->above)
977 if (!QUERY_FLAG (tmp, FLAG_IS_FLOOR)) 913 if (!QUERY_FLAG (tmp, FLAG_IS_FLOOR))
978 break; 914 break;
979 915
980 /* If nothing above us to move, nothing to do */ 916 /* If nothing above us to move, nothing to do */
981 if (!tmp || QUERY_FLAG (tmp, FLAG_WIZPASS)) 917 if (!tmp || QUERY_FLAG (tmp, FLAG_WIZPASS))
986 if (tmp->type == PLAYER) 922 if (tmp->type == PLAYER)
987 { 923 {
988 if (INVOKE_OBJECT (TRIGGER, op, ARG_OBJECT (tmp))) 924 if (INVOKE_OBJECT (TRIGGER, op, ARG_OBJECT (tmp)))
989 return; 925 return;
990 926
991 enter_exit (tmp, head); 927 tmp->enter_exit (head);
992 } 928 }
993 else 929 else
994 /* Currently only players can transfer maps */ 930 /* Currently only players can transfer maps */
995 return; 931 return;
996 } 932 }
1014 if (INVOKE_OBJECT (TRIGGER, op, ARG_OBJECT (tmp))) 950 if (INVOKE_OBJECT (TRIGGER, op, ARG_OBJECT (tmp)))
1015 return; 951 return;
1016 teleport (head, TELEPORTER, tmp); 952 teleport (head, TELEPORTER, tmp);
1017 } 953 }
1018} 954}
1019
1020 955
1021/* This object will teleport someone to a different map 956/* This object will teleport someone to a different map
1022 and will also apply changes to the player from its inventory. 957 and will also apply changes to the player from its inventory.
1023 This was invented for giving classes, but there's no reason it 958 This was invented for giving classes, but there's no reason it
1024 can't be generalized. 959 can't be generalized.
1025*/ 960*/
1026
1027void 961void
1028move_player_changer (object *op) 962move_player_changer (object *op)
1029{ 963{
1030 object *player; 964 object *player;
1031 object *walk; 965 object *walk;
1032 char c;
1033 966
1034 if (!op->above || !EXIT_PATH (op)) 967 if (!op->above || !EXIT_PATH (op))
1035 return; 968 return;
1036 969
1037 /* This isn't all that great - means that the player_mover 970 /* This isn't all that great - means that the player_mover
1038 * needs to be on top. 971 * needs to be on top.
1039 */ 972 */
1040 if (op->above->type == PLAYER) 973 if (op->above->type == PLAYER)
1041 { 974 {
1042 if (INVOKE_OBJECT (TRIGGER, op, ARG_OBJECT (player))) 975 if (INVOKE_OBJECT (TRIGGER, op, ARG_OBJECT (player)))
1043 return; 976 return;
977
1044 player = op->above; 978 player = op->above;
1045 979
1046 for (walk = op->inv; walk != NULL; walk = walk->below) 980 for (walk = op->inv; walk; walk = walk->below)
1047 apply_changes_to_player (player, walk); 981 apply_changes_to_player (player, walk);
1048 982
1049 player->update_stats (); 983 player->update_stats ();
1050 984
1051 esrv_send_inventory (op->above, op->above); 985 esrv_send_inventory (op->above, op->above);
1052 esrv_update_item (UPD_FACE, op->above, op->above); 986 esrv_update_item (UPD_FACE, op->above, op->above);
1053 987
1054 /* update players death & WoR home-position */ 988 /* update players death & WoR home-position */
1055 sscanf (EXIT_PATH (op), "%c", &c); 989 if (*EXIT_PATH (op) == '/')
1056 if (c == '/')
1057 { 990 {
1058 strcpy (player->contr->savebed_map, EXIT_PATH (op)); 991 player->contr->savebed_map = EXIT_PATH (op);
1059 player->contr->bed_x = EXIT_X (op); 992 player->contr->bed_x = EXIT_X (op);
1060 player->contr->bed_y = EXIT_Y (op); 993 player->contr->bed_y = EXIT_Y (op);
1061 } 994 }
1062 else 995 else
1063 LOG (llevDebug, "WARNING: destination '%s' in player_changer must be an absolute path!\n", &EXIT_PATH (op)); 996 LOG (llevDebug, "WARNING: destination '%s' in player_changer must be an absolute path!\n", &EXIT_PATH (op));
1064 997
1065 enter_exit (op->above, op); 998 op->above->enter_exit (op);
1066 player->contr->save ();
1067 } 999 }
1068} 1000}
1069 1001
1070/* firewalls fire other spells. 1002/* firewalls fire other spells.
1071 * The direction of the wall is stored in op->stats.sp. 1003 * The direction of the wall is stored in op->stats.sp.
1080 return; /* dm has created a firewall in his inventory */ 1012 return; /* dm has created a firewall in his inventory */
1081 1013
1082 spell = op->inv; 1014 spell = op->inv;
1083 1015
1084 if (!spell || spell->type != SPELL) 1016 if (!spell || spell->type != SPELL)
1085 spell = &op->other_arch->clone; 1017 spell = op->other_arch;
1086 1018
1087 if (!spell) 1019 if (!spell)
1088 { 1020 {
1089 LOG (llevError, "move_firewall: no spell specified (%s, %s, %d, %d)\n", &op->name, op->map->name, op->x, op->y); 1021 LOG (llevError, "move_firewall: no spell specified (%s, %s, %d, %d)\n", &op->name, &op->map->name, op->x, op->y);
1090 return; 1022 return;
1091 } 1023 }
1092 1024
1093 cast_spell (op, op, op->stats.sp ? op->stats.sp : rndm (1, 8), spell, NULL); 1025 cast_spell (op, op, op->stats.sp ? op->stats.sp : rndm (1, 8), spell, NULL);
1094} 1026}
1103 * it'll paralyze the victim for hp*his speed/op->speed 1035 * it'll paralyze the victim for hp*his speed/op->speed
1104 */ 1036 */
1105void 1037void
1106move_player_mover (object *op) 1038move_player_mover (object *op)
1107{ 1039{
1108 object *victim, *nextmover;
1109 int dir = op->stats.sp; 1040 int dir = op->stats.sp;
1110 sint16 nx, ny; 1041 sint16 nx, ny;
1111 maptile *m; 1042 maptile *m;
1112 1043
1113 /* Determine direction now for random movers so we do the right thing */ 1044 /* Determine direction now for random movers so we do the right thing */
1114 if (!dir) 1045 if (!dir)
1115 dir = rndm (1, 8); 1046 dir = rndm (1, 8);
1116 1047
1117 for (victim = GET_MAP_OB (op->map, op->x, op->y); victim != NULL; victim = victim->above) 1048 for (object *victim = op->ms ().bot; victim; victim = victim->above)
1118 { 1049 {
1119 if (QUERY_FLAG (victim, FLAG_ALIVE) && !QUERY_FLAG (victim, FLAG_WIZPASS) && 1050 if (QUERY_FLAG (victim, FLAG_ALIVE) && !QUERY_FLAG (victim, FLAG_WIZPASS) &&
1120 (victim->move_type & op->move_type || !victim->move_type)) 1051 (victim->move_type & op->move_type || !victim->move_type))
1121 { 1052 {
1122 1053
1132 nx = op->x + freearr_x[dir]; 1063 nx = op->x + freearr_x[dir];
1133 ny = op->y + freearr_y[dir]; 1064 ny = op->y + freearr_y[dir];
1134 m = op->map; 1065 m = op->map;
1135 if (get_map_flags (m, &m, nx, ny, &nx, &ny) & P_OUT_OF_MAP) 1066 if (get_map_flags (m, &m, nx, ny, &nx, &ny) & P_OUT_OF_MAP)
1136 { 1067 {
1137 LOG (llevError, "move_player_mover: Trying to push player off the map! map=%s (%d, %d)\n", m->path, op->x, op->y); 1068 LOG (llevError, "move_player_mover: Trying to push player off the map! map=%s (%d, %d)\n", &m->path, op->x, op->y);
1138 return; 1069 return;
1139 } 1070 }
1140 1071
1141 if (should_director_abort (op, victim)) 1072 if (should_director_abort (op, victim))
1142 return; 1073 return;
1143 1074
1144 for (nextmover = GET_MAP_OB (m, nx, ny); nextmover != NULL; nextmover = nextmover->above) 1075 for (object *nextmover = m->at (nx, ny).bot; nextmover; nextmover = nextmover->above)
1145 { 1076 {
1146 if (nextmover->type == PLAYERMOVER) 1077 if (nextmover->type == PLAYERMOVER)
1147 nextmover->speed_left = -.99; 1078 nextmover->speed_left = -.99f;
1079
1148 if (QUERY_FLAG (nextmover, FLAG_ALIVE)) 1080 if (QUERY_FLAG (nextmover, FLAG_ALIVE))
1149 {
1150 op->speed_left = -1.1; /* wait until the next thing gets out of the way */ 1081 op->speed_left = -1.1f; /* wait until the next thing gets out of the way */
1151 }
1152 } 1082 }
1153 1083
1154 if (victim->type == PLAYER) 1084 if (victim->type == PLAYER)
1155 { 1085 {
1156 /* only level >=1 movers move people */ 1086 /* only level >=1 movers move people */
1160 * is cleared, otherwise the player will get stuck in 1090 * is cleared, otherwise the player will get stuck in
1161 * place. This can happen if the player used a spell to 1091 * place. This can happen if the player used a spell to
1162 * get to this space. 1092 * get to this space.
1163 */ 1093 */
1164 victim->contr->fire_on = 0; 1094 victim->contr->fire_on = 0;
1165 victim->speed_left = -FABS (victim->speed); 1095 victim->speed_left = 1.f;
1166 move_player (victim, dir); 1096 move_player (victim, dir);
1167 } 1097 }
1168 else 1098 else
1169 return; 1099 return;
1170 } 1100 }
1174 if (!op->stats.maxsp && op->attacktype) 1104 if (!op->stats.maxsp && op->attacktype)
1175 op->stats.maxsp = 2; 1105 op->stats.maxsp = 2;
1176 1106
1177 if (op->attacktype) 1107 if (op->attacktype)
1178 { /* flag to paralyze the player */ 1108 { /* flag to paralyze the player */
1179
1180 victim->speed_left = -FABS (op->stats.maxsp * victim->speed / op->speed); 1109 victim->speed_left = max (-5.f, -FABS (op->stats.maxsp * victim->speed / op->speed));
1181 /* Not sure why, but for some chars on metalforge, they
1182 * would sometimes get -inf speed_left, and from the
1183 * description, it could only happen here, so just put
1184 * a lower sanity limit. My only guess is that the
1185 * mover has 0 speed.
1186 */
1187 if (victim->speed_left < -5.0)
1188 victim->speed_left = -5.0;
1189 } 1110 }
1190 } 1111 }
1191 } 1112 }
1192} 1113}
1193 1114
1203{ 1124{
1204 object *tmp; 1125 object *tmp;
1205 1126
1206 if (!op->other_arch) 1127 if (!op->other_arch)
1207 { 1128 {
1208 LOG (llevInfo, "Duplicator with no other_arch! %d %d %s\n", op->x, op->y, op->map ? op->map->path : "nullmap"); 1129 LOG (llevInfo, "Duplicator with no other_arch! %d %d %s\n", op->x, op->y, op->map ? &op->map->path : "nullmap");
1209 return; 1130 return;
1210 } 1131 }
1211 1132
1212 if (op->above == NULL) 1133 if (op->above == NULL)
1213 return; 1134 return;
1135
1214 for (tmp = op->above; tmp != NULL; tmp = tmp->above) 1136 for (tmp = op->above; tmp; tmp = tmp->above)
1215 { 1137 {
1216 if (strcmp (op->other_arch->name, tmp->arch->name) == 0) 1138 if (op->other_arch->archname == tmp->arch->archname)
1217 { 1139 {
1218 if (op->level <= 0) 1140 if (op->level <= 0)
1219 tmp->destroy (); 1141 tmp->destroy ();
1220 else 1142 else
1221 { 1143 {
1243 * has to make sure that there is in fact space for the object. 1165 * has to make sure that there is in fact space for the object.
1244 * It should really do this for small objects also, but there is 1166 * It should really do this for small objects also, but there is
1245 * more concern with large objects, most notably a part being placed 1167 * more concern with large objects, most notably a part being placed
1246 * outside of the map which would cause the server to crash 1168 * outside of the map which would cause the server to crash
1247*/ 1169*/
1248
1249void 1170void
1250move_creator (object *creator) 1171move_creator (object *creator)
1251{ 1172{
1252 object *new_ob; 1173 object *new_ob;
1253 1174
1278 } 1199 }
1279 else 1200 else
1280 { 1201 {
1281 if (creator->other_arch == NULL) 1202 if (creator->other_arch == NULL)
1282 { 1203 {
1283 LOG (llevError, "move_creator: Creator doesn't have other arch set: %s (%s, %d, %d)\n", &creator->name, creator->map->path, 1204 LOG (llevError, "move_creator: Creator doesn't have other arch set: %s (%s, %d, %d)\n",
1284 creator->x, creator->y); 1205 &creator->name, &creator->map->path, creator->x, creator->y);
1285 return; 1206 return;
1286 } 1207 }
1287 1208
1288 new_ob = object_create_arch (creator->other_arch); 1209 new_ob = object_create_arch (creator->other_arch);
1289 fix_generated_item (new_ob, creator, 0, 0, GT_MINIMAL); 1210 fix_generated_item (new_ob, creator, 0, 0, GT_MINIMAL);
1290 } 1211 }
1291 1212
1292 /* Make sure this multipart object fits */ 1213 /* Make sure this multipart object fits */
1293 if (new_ob->arch->more && ob_blocked (new_ob, creator->map, creator->x, creator->y)) 1214 if (new_ob->arch->more && new_ob->blocked (creator->map, creator->x, creator->y))
1294 { 1215 {
1295 new_ob->destroy (); 1216 new_ob->destroy ();
1296 return; 1217 return;
1297 } 1218 }
1219
1220 // for now lets try to identify everything generated here, it mostly
1221 // happens automated, so this will at least fix many identify-experience holes
1222 SET_FLAG (new_ob, FLAG_IDENTIFIED);
1298 1223
1299 insert_ob_in_map_at (new_ob, creator->map, creator, 0, creator->x, creator->y); 1224 insert_ob_in_map_at (new_ob, creator->map, creator, 0, creator->x, creator->y);
1300 if (QUERY_FLAG (new_ob, FLAG_FREED)) 1225 if (QUERY_FLAG (new_ob, FLAG_FREED))
1301 return; 1226 return;
1302 1227
1312 with a specific code as the slaying field. 1237 with a specific code as the slaying field.
1313 At that time, it writes the contents of its own message 1238 At that time, it writes the contents of its own message
1314 field to the player. The marker will decrement hp to 1239 field to the player. The marker will decrement hp to
1315 0 and then delete itself every time it grants a mark. 1240 0 and then delete itself every time it grants a mark.
1316 unless hp was zero to start with, in which case it is infinite.*/ 1241 unless hp was zero to start with, in which case it is infinite.*/
1317
1318void 1242void
1319move_marker (object *op) 1243move_marker (object *op)
1320{ 1244{
1321 if (object *tmp = op->ms ().player ()) 1245 if (object *tmp = op->ms ().player ())
1322 { 1246 {
1323 object *tmp2;
1324
1325 /* remove an old force with a slaying field == op->name */ 1247 /* remove an old force with a slaying field == op->name */
1326 for (tmp2 = tmp->inv; tmp2; tmp2 = tmp2->below) 1248 if (object *force = tmp->force_find (op->name))
1327 if (tmp2->type == FORCE && tmp2->slaying && !strcmp (tmp2->slaying, op->name)) 1249 force->destroy ();
1250
1251 if (!tmp->force_find (op->slaying))
1328 { 1252 {
1329 tmp2->destroy (); 1253 tmp->force_add (op->slaying, op->stats.food);
1330 break;
1331 }
1332 1254
1333 /* cycle through his inventory to look for the MARK we want to
1334 * place
1335 */
1336 for (tmp2 = tmp->inv; tmp2; tmp2 = tmp2->below)
1337 if (tmp2->type == FORCE && tmp2->slaying && !strcmp (tmp2->slaying, op->slaying))
1338 break;
1339
1340 /* if we didn't find our own MARK */
1341 if (tmp2 == NULL)
1342 {
1343 object *force = get_archetype (FORCE_NAME);
1344
1345 if (op->stats.food)
1346 {
1347 force->set_speed (0.01);
1348 force->speed_left = -op->stats.food;
1349 }
1350 else
1351 force->set_speed (0);
1352
1353 /* put in the lock code */
1354 force->slaying = op->slaying;
1355
1356 if (op->lore)
1357 force->lore = op->lore;
1358
1359 insert_ob_in_ob (force, tmp);
1360 if (op->msg) 1255 if (op->msg)
1361 new_draw_info (NDI_UNIQUE | NDI_NAVY, 0, tmp, op->msg); 1256 new_draw_info (NDI_UNIQUE | NDI_NAVY, 0, tmp, op->msg);
1362 1257
1363 if (op->stats.hp > 0) 1258 if (op->stats.hp > 0)
1364 { 1259 {
1365 op->stats.hp--; 1260 op->stats.hp--;
1261
1366 if (op->stats.hp == 0) 1262 if (op->stats.hp == 0)
1367 { 1263 {
1368 /* marker expires--granted mark number limit */ 1264 /* marker expires--granted mark number limit */
1369 op->destroy (); 1265 op->destroy ();
1370 return; 1266 return;
1372 } 1268 }
1373 } 1269 }
1374 } 1270 }
1375} 1271}
1376 1272
1377int 1273void
1378process_object (object *op) 1274process_object (object *op)
1379{ 1275{
1380 if (QUERY_FLAG (op, FLAG_IS_A_TEMPLATE)) 1276 if (expect_false (QUERY_FLAG (op, FLAG_IS_A_TEMPLATE)))
1381 return 0; 1277 return;
1382 1278
1383 if (INVOKE_OBJECT (TICK, op)) 1279 if (expect_false (INVOKE_OBJECT (TICK, op)))
1384 return 0; 1280 return;
1385 1281
1386 if (QUERY_FLAG (op, FLAG_MONSTER)) 1282 if (QUERY_FLAG (op, FLAG_MONSTER))
1387 if (move_monster (op) || QUERY_FLAG (op, FLAG_FREED)) 1283 if (move_monster (op) || QUERY_FLAG (op, FLAG_FREED))
1388 return 1; 1284 return;
1389 1285
1390 if (QUERY_FLAG (op, FLAG_ANIMATE) && op->anim_speed == 0) 1286 if (QUERY_FLAG (op, FLAG_ANIMATE) && op->anim_speed == 0)
1391 { 1287 {
1392 if (op->type == PLAYER)
1393 animate_object (op, op->facing);
1394 else
1395 animate_object (op, op->direction); 1288 animate_object (op, op->contr ? op->facing : op->direction);
1396 1289
1397 if (QUERY_FLAG (op, FLAG_SEE_ANYWHERE)) 1290 if (QUERY_FLAG (op, FLAG_SEE_ANYWHERE))
1398 make_sure_seen (op); 1291 make_sure_seen (op);
1399 } 1292 }
1400 1293
1294 if (expect_false (
1295 op->flag [FLAG_GENERATOR]
1296 || op->flag [FLAG_CHANGING]
1297 || op->flag [FLAG_IS_USED_UP]
1298 ))
1299 {
1401 if (QUERY_FLAG (op, FLAG_CHANGING) && !op->state) 1300 if (QUERY_FLAG (op, FLAG_CHANGING) && !op->state)
1402 { 1301 {
1403 change_object (op); 1302 change_object (op);
1404 return 1; 1303 return;
1405 } 1304 }
1406 1305
1407 if (QUERY_FLAG (op, FLAG_GENERATOR) && !QUERY_FLAG (op, FLAG_FRIENDLY)) 1306 if (QUERY_FLAG (op, FLAG_GENERATOR) && !QUERY_FLAG (op, FLAG_FRIENDLY))
1408 generate_monster (op); 1307 generate_monster (op);
1409 1308
1410 if (QUERY_FLAG (op, FLAG_IS_USED_UP) && --op->stats.food <= 0) 1309 if (QUERY_FLAG (op, FLAG_IS_USED_UP) && --op->stats.food <= 0)
1411 { 1310 {
1412 if (QUERY_FLAG (op, FLAG_APPLIED)) 1311 if (QUERY_FLAG (op, FLAG_APPLIED))
1413 remove_force (op); 1312 remove_force (op);
1414 else 1313 else
1415 { 1314 {
1416 /* IF necessary, delete the item from the players inventory */ 1315 /* If necessary, delete the item from the players inventory */
1417 object *pl = op->in_player (); 1316 if (object *pl = op->in_player ())
1418
1419 if (pl)
1420 esrv_del_item (pl->contr, op->count); 1317 esrv_del_item (pl->contr, op->count);
1421 1318
1422 op->remove (); 1319 op->remove ();
1423 1320
1424 if (QUERY_FLAG (op, FLAG_SEE_ANYWHERE)) 1321 if (QUERY_FLAG (op, FLAG_SEE_ANYWHERE))
1425 make_sure_not_seen (op); 1322 make_sure_not_seen (op);
1426 1323
1427 op->destroy (); 1324 op->destroy ();
1428 } 1325 }
1429 1326
1430 return 1; 1327 return;
1328 }
1431 } 1329 }
1432 1330
1433 switch (op->type) 1331 switch (op->type)
1434 { 1332 {
1435 case SPELL_EFFECT: 1333 case SPELL_EFFECT:
1436 move_spell_effect (op); 1334 move_spell_effect (op);
1437 return 1; 1335 break;
1438 1336
1439 case ROD: 1337 case ROD:
1440 case HORN: 1338 case HORN:
1441 regenerate_rod (op); 1339 regenerate_rod (op);
1442 return 1; 1340 break;
1443 1341
1444 case FORCE: 1342 case FORCE:
1445 case POTION_EFFECT: 1343 case POTION_EFFECT:
1446 remove_force (op); 1344 remove_force (op);
1447 return 1; 1345 break;
1448 1346
1449 case BLINDNESS: 1347 case BLINDNESS:
1450 remove_blindness (op); 1348 remove_blindness (op);
1451 return 0; 1349 break;
1452 1350
1453 case POISONING: 1351 case POISONING:
1454 poison_more (op); 1352 poison_more (op);
1455 return 0; 1353 break;
1456 1354
1457 case DISEASE: 1355 case DISEASE:
1458 move_disease (op); 1356 move_disease (op);
1459 return 0; 1357 break;
1460 1358
1461 case SYMPTOM: 1359 case SYMPTOM:
1462 move_symptom (op); 1360 move_symptom (op);
1463 return 0; 1361 break;
1464 1362
1465 case THROWN_OBJ: 1363 case THROWN_OBJ:
1466 case ARROW: 1364 case ARROW:
1467 move_arrow (op); 1365 move_arrow (op);
1468 return 0; 1366 break;
1469 1367
1470 case DOOR: 1368 case DOOR:
1471 remove_door (op); 1369 remove_door (op);
1472 return 0; 1370 break;
1473 1371
1474 case LOCKED_DOOR: 1372 case LOCKED_DOOR:
1475 remove_door2 (op); 1373 remove_door2 (op);
1476 return 0; 1374 break;
1477 1375
1478 case TELEPORTER: 1376 case TELEPORTER:
1479 move_teleporter (op); 1377 move_teleporter (op);
1480 return 0; 1378 break;
1481 1379
1482 case GOLEM: 1380 case GOLEM:
1483 move_golem (op); 1381 move_golem (op);
1484 return 0; 1382 break;
1485 1383
1486 case EARTHWALL: 1384 case EARTHWALL:
1487 hit_player (op, 2, op, AT_PHYSICAL, 1); 1385 hit_player (op, 2, op, AT_PHYSICAL, 1);
1488 return 0; 1386 break;
1489 1387
1490 case FIREWALL: 1388 case FIREWALL:
1491 move_firewall (op); 1389 move_firewall (op);
1492 if (op->stats.maxsp) 1390 if (op->stats.maxsp)
1493 animate_turning (op); 1391 animate_turning (op);
1494 return 0; 1392 break;
1495 1393
1496 case MOOD_FLOOR: 1394 case MOOD_FLOOR:
1497 do_mood_floor (op); 1395 do_mood_floor (op);
1498 return 0; 1396 break;
1499 1397
1500 case GATE: 1398 case GATE:
1501 move_gate (op); 1399 move_gate (op);
1502 return 0; 1400 break;
1503 1401
1504 case TIMED_GATE: 1402 case TIMED_GATE:
1505 move_timed_gate (op); 1403 move_timed_gate (op);
1506 return 0; 1404 break;
1507 1405
1508 case TRIGGER: 1406 case TRIGGER:
1509 case TRIGGER_BUTTON: 1407 case TRIGGER_BUTTON:
1510 case TRIGGER_PEDESTAL: 1408 case TRIGGER_PEDESTAL:
1511 case TRIGGER_ALTAR: 1409 case TRIGGER_ALTAR:
1512 animate_trigger (op); 1410 animate_trigger (op);
1513 return 0; 1411 break;
1514 1412
1515 case DETECTOR: 1413 case DETECTOR:
1516 move_detector (op); 1414 move_detector (op);
1517 1415
1518 case DIRECTOR: 1416 case DIRECTOR:
1519 if (op->stats.maxsp) 1417 if (op->stats.maxsp)
1520 animate_turning (op); 1418 animate_turning (op);
1521 return 0; 1419 break;
1522 1420
1523 case HOLE: 1421 case HOLE:
1524 move_hole (op); 1422 move_hole (op);
1525 return 0; 1423 break;
1526 1424
1527 case DEEP_SWAMP: 1425 case DEEP_SWAMP:
1528 move_deep_swamp (op); 1426 move_deep_swamp (op);
1529 return 0; 1427 break;
1530 1428
1531 case RUNE: 1429 case RUNE:
1532 case TRAP: 1430 case TRAP:
1533 move_rune (op); 1431 move_rune (op);
1534 return 0; 1432 break;
1535 1433
1536 case PLAYERMOVER: 1434 case PLAYERMOVER:
1537 move_player_mover (op); 1435 move_player_mover (op);
1538 return 0; 1436 break;
1539 1437
1540 case CREATOR: 1438 case CREATOR:
1541 move_creator (op); 1439 move_creator (op);
1542 return 0; 1440 break;
1543 1441
1544 case MARKER: 1442 case MARKER:
1545 move_marker (op); 1443 move_marker (op);
1546 return 0; 1444 break;
1547 1445
1548 case PLAYER_CHANGER: 1446 case PLAYER_CHANGER:
1549 move_player_changer (op); 1447 move_player_changer (op);
1550 return 0; 1448 break;
1551 1449
1552 case PEACEMAKER: 1450 case PEACEMAKER:
1553 move_peacemaker (op); 1451 move_peacemaker (op);
1554 return 0; 1452 break;
1555 }
1556 1453
1557 return 0; 1454 case PLAYER:
1455 // players have their own speed-management, so undo the --speed_left
1456 ++op->speed_left;
1457 break;
1458 }
1558} 1459}
1460

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines