Пример #1
0
        public static Func <WAngle> WorldFacingFromInit(IActorInitializer init, TraitInfo info, WAngle defaultFacing)
        {
            // (Dynamic)TurretFacingInit is specified relative to the actor body.
            // We need to add the body facing to return an absolute world angle.
            Func <WAngle> bodyFacing = null;
            var           facingInit = init.GetOrDefault <FacingInit>();

            if (facingInit != null)
            {
                var facing = facingInit.Value;
                bodyFacing = () => facing;
            }

            var turretFacingInit = init.GetOrDefault <TurretFacingInit>(info);

            if (turretFacingInit != null)
            {
                var facing = turretFacingInit.Value;
                return(bodyFacing != null ? (Func <WAngle>)(() => bodyFacing() + facing) : () => facing);
            }

            var dynamicFacingInit = init.GetOrDefault <DynamicTurretFacingInit>(info);

            if (dynamicFacingInit != null)
            {
                return(bodyFacing != null ? () => bodyFacing() + dynamicFacingInit.Value() : dynamicFacingInit.Value);
            }

            return(bodyFacing ?? (() => defaultFacing));
        }
Пример #2
0
        public static Func <int> TurretFacingFromInit(IActorInitializer init, TraitInfo info, int defaultFacing, string turret = null)
        {
            if (turret != null)
            {
                Func <int> getFacing;
                var        dynamicTurretFacingsInit = init.GetOrDefault <DynamicTurretFacingsInit>();
                if (dynamicTurretFacingsInit != null && dynamicTurretFacingsInit.Value.TryGetValue(turret, out getFacing))
                {
                    return(getFacing);
                }

                int facing;
                var turretFacingsInit = init.GetOrDefault <TurretFacingsInit>();
                if (turretFacingsInit != null && turretFacingsInit.Value.TryGetValue(turret, out facing))
                {
                    return(() => facing);
                }
            }

            var turretFacingInit = init.GetOrDefault <TurretFacingInit>(info);

            if (turretFacingInit != null)
            {
                var facing = turretFacingInit.Value;
                return(() => facing);
            }

            var dynamicFacingInit = init.GetOrDefault <DynamicFacingInit>();

            if (dynamicFacingInit != null)
            {
                return(dynamicFacingInit.Value);
            }

            var facingInit = init.GetOrDefault <FacingInit>();

            if (facingInit != null)
            {
                var facing = facingInit.Value;
                return(() => facing);
            }

            return(() => defaultFacing);
        }
Пример #3
0
        public Func <WAngle> LocalFacingFromInit(IActorInitializer init)
        {
            var turretFacingInit = init.GetOrDefault <TurretFacingInit>(this);

            if (turretFacingInit != null)
            {
                var facing = turretFacingInit.Value;
                return(() => facing);
            }

            var dynamicFacingInit = init.GetOrDefault <DynamicTurretFacingInit>(this);

            if (dynamicFacingInit != null)
            {
                return(dynamicFacingInit.Value);
            }

            return(() => InitialFacing);
        }