Example #1
0
    /// <summary>
    /// Swat AI
    /// if there is no building under siege they will just roam through the level, going to different civilian actions to find the player,
    /// if there is a building under siege, once the police have surrounded all the buildings entrances they will move room by room until they have checked all the rooms
    /// With both they will respond to noises & cctv alerts.
    /// </summary>
    void newSwatController()
    {
        if (buildingUnderSiege == null)
        {
            if (areWeFormedUp() == true)
            {
                if (investigatePoint == false && seenHostile == false)
                {
                    if (setCivilPoints == false)
                    {
                        swatCivilPoint = LevelController.me.getCivilianAction().gameObject;
                        foreach (GameObject g in swatInLevel)
                        {
                            NPCController npcc = g.GetComponent <NPCController> ();
                            if (npcc.inv.doWeHaveAWeaponWeCanUse() == true)
                            {
                                Weapon w = npcc.inv.getWeaponWeCanUse();
                                w.equipItem();
                            }
                            if (npcc.currentBehaviour == null)
                            {
                            }
                            else
                            {
                                Destroy(npcc.currentBehaviour);
                            }
                            NPCBehaviour_SwatGoToPoint beh = g.AddComponent <NPCBehaviour_SwatGoToPoint> ();
                            beh.point             = swatCivilPoint;
                            npcc.currentBehaviour = beh;
                        }
                        setCivilPoints = true;
                    }

                    foreach (GameObject g in swatInLevel)
                    {
                        NPCController npcc = g.GetComponent <NPCController> ();
                        if (npcc.GetComponent <NPCBehaviour_SwatGoToPoint> () == false)
                        {
                            if (npcc.inv.doWeHaveAWeaponWeCanUse() == true)
                            {
                                Weapon w = npcc.inv.getWeaponWeCanUse();
                                w.equipItem();
                            }
                            if (npcc.currentBehaviour == null)
                            {
                            }
                            else
                            {
                                Destroy(npcc.currentBehaviour);
                            }
                            NPCBehaviour_SwatGoToPoint beh = g.AddComponent <NPCBehaviour_SwatGoToPoint> ();
                            beh.point             = swatCivilPoint;
                            npcc.currentBehaviour = beh;
                        }
                    }

                    bool shouldWeReset = true;
                    foreach (GameObject g in swatInLevel)
                    {
                        if (Vector2.Distance(g.transform.position, swatCivilPoint.transform.position) > 5.0f)
                        {
                            shouldWeReset = false;
                        }
                    }

                    if (shouldWeReset == true)
                    {
                        setCivilPoints = false;
                    }
                }
                else if (seenHostile == true)
                {
                    if (setSwatToAttack == false)
                    {
                        PhoneTab_RadioHack.me.setNewText("Target spotted, moving to engage.", radioHackBand.swat);

                        attacking = new List <NPCBehaviour_SWATAttackTarget> ();
                        foreach (GameObject g in swatInLevel)
                        {
                            NPCController npc = g.GetComponent <NPCController> ();
                            if (npc.currentBehaviour == null)
                            {
                            }
                            else
                            {
                                Destroy(npc.currentBehaviour);
                            }
                            NPCBehaviour_SWATAttackTarget nb = g.AddComponent <NPCBehaviour_SWATAttackTarget> ();
                            npc.currentBehaviour = nb;
                            attacking.Add(nb);
                        }
                        setSwatToAttack = true;
                    }
                    else
                    {
                        //add some condition to  check if they have lost the target
                        if (doSwatStillHaveTarget() == true)
                        {
                            lastRoom = LevelController.me.roomPlayerIsIn;
                        }
                        else
                        {
                            swatLoseTargetTimer -= Time.deltaTime;
                            if (swatLoseTargetTimer <= 0)
                            {
                                if (lastRoom == null)
                                {
                                }
                                else
                                {
                                    PhoneTab_RadioHack.me.setNewText("Target lost, moving to " + lastRoom.roomName, radioHackBand.swat);
                                }
                                seenHostile         = false;
                                investigatePoint    = false;
                                currentRoomSwat     = null;
                                goingToRoom         = true;
                                swatLoseTargetTimer = 10.0f;
                                setSwatToAttack     = false;
                            }
                        }
                    }
                }
                else if (investigatePoint == true)
                {
                    if (investigate.areWeAtPosition() == false)
                    {
                        swatTarget = investigate.haveWeSeenSuspiciousObject();
                        if (swatTarget == null)
                        {
                            seenHostile = false;
                        }
                        else
                        {
                            seenHostile = true;
                        }
                    }
                    else if (swatGoingToCurrentPoint != null)
                    {
                        if (seenHostile == false)
                        {
                            NPCController npc = swatInvestigating.GetComponent <NPCController> ();

                            if (npc.currentBehaviour == null)
                            {
                            }
                            else
                            {
                                Destroy(npc.currentBehaviour);
                            }

                            NPCBehaviour nb = swatGoingToCurrentPoint.AddComponent <NPCBehaviour_SwatGoToPoint> ();
                            npc.currentBehaviour = nb;
                        }
                    }
                }
            }
            else
            {
                //check for form up stuff
                foreach (GameObject g in swatInLevel)
                {
                    NPCController npc = g.GetComponent <NPCController> ();

                    if (npc.currentBehaviour == null || npc.currentBehaviour.myType != behaviourType.formUp)
                    {
                        if (npc.currentBehaviour == null)
                        {
                        }
                        else
                        {
                            Destroy(npc.currentBehaviour);
                        }

                        NPCBehaviour_SwatFormUp newB = g.AddComponent <NPCBehaviour_SwatFormUp> ();
                        npc.currentBehaviour = newB;
                    }
                }
            }
        }
        else
        {
            if (buildingSurrounded == true && areWeFormedUp() == true && areAllSwatSpawned() == true)
            {
                //Debug.Log ("Swat surrounded building and are formed up");
                if (investigatePoint == false && seenHostile == false)
                {
                    if (roomsToGoTo == null || roomsToGoTo.Count == 0)
                    {
                        getRoomsToGoTo();
                    }

                    if (roomsGoingTo == null || roomsGoingTo.Count == 0)
                    {
                        roomsGoingTo = roomsToGoTo;
                    }

                    //if (currentRoomSwat == null) {
                    //	currentRoomSwat = roomsGoingTo [0];
                    //	roomsGoingTo.Remove (lastRoom);
                    //}

                    if (currentRoomSwat == null)
                    {
                        swatGoingIn  = new List <GameObject> ();
                        goToEntrance = new List <NPCBehaviour_SwatGoToRoomEntrance> ();



                        if (lastRoom == null)
                        {
                            currentRoomSwat = roomsGoingTo [0];
                            if (currentRoomSwat.nodesForSwat == null || currentRoomSwat.nodesForSwat.Count == 0)
                            {
                                currentRoomSwat.setPointsToGoTo();
                            }
                        }
                        else
                        {
                            currentRoomSwat = lastRoom;
                            lastRoom        = null;
                            if (currentRoomSwat.nodesForSwat == null || currentRoomSwat.nodesForSwat.Count == 0)
                            {
                                currentRoomSwat.setPointsToGoTo();
                            }
                        }
                        roomsGoingTo.RemoveAt(0);
                        goingToRoom = true;

                        if (roomsGoingTo.Count == 0)
                        {
                            roomsGoingTo = roomsToGoTo;
                        }

                        setPointsToGoTo();
                    }

                    if (pointsToSecure == null || pointsToSecure.Count == 0)
                    {
                        getPointsToSecure();
                    }

                    if (pointsToGoTo == null || pointsToGoTo.Count == 0)
                    {
                        setPointsToGoTo();
                    }


                    if (nb == null && goingToRoom == false)
                    {
                        //Debug.Log ("Not going to room");
                        currentPoint = pointsToGoTo [0];
                        if (swatGoingToCurrentPoint == null || swatGoingIn.Count == 0)
                        {
                            swatGoingToCurrentPoint = getFreeSwatNearPoint(currentPoint.transform.position);
                            swatGoingIn.Add(swatGoingToCurrentPoint);
                        }
                        else
                        {
                            foreach (GameObject g in swatInLevel)
                            {
                                if (swatGoingIn.Contains(g) == false)                                           //TODO add checks for if they are dead/going for target etc...
                                {
                                    swatGoingToCurrentPoint = g;
                                    swatGoingIn.Add(g);

                                    break;
                                }
                            }
                        }
                        if (swatGoingIn.Count == swatInLevel.Count)
                        {
                            swatGoingIn.Clear();
                        }

                        if (swatGoingToCurrentPoint == null)
                        {
                        }
                        else
                        {
                            NPCController npc = swatGoingToCurrentPoint.GetComponent <NPCController> ();
                            if (npc.currentBehaviour == null)
                            {
                            }
                            else
                            {
                                Destroy(npc.currentBehaviour);
                            }
                            nb = swatGoingToCurrentPoint.AddComponent <NPCBehaviour_SwatGoToPoint> ();
                            npc.currentBehaviour = nb;
                        }
                    }
                    else if (nb == null && goingToRoom == true)
                    {
                        //Debug.Log ("Going to room");
                        if (goToEntrance == null || goToEntrance.Count == 0)
                        {
                            goToEntrance = new List <NPCBehaviour_SwatGoToRoomEntrance> ();
                            foreach (GameObject g in swatInLevel)
                            {
                                NPCController n = g.GetComponent <NPCController> ();
                                if (n.currentBehaviour == null)
                                {
                                }
                                else
                                {
                                    Destroy(n.currentBehaviour);
                                }

                                NPCBehaviour_SwatGoToRoomEntrance nb = n.gameObject.AddComponent <NPCBehaviour_SwatGoToRoomEntrance> ();
                                n.currentBehaviour = nb;
                                goToEntrance.Add(nb);
                            }
                        }

                        if (areSwatAtEntranceToRoom() == true)
                        {
                            PhoneTab_RadioHack.me.setNewText("SWAT Team secutring " + currentRoomSwat.roomName, radioHackBand.swat);

                            goingToRoom = false;
                        }
                    }
                    else if (nb.areWeAtPosition() == true)
                    {
                        pointsBeenTo.Add(pointsToGoTo [0]);
                        pointsToGoTo.RemoveAt(0);
                        if (pointsToGoTo.Count == 0)
                        {
                            PhoneTab_RadioHack.me.setNewText(currentRoomSwat.roomName + "Has been secured, moving to " + roomsGoingTo [0].roomName, radioHackBand.swat);

                            currentRoomSwat = null;
                            pointsBeenTo.Clear();
                            swatGoingIn.Clear();
                            goToEntrance.Clear();
                            goingToRoom = true;
                        }
                        nb = null;
                    }
                }
                else if (seenHostile == true)
                {
                    if (setSwatToAttack == false)
                    {
                        PhoneTab_RadioHack.me.setNewText("Target spotted, moving to engage.", radioHackBand.swat);

                        attacking = new List <NPCBehaviour_SWATAttackTarget> ();
                        foreach (GameObject g in swatInLevel)
                        {
                            NPCController npc = g.GetComponent <NPCController> ();
                            if (npc.currentBehaviour == null)
                            {
                            }
                            else
                            {
                                Destroy(npc.currentBehaviour);
                            }
                            NPCBehaviour_SWATAttackTarget nb = g.AddComponent <NPCBehaviour_SWATAttackTarget> ();
                            npc.currentBehaviour = nb;
                            attacking.Add(nb);
                        }
                        setSwatToAttack = true;
                    }
                    else
                    {
                        //add some condition to  check if they have lost the target
                        if (doSwatStillHaveTarget() == true)
                        {
                            lastRoom = LevelController.me.roomPlayerIsIn;
                        }
                        else
                        {
                            swatLoseTargetTimer -= Time.deltaTime;
                            if (swatLoseTargetTimer <= 0)
                            {
                                if (lastRoom == null)
                                {
                                }
                                else
                                {
                                    PhoneTab_RadioHack.me.setNewText("Target lost, moving to " + lastRoom.roomName, radioHackBand.swat);
                                }
                                seenHostile         = false;
                                investigatePoint    = false;
                                currentRoomSwat     = null;
                                goingToRoom         = true;
                                swatLoseTargetTimer = 10.0f;
                                setSwatToAttack     = false;
                            }
                        }
                    }
                }
                else if (investigatePoint == true)
                {
                    if (investigate.areWeAtPosition() == false)
                    {
                        swatTarget = investigate.haveWeSeenSuspiciousObject();
                        if (swatTarget == null)
                        {
                            seenHostile = false;
                        }
                        else
                        {
                            seenHostile = true;
                        }
                    }
                    else
                    {
                        if (seenHostile == false)
                        {
                            NPCController npc = swatInvestigating.GetComponent <NPCController> ();

                            if (npc.currentBehaviour == null)
                            {
                            }
                            else
                            {
                                Destroy(npc.currentBehaviour);
                            }

                            NPCBehaviour nb = swatGoingToCurrentPoint.AddComponent <NPCBehaviour_SwatGoToPoint> ();
                            npc.currentBehaviour = nb;
                        }
                    }
                }
            }
            else
            {
                foreach (GameObject g in swatInLevel)
                {
                    NPCController npc = g.GetComponent <NPCController> ();

                    if (npc.currentBehaviour == null || npc.currentBehaviour.myType != behaviourType.formUp)
                    {
                        if (npc.currentBehaviour == null)
                        {
                        }
                        else
                        {
                            Destroy(npc.currentBehaviour);
                        }

                        NPCBehaviour_SwatFormUp newB = g.AddComponent <NPCBehaviour_SwatFormUp> ();
                        npc.currentBehaviour = newB;
                    }
                }
            }
        }
    }
Example #2
0
    /// <summary>
    ///  Checks for if any swat are dead and will remove them from active swat + fix any behaviours if they were the swat member currently going to the point.
    /// </summary>
    void shouldWeRefreshSWAT()
    {
        bool refresh = false;

        if (swatInLevel == null)
        {
            return;
        }

        foreach (GameObject g in swatInLevel)
        {
            NPCController npc = g.GetComponent <NPCController> ();

            if (npc == null)
            {
                continue;
            }

            if (npc.npcB.myType == AIType.swat)
            {
                //Debug.Log (npc.gameObject.name+ " Fount swat with " + npc.myHealth.healthValue);

                if (npc.gameObject.tag == "Dead/Knocked" && npc.myHealth.healthValue <= 0)
                {
                    refresh = true;
                }
            }
        }

        if (refresh == true)
        {
            //Debug.Log ("Refreshing swat");
            List <NPCController> swatAvailable = new List <NPCController> ();


            foreach (GameObject g in swatInLevel)
            {
                NPCController npc = g.GetComponent <NPCController> ();
                if (npc.npcB.myType == AIType.swat)
                {
                    if (npc.myHealth.healthValue > 0)
                    {
                        swatAvailable.Add(npc);
                    }
                }
            }
            if (buildingSurrounded == true)
            {
                if (investigatePoint == true)
                {
                    NPCController investigatingController = swatInvestigating.GetComponent <NPCController> ();
                    if (swatAvailable.Contains(investigatingController) == false)
                    {
                        swatInvestigating = swatAvailable [0].gameObject;
                        NPCController npc = swatInvestigating.GetComponent <NPCController> ();
                        if (npc.currentBehaviour == null)
                        {
                        }
                        else
                        {
                            Destroy(npc.currentBehaviour);
                        }

                        investigate          = swatInvestigating.AddComponent <NPCBehaviour_SwatInvestigatePoint> ();
                        npc.currentBehaviour = investigate;
                        investigatePoint     = true;
                    }
                }
                else if (investigatePoint == false && seenHostile == false)
                {
                    if (goingToRoom == true)
                    {
                        goToEntrance = new List <NPCBehaviour_SwatGoToRoomEntrance> ();

                        foreach (NPCController n in swatAvailable)
                        {
                            if (n.currentBehaviour == null)
                            {
                            }
                            else
                            {
                                Destroy(n.currentBehaviour);
                            }

                            NPCBehaviour_SwatGoToRoomEntrance nb = n.gameObject.AddComponent <NPCBehaviour_SwatGoToRoomEntrance> ();
                            n.currentBehaviour = nb;
                            goToEntrance.Add(nb);
                        }
                    }
                    else
                    {
                        NPCController investigatingController = swatGoingToCurrentPoint.GetComponent <NPCController> ();
                        if (swatAvailable.Contains(investigatingController) == false)
                        {
                            swatGoingToCurrentPoint = swatAvailable [0].gameObject;

                            NPCController npc = swatGoingToCurrentPoint.GetComponent <NPCController> ();
                            if (npc.currentBehaviour == null)
                            {
                            }
                            else
                            {
                                Destroy(npc.currentBehaviour);
                            }
                            nb = swatGoingToCurrentPoint.AddComponent <NPCBehaviour_SwatGoToPoint> ();
                            npc.currentBehaviour = nb;
                        }
                    }
                }
            }
            swatInLevel.Clear();
            foreach (NPCController n in swatAvailable)
            {
                swatInLevel.Add(n.gameObject);
            }
        }
    }