share/hedgewars/Data/Scripts/Multiplayer/Balanced_Random_Weapon.lua
author Wuzzy <Wuzzy2@mail.ru>
Thu, 30 Aug 2018 22:07:01 +0200
changeset 13718 6d57f5f61c09
parent 13173 4d1cf0d76eb7
child 13719 ed22eb551a75
permissions -rw-r--r--
BRW now allows weapon scheme customization See script comments to see how.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
13718
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13173
diff changeset
     1
--[[
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13173
diff changeset
     2
Balanced Random Weapon
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13173
diff changeset
     3
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13173
diff changeset
     4
Every turn, each hog gets 1-3 random weapons. Weapons are reset every turn.
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13173
diff changeset
     5
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13173
diff changeset
     6
= CUSTOMIZATION =
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13173
diff changeset
     7
The weapon chances are chosen with the weapons scheme.
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13173
diff changeset
     8
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13173
diff changeset
     9
The "ammo count" tab is used to set the probability level that you get
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13173
diff changeset
    10
equipped with the ammo at the start of a turn:
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13173
diff changeset
    11
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13173
diff changeset
    12
* infinity = always get this weapon
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13173
diff changeset
    13
* 3-8 bullets = high probability (more bullets don't make it more likely)
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13173
diff changeset
    14
* 2 bullets = medium probability
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13173
diff changeset
    15
* 1 bullet = low probability
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13173
diff changeset
    16
* 0 bullets = never
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13173
diff changeset
    17
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13173
diff changeset
    18
For utilities, the low and medium probabilities are the same.
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13173
diff changeset
    19
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13173
diff changeset
    20
The "probabilities" tab is, as usual, for crate probabilities.
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13173
diff changeset
    21
The "ammo in crate" and "delay" tabs also work as expected.
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13173
diff changeset
    22
]]
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13173
diff changeset
    23
8043
da083f8d95e6 We need custom script loading function in lua now
unc0rr
parents: 5827
diff changeset
    24
HedgewarsScriptLoad("/Scripts/Locale.lua")
da083f8d95e6 We need custom script loading function in lua now
unc0rr
parents: 5827
diff changeset
    25
HedgewarsScriptLoad("/Scripts/Tracker.lua")
5127
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
    26
13718
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13173
diff changeset
    27
local weapons = {}
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13173
diff changeset
    28
local weapons_values = {}
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13173
diff changeset
    29
local airweapons = {}
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13173
diff changeset
    30
local airweapons_values = {}
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13173
diff changeset
    31
local utilities = {}
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13173
diff changeset
    32
local utilities_values = {}
5127
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
    33
13718
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13173
diff changeset
    34
local isUtility, isAirWeapon
5127
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
    35
5141
2fb6555011d3 cleared up Random Weapons and implemented remembering of weapons in Balanced Random Weapons too, also seems to work
Henek
parents: 5127
diff changeset
    36
function randomAmmo()
13718
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13173
diff changeset
    37
--[[
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13173
diff changeset
    38
= WEAPON SELECTION ALGORITHM =
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13173
diff changeset
    39
Each turn, a team gets 3 "points". Each ammo that has been activated
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13173
diff changeset
    40
has a "cost" of 1-3 which is derived from the ammo probability specified
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13173
diff changeset
    41
from the ammo menu (see getCost).
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13173
diff changeset
    42
Utilities are forced to have a cost of 1-2.
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13173
diff changeset
    43
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13173
diff changeset
    44
Steps:
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13173
diff changeset
    45
1. Add a random weapon to ammo and subtract cost
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13173
diff changeset
    46
2. If there's still points left:
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13173
diff changeset
    47
    a. Forget any item in mind
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13173
diff changeset
    48
    b. Choose a random weapon and keep it in mind (but don't add it to the ammo yet)
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13173
diff changeset
    49
    c. Choose a random utility and keep it in mind (but don't add it to the ammo yet)
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13173
diff changeset
    50
    d. Forget any items which are either too expensive or have already been taken by this hedgehog
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13173
diff changeset
    51
    e. Randomly add one of the items which are still in mind to the hedgehog's ammo and substract cost
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13173
diff changeset
    52
    f. Return to step 2
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13173
diff changeset
    53
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13173
diff changeset
    54
If 0 points are left, the algorithm terminates.
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13173
diff changeset
    55
]]
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13173
diff changeset
    56
5141
2fb6555011d3 cleared up Random Weapons and implemented remembering of weapons in Balanced Random Weapons too, also seems to work
Henek
parents: 5127
diff changeset
    57
    local n = 3   --"points" to be allocated on weapons
5827
a416f1070fdf we don't need trailing whitespaces... I guess :P
sheepluva
parents: 5141
diff changeset
    58
5141
2fb6555011d3 cleared up Random Weapons and implemented remembering of weapons in Balanced Random Weapons too, also seems to work
Henek
parents: 5127
diff changeset
    59
    --pick random weapon and subtract cost
2fb6555011d3 cleared up Random Weapons and implemented remembering of weapons in Balanced Random Weapons too, also seems to work
Henek
parents: 5127
diff changeset
    60
    local r = GetRandom(table.maxn(weapons_values)) + 1
2fb6555011d3 cleared up Random Weapons and implemented remembering of weapons in Balanced Random Weapons too, also seems to work
Henek
parents: 5127
diff changeset
    61
    local picked_items = {}
2fb6555011d3 cleared up Random Weapons and implemented remembering of weapons in Balanced Random Weapons too, also seems to work
Henek
parents: 5127
diff changeset
    62
    table.insert(picked_items, weapons[r])
2fb6555011d3 cleared up Random Weapons and implemented remembering of weapons in Balanced Random Weapons too, also seems to work
Henek
parents: 5127
diff changeset
    63
    n = n - weapons_values[r]
5827
a416f1070fdf we don't need trailing whitespaces... I guess :P
sheepluva
parents: 5141
diff changeset
    64
a416f1070fdf we don't need trailing whitespaces... I guess :P
sheepluva
parents: 5141
diff changeset
    65
5141
2fb6555011d3 cleared up Random Weapons and implemented remembering of weapons in Balanced Random Weapons too, also seems to work
Henek
parents: 5127
diff changeset
    66
    --choose any weapons or utilities to use up remaining n
5827
a416f1070fdf we don't need trailing whitespaces... I guess :P
sheepluva
parents: 5141
diff changeset
    67
5141
2fb6555011d3 cleared up Random Weapons and implemented remembering of weapons in Balanced Random Weapons too, also seems to work
Henek
parents: 5127
diff changeset
    68
    while n > 0 do
2fb6555011d3 cleared up Random Weapons and implemented remembering of weapons in Balanced Random Weapons too, also seems to work
Henek
parents: 5127
diff changeset
    69
        local items = {}
2fb6555011d3 cleared up Random Weapons and implemented remembering of weapons in Balanced Random Weapons too, also seems to work
Henek
parents: 5127
diff changeset
    70
        local items_values = {}
2fb6555011d3 cleared up Random Weapons and implemented remembering of weapons in Balanced Random Weapons too, also seems to work
Henek
parents: 5127
diff changeset
    71
2fb6555011d3 cleared up Random Weapons and implemented remembering of weapons in Balanced Random Weapons too, also seems to work
Henek
parents: 5127
diff changeset
    72
        for i, w in pairs(weapons_values) do
2fb6555011d3 cleared up Random Weapons and implemented remembering of weapons in Balanced Random Weapons too, also seems to work
Henek
parents: 5127
diff changeset
    73
            local used = false
2fb6555011d3 cleared up Random Weapons and implemented remembering of weapons in Balanced Random Weapons too, also seems to work
Henek
parents: 5127
diff changeset
    74
            if w <= n then
2fb6555011d3 cleared up Random Weapons and implemented remembering of weapons in Balanced Random Weapons too, also seems to work
Henek
parents: 5127
diff changeset
    75
                --check that this weapon hasn't been given already
2fb6555011d3 cleared up Random Weapons and implemented remembering of weapons in Balanced Random Weapons too, also seems to work
Henek
parents: 5127
diff changeset
    76
                for j, k in pairs(picked_items) do
2fb6555011d3 cleared up Random Weapons and implemented remembering of weapons in Balanced Random Weapons too, also seems to work
Henek
parents: 5127
diff changeset
    77
                    if weapons[i] == k then
2fb6555011d3 cleared up Random Weapons and implemented remembering of weapons in Balanced Random Weapons too, also seems to work
Henek
parents: 5127
diff changeset
    78
                        used = true
2fb6555011d3 cleared up Random Weapons and implemented remembering of weapons in Balanced Random Weapons too, also seems to work
Henek
parents: 5127
diff changeset
    79
                    end
2fb6555011d3 cleared up Random Weapons and implemented remembering of weapons in Balanced Random Weapons too, also seems to work
Henek
parents: 5127
diff changeset
    80
                end
2fb6555011d3 cleared up Random Weapons and implemented remembering of weapons in Balanced Random Weapons too, also seems to work
Henek
parents: 5127
diff changeset
    81
                if not used then
2fb6555011d3 cleared up Random Weapons and implemented remembering of weapons in Balanced Random Weapons too, also seems to work
Henek
parents: 5127
diff changeset
    82
                    table.insert(items_values, w)
2fb6555011d3 cleared up Random Weapons and implemented remembering of weapons in Balanced Random Weapons too, also seems to work
Henek
parents: 5127
diff changeset
    83
                    table.insert(items, weapons[i])
2fb6555011d3 cleared up Random Weapons and implemented remembering of weapons in Balanced Random Weapons too, also seems to work
Henek
parents: 5127
diff changeset
    84
                end
2fb6555011d3 cleared up Random Weapons and implemented remembering of weapons in Balanced Random Weapons too, also seems to work
Henek
parents: 5127
diff changeset
    85
            end
2fb6555011d3 cleared up Random Weapons and implemented remembering of weapons in Balanced Random Weapons too, also seems to work
Henek
parents: 5127
diff changeset
    86
        end
2fb6555011d3 cleared up Random Weapons and implemented remembering of weapons in Balanced Random Weapons too, also seems to work
Henek
parents: 5127
diff changeset
    87
2fb6555011d3 cleared up Random Weapons and implemented remembering of weapons in Balanced Random Weapons too, also seems to work
Henek
parents: 5127
diff changeset
    88
        for i, w in pairs(utilities_values) do
2fb6555011d3 cleared up Random Weapons and implemented remembering of weapons in Balanced Random Weapons too, also seems to work
Henek
parents: 5127
diff changeset
    89
            local used = false
2fb6555011d3 cleared up Random Weapons and implemented remembering of weapons in Balanced Random Weapons too, also seems to work
Henek
parents: 5127
diff changeset
    90
            if w <= n then
2fb6555011d3 cleared up Random Weapons and implemented remembering of weapons in Balanced Random Weapons too, also seems to work
Henek
parents: 5127
diff changeset
    91
                --check that this weapon hasn't been given already
2fb6555011d3 cleared up Random Weapons and implemented remembering of weapons in Balanced Random Weapons too, also seems to work
Henek
parents: 5127
diff changeset
    92
                for j, k in pairs(picked_items) do
2fb6555011d3 cleared up Random Weapons and implemented remembering of weapons in Balanced Random Weapons too, also seems to work
Henek
parents: 5127
diff changeset
    93
                    if utilities[i] == k then
2fb6555011d3 cleared up Random Weapons and implemented remembering of weapons in Balanced Random Weapons too, also seems to work
Henek
parents: 5127
diff changeset
    94
                        used = true
2fb6555011d3 cleared up Random Weapons and implemented remembering of weapons in Balanced Random Weapons too, also seems to work
Henek
parents: 5127
diff changeset
    95
                    end
2fb6555011d3 cleared up Random Weapons and implemented remembering of weapons in Balanced Random Weapons too, also seems to work
Henek
parents: 5127
diff changeset
    96
                end
2fb6555011d3 cleared up Random Weapons and implemented remembering of weapons in Balanced Random Weapons too, also seems to work
Henek
parents: 5127
diff changeset
    97
                if not used then
2fb6555011d3 cleared up Random Weapons and implemented remembering of weapons in Balanced Random Weapons too, also seems to work
Henek
parents: 5127
diff changeset
    98
                    table.insert(items_values, w)
2fb6555011d3 cleared up Random Weapons and implemented remembering of weapons in Balanced Random Weapons too, also seems to work
Henek
parents: 5127
diff changeset
    99
                    table.insert(items, utilities[i])
2fb6555011d3 cleared up Random Weapons and implemented remembering of weapons in Balanced Random Weapons too, also seems to work
Henek
parents: 5127
diff changeset
   100
                end
2fb6555011d3 cleared up Random Weapons and implemented remembering of weapons in Balanced Random Weapons too, also seems to work
Henek
parents: 5127
diff changeset
   101
            end
2fb6555011d3 cleared up Random Weapons and implemented remembering of weapons in Balanced Random Weapons too, also seems to work
Henek
parents: 5127
diff changeset
   102
        end
5827
a416f1070fdf we don't need trailing whitespaces... I guess :P
sheepluva
parents: 5141
diff changeset
   103
5141
2fb6555011d3 cleared up Random Weapons and implemented remembering of weapons in Balanced Random Weapons too, also seems to work
Henek
parents: 5127
diff changeset
   104
        local r = GetRandom(table.maxn(items_values)) + 1
2fb6555011d3 cleared up Random Weapons and implemented remembering of weapons in Balanced Random Weapons too, also seems to work
Henek
parents: 5127
diff changeset
   105
        table.insert(picked_items, items[r])
2fb6555011d3 cleared up Random Weapons and implemented remembering of weapons in Balanced Random Weapons too, also seems to work
Henek
parents: 5127
diff changeset
   106
        n = n - items_values[r]
2fb6555011d3 cleared up Random Weapons and implemented remembering of weapons in Balanced Random Weapons too, also seems to work
Henek
parents: 5127
diff changeset
   107
    end
5827
a416f1070fdf we don't need trailing whitespaces... I guess :P
sheepluva
parents: 5141
diff changeset
   108
5141
2fb6555011d3 cleared up Random Weapons and implemented remembering of weapons in Balanced Random Weapons too, also seems to work
Henek
parents: 5127
diff changeset
   109
    return picked_items
2fb6555011d3 cleared up Random Weapons and implemented remembering of weapons in Balanced Random Weapons too, also seems to work
Henek
parents: 5127
diff changeset
   110
end
2fb6555011d3 cleared up Random Weapons and implemented remembering of weapons in Balanced Random Weapons too, also seems to work
Henek
parents: 5127
diff changeset
   111
2fb6555011d3 cleared up Random Weapons and implemented remembering of weapons in Balanced Random Weapons too, also seems to work
Henek
parents: 5127
diff changeset
   112
function assignAmmo(hog)
2fb6555011d3 cleared up Random Weapons and implemented remembering of weapons in Balanced Random Weapons too, also seems to work
Henek
parents: 5127
diff changeset
   113
    local name = GetHogTeamName(hog)
2fb6555011d3 cleared up Random Weapons and implemented remembering of weapons in Balanced Random Weapons too, also seems to work
Henek
parents: 5127
diff changeset
   114
    local processed = getTeamValue(name, "processed")
2fb6555011d3 cleared up Random Weapons and implemented remembering of weapons in Balanced Random Weapons too, also seems to work
Henek
parents: 5127
diff changeset
   115
    if processed == nil or not processed then
2fb6555011d3 cleared up Random Weapons and implemented remembering of weapons in Balanced Random Weapons too, also seems to work
Henek
parents: 5127
diff changeset
   116
        local ammo = getTeamValue(name, "ammo")
2fb6555011d3 cleared up Random Weapons and implemented remembering of weapons in Balanced Random Weapons too, also seems to work
Henek
parents: 5127
diff changeset
   117
        if ammo == nil then
2fb6555011d3 cleared up Random Weapons and implemented remembering of weapons in Balanced Random Weapons too, also seems to work
Henek
parents: 5127
diff changeset
   118
            ammo = randomAmmo()
2fb6555011d3 cleared up Random Weapons and implemented remembering of weapons in Balanced Random Weapons too, also seems to work
Henek
parents: 5127
diff changeset
   119
            setTeamValue(name, "ammo", ammo)
2fb6555011d3 cleared up Random Weapons and implemented remembering of weapons in Balanced Random Weapons too, also seems to work
Henek
parents: 5127
diff changeset
   120
        end
2fb6555011d3 cleared up Random Weapons and implemented remembering of weapons in Balanced Random Weapons too, also seems to work
Henek
parents: 5127
diff changeset
   121
        for i, w in pairs(ammo) do
2fb6555011d3 cleared up Random Weapons and implemented remembering of weapons in Balanced Random Weapons too, also seems to work
Henek
parents: 5127
diff changeset
   122
            AddAmmo(hog, w)
2fb6555011d3 cleared up Random Weapons and implemented remembering of weapons in Balanced Random Weapons too, also seems to work
Henek
parents: 5127
diff changeset
   123
        end
2fb6555011d3 cleared up Random Weapons and implemented remembering of weapons in Balanced Random Weapons too, also seems to work
Henek
parents: 5127
diff changeset
   124
        setTeamValue(name, "processed", true)
2fb6555011d3 cleared up Random Weapons and implemented remembering of weapons in Balanced Random Weapons too, also seems to work
Henek
parents: 5127
diff changeset
   125
    end
2fb6555011d3 cleared up Random Weapons and implemented remembering of weapons in Balanced Random Weapons too, also seems to work
Henek
parents: 5127
diff changeset
   126
end
2fb6555011d3 cleared up Random Weapons and implemented remembering of weapons in Balanced Random Weapons too, also seems to work
Henek
parents: 5127
diff changeset
   127
2fb6555011d3 cleared up Random Weapons and implemented remembering of weapons in Balanced Random Weapons too, also seems to work
Henek
parents: 5127
diff changeset
   128
function reset(hog)
2fb6555011d3 cleared up Random Weapons and implemented remembering of weapons in Balanced Random Weapons too, also seems to work
Henek
parents: 5127
diff changeset
   129
    setTeamValue(GetHogTeamName(hog), "processed", false)
2fb6555011d3 cleared up Random Weapons and implemented remembering of weapons in Balanced Random Weapons too, also seems to work
Henek
parents: 5127
diff changeset
   130
end
2fb6555011d3 cleared up Random Weapons and implemented remembering of weapons in Balanced Random Weapons too, also seems to work
Henek
parents: 5127
diff changeset
   131
5127
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
   132
function onGameInit()
10036
3be36d2fdca6 use new API for changing GameFlags
sheepluva
parents: 8043
diff changeset
   133
    DisableGameFlags(gfPerHogAmmo)
3be36d2fdca6 use new API for changing GameFlags
sheepluva
parents: 8043
diff changeset
   134
    EnableGameFlags(gfResetWeps)
5141
2fb6555011d3 cleared up Random Weapons and implemented remembering of weapons in Balanced Random Weapons too, also seems to work
Henek
parents: 5127
diff changeset
   135
    Goals = loc("Each turn you get 1-3 random weapons")
13718
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13173
diff changeset
   136
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13173
diff changeset
   137
    isUtility = {
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13173
diff changeset
   138
        [amTeleport] = true,
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13173
diff changeset
   139
        [amGirder] = true,
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13173
diff changeset
   140
        [amSwitch] = true,
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13173
diff changeset
   141
        [amLowGravity] = true,
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13173
diff changeset
   142
        [amResurrector] = true,
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13173
diff changeset
   143
        [amRope] = true,
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13173
diff changeset
   144
        [amParachute] = true,
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13173
diff changeset
   145
        [amJetpack] = true,
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13173
diff changeset
   146
        [amPortalGun] = true,
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13173
diff changeset
   147
        [amRubber] = true,
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13173
diff changeset
   148
        [amTardis] = true,
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13173
diff changeset
   149
        [amLandGun] = true,
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13173
diff changeset
   150
        [amExtraTime] = true,
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13173
diff changeset
   151
        [amVampiric] = true,
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13173
diff changeset
   152
        [amLaserSight] = true,
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13173
diff changeset
   153
        [amExtraDamage] = true,
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13173
diff changeset
   154
        [amInvulnerable] = true,
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13173
diff changeset
   155
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13173
diff changeset
   156
        -- unusual classification
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13173
diff changeset
   157
        [amSnowball] = true,
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13173
diff changeset
   158
    }
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13173
diff changeset
   159
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13173
diff changeset
   160
    isAirWeapon = {
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13173
diff changeset
   161
        [amAirAttack] = true,
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13173
diff changeset
   162
        [amMineStrike] = true,
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13173
diff changeset
   163
        [amNapalm] = true,
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13173
diff changeset
   164
        [amDrillStrike] = true,
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13173
diff changeset
   165
        [amPiano] = true,
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13173
diff changeset
   166
    }
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13173
diff changeset
   167
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13173
diff changeset
   168
end
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13173
diff changeset
   169
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13173
diff changeset
   170
local function getCost(ammoType, ammoCount)
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13173
diff changeset
   171
    if ammoCount == 0 or ammoCount == 9 then
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13173
diff changeset
   172
        return 0
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13173
diff changeset
   173
    else
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13173
diff changeset
   174
        local max
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13173
diff changeset
   175
        if isUtility[ammoType] then
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13173
diff changeset
   176
            -- Force-limit cost of utilities to 2 because utilities with
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13173
diff changeset
   177
            -- a cost of 3 could never be "paid"
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13173
diff changeset
   178
            max = 2
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13173
diff changeset
   179
        else
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13173
diff changeset
   180
            max = 3
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13173
diff changeset
   181
        end
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13173
diff changeset
   182
        return math.max(1, math.min(max, 4 - ammoCount))
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13173
diff changeset
   183
    end
5127
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
   184
end
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
   185
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
   186
function onGameStart()
5141
2fb6555011d3 cleared up Random Weapons and implemented remembering of weapons in Balanced Random Weapons too, also seems to work
Henek
parents: 5127
diff changeset
   187
    trackTeams()
5127
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
   188
    if MapHasBorder() == false then
13718
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13173
diff changeset
   189
        for a = 0, AmmoTypeMax do
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13173
diff changeset
   190
            if a ~= amNothing and a ~= amSkip then
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13173
diff changeset
   191
                local ammoCount = GetAmmo(a)
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13173
diff changeset
   192
                local cost = getCost(a, ammoCount)
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13173
diff changeset
   193
                if cost > 0 and isAirWeapon[a] then
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13173
diff changeset
   194
                    table.insert(airweapons, a)
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13173
diff changeset
   195
                    table.insert(airweapons_values, cost)
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13173
diff changeset
   196
                end
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13173
diff changeset
   197
            end
5127
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
   198
        end
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
   199
    end
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
   200
end
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
   201
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
   202
function onAmmoStoreInit()
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
   203
    SetAmmo(amSkip, 9, 0, 0, 0)
5827
a416f1070fdf we don't need trailing whitespaces... I guess :P
sheepluva
parents: 5141
diff changeset
   204
13718
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13173
diff changeset
   205
    for a=0, AmmoTypeMax do
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13173
diff changeset
   206
        if a ~= amNothing and a ~= amSkip then
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13173
diff changeset
   207
            local ammoCount, prob, delay, ammoInCrate = GetAmmo(a)
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13173
diff changeset
   208
            local cost = getCost(a, ammoCount)
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13173
diff changeset
   209
            if (not isAirWeapon[a]) then
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13173
diff changeset
   210
                if cost > 0 then
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13173
diff changeset
   211
                    if isUtility[a] then
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13173
diff changeset
   212
                        table.insert(utilities, a)
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13173
diff changeset
   213
                        table.insert(utilities, cost)
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13173
diff changeset
   214
                    else
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13173
diff changeset
   215
                        table.insert(weapons, a)
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13173
diff changeset
   216
                        table.insert(weapons_values, cost)
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13173
diff changeset
   217
                    end
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13173
diff changeset
   218
                end
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13173
diff changeset
   219
            else
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13173
diff changeset
   220
                prob = 0
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13173
diff changeset
   221
            end
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13173
diff changeset
   222
            local realAmmoCount
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13173
diff changeset
   223
            if ammoCount ~= 9 then
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13173
diff changeset
   224
                realAmmoCount = 0
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13173
diff changeset
   225
            else
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13173
diff changeset
   226
                realAmmoCount = 1
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13173
diff changeset
   227
            end
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13173
diff changeset
   228
            SetAmmo(a, realAmmoCount, prob, delay, ammoInCrate)
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13173
diff changeset
   229
        end
5127
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
   230
    end
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
   231
end
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
   232
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
   233
function onNewTurn()
5141
2fb6555011d3 cleared up Random Weapons and implemented remembering of weapons in Balanced Random Weapons too, also seems to work
Henek
parents: 5127
diff changeset
   234
    runOnGears(assignAmmo)
2fb6555011d3 cleared up Random Weapons and implemented remembering of weapons in Balanced Random Weapons too, also seems to work
Henek
parents: 5127
diff changeset
   235
    runOnGears(reset)
2fb6555011d3 cleared up Random Weapons and implemented remembering of weapons in Balanced Random Weapons too, also seems to work
Henek
parents: 5127
diff changeset
   236
    setTeamValue(GetHogTeamName(CurrentHedgehog), "ammo", nil)
2fb6555011d3 cleared up Random Weapons and implemented remembering of weapons in Balanced Random Weapons too, also seems to work
Henek
parents: 5127
diff changeset
   237
end
5127
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
   238
5141
2fb6555011d3 cleared up Random Weapons and implemented remembering of weapons in Balanced Random Weapons too, also seems to work
Henek
parents: 5127
diff changeset
   239
function onGearAdd(gear)
2fb6555011d3 cleared up Random Weapons and implemented remembering of weapons in Balanced Random Weapons too, also seems to work
Henek
parents: 5127
diff changeset
   240
    if GetGearType(gear) == gtHedgehog then
2fb6555011d3 cleared up Random Weapons and implemented remembering of weapons in Balanced Random Weapons too, also seems to work
Henek
parents: 5127
diff changeset
   241
        trackGear(gear)
5127
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
   242
    end
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
   243
end
5141
2fb6555011d3 cleared up Random Weapons and implemented remembering of weapons in Balanced Random Weapons too, also seems to work
Henek
parents: 5127
diff changeset
   244
2fb6555011d3 cleared up Random Weapons and implemented remembering of weapons in Balanced Random Weapons too, also seems to work
Henek
parents: 5127
diff changeset
   245
function onGearDelete(gear)
2fb6555011d3 cleared up Random Weapons and implemented remembering of weapons in Balanced Random Weapons too, also seems to work
Henek
parents: 5127
diff changeset
   246
    trackDeletion(gear)
2fb6555011d3 cleared up Random Weapons and implemented remembering of weapons in Balanced Random Weapons too, also seems to work
Henek
parents: 5127
diff changeset
   247
end