Beispiel #1
0
 private void spawnUnits(int numberOfUnits, EMERGENCY_TYPE type, Vector3 targetPosition)
 {
     for (int i = 0; i < numberOfUnits; i++)
     {
         spawnUnit(type, targetPosition);
     }
     EmergencyDispatch.Report(UNIT_STATUS.AWAITING_SPAWN, null, emergencyId);
 }
Beispiel #2
0
    private void spawnUnit(EMERGENCY_TYPE type, Vector3 targetPosition)
    {
        List <Pos> endPositions = getEndPosForVector(targetPosition);

        Pos startPos;

        do
        {
            startPos = NodeIndex.getPosById(Misc.pickRandomKey(NodeIndex.endPointDriveWayIndex));
        } while (startPos.Id == endPositions[0].Id || (endPositions.Count == 2 && startPos.Id == endPositions[1].Id));

        // Find out which is the closest of the two end points
        Pos endPos        = null;
        Pos secondLastPos = null;

        if (endPositions.Count == 1)
        {
            endPos = endPositions[0];
        }
        else
        {
            if (Game.isPathToFirstClosest(startPos, endPositions[0], endPositions[1]))
            {
                endPos        = endPositions[1];
                secondLastPos = endPositions[0];
            }
            else
            {
                endPos        = endPositions[0];
                secondLastPos = endPositions[1];
            }
        }

        // TODO - When having Ambulance or Fire Truck, change some of these
        // TODO - Which of these SHOULD be "Po-liz", and which shouldn't
        float       speedFactor  = Misc.randomRange(1.1f, 1.5f);
        float       acceleration = Misc.randomRange(3f, 3.5f);
        long        newId        = 0L;
        string      newName      = "Po-liz";
        float       newTime      = GameTimer.elapsedTime() + Misc.randomRange(5f, 15f);
        List <long> newWayPoints = secondLastPos != null ? new List <long>()
        {
            secondLastPos.Id
        } : new List <long>();
        string       newBrand        = "Po-liz";
        string       newType         = "Po-liz";
        List <long>  newPassengerIds = new List <long>();
        List <float> newMood         = new List <float>()
        {
            1f, 0f, 1.5f
        };

        Setup.VehicleSetup vehicleSetup = new Setup.VehicleSetup(newId, newName, newTime, startPos.Id, endPos.Id, null, false, false, newWayPoints, newBrand, null, newType, 0, 0F, 1F, 0L, newPassengerIds, speedFactor, acceleration, 0F, 0F, 0f, null, null, newMood, 0.1F, 0.05F, true, true);
        vehicleSetup.emergencyId = emergencyId;

        CustomObjectCreator.instance.addVehicle(vehicleSetup);
    }
Beispiel #3
0
    private void grabOrSpawn(int numberOfUnits, EMERGENCY_TYPE type, Vector3 closestToPosition, Vehicle potentialVehicle)
    {
        // TODO - Based on "type"
        string         brand = "Po-liz";
        List <Vehicle> availableEmergencyUnits = Misc.GetVehicles(brand);

        // If position is not on map... pretend it's on of our endpoints
        if (closestToPosition == Misc.VECTOR3_NULL)
        {
            long endPointNode = Misc.pickRandomKey(NodeIndex.endPointDriveWayIndex);
            if (endPointNode != 0L)
            {
                closestToPosition = Game.getCameraPosition(NodeIndex.getPosById(endPointNode));
            }
        }
        else
        {
            // Make a collider, this will grow once emergency vehicles are standing still - when dispatching vehicle sees this, it has arrived
            BoxCollider collider = createCollider(closestToPosition, potentialVehicle);
            registerCollider(emergencyId, collider);
        }

        // Filter the units that are already on the way to other emergencies - and can re-route to given position
        availableEmergencyUnits = availableEmergencyUnits.FindAll(vehicle => !vehicle.areSirensOn() && vehicle.canReroute(closestToPosition));

        // If there are too many, pick out some, either by position, or randomly...
        if (availableEmergencyUnits.Count > numberOfUnits)
        {
            availableEmergencyUnits = pickUnits(numberOfUnits, closestToPosition, availableEmergencyUnits);
        }

        // Dispatch units on map
        dispatchUnits(availableEmergencyUnits, closestToPosition);

        // If there aren't units on the map, spawn "the rest"
        spawnUnits(numberOfUnits - availableEmergencyUnits.Count, type, closestToPosition);

//        Debug.Log(availableEmergencyUnits.Count);
    }