Crossfire Server, Trunk  R22047
common_apply.c
Go to the documentation of this file.
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 crossfire-devel@real-time.com
22 */
27 #include <global.h>
28 #include <ob_methods.h>
29 #include <ob_types.h>
30 #include <sproto.h>
31 
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 
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  }
77  trap = HEAD(trap);
78 
79  if (events_execute_object_event(trap, EVENT_TRIGGER, originator, victim, NULL, SCRIPT_FIX_ALL) != 0) {
81  return METHOD_ERROR;
82  }
83  return METHOD_OK;
84 }
85 
86 void common_post_ob_move_on(object *trap, object *victim, object *originator) {
88  if (ob_move_on_recursion_depth < 0) /* Safety net :) */
90 }
void common_post_ob_move_on(object *trap, object *victim, object *originator)
Definition: common_apply.c:86
#define METHOD_ERROR
Definition: ob_methods.h:17
method_ret common_pre_ob_move_on(object *trap, object *victim, object *originator)
Definition: common_apply.c:51
method_ret common_ob_move_on(ob_methods *context, object *trap, object *victim, object *originator)
Definition: common_apply.c:41
#define SCRIPT_FIX_ALL
Definition: global.h:370
char method_ret
Definition: ob_methods.h:14
#define METHOD_OK
Definition: ob_methods.h:15
#define QUERY_FLAG(xyz, p)
Definition: define.h:225
#define FLAG_APPLIED
Definition: define.h:235
static int ob_move_on_recursion_depth
Definition: common_apply.c:49
int events_execute_object_event(object *op, int eventcode, object *activator, object *third, const char *message, int fix)
Definition: events.cpp:259
void LOG(LogLevel logLevel, const char *format,...)
Definition: logger.c:51
#define EVENT_TRIGGER
Definition: events.h:33
#define FLAG_WIZPASS
Definition: define.h:315