26 for (
int t = 0; (pathSize>>t); t++)
30 long x = (random()%
width)&(~pathSize);
31 long y = (random()%
height)&(~pathSize);
40 for (
int t = 0; t < pathWidth; t++)
51 for (
int t = 0; t < pathWidth; t++)
62 for (
int t = 0; t < pathWidth; t++)
73 for (
int t = 0; t < pathWidth; t++)
84 for (
int x = 0; x <
width; x++)
85 for (
int y = 0; y <
height; y++)
96 void MakeMaze(
Map *map,
int corridorWidth,
int startx,
int starty)
100 int boxSize = corridorWidth+1;
102 startx =
width/(2*boxSize);
104 startx = startx-startx%boxSize;
106 starty =
height/(2*boxSize);
108 starty = starty-starty%boxSize;
112 for (
int x = 0; x <
width; x+=boxSize)
114 for (
int y = 0; y <
height; y+=boxSize)
117 for (
int x = 0; x <
width; x+=boxSize)
118 for (
int y = 0; y <
height; y += boxSize)
132 bool lastRandom =
false;
136 if (lastRandom || (1 != random()%10))
144 val = ((random()%(3*x.size()/2))+x.size()/2)%x.size();
156 for (
int t = 0; t < boxSize-1; t++)
161 y.push_back(y[val]-1);
172 for (
int t = 0; t < boxSize-1; t++)
177 y.push_back(y[val]+1);
188 for (
int t = 0; t < boxSize-1; t++)
192 x.push_back(x[val]+1);
204 for (
int t = 0; t < boxSize-1; t++)
208 x.push_back(x[val]-1);
239 for (
int x = 0; x <
height; x += roomSize)
244 for (
int y = 0; y <
width; y += roomSize)
246 if ((random()%100) < openingProbability)
248 int val = roomSize/8;
251 for (
int z = 0; z < val; z++)
258 for (
int x = 0; x <
width; x += roomSize)
263 for (
int y = 0; y <
height; y += roomSize)
265 if ((random()%100) < openingProbability)
267 int val = roomSize/8;
270 for (
int z = 0; z < val; z++)
282 for (
int x = 0; x < total; x++)
302 dirs.push_back({l.
x-2, l.
y});
304 dirs.push_back({l.
x+2, l.
y});
306 dirs.push_back({l.
x, l.
y-2});
308 dirs.push_back({l.
x, l.
y+2});
310 if (dirs.size() != 1)
318 dirs.push_back({l.
x+2, l.
y});
320 dirs.push_back({l.
x-2, l.
y});
322 dirs.push_back({l.
x, l.
y+2});
324 dirs.push_back({l.
x, l.
y-2});
335 assert(branchPercent >= 0 && branchPercent <= 1 && straightPercent >= 0 && straightPercent <= 1);
339 std::vector<loc> places;
342 places.push_back({startx, starty});
344 std::vector<loc> straight;
345 std::vector<loc> all;
346 while (places.size() > 0)
349 int which = (int)random()%places.size();
351 which = places.size()-1;
353 loc currLoc = places[which];
354 places.erase(places.begin()+which);
359 if (straight.size() > 0 && (random()%10000) < 10000*straightPercent)
361 Burrow(m, currLoc, straight[0]);
362 places.push_back(straight[0]);
366 if ((random()%10000) < 10000*branchPercent)
368 while (all.size() > 2)
369 all.erase(all.begin()+random()%all.size());
372 while (all.size() > 1)
373 all.erase(all.begin()+random()%all.size());
378 places.push_back(next);
380 std::random_device rd;
381 std::mt19937 g(rd());
383 std::shuffle(places.begin(), places.end(), g);
388 Map *
MakeWarehouseMap(
int columns,
int rows,
int corridor,
int shelfWidth,
int shelfHeight,
int leftMargin,
int rightMargin)
390 int mapWidth = leftMargin+rightMargin+columns*shelfWidth+(columns-1)*corridor+2;
391 int mapHeight = rows*shelfHeight+(rows+1)*corridor+2;
392 Map *map =
new Map(mapWidth, mapHeight);
394 map->SetTerrainType(0, 0, 0, mapHeight-1,
kTrees);
395 map->SetTerrainType(mapWidth-1, 0, mapWidth-1, mapHeight-1,
kTrees);
396 map->SetTerrainType(0, mapHeight-1, mapWidth-1, mapHeight-1,
kTrees);
397 map->SetTerrainType(0, 0, mapWidth-1, 0,
kTrees);
399 for (
int x = 1+leftMargin; x+shelfWidth+rightMargin < mapWidth; x += shelfWidth+corridor)
401 for (
int y = 1+corridor; y+shelfHeight+corridor < mapHeight; y += shelfHeight+corridor)
403 map->SetRectHeight(x, y, x+shelfWidth-1, y+shelfHeight-1, 0,
kTrees);