Esempio n. 1
0
        public PositionComponent GetNearestEnemy(Entity source_entity)
        {
            Player                   source_player       = source_entity.GetOwnerPlayer();
            PositionComponent        source_position_cmp = source_entity.GetComponent(PositionComponent.ID) as PositionComponent;
            Vector3FP                source_position     = source_position_cmp.CurrentPosition;
            List <PositionComponent> list = source_position_cmp.GetSpacePartition().CollectEntity_All();

            PositionComponent potential_enemy = null;
            FixPoint          min_distance    = FixPoint.MaxValue;

            for (int i = 0; i < list.Count; ++i)
            {
                PositionComponent target_position_component = list[i];
                Entity            entity = target_position_component.GetOwnerEntity();
                if (entity.GetComponent(DamagableComponent.ID) == null)
                {
                    continue;
                }
                if (!FactionRelation.IsFactionSatisfied(source_player.GetFaction(entity.GetOwnerPlayerID()), FactionRelation.Enemy))
                {
                    continue;
                }
                Vector3FP offset   = source_position - target_position_component.CurrentPosition;
                FixPoint  distance = FixPoint.FastDistance(offset.x, offset.z);
                if (distance < min_distance)
                {
                    potential_enemy = target_position_component;
                    min_distance    = distance;
                }
            }
            return(potential_enemy);
        }
Esempio n. 2
0
        void GatherGeneral(ISpacePartition partition, Player player, Vector3FP position, Vector2FP facing, TargetGatheringParam param, List <Entity> targets)
        {
            if (partition == null)
            {
                return;
            }

            List <PositionComponent> list = null;
            int gathering_type            = param.m_type;

            if (gathering_type == TargetGatheringType.ForwardRectangle)
            {
                list = partition.CollectEntity_ForwardRectangle(position, facing, param.m_param1, param.m_param2);
            }
            else if (gathering_type == TargetGatheringType.SurroundingRing)
            {
                list = partition.CollectEntity_SurroundingRing(position, param.m_param1, param.m_param2);
            }
            else if (gathering_type == TargetGatheringType.ForwardSector)
            {
                list = partition.CollectEntity_ForwardSector(position, facing, param.m_param1, param.m_param2);
            }
            else if (gathering_type == TargetGatheringType.All)
            {
                list = partition.CollectEntity_All();
            }
            if (list == null)
            {
                return;
            }

            for (int i = 0; i < list.Count; ++i)
            {
                PositionComponent position_component = list[i];
                Entity            entity             = position_component.GetOwnerEntity();
                if (param.m_category != 0)
                {
                    EntityDefinitionComponent definition_component = entity.GetComponent(EntityDefinitionComponent.ID) as EntityDefinitionComponent;
                    if (definition_component == null)
                    {
                        continue;
                    }
                    if (!definition_component.IsCategory(param.m_category))
                    {
                        continue;
                    }
                }
                if (player != null && !FactionRelation.IsFactionSatisfied(player.GetFaction(entity.GetOwnerPlayerID()), param.m_faction))
                {
                    continue;
                }
                targets.Add(entity);
            }
        }