Crossfire Server, Trunk  R213250
teleporter.c
Go to the documentation of this file.
1 /*
2  CrossFire, A Multiplayer game for X-windows
3 
4  Copyright (C) 2008 Crossfire Development Team
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program; if not, write to the Free Software
18  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 
20  The authors can be reached via e-mail at crossfire-devel@real-time.com
21 */
22 
28 #include <global.h>
29 #include <ob_methods.h>
30 #include <ob_types.h>
31 #include <sounds.h>
32 #include <sproto.h>
33 #include <string.h>
34 
35 static method_ret teleporter_type_process(ob_methods *context, object *op);
36 static method_ret teleporter_type_trigger(ob_methods *context, object *op, object *cause, int state);
37 
44 }
45 
52 static void move_teleporter(object *op) {
53  object *tmp, *head;
54 
55  /* if this is a multipart teleporter, handle the other parts
56  * The check for speed isn't strictly needed - basically, if
57  * there is an old multipart teleporter in which the other parts
58  * have speed, we don't really want to call it twice for the same
59  * function - in fact, as written below, part N would get called
60  * N times without the speed check.
61  */
62  if (op->more && FABS(op->more->speed) < MIN_ACTIVE_SPEED)
63  move_teleporter(op->more);
64 
65  head = HEAD(op);
66  for (tmp = op->above; tmp != NULL; tmp = tmp->above) {
67  if (QUERY_FLAG(tmp, FLAG_IS_FLOOR)) continue; /* Ignore floors */
68  if (op->other_arch && strcmp(op->other_arch->name,tmp->name) != 0 ) continue; /* Ignore if other_arch doesn't match */
69  if (QUERY_FLAG(tmp, FLAG_WIZPASS)) continue; /* Don't teleport the DM */
70  /*
71  * Use the subtype as a bitmask to specify types of objects to *ignore*:
72  * 1 -- non-player
73  * 2 -- players
74  * 4 -- non-monster
75  * 8 -- monsters
76  * 16 -- no-pick objects
77  * ... -- add more as needed
78  *
79  * For most purposes, restricting players/non-players is the big win here.
80  * For objects, use the other_arch field to restrict it to the particular object.
81  */
82  if ( (op->subtype & 1) && tmp->type != PLAYER ) continue; /* If flagged for player only */
83  if ( (op->subtype & 2) && tmp->type == PLAYER ) continue; /* If flagged for non-player only */
84  if ( (op->subtype & 4) && !QUERY_FLAG(tmp, FLAG_MONSTER) ) continue; /* If flagged for monster only */
85  if ( (op->subtype & 8) && QUERY_FLAG(tmp, FLAG_MONSTER) ) continue; /* If flagged for non-monster only */
86  if ( (op->subtype & 16) && QUERY_FLAG(tmp, FLAG_NO_PICK) ) continue; /* If flagged skip non-pickupable objects */
87  /* ... */
88  break;
89  }
90 
91  /* If nothing above us to move, nothing to do */
92  if (!tmp) return;
93 
94  if (EXIT_PATH(head)) {
95  if (tmp->type == PLAYER) {
96  /* Lauwenmark: Handle for plugin TRIGGER event */
97  if (execute_event(op, EVENT_TRIGGER, tmp, NULL, NULL, SCRIPT_FIX_ALL) != 0)
98  return;
99  enter_exit(tmp, head);
100  }
101  else
102  /* Currently only players can transfer maps */
103  return;
104  } else if (EXIT_X(head) || EXIT_Y(head)) {
105  if (out_of_map(head->map, EXIT_X(head), EXIT_Y(head))) {
106  LOG(llevError, "Removed illegal teleporter.\n");
107  object_remove(head);
109  return;
110  }
111  /* Lauwenmark: Handle for plugin TRIGGER event */
112  if (execute_event(op, EVENT_TRIGGER, tmp, NULL, NULL, SCRIPT_FIX_ALL) != 0)
113  return;
114  transfer_ob(tmp, EXIT_X(head), EXIT_Y(head), 0, head);
115  } else {
116  /* Random teleporter */
117  /* Lauwenmark: Handle for plugin TRIGGER event */
118  if (execute_event(op, EVENT_TRIGGER, tmp, NULL, NULL, SCRIPT_FIX_ALL) != 0)
119  return;
120  teleport(head, TELEPORTER, tmp);
121  }
122 }
123 
130 static method_ret teleporter_type_process(ob_methods *context, object *op) {
131  move_teleporter(op);
132  return METHOD_OK;
133 }
134 
143 static method_ret teleporter_type_trigger(ob_methods *context, object *op, object *cause, int state) {
144  move_teleporter(op);
145  return METHOD_OK;
146 }
#define FLAG_IS_FLOOR
Definition: define.h:303
void enter_exit(object *op, object *exit_ob)
Definition: server.c:722
#define FABS(x)
Definition: define.h:22
static method_ret teleporter_type_trigger(ob_methods *context, object *op, object *cause, int state)
Definition: teleporter.c:143
uint8_t subtype
Definition: object.h:340
struct obj * above
Definition: object.h:288
#define SCRIPT_FIX_ALL
Definition: global.h:367
struct archt * other_arch
Definition: object.h:415
char method_ret
Definition: ob_methods.h:14
void object_free_drop_inventory(object *ob)
Definition: object.c:1389
#define METHOD_OK
Definition: ob_methods.h:15
struct mapdef * map
Definition: object.h:297
const char * name
Definition: object.h:311
void init_type_teleporter(void)
Definition: teleporter.c:41
#define EXIT_PATH(xyz)
Definition: define.h:455
static method_ret teleporter_type_process(ob_methods *context, object *op)
Definition: teleporter.c:130
int teleport(object *teleporter, uint8_t tele_type, object *user)
Definition: move.c:188
#define EXIT_X(xyz)
Definition: define.h:457
float speed
Definition: object.h:328
#define QUERY_FLAG(xyz, p)
Definition: define.h:225
#define HEAD(op)
Definition: object.h:594
#define EXIT_Y(xyz)
Definition: define.h:458
void register_trigger(int ob_type, trigger_func method)
Definition: ob_types.c:98
Definition: object.h:107
static void move_teleporter(object *op)
Definition: teleporter.c:52
uint8_t type
Definition: object.h:339
int out_of_map(mapstruct *m, int x, int y)
Definition: map.c:2313
int execute_event(object *op, int eventcode, object *activator, object *third, const char *message, int fix)
Definition: main.c:365
void register_process(int ob_type, process_func method)
Definition: ob_types.c:71
#define MIN_ACTIVE_SPEED
Definition: define.h:676
#define FLAG_MONSTER
Definition: define.h:245
void LOG(LogLevel logLevel, const char *format,...)
Definition: logger.c:51
int transfer_ob(object *op, int x, int y, int randomly, object *originator)
Definition: move.c:144
#define FLAG_NO_PICK
Definition: define.h:239
#define FLAG_WIZPASS
Definition: define.h:315
struct obj * more
Definition: object.h:295
const char * name
Definition: object.h:468
#define EVENT_TRIGGER
Definition: plugin.h:74
void object_remove(object *op)
Definition: object.c:1666