Crossfire Server, Trunk  R20513
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;
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  head = HEAD(op);
65  for (tmp = op->above; tmp != NULL; tmp = tmp->above)
66  if (!QUERY_FLAG(tmp, FLAG_IS_FLOOR))
67  break;
68 
69  /* If nothing above us to move, nothing to do */
70  if (!tmp || QUERY_FLAG(tmp, FLAG_WIZPASS))
71  return;
72 
73  if (EXIT_PATH(head)) {
74  if (tmp->type == PLAYER) {
75  /* Lauwenmark: Handle for plugin TRIGGER event */
76  if (execute_event(op, EVENT_TRIGGER, tmp, NULL, NULL, SCRIPT_FIX_ALL) != 0)
77  return;
78  enter_exit(tmp, head);
79  }
80  else
81  /* Currently only players can transfer maps */
82  return;
83  } else if (EXIT_X(head) || EXIT_Y(head)) {
84  if (out_of_map(head->map, EXIT_X(head), EXIT_Y(head))) {
85  LOG(llevError, "Removed illegal teleporter.\n");
86  object_remove(head);
88  return;
89  }
90  /* Lauwenmark: Handle for plugin TRIGGER event */
91  if (execute_event(op, EVENT_TRIGGER, tmp, NULL, NULL, SCRIPT_FIX_ALL) != 0)
92  return;
93  transfer_ob(tmp, EXIT_X(head), EXIT_Y(head), 0, head);
94  } else {
95  /* Random teleporter */
96  /* Lauwenmark: Handle for plugin TRIGGER event */
97  if (execute_event(op, EVENT_TRIGGER, tmp, NULL, NULL, SCRIPT_FIX_ALL) != 0)
98  return;
99  teleport(head, TELEPORTER, tmp);
100  }
101 }
102 
109 static method_ret teleporter_type_process(ob_methods *context, object *op) {
110  move_teleporter(op);
111  return METHOD_OK;
112 }
113 
122 static method_ret teleporter_type_trigger(ob_methods *context, object *op, object *cause, int state) {
123  move_teleporter(op);
124  return METHOD_OK;
125 }
Error, serious thing.
Definition: logger.h:11
Sound-related defines.
#define FLAG_IS_FLOOR
Can&#39;t see what&#39;s underneath this object.
Definition: define.h:303
void enter_exit(object *op, object *exit_ob)
Tries to move &#39;op&#39; to exit_ob.
Definition: server.c:706
Typedefs for ob_methods.
Definition: ob_methods.h:45
#define FABS(x)
Decstations have trouble with fabs()...
Definition: define.h:22
static method_ret teleporter_type_trigger(ob_methods *context, object *op, object *cause, int state)
A teleporter is triggered.
Definition: teleporter.c:122
struct obj * above
Pointer to the object stacked above this one.
Definition: object.h:288
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
void object_free_drop_inventory(object *ob)
Frees everything allocated by an object, removes it from the list of used objects, and puts it on the list of free objects.
Definition: object.c:1368
#define METHOD_OK
Definition: ob_methods.h:15
struct mapdef * map
Pointer to the map in which this object is present.
Definition: object.h:297
void init_type_teleporter(void)
Initializer for the teleporter object type.
Definition: teleporter.c:40
#define EXIT_PATH(xyz)
Definition: define.h:455
static method_ret teleporter_type_process(ob_methods *context, object *op)
Processes a teleporter.
Definition: teleporter.c:109
int teleport(object *teleporter, uint8_t tele_type, object *user)
Teleport an item around a nearby random teleporter of specified type.
Definition: move.c:188
#define EXIT_X(xyz)
Definition: define.h:457
float speed
The overall speed of this object.
Definition: object.h:328
#define QUERY_FLAG(xyz, p)
Definition: define.h:225
#define HEAD(op)
Returns the head part of an object.
Definition: object.h:594
#define EXIT_Y(xyz)
Definition: define.h:458
void register_trigger(int ob_type, trigger_func method)
Registers the trigger method for the given type.
Definition: ob_types.c:98
Object type variables.
See Player.
Definition: object.h:107
static void move_teleporter(object *op)
Move function for teleporter objects.
Definition: teleporter.c:51
uint8_t type
PLAYER, BULLET, etc.
Definition: object.h:338
int out_of_map(mapstruct *m, int x, int y)
this returns TRUE if the coordinates (x,y) are out of map m.
Definition: map.c:2294
int execute_event(object *op, int eventcode, object *activator, object *third, const char *message, int fix)
Definition: main.c:364
void register_process(int ob_type, process_func method)
Registers the process method for the given type.
Definition: ob_types.c:71
#define MIN_ACTIVE_SPEED
Cut off point of when an object is put on the active list or not.
Definition: define.h:674
void LOG(LogLevel logLevel, const char *format,...)
Logs a message to stderr, or to file.
Definition: logger.c:51
int transfer_ob(object *op, int x, int y, int randomly, object *originator)
Move an object (even linked objects) to another spot on the same map.
Definition: move.c:144
#define FLAG_WIZPASS
The wizard can go through walls.
Definition: define.h:315
Object type functions and variables.
struct obj * more
Pointer to the rest of a large body of objects.
Definition: object.h:295
See Teleporter.
Definition: object.h:141
#define EVENT_TRIGGER
Button pushed, lever pulled, etc.
Definition: plugin.h:74
void object_remove(object *op)
This function removes the object op from the linked list of objects which it is currently tied to...
Definition: object.c:1654