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.51 by root, Fri May 18 20:45:37 2007 UTC vs.
Revision 1.69 by root, Sat Sep 15 15:58:06 2007 UTC

1/* 1/*
2 * CrossFire, A Multiplayer game 2 * This file is part of Crossfire TRT, the Roguelike Realtime MORPG.
3 * 3 *
4 * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team 4 * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Crossfire TRT team
5 * Copyright (C) 2002 Mark Wedel & Crossfire Development Team 5 * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team
6 * Copyright (C) 1992 Frank Tore Johansen 6 * Copyright (©) 1992,2007 Frank Tore Johansen
7 * 7 *
8 * This program is free software; you can redistribute it and/or modify 8 * Crossfire TRT 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 2 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,
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 GNU General Public License
19 * along with this program; if not, write to the Free Software 19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 * 20 *
22 * The authors can be reached via e-mail at <crossfire@schmorp.de> 21 * The authors can be reached via e-mail to <crossfire@schmorp.de>
23 */ 22 */
24 23
25/* 24/*
26 * 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
27 * collected in this file. 26 * collected in this file.
97 96
98 if (GENERATE_SPEED (gen) && rndm (0, GENERATE_SPEED (gen) - 1)) 97 if (GENERATE_SPEED (gen) && rndm (0, GENERATE_SPEED (gen) - 1))
99 return; 98 return;
100 99
101 object *op; 100 object *op;
101 int dir;
102 102
103 if (QUERY_FLAG (gen, FLAG_CONTENT_ON_GEN)) 103 if (QUERY_FLAG (gen, FLAG_CONTENT_ON_GEN))
104 { 104 {
105 // either copy one item form the inventory... 105 // either copy one item from the inventory...
106 if (!gen->inv) 106 if (!gen->inv)
107 return; 107 return;
108 108
109 // first select one item from the inventory 109 // first select one item from the inventory
110 int index = 0; 110 int index = 0;
111 for (object *tmp = gen->inv; tmp; tmp = tmp->below) 111 for (object *tmp = gen->inv; tmp; tmp = tmp->below)
112 if (!rndm (++index)) 112 if (!rndm (++index))
113 op = tmp; 113 op = tmp;
114 114
115 dir = find_free_spot (op, gen->map, gen->x, gen->y, 1, SIZEOFFREE1 + 1);
116 if (dir < 0)
117 return;
118
115 op = object_create_clone (op); 119 op = object_create_clone (op);
116 120
117 CLEAR_FLAG (op, FLAG_IS_A_TEMPLATE); 121 CLEAR_FLAG (op, FLAG_IS_A_TEMPLATE);
118 unflag_inv (op, FLAG_IS_A_TEMPLATE); 122 unflag_inv (op, FLAG_IS_A_TEMPLATE);
119 } 123 }
124 else if (gen->other_arch)
125 {
126 // ...or use other_arch
127 dir = find_free_spot (gen->other_arch, gen->map, gen->x, gen->y, 1, SIZEOFFREE1 + 1);
128 if (dir < 0)
129 return;
130
131 op = arch_to_object (gen->other_arch);
132 }
120 else 133 else
121 {
122 // ...or use other_arch
123 if (archetype *at = gen->other_arch)
124 op = arch_to_object (at);
125 else
126 return; 134 return;
127 }
128 135
129 op->expand_tail (); 136 op->expand_tail ();
130 137
131 int i = find_free_spot (op, gen->map, gen->x, gen->y, 1, 9); 138 mapxy pos (gen); pos.move (dir);
132 if (i >= 0) 139
140 if (pos.insert (op, gen))
133 { 141 {
134 if (insert_ob_in_map_at (op, gen->map, gen, 0, gen->x + freearr_x[i], gen->y + freearr_y[i]))
135 {
136 if (rndm (0, 9)) 142 if (rndm (0, 9))
137 generate_artifact (op, gen->map->difficulty); 143 generate_artifact (op, gen->map->difficulty);
138 144
139 if (op->has_random_items ()) 145 if (op->has_random_items ())
140 create_treasure (op->randomitems, op, GT_APPLY, gen->map->difficulty); 146 create_treasure (op->randomitems, op, GT_APPLY, gen->map->difficulty);
141 147
142 return; 148 return;
143 }
144 } 149 }
145 150
146 op->destroy (); 151 op->destroy ();
147} 152}
148 153
235 if (op->value) 240 if (op->value)
236 { 241 {
237 if (--op->stats.wc <= 0) 242 if (--op->stats.wc <= 0)
238 { /* Reached bottom, let's stop */ 243 { /* Reached bottom, let's stop */
239 op->stats.wc = 0; 244 op->stats.wc = 0;
240 if (op->arch->clone.speed) 245 if (op->arch->speed)
241 op->value = 0; 246 op->value = 0;
242 else 247 else
243 op->set_speed (0); 248 op->set_speed (0);
244 } 249 }
245 250
265 * objects are above the gate. If so, we finish closing the gate, 270 * objects are above the gate. If so, we finish closing the gate,
266 * otherwise, we fall through to the code below which should lower 271 * otherwise, we fall through to the code below which should lower
267 * the gate slightly. 272 * the gate slightly.
268 */ 273 */
269 274
270 for (tmp = op->above; tmp != NULL; tmp = tmp->above) 275 for (tmp = op->above; tmp; tmp = tmp->above)
271 if (!QUERY_FLAG (tmp, FLAG_NO_PICK) || QUERY_FLAG (tmp, FLAG_CAN_ROLL) || QUERY_FLAG (tmp, FLAG_ALIVE)) 276 if (!QUERY_FLAG (tmp, FLAG_NO_PICK) || QUERY_FLAG (tmp, FLAG_CAN_ROLL) || QUERY_FLAG (tmp, FLAG_ALIVE))
272 break; 277 break;
273 278
274 if (tmp == NULL) 279 if (!tmp)
275 { 280 {
276 if (op->arch->clone.speed) 281 if (op->arch->speed)
277 op->value = 1; 282 op->value = 1;
278 else 283 else
279 op->set_speed (0); 284 op->set_speed (0);
280 285
281 return; 286 return;
292 } 297 }
293 else 298 else
294 { /* The gate is still going up */ 299 { /* The gate is still going up */
295 op->stats.wc++; 300 op->stats.wc++;
296 301
297 if ((int) op->stats.wc >= (NUM_ANIMATIONS (op))) 302 if (op->stats.wc >= NUM_ANIMATIONS (op))
298 op->stats.wc = (signed char) NUM_ANIMATIONS (op) - 1; 303 op->stats.wc = NUM_ANIMATIONS (op) - 1;
299 304
300 /* If there is something on top of the gate, we try to roll it off. 305 /* If there is something on top of the gate, we try to roll it off.
301 * If a player/monster, we don't roll, we just hit them with damage 306 * If a player/monster, we don't roll, we just hit them with damage
302 */ 307 */
303 if ((int) op->stats.wc >= NUM_ANIMATIONS (op) / 2) 308 if (op->stats.wc >= NUM_ANIMATIONS (op) / 2)
304 { 309 {
305 /* Halfway or further, check blocks */ 310 /* Halfway or further, check blocks */
306 /* First, get the top object on the square. */ 311 /* First, get the top object on the square. */
307 for (tmp = op->above; tmp && tmp->above; tmp = tmp->above) 312 for (tmp = op->above; tmp && tmp->above; tmp = tmp->above)
308 ; 313 ;
310 if (tmp) 315 if (tmp)
311 { 316 {
312 if (QUERY_FLAG (tmp, FLAG_ALIVE)) 317 if (QUERY_FLAG (tmp, FLAG_ALIVE))
313 { 318 {
314 hit_player (tmp, random_roll (0, op->stats.dam, tmp, PREFER_LOW), op, AT_PHYSICAL, 1); 319 hit_player (tmp, random_roll (0, op->stats.dam, tmp, PREFER_LOW), op, AT_PHYSICAL, 1);
320 op->play_sound (sound_find ("blocked_gate"));
315 321
316 if (tmp->type == PLAYER) 322 if (tmp->type == PLAYER)
317 new_draw_info_format (NDI_UNIQUE, 0, tmp, "You are crushed by the %s!", &op->name); 323 new_draw_info_format (NDI_UNIQUE, 0, tmp, "You are crushed by the %s!", &op->name);
318 } 324 }
319 else
320 /* If the object is not alive, and the object either can 325 /* If the object is not alive, and the object either can
321 * be picked up or the object rolls, move the object 326 * be picked up or the object rolls, move the object
322 * off the gate. 327 * off the gate.
323 */ 328 */
324 if (!QUERY_FLAG (tmp, FLAG_ALIVE) && (!QUERY_FLAG (tmp, FLAG_NO_PICK) || QUERY_FLAG (tmp, FLAG_CAN_ROLL))) 329 else if (!QUERY_FLAG (tmp, FLAG_ALIVE) && (!QUERY_FLAG (tmp, FLAG_NO_PICK) || QUERY_FLAG (tmp, FLAG_CAN_ROLL)))
325 { 330 {
326 /* If it has speed, it should move itself, otherwise: */ 331 /* If it has speed, it should move itself, otherwise: */
327 int i = find_free_spot (tmp, op->map, op->x, op->y, 1, 9); 332 int i = find_free_spot (tmp, op->map, op->x, op->y, 1, SIZEOFFREE1 + 1);
328 333
329 /* If there is a free spot, move the object someplace */ 334 /* If there is a free spot, move the object someplace */
330 if (i != -1) 335 if (i > 0)
331 { 336 {
337 mapxy pos (tmp);
338 pos.move (i);
339 if (pos.normalise ())
332 tmp->remove (); 340 tmp->move_to (pos);
333 tmp->x += freearr_x[i], tmp->y += freearr_y[i];
334 insert_ob_in_map (tmp, op->map, op, 0);
335 } 341 }
336 } 342 }
337 } 343 }
338 344
339 /* See if there is still anything blocking the gate */ 345 /* See if there is still anything blocking the gate */
340 for (tmp = op->above; tmp != NULL; tmp = tmp->above) 346 for (tmp = op->above; tmp; tmp = tmp->above)
341 if (!QUERY_FLAG (tmp, FLAG_NO_PICK) || QUERY_FLAG (tmp, FLAG_CAN_ROLL) || QUERY_FLAG (tmp, FLAG_ALIVE)) 347 if (!QUERY_FLAG (tmp, FLAG_NO_PICK) || QUERY_FLAG (tmp, FLAG_CAN_ROLL) || QUERY_FLAG (tmp, FLAG_ALIVE))
342 break; 348 break;
343 349
344 /* IF there is, start putting the gate down */ 350 /* IF there is, start putting the gate down */
345 if (tmp) 351 if (tmp)
346 {
347 op->stats.food = 1; 352 op->stats.food = 1;
348 }
349 else 353 else
350 { 354 {
351 op->move_block = MOVE_ALL; 355 op->move_block = MOVE_ALL;
356
352 if (!op->arch->clone.stats.ac) 357 if (!op->arch->stats.ac)
353 SET_FLAG (op, FLAG_BLOCKSVIEW); 358 SET_FLAG (op, FLAG_BLOCKSVIEW);
354 update_all_los (op->map, op->x, op->y); 359 update_all_los (op->map, op->x, op->y);
355 } 360 }
356 } /* gate is halfway up */ 361 } /* gate is halfway up */
357 362
370 int v = op->value; 375 int v = op->value;
371 376
372 if (op->stats.sp) 377 if (op->stats.sp)
373 { 378 {
374 move_gate (op); 379 move_gate (op);
380
375 if (op->value != v) /* change direction ? */ 381 if (op->value != v) /* change direction ? */
376 op->stats.sp = 0; 382 op->stats.sp = 0;
377 return; 383 return;
378 } 384 }
385
379 if (--op->stats.hp <= 0) 386 if (--op->stats.hp <= 0)
380 { /* keep gate down */ 387 { /* keep gate down */
381 move_gate (op); 388 move_gate (op);
389
382 if (op->value != v) 390 if (op->value != v)
383 op->set_speed (0); 391 op->set_speed (0);
384 } 392 }
385} 393}
386 394
398 int last = op->value; 406 int last = op->value;
399 int detected; 407 int detected;
400 408
401 detected = 0; 409 detected = 0;
402 410
403 for (tmp = GET_MAP_OB (op->map, op->x, op->y); tmp != NULL && !detected; tmp = tmp->above) 411 for (tmp = op->ms ().bot; tmp && !detected; tmp = tmp->above)
404 { 412 {
405 object *tmp2; 413 object *tmp2;
406 414
407 if (op->stats.hp) 415 if (op->stats.hp)
408 { 416 {
428 if (detected && last == 0) 436 if (detected && last == 0)
429 { 437 {
430 op->value = 1; 438 op->value = 1;
431 push_button (op); 439 push_button (op);
432 } 440 }
441
433 if (!detected && last == 1) 442 if (!detected && last == 1)
434 { 443 {
435 op->value = 0; 444 op->value = 0;
436 push_button (op); 445 push_button (op);
437 } 446 }
441 if (detected && last == 1) 450 if (detected && last == 1)
442 { 451 {
443 op->value = 0; 452 op->value = 0;
444 push_button (op); 453 push_button (op);
445 } 454 }
455
446 if (!detected && last == 0) 456 if (!detected && last == 0)
447 { 457 {
448 op->value = 1; 458 op->value = 1;
449 push_button (op); 459 push_button (op);
450 } 460 }
451 } 461 }
452} 462}
453
454 463
455void 464void
456animate_trigger (object *op) 465animate_trigger (object *op)
457{ 466{
458 if ((unsigned char) ++op->stats.wc >= NUM_ANIMATIONS (op)) 467 if ((unsigned char) ++op->stats.wc >= NUM_ANIMATIONS (op))
490 499
491 SET_ANIMATION (op, op->stats.wc); 500 SET_ANIMATION (op, op->stats.wc);
492 update_object (op, UP_OBJ_FACE); 501 update_object (op, UP_OBJ_FACE);
493 return; 502 return;
494 } 503 }
504
495 /* We're closing */ 505 /* We're closing */
496 op->move_on = 0; 506 op->move_on = 0;
497 507
498 op->stats.wc++; 508 op->stats.wc++;
499 if ((int) op->stats.wc >= NUM_ANIMATIONS (op)) 509 if ((int) op->stats.wc >= NUM_ANIMATIONS (op))
598 op->spellarg = NULL; 608 op->spellarg = NULL;
599 op->stats.sp = 0; 609 op->stats.sp = 0;
600 op->stats.hp = 0; 610 op->stats.hp = 0;
601 op->stats.grace = 0; 611 op->stats.grace = 0;
602 op->level = 0; 612 op->level = 0;
603 op->face = op->arch->clone.face; 613 op->face = op->arch->face;
604 op->owner = NULL; /* So that stopped arrows will be saved */ 614 op->owner = NULL; /* So that stopped arrows will be saved */
605 update_object (op, UP_OBJ_CHANGE); 615 update_object (op, UP_OBJ_CHANGE);
606 return op; 616 return op;
607} 617}
608 618
640/* Move an arrow along its course. op is the arrow or thrown object. 650/* Move an arrow along its course. op is the arrow or thrown object.
641 */ 651 */
642void 652void
643move_arrow (object *op) 653move_arrow (object *op)
644{ 654{
645 object *tmp;
646 sint16 new_x, new_y;
647 int was_reflected, mflags; 655 int was_reflected;
648 maptile *m;
649 656
650 if (op->map == NULL) 657 if (!op->map)
651 { 658 {
652 LOG (llevError, "BUG: Arrow had no map.\n"); 659 LOG (llevError, "BUG: Arrow had no map.\n");
653 op->destroy (); 660 op->destroy ();
654 return; 661 return;
655 } 662 }
685 stop_arrow (op); 692 stop_arrow (op);
686 return; 693 return;
687 } 694 }
688 695
689 /* Calculate target map square */ 696 /* Calculate target map square */
690 new_x = op->x + DIRX (op);
691 new_y = op->y + DIRY (op);
692 was_reflected = 0; 697 was_reflected = 0;
693 698
694 m = op->map; 699 mapxy pos (op); pos.move (op->direction);
695 mflags = get_map_flags (m, &m, new_x, new_y, &new_x, &new_y);
696 700
697 if (mflags & P_OUT_OF_MAP) 701 if (!pos.normalise ())
698 { 702 {
699 stop_arrow (op); 703 stop_arrow (op);
700 return; 704 return;
701 } 705 }
702 706
703 /* only need to look for living creatures if this flag is set */ 707 /* only need to look for living creatures if this flag is set */
704 if (mflags & P_IS_ALIVE) 708 if (pos->flags () & P_IS_ALIVE)
705 { 709 {
706 for (tmp = GET_MAP_OB (m, new_x, new_y); tmp != NULL; tmp = tmp->above) 710 object *tmp;
711
712 for (tmp = pos->bot; tmp; tmp = tmp->above)
707 if (QUERY_FLAG (tmp, FLAG_ALIVE)) 713 if (QUERY_FLAG (tmp, FLAG_ALIVE))
708 break; 714 break;
709 715
710 /* Not really fair, but don't let monsters hit themselves with 716 /* Not really fair, but don't let monsters hit themselves with
711 * their own arrow - this can be because they fire it then 717 * their own arrow - this can be because they fire it then
734 return; 740 return;
735 } 741 }
736 } /* if this is not hitting its owner */ 742 } /* if this is not hitting its owner */
737 } /* if there is something alive on this space */ 743 } /* if there is something alive on this space */
738 744
739 if (OB_TYPE_MOVE_BLOCK (op, GET_MAP_MOVE_BLOCK (m, new_x, new_y))) 745 if (OB_TYPE_MOVE_BLOCK (op, pos->move_block))
740 { 746 {
741 int retry = 0; 747 int retry = 0;
742 748
743 /* if the object doesn't reflect, stop the arrow from moving 749 /* if the object doesn't reflect, stop the arrow from moving
744 * note that this code will now catch cases where a monster is 750 * note that this code will now catch cases where a monster is
757 if (op->direction & 1) 763 if (op->direction & 1)
758 { 764 {
759 op->direction = absdir (op->direction + 4); 765 op->direction = absdir (op->direction + 4);
760 retry = 1; 766 retry = 1;
761 } 767 }
768
762 /* There were two blocks with identical code - 769 /* There were two blocks with identical code -
763 * use this retry here to make this one block 770 * use this retry here to make this one block
764 * that did the same thing. 771 * that did the same thing.
765 */ 772 */
766 while (retry < 2) 773 while (retry < 2)
767 { 774 {
768 int left, right, mflags;
769 maptile *m1;
770 sint16 x1, y1;
771
772 retry++; 775 retry++;
773 776
774 /* Need to check for P_OUT_OF_MAP: if the arrow is tavelling 777 /* Need to check for P_OUT_OF_MAP: if the arrow is travelling
775 * over a corner in a tiled map, it is possible that 778 * over a corner in a tiled map, it is possible that
776 * op->direction is within an adjacent map but either 779 * op->direction is within an adjacent map but either
777 * op->direction-1 or op->direction+1 does not exist. 780 * op->direction-1 or op->direction+1 does not exist.
778 */ 781 */
779 mflags = get_map_flags (op->map, &m1, op->x + freearr_x[absdir (op->direction - 1)], 782 mapxy pos1 (pos); pos1.move (absdir (op->direction - 1));
780 op->y + freearr_y[absdir (op->direction - 1)], &x1, &y1); 783 bool left = pos1.normalise () && OB_TYPE_MOVE_BLOCK (op, pos1->move_block);
781 left = (mflags & P_OUT_OF_MAP) ? 0 : OB_TYPE_MOVE_BLOCK (op, (GET_MAP_MOVE_BLOCK (m1, x1, y1)));
782 784
783 mflags = get_map_flags (op->map, &m1, op->x + freearr_x[absdir (op->direction + 1)], 785 mapxy pos2 (pos); pos2.move (absdir (op->direction + 1));
784 op->y + freearr_y[absdir (op->direction + 1)], &x1, &y1); 786 bool right = pos2.normalise () && OB_TYPE_MOVE_BLOCK (op, pos2->move_block);
785 right = (mflags & P_OUT_OF_MAP) ? 0 : OB_TYPE_MOVE_BLOCK (op, (GET_MAP_MOVE_BLOCK (m1, x1, y1)));
786 787
787 if (left == right) 788 if (left == right)
788 op->direction = absdir (op->direction + 4); 789 op->direction = absdir (op->direction + 4);
789 else if (left) 790 else if (left)
790 op->direction = absdir (op->direction + 2); 791 op->direction = absdir (op->direction + 2);
791 else if (right) 792 else if (right)
792 op->direction = absdir (op->direction - 2); 793 op->direction = absdir (op->direction - 2);
793 794
794 mflags = get_map_flags (op->map, &m1, op->x + DIRX (op), op->y + DIRY (op), &x1, &y1);
795
796 /* If this space is not out of the map and not blocked, valid space - 795 /* If this space is not out of the map and not blocked, valid space -
797 * don't need to retry again. 796 * don't need to retry again.
798 */ 797 */
799 if (!(mflags & P_OUT_OF_MAP) && !OB_TYPE_MOVE_BLOCK (op, GET_MAP_MOVE_BLOCK (m1, x1, y1))) 798 mapxy pos3 (pos); pos3.move (op->direction);
799 if (pos3.normalise () && !OB_TYPE_MOVE_BLOCK (op, pos3->move_block))
800 break; 800 break;
801
802 } 801 }
802
803 /* Couldn't find a direction to move the arrow to - just 803 /* Couldn't find a direction to move the arrow to - just
804 * top it from moving. 804 * stop it from moving.
805 */ 805 */
806 if (retry == 2) 806 if (retry == 2)
807 { 807 {
808 stop_arrow (op); 808 stop_arrow (op);
809 return; 809 return;
810 } 810 }
811
811 /* update object image for new facing */ 812 /* update object image for new facing */
812 /* many thrown objects *don't* have more than one face */ 813 /* many thrown objects *don't* have more than one face */
813 if (GET_ANIM_ID (op)) 814 if (GET_ANIM_ID (op))
814 SET_ANIMATION (op, op->direction); 815 SET_ANIMATION (op, op->direction);
815 } /* object is reflected */ 816 } /* object is reflected */
816 } /* object ran into a wall */ 817 } /* object ran into a wall */
817 818
818 /* Move the arrow. */
819 op->remove ();
820 op->x = new_x;
821 op->y = new_y;
822
823 /* decrease the speed as it flies. 0.05 means a standard bow will shoot 819 /* decrease the speed as it flies. 0.05 means a standard bow will shoot
824 * about 17 squares. Tune as needed. 820 * about 17 squares. Tune as needed.
825 */ 821 */
826 op->speed -= 0.05; 822 op->speed -= 0.05;
827 insert_ob_in_map (op, m, op, 0);
828}
829 823
830/* This routine doesnt seem to work for "inanimate" objects that 824 /* Move the arrow. */
831 * are being carried, ie a held torch leaps from your hands!. 825 op->move_to (pos);
832 * Modified this routine to allow held objects. b.t. */ 826}
833 827
834void 828void
835change_object (object *op) 829change_object (object *op)
836{ /* Doesn`t handle linked objs yet */ 830{ /* Doesn`t handle linked objs yet */
837 int i, j; 831 int i, j;
838 832
839 if (op->other_arch == NULL) 833 if (!op->other_arch)
840 { 834 {
841 LOG (llevError, "Change object (%s) without other_arch error.\n", &op->name); 835 LOG (llevError, "Change object (%s) without other_arch error.\n", op->debug_desc ());
842 return; 836 return;
843 } 837 }
844 838
845 /* In non-living items only change when food value is 0 */ 839 /* In non-living items only change when food value is 0 */
846 if (!QUERY_FLAG (op, FLAG_ALIVE)) 840 if (!QUERY_FLAG (op, FLAG_ALIVE))
847 { 841 {
848 if (op->stats.food-- > 0) 842 if (op->stats.food-- > 0)
849 return; 843 return;
850 else 844
851 op->stats.food = 1; /* so 1 other_arch is made */ 845 op->stats.food = 1; /* so 1 other_arch is made */
852 } 846 }
853 847
854 object *pl = op->in_player ();
855 object *env = op->env; 848 object *env = op->env;
856 849
857 op->remove (); 850 op->remove ();
858 for (i = 0; i < NROFNEWOBJS (op); i++) 851 for (i = 0; i < op->stats.food; i++)
859 { 852 {
860 object *tmp = arch_to_object (op->other_arch); 853 object *tmp = arch_to_object (op->other_arch);
861 854
862 if (op->type == LAMP) 855 if (op->type == LAMP)
863 tmp->stats.food = op->stats.food - 1; 856 tmp->stats.food = op->stats.food - 1;
864 857
865 tmp->stats.hp = op->stats.hp; /* The only variable it keeps. */ 858 tmp->stats.hp = op->stats.hp; /* The only variable it keeps. */
866 if (env) 859 if (env)
867 { 860 {
868 tmp->x = env->x, tmp->y = env->y;
869 tmp = insert_ob_in_ob (tmp, env); 861 tmp = env->insert (tmp);
870 862
871 /* If this object is the players inventory, we need to tell the 863 /* If this object is the players inventory, we need to tell the
872 * client of the change. Insert_ob_in_map takes care of the 864 * client of the change. Insert_ob_in_map takes care of the
873 * updating the client, so we don't need to do that below. 865 * updating the client, so we don't need to do that below.
874 */ 866 */
875 if (pl) 867 if (object *pl = op->in_player ())
876 { 868 {
877 esrv_del_item (pl->contr, op->count); 869 esrv_del_item (pl->contr, op->count);
878 esrv_send_item (pl, tmp); 870 esrv_send_item (pl, tmp);
879 } 871 }
880 } 872 }
881 else 873 else
882 { 874 {
883 j = find_first_free_spot (tmp, op->map, op->x, op->y); 875 j = find_first_free_spot (tmp, op->map, op->x, op->y);
884 if (j == -1) /* No free spot */ 876 if (j < 0) /* No free spot */
885 tmp->destroy (); 877 tmp->destroy ();
886 else 878 else
887 { 879 {
888 tmp->x = op->x + freearr_x[j], tmp->y = op->y + freearr_y[j]; 880 mapxy pos (op); pos.move (j);
889 insert_ob_in_map (tmp, op->map, op, 0); 881
882 if (pos.normalise ())
883 pos.insert (tmp, op);
890 } 884 }
891 } 885 }
892 } 886 }
893 887
894 op->destroy (); 888 op->destroy ();
910 move_teleporter (op->more); 904 move_teleporter (op->more);
911 905
912 if (op->head) 906 if (op->head)
913 head = op->head; 907 head = op->head;
914 908
915 for (tmp = op->above; tmp != NULL; tmp = tmp->above) 909 for (tmp = op->above; tmp; tmp = tmp->above)
916 if (!QUERY_FLAG (tmp, FLAG_IS_FLOOR)) 910 if (!QUERY_FLAG (tmp, FLAG_IS_FLOOR))
917 break; 911 break;
918 912
919 /* If nothing above us to move, nothing to do */ 913 /* If nothing above us to move, nothing to do */
920 if (!tmp || QUERY_FLAG (tmp, FLAG_WIZPASS)) 914 if (!tmp || QUERY_FLAG (tmp, FLAG_WIZPASS))
953 if (INVOKE_OBJECT (TRIGGER, op, ARG_OBJECT (tmp))) 947 if (INVOKE_OBJECT (TRIGGER, op, ARG_OBJECT (tmp)))
954 return; 948 return;
955 teleport (head, TELEPORTER, tmp); 949 teleport (head, TELEPORTER, tmp);
956 } 950 }
957} 951}
958
959 952
960/* This object will teleport someone to a different map 953/* This object will teleport someone to a different map
961 and will also apply changes to the player from its inventory. 954 and will also apply changes to the player from its inventory.
962 This was invented for giving classes, but there's no reason it 955 This was invented for giving classes, but there's no reason it
963 can't be generalized. 956 can't be generalized.
1016 return; /* dm has created a firewall in his inventory */ 1009 return; /* dm has created a firewall in his inventory */
1017 1010
1018 spell = op->inv; 1011 spell = op->inv;
1019 1012
1020 if (!spell || spell->type != SPELL) 1013 if (!spell || spell->type != SPELL)
1021 spell = &op->other_arch->clone; 1014 spell = op->other_arch;
1022 1015
1023 if (!spell) 1016 if (!spell)
1024 { 1017 {
1025 LOG (llevError, "move_firewall: no spell specified (%s, %s, %d, %d)\n", &op->name, &op->map->name, op->x, op->y); 1018 LOG (llevError, "move_firewall: no spell specified (%s, %s, %d, %d)\n", &op->name, &op->map->name, op->x, op->y);
1026 return; 1019 return;
1094 * is cleared, otherwise the player will get stuck in 1087 * is cleared, otherwise the player will get stuck in
1095 * place. This can happen if the player used a spell to 1088 * place. This can happen if the player used a spell to
1096 * get to this space. 1089 * get to this space.
1097 */ 1090 */
1098 victim->contr->fire_on = 0; 1091 victim->contr->fire_on = 0;
1099 victim->speed_left = 0.f; 1092 victim->speed_left = 1.f;
1100 move_player (victim, dir); 1093 move_player (victim, dir);
1101 } 1094 }
1102 else 1095 else
1103 return; 1096 return;
1104 } 1097 }
1137 if (op->above == NULL) 1130 if (op->above == NULL)
1138 return; 1131 return;
1139 1132
1140 for (tmp = op->above; tmp; tmp = tmp->above) 1133 for (tmp = op->above; tmp; tmp = tmp->above)
1141 { 1134 {
1142 if (op->other_arch->name == tmp->arch->name) 1135 if (op->other_arch->archname == tmp->arch->archname)
1143 { 1136 {
1144 if (op->level <= 0) 1137 if (op->level <= 0)
1145 tmp->destroy (); 1138 tmp->destroy ();
1146 else 1139 else
1147 { 1140 {
1169 * has to make sure that there is in fact space for the object. 1162 * has to make sure that there is in fact space for the object.
1170 * It should really do this for small objects also, but there is 1163 * It should really do this for small objects also, but there is
1171 * more concern with large objects, most notably a part being placed 1164 * more concern with large objects, most notably a part being placed
1172 * outside of the map which would cause the server to crash 1165 * outside of the map which would cause the server to crash
1173*/ 1166*/
1174
1175void 1167void
1176move_creator (object *creator) 1168move_creator (object *creator)
1177{ 1169{
1178 object *new_ob; 1170 object *new_ob;
1179 1171
1214 new_ob = object_create_arch (creator->other_arch); 1206 new_ob = object_create_arch (creator->other_arch);
1215 fix_generated_item (new_ob, creator, 0, 0, GT_MINIMAL); 1207 fix_generated_item (new_ob, creator, 0, 0, GT_MINIMAL);
1216 } 1208 }
1217 1209
1218 /* Make sure this multipart object fits */ 1210 /* Make sure this multipart object fits */
1219 if (new_ob->arch->more && ob_blocked (new_ob, creator->map, creator->x, creator->y)) 1211 if (new_ob->arch->more && new_ob->blocked (creator->map, creator->x, creator->y))
1220 { 1212 {
1221 new_ob->destroy (); 1213 new_ob->destroy ();
1222 return; 1214 return;
1223 } 1215 }
1216
1217 // for now lets try to identify everything generated here, it mostly
1218 // happens automated, so this will at least fix many identify-experience holes
1219 SET_FLAG (new_ob, FLAG_IDENTIFIED);
1224 1220
1225 insert_ob_in_map_at (new_ob, creator->map, creator, 0, creator->x, creator->y); 1221 insert_ob_in_map_at (new_ob, creator->map, creator, 0, creator->x, creator->y);
1226 if (QUERY_FLAG (new_ob, FLAG_FREED)) 1222 if (QUERY_FLAG (new_ob, FLAG_FREED))
1227 return; 1223 return;
1228 1224
1243void 1239void
1244move_marker (object *op) 1240move_marker (object *op)
1245{ 1241{
1246 if (object *tmp = op->ms ().player ()) 1242 if (object *tmp = op->ms ().player ())
1247 { 1243 {
1248 object *tmp2;
1249
1250 /* remove an old force with a slaying field == op->name */ 1244 /* remove an old force with a slaying field == op->name */
1251 for (tmp2 = tmp->inv; tmp2; tmp2 = tmp2->below) 1245 if (object *force = tmp->force_find (op->name))
1252 if (tmp2->type == FORCE && tmp2->slaying && tmp2->slaying == op->name) 1246 force->destroy ();
1247
1248 if (!tmp->force_find (op->slaying))
1253 { 1249 {
1254 tmp2->destroy (); 1250 tmp->force_add (op->slaying, op->stats.food);
1255 break;
1256 }
1257 1251
1258 /* cycle through his inventory to look for the MARK we want to
1259 * place
1260 */
1261 for (tmp2 = tmp->inv; tmp2; tmp2 = tmp2->below)
1262 if (tmp2->type == FORCE && tmp2->slaying && tmp2->slaying == op->slaying)
1263 break;
1264
1265 /* if we didn't find our own MARK */
1266 if (!tmp2)
1267 {
1268 object *force = get_archetype (FORCE_NAME);
1269
1270 if (op->stats.food)
1271 {
1272 force->set_speed (0.01);
1273 force->speed_left = -op->stats.food;
1274 }
1275 else
1276 force->set_speed (0);
1277
1278 /* put in the lock code */
1279 force->slaying = op->slaying;
1280
1281 if (op->lore)
1282 force->lore = op->lore;
1283
1284 insert_ob_in_ob (force, tmp);
1285 if (op->msg) 1252 if (op->msg)
1286 new_draw_info (NDI_UNIQUE | NDI_NAVY, 0, tmp, op->msg); 1253 new_draw_info (NDI_UNIQUE | NDI_NAVY, 0, tmp, op->msg);
1287 1254
1288 if (op->stats.hp > 0) 1255 if (op->stats.hp > 0)
1289 { 1256 {
1290 op->stats.hp--; 1257 op->stats.hp--;
1258
1291 if (op->stats.hp == 0) 1259 if (op->stats.hp == 0)
1292 { 1260 {
1293 /* marker expires--granted mark number limit */ 1261 /* marker expires--granted mark number limit */
1294 op->destroy (); 1262 op->destroy ();
1295 return; 1263 return;
1300} 1268}
1301 1269
1302void 1270void
1303process_object (object *op) 1271process_object (object *op)
1304{ 1272{
1305 if (QUERY_FLAG (op, FLAG_IS_A_TEMPLATE)) 1273 if (expect_false (QUERY_FLAG (op, FLAG_IS_A_TEMPLATE)))
1306 return; 1274 return;
1307 1275
1308 if (INVOKE_OBJECT (TICK, op)) 1276 if (expect_false (INVOKE_OBJECT (TICK, op)))
1309 return; 1277 return;
1310 1278
1311 if (QUERY_FLAG (op, FLAG_MONSTER)) 1279 if (QUERY_FLAG (op, FLAG_MONSTER))
1312 if (move_monster (op) || QUERY_FLAG (op, FLAG_FREED)) 1280 if (move_monster (op) || QUERY_FLAG (op, FLAG_FREED))
1313 return; 1281 return;
1318 1286
1319 if (QUERY_FLAG (op, FLAG_SEE_ANYWHERE)) 1287 if (QUERY_FLAG (op, FLAG_SEE_ANYWHERE))
1320 make_sure_seen (op); 1288 make_sure_seen (op);
1321 } 1289 }
1322 1290
1291 if (expect_false (
1323 if (op->flag [FLAG_GENERATOR] 1292 op->flag [FLAG_GENERATOR]
1324 || op->flag [FLAG_CHANGING] 1293 || op->flag [FLAG_CHANGING]
1325 || op->flag [FLAG_IS_USED_UP]) 1294 || op->flag [FLAG_IS_USED_UP]
1295 ))
1326 { 1296 {
1327 if (QUERY_FLAG (op, FLAG_CHANGING) && !op->state) 1297 if (QUERY_FLAG (op, FLAG_CHANGING) && !op->state)
1328 { 1298 {
1329 change_object (op); 1299 change_object (op);
1330 return; 1300 return;
1338 if (QUERY_FLAG (op, FLAG_APPLIED)) 1308 if (QUERY_FLAG (op, FLAG_APPLIED))
1339 remove_force (op); 1309 remove_force (op);
1340 else 1310 else
1341 { 1311 {
1342 /* If necessary, delete the item from the players inventory */ 1312 /* If necessary, delete the item from the players inventory */
1343 object *pl = op->in_player (); 1313 if (object *pl = op->in_player ())
1344
1345 if (pl)
1346 esrv_del_item (pl->contr, op->count); 1314 esrv_del_item (pl->contr, op->count);
1347 1315
1348 op->remove (); 1316 op->remove ();
1349 1317
1350 if (QUERY_FLAG (op, FLAG_SEE_ANYWHERE)) 1318 if (QUERY_FLAG (op, FLAG_SEE_ANYWHERE))

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines