void spawnRubble(Pos position, portraitType type) { int randomIndex; GameObject randomObject; switch (type) { case portraitType.orc: randomIndex = rng.Next(0, orcRubble.Length); randomObject = orcRubble[randomIndex]; break; case portraitType.undead: randomIndex = rng.Next(0, undeadRubble.Length); randomObject = undeadRubble[randomIndex]; break; default: randomIndex = rng.Next(0, folliageRubble.Length); randomObject = folliageRubble[randomIndex]; break; } allEnvironmentObject.Add(mapManager.instantiate_environment(randomObject, position, true)); }
public void spawnEnvironment() { for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { Pos position = new Pos(x, y); if (isValidPotraitSpawn(position)) { portraitType type = getRandomPortraitType(); spawnPortrait(position, type); } } } }
void spawnPortrait(Pos position, portraitType type) { int radius = rng.Next(minRadius, maxRadius); Pos startPos = new Pos(position.x - radius, position.y - radius); Pos endPos = new Pos(position.x + radius, position.y + radius); List <Pos> validPosList = getListOfValidPositions(startPos, endPos); List <Pos> rubblePosList = validPosList; int targetRubbleQuota = (int)(validPosList.Count * rubbleDensity); int targetStructureQuota = (int)(validPosList.Count * structureDensity); int targetObjectQuota = (int)(validPosList.Count * objectDensity); Pos spawnPos; int i, randomIndex, portraitMargin; if (validPosList.Count < minArea) { return; } if (validPosList.Count < smallArea) { type = portraitType.folliage; } for (i = targetRubbleQuota; i > 0; i--) { if (rubblePosList.Count <= 0) { break; } randomIndex = rng.Next(0, rubblePosList.Count); spawnPos = rubblePosList[randomIndex]; spawnRubble(spawnPos, type); rubblePosList.RemoveAt(randomIndex); } for (i = targetStructureQuota; i > 0; i--) { if (validPosList.Count <= 0) { break; } int attempt = validPosList.Count; do { randomIndex = rng.Next(0, validPosList.Count); spawnPos = validPosList[randomIndex]; attempt--; } while (!isValidStructureSpawn(spawnPos, validPosList, structureRadius) && attempt > 0); if (isValidStructureSpawn(spawnPos, validPosList, structureRadius)) { spawnStructure(spawnPos, type); validPosList.RemoveAt(randomIndex); } } for (i = targetObjectQuota; i > 0; i--) { if (validPosList.Count <= 0) { break; } randomIndex = rng.Next(0, validPosList.Count); spawnPos = validPosList[randomIndex]; spawnObject(spawnPos, type); validPosList.RemoveAt(randomIndex); } portraitMargin = rng.Next(minPortraitMargin, maxPortraitMargin); updatePaintedList(position, radius + portraitMargin); }