Crossfire Server, Trunk
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(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  */
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) {
87  (void)trap;
88  (void)victim;
89  (void)originator;
91  if (ob_move_on_recursion_depth < 0) /* Safety net :) */
93 }
global.h
common_post_ob_move_on
void common_post_ob_move_on(object *trap, object *victim, object *originator)
Definition: common_apply.c:86
QUERY_FLAG
#define QUERY_FLAG(xyz, p)
Definition: define.h:226
METHOD_OK
#define METHOD_OK
Definition: ob_methods.h:15
common_pre_ob_move_on
method_ret common_pre_ob_move_on(object *trap, object *victim, object *originator)
Definition: common_apply.c:51
SIGN
@ SIGN
Definition: object.h:211
FLAG_APPLIED
#define FLAG_APPLIED
Definition: define.h:235
events_execute_object_event
int events_execute_object_event(object *op, int eventcode, object *activator, object *third, const char *message, int fix)
Definition: events.cpp:274
common_ob_move_on
method_ret common_ob_move_on(object *trap, object *victim, object *originator)
Definition: common_apply.c:41
obj::name
sstring name
Definition: object.h:314
EVENT_TRIGGER
#define EVENT_TRIGGER
Definition: events.h:33
HEAD
#define HEAD(op)
Definition: object.h:593
CONTAINER
@ CONTAINER
Definition: object.h:231
SCRIPT_FIX_ALL
#define SCRIPT_FIX_ALL
Definition: global.h:377
FLAG_WIZPASS
#define FLAG_WIZPASS
Definition: define.h:314
sproto.h
nlohmann::detail::void
j template void())
Definition: json.hpp:4099
EXIT
@ EXIT
Definition: object.h:181
obj::arch
struct archt * arch
Definition: object.h:417
method_ret
char method_ret
Definition: ob_methods.h:14
ob_types.h
obj::type
uint8_t type
Definition: object.h:343
reputation.victim
victim
Definition: reputation.py:14
LOG
void LOG(LogLevel logLevel, const char *format,...)
Definition: logger.c:51
ob_move_on_recursion_depth
static int ob_move_on_recursion_depth
Definition: common_apply.c:49
METHOD_ERROR
#define METHOD_ERROR
Definition: ob_methods.h:17
archt::name
sstring name
Definition: object.h:470
ob_methods.h
llevDebug
@ llevDebug
Definition: logger.h:13