Debian Codegraph @

types/common/common_apply.c

raw symbols SCIP
1 /*
2 CrossFire, A Multiplayer game for X-windows
3
4 Copyright (C) 2007 Mark Wedel & Crossfire Development Team
5 Copyright (C) 1992 Frank Tore Johansen
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20
21 The authors can be reached via e-mail at [email protected]
22 */
23 /** @file common_apply.c
24 * This file contains apply-related methods that are common to many
25 * classes of objects.
26 */
27 #include <global.h>
28 #include <ob_methods.h>
29 #include <ob_types.h>
30 #include <sproto.h>
31
32 /**
33 * 'victim' moves onto 'trap'
34 * 'victim' leaves 'trap'
35 * effect is determined by move_on/move_off of trap and move_type of victim.
36 *
37 * originator: Player, monster or other object that caused 'victim' to move
38 * onto 'trap'. Will receive messages caused by this action. May be NULL.
39 * However, some types of traps require an originator to function.
40 */
41 method_ret common_ob_move_on(ob_methods *context, object *trap, object *victim, object *originator) {
42 if (common_pre_ob_move_on(trap, victim, originator) == METHOD_ERROR)
43 return METHOD_OK;
44 LOG(llevDebug, "name %s, arch %s, type %d with fly/walk on/off not handled in move_apply()\n", trap->name, trap->arch->name, trap->type);
45 common_post_ob_move_on(trap, victim, originator);
46 return METHOD_OK;
47 }
48
49 static int ob_move_on_recursion_depth = 0;
50
51 method_ret common_pre_ob_move_on(object *trap, object *victim, object *originator) {
52 /* If player is DM, only 2 cases to consider:
53 * - exits
54 * - opened containers on the ground, which should be closed.
55 */
56 if (QUERY_FLAG(victim, FLAG_WIZPASS)
57 && trap->type != EXIT
58 && trap->type != SIGN
59 && trap->type != CONTAINER
60 && !QUERY_FLAG(trap, FLAG_APPLIED))
61 return METHOD_ERROR;
62
63 /* common_ob_move_on() is the most likely candidate for causing unwanted and
64 * possibly unlimited recursion.
65 */
66 /* The following was changed because it was causing perfectly correct
67 * maps to fail. 1) it's not an error to recurse:
68 * rune detonates, summoning monster. monster lands on nearby rune.
69 * nearby rune detonates. This sort of recursion is expected and
70 * proper. This code was causing needless crashes.
71 */
72 if (ob_move_on_recursion_depth >= 500) {
73 LOG(llevDebug, "WARNING: move_apply(): aborting recursion [trap arch %s, name %s; victim arch %s, name %s]\n", trap->arch->name, trap->name, victim->arch->name, victim->name);
74 return METHOD_ERROR;
75 }
76 ob_move_on_recursion_depth++;
77 trap = HEAD(trap);
78
79 /* Lauwenmark: Handle for plugin trigger event */
80 if (execute_event(trap, EVENT_TRIGGER, originator, victim, NULL, SCRIPT_FIX_ALL) != 0) {
81 ob_move_on_recursion_depth--;
82 return METHOD_ERROR;
83 }
84 return METHOD_OK;
85 }
86
87 void common_post_ob_move_on(object *trap, object *victim, object *originator) {
88 ob_move_on_recursion_depth--;
89 if (ob_move_on_recursion_depth < 0) /* Safety net :) */
90 ob_move_on_recursion_depth = 0;
91 }