00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
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
00055
00056
00057
00058
00059
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
00072 if (!tmp || QUERY_FLAG(tmp, FLAG_WIZPASS))
00073 return;
00074
00075 if (EXIT_PATH(head)) {
00076 if (tmp->type == PLAYER) {
00077
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
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
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
00098
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 }