| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
#include "global.h" |
| 19 |
|
| 20 |
#include <string.h> |
| 21 |
|
| 22 |
#include "ob_methods.h" |
| 23 |
#include "ob_types.h" |
| 24 |
#include "sounds.h" |
| 25 |
#include "sproto.h" |
| 26 |
|
| 27 |
static method_ret exit_type_move_on(ob_methods *context, object *trap, object *victim, object *originator); |
| 28 |
static method_ret exit_type_apply(ob_methods *context, object *exit, object *op, int autoapply); |
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
void init_type_exit(void) { |
| 34 |
register_move_on(EXIT, exit_type_move_on); |
| 35 |
register_apply(EXIT, exit_type_apply); |
| 36 |
} |
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
static method_ret exit_type_move_on(ob_methods *context, object *trap, object *victim, object *originator) { |
| 47 |
if (common_pre_ob_move_on(trap, victim, originator) == METHOD_ERROR) |
| 48 |
return METHOD_OK; |
| 49 |
if (victim->type == PLAYER && EXIT_PATH(trap)) { |
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
if (trap->msg |
| 54 |
&& strncmp(EXIT_PATH(trap), "/!", 2) |
| 55 |
&& strncmp(EXIT_PATH(trap), "/random/", 8)) |
| 56 |
draw_ext_info(NDI_NAVY, 0, victim, MSG_TYPE_APPLY, MSG_TYPE_APPLY_TRAP, trap->msg); |
| 57 |
enter_exit(victim, trap); |
| 58 |
} |
| 59 |
common_post_ob_move_on(trap, victim, originator); |
| 60 |
return METHOD_OK; |
| 61 |
} |
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
static int is_legal_2ways_exit(object *op, object *exit) { |
| 85 |
object *tmp; |
| 86 |
object *exit_owner; |
| 87 |
player *pp; |
| 88 |
mapstruct *exitmap; |
| 89 |
|
| 90 |
if (exit->stats.exp != 1) |
| 91 |
return 1; |
| 92 |
if (!has_been_loaded(EXIT_PATH(exit)) && exit->race) |
| 93 |
return 0; |
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
if (!strncmp(EXIT_PATH(exit), settings.localdir, strlen(settings.localdir))) |
| 98 |
exitmap = ready_map_name(EXIT_PATH(exit), MAP_PLAYER_UNIQUE); |
| 99 |
else |
| 100 |
exitmap = ready_map_name(EXIT_PATH(exit), 0); |
| 101 |
if (exitmap) { |
| 102 |
tmp = GET_MAP_OB(exitmap, EXIT_X(exit), EXIT_Y(exit)); |
| 103 |
if (!tmp) |
| 104 |
return 0; |
| 105 |
for ((tmp = GET_MAP_OB(exitmap, EXIT_X(exit), EXIT_Y(exit))); tmp; tmp = tmp->above) { |
| 106 |
if (tmp->type != EXIT) |
| 107 |
continue; |
| 108 |
if (!EXIT_PATH(tmp)) |
| 109 |
continue; |
| 110 |
if ((EXIT_X(tmp) != exit->x) || (EXIT_Y(tmp) != exit->y)) |
| 111 |
continue; |
| 112 |
if (strcmp(exit->map->path, EXIT_PATH(tmp)) != 0) |
| 113 |
continue; |
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
if (!exit->race) |
| 121 |
return 1; |
| 122 |
exit_owner = NULL; |
| 123 |
for (pp = first_player; pp; pp = pp->next) { |
| 124 |
if (!pp->ob) |
| 125 |
continue; |
| 126 |
if (pp->ob->name != exit->race) |
| 127 |
continue; |
| 128 |
exit_owner = pp->ob; |
| 129 |
break; |
| 130 |
} |
| 131 |
if (!exit_owner) |
| 132 |
return 0; |
| 133 |
if (exit_owner->contr == op->contr) |
| 134 |
return 1; |
| 135 |
if (exit_owner |
| 136 |
&& (op->contr) |
| 137 |
&& ((exit_owner->contr->party == NULL) |
| 138 |
|| (exit_owner->contr->party != op->contr->party))) |
| 139 |
return 0; |
| 140 |
return 1; |
| 141 |
} |
| 142 |
} |
| 143 |
return 0; |
| 144 |
} |
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
static method_ret exit_type_apply(ob_methods *context, object *exit, object *op, int autoapply) { |
| 155 |
if (op->type != PLAYER) |
| 156 |
return METHOD_ERROR; |
| 157 |
if (!EXIT_PATH(exit) || !is_legal_2ways_exit(op, exit)) { |
| 158 |
char name[MAX_BUF]; |
| 159 |
|
| 160 |
query_name(exit, name, MAX_BUF); |
| 161 |
draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_APPLY, MSG_TYPE_APPLY_FAILURE, |
| 162 |
"The %s is closed.", name); |
| 163 |
} else { |
| 164 |
|
| 165 |
if (exit->msg |
| 166 |
&& strncmp(EXIT_PATH(exit), "/!", 2) |
| 167 |
&& strncmp(EXIT_PATH(exit), "/random/", 8)) |
| 168 |
draw_ext_info(NDI_NAVY, 0, op, MSG_TYPE_APPLY, MSG_TYPE_APPLY_SUCCESS, exit->msg); |
| 169 |
enter_exit(op, exit); |
| 170 |
} |
| 171 |
return METHOD_OK; |
| 172 |
} |