Crossfire Server, Branches 1.12  R18729
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  if (trap->head)
78  trap = trap->head;
79 
80  /* Lauwenmark: Handle for plugin trigger event */
81  if (execute_event(trap, EVENT_TRIGGER, originator, victim, NULL, SCRIPT_FIX_ALL) != 0) {
83  return METHOD_ERROR;
84  }
85  return METHOD_OK;
86 }
87 
88 void common_post_ob_move_on(object *trap, object *victim, object *originator) {
90  if (ob_move_on_recursion_depth < 0) /* Safety net :) */
92 }
void common_post_ob_move_on(object *trap, object *victim, object *originator)
Definition: common_apply.c:88
#define METHOD_ERROR
Definition: ob_methods.h:44
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:450
char method_ret
Definition: ob_methods.h:41
#define METHOD_OK
Definition: ob_methods.h:42
const char * name
Definition: object.h:167
#define QUERY_FLAG(xyz, p)
Definition: define.h:514
#define EXIT
Definition: define.h:228
#define SIGN
Definition: define.h:280
#define CONTAINER
Definition: define.h:306
struct archt * arch
Definition: object.h:263
#define FLAG_APPLIED
Definition: define.h:531
int execute_event(object *op, int eventcode, object *activator, object *third, const char *message, int fix)
Definition: standalone.c:225
static int ob_move_on_recursion_depth
Definition: common_apply.c:49
struct obj * head
Definition: object.h:154
void LOG(LogLevel logLevel, const char *format,...)
Definition: logger.c:63
#define FLAG_WIZPASS
Definition: define.h:611
const char * name
Definition: object.h:322
#define EVENT_TRIGGER
Definition: plugin.h:71
uint8 type
Definition: object.h:189