Ejemplo n.º 1
0
 public Dialog_Rename_Ship(Building_CustomShipComputerCore core)
 {
     this.shipcore = core;
     this.curName  = core.outputname;
 }
Ejemplo n.º 2
0
        private static List <String> saveShip(List <Building> list, List <String> errors)
        {
            Log.Message("SAVE SHIP STARTED");
            string saved_name = "ship_file_name";

            try
            {
                foreach (Building building in list)
                {
                    if (building.def == ThingDefOf.Ship_ComputerCore)
                    {
                        Log.Message("getting ship name");
                        Building_CustomShipComputerCore core = building as Building_CustomShipComputerCore;
                        saved_name = core.outputname;
                        Log.Message("ship name : " + saved_name);
                    }
                }
            }
            catch (Exception e)
            {
                Log.Message("CUSTOM_SHIP_COMPUTER_CORE is not valid");
                errors.Add("CUSTOM_SHIP_COMPUTER_CORE is not valid");
                Log.Message(e.Message);
            }

            if (saved_name == "")
            {
                saved_name = "ship_file_name";
            }

            string str1 = Path.Combine(GenFilePaths.SaveDataFolderPath, "Ships");

            str1.Replace('/', '\\');
            Log.Message("checking if folder exists : " + str1);
            if (!System.IO.Directory.Exists(str1))
            {
                Log.Message("creating folder : " + str1);
                System.IO.Directory.CreateDirectory(str1);
                Log.Message("folder created successfully");
            }

            int    num    = 0;
            string orstr2 = Path.Combine(str1, saved_name);

            Log.Message(orstr2);
            string str2 = orstr2 + ".rwship";

            while (System.IO.File.Exists(str2))
            {
                num++;
                str2 = orstr2 + num.ToString() + ".rwship";
            }

            Log.Message(str2);

            SafeSaver.Save(str2, "RWShip", (Action)(() =>
            {
                Log.Message("safesaver");
                ScribeMetaHeaderUtility.WriteMetaHeader();


                List <Pawn> launchedpawns = new List <Pawn>();
                foreach (Building building in list)
                {
                    if (building.def == ThingDefOf.Ship_CryptosleepCasket)
                    {
                        Building_CryptosleepCasket cask = building as Building_CryptosleepCasket;
                        if (cask.HasAnyContents)
                        {
                            Pawn pawn = cask.ContainedThing as Pawn;
                            launchedpawns.Add(pawn);
                        }
                    }
                }

                //start saving
                Scribe_Collections.Look <Building>(ref list, "buildings", LookMode.Deep);

                Scribe_Deep.Look <ResearchManager>(ref Current.Game.researchManager, false, "researchManager", new object[0]);
                Scribe_Deep.Look <UniqueIDsManager>(ref Current.Game.uniqueIDsManager, false, "uniqueIDsManager", new object[0]);
                Scribe_Deep.Look <DrugPolicyDatabase>(ref Current.Game.drugPolicyDatabase, false, "drugPolicyDatabase", new object[0]);
                Scribe_Deep.Look <OutfitDatabase>(ref Current.Game.outfitDatabase, false, "outfitDatabase", new object[0]);
                Scribe_Deep.Look <IdeoManager>(ref Current.Game.World.ideoManager, false, "ideo", new object[0]);
                //    Scribe_Deep.Look<TaleManager>(ref Current.Game.taleManager, false, "taleManager", new object[0]);
                //    Scribe_Deep.Look<PlayLog>(ref Current.Game.playLog, false, "playLog", new object[0]);


                int year = GenDate.YearsPassed;
                Log.Message("year:" + year);
                Scribe_Values.Look <int>(ref year, "currentyear", 0);

                List <Pawn> savedpawns = new List <Pawn>();
                List <Pawn> mappawns = Current.Game.CurrentMap.mapPawns.AllPawns.ToList();
                for (int i = 0; i < mappawns.Count; i++)
                {
                    Pawn p = mappawns[i];
                    if (p == null)
                    {
                        continue;
                    }
                    if (p.Destroyed)
                    {
                        continue;
                    }
                    if (p.Faction != Faction.OfPlayer)
                    {
                        continue;
                    }
                    if (launchedpawns.Contains(p))
                    {
                        continue;
                    }
                    Log.Message("rpawns:" + p.Name);
                    savedpawns.Add(p);
                }
                for (int i = 0; i < Current.Game.World.worldPawns.AllPawnsAliveOrDead.Count(); i++)
                {
                    Pawn efpawn = null;
                    try
                    {
                        Pawn pawn = Current.Game.World.worldPawns.AllPawnsAliveOrDead.ElementAt(i);
                        efpawn = pawn;
                        if (pawn == null)
                        {
                            continue;
                        }
                        if (pawn.Destroyed)
                        {
                            continue;
                        }
                        Log.Message("world pawn:" + pawn.Name);
                        if (pawn.Faction == Faction.OfPlayer)
                        {
                            Log.Message("colonistsaved:" + pawn.Name);
                            savedpawns.Add(pawn);
                            continue;
                        }

                        foreach (Pawn colonist in launchedpawns)
                        {
                            bool doo = false;
                            if (
                                pawn.relations.DirectRelationExists(PawnRelationDefOf.Bond, colonist) ||
                                pawn.relations.DirectRelationExists(PawnRelationDefOf.Lover, colonist) ||
                                pawn.relations.DirectRelationExists(PawnRelationDefOf.Parent, colonist) ||
                                pawn.relations.DirectRelationExists(PawnRelationDefOf.Child, colonist) ||
                                pawn.relations.DirectRelationExists(PawnRelationDefOf.ExSpouse, colonist) ||
                                pawn.relations.DirectRelationExists(PawnRelationDefOf.Spouse, colonist) ||
                                pawn.relations.DirectRelationExists(PawnRelationDefOf.Fiance, colonist))
                            {
                                doo = true;
                            }
                            if (pawn.relations.FamilyByBlood.Contains(colonist))
                            {
                                doo = true;
                            }
                            if (doo)
                            {
                                Log.Message("relativeof:" + colonist.Name);
                                pawn.SetFaction(Current.Game.World.factionManager.OfPlayer);
                                savedpawns.Add(pawn);
                                break;
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        Log.Error("ERROR AT PAWN");
                        Log.Error(e.Message);
                        errors.Add("ERROR AT PAWN");
                        errors.Add(e.Message);
                        try
                        {
                            Log.Message(efpawn.Name.ToString());
                            errors.Add(efpawn.Name.ToString());
                        }
                        catch (Exception innere)
                        {
                            Log.Error("cannot access its name");
                            errors.Add("cannot access its name");
                            Log.Message("innerebegin");
                            Log.Error(innere.Message);
                            Log.Message("innereend");
                        }
                    }
                }
                Log.Message("Finishing");
                Log.Message("Current.Game.World.worldPawns.AllPawnsAliveOrDead.Count:" + Current.Game.World.worldPawns.AllPawnsAliveOrDead.Count());

                Log.Message("savedpawns saving");
                Scribe_Collections.Look <Pawn>(ref savedpawns, "oldpawns", LookMode.Deep);
                Log.Message("savedpawns saved successfully");
            }));
            return(errors);
        }