EDITOR.CPP 22 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111
  1. #include "global.h"
  2. #include "mouse.h"
  3. /******************************************************************************
  4. ******************************************************************************/
  5. #define TRUE 1
  6. #define FALSE 0
  7. /******************************************************************************
  8. *****************************************************************************/
  9. // EDITOR GLOBAL VARIABLES...
  10. int e_button_lit=0;
  11. int ed_zone=0;
  12. int ed_poss=0;
  13. int ed_last_poss=0;
  14. int ed_last_zone=0;
  15. int picked_up=0;
  16. char tac_buffer[((32*2)+4)*10*2*5];
  17. int temp_tactic[10][2];
  18. int undo_tactic[10][2];
  19. int ed_tactic[(32*2)+6][10][2]; //Current Tactic Buffer.
  20. char tac_name[9]="new_tacs";
  21. struct buttons {
  22. int x;
  23. int y;
  24. int w;
  25. char s[10];
  26. char l;
  27. };
  28. buttons ed_buttons[]={{186,12,1,"C",0},{292,12,1,"C",0},
  29. {186,90,1,"C",0},{292,90,1,"C",0},
  30. {12,120,4,"LOAD",0},{60,120,4,"SAVE",0},
  31. {220,98,6,"POSS ",0},{192+12,132,4,"COPY",0},
  32. {240+12,132,4,"SWAP",0},{192+12,156,4,"UNDO",0},
  33. {240+12,156,4,"INIT",0},{320-40,200-16,4,"GAME",0},
  34. {108,120,4,"NAME",0},{186,42,1,"K",0},{292,42,1,"K",0}};
  35. int max_buttons=(sizeof(ed_buttons)/sizeof(buttons));
  36. /******************************************************************************
  37. *****************************************************************************/
  38. // EDITOR FUNCTIONS...
  39. /******************************************************************************
  40. *****************************************************************************/
  41. float rem(float n,int d)
  42. {
  43. return((n/d)-((int)n/d));
  44. }
  45. /******************************************************************************
  46. *****************************************************************************/
  47. void e_line_border(int x,int y,int wid,int hgt,int col)
  48. {
  49. int c=_getcolor();
  50. _moveto(x,y);
  51. _setcolor(col);
  52. _lineto(x+wid-1,y);
  53. _lineto(x+wid-1,y+hgt-1);
  54. _lineto(x,y+hgt-1);
  55. _lineto(x,y);
  56. _setcolor(c);
  57. }
  58. /******************************************************************************
  59. *****************************************************************************/
  60. void draw_grid()
  61. {
  62. _setcolor(4);
  63. float step=(160.2)/7;
  64. float x=8+(step/2);
  65. for (int i=1; i<8; i++, x+=step )
  66. {
  67. _moveto((int)x,8);
  68. _lineto((int)x,108);
  69. }
  70. step=100/3;
  71. x=8+(step/2);
  72. for (i=1; i<4; i++, x+=step )
  73. {
  74. _moveto(8,(int)x);
  75. _lineto(168,(int)x);
  76. }
  77. }
  78. /******************************************************************************
  79. *****************************************************************************/
  80. void draw_zones()
  81. {
  82. _setcolor(7);
  83. float step=(84)/7;
  84. float x=200+(step/2);
  85. for (int i=1; i<8; i++, x+=step )
  86. {
  87. _moveto((int)x,24);
  88. _lineto((int)x,68+16);
  89. }
  90. step=60/3;
  91. x=24+(step/2);
  92. for (i=1; i<4; i++, x+=step )
  93. {
  94. _moveto(200,(int)x);
  95. _lineto(200+84,(int)x);
  96. }
  97. e_line_border(200,24,85,61,7);
  98. _moveto(216,12);
  99. _outgtext("ZONE 1");
  100. }
  101. /******************************************************************************
  102. *****************************************************************************/
  103. void draw_markings()
  104. {
  105. _moveto(8,8);
  106. _setcolor(7);
  107. _lineto(168,8);
  108. _lineto(168,108);
  109. _lineto(8,108);
  110. _lineto(8,8);
  111. // Left Goal
  112. _moveto(7,50-5+7);
  113. _lineto(4,50-5+7);
  114. _lineto(4,50+5+7);
  115. _lineto(7,50+5+7);
  116. // Right Goal
  117. _moveto(161+8,50-5+7);
  118. _lineto(165+8,50-5+7);
  119. _lineto(165+8,50+5+7);
  120. _lineto(161+8,50+5+7);
  121. // Left Six Yard Box
  122. _moveto(8,50-13+7);
  123. _lineto(8+8,50-13+7);
  124. _lineto(8+8,50+13+7);
  125. _lineto(8,50+13+7);
  126. // Right Six Yard Box
  127. _moveto(160+8,50-13+7);
  128. _lineto(160-8+8,50-13+7);
  129. _lineto(160-8+8,50+13+7);
  130. _lineto(160+8,50+13+7);
  131. // Left 18 Yard Box
  132. _moveto(8,50-29+7);
  133. _lineto(8+24,50-29+7);
  134. _lineto(8+24,50+29+7);
  135. _lineto(8,50+29+7);
  136. // Right 18 Yard Box
  137. _moveto(160+8,50-29+7);
  138. _lineto(160+8-24,50-29+7);
  139. _lineto(160+8-24,50+29+7);
  140. _lineto(160+8,50+29+7);
  141. // Centre circle
  142. _ellipse(_GBORDER,80+8-13,50+7-13,80+8+13,50+7+13);
  143. _setcolor(2);
  144. _moveto(10,54);
  145. _outgtext("1");
  146. }
  147. /******************************************************************************
  148. *****************************************************************************/
  149. void draw_edteam()
  150. {
  151. char st[3];
  152. int x,y;
  153. int c=_getcolor();
  154. int p=_getplotaction();
  155. _setcolor(2);
  156. _setplotaction(_GXOR);
  157. for (int i=0; i<10; i++)
  158. {
  159. sprintf(st,"%d",i+2);
  160. x=(ed_tactic[ed_zone+((ed_zone<32*2) ? ed_poss*32:0)][i][0])/8;
  161. y=(ed_tactic[ed_zone+((ed_zone<32*2) ? ed_poss*32:0)][i][1])/8;
  162. _moveto(8+x-3,8+y-3);
  163. HideMouse();
  164. _outgtext(st);
  165. ShowMouse();
  166. }
  167. _setplotaction(p);
  168. _setcolor(c);
  169. }
  170. /******************************************************************************
  171. *****************************************************************************/
  172. void e_draw_buttons()
  173. {
  174. int x,y,w;
  175. char st[10];
  176. for (int i=0; i<max_buttons; i++)
  177. {
  178. x=ed_buttons[i].x;
  179. y=ed_buttons[i].y;
  180. w=ed_buttons[i].w;
  181. strcpy(st,ed_buttons[i].s);
  182. _moveto(x,y);
  183. _outgtext(st);
  184. e_line_border(x-4,y-4,w*8+8,16,1);
  185. }
  186. }
  187. /******************************************************************************
  188. *****************************************************************************/
  189. void e_light_button(int b)
  190. {
  191. int x,y,w,c;
  192. c=_getcolor();
  193. char st[10];
  194. x=ed_buttons[b].x;
  195. y=ed_buttons[b].y;
  196. w=ed_buttons[b].w;
  197. strcpy(st,ed_buttons[b].s);
  198. _setcolor(7);
  199. _moveto(x,y);
  200. HideMouse();
  201. _outgtext(st);
  202. _setcolor(c);
  203. ShowMouse();
  204. e_button_lit=b+1;
  205. }
  206. /******************************************************************************
  207. *****************************************************************************/
  208. void e_unlight_button(int b)
  209. {
  210. int x,y,w;
  211. char st[10];
  212. x=ed_buttons[b].x;
  213. y=ed_buttons[b].y;
  214. w=ed_buttons[b].w;
  215. strcpy(st,ed_buttons[b].s);
  216. _moveto(x,y);
  217. HideMouse();
  218. _outgtext(st);
  219. ShowMouse();
  220. if (e_button_lit==b+1)
  221. e_button_lit=0;
  222. }
  223. /******************************************************************************
  224. *****************************************************************************/
  225. void e_process_butts()
  226. {
  227. int x,y,w;
  228. for (int i=0; i<max_buttons; i++)
  229. {
  230. x=ed_buttons[i].x;
  231. y=ed_buttons[i].y;
  232. w=ed_buttons[i].w;
  233. if ((Mouse.x/2>=x-4) && (Mouse.x/2<=x+(w*8)+4)
  234. && (Mouse.y>=y-4) && (Mouse.y<=y+12))
  235. {
  236. if (!ed_buttons[i].l)
  237. {
  238. e_light_button(i); //Mouse will highlight button.
  239. ed_buttons[i].l=1;
  240. }
  241. }
  242. else
  243. {
  244. if (ed_buttons[i].l)
  245. {
  246. e_unlight_button(i);
  247. ed_buttons[i].l=0;
  248. }
  249. }
  250. }
  251. }
  252. /******************************************************************************
  253. *****************************************************************************/
  254. void undo_copy()
  255. {
  256. memcpy(undo_tactic,ed_tactic[ed_zone+((ed_zone<32*2) ? ed_poss*32:0)],10*2*sizeof(int));
  257. }
  258. /******************************************************************************
  259. *****************************************************************************/
  260. void reset_poss()
  261. {
  262. ed_last_poss=ed_poss;
  263. }
  264. /******************************************************************************
  265. *****************************************************************************/
  266. void init_zgrid()
  267. {
  268. _setplotaction(_GXOR);
  269. ed_zone=0;
  270. undo_copy();
  271. _moveto(200-3,24-3);
  272. HideMouse();
  273. int c=_getcolor();
  274. _setcolor(7);
  275. _outgtext("O");
  276. ShowMouse();
  277. _setplotaction(_GPSET);
  278. _setcolor(c);
  279. }
  280. /******************************************************************************
  281. *****************************************************************************/
  282. void write_name()
  283. {
  284. _moveto(8,184);
  285. int c=_getcolor();
  286. int g=_getplotaction();
  287. _setplotaction(_GXOR);
  288. _setcolor(3);
  289. _outgtext(tac_name);
  290. _setcolor(c);
  291. _setplotaction(g);
  292. }
  293. /******************************************************************************
  294. *****************************************************************************/
  295. void input_keys(char *i,int chars)
  296. {
  297. char buff[2+41];
  298. int n=chars;
  299. if (!n)
  300. n=8+1; // filename.
  301. buff[0]=n;
  302. cgets(buff);
  303. strcpy(i,buff+2);
  304. }
  305. /******************************************************************************
  306. *****************************************************************************/
  307. void name_butt()
  308. {
  309. write_name();
  310. _settextposition(24,2);
  311. _outtext("New name: ");
  312. input_keys(tac_name,0); //0=filename.
  313. _settextposition(24,2);
  314. _outtext(" ");
  315. write_name();
  316. }
  317. /******************************************************************************
  318. *****************************************************************************/
  319. void save_butt()
  320. {
  321. write_name();
  322. _settextposition(24,2);
  323. _outtext("Are you sure(Y/N)?");
  324. char k;
  325. do
  326. {
  327. k=getch();
  328. } while(k!='y' && k!='n');
  329. if (k=='y')
  330. {
  331. _settextposition(24,2);
  332. _outtext(" ");
  333. _settextposition(24,2);
  334. _outtext("Saving: ");
  335. char file_name[13];
  336. strcpy(file_name,tac_name);
  337. strcat(file_name,".tac");
  338. _outtext(file_name);
  339. FILE *fp1=fopen(file_name,"wb");
  340. if (fp1==0)
  341. {
  342. _settextposition(24,2);
  343. _outtext("Save Failed");
  344. delay(1200);
  345. }
  346. else
  347. {
  348. fwrite(ed_tactic,sizeof(int),((32*2)+6)*10*2,fp1);
  349. fclose(fp1);
  350. delay(600);
  351. }
  352. }
  353. _settextposition(24,2);
  354. _outtext(" ");
  355. write_name();
  356. }
  357. /******************************************************************************
  358. *****************************************************************************/
  359. void load_butt()
  360. {
  361. draw_edteam();
  362. write_name();
  363. _settextposition(24,2);
  364. _outtext("Are you sure(Y/N)?");
  365. char k;
  366. do
  367. {
  368. k=getch();
  369. } while(k!='y' && k!='n');
  370. if (k=='y')
  371. {
  372. _settextposition(24,2);
  373. _outtext(" ");
  374. _settextposition(24,2);
  375. _outtext("Loading: ");
  376. char file_name[13];
  377. strcpy(file_name,tac_name);
  378. strcat(file_name,".tac");
  379. _outtext(file_name);
  380. FILE *fp1=fopen(file_name,"rb");
  381. if (fp1==0)
  382. {
  383. _settextposition(24,2);
  384. _outtext("Load Failed");
  385. delay(1200);
  386. }
  387. else
  388. {
  389. fread(ed_tactic,sizeof(int),((32*2)+6)*10*2,fp1);
  390. fclose(fp1);
  391. delay(600);
  392. }
  393. }
  394. _settextposition(24,2);
  395. _outtext(" ");
  396. write_name();
  397. draw_edteam();
  398. }
  399. /******************************************************************************
  400. *****************************************************************************/
  401. void get_zx_zy(int *zx,int *zy)
  402. {
  403. switch(ed_zone)
  404. {
  405. case 32+32:
  406. { // top left corner.
  407. *zx=1;
  408. *zy=-9;
  409. break;
  410. }
  411. case 32+33:
  412. { // top right corner.
  413. *zx=84;
  414. *zy=-9;
  415. break;
  416. }
  417. case 32+34:
  418. { // bot left corner.
  419. *zx=1;
  420. *zy=70-1;
  421. break;
  422. }
  423. case 32+35:
  424. { // bot right corner.
  425. *zx=84;
  426. *zy=70-1;
  427. break;
  428. }
  429. case 32+36:
  430. { // home centre.
  431. *zx=-11;
  432. *zy=35;
  433. break;
  434. }
  435. case 32+37:
  436. { // away centre.
  437. *zx=95;
  438. *zy=35;
  439. break;
  440. }
  441. default:
  442. {
  443. *zy=(ed_zone/8)*20;
  444. *zx=rem(ed_zone,8)*12*8;
  445. }
  446. }
  447. }
  448. /******************************************************************************
  449. *****************************************************************************/
  450. void zone_grid()
  451. {
  452. int c=_getcolor();
  453. _setcolor(7);
  454. int x=(Mouse.x/2)-200;
  455. int y=(Mouse.y-24);
  456. x=((x+6)/12);
  457. y=((y+10)/20);
  458. int zone=x+(y*8);
  459. if (zone!=ed_zone)
  460. {
  461. reset_poss();
  462. _setplotaction(_GXOR);
  463. char st[5];
  464. int zx,zy;
  465. get_zx_zy(&zx,&zy);
  466. _moveto(200-3+zx,24-3+zy);
  467. HideMouse();
  468. _outgtext("O");
  469. _moveto(256,12);
  470. sprintf(st,"%d",ed_zone+1);
  471. _outgtext(st);
  472. draw_edteam();
  473. ed_last_zone=ed_zone;
  474. ed_zone=zone;
  475. undo_copy();
  476. zy=(ed_zone/8)*20;
  477. zx=rem(ed_zone,8)*12*8;
  478. _moveto(200-3+zx,24-3+zy);
  479. _outgtext("O");
  480. _moveto(256,12);
  481. sprintf(st,"%d",ed_zone+1);
  482. _outgtext(st);
  483. _setplotaction(_GPSET);
  484. ShowMouse();
  485. draw_edteam();
  486. }
  487. _setcolor(c);
  488. }
  489. /******************************************************************************
  490. *****************************************************************************/
  491. void top_l_corn()
  492. {
  493. reset_poss();
  494. if (ed_zone!=32*2)
  495. { int c=_getcolor();
  496. _setcolor(7);
  497. _setplotaction(_GXOR);
  498. char st[5];
  499. int zx,zy;
  500. get_zx_zy(&zx,&zy);
  501. _moveto(200-3+zx,24-3+zy);
  502. HideMouse();
  503. _outgtext("O");
  504. _moveto(256,12);
  505. sprintf(st,"%d",ed_zone+1);
  506. _outgtext(st);
  507. draw_edteam();
  508. ed_last_zone=ed_zone;
  509. ed_zone=32*2;
  510. _moveto(200-2,16-4);
  511. _outgtext("O");
  512. _moveto(256,12);
  513. sprintf(st,"%d",ed_zone+1);
  514. _outgtext(st);
  515. _setplotaction(_GPSET);
  516. ShowMouse();
  517. draw_edteam();
  518. _setcolor(c);
  519. }
  520. }
  521. /******************************************************************************
  522. *****************************************************************************/
  523. void top_r_corn()
  524. {
  525. reset_poss();
  526. if (ed_zone!=1+(32*2))
  527. { int c=_getcolor();
  528. _setcolor(7);
  529. _setplotaction(_GXOR);
  530. char st[5];
  531. int zx,zy;
  532. get_zx_zy(&zx,&zy);
  533. _moveto(200-3+zx,24-3+zy);
  534. HideMouse();
  535. _outgtext("O");
  536. _moveto(256,12);
  537. sprintf(st,"%d",ed_zone+1);
  538. _outgtext(st);
  539. draw_edteam();
  540. ed_last_zone=ed_zone;
  541. ed_zone=1+(32*2);
  542. _moveto(284-3,16-4);
  543. _outgtext("O");
  544. _moveto(256,12);
  545. sprintf(st,"%d",ed_zone+1);
  546. _outgtext(st);
  547. _setplotaction(_GPSET);
  548. ShowMouse();
  549. draw_edteam();
  550. _setcolor(c);
  551. }
  552. }
  553. /******************************************************************************
  554. *****************************************************************************/
  555. void bot_l_corn()
  556. {
  557. reset_poss();
  558. if (ed_zone!=2+(32*2))
  559. { int c=_getcolor();
  560. _setcolor(7);
  561. _setplotaction(_GXOR);
  562. char st[5];
  563. int zx,zy;
  564. get_zx_zy(&zx,&zy);
  565. _moveto(200-3+zx,24-3+zy);
  566. HideMouse();
  567. _outgtext("O");
  568. _moveto(256,12);
  569. sprintf(st,"%d",ed_zone+1);
  570. _outgtext(st);
  571. draw_edteam();
  572. ed_last_zone=ed_zone;
  573. ed_zone=2+(32*2);
  574. _moveto(200-2,94-4);
  575. _outgtext("O");
  576. _moveto(256,12);
  577. sprintf(st,"%d",ed_zone+1);
  578. _outgtext(st);
  579. _setplotaction(_GPSET);
  580. ShowMouse();
  581. draw_edteam();
  582. _setcolor(c);
  583. }
  584. }
  585. /******************************************************************************
  586. *****************************************************************************/
  587. void bot_r_corn()
  588. {
  589. reset_poss();
  590. if (ed_zone!=3+(32*2))
  591. { int c=_getcolor();
  592. _setcolor(7);
  593. _setplotaction(_GXOR);
  594. char st[5];
  595. int zx,zy;
  596. get_zx_zy(&zx,&zy);
  597. _moveto(200-3+zx,24-3+zy);
  598. HideMouse();
  599. _outgtext("O");
  600. _moveto(256,12);
  601. sprintf(st,"%d",ed_zone+1);
  602. _outgtext(st);
  603. draw_edteam();
  604. ed_last_zone=ed_zone;
  605. ed_zone=3+(32*2);
  606. _moveto(284-3,94-4);
  607. _outgtext("O");
  608. _moveto(256,12);
  609. sprintf(st,"%d",ed_zone+1);
  610. _outgtext(st);
  611. _setplotaction(_GPSET);
  612. ShowMouse();
  613. draw_edteam();
  614. _setcolor(c);
  615. }
  616. }
  617. /******************************************************************************
  618. *****************************************************************************/
  619. void home_centre()
  620. {
  621. reset_poss();
  622. if (ed_zone!=4+(32*2))
  623. { int c=_getcolor();
  624. _setcolor(7);
  625. _setplotaction(_GXOR);
  626. char st[5];
  627. int zx,zy;
  628. get_zx_zy(&zx,&zy);
  629. _moveto(200-3+zx,24-3+zy);
  630. HideMouse();
  631. _outgtext("O");
  632. _moveto(256,12);
  633. sprintf(st,"%d",ed_zone+1);
  634. _outgtext(st);
  635. draw_edteam();
  636. ed_last_zone=ed_zone;
  637. ed_zone=4+(32*2);
  638. _moveto(189-3,60-4);
  639. _outgtext("O");
  640. _moveto(256,12);
  641. sprintf(st,"%d",ed_zone+1);
  642. _outgtext(st);
  643. _setplotaction(_GPSET);
  644. ShowMouse();
  645. draw_edteam();
  646. _setcolor(c);
  647. }
  648. }
  649. /******************************************************************************
  650. *****************************************************************************/
  651. void away_centre()
  652. {
  653. reset_poss();
  654. if (ed_zone!=5+(32*2))
  655. { int c=_getcolor();
  656. _setcolor(7);
  657. _setplotaction(_GXOR);
  658. char st[5];
  659. int zx,zy;
  660. get_zx_zy(&zx,&zy);
  661. _moveto(200-3+zx,24-3+zy);
  662. HideMouse();
  663. _outgtext("O");
  664. _moveto(256,12);
  665. sprintf(st,"%d",ed_zone+1);
  666. _outgtext(st);
  667. draw_edteam();
  668. ed_last_zone=ed_zone;
  669. ed_zone=5+(32*2);
  670. _moveto(295-3,60-4);
  671. _outgtext("O");
  672. _moveto(256,12);
  673. sprintf(st,"%d",ed_zone+1);
  674. _outgtext(st);
  675. _setplotaction(_GPSET);
  676. ShowMouse();
  677. draw_edteam();
  678. _setcolor(c);
  679. }
  680. }
  681. /******************************************************************************
  682. *****************************************************************************/
  683. void poss_butt()
  684. {
  685. reset_poss();
  686. HideMouse();
  687. if (!ed_poss)
  688. {
  689. ed_last_zone=ed_zone;
  690. int g=_getplotaction();
  691. int c=_getcolor();
  692. _setcolor(5);
  693. _setplotaction(_GXOR);
  694. _moveto(260,98);
  695. _outgtext("x");
  696. _setcolor(7);
  697. _moveto(260,98);
  698. _outgtext("O");
  699. _setplotaction(g);
  700. _setcolor(c);
  701. MouseRelease();
  702. draw_edteam();
  703. ed_poss=1;
  704. draw_edteam();
  705. }
  706. else
  707. {
  708. ed_last_zone=ed_zone;
  709. int g=_getplotaction();
  710. int c=_getcolor();
  711. _setcolor(7);
  712. _setplotaction(_GXOR);
  713. _moveto(260,98);
  714. _outgtext("O");
  715. _setcolor(5);
  716. _moveto(260,98);
  717. _outgtext("x");
  718. _setplotaction(g);
  719. _setcolor(c);
  720. MouseRelease();
  721. draw_edteam();
  722. ed_poss=0;
  723. draw_edteam();
  724. }
  725. ShowMouse();
  726. }
  727. /******************************************************************************
  728. *****************************************************************************/
  729. void undo_butt()
  730. {
  731. HideMouse();
  732. draw_edteam();
  733. memcpy(ed_tactic[ed_zone+((ed_zone<32*2) ? ed_poss*32:0)],undo_tactic,10*2*sizeof(int));
  734. draw_edteam();
  735. ShowMouse();
  736. MouseRelease();
  737. }
  738. /******************************************************************************
  739. *****************************************************************************/
  740. void init_butt()
  741. {
  742. HideMouse();
  743. draw_edteam();
  744. memset(&(ed_tactic[ed_zone+((ed_zone<32*2) ? ed_poss*32:0)]),0,10*2*sizeof(int));
  745. draw_edteam();
  746. ShowMouse();
  747. MouseRelease();
  748. }
  749. /******************************************************************************
  750. *****************************************************************************/
  751. void copy_butt()
  752. {
  753. HideMouse();
  754. draw_edteam();
  755. memcpy(ed_tactic[ed_zone+((ed_zone<32*2) ? ed_poss*32:0)],
  756. ed_tactic[ed_last_zone+((ed_last_zone<32*2) ? ed_last_poss*32:0)],10*2*sizeof(int));
  757. draw_edteam();
  758. ShowMouse();
  759. MouseRelease();
  760. }
  761. /******************************************************************************
  762. *****************************************************************************/
  763. void swap_butt()
  764. {
  765. HideMouse();
  766. draw_edteam();
  767. // Store last zone.
  768. memcpy(temp_tactic,ed_tactic[ed_last_zone+((ed_last_zone<32*2) ? ed_last_poss*32:0)],10*2*sizeof(int));
  769. // Last=current.
  770. memcpy(ed_tactic[ed_last_zone+((ed_last_zone<32*2) ? ed_last_poss*32:0)]
  771. ,ed_tactic[ed_zone+((ed_zone<32*2) ? ed_poss*32:0)],10*2*sizeof(int));
  772. // current=last.
  773. memcpy(ed_tactic[ed_zone+((ed_zone<32*2) ? ed_poss*32:0)],temp_tactic,10*2*sizeof(int));
  774. draw_edteam();
  775. ShowMouse();
  776. MouseRelease();
  777. }
  778. /******************************************************************************
  779. *****************************************************************************/
  780. void e_go_button()
  781. {
  782. switch(e_button_lit)
  783. {
  784. case 1:
  785. {
  786. top_l_corn();
  787. break;
  788. }
  789. case 2:
  790. {
  791. top_r_corn();
  792. break;
  793. }
  794. case 3:
  795. {
  796. bot_l_corn();
  797. break;
  798. }
  799. case 4:
  800. {
  801. bot_r_corn();
  802. break;
  803. }
  804. case 5:
  805. {
  806. load_butt();
  807. break;
  808. }
  809. case 6:
  810. {
  811. save_butt();
  812. break;
  813. }
  814. case 7:
  815. {
  816. poss_butt();
  817. break;
  818. }
  819. case 8:
  820. {
  821. copy_butt();
  822. break;
  823. }
  824. case 9:
  825. {
  826. swap_butt();
  827. break;
  828. }
  829. case 10:
  830. {
  831. undo_butt();
  832. break;
  833. }
  834. case 11:
  835. {
  836. init_butt();
  837. break;
  838. }
  839. case 12:
  840. {
  841. in_game=TRUE; //return to game.
  842. break;
  843. }
  844. case 13:
  845. {
  846. name_butt();
  847. break;
  848. }
  849. case 14:
  850. {
  851. home_centre();
  852. break;
  853. }
  854. case 15:
  855. {
  856. away_centre();
  857. break;
  858. }
  859. }
  860. }
  861. /******************************************************************************
  862. *****************************************************************************/
  863. void capture_ed()
  864. {
  865. int nd=5000;
  866. int mx=((Mouse.x/2)-8)*8;
  867. int my=(Mouse.y-8)*8;
  868. int x,y,d;
  869. for (int i=0; i<10; i++)
  870. {
  871. x=ed_tactic[ed_zone+((ed_zone<32*2) ? ed_poss*32:0)][i][0];
  872. y=ed_tactic[ed_zone+((ed_zone<32*2) ? ed_poss*32:0)][i][1];
  873. x-=mx;
  874. y-=my;
  875. d=calc_dist(x,y);
  876. if (d<nd)
  877. {
  878. nd=d;
  879. picked_up=i+1;
  880. }
  881. }
  882. }
  883. /******************************************************************************
  884. *****************************************************************************/
  885. void move_ed()
  886. {
  887. int c=_getcolor();
  888. _setcolor(2);
  889. int mx=((Mouse.x/2)-8)*8;
  890. int my=(Mouse.y-8)*8;
  891. int x=ed_tactic[ed_zone+((ed_zone<32*2) ? ed_poss*32:0)][picked_up-1][0];
  892. int y=ed_tactic[ed_zone+((ed_zone<32*2) ? ed_poss*32:0)][picked_up-1][1];
  893. _setplotaction(_GXOR);
  894. char st[3];
  895. sprintf(st,"%d",picked_up+1);
  896. _moveto(8+(x/8)-3,8+(y/8)-3);
  897. HideMouse();
  898. _outgtext(st);
  899. ed_tactic[ed_zone+((ed_zone<32*2) ? ed_poss*32:0)][picked_up-1][0]=mx;
  900. ed_tactic[ed_zone+((ed_zone<32*2) ? ed_poss*32:0)][picked_up-1][1]=my;
  901. _moveto(8+(mx/8)-3,8+(my/8)-3);
  902. _outgtext(st);
  903. ShowMouse();
  904. _setplotaction(_GPSET);
  905. _setcolor(c);
  906. }
  907. /******************************************************************************
  908. *****************************************************************************/
  909. void pitch_grid()
  910. {
  911. if (picked_up)
  912. move_ed();
  913. else
  914. {
  915. capture_ed();
  916. MouseYlim(8,107);
  917. MouseXlim(8*2,167*2);
  918. }
  919. }
  920. /******************************************************************************
  921. *****************************************************************************/
  922. void e_mouse_fired()
  923. {
  924. if (e_button_lit)
  925. e_go_button();
  926. else
  927. {
  928. if ((Mouse.x/2>=200) && (Mouse.x/2<=284)
  929. && (Mouse.y>=24) && (Mouse.y<=84))
  930. zone_grid();
  931. else
  932. {
  933. if ((Mouse.x/2>=8) && (Mouse.x/2<=168)
  934. && (Mouse.y>=8) && (Mouse.y<=108))
  935. pitch_grid();
  936. }
  937. }
  938. }
  939. /******************************************************************************
  940. *****************************************************************************/
  941. /******************************************************************************
  942. *****************************************************************************/
  943. // Editor Main...
  944. void editor_main()
  945. {
  946. _clearscreen(_GCLEARSCREEN);
  947. InitMouse();
  948. MouseYlim(0,200-4);
  949. MouseXlim(0,(320-4)*2);
  950. _setplotaction(_GPSET);
  951. e_line_border(0,0,320,200,1);
  952. draw_grid();
  953. draw_markings();
  954. draw_zones();
  955. _setcolor(5);
  956. e_draw_buttons();
  957. _moveto(260,98);
  958. _outgtext("x");
  959. init_zgrid();
  960. write_name();
  961. draw_edteam();
  962. ShowMouse();
  963. // Main Loop For Editor...
  964. while (!in_game)
  965. {
  966. ReportMouse();
  967. e_process_butts();
  968. if (Mouse.b&&1)
  969. e_mouse_fired();
  970. else
  971. {
  972. if (picked_up)
  973. {
  974. picked_up=0;
  975. MouseYlim(0,200-4);
  976. MouseXlim(0,(320-4)*2);
  977. }
  978. }
  979. delay(50);
  980. }
  981. _clearscreen(_GCLEARSCREEN);
  982. memcpy(match_tactics1,ed_tactic,(((32*2)+6)*10*2)*sizeof(int));
  983. memcpy(match_tactics2,ed_tactic,(((32*2)+6)*10*2)*sizeof(int));
  984. MouseRelease();
  985. }