Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Public Class Form1
- 'Declaring all variables
- Dim ReactorOn As Boolean = False
- Dim Heat As Decimal = 0 'Reactor heat
- Dim HeatRate As Decimal = 0 'Reactor heat rate of change
- Dim HeatInc As Decimal = 0 'HeatRate positive portion from fuel and plasma rods
- Dim HeatDec As Decimal = 0 'HeatRate negative portion from rods and DU
- Dim TotalFuel As Decimal = 0 'Total amount of fuel, including DU
- Dim TotalFuelPast As Decimal = 0 'Same as above variable, used by timer to keep track of fuel
- Dim Fuel1Num As Decimal = 0 'Amount of yranium in reactor
- Dim Fuel2Num As Decimal = 0 'Amount of stabilized Uranium in reactor
- Dim Fuel3Num As Decimal = 0 'Amount of plutonium in reactor
- Dim Fuel4Num As Decimal = 0 'Amount of mithril in reactor
- Dim DUNum As Decimal = 0 'Amount of DU in reactor
- Dim DUNumPast As Decimal = 0 'Same as above variable, used by timer to keep track of DU
- Dim TotalRods As UShort = 0 'Total number of rods inserted
- Dim Rod1Num As UShort = 0 'Number of control rods inserted
- Dim Rod2Num As UShort = 0 'Number of silver rods inserted
- Dim Rod3Num As UShort = 0 'Number of advanced rods inserted
- Dim Rod4Num As UShort = 0 'Number of bluespace rods inserted
- Dim Rod5Num As UShort = 0 'Number of plasma rods inserted
- Dim Fuel1Rate As Decimal = 0.05 'Heat effect of uranium
- Dim Fuel2Rate As Decimal = 0.05 'Heat effect of stabilized uranium
- Dim Fuel3Rate As Decimal = 0.25 'Heat effect of plutionium
- Dim Fuel4Rate As Decimal = 5 'Heat effect of mithril
- Dim Fuel1Decay As Decimal = 0.5 'Decay rate of uranium
- Dim Fuel2Decay As Decimal = 0.25 'Decay rate of stabilized uranium
- Dim Fuel3Decay As Decimal = 0.75 'Decay rate of plutionium. We stop here because fuel4 (mithril) doesn't decay
- Dim DURate As Decimal = -0.01 'Heat effect of depleted uranium
- Dim Rod1Rate As Decimal = -0.1 'Heat effect of control rods
- Dim Rod2Rate As Decimal = -0.25 'Heat effect of silver rods
- Dim Rod3Rate As Decimal = -0.5 'Heat effect of advanced rods
- Dim Rod4Rate As Decimal = -5 'Heat effect of bluespace rods
- Dim Rod5Rate As Decimal = 5 'Heat effect of plasma rods
- Dim Drain As Decimal = -0.01 'Passive heat drain from reactor. Always active
- Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'When the form opens
- CheckHeatRate()
- End Sub
- Function CheckHeatRate() 'Called by other functions. Checks what the current heatrate should be and updates it. Call this every time you change fuel or rods
- HeatInc = (Fuel1Num * Fuel1Rate) + (Fuel2Num * Fuel2Rate) + (Fuel3Num * Fuel3Rate) + (Fuel4Num * Fuel4Rate) + (Rod5Num * Rod5Rate) 'Sums up all positive effects
- ShowVal_HeatInc.Text = HeatInc 'Displays Heat Increase
- HeatDec = (Rod1Num * Rod1Rate) + (Rod2Num * Rod2Rate) + (Rod3Num * Rod3Rate) + (Rod4Num * Rod4Rate) + (DUNum * DURate) + Drain 'Sums up all negative effects
- ShowVal_HeatDec.Text = (-1 * HeatDec) 'Displays Heat Decrease, but as a positive number
- HeatRate = HeatInc + HeatDec 'Sets HeatRate
- ShowVal_HeatRate.Text = HeatRate 'Displays Heat Rate
- End Function
- Private Sub Button_ReactorOn_Click(sender As Object, e As EventArgs) Handles Button_ReactorOn.Click 'When "Fire!" button is clicked
- If ReactorOn = True Then 'If the reactor is already on, nothing happens
- ElseIf TotalFuel - DUNum = 0 Then 'Otherwise if reactor has no fuel, it warns you
- MsgBox("Add some fuel to the reactor!")
- Else 'Otherwise it turns on
- Heat = 1 'Sets heat to 1 to avoid turning off immediately
- CheckHeat() 'Adjusts interface based on heat
- ReactorOn = True 'Turns on the reactor
- ShowVal_ReactorState.Text = "ON" 'Changes the indicator
- ShowVal_ReactorState.BackColor = Color.LimeGreen
- Timer_Reactor.Enabled = True 'Enables reactor timer
- Bar_Heat.Value = Heat 'Adjusts heat bar length according to heat
- End If
- End Sub
- Private Sub Timer_Reactor_Tick(sender As Object, e As EventArgs) Handles Timer_Reactor.Tick 'While reactor is on:
- If Heat + HeatRate <= 0 Then 'If heat would reach 0 on this tick
- Heat = 0
- CheckHeat()
- ShowVal_ReactorState.Text = "OFF" 'Changes the indicator
- ShowVal_ReactorState.BackColor = Color.Red
- ReactorOn = False
- Timer_Reactor.Enabled = False 'Turns off this timer
- MsgBox("The reactor ran out of heat and has turned off.")
- ElseIf Heat + HeatRate >= 100 Then 'If heat would reach 100 this tick
- Heat = 0
- CheckHeat()
- ShowVal_ReactorState.Text = "OFF" 'Changes the indicator
- ShowVal_ReactorState.BackColor = Color.Red
- ReactorOn = False
- Timer_Reactor.Enabled = False 'Turns off this timer
- Fuel1Num = 0 'Changes all fuel to DU
- Fuel2Num = 0
- Fuel3Num = 0
- Fuel4Num = 0
- DUNum = TotalFuel
- CheckFuel()
- CheckHeatRate()
- MsgBox("The reactor has overheated and exploded!")
- ElseIf TotalFuel - DUNum = 0 Then 'If reactor runs out of fuel
- ShowVal_ReactorState.Text = "OFF" 'Changes the indicator
- ShowVal_ReactorState.BackColor = Color.Red
- ReactorOn = False
- Timer_Reactor.Enabled = False 'Turns off this timer
- Timer_Heat.Enabled = True 'Turns on the heat timer to reduce heat
- MsgBox("The reactor ran out of fuel and has shut off.")
- Else 'Otherwise, react normally for a tick
- Heat += HeatRate 'Changes heat by heatrate
- CheckHeat() 'Adjusts interface based on heat
- TotalFuelPast = TotalFuel 'Remembers how much fuel was present at the start of the tick
- DUNumPast = DUNum 'Remembers how much DU was present at the start of the tick
- If Fuel1Num = 0 Then 'If this fuel type is empty, do nothing
- ElseIf Fuel1Num - Fuel1Decay <= 0 Then 'Otherwise, if this fuel type would go to or below 0 this tick
- DUNum += Fuel1Num 'Adds amount that is left to DU
- Fuel1Num = 0 'Then sets the fuel to 0
- Else 'Otherwise
- Fuel1Num -= Fuel1Decay 'Reduces fuel by its decay amount
- DUNum += Fuel1Decay 'Increases DU by that same amount
- End If
- If Fuel2Num = 0 Then 'Repeat above but for other fuel types
- ElseIf Fuel2Num - Fuel2Decay <= 0 Then
- DUNum += Fuel2Num
- Fuel2Num = 0
- Else
- Fuel2Num -= Fuel2Decay
- DUNum += Fuel2Decay
- End If
- If Fuel3Num = 0 Then
- ElseIf Fuel3Num - Fuel3Decay <= 0 Then
- DUNum += Fuel3Num
- Fuel3Num = 0
- Else
- Fuel3Num -= Fuel3Decay
- DUNum += Fuel3Decay
- End If 'We stop here because fuel4 (mithril) doesn't decay
- CheckFuel() 'Now we update fuels
- CheckHeatRate() 'And heat rate
- 'And that's one tick of the reactor!
- End If
- End Sub
- Private Sub Timer_Heat_Tick(sender As Object, e As EventArgs) Handles Timer_Heat.Tick 'Drains reactor of heat after having run out of fuel
- If Heat + HeatRate <= 0 Then 'If heat would reach 0 on this tick
- Heat = 0
- CheckHeat()
- ShowVal_ReactorState.Text = "OFF" 'Changes the indicator
- ShowVal_ReactorState.BackColor = Color.Red
- ReactorOn = False
- Timer_Heat.Enabled = False 'Turns off this timer
- Else
- Heat += HeatRate 'Changes heat by heatrate
- CheckHeat() 'Adjusts interface based on heat
- End If
- End Sub
- Private Sub Button_DUClear_Click(sender As Object, e As EventArgs) Handles Button_DUClear.Click 'When clearing DU
- If ReactorOn = True Then
- MsgBox("You must wait for the reactor to shut off before clearing depleted uranium.")
- Else 'Empties DU and sets TotalFuel accordingly
- TotalFuel -= DUNum
- DUNum = 0
- CheckFuel() 'Adjusts interface
- CheckHeatRate() 'Adjusts heat rates
- End If
- End Sub
- End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement