示例#1
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);
            }
        }
    }
示例#2
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;
        }
    }
示例#3
0
    void OnTriggerEnter(Collider other)
    {
        if (other.CompareTag("BlueBase"))
        {
            // Instant refuel
            thisSoaActor.fuelRemaining_s = fuelTankSize_s;

            // Process casualties/supplies
            BlueBaseSim b = other.gameObject.GetComponent <BlueBaseSim>();
            if (b != null)
            {
                // Deliver specified # of casualties first
                int numCasualtiesToDeliver = RequestCasualtyDelivery((int)thisSoaActor.numCasualtiesStored);
                for (int i = 0; i < numCasualtiesToDeliver; i++)
                {
                    simControlScript.soaEventLogger.LogCasualtyDelivery(gameObject.name, other.name);
                }
                b.Casualties += numCasualtiesToDeliver;
                thisSoaActor.numCasualtiesStored = (uint)(thisSoaActor.numCasualtiesStored - numCasualtiesToDeliver);

                // Pick up specified # of supplies next
                int numSuppliesToPickup = RequestSupplyPickup((int)thisSoaActor.GetNumFreeSlots(), b.Supply);
                b.Supply -= numSuppliesToPickup;
                thisSoaActor.numSuppliesStored = (uint)(thisSoaActor.numSuppliesStored + numSuppliesToPickup);

                // Make a new observation about the site
                thisSoaActor.RegisterSiteObservation(new soa.Belief_Base(
                                                         b.destination_id, b.gridCells, b.Supply));
            }
        }

        if (other.CompareTag("NGO"))
        {
            NgoSim n = other.gameObject.GetComponent <NgoSim>();
            if (n != null)
            {
                // Deliver specified # of supplies first
                int numSuppliesToDeliver = RequestSupplyDelivery((int)thisSoaActor.numSuppliesStored, n.destination_id);
                for (int i = 0; i < numSuppliesToDeliver; i++)
                {
                    simControlScript.soaEventLogger.LogSupplyDelivered(gameObject.name, other.name);
                }
                n.Supply += numSuppliesToDeliver;
                thisSoaActor.numSuppliesStored = (uint)(thisSoaActor.numSuppliesStored - numSuppliesToDeliver);

                // Pickup specified # of casualties next
                int numCasualtiesToPickup = RequestCasualtyPickup((int)thisSoaActor.GetNumFreeSlots(), n.Casualties, n.destination_id);
                n.Casualties -= numCasualtiesToPickup;
                thisSoaActor.numCasualtiesStored = (uint)(thisSoaActor.numCasualtiesStored + numCasualtiesToPickup);

                // Make a new observation about the site
                thisSoaActor.RegisterSiteObservation(new soa.Belief_NGOSite(
                                                         n.destination_id, n.gridCells, n.Supply, n.Casualties, n.Civilians));
            }
        }

        if (other.CompareTag("Village"))
        {
            VillageSim v = other.gameObject.GetComponent <VillageSim>();
            if (v != null)
            {
                // Deliver specified # of supplies first
                int numSuppliesToDeliver = RequestSupplyDelivery((int)thisSoaActor.numSuppliesStored, v.destination_id);
                for (int i = 0; i < numSuppliesToDeliver; i++)
                {
                    simControlScript.soaEventLogger.LogSupplyDelivered(gameObject.name, other.name);
                }
                v.Supply += numSuppliesToDeliver;
                thisSoaActor.numSuppliesStored = (uint)(thisSoaActor.numSuppliesStored - numSuppliesToDeliver);

                // Pickup specified # of casualties next twupy1
                int numCasualtiesToPickup = RequestCasualtyPickup((int)thisSoaActor.GetNumFreeSlots(), v.Casualties, v.destination_id);
                v.Casualties -= numCasualtiesToPickup;
                thisSoaActor.numCasualtiesStored = (uint)(thisSoaActor.numCasualtiesStored + numCasualtiesToPickup);

                // Make a new observation about the site
                thisSoaActor.RegisterSiteObservation(new soa.Belief_Village(
                                                         v.destination_id, v.gridCells, v.Supply, v.Casualties));
            }
        }
    }