Beispiel #1
0
    public void ExitCover()
    {
        if (m_cover != null)
        {
            CoverSpot spot = m_cover.GetComponent <CoverSpot>();
            if (spot != null)
            {
                spot.SetUse(false);
                spot.SetOwner(null);
            }

            m_cover = null;

            inCover     = 0.0f;
            takingCover = false;

            /*Uncrouch();
             * peek = 0;
             * crouchPeek = false;
             * peekCooldown = 500.0f;
             * crouchPeekCooldown = 500.0f;
             * peekDur = 0.0f;
             * crouchPeekDur = 0.0f;*/
            //m_waypoint = m_oldpoint;
        }
    }
Beispiel #2
0
    public void TakeCover()
    {
        //find cover
        if (!takingCover)
        {
            //m_oldpoint = m_waypoint;

            //get nearest cover
            int layerMask = 1 << 9;

            Collider[] coverSpots = Physics.OverlapSphere(transform.position, 30.0f, layerMask, QueryTriggerInteraction.Collide);
            float      value      = 200000.0f;

            foreach (Collider spot in coverSpots)
            {
                CoverSpot thisSpot = spot.GetComponent <CoverSpot>();

                if (!thisSpot.InUse())
                {
                    UnityEngine.AI.NavMeshPath testPath = new UnityEngine.AI.NavMeshPath();
                    m_agent.CalculatePath(spot.transform.position, testPath);

                    float   tempDist   = 0.0f;
                    Vector3 prevCorner = testPath.corners[0];

                    for (int i = 1; i < testPath.corners.Length; i++)
                    {
                        Vector3 curCorner = testPath.corners[i];
                        float   thisDist  = Vector3.Distance(prevCorner, curCorner);
                        tempDist += thisDist;
                        if (Physics.Raycast(prevCorner, (curCorner - prevCorner), thisDist, (1 << 12)))
                        {
                            tempDist += 100.0f;
                        }
                        prevCorner = curCorner;
                    }

                    float newDanger = thisSpot.GetSquadDanger();

                    float shootable = 0.0f;
                    if (thisSpot.IsLow())
                    {
                        //shootable = 40.0f;
                    }

                    float closeTarget = 0.0f;
                    if (m_target != null)
                    {
                        //closeTarget = Vector3.Distance(spot.transform.position, m_target.position) * 15.0f;
                    }

                    float newValue = (tempDist * 15.0f) + newDanger - shootable + closeTarget;

                    if (newValue < value)
                    {
                        //Debug.Log(tempDist + " " + newDanger + " " + newValue);
                        m_cover = spot.transform;
                        value   = newValue;
                    }
                }
            }

            CoverSpot checkSpot = m_cover.GetComponent <CoverSpot>();
            if (checkSpot != null)
            {
                checkSpot.SetUse(true);
                checkSpot.SetOwner(transform);
                inCover     = 3000.0f;
                takingCover = true;
                holding     = false;
            }
        }
    }
Beispiel #3
0
    public void EnterDoor(Transform door, int side, int state)
    {
        Debug.Log("attempting to enter door");
        if (isLeader)
        {
            m_doorstate = state;
            m_doorside  = side;

            if (takingCover)
            {
                takingCover = false;
                inCover     = 0.0f;

                CoverSpot checkSpot = m_cover.GetComponent <CoverSpot>();
                if (checkSpot != null)
                {
                    checkSpot.SetUse(false);
                    checkSpot.SetOwner(null);
                    holding = false;
                }
            }

            stacking = true;
            //m_oldpoint = m_waypoint;
            //m_waypoint = door;

            m_agent.destination  = door.position + door.forward * side;
            m_agent.destination += door.right * 2.5f;

            m_door = door;

            int stackLeft  = 0;
            int stackRight = 1;
            int neg        = -1;

            foreach (SquadMember squad in m_squad)
            {
                if (squad != null)
                {
                    int thisStack = 0;
                    if (neg == -1)
                    {
                        stackLeft++;
                        thisStack = stackLeft;
                    }
                    else
                    {
                        stackRight++;
                        thisStack = stackRight;
                    }

                    squad.stacking = true;

                    if (squad.takingCover)
                    {
                        squad.takingCover = false;
                        squad.inCover     = 0.0f;

                        CoverSpot checkSpot = squad.m_cover.GetComponent <CoverSpot>();
                        if (checkSpot != null)
                        {
                            checkSpot.SetUse(false);
                            checkSpot.SetOwner(null);
                            squad.holding = false;
                        }

                        squad.m_door = door;

                        //squad.m_waypoint = squad.m_oldpoint;
                    }

                    squad.m_agent.destination  = door.position + door.forward * side;
                    squad.m_agent.destination += door.right * (2.5f + (1.0f * thisStack)) * neg;

                    neg *= -1;
                }
            }
        }
    }