Advertisement
Guest User

Untitled

a guest
Apr 30th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 21.16 KB | None | 0 0
  1. local seed              = os.time()
  2. local neutrals, homes   = 24,   1
  3. local homeprod, ships   = 100,  100
  4. local prodmin, prodmax  = 15,   100
  5. local costmin, costmax  = 0,    50
  6. local botrate, speed    = .25,  1
  7. local crash, solid      = false, true
  8. local botvsbot, show    = false, false
  9. local spawnside = "random"
  10.  
  11. local time = 0
  12. local running = false
  13. local botmemory, bot2memory = {}, {}
  14. local neutral, player, enemy;
  15. function init_game()
  16.     g2.game_reset()
  17.     time = 0
  18.     botmemory, bot2memory = {}, {}
  19.     math.randomseed(seed)
  20.     g2.ticks = speed
  21.     running = true
  22.    
  23.     neutral = g2.new_user("neutral",0x555555)
  24.     player  = g2.new_user("player", 0x0000ff)
  25.     enemy   = g2.new_user("enemy",  0xff0000)
  26.     if crash then
  27.         player.fleet_crash  = 100
  28.         enemy.fleet_crash   = 100
  29.     end
  30.    
  31.     neutral.user_neutral = 1
  32.     neutral.ships_production_enabled = 0
  33.     if show then player.ui_ships_show_mask = 0xf end
  34.     g2.player = player
  35.  
  36.     local planets = neutrals+homes*2
  37.     local w = math.sqrt(planets)*480/4
  38.     local h = math.sqrt(planets)*230/4
  39.  
  40.    
  41.     for i = 1, (neutrals+neutrals%2)/2 do
  42.         local prod, ships = math.random(prodmin, prodmax), math.random(costmin, costmax)
  43.         local x, y = math.random()*w, math.random()*h
  44.         g2.new_planet(neutral,   x,   y, prod, ships)
  45.         g2.new_planet(neutral, w-x, h-y, prod, ships)
  46.     end
  47.    
  48.     local a = math.random()
  49.     for i = 1, homes do
  50.         local x = w*(1+math.cos(a*math.pi*2))*.5
  51.         local y = h*(1+math.sin(a*math.pi*2))*.5
  52.         if spawnside == "right" then
  53.             if x*2 < w then x = w-x end
  54.         elseif spawnside == "left" then
  55.             if x*2 > w then x = w-x end
  56.         end
  57.         g2.new_planet(player,  x,   y, homeprod, ships)
  58.         g2.new_planet(enemy, w-x, h-y, homeprod, ships)
  59.         a = a + .5/homes
  60.     end
  61.    
  62.     g2.planets_settle()
  63.    
  64.     for _, p in pairs(g2.search("planet")) do
  65.         p.has_collide = solid
  66.     end
  67. end
  68.  
  69. function _bots_data()
  70.     local r = g2.search("user OR planet OR fleet")
  71.     local res = {}
  72.     for _,o in ipairs(r) do
  73.         local _type = nil
  74.         if o.has_user then res[o.n] = {
  75.             n = o.n, is_user = true,
  76.             team = o.user_team_n,
  77.             neutral = o.user_neutral,
  78.             }
  79.         elseif o.has_planet then local u = o:owner() ; res[o.n] = {
  80.             n = o.n, is_planet = true,
  81.             x = o.position_x, y = o.position_y, r = o.planet_r,
  82.             ships = o.ships_value, production = o.ships_production,
  83.             owner = o.owner_n, team = u.user_team_n, neutral = u.user_neutral,
  84.             }
  85.         elseif o.has_fleet then local u = o:owner() ;
  86.             local sync_id = tostring(o.sync_id) ; res[sync_id] = {
  87.             _n = o.n, n = sync_id, is_fleet = true,
  88.             x = o.position_x, y = o.position_y, r = o.fleet_r,
  89.             ships = o.fleet_ships,
  90.             owner = o.owner_n, team = u.user_team_n,
  91.             target = o.fleet_target,
  92.             }
  93.         end
  94.     end
  95.     return res
  96. end
  97.  
  98. function bot(params)
  99.     local abs, floor, ceil, max, min, HUGE, random, PI, sqrt, sort = math.abs, math.floor, math.ceil, math.max, math.min, math.huge, math.random, math.pi, math.sqrt, table.sort
  100.     local function send(p,f,t)return{percent=p,from=f.ships and{f.n}or f,to=t.n}end
  101.     local function redirect(f,t)return{from=f.ships and{f.n}or f,to=t.n}end
  102.     local function distance(a,b)local dx,dy=b.x-a.x,b.y-a.y return sqrt(dx*dx+dy*dy)end
  103.     local G,USER,memory=params.items,params.user,params.memory
  104.     local FIRST=not memory.init
  105.     if FIRST then memory.init=true end
  106.     local uteam=G[USER].team
  107.     local homes,eteam=memory.homes,memory.eteam
  108.     if not homes then
  109.         homes={}
  110.         for _,v in pairs(G)do
  111.             if v.is_planet and not v.neutral then
  112.                 local o=v.team
  113.                 local h=homes[o]
  114.                 if not h or h.production<v.production then
  115.                     homes[o]=v
  116.                 end
  117.             end
  118.         end
  119.         for k,v in pairs(homes)do if k~=uteam then memory.eteam,eteam=k,k end end
  120.         memory.homes=homes
  121.     end
  122.     local home,ehome=homes[uteam],homes[eteam]
  123.     local ships,total,tprod,myprod=0,0,0,0
  124.     local data={planets={},neutral={},myplanets={},myteam={},eplanets={},others={},fleets={},myfleets={},efleets={},mystuff={}}
  125.     for _,p in pairs(G)do
  126.         local o,s=p.team,p.ships
  127.         if not p.is_user and not p.neutral then
  128.             if o==uteam then
  129.                 ships=ships+s
  130.             end
  131.             total=total+s
  132.         end
  133.         if p.is_planet then
  134.             data.planets[#data.planets+1]=p
  135.             if p.neutral then
  136.                 data.neutral[#data.neutral+1]=p
  137.                 data.others[#data.others+1]=p
  138.             else
  139.                 tprod=tprod+p.production
  140.                 if o==uteam then
  141.                     data.myteam[#data.myteam+1]=p
  142.                     if p.owner==USER then
  143.                         myprod=myprod+p.production
  144.                         data.myplanets[#data.myplanets+1]=p
  145.                         data.mystuff[#data.mystuff+1]=p
  146.                     end
  147.                 else
  148.                     data.others[#data.others+1]=p
  149.                     data.eplanets[#data.eplanets+1]=p
  150.                 end
  151.             end
  152.         elseif p.is_fleet then
  153.             data.fleets[#data.fleets+1]=p
  154.             if p.team==uteam then
  155.                 data.myfleets[#data.myfleets+1]=p
  156.                 data.mystuff[#data.mystuff+1]=p
  157.             else
  158.                 data.efleets[#data.efleets+1]=p
  159.             end
  160.         end
  161.     end
  162.     local planets,control=data.myplanets,ships/total
  163.     if FIRST and home and #data.neutral~=0 then
  164.         local function path(f,t,set)
  165.             local ft=distance(f,t)
  166.             for i=1,#set do local p=set[i]
  167.                 if p~=f and p~=t then
  168.                     local pt=distance(p,t)
  169.                     if pt<ft then
  170.                         local fp=distance(f,p)
  171.                         if fp<ft and(pt+fp-p.r*2)<ft then
  172.                             t,ft=p,fp
  173.                         end
  174.                     end
  175.                 end
  176.             end
  177.             return t
  178.         end
  179.         local function recovertime(a,b)
  180.             local r=b.ships-a.ships
  181.             if r<0 then
  182.                 return distance(a,b)/20+b.ships*50/b.production
  183.             elseif a.is_planet then
  184.                 return distance(a,b)/20+b.ships*50/b.production+r*50/a.production
  185.             else
  186.                 return HUGE
  187.             end
  188.         end
  189.         local function pathlength(f,t,set)
  190.             local d=0
  191.             for i=1,20 do
  192.                 if f==t then break end
  193.                 local F=path(f,t,set)
  194.                 d=d+distance(f,F)/40
  195.                 f=F
  196.             end
  197.             return d
  198.         end
  199.         local eeval,enemy=HUGE
  200.         for _,v in pairs(data.eplanets)do
  201.             local n=distance(v,home)
  202.             if eeval>n then eeval,enemy=n,v end
  203.         end
  204.         if not enemy then
  205.             local eeval=-HUGE
  206.             for _,v in pairs(data.others)do
  207.                 local n=distance(v,home)
  208.                 if n>eeval then eeval,enemy=n,v end
  209.             end
  210.         end
  211.         local p,expand=data.neutral,{}
  212.         local rt={}for _,v in pairs(p)do rt[v]=recovertime(home,v)end
  213.         sort(p,function(a,b)return rt[a]<rt[b]end)
  214.         local c=home.ships
  215.         local cinit,ships,n,excess=c,c,0,0
  216.         local benefit=home.production*distance(enemy,home)/2000
  217.         local prod=home.production
  218.         for i=1,#p do local v=p[i]
  219.             if home and enemy and distance(enemy,v)<distance(home,v)then break end
  220.             local s=max(1,v.ships+1)
  221.             local ben=((distance(enemy,v)-pathlength(home,v,expand))/40)*v.production/50-s
  222.             if c<s then
  223.                 excess=excess+s-max(c,0)
  224.                 ben=ben-excess*v.production/prod
  225.             end
  226.             if benefit+ben+c>cinit then
  227.                 benefit=benefit+ben
  228.                 c=c-s
  229.                 if c>0 then prod=prod+v.production end
  230.                 expand[#expand+1]=v
  231.             end
  232.         end
  233.         memory.expand=expand
  234.         return
  235.     end
  236.     local stuff=data.mystuff
  237.     sort(stuff,function(a,b)return a.ships>b.ships end)
  238.     local targets=data.eplanets
  239.     local defend=myprod/tprod>.5 and control<.8
  240.     if memory.expand then
  241.         for _,v in pairs(memory.expand)do
  242.             local v=G[v.n]
  243.             if v and v.neutral then
  244.                 targets[#targets+1]=v
  245.             end
  246.         end
  247.     end
  248.     local function tunnel(f,t)
  249.         if not t then return end
  250.         local ft=distance(f,t)
  251.         for _,p in pairs(data.myteam)do
  252.             local fp=distance(f,p)
  253.             if fp<ft then
  254.                 local pt=distance(p,t)
  255.                 if p~=f and pt<ft and(pt+fp-p.r*2)<ft then
  256.                     t,ft=p,fp
  257.                 end
  258.             end
  259.         end
  260.         return t
  261.     end
  262.     local finish=control>.7
  263.     local GetTarget=function(f)
  264.         local teval,t=HUGE
  265.         for _,v in pairs(targets)do
  266.             local s=v.ships
  267.             if v.neutral then
  268.                 local dist=distance(f,v)
  269.                 for _,x in pairs(data.myfleets)do if x~=f and x.target==v.n then s=s-floor(x.ships)end end
  270.             else
  271.                 local close=distance(f,v)
  272.                 s=s+ceil(v.production*close/2000)
  273.             end
  274.             if floor(s)>=0 then
  275.                 local n=distance(f,v)/10+s-v.production/4
  276.                 if v.neutral then n=distance(f,v)/10 end
  277.                 if teval>n then teval,t=n,v end
  278.             end
  279.         end
  280.         return t
  281.     end
  282.     if finish then
  283.         GetTarget=function(f)
  284.             local teval,t=HUGE
  285.             for _,v in pairs(targets)do
  286.                 local d=distance(f,v)
  287.                 if teval>d then teval,t=d,v end
  288.             end
  289.             return t
  290.         end
  291.     end
  292.     local selected,maintarget,percent={}
  293.     local danger,help={},{}
  294.     for ind,f in pairs(data.myplanets)do
  295.         local available,dist=floor(f.ships),HUGE
  296.         for _,v in pairs(data.efleets)do
  297.             local targ=G[v.target]
  298.             if targ.neutral then
  299.                 if distance(targ,f)<100 then
  300.                     targ=f
  301.                 end
  302.             end
  303.             if targ==f then
  304.                 available=available-ceil(v.ships)
  305.                 dist=min(dist,distance(v,f)-f.r)
  306.             end
  307.         end
  308.         local h=0
  309.         for _,v in pairs(data.myfleets)do
  310.             if v.target==f.n then
  311.                 h=h+v.ships
  312.             end
  313.         end
  314.         help[f]=h
  315.         danger[f]=floor(available+f.production*dist/2000)
  316.     end
  317.     for ind,f in pairs(stuff)do
  318.         if f.is_planet then
  319.             local available=danger[f]or f.ships
  320.             if available>0 then
  321.                 local t0=GetTarget(f)
  322.                 local t=tunnel(f,t0)
  323.                 local low,t2=0
  324.                 for _,v in pairs(data.myplanets)do
  325.                     local d=(danger[v]or v.ships)+(help[v]or 0)
  326.                     if d<low then low,t2=d,v end
  327.                 end
  328.                 if t then
  329.                     if t2 and defend and not t.neutral and distance(t,f)>distance(t2,f)and t2~=f then t=t2 end
  330.                 elseif t2 and defend and t2~=f then
  331.                     t=t2
  332.                 end
  333.                 if t then
  334.                     if not maintarget then maintarget=t end
  335.                     if maintarget~=t and t0 then
  336.                         if distance(f,t0)+10>distance(f,maintarget)+distance(maintarget,t0)-maintarget.r*2 then
  337.                             t=maintarget
  338.                         end
  339.                     end
  340.                     if maintarget==t then
  341.                         local a=floor(available*20/f.ships)*5
  342.                         if t.neutral then a=min(a,ceil((t.ships+1)*20/f.ships)*10)end
  343.                         if not percent then percent=a end
  344.                         if percent<=a then
  345.                             t.ships=t.ships-floor(ceil(a*20/f.ships)*f.ships/20+.5)
  346.                             selected[#selected+1]=f.n
  347.                         end
  348.                     end
  349.                 end
  350.             end
  351.         else
  352.             local t=tunnel(f,GetTarget(f))
  353.             local low,t2=0
  354.             local targ=G[f.target]
  355.             for _,v in pairs(data.myplanets)do
  356.                 local d=(danger[v]or v.ships)+(help[v]or 0)
  357.                 if v==targ then d=d-f.ships end
  358.                 if d<low then low,t2=d,v end
  359.             end
  360.             if t then
  361.                 if t2 and defend and not t.neutral and distance(t,f)>distance(t2,f) then t=t2 end
  362.             elseif t2 and defend then
  363.                 t=t2
  364.             end
  365.             if t then
  366.                 if f.target~=t.n then
  367.                     if not maintarget then maintarget=t end
  368.                     if maintarget==t then
  369.                         f.target=t.n
  370.                         selected[#selected+1]=f.n
  371.                     end
  372.                 end
  373.             end
  374.         end
  375.     end
  376.     if maintarget and #selected>0 then
  377.         --[[if finish then
  378.             return send(50,{selected[1],selected[2]},maintarget)
  379.         end]]
  380.         return send(percent,selected,maintarget)
  381.     end
  382. end
  383.  
  384. function copy(o)
  385.     if type(o) ~= 'table' then return o end
  386.     local r = {}
  387.     for k,v in pairs(o) do r[k] = copy(v) end
  388.     return r
  389. end
  390.  
  391. function _bots_run(_data,uid,memory)
  392.     local data = copy(_data)
  393.     local res = bot({items=data, user=uid, memory=memory})
  394.     if not res then return end
  395.     local data = _data
  396.     local percent = res.percent or 50
  397.     percent = math.max(5,math.min(100,math.floor(percent/5 + .5) * 5))
  398.     local from = res.from ; if type(from) ~= 'table' then from = {from} end
  399.     local to = res.to
  400.     if data[to].is_planet then
  401.         for _,f in pairs(from) do
  402.             if data[f].is_planet and data[f].owner == uid then
  403.                 g2_fleet_send(percent,f,to)
  404.             end
  405.             if data[f].is_fleet and data[f].owner == uid and data[f].target ~= to then
  406.                 g2_fleet_redirect(data[f]._n,to)
  407.             end
  408.         end
  409.     end
  410. end
  411.  
  412. function loop(t)
  413.     if g2.state ~= "play" then return end
  414.     time = time + t
  415.     if time >= botrate then
  416.         time = time - botrate
  417.         local data = _bots_data()
  418.         _bots_run(data, enemy.n, botmemory)
  419.         if botvsbot then
  420.             _bots_run(data, player.n, bot2memory)
  421.         end
  422.     end
  423.    
  424.     local winner;
  425.     for _, p in pairs(g2.search("planet OR fleet -neutral")) do
  426.         local user = p:owner()
  427.         if not winner then
  428.             winner = user
  429.         elseif winner ~= user then
  430.             return
  431.         end
  432.     end
  433.    
  434.     if winner then
  435.         if winner.has_player then
  436.             init_pause("win")
  437.         else
  438.             init_pause("lose")
  439.         end
  440.     end
  441. end
  442.  
  443. function readmenu()
  444.     if g2.state ~= "menu" then return end
  445.     seed     = tonumber(g2.form.seed    ) or 0
  446.     neutrals = tonumber(g2.form.neutrals) or 24
  447.     homes    = tonumber(g2.form.homes   ) or 1
  448.     homeprod = tonumber(g2.form.homeprod) or 100
  449.     ships    = tonumber(g2.form.ships   ) or 100
  450.     prodmin  = tonumber(g2.form.prodmin ) or 15
  451.     prodmax  = tonumber(g2.form.prodmax ) or 100
  452.     costmin  = tonumber(g2.form.costmin ) or 0
  453.     costmax  = tonumber(g2.form.costmax ) or 50
  454.     botrate  = tonumber(g2.form.botrate ) or 0
  455.     speed    = tonumber(g2.form.speed   ) or 1
  456.     neutrals = neutrals + neutrals%2
  457.     if prodmin > prodmax then prodmin, prodmax = prodmax, prodmin end
  458.     if costmin > costmax then costmin, costmax = costmax, costmin end
  459.     g2.ticks = speed
  460. end
  461.  
  462. function refresh()
  463.     if g2.state == "menu" then
  464.         readmenu()
  465.         init_menu()
  466.     else
  467.         show_toggles()
  468.     end
  469. end
  470.  
  471. function event(e)
  472.     if e.type == "onclick" then
  473.         if e.value:sub(1,4) == "init" then
  474.             readmenu()
  475.             init_game()
  476.             init_getready()
  477.             botvsbot = e.value == "initbot"
  478.         elseif e.value == "newmap" then
  479.             readmenu()
  480.             seed = seed + 1
  481.             init_game()
  482.             init_getready()
  483.         elseif e.value == "restart" then
  484.             readmenu()
  485.             init_game()
  486.             init_getready()
  487.         elseif e.value == "resume" then
  488.             readmenu()
  489.             g2.state = "play"
  490.         elseif e.value == "menu" then
  491.             init_menu()
  492.         elseif e.value == "toggle" then
  493.             show_toggles()
  494.         elseif e.value == "quit" then
  495.             g2.state = "quit"
  496.         elseif e.value == "switch" then
  497.             if spawnside == "right" then
  498.                 spawnside = "left"
  499.             elseif spawnside == "left" then
  500.                 spawnside = "right"
  501.             end
  502.             for _, p in pairs(g2.search("planet -neutral")) do
  503.                 p:planet_chown(p:owner() == player and enemy or player)
  504.             end
  505.             for _, f in pairs(g2.search("fleet")) do
  506.                 for _, p in pairs(g2.search("planet")) do
  507.                     if p.n == f.fleet_target then
  508.                         g2.new_fleet(f:owner() == player and enemy or player, f.fleet_ships, f, p)
  509.                         f:destroy()
  510.                         break
  511.                     end
  512.                 end
  513.             end
  514.         elseif e.value == "crash" then
  515.             crash = not crash
  516.             refresh()
  517.             if running then
  518.                 local value = crash and 100 or 0
  519.                 player.fleet_crash  = value
  520.                 enemy.fleet_crash   = value
  521.                 for _, f in pairs(g2.search("fleet")) do
  522.                     for _, p in pairs(g2.search("planet")) do
  523.                         if p.n == f.fleet_target then
  524.                             g2.new_fleet(f:owner(), f.fleet_ships, f, p)
  525.                             f:destroy()
  526.                             break
  527.                         end
  528.                     end
  529.                 end
  530.             end
  531.         elseif e.value == "show" then
  532.             show = not show
  533.             refresh()
  534.             if running then
  535.                 player.ui_ships_show_mask = show and 0xf or 0x17
  536.             end
  537.         elseif e.value == "solid" then
  538.             solid = not solid
  539.             refresh()
  540.             if running then
  541.                 for _, p in pairs(g2.search("planet")) do
  542.                     p.has_collide = solid
  543.                 end
  544.             end
  545.         elseif e.value == "lockside" then
  546.             spawnside = spawnside == "random" and "right" or "random"
  547.             refresh()
  548.         elseif e.value == "bebot" then
  549.             botvsbot = not botvsbot
  550.             g2.state = "play"
  551.         elseif e.value == "pause" then
  552.             readmenu()
  553.             init_pause()
  554.         elseif e.value == "toggleback" then
  555.             botrate  = tonumber(g2.form.botrate ) or 0
  556.             speed    = tonumber(g2.form.speed   ) or 1
  557.             g2.ticks = speed
  558.             init_pause()
  559.         end
  560.     elseif e.type == "pause" then
  561.         init_pause()
  562.     end
  563. end
  564.  
  565. function init_menu()
  566.     g2.state = "menu"
  567.     g2.html  = [[<table>
  568.     <tr><td colspan=6><h1>Waffle3z's Bot 1v1</h1>
  569.     <tr><td><p>&nbsp;</p>
  570.     <tr><td><p>Map seed:            </p><td colspan=2><input type='text' name='seed'    />
  571.         <td><p>Bot move time:       </p><td colspan=2><input type='text' name='botrate' />
  572.     <tr><td><p>Neutrals:            </p><td colspan=2><input type='text' name='neutrals'/>
  573.         <td><p>Homes:               </p><td colspan=2><input type='text' name='homes'   />
  574.     <tr><td><p>Home production:     </p><td colspan=2><input type='text' name='homeprod'/>
  575.         <td><p>Starting ships:      </p><td colspan=2><input type='text' name='ships'   />
  576.     <tr><td><p>Neutral prod range:  </p><td><input type='text' name='prodmin' /><td><input type='text' name='prodmax' />
  577.         <td colspan=3><input type='button'      name='crash' value='Ships crash'   onclick='crash'    class='ibutton]]..(crash and 2 or 1)..[[' icon='klass-fighter'/>
  578.     <tr><td><p>Neutral cost range:  </p><td><input type='text' name='costmin' /><td><input type='text' name='costmax' />
  579.         <td colspan=3><input type='button'      name='show'  value='Enemy ships'   onclick='show'     class='ibutton]]..(show  and 2 or 1)..[[' icon='icon-search'  />
  580.     <tr><td><p>Game speed:          </p><td colspan=2><input type='text' name='speed'/>
  581.         <td colspan=3><input type='button'      name='show'  value='Solid planets' onclick='solid'    class='ibutton]]..(solid and 2 or 1)..[[' icon='icon-world'   />
  582.     <tr><td colspan=3><p>&nbsp;</p>
  583.         <td colspan=3><input type='button'      name='show'  value='Lock side'     onclick='lockside' class='ibutton]]..(spawnside == "random" and 1 or 2)..[[' icon='icon-forever'/>]]
  584.     if running then
  585.         g2.html = g2.html..[[
  586.         <tr><td colspan=6><table><tr><td><input type='button' value='Resume'  onclick='pause'  class='ibutton1' icon='icon-play'   /></table>
  587.         <tr><td colspan=6><table><tr><td><input type='button' value='Restart' onclick='init'   class='ibutton1' icon='icon-restart'/></table>
  588.         <tr><td colspan=6><table><tr><td><input type='button' value='New Map' onclick='newmap' class='ibutton1' icon='icon-new_map'/></table>]]
  589.     else
  590.         g2.html = g2.html..[[
  591.         <tr><td colspan=6><table><tr><td><input type='button' value='Play'       onclick='init'    class='ibutton1' icon='icon-play'   /></table>
  592.         <tr><td colspan=6><table><tr><td><input type='button' value='Bot VS Bot' onclick='initbot' class='ibutton1' icon='icon-rivalry'/></table>
  593.         </table>]]
  594.     end
  595.     g2.form.seed     = seed
  596.     g2.form.neutrals = neutrals
  597.     g2.form.homes    = homes
  598.     g2.form.homeprod = homeprod
  599.     g2.form.ships    = ships
  600.     g2.form.prodmin  = prodmin
  601.     g2.form.prodmax  = prodmax
  602.     g2.form.costmin  = costmin
  603.     g2.form.costmax  = costmax
  604.     g2.form.botrate  = botrate
  605.     g2.form.speed    = speed
  606. end
  607. init = init_menu
  608.  
  609. function show_toggles()
  610.     g2.html = [[<table>
  611.         <tr><td colspan=2><input type='button' name='crash' value='Ships crash'   onclick='crash' class='ibutton]]..(crash and 2 or 1)..[[' icon='klass-fighter'/>
  612.         <tr><td colspan=2><input type='button' name='show'  value='Enemy ships'   onclick='show'  class='ibutton]]..(show  and 2 or 1)..[[' icon='icon-search'  />
  613.         <tr><td colspan=2><input type='button' name='show'  value='Solid planets' onclick='solid' class='ibutton]]..(solid and 2 or 1)..[[' icon='icon-world'   />
  614.         <tr><td><p>Game speed:          </p><td><input type='text' name='speed'  />
  615.         <tr><td><p>Bot move time:       </p><td><input type='text' name='botrate'/>
  616.         <tr><td colspan=2><input type='button' value='Back' onclick='toggleback' class='ibutton1' icon='icon-restart'/>
  617.     ]]
  618.     g2.form.speed    = speed
  619.     g2.form.botrate  = botrate
  620. end
  621.  
  622. function init_getready()
  623.     g2.state = "pause"
  624.     g2.html  = [[<table>
  625.     <tr><td><h1>Get Ready!</h1>
  626.     <tr><td><input type='button' value='Begin'        onclick='resume' class='ibutton1'                             icon='icon-play'    />
  627.     <tr><td><input type='button' value='Become bot'   onclick='bebot'  class='ibutton]]..(botvsbot and 2 or 1)..[[' icon='icon-rivalry' />
  628.     <tr><td><input type='button' value='Switch sides' onclick='switch' class='ibutton1'                             icon='icon-forever' />
  629.     <tr><td><input type='button' value='New Map'      onclick='newmap' class='ibutton1'                             icon='icon-new_map' />
  630.     <tr><td><input type='button' value='Toggles'      onclick='toggle' class='ibutton1'                             icon='icon-custom'  />
  631.     <tr><td><input type='button' value='Menu'         onclick='menu'   class='ibutton1'                             icon='icon-settings'/>]]
  632. end
  633.  
  634. function init_pause(x)
  635.     g2.state = "pause"
  636.     g2.html  = [[<table>
  637.     <tr><td><input type='button' value='Resume'  onclick='resume'  class='ibutton1' icon='icon-resume' />
  638.     <tr><td><input type='button' value='Restart' onclick='restart' class='ibutton1' icon='icon-restart'/>]]
  639.     if x == "win" then
  640.         running = false
  641.         g2.html = [[<table>
  642.         <tr><td><h1>Good Job!</h1>
  643.         <tr><td><input type='button' value='Replay'  onclick='restart' class='ibutton1' icon='icon-restart' />
  644.         <tr><td><input type='button' value='New Map' onclick='newmap'  class='ibutton1' icon='icon-new_map' />
  645.         <tr><td><input type='button' value='Menu'    onclick='menu'    class='ibutton1' icon='icon-settings'/>]]
  646.     elseif x == "lose" then
  647.         running = false
  648.         g2.html = [[<table>
  649.         <tr><td><input type='button' value='Try Again' onclick='restart' class='ibutton1' icon='icon-restart' />
  650.         <tr><td><input type='button' value='New Map'   onclick='newmap'  class='ibutton1' icon='icon-new_map' />
  651.         <tr><td><input type='button' value='Menu'      onclick='menu'    class='ibutton1' icon='icon-settings'/>]]
  652.     else
  653.         g2.html = g2.html..[[
  654.         <tr><td><input type='button' value='Become bot'   onclick='bebot'  class='ibutton]]..(botvsbot and 2 or 1)..[[' icon='icon-rivalry' />
  655.         <tr><td><input type='button' value='Switch sides' onclick='switch' class='ibutton1'                             icon='icon-forever' />
  656.         <tr><td><input type='button' value='New Map'      onclick='newmap' class='ibutton1'                             icon='icon-new_map' />
  657.         <tr><td><input type='button' value='Toggles'      onclick='toggle' class='ibutton1'                             icon='icon-custom'  />
  658.         <tr><td><input type='button' value='Menu'         onclick='menu'   class='ibutton1'                             icon='icon-settings'/>]]
  659.     end
  660.     g2.html = g2.html..[[]]
  661. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement