Crossfire Server, Branches 1.12  R18729
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 
34 static method_ret teleporter_type_process(ob_methods *context, object *op);
35 static method_ret teleporter_type_trigger(ob_methods *context, object *op, object *cause, int state);
36 
43 }
44 
51 static void move_teleporter(object *op) {
52  object *tmp, *head = op;
53 
54  /* if this is a multipart teleporter, handle the other parts
55  * The check for speed isn't strictly needed - basically, if
56  * there is an old multipart teleporter in which the other parts
57  * have speed, we don't really want to call it twice for the same
58  * function - in fact, as written below, part N would get called
59  * N times without the speed check.
60  */
61  if (op->more && FABS(op->more->speed) < MIN_ACTIVE_SPEED)
62  move_teleporter(op->more);
63 
64  if (op->head)
65  head = op->head;
66 
67  for (tmp = op->above; tmp != NULL; tmp = tmp->above)
68  if (!QUERY_FLAG(tmp, FLAG_IS_FLOOR))
69  break;
70 
71  /* If nothing above us to move, nothing to do */
72  if (!tmp || QUERY_FLAG(tmp, FLAG_WIZPASS))
73  return;
74 
75  if (EXIT_PATH(head)) {
76  if (tmp->type == PLAYER) {
77  /* Lauwenmark: Handle for plugin TRIGGER event */
78  if (execute_event(op, EVENT_TRIGGER, tmp, NULL, NULL, SCRIPT_FIX_ALL) != 0)
79  return;
80  enter_exit(tmp, head);
81  }
82  else
83  /* Currently only players can transfer maps */
84  return;
85  } else if (EXIT_X(head)||EXIT_Y(head)) {
86  if (out_of_map(head->map, EXIT_X(head), EXIT_Y(head))) {
87  LOG(llevError, "Removed illegal teleporter.\n");
88  remove_ob(head);
89  free_object(head);
90  return;
91  }
92  /* Lauwenmark: Handle for plugin TRIGGER event */
93  if (execute_event(op, EVENT_TRIGGER, tmp, NULL, NULL, SCRIPT_FIX_ALL) != 0)
94  return;
95  transfer_ob(tmp, EXIT_X(head), EXIT_Y(head), 0, head);
96  } else {
97  /* Random teleporter */
98  /* Lauwenmark: Handle for plugin TRIGGER event */
99  if (execute_event(op, EVENT_TRIGGER, tmp, NULL, NULL, SCRIPT_FIX_ALL) != 0)
100  return;
101  teleport(head, TELEPORTER, tmp);
102  }
103 }
104 
111 static method_ret teleporter_type_process(ob_methods *context, object *op) {
112  move_teleporter(op);
113  return METHOD_OK;
114 }
115 
124 static method_ret teleporter_type_trigger(ob_methods *context, object *op, object *cause, int state) {
125  move_teleporter(op);
126  return METHOD_OK;
127 }
#define FLAG_IS_FLOOR
Definition: define.h:599
int teleport(object *teleporter, uint8 tele_type, object *user)
Definition: move.c:244
void enter_exit(object *op, object *exit_ob)
Definition: server.c:740
#define TELEPORTER
Definition: define.h:155
#define FABS(x)
Definition: define.h:61
static method_ret teleporter_type_trigger(ob_methods *context, object *op, object *cause, int state)
Definition: teleporter.c:124
struct obj * above
Definition: object.h:146
#define SCRIPT_FIX_ALL
Definition: global.h:450
#define PLAYER
Definition: define.h:113
char method_ret
Definition: ob_methods.h:41
void remove_ob(object *op)
Definition: object.c:1515
#define METHOD_OK
Definition: ob_methods.h:42
struct mapdef * map
Definition: object.h:155
void init_type_teleporter(void)
Definition: teleporter.c:40
#define EXIT_PATH(xyz)
Definition: define.h:748
static method_ret teleporter_type_process(ob_methods *context, object *op)
Definition: teleporter.c:111
#define EXIT_X(xyz)
Definition: define.h:750
float speed
Definition: object.h:181
#define QUERY_FLAG(xyz, p)
Definition: define.h:514
#define EXIT_Y(xyz)
Definition: define.h:751
void register_trigger(int ob_type, trigger_func method)
Definition: ob_types.c:115
static void move_teleporter(object *op)
Definition: teleporter.c:51
int out_of_map(mapstruct *m, int x, int y)
Definition: map.c:2300
int execute_event(object *op, int eventcode, object *activator, object *third, const char *message, int fix)
Definition: standalone.c:225
void register_process(int ob_type, process_func method)
Definition: ob_types.c:88
#define MIN_ACTIVE_SPEED
Definition: define.h:1063
struct obj * head
Definition: object.h:154
void LOG(LogLevel logLevel, const char *format,...)
Definition: logger.c:63
int transfer_ob(object *op, int x, int y, int randomly, object *originator)
Definition: move.c:197
void free_object(object *ob)
Definition: object.c:1238
#define FLAG_WIZPASS
Definition: define.h:611
struct obj * more
Definition: object.h:153
#define EVENT_TRIGGER
Definition: plugin.h:71
uint8 type
Definition: object.h:189