Tintin++ Corpse Sorter

Corpse Sorting…will arrange all your corpses in your inventory, smuggled or carried by your undead into size order. Currently this will sort all of the smallest corpses into your inventory and transfer the largest corpses to your undead or smuggled inventory (reverse sorting coming in a future update).

This code should be saved in a file called "CorpseSort.tin"
Then set up a tt++ alias (or type in) "#READ CorpseSort.tin"…it will read in the code, do the sorting and then remove itself again.

N.B. Needs the mudside aliases specified in the comments at the top of the program for it to work.

#CLASS {cCorpseSort} {kill};
#CLASS {cCorpseSort} {open};

#NOP Corpse Sorter Version 3.2
#NOP By Balthus.

#NOP *** Corpses are dropped on the ground to swap/sort them. ***
#NOP *** Therefore be careful where you choose to do a sort.  ***

#NOP ALIASES NEEDED FOR THIS TO WORK:
#NOP
#NOP alias cs_me_get get preservation $1
#NOP alias cs_me_drop drop preservation $1
#NOP alias cs_minion_get =get preservation $1
#NOP alias cs_minion_drop =drop preservation $1
#NOP alias cs_smuggle_get qtrance get preservation $1/smuggle preservation
#NOP alias cs_smuggle_drop qtrance smuggle remove preservation $1/drop preservation

#VAR {corpses[listname]} {me};
#VAR {corpses[me][list]} {};
#VAR {corpses[minion][list]} {};
#VAR {corpses[smuggle][list]} {};

#ACTION {Listing the corpses carried by your undead follower master...}
{
    #VAR {corpses[listname]} {minion};
};

#ACTION {Items you currently smuggling}
{
    #VAR {corpses[listname]} {smuggle};
};

#ACTION {You speak: Corpse List Finished}
{
    .aProcessCorpse;
};

#ACTION {^%.%.%?\(%*\) %*$}
{
    #VAR {lvCorpseLoop} 0;
    #VAR {lvCorpseSize} {};
    #PARSE {%4} {i}
    {
        #IF {"$lvCorpseSize" == "$gvNull"}
        {
            #MATH {lvCorpseLoop} {$lvCorpseLoop + 1};
            #IF {"$i" == "|"} {#VAR {lvCorpseSize} {$lvCorpseLoop};};
            #IF {"$i" == "\*"} {#MATH {lvCorpseSize} {11 - $lvCorpseLoop};};
        };
    };
    #LIST {corpses[$corpses[listname]][list]} {ins} {-1} {$lvCorpseSize};
    #UNVAR {lvCorpseLoop};
    #UNVAR {lvCorpseSize};
};

#ALIAS {.aProcessCorpse}
{
    #WHILE {@fSwapCorpse{{me}{smuggle}} > 0} {#NOP;};
    #WHILE {@fSwapCorpse{{me}{minion}} > 0} {#NOP;};
    #WHILE {@fSwapCorpse{{minion}{smuggle}} > 0} {#NOP;};
    .aSortCorpse {me};
    .aSortCorpse {minion};
    .aSortCorpse {smuggle};
    #CLASS {cCorpseSort} {kill};
};

#ALIAS {.aSortCorpse}
{
    #VAR {corpses[%1][sortpos]} {0};
    #VAR {corpses[%1][max][size]} {0};
    #VAR {corpses[%1][count]} {0};
    #FOREACH {$corpses[%1][list][]} {i}
    {
        #IF {$corpses[%1][list][$i] > $corpses[%1][max][size]}
        {
            #VAR {corpses[%1][max][size]} {$corpses[%1][list][$i]};
        };
        #IF {$corpses[%1][list][$i] < $corpses[%1][max][size]}
        {
            #VAR {corpses[%1][sortpos]} {$i};
        };
        #MATH {corpses[%1][count]} {$corpses[%1][count] + 1};
    };
    #MATH {corpses[%1][max][size]} {$corpses[%1][max][size] - 1};    
    #LOOP {$corpses[%1][max][size]} {1} {i}
    {
        #FOREACH {$corpses[%1][list]} {j}
        {
            #IF {$j <= $corpses[%1][sortpos]}
            {
                #IF {$corpses[%1][list][$j] == $i && $j > 1}
                {
                    #SEND {!cs_%1_drop $j};
                    #SEND {!cs_%1_get};
                    #LIST {corpses[%1][list]} {del} {$j};
                    #LIST {corpses[%1][list]} {ins} {1} {&i};
                };
            };
        };    
    };
};

#FUNCTION {fSwapCorpse}
{
    #IF {$corpses[%1][list][1] == 0}
    {
        #RETURN 0;
    };
    #IF {$corpses[%2][list][1] == 0}
    {
        #RETURN 0;
    };    
    #VAR {corpses[%1][max][pos]} {0};
    #VAR {corpses[%1][max][size]} {0};
    #FOREACH {$corpses[%1][list][]} {i}
    {
        #IF {$corpses[%1][list][$i] > $corpses[%1][max][size]}
        {
            #VAR {corpses[%1][max][size]} {$corpses[%1][list][$i]};
            #VAR {corpses[%1][max][pos]} {$i};
        };
    };
    #VAR {corpses[%2][min][pos]} {999};
    #VAR {corpses[%2][min][size]} {999};
    #FOREACH {$corpses[%2][list][]} {i}
    {
        #IF {$corpses[%2][list][$i] < $corpses[%2][min][size]}
        {
            #VAR {corpses[%2][min][size]} {$corpses[%2][list][$i]};
            #VAR {corpses[%2][min][pos]} {$i};
        };
    };
    #IF {$corpses[%1][max][size] > $corpses[%2][min][size]}
    {
        #SEND {!cs_%2_drop $corpses[%2][min][pos]};
        #SEND {!cs_%1_drop $corpses[%1][max][pos]};
        #SEND {!cs_%1_get 2};
        #SEND {!cs_%2_get};
        #LIST {corpses[%1][list]} {del} {$corpses[%1][max][pos]};
        #LIST {corpses[%1][list]} {ins} {1} {$corpses[%2][min][size]};
        #LIST {corpses[%2][list]} {del} {$corpses[%2][min][pos]};
        #LIST {corpses[%2][list]} {ins} {1} {$corpses[%1][max][size]};
        #RETURN 1;
    }
    {
        #RETURN 0;
    };
};

#SEND {!ic};
#SEND {!iu c};
#SEND {!smuggle};
#SEND {!nsay Corpse List Finished};
#CLASS {cCorpseSort} {close};
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License