void Populate() { worldContents.Clear(); float enemyDivision = 1.0f / enemies.Count; float floraDivision = 1.0f / flora.Count; float pickupDivision = 1.0f / pickups.Count; int numWaterTiles = cave.WaterSize(); int numFloorTiles = cave.FloorSize(); int tilesProcessed = 0; int tileSkip = 0; int numPickups = 0; for (int i = 0, c = 0; i < numWaterTiles && c < waterString.Length; i += tileSkip, ++c, tilesProcessed += tileSkip) { char tile = waterString[c]; float prob = Random.Range(0.0f, 1.0f); int index = 0; switch (charToObj[tile]) { case ObjType.ENEMY: index = Mathf.Min((int)(prob / enemyDivision), enemies.Count - 1); GameObject newEnemy = Instantiate(enemies[index]) as GameObject; newEnemy.transform.position = cave.GetWaterCoords(i); worldContents.Add(newEnemy); break; case ObjType.PICKUP: ++numPickups; index = Mathf.Min((int)(prob / pickupDivision), pickups.Count - 1); GameObject newPickup = Instantiate(pickups[index]) as GameObject; newPickup.transform.position = cave.GetWaterCoords(i); worldContents.Add(newPickup); break; } tileSkip = Random.Range(waterSkipMin, waterSkipMax + 1); } print("Water Tile Spec Surplus: " + (tilesProcessed - numWaterTiles)); FindObjectOfType <PlayerController>().SetNumTreasures(numPickups); tilesProcessed = 0; for (int i = 0, c = 0; i < numFloorTiles && c < floorString.Length; i += tileSkip, ++c, tilesProcessed += tileSkip) { char tile = floorString[c]; float prob = Random.Range(0.0f, 1.0f); int index = 0; switch (charToObj[tile]) { case ObjType.FLORA: index = Mathf.Min((int)(prob / floraDivision), flora.Count - 1); GameObject newFlora = Instantiate(flora[index]) as GameObject; newFlora.transform.position = cave.GetFloorCoords(i); cave.flora.Add(cave.GetTileCoords(newFlora.transform.position), newFlora); worldContents.Add(newFlora); break; } tileSkip = Random.Range(floorSkipMin, floorSkipMax + 1); } print("Floor Tile Spec Surplus: " + (tilesProcessed - numFloorTiles)); }