Exemplo n.º 1
0
        private void OnVesselWillDestroy(Vessel vessel)
        {
            if (vesselWorker.VesselRecentlyKilled(vessel.id))
            {
                return;
            }
            bool pilotedByAnotherPlayer = lockSystem.LockExists("control-" + vessel.id) && !lockSystem.LockIsOurs("control-" + vessel.id);
            bool updatedByAnotherPlayer = lockSystem.LockExists("update-" + vessel.id) && !lockSystem.LockIsOurs("update-" + vessel.id);
            bool updatedInTheFuture     = vesselWorker.VesselUpdatedInFuture(vessel.id);

            //Vessel was packed within the last 5 seconds
            if (lastPackTime.ContainsKey(vessel.id) && (Client.realtimeSinceStartup - lastPackTime[vessel.id]) < 5f)
            {
                lastPackTime.Remove(vessel.id);
                if (vessel.situation == Vessel.Situations.FLYING && (pilotedByAnotherPlayer || updatedByAnotherPlayer || updatedInTheFuture))
                {
                    DarkLog.Debug("Hacky load: Saving player vessel getting packed in atmosphere");
                    ProtoVessel pv        = vessel.BackupVessel();
                    ConfigNode  savedNode = new ConfigNode();
                    pv.Save(savedNode);
                    vesselWorker.LoadVessel(savedNode, vessel.id, true);
                }
            }
            if (lastPackTime.ContainsKey(vessel.id))
            {
                lastPackTime.Remove(vessel.id);
            }
        }
Exemplo n.º 2
0
        private void OnCrewKilled(EventReport report)
        {
            Part part = report.origin;

            if (part != null)
            {
                Vessel vessel = part.vessel;

                if (vessel != null)
                {
                    if ((lockSystem.LockExists("control-" + vessel.id) && !lockSystem.LockIsOurs("control-" + vessel.id)) || !lockSystem.LockExists("control-" + vessel.id))
                    {
                        if (!repLossHasReason)
                        {
                            repLossHasReason = true;
                            repEventTimer    = Client.realtimeSinceStartup;
                        }
                    }
                }
                else
                {
                    if (!repLossHasReason)
                    {
                        repLossHasReason = true;
                        repEventTimer    = Client.realtimeSinceStartup;
                    }
                }
            }
            else
            {
                if (!repLossHasReason)
                {
                    repLossHasReason = true;
                    repEventTimer    = Client.realtimeSinceStartup;
                }
            }
        }
Exemplo n.º 3
0
 private void SetVesselColor(Vessel colorVessel)
 {
     if (workerEnabled)
     {
         if (lockSystem.LockExists("control-" + colorVessel.id.ToString()) && !lockSystem.LockIsOurs("control-" + colorVessel.id.ToString()))
         {
             string vesselOwner = lockSystem.LockOwner("control-" + colorVessel.id.ToString());
             DarkLog.Debug("Vessel " + colorVessel.id.ToString() + " owner is " + vesselOwner);
             colorVessel.orbitDriver.orbitColor = GetPlayerColor(vesselOwner);
         }
         else
         {
             colorVessel.orbitDriver.orbitColor = DEFAULT_COLOR;
         }
     }
 }
        private void Update()
        {
            if (workerEnabled)
            {
                if ((Client.realtimeSinceStartup - lastPlayerStatusCheck) > PLAYER_STATUS_CHECK_INTERVAL)
                {
                    lastPlayerStatusCheck     = Client.realtimeSinceStartup;
                    myPlayerStatus.vesselText = "";
                    myPlayerStatus.statusText = "";
                    if (HighLogic.LoadedSceneIsFlight)
                    {
                        //Send vessel+status update
                        if (FlightGlobals.ActiveVessel != null)
                        {
                            if (!vesselWorker.isSpectating)
                            {
                                myPlayerStatus.vesselText = FlightGlobals.ActiveVessel.vesselName;
                                string bodyName = FlightGlobals.ActiveVessel.mainBody.bodyName;
                                switch (FlightGlobals.ActiveVessel.situation)
                                {
                                case (Vessel.Situations.DOCKED):
                                    myPlayerStatus.statusText = "Docked above " + bodyName;
                                    break;

                                case (Vessel.Situations.ESCAPING):
                                    if (FlightGlobals.ActiveVessel.orbit.timeToPe < 0)
                                    {
                                        myPlayerStatus.statusText = "Escaping " + bodyName;
                                    }
                                    else
                                    {
                                        myPlayerStatus.statusText = "Encountering " + bodyName;
                                    }
                                    break;

                                case (Vessel.Situations.FLYING):
                                    if (!SafetyBubble.isInSafetyBubble(FlightGlobals.fetch.activeVessel.GetWorldPos3D(), FlightGlobals.fetch.activeVessel.mainBody, vesselWorker.safetyBubbleDistance))
                                    {
                                        myPlayerStatus.statusText = "Flying above " + bodyName;
                                    }
                                    else
                                    {
                                        myPlayerStatus.statusText = "Flying in safety bubble";
                                    }
                                    break;

                                case (Vessel.Situations.LANDED):
                                    if (!SafetyBubble.isInSafetyBubble(FlightGlobals.fetch.activeVessel.GetWorldPos3D(), FlightGlobals.fetch.activeVessel.mainBody, vesselWorker.safetyBubbleDistance))
                                    {
                                        myPlayerStatus.statusText = "Landed on " + bodyName;
                                    }
                                    else
                                    {
                                        myPlayerStatus.statusText = "Landed in safety bubble";
                                    }
                                    break;

                                case (Vessel.Situations.ORBITING):
                                    myPlayerStatus.statusText = "Orbiting " + bodyName;
                                    break;

                                case (Vessel.Situations.PRELAUNCH):
                                    if (!SafetyBubble.isInSafetyBubble(FlightGlobals.fetch.activeVessel.GetWorldPos3D(), FlightGlobals.fetch.activeVessel.mainBody, vesselWorker.safetyBubbleDistance))
                                    {
                                        myPlayerStatus.statusText = "Launching from " + bodyName;
                                    }
                                    else
                                    {
                                        myPlayerStatus.statusText = "Launching from safety bubble";
                                    }
                                    break;

                                case (Vessel.Situations.SPLASHED):
                                    myPlayerStatus.statusText = "Splashed on " + bodyName;
                                    break;

                                case (Vessel.Situations.SUB_ORBITAL):
                                    if (FlightGlobals.ActiveVessel.verticalSpeed > 0)
                                    {
                                        myPlayerStatus.statusText = "Ascending from " + bodyName;
                                    }
                                    else
                                    {
                                        myPlayerStatus.statusText = "Descending to " + bodyName;
                                    }
                                    break;

                                default:
                                    break;
                                }
                            }
                            else
                            {
                                if (lockSystem.LockExists("control-" + FlightGlobals.ActiveVessel.id.ToString()))
                                {
                                    if (lockSystem.LockIsOurs("control-" + FlightGlobals.ActiveVessel.id.ToString()))
                                    {
                                        myPlayerStatus.statusText = "Waiting for vessel control";
                                    }
                                    else
                                    {
                                        myPlayerStatus.statusText = "Spectating " + lockSystem.LockOwner("control-" + FlightGlobals.ActiveVessel.id.ToString());
                                    }
                                }
                                else
                                {
                                    if (permissions.PlayerHasVesselPermission(myPlayerStatus.playerName, FlightGlobals.ActiveVessel.id))
                                    {
                                        myPlayerStatus.statusText = "Spectating future updates";
                                    }
                                    else
                                    {
                                        myPlayerStatus.statusText = "Spectating protected vessel";
                                    }
                                }
                            }
                        }
                        else
                        {
                            myPlayerStatus.statusText = "Loading";
                        }
                    }
                    else
                    {
                        //Send status update
                        switch (HighLogic.LoadedScene)
                        {
                        case (GameScenes.EDITOR):
                            myPlayerStatus.statusText = "Building";
                            if (EditorDriver.editorFacility == EditorFacility.VAB)
                            {
                                myPlayerStatus.statusText = "Building in VAB";
                            }
                            if (EditorDriver.editorFacility == EditorFacility.SPH)
                            {
                                myPlayerStatus.statusText = "Building in SPH";
                            }
                            break;

                        case (GameScenes.SPACECENTER):
                            myPlayerStatus.statusText = "At Space Center";
                            break;

                        case (GameScenes.TRACKSTATION):
                            myPlayerStatus.statusText = "At Tracking Station";
                            break;

                        case (GameScenes.LOADING):
                            myPlayerStatus.statusText = "Loading";
                            break;

                        default:
                            break;
                        }
                    }
                }

                bool statusDifferent = false;
                statusDifferent = statusDifferent || (myPlayerStatus.vesselText != lastPlayerStatus.vesselText);
                statusDifferent = statusDifferent || (myPlayerStatus.statusText != lastPlayerStatus.statusText);
                if (statusDifferent && ((Client.realtimeSinceStartup - lastPlayerStatusSend) > PLAYER_STATUS_SEND_THROTTLE))
                {
                    lastPlayerStatusSend        = Client.realtimeSinceStartup;
                    lastPlayerStatus.vesselText = myPlayerStatus.vesselText;
                    lastPlayerStatus.statusText = myPlayerStatus.statusText;
                    networkWorker.SendPlayerStatus(myPlayerStatus);
                }

                while (addStatusQueue.Count > 0)
                {
                    PlayerStatus newStatusEntry = addStatusQueue.Dequeue();
                    bool         found          = false;
                    foreach (PlayerStatus playerStatusEntry in playerStatusList)
                    {
                        if (playerStatusEntry.playerName == newStatusEntry.playerName)
                        {
                            found = true;
                            playerStatusEntry.vesselText = newStatusEntry.vesselText;
                            playerStatusEntry.statusText = newStatusEntry.statusText;
                        }
                    }
                    if (!found)
                    {
                        playerStatusList.Add(newStatusEntry);
                        DarkLog.Debug("Added " + newStatusEntry.playerName + " to status list");
                    }
                }

                while (removeStatusQueue.Count > 0)
                {
                    string       removeStatusString = removeStatusQueue.Dequeue();
                    PlayerStatus removeStatus       = null;
                    foreach (PlayerStatus currentStatus in playerStatusList)
                    {
                        if (currentStatus.playerName == removeStatusString)
                        {
                            removeStatus = currentStatus;
                        }
                    }
                    if (removeStatus != null)
                    {
                        playerStatusList.Remove(removeStatus);

                        DarkLog.Debug("Removed " + removeStatusString + " from status list");
                    }
                    else
                    {
                        DarkLog.Debug("Cannot remove non-existant player " + removeStatusString);
                    }
                }
            }
        }
Exemplo n.º 5
0
        private void Update()
        {
            if (!workerEnabled)
            {
                return;
            }
            InitializeScenario();
            if (scenario == null)
            {
                return;
            }

            if (lastAsteroidCheck + ASTEROID_CHECK_INTERVAL > Client.realtimeSinceStartup)
            {
                return;
            }
            lastAsteroidCheck = Client.realtimeSinceStartup;

            //Try to acquire the asteroid-spawning lock if nobody else has it.
            if (!lockSystem.LockExists("asteroid-spawning"))
            {
                lockSystem.AcquireLock("asteroid-spawning", false);
            }

            //We have the spawn lock, lets do stuff.
            if (lockSystem.LockIsOurs("asteroid-spawning"))
            {
                if (HighLogic.LoadedSceneIsFlight && !FlightGlobals.ready)
                {
                    return;
                }
                if (HighLogic.CurrentGame.flightState.protoVessels == null)
                {
                    return;
                }
                if (FlightGlobals.fetch.vessels == null)
                {
                    return;
                }
                if (HighLogic.CurrentGame.flightState.protoVessels.Count == 0)
                {
                    return;
                }
                if (FlightGlobals.fetch.vessels.Count == 0)
                {
                    return;
                }
                int beforeSpawn = GetAsteroidCount();
                if (beforeSpawn < maxNumberOfUntrackedAsteroids)
                {
                    ProtoVessel asty = SpawnAsteroid();
                    DarkLog.Debug("Spawned asteroid " + asty.vesselName + ", have " + (beforeSpawn) + ", need " + maxNumberOfUntrackedAsteroids);
                }
            }

            //Check for changes to tracking
            lock (serverAsteroids)
            {
                foreach (Vessel asteroid in GetCurrentAsteroids())
                {
                    if (asteroid.state != Vessel.State.DEAD)
                    {
                        if (!serverAsteroidTrackStatus.ContainsKey(asteroid.id))
                        {
                            serverAsteroidTrackStatus.Add(asteroid.id, asteroid.DiscoveryInfo.trackingStatus.Value);
                        }
                        else
                        {
                            if (asteroid.DiscoveryInfo.trackingStatus.Value != serverAsteroidTrackStatus[asteroid.id])
                            {
                                ProtoVessel pv = asteroid.BackupVessel();
                                DarkLog.Debug("Sending changed asteroid, new state: " + asteroid.DiscoveryInfo.trackingStatus.Value + "!");
                                serverAsteroidTrackStatus[asteroid.id] = asteroid.DiscoveryInfo.trackingStatus.Value;
                                networkWorker.SendVesselProtoMessage(pv, false, false);
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 6
0
        private void Update()
        {
            if (workerEnabled)
            {
                if (scenarioController == null)
                {
                    foreach (ProtoScenarioModule psm in HighLogic.CurrentGame.scenarios)
                    {
                        if (psm != null)
                        {
                            if (psm.moduleName == "ScenarioDiscoverableObjects")
                            {
                                if (psm.moduleRef != null)
                                {
                                    scenarioController = (ScenarioDiscoverableObjects)psm.moduleRef;
                                    scenarioController.spawnInterval = float.MaxValue;
                                }
                            }
                        }
                    }
                }

                if (scenarioController != null)
                {
                    if ((Client.realtimeSinceStartup - lastAsteroidCheck) > ASTEROID_CHECK_INTERVAL)
                    {
                        lastAsteroidCheck = Client.realtimeSinceStartup;
                        //Try to acquire the asteroid-spawning lock if nobody else has it.
                        if (!lockSystem.LockExists("asteroid-spawning"))
                        {
                            lockSystem.AcquireLock("asteroid-spawning", false);
                        }

                        //We have the spawn lock, lets do stuff.
                        if (lockSystem.LockIsOurs("asteroid-spawning"))
                        {
                            if ((HighLogic.CurrentGame.flightState.protoVessels != null) && (FlightGlobals.fetch.vessels != null))
                            {
                                if ((HighLogic.CurrentGame.flightState.protoVessels.Count == 0) || (FlightGlobals.fetch.vessels.Count > 0))
                                {
                                    int beforeSpawn      = GetAsteroidCount();
                                    int asteroidsToSpawn = maxNumberOfUntrackedAsteroids - beforeSpawn;
                                    for (int asteroidsSpawned = 0; asteroidsSpawned < asteroidsToSpawn; asteroidsSpawned++)
                                    {
                                        DarkLog.Debug("Spawning asteroid, have " + (beforeSpawn + asteroidsSpawned) + ", need " + maxNumberOfUntrackedAsteroids);
                                        scenarioController.SpawnAsteroid();
                                    }
                                }
                            }
                        }

                        //Check for changes to tracking
                        foreach (Vessel asteroid in GetCurrentAsteroids())
                        {
                            if (asteroid.state != Vessel.State.DEAD)
                            {
                                if (!serverAsteroidTrackStatus.ContainsKey(asteroid.id.ToString()))
                                {
                                    serverAsteroidTrackStatus.Add(asteroid.id.ToString(), asteroid.DiscoveryInfo.trackingStatus.Value);
                                }
                                else
                                {
                                    if (asteroid.DiscoveryInfo.trackingStatus.Value != serverAsteroidTrackStatus[asteroid.id.ToString()])
                                    {
                                        ProtoVessel pv = asteroid.BackupVessel();
                                        DarkLog.Debug("Sending changed asteroid, new state: " + asteroid.DiscoveryInfo.trackingStatus.Value + "!");
                                        serverAsteroidTrackStatus[asteroid.id.ToString()] = asteroid.DiscoveryInfo.trackingStatus.Value;
                                        networkWorker.SendVesselProtoMessage(pv, false, false);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 7
0
        private void Update()
        {
            if (!workerEnabled)
            {
                return;
            }
            if (Client.realtimeSinceStartup - lastAsteroidCheck < ASTEROID_CHECK_INTERVAL)
            {
                return;
            }
            else
            {
                lastAsteroidCheck = Client.realtimeSinceStartup;
            }
            if (!initialized)
            {
                InitializeScenario();
            }

            //Try to acquire the asteroid-spawning lock if nobody else has it.
            if (!lockSystem.LockExists("asteroid-spawning"))
            {
                lockSystem.AcquireLock("asteroid-spawning", false);
            }

            //We have the spawn lock, lets do stuff.
            if (lockSystem.LockIsOurs("asteroid-spawning"))
            {
                if ((HighLogic.CurrentGame.flightState.protoVessels != null) && (FlightGlobals.fetch.vessels != null))
                {
                    if ((HighLogic.CurrentGame.flightState.protoVessels.Count == 0) || (FlightGlobals.fetch.vessels.Count > 0))
                    {
                        int beforeSpawn      = GetAsteroidCount();
                        int asteroidsToSpawn = maxNumberOfUntrackedAsteroids - beforeSpawn;
                        if (asteroidsToSpawn > 0)
                        {
                            foreach (Vessel asty in SpawnAsteroids(1)) // spawn 1 every ASTEROID_CHECK_INTERVAL seconds
                            {
                                DarkLog.Debug("Spawned asteroid " + asty.name + ", have " + (beforeSpawn) + ", need " + maxNumberOfUntrackedAsteroids);
                            }
                        }
                    }
                }
            }

            //Check for changes to tracking
            foreach (Vessel asteroid in GetCurrentAsteroids())
            {
                if (asteroid.state != Vessel.State.DEAD)
                {
                    if (!serverAsteroidTrackStatus.ContainsKey(asteroid.id.ToString()))
                    {
                        serverAsteroidTrackStatus.Add(asteroid.id.ToString(), asteroid.DiscoveryInfo.trackingStatus.Value);
                    }
                    else
                    {
                        if (asteroid.DiscoveryInfo.trackingStatus.Value != serverAsteroidTrackStatus[asteroid.id.ToString()])
                        {
                            ProtoVessel pv = asteroid.BackupVessel();
                            DarkLog.Debug("Sending changed asteroid, new state: " + asteroid.DiscoveryInfo.trackingStatus.Value + "!");
                            serverAsteroidTrackStatus[asteroid.id.ToString()] = asteroid.DiscoveryInfo.trackingStatus.Value;
                            networkWorker.SendVesselProtoMessage(pv, false, false);
                        }
                    }
                }
            }
        }
Exemplo n.º 8
0
        private void OnVesselCreate(Vessel vessel)
        {
            ProtoVessel pv          = vessel.BackupVessel();
            List <uint> vesselParts = new List <uint>();
            bool        killShip    = false;
            bool        vesselOk    = false;

            foreach (ProtoPartSnapshot pps in pv.protoPartSnapshots)
            {
                if (pps.flightID == 0)
                {
                    loadGuid = vessel.id;
                    //When you spawn a new vessel in all the part ID's are 0 until OnFlightReady.
                    return;
                }
                vesselParts.Add(pps.flightID);
                if (partToVessel.ContainsKey(pps.flightID))
                {
                    killShip = true;
                    foreach (Vessel otherVessel in partToVessel[pps.flightID])
                    {
                        if (otherVessel.id == vessel.id)
                        {
                            vesselOk = true;
                        }
                        //Either of the locks are ours or neither of the locks exist
                        if (lockSystem.LockIsOurs("control-" + otherVessel.id) || lockSystem.LockIsOurs("update-" + otherVessel.id) || (!lockSystem.LockExists("control-" + otherVessel.id) && !lockSystem.LockExists("update-" + otherVessel.id)))
                        {
                            vesselOk = true;
                        }
                    }
                }
            }
            if (killShip && !vesselOk)
            {
                DarkLog.Debug("PartKiller: Destroying vessel fragment");
                vessel.Die();
            }
            else
            {
                vesselToPart.Add(vessel, vesselParts);
                foreach (uint partID in vesselParts)
                {
                    if (!partToVessel.ContainsKey(partID))
                    {
                        partToVessel.Add(partID, new List <Vessel>());
                    }
                    partToVessel[partID].Add(vessel);
                }
            }
        }