diff Lists.lua @ 42:72055fc7e115

A lot of work to reign in namespacing (inspiration: WIM)
author John@Doomsday
date Thu, 15 Mar 2012 08:47:41 -0400
parents dc9bfacca238
children 4109683c3172
line wrap: on
line diff
--- a/Lists.lua	Wed Mar 14 22:06:19 2012 -0400
+++ b/Lists.lua	Thu Mar 15 08:47:41 2012 -0400
@@ -62,37 +62,54 @@
 --}}}
 
 -- there are some dep chains here. for instance, to have a raidIdP value, a
--- person must have a bsk.persons value which leads to a personName2id which
+-- person must have a persons value which leads to a personName2id which
 -- leads to a raidIdP
-
-bsk.lists = {}
-bsk.persons = {}
-
-bsk.raidNameP = {} -- "name" is present in raid
-bsk.raidIdP = {} -- "id" is present in raid
-bsk.reserveIdP = {} -- "reserve id present"
-local personName2id = {} -- given "name" get that person's id
-
+local bsk = bsk
+local _G=_G
+local table=table
+local string=string
 local tinsert = table.insert
 local sformat = string.format
 local getn = table.getn
+local wipe = wipe
+local pairs=pairs
+local ipairs=ipairs
+local tonumber=tonumber
+local tostring=tostring
+local time=time
+local date=date
+local math=math
+local type=type
+local assert=assert
+local getmetatable=getmetatable
+local setmetatable=setmetatable
+setfenv(1,bsk)
 
-function bsk:SelfDestruct()
-    bsk.lists = {}
-    bsk.persons = {}
-    bsk.db.profile.persons = {}
-    bsk.db.profile.changes = {}
-    bsk.db.profile.lists = {}
-    bsk.raidNameP = {}
-    bsk.raidIdP = {}
-    bsk.reserveIdP = {}
+lists = {}
+persons = {}
+
+raidNameP = {} -- "name" is present in raid
+raidIdP = {} -- "id" is present in raid
+reserveIdP = {} -- "reserve id present"
+local personName2id = {} -- given "name" get that person's id
+
+
+function SelfDestruct()
+    lists = {}
+    persons = {}
+    db.profile.persons = {}
+    db.profile.changes = {}
+    db.profile.lists = {}
+    raidNameP = {}
+    raidIdP = {}
+    reserveIdP = {}
     personName2id = {}
 end
-function bsk:tcopy(to, from)
+function tcopy(to, from)
   for k,v in pairs(from) do
     if(type(v)=="table") then
       to[k] = {}
-      bsk:tcopy(to[k], v);
+      tcopy(to[k], v);
     else
       to[k] = v;
     end
@@ -105,110 +122,110 @@
 end
 
 -- Debugging {{{
-function bsk:PrettyPrintList(listIndex)
-    local list = bsk.lists[listIndex]
+function PrettyPrintList(listIndex)
+    local list = lists[listIndex]
     bsk:Print("List: " .. list.name .. " (" .. listIndex .. ") - last modified " .. date("%m/%d/%y %H:%M:%S", list.time) .. " (",list.time,")" )
     for i = 1,#list do
-        bsk:Print("  " .. i .. " - " .. bsk.persons[list[i].id].main)
+        bsk:Print("  " .. i .. " - " .. persons[list[i].id].main)
     end
 end
-function bsk:PrettyPrintLists()
-    for i,_ in pairs(bsk.lists) do
-        bsk:PrettyPrintList(i)
+function PrettyPrintLists()
+    for i,_ in pairs(lists) do
+        PrettyPrintList(i)
     end
 end
-function bsk:PrintLists()
-    bsk:PrintTable(bsk.lists)
+function PrintLists()
+    PrintTable(lists)
 end
-function bsk:PrintChanges()
-    bsk:PrintTable(bsk.db.profile.changes)
+function PrintChanges()
+    PrintTable(db.profile.changes)
 end
-function bsk:PrintPersons()
-    bsk:PrintTable(bsk.persons)
+function PrintPersons()
+    PrintTable(persons)
 end
-function bsk:PrintAPI(object)
+function PrintAPI(object)
     for i,v in pairs(object) do
         if type(v) == "function" then
             bsk:Print("function "..i.."()")
         end
     end
 end
-function bsk:PrintTable(table, depth)
+function PrintTable(table, depth)
     depth = depth or ""
     if not table then return end
-    if #depth > 3*5 then self:Print(depth.."Recursion too deep - stopping"); return end
+    if #depth > 3*5 then bsk:Print(depth.."Recursion too deep - stopping"); return end
     for i,v in pairs(table) do 
         if( type(v) == "string" ) then
-            self:Print(depth .. i ..  " - " .. v) 
+            bsk:Print(depth .. i ..  " - " .. v) 
         elseif( type(v) == "number" ) then
-            self:Print(depth .. i .. " - " .. tostring(v))
+            bsk:Print(depth .. i .. " - " .. tostring(v))
         elseif( type(v) == "table" ) then
-            self:Print(depth .. i .." - ") 
-            self:PrintTable(v,depth.."   ")
+            bsk:Print(depth .. i .." - ") 
+            PrintTable(v,depth.."   ")
         elseif( type(v) == "boolean" ) then
-            self:Print(depth .. i .. " - " .. tostring(v))
+            bsk:Print(depth .. i .. " - " .. tostring(v))
         elseif( type(v) == "function" ) then
-            self:Print(depth .. "function " .. i .. "()")
+            bsk:Print(depth .. "function " .. i .. "()")
         else
-            self:Print(depth .. i .. " - not sure how to print type: " .. type(v) )
+            bsk:Print(depth .. i .. " - not sure how to print type: " .. type(v) )
         end
     end
 end
 
-function bsk:PrintRaidAndReserve()
+function PrintRaidAndReserve()
     bsk:Print("RaidNameP")
-    bsk:PrintTable(bsk.raidNameP)
+    PrintTable(raidNameP)
     bsk:Print("RaidIdP")
-    bsk:PrintTable(bsk.raidIdP)
+    PrintTable(raidIdP)
     bsk:Print("ReserveP")
-    bsk:PrintTable(bsk.reserveIdP)
+    PrintTable(reserveIdP)
     bsk:Print("personName2id")
-    bsk:PrintTable(personName2id)
+    PrintTable(personName2id)
 end
 --}}}
 
-function bsk:UpdatePersonsReverse()
-    for i,v in pairs(bsk.persons) do
+function UpdatePersonsReverse()
+    for i,v in pairs(persons) do
         if i ~= "time" then
             personName2id[v.main] = i
         end
     end
 end
 
--- Change processing {{{
-function bsk:CreateWorkingStateFromChanges(changes)
-    local personsBase = self.db.profile.persons
-    local lists = self.db.profile.lists
+-- Czohange processing {{{
+function CreateWorkingStateFromChanges(changes)
+    local personsBase = db.profile.persons
+    local lists = db.profile.lists
 
     -- copy the base to the working state
-    wipe(bsk.lists)
-    wipe(bsk.persons)
+    wipe(lists)
+    wipe(persons)
     wipe(personName2id)
 
-    bsk:tcopy(bsk.lists,lists)
-    bsk:tcopy(bsk.persons,personsBase)
+    tcopy(lists,lists)
+    tcopy(persons,personsBase)
 
     -- now just go through the changes list applying each
     for i,v in ipairs(changes) do
-        bsk:ProcessChange(v)
+        ProcessChange(v)
     end
 
     -- update the persons reverse list
-    bsk:UpdatePersonsReverse()
+    UpdatePersonsReverse()
 end
 
-function bsk:CreateChange(change)
+function CreateChange(change)
     -- sanity
     assert(change)
     assert(change.action)
     assert(change.arg)
 
-    bsk:StartChange(change)
-    bsk:CommitChange(change)
+    StartChange(change)
+    CommitChange(change)
 end
 
-function bsk:StartChange(change)
-    local changes = self.db.profile.changes
+function StartChange(change)
+    local changes = db.profile.changes
     change.time = time()
     local n = getn(changes)
     if n > 0 then
@@ -218,39 +235,40 @@
     end
 end
 
-function bsk:CommitChange(change)
-    local changes = self.db.profile.changes
+function CommitChange(change)
+    local changes = db.profile.changes
     tinsert(changes,change)
     -- TODO: broadcast change
 end
 
-function bsk:ProcessChange(change)
+function ProcessChange(change)
     if change.action == "AddPerson" then
-        bsk:DoAddPerson(change)
+        DoAddPerson(change)
     elseif change.action == "RenameList" then
-        bsk:DoRenameList(change)
+        DoRenameList(change)
     elseif change.action == "CreateList" then
-        bsk:DoCreateList(change)
+        DoCreateList(change)
     elseif change.action == "DeleteList" then
-        bsk:DoDeleteList(change)
+        DoDeleteList(change)
     elseif change.action == "AddToListEnd" then
-        bsk:DoAddPersonToListEnd(change)
+        DoAddPersonToListEnd(change)
     elseif change.action == "AddToListRand" then
-        bsk:DoAddPersonToListRandom(change)
+        DoAddPersonToListRandom(change)
     elseif change.action == "RemovePerson" then
-        bsk:DoRemovePerson(change)
+        DoRemovePerson(change)
     elseif change.action == "RemovePersonFromList" then
-        bsk:DoRemovePersonFromList(change)
+        DoRemovePersonFromList(change)
     elseif change.action == "SuicidePerson" then
-        bsk:DoSuicidePerson(change)
+        DoSuicidePerson(change)
     else
         bsk:Print("Unknown message encountered")
-        bsk:PrintTable(change)
+        PrintTable(change)
         assert(false)
     end 
 end
 
 --}}}
+--
 -- holy crap long winded {{{
 -- timestamp logic:
 -- use time() for comparisons - local clients use date() to make it pretty. only
@@ -286,12 +304,12 @@
 -- Action Discussion {{{
 -- The actual actions for changes start here
 --
--- Each action occurs as a pair of functions. The bsk:Action() function is from
+-- Each action occurs as a pair of functions. The Action() function is from
 -- a list admin's point of view. Each will check for admin status, then create a
 -- change bundle, call the handler for that change (ie the DoAction func), and
 -- then record/transmist the bundle. These are simple and repetitive functions.
 --
--- The bsk:DoAction() function is tasked with executing the bundle and is what
+-- The DoAction() function is tasked with executing the bundle and is what
 -- non-admins and admins alike will call to transform their working state via a
 -- change packet. Each Do() function will accept *only* a change packet, and
 -- it's assumed that the change has been vetted elsewhere. These are very blunt
@@ -299,11 +317,11 @@
 --
 -- Note that "undo" has no special voodoo to it. It's basically a change that
 -- reverses the prior change on the stack.--}}}
-function bsk:DoAddPerson(change)--{{{
+function DoAddPerson(change)--{{{
     assert(change)
     assert(change.arg.id)
     -- require admin
-    local persons = bsk.persons
+    local persons = persons
     local name = change.arg.name
     local id = change.arg.id
     assert(persons[id]==nil)
@@ -312,52 +330,52 @@
     personName2id[name] = id
     return true
 end--}}}
-function bsk:AddPerson(name)--{{{
-    local persons = bsk.persons
-    local guid = UnitGUID(name)
+function AddPerson(name)--{{{
+    local persons = persons
+    local guid = _G.UnitGUID(name)
     -- TODO: check guid to be sure it's a player
     if not guid then
-        self:Print(sformat("Could not add player %s - they must be in range or group",name))
+        bsk:Print(sformat("Could not add player %s - they must be in range or group",name))
         return
     end
-    local _,englishClass = UnitClass(name)
+    local _,englishClass = _G.UnitClass(name)
     --bsk:Print("Person " .. name .. " is class " .. englishClass)
     local id = string.sub(guid,6) -- skip at least 0x0580 ...
     id = id:gsub("^0*(.*)","%1") -- nom all leading zeroes remaining
     
     if persons[id] and persons[id] ~= name then
-        self:Print(sformat("Namechange detected for %s - new is %s, please rename the existing entry", persons[id].main, name))
+        bsk:Print(sformat("Namechange detected for %s - new is %s, please rename the existing entry", persons[id].main, name))
         return
     end
     if persons[id] ~= nil then
-        self:Print(sformat("%s is already in the persons list; disregarding", name))
+        bsk:Print(sformat("%s is already in the persons list; disregarding", name))
         return
     end
     local change = {action="AddPerson",arg={name=name,id=id,class=englishClass}}
-    if bsk:DoAddPerson(change) then
-        bsk:CreateChange(change)
+    if DoAddPerson(change) then
+        CreateChange(change)
     end
 end--}}}
-function bsk:DoCreateList(change)--{{{
-    --if bsk:GetListIndex(change.arg.name) then
-    --    self:Print(sformat("List %s already exists",v.name))
+function DoCreateList(change)--{{{
+    --if GetListIndex(change.arg.name) then
+    --    bsk:Print(sformat("List %s already exists",v.name))
     --    return false
     --end
-    bsk.lists[change.arg.id]={name=change.arg.name,time=change.time}
+    lists[change.arg.id]={name=change.arg.name,time=change.time}
     return true
 end--}}}
-function bsk:CreateList(name)--{{{
+function CreateList(name)--{{{
     -- require admin
     local change={action="CreateList",arg={name=name}}
-    bsk:StartChange(change)
+    StartChange(change)
     change.arg.id=change.time -- use the creation timestamp as the list's index. it's as unique as anything...
-    self:Print("Creating ... " .. name)
-    if bsk:DoCreateList(change) then
-        bsk:CommitChange(change)
+    bsk:Print("Creating ... " .. name)
+    if DoCreateList(change) then
+        CommitChange(change)
     end
 end--}}}
-function bsk:DoAddPersonToListEnd(change)--{{{
-    local list = bsk.lists[change.arg.listIndex]
+function DoAddPersonToListEnd(change)--{{{
+    local list = lists[change.arg.listIndex]
     local index
     if getn(list) > 0 then
         index = list[#list].index + 0.1
@@ -372,23 +390,23 @@
 
     return true
 end--}}}
-function bsk:AddPersonToListEnd(name,listName)--{{{
+function AddPersonToListEnd(name,listName)--{{{
     -- require admin
-    local listIndex = bsk:GetListIndex(listName)
+    local listIndex = GetListIndex(listName)
     local id = personName2id[name]
-    if bsk:IdIsInList(id,bsk.lists[listIndex]) then
+    if IdIsInList(id,lists[listIndex]) then
         bsk:Print(sformat("Person %s is already on the reqeuested list",name))
         return false
     end
     bsk:Print(sformat("Adding %s (%s) to list %s (%s)", name, id, listName, listIndex))
     local change = {action="AddToListEnd",arg={id=id,listIndex=listIndex}}
-    bsk:StartChange(change)
-    if bsk:DoAddPersonToListEnd(change) then
-        bsk:CommitChange(change)
+    StartChange(change)
+    if DoAddPersonToListEnd(change) then
+        CommitChange(change)
     end
 end--}}}
-function bsk:DoAddPersonToListRandom(change)--{{{
-    local list = bsk.lists[change.arg.listIndex]
+function DoAddPersonToListRandom(change)--{{{
+    local list = lists[change.arg.listIndex]
     local entry = {index=change.arg.roll, id=change.arg.id}
 
     tinsert(list,entry)
@@ -397,34 +415,34 @@
 
     return true
 end--}}}
-function bsk:AddPersonToListRandom(name,listName)--{{{
+function AddPersonToListRandom(name,listName)--{{{
     -- require admin
-    local listIndex = bsk:GetListIndex(listName)
-    if bsk.lists[listIndex].closedRandom then
-        self:Print("Cannot add person to list by random roll because an add-to-end operation has already occurred")
+    local listIndex = GetListIndex(listName)
+    if lists[listIndex].closedRandom then
+        bsk:Print("Cannot add person to list by random roll because an add-to-end operation has already occurred")
         return false
     end
     local id = personName2id[name]
-    if bsk:IdIsInList(id,bsk.lists[listIndex]) then
+    if IdIsInList(id,lists[listIndex]) then
         bsk:Print(sformat("Person %s is already on the reqeuested list",name))
         return false
     end
     local roll = math.random()
     bsk:Print(sformat("Adding %s (%s) to list %s (%s) with roll (%f)", name, id, listName, listIndex, roll))
     local change = {action="AddToListRand",arg={id=id,listIndex=listIndex,roll=roll}}
-    bsk:StartChange(change)
-    if bsk:DoAddPersonToListRandom(change) then
-        bsk:CommitChange(change)
+    StartChange(change)
+    if DoAddPersonToListRandom(change) then
+        CommitChange(change)
     end
 end--}}}
-function bsk:DoRemovePerson(change)--{{{
-    local person = bsk.persons[change.arg.id]
+function DoRemovePerson(change)--{{{
+    local person = persons[change.arg.id]
     personName2id[person.main] = nil
-    bsk.persons[change.arg.id] = nil
-    bsk.persons.time = change.time
+    persons[change.arg.id] = nil
+    persons.time = change.time
     return true
 end--}}}
-function bsk:RemovePerson(name)--{{{
+function RemovePerson(name)--{{{
     local id = personName2id[name]
     if not id then
         bsk:Print(sformat("%s is not in the persons list, please check your spelling", name))
@@ -432,24 +450,24 @@
     end
     local listsTheyreOn = {}
     -- check if they're active on any loot list
-    for i,v in pairs(bsk.lists) do
-        if bsk:IdIsInList(id,v) then
+    for i,v in pairs(lists) do
+        if IdIsInList(id,v) then
             tinsert(listsTheyreOn,v.name)
             break
         end
     end
     if getn(listsTheyreOn) > 0 then
-        self:Print(sformat("Cannot remove person %s because they are on one or more lists (%s)",name,table.concat(listsTheyreOn,", ")))
+        bsk:Print(sformat("Cannot remove person %s because they are on one or more lists (%s)",name,table.concat(listsTheyreOn,", ")))
         return false
     end
     local change = {action="RemovePerson",arg={id=id}}
-    bsk:StartChange(change)
-    if bsk:DoRemovePerson(change) then
-        bsk:CommitChange(change)
+    StartChange(change)
+    if DoRemovePerson(change) then
+        CommitChange(change)
     end
 end--}}}
-function bsk:DoSuicidePerson(change)--{{{
-    local list = bsk.lists[change.arg.listIndex]
+function DoSuicidePerson(change)--{{{
+    local list = lists[change.arg.listIndex]
     local affected = shallowCopy(change.arg.affect)
     -- the goal here is to rotate the suicide list by 1
     -- then we can just mash it on top of the intersection between the original
@@ -459,7 +477,7 @@
     local temp = table.remove(replacement,1) -- pop
     tinsert(replacement,temp) -- push_back
     --bsk:Print(sformat("Before suicide of %s on list %s",slist[1],list.name))
-    --bsk:PrintTable(list)
+    --PrintTable(list)
     for i = 1, #list do
         if list[i].id == affected[1] then
             table.remove(affected,1)
@@ -470,46 +488,46 @@
     list.time=change.time
     return true
 end--}}}
-function bsk:SuicidePerson(name,listName)--{{{
+function SuicidePerson(name,listName)--{{{
     -- require admin
-    bsk:PopulateRaidList()
-    local listIndex = bsk:GetListIndex(listName)
+    PopulateRaidList()
+    local listIndex = GetListIndex(listName)
     local id = personName2id[name]
-    local affect=bsk:GetSuicideList(id,bsk.lists[listIndex])
+    local affect=GetSuicideList(id,lists[listIndex])
     local change = {action="SuicidePerson",arg={affect=affect,listIndex=listIndex}}
-    bsk:StartChange(change)
-    if bsk:DoSuicidePerson(change) then
-       bsk:CommitChange(change)
+    StartChange(change)
+    if DoSuicidePerson(change) then
+       CommitChange(change)
     end
 end--}}}
-function bsk:DoRenameList(change)--{{{
-    bsk.lists[change.arg.listIndex].name = change.arg.name
-    bsk.lists[change.arg.listIndex].time = change.time
+function DoRenameList(change)--{{{
+    lists[change.arg.listIndex].name = change.arg.name
+    lists[change.arg.listIndex].time = change.time
     return true
 end--}}}
-function bsk:RenameList(listName,newListName)--{{{
+function RenameList(listName,newListName)--{{{
     -- require admin
-    local listIndex = bsk:GetListIndex(listName)
+    local listIndex = GetListIndex(listName)
     local change = {action="RenameList",arg={listIndex=listIndex,name=newListName}}
-    bsk:StartChange(change)
-    if bsk:DoRenameList(change) then
-       bsk:CommitChange(change)
+    StartChange(change)
+    if DoRenameList(change) then
+       CommitChange(change)
     end
 end--}}}
-function bsk:DoDeleteList(change)--{{{
-    bsk.lists[change.arg.listIndex] = nil
+function DoDeleteList(change)--{{{
+    lists[change.arg.listIndex] = nil
     return true
 end--}}}
-function bsk:DeleteList(listName)--{{{
-    local listIndex = bsk:GetListIndex(listName)
+function DeleteList(listName)--{{{
+    local listIndex = GetListIndex(listName)
     local change = {action="DeleteList",arg={listIndex=listIndex}}
-    bsk:StartChange(change)
-    if bsk:DoDeleteList(change) then
-       bsk:CommitChange(change)
+    StartChange(change)
+    if DoDeleteList(change) then
+       CommitChange(change)
     end
 end--}}}
-function bsk:DoRemovePersonFromList(change)--{{{
-    local list = bsk.lists[change.arg.listIndex]
+function DoRemovePersonFromList(change)--{{{
+    local list = lists[change.arg.listIndex]
 
     for i,v in ipairs(list) do
         if v.id == change.arg.id then
@@ -521,23 +539,23 @@
     list.time = change.time
     return true
 end--}}}
-function bsk:RemovePersonFromList(name,listName)--{{{
-    local listIndex = bsk:GetListIndex(listName)
+function RemovePersonFromList(name,listName)--{{{
+    local listIndex = GetListIndex(listName)
     local pid = personName2id[name]
     -- todo: check that they're on the list in the first place
     local change = {action="RemovePersonFromList",arg={id=pid,listIndex=listIndex}}
-    bsk:StartChange(change)
-    if bsk:DoRemovePersonFromList(change) then
-       bsk:CommitChange(change)
+    StartChange(change)
+    if DoRemovePersonFromList(change) then
+       CommitChange(change)
     end
 end
 --}}}
 --}}}
 -- Higher order actions (ie calls other standard actions){{{
 
-function bsk:TrimLists(time)
-    if not bsk:CheckListCausality() then
-        self:Print("Unable to trim changelist due to violated causality")
+function TrimLists(time)
+    if not CheckListCausality() then
+        bsk:Print("Unable to trim changelist due to violated causality")
         return false
     end
 
@@ -547,7 +565,7 @@
 
     -- bisect the changes list by "time"
     local before = {}
-    for i,v in ipairs(self.db.profile.changes) do
+    for i,v in ipairs(db.profile.changes) do
         if v.time <= time then
             tinsert(before,v)
         else
@@ -556,44 +574,44 @@
     end
 
     -- apply first half
-    bsk:CreateWorkingStateFromChanges(before)
+    CreateWorkingStateFromChanges(before)
 
     -- save this state permanently; trim the changes permanently
-    bsk:tcopy(bsk.db.profile.persons,bsk.persons)
-    bsk:tcopy(bsk.db.profile.lists,bsk.lists)
-    while bsk.db.profile.changes ~= nil and bsk.db.profile.changes[1] ~= nil and bsk.db.profile.changes[1].time <= time do
-        table.remove(bsk.db.profile.changes,1)
+    tcopy(db.profile.persons,persons)
+    tcopy(db.profile.lists,lists)
+    while db.profile.changes ~= nil and db.profile.changes[1] ~= nil and db.profile.changes[1].time <= time do
+        table.remove(db.profile.changes,1)
     end
 
     -- using the trimmed list and the new bases, recreate the working state
-    bsk:CreateWorkingStateFromChanges(bsk.db.profile.changes)
+    CreateWorkingStateFromChanges(db.profile.changes)
 end
 
-function bsk:AddMissingPersons()
-    bsk:PopulateRaidList() 
+function AddMissingPersons()
+    PopulateRaidList() 
     local t = {}
-    for id,_ in pairs(bsk.persons) do
+    for id,_ in pairs(persons) do
         t[id] = true
     end
-    for name,_ in pairs(bsk.raidNameP) do
+    for name,_ in pairs(raidNameP) do
         if personName2id[name] == nil then
             bsk:Print(sformat("Person %s is missing from the persons list - adding",name))
-            bsk:AddPerson(name)
+            AddPerson(name)
         end
     end
     -- TODO: batch into a single op - no need to spam 25 messages in a row
 end
 
-function bsk:PopulateListRandom(listIndex)
+function PopulateListRandom(listIndex)
     -- difference (raid+reserve)-list, then random shuffle that, then add
-    bsk:PopulateRaidList()
-    local list = bsk.lists[listIndex]
+    PopulateRaidList()
+    local list = lists[listIndex]
 
     local t = {} -- after loops, contains intersection of IDs present between raid and reserve
-    for i,v in pairs(bsk.raidIdP) do
+    for i,v in pairs(raidIdP) do
         if v then t[i] = true end 
     end
-    for i,v in pairs(bsk.reserveIdP) do
+    for i,v in pairs(reserveIdP) do
         if v then t[i] = true end 
     end
 
@@ -609,35 +627,36 @@
     -- add all remaining
     for i,v in pairs(t) do
         if v then
-            bsk:AddPersonToListRandom(bsk.persons[i].main,list.name) -- TODO: APTLR keys off of string names. probably need to change this.
+            AddPersonToListRandom(persons[i].main,list.name) -- TODO: APTLR keys off of string names. probably need to change this.
         end
     end
 end
 
-function bsk:NukePerson(name) -- delete from all lists and then from persons
+function NukePerson(name) -- delete from all lists and then from persons
     local pid = personName2id[name]
-    for i,v in pairs(bsk.lists) do
-        bsk:RemovePersonFromList(name,v.name)
+    for i,v in pairs(lists) do
+        RemovePersonFromList(name,v.name)
     end
-    bsk:RemovePerson(name)
+    RemovePerson(name)
 end
 --}}}
 -- "Soft" actions- ie things that cause nonpermanent state {{{
 
 -- reserves
-function bsk:AddReserve(name)
-    bsk.reserveIdP[personName2id[name]]=true
+function AddReserve(name)
+    bsk:Print("Reserving" .. name)
+    reserveIdP[personName2id[name]]=true
     -- TODO: communicate to others. don't store this in any way.
 end
 
-function bsk:RemoveReserve(name)
-    bsk.reserveIdP[personName2id[name]]=false
+function RemoveReserve(name)
+    reserveIdP[personName2id[name]]=false
     -- TODO: communicate to others. don't store this in any way.
 end
 
 
---function bsk:GetActiveList()
---    return bsk.lists[1] -- todo!
+--function GetActiveList()
+--    return lists[1] -- todo!
 --end
 
 --}}}
@@ -647,24 +666,24 @@
 local pID = {}
 local rID = {}
 for i = 1, 4 do
-    pID[i] = format("party%d", i)
+    pID[i] = sformat("party%d", i)
 end
 for i = 1, 40 do
-    rID[i] = format("raid%d", i)
+    rID[i] = sformat("raid%d", i)
 end
-function bsk:PopulateRaidList()
-    local inParty = GetNumPartyMembers()
-    local inRaid = GetNumRaidMembers()
+function PopulateRaidList()
+    local inParty = _G.GetNumPartyMembers()
+    local inRaid = _G.GetNumRaidMembers()
     local add = function(unitNameArg) 
-        local name = UnitName(unitNameArg)
-        bsk.raidNameP[name]=true
+        local name = _G.UnitName(unitNameArg)
+        raidNameP[name]=true
         if personName2id[name] ~= nil then
-            bsk.raidIdP[personName2id[name]]=true 
+            raidIdP[personName2id[name]]=true 
         end
     end
 
-    wipe(bsk.raidNameP)
-    wipe(bsk.raidIdP)
+    wipe(raidNameP)
+    wipe(raidIdP)
     if inRaid > 0 then
         for i = 1, inRaid do
             add(rID[i])
@@ -679,7 +698,7 @@
         -- You're alone
         add("player")
     end
-    --bsk:PrintTable(bsk.raidNameP)
+    --PrintTable(raidNameP)
 end
 
 -- undo rules!
@@ -691,9 +710,9 @@
 -- prevent proper undo, such as add/delete player or add/delete list
 
 
-function bsk:GetSuicideList(id,list)
-    --self:Print("Calculating changeset for "..name.." from list -")
-    --self:PrintTable(list)
+function GetSuicideList(id,list)
+    --bsk:Print("Calculating changeset for "..name.." from list -")
+    --PrintTable(list)
     local t = {}
     local ret = {}
     local pushing = false
@@ -701,17 +720,17 @@
         if list[i].id == id then
             pushing = true
         end
-        if pushing and (bsk.raidIdP[list[i].id] or bsk.reserveIdP[list[i].id]) then
+        if pushing and (raidIdP[list[i].id] or reserveIdP[list[i].id]) then
             tinsert(ret,list[i].id)
         end
     end
     --bsk:Print("GSL")
-    --bsk:PrintTable(ret)
+    --PrintTable(ret)
     --bsk:Print("GSL")
     return ret
 end
 
-function bsk:IdIsInList(id,listRef)
+function IdIsInList(id,listRef)
     for i = 1,#listRef do
         if id == listRef[i].id then
             return true
@@ -721,9 +740,9 @@
 end
 
 -- returns true if the events in the list are in time order
-function bsk:CheckListCausality()
+function CheckListCausality()
     local t = nil
-    for i,v in ipairs(bsk.db.profile.changes) do
+    for i,v in ipairs(db.profile.changes) do
         if t ~= nil then
             if v.time <= t then
                 return false
@@ -736,8 +755,8 @@
 
 -- Support functions
 
-function bsk:GetListIndex(name)
-    for i,v in pairs(bsk.lists) do
+function GetListIndex(name)
+    for i,v in pairs(lists) do
         if v.name == name then
             return i
         end
@@ -745,12 +764,4 @@
     return nil
 end
 
-local shuffleArray = function(array)
-    local arrayCount = #array
-    for i = arrayCount, 2, -1 do
-        local j = math.random(1, i)
-        array[i], array[j] = array[j], array[i]
-    end
-    return array
-end