/// <summary> /// El punto real es el que cuenta el rango de accion que tiene la entidad, y ve si ocupa todo el hexagono o no. /// </summary> private static FractionalHex GetPositionOfAction(BEPosibleTarget initialTarget, FractionalHex entityPosition, Fix64 entityActionRange) { bool isFullHex = initialTarget.OccupiesFullHex; FractionalHex realTargetPos; if (!isFullHex) { var reversedDirection = (entityPosition - initialTarget.Position).NormalizedManhathan(); //es el punto en el que uno realmente quiere llegar. realTargetPos = initialTarget.Position + reversedDirection * (entityActionRange + initialTarget.Radius); //it use the act range + the target radius. } else { var reversedDirection = (entityPosition - initialTarget.Position).NormalizedManhathan(); realTargetPos = FractionalHex.GetBorderPointOfTheHex(initialTarget.Position.Round(), reversedDirection) + reversedDirection * Fix64.Max(entityActionRange, (Fix64)0.001);//Es necesario q tenga un offset } return(realTargetPos); }
protected override void OnUpdate() { List <EntityOnVision> unitsOnVisionTeam_0 = SightSystem.GetUnitsOnVisionOfTeam(0); List <EntityOnVision> unitsOnVisionTeam_1 = SightSystem.GetUnitsOnVisionOfTeam(1); List <EntityOnVision> unitsOnVisionTeam_2 = SightSystem.GetUnitsOnVisionOfTeam(2); List <EntityOnVision> unitsOnVisionTeam_3 = SightSystem.GetUnitsOnVisionOfTeam(3); List <EntityOnVision> unitsOnVisionTeam_4 = SightSystem.GetUnitsOnVisionOfTeam(4); List <EntityOnVision> unitsOnVisionTeam_5 = SightSystem.GetUnitsOnVisionOfTeam(5); List <EntityOnVision> unitsOnVisionTeam_6 = SightSystem.GetUnitsOnVisionOfTeam(6); List <EntityOnVision> unitsOnVisionTeam_7 = SightSystem.GetUnitsOnVisionOfTeam(7); var sortedByHex_UnitsOnVisionTeam_0 = SpartialSortUtils.GetHexToPointsDictionary(unitsOnVisionTeam_0); var sortedByHex_UnitsOnVisionTeam_1 = SpartialSortUtils.GetHexToPointsDictionary(unitsOnVisionTeam_1); var sortedByHex_UnitsOnVisionTeam_2 = SpartialSortUtils.GetHexToPointsDictionary(unitsOnVisionTeam_2); var sortedByHex_UnitsOnVisionTeam_3 = SpartialSortUtils.GetHexToPointsDictionary(unitsOnVisionTeam_3); var sortedByHex_UnitsOnVisionTeam_4 = SpartialSortUtils.GetHexToPointsDictionary(unitsOnVisionTeam_4); var sortedByHex_UnitsOnVisionTeam_5 = SpartialSortUtils.GetHexToPointsDictionary(unitsOnVisionTeam_5); var sortedByHex_UnitsOnVisionTeam_6 = SpartialSortUtils.GetHexToPointsDictionary(unitsOnVisionTeam_6); var sortedByHex_UnitsOnVisionTeam_7 = SpartialSortUtils.GetHexToPointsDictionary(unitsOnVisionTeam_7); var buildingsOnVisionTeam_0 = SightSystem.GetBuildingsOnVisionOfTeam(0); var buildingsOnVisionTeam_1 = SightSystem.GetBuildingsOnVisionOfTeam(1); var buildingsOnVisionTeam_2 = SightSystem.GetBuildingsOnVisionOfTeam(2); var buildingsOnVisionTeam_3 = SightSystem.GetBuildingsOnVisionOfTeam(3); var buildingsOnVisionTeam_4 = SightSystem.GetBuildingsOnVisionOfTeam(4); var buildingsOnVisionTeam_5 = SightSystem.GetBuildingsOnVisionOfTeam(5); var buildingsOnVisionTeam_6 = SightSystem.GetBuildingsOnVisionOfTeam(6); var buildingsOnVisionTeam_7 = SightSystem.GetBuildingsOnVisionOfTeam(7); //normal group entities. #region Group that targets entities on vision. Entities.WithAll <Group, BEPosibleTarget>().WithNone <GroupOnGather>().ForEach((Entity entity, ref HexPosition hexPosition, ref SightRange sightRange, ref GroupBehaviour behaviour, ref ActTargetFilters filters, ref Team team, ref MovementState movementState) => { var buffer = EntityManager.GetBuffer <BEPosibleTarget>(entity); buffer.Clear(); var sortedByHex_UnitsOnTeamVision = GetSortedUnitsOnTeamVision(team.Number, sortedByHex_UnitsOnVisionTeam_0, sortedByHex_UnitsOnVisionTeam_1, sortedByHex_UnitsOnVisionTeam_2, sortedByHex_UnitsOnVisionTeam_3, sortedByHex_UnitsOnVisionTeam_4, sortedByHex_UnitsOnVisionTeam_5, sortedByHex_UnitsOnVisionTeam_6, sortedByHex_UnitsOnVisionTeam_7); var buildingsOnTeamVision = GetBuildingOnTeamVision(team.Number, buildingsOnVisionTeam_0, buildingsOnVisionTeam_1, buildingsOnVisionTeam_2, buildingsOnVisionTeam_3, buildingsOnVisionTeam_4, buildingsOnVisionTeam_5, buildingsOnVisionTeam_6, buildingsOnVisionTeam_7); switch (behaviour.Value) { case Behaviour.PASSIVE: if (EntityManager.HasComponent <PriorityGroupTarget>(entity)) { PostUpdateCommands.RemoveComponent <PriorityGroupTarget>(entity); } if (!movementState.DestinationReached) { break; } FindAndAddPosibleTargetsToBuffer(hexPosition.HexCoordinates, sightRange.Value, filters, team, sortedByHex_UnitsOnTeamVision, buildingsOnTeamVision, buffer); break; case Behaviour.DEFAULT: if (EntityManager.HasComponent <PriorityGroupTarget>(entity)) { PostUpdateCommands.RemoveComponent <PriorityGroupTarget>(entity); } if (!movementState.DestinationReached) { break; } FindAndAddPosibleTargetsToBuffer(hexPosition.HexCoordinates, sightRange.Value, filters, team, sortedByHex_UnitsOnTeamVision, buildingsOnTeamVision, buffer); break; case Behaviour.AGRESIVE: //este modo agrega la entidad más cercana no bloqueada, como blanco prioritario. agrega a todas las entidades cercanas como posibles targets. PriorityGroupTarget priorityTarget; if (GetPriorityTargetAndAddPosibleTargets(out priorityTarget, hexPosition.HexCoordinates, sightRange.Value, team, filters, sortedByHex_UnitsOnTeamVision, buildingsOnTeamVision, buffer)) { // 1° if there isn´t a priorityTarget component we add one. if (!EntityManager.HasComponent <PriorityGroupTarget>(entity)) { PostUpdateCommands.AddComponent <PriorityGroupTarget>(entity, priorityTarget); } else { PostUpdateCommands.SetComponent <PriorityGroupTarget>(entity, priorityTarget); } } else { // 1° if there is a priorityTarget component we remove it. if (EntityManager.HasComponent <PriorityGroupTarget>(entity)) { PostUpdateCommands.RemoveComponent <PriorityGroupTarget>(entity); } } break; default: throw new System.NotImplementedException(); } }); #endregion #region Groups that are gathering Entities.WithAll <Group, BEPosibleTarget, BEResourceSource>().ForEach((Entity entity, ref GroupOnGather onGather, ref HexPosition hexPosition, ref SightRange sightRange, ref Team team, ref MovementState movementState) => { //UnityEngine.Debug.Log($"Group on gather. Entity: {entity.Index}. Gather resource: {onGather.GatheringResourceType}."); //Los targets son: todos los elementos del BEResourceSource + todos los elementos de los droppoints var posTargetBuffer = EntityManager.GetBuffer <BEPosibleTarget>(entity); posTargetBuffer.Clear(); if (!movementState.DestinationReached) { return; } var resSourceBuffer = EntityManager.GetBuffer <BEResourceSource>(entity); var allDropPointsOfTeam = DropPointSystem.GetAllDropPointsOfTeam(onGather.GatheringResourceType, team.Number); foreach (var resSource in resSourceBuffer) { if (resSource.currentGatherers >= resSource.maxGatherers) { continue; } var posTarget = new BEPosibleTarget() { Entity = resSource.entity, Position = (FractionalHex)resSource.position, Radius = Fix64.Zero, IsUnit = false, GatherTarget = true, IsResource = true, OccupiesFullHex = true, OccupyingHex = resSource.position, ActTypeTarget = ActType.GATHER, }; posTargetBuffer.Add(posTarget); } foreach (var dropPoint in allDropPointsOfTeam) { var posTarget = new BEPosibleTarget() { Entity = dropPoint.Value, Position = (FractionalHex)dropPoint.Key, Radius = Fix64.Zero, IsUnit = false, GatherTarget = true, IsResource = false, OccupiesFullHex = true, OccupyingHex = dropPoint.Key, ActTypeTarget = ActType.STORE }; posTargetBuffer.Add(posTarget); } }); #endregion }