… | |
… | |
1991 | * customized, changed states, etc. |
1991 | * customized, changed states, etc. |
1992 | */ |
1992 | */ |
1993 | int |
1993 | int |
1994 | find_free_spot (const object *ob, maptile *m, int x, int y, int start, int stop) |
1994 | find_free_spot (const object *ob, maptile *m, int x, int y, int start, int stop) |
1995 | { |
1995 | { |
|
|
1996 | int altern[SIZEOFFREE]; |
1996 | int index = 0, flag; |
1997 | int index = 0, flag; |
1997 | int altern[SIZEOFFREE]; |
|
|
1998 | |
1998 | |
1999 | for (int i = start; i < stop; i++) |
1999 | for (int i = start; i < stop; i++) |
2000 | { |
2000 | { |
2001 | flag = ob_blocked (ob, m, x + freearr_x[i], y + freearr_y[i]); |
2001 | mapxy pos (m, x, y); pos.move (i); |
2002 | if (!flag) |
2002 | |
|
|
2003 | if (!pos.normalise ()) |
|
|
2004 | continue; |
|
|
2005 | |
|
|
2006 | mapspace &ms = *pos; |
|
|
2007 | |
|
|
2008 | if (ms.flags () & P_IS_ALIVE) |
|
|
2009 | continue; |
|
|
2010 | |
|
|
2011 | /* However, often |
|
|
2012 | * ob doesn't have any move type (when used to place exits) |
|
|
2013 | * so the AND operation in OB_TYPE_MOVE_BLOCK doesn't work. |
|
|
2014 | */ |
|
|
2015 | if (ob->move_type == 0 && ms.move_block != MOVE_ALL) |
|
|
2016 | { |
2003 | altern [index++] = i; |
2017 | altern [index++] = i; |
|
|
2018 | continue; |
|
|
2019 | } |
2004 | |
2020 | |
2005 | /* Basically, if we find a wall on a space, we cut down the search size. |
2021 | /* Basically, if we find a wall on a space, we cut down the search size. |
2006 | * In this way, we won't return spaces that are on another side of a wall. |
2022 | * In this way, we won't return spaces that are on another side of a wall. |
2007 | * This mostly work, but it cuts down the search size in all directions - |
2023 | * This mostly work, but it cuts down the search size in all directions - |
2008 | * if the space being examined only has a wall to the north and empty |
2024 | * if the space being examined only has a wall to the north and empty |
2009 | * spaces in all the other directions, this will reduce the search space |
2025 | * spaces in all the other directions, this will reduce the search space |
2010 | * to only the spaces immediately surrounding the target area, and |
2026 | * to only the spaces immediately surrounding the target area, and |
2011 | * won't look 2 spaces south of the target space. |
2027 | * won't look 2 spaces south of the target space. |
2012 | */ |
2028 | */ |
2013 | else if ((flag & P_NO_PASS) && maxfree[i] < stop) |
2029 | if (ms.move_block == MOVE_ALL && maxfree[i] < stop) |
|
|
2030 | { |
2014 | stop = maxfree[i]; |
2031 | stop = maxfree[i]; |
|
|
2032 | continue; |
|
|
2033 | } |
|
|
2034 | |
|
|
2035 | /* Note it is intentional that we check ob - the movement type of the |
|
|
2036 | * head of the object should correspond for the entire object. |
|
|
2037 | */ |
|
|
2038 | if (OB_TYPE_MOVE_BLOCK (ob, ms.move_block)) |
|
|
2039 | continue; |
|
|
2040 | |
|
|
2041 | altern [index++] = i; |
2015 | } |
2042 | } |
2016 | |
2043 | |
2017 | if (!index) |
2044 | if (!index) |
2018 | return -1; |
2045 | return -1; |
2019 | |
2046 | |
… | |
… | |
2028 | */ |
2055 | */ |
2029 | int |
2056 | int |
2030 | find_first_free_spot (const object *ob, maptile *m, int x, int y) |
2057 | find_first_free_spot (const object *ob, maptile *m, int x, int y) |
2031 | { |
2058 | { |
2032 | for (int i = 0; i < SIZEOFFREE; i++) |
2059 | for (int i = 0; i < SIZEOFFREE; i++) |
2033 | if (!ob_blocked (ob, m, x + freearr_x[i], y + freearr_y[i])) |
2060 | if (!ob->blocked (m, x + freearr_x[i], y + freearr_y[i])) |
2034 | return i; |
2061 | return i; |
2035 | |
2062 | |
2036 | return -1; |
2063 | return -1; |
2037 | } |
2064 | } |
2038 | |
2065 | |