Example #1
0
        static void Postfix()
        {
#if DEBUG
            Log.Warning("Patch_Page_SelectScenario_PreOpen Postfix");
#endif
            ResearchTimeUtil.ResetResearchFactor();
        }
Example #2
0
 public static void UpdateFactor(float newFactor)
 {
     if (CurrentFactor != newFactor)
     {
         ResearchTimeUtil.ApplyFactor(newFactor, true, CurrentFactor);
         CurrentFactor = newFactor;
     }
 }
Example #3
0
        public static void InitializeNewGame()
        {
            Settings.GameFactor.Copy(Settings.GlobalFactor);
            CurrentFactor = Settings.GameFactor.AsFloat;
            ResearchTimeUtil.ApplyFactor(CurrentFactor, true);
#if DEBUG
            Log.Warning("InitializeNewGame: Global: " + Settings.GlobalFactor.AsString + " Game: " + Settings.GameFactor.AsString);
#endif
        }
Example #4
0
        public override void DoSettingsWindowContents(Rect rect)
        {
            GUI.BeginGroup(new Rect(0, 60, 600, 200));
            {
                Text.Font = GameFont.Medium;
                Widgets.Label(new Rect(0, 0, 300, 40), "ChangeResearchSpeed.Global".Translate());

                Text.Font = GameFont.Small;
                Widgets.Label(new Rect(0, 40, 300, 20), "ChangeResearchSpeed.Factor".Translate() + ":");

                Settings.GlobalFactor.AsString = Widgets.TextField(new Rect(320, 40, 100, 20), Settings.GlobalFactor.AsString);

                if (Widgets.ButtonText(new Rect(320, 65, 100, 20), "ChangeResearchSpeed.Apply".Translate()))
                {
                    if (Settings.GlobalFactor.ValidateInput())
                    {
                        base.GetSettings <Settings>().Write();
                        Messages.Message("ChangeResearchSpeed.Global".Translate() + " " + "ChangeResearchSpeed.ResearchTimesUpdated".Translate(),
                                         MessageTypeDefOf.PositiveEvent);
                    }
                }

                if (Current.Game != null)
                {
                    Text.Font = GameFont.Medium;
                    Widgets.Label(new Rect(0, 90, 300, 40), "ChangeResearchSpeed.CurrentGame".Translate());

                    Text.Font = GameFont.Small;
                    Widgets.Label(new Rect(0, 130, 300, 20), "ChangeResearchSpeed.Factor".Translate() + ":");

                    Settings.GameFactor.AsString = Widgets.TextField(new Rect(320, 130, 100, 20), Settings.GameFactor.AsString);

                    if (Widgets.ButtonText(new Rect(320, 155, 100, 20), "ChangeResearchSpeed.Apply".Translate()))
                    {
                        if (Settings.GameFactor.ValidateInput())
                        {
                            WorldComp.UpdateFactor(Settings.GameFactor.AsFloat);
                            Messages.Message(
                                "ChangeResearchSpeed.CurrentGame".Translate() + " " + "ChangeResearchSpeed.ResearchTimesUpdated".Translate(),
                                MessageTypeDefOf.PositiveEvent);
                        }
                    }
                }
            }
            GUI.EndGroup();

            Listing_Standard l = new Listing_Standard(GameFont.Small);

            l.BeginScrollView(new Rect(0, 300, rect.width, rect.height - 300), ref scroll, ref view);
            //l.Begin(new Rect(0, 300, 400, 300));
            l.ColumnWidth = rect.width - 100;
            l.CheckboxLabeled(
                "ChangeResearchSpeed.AllowTechAdvance".Translate(),
                ref Settings.AllowTechAdvance,
                "ChangeResearchSpeed.AllowTechAdvanceToolTip".Translate());
            if (Settings.AllowTechAdvance)
            {
                l.CheckboxLabeled("ChangeResearchSpeed.StaticNumberResearchPerTier".Translate(), ref Settings.StaticNumberResearchPerTier);
                if (Settings.StaticNumberResearchPerTier)
                {
                    neolithicInput  = l.TextEntryLabeled("ChangeResearchSpeed.NeolithicNeeded".Translate() + ":  ", neolithicInput);
                    medievalInput   = l.TextEntryLabeled("ChangeResearchSpeed.MedievalNeeded".Translate() + ":  ", medievalInput);
                    industrialInput = l.TextEntryLabeled("ChangeResearchSpeed.IndustrialNeeded".Translate() + ":  ", industrialInput);
                    spacerInput     = l.TextEntryLabeled("ChangeResearchSpeed.SpacerNeeded".Translate() + ":  ", spacerInput);
                }

                Rect c = l.GetRect(32f);
                if (Widgets.ButtonText(new Rect(c.xMin, c.yMin, 100, c.height), "Confirm".Translate()))
                {
                    if (!int.TryParse(neolithicInput, out Settings.NeolithicNeeded))
                    {
                        Messages.Message("ChangeResearchSpeed.InvalidNeolithicInput".Translate(), MessageTypeDefOf.RejectInput);
                        return;
                    }

                    if (!int.TryParse(medievalInput, out Settings.MedievalNeeded))
                    {
                        Messages.Message("ChangeResearchSpeed.InvalidMedievalInput".Translate(), MessageTypeDefOf.RejectInput);
                        return;
                    }

                    if (!int.TryParse(industrialInput, out Settings.IndustrialNeeded))
                    {
                        Messages.Message("ChangeResearchSpeed.InvalidIndustrialInput".Translate(), MessageTypeDefOf.RejectInput);
                        return;
                    }

                    if (!int.TryParse(spacerInput, out Settings.SpacerNeeded))
                    {
                        Messages.Message("ChangeResearchSpeed.InvalidSpacerInput".Translate(), MessageTypeDefOf.RejectInput);
                        return;
                    }

                    Messages.Message("ChangeResearchSpeed.ResearchNeededSet".Translate(), MessageTypeDefOf.PositiveEvent);
                }

                if (Widgets.ButtonText(new Rect(c.xMax - 100, c.yMin, 100, c.height), "ChangeResearchSpeed.Default".Translate()))
                {
                    Settings.NeolithicNeeded  = Settings.DEFAULT_NEOLITHIC_NEEDED;
                    Settings.MedievalNeeded   = Settings.DEFAULT_MEDIEVAL_NEEDED;
                    Settings.IndustrialNeeded = Settings.DEFAULT_INDUSTRIAL_NEEDED;
                    Settings.SpacerNeeded     = Settings.DEFAULT_SPACER_NEEDED;

                    neolithicInput  = Settings.NeolithicNeeded.ToString();
                    medievalInput   = Settings.MedievalNeeded.ToString();
                    industrialInput = Settings.IndustrialNeeded.ToString();
                    spacerInput     = Settings.SpacerNeeded.ToString();

                    Messages.Message("ChangeResearchSpeed.ResearchNeededDefaulted".Translate(), MessageTypeDefOf.PositiveEvent);
                }
            }

            l.CheckboxLabeled(
                "ChangeResearchSpeed.ChangeBaseCosts".Translate(),
                ref Settings.ChangeBaseCosts,
                "ChangeResearchSpeed.ChangeBaseCostsToolTip".Translate());
            if (Settings.ChangeBaseCosts)
            {
                if (techValues == null)
                {
                    techValues = new Dictionary <string, string>();
                }
                var techs = ResearchTimeUtil.GetResearchBaseCosts();
                foreach (var tech in techs.Keys)
                {
                    var techDef = ResearchTimeUtil.GetResearchDef(tech);
                    if (techDef != null)
                    {
                        float  cost;
                        string value;
                        if ((value = techValues.TryGetValue(tech, null)) == null)
                        {
                            if (Settings.ResearchBaseCosts.TryGetValue(tech, out cost))
                            {
                                value = ((int)cost).ToString();
                            }
                            else
                            {
                                value = techDef.baseCost.ToString();
                            }
                            techValues.Add(tech, value);
                        }

                        value = l.TextEntryLabeled(techDef.LabelCap + "(default: " + techs[tech] + ")", value);
                        int costInt;
                        if (int.TryParse(value, out costInt) && costInt >= 100)
                        {
                            if (costInt != (int)techDef.baseCost)
                            {
                                ResearchTimeUtil.ChangeBaseCost(techDef, costInt);
                            }
                            if (Settings.ResearchBaseCosts.ContainsKey(tech))
                            {
                                Settings.ResearchBaseCosts[tech] = costInt;
                            }
                            else
                            {
                                Settings.ResearchBaseCosts.Add(tech, costInt);
                            }
                        }

                        techValues[tech] = value;
                    }
                }
            }

            //l.End();
            l.EndScrollView(ref view);
        }
Example #5
0
        public override void ExposeData()
        {
            base.ExposeData();
            Scribe_Values.Look <string>(ref (GlobalFactor.AsString), "ChangeResearchSpeed.Factor", "1.00", false);
            Scribe_Values.Look <bool>(ref AllowTechAdvance, "ChangeResearchSpeed.AllowTechAdvance", false, false);
            Scribe_Values.Look <bool>(ref StaticNumberResearchPerTier, "ChangeResearchSpeed.StaticNumberResearchPerTier", false, false);
            Scribe_Values.Look <int>(ref NeolithicNeeded, "ChangeResearchSpeed.NeolithicNeeded", DEFAULT_NEOLITHIC_NEEDED, false);
            Scribe_Values.Look <int>(ref MedievalNeeded, "ChangeResearchSpeed.MedievalNeeded", DEFAULT_MEDIEVAL_NEEDED, false);
            Scribe_Values.Look <int>(ref IndustrialNeeded, "ChangeResearchSpeed.IndustrialNeeded", DEFAULT_INDUSTRIAL_NEEDED, false);
            Scribe_Values.Look <int>(ref SpacerNeeded, "ChangeResearchSpeed.SpacerNeeded", DEFAULT_SPACER_NEEDED, false);
            Scribe_Values.Look <bool>(ref ChangeBaseCosts, "ChangeResearchSpeed.ChangeBaseCosts", false, false);

            if (ResearchTimeUtil.ResearchBaseCostsExists())
            {
                foreach (var tech in ResearchTimeUtil.GetResearchBaseCosts())
                {
                    float cost;
                    if (!ResearchBaseCosts.TryGetValue(tech.Key, out cost))
                    {
                        cost = tech.Value;
                        ResearchBaseCosts.Add(tech.Key, cost);
                    }

                    Scribe_Values.Look <float>(ref cost, tech.Key, tech.Value, false);
                    ResearchBaseCosts[tech.Key] = cost;
                }
            }
            else
            {
                if (Scribe.mode == LoadSaveMode.LoadingVars)
                {
                    var settingsNode = Scribe.loader.curXmlParent;
                    for (int i = 0; i < settingsNode.ChildNodes.Count; i++)
                    {
                        var node        = settingsNode.ChildNodes[i];
                        var techDefName = node.Name;
                        if (!techDefName.Contains("ChangeResearchSpeed"))
                        {
                            float cost = 0;
                            Scribe_Values.Look <float>(ref cost, techDefName);
                            ResearchBaseCosts.Add(techDefName, cost);
                        }
                    }
                }

                //foreach (var tech in DefDatabase<ResearchProjectDef>.AllDefsListForReading)
                //{
                //	float cost;
                //	if (!ResearchBaseCosts.TryGetValue(tech.defName, out cost))
                //	{
                //		cost = tech.baseCost;
                //		ResearchBaseCosts.Add(tech.defName, cost);
                //	}

                //	Log.Warning("CRS: " + tech.defName+ " baseCost before: " + cost);
                //	Scribe_Values.Look<float>(ref cost, tech.defName, tech.baseCost, false);
                //	Log.Warning("CRS: " + tech.defName + " baseCost after: " + cost);
                //	ResearchBaseCosts[tech.defName] = cost;
                //}
            }
        }
Example #6
0
        public override void ExposeData()
        {
            base.ExposeData();

            List <string> completed = new List <string>();

            if (Scribe.mode == LoadSaveMode.Saving)
            {
                // Populated the completed research
                foreach (ResearchProjectDef def in DefDatabase <ResearchProjectDef> .AllDefs)
                {
                    if (def.IsFinished)
                    {
                        completed.Add(def.defName);
                    }
                }
            }
#if DEBUG
            Log.Warning(Scribe.mode + " Pre " + completed.Count);
#endif

            Scribe_Values.Look <float>(ref CurrentFactor, "ModifyResearchTime.Factor", 1f, false);
            try
            {
                Scribe_Collections.Look(ref completed, "ModifyResearchTime.Completed", LookMode.Value);
            }
            catch
            {
                completed = null;
            }

#if DEBUG
            Log.Warning(Scribe.mode + " Post " + completed.Count);
#endif

            Settings.GameFactor.AsFloat = CurrentFactor;

            if (Scribe.mode == LoadSaveMode.LoadingVars && completed != null)
            {
                // Create the completed research lookup
                completedLookup = new Dictionary <string, bool>();
                foreach (string c in completed)
                {
                    completedLookup[c] = true;
                }
                completed.Clear();
                completed = null;
            }
            else if (Scribe.mode == LoadSaveMode.PostLoadInit)
            {
                // Use the completed research lookup to make the completed research as finished
                CurrentFactor = Settings.GameFactor.AsFloat;
                ResearchTimeUtil.ApplyFactor(CurrentFactor, false);

                foreach (ResearchProjectDef def in DefDatabase <ResearchProjectDef> .AllDefs)
                {
                    if (completedLookup.ContainsKey(def.defName))
                    {
#if DEBUG
                        Log.Warning("Completed: " + def.defName);
#endif
                        Find.ResearchManager.FinishProject(def, false);
                    }
                }
                completedLookup.Clear();
                completedLookup = null;
            }
        }
Example #7
0
        static void Postfix()
        {
            if (Settings.AllowTechAdvance == true)
            {
                TechLevel currentTechLevel = Faction.OfPlayer.def.techLevel;
#if DEBUG
                Log.Warning("Tech Level: " + currentTechLevel);
#endif
                int totalCurrentAndPast = 0;
                int finishedResearch    = 0;

                foreach (ResearchProjectDef def in DefDatabase <ResearchProjectDef> .AllDefs)
                {
                    if (def.IsFinished)
                    {
                        ++finishedResearch;
                        //if (def.techLevel <= currentTechLevel)
                        //    ++finishedCurrentAndPast;
                        //else
                        //    ++finishedFuture;
                    }


                    if (def.techLevel <= currentTechLevel)
                    {
                        ++totalCurrentAndPast;
                    }
                }

                int  neededTechsToAdvance = 0;
                bool useStatisPerTier     = Settings.StaticNumberResearchPerTier;
                if (useStatisPerTier)
                {
                    switch (Faction.OfPlayer.def.techLevel)
                    {
                    case TechLevel.Neolithic:
                        neededTechsToAdvance = Settings.NeolithicNeeded;
                        break;

                    case TechLevel.Medieval:
                        neededTechsToAdvance = Settings.MedievalNeeded;
                        break;

                    case TechLevel.Industrial:
                        neededTechsToAdvance = Settings.IndustrialNeeded;
                        break;

                    case TechLevel.Spacer:
                        neededTechsToAdvance = Settings.SpacerNeeded;
                        break;
                    }
                }

#if DEBUG
                Log.Warning("Current Tech Level: " + Faction.OfPlayer.def.techLevel);
                Log.Warning("neededTechsToAdvance: " + neededTechsToAdvance);
                Log.Warning("totalCurrentAndPast: " + totalCurrentAndPast);
                Log.Warning("finishedResearch: " + finishedResearch);
#endif

                if ((useStatisPerTier && neededTechsToAdvance < finishedResearch) ||
                    (!useStatisPerTier && totalCurrentAndPast + 1 < finishedResearch))
                {
                    if (Faction.OfPlayer.def.techLevel < TechLevel.Spacer)
                    {
                        if (Scribe.mode == LoadSaveMode.Inactive)
                        {
                            // Only display this message is not loading
                            Messages.Message(
                                "Advancing Tech Level from [" + currentTechLevel.ToString() + "] to [" + (currentTechLevel + 1).ToString() + "].",
                                MessageTypeDefOf.PositiveEvent);
                        }

                        Faction.OfPlayer.def.techLevel = currentTechLevel + 1;
                    }
                }
                else
                {
                    int needed = (useStatisPerTier) ? neededTechsToAdvance - finishedResearch : totalCurrentAndPast + 1 - finishedResearch;
                    Log.Message("Tech Advance: Need to research [" + needed + "] more technologies");
                }
            }
            if (Settings.ChangeBaseCosts)
            {
                foreach (var cost in Settings.ResearchBaseCosts)
                {
                    var techDef = ResearchTimeUtil.GetResearchDef(cost.Key);
                    if (techDef != null)
                    {
                        techDef.baseCost = cost.Value;
                    }
                }
            }
        }