Help with sorting map

ereinion

Member
I have created a short script to print the values of all the drops I can get from my familiars:

PHP:
int get_price(item item_to_check, float acceptable_age) {
    return ((historical_age(item_to_check) <= acceptable_age)? historical_price(item_to_check) : mall_price(item_to_check));
}

void print_drop_values() {
    familiar f;
    int[familiar] drop_value;
    
    foreach f in $familiars[] {
        //print(f.name);
        if (have_familiar(f)) {
            if (f.drops_limit > 0) {
                drop_value[f] = get_price(f.drop_item, 1);
            }
        }
    }
    
    sort drop_value by value;
    foreach f in drop_value {
        print(f + " - " + f.drop_item + " - " + drop_value[f]);
    }
}
void main() {
    print_drop_values();
}
Hoewever, I have some issues with understanding the output I get:
Code:
[COLOR=olive]> test.ash[/COLOR]

Astral Badger - astral      mushroom - 0
Green Pixie - tiny bottle of absinthe - 0
Llama Lama -      llama lama gong - 0
Cotton Candy Carnie - none - 0
Baby Sandworm -      agua de vida - 105
Rogue Program - Game Grid token - 115
Li'l      Xenomorph - transporter transponder - 825
Pair of Stomping Boots - none      - 900
Bloovian Groose - groose grease - 1475
Blavious Kloop -      devilish folio - 1500
Angry Jung Man - psychoanalytic jar - 1500
Unconscious      Collective - Unconscious Collective Dream Jar - 2900
Grimstone Golem -      grimstone mask - 7250
Grim Brother - grim fairy tale - 7300
Miniature      Sword & Martini Guy - mini-martini - 9500
Galloping Grill - hot      ashes - 9539
Fist Turkey - none - 9800
Golden Monkey - powdered gold      - 9800
Adventurous Spelunker - Tales of Spelunking - 9850
Puck Man -      power pill - 9950
Ms. Puck Man - power pill - 15000
Machine Elf -      Deep Machine Tunnels snowglobe - 15000

How come some of the values are 0? Furthermore, values for e.g. the dream jar seems too low compared to what I get when I search for it in the mall (current price is 9200 meat).

Finally, I wanted the drops to be sorted descending instead of ascending, so I tried to change line 18 of the script to
Code:
sort drop_value by -value;
After doing this, the output from the script changes to

Code:
[COLOR=olive]> test.ash[/COLOR]

Astral Badger - astral      mushroom - 15000
Green Pixie - tiny bottle of absinthe - 15000
Llama      Lama - llama lama gong - 9950
Cotton Candy Carnie - none - 9850
Baby      Sandworm - agua de vida - 9800
Rogue Program - Game Grid token - 9800
Li'l      Xenomorph - transporter transponder - 9539
Pair of Stomping Boots -      none - 9500
Bloovian Groose - groose grease - 7300
Blavious Kloop -      devilish folio - 7250
Angry Jung Man - psychoanalytic jar - 2900
Unconscious      Collective - Unconscious Collective Dream Jar - 1500
Grimstone Golem -      grimstone mask - 1500
Grim Brother - grim fairy tale - 1475
Miniature      Sword & Martini Guy - mini-martini - 900
Galloping Grill - hot      ashes - 825
Fist Turkey - none - 115
Golden Monkey - powdered gold -      105
Adventurous Spelunker - Tales of Spelunking - 0
Puck Man - power      pill - 0
Ms. Puck Man - power pill - 0
Machine Elf - Deep Machine      Tunnels snowglobe - 0

The order of the familiars is still the same, but the values stored for each of them has changed. Can someone please give me a pointer on where I am going wrong with this?
 

lostcalpolydude

Developer
Staff member
For your second point, this page has some info about what you need to do to use sort properly.

For your first point, some of the items being printed are "none", so those will give a price of 0. Using sort to unlink prices from familiars is the source of your confusion about identifying that issue.
 

ereinion

Member
Ah, so if I am reading that correctly, I can't sort my map while keeping the values linked to the keys?

What I'll have to do is e.g. changing my map to an array holding the familiars drops, and then do something like

Code:
sort drop_values by get_price(value);

-edit-
Here we go.
Code:
int get_price(item item_to_check, float acceptable_age) {
    return ((historical_age(item_to_check) <= acceptable_age)? historical_price(item_to_check) : mall_price(item_to_check));
}

void print_drop_values() {
    familiar f;
    familiar[50] item_drop;
    int i;
    
    foreach f in $familiars[] {
        if (have_familiar(f)) {
            if (f.drops_limit > 0) {
                item_drop[i] = f;
                i = i + 1;
            }
        }
    }
    
    sort item_drop by -get_price(value.drop_item, 1);
    foreach i in item_drop {
        f = item_drop[i];
        if (item_drop[i] != $familiar[none]) {
            print(f + " - " + f.drop_item + " - " + get_price(f.drop_item, 1));
        }
    }
}
void main() {
    print_drop_values();
}
Now to figure out a sensible way to incorporate the familiars with drop_item = $item[none]. Do any of you have any suggestions?
 
Last edited:

Pazleysox

Member
Code:
    foreach f in $familiars[] {
Now to figure out a sensible way to incorporate the familiars with drop_item = $item[none]. Do any of you have any suggestions?

Try putting the familiar type in, rather than leaving it blank. This way you're only searching for familiars with drops, and familiars you have. :)

Code:
foreach f in $familiars[Adventurous Spelunker, Ancient Yuletide Troll, Angry Jung Man, Astral Badger, Baby Bugged Bugbear, Baby Sandworm, 
				Blavious Kloop, Bloovian Groose, BRICKO chick, Cotton Candy Carnie, Crimbo Shrub, Fist Turkey, Galloping Grill,
				Gelatinous Cubeling, Golden Monkey, Green Pixie, Grim Brother, Grimstone Golem, Knob Goblin Organ Grinder,
				Lil' Barrel Mimic, Li'l Xenomorph, Llama Lama, Mechanical Songbird, Miniature Sword & Martini Guy, Ms. Puck Man, Obtuse Angel, 
				Penguin Goodfella, Pottery Barn Owl, Puck Man, Rock Lobster, Rogue Program, Slimeling, Stocking Mimic, 
				Sugar Fruit Fairy, Twitching Space Critter, Unconscious Collective]

EDIT: Now, I could be wrong, but I believe this is the complete list of familiars with drops. And before you say it, TPTB (The powers that be) already know "Miniature Sword & Martini Guy"

Heh, look at that. I helped someone. lol Usually the other way around.
 
Last edited:

lostcalpolydude

Developer
Staff member
EDIT: Now, I could be wrong, but I believe this is the complete list of familiars with drops.

It is for now, maybe. New familiars get made often enough, and then the list needs updating.

Your suggestion won't change the fact that $familiar[Fist Turkey].drop_item == $item[none], so it doesn't actually help here.

For an actual solution, I don't know that there is one besides hard-coding the drops somehow.
 

Pazleysox

Member
It is for now, maybe. New familiars get made often enough, and then the list needs updating.

Your suggestion won't change the fact that $familiar[Fist Turkey].drop_item == $item[none], so it doesn't actually help here.

For an actual solution, I don't know that there is one besides hard-coding the drops somehow.

Hard coding familiar drops won't be any better than hard coding the familiars, the script will still have to be updated.

I ran the script with the addition of the familiar names, then re-ran it after removing Fist Turkey. Here's the 2 results:
Code:
Puck Man - power pill - 15000
Golden Monkey - powdered gold - 10000
Rogue Program - Game Grid token - 9539
Grimstone Golem - grimstone mask - 7250
Galloping Grill - hot ashes - 825
Fist Turkey - none - 0
Code:
Puck Man - power pill - 15000
Golden Monkey - powdered gold - 10000
Rogue Program - Game Grid token - 9539
Grimstone Golem - grimstone mask - 7250
Galloping Grill - hot ashes - 825
 

lostcalpolydude

Developer
Staff member
Hard coding familiar drops won't be any better than hard coding the familiars, the script will still have to be updated.

Hard-coding familiars provides no benefit. The script might have to be updated, but only if drop_item is none for a new familiar.
 
Top