USER.CPP 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883
  1. /******************************************************************************
  2. ******************************************************************************/
  3. // User Interface routines...
  4. /******************************************************************************
  5. ******************************************************************************/
  6. #include <math.h>
  7. #include <string.h>
  8. #include <stdio.h>
  9. #include "defines.h"
  10. #include "mouse.h"
  11. #include "externs.h"
  12. extern char on_3d;
  13. extern void editor_main();
  14. /******************************************************************************
  15. ******************************************************************************/
  16. void init_keyboard()
  17. {
  18. key2[UP_KEY]=0x1e; // A
  19. key2[DN_KEY]=0x2c; // Z
  20. key2[LF_KEY]=0x33; // <
  21. key2[RT_KEY]=0x34; // >
  22. key2[F1_KEY]=0x10; // Q
  23. key2[F2_KEY]=0x35; // /
  24. key1[UP_KEY]=-0x48; // Arrow Up
  25. key1[DN_KEY]=-0x50; // Arrow Dn
  26. key1[LF_KEY]=-0x4b; // Arrow Lf
  27. key1[RT_KEY]=-0x4d; // Arrow Rt
  28. key1[F1_KEY]=0x52; // 0(num)
  29. key1[F2_KEY]=0x53; // .(num)
  30. }
  31. /******************************************************************************
  32. ******************************************************************************/
  33. void delete_net_user(int u)
  34. {
  35. users_left--;
  36. if (u==user_taker)
  37. user_taker=FALSE;
  38. short tm=0;
  39. int i;
  40. char copy=FALSE;
  41. short type=users[u-1].type;
  42. if (type<0)
  43. {
  44. // Auto Player...
  45. if (type==-1)
  46. {
  47. // Auto-user A.
  48. for (i=0; i<auto_users_a; i++)
  49. {
  50. if (auto_users_list_a[i]==u)
  51. // Found user...
  52. {
  53. /*
  54. if (last_user_a>=i && last_user_a)
  55. last_user_a--;
  56. if (play_ball_a>=i && play_ball_a)
  57. play_ball_a--;
  58. */
  59. copy=TRUE;
  60. }
  61. if (copy && i<auto_users_a)
  62. auto_users_list_a[i]=auto_users_list_a[i+1];
  63. }
  64. auto_users_a--;
  65. }
  66. else
  67. {
  68. // Auto-user B.
  69. for (i=0; i<auto_users_b; i++)
  70. {
  71. if (auto_users_list_b[i]==u)
  72. // Found user...
  73. {
  74. /*
  75. if (last_user_b>=i && last_user_b)
  76. last_user_b--;
  77. if (play_ball_b>=i && play_ball_b)
  78. play_ball_b--;
  79. */
  80. copy=TRUE;
  81. }
  82. if (copy && i<auto_users_b)
  83. auto_users_list_b[i]=auto_users_list_b[i+1];
  84. }
  85. auto_users_b--;
  86. }
  87. }
  88. else
  89. {
  90. // Fixed Player...
  91. if (fixed_net_user==u)
  92. fixed_net_user=0;
  93. }
  94. for (i=0; i<22; i++)
  95. {
  96. if (teams[i].control==u)
  97. teams[i].control=FALSE; // No user control of player!
  98. }
  99. users[u-1].type=0;
  100. users[u-1].control=NO_CTRL;
  101. sprintf(glob_str1,"USER %d has quit!",u);
  102. add_message(&glob_str1[0],RED,TRUE);
  103. if (users_left==1)
  104. sprintf(glob_str2,"You are now the only user in the game!");
  105. else
  106. sprintf(glob_str2,"There are %d users left in the game!",users_left);
  107. add_message(&glob_str2[0],YELLOW);
  108. }
  109. /******************************************************************************
  110. ******************************************************************************/
  111. // Add team user.
  112. void add_team_user(short t,short c)
  113. {
  114. users[num_of_users].type=t; // User team.
  115. users[num_of_users].control=c; // Control type.
  116. users[num_of_users++].plr=-1; // Current player.
  117. /*
  118. if (c==JOY1_CTRL)
  119. joystick1_on=TRUE;
  120. if (c==JOY2_CTRL)
  121. joystick2_on=TRUE;
  122. */
  123. if (t==-1)
  124. auto_users_list_a[auto_users_a++]=num_of_users;
  125. if (t==-2)
  126. auto_users_list_b[auto_users_b++]=num_of_users;
  127. #ifdef SUPPORT_LP
  128. if (c==LOGPAD_CTRL)
  129. lp_user=num_of_users;
  130. #endif
  131. }
  132. /******************************************************************************
  133. ******************************************************************************/
  134. // Add User as fixed player.
  135. void add_fixed_user(short p,short c)
  136. {
  137. users[num_of_users].type=p; // User fixed player.
  138. users[num_of_users].control=c; // Control type.
  139. users[num_of_users++].plr=p; // Current player.
  140. /*
  141. if (c==JOY1_CTRL)
  142. joystick1_on=TRUE;
  143. if (c==JOY2_CTRL)
  144. joystick2_on=TRUE;
  145. */
  146. teams[p-1].control=num_of_users; // Tag player as user controlled!
  147. if (c!=NET_CTRL && network_on)
  148. fixed_net_user=num_of_users;
  149. #ifdef SUPPORT_LP
  150. if (c==LOGPAD_CTRL)
  151. lp_user=num_of_users;
  152. #endif
  153. }
  154. /******************************************************************************
  155. ******************************************************************************/
  156. // Initialise Fixed control players.
  157. void clear_all_fixed()
  158. {
  159. for (int i=0; i<players; i++)
  160. {
  161. teams[i].control=FALSE;
  162. }
  163. }
  164. /******************************************************************************
  165. ******************************************************************************/
  166. // Initialise User Configuration Table...
  167. void init_users()
  168. {
  169. memset((void *)users,0,MAX_NET_USERS*(sizeof(user_config)));
  170. num_of_users=0;
  171. auto_users_a=0;
  172. auto_users_b=0;
  173. fixed_net_user=0;
  174. clear_all_fixed();
  175. // add_team_user(TEAM_A,MOUSE_CTRL);
  176. // add_team_user(TEAM_A,KEY1_CTRL);
  177. // add_team_user(TEAM_A,KEY2_CTRL);
  178. // add_team_user(TEAM_A,JOY1_CTRL);
  179. // add_team_user(TEAM_A,KEY2_CTRL);
  180. // add_fixed_user(15,JOY2_CTRL);
  181. // add_team_user(TEAM_A,KEY2_CTRL);
  182. // add_fixed_user(11,KEY1_CTRL);
  183. }
  184. /******************************************************************************
  185. ******************************************************************************/
  186. void go_button()
  187. {
  188. switch(button_lit)
  189. {
  190. case 1:
  191. {
  192. in_game=FALSE;
  193. break;
  194. }
  195. case 2:
  196. {
  197. grid_map(); //Draw zonal grid on pitch.
  198. MouseRelease();
  199. break;
  200. }
  201. case 3:
  202. {
  203. faster(); //Speed up.
  204. break;
  205. }
  206. case 4:
  207. {
  208. slower(); //Slow down.
  209. break;
  210. }
  211. case 5:
  212. {
  213. show_nums(); //Show player nos.
  214. MouseRelease();
  215. break;
  216. }
  217. case 6:
  218. {
  219. set_xyspin++; //Add clockwise swerve.
  220. MouseRelease();
  221. break;
  222. }
  223. case 7:
  224. {
  225. set_xyspin--; //Add anti-clockwise swerve.
  226. MouseRelease();
  227. break;
  228. }
  229. case 8:
  230. {
  231. set_zspin++; //Add Top-spin swerve.
  232. MouseRelease();
  233. break;
  234. }
  235. case 9:
  236. {
  237. set_zspin--; //Add Back-spin swerve.
  238. MouseRelease();
  239. break;
  240. }
  241. case 10:
  242. {
  243. // on_3d=TRUE; //Use 3d display.
  244. break;
  245. }
  246. }
  247. }
  248. /******************************************************************************
  249. *****************************************************************************/
  250. void mouse_fired()
  251. {
  252. if (!on_3d)
  253. {
  254. if (button_lit)
  255. go_button();
  256. }
  257. }
  258. /******************************************************************************
  259. *****************************************************************************/
  260. void process_butts()
  261. {
  262. int x,y,w;
  263. for (int i=0; i<max_butts; i++)
  264. {
  265. x=us_buttons[i].x;
  266. y=us_buttons[i].y;
  267. w=us_buttons[i].w;
  268. if ((Mouse.x/2>=x-4) && (Mouse.x/2<=x+(w*8)+4)
  269. && (Mouse.y>=y-4) && (Mouse.y<=y+12))
  270. {
  271. if (!us_buttons[i].l)
  272. {
  273. light_button(i); //Mouse will highlight button.
  274. us_buttons[i].l=1;
  275. }
  276. }
  277. else
  278. {
  279. if (us_buttons[i].l)
  280. {
  281. unlight_button(i);
  282. us_buttons[i].l=0;
  283. }
  284. }
  285. }
  286. }
  287. /******************************************************************************
  288. *****************************************************************************/
  289. // Low level input code has moved to network.c...
  290. /******************************************************************************
  291. *****************************************************************************/
  292. // Converts integer input from interrupts into expected data in users_dir array
  293. void convert_inputs()
  294. {
  295. short x,y;
  296. for (int i=0; i<num_of_users; i++)
  297. {
  298. x=users_dir_i[readptr][i].x_f1;
  299. y=users_dir_i[readptr][i].y_f2;
  300. if (x==12345&&y==12345) // Magic quit data from master in network game
  301. delete_net_user(i+1);
  302. else
  303. {
  304. users_dir[i].f=(x&1)|((y&1)<<1);
  305. #ifdef EURO96
  306. users_dir[i].f+=((x&6)<<1);
  307. users_dir[i].f+=((y&6)<<3);
  308. x&=0xfff8;
  309. y&=0xfff8;
  310. #else
  311. #ifdef SUPPORT_LP
  312. if (users[i].control==LOGPAD_CTRL)
  313. {
  314. users_dir[i].f+=((x&6)<<1);
  315. users_dir[i].f+=((y&6)<<3);
  316. }
  317. x&=0xfff8;
  318. y&=0xfff8;
  319. #else
  320. x&=0xfffe;
  321. y&=0xfffe;
  322. #endif
  323. #endif
  324. users_dir[i].m=(x || y);
  325. users_dir[i].x=x/32768.;
  326. users_dir[i].y=y/32768.;
  327. }
  328. }
  329. }
  330. /******************************************************************************
  331. *****************************************************************************/
  332. // Reset Auto-selected User...
  333. void clear_auto(short u)
  334. {
  335. users[u-1].plr=0;
  336. for (int i=1; i<=players; i++)
  337. {
  338. if (teams[i-1].control==u)
  339. {
  340. teams[i-1].control=FALSE;
  341. teams[i-1].tm_htype=FALSE;
  342. }
  343. }
  344. }
  345. /******************************************************************************
  346. *****************************************************************************/
  347. // Reset All Auto-selected Users...
  348. void clear_all_autos()
  349. {
  350. for (short i=0; i<auto_users_a; i++)
  351. {
  352. clear_auto(auto_users_list_a[i]);
  353. }
  354. for (i=0; i<auto_users_b; i++)
  355. {
  356. clear_auto(auto_users_list_b[i]);
  357. }
  358. }
  359. /******************************************************************************
  360. *****************************************************************************/
  361. void reset_f_held()
  362. {
  363. f1_down=FALSE;
  364. f2_down=FALSE;
  365. }
  366. /******************************************************************************
  367. *****************************************************************************/
  368. short user_keeper_a()
  369. {
  370. short u=teams[KP_A-1].control;
  371. if (!u)
  372. if (auto_users_a)
  373. {
  374. if (++play_ball_a>=auto_users_a)
  375. play_ball_a=0;
  376. u=auto_users_list_a[play_ball_a];
  377. clear_auto(u);
  378. }
  379. else
  380. u=0;
  381. return(u);
  382. }
  383. /******************************************************************************
  384. *****************************************************************************/
  385. short user_keeper_b()
  386. {
  387. short u=teams[KP_B-1].control;
  388. if (!u)
  389. if (auto_users_b)
  390. {
  391. if (++play_ball_b>=auto_users_b)
  392. play_ball_b=0;
  393. u=auto_users_list_b[play_ball_b];
  394. clear_auto(u);
  395. }
  396. else
  397. u=0;
  398. return(u);
  399. }
  400. /******************************************************************************
  401. *****************************************************************************/
  402. short user_taker_a(short p)
  403. {
  404. reset_f_held();
  405. short u=teams[p-1].control;
  406. if (!u)
  407. {
  408. if (auto_users_a)
  409. {
  410. if (++play_ball_a>=auto_users_a)
  411. play_ball_a=0;
  412. u=auto_users_list_a[play_ball_a];
  413. clear_auto(u);
  414. }
  415. else
  416. u=0;
  417. }
  418. return(u);
  419. }
  420. /******************************************************************************
  421. *****************************************************************************/
  422. short user_taker_b(short p)
  423. {
  424. reset_f_held();
  425. short u=teams[p-1].control;
  426. if (!u)
  427. {
  428. if (auto_users_b)
  429. {
  430. if (++play_ball_b>=auto_users_b)
  431. play_ball_b=0;
  432. u=auto_users_list_b[play_ball_b];
  433. clear_auto(u);
  434. }
  435. else
  436. u=0;
  437. }
  438. return(u);
  439. }
  440. /******************************************************************************
  441. *****************************************************************************/
  442. void auto_select_a(short u)
  443. {
  444. // Team A...
  445. closest=FALSE;
  446. last_plr_a=users[u-1].plr;
  447. if (!(ball_poss && u==teams[ball_poss-1].control))
  448. // This guy doesn't have ball!
  449. {
  450. if (ball_poss!=KP_A && ball_poss<=players/2 && ball_poss
  451. && !teams[ball_poss-1].control)
  452. {
  453. // His team-mate has ball who isn't a user... (make him this user!)
  454. clear_auto(u);
  455. users[u-1].chng=TRUE; // changed control.
  456. reset_ideas(&teams[ball_poss-1]);
  457. teams[ball_poss-1].control=u;
  458. users[u-1].plr=ball_poss;
  459. }
  460. else
  461. // Get closest...
  462. {
  463. short main_guy;
  464. if (user_taker2==u)
  465. main_guy=KP_A;
  466. else
  467. if (receiver_a)
  468. main_guy=receiver_a;
  469. else
  470. if (interceptor_a)
  471. main_guy=interceptor_a;
  472. else
  473. if (near_path_a)
  474. main_guy=near_path_a;
  475. else
  476. main_guy=0;
  477. float d;
  478. int guy=0;
  479. float lowest=2000;
  480. for (int i=1; i<12; i++)
  481. {
  482. if ((i!=KP_A || match_mode==GOAL_KICK_BL || match_mode==GOAL_KICK_TL || user_taker2)
  483. && teams[i-1].guy_on>0 && (!teams[i-1].control || teams[i-1].control==u))
  484. {
  485. if (teams[i-1].tm_act!=FALL_ACT)
  486. {
  487. if (i==main_guy)
  488. d=1;
  489. else
  490. d=teams[i-1].tm_dist;
  491. if (d<lowest)
  492. {
  493. guy=i;
  494. lowest=d;
  495. }
  496. }
  497. }
  498. }
  499. if (guy!=last_plr_a && guy &&
  500. (last_plr_a<=0 || (last_plr_a>0 && !sel_circle[last_plr_a-1]) || receiver_a))
  501. {
  502. clear_auto(u);
  503. teams[guy-1].control=u;
  504. users[u-1].chng=TRUE; // changed control
  505. users[u-1].plr=guy;
  506. }
  507. }
  508. }
  509. }
  510. /******************************************************************************
  511. *****************************************************************************/
  512. void auto_select_b(short u)
  513. {
  514. // Team B...
  515. closest=FALSE;
  516. last_plr_b=users[u-1].plr;
  517. if (!(ball_poss && u==teams[ball_poss-1].control))
  518. // This guy doesn't have ball!
  519. {
  520. if (ball_poss!=KP_B && ball_poss>players/2
  521. && !teams[ball_poss-1].control)
  522. {
  523. // His team-mate has ball who isn't a user... (make him this user!)
  524. clear_auto(u);
  525. users[u-1].chng=TRUE; // changed control.
  526. reset_ideas(&teams[ball_poss-1]);
  527. teams[ball_poss-1].control=u;
  528. users[u-1].plr=ball_poss;
  529. }
  530. else
  531. // Get closest...
  532. {
  533. short main_guy;
  534. if (user_taker2==u)
  535. main_guy=KP_B;
  536. else
  537. if (receiver_b)
  538. main_guy=receiver_b;
  539. else
  540. if (interceptor_b)
  541. main_guy=interceptor_b;
  542. else
  543. if (near_path_b)
  544. main_guy=near_path_b;
  545. else
  546. main_guy=0;
  547. float d;
  548. int guy=0;
  549. float lowest=2000;
  550. for (int i=12; i<=players; i++)
  551. {
  552. if ((i!=KP_B || match_mode==GOAL_KICK_BR || match_mode==GOAL_KICK_TR || user_taker2)
  553. && teams[i-1].guy_on>0 && (!teams[i-1].control || teams[i-1].control==u))
  554. {
  555. if (teams[i-1].tm_act!=FALL_ACT)
  556. {
  557. if (i==main_guy)
  558. d=1;
  559. else
  560. d=teams[i-1].tm_dist;
  561. if (d<lowest)
  562. {
  563. guy=i;
  564. lowest=d;
  565. }
  566. }
  567. }
  568. }
  569. if (guy!=last_plr_b && guy &&
  570. (last_plr_b<=0 || (last_plr_b>0 && !sel_circle[last_plr_b-1]) || receiver_b))
  571. {
  572. clear_auto(u);
  573. teams[guy-1].control=u;
  574. users[u-1].chng=TRUE; // changed control
  575. users[u-1].plr=guy;
  576. }
  577. }
  578. }
  579. }
  580. /******************************************************************************
  581. *****************************************************************************/
  582. void reselect_a()
  583. {
  584. // Team A!
  585. short user,maxu,au,max_au;
  586. signed char p;
  587. float max=-1;
  588. float d;
  589. if (auto_users_a)
  590. {
  591. if (last_user_a==auto_users_a)
  592. last_user_a=0;
  593. maxu=auto_users_list_a[last_user_a];
  594. if (++last_user_a==auto_users_a)
  595. last_user_a=0;
  596. au=last_user_a;
  597. max_au=au;
  598. for (short i=1; i<auto_users_a; i++)
  599. {
  600. if (au==auto_users_a)
  601. au=0;
  602. user=auto_users_list_a[au];
  603. p=users[user-1].plr;
  604. if (p<=0)
  605. d=1500;
  606. else
  607. d=(teams[p-1].tm_dist);
  608. if (d>max)
  609. {
  610. max=d;
  611. maxu=user;
  612. max_au=au;
  613. }
  614. au++;
  615. }
  616. auto_select_a(maxu); // Team Control.
  617. if (!ball_poss)
  618. last_user_a=max_au;
  619. }
  620. }
  621. /******************************************************************************
  622. *****************************************************************************/
  623. void reselect_b()
  624. {
  625. // Team B!
  626. short user,maxu,au,max_au;
  627. signed char p;
  628. float max=-1;
  629. float d;
  630. if (auto_users_b)
  631. {
  632. if (last_user_b==auto_users_b)
  633. last_user_b=0;
  634. maxu=auto_users_list_b[last_user_b];
  635. if (++last_user_b==auto_users_b)
  636. last_user_b=0;
  637. au=last_user_b;
  638. max_au=au;
  639. for (short i=1; i<auto_users_b; i++)
  640. {
  641. if (au==auto_users_b)
  642. au=0;
  643. user=auto_users_list_b[au];
  644. p=users[user-1].plr;
  645. if (p<=0)
  646. d=1500;
  647. else
  648. d=(teams[p-1].tm_dist);
  649. if (d>max)
  650. {
  651. max=d;
  652. maxu=user;
  653. max_au=au;
  654. }
  655. au++;
  656. }
  657. auto_select_b(maxu); // Team Control.
  658. if (!ball_poss)
  659. last_user_b=max_au;
  660. }
  661. }
  662. /******************************************************************************
  663. *****************************************************************************/
  664. void reselect()
  665. {
  666. predict_ball();
  667. get_nearest();
  668. new_select=FALSE; // Can be same player...
  669. closest=FALSE;
  670. reselect_a();
  671. reselect_b();
  672. }
  673. /******************************************************************************
  674. *****************************************************************************/
  675. void reselect_all_users()
  676. {
  677. for (short i=0; i<num_of_users; i++)
  678. {
  679. reselect();
  680. }
  681. }
  682. /******************************************************************************
  683. *****************************************************************************/
  684. #ifdef FORCE_SELECT
  685. void force_users()
  686. {
  687. if (!match_mode && num_of_users)
  688. {
  689. short f_user;
  690. for (f_user=1; f_user<=MAX_USERS; f_user++)
  691. {
  692. if (!(forced&1))
  693. forced>>=1;
  694. else
  695. break;
  696. }
  697. short p=users[f_user-1].plr;
  698. short tm=(p<12 ? 12:23);
  699. for (short i=1; i<=10; i++)
  700. {
  701. if (++p==tm)
  702. p-=10; // Can't be keeper!
  703. if (sel_circle[p-1] && !teams[p-1].control)
  704. break;
  705. }
  706. if (i!=11)
  707. {
  708. // Successfull forced selection...
  709. if (p<12)
  710. last_plr_a=users[f_user-1].plr;
  711. else
  712. last_plr_b=users[f_user-1].plr;
  713. clear_auto(f_user);
  714. teams[p-1].control=f_user;
  715. users[f_user-1].chng=TRUE; // changed control
  716. users[f_user-1].plr=p;
  717. }
  718. }
  719. }
  720. #endif
  721. /******************************************************************************
  722. *****************************************************************************/
  723. void new_users()
  724. {
  725. #ifdef NO_AUTO_SEL
  726. if (!key_togs[0x43])
  727. #endif
  728. if (ball_poss && num_of_users && !match_mode)
  729. {
  730. // Normal play with users and some-one on ball!
  731. if (ball_travel++>select_cnt)
  732. {
  733. ball_travel=0;
  734. new_select=FALSE; // Can be same player...
  735. closest=TRUE;
  736. reselect_a();
  737. reselect_b();
  738. }
  739. }
  740. #ifdef FORCE_SELECT
  741. if (forced)
  742. force_users();
  743. #endif
  744. }