예제 #1
0
 //Removes a frozen kerbal from the vessel.
 private bool RemoveKerbal(ProtoCrewMember kerbal, int SeatIndx)
 {
     try
     {
          Utilities.Log_Debug("RemoveKerbal " + kerbal.name + " seat " + SeatIndx);
         FrznCrewMbr tmpcrew = _StoredCrewList.Find(a => a.CrewName == kerbal.name);  // Find the thawed kerbal in the frozen kerbal list.
         if (tmpcrew == null)
         {
             FrznCrewMbr frzncrew = new FrznCrewMbr(kerbal.name, SeatIndx, vessel.id, vessel.name);
              Utilities.Log_Debug("Adding _StoredCrewList entry");
             _StoredCrewList.Add(frzncrew);
         }
         else
         {
              Utilities.Log("Found Kerbal in the stored frozen crew list for this part.");
              Utilities.Log("Crewmember:" + tmpcrew.CrewName + " Seat:" + tmpcrew.SeatIdx);
         }
         // Update the saved frozen kerbals dictionary
         KerbalInfo kerbalInfo = new KerbalInfo(Planetarium.GetUniversalTime());
         kerbalInfo.vesselID = CrntVslID;
         kerbalInfo.vesselName = CrntVslName;
         kerbalInfo.type = ProtoCrewMember.KerbalType.Unowned;
         kerbalInfo.status = ProtoCrewMember.RosterStatus.Dead;
         if (partHasInternals)
         {
             kerbalInfo.seatName = part.internalModel.seats[SeatIndx].seatTransformName;
             kerbalInfo.seatIdx = SeatIndx;
         }
         else
         {
             kerbalInfo.seatName = "Unknown";
             kerbalInfo.seatIdx = -1;
         }
         kerbalInfo.partID = CrntPartID;
         kerbalInfo.experienceTraitName = kerbal.experienceTrait.Title;
          Utilities.Log_Debug("Adding New Frozen Crew to dictionary");
         try
         {
             if (!DeepFreeze.Instance.DFgameSettings.KnownFrozenKerbals.ContainsKey(kerbal.name))
             {
                 DeepFreeze.Instance.DFgameSettings.KnownFrozenKerbals.Add(kerbal.name, kerbalInfo);
             }
             if (DeepFreeze.Instance.DFsettings.debugging) DeepFreeze.Instance.DFgameSettings.DmpKnownFznKerbals();
         }
         catch (Exception ex)
         {
              Utilities.Log("Unable to add to knownfrozenkerbals frozen crewmember " + kerbal.name);
              Utilities.Log("Err: " + ex);
             ScreenMessages.PostScreenMessage("DeepFreezer mechanical failure", 5.0f, ScreenMessageStyle.UPPER_CENTER);
             return false;
         }
         if (partHasInternals && ExternalDoorActive)
             Utilities.setHelmetshaders(kerbal.KerbalRef, true);
         // remove the CrewMember from the part crewlist and unregister their traits, because they are frozen, and this is the only way to trick the game.
         kerbal.UnregisterExperienceTraits(part);
         part.protoModuleCrew.Remove(kerbal);
         if (partHasInternals)
         {
             if (part.internalModel.seats[SeatIndx].kerbalRef != kerbal.KerbalRef)
             {
                 part.internalModel.seats[SeatIndx].kerbalRef = kerbal.KerbalRef;
                 setseatstaticoverlay(part.internalModel.seats[SeatIndx]);
             }
             part.internalModel.seats[SeatIndx].taken = true; // Set their seat to Taken, because they are really still there. :)
             seatTakenbyFrznKerbal[SeatIndx] = true;
         }
         // Set our newly frozen Popsicle, er Kerbal, to Unowned type (usually a Crew) and Dead status.
         kerbal.type = ProtoCrewMember.KerbalType.Unowned;
         kerbal.rosterStatus = ProtoCrewMember.RosterStatus.Dead;
         if (kerbal.KerbalRef != null)
         {
             //Remove them from the GUIManager Portrait cams.
             DFPortraits.DestroyPortrait(kerbal.KerbalRef);
         }
         return true;
     }
     catch (Exception ex)
     {
         Debug.Log("Remove Kerbal " + kerbal.name + " for DeepFreeze failed");
         Debug.Log("Err: " + ex);
         return false;
     }
 }
예제 #2
0
        internal void resetFrozenKerbals()
        {
            try
            {
                // Create a list of kerbals that are in Invalid Seats (SeatIndx == -1 where kerbal is in this part in this vessel & they are not comatose/tourist
                List<KeyValuePair<string, KerbalInfo>> kerbalsInvSeats = DeepFreeze.Instance.DFgameSettings.KnownFrozenKerbals.Where(e => e.Value.partID == CrntPartID && e.Value.vesselID == CrntVslID && e.Value.type != ProtoCrewMember.KerbalType.Tourist && e.Value.seatIdx == -1).ToList();
                // create a list of kerbal that are in this part in this vessel & they are not comatose/tourist
                List<KeyValuePair<string, KerbalInfo>> FrznKerbalsinPart = DeepFreeze.Instance.DFgameSettings.KnownFrozenKerbals.Where(e => e.Value.partID == CrntPartID && e.Value.vesselID == CrntVslID && e.Value.type != ProtoCrewMember.KerbalType.Tourist).ToList();

                //If we found any Invalid Seat assignments we need to find them empty seats
                if (kerbalsInvSeats.Any())
                {
                    bool[] seatIndxs = new bool[FreezerSize];  //Create a bool array to store whether seats are taken or not
                                                               //go through all the frozen kerbals in the part that don't have invalid seats and set bool array seat index to true (taken) for each
                    foreach (KeyValuePair<string, KerbalInfo> frznkerbal in FrznKerbalsinPart)
                    {
                        if (frznkerbal.Value.seatIdx > -1 && frznkerbal.Value.seatIdx < FreezerSize - 1)
                            seatIndxs[frznkerbal.Value.seatIdx] = true;
                    }
                    //go through all the thawed kerbals in the part and set bool array seat index to true (taken) for each
                    foreach (ProtoCrewMember crew in part.protoModuleCrew)
                    {
                        seatIndxs[crew.seatIdx] = true;
                    }
                    //Go through all our kerbals with invalid seats and find them an empty seat.
                    foreach (KeyValuePair<string, KerbalInfo> frznkerbal in kerbalsInvSeats)
                    {
                        //Iterate for the number of seats in the part
                        for (int i = 0; i < FreezerSize; i++)
                        {
                            if (seatIndxs[i] == false)  //If seat not already taken we take it
                            {
                                seatIndxs[i] = true;
                                frznkerbal.Value.seatIdx = i;
                                frznkerbal.Value.seatName = part.internalModel.seats[i].seatTransformName;
                                break;
                            }
                        }
                    }
                }

                // Iterate through the dictionary of all known frozen kerbals where kerbal is in this part in this vessel & they are not comatose/tourist
                foreach (KeyValuePair<string, KerbalInfo> kerbal in FrznKerbalsinPart)
                {
                    //Check if they are in the _StoredCrewList and if they aren't Add them in.
                    FrznCrewMbr fzncrew = new FrznCrewMbr(kerbal.Key, kerbal.Value.seatIdx, CrntVslID, CrntVslName);
                    FrznCrewMbr tmpcrew = _StoredCrewList.Find(a => a.CrewName == kerbal.Key);
                    if (tmpcrew == null)
                    {
                        //add them to our storedcrewlist for this part.
                        Utilities.Log_Debug("DeepFreezer Adding frozen kerbal to this part storedcrewlist " + kerbal.Key);
                        _StoredCrewList.Add(fzncrew);
                    }

                    //check if they are in the part and spawned, if not do so.
                    ProtoCrewMember crewmember = HighLogic.CurrentGame.CrewRoster.Unowned.FirstOrDefault(a => a.name == kerbal.Key);
                    if (crewmember != null)
                    {
                        if (partHasInternals)
                        {
                            crewmember.seatIdx = kerbal.Value.seatIdx;
                            if (crewmember.seatIdx != -1 && crewmember.seatIdx < FreezerSize)
                                crewmember.seat = part.internalModel.seats[crewmember.seatIdx];
                            if (crewmember.KerbalRef == null)
                            {
                                crewmember.Spawn();
                            }
                            crewmember.KerbalRef.transform.parent =
                                part.internalModel.seats[crewmember.seatIdx].seatTransform;
                            crewmember.KerbalRef.transform.localPosition = Vector3.zero;
                            crewmember.KerbalRef.transform.localRotation = Quaternion.identity;
                            crewmember.KerbalRef.InPart = null;
                            if (ExternalDoorActive)
                            {
                                //set the seat to allow helmet, this will cause the helmet to appear
                                crewmember.KerbalRef.showHelmet = true;
                            }
                            else
                            {
                                crewmember.KerbalRef.showHelmet = false;
                                crewmember.KerbalRef.ShowHelmet(false);
                            }
                            seatTakenbyFrznKerbal[crewmember.seatIdx] = true;
                            //setup seat and part settings for frozen kerbal.
                            Utilities.setFrznKerbalLayer(part, crewmember, false);
                            part.internalModel.seats[crewmember.seatIdx].taken = true;
                            part.internalModel.seats[crewmember.seatIdx].kerbalRef = crewmember.KerbalRef;
                            part.internalModel.seats[crewmember.seatIdx].crew = crewmember;
                            setseatstaticoverlay(part.internalModel.seats[crewmember.seatIdx]);
                        }
                        //Unregister their traits/abilities and remove them from the Portrait Cameras if they are there.
                        crewmember.UnregisterExperienceTraits(part);
                        part.protoModuleCrew.Remove(crewmember);
                        DFPortraits.DestroyPortrait(crewmember.KerbalRef);
                    }
                    else
                    {
                        Utilities.Log("DeepFreezer Error attempting to resetFrozenKerbal {0}, cannot find them in the Roster", kerbal.Key);
                    }
                }
            }
            catch (Exception ex)
            {
                Utilities.Log("DeepFreezer Error attempting to resetFrozenKerbals, Critical ERROR, Report on the forum");
                Utilities.Log(ex.Message);
            }
        }