Guest User

Untitled

a guest
Apr 25th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.67 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <allegro.h>
  5.  
  6.  
  7.  
  8. #define DIM1 150
  9. #define LARGURA_JANELA 400
  10. #define ALTURA_JANELA 400
  11.  
  12.  
  13.  
  14. int airport_presentation();
  15. void air_traffic_control();
  16. void menu_inicial();
  17. void list_airplanes_by_destination();
  18.  
  19. void draw_runway(float x0, float y0, float x1, float y1, int marcas, int ponto, float largura, int cor)
  20. /*incompleta*/
  21. {
  22. int q;
  23. int xNovo1, yNovo1;
  24. largura=largura/2;
  25.  
  26. if(x0==x1)
  27. { yNovo1=y0+ponto;
  28.  
  29. line(screen, x0, y0, x0+30, y0-30, cor);}/*falta outra linha*/
  30.  
  31. else
  32. { xNovo1=x0+ponto;
  33. line(screen, x0, y0, x0-30, y1+30, cor);}
  34.  
  35.  
  36. do
  37. {do {
  38.  
  39. for (q=1; q<=marcas; q++)
  40. {
  41. circlefill(screen, x0, y0, largura, cor);
  42. }
  43.  
  44. x0=x0+largura;
  45. y0=y0+largura;
  46.  
  47. } while (x0<=x1 && y0<=y1);}
  48. while(!key[KEY_ESC]);
  49. allegro_exit();
  50.  
  51.  
  52. }
  53.  
  54.  
  55. typedef struct
  56. {
  57. int nome, o, w, s, par1, par2; /*sem route*/
  58. float alt1, alt2, x, y;
  59. char rate[3], sp1, sp2;
  60. } ARRIVAL[3];
  61.  
  62. typedef struct
  63. {
  64. char from[20], to[20], operation [20];
  65. int spd, alt, x, y, heading, ref_spd, ref_alt, ref_heading;
  66. } PLANE;
  67.  
  68. typedef struct
  69. {
  70. int nome, marks, alt1, alt2, spd1, spd2, par1, par2;
  71. float in, largura, x0, y0, x1, y1;
  72. char rate[3], color[10];
  73. } RUNWAY;
  74.  
  75.  
  76. int teste_cor (char cor[10])
  77. {
  78. int num;
  79.  
  80. if (strcmp(cor,"red")==0)
  81. num = 12;
  82. else
  83. if (strcmp(cor,"orange")==0)
  84. num = 6;
  85. else
  86. if (strcmp(cor,"yellow")==0)
  87. num = 14;
  88. else
  89. if (strcmp(cor,"white")==0)
  90. num = 7;
  91. else
  92. if (strcmp(cor,"grey")==0)
  93. num = 8;
  94. else
  95. if (strcmp(cor,"purple")==0)
  96. num = 5;
  97. else
  98. if (strcmp(cor,"pink")==0)
  99. num = 13;
  100. else
  101. if (strcmp(cor,"green")==0)
  102. num = 10;
  103. else
  104. if (strcmp(cor,"blue")==0)
  105. num = 9;
  106.  
  107. return num;
  108. }
  109.  
  110.  
  111. int convertM(int a)
  112.  
  113. {
  114. return (a*400)/40;
  115. }
  116.  
  117.  
  118. /*
  119. void draw_gate(float x0,float y0,float x1,float y1, int c)
  120.  
  121. {
  122. x0=convertM(x0);
  123. y0=convertM(y0);
  124. x1=convertM(x1);
  125. y1=convertM(y1);
  126.  
  127. acquire_screen();
  128. rectfill(screen, x0, y0, x1, y1, c);
  129. release_screen();
  130.  
  131. }*/
  132.  
  133.  
  134.  
  135. void menu_inicial()
  136.  
  137. {
  138. char s[DIM1];
  139. char opcao;
  140.  
  141. do
  142. {
  143.  
  144. 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: ");
  145.  
  146.  
  147. fgets(s,DIM1,stdin);
  148.  
  149. if (s[1]=='\n')
  150.  
  151. {
  152.  
  153. opcao = s[0];
  154.  
  155. switch (opcao)
  156. {
  157. case '0': exit (0); break;
  158. case '1': airport_presentation(); break;
  159. case '2': air_traffic_control(); break;
  160. default: printf ("Unknown option");
  161. }
  162.  
  163.  
  164. }
  165.  
  166. else printf("Unknown option");
  167.  
  168.  
  169. }
  170.  
  171. while (opcao!=0);
  172.  
  173.  
  174. return;
  175.  
  176. }
  177.  
  178.  
  179.  
  180.  
  181. void air_traffic_control ()
  182.  
  183. {
  184. char s2[DIM1];
  185. char opcao2;
  186.  
  187. do
  188. {
  189.  
  190. 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: ");
  191.  
  192. fgets(s2,DIM1,stdin);
  193.  
  194. if (s2[1]=='\n')
  195.  
  196. {
  197.  
  198. opcao2 = s2[0];
  199.  
  200. switch (opcao2)
  201. {
  202. case '0': menu_inicial(); break;
  203. case '2': list_airplanes_by_destination(); break;
  204. case '1':
  205. case '3':
  206. case '4':
  207. case '5':
  208. case '6': printf ("under construction"); break;
  209. default: printf ("Unknown option");
  210.  
  211. }
  212. }
  213.  
  214. else printf ("Unknown option");
  215.  
  216. } while (opcao2!=0);
  217.  
  218. return;
  219.  
  220. }
  221.  
  222.  
  223.  
  224. int airport_presentation()
  225.  
  226. {
  227. int ret, cor_runway;
  228. int x,y,alt;
  229. char color[10], tipo[20];
  230. /*BITMAP *bpmap;*/
  231. FILE *fp;
  232.  
  233.  
  234.  
  235.  
  236. fp=fopen("airportpresentation.txt", "r");
  237.  
  238. if(fp==NULL)
  239. {
  240. printf("ERRO NA ABERTURA DO FICHEIRO");
  241. menu_inicial();
  242. }
  243.  
  244.  
  245. fscanf(fp, "AIRPORT_SPACE %d %d %d %s", &x, &y, &alt, color);
  246. /*
  247. x=convertM(x);
  248. y=convertM(y);
  249.  
  250. allegro_init();
  251.  
  252. install_keyboard();
  253. printf("ok6");
  254. ret = set_gfx_mode(GFX_AUTODETECT_WINDOWED, x, y, 0, 0);
  255.  
  256. if(ret != 0)
  257. {
  258. allegro_message("Graphic error - Exiting");
  259. return 1;
  260. }*/
  261.  
  262. fscanf(fp, "\n\n%s", tipo);
  263.  
  264.  
  265. if ((strcmp(tipo, "RUNWAY")==0))
  266.  
  267. do {
  268.  
  269. RUNWAY * runway = (RUNWAY*) malloc(sizeof(RUNWAY));
  270.  
  271.  
  272.  
  273. if ((runway)==NULL)
  274. printf("erroalocaçao");
  275.  
  276. x=convertM(x);
  277. y=convertM(y);
  278.  
  279. allegro_init();
  280.  
  281. install_keyboard();
  282.  
  283. ret = set_gfx_mode(GFX_AUTODETECT_WINDOWED, x, y, 0, 0);
  284.  
  285. if(ret != 0)
  286. {
  287. allegro_message("Graphic error - Exiting");
  288. return 1;
  289. }
  290.  
  291.  
  292.  
  293. 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);
  294.  
  295. fscanf(fp, "\nMARKS_IN: %d %f", runway->marks, runway->in);
  296. fscanf(fp, "\nALTITUDES: %d %d", runway->alt1,runway->alt2);
  297. fscanf(fp, "\nSPEEDS: %d %d", runway->spd1, runway->spd2);
  298. fscanf(fp, "\nGENERATION_RATE: %s %d %d", runway->rate, runway->par1, runway->par2);
  299.  
  300.  
  301. runway->x0=convertM(runway->x0);
  302. runway->y0=convertM(runway->y0);
  303. runway->x1=convertM(runway->x1);
  304. runway->y1=convertM(runway->y1);
  305. runway->largura=convertM(runway->largura);
  306. runway->in=convertM(runway->in);
  307.  
  308.  
  309. cor_runway=teste_cor(runway->color);
  310.  
  311.  
  312.  
  313. /* draw_runway(runway->x0, runway->y0, runway->x1, runway->y1, runway->marks, runway->in, runway->largura, cor_runway);
  314. printf ("ok5");
  315. }
  316.  
  317.  
  318. /* textprintf_ex(screen, font, 390, 390, 4, -1, "alt");*/
  319.  
  320. /*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);
  321.  
  322. fscanf(fp, "\nMARKS_IN: %d %d", &runway.marks, &runway.in);
  323. fscanf(fp, "\nALTITUDES: %d %d", &runway.alt1, &runway.alt2);
  324. fscanf(fp, "\nSPEEDS: %d %d", &runway.spd1, &runway.spd2);
  325. fscanf(fp, "\nGENERATION_RATE: %s %d %d", runway.rate, &runway.par1, &runway.par2);
  326.  
  327. runway.x0=convertM(runway.x0);
  328. runway.y0=convertM(runway.y0);
  329. runway.x1=convertM(runway.x1);
  330. runway.y1=convertM(runway.y1);
  331. runway.largura=convertM(runway.largura);
  332. runway.in=convertM(runway.in);
  333.  
  334. cor_runway=teste_cor(runway.color);
  335.  
  336.  
  337. draw_runway(runway.x0, runway.y0, runway.x1, runway.y1, runway.marks, runway.in, runway.largura, cor_runway);*/
  338.  
  339.  
  340. free (runway);
  341.  
  342. }
  343.  
  344. while(!key[KEY_ESC]);
  345. allegro_exit();
  346.  
  347.  
  348.  
  349.  
  350. /*while(!key[KEY_ESC]);
  351. allegro_exit();*/
  352. return 0;
  353.  
  354. }
  355.  
  356.  
  357.  
  358. void list_airplanes_by_destination()
  359.  
  360. {
  361. FILE *fp;
  362. int p, spd, alt, he, rspd, ralt, rh; /*plane, speed, altitude, heading, ref speed, ref altitude, ref heading*/
  363.  
  364.  
  365. char sf[20], st[20], so[20]; /*from to operation*/
  366. float x, y;
  367. int a=0, b=0, c=0, d=0, e=0, f=0, g=0, h=0, i=0;
  368.  
  369.  
  370. if ((fp=fopen("ficheiro.txt", "r"))==NULL)
  371. {
  372. printf("ERRO NA ABERTURA DO FICHEIRO");
  373. air_traffic_control();
  374. }
  375.  
  376.  
  377. do
  378.  
  379. {
  380.  
  381. 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);
  382.  
  383.  
  384. if(alt>1000 && alt<2000)
  385. a++;
  386.  
  387. if(alt>2000 && alt<3000)
  388. b++;
  389.  
  390. if(alt>3000 && alt<4000)
  391. c++;
  392.  
  393. if(alt>4000 && alt<5000)
  394. d++;
  395.  
  396. if(alt>5000 && alt<6000)
  397. e++;
  398.  
  399. if(alt>6000 && alt<7000)
  400. f++;
  401.  
  402. if(alt>7000 && alt<8000)
  403. g++;
  404.  
  405. if(alt>8000 && alt<9000)
  406. h++;
  407.  
  408. if(alt>9000 && alt<10000)
  409. i++;
  410.  
  411.  
  412. }
  413. while (!feof(fp));
  414.  
  415. printf("\n\tO número de aeronaves no intervalo 1000 a 2000 é %d.\n\n", a);
  416. printf("\tO número de aeronaves no intervalo 2000 a 3000 é %d.\n\n", b);
  417. printf("\tO número de aeronaves no intervalo 3000 a 4000 é %d.\n\n", c);
  418. printf("\tO número de aeronaves no intervalo 4000 a 5000 é %d.\n\n", d);
  419. printf("\tO número de aeronaves no intervalo 5000 a 6000 é %d.\n\n", e);
  420. printf("\tO número de aeronaves no intervalo 6000 a 7000 é %d.\n\n", f);
  421. printf("\tO número de aeronaves no intervalo 7000 a 8000 é %d.\n\n", g);
  422. printf("\tO número de aeronaves no intervalo 8000 a 9000 é %d.\n\n", h);
  423. printf("\tO número de aeronaves no intervalo 9000 a 10000 é %d.\n\n", i);
  424.  
  425.  
  426. return;
  427. }
  428.  
  429.  
  430.  
  431. int main()
  432.  
  433. {
  434.  
  435. menu_inicial();
  436.  
  437. return 0;
  438. }
Add Comment
Please, Sign In to add comment