Debian Codegraph @

server/time.c

raw symbols SCIP
1 /*
2 * Crossfire -- cooperative multi-player graphical RPG and adventure game
3 *
4 * Copyright (c) 1999-2014 Mark Wedel and the Crossfire Development Team
5 * Copyright (c) 1992 Frank Tore Johansen
6 *
7 * Crossfire is free software and comes with ABSOLUTELY NO WARRANTY. You are
8 * welcome to redistribute it under certain conditions. For details, please
9 * see COPYING and LICENSE.
10 *
11 * The authors can be reached via e-mail at <[email protected]>.
12 */
13
14 /**
15 * @file
16 * Routines that is executed from objects based on their speed have been
17 * collected in this file.
18 */
19
20 #include "global.h"
21
22 #include <stdlib.h>
23
24 #include "spells.h"
25 #include "sproto.h"
26
27 /**
28 * Remove non locked doors. The functions check to see if similar
29 * doors are next to the one that is being removed, and if so, set it
30 * so those will be removed shortly (in a cascade like fashion.)
31 *
32 * @sa remove_locked_door().
33 *
34 * @param op
35 * door to remove.
36 */
37 void remove_door(object *op) {
38 int i;
39 object *tmp;
40
41 for (i = 1; i < 9; i += 2)
42 if ((tmp = map_find_by_type(op->map, op->x+freearr_x[i], op->y+freearr_y[i], DOOR)) != NULL) {
43 tmp->speed = 0.1;
44 object_update_speed(tmp);
45 tmp->speed_left = -0.2;
46 }
47
48 if (op->other_arch) {
49 tmp = arch_to_object(op->other_arch);
50 tmp->level = op->level;
51 object_insert_in_map_at(tmp, op->map, op, 0, op->x, op->y);
52 }
53 object_remove(op);
54 object_free_drop_inventory(op);
55 }
56
57 /**
58 * Same as remove_door() but for locked doors.
59 *
60 * @param op
61 * door to remove.
62 */
63 void remove_locked_door(object *op) {
64 int i;
65 object *tmp;
66
67 for (i = 1; i < 9; i += 2) {
68 tmp = map_find_by_type(op->map, op->x+freearr_x[i], op->y+freearr_y[i], LOCKED_DOOR);
69 if (tmp && tmp->slaying == op->slaying) {/* same key both doors */
70 tmp->speed = 0.1;
71 object_update_speed(tmp);
72 tmp->speed_left = -0.2;
73 }
74 }
75 if (op->other_arch) {
76 tmp = arch_to_object(op->other_arch);
77 tmp->level = op->level;
78 object_insert_in_map_at(tmp, op->map, op, 0, op->x, op->y);
79 }
80 object_remove(op);
81 object_free_drop_inventory(op);
82 }
83
84 /**
85 * Will generate a monster according to parameters of generator.
86 *
87 * What is generated should be in the generator's inventory.
88 *
89 * See generate_monster() for the main generator function.
90 *
91 * @param gen
92 * generator.
93 * @return
94 * TRUE if put a monster on a map, FALSE if did not
95 */
96 static int generate_monster_inv(object *gen) {
97 int i;
98 int nx, ny;
99 object *op, *head = NULL;
100 const char *code;
101 int qty = 0;
102
103 /* Code below assumes the generator is on a map, as it tries
104 * to place the monster on the map. So if the generator
105 * isn't on a map, complain and exit.
106 */
107 if (gen->map == NULL) {
108 LOG(llevError, "Generator (%s) not on a map?\n", gen->name);
109 return FALSE;
110 }
111
112 /*First count number of objects in inv*/
113 FOR_INV_PREPARE(gen, op)
114 qty++;
115 FOR_INV_FINISH();
116 if (!qty) {
117 LOG(llevError, "Generator (%s) has no inventory in generate_monster_inv?\n", gen->name);
118 return FALSE;/*No inventory*/
119 }
120 qty = rndm(0, qty-1);
121 op = NULL;
122 FOR_INV_PREPARE(gen, tmp) {
123 op = tmp;
124 if (qty == 0)
125 break;
126 qty--;
127 } FOR_INV_FINISH();
128 i = object_find_multi_free_spot_within_radius(op, gen, &nx, &ny);
129 if (i == -1)
130 return FALSE;
131 head = object_create_clone(op);
132 CLEAR_FLAG(head, FLAG_IS_A_TEMPLATE);
133 object_unset_flag_inv(head, FLAG_IS_A_TEMPLATE);
134 if (rndm(0, 9))
135 generate_artifact(head, gen->map->difficulty);
136 code = object_get_value(gen, "generator_code");
137 if (code) {
138 object_set_value(head, "generator_code", code, 1);
139 }
140 object_insert_in_map_at(head, gen->map, gen, 0, nx, ny);
141 if (QUERY_FLAG(head, FLAG_FREED))
142 return TRUE;
143 object_fix_multipart(head);
144 if (HAS_RANDOM_ITEMS(head)) {
145 create_treasure(head->randomitems, head, 0, gen->map->difficulty, 0);
146 if (QUERY_FLAG(head, FLAG_MONSTER)) {
147 monster_check_apply_all(head);
148 }
149 }
150 return TRUE;
151 }
152
153 /**
154 * Generate a monster from the other_arch field.
155 *
156 * See generate_monster() for the main generator function.
157 *
158 * @param gen
159 * generator.
160 * @return
161 * TRUE if monster was put on map, FALSE if not
162 */
163 static int generate_monster_arch(object *gen) {
164 int i;
165 int nx, ny;
166 object *op, *head = NULL, *prev = NULL;
167 archetype *at = gen->other_arch;
168 const char *code;
169
170 if (gen->other_arch == NULL) {
171 LOG(llevError, "Generator without other_arch: %s\n", gen->name);
172 return FALSE;
173 }
174 /* Code below assumes the generator is on a map, as it tries
175 * to place the monster on the map. So if the generator
176 * isn't on a map, complain and exit.
177 */
178 if (gen->map == NULL) {
179 LOG(llevError, "Generator (%s) not on a map?\n", gen->name);
180 return FALSE;
181 }
182 i = object_find_multi_free_spot_within_radius(&at->clone, gen, &nx, &ny);
183 if (i == -1)
184 return FALSE;
185 while (at != NULL) {
186 op = arch_to_object(at);
187 op->x = nx+at->clone.x;
188 op->y = ny+at->clone.y;
189
190 if (head != NULL) {
191 op->head = head;
192 prev->more = op;
193 }
194
195 if (rndm(0, 9))
196 generate_artifact(op, gen->map->difficulty);
197
198 code = object_get_value(gen, "generator_code");
199
200 object_insert_in_map(op, gen->map, gen, 0);
201 /* Did generate a monster, just didn't live very long */
202 if (QUERY_FLAG(op, FLAG_FREED))
203 return TRUE;
204 if (HAS_RANDOM_ITEMS(op)) {
205 create_treasure(op->randomitems, op, 0, gen->map->difficulty, 0);
206 if (QUERY_FLAG(op, FLAG_MONSTER)) {
207 monster_check_apply_all(op);
208 }
209 }
210 if (head == NULL) {
211 head = op;
212 if (code) {
213 object_set_value(head, "generator_code", code, 1);
214 }
215 }
216 prev = op;
217 at = at->more;
218 }
219 return TRUE;
220 }
221
222 /**
223 * Main generator function. Will generate a monster based on the parameters.
224 *
225 * @param gen
226 * generator.
227 */
228 static void generate_monster(object *gen) {
229 int8_t children, max_children;
230 int8_t x, y;
231 const char *code, *value;
232 int did_gen = 0;
233
234 if (GENERATE_SPEED(gen) && rndm(0, GENERATE_SPEED(gen)-1))
235 return;
236
237 value = object_get_value(gen, "generator_max_map");
238 if (value) {
239 max_children = (int8_t)strtol(value, NULL, 10);
240 if (max_children < 1)
241 return;
242 code = object_get_value(gen, "generator_code");
243 if (code) {
244 /* Generator has a limit and has created some,
245 * so count how many already exist
246 */
247 children = 0;
248 for (x = 0; x < MAP_WIDTH(gen->map); x++) {
249 for (y = 0; y < MAP_HEIGHT(gen->map); y++) {
250 FOR_MAP_PREPARE(gen->map, x, y, tmp) {
251 value = object_get_value(tmp, "generator_code");
252 if (value && value == code) {
253 children++;
254 }
255 } FOR_MAP_FINISH();
256 }
257 }
258 /* and return without generating if there are already enough */
259 if (children >= max_children+1)
260 return;
261 } else {
262 /* Generator has a limit, but hasn't created anything yet,
263 * so no need to count, just set code and go
264 */
265 value = object_get_value(gen, "generator_name");
266 if (value) {
267 object_set_value(gen, "generator_code", value, 1);
268 } else if (gen->name) {
269 object_set_value(gen, "generator_code", gen->name, 1);
270 } else {
271 object_set_value(gen, "generator_code", "generator", 1);
272 }
273 }
274 } /* If this has a max map generator limit */
275
276 if (QUERY_FLAG(gen, FLAG_CONTENT_ON_GEN))
277 did_gen = generate_monster_inv(gen);
278 else
279 did_gen = generate_monster_arch(gen);
280
281 /* See if generator has a generator_limit limit set */
282 value = object_get_value(gen, "generator_limit");
283
284 /* Only do this if we actually made a monster. If the generator
285 * was unable to create a monster (no space for example),
286 * we don't want to prematurely remove the generator.
287 */
288 if (value && did_gen) {
289 int limit = atoi(value), num_generated = 0;
290
291 value = object_get_value(gen, "generator_generated");
292 if (value)
293 num_generated = atoi(value);
294
295 if (num_generated++ >= limit) {
296 object_remove(gen);
297 object_free_drop_inventory(gen);
298 } else {
299 char buf[50];
300
301 snprintf(buf, sizeof(buf), "%d", num_generated);
302 object_set_value(gen, "generator_generated", buf, 1);
303 }
304 }
305 }
306
307 /**
308 * Move for ::FORCE objects.
309 *
310 * @param op
311 * force to test.
312 * @todo rename to move_force?
313 */
314 static void remove_force(object *op) {
315 if (--op->duration > 0) {
316 check_spell_expiry(op);
317 return;
318 }
319
320 switch (op->subtype) {
321 case FORCE_CONFUSION:
322 if (op->env != NULL) {
323 CLEAR_FLAG(op->env, FLAG_CONFUSED);
324 draw_ext_info(NDI_UNIQUE, 0, op->env,
325 MSG_TYPE_ATTRIBUTE, MSG_TYPE_ATTRIBUTE_BAD_EFFECT_END,
326 "You regain your senses.");
327 }
328 break;
329
330 case FORCE_TRANSFORMED_ITEM:
331 /* The force is into the item that was created */
332 if (op->env != NULL && op->inv != NULL) {
333 object *inv = op->inv;
334 object *pl = object_get_player_container(op);
335
336 object_remove(inv);
337 inv->weight = (inv->nrof ? (int32_t)(op->env->weight/inv->nrof) : op->env->weight);
338 if (op->env->env) {
339 object_insert_in_ob(inv, op->env->env);
340 if (pl) {
341 char name[HUGE_BUF];
342
343 query_short_name(inv, name, HUGE_BUF);
344 draw_ext_info_format(NDI_UNIQUE, 0, pl, MSG_TYPE_ITEM, MSG_TYPE_ITEM_CHANGE,
345 "Your %s recovers its original form.",
346 name);
347 }
348 } else {
349 /* Object on map */
350 object_insert_in_map_at(inv, op->env->map, NULL, 0, op->env->x, op->env->y);
351 }
352 inv = op->env;
353 object_remove(op);
354 object_free_drop_inventory(op);
355 object_remove(inv);
356 }
357 return;
358
359 default:
360 break;
361 }
362
363 if (op->env != NULL) {
364 CLEAR_FLAG(op, FLAG_APPLIED);
365 change_abil(op->env, op);
366 fix_object(op->env);
367 }
368 object_remove(op);
369 object_free_drop_inventory(op);
370 }
371
372 /**
373 * Animate a ::TRIGGER.
374 *
375 * @param op
376 * trigger.
377 */
378 static void animate_trigger(object *op) {
379 if ((unsigned char)++op->stats.wc >= NUM_ANIMATIONS(op)) {
380 op->stats.wc = 0;
381 check_trigger(op, NULL);
382 } else {
383 SET_ANIMATION(op, op->stats.wc);
384 object_update(op, UP_OBJ_FACE);
385 }
386 }
387
388 /**
389 * Move a ::HOLE.
390 *
391 * @param op
392 * hole to move.
393 */
394 static void move_hole(object *op) { /* 1 = opening, 0 = closing */
395 if (op->value) { /* We're opening */
396 if (--op->stats.wc <= 0) { /* Opened, let's stop */
397 op->stats.wc = 0;
398 op->speed = 0;
399 object_update_speed(op);
400
401 /* Hard coding this makes sense for holes I suppose */
402 op->move_on = MOVE_WALK;
403 FOR_ABOVE_PREPARE(op, tmp)
404 ob_move_on(op, tmp, tmp);
405 FOR_ABOVE_FINISH();
406 }
407
408 op->state = op->stats.wc;
409 animate_object(op, 0);
410 object_update(op, UP_OBJ_FACE);
411 return;
412 }
413 /* We're closing */
414 op->move_on = 0;
415
416 op->stats.wc++;
417 if ((int)op->stats.wc >= NUM_ANIMATIONS(op))
418 op->stats.wc = NUM_ANIMATIONS(op)-1;
419
420 op->state = op->stats.wc;
421 animate_object(op, 0);
422 object_update(op, UP_OBJ_FACE);
423 if ((unsigned char)op->stats.wc == (NUM_ANIMATIONS(op)-1)) {
424 op->speed = 0;
425 object_update_speed(op); /* closed, let's stop */
426 return;
427 }
428 }
429
430 /**
431 * An item (::ARROW or such) stops moving.
432 *
433 * stop_item() returns a pointer to the stopped object. The stopped object
434 * may or may not have been removed from maps or inventories. It will not
435 * have been merged with other items.
436 *
437 * This function assumes that only items on maps need special treatment.
438 *
439 * If the object can't be stopped, or it was destroyed while trying to stop
440 * it, NULL is returned.
441 *
442 * fix_stopped_item() should be used if the stopped item should be put on
443 * the map.
444 *
445 * @param op
446 * object to check.
447 * @return
448 * pointer to stopped object, NULL if destroyed or can't be stopped.
449 */
450 object *stop_item(object *op) {
451 if (free_no_drop(op))
452 return NULL;
453
454 if (op->map == NULL)
455 return op;
456
457 switch (op->type) {
458 case THROWN_OBJ: {
459 object *payload = op->inv;
460
461 if (payload == NULL)
462 return NULL;
463 object_remove(payload);
464 object_remove(op);
465 object_free_drop_inventory(op);
466 return payload;
467 }
468
469 case ARROW:
470 if (op->speed >= MIN_ACTIVE_SPEED)
471 op = fix_stopped_arrow(op);
472 return op;
473
474 default:
475 return op;
476 }
477 }
478
479 /**
480 * Put stopped item where stop_item() had found it.
481 * Inserts item into the old map, or merges it if it already is on the map.
482 *
483 * @param op
484 * object to stop.
485 * @param map
486 * must be the value of op->map before stop_item() was called.
487 * @param originator
488 * what caused op to be stopped.
489 */
490 void fix_stopped_item(object *op, mapstruct *map, object *originator) {
491 if (map == NULL)
492 return;
493 if (QUERY_FLAG(op, FLAG_REMOVED))
494 object_insert_in_map(op, map, originator, 0);
495 else if (op->type == ARROW)
496 object_merge(op, NULL); /* only some arrows actually need this */
497 }
498
499 /**
500 * An ::ARROW stops moving.
501 *
502 * @param op
503 * arrow stopping.
504 * @return
505 * arrow, or NULL if it was broken.
506 */
507 object *fix_stopped_arrow(object *op) {
508 if (free_no_drop(op))
509 return NULL;
510
511 if (rndm(0, 99) < op->stats.food) {
512 /* Small chance of breaking */
513 object_remove(op);
514 object_free_drop_inventory(op);
515 return NULL;
516 }
517
518 op->direction = 0;
519 op->move_on = 0;
520 op->move_type = 0;
521 op->speed = 0;
522 object_update_speed(op);
523 op->stats.wc = op->stats.sp;
524 op->stats.dam = op->stats.hp;
525 op->attacktype = op->stats.grace;
526 if (op->slaying != NULL)
527 FREE_AND_CLEAR_STR(op->slaying);
528
529 if (op->skill != NULL)
530 FREE_AND_CLEAR_STR(op->skill);
531
532 if (op->spellarg != NULL) {
533 op->slaying = add_string(op->spellarg);
534 free(op->spellarg);
535 op->spellarg = NULL;
536 } else
537 op->slaying = NULL;
538
539 /* Reset these to zero, so that object_can_merge will work properly */
540 op->spellarg = NULL;
541 op->stats.sp = 0;
542 op->stats.hp = 0;
543 op->stats.grace = 0;
544 op->level = 0;
545 animate_object(op, 0);
546 object_clear_owner(op); /* So that stopped arrows will be saved */
547 object_update(op, UP_OBJ_FACE);
548 return op;
549 }
550
551 /**
552 * Check whether the given object is FLAG_NO_DROP. If so, (optionally) remove
553 * and free it.
554 *
555 * @param op
556 * the object to check
557 * @return
558 * whether the object was freed
559 */
560 int free_no_drop(object *op) {
561 if (!QUERY_FLAG(op, FLAG_NO_DROP)) {
562 return 0;
563 }
564
565 if (!QUERY_FLAG(op, FLAG_REMOVED)) {
566 object_remove(op);
567 }
568
569 object_free(op, FREE_OBJ_FREE_INVENTORY);
570 return 1;
571 }
572
573 /**
574 * Replaces op with its other_arch if it has reached its end of life.
575 *
576 * This routine doesnt seem to work for "inanimate" objects that
577 * are being carried, ie a held torch leaps from your hands!.
578 * Modified this routine to allow held objects. b.t.
579 *
580 * @param op
581 * object to change. Will be removed and replaced.
582 *
583 * @note Now handles multipart objects!
584 * If it fails to insert a multipart object, it re-inserts the original object.
585 * So, FLAG_FREED and FLAG_REMOVED will not be set in op if it is put back.
586 */
587 void change_object(object *op) {
588 object *env;
589 int i;
590 int friendly;
591 int unaggressive;
592 object *owner;
593
594 if (op->other_arch == NULL) {
595 LOG(llevError, "Change object (%s) without other_arch error.\n", op->name);
596 return;
597 }
598
599 /* In non-living items only change when food value is 0 */
600 if (!QUERY_FLAG(op, FLAG_ALIVE)) {
601 if (op->stats.food-- > 0)
602 return;
603 else
604 op->stats.food = 1; /* so 1 other_arch is made */
605 }
606
607 env = op->env;
608 object_remove(op);
609 friendly = QUERY_FLAG(op, FLAG_FRIENDLY);
610 unaggressive = QUERY_FLAG(op, FLAG_UNAGGRESSIVE);
611 owner = object_get_owner(op);
612 for (i = 0; i < op->stats.food; i++) {
613 object *tmp;
614
615 tmp = arch_to_object(op->other_arch);
616 if (op->type == LAMP)
617 tmp->stats.food = op->stats.food-1;
618 tmp->stats.hp = op->stats.hp;
619 if (friendly) {
620 SET_FLAG(tmp, FLAG_FRIENDLY);
621 add_friendly_object(tmp);
622 tmp->attack_movement = PETMOVE;
623 if (owner != NULL)
624 object_set_owner(tmp, owner);
625 }
626 if (unaggressive)
627 SET_FLAG(tmp, FLAG_UNAGGRESSIVE);
628 if (env) {
629 tmp->x = env->x,
630 tmp->y = env->y;
631 tmp = object_insert_in_ob(tmp, env);
632 }
633 // If there is more to the object, put in the map,
634 // then initiate the process of setting up multipartdom.
635 else if (tmp->arch->more)
636 {
637 tmp->map = op->map;
638 // Get the best free spot for the object
639 // Using the clone of the arch because I do not think that the actual object is ready yet.
640 if (object_find_multi_free_spot_around(&tmp->arch->clone, op, &tmp->x, &tmp->y) != 0)
641 {
642 LOG(llevInfo, "change_object: Failed to find a spot to put changing multipart object\n");
643 // Put the orignal object back.
644 object_insert_in_map(op, op->map, NULL, INS_NO_MERGE|INS_ABOVE_FLOOR_ONLY|INS_NO_WALK_ON);
645 // Free the failed object
646 object_free_drop_inventory(tmp);
647 // Bail out so we don't break things.
648 return;
649 }
650 object_insert_in_map(tmp, op->map, op, INS_NO_MERGE|INS_ABOVE_FLOOR_ONLY|INS_NO_WALK_ON);
651 object_fix_multipart(tmp);
652 }
653 else{
654 // Single-size objects work here.
655 object_insert_to_free_spot_or_free(tmp, op->map, op->x, op->y, 1, SIZEOFFREE1+1, op);
656 }
657 }
658 if (friendly)
659 remove_friendly_object(op);
660 object_free_drop_inventory(op);
661 }
662
663 /**
664 * Move for ::FIREWALL.
665 *
666 * firewalls fire other spells.
667 * The direction of the wall is stored in op->direction.
668 * walls can have hp, so they can be torn down.
669 *
670 * @param op
671 * firewall.
672 */
673 void move_firewall(object *op) {
674 object *spell;
675
676 if (!op->map)
677 return; /* dm has created a firewall in his inventory */
678
679 spell = op->inv;
680 if (!spell) {
681 LOG(llevError, "firewall '%s' in (%s, %d, %d) has no spell\n", op->name, op->map->path, op->x, op->y);
682 return;
683 }
684
685 cast_spell(op, op, op->direction ? op->direction : get_random_dir(), spell, NULL);
686 }
687
688
689 /**
690 * This function takes a ::PLAYERMOVER as an
691 * argument, and performs the function of a player mover, which is:
692 *
693 * a player mover finds any players that are sitting on it. It
694 * moves them in the op->stats.sp direction. speed is how often it'll move.
695 * - If attacktype is nonzero it will paralyze the player. If lifesave is set,
696 * - it'll dissapear after hp+1 moves. If hp is set and attacktype is set,
697 * - it'll paralyze the victim for hp*his speed/op->speed
698 *
699 * @param op
700 * mover.
701 */
702 void move_player_mover(object *op) {
703 int dir = op->stats.sp;
704 int16_t nx, ny;
705 mapstruct *m;
706
707 if (!op->map) {
708 if (op->env && op->env->map)
709 LOG(llevError, "move_player_mover: mover not in a map at %s %d %d!\n", op->env->map->path, op->env->x, op->env->y);
710 else
711 LOG(llevError, "move_player_mover: mover not in a map at undefinite location!");
712 op->speed = 0;
713 object_update_speed(op);
714 return;
715 }
716
717 /* Determine direction now for random movers so we do the right thing */
718 if (!dir)
719 dir = get_random_dir();
720
721 FOR_MAP_PREPARE(op->map, op->x, op->y, victim) {
722 if (QUERY_FLAG(victim, FLAG_ALIVE)
723 && !QUERY_FLAG(victim, FLAG_WIZPASS)
724 && (victim->move_type&op->move_type || !victim->move_type)) {
725 victim = HEAD(victim);
726
727 if (QUERY_FLAG(op, FLAG_LIFESAVE) && op->stats.hp-- < 0) {
728 object_remove(op);
729 object_free_drop_inventory(op);
730 return;
731 }
732 nx = op->x+freearr_x[dir];
733 ny = op->y+freearr_y[dir];
734 m = op->map;
735 if (get_map_flags(m, &m, nx, ny, &nx, &ny)&P_OUT_OF_MAP) {
736 LOG(llevError, "move_player_mover: Trying to push player off the map! map=%s (%d, %d)\n", m->path, op->x, op->y);
737 return;
738 }
739
740 if (should_director_abort(op, victim))
741 return;
742
743 FOR_MAP_PREPARE(m, nx, ny, nextmover) {
744 if (nextmover->type == PLAYERMOVER)
745 nextmover->speed_left = -.99;
746 if (QUERY_FLAG(nextmover, FLAG_ALIVE)) {
747 op->speed_left = -1.1; /* wait until the next thing gets out of the way */
748 }
749 } FOR_MAP_FINISH();
750
751 if (victim->type == PLAYER) {
752 /* only level >= 1 movers move people */
753 if (op->level) {
754 /* Following is a bit of hack. We need to make sure it
755 * is cleared, otherwise the player will get stuck in
756 * place. This can happen if the player used a spell to
757 * get to this space.
758 */
759 victim->contr->fire_on = 0;
760 victim->speed_left = -FABS(victim->speed);
761 move_player(victim, dir);
762 } else
763 return;
764 } else
765 move_object(victim, dir);
766
767 if (!op->stats.maxsp && op->attacktype)
768 op->stats.maxsp = 2.0;
769
770 if (op->attacktype) { /* flag to paralyze the player */
771 victim->speed_left = -FABS(op->stats.maxsp*victim->speed/op->speed);
772 /* Not sure why, but for some chars on metalforge, they
773 * would sometimes get -inf speed_left, and from the
774 * description, it could only happen here, so just put
775 * a lower sanity limit. My only guess is that the
776 * mover has 0 speed.
777 */
778 if (victim->speed_left < -5.0)
779 victim->speed_left = -5.0;
780 }
781 }
782 } FOR_MAP_FINISH();
783 }
784
785 /**
786 * Main object move function.
787 *
788 * @param op
789 * object to move.
790 * @return
791 * 0 if object didn't move, 1 else?
792 * @todo remove unused return value?
793 */
794 int process_object(object *op) {
795 if (QUERY_FLAG(op, FLAG_IS_A_TEMPLATE))
796 return 0;
797
798 /* Lauwenmark: Handle for plugin time event */
799 if (execute_event(op, EVENT_TIME, NULL, NULL, NULL, SCRIPT_FIX_NOTHING) != 0)
800 return 0;
801
802 if (QUERY_FLAG(op, FLAG_MONSTER))
803 if (monster_move(op) || QUERY_FLAG(op, FLAG_FREED))
804 return 1;
805
806 if ((QUERY_FLAG(op, FLAG_ANIMATE) && op->anim_speed == 0)
807 || (op->temp_animation && op->temp_anim_speed == 0)) {
808 op->state++;
809 if (op->type == PLAYER)
810 animate_object(op, op->facing);
811 else
812 animate_object(op, op->direction);
813
814 if (QUERY_FLAG(op, FLAG_SEE_ANYWHERE))
815 make_sure_seen(op);
816 }
817 if (QUERY_FLAG(op, FLAG_CHANGING) && !op->state) {
818 change_object(op);
819 return 1;
820 }
821 if (QUERY_FLAG(op, FLAG_GENERATOR) && !QUERY_FLAG(op, FLAG_FRIENDLY))
822 generate_monster(op);
823
824 /* If object can be used up, decrement 'food' and eventually remove it. */
825 if (QUERY_FLAG(op, FLAG_IS_USED_UP) && op->stats.food-- <= 0) {
826 if (QUERY_FLAG(op, FLAG_APPLIED)) {
827 remove_force(op);
828 } else {
829 if (op->env != NULL && op->env->type == PLAYER) {
830 sstring key;
831 key_value *used_up_message;
832
833 key = add_string("used_up_message");
834 used_up_message = object_get_key_value(op, key);
835 free_string(key);
836
837 if (used_up_message != NULL) {
838 draw_ext_info_format(
839 NDI_BLACK, 0, op->env, MSG_TYPE_ITEM, MSG_TYPE_ITEM_REMOVE,
840 "The %s %s.", op->name, used_up_message->value);
841 }
842 }
843
844 object_remove(op);
845 if (QUERY_FLAG(op, FLAG_SEE_ANYWHERE))
846 make_sure_not_seen(op);
847 object_free(op, FREE_OBJ_DROP_ABOVE_FLOOR);
848 }
849 return 1;
850 }
851 return (ob_process(op) == METHOD_OK ? 1 : 0);
852 }
853
854 void legacy_remove_force(object *op) {
855 remove_force(op);
856 }
857
858 void legacy_animate_trigger(object *op) {
859 animate_trigger(op);
860 }
861
862 void legacy_move_hole(object *op) {
863 move_hole(op);
864 }