1
0
mirror of https://gitlab.com/klmp200/LO41.git synced 2025-07-12 04:39:23 +00:00

Les ascenseurs sont intelligents... mais ils finissent pas trop leur travail quand même.

This commit is contained in:
Aethor
2018-06-21 18:22:02 +02:00
parent 479cbb6846
commit 12c4e1af19
2 changed files with 19 additions and 12 deletions

View File

@ -31,9 +31,9 @@ int get_next_call_Building(THIS(Building), int elevator_floor){
int next_target = -1;
for(i=0; i<FLOORS; i++){
if(waiting_floors[i] > 0){
if(abs(elevator_floor - waiting_floors[i]) < best_diff){
best_diff = abs(elevator_floor - waiting_floors[i]);
next_target = waiting_floors[i];
if(abs(elevator_floor - i) < best_diff){
best_diff = abs(elevator_floor - i);
next_target = i;
}
}
}
@ -198,13 +198,12 @@ void go_to_floor_Building(THIS(Building), int origin, int destination, Passenger
if (origin < 0 || origin >= FLOORS) {CRASH("You are trying to start from a non existing floor\n");}
if (destination < 0 || destination >= FLOORS) {CRASH("You are trying to reach a non existing floor\n");}
/*if(!this->waiting_passengers->contains(this->waiting_passengers, (void*) passenger, passenger->compare)){
this->waiting_passengers->insert_tail(this->waiting_passengers, (void*) passenger, sizeof(Passenger));//todo : check if inside list
}*/
this->waiting_floors[origin]++;//on ajoute à la liste des attentes
pthread_cond_wait(this->condition_floors[origin], this->mutex_cond_get_inside_elevator);
elevator_number = this->get_inside_elevator(this, origin, passenger);
if (elevator_number != -1){ //passenger accepted in elevator
this->waiting_floors[origin]--;//on retire de la liste des attentes
if (passenger->type == RESIDENT)
printf("Le résident %s rentre dans l'ascenseur %s depuis l'étage %d\n", passenger->get_name(passenger),
this->elevators[elevator_number]->name, origin);