Esempio n. 1
0
        public override void AutoTileArea(ReRandom rand, Loc rectStart, Loc rectSize, PlacementMethod placementMethod, QueryMethod queryMethod)
        {
            int[][] pass1Array = new int[rectSize.X][];
            for (int ii = 0; ii < rectSize.X; ii++)
            {
                pass1Array[ii] = new int[rectSize.Y];
                for (int jj = 0; jj < rectSize.Y; jj++)
                {
                    pass1Array[ii][jj] = -1;
                }
            }

            for (int x = 0; x < rectSize.X; x++)
            {
                for (int y = 0; y < rectSize.Y; y++)
                {
                    int neighborCode = -1;
                    if (queryMethod(rectStart.X + x, rectStart.Y + y))
                    {
                        neighborCode = textureBlock(rectStart.X + x, rectStart.Y + y, queryMethod);
                    }

                    if (neighborCode != -1)
                    {
                        placementMethod(rectStart.X + x, rectStart.Y + y, GetTile(rand, neighborCode));
                    }
                }
            }
        }
Esempio n. 2
0
        protected List <TileLayer> SelectTileLayers(ReRandom rand, List <List <TileLayer> > anims)
        {
            List <TileLayer> returnLayers = new List <TileLayer>();

            if (anims.Count > 0)
            {
                int index = 0;
                for (int ii = 0; ii < anims.Count - 1; ii++)
                {
                    if (rand.Next() % 2 == 0)
                    {
                        index++;
                    }
                    else
                    {
                        break;
                    }
                }
                foreach (TileLayer anim in anims[index])
                {
                    returnLayers.Add(new TileLayer(anim));
                }
            }
            return(returnLayers);
        }
Esempio n. 3
0
        public IEnumerator <YieldInstruction> BeginRescue(string sosPath)
        {
            SOSMail sos = (SOSMail)DataManager.LoadRescueMail(sosPath);

            //specify seed with a random byte, verify goals work in all cases
            sos.RescueSeed = (byte)(MathUtils.Rand.NextUInt64() % byte.MaxValue);
            ReRandom rerand = new ReRandom(sos.Seed);

            for (int ii = 0; ii < sos.RescueSeed; ii++)
            {
                rerand.NextUInt64();
            }


            yield return(CoroutineManager.Instance.StartCoroutine(BeginGame(sos.Goal.ID, rerand.NextUInt64(), GameProgress.DungeonStakes.Risk, true, false)));

            //set a rescuing boolean so that rescuability is disabled
            //must also set a goal variable somewhere
            //actually, just save the entire SOS mail somewhere as the current SOS
            DataManager.Instance.Save.Rescue = new RescueState(sos, true);
            //this is after saving the fail file, but before saving the first state of the replay
            yield return(CoroutineManager.Instance.StartCoroutine(BeginSegment(new ZoneLoc(sos.Goal.ID, new SegLoc(0, 0)))));


            //must also set script variables for dungeon if they matter
            //when this mission ends, all scripts must move the player back to the rescue start location...
            //if the mission was a success, the replay must be packaged into an AOK mail
        }
Esempio n. 4
0
        public override void AutoTileArea(ulong randSeed, Loc rectStart, Loc rectSize, Loc totalSize, PlacementMethod placementMethod, QueryMethod presenceMethod, QueryMethod queryMethod)
        {
            ReRandom rand = new ReRandom(randSeed);

            for (int xx = 0; xx < rectStart.X + rectSize.X; xx++)
            {
                int yy = 0;
                for (; yy < rectStart.Y + rectSize.Y; yy++)
                {
                    ulong subSeed = rand.NextUInt64();
                    if (xx >= rectStart.X && yy >= rectStart.Y)
                    {
                        if (Collision.InBounds(totalSize.X, totalSize.Y, new Loc(xx, yy)) && presenceMethod(xx, yy))
                        {
                            placementMethod(xx, yy, GetVariantCode(new ReRandom(subSeed), 0));
                        }
                    }
                }
                while (yy < totalSize.Y)
                {
                    rand.NextUInt64();
                    yy++;
                }
            }
        }
Esempio n. 5
0
        private void loadAOK(string aokPath, AOKMail aok)
        {
            //cut to black and verify the mail behind the scenes
            //If the replay succeeds, set the rescue state to true and take them back to the title.

            //check the AOK mail
            ReRandom rerand = new ReRandom(aok.Seed);

            for (int ii = 0; ii < aok.RescueSeed; ii++)
            {
                rerand.NextUInt64();
            }
            ulong rolledSeed = rerand.NextUInt64();

            if (aok.RescueReplay.States[0].Save.Rand.FirstSeed == rolledSeed)
            {
                //when starting, we must persist the AOK data so we know what data to put into the SOS
                //and the path so we know which path to delete if we fail to verify.
                //let's store it in this menu
                //when the replay ends, it will look for this menu and inject the result: pass, or fail
                testingPath = aokPath;
                testingMail = aok;

                TitleScene.TitleMenuSaveState = MenuManager.Instance.SaveMenuState();
                MenuManager.Instance.ClearMenus();
                GameManager.Instance.SceneOutcome = validateReplay(aok.RescueReplay);
            }
            else
            {
                File.Delete(aokPath);
                MenuManager.Instance.AddMenu(MenuManager.Instance.CreateDialogue(MenuManager.Instance.RemoveMenu, Text.FormatKey("DLG_AWAIT_RESCUE_AOK_FAIL")), true);
            }
        }
Esempio n. 6
0
        public override void AutoTileArea(ReRandom rand, Loc rectStart, Loc rectSize, PlacementMethod placementMethod, QueryMethod queryMethod)
        {
            int[][] mainArray = new int[rectSize.X + 2][];
            for (int ii = 0; ii < rectSize.X + 2; ii++)
            {
                mainArray[ii] = new int[rectSize.Y + 2];
                for (int jj = 0; jj < rectSize.Y + 2; jj++)
                {
                    mainArray[ii][jj] = -1;
                }
            }
            int[][] looseArray = new int[rectSize.X][];
            for (int ii = 0; ii < rectSize.X; ii++)
            {
                looseArray[ii] = new int[rectSize.Y];
                for (int jj = 0; jj < rectSize.Y; jj++)
                {
                    looseArray[ii][jj] = -1;
                }
            }

            for (int x = 0; x < rectSize.X + 2; x++)
            {
                for (int y = 0; y < rectSize.Y + 2; y++)
                {
                    if (queryMethod(rectStart.X + x - 1, rectStart.Y + y - 1))
                    {
                        textureMainBlock(mainArray, rectStart, rectStart.X + x - 1, rectStart.Y + y - 1, queryMethod);
                    }
                }
            }

            for (int x = 0; x < rectSize.X; x++)
            {
                for (int y = 0; y < rectSize.Y; y++)
                {
                    if (queryMethod(rectStart.X + x, rectStart.Y + y) && mainArray[x + 1][y + 1] == -1)
                    {
                        textureLooseBlock(looseArray, mainArray, rectStart, rectStart.X + x, rectStart.Y + y, queryMethod);
                    }
                }
            }

            for (int ii = 0; ii < rectSize.X; ii++)
            {
                for (int jj = 0; jj < rectSize.Y; jj++)
                {
                    int neighborCode = mainArray[ii + 1][jj + 1];
                    if (looseArray[ii][jj] != -1)
                    {
                        neighborCode = looseArray[ii][jj];
                    }

                    if (neighborCode != -1)
                    {
                        placementMethod(rectStart.X + ii, rectStart.Y + jj, GetTile(rand, neighborCode));
                    }
                }
            }
        }
Esempio n. 7
0
        public void RandRangeCanPick0()
        {
            var testPicker = RandRange.Empty;
            var rand       = new ReRandom(0);

            Assert.That(testPicker.CanPick, Is.EqualTo(true));
            Assert.That(testPicker.Pick(rand), Is.EqualTo(0));
        }
        protected MoneySpawnZoneStep(MoneySpawnZoneStep other, ulong seed) : this()
        {
            StartAmount = other.StartAmount;
            AddAmount   = other.AddAmount;
            Priority    = other.Priority;

            ReRandom rand = new ReRandom(seed);

            chosenStart = StartAmount.Pick(rand);
            chosenAdd   = AddAmount.Pick(rand);
        }
Esempio n. 9
0
        public BaseMap()
        {
            rand        = new ReRandom(0);
            EntryPoints = new List <LocRay8>();

            Layers = new List <MapLayer>();

            Items     = new List <MapItem>();
            MapTeams  = new List <Team>();
            AllyTeams = new List <Team>();
        }
Esempio n. 10
0
        public void RestartLogs(ulong seed)
        {
            StartDate  = String.Format("{0:yyyy-MM-dd_HH-mm-ss}", DateTime.Now);
            TotalTurns = 0;
            EndDate    = "";
            Location   = "";
            Trail      = new List <string>();

            Rand = new ReRandom(seed);//reseed own random
            DataManager.Instance.MsgLog.Clear();
        }
Esempio n. 11
0
 public GameAction GetAction(Character controlledChar, ReRandom rand, bool preThink)
 {
     try
     {
         return(GetNextMove(controlledChar, preThink, rand));
     }
     catch (Exception ex)
     {
         DiagManager.Instance.LogError(new Exception("AI Error\n", ex));
     }
     return(new GameAction(GameAction.ActionType.Wait, Dir8.None));
 }
Esempio n. 12
0
        public Map GetMap(SegLoc id)
        {
            if (!maps.ContainsKey(id))
            {
                //NOTE: with the way this is currently done, the random numbers used by the maps end up being related to the random numbers used by the postprocs
                //not that anyone would really notice...
                ReRandom totalRand = new ReRandom(rand.FirstSeed);
                for (int ii = 0; ii < id.Segment; ii++)
                {
                    totalRand.NextUInt64();
                }
                ulong structSeed = totalRand.NextUInt64();
                DiagManager.Instance.LogInfo("Struct Seed: " + structSeed);
                ReRandom structRand = new ReRandom(structSeed);
                for (int ii = 0; ii < id.ID; ii++)
                {
                    structRand.NextUInt64();
                }

                ulong mapSeed = structRand.NextUInt64();

                //load the struct context if it isn't present yet
                if (!structureContexts.ContainsKey(id.Segment))
                {
                    ReRandom       initRand   = new ReRandom(structSeed);
                    ZoneGenContext newContext = new ZoneGenContext();
                    newContext.CurrentZone    = zoneIndex;
                    newContext.CurrentSegment = id.Segment;
                    foreach (ZonePostProc zoneStep in Structures[id.Segment].PostProcessingSteps)
                    {
                        //TODO: find a better way to feed ZonePostProcs into full structures.
                        //Is there a way for them to be stateless?
                        //Additionally, the ZonePostProcs themselves sometimes hold IGenSteps that are copied over to the layouts.
                        //Is that really OK? (I would guess yes because there is no chance by design for them to be mutated when generating...)
                        ZonePostProc newStep = zoneStep.Instantiate(initRand.NextUInt64());
                        newContext.ZoneSteps.Add(newStep);
                    }
                    structureContexts[id.Segment] = newContext;
                }
                ZoneGenContext zoneContext = structureContexts[id.Segment];
                zoneContext.CurrentID = id.ID;
                zoneContext.Seed      = mapSeed;

                //TODO: remove the need for this explicit cast
                //make a parameterized version of zonestructure and then make zonestructure itself put in basemapgencontext as the parameter
                Map map = ((BaseMapGenContext)Structures[id.Segment].GetMap(zoneContext)).Map;

                //uncomment this to cache the state of every map after its generation.  it's not nice on memory though...
                //maps.Add(id, map);
                return(map);
            }
            return(maps[id]);
        }
Esempio n. 13
0
        private List <TileLayer> GetTile(ReRandom rand)
        {
            List <TileLayer> tileList = new List <TileLayer>();

            tileList.Add(new TileLayer(SelectTile(rand, Ground)));
            if (Variations.Count > 0)
            {
                tileList.Add(new TileLayer(SelectTile(rand, Variations)));
            }

            return(tileList);
        }
Esempio n. 14
0
 public override void AutoTileArea(ReRandom rand, Loc rectStart, Loc rectSize, PlacementMethod placementMethod, QueryMethod queryMethod)
 {
     for (int ii = 0; ii < rectSize.X; ii++)
     {
         for (int jj = 0; jj < rectSize.Y; jj++)
         {
             if (queryMethod(rectStart.X + ii, rectStart.Y + jj))
             {
                 placementMethod(rectStart.X + ii, rectStart.Y + jj, GetTile(rand));
             }
         }
     }
 }
Esempio n. 15
0
        public GameAction GetNextMove(Character controlledChar, bool preThink, ReRandom rand)
        {
            foreach (BasePlan plan in Plans)
            {
                GameAction result = AttemptPlan(controlledChar, plan, preThink, rand);
                if (result != null)
                {
                    return(result);
                }
            }

            currentPlan = null;
            return(new GameAction(GameAction.ActionType.Wait, Dir8.None));
        }
Esempio n. 16
0
        public override void AutoTileArea(ulong randSeed, Loc rectStart, Loc rectSize, Loc totalSize, PlacementMethod placementMethod, QueryMethod presenceMethod, QueryMethod queryMethod)
        {
            int[][] mainArray = new int[rectSize.X][];
            for (int ii = 0; ii < rectSize.X; ii++)
            {
                mainArray[ii] = new int[rectSize.Y];
                for (int jj = 0; jj < rectSize.Y; jj++)
                {
                    mainArray[ii][jj] = -1;
                }
            }

            for (int xx = 0; xx < rectSize.X; xx++)
            {
                for (int yy = 0; yy < rectSize.Y; yy++)
                {
                    if (Collision.InBounds(totalSize.X, totalSize.Y, new Loc(rectStart.X + xx, rectStart.Y + yy)) && presenceMethod(rectStart.X + xx, rectStart.Y + yy))
                    {
                        textureMainBlock(mainArray, rectStart, rectStart.X + xx, rectStart.Y + yy, queryMethod);
                    }
                }
            }

            ReRandom rand = new ReRandom(randSeed);

            //rand next is called for every tile up to the rectangle involved
            //there exists a jump function for rand, but not for arbitrary length
            //if the rand function changes to allow it, change this code block to jump directly to the correct values.
            for (int xx = 0; xx < rectStart.X + rectSize.X; xx++)
            {
                int yy = 0;
                for (; yy < rectStart.Y + rectSize.Y; yy++)
                {
                    ulong subSeed = rand.NextUInt64();
                    if (xx >= rectStart.X && yy >= rectStart.Y)
                    {
                        int neighborCode = mainArray[xx - rectStart.X][yy - rectStart.Y];
                        if (neighborCode != -1)
                        {
                            placementMethod(xx, yy, GetVariantCode(new ReRandom(subSeed), neighborCode));
                        }
                    }
                }
                while (yy < totalSize.Y)
                {
                    rand.NextUInt64();
                    yy++;
                }
            }
        }
Esempio n. 17
0
        public Character CreatePlayer(ReRandom rand, MonsterID form, int level, int intrinsic, int personality)
        {
            MonsterID   formData = form;
            MonsterData dex      = DataManager.Instance.GetMonster(formData.Species);

            CharData character = new CharData();

            character.BaseForm = formData;
            character.Level    = level;

            BaseMonsterForm formEntry = dex.Forms[formData.Form];

            List <int> final_skills = formEntry.RollLatestSkills(character.Level, new List <int>());

            for (int ii = 0; ii < final_skills.Count; ii++)
            {
                character.BaseSkills[ii] = new SlotSkill(final_skills[ii]);
            }

            if (form.Gender == Gender.Unknown)
            {
                character.BaseForm.Gender = dex.Forms[formData.Form].RollGender(rand);
            }

            if (intrinsic == -1)
            {
                character.BaseIntrinsics[0] = formEntry.RollIntrinsic(rand, 2);
            }
            else
            {
                character.BaseIntrinsics[0] = intrinsic;
            }

            if (personality == -1)
            {
                character.Discriminator = rand.Next();
            }
            else
            {
                character.Discriminator = personality;
            }


            character.OriginalUUID = DataManager.Instance.Save.UUID;
            character.OriginalTeam = DataManager.Instance.Save.ActiveTeam.Name;
            character.MetAt        = Text.FormatKey("MET_AT_START");

            return(CreatePlayer(character));
        }
Esempio n. 18
0
        public void ProposeSizeStats()
        {
            ReRandom rand = new ReRandom(0);

            Console.WriteLine(string.Format("Dims\tMin%\t10Pct%\tMed%\tMax%"));
            for (int xx = 3; xx < 21; xx++)
            {
                for (int yy = 3; yy <= xx; yy++)
                {
                    RoomGenCave <ITiledGenContext> roomGen = new RoomGenCave <ITiledGenContext>(new RandRange(xx, xx + 3), new RandRange(yy, yy + 3));

                    List <int> rolledW = new List <int>();
                    List <int> rolledH = new List <int>();
                    List <int> rolledA = new List <int>();
                    for (int ii = 0; ii < 1000; ii++)
                    {
                        Loc size = roomGen.ProposeSize(rand);
                        rolledW.Add(size.X);
                        rolledH.Add(size.Y);
                        rolledA.Add(size.X * size.Y);
                    }

                    rolledW.Sort();
                    rolledH.Sort();
                    rolledA.Sort();

                    // Console.WriteLine(String.Format("Orig Size: {0}x{1}", xx, yy));
                    // Console.WriteLine(String.Format("Height Min: {0}    10pct: {1}    25pct: {2}    Med: {3}    Max: {4}", rolledH[0], rolledH[rolledH.Count / 10], rolledH[rolledH.Count / 4], rolledH[rolledH.Count / 2], rolledH[rolledH.Count - 1]));
                    // Console.WriteLine(String.Format("Width Min: {0}    10pct: {1}    25pct: {2}    Med: {3}    Max: {4}", rolledW[0], rolledW[rolledW.Count / 10], rolledW[rolledW.Count / 4], rolledW[rolledW.Count / 2], rolledW[rolledW.Count - 1]));
                    // Console.WriteLine(String.Format(
                    //    "Area% Min: {0}%    10pct: {1}%    25pct: {2}%    Med: {3}%    Max: {4}%",
                    //    rolledA[0] * 100 / (xx * yy),
                    //    rolledA[rolledA.Count / 10] * 100 / (xx * yy),
                    //    rolledA[rolledA.Count / 4] * 100 / (xx * yy),
                    //    rolledA[rolledA.Count / 2] * 100 / (xx * yy),
                    //    rolledA[rolledA.Count - 1] * 100 / (xx * yy)));
                    Console.WriteLine(string.Format(
                                          "{0}x{1}\t{2}\t{3}\t{4}\t{5}",
                                          xx,
                                          yy,
                                          rolledA[0] * 1000 / (xx * yy),
                                          rolledA[rolledA.Count / 10] * 1000 / (xx * yy),
                                          rolledA[rolledA.Count / 2] * 1000 / (xx * yy),
                                          rolledA[rolledA.Count - 1] * 1000 / (xx * yy)));
                }
            }
        }
Esempio n. 19
0
        protected int SelectTileVariant(ReRandom rand, int count)
        {
            int index = 0;

            for (int ii = 0; ii < count - 1; ii++)
            {
                if (rand.Next() % 2 == 0)
                {
                    index++;
                }
                else
                {
                    break;
                }
            }
            return(index);
        }
Esempio n. 20
0
        protected SpreadPlanSpaced(SpreadPlanSpaced other, ulong seed) : base(other, seed)
        {
            FloorSpacing = other.FloorSpacing;
            FloorRange   = other.FloorRange;

            ReRandom rand = new ReRandom(seed);

            dropPoints = new HashSet <int>();

            int currentFloor = FloorRange.Min;

            currentFloor += rand.Next(FloorSpacing.Max);

            while (currentFloor < FloorRange.Max)
            {
                dropPoints.Add(currentFloor);
                currentFloor += FloorSpacing.Pick(rand);
            }
        }
Esempio n. 21
0
        public override void AutoTileArea(ReRandom rand, Loc rectStart, Loc rectSize, PlacementMethod placementMethod, QueryMethod queryMethod)
        {
            for (int ii = 0; ii < rectSize.X; ii++)
            {
                for (int jj = 0; jj < rectSize.Y; jj++)
                {
                    int neighborCode = -1;
                    if (queryMethod(ii + rectStart.X, jj + rectStart.Y))
                    {
                        neighborCode = textureWaterTile(ii + rectStart.X, jj + rectStart.Y, queryMethod);
                    }

                    if (neighborCode != -1)
                    {
                        placementMethod(rectStart.X + ii, rectStart.Y + jj, GetTile(rand, neighborCode));
                    }
                }
            }
        }
Esempio n. 22
0
 protected TileLayer SelectTile(ReRandom rand, List <TileLayer> anims)
 {
     if (anims.Count > 0)
     {
         int index = 0;
         for (int ii = 0; ii < anims.Count - 1; ii++)
         {
             if (rand.Next() % 2 == 0)
             {
                 index++;
             }
             else
             {
                 break;
             }
         }
         return(anims[index]);
     }
     return(new TileLayer());
 }
Esempio n. 23
0
        public override void AutoTileArea(ulong randSeed, Loc rectStart, Loc rectSize, Loc totalSize, PlacementMethod placementMethod, QueryMethod presenceMethod, QueryMethod queryMethod)
        {
            int[][] pass1Array = new int[rectSize.X][];
            for (int ii = 0; ii < rectSize.X; ii++)
            {
                pass1Array[ii] = new int[rectSize.Y];
                for (int jj = 0; jj < rectSize.Y; jj++)
                {
                    pass1Array[ii][jj] = -1;
                }
            }

            ReRandom rand = new ReRandom(randSeed);

            for (int xx = 0; xx < rectStart.X + rectSize.X; xx++)
            {
                int yy = 0;
                for (; yy < rectStart.Y + rectSize.Y; yy++)
                {
                    ulong subSeed = rand.NextUInt64();
                    if (xx >= rectStart.X && yy >= rectStart.Y)
                    {
                        int neighborCode = -1;
                        if (Collision.InBounds(totalSize.X, totalSize.Y, new Loc(xx, yy)) && presenceMethod(xx, yy))
                        {
                            neighborCode = textureBlock(xx, yy, queryMethod);
                        }

                        if (neighborCode != -1)
                        {
                            placementMethod(xx, yy, GetVariantCode(new ReRandom(subSeed), neighborCode));
                        }
                    }
                }
                while (yy < totalSize.Y)
                {
                    rand.NextUInt64();
                    yy++;
                }
            }
        }
Esempio n. 24
0
        public GroundMap()
        {
            AssetName    = "";
            rand         = new ReRandom(0);
            ScriptEvents = new Dictionary <LuaEngine.EMapCallbacks, ScriptEvent>();

            Entities = new List <EntityLayer>();

            Status = new Dictionary <int, MapStatus>();

            Background = new MapBG();
            BlankBG    = new AutoTile();

            Name    = new LocalText();
            Comment = "";
            Music   = "";

            Layers = new List <MapLayer>();

            Decorations = new List <AnimLayer>();
        }
Esempio n. 25
0
        protected SpreadPlanQuota(SpreadPlanQuota other, ulong seed) : base(other, seed)
        {
            Quota = other.Quota;

            ReRandom rand         = new ReRandom(seed);
            int      chosenAmount = Quota.Pick(rand);

            dropPoints = new HashSet <int>();

            List <int> availableFloors = new List <int>();

            for (int ii = FloorRange.Min; ii < FloorRange.Max; ii++)
            {
                availableFloors.Add(ii);
            }

            while (availableFloors.Count > 0 && dropPoints.Count < chosenAmount)
            {
                int chosenIndex = rand.Next(availableFloors.Count);
                dropPoints.Add(availableFloors[chosenIndex]);
                availableFloors.RemoveAt(chosenIndex);
            }
        }
Esempio n. 26
0
        public Zone(ulong seed, int zoneIndex)
        {
            DiagManager.Instance.LogInfo("Zone Seed: " + seed);
            rand = new ReRandom(seed);

            this.ID = zoneIndex;
            Name    = new LocalText();

            CurrentMapID = SegLoc.Invalid;

            Level       = -1;
            TeamSize    = -1;
            BagRestrict = -1;
            BagSize     = -1;

            structureContexts = new Dictionary <int, ZoneGenContext>();
            maps     = new Dictionary <SegLoc, Map>();
            Segments = new List <ZoneSegmentBase>();

            CarryOver = new List <MapStatus>();

            ScriptEvents = new Dictionary <LuaEngine.EZoneCallbacks, ScriptEvent>();
        }
        public override void AutoTileArea(ulong randSeed, Loc rectStart, Loc rectSize, Loc totalSize, PlacementMethod placementMethod, QueryMethod presenceMethod, QueryMethod queryMethod)
        {
            int[][] mainArray = new int[rectSize.X + 2][];
            for (int ii = 0; ii < rectSize.X + 2; ii++)
            {
                mainArray[ii] = new int[rectSize.Y + 2];
                for (int jj = 0; jj < rectSize.Y + 2; jj++)
                {
                    mainArray[ii][jj] = -1;
                }
            }
            int[][] looseArray = new int[rectSize.X][];
            for (int ii = 0; ii < rectSize.X; ii++)
            {
                looseArray[ii] = new int[rectSize.Y];
                for (int jj = 0; jj < rectSize.Y; jj++)
                {
                    looseArray[ii][jj] = -1;
                }
            }

            for (int xx = 0; xx < rectSize.X + 2; xx++)
            {
                for (int yy = 0; yy < rectSize.Y + 2; yy++)
                {
                    if (Collision.InBounds(totalSize.X, totalSize.Y, new Loc(rectStart.X + xx, rectStart.Y + yy)) && presenceMethod(rectStart.X + xx - 1, rectStart.Y + yy - 1))
                    {
                        textureMainBlock(mainArray, rectStart, rectStart.X + xx - 1, rectStart.Y + yy - 1, queryMethod);
                    }
                }
            }

            for (int xx = 0; xx < rectSize.X; xx++)
            {
                for (int yy = 0; yy < rectSize.Y; yy++)
                {
                    if (Collision.InBounds(totalSize.X, totalSize.Y, new Loc(rectStart.X + xx, rectStart.Y + yy)) && presenceMethod(rectStart.X + xx, rectStart.Y + yy) && mainArray[xx + 1][yy + 1] == -1)
                    {
                        textureLooseBlock(looseArray, mainArray, rectStart, rectStart.X + xx, rectStart.Y + yy, queryMethod);
                    }
                }
            }

            ReRandom rand = new ReRandom(randSeed);

            for (int xx = 0; xx < rectStart.X + rectSize.X; xx++)
            {
                int yy = 0;
                for (; yy < rectStart.Y + rectSize.Y; yy++)
                {
                    ulong subSeed = rand.NextUInt64();
                    if (xx >= rectStart.X && yy >= rectStart.Y)
                    {
                        int neighborCode = mainArray[xx + 1 - rectStart.X][yy + 1 - rectStart.Y];
                        if (looseArray[xx - rectStart.X][yy - rectStart.Y] != -1)
                        {
                            neighborCode = looseArray[xx - rectStart.X][yy - rectStart.Y];
                        }

                        if (neighborCode != -1)
                        {
                            placementMethod(xx, yy, GetVariantCode(new ReRandom(subSeed), neighborCode));
                        }
                    }
                }
                while (yy < totalSize.Y)
                {
                    rand.NextUInt64();
                    yy++;
                }
            }
        }
        private int GetVariantCode(ReRandom rand, int neighborCode)
        {
            List <TileLayer> tileVars = GetTileVariants(neighborCode);

            return(SelectTileVariant(rand, tileVars.Count) << 8 | neighborCode);
        }
Esempio n. 29
0
        private List <TileLayer> GetTile(ReRandom rand, int neighborCode)
        {
            List <TileLayer> tileList = new List <TileLayer>();
            int mask = Convert.ToInt32("11110000", 2);

            if ((neighborCode & Convert.ToInt32("00001111", 2)) == Convert.ToInt32("00000000", 2))
            {
                tileList.Add(new TileLayer(Surrounded));
            }
            else if ((neighborCode & Convert.ToInt32("00001111", 2)) == Convert.ToInt32("00000001", 2))
            {
                tileList.Add(new TileLayer(ColumnTop));
            }
            else if ((neighborCode & Convert.ToInt32("00001111", 2)) == Convert.ToInt32("00000010", 2))
            {
                tileList.Add(new TileLayer(RowRight));
            }
            else if ((neighborCode & Convert.ToInt32("00001111", 2)) == Convert.ToInt32("00000100", 2))
            {
                tileList.Add(new TileLayer(ColumnBottom));
            }
            else if ((neighborCode & Convert.ToInt32("00001111", 2)) == Convert.ToInt32("00001000", 2))
            {
                tileList.Add(new TileLayer(RowLeft));
            }
            else if ((neighborCode & Convert.ToInt32("00001111", 2)) == Convert.ToInt32("00000101", 2))
            {
                tileList.Add(new TileLayer(ColumnCenter));
            }
            else if ((neighborCode & Convert.ToInt32("00001111", 2)) == Convert.ToInt32("00001010", 2))
            {
                tileList.Add(new TileLayer(RowCenter));
            }
            else if ((neighborCode & Convert.ToInt32("00001111", 2)) == Convert.ToInt32("00000011", 2))
            {
                tileList.Add(new TileLayer(TopRight));
                mask &= Convert.ToInt32("11100000", 2);
            }
            else if ((neighborCode & Convert.ToInt32("00001111", 2)) == Convert.ToInt32("00000110", 2))
            {
                tileList.Add(new TileLayer(BottomRight));
                mask &= Convert.ToInt32("11010000", 2);
            }
            else if ((neighborCode & Convert.ToInt32("00001111", 2)) == Convert.ToInt32("00001100", 2))
            {
                tileList.Add(new TileLayer(BottomLeft));
                mask &= Convert.ToInt32("10110000", 2);
            }
            else if ((neighborCode & Convert.ToInt32("00001111", 2)) == Convert.ToInt32("00001001", 2))
            {
                tileList.Add(new TileLayer(TopLeft));
                mask &= Convert.ToInt32("01110000", 2);
            }
            else if ((neighborCode & Convert.ToInt32("00001111", 2)) == Convert.ToInt32("00000111", 2))
            {
                tileList.Add(new TileLayer(Right));
                mask &= Convert.ToInt32("11000000", 2);
            }
            else if ((neighborCode & Convert.ToInt32("00001111", 2)) == Convert.ToInt32("00001011", 2))
            {
                tileList.Add(new TileLayer(Top));
                mask &= Convert.ToInt32("01100000", 2);
            }
            else if ((neighborCode & Convert.ToInt32("00001111", 2)) == Convert.ToInt32("00001101", 2))
            {
                tileList.Add(new TileLayer(Left));
                mask &= Convert.ToInt32("00110000", 2);
            }
            else if ((neighborCode & Convert.ToInt32("00001111", 2)) == Convert.ToInt32("00001110", 2))
            {
                tileList.Add(new TileLayer(Bottom));
                mask &= Convert.ToInt32("10010000", 2);
            }
            else if ((neighborCode & Convert.ToInt32("00001111", 2)) == Convert.ToInt32("00001111", 2))
            {
                tileList.Add(new TileLayer(Center));
                mask &= Convert.ToInt32("00000000", 2);
            }

            //add edges
            int diagonal_map = neighborCode | mask;

            if ((diagonal_map & Convert.ToInt32("00010000", 2)) == 0)
            {
                tileList.Add(new TileLayer(TopRightEdge));
            }

            if ((diagonal_map & Convert.ToInt32("00100000", 2)) == 0)
            {
                tileList.Add(new TileLayer(BottomRightEdge));
            }

            if ((diagonal_map & Convert.ToInt32("01000000", 2)) == 0)
            {
                tileList.Add(new TileLayer(BottomLeftEdge));
            }

            if ((diagonal_map & Convert.ToInt32("10000000", 2)) == 0)
            {
                tileList.Add(new TileLayer(TopLeftEdge));
            }

            return(tileList);
        }
Esempio n. 30
0
 public void LoadRand(ReRandom rand)
 {
     this.rand = rand;
 }