DISPLAY.CPP 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525
  1. /******************************************************************************
  2. *******************************************************************************
  3. Display output routines...
  4. ******************************************************************************
  5. *****************************************************************************/
  6. #include "global.h"
  7. #include "defines.h"
  8. #include "externs.h"
  9. #include "mouse.h"
  10. #include "time.h"
  11. #include "3deng.h"
  12. extern int scale;
  13. extern char camera;
  14. extern int play_cam;
  15. extern buff_info main_buff,vidi_buff;
  16. extern plyrdat pos[];
  17. /*****************************************************************************
  18. *****************************************************************************/
  19. /*****************************************************************************
  20. *****************************************************************************/
  21. void init_pitch_sprites()
  22. {
  23. pitch_sprs=0;
  24. spr_coord_tab[0]=0;
  25. }
  26. /*****************************************************************************
  27. *****************************************************************************/
  28. void add_pitch_sprite(short x,short y,short z,short ref)
  29. {
  30. // Set up real 3d sprite...
  31. spr_coord_tab[0]+=1;
  32. spr_coord_tab[3*pitch_sprs+1]=x;
  33. spr_coord_tab[3*pitch_sprs+2]=z;
  34. spr_coord_tab[3*pitch_sprs+3]=-y;
  35. spr_ref_tab[pitch_sprs++]=ref;
  36. }
  37. /******************************************************************************
  38. *****************************************************************************/
  39. void grid_map()
  40. {
  41. int c=_getcolor();
  42. int g=_getplotaction();
  43. _setcolor(2);
  44. _setplotaction(_GXOR);
  45. float step=(320.2)/7;
  46. float step2=step*224/320;
  47. float x=0+(step/2);
  48. float x2=48+(step2/2);
  49. for (int i=1; i<8; i++, x+=step, x2+=step2 )
  50. {
  51. _moveto((int)x,131);
  52. _lineto((int)x2,32);
  53. }
  54. step=100/3;
  55. float lstep=48/3;
  56. x=32+(step/2);
  57. float lx=48-(lstep/2);
  58. for (i=1; i<4; i++, x+=step, lx-=lstep )
  59. {
  60. _moveto(lx,(int)x);
  61. _lineto(272+(47-lx),(int)x);
  62. }
  63. _setcolor(c);
  64. _setplotaction(g);
  65. }
  66. /******************************************************************************
  67. ******************************************************************************/
  68. void line_border(int x,int y,int wid,int hgt,int col)
  69. {
  70. int c=_getcolor();
  71. _moveto(x,y);
  72. _setcolor(col);
  73. _lineto(x+wid-1,y);
  74. _lineto(x+wid-1,y+hgt-1);
  75. _lineto(x,y+hgt-1);
  76. _lineto(x,y);
  77. _setcolor(c);
  78. }
  79. /******************************************************************************
  80. *****************************************************************************/
  81. void draw_buttons()
  82. {
  83. int x,y,w;
  84. char st[10];
  85. for (int i=0; i<max_butts; i++)
  86. {
  87. x=us_buttons[i].x;
  88. y=us_buttons[i].y;
  89. w=us_buttons[i].w;
  90. strcpy(st,us_buttons[i].s);
  91. _moveto(x,y);
  92. _outgtext(st);
  93. line_border(x-4,y-4,w*8+8,16,1);
  94. }
  95. }
  96. /******************************************************************************
  97. *****************************************************************************/
  98. void light_button(int b)
  99. {
  100. int x,y,w,c;
  101. c=_getcolor();
  102. char st[10];
  103. x=us_buttons[b].x;
  104. y=us_buttons[b].y;
  105. w=us_buttons[b].w;
  106. strcpy(st,us_buttons[b].s);
  107. _setcolor(7);
  108. _moveto(x,y);
  109. HideMouse();
  110. _outgtext(st);
  111. _setcolor(c);
  112. ShowMouse();
  113. button_lit=b+1;
  114. }
  115. /******************************************************************************
  116. *****************************************************************************/
  117. void unlight_button(int b)
  118. {
  119. int x,y,w;
  120. char st[10];
  121. x=us_buttons[b].x;
  122. y=us_buttons[b].y;
  123. w=us_buttons[b].w;
  124. strcpy(st,us_buttons[b].s);
  125. _moveto(x,y);
  126. HideMouse();
  127. _outgtext(st);
  128. ShowMouse();
  129. if (button_lit==b+1)
  130. button_lit=0; //no other button lit!
  131. }
  132. /******************************************************************************
  133. *****************************************************************************/
  134. void conv_xypitch(float x, float y, int *screen_x, int *screen_y)
  135. {
  136. float x2,xoff;
  137. x2=x;
  138. x=-(x-halfway_line);
  139. xoff=scr_pinch*(((float)pitch_wid-y)/(50.0*16))*x/(40.0*16.0);
  140. x2=(x2/4)+xoff;
  141. *screen_x=x2;
  142. *screen_y=(y/8);
  143. }
  144. /******************************************************************************
  145. ****************************************************************************/
  146. void pitch_markings()
  147. {
  148. int g=_getplotaction();
  149. int c=_getcolor();
  150. int x,y;
  151. _setcolor(7);
  152. // Left Goal
  153. conv_xypitch(0,357,&x,&y);
  154. _moveto(x,y+32);
  155. _lineto(x,y+32-4);
  156. _moveto(x,y+32);
  157. conv_xypitch(-28,357,&x,&y);
  158. _lineto(x,y+32);
  159. _lineto(x,y+32-4);
  160. _moveto(x,y+32);
  161. conv_xypitch(-28,443,&x,&y);
  162. _lineto(x,y+32);
  163. _lineto(x,y+32-4);
  164. _moveto(x,y+32);
  165. conv_xypitch(0,443,&x,&y);
  166. _lineto(x,y+32);
  167. _lineto(x,y+32-4);
  168. conv_xypitch(0,357,&x,&y);
  169. _lineto(x,y+32-4);
  170. conv_xypitch(-28,357,&x,&y);
  171. _lineto(x,y+32-4);
  172. conv_xypitch(-28,443,&x,&y);
  173. _lineto(x,y+32-4);
  174. conv_xypitch(0,443,&x,&y);
  175. _lineto(x,y+32-4);
  176. // Right Goal
  177. conv_xypitch(pitch_len,357,&x,&y);
  178. _moveto(x,y+32);
  179. _lineto(x,y+32-4);
  180. _moveto(x,y+32);
  181. conv_xypitch(pitch_len+28,357,&x,&y);
  182. _lineto(x,y+32);
  183. _lineto(x,y+32-4);
  184. _moveto(x,y+32);
  185. conv_xypitch(pitch_len+28,443,&x,&y);
  186. _lineto(x,y+32);
  187. _lineto(x,y+32-4);
  188. _moveto(x,y+32);
  189. conv_xypitch(pitch_len,443,&x,&y);
  190. _lineto(x,y+32);
  191. _lineto(x,y+32-4);
  192. conv_xypitch(pitch_len,357,&x,&y);
  193. _lineto(x,y+32-4);
  194. conv_xypitch(pitch_len+28,357,&x,&y);
  195. _lineto(x,y+32-4);
  196. conv_xypitch(pitch_len+28,443,&x,&y);
  197. _lineto(x,y+32-4);
  198. conv_xypitch(pitch_len,443,&x,&y);
  199. _lineto(x,y+32-4);
  200. _setcolor(1);
  201. // Left Six Yard Box
  202. conv_xypitch(0,293,&x,&y);
  203. _moveto(x,y+32);
  204. conv_xypitch(6.0*prat,293,&x,&y);
  205. _lineto(x,y+32);
  206. conv_xypitch(6.0*prat,507,&x,&y);
  207. _lineto(x,y+32);
  208. conv_xypitch(0,507,&x,&y);
  209. _lineto(x,y+32);
  210. // Right Six Yard Box
  211. conv_xypitch(80*16,293,&x,&y);
  212. _moveto(x,y+32);
  213. conv_xypitch(80*16-(6.0*prat),293,&x,&y);
  214. _lineto(x,y+32);
  215. conv_xypitch(80*16-(6.0*prat),507,&x,&y);
  216. _lineto(x,y+32);
  217. conv_xypitch(80*16,507,&x,&y);
  218. _lineto(x,y+32);
  219. // Left 18 Yard Box
  220. conv_xypitch(0,208,&x,&y);
  221. _moveto(x,y+32);
  222. conv_xypitch(18.0*prat,208,&x,&y);
  223. _lineto(x,y+32);
  224. conv_xypitch(18.0*prat,592,&x,&y);
  225. _lineto(x,y+32);
  226. conv_xypitch(0,592,&x,&y);
  227. _lineto(x,y+32);
  228. // Right 18 Yard Box
  229. conv_xypitch(80*16,208,&x,&y);
  230. _moveto(x,y+32);
  231. conv_xypitch(80*16-(18.0*prat),208,&x,&y);
  232. _lineto(x,y+32);
  233. conv_xypitch(80*16-(18.0*prat),592,&x,&y);
  234. _lineto(x,y+32);
  235. conv_xypitch(80*16,592,&x,&y);
  236. _lineto(x,y+32);
  237. // Centre circle
  238. _ellipse(_GBORDER,160-13,82-13,160+13,82+13);
  239. _setcolor(c);
  240. _setplotaction(g);
  241. }
  242. /******************************************************************************
  243. ****************************************************************************/
  244. void draw_pitch()
  245. {
  246. _setcolor(0);
  247. _lineto(48,32);
  248. _setcolor(1);
  249. _lineto(48+112+111,32);
  250. _lineto(319,131);
  251. _lineto(0,131);
  252. _lineto(48,32);
  253. _lineto(160,32);
  254. _lineto(160,131);
  255. }
  256. /******************************************************************************
  257. *****************************************************************************/
  258. void pitch_plot(int x,int y,int z,char c,char a) //Place screen coords on plot buffer.
  259. {
  260. if (plot_buffer) //Choose Buffer.
  261. {
  262. scr_a[plot_cnta][0]=x;
  263. scr_a[plot_cnta][1]=y-(z/8);
  264. scr_a[plot_cnta][2]=c;
  265. scr_a[plot_cnta++][3]=a;
  266. }
  267. else
  268. {
  269. scr_b[plot_cntb][0]=x;
  270. scr_b[plot_cntb][1]=y-(z/8);
  271. scr_b[plot_cntb][2]=c;
  272. scr_b[plot_cntb++][3]=a;
  273. }
  274. }
  275. /******************************************************************************
  276. *****************************************************************************/
  277. void draw_buffer()
  278. {
  279. char pn[3]=" ";
  280. for (int coords=1; (plot_buffer) ? coords<plot_cnta : coords<plot_cntb;
  281. coords++)
  282. {
  283. if (plot_buffer) //Choose Buffer.
  284. {
  285. if (scr_a[coords][3]==0)
  286. {
  287. _setcolor(scr_a[coords][2]);
  288. _setpixel(scr_a[coords][0],scr_a[coords][1]);
  289. }
  290. else
  291. {
  292. _setcolor(scr_a[coords][2]);
  293. _moveto(scr_a[coords][0]-3,scr_a[coords][1]-3);
  294. sprintf(pn,"%d",scr_a[coords][3]);
  295. _outgtext(pn);
  296. }
  297. }
  298. else
  299. {
  300. if (scr_b[coords][3]==0)
  301. {
  302. _setcolor(scr_b[coords][2]);
  303. _setpixel(scr_b[coords][0],scr_b[coords][1]);
  304. }
  305. else
  306. {
  307. _setcolor(scr_b[coords][2]);
  308. _moveto(scr_b[coords][0]-3,scr_b[coords][1]-3);
  309. sprintf(pn,"%d",scr_b[coords][3]);
  310. _outgtext(pn);
  311. }
  312. }
  313. }
  314. }
  315. /******************************************************************************
  316. *****************************************************************************/
  317. void draw_ball()
  318. {
  319. float bx=(pos+25)->x;
  320. float bz=((pos+25)->y);
  321. float by=((pos+25)->z);
  322. conv_xypitch(bx,by,&scr_x,&scr_y);
  323. pitch_plot(scr_x,scr_y+32,(int)bz,ball_col,0);
  324. pitch_plot(scr_x,scr_y+31,(int)bz,ball_col,0);
  325. pitch_plot(scr_x+1,scr_y+32,(int)bz,ball_col,0);
  326. pitch_plot(scr_x+1,scr_y+31,(int)bz,ball_col,0);
  327. pitch_plot(scr_x,scr_y+32,0,shadow_col,0);
  328. pitch_plot(scr_x+1,scr_y+32,0,shadow_col,0);
  329. }
  330. /******************************************************************************
  331. *****************************************************************************/
  332. void draw_team()
  333. {
  334. float tx,ty,tz;
  335. for (int i=0; i<(players/2); i++)
  336. {
  337. tx=(pos+i)->x;
  338. tz=(pos+i)->y;
  339. ty=(pos+i)->z;
  340. conv_xypitch(tx,ty,&scr_x,&scr_y);
  341. if (play_nums_on)
  342. {
  343. pitch_plot(scr_x,scr_y+32,(int)tz,team_a_col,i+2);
  344. }
  345. else
  346. {
  347. pitch_plot(scr_x,scr_y+32,(int)tz,team_a_col,0);
  348. pitch_plot(scr_x,scr_y+33,(int)tz,team_a_col,0);
  349. if ((teams[i].int_cnt) && (teams[i].int_move==I_INTERCEPT))
  350. pitch_plot(scr_x,scr_y+31,(int)tz,7,0);
  351. }
  352. }
  353. for (i=11; i<players; i++)
  354. {
  355. tx=(pos+i)->x;
  356. tz=(pos+i)->y;
  357. ty=(pos+i)->z;
  358. conv_xypitch(tx,ty,&scr_x,&scr_y);
  359. if (play_nums_on)
  360. {
  361. pitch_plot(scr_x,scr_y+32,(int)tz,team_b_col,i-8);
  362. }
  363. else
  364. {
  365. pitch_plot(scr_x,scr_y+32,(int)tz,team_b_col,0);
  366. pitch_plot(scr_x,scr_y+33,(int)tz,team_b_col,0);
  367. if ((teams[i].int_cnt) && (teams[i].int_move==I_INTERCEPT))
  368. pitch_plot(scr_x,scr_y+31,(int)tz,7,0);
  369. }
  370. }
  371. }
  372. /******************************************************************************
  373. *****************************************************************************/
  374. void panel_data()
  375. {
  376. char info_str1[40];
  377. char info_str2[40];
  378. char info_str3[4];
  379. char info_str4[12];
  380. /*
  381. // sprintf(info_str1,"zone =%d poss =%d ",ball_zone1,ball_poss);
  382. sprintf(info_str1,"opps =%d poss =%d ",opponents_near_holder,ball_poss);
  383. // sprintf(info_str1,"a =%d b =%d ",interceptor_a+1,interceptor_b+1);
  384. // sprintf(info_str2,"last =%d bspd =%d ",last_touch,ball_speed);
  385. sprintf(info_str2,"xyspin =%d zspin =%d ",set_xyspin,set_zspin);
  386. _settextposition(21,0);
  387. _outtext(info_str1);
  388. _settextposition(22,0);
  389. _outtext(info_str2);
  390. _settextposition(23,0);
  391. _outtext(action);
  392. _outtext(" ");
  393. */
  394. sprintf(info_str4,"%d - %d ",team_a_goals,team_b_goals);
  395. _settextposition(20,0);
  396. _outtext(info_str4);
  397. sprintf(info_str3,"%d ",delay_cnt);
  398. _settextposition(20,37);
  399. _outtext(info_str3);
  400. }
  401. /******************************************************************************
  402. ******************************************************************************/
  403. void slower()
  404. {
  405. delay_cnt++;
  406. }
  407. /******************************************************************************
  408. ******************************************************************************/
  409. void faster()
  410. {
  411. if (delay_cnt>0)
  412. delay_cnt--;
  413. }
  414. /******************************************************************************
  415. ******************************************************************************/
  416. void show_nums()
  417. {
  418. if (play_nums_on)
  419. play_nums_on=FALSE;
  420. else
  421. play_nums_on=TRUE;
  422. }
  423. /******************************************************************************
  424. *****************************************************************************/
  425. int old_time=0;
  426. int prev_count=0;
  427. int times=0;
  428. void frame_count()
  429. {
  430. updates++;
  431. frames++;
  432. times++;
  433. int cl=count-oldcnt;
  434. if (count-prev_count>TIMER_SPEED)
  435. {
  436. prev_count=count;
  437. old_time=times;
  438. }
  439. if (cl>(TIMER_SPEED/4)) // Re-time interval (1/4 sec)!
  440. {
  441. oldcnt=count;
  442. MF=((float)cl*game_speed)/(frames*TIMER_SPEED);
  443. if (MF>6 && game_speed==REAL_SPEED)
  444. MF=6;
  445. frames=0;
  446. }
  447. }
  448. void oframe_count()
  449. {
  450. updates++;
  451. int cl=clock();
  452. frames++;
  453. int c=cl/CLOCKS_PER_SEC;
  454. if (c!=last_second)
  455. {
  456. seconds++;
  457. frms_per_sec=frames;
  458. frames=0;
  459. last_second=c;
  460. int frame_time=cl-old_clock;
  461. old_clock=cl;
  462. MF=((float)(frame_time)*game_speed)/(frms_per_sec*100);
  463. }
  464. }