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.59 by root, Sun Jul 1 05:00:20 2007 UTC vs.
Revision 1.95 by root, Mon Oct 26 11:31:39 2009 UTC

1/* 1/*
2 * This file is part of Crossfire TRT, the Roguelike Realtime MORPG. 2 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 * 3 *
4 * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Crossfire TRT team 4 * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team 5 * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team
6 * Copyright (©) 1992,2007 Frank Tore Johansen 6 * Copyright (©) 1992,2007 Frank Tore Johansen
7 * 7 *
8 * Crossfire TRT is free software: you can redistribute it and/or modify 8 * Deliantra is free software: you can redistribute it and/or modify it under
9 * it under the terms of the GNU General Public License as published by 9 * the terms of the Affero GNU General Public License as published by the
10 * the Free Software Foundation, either version 3 of the License, or 10 * Free Software Foundation, either version 3 of the License, or (at your
11 * (at your option) any later version. 11 * option) any later version.
12 * 12 *
13 * 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,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details. 16 * GNU General Public License for more details.
17 * 17 *
18 * You should have received a copy of the GNU General Public License 18 * You should have received a copy of the Affero GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>. 19 * and the GNU General Public License along with this program. If not, see
20 * <http://www.gnu.org/licenses/>.
20 * 21 *
21 * The authors can be reached via e-mail to <crossfire@schmorp.de> 22 * The authors can be reached via e-mail to <support@deliantra.net>
22 */ 23 */
23 24
24/* 25/*
25 * Routines that is executed from objects based on their speed have been 26 * Routines that is executed from objects based on their speed have been
26 * collected in this file. 27 * collected in this file.
34 * so those will be removed shortly (in a cascade like fashion.) 35 * so those will be removed shortly (in a cascade like fashion.)
35 */ 36 */
36void 37void
37remove_door (object *op) 38remove_door (object *op)
38{ 39{
40 for (int i = 1; i < SIZEOFFREE1 + 1; i += 2)
41 {
42 object *tmp;
43 mapxy pos (op);
44 pos.move (i);
45 if (pos.normalise ()
46 && (tmp = present (DOOR, pos.m, pos.x, pos.y)))
47 {
48 tmp->set_speed (0.1f);
49 tmp->speed_left = -0.2f;
50 }
51 }
52
53 if (op->other_arch)
54 {
55 object *tmp = arch_to_object (op->other_arch);
56 tmp->x = op->x;
57 tmp->y = op->y;
58 tmp->map = op->map;
59 tmp->level = op->level;
60 insert_ob_in_map (tmp, op->map, op, 0);
61 }
62
63 op->drop_and_destroy ();
64}
65
66void
67remove_door2 (object *op)
68{
39 int i; 69 int i;
40 object *tmp; 70 object *tmp;
41 71
42 for (i = 1; i < 9; i += 2) 72 for (i = 1; i < 9; i += 2)
73 {
43 if ((tmp = present (DOOR, op->map, op->x + freearr_x[i], op->y + freearr_y[i])) != NULL) 74 tmp = present (LOCKED_DOOR, op->map, op->x + freearr_x[i], op->y + freearr_y[i]);
44 { 75 if (tmp && tmp->slaying == op->slaying)
76 { /* same key both doors */
45 tmp->set_speed (0.1f); 77 tmp->set_speed (0.1f);
46 tmp->speed_left = -0.2f; 78 tmp->speed_left = -0.2f;
47 } 79 }
80 }
48 81
49 if (op->other_arch) 82 if (op->other_arch)
50 { 83 {
51 tmp = arch_to_object (op->other_arch); 84 tmp = arch_to_object (op->other_arch);
52 tmp->x = op->x; 85 tmp->x = op->x;
54 tmp->map = op->map; 87 tmp->map = op->map;
55 tmp->level = op->level; 88 tmp->level = op->level;
56 insert_ob_in_map (tmp, op->map, op, 0); 89 insert_ob_in_map (tmp, op->map, op, 0);
57 } 90 }
58 91
59 op->destroy (); 92 op->drop_and_destroy ();
60}
61
62void
63remove_door2 (object *op)
64{
65 int i;
66 object *tmp;
67
68 for (i = 1; i < 9; i += 2)
69 {
70 tmp = present (LOCKED_DOOR, op->map, op->x + freearr_x[i], op->y + freearr_y[i]);
71 if (tmp && tmp->slaying == op->slaying)
72 { /* same key both doors */
73 tmp->set_speed (0.1f);
74 tmp->speed_left = -0.2f;
75 }
76 }
77
78 if (op->other_arch)
79 {
80 tmp = arch_to_object (op->other_arch);
81 tmp->x = op->x;
82 tmp->y = op->y;
83 tmp->map = op->map;
84 tmp->level = op->level;
85 insert_ob_in_map (tmp, op->map, op, 0);
86 }
87
88 op->destroy ();
89} 93}
90 94
91void 95void
92generate_monster (object *gen) 96generate_monster (object *gen)
93{ 97{
95 return; 99 return;
96 100
97 if (GENERATE_SPEED (gen) && rndm (0, GENERATE_SPEED (gen) - 1)) 101 if (GENERATE_SPEED (gen) && rndm (0, GENERATE_SPEED (gen) - 1))
98 return; 102 return;
99 103
104 // sleeping generators won't generate, this will make monsters like
105 // centipedes not generate more centipedes when being asleep.
106 if (gen->flag [FLAG_SLEEP])
107 return;
108
100 object *op; 109 object *op;
110 int dir;
101 111
102 if (QUERY_FLAG (gen, FLAG_CONTENT_ON_GEN)) 112 if (QUERY_FLAG (gen, FLAG_CONTENT_ON_GEN))
103 { 113 {
104 // either copy one item from the inventory... 114 // either copy one item from the inventory...
105 if (!gen->inv) 115 if (!gen->inv)
109 int index = 0; 119 int index = 0;
110 for (object *tmp = gen->inv; tmp; tmp = tmp->below) 120 for (object *tmp = gen->inv; tmp; tmp = tmp->below)
111 if (!rndm (++index)) 121 if (!rndm (++index))
112 op = tmp; 122 op = tmp;
113 123
114 op = object_create_clone (op); 124 dir = find_free_spot (op, gen->map, gen->x, gen->y, 1, SIZEOFFREE1 + 1);
125 if (dir < 0)
126 return;
127
128 op = op->deep_clone ();
115 129
116 CLEAR_FLAG (op, FLAG_IS_A_TEMPLATE); 130 CLEAR_FLAG (op, FLAG_IS_A_TEMPLATE);
117 unflag_inv (op, FLAG_IS_A_TEMPLATE); 131 unflag_inv (op, FLAG_IS_A_TEMPLATE);
118 } 132 }
119 else if (gen->other_arch) 133 else if (gen->other_arch)
120 { 134 {
121 // ...or use other_arch 135 // ...or use other_arch
136 dir = find_free_spot (gen->other_arch, gen->map, gen->x, gen->y, 1, SIZEOFFREE1 + 1);
137 if (dir < 0)
138 return;
139
122 op = arch_to_object (gen->other_arch); 140 op = arch_to_object (gen->other_arch);
123 } 141 }
124 else 142 else
125 return; 143 return;
126 144
127 op->expand_tail (); 145 op->expand_tail ();
128 146
129 int i = find_free_spot (op, gen->map, gen->x, gen->y, 1, 9); 147 mapxy pos (gen); pos.move (dir);
130 if (i >= 0) 148
149 if (pos.insert (op, gen))
131 { 150 {
132 if (insert_ob_in_map_at (op, gen->map, gen, 0, gen->x + freearr_x[i], gen->y + freearr_y[i]))
133 {
134 if (rndm (0, 9)) 151 if (rndm (0, 9))
135 generate_artifact (op, gen->map->difficulty); 152 generate_artifact (op, gen->map->difficulty);
136 153
137 if (op->has_random_items ()) 154 if (op->has_random_items ())
138 create_treasure (op->randomitems, op, GT_APPLY, gen->map->difficulty); 155 create_treasure (op->randomitems, op, GT_APPLY, gen->map->difficulty);
139 156
140 return; 157 return;
141 }
142 } 158 }
143 159
144 op->destroy (); 160 op->destroy ();
145} 161}
146 162
263 * objects are above the gate. If so, we finish closing the gate, 279 * objects are above the gate. If so, we finish closing the gate,
264 * otherwise, we fall through to the code below which should lower 280 * otherwise, we fall through to the code below which should lower
265 * the gate slightly. 281 * the gate slightly.
266 */ 282 */
267 283
268 for (tmp = op->above; tmp != NULL; tmp = tmp->above) 284 for (tmp = op->above; tmp; tmp = tmp->above)
269 if (!QUERY_FLAG (tmp, FLAG_NO_PICK) || QUERY_FLAG (tmp, FLAG_CAN_ROLL) || QUERY_FLAG (tmp, FLAG_ALIVE)) 285 if (!QUERY_FLAG (tmp, FLAG_NO_PICK) || QUERY_FLAG (tmp, FLAG_CAN_ROLL) || QUERY_FLAG (tmp, FLAG_ALIVE))
270 break; 286 break;
271 287
272 if (tmp == NULL) 288 if (!tmp)
273 { 289 {
274 if (op->arch->speed) 290 if (op->arch->speed)
275 op->value = 1; 291 op->value = 1;
276 else 292 else
277 op->set_speed (0); 293 op->set_speed (0);
290 } 306 }
291 else 307 else
292 { /* The gate is still going up */ 308 { /* The gate is still going up */
293 op->stats.wc++; 309 op->stats.wc++;
294 310
295 if ((int) op->stats.wc >= (NUM_ANIMATIONS (op))) 311 if (op->stats.wc >= NUM_ANIMATIONS (op))
296 op->stats.wc = (signed char) NUM_ANIMATIONS (op) - 1; 312 op->stats.wc = NUM_ANIMATIONS (op) - 1;
297 313
298 /* If there is something on top of the gate, we try to roll it off. 314 /* If there is something on top of the gate, we try to roll it off.
299 * If a player/monster, we don't roll, we just hit them with damage 315 * If a player/monster, we don't roll, we just hit them with damage
300 */ 316 */
301 if ((int) op->stats.wc >= NUM_ANIMATIONS (op) / 2) 317 if (op->stats.wc >= NUM_ANIMATIONS (op) / 2)
302 { 318 {
303 /* Halfway or further, check blocks */ 319 /* Halfway or further, check blocks */
304 /* First, get the top object on the square. */ 320 /* First, get the top object on the square. */
305 for (tmp = op->above; tmp && tmp->above; tmp = tmp->above) 321 for (tmp = op->above; tmp && tmp->above; tmp = tmp->above)
306 ; 322 ;
308 if (tmp) 324 if (tmp)
309 { 325 {
310 if (QUERY_FLAG (tmp, FLAG_ALIVE)) 326 if (QUERY_FLAG (tmp, FLAG_ALIVE))
311 { 327 {
312 hit_player (tmp, random_roll (0, op->stats.dam, tmp, PREFER_LOW), op, AT_PHYSICAL, 1); 328 hit_player (tmp, random_roll (0, op->stats.dam, tmp, PREFER_LOW), op, AT_PHYSICAL, 1);
329 op->play_sound (sound_find ("blocked_gate"));
313 330
314 if (tmp->type == PLAYER) 331 if (tmp->type == PLAYER)
315 new_draw_info_format (NDI_UNIQUE, 0, tmp, "You are crushed by the %s!", &op->name); 332 new_draw_info_format (NDI_UNIQUE, 0, tmp, "You are crushed by the %s!", &op->name);
316 } 333 }
317 else
318 /* If the object is not alive, and the object either can 334 /* If the object is not alive, and the object either can
319 * be picked up or the object rolls, move the object 335 * be picked up or the object rolls, move the object
320 * off the gate. 336 * off the gate.
321 */ 337 */
322 if (!QUERY_FLAG (tmp, FLAG_ALIVE) && (!QUERY_FLAG (tmp, FLAG_NO_PICK) || QUERY_FLAG (tmp, FLAG_CAN_ROLL))) 338 else if (!QUERY_FLAG (tmp, FLAG_ALIVE) && (!QUERY_FLAG (tmp, FLAG_NO_PICK) || QUERY_FLAG (tmp, FLAG_CAN_ROLL)))
323 { 339 {
324 /* If it has speed, it should move itself, otherwise: */ 340 /* If it has speed, it should move itself, otherwise: */
325 int i = find_free_spot (tmp, op->map, op->x, op->y, 1, 9); 341 int i = find_free_spot (tmp, op->map, op->x, op->y, 1, SIZEOFFREE1 + 1);
326 342
327 /* If there is a free spot, move the object someplace */ 343 /* If there is a free spot, move the object someplace */
328 if (i != -1) 344 if (i > 0)
329 { 345 {
346 mapxy pos (tmp);
347 pos.move (i);
348 if (pos.normalise ())
330 tmp->remove (); 349 tmp->move_to (pos);
331 tmp->x += freearr_x[i], tmp->y += freearr_y[i];
332 insert_ob_in_map (tmp, op->map, op, 0);
333 } 350 }
334 } 351 }
335 } 352 }
336 353
337 /* See if there is still anything blocking the gate */ 354 /* See if there is still anything blocking the gate */
338 for (tmp = op->above; tmp != NULL; tmp = tmp->above) 355 for (tmp = op->above; tmp; tmp = tmp->above)
339 if (!QUERY_FLAG (tmp, FLAG_NO_PICK) || QUERY_FLAG (tmp, FLAG_CAN_ROLL) || QUERY_FLAG (tmp, FLAG_ALIVE)) 356 if (!QUERY_FLAG (tmp, FLAG_NO_PICK) || QUERY_FLAG (tmp, FLAG_CAN_ROLL) || QUERY_FLAG (tmp, FLAG_ALIVE))
340 break; 357 break;
341 358
342 /* IF there is, start putting the gate down */ 359 /* IF there is, start putting the gate down */
343 if (tmp) 360 if (tmp)
344 {
345 op->stats.food = 1; 361 op->stats.food = 1;
346 }
347 else 362 else
348 { 363 {
349 op->move_block = MOVE_ALL; 364 op->move_block = MOVE_ALL;
365
350 if (!op->arch->stats.ac) 366 if (!op->arch->stats.ac)
351 SET_FLAG (op, FLAG_BLOCKSVIEW); 367 SET_FLAG (op, FLAG_BLOCKSVIEW);
352 update_all_los (op->map, op->x, op->y); 368 update_all_los (op->map, op->x, op->y);
353 } 369 }
354 } /* gate is halfway up */ 370 } /* gate is halfway up */
368 int v = op->value; 384 int v = op->value;
369 385
370 if (op->stats.sp) 386 if (op->stats.sp)
371 { 387 {
372 move_gate (op); 388 move_gate (op);
389
373 if (op->value != v) /* change direction ? */ 390 if (op->value != v) /* change direction ? */
374 op->stats.sp = 0; 391 op->stats.sp = 0;
375 return; 392 return;
376 } 393 }
394
377 if (--op->stats.hp <= 0) 395 if (--op->stats.hp <= 0)
378 { /* keep gate down */ 396 { /* keep gate down */
379 move_gate (op); 397 move_gate (op);
398
380 if (op->value != v) 399 if (op->value != v)
381 op->set_speed (0); 400 op->set_speed (0);
382 } 401 }
383} 402}
384 403
396 int last = op->value; 415 int last = op->value;
397 int detected; 416 int detected;
398 417
399 detected = 0; 418 detected = 0;
400 419
401 for (tmp = GET_MAP_OB (op->map, op->x, op->y); tmp != NULL && !detected; tmp = tmp->above) 420 for (tmp = op->ms ().bot; tmp && !detected; tmp = tmp->above)
402 { 421 {
403 object *tmp2; 422 object *tmp2;
404 423
405 if (op->stats.hp) 424 if (op->stats.hp)
406 { 425 {
424 if (op->stats.sp == 1) 443 if (op->stats.sp == 1)
425 { 444 {
426 if (detected && last == 0) 445 if (detected && last == 0)
427 { 446 {
428 op->value = 1; 447 op->value = 1;
429 push_button (op); 448 push_button (op, tmp);
430 } 449 }
450
431 if (!detected && last == 1) 451 if (!detected && last == 1)
432 { 452 {
433 op->value = 0; 453 op->value = 0;
434 push_button (op); 454 push_button (op, tmp);
435 } 455 }
436 } 456 }
437 else 457 else
438 { /* in this case, we unset buttons */ 458 { /* in this case, we unset buttons */
439 if (detected && last == 1) 459 if (detected && last == 1)
440 { 460 {
441 op->value = 0; 461 op->value = 0;
442 push_button (op); 462 push_button (op, tmp);
443 } 463 }
464
444 if (!detected && last == 0) 465 if (!detected && last == 0)
445 { 466 {
446 op->value = 1; 467 op->value = 1;
447 push_button (op); 468 push_button (op, tmp);
448 } 469 }
449 } 470 }
450} 471}
451
452 472
453void 473void
454animate_trigger (object *op) 474animate_trigger (object *op)
455{ 475{
456 if ((unsigned char) ++op->stats.wc >= NUM_ANIMATIONS (op)) 476 if ((unsigned char) ++op->stats.wc >= NUM_ANIMATIONS (op))
466} 486}
467 487
468void 488void
469move_hole (object *op) 489move_hole (object *op)
470{ /* 1 = opening, 0 = closing */ 490{ /* 1 = opening, 0 = closing */
471 object *next, *tmp;
472
473 if (op->value) 491 if (op->value)
474 { /* We're opening */ 492 { /* We're opening */
475 if (--op->stats.wc <= 0) 493 if (--op->stats.wc <= 0)
476 { /* Opened, let's stop */ 494 { /* Opened, let's stop */
477 op->stats.wc = 0; 495 op->stats.wc = 0;
478 op->set_speed (0); 496 op->set_speed (0);
479 497
480 /* Hard coding this makes sense for holes I suppose */ 498 /* Hard coding this makes sense for holes I suppose */
481 op->move_on = MOVE_WALK; 499 op->move_on = MOVE_WALK;
482 for (tmp = op->above; tmp != NULL; tmp = next) 500 for (object *next, *tmp = op->above; tmp; tmp = next)
483 { 501 {
484 next = tmp->above; 502 next = tmp->above;
485 move_apply (op, tmp, tmp); 503 move_apply (op, tmp, tmp);
486 } 504 }
487 } 505 }
488 506
489 SET_ANIMATION (op, op->stats.wc); 507 SET_ANIMATION (op, op->stats.wc);
490 update_object (op, UP_OBJ_FACE); 508 update_object (op, UP_OBJ_FACE);
491 return; 509 return;
492 } 510 }
511
493 /* We're closing */ 512 /* We're closing */
494 op->move_on = 0; 513 op->move_on = 0;
495 514
496 op->stats.wc++; 515 op->stats.wc++;
497 if ((int) op->stats.wc >= NUM_ANIMATIONS (op)) 516 if ((int) op->stats.wc >= NUM_ANIMATIONS (op))
528 { 547 {
529 object *payload = op->inv; 548 object *payload = op->inv;
530 549
531 if (payload == NULL) 550 if (payload == NULL)
532 return NULL; 551 return NULL;
552
533 payload->remove (); 553 payload->remove ();
534 op->destroy (); 554 op->destroy ();
535 return payload; 555 return payload;
536 } 556 }
537 557
580 600
581 // restore original wc, dam, attacktype and slaying 601 // restore original wc, dam, attacktype and slaying
582 op->stats.wc = op->stats.sp; 602 op->stats.wc = op->stats.sp;
583 op->stats.dam = op->stats.hp; 603 op->stats.dam = op->stats.hp;
584 op->attacktype = op->stats.grace; 604 op->attacktype = op->stats.grace;
605 op->slaying = op->custom_name;
585 606
586 if (op->spellarg)
587 {
588 op->slaying = op->spellarg;
589 free (op->spellarg);
590 op->spellarg = 0;
591 }
592 else
593 op->slaying = 0;
594
595 /* Reset these to zero, so that object::can_merge will work properly */ 607 /* Reset these to defaults, so that object::can_merge will work properly */
596 op->spellarg = NULL; 608 op->custom_name = 0;
597 op->stats.sp = 0; 609 op->stats.sp = 0;
598 op->stats.hp = 0; 610 op->stats.hp = 0;
599 op->stats.grace = 0; 611 op->stats.grace = 0;
600 op->level = 0; 612 op->level = 0;
601 op->face = op->arch->face; 613 op->face = op->arch->face;
602 op->owner = NULL; /* So that stopped arrows will be saved */ 614 op->owner = 0;
615
603 update_object (op, UP_OBJ_CHANGE); 616 update_object (op, UP_OBJ_CHANGE);
617
604 return op; 618 return op;
605} 619}
606 620
607/* stop_arrow() - what to do when a non-living flying object 621/* stop_arrow() - what to do when a non-living flying object
608 * has to stop. Sept 96 - I added in thrown object code in 622 * has to stop. Sept 96 - I added in thrown object code in
617 if (INVOKE_OBJECT (STOP, op)) 631 if (INVOKE_OBJECT (STOP, op))
618 return; 632 return;
619 633
620 if (op->inv) 634 if (op->inv)
621 { 635 {
636 // replace this by straightforward drop to ground?
622 object *payload = op->inv; 637 object *payload = op->inv;
623 638
624 payload->remove ();
625 payload->owner = 0; 639 payload->owner = 0;
626 insert_ob_in_map (payload, op->map, payload, 0); 640 insert_ob_in_map (payload, op->map, payload, 0);
627 op->destroy (); 641 op->destroy ();
628 } 642 }
629 else 643 else
638/* Move an arrow along its course. op is the arrow or thrown object. 652/* Move an arrow along its course. op is the arrow or thrown object.
639 */ 653 */
640void 654void
641move_arrow (object *op) 655move_arrow (object *op)
642{ 656{
643 object *tmp;
644 sint16 new_x, new_y;
645 int was_reflected, mflags; 657 int was_reflected;
646 maptile *m;
647 658
648 if (op->map == NULL) 659 if (!op->map)
649 { 660 {
650 LOG (llevError, "BUG: Arrow had no map.\n"); 661 LOG (llevError, "BUG: Arrow had no map.\n");
651 op->destroy (); 662 op->destroy ();
652 return; 663 return;
653 } 664 }
661 * is if the player throws a bomb - the bomb explodes on its own, 672 * is if the player throws a bomb - the bomb explodes on its own,
662 * but this object sticks around. We could handle the cleanup in the 673 * but this object sticks around. We could handle the cleanup in the
663 * bomb code, but there are potential other cases where that could happen, 674 * bomb code, but there are potential other cases where that could happen,
664 * and it is easy enough to clean it up here. 675 * and it is easy enough to clean it up here.
665 */ 676 */
666 if (op->inv == NULL) 677 if (!op->inv)
667 { 678 {
668 op->destroy (); 679 op->destroy ();
669 return; 680 return;
670 } 681 }
671 682
683 stop_arrow (op); 694 stop_arrow (op);
684 return; 695 return;
685 } 696 }
686 697
687 /* Calculate target map square */ 698 /* Calculate target map square */
688 new_x = op->x + DIRX (op);
689 new_y = op->y + DIRY (op);
690 was_reflected = 0; 699 was_reflected = 0;
691 700
692 m = op->map; 701 mapxy pos (op); pos.move (op->direction);
693 mflags = get_map_flags (m, &m, new_x, new_y, &new_x, &new_y);
694 702
695 if (mflags & P_OUT_OF_MAP) 703 if (!pos.normalise ())
696 { 704 {
697 stop_arrow (op); 705 stop_arrow (op);
698 return; 706 return;
699 } 707 }
700 708
701 /* only need to look for living creatures if this flag is set */ 709 /* only need to look for living creatures if this flag is set */
702 if (mflags & P_IS_ALIVE) 710 if (pos->flags () & P_IS_ALIVE)
703 { 711 {
704 for (tmp = GET_MAP_OB (m, new_x, new_y); tmp != NULL; tmp = tmp->above) 712 object *tmp;
713
714 for (tmp = pos->bot; tmp; tmp = tmp->above)
705 if (QUERY_FLAG (tmp, FLAG_ALIVE)) 715 if (QUERY_FLAG (tmp, FLAG_ALIVE))
706 break; 716 break;
707 717
708 /* Not really fair, but don't let monsters hit themselves with 718 /* Not really fair, but don't let monsters hit themselves with
709 * their own arrow - this can be because they fire it then 719 * their own arrow - this can be because they fire it then
732 return; 742 return;
733 } 743 }
734 } /* if this is not hitting its owner */ 744 } /* if this is not hitting its owner */
735 } /* if there is something alive on this space */ 745 } /* if there is something alive on this space */
736 746
737 if (OB_TYPE_MOVE_BLOCK (op, GET_MAP_MOVE_BLOCK (m, new_x, new_y))) 747 if (OB_TYPE_MOVE_BLOCK (op, pos->move_block))
738 { 748 {
739 int retry = 0; 749 int retry = 0;
740 750
741 /* if the object doesn't reflect, stop the arrow from moving 751 /* if the object doesn't reflect, stop the arrow from moving
742 * note that this code will now catch cases where a monster is 752 * note that this code will now catch cases where a monster is
755 if (op->direction & 1) 765 if (op->direction & 1)
756 { 766 {
757 op->direction = absdir (op->direction + 4); 767 op->direction = absdir (op->direction + 4);
758 retry = 1; 768 retry = 1;
759 } 769 }
770
760 /* There were two blocks with identical code - 771 /* There were two blocks with identical code -
761 * use this retry here to make this one block 772 * use this retry here to make this one block
762 * that did the same thing. 773 * that did the same thing.
763 */ 774 */
764 while (retry < 2) 775 while (retry < 2)
765 { 776 {
766 int left, right, mflags;
767 maptile *m1;
768 sint16 x1, y1;
769
770 retry++; 777 retry++;
771 778
772 /* Need to check for P_OUT_OF_MAP: if the arrow is tavelling 779 /* Need to check for P_OUT_OF_MAP: if the arrow is travelling
773 * over a corner in a tiled map, it is possible that 780 * over a corner in a tiled map, it is possible that
774 * op->direction is within an adjacent map but either 781 * op->direction is within an adjacent map but either
775 * op->direction-1 or op->direction+1 does not exist. 782 * op->direction-1 or op->direction+1 does not exist.
776 */ 783 */
777 mflags = get_map_flags (op->map, &m1, op->x + freearr_x[absdir (op->direction - 1)], 784 mapxy pos1 (pos); pos1.move (absdir (op->direction - 1));
778 op->y + freearr_y[absdir (op->direction - 1)], &x1, &y1); 785 bool left = pos1.normalise () && OB_TYPE_MOVE_BLOCK (op, pos1->move_block);
779 left = (mflags & P_OUT_OF_MAP) ? 0 : OB_TYPE_MOVE_BLOCK (op, (GET_MAP_MOVE_BLOCK (m1, x1, y1)));
780 786
781 mflags = get_map_flags (op->map, &m1, op->x + freearr_x[absdir (op->direction + 1)], 787 mapxy pos2 (pos); pos2.move (absdir (op->direction + 1));
782 op->y + freearr_y[absdir (op->direction + 1)], &x1, &y1); 788 bool right = pos2.normalise () && OB_TYPE_MOVE_BLOCK (op, pos2->move_block);
783 right = (mflags & P_OUT_OF_MAP) ? 0 : OB_TYPE_MOVE_BLOCK (op, (GET_MAP_MOVE_BLOCK (m1, x1, y1)));
784 789
785 if (left == right) 790 if (left == right)
786 op->direction = absdir (op->direction + 4); 791 op->direction = absdir (op->direction + 4);
787 else if (left) 792 else if (left)
788 op->direction = absdir (op->direction + 2); 793 op->direction = absdir (op->direction + 2);
789 else if (right) 794 else if (right)
790 op->direction = absdir (op->direction - 2); 795 op->direction = absdir (op->direction - 2);
791 796
792 mflags = get_map_flags (op->map, &m1, op->x + DIRX (op), op->y + DIRY (op), &x1, &y1);
793
794 /* If this space is not out of the map and not blocked, valid space - 797 /* If this space is not out of the map and not blocked, valid space -
795 * don't need to retry again. 798 * don't need to retry again.
796 */ 799 */
797 if (!(mflags & P_OUT_OF_MAP) && !OB_TYPE_MOVE_BLOCK (op, GET_MAP_MOVE_BLOCK (m1, x1, y1))) 800 mapxy pos3 (pos); pos3.move (op->direction);
801 if (pos3.normalise () && !OB_TYPE_MOVE_BLOCK (op, pos3->move_block))
798 break; 802 break;
799
800 } 803 }
804
801 /* Couldn't find a direction to move the arrow to - just 805 /* Couldn't find a direction to move the arrow to - just
802 * top it from moving. 806 * stop it from moving.
803 */ 807 */
804 if (retry == 2) 808 if (retry == 2)
805 { 809 {
806 stop_arrow (op); 810 stop_arrow (op);
807 return; 811 return;
808 } 812 }
813
809 /* update object image for new facing */ 814 /* update object image for new facing */
810 /* many thrown objects *don't* have more than one face */ 815 /* many thrown objects *don't* have more than one face */
811 if (GET_ANIM_ID (op)) 816 if (op->has_anim ())
812 SET_ANIMATION (op, op->direction); 817 op->set_anim_frame (op->direction);
813 } /* object is reflected */ 818 } /* object is reflected */
814 } /* object ran into a wall */ 819 } /* object ran into a wall */
815
816 /* Move the arrow. */
817 op->remove ();
818 op->x = new_x;
819 op->y = new_y;
820 820
821 /* decrease the speed as it flies. 0.05 means a standard bow will shoot 821 /* decrease the speed as it flies. 0.05 means a standard bow will shoot
822 * about 17 squares. Tune as needed. 822 * about 17 squares. Tune as needed.
823 */ 823 */
824 op->speed -= 0.05; 824 op->speed -= 0.05;
825 insert_ob_in_map (op, m, op, 0);
826}
827 825
828/* This routine doesnt seem to work for "inanimate" objects that 826 /* Move the arrow. */
829 * are being carried, ie a held torch leaps from your hands!. 827 op->move_to (pos);
830 * Modified this routine to allow held objects. b.t. */ 828}
831 829
832void 830void
833change_object (object *op) 831change_object (object *op)
834{ /* Doesn`t handle linked objs yet */ 832{ /* Doesn`t handle linked objs yet */
835 int i, j; 833 int i, j;
836 834
837 if (op->other_arch == NULL) 835 if (!op->other_arch)
838 { 836 {
839 LOG (llevError, "Change object (%s) without other_arch error.\n", &op->name); 837 LOG (llevError, "Change object (%s) without other_arch error.\n", op->debug_desc ());
840 return; 838 return;
841 } 839 }
842 840
843 /* In non-living items only change when food value is 0 */ 841 /* In non-living items only change when food value is 0 */
844 if (!QUERY_FLAG (op, FLAG_ALIVE)) 842 if (!QUERY_FLAG (op, FLAG_ALIVE))
845 { 843 {
846 if (op->stats.food-- > 0) 844 if (op->stats.food-- > 0)
847 return; 845 return;
846
847 op->stats.food = 1; /* so 1 other_arch is made */
848 }
849
850 object *env = op->env;
851
852 op->remove ();
853 for (i = 0; i < op->stats.food; i++)
854 {
855 object *tmp = arch_to_object (op->other_arch);
856
857 tmp->stats.hp = op->stats.hp; /* The only variable it keeps. */
858
859 if (env)
860 env->insert (tmp);
848 else 861 else
849 op->stats.food = 1; /* so 1 other_arch is made */
850 }
851
852 object *pl = op->in_player ();
853 object *env = op->env;
854
855 op->remove ();
856 for (i = 0; i < NROFNEWOBJS (op); i++)
857 {
858 object *tmp = arch_to_object (op->other_arch);
859
860 if (op->type == LAMP)
861 tmp->stats.food = op->stats.food - 1;
862
863 tmp->stats.hp = op->stats.hp; /* The only variable it keeps. */
864 if (env)
865 {
866 tmp->x = env->x, tmp->y = env->y;
867 tmp = insert_ob_in_ob (tmp, env);
868
869 /* If this object is the players inventory, we need to tell the
870 * client of the change. Insert_ob_in_map takes care of the
871 * updating the client, so we don't need to do that below.
872 */
873 if (pl)
874 {
875 esrv_del_item (pl->contr, op->count);
876 esrv_send_item (pl, tmp);
877 }
878 }
879 else
880 { 862 {
881 j = find_first_free_spot (tmp, op->map, op->x, op->y); 863 j = find_first_free_spot (tmp, op->map, op->x, op->y);
882 if (j == -1) /* No free spot */ 864 if (j < 0) /* No free spot */
883 tmp->destroy (); 865 tmp->destroy ();
884 else 866 else
885 { 867 {
886 tmp->x = op->x + freearr_x[j], tmp->y = op->y + freearr_y[j]; 868 mapxy pos (op); pos.move (j);
887 insert_ob_in_map (tmp, op->map, op, 0); 869
870 if (pos.normalise ())
871 pos.insert (tmp, op);
888 } 872 }
889 } 873 }
890 } 874 }
891 875
892 op->destroy (); 876 op->destroy ();
948 else 932 else
949 { 933 {
950 /* Random teleporter */ 934 /* Random teleporter */
951 if (INVOKE_OBJECT (TRIGGER, op, ARG_OBJECT (tmp))) 935 if (INVOKE_OBJECT (TRIGGER, op, ARG_OBJECT (tmp)))
952 return; 936 return;
937
953 teleport (head, TELEPORTER, tmp); 938 teleport (head, TELEPORTER, tmp);
954 } 939 }
955} 940}
956 941
957/* This object will teleport someone to a different map 942/* This object will teleport someone to a different map
1166 * has to make sure that there is in fact space for the object. 1151 * has to make sure that there is in fact space for the object.
1167 * It should really do this for small objects also, but there is 1152 * It should really do this for small objects also, but there is
1168 * more concern with large objects, most notably a part being placed 1153 * more concern with large objects, most notably a part being placed
1169 * outside of the map which would cause the server to crash 1154 * outside of the map which would cause the server to crash
1170*/ 1155*/
1171
1172void 1156void
1173move_creator (object *creator) 1157move_creator (object *creator)
1174{ 1158{
1175 object *new_ob; 1159 object *new_ob;
1176 1160
1178 { 1162 {
1179 creator->stats.hp = -1; 1163 creator->stats.hp = -1;
1180 return; 1164 return;
1181 } 1165 }
1182 1166
1183 if (creator->inv != NULL) 1167 if (creator->inv)
1184 { 1168 {
1185 object *ob; 1169 object *ob;
1186 int i; 1170 int i;
1187 object *ob_to_copy; 1171 object *ob_to_copy;
1188 1172
1193 if (rndm (0, i) == 0) 1177 if (rndm (0, i) == 0)
1194 { 1178 {
1195 ob_to_copy = ob; 1179 ob_to_copy = ob;
1196 } 1180 }
1197 } 1181 }
1198 new_ob = object_create_clone (ob_to_copy); 1182 new_ob = ob_to_copy->deep_clone ();
1199 CLEAR_FLAG (new_ob, FLAG_IS_A_TEMPLATE); 1183 CLEAR_FLAG (new_ob, FLAG_IS_A_TEMPLATE);
1200 unflag_inv (new_ob, FLAG_IS_A_TEMPLATE); 1184 unflag_inv (new_ob, FLAG_IS_A_TEMPLATE);
1201 } 1185 }
1202 else 1186 else
1203 { 1187 {
1204 if (creator->other_arch == NULL) 1188 if (!creator->other_arch)
1205 { 1189 {
1206 LOG (llevError, "move_creator: Creator doesn't have other arch set: %s (%s, %d, %d)\n", 1190 LOG (llevError, "move_creator: Creator doesn't have other arch set: %s (%s, %d, %d)\n",
1207 &creator->name, &creator->map->path, creator->x, creator->y); 1191 &creator->name, &creator->map->path, creator->x, creator->y);
1208 return; 1192 return;
1209 } 1193 }
1211 new_ob = object_create_arch (creator->other_arch); 1195 new_ob = object_create_arch (creator->other_arch);
1212 fix_generated_item (new_ob, creator, 0, 0, GT_MINIMAL); 1196 fix_generated_item (new_ob, creator, 0, 0, GT_MINIMAL);
1213 } 1197 }
1214 1198
1215 /* Make sure this multipart object fits */ 1199 /* Make sure this multipart object fits */
1216 if (new_ob->arch->more && ob_blocked (new_ob, creator->map, creator->x, creator->y)) 1200 if (new_ob->arch->more && new_ob->blocked (creator->map, creator->x, creator->y))
1217 { 1201 {
1218 new_ob->destroy (); 1202 new_ob->destroy ();
1219 return; 1203 return;
1220 } 1204 }
1205
1206 // for now lets try to identify everything generated here, it mostly
1207 // happens automated, so this will at least fix many identify-experience holes
1208 SET_FLAG (new_ob, FLAG_IDENTIFIED);
1221 1209
1222 insert_ob_in_map_at (new_ob, creator->map, creator, 0, creator->x, creator->y); 1210 insert_ob_in_map_at (new_ob, creator->map, creator, 0, creator->x, creator->y);
1223 if (QUERY_FLAG (new_ob, FLAG_FREED)) 1211 if (QUERY_FLAG (new_ob, FLAG_FREED))
1224 return; 1212 return;
1225 1213
1226 if (creator->slaying) 1214 if (creator->slaying)
1227 {
1228 new_ob->name = new_ob->title = creator->slaying; 1215 new_ob->name = new_ob->title = creator->slaying;
1229 }
1230} 1216}
1231 1217
1232/* move_marker --peterm@soda.csua.berkeley.edu 1218/* move_marker --peterm@soda.csua.berkeley.edu
1233 when moved, a marker will search for a player sitting above 1219 when moved, a marker will search for a player sitting above
1234 it, and insert an invisible, weightless force into him 1220 it, and insert an invisible, weightless force into him
1240void 1226void
1241move_marker (object *op) 1227move_marker (object *op)
1242{ 1228{
1243 if (object *tmp = op->ms ().player ()) 1229 if (object *tmp = op->ms ().player ())
1244 { 1230 {
1245 object *tmp2;
1246
1247 /* remove an old force with a slaying field == op->name */ 1231 /* remove an old force with a slaying field == op->name */
1248 for (tmp2 = tmp->inv; tmp2; tmp2 = tmp2->below) 1232 if (object *force = tmp->force_find (op->name))
1249 if (tmp2->type == FORCE && tmp2->slaying && tmp2->slaying == op->name) 1233 force->destroy ();
1234
1235 if (op->slaying && !tmp->force_find (op->slaying))
1250 { 1236 {
1251 tmp2->destroy (); 1237 tmp->force_add (op->slaying, op->stats.food);
1252 break;
1253 }
1254 1238
1255 /* cycle through his inventory to look for the MARK we want to
1256 * place
1257 */
1258 for (tmp2 = tmp->inv; tmp2; tmp2 = tmp2->below)
1259 if (tmp2->type == FORCE && tmp2->slaying && tmp2->slaying == op->slaying)
1260 break;
1261
1262 /* if we didn't find our own MARK */
1263 if (!tmp2)
1264 {
1265 object *force = get_archetype (FORCE_NAME);
1266
1267 if (op->stats.food)
1268 {
1269 force->set_speed (0.01);
1270 force->speed_left = -op->stats.food;
1271 }
1272 else
1273 force->set_speed (0);
1274
1275 /* put in the lock code */
1276 force->slaying = op->slaying;
1277
1278 if (op->lore)
1279 force->lore = op->lore;
1280
1281 insert_ob_in_ob (force, tmp);
1282 if (op->msg) 1239 if (op->msg)
1283 new_draw_info (NDI_UNIQUE | NDI_NAVY, 0, tmp, op->msg); 1240 new_draw_info (NDI_UNIQUE | NDI_NAVY, 0, tmp, op->msg);
1284 1241
1285 if (op->stats.hp > 0) 1242 if (op->stats.hp > 0)
1286 { 1243 {
1287 op->stats.hp--; 1244 op->stats.hp--;
1245
1288 if (op->stats.hp == 0) 1246 if (op->stats.hp == 0)
1289 { 1247 {
1290 /* marker expires--granted mark number limit */ 1248 /* marker expires--granted mark number limit */
1291 op->destroy (); 1249 op->destroy ();
1292 return; 1250 return;
1294 } 1252 }
1295 } 1253 }
1296 } 1254 }
1297} 1255}
1298 1256
1257// mapscript objects activate themselves (only) then their timer fires
1258// TODO: maybe they should simply trigger the link like any other object?
1259void
1260move_mapscript (object *op)
1261{
1262 op->set_speed (0);
1263 cfperl_mapscript_activate (op, true, op, 0);
1264}
1265
1266void move_lamp (object *op)
1267{
1268 // if the lamp/torch is off, we should disable it.
1269 if (!op->glow_radius)
1270 {
1271 op->set_speed (0);
1272 return;
1273 }
1274 else
1275 {
1276 // check whether the face might need to be updated
1277 // (currently this is needed to have already switched on torches
1278 // on maps, as they just set the glow_radius in the archetype)
1279 if (op->other_arch
1280 && (
1281 (op->flag [FLAG_ANIMATE] != op->other_arch->flag [FLAG_ANIMATE])
1282 || (op->flag [FLAG_ANIMATE]
1283 ? (op->animation_id != op->other_arch->animation_id)
1284 : (op->face != op->other_arch->face))
1285 ))
1286 get_animation_from_arch (op, op->other_arch);
1287 }
1288
1289 // lamps and torches on maps don't use up their fuel
1290 if (op->is_on_map ())
1291 return;
1292
1293 if (op->stats.food > 0)
1294 {
1295 op->stats.food--;
1296 return;
1297 }
1298
1299 apply_lamp (op, false);
1300}
1301
1299void 1302void
1300process_object (object *op) 1303process_object (object *op)
1301{ 1304{
1302 if (expect_false (QUERY_FLAG (op, FLAG_IS_A_TEMPLATE))) 1305 if (expect_false (QUERY_FLAG (op, FLAG_IS_A_TEMPLATE)))
1303 return; 1306 return;
1336 { 1339 {
1337 if (QUERY_FLAG (op, FLAG_APPLIED)) 1340 if (QUERY_FLAG (op, FLAG_APPLIED))
1338 remove_force (op); 1341 remove_force (op);
1339 else 1342 else
1340 { 1343 {
1341 /* If necessary, delete the item from the players inventory */ 1344 op->remove (); // TODO: really necessary?
1342 object *pl = op->in_player ();
1343
1344 if (pl)
1345 esrv_del_item (pl->contr, op->count);
1346
1347 op->remove ();
1348 1345
1349 if (QUERY_FLAG (op, FLAG_SEE_ANYWHERE)) 1346 if (QUERY_FLAG (op, FLAG_SEE_ANYWHERE))
1350 make_sure_not_seen (op); 1347 make_sure_not_seen (op);
1351 1348
1352 op->destroy (); 1349 op->drop_and_destroy ();
1353 } 1350 }
1354 1351
1355 return; 1352 return;
1356 } 1353 }
1357 } 1354 }
1481 1478
1482 case PLAYER: 1479 case PLAYER:
1483 // players have their own speed-management, so undo the --speed_left 1480 // players have their own speed-management, so undo the --speed_left
1484 ++op->speed_left; 1481 ++op->speed_left;
1485 break; 1482 break;
1486 }
1487}
1488 1483
1484 case MAPSCRIPT:
1485 move_mapscript (op);
1486 break;
1487
1488 case LAMP:
1489 case TORCH:
1490 move_lamp (op);
1491 break;
1492 }
1493}
1494

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines