pgs_prey_genome.lsl
///////////////////////////////////////////////////////////////////////////
//  Copyright (C) Wizardry and Steamworks 2011 - License: GNU GPLv3      //
//  Please see: http://www.gnu.org/licenses/gpl.html for legal details,  //
//  rights of fair usage, the disclaimer and warranty conditions.        //
///////////////////////////////////////////////////////////////////////////
 
// Reference land types
list _landReference = [ "Green", 1, "Black", 2, "Brown", 3 ];
// Reference genomes
list _genotypeReference = [ "BB", 1, "Bb", 2, "bB", 3, "bb", 4 ];
 
string _genome = "";
string _landType = "";
integer _mouseID = 1;
 
// Owner key.
key _owner = NULL_KEY;
 
setparams(integer param) {
    list opt = llParseString2List(llGetSubString((string)param, 0, 4), [], [ "1", "2", "3", "4", "5", "6" ]);
    integer itra=llGetListLength(opt)-1;
    do {
        if(llList2Integer(opt, itra) == 5) {
            _genome = llList2String(_genotypeReference, llListFindList(_genotypeReference, (list)llList2Integer(opt, itra+1))-1);
            jump next_param;
        }
        if(llList2Integer(opt, itra) == 6) {
            _landType = llList2String(_landReference, llListFindList(_landReference, (list)llList2Integer(opt, itra+1))-1);
            jump next_param;
        }
@next_param;
    } while(--itra>=0);
 
    list id = llParseString2List(llGetSubString((string)param, 5, -1), [], ["1", "2", "3", "4", "5", "6", "7", "8", "9" ]);
    _mouseID = (integer)llDumpList2String(id, "");
}
 
default
{
    state_entry()
    {
        integer comChannel = ((integer)("0x"+llGetSubString((string)llGetOwner(),-8,-1)) & 0x3FFFFFFF) ^ 0xBFFFFFFF;
        llListen(comChannel+3, "[BIOSE-SX]-[WaS-K] Population Genetics and Selection", "", "");
    }
 
    listen(integer channel, string name, key id, string message)
    {
        list opt = llParseString2List(message, [",", ":"], []);
        integer itra=llGetListLength(opt)-1;
        do {
            if(llList2String(opt, itra) == "SHOW_GENOTYPES") {
                llSetTimerEvent(0);
                llSetText(_genome, <1,1,1>, 1.0);
                jump next_msg;
            }
            if(llList2String(opt, itra) == "HIDE_GENOTYPES") {
                llSetTimerEvent(1);
                jump next_msg;
            }
@next_msg;
        } while(--itra>=0);
    }
 
    timer() {
        llSetTimerEvent(0);
        float itra=1.0;
        do {
            llSetText(_genome, <1,1,1>, itra);
        } while(itra-=0.1>0.0);
        llSetText(_genome, <0,0,0>, 0.0);
    }
    changed(integer change) {
        if(change & CHANGED_OWNER) llResetScript();
    }
    on_rez(integer num) {
        setparams(num);
    }
}