Jump to content

Cannot detect free places to light fire


kushroom

Recommended Posts

Hey guys im working on a ge cooker, where I have tiles closest to the bank at the ge that are able to have fires lighted at. When i run the code to detect the fires in the area around the bank it does that fine and logs all of them. So i try and take and check those locations vs the locations of lite fires so the script knows where to make a new fire that is closest to the bank, here is my variables and code commented for easy reading. If anyone could help me detect which free spaces in my array of positions that do not contain a ground object so I can have it light fires, that would be more than appreicated! Thanks as always guys!

 

Variables:

	private final Area fireZone = new Area(3161,3486,3168,3493);
	private ArrayList<Position> positions = new ArrayList<Position>();
	private final Position[] fireSpots = {
			new Position(3166,3492,0),
			new Position(3163, 3492, 0), 
			new Position(3162, 3492, 0),
			new Position(3162, 3491, 0),
			new Position(3161, 3490, 0),
			new Position(3161, 3489, 0),
			new Position(3162, 3488, 0),
			new Position(3162, 3487, 0),
			new Position(3163, 3487, 0),
			new Position(3164, 3486, 0),
			new Position(3165, 3486, 0),
			new Position(3166, 3487, 0),
			new Position(3167, 3487, 0),
			new Position(3167, 3488, 0),
			new Position(3168, 3489, 0),
			new Position(3168, 3490, 0),
			new Position(3167, 3491, 0),
			new Position(3167, 3492, 0),
			new Position(3166, 3492, 0),
			new Position(3165, 3493, 0),
			new Position(3164, 3493, 0),
			new Position(3163, 3492, 0)};
	private boolean done = false;

Methods:

private Position getNearestFree(){
		if(done){
			try {
				sleep(5000);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
			return null;
		} else { //start of else statement
		removeAll(positions); //Emptys the arraylist to ensure that there is no previous saved variables
		ArrayList<RS2Object> fires = new ArrayList<RS2Object>();
		for(Position p : fireSpots){
			positions.add(p); //Adds the spots in which you can light logs from an array to an array list
		}
		List<RS2Object> fire2 = getObjects().getAll();
		for(int i=0;i<fire2.size();i++){
			if(fireZone.contains(fire2.get(i)) && fire2.get(i).getName().equals("Fire")){
				fires.add(fire2.get(i)); //Adds fires from fireZone (Space around ge)
			}
		}
		for(int i=0;i<fires.size();i++){ //Remove fires that are lit from array of positions that are lightable
			for(int j=0;j<positions.size();j++){
				if(fires.get(i).getPosition() == positions.get(j)){
					positions.remove(j);
				}
			}
		}
		int dis = 513;
		int temp = 513;
		int objIndex = 0;
		for(int i=0;i<positions.size();i++){
			temp = map.distance(positions.get(i));
			if(temp < dis){
				dis = temp;
				objIndex = i;
			}
		}
		done = true;
		return positions.get(objIndex);
		} //end of else statement
	}
	
	private void removeAll(ArrayList<?> objs){
		if(objs.size() > 0){
			for(int i=0;i<objs.size();i++){
				objs.remove(i);
			}
		}
	}
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

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