Crossfire Server, Trunk  R20513
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  /* Lauwenmark: Handle for plugin trigger event */
80  if (execute_event(trap, EVENT_TRIGGER, originator, victim, NULL, SCRIPT_FIX_ALL) != 0) {
82  return METHOD_ERROR;
83  }
84  return METHOD_OK;
85 }
86 
87 void common_post_ob_move_on(object *trap, object *victim, object *originator) {
89  if (ob_move_on_recursion_depth < 0) /* Safety net :) */
91 }
Typedefs for ob_methods.
Definition: ob_methods.h:45
void common_post_ob_move_on(object *trap, object *victim, object *originator)
Definition: common_apply.c:87
#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)
&#39;victim&#39; moves onto &#39;trap&#39; &#39;victim&#39; leaves &#39;trap&#39; effect is determined by move_on/move_off of trap an...
Definition: common_apply.c:41
Global type definitions and header inclusions.
#define SCRIPT_FIX_ALL
Definition: global.h:361
char method_ret
Define some standard return values for callbacks which don&#39;t need to return any other results...
Definition: ob_methods.h:14
See Sign & Magic Mouth.
Definition: object.h:211
See Exit.
Definition: object.h:181
#define METHOD_OK
Definition: ob_methods.h:15
const char * name
The name of the object, obviously...
Definition: object.h:311
#define QUERY_FLAG(xyz, p)
Definition: define.h:225
#define HEAD(op)
Returns the head part of an object.
Definition: object.h:594
Object type variables.
See Container.
Definition: object.h:231
struct archt * arch
Pointer to archetype.
Definition: object.h:412
Only for debugging purposes.
Definition: logger.h:13
uint8_t type
PLAYER, BULLET, etc.
Definition: object.h:338
#define FLAG_APPLIED
Object is ready for use by living.
Definition: define.h:235
int execute_event(object *op, int eventcode, object *activator, object *third, const char *message, int fix)
Definition: main.c:364
static int ob_move_on_recursion_depth
Definition: common_apply.c:49
void LOG(LogLevel logLevel, const char *format,...)
Logs a message to stderr, or to file.
Definition: logger.c:51
#define FLAG_WIZPASS
The wizard can go through walls.
Definition: define.h:315
Object type functions and variables.
const char * name
More definite name, like "generate_kobold".
Definition: object.h:466
#define EVENT_TRIGGER
Button pushed, lever pulled, etc.
Definition: plugin.h:74