share/hedgewars/Data/Scripts/Multiplayer/Balanced_Random_Weapon.lua
author Wuzzy <Wuzzy2@mail.ru>
Fri, 31 Aug 2018 11:11:58 +0200
changeset 13722 ed22eb551a75
parent 13721 6d57f5f61c09
child 13723 7284233d9132
permissions -rw-r--r--
Fix BRW breaking when weapon scheme assigns 2 bullet for all ammos
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
13721
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13178
diff changeset
     1
--[[
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13178
diff changeset
     2
Balanced Random Weapon
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13178
diff changeset
     3
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13178
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: 13178
diff changeset
     5
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13178
diff changeset
     6
= CUSTOMIZATION =
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13178
diff changeset
     7
The weapon chances are chosen with the weapons scheme.
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13178
diff changeset
     8
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13178
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: 13178
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: 13178
diff changeset
    11
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13178
diff changeset
    12
* infinity = always get this weapon
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13178
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: 13178
diff changeset
    14
* 2 bullets = medium probability
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13178
diff changeset
    15
* 1 bullet = low probability
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13178
diff changeset
    16
* 0 bullets = never
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13178
diff changeset
    17
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13178
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: 13178
diff changeset
    19
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13178
diff changeset
    20
The "probabilities" tab is, as usual, for crate probabilities.
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13178
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: 13178
diff changeset
    22
]]
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13178
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
13721
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13178
diff changeset
    27
local weapons = {}
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13178
diff changeset
    28
local weapons_values = {}
13722
ed22eb551a75 Fix BRW breaking when weapon scheme assigns 2 bullet for all ammos
Wuzzy <Wuzzy2@mail.ru>
parents: 13721
diff changeset
    29
local weapons_count = 0
13721
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13178
diff changeset
    30
local airweapons = {}
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13178
diff changeset
    31
local airweapons_values = {}
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13178
diff changeset
    32
local utilities = {}
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13178
diff changeset
    33
local utilities_values = {}
5127
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
    34
13721
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13178
diff changeset
    35
local isUtility, isAirWeapon
5127
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
    36
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
    37
function randomAmmo()
13721
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13178
diff changeset
    38
--[[
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13178
diff changeset
    39
= WEAPON SELECTION ALGORITHM =
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13178
diff changeset
    40
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: 13178
diff changeset
    41
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: 13178
diff changeset
    42
from the ammo menu (see getCost).
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13178
diff changeset
    43
Utilities are forced to have a cost of 1-2.
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13178
diff changeset
    44
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13178
diff changeset
    45
Steps:
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13178
diff changeset
    46
1. Add a random weapon to ammo and subtract cost
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13178
diff changeset
    47
2. If there's still points left:
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13178
diff changeset
    48
    a. Forget any item in mind
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13178
diff changeset
    49
    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: 13178
diff changeset
    50
    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: 13178
diff changeset
    51
    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: 13178
diff changeset
    52
    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: 13178
diff changeset
    53
    f. Return to step 2
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13178
diff changeset
    54
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13178
diff changeset
    55
If 0 points are left, the algorithm terminates.
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13178
diff changeset
    56
]]
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13178
diff changeset
    57
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
    58
    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
    59
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
    60
    --pick random weapon and subtract cost
13722
ed22eb551a75 Fix BRW breaking when weapon scheme assigns 2 bullet for all ammos
Wuzzy <Wuzzy2@mail.ru>
parents: 13721
diff changeset
    61
    local r = GetRandom(weapons_count) + 1
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
    62
    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
    63
    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
    64
    n = n - weapons_values[r]
5827
a416f1070fdf we don't need trailing whitespaces... I guess :P
sheepluva
parents: 5141
diff changeset
    65
a416f1070fdf we don't need trailing whitespaces... I guess :P
sheepluva
parents: 5141
diff changeset
    66
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
    67
    --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
    68
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
    69
    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
    70
        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
    71
        local items_values = {}
13722
ed22eb551a75 Fix BRW breaking when weapon scheme assigns 2 bullet for all ammos
Wuzzy <Wuzzy2@mail.ru>
parents: 13721
diff changeset
    72
        local items_count = 0
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
    73
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
        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
    75
            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
    76
            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
    77
                --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
    78
                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
    79
                    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
    80
                        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
    81
                    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
    82
                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
    83
                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
    84
                    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
    85
                    table.insert(items, weapons[i])
13722
ed22eb551a75 Fix BRW breaking when weapon scheme assigns 2 bullet for all ammos
Wuzzy <Wuzzy2@mail.ru>
parents: 13721
diff changeset
    86
                    items_count = items_count + 1
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
    87
                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
    88
            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
    89
        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
    90
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
        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
    92
            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
    93
            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
    94
                --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
    95
                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
    96
                    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
    97
                        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
    98
                    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
    99
                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
   100
                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
   101
                    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
   102
                    table.insert(items, utilities[i])
13722
ed22eb551a75 Fix BRW breaking when weapon scheme assigns 2 bullet for all ammos
Wuzzy <Wuzzy2@mail.ru>
parents: 13721
diff changeset
   103
                    items_count = items_count + 1
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
                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
   105
            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
   106
        end
5827
a416f1070fdf we don't need trailing whitespaces... I guess :P
sheepluva
parents: 5141
diff changeset
   107
13722
ed22eb551a75 Fix BRW breaking when weapon scheme assigns 2 bullet for all ammos
Wuzzy <Wuzzy2@mail.ru>
parents: 13721
diff changeset
   108
        if items_count > 0 then
ed22eb551a75 Fix BRW breaking when weapon scheme assigns 2 bullet for all ammos
Wuzzy <Wuzzy2@mail.ru>
parents: 13721
diff changeset
   109
            local r = GetRandom(items_count) + 1
ed22eb551a75 Fix BRW breaking when weapon scheme assigns 2 bullet for all ammos
Wuzzy <Wuzzy2@mail.ru>
parents: 13721
diff changeset
   110
            table.insert(picked_items, items[r])
ed22eb551a75 Fix BRW breaking when weapon scheme assigns 2 bullet for all ammos
Wuzzy <Wuzzy2@mail.ru>
parents: 13721
diff changeset
   111
            n = n - items_values[r]
ed22eb551a75 Fix BRW breaking when weapon scheme assigns 2 bullet for all ammos
Wuzzy <Wuzzy2@mail.ru>
parents: 13721
diff changeset
   112
        else
ed22eb551a75 Fix BRW breaking when weapon scheme assigns 2 bullet for all ammos
Wuzzy <Wuzzy2@mail.ru>
parents: 13721
diff changeset
   113
            break
ed22eb551a75 Fix BRW breaking when weapon scheme assigns 2 bullet for all ammos
Wuzzy <Wuzzy2@mail.ru>
parents: 13721
diff changeset
   114
        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
   115
    end
5827
a416f1070fdf we don't need trailing whitespaces... I guess :P
sheepluva
parents: 5141
diff changeset
   116
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
   117
    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
   118
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
   119
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
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
   121
    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
   122
    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
   123
    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
   124
        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
   125
        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
   126
            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
   127
            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
   128
        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
   129
        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
   130
            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
   131
        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
   132
        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
   133
    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
   134
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
   135
2fb6555011d3 cleared up Random Weapons and implemented remembering of weapons in Balanced Random Weapons too, also seems to work
Henek
parents: 5127
diff changeset
   136
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
   137
    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
   138
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
   139
5127
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
   140
function onGameInit()
10036
3be36d2fdca6 use new API for changing GameFlags
sheepluva
parents: 8043
diff changeset
   141
    DisableGameFlags(gfPerHogAmmo)
3be36d2fdca6 use new API for changing GameFlags
sheepluva
parents: 8043
diff changeset
   142
    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
   143
    Goals = loc("Each turn you get 1-3 random weapons")
13721
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13178
diff changeset
   144
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13178
diff changeset
   145
    isUtility = {
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13178
diff changeset
   146
        [amTeleport] = true,
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13178
diff changeset
   147
        [amGirder] = true,
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13178
diff changeset
   148
        [amSwitch] = true,
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13178
diff changeset
   149
        [amLowGravity] = true,
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13178
diff changeset
   150
        [amResurrector] = true,
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13178
diff changeset
   151
        [amRope] = true,
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13178
diff changeset
   152
        [amParachute] = true,
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13178
diff changeset
   153
        [amJetpack] = true,
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13178
diff changeset
   154
        [amPortalGun] = true,
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13178
diff changeset
   155
        [amRubber] = true,
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13178
diff changeset
   156
        [amTardis] = true,
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13178
diff changeset
   157
        [amLandGun] = true,
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13178
diff changeset
   158
        [amExtraTime] = true,
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13178
diff changeset
   159
        [amVampiric] = true,
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13178
diff changeset
   160
        [amLaserSight] = true,
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13178
diff changeset
   161
        [amExtraDamage] = true,
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13178
diff changeset
   162
        [amInvulnerable] = true,
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13178
diff changeset
   163
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13178
diff changeset
   164
        -- unusual classification
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13178
diff changeset
   165
        [amSnowball] = true,
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13178
diff changeset
   166
    }
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13178
diff changeset
   167
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13178
diff changeset
   168
    isAirWeapon = {
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13178
diff changeset
   169
        [amAirAttack] = true,
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13178
diff changeset
   170
        [amMineStrike] = true,
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13178
diff changeset
   171
        [amNapalm] = true,
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13178
diff changeset
   172
        [amDrillStrike] = true,
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13178
diff changeset
   173
        [amPiano] = true,
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13178
diff changeset
   174
    }
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13178
diff changeset
   175
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13178
diff changeset
   176
end
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13178
diff changeset
   177
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13178
diff changeset
   178
local function getCost(ammoType, ammoCount)
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13178
diff changeset
   179
    if ammoCount == 0 or ammoCount == 9 then
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13178
diff changeset
   180
        return 0
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13178
diff changeset
   181
    else
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13178
diff changeset
   182
        local max
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13178
diff changeset
   183
        if isUtility[ammoType] then
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13178
diff changeset
   184
            -- Force-limit cost of utilities to 2 because utilities with
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13178
diff changeset
   185
            -- a cost of 3 could never be "paid"
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13178
diff changeset
   186
            max = 2
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13178
diff changeset
   187
        else
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13178
diff changeset
   188
            max = 3
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13178
diff changeset
   189
        end
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13178
diff changeset
   190
        return math.max(1, math.min(max, 4 - ammoCount))
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13178
diff changeset
   191
    end
5127
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
   192
end
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
   193
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
   194
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
   195
    trackTeams()
5127
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
   196
    if MapHasBorder() == false then
13721
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13178
diff changeset
   197
        for a = 0, AmmoTypeMax do
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13178
diff changeset
   198
            if a ~= amNothing and a ~= amSkip then
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13178
diff changeset
   199
                local ammoCount = GetAmmo(a)
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13178
diff changeset
   200
                local cost = getCost(a, ammoCount)
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13178
diff changeset
   201
                if cost > 0 and isAirWeapon[a] then
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13178
diff changeset
   202
                    table.insert(airweapons, a)
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13178
diff changeset
   203
                    table.insert(airweapons_values, cost)
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13178
diff changeset
   204
                end
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13178
diff changeset
   205
            end
5127
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
   206
        end
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
   207
    end
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
   208
end
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
   209
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
   210
function onAmmoStoreInit()
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
   211
    SetAmmo(amSkip, 9, 0, 0, 0)
5827
a416f1070fdf we don't need trailing whitespaces... I guess :P
sheepluva
parents: 5141
diff changeset
   212
13721
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13178
diff changeset
   213
    for a=0, AmmoTypeMax do
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13178
diff changeset
   214
        if a ~= amNothing and a ~= amSkip then
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13178
diff changeset
   215
            local ammoCount, prob, delay, ammoInCrate = GetAmmo(a)
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13178
diff changeset
   216
            local cost = getCost(a, ammoCount)
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13178
diff changeset
   217
            if (not isAirWeapon[a]) then
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13178
diff changeset
   218
                if cost > 0 then
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13178
diff changeset
   219
                    if isUtility[a] then
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13178
diff changeset
   220
                        table.insert(utilities, a)
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13178
diff changeset
   221
                        table.insert(utilities, cost)
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13178
diff changeset
   222
                    else
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13178
diff changeset
   223
                        table.insert(weapons, a)
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13178
diff changeset
   224
                        table.insert(weapons_values, cost)
13722
ed22eb551a75 Fix BRW breaking when weapon scheme assigns 2 bullet for all ammos
Wuzzy <Wuzzy2@mail.ru>
parents: 13721
diff changeset
   225
                        weapons_count = weapons_count + 1
13721
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13178
diff changeset
   226
                    end
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13178
diff changeset
   227
                end
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13178
diff changeset
   228
            else
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13178
diff changeset
   229
                prob = 0
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13178
diff changeset
   230
            end
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13178
diff changeset
   231
            local realAmmoCount
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13178
diff changeset
   232
            if ammoCount ~= 9 then
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13178
diff changeset
   233
                realAmmoCount = 0
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13178
diff changeset
   234
            else
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13178
diff changeset
   235
                realAmmoCount = 1
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13178
diff changeset
   236
            end
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13178
diff changeset
   237
            SetAmmo(a, realAmmoCount, prob, delay, ammoInCrate)
6d57f5f61c09 BRW now allows weapon scheme customization
Wuzzy <Wuzzy2@mail.ru>
parents: 13178
diff changeset
   238
        end
5127
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
   239
    end
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
   240
end
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
   241
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
   242
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
   243
    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
   244
    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
   245
    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
   246
end
5127
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
   247
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
   248
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
   249
    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
   250
        trackGear(gear)
5127
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
   251
    end
b0b6f17a6a3c added Balanced Random Weapon gameplay script
claymore
parents:
diff changeset
   252
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
   253
2fb6555011d3 cleared up Random Weapons and implemented remembering of weapons in Balanced Random Weapons too, also seems to work
Henek
parents: 5127
diff changeset
   254
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
   255
    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
   256
end