Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <allegro.h>
- #define DIM1 150
- #define LARGURA_JANELA 400
- #define ALTURA_JANELA 400
- int airport_presentation();
- void air_traffic_control();
- void menu_inicial();
- void list_airplanes_by_destination();
- void draw_runway(float x0, float y0, float x1, float y1, int marcas, int ponto, float largura, int cor)
- /*incompleta*/
- {
- int q;
- int xNovo1, yNovo1;
- largura=largura/2;
- if(x0==x1)
- { yNovo1=y0+ponto;
- line(screen, x0, y0, x0+30, y0-30, cor);}/*falta outra linha*/
- else
- { xNovo1=x0+ponto;
- line(screen, x0, y0, x0-30, y1+30, cor);}
- do
- {do {
- for (q=1; q<=marcas; q++)
- {
- circlefill(screen, x0, y0, largura, cor);
- }
- x0=x0+largura;
- y0=y0+largura;
- } while (x0<=x1 && y0<=y1);}
- while(!key[KEY_ESC]);
- allegro_exit();
- }
- typedef struct
- {
- int nome, o, w, s, par1, par2; /*sem route*/
- float alt1, alt2, x, y;
- char rate[3], sp1, sp2;
- } ARRIVAL[3];
- typedef struct
- {
- char from[20], to[20], operation [20];
- int spd, alt, x, y, heading, ref_spd, ref_alt, ref_heading;
- } PLANE;
- typedef struct
- {
- int nome, marks, alt1, alt2, spd1, spd2, par1, par2;
- float in, largura, x0, y0, x1, y1;
- char rate[3], color[10];
- } RUNWAY;
- int teste_cor (char cor[10])
- {
- int num;
- if (strcmp(cor,"red")==0)
- num = 12;
- else
- if (strcmp(cor,"orange")==0)
- num = 6;
- else
- if (strcmp(cor,"yellow")==0)
- num = 14;
- else
- if (strcmp(cor,"white")==0)
- num = 7;
- else
- if (strcmp(cor,"grey")==0)
- num = 8;
- else
- if (strcmp(cor,"purple")==0)
- num = 5;
- else
- if (strcmp(cor,"pink")==0)
- num = 13;
- else
- if (strcmp(cor,"green")==0)
- num = 10;
- else
- if (strcmp(cor,"blue")==0)
- num = 9;
- return num;
- }
- int convertM(int a)
- {
- return (a*400)/40;
- }
- /*
- void draw_gate(float x0,float y0,float x1,float y1, int c)
- {
- x0=convertM(x0);
- y0=convertM(y0);
- x1=convertM(x1);
- y1=convertM(y1);
- acquire_screen();
- rectfill(screen, x0, y0, x1, y1, c);
- release_screen();
- }*/
- void menu_inicial()
- {
- char s[DIM1];
- char opcao;
- do
- {
- printf("\n\n\t\tCONTROLO AEREO\n\n\t Select one of the following options:\n\n\t0-Exit\n\n\t 1-Airport presentation\n\n\t 2-Air Traffic Control\n\n\tOption: ");
- fgets(s,DIM1,stdin);
- if (s[1]=='\n')
- {
- opcao = s[0];
- switch (opcao)
- {
- case '0': exit (0); break;
- case '1': airport_presentation(); break;
- case '2': air_traffic_control(); break;
- default: printf ("Unknown option");
- }
- }
- else printf("Unknown option");
- }
- while (opcao!=0);
- return;
- }
- void air_traffic_control ()
- {
- char s2[DIM1];
- char opcao2;
- do
- {
- printf("\n\n\n\t\tMENU AIR TRAFFIC CONTROL\n\n\t 0 - Back to previous menu\n\n\t 1 - Load simulation state\n\n\t 2 -List airplanes by destination\n\n\t 3 - Add airplane\n\n\t 4 - Remove airplane\n\n\t 5 - Store simulation state\n\n\t 6 - Run ATC simulation\n\n\t Option: ");
- fgets(s2,DIM1,stdin);
- if (s2[1]=='\n')
- {
- opcao2 = s2[0];
- switch (opcao2)
- {
- case '0': menu_inicial(); break;
- case '2': list_airplanes_by_destination(); break;
- case '1':
- case '3':
- case '4':
- case '5':
- case '6': printf ("under construction"); break;
- default: printf ("Unknown option");
- }
- }
- else printf ("Unknown option");
- } while (opcao2!=0);
- return;
- }
- int airport_presentation()
- {
- int ret, cor_runway;
- int x,y,alt;
- char color[10], tipo[20];
- /*BITMAP *bpmap;*/
- FILE *fp;
- fp=fopen("airportpresentation.txt", "r");
- if(fp==NULL)
- {
- printf("ERRO NA ABERTURA DO FICHEIRO");
- menu_inicial();
- }
- fscanf(fp, "AIRPORT_SPACE %d %d %d %s", &x, &y, &alt, color);
- /*
- x=convertM(x);
- y=convertM(y);
- allegro_init();
- install_keyboard();
- printf("ok6");
- ret = set_gfx_mode(GFX_AUTODETECT_WINDOWED, x, y, 0, 0);
- if(ret != 0)
- {
- allegro_message("Graphic error - Exiting");
- return 1;
- }*/
- fscanf(fp, "\n\n%s", tipo);
- if ((strcmp(tipo, "RUNWAY")==0))
- do {
- RUNWAY * runway = (RUNWAY*) malloc(sizeof(RUNWAY));
- if ((runway)==NULL)
- printf("erroalocaçao");
- x=convertM(x);
- y=convertM(y);
- allegro_init();
- install_keyboard();
- ret = set_gfx_mode(GFX_AUTODETECT_WINDOWED, x, y, 0, 0);
- if(ret != 0)
- {
- allegro_message("Graphic error - Exiting");
- return 1;
- }
- fscanf(fp, "\n\nRUNWAY %d (%f, %f) (%f, %f) %f %s", runway->nome, runway->x0, runway->y0, runway->x1, runway->y1, runway->largura, runway->color);
- fscanf(fp, "\nMARKS_IN: %d %f", runway->marks, runway->in);
- fscanf(fp, "\nALTITUDES: %d %d", runway->alt1,runway->alt2);
- fscanf(fp, "\nSPEEDS: %d %d", runway->spd1, runway->spd2);
- fscanf(fp, "\nGENERATION_RATE: %s %d %d", runway->rate, runway->par1, runway->par2);
- runway->x0=convertM(runway->x0);
- runway->y0=convertM(runway->y0);
- runway->x1=convertM(runway->x1);
- runway->y1=convertM(runway->y1);
- runway->largura=convertM(runway->largura);
- runway->in=convertM(runway->in);
- cor_runway=teste_cor(runway->color);
- /* draw_runway(runway->x0, runway->y0, runway->x1, runway->y1, runway->marks, runway->in, runway->largura, cor_runway);
- printf ("ok5");
- }
- /* textprintf_ex(screen, font, 390, 390, 4, -1, "alt");*/
- /*fscanf(fp, "\n\nRUNWAY %d (%f, %f) (%f, %f) %d %s", &runway.nome, &runway.x0, &runway.y0, &runway.x1, &runway.y1, &runway.largura, runway.color);
- fscanf(fp, "\nMARKS_IN: %d %d", &runway.marks, &runway.in);
- fscanf(fp, "\nALTITUDES: %d %d", &runway.alt1, &runway.alt2);
- fscanf(fp, "\nSPEEDS: %d %d", &runway.spd1, &runway.spd2);
- fscanf(fp, "\nGENERATION_RATE: %s %d %d", runway.rate, &runway.par1, &runway.par2);
- runway.x0=convertM(runway.x0);
- runway.y0=convertM(runway.y0);
- runway.x1=convertM(runway.x1);
- runway.y1=convertM(runway.y1);
- runway.largura=convertM(runway.largura);
- runway.in=convertM(runway.in);
- cor_runway=teste_cor(runway.color);
- draw_runway(runway.x0, runway.y0, runway.x1, runway.y1, runway.marks, runway.in, runway.largura, cor_runway);*/
- free (runway);
- }
- while(!key[KEY_ESC]);
- allegro_exit();
- /*while(!key[KEY_ESC]);
- allegro_exit();*/
- return 0;
- }
- void list_airplanes_by_destination()
- {
- FILE *fp;
- int p, spd, alt, he, rspd, ralt, rh; /*plane, speed, altitude, heading, ref speed, ref altitude, ref heading*/
- char sf[20], st[20], so[20]; /*from to operation*/
- float x, y;
- int a=0, b=0, c=0, d=0, e=0, f=0, g=0, h=0, i=0;
- if ((fp=fopen("ficheiro.txt", "r"))==NULL)
- {
- printf("ERRO NA ABERTURA DO FICHEIRO");
- air_traffic_control();
- }
- do
- {
- fscanf(fp,"******************************\nPLANE: %d\nFROM: %s\nTO: %s\nOPERATION: %s\nX: %f\nY: %f\nSPD: %d\nALT: %d\nHEADING: %d\nREF_SPD: %d\nREF_ALT: %d\nREF_HEADING: %d\n", &p, sf, st, so, &x, &y, &spd, &alt, &he, &rspd, &ralt, &rh);
- if(alt>1000 && alt<2000)
- a++;
- if(alt>2000 && alt<3000)
- b++;
- if(alt>3000 && alt<4000)
- c++;
- if(alt>4000 && alt<5000)
- d++;
- if(alt>5000 && alt<6000)
- e++;
- if(alt>6000 && alt<7000)
- f++;
- if(alt>7000 && alt<8000)
- g++;
- if(alt>8000 && alt<9000)
- h++;
- if(alt>9000 && alt<10000)
- i++;
- }
- while (!feof(fp));
- printf("\n\tO número de aeronaves no intervalo 1000 a 2000 é %d.\n\n", a);
- printf("\tO número de aeronaves no intervalo 2000 a 3000 é %d.\n\n", b);
- printf("\tO número de aeronaves no intervalo 3000 a 4000 é %d.\n\n", c);
- printf("\tO número de aeronaves no intervalo 4000 a 5000 é %d.\n\n", d);
- printf("\tO número de aeronaves no intervalo 5000 a 6000 é %d.\n\n", e);
- printf("\tO número de aeronaves no intervalo 6000 a 7000 é %d.\n\n", f);
- printf("\tO número de aeronaves no intervalo 7000 a 8000 é %d.\n\n", g);
- printf("\tO número de aeronaves no intervalo 8000 a 9000 é %d.\n\n", h);
- printf("\tO número de aeronaves no intervalo 9000 a 10000 é %d.\n\n", i);
- return;
- }
- int main()
- {
- menu_inicial();
- return 0;
- }
Add Comment
Please, Sign In to add comment