/// <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); } }