Crossfire Server, Branch 1.12
R12190
|
00001 /* 00002 CrossFire, A Multiplayer game for X-windows 00003 00004 Copyright (C) 2008 Crossfire Development Team 00005 00006 This program is free software; you can redistribute it and/or modify 00007 it under the terms of the GNU General Public License as published by 00008 the Free Software Foundation; either version 2 of the License, or 00009 (at your option) any later version. 00010 00011 This program is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 GNU General Public License for more details. 00015 00016 You should have received a copy of the GNU General Public License 00017 along with this program; if not, write to the Free Software 00018 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00019 00020 The authors can be reached via e-mail at crossfire-devel@real-time.com 00021 */ 00022 00028 #include <global.h> 00029 #include <ob_methods.h> 00030 #include <ob_types.h> 00031 #include <sounds.h> 00032 #include <sproto.h> 00033 00034 static method_ret teleporter_type_process(ob_methods *context, object *op); 00035 static method_ret teleporter_type_trigger(ob_methods *context, object *op, object *cause, int state); 00036 00040 void init_type_teleporter(void) { 00041 register_process(TELEPORTER, teleporter_type_process); 00042 register_trigger(TELEPORTER, teleporter_type_trigger); 00043 } 00044 00051 static void move_teleporter(object *op) { 00052 object *tmp, *head = op; 00053 00054 /* if this is a multipart teleporter, handle the other parts 00055 * The check for speed isn't strictly needed - basically, if 00056 * there is an old multipart teleporter in which the other parts 00057 * have speed, we don't really want to call it twice for the same 00058 * function - in fact, as written below, part N would get called 00059 * N times without the speed check. 00060 */ 00061 if (op->more && FABS(op->more->speed) < MIN_ACTIVE_SPEED) 00062 move_teleporter(op->more); 00063 00064 if (op->head) 00065 head = op->head; 00066 00067 for (tmp = op->above; tmp != NULL; tmp = tmp->above) 00068 if (!QUERY_FLAG(tmp, FLAG_IS_FLOOR)) 00069 break; 00070 00071 /* If nothing above us to move, nothing to do */ 00072 if (!tmp || QUERY_FLAG(tmp, FLAG_WIZPASS)) 00073 return; 00074 00075 if (EXIT_PATH(head)) { 00076 if (tmp->type == PLAYER) { 00077 /* Lauwenmark: Handle for plugin TRIGGER event */ 00078 if (execute_event(op, EVENT_TRIGGER, tmp, NULL, NULL, SCRIPT_FIX_ALL) != 0) 00079 return; 00080 enter_exit(tmp, head); 00081 } 00082 else 00083 /* Currently only players can transfer maps */ 00084 return; 00085 } else if (EXIT_X(head)||EXIT_Y(head)) { 00086 if (out_of_map(head->map, EXIT_X(head), EXIT_Y(head))) { 00087 LOG(llevError, "Removed illegal teleporter.\n"); 00088 remove_ob(head); 00089 free_object(head); 00090 return; 00091 } 00092 /* Lauwenmark: Handle for plugin TRIGGER event */ 00093 if (execute_event(op, EVENT_TRIGGER, tmp, NULL, NULL, SCRIPT_FIX_ALL) != 0) 00094 return; 00095 transfer_ob(tmp, EXIT_X(head), EXIT_Y(head), 0, head); 00096 } else { 00097 /* Random teleporter */ 00098 /* Lauwenmark: Handle for plugin TRIGGER event */ 00099 if (execute_event(op, EVENT_TRIGGER, tmp, NULL, NULL, SCRIPT_FIX_ALL) != 0) 00100 return; 00101 teleport(head, TELEPORTER, tmp); 00102 } 00103 } 00104 00111 static method_ret teleporter_type_process(ob_methods *context, object *op) { 00112 move_teleporter(op); 00113 return METHOD_OK; 00114 } 00115 00124 static method_ret teleporter_type_trigger(ob_methods *context, object *op, object *cause, int state) { 00125 move_teleporter(op); 00126 return METHOD_OK; 00127 }