Crossfire Server, Trunk
teleporter.cpp
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:112
global.h
llevError
@ llevError
Definition: logger.h:11
FABS
#define FABS(x)
Definition: define.h:22
LOG
void LOG(LogLevel logLevel, const char *format,...)
Definition: logger.cpp:58
QUERY_FLAG
#define QUERY_FLAG(xyz, p)
Definition: define.h:226
METHOD_OK
#define METHOD_OK
Definition: ob_methods.h:15
EXIT_PATH
#define EXIT_PATH(xyz)
Definition: define.h:439
object::map
struct mapstruct * map
Definition: object.h:305
teleporter_type_trigger
static method_ret teleporter_type_trigger(object *op, object *cause, int state)
Definition: teleporter.cpp:138
Ice.tmp
int tmp
Definition: Ice.py:207
register_process
void register_process(int ob_type, process_func method)
Definition: ob_types.cpp:71
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:299
FLAG_NO_PICK
#define FLAG_NO_PICK
Definition: define.h:239
object_free_drop_inventory
void object_free_drop_inventory(object *ob)
Definition: object.cpp:1560
teleport
int teleport(object *teleporter, uint8_t tele_type, object *user)
Definition: move.cpp:204
teleporter_type_process
static method_ret teleporter_type_process(object *op)
Definition: teleporter.cpp:126
EVENT_TRIGGER
#define EVENT_TRIGGER
Definition: events.h:34
HEAD
#define HEAD(op)
Definition: object.h:607
init_type_teleporter
void init_type_teleporter(void)
Definition: teleporter.cpp:41
out_of_map
int out_of_map(mapstruct *m, int x, int y)
Definition: map.cpp:2293
SCRIPT_FIX_ALL
#define SCRIPT_FIX_ALL
Definition: global.h:389
FLAG_WIZPASS
#define FLAG_WIZPASS
Definition: define.h:314
sproto.h
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.cpp:163
register_trigger
void register_trigger(int ob_type, trigger_func method)
Definition: ob_types.cpp:98
method_ret
char method_ret
Definition: ob_methods.h:14
ob_types.h
sounds.h
enter_exit
void enter_exit(object *op, object *exit_ob)
Definition: server.cpp:727
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_remove
void object_remove(object *op)
Definition: object.cpp:1833
ob_methods.h
dragon.state
state
Definition: dragon.py:84
TELEPORTER
@ TELEPORTER
Definition: object.h:146
move_teleporter
static void move_teleporter(object *op)
Definition: teleporter.cpp:52
FLAG_IS_FLOOR
#define FLAG_IS_FLOOR
Definition: define.h:302