share/hedgewars/Data/Scripts/Multiplayer/Balanced_Random_Weapon.lua
author Henek
Mon, 11 Apr 2011 00:35:53 +0200
changeset 5138 f991f87969ff
parent 5127 b0b6f17a6a3c
child 5141 2fb6555011d3
permissions -rw-r--r--
now Random Weapons will show the weapon you will get during the other players turns not tested online yet, would be happy if someone could and report to me results

loadfile(GetDataPath() .. "Scripts/Locale.lua")()

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 }

--                      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
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}

local airweapons = { amAirAttack, amMineStrike, amNapalm, amDrillStrike }

--                         A,M,N,D
local airweapons_values = {2,2,2,2}

local utilities = { amTeleport, amGirder, amSwitch, amLowGravity, amResurrector, amRope, amParachute, amJetpack, amPortalGun, amSnowball }

--                        T,G,S,L,R,R,P,J,P,S
local utilities_values = {1,2,2,1,2,2,1,2,2,2}

function onGameInit()
    GameFlags = band(bor(GameFlags, gfResetWeps), bnot(gfPerHogAmmo))
    Goals = loc("Each turn you get 1-3 random weapons|The stronger they are, the fewer you get")
end

function onGameStart()
    if MapHasBorder() == false then
        for i, w in pairs(airweapons) do
            table.insert(weapons, w)
        end
        for i, w in pairs(airweapons_values) do
            table.insert(weapons_values, w)
        end
    end

    --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)
end

function onAmmoStoreInit()
    SetAmmo(amSkip, 9, 0, 0, 0)
    
    SetAmmo(amExtraDamage, 0, 1, 0, 1)
    SetAmmo(amInvulnerable, 0, 1, 0, 1)
    SetAmmo(amExtraTime, 0, 1, 0, 1)
    SetAmmo(amLaserSight, 0, 1, 0, 1)
    SetAmmo(amVampiric, 0, 1, 0, 1)

    for i, w in pairs(utilities) do
        SetAmmo(w, 0, 0, 0, 1)
    end

    for i, w in pairs(weapons) do
        SetAmmo(w, 0, 0, 0, 1)
    end

    for i, w in pairs(airweapons) do
        SetAmmo(w, 0, 0, 0, 1)
    end
end

function onNewTurn()
    local n = 3   --"points" to be allocated on weapons
    
    --pick random weapon and subtract cost
    local r = GetRandom(table.maxn(weapons_values)) + 1
    AddAmmo(CurrentHedgehog, weapons[r])
    local items_used = {}
    items_used[1] = weapons[r]
    n = n - weapons_values[r]
    
    
    --choose any weapons or utilities to use up remaining n
    
    while n > 0 do
        local items = {}
        local items_values = {}

        for i, w in pairs(weapons_values) do
            local used = false
            if w <= n then
                --check that this weapon hasn't been given already
                for j = 1, table.maxn(items_used) do
                    if weapons[i] == items_used[j] then
                        used = true
                    end
                end
                if not used then
                    table.insert(items_values, w)
                    table.insert(items, weapons[i])
                end
            end
        end

        for i, w in pairs(utilities_values) do
            local used = false
            if w <= n then
                --check that this weapon hasn't been given already
                for j = 1, table.maxn(items_used) do
                    if utilities[i] == items_used[j] then
                        used = true
                    end
                end
                if not used then
                    table.insert(items_values, w)
                    table.insert(items, utilities[i])
                end
            end
        end
        
        local r = GetRandom(table.maxn(items_values)) + 1
        AddAmmo(CurrentHedgehog, items[r])
        table.insert(items_used, items[r])
        n = n - items_values[r]
    end
end