public string SetToBlockMover(ModuleBlockMover blockMover)
 {
     blockMover.SetDirty();
     blockMover.SetMinLimit(minValueLimit ?? 0f);
     blockMover.SetMaxLimit(maxValueLimit ?? blockMover.TrueLimitVALUE);
     blockMover.MAXVELOCITY = maxVelocity.HasValue ? velocity.Value : blockMover.MAXVELOCITY;
     if (targetValue.HasValue)
     {
         blockMover.VALUE = targetValue.Value;
     }
     if (velocity.HasValue)
     {
         blockMover.VELOCITY = velocity.Value;
     }
     if (jointStrength.HasValue)
     {
         blockMover.SPRSTR = jointStrength.Value;
     }
     if (jointDampen.HasValue)
     {
         blockMover.SPRDAM = jointDampen.Value;
     }
     if (moverType.HasValue)
     {
         blockMover.moverType = moverType.Value;
     }
     blockMover.CannotBeFreeJoint = blockMover.CannotBeFreeJoint;
     if (lockOffsetParent.HasValue)
     {
         blockMover.LockJointBackPush = lockOffsetParent.Value;
     }
     return(InputOperator.StringArrayToProcessOperations(ToString(), ref blockMover.ProcessOperations));
 }
Esempio n. 2
0
 internal static void SetState(bool showUI, ModuleBlockMover blockMover, Rect refWindow)
 {
     if (showUI)
     {
         lastBlockMover = blockMover;
         float width = 600, height = 500;
         window = new Rect(refWindow.center.x - width * 0.5f, refWindow.center.y - height * 0.5f, width, height);
         GUI.FocusWindow(978243);
     }
     else
     {
         lastBlockMover = null;
     }
 }
 public void ResetValues(ModuleBlockMover block)
 {
     foreach (Variable v in Variables)
     {
         v.ResetValue(block);
     }
     if (ExpandLimitsToBlock)
     {
         minValueLimit = 0f;
         maxValueLimit = block.TrueLimitVALUE;
     }
     if (ExpandVelocityToBlock)
     {
         maxVelocity = block.TrueMaxVELOCITY;
     }
 }
            public override void ResetValue(ModuleBlockMover block)
            {
                value = DefaultValue;
                cache = null;

                if (LimitsAreValue)
                {
                    MinValue = 0f;
                    MaxValue = block.TrueLimitVALUE;
                }
                if (LimitsAreVelocity)
                {
                    MinValue = -block.TrueMaxVELOCITY;
                    MaxValue = block.TrueMaxVELOCITY;
                }
                value = Mathf.Clamp(value, MinValue, MaxValue);
            }
Esempio n. 5
0
        public static void ConvertSerialToBlockMover(SerialData serialData, ModuleBlockMover blockMover)
        {
            string ProcessList;
            blockMover.SetDirty();
            blockMover.moverType = ModuleBlockMover.MoverType.Static;
            blockMover.LockJointBackPush = true;
            blockMover.LOCALINPUT = serialData.Local;
            blockMover._CENTERLIMIT = serialData.Stretch != 0 ? serialData.Stretch / 2f : blockMover.HalfLimitVALUE;
            blockMover._EXTENTLIMIT = blockMover._CENTERLIMIT;
            blockMover.UseLIMIT = serialData.Stretch != 0 && serialData.Stretch != blockMover.TrueLimitVALUE;
            blockMover.VELOCITY = 0f;
            blockMover.VALUE = serialData.IsOpen ? serialData.Stretch : 0f;
            blockMover.PVALUE = blockMover.VALUE;

            var mode = GetMode(serialData.Toggle, serialData.Invert, serialData.PreferState);
            ProcessList = ModeToProcessFormat[(int)mode];
            ProcessList = ProcessList.Replace("<Input>", serialData.Input.ToString());
            ProcessList = ProcessList.Replace("<Extent>", (serialData.Stretch == 0 ? blockMover.TrueLimitVALUE : serialData.Stretch).ToString());
            ProcessList = ProcessList.Replace("<ToggleState>", serialData.IsOpen ? "1" : "-1");
            InputOperator.StringArrayToProcessOperations(ProcessList, ref blockMover.ProcessOperations);
        }
 public override void ResetValue(ModuleBlockMover block)
 {
     value = DefaultValue;
 }
 public abstract void ResetValue(ModuleBlockMover block);
Esempio n. 8
0
        public bool ConditionMatched(ModuleBlockMover block, bool localInput, float m_Val, float m_Vel)
        {
            bool Invert = m_InputParam < 0;

            switch (m_InputType)
            {
            case InputType.AlwaysOn:
                return(true);

            case InputType.OnPress:
                m_InputParam = Mathf.Sign(m_InputParam);
                return((KeyState(CanInput(block, localInput)) == 1) != Invert);

            case InputType.OnRelease:
                m_InputParam = Mathf.Sign(m_InputParam);
                return((KeyState(CanInput(block, localInput)) == 3) != Invert);

            case InputType.WhileHeld:
                m_InputParam = Mathf.Sign(m_InputParam);
                return((KeyState(CanInput(block, localInput)) != 0) != Invert);

            case InputType.Toggle:
                m_InputParam = Mathf.Sign(m_InputParam - 0.001f);
                if (KeyState(CanInput(block, localInput)) == 1)
                {
                    m_InputParam = -m_InputParam;
                }
                return(m_InputParam > 0);

            case InputType.EnemyTechIsNear:
                Visible target = block.GetTarget();
                if (target == null)
                {
                    return(Invert);
                }
                return(((target.centrePosition - block.block.centreOfMassWorld).sqrMagnitude < m_InputParam * m_InputParam) != Invert);

            case InputType.PlayerTechIsNear:
                if (Singleton.playerTank == null)
                {
                    return(Invert);
                }
                if (Singleton.playerTank == block.block.tank)
                {
                    return(!Invert);
                }
                return(((Singleton.playerTank.visible.centrePosition - block.block.centreOfMassWorld).sqrMagnitude < m_InputParam * m_InputParam) != Invert);

            case InputType.AboveSurfaceElev:
                var comw = block.block.centreOfMassWorld;
                ManWorld.inst.GetTerrainHeight(comw, out float outHeight);
                return((comw.y > outHeight + m_InputParam) != Invert);

            case InputType.AboveVelocity:
                return((block.block.tank.rbody.GetPointVelocity(block.block.centreOfMassWorld).sqrMagnitude > m_InputParam * m_InputParam) != Invert);

            case InputType.IfPosAbove:
                if (block.IsPlanarVALUE)
                {
                    return(((block.PVALUE + 900) % 360) - 180 > m_InputParam);
                }
                m_InputParam = Mathf.Max(m_InputParam, 0f);
                return(block.PVALUE > m_InputParam);

            case InputType.IfPosBelow:
                if (block.IsPlanarVALUE)
                {
                    return(((block.PVALUE + 900) % 360) - 180 < m_InputParam);
                }
                m_InputParam = Mathf.Max(m_InputParam, 0f);
                return(block.PVALUE < m_InputParam);

            case InputType.IfPosEqual:
                if (block.IsPlanarVALUE)
                {
                    return(m_InputParam.Approximately(((block.PVALUE + 900) % 360) - 180));
                }
                m_InputParam = Mathf.Max(m_InputParam, 0f);
                return(block.PVALUE.Approximately(m_InputParam));

            case InputType.IfSpeedAbove:
                return(m_Vel > m_InputParam);

            case InputType.IfSpeedBelow:
                return(m_Vel < m_InputParam);

            case InputType.IfSpeedEqual:
                return(m_Vel.Approximately(m_InputParam));

            default:
                return(false);
            }
        }
Esempio n. 9
0
 static bool CanInput(ModuleBlockMover block, bool LocalInput)
 {
     return(!LocalInput || block.block.tank == Singleton.playerTank);
 }
Esempio n. 10
0
        /// <summary>
        /// Process this operation, checking if it's active and then modifying values based on its function
        /// </summary>
        /// <param name="block">The ModuleBlockMover to use for calculations</param>
        /// <param name="ProjectDirToPlane">Is the value used on a plane, or on an axis</param>
        /// <param name="Value">Positional value to modify</param>
        /// <param name="Velocity">Positional velocity to modify</param>
        /// <param name="FreeJoint">Allow free-moving in the attached body</param>
        /// <param name="LockJoint">Ghost-phasing</param>
        /// <returns>Returns true if satisfied</returns>
        public bool Calculate(ModuleBlockMover blockMover, bool LocalInput, bool ProjectDirToPlane, ref float Value, ref float Velocity, ref ModuleBlockMover.MoverType moverType, out int Skip)
        {
            Skip = 0;
            switch (m_OperationType)
            {
            case OperationType.OrThen: return(false);

            case OperationType.ElseThen: Skip = 1; return(false);

            default: break;
            }
            TankBlock block = blockMover.block;

            if (ConditionMatched(blockMover, LocalInput, Value, Velocity))
            {
                switch (m_OperationType)
                {
                case OperationType.ShiftPos:
                    Value += m_Strength;
                    return(true);

                case OperationType.SetPos:
                    Value = m_Strength;
                    return(true);

                case OperationType.ShiftSpeed:
                    Velocity += m_Strength;
                    return(true);

                case OperationType.SetSpeed:
                    Velocity = m_Strength;
                    return(true);

                case OperationType.ArrowPoint:
                    var vel = block.tank.rbody.GetPointVelocity(block.centreOfMassWorld);
                    if (blockMover.IsPlanarVALUE)
                    {
                        var planar = Vector3.ProjectOnPlane(vel * Mathf.Sign(m_Strength), block.trans.up);
                        Value += SafePlanarPointAngle(block.trans, planar, Value) * Mathf.Clamp01(m_Strength * m_Strength * planar.magnitude);
                        return(true);
                    }
                    Value += block.trans.InverseTransformDirection(vel * Mathf.Sign(m_Strength)).y *Mathf.Clamp01(m_Strength * m_Strength);
                    return(true);

                case OperationType.TargetPoint:
                    Visible target = blockMover.GetTarget();
                    if (target == null)
                    {
                        if (m_ResetTimer)
                        {
                            Value        = blockMover.UseLIMIT ? blockMover._CENTERLIMIT : 0f;
                            m_ResetTimer = false;
                        }
                        return(false);
                    }
                    m_ResetTimer = true;
                    Value       += PointAtTarget(block.trans, (target.GetAimPoint(block.trans.position) - block.centreOfMassWorld) * Mathf.Sign(m_Strength), ProjectDirToPlane, Value) * m_Strength * m_Strength;// * Mathf.Abs(m_Strength);
                    return(true);

                case OperationType.TargetPointPredictive:
                    float muzzleVelocity = Mathf.Abs(m_Strength);
                    bool  useGravity     = m_Strength > 0;

                    Visible targetPred = blockMover.GetTarget();

                    if (targetPred == null)
                    {
                        if (m_ResetTimer)
                        {
                            Value        = blockMover.UseLIMIT ? blockMover._CENTERLIMIT : 0f;
                            m_ResetTimer = false;
                        }
                        return(false);
                    }

                    Vector3 BlockCenter    = block.centreOfMassWorld;
                    Vector3 AimPointVector = targetPred.GetAimPoint(BlockCenter);
                    Vector3 vector         = AimPointVector - BlockCenter;
                    if (muzzleVelocity > 0f)
                    {
                        Vector3   dist             = vector;
                        Rigidbody rbodyTank        = block.tank.rbody;
                        Vector3   angularToggle    = rbodyTank.angularVelocity;
                        Vector3   relativeVelocity = targetPred.rbody.velocity - (rbodyTank.velocity + angularToggle);

                        float time = dist.magnitude / muzzleVelocity;

                        Vector3 relativeAcceleration = BallisticTargeting.GetAcceleration(targetPred.tank) - BallisticTargeting.GetAcceleration(block.tank);

                        if (useGravity)
                        {
                            relativeAcceleration -= Physics.gravity;
                        }

                        float exactTime = BallisticTargeting.SolveBallisticArc(BlockCenter, muzzleVelocity, AimPointVector, relativeVelocity, relativeAcceleration);
                        if (exactTime != Mathf.Infinity)
                        {
                            time = exactTime;
                        }

                        // vector now represents where the enemy will be - still need elevation
                        vector += (time * relativeVelocity) + (relativeAcceleration * time * time / 2);
                    }

                    m_ResetTimer = true;
                    Value       += PointAtTarget(block.trans, vector, ProjectDirToPlane, Value);// * Mathf.Abs(m_Strength);
                    return(true);

                case OperationType.PlayerPoint:
                    Tank playerTank = Singleton.playerTank;
                    if (playerTank == null)
                    {
                        return(false);
                    }
                    Value += PointAtTarget(block.trans, (playerTank.WorldCenterOfMass - block.centreOfMassWorld) * Mathf.Sign(m_Strength), ProjectDirToPlane, Value) * m_Strength * m_Strength;    // * Mathf.Abs(m_Strength);
                    return(true);

                case OperationType.GroundPoint:
                    var comw = block.centreOfMassWorld;
                    ManWorld.inst.GetTerrainHeight(comw, out float outHeight);
                    //return (comw.y > outHeight + m_InputParam);
                    float reducer = Mathf.Abs(Vector3.Dot(block.trans.up, Vector3.up));
                    if (blockMover.IsPlanarVALUE)
                    {
                        reducer = 1f - reducer;
                    }
                    Value += PointAtTarget(block.trans, Vector3.up * (outHeight - comw.y) * Mathf.Sign(m_Strength), ProjectDirToPlane, Value) * m_Strength * m_Strength * reducer;
                    //Value += PointAtTarget(block.trans, Vector3.down * Mathf.Sign(m_Strength), ProjectDirToPlane, Value) * m_Strength * m_Strength;// * Mathf.Abs(m_Strength);
                    return(true);

                case OperationType.NorthPoint:

                    if (blockMover.IsPlanarVALUE)
                    {
                        Value = (Vector3.SignedAngle(block.trans.forward, Vector3.ProjectOnPlane(Vector3.forward, block.trans.up), block.trans.up) + m_Strength + 900f) % 360f - 180f;
                    }
                    else
                    {
                        float rad = m_Strength * Mathf.Deg2Rad;
                        Value = block.trans.InverseTransformDirection(new Vector3(Mathf.Sin(rad), 0f, Mathf.Cos(rad))).y;
                    }
                    return(true);

                case OperationType.SetFreeJoint:
                    if (blockMover.CanOnlyBeLockJoint)
                    {
                        return(false);
                    }
                    if (blockMover.CannotBeFreeJoint)
                    {
                        moverType = ModuleBlockMover.MoverType.Dynamic;
                    }
                    else
                    {
                        moverType = ModuleBlockMover.MoverType.Physics;
                    }
                    return(true);

                case OperationType.SetBodyJoint:
                    if (blockMover.CanOnlyBeLockJoint)
                    {
                        return(false);
                    }
                    moverType = ModuleBlockMover.MoverType.Dynamic;
                    return(true);

                case OperationType.SetLockJoint:
                    if (blockMover.CanOnlyBeLockJoint)
                    {
                        return(false);
                    }
                    moverType = ModuleBlockMover.MoverType.Static;
                    return(true);

                case OperationType.CameraPoint:
                    var camTr = Singleton.cameraTrans;
                    if (camTr == null)
                    {
                        return(false);
                    }
                    Value += PointAtTarget(block.trans, camTr.forward * Mathf.Sign(m_Strength), ProjectDirToPlane, Value) * m_Strength * m_Strength;    // * Mathf.Abs(m_Strength);
                    return(true);

                case OperationType.IfThen:
                    if (m_ResetTimer)
                    {
                        m_InternalTimer = 0f;
                        m_ResetTimer    = false;
                    }
                    if (m_Strength == 0f)
                    {
                        return(true);
                    }

                    m_InternalTimer += Time.fixedDeltaTime;
                    // If time is satisfied and strength is positive, do not skip. Negative strength will only activate within that timeframe
                    bool met = (m_InternalTimer >= Mathf.Abs(m_Strength)) == (m_Strength >= 0f);
                    Skip = met ? 0 : 1;
                    return(met);

                case OperationType.CursorPoint:
                    Value += PointAtTarget(block.trans, (AdjustAttachPosition.PointerPos - block.centreOfMassWorld) * Mathf.Sign(m_Strength), ProjectDirToPlane, Value) * m_Strength * m_Strength;    // * Mathf.Abs(m_Strength);
                    return(true);

                case OperationType.Nothing:
                    return(true);    // Light it up in the GUI. Technically, the task did not fail

                case OperationType.FireWeapons:
                    if (blockMover.Holder == null)
                    {
                        return(false);
                    }
                    if (m_Strength < 0)
                    {
                        blockMover.Holder.ForceNoFireNextFrame = true;
                    }
                    else
                    {
                        blockMover.Holder.ForceFireNextFrame = true;
                    }
                    return(true);

                default:
                    return(false);
                }
            }
            else if (m_OperationType == OperationType.IfThen)
            {
                if (m_Strength != 0)
                {
                    m_InternalTimer += Time.fixedDeltaTime;
                }
                if (m_ResetTimer)
                {
                    m_InternalTimer = 0f;
                }
                else
                {
                    m_ResetTimer = true;
                }
                Skip = 1;
            }
            return(false);
        }
Esempio n. 11
0
        public static void ConvertSerialToBlockMover(SerialData serialData, ModuleBlockMover blockMover)
        {
            string ProcessList;

            blockMover.SetDirty();
            blockMover.moverType         = ModuleBlockMover.MoverType.Static;
            blockMover.LockJointBackPush = true;
            blockMover.LOCALINPUT        = serialData.Local;
            blockMover._CENTERLIMIT      = serialData.minRestrict;
            blockMover._EXTENTLIMIT      = serialData.rangeRestrict;// / 2f;
            blockMover.UseLIMIT          = serialData.Restrict && serialData.rangeRestrict != 0f;
            blockMover.VELOCITY          = 0f;
            blockMover.VALUE             = serialData.Angle;
            blockMover.PVALUE            = serialData.Angle;
            blockMover.MAXVELOCITY       = serialData.Speed;
            switch (serialData.mode)
            {
            case Mode.Positional:
                if (serialData.StartDelay != 0f)
                {
                    ProcessList = PositionalDelay;
                }
                else
                {
                    ProcessList = Positional;
                }
                break;

            case Mode.Directional:
                blockMover.VELOCITY = serialData.Direction * serialData.Speed;
                if (serialData.CWDelay + serialData.CCWDelay != 0f)
                {
                    ProcessList = DirectionalDelay;
                }
                else
                {
                    ProcessList = Directional;
                }
                break;

            case Mode.Speed:
                blockMover.VELOCITY = serialData.Direction * serialData.Speed;
                if (serialData.StartDelay != 0f)
                {
                    ProcessList = SpeedDelay;
                }
                else
                {
                    ProcessList = Speed;
                }
                break;

            case Mode.OnOff:
                blockMover.VELOCITY = serialData.Direction * serialData.Speed;
                if (serialData.Restrict)
                {
                    if (serialData.CWDelay + serialData.CCWDelay != 0f)
                    {
                        ProcessList = OnOffLimitDelay;
                    }
                    else
                    {
                        ProcessList = OnOffLimit;
                    }
                }
                else
                {
                    if (serialData.StartDelay != 0f)
                    {
                        ProcessList = OnOffDelay;
                    }
                    else
                    {
                        ProcessList = OnOff;
                    }
                }
                break;

            case Mode.Aim:
                if (serialData.StartDelay != 0f)
                {
                    ProcessList = TargetDelay;
                }
                else
                {
                    ProcessList = Target;
                }
                break;

            case Mode.Turning:
                blockMover.VELOCITY = serialData.Direction * serialData.Speed;
                if (serialData.Restrict)
                {
                    if (serialData.StartDelay != 0f)
                    {
                        ProcessList = TurningLimitDelay;
                    }
                    else
                    {
                        ProcessList = TurningLimit;
                    }
                }
                else
                {
                    if (serialData.StartDelay != 0f)
                    {
                        ProcessList = TurningDelay;
                    }
                    else
                    {
                        ProcessList = Turning;
                    }
                }
                break;

            case Mode.AimAtPlayer:
                ProcessList = AimAtPlayer;
                break;

            case Mode.Throttle:
                blockMover.VELOCITY = serialData.Direction * serialData.Speed;
                if (serialData.StartDelay != 0f)
                {
                    ProcessList = ThrottleDelay;
                }
                else
                {
                    ProcessList = Throttle;
                }
                break;

            case Mode.AimAtVelocity:
                blockMover.VELOCITY = serialData.Direction * serialData.Speed;
                ProcessList         = AimAtVelocity;
                break;

            case Mode.Cycle:
                blockMover.VELOCITY = serialData.Direction * serialData.Speed;
                if (serialData.Restrict)
                {
                    if (serialData.StartDelay != 0f || serialData.CCWDelay != 0f || serialData.CWDelay != 0f)
                    {
                        ProcessList = CycleLimitDelay;
                    }
                    else
                    {
                        ProcessList = CycleLimit;
                    }
                }
                else
                {
                    if (serialData.StartDelay != 0f || serialData.CCWDelay != 0f || serialData.CWDelay != 0f)
                    {
                        ProcessList = CycleDelay;
                    }
                    else
                    {
                        ProcessList = Cycle;
                    }
                }
                break;

            default:
                Console.WriteLine("ModuleSwivel.ConvertSerialToBlockMover() : Cannot deserialize " + serialData.mode.ToString() + ", missing conversion!");
                ProcessList = "";
                break;
            }
            ProcessList = ProcessList.Replace("<KeyR>", serialData.Input1.ToString());
            ProcessList = ProcessList.Replace("<KeyL>", serialData.Input2.ToString());
            ProcessList = ProcessList.Replace("<SD>", ((serialData.StartDelay / serialData.Speed) * Time.fixedDeltaTime).ToString());
            ProcessList = ProcessList.Replace("<CWD>", ((serialData.CWDelay / serialData.Speed) * Time.fixedDeltaTime).ToString());
            ProcessList = ProcessList.Replace("<CCWD>", ((serialData.CCWDelay / serialData.Speed) * Time.fixedDeltaTime).ToString());
            ProcessList = ProcessList.Replace("<Speed>", serialData.Speed.ToString());
            ProcessList = ProcessList.Replace("<Smooth>", (serialData.Speed * 0.025f).ToString()); // Position += (Direction +- 0.025f) * Speed
            ProcessList = ProcessList.Replace("<Smooth2>", (serialData.Speed * 0.05f).ToString());
            ProcessList = ProcessList.Replace("<LimitC>", blockMover._CENTERLIMIT.ToString());
            ProcessList = ProcessList.Replace("<LimitL>", (((blockMover.MINVALUELIMIT + 900) % 360) - 180).ToString());
            ProcessList = ProcessList.Replace("<LimitR>", (((blockMover.MAXVALUELIMIT + 900) % 360) - 180).ToString());
            InputOperator.StringArrayToProcessOperations(ProcessList, ref blockMover.ProcessOperations);
        }