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.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;
104 int dir;
101 105
102 if (QUERY_FLAG (gen, FLAG_CONTENT_ON_GEN)) 106 if (QUERY_FLAG (gen, FLAG_CONTENT_ON_GEN))
103 { 107 {
104 // either copy one item from the inventory... 108 // either copy one item from the inventory...
105 if (!gen->inv) 109 if (!gen->inv)
109 int index = 0; 113 int index = 0;
110 for (object *tmp = gen->inv; tmp; tmp = tmp->below) 114 for (object *tmp = gen->inv; tmp; tmp = tmp->below)
111 if (!rndm (++index)) 115 if (!rndm (++index))
112 op = tmp; 116 op = tmp;
113 117
118 dir = find_free_spot (op, gen->map, gen->x, gen->y, 1, SIZEOFFREE1 + 1);
119 if (dir < 0)
120 return;
121
114 op = object_create_clone (op); 122 op = object_create_clone (op);
115 123
116 CLEAR_FLAG (op, FLAG_IS_A_TEMPLATE); 124 CLEAR_FLAG (op, FLAG_IS_A_TEMPLATE);
117 unflag_inv (op, FLAG_IS_A_TEMPLATE); 125 unflag_inv (op, FLAG_IS_A_TEMPLATE);
118 } 126 }
119 else if (gen->other_arch) 127 else if (gen->other_arch)
120 { 128 {
121 // ...or use other_arch 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
122 op = arch_to_object (gen->other_arch); 134 op = arch_to_object (gen->other_arch);
123 } 135 }
124 else 136 else
125 return; 137 return;
126 138
127 op->expand_tail (); 139 op->expand_tail ();
128 140
129 int i = find_free_spot (op, gen->map, gen->x, gen->y, 1, 9); 141 mapxy pos (gen); pos.move (dir);
130 if (i >= 0) 142
143 if (pos.insert (op, gen))
131 { 144 {
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)) 145 if (rndm (0, 9))
135 generate_artifact (op, gen->map->difficulty); 146 generate_artifact (op, gen->map->difficulty);
136 147
137 if (op->has_random_items ()) 148 if (op->has_random_items ())
138 create_treasure (op->randomitems, op, GT_APPLY, gen->map->difficulty); 149 create_treasure (op->randomitems, op, GT_APPLY, gen->map->difficulty);
139 150
140 return; 151 return;
141 }
142 } 152 }
143 153
144 op->destroy (); 154 op->destroy ();
145} 155}
146 156
263 * 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,
264 * otherwise, we fall through to the code below which should lower 274 * otherwise, we fall through to the code below which should lower
265 * the gate slightly. 275 * the gate slightly.
266 */ 276 */
267 277
268 for (tmp = op->above; tmp != NULL; tmp = tmp->above) 278 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)) 279 if (!QUERY_FLAG (tmp, FLAG_NO_PICK) || QUERY_FLAG (tmp, FLAG_CAN_ROLL) || QUERY_FLAG (tmp, FLAG_ALIVE))
270 break; 280 break;
271 281
272 if (tmp == NULL) 282 if (!tmp)
273 { 283 {
274 if (op->arch->speed) 284 if (op->arch->speed)
275 op->value = 1; 285 op->value = 1;
276 else 286 else
277 op->set_speed (0); 287 op->set_speed (0);
290 } 300 }
291 else 301 else
292 { /* The gate is still going up */ 302 { /* The gate is still going up */
293 op->stats.wc++; 303 op->stats.wc++;
294 304
295 if ((int) op->stats.wc >= (NUM_ANIMATIONS (op))) 305 if (op->stats.wc >= NUM_ANIMATIONS (op))
296 op->stats.wc = (signed char) NUM_ANIMATIONS (op) - 1; 306 op->stats.wc = NUM_ANIMATIONS (op) - 1;
297 307
298 /* 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.
299 * 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
300 */ 310 */
301 if ((int) op->stats.wc >= NUM_ANIMATIONS (op) / 2) 311 if (op->stats.wc >= NUM_ANIMATIONS (op) / 2)
302 { 312 {
303 /* Halfway or further, check blocks */ 313 /* Halfway or further, check blocks */
304 /* First, get the top object on the square. */ 314 /* First, get the top object on the square. */
305 for (tmp = op->above; tmp && tmp->above; tmp = tmp->above) 315 for (tmp = op->above; tmp && tmp->above; tmp = tmp->above)
306 ; 316 ;
308 if (tmp) 318 if (tmp)
309 { 319 {
310 if (QUERY_FLAG (tmp, FLAG_ALIVE)) 320 if (QUERY_FLAG (tmp, FLAG_ALIVE))
311 { 321 {
312 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"));
313 324
314 if (tmp->type == PLAYER) 325 if (tmp->type == PLAYER)
315 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);
316 } 327 }
317 else
318 /* If the object is not alive, and the object either can 328 /* If the object is not alive, and the object either can
319 * be picked up or the object rolls, move the object 329 * be picked up or the object rolls, move the object
320 * off the gate. 330 * off the gate.
321 */ 331 */
322 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)))
323 { 333 {
324 /* If it has speed, it should move itself, otherwise: */ 334 /* If it has speed, it should move itself, otherwise: */
325 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);
326 336
327 /* If there is a free spot, move the object someplace */ 337 /* If there is a free spot, move the object someplace */
328 if (i != -1) 338 if (i > 0)
329 { 339 {
340 mapxy pos (tmp);
341 pos.move (i);
342 if (pos.normalise ())
330 tmp->remove (); 343 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 } 344 }
334 } 345 }
335 } 346 }
336 347
337 /* See if there is still anything blocking the gate */ 348 /* See if there is still anything blocking the gate */
338 for (tmp = op->above; tmp != NULL; tmp = tmp->above) 349 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)) 350 if (!QUERY_FLAG (tmp, FLAG_NO_PICK) || QUERY_FLAG (tmp, FLAG_CAN_ROLL) || QUERY_FLAG (tmp, FLAG_ALIVE))
340 break; 351 break;
341 352
342 /* IF there is, start putting the gate down */ 353 /* IF there is, start putting the gate down */
343 if (tmp) 354 if (tmp)
344 {
345 op->stats.food = 1; 355 op->stats.food = 1;
346 }
347 else 356 else
348 { 357 {
349 op->move_block = MOVE_ALL; 358 op->move_block = MOVE_ALL;
359
350 if (!op->arch->stats.ac) 360 if (!op->arch->stats.ac)
351 SET_FLAG (op, FLAG_BLOCKSVIEW); 361 SET_FLAG (op, FLAG_BLOCKSVIEW);
352 update_all_los (op->map, op->x, op->y); 362 update_all_los (op->map, op->x, op->y);
353 } 363 }
354 } /* gate is halfway up */ 364 } /* gate is halfway up */
368 int v = op->value; 378 int v = op->value;
369 379
370 if (op->stats.sp) 380 if (op->stats.sp)
371 { 381 {
372 move_gate (op); 382 move_gate (op);
383
373 if (op->value != v) /* change direction ? */ 384 if (op->value != v) /* change direction ? */
374 op->stats.sp = 0; 385 op->stats.sp = 0;
375 return; 386 return;
376 } 387 }
388
377 if (--op->stats.hp <= 0) 389 if (--op->stats.hp <= 0)
378 { /* keep gate down */ 390 { /* keep gate down */
379 move_gate (op); 391 move_gate (op);
392
380 if (op->value != v) 393 if (op->value != v)
381 op->set_speed (0); 394 op->set_speed (0);
382 } 395 }
383} 396}
384 397
396 int last = op->value; 409 int last = op->value;
397 int detected; 410 int detected;
398 411
399 detected = 0; 412 detected = 0;
400 413
401 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)
402 { 415 {
403 object *tmp2; 416 object *tmp2;
404 417
405 if (op->stats.hp) 418 if (op->stats.hp)
406 { 419 {
426 if (detected && last == 0) 439 if (detected && last == 0)
427 { 440 {
428 op->value = 1; 441 op->value = 1;
429 push_button (op); 442 push_button (op);
430 } 443 }
444
431 if (!detected && last == 1) 445 if (!detected && last == 1)
432 { 446 {
433 op->value = 0; 447 op->value = 0;
434 push_button (op); 448 push_button (op);
435 } 449 }
439 if (detected && last == 1) 453 if (detected && last == 1)
440 { 454 {
441 op->value = 0; 455 op->value = 0;
442 push_button (op); 456 push_button (op);
443 } 457 }
458
444 if (!detected && last == 0) 459 if (!detected && last == 0)
445 { 460 {
446 op->value = 1; 461 op->value = 1;
447 push_button (op); 462 push_button (op);
448 } 463 }
449 } 464 }
450} 465}
451
452 466
453void 467void
454animate_trigger (object *op) 468animate_trigger (object *op)
455{ 469{
456 if ((unsigned char) ++op->stats.wc >= NUM_ANIMATIONS (op)) 470 if ((unsigned char) ++op->stats.wc >= NUM_ANIMATIONS (op))
488 502
489 SET_ANIMATION (op, op->stats.wc); 503 SET_ANIMATION (op, op->stats.wc);
490 update_object (op, UP_OBJ_FACE); 504 update_object (op, UP_OBJ_FACE);
491 return; 505 return;
492 } 506 }
507
493 /* We're closing */ 508 /* We're closing */
494 op->move_on = 0; 509 op->move_on = 0;
495 510
496 op->stats.wc++; 511 op->stats.wc++;
497 if ((int) op->stats.wc >= NUM_ANIMATIONS (op)) 512 if ((int) op->stats.wc >= NUM_ANIMATIONS (op))
638/* 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.
639 */ 654 */
640void 655void
641move_arrow (object *op) 656move_arrow (object *op)
642{ 657{
643 object *tmp;
644 sint16 new_x, new_y;
645 int was_reflected, mflags; 658 int was_reflected;
646 maptile *m;
647 659
648 if (op->map == NULL) 660 if (!op->map)
649 { 661 {
650 LOG (llevError, "BUG: Arrow had no map.\n"); 662 LOG (llevError, "BUG: Arrow had no map.\n");
651 op->destroy (); 663 op->destroy ();
652 return; 664 return;
653 } 665 }
683 stop_arrow (op); 695 stop_arrow (op);
684 return; 696 return;
685 } 697 }
686 698
687 /* Calculate target map square */ 699 /* Calculate target map square */
688 new_x = op->x + DIRX (op);
689 new_y = op->y + DIRY (op);
690 was_reflected = 0; 700 was_reflected = 0;
691 701
692 m = op->map; 702 mapxy pos (op); pos.move (op->direction);
693 mflags = get_map_flags (m, &m, new_x, new_y, &new_x, &new_y);
694 703
695 if (mflags & P_OUT_OF_MAP) 704 if (!pos.normalise ())
696 { 705 {
697 stop_arrow (op); 706 stop_arrow (op);
698 return; 707 return;
699 } 708 }
700 709
701 /* 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 */
702 if (mflags & P_IS_ALIVE) 711 if (pos->flags () & P_IS_ALIVE)
703 { 712 {
704 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)
705 if (QUERY_FLAG (tmp, FLAG_ALIVE)) 716 if (QUERY_FLAG (tmp, FLAG_ALIVE))
706 break; 717 break;
707 718
708 /* Not really fair, but don't let monsters hit themselves with 719 /* Not really fair, but don't let monsters hit themselves with
709 * their own arrow - this can be because they fire it then 720 * their own arrow - this can be because they fire it then
732 return; 743 return;
733 } 744 }
734 } /* if this is not hitting its owner */ 745 } /* if this is not hitting its owner */
735 } /* if there is something alive on this space */ 746 } /* if there is something alive on this space */
736 747
737 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))
738 { 749 {
739 int retry = 0; 750 int retry = 0;
740 751
741 /* if the object doesn't reflect, stop the arrow from moving 752 /* if the object doesn't reflect, stop the arrow from moving
742 * 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
755 if (op->direction & 1) 766 if (op->direction & 1)
756 { 767 {
757 op->direction = absdir (op->direction + 4); 768 op->direction = absdir (op->direction + 4);
758 retry = 1; 769 retry = 1;
759 } 770 }
771
760 /* There were two blocks with identical code - 772 /* There were two blocks with identical code -
761 * use this retry here to make this one block 773 * use this retry here to make this one block
762 * that did the same thing. 774 * that did the same thing.
763 */ 775 */
764 while (retry < 2) 776 while (retry < 2)
765 { 777 {
766 int left, right, mflags;
767 maptile *m1;
768 sint16 x1, y1;
769
770 retry++; 778 retry++;
771 779
772 /* 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
773 * over a corner in a tiled map, it is possible that 781 * over a corner in a tiled map, it is possible that
774 * op->direction is within an adjacent map but either 782 * op->direction is within an adjacent map but either
775 * op->direction-1 or op->direction+1 does not exist. 783 * op->direction-1 or op->direction+1 does not exist.
776 */ 784 */
777 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));
778 op->y + freearr_y[absdir (op->direction - 1)], &x1, &y1); 786 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 787
781 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));
782 op->y + freearr_y[absdir (op->direction + 1)], &x1, &y1); 789 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 790
785 if (left == right) 791 if (left == right)
786 op->direction = absdir (op->direction + 4); 792 op->direction = absdir (op->direction + 4);
787 else if (left) 793 else if (left)
788 op->direction = absdir (op->direction + 2); 794 op->direction = absdir (op->direction + 2);
789 else if (right) 795 else if (right)
790 op->direction = absdir (op->direction - 2); 796 op->direction = absdir (op->direction - 2);
791 797
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 - 798 /* If this space is not out of the map and not blocked, valid space -
795 * don't need to retry again. 799 * don't need to retry again.
796 */ 800 */
797 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))
798 break; 803 break;
799
800 } 804 }
805
801 /* Couldn't find a direction to move the arrow to - just 806 /* Couldn't find a direction to move the arrow to - just
802 * top it from moving. 807 * stop it from moving.
803 */ 808 */
804 if (retry == 2) 809 if (retry == 2)
805 { 810 {
806 stop_arrow (op); 811 stop_arrow (op);
807 return; 812 return;
808 } 813 }
814
809 /* update object image for new facing */ 815 /* update object image for new facing */
810 /* many thrown objects *don't* have more than one face */ 816 /* many thrown objects *don't* have more than one face */
811 if (GET_ANIM_ID (op)) 817 if (GET_ANIM_ID (op))
812 SET_ANIMATION (op, op->direction); 818 SET_ANIMATION (op, op->direction);
813 } /* object is reflected */ 819 } /* object is reflected */
814 } /* object ran into a wall */ 820 } /* object ran into a wall */
815 821
816 /* Move the arrow. */
817 op->remove ();
818 op->x = new_x;
819 op->y = new_y;
820
821 /* 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
822 * about 17 squares. Tune as needed. 823 * about 17 squares. Tune as needed.
823 */ 824 */
824 op->speed -= 0.05; 825 op->speed -= 0.05;
825 insert_ob_in_map (op, m, op, 0);
826}
827 826
828/* This routine doesnt seem to work for "inanimate" objects that 827 /* Move the arrow. */
829 * are being carried, ie a held torch leaps from your hands!. 828 op->move_to (pos);
830 * Modified this routine to allow held objects. b.t. */ 829}
831 830
832void 831void
833change_object (object *op) 832change_object (object *op)
834{ /* Doesn`t handle linked objs yet */ 833{ /* Doesn`t handle linked objs yet */
835 int i, j; 834 int i, j;
836 835
837 if (op->other_arch == NULL) 836 if (!op->other_arch)
838 { 837 {
839 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 ());
840 return; 839 return;
841 } 840 }
842 841
843 /* In non-living items only change when food value is 0 */ 842 /* In non-living items only change when food value is 0 */
844 if (!QUERY_FLAG (op, FLAG_ALIVE)) 843 if (!QUERY_FLAG (op, FLAG_ALIVE))
845 { 844 {
846 if (op->stats.food-- > 0) 845 if (op->stats.food-- > 0)
847 return; 846 return;
848 else 847
849 op->stats.food = 1; /* so 1 other_arch is made */ 848 op->stats.food = 1; /* so 1 other_arch is made */
850 } 849 }
851 850
852 object *pl = op->in_player ();
853 object *env = op->env; 851 object *env = op->env;
854 852
855 op->remove (); 853 op->remove ();
856 for (i = 0; i < NROFNEWOBJS (op); i++) 854 for (i = 0; i < op->stats.food; i++)
857 { 855 {
858 object *tmp = arch_to_object (op->other_arch); 856 object *tmp = arch_to_object (op->other_arch);
859 857
860 if (op->type == LAMP) 858 if (op->type == LAMP)
861 tmp->stats.food = op->stats.food - 1; 859 tmp->stats.food = op->stats.food - 1;
862 860
863 tmp->stats.hp = op->stats.hp; /* The only variable it keeps. */ 861 tmp->stats.hp = op->stats.hp; /* The only variable it keeps. */
864 if (env) 862 if (env)
865 { 863 {
866 tmp->x = env->x, tmp->y = env->y;
867 tmp = insert_ob_in_ob (tmp, env); 864 tmp = env->insert (tmp);
868 865
869 /* 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
870 * 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
871 * 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.
872 */ 869 */
873 if (pl) 870 if (object *pl = op->in_player ())
874 { 871 {
875 esrv_del_item (pl->contr, op->count); 872 esrv_del_item (pl->contr, op->count);
876 esrv_send_item (pl, tmp); 873 esrv_send_item (pl, tmp);
877 } 874 }
878 } 875 }
879 else 876 else
880 { 877 {
881 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);
882 if (j == -1) /* No free spot */ 879 if (j < 0) /* No free spot */
883 tmp->destroy (); 880 tmp->destroy ();
884 else 881 else
885 { 882 {
886 tmp->x = op->x + freearr_x[j], tmp->y = op->y + freearr_y[j]; 883 mapxy pos (op); pos.move (j);
887 insert_ob_in_map (tmp, op->map, op, 0); 884
885 if (pos.normalise ())
886 pos.insert (tmp, op);
888 } 887 }
889 } 888 }
890 } 889 }
891 890
892 op->destroy (); 891 op->destroy ();
1166 * 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.
1167 * 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
1168 * more concern with large objects, most notably a part being placed 1167 * more concern with large objects, most notably a part being placed
1169 * outside of the map which would cause the server to crash 1168 * outside of the map which would cause the server to crash
1170*/ 1169*/
1171
1172void 1170void
1173move_creator (object *creator) 1171move_creator (object *creator)
1174{ 1172{
1175 object *new_ob; 1173 object *new_ob;
1176 1174
1211 new_ob = object_create_arch (creator->other_arch); 1209 new_ob = object_create_arch (creator->other_arch);
1212 fix_generated_item (new_ob, creator, 0, 0, GT_MINIMAL); 1210 fix_generated_item (new_ob, creator, 0, 0, GT_MINIMAL);
1213 } 1211 }
1214 1212
1215 /* Make sure this multipart object fits */ 1213 /* Make sure this multipart object fits */
1216 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))
1217 { 1215 {
1218 new_ob->destroy (); 1216 new_ob->destroy ();
1219 return; 1217 return;
1220 } 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);
1221 1223
1222 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);
1223 if (QUERY_FLAG (new_ob, FLAG_FREED)) 1225 if (QUERY_FLAG (new_ob, FLAG_FREED))
1224 return; 1226 return;
1225 1227
1240void 1242void
1241move_marker (object *op) 1243move_marker (object *op)
1242{ 1244{
1243 if (object *tmp = op->ms ().player ()) 1245 if (object *tmp = op->ms ().player ())
1244 { 1246 {
1245 object *tmp2;
1246
1247 /* remove an old force with a slaying field == op->name */ 1247 /* remove an old force with a slaying field == op->name */
1248 for (tmp2 = tmp->inv; tmp2; tmp2 = tmp2->below) 1248 if (object *force = tmp->force_find (op->name))
1249 if (tmp2->type == FORCE && tmp2->slaying && tmp2->slaying == op->name) 1249 force->destroy ();
1250
1251 if (!tmp->force_find (op->slaying))
1250 { 1252 {
1251 tmp2->destroy (); 1253 tmp->force_add (op->slaying, op->stats.food);
1252 break;
1253 }
1254 1254
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) 1255 if (op->msg)
1283 new_draw_info (NDI_UNIQUE | NDI_NAVY, 0, tmp, op->msg); 1256 new_draw_info (NDI_UNIQUE | NDI_NAVY, 0, tmp, op->msg);
1284 1257
1285 if (op->stats.hp > 0) 1258 if (op->stats.hp > 0)
1286 { 1259 {
1287 op->stats.hp--; 1260 op->stats.hp--;
1261
1288 if (op->stats.hp == 0) 1262 if (op->stats.hp == 0)
1289 { 1263 {
1290 /* marker expires--granted mark number limit */ 1264 /* marker expires--granted mark number limit */
1291 op->destroy (); 1265 op->destroy ();
1292 return; 1266 return;
1337 if (QUERY_FLAG (op, FLAG_APPLIED)) 1311 if (QUERY_FLAG (op, FLAG_APPLIED))
1338 remove_force (op); 1312 remove_force (op);
1339 else 1313 else
1340 { 1314 {
1341 /* If necessary, delete the item from the players inventory */ 1315 /* If necessary, delete the item from the players inventory */
1342 object *pl = op->in_player (); 1316 if (object *pl = op->in_player ())
1343
1344 if (pl)
1345 esrv_del_item (pl->contr, op->count); 1317 esrv_del_item (pl->contr, op->count);
1346 1318
1347 op->remove (); 1319 op->remove ();
1348 1320
1349 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