コード例 #1
0
 public override bool TryGetValue(GridVector location, int zoomlevel, out MaptileData data)
 {
     data = default(MaptileData);
     using (var connection = new NpgsqlConnection(m_ConnectionString))
     {
         connection.Open();
         using (var cmd = new NpgsqlCommand("SELECT * FROM maptiles WHERE \"LocX\" = @locx AND \"LocY\" = @locy AND \"ZoomLevel\" = @zoomlevel LIMIT 1", connection))
         {
             cmd.Parameters.AddParameter("@locx", location.X);
             cmd.Parameters.AddParameter("@locy", location.Y);
             cmd.Parameters.AddParameter("@zoomlevel", zoomlevel);
             using (NpgsqlDataReader reader = cmd.ExecuteReader())
             {
                 if (reader.Read())
                 {
                     data             = new MaptileData();
                     data.Location.X  = (uint)(int)reader["LocX"];
                     data.Location.Y  = (uint)(int)reader["LocY"];
                     data.LastUpdate  = reader.GetDate("LastUpdate");
                     data.ContentType = (string)reader["ContentType"];
                     data.ZoomLevel   = (int)reader["ZoomLevel"];
                     data.Data        = reader.GetBytes("Data");
                     return(true);
                 }
             }
         }
     }
     return(false);
 }
コード例 #2
0
    public override bool Equals(object obj)
    {
        if (obj == null)
        {
            return(false);
        }
        if (this.GetType() != obj.GetType())
        {
            return(false);
        }

        if (object.ReferenceEquals(obj, null) && object.ReferenceEquals(this, null))
        {
            return(true);
        }

        if (object.ReferenceEquals(null, obj) || object.ReferenceEquals(null, this))
        {
            return(false);
        }

        GridVector vector = (GridVector)obj;

        return(vector.X == this.X && vector.Y == this.Y);
    }
コード例 #3
0
        public override List <MaptileInfo> GetUpdateTimes(GridVector minloc, GridVector maxloc, int zoomlevel)
        {
            var infos = new List <MaptileInfo>();

            using (var connection = new NpgsqlConnection(m_ConnectionString))
            {
                connection.Open();
                using (var cmd = new NpgsqlCommand("SELECT \"LocX\", \"LocY\", \"LastUpdate\" FROM maptiles WHERE \"ZoomLevel\" = @zoomlevel AND \"LocX\" >= @locxlow AND \"LocY\" >= @locylow AND \"LocX\" <= @locxhigh AND \"LocY\" <= @locyhigh", connection))
                {
                    cmd.Parameters.AddParameter("@zoomlevel", zoomlevel);
                    cmd.Parameters.AddParameter("@locxlow", minloc.X);
                    cmd.Parameters.AddParameter("@locylow", minloc.Y);
                    cmd.Parameters.AddParameter("@locxhigh", maxloc.X);
                    cmd.Parameters.AddParameter("@locyhigh", maxloc.Y);
                    using (NpgsqlDataReader reader = cmd.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            var info = new MaptileInfo
                            {
                                Location = new GridVector {
                                    X = (uint)(int)reader["LocX"], Y = (uint)(int)reader["LocY"]
                                },
                                LastUpdate = reader.GetDate("LastUpdate"),
                                ZoomLevel  = zoomlevel
                            };
                            infos.Add(info);
                        }
                    }
                }
            }
            return(infos);
        }
コード例 #4
0
        public override List <MaptileInfo> GetUpdateTimes(UUID scopeid, GridVector minloc, GridVector maxloc, int zoomlevel)
        {
            var infos = new List <MaptileInfo>();

            using (var connection = new MySqlConnection(m_ConnectionString))
            {
                connection.Open();
                using (var cmd = new MySqlCommand("SELECT LocX, LocY, LastUpdate FROM maptiles WHERE ScopeID = @scopeid AND ZoomLevel = @zoomlevel AND locX >= @locxlow AND locY >= @locylow AND locX <= @locxhigh AND locY <= @locyhigh", connection))
                {
                    cmd.Parameters.AddParameter("@scopeid", scopeid);
                    cmd.Parameters.AddParameter("@zoomlevel", zoomlevel);
                    cmd.Parameters.AddParameter("@locxlow", minloc.X);
                    cmd.Parameters.AddParameter("@locylow", minloc.Y);
                    cmd.Parameters.AddParameter("@locxhigh", maxloc.X);
                    cmd.Parameters.AddParameter("@locyhigh", maxloc.Y);
                    using (MySqlDataReader reader = cmd.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            var info = new MaptileInfo()
                            {
                                Location = new GridVector {
                                    X = reader.GetUInt32("LocX"), Y = reader.GetUInt32("LocY")
                                },
                                LastUpdate = reader.GetDate("LastUpdate"),
                                ScopeID    = scopeid,
                                ZoomLevel  = zoomlevel
                            };
                            infos.Add(info);
                        }
                    }
                }
            }
            return(infos);
        }
コード例 #5
0
            private static ParcelInfo LoadParcel(XmlTextReader reader, GridVector regionSize, List <ParcelAccessEntry> whiteList, List <ParcelAccessEntry> blackList)
            {
                var pinfo = new ParcelInfo((int)regionSize.X / 4, (int)regionSize.Y / 4);

                for (;;)
                {
                    if (!reader.Read())
                    {
                        throw new OARFormatException();
                    }

                    switch (reader.NodeType)
                    {
                    case XmlNodeType.Element:
                        if (reader.Name != "LandData")
                        {
                            throw new OARFormatException();
                        }
                        LoadParcelInner(reader, pinfo, whiteList, blackList);
                        return(pinfo);

                    default:
                        break;
                    }
                }
            }
コード例 #6
0
        public override List <RegionInfo> GetRegionsByRange(GridVector min, GridVector max)
        {
            var result = new List <RegionInfo>();

            using (var connection = new MySqlConnection(m_ConnectionString))
            {
                connection.Open();
                using (var cmd = new MySqlCommand("SELECT * FROM `" + MySqlHelper.EscapeString(m_TableName) + "` WHERE " +
                                                  "locX+sizeX > @xmin AND locX <= @xmax AND locY+sizeY > @ymin AND locY <= @ymax", connection))
                {
                    cmd.Parameters.AddWithValue("@xmin", min.X);
                    cmd.Parameters.AddWithValue("@ymin", min.Y);
                    cmd.Parameters.AddWithValue("@xmax", max.X);
                    cmd.Parameters.AddWithValue("@ymax", max.Y);
                    using (MySqlDataReader dbReader = cmd.ExecuteReader())
                    {
                        while (dbReader.Read())
                        {
                            result.Add(ToRegionInfo(dbReader));
                        }
                    }
                }
            }

            return(result);
        }
コード例 #7
0
    public GridVector CheckforHuman(GridVector g)
    {
        //print("Count: " + GlobalVars.OccupiedGrid.Count);

        foreach (GridVector grid in GlobalVars.OccupiedGrid)
        {
            if (turnController.GetUnitAt(grid) != null)
            {
                //print("Owner: " + turnController.GetUnitAt(grid).GetComponent<attachableUnitDetails>().owner);

                if (turnController.GetUnitAt(grid).GetComponent<attachableUnitDetails>().owner == 0)
                {
                    if (Vector2.Distance(new Vector2(g.x, g.z), new Vector2(grid.x, grid.z)) == 1)
                    {
                        print("Trying: " + Vector2.Distance(new Vector2(g.x, g.z), new Vector2(grid.x, grid.z)));
                        print("Made it: " + turnController.GetUnitAt(grid).GetComponent<attachableUnitDetails>().owner);

                        return grid;

                        //print("This is it: " + grid);
                    }
                }
            }
        }

        return null;
    }
コード例 #8
0
    private void AddSequence(GameObject sequence)
    {
        needle += sequenceGaps + 1;

        Vector2   position    = new Vector2(0, needle);
        Transform newSequence = Instantiate(sequence, position, Quaternion.identity, transform).transform;

        int furthestAway = needle;

        foreach (Transform e in newSequence)
        {
            GridVector gridPosition = e.GetComponent <GridTransform>().GridPosition;

            if (gridPosition.Y > furthestAway)
            {
                furthestAway = gridPosition.Y;
            }
            else if (gridPosition.Y < needle)
            {
                Debug.LogWarning("Enemy is under the defined bounds of the sequence!");
            }
        }

        needle = furthestAway;

        Unpack(newSequence);
    }
コード例 #9
0
    public static void UpdateOccupied(GridVector oldGv, GridVector newGv)
    {
        int count = 0;
        int pos = 0;
        bool found = false;

        //Debug.Log(oldGv.x + " : " + oldGv.z);

        foreach (GridVector gv in OccupiedGrid)
        {
            if (oldGv.x == gv.x && oldGv.z == gv.z)
            {
                pos = count;
                found = true;
            }
            
            count++;
        }

        if (found)
        {
            //Debug.Log("Found");
            OccupiedGrid.RemoveAt(pos);
            OccupiedGrid.Add(new GridVector(newGv.x,newGv.z));
        }
        else
        {
            Debug.Log("Not found");
        }

        //Debug.Log("Done");

        //Debug.Log("Count: " + OccupiedGrid.Count);
    }
コード例 #10
0
 public bool CheckforHumanThere(GridVector g)
 {
     if (turnController.GetUnitAt(g).GetComponent<attachableUnitDetails>().owner == 0)
         return false;
     else
         return true;
 }
コード例 #11
0
 public void OnPlayerMove(GridVector where)
 {
     if (where.Y + renderDistance >= needle)
     {
         UpdateChunk(where);
     }
 }
コード例 #12
0
ファイル: CellGridLayout.cs プロジェクト: vain0x/virtual-grid
        public GridVector Measure(GridMeasure available, GridLayoutModel model)
        {
            var row    = RowIndex.From(1);
            var column = ColumnIndex.From(1);

            return(GridVector.Create(row, column));
        }
コード例 #13
0
    //dir is a NON diagonal direction vector
    public List <GridCell> GetGridCellsInLine(GridCell cell, GridVector gridVector, bool includeObstructed = false, bool contiguous = true, Func <GridCell, bool> includeFilter = null)
    {
        List <GridCell> adjGridCells = new List <GridCell>();

        for (int i = 0; ((i < gridVector.Distance) || (gridVector.Distance == 0)); i++)
        {
            cell = GetAdjacentGridCellFromGridCell(cell, gridVector.Direction);
            if (cell != null)
            {
                bool includeGridCell = !GridCellObstructed(cell) && (includeFilter == null || includeFilter(cell));

                if (includeGridCell || includeObstructed)   //if cell wasn't obstructed (or we want to include obstructed ones anyways)
                {
                    adjGridCells.Add(cell);
                }

                if (!includeGridCell && contiguous)   //if the cell was obstructed, and a contiguous line of grid cells were wanted
                {
                    break;
                }
            }
            else
            {
                break;
            }
        }

        return(adjGridCells);
    }
コード例 #14
0
    //dir is a NON diagonal direction vector
    public List <Vector3> GetGridPositionsInLine(Vector3 pos, GridVector gridVector, bool includeObstructed = false, bool contiguous = true, Func <GridCell, bool> includeFilter = null)
    {
        List <Vector3> adjGridSquares = new List <Vector3>();

        for (int i = 0; ((i < gridVector.Distance) || (gridVector.Distance == 0)); i++)
        {
            pos = GetAdjacentGridSquareFromPos(pos, gridVector.Direction);
            GridCell posGridCell = GetGridCellFromPoint(pos);
            if (posGridCell != null)
            {
                bool includeGridCell = !GridCellObstructed(posGridCell) && (includeFilter == null || includeFilter(posGridCell));

                if (includeGridCell || includeObstructed)   //if cell wasn't obstructed (or we want to include obstructed ones anyways)
                {
                    adjGridSquares.Add(pos);
                }

                if (!includeGridCell && contiguous)  //if the cell was obstructed, and a contiguous line of grid cells were wanted
                {
                    break;
                }
            }
            else
            {
                break;
            }
        }

        return(adjGridSquares);
    }
コード例 #15
0
 public static ParcelInfo GetParcelInfo(Stream s, GridVector regionSize, List <ParcelAccessEntry> whiteList, List <ParcelAccessEntry> blackList)
 {
     using (XmlTextReader reader = s.CreateXmlReader())
     {
         return(LoadParcel(reader, regionSize, whiteList, blackList));
     }
 }
コード例 #16
0
        public override List <RegionInfo> GetRegionsByRange(GridVector min, GridVector max)
        {
            var result = new List <RegionInfo>();

            using (var connection = new NpgsqlConnection(m_ConnectionString))
            {
                connection.Open();
                using (var cmd = new NpgsqlCommand("SELECT * FROM " + m_TableName + " WHERE " +
                                                   "\"locX\"+\"sizeX\" > @xmin AND \"locX\" <= @xmax AND \"locY\"+\"sizeY\" > @ymin AND \"locY\" <= @ymax", connection))
                {
                    cmd.Parameters.AddParameter("@xmin", min.X);
                    cmd.Parameters.AddParameter("@ymin", min.Y);
                    cmd.Parameters.AddParameter("@xmax", max.X);
                    cmd.Parameters.AddParameter("@ymax", max.Y);
                    using (NpgsqlDataReader dbReader = cmd.ExecuteReader())
                    {
                        while (dbReader.Read())
                        {
                            result.Add(ToRegionInfo(dbReader));
                        }
                    }
                }
            }

            return(result);
        }
コード例 #17
0
 public override bool TryGetValue(UUID scopeid, GridVector location, int zoomlevel, out MaptileData data)
 {
     data = default(MaptileData);
     using (var connection = new MySqlConnection(m_ConnectionString))
     {
         connection.Open();
         using (var cmd = new MySqlCommand("SELECT * FROM maptiles WHERE LocX = @locx AND LocY = @locy AND ZoomLevel = @zoomlevel", connection))
         {
             cmd.Parameters.AddParameter("@locx", location.X);
             cmd.Parameters.AddParameter("@locy", location.Y);
             cmd.Parameters.AddParameter("@zoomlevel", zoomlevel);
             using (MySqlDataReader reader = cmd.ExecuteReader())
             {
                 if (reader.Read())
                 {
                     data             = new MaptileData();
                     data.Location.X  = reader.GetUInt32("LocX");
                     data.Location.Y  = reader.GetUInt32("LocY");
                     data.ScopeID     = reader.GetUUID("ScopeID");
                     data.LastUpdate  = reader.GetDate("LastUpdate");
                     data.ContentType = reader.GetString("ContentType");
                     data.ZoomLevel   = reader.GetInt32("ZoomLevel");
                     data.Data        = reader.GetBytes("Data");
                     return(true);
                 }
             }
         }
     }
     return(false);
 }
コード例 #18
0
 public void OnPlayerMove(GridVector where)
 {
     if (gridTransform.GridPosition.Y + offscreenDeletion <= where.Y)
     {
         Destroy(gameObject);
     }
 }
コード例 #19
0
    public void GoStraight(GoTypes how)
    {
        GridVector currentPosition = myGridTransform.GridPosition;
        GridVector position        = currentPosition + new GridVector(0, 1);

        MoveTo(position, how);

        animator.SetTrigger("MoveStraight");
    }
コード例 #20
0
    public override void OnPlayerMove(GridVector where)
    {
        GridVector attack = gridTransform.GridPosition - new GridVector(0, 1);

        if (where == attack)
        {
            enemyController.DealDamage(1, 0);
        }
    }
コード例 #21
0
    public void MoveTo(GridVector where)
    {
        foreach (GridTransform g in enemiesList.ListEnemies(where))
        {
            g.GetComponent <EnemyController>().GetPushedBack();
        }

        transform.position = (Vector2) where;
    }
コード例 #22
0
        private void HandleParcelInfoOnLocal(AgentCircuit circuit, GridVector location, SceneInterface scene, ParcelInfoRequest req)
        {
            ParcelInfo pinfo;

            if (scene.Parcels.TryGetValue(req.ParcelID.RegionPos, out pinfo))
            {
                SendParcelInfo(circuit, location, scene.Name, pinfo);
            }
        }
コード例 #23
0
        public override void RelocateRegion(GridVector location)
        {
            RegionInfo ri = GetRegionInfo();

            ri.Location = location;
            GridService.RegisterRegion(ri);
            GridPosition = location;
            RegionStorage?.RegisterRegion(ri);
        }
コード例 #24
0
        public override List <RegionInfo> GetRegionsByRange(GridVector min, GridVector max)
        {
            var res = from region in m_Data.Values where
                      region.Location.X + region.Size.X >= min.X && region.Location.X <= max.X &&
                      region.Location.Y + region.Size.Y > min.Y && region.Location.Y <= max.Y
                      select new RegionInfo(region);

            return(new List <RegionInfo>(res));
        }
コード例 #25
0
    public void OnPlayerMove(GridVector where)
    {
        foreach (GridTransform g in enemies)
        {
            g.SendMessage("OnPlayerMove", where);
        }

        tileScroll.OnPlayerMove(where);
    }
コード例 #26
0
        public GridVector Measure(GridMeasure available, GridLayoutModel model)
        {
            var first = model.Measure(First, available);

            available = available.Reduce(first);

            var second = model.Measure(Second, available);

            return(GridVector.Create(first.Row + second.Row, first.Column.Max(second.Column)));
        }
コード例 #27
0
 public IEnumerable <object> Locate(GridVector index)
 {
     foreach (var element in _elements.Values)
     {
         if (element.LastArrange.ContainsStrictly(index))
         {
             yield return(element.ElementKey);
         }
     }
 }
コード例 #28
0
ファイル: ViewerAgent.cs プロジェクト: ft-/silversim-testing
        public GridVector GetRootAgentGridPosition(GridVector defPos)
        {
            AgentCircuit circuit;

            if (Circuits.TryGetValue(SceneID, out circuit))
            {
                return(circuit.Scene.GridPosition);
            }
            return(defPos);
        }
コード例 #29
0
        public override bool Remove(GridVector location, int zoomlevel)
        {
            bool removed = m_MaptileService.Remove(location, zoomlevel);

            while (++zoomlevel < MaxZoomLevel)
            {
                location = location.AlignToZoomlevel(zoomlevel);
                m_MaptileService.Remove(location, zoomlevel);
            }
            return(removed);
        }
コード例 #30
0
 public MaptileData this[GridVector location, int zoomlevel]
 {
     get
     {
         MaptileData data;
         if (TryGetValue(location, zoomlevel, out data))
         {
             return(data);
         }
         throw new KeyNotFoundException();
     }
 }
コード例 #31
0
        public override void Store(MaptileData data)
        {
            m_MaptileService.Store(data);
            int        zoomlevel = data.ZoomLevel;
            GridVector location  = data.Location;

            while (++zoomlevel < MaxZoomLevel)
            {
                location = location.AlignToZoomlevel(zoomlevel);
                m_MaptileService.Remove(location, zoomlevel);
            }
        }
コード例 #32
0
        public List <RegionInfo> GetNeighbors(RegionInfo thisRegion, uint drawdistance)
        {
            var        neighbors     = new List <RegionInfo>();
            GridVector thisExtentPos = thisRegion.Location + thisRegion.Size;

            foreach (RegionInfo otherRegion in Values)
            {
                if (otherRegion.ID == thisRegion.ID && otherRegion.GridURI == thisRegion.GridURI)
                {
                    GridVector otherExtentPos = otherRegion.Location + otherRegion.Size;

                    /* the first two cases are direct neighbors */
                    if (thisRegion.Location.X == otherExtentPos.X || otherRegion.Location.X == thisExtentPos.X)
                    {
                        if ((thisRegion.Location.Y >= otherRegion.Location.Y && thisRegion.Location.Y < otherExtentPos.Y) ||
                            (otherRegion.Location.Y >= thisRegion.Location.Y && otherRegion.Location.Y < thisExtentPos.Y))
                        {
                            neighbors.Add(otherRegion);
                        }
                    }
                    else if (thisRegion.Location.Y == otherExtentPos.Y || otherRegion.Location.Y == thisExtentPos.Y)
                    {
                        if ((thisRegion.Location.Y >= otherRegion.Location.Y && thisRegion.Location.Y < otherExtentPos.Y) ||
                            (otherRegion.Location.Y >= thisRegion.Location.Y && otherRegion.Location.Y < thisExtentPos.Y))
                        {
                            neighbors.Add(otherRegion);
                        }
                    }
                    else if (IsPointInBox(otherRegion.Location, thisRegion.Location, thisExtentPos, drawdistance) ||
                             IsPointInBox(otherExtentPos, thisRegion.Location, thisExtentPos, drawdistance))
                    {
                        neighbors.Add(otherRegion);
                    }
                    else
                    {
                        GridVector aa;
                        GridVector bb;

                        aa   = otherRegion.Location;
                        bb   = otherExtentPos;
                        aa.Y = otherExtentPos.Y;
                        bb.Y = otherRegion.Location.Y;
                        if (IsPointInBox(aa, thisRegion.Location, thisExtentPos, drawdistance) ||
                            IsPointInBox(bb, thisRegion.Location, thisExtentPos, drawdistance))
                        {
                            neighbors.Add(otherRegion);
                        }
                    }
                }
            }

            return(neighbors);
        }
コード例 #33
0
        public GridVector CacheInterGridDestination(RegionInfo di)
        {
            CleanDestinationCache();
            var hgRegionHandle = new GridVector
            {
                GridX = NewInterGridRegionLocX,
                GridY = 0
            };

            m_InterGridDestinations[hgRegionHandle.RegionHandle] = new KeyValuePair <ulong, RegionInfo>(Date.GetUnixTime(), di);
            return(hgRegionHandle);
        }
コード例 #34
0
    public static bool CheckGridSpace(GridVector curr,int x, int z)
    {
        if(curr != null)
            if (curr.x == x && curr.z == z)
                return false;

        foreach (GridVector gv in OccupiedGrid)
        {
            if (gv.x == x && gv.z == z)
                return false;
        }

        return true;
    }
コード例 #35
0
    public static Color CheckAvailabilityOnGridColor(GridVector curr, GridVector gridVector,bool mode)
    {
        foreach (GridVector gv in GlobalVars.OccupiedGrid)
        {            
            if (gv.x == gridVector.x && gv.z == gridVector.z)
            {
                return WRONG;
            }

        }//foreach

        if (mode)
        {
            if (GlobalVars.CheckGridHalf(gridVector.z))
                return RIGHT;
            else
                return WRONG;
        }
        else
        {
            if ((curr.x + 1) == gridVector.x && curr.z == gridVector.z)
            {
                return RIGHT;
            }

            if ((curr.x - 1) == gridVector.x && curr.z == gridVector.z)
            {
                return RIGHT;
            }

            if (curr.x == gridVector.x && (curr.z + 1) == gridVector.z)
            {
                return RIGHT;
            }

            if (curr.x == gridVector.x && (curr.z - 1) == gridVector.z)
            {
                return RIGHT;
            }

            ////////////////////////////////////////////////////////////////

            if ((curr.x + 1) == gridVector.x && (curr.z + 1) == gridVector.z)
            {
                return RIGHT;
            }

            if ((curr.x - 1) == gridVector.x && (curr.z + 1) == gridVector.z)
            {
                return RIGHT;
            }

            if ((curr.x + 1) == gridVector.x && (curr.z - 1) == gridVector.z)
            {
                return RIGHT;
            }

            if ((curr.x - 1) == gridVector.x && (curr.z - 1) == gridVector.z)
            {
                return RIGHT;
            }
        }

        return WRONG;

    }// Color
コード例 #36
0
    public static void Remove(GridVector gv)
    {
        int count = 0;
        int pos = 0;
        bool found = false;

        Debug.Log("Removing");

        foreach (GridVector g in OccupiedGrid)
        {
            if(g.x == gv.x && g.z == gv.z)
            {
                Debug.Log("Found");
                pos = count;
                found = true;
            }

            count++;
        }

        if(found)
        {
            Debug.Log("Removed properly");
            OccupiedGrid.RemoveAt(pos);
        }
    }
コード例 #37
0
    }// Color

    public static bool CheckImmediateAdjacencyOnGrid(GridVector currP,GridVector otherP)
    {
        /// N,S,E,W
        
        //print(currP.x + "," + currP.z + " : " + otherP.x + "," + otherP.z);

        try
        {
            if (otherP.x == currP.x && otherP.z == currP.z + 1) // north
            {
                return true;
            }
        }catch(Exception e){e.ToString();}

        try
        {
            if (otherP.x == currP.x && otherP.z == currP.z - 1) // south
            {
                return true;
            }
        }
        catch (Exception e) { e.ToString(); }

        try
        {
            if (otherP.x == currP.x + 1 && otherP.z == currP.z) // east
            {
                return true;
            }
        }
        catch (Exception e) { e.ToString(); }

        try
        {
            if (otherP.x == currP.x - 1 && otherP.z == currP.z) // west
            {
                return true;
            }
        }
        catch (Exception e) { e.ToString(); }

        /// NE,NW,SE,NW

        try
        {
            if (otherP.x == currP.x - 1 && otherP.z == currP.z + 1) // north east
            {
                return true;
            }
        }
        catch (Exception e) { e.ToString(); }

        try
        {
            if (otherP.x == currP.x + 1 && otherP.z == currP.z + 1) // north west
            {
                return true;
            }
        }
        catch (Exception e) { e.ToString(); }

        try
        {
            if (otherP.x == currP.x - 1 && otherP.z == currP.z - 1) // south east
            {
                return true;
            }
        }
        catch (Exception e) { e.ToString(); }

        try
        {
            if (otherP.x == currP.x + 1 && otherP.z == currP.z - 1) // south west
            {
                return true;
            }
        }
        catch (Exception e) { e.ToString(); }

        ///

        return false;
    }
コード例 #38
0
ファイル: GridManager.cs プロジェクト: hubatish/hftMaze
 public IEnumerable<RaycastHit2D> GetHitsAtij(GridVector ijPos)
 {
     return GetHitsAtPos(ijToxy(ijPos));
 }
コード例 #39
0
    public void ShowMovementSquares(GridVector CurrentPosition,int MovementCount)
    {
        CleanUpTiles();

        print("Creating Tiles");

        for (int i = 0; i < MovementCount; i++) // North
        {
            if (Grid.CheckAvailabilityOnGrid(new GridVector(CurrentPosition.x, CurrentPosition.z + i)))
            {
                GameObject temp = Instantiate(PredictTile, new Vector3(CurrentPosition.x, 0, CurrentPosition.z + i), Quaternion.identity) as GameObject;
                temp.transform.parent = PredictiveTileHolder.transform;
                PredictiveTiles.Add(temp);
                temp.gameObject.name = Count + "";
                Count++;
            }

            for (int j = 1; j < MovementCount; j++) // Left
            {
                if (Grid.CheckAvailabilityOnGrid(new GridVector(CurrentPosition.x - j,CurrentPosition.z + i)))
                {
                    GameObject temp = Instantiate(PredictTile, new Vector3(CurrentPosition.x - j, 0, CurrentPosition.z + i), Quaternion.identity) as GameObject;
                    temp.transform.parent = PredictiveTileHolder.transform;
                    PredictiveTiles.Add(temp);
                    temp.gameObject.name = Count + "";
                    Count++;
                }
            }

            for (int k = 1; k < MovementCount; k++) // Right
            {

                if (Grid.CheckAvailabilityOnGrid(new GridVector(CurrentPosition.x + k, CurrentPosition.z + i)))
                {
                    GameObject temp = Instantiate(PredictTile, new Vector3(CurrentPosition.x + k, 0, CurrentPosition.z + i), Quaternion.identity) as GameObject;
                    temp.transform.parent = PredictiveTileHolder.transform;
                    PredictiveTiles.Add(temp);
                    temp.gameObject.name = Count + "";
                    Count++;
                }
            }
        }

       
        for (int i = 1; i < MovementCount; i++) // South
        {
            
            if (Grid.CheckAvailabilityOnGrid(new GridVector(CurrentPosition.x, CurrentPosition.z - i)))
            {
                GameObject temp = Instantiate(PredictTile, new Vector3(CurrentPosition.x, 0, CurrentPosition.z - i), Quaternion.identity) as GameObject;
                temp.transform.parent = PredictiveTileHolder.transform;
                PredictiveTiles.Add(temp);
                temp.gameObject.name = Count + "";
                Count++;
            }
            
            
            for (int j = 1; j < MovementCount; j++) // Left
            {
                if (Grid.CheckAvailabilityOnGrid(new GridVector(CurrentPosition.x - j, CurrentPosition.z - i)))
                {
                    GameObject temp = Instantiate(PredictTile, new Vector3(CurrentPosition.x - j, 0, CurrentPosition.z - i), Quaternion.identity) as GameObject;
                    temp.transform.parent = PredictiveTileHolder.transform;
                    PredictiveTiles.Add(temp);
                    temp.gameObject.name = Count + "";
                    Count++;
                }
            }

            for (int k = 1; k < MovementCount; k++) // Right
            {
                if (Grid.CheckAvailabilityOnGrid(new GridVector(CurrentPosition.x + k, CurrentPosition.z - i)))
                {
                    GameObject temp = Instantiate(PredictTile, new Vector3(CurrentPosition.x + k, 0, CurrentPosition.z - i), Quaternion.identity) as GameObject;
                    temp.transform.parent = PredictiveTileHolder.transform;
                    PredictiveTiles.Add(temp);
                    temp.gameObject.name = Count + "";
                    Count++;
                }
            }
        }
    }
コード例 #40
0
ファイル: GridManager.cs プロジェクト: hubatish/hftMaze
 public Vector2 ijToxy(GridVector ijPos)
 {
     return new Vector2((float)xOffset + ijPos.x * xGridSize, (float)yOffset + ijPos.y * yGridSize);
 }
コード例 #41
0
ファイル: GridManager.cs プロジェクト: hubatish/hftMaze
 //given an ij in grid, return that block's real x,y,z location
 public Vector3 ijToxyz(GridVector ijPos)
 {
     return new Vector3((float)xOffset + ijPos.x * xGridSize, (float)yOffset + ijPos.y * yGridSize, transform.position.z);
 }
コード例 #42
0
    }// Color

    public static bool CheckAvailabilityOnGrid(GridVector gridVector)
    {
        foreach (GridVector gv in GlobalVars.OccupiedGrid)
        {
            if (gv.x == gridVector.x && gv.z == gridVector.z)
            {
                return false;
            }

        }//foreach

        return true;

    }// Color
コード例 #43
0
    public void PlaceUnits()
    {
        GameObject compUnit;
        attachableUnitDetails deets;

        GridVector curr = new GridVector(-1, -1);

        while (GlobalVars.ComputerPlacedCount < GlobalVars.MAX_UNITS)
        {
            compUnit = new GameObject();            
            compUnit.transform.parent = compPieces.transform;

            deets = compUnit.gameObject.AddComponent<attachableUnitDetails>();

            deets.unit = new Unit();
            deets.unit.BAB = 15;
            deets.unit.maxHealth = 30;
            deets.unit.health = 30;
            deets.unit.armorClass = 15;

            switch(Random.Range(0,3))
            {
                case 0:
                    deets._class = new Fighter();
                    deets._class.spriteImage = spriteModels.dwarf_fighter;
                    deets._class.model = spriteModels.model_dwarf_fighter;
                    deets._class.level = 3;
                    break;

                case 1:
                    deets._class = new Ranger();
                    deets._class.spriteImage = spriteModels.dwarf_ranger;
                    deets._class.model = spriteModels.model_dwarf_ranger;
                    deets._class.level = 3;
                    break;

                case 2:
                    deets._class = new Sorcerer();
                    deets._class.spriteImage = spriteModels.dwarf_sorcerer;
                    deets._class.model = spriteModels.model_dwarf_sorcerer;
                    deets._class.level = 3;
                    break;
            }
            
            compUnit.gameObject.name = deets._class.ToString();

            TurnController.compUnits.Add(compUnit.gameObject);

            ////////////////////////////////////////////////////////////////////////////////////

            GameObject unitModel = TurnController.compUnits[GlobalVars.ComputerPlacedCount].gameObject.GetComponent<attachableUnitDetails>()._class.model;
            attachableUnitDetails compModComp = TurnController.compUnits[GlobalVars.ComputerPlacedCount].gameObject.GetComponent<attachableUnitDetails>();

            compModComp.owner = 1;

            unitModel.transform.Find("Tops").GetComponent<SkinnedMeshRenderer>().material = compMat;

            //

            bool foundPlace = false;

            while(!foundPlace)
            {
                x = Random.Range(1, GlobalVars.GridSize);
                z = Random.Range(GlobalVars.GridSize - GlobalVars.StartRowCount, GlobalVars.GridSize);

                foundPlace = GlobalVars.CheckGridSpace(curr, x, z);
            }

            compModComp._class.gridVector = new GridVector(x, z);

            GlobalVars.OccupiedGrid.Add(new GridVector(x, z));

            //print("X: " + x + " Z: " + z);

            Vector3 finalPosition = new Vector3(x , 0, z);

            //

            Quaternion q = new Quaternion(0, 180.0f, 0, 0);

            compModComp._class.unitBoardModel = Instantiate(unitModel, finalPosition, q) as GameObject;

            compModComp._class.unitBoardModel.name = "Computer Model Player: " + TurnController.playerUnits[GlobalVars.ComputerPlacedCount].gameObject.GetComponent<attachableUnitDetails>()._class.model.name;

            compModComp._class.unitBoardModel.gameObject.transform.SetParent(compPieces.transform);
            
            GlobalVars.ComputerPlacedCount++;
        }

        //print("GlobalVars.OccupiedGrid: " + GlobalVars.OccupiedGrid.Count);
    }
コード例 #44
0
    public void FindAndAttack(GameObject enemyCurr)
    {
        GameObject currentEnemy = enemyCurr;
        GameObject closestPlayerUnit = null;
        int closestCost = 100;

        //Quaternion q = new Quaternion(0, 0, 0, 0);
        //Quaternion q2 = new Quaternion(0, 180.0f, 0, 0);

        foreach (GameObject go in TurnController.playerUnits)
        {
            int x = CostDistance(currentEnemy, go);

            if (x < closestCost)
            {
                closestPlayerUnit = go;
                closestCost = x;
            }
        }

        GridVector e = enemyCurr.GetComponent<attachableUnitDetails>()._class.gridVector;
        GridVector p = closestPlayerUnit.GetComponent<attachableUnitDetails>()._class.gridVector;

        Vector3 finalPosition = Vector3.zero;
        GridVector gv;

        ////////////////////////////////////////////////////////////////////////
        /// MAKE COMPUTER MOVE
        //////////////////////////////////////////////////////////////////////

        bool attackRange = false;

        GridVector close = grid.CheckforHuman(e);

        if (close != null)
        {
            //print("In attack range");
            
            GameObject go = turnController.GetUnitAt(close);
            
            int difference = go.GetComponent<attachableUnitDetails>().unit.health;

            //print("Health Before: " + go.GetComponent<attachableUnitDetails>().unit.health);

            go.GetComponent<attachableUnitDetails>().unit.takeDmg(enemyCurr.GetComponent<attachableUnitDetails>().unit.compAtk());

            //print("Health After: " + go.GetComponent<attachableUnitDetails>().unit.health);

            difference -= go.GetComponent<attachableUnitDetails>().unit.health;

            messageController.UpdateStatusMessage("Attacked by player for: " + difference + "!");

            AttackAnimation(enemyCurr.GetComponent<attachableUnitDetails>()._class.unitBoardModel,go.GetComponent<attachableUnitDetails>()._class.unitBoardModel);

            CheckPlayerDead(go);

            attackRange = true;
        }
        
        if(!attackRange)
        {
            //print("Computer Compare: " + e.z + " " + p.z);

            GridVector curr = new GridVector(-1, -1);

            if (e.z < p.z)
            {
                gv = new GridVector(e.x, e.z + 1);
                
                if (GlobalVars.CheckGridSpace(curr,gv.x, gv.z))
                {
                    //print("1");

                    finalPosition = new Vector3(e.x, 0, e.z + 1);

                    StartCoroutine(WalkAnimation(enemyCurr.GetComponent<attachableUnitDetails>()._class.unitBoardModel, finalPosition, 12f));

                    GlobalVars.UpdateOccupied(enemyCurr.GetComponent<attachableUnitDetails>()._class.gridVector, gv);

                    enemyCurr.GetComponent<attachableUnitDetails>()._class.gridVector = gv;
                }
            }
            else if(e.z > p.z)
            {
                gv = new GridVector(e.x, e.z - 1);

                if (GlobalVars.CheckGridSpace(curr, gv.x, gv.z))
                {
                    //print("2");

                    finalPosition = new Vector3(e.x, 0, e.z - 1);

                    StartCoroutine(WalkAnimation(enemyCurr.GetComponent<attachableUnitDetails>()._class.unitBoardModel, finalPosition, 12f));

                    GlobalVars.UpdateOccupied(enemyCurr.GetComponent<attachableUnitDetails>()._class.gridVector, gv);
                    
                    enemyCurr.GetComponent<attachableUnitDetails>()._class.gridVector = gv;
                }
            }
            else
            {
                if (e.x > p.x)
                {
                    gv = new GridVector(e.x - 1, e.z);

                    if (GlobalVars.CheckGridSpace(curr, gv.x, gv.z))
                    {
                        //print("3");

                        finalPosition = new Vector3((e.x - 1), 0, e.z);

                        StartCoroutine(WalkAnimation(enemyCurr.GetComponent<attachableUnitDetails>()._class.unitBoardModel, finalPosition, 12f));

                        GlobalVars.UpdateOccupied(enemyCurr.GetComponent<attachableUnitDetails>()._class.gridVector, gv);

                        enemyCurr.GetComponent<attachableUnitDetails>()._class.gridVector = gv;
                    }
                }
                else
                {

                    gv = new GridVector(e.x + 1, e.z);

                    if (GlobalVars.CheckGridSpace(curr, gv.x, gv.z))
                    {
                        //print("4");

                        finalPosition = new Vector3((e.x + 1), 0, e.z);
                        
                        StartCoroutine(WalkAnimation(enemyCurr.GetComponent<attachableUnitDetails>()._class.unitBoardModel, finalPosition, 12f));

                        GlobalVars.UpdateOccupied(enemyCurr.GetComponent<attachableUnitDetails>()._class.gridVector, gv);
                        
                        enemyCurr.GetComponent<attachableUnitDetails>()._class.gridVector = gv;
                    }
                }

            }

            //print("Final position: " + finalPosition);
        }
    }
コード例 #45
0
ファイル: GridManager.cs プロジェクト: hubatish/hftMaze
 //given an xy, return what that would be in i, j, from grid
 public GridVector xyToij(Vector2 xyPos)
 {
     GridVector ijPos = new GridVector();
         ijPos.x = (int)Mathf.Round((xyPos.x - xOffset) / xGridSize);
         ijPos.y = (int)Mathf.Round((xyPos.y - yOffset) / yGridSize);
         return ijPos;
 }
コード例 #46
0
    public void OnPointerClick(PointerEventData eventData)
    {
        //print(gameObject.name + " " + GlobalVars.PLACE_MODE + " " + GlobalVars.MOUSE);
        
        currentPosition = new Vector3(gv.x, 0, gv.z);

        if (GlobalVars.PLACE_MODE && GlobalVars.MOUSE)
        {
            if (currentPosition.x >= 0.5f && currentPosition.x <= GlobalVars.GridSize + 0.5f && currentPosition.z >= 0.5f && currentPosition.z <= GlobalVars.GridSize + 0.5f) // Mouse Cursor withing Grid
            {
                SelectedTile.gameObject.GetComponent<MeshRenderer>().enabled = true;

                float x, y, z;

                if (currentPosition.x < 1)
                {
                    x = 1;
                }
                else
                {
                    x = (float)Math.Floor(currentPosition.x);
                }

                if (currentPosition.z < 1)
                {
                    z = 1;
                }
                else
                {
                    z = (float)Math.Floor(currentPosition.z);
                }

                y = Height;

                Vector3 finalPosition = new Vector3(x, y, z);
                int xi, zi;

                xi = Convert.ToInt32(x);
                zi = Convert.ToInt32(z);

                GridVector curr = new GridVector(-1, -1);

                if (GlobalVars.CheckGridHalf(zi))
                {
                    if (GlobalVars.PlacedCount < TurnController.playerUnits.Count && GlobalVars.CheckGridSpace(curr, xi, zi))
                    {
                        if (currentPosition.x >= 0.5f && currentPosition.x <= GlobalVars.GridSize + 0.5f && currentPosition.z >= 0.5f && currentPosition.z <= GlobalVars.GridSize + 0.5f)
                        {
                            CreatePlayerPiece(finalPosition, xi, zi);
                        }
                    }

                    if (GlobalVars.PlacedCount >= TurnController.playerUnits.Count)
                    {
                        GlobalVars.PLACE_MODE = false;
                        SelectedTile.gameObject.GetComponent<MeshRenderer>().enabled = false;
                        placeunits.donePlacing();
                    }

                }

                SelectedTile.transform.position = finalPosition;

                SelectedTile.GetComponent<MeshRenderer>().sharedMaterial.color = Grid.CheckAvailabilityOnGridColor(null, new GridVector((int)SelectedTile.transform.position.x, (int)SelectedTile.transform.position.z), true);
            }
            else
            {
                SelectedTile.gameObject.GetComponent<MeshRenderer>().enabled = false;
            }
        }

        ////////////////////////////////////////////////////////////////////////////////////////////

        if (GlobalVars.PLAYER_TURN && GlobalVars.MOUSE)
        {
            //print("player move");

            if (currentPosition.x >= 0 && currentPosition.x <= GlobalVars.GridSize && currentPosition.z >= 0 && currentPosition.z <= GlobalVars.GridSize) // Mouse Cursor withing Grid
            {
                SelectedTile.gameObject.GetComponent<MeshRenderer>().enabled = true;
                
                Vector3 finalPosition = new Vector3(currentPosition.x, currentPosition.y, currentPosition.z);
                int xi, zi;

                xi = Convert.ToInt32(currentPosition.x);
                zi = Convert.ToInt32(currentPosition.z);

                GridVector temp = new GridVector(xi, zi);

                GridVector tempgv = turnController.currentTurnUnit.GetComponent<attachableUnitDetails>()._class.gridVector;

                ////////////////////////////////////////
                
                if (GlobalVars.CheckGridSpace(tempgv, xi, zi))
                {
                    //print("Free Grid space");

                    if (Grid.CheckImmediateAdjacencyOnGrid(tempgv, temp))
                    {
                        walkUnitToSpace(turnController.currentTurnUnit.GetComponent<attachableUnitDetails>()._class.unitBoardModel,finalPosition);

                        GlobalVars.UpdateOccupied(tempgv, temp);

                        turnController.currentTurnUnit.GetComponent<attachableUnitDetails>()._class.gridVector = new GridVector(temp.x, temp.z);

                        turnController.unitTurn++;
                    }

                    SelectedTile.gameObject.GetComponent<MeshRenderer>().enabled = false;

                    GlobalVars.PLAYER_TURN = false;
                }
                else
                {

                    if(Grid.CheckImmediateAdjacencyOnGrid(tempgv, temp) && gridscr.CheckforHumanThere(temp))
                    {
                        GlobalVars.PLAYER_TURN = false;

                        print("Attacking");

                        GameObject go = turnController.GetUnitAt(new GridVector(xi, zi));

                        int difference = go.GetComponent<attachableUnitDetails>().unit.health;

                        go.GetComponent<attachableUnitDetails>().unit.takeDmg(turnController.currentTurnUnit.GetComponent<attachableUnitDetails>().unit.playerAtk());

                        difference -= go.GetComponent<attachableUnitDetails>().unit.health;

                        messageController.UpdateStatusMessage("Attacked the computer for: " + difference + "!");

                        dumbComputer.CheckComputerDead(go);

                        AttackAnimation(turnController.currentTurnUnit.GetComponent<attachableUnitDetails>()._class.unitBoardModel, go);

                        GlobalVars.GoldCount += 50;

                        turnController.unitTurn++;
                    }
                    else
                        print("Not Attacking: " + Grid.CheckImmediateAdjacencyOnGrid(tempgv, temp) + " : " + gridscr.CheckforHuman(gv) == null);

                    turnController.DrawHealth();
                }

                SelectedTile.transform.position = finalPosition;

                SelectedTile.GetComponent<MeshRenderer>().sharedMaterial.color = Grid.CheckAvailabilityOnGridColor(gv, new GridVector((int)SelectedTile.transform.position.x, (int)SelectedTile.transform.position.z), false);
            }
            else
                SelectedTile.gameObject.GetComponent<MeshRenderer>().enabled = false;

        }
    }
コード例 #47
0
 public void setGrid(int x,int z)
 {
     gv = new GridVector(x, z);
 }
コード例 #48
0
    public GameObject GetUnitAt(GridVector gridVector)
    {
        foreach (GameObject go in compUnits)
        {
            if (go.GetComponent<attachableUnitDetails>()._class.gridVector.x == gridVector.x && go.GetComponent<attachableUnitDetails>()._class.gridVector.z == gridVector.z)
            {
                return go;
            }
        }

        foreach (GameObject go in playerUnits)
        {
            if (go.GetComponent<attachableUnitDetails>()._class.gridVector.x == gridVector.x && go.GetComponent<attachableUnitDetails>()._class.gridVector.z == gridVector.z)
            {
                return go;
            }
        }

        return null;
    }