RULES.CPP 60 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979
  1. /******************************************************************************
  2. *******************************************************************************
  3. Match rules and control routines...
  4. ******************************************************************************
  5. *****************************************************************************/
  6. #include "global.h"
  7. #include "defines.h"
  8. #include "externs.h"
  9. #include "data.h"
  10. #include "audio.h"
  11. #include "front.h"
  12. #include "eurofrnt\euro_int.h"
  13. extern match_data match_info;
  14. extern team_info game_data[];
  15. extern setup_info setup;
  16. int timeout;
  17. extern char old_tac_a,old_tac_b;
  18. extern void load_new_tactics();
  19. /******************************************************************************
  20. *****************************************************************************/
  21. void decide_set_kick()
  22. {
  23. support_me=FALSE;
  24. int p;
  25. switch(set_piece_on)
  26. {
  27. case(SETP_CORNER):
  28. if (ref_wait<0)
  29. must_shoot=TRUE;
  30. p=pass_decide(&teams[setp_taker-1],TRUE);
  31. if (p)
  32. make_pass(&teams[setp_taker-1],p,TRUE);
  33. else
  34. if (shoot_decide(&teams[setp_taker-1]))
  35. make_shoot(&teams[setp_taker-1]);
  36. else
  37. support_me=TRUE; // No action (help).
  38. break;
  39. case(SETP_CENTRE):
  40. must_pass=TRUE;
  41. p=centre_guy_2;
  42. pass_type=5;
  43. if (p)
  44. make_pass(&teams[setp_taker-1],p,FALSE);
  45. else
  46. support_me=TRUE; // No action (help).
  47. must_pass=FALSE;
  48. break;
  49. case(SETP_IFKICK):
  50. if (ref_wait<0)
  51. must_punt=TRUE;
  52. p=pass_decide(&teams[setp_taker-1],FALSE);
  53. if (p)
  54. make_pass(&teams[setp_taker-1],p,FALSE);
  55. else
  56. if (punt_decide(&teams[setp_taker-1]))
  57. make_punt(&teams[setp_taker-1]);
  58. else
  59. support_me=TRUE; // No action (help).
  60. break;
  61. case(SETP_GKICK):
  62. if (ref_wait<0)
  63. must_punt=TRUE;
  64. p=pass_decide(&teams[setp_taker-1],FALSE);
  65. if (p && p!=KP_A && p!=KP_B)
  66. make_pass(&teams[setp_taker-1],p,FALSE);
  67. else
  68. {
  69. if (!seed&3)
  70. must_punt=TRUE;
  71. if (punt_decide(&teams[setp_taker-1]))
  72. make_punt(&teams[setp_taker-1]);
  73. else
  74. support_me=TRUE; // No action (help).
  75. }
  76. break;
  77. case(SETP_DFKICK):
  78. if (ref_wait<0)
  79. must_shoot=TRUE;
  80. p=pass_decide(&teams[setp_taker-1],FALSE);
  81. if (p)
  82. make_pass(&teams[setp_taker-1],p,FALSE);
  83. else
  84. if (punt_decide(&teams[setp_taker-1]))
  85. make_punt(&teams[setp_taker-1]);
  86. else
  87. if (shoot_decide(&teams[setp_taker-1]))
  88. make_shoot(&teams[setp_taker-1]);
  89. else
  90. support_me=TRUE; // No action (help).
  91. break;
  92. case(SETP_PENALTY):
  93. must_shoot=TRUE;
  94. if (shoot_decide(&teams[setp_taker-1]))
  95. {
  96. penalty_shot=TRUE;
  97. make_shoot(&teams[setp_taker-1]);
  98. }
  99. else
  100. support_me=TRUE; // No action (help).
  101. break;
  102. }
  103. }
  104. /******************************************************************************
  105. *****************************************************************************/
  106. char all_standing()
  107. {
  108. int i=0;
  109. if (--setp_wait_cnt)
  110. {
  111. for (i=0; i<players; i++)
  112. {
  113. if (teams[i].guy_on>0 && teams[i].tm_act!=STAND_ACT && teams[i].tm_act!=PICKUP_ACT
  114. && teams[i].dir_mode!=6 && (teams[i].tm_act!=RUN_ACT || teams[i].tm_off!=-2))
  115. i=100;
  116. }
  117. }
  118. else
  119. setp_wait_cnt=1;
  120. return((i<=players) ? TRUE:FALSE);
  121. }
  122. /******************************************************************************
  123. *****************************************************************************/
  124. void clear_wall()
  125. {
  126. for (int j=0; j<men_in_wall; j++)
  127. {
  128. teams[wguys[j].guy-1].tm_wall=0;
  129. }
  130. men_in_wall=0;
  131. }
  132. /******************************************************************************
  133. *****************************************************************************/
  134. void ready_set_kick()
  135. {
  136. if (set_piece_on)
  137. {
  138. if (men_in_wall && (match_mode==DF_KICK_A || match_mode==DF_KICK_B))
  139. clear_wall();
  140. arrow_on=FALSE;
  141. match_mode=0;
  142. offside_now=FALSE;
  143. dead_ball_cnt=0;
  144. game_action=0;
  145. teams[setp_taker-1].tm_leave=-TRUE; // Not allowed to touch ball after kick!
  146. user_taker=0;
  147. // Referee normal mode...
  148. refs[0].act=0;
  149. set_piece_on=FALSE;
  150. already_there=FALSE;
  151. reselect();
  152. }
  153. }
  154. /******************************************************************************
  155. *****************************************************************************/
  156. void go_set_kick(char type)
  157. {
  158. short p;
  159. if (type)
  160. {
  161. ready_set_kick();
  162. switch(type)
  163. {
  164. case(PASS_FEET):
  165. must_pass=TRUE;
  166. p=pass_decide(&teams[setp_taker-1],FALSE);
  167. if (p)
  168. make_pass(&teams[setp_taker-1],p,FALSE);
  169. break;
  170. case(PASS_HEAD):
  171. must_pass=TRUE;
  172. chip_pass=TRUE;
  173. p=(pass_decide(&teams[setp_taker-1],FALSE));
  174. if (p)
  175. make_pass(&teams[setp_taker-1],p,FALSE);
  176. break;
  177. case(PUNT):
  178. must_punt=TRUE;
  179. if (punt_decide(&teams[setp_taker-1]))
  180. make_punt(&teams[setp_taker-1]);
  181. break;
  182. default:
  183. must_pass=TRUE;
  184. break;
  185. }
  186. }
  187. }
  188. /******************************************************************************
  189. *****************************************************************************/
  190. void ready_ckick()
  191. {
  192. arrow_on=FALSE;
  193. match_mode=0;
  194. dead_ball_cnt=0;
  195. collect_ball(&teams[corner_taker-1]);
  196. game_action=0;
  197. teams[corner_taker-1].tm_leave=-TRUE; // Not allowed to touch ball!
  198. user_taker=0;
  199. }
  200. /******************************************************************************
  201. *****************************************************************************/
  202. void go_ckick(char type)
  203. {
  204. if (type)
  205. {
  206. ready_ckick();
  207. switch(type)
  208. {
  209. case(PASS_FEET):
  210. must_pass=TRUE;
  211. break;
  212. case(PASS_HEAD):
  213. must_pass=TRUE;
  214. break;
  215. case(PUNT):
  216. must_punt=TRUE;
  217. break;
  218. default:
  219. must_pass=TRUE;
  220. break;
  221. }
  222. }
  223. }
  224. /******************************************************************************
  225. *****************************************************************************/
  226. void await_set_kick()
  227. {
  228. if (!hold_up_play)
  229. {
  230. if ((!player_on_off && (all_standing() && already_there) || (support_me)))
  231. {
  232. if (!allow_replay)
  233. init_replay();
  234. if (ball_poss!=setp_taker)
  235. collect_ball(&teams[setp_taker-1]);
  236. if (refs[0].act==4)
  237. {
  238. // Referee wait for kick mode...
  239. refs[0].act=2;
  240. ktaker=setp_taker;
  241. ref_wait=(160-ref_strictness)*REAL_SPEED/8;
  242. play_fx(PS_SHORTWHISTLE,refs[0].x,refs[0].y);
  243. clock_running=TRUE;
  244. kickoff=FALSE;
  245. }
  246. if (user_taker)
  247. {
  248. if (reselection)
  249. {
  250. setp_kick_x=teams[setp_taker-1].tm_xdis;
  251. setp_kick_y=teams[setp_taker-1].tm_ydis;
  252. setp_power=0;
  253. setp_hgt=0;
  254. setp_byd=cntspot_y;
  255. reselection=FALSE;
  256. teams[setp_taker-1].dir_mode=1;
  257. teams[setp_taker-1].control=user_taker;
  258. users[user_taker-1].plr=setp_taker;
  259. #ifdef EURO96
  260. if (match_mode==PEN_KICK_A && user_taker2)
  261. {
  262. teams[KP_B-1].control=user_taker2;
  263. users[user_taker2-1].plr=KP_B;
  264. }
  265. if (match_mode==PEN_KICK_B && user_taker2)
  266. {
  267. teams[KP_A-1].control=user_taker2;
  268. users[user_taker2-1].plr=KP_A;
  269. }
  270. #endif
  271. reselect_all_users();
  272. arrow_on=TRUE;
  273. arrow_guy=setp_taker;
  274. if (match_mode>=GOAL_KICK_TL && match_mode<=GOAL_KICK_BR)
  275. support_me=FALSE;
  276. else
  277. support_me=TRUE;
  278. }
  279. }
  280. else
  281. {
  282. if (refs[0].act==2)
  283. {
  284. #ifdef EURO96
  285. if (match_mode!=PEN_KICK_A && match_mode!=PEN_KICK_B)
  286. #endif
  287. {
  288. decide_set_kick();
  289. if (!support_me)
  290. // Doesnt need support....
  291. ready_set_kick();
  292. }
  293. }
  294. }
  295. }
  296. }
  297. else
  298. hold_up_play--;
  299. }
  300. /*****************************************************************************
  301. *****************************************************************************/
  302. void swap_users()
  303. {
  304. // Team A users now play Team B...
  305. short p;
  306. for (int u=0; u<num_of_users; u++)
  307. {
  308. if (users[u].type>0)
  309. {
  310. // Fixed-player...
  311. if (users[u].type>11)
  312. users[u].type-=11;
  313. else
  314. users[u].type+=11;
  315. }
  316. else
  317. {
  318. // Auto-player...
  319. if (users[u].type==-1)
  320. users[u].type=-2;
  321. else
  322. users[u].type=-1;
  323. }
  324. p=users[u].plr;
  325. if (p>11)
  326. users[u].plr=p-11;
  327. else
  328. if (p<12 && p>0)
  329. users[u].plr=p+11;
  330. }
  331. p=auto_users_a;
  332. auto_users_a=auto_users_b;
  333. auto_users_b=p;
  334. short t[10];
  335. memcpy(&t,&auto_users_list_a,sizeof(t));
  336. memcpy(&auto_users_list_a,&auto_users_list_b,sizeof(t));
  337. memcpy(&auto_users_list_b,&t,sizeof(t));
  338. }
  339. /*****************************************************************************
  340. *****************************************************************************/
  341. void swap_teams()
  342. {
  343. match_half+=1;
  344. match_player a;
  345. swap_users();
  346. for (short p=0; p<11; p++)
  347. {
  348. memcpy(&a,&teams[p],sizeof(a));
  349. memcpy(&teams[p],&teams[p+11],sizeof(a));
  350. memcpy(&teams[p+11],&a,sizeof(a));
  351. teams[p].tm_player=p+1;
  352. teams[p+11].tm_player=p+12;
  353. }
  354. char t=team_a;
  355. team_a=team_b;
  356. team_b=t;
  357. p=players_off_a;
  358. players_off_a=players_off_b;
  359. players_off_b=p;
  360. old_tac_a=-1;
  361. old_tac_b=-1;
  362. load_new_tactics();
  363. }
  364. /*****************************************************************************
  365. *****************************************************************************/
  366. char in_tunnel()
  367. {
  368. for(short p=0; p<players; p++)
  369. {
  370. if (teams[p].draw_me)
  371. return(FALSE);
  372. }
  373. return(TRUE);
  374. }
  375. /*****************************************************************************
  376. *****************************************************************************/
  377. void await_swap()
  378. {
  379. if (in_tunnel() || !(timeout--))
  380. {
  381. if (match_half>=11)
  382. end_game=TRUE;
  383. else
  384. swap_teams();
  385. camera=old_cam;
  386. if (last_centre)
  387. {
  388. // Team A had last kick off...(not including goal respots)
  389. last_centre=FALSE;
  390. match_mode=CENTRE_B;
  391. init_match_mode();
  392. }
  393. else
  394. {
  395. // Team B had last kick off...(not including goal respots)
  396. last_centre=TRUE;
  397. match_mode=CENTRE_A;
  398. init_match_mode();
  399. }
  400. }
  401. }
  402. /*****************************************************************************
  403. *****************************************************************************/
  404. void remember_cam()
  405. {
  406. if (camera!=15)
  407. {
  408. old_cam=camera;
  409. }
  410. // old_cam is already remembered if camera=15!
  411. }
  412. /*****************************************************************************
  413. *****************************************************************************/
  414. void init_swap_ends()
  415. {
  416. allow_replay=FALSE;
  417. remember_cam();
  418. timeout=20*15;
  419. clock_running=FALSE;
  420. camera=16;
  421. reset_ball();
  422. dead_ball_cnt=40;
  423. for (int i=0; i<players; i++)
  424. {
  425. init_stand_act(&teams[i]);
  426. }
  427. }
  428. /******************************************************************************
  429. *****************************************************************************/
  430. void await_throw()
  431. {
  432. if (already_there && !player_on_off)
  433. {
  434. float x=teams[throw_in_taker-1].tm_x;
  435. float y=teams[throw_in_taker-1].tm_y;
  436. if (calc_dist(incident_x-x,incident_y-y)<prat*3)
  437. {
  438. if (user_taker)
  439. {
  440. if (reselection)
  441. {
  442. reselection=FALSE;
  443. teams[throw_in_taker-1].dir_mode=1;
  444. teams[throw_in_taker-1].control=user_taker;
  445. users[user_taker-1].plr=throw_in_taker;
  446. reselect_all_users();
  447. arrow_on=TRUE;
  448. arrow_guy=throw_in_taker;
  449. }
  450. }
  451. if (ball_in_hands)
  452. {
  453. match_mode=0;
  454. ball_in_hands=TRUE;
  455. init_throw_act(&teams[throw_in_taker-1]);
  456. collect_ball(&teams[throw_in_taker-1]);
  457. teams[throw_in_taker-1].tm_leave=-TRUE; // Not allowed to touch ball!
  458. }
  459. else
  460. {
  461. if (teams[throw_in_taker-1].tm_act!=PICKUP_ACT)
  462. init_pickup_act(&teams[throw_in_taker-1]);
  463. }
  464. }
  465. }
  466. }
  467. /******************************************************************************
  468. *****************************************************************************/
  469. void ball_situation()
  470. {
  471. if (match_mode)
  472. {
  473. if (match_mode==SWAP_ENDS)
  474. // Half time or extra time.
  475. await_swap();
  476. else
  477. if (set_piece_on!=SETP_THROW)
  478. await_set_kick();
  479. else
  480. await_throw();
  481. }
  482. }
  483. /******************************************************************************
  484. ******************************************************************************/
  485. void stop()
  486. {
  487. alarm=FALSE;
  488. mf_fixed=TRUE;
  489. stop_min+=1000;
  490. watch=TRUE;
  491. }
  492. /******************************************************************************
  493. ******************************************************************************/
  494. void add_player_time()
  495. {
  496. for (int p=0; p<22; p++)
  497. {
  498. teams[p].tm_time++;
  499. }
  500. }
  501. /******************************************************************************
  502. ******************************************************************************/
  503. void match_clock()
  504. {
  505. if (demo_match)
  506. rolling_clock--;
  507. if (!match_mode && !penalty_game && !stop_clock && !just_scored)
  508. {
  509. match_time.sec+=90.0/(time_factor*REAL_SPEED);
  510. if (match_time.sec>=60)
  511. {
  512. match_time.sec-=60;
  513. match_time.min+=1;
  514. add_player_time();
  515. }
  516. if ((alarm) && (match_time.min>=stop_min) && (match_time.sec>=stop_sec))
  517. stop();
  518. }
  519. }
  520. /******************************************************************************
  521. *****************************************************************************/
  522. void kill_ball()
  523. {
  524. reset_all_ideas();
  525. holder_lose_ball();
  526. stop_ball_spin();
  527. ballxdis=0;
  528. ballydis=0;
  529. ballzdis=0;
  530. ballx=incident_x;
  531. bally=incident_y;
  532. ballz=ball_diam/2;
  533. dead_ball_cnt=50;
  534. }
  535. /******************************************************************************
  536. *****************************************************************************/
  537. void pen_to_team_a()
  538. {
  539. away_pens_left--;
  540. // Team A penalty...
  541. match_mode=PEN_KICK_A;
  542. do{
  543. if (!(--pen_taker_a))
  544. pen_taker_a=10;
  545. }while(!teams[pen_taker_a].guy_on);
  546. // Guy hasn't been sent off!
  547. user_taker=user_taker_a(pen_taker_a+1);
  548. #ifdef EURO96
  549. user_taker2=user_keeper_b();
  550. #endif
  551. penalty_taker=pen_taker_a+1;
  552. }
  553. /******************************************************************************
  554. *****************************************************************************/
  555. void pen_to_team_b()
  556. {
  557. home_pens_left--;
  558. // Team B penalty...
  559. match_mode=PEN_KICK_B;
  560. do{
  561. if ((--pen_taker_b)==11)
  562. pen_taker_b=21;
  563. }while(!teams[pen_taker_b].guy_on);
  564. // Guy hasn't been sent off!
  565. user_taker=user_taker_b(pen_taker_b+1);
  566. #ifdef EURO96
  567. user_taker2=user_keeper_a();
  568. #endif
  569. penalty_taker=pen_taker_b+1;
  570. }
  571. /******************************************************************************
  572. *****************************************************************************/
  573. void do_penalties()
  574. {
  575. if (!match_mode)
  576. {
  577. // Normal play...
  578. if (!penalty_counter)
  579. {
  580. // Next penalty...
  581. if (penalties>=10 && !(penalties&1))
  582. {
  583. // If at least 5 penalties each and both taken same no...
  584. if (team_a_goals!=team_b_goals)
  585. {
  586. penalty_game=FALSE;
  587. }
  588. }
  589. else
  590. {
  591. if (penalties<10)
  592. {
  593. if (team_a_goals>team_b_goals)
  594. {
  595. // Home team winning...
  596. if (away_pens_left<(team_a_goals-team_b_goals))
  597. penalty_game=FALSE;
  598. }
  599. else
  600. {
  601. // Away team winning...
  602. if (home_pens_left<(team_b_goals-team_a_goals))
  603. penalty_game=FALSE;
  604. }
  605. }
  606. }
  607. if (penalty_game)
  608. {
  609. penalties++;
  610. penalty_counter=5*REAL_SPEED;
  611. kill_ball();
  612. game_action=2; // gather outside box!
  613. if (!penalty_team)
  614. {
  615. penalty_team=TRUE; // Setup next for team!
  616. if (match_half&1)
  617. pen_to_team_b();
  618. else
  619. pen_to_team_a();
  620. }
  621. else
  622. {
  623. penalty_team=FALSE; // Setup next for team!
  624. if (match_half&1)
  625. pen_to_team_a();
  626. else
  627. pen_to_team_b();
  628. }
  629. init_match_mode();
  630. }
  631. }
  632. else
  633. {
  634. penalty_counter--;
  635. }
  636. }
  637. }
  638. /******************************************************************************
  639. *****************************************************************************/
  640. void match_rules()
  641. {
  642. if (penalty_game)
  643. {
  644. if (match_mode!=PEN_KICK_A && match_mode!=PEN_KICK_B && match_mode!=SWAP_ENDS)
  645. match_mode=0;
  646. do_penalties();
  647. }
  648. match_clock();
  649. if (dead_ball_cnt)
  650. ball_situation();
  651. }
  652. /******************************************************************************
  653. *****************************************************************************/
  654. char bounds_rules()
  655. {
  656. float xoff=0;
  657. float yoff=0;
  658. /***********************/
  659. if (ballx<0)
  660. {
  661. // Past Left Goal-line...
  662. xoff=-ballx;
  663. if (last_touch<12)
  664. {
  665. // Corner!
  666. if (!team_b_on)
  667. {
  668. if (bally>cntspot_y)
  669. return(GOAL_KICK_BL);
  670. else
  671. return(GOAL_KICK_TL);
  672. }
  673. else
  674. {
  675. if (bally>cntspot_y)
  676. return(CORNER_BL);
  677. else
  678. return(CORNER_TL);
  679. }
  680. }
  681. else
  682. {
  683. // Goal Kick!
  684. if (!team_a_on)
  685. {
  686. if (bally>cntspot_y)
  687. return(CORNER_BL);
  688. else
  689. return(CORNER_TL);
  690. }
  691. else
  692. {
  693. if (bally>cntspot_y)
  694. return(GOAL_KICK_BL);
  695. else
  696. return(GOAL_KICK_TL);
  697. }
  698. }
  699. }
  700. /***********************/
  701. if (ballx>=pitch_len)
  702. {
  703. // Past Right Goal-line...
  704. xoff=ballx-(pitch_len-1);
  705. if (last_touch>11)
  706. {
  707. // Corner!
  708. if (!team_a_on)
  709. {
  710. if (bally>cntspot_y)
  711. return(GOAL_KICK_BR);
  712. else
  713. return(GOAL_KICK_TR);
  714. }
  715. else
  716. {
  717. if (bally>cntspot_y)
  718. return(CORNER_BR);
  719. else
  720. return(CORNER_TR);
  721. }
  722. }
  723. else
  724. {
  725. // Goal Kick!
  726. if (!team_b_on)
  727. {
  728. if (bally>cntspot_y)
  729. return(CORNER_BR);
  730. else
  731. return(CORNER_TR);
  732. }
  733. else
  734. {
  735. if (bally>cntspot_y)
  736. return(GOAL_KICK_BR);
  737. else
  738. return(GOAL_KICK_TR);
  739. }
  740. }
  741. }
  742. /***********************/
  743. if (bally<0)
  744. yoff=-bally;
  745. if (bally>=pitch_wid)
  746. yoff=bally-(pitch_wid-1);
  747. if (yoff>xoff)
  748. {
  749. // Over top side-line...
  750. incident_x=ballx;
  751. incident_y=((bally<0) ? 0:pitch_wid-1);
  752. if (last_touch<12)
  753. // Throw-in to team B!
  754. if (!team_b_on)
  755. return(THROW_IN_A);
  756. else
  757. return(THROW_IN_B);
  758. else
  759. if (!team_a_on)
  760. return(THROW_IN_B);
  761. else
  762. return(THROW_IN_A);
  763. }
  764. return(0);
  765. }
  766. /******************************************************************************
  767. *****************************************************************************/
  768. // INITIALISE MATCH SITUATIONS...
  769. /******************************************************************************
  770. *****************************************************************************/
  771. /******************************************************************************
  772. *****************************************************************************/
  773. void throw_taker(int p)
  774. {
  775. // Decision is made on the closest tactical position at current ball_zone...
  776. int min_d=1000;
  777. int d;
  778. for (int pn=p; pn<p+10; pn++)
  779. {
  780. if (teams[pn-1].guy_on>0)
  781. {
  782. if (pn<12)
  783. d=calc_dist(ballx-match_tactics1[ball_zone1][pn-2][0],
  784. bally-match_tactics1[ball_zone1][pn-2][1]);
  785. else
  786. d=calc_dist((pitch_len-ballx)-match_tactics2[ball_zone2][pn-13][0],
  787. (pitch_wid-bally)-match_tactics2[ball_zone2][pn-13][1]);
  788. if (d<min_d)
  789. {
  790. min_d=d;
  791. throw_in_taker=pn;
  792. }
  793. }
  794. }
  795. }
  796. /******************************************************************************
  797. *****************************************************************************/
  798. int get_taker(int p)
  799. {
  800. // Decision is made on the closest tactical position at current ball_zone...
  801. int min_d=1000;
  802. int d,taker;
  803. for (int pn=p; pn<(p<12 ? 12:23); pn++)
  804. {
  805. if (teams[pn-1].guy_on>0)
  806. {
  807. if (pn==KP_A)
  808. d=calc_dist(ballx-0,bally-cntspot_y);
  809. else
  810. if (pn==KP_B)
  811. d=calc_dist(pitch_len,bally-cntspot_y);
  812. else
  813. if (pn<12)
  814. d=calc_dist(ballx-match_tactics1[ball_zone1][pn-2][0],
  815. bally-match_tactics1[ball_zone1][pn-2][1]);
  816. else
  817. d=calc_dist((pitch_len-ballx)-match_tactics2[ball_zone2][pn-13][0],
  818. (pitch_wid-bally)-match_tactics2[ball_zone2][pn-13][1]);
  819. if (d<min_d)
  820. {
  821. min_d=d;
  822. taker=pn;
  823. }
  824. }
  825. }
  826. return(taker);
  827. }
  828. /******************************************************************************
  829. *****************************************************************************/
  830. void centre_takers()
  831. {
  832. int p;
  833. centre_guy_1=0;
  834. centre_guy_2=0;
  835. if (match_mode==CENTRE_A)
  836. {
  837. p=2;
  838. flag=TRUE;
  839. }
  840. else
  841. {
  842. p=13;
  843. flag=FALSE;
  844. }
  845. int d;
  846. int min_d=1000;
  847. // Decide on which two players shall take centre.
  848. // Decision is made on the two closest tactical positions...
  849. for (int pn=p; pn<p+10; pn++)
  850. {
  851. if (teams[pn-1].guy_on>0)
  852. {
  853. if (flag)
  854. d=calc_dist(cntspot_x-match_tactics1[68][pn-2][0],
  855. cntspot_y-match_tactics1[68][pn-2][1]);
  856. else
  857. d=calc_dist(cntspot_x-match_tactics2[68][pn-13][0],
  858. cntspot_y-match_tactics2[68][pn-13][1]);
  859. if (d<min_d)
  860. {
  861. min_d=d;
  862. centre_guy_1=pn;
  863. }
  864. }
  865. }
  866. min_d=1000;
  867. for (pn=p; pn<p+10; pn++)
  868. {
  869. if (teams[pn-1].guy_on>0)
  870. {
  871. if (flag)
  872. d=calc_dist(cntspot_x-match_tactics1[68][pn-2][0],
  873. cntspot_y-match_tactics1[68][pn-2][1]);
  874. else
  875. d=calc_dist(cntspot_x-match_tactics2[68][pn-13][0],
  876. cntspot_y-match_tactics2[68][pn-13][1]);
  877. if ((d<min_d) && (centre_guy_1!=pn))
  878. {
  879. min_d=d;
  880. centre_guy_2=pn;
  881. }
  882. }
  883. }
  884. }
  885. /******************************************************************************
  886. *****************************************************************************/
  887. void init_centre()
  888. {
  889. if (kickoff && next_mins)
  890. {
  891. match_time.min=next_mins;
  892. match_time.sec=0;
  893. match_mode=CENTRE_A;
  894. last_goal=0;
  895. }
  896. reset_ball();
  897. dead_ball_cnt=40;
  898. ballx=cntspot_x;
  899. bally=cntspot_y;
  900. ballz=ball_diam/2;
  901. if (match_mode==CENTRE_A)
  902. {
  903. // Team A centre.
  904. ball_zone1=68;
  905. ball_zone2=69;
  906. refs[0].goto_x=cntspot_x+5*prat;
  907. centre_takers();
  908. do_kickoff_menu(team_a);
  909. }
  910. else
  911. {
  912. // Team B centre.
  913. ball_zone2=68;
  914. ball_zone1=69;
  915. refs[0].goto_x=cntspot_x-5*prat;
  916. centre_takers();
  917. do_kickoff_menu(team_b);
  918. }
  919. game_action=1; // 10 Yards away!
  920. // Referee go to spot behind incident...
  921. refs[0].act=1;
  922. refs[0].target=0; // Ball!
  923. refs[0].goto_y=cntspot_y;
  924. main_man=centre_guy_1;
  925. user_taker=0;
  926. /*
  927. if (centre_guy_1>11)
  928. user_taker=user_taker_b(centre_guy_1);
  929. else
  930. user_taker=user_taker_a(centre_guy_1);
  931. */
  932. }
  933. /******************************************************************************
  934. *****************************************************************************/
  935. void init_corner()
  936. {
  937. PlayCommentaryMessage(SP_CORNER);
  938. comsetp=40;
  939. user_taker=0;
  940. dead_ball_cnt=20;
  941. switch(match_mode)
  942. {
  943. case(CORNER_TL):
  944. ballx=prat-1;
  945. bally=prat-1;
  946. ballz=ball_diam/2;
  947. ball_zone1=64;
  948. ball_zone2=67;
  949. last_touch=12; // team b has possession.
  950. if ((corn_kicker_b) && (teams[corn_kicker_b-1].guy_on>0))
  951. corner_taker=corn_kicker_b;
  952. else
  953. corner_taker=get_taker(13);
  954. do_corner_menu(team_b);
  955. break;
  956. case(CORNER_BL):
  957. ballx=prat-1;
  958. bally=pitch_wid-prat+1;
  959. ballz=ball_diam/2;
  960. ball_zone1=66;
  961. ball_zone2=65;
  962. last_touch=12; // team b has possession.
  963. if ((corn_kicker_b) && (teams[corn_kicker_b-1].guy_on>0))
  964. corner_taker=corn_kicker_b;
  965. else
  966. corner_taker=get_taker(13);
  967. do_corner_menu(team_b);
  968. break;
  969. case(CORNER_TR):
  970. ballx=pitch_len-prat+1;
  971. bally=prat-1;
  972. ballz=ball_diam/2;
  973. ball_zone1=65;
  974. ball_zone2=66;
  975. last_touch=1; // team a has possession.
  976. if ((corn_kicker_a) && (teams[corn_kicker_a-1].guy_on>0))
  977. corner_taker=corn_kicker_a;
  978. else
  979. corner_taker=get_taker(2);
  980. do_corner_menu(team_a);
  981. break;
  982. case(CORNER_BR):
  983. ballx=pitch_len-prat+1;
  984. bally=pitch_wid-prat+1;
  985. ballz=ball_diam/2;
  986. ball_zone1=67;
  987. ball_zone2=64;
  988. last_touch=1; // team a has possession.
  989. if ((corn_kicker_a) && (teams[corn_kicker_a-1].guy_on>0))
  990. corner_taker=corn_kicker_a;
  991. else
  992. corner_taker=get_taker(2);
  993. do_corner_menu(team_a);
  994. break;
  995. }
  996. incident_x=ballx+((ballx<cntspot_x) ? -4:4);
  997. incident_y=bally+((bally<cntspot_y) ? -8:8);
  998. game_action=1; // 10 Yards away!
  999. if (corner_taker>11)
  1000. user_taker=user_taker_b(corner_taker);
  1001. else
  1002. user_taker=user_taker_a(corner_taker);
  1003. main_man=corner_taker;
  1004. // Referee go to spot between centre spot and ball...
  1005. refs[0].act=1;
  1006. refs[0].target=0; // Ball!
  1007. refs[0].goto_x=cntspot_x+((ballx-cntspot_x)/2);
  1008. refs[0].goto_y=cntspot_y+((bally-cntspot_y)/2);
  1009. last_touch=main_man;
  1010. pre_kp_touch=last_touch;
  1011. ball_in_hands=FALSE;
  1012. }
  1013. /******************************************************************************
  1014. *****************************************************************************/
  1015. void init_gkick()
  1016. {
  1017. if (fired_a_shot)
  1018. {
  1019. if ((ABS(bally_out-cntspot_y)>prat*7) || (ballz_out>prat*4))
  1020. // Miles away...
  1021. PlayCommentaryMessage(PM_WIDE);
  1022. else
  1023. // Near miss..
  1024. PlayCommentaryMessage(PM_CLOSE);
  1025. }
  1026. else
  1027. PlayCommentaryMessage(SP_GOALKICK);
  1028. dead_ball_cnt=100;
  1029. switch(match_mode)
  1030. {
  1031. case(GOAL_KICK_TL):
  1032. ballx=(5.8*prat);
  1033. bally=cntspot_y-(5.0*prat);
  1034. ballz=ball_diam/2;
  1035. ball_zone1=11;
  1036. ball_zone2=20;
  1037. last_touch=1; // team a has possession.
  1038. if ((goal_kicker_a) && (teams[goal_kicker_a-1].guy_on>0))
  1039. gkick_taker=goal_kicker_a;
  1040. else
  1041. gkick_taker=get_taker(1);
  1042. do_goalkick_menu(team_a);
  1043. break;
  1044. case(GOAL_KICK_BL):
  1045. ballx=(5.8*prat);
  1046. bally=cntspot_y+(5.0*prat);
  1047. ballz=ball_diam/2;
  1048. ball_zone1=19;
  1049. ball_zone2=12;
  1050. last_touch=1; // team a has possession.
  1051. if ((goal_kicker_a) && (teams[goal_kicker_a-1].guy_on>0))
  1052. gkick_taker=goal_kicker_a;
  1053. else
  1054. gkick_taker=get_taker(1);
  1055. do_goalkick_menu(team_a);
  1056. break;
  1057. case(GOAL_KICK_TR):
  1058. ballx=pitch_len-(5.8*prat);
  1059. bally=cntspot_y-(5.0*prat);
  1060. ballz=ball_diam/2;
  1061. ball_zone1=12;
  1062. ball_zone2=19;
  1063. last_touch=12; // team b has possession.
  1064. if ((goal_kicker_b) && (teams[goal_kicker_b-1].guy_on>0))
  1065. gkick_taker=goal_kicker_b;
  1066. else
  1067. gkick_taker=get_taker(12);
  1068. do_goalkick_menu(team_b);
  1069. break;
  1070. case(GOAL_KICK_BR):
  1071. ballx=pitch_len-(5.8*prat);
  1072. bally=cntspot_y+(5.0*prat);
  1073. ballz=ball_diam/2;
  1074. ball_zone1=20;
  1075. ball_zone2=11;
  1076. last_touch=12; // team b has possession.
  1077. if ((goal_kicker_b) && (teams[goal_kicker_b-1].guy_on>0))
  1078. gkick_taker=goal_kicker_b;
  1079. else
  1080. gkick_taker=get_taker(12);
  1081. do_goalkick_menu(team_b);
  1082. break;
  1083. }
  1084. incident_x=ballx;
  1085. incident_y=bally;
  1086. game_action=1; // 10 Yards away!
  1087. main_man=gkick_taker;
  1088. // Referee go to spot between centre spot and ball...
  1089. refs[0].act=1;
  1090. refs[0].target=0; // Ball!
  1091. refs[0].goto_x=cntspot_x+((ballx-cntspot_x)/2);
  1092. refs[0].goto_y=cntspot_y+((bally-cntspot_y)/2);
  1093. last_touch=main_man;
  1094. pre_kp_touch=last_touch;
  1095. user_taker=0;
  1096. if (gkick_taker>11)
  1097. user_taker=user_taker_b(gkick_taker);
  1098. else
  1099. user_taker=user_taker_a(gkick_taker);
  1100. float ang=(64.-seed)*(PI/(8*64));
  1101. if (match_mode<GOAL_KICK_TR)
  1102. {
  1103. // Goal_kick to team A...
  1104. taker_x=ballx-(cos(ang)*4);
  1105. taker_y=bally+(sin(ang)*4);
  1106. }
  1107. else
  1108. {
  1109. // Goal_kick to team B...
  1110. taker_x=ballx+(cos(ang)*4);
  1111. taker_y=bally+(sin(ang)*4);
  1112. }
  1113. }
  1114. /******************************************************************************
  1115. *****************************************************************************/
  1116. void init_throw()
  1117. {
  1118. stop_clock=TRUE;
  1119. user_taker=0;
  1120. dead_ball_cnt=100;
  1121. if (match_mode==THROW_IN_A)
  1122. {
  1123. do_throw_menu(team_a);
  1124. last_touch=1; // Team A have possession...
  1125. throw_taker(2);
  1126. if (ballx_out>(pitch_len-(prat*20)))
  1127. PlayCommentaryMessage(SP_LONGTHROWIN);
  1128. else
  1129. PlayCommentaryMessage(SP_THROWIN);
  1130. }
  1131. if (match_mode==THROW_IN_B)
  1132. {
  1133. do_throw_menu(team_b);
  1134. last_touch=12; // Team B have possession...
  1135. throw_taker(13);
  1136. if (ballx_out<(prat*20))
  1137. PlayCommentaryMessage(SP_LONGTHROWIN);
  1138. else
  1139. PlayCommentaryMessage(SP_THROWIN);
  1140. }
  1141. teams[throw_in_taker-1].int_move=I_THROW;
  1142. ballx=incident_x;
  1143. bally=incident_y;
  1144. ballz=ball_diam/2;
  1145. game_action=1; // 10 Yards away!
  1146. if (throw_in_taker>11)
  1147. user_taker=user_taker_b(throw_in_taker);
  1148. else
  1149. user_taker=user_taker_a(throw_in_taker);
  1150. // Linesman go to spot behind incident...
  1151. if (bally>cntspot_y)
  1152. // Bottom linesman....
  1153. {
  1154. refs[2].act=1;
  1155. refs[2].goto_y=refs[2].y;
  1156. if (refs[2].x>ballx+prat*4)
  1157. refs[2].goto_x=ballx+prat*4;
  1158. else
  1159. if (refs[2].x<ballx-prat*4)
  1160. refs[2].goto_x=ballx-prat*4;
  1161. else
  1162. refs[2].act=0;
  1163. }
  1164. else
  1165. // Top linesman....
  1166. {
  1167. refs[1].act=1;
  1168. refs[1].goto_y=refs[1].y;
  1169. if (refs[1].x>ballx+prat*4)
  1170. refs[1].goto_x=ballx+prat*4;
  1171. else
  1172. if (refs[1].x<ballx-prat*4)
  1173. refs[1].goto_x=ballx-prat*4;
  1174. else
  1175. refs[1].act=0;
  1176. }
  1177. main_man=throw_in_taker;
  1178. }
  1179. /******************************************************************************
  1180. *****************************************************************************/
  1181. char penalty(int fouler)
  1182. {
  1183. if (ballx<cntspot_x)
  1184. {
  1185. // Team A box...
  1186. if ((fouler<12) && (ballx<prat*18) && (bally<cntspot_y+(prat*22)) && (bally>cntspot_y-(prat*22)))
  1187. return(TRUE);
  1188. }
  1189. else
  1190. {
  1191. // Team B box...
  1192. if ((fouler>11) && (ballx>pitch_len-(prat*18)) && (bally<cntspot_y+(prat*22)) && (bally>cntspot_y-(prat*22)))
  1193. return(TRUE);
  1194. }
  1195. return(FALSE);
  1196. }
  1197. /******************************************************************************
  1198. *****************************************************************************/
  1199. void init_offside(match_player *player)
  1200. {
  1201. float d,x;
  1202. if (player->tm_player>11)
  1203. // Top linesman...
  1204. {
  1205. x=defense_a-player->tm_x; // How much offside.
  1206. d=(pitch_wid-calc_dist(player->tm_x-refs[1].x,player->tm_y-refs[1].y))/prat;
  1207. }
  1208. else
  1209. // Bot linesman...
  1210. {
  1211. x=player->tm_x-defense_b; // How much offside.
  1212. d=(pitch_wid-calc_dist(player->tm_x-refs[2].x,player->tm_y-refs[2].y))/prat;
  1213. }
  1214. d=ref_accuracy/2+(ref_accuracy*((d*d*0.000740740)-(0.07*d)+1));
  1215. if (d<1)
  1216. d=1;
  1217. if (seed<d/2+x)
  1218. {
  1219. // The linesman sees the Offside...
  1220. player->tm_off=TRUE;
  1221. }
  1222. else
  1223. {
  1224. short rel=(128-ref_accuracy)/4;
  1225. player->tm_off=-TRUE;
  1226. if (ball_released<0)
  1227. {
  1228. ball_released+=rel;
  1229. if (ball_released>0)
  1230. ball_released=0;
  1231. }
  1232. else
  1233. {
  1234. ball_released-=rel;
  1235. if (ball_released<0)
  1236. ball_released=0;
  1237. }
  1238. }
  1239. }
  1240. /******************************************************************************
  1241. *****************************************************************************/
  1242. void big_yeller(int plr)
  1243. {
  1244. card_is_out=3*REAL_SPEED;
  1245. int t;
  1246. booking=TRUE;
  1247. if (plr<12)
  1248. t=team_a;
  1249. else
  1250. t=team_b;
  1251. PlayCommentaryMessage(FU_YELLOWCARD);
  1252. do_booked_menu(t,teams[plr-1].shirt-1);
  1253. inc_yellow(plr);
  1254. }
  1255. /******************************************************************************
  1256. *****************************************************************************/
  1257. void ger_em_off(int plr)
  1258. {
  1259. // Off
  1260. inc_red(plr);
  1261. card_is_out=6*REAL_SPEED;
  1262. booking=TRUE;
  1263. if (plr<12)
  1264. players_off_a++;
  1265. else
  1266. players_off_b++;
  1267. player_on_off=plr;
  1268. sub_camera=camera;
  1269. camera=17;
  1270. reset_ideas(&teams[plr-1]);
  1271. init_off_int(&teams[plr-1]);
  1272. PlayCommentaryMessage(FU_REDCARD);
  1273. int t,p;
  1274. if (plr<12)
  1275. {
  1276. t=team_a;
  1277. game_data[team_a==0 ? setup.team_a:setup.team_b].players[plr-1].flags|=2;
  1278. }
  1279. else
  1280. {
  1281. t=team_b;
  1282. game_data[team_b==0 ? setup.team_a:setup.team_b].players[plr-12].flags|=2;
  1283. }
  1284. do_off_menu(t,teams[plr-1].shirt-1);
  1285. // teams[plr-1].guy_on=-1; // Waiting to be sent off!
  1286. if (corn_kicker_a==plr)
  1287. corn_kicker_a=0;
  1288. if (corn_kicker_b==plr)
  1289. corn_kicker_b=0;
  1290. if (goal_kicker_a==plr)
  1291. if (plr<12)
  1292. goal_kicker_a=KP_A;
  1293. else
  1294. goal_kicker_a=KP_B;
  1295. if (goal_kicker_b==plr)
  1296. if (plr<12)
  1297. goal_kicker_a=KP_A;
  1298. else
  1299. goal_kicker_a=KP_B;
  1300. if (fkick_taker_a==plr)
  1301. fkick_taker_a=0;
  1302. if (fkick_taker_b==plr)
  1303. fkick_taker_b=0;
  1304. }
  1305. /******************************************************************************
  1306. *****************************************************************************/
  1307. void send_off_plr(int plr,float nasty)
  1308. {
  1309. if (plr!=KP_A && plr!=KP_B && EUROmatch_info.bookings)
  1310. {
  1311. if (teams[plr-1].tm_book)
  1312. {
  1313. // He's had a yellow card...
  1314. if (nasty>seed)
  1315. {
  1316. if ((plr<12 && players_off_a<5) || (plr>11 && players_off_b<5))
  1317. ger_em_off(plr);
  1318. }
  1319. }
  1320. else
  1321. {
  1322. if (nasty>seed*4)
  1323. {
  1324. if ((plr<12 && players_off_a<5) || (plr>11 && players_off_b<5))
  1325. ger_em_off(plr);
  1326. }
  1327. else
  1328. if (nasty>seed)
  1329. big_yeller(plr);
  1330. }
  1331. }
  1332. }
  1333. /******************************************************************************
  1334. *****************************************************************************/
  1335. void punish_foul(int fouler,char direct)
  1336. {
  1337. user_taker=0;
  1338. in_range=FALSE;
  1339. reset_all_ideas();
  1340. holder_lose_ball();
  1341. stop_ball_spin();
  1342. ballxdis=0;
  1343. ballydis=0;
  1344. ballzdis=0;
  1345. ballx=incident_x;
  1346. bally=incident_y;
  1347. ballz=ball_diam/2;
  1348. dead_ball_cnt=50;
  1349. last_touch=fouler;
  1350. float nastiness;
  1351. booking=0;
  1352. nastiness=sqrt(teams[last_touch-1].tm_dist*4)*ref_strictness/6; // distance to ball. (how late was the challenge?)
  1353. if (!man_down)
  1354. nastiness/=3;
  1355. // Shall we send him off?
  1356. if (direct)
  1357. send_off_plr(last_touch,nastiness);
  1358. if (direct && (penalty(fouler)))
  1359. {
  1360. inc_pfoul(fouler);
  1361. if (seed&2 && !player_on_off)
  1362. PlayCommentaryMessage(FU_DIVE);
  1363. init_speech(players+1,SAY_PENALTY);
  1364. game_action=2; // gather outside box!
  1365. if (fouler>11)
  1366. // Team A P.K.
  1367. {
  1368. match_mode=PEN_KICK_A;
  1369. if ((penalty_taker_a) && (teams[penalty_taker_a-1].guy_on>0))
  1370. penalty_taker=penalty_taker_a;
  1371. else
  1372. penalty_taker=get_taker(2);
  1373. if (!booking)
  1374. do_penalty_menu(team_a);
  1375. user_taker=user_taker_a(penalty_taker);
  1376. #ifdef EURO96
  1377. user_taker2=user_keeper_b();
  1378. #endif
  1379. }
  1380. else
  1381. // Team B P.K.
  1382. {
  1383. match_mode=PEN_KICK_B;
  1384. if ((penalty_taker_b) && (teams[penalty_taker_b-1].guy_on>0))
  1385. penalty_taker=penalty_taker_b;
  1386. else
  1387. penalty_taker=get_taker(13);
  1388. if (!booking)
  1389. do_penalty_menu(team_b);
  1390. user_taker=user_taker_b(penalty_taker);
  1391. #ifdef EURO96
  1392. user_taker2=user_keeper_a();
  1393. #endif
  1394. }
  1395. }
  1396. else
  1397. {
  1398. game_action=1; // 10 Yards away!
  1399. if (fouler>11)
  1400. // Team A F.K.
  1401. {
  1402. if (!direct)
  1403. {
  1404. // Not on the ball..(INDIRECT)
  1405. inc_ifoul(fouler);
  1406. init_speech(players+1,SAY_OFFSIDE);
  1407. match_mode=IF_KICK_A;
  1408. fkick_taker=get_taker(2);
  1409. if (!booking)
  1410. if (offside_now)
  1411. do_offside_menu(team_a);
  1412. else
  1413. do_indirect_menu(team_a);
  1414. }
  1415. else
  1416. // On the ball..(DIRECT)
  1417. {
  1418. if (!player_on_off)
  1419. {
  1420. if (seed&64)
  1421. PlayCommentaryMessage(FU_BADFOUL);
  1422. else
  1423. PlayCommentaryMessage(FU_FREEKICK);
  1424. }
  1425. inc_dfoul(fouler);
  1426. init_speech(players+1,SAY_FOUL);
  1427. match_mode=DF_KICK_A;
  1428. if ((fkick_taker_a) && (teams[fkick_taker_a-1].guy_on>0))
  1429. fkick_taker=fkick_taker_a;
  1430. else
  1431. fkick_taker=get_taker(2);
  1432. }
  1433. user_taker=user_taker_a(fkick_taker);
  1434. }
  1435. else
  1436. // Team B F.K.
  1437. {
  1438. if (!direct)
  1439. {
  1440. // Not on the ball..(INDIRECT)
  1441. inc_ifoul(fouler);
  1442. init_speech(players+1,SAY_OFFSIDE);
  1443. match_mode=IF_KICK_B;
  1444. fkick_taker=get_taker(13);
  1445. if (!booking)
  1446. if (offside_now)
  1447. do_offside_menu(team_b);
  1448. else
  1449. do_indirect_menu(team_a);
  1450. }
  1451. else
  1452. // On the ball..(DIRECT)
  1453. {
  1454. if (!player_on_off)
  1455. {
  1456. if (seed&64)
  1457. PlayCommentaryMessage(FU_BADFOUL);
  1458. else
  1459. PlayCommentaryMessage(FU_FREEKICK);
  1460. }
  1461. inc_dfoul(fouler);
  1462. init_speech(players+1,SAY_FOUL);
  1463. match_mode=DF_KICK_B;
  1464. if ((fkick_taker_b) && (teams[fkick_taker_b-1].guy_on>0))
  1465. fkick_taker=fkick_taker_b;
  1466. else
  1467. fkick_taker=get_taker(13);
  1468. }
  1469. user_taker=user_taker_b(fkick_taker);
  1470. }
  1471. }
  1472. init_match_mode();
  1473. }
  1474. /******************************************************************************
  1475. *****************************************************************************/
  1476. void retake_foul()
  1477. {
  1478. punish_foul(bad_guy,direct_fk);
  1479. play_advantage=FALSE;
  1480. }
  1481. /******************************************************************************
  1482. *****************************************************************************/
  1483. void init_foul(int fouler,char direct,char see)
  1484. {
  1485. play_advantage=FALSE;
  1486. af_randomize();
  1487. float x,y,d;
  1488. d=calc_dist(ballx-refs[0].x,bally-refs[0].y)/prat;
  1489. d=(ref_accuracy/d)*2*man_down;
  1490. if (d>128)
  1491. d=128;
  1492. if (!just_scored && EUROmatch_info.freekicks && ((seed<d) || (see)))
  1493. {
  1494. incident_x=teams[fouler-1].tm_x;
  1495. incident_y=teams[fouler-1].tm_y;
  1496. direct_fk=direct;
  1497. bad_guy=fouler;
  1498. // The referee sees the foul...
  1499. if (offside_now)
  1500. // Cannot play advantage with offside rule...
  1501. punish_foul(fouler,direct_fk);
  1502. else
  1503. {
  1504. af_randomize();
  1505. // May play advantage...
  1506. if (fouler<12)
  1507. // Team A commited foul...
  1508. {
  1509. if ((!ball_poss) && (seed>ref_strictness))
  1510. // Ball is free...play temporary advantage...
  1511. {
  1512. play_advantage=TRUE;
  1513. init_speech(players+1,SAY_ADV);
  1514. }
  1515. else
  1516. if (ball_poss<12)
  1517. punish_foul(fouler,direct_fk);
  1518. }
  1519. else
  1520. // Team B commited foul...
  1521. {
  1522. if ((!ball_poss) && (seed>ref_strictness))
  1523. // Ball is free...play temporary advantage...
  1524. {
  1525. play_advantage=TRUE;
  1526. init_speech(players+1,SAY_ADV);
  1527. }
  1528. else
  1529. if (ball_poss>11 || !ball_poss)
  1530. punish_foul(fouler,direct_fk);
  1531. }
  1532. }
  1533. }
  1534. else
  1535. {
  1536. if (seed&2 && !just_scored)
  1537. PlayCommentaryMessage(FU_DIVE);
  1538. }
  1539. }
  1540. /******************************************************************************
  1541. *****************************************************************************/
  1542. extern int pen_cnt;
  1543. void force_penalty()
  1544. {
  1545. pen_cnt=100;
  1546. holder_lose_ball();
  1547. ball_poss=12;
  1548. ballx=pitch_len-2;
  1549. bally=cntspot_y;
  1550. ballz=ball_diam/2;
  1551. init_foul(13,TRUE,TRUE);
  1552. }
  1553. /******************************************************************************
  1554. *****************************************************************************/
  1555. void init_fkick()
  1556. {
  1557. float x,y,d;
  1558. if (last_touch<12)
  1559. x=-ballx;
  1560. else
  1561. x=pitch_len-ballx;
  1562. y=cntspot_y-bally;
  1563. d=calc_dist(x,y);
  1564. taker_x=ballx-(x*BESIDE_BALL/d);
  1565. taker_y=bally-(y*BESIDE_BALL/d);
  1566. // Referee go to spot behind incident...
  1567. refs[0].act=1;
  1568. refs[0].target=0; // Ball!
  1569. float rx=refs[0].x-ballx;
  1570. float ry=refs[0].y-bally;
  1571. float rd=calc_dist(rx,ry);
  1572. refs[0].goto_x=ballx+(rx*BESIDE_BALL*16/rd);
  1573. refs[0].goto_y=bally+(ry*BESIDE_BALL*16/rd);
  1574. main_man=fkick_taker;
  1575. last_touch=fkick_taker;
  1576. pre_kp_touch=last_touch;
  1577. }
  1578. /******************************************************************************
  1579. *****************************************************************************/
  1580. void find_wall_guys(int guys,float x,float y)
  1581. {
  1582. int d,pn,min_d,wall_cnt;
  1583. float dist=prat*0.9;
  1584. float xd=x*dist;
  1585. float yd=y*dist;
  1586. float cx=wallx-xd;
  1587. float cy=wally-yd;
  1588. wall_cnt=0;
  1589. for (int j=0; j<men_in_wall; j++)
  1590. {
  1591. min_d=2000;
  1592. for (int i=guys; i<guys+10; i++)
  1593. {
  1594. if ((!teams[i-1].tm_wall) && (teams[i-1].guy_on>0))
  1595. {
  1596. if (i<12)
  1597. d=calc_dist(ballx-match_tactics1[ball_zone1][i-2][0],
  1598. bally-match_tactics1[ball_zone1][i-2][1]);
  1599. else
  1600. d=calc_dist((pitch_len-ballx)-match_tactics2[ball_zone2][i-13][0],
  1601. (pitch_wid-bally)-match_tactics2[ball_zone2][i-13][1]);
  1602. if (d<min_d)
  1603. {
  1604. min_d=d;
  1605. pn=i;
  1606. }
  1607. }
  1608. }
  1609. if (min_d!=2000)
  1610. {
  1611. // found an idiot...
  1612. teams[pn-1].tm_wall=TRUE;
  1613. wguys[j].guy=pn;
  1614. wguys[j].x=cx;
  1615. wguys[j].y=cy;
  1616. cx=cx+xd;
  1617. cy=cy+yd;
  1618. wall_cnt++;
  1619. }
  1620. }
  1621. men_in_wall=wall_cnt;
  1622. // Get keeper position...
  1623. float gx,gy;
  1624. x=wguys[wall_cnt-2].x-incident_x; // 2nd last man in wall!
  1625. y=wguys[wall_cnt-2].y-incident_y;
  1626. if (guys>11)
  1627. // Team B's goal...
  1628. gx=pitch_len-prat;
  1629. else
  1630. // Team A's goal...
  1631. gx=0+prat;
  1632. gx=gx-incident_x;
  1633. gy=y*gx/x;
  1634. keeper_pos_x=gx+incident_x;
  1635. keeper_pos_y=gy+incident_y;
  1636. }
  1637. /*****************************************************************************
  1638. *****************************************************************************/
  1639. void inc_pfoul(short p)
  1640. {
  1641. teams[p-1].tm_fouls+=10; // add giving penalty to foul list.
  1642. }
  1643. /*****************************************************************************
  1644. *****************************************************************************/
  1645. void inc_dfoul(short p)
  1646. {
  1647. teams[p-1].tm_fouls+=3; // add direct F.K. to foul list.
  1648. }
  1649. /*****************************************************************************
  1650. *****************************************************************************/
  1651. void inc_ifoul(short p)
  1652. {
  1653. teams[p-1].tm_fouls++; // add indirect F.K. to foul list.
  1654. }
  1655. /*****************************************************************************
  1656. *****************************************************************************/
  1657. void inc_pass(short p)
  1658. {
  1659. teams[p-1].tm_pass++; // Passes attempted.
  1660. }
  1661. /*****************************************************************************
  1662. *****************************************************************************/
  1663. void inc_work(short p)
  1664. {
  1665. teams[p-1].tm_work++; // Passes attempted.
  1666. }
  1667. /******************************************************************************
  1668. *****************************************************************************/
  1669. void inc_pwon(short p)
  1670. {
  1671. teams[p-1].tm_pwon++; // Passes won.
  1672. }
  1673. /******************************************************************************
  1674. *****************************************************************************/
  1675. void inc_tack(short p)
  1676. {
  1677. teams[p-1].tm_tacks++; // Tackles attempted.
  1678. }
  1679. /******************************************************************************
  1680. *****************************************************************************/
  1681. void inc_twon(short p)
  1682. {
  1683. teams[p-1].tm_twon++; // Tackles won.
  1684. }
  1685. /******************************************************************************
  1686. *****************************************************************************/
  1687. void inc_poss(short p)
  1688. {
  1689. teams[p-1].tm_posst++; // Possession time.
  1690. }
  1691. /******************************************************************************
  1692. *****************************************************************************/
  1693. void inc_inj(short p,short i)
  1694. {
  1695. teams[p-1].tm_inj+=i; // Injury.
  1696. }
  1697. /******************************************************************************
  1698. *****************************************************************************/
  1699. void inc_yellow(short p)
  1700. {
  1701. teams[p-1].tm_book++; // Yellow card.
  1702. }
  1703. /******************************************************************************
  1704. *****************************************************************************/
  1705. void inc_red(short p)
  1706. {
  1707. teams[p-1].tm_book+=5; // Red card.
  1708. }
  1709. /******************************************************************************
  1710. *****************************************************************************/
  1711. void inc_shot(short p)
  1712. {
  1713. teams[p-1].tm_shots++; // Shots attempted.
  1714. }
  1715. /******************************************************************************
  1716. *****************************************************************************/
  1717. void inc_goal(short p)
  1718. {
  1719. teams[p-1].tm_goals++; // Goals scored.
  1720. }
  1721. /******************************************************************************
  1722. *****************************************************************************/
  1723. void inc_ogs(short p)
  1724. {
  1725. teams[p-1].tm_ogs++; // Own goals scored.
  1726. }
  1727. /******************************************************************************
  1728. *****************************************************************************/
  1729. void inc_save(short p)
  1730. {
  1731. teams[p-1].tm_saved++; // shots saved.
  1732. }
  1733. /******************************************************************************
  1734. *****************************************************************************/
  1735. void inc_saves(short p)
  1736. {
  1737. teams[p-1].tm_kpsaves++; // Saved shot.
  1738. }
  1739. /******************************************************************************
  1740. *****************************************************************************/
  1741. void add_comp_pass(short plr)
  1742. {
  1743. if (last_touch && ((last_touch<12 && plr<12)
  1744. || (last_touch>11 && plr>11)))
  1745. inc_pwon(last_touch);
  1746. }
  1747. /******************************************************************************
  1748. *****************************************************************************/
  1749. void init_dfkick()
  1750. {
  1751. comsetp=40;
  1752. int taker;
  1753. float d,x,y,range;
  1754. if (!booking)
  1755. {
  1756. if (last_touch<12)
  1757. do_direct_menu(team_b);
  1758. else
  1759. do_direct_menu(team_a);
  1760. }
  1761. if (last_touch<12)
  1762. // F.K. to Team B...
  1763. {
  1764. last_touch=12; // Team B have possession...
  1765. x=-ballx;
  1766. y=cntspot_y-bally;
  1767. d=calc_dist(x,y);
  1768. taker_x=ballx-(x*BESIDE_BALL/d);
  1769. taker_y=bally-(y*BESIDE_BALL/d);
  1770. // Referee go to spot behind incident...
  1771. refs[0].act=1;
  1772. refs[0].target=0; // Ball!
  1773. float rx=refs[0].x-ballx;
  1774. float ry=refs[0].y-bally;
  1775. float rd=calc_dist(rx,ry);
  1776. refs[0].goto_x=ballx+(rx*BESIDE_BALL*16/rd);
  1777. refs[0].goto_y=bally+(ry*BESIDE_BALL*16/rd);
  1778. range=calc_dist(x,y);
  1779. if (range>(MIN_SHOOT_DIST+((float)teams[fkick_taker-1].tm_pow*3)))
  1780. // Out of shooting range!
  1781. {
  1782. men_in_wall=0; // No wall!
  1783. taker=-1;
  1784. }
  1785. else
  1786. // In shooting range!
  1787. {
  1788. in_range=TRUE;
  1789. if (incident_y<cntspot_y)
  1790. // Near post is top!
  1791. {
  1792. y=top_post_y-incident_y;
  1793. range=calc_dist(incident_x,y);
  1794. }
  1795. else
  1796. // Near post is bottom!
  1797. {
  1798. y=bot_post_y-incident_y;
  1799. range=calc_dist(incident_x,y);
  1800. }
  1801. y=y/range; // horiz. vector to goal!
  1802. x=-incident_x/range;
  1803. men_in_wall=5.5-(ABS(y)*3); // Team A make wall.
  1804. taker=fkick_taker;
  1805. wallx=incident_x+(prat*10*x);
  1806. wally=incident_y+(prat*10*y); // Wall coords...
  1807. if (incident_y<cntspot_y)
  1808. x=-x;
  1809. else
  1810. y=-y;
  1811. find_wall_guys(2,y,x); // x,y reversed for right angle!
  1812. if (!player_on_off)
  1813. PlayCommentaryMessage(FU_WALL);
  1814. }
  1815. }
  1816. else
  1817. // F.K. to Team A...
  1818. {
  1819. last_touch=1; // Team A have possession...
  1820. x=pitch_len-ballx;
  1821. y=cntspot_y-bally;
  1822. d=calc_dist(x,y);
  1823. taker_x=incident_x-(x*BESIDE_BALL/d);
  1824. taker_y=incident_y-(y*BESIDE_BALL/d);
  1825. // Referee go to spot behind incident...
  1826. refs[0].act=1;
  1827. refs[0].target=0; // Ball!
  1828. float rx=refs[0].x-ballx;
  1829. float ry=refs[0].y-bally;
  1830. float rd=calc_dist(rx,ry);
  1831. refs[0].goto_x=ballx+(rx*BESIDE_BALL*16/rd);
  1832. refs[0].goto_y=bally+(ry*BESIDE_BALL*16/rd);
  1833. range=calc_dist(x,y);
  1834. if (range>(MIN_SHOOT_DIST+((float)teams[fkick_taker-1].tm_pow*3)))
  1835. // Out of shooting range!
  1836. {
  1837. men_in_wall=0; // No wall!
  1838. taker=0; // Anybody can take F.K.
  1839. }
  1840. else
  1841. // In shooting range!
  1842. {
  1843. in_range=TRUE;
  1844. if (incident_y<cntspot_y)
  1845. // Near post is top!
  1846. {
  1847. y=top_post_y-incident_y;
  1848. range=calc_dist(pitch_len-incident_x,y);
  1849. }
  1850. else
  1851. // Near post is bottom!
  1852. {
  1853. y=bot_post_y-incident_y;
  1854. range=calc_dist(pitch_len-incident_x,y);
  1855. }
  1856. y=y/range; // horiz. vector to goal!
  1857. x=(pitch_len-incident_x)/range;
  1858. men_in_wall=5.5-(ABS(y)*3); // Team B make wall.
  1859. taker=fkick_taker;
  1860. wallx=incident_x+(prat*10*x);
  1861. wally=incident_y+(prat*10*y); // Wall coords...
  1862. if (incident_y<cntspot_y)
  1863. y=-y;
  1864. else
  1865. x=-x;
  1866. find_wall_guys(13,y,x); // x,y reversed for right angle!
  1867. if (!player_on_off)
  1868. PlayCommentaryMessage(FU_WALL);
  1869. }
  1870. }
  1871. if (taker<1)
  1872. // Not close enough to take shot so nearest can take!
  1873. {
  1874. int min_d=1000;
  1875. int d;
  1876. int p=(taker<0 ? 13:2);
  1877. for (int pn=p; pn<p+10; pn++)
  1878. {
  1879. if (teams[pn-1].guy_on>0)
  1880. {
  1881. if (pn<12)
  1882. d=calc_dist(ballx-match_tactics1[ball_zone1][pn-2][0],
  1883. bally-match_tactics1[ball_zone1][pn-2][1]);
  1884. else
  1885. d=calc_dist((pitch_len-ballx)-match_tactics2[ball_zone2][pn-13][0],
  1886. (pitch_wid-bally)-match_tactics2[ball_zone2][pn-13][1]);
  1887. if (d<min_d)
  1888. {
  1889. min_d=d;
  1890. fkick_taker=pn;
  1891. }
  1892. }
  1893. }
  1894. }
  1895. main_man=fkick_taker;
  1896. last_touch=fkick_taker;
  1897. pre_kp_touch=last_touch;
  1898. }
  1899. /******************************************************************************
  1900. *****************************************************************************/
  1901. void init_penalty()
  1902. {
  1903. if (!penalty_game)
  1904. PlayCommentaryMessage(SP_PENALTY);
  1905. float x,y,range;
  1906. if (match_mode==PEN_KICK_A)
  1907. {
  1908. ballx=pitch_len-(prat*12);
  1909. #ifdef EURO96
  1910. taker_x=ballx-PEN_RUNUP_DIST;
  1911. #else
  1912. taker_x=ballx-8;
  1913. #endif
  1914. }
  1915. else
  1916. {
  1917. ballx=(prat*12);
  1918. #ifdef EURO96
  1919. taker_x=ballx+PEN_RUNUP_DIST;
  1920. #else
  1921. taker_x=ballx+8;
  1922. #endif
  1923. }
  1924. taker_y=cntspot_y;
  1925. bally=cntspot_y;
  1926. incident_x=ballx;
  1927. incident_y=bally;
  1928. // Referee go to spot above penalty spot...
  1929. refs[0].act=1;
  1930. refs[0].target=0; // Ball!
  1931. refs[0].goto_x=ballx;
  1932. refs[0].goto_y=cntspot_y-(prat*10);
  1933. if ((!penalty_taker) || (!teams[penalty_taker-1].guy_on))
  1934. // No particular player chosen nearest can take!
  1935. {
  1936. int min_d=1000;
  1937. int d;
  1938. int p=(match_mode==PEN_KICK_B ? 13:2);
  1939. for (int pn=p; pn<p+10; pn++)
  1940. {
  1941. if (pn<12)
  1942. d=calc_dist(ballx-match_tactics1[ball_zone1][pn-2][0],
  1943. bally-match_tactics1[ball_zone1][pn-2][1]);
  1944. else
  1945. d=calc_dist((pitch_len-ballx)-match_tactics2[ball_zone2][pn-13][0],
  1946. (pitch_wid-bally)-match_tactics2[ball_zone2][pn-13][1]);
  1947. if (d<min_d)
  1948. {
  1949. min_d=d;
  1950. penalty_taker=pn;
  1951. }
  1952. }
  1953. }
  1954. main_man=penalty_taker;
  1955. /*
  1956. if (main_man<12)
  1957. {
  1958. // Team A penalty...
  1959. user_keeper_b();
  1960. }
  1961. else
  1962. {
  1963. // Team B penalty...
  1964. user_keeper_a();
  1965. }
  1966. */
  1967. }
  1968. /******************************************************************************
  1969. *****************************************************************************/
  1970. void init_match_mode()
  1971. {
  1972. ref_wait=(160-ref_strictness)*REAL_SPEED/8;
  1973. support_me=FALSE;
  1974. spec_kick_type=0;
  1975. already_there=FALSE; // Taker is not in position.
  1976. reselection=FALSE; // When do I reselect auto users.
  1977. clear_all_autos(); // Clear all auto selected players.
  1978. if (match_mode)
  1979. {
  1980. play_advantage=FALSE;
  1981. setp_wait_cnt=MAX_SETP_WAIT;
  1982. if (ball_limbo_on)
  1983. {
  1984. ball_limbo_on=FALSE;
  1985. teams[ball_limbo_p-1].tm_limbo=FALSE;
  1986. }
  1987. teams[KP_A-1].tm_limbo=0;
  1988. teams[KP_B-1].tm_limbo=0;
  1989. reset_all_ideas();
  1990. holder_lose_ball();
  1991. if (teams[KP_A-1].tm_act==KPHOLD_ACT)
  1992. init_stand_act(&teams[KP_A-1]);
  1993. if (teams[KP_B-1].tm_act==KPHOLD_ACT)
  1994. init_stand_act(&teams[KP_B-1]);
  1995. }
  1996. switch(match_mode)
  1997. {
  1998. // Normal Play.
  1999. case(0):
  2000. break;
  2001. // Corner.
  2002. case(CORNER_TL):
  2003. case(CORNER_BL):
  2004. case(CORNER_TR):
  2005. case(CORNER_BR):
  2006. set_piece_on=SETP_CORNER;
  2007. can_be_offside=FALSE;
  2008. play_fx(PS_SHORTWHISTLE,refs[0].x,refs[0].y);
  2009. init_corner();
  2010. break;
  2011. // Centre.
  2012. case(CENTRE_A):
  2013. if (!team_a_on)
  2014. match_mode=CENTRE_B;
  2015. case(CENTRE_B):
  2016. if (!team_b_on)
  2017. match_mode=CENTRE_A;
  2018. set_piece_on=SETP_CENTRE;
  2019. can_be_offside=TRUE;
  2020. play_fx(PS_SHORTWHISTLE,refs[0].x,refs[0].y);
  2021. init_centre();
  2022. break;
  2023. // Goal kick.
  2024. case(GOAL_KICK_TL):
  2025. case(GOAL_KICK_BL):
  2026. case(GOAL_KICK_TR):
  2027. case(GOAL_KICK_BR):
  2028. set_piece_on=SETP_GKICK;
  2029. can_be_offside=FALSE;
  2030. play_fx(PS_SHORTWHISTLE,refs[0].x,refs[0].y);
  2031. init_gkick();
  2032. break;
  2033. // Throw in.
  2034. case(THROW_IN_A):
  2035. case(THROW_IN_B):
  2036. set_piece_on=SETP_THROW;
  2037. can_be_offside=FALSE;
  2038. play_fx(PS_SHORTWHISTLE,refs[0].x,refs[0].y);
  2039. init_throw();
  2040. break;
  2041. // Indirect free kick.
  2042. case(IF_KICK_A):
  2043. if (!team_a_on)
  2044. match_mode=IF_KICK_B;
  2045. case(IF_KICK_B):
  2046. if (!team_b_on)
  2047. match_mode=IF_KICK_A;
  2048. can_be_offside=TRUE;
  2049. play_fx(PS_LONGWHISTLE,refs[0].x,refs[0].y);
  2050. set_piece_on=SETP_IFKICK;
  2051. init_fkick();
  2052. break;
  2053. // Direct free kick.
  2054. case(DF_KICK_A):
  2055. if (!team_a_on)
  2056. match_mode=DF_KICK_B;
  2057. case(DF_KICK_B):
  2058. if (!team_b_on)
  2059. match_mode=DF_KICK_A;
  2060. can_be_offside=TRUE;
  2061. play_fx(PS_LONGWHISTLE,refs[0].x,refs[0].y);
  2062. set_piece_on=SETP_DFKICK;
  2063. init_dfkick();
  2064. break;
  2065. // Penalty kick.
  2066. case(PEN_KICK_A):
  2067. if (!team_a_on)
  2068. match_mode=PEN_KICK_B;
  2069. case(PEN_KICK_B):
  2070. if (!team_b_on)
  2071. match_mode=PEN_KICK_A;
  2072. can_be_offside=FALSE;
  2073. play_fx(PS_LONGWHISTLE,refs[0].x,refs[0].y);
  2074. set_piece_on=SETP_PENALTY;
  2075. init_penalty();
  2076. break;
  2077. case(SWAP_ENDS):
  2078. init_swap_ends();
  2079. break;
  2080. }
  2081. setp_taker=main_man;
  2082. }
  2083. /******************************************************************************
  2084. *****************************************************************************/
  2085. char offc_thinking()
  2086. {
  2087. int f=((129-ref_accuracy)/4)+1;
  2088. int t=logic_cnt/f;
  2089. int r=logic_cnt-(t*f);
  2090. return(!r);
  2091. }
  2092. /******************************************************************************
  2093. *****************************************************************************/
  2094. void init_ref_stand(officials *lman)
  2095. {
  2096. if (ABS(lman->anim)!=MC_STAND)
  2097. {
  2098. lman->anim=MC_STAND;
  2099. lman->newanim=TRUE;
  2100. lman->frm=0;
  2101. lman->fstep=MC_STAND_FS;
  2102. }
  2103. }
  2104. /******************************************************************************
  2105. *****************************************************************************/
  2106. void init_ref_run(officials *lman)
  2107. {
  2108. if (ABS(lman->anim)==MC_JOG)
  2109. {
  2110. // Tween to run from jog....
  2111. lman->anim=MC_RUN;
  2112. lman->fstep=MC_RUN_FS;
  2113. }
  2114. else
  2115. if (ABS(lman->anim)!=MC_RUN)
  2116. {
  2117. lman->anim=MC_RUN;
  2118. lman->newanim=TRUE;
  2119. lman->frm=0;
  2120. lman->fstep=MC_RUN_FS;
  2121. }
  2122. }
  2123. /******************************************************************************
  2124. *****************************************************************************/
  2125. void init_ref_jog(officials *lman)
  2126. {
  2127. if (ABS(lman->anim)==MC_RUN)
  2128. {
  2129. // Tween to jog from run....
  2130. lman->anim=MC_JOG;
  2131. lman->fstep=MC_JOG_FS;
  2132. }
  2133. else
  2134. if (ABS(lman->anim)!=MC_JOG)
  2135. {
  2136. lman->anim=MC_JOG;
  2137. lman->newanim=TRUE;
  2138. lman->frm=0;
  2139. lman->fstep=MC_JOG_FS;
  2140. }
  2141. }
  2142. /******************************************************************************
  2143. *****************************************************************************/
  2144. void init_rtrot_anim(officials *lman)
  2145. {
  2146. float x=lman->goto_x-lman->x;
  2147. float y=lman->goto_y-lman->y;
  2148. float d=calc_dist(x,y);
  2149. lman->fstep=MC_TROTA_FS;
  2150. x=x/d;
  2151. y=y/d;
  2152. float nx=(x*lman->dir_x)+(y*lman->dir_y);
  2153. float ny=(y*lman->dir_x)-(x*lman->dir_y);
  2154. if (lman->anim<MC_TROTB || lman->anim>MC_TROTE)
  2155. // Not currently in trot animation...
  2156. {
  2157. lman->frm=0;
  2158. lman->newanim=TRUE;
  2159. }
  2160. switch((1+get_dir(nx,ny)))
  2161. {
  2162. case(8):
  2163. lman->anim=MC_TROTF;
  2164. break;
  2165. case(7):
  2166. lman->anim=MC_TROTG;
  2167. break;
  2168. case(6):
  2169. lman->anim=MC_TROTH;
  2170. break;
  2171. case(5):
  2172. lman->anim=MC_TROTA;
  2173. break;
  2174. case(4):
  2175. lman->anim=MC_TROTB;
  2176. break;
  2177. case(3):
  2178. lman->anim=MC_TROTC;
  2179. break;
  2180. case(2):
  2181. lman->anim=MC_TROTD;
  2182. break;
  2183. case(1):
  2184. lman->anim=MC_TROTE;
  2185. break;
  2186. }
  2187. }
  2188. /******************************************************************************
  2189. *****************************************************************************/
  2190. void init_refs_anim(officials *lman,int an)
  2191. {
  2192. switch(an)
  2193. {
  2194. case(MC_STAND):
  2195. init_ref_stand(lman);
  2196. break;
  2197. case(MC_RUN):
  2198. init_ref_run(lman);
  2199. break;
  2200. case(MC_JOG):
  2201. init_ref_jog(lman);
  2202. break;
  2203. case(MC_TROTA):
  2204. init_rtrot_anim(lman);
  2205. break;
  2206. }
  2207. }
  2208. /******************************************************************************
  2209. *****************************************************************************/
  2210. void lman_follow(officials *lman)
  2211. {
  2212. if (match_mode)
  2213. {
  2214. init_refs_anim(lman,MC_STAND);
  2215. lman->go=12+(129-ref_accuracy)/4;
  2216. }
  2217. else
  2218. {
  2219. float x;
  2220. if (lman->go>0)
  2221. lman->go--;
  2222. else
  2223. {
  2224. if (lman->y<cntspot_y)
  2225. // Top Linesman...
  2226. {
  2227. lman->dir_x=0;
  2228. lman->dir_y=1;
  2229. if (ballx>cntspot_x)
  2230. x=((ballx-defense_a)/1.25)*(pitch_wid-bally)/pitch_wid;
  2231. else
  2232. x=0;
  2233. if (defense_a+x-2>lman->x)
  2234. {
  2235. lman->goto_x=lman->x+2;
  2236. if (lman->anim!=MC_TROTG)
  2237. init_refs_anim(lman,MC_TROTA);
  2238. lman->x=lman->goto_x;
  2239. }
  2240. else
  2241. if (defense_a+x+2<lman->x)
  2242. {
  2243. lman->goto_x=lman->x-2;
  2244. if (lman->anim!=MC_TROTC)
  2245. init_refs_anim(lman,MC_TROTA);
  2246. lman->x=lman->goto_x;
  2247. }
  2248. else
  2249. {
  2250. init_refs_anim(lman,MC_STAND);
  2251. lman->go=12+(129-ref_accuracy)/4;
  2252. }
  2253. }
  2254. else
  2255. {
  2256. // Bot. Linesman...
  2257. lman->dir_x=0;
  2258. lman->dir_y=-1;
  2259. if (ballx<cntspot_x)
  2260. x=((defense_b-ballx)/1.25)*bally/pitch_wid;
  2261. else
  2262. x=0;
  2263. if (defense_b+x-2>lman->x)
  2264. {
  2265. lman->goto_x=lman->x+2;
  2266. if (lman->anim!=MC_TROTC)
  2267. init_refs_anim(lman,MC_TROTA);
  2268. lman->x=lman->goto_x;
  2269. }
  2270. else
  2271. if (defense_b+x+2<lman->x)
  2272. {
  2273. lman->goto_x=lman->x-2;
  2274. if (lman->anim!=MC_TROTG)
  2275. init_refs_anim(lman,MC_TROTA);
  2276. lman->x=lman->goto_x;
  2277. }
  2278. else
  2279. {
  2280. init_refs_anim(lman,MC_STAND);
  2281. lman->go=12+(129-ref_accuracy)/4;
  2282. }
  2283. }
  2284. }
  2285. }
  2286. }
  2287. /******************************************************************************
  2288. *****************************************************************************/
  2289. void await_kicker(officials *offc)
  2290. {
  2291. init_refs_anim(&refs[0],MC_STAND);
  2292. if ((!match_mode) && (teams[ktaker-1].tm_act!=THROW_ACT))
  2293. offc->act=0;
  2294. else
  2295. {
  2296. if (!(--ref_wait) && match_mode!=PEN_KICK_A && match_mode!=PEN_KICK_B)
  2297. {
  2298. // Time-up!!!
  2299. #ifdef STOP_TIME_WASTING
  2300. if (!practice)
  2301. #else
  2302. if (!practice && teams[ktaker-1].tm_act!=THROW_ACT)
  2303. #endif
  2304. {
  2305. ref_wait=-1;
  2306. // Cannot be in practice mode...
  2307. if (teams[ktaker-1].tm_act==THROW_ACT)
  2308. {
  2309. // Give away a throw...
  2310. if (ktaker>11)
  2311. // Team A gets Throw In...
  2312. {
  2313. match_mode=THROW_IN_A;
  2314. init_match_mode();
  2315. init_stand_act(&teams[ktaker-1]);
  2316. holder_lose_ball();
  2317. }
  2318. else
  2319. // Team B gets Throw In...
  2320. {
  2321. match_mode=THROW_IN_B;
  2322. init_match_mode();
  2323. init_stand_act(&teams[ktaker-1]);
  2324. holder_lose_ball();
  2325. }
  2326. }
  2327. /*
  2328. else
  2329. {
  2330. if ((match_mode>=CORNER_TL) && (match_mode<=CORNER_BR))
  2331. {
  2332. // Give opposing team a Goal Kick...
  2333. match_mode+=6;
  2334. init_match_mode();
  2335. init_stand_act(&teams[setp_taker-1]);
  2336. holder_lose_ball();
  2337. }
  2338. else
  2339. {
  2340. // Opposing Team recieves Indirect Free Kick...
  2341. init_foul(ktaker,FALSE,TRUE);
  2342. init_stand_act(&teams[setp_taker-1]);
  2343. holder_lose_ball();
  2344. }
  2345. }
  2346. init_speech(players+1,SAY_TIMEW);
  2347. */
  2348. }
  2349. }
  2350. }
  2351. }
  2352. /******************************************************************************
  2353. *****************************************************************************/
  2354. void goto_target(officials *offc)
  2355. {
  2356. float tx,ty,x,y,d,bd,nx,ny,ox,oy,dif,spd;
  2357. tx=offc->goto_x-offc->x;
  2358. ty=offc->goto_y-offc->y;
  2359. d=calc_dist(tx,ty);
  2360. tx=tx/d;
  2361. ty=ty/d;
  2362. offc->dir_x=tx;
  2363. offc->dir_y=ty;
  2364. if (d>2.6)
  2365. // Not there yet...
  2366. {
  2367. init_refs_anim(offc,MC_JOG);
  2368. spd=2.6;
  2369. }
  2370. else
  2371. {
  2372. init_refs_anim(offc,MC_STAND);
  2373. offc->act=3; // Face target!
  2374. spd=0;
  2375. }
  2376. offc->x+=tx*spd;
  2377. offc->y+=ty*spd;
  2378. }
  2379. /******************************************************************************
  2380. *****************************************************************************/
  2381. void at_target(officials *referee)
  2382. {
  2383. // Turns player to face object (ball or player!)
  2384. float nx,ny,x,y,bd,xd,yd,dif;
  2385. float max=(PI/12);
  2386. if (!referee->target)
  2387. {
  2388. // Face ball!
  2389. x=ballx-referee->x;
  2390. y=bally-referee->y;
  2391. }
  2392. else
  2393. {
  2394. // Face Player!
  2395. x=teams[referee->target-1].tm_x-referee->x;
  2396. y=teams[referee->target-1].tm_x-referee->y;
  2397. }
  2398. bd=calc_dist(x,y);
  2399. x=x/bd;
  2400. y=y/bd;
  2401. xd=referee->dir_x;
  2402. yd=referee->dir_y;
  2403. dif=((x*xd)+(y*yd));
  2404. if (dif<cos(max))
  2405. {
  2406. if ((x*yd)>(y*xd))
  2407. max=-max;
  2408. nx=(xd*cos(max))-(yd*sin(max));
  2409. ny=(yd*cos(max))+(xd*sin(max));
  2410. }
  2411. else
  2412. {
  2413. nx=x;
  2414. ny=y;
  2415. referee->act=4; // Action complete!
  2416. }
  2417. bd=calc_dist(nx,ny);
  2418. nx=nx/bd;
  2419. ny=ny/bd;
  2420. referee->dir_x=nx;
  2421. referee->dir_y=ny;
  2422. }
  2423. /******************************************************************************
  2424. *****************************************************************************/
  2425. void follow_play(officials *referee)
  2426. {
  2427. float tx,ty,x,y,d,bd,nx,ny,ox,oy,dif,spd;
  2428. if (!match_mode)
  2429. {
  2430. x=ballx-referee->x;
  2431. y=bally-referee->y;
  2432. bd=calc_dist(x,y);
  2433. // Face Ball...
  2434. if (bd>0.2)
  2435. {
  2436. referee->dir_x=x/bd;
  2437. referee->dir_y=y/bd;
  2438. }
  2439. tx=cntspot_x+((ballx-cntspot_x)*0.5)+((last_touch<12) ? (prat*10):(prat*-10));
  2440. ty=cntspot_y+((bally-cntspot_y)*0.5);
  2441. tx=tx-referee->x;
  2442. ty=ty-referee->y;
  2443. d=calc_dist(tx,ty);
  2444. if (d>prat*2)
  2445. {
  2446. // Keep distance from ball..
  2447. if ((bd>0.2) && (bd<prat*10) && (!dead_ball_cnt))
  2448. {
  2449. tx-=x*50/bd;
  2450. ty-=y*50/bd;
  2451. d=calc_dist(tx,ty);
  2452. }
  2453. if (d>prat*2)
  2454. {
  2455. referee->goto_x=referee->x+tx;
  2456. referee->goto_y=referee->y+ty;
  2457. tx=tx/d;
  2458. ty=ty/d;
  2459. // Get angle of movement Vs facing...
  2460. dif=((referee->dir_x*tx)+(referee->dir_y*ty));
  2461. if (dif>1.0)
  2462. dif=1;
  2463. if (dif<-1.0)
  2464. dif=-1;
  2465. init_refs_anim(&refs[0],MC_TROTA);
  2466. spd=2.2;
  2467. referee->x+=tx*spd;
  2468. referee->y+=ty*spd;
  2469. }
  2470. else
  2471. {
  2472. init_refs_anim(&refs[0],MC_STAND);
  2473. }
  2474. }
  2475. else
  2476. {
  2477. init_refs_anim(&refs[0],MC_STAND);
  2478. }
  2479. }
  2480. }
  2481. /******************************************************************************
  2482. *****************************************************************************/
  2483. void process_ref(officials *offc)
  2484. {
  2485. if (match_mode==SWAP_ENDS)
  2486. init_refs_anim(&refs[0],MC_STAND);
  2487. else
  2488. {
  2489. switch(offc->act)
  2490. {
  2491. case(0): // Follow Play...
  2492. follow_play(offc);
  2493. break;
  2494. case(1): // Goto target..
  2495. goto_target(offc);
  2496. break;
  2497. case(2): // Wait for someone to kick ball..
  2498. await_kicker(offc);
  2499. break;
  2500. case(3): // Stand and turn...
  2501. at_target(offc);
  2502. break;
  2503. case(4): // Facing target now...
  2504. at_target(offc);
  2505. break;
  2506. }
  2507. }
  2508. }
  2509. /******************************************************************************
  2510. *****************************************************************************/
  2511. void process_lman(officials *offc)
  2512. {
  2513. switch(offc->act)
  2514. {
  2515. case(0): // Follow Play...
  2516. lman_follow(offc);
  2517. break;
  2518. case(1): // Follow Play...
  2519. goto_target(offc);
  2520. break;
  2521. }
  2522. }
  2523. /******************************************************************************
  2524. *****************************************************************************/
  2525. void anim_officials(officials *offc)
  2526. {
  2527. offc->frm+=offc->fstep;
  2528. }
  2529. /******************************************************************************
  2530. *****************************************************************************/
  2531. void process_offs()
  2532. {
  2533. process_ref(&refs[0]);
  2534. process_lman(&refs[1]);
  2535. process_lman(&refs[2]);
  2536. anim_officials(&refs[0]);
  2537. anim_officials(&refs[1]);
  2538. anim_officials(&refs[2]);
  2539. }