Reducing ASH function bloat

holatuwol

Developer
I'm thinking of removing a whole mass of functions from the ASH, because with the 'dot' operator a lot of functions now no longer have intuitive names and the scripts I'm writing aren't easy to read. That, and there's this huge function bloat that I saw when I was skimming through the function list.

I'm starting with the xxx_to_xxx functions, as I get the feeling that they are more intuitive if they were just to_xxx functions that you call on the value. Before I continue, will anyone be offended by the idea that a lot of scripts will suddenly stop working because the newer versions of mafia won't parse them?
 

izchak

Member
Is it possible we could get an 'interim' period, with deprecated methods still being allowed, but with a warning that it is deprecated, and liable to be removed soon?

Sort of like..
Warning: string_to_int() is deprecated, and liable to be removed soon. Use to_int() instead!

That way those of us without sed/perl can start replacing our soon to be deprecated methods, without having everything break...

Those of us with sed/perl can obviously search/replace all of our XXX_to_YYY calls into to_YYY.
sed -i 's/string_to_int/to_int/g' mafia/scripts/**/*.ash
or something like that. My sed skillz are rusty!
 

holatuwol

Developer
Most of the xxx_to_xxx will continue to be available, however there will no longer be any type checking on them.  Not that this matters, fundamentally speaking, since you're just interested in the return value for these anyway.  In addition to this, I've removed the following functions which I didn't see any point to:

void put_closet( int meat )
void take_closet( int meat )
zodiac my_zodiac()

Other things removed include a few other quest-related functions, like auto-completers for the gourd quest (which I don't think anyone actually used in ASH), the automatic guild unlock (which I'm not sure anyone used) and the nemesis quest (same deal -- this seems more like a CLI thing anyway).  I don't really understand the zodiac data type given that they're not that useful, so they're gone as well.

I have removed all the trapper and bounty hunter functions both from the CLI and the ASH.  They will continue to be available through the GUI.  The trapper may eventually come back, but the bounty hunter is expected to change with NS13 according to a radio show, so it's not likely to return at all.

For consistency reasons, museum_amount was changed to display_amount to match all of the put_display functions.  closet_amount was removed and combined with item_amount -- so now, item_amount will return how much is available in the inventory and in the closet.

The mind control functions were changed to current_mcd and change_mcd.  The equip_familiar function was changed to use_familiar.  The current_equipment function was changed to equipped_item.  equip_slot was changed to equip and the two unequip functions were removed.  Now, if you wish to remove something, equip $item[none] to that slot.

Finally, after all this removal, I've duplicated (more or less) the function written for Illarion's NeoStasis to calculate expected damage, and it's (not unsurprisingly) expected_damage.  Other functions related to this same calculation may disappear later on ... I'm still trying to decide if I should remove them.

In the process of re-organizing the functions, I decided to add moon_light, just because I don't expect anyone to come up with a convincing use for it, and the proposed use, while inconsistent with what I want, isn't nearly as bad as, say, NPZR stasis.  Since belts are fairly crappy for dedicated item farmers, I reasoned out (after a lot of deliberation) that it's not worth arguing over, so it's implemented.
 
I can certainly understand the bloat issue.

[quote author=holatuwol link=topic=938.msg4645#msg4645 date=1180043990]
For consistency reasons, museum_amount was changed to display_amount to match all of the put_display functions. closet_amount was removed and combined with item_amount -- so now, item_amount will return how much is available in the inventory and in the closet.
[/quote]

Just a thought or idea which goes along the same path, but might do more for eliminating ash function bloat:

New Data type: $Storage[] (maybe a better name for it?)
Possibilities: inventory, closet, hagnk, display, shop, stash

Replacement for all put and take type commands:
put(in, amount, item) where to is of the $Storage type and shop in the to location would leave limit and price blank. Hagnk in the to location would generate an error.
Take(from, amount, item) where from is of the $Storage type

Replacement for all amount type functions:
amount(in, item) where in would be of the $storage type

The shop_put command has extra parameters, but for it we could resort to the CLI version if we need them. When shop is passed to take it might generate an error, or it might have a clever way of handling it like if less than 3 take 1 at a time, more than 3 take all, then put the excess back.

It seems this would actually take 15 (i think) functions and reduce them to 3, and a new datatype. item_amount returning the total in the closet, and inventory might prove separately useful, but excluding it from removal isn't as productive. 6 of one half a dozen of the other.

visual samples:
int a = $storage[closet].amount($item[turtle totem]);
$storage[display].take(1, $item[turtle totem]);
$storage[display].put(1, $item[turtle totem]);

take($storage[display], 1, $item[turtle totem]); if converted to a sentence like a person would say it would be "Take from display case one turtle totem." which I think covers readability, and making sense.

As you can probably see this would also allow users to quick fix most of their scripts using search/replace in their favorite editor, reduces ash function bloat, and does not reduce functionality. All functions remain available, but require a slightly different calling convention. Some new functionality may even come to be in the process.

I cannot say that I personally use closet_amount, but I know my sister does. I do not remember the script details, and she is away from home right now, but I know closet_amount was required for it to function properly as it verified items which she needs are in her closet, then gets rid of any excess which lingered in her inventory. It could be changed to use the museum, but she prefers people not know what she has to reduce the likelihood of beggars and scammers bugging her.




other ideas after looking through the wiki:

void wait( int delay ) seems to me that this one could be a candidate for becoming a cli_execute only command? Just a thought. It would be easy for most users to fix their scripts in this event.

void print( string helloworld )
void echo( string helloworld )
is there a functional difference between these 2 commands? Could they be merged in some fashion if so?

stat current_hit_stat()
int buffed_hit_stat()
since current_hit_stat tells you what stat to check isn't buffed_hit_stat replication of int my_buffedstat( stat st )? Couldn't the user use my_buffedstat(current_hit_stat()) to arrive at the same place?

float elemental_resistance( element elem )
float cold_resistance()
float hot_resistance()
float sleaze_resistance()
float spooky_resistance()
float stench_resistance()
Looks like 1 function that does what's wanted and 5 more that do the same? Really if you wanted to these could be combined with the list below also

int raw_damage_absorption()
float damage_absorption_percent()
int damage_reduction()
int combat_percent_modifier()
int initiative_modifier()
int fixed_experience_bonus()
int meat_drop_modifier()
int item_drop_modifier()
int monster_level_adjustment()

seems these functions could be reduced to 1:
float Modifier(string) where string would be one of: "raw_damage_absorption", "damage_absorption_percent", "damage_reduction", "combat_percent", "initiative", "fixed_experience_bonus", "meat_drop_modifier", "item_drop_modifier", "monster_level_adjustment" and possibly the various elemental resistances from above. Does kolmafia auto convert float to int as needed?

Well if you make use of any one of these ideas (and/or hopefully change your mind about closet_amount's functionality being just gone) then it was worth my effort to type all this ;D wow this is a long post!
 

muffins

Member
Ouch... I actually use closet_amount quite heavily, primarily to protect quest items (primarily NS, of course) and to just generally keep my inventory tidy. It also allows me to otherwise sell the extra "protected" items without worrying about selling an item I'd like to keep safe. I do like the idea of a "combined inventory/closet amount" function, but without closet_amount, changing my scripts to reflect this could possibly cause extra server load via over-closeting items I only need to closet one of, and I'd rather not do that.

Any other options for something like this? I suppose I could enable and disable the memento list, but I'd be worried I might leave it off when it needs to be on.
 

holatuwol

Developer
One of the things about ASH function bloat is that I don't want to make ASH more complicated just to make the functions look simpler, when nothing really changes.  So, adding new data types or having functions which accept additional parameters instead doesn't serve this purpose, since internally, ASH just got more complicated not less (even though it looks simpler from the outside).

That said, I've removed echo, and I've re-added closet_amount.  The item_amount now returns the value it used to return (the amount in your inventory) and a new function available_amount has been added in order to give you the sum total of everything in your inventory and closet, including items you have equipped (if applicable) and in storage if you've broken Ronin.

All the elemental resistance methods have been removed in favor of the following two methods:  elemental_resistance() and elemental_resistance( monster ).  The motivation is that usually you're not looking for immunity against a particular element, you're just seeing how well you can resist a given monster.  The former method is for in-battle consult scripts, the latter for general purpose use.

Given the change, monster_attack_element has been removed and monster_defense_element has been renamed to monster_element.
 

muffins

Member
Oh, hola, much, much, much, MUCH love for re-adding closet_amount, and for the available_amount function. <33333333333!

(No, I'm not drunk, just sleep deprived... guess I should go fix that now.)

Seriously though, thank you!
 
Top