示例#1
0
文件: Level.cs 项目: Dzugaru/hexes
            public WorldBlock Get(HexXY p)
            {
                for (int i = 0; i < cacheSz; i++)
                {
                    if (cache[i].pos == p)
                    {
                        return(cache[i].worldBlock);
                    }
                }

                WorldBlock block = null;

                all.TryGetValue(p, out block);
                if (block != null)
                {
                    for (int i = 1; i < cacheMaxSz; i++)
                    {
                        cache[i] = cache[i - 1];
                    }
                    cache[0] = new CacheEntry()
                    {
                        pos = p, worldBlock = block
                    };
                    cacheSz = Math.Min(cacheSz + 1, cacheMaxSz);
                }

                return(block);
            }
示例#2
0
文件: Level.cs 项目: Dzugaru/hexes
        public bool RemoveEntity(HexXY p, Entity ent)
        {
            HexXY      localPos;
            WorldBlock block = GetBlockWithCell(p, false, out localPos);

            return(block.entityMap[localPos.x, localPos.y].Remove(ent));
        }
示例#3
0
文件: Level.cs 项目: Dzugaru/hexes
        public int GetPFExpandMap(HexXY p)
        {
            HexXY      localPos;
            WorldBlock block = GetBlockWithCell(p, false, out localPos);

            return(block.pfExpandMap[localPos.x, localPos.y]);
        }
示例#4
0
        public void OnMove(HexXY from, HexXY to, bool isDrawing)
        {
            EnsurePrevMoveFinished();

            if (!WorldBlock.CanTryToMoveToBlockType(Level.S.GetPFBlockedMap(to)))
            {
                avatar.finishState = Avatar.FinishedState.CantMoveThere;
                return;
            }

            if (!isDrawing)
            {
                if (!avatar.spell.caster.SpendMana(1))
                {
                    avatar.finishState = Avatar.FinishedState.NoManaLeft;
                    return;
                }
            }
            else
            {
                if (!avatar.spell.caster.SpendMana(5))
                {
                    avatar.finishState = Avatar.FinishedState.NoManaLeft;
                    return;
                }
            }

            this.isDrawing = isDrawing;

            Interfacing.PerformInterfaceMove(graphicsHandle, to, movTime);
            movTimeLeft = movTime * 0.75f; //TODO: this is point in time when avatar element entity changes pos
            movPos      = to;
        }
示例#5
0
文件: Level.cs 项目: Dzugaru/hexes
        public byte GetPFStepsMap(HexXY p)
        {
            HexXY      localPos;
            WorldBlock block = GetBlockWithCell(p, false, out localPos);

            return(block.pfStepsMap[localPos.x, localPos.y]);
        }
示例#6
0
文件: Level.cs 项目: Dzugaru/hexes
        public void AddEntity(HexXY p, Entity ent)
        {
            HexXY      localPos;
            WorldBlock block = GetBlockWithCell(p, false, out localPos);

            block.entityMap[localPos.x, localPos.y].Add(ent);
        }
示例#7
0
文件: Level.cs 项目: Dzugaru/hexes
            public WorldBlock GetNoCache(HexXY p)
            {
                WorldBlock block = null;

                all.TryGetValue(p, out block);
                return(block);
            }
示例#8
0
文件: Level.cs 项目: Dzugaru/hexes
        public WorldBlock SetCellType(HexXY p, TerrainCellType type)
        {
            HexXY      localPos;
            WorldBlock block = GetBlockWithCell(p, true, out localPos);

            block.SetCellType(localPos, type);
            return(block);
        }
示例#9
0
文件: Level.cs 项目: Dzugaru/hexes
        public WorldBlock SetPFBlockedMap(HexXY p, WorldBlock.PFBlockType val)
        {
            HexXY      localPos;
            WorldBlock block = GetBlockWithCell(p, false, out localPos);

            block.pfBlockedMap[localPos.x, localPos.y] = val;
            return(block);
        }
示例#10
0
文件: Level.cs 项目: Dzugaru/hexes
        public WorldBlock SetPFExpandMap(HexXY p, int val)
        {
            HexXY      localPos;
            WorldBlock block = GetBlockWithCell(p, false, out localPos);

            block.pfExpandMap[localPos.x, localPos.y] = val;
            return(block);
        }
示例#11
0
文件: Level.cs 项目: Dzugaru/hexes
        public WorldBlock SetPFStepsMap(HexXY p, byte val)
        {
            HexXY      localPos;
            WorldBlock block = GetBlockWithCell(p, false, out localPos);

            block.pfStepsMap[localPos.x, localPos.y] = val;
            return(block);
        }
示例#12
0
文件: Player.cs 项目: Dzugaru/hexes
 public void Move(HexXY p)
 {
     if (!cantMove && WorldBlock.CanTryToMoveToBlockType(Level.S.GetPFBlockedMap(p)) &&
         (!dest.HasValue || p != dest))
     {
         afterMoveAction = null;
         dest            = p;
         distToStop      = 0;
         MovePart();
     }
 }
示例#13
0
文件: Level.cs 项目: Dzugaru/hexes
        public static void Load(BinaryReader reader)
        {
            var level = new Level();
            int count = reader.ReadInt32();

            for (int i = 0; i < count; i++)
            {
                var wb = WorldBlock.Load(reader);
                level.wbCache.Add(wb.position, wb);
            }
        }
示例#14
0
 public void OnMove(HexXY from, HexXY to, bool isDrawing)
 {
     if (!WorldBlock.CanTryToMoveToBlockType(Level.S.GetPFBlockedMap(to)))
     {
         avatar.finishState = Avatar.FinishedState.CantMoveThere;
     }
     else
     {
         Interfacing.PerformInterfaceMove(graphicsHandle, to, movTime);
         movTimeLeft = movTime * 0.75f; //TODO: this is point in time when avatar changes pos
     }
 }
示例#15
0
文件: Level.cs 项目: Dzugaru/hexes
        public WorldBlock.PFBlockType GetPFBlockedMap(HexXY p)
        {
            HexXY      localPos;
            WorldBlock block = GetBlockWithCell(p, false, out localPos);

            if (block == null)
            {
                return(WorldBlock.PFBlockType.EdgeBlocked);
            }
            else
            {
                return(block.pfBlockedMap[localPos.x, localPos.y]);
            }
        }
示例#16
0
文件: Level.cs 项目: Dzugaru/hexes
        public TerrainCellType GetCellType(HexXY p)
        {
            HexXY      localPos;
            WorldBlock block = GetBlockWithCell(p, false, out localPos);

            if (block == null)
            {
                return(TerrainCellType.Empty);
            }
            else
            {
                return(block.GetCellType(localPos));
            }
        }
示例#17
0
文件: Level.cs 项目: Dzugaru/hexes
        public IEnumerable <Entity> GetEntities(HexXY p)
        {
            HexXY      localPos;
            WorldBlock block = GetBlockWithCell(p, false, out localPos);

            if (block == null)
            {
                yield break;
            }
            else
            {
                foreach (var ent in block.entityMap[localPos.x, localPos.y])
                {
                    yield return(ent);
                }
            }
        }
示例#18
0
        public static WorldBlock Load(BinaryReader reader)
        {
            var pos = new HexXY(reader.ReadInt32(), reader.ReadInt32());

            var wb = new WorldBlock(pos);

            for (int x = 0; x < sz; x++)
            {
                for (int y = 0; y < sz; y++)
                {
                    var type = (TerrainCellType)reader.ReadByte();
                    wb.cellTypes[x, y] = type;
                    ++wb.cellTypeCounts[(int)type];
                    wb.pfBlockedMap[x, y] = (PFBlockType)reader.ReadByte();
                }
            }
            return(wb);
        }
示例#19
0
        public void OnMove(HexXY from, HexXY to, bool isDrawing)
        {
            if (!isDrawing || !WorldBlock.CanTryToMoveToBlockType(Level.S.GetPFBlockedMap(to)))
            {
                if (!avatar.spell.caster.SpendMana(1))
                {
                    avatar.finishState = Avatar.FinishedState.NoManaLeft;
                    return;
                }
            }
            else
            {
                if (!avatar.spell.caster.SpendMana(10))
                {
                    avatar.finishState = Avatar.FinishedState.NoManaLeft;
                    return;
                }

                var spellEffect = new SpellEffects.Stone(1);
                spellEffect.StackOn(to);
            }
        }
示例#20
0
文件: Level.cs 项目: Dzugaru/hexes
        WorldBlock GetBlockWithCell(HexXY p, bool shouldCreateIfNotFound, out HexXY localp)
        {
            localp = new HexXY(0, 0);
            HexXY blockPos = GetBlockCoords(p);

            WorldBlock block = wbCache.Get(blockPos);

            if (block == null)
            {
                if (!shouldCreateIfNotFound)
                {
                    return(null);
                }
                else
                {
                    block = new WorldBlock(blockPos);
                    wbCache.Add(blockPos, block);
                }
            }

            localp.x = p.x - blockPos.x * WorldBlock.sz;
            localp.y = p.y - blockPos.y * WorldBlock.sz;
            return(block);
        }
示例#21
0
        public static uint?FindPath(HexXY from, HexXY to, HexXY[] pathStorage, uint distToStop = 0, uint dynBlockCost = 0)
        {
            front.Reset();
            front.Enqueue(new XYCost(from, 0, 0, GetHeuristic(from, to)));

            //TODO: assume we're in the single worldblock for now
            ++Level.S.pfExpandMarker;
            Level.S.SetPFExpandMap(from, Level.S.pfExpandMarker);

            XYCost c;
            bool   isFound = false;

            do
            {
                c = front.Dequeue();

                if (HexXY.Dist(c.p, to) <= distToStop)
                {
                    isFound = true;
                    break;
                }

                foreach (var st in steps)
                {
                    var np        = c.p + st;
                    var blockType = Level.S.GetPFBlockedMap(np);
                    if (WorldBlock.CanTryToMoveToBlockType(blockType) &&
                        Level.S.GetPFExpandMap(np) < Level.S.pfExpandMarker)
                    {
                        Level.S.SetPFExpandMap(np, Level.S.pfExpandMarker);
                        uint cost = (uint)(c.cost + WorldBlock.PFGetPassCost(np));

                        if (dynBlockCost > 0 && np != to && blockType == WorldBlock.PFBlockType.DynamicBlocked)
                        {
                            cost += dynBlockCost;
                        }

                        var n = new XYCost(np, c.len + 1, cost, cost + GetHeuristic(np, to));
                        front.Enqueue(n);
                        Level.S.SetPFStepsMap(np, st.backIdx);
                    }
                }
            } while (front.Count > 0);

            if (isFound && c.len <= pathStorage.Length)
            {
                uint  pathLen = c.len;
                HexXY p       = c.p;
                for (int i = 0; i < pathLen; i++)
                {
                    pathStorage[pathLen - i - 1] = p;
                    var backIdx = Level.S.GetPFStepsMap(p);
                    p = p + steps[backIdx];
                }
                return(pathLen);
            }
            else
            {
                return(null);
            }
        }
示例#22
0
文件: Level.cs 项目: Dzugaru/hexes
 public void Add(HexXY p, WorldBlock block)
 {
     all.Add(p, block);
 }