Crossfire Server, Trunk
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(object *op);
36 static method_ret teleporter_type_trigger(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) {
97  return;
98  enter_exit(tmp, head);
99  }
100  else
101  /* Currently only players can transfer maps */
102  return;
103  } else if (EXIT_X(head) || EXIT_Y(head)) {
104  if (out_of_map(head->map, EXIT_X(head), EXIT_Y(head))) {
105  LOG(llevError, "Removed illegal teleporter.\n");
106  object_remove(head);
108  return;
109  }
111  return;
112  transfer_ob(tmp, EXIT_X(head), EXIT_Y(head), 0, head);
113  } else {
114  /* Random teleporter */
116  return;
117  teleport(head, TELEPORTER, tmp);
118  }
119 }
120 
128  return METHOD_OK;
129 }
130 
138 static method_ret teleporter_type_trigger(object *op, object *cause, int state) {
139  (void)cause;
140  (void)state;
142  return METHOD_OK;
143 }
PLAYER
@ PLAYER
Definition: object.h:107
global.h
object_remove
void object_remove(object *op)
Definition: object.c:1819
llevError
@ llevError
Definition: logger.h:11
FABS
#define FABS(x)
Definition: define.h:22
obj::map
struct mapdef * map
Definition: object.h:300
QUERY_FLAG
#define QUERY_FLAG(xyz, p)
Definition: define.h:226
register_process
void register_process(int ob_type, process_func method)
Definition: ob_types.c:71
out_of_map
int out_of_map(mapstruct *m, int x, int y)
Definition: map.c:2312
METHOD_OK
#define METHOD_OK
Definition: ob_methods.h:15
EXIT_PATH
#define EXIT_PATH(xyz)
Definition: define.h:439
init_type_teleporter
void init_type_teleporter(void)
Definition: teleporter.c:41
Ice.tmp
int tmp
Definition: Ice.py:207
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
FLAG_NO_PICK
#define FLAG_NO_PICK
Definition: define.h:239
move_teleporter
static void move_teleporter(object *op)
Definition: teleporter.c:52
teleport
int teleport(object *teleporter, uint8_t tele_type, object *user)
Definition: move.c:204
EVENT_TRIGGER
#define EVENT_TRIGGER
Definition: events.h:33
HEAD
#define HEAD(op)
Definition: object.h:593
SCRIPT_FIX_ALL
#define SCRIPT_FIX_ALL
Definition: global.h:377
teleporter_type_trigger
static method_ret teleporter_type_trigger(object *op, object *cause, int state)
Definition: teleporter.c:138
FLAG_WIZPASS
#define FLAG_WIZPASS
Definition: define.h:314
sproto.h
register_trigger
void register_trigger(int ob_type, trigger_func method)
Definition: ob_types.c:98
nlohmann::detail::void
j template void())
Definition: json.hpp:4099
FLAG_MONSTER
#define FLAG_MONSTER
Definition: define.h:245
EXIT_X
#define EXIT_X(xyz)
Definition: define.h:441
transfer_ob
int transfer_ob(object *op, int x, int y, int randomly, object *originator)
Definition: move.c:163
method_ret
char method_ret
Definition: ob_methods.h:14
ob_types.h
sounds.h
LOG
void LOG(LogLevel logLevel, const char *format,...)
Definition: logger.c:51
enter_exit
void enter_exit(object *op, object *exit_ob)
Definition: server.c:732
give.op
op
Definition: give.py:33
EXIT_Y
#define EXIT_Y(xyz)
Definition: define.h:442
MIN_ACTIVE_SPEED
#define MIN_ACTIVE_SPEED
Definition: define.h:639
object_free_drop_inventory
void object_free_drop_inventory(object *ob)
Definition: object.c:1546
quest.state
state
Definition: quest.py:13
teleporter_type_process
static method_ret teleporter_type_process(object *op)
Definition: teleporter.c:126
ob_methods.h
TELEPORTER
@ TELEPORTER
Definition: object.h:141
FLAG_IS_FLOOR
#define FLAG_IS_FLOOR
Definition: define.h:302