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.63 by root, Sat Aug 4 22:23:47 2007 UTC vs.
Revision 1.72 by root, Thu Nov 8 19:43:29 2007 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 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
9 * 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
10 * the Free Software Foundation, either version 3 of the License, or 10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version. 11 * (at your 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,
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 GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>. 19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 * 20 *
21 * The authors can be reached via e-mail to <crossfire@schmorp.de> 21 * The authors can be reached via e-mail to <support@deliantra.net>
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.
34 * so those will be removed shortly (in a cascade like fashion.) 34 * so those will be removed shortly (in a cascade like fashion.)
35 */ 35 */
36void 36void
37remove_door (object *op) 37remove_door (object *op)
38{ 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)
67{
39 int i; 68 int i;
40 object *tmp; 69 object *tmp;
41 70
42 for (i = 1; i < 9; i += 2) 71 for (i = 1; i < 9; i += 2)
72 {
43 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]);
44 { 74 if (tmp && tmp->slaying == op->slaying)
75 { /* same key both doors */
45 tmp->set_speed (0.1f); 76 tmp->set_speed (0.1f);
46 tmp->speed_left = -0.2f; 77 tmp->speed_left = -0.2f;
47 } 78 }
79 }
48 80
49 if (op->other_arch) 81 if (op->other_arch)
50 { 82 {
51 tmp = arch_to_object (op->other_arch); 83 tmp = arch_to_object (op->other_arch);
52 tmp->x = op->x; 84 tmp->x = op->x;
58 90
59 op->destroy (); 91 op->destroy ();
60} 92}
61 93
62void 94void
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}
90
91void
92generate_monster (object *gen) 95generate_monster (object *gen)
93{ 96{
94 if (!gen->map) 97 if (!gen->map)
95 return; 98 return;
96 99
97 if (GENERATE_SPEED (gen) && rndm (0, GENERATE_SPEED (gen) - 1)) 100 if (GENERATE_SPEED (gen) && rndm (0, GENERATE_SPEED (gen) - 1))
98 return; 101 return;
99 102
100 object *op; 103 object *op;
101 int i; 104 int dir;
102 105
103 if (QUERY_FLAG (gen, FLAG_CONTENT_ON_GEN)) 106 if (QUERY_FLAG (gen, FLAG_CONTENT_ON_GEN))
104 { 107 {
105 // either copy one item from the inventory... 108 // either copy one item from the inventory...
106 if (!gen->inv) 109 if (!gen->inv)
110 int index = 0; 113 int index = 0;
111 for (object *tmp = gen->inv; tmp; tmp = tmp->below) 114 for (object *tmp = gen->inv; tmp; tmp = tmp->below)
112 if (!rndm (++index)) 115 if (!rndm (++index))
113 op = tmp; 116 op = tmp;
114 117
115 i = find_free_spot (op, gen->map, gen->x, gen->y, 1, 9); 118 dir = find_free_spot (op, gen->map, gen->x, gen->y, 1, SIZEOFFREE1 + 1);
116 if (i < 0) 119 if (dir < 0)
117 return; 120 return;
118 121
119 op = object_create_clone (op); 122 op = object_create_clone (op);
120 123
121 CLEAR_FLAG (op, FLAG_IS_A_TEMPLATE); 124 CLEAR_FLAG (op, FLAG_IS_A_TEMPLATE);
122 unflag_inv (op, FLAG_IS_A_TEMPLATE); 125 unflag_inv (op, FLAG_IS_A_TEMPLATE);
123 } 126 }
124 else if (gen->other_arch) 127 else if (gen->other_arch)
125 { 128 {
126 // ...or use other_arch 129 // ...or use other_arch
127 i = find_free_spot (gen->other_arch, gen->map, gen->x, gen->y, 1, 9); 130 dir = find_free_spot (gen->other_arch, gen->map, gen->x, gen->y, 1, SIZEOFFREE1 + 1);
128 if (i < 0) 131 if (dir < 0)
129 return; 132 return;
130 133
131 op = arch_to_object (gen->other_arch); 134 op = arch_to_object (gen->other_arch);
132 } 135 }
133 else 136 else
134 return; 137 return;
135 138
136 op->expand_tail (); 139 op->expand_tail ();
137 140
138 if (insert_ob_in_map_at (op, gen->map, gen, 0, gen->x + freearr_x[i], gen->y + freearr_y[i])) 141 mapxy pos (gen); pos.move (dir);
142
143 if (pos.insert (op, gen))
139 { 144 {
140 if (rndm (0, 9)) 145 if (rndm (0, 9))
141 generate_artifact (op, gen->map->difficulty); 146 generate_artifact (op, gen->map->difficulty);
142 147
143 if (op->has_random_items ()) 148 if (op->has_random_items ())
268 * 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,
269 * otherwise, we fall through to the code below which should lower 274 * otherwise, we fall through to the code below which should lower
270 * the gate slightly. 275 * the gate slightly.
271 */ 276 */
272 277
273 for (tmp = op->above; tmp != NULL; tmp = tmp->above) 278 for (tmp = op->above; tmp; tmp = tmp->above)
274 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))
275 break; 280 break;
276 281
277 if (tmp == NULL) 282 if (!tmp)
278 { 283 {
279 if (op->arch->speed) 284 if (op->arch->speed)
280 op->value = 1; 285 op->value = 1;
281 else 286 else
282 op->set_speed (0); 287 op->set_speed (0);
295 } 300 }
296 else 301 else
297 { /* The gate is still going up */ 302 { /* The gate is still going up */
298 op->stats.wc++; 303 op->stats.wc++;
299 304
300 if ((int) op->stats.wc >= (NUM_ANIMATIONS (op))) 305 if (op->stats.wc >= NUM_ANIMATIONS (op))
301 op->stats.wc = (signed char) NUM_ANIMATIONS (op) - 1; 306 op->stats.wc = NUM_ANIMATIONS (op) - 1;
302 307
303 /* 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.
304 * 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
305 */ 310 */
306 if ((int) op->stats.wc >= NUM_ANIMATIONS (op) / 2) 311 if (op->stats.wc >= NUM_ANIMATIONS (op) / 2)
307 { 312 {
308 /* Halfway or further, check blocks */ 313 /* Halfway or further, check blocks */
309 /* First, get the top object on the square. */ 314 /* First, get the top object on the square. */
310 for (tmp = op->above; tmp && tmp->above; tmp = tmp->above) 315 for (tmp = op->above; tmp && tmp->above; tmp = tmp->above)
311 ; 316 ;
313 if (tmp) 318 if (tmp)
314 { 319 {
315 if (QUERY_FLAG (tmp, FLAG_ALIVE)) 320 if (QUERY_FLAG (tmp, FLAG_ALIVE))
316 { 321 {
317 hit_player (tmp, random_roll (0, 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"));
318 324
319 if (tmp->type == PLAYER) 325 if (tmp->type == PLAYER)
320 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);
321 } 327 }
322 else
323 /* If the object is not alive, and the object either can 328 /* If the object is not alive, and the object either can
324 * be picked up or the object rolls, move the object 329 * be picked up or the object rolls, move the object
325 * off the gate. 330 * off the gate.
326 */ 331 */
327 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)))
328 { 333 {
329 /* If it has speed, it should move itself, otherwise: */ 334 /* If it has speed, it should move itself, otherwise: */
330 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);
331 336
332 /* If there is a free spot, move the object someplace */ 337 /* If there is a free spot, move the object someplace */
333 if (i != -1) 338 if (i > 0)
334 { 339 {
340 mapxy pos (tmp);
341 pos.move (i);
342 if (pos.normalise ())
335 tmp->remove (); 343 tmp->move_to (pos);
336 tmp->x += freearr_x[i], tmp->y += freearr_y[i];
337 insert_ob_in_map (tmp, op->map, op, 0);
338 } 344 }
339 } 345 }
340 } 346 }
341 347
342 /* See if there is still anything blocking the gate */ 348 /* See if there is still anything blocking the gate */
343 for (tmp = op->above; tmp != NULL; tmp = tmp->above) 349 for (tmp = op->above; tmp; tmp = tmp->above)
344 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))
345 break; 351 break;
346 352
347 /* IF there is, start putting the gate down */ 353 /* IF there is, start putting the gate down */
348 if (tmp) 354 if (tmp)
349 {
350 op->stats.food = 1; 355 op->stats.food = 1;
351 }
352 else 356 else
353 { 357 {
354 op->move_block = MOVE_ALL; 358 op->move_block = MOVE_ALL;
359
355 if (!op->arch->stats.ac) 360 if (!op->arch->stats.ac)
356 SET_FLAG (op, FLAG_BLOCKSVIEW); 361 SET_FLAG (op, FLAG_BLOCKSVIEW);
357 update_all_los (op->map, op->x, op->y); 362 update_all_los (op->map, op->x, op->y);
358 } 363 }
359 } /* gate is halfway up */ 364 } /* gate is halfway up */
373 int v = op->value; 378 int v = op->value;
374 379
375 if (op->stats.sp) 380 if (op->stats.sp)
376 { 381 {
377 move_gate (op); 382 move_gate (op);
383
378 if (op->value != v) /* change direction ? */ 384 if (op->value != v) /* change direction ? */
379 op->stats.sp = 0; 385 op->stats.sp = 0;
380 return; 386 return;
381 } 387 }
388
382 if (--op->stats.hp <= 0) 389 if (--op->stats.hp <= 0)
383 { /* keep gate down */ 390 { /* keep gate down */
384 move_gate (op); 391 move_gate (op);
392
385 if (op->value != v) 393 if (op->value != v)
386 op->set_speed (0); 394 op->set_speed (0);
387 } 395 }
388} 396}
389 397
401 int last = op->value; 409 int last = op->value;
402 int detected; 410 int detected;
403 411
404 detected = 0; 412 detected = 0;
405 413
406 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)
407 { 415 {
408 object *tmp2; 416 object *tmp2;
409 417
410 if (op->stats.hp) 418 if (op->stats.hp)
411 { 419 {
431 if (detected && last == 0) 439 if (detected && last == 0)
432 { 440 {
433 op->value = 1; 441 op->value = 1;
434 push_button (op); 442 push_button (op);
435 } 443 }
444
436 if (!detected && last == 1) 445 if (!detected && last == 1)
437 { 446 {
438 op->value = 0; 447 op->value = 0;
439 push_button (op); 448 push_button (op);
440 } 449 }
444 if (detected && last == 1) 453 if (detected && last == 1)
445 { 454 {
446 op->value = 0; 455 op->value = 0;
447 push_button (op); 456 push_button (op);
448 } 457 }
458
449 if (!detected && last == 0) 459 if (!detected && last == 0)
450 { 460 {
451 op->value = 1; 461 op->value = 1;
452 push_button (op); 462 push_button (op);
453 } 463 }
454 } 464 }
455} 465}
456
457 466
458void 467void
459animate_trigger (object *op) 468animate_trigger (object *op)
460{ 469{
461 if ((unsigned char) ++op->stats.wc >= NUM_ANIMATIONS (op)) 470 if ((unsigned char) ++op->stats.wc >= NUM_ANIMATIONS (op))
493 502
494 SET_ANIMATION (op, op->stats.wc); 503 SET_ANIMATION (op, op->stats.wc);
495 update_object (op, UP_OBJ_FACE); 504 update_object (op, UP_OBJ_FACE);
496 return; 505 return;
497 } 506 }
507
498 /* We're closing */ 508 /* We're closing */
499 op->move_on = 0; 509 op->move_on = 0;
500 510
501 op->stats.wc++; 511 op->stats.wc++;
502 if ((int) op->stats.wc >= NUM_ANIMATIONS (op)) 512 if ((int) op->stats.wc >= NUM_ANIMATIONS (op))
643/* 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.
644 */ 654 */
645void 655void
646move_arrow (object *op) 656move_arrow (object *op)
647{ 657{
648 object *tmp;
649 sint16 new_x, new_y;
650 int was_reflected, mflags; 658 int was_reflected;
651 maptile *m;
652 659
653 if (op->map == NULL) 660 if (!op->map)
654 { 661 {
655 LOG (llevError, "BUG: Arrow had no map.\n"); 662 LOG (llevError, "BUG: Arrow had no map.\n");
656 op->destroy (); 663 op->destroy ();
657 return; 664 return;
658 } 665 }
688 stop_arrow (op); 695 stop_arrow (op);
689 return; 696 return;
690 } 697 }
691 698
692 /* Calculate target map square */ 699 /* Calculate target map square */
693 new_x = op->x + DIRX (op);
694 new_y = op->y + DIRY (op);
695 was_reflected = 0; 700 was_reflected = 0;
696 701
697 m = op->map; 702 mapxy pos (op); pos.move (op->direction);
698 mflags = get_map_flags (m, &m, new_x, new_y, &new_x, &new_y);
699 703
700 if (mflags & P_OUT_OF_MAP) 704 if (!pos.normalise ())
701 { 705 {
702 stop_arrow (op); 706 stop_arrow (op);
703 return; 707 return;
704 } 708 }
705 709
706 /* 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 */
707 if (mflags & P_IS_ALIVE) 711 if (pos->flags () & P_IS_ALIVE)
708 { 712 {
709 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)
710 if (QUERY_FLAG (tmp, FLAG_ALIVE)) 716 if (QUERY_FLAG (tmp, FLAG_ALIVE))
711 break; 717 break;
712 718
713 /* Not really fair, but don't let monsters hit themselves with 719 /* Not really fair, but don't let monsters hit themselves with
714 * their own arrow - this can be because they fire it then 720 * their own arrow - this can be because they fire it then
737 return; 743 return;
738 } 744 }
739 } /* if this is not hitting its owner */ 745 } /* if this is not hitting its owner */
740 } /* if there is something alive on this space */ 746 } /* if there is something alive on this space */
741 747
742 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))
743 { 749 {
744 int retry = 0; 750 int retry = 0;
745 751
746 /* if the object doesn't reflect, stop the arrow from moving 752 /* if the object doesn't reflect, stop the arrow from moving
747 * 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
760 if (op->direction & 1) 766 if (op->direction & 1)
761 { 767 {
762 op->direction = absdir (op->direction + 4); 768 op->direction = absdir (op->direction + 4);
763 retry = 1; 769 retry = 1;
764 } 770 }
771
765 /* There were two blocks with identical code - 772 /* There were two blocks with identical code -
766 * use this retry here to make this one block 773 * use this retry here to make this one block
767 * that did the same thing. 774 * that did the same thing.
768 */ 775 */
769 while (retry < 2) 776 while (retry < 2)
770 { 777 {
771 int left, right, mflags;
772 maptile *m1;
773 sint16 x1, y1;
774
775 retry++; 778 retry++;
776 779
777 /* 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
778 * over a corner in a tiled map, it is possible that 781 * over a corner in a tiled map, it is possible that
779 * op->direction is within an adjacent map but either 782 * op->direction is within an adjacent map but either
780 * op->direction-1 or op->direction+1 does not exist. 783 * op->direction-1 or op->direction+1 does not exist.
781 */ 784 */
782 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));
783 op->y + freearr_y[absdir (op->direction - 1)], &x1, &y1); 786 bool left = pos1.normalise () && OB_TYPE_MOVE_BLOCK (op, pos1->move_block);
784 left = (mflags & P_OUT_OF_MAP) ? 0 : OB_TYPE_MOVE_BLOCK (op, (GET_MAP_MOVE_BLOCK (m1, x1, y1)));
785 787
786 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));
787 op->y + freearr_y[absdir (op->direction + 1)], &x1, &y1); 789 bool right = pos2.normalise () && OB_TYPE_MOVE_BLOCK (op, pos2->move_block);
788 right = (mflags & P_OUT_OF_MAP) ? 0 : OB_TYPE_MOVE_BLOCK (op, (GET_MAP_MOVE_BLOCK (m1, x1, y1)));
789 790
790 if (left == right) 791 if (left == right)
791 op->direction = absdir (op->direction + 4); 792 op->direction = absdir (op->direction + 4);
792 else if (left) 793 else if (left)
793 op->direction = absdir (op->direction + 2); 794 op->direction = absdir (op->direction + 2);
794 else if (right) 795 else if (right)
795 op->direction = absdir (op->direction - 2); 796 op->direction = absdir (op->direction - 2);
796 797
797 mflags = get_map_flags (op->map, &m1, op->x + DIRX (op), op->y + DIRY (op), &x1, &y1);
798
799 /* 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 -
800 * don't need to retry again. 799 * don't need to retry again.
801 */ 800 */
802 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))
803 break; 803 break;
804
805 } 804 }
805
806 /* Couldn't find a direction to move the arrow to - just 806 /* Couldn't find a direction to move the arrow to - just
807 * top it from moving. 807 * stop it from moving.
808 */ 808 */
809 if (retry == 2) 809 if (retry == 2)
810 { 810 {
811 stop_arrow (op); 811 stop_arrow (op);
812 return; 812 return;
813 } 813 }
814
814 /* update object image for new facing */ 815 /* update object image for new facing */
815 /* many thrown objects *don't* have more than one face */ 816 /* many thrown objects *don't* have more than one face */
816 if (GET_ANIM_ID (op)) 817 if (GET_ANIM_ID (op))
817 SET_ANIMATION (op, op->direction); 818 SET_ANIMATION (op, op->direction);
818 } /* object is reflected */ 819 } /* object is reflected */
819 } /* object ran into a wall */ 820 } /* object ran into a wall */
820 821
821 /* Move the arrow. */
822 op->remove ();
823 op->x = new_x;
824 op->y = new_y;
825
826 /* 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
827 * about 17 squares. Tune as needed. 823 * about 17 squares. Tune as needed.
828 */ 824 */
829 op->speed -= 0.05; 825 op->speed -= 0.05;
830 insert_ob_in_map (op, m, op, 0);
831}
832 826
833/* This routine doesnt seem to work for "inanimate" objects that 827 /* Move the arrow. */
834 * are being carried, ie a held torch leaps from your hands!. 828 op->move_to (pos);
835 * Modified this routine to allow held objects. b.t. */ 829}
836 830
837void 831void
838change_object (object *op) 832change_object (object *op)
839{ /* Doesn`t handle linked objs yet */ 833{ /* Doesn`t handle linked objs yet */
840 int i, j; 834 int i, j;
841 835
842 if (op->other_arch == NULL) 836 if (!op->other_arch)
843 { 837 {
844 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 ());
845 return; 839 return;
846 } 840 }
847 841
848 /* In non-living items only change when food value is 0 */ 842 /* In non-living items only change when food value is 0 */
849 if (!QUERY_FLAG (op, FLAG_ALIVE)) 843 if (!QUERY_FLAG (op, FLAG_ALIVE))
850 { 844 {
851 if (op->stats.food-- > 0) 845 if (op->stats.food-- > 0)
852 return; 846 return;
853 else 847
854 op->stats.food = 1; /* so 1 other_arch is made */ 848 op->stats.food = 1; /* so 1 other_arch is made */
855 } 849 }
856 850
857 object *pl = op->in_player ();
858 object *env = op->env; 851 object *env = op->env;
859 852
860 op->remove (); 853 op->remove ();
861 for (i = 0; i < NROFNEWOBJS (op); i++) 854 for (i = 0; i < op->stats.food; i++)
862 { 855 {
863 object *tmp = arch_to_object (op->other_arch); 856 object *tmp = arch_to_object (op->other_arch);
864 857
865 if (op->type == LAMP) 858 if (op->type == LAMP)
866 tmp->stats.food = op->stats.food - 1; 859 tmp->stats.food = op->stats.food - 1;
867 860
868 tmp->stats.hp = op->stats.hp; /* The only variable it keeps. */ 861 tmp->stats.hp = op->stats.hp; /* The only variable it keeps. */
869 if (env) 862 if (env)
870 { 863 {
871 tmp->x = env->x, tmp->y = env->y;
872 tmp = insert_ob_in_ob (tmp, env); 864 tmp = env->insert (tmp);
873 865
874 /* 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
875 * 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
876 * 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.
877 */ 869 */
878 if (pl) 870 if (object *pl = op->in_player ())
879 { 871 {
880 esrv_del_item (pl->contr, op->count); 872 esrv_del_item (pl->contr, op->count);
881 esrv_send_item (pl, tmp); 873 esrv_send_item (pl, tmp);
882 } 874 }
883 } 875 }
884 else 876 else
885 { 877 {
886 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);
887 if (j == -1) /* No free spot */ 879 if (j < 0) /* No free spot */
888 tmp->destroy (); 880 tmp->destroy ();
889 else 881 else
890 { 882 {
891 tmp->x = op->x + freearr_x[j], tmp->y = op->y + freearr_y[j]; 883 mapxy pos (op); pos.move (j);
892 insert_ob_in_map (tmp, op->map, op, 0); 884
885 if (pos.normalise ())
886 pos.insert (tmp, op);
893 } 887 }
894 } 888 }
895 } 889 }
896 890
897 op->destroy (); 891 op->destroy ();
1171 * 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.
1172 * 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
1173 * more concern with large objects, most notably a part being placed 1167 * more concern with large objects, most notably a part being placed
1174 * outside of the map which would cause the server to crash 1168 * outside of the map which would cause the server to crash
1175*/ 1169*/
1176
1177void 1170void
1178move_creator (object *creator) 1171move_creator (object *creator)
1179{ 1172{
1180 object *new_ob; 1173 object *new_ob;
1181 1174
1216 new_ob = object_create_arch (creator->other_arch); 1209 new_ob = object_create_arch (creator->other_arch);
1217 fix_generated_item (new_ob, creator, 0, 0, GT_MINIMAL); 1210 fix_generated_item (new_ob, creator, 0, 0, GT_MINIMAL);
1218 } 1211 }
1219 1212
1220 /* Make sure this multipart object fits */ 1213 /* Make sure this multipart object fits */
1221 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))
1222 { 1215 {
1223 new_ob->destroy (); 1216 new_ob->destroy ();
1224 return; 1217 return;
1225 } 1218 }
1226 1219
1318 if (QUERY_FLAG (op, FLAG_APPLIED)) 1311 if (QUERY_FLAG (op, FLAG_APPLIED))
1319 remove_force (op); 1312 remove_force (op);
1320 else 1313 else
1321 { 1314 {
1322 /* If necessary, delete the item from the players inventory */ 1315 /* If necessary, delete the item from the players inventory */
1323 object *pl = op->in_player (); 1316 if (object *pl = op->in_player ())
1324
1325 if (pl)
1326 esrv_del_item (pl->contr, op->count); 1317 esrv_del_item (pl->contr, op->count);
1327 1318
1328 op->remove (); 1319 op->remove ();
1329 1320
1330 if (QUERY_FLAG (op, FLAG_SEE_ANYWHERE)) 1321 if (QUERY_FLAG (op, FLAG_SEE_ANYWHERE))

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines