Quick and dirty, surtout dirty…

This commit is contained in:
Antoine Bartuccio 2018-06-22 07:46:29 +02:00
parent d787d870f8
commit 4c29987de1
Signed by: klmp200
GPG Key ID: E7245548C53F904B
3 changed files with 8 additions and 1 deletions

View File

@ -20,13 +20,14 @@ void * runnable_ElevatorBreaker(void * void_this){
AGENT_OPTIONS AGENT_OPTIONS
while (data->is_active_passengers_left(data)){ while (this->breaks < MAX_BREAKS && data->is_active_passengers_left(data)){
usleep(900000); usleep(900000);
// One chance out of two to break something // One chance out of two to break something
if ((rand() % 101) > 50) { if ((rand() % 101) > 50) {
selected_elevator = data->get_main_building(data)->elevators[rand() % ELEVATOR_NB]; selected_elevator = data->get_main_building(data)->elevators[rand() % ELEVATOR_NB];
selected_elevator->damage(selected_elevator); selected_elevator->damage(selected_elevator);
printf("ALERTE : L'ascenseur %s est endommagé\n", selected_elevator->name); printf("ALERTE : L'ascenseur %s est endommagé\n", selected_elevator->name);
this->breaks++;
} }
} }
@ -37,6 +38,7 @@ void * runnable_ElevatorBreaker(void * void_this){
ElevatorBreaker *_init_ElevatorBreaker(){ ElevatorBreaker *_init_ElevatorBreaker(){
ElevatorBreaker *new_elevator_breaker = malloc_or_die(sizeof(ElevatorBreaker)); ElevatorBreaker *new_elevator_breaker = malloc_or_die(sizeof(ElevatorBreaker));
new_elevator_breaker->thread_number = -1; new_elevator_breaker->thread_number = -1;
new_elevator_breaker->breaks = 0;
LINK_ALL(ElevatorBreaker, new_elevator_breaker, LINK_ALL(ElevatorBreaker, new_elevator_breaker,
set_thread_number, set_thread_number,

View File

@ -5,10 +5,13 @@
#ifndef LO41_ELEVATORBREAKER_H #ifndef LO41_ELEVATORBREAKER_H
#define LO41_ELEVATORBREAKER_H #define LO41_ELEVATORBREAKER_H
#define MAX_BREAKS 30
#include "../Objects.h" #include "../Objects.h"
typedef struct o_ElevatorBreaker { typedef struct o_ElevatorBreaker {
PRIVATE int thread_number; PRIVATE int thread_number;
PRIVATE int breaks;
PUBLIC void * (*runnable)(void * void_this); PUBLIC void * (*runnable)(void * void_this);
PUBLIC void (*set_thread_number)(_THIS(ElevatorBreaker), int data); PUBLIC void (*set_thread_number)(_THIS(ElevatorBreaker), int data);

View File

@ -25,6 +25,8 @@ void * runnable_Visitor(void * void_this){
printf("Visiteur %s : J'apelle à l'interphone\nVisiteur %s : J'apprends que %s habite à l'étage %d\n", this->name, this->name, this->contact_name, (this->destination = data->use_call_box(data, this->contact_name))); printf("Visiteur %s : J'apelle à l'interphone\nVisiteur %s : J'apprends que %s habite à l'étage %d\n", this->name, this->name, this->contact_name, (this->destination = data->use_call_box(data, this->contact_name)));
if (this->destination == this->position) if (this->destination == this->position)
printf("Visiteur %s : pas besoin de prendre l'ascenseur pour cet étage, je vais y aller à pied\n", this->name); printf("Visiteur %s : pas besoin de prendre l'ascenseur pour cet étage, je vais y aller à pied\n", this->name);
else if (this->destination == -1)
printf("Visiteur %s : Je me suis trompé de bâtiment, %s n'habite pas ici.\n", this->name, this->contact_name);
else else
data->main_building->go_to_floor(data->main_building, this->position, this->destination, passenger); data->main_building->go_to_floor(data->main_building, this->position, this->destination, passenger);