share/hedgewars/Data/Scripts/Tracker.lua
author Henek
Sat, 22 Jan 2011 22:31:05 +0100
changeset 4869 7a720b5d2247
parent 4854 881c8232b66a
child 4873 98dbb9b985e5
permissions -rw-r--r--
added GetGearRaduis and minor Tracker things
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4854
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
     1
-- Library for keeping track of gears in the game
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
     2
-- and running functions on them
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
     3
-- also keeps track of clans and teams
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
     4
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
     5
local trackingTeams = false
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
     6
local resurrecting = false
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
     7
local gears = {}
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
     8
local teams = {}
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
     9
local clans = {}
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
    10
local resurrectedHogs = {}
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
    11
local gearValues = {}
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
    12
local teamValues = {}
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
    13
local clanValues = {}
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
    14
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
    15
-- Registers when a gear is added
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
    16
function trackGear(gear)
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
    17
    table.insert(gears, gear)
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
    18
    if trackingTeams and GetGearType(gear) == gtResurrector then
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
    19
        resurrecting = true
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
    20
    elseif resurrecting and GetGearType(gear) == gtHedgehog then
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
    21
        table.insert(resurrectedHogs, gear)
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
    22
    end
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
    23
end
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
    24
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
    25
-- Registers when a gear is deleted
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
    26
function trackDeletion(gear)
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
    27
    gearValues[gear] = nil
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
    28
    for k, g in ipairs(gears) do
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
    29
        if g == gear then
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
    30
            table.remove(gears, k)
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
    31
            break
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
    32
        end
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
    33
    end
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
    34
    if trackingTeams and GetGearType(gear) == gtHedgehog then
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
    35
        for team, hogs in pairs(teams) do
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
    36
            if team == GetHogTeamName(gear) then
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
    37
                if table.maxn(hogs) == 1 then
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
    38
                    hogs = nil
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
    39
                else
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
    40
                    for k, hog in ipairs(hogs) do
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
    41
                        if hog == gear then
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
    42
                            table.remove(hogs, k)
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
    43
                            break
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
    44
                        end
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
    45
                    end
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
    46
                end
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
    47
                break
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
    48
            end
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
    49
        end
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
    50
    elseif resurrecting and GetGearType(gear) == gtResurrector then
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
    51
        for k, gear in ipairs(resurrectedHogs) do
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
    52
            team = GetHogTeamName(gear)
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
    53
            if teams[team] == nil then
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
    54
                teams[team] = {}
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
    55
            end
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
    56
            table.insert(teams[team], gear)
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
    57
        end
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
    58
        resurrecting = false
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
    59
        resurrectedHogs = {}
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
    60
    end
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
    61
end
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
    62
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
    63
-- Not needed?
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
    64
-- Registers when a gear is resurrected
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
    65
--function trackResurrection(gear)
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
    66
--    if trackingTeams then
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
    67
--        if GetGearType(gear) == gtHedgehog then
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
    68
--            found = false
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
    69
--            for team, hogs in pairs(teams) do
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
    70
--                if team == GetHogTeamName(gear) then
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
    71
--                    table.insert(hogs, gear)
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
    72
--                    found = true
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
    73
--                end
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
    74
--            end
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
    75
--            if not found then
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
    76
--                teams[GetHogTeamName(gear)] = { gear }
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
    77
--            end
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
    78
--        end
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
    79
--    end
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
    80
--end
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
    81
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
    82
-- Start to keep track of teams
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
    83
function trackTeams()
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
    84
    if not trackingTeams then
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
    85
        trackingTeams = true
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
    86
        for k, gear in ipairs(gears) do
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
    87
            if GetGearType(gear) == gtHedgehog then
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
    88
                team = GetHogTeamName(gear)
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
    89
                if teams[team] == nil then
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
    90
                    teams[team] = { gear }
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
    91
                    clans[team] = GetHogClan(gear)
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
    92
                else
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
    93
                    table.insert(teams[team], gear)
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
    94
                end
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
    95
            end
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
    96
        end
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
    97
    end
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
    98
end
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
    99
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   100
-- Get a value for a specific gear
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   101
function getGearValue(gear, key)
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   102
    if gearValues[gear] ~= nil then
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   103
        return gearValues[gear][key]
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   104
    end
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   105
    return nil
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   106
end
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   107
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   108
-- Set a value for a specific gear
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   109
function setGearValue(gear, key, value)
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   110
    found = false
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   111
    for id, values in pairs(gearValues) do
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   112
        if id == gear then
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   113
            values[key] = value
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   114
            found = true
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   115
        end
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   116
    end
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   117
    if not found then
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   118
        gearValues[gear] = { [key] = value }
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   119
    end
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   120
end
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   121
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   122
-- Increase a value for a specific gear
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   123
function increaseGearValue(gear, key)
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   124
    for id, values in pairs(gearValues) do
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   125
        if id == gear then
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   126
            values[key] = values[key] + 1
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   127
        end
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   128
    end
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   129
end
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   130
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   131
-- Decrease a value for a specific gear
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   132
function decreaseGearValue(gear, key)
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   133
    for id, values in pairs(gearValues) do
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   134
        if id == gear then
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   135
            values[key] = values[key] - 1
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   136
        end
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   137
    end
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   138
end
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   139
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   140
-- Get a value for a specific team
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   141
function getTeamValue(team, key)
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   142
    if teamValues[team] ~= nil then
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   143
        return teamValues[team][key]
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   144
    end
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   145
    return nil
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   146
end
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   147
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   148
-- Set a value for a specific team
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   149
function setTeamValue(team, key, value)
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   150
    found = false
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   151
    for name, values in pairs(teamValues) do
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   152
        if name == team then
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   153
            values[key] = value
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   154
            found = true
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   155
        end
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   156
    end
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   157
    if not found then
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   158
        teamValues[team] = { [key] = value }
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   159
    end
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   160
end
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   161
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   162
-- Increase a value for a specific team
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   163
function increaseTeamValue(team, key)
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   164
    for name, values in pairs(teamValues) do
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   165
        if name == team then
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   166
            values[key] = values[key] + 1
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   167
        end
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   168
    end
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   169
end
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   170
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   171
-- Decrease a value for a specific team
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   172
function decreaseTeamValue(team, key)
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   173
    for name, values in pairs(teamValues) do
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   174
        if name == team then
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   175
            values[key] = values[key] - 1
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   176
        end
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   177
    end
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   178
end
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   179
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   180
-- Get a value for a specific clan
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   181
function getClanValue(clan, key)
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   182
    if clanValues[clan] ~= nil then
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   183
        return clanValues[clan][key]
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   184
    end
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   185
    return nil
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   186
end
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   187
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   188
-- Set a value for a specific clan
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   189
function setClanValue(clan, key, value)
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   190
    found = false
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   191
    for num, values in ipairs(clanValues) do
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   192
        if num == clan then
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   193
            values[key] = value
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   194
            found = true
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   195
        end
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   196
    end
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   197
    if not found then
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   198
        clanValues[clan] = { [key] = value }
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   199
    end
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   200
end
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   201
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   202
-- Increase a value for a specific clan
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   203
function increaseClanValue(clan, key)
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   204
    for num, values in ipairs(clanValues) do
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   205
        if num == clan then
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   206
            values[key] = values[key] + 1
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   207
        end
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   208
    end
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   209
end
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   210
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   211
-- Decrease a value for a specific clan
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   212
function decreaseClanValue(clan, key)
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   213
    for num, values in ipairs(clanValues) do
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   214
        if num == clan then
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   215
            values[key] = values[key] - 1
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   216
        end
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   217
    end
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   218
end
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   219
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   220
-- Run a function on all tracked gears
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   221
function runOnGears(func)
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   222
    for k, gear in ipairs(gears) do
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   223
        func(gear)
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   224
    end
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   225
end
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   226
4869
7a720b5d2247 added GetGearRaduis and minor Tracker things
Henek
parents: 4854
diff changeset
   227
-- Run a function on all gears within a box
7a720b5d2247 added GetGearRaduis and minor Tracker things
Henek
parents: 4854
diff changeset
   228
function runOnGearsInBox(func, x, y, w, h)
7a720b5d2247 added GetGearRaduis and minor Tracker things
Henek
parents: 4854
diff changeset
   229
    for k, gear in ipairs(gears) do
7a720b5d2247 added GetGearRaduis and minor Tracker things
Henek
parents: 4854
diff changeset
   230
        gx, gy = GetGearPosition(gear)
7a720b5d2247 added GetGearRaduis and minor Tracker things
Henek
parents: 4854
diff changeset
   231
        if gx >= x and gy >= y and gx <= x + w and gy <= y + h then
7a720b5d2247 added GetGearRaduis and minor Tracker things
Henek
parents: 4854
diff changeset
   232
            func(gear)
7a720b5d2247 added GetGearRaduis and minor Tracker things
Henek
parents: 4854
diff changeset
   233
        end
7a720b5d2247 added GetGearRaduis and minor Tracker things
Henek
parents: 4854
diff changeset
   234
    end
7a720b5d2247 added GetGearRaduis and minor Tracker things
Henek
parents: 4854
diff changeset
   235
end
7a720b5d2247 added GetGearRaduis and minor Tracker things
Henek
parents: 4854
diff changeset
   236
7a720b5d2247 added GetGearRaduis and minor Tracker things
Henek
parents: 4854
diff changeset
   237
-- Run a function on all gears within a circle
7a720b5d2247 added GetGearRaduis and minor Tracker things
Henek
parents: 4854
diff changeset
   238
function runOnGearsInCircle(func, x, y, r)
7a720b5d2247 added GetGearRaduis and minor Tracker things
Henek
parents: 4854
diff changeset
   239
    for k, gear in ipairs(gears) do
7a720b5d2247 added GetGearRaduis and minor Tracker things
Henek
parents: 4854
diff changeset
   240
        gx, gy = GetGearPosition(gear)
7a720b5d2247 added GetGearRaduis and minor Tracker things
Henek
parents: 4854
diff changeset
   241
        gr = GetGearRadius(gear)
7a720b5d2247 added GetGearRaduis and minor Tracker things
Henek
parents: 4854
diff changeset
   242
        if (r + gr) ^ 2 >= (x - gx) ^ 2 + (y - gy) ^ 2 then
7a720b5d2247 added GetGearRaduis and minor Tracker things
Henek
parents: 4854
diff changeset
   243
            func(gear)
7a720b5d2247 added GetGearRaduis and minor Tracker things
Henek
parents: 4854
diff changeset
   244
        end
7a720b5d2247 added GetGearRaduis and minor Tracker things
Henek
parents: 4854
diff changeset
   245
    end
7a720b5d2247 added GetGearRaduis and minor Tracker things
Henek
parents: 4854
diff changeset
   246
end
7a720b5d2247 added GetGearRaduis and minor Tracker things
Henek
parents: 4854
diff changeset
   247
4854
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   248
-- Run a function on all tracked hogs
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   249
function runOnHogs(func)
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   250
    for k, hogs in pairs(teams) do
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   251
        for m, hog in ipairs(hogs) do
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   252
            func(hog)
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   253
        end
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   254
    end
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   255
end
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   256
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   257
-- Run a function on hogs in a team
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   258
function runOnHogsInTeam(func, team)
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   259
    if teams[team] ~= nil then
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   260
        for k, hog in ipairs(teams[team]) do
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   261
            func(hog)
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   262
        end
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   263
    end
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   264
end
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   265
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   266
-- Run a function on hogs in other teams
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   267
function runOnHogsInOtherTeams(func, team)
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   268
    for k, hogs in pairs(teams) do
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   269
        if k ~= team then
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   270
            for m, hog in ipairs(hogs) do
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   271
                func(hog)
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   272
            end
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   273
        end
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   274
    end
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   275
end
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   276
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   277
-- Run a function on hogs in a clan
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   278
function runOnHogsInClan(func, clan)
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   279
    for i = 1, table.maxn(clans) do
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   280
        if clans[i] == clan then
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   281
            for k, hog in ipairs(teams[i]) do
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   282
                func(hog)
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   283
            end
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   284
        end
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   285
    end
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   286
end
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   287
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   288
-- Run a function on hogs in other clans
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   289
function runOnHogsInOtherClans(func, clan)
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   290
    for i = 1, table.maxn(clans) do
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   291
        if clans[i] ~= clan then
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   292
            for k, hog in ipairs(teams[i]) do
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   293
                func(hog)
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   294
            end
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   295
        end
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   296
    end
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   297
end
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   298
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   299
function numGears()
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   300
    return table.maxn(gears)
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   301
end
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   302
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   303
function numTeams()
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   304
    num = 0
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   305
    for team, hogs in pairs(teams) do
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   306
        num = num + 1
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   307
    end
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   308
    return num
881c8232b66a adding my new Tracker library so mikade can use it with you guys on dev, still might change a bit though
Henek
parents:
diff changeset
   309
end