<commit_before>package fr.utbm.lo43.entities;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Random;

import org.newdawn.slick.Color;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.geom.Rectangle;
import org.newdawn.slick.geom.Vector2f;
import org.newdawn.slick.state.StateBasedGame;

import fr.utbm.lo43.dijkstra.DijkstraPathfinding;
import fr.utbm.lo43.dijkstra.Dijkstrable;
import fr.utbm.lo43.dijkstra.Path;
import fr.utbm.lo43.logic.Filiere;
import fr.utbm.lo43.logic.Line;
import fr.utbm.lo43.logic.Map;

public class Station extends EntityClickable implements EntityDrawable, Dijkstrable
{
	//24 taille case
	//Quadrillage
	//Jerem: rajout de ma part, à voir s'il ne faut pas le mettre dans le diagramme
	//En FR en plus
	protected Filiere filiere;
	public static final int MAXIMUM_PASSENGER = 8;
	public static final int CRITICAL_PASSENGER = 6;	
	private int waitedTime ;

	private static final int MAX_WAITING_TIME = 30;
	private static final int BONUS_WAITING_TIME = 15;
	
	private Image preview;
		
	private boolean alcoolized;
	private int maxWaitingTime;
	private int extraTime;
	
	protected ArrayList<Passenger> waitingPassenger;
	
	//HashMap qui donne la prochaine station a atteindre pour atteindre une filiere a partir de cette station 
	private HashMap<Filiere, Station> nextStop;
	
	public Station(Vector2f _position, Filiere type) 
	{
		super(_position);
		filiere = type;
		waitingPassenger = new ArrayList<>();
		Map.getInstance().calculateNextStopStations();
		try 
		{
			preview = new Image("asset/"+filiere.toString().toLowerCase()+".png");
			
		}
		catch (SlickException e) 
		{
			e.printStackTrace();
		}
		
		size.x = Map.GRID_SIZE*2;
		size.y = Map.GRID_SIZE*2;
		
		drawable = true;
	}
	
	public Passenger newPassenger()
	{
		Filiere passenger_type = filiere;
		
		int stations_size = Map.getInstance().getStationsLenght();
		Random rand = new Random();
		
		
		while(passenger_type == filiere){
			int index = rand.nextInt(stations_size);
			passenger_type = Map.getInstance().stations.get(index).filiere;
		}
		
		float offsetX,offsetY;
		
		offsetX = waitingPassenger.size()%4;
		offsetY = 0;
		
		offsetX = getPosition().x + offsetX * Map.GRID_SIZE/2;
		offsetY = getPosition().y + waitingPassenger.size()/4 * Map.GRID_SIZE*1.5f ;
		
		Passenger p = new Passenger(new Vector2f(offsetX,offsetY), passenger_type);
		waitingPassenger.add(p);
		
		return p;
	}
	
	/**
	 * Permet de remplir la HashMap nextStop
	 */
	public void setNextStop(DijkstraPathfinding<Station> pathfinding){
		nextStop = new HashMap<>();
		Path<Station> shortestPath;
		Station tempStation;
		float minDistance = -1;
		
		for(Filiere f : Filiere.values()){
			if(f == filiere){
			minDistance = -1;
			tempStation = null;
			for(Station s : Map.getInstance().stations){
				if(s.filiere == f){
					shortestPath = pathfinding.getShortestPath(this, s);
					/*for(Station test : shortestPath.getElements()){
						
						System.out.println(test);
					}*/
					if((shortestPath.getWeight()<minDistance || minDistance == -1) && shortestPath.getWeight()!=-1){
						minDistance = shortestPath.getWeight();
						tempStation = shortestPath.get(0);
					
					}
					
					
				}
			}
			nextStop.put(f, tempStation);
			}
		}
		for(Filiere f : Filiere.values()){<commit_msg>Modification setnexstop<commit_after>package fr.utbm.lo43.entities;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Random;

import org.newdawn.slick.Color;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.geom.Rectangle;
import org.newdawn.slick.geom.Vector2f;
import org.newdawn.slick.state.StateBasedGame;

import fr.utbm.lo43.dijkstra.DijkstraPathfinding;
import fr.utbm.lo43.dijkstra.Dijkstrable;
import fr.utbm.lo43.dijkstra.Path;
import fr.utbm.lo43.logic.Filiere;
import fr.utbm.lo43.logic.Line;
import fr.utbm.lo43.logic.Map;

public class Station extends EntityClickable implements EntityDrawable, Dijkstrable
{
	//24 taille case
	//Quadrillage
	//Jerem: rajout de ma part, à voir s'il ne faut pas le mettre dans le diagramme
	//En FR en plus
	protected Filiere filiere;
	public static final int MAXIMUM_PASSENGER = 8;
	public static final int CRITICAL_PASSENGER = 6;	
	private int waitedTime ;

	private static final int MAX_WAITING_TIME = 30;
	private static final int BONUS_WAITING_TIME = 15;
	
	private Image preview;
		
	private boolean alcoolized;
	private int maxWaitingTime;
	private int extraTime;
	
	protected ArrayList<Passenger> waitingPassenger;
	
	//HashMap qui donne la prochaine station a atteindre pour atteindre une filiere a partir de cette station 
	private HashMap<Filiere, Station> nextStop;
	
	public Station(Vector2f _position, Filiere type) 
	{
		super(_position);
		filiere = type;
		waitingPassenger = new ArrayList<>();
		Map.getInstance().calculateNextStopStations();
		try 
		{
			preview = new Image("asset/"+filiere.toString().toLowerCase()+".png");
			
		}
		catch (SlickException e) 
		{
			e.printStackTrace();
		}
		
		size.x = Map.GRID_SIZE*2;
		size.y = Map.GRID_SIZE*2;
		
		drawable = true;
	}
	
	public Passenger newPassenger()
	{
		Filiere passenger_type = filiere;
		
		int stations_size = Map.getInstance().getStationsLenght();
		Random rand = new Random();
		
		
		while(passenger_type == filiere){
			int index = rand.nextInt(stations_size);
			passenger_type = Map.getInstance().stations.get(index).filiere;
		}
		
		float offsetX,offsetY;
		
		offsetX = waitingPassenger.size()%4;
		offsetY = 0;
		
		offsetX = getPosition().x + offsetX * Map.GRID_SIZE/2;
		offsetY = getPosition().y + waitingPassenger.size()/4 * Map.GRID_SIZE*1.5f ;
		
		Passenger p = new Passenger(new Vector2f(offsetX,offsetY), passenger_type);
		waitingPassenger.add(p);
		
		return p;
	}
	
	/**
	 * Permet de remplir la HashMap nextStop
	 */
	public void setNextStop(DijkstraPathfinding<Station> pathfinding){
		nextStop = new HashMap<>();
		Path<Station> shortestPath;
		Station tempStation;
		float minDistance = -1;
		
		for(Filiere f : Filiere.values()){
	
			minDistance = -1;
			tempStation = null;
			for(Station s : Map.getInstance().stations){
				if(s.filiere == f){
					shortestPath = pathfinding.getShortestPath(this, s);
					for(Station test : shortestPath.getElements()){
						
						System.out.println(test);
					}
					if((shortestPath.getWeight()<minDistance || minDistance == -1) && shortestPath.getWeight()!=-1){
						minDistance = shortestPath.getWeight();
						tempStation = shortestPath.get(0);
					
					}
					
					
				}
			}
			nextStop.put(f, tempStation);
			
		}
		for(Filiere f : Filiere.values()){
{'fraction_non_alphanumeric': 0.1130917592051432, 'fraction_numerical': 0.011104617182933957, 'mean_word_length': 3.8753561253561255, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5707238', 'n_tokens_mistral': 2715, 'n_tokens_neox': 2302, 'n_words': 512}