Exemple #1
0
    public static InuFloat operator -(InuFloat c1, float c2)
    {
        InuFloat result = new InuFloat();

        result.v = c1.v - (long)(c2 * FLOAT_SCALE);
        return(result);
    }
    public static InuFloat Float(InuFloat min, InuFloat max)
    {
        InuFloat result = new InuFloat();

        result.ScaledSet(Long(min.i, max.i));
        return(result);
    }
Exemple #3
0
    public static InuFloat operator *(InuFloat c1, float c2)
    {
        InuFloat result = new InuFloat();

        result.v = (int)(c1.v * c2);
        return(result);
    }
Exemple #4
0
    public static InuFloat operator /(InuFloat c1, float c2)
    {
        InuFloat result = new InuFloat();

        result.v = (long)(c1.v / c2);
        return(result);
    }
Exemple #5
0
    public static InuFloat operator /(InuFloat c1, InuFloat c2)
    {
        InuFloat result = new InuFloat();

        result.v = c1.v * INT_SCALE / c2.v;
        return(result);
    }
Exemple #6
0
    public static InuFloat FromScaledValue(long _v)
    {
        InuFloat result = new InuFloat();

        result.ScaledSet(_v);
        return(result);
    }
Exemple #7
0
    public static InuFloat operator -(InuFloat c1, InuFloat c2)
    {
        InuFloat result = new InuFloat();

        result.v = c1.v - c2.v;
        return(result);
    }
Exemple #8
0
    public static InuFloat operator -(InuFloat c1)
    {
        InuFloat result = new InuFloat();

        result.v = -c1.v;
        return(result);
    }
Exemple #9
0
 public static InuFloat Max(InuFloat c1, InuFloat c2)
 {
     if (c1.v >= c2.v)
     {
         return(c1);
     }
     return(c2);
 }
Exemple #10
0
 public static InuFloat Min(InuFloat c1, InuFloat c2)
 {
     if (c1.v <= c2.v)
     {
         return(c1);
     }
     return(c2);
 }
Exemple #11
0
    public static InuVector2 Lerp(InuVector2 _start, InuVector2 _end, InuFloat _t)
    {
        InuVector2 result = new InuVector2();

        result.x = InuFloat.Lerp(_start.x, _end.x, _t);
        result.z = InuFloat.Lerp(_start.z, _end.z, _t);
        return(result);
    }
Exemple #12
0
 public static void Refresh(long _i = 0)
 {
     if (Time.frameCount != m_frame)
     {
         m_frame = Time.frameCount;
         m_deltaTime.Set(Time.deltaTime);
         m_time += m_deltaTime;
     }
 }
 public InuAI_UnitAttack(InuStructure _t, InuDefine.EInuAIType _aiType, InuFloat _range, InuFloat _sight)
 {
     mInuObj         = _t;
     mTarget         = null;
     mAIType         = _aiType;
     mAttackRange    = _range;
     mAttackRangeSqr = mAttackRange * mAttackRange;
     mSightRange     = _sight;
     mSightRangeSqr  = mSightRange * mSightRange;
 }
Exemple #14
0
    public static InuFloat Abs(InuFloat f)
    {
        if (f.v >= 0)
        {
            return(f);
        }
        InuFloat result = new InuFloat();

        result.v = -f.v;
        return(result);
    }
Exemple #15
0
    //public InuAI_Path CreatePathAI(InuStructure src, InuDefine.EInuPathAI aiType, InuFloat speed, bool inAir, bool isDefense)
    //{
    //    InuAI_Path ai = new InuAI_Path(src, aiType, speed, inAir, isDefense);
    //    return ai;
    //}

    //public void DestroyPathAI(InuAI_Path _ai)
    //{
    //    if (_ai == null)
    //        return;
    //    _ai.Destroy();
    //    mList_Path.Remove(_ai);
    //}

    #endregion

    #region Defense AI interfaces
    public InuAI_Attack CreateDefenseAI(InuStructure src,
                                        InuDefine.EInuAIType aiType,
                                        InuFloat attackRange,
                                        InuFloat sightRange
                                        )
    {
        InuAI_Attack ai = null;

        //ai = new InuAI_UnitAttack(src, attackScale, aiType, pickTargetAiType, attackRange, sightRange);
        return(ai);
    }
    protected override void InuStart()
    {
        base.InuStart();
        mHp     = mMaxHp;
        mShield = mMaxShield;

        if (state == InuDefine.EInuState.eCount)
        {
            state = InuDefine.EInuState.eIdle;
        }
    }
Exemple #17
0
    public void Normalize()
    {
        InuFloat mag = magnitude;

        if (mag == 0)
        {
            Debug.LogError("InuVector2 Normalize Error x:" + x.i + "  z:" + z.i);
            return;
        }
        x /= mag;
        z /= mag;
    }
Exemple #18
0
    public static int RoundDown(InuFloat f)
    {
        int      baseValue = (int)f.floatValue;
        InuFloat m         = f - baseValue;

        if (m >= 0.0f)
        {
            return(baseValue);
        }
        else
        {
            return(baseValue - 1);
        }
    }
Exemple #19
0
 public static InuFloat Clamp(InuFloat c, InuFloat min, InuFloat max)
 {
     if (c < min)
     {
         return(min);
     }
     else if (c > max)
     {
         return(max);
     }
     else
     {
         return(c);
     }
 }
Exemple #20
0
    public static InuFloat operator *(InuFloat c1, InuFloat c2)
    {
        InuFloat result = new InuFloat();

        result.v = (c1.v * c2.v); // INT_SCALE;
        if (result.v < INT_SCALE && result.v > -INT_SCALE && result.v != 0)
        {
            result.v = result.v > 0 ? 1 : -1;
        }
        else
        {
            result.v /= INT_SCALE;
        }
        return(result);
    }
Exemple #21
0
    public static int Round(InuFloat f)
    {
        int      baseValue = (int)f.floatValue;
        InuFloat m         = f - baseValue;

        if (m > 0.5f)
        {
            return(baseValue + 1);
        }
        else if (m < -0.5f)
        {
            return(baseValue - 1);
        }
        else
        {
            return(baseValue);
        }
    }
    bool InuHandleStep(List <Dictionary <string, object> > stateData, Dictionary <string, object> _data)
    {
        Dictionary <string, object> _tempData = new Dictionary <string, object>(_data);
        // exitStep = true: update next step's logic in next frame
        // exitStep = false: if next step's time arrives, update next logic in this frame
        bool     exitStep = true;
        InuFloat stepTime = new InuFloat((float)_tempData[InuParam.time]);

        // if the step time arrives
        if (mInuTimer >= stepTime)
        {
            InuCmd inucmd = (InuCmd)_tempData[InuParam.cmd];
            exitStep = false;

            // following is step logic
            switch (inucmd)
            {
            // do nothing cmd: just do nothing in this step
            case InuCmd.DoNothing:
                break;

            // exit cmd: do nothing any more in this state
            case InuCmd.Exit:
                mInuStep = short.MaxValue;
                exitStep = true;
                OnStateExit(state);
                return(exitStep);

            // go to cmd: move to a specific step, can jump over several steps, or jump back
            case InuCmd.GoTo:
                mInuStep = (short)_tempData[InuParam.step];
                if (stateData != null)
                {
                    // reach the end of state logic
                    if (mInuStep >= stateData.Count || mInuStep < 0)
                    {
                        if (mInuStep >= stateData.Count)
                        {
                            OnStateComplete(state);
                        }
                    }
                    // if not, set the timer
                    else
                    {
                        Dictionary <string, object> stepData = stateData[mInuStep];
                        mInuTimer = new InuFloat((float)stepData[InuParam.time]);
                    }
                }
                exitStep = true;
                return(exitStep);

            case InuCmd.UsePrefab:
                InuUpdatePrefab(_tempData);
                break;

            // play animation cmd: play specific animation for which models
            case InuCmd.PlayAnimation:
                InuPlayAnimation(_tempData, false);
                break;

            // crossfade animation cmd: crossfade to another animation
            case InuCmd.CrossFadeAnimation:
                InuPlayAnimation(_tempData, true);
                break;

            // stop current animation cmd: stop immediately
            case InuCmd.StopAnimation:
                InuStopAnimation(_tempData);
                break;

            // play a particle effect cmd: play an effect on a dummy position
            case InuCmd.PlayEffect:
                InuPlayEffect(_tempData);
                break;

            // stop a particle effect cmd: stop a specific effect with name
            case InuCmd.StopEffect:
                InuStopEffect(_tempData);
                break;

            // play sound cmd: play a sfx
            case InuCmd.PlaySfx:
                InuPlaySfx(_tempData);
                break;

            // Shake position cmd: iTween Shake utility
            case InuCmd.ShakePosition:
                Inu_ShakePosition(_tempData);
                break;

            // Orient to target cmd: face to an object within a second, the object(target) is assigned by its own AI
            case InuCmd.OrientToTarget:
                Inu_OrientToTarget(_tempData);
                break;

            // Destroy cmd: destroy this gameObject, be careful!
            case InuCmd.Destroy:
                Inu_Destroy(_tempData);
                mInuStep = short.MaxValue;
                exitStep = true;
                OnStateDestroy(state);
                return(exitStep);

            // Shake camera cmd
            case InuCmd.ShakeCamera:
                Inu_ShakeCamera(_tempData);
                break;

            // Goto Another state cmd
            case InuCmd.GoToState:
                Inu_GoToState(_tempData);
                exitStep = true;
                OnStateExit(state);
                return(exitStep);

            // Wait customized time: the time is given by outside
            case InuCmd.WaitCustomTime:
                Inu_WaitCustomTime(_tempData);
                exitStep = true;
                break;

            // Handle extra cmd in derived classes
            default:
                exitStep = Inu_ExtraFunction(_tempData);
                break;
            }

            // When State Logic Updating, change the state is very dangerous
            // if state changed, leave current state immediately
            if (mInuNextState != InuDefine.EInuState.eCount)
            {
                return(true);
            }

            mInuTimer -= stepTime;
            // step increment
            if (mInuStep < short.MaxValue)
            {
                mInuStep++;
            }
            if (mInuStep >= stateData.Count)
            {
                OnStateComplete(state);
            }
        }
        else
        {
            exitStep = true;
        }

        return(exitStep);
    }
Exemple #23
0
 public static InuFloat Lerp(InuFloat start, InuFloat end, InuFloat t)
 {
     return(start + (end - start) * t);
 }
Exemple #24
0
 public InuVector2(Vector3 _v)
 {
     x = new InuFloat(_v.x);
     z = new InuFloat(_v.z);
 }
Exemple #25
0
 public InuVector2(float _x, float _z)
 {
     x = new InuFloat(_x);
     z = new InuFloat(_z);
 }
Exemple #26
0
 public InuVector2(InuFloat _x, InuFloat _z)
 {
     x = _x;
     z = _z;
 }
Exemple #27
0
    public static InuFloat Sqrt(InuFloat _sqr)
    {
        //Debug.LogError("111: " + _sqr);
        if (_sqr.i < 0)
        {
            return(InuFloat.ZERO);
        }
        if (_sqr.i == 0)
        {
            return(InuFloat.ZERO);
        }
        long b = _sqr.i; // big
        long s = 0;

        if (_sqr.i > INT_SCALE * INT_SCALE)
        {
            if (b > 100)
            {
                b = 10;
                while (b * (b / INT_SCALE) < _sqr.i)
                {
                    b *= 10;
                }
            }
            //int loop = 0;
            while (b - s > 1)
            {
                long m = (b + s) / 2;
                if (m * (m / INT_SCALE) > _sqr.i)
                {
                    b = m;
                }
                else
                {
                    s = m;
                }

                //loop++;
            }
        }
        else
        {
            b *= 10;
            //long new_scale = INT_SCALE;// *INT_SCALE;
            //long sqr_i = _sqr.i;// *INT_SCALE;
            //b *= INT_SCALE;
            //s *= INT_SCALE;
            while (b - s > 1)
            {
                long m = (b + s) / 2;
                if (m * m > _sqr.i * INT_SCALE)
                {
                    b = m;
                }
                else
                {
                    s = m;
                }

                //loop++;
            }
            //b /= INT_SCALE;
            //s /= INT_SCALE;
        }
        //Debug.LogError("loop: " + loop);
        InuFloat result = new InuFloat();

        if (s == 0)
        {
            result.ScaledSet(1);
        }
        else
        {
            result.ScaledSet(s);
        }
        //Debug.LogError("222: " + result);
        return(result);
    }