예제 #1
0
        void drawDirty()
        {
            for (int x = 0; x < Bounds.X; x++)
            {
                for (int y = 0; y < Bounds.Y; y++)
                {
                    if (!UsedCells[x, y])
                    {
                        continue;
                    }

                    var isBorder = false;
                    if (info.Border > 0)
                    {
                        for (int bx = x - info.Border; bx <= x + info.Border; bx++)
                        {
                            if (bx < 0 || bx >= Bounds.X)
                            {
                                continue;
                            }

                            for (int by = y - info.Border; by <= y + info.Border; by++)
                            {
                                if (bx == x && by == y)
                                {
                                    continue;
                                }

                                if (by < 0 || by >= Bounds.Y)
                                {
                                    continue;
                                }

                                if (UsedCells[bx, by])
                                {
                                    continue;
                                }

                                if (Loader.CanAcquireCell(new MPos(bx, by), info.ID))
                                {
                                    Loader.SetTerrain(bx, by, info.BorderTerrain[Random.Next(info.BorderTerrain.Length)]);
                                }
                            }
                        }
                    }
                    else if (info.Border < 0)
                    {
                        for (int bx = info.Border; bx <= -info.Border; bx++)
                        {
                            if (isBorder)
                            {
                                break;
                            }

                            for (int by = info.Border; by <= -info.Border; by++)
                            {
                                if (bx == 0 && by == 0)
                                {
                                    continue;
                                }

                                var borderPos = new MPos(x + by, y + bx);

                                if (borderPos.X < 0 || borderPos.Y < 0)
                                {
                                    continue;
                                }
                                if (borderPos.X >= Bounds.X || borderPos.Y >= Bounds.Y)
                                {
                                    continue;
                                }

                                // Replace if there are not used cells nearby, thus inset the border.
                                if (!UsedCells[borderPos.X, borderPos.Y])
                                {
                                    Loader.SetTerrain(x, y, info.BorderTerrain[Random.Next(info.BorderTerrain.Length)]);
                                    isBorder = true;

                                    break;
                                }
                            }
                        }
                    }

                    if (isBorder)
                    {
                        continue;
                    }

                    var value  = noise[x, y];
                    var number = (int)Math.Floor(value * (info.Terrain.Length - 1));
                    Loader.SetTerrain(x, y, info.Terrain[number]);

                    if (info.SpawnActors != null)
                    {
                        foreach (var a in info.SpawnActors)
                        {
                            if (Random.NextDouble() <= a.Probability)
                            {
                                Loader.AddActor(new CPos(1024 * x + Random.Next(896) - 448, 1024 * y + Random.Next(896) - 448, 0), a);
                                break;                                 // If an actor is already spawned, we don't want any other actor to spawn because they will probably overlap
                            }
                        }
                    }
                }
            }
        }