MCPcopy Create free account
hub / github.com/OpenFodder/openfodder / getRandomXYByFeatures

Method getRandomXYByFeatures

Source/Map/Random.cpp:192–237  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

190
191
192cPosition* cRandomMap::getRandomXYByFeatures(std::vector<eTerrainFeature> pFeatures, size_t pRadius, bool pIgnoreSprites) {
193 size_t Radius = pRadius * TILE_WIDTH_PIXELS;
194 cPosition* Position = new cPosition();
195
196 cPosition PosStart;
197 PosStart.mX = 16 + (pRadius + (mParams.mRandom.getu() % (mParams.mWidth - pRadius))) * TILE_WIDTH_PIXELS;
198 PosStart.mY = 16 + (pRadius + (mParams.mRandom.getu() % (mParams.mHeight - pRadius))) * TILE_HEIGHT_PIXELS;
199
200 // Move 1 tile each direction
201 for (Position->mY = PosStart.mY; Position->mY <= getHeightPixels(); Position->mY += 16) {
202 if (Position->mY != PosStart.mY)
203 PosStart.mX = Radius;
204
205 for (Position->mX = PosStart.mX; Position->mX <= getWidthPixels(); Position->mX += 16) {
206
207
208 if (!pIgnoreSprites) {
209 if (CheckRadiusSprites(Position, Radius))
210 continue;
211 }
212 // Check land for one of the features
213 if (CheckRadiusFeatures(pFeatures, Position, Radius))
214 return Position;
215 }
216 }
217
218 // Return to start of map
219 for (Position->mY = Radius; Position->mY < PosStart.mY; Position->mY += 8) {
220 for (Position->mX = Radius; Position->mX <= getWidthPixels(); Position->mX += 8) {
221
222 if (!pIgnoreSprites) {
223 if (CheckRadiusSprites(Position, Radius))
224 continue;
225 }
226 // Check land for one of the features
227 if (CheckRadiusFeatures(pFeatures, Position, Radius))
228 return Position;
229 }
230 }
231
232 // Fail
233 Position->mX = -1;
234 Position->mY = -1;
235
236 return Position;
237}
238
239cPosition* cRandomMap::getRandomXYByTerrainType(eTerrainFeature pType, size_t pRadius) {
240

Callers

nothing calls this directly

Calls 1

getuMethod · 0.80

Tested by

no test coverage detected