Advertisement
Guest User

Untitled

a guest
Jul 20th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Public Class Form1
  2.     'Declaring all variables
  3.    Dim ReactorOn As Boolean = False
  4.  
  5.     Dim Heat As Decimal = 0 'Reactor heat
  6.    Dim HeatRate As Decimal = 0 'Reactor heat rate of change
  7.    Dim HeatInc As Decimal = 0 'HeatRate positive portion from fuel and plasma rods
  8.    Dim HeatDec As Decimal = 0 'HeatRate negative portion from rods and DU
  9.  
  10.     Dim TotalFuel As Decimal = 0 'Total amount of fuel, including DU
  11.    Dim TotalFuelPast As Decimal = 0 'Same as above variable, used by timer to keep track of fuel
  12.    Dim Fuel1Num As Decimal = 0 'Amount of yranium in reactor
  13.    Dim Fuel2Num As Decimal = 0 'Amount of stabilized Uranium in reactor
  14.    Dim Fuel3Num As Decimal = 0 'Amount of plutonium in reactor
  15.    Dim Fuel4Num As Decimal = 0 'Amount of mithril in reactor
  16.  
  17.     Dim DUNum As Decimal = 0 'Amount of DU in reactor
  18.    Dim DUNumPast As Decimal = 0 'Same as above variable, used by timer to keep track of DU
  19.  
  20.     Dim TotalRods As UShort = 0 'Total number of rods inserted
  21.    Dim Rod1Num As UShort = 0 'Number of control rods inserted
  22.    Dim Rod2Num As UShort = 0 'Number of silver rods inserted
  23.    Dim Rod3Num As UShort = 0 'Number of advanced rods inserted
  24.    Dim Rod4Num As UShort = 0 'Number of bluespace rods inserted
  25.    Dim Rod5Num As UShort = 0 'Number of plasma rods inserted
  26.  
  27.     Dim Fuel1Rate As Decimal = 0.05 'Heat effect of uranium
  28.    Dim Fuel2Rate As Decimal = 0.05 'Heat effect of stabilized uranium
  29.    Dim Fuel3Rate As Decimal = 0.25 'Heat effect of plutionium
  30.    Dim Fuel4Rate As Decimal = 5 'Heat effect of mithril
  31.  
  32.     Dim Fuel1Decay As Decimal = 0.5 'Decay rate of uranium
  33.    Dim Fuel2Decay As Decimal = 0.25 'Decay rate of stabilized uranium
  34.    Dim Fuel3Decay As Decimal = 0.75 'Decay rate of plutionium. We stop here because fuel4 (mithril) doesn't decay
  35.  
  36.     Dim DURate As Decimal = -0.01 'Heat effect of depleted uranium
  37.  
  38.     Dim Rod1Rate As Decimal = -0.1 'Heat effect of control rods
  39.    Dim Rod2Rate As Decimal = -0.25 'Heat effect of silver rods
  40.    Dim Rod3Rate As Decimal = -0.5 'Heat effect of advanced rods
  41.    Dim Rod4Rate As Decimal = -5 'Heat effect of bluespace rods
  42.    Dim Rod5Rate As Decimal = 5 'Heat effect of plasma rods
  43.  
  44.     Dim Drain As Decimal = -0.01 'Passive heat drain from reactor. Always active
  45.  
  46.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'When the form opens
  47.        CheckHeatRate()
  48.  
  49.     End Sub
  50.  
  51. 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
  52.        HeatInc = (Fuel1Num * Fuel1Rate) + (Fuel2Num * Fuel2Rate) + (Fuel3Num * Fuel3Rate) + (Fuel4Num * Fuel4Rate) + (Rod5Num * Rod5Rate) 'Sums up all positive effects
  53.        ShowVal_HeatInc.Text = HeatInc 'Displays Heat Increase
  54.  
  55.         HeatDec = (Rod1Num * Rod1Rate) + (Rod2Num * Rod2Rate) + (Rod3Num * Rod3Rate) + (Rod4Num * Rod4Rate) + (DUNum * DURate) + Drain 'Sums up all negative effects
  56.        ShowVal_HeatDec.Text = (-1 * HeatDec) 'Displays Heat Decrease, but as a positive number
  57.  
  58.         HeatRate = HeatInc + HeatDec 'Sets HeatRate
  59.        ShowVal_HeatRate.Text = HeatRate 'Displays Heat Rate
  60.  
  61.     End Function
  62.     Private Sub Button_ReactorOn_Click(sender As Object, e As EventArgs) Handles Button_ReactorOn.Click 'When "Fire!" button is clicked
  63.        If ReactorOn = True Then 'If the reactor is already on, nothing happens
  64.  
  65.         ElseIf TotalFuel - DUNum = 0 Then 'Otherwise if reactor has no fuel, it warns you
  66.            MsgBox("Add some fuel to the reactor!")
  67.  
  68.         Else 'Otherwise it turns on
  69.            Heat = 1 'Sets heat to 1 to avoid turning off immediately
  70.  
  71.             CheckHeat() 'Adjusts interface based on heat
  72.  
  73.             ReactorOn = True 'Turns on the reactor
  74.            ShowVal_ReactorState.Text = "ON" 'Changes the indicator
  75.            ShowVal_ReactorState.BackColor = Color.LimeGreen
  76.             Timer_Reactor.Enabled = True 'Enables reactor timer
  77.            Bar_Heat.Value = Heat 'Adjusts heat bar length according to heat
  78.  
  79.         End If
  80.  
  81.     End Sub
  82.  
  83. Private Sub Timer_Reactor_Tick(sender As Object, e As EventArgs) Handles Timer_Reactor.Tick 'While reactor is on:
  84.        If Heat + HeatRate <= 0 Then 'If heat would reach 0 on this tick
  85.            Heat = 0
  86.  
  87.             CheckHeat()
  88.  
  89.             ShowVal_ReactorState.Text = "OFF" 'Changes the indicator
  90.            ShowVal_ReactorState.BackColor = Color.Red
  91.             ReactorOn = False
  92.             Timer_Reactor.Enabled = False 'Turns off this timer
  93.            MsgBox("The reactor ran out of heat and has turned off.")
  94.  
  95.         ElseIf Heat + HeatRate >= 100 Then 'If heat would reach 100 this tick
  96.            Heat = 0
  97.  
  98.             CheckHeat()
  99.  
  100.             ShowVal_ReactorState.Text = "OFF" 'Changes the indicator
  101.            ShowVal_ReactorState.BackColor = Color.Red
  102.             ReactorOn = False
  103.             Timer_Reactor.Enabled = False 'Turns off this timer
  104.  
  105.             Fuel1Num = 0 'Changes all fuel to DU
  106.            Fuel2Num = 0
  107.             Fuel3Num = 0
  108.             Fuel4Num = 0
  109.             DUNum = TotalFuel
  110.  
  111.             CheckFuel()
  112.  
  113.             CheckHeatRate()
  114.  
  115.             MsgBox("The reactor has overheated and exploded!")
  116.  
  117.         ElseIf TotalFuel - DUNum = 0 Then 'If reactor runs out of fuel
  118.            ShowVal_ReactorState.Text = "OFF" 'Changes the indicator
  119.            ShowVal_ReactorState.BackColor = Color.Red
  120.             ReactorOn = False
  121.             Timer_Reactor.Enabled = False 'Turns off this timer
  122.            Timer_Heat.Enabled = True 'Turns on the heat timer to reduce heat
  123.            MsgBox("The reactor ran out of fuel and has shut off.")
  124.  
  125.         Else 'Otherwise, react normally for a tick
  126.            Heat += HeatRate 'Changes heat by heatrate
  127.  
  128.             CheckHeat() 'Adjusts interface based on heat
  129.  
  130.             TotalFuelPast = TotalFuel 'Remembers how much fuel was present at the start of the tick
  131.            DUNumPast = DUNum 'Remembers how much DU was present at the start of the tick
  132.  
  133.             If Fuel1Num = 0 Then 'If this fuel type is empty, do nothing
  134.  
  135.             ElseIf Fuel1Num - Fuel1Decay <= 0 Then 'Otherwise, if this fuel type would go to or below 0 this tick
  136.                DUNum += Fuel1Num 'Adds amount that is left to DU
  137.                Fuel1Num = 0 'Then sets the fuel to 0
  138.  
  139.             Else 'Otherwise
  140.                Fuel1Num -= Fuel1Decay 'Reduces fuel by its decay amount
  141.                DUNum += Fuel1Decay 'Increases DU by that same amount
  142.  
  143.             End If
  144.  
  145.             If Fuel2Num = 0 Then 'Repeat above but for other fuel types
  146.  
  147.             ElseIf Fuel2Num - Fuel2Decay <= 0 Then
  148.                 DUNum += Fuel2Num
  149.                 Fuel2Num = 0
  150.  
  151.             Else
  152.                 Fuel2Num -= Fuel2Decay
  153.                 DUNum += Fuel2Decay
  154.  
  155.             End If
  156.  
  157.             If Fuel3Num = 0 Then
  158.  
  159.             ElseIf Fuel3Num - Fuel3Decay <= 0 Then
  160.                 DUNum += Fuel3Num
  161.                 Fuel3Num = 0
  162.  
  163.             Else
  164.                 Fuel3Num -= Fuel3Decay
  165.                 DUNum += Fuel3Decay
  166.  
  167.             End If 'We stop here because fuel4 (mithril) doesn't decay
  168.  
  169.             CheckFuel() 'Now we update fuels
  170.  
  171.             CheckHeatRate() 'And heat rate
  172.  
  173.             'And that's one tick of the reactor!
  174.  
  175.         End If
  176.  
  177.     End Sub
  178.  
  179.     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
  180.        If Heat + HeatRate <= 0 Then 'If heat would reach 0 on this tick
  181.            Heat = 0
  182.  
  183.             CheckHeat()
  184.  
  185.             ShowVal_ReactorState.Text = "OFF" 'Changes the indicator
  186.            ShowVal_ReactorState.BackColor = Color.Red
  187.             ReactorOn = False
  188.             Timer_Heat.Enabled = False 'Turns off this timer
  189.        Else
  190.             Heat += HeatRate 'Changes heat by heatrate
  191.  
  192.             CheckHeat() 'Adjusts interface based on heat
  193.  
  194.         End If
  195.  
  196.     End Sub
  197.  
  198.     Private Sub Button_DUClear_Click(sender As Object, e As EventArgs) Handles Button_DUClear.Click 'When clearing DU
  199.        If ReactorOn = True Then
  200.             MsgBox("You must wait for the reactor to shut off before clearing depleted uranium.")
  201.         Else 'Empties DU and sets TotalFuel accordingly
  202.            TotalFuel -= DUNum
  203.             DUNum = 0
  204.  
  205.             CheckFuel() 'Adjusts interface
  206.  
  207.             CheckHeatRate() 'Adjusts heat rates
  208.  
  209.         End If
  210.  
  211.  
  212.     End Sub
  213. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement