Пример #1
0
    private bool spawnNearDefaultLocation()
    {
        bool result = false;
        SpawnPointSelector spawnPointSelector = Object.FindObjectOfType <DefaultSpawnPointSelector>();

        if (spawnPointSelector != null)
        {
            result = true;
            setPositionToSpawnPoint(spawnPointSelector);
        }
        return(result);
    }
Пример #2
0
    private bool spawnNearTransition(ZoneDefinition previousZone)
    {
        bool       result     = false;
        GameObject gameObject = null;

        ZoneTransition[] array = Object.FindObjectsOfType <ZoneTransition>();
        foreach (ZoneTransition zoneTransition in array)
        {
            if (zoneTransition.Zone == null)
            {
                Log.LogErrorFormatted(this, "Invalid zone transition found while attempting to spawn player. No zone definition assigned to transition '{0}'", zoneTransition.GetPath());
            }
            else if (zoneTransition.Zone.ZoneName == previousZone.ZoneName)
            {
                gameObject = zoneTransition.gameObject;
                break;
            }
        }
        if (gameObject != null)
        {
            SpawnPointSelector component = gameObject.GetComponent <SpawnPointSelector>();
            if (component != null)
            {
                result = true;
                setPositionToSpawnPoint(component);
            }
            else
            {
                result = false;
            }
        }
        else
        {
            MapTransition mapTransition = Object.FindObjectOfType <MapTransition>();
            if (mapTransition != null)
            {
                SpawnPointSelector component = mapTransition.GetComponent <SpawnPointSelector>();
                if (component != null)
                {
                    result = true;
                    setPositionToSpawnPoint(component);
                }
            }
        }
        return(result);
    }
Пример #3
0
    private IEnumerator setPositionToSpawnPointWaitAFrame(SpawnPointSelector spawner)
    {
        base.transform.position = spawner.SelectSpawnPosition(CoordinateSpace.World);
        base.transform.rotation = spawner.SelectSpawnRotation(CoordinateSpace.World);
        yield return(null);

        LocomotionTracker tracker = ClubPenguin.SceneRefs.ZoneLocalPlayerManager.LocalPlayerGameObject.GetComponent <LocomotionTracker>();

        if (tracker != null)
        {
            tracker.SetCurrentController <RunController>();
        }
        base.transform.position = spawner.SelectSpawnPosition(CoordinateSpace.World);
        base.transform.rotation = spawner.SelectSpawnRotation(CoordinateSpace.World);
        yield return(null);

        LocomotionActionEvent movement = default(LocomotionActionEvent);

        movement.Type      = LocomotionAction.Move;
        movement.Position  = base.transform.position;
        movement.Direction = Vector3.zero;
        sendNetworkMessage(movement);
    }
Пример #4
0
        public DCSMissionUnitGroup AddUnitGroup(
            DCSMission mission, string[] units, Side side,
            Coordinates coordinates, string groupLua, string unitLua,
            DCSSkillLevel skill, DCSMissionUnitGroupFlags flags = 0, UnitTaskPayload payload = UnitTaskPayload.Default,
            Coordinates?coordinates2 = null, int airbaseID = 0, bool requiresParkingSpots = false, bool requiresOpenAirParking = false, Country?country = null, PlayerStartLocation startLocation = PlayerStartLocation.Runway)
        {
            if (units.Length == 0)
            {
                return(null);                   // No units database entries ID provided, cancel group creation
            }
            // TODO: check for missing units
            DBEntryUnit[] unitsBP = (from string u in units where Database.Instance.EntryExists <DBEntryUnit>(u) select Database.Instance.GetEntry <DBEntryUnit>(u)).ToArray();
            unitsBP = (from DBEntryUnit u in unitsBP where u != null select u).ToArray();
            if (unitsBP.Length == 0)
            {
                return(null);                                                                             // All database entries were null, cancel group creation
            }
            Coalition coalition = (side == Side.Ally) ? mission.CoalitionPlayer : mission.CoalitionEnemy; // Pick group coalition

            if (!country.HasValue)
            {
                country = coalition == Coalition.Blue? Country.CJTFBlue : Country.CJTFRed;
            }

            double groupHeading = unitsBP[0].IsAircraft ? 0 : Toolbox.RandomDouble(Toolbox.TWO_PI); // Generate global group heading

            // Generate units in the group
            int         unitIndex = 0;
            Coordinates?lastSpot  = null;
            List <DCSMissionUnitGroupUnit> groupUnits = new List <DCSMissionUnitGroupUnit>();

            foreach (DBEntryUnit unitBP in unitsBP)
            {
                if (unitBP == null)
                {
                    continue;
                }

                for (int i = 0; i < unitBP.DCSIDs.Length; i++)
                {
                    // Set unit coordinates and heading
                    Coordinates unitCoordinates = coordinates;
                    double      unitHeading     = groupHeading;

                    SetUnitCoordinatesAndHeading(ref unitCoordinates, ref unitHeading, unitBP, unitIndex);

                    // Get parking spot for the unit, if unit is parked at an airdrome
                    int parkingSpot = 0;
                    if (airbaseID > 0)
                    {
                        if (requiresParkingSpots)
                        {
                            parkingSpot = SpawnPointSelector.GetFreeParkingSpot(airbaseID, lastSpot, out Coordinates parkingCoordinates, requiresOpenAirParking);
                            if (parkingSpot >= 0)
                            {
                                unitCoordinates = parkingCoordinates;
                            }
                            else
                            {
                                parkingSpot = 0;
                            }
                            lastSpot = unitCoordinates;
                        }
                    }
                    else if (airbaseID == -99)  //carrier code always parks 1 maybe will need more
                    {
                        parkingSpot = 1;
                    }
                    // Add unit to the list of units
                    DCSMissionUnitGroupUnit unit = new DCSMissionUnitGroupUnit
                    {
                        Coordinates = unitCoordinates,
                        Heading     = unitHeading,
                        ID          = NextUnitID,
                        Type        = unitBP.DCSIDs[i],
                        ParkingSpot = parkingSpot,
                        Name        = unitBP.ID
                    };
                    groupUnits.Add(unit);
                    unitIndex++; NextUnitID++;
                }
            }

            // Generate group name
            string       groupName;
            UnitCallsign callsign = new UnitCallsign();

            if (unitsBP[0].IsAircraft) // Aircraft group, name is a callsign
            {
                callsign  = CallsignGenerator.GetCallsign(unitsBP[0].Families[0], coalition);
                groupName = callsign.GroupName;
            }
            else // Vehicle/ship/static group, name is a random group name
            {
                groupName = GetGroupName(unitsBP[0].Families[0]);
            }

            // Add group to the mission
            DCSMissionUnitGroup group = new DCSMissionUnitGroup
            {
                AirbaseID     = airbaseID,
                CallsignLua   = callsign.Lua,
                Category      = unitsBP[0].Category,
                Coalition     = coalition,
                Country       = country.Value,
                Coordinates   = airbaseID != 0?  groupUnits[0].Coordinates : coordinates,
                Coordinates2  = coordinates2 ?? coordinates + Coordinates.CreateRandom(1, 2) * Toolbox.NM_TO_METERS,
                Flags         = flags,
                GroupID       = NextGroupID,
                LuaGroup      = groupLua,
                Name          = groupName,
                Skill         = skill,
                Payload       = payload,
                UnitID        = units[0],
                LuaUnit       = unitLua,
                Units         = groupUnits.ToArray(),
                StartLocation = startLocation
            };

            mission.UnitGroups.Add(group);

            NextGroupID++;

            DebugLog.Instance.WriteLine($"Added \"{group.Units[0].Type}\" unit group \"{group.Name}\" for coalition {group.Coalition.ToString().ToUpperInvariant()}", 2);

            return(group);
        }
Пример #5
0
 private void setPositionToSpawnPoint(SpawnPointSelector spawner)
 {
     StartCoroutine(setPositionToSpawnPointWaitAFrame(spawner));
 }