Fly_Simulator/Sources/src/main.c

386 lines
12 KiB
C

//-----
// Nom du projet : Fly Simulator
// Version : - dev -
// Dernière modification le : 23 juillet 2019
//-----
#include <gint/display.h>
#include <gint/keyboard.h>
#include <gint/std/string.h>
#include <gint/std/stdio.h>
#define C_RED 0xf800
#define C_GREEN 0x07e0
#define C_BLUE 0x001f
//communication : gère les communications entre la tour et l'avion
void communication (int *com_id, int *id, const int langue);
//display_comm : affiche les communications
void display_comm (char *msg_1,char *msg_2,char *msg_3, const int *joueur);
//fill_char : initialise une chaine avec un nombre de caractères répétés 'n' fois
char *fill_char(char *dest, const char *src, unsigned int debut, unsigned int fin);
int main (void)
{
int com_id = 1, id = 0, langue = 0;// variables des communications
int key = 0;//variables diverses
dclear(C_WHITE);
dtext(1, 1, "Choix de la langue", C_RED, C_NONE);
dtext(1, 12, " 1. Francais", C_BLUE, C_NONE);
dtext(1, 23, " 2. Anglais", C_BLACK, C_NONE);
dupdate();
while (langue == 0)
{
key = getkey().key;
if (key == KEY_1) langue = 1;
if (key == KEY_2) langue = 2;
}
while(com_id <= 26)
{
communication(&com_id, &id, langue);
key = getkey().key;
dupdate();
if(key == KEY_EXIT) return 0;
}
getkey();
return 0;
}
void communication(int *com_id, int *id, const int langue)
{
//faire un choix de la langue Français / Anglais
const char *avion = "Cessna 172", *immat = "F-GUXF", *immat_courte = "F-XF", *aipt_depart = "Caen", *aipt_arrivee = "Le Havre", *freq_cont = "117.15", *freq_arrivee = "122.80", *passagers = "4";//données de l'avion et de son trajet
char msg_1[70], msg_2[70], msg_3[70];
fill_char(msg_1, " ", 0, 70);
fill_char(msg_2, " ", 0, 70);
fill_char(msg_3, " ", 0, 70);
if (langue == 1)
{
switch (*com_id)
{
case 1:
*id = 1;
sprintf(msg_1, "%s tour, %s. Bonjour.", aipt_depart, immat);
break;
case 2:
*id = 0;
sprintf(msg_1, "%s, %s bonjour.", immat, aipt_depart);
break;
case 3:
*id = 1;
sprintf(msg_1, "%s %s. %s passagers a bord. Demandons", immat, avion, passagers);
sprintf(msg_2, "vol vers %s.", aipt_arrivee);
break;
case 4:
*id = 0;
sprintf(msg_1, "%s vol autorise. Rappelez pret au depart.", immat_courte);
break;
case 5:
*id = 1;
sprintf(msg_1, "Rappelons pret au depart, %s.", immat_courte);
break;
case 6:
*id = 1;
sprintf(msg_1, "%s, pret au depart.", immat_courte);
break;
case 7:
*id = 0;
sprintf(msg_1, "%s, autorise decollage.", immat_courte);
break;
case 8:
*id = 1;
sprintf(msg_1, "Autorise decollage, %s.", immat_courte);
break;
case 9:
*id = 0;
sprintf(msg_1, "%s, vous quittez mon espace. Services radar", immat_courte);
sprintf(msg_2, "et radio termines. Informations de vol avec");
sprintf(msg_3, "Controle, %s. Au revoir.", freq_cont);
break;
case 10:
*id = 1;
sprintf(msg_1, "Controle, %s. Bonne journee, %s.", freq_cont, immat_courte);
break;
case 11:
*id = 1;
sprintf(msg_1, "Controle %s. Bonjour.", immat);
break;
case 12:
*id = 0;
sprintf(msg_1, "%s Controle, bienvenu.", immat_courte);
break;
case 13:
*id = 1;
sprintf(msg_1, "%s %s. %s passagers a bord. Sortie de", immat, avion, passagers);
sprintf(msg_2, "%s vers %s.", aipt_depart, aipt_arrivee);
break;
case 14:
*id = 0;
sprintf(msg_1, "%s, identifie radar.", immat_courte);
break;
case 15:
*id = 0;
sprintf(msg_1, "%s, vous quittez mon espace. Contactez", immat_courte);
sprintf(msg_2, "%s, %s. Bon vol.", aipt_arrivee, freq_arrivee);
break;
case 16:
*id = 1;
sprintf(msg_1, "%s %s. Au revoir, %s.", aipt_arrivee, freq_arrivee, immat_courte);
break;
case 17:
*id = 1;
sprintf(msg_1, "%s tour, %s. Bonjour.", aipt_arrivee, immat);
break;
case 18:
*id = 0;
sprintf(msg_1, "%s, %s, a l'ecoute.", immat_courte, aipt_arrivee);
break;
case 19:
*id = 1;
sprintf(msg_1, "%s %s. %s passagers a bord. Demandons", immat, avion, passagers);
sprintf(msg_2, "consignes pour atterrissage sur %s.", aipt_arrivee);
break;
case 20:
*id = 0;
sprintf(msg_1, "%s, commencez votre approche.", immat_courte);
break;
case 21:
*id = 1;
sprintf(msg_1, "Commencons notre approche, %s.", immat_courte);
break;
case 22:
*id = 1;
sprintf(msg_1, "%s en finale, demandons autorisation", immat_courte);
sprintf(msg_2, "d'atterrissage.");
break;
case 23:
*id = 0;
sprintf(msg_1, "%s, autorise atterrissage. Rappelez au sol.", immat_courte);
break;
case 24:
*id = 1;
sprintf(msg_1, "Autorise atterrissage, rappelons au sol, %s.", immat_courte);
break;
case 25:
*id = 1;
sprintf(msg_1, "%s, au sol, pour quitter. Merci.", immat_courte);
break;
case 26:
*id = 0;
sprintf(msg_1, "%s, quittez la frequence a bientot.", immat_courte);
break;
}
}
else
{
switch (*com_id)
{
case 1:
*id = 1;
sprintf(msg_1, "%s tower, %s. Good morning.", aipt_depart, immat);
break;
case 2:
*id = 0;
sprintf(msg_1, "%s, %s Hello.", immat, aipt_depart);
break;
case 3:
*id = 1;
sprintf(msg_1, "%s %s. %s passengers on board. Request", immat, avion, passagers);
sprintf(msg_2, "flight to %s.", aipt_arrivee);
break;
case 4:
*id = 0;
sprintf(msg_1, "%s authorized flight. Call back clear to take off.", immat_courte);
break;
case 5:
*id = 1;
sprintf(msg_1, "Call back clear to take off, %s.", immat_courte);
break;
case 6:
*id = 1;
sprintf(msg_1, "%s, clear for take off.", immat_courte);
break;
case 7:
*id = 0;
sprintf(msg_1, "%s, authorized take off.", immat_courte);
break;
case 8:
*id = 1;
sprintf(msg_1, "Authorized take off, %s.", immat_courte);
break;
case 9:
*id = 0;
sprintf(msg_1, "%s, you leave my airpace. Services radar", immat_courte);
sprintf(msg_2, "and radio terminated. Informations of flight");
sprintf(msg_3, "with Controle, %s. Bye.", freq_cont);
break;
case 10:
*id = 1;
sprintf(msg_1, "Controle, %s. See you, %s.", freq_cont, immat_courte);
break;
case 11:
*id = 1;
sprintf(msg_1, "Controle %s. Hello.", immat);
break;
case 12:
*id = 0;
sprintf(msg_1, "%s Controle, welcome.", immat_courte);
break;
case 13:
*id = 1;
sprintf(msg_1, "%s %s. %s passengers on board. Exit", immat, avion, passagers);
sprintf(msg_2, "%s towards %s.", aipt_depart, aipt_arrivee);
break;
case 14:
*id = 0;
sprintf(msg_1, "%s, identify radar.", immat_courte);
break;
case 15:
*id = 0;
sprintf(msg_1, "%s, you leave my airspace. Contact", immat_courte);
sprintf(msg_2, "%s, %s. Have a good flight.", aipt_arrivee, freq_arrivee);
break;
case 16:
*id = 1;
sprintf(msg_1, "%s %s. Good bye, %s.", aipt_arrivee, freq_arrivee, immat_courte);
break;
case 17:
*id = 1;
sprintf(msg_1, "%s tower, %s. Hy.", aipt_arrivee, immat);
break;
case 18:
*id = 0;
sprintf(msg_1, "%s, %s, listen.", immat_courte, aipt_arrivee);
break;
case 19:
*id = 1;
sprintf(msg_1, "%s %s. %s passengers on board. Request", immat, avion, passagers);
sprintf(msg_2, "instructions for landing on %s.", aipt_arrivee);
break;
case 20:
*id = 0;
sprintf(msg_1, "%s, starts your approach.", immat_courte);
break;
case 21:
*id = 1;
sprintf(msg_1, "We start our approach, %s.", immat_courte);
break;
case 22:
*id = 1;
sprintf(msg_1, "%s on final, request clearance", immat_courte);
sprintf(msg_2, "to landing.");
break;
case 23:
*id = 0;
sprintf(msg_1, "%s, authorized landing. Call back on ground.", immat_courte);
break;
case 24:
*id = 1;
sprintf(msg_1, "Authorized landing, call back on ground, %s.", immat_courte);
break;
case 25:
*id = 1;
sprintf(msg_1, "%s, on ground for leave. Thanks.", immat_courte);
break;
case 26:
*id = 0;
sprintf(msg_1, "%s, leave frequence, see you.", immat_courte);
break;
}
}
display_comm(msg_1, msg_2, msg_3, &(*id));
*com_id += 1;
}
void display_comm (char *msg_1,char *msg_2, char *msg_3, const int *joueur)
{
fill_char(msg_1, " ", strlen(msg_1), 70);
fill_char(msg_2, " ", strlen(msg_2), 70);
fill_char(msg_3, " ", strlen(msg_3), 70);
if (*joueur == 1){
dtext(1, 1, msg_1, C_BLUE, C_WHITE);
dtext(1, 12, msg_2, C_BLUE, C_WHITE);
dtext(1, 23, msg_3, C_BLUE, C_WHITE);
}
else{
dtext(1, 1, msg_1, C_BLACK, C_WHITE);
dtext(1, 12, msg_2, C_BLACK, C_WHITE);
dtext(1, 23, msg_3, C_BLACK, C_WHITE);
}
}
char *fill_char(char *dest, const char *src, unsigned int debut, unsigned int fin)
{
unsigned int i;
for (i = debut ; i < fin ; i++)
{
dest[i] = src[0];
}
dest[fin] = '\0';
return dest;
}