Ejemplo n.º 1
0
            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);
            }
Ejemplo n.º 2
0
        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));
        }
Ejemplo n.º 3
0
        public int GetPFExpandMap(HexXY p)
        {
            HexXY      localPos;
            WorldBlock block = GetBlockWithCell(p, false, out localPos);

            return(block.pfExpandMap[localPos.x, localPos.y]);
        }
Ejemplo n.º 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;
        }
Ejemplo n.º 5
0
        public byte GetPFStepsMap(HexXY p)
        {
            HexXY      localPos;
            WorldBlock block = GetBlockWithCell(p, false, out localPos);

            return(block.pfStepsMap[localPos.x, localPos.y]);
        }
Ejemplo n.º 6
0
        public void AddEntity(HexXY p, Entity ent)
        {
            HexXY      localPos;
            WorldBlock block = GetBlockWithCell(p, false, out localPos);

            block.entityMap[localPos.x, localPos.y].Add(ent);
        }
Ejemplo n.º 7
0
            public WorldBlock GetNoCache(HexXY p)
            {
                WorldBlock block = null;

                all.TryGetValue(p, out block);
                return(block);
            }
Ejemplo n.º 8
0
        public WorldBlock SetCellType(HexXY p, TerrainCellType type)
        {
            HexXY      localPos;
            WorldBlock block = GetBlockWithCell(p, true, out localPos);

            block.SetCellType(localPos, type);
            return(block);
        }
Ejemplo n.º 9
0
        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);
        }
Ejemplo n.º 10
0
        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);
        }
Ejemplo n.º 11
0
        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);
        }
Ejemplo n.º 12
0
 public void Move(HexXY p)
 {
     if (!cantMove && WorldBlock.CanTryToMoveToBlockType(Level.S.GetPFBlockedMap(p)) &&
         (!dest.HasValue || p != dest))
     {
         afterMoveAction = null;
         dest            = p;
         distToStop      = 0;
         MovePart();
     }
 }
Ejemplo n.º 13
0
        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);
            }
        }
Ejemplo n.º 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
     }
 }
Ejemplo n.º 15
0
        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]);
            }
        }
Ejemplo n.º 16
0
        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));
            }
        }
Ejemplo n.º 17
0
        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);
                }
            }
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
            }
        }
Ejemplo n.º 20
0
        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);
        }
Ejemplo n.º 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);
            }
        }
Ejemplo n.º 22
0
 public void Add(HexXY p, WorldBlock block)
 {
     all.Add(p, block);
 }