Example #1
0
        public override void Apply(ZoneGenContext zoneContext, IGenContext context, StablePriorityQueue <Priority, IGenStep> queue)
        {
            //find the first postproc that is a GridRoom postproc and add this to its special rooms
            //NOTE: if a room-based generator is not found as the generation step, it will just skip this floor but treat it as though it was placed.
            if (SpreadPlan.CheckIfDistributed(zoneContext, context))
            {
                //TODO: allow arbitrary components to be added
                RoomGenOption genDuo = Spawns.Pick(context.Rand);
                SetGridSpecialRoomStep <MapGenContext> specialStep     = new SetGridSpecialRoomStep <MapGenContext>();
                SetSpecialRoomStep <ListMapGenContext> listSpecialStep = new SetSpecialRoomStep <ListMapGenContext>();

                specialStep.Filters = genDuo.Filters;
                if (specialStep.CanApply(context))
                {
                    specialStep.Rooms = new PresetPicker <RoomGen <MapGenContext> >(genDuo.GridOption);
                    specialStep.RoomComponents.Set(new ImmutableRoom());
                    queue.Enqueue(PriorityGrid, specialStep);
                }
                else if (listSpecialStep.CanApply(context))
                {
                    listSpecialStep.Rooms = new PresetPicker <RoomGen <ListMapGenContext> >(genDuo.ListOption);
                    listSpecialStep.RoomComponents.Set(new ImmutableRoom());
                    PresetPicker <PermissiveRoomGen <ListMapGenContext> > picker = new PresetPicker <PermissiveRoomGen <ListMapGenContext> >();
                    picker.ToSpawn        = new RoomGenAngledHall <ListMapGenContext>(0);
                    listSpecialStep.Halls = picker;
                    queue.Enqueue(PriorityList, listSpecialStep);
                }
            }
        }
 public void AddEventsToQueue <T>(StablePriorityQueue <GameEventPriority, EventQueueElement <T> > queue, Priority maxPriority, ref Priority nextPriority, PriorityList <T> effectList, Character targetChar) where T : GameEvent
 {
     foreach (Priority priority in effectList.GetPriorities())
     {
         //if an item has the same priority variable as the nextPriority, enqueue it
         //if an item has a higher priority variable than nextPriority, ignore it
         //if an item has a lower priority variable than nextPriority, check against maxPriority
         for (int ii = 0; ii < effectList.GetCountAtPriority(priority); ii++)
         {
             if (priority == nextPriority)
             {
                 GameEventPriority     gameEventPriority = new GameEventPriority(priority, GameEventPriority.USER_PORT_PRIORITY, GetEventCause(), GetID(), ii);
                 EventQueueElement <T> eventQueueElement = new EventQueueElement <T>(this, null, effectList.Get(priority, ii), targetChar);
                 queue.Enqueue(gameEventPriority, eventQueueElement);
             }
             else if (priority < nextPriority || nextPriority == Priority.Invalid)
             {
                 //if the item has a lower priority variable than maxPriority, ignore it
                 //if the item has a higher priority variable than maxPriority, clear the queue and add the new item
                 if (priority > maxPriority || maxPriority == Priority.Invalid)
                 {
                     nextPriority = priority;
                     queue.Clear();
                     GameEventPriority     gameEventPriority = new GameEventPriority(priority, GameEventPriority.USER_PORT_PRIORITY, GetEventCause(), GetID(), ii);
                     EventQueueElement <T> eventQueueElement = new EventQueueElement <T>(this, null, effectList.Get(priority, ii), targetChar);
                     queue.Enqueue(gameEventPriority, eventQueueElement);
                 }
             }
         }
     }
 }
Example #3
0
        private void preCalculateCoverage(StablePriorityQueue <int, Loc> tilesToHit, int delay)
        {
            Loc leftDiff, rightDiff;

            if (Dir.IsDiagonal())
            {
                leftDiff  = DirExt.AddAngles(Dir, Dir8.UpRight).GetLoc();
                rightDiff = DirExt.AddAngles(Dir, Dir8.UpLeft).GetLoc();
            }
            else
            {
                leftDiff  = DirExt.AddAngles(Dir, Dir8.Right).GetLoc();
                rightDiff = DirExt.AddAngles(Dir, Dir8.Left).GetLoc();
            }

            Loc candTile = StartPoint;

            for (int ii = 0; ii < MaxDistance; ii++)
            {
                candTile += Dir.GetLoc();

                tilesToHit.Enqueue(calculateTimeToHit(StartPoint, candTile) + delay, candTile);

                if (Wide)
                {
                    tilesToHit.Enqueue(calculateTimeToHit(StartPoint + leftDiff, candTile + leftDiff) + delay, candTile + leftDiff);
                    tilesToHit.Enqueue(calculateTimeToHit(StartPoint + rightDiff, candTile + rightDiff) + delay, candTile + rightDiff);
                }
            }
        }
Example #4
0
 public void AddEventsToQueue <T>(StablePriorityQueue <GameEventPriority, Tuple <GameEventOwner, Character, T> > queue, Priority maxPriority, ref Priority nextPriority, PriorityList <T> effectList) where T : GameEvent
 {
     foreach (Priority priority in effectList.GetPriorities())
     {
         //if an item has the same priority variable as the nextPriority, enqueue it
         //if an item has a higher priority variable than nextPriority, ignore it
         //if an item has a lower priority variable than nextPriority, check against maxPriority
         for (int ii = 0; ii < effectList.GetCountAtPriority(priority); ii++)
         {
             if (priority == nextPriority)
             {
                 queue.Enqueue(new GameEventPriority(priority, PortPriority, Passive.GetEventCause(), Passive.GetID(), ii), new Tuple <GameEventOwner, Character, T>(Passive, EventChar, effectList.Get(priority, ii)));
             }
             else if (priority < nextPriority || nextPriority == Priority.Invalid)
             {
                 //if the item has a lower priority variable than maxPriority, ignore it
                 //if the item has an equal or higher priority variable than maxPriority, clear the queue and add the new item
                 if (priority > maxPriority || maxPriority == Priority.Invalid)
                 {
                     nextPriority = priority;
                     queue.Clear();
                     queue.Enqueue(new GameEventPriority(priority, PortPriority, Passive.GetEventCause(), Passive.GetID(), ii), new Tuple <GameEventOwner, Character, T>(Passive, EventChar, effectList.Get(priority, ii)));
                 }
             }
         }
     }
 }
Example #5
0
        public void TestIntQueueUpdatePriority()
        {
            StablePriorityQueue <Node> stableQueue = new StablePriorityQueue <Node>(100);
            Node n1 = new Node();
            Node n2 = new Node();
            Node n3 = new Node();
            Node n4 = new Node();

            stableQueue.Enqueue(n1, 1);
            stableQueue.Enqueue(n2, 1);
            stableQueue.Enqueue(n3, 1);
            stableQueue.Enqueue(n4, 1);
            Node node = stableQueue.First;

            Assert.IsTrue(node == n1);
            stableQueue.UpdatePriority(n1, 1);
            node = stableQueue.First;
            Assert.IsTrue(node == n1);
            stableQueue.UpdatePriority(n1, 2);
            node = stableQueue.First;
            Assert.IsTrue(node == n2);
            stableQueue.UpdatePriority(n1, 1);
            node = stableQueue.First;
            Assert.IsTrue(node == n1);
            stableQueue.Dequeue();
            node = stableQueue.First;
            Assert.IsTrue(node == n2);
            stableQueue.Dequeue();
            node = stableQueue.First;
            Assert.IsTrue(node == n3);
        }
Example #6
0
        private void preCalculateCoverage(StablePriorityQueue <int, Loc> tilesToHit, int delay)
        {
            Loc topLeft = Origin - new Loc(MaxRadius);

            bool[][] connectionGrid = new bool[MaxRadius * 2 + 1][];
            for (int xx = 0; xx < connectionGrid.Length; xx++)
            {
                connectionGrid[xx] = new bool[MaxRadius * 2 + 1];
            }

            connectionGrid[Origin.X - topLeft.X][Origin.Y - topLeft.Y] = true;
            tilesToHit.Enqueue(calculateTimeToHit(Origin) + delay, Origin);

            Loc backup = Origin;

            if (MaxRadius > 0 && ZoneManager.Instance.CurrentMap.TileBlocked(Origin, true))
            {
                backup += Dir.Reverse().GetLoc();
            }

            Grid.FloodFill(new Rect(Origin - new Loc(MaxRadius), new Loc(MaxRadius * 2 + 1)),
                           (Loc testLoc) =>
            {
                if (connectionGrid[testLoc.X - topLeft.X][testLoc.Y - topLeft.Y])
                {
                    return(true);
                }
                if (!Collision.InBounds(ZoneManager.Instance.CurrentMap.Width, ZoneManager.Instance.CurrentMap.Height, testLoc))
                {
                    return(true);
                }
                if (!IsInSquareHitbox(testLoc, Origin, MaxRadius, HitArea, Dir))
                {
                    return(true);
                }
                if (ZoneManager.Instance.CurrentMap.TileBlocked(testLoc, true))
                {
                    return(true);
                }

                return(false);
            },
                           (Loc testLoc) =>
            {
                return(false);
            },
                           (Loc fillLoc) =>
            {
                if (fillLoc != Origin)
                {
                    connectionGrid[fillLoc.X - topLeft.X][fillLoc.Y - topLeft.Y] = true;
                    tilesToHit.Enqueue(calculateTimeToHit(fillLoc) + delay, fillLoc);
                }
            },
                           backup);
        }
Example #7
0
        public override void Apply(ZoneGenContext zoneContext, IGenContext context, StablePriorityQueue <Priority, IGenStep> queue)
        {
            int id = zoneContext.CurrentID;

            foreach (int floorId in SpreadPlan.DropPoints)
            {
                if (floorId != zoneContext.CurrentID)
                {
                    continue;
                }
                foreach (IGenPriority vaultStep in VaultSteps)
                {
                    queue.Enqueue(vaultStep.Priority, vaultStep.GetItem());
                }

                {
                    SpawnList <MapItem> itemListSlice = Items.GetSpawnList(id);
                    PickerSpawner <ListMapGenContext, MapItem> constructedSpawns = new PickerSpawner <ListMapGenContext, MapItem>(new LoopedRand <MapItem>(itemListSlice, ItemAmount[id]));

                    List <IStepSpawner <ListMapGenContext, MapItem> > steps = new List <IStepSpawner <ListMapGenContext, MapItem> >();
                    steps.Add(constructedSpawns);
                    if (ItemSpawners.ContainsItem(id))
                    {
                        IStepSpawner <ListMapGenContext, MapItem> treasures = ItemSpawners[id].Copy();
                        steps.Add(treasures);
                    }
                    PresetMultiRand <IStepSpawner <ListMapGenContext, MapItem> > groupRand   = new PresetMultiRand <IStepSpawner <ListMapGenContext, MapItem> >(steps.ToArray());
                    RandomRoomSpawnStep <ListMapGenContext, MapItem>             detourItems = ItemPlacements[id].Copy();
                    detourItems.Spawn = new MultiStepSpawner <ListMapGenContext, MapItem>(groupRand);
                    queue.Enqueue(ItemPriority, detourItems);
                }


                SpawnList <MobSpawn> mobListSlice = Mobs.GetSpawnList(id);
                if (mobListSlice.CanPick)
                {
                    //secret enemies
                    SpecificTeamSpawner specificTeam = new SpecificTeamSpawner();

                    MobSpawn newSpawn = mobListSlice.Pick(context.Rand).Copy();
                    specificTeam.Spawns.Add(newSpawn);

                    //use bruteforce clone for this
                    PlaceRandomMobsStep <ListMapGenContext> secretMobPlacement = MobPlacements[id].Copy();
                    secretMobPlacement.Spawn = new LoopedTeamSpawner <ListMapGenContext>(specificTeam, MobAmount[id]);
                    queue.Enqueue(MobPriority, secretMobPlacement);
                }
            }
        }
Example #8
0
            public IMessage PublishByNumber(Type type, IEventArgs args, int priority = MessageUrgency.Common)
            {
                var message = _pool.Get();

                message.Begin();
                message.SetArgs(args).SetType(type);
                if (priority < 0)
                {
                    HandleMessage(message);
                }
                else
                {
                    using (new LockWait(ref _lock_message))
                    {
                        if (_queue.count == _queue.capcity)
                        {
                            _queue.Resize(_queue.capcity * 2);
                        }
                        var node = nodePool.Get();
                        _queue.Enqueue(node, priority);
                        excuteMap.Add(node, message);
                        _list.Add(node);
                    }
                }
                return(message);
            }
        public override void Apply(ZoneGenContext zoneContext, IGenContext context, StablePriorityQueue <Priority, IGenStep> queue)
        {
            ItemSpawnStep <BaseMapGenContext> spawnStep = new ItemSpawnStep <BaseMapGenContext>();

            spawnStep.Spawns = Spawns.GetSpawnList(zoneContext.CurrentID);
            queue.Enqueue(Priority, spawnStep);
        }
Example #10
0
        private void addToQueue(ZoneGenContext zoneContext, IGenContext context, StablePriorityQueue <Priority, IGenStep> queue)
        {
            int id = zoneContext.CurrentID;

            IMonsterHouseBaseStep monsterHouseStep = HouseStepSpawns.Pick(context.Rand).CreateNew();
            SpawnList <MapItem>   itemListSlice    = Items.GetSpawnList(id);

            for (int jj = 0; jj < itemListSlice.Count; jj++)
            {
                monsterHouseStep.Items.Add(new MapItem(itemListSlice.GetSpawn(jj)), itemListSlice.GetSpawnRate(jj));
            }
            SpawnList <ItemTheme> itemThemeListSlice = ItemThemes.GetSpawnList(id);

            for (int jj = 0; jj < itemThemeListSlice.Count; jj++)
            {
                monsterHouseStep.ItemThemes.Add(itemThemeListSlice.GetSpawn(jj).Copy(), itemThemeListSlice.GetSpawnRate(jj));
            }
            SpawnList <MobSpawn> mobListSlice = Mobs.GetSpawnList(id);

            for (int jj = 0; jj < mobListSlice.Count; jj++)
            {
                MobSpawn newSpawn = mobListSlice.GetSpawn(jj).Copy();
                monsterHouseStep.Mobs.Add(newSpawn, mobListSlice.GetSpawnRate(jj));
            }
            SpawnList <MobTheme> mobThemeListSlice = MobThemes.GetSpawnList(id);

            for (int jj = 0; jj < mobThemeListSlice.Count; jj++)
            {
                monsterHouseStep.MobThemes.Add(mobThemeListSlice.GetSpawn(jj).Copy(), mobThemeListSlice.GetSpawnRate(jj));
            }

            queue.Enqueue(Priority, monsterHouseStep);
        }
 public void Add(T task)
 {
     lock (LockObject)
     {
         queue.Enqueue(task, task.Priority);
     }
 }
            public IMessage PublishByNumber(Type type, IEventArgs args, int priority = MessageUrgency.Common)
            {
                var message = Framework.GlobalAllocate <Message>();

                message.Begin();
                message.SetArgs(args).SetType(type);
                if (priority < 0)
                {
                    HandleMessage(message);
                }
                else
                {
                    using (new LockWait(ref _lock_message))
                    {
                        if (_priorityQueue.count == _priorityQueue.capcity)
                        {
                            _priorityQueue.Resize(_priorityQueue.capcity * 2);
                        }
                        StablePriorityQueueNode node = Framework.GlobalAllocate <StablePriorityQueueNode>();
                        _priorityQueue.Enqueue(node, priority);
                        excuteMap.Add(node, message);
                        _updatelist.Add(node);
                    }
                }
                return(message);
            }
Example #13
0
 public override void Apply(ZoneGenContext zoneContext, IGenContext context, StablePriorityQueue <Priority, IGenStep> queue)
 {
     if (SpreadPlan.CheckIfDistributed(zoneContext, context))
     {
         IGenPriority genStep = Spawns.Pick(context.Rand);
         queue.Enqueue(genStep.Priority, genStep.GetItem());
     }
 }
Example #14
0
    public void Enqueue(T item, float priority)
    {
        SimpleNode node = new SimpleNode(item);

        if (queue.Count == queue.MaxSize)
        {
            queue.Resize(queue.MaxSize * 2 + 1);
        }

        queue.Enqueue(node, priority);
    }
Example #15
0
        private void preCalculateCoverage(StablePriorityQueue <int, Loc> tilesToHit, int delay)
        {
            HashSet <Loc> hitTiles    = new HashSet <Loc>();
            HashSet <Loc> returnTiles = new HashSet <Loc>();

            Loc candTile = StartPoint;

            for (int ii = 0; ii < MaxDistance; ii++)
            {
                candTile = candTile + Dir.GetLoc();
                tilesToHit.Enqueue(calculateTimeToHit(candTile, false) + delay, candTile);
            }
            if (Boomerang)
            {
                for (int ii = 0; ii < MaxDistance - 1; ii++)
                {
                    candTile = candTile - Dir.GetLoc();
                    tilesToHit.Enqueue(calculateTimeToHit(candTile, true) + delay, candTile);
                }
            }
        }
        public override void Apply(ZoneGenContext zoneContext, IGenContext context, StablePriorityQueue <Priority, IGenStep> queue)
        {
            TileSpawnStep <BaseMapGenContext> spawnStep = new TileSpawnStep <BaseMapGenContext>();

            SpawnList <EffectTile> spawner = Spawns.GetSpawnList(zoneContext.CurrentID);

            for (int ii = 0; ii < spawner.Count; ii++)
            {
                spawnStep.Spawns.Add(spawner.GetSpawn(ii), spawner.GetSpawnRate(ii));
            }

            queue.Enqueue(Priority, spawnStep);
        }
Example #17
0
        public override void Apply(ZoneGenContext zoneContext, IGenContext context, StablePriorityQueue <Priority, IGenStep> queue)
        {
            int id = zoneContext.CurrentID;

            foreach (int floorId in SpreadPlan.DropPoints)
            {
                if (floorId != zoneContext.CurrentID)
                {
                    continue;
                }
                {
                    SpawnList <AddBossRoomStep <ListMapGenContext> > bossListSlice = BossSteps.GetSpawnList(id);
                    if (!bossListSlice.CanPick)
                    {
                        return;
                    }
                    AddBossRoomStep <ListMapGenContext> bossStep = bossListSlice.Pick(context.Rand).Copy();
                    queue.Enqueue(BossRoomPriority, bossStep);
                }

                foreach (IGenPriority vaultStep in VaultSteps)
                {
                    queue.Enqueue(vaultStep.Priority, vaultStep.GetItem());
                }

                {
                    SpawnList <MapItem> itemListSlice = Items.GetSpawnList(id);
                    PickerSpawner <ListMapGenContext, MapItem> constructedSpawns = new PickerSpawner <ListMapGenContext, MapItem>(new LoopedRand <MapItem>(itemListSlice, ItemAmount[id]));

                    IStepSpawner <ListMapGenContext, MapItem> treasures = ItemSpawners[id].Copy();

                    PresetMultiRand <IStepSpawner <ListMapGenContext, MapItem> > groupRand = new PresetMultiRand <IStepSpawner <ListMapGenContext, MapItem> >(constructedSpawns, treasures);

                    RandomRoomSpawnStep <ListMapGenContext, MapItem> detourItems = ItemPlacements[id].Copy();
                    detourItems.Spawn = new MultiStepSpawner <ListMapGenContext, MapItem>(groupRand);
                    queue.Enqueue(RewardPriority, detourItems);
                }
            }
        }
Example #18
0
        public void UpdateHitQueue(StablePriorityQueue <int, HitboxHit> hitTargets)
        {
            //when updating, the base will update the time elapsed
            //when this method is reached, hits will be delegated accordingly

            while (TilesToHit.Count > 0 && (Finished || time >= TilesToHit.FrontPriority()))
            {
                int priority = TilesToHit.FrontPriority();
                Loc tile     = TilesToHit.Dequeue();

                //filter out the hitboxes that are not wanted
                TargetHitType type = IsValidTileTarget(tile);
                if (type == TargetHitType.Burst)
                {
                    hitTargets.Enqueue(priority, new HitboxHit(tile, true));
                }
                else if (type == TargetHitType.Tile)
                {
                    hitTargets.Enqueue(priority, new HitboxHit(tile, false));
                }
            }
        }
Example #19
0
        public override void Apply(ZoneGenContext zoneContext, IGenContext context, StablePriorityQueue <Priority, IGenStep> queue)
        {
            GameProgress progress = DataManager.Instance.Save;

            if (progress != null && progress.Rescue != null && progress.Rescue.Rescuing)
            {
                if (progress.Rescue.SOS.Goal.ID == zoneContext.CurrentZone &&
                    progress.Rescue.SOS.Goal.StructID.Segment == zoneContext.CurrentSegment &&
                    progress.Rescue.SOS.Goal.StructID.ID == zoneContext.CurrentID)
                {
                    queue.Enqueue(Priority, new RescueSpawner <BaseMapGenContext>());
                }
            }
        }
Example #20
0
        /// <summary>
        /// 按批量方式进行资源的加载
        /// 如果指定使用标签进行资源加载,则会忽略<paramref name="addresses"/>的值
        /// </summary>
        /// <param name="label">加载设定指定标签的资源</param>
        /// <param name="addresses">资源加载地址</param>
        /// <param name="isInstance">是否需要实例化</param>
        /// <param name="complete">单个资源加载完毕后回调</param>
        /// <param name="batchComplete">所有资源加载完毕后回调</param>
        /// <param name="progress">单个资源加载进度回调</param>
        /// <param name="batchProgress">所有资源加载进度回调</param>
        /// <param name="priority">优先级</param>
        /// <param name="userData">自定义参数</param>
        /// <returns></returns>
        internal AssetHandler LoadBatchAssetAsync(
            string label,
            string[] addresses,
            bool isInstance,
            OnAssetLoadComplete complete,
            OnBatchAssetLoadComplete batchComplete,
            OnAssetLoadProgress progress,
            OnBatchAssetsLoadProgress batchProgress,
            AssetLoaderPriority priority,
            SystemObject userData)
        {
            //如果指定按标签加载资源,则查找标记为指定标签的所有资源
            if (!string.IsNullOrEmpty(label))
            {
                addresses = addressConfig.GetAddressesByLabel(label);
                DebugLog.Debug(AssetConst.LOGGER_NAME, $"AssetLoader::LoadBatchAssetAsync->Load asset by label.label = {label},addresses = {string.Join(",",addresses)}");
            }

            if (addresses == null || addresses.Length == 0)
            {
                DebugLog.Error(AssetConst.LOGGER_NAME, "AAssetLoader::LoadBatchAssetAsync->addresses is null");
                return(null);
            }
            //获取资源真实的路径
            string[] paths = addressConfig.GetPathsByAddresses(addresses);
            if (paths == null || paths.Length == 0)
            {
                DebugLog.Error(AssetConst.LOGGER_NAME, "AssetLoader::LoadBatchAssetAsync->paths is null");
                return(null);
            }
            else
            {
                DebugLog.Debug(AssetConst.LOGGER_NAME, $"AssetLoader::LoadBatchAssetAsync->find assetPath by address.addresses = {string.Join(",", addresses)},path = {string.Join(",",paths)}");
            }

            if (dataWaitingQueue.Count >= dataWaitingQueue.MaxSize)
            {
                dataWaitingQueue.Resize(dataWaitingQueue.MaxSize * 2);
                DebugLog.Debug(AssetConst.LOGGER_NAME, "AssetLoader::LoadBatchAssetAsync->Reset the queue size.");
            }

            AssetLoaderData data = dataPool.Get();

            data.InitData(label, addresses, paths, isInstance, complete, progress, batchComplete, batchProgress, userData);
            data.State = AssetLoaderDataState.Waiting;
            dataWaitingQueue.Enqueue(data, (float)priority);

            return(data.Handler);
        }
Example #21
0
 private void preCalculateCoverage(StablePriorityQueue <int, Loc> tilesToHit, int delay)
 {
     for (int ii = -MaxRadius; ii <= MaxRadius; ii++)
     {
         for (int jj = -MaxRadius; jj <= MaxRadius; jj++)
         {
             Loc candTile = new Loc(ii, jj) + Origin;
             if (IsInSquareHitbox(candTile, Origin, MaxRadius, HitArea, Dir) &&
                 Collision.InBounds(ZoneManager.Instance.CurrentMap.Width, ZoneManager.Instance.CurrentMap.Height, candTile))
             {
                 tilesToHit.Enqueue(calculateTimeToHit(candTile) + delay, candTile);
             }
         }
     }
 }
Example #22
0
        public override void Apply(ZoneGenContext zoneContext, IGenContext context, StablePriorityQueue <Priority, IGenStep> queue)
        {
            MobSpawnStep <BaseMapGenContext> spawnStep = new MobSpawnStep <BaseMapGenContext>();

            PoolTeamSpawner spawner = new PoolTeamSpawner();

            spawner.Spawns    = Spawns.GetSpawnList(zoneContext.CurrentID);
            spawner.TeamSizes = TeamSizes.GetSpawnList(zoneContext.CurrentID);
            spawnStep.Spawns.Add(spawner, spawner.Spawns.SpawnTotal);

            SpawnList <SpecificTeamSpawner> specificSpawner = SpecificSpawns.GetSpawnList(zoneContext.CurrentID);

            for (int ii = 0; ii < specificSpawner.Count; ii++)
            {
                spawnStep.Spawns.Add(specificSpawner.GetSpawn(ii), specificSpawner.GetSpawnRate(ii));
            }

            queue.Enqueue(Priority, spawnStep);
        }
Example #23
0
        public IEnumerator <YieldInstruction> BeforeExplosion(BattleContext context)
        {
            EventEnqueueFunction <BattleEvent> function = (StablePriorityQueue <GameEventPriority, Tuple <GameEventOwner, Character, BattleEvent> > queue, Priority maxPriority, ref Priority nextPriority) =>
            {
                DataManager.Instance.UniversalEvent.AddEventsToQueue(queue, maxPriority, ref nextPriority, DataManager.Instance.UniversalEvent.BeforeExplosions);

                context.Data.AddEventsToQueue <BattleEvent>(queue, maxPriority, ref nextPriority, context.Data.BeforeExplosions);

                StablePriorityQueue <int, Character> charQueue = new StablePriorityQueue <int, Character>();
                foreach (Character character in ZoneManager.Instance.CurrentMap.IterateCharacters())
                {
                    if (!character.Dead)
                    {
                        charQueue.Enqueue(-character.Speed, character);
                    }
                }
                int portPriority = 0;

                while (charQueue.Count > 0)
                {
                    Character character = charQueue.Dequeue();
                    foreach (PassiveContext effectContext in character.IterateProximityPassives(context.User, context.ExplosionTile, portPriority))
                    {
                        effectContext.AddEventsToQueue(queue, maxPriority, ref nextPriority, ((ProximityData)effectContext.EventData).BeforeExplosions);
                    }

                    portPriority++;
                }
            };

            foreach (Tuple <GameEventOwner, Character, BattleEvent> effect in IterateEvents <BattleEvent>(function))
            {
                yield return(CoroutineManager.Instance.StartCoroutine(effect.Item3.Apply(effect.Item1, effect.Item2, context)));

                if (context.CancelState.Cancel)
                {
                    yield break;
                }
            }
        }
Example #24
0
        public override void Apply(ZoneGenContext zoneContext, IGenContext context, StablePriorityQueue <Priority, IGenStep> queue)
        {
            SpawnDict <string, SpawnList <InvItem> > spawns = new SpawnDict <string, SpawnList <InvItem> >();

            //contains all LISTS that intersect the current ID
            foreach (string key in Spawns.Keys)
            {
                //get all items within the spawnrangelist that intersect the current ID
                SpawnList <InvItem> slicedList = Spawns[key].Spawns.GetSpawnList(zoneContext.CurrentID);

                // add the spawnlist under the current key, with the key having the spawnrate for this id
                if (slicedList.CanPick && Spawns[key].SpawnRates.ContainsItem(zoneContext.CurrentID) && Spawns[key].SpawnRates[zoneContext.CurrentID] > 0)
                {
                    spawns.Add(key, slicedList, Spawns[key].SpawnRates[zoneContext.CurrentID]);
                }
            }

            ItemSpawnStep <BaseMapGenContext> spawnStep = new ItemSpawnStep <BaseMapGenContext>();

            spawnStep.Spawns = spawns;
            queue.Enqueue(Priority, spawnStep);
        }
Example #25
0
        private static void Update_OPTICS(ref Dictionary <PointD, Tuple <bool, double?> > DictionnaryOfOPTICS, List <PointD> list_of_neighbors, PointD point, ref StablePriorityQueue <PointDQueue> seeds, double epsilon, int min_points)
        {
            double?core_dist = Core_distance(DictionnaryOfOPTICS, point, epsilon, min_points);

            foreach (PointD O in list_of_neighbors)
            {
                if (DictionnaryOfOPTICS[O].Item1 == false)
                {
                    double?reachability = Reachability_distance(DictionnaryOfOPTICS, point, O, epsilon, min_points);
                    if (DictionnaryOfOPTICS[O].Item2 == null)
                    {
                        DictionnaryOfOPTICS[O] = new Tuple <bool, double?>(DictionnaryOfOPTICS[O].Item1, reachability);
                        seeds.Enqueue(new PointDQueue(O.X, O.Y), (float)reachability);
                    }
                    else if (reachability < DictionnaryOfOPTICS[O].Item2)
                    {
                        DictionnaryOfOPTICS[O] = new Tuple <bool, double?>(DictionnaryOfOPTICS[O].Item1, reachability);
                        seeds.UpdatePriority(new PointDQueue(O.X, O.Y), (float)reachability);
                    }
                }
            }
        }
Example #26
0
        public IGenContext GenMap(ZoneGenContext zoneContext)
        {
            //it will first create the instance of the context,
            //and set up a local List<GenPriority<IGenStep>> variable
            //the zonecontext members include runtime zonepostprocs
            //that will appreciate a IGenContext + List<GenPriority<IGenStep>> being passed into them
            //then, gensteps will continue on as per usual

            T map = (T)Activator.CreateInstance(typeof(T));

            map.InitSeed(zoneContext.Seed);

            GenContextDebug.DebugInit(map);

            //postprocessing steps:
            StablePriorityQueue <Priority, IGenStep> queue = new StablePriorityQueue <Priority, IGenStep>();

            foreach (Priority priority in GenSteps.GetPriorities())
            {
                foreach (IGenStep genStep in GenSteps.GetItems(priority))
                {
                    queue.Enqueue(priority, genStep);
                }
            }

            foreach (ZonePostProc zoneStep in zoneContext.ZoneSteps)
            {
                zoneStep.Apply(zoneContext, map, queue);
            }

            ApplyGenSteps(map, queue);

            map.FinishGen();

            return(map);
        }
Example #27
0
        private GameAction DumbAvoid(Character controlledChar, bool preThink, List <Character> seenCharacters, CharIndex ownIndex, IRandom rand)
        {
            StablePriorityQueue <double, Dir8> candidateDirs = new StablePriorityQueue <double, Dir8>();

            //choose the single direction that avoids other characters the most
            bool respectPeers = !preThink;

            for (int ii = -1; ii < DirExt.DIR8_COUNT; ii++)
            {
                Loc checkLoc = controlledChar.CharLoc + ((Dir8)ii).GetLoc();

                double dirDistance = 0;
                //iterated in increasing character indices
                foreach (Character seenChar in seenCharacters)
                {
                    if (RunFromAllies && !RunFromFoes)
                    {
                        //only avoid if their character index is lower than this one, aka higher ranking member
                        CharIndex seenIndex = ZoneManager.Instance.CurrentMap.GetCharIndex(seenChar);
                        if (seenIndex.Team > ownIndex.Team)
                        {
                            break;
                        }
                        else if (seenIndex.Team == ownIndex.Team)
                        {
                            if (seenIndex.Char > ownIndex.Char && seenChar.MemberTeam.LeaderIndex != seenIndex.Char)
                            {
                                continue;
                            }
                        }
                    }

                    dirDistance += Math.Sqrt((checkLoc - seenChar.CharLoc).DistSquared());
                }

                candidateDirs.Enqueue(-dirDistance, (Dir8)ii);
            }


            Grid.LocTest checkDiagBlock = (Loc testLoc) =>
            {
                return(ZoneManager.Instance.CurrentMap.TileBlocked(testLoc, controlledChar.Mobility, true));
                //enemy/ally blockings don't matter for diagonals
            };

            Grid.LocTest checkBlock = (Loc testLoc) =>
            {
                if (ZoneManager.Instance.CurrentMap.TileBlocked(testLoc, controlledChar.Mobility))
                {
                    return(true);
                }

                if ((IQ & AIFlags.TrapAvoider) != AIFlags.None)
                {
                    Tile tile = ZoneManager.Instance.CurrentMap.Tiles[testLoc.X][testLoc.Y];
                    if (tile.Effect.ID > -1)
                    {
                        TileData entry = DataManager.Instance.GetTile(tile.Effect.ID);
                        if (entry.StepType == TileData.TriggerType.Trap || entry.StepType == TileData.TriggerType.Site || entry.StepType == TileData.TriggerType.Switch)
                        {
                            return(true);
                        }
                    }
                }

                if (respectPeers && BlockedByChar(testLoc, Alignment.Self | Alignment.Foe))
                {
                    return(true);
                }

                return(false);
            };

            //try each direction from most appealing to least appealing, stopping if we get to "none"
            while (candidateDirs.Count > 0)
            {
                Dir8 highestDir = candidateDirs.Dequeue();
                if (highestDir == Dir8.None)
                {
                    if (AbortIfCornered)//this plan will be aborted, try the next plan in the list
                    {
                        return(null);
                    }
                    else//cry in a corner
                    {
                        return(new GameAction(GameAction.ActionType.Wait, Dir8.None));
                    }
                }
                else
                {
                    //check to see if we can walk this way
                    if (!Grid.IsDirBlocked(controlledChar.CharLoc, highestDir, checkBlock, checkDiagBlock))
                    {
                        return(TrySelectWalk(controlledChar, highestDir));
                    }
                }
            }

            if (AbortIfCornered)//this plan will be aborted, try the next plan in the list
            {
                return(null);
            }
            else//cry in a corner
            {
                return(new GameAction(GameAction.ActionType.Wait, Dir8.None));
            }
        }
Example #28
0
 public override void Apply(ZoneGenContext zoneContext, IGenContext context, StablePriorityQueue <Priority, IGenStep> queue)
 {
     queue.Enqueue(Priority, new MapNameIDStep <BaseMapGenContext>(zoneContext.CurrentID, LocalText.FormatLocalText(Name, (zoneContext.CurrentID + 1).ToString())));
 }
        public override void Apply(ZoneGenContext zoneContext, IGenContext context, StablePriorityQueue <Priority, IGenStep> queue)
        {
            RandRange amount = new RandRange(chosenStart + chosenAdd * zoneContext.CurrentID);

            queue.Enqueue(Priority, new MoneySpawnStep <BaseMapGenContext>(amount));
        }