Пример #1
0
    private static bool PassTeamFilter(ActTargetFilters filters, int team, int teamB)
    {
        bool sameTeam = team == teamB;

        if (sameTeam && filters.ActOnTeamates)
        {
            return(true);
        }
        else if (!sameTeam && filters.ActOnEnemies)
        {
            return(true);
        }
        else
        {
            return(false);
        }
    }
Пример #2
0
    private static void FindAndAddPosibleTargetsToBuffer(FractionalHex position, Fix64 sightRange, ActTargetFilters filters, Team team, Dictionary <Hex, List <EntityOnVision> > unitsForeachHex, List <BuildingOnVision> buildingsOnSight, DynamicBuffer <BEPosibleTarget> buffer)
    {
        Hex roundedPosition = position.Round();

        //buildings
        foreach (var building in buildingsOnSight)
        {
            var buildingHex       = building.building.position;
            var reversedDirection = (position - (FractionalHex)buildingHex).NormalizedManhathan();
            var fullHexTargetPos  = FractionalHex.GetBorderPointOfTheHex(buildingHex, reversedDirection);

            var buildingPos = (FractionalHex)buildingHex;

            if (ValidPossibleTarget(position, sightRange, team.Number, filters, buildingPos, (Fix64)0.5, building.team))
            {
                buffer.Add(new BEPosibleTarget()
                {
                    Position        = buildingPos,
                    Radius          = Fix64.Zero,
                    Entity          = building.entity,
                    IsUnit          = false,
                    OccupiesFullHex = true,
                    OccupyingHex    = buildingHex,
                    GatherTarget    = false,
                    ActTypeTarget   = filters.actType
                });
            }
        }


        //units
        var pointsOfHex = SpartialSortUtils.GetAllPointsAtRange(roundedPosition, (int)Fix64.Ceiling(sightRange), unitsForeachHex);

        foreach (var point in pointsOfHex)
        {
            int    pointTeam   = point.team;
            Entity pointEntity = point.entity;
            var    pointRadius = point.collider.Radius;


            if (ValidPossibleTarget(position, sightRange, team.Number, filters, point.position, pointRadius, pointTeam))
            {
                buffer.Add(new BEPosibleTarget()
                {
                    Position        = point.position,
                    Radius          = pointRadius,
                    Entity          = pointEntity,
                    IsUnit          = true,
                    OccupiesFullHex = false,
                    OccupyingHex    = point.position.Round(),
                    GatherTarget    = false,
                    ActTypeTarget   = filters.actType
                });
            }
        }
    }
Пример #3
0
 private static bool ValidPossibleTarget(FractionalHex position, Fix64 sightRange, int team, ActTargetFilters filters, FractionalHex pointPos, Fix64 pointRadius, int pointTeam)
 {
     if (pointPos.Distance(position) > sightRange + pointRadius)
     {
         return(false);
     }
     else
     {
         return(PassTeamFilter(filters, team, pointTeam));
     }
 }
Пример #4
0
    /// <summary>
    /// Gets the target if true.
    /// debo ver una buena manera de conseguir el parent entity.
    /// </summary>
    private static bool GetPriorityTargetAndAddPosibleTargets(out PriorityGroupTarget target, FractionalHex position, Fix64 sightRange, Team team, ActTargetFilters filters, Dictionary <Hex, List <EntityOnVision> > unitsForeachHex, List <BuildingOnVision> buildingsOnSight, DynamicBuffer <BEPosibleTarget> buffer)
    {
        //no es lo más eficiente. Pero es más facil de mantener.
        FindAndAddPosibleTargetsToBuffer(position, sightRange, filters, team, unitsForeachHex, buildingsOnSight, buffer);


        Hex roundedPosition = position.Round();
        var pointsOfHex     = SpartialSortUtils.GetAllPointsAtRange(roundedPosition, (int)Fix64.Ceiling(sightRange), unitsForeachHex);

        target = new PriorityGroupTarget();
        var  bestTargetDistance    = Fix64.MaxValue;
        bool arePrioriryTarget     = false;
        bool areUnitPriorityTarget = false;

        //units firs because we search if there is a unit in sight and if so there cannot be a building as a priority target.
        foreach (var point in pointsOfHex)
        {
            int    pointTeam   = point.team;
            Entity pointEntity = point.entity;
            var    pointLayer  = point.collider.Layer;
            var    pointRadius = point.collider.Radius;


            if (ValidPossibleTarget(position, sightRange, team.Number, filters, point.position, pointRadius, pointTeam))
            {
                //buffer.Add(new BEPosibleTarget()
                //{
                //    Position = point.position,
                //    Radius = pointRadius,
                //    Entity = pointEntity,
                //    IsUnit = true,
                //    GatherTarget = false,
                //    OccupiesFullHex = false,
                //    ActTypeTarget = filters.actType
                //});
                //hay que ver si hay algo que bloquea el paso
                if (MapUtilities.PathToPointIsClear(position, point.position))
                {
                    areUnitPriorityTarget = true;
                    arePrioriryTarget     = true;
                    var distance = point.position.Distance(position);
                    if (distance < bestTargetDistance)
                    {
                        bestTargetDistance = distance;
                        target             = new PriorityGroupTarget()
                        {
                            //TargetPosition = point.position,
                            //TargetEntity = pointEntity,
                            TargetHex = point.position.Round(),
                            //IsUnit = true
                        };
                    }
                }
            }
        }

        //buildings
        foreach (var building in buildingsOnSight)
        {
            var buildingPos = (FractionalHex)building.building.position;

            //if (ValidPossibleTarget(position, sightRange, team.Number, filters, buildingPos, (Fix64)0.5, building.team))
            //{
            //    buffer.Add(new BEPosibleTarget()
            //    {
            //        Position = buildingPos,
            //        Radius = Fix64.Zero,
            //        Entity = building.entity,
            //        IsUnit = false,
            //        GatherTarget = false,
            //        OccupiesFullHex = true,
            //        ActTypeTarget = filters.actType
            //    });
            //}
            if (ValidPossibleTarget(position, sightRange, team.Number, filters, buildingPos, (Fix64)0.5, building.team))
            {
                if (!areUnitPriorityTarget)
                {
                    if (MapUtilities.PathToPointIsClear(position, buildingPos))
                    {
                        arePrioriryTarget = true;
                        var distance = buildingPos.Distance(position);
                        if (distance < bestTargetDistance)
                        {
                            bestTargetDistance = distance;
                            target             = new PriorityGroupTarget()
                            {
                                //TargetPosition = buildingPos,
                                //TargetEntity = building.entity,
                                TargetHex = buildingPos.Round(),
                                //IsUnit = false
                            };
                        }
                    }
                }
            }
        }

        return(arePrioriryTarget);
    }