Jump to content

Closest bank to you


Recommended Posts

Posted (edited)
    public Area getNearBank(){
    	Field bank = null;
    	int minDist = Integer.MAX_VALUE;
    	for(Field f : Banks.class.getDeclaredFields()){
    		try {
    			int distance = getMap().distance(((Area) f.get(f.getName())).getRandomPosition());
    			if(distance < minDist && distance != -1){
    				minDist = distance;
    				bank = f;
    			}
			} catch (IllegalArgumentException | IllegalAccessException e) {
				e.printStackTrace();
			}
    	}
    	
    	if(bank != null)
			try {
				return (Area) bank.get(bank.getName());
			} catch (IllegalArgumentException | IllegalAccessException e) {
				return null;
			}
		else
    		return null;
    }

Can someone plz update this with streams. Thanks

@Alek plz turn Banks into actual enums so I dont have to do this gunk

Edited by k9thebeast
Posted
6 minutes ago, the wamie said:

There is a snipper around on the forum which lets you get the closest bank in a cleaner way imo.

It does it by creating an Enum yourself and filling it with the appropriate Area.
Link: 

 

Wouldn't really call filling your own enum up with all the possible banks cleaner, but your pick lol. Combine the two if you like, his does have some nice components. @LoudPacks

Posted (edited)

Personally I think it is cleaner because it allows you to easily add multiple custom banks that are not defined in the API. Without needing to alter any code, while if I wanted to add some to your snippet I would need to alter the way you check each bank. But that is just me. (Just explaining why I personally think it is cleaner, not saying its the best option)

Edited by the wamie
Posted
1 hour ago, Alek said:

Both your solution and LoudPacks solution won't work with web walking. 

Well I use webwalking, and it works just fine in the script I am currently testing, I just use the enum to populate a JComboBox and fill the variables inside the Settings class.
Then for walking I get the Area from the Settings, and web walking works perfectly fine.

Posted
8 minutes ago, the wamie said:

Well I use webwalking, and it works just fine in the script I am currently testing, I just use the enum to populate a JComboBox and fill the variables inside the Settings class.
Then for walking I get the Area from the Settings, and web walking works perfectly fine.

Not to vent on you, but I have to explain this topic so many times its getting annoying.

The closest bank in regards to the map coords is different than actual traversing. Consider wanting to grab the closest bank to you. The closest bank in coords is on the other side of a river which; you can't cross the river but its the closest. This is a common error in such approaches, because although its physically closer, actually walking there is much longer.

 

 

Posted
17 minutes ago, Alek said:

Not to vent on you, but I have to explain this topic so many times its getting annoying.

The closest bank in regards to the map coords is different than actual traversing. Consider wanting to grab the closest bank to you. The closest bank in coords is on the other side of a river which; you can't cross the river but its the closest. This is a common error in such approaches, because although its physically closer, actually walking there is much longer.

 

 

No worries, I was just curious and thought you meant the coords won't work with the webwalk in that way, my appologies for not understanding correctly.
But that makes a lot of sense. Should have thought about that myself. Ah well, thanks for the explanation.

Posted
3 minutes ago, the wamie said:

No worries, I was just curious and thought you meant the coords won't work with the webwalk in that way, my appologies for not understanding correctly.
But that makes a lot of sense. Should have thought about that myself. Ah well, thanks for the explanation.

When you pass an array/list of positions into webwalkevent, it automatically generates the fastest route. If you use prefetchrequirements, you can grab the closest bank without actually walking there.

  • Like 1
Posted (edited)
On 6/20/2017 at 3:12 AM, k9thebeast said:

Wouldn't really call filling your own enum up with all the possible banks cleaner, but your pick lol. Combine the two if you like, his does have some nice components. @LoudPacks

But yea like Alek said it doesn't account for the actual path distance so it might not be the best way.

Edited by LoudPacks

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...