MCPcopy Create free account
hub / github.com/NetHack/NetHack / finddpos

Function finddpos

src/mklev.c:146–205  ·  view source on GitHub ↗

find a valid door position at room edge. dir is the preferred edge of the room. if found, returns TRUE and the coordinate in cc */

Source from the content-addressed store, hash-verified

144 dir is the preferred edge of the room.
145 if found, returns TRUE and the coordinate in cc */
146staticfn boolean
147finddpos(coord *cc, int dir, struct mkroom *aroom)
148{
149 coordxy x, y;
150 coordxy x1, y1, x2, y2;
151 int tryct = 0;
152
153 switch (dir) {
154 case DIR_N:
155 x1 = aroom->lx;
156 x2 = aroom->hx;
157 y1 = aroom->ly - 1;
158 y2 = aroom->ly - 1;
159 break;
160 case DIR_S:
161 x1 = aroom->lx;
162 x2 = aroom->hx;
163 y1 = aroom->hy + 1;
164 y2 = aroom->hy + 1;
165 break;
166 case DIR_W:
167 x1 = aroom->lx - 1;
168 x2 = aroom->lx - 1;
169 y1 = aroom->ly;
170 y2 = aroom->hy;
171 break;
172 case DIR_E:
173 x1 = aroom->hx + 1;
174 x2 = aroom->hx + 1;
175 y1 = aroom->ly;
176 y2 = aroom->hy;
177 break;
178 default:
179 impossible("finddpos: illegal dir");
180 return FALSE;
181 }
182
183 /* try random points */
184 do {
185 x = (x2 - x1) ? rn1(x2 - x1 + 1, x1) : x1;
186 y = (y2 - y1) ? rn1(y2 - y1 + 1, y1) : y1;
187 if (finddpos_shift(&x, &y, dir, aroom))
188 goto gotit;
189 } while (++tryct < 20);
190
191 /* try all the points */
192 for (x = x1; x <= x2; x++)
193 for (y = y1; y <= y2; y++)
194 if (finddpos_shift(&x, &y, dir, aroom))
195 goto gotit;
196
197 /* cannot find something reasonable -- strange */
198 cc->x = x1;
199 cc->y = y1;
200 return FALSE;
201 gotit:
202 cc->x = x;
203 cc->y = y;

Callers 2

joinFunction · 0.85
place_nicheFunction · 0.85

Calls 2

finddpos_shiftFunction · 0.85
impossibleFunction · 0.70

Tested by

no test coverage detected