project_files/Android-build/SDL-android-project/assets/Data/Scripts/Multiplayer/Balanced_Random_Weapon.lua
author Wuzzy <Wuzzy2@mail.ru>
Fri, 04 May 2018 14:38:01 +0200
changeset 13378 c53530142442
parent 7568 75ba91f14ed5
permissions -rw-r--r--
Lua API: Add EnableSwitchHog to manually enable hog switching
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7568
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
     1
loadfile(GetDataPath() .. "Scripts/Locale.lua")()
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
     2
loadfile(GetDataPath() .. "Scripts/Tracker.lua")()
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
     3
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
     4
local weapons = { amGrenade, amClusterBomb, amBazooka, amBee, amShotgun, amMine, amDEagle, amDynamite, amFirePunch, amWhip, amPickHammer, amBaseballBat, amMortar, amCake, amSeduction, amWatermelon, amHellishBomb, amDrill, amBallgun, amRCPlane, amSniperRifle, amMolotov, amBirdy, amBlowTorch, amGasBomb, amFlamethrower, amSMine, amKamikaze }
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
     5
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
     6
--                      G,C,B,B,S,M,D,D,F,W,P,B,M,C,S,W,H,D,B,R,S,M,B,B,G,F,S,K
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
     7
local weapons_values = {1,1,1,2,1,1,1,2,1,1,1,2,1,3,1,3,3,2,3,3,1,1,2,1,1,2,2,1}
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
     8
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
     9
local airweapons = { amAirAttack, amMineStrike, amNapalm, amDrillStrike }
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    10
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    11
--                         A,M,N,D
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    12
local airweapons_values = {2,2,2,2}
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    13
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    14
local utilities = { amTeleport, amGirder, amSwitch, amLowGravity, amResurrector, amRope, amParachute, amJetpack, amPortalGun, amSnowball }
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    15
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    16
--                        T,G,S,L,R,R,P,J,P,S
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    17
local utilities_values = {1,2,2,1,2,2,1,2,2,2}
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    18
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    19
function randomAmmo()
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    20
    local n = 3   --"points" to be allocated on weapons
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    21
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    22
    --pick random weapon and subtract cost
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    23
    local r = GetRandom(table.maxn(weapons_values)) + 1
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    24
    local picked_items = {}
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    25
    table.insert(picked_items, weapons[r])
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    26
    n = n - weapons_values[r]
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    27
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    28
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    29
    --choose any weapons or utilities to use up remaining n
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    30
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    31
    while n > 0 do
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    32
        local items = {}
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    33
        local items_values = {}
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    34
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    35
        for i, w in pairs(weapons_values) do
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    36
            local used = false
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    37
            if w <= n then
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    38
                --check that this weapon hasn't been given already
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    39
                for j, k in pairs(picked_items) do
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    40
                    if weapons[i] == k then
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    41
                        used = true
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    42
                    end
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    43
                end
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    44
                if not used then
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    45
                    table.insert(items_values, w)
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    46
                    table.insert(items, weapons[i])
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    47
                end
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    48
            end
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    49
        end
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    50
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    51
        for i, w in pairs(utilities_values) do
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    52
            local used = false
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    53
            if w <= n then
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    54
                --check that this weapon hasn't been given already
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    55
                for j, k in pairs(picked_items) do
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    56
                    if utilities[i] == k then
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    57
                        used = true
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    58
                    end
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    59
                end
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    60
                if not used then
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    61
                    table.insert(items_values, w)
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    62
                    table.insert(items, utilities[i])
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    63
                end
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    64
            end
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    65
        end
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    66
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    67
        local r = GetRandom(table.maxn(items_values)) + 1
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    68
        table.insert(picked_items, items[r])
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    69
        n = n - items_values[r]
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    70
    end
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    71
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    72
    return picked_items
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    73
end
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    74
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    75
function assignAmmo(hog)
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    76
    local name = GetHogTeamName(hog)
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    77
    local processed = getTeamValue(name, "processed")
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    78
    if processed == nil or not processed then
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    79
        local ammo = getTeamValue(name, "ammo")
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    80
        if ammo == nil then
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    81
            ammo = randomAmmo()
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    82
            setTeamValue(name, "ammo", ammo)
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    83
        end
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    84
        for i, w in pairs(ammo) do
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    85
            AddAmmo(hog, w)
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    86
        end
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    87
        setTeamValue(name, "processed", true)
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    88
    end
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    89
end
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    90
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    91
function reset(hog)
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    92
    setTeamValue(GetHogTeamName(hog), "processed", false)
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    93
end
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    94
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    95
function onGameInit()
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    96
    GameFlags = band(bor(GameFlags, gfResetWeps), bnot(gfPerHogAmmo))
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    97
    Goals = loc("Each turn you get 1-3 random weapons")
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    98
end
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
    99
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
   100
function onGameStart()
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
   101
    trackTeams()
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
   102
    if MapHasBorder() == false then
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
   103
        for i, w in pairs(airweapons) do
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
   104
            table.insert(weapons, w)
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
   105
        end
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
   106
        for i, w in pairs(airweapons_values) do
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
   107
            table.insert(weapons_values, w)
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
   108
        end
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
   109
    end
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
   110
end
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
   111
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
   112
function onAmmoStoreInit()
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
   113
    SetAmmo(amSkip, 9, 0, 0, 0)
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
   114
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
   115
    SetAmmo(amExtraDamage, 0, 1, 0, 1)
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
   116
    SetAmmo(amInvulnerable, 0, 1, 0, 1)
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
   117
    SetAmmo(amExtraTime, 0, 1, 0, 1)
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
   118
    SetAmmo(amLaserSight, 0, 1, 0, 1)
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
   119
    SetAmmo(amVampiric, 0, 1, 0, 1)
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
   120
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
   121
    for i, w in pairs(utilities) do
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
   122
        SetAmmo(w, 0, 0, 0, 1)
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
   123
    end
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
   124
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
   125
    for i, w in pairs(weapons) do
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
   126
        SetAmmo(w, 0, 0, 0, 1)
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
   127
    end
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
   128
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
   129
    for i, w in pairs(airweapons) do
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
   130
        SetAmmo(w, 0, 0, 0, 1)
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
   131
    end
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
   132
end
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
   133
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
   134
function onNewTurn()
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
   135
    runOnGears(assignAmmo)
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
   136
    runOnGears(reset)
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
   137
    setTeamValue(GetHogTeamName(CurrentHedgehog), "ammo", nil)
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
   138
end
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
   139
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
   140
function onGearAdd(gear)
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
   141
    if GetGearType(gear) == gtHedgehog then
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
   142
        trackGear(gear)
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
   143
    end
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
   144
end
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
   145
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
   146
function onGearDelete(gear)
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
   147
    trackDeletion(gear)
75ba91f14ed5 Hedgeroid:
Medo <smaxein@googlemail.com>
parents:
diff changeset
   148
end