Ejemplo n.º 1
0
    public bool TryMoveTo(Port port)
    {
        bool res = navAgent.MoveTo(port.CornerPosition, NavAgent.ToInt(port.CornerPosition));

        if (res)
        {
            Target = port;
        }
        return(res);
    }
Ejemplo n.º 2
0
    public static void CalculateTownCollide(NavAgent agent)
    {
        Vector2 p = agent.pos;

        Vector2Int cell   = NavAgent.ToInt(p);
        Region     region = agent.lastCollidedTown;

        bool Collide()
        {
            if ((region.pos - p).sqrMagnitude < townRadiusSqr)
            {
                if (region.curOwner == agent.owner)
                {
                    agent.InTown = true;
                    return(true);
                }
                Vector2 n = (p - region.pos);
                agent.CollideForce += n.normalized * (1f - n.sqrMagnitude / townRadiusSqr);

                return(true);
            }
            return(false);
        }

        if (region != null)
        {
            if (Collide())
            {
                return;
            }
        }
        region = MapMetrics.GetRegion(cell);
        if (region.Capital == cell)
        {
            if (Collide())
            {
                return;
            }
        }
        foreach (var d in MapMetrics.OctoDelta)
        {
            if ((region = MapMetrics.GetRegion(cell + d))?.Capital == cell + d)
            {
                if (Collide())
                {
                    return;
                }
            }
        }
        agent.InTown           = false;
        agent.lastCollidedTown = null;
    }