Advertisement
Guest User

coldwar.lua

a guest
Aug 11th, 2017
397
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 18.07 KB | None | 0 0
  1. -- Cold War Simulator by Saldor010
  2.  
  3. local args = {...}
  4. if not fs.exists("cobalt") and not fs.exists(args[1]) then
  5.      term.setTextColor(colors.red)
  6.     print("Cobalt could not be found on this machine. Cobalt is required to run this game.")
  7.     term.setTextColor(colors.lime)
  8.     print("To download cobalt, please press the Y key now.")
  9.     term.setTextColor(colors.blue)
  10.     print("If you already have cobalt, and we just can't find it, please supply the path as the second argument.")
  11.     local ev,p1,p2,p3,p4,p5 = os.pullEvent("char")
  12.     if string.lower(p1) == "y" then
  13.         shell.run("pastebin","run","h5h4fm3t")
  14.     else
  15.         term.setTextColor(colors.red)
  16.         print("Cancelled installation of Cobalt.")
  17.     end
  18.     error()
  19. end
  20. local cobalt = dofile(args[1] or "cobalt")
  21. cobalt.ui = dofile("cobalt-ui/init.lua")
  22.  
  23. local nations = {
  24.     ["United States"] = {
  25.         ["Population"] = 0,
  26.         ["Image"] = "US.nfp",
  27.         ["Color"] = colors.blue,
  28.         ["Cities"] = {
  29.             ["Los Angeles"] = {
  30.                 ["X"] = 8,
  31.                 ["Y"] = 13,
  32.                 ["Population"] = 500000, --500K
  33.                 ["Nukes"] = 0,
  34.                 ["Cruise"] = 0,
  35.                 ["Icon"] = "@",
  36.             },
  37.             ["Seattle"] = {
  38.                 ["X"] = 7,
  39.                 ["Y"] = 4,
  40.                 ["Population"] = 400000, --400K
  41.                 ["Nukes"] = 0,
  42.                 ["Cruise"] = 0,
  43.                 ["Icon"] = "@",
  44.             },
  45.             ["Dallas"] = {
  46.                 ["X"] = 29,
  47.                 ["Y"] = 15,
  48.                 ["Population"] = 300000, --300K
  49.                 ["Nukes"] = 0,
  50.                 ["Cruise"] = 0,
  51.                 ["Icon"] = "@",
  52.             },
  53.             ["New York"] = {
  54.                 ["X"] = 45,
  55.                 ["Y"] = 8,
  56.                 ["Population"] = 1000000, --1M
  57.                 ["Nukes"] = 0,
  58.                 ["Cruise"] = 1,
  59.                 ["Icon"] = "$",
  60.             },
  61.             ["Wash D.C."] = {
  62.                 ["X"] = 43,
  63.                 ["Y"] = 9,
  64.                 ["Population"] = 1000000, --1M
  65.                 ["Nukes"] = 0,
  66.                 ["Cruise"] = 1,
  67.                 ["Icon"] = "$",
  68.             },
  69.             ["Denver"] = {
  70.                 ["X"] = 19,
  71.                 ["Y"] = 10,
  72.                 ["Population"] = 100000, --100K
  73.                 ["Nukes"] = 0,
  74.                 ["Cruise"] = 0,
  75.                 ["Icon"] = "@",
  76.             },
  77.             ["Minneapolis"] = {
  78.                 ["X"] = 30,
  79.                 ["Y"] = 7,
  80.                 ["Population"] = 100000, --100K
  81.                 ["Nukes"] = 0,
  82.                 ["Cruise"] = 0,
  83.                 ["Icon"] = "@",
  84.             },
  85.         },
  86.     },
  87.     ["China"] = {
  88.         ["Population"] = 0,
  89.         ["Image"] = "China.nfp",
  90.         ["Color"] = colors.red,
  91.         ["Cities"] = {
  92.             ["Beijing"] = {
  93.                 ["X"] = 42,
  94.                 ["Y"] = 7,
  95.                 ["Population"] = 1000000, --1M
  96.                 ["Nukes"] = 0,
  97.                 ["Cruise"] = 1,
  98.                 ["Icon"] = "$",
  99.             },
  100.             ["Shanghai"] = {
  101.                 ["X"] = 47,
  102.                 ["Y"] = 12,
  103.                 ["Population"] = 500000, --500K
  104.                 ["Nukes"] = 0,
  105.                 ["Cruise"] = 0,
  106.                 ["Icon"] = "@",
  107.             },
  108.             ["Hong Kong"] = {
  109.                 ["X"] = 43,
  110.                 ["Y"] = 18,
  111.                 ["Population"] = 1000000, --1M
  112.                 ["Nukes"] = 0,
  113.                 ["Cruise"] = 1,
  114.                 ["Icon"] = "$",
  115.             },
  116.             ["Chengdu"] = {
  117.                 ["X"] = 34,
  118.                 ["Y"] = 13,
  119.                 ["Population"] = 300000, --300K
  120.                 ["Nukes"] = 0,
  121.                 ["Cruise"] = 0,
  122.                 ["Icon"] = "@",
  123.             },
  124.             ["Xi'an"] = {
  125.                 ["X"] = 36,
  126.                 ["Y"] = 11,
  127.                 ["Population"] = 100000, --100K
  128.                 ["Nukes"] = 0,
  129.                 ["Cruise"] = 0,
  130.                 ["Icon"] = "@",
  131.             },
  132.             ["Urumqi"] = {
  133.                 ["X"] = 12,
  134.                 ["Y"] = 5,
  135.                 ["Population"] = 100000, --100K
  136.                 ["Nukes"] = 0,
  137.                 ["Cruise"] = 0,
  138.                 ["Icon"] = "@",
  139.             },
  140.             ["Guangzhou"] = {
  141.                 ["X"] = 42,
  142.                 ["Y"] = 17,
  143.                 ["Population"] = 400000, --400K
  144.                 ["Nukes"] = 0,
  145.                 ["Cruise"] = 0,
  146.                 ["Icon"] = "@",
  147.             },
  148.         },
  149.     }
  150. }
  151.  
  152. for k,v in pairs(nations) do
  153.     local Napop = 0
  154.    
  155.     if fs.exists(v["Image"]) then
  156.         v["Image"] = cobalt.surface.load(v["Image"])
  157.     else
  158.         error("Missing image : "..v["Image"])
  159.     end
  160.    
  161.     for p,b in pairs(v["Cities"]) do
  162.         b["DefaultIcon"] = b["Icon"]
  163.         Napop = Napop + b["Population"]
  164.     end
  165.     v["Population"] = Napop -- The population that the nation was at when the game started E.G. Perfectly healthy nation
  166. end
  167.  
  168. local nationSelectedForPlaying = "United States"
  169. local nationSelectedForFighting = "China"
  170. local nationSelectedForGUI = "United States"
  171. local nationSelectedForTurn = "United States"
  172.  
  173. local AIPaused = false
  174. local turn = 1
  175. local TURNOVER = false
  176. local turnString = "Turn "..tostring(turn)
  177. local turnStringTICK = 20
  178. local tick = 0
  179. local tickRate = 0.2
  180.  
  181. local ContextSelected = nil
  182. local ContextDisabled = false
  183. local ContextOverride = false
  184. local ContextPanel = cobalt.ui.new({w = 14,h = 6, x = -100, y=-100})
  185. local ContextLabels = {
  186.     [1] = ContextPanel:add("text",{text="",wrap="center",foreColour = colors.white, backColour = colors.black,x=1,y=1}),
  187.     [2] = ContextPanel:add("text",{text="",wrap="center",foreColour = colors.white, backColour = colors.black,x=1,y=2}),
  188.     [3] = ContextPanel:add("text",{text="",wrap="left",foreColour = colors.white, backColour = colors.black,x=1,y=3}),
  189.     [4] = ContextPanel:add("text",{text="",wrap="left",foreColour = colors.white, backColour = colors.black,x=1,y=4}),
  190. }
  191. local ContextButtons = {
  192.     [1] = ContextPanel:add("button",{wrap="left",y=5,w=12,h=1,text=""}),
  193.     [2] = ContextPanel:add("button",{wrap="left",y=6,w=12,h=1,text=""}),
  194. }
  195. local AlertTimer = 0
  196. local AlertPanel = cobalt.ui.new({w=51,h=3,x=1,y=math.floor(19/2),state=false})
  197. local AlertText = AlertPanel:add("text",{w=51,h=1,y=2,text="",wrap="center"})
  198.  
  199. local Animations = {}
  200.  
  201. local function FireNuke(from,to,playerControlled)
  202.     from.Nukes = from.Nukes - 1
  203.     ContextOverride = nil
  204.     ContextDisabled = true
  205.    
  206.     if playerControlled then nationSelectedForGUI = nationSelectedForPlaying else nationSelectedForGUI = nationSelectedForFighting end
  207.     table.insert(Animations,{
  208.         ["Type"] = "NukeAway",
  209.         ["X"] = from.X,
  210.         ["Y"] = from.Y,
  211.         ["step"] = 0,
  212.         ["stepLimit"] = 10,
  213.         ["Function"] = function()
  214.             if playerControlled then nationSelectedForGUI = nationSelectedForFighting else nationSelectedForGUI = nationSelectedForPlaying end
  215.             if to.Cruise > 0 then
  216.                 table.insert(Animations,{
  217.                     ["Type"] = "NukeFailure",
  218.                     ["X"] = to.X,
  219.                     ["Y"] = to.Y,
  220.                     ["step"] = 0,
  221.                     ["stepLimit"] = 10,
  222.                     ["Function"] = function()
  223.                         to.Cruise = to.Cruise - 1
  224.                        
  225.                         if playerControlled then ContextDisabled = false for k,v in pairs(nations[nationSelectedForPlaying]["Cities"]) do v["Icon"] = v["DefaultIcon"] end end
  226.                         if not playerControlled then AIPaused = false end
  227.                     end
  228.                 })
  229.             else
  230.                 table.insert(Animations,{
  231.                     ["Type"] = "NukeSuccess",
  232.                     ["X"] = to.X,
  233.                     ["Y"] = to.Y,
  234.                     ["step"] = 0,
  235.                     ["stepLimit"] = 20,
  236.                     ["Function"] = function()
  237.                         to.Population = to.Population / 2
  238.                         to.Nukes = math.floor(to.Nukes / 2)
  239.                        
  240.                         if playerControlled then ContextDisabled = false for k,v in pairs(nations[nationSelectedForPlaying]["Cities"]) do v["Icon"] = v["DefaultIcon"] end end
  241.                         if not playerControlled then AIPaused = false end
  242.                     end
  243.                 })
  244.             end
  245.         end
  246.     })
  247. end
  248.  
  249. local ContextMenu = {
  250.     ["You"] = { -- Clicking on your own cities
  251.         [1] = {
  252.             ["Text"] = "Build Nuke",
  253.             ["Function"] = function(city)
  254.                 city.Icon = "N"
  255.                 city.Work = "BuildNuke"
  256.             end,
  257.         },
  258.         [2] = {
  259.             ["Text"] = "Build Cruise",
  260.             ["Function"] = function(city)
  261.                 city.Icon = "C"
  262.                 city.Work = "BuildCruise"
  263.             end,
  264.         },
  265.     },
  266.     ["Enemy"] = { -- Clicking on enemy cities
  267.         [1] = {
  268.             ["Text"] = "Fire Nuke",
  269.             ["Function"] = function(city)
  270.                 ContextPanel.x = -100
  271.                 ContextPanel.y = -100
  272.                 ContextDisabled = true
  273.                
  274.                 for k,v in pairs(nations[nationSelectedForPlaying]["Cities"]) do
  275.                     v["Icon"] = tostring(v["Nukes"])
  276.                 end
  277.                
  278.                 nationSelectedForGUI = nationSelectedForPlaying
  279.                 AlertPanel.backColour = nations[nationSelectedForPlaying]["Color"]
  280.                 AlertText.backColour = nations[nationSelectedForPlaying]["Color"]
  281.                 AlertText.foreColour = colors.white
  282.                 AlertText.text = "Select a friendly city to fire from."
  283.                 AlertPanel.state = "_ALL"
  284.                 AlertText.state = "_ALL"
  285.                 AlertTimer = 10
  286.                
  287.                 ContextOverride = function(city2)
  288.                     if city2.Nukes > 0 then
  289.                         FireNuke(city2,city,true)
  290.                     end
  291.                 end
  292.             end,
  293.         }
  294.     },
  295. }
  296.  
  297. for k,v in pairs(ContextButtons) do
  298.     v.onclick = function()
  299.         if nationSelectedForGUI == nationSelectedForPlaying then
  300.             if ContextMenu["You"][k] then
  301.                 ContextMenu["You"][k]["Function"](ContextSelected)
  302.             end
  303.         else
  304.             if ContextMenu["Enemy"][k] then
  305.                 ContextMenu["Enemy"][k]["Function"](ContextSelected)
  306.             end
  307.         end
  308.     end
  309. end
  310.  
  311. local MainPanel = cobalt.ui.new({w=4,h=1})
  312. local SwapViewButton = MainPanel:add("button",{w=4,h=1,text="View",foreColour = colors.white,backColour = colors.grey})
  313. SwapViewButton.onclick = function()
  314.     if nationSelectedForPlaying == nationSelectedForGUI then
  315.         nationSelectedForGUI = nationSelectedForFighting
  316.     else
  317.         nationSelectedForGUI = nationSelectedForPlaying
  318.     end
  319. end
  320.  
  321. local MX,MY = 0,0
  322.  
  323. local function renderPop(pop)
  324.     if not pop then pop = 0 end
  325.     if pop >= 1000 then -- K
  326.         if pop >= 1000000 then -- M
  327.             pop = math.floor(pop / 100000)/10
  328.             pop = tostring(pop).."M"
  329.             return pop
  330.         else
  331.             pop = math.floor(pop / 1000)
  332.             pop = tostring(pop).."K"
  333.             return pop
  334.         end
  335.     else
  336.         return pop
  337.     end
  338. end
  339.  
  340. local AISteps = {}
  341. --[[local function NextTurn()
  342.     -- Enemy AI's turn
  343.     AINotDone = true
  344.     ContextDisabled = true
  345.     nationSelectedForTurn = nationSelectedForFighting
  346.     nationSelectedForGUI = nationSelectedForFighting
  347.     for k,v in pairs(nations[nationSelectedForFighting]["Cities"]) do
  348.         if v.Work == "BuildCruise" then
  349.             v.Cruise = v.Cruise + 1
  350.         elseif v.Work == "BuildNuke" then
  351.             v.Nukes = v.Nukes + 1
  352.         end
  353.        
  354.         if v.Cruise <= 0 then
  355.             v.Work = "BuildCruise"
  356.         elseif v.Cruise <= 1 and v.Population > 500000 then
  357.             v.Work = "BuildCruise"
  358.         else
  359.             v.Work = "BuildNuke"
  360.         end
  361.        
  362.         if v.Nukes > 0 then
  363.             local highest = nil
  364.             for p,b in pairs(nations[nationSelectedForPlaying]["Cities"]) do
  365.                 if highest == nil then highest = b else
  366.                     if b.Population > highest.Population then highest = b end
  367.                 end
  368.             end
  369.             FireNuke(v,b,false)
  370.         end
  371.        
  372.         v.Icon = v.DefaultIcon
  373.     end
  374.    
  375.     -- Enemy turn over
  376.     turn = turn + 1
  377.     nationSelectedForTurn = nationSelectedForPlaying
  378.     nationSelectedForGUI = nationSelectedForPlaying
  379.     ContextDisabled = false
  380.    
  381.     for k,v in pairs(nations[nationSelectedForPlaying]["Cities"]) do
  382.         if v.Work == "BuildCruise" then
  383.             v.Cruise = v.Cruise + 1
  384.         elseif v.Work == "BuildNuke" then
  385.             v.Nukes = v.Nukes + 1
  386.         end
  387.         v.Icon = v.DefaultIcon
  388.         v.Work = nil
  389.     end
  390. end]]--
  391.  
  392. local NextTurnPanel = cobalt.ui.new({w = 9,h = 1, x = 1, y=19})
  393. local NextTurnButton = NextTurnPanel:add("button",{w=9,h=1,text="Next Turn"})
  394. NextTurnButton.onclick = function()
  395.     TURNOVER = true
  396. end
  397.  
  398. local AISteps = {}
  399. function cobalt.update( dt )
  400.     tick = tick + dt
  401.     if tick >= tickRate then
  402.         tick = 0
  403.         -- Do a game update
  404.        
  405.         turnStringTICK = turnStringTICK - 1
  406.         if turnStringTICK <= 0 then
  407.             turnStringTICK = 20
  408.             if string.sub(turnString,1,1) == "T" then
  409.                 if nationSelectedForTurn == nationSelectedForPlaying then
  410.                     turnString = "Your turn"
  411.                 else
  412.                     turnString = "Enemy's turn"
  413.                 end
  414.             else
  415.                 turnString = "Turn "..tostring(turn)
  416.             end
  417.         end
  418.        
  419.         AlertTimer = AlertTimer - 1
  420.         if AlertTimer <= 0 then
  421.             AlertPanel.state = false
  422.             AlertText.state = false
  423.         end
  424.        
  425.         local deleteAnim = {}
  426.         for k,v in pairs(Animations) do
  427.             v.step = v.step + 1
  428.             if v.step >= v.stepLimit then
  429.                 v.Function()
  430.                 table.insert(deleteAnim,k)
  431.             end
  432.         end
  433.         for k,v in pairs(deleteAnim) do
  434.             Animations[v] = nil
  435.         end
  436.        
  437.         if TURNOVER == true then -- Next turn
  438.             TURNOVER = false
  439.             nationSelectedForTurn = nationSelectedForFighting
  440.         end
  441.        
  442.         if nationSelectedForTurn == nationSelectedForFighting and AIPaused == false then -- AI step
  443.             nationSelectedForGUI = nationSelectedForFighting
  444.             if #AISteps == 0 then
  445.                 for k,v in pairs(nations[nationSelectedForFighting]["Cities"]) do
  446.                     if v.Work == "BuildCruise" then
  447.                         v.Cruise = v.Cruise + 1
  448.                     elseif v.Work == "BuildNuke" then
  449.                         v.Nukes = v.Nukes + 1
  450.                     end
  451.                    
  452.                     if v.Cruise <= 0 then
  453.                         table.insert(AISteps,{
  454.                             ["BuildCruise"] = v
  455.                         })
  456.                         --v.Work = "BuildCruise"
  457.                     elseif v.Cruise <= 1 and v.Population > 500000 then
  458.                         table.insert(AISteps,{
  459.                             ["BuildCruise"] = v
  460.                         })
  461.                         --v.Work = "BuildCruise"
  462.                     else
  463.                         table.insert(AISteps,{
  464.                             ["BuildNuke"] = v
  465.                         })
  466.                         --v.Work = "BuildNuke"
  467.                     end
  468.                    
  469.                     if v.Nukes > 0 then
  470.                         local highest = nil
  471.                         for p,b in pairs(nations[nationSelectedForPlaying]["Cities"]) do
  472.                             if highest == nil then highest = b else
  473.                                 if b.Population > highest.Population then highest = b end
  474.                             end
  475.                         end
  476.                         table.insert(AISteps,{
  477.                             ["FireNuke"] = {
  478.                                 ["from"] = v,
  479.                                 ["to"] = highest
  480.                             }
  481.                         })
  482.                         --FireNuke(v,b,false)
  483.                     end
  484.                 end
  485.             else
  486.                 local WorkToDo = AISteps[1]
  487.                 if WorkToDo["BuildCruise"] then
  488.                     WorkToDo["BuildCruise"].Work = "BuildCruise"
  489.                     WorkToDo["BuildCruise"].Icon = "C"
  490.                 elseif WorkToDo["BuildNuke"] then
  491.                     WorkToDo["BuildNuke"].Work = "BuildNuke"
  492.                     WorkToDo["BuildNuke"].Icon = "N"
  493.                 elseif WorkToDo["FireNuke"] then
  494.                     AIPaused = true
  495.                     FireNuke(WorkToDo["FireNuke"]["from"],WorkToDo["FireNuke"]["to"],false)
  496.                 end
  497.                 table.remove(AISteps,1)
  498.                 if #AISteps == 0 then
  499.                     nationSelectedForGUI = nationSelectedForPlaying
  500.                     nationSelectedForTurn = nationSelectedForPlaying
  501.                    
  502.                     for k,v in pairs(nations[nationSelectedForPlaying]["Cities"]) do
  503.                         if v.Work == "BuildCruise" then
  504.                             v.Cruise = v.Cruise + 1
  505.                         elseif v.Work == "BuildNuke" then
  506.                             v.Nukes = v.Nukes + 1
  507.                         end
  508.                     end
  509.                 end
  510.             end
  511.         end
  512.     end
  513. end
  514.  
  515. function cobalt.draw()
  516.     if nationSelectedForGUI and nations[nationSelectedForGUI] then
  517.         local N = nations[nationSelectedForGUI]
  518.         cobalt.application.view:drawSurface(1,1,N["Image"])
  519.        
  520.         local Npop = 0
  521.         for k,v in pairs(N["Cities"]) do
  522.             term.setTextColor(colors.white)
  523.             cobalt.graphics.print(v["Icon"],v["X"],v["Y"])
  524.             Npop = Npop + v["Population"]
  525.         end
  526.        
  527.         cobalt.graphics.center(nationSelectedForGUI.." - "..renderPop(Npop),1,0,51,colors.black,colors.white)
  528.     end
  529.    
  530.     for k,v in pairs(Animations) do
  531.         if v.Type == "NukeAway" then
  532.             cobalt.graphics.print("^",v.X,v.Y-v.step)
  533.             --[[for i=1,v.step do
  534.                 cobalt.graphics.print("@",v.X,v.Y-i+1,colors.black,colors.gray)
  535.             end]]--
  536.         elseif v.Type == "NukeSuccess" then
  537.             if v.step <= 10 then
  538.                 cobalt.graphics.print("V",v.X,v.Y-10+v.step)
  539.             end
  540.             if v.step > 10 then cobalt.graphics.print("@",v.X,v.Y,colors.red,colors.orange) end
  541.             if v.step > 12 then cobalt.graphics.print("@",v.X-1,v.Y,colors.red,colors.orange) cobalt.graphics.print("@",v.X+1,v.Y,colors.red,colors.orange) cobalt.graphics.print("@",v.X,v.Y-1,colors.red,colors.orange) end
  542.             if v.step > 14 then cobalt.graphics.print("@",v.X,v.Y-2,colors.red,colors.orange) end
  543.             if v.step > 16 then cobalt.graphics.print("@",v.X-1,v.Y-3,colors.red,colors.orange) cobalt.graphics.print("@",v.X,v.Y-3,colors.red,colors.orange) cobalt.graphics.print("@",v.X+1,v.Y-3,colors.red,colors.orange) end
  544.             if v.step > 18 then cobalt.graphics.print("@",v.X-1,v.Y-4,colors.red,colors.orange) cobalt.graphics.print("@",v.X,v.Y-4,colors.red,colors.orange) cobalt.graphics.print("@",v.X+1,v.Y-4,colors.red,colors.orange) end
  545.         elseif v.Type == "NukeFailure" then
  546.             if v.step <= 6 then
  547.                 cobalt.graphics.print("V",v.X,v.Y-10+v.step)
  548.             end
  549.             if v.step > 2 and v.step <= 6 then
  550.                 cobalt.graphics.print("^",v.X,v.Y-v.step+2)
  551.             end
  552.             if v.step > 6 then
  553.                 cobalt.graphics.print("*",v.X,v.Y-4,colors.black,colors.orange)
  554.             end
  555.         end
  556.     end
  557.    
  558.     cobalt.ui.draw()
  559.    
  560.     cobalt.graphics.print(turnString,52-turnString:len(),1)
  561.     --cobalt.graphics.print(MX..";"..MY,1,19)
  562. end
  563.  
  564. function cobalt.mousepressed( x, y, button )
  565.     MX,MY = x,y
  566.    
  567.     cobalt.ui.mousepressed(x,y,button)
  568.    
  569.     if nationSelectedForGUI and nations[nationSelectedForGUI] then
  570.         local N = nations[nationSelectedForGUI]
  571.         local clickOut = true
  572.         if x >= ContextPanel.x and x <= ContextPanel.x+ContextPanel.w-1 and y >= ContextPanel.y and y <= ContextPanel.y+ContextPanel.h-1 then
  573.             clickOut = false
  574.         else
  575.             for k,v in pairs(N["Cities"]) do
  576.                 if v["X"] == x and v["Y"] == y then
  577.                     if not ContextDisabled then
  578.                         ContextSelected = v
  579.                         ContextPanel.backColour = colors.red
  580.                         ContextLabels[1].text = k
  581.                         ContextLabels[2].text = "Pop: "..renderPop(v["Population"])
  582.                         ContextLabels[3].text = "Nukes: "..v["Nukes"]
  583.                         ContextLabels[4].text = "Cruise: "..v["Cruise"]
  584.                         if nationSelectedForGUI ~= nationSelectedForPlaying then
  585.                             ContextPanel.backColour = colors.red
  586.                             ContextLabels[1].backColour = colors.red
  587.                             ContextLabels[2].backColour = colors.red
  588.                             ContextLabels[3].backColour = colors.red
  589.                             ContextLabels[4].backColour = colors.red
  590.                             for i=1,2 do
  591.                                 ContextButtons[i]["backColour"] = colors.red
  592.                                 if ContextMenu["Enemy"][i] then
  593.                                     ContextButtons[i]["text"] = ContextMenu["Enemy"][i]["Text"]
  594.                                 else
  595.                                     ContextButtons[i]["text"] = ""
  596.                                 end
  597.                             end
  598.                         else
  599.                             ContextPanel.backColour = colors.blue
  600.                             ContextLabels[1].backColour = colors.blue
  601.                             ContextLabels[2].backColour = colors.blue
  602.                             ContextLabels[3].backColour = colors.blue
  603.                             ContextLabels[4].backColour = colors.blue
  604.                             for i=1,2 do
  605.                                 ContextButtons[i]["backColour"] = colors.blue
  606.                                 if ContextMenu["You"][i] then
  607.                                     ContextButtons[i]["text"] = ContextMenu["You"][i]["Text"]
  608.                                 else
  609.                                     ContextButtons[i]["text"] = ""
  610.                                 end
  611.                             end
  612.                         end
  613.                    
  614.                         local xF = x+1
  615.                         local yF = y
  616.                        
  617.                         if x+ContextPanel.w >= 51 then xF = x-ContextPanel.w end
  618.                         if y+ContextPanel.h >= 19 then yF = y-ContextPanel.h end
  619.                        
  620.                         ContextPanel.x = xF
  621.                         ContextPanel.y = yF
  622.                         clickOut = false
  623.                     elseif ContextOverride then
  624.                         ContextOverride(v)
  625.                     end
  626.                 end
  627.             end
  628.         end
  629.         if clickOut then
  630.             ContextSelected = nil
  631.             ContextPanel.x = -100
  632.             ContextPanel.y = -100
  633.         end
  634.     end
  635. end
  636.  
  637. function cobalt.mousereleased( x, y, button )
  638.     cobalt.ui.mousereleased(x,y,button)
  639. end
  640.  
  641. function cobalt.keypressed( keycode, key )
  642.  
  643. end
  644.  
  645. function cobalt.keyreleased( keycode, key )
  646.  
  647. end
  648.  
  649. function cobalt.textinput( t )
  650.  
  651. end
  652.  
  653. cobalt.initLoop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement