Feature - Implemented run_combat() with a combat filter.

Winterbay

Active member
BCA currently does the following when handling faxes, which is a place where you may want to use a combat filter, but can't directly since by just using the item Mafia runs the fight for you:

1) Request a fax
2) Check that you got the correct fax
3) call visit_url("inv_use.php?pwd=&which=3&whichitem=4873");
4) call bumRunCombat() which takes a string argument for if to use a combat filter or not

bumRunCombat currently looks like this:
Code:
string bumRunCombat(string consult) {
    //If we're not in a combat, we don't need to run this
    if (!contains_text(visit_url("fight.php"), "Combat")) {
        print("BCC: You aren't in a combat (or something to do with Ed which I can't work out), so bumRunCombat() doesn't need to do anything.", "purple");
        return to_string(run_combat());
    }
    
    if (consult != "") {
        print("BCC: This isn't actually adventuring at the noob cave. Don't worry! (Consult Script = "+consult+")", "purple");
        adv1($location[noob cave], -1, consult);
    }
    else if (my_primestat() == $stat[Mysticality] && in_hardcore()) {
        print("BCC: This isn't actually adventuring at the noob cave. Don't worry! (Myst)", "purple");
        adv1($location[noob cave], -1, "consultMyst");
    }
    else if (can_interact()) {
        print("BCC: This isn't actually adventuring at the noob cave. Don't worry. (Can_Interact() == True)", "purple");
        adv1($location[noob cave], -1, "consultCasual");
    }
    print("BCC: Run_Combat() being used normally.", "purple");
    return to_string(run_combat());
}

This can be adapted for other usages as well I guess, but a runCombat(string filter_function) would make that a lot easier I guess...
 

Bale

Minion
Ah! So as a workaround adv1() can be used to finish the fight. That's nice to know.

It's rather kludgy since you're sending it a bogus location that causes a completely unnecessary server hit. You should probably have made this feature request a long time ago to save all those server hits from a popular script.
 
You should probably have made this feature request a long time ago to save all those server hits from a popular script.

This feature request was made a long time ago.

http://kolmafia.us/showthread.php?4454-run_combat()-with-a-combat-filter

http://kolmafia.us/showthread.php?6402-run_combat(string)-Request

Ah! So as a workaround adv1() can be used to finish the fight. That's nice to know.

That is funny Bale, since you seemed to have commented in both threads and I think this particular workaround is mentioned in one of them or both, I can't remember for sure though. ;)
 

randombk

New member
In other words, extending the combat filter feature to run_combat() merely seems to be a matter of consistency.

^I second this. As someone who is just beginning ash scripting, the lack of such a feature just seems like a gaping hole in the api. I think that the fact that this has been requested many times already (sorry for that btw) shows that this is such a natural conclusion for a programmer to reach.

I read the other threads, and I'm now using a workaround suggested there, but I think it'll be so much easier if that wasn't needed. I'll keep the feature tag in the thread name for a bit longer, to see if I can get a final decision on this matter, then I'll change it, but thanks, everyone for helping!
 

Theraze

Active member
Just a note... you should never change the FReq tag. Let a developer decide if the feature is worthy of adding. If it piques their interest in 9 months, at least you get your feature. Only change it yourself if you never want them to consider your idea ever again and you're frankly quite ashamed you asked in the first place.
 

heeheehee

Developer
Staff member
Overload run_combat to use a combat filter

I've been getting back into scripting, and I was surprised to see that an overloaded version of run_combat() doesn't exist. It seemed like a simple enough addition, based off of the overloaded form of adventure().

Code:
	public static Value run_combat( Interpreter interpreter, final Value filterFunction )
	{
		try
		{
			String filter = filterFunction.toString();
			Macrofier.setMacroOverride( filter, interpreter );

			return RuntimeLibrary.run_combat( interpreter );
		}
		finally
		{
			Macrofier.resetMacroOverride();
		}
	}
 

lostcalpolydude

Developer
Staff member
Merged the 3 threads for this feature.

I think
Code:
--- src/net/sourceforge/kolmafia/textui/RuntimeLibrary.java (15330)
+++ Current File
@@ -1018,6 +1018,9 @@
 		params = new Type[] {};
 		functions.add( new LibraryFunction( "run_combat", DataTypes.BUFFER_TYPE, params ) );
 
+		params = new Type[] { DataTypes.STRING_TYPE };
+		functions.add( new LibraryFunction( "run_combat", DataTypes.BUFFER_TYPE, params ) );
+
 		params = new Type[] {};
 		functions.add( new LibraryFunction( "run_turn", DataTypes.BUFFER_TYPE, params ) );
 
@@ -4747,6 +4750,28 @@
 		return new Value( DataTypes.BUFFER_TYPE, "", new StringBuffer( response == null ? "" : response ) );
 	}
 
+	public static Value run_combat( Interpreter interpreter, Value filterFunction )
+	{
+		if ( FightRequest.currentRound == 0 && !FightRequest.inMultiFight )
+		{
+			return new Value( DataTypes.BUFFER_TYPE, "", new StringBuffer( "" ) );
+		}
+		try
+		{
+			String filter = filterFunction.toString();
+			Macrofier.setMacroOverride( filter, interpreter );
+			FightRequest.INSTANCE.nextRound( null );
+		}
+		finally
+		{
+			Macrofier.resetMacroOverride();
+		}
+
+		String response = FightRequest.lastResponseText;
+
+		return new Value( DataTypes.BUFFER_TYPE, "", new StringBuffer( response == null ? "" : response ) );
+	}
+
 	public static Value run_turn( Interpreter interpreter )
 	{
 		if ( FightRequest.currentRound > 0 || FightRequest.inMultiFight )

will implement this, but I doubt I can properly test it since I don't use anything like this in my scripts. I assume there are people who want this and are capable of making the change locally to test it out to give feedback.
 

heeheehee

Developer
Staff member
I vaguely recall implementing something pretty much identical to this when I was writing a casualscript. Seemed to work fine.
 

Theraze

Active member
Your report isn't a matter of this working differently from adventure or adv1. If you have a request to change how combat filters work, which is not the same as using a consult script, that would be a separate feature request.

Might I suggest rereading the 'adventure' wiki page located: http://wiki.kolmafia.us/index.php?title=Adventure
A combat filter function takes the parameters of a consult script, but returns lines like a CCS, not like a consult script.

If you want a simple action to repeat, you will need to tell it to repeat. For example, return "item seal tooth; repeat" instead of just return "item seal tooth" will make it throw the tooth until combat is over.
 

Bale

Minion
Try this:

PHP:
string simpleCombatFilter(int round, string opp, string text)
{
    return "\"item seal tooth; repeat\"";
}
 
Top