mirror of
https://gitlab.com/klmp200/LO41.git
synced 2024-12-11 18:31:11 +00:00
Quick and dirty, surtout dirty…
This commit is contained in:
parent
d787d870f8
commit
4c29987de1
@ -20,13 +20,14 @@ void * runnable_ElevatorBreaker(void * void_this){
|
||||
|
||||
AGENT_OPTIONS
|
||||
|
||||
while (data->is_active_passengers_left(data)){
|
||||
while (this->breaks < MAX_BREAKS && data->is_active_passengers_left(data)){
|
||||
usleep(900000);
|
||||
// One chance out of two to break something
|
||||
if ((rand() % 101) > 50) {
|
||||
selected_elevator = data->get_main_building(data)->elevators[rand() % ELEVATOR_NB];
|
||||
selected_elevator->damage(selected_elevator);
|
||||
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 *new_elevator_breaker = malloc_or_die(sizeof(ElevatorBreaker));
|
||||
new_elevator_breaker->thread_number = -1;
|
||||
new_elevator_breaker->breaks = 0;
|
||||
|
||||
LINK_ALL(ElevatorBreaker, new_elevator_breaker,
|
||||
set_thread_number,
|
||||
|
@ -5,10 +5,13 @@
|
||||
#ifndef LO41_ELEVATORBREAKER_H
|
||||
#define LO41_ELEVATORBREAKER_H
|
||||
|
||||
#define MAX_BREAKS 30
|
||||
|
||||
#include "../Objects.h"
|
||||
|
||||
typedef struct o_ElevatorBreaker {
|
||||
PRIVATE int thread_number;
|
||||
PRIVATE int breaks;
|
||||
|
||||
PUBLIC void * (*runnable)(void * void_this);
|
||||
PUBLIC void (*set_thread_number)(_THIS(ElevatorBreaker), int data);
|
||||
|
@ -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)));
|
||||
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);
|
||||
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
|
||||
data->main_building->go_to_floor(data->main_building, this->position, this->destination, passenger);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user