예제 #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
파일: Pathfinder.cs 프로젝트: Dzugaru/hexes
        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);
 }