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.13 by root, Sat Sep 16 22:24:13 2006 UTC vs.
Revision 1.27 by root, Tue Dec 26 09:52:40 2006 UTC

44 object *tmp; 44 object *tmp;
45 45
46 for (i = 1; i < 9; i += 2) 46 for (i = 1; i < 9; i += 2)
47 if ((tmp = present (DOOR, op->map, op->x + freearr_x[i], op->y + freearr_y[i])) != NULL) 47 if ((tmp = present (DOOR, op->map, op->x + freearr_x[i], op->y + freearr_y[i])) != NULL)
48 { 48 {
49 tmp->speed = 0.1; 49 tmp->set_speed (0.1);
50 update_ob_speed (tmp);
51 tmp->speed_left = -0.2; 50 tmp->speed_left = -0.2;
52 } 51 }
53 52
54 if (op->other_arch) 53 if (op->other_arch)
55 { 54 {
58 tmp->y = op->y; 57 tmp->y = op->y;
59 tmp->map = op->map; 58 tmp->map = op->map;
60 tmp->level = op->level; 59 tmp->level = op->level;
61 insert_ob_in_map (tmp, op->map, op, 0); 60 insert_ob_in_map (tmp, op->map, op, 0);
62 } 61 }
63 remove_ob (op); 62
64 free_object (op); 63 op->destroy ();
65} 64}
66 65
67void 66void
68remove_door2 (object *op) 67remove_door2 (object *op)
69{ 68{
73 for (i = 1; i < 9; i += 2) 72 for (i = 1; i < 9; i += 2)
74 { 73 {
75 tmp = present (LOCKED_DOOR, op->map, op->x + freearr_x[i], op->y + freearr_y[i]); 74 tmp = present (LOCKED_DOOR, op->map, op->x + freearr_x[i], op->y + freearr_y[i]);
76 if (tmp && tmp->slaying == op->slaying) 75 if (tmp && tmp->slaying == op->slaying)
77 { /* same key both doors */ 76 { /* same key both doors */
78 tmp->speed = 0.1; 77 tmp->set_speed (0.1);
79 update_ob_speed (tmp);
80 tmp->speed_left = -0.2; 78 tmp->speed_left = -0.2;
81 } 79 }
82 } 80 }
81
83 if (op->other_arch) 82 if (op->other_arch)
84 { 83 {
85 tmp = arch_to_object (op->other_arch); 84 tmp = arch_to_object (op->other_arch);
86 tmp->x = op->x; 85 tmp->x = op->x;
87 tmp->y = op->y; 86 tmp->y = op->y;
88 tmp->map = op->map; 87 tmp->map = op->map;
89 tmp->level = op->level; 88 tmp->level = op->level;
90 insert_ob_in_map (tmp, op->map, op, 0); 89 insert_ob_in_map (tmp, op->map, op, 0);
91 } 90 }
92 remove_ob (op); 91
93 free_object (op); 92 op->destroy ();
94} 93}
95 94
96/* Will generate a monster according to content 95/* Will generate a monster according to content
97 * of generator. 96 * of generator.
98 */ 97 */
133 if (rndm (0, 9)) 132 if (rndm (0, 9))
134 generate_artifact (head, gen->map->difficulty); 133 generate_artifact (head, gen->map->difficulty);
135 insert_ob_in_map_at (head, gen->map, gen, 0, gen->x + freearr_x[i], gen->y + freearr_y[i]); 134 insert_ob_in_map_at (head, gen->map, gen, 0, gen->x + freearr_x[i], gen->y + freearr_y[i]);
136 if (QUERY_FLAG (head, FLAG_FREED)) 135 if (QUERY_FLAG (head, FLAG_FREED))
137 return; 136 return;
138 if (HAS_RANDOM_ITEMS (head)) 137 if (head->has_random_items ())
139 create_treasure (head->randomitems, head, GT_APPLY, gen->map->difficulty, 0); 138 create_treasure (head->randomitems, head, GT_APPLY, gen->map->difficulty, 0);
140} 139}
141 140
142void 141void
143generate_monster_arch (object *gen) 142generate_monster_arch (object *gen)
144{ 143{
145 int i; 144 int i;
146 object *op, *head = NULL, *prev = NULL; 145 object *op, *head = NULL, *prev = NULL;
147 archetype *at = gen->other_arch; 146 archetype *at = gen->other_arch;
148 147
149 if (gen->other_arch == NULL) 148 if (!gen->other_arch)
150 {
151 //LOG(llevError,"Generator without other_arch: %s\n",gen->name);
152 return; 149 return;
153 } 150
154 /* Code below assumes the generator is on a map, as it tries 151 /* Code below assumes the generator is on a map, as it tries
155 * to place the monster on the map. So if the generator 152 * to place the monster on the map. So if the generator
156 * isn't on a map, complain and exit. 153 * isn't on a map, complain and exit.
157 */ 154 */
158 if (gen->map == NULL) 155 if (!gen->map)
159 {
160 //LOG(llevError,"Generator (%s) not on a map?\n", gen->name);
161 return; 156 return;
162 } 157
163 i = find_free_spot (&at->clone, gen->map, gen->x, gen->y, 1, 9); 158 i = find_free_spot (&at->clone, gen->map, gen->x, gen->y, 1, 9);
164 if (i == -1) 159 if (i == -1)
165 return; 160 return;
161
166 while (at != NULL) 162 while (at)
167 { 163 {
168 op = arch_to_object (at); 164 op = arch_to_object (at);
169 op->x = gen->x + freearr_x[i] + at->clone.x; 165 op->x = gen->x + freearr_x[i] + at->clone.x;
170 op->y = gen->y + freearr_y[i] + at->clone.y; 166 op->y = gen->y + freearr_y[i] + at->clone.y;
171 167
172 if (head != NULL) 168 if (head)
173 op->head = head, prev->more = op; 169 op->head = head, prev->more = op;
174 170
175 if (rndm (0, 9)) 171 if (rndm (0, 9))
176 generate_artifact (op, gen->map->difficulty); 172 generate_artifact (op, gen->map->difficulty);
173
177 insert_ob_in_map (op, gen->map, gen, 0); 174 insert_ob_in_map (op, gen->map, gen, 0);
178 if (QUERY_FLAG (op, FLAG_FREED)) 175 if (QUERY_FLAG (op, FLAG_FREED))
179 return; 176 return;
180 if (HAS_RANDOM_ITEMS (op)) 177
178 if (op->has_random_items ())
181 create_treasure (op->randomitems, op, GT_APPLY, gen->map->difficulty, 0); 179 create_treasure (op->randomitems, op, GT_APPLY, gen->map->difficulty, 0);
180
182 if (head == NULL) 181 if (head == NULL)
183 head = op; 182 head = op;
183
184 prev = op; 184 prev = op;
185 at = at->more; 185 at = at->more;
186 } 186 }
187} 187}
188 188
190generate_monster (object *gen) 190generate_monster (object *gen)
191{ 191{
192 192
193 if (GENERATE_SPEED (gen) && rndm (0, GENERATE_SPEED (gen) - 1)) 193 if (GENERATE_SPEED (gen) && rndm (0, GENERATE_SPEED (gen) - 1))
194 return; 194 return;
195
195 if (QUERY_FLAG (gen, FLAG_CONTENT_ON_GEN)) 196 if (QUERY_FLAG (gen, FLAG_CONTENT_ON_GEN))
196 generate_monster_inv (gen); 197 generate_monster_inv (gen);
197 else 198 else
198 generate_monster_arch (gen); 199 generate_monster_arch (gen);
199 200
203remove_force (object *op) 204remove_force (object *op)
204{ 205{
205 if (--op->duration > 0) 206 if (--op->duration > 0)
206 return; 207 return;
207 208
209 if (op->env)
208 switch (op->subtype) 210 switch (op->subtype)
209 { 211 {
210 case FORCE_CONFUSION: 212 case FORCE_CONFUSION:
211 if (op->env != NULL)
212 {
213 CLEAR_FLAG (op->env, FLAG_CONFUSED); 213 CLEAR_FLAG (op->env, FLAG_CONFUSED);
214 new_draw_info (NDI_UNIQUE, 0, op->env, "You regain your senses.\n"); 214 new_draw_info (NDI_UNIQUE, 0, op->env, "You regain your senses.\n");
215 }
216 215
217 default: 216 default:
218 if (op->env != NULL)
219 {
220 CLEAR_FLAG (op, FLAG_APPLIED); 217 CLEAR_FLAG (op, FLAG_APPLIED);
221 change_abil (op->env, op); 218 change_abil (op->env, op);
222 fix_player (op->env); 219 op->env->update_stats ();
223 }
224 } 220 }
225 remove_ob (op); 221
226 free_object (op); 222 op->destroy ();
227} 223}
228 224
229void 225void
230remove_blindness (object *op) 226remove_blindness (object *op)
231{ 227{
232 if (--op->stats.food > 0) 228 if (--op->stats.food > 0)
233 return; 229 return;
230
234 CLEAR_FLAG (op, FLAG_APPLIED); 231 CLEAR_FLAG (op, FLAG_APPLIED);
232
235 if (op->env != NULL) 233 if (op->env)
236 { 234 {
237 change_abil (op->env, op); 235 change_abil (op->env, op);
238 fix_player (op->env); 236 op->env->update_stats ();
239 } 237 }
240 remove_ob (op); 238
241 free_object (op); 239 op->destroy ();
242} 240}
243 241
244void 242void
245poison_more (object *op) 243poison_more (object *op)
246{ 244{
247 if (op->env == NULL || !QUERY_FLAG (op->env, FLAG_ALIVE) || op->env->stats.hp < 0) 245 if (op->env == NULL || !QUERY_FLAG (op->env, FLAG_ALIVE) || op->env->stats.hp < 0)
248 { 246 {
249 remove_ob (op); 247 op->destroy ();
250 free_object (op);
251 return; 248 return;
252 } 249 }
250
253 if (op->stats.food == 1) 251 if (op->stats.food == 1)
254 { 252 {
255 /* need to remove the object before fix_player is called, else fix_player 253 /* need to remove the object before fix_player is called, else fix_player
256 * will not do anything. 254 * will not do anything.
257 */ 255 */
258 if (op->env->type == PLAYER) 256 if (op->env->type == PLAYER)
259 { 257 {
260 CLEAR_FLAG (op, FLAG_APPLIED); 258 CLEAR_FLAG (op, FLAG_APPLIED);
261 fix_player (op->env); 259 op->env->update_stats ();
262 new_draw_info (NDI_UNIQUE, 0, op->env, "You feel much better now."); 260 new_draw_info (NDI_UNIQUE, 0, op->env, "You feel much better now.");
263 } 261 }
264 remove_ob (op); 262
265 free_object (op); 263 op->destroy ();
266 return; 264 return;
267 } 265 }
266
268 if (op->env->type == PLAYER) 267 if (op->env->type == PLAYER)
269 { 268 {
270 op->env->stats.food--; 269 op->env->stats.food--;
271 new_draw_info (NDI_UNIQUE, 0, op->env, "You feel very sick..."); 270 new_draw_info (NDI_UNIQUE, 0, op->env, "You feel very sick...");
272 } 271 }
280 object *tmp; 279 object *tmp;
281 280
282 if (op->stats.wc < 0 || (int) op->stats.wc >= NUM_ANIMATIONS (op)) 281 if (op->stats.wc < 0 || (int) op->stats.wc >= NUM_ANIMATIONS (op))
283 { 282 {
284 LOG (llevError, "Gate error: animation was %d, max=%d\n", op->stats.wc, NUM_ANIMATIONS (op)); 283 LOG (llevError, "Gate error: animation was %d, max=%d\n", op->stats.wc, NUM_ANIMATIONS (op));
285 dump_object (op);
286 LOG (llevError, "%s\n", errmsg);
287 op->stats.wc = 0; 284 op->stats.wc = 0;
288 } 285 }
289 286
290 /* We're going down */ 287 /* We're going down */
291 if (op->value) 288 if (op->value)
294 { /* Reached bottom, let's stop */ 291 { /* Reached bottom, let's stop */
295 op->stats.wc = 0; 292 op->stats.wc = 0;
296 if (op->arch->clone.speed) 293 if (op->arch->clone.speed)
297 op->value = 0; 294 op->value = 0;
298 else 295 else
299 {
300 op->speed = 0; 296 op->set_speed (0);
301 update_ob_speed (op);
302 } 297 }
303 } 298
304 if ((int) op->stats.wc < (NUM_ANIMATIONS (op) / 2 + 1)) 299 if ((int) op->stats.wc < (NUM_ANIMATIONS (op) / 2 + 1))
305 { 300 {
306 op->move_block = 0; 301 op->move_block = 0;
307 CLEAR_FLAG (op, FLAG_BLOCKSVIEW); 302 CLEAR_FLAG (op, FLAG_BLOCKSVIEW);
308 update_all_los (op->map, op->x, op->y); 303 update_all_los (op->map, op->x, op->y);
309 } 304 }
305
310 SET_ANIMATION (op, op->stats.wc); 306 SET_ANIMATION (op, op->stats.wc);
311 update_object (op, UP_OBJ_CHANGE); 307 update_object (op, UP_OBJ_CHANGE);
312 return; 308 return;
313 } 309 }
314 310
331 if (tmp == NULL) 327 if (tmp == NULL)
332 { 328 {
333 if (op->arch->clone.speed) 329 if (op->arch->clone.speed)
334 op->value = 1; 330 op->value = 1;
335 else 331 else
336 {
337 op->speed = 0; 332 op->set_speed (0);
338 update_ob_speed (op); /* Reached top, let's stop */ 333
339 }
340 return; 334 return;
341 } 335 }
342 } 336 }
343 337
344 if (op->stats.food) 338 if (op->stats.food)
384 int i = find_free_spot (tmp, op->map, op->x, op->y, 1, 9); 378 int i = find_free_spot (tmp, op->map, op->x, op->y, 1, 9);
385 379
386 /* If there is a free spot, move the object someplace */ 380 /* If there is a free spot, move the object someplace */
387 if (i != -1) 381 if (i != -1)
388 { 382 {
389 remove_ob (tmp); 383 tmp->remove ();
390 tmp->x += freearr_x[i], tmp->y += freearr_y[i]; 384 tmp->x += freearr_x[i], tmp->y += freearr_y[i];
391 insert_ob_in_map (tmp, op->map, op, 0); 385 insert_ob_in_map (tmp, op->map, op, 0);
392 } 386 }
393 } 387 }
394 } 388 }
435 } 429 }
436 if (--op->stats.hp <= 0) 430 if (--op->stats.hp <= 0)
437 { /* keep gate down */ 431 { /* keep gate down */
438 move_gate (op); 432 move_gate (op);
439 if (op->value != v) 433 if (op->value != v)
440 { /* ready ? */
441 op->speed = 0; 434 op->set_speed (0);
442 update_ob_speed (op);
443 }
444 } 435 }
445} 436}
446 437
447/* slaying: name of the thing the detector is to look for 438/* slaying: name of the thing the detector is to look for
448 * speed: frequency of 'glances' 439 * speed: frequency of 'glances'
458 int last = op->value; 449 int last = op->value;
459 int detected; 450 int detected;
460 451
461 detected = 0; 452 detected = 0;
462 453
463 for (tmp = get_map_ob (op->map, op->x, op->y); tmp != NULL && !detected; tmp = tmp->above) 454 for (tmp = GET_MAP_OB (op->map, op->x, op->y); tmp != NULL && !detected; tmp = tmp->above)
464 { 455 {
465 object *tmp2; 456 object *tmp2;
466 457
467 if (op->stats.hp) 458 if (op->stats.hp)
468 { 459 {
535 if (op->value) 526 if (op->value)
536 { /* We're opening */ 527 { /* We're opening */
537 if (--op->stats.wc <= 0) 528 if (--op->stats.wc <= 0)
538 { /* Opened, let's stop */ 529 { /* Opened, let's stop */
539 op->stats.wc = 0; 530 op->stats.wc = 0;
540 op->speed = 0; 531 op->set_speed (0);
541 update_ob_speed (op);
542 532
543 /* Hard coding this makes sense for holes I suppose */ 533 /* Hard coding this makes sense for holes I suppose */
544 op->move_on = MOVE_WALK; 534 op->move_on = MOVE_WALK;
545 for (tmp = op->above; tmp != NULL; tmp = next) 535 for (tmp = op->above; tmp != NULL; tmp = next)
546 { 536 {
547 next = tmp->above; 537 next = tmp->above;
548 move_apply (op, tmp, tmp); 538 move_apply (op, tmp, tmp);
549 } 539 }
550 } 540 }
541
551 SET_ANIMATION (op, op->stats.wc); 542 SET_ANIMATION (op, op->stats.wc);
552 update_object (op, UP_OBJ_FACE); 543 update_object (op, UP_OBJ_FACE);
553 return; 544 return;
554 } 545 }
555 /* We're closing */ 546 /* We're closing */
556 op->move_on = 0; 547 op->move_on = 0;
557 548
558 op->stats.wc++; 549 op->stats.wc++;
559 if ((int) op->stats.wc >= NUM_ANIMATIONS (op)) 550 if ((int) op->stats.wc >= NUM_ANIMATIONS (op))
560 op->stats.wc = NUM_ANIMATIONS (op) - 1; 551 op->stats.wc = NUM_ANIMATIONS (op) - 1;
552
561 SET_ANIMATION (op, op->stats.wc); 553 SET_ANIMATION (op, op->stats.wc);
562 update_object (op, UP_OBJ_FACE); 554 update_object (op, UP_OBJ_FACE);
563 if ((unsigned char) op->stats.wc == (NUM_ANIMATIONS (op) - 1)) 555 if ((unsigned char) op->stats.wc == (NUM_ANIMATIONS (op) - 1))
564 {
565 op->speed = 0;
566 update_ob_speed (op); /* closed, let's stop */ 556 op->set_speed (0); /* closed, let's stop */
567 return;
568 }
569} 557}
570 558
571 559
572/* stop_item() returns a pointer to the stopped object. The stopped object 560/* stop_item() returns a pointer to the stopped object. The stopped object
573 * may or may not have been removed from maps or inventories. It will not 561 * may or may not have been removed from maps or inventories. It will not
593 { 581 {
594 object *payload = op->inv; 582 object *payload = op->inv;
595 583
596 if (payload == NULL) 584 if (payload == NULL)
597 return NULL; 585 return NULL;
598 remove_ob (payload); 586 payload->remove ();
599 remove_ob (op); 587 op->destroy ();
600 free_object (op);
601 return payload; 588 return payload;
602 } 589 }
603 590
604 case ARROW: 591 case ARROW:
605 if (op->speed >= MIN_ACTIVE_SPEED) 592 if (op->speed >= MIN_ACTIVE_SPEED)
632fix_stopped_arrow (object *op) 619fix_stopped_arrow (object *op)
633{ 620{
634 if (rndm (0, 99) < op->stats.food) 621 if (rndm (0, 99) < op->stats.food)
635 { 622 {
636 /* Small chance of breaking */ 623 /* Small chance of breaking */
637 remove_ob (op); 624 op->destroy ();
638 free_object (op);
639 return NULL; 625 return NULL;
640 } 626 }
641 627
628 op->set_speed (0);
642 op->direction = 0; 629 op->direction = 0;
643 op->move_on = 0; 630 op->move_on = 0;
644 op->move_type = 0; 631 op->move_type = 0;
645 op->speed = 0;
646 update_ob_speed (op);
647 op->stats.wc = op->stats.sp; 632 op->stats.wc = op->stats.sp;
648 op->stats.dam = op->stats.hp; 633 op->stats.dam = op->stats.hp;
649 op->attacktype = op->stats.grace; 634 op->attacktype = op->stats.grace;
650 op->slaying = 0; 635 op->slaying = 0;
651 op->skill = 0; 636 op->skill = 0;
657 op->spellarg = NULL; 642 op->spellarg = NULL;
658 } 643 }
659 else 644 else
660 op->slaying = NULL; 645 op->slaying = NULL;
661 646
662 /* Reset these to zero, so that CAN_MERGE will work properly */ 647 /* Reset these to zero, so that object::can_merge will work properly */
663 op->spellarg = NULL; 648 op->spellarg = NULL;
664 op->stats.sp = 0; 649 op->stats.sp = 0;
665 op->stats.hp = 0; 650 op->stats.hp = 0;
666 op->stats.grace = 0; 651 op->stats.grace = 0;
667 op->level = 0; 652 op->level = 0;
676 * here too. -b.t. 661 * here too. -b.t.
677 * 662 *
678 * Returns a pointer to the stopped object (which will have been removed 663 * Returns a pointer to the stopped object (which will have been removed
679 * from maps or inventories), or NULL if was destroyed. 664 * from maps or inventories), or NULL if was destroyed.
680 */ 665 */
681
682static void 666static void
683stop_arrow (object *op) 667stop_arrow (object *op)
684{ 668{
685 if (INVOKE_OBJECT (STOP, op)) 669 if (INVOKE_OBJECT (STOP, op))
686 return; 670 return;
687 671
688 if (op->inv) 672 if (op->inv)
689 { 673 {
690 object *payload = op->inv; 674 object *payload = op->inv;
691 675
692 remove_ob (payload); 676 payload->remove ();
693 clear_owner (payload); 677 payload->owner = 0;
694 insert_ob_in_map (payload, op->map, payload, 0); 678 insert_ob_in_map (payload, op->map, payload, 0);
695 remove_ob (op); 679 op->destroy ();
696 free_object (op);
697 } 680 }
698 else 681 else
699 { 682 {
700 op = fix_stopped_arrow (op); 683 op = fix_stopped_arrow (op);
701 if (op) 684 if (op)
715 maptile *m; 698 maptile *m;
716 699
717 if (op->map == NULL) 700 if (op->map == NULL)
718 { 701 {
719 LOG (llevError, "BUG: Arrow had no map.\n"); 702 LOG (llevError, "BUG: Arrow had no map.\n");
720 remove_ob (op); 703 op->destroy ();
721 free_object (op);
722 return; 704 return;
723 } 705 }
724 706
725 /* we need to stop thrown objects at some point. Like here. */ 707 /* we need to stop thrown objects at some point. Like here. */
726 if (op->type == THROWN_OBJ) 708 if (op->type == THROWN_OBJ)
733 * bomb code, but there are potential other cases where that could happen, 715 * bomb code, but there are potential other cases where that could happen,
734 * and it is easy enough to clean it up here. 716 * and it is easy enough to clean it up here.
735 */ 717 */
736 if (op->inv == NULL) 718 if (op->inv == NULL)
737 { 719 {
738 remove_ob (op); 720 op->destroy ();
739 free_object (op);
740 return; 721 return;
741 } 722 }
723
742 if (op->last_sp-- < 0) 724 if (op->last_sp-- < 0)
743 { 725 {
744 stop_arrow (op); 726 stop_arrow (op);
745 return; 727 return;
746 } 728 }
769 } 751 }
770 752
771 /* only need to look for living creatures if this flag is set */ 753 /* only need to look for living creatures if this flag is set */
772 if (mflags & P_IS_ALIVE) 754 if (mflags & P_IS_ALIVE)
773 { 755 {
774 for (tmp = get_map_ob (m, new_x, new_y); tmp != NULL; tmp = tmp->above) 756 for (tmp = GET_MAP_OB (m, new_x, new_y); tmp != NULL; tmp = tmp->above)
775 if (QUERY_FLAG (tmp, FLAG_ALIVE)) 757 if (QUERY_FLAG (tmp, FLAG_ALIVE))
776 break; 758 break;
777
778 759
779 /* Not really fair, but don't let monsters hit themselves with 760 /* Not really fair, but don't let monsters hit themselves with
780 * their own arrow - this can be because they fire it then 761 * their own arrow - this can be because they fire it then
781 * move into it. 762 * move into it.
782 */ 763 */
783
784 if (tmp != NULL && tmp != op->owner) 764 if (tmp && tmp != op->owner)
785 { 765 {
786 /* Found living object, but it is reflecting the missile. Update 766 /* Found living object, but it is reflecting the missile. Update
787 * as below. (Note that for living creatures there is a small 767 * as below. (Note that for living creatures there is a small
788 * chance that reflect_missile fails.) 768 * chance that reflect_missile fails.)
789 */ 769 */
790
791 if (QUERY_FLAG (tmp, FLAG_REFL_MISSILE) && (rndm (0, 99)) < (90 - op->level / 10)) 770 if (QUERY_FLAG (tmp, FLAG_REFL_MISSILE) && (rndm (0, 99)) < (90 - op->level / 10))
792 { 771 {
793
794 int number = op->face->number; 772 int number = op->face->number;
795 773
796 op->direction = absdir (op->direction + 4); 774 op->direction = absdir (op->direction + 4);
797 op->state = 0; 775 op->state = 0;
776
798 if (GET_ANIM_ID (op)) 777 if (GET_ANIM_ID (op))
799 { 778 {
800 number += 4; 779 number += 4;
780
801 if (number > GET_ANIMATION (op, 8)) 781 if (number > GET_ANIMATION (op, 8))
802 number -= 8; 782 number -= 8;
783
803 op->face = &new_faces[number]; 784 op->face = &new_faces[number];
804 } 785 }
786
805 was_reflected = 1; /* skip normal movement calculations */ 787 was_reflected = 1; /* skip normal movement calculations */
806 } 788 }
807 else 789 else
808 { 790 {
809 /* Attack the object. */ 791 /* Attack the object. */
810 op = hit_with_arrow (op, tmp); 792 op = hit_with_arrow (op, tmp);
793
811 if (op == NULL) 794 if (!op)
812 return; 795 return;
813 } 796 }
814 } /* if this is not hitting its owner */ 797 } /* if this is not hitting its owner */
815 } /* if there is something alive on this space */ 798 } /* if there is something alive on this space */
816
817 799
818 if (OB_TYPE_MOVE_BLOCK (op, GET_MAP_MOVE_BLOCK (m, new_x, new_y))) 800 if (OB_TYPE_MOVE_BLOCK (op, GET_MAP_MOVE_BLOCK (m, new_x, new_y)))
819 { 801 {
820 int retry = 0; 802 int retry = 0;
821 803
893 SET_ANIMATION (op, op->direction); 875 SET_ANIMATION (op, op->direction);
894 } /* object is reflected */ 876 } /* object is reflected */
895 } /* object ran into a wall */ 877 } /* object ran into a wall */
896 878
897 /* Move the arrow. */ 879 /* Move the arrow. */
898 remove_ob (op); 880 op->remove ();
899 op->x = new_x; 881 op->x = new_x;
900 op->y = new_y; 882 op->y = new_y;
901 883
902 /* decrease the speed as it flies. 0.05 means a standard bow will shoot 884 /* decrease the speed as it flies. 0.05 means a standard bow will shoot
903 * about 17 squares. Tune as needed. 885 * about 17 squares. Tune as needed.
911 * Modified this routine to allow held objects. b.t. */ 893 * Modified this routine to allow held objects. b.t. */
912 894
913void 895void
914change_object (object *op) 896change_object (object *op)
915{ /* Doesn`t handle linked objs yet */ 897{ /* Doesn`t handle linked objs yet */
916 object *tmp, *env, *pl;
917 int i, j; 898 int i, j;
918 899
919 if (op->other_arch == NULL) 900 if (op->other_arch == NULL)
920 { 901 {
921 LOG (llevError, "Change object (%s) without other_arch error.\n", &op->name); 902 LOG (llevError, "Change object (%s) without other_arch error.\n", &op->name);
928 if (op->stats.food-- > 0) 909 if (op->stats.food-- > 0)
929 return; 910 return;
930 else 911 else
931 op->stats.food = 1; /* so 1 other_arch is made */ 912 op->stats.food = 1; /* so 1 other_arch is made */
932 } 913 }
914
915 object *pl = op->in_player ();
933 env = op->env; 916 object *env = op->env;
934 remove_ob (op); 917
918 op->remove ();
935 for (i = 0; i < NROFNEWOBJS (op); i++) 919 for (i = 0; i < NROFNEWOBJS (op); i++)
936 { 920 {
937 tmp = arch_to_object (op->other_arch); 921 object *tmp = arch_to_object (op->other_arch);
922
938 if (op->type == LAMP) 923 if (op->type == LAMP)
939 tmp->stats.food = op->stats.food - 1; 924 tmp->stats.food = op->stats.food - 1;
925
940 tmp->stats.hp = op->stats.hp; /* The only variable it keeps. */ 926 tmp->stats.hp = op->stats.hp; /* The only variable it keeps. */
941 if (env) 927 if (env)
942 { 928 {
943 tmp->x = env->x, tmp->y = env->y; 929 tmp->x = env->x, tmp->y = env->y;
944 tmp = insert_ob_in_ob (tmp, env); 930 tmp = insert_ob_in_ob (tmp, env);
931
945 /* If this object is the players inventory, we need to tell the 932 /* If this object is the players inventory, we need to tell the
946 * client of the change. Insert_ob_in_map takes care of the 933 * client of the change. Insert_ob_in_map takes care of the
947 * updating the client, so we don't need to do that below. 934 * updating the client, so we don't need to do that below.
948 */ 935 */
949 if ((pl = is_player_inv (env)) != NULL) 936 if (pl)
950 { 937 {
951 esrv_del_item (pl->contr, op->count); 938 esrv_del_item (pl->contr, op->count);
952 esrv_send_item (pl, tmp); 939 esrv_send_item (pl, tmp);
953 } 940 }
954 } 941 }
955 else 942 else
956 { 943 {
957 j = find_first_free_spot (tmp, op->map, op->x, op->y); 944 j = find_first_free_spot (tmp, op->map, op->x, op->y);
958 if (j == -1) /* No free spot */ 945 if (j == -1) /* No free spot */
959 free_object (tmp); 946 tmp->destroy ();
960 else 947 else
961 { 948 {
962 tmp->x = op->x + freearr_x[j], tmp->y = op->y + freearr_y[j]; 949 tmp->x = op->x + freearr_x[j], tmp->y = op->y + freearr_y[j];
963 insert_ob_in_map (tmp, op->map, op, 0); 950 insert_ob_in_map (tmp, op->map, op, 0);
964 } 951 }
965 } 952 }
966 } 953 }
967 free_object (op); 954
955 op->destroy ();
968} 956}
969 957
970void 958void
971move_teleporter (object *op) 959move_teleporter (object *op)
972{ 960{
1009 else if (EXIT_X (head) || EXIT_Y (head)) 997 else if (EXIT_X (head) || EXIT_Y (head))
1010 { 998 {
1011 if (out_of_map (head->map, EXIT_X (head), EXIT_Y (head))) 999 if (out_of_map (head->map, EXIT_X (head), EXIT_Y (head)))
1012 { 1000 {
1013 LOG (llevError, "Removed illegal teleporter.\n"); 1001 LOG (llevError, "Removed illegal teleporter.\n");
1014 remove_ob (head); 1002 head->destroy ();
1015 free_object (head);
1016 return; 1003 return;
1017 } 1004 }
1005
1018 if (INVOKE_OBJECT (TRIGGER, op, ARG_OBJECT (tmp))) 1006 if (INVOKE_OBJECT (TRIGGER, op, ARG_OBJECT (tmp)))
1019 return; 1007 return;
1008
1020 transfer_ob (tmp, EXIT_X (head), EXIT_Y (head), 0, head); 1009 transfer_ob (tmp, EXIT_X (head), EXIT_Y (head), 0, head);
1021 } 1010 }
1022 else 1011 else
1023 { 1012 {
1024 /* Random teleporter */ 1013 /* Random teleporter */
1055 player = op->above; 1044 player = op->above;
1056 1045
1057 for (walk = op->inv; walk != NULL; walk = walk->below) 1046 for (walk = op->inv; walk != NULL; walk = walk->below)
1058 apply_changes_to_player (player, walk); 1047 apply_changes_to_player (player, walk);
1059 1048
1060 fix_player (player); 1049 player->update_stats ();
1061 1050
1062 esrv_send_inventory (op->above, op->above); 1051 esrv_send_inventory (op->above, op->above);
1063 esrv_update_item (UPD_FACE, op->above, op->above); 1052 esrv_update_item (UPD_FACE, op->above, op->above);
1064 1053
1065 /* update players death & WoR home-position */ 1054 /* update players death & WoR home-position */
1072 } 1061 }
1073 else 1062 else
1074 LOG (llevDebug, "WARNING: destination '%s' in player_changer must be an absolute path!\n", &EXIT_PATH (op)); 1063 LOG (llevDebug, "WARNING: destination '%s' in player_changer must be an absolute path!\n", &EXIT_PATH (op));
1075 1064
1076 enter_exit (op->above, op); 1065 enter_exit (op->above, op);
1077 save_player (player, 1); 1066 player->contr->save ();
1078 } 1067 }
1079} 1068}
1080 1069
1081/* firewalls fire other spells. 1070/* firewalls fire other spells.
1082 * The direction of the wall is stored in op->stats.sp. 1071 * The direction of the wall is stored in op->stats.sp.
1089 1078
1090 if (!op->map) 1079 if (!op->map)
1091 return; /* dm has created a firewall in his inventory */ 1080 return; /* dm has created a firewall in his inventory */
1092 1081
1093 spell = op->inv; 1082 spell = op->inv;
1083
1094 if (!spell || spell->type != SPELL) 1084 if (!spell || spell->type != SPELL)
1095 spell = &op->other_arch->clone; 1085 spell = &op->other_arch->clone;
1086
1096 if (!spell) 1087 if (!spell)
1097 { 1088 {
1098 LOG (llevError, "move_firewall: no spell specified (%s, %s, %d, %d)\n", &op->name, op->map->name, op->x, op->y); 1089 LOG (llevError, "move_firewall: no spell specified (%s, %s, %d, %d)\n", &op->name, op->map->name, op->x, op->y);
1099 return; 1090 return;
1100 } 1091 }
1101 1092
1102 cast_spell (op, op, op->stats.sp ? op->stats.sp : rndm (1, 8), spell, NULL); 1093 cast_spell (op, op, op->stats.sp ? op->stats.sp : rndm (1, 8), spell, NULL);
1103} 1094}
1104
1105 1095
1106/* move_player_mover: this function takes a "player mover" as an 1096/* move_player_mover: this function takes a "player mover" as an
1107 * argument, and performs the function of a player mover, which is: 1097 * argument, and performs the function of a player mover, which is:
1108 * 1098 *
1109 * a player mover finds any players that are sitting on it. It 1099 * a player mover finds any players that are sitting on it. It
1122 1112
1123 /* Determine direction now for random movers so we do the right thing */ 1113 /* Determine direction now for random movers so we do the right thing */
1124 if (!dir) 1114 if (!dir)
1125 dir = rndm (1, 8); 1115 dir = rndm (1, 8);
1126 1116
1127 for (victim = get_map_ob (op->map, op->x, op->y); victim != NULL; victim = victim->above) 1117 for (victim = GET_MAP_OB (op->map, op->x, op->y); victim != NULL; victim = victim->above)
1128 { 1118 {
1129 if (QUERY_FLAG (victim, FLAG_ALIVE) && !QUERY_FLAG (victim, FLAG_WIZPASS) && 1119 if (QUERY_FLAG (victim, FLAG_ALIVE) && !QUERY_FLAG (victim, FLAG_WIZPASS) &&
1130 (victim->move_type & op->move_type || !victim->move_type)) 1120 (victim->move_type & op->move_type || !victim->move_type))
1131 { 1121 {
1132 1122
1133 if (victim->head) 1123 if (victim->head)
1134 victim = victim->head; 1124 victim = victim->head;
1135 1125
1136 if (QUERY_FLAG (op, FLAG_LIFESAVE) && op->stats.hp-- < 0) 1126 if (QUERY_FLAG (op, FLAG_LIFESAVE) && op->stats.hp-- < 0)
1137 { 1127 {
1138 remove_ob (op); 1128 op->remove ();
1139 free_object (op);
1140 return; 1129 return;
1141 } 1130 }
1131
1142 nx = op->x + freearr_x[dir]; 1132 nx = op->x + freearr_x[dir];
1143 ny = op->y + freearr_y[dir]; 1133 ny = op->y + freearr_y[dir];
1144 m = op->map; 1134 m = op->map;
1145 if (get_map_flags (m, &m, nx, ny, &nx, &ny) & P_OUT_OF_MAP) 1135 if (get_map_flags (m, &m, nx, ny, &nx, &ny) & P_OUT_OF_MAP)
1146 { 1136 {
1149 } 1139 }
1150 1140
1151 if (should_director_abort (op, victim)) 1141 if (should_director_abort (op, victim))
1152 return; 1142 return;
1153 1143
1154 for (nextmover = get_map_ob (m, nx, ny); nextmover != NULL; nextmover = nextmover->above) 1144 for (nextmover = GET_MAP_OB (m, nx, ny); nextmover != NULL; nextmover = nextmover->above)
1155 { 1145 {
1156 if (nextmover->type == PLAYERMOVER) 1146 if (nextmover->type == PLAYERMOVER)
1157 nextmover->speed_left = -.99; 1147 nextmover->speed_left = -.99;
1158 if (QUERY_FLAG (nextmover, FLAG_ALIVE)) 1148 if (QUERY_FLAG (nextmover, FLAG_ALIVE))
1159 { 1149 {
1224 for (tmp = op->above; tmp != NULL; tmp = tmp->above) 1214 for (tmp = op->above; tmp != NULL; tmp = tmp->above)
1225 { 1215 {
1226 if (strcmp (op->other_arch->name, tmp->arch->name) == 0) 1216 if (strcmp (op->other_arch->name, tmp->arch->name) == 0)
1227 { 1217 {
1228 if (op->level <= 0) 1218 if (op->level <= 0)
1229 { 1219 tmp->destroy ();
1230 remove_ob (tmp);
1231 free_object (tmp);
1232 }
1233 else 1220 else
1234 { 1221 {
1235 uint64 new_nrof = (uint64) tmp->nrof * op->level; 1222 uint64 new_nrof = (uint64) tmp->nrof * op->level;
1236 1223
1237 if (new_nrof >= 1UL << 31) 1224 if (new_nrof >= 1UL << 31)
1238 new_nrof = 1UL << 31; 1225 new_nrof = 1UL << 31;
1226
1239 tmp->nrof = new_nrof; 1227 tmp->nrof = new_nrof;
1240 } 1228 }
1229
1241 break; 1230 break;
1242 } 1231 }
1243 } 1232 }
1244} 1233}
1245 1234
1301 } 1290 }
1302 1291
1303 /* Make sure this multipart object fits */ 1292 /* Make sure this multipart object fits */
1304 if (new_ob->arch->more && ob_blocked (new_ob, creator->map, creator->x, creator->y)) 1293 if (new_ob->arch->more && ob_blocked (new_ob, creator->map, creator->x, creator->y))
1305 { 1294 {
1306 free_object (new_ob); 1295 new_ob->destroy ();
1307 return; 1296 return;
1308 } 1297 }
1309 1298
1310 insert_ob_in_map_at (new_ob, creator->map, creator, 0, creator->x, creator->y); 1299 insert_ob_in_map_at (new_ob, creator->map, creator, 0, creator->x, creator->y);
1311 if (QUERY_FLAG (new_ob, FLAG_FREED)) 1300 if (QUERY_FLAG (new_ob, FLAG_FREED))
1327 unless hp was zero to start with, in which case it is infinite.*/ 1316 unless hp was zero to start with, in which case it is infinite.*/
1328 1317
1329void 1318void
1330move_marker (object *op) 1319move_marker (object *op)
1331{ 1320{
1321 if (object *tmp = op->ms ().player ())
1322 {
1332 object *tmp, *tmp2; 1323 object *tmp2;
1333 1324
1334 for (tmp = get_map_ob (op->map, op->x, op->y); tmp != NULL; tmp = tmp->above)
1335 {
1336 if (tmp->type == PLAYER)
1337 { /* we've got someone to MARK */
1338
1339 /* remove an old force with a slaying field == op->name */ 1325 /* remove an old force with a slaying field == op->name */
1340 for (tmp2 = tmp->inv; tmp2 != NULL; tmp2 = tmp2->below) 1326 for (tmp2 = tmp->inv; tmp2; tmp2 = tmp2->below)
1341 {
1342 if (tmp2->type == FORCE && tmp2->slaying && !strcmp (tmp2->slaying, op->name)) 1327 if (tmp2->type == FORCE && tmp2->slaying && !strcmp (tmp2->slaying, op->name))
1343 break;
1344 }
1345
1346 if (tmp2)
1347 { 1328 {
1348 remove_ob (tmp2); 1329 tmp2->destroy ();
1349 free_object (tmp2); 1330 break;
1350 } 1331 }
1351 1332
1352 /* cycle through his inventory to look for the MARK we want to 1333 /* cycle through his inventory to look for the MARK we want to
1353 * place 1334 * place
1354 */ 1335 */
1355 for (tmp2 = tmp->inv; tmp2 != NULL; tmp2 = tmp2->below) 1336 for (tmp2 = tmp->inv; tmp2; tmp2 = tmp2->below)
1356 {
1357 if (tmp2->type == FORCE && tmp2->slaying && !strcmp (tmp2->slaying, op->slaying)) 1337 if (tmp2->type == FORCE && tmp2->slaying && !strcmp (tmp2->slaying, op->slaying))
1358 break; 1338 break;
1359 }
1360 1339
1361 /* if we didn't find our own MARK */ 1340 /* if we didn't find our own MARK */
1362 if (tmp2 == NULL) 1341 if (tmp2 == NULL)
1363 { 1342 {
1364 object *force = get_archetype (FORCE_NAME); 1343 object *force = get_archetype (FORCE_NAME);
1365 1344
1366 force->speed = 0;
1367 if (op->stats.food) 1345 if (op->stats.food)
1346 {
1347 force->set_speed (0.01);
1348 force->speed_left = -op->stats.food;
1349 }
1350 else
1351 force->set_speed (0);
1352
1353 /* put in the lock code */
1354 force->slaying = op->slaying;
1355
1356 if (op->lore)
1357 force->lore = op->lore;
1358
1359 insert_ob_in_ob (force, tmp);
1360 if (op->msg)
1361 new_draw_info (NDI_UNIQUE | NDI_NAVY, 0, tmp, op->msg);
1362
1363 if (op->stats.hp > 0)
1364 {
1365 op->stats.hp--;
1366 if (op->stats.hp == 0)
1368 { 1367 {
1369 force->speed = 0.01; 1368 /* marker expires--granted mark number limit */
1370 force->speed_left = -op->stats.food; 1369 op->destroy ();
1370 return;
1371 } 1371 }
1372 update_ob_speed (force);
1373 /* put in the lock code */
1374 force->slaying = op->slaying;
1375
1376 if (op->lore)
1377 force->lore = op->lore;
1378
1379 insert_ob_in_ob (force, tmp);
1380 if (op->msg)
1381 new_draw_info (NDI_UNIQUE | NDI_NAVY, 0, tmp, op->msg);
1382
1383 if (op->stats.hp > 0)
1384 {
1385 op->stats.hp--;
1386 if (op->stats.hp == 0)
1387 {
1388 /* marker expires--granted mark number limit */
1389 remove_ob (op);
1390 free_object (op);
1391 return;
1392 }
1393 } 1372 }
1394 } /* if tmp2 == NULL */ 1373 }
1395 } /* if tmp->type == PLAYER */ 1374 }
1396 } /* For all objects on this space */
1397} 1375}
1398 1376
1399int 1377int
1400process_object (object *op) 1378process_object (object *op)
1401{ 1379{
1434 if (QUERY_FLAG (op, FLAG_APPLIED)) 1412 if (QUERY_FLAG (op, FLAG_APPLIED))
1435 remove_force (op); 1413 remove_force (op);
1436 else 1414 else
1437 { 1415 {
1438 /* IF necessary, delete the item from the players inventory */ 1416 /* IF necessary, delete the item from the players inventory */
1439 object *pl = is_player_inv (op); 1417 object *pl = op->in_player ();
1440 1418
1441 if (pl) 1419 if (pl)
1442 esrv_del_item (pl->contr, op->count); 1420 esrv_del_item (pl->contr, op->count);
1443 1421
1444 remove_ob (op); 1422 op->remove ();
1445 1423
1446 if (QUERY_FLAG (op, FLAG_SEE_ANYWHERE)) 1424 if (QUERY_FLAG (op, FLAG_SEE_ANYWHERE))
1447 make_sure_not_seen (op); 1425 make_sure_not_seen (op);
1448 1426
1449 free_object (op); 1427 op->destroy ();
1450 } 1428 }
1451 1429
1452 return 1; 1430 return 1;
1453 } 1431 }
1454 1432
1485 return 0; 1463 return 0;
1486 1464
1487 case THROWN_OBJ: 1465 case THROWN_OBJ:
1488 case ARROW: 1466 case ARROW:
1489 move_arrow (op); 1467 move_arrow (op);
1490 return 0;
1491
1492 case LIGHTNING: /* It now moves twice as fast */
1493 move_bolt (op);
1494 return 0; 1468 return 0;
1495 1469
1496 case DOOR: 1470 case DOOR:
1497 remove_door (op); 1471 remove_door (op);
1498 return 0; 1472 return 0;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines