Esempio n. 1
0
 public void UpdateUnderLandCase(LandCase underLandCase)
 {
     if (underLandCase != null)
     {
         this.underLandCaseData = new LandCaseData(underLandCase.LandWall != null, underLandCase.LandWater != null);
     }
 }
Esempio n. 2
0
 public void UpdateOverLandCase(LandCase overLandeCase)
 {
     if (overLandeCase != null)
     {
         this.overLandCaseData = new LandCaseData(overLandeCase.LandWall != null, overLandeCase.LandWater != null);
     }
 }
        public override int GenerateLandLayer(WorldGenerator worldGenerator, ILandChunk landChunk, IntRect area, int seed, int minAltitude, int maxAltitude)
        {
            ALandLayerGenerator groundLandLayerGenerator = worldGenerator.Generators["defaultGround"];

            ALandLayerGenerator altitudeLandLayerGenerator = worldGenerator.Generators["altitude"];

            ALandLayerGenerator cliffLandLayerGenerator = worldGenerator.Generators["cliff"];

            ALandLayerGenerator elementLandLayerGenerator = worldGenerator.Generators["element"];

            bool isThereSandElement = false;

            Random random = new Random(seed);

            for (int i = 0; i < area.Height; i++)
            {
                for (int j = 0; j < area.Width; j++)
                {
                    int altitude = altitudeLandLayerGenerator.GetComputedPowerAt(j, i);

                    int altitudeOffset = cliffLandLayerGenerator.GetComputedPowerAt(j, i);

                    int elementIndex = random.Next(0, 8);

                    int power = this.GetElementPower(elementLandLayerGenerator.GetComputedPowerAt(j, i));

                    LandType landType = (LandType)groundLandLayerGenerator.GetComputedPowerAt(j, i);

                    if (landType == LandType.SAND)
                    {
                        if (power >= 8 && random.Next(0, 3) > 0 && altitudeOffset == 0)
                        {
                            float trueAltitude = altitudeLandLayerGenerator.GetPowerAt(new SFML.System.Vector2f(area.Left + j, area.Top + i));

                            if ((elementIndex == 1 || elementIndex == 3) &&
                                trueAltitude > 0.6 && random.Next(0, 4) > 0)
                            {
                                elementIndex -= 1;
                            }

                            GroundElementLandObject groundElement = new GroundElementLandObject(area.Left + j, area.Top + i, altitude, landType, elementIndex);

                            LandCase landCase = landChunk.GetLandCase(i, j, altitude);

                            landCase.LandOverGround = groundElement;

                            isThereSandElement = true;
                        }
                    }
                }
            }

            if (isThereSandElement)
            {
                landChunk.AddTypeInChunk(typeof(GroundElementLandObject));
            }

            return(random.Next());
        }
Esempio n. 4
0
        public override int GenerateLandLayer(WorldGenerator worldGenerator, ILandChunk landChunk, IntRect area, int seed, int minAltitude, int maxAltitude)
        {
            ALandLayerGenerator grassLandLayerGenerator = worldGenerator.Generators["grass"];

            ALandLayerGenerator altitudeLandLayerGenerator = worldGenerator.Generators["altitude"];

            ALandLayerGenerator cliffLandLayerGenerator = worldGenerator.Generators["cliff"];

            ALandLayerGenerator elementLandLayerGenerator = worldGenerator.Generators["element"];

            bool isThereGrassElement = false;

            Random random = new Random(seed);

            for (int i = 0; i < area.Height; i++)
            {
                for (int j = 0; j < area.Width; j++)
                {
                    int altitude = altitudeLandLayerGenerator.GetComputedPowerAt(j, i);

                    int altitudeOffset = cliffLandLayerGenerator.GetComputedPowerAt(j, i);

                    int elementIndex = random.Next(0, 12);

                    int power = this.GetElementPower(elementLandLayerGenerator.GetComputedPowerAt(j, i));

                    GrassType grassType = (GrassType)grassLandLayerGenerator.GetComputedPowerAt(j, i);

                    if (power >= 2 && random.Next(0, 3) > 0 && altitudeOffset == 0 && grassType != GrassType.NONE)
                    {
                        GrassElementLandObject grassElement = new GrassElementLandObject(area.Left + j, area.Top + i, altitude, grassType, elementIndex);

                        LandCase landCase = landChunk.GetLandCase(i, j, altitude);

                        landCase.LandOverGround = grassElement;

                        isThereGrassElement = true;
                    }
                }
            }

            if (isThereGrassElement)
            {
                landChunk.AddTypeInChunk(typeof(GrassElementLandObject));
            }

            return(random.Next());
        }
Esempio n. 5
0
        public LandCase2D(LandWorld2D landWorld2D, LandCase landCase)
        {
            this.landGroundOverWallList = new List <ILandObject2D>();

            this.landWater = null;

            this.landOverWall = null;

            this.landWall = null;

            this.landOverGround = null;

            this.landGroundList = new List <ILandObject2D>();

            this.underLandCaseData = new LandCaseData(false, false);
            this.overLandCaseData  = new LandCaseData(false, false);

            foreach (ILandObject landGroundObject in landCase.LandGroundList)
            {
                ILandObject2D landObject2D = LandWorld2D.MappingObjectModelView[landGroundObject.GetType()].CreateObject2D(landWorld2D, landGroundObject) as ILandObject2D;

                this.landGroundList.Add(landObject2D);
            }

            if (landCase.LandOverGround != null)
            {
                ILandObject2D landObject2D = LandWorld2D.MappingObjectModelView[landCase.LandOverGround.GetType()].CreateObject2D(landWorld2D, landCase.LandOverGround) as ILandObject2D;

                this.landOverGround = landObject2D;
            }

            if (landCase.LandWall != null)
            {
                foreach (ILandObject landGroundOverWallObject in landCase.LandGroundOverWallList)
                {
                    ILandObject2D landObject2D = LandWorld2D.MappingObjectModelView[landGroundOverWallObject.GetType()].CreateObject2D(landWorld2D, landGroundOverWallObject) as ILandObject2D;

                    this.landGroundOverWallList.Add(landObject2D);
                }
            }

            if (landCase.LandWater != null)
            {
                ILandObject2D landObject2D = LandWorld2D.MappingObjectModelView[landCase.LandWater.GetType()].CreateObject2D(landWorld2D, landCase.LandWater) as ILandObject2D;

                this.landWater = landObject2D;
            }

            if (landCase.LandWall != null)
            {
                ILandObject2D landObject2D = LandWorld2D.MappingObjectModelView[landCase.LandWall.GetType()].CreateObject2D(landWorld2D, landCase.LandWall) as ILandObject2D;

                this.landWall = landObject2D;
            }

            if (landCase.LandWall != null)
            {
                if (landCase.LandOverWall != null)
                {
                    ILandObject2D landObject2D = LandWorld2D.MappingObjectModelView[landCase.LandOverWall.GetType()].CreateObject2D(landWorld2D, landCase.LandOverWall) as ILandObject2D;

                    this.landOverWall = landObject2D;
                }
            }
        }
Esempio n. 6
0
        public override IObject2D CreateObject2D(LandWorld2D landWorld2D, IObject obj)
        {
            LandCase landCase = obj as LandCase;

            return(new LandCase2D(landWorld2D, landCase));
        }
        public override int GenerateLandLayer(WorldGenerator worldGenerator, ILandChunk landChunk, IntRect area, int seed, int minAltitude, int maxAltitude)
        {
            ALandLayerGenerator mountainLandLayerGenerator = worldGenerator.Generators["mountain"];

            ALandLayerGenerator altitudeLandLayerGenerator = worldGenerator.Generators["altitude"];

            ALandLayerGenerator cliffLandLayerGenerator = worldGenerator.Generators["cliff"];

            ALandLayerGenerator elementLandLayerGenerator = worldGenerator.Generators["element"];

            bool isThereMountainElement = false;

            Random random = new Random(seed);

            for (int i = 0; i < area.Height; i++)
            {
                for (int j = 0; j < area.Width; j++)
                {
                    int altitude = altitudeLandLayerGenerator.GetComputedPowerAt(j, i);

                    int altitudeOffset = cliffLandLayerGenerator.GetComputedPowerAt(j, i);

                    int elementIndex = random.Next(0, 5);

                    int power = this.GetElementPower(elementLandLayerGenerator.GetComputedPowerAt(j, i));

                    MountainType mountainType = (MountainType)mountainLandLayerGenerator.GetComputedPowerAt(j, i);

                    if (mountainType == MountainType.PROJECTING)
                    {
                        if (elementIndex == 3 && random.Next(0, 3) > 0)
                        {
                            elementIndex = random.Next(0, 3);
                        }
                    }
                    else if (mountainType == MountainType.ROUGH)
                    {
                        if (elementIndex < 3 && random.Next(0, 3) > 0)
                        {
                            elementIndex = 3;
                        }
                    }

                    if (power >= 2 && random.Next(0, 3) > 0 && altitudeOffset == 0 && mountainType != MountainType.NONE)
                    {
                        MountainElementLandObject mountainElement = new MountainElementLandObject(area.Left + j, area.Top + i, altitude, mountainType, elementIndex);

                        LandCase landCase = landChunk.GetLandCase(i, j, altitude);

                        landCase.LandOverGround = mountainElement;

                        isThereMountainElement = true;
                    }
                }
            }

            if (isThereMountainElement)
            {
                landChunk.AddTypeInChunk(typeof(MountainElementLandObject));
            }

            return(random.Next());
        }
Esempio n. 8
0
        protected static void AssignGround(
            ILandChunk landChunk,
            int i, int j,
            int altitude, int altitudeOffset,
            ILandObject mainLandObject, ILandObject secondLandObject,
            bool onlyGround = false)
        {
            if (mainLandObject != null || secondLandObject != null)
            {
                if (altitudeOffset == 0)
                {
                    landChunk.InitializeLandCase(i, j, altitude);
                    LandCase landCase = landChunk.GetLandCase(i, j, altitude);

                    if (mainLandObject != null)
                    {
                        landCase.AddLandGround(mainLandObject);
                    }

                    if (secondLandObject != null)
                    {
                        landCase.AddLandGround(secondLandObject);
                    }
                }
                else
                {
                    for (int z = 0; z < altitudeOffset; z++)
                    {
                        landChunk.InitializeLandCase(i, j, altitude + z);
                        LandCase landCase = landChunk.GetLandCase(i, j, altitude + z);
                        //if (landCase == null)
                        //{
                        //    throw new Exception("if offset > 0, case must be already initialized thanks to CliffLayerGenerator !");
                        //}

                        if (mainLandObject != null)
                        {
                            ILandObject cloneMainObject = mainLandObject.Clone();
                            cloneMainObject.Altitude = altitude + z;

                            landCase.AddLandGround(cloneMainObject);
                        }

                        if (secondLandObject != null)
                        {
                            ILandObject cloneSecondObject = secondLandObject.Clone();
                            cloneSecondObject.Altitude = altitude + z;

                            landCase.AddLandGround(cloneSecondObject);
                        }

                        if (onlyGround == false && landCase.LandWall != null)
                        {
                            if (mainLandObject != null)
                            {
                                ILandObject cloneMainObject = mainLandObject.Clone(landCase.LandWall.LandTransition);
                                if (cloneMainObject != null)
                                {
                                    cloneMainObject.Altitude = altitude + z;

                                    landCase.AddLandGroundOverWall(cloneMainObject);
                                }
                            }

                            if (secondLandObject != null)
                            {
                                ILandObject cloneSecondObject = secondLandObject.Clone(landCase.LandWall.LandTransition);
                                if (cloneSecondObject != null)
                                {
                                    cloneSecondObject.Altitude = altitude + z;

                                    landCase.AddLandGroundOverWall(cloneSecondObject);
                                }
                            }
                        }
                    }
                }
            }
        }