… | |
… | |
2057 | * there is capable of. |
2057 | * there is capable of. |
2058 | */ |
2058 | */ |
2059 | int |
2059 | int |
2060 | find_dir (maptile *m, int x, int y, object *exclude) |
2060 | find_dir (maptile *m, int x, int y, object *exclude) |
2061 | { |
2061 | { |
2062 | int i, max = SIZEOFFREE, mflags; |
2062 | int max = SIZEOFFREE, mflags; |
2063 | |
|
|
2064 | sint16 nx, ny; |
|
|
2065 | object *tmp; |
|
|
2066 | maptile *mp; |
|
|
2067 | |
|
|
2068 | MoveType blocked, move_type; |
2063 | MoveType move_type; |
2069 | |
2064 | |
2070 | if (exclude && exclude->head_ () != exclude) |
2065 | if (exclude && exclude->head_ () != exclude) |
2071 | { |
2066 | { |
2072 | exclude = exclude->head; |
2067 | exclude = exclude->head; |
2073 | move_type = exclude->move_type; |
2068 | move_type = exclude->move_type; |
… | |
… | |
2076 | { |
2071 | { |
2077 | /* If we don't have anything, presume it can use all movement types. */ |
2072 | /* If we don't have anything, presume it can use all movement types. */ |
2078 | move_type = MOVE_ALL; |
2073 | move_type = MOVE_ALL; |
2079 | } |
2074 | } |
2080 | |
2075 | |
2081 | for (i = 1; i < max; i++) |
2076 | for (int i = 1; i < max; i++) |
2082 | { |
2077 | { |
2083 | mp = m; |
2078 | mapxy pos (m, x, y); |
2084 | nx = x + freearr_x[i]; |
2079 | pos.move (i); |
2085 | ny = y + freearr_y[i]; |
|
|
2086 | |
2080 | |
2087 | mflags = get_map_flags (m, &mp, nx, ny, &nx, &ny); |
2081 | if (!pos.normalise ()) |
2088 | |
|
|
2089 | if (mflags & P_OUT_OF_MAP) |
|
|
2090 | max = maxfree[i]; |
2082 | max = maxfree[i]; |
2091 | else |
2083 | else |
2092 | { |
2084 | { |
2093 | mapspace &ms = mp->at (nx, ny); |
2085 | mapspace &ms = *pos; |
2094 | |
2086 | |
2095 | blocked = ms.move_block; |
|
|
2096 | |
|
|
2097 | if ((move_type & blocked) == move_type) |
2087 | if ((move_type & ms.move_block) == move_type) |
2098 | max = maxfree[i]; |
2088 | max = maxfree [i]; |
2099 | else if (mflags & P_IS_ALIVE) |
2089 | else if (ms.flags () & P_IS_ALIVE) |
2100 | { |
2090 | { |
2101 | for (tmp = ms.bot; tmp; tmp = tmp->above) |
2091 | for (object *tmp = ms.bot; tmp; tmp = tmp->above) |
2102 | if ((tmp->flag [FLAG_MONSTER] || tmp->is_player ()) |
2092 | if ((tmp->flag [FLAG_MONSTER] || tmp->is_player ()) |
2103 | && (tmp != exclude || (tmp->head_ () != tmp && tmp->head_ () != exclude))) |
2093 | && (tmp != exclude || (tmp->head_ () != tmp && tmp->head_ () != exclude))) |
2104 | break; |
|
|
2105 | |
|
|
2106 | if (tmp) |
|
|
2107 | return freedir[i]; |
2094 | return freedir [i]; |
2108 | } |
2095 | } |
2109 | } |
2096 | } |
2110 | } |
2097 | } |
2111 | |
2098 | |
2112 | return 0; |
2099 | return 0; |