share/hedgewars/Data/Scripts/Multiplayer/Balanced_Random_Weapon.lua
author claymore
Fri, 08 Apr 2011 21:15:57 +0200
changeset 5127 b0b6f17a6a3c
child 5141 2fb6555011d3
permissions -rw-r--r--
added Balanced Random Weapon gameplay script
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5127
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
     1
loadfile(GetDataPath() .. "Scripts/Locale.lua")()
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
     2
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
     3
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 }
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
     4
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
     5
--                      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
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
     6
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}
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
     7
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
     8
local airweapons = { amAirAttack, amMineStrike, amNapalm, amDrillStrike }
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
     9
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
    10
--                         A,M,N,D
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
    11
local airweapons_values = {2,2,2,2}
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
    12
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
    13
local utilities = { amTeleport, amGirder, amSwitch, amLowGravity, amResurrector, amRope, amParachute, amJetpack, amPortalGun, amSnowball }
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
    14
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
    15
--                        T,G,S,L,R,R,P,J,P,S
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
    16
local utilities_values = {1,2,2,1,2,2,1,2,2,2}
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
    17
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
    18
function onGameInit()
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
    19
    GameFlags = band(bor(GameFlags, gfResetWeps), bnot(gfPerHogAmmo))
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
    20
    Goals = loc("Each turn you get 1-3 random weapons|The stronger they are, the fewer you get")
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
    21
end
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
    22
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
    23
function onGameStart()
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
    24
    if MapHasBorder() == false then
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
    25
        for i, w in pairs(airweapons) do
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
    26
            table.insert(weapons, w)
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
    27
        end
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
    28
        for i, w in pairs(airweapons_values) do
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
    29
            table.insert(weapons_values, w)
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
    30
        end
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
    31
    end
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
    32
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
    33
    --ShowMission(loc("Balanced Random Weapons"), loc("A game of luck"), loc("Each turn you'll get a weapon, and if it sucks you'll get some more!"), -amSkip, 0)
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
    34
end
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
    35
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
    36
function onAmmoStoreInit()
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
    37
    SetAmmo(amSkip, 9, 0, 0, 0)
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
    38
    
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
    39
    SetAmmo(amExtraDamage, 0, 1, 0, 1)
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
    40
    SetAmmo(amInvulnerable, 0, 1, 0, 1)
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
    41
    SetAmmo(amExtraTime, 0, 1, 0, 1)
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
    42
    SetAmmo(amLaserSight, 0, 1, 0, 1)
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
    43
    SetAmmo(amVampiric, 0, 1, 0, 1)
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
    44
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
    45
    for i, w in pairs(utilities) do
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
    46
        SetAmmo(w, 0, 0, 0, 1)
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
    47
    end
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
    48
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
    49
    for i, w in pairs(weapons) do
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
    50
        SetAmmo(w, 0, 0, 0, 1)
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
    51
    end
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
    52
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
    53
    for i, w in pairs(airweapons) do
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
    54
        SetAmmo(w, 0, 0, 0, 1)
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
    55
    end
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
    56
end
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
    57
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
    58
function onNewTurn()
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
    59
    local n = 3   --"points" to be allocated on weapons
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
    60
    
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
    61
    --pick random weapon and subtract cost
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
    62
    local r = GetRandom(table.maxn(weapons_values)) + 1
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
    63
    AddAmmo(CurrentHedgehog, weapons[r])
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
    64
    local items_used = {}
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
    65
    items_used[1] = weapons[r]
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
    66
    n = n - weapons_values[r]
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
    67
    
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
    68
    
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
    69
    --choose any weapons or utilities to use up remaining n
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
    70
    
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
    71
    while n > 0 do
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
    72
        local items = {}
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
    73
        local items_values = {}
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
    74
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
    75
        for i, w in pairs(weapons_values) do
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
    76
            local used = false
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
    77
            if w <= n then
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
    78
                --check that this weapon hasn't been given already
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
    79
                for j = 1, table.maxn(items_used) do
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
    80
                    if weapons[i] == items_used[j] then
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
    81
                        used = true
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
    82
                    end
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
    83
                end
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
    84
                if not used then
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
    85
                    table.insert(items_values, w)
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
    86
                    table.insert(items, weapons[i])
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
    87
                end
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
    88
            end
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
    89
        end
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
    90
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
    91
        for i, w in pairs(utilities_values) do
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
    92
            local used = false
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
    93
            if w <= n then
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
    94
                --check that this weapon hasn't been given already
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
    95
                for j = 1, table.maxn(items_used) do
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
    96
                    if utilities[i] == items_used[j] then
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
    97
                        used = true
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
    98
                    end
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
    99
                end
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
   100
                if not used then
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
   101
                    table.insert(items_values, w)
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
   102
                    table.insert(items, utilities[i])
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
   103
                end
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
   104
            end
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
   105
        end
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
   106
        
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
   107
        local r = GetRandom(table.maxn(items_values)) + 1
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
   108
        AddAmmo(CurrentHedgehog, items[r])
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
   109
        table.insert(items_used, items[r])
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
   110
        n = n - items_values[r]
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
   111
    end
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
   112
end