New CLI command: consumed

Chish

Member
I couldn't find a CLI command that showed me how much I had eaten, so I wrote one. This site's uploader will not let me add it as an attachment for some reason, so here is /textui/command/consumedCommand.java:

Code:
/**
 * Copyright (c) 2005-2012, KoLmafia development team
 * http://kolmafia.sourceforge.net/
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 *  [1] Redistributions of source code must retain the above copyright
 *      notice, this list of conditions and the following disclaimer.
 *  [2] Redistributions in binary form must reproduce the above copyright
 *      notice, this list of conditions and the following disclaimer in
 *      the documentation and/or other materials provided with the
 *      distribution.
 *  [3] Neither the name "KoLmafia" nor the names of its contributors may
 *      be used to endorse or promote products derived from this software
 *      without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION ) HOWEVER
 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE ) ARISING IN
 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

package net.sourceforge.kolmafia.textui.command;

import net.sourceforge.kolmafia.AdventureResult;
import net.sourceforge.kolmafia.KoLCharacter;
import net.sourceforge.kolmafia.KoLConstants;
import net.sourceforge.kolmafia.KoLmafia;
import net.sourceforge.kolmafia.RequestLogger;
import net.sourceforge.kolmafia.RequestThread;

public class ConsumedCommand
	extends AbstractCommand
{
	public ConsumedCommand()
	{
		this.usage = " - shows stomach/liver/spleen used.";
	}

	@Override
	public void run( final String cmd, final String parameters )
	{
		ConsumedCommand.consumed();
	}

	public static void consumed( )
	{
		RequestLogger.printLine( "Fullness: " + KoLCharacter.getFullness() + " / " + KoLCharacter.getFullnessLimit() );
		RequestLogger.printLine( "Inebriety: " + KoLCharacter.getInebriety() + " / " + KoLCharacter.getInebrietyLimit() );
		RequestLogger.printLine( "Spleen Use: " + KoLCharacter.getSpleenUse() + " / " + KoLCharacter.getSpleenLimit() );
		return;
	}
}

also be sure to add a line to KoLmafiaCLI.java (starting from line 730):

Code:
		new CondRefCommand().register( "condref" );
		new ConsumedCommand().register( "consumed" );
		new CouncilCommand().register( "council" );

What do you guys think? modref should also be changed to include this data IMO. Should I just start pushing to svn? How do I get write access?
 

Theraze

Active member
So it's just a new command that shows my_fullness()/fullness_limit(), my_inebriety/inebriety_limit(), and my_spleen_use()/spleen_limit()?

If you want to see one in the gCLI, just type it without the (). Or, to replicate this natively, try this:
> ashq print_html("Fullness: "+my_fullness()+"/"+fullness_limit()+"\nInebriety: "+my_inebriety()+"/"+inebriety_limit()+"\nSpleen Use: "+my_spleen_use()+"/"+spleen_limit())

Fullness: 15/15
Inebriety: 23/19
Spleen Use: 0/15
To turn it into an alias named "consumed", this should work:
alias consumed => ashq print_html("Fullness: "+my_fullness()+"/"+fullness_limit()+"\nInebriety: "+my_inebriety()+"/"+inebriety_limit()+"\nSpleen Use: "+my_spleen_use()+"/"+spleen_limit())
 

Chish

Member
oh... I didn't know you could call the Java functions directly from the CLI. Huh, well that's interesting. Thanks for that tidbit.

But where are the functions my_inebriety() , etc. from?

edit: nevermind, found them in /textui/RuntimeLibrary.java
 
Last edited:

roippi

Developer
Well, okay. Long post coming up, and it's likely going to come across as a bit harsh. I really don't mean to dissuade you from trying to contribute to the codebase, we're always open to new developer talent. I'm just providing constructive criticism.

How do I get write access?

Well, we grant it to you if you demonstrate that you "get it." That's a very brief way to sum up what the rest of this post is going to be about. I'd say it can be broken down, roughly, to:

1) Trust - we trust you not to commit harmful things to the codebase.
2) Ability - generally capable at coding in Java.
3) Familiarity - specifically, that you understand how various mafia subsystems work in a general sense. You don't need to be an expert in everything, generally getting to know one specific part of mafia well will lend at least vague familiarity with many other parts. A lot of devs tend to specialize in one area, in fact, at least to start with.

The above are not mutually exclusive; a really nice guy, for example, may never maliciously code something to be harmful, but he may be a subpar programmer and commit something that autosells one's entire inventory.

Which, all together, answers your question in the general sense. Submit patches, let us get to know you and your code. Of the three above points, 2 and 3 are important, but #1 is vital. Mafia is somewhat unique in that the user base is by and large directly hooked up to the development branch. This makes us very agile in dealing with new content, but one rogue commit can have devastating impacts on many people. We have to trust you.

------

On to specific comments for your code. Probably most notably, it violates #3 from above. While it is true that no CLI command displays fullness, a command "status" exists that you could have just added to if you wanted this information to be available in a CLI command. That command already displays drunk, in addition to other info.

I also have to point out that "modref should also be changed to include this data" is just.. wrong. Fullness/drunk/spleen are not modifiers.

I have worries about #2 as well. You should know how to make a .patch file - either using diff, tortoisesvn, or IDE-specific tools.
 

roippi

Developer
oh... I didn't know you could call the Java functions directly from the CLI. Huh, well that's interesting. Thanks for that tidbit.

But where are the functions my_inebriety() , etc. from?

edit: nevermind, found them in /textui/RuntimeLibrary.java

They are not java functions, they are ASH functions. I think you need to spend a bit of time on the wiki.
 

Chish

Member
KoLCharacter.getFullness() is obviously the Java function and my_fullness() is obviously the ASH function. I just had a brain fart in my post.
 

Chish

Member
How does this look?

Patch for ShowDataCommand.java attached.
 

Attachments

  • ShowDataCommandPatch.diff
    157 bytes · Views: 40

Theraze

Active member
That's a diff, not a patch. A patch shows you... a lot more. Including which version of the code you're comitting to, etc.

Also, to find ASH commands, use the ASHREF CLI command.
 

Catch-22

Active member
How does this look?

Patch for ShowDataCommand.java attached.

Nope. You'll need to create the patch by right-clicking on the entire kolmafia SVN folder, not just the one file you modified. As Theraze has noted, that's a diff not a patch.

There's also a subforum for feature requests, which is typically where you would attach a patch file along with your feature request.

Feature requests generally have to be something that isn't easily accomplished using existing functionality in KoLmafia. What you're trying to do can be accomplished fairly easily using existing ASH commands (see Theraze's post above).

Welcome aboard though, I encourage you to read the wiki and get to know ASH before you dive too deep into the java files :)
 

roippi

Developer
When I said diff I was referring to svn diff.

Like I mentioned above, we would probably reject a new command for this. If you wanted to add fullness and spleenhit to the "status" command, we'd probably accept that.
 

holatuwol

Developer
As others have noted, you need to provide a diff that someone can quickly apply with patch -p0 or equivalent after dropping your diff into the root of the source tree (make it as easy as possible).

That being said, even though it wasn't in the correct format, your changes weren't all that complex and I don't see anything wrong with adding that information to the "status" CLI command, so I manually applied the suggested changes in r11133.
 
Top