SmashLib: Expected results from smashing

SmashLib 1.2

SmashLib attempts to tell you what you're going to get when you smash something. Since it's impossible to know exactly what you're going to get, it takes an expected value approach: if half the time you'll get a twinkly powder, and half the time you'll get a cold powder, it tells you you'll get .5 twinkly powders and .5 cold powders.

SmashLib handles both regular equipment and any weird stuff that Mafia deals with in pulverize.ash. In essence, SmashLib is designed to be a script version of the Pulverize Helper, and should tell you the same thing with a little more detail.

SmashLib requires ZLib

For Scripters:
SmashLib provides a way for scripts to get at the results of smashing things via three basic functions:

float [string] get_smash_element(item it) : Returns a map of elements/pseudo-elements to fraction of results of that element. Possible elements are: twinkly, cold, hot, sleaze, stench, useless, epic, sea salt, ultimate, sugar, depleted Grimacite, and Crovacite

string get_smash_tier(item it) : Returns a string representing the smash tier: 1P, 2P, 3P, 1N, 2N, 3N, 1W, 2W, 3W, or exception. "exception" serves as flag to note that the item is smashable, but not a normal smashable.

float [item] get_smash_yield(item it) : Combines element and tier to give all the expected results of smashing the item (including elemental jewels).

Keys are not present in maps unless they are actual results.

Other functions include:
boolean is_smashable(item it);
boolean is_malusable(item it);
boolean smash(int quantity, item it);
// a wrapper for CLI's "smash" command
item to_jewel(element el);
float [string] get_wad_yield(item it, boolean malus);
float [string] get_wad_yield(int [item] its, boolean malus);
void print_smash_report(item it);
void print_smash_report(string it_str);


For Users:
Although primarily for scripters, others may like SmashLib as an alternative to the Pulverize Helper for items you don't have at the moment. Create this alias to get a smash report for any item:

alias sr => ash import <SmashLib.ash> print_smash_report($item[%%]);

For example, typing sr demonskin jacket in the CLI gives this output:

Code:
demonskin jacket
Tier: 1N
Elements:
 hot: 0.5
 twinkly: 0.5
Expected Yields:
 hot nuggets: 0.25
 hot powder: 1.0
 twinkly nuggets: 0.25
 twinkly powder: 1.0

A call for testing: I'd very much appreciate if one or two people could verify my math in the wads section of get_smash_yield(). Those elemental jewel chances make things fiddly, and I'm not sure I trust my math.

Version History:
1.2: added smash(int quantity, item it) function (it just wraps the equivalent cli command)
1.1: fixed bounds problem in get_smash_tier(); switched from abort() to zlib's vprint(); suggested a better command for the alias
1.01: changed record holding equipment.txt data; Mafia doesn't like to read in fields that aren't there any more
 

Attachments

  • SmashLib.ash
    14.8 KB · Views: 1,253
Last edited:

Quincunx

New member
In the get_smash_tier function, line 270 should be
Code:
if (requirement >= 75) return "3W";
instead of
Code:
if (requirement > 75)  return "3W";
This way, equipment with 75 power like Elmley shades and Energy Drink IV will no longer return a tier of "".

Same thing for equipment with a power of 180. That should have a tier of "3W", not "".
 
Last edited:

philmasterplus

Active member
Could you please create a boolean smash_item( int q , item i ) version of the smash() function that will do nothing but return true when the quantity is zero or negative, similar to the put_closet() and similar functions? Because I've been unexpectedly shafted more than once by how the smash command auto-interprets it.
I could make a function myself, it would be trivial, but I thought it would be best if SmashLib were to provide this functionality in the first place.
 

heeheehee

Developer
Staff member
For future reference (as close to aqua's style as possible):
PHP:
boolean smash_item(int q, item i);
...
boolean smash_item(int q, item i)
{
    if(q<1) return true;
    return smash(q,i);
}
 

slyz

Developer
I just noticed SmashLib returns stuffed Mr Klaw items as yielding 1P Twinkly, but they yield useless powder.

Apparently, items that do not have any enchantment yield useless powder. In the case of stuffies, we could simply check if the item is giftable and not tradeable.

Changes to make:
- line 158
PHP:
if (is_giftable(it) && !is_tradeable(it))
{	
	result["useless"] = 1.0;
	return result;
}

- line 260
PHP:
if (is_giftable(it) && !is_tradeable(it))
	return "exception";
 
Last edited:

philmasterplus

Active member
Bug: is_smashable() returns true for quest items, even though they are not smashable. (e.g. Lord Spookyraven's spectacles.) Could you please fix it in the next release?
 

Winterbay

Active member
Can anyone tell me what happens if you call the CLI smash-command with say 5 twinkly nuggets. Do you get a wad then? (i'm currenty in a moxie run)

Also: The bug in the post above is fixed in the version I'm working on.

Edit: The attached version of smashlib should take advantage of Mafias nifty get_related function to make the script a lot shorter than it was before. I do not think I've messed anything up but comments are welcome :)
 
Last edited:

xKiv

Active member
Can anyone tell me what happens if you call the CLI smash-command with say 5 twinkly nuggets. Do you get a wad then? (i'm currenty in a moxie run)

I am fairly certain this worked when I had malus access (powders->nuggets, nuggets->wads).
 

Erwyn

New member
SmashLib isn't calling zlib properly for me. It gives me a reference of (SmashLib, line 28). This happens whether I run SmashLib or Price Advisor. Help, please?
 

Theraze

Active member
Line 28 is check_version... question, have you updated mafia and zlib to the latest versions recently?
 

Erwyn

New member
With mafia, I'm using the latest daily build and zlib was downloaded from its thread here, first post (I think).
 

Theraze

Active member
Check to see if you have an old copy of zlib in another folder? That can cause it to fail...
 

Erwyn

New member
Thank you for your help. I tried your suggestion and it's still giving me fits. I've got an idea...hopefully this whole thing is just user error. :p
 
Top