share/hedgewars/Data/Scripts/Multiplayer/Gravity.lua
author Wuzzy <Wuzzy2@mail.ru>
Sat, 20 Apr 2019 16:46:07 +0200
changeset 14844 358d81e29a88
parent 12814 b4e20bb485f9
permissions -rw-r--r--
Space Invasion: Fix minor visual glitches of shield
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
9836
00cbbb195f11 Rework of No Gravity script:
unc0rr
parents: 9819
diff changeset
     1
HedgewarsScriptLoad("/Scripts/Locale.lua")
9906
93c16a4b0c6a Only emit roomNameUpdated when it actually is changed
unc0rr
parents: 9902
diff changeset
     2
HedgewarsScriptLoad("/Scripts/Params.lua")
9836
00cbbb195f11 Rework of No Gravity script:
unc0rr
parents: 9819
diff changeset
     3
00cbbb195f11 Rework of No Gravity script:
unc0rr
parents: 9819
diff changeset
     4
local gravity = 100
9908
81eb25ddf594 - Utility script for parameters handling
unc0rr
parents: 9906
diff changeset
     5
local mingravity
81eb25ddf594 - Utility script for parameters handling
unc0rr
parents: 9906
diff changeset
     6
local maxgravity
11893
25a6faa5ac46 Fix low gravity utility not working in Gravity script (fixes #13)
Wuzzy <almikes@aol.com>
parents: 10758
diff changeset
     7
local mingravity_normal
25a6faa5ac46 Fix low gravity utility not working in Gravity script (fixes #13)
Wuzzy <almikes@aol.com>
parents: 10758
diff changeset
     8
local maxgravity_normal
25a6faa5ac46 Fix low gravity utility not working in Gravity script (fixes #13)
Wuzzy <almikes@aol.com>
parents: 10758
diff changeset
     9
local mingravity_low
25a6faa5ac46 Fix low gravity utility not working in Gravity script (fixes #13)
Wuzzy <almikes@aol.com>
parents: 10758
diff changeset
    10
local maxgravity_low
9908
81eb25ddf594 - Utility script for parameters handling
unc0rr
parents: 9906
diff changeset
    11
local delta = 0
81eb25ddf594 - Utility script for parameters handling
unc0rr
parents: 9906
diff changeset
    12
local period
81eb25ddf594 - Utility script for parameters handling
unc0rr
parents: 9906
diff changeset
    13
local periodtimer = 0
9836
00cbbb195f11 Rework of No Gravity script:
unc0rr
parents: 9819
diff changeset
    14
local wdGameTicks = 0
00cbbb195f11 Rework of No Gravity script:
unc0rr
parents: 9819
diff changeset
    15
local wdTTL = 0
9908
81eb25ddf594 - Utility script for parameters handling
unc0rr
parents: 9906
diff changeset
    16
local mln = 1000000
11893
25a6faa5ac46 Fix low gravity utility not working in Gravity script (fixes #13)
Wuzzy <almikes@aol.com>
parents: 10758
diff changeset
    17
local lowGravityUsed = false
9836
00cbbb195f11 Rework of No Gravity script:
unc0rr
parents: 9819
diff changeset
    18
9985
42cd42e44c9a GravRacer, GravHigh, GravMutant, Grav... uhm... shoppamap? Easy! Gravity script could be combined with any other script now.
unc0rr
parents: 9910
diff changeset
    19
local script2_onNewTurn
42cd42e44c9a GravRacer, GravHigh, GravMutant, Grav... uhm... shoppamap? Easy! Gravity script could be combined with any other script now.
unc0rr
parents: 9910
diff changeset
    20
local script2_onGameTick20
11894
dd3cbbde7876 Improve mission panel in Gravity script (don't overwrite game modifier texts)
Wuzzy <almikes@aol.com>
parents: 11893
diff changeset
    21
local script2_onGameInit
11893
25a6faa5ac46 Fix low gravity utility not working in Gravity script (fixes #13)
Wuzzy <almikes@aol.com>
parents: 10758
diff changeset
    22
local script2_onHogAttack
9985
42cd42e44c9a GravRacer, GravHigh, GravMutant, Grav... uhm... shoppamap? Easy! Gravity script could be combined with any other script now.
unc0rr
parents: 9910
diff changeset
    23
42cd42e44c9a GravRacer, GravHigh, GravMutant, Grav... uhm... shoppamap? Easy! Gravity script could be combined with any other script now.
unc0rr
parents: 9910
diff changeset
    24
42cd42e44c9a GravRacer, GravHigh, GravMutant, Grav... uhm... shoppamap? Easy! Gravity script could be combined with any other script now.
unc0rr
parents: 9910
diff changeset
    25
function grav_onNewTurn()
11893
25a6faa5ac46 Fix low gravity utility not working in Gravity script (fixes #13)
Wuzzy <almikes@aol.com>
parents: 10758
diff changeset
    26
    lowGravityUsed = false
25a6faa5ac46 Fix low gravity utility not working in Gravity script (fixes #13)
Wuzzy <almikes@aol.com>
parents: 10758
diff changeset
    27
    if maxgravity_normal == nil then
25a6faa5ac46 Fix low gravity utility not working in Gravity script (fixes #13)
Wuzzy <almikes@aol.com>
parents: 10758
diff changeset
    28
        gravity = mingravity_normal
25a6faa5ac46 Fix low gravity utility not working in Gravity script (fixes #13)
Wuzzy <almikes@aol.com>
parents: 10758
diff changeset
    29
    else
25a6faa5ac46 Fix low gravity utility not working in Gravity script (fixes #13)
Wuzzy <almikes@aol.com>
parents: 10758
diff changeset
    30
        mingravity = mingravity_normal
25a6faa5ac46 Fix low gravity utility not working in Gravity script (fixes #13)
Wuzzy <almikes@aol.com>
parents: 10758
diff changeset
    31
        maxgravity = maxgravity_normal
25a6faa5ac46 Fix low gravity utility not working in Gravity script (fixes #13)
Wuzzy <almikes@aol.com>
parents: 10758
diff changeset
    32
        if period > 0 then
25a6faa5ac46 Fix low gravity utility not working in Gravity script (fixes #13)
Wuzzy <almikes@aol.com>
parents: 10758
diff changeset
    33
           delta = div(maxgravity_normal - mingravity_normal, period)
25a6faa5ac46 Fix low gravity utility not working in Gravity script (fixes #13)
Wuzzy <almikes@aol.com>
parents: 10758
diff changeset
    34
        end
25a6faa5ac46 Fix low gravity utility not working in Gravity script (fixes #13)
Wuzzy <almikes@aol.com>
parents: 10758
diff changeset
    35
    end
10738
62659c427e5d Fix setting gravity multiplied by million for a moment of time on new turn on certain circumstances
unc0rr
parents: 10509
diff changeset
    36
    if delta ~= nil and period == nil then 
62659c427e5d Fix setting gravity multiplied by million for a moment of time on new turn on certain circumstances
unc0rr
parents: 10509
diff changeset
    37
      SetGravity(gravity)
62659c427e5d Fix setting gravity multiplied by million for a moment of time on new turn on certain circumstances
unc0rr
parents: 10509
diff changeset
    38
    else
62659c427e5d Fix setting gravity multiplied by million for a moment of time on new turn on certain circumstances
unc0rr
parents: 10509
diff changeset
    39
      SetGravity(div(gravity, mln))
62659c427e5d Fix setting gravity multiplied by million for a moment of time on new turn on certain circumstances
unc0rr
parents: 10509
diff changeset
    40
    end
62659c427e5d Fix setting gravity multiplied by million for a moment of time on new turn on certain circumstances
unc0rr
parents: 10509
diff changeset
    41
    
9836
00cbbb195f11 Rework of No Gravity script:
unc0rr
parents: 9819
diff changeset
    42
    wdGameTicks = GameTime
9985
42cd42e44c9a GravRacer, GravHigh, GravMutant, Grav... uhm... shoppamap? Easy! Gravity script could be combined with any other script now.
unc0rr
parents: 9910
diff changeset
    43
    
42cd42e44c9a GravRacer, GravHigh, GravMutant, Grav... uhm... shoppamap? Easy! Gravity script could be combined with any other script now.
unc0rr
parents: 9910
diff changeset
    44
    if script2_onNewTurn ~= nil then
42cd42e44c9a GravRacer, GravHigh, GravMutant, Grav... uhm... shoppamap? Easy! Gravity script could be combined with any other script now.
unc0rr
parents: 9910
diff changeset
    45
        script2_onNewTurn()
42cd42e44c9a GravRacer, GravHigh, GravMutant, Grav... uhm... shoppamap? Easy! Gravity script could be combined with any other script now.
unc0rr
parents: 9910
diff changeset
    46
    end    
9816
e71188c140ee No gravity mode
unc0rr
parents:
diff changeset
    47
end
e71188c140ee No gravity mode
unc0rr
parents:
diff changeset
    48
9985
42cd42e44c9a GravRacer, GravHigh, GravMutant, Grav... uhm... shoppamap? Easy! Gravity script could be combined with any other script now.
unc0rr
parents: 9910
diff changeset
    49
function grav_onGameTick20()
9898
b87695f82d2e Don't set gravity to normal immediately on turn end, let watchdog do its job if game gets frozen
unc0rr
parents: 9836
diff changeset
    50
    if wdGameTicks + 15000 < GameTime then
9816
e71188c140ee No gravity mode
unc0rr
parents:
diff changeset
    51
        SetGravity(100)
9908
81eb25ddf594 - Utility script for parameters handling
unc0rr
parents: 9906
diff changeset
    52
    else
81eb25ddf594 - Utility script for parameters handling
unc0rr
parents: 9906
diff changeset
    53
        if wdTTL ~= TurnTimeLeft then
81eb25ddf594 - Utility script for parameters handling
unc0rr
parents: 9906
diff changeset
    54
            wdGameTicks = GameTime
81eb25ddf594 - Utility script for parameters handling
unc0rr
parents: 9906
diff changeset
    55
        end
81eb25ddf594 - Utility script for parameters handling
unc0rr
parents: 9906
diff changeset
    56
81eb25ddf594 - Utility script for parameters handling
unc0rr
parents: 9906
diff changeset
    57
        if delta == nil then
81eb25ddf594 - Utility script for parameters handling
unc0rr
parents: 9906
diff changeset
    58
            if periodtimer == 0 then
81eb25ddf594 - Utility script for parameters handling
unc0rr
parents: 9906
diff changeset
    59
                periodtimer = period * 2
10758
0f3a0f117810 Random gravity values interval should include maxgravity
unc0rr
parents: 10738
diff changeset
    60
                SetGravity(div(GetRandom(maxgravity - mingravity + 1) + mingravity, mln))
9908
81eb25ddf594 - Utility script for parameters handling
unc0rr
parents: 9906
diff changeset
    61
            else
81eb25ddf594 - Utility script for parameters handling
unc0rr
parents: 9906
diff changeset
    62
                periodtimer = periodtimer - 1
81eb25ddf594 - Utility script for parameters handling
unc0rr
parents: 9906
diff changeset
    63
            end
81eb25ddf594 - Utility script for parameters handling
unc0rr
parents: 9906
diff changeset
    64
        elseif delta == 0 then
81eb25ddf594 - Utility script for parameters handling
unc0rr
parents: 9906
diff changeset
    65
            SetGravity(gravity)
81eb25ddf594 - Utility script for parameters handling
unc0rr
parents: 9906
diff changeset
    66
        else
81eb25ddf594 - Utility script for parameters handling
unc0rr
parents: 9906
diff changeset
    67
            if delta > 0 and gravity + delta > maxgravity then
81eb25ddf594 - Utility script for parameters handling
unc0rr
parents: 9906
diff changeset
    68
                gravity = maxgravity
81eb25ddf594 - Utility script for parameters handling
unc0rr
parents: 9906
diff changeset
    69
                delta = -delta
10509
d62d3c706947 some gravity script fixes
sheepluva
parents: 9985
diff changeset
    70
            elseif delta < 0 and gravity + delta < mingravity then
9908
81eb25ddf594 - Utility script for parameters handling
unc0rr
parents: 9906
diff changeset
    71
                gravity = mingravity
81eb25ddf594 - Utility script for parameters handling
unc0rr
parents: 9906
diff changeset
    72
                delta = -delta
81eb25ddf594 - Utility script for parameters handling
unc0rr
parents: 9906
diff changeset
    73
            else
81eb25ddf594 - Utility script for parameters handling
unc0rr
parents: 9906
diff changeset
    74
                gravity = gravity + delta
81eb25ddf594 - Utility script for parameters handling
unc0rr
parents: 9906
diff changeset
    75
            end
81eb25ddf594 - Utility script for parameters handling
unc0rr
parents: 9906
diff changeset
    76
81eb25ddf594 - Utility script for parameters handling
unc0rr
parents: 9906
diff changeset
    77
            SetGravity(div(gravity, mln))
81eb25ddf594 - Utility script for parameters handling
unc0rr
parents: 9906
diff changeset
    78
        end
9816
e71188c140ee No gravity mode
unc0rr
parents:
diff changeset
    79
    end
9836
00cbbb195f11 Rework of No Gravity script:
unc0rr
parents: 9819
diff changeset
    80
00cbbb195f11 Rework of No Gravity script:
unc0rr
parents: 9819
diff changeset
    81
    wdTTL = TurnTimeLeft
9985
42cd42e44c9a GravRacer, GravHigh, GravMutant, Grav... uhm... shoppamap? Easy! Gravity script could be combined with any other script now.
unc0rr
parents: 9910
diff changeset
    82
    
42cd42e44c9a GravRacer, GravHigh, GravMutant, Grav... uhm... shoppamap? Easy! Gravity script could be combined with any other script now.
unc0rr
parents: 9910
diff changeset
    83
    if script2_onGameTick20 ~= nil then
42cd42e44c9a GravRacer, GravHigh, GravMutant, Grav... uhm... shoppamap? Easy! Gravity script could be combined with any other script now.
unc0rr
parents: 9910
diff changeset
    84
        script2_onGameTick20()
42cd42e44c9a GravRacer, GravHigh, GravMutant, Grav... uhm... shoppamap? Easy! Gravity script could be combined with any other script now.
unc0rr
parents: 9910
diff changeset
    85
    end    
9816
e71188c140ee No gravity mode
unc0rr
parents:
diff changeset
    86
end
9836
00cbbb195f11 Rework of No Gravity script:
unc0rr
parents: 9819
diff changeset
    87
9985
42cd42e44c9a GravRacer, GravHigh, GravMutant, Grav... uhm... shoppamap? Easy! Gravity script could be combined with any other script now.
unc0rr
parents: 9910
diff changeset
    88
function onParameters()
9906
93c16a4b0c6a Only emit roomNameUpdated when it actually is changed
unc0rr
parents: 9902
diff changeset
    89
    parseParams()
9908
81eb25ddf594 - Utility script for parameters handling
unc0rr
parents: 9906
diff changeset
    90
11894
dd3cbbde7876 Improve mission panel in Gravity script (don't overwrite game modifier texts)
Wuzzy <almikes@aol.com>
parents: 11893
diff changeset
    91
    gravity = tonumber(params["g"]) or gravity
9908
81eb25ddf594 - Utility script for parameters handling
unc0rr
parents: 9906
diff changeset
    92
11893
25a6faa5ac46 Fix low gravity utility not working in Gravity script (fixes #13)
Wuzzy <almikes@aol.com>
parents: 10758
diff changeset
    93
    mingravity_normal = gravity
25a6faa5ac46 Fix low gravity utility not working in Gravity script (fixes #13)
Wuzzy <almikes@aol.com>
parents: 10758
diff changeset
    94
    if mingravity_normal > 0 then
25a6faa5ac46 Fix low gravity utility not working in Gravity script (fixes #13)
Wuzzy <almikes@aol.com>
parents: 10758
diff changeset
    95
        mingravity_low = div(mingravity_normal, 2)
25a6faa5ac46 Fix low gravity utility not working in Gravity script (fixes #13)
Wuzzy <almikes@aol.com>
parents: 10758
diff changeset
    96
    else
25a6faa5ac46 Fix low gravity utility not working in Gravity script (fixes #13)
Wuzzy <almikes@aol.com>
parents: 10758
diff changeset
    97
        mingravity_low = mingravity_normal * 2
25a6faa5ac46 Fix low gravity utility not working in Gravity script (fixes #13)
Wuzzy <almikes@aol.com>
parents: 10758
diff changeset
    98
    end
25a6faa5ac46 Fix low gravity utility not working in Gravity script (fixes #13)
Wuzzy <almikes@aol.com>
parents: 10758
diff changeset
    99
    mingravity = mingravity_normal
25a6faa5ac46 Fix low gravity utility not working in Gravity script (fixes #13)
Wuzzy <almikes@aol.com>
parents: 10758
diff changeset
   100
    if type(tonumber(params["g2"])) == "number" then
25a6faa5ac46 Fix low gravity utility not working in Gravity script (fixes #13)
Wuzzy <almikes@aol.com>
parents: 10758
diff changeset
   101
        maxgravity_normal = tonumber(params["g2"])
25a6faa5ac46 Fix low gravity utility not working in Gravity script (fixes #13)
Wuzzy <almikes@aol.com>
parents: 10758
diff changeset
   102
        if maxgravity_normal > 0 then
25a6faa5ac46 Fix low gravity utility not working in Gravity script (fixes #13)
Wuzzy <almikes@aol.com>
parents: 10758
diff changeset
   103
            maxgravity_low = div(maxgravity_normal, 2)
25a6faa5ac46 Fix low gravity utility not working in Gravity script (fixes #13)
Wuzzy <almikes@aol.com>
parents: 10758
diff changeset
   104
        else
25a6faa5ac46 Fix low gravity utility not working in Gravity script (fixes #13)
Wuzzy <almikes@aol.com>
parents: 10758
diff changeset
   105
            maxgravity_low = maxgravity_normal * 2
25a6faa5ac46 Fix low gravity utility not working in Gravity script (fixes #13)
Wuzzy <almikes@aol.com>
parents: 10758
diff changeset
   106
        end
25a6faa5ac46 Fix low gravity utility not working in Gravity script (fixes #13)
Wuzzy <almikes@aol.com>
parents: 10758
diff changeset
   107
        maxgravity = maxgravity_normal
25a6faa5ac46 Fix low gravity utility not working in Gravity script (fixes #13)
Wuzzy <almikes@aol.com>
parents: 10758
diff changeset
   108
    end
9908
81eb25ddf594 - Utility script for parameters handling
unc0rr
parents: 9906
diff changeset
   109
    period = params["period"]
81eb25ddf594 - Utility script for parameters handling
unc0rr
parents: 9906
diff changeset
   110
11893
25a6faa5ac46 Fix low gravity utility not working in Gravity script (fixes #13)
Wuzzy <almikes@aol.com>
parents: 10758
diff changeset
   111
    if type(mingravity) == "number" and type(maxgravity) == "number" then
9908
81eb25ddf594 - Utility script for parameters handling
unc0rr
parents: 9906
diff changeset
   112
        if period ~= nil then
81eb25ddf594 - Utility script for parameters handling
unc0rr
parents: 9906
diff changeset
   113
            period = div(period, 40)
81eb25ddf594 - Utility script for parameters handling
unc0rr
parents: 9906
diff changeset
   114
        else
81eb25ddf594 - Utility script for parameters handling
unc0rr
parents: 9906
diff changeset
   115
            period = 125
81eb25ddf594 - Utility script for parameters handling
unc0rr
parents: 9906
diff changeset
   116
        end
81eb25ddf594 - Utility script for parameters handling
unc0rr
parents: 9906
diff changeset
   117
10509
d62d3c706947 some gravity script fixes
sheepluva
parents: 9985
diff changeset
   118
        mingravity = mingravity * mln
11893
25a6faa5ac46 Fix low gravity utility not working in Gravity script (fixes #13)
Wuzzy <almikes@aol.com>
parents: 10758
diff changeset
   119
        mingravity_normal = mingravity_normal * mln
25a6faa5ac46 Fix low gravity utility not working in Gravity script (fixes #13)
Wuzzy <almikes@aol.com>
parents: 10758
diff changeset
   120
        mingravity_low = mingravity_low * mln
10509
d62d3c706947 some gravity script fixes
sheepluva
parents: 9985
diff changeset
   121
        maxgravity = maxgravity * mln
11893
25a6faa5ac46 Fix low gravity utility not working in Gravity script (fixes #13)
Wuzzy <almikes@aol.com>
parents: 10758
diff changeset
   122
        maxgravity_normal = maxgravity_normal * mln
25a6faa5ac46 Fix low gravity utility not working in Gravity script (fixes #13)
Wuzzy <almikes@aol.com>
parents: 10758
diff changeset
   123
        maxgravity_low = maxgravity_low * mln
10509
d62d3c706947 some gravity script fixes
sheepluva
parents: 9985
diff changeset
   124
9908
81eb25ddf594 - Utility script for parameters handling
unc0rr
parents: 9906
diff changeset
   125
        if mingravity > maxgravity then
81eb25ddf594 - Utility script for parameters handling
unc0rr
parents: 9906
diff changeset
   126
            mingravity, maxgravity = maxgravity, mingravity
11893
25a6faa5ac46 Fix low gravity utility not working in Gravity script (fixes #13)
Wuzzy <almikes@aol.com>
parents: 10758
diff changeset
   127
            mingravity_normal, maxgravity_normal = maxgravity_normal, mingravity_normal
25a6faa5ac46 Fix low gravity utility not working in Gravity script (fixes #13)
Wuzzy <almikes@aol.com>
parents: 10758
diff changeset
   128
            mingravity_low, maxgravity_low = maxgravity_low, mingravity_low
9908
81eb25ddf594 - Utility script for parameters handling
unc0rr
parents: 9906
diff changeset
   129
        end
81eb25ddf594 - Utility script for parameters handling
unc0rr
parents: 9906
diff changeset
   130
81eb25ddf594 - Utility script for parameters handling
unc0rr
parents: 9906
diff changeset
   131
        gravity = mingravity
81eb25ddf594 - Utility script for parameters handling
unc0rr
parents: 9906
diff changeset
   132
81eb25ddf594 - Utility script for parameters handling
unc0rr
parents: 9906
diff changeset
   133
        if period > 0 then
11893
25a6faa5ac46 Fix low gravity utility not working in Gravity script (fixes #13)
Wuzzy <almikes@aol.com>
parents: 10758
diff changeset
   134
            delta = div(maxgravity_normal - mingravity_normal, period)
9908
81eb25ddf594 - Utility script for parameters handling
unc0rr
parents: 9906
diff changeset
   135
        else
81eb25ddf594 - Utility script for parameters handling
unc0rr
parents: 9906
diff changeset
   136
            period = -period
81eb25ddf594 - Utility script for parameters handling
unc0rr
parents: 9906
diff changeset
   137
            delta = nil
81eb25ddf594 - Utility script for parameters handling
unc0rr
parents: 9906
diff changeset
   138
        end
81eb25ddf594 - Utility script for parameters handling
unc0rr
parents: 9906
diff changeset
   139
    end
9985
42cd42e44c9a GravRacer, GravHigh, GravMutant, Grav... uhm... shoppamap? Easy! Gravity script could be combined with any other script now.
unc0rr
parents: 9910
diff changeset
   140
    
42cd42e44c9a GravRacer, GravHigh, GravMutant, Grav... uhm... shoppamap? Easy! Gravity script could be combined with any other script now.
unc0rr
parents: 9910
diff changeset
   141
    secondScript = params["script2"]
42cd42e44c9a GravRacer, GravHigh, GravMutant, Grav... uhm... shoppamap? Easy! Gravity script could be combined with any other script now.
unc0rr
parents: 9910
diff changeset
   142
    
42cd42e44c9a GravRacer, GravHigh, GravMutant, Grav... uhm... shoppamap? Easy! Gravity script could be combined with any other script now.
unc0rr
parents: 9910
diff changeset
   143
    if secondScript ~= nil then
42cd42e44c9a GravRacer, GravHigh, GravMutant, Grav... uhm... shoppamap? Easy! Gravity script could be combined with any other script now.
unc0rr
parents: 9910
diff changeset
   144
        onParameters = nil
42cd42e44c9a GravRacer, GravHigh, GravMutant, Grav... uhm... shoppamap? Easy! Gravity script could be combined with any other script now.
unc0rr
parents: 9910
diff changeset
   145
        HedgewarsScriptLoad("/Scripts/Multiplayer/" .. secondScript .. ".lua")
42cd42e44c9a GravRacer, GravHigh, GravMutant, Grav... uhm... shoppamap? Easy! Gravity script could be combined with any other script now.
unc0rr
parents: 9910
diff changeset
   146
        
42cd42e44c9a GravRacer, GravHigh, GravMutant, Grav... uhm... shoppamap? Easy! Gravity script could be combined with any other script now.
unc0rr
parents: 9910
diff changeset
   147
        script2_onNewTurn = onNewTurn
42cd42e44c9a GravRacer, GravHigh, GravMutant, Grav... uhm... shoppamap? Easy! Gravity script could be combined with any other script now.
unc0rr
parents: 9910
diff changeset
   148
        script2_onGameTick20 = onGameTick20
11894
dd3cbbde7876 Improve mission panel in Gravity script (don't overwrite game modifier texts)
Wuzzy <almikes@aol.com>
parents: 11893
diff changeset
   149
        script2_onGameInit = onGameInit
11893
25a6faa5ac46 Fix low gravity utility not working in Gravity script (fixes #13)
Wuzzy <almikes@aol.com>
parents: 10758
diff changeset
   150
        script2_onHogAttack = onHogAttack
9985
42cd42e44c9a GravRacer, GravHigh, GravMutant, Grav... uhm... shoppamap? Easy! Gravity script could be combined with any other script now.
unc0rr
parents: 9910
diff changeset
   151
                
42cd42e44c9a GravRacer, GravHigh, GravMutant, Grav... uhm... shoppamap? Easy! Gravity script could be combined with any other script now.
unc0rr
parents: 9910
diff changeset
   152
        if onParameters ~= nil then
42cd42e44c9a GravRacer, GravHigh, GravMutant, Grav... uhm... shoppamap? Easy! Gravity script could be combined with any other script now.
unc0rr
parents: 9910
diff changeset
   153
            onParameters()
42cd42e44c9a GravRacer, GravHigh, GravMutant, Grav... uhm... shoppamap? Easy! Gravity script could be combined with any other script now.
unc0rr
parents: 9910
diff changeset
   154
        end
42cd42e44c9a GravRacer, GravHigh, GravMutant, Grav... uhm... shoppamap? Easy! Gravity script could be combined with any other script now.
unc0rr
parents: 9910
diff changeset
   155
    end
42cd42e44c9a GravRacer, GravHigh, GravMutant, Grav... uhm... shoppamap? Easy! Gravity script could be combined with any other script now.
unc0rr
parents: 9910
diff changeset
   156
    
42cd42e44c9a GravRacer, GravHigh, GravMutant, Grav... uhm... shoppamap? Easy! Gravity script could be combined with any other script now.
unc0rr
parents: 9910
diff changeset
   157
    onNewTurn = grav_onNewTurn
42cd42e44c9a GravRacer, GravHigh, GravMutant, Grav... uhm... shoppamap? Easy! Gravity script could be combined with any other script now.
unc0rr
parents: 9910
diff changeset
   158
    onGameTick20 = grav_onGameTick20
11894
dd3cbbde7876 Improve mission panel in Gravity script (don't overwrite game modifier texts)
Wuzzy <almikes@aol.com>
parents: 11893
diff changeset
   159
    onGameInit = grav_onGameInit
11893
25a6faa5ac46 Fix low gravity utility not working in Gravity script (fixes #13)
Wuzzy <almikes@aol.com>
parents: 10758
diff changeset
   160
    onHogAttack = grav_onHogAttack
9836
00cbbb195f11 Rework of No Gravity script:
unc0rr
parents: 9819
diff changeset
   161
end
00cbbb195f11 Rework of No Gravity script:
unc0rr
parents: 9819
diff changeset
   162
11894
dd3cbbde7876 Improve mission panel in Gravity script (don't overwrite game modifier texts)
Wuzzy <almikes@aol.com>
parents: 11893
diff changeset
   163
function grav_onGameInit()
11893
25a6faa5ac46 Fix low gravity utility not working in Gravity script (fixes #13)
Wuzzy <almikes@aol.com>
parents: 10758
diff changeset
   164
    DisableGameFlags(gfLowGravity)
25a6faa5ac46 Fix low gravity utility not working in Gravity script (fixes #13)
Wuzzy <almikes@aol.com>
parents: 10758
diff changeset
   165
11894
dd3cbbde7876 Improve mission panel in Gravity script (don't overwrite game modifier texts)
Wuzzy <almikes@aol.com>
parents: 11893
diff changeset
   166
    local v, printperiod
dd3cbbde7876 Improve mission panel in Gravity script (don't overwrite game modifier texts)
Wuzzy <almikes@aol.com>
parents: 11893
diff changeset
   167
    if period ~= nil then
dd3cbbde7876 Improve mission panel in Gravity script (don't overwrite game modifier texts)
Wuzzy <almikes@aol.com>
parents: 11893
diff changeset
   168
        local period_ms = period * 40
dd3cbbde7876 Improve mission panel in Gravity script (don't overwrite game modifier texts)
Wuzzy <almikes@aol.com>
parents: 11893
diff changeset
   169
        if period_ms % 1000 == 0 then
dd3cbbde7876 Improve mission panel in Gravity script (don't overwrite game modifier texts)
Wuzzy <almikes@aol.com>
parents: 11893
diff changeset
   170
            printperiod = string.format(loc("%i s"), div(period_ms, 1000))
dd3cbbde7876 Improve mission panel in Gravity script (don't overwrite game modifier texts)
Wuzzy <almikes@aol.com>
parents: 11893
diff changeset
   171
        else
dd3cbbde7876 Improve mission panel in Gravity script (don't overwrite game modifier texts)
Wuzzy <almikes@aol.com>
parents: 11893
diff changeset
   172
            printperiod = string.format(loc("%i ms"), period_ms)
dd3cbbde7876 Improve mission panel in Gravity script (don't overwrite game modifier texts)
Wuzzy <almikes@aol.com>
parents: 11893
diff changeset
   173
        end
dd3cbbde7876 Improve mission panel in Gravity script (don't overwrite game modifier texts)
Wuzzy <almikes@aol.com>
parents: 11893
diff changeset
   174
    end
9908
81eb25ddf594 - Utility script for parameters handling
unc0rr
parents: 9906
diff changeset
   175
    if delta == nil then
11894
dd3cbbde7876 Improve mission panel in Gravity script (don't overwrite game modifier texts)
Wuzzy <almikes@aol.com>
parents: 11893
diff changeset
   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)
9908
81eb25ddf594 - Utility script for parameters handling
unc0rr
parents: 9906
diff changeset
   177
    elseif period ~= nil then
11894
dd3cbbde7876 Improve mission panel in Gravity script (don't overwrite game modifier texts)
Wuzzy <almikes@aol.com>
parents: 11893
diff changeset
   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)
dd3cbbde7876 Improve mission panel in Gravity script (don't overwrite game modifier texts)
Wuzzy <almikes@aol.com>
parents: 11893
diff changeset
   179
    elseif gravity > 100 then
dd3cbbde7876 Improve mission panel in Gravity script (don't overwrite game modifier texts)
Wuzzy <almikes@aol.com>
parents: 11893
diff changeset
   180
        v = string.format(loc("High Gravity: Gravity is %i%%"), gravity)
dd3cbbde7876 Improve mission panel in Gravity script (don't overwrite game modifier texts)
Wuzzy <almikes@aol.com>
parents: 11893
diff changeset
   181
    elseif gravity < 100 then
dd3cbbde7876 Improve mission panel in Gravity script (don't overwrite game modifier texts)
Wuzzy <almikes@aol.com>
parents: 11893
diff changeset
   182
        v = string.format(loc("Low Gravity: Gravity is %i%%"), gravity)
9908
81eb25ddf594 - Utility script for parameters handling
unc0rr
parents: 9906
diff changeset
   183
    else
11894
dd3cbbde7876 Improve mission panel in Gravity script (don't overwrite game modifier texts)
Wuzzy <almikes@aol.com>
parents: 11893
diff changeset
   184
        v = loc("Gravity: 100%") .. "|" ..
dd3cbbde7876 Improve mission panel in Gravity script (don't overwrite game modifier texts)
Wuzzy <almikes@aol.com>
parents: 11893
diff changeset
   185
            loc("Script parameter examples:") .. "|" ..
dd3cbbde7876 Improve mission panel in Gravity script (don't overwrite game modifier texts)
Wuzzy <almikes@aol.com>
parents: 11893
diff changeset
   186
            loc("“g=150”, where 150 is 150% of normal gravity.") .. "|" ..
dd3cbbde7876 Improve mission panel in Gravity script (don't overwrite game modifier texts)
Wuzzy <almikes@aol.com>
parents: 11893
diff changeset
   187
            loc("“g=50, g2=150, period=4000” for gravity changing|from 50 to 150 and back with period of 4000 ms.") .. "|" ..
12814
b4e20bb485f9 Remove newlines at end of Gravity mission panel
Wuzzy <Wuzzy2@mail.ru>
parents: 11894
diff changeset
   188
            loc("Set period to negative value for random gravity.")
9908
81eb25ddf594 - Utility script for parameters handling
unc0rr
parents: 9906
diff changeset
   189
    end
11894
dd3cbbde7876 Improve mission panel in Gravity script (don't overwrite game modifier texts)
Wuzzy <almikes@aol.com>
parents: 11893
diff changeset
   190
    Goals = v
9908
81eb25ddf594 - Utility script for parameters handling
unc0rr
parents: 9906
diff changeset
   191
11894
dd3cbbde7876 Improve mission panel in Gravity script (don't overwrite game modifier texts)
Wuzzy <almikes@aol.com>
parents: 11893
diff changeset
   192
    if script2_onGameInit ~= nil then
dd3cbbde7876 Improve mission panel in Gravity script (don't overwrite game modifier texts)
Wuzzy <almikes@aol.com>
parents: 11893
diff changeset
   193
        script2_onGameInit()
9985
42cd42e44c9a GravRacer, GravHigh, GravMutant, Grav... uhm... shoppamap? Easy! Gravity script could be combined with any other script now.
unc0rr
parents: 9910
diff changeset
   194
    end
9902
eb8e8b09b2f0 Special script parameter variable in game scheme
unc0rr
parents: 9898
diff changeset
   195
end
9985
42cd42e44c9a GravRacer, GravHigh, GravMutant, Grav... uhm... shoppamap? Easy! Gravity script could be combined with any other script now.
unc0rr
parents: 9910
diff changeset
   196
11893
25a6faa5ac46 Fix low gravity utility not working in Gravity script (fixes #13)
Wuzzy <almikes@aol.com>
parents: 10758
diff changeset
   197
function grav_onHogAttack(ammoType)
25a6faa5ac46 Fix low gravity utility not working in Gravity script (fixes #13)
Wuzzy <almikes@aol.com>
parents: 10758
diff changeset
   198
    if ammoType == amLowGravity then
25a6faa5ac46 Fix low gravity utility not working in Gravity script (fixes #13)
Wuzzy <almikes@aol.com>
parents: 10758
diff changeset
   199
        lowGravityUsed = true
25a6faa5ac46 Fix low gravity utility not working in Gravity script (fixes #13)
Wuzzy <almikes@aol.com>
parents: 10758
diff changeset
   200
        if maxgravity_normal == nil then
25a6faa5ac46 Fix low gravity utility not working in Gravity script (fixes #13)
Wuzzy <almikes@aol.com>
parents: 10758
diff changeset
   201
            gravity = mingravity_low
25a6faa5ac46 Fix low gravity utility not working in Gravity script (fixes #13)
Wuzzy <almikes@aol.com>
parents: 10758
diff changeset
   202
        else
25a6faa5ac46 Fix low gravity utility not working in Gravity script (fixes #13)
Wuzzy <almikes@aol.com>
parents: 10758
diff changeset
   203
            mingravity = mingravity_low
25a6faa5ac46 Fix low gravity utility not working in Gravity script (fixes #13)
Wuzzy <almikes@aol.com>
parents: 10758
diff changeset
   204
            maxgravity = maxgravity_low
25a6faa5ac46 Fix low gravity utility not working in Gravity script (fixes #13)
Wuzzy <almikes@aol.com>
parents: 10758
diff changeset
   205
            if period > 0 then
25a6faa5ac46 Fix low gravity utility not working in Gravity script (fixes #13)
Wuzzy <almikes@aol.com>
parents: 10758
diff changeset
   206
                delta = div(maxgravity_low - mingravity_low, period)
25a6faa5ac46 Fix low gravity utility not working in Gravity script (fixes #13)
Wuzzy <almikes@aol.com>
parents: 10758
diff changeset
   207
            end
25a6faa5ac46 Fix low gravity utility not working in Gravity script (fixes #13)
Wuzzy <almikes@aol.com>
parents: 10758
diff changeset
   208
        end
25a6faa5ac46 Fix low gravity utility not working in Gravity script (fixes #13)
Wuzzy <almikes@aol.com>
parents: 10758
diff changeset
   209
    end
25a6faa5ac46 Fix low gravity utility not working in Gravity script (fixes #13)
Wuzzy <almikes@aol.com>
parents: 10758
diff changeset
   210
    if script2_onHogAttack ~= nil then
25a6faa5ac46 Fix low gravity utility not working in Gravity script (fixes #13)
Wuzzy <almikes@aol.com>
parents: 10758
diff changeset
   211
        script2_onHogAttack()
25a6faa5ac46 Fix low gravity utility not working in Gravity script (fixes #13)
Wuzzy <almikes@aol.com>
parents: 10758
diff changeset
   212
    end
25a6faa5ac46 Fix low gravity utility not working in Gravity script (fixes #13)
Wuzzy <almikes@aol.com>
parents: 10758
diff changeset
   213
end