示例#1
0
        // feedback finish,you should compute the avg of the 10 frame data
        public override void Update(UEntity uEntity)
        {
            if (uEntity.GetComponent <AIState> ().mFeedbackerState)
            {
                float sum = 0.0f;
                for (int i = 0; i < 10; i++)
                {
                    sum += uEntity.GetComponent <AIState> ().mframebuffer [i];
                }
                sum /= 10.0f;
                for (int i = 0; i < uEntity.GetComponent <AIState> ().mPowerEdge [uEntity.GetComponent <AIState> ().mid_fir].Count; i++)
                {
                    if (uEntity.GetComponent <AIState> ().mPowerEdge [uEntity.GetComponent <AIState> ().mid_fir] [i].id == uEntity.GetComponent <AIState> ().mid_sec)
                    {
                        PowerNode tpn = new PowerNode();
                        tpn.id    = uEntity.GetComponent <AIState> ().mPowerEdge [uEntity.GetComponent <AIState> ().mid_fir] [i].id;
                        tpn.power = uEntity.GetComponent <AIState> ().mPowerEdge [uEntity.GetComponent <AIState> ().mid_fir] [i].power + sum;
                        if (tpn.power > 3.0f)
                        {
                            tpn.power = 3.0f;
                        }
                        if (tpn.power < 0.3f)
                        {
                            tpn.power = 0.3f;
                        }
                        uEntity.GetComponent <AIState> ().mPowerEdge [uEntity.GetComponent <AIState> ().mid_fir] [i] = tpn;
                        Debug.Log(uEntity.GetComponent <AIState> ().mid_fir + " " + uEntity.GetComponent <AIState> ().mPowerEdge [uEntity.GetComponent <AIState> ().mid_fir] [i].power + " " + uEntity.GetComponent <AIState> ().mPowerEdge [uEntity.GetComponent <AIState> ().mid_fir] [i].id);
                        break;
                    }
                }

                uEntity.GetComponent <AIState> ().mFeedbackerState = false;
            }
        }
示例#2
0
        // add a transfer about a node to another node
        public void AddEdge(StateTranfer pTranfer, StateFeedbacker pFeedbacker, int id1, int id2)
        {
            TranferNode tn = new TranferNode();

            tn.id       = id2;
            tn.mTranfer = pTranfer;

            FeedbackerNode fn = new FeedbackerNode();

            fn.id          = id2;
            fn.mFeedbacker = pFeedbacker;

            PowerNode pn = new PowerNode();

            pn.id    = id2;
            pn.power = 1.0f;

            mTranfer [id1].Add(tn);
            mFeedbacker [id1].Add(fn);
            mPowerEdge [id1].Add(pn);
        }
示例#3
0
        public override void Update(UEntity uEntity)
        {
            base.Update(uEntity);
            if (!uEntity.GetComponent <AIStrategy> ().isEnable)
            {
                return;
            }
            AIEntity pEntity = (AIEntity)uEntity;
            // get lod now
            int lod = uEntity.GetComponent <LODComponent> ().mLOD;

            // compute logic update velocity
            lod = lod * lod * lod;
            // update logic with lod
            if (pEntity.GetComponent <AIStrategy> ().timer <= 0.2f * lod)
            {
                pEntity.GetComponent <AIStrategy> ().timer += Time.deltaTime;
                return;
            }

            pEntity.GetComponent <AIStrategy> ().timer = 0.0f;
            // having cache ?
            if (pEntity.GetComponent <AIStrategy> ().IDBuffer != -1)
            {
                if (pEntity.GetComponent <AIStrategy> ().BufferFrame != 0)
                {
                    pEntity.GetComponent <AIStrategy> ().BufferFrame--;
                }
                else
                {
                    pEntity.GetComponent <AIStrategy> ().IDBuffer = -1;
                }
                return;
            }
            //the min value of the strategy action
            float minValue = 0.15f;
            // the max
            actionNode tActionNode1 = new actionNode();

            tActionNode1.action = 0.0f;
            tActionNode1.mid    = -1;
            // the second max
            actionNode tActionNode2 = new actionNode();

            tActionNode2.action = 0.0f;
            tActionNode2.mid    = -1;

            for (int i = 0; i < pEntity.GetComponent <AIStrategy> ().tempCount; i++)
            {
                float tempRate = pEntity.GetComponent <AIStrategy> ().mStrategyActioner [i](pEntity);
                tempRate *= pEntity.GetComponent <AIStrategy> ().mPower [i];
                if (tempRate > tActionNode1.action)
                {
                    tActionNode2.action = tActionNode1.action;
                    tActionNode2.mid    = tActionNode1.mid;
                    tActionNode1.action = tempRate;
                    tActionNode1.mid    = i;
                }
                else if (tempRate > tActionNode2.action)
                {
                    tActionNode2.action = tempRate;
                    tActionNode2.mid    = i;
                }
            }

            if (tActionNode1.action > minValue)
            {
                if (tActionNode1.mid == pEntity.GetComponent <AIStrategy> ().tempID)
                {
                    return;
                }
                // transfer, so compute the last frame data
                if (pEntity.GetComponent <AIStrategy> ().mFrameCaptureCounter != 10)
                {
                    float sum = 0.0f;
                    for (int i = 0; i < 10 - pEntity.GetComponent <AIStrategy> ().mFrameCaptureCounter; i++)
                    {
                        sum += pEntity.GetComponent <AIStrategy> ().bufferdata [i];
                    }
                    sum /= 10 - pEntity.GetComponent <AIStrategy> ().mFrameCaptureCounter;
                    pEntity.GetComponent <AIStrategy> ().mPower [pEntity.GetComponent <AIStrategy> ().LastID] += sum;
                    if (pEntity.GetComponent <AIStrategy> ().mPower [pEntity.GetComponent <AIStrategy> ().LastID] > 3.0f)
                    {
                        pEntity.GetComponent <AIStrategy> ().mPower [pEntity.GetComponent <AIStrategy> ().LastID] = 3.0f;
                    }
                    if (pEntity.GetComponent <AIStrategy> ().mPower [pEntity.GetComponent <AIStrategy> ().LastID] < 0.3f)
                    {
                        pEntity.GetComponent <AIStrategy> ().mPower [pEntity.GetComponent <AIStrategy> ().LastID] = 0.3f;
                    }
                    pEntity.GetComponent <AIStrategy> ().mFrameCaptureCounter = 10;
                }
                pEntity.GetComponent <AIStrategy> ().LastID             = pEntity.GetComponent <AIStrategy> ().tempID;
                pEntity.GetComponent <AIStrategy> ().mFrameCaptureStart = true;

                for (int i = 0; i < pEntity.GetComponent <AIState> ().mtempCount; i++)
                {
                    for (int j = 0; j < pEntity.GetComponent <AIStrategy> ().mAIState [pEntity.GetComponent <AIStrategy> ().tempID].mPowerEdge [i].Count; j++)
                    {
                        PowerNode pnt = new PowerNode();
                        pnt.id    = pEntity.GetComponent <AIState> ().mPowerEdge [i] [j].id;
                        pnt.power = pEntity.GetComponent <AIState> ().mPowerEdge [i] [j].power;
                        pEntity.GetComponent <AIStrategy> ().mAIState [pEntity.GetComponent <AIStrategy> ().tempID].mPowerEdge [i] [j] = pnt;
                    }
                }
                // update Strategy
                pEntity.GetComponent <AIStrategy> ().mStrategyExit[pEntity.GetComponent <AIStrategy>().tempID](pEntity);
                pEntity.GetComponent <AIStrategy> ().SetEntry(tActionNode1.mid);
                pEntity.GetComponent <AIStrategy> ().mStrategyEnter[pEntity.GetComponent <AIStrategy>().tempID](pEntity);
                // update cache
                if (tActionNode1.action - tActionNode2.action > 0.3f)
                {
                    pEntity.GetComponent <AIStrategy> ().IDBuffer    = pEntity.GetComponent <AIStrategy> ().tempID;
                    pEntity.GetComponent <AIStrategy> ().BufferFrame = 6;
                }
            }
        }
示例#4
0
        public override void Update(UEntity uEntity)
        {
            if (!uEntity.GetComponent <AIState> ().isEnable)
            {
                return;
            }

            // update state node
            uEntity.GetComponent <AIState> ().mExecuter [uEntity.GetComponent <AIState> ().tempID]((AIEntity)uEntity);



            if (uEntity.GetComponent <AIState> ().mStateAnimation.Count != 0)
            {
                // update animation
                string tName = uEntity.GetComponent <AIState> ().mStateAnimation [uEntity.GetComponent <AIState> ().tempID];
                uEntity.GetComponent <AIAnimation> ().mtempAnim = tName;
            }

            // get lod
            int lod = uEntity.GetComponent <LODComponent> ().mLOD;

            lod = lod * lod * lod;

            if (uEntity.GetComponent <AIState> ().timer <= 0.2f * lod)
            {
                uEntity.GetComponent <AIState> ().timer += Time.deltaTime;
                return;
            }

            uEntity.GetComponent <AIState> ().timer = 0.0f;

            // check the logic update

            // check any transfer
            for (int i = 0; i < uEntity.GetComponent <AIState> ().mTranfer[0].Count; i++)
            {
                if (uEntity.GetComponent <AIState> ().mTranfer [0] [i].id == uEntity.GetComponent <AIState> ().tempID)
                {
                    continue;
                }

                float tRate  = uEntity.GetComponent <AIState> ().mTranfer [0] [i].mTranfer(((AIEntity)uEntity));
                float tPower = uEntity.GetComponent <AIState> ().mPowerEdge [0] [i].power;

                bool returning = false;
                if (tRate * tPower > 0.04f)
                {
                    if (Random.Range(0.0f, 1.0f) <= tRate * tPower)
                    {
                        uEntity.GetComponent <AIState> ().mTempFeedbacker = uEntity.GetComponent <AIState> ().mFeedbacker [0] [i].mFeedbacker;
                        if (uEntity.GetComponent <AIState> ().mCaptureFrame > 0)
                        {
                            float sum = 0.0f;
                            for (int j = 0; j < 10 - uEntity.GetComponent <AIState> ().mCaptureFrame; j++)
                            {
                                sum += uEntity.GetComponent <AIState> ().mframebuffer [j];
                            }
                            sum /= 10.0f - uEntity.GetComponent <AIState> ().mCaptureFrame;
                            for (int j = 0; j < uEntity.GetComponent <AIState> ().mPowerEdge [uEntity.GetComponent <AIState> ().mid_fir].Count; j++)
                            {
                                if (uEntity.GetComponent <AIState> ().mPowerEdge [uEntity.GetComponent <AIState> ().mid_fir] [j].id == uEntity.GetComponent <AIState> ().mid_sec)
                                {
                                    PowerNode tpn = new PowerNode();
                                    tpn.id    = uEntity.GetComponent <AIState> ().mPowerEdge [uEntity.GetComponent <AIState> ().mid_fir] [j].id;
                                    tpn.power = uEntity.GetComponent <AIState> ().mPowerEdge [uEntity.GetComponent <AIState> ().mid_fir] [j].power + sum;
                                    if (tpn.power > 3.0f)
                                    {
                                        tpn.power = 3.0f;
                                    }
                                    if (tpn.power < 0.3f)
                                    {
                                        tpn.power = 0.3f;
                                    }
                                    uEntity.GetComponent <AIState> ().mPowerEdge [uEntity.GetComponent <AIState> ().mid_fir] [j] = tpn;
                                    break;
                                }
                            }
                        }
                        uEntity.GetComponent <AIState> ().mCaptureFrame = 10;
                        uEntity.GetComponent <AIState> ().mid_fir       = 0;
                        uEntity.GetComponent <AIState> ().mid_sec       = uEntity.GetComponent <AIState> ().mTranfer [0] [i].id;
                        uEntity.GetComponent <AIState> ().mExiter [uEntity.GetComponent <AIState> ().tempID] ((AIEntity)uEntity);
                        uEntity.GetComponent <AIState> ().tempID = uEntity.GetComponent <AIState> ().mTranfer [0] [i].id;
                        uEntity.GetComponent <AIState> ().mEnterer [uEntity.GetComponent <AIState> ().tempID] ((AIEntity)uEntity);
                        returning = true;
                    }
                }

                if (returning)
                {
                    return;
                }
            }

            // check the transfer with this state
            for (int i = 0; i < uEntity.GetComponent <AIState> ().mTranfer [uEntity.GetComponent <AIState> ().tempID].Count; i++)
            {
                float tRate    = uEntity.GetComponent <AIState> ().mTranfer [uEntity.GetComponent <AIState> ().tempID] [i].mTranfer(((AIEntity)uEntity));
                float tPower   = uEntity.GetComponent <AIState> ().mPowerEdge [uEntity.GetComponent <AIState> ().tempID] [i].power;
                bool  breaking = false;
                if (tRate * tPower > 0.04f)
                {
                    if (Random.Range(0.0f, 1.0f) <= tRate * tPower)
                    {
                        uEntity.GetComponent <AIState> ().mTempFeedbacker = uEntity.GetComponent <AIState> ().mFeedbacker [uEntity.GetComponent <AIState> ().tempID] [i].mFeedbacker;
                        if (uEntity.GetComponent <AIState> ().mCaptureFrame > 0)
                        {
                            float sum = 0.0f;
                            for (int j = 0; j < 10 - uEntity.GetComponent <AIState> ().mCaptureFrame; j++)
                            {
                                sum += uEntity.GetComponent <AIState> ().mframebuffer [j];
                            }
                            sum /= 10.0f - uEntity.GetComponent <AIState> ().mCaptureFrame;
                            for (int j = 0; j < uEntity.GetComponent <AIState> ().mPowerEdge [uEntity.GetComponent <AIState> ().mid_fir].Count; j++)
                            {
                                if (uEntity.GetComponent <AIState> ().mPowerEdge [uEntity.GetComponent <AIState> ().mid_fir] [j].id == uEntity.GetComponent <AIState> ().mid_sec)
                                {
                                    PowerNode tpn = new PowerNode();
                                    tpn.id    = uEntity.GetComponent <AIState> ().mPowerEdge [uEntity.GetComponent <AIState> ().mid_fir] [j].id;
                                    tpn.power = uEntity.GetComponent <AIState> ().mPowerEdge [uEntity.GetComponent <AIState> ().mid_fir] [j].power + sum;
                                    if (tpn.power > 3.0f)
                                    {
                                        tpn.power = 3.0f;
                                    }
                                    if (tpn.power < 0.3f)
                                    {
                                        tpn.power = 0.3f;
                                    }
                                    uEntity.GetComponent <AIState> ().mPowerEdge [uEntity.GetComponent <AIState> ().mid_fir] [j] = tpn;
                                    break;
                                }
                            }
                        }
                        uEntity.GetComponent <AIState> ().mCaptureFrame = 10;
                        uEntity.GetComponent <AIState> ().mid_fir       = uEntity.GetComponent <AIState> ().tempID;
                        uEntity.GetComponent <AIState> ().mid_sec       = uEntity.GetComponent <AIState> ().mTranfer [uEntity.GetComponent <AIState> ().tempID] [i].id;
                        uEntity.GetComponent <AIState> ().mExiter [uEntity.GetComponent <AIState> ().tempID] ((AIEntity)uEntity);
                        uEntity.GetComponent <AIState> ().tempID = uEntity.GetComponent <AIState> ().mTranfer [uEntity.GetComponent <AIState> ().tempID] [i].id;
                        uEntity.GetComponent <AIState> ().mEnterer [uEntity.GetComponent <AIState> ().tempID] ((AIEntity)uEntity);
                        breaking = true;
                    }
                }
                if (breaking)
                {
                    break;
                }
            }
        }