share/hedgewars/Data/Scripts/Multiplayer/Gravity.lua
changeset 11899 dd3cbbde7876
parent 11898 25a6faa5ac46
child 12819 b4e20bb485f9
equal deleted inserted replaced
11898:25a6faa5ac46 11899:dd3cbbde7876
    16 local mln = 1000000
    16 local mln = 1000000
    17 local lowGravityUsed = false
    17 local lowGravityUsed = false
    18 
    18 
    19 local script2_onNewTurn
    19 local script2_onNewTurn
    20 local script2_onGameTick20
    20 local script2_onGameTick20
    21 local script2_onGameStart
    21 local script2_onGameInit
    22 local script2_onHogAttack
    22 local script2_onHogAttack
    23 
    23 
    24 
    24 
    25 function grav_onNewTurn()
    25 function grav_onNewTurn()
    26     lowGravityUsed = false
    26     lowGravityUsed = false
    86 end
    86 end
    87 
    87 
    88 function onParameters()
    88 function onParameters()
    89     parseParams()
    89     parseParams()
    90 
    90 
    91     gravity = tonumber(params["g"]) or 100
    91     gravity = tonumber(params["g"]) or gravity
    92 
    92 
    93     mingravity_normal = gravity
    93     mingravity_normal = gravity
    94     if mingravity_normal > 0 then
    94     if mingravity_normal > 0 then
    95         mingravity_low = div(mingravity_normal, 2)
    95         mingravity_low = div(mingravity_normal, 2)
    96     else
    96     else
   144         onParameters = nil
   144         onParameters = nil
   145         HedgewarsScriptLoad("/Scripts/Multiplayer/" .. secondScript .. ".lua")
   145         HedgewarsScriptLoad("/Scripts/Multiplayer/" .. secondScript .. ".lua")
   146         
   146         
   147         script2_onNewTurn = onNewTurn
   147         script2_onNewTurn = onNewTurn
   148         script2_onGameTick20 = onGameTick20
   148         script2_onGameTick20 = onGameTick20
   149         script2_onGameStart = onGameStart
   149         script2_onGameInit = onGameInit
   150         script2_onHogAttack = onHogAttack
   150         script2_onHogAttack = onHogAttack
   151                 
   151                 
   152         if onParameters ~= nil then
   152         if onParameters ~= nil then
   153             onParameters()
   153             onParameters()
   154         end
   154         end
   155     end
   155     end
   156     
   156     
   157     onNewTurn = grav_onNewTurn
   157     onNewTurn = grav_onNewTurn
   158     onGameTick20 = grav_onGameTick20
   158     onGameTick20 = grav_onGameTick20
   159     onGameStart = grav_onGameStart
   159     onGameInit = grav_onGameInit
   160     onHogAttack = grav_onHogAttack
   160     onHogAttack = grav_onHogAttack
   161 end
   161 end
   162 
   162 
   163 function grav_onGameStart()
   163 function grav_onGameInit()
   164     DisableGameFlags(gfLowGravity)
   164     DisableGameFlags(gfLowGravity)
   165 
   165 
       
   166     local v, printperiod
       
   167     if period ~= nil then
       
   168         local period_ms = period * 40
       
   169         if period_ms % 1000 == 0 then
       
   170             printperiod = string.format(loc("%i s"), div(period_ms, 1000))
       
   171         else
       
   172             printperiod = string.format(loc("%i ms"), period_ms)
       
   173         end
       
   174     end
   166     if delta == nil then
   175     if delta == nil then
   167         v = string.format(loc("random in range from %i%% to %i%% with period of %i msec"), div(mingravity_normal, mln), div(maxgravity_normal, mln), period * 40)
   176         v = string.format(loc("Crazy Gravity: Gravity randomly changes within a range from %i%% to %i%% with a period of %s"), div(mingravity_normal, mln), div(maxgravity_normal, mln), printperiod)
   168     elseif period ~= nil then
   177     elseif period ~= nil then
   169         v = string.format(loc("changing range from %i%% to %i%% with period of %i msec"), div(mingravity_normal, mln), div(maxgravity_normal, mln), period * 40)
   178         v = string.format(loc("Oscillating Gravity: Gravity periodically changes within a range from %i%% to %i%% with a period of %s"), div(mingravity_normal, mln), div(maxgravity_normal, mln), printperiod)
   170     else
   179     elseif gravity > 100 then
   171         v = gravity .. "%"
   180         v = string.format(loc("High Gravity: Gravity is %i%%"), gravity)
   172     end
   181     elseif gravity < 100 then
   173 
   182         v = string.format(loc("Low Gravity: Gravity is %i%%"), gravity)
   174     ShowMission(loc("Gravity"),
   183     else
   175                 loc("Current setting is ") .. v,
   184         v = loc("Gravity: 100%") .. "|" ..
   176                 loc("Setup:|'g=150', where 150 is 150% of normal gravity") .. "|"
   185             loc("Script parameter examples:") .. "|" ..
   177                 .. loc("or 'g=50, g2=150, period=4000' for gravity changing|from 50 to 150 and back with period of 4000 msec")
   186             loc("“g=150”, where 150 is 150% of normal gravity.") .. "|" ..
   178                 .. "||" .. loc("Set period to negative value for random gravity"),
   187             loc("“g=50, g2=150, period=4000” for gravity changing|from 50 to 150 and back with period of 4000 ms.") .. "|" ..
   179                 0, 5000)
   188             loc("Set period to negative value for random gravity.") .. "| |"
   180                 
   189     end
   181     if script2_onGameStart ~= nil then
   190     Goals = v
   182         script2_onGameStart()
   191 
       
   192     if script2_onGameInit ~= nil then
       
   193         script2_onGameInit()
   183     end
   194     end
   184 end
   195 end
   185 
   196 
   186 function grav_onHogAttack(ammoType)
   197 function grav_onHogAttack(ammoType)
   187     if ammoType == amLowGravity then
   198     if ammoType == amLowGravity then