Ejemplo n.º 1
0
    public SightInfo[,] GetPoliceSight()
    {
        if (policeSightRule == null)
        {
            policeSightRule =
                new SightRay(0, 0, new SightRay[]
            {
                new SightRay(1, 0, new SightRay[]
                {
                    new SightRay(0, -1, new SightRay[]
                    {
                        new SightRay(1, 0)
                    }),
                    new SightRay(1, 0, new SightRay[]
                    {
                        new SightRay(1, 0)
                    }),
                    new SightRay(0, 1, new SightRay[]
                    {
                        new SightRay(1, 0)
                    })
                })
            });
        }
        SightInfo[,] sightInfos = new SightInfo[mapSizeX, mapSizeY];
        for (int x = 0; x < mapSizeX; x++)
        {
            for (int y = 0; y < mapSizeY; y++)
            {
                sightInfos[x, y] = new SightInfo();
            }
        }

        for (int i = 0; i < polices.Length; i++)
        {
            Vector2Int policePos = new Vector2Int((int)polices[i].mapPos.x, (int)polices[i].mapPos.y);
            int        sin       = (int)Mathf.Sin((int)polices[i].angle * Mathf.Deg2Rad);
            int        cos       = (int)Mathf.Cos((int)polices[i].angle * Mathf.Deg2Rad);

            PoliceSightDFS(sightInfos, policePos, sin, cos, policeSightRule);
        }

        return(sightInfos);
    }
Ejemplo n.º 2
0
    public SightInfo[,] GetThiefSight()
    {
        SightInfo[,] sightInfos = new SightInfo[mapSizeX, mapSizeY];
        for (int x = 0; x < mapSizeX; x++)
        {
            for (int y = 0; y < mapSizeY; y++)
            {
                sightInfos[x, y] = new SightInfo();
            }
        }
        for (int i = 0; i < thieves.Length; i++)
        {
            if (thieves[i] != null)
            {
                Vector2Int thiefPos = new Vector2Int((int)thieves[i].mapPos.x, (int)thieves[i].mapPos.y);

                Vector2Int minCoord = new Vector2Int(Mathf.Clamp(thiefPos.x - 2, 0, mapSizeX - 1), Mathf.Clamp(thiefPos.y - 2, 0, mapSizeY - 1));
                Vector2Int maxCoord = new Vector2Int(Mathf.Clamp(thiefPos.x + 2, 0, mapSizeX - 1), Mathf.Clamp(thiefPos.y + 2, 0, mapSizeY - 1));
                for (int x = minCoord.x; x <= maxCoord.x; x++)
                {
                    for (int y = minCoord.y; y <= maxCoord.y; y++)
                    {
                        if (map[x, y] != TileType.Wall)
                        {
                            int enemy = 0, treasure = 0;
                            foreach (PoliceInfo police in polices)
                            {
                                if ((int)police.mapPos.x == x && (int)police.mapPos.y == y)
                                {
                                    enemy++;
                                }
                            }
                            if (treasures.TryGetValue(new Vector2(x, y), out TreasureInfo o))
                            {
                                treasure += o.value;
                            }
                            sightInfos[x, y] = new SightInfo(true, enemy, treasure);
                        }
                    }
                }
            }
        }
        return(sightInfos);
    }
Ejemplo n.º 3
0
        /// <summary>
        /// 从一行测量数据中提取信息
        /// </summary>
        /// <param name="strLine">数据行</param>
        /// <param name="LineID">线路ID号</param>
        /// <returns></returns>
        private static SightInfo GetCLData(string strLine, int LineID)
        {
            SightInfo CLData = new SightInfo();

            CLData.LineID  = LineID;
            CLData.Adr     = System.Convert.ToInt32(strLine.Substring(10, 6).Trim());
            CLData.ptName  = strLine.Substring(20, 9).Trim();
            CLData.TimeStr = strLine.Substring(35, 8).Trim();
            if (strLine.Substring(49, 2) == "Rb")
            {
                CLData.SType = "B";
            }
            else
            {
                CLData.SType = "F";
            }
            CLData.RD = System.Convert.ToDouble(strLine.Substring(51, 15).Trim()); // 中丝读数
            CLData.HD = System.Convert.ToDouble(strLine.Substring(74, 15).Trim()); // 视距

            return(CLData);
        }