Ejemplo n.º 1
0
    void OnTriggerEnter(Collider other)
    {
        if (other.CompareTag("BluePolice")) // Killed by police
        {
            SoaSensor s = other.gameObject.GetComponentInChildren <SoaSensor>();
            if (s != null)
            {
                s.logKill(thisSoaActor);
            }

            // Log event
            simControlScript.soaEventLogger.LogRedTruckCaptured(other.name, gameObject.name);

            // Find out where to retreat to
            BluePoliceSim b = other.gameObject.GetComponent <BluePoliceSim>();
            Vector3       retreatBasePosition = GetRetreatRedBase(b).transform.position;

            // Destroy self
            simControlScript.DestroyRedTruck(gameObject);

            // Configure a replacement agent
            RedTruckConfig c = new RedTruckConfig(
                retreatBasePosition.x / SimControl.KmToUnity,
                thisSoaActor.simAltitude_km,
                retreatBasePosition.z / SimControl.KmToUnity,
                new Optional <int>(),   // id (determined at runtime)
                new Optional <float>(), // beamwidth (use default)
                new Optional <string>(),
                new Optional <bool>(),
                new Optional <bool>(),
                new Optional <float>(),
                new Optional <float>(),
                new Optional <int>());

            // Instantiate and activate a replacement
            simControlScript.ActivateRedTruck(simControlScript.InstantiateRedTruck(c, true));
        }

        if (other.CompareTag("RedBase"))
        {
            RedBaseSim rb = other.gameObject.GetComponent <RedBaseSim>();
            if (rb != null)
            {
                // Drop off all civilians currently carried at the base
                for (int i = 0; i < thisSoaActor.numCiviliansStored; i++)
                {
                    simControlScript.soaEventLogger.LogCivilianInRedCustody(gameObject.name, other.name);
                }
                rb.Civilians += thisSoaActor.numCiviliansStored;
                thisSoaActor.numCiviliansStored = 0;

                // Assign a (target, closestBaseFromThatTarget) pair
                waypointScript.On = false;
                thisNavAgent.ResetPath();
                waypointScript.waypointIndex = 0;
                waypointScript.waypoints.Clear();

                // Nearest red base to intitial position assigns target
                target = rb.AssignTarget();

                // Store the initial target assignment in railsTarget, regardless of predRedMovement level
                if (assignRailsTarget)
                {
                    railsTarget       = target;
                    assignRailsTarget = false; //so that we don't do this again
                }

                // On rails, so set target back to initial assignment
                if (rails)
                {
                    target = railsTarget;
                }

                // Find red base closest to target
                closestBaseFromTarget = simControlScript.FindClosestInList(target, simControlScript.RedBases);

                // Add (target, closestBaseFromTarget) pair to waypointScript
                waypointScript.waypoints.Add(target);
                waypointScript.waypoints.Add(closestBaseFromTarget);
                waypointScript.On = true;

                // Weapon
                foreach (SoaWeapon weapon in thisSoaActor.Weapons)
                {
                    weapon.enabled = rb.EnableWeapon();
                }
            }
            // Indicate that actor is heading toward target
            zig = true;
        }

        if (other.CompareTag("NGO"))
        {
            // Red truck can inflict casualties, destroy supplies, and pick up civilians
            // at NGO sites
            NgoSim n = other.gameObject.GetComponent <NgoSim>();
            if (n != null)
            {
                // Act greedy and pick up as many civilians as you have room for
                uint numFreeSlots = thisSoaActor.GetNumFreeSlots();
                n.Civilians += numFreeSlots; // Keeps track of civilians taken from this site
                thisSoaActor.numCiviliansStored += numFreeSlots;

                // Only inflict one casualty and take one supply
                n.Casualties += 1f;
                n.Supply      = (n.Supply > 1f) ? (n.Supply - 1f) : 0f; // Can't go negative

                Debug.Log(transform.name + " attacks " + other.name);
            }
            // Indicates that actor is heading toward the closestBaseFromTarget
            zig = false;
        }

        if (other.CompareTag("Village"))
        {
            // Red truck only inflicts casualties and destroys supplies at villages
            VillageSim v = other.gameObject.GetComponent <VillageSim>();
            if (v != null)
            {
                // Only inflict one casualty and take one supply
                v.Casualties += 1f;
                v.Supply      = (v.Supply > 1f) ? (v.Supply - 1f) : 0f; // Can't go negative

                Debug.Log(transform.name + " attacks " + other.name);
            }
            // Indicates that actor is heading toward the closestBaseFromTarget
            zig = false;
        }
    }
Ejemplo n.º 2
0
    void OnTriggerEnter(Collider other)
    {
        // Return if triggered too early (SoaActor has not instantiated yet)
        if (thisSoaActor == null)
        {
            return;
        }

        if (other.CompareTag("BluePolice")) // Killed by police
        {
            SoaSensor s = other.gameObject.GetComponentInChildren <SoaSensor>();
            if (s != null)
            {
                s.logKill(thisSoaActor);
            }

            // Log event
            simControlScript.soaEventLogger.LogRedDismountCaptured(other.name, gameObject.name);

            // Find out where to retreat to
            BluePoliceSim b = other.gameObject.GetComponent <BluePoliceSim>();
            Vector3       retreatBasePosition = GetRetreatRedBase(b).transform.position;

            // Destroy self
            simControlScript.DestroyRedDismount(gameObject);

            // Configure a replacement agent
            RedDismountConfig c = new RedDismountConfig(
                retreatBasePosition.x / SimControl.KmToUnity,
                thisSoaActor.simAltitude_km,
                retreatBasePosition.z / SimControl.KmToUnity,
                new Optional <int>(),   // id (determined at runtime)
                new Optional <float>(), // beamwidth (use default)
                new Optional <string>(),
                new Optional <bool>(),
                new Optional <float>(),
                new Optional <int>());

            // Instantiate and activate a replacement
            simControlScript.ActivateRedDismount(simControlScript.InstantiateRedDismount(c, true));
        }

        if (other.CompareTag("RedBase"))
        {
            RedBaseSim rb = other.gameObject.GetComponent <RedBaseSim>();
            if (rb != null)
            {
                // Drop off all civilians currently carried at the base
                for (int i = 0; i < thisSoaActor.numCiviliansStored; i++)
                {
                    simControlScript.soaEventLogger.LogCivilianInRedCustody(gameObject.name, other.name);
                }
                rb.Civilians += thisSoaActor.numCiviliansStored;
                thisSoaActor.numCiviliansStored = 0;

                // Assign a new target and return to closest base from that target
                waypointScript.On = false;
                thisNavAgent.ResetPath();
                waypointScript.waypointIndex = 0;
                waypointScript.waypoints.Clear();
                GameObject target = rb.AssignTarget();
                waypointScript.waypoints.Add(target);
                waypointScript.waypoints.Add(simControlScript.FindClosestInList(target, simControlScript.RedBases));
                waypointScript.On = true;

                foreach (SoaWeapon weapon in thisSoaActor.Weapons)
                {
                    weapon.enabled = rb.EnableWeapon();
                }
            }
        }

        if (other.CompareTag("NGO"))
        {
            // Red dismount can inflict casualties, destroy supplies, and pick up civilians
            // at NGO sites
            NgoSim n = other.gameObject.GetComponent <NgoSim>();
            if (n != null)
            {
                // Act greedy and pick up as many civilians as you have room for
                uint numFreeSlots = thisSoaActor.GetNumFreeSlots();
                n.Civilians += numFreeSlots; // Keeps track of civilians taken from this site
                thisSoaActor.numCiviliansStored += numFreeSlots;

                // Only inflict one casualty and take one supply
                n.Casualties += 1f;
                n.Supply      = (n.Supply > 1f) ? (n.Supply - 1f) : 0f; // Can't go negative

                Debug.Log(transform.name + " attacks " + other.name);
            }
        }

        if (other.CompareTag("Village"))
        {
            // Red dismount only inflicts casualties and destroys supplies at villages
            VillageSim v = other.gameObject.GetComponent <VillageSim>();
            if (v != null)
            {
                // Only inflict one casualty and take one supply
                v.Casualties += 1f;
                v.Supply      = (v.Supply > 1f) ? (v.Supply - 1f) : 0f; // Can't go negative

                Debug.Log(transform.name + " attacks " + other.name);
            }
        }
    }