
MusicChoices = {

    drama = 0,
    last = "",

    compareByDrama = function (a, b)
        --   SurvivorSelector.contextwith = with;
        -- SurvivorSelector.contextagainst = against;
        local totala = math.abs(MusicChoices.drama - a.scores.drama) - a.scores.bias;
        local totalb = math.abs(MusicChoices.drama - b.scores.drama) - b.scores.bias;
        if MusicChoices.last == a.file then
            totala = 100000;
        end
        if MusicChoices.last == b.file then
            totalb = 100000;
        end

        if(totala < totalb) then
            return true
        else
            return false
        end
    end,

    compareByAmbientDrama = function (a, b)
    --   SurvivorSelector.contextwith = with;
    -- SurvivorSelector.contextagainst = against;
        local totala = math.abs(MusicChoices.drama - a.scores.drama);
        local totalb = math.abs(MusicChoices.drama - b.scores.drama);
        if MusicChoices.last == a.file then
            totala = 100000;
        end
        if MusicChoices.last == b.file then
            totalb = 100000;
        end

        if(totala < totalb) then
            return true
        else
            return false
        end
    end,

    get = function(drama)

        local musictable = MusicChoices.choices;
        if getSoundManager():isRemastered() then
            musictable = MusicChoices.remasteredchoices;
        end

        MusicChoices.drama = drama;
       table.sort(musictable, MusicChoices.compareByDrama);
       local c = 0;
       for i, k in ipairs(musictable) do
          c = c + 1;
       end
       c = c * 0.2;
       local i = ZombRand(c)+1;


        MusicChoices.last =  musictable[i].file;
        return musictable[i].file;
    end,

    getAmbient = function(drama)
        MusicChoices.drama = drama;
        table.sort(MusicChoices.ambient, MusicChoices.compareByAmbientDrama);
        local c = 0;
        local ambients = {};
        for i, k in ipairs(MusicChoices.ambient) do
            local found = false;
            for x=0,getSoundManager():getAmbientPieces():size() -1 do
                if getSoundManager():getAmbientPieces():get(x):getName() == k.file then
                    found = true;
                    break;
                end
            end
            if not found then
                table.insert(ambients, k);
                c = c + 1;
            end
        end
        c = c * 0.2;
        local i = ZombRand(c)+1;


        MusicChoices.last =  ambients[i].file;
        return ambients[i].file;
    end,

    choices = {

        {
            file="alone",
            scores = {
                drama = 3,
                bias = 5,
            }
        },


        {
            file="long_ambient",
            scores = {
                drama = 2,
                bias = 4,
            }
        },

        {
            file="barricading",
            scores = {
                drama = 2,
                bias = 5,
            }
        },
        {
            file="ambient1",
            scores = {
                drama = 2,
                bias = 3,
            }
        },
        {
            file="ambient2",
            scores = {
                drama = 2,
                bias = 3,
            }
        },
        {
            file="long_ambient",
            scores = {
                drama = 2,
                bias = 5,
            }
        },
        {
            file="the_inevitable",
            scores = {
                drama = 4,
                bias = 5,
            }
        },
        {
            file="what_was_lost",
            scores = {
                drama = 2,
                bias = 5,
            }
        },
        {
            file="wwl_tense",
            scores = {
                drama = 6,
                bias = 5,
            }
        },
        {
            file="wwl_active",
            scores = {
                drama = 6,
                bias = 5,
            }
        },
        {
            file="guitar",
            scores = {
                drama = 4,
                bias = 5,
            }
        },
        {
            file="the_zombie_threat",
            scores = {
                drama = 5,
                bias = 5,
            }
        },
        {
            file="PZ",
            scores = {
                drama = 5,
                bias = 5,
            }
        },
        {
            file="piano",
            scores = {
                drama = 3,
                bias = 5,
            }
        },
        {
            file="low",
            scores = {
                drama = 4,
                bias = 5,
            }
        },
        {
            file="fight_or_flight",
            scores = {
                drama = 9,
                bias = 5,
            }
        },

        {
            file="chase",
            scores = {
                  drama = 10,
                  bias = 5,
                }
            },
        {
            file="desperate_escape",
            scores = {
                drama = 9,
                bias = 5,
            }
        },
		{
            file="the_horde",
            scores = {
                drama = 9,
                bias = 5,
            }
        },

        {
            file="maybe_we_can_win_this",
            scores = {
                drama = 7,
                bias = 4,
            }
        },
        {
            file="maybe_not",
            scores = {
                drama = 6,
                bias = 5,
            }
        },
        {
            file="raider",
            scores = {
                drama = 4,
                bias = 5,
            }
        },
        {
            file="run",
            scores = {
                drama = 9,
                bias = 5,
            }
        },
        {
            file="saying_goodbye",
            scores = {
                drama = 3,
                bias = 5,
            }
        },
        {
            file="where_is_everyone",
            scores = {
                drama = 2,
                bias = 5,
            }
        },
        {
            file="they_were_once_here",
            scores = {
                drama = 2,
                bias = 5,
            }
        },
        {
            file="work_fast",
            scores = {
                drama = 5,
                bias = 5,
            }
        },
    },

    ambient = {

        {
            file="RhythmicAmbient",
            scores = {
                drama = 4,
            }
        },
        {
            file="VoiceAmbient",
            scores = {
                drama = 5,
            }
        },
        {
            file="PercussiveAmbient",
            scores = {
                drama = 6,
            }
        },
        {
            file="IntenseAmbient",
            scores = {
                drama = 7,
            }
        },
        {
            file="ZombieAmbient",
            scores = {
                drama = 8,
            }
        },
        {
            file="BrassAmbient",
            scores = {
                drama = 9,
            }
        },
        {
            file="CreepyAmbient",
            scores = {
                drama = 10,
            }
        },
    },

    remasteredchoices = {

    {
        file="Alone",
        scores = {
            drama = 3,
            bias = 5,
        }

    },
    {
        file="Barricading",
        scores = {
            drama = 2,
            bias = 5,
        }
    },
    {
        file="Ambient",
        scores = {
            drama = 2,
            bias = 3,
        }
    },
    {
        file="The Inevitable",
        scores = {
            drama = 4,
            bias = 5,
        }
    },
    {
        file="What Was Lost",
        scores = {
            drama = 2,
            bias = 5,
        }
    },
    {
        file="What Was Lost Active",
        scores = {
            drama = 6,
            bias = 5,
        }
    },
    {
        file="What Was Lost Active 2",
        scores = {
            drama = 6,
            bias = 5,
        }
    },
    {
        file="Ambient Guitar",
        scores = {
            drama = 4,
            bias = 5,
        }
    },
    {
        file="The Zombie Threat",
        scores = {
            drama = 5,
            bias = 5,
        }
    },

    {
        file="Ambient Piano",
        scores = {
            drama = 3,
            bias = 5,
        }
    },
    {
        file="Ambient Low",
        scores = {
            drama = 4,
            bias = 5,
        }
    },
    {
        file="Fight or Flight",
        scores = {
            drama = 9,
            bias = 5,
        }
    },

    {
        file="Chase",
        scores = {
            drama = 10,
            bias = 5,
        }
    },
    {
        file="Desperate Escape",
        scores = {
            drama = 9,
            bias = 5,
        }
    },
    {
        file="The Horde",
        scores = {
            drama = 9,
            bias = 5,
        }
    },

    {
        file="Maybe We Can Win This",
        scores = {
            drama = 7,
            bias = 4,
        }
    },
    {
        file="Maybe Not",
        scores = {
            drama = 6,
            bias = 5,
        }
    },
    {
        file="Ambient Raider",
        scores = {
            drama = 4,
            bias = 5,
        }
    },
    {
        file="Run",
        scores = {
            drama = 9,
            bias = 5,
        }
    },
    {
        file="Saying Goodbye",
        scores = {
            drama = 3,
            bias = 5,
        }
    },
    {
        file="Where is Everyone",
        scores = {
            drama = 2,
            bias = 5,
        }
    },
    {
        file="They Were Once Here",
        scores = {
            drama = 2,
            bias = 5,
        }
    },
    {
        file="Work Fast",
        scores = {
            drama = 5,
            bias = 5,
        }
    },
    {
        file="Slow Sad",
        scores = {
            drama = 2,
            bias = 4,
        }
    },
    }

}
