Hmm...I've a suggestion for you. It seems, from your code, that you plan to make adding more machines less of a bother. All well and good, however, I believe I've a method that'd work better, and allow you to design a tool that'd let you easily (and quickly) create new machines that can be plugged into the program at runtime. My suggestion involves serialization. Basically, what you'd have is a single class that'd represent a generic machine: a name, EU/t output, configurable output, etc. Something like...
Code:using System; using System.Text; using System.Runtime.Serialization; using System.Runtime.Serialization.Formatters.Binary; [Serializable()] public sealed class Machine : ISerializable { public string Name; public int EUOut; public bool ConfigOutput; //Can the optput be configured by the user? public Machine() { this.Name = "Generic Machine"; this.EUOut = 16; this.ConfigOutput = false; } public Machine( Machine other ) { this.Name = other.Name; this.EUOut = other.EUOut; this.ConfigOutput = other.ConfigOutput; } // Deserialization constructor, this is called // when we use the deserialization method in // our main program code, as detailed later. public Machine( SerializationInfo info, StreamingContext ctxt ) { this.Name = (string) info.GetValue( "Name", typeof( string ) ); this.EUOut = (int ) info.GetValue( "EUOut", typeof( int ) ); this.ConfigOutput = (bool ) info.GetValue( "ConfigOutput", typeof( bool ) ); } // Serialization function. This is called // automatically when we use the serialization // method in the tool code, as detailed later. public void GetObjectData( Serialization info, StreamingContext ctxt ) { info.AddValue( "Name", this.Name ); info.AddValue( "EUOut", this.EUOut ); info.AddValue( "ConfigOutput", this.ConfigOutput ); } }
Now, when you get to your actual form/tool code, you'd want somethin like...
Code:// Form code for deserialization. // Requires System.Runtime.Serialization, // System.Runtime.Serialization.Formatters.Binary, and // System.IO Stream stream = File.Open( filename, FileMode.Open ); BinaryFormatter formatter = new BinaryFormatter(); Machine machine = (Machine) formatter.Deserialize( stream ); // Tool code for serialization. Has the // same requirements as deserialization. // Assumes you have a local variable called // "machine" of type Machine. Stream stream = File.Open( filename, FileMode.OpenOrCreate ); BinaryFormatter formatter = new BinaryFormatter(); formatter.Serialize( stream, machine );
Probably know all this, but I figured I'd throw in my $0.02. I've used this method before with several projects, and lemme tell ya, it saves a lot of time and frustration when it comes to scripting your programs and making 'em more flexible.
Thank you for the suggestion - I've thought of this, but I decided to do a multidimensional array instead (For now).
I've made two array that handle IC2/Greg machines separately - At the moment my goal is to show EU/t total, and maybe in the future total amount of EU produced (Example - When a certain generator receives a certain fuel, it produces more EU within those ticks.)
So in that thought - When I eventually do allow the ability to show total EU, along with being able to change fuels... I might look into serialization again, or trying reading XML files that contain modifiers.
At this moment of development, I want to code functionality, and then improve it later. I did however change my system on adding machines, and assigning their max EU/t outputs.