public void PercentageResearch() { var mod = Mod.Current; var gal = Galaxy.Current; var tech = mod.Technologies.FindByName("Ice Planet Colonization"); tech.LevelCost = 500000; // in case the mod changes tech.MaximumLevel = 5; // so we can actually test getting past level 1 // TODO - allocate to multiple techs emp.ResearchedTechnologies[tech] = 0; emp.BonusResearch = tech.GetBaseLevelCost(1) + tech.GetBaseLevelCost(2); var cmd = new ResearchCommand(); cmd.Issuer = emp; cmd.Executor = emp; cmd.Spending[tech] = 100; // check command client safety cmd.CheckForClientSafety(); // perform research emp.ResearchCommand = cmd; Galaxy.ProcessTurn(false); // verify research was done // 500K for first level, 1M for second Assert.AreEqual(2, emp.ResearchedTechnologies[tech]); }
public void QueuedResearch() { // for convenience var mod = Mod.Current; var gal = Galaxy.Current; // set up techs var t1 = mod.Technologies.FindByName("Planetary Weapons"); t1.LevelCost = 5000; // in case the mod changes var t2 = mod.Technologies.FindByName("Smaller Weapons"); t2.LevelCost = 5000; // in case the mod changes emp.AccumulatedResearch[t1] = 1000; // make sure to test spillover properly // reset tech levels emp.ResearchedTechnologies[t1] = 0; emp.ResearchedTechnologies[t2] = 0; // give them some RP emp.BonusResearch = t1.GetBaseLevelCost(1) + 1; // create research command var cmd = new ResearchCommand { Issuer = emp, Executor = emp, }; cmd.Queue.Add(t1); cmd.Queue.Add(t2); // perform research emp.ResearchCommand = cmd; Galaxy.ProcessTurn(false); // should have level 1 in t1 and level 0 in t2 Assert.AreEqual(1, emp.ResearchedTechnologies[t1]); Assert.AreEqual(0, emp.ResearchedTechnologies[t2]); // should have no spillover in t1 and 1001 points in t2 Assert.AreEqual(0, emp.GetResearchProgress(t1, 2).Value); Assert.AreEqual(1001, emp.GetResearchProgress(t2, 1).Value); // another turn! emp.BonusResearch = 100000; emp.ResearchCommand = cmd; Galaxy.ProcessTurn(false); // should have level 2+ in t1 and level 1+ in t2 // (levels could be higher if extra RP gets randomly assigned to those techs) Assert.IsTrue(2 <= emp.ResearchedTechnologies[t1], $"{t1} level should be at least 2"); Assert.IsTrue(1 <= emp.ResearchedTechnologies[t2], $"{t2} level should be at least 1"); }
private void Save() { var cmd = new ResearchCommand(); cmd.Spending.Clear(); foreach (var kvp in Empire.Current.ResearchSpending) { cmd.Spending[kvp.Key] = kvp.Value; } cmd.Queue.Clear(); foreach (var tech in Empire.Current.ResearchQueue) { cmd.Queue.Add(tech); } Empire.Current.ResearchCommand = cmd; }
/// <Summary> /// The OK button has been pressed. Just exit the dialog. /// </Summary> /// <param name="sender">The source of the event.</param> /// <param name="e">A <see cref="EventArgs"/> that contains the event data.</param> private void OKClicked(object sender, EventArgs e) { //Generate a research command to describe the changes. ResearchCommand command = new ResearchCommand(); command.Budget = (int)budgetPercentage.Value; command.Topics.Zero(); command.Topics[targetArea] = 1; if (command.IsValid(clientState.EmpireState)) { clientState.Commands.Push(command); command.ApplyToState(clientState.EmpireState); } // This is done for synchronization. We wait for the event handlers // to return something (and thus complete) before closing the Form and invalidating // all event handlers and delegates thus crashing everything into the fiery void of despair. if (ResearchAllocationChangedEvent()) { } Close(); }
/// <Summary> /// Manage research. /// Only changes research field after completing the previous research level. /// </Summary> private void HandleResearch() { // Generate a research command to describe the changes. ResearchCommand command = new ResearchCommand(); command.Topics.Zero(); // Set the percentage of production to dedicate to research command.Budget = 0; // check if messages contains info about tech advence. Could be more than one, so use a flag to prevent setting the research level multiple times. bool hasAdvanced = false; foreach (Message msg in clientState.Messages) { if (!string.IsNullOrEmpty(msg.Type) && msg.Type == "TechAdvance") //// if (!string.IsNullOrEmpty(msg.Type) && msg.Text.Contains("Your race has advanced to Tech Level") == true) // can be removed if the previous line works { hasAdvanced = true; } } if (hasAdvanced) { // pick next topic int minLevel = int.MaxValue; Nova.Common.TechLevel.ResearchField targetResearchField = TechLevel.ResearchField.Weapons; // default to researching weapons if (clientState.EmpireState.ResearchLevels[TechLevel.ResearchField.Propulsion] < 3) { // Prop 3 - Long Hump 6 - Warp 6 engine (or fuel mizer at Prop 2) targetResearchField = TechLevel.ResearchField.Propulsion; } else if (clientState.EmpireState.ResearchLevels[TechLevel.ResearchField.Electronics] < 1) { // Elec 1 - Rhino Scanner - 50 ly scan targetResearchField = TechLevel.ResearchField.Electronics; } else if (clientState.EmpireState.ResearchLevels[TechLevel.ResearchField.Construction] < 3) { // Cons 3 - Destroyer & Medium Freighter targetResearchField = TechLevel.ResearchField.Construction; } else if (clientState.EmpireState.ResearchLevels[TechLevel.ResearchField.Electronics] < 5) { // Elec 5 - Scanners targetResearchField = TechLevel.ResearchField.Electronics; } else if (clientState.EmpireState.ResearchLevels[TechLevel.ResearchField.Weapons] < 6) { // Wep 6 - Beta Torp (@5) and Yakimora Light Phaser targetResearchField = TechLevel.ResearchField.Weapons; } else if (clientState.EmpireState.ResearchLevels[TechLevel.ResearchField.Propulsion] < 7) { // Prop 7 - Warp 8 engine targetResearchField = TechLevel.ResearchField.Propulsion; } else if (clientState.EmpireState.ResearchLevels[TechLevel.ResearchField.Construction] < 6) { // Cons 6 - Frigate targetResearchField = TechLevel.ResearchField.Construction; } else if (clientState.EmpireState.ResearchLevels[TechLevel.ResearchField.Biotechnology] < 4) { // Bio 4 - Unlock terraform and prep for mines targetResearchField = TechLevel.ResearchField.Biotechnology; } else if (clientState.EmpireState.ResearchLevels[TechLevel.ResearchField.Energy] < 3) { // Energy 3 - Mines and shields targetResearchField = TechLevel.ResearchField.Energy; } else if (clientState.EmpireState.ResearchLevels[TechLevel.ResearchField.Construction] < 9) { // Cons 9 - Cruiser targetResearchField = TechLevel.ResearchField.Construction; } else if (clientState.EmpireState.ResearchLevels[TechLevel.ResearchField.Energy] < 6) { // Energy 6 - Shields targetResearchField = TechLevel.ResearchField.Energy; } else if (clientState.EmpireState.ResearchLevels[TechLevel.ResearchField.Weapons] < 12) { // Weapons 12 - Jihad Missile targetResearchField = TechLevel.ResearchField.Weapons; } else if (clientState.EmpireState.ResearchLevels[TechLevel.ResearchField.Construction] < 13) { // Cons 13 - Battleships targetResearchField = TechLevel.ResearchField.Construction; } else if (clientState.EmpireState.ResearchLevels[TechLevel.ResearchField.Energy] < 11) { // Energy 11 - Bear Neutrino at 10, and unlocks Syncro Sapper (need weapons 21) targetResearchField = TechLevel.ResearchField.Energy; } else if (clientState.EmpireState.ResearchLevels[TechLevel.ResearchField.Electronics] < 11) { // Elect 11 - Jammer 20 and Super Computer targetResearchField = TechLevel.ResearchField.Electronics; } else if (clientState.EmpireState.ResearchLevels[TechLevel.ResearchField.Propulsion] < 12) { // Prop 12 - Warp 10 and Overthruster targetResearchField = TechLevel.ResearchField.Propulsion; } else if (clientState.EmpireState.ResearchLevels[TechLevel.ResearchField.Biotechnology] < 7) { // Bio 7 maybe - scanners, Anti-matter generator, smart bombs targetResearchField = TechLevel.ResearchField.Biotechnology; } else if (clientState.EmpireState.ResearchLevels[TechLevel.ResearchField.Weapons] < 24) { // Weapons 24 - research all remaining weapons technologies targetResearchField = TechLevel.ResearchField.Weapons; } else if (clientState.EmpireState.ResearchLevels[TechLevel.ResearchField.Construction] < 26) { // Cons 26 - Nubian targetResearchField = TechLevel.ResearchField.Construction; } else if (clientState.EmpireState.ResearchLevels[TechLevel.ResearchField.Electronics] < 19) { // Elect 19 - Battle nexus targetResearchField = TechLevel.ResearchField.Electronics; } else if (clientState.EmpireState.ResearchLevels[TechLevel.ResearchField.Energy] < 22) { // Energy 22 - Complete Phase Shield targetResearchField = TechLevel.ResearchField.Energy; } else if (clientState.EmpireState.ResearchLevels[TechLevel.ResearchField.Propulsion] < 23) { // Prop 23 - Trans-Star 10 targetResearchField = TechLevel.ResearchField.Propulsion; } else if (clientState.EmpireState.ResearchLevels[TechLevel.ResearchField.Biotechnology] < 10) { // Bio 10 - RNA Scanner targetResearchField = TechLevel.ResearchField.Biotechnology; } else { // research lowest tech field for (TechLevel.ResearchField field = TechLevel.FirstField; field <= TechLevel.LastField; field++) { if (clientState.EmpireState.ResearchLevels[field] < minLevel) { minLevel = clientState.EmpireState.ResearchLevels[field]; targetResearchField = field; } } } command.Topics[targetResearchField] = 1; } if (command.IsValid(clientState.EmpireState)) { clientState.Commands.Push(command); command.ApplyToState(clientState.EmpireState); } }