Beispiel #1
0
    //Finds and returns a list of valid neighbors around a given point
    private static List <OddQPoint> Neighbors(OddQPoint center)
    {
        List <OddQPoint> items = new List <OddQPoint>();

        int parity = center.q & 1;

        OddQPoint n;

        foreach (OddQPoint dir in directions[parity])
        {
            n = new OddQPoint(center.q + dir.q, center.r + dir.r);

            if (MapMaster.IsCellOnMap(n.q, n.r))
            {
                items.Add(n);
            }
        }

        return(items);
    }
Beispiel #2
0
    public static void DecideMove()
    {
        if (target != null)
        {
            if (Input.GetKey(KeyCode.Mouse0))
            {
                instance.BuildMarker();
            }
            else if (Input.GetKeyUp(KeyCode.Mouse0) && instance.radiusMarker != null)
            {
                instance.timePressed = 0;

                foreach (HexCell h in MapMaster.CellsWithinArea(target.CurrentHex, instance.uSize))
                {
                    Unit u = h.Unit;
                    if (u != null)
                    {
                        if (!u.Moved && u.Player == PlayerMaster.CurrentTurn)
                        {
                            instance.uQue.Add(u);
                        }
                    }
                }

                GameObject.Destroy(instance.radiusMarker);
                instance.radiusMarker = null;
                instance.uSize        = 0;
                // target = null;
            }
        }

        if (Input.GetKeyDown(KeyCode.Mouse0) /*&& Events.GetComponent<Pause>().paused == false*/)
        {
            Ray        ray;
            RaycastHit hit;
            ray = Camera.main.ScreenPointToRay(Input.mousePosition);

            if (Physics.Raycast(ray, out hit))
            {
                Unit    u = hit.transform.gameObject.GetComponent <Unit>();
                HexCell h = hit.transform.gameObject.GetComponent <HexCell>();
                //Debug.Log(u == null ? "" : u.UName);

                if (u != null)
                {
                    SetTarget(u);
                }
                else if (h != null)
                {
                    if (instance.uQue.Count == 0)
                    {
                        EvaluateTile(h);
                    }
                    else
                    {
                        if (target != null)
                        {
                            HighlightMaster.ToggleTileHighlights(false, MapMaster.CellsWithinArea(target.CurrentHex, target.MoveSpeed));

                            Vector3 directionVector = HexCell.TravelDirection(target.CurrentHex.Cube, h.Cube);
                            Vector2 endpoint;
                            HexCell goal;

                            List <HexCell> newPath;

                            List <KeyValuePair <Unit, List <HexCell> > > paths = new List <KeyValuePair <Unit, List <HexCell> > >();

                            foreach (Unit un in instance.uQue)
                            {
                                un.CurrentHex.passable = true;
                            }
                            foreach (Unit un in instance.uQue)
                            {
                                endpoint = HexCell.NewLocationInOffset(un.CurrentHex.Cube, directionVector);
                                if (!MapMaster.IsCellOnMap((int)endpoint.y, (int)endpoint.x))
                                {
                                    continue;
                                }
                                goal    = MapMaster.Map[(int)endpoint.y, (int)endpoint.x];
                                newPath = HexStar.GetPath(un.CurrentHex, goal, un.MoveSpeed);
                                if (newPath.Count > 0)
                                {
                                    paths.Add(new KeyValuePair <Unit, List <HexCell> >(un, newPath));
                                }
                                else
                                {
                                    un.CurrentHex.passable = false;
                                }
                            }

                            EvaluateTileGroup(paths);
                            instance.uQue.Clear();
                            if (!target.Moved && target.UName == "Infantry")
                            {
                                target.GetComponentInChildren <Animator>().Play("GoToIdle");
                            }
                            target = null;
                        }
                    }
                }
            }
        }
    }