Example #1
0
    public void GroundUpdate(Packet packet)
    {
        lastMessage = (Message_ShipUpdate)((PacketSingle)packet).message;
        if (lastMessage.UID != networkUID)
        {
            return;
        }

        targetPositionGlobal = lastMessage.position + lastMessage.velocity.toVector3 * Networker.pingToHost;
        targetVelocity       = lastMessage.velocity.toVector3;
        //targetRotation = lastMessage.rotation;
        //targetRotation = targetRotation.normalized;
        //could not get the rotation to work for whatever reason, so ground moves face their velocity vector

        //Debug.Log("Ground reciever rotation is: " + lastMessage.rotation.ToString());

        if ((VTMapManager.GlobalToWorldPoint(lastMessage.position) - groundUnitMover.transform.position).magnitude > 100)
        {
            Debug.Log("Ground mover is too far, teleporting.");
            groundUnitMover.transform.position = VTMapManager.GlobalToWorldPoint(lastMessage.position);
            Quaternion qs = lastMessage.rotation;
            qs = qs.normalized;
            groundUnitMover.transform.rotation = qs;
            smoothedPosition = lastMessage.position;
            if (targetVelocity.sqrMagnitude > 1)
            {
                smoothedRotation = Quaternion.LookRotation(targetVelocity);
            }
            //smoothedRotation = lastMessage.rotation;
            //smoothedRotation = smoothedRotation.normalized;
        }
    }
Example #2
0
    public void RigidbodyUpdate(Packet packet)
    {
        Message_RigidbodyUpdate rigidbodyUpdate = (Message_RigidbodyUpdate)((PacketSingle)packet).message;

        //Debug.Log($"Rigidbody Update\nOur Network ID = {networkUID} Packet Network ID = {rigidbodyUpdate.networkUID}");
        if (rigidbodyUpdate.networkUID != networkUID)
        {
            return;
        }

        if (rigidbodyUpdate.sequenceNumber <= mostCurrentUpdateNumber)
        {
            return;
        }
        mostCurrentUpdateNumber = rigidbodyUpdate.sequenceNumber;

        globalTargetPosition   = rigidbodyUpdate.position + rigidbodyUpdate.velocity * latency;
        localTargetPosition    = VTMapManager.GlobalToWorldPoint(globalTargetPosition);
        targetVelocity         = rigidbodyUpdate.velocity.toVector3;
        targetRotation         = rigidbodyUpdate.rotation * Quaternion.Euler(rigidbodyUpdate.angularVelocity.toVector3 * latency);
        targetRotationVelocity = rigidbodyUpdate.angularVelocity.toVector3;

        if (Vector3.Distance(transform.position, localTargetPosition) > positionThreshold)
        {
            //Debug.Log("Outside of thresh hold, moving " + gameObject.name);
            transform.position = localTargetPosition;

            transform.rotation = rigidbodyUpdate.rotation;
        }
    }
    public void BulletHit(Packet packet)
    {
        bulletMessage = (Message_BulletHit)((PacketSingle)packet).message;

        Debug.Log("handling bullet hit");

        if (bulletMessage.destUID != networkUID)
        {
            return;
        }


        RaycastHit hitInfo;
        Vector3    pos = VTMapManager.GlobalToWorldPoint(bulletMessage.pos);
        Vector3    vel = bulletMessage.dir.toVector3;
        Vector3    a   = pos;

        a += vel * 100.0f;

        bool   flag   = Physics.Linecast(pos, a, out hitInfo, 1025);
        Hitbox hitbox = null;

        if (flag)
        {
            hitbox = hitInfo.collider.GetComponent <Hitbox>();
            if ((bool)hitbox && (bool)hitbox.actor)
            {
                Debug.Log("found  target bullet hit");
                hitbox.Damage(bulletMessage.damage, hitInfo.point, Health.DamageTypes.Impact, hitbox.actor, "lol");
                BulletHitManager.instance.CreateBulletHit(hitInfo.point, -vel, true);
            }
        }
    }
    public void RigidbodyUpdate(Packet packet)
    {
        Message_RigidbodyUpdate rigidbodyUpdate = (Message_RigidbodyUpdate)((PacketSingle)packet).message;

        //Debug.Log($"Rigidbody Update\nOur Network ID = {networkUID} Packet Network ID = {rigidbodyUpdate.networkUID}");
        if (rigidbodyUpdate.networkUID != networkUID)
        {
            return;
        }
        targetPosition     = VTMapManager.GlobalToWorldPoint(rigidbodyUpdate.position);
        rb.velocity        = rigidbodyUpdate.velocity.toVector3;
        rb.angularVelocity = rigidbodyUpdate.angularVelocity.toVector3;
        transform.rotation = Quaternion.Euler(rigidbodyUpdate.rotation.toVector3); //Angular Velocity doesn't seem to be working so I'm just setting the rotation.

        if (Vector3.Distance(transform.position, targetPosition) > positionThreshhold)
        {
            Debug.Log("Outside of thresh hold, moving " + gameObject.name);
            transform.position = targetPosition;
        }
        else
        {
            //Debug.Log($"Updating Position of UID {networkUID} to {transform.position} : {rb.velocity}" +
            //   $"\nNetwork Message was {rigidbodyUpdate.position} : {rigidbodyUpdate.velocity}");
        }
    }
    public void BulletHit(Packet packet)
    {
        bulletMessage = (Message_BulletHit)((PacketSingle)packet).message;

        Debug.Log("handling bullet hit");

        if (bulletMessage.destUID != networkUID)
        {
            return;
        }
        Vector3 pos = VTMapManager.GlobalToWorldPoint(bulletMessage.pos);
        Vector3 vel = bulletMessage.dir.toVector3;

        RaycastHit[] hits;
        hits = Physics.RaycastAll(pos, vel, 100.0f, 1025);
        Hitbox hitbox = null;

        for (int i = 0; i < hits.Length; i++)
        {
            RaycastHit hit = hits[i];
            hitbox = hit.collider.GetComponent <Hitbox>();
            if ((bool)hitbox && (bool)hitbox.actor)
            {
                Debug.Log("found  target bullet hit");
                hitbox.Damage(bulletMessage.damage, hit.point, Health.DamageTypes.Impact, hitbox.actor, "Bullet Hit Network");
                BulletHitManager.instance.CreateBulletHit(hit.point, -vel, true);
            }
        }
    }
 void FixedUpdate()
 {
     targetPositionGlobal += targetVelocity * Time.fixedDeltaTime;
     targetPosition        = VTMapManager.GlobalToWorldPoint(new Vector3D(targetPositionGlobal));
     ship.rb.MovePosition(ship.transform.position + targetVelocity * Time.fixedDeltaTime + ((targetPosition - ship.transform.position) * Time.fixedDeltaTime) / smoothTime);
     ship.rb.velocity = targetVelocity + (targetPosition - ship.transform.position) / smoothTime;
     ship.rb.MoveRotation(Quaternion.Lerp(ship.transform.rotation, targetRotation, Time.fixedDeltaTime / rotSmoothTime));
 }
 public static Vector3 GetTargetPos()
 {
     if (targetActor != null)
     {
         return(targetActor.transform.position);
     }
     return(VTMapManager.GlobalToWorldPoint(lastTargetPositon));
 }
    void FixedUpdate()
    {
        ///stops baha touching our velocities
        actor.fixedVelocityUpdate = true;
        if (rb == null)
        {
            Debug.LogError("Rigid body is null on object " + gameObject.name);
        }
        if (rb.isKinematic == false)
        {
            rb.isKinematic = true;
            Debug.Log("Rigidbody was not kinematic on " + gameObject.name);
        }

        if (kplane != null) // yes this can be null on objects that arent airplanes
        {
            if (kplane.enabled == true)
            {
                kplane.enabled = false;
                Debug.Log("Disabled kplane again on " + gameObject.name);
            }
        }
        if (playerWeRepresent == null)
        {
            int playerID = PlayerManager.FindPlayerIDFromNetworkUID(networkUID);                                               //get the ping of the player we represent
            if (playerID == -1)
            {                                                                                                                  //we are not a player, get the ping from the host
                playerID = PlayerManager.FindPlayerIDFromNetworkUID(PlayerManager.GetPlayerUIDFromCSteamID(Networker.hostID)); //getting the host
            }
            if (playerID != -1)                                                                                                //couldnt find host latency, that sucks
            {
                playerWeRepresent = PlayerManager.players[playerID];
            }
        }
        if (playerWeRepresent != null)
        {
            //delta time needs to be added to latency as this runs after packet has arrived for a while
            latency = playerWeRepresent.ping + Time.fixedDeltaTime;
        }

        globalTargetPosition += new Vector3D(targetVelocity * Time.fixedDeltaTime);
        localTargetPosition   = VTMapManager.GlobalToWorldPoint(globalTargetPosition);

        Quaternion quatVel         = Quaternion.Euler(targetRotationVelocity * Time.fixedDeltaTime);
        Quaternion currentRotation = transform.rotation;

        currentRotation *= quatVel;
        targetRotation  *= quatVel;

        rb.velocity = targetVelocity + (localTargetPosition - transform.position) / smoothingTime;
        //actor.SetCustomVelocity(Vector3.Lerp(actor.velocity, targetVelocity + (localTargetPosition - transform.position) / smoothingTime, Time.fixedDeltaTime / velSmoothingTime));
        actor.SetCustomVelocity(rb.velocity);

        rb.MovePosition(transform.position + targetVelocity * Time.fixedDeltaTime + ((localTargetPosition - transform.position) * Time.fixedDeltaTime) / smoothingTime);
        Quaternion quat = Quaternion.Slerp(currentRotation, targetRotation, Time.fixedDeltaTime / rotSmoothingTime);

        rb.MoveRotation(quat.normalized);
    }
 void FixedUpdate()
 {
     targetPositionGlobal += targetVelocity * Time.fixedDeltaTime;
     targetPosition        = VTMapManager.GlobalToWorldPoint(targetPositionGlobal);
     ship.rb.MovePosition(ship.transform.position + targetVelocity * Time.fixedDeltaTime + ((targetPosition - ship.transform.position) * Time.fixedDeltaTime) / smoothTime);
     ship.rb.velocity = targetVelocity + (targetPosition - ship.transform.position) / smoothTime;
     shipTraverse.Field("_velocity").SetValue(ship.rb.velocity);//makes the wake emit partical
     ship.rb.MoveRotation(Quaternion.Lerp(ship.transform.rotation, targetRotation, Time.fixedDeltaTime / rotSmoothTime));
 }
Example #10
0
    public override void StartTask(TrafficAI_Base ai)
    {
        Debug.Log("Starting fly off map task!");
        TrafficAI_Transport ai2 = (TrafficAI_Transport)ai;

        ai2.waypoint.GetTransform().position = VTMapManager.GlobalToWorldPoint(AirTraffic.PointOnMapRadius());
        ai2.aircraft.SetOrbitNow(ai2.waypoint, 10000, AirTraffic.cruisingAltitudes.Random());
        ai2.pilot.navSpeed = UnityEngine.Random.Range(ai2.normalSpeed, ai2.pilot.maxSpeed);
        base.StartTask(ai2);
    }
Example #11
0
    public override void StartTask(TrafficAI_Base ai)
    {
        Debug.Log("Starting landing at temporary task!");
        TrafficAI_Transport transportAI = (TrafficAI_Transport)ai;

        ai.waypoint.GetTransform().position = VTMapManager.GlobalToWorldPoint(point);
        transportAI.aircraft.LandAtWpt(ai.waypoint);
        idleTimer = UnityEngine.Random.Range(15f, 30f);
        base.StartTask(ai);
    }
Example #12
0
    public override void StartTask(TrafficAI_Base ai)
    {
        Debug.Log("Starting scout airbase!");
        TrafficAI_CAP capAI = (TrafficAI_CAP)ai;

        ai.waypoint.GetTransform().position = VTMapManager.GlobalToWorldPoint(point);
        capAI.Orbit(ai.waypoint, radius, alt);
        idleTimer = UnityEngine.Random.Range(30f, 120f);
        arived    = false;
        base.StartTask(ai);
    }
    public override void Spawn(Vector3D pos, Vector3 dir)
    {
        Debug.Log("Reseting aircraft");
        foreach (CAP_Aircraft plane in formation)
        {
            plane.aircraft.transform.position = VTMapManager.GlobalToWorldPoint(pos);
            plane.aircraft.transform.LookAt(plane.aircraft.transform.position + dir);
            plane.rb.velocity = plane.gameObject.transform.forward * plane.pilot.navSpeed;

            plane.gameObject.GetComponentInChildren <GearAnimator>().RetractImmediate();
            plane.gameObject.GetComponent <KinematicPlane>().SetToKinematic();
            Debug.Log("aircraft reset");
        }
    }
Example #14
0
        int GetSpawnID(AICarrierSpawn carrier)
        {
            Vector3 b      = VTMapManager.GlobalToWorldPoint(new Vector3D(actor.transform.position));
            int     result = 0;
            float   num    = float.MaxValue;

            for (int i = 0; i < carrier.spawnPoints.Count; i++)
            {
                float sqrMagnitude = (carrier.spawnPoints[i].spawnTf.position - b).sqrMagnitude;
                if (sqrMagnitude < num)
                {
                    result = i;
                    num    = sqrMagnitude;
                }
            }
            return(result);
        }
Example #15
0
    private Actor GetActorAtPosition(Vector3D globalPos)
    {
        Vector3 worldPos = VTMapManager.GlobalToWorldPoint(globalPos);
        Actor   result   = null;
        float   num      = 250000f;

        for (int i = 0; i < TargetManager.instance.allActors.Count; i++)
        {
            float sqrMagnitude = (TargetManager.instance.allActors[i].position - worldPos).sqrMagnitude;
            if (sqrMagnitude < num)
            {
                num    = sqrMagnitude;
                result = TargetManager.instance.allActors[i];
            }
        }
        return(result);
    }
Example #16
0
    private void FixedUpdate()
    {
        globalLastPosition += new Vector3D(lastVelocity * Time.fixedDeltaTime);
        localLastPosition   = VTMapManager.GlobalToWorldPoint(globalLastPosition);
        Quaternion quatVel = Quaternion.Euler(lastAngularVelocity * Time.fixedDeltaTime);

        lastRotation *= quatVel;

        lastUp      = lastRotation * Vector3.up;
        lastForward = lastRotation * Vector3.forward;
        tick       += Time.fixedDeltaTime;
        if (tick > 1.0f / tickRate || Vector3.Distance(localLastPosition, transform.TransformPoint(originOffset)) > threshold || Vector3.Angle(lastUp, transform.up) > angleThreshold || Vector3.Angle(lastForward, transform.forward) > angleThreshold)
        {
            tick        = 0.0f;
            lastUp      = transform.up;
            lastForward = transform.forward;

            globalLastPosition = VTMapManager.WorldToGlobalPoint(transform.TransformPoint(originOffset));
            lastVelocity       = rb.velocity;

            lastRotation        = transform.rotation;
            lastAngularVelocity = rb.angularVelocity * Mathf.Rad2Deg;

            lastMessage.position = VTMapManager.WorldToGlobalPoint(transform.TransformPoint(originOffset));
            lastMessage.rotation = transform.rotation;
            if (Multiplayer.SoloTesting)
            {
                lastMessage.position += new Vector3D(-30, 0, 0);
            }
            lastMessage.velocity        = new Vector3D(rb.velocity);
            lastMessage.angularVelocity = new Vector3D(rb.angularVelocity * Mathf.Rad2Deg);
            lastMessage.networkUID      = networkUID;
            lastMessage.sequenceNumber  = ++updateNumber;
            if (Networker.isHost)
            {
                NetworkSenderThread.Instance.SendPacketAsHostToAllClients(lastMessage, Steamworks.EP2PSend.k_EP2PSendUnreliableNoDelay);
            }
            else
            {
                NetworkSenderThread.Instance.SendPacketToSpecificPlayer(Networker.hostID, lastMessage, Steamworks.EP2PSend.k_EP2PSendUnreliableNoDelay);
            }
        }
        // Temperz STOP KILLING PERFORMANCE AND HARD DRIVES!
        //Debug.Log($"{actor.name} is not outside of the threshold {Threshold}, the distance is {Vector3.Distance(lastPos, gameObject.transform.position)} not updating it.");
    }
    public void ShipUpdate(Packet packet)
    {
        lastMessage = (Message_ShipUpdate)((PacketSingle)packet).message;
        if (lastMessage.UID != networkUID)
        {
            return;
        }

        targetPositionGlobal = lastMessage.position.toVector3 + lastMessage.velocity.toVector3 * Networker.pingToHost;
        targetVelocity       = lastMessage.velocity.toVector3;
        targetRotation       = lastMessage.rotation;

        if ((VTMapManager.GlobalToWorldPoint(lastMessage.position) - ship.transform.position).magnitude > 100)
        {
            Debug.Log("Ship is too far, teleporting. This message should apear once per ship at spawn, if ur seeing more something is probably fucky");
            ship.transform.position = VTMapManager.GlobalToWorldPoint(lastMessage.position);
        }
    }
Example #18
0
    public void BulletHit(Packet packet)
    {
        bulletMessage = (Message_BulletHit)((PacketSingle)packet).message;

        Debug.Log("handling bullet hit");

        if (bulletMessage.destUID != networkUID)
        {
            return;
        }


        RaycastHit hitInfo;
        Vector3    pos = VTMapManager.GlobalToWorldPoint(bulletMessage.pos);
        Vector3    vel = bulletMessage.dir.toVector3;
        Vector3    a   = pos;

        a += vel * 100.0f;

        bool  flag   = Physics.Linecast(pos, a, out hitInfo, 1025);
        Actor source = null;

        if (AIDictionaries.allActors.ContainsKey(bulletMessage.sourceActorUID))
        {
            source = AIDictionaries.allActors[bulletMessage.sourceActorUID];
        }
        Hitbox hitbox = null;

        if (flag)
        {
            hitbox = hitInfo.collider.GetComponent <Hitbox>();
            if ((bool)hitbox && (bool)hitbox.actor)
            {
                Debug.Log("found  target bullet hit");
                hitbox.Damage(bulletMessage.damage * 3.0f, hitInfo.point, Health.DamageTypes.Impact, source, "Bullet Impact");
                BulletHitManager.instance.CreateBulletHit(hitInfo.point, -vel, true);
            }
        }
        else
        {
            health.Damage(bulletMessage.damage * 3.0f, ownerActor.gameObject.transform.position, Health.DamageTypes.Impact, source, "Bullet Impact");
            BulletHitManager.instance.CreateBulletHit(ownerActor.gameObject.transform.position, -vel, true);
        }
    }
Example #19
0
    void FixedUpdate()
    {
        if (targetVelocity.sqrMagnitude > 1)
        {
            targetRotation = Quaternion.LookRotation(targetVelocity);
        }

        targetPositionGlobal += targetVelocity * Time.fixedDeltaTime;

        smoothedPosition = smoothedPosition + targetVelocity * Time.fixedDeltaTime + ((targetPositionGlobal - smoothedPosition) * Time.fixedDeltaTime) / smoothTime;
        smoothedRotation = Quaternion.Slerp(smoothedRotation, targetRotation, Time.fixedDeltaTime / rotSmoothTime);
        smoothedRotation = smoothedRotation.normalized;
        Vector3    adjustedPos      = VTMapManager.GlobalToWorldPoint(smoothedPosition);
        Vector3    surfaceNormal    = smoothedRotation * Vector3.up;
        Vector3    surfaceRight     = smoothedRotation * Vector3.right;
        Vector3    surfaceForward   = smoothedRotation * Vector3.forward;
        Quaternion adjustedRotation = smoothedRotation;

        RaycastHit hit;

        if (Physics.Raycast(adjustedPos + 500 * Vector3.up, Vector3.down, out hit, 1000, 1, QueryTriggerInteraction.Ignore))
        {
            adjustedPos    = hit.point + hit.normal * groundUnitMover.height;
            surfaceNormal  = hit.normal;
            surfaceRight   = Vector3.Cross(surfaceNormal, smoothedRotation * Vector3.forward);
            surfaceForward = Vector3.Cross(surfaceRight, surfaceNormal);
            if (surfaceForward != Vector3.zero && surfaceNormal != Vector3.zero)
            {
                adjustedRotation = Quaternion.LookRotation(surfaceForward, surfaceNormal);
            }
        }
        adjustedRotation = adjustedRotation.normalized;
        //groundTraverse.Field("velocity").SetValue(targetVelocity + (targetPositionGlobal - smoothedPosition).toVector3 / smoothTime);

        rb.MovePosition(adjustedPos);
        rb.MoveRotation(adjustedRotation);//move rotation was throwing "Rotation quaternions must be unit length"

        if (isSoldier)
        {
            soldier.animator.SetFloat(walkingAnimation, (targetVelocity + (targetPositionGlobal - smoothedPosition).toVector3 / smoothTime).magnitude);
        }
    }
Example #20
0
    private void FixedUpdate()
    {
        globalLastPosition += new Vector3D(lastVelocity * Time.fixedDeltaTime);
        localLastPosition   = VTMapManager.GlobalToWorldPoint(globalLastPosition);
        Quaternion quatVel = Quaternion.Euler(lastAngularVelocity * Time.fixedDeltaTime);

        lastRotation *= quatVel;

        lastUp      = lastRotation * Vector3.up;
        lastForward = lastRotation * Vector3.forward;
        tick       += Time.fixedDeltaTime;
        if (tick > 1.0f / tickRate || Vector3.Distance(localLastPosition, transform.TransformPoint(originOffset)) > threshold || Vector3.Angle(lastUp, transform.up) > angleThreshold || Vector3.Angle(lastForward, transform.forward) > angleThreshold)
        {
            tick        = 0.0f;
            lastUp      = transform.up;
            lastForward = transform.forward;

            globalLastPosition = VTMapManager.WorldToGlobalPoint(transform.TransformPoint(originOffset));
            lastVelocity       = rb.velocity;

            lastRotation        = transform.rotation;
            lastAngularVelocity = rb.angularVelocity * Mathf.Rad2Deg;

            lastMessage.position = VTMapManager.WorldToGlobalPoint(transform.TransformPoint(originOffset));
            lastMessage.rotation = transform.rotation;

            lastMessage.velocity        = new Vector3D(rb.velocity);
            lastMessage.angularVelocity = new Vector3D(rb.angularVelocity * Mathf.Rad2Deg);
            lastMessage.networkUID      = networkUID;
            lastMessage.sequenceNumber  = ++updateNumber;
            if (Networker.isHost)
            {
                Networker.addToUnreliableSendBuffer(lastMessage);
            }
            else
            {
                NetworkSenderThread.Instance.SendPacketToSpecificPlayer(Networker.hostID, lastMessage, Steamworks.EP2PSend.k_EP2PSendUnreliable);
            }
        }
    }
Example #21
0
        Runway GetRunway()
        {
            Vector3 b      = VTMapManager.GlobalToWorldPoint(new Vector3D(actor.transform.position));
            Runway  result = null;
            float   num    = float.MaxValue;

            foreach (AirportManager airportManager in VTMapManager.fetch.airports)
            {
                foreach (Runway runway in airportManager.runways)
                {
                    if (runway)
                    {
                        float sqrMagnitude = (runway.transform.position - b).sqrMagnitude;
                        if (sqrMagnitude < num)
                        {
                            result = runway;
                            num    = sqrMagnitude;
                        }
                    }
                }
            }
            return(result);
        }
Example #22
0
        AirportManager GetAirport()
        {
            Vector3        b      = VTMapManager.GlobalToWorldPoint(new Vector3D(actor.transform.position));
            AirportManager result = null;
            float          num    = float.MaxValue;

            foreach (AirportManager airportManager in VTScenario.current.GetAllAirports())
            {
                foreach (Runway runway in airportManager.runways)
                {
                    if (runway)
                    {
                        float sqrMagnitude = (runway.transform.position - b).sqrMagnitude;
                        if (sqrMagnitude < num)
                        {
                            result = airportManager;
                            num    = sqrMagnitude;
                        }
                    }
                }
            }
            return(result);
        }
Example #23
0
    public override void LateUpdate(FlybyCameraMFDPage mfdPage)
    {
        if (Input.GetKeyDown(KeyCode.Mouse0))
        {
            mfdPage.CycleFovs();
        }

        SCamPlus.rotation.y += Input.GetAxis("Mouse X") * SCamPlus.sensitivity / 60f * mfdPage.flybyCam.fieldOfView;
        SCamPlus.rotation.x += Input.GetAxis("Mouse Y") * -SCamPlus.sensitivity / 60f * mfdPage.flybyCam.fieldOfView;

        SCamPlus.rotation.x = Mathf.Clamp(SCamPlus.rotation.x, -90, 90);
        mfdPage.flybyCam.transform.eulerAngles = (Vector2)SCamPlus.rotation;

        float speedFactor = 10;

        if (Input.GetKey(KeyCode.LeftShift))
        {
            speedFactor = 1000;
        }
        SCamPlus.position += (mfdPage.flybyCam.transform.forward * Input.GetAxis("Vertical") + mfdPage.flybyCam.transform.right * Input.GetAxis("Horizontal")) * Time.deltaTime * speedFactor;
        mfdPage.flybyCam.transform.position = VTMapManager.GlobalToWorldPoint(SCamPlus.position);
        mfdPage.behaviorText.text           = "FreeCam";
    }
Example #24
0
    public static GameObject SpawnRepresentation(ulong networkID, Vector3D position, Quaternion rotation, bool isLeft)
    {
        if (networkID == localUID)
        {
            return(null);
        }

        int playerID = FindPlayerIDFromNetworkUID(networkID);

        if (playerID == -1)
        {
            Debug.LogError("Spawn Representation couldn't find a player id.");
        }
        Player player = players[playerID];

        if (player.vehicle != null)
        {
            GameObject.Destroy(player.vehicle);
        }

        GameObject newVehicle = null;

        switch (player.vehicleType)
        {
        case VTOLVehicles.None:
            Debug.LogError("Vehcile Enum seems to be none, couldn't spawn player vehicle");
            return(null);

        case VTOLVehicles.AV42C:
            if (null == av42cPrefab)
            {
                SetPrefabs();
            }
            newVehicle = GameObject.Instantiate(av42cPrefab, VTMapManager.GlobalToWorldPoint(position), rotation);
            break;

        case VTOLVehicles.FA26B:
            if (null == fa26bPrefab)
            {
                SetPrefabs();
            }
            newVehicle = GameObject.Instantiate(fa26bPrefab, VTMapManager.GlobalToWorldPoint(position), rotation);
            break;

        case VTOLVehicles.F45A:
            if (null == f45Prefab)
            {
                SetPrefabs();
            }
            newVehicle = GameObject.Instantiate(f45Prefab, VTMapManager.GlobalToWorldPoint(position), rotation);
            break;
        }
        //Debug.Log("Setting vehicle name");
        newVehicle.name = $"Client [{player.cSteamID}]";
        Debug.Log($"Spawned new vehicle at {newVehicle.transform.position}");
        if (Networker.isHost)
        {
            HealthNetworker_Receiver healthNetworker = newVehicle.AddComponent <HealthNetworker_Receiver>();
            healthNetworker.networkUID = networkID;
        }
        else
        {
            HealthNetworker_ReceiverHostEnforced healthNetworker = newVehicle.AddComponent <HealthNetworker_ReceiverHostEnforced>();
            healthNetworker.networkUID = networkID;
        }
        RigidbodyNetworker_Receiver rbNetworker = newVehicle.AddComponent <RigidbodyNetworker_Receiver>();

        rbNetworker.networkUID = networkID;

        PlaneNetworker_Receiver planeReceiver = newVehicle.AddComponent <PlaneNetworker_Receiver>();

        planeReceiver.networkUID = networkID;

        if (player.vehicleType == VTOLVehicles.AV42C || player.vehicleType == VTOLVehicles.F45A)
        {
            //Debug.Log("Adding Tilt Controller to this vehicle " + message.networkID);
            EngineTiltNetworker_Receiver tiltReceiver = newVehicle.AddComponent <EngineTiltNetworker_Receiver>();
            tiltReceiver.networkUID = networkID;
        }

        Rigidbody rb      = newVehicle.GetComponent <Rigidbody>();
        AIPilot   aIPilot = newVehicle.GetComponent <AIPilot>();

        RotationToggle wingRotator = aIPilot.wingRotator;

        if (wingRotator != null)
        {
            WingFoldNetworker_Receiver wingFoldReceiver = newVehicle.AddComponent <WingFoldNetworker_Receiver>();
            wingFoldReceiver.networkUID     = networkID;
            wingFoldReceiver.wingController = wingRotator;
        }

        LockingRadar lockingRadar = newVehicle.GetComponentInChildren <LockingRadar>();

        if (lockingRadar != null)
        {
            Debug.Log($"Adding LockingRadarReciever to vehicle {newVehicle.name}");
            LockingRadarNetworker_Receiver lockingRadarReceiver = newVehicle.AddComponent <LockingRadarNetworker_Receiver>();
            lockingRadarReceiver.networkUID = networkID;
        }

        ExteriorLightsController extLight = newVehicle.GetComponentInChildren <ExteriorLightsController>();

        if (extLight != null)
        {
            ExtLight_Receiver extLightReceiver = newVehicle.AddComponent <ExtLight_Receiver>();
            extLightReceiver.lightsController = extLight;
            extLightReceiver.networkUID       = networkID;
        }

        aIPilot.enabled = false;
        Debug.Log($"Changing {newVehicle.name}'s position and rotation\nPos:{rb.position} Rotation:{rb.rotation.eulerAngles}");
        aIPilot.kPlane.SetToKinematic();
        aIPilot.kPlane.enabled = false;
        rb.interpolation       = RigidbodyInterpolation.None;

        aIPilot.kPlane.enabled = true;
        aIPilot.kPlane.SetVelocity(Vector3.zero);
        aIPilot.kPlane.SetToDynamic();
        rb.interpolation = RigidbodyInterpolation.Interpolate;

        Debug.Log($"Finished changing {newVehicle.name}\n Pos:{rb.position} Rotation:{rb.rotation.eulerAngles}");

        AvatarManager.SetupAircraftRoundels(newVehicle.transform, player.vehicleType, player.cSteamID, Vector3.zero);

        GameObject parent  = new GameObject("Name Tag Holder");
        GameObject nameTag = new GameObject("Name Tag");

        parent.transform.SetParent(newVehicle.transform);
        parent.transform.localRotation = Quaternion.Euler(0, 180, 0);
        nameTag.transform.SetParent(parent.transform);
        nameTag.AddComponent <Nametag>().SetText(
            SteamFriends.GetFriendPersonaName(player.cSteamID),
            newVehicle.transform, VRHead.instance.transform);
        if (isLeft != PlayerManager.teamLeftie)
        {
            aIPilot.actor.team = Teams.Enemy;
        }

        TargetManager.instance.RegisterActor(aIPilot.actor);
        player.leftie  = isLeft;
        player.vehicle = newVehicle;

        if (!VTOLVR_Multiplayer.AIDictionaries.allActors.ContainsKey(networkID))
        {
            VTOLVR_Multiplayer.AIDictionaries.allActors[networkID]            = aIPilot.actor;
            VTOLVR_Multiplayer.AIDictionaries.reverseAllActors[aIPilot.actor] = networkID;
        }
        else
        {
            VTOLVR_Multiplayer.AIDictionaries.allActors.Remove(networkID);
            VTOLVR_Multiplayer.AIDictionaries.reverseAllActors.Remove(aIPilot.actor);

            VTOLVR_Multiplayer.AIDictionaries.allActors[networkID]            = aIPilot.actor;
            VTOLVR_Multiplayer.AIDictionaries.reverseAllActors[aIPilot.actor] = networkID;
        }

        return(newVehicle);
    }
    public void MissileUpdate(Packet packet)
    {
        lastMessage = ((PacketSingle)packet).message as Message_MissileUpdate;

        if (lastMessage.networkUID != networkUID)
        {
            return;
        }
        if (!thisMissile.gameObject.activeSelf)
        {
            Debug.LogError(thisMissile.gameObject.name + " isn't active in hiearchy, changing it to active.");
            thisMissile.gameObject.SetActive(true);
        }
        if (traverse == null)
        {
            traverse = Traverse.Create(thisML);
        }
        if (!thisMissile.fired)
        {
            Debug.Log(thisMissile.gameObject.name + " missile fired on one end but not another, firing here.");
            if (thisML == null)
            {
                Debug.LogError($"Missile launcher is null on missile {thisMissile.actor.name}, someone forgot to assign it.");
            }
            if (lastMessage.guidanceMode == Missile.GuidanceModes.Radar)
            {
                // thisMissile.debugMissile = true;
                RadarMissileLauncher radarLauncher = thisML as RadarMissileLauncher;
                if (!VTOLVR_Multiplayer.AIDictionaries.allActors.TryGetValue(lastMessage.radarLock, out Actor actor))
                {
                    Debug.LogWarning($"Could not resolve missile launcher radar lock from uID {lastMessage.radarLock}.");
                }
                else
                {
                    if (radarLauncher.lockingRadar != null)
                    {
                        radarLauncher.lockingRadar.ForceLock(actor, out lockData);
                    }
                    else
                    {
                        Debug.LogWarning("Locking Radar null on object " + thisMissile.name);
                    }
                }
                if (radarLauncher != null)
                {
                    Debug.Log("Guidance mode radar, firing it as a radar missile.");
                    traverse.Field("missileIdx").SetValue(idx);
                    if (!radarLauncher.TryFireMissile())
                    {
                        Debug.LogError($"Could not fire radar missile, lock data is as follows: Locked: {lockData.locked}, Actor: {lockData.actor}");
                    }
                    else
                    {
                        RigidbodyNetworker_Receiver rbReceiver = gameObject.AddComponent <RigidbodyNetworker_Receiver>();
                        rbReceiver.networkUID = networkUID;
                    }
                }
            }
            else
            {
                if (lastMessage.guidanceMode == Missile.GuidanceModes.Heat)
                {
                    Debug.Log("Guidance mode Heat.");
                    thisMissile.heatSeeker.transform.rotation = lastMessage.seekerRotation;
                    thisMissile.heatSeeker.SetHardLock();
                }

                if (lastMessage.guidanceMode == Missile.GuidanceModes.Optical)
                {
                    Debug.Log("Guidance mode Optical.");

                    GameObject emptyGO      = new GameObject();
                    Transform  newTransform = emptyGO.transform;

                    newTransform.position = VTMapManager.GlobalToWorldPoint(lastMessage.targetPosition);
                    thisMissile.SetOpticalTarget(newTransform);
                    //thisMissile.heatSeeker.SetHardLock();

                    if (thisMissile.opticalLOAL)
                    {
                        thisMissile.SetLOALInitialTarget(VTMapManager.GlobalToWorldPoint(lastMessage.targetPosition));
                    }
                }
                Debug.Log("Try fire missile clientside");
                traverse.Field("missileIdx").SetValue(idx);
                thisML.FireMissile();
                RigidbodyNetworker_Receiver rbReceiver = gameObject.AddComponent <RigidbodyNetworker_Receiver>();
                rbReceiver.networkUID = networkUID;
            }
            if (hasFired != thisMissile.fired)
            {
                Debug.Log("Missile fired " + thisMissile.name);
                hasFired = true;
                if (colliderLayers.Count > 0)
                {
                    StartCoroutine(colliderTimer());
                }
            }
        }

        //explode missle after it has done its RB physics fixed timestep
        if (lastMessage.hasExploded)
        {
            Debug.Log("Missile exploded.");
            if (thisMissile != null)
            {
                traverse.Field("detonated").SetValue(false);

                ///thisMissile.rb.velocity = thisMissile.transform.forward * 10.0f;
                thisMissile.Detonate();
            }
        }
    }
Example #26
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++;
        }
    }