public HPInfo[] GenerateHPInfo()
    {
        if (!Networker.isHost)
        {
            Debug.LogError("Generate HPInfo was ran from a player which isn't the host.");
            return(null);
        }

        return(PlaneEquippableManager.generateHpInfoListFromWeaponManager(weaponManager,
                                                                          PlaneEquippableManager.HPInfoListGenerateNetworkType.receiver).ToArray());
    }
Beispiel #2
0
    public void WeaponSet(Packet packet)
    {
        if (weaponManager == null)
        {
            return;
        }
        //This message has only been sent to us so no need to check UID
        List <HPInfo> hpInfos = PlaneEquippableManager.generateHpInfoListFromWeaponManager(weaponManager,
                                                                                           PlaneEquippableManager.HPInfoListGenerateNetworkType.sender);

        List <int> cm = PlaneEquippableManager.generateCounterMeasuresFromCmManager(cmManager);

        float fuel = PlaneEquippableManager.generateLocalFuelValue();

        NetworkSenderThread.Instance.SendPacketToSpecificPlayer(Networker.hostID,
                                                                new Message_WeaponSet_Result(hpInfos.ToArray(), cm.ToArray(), fuel, networkUID),
                                                                Steamworks.EP2PSend.k_EP2PSendReliable);
    }
    public void WeaponSet_Result(Packet packet)
    {
        Message_WeaponSet_Result message = (Message_WeaponSet_Result)((PacketSingle)packet).message;

        if (message.UID != networkUID)
        {
            return;
        }

        if (Networker.isHost && packet.networkUID != networkUID)
        {
            //Debug.Log("Generating UIDS for any missiles the new vehicle has");
            for (int i = 0; i < message.hpLoadout.Length; i++)
            {
                for (int j = 0; j < message.hpLoadout[i].missileUIDS.Length; j++)
                {
                    if (message.hpLoadout[i].missileUIDS[j] != 0)
                    {
                        //Storing the old one
                        ulong clientsUID = message.hpLoadout[i].missileUIDS[j];
                        //Generating a new global UID for that missile
                        message.hpLoadout[i].missileUIDS[j] = Networker.GenerateNetworkUID();
                        //Sending it back to that client
                        NetworkSenderThread.Instance.SendPacketToSpecificPlayer(PlayerManager.GetPlayerCSteamID(message.UID),
                                                                                new Message_RequestNetworkUID(clientsUID, message.hpLoadout[i].missileUIDS[j]),
                                                                                EP2PSend.k_EP2PSendReliable);
                    }
                }
            }
        }

        PlaneEquippableManager.SetLoadout(gameObject, networkUID, message.normalizedFuel, message.hpLoadout, message.cmLoadout);
        noAmmo = false;
        if (Networker.isHost)
        {
            NetworkSenderThread.Instance.SendPacketAsHostToAllButOneSpecificClient(PlayerManager.GetPlayerCSteamID(message.UID),
                                                                                   message,
                                                                                   Steamworks.EP2PSend.k_EP2PSendReliable);
        }
    }
Beispiel #4
0
    public void Rearm()
    {
        Debug.Log("Rearm!");

        GameObject            vehicle = VTOLAPI.GetPlayersVehicleGameObject();
        WeaponManager         wm      = vehicle.GetComponentInChildren <WeaponManager>();
        CountermeasureManager cm      = vehicle.GetComponentInChildren <CountermeasureManager>();

        Message_WeaponSet_Result rearm = new Message_WeaponSet_Result(
            PlaneEquippableManager.generateHpInfoListFromWeaponManager(wm, PlaneEquippableManager.HPInfoListGenerateNetworkType.generate, PlayerManager.localUID).ToArray(),
            PlaneEquippableManager.generateCounterMeasuresFromCmManager(cm).ToArray(),
            PlaneEquippableManager.generateLocalFuelValue(),
            PlayerManager.localUID);

        if (Networker.isHost)
        {
            NetworkSenderThread.Instance.SendPacketAsHostToAllClients(rearm, Steamworks.EP2PSend.k_EP2PSendReliable);
        }
        else
        {
            NetworkSenderThread.Instance.SendPacketToSpecificPlayer(Networker.hostID, rearm, Steamworks.EP2PSend.k_EP2PSendReliable);
        }
    }
 public int[] GetCMS()
 {
     //There is only ever 2 counter measures, thats why it's hard coded.
     return(PlaneEquippableManager.generateCounterMeasuresFromCmManager(cmManager).ToArray());
 }
 static void Postfix(AIUnitSpawn __instance)
 {
     if (Networker.isHost)
     {
         Debug.Log("Setting up new AI.");
         AIManager.setupAIAircraft(__instance.actor);
         Debug.Log("Telling client about newly spawned AI.");
         Actor actor = __instance.actor;
         if (!actor.isPlayer)
         {
             if (actor.name.Contains("Client"))
             {
                 return;
             }
             bool Aggresion = false;
             if (actor.gameObject.GetComponent <UIDNetworker_Sender>() != null)
             {
                 Debug.Log("Try sending ai " + actor.name + " to client.");
                 HPInfo[]            hPInfos2  = null;
                 int[]               cmLoadout = null;
                 UIDNetworker_Sender uidSender = actor.gameObject.GetComponent <UIDNetworker_Sender>();
                 if (actor.role == Actor.Roles.Air)
                 {
                     WeaponManager wm = actor.gameObject.GetComponent <WeaponManager>();
                     if (wm != null)
                     {
                         hPInfos2 = PlaneEquippableManager.generateHpInfoListFromWeaponManager(actor.weaponManager, PlaneEquippableManager.HPInfoListGenerateNetworkType.sender, uidSender.networkUID).ToArray();
                     }
                 }
                 AIUnitSpawn aIUnitSpawn = actor.gameObject.GetComponent <AIUnitSpawn>();
                 if (aIUnitSpawn == null)
                 {
                     Debug.LogWarning("AI unit spawn is null on ai " + actor.name);
                 }
                 else
                 {
                     Aggresion = aIUnitSpawn.engageEnemies;
                 }
                 bool            canBreak = false;
                 PhoneticLetters letters  = new PhoneticLetters();
                 foreach (var Group in VTScenario.current.groups.GetExistingGroups(actor.team))
                 {
                     foreach (var ID in Group.unitIDs)
                     {
                         if (ID == actor.unitSpawn.unitID)
                         {
                             letters  = Group.groupID;
                             canBreak = true;
                             break;
                         }
                     }
                     if (canBreak)
                     {
                         break;
                     }
                 }
                 List <ulong> ids = new List <ulong>();
                 ulong        lastID;
                 SAMLauncher  launcher = actor.gameObject.GetComponentInChildren <SAMLauncher>();
                 if (launcher != null)
                 {
                     foreach (var radar in launcher.lockingRadars)
                     {
                         if (radar.myActor == null)
                         {
                             Debug.LogError("Locking radar on one of the SAM's is literally null.");
                         }
                         if (VTOLVR_Multiplayer.AIDictionaries.reverseAllActors.TryGetValue(radar.myActor, out lastID))
                         {
                             ids.Add(lastID);
                             // Debug.Log("Aded a radar ID");
                         }
                         else
                         {
                             Debug.LogError("Couldn't get a locking radar on one of the SAM's, probably a dictionary problem.");
                         }
                     }
                 }
                 ulong[] irIDS             = new ulong[0];
                 IRSAMNetworker_Sender irs = actor.gameObject.GetComponentInChildren <IRSAMNetworker_Sender>();
                 if (irs != null)
                 {
                     irIDS = irs.irIDs;
                 }
                 Debug.Log("Finally sending AI " + actor.name + " to client all clients.");
                 if (canBreak)
                 {
                     NetworkSenderThread.Instance.SendPacketAsHostToAllClients(new Message_SpawnAIVehicle(actor.name, AIManager.GetUnitNameFromCatalog(actor.unitSpawn.unitName),
                                                                                                          VTMapManager.WorldToGlobalPoint(actor.gameObject.transform.position),
                                                                                                          new Vector3D(actor.gameObject.transform.rotation.eulerAngles), uidSender.networkUID, hPInfos2, cmLoadout, 0.65f, Aggresion, actor.unitSpawn.unitSpawner.unitInstanceID, letters, ids.ToArray(), irIDS),
                                                                               EP2PSend.k_EP2PSendReliable);
                 }
                 else
                 {
                     // Debug.Log("It seems that " + actor.name + " is not in a unit group, sending anyways.");
                     NetworkSenderThread.Instance.SendPacketAsHostToAllClients(new Message_SpawnAIVehicle(actor.name, AIManager.GetUnitNameFromCatalog(actor.unitSpawn.unitName),
                                                                                                          VTMapManager.WorldToGlobalPoint(actor.gameObject.transform.position),
                                                                                                          new Vector3D(actor.gameObject.transform.rotation.eulerAngles), uidSender.networkUID, hPInfos2, cmLoadout, 0.65f, Aggresion, actor.unitSpawn.unitSpawner.unitInstanceID, ids.ToArray(), irIDS),
                                                                               EP2PSend.k_EP2PSendReliable);
                 }
             }
             else
             {
                 Debug.Log("Could not find the UIDNetworker_Sender");
             }
         }
         AIManager.TellClientAboutAI(new Steamworks.CSteamID(0));
     }
 }
Beispiel #7
0
    /// <summary>
    /// When the user has received a message of spawn player vehicle,
    /// this creates the player vehicle and removes any thing which shouldn't
    /// be on it.
    /// </summary>
    /// <param name="packet">The message</param>
    public static void SpawnPlayerVehicle(Packet packet, CSteamID sender) //Both, but never spawns the local vehicle, only executes spawn vehicle messages from other clients
    {
        // We don't actually need the "sender" id, unless we're a client and want to check that the packet came from the host
        // which we're not doing right now.
        Message_SpawnPlayerVehicle message = (Message_SpawnPlayerVehicle)((PacketSingle)packet).message;

        if (message.networkID == PlayerManager.localUID)
        {
            return;
        }

        Debug.Log($"Recived a Spawn Vehicle Message from: {message.csteamID}");
        CSteamID spawnerSteamId = new CSteamID(message.csteamID);

        if (!gameLoaded)
        {
            Debug.LogWarning("Our game isn't loaded, adding spawn vehicle to queue");
            playersToSpawnQueue.Enqueue(packet);
            playersToSpawnIdQueue.Enqueue(sender);
            return;
        }
        //foreach (ulong id in spawnedVehicles)
        //{
        //    if (id == message.csteamID)
        //    {
        //        Debug.Log("Got a spawnedVehicle message for a vehicle we have already added! Returning....");
        //        return;
        //    }
        //}
        //spawnedVehicles.Add(message.csteamID);
        Debug.Log("Got a new spawnVehicle uID.");
        if (Networker.isHost)
        {
            //Debug.Log("Generating UIDS for any missiles the new vehicle has");
            for (int i = 0; i < message.hpLoadout.Length; i++)
            {
                for (int j = 0; j < message.hpLoadout[i].missileUIDS.Length; j++)
                {
                    if (message.hpLoadout[i].missileUIDS[j] != 0)
                    {
                        //Storing the old one
                        ulong clientsUID = message.hpLoadout[i].missileUIDS[j];
                        //Generating a new global UID for that missile
                        message.hpLoadout[i].missileUIDS[j] = Networker.GenerateNetworkUID();
                        //Sending it back to that client
                        NetworkSenderThread.Instance.SendPacketToSpecificPlayer(spawnerSteamId,
                                                                                new Message_RequestNetworkUID(clientsUID, message.hpLoadout[i].missileUIDS[j]),
                                                                                EP2PSend.k_EP2PSendReliable);
                    }
                }
            }

            Debug.Log("Telling other clients about new player and new player about other clients. Player count = " + players.Count);
            for (int i = 0; i < players.Count; i++)
            {
                if (players[i].cSteamID == SteamUser.GetSteamID())
                {
                    //Debug.LogWarning("Skiping this one as it's the host");
                    //Send the host player to the new player.
                    //Debug.Log($"Running host code to tell new player about host vehicle.");

                    GameObject    localVehicle       = VTOLAPI.GetPlayersVehicleGameObject();
                    WeaponManager localWeaponManager = localVehicle.GetComponent <WeaponManager>();

                    List <HPInfo> hpInfos = PlaneEquippableManager.generateHpInfoListFromWeaponManager(localWeaponManager,
                                                                                                       PlaneEquippableManager.HPInfoListGenerateNetworkType.sender);
                    CountermeasureManager cmManager = localVehicle.GetComponentInChildren <CountermeasureManager>();
                    List <int>            cm        = PlaneEquippableManager.generateCounterMeasuresFromCmManager(cmManager);
                    float fuel = PlaneEquippableManager.generateLocalFuelValue();

                    NetworkSenderThread.Instance.SendPacketToSpecificPlayer(spawnerSteamId,
                                                                            new Message_SpawnPlayerVehicle(
                                                                                players[i].vehicleType,
                                                                                VTMapManager.WorldToGlobalPoint(players[i].vehicle.transform.position),
                                                                                players[i].vehicle.transform.rotation,
                                                                                players[i].cSteamID.m_SteamID,
                                                                                players[i].vehicleUID,
                                                                                hpInfos.ToArray(),
                                                                                cm.ToArray(),
                                                                                fuel, players[i].leftie),
                                                                            EP2PSend.k_EP2PSendReliable);

                    //Debug.Log($"We have told the new player about the host and NOT the other way around.");
                    //Debug.Log($"We don't need to resync the host weapons, that's guaranteed to already be up to date.");
                    continue;
                }

                if (players[i].vehicle != null)
                {
                    PlaneNetworker_Receiver existingPlayersPR = players[i].vehicle.GetComponent <PlaneNetworker_Receiver>();
                    //We first send the new player to an existing spawned in player
                    NetworkSenderThread.Instance.SendPacketToSpecificPlayer(players[i].cSteamID, message, EP2PSend.k_EP2PSendReliable);
                    //Then we send this current player to the new player.
                    NetworkSenderThread.Instance.SendPacketToSpecificPlayer(spawnerSteamId,
                                                                            new Message_SpawnPlayerVehicle(
                                                                                players[i].vehicleType,
                                                                                VTMapManager.WorldToGlobalPoint(players[i].vehicle.transform.position),
                                                                                players[i].vehicle.transform.rotation,
                                                                                players[i].cSteamID.m_SteamID,
                                                                                players[i].vehicleUID,
                                                                                existingPlayersPR.GenerateHPInfo(),
                                                                                existingPlayersPR.GetCMS(),
                                                                                existingPlayersPR.GetFuel(), players[i].leftie),
                                                                            EP2PSend.k_EP2PSendReliable);
                    //Debug.Log($"We have told {players[i].cSteamID.m_SteamID} about the new player ({message.csteamID}) and the other way round.");

                    //We ask the existing player what their load out just incase the host's player receiver was out of sync.
                    NetworkSenderThread.Instance.SendPacketToSpecificPlayer(players[i].cSteamID,
                                                                            new Message(MessageType.WeaponsSet),
                                                                            EP2PSend.k_EP2PSendReliable);
                    //Debug.Log($"We have asked {players[i].cSteamID.m_SteamID} what their current weapons are, and now waiting for a responce."); // marsh typo response lmao
                }
                else
                {
                    Debug.Log("players[" + i + "].vehicle is null");
                }
            }
        }

        if (Networker.isHost)
        {
            Debug.Log("Telling connected client about AI units");
            AIManager.TellClientAboutAI(spawnerSteamId);
        }
        AddToPlayerList(new Player(spawnerSteamId, null, message.vehicle, message.networkID, message.leftie));

        GameObject puppet = SpawnRepresentation(message.networkID, message.position, message.rotation, message.leftie);

        if (puppet != null)
        {
            PlaneEquippableManager.SetLoadout(puppet, message.networkID, message.normalizedFuel, message.hpLoadout, message.cmLoadout);
        }
    }
Beispiel #8
0
    public static void SetupLocalAircraft(GameObject localVehicle, Vector3 pos, Quaternion rot, ulong UID)
    {
        VTOLVehicles currentVehicle = VTOLAPI.GetPlayersVehicleEnum();
        Actor        actor          = localVehicle.GetComponent <Actor>();

        if (VTOLVR_Multiplayer.AIDictionaries.allActors.ContainsKey(UID))
        {
            VTOLVR_Multiplayer.AIDictionaries.allActors[UID] = actor;
        }
        else
        {
            VTOLVR_Multiplayer.AIDictionaries.allActors.Add(UID, actor);
        }
        if (VTOLVR_Multiplayer.AIDictionaries.allActors.ContainsKey(UID))
        {
            VTOLVR_Multiplayer.AIDictionaries.reverseAllActors[actor] = UID;
        }
        else
        {
            VTOLVR_Multiplayer.AIDictionaries.reverseAllActors.Add(actor, UID);
        }

        RigidbodyNetworker_Sender rbSender = localVehicle.AddComponent <RigidbodyNetworker_Sender>();

        rbSender.networkUID = UID;

        //rbSender.SetSpawn(pos, rot);
        if (currentVehicle == VTOLVehicles.AV42C)
        {
            rbSender.originOffset = av42Offset;
        }

        Debug.Log("Adding Plane Sender");
        PlaneNetworker_Sender planeSender = localVehicle.AddComponent <PlaneNetworker_Sender>();

        planeSender.networkUID = UID;

        if (currentVehicle == VTOLVehicles.AV42C || currentVehicle == VTOLVehicles.F45A)
        {
            Debug.Log("Added Tilt Updater to our vehicle");
            EngineTiltNetworker_Sender tiltSender = localVehicle.AddComponent <EngineTiltNetworker_Sender>();
            tiltSender.networkUID = UID;
        }

        if (actor != null)
        {
            if (actor.unitSpawn != null)
            {
                if (actor.unitSpawn.unitSpawner == null)
                {
                    Debug.Log("unit spawner was null, adding one");
                    actor.unitSpawn.unitSpawner = actor.gameObject.AddComponent <UnitSpawner>();
                }
            }
        }

        if (localVehicle.GetComponent <Health>() != null)
        {
            HealthNetworker_Sender healthNetworker = localVehicle.AddComponent <HealthNetworker_Sender>();
            PlayerNetworker_Sender playerNetworker = localVehicle.AddComponent <PlayerNetworker_Sender>();



            healthNetworker.networkUID = UID;
            playerNetworker.networkUID = UID;
            Debug.Log("added health sender to local player");
        }
        else
        {
            Debug.Log("local player has no health?");
        }

        if (localVehicle.GetComponentInChildren <WingFoldController>() != null)
        {
            WingFoldNetworker_Sender wingFold = localVehicle.AddComponent <WingFoldNetworker_Sender>();
            wingFold.wingController = localVehicle.GetComponentInChildren <WingFoldController>().toggler;
            wingFold.networkUID     = UID;
        }

        if (localVehicle.GetComponentInChildren <StrobeLightController>() != null)
        {
            ExtLight_Sender extLight = localVehicle.AddComponent <ExtLight_Sender>();
            extLight.networkUID = UID;
        }

        if (localVehicle.GetComponentInChildren <LockingRadar>() != null)
        {
            Debug.Log($"Adding LockingRadarSender to player {localVehicle.name}");
            LockingRadarNetworker_Sender radarSender = localVehicle.AddComponent <LockingRadarNetworker_Sender>();
            radarSender.networkUID = UID;
        }

        if (currentVehicle == VTOLVehicles.AV42C)
        {
            AvatarManager.SetupAircraftRoundels(localVehicle.transform, currentVehicle, GetPlayerCSteamID(localUID), av42Offset);
        }
        else
        {
            AvatarManager.SetupAircraftRoundels(localVehicle.transform, currentVehicle, GetPlayerCSteamID(localUID), Vector3.zero);
        }

        if (Multiplayer.SoloTesting)
        {
            pos += new Vector3(20, 0, 0);
        }

        List <HPInfo>         hpInfos   = PlaneEquippableManager.generateLocalHpInfoList(UID);
        CountermeasureManager cmManager = localVehicle.GetComponentInChildren <CountermeasureManager>();
        List <int>            cm        = PlaneEquippableManager.generateCounterMeasuresFromCmManager(cmManager);
        float fuel = PlaneEquippableManager.generateLocalFuelValue();

        Debug.Log("Assembled our local vehicle");
        if (!Networker.isHost || Multiplayer.SoloTesting)
        {
            // Not host, so send host the spawn vehicle message
            Debug.Log($"Sending spawn vehicle message to: {Networker.hostID}");
            NetworkSenderThread.Instance.SendPacketToSpecificPlayer(Networker.hostID,
                                                                    new Message_SpawnPlayerVehicle(currentVehicle,
                                                                                                   new Vector3D(pos),
                                                                                                   rot,
                                                                                                   SteamUser.GetSteamID().m_SteamID,
                                                                                                   UID,
                                                                                                   hpInfos.ToArray(),
                                                                                                   cm.ToArray(),
                                                                                                   fuel, PlayerManager.teamLeftie),
                                                                    EP2PSend.k_EP2PSendReliable);
        }
        else
        {
            //Debug.Log("I am host, no need to immediately forward my assembled vehicle");
            NetworkSenderThread.Instance.SendPacketAsHostToAllClients(new Message_SpawnPlayerVehicle(currentVehicle,
                                                                                                     new Vector3D(pos),
                                                                                                     rot,
                                                                                                     SteamUser.GetSteamID().m_SteamID,
                                                                                                     UID,
                                                                                                     hpInfos.ToArray(),
                                                                                                     cm.ToArray(),
                                                                                                     fuel, PlayerManager.teamLeftie),
                                                                      EP2PSend.k_EP2PSendReliable);
        }
    }
Beispiel #9
0
    public static void setupAIAircraft(Actor actor)
    {
        if (actor.role == Actor.Roles.Missile || actor.isPlayer)
        {
            return;
        }
        if (actor.name.Contains("Rearm/Refuel"))
        {
            return;
        }
        foreach (AI ai in AIManager.AIVehicles)
        {
            if (ai.actor == actor)
            {
                return;
            }
        }
        if (actor.parentActor == null)
        {
            AIManager.AIVehicles.Add(new AIManager.AI(actor.gameObject, actor.unitSpawn.unitName, actor, Networker.networkUID + 1));
            foreach (Actor child in actor.gameObject.GetComponentsInChildren <Actor>())
            {
                ulong networkUID = Networker.GenerateNetworkUID();
                Debug.Log("Adding UID senders to " + child.name + $", their uID will be {networkUID}.");
                if (!VTOLVR_Multiplayer.AIDictionaries.allActors.ContainsKey(networkUID))
                {
                    VTOLVR_Multiplayer.AIDictionaries.allActors.Add(networkUID, child);
                }
                if (!VTOLVR_Multiplayer.AIDictionaries.reverseAllActors.ContainsKey(child))
                {
                    VTOLVR_Multiplayer.AIDictionaries.reverseAllActors.Add(child, networkUID);
                }
                UIDNetworker_Sender uidSender = child.gameObject.AddComponent <UIDNetworker_Sender>();
                uidSender.networkUID = networkUID;
                Debug.Log("Added UID sender!");

                Debug.Log("Checking for locking radars");
                foreach (LockingRadar radar in child.GetComponentsInChildren <LockingRadar>())
                {
                    if (radar.GetComponent <Actor>() == child)
                    {
                        Debug.Log($"Adding radar sender to object {child.name} as it is the same game object as this actor.");
                        LockingRadarNetworker_Sender lastLockingSender = child.gameObject.AddComponent <LockingRadarNetworker_Sender>();
                        lastLockingSender.networkUID = networkUID;
                        Debug.Log("Added locking radar!");
                    }
                    else if (radar.GetComponentInParent <Actor>() == child)
                    {
                        Debug.Log($"Adding radar sender to object {child.name} as it is a child of this actor.");
                        LockingRadarNetworker_Sender lastLockingSender = child.gameObject.AddComponent <LockingRadarNetworker_Sender>();
                        lastLockingSender.networkUID = networkUID;
                        Debug.Log("Added locking radar!");
                    }
                    else
                    {
                        Debug.Log("This radar is not direct child of this actor, ignoring");
                    }
                }

                Debug.Log("Checking for health");
                if (child.gameObject.GetComponent <Health>() != null)
                {
                    Debug.Log("adding health sender to ai");
                    HealthNetworker_Sender healthNetworker = child.gameObject.AddComponent <HealthNetworker_Sender>();
                    healthNetworker.networkUID = networkUID;
                    Debug.Log("added health sender to ai!");
                }
                else
                {
                    Debug.Log(child.name + " has no health?");
                }

                Debug.Log("checking for movement type");
                if (child.gameObject.GetComponent <ShipMover>() != null)
                {
                    Debug.Log("I am a ship!");
                    ShipNetworker_Sender shipNetworker = child.gameObject.AddComponent <ShipNetworker_Sender>();
                    shipNetworker.networkUID = networkUID;
                }
                else if (child.gameObject.GetComponent <GroundUnitMover>() != null)
                {
                    Debug.Log("I am a ground mover!");
                    if (child.gameObject.GetComponent <Rigidbody>() != null)
                    {
                        GroundNetworker_Sender lastGroundSender = child.gameObject.AddComponent <GroundNetworker_Sender>();
                        lastGroundSender.networkUID = networkUID;
                    }
                }
                else if (child.gameObject.GetComponent <Rigidbody>() != null)
                {
                    Debug.Log("I am physicsy!");
                    RigidbodyNetworker_Sender lastRigidSender = child.gameObject.AddComponent <RigidbodyNetworker_Sender>();
                    lastRigidSender.networkUID = networkUID;
                    //reduced tick rate for ground Units
                    if (child.role == Actor.Roles.Ground)
                    {
                        lastRigidSender.tickRate = 0.01f;
                    }
                    if (child.role == Actor.Roles.GroundArmor)
                    {
                        lastRigidSender.tickRate = 1.0f;
                    }
                }

                Debug.Log("checking if aircraft");
                if (!child.isPlayer && child.role == Actor.Roles.Air)
                {
                    if (child.weaponManager != null)
                    {
                        PlaneEquippableManager.generateHpInfoListFromWeaponManager(child.weaponManager, PlaneEquippableManager.HPInfoListGenerateNetworkType.generate, uidSender.networkUID);
                    }
                    PlaneNetworker_Sender lastPlaneSender = child.gameObject.AddComponent <PlaneNetworker_Sender>();
                    lastPlaneSender.networkUID = networkUID;
                }

                Debug.Log("checking ext lights");
                if (child.gameObject.GetComponentInChildren <ExteriorLightsController>() != null)
                {
                    //ExtNPCLight_Sender extLight = actor.gameObject.AddComponent<ExtNPCLight_Sender>();
                    //extLight.networkUID = networkUID;
                }

                Debug.Log("checking for guns");
                if (child.gameObject.GetComponentsInChildren <Actor>().Count() <= 1)
                {//only run this code on units without subunits
                    ulong turretCount = 0;
                    foreach (ModuleTurret moduleTurret in child.gameObject.GetComponentsInChildren <ModuleTurret>())
                    {
                        TurretNetworker_Sender tSender = moduleTurret.gameObject.AddComponent <TurretNetworker_Sender>();
                        tSender.networkUID = networkUID;
                        tSender.turretID   = turretCount;
                        Debug.Log("Added turret " + turretCount + " to actor " + networkUID + " uid");
                        turretCount++;
                    }
                    ulong gunCount = 0;
                    foreach (GunTurretAI moduleTurret in child.gameObject.GetComponentsInChildren <GunTurretAI>())
                    {
                        AAANetworker_Sender gSender = moduleTurret.gameObject.AddComponent <AAANetworker_Sender>();
                        gSender.networkUID = networkUID;
                        gSender.gunID      = gunCount;
                        Debug.Log("Added gun " + gunCount + " to actor " + networkUID + " uid");
                        gunCount++;
                    }
                }

                Debug.Log("checking for IRSams");
                IRSamLauncher ml = child.gameObject.GetComponentInChildren <IRSamLauncher>();
                if (ml != null)
                {
                    List <ulong>            samIDS = new List <ulong>();
                    MissileNetworker_Sender lastSender;
                    for (int i = 0; i < ml.ml.missiles.Length; i++)
                    {
                        lastSender            = ml.ml.missiles[i].gameObject.AddComponent <MissileNetworker_Sender>();
                        lastSender.networkUID = Networker.GenerateNetworkUID();
                        samIDS.Add(lastSender.networkUID);
                    }
                    child.gameObject.AddComponent <IRSAMNetworker_Sender>().irIDs = samIDS.ToArray();
                }

                Debug.Log("checking for soldier");
                Soldier soldier = child.gameObject.GetComponentInChildren <Soldier>();
                if (soldier != null)
                {
                    if (soldier.soldierType == Soldier.SoldierTypes.IRMANPAD)
                    {
                        List <ulong>            samIDS = new List <ulong>();
                        MissileNetworker_Sender lastSender;
                        for (int i = 0; i < soldier.irMissileLauncher.missiles.Length; i++)
                        {
                            lastSender            = soldier.irMissileLauncher.missiles[i].gameObject.AddComponent <MissileNetworker_Sender>();
                            lastSender.networkUID = Networker.GenerateNetworkUID();
                            samIDS.Add(lastSender.networkUID);
                        }
                        child.gameObject.AddComponent <IRSAMNetworker_Sender>().irIDs = samIDS.ToArray();
                    }
                }

                Debug.Log("checking for airport");
                AirportManager airport = child.gameObject.GetComponent <AirportManager>();
                if (airport != null)
                {
                    AIManager.SetUpCarrier(child.gameObject, networkUID, child.team);
                }
                //if (!child.unitSpawn.unitSpawner.spawned)
                //{
                //    Debug.Log("Actor " + child.name + " isn't spawned yet, still sending.");
                //}
            }
        }
        else
        {
            Debug.Log(actor.name + " has a parent, not giving an uID sender.");
        }
    }
Beispiel #10
0
    /// <summary>
    /// Tell the connected clients about all the vehicles the host has. This code should never be run on a client.
    /// </summary>
    /// <param name="steamID">Pass 0 to tell it to every client.</param>
    public static void TellClientAboutAI(CSteamID steamID)
    {
        if (!Networker.isHost)
        {
            Debug.LogWarning("The client shouldn't be trying to tell everyone about AI");
            return;
        }
        Debug.Log("Trying sending AI's to client " + steamID);
        foreach (var actor in TargetManager.instance.allActors)
        {
            if (actor == null)
            {
                continue;
            }
            if (actor.parentActor != null)
            {
                continue;
            }
            Debug.Log("Trying sending new stage 1");
            if (!actor.isPlayer)
            {
                if (actor.name.Contains("Client [") == false)
                {
                    Debug.Log("Trying sending new stage 2");
                    bool Aggresion = false;
                    if (actor.gameObject.GetComponent <UIDNetworker_Sender>() != null)
                    {
                        Debug.Log("Try sending ai " + actor.name + " to client.");
                        HPInfo[]            hPInfos2  = null;
                        int[]               cmLoadout = null;
                        UIDNetworker_Sender uidSender = actor.gameObject.GetComponent <UIDNetworker_Sender>();
                        List <ulong>        subUIDs   = new List <ulong>();
                        foreach (UIDNetworker_Sender subActor in actor.gameObject.GetComponentsInChildren <UIDNetworker_Sender>())
                        {
                            subUIDs.Add(subActor.networkUID);
                            Debug.Log("Found ID sender with ID " + subActor.networkUID);
                        }

                        if (actor.role == Actor.Roles.Air)
                        {
                            WeaponManager wm = actor.gameObject.GetComponent <WeaponManager>();
                            if (wm != null)
                            {
                                hPInfos2 = PlaneEquippableManager.generateHpInfoListFromWeaponManager(actor.weaponManager, PlaneEquippableManager.HPInfoListGenerateNetworkType.sender, uidSender.networkUID).ToArray();
                            }
                        }
                        AIUnitSpawn aIUnitSpawn = actor.gameObject.GetComponent <AIUnitSpawn>();
                        if (aIUnitSpawn == null)
                        {
                            Debug.LogWarning("AI unit spawn is null on ai " + actor.name);
                        }
                        else
                        {
                            Aggresion = aIUnitSpawn.engageEnemies;
                        }
                        bool            canBreak = false;
                        PhoneticLetters letters  = new PhoneticLetters();
                        foreach (var Group in VTScenario.current.groups.GetExistingGroups(actor.team))
                        {
                            foreach (var ID in Group.unitIDs)
                            {
                                if (aIUnitSpawn != null)
                                {
                                    if (ID == actor.unitSpawn.unitID)
                                    {
                                        letters  = Group.groupID;
                                        canBreak = true;
                                        break;
                                    }
                                }
                            }
                            if (canBreak)
                            {
                                break;
                            }
                        }

                        Debug.LogWarning("passed group stuff");
                        List <ulong> ids = new List <ulong>();
                        ulong        lastID;
                        SAMLauncher  launcher = actor.gameObject.GetComponentInChildren <SAMLauncher>();
                        if (launcher != null)
                        {
                            foreach (var radar in launcher.lockingRadars)
                            {
                                if (radar.myActor == null)
                                {
                                    Debug.LogError("Locking radar on one of the SAM's is literally null.");
                                }
                                if (VTOLVR_Multiplayer.AIDictionaries.reverseAllActors.TryGetValue(radar.myActor, out lastID))
                                {
                                    ids.Add(lastID);
                                    // Debug.Log("Aded a radar ID");
                                }
                                else
                                {
                                    Debug.LogError("Couldn't get a locking radar on one of the SAM's, probably a dictionary problem.");
                                }
                            }
                        }
                        ulong[] irIDS             = new ulong[0];
                        IRSAMNetworker_Sender irs = actor.gameObject.GetComponentInChildren <IRSAMNetworker_Sender>();
                        if (irs != null)
                        {
                            irIDS = irs.irIDs;
                        }
                        bool redfor = false;

                        if (actor.team == Teams.Enemy)
                        {
                            redfor = true;
                        }
                        if (steamID != new CSteamID(0))
                        {
                            Debug.Log("Finally sending AI " + actor.name + " to client " + steamID);
                            Debug.Log("This unit is made from " + subUIDs.Count + " actors! ");
                            if (canBreak)
                            {
                                NetworkSenderThread.Instance.SendPacketToSpecificPlayer(steamID, new Message_SpawnAIVehicle(actor.name, GetUnitNameFromCatalog(actor.unitSpawn.unitName), redfor,
                                                                                                                            VTMapManager.WorldToGlobalPoint(actor.gameObject.transform.position),
                                                                                                                            actor.gameObject.transform.rotation, uidSender.networkUID, subUIDs.ToArray(), hPInfos2, cmLoadout, 0.65f, Aggresion, actor.unitSpawn.unitSpawner.unitInstanceID, letters, ids.ToArray(), irIDS),
                                                                                        EP2PSend.k_EP2PSendReliableWithBuffering);
                            }
                            else
                            {
                                // Debug.Log("It seems that " + actor.name + " is not in a unit group, sending anyways.");
                                NetworkSenderThread.Instance.SendPacketToSpecificPlayer(steamID, new Message_SpawnAIVehicle(actor.name, GetUnitNameFromCatalog(actor.unitSpawn.unitName), redfor,
                                                                                                                            VTMapManager.WorldToGlobalPoint(actor.gameObject.transform.position),
                                                                                                                            actor.gameObject.transform.rotation, uidSender.networkUID, subUIDs.ToArray(), hPInfos2, cmLoadout, 0.65f, Aggresion, actor.unitSpawn.unitSpawner.unitInstanceID, ids.ToArray(), irIDS),
                                                                                        EP2PSend.k_EP2PSendReliableWithBuffering);
                            }
                        }
                        else
                        {
                            Debug.Log("Finally sending AI " + actor.name + " to client all clients.");
                            Debug.Log("This unit is made from " + subUIDs.Count + " actors! ");
                            if (canBreak)
                            {
                                Networker.addToReliableSendBuffer(new Message_SpawnAIVehicle(actor.name, GetUnitNameFromCatalog(actor.unitSpawn.unitName), redfor,
                                                                                             VTMapManager.WorldToGlobalPoint(actor.gameObject.transform.position),
                                                                                             actor.gameObject.transform.rotation, uidSender.networkUID, subUIDs.ToArray(), hPInfos2, cmLoadout, 0.65f, Aggresion, actor.unitSpawn.unitSpawner.unitInstanceID, letters, ids.ToArray(), irIDS));
                            }
                            else
                            {
                                // Debug.Log("It seems that " + actor.name + " is not in a unit group, sending anyways.");
                                Networker.addToReliableSendBuffer(new Message_SpawnAIVehicle(actor.name, GetUnitNameFromCatalog(actor.unitSpawn.unitName), redfor,
                                                                                             VTMapManager.WorldToGlobalPoint(actor.gameObject.transform.position),
                                                                                             actor.gameObject.transform.rotation, uidSender.networkUID, subUIDs.ToArray(), hPInfos2, cmLoadout, 0.65f, Aggresion, actor.unitSpawn.unitSpawner.unitInstanceID, ids.ToArray(), irIDS));
                            }
                        }
                    }
                    else
                    {
                        Debug.Log("Could not find the UIDNetworker_Sender");
                    }
                }
            }
        }
    }
Beispiel #11
0
    /// <summary>
    /// This is used by the client and only the client to spawn ai vehicles.
    /// </summary>
    public static void SpawnAIVehicle(Packet packet) // This should never run on the host
    {
        if (Networker.isHost)
        {
            Debug.LogWarning("Host shouldn't be trying to spawn an ai vehicle.");
            return;
        }
        Message_SpawnAIVehicle message = (Message_SpawnAIVehicle)((PacketSingle)packet).message;

        if (!PlayerManager.gameLoaded)
        {
            Debug.LogWarning("Our game isn't loaded, adding spawn vehicle to queue");
            AIsToSpawnQueue.Enqueue(packet);
            return;
        }
        foreach (ulong id in spawnedAI)
        {
            if (id == message.rootActorNetworkID)
            {
                Debug.Log("Got a spawnAI message for a vehicle we have already added! Name == " + message.unitName + " Returning...");
                return;
            }
        }

        spawnedAI.Add(message.rootActorNetworkID);
        //Debug.Log("Got a new aiSpawn uID.");
        if (message.unitName == "Player")
        {
            Debug.LogWarning("Player shouldn't be sent to someones client....");
            return;
        }
        Debug.Log("Trying to spawn AI " + message.aiVehicleName);

        GameObject prefab = UnitCatalogue.GetUnitPrefab(message.unitName);

        if (prefab == null)
        {
            Debug.LogError(message.unitName + " was not found.");
            return;
        }
        GameObject newAI = GameObject.Instantiate(prefab, VTMapManager.GlobalToWorldPoint(message.position), message.rotation);

        //Debug.Log("Setting vehicle name");
        newAI.name = message.aiVehicleName;
        Actor actor = newAI.GetComponent <Actor>();

        if (actor == null)
        {
            Debug.LogError("actor is null on object " + newAI.name);
        }

        if (message.redfor)
        {
            actor.team = Teams.Enemy;
        }
        else
        {
            actor.team = Teams.Allied;
        }

        AirportManager airport = newAI.GetComponent <AirportManager>();

        UnitSpawn unitSP = newAI.GetComponent <UnitSpawn>();

        GameObject.Destroy(unitSP);
        if (airport != null)
        {
            newAI.AddComponent <UnitSpawn>();
        }
        else
        {
            newAI.AddComponent <AICarrierSpawn>();
        }

        unitSP = newAI.GetComponent <UnitSpawn>();

        UnitSpawner UnitSpawner = new UnitSpawner();

        actor.unitSpawn             = unitSP;
        actor.unitSpawn.unitSpawner = UnitSpawner;
        unitSP.actor = actor;
        Traverse.Create(actor.unitSpawn.unitSpawner).Field("_spawnedUnit").SetValue(unitSP);
        Traverse.Create(actor.unitSpawn.unitSpawner).Field("_spawned").SetValue(true);
        Traverse.Create(actor.unitSpawn.unitSpawner).Field("_unitInstanceID").SetValue(message.unitInstanceID); // To make objectives work.
        UnitSpawner.team     = actor.team;
        UnitSpawner.unitName = actor.unitSpawn.unitName;

        if (!PlayerManager.teamLeftie)
        {
            UnitSpawner.team = actor.team;
        }
        else
        {
            if (actor.team == Teams.Enemy)
            {
                foreach (Actor subActor in newAI.GetComponentsInChildren <Actor>())
                {
                    subActor.team = Teams.Allied;
                    TargetManager.instance.UnregisterActor(subActor);
                    TargetManager.instance.RegisterActor(subActor);
                }
            }
            else
            if (actor.team == Teams.Allied)
            {
                foreach (Actor subActor in newAI.GetComponentsInChildren <Actor>())
                {
                    subActor.team = Teams.Enemy;
                    TargetManager.instance.UnregisterActor(subActor);
                    TargetManager.instance.RegisterActor(subActor);
                }
            }
            UnitSpawner.team = actor.team;


            if (airport != null)
            {
                airport.team = actor.team;
                SetUpCarrier(newAI, message.rootActorNetworkID, actor.team);
            }
        }

        TargetManager.instance.UnregisterActor(actor);
        TargetManager.instance.RegisterActor(actor);
        VTScenario.current.units.AddSpawner(actor.unitSpawn.unitSpawner);

        if (message.hasGroup)
        {
            VTScenario.current.groups.AddUnitToGroup(UnitSpawner, message.unitGroup);
        }
        Debug.Log(actor.name + $" has had its unitInstanceID set at value {actor.unitSpawn.unitSpawner.unitInstanceID}.");
        VTScenario.current.units.AddSpawner(actor.unitSpawn.unitSpawner);
        Debug.Log($"Spawned new vehicle at {newAI.transform.position}");

        newAI.AddComponent <FloatingOriginTransform>();

        newAI.transform.position = VTMapManager.GlobalToWorldPoint(message.position);
        newAI.transform.rotation = message.rotation;

        Debug.Log("This unit should have " + message.networkIDs.Length + " actors! ");

        int currentSubActorID = 0;

        foreach (Actor child in newAI.GetComponentsInChildren <Actor>())
        {
            Debug.Log("setting up actor: " + currentSubActorID);
            UIDNetworker_Receiver uidReciever = child.gameObject.AddComponent <UIDNetworker_Receiver>();
            uidReciever.networkUID = message.networkIDs[currentSubActorID];

            if (child.gameObject.GetComponent <Health>() != null)
            {
                HealthNetworker_Receiver healthNetworker = child.gameObject.AddComponent <HealthNetworker_Receiver>();
                healthNetworker.networkUID = message.networkIDs[currentSubActorID];
                //HealthNetworker_Sender healthNetworkerS = newAI.AddComponent<HealthNetworker_Sender>();
                //healthNetworkerS.networkUID = message.networkID;
                // Debug.Log("added health Sender to ai");
                // Debug.Log("added health reciever to ai");
            }
            else
            {
                Debug.Log(message.aiVehicleName + " has no health?");
            }

            if (child.gameObject.GetComponent <ShipMover>() != null)
            {
                ShipNetworker_Receiver shipNetworker = child.gameObject.AddComponent <ShipNetworker_Receiver>();
                shipNetworker.networkUID = message.networkIDs[currentSubActorID];
            }
            else if (child.gameObject.GetComponent <GroundUnitMover>() != null)
            {
                if (child.gameObject.GetComponent <Rigidbody>() != null)
                {
                    GroundNetworker_Receiver groundNetworker = child.gameObject.AddComponent <GroundNetworker_Receiver>();
                    groundNetworker.networkUID = message.networkIDs[currentSubActorID];
                }
            }
            else if (child.gameObject.GetComponent <Rigidbody>() != null)
            {
                Rigidbody rb = child.gameObject.GetComponent <Rigidbody>();
                RigidbodyNetworker_Receiver rbNetworker = child.gameObject.AddComponent <RigidbodyNetworker_Receiver>();
                rbNetworker.networkUID = message.networkIDs[currentSubActorID];
            }
            if (child.role == Actor.Roles.Air)
            {
                PlaneNetworker_Receiver planeReceiver = child.gameObject.AddComponent <PlaneNetworker_Receiver>();
                planeReceiver.networkUID = message.networkIDs[currentSubActorID];
                AIPilot aIPilot = child.gameObject.GetComponent <AIPilot>();
                aIPilot.enabled = false;
                aIPilot.kPlane.SetToKinematic();
                aIPilot.kPlane.enabled = false;
                aIPilot.commandState   = AIPilot.CommandStates.Navigation;
                aIPilot.kPlane.enabled = true;
                aIPilot.kPlane.SetVelocity(Vector3.zero);
                aIPilot.kPlane.SetToDynamic();

                RotationToggle wingRotator = aIPilot.wingRotator;
                if (wingRotator != null)
                {
                    WingFoldNetworker_Receiver wingFoldReceiver = child.gameObject.AddComponent <WingFoldNetworker_Receiver>();
                    wingFoldReceiver.networkUID     = message.networkIDs[currentSubActorID];
                    wingFoldReceiver.wingController = wingRotator;
                }
                if (aIPilot.isVtol)
                {
                    //Debug.Log("Adding Tilt Controller to this vehicle " + message.networkID);
                    EngineTiltNetworker_Receiver tiltReceiver = child.gameObject.AddComponent <EngineTiltNetworker_Receiver>();
                    tiltReceiver.networkUID = message.networkIDs[currentSubActorID];
                }

                if (child.gameObject.GetComponentInChildren <ExteriorLightsController>() != null)
                {
                    ExtLight_Receiver extLight = child.gameObject.AddComponent <ExtLight_Receiver>();
                    extLight.networkUID = message.networkIDs[currentSubActorID];
                }

                Rigidbody rb = child.gameObject.GetComponent <Rigidbody>();

                foreach (Collider collider in child.gameObject.GetComponentsInChildren <Collider>())
                {
                    if (collider)
                    {
                        collider.gameObject.layer = 9;
                    }
                }

                Debug.Log("Doing weapon manager shit on " + child.gameObject.name + ".");
                WeaponManager weaponManager = child.gameObject.GetComponent <WeaponManager>();
                if (weaponManager == null)
                {
                    Debug.LogError(child.gameObject.name + " does not seem to have a weapon maanger on it.");
                }
                else
                {
                    PlaneEquippableManager.SetLoadout(child.gameObject, message.networkIDs[currentSubActorID], message.normalizedFuel, message.hpLoadout, message.cmLoadout);
                }
            }

            AIUnitSpawn aIUnitSpawn = child.gameObject.GetComponent <AIUnitSpawn>();
            if (aIUnitSpawn == null)
            {
                Debug.LogWarning("AI unit spawn is null on respawned unit " + aIUnitSpawn);
            }
            // else
            // newAI.GetComponent<AIUnitSpawn>().SetEngageEnemies(message.Aggresive);
            VehicleMover vehicleMover = child.gameObject.GetComponent <VehicleMover>();
            if (vehicleMover != null)
            {
                vehicleMover.enabled  = false;
                vehicleMover.behavior = GroundUnitMover.Behaviors.Parked;
            }
            else
            {
                GroundUnitMover ground = child.gameObject.GetComponent <GroundUnitMover>();
                if (ground != null)
                {
                    ground.enabled  = false;
                    ground.behavior = GroundUnitMover.Behaviors.Parked;
                }
            }

            Debug.Log("Checking for gun turrets on child " + child.name);
            if (child.gameObject.GetComponentsInChildren <Actor>().Length <= 1)
            {//only run this code on units without subunits
                Debug.Log("This is a child, with " + child.gameObject.GetComponentsInChildren <Actor>().Length + " actors, so it could have guns!");
                ulong turretCount = 0;
                foreach (ModuleTurret moduleTurret in child.gameObject.GetComponentsInChildren <ModuleTurret>())
                {
                    TurretNetworker_Receiver tRec = child.gameObject.AddComponent <TurretNetworker_Receiver>();
                    tRec.networkUID = message.networkIDs[currentSubActorID];
                    tRec.turretID   = turretCount;
                    Debug.Log("Added turret " + turretCount + " to actor " + message.networkIDs[currentSubActorID] + " uid");
                    turretCount++;
                }
                ulong gunCount = 0;
                foreach (GunTurretAI turretAI in child.gameObject.GetComponentsInChildren <GunTurretAI>())
                {
                    turretAI.SetEngageEnemies(false);
                    AAANetworker_Reciever aaaRec = child.gameObject.AddComponent <AAANetworker_Reciever>();
                    aaaRec.networkUID = message.networkIDs[currentSubActorID];
                    aaaRec.gunID      = gunCount;
                    Debug.Log("Added gun " + gunCount + " to actor " + message.networkIDs[currentSubActorID] + " uid");
                    gunCount++;
                }
            }
            else
            {
                Debug.Log("This isnt a child leaf thing, it has " + child.gameObject.GetComponentsInChildren <Actor>().Length + " actors");
            }
            IRSamLauncher iLauncher = child.gameObject.GetComponent <IRSamLauncher>();
            if (iLauncher != null)
            {
                //iLauncher.ml.RemoveAllMissiles();
                iLauncher.ml.LoadAllMissiles();
                iLauncher.SetEngageEnemies(false);
                MissileNetworker_Receiver mlr;
                //iLauncher.ml.LoadCount(message.IRSamMissiles.Length);
                Debug.Log($"Adding IR id's on IR SAM, len = {message.IRSamMissiles.Length}.");
                for (int i = 0; i < message.IRSamMissiles.Length; i++)
                {
                    mlr            = iLauncher.ml.missiles[i]?.gameObject.AddComponent <MissileNetworker_Receiver>();
                    mlr.thisML     = iLauncher.ml;
                    mlr.networkUID = message.IRSamMissiles[i];
                }
                Debug.Log("Added IR id's.");
            }
            Soldier soldier = child.gameObject.GetComponent <Soldier>();
            if (soldier != null)
            {
                soldier.SetEngageEnemies(false);
                if (soldier.soldierType == Soldier.SoldierTypes.IRMANPAD)
                {
                    soldier.SetEngageEnemies(false);
                    IRMissileLauncher ir = soldier.irMissileLauncher;
                    if (ir != null)
                    {
                        //ir.RemoveAllMissiles();
                        ir.LoadAllMissiles();
                        MissileNetworker_Receiver mlr;
                        //ir.LoadCount(message.IRSamMissiles.Length);
                        Debug.Log($"Adding IR id's on manpads, len = {message.IRSamMissiles.Length}.");
                        for (int i = 0; i < message.IRSamMissiles.Length; i++)
                        {
                            mlr            = ir.missiles[i]?.gameObject.AddComponent <MissileNetworker_Receiver>();
                            mlr.thisML     = ir;
                            mlr.networkUID = message.IRSamMissiles[i];
                        }
                        Debug.Log("Added IR id's on manpads.");
                    }
                    else
                    {
                        Debug.Log($"Manpad {message.networkIDs} forgot its rocket launcher pepega.");
                    }
                }
            }

            Debug.Log("Checking for SAM launchers");
            SAMLauncher launcher = child.gameObject.GetComponent <SAMLauncher>();
            if (launcher != null)
            {
                Debug.Log("I found a sam launcher!");
                SamNetworker_Reciever samNetworker = launcher.gameObject.AddComponent <SamNetworker_Reciever>();
                samNetworker.networkUID = message.networkIDs[currentSubActorID];
                samNetworker.radarUIDS  = message.radarIDs;
                //Debug.Log($"Added samNetworker to uID {message.networkID}.");
                launcher.SetEngageEnemies(false);
                launcher.fireInterval  = float.MaxValue;
                launcher.lockingRadars = null;
            }

            /*IRSamLauncher ml = actor.gameObject.GetComponentInChildren<IRSamLauncher>();
             * if (ml != null)
             * {
             *  ml.SetEngageEnemies(false);
             *  MissileNetworker_Receiver lastRec;
             *  for (int i = 0; i < ml.ml.missiles.Length; i++)
             *  {
             *      lastRec = ml.ml.missiles[i].gameObject.AddComponent<MissileNetworker_Receiver>();
             *      lastRec.networkUID = message.IRSamMissiles[i];
             *      lastRec.thisML = ml.ml;
             *  }
             * }*/
            //this code for ir missiles was here twice, so i dissable the seccond copy

            Debug.Log("Checking for locking radars");
            foreach (LockingRadar radar in child.GetComponentsInChildren <LockingRadar>())
            {
                if (radar.GetComponent <Actor>() == child)
                {
                    Debug.Log($"Adding radar receiver to object {child.name} as it is the same game object as this actor.");
                    LockingRadarNetworker_Receiver lastLockingReceiver = child.gameObject.AddComponent <LockingRadarNetworker_Receiver>();
                    lastLockingReceiver.networkUID = message.networkIDs[currentSubActorID];
                    Debug.Log("Added locking radar!");
                }
                else if (radar.GetComponentInParent <Actor>() == child)
                {
                    Debug.Log($"Adding radar receiver to object {child.name} as it is a child of this actor.");
                    LockingRadarNetworker_Receiver lastLockingReceiver = child.gameObject.AddComponent <LockingRadarNetworker_Receiver>();
                    lastLockingReceiver.networkUID = message.networkIDs[currentSubActorID];
                    Debug.Log("Added locking radar!");
                }
                else
                {
                    Debug.Log("This radar is not direct child of this actor, ignoring");
                }
            }
            AIVehicles.Add(new AI(child.gameObject, message.aiVehicleName, child, message.networkIDs[currentSubActorID]));
            Debug.Log("Spawned in AI " + child.gameObject.name);

            if (!VTOLVR_Multiplayer.AIDictionaries.allActors.ContainsKey(message.networkIDs[currentSubActorID]))
            {
                VTOLVR_Multiplayer.AIDictionaries.allActors.Add(message.networkIDs[currentSubActorID], child);
            }
            if (!VTOLVR_Multiplayer.AIDictionaries.reverseAllActors.ContainsKey(actor))
            {
                VTOLVR_Multiplayer.AIDictionaries.reverseAllActors.Add(child, message.networkIDs[currentSubActorID]);
            }

            currentSubActorID++;
        }
    }