viewing paste topic/4321- comb_sort_itemlist | Athena

Posted on the | Last edited on
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
prontera,152,188,5  script  test getitemname2   100,{
    getinventorylist;
    dispbottom "No sort === Total items : "+ @inventorylist_count +" ===";
    .@i = 0;
    while ( .@i < @inventorylist_count ) {
        .@itemname$ = callfunc("getitemname2", @inventorylist_id[.@i], @inventorylist_identify[.@i], @inventorylist_refine[.@i], @inventorylist_attribute[.@i], @inventorylist_card1[.@i], @inventorylist_card2[.@i], @inventorylist_card3[.@i], @inventorylist_card4[.@i]);
        dispbottom "("+ @inventorylist_id[.@i] +") "+ .@itemname$ +": "+ @inventorylist_amount[.@i] +" ea." + @inventorylist_identify[.@i] +" "+ @inventorylist_attribute[.@i];
        .@i++;
    }
    end;
}
 
prontera,155,188,5  script  getitemname2 ID sorted  100,{
    freeloop 1;
    getinventorylist;
    dispbottom "Comb sort === Total items : "+ @inventorylist_count +" ===";
    callfunc "comb_sort", @inventorylist_id, .@output, @inventorylist_count;
    .@i = 0;
    while ( .@i < @inventorylist_count ) {
//      dispbottom @inventorylist_id[ .@output[.@i] ] +"";
        .@itemname$ = callfunc("getitemname2", @inventorylist_id[ .@output[.@i] ], @inventorylist_identify[ .@output[.@i] ], @inventorylist_refine[ .@output[.@i] ], @inventorylist_attribute[ .@output[.@i] ], @inventorylist_card1[ .@output[.@i] ], @inventorylist_card2[ .@output[.@i] ], @inventorylist_card3[ .@output[.@i] ], @inventorylist_card4[ .@output[.@i] ]);
        dispbottom "("+ @inventorylist_id[ .@output[.@i] ] +") "+ .@itemname$ +": "+ @inventorylist_amount[ .@output[.@i] ] +" ea.";
        .@i++;
    }
    end;
}
 
//  callfunc "comb_sort", <input array>, <output index>, <total index>;
function    script  comb_sort   {
    while ( .@i < getarg(2) ) {
        set .@arr[.@i], getelementofarray( getarg(0), .@i );
        set getelementofarray( getarg(1), .@i ), .@i; // note : I'm generating a dummy index here, so this one will be output as the sorted index later
        .@i++;
    }
    .@size = .@gap = getarg(2);
    do {
        if ( .@gap > 1 )
            .@gap = .@gap * 10 / 13;
        .@i = .@swap = 0;
        while ( .@i + .@gap < .@size ) {
            if ( .@arr[.@i] > .@arr[ .@i + .@gap ] ) {
                .@tmp = .@arr[.@i];
                .@arr[.@i] = .@arr[ .@i + .@gap ];
                .@arr[ .@i + .@gap ] = .@tmp;
                .@tmp = getelementofarray( getarg(1), .@i ); // dummy index is being swap here
                set getelementofarray( getarg(1), .@i ), getelementofarray( getarg(1), .@i + .@gap );
                set getelementofarray( getarg(1), .@i + .@gap ), .@tmp;
                .@swap = 1;
            }
            .@i++;
        }
    } while ( .@swap || .@gap > 1 );
    return;
}
Viewed 1356 times, submitted by AnnieRuru.