Exemplo n.º 1
0
        public ImpactType GetImpactType(World world, CPos cell, WPos pos, Actor firedBy)
        {
            // Missiles need a margin because they sometimes explode a little above ground
            // due to their explosion check triggering slightly too early (because of CloseEnough).
            // TODO: Base ImpactType on target altitude instead of explosion altitude.
            var airMargin = new WDist(128);

            // Matching target actor
            if (ValidImpactTypes.HasFlag(ImpactType.TargetHit) && GetDirectHit(world, cell, pos, firedBy, true))
            {
                return(ImpactType.TargetHit);
            }

            var dat         = world.Map.DistanceAboveTerrain(pos);
            var isDirectHit = GetDirectHit(world, cell, pos, firedBy);

            if (dat.Length > airMargin.Length)
            {
                return(isDirectHit ? ImpactType.AirHit : ImpactType.Air);
            }

            if (dat.Length <= airMargin.Length && world.Map.GetTerrainInfo(cell).IsWater)
            {
                return(isDirectHit ? ImpactType.WaterHit : ImpactType.Water);
            }

            if (isDirectHit)
            {
                return(ImpactType.GroundHit);
            }

            // Matching target terrain
            if (ValidImpactTypes.HasFlag(ImpactType.TargetTerrain) &&
                IsValidTarget(world.Map.GetTerrainInfo(cell).TargetTypes))
            {
                return(ImpactType.TargetTerrain);
            }

            return(ImpactType.Ground);
        }
Exemplo n.º 2
0
        public bool IsValidImpact(WPos pos, Actor firedBy)
        {
            var world      = firedBy.World;
            var targetTile = world.Map.CellContaining(pos);

            if (!world.Map.Contains(targetTile))
            {
                return(false);
            }

            var impactType = GetImpactType(world, targetTile, pos);

            if (!ValidImpactTypes.HasFlag(impactType) || InvalidImpactTypes.HasFlag(impactType))
            {
                return(false);
            }

            return(true);
        }