Hey guys,
So there needs to be a bit of back story for you to understand this one, and I'll try to keep it as minimal as possible.
So I'm a moderate modded minecraft player these days, and I've taken quite the fancy to a mod named RotaryCraft. However, this mod is quite mathematically intensive compared to many other minecraft mods, and so therefore many players dislike it because of this. However its gameplay is awesome and I'm sure many more players would enjoy it if they didn't have to worry so much about the mathematical side of it. The maths itself is really quite simple, however many play minecraft to relax and *not* use their brain.
Now, RotaryCraft has a series of engines that output a specific amount of speed (measured in Rad/s) and torque (measured in Nm) which when multiplied together give the engine's total power output in Watts. But this is not the problem.
RotaryCraft's main set of mechanics rely on using gearboxes to modify the torque or speed outputs of each engine according to what the engine is required to power. For example, a Pulse Jet Furnace from RotaryCraft requires 131072 Rad/s of speed to run, but has no torque requirement.
This means that there are a series of gearboxes in the mod that allow you to change the torque and speed. These gearboxes come in the ratios of 2:1, 4:1, 8:1, 16:1 and 32:1. However, most of the time it's not just using gearboxes to achieve the desired result, it also requires up to 4 of the same engine in order to achieve certain results. This is done using a shaft junction, and only 4 engines may be chained at any given time. Different engines cannot be chained for obvious reasons (we're talking about shafts here, try merging the speeds of two different shafts and see what happens.). Using shaft junctions will multiply the outputted torque by the number of engines being used.
Here comes the fun part.
What I want this program to do, is calculate what gearbox ratios are required to reach a user inputted speed or torque, and output this, along with what engines were used to achieve that result.
I've already written some dictionaries containing all the necessary values, and I've written a Gearbox method that *should* deal with the ratios. But now I need the program to loop over all the engines, take each engine's speed and torque, and attempt to achieve the user inputted value. Of course if the value is unattainable from any engine, it will output this as well.
Another important thing to note is that more than 1 gearbox can be used, and they multiply. Meaning that I could chain a 2:1 and a 4:1 gearbox to achieve the same result as an 8:1 gearbox. This becomes more relevant once you start needing ratios of like 512:1. (A 32:1 and a 16:1 would achieve this).
Here's the code I've got so far, and it also has all the power information for each engine.
So there needs to be a bit of back story for you to understand this one, and I'll try to keep it as minimal as possible.
So I'm a moderate modded minecraft player these days, and I've taken quite the fancy to a mod named RotaryCraft. However, this mod is quite mathematically intensive compared to many other minecraft mods, and so therefore many players dislike it because of this. However its gameplay is awesome and I'm sure many more players would enjoy it if they didn't have to worry so much about the mathematical side of it. The maths itself is really quite simple, however many play minecraft to relax and *not* use their brain.
Now, RotaryCraft has a series of engines that output a specific amount of speed (measured in Rad/s) and torque (measured in Nm) which when multiplied together give the engine's total power output in Watts. But this is not the problem.
RotaryCraft's main set of mechanics rely on using gearboxes to modify the torque or speed outputs of each engine according to what the engine is required to power. For example, a Pulse Jet Furnace from RotaryCraft requires 131072 Rad/s of speed to run, but has no torque requirement.
This means that there are a series of gearboxes in the mod that allow you to change the torque and speed. These gearboxes come in the ratios of 2:1, 4:1, 8:1, 16:1 and 32:1. However, most of the time it's not just using gearboxes to achieve the desired result, it also requires up to 4 of the same engine in order to achieve certain results. This is done using a shaft junction, and only 4 engines may be chained at any given time. Different engines cannot be chained for obvious reasons (we're talking about shafts here, try merging the speeds of two different shafts and see what happens.). Using shaft junctions will multiply the outputted torque by the number of engines being used.
Here comes the fun part.
What I want this program to do, is calculate what gearbox ratios are required to reach a user inputted speed or torque, and output this, along with what engines were used to achieve that result.
I've already written some dictionaries containing all the necessary values, and I've written a Gearbox method that *should* deal with the ratios. But now I need the program to loop over all the engines, take each engine's speed and torque, and attempt to achieve the user inputted value. Of course if the value is unattainable from any engine, it will output this as well.
Another important thing to note is that more than 1 gearbox can be used, and they multiply. Meaning that I could chain a 2:1 and a 4:1 gearbox to achieve the same result as an 8:1 gearbox. This becomes more relevant once you start needing ratios of like 512:1. (A 32:1 and a 16:1 would achieve this).
Here's the code I've got so far, and it also has all the power information for each engine.
Code:
namespace Engine_Selection
{
public partial class Form1 : Form
{
Dictionary<string, int> EngineSpeeds = new Dictionary<string, int>();
Dictionary<string, int> EngineTorques = new Dictionary<string, int>();
Dictionary<string, int> EnginePower = new Dictionary<string, int>();
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
InitialiseDictionary();
}
private void InitialiseDictionary()
{
// Engine speed entries. (Rad/s)
EngineSpeeds.Add("DC Electric Engine", 256);
EngineSpeeds.Add("Wind Turbine", 1024);
EngineSpeeds.Add("Steam Engine", 512);
EngineSpeeds.Add("Gasoline Engine", 512);
EngineSpeeds.Add("AC Electric Engine", 256);
EngineSpeeds.Add("Performance Engine", 1024);
EngineSpeeds.Add("Hydrokinetic Engine", 32);
EngineSpeeds.Add("Microturbine", 131072);
EngineSpeeds.Add("Gas Turbine", 65536);
// Engine torque entries. (Nm)
EngineTorques.Add("DC Electric Engine", 4);
EngineTorques.Add("Wind Turbine", 4);
EngineTorques.Add("Steam Engine", 32);
EngineTorques.Add("Gasoline Engine", 128);
EngineTorques.Add("AC Electric Engine", 512);
EngineTorques.Add("Performance Engine", 256);
EngineTorques.Add("Hydrokinetic Engine", 16384);
EngineTorques.Add("Microturbine", 16);
EngineTorques.Add("Gas Turbine", 1024);
// Engine power entries. (W)
EnginePower.Add("DC Electric Engine", 1024);
EnginePower.Add("Wind Turbine", 4096);
EnginePower.Add("Steam Engine", 16384);
EnginePower.Add("Gasoline Engine", 65536);
EnginePower.Add("AC Electric Engine", 131072);
EnginePower.Add("Performance Engine", 262144);
EnginePower.Add("Hydrokinetic Engine", 524188);
EnginePower.Add("Microturbine", 2097152);
EnginePower.Add("Gas Turbine", 67108864);
return;
}
private void BtnCalculate_Click(object sender, EventArgs e)
{
int Speed = 0;
int Torque = 0;
int Power = 0;
if (TxtSpeed.Text != "")
if (int.TryParse(TxtSpeed.Text, out Speed)) ;
if (TxtTorque.Text != "")
if (int.TryParse(TxtTorque.Text, out Torque)) ;
if (TxtPower.Text != "")
if (int.TryParse(TxtPower.Text, out Power)) ;
// A generic method works best, but now I need to call this method from the
// loop logic, and that's a bitch... Perhaps a while statement can help here?
}
private void Gearbox(int InputSpeed, int InputTorque, string Mode, int Magnitude, out int OutputSpeed, out int OutputTorque)
{
// Setting outputs to inputs in order to fulfil requirements for out parameters.
OutputSpeed = InputSpeed;
OutputTorque = InputTorque;
// Gearbox set to speed.
if (Mode == "Speed")
{
OutputSpeed = InputSpeed * Magnitude;
OutputTorque = InputTorque / Magnitude;
}
// Gearbox set to torque.
if (Mode == "Torque")
{
OutputSpeed = InputSpeed / Magnitude;
OutputTorque = InputTorque * Magnitude;
}
return;
}
}
}