Maps without Return Values?

macman104

Member
*Solved, read the last edit if you want to know, or, ya know, read it all if you want*

I'm working on a map for my namespaces script to allow easy switching of the auto attack preference. I initially was going to have a map, that was the following
Code:
skill [string] autoAttackSkills;

autoAttackSkills["CHRONIC INDIGESTION"] = $skill[Chronic Indigestion];
autoAttackSkills["CLEESH"] = $skill[CLEESH];
autoAttackSkills["COLD BREATH"] = $skill[Cold Breath];
autoAttackSkills["CONE OF WHATEVER"] = $skill[Cone of Whatever];
autoAttackSkills["DISCO DANCE II: ELECTRIC BOOGALOO"] = $skill[Disco Dance II: Electric Boogaloo];
autoAttackSkills["DISCO DANCE OF DOOM"] = $skill[Disco Dance of Doom];
autoAttackSkills["DISCO EYE-POKE"] = $skill[Disco Eye-Poke];
autoAttackSkills["DISCO FACE STAB"] = $skill[Disco Face Stab];
autoAttackSkills["ENTANGLING NOODLES"] = $skill[Entangling Noodles];
autoAttackSkills["EXTREME RAY OF SOMETHING"] = $skill[eXtreme Ray of Something];
autoAttackSkills["FEARFUL FETTUCINI"] = $skill[Fearful Fettucini];
//autoAttackSkills["GIVE IN TO YOUR VAMPIRIC URGES"] = $skill[Give In To Your Vampiric Urges]
autoAttackSkills["HEAD + KNEE + SHIELD COMBO"] = $skill[Head + Knee + Shield Combo];
autoAttackSkills["HEAD + KNEE COMBO"] = $skill[Head + Knee Combo];
autoAttackSkills["HEAD + SHIELD COMBO"] = $skill[Head + Shield Combo];
autoAttackSkills["HEADBUTT"] = $skill[Headbutt];
autoAttackSkills["HOT BREATH"] = $skill[Hot Breath];
autoAttackSkills["KNEE + SHIELD COMBO"] = $skill[Knee + Shield Combo];
autoAttackSkills["KNEEBUTT"] = $skill[Kneebutt];
autoAttackSkills["LASAG"] = $skill[Lasagna Bandages];
autoAttackSkills["LS"] = $skill[Lunge-Smack];
autoAttackSkills["LTS"] = $skill[Lunging Thrust-Smack];
autoAttackSkills["MAGIC MISSILE"] = $skill[Magic Missile];
autoAttackSkills["MINOR RAY OF SOMETHING"] = $skill[Minor Ray of Something];
autoAttackSkills["MOXIOUS MANEUVER"] = $skill[Moxious Maneuver];
autoAttackSkills["PICKP"] = $skill[Pickpocket];
autoAttackSkills["SAUCEGEYSER"] = $skill[Saucegeyser];
autoAttackSkills["SAUCESTORM"] = $skill[Saucestorm];
autoAttackSkills["SAUCY SALVE"] = $skill[Saucy Salve];
autoAttackSkills["SHAKE HANDS"] = $skill[Shake Hands];
autoAttackSkills["SHIELDBUTT"] = $skill[Shieldbutt];
autoAttackSkills["SLEAZY BREATH"] = $skill[Sleazy Breath];
autoAttackSkills["SPECTRAL SNAPPER"] = $skill[Spectral Snapper];
autoAttackSkills["SPOOKY BREATH"] = $skill[Spooky Breath];
autoAttackSkills["STINKY BREATH"] = $skill[Stinky Breath];
autoAttackSkills["STREAM"] = $skill[Stream of Sauce];
autoAttackSkills["TANGO OF TERROR"] = $skill[Tango of Terror];
autoAttackSkills["TS"] = $skill[Thrust-Smack];
autoAttackSkills["WAVE OF SAUCE"] = $skill[Wave of Sauce];
autoAttackSkills["WEAPON OF THE PASTALORD"] = $skill[Weapon of the Pastalord];
However, as you can see by the one commented line in the middle, mafia doesn't necessarily recognize all the skills (I'll submit that it is a skill granted from an ultra-rare, and I didn't even know mafia didn't have it as a skill until I started working on this. Add that one skill, plus the fact that I realized I needed things like pickpocket, and attack with weapon, and disabled. So I started moving over to having a record that looked like this:
Code:
record attackSkill
{
	string fullName;
	string shortcutName;
	int skillNum;
}

int [attackSkill] autoAttackSkills;
Now, the trouble I'm having is purely a preference thing, but I'll ask about it anyway. I'm having trouble getting over the redundency of mapping the skills to an int, when the record has the int.

Well..."why not take the int out of the record and just go with that" you say? I could, and if I have to, I will. However, the complete structure of an attack skill, consists of the name, shortcut name, and the skill number that will be used to set the property. Because of that, the record feels incomplete without that value in there.

So...is there any way to have an aggregate of attack skills without mapping them to a certain integer? If not, and you (hola and veracity) are either too busy (which I'm sure you are with the end of school approaching), or feel that the time to change this outweighs the priority of this, please feel free to say so. This was less of a post to get you to change things, than it was to simply explore if there was a way available now (although don't let that discourage you ;)).

Thanks.

EDIT: I just realized I have some issues with my record/map of said record. So...don't pick on that ;D. Either I'll figure out what I actually wanted to do, or if someone suggest something, that works as well.

EDIT^2: I'll leave this thread up for the hell of it. But I realized in trying to "fix" my map, since I obviously can't index by a record (at least...I don't think you can), and by reading over the initial discussion when records were first thought of on the dev forum, that I should simply be setting the record type as the value for the map. So I now have:
Code:
record attackSkill
{
	string fullName;
	string shortcutName;
	int skillNum;
}

attackSkill [string] autoAttackSkills;
Where the strings will be mapped according to the shortcut name.

So...
Code:
boolean changeAutoAttack(string newAttack)
{
	int attackNum;
	
	foreach attack in autoAttackSkill
	{
		if(autoAttackSkill[attack].shortcutName == newAttack)
		{
			attackNum = autoAttackSkill[attack].skillNum;
			set_property("defaultAutoAttack", attackNum);
		}
	}
}
*Sigh* This is what not writing anything for ASH since, g-d knows when does to you... thanks for reading all. Lol
 

holatuwol

Developer
I do not believe you can use a record as an index (at least, the error messages I got when trying it out said as much).  So, you could just omit the skill ID and make it look like you're writing proper object oriented stuff with use accessor 'methods' instead of accessing the variables directly.

Code:
record AttackSkill
{
	string fullName;
	int autoAttackId;
};

AttackSkill [string] autoAttackSkills;

int getSkillId( AttackSkill sk )
{
	return sk.autoAttackId;
}

string getFullName( AttackSkill sk )
{
	return sk.fullName;
}

string getShortcutName( AttackSkill sk )
{
	foreach key in autoAttackSkills
	{
		if ( autoAttackSkills[key].autoAttackId == sk.autoAttackId )
			return key;
	}

	return sk.getFullName();
}

file_to_map( "autoattack.txt", autoAttackSkills );

foreach shortName in autoAttackSkills
{
	AttackSkill sk = autoAttackSkills[shortName];
	print( sk.getSkillId() + ": " + sk.getFullName() + " (aka " + sk.getShortcutName() + ")" );
}
 

macman104

Member
Hmm....you're idea of the accessors *is* tempting...I'll have to think on that. Then I'm back to mapping to skills from the shortcut name, like I was. Hmm....

Okie! Well, now that this mess has been resolved, I was wondering, there is currently a "to_upper_case" and lower case version. I was wondering, could we get a ignore_case for conditionals? So instead of casting the users input to uppercase (which I should have shown in the earlier post of the changeAutoAttack function), I can just say:
Code:
boolean changeAutoAttack(string newAttack)
{
	int attackNum;
	
	foreach attack in autoAttackSkill
	{
		if(autoAttackSkill[attack].shortcutName == newAttack.ignore_case())
		{
			attackNum = autoAttackSkill[attack].skillNum;
			set_property("defaultAutoAttack", attackNum);
		}
	}
}
 

holatuwol

Developer
KoLmafia already ignores case when testing for equality. The upper/lowercase modifiers are there so that index_of works correctly.
 

macman104

Member
[quote author=holatuwol link=topic=884.msg4336#msg4336 date=1177562282]
KoLmafia already ignores case when testing for equality. The upper/lowercase modifiers are there so that index_of works correctly.[/quote]Oh. Awesome.
Ok, so I rewrote my function to be shorter, and now I use the contains operation for maps. However, based on my testing, this *is* case-sensitive. Is this correct? If so...does that change your mind about ignore_case, or should I put in a switch to change the input to uppercase?
 

holatuwol

Developer
Oh right, "contains" is case sensitive. Because of the way maps work, ignorecase would be a pain to implement for them, so chances are that's not going to change any time soon.
 

macman104

Member
[quote author=holatuwol link=topic=884.msg4339#msg4339 date=1177568821]
Oh right, "contains" is case sensitive. Because of the way maps work, ignorecase would be a pain to implement for them, so chances are that's not going to change any time soon.
[/quote]Fair enough, I'll go ahead and modify the script. Thanks.

Quick Question: Is there anywhere that I can get all of the valid values for the battleAction property? Or are there various lists that I can combine to get that list?
 

holatuwol

Developer
For battleAction? Same values as are used in CCS. So things starting with "skill" or "item" along with "delevel" or "attack" more or less covers it. In theory, you can create "default" values for your CCS by using set_property( "battleAction", "semi-colon; delimited; list" );
 
Top