INTELL.CPP 174 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269
  1. /******************************************************************************
  2. *******************************************************************************/
  3. // Player intelligence and decision making routines...
  4. /******************************************************************************
  5. *****************************************************************************/
  6. #include "global.h"
  7. #include "defines.h"
  8. #include "externs.h"
  9. #include "data.h"
  10. #include "audio.h" // Kev's audio calls.
  11. #include "front.h"
  12. #include "eurofrnt\euro_int.h"
  13. extern match_data match_info;
  14. extern team_info game_data[];
  15. extern float save_offs[];
  16. extern setup_info setup;
  17. extern stad_info stadlist[];
  18. extern void reselect_a();
  19. extern void reselect_b();
  20. /******************************************************************************
  21. *****************************************************************************/
  22. // Intelligence Flags and Variables...
  23. char cross_on=FALSE;
  24. /******************************************************************************
  25. *****************************************************************************/
  26. short get_there_time(int p_num,float x,float y)
  27. {
  28. stop_and_face=FALSE;
  29. must_face_time=0;
  30. int t1=0;
  31. int t2=0;
  32. int mft1=0;
  33. int mft2=0;
  34. int t;
  35. int mft;
  36. float d;
  37. float rate=full_spd(&teams[p_num-1]); // Running speed!
  38. float px,py;
  39. px=teams[p_num-1].tm_x;
  40. py=teams[p_num-1].tm_y;
  41. x=x-px;
  42. y=y-py; // Offset.
  43. float sx=x;
  44. float sy=y;
  45. float xd=teams[p_num-1].tm_xdis;
  46. float yd=teams[p_num-1].tm_ydis; //Current facing dir.
  47. float max=MAX_TURN2;
  48. float old_max=max;
  49. float cmax=cos(max);
  50. float ox,oy,a,turn_spd,last_a;
  51. // Player must have ball slightly
  52. if (teams[p_num-1].tm_act<=TURN_ACT)
  53. {
  54. // Can i turn on the spot?
  55. a=angle_to_xy(x,y,xd,yd);
  56. t1=ABS(acos(a)/max); // time to turn!
  57. // Time to go straight to point...
  58. d=calc_dist(x,y);
  59. t1+=d/rate+1;
  60. if (must_face)
  61. {
  62. // User forced to face in a particular direction (after getting to target)...
  63. a=angle_to_xy(must_face_x,must_face_y,x/d,y/d);
  64. mft1=ABS(acos(a)/max)+1; // time to turn!
  65. }
  66. }
  67. else
  68. t1=2000;
  69. a=angle_to_xy(x,y,xd,yd);
  70. last_a=a;
  71. d=calc_dist(x,y);
  72. // Time to get to target point...
  73. for (int i=0; i<50; i++)
  74. {
  75. // Init run...
  76. if (d<IM_THERE_DIST)
  77. break;
  78. else
  79. t2++;
  80. // Go forward...
  81. turn_spd=(1.0+a)/2;
  82. x-=xd*rate*turn_spd; // Move on...
  83. y-=yd*rate*turn_spd;
  84. // Turn...
  85. d=calc_dist(x,y);
  86. ox=xd;
  87. oy=yd;
  88. max=old_max;
  89. if (a<cmax)
  90. {
  91. // Need to turn...
  92. if ((x*oy/d)>(y*ox/d))
  93. max=-max;
  94. xd=(ox*cos(max))-(oy*sin(max));
  95. yd=(oy*cos(max))+(ox*sin(max));
  96. }
  97. else
  98. {
  99. // Final turn...
  100. // xd=x/d;
  101. // yd=y/d;
  102. t2+=d/rate;
  103. if (d-((t2-1)*rate)>.1)
  104. t2++;
  105. break;
  106. }
  107. last_a=a;
  108. a=angle_to_xy(x,y,xd,yd);
  109. if (last_a>a)
  110. // Getting further forget it!
  111. {
  112. t2=2000;
  113. break; // (exit)
  114. }
  115. }
  116. if (i>50)
  117. t=2000; // Could not find intersection!
  118. if (must_face)
  119. {
  120. // User forced to face in a particular direction (after getting to target)...
  121. a=angle_to_xy(must_face_x,must_face_y,xd,yd);
  122. mft2=ABS(acos(a)/max)+1; // time to turn!
  123. }
  124. if ((t1+mft1)<(t2+mft2))
  125. {
  126. // Rotate and run...
  127. t=t1+mft1;
  128. mft=mft1;
  129. d=calc_dist(sx,sy);
  130. x_face=sx/d; // New dir...
  131. y_face=sy/d;
  132. stop_and_face=TRUE;
  133. }
  134. else
  135. {
  136. // Turn and run...
  137. t=t2+mft2;
  138. mft=mft2;
  139. x_face=x/d; // New dir...
  140. y_face=y/d;
  141. }
  142. if (must_face)
  143. {
  144. x_face=must_face_x;
  145. y_face=must_face_y;
  146. must_face_time=mft;
  147. }
  148. return(t);
  149. }
  150. /******************************************************************************
  151. *****************************************************************************/
  152. short get_facing_opp_dir(match_player *player)
  153. {
  154. /*
  155. Output: 1 = Side On.
  156. -1 = Behind.
  157. 0 = Face On.
  158. */
  159. int d=get_dir(ballx-player->tm_x,bally-player->tm_y);
  160. // Direction to ball!
  161. int opp=teams[ball_poss-1].face_dir;
  162. if (opp==d)
  163. return(-1);
  164. d=d-opp;
  165. if (d<0)
  166. d+=8;
  167. if ((d==1) || (d==7))
  168. return(-1);
  169. if ((d==2) || (d==6))
  170. return(1);
  171. else
  172. return(0);
  173. }
  174. /******************************************************************************
  175. *****************************************************************************/
  176. char thinking(match_player *player)
  177. {
  178. int f=(130-player->tm_flair)/2;
  179. int t=logic_cnt/f;
  180. int r=logic_cnt-(t*f);
  181. return(!r);
  182. }
  183. /******************************************************************************
  184. *****************************************************************************/
  185. char plr_facing(float x,float y,match_player *player)
  186. {
  187. float xd=player->tm_xdis;
  188. float yd=player->tm_ydis;
  189. float d=calc_dist(x,y);
  190. float a=((x*xd)+(y*yd))/d;
  191. if (a>FACING_ANGLE) // 5 degrees!
  192. return(TRUE);
  193. else
  194. return(FALSE);
  195. }
  196. /******************************************************************************
  197. *****************************************************************************/
  198. char plr_facing_goal(float x,float y,match_player *player)
  199. {
  200. // Is the player facing between the goal posts of goal(x,y)?
  201. float xd=player->tm_xdis;
  202. float yd=player->tm_ydis;
  203. if ((x>0 && xd<0) || (x<0 && xd>0))
  204. return(FALSE);
  205. float yt;
  206. if (user_controlled)
  207. yt=(top_post_y-prat*6)-player->tm_y;
  208. else
  209. yt=top_post_y-player->tm_y;
  210. float d=calc_dist(x,yt);
  211. float xt=x/d;
  212. yt=yt/d;
  213. float yb;
  214. if (user_controlled)
  215. yb=(bot_post_y+prat*6)-player->tm_y;
  216. else
  217. yb=bot_post_y-player->tm_y;
  218. d=calc_dist(x,yb);
  219. float xb=x/d;
  220. yb=yb/d;
  221. char dir=0;
  222. if ((xt*yd)>(yt*xd))
  223. dir=TRUE;
  224. if ((xb*yd)>(yb*xd))
  225. {
  226. if (dir)
  227. return(FALSE);
  228. else
  229. return(TRUE);
  230. }
  231. else
  232. {
  233. if (dir)
  234. return(TRUE);
  235. else
  236. return(FALSE);
  237. }
  238. return(FALSE);
  239. }
  240. /******************************************************************************
  241. *****************************************************************************/
  242. void run_back(match_player *player)
  243. {
  244. player->tm_off=-2;
  245. if (player->tm_player<12)
  246. // Team A...
  247. {
  248. init_run_act(player,defense_b-(prat*3),player->tm_y,TRUE);
  249. }
  250. else
  251. // Team B...
  252. {
  253. init_run_act(player,defense_a+(prat*3),player->tm_y,TRUE);
  254. }
  255. }
  256. /******************************************************************************
  257. *****************************************************************************/
  258. void keeper_boxes()
  259. {
  260. if ((teams[KP_A-1].tm_x>(prat*16)) || (teams[KP_A-1].tm_y>(cntspot_y+(19*prat)))
  261. || (teams[KP_A-1].tm_y<(cntspot_y-(19*prat))) || (teams[KP_A-1].tm_x<0))
  262. keeper_a_in_box=FALSE;
  263. else
  264. keeper_a_in_box=TRUE;
  265. if ((teams[KP_B-1].tm_x<pitch_len-(prat*16)) || (teams[KP_B-1].tm_y>(cntspot_y+(19*prat)))
  266. || (teams[KP_B-1].tm_y<(cntspot_y-(19*prat))) || (teams[KP_B-1].tm_x>pitch_len))
  267. keeper_b_in_box=FALSE;
  268. else
  269. keeper_b_in_box=TRUE;
  270. }
  271. /******************************************************************************
  272. *****************************************************************************/
  273. void reset_ideas(match_player *player)
  274. {
  275. player->tm_strike=FALSE;
  276. player->special=FALSE;
  277. player->tm_z=0;
  278. if (player->int_move!=I_OFF)
  279. {
  280. if ((player->int_move==I_INTERCEPT) && (player->tm_act==RUN_ACT))
  281. player->go_cnt=1; // Stop running!
  282. if (player->int_move==I_RUN_ON)
  283. {
  284. want_pass=0;
  285. player->int_move=0;
  286. player->int_cnt=0;
  287. }
  288. if (player->int_cnt)
  289. {
  290. if (player->tm_player==interceptor_a)
  291. interceptor_a=0;
  292. if (player->tm_player==interceptor_b)
  293. interceptor_b=0;
  294. player->int_move=0;
  295. player->int_cnt=0;
  296. }
  297. }
  298. }
  299. /******************************************************************************
  300. *****************************************************************************/
  301. void reset_all_ideas()
  302. {
  303. for (int i=0; i<players; i++)
  304. {
  305. reset_ideas(&teams[i]);
  306. teams[i].tm_leave=FALSE;
  307. }
  308. keep_dive=FALSE;
  309. }
  310. /******************************************************************************
  311. *****************************************************************************/
  312. void reset_leaves()
  313. {
  314. for (int i=0; i<players; i++)
  315. {
  316. teams[i].tm_leave=FALSE;
  317. }
  318. }
  319. /******************************************************************************
  320. *****************************************************************************/
  321. void save_in_zone_a(match_player *player,float x,float y,float z,int bp,char forced)
  322. {
  323. float factor;
  324. keeper_on_grnd=FALSE;
  325. keeper_will_save=TRUE;
  326. int zone=1;
  327. if (z<SAVE_FEET_HGT)
  328. // Feet level...
  329. {
  330. if (bp<=SAVE_AFOOTB_TIME/keeper_spd && !keep_dive)
  331. {
  332. keeper_contact=MCC_AFOOTB;
  333. factor=1./((float)bp/(SAVE_AFOOTB_TIME/keeper_spd));
  334. if (factor>max_kp_margin && !forced)
  335. {
  336. // Ball is too fast!
  337. factor=max_kp_margin;
  338. keeper_will_save=FALSE;
  339. player->tm_fstep=MC_AFOOTB_FS*factor*keeper_spd;
  340. }
  341. else
  342. player->tm_fstep=keeper_contact/bp;
  343. if (player->tm_fstep>=1)
  344. player->tm_fstep=1;
  345. save_block=TRUE;
  346. init_save_act(player,x,y,z,MC_AFOOTB,zone,bp,(int)(SAVE_AFOOTB_TIME/keeper_spd));
  347. }
  348. else
  349. if (bp<=SAVE_AFOOTC_TIME/keeper_spd || keep_dive)
  350. {
  351. keeper_contact=MCC_AFOOTC;
  352. factor=1./((float)bp/(SAVE_AFOOTC_TIME/keeper_spd));
  353. if (factor>max_kp_margin && !forced)
  354. {
  355. // Ball is too fast!
  356. factor=max_kp_margin;
  357. keeper_will_save=FALSE;
  358. player->tm_fstep=MC_AFOOTC_FS*factor*keeper_spd;
  359. }
  360. else
  361. player->tm_fstep=keeper_contact/bp;
  362. if (player->tm_fstep>=1)
  363. player->tm_fstep=1;
  364. save_block=FALSE;
  365. keeper_on_grnd=TRUE;
  366. init_save_act(player,x,y,z,MC_AFOOTC,zone,bp,(int)(SAVE_AFOOTC_TIME/keeper_spd));
  367. }
  368. else
  369. // Move to best position...
  370. {
  371. shot_acknowledged=1;
  372. }
  373. }
  374. else
  375. if (z<SAVE_CHEST_HGT)
  376. // Chest level...
  377. {
  378. if (bp<=SAVE_ABODYB_TIME/keeper_spd && !keep_dive)
  379. {
  380. keeper_contact=MCC_ABODYB;
  381. factor=1./((float)bp/(SAVE_ABODYB_TIME/keeper_spd));
  382. if (factor>max_kp_margin && !forced)
  383. {
  384. // Ball is too fast!
  385. factor=max_kp_margin;
  386. keeper_will_save=FALSE;
  387. player->tm_fstep=MC_ABODYB_FS*factor*keeper_spd;
  388. }
  389. else
  390. player->tm_fstep=keeper_contact/bp;
  391. if (player->tm_fstep>=1)
  392. player->tm_fstep=1;
  393. save_block=TRUE;
  394. init_save_act(player,x,y,z,MC_ABODYB,zone,bp,(int)(SAVE_ABODYB_TIME/keeper_spd));
  395. }
  396. else
  397. if (bp<=SAVE_ABODYC_TIME/keeper_spd || keep_dive)
  398. {
  399. keeper_contact=MCC_ABODYC;
  400. factor=1./((float)bp/(SAVE_ABODYC_TIME/keeper_spd));
  401. if (factor>max_kp_margin && !forced)
  402. {
  403. // Ball is too fast!
  404. factor=max_kp_margin;
  405. keeper_will_save=FALSE;
  406. player->tm_fstep=MC_ABODYC_FS*factor*keeper_spd;
  407. }
  408. else
  409. player->tm_fstep=keeper_contact/bp;
  410. if (player->tm_fstep>=1)
  411. player->tm_fstep=1;
  412. save_block=FALSE;
  413. init_save_act(player,x,y,z,MC_ABODYC,zone,bp,(int)(SAVE_ABODYC_TIME/keeper_spd));
  414. }
  415. else
  416. // Move to best position...
  417. {
  418. shot_acknowledged=1;
  419. }
  420. }
  421. else
  422. if (z<SAVE_HEAD_HGT)
  423. // Head level...
  424. {
  425. if (bp<=SAVE_AHEADB_TIME/keeper_spd && !keep_dive)
  426. {
  427. keeper_contact=MCC_AHEADB;
  428. factor=1./((float)bp/(SAVE_AHEADB_TIME/keeper_spd));
  429. if (factor>max_kp_margin && !forced)
  430. {
  431. // Ball is too fast!
  432. factor=max_kp_margin;
  433. keeper_will_save=FALSE;
  434. player->tm_fstep=MC_AHEADB_FS*factor*keeper_spd;
  435. }
  436. else
  437. player->tm_fstep=keeper_contact/bp;
  438. if (player->tm_fstep>=1)
  439. player->tm_fstep=1;
  440. save_block=TRUE;
  441. init_save_act(player,x,y,z,MC_AHEADB,zone,bp,(int)(SAVE_AHEADB_TIME/keeper_spd));
  442. }
  443. else
  444. if (bp<=SAVE_AHEADC_TIME/keeper_spd || keep_dive)
  445. {
  446. keeper_contact=MCC_AHEADC;
  447. factor=1./((float)bp/(SAVE_AHEADC_TIME/keeper_spd));
  448. if (factor>max_kp_margin && !forced)
  449. {
  450. // Ball is too fast!
  451. factor=max_kp_margin;
  452. keeper_will_save=FALSE;
  453. player->tm_fstep=MC_AHEADC_FS*factor*keeper_spd;
  454. }
  455. else
  456. player->tm_fstep=keeper_contact/bp;
  457. if (player->tm_fstep>=1)
  458. player->tm_fstep=1;
  459. save_block=FALSE;
  460. init_save_act(player,x,y,z,MC_AHEADC,zone,bp,(int)(SAVE_AHEADC_TIME/keeper_spd));
  461. }
  462. else
  463. // Move to best position...
  464. {
  465. shot_acknowledged=1;
  466. }
  467. }
  468. else
  469. if (z<SAVE_JUMP_HGT)
  470. // Above head level...
  471. {
  472. if (bp<=SAVE_AJUMPB_TIME/keeper_spd && !keep_dive)
  473. {
  474. keeper_contact=MCC_AJUMPB;
  475. factor=1./((float)bp/(SAVE_AJUMPB_TIME/keeper_spd));
  476. if (factor>max_kp_margin && !forced)
  477. {
  478. // Ball is too fast!
  479. factor=max_kp_margin;
  480. keeper_will_save=FALSE;
  481. player->tm_fstep=MC_AJUMPB_FS*factor*keeper_spd;
  482. }
  483. else
  484. player->tm_fstep=keeper_contact/bp;
  485. if (player->tm_fstep>=1)
  486. player->tm_fstep=1;
  487. save_block=TRUE;
  488. init_save_act(player,x,y,z,MC_AJUMPB,zone,bp,(int)(SAVE_AJUMPB_TIME/keeper_spd));
  489. }
  490. else
  491. if (bp<=SAVE_AJUMPC_TIME/keeper_spd || keep_dive)
  492. {
  493. keeper_contact=MCC_AJUMPC;
  494. factor=1./((float)bp/(SAVE_AJUMPC_TIME/keeper_spd));
  495. if (factor>max_kp_margin && !forced)
  496. {
  497. // Ball is too fast!
  498. factor=max_kp_margin;
  499. keeper_will_save=FALSE;
  500. player->tm_fstep=MC_AJUMPC_FS*factor*keeper_spd;
  501. }
  502. else
  503. player->tm_fstep=keeper_contact/bp;
  504. if (player->tm_fstep>=1)
  505. player->tm_fstep=1;
  506. save_block=FALSE;
  507. init_save_act(player,x,y,z,MC_AJUMPC,zone,bp,(int)(SAVE_AJUMPC_TIME/keeper_spd));
  508. }
  509. else
  510. // Move to best position...
  511. {
  512. shot_acknowledged=1;
  513. }
  514. }
  515. }
  516. /******************************************************************************
  517. *****************************************************************************/
  518. void save_in_zone_b(match_player *player,float x,float y,float z,int bp,char forced)
  519. {
  520. float factor;
  521. keeper_on_grnd=FALSE;
  522. keeper_will_save=TRUE;
  523. int zone=2;
  524. if (z<SAVE_FEET_HGT)
  525. // Feet level...
  526. {
  527. if (bp<=SAVE_BFOOTB_TIME/keeper_spd && !keep_dive)
  528. {
  529. keeper_contact=MCC_BFOOTB;
  530. factor=1./((float)bp/(SAVE_BFOOTB_TIME/keeper_spd));
  531. if (factor>max_kp_margin && !forced)
  532. {
  533. // Ball is too fast!
  534. factor=max_kp_margin;
  535. keeper_will_save=FALSE;
  536. player->tm_fstep=MC_BFOOTB_FS*factor*keeper_spd;
  537. }
  538. else
  539. player->tm_fstep=keeper_contact/bp;
  540. if (player->tm_fstep>=1)
  541. player->tm_fstep=1;
  542. save_block=TRUE;
  543. init_save_act(player,x,y,z,MC_BFOOTBL,zone,bp,(int)(SAVE_BFOOTB_TIME/keeper_spd));
  544. }
  545. else
  546. if (bp<=SAVE_BFOOTC_TIME/keeper_spd || keep_dive)
  547. {
  548. keeper_contact=MCC_BFOOTC;
  549. factor=1./((float)bp/(SAVE_BFOOTC_TIME/keeper_spd));
  550. if (factor>max_kp_margin && !forced)
  551. {
  552. // Ball is too fast!
  553. factor=max_kp_margin;
  554. keeper_will_save=FALSE;
  555. player->tm_fstep=MC_BFOOTC_FS*factor*keeper_spd;
  556. }
  557. else
  558. player->tm_fstep=keeper_contact/bp;
  559. if (player->tm_fstep>=1)
  560. player->tm_fstep=1;
  561. save_block=FALSE;
  562. keeper_on_grnd=TRUE;
  563. init_save_act(player,x,y,z,MC_BFOOTCL,zone,bp,(int)(SAVE_BFOOTC_TIME/keeper_spd));
  564. }
  565. else
  566. // Move to best position...
  567. {
  568. shot_acknowledged=1;
  569. }
  570. }
  571. else
  572. if (z<SAVE_CHEST_HGT)
  573. // Chest level...
  574. {
  575. if (bp<=SAVE_BBODYB_TIME/keeper_spd && !keep_dive)
  576. {
  577. keeper_contact=MCC_BBODYB;
  578. factor=1./((float)bp/(SAVE_BBODYB_TIME/keeper_spd));
  579. if (factor>max_kp_margin && !forced)
  580. {
  581. // Ball is too fast!
  582. factor=max_kp_margin;
  583. keeper_will_save=FALSE;
  584. player->tm_fstep=MC_BBODYB_FS*factor*keeper_spd;
  585. }
  586. else
  587. player->tm_fstep=keeper_contact/bp;
  588. if (player->tm_fstep>=1)
  589. player->tm_fstep=1;
  590. save_block=TRUE;
  591. keeper_on_grnd=TRUE;
  592. init_save_act(player,x,y,z,MC_BBODYBL,zone,bp,(int)(SAVE_BBODYB_TIME/keeper_spd));
  593. }
  594. else
  595. if (bp<=SAVE_BBODYC_TIME/keeper_spd || keep_dive)
  596. {
  597. keeper_contact=MCC_BBODYC;
  598. factor=1./((float)bp/(SAVE_BBODYC_TIME/keeper_spd));
  599. if (factor>max_kp_margin && !forced)
  600. {
  601. // Ball is too fast!
  602. factor=max_kp_margin;
  603. keeper_will_save=FALSE;
  604. player->tm_fstep=MC_BBODYC_FS*factor*keeper_spd;
  605. }
  606. else
  607. player->tm_fstep=keeper_contact/bp;
  608. if (player->tm_fstep>=1)
  609. player->tm_fstep=1;
  610. save_block=FALSE;
  611. keeper_on_grnd=TRUE;
  612. init_save_act(player,x,y,z,MC_BBODYCL,zone,bp,(int)(SAVE_BBODYC_TIME/keeper_spd));
  613. }
  614. else
  615. // Move to best position...
  616. {
  617. shot_acknowledged=1;
  618. }
  619. }
  620. else
  621. if (z<SAVE_HEAD_HGT)
  622. // Head level...
  623. {
  624. if (bp<=SAVE_BHEADB_TIME/keeper_spd && !keep_dive)
  625. {
  626. keeper_contact=MCC_BHEADB;
  627. factor=1./((float)bp/(SAVE_BHEADB_TIME/keeper_spd));
  628. if (factor>max_kp_margin && !forced)
  629. {
  630. // Ball is too fast!
  631. factor=max_kp_margin;
  632. keeper_will_save=FALSE;
  633. player->tm_fstep=MC_BHEADB_FS*factor*keeper_spd;
  634. }
  635. else
  636. player->tm_fstep=keeper_contact/bp;
  637. if (player->tm_fstep>=1)
  638. player->tm_fstep=1;
  639. save_block=TRUE;
  640. init_save_act(player,x,y,z,MC_BHEADBL,zone,bp,(int)(SAVE_BHEADB_TIME/keeper_spd));
  641. }
  642. else
  643. if (bp<=SAVE_BHEADC_TIME/keeper_spd || keep_dive)
  644. {
  645. keeper_contact=MCC_BHEADC;
  646. factor=1./((float)bp/(SAVE_BHEADC_TIME/keeper_spd));
  647. if (factor>max_kp_margin && !forced)
  648. {
  649. // Ball is too fast!
  650. factor=max_kp_margin;
  651. keeper_will_save=FALSE;
  652. player->tm_fstep=MC_BHEADC_FS*factor*keeper_spd;
  653. }
  654. else
  655. player->tm_fstep=keeper_contact/bp;
  656. if (player->tm_fstep>=1)
  657. player->tm_fstep=1;
  658. save_block=FALSE;
  659. init_save_act(player,x,y,z,MC_BHEADCL,zone,bp,(int)(SAVE_BHEADC_TIME/keeper_spd));
  660. }
  661. else
  662. // Move to best position...
  663. {
  664. shot_acknowledged=1;
  665. }
  666. }
  667. else
  668. if (z<SAVE_JUMP_HGT)
  669. // Above head level...
  670. {
  671. if (bp<=SAVE_BJUMPB_TIME/keeper_spd && !keep_dive)
  672. {
  673. keeper_contact=MCC_BJUMPB;
  674. factor=1./((float)bp/(SAVE_BJUMPB_TIME/keeper_spd));
  675. if (factor>max_kp_margin && !forced)
  676. {
  677. // Ball is too fast!
  678. factor=max_kp_margin;
  679. keeper_will_save=FALSE;
  680. player->tm_fstep=MC_BJUMPB_FS*factor*keeper_spd;
  681. }
  682. else
  683. player->tm_fstep=keeper_contact/bp;
  684. if (player->tm_fstep>=1)
  685. player->tm_fstep=1;
  686. save_block=TRUE;
  687. init_save_act(player,x,y,z,MC_BJUMPBL,zone,bp,(int)(SAVE_BJUMPB_TIME/keeper_spd));
  688. }
  689. else
  690. // Move to best position...
  691. {
  692. shot_acknowledged=1;
  693. }
  694. }
  695. }
  696. /******************************************************************************
  697. *****************************************************************************/
  698. void save_in_zone_c(match_player *player,float x,float y,float z,int bp,char forced)
  699. {
  700. float factor;
  701. keeper_will_save=TRUE;
  702. keeper_on_grnd=FALSE;
  703. int zone=3;
  704. if (z<SAVE_FEET_HGT)
  705. // Feet level...
  706. {
  707. if (bp<=SAVE_CFOOTB_TIME/keeper_spd && !keep_dive)
  708. {
  709. keeper_contact=MCC_CFOOTB;
  710. factor=1./((float)bp/(SAVE_CFOOTB_TIME/keeper_spd));
  711. if (factor>max_kp_margin && !forced)
  712. {
  713. // Ball is too fast!
  714. factor=max_kp_margin;
  715. keeper_will_save=FALSE;
  716. player->tm_fstep=MC_CFOOTB_FS*factor*keeper_spd;
  717. }
  718. else
  719. player->tm_fstep=keeper_contact/bp;
  720. if (player->tm_fstep>=1)
  721. player->tm_fstep=1;
  722. save_block=TRUE;
  723. keeper_on_grnd=TRUE;
  724. init_save_act(player,x,y,z,MC_CFOOTBL,zone,bp,(int)(SAVE_CFOOTB_TIME/keeper_spd));
  725. }
  726. else
  727. if (bp<=SAVE_CFOOTC_TIME/keeper_spd || keep_dive)
  728. {
  729. keeper_contact=MCC_CFOOTC;
  730. factor=1./((float)bp/(SAVE_CFOOTC_TIME/keeper_spd));
  731. if (factor>max_kp_margin && !forced)
  732. {
  733. // Ball is too fast!
  734. factor=max_kp_margin;
  735. keeper_will_save=FALSE;
  736. player->tm_fstep=MC_CFOOTC_FS*factor*keeper_spd;
  737. }
  738. else
  739. player->tm_fstep=keeper_contact/bp;
  740. if (player->tm_fstep>=1)
  741. player->tm_fstep=1;
  742. save_block=FALSE;
  743. keeper_on_grnd=TRUE;
  744. init_save_act(player,x,y,z,MC_CFOOTCL,zone,bp,(int)(SAVE_CFOOTC_TIME/keeper_spd));
  745. }
  746. else
  747. // Move to best position...
  748. {
  749. shot_acknowledged=1;
  750. }
  751. }
  752. else
  753. if (z<SAVE_CHEST_HGT)
  754. // Chest level...
  755. {
  756. if (bp<=SAVE_CBODYB_TIME/keeper_spd && !keep_dive)
  757. {
  758. keeper_contact=MCC_CBODYB;
  759. factor=1./((float)bp/(SAVE_CBODYB_TIME/keeper_spd));
  760. if (factor>max_kp_margin && !forced)
  761. {
  762. // Ball is too fast!
  763. factor=max_kp_margin;
  764. keeper_will_save=FALSE;
  765. player->tm_fstep=MC_CBODYB_FS*factor*keeper_spd;
  766. }
  767. else
  768. player->tm_fstep=keeper_contact/bp;
  769. if (player->tm_fstep>=1)
  770. player->tm_fstep=1;
  771. save_block=TRUE;
  772. keeper_on_grnd=TRUE;
  773. init_save_act(player,x,y,z,MC_CBODYBL,zone,bp,(int)(SAVE_CBODYB_TIME/keeper_spd));
  774. }
  775. else
  776. if (bp<=SAVE_CBODYC_TIME/keeper_spd || keep_dive)
  777. {
  778. keeper_contact=MCC_CBODYC;
  779. factor=1./((float)bp/(SAVE_CBODYC_TIME/keeper_spd));
  780. if (factor>max_kp_margin && !forced)
  781. {
  782. // Ball is too fast!
  783. factor=max_kp_margin;
  784. keeper_will_save=FALSE;
  785. player->tm_fstep=MC_CBODYC_FS*factor*keeper_spd;
  786. }
  787. else
  788. player->tm_fstep=keeper_contact/bp;
  789. if (player->tm_fstep>=1)
  790. player->tm_fstep=1;
  791. save_block=FALSE;
  792. keeper_on_grnd=TRUE;
  793. init_save_act(player,x,y,z,MC_CBODYCL,zone,bp,(int)(SAVE_CBODYC_TIME/keeper_spd));
  794. }
  795. else
  796. // Move to best position...
  797. {
  798. shot_acknowledged=1;
  799. }
  800. }
  801. else
  802. if (z<SAVE_HEAD_HGT)
  803. // Head level...
  804. {
  805. if (bp<=SAVE_CHEADB_TIME/keeper_spd && !keep_dive)
  806. {
  807. keeper_contact=MCC_CHEADB;
  808. factor=1./((float)bp/(SAVE_CHEADB_TIME/keeper_spd));
  809. if (factor>max_kp_margin && !forced)
  810. {
  811. // Ball is too fast!
  812. factor=max_kp_margin;
  813. keeper_will_save=FALSE;
  814. player->tm_fstep=MC_CHEADB_FS*factor*keeper_spd;
  815. }
  816. else
  817. player->tm_fstep=keeper_contact/bp;
  818. if (player->tm_fstep>=1)
  819. player->tm_fstep=1;
  820. save_block=TRUE;
  821. init_save_act(player,x,y,z,MC_CHEADBL,zone,bp,(int)(SAVE_CHEADB_TIME/keeper_spd));
  822. }
  823. else
  824. // Move to best position...
  825. {
  826. shot_acknowledged=1;
  827. }
  828. }
  829. else
  830. if (z<SAVE_JUMP_HGT)
  831. // Above head level...
  832. {
  833. if (bp<=SAVE_CJUMPB_TIME/keeper_spd || keep_dive)
  834. {
  835. keeper_contact=MCC_CJUMPB;
  836. factor=1./((float)bp/(SAVE_CJUMPB_TIME/keeper_spd));
  837. if (factor>max_kp_margin && !forced)
  838. {
  839. // Ball is too fast!
  840. factor=max_kp_margin;
  841. keeper_will_save=FALSE;
  842. player->tm_fstep=MC_CJUMPB_FS*factor*keeper_spd;
  843. }
  844. else
  845. player->tm_fstep=keeper_contact/bp;
  846. if (player->tm_fstep>=1)
  847. player->tm_fstep=1;
  848. save_block=TRUE;
  849. init_save_act(player,x,y,z,MC_CJUMPBL,zone,bp,(int)(SAVE_CJUMPB_TIME/keeper_spd));
  850. }
  851. else
  852. // Move to best position...
  853. {
  854. shot_acknowledged=1;
  855. }
  856. }
  857. }
  858. /******************************************************************************
  859. *****************************************************************************/
  860. // Send keeper to point between centre of goal and ball!
  861. // Point ratio between goal and ball varies with distance to ball.
  862. // i.e. If opponent is close then point will be further from goal.
  863. void close_angle(match_player *player,float d,float &x,float &y)
  864. {
  865. float gx,gd,cd;
  866. cd=CLOSE_ANG_DIST+(prat*player->tm_vis)/8;
  867. if (player->tm_player<12)
  868. // Keeper A...
  869. gx=0;
  870. else
  871. // Keeper B...
  872. gx=pitch_len;
  873. gd=prat+(d*((cd-d)/cd)); // How far target point is along line.
  874. x=gx+((ballx-gx)*gd/d);
  875. y=cntspot_y+((bally-cntspot_y)*gd/d);
  876. }
  877. /******************************************************************************
  878. *****************************************************************************/
  879. char target_towards_ball(float tx,float ty,float px,float py)
  880. {
  881. // Get distance of target to present ball pos.
  882. float d=calc_dist(tx-ballx,ty-bally);
  883. if (d<=calc_dist(px-ballx,py-bally))
  884. return(TRUE); // Player is further from ball than target!
  885. return(FALSE);
  886. }
  887. /******************************************************************************
  888. *****************************************************************************/
  889. void init_user_save(match_player *player)
  890. {
  891. int t;
  892. float dist=prat*1.4;
  893. keeper_will_save=FALSE;
  894. save_block=TRUE;
  895. reset_ideas(player);
  896. if (save_direction)
  897. {
  898. // Direction selected...
  899. if (save_direction>0)
  900. {
  901. // Raw Left...
  902. if (match_mode==PEN_KICK_A)
  903. {
  904. // Dive Right and Up-field...
  905. init_anim(player,MC_CBODYBR);
  906. t=(SAVE_BBODYB_TIME/keeper_spd);
  907. dist=-dist;
  908. }
  909. else
  910. {
  911. // Dive Right and Down-field...
  912. init_anim(player,MC_CBODYBR);
  913. t=(SAVE_BBODYB_TIME/keeper_spd);
  914. }
  915. }
  916. else
  917. {
  918. // Raw Right...
  919. if (match_mode==PEN_KICK_A)
  920. {
  921. // Dive Left and Down-field...
  922. init_anim(player,MC_CBODYBL);
  923. t=(SAVE_BBODYB_TIME/keeper_spd);
  924. }
  925. else
  926. {
  927. // Dive Left and Up-field...
  928. init_anim(player,MC_CBODYBL);
  929. t=(SAVE_BBODYB_TIME/keeper_spd);
  930. dist=-dist;
  931. }
  932. }
  933. }
  934. else
  935. {
  936. init_anim(player,MC_ABODYB);
  937. t=(SAVE_ABODYB_TIME/keeper_spd);
  938. dist=0;
  939. }
  940. player->go_tx=player->tm_x;
  941. player->go_ty=player->tm_y+dist;
  942. player->go_txdis=0;
  943. player->go_tydis=dist/t;
  944. player->go_cnt=1/player->tm_fstep;
  945. player->dir_mode=5;
  946. player->tm_zdis=0;
  947. if (keeper_on_grnd)
  948. // Stay down for a bit after save...
  949. if (save_block)
  950. player->int_cnt=4+((128-player->tm_rate)/12)+1/player->tm_fstep; // Time to get up!
  951. else
  952. player->int_cnt=18+1/player->tm_fstep; // Time to get up!
  953. else
  954. player->int_cnt=2+1/player->tm_fstep;
  955. player->int_move=I_SAVE_WAIT;
  956. action="Save";
  957. player->tm_act=SAVE_ACT;
  958. newdx=player->tm_xdis;
  959. newdy=player->tm_ydis;
  960. }
  961. /******************************************************************************
  962. *****************************************************************************/
  963. #define DIVE_POINT 3
  964. #define DIVE_FEET_DIST (prat*4)
  965. // Someone has shot...
  966. // Send keeper to intersection with ball path.
  967. // If he cannot meet ball then best try!
  968. void go_to_save_path(match_player *player,char forced=FALSE)
  969. {
  970. keeper_spd=((float)(player->tm_flair+player->tm_rate)/128)*(forced ? 2:1);
  971. // Calculate next frame distance to the ball...
  972. float d=calc_dist(player->tm_x-(ballx+ballxdis),player->tm_y-(bally+ballydis));
  973. if (!forced)
  974. {
  975. if (d<player->tm_dist)
  976. // Ball is getting closer...
  977. {
  978. if (player->tm_player==KP_A)
  979. {
  980. // Keeper A
  981. if (ballx<cntspot_x)
  982. shot_acknowledged=1+((128-player->tm_vis)/8);
  983. }
  984. else
  985. {
  986. // Keeper B
  987. if (ballx>cntspot_x)
  988. shot_acknowledged=1+((128-player->tm_vis)/8);
  989. }
  990. }
  991. }
  992. if (shot_acknowledged || forced)
  993. {
  994. int flag;
  995. int vision=((128-player->tm_vis)/2);
  996. // Is shot on Target?
  997. // if (ABS(ballxdis)>0)
  998. {
  999. float kp_xoff;
  1000. float x,y,z,ox,oy,oz;
  1001. float xc,yc,zc;
  1002. float xf,yf,zf;
  1003. float xns,yns,zns;
  1004. int bp,ob;
  1005. float min_d=2000;
  1006. float d,t,fd;
  1007. float px=player->tm_x;
  1008. float py=player->tm_y;
  1009. float rate=actual_spd(player); // Dive is 2 x rate.
  1010. flag=FALSE;
  1011. char in_area=FALSE;
  1012. bp=1;
  1013. ob=1;
  1014. ox=ballx;
  1015. oy=bally;
  1016. oz=ballz;
  1017. xc=ballx;
  1018. yc=bally;
  1019. zc=ballz;
  1020. if (!keep_dive)
  1021. {
  1022. float see_swerve;
  1023. see_swerve=(64.+(player->tm_vis/2))/128;
  1024. for (int i=1; i<50; i++)
  1025. {
  1026. // Coords without swerve...
  1027. xns=ns_ball_pred_tab[i][0];
  1028. yns=ns_ball_pred_tab[i][1];
  1029. zns=ns_ball_pred_tab[i][2];
  1030. // Coords with swerve...
  1031. x=ball_pred_tab[i][0];
  1032. y=ball_pred_tab[i][1];
  1033. z=ball_pred_tab[i][2];
  1034. // Coords seeing some swerve...
  1035. x=xns+((x-xns)*see_swerve);
  1036. y=yns+((y-yns)*see_swerve);
  1037. z=zns+((z-zns)*see_swerve);
  1038. in_area=FALSE;
  1039. if (y>top_post_y && y<bot_post_y)
  1040. kp_xoff=4;
  1041. else
  1042. kp_xoff=0;
  1043. // Try and stop keeper saving and carrying ball behind line...
  1044. if (x>cntspot_x)
  1045. {
  1046. // Team B goal-line...
  1047. if (x>=pitch_len-kp_xoff)
  1048. {
  1049. i=60;
  1050. if (ABS(y-cntspot_y)>((prat*4.5)+(128-player->tm_flair)/4))
  1051. // Too wide!
  1052. flag=FALSE; // Don't bother saving!
  1053. }
  1054. }
  1055. if (x<=cntspot_x)
  1056. {
  1057. // Team A goal-line...
  1058. if (x<0+kp_xoff)
  1059. {
  1060. i=60;
  1061. if (ABS(y-cntspot_y)>((prat*4.5)+(128-player->tm_flair)/4))
  1062. // Too wide!
  1063. flag=FALSE; // Don't bother saving!
  1064. }
  1065. }
  1066. if (i!=60)
  1067. {
  1068. if (player->tm_player<12)
  1069. {
  1070. if (x<prat*18 && y>cntspot_y-(21*prat)
  1071. && (y<cntspot_y+(21*prat)))
  1072. in_area=TRUE;
  1073. }
  1074. else
  1075. {
  1076. if (x>pitch_len-(prat*18) && y>cntspot_y-(21*prat)
  1077. && (y<cntspot_y+(21*prat)))
  1078. in_area=TRUE;
  1079. }
  1080. if (in_area)
  1081. {
  1082. d=calc_dist(x-px,y-py);
  1083. // if (d<min_d && z<SAVE_JUMP_HGT+prat && target_towards_ball(x,y,px,py))
  1084. if (d<min_d && z<SAVE_JUMP_HGT+prat/2)
  1085. // Store closest ball!
  1086. {
  1087. ox=xc;
  1088. oy=yc;
  1089. oz=zc;
  1090. ob=bp;
  1091. min_d=d;
  1092. bp=i;
  1093. xc=x;
  1094. yc=y;
  1095. zc=z;
  1096. flag=TRUE;
  1097. }
  1098. else
  1099. // Getting further away...
  1100. {
  1101. if (d-min_d>prat)
  1102. // Definately not getting any closer...
  1103. {
  1104. i=60; // Quit.
  1105. }
  1106. }
  1107. }
  1108. }
  1109. }
  1110. }
  1111. else
  1112. {
  1113. flag=TRUE;
  1114. xc=ball_pred_tab[DIVE_POINT][0];
  1115. yc=ball_pred_tab[DIVE_POINT][1];
  1116. zc=ball_pred_tab[DIVE_POINT][2];
  1117. d=calc_dist(xc-px,yc-py);
  1118. x=(xc-px)/d;
  1119. y=(yc-py)/d;
  1120. if (keep_dive)
  1121. {
  1122. xc+=x*prat;
  1123. yc+=y*prat;
  1124. }
  1125. ox=xc;
  1126. oy=yc;
  1127. oz=zc;
  1128. ob=DIVE_POINT;
  1129. bp=DIVE_POINT;
  1130. }
  1131. if (flag)
  1132. // Shot is in area...
  1133. {
  1134. x=ox+((xc-ox)/2); // Between closest and one before...
  1135. y=oy+((yc-oy)/2);
  1136. z=oz+((zc-oz)/2);
  1137. if (forced) // Forced to dive at attackers feet...
  1138. {
  1139. fd=calc_dist(x-px,y-py);
  1140. xf=(x-px)/fd;
  1141. yf=(y-py)/fd;
  1142. x+=xf*3;
  1143. y+=yf*3; // Dive beyond point of contact...
  1144. }
  1145. // bp=ob;
  1146. // Nearest ball coord.
  1147. d=calc_dist(x-px,y-py); // Distance to keeper...
  1148. char st=player->go_step;
  1149. player->go_step=TRUE;
  1150. t=d/actual_spd(player); // Time to step there...
  1151. player->go_step=st;
  1152. max_kp_margin=1.5+(1.8*time_factor/90);
  1153. /*************************************************************/
  1154. /*************************************************************/
  1155. #ifdef EURO96
  1156. if (penalty_shot && user_controlled)
  1157. {
  1158. if (users_dir[user_controlled-1].f&8)
  1159. save_direction=-1;
  1160. if (users_dir[user_controlled-1].f&4)
  1161. save_direction=1;
  1162. char good_choice=FALSE;
  1163. // User decides which way to dive...
  1164. if (t<1 && !save_direction)
  1165. {
  1166. // Straight on...(good choice!)
  1167. good_choice=TRUE;
  1168. }
  1169. else
  1170. {
  1171. if (save_direction)
  1172. {
  1173. // User has chosen a direction...
  1174. if (save_direction<0)
  1175. {
  1176. // Left selected...
  1177. if ((x<cntspot_x && player->tm_y>(y+(SAVE_ZONE_A/2)))
  1178. || (x>cntspot_x && player->tm_y<(y-(SAVE_ZONE_A/2))))
  1179. {
  1180. good_choice=TRUE;
  1181. }
  1182. }
  1183. else
  1184. {
  1185. // Right selected...
  1186. if ((x<cntspot_x && player->tm_y<(y-(SAVE_ZONE_A/2)))
  1187. || (x>cntspot_x && player->tm_y>(y+(SAVE_ZONE_A/2))))
  1188. {
  1189. good_choice=TRUE;
  1190. }
  1191. }
  1192. }
  1193. else
  1194. {
  1195. if (d<=SAVE_ZONE_A)
  1196. good_choice=TRUE;
  1197. }
  1198. }
  1199. if (good_choice)
  1200. {
  1201. // Let computer save...
  1202. if (t<1)
  1203. {
  1204. save_in_zone_a(player,x,y,z,bp,forced);
  1205. }
  1206. else
  1207. {
  1208. if (d<=SAVE_ZONE_A)
  1209. save_in_zone_a(player,x,y,z,bp,forced);
  1210. else
  1211. if (d<=SAVE_ZONE_B)
  1212. save_in_zone_b(player,x,y,z,bp,forced);
  1213. else
  1214. if (d<=(SAVE_ZONE_C+prat*2))
  1215. save_in_zone_c(player,x,y,z,bp,forced);
  1216. else
  1217. keep_dive=FALSE;
  1218. }
  1219. }
  1220. else
  1221. {
  1222. // Save in the direction of user's choice...
  1223. init_user_save(player);
  1224. }
  1225. }
  1226. else
  1227. #endif
  1228. /*************************************************************/
  1229. /*************************************************************/
  1230. {
  1231. if (t<1)
  1232. /************************************/
  1233. // Already in preferred position... //
  1234. /************************************/
  1235. {
  1236. save_in_zone_a(player,x,y,z,bp,forced);
  1237. }
  1238. else
  1239. {
  1240. if (t<bp-SAVE_AHEADC_TIME)
  1241. /************************************************************/
  1242. // Can get body behind it and still have time to animate... //
  1243. /************************************************************/
  1244. {
  1245. reset_ideas(player);
  1246. player->go_step=TRUE;
  1247. if (player->tm_player<12)
  1248. init_run_act(player,x-prat,y,TRUE); //ball meet point
  1249. else
  1250. init_run_act(player,x+prat,y,TRUE); //ball meet point
  1251. }
  1252. else
  1253. {
  1254. if (d<=SAVE_ZONE_A)
  1255. save_in_zone_a(player,x,y,z,bp,forced);
  1256. else
  1257. if (d<=SAVE_ZONE_B)
  1258. save_in_zone_b(player,x,y,z,bp,forced);
  1259. else
  1260. if (d<=(SAVE_ZONE_C+prat*2))
  1261. save_in_zone_c(player,x,y,z,bp,forced);
  1262. else
  1263. keep_dive=FALSE;
  1264. }
  1265. }
  1266. }
  1267. }
  1268. }
  1269. }
  1270. }
  1271. /******************************************************************************
  1272. *****************************************************************************/
  1273. void fake_ball_poss(int p,float x,float y,float z)
  1274. {
  1275. save_ball_poss=ball_poss;
  1276. save_ballx=ballx;
  1277. save_bally=bally;
  1278. save_ballz=ballz;
  1279. ballx=x;
  1280. bally=y;
  1281. ballz=z;
  1282. ball_poss=p;
  1283. }
  1284. /******************************************************************************
  1285. *****************************************************************************/
  1286. void restore_ball_poss()
  1287. {
  1288. ball_poss=save_ball_poss;
  1289. ballx=save_ballx;
  1290. bally=save_bally;
  1291. ballz=save_ballz;
  1292. }
  1293. /******************************************************************************
  1294. *****************************************************************************/
  1295. char kick_straight()
  1296. {
  1297. if (pass_type==-1 || (pass_type>=4 && pass_type<=6))
  1298. return(TRUE);
  1299. else
  1300. return(FALSE);
  1301. }
  1302. /******************************************************************************
  1303. *****************************************************************************/
  1304. char first_time_strike(int p,float x,float y,float z,float px,float py)
  1305. {
  1306. float d;
  1307. float obx=ballx;
  1308. float oby=bally;
  1309. char sr=teams[p-1].tm_srng;
  1310. if (p<12)
  1311. d=calc_dist(pitch_len-x,cntspot_y-y);
  1312. else
  1313. d=calc_dist(x,cntspot_y-y);
  1314. if (d<(MIN_SHOOT_DIST+((float)teams[p-1].tm_pow*3)))
  1315. teams[p-1].tm_srng=TRUE;
  1316. else
  1317. teams[p-1].tm_srng=FALSE;
  1318. float xpd=teams[p-1].tm_xdis;
  1319. float ypd=teams[p-1].tm_ydis;
  1320. teams[p-1].tm_xdis=x_face;
  1321. teams[p-1].tm_ydis=y_face;
  1322. ballx=teams[p-1].tm_x;
  1323. bally=teams[p-1].tm_y;
  1324. pass_type=FALSE;
  1325. receiver=FALSE;
  1326. char allow=0;
  1327. float gx,gy;
  1328. if (p<12)
  1329. gx=pitch_len;
  1330. else
  1331. gx=0;
  1332. gy=cntspot_y;
  1333. gx-=x;
  1334. gy-=y;
  1335. d=calc_dist(gx,gy);
  1336. fake_ball_poss(p,x,y,z);
  1337. if (auto_select)
  1338. {
  1339. if (ball_int_speed>6)
  1340. {
  1341. // Ball is moving so he can trap...
  1342. allow=128; // Can control it...
  1343. }
  1344. if (shoot_decide(&teams[p-1]))
  1345. {
  1346. pass_type=0;
  1347. allow+=3; // Kick or volley!
  1348. if (d<MIN_HEADER_RNG+(prat*teams[p-1].tm_pow/8))
  1349. // In head range also!
  1350. {
  1351. allow+=8+16; // Standing or Jumping header!
  1352. if (kick_straight())
  1353. // Target is forward!
  1354. allow+=4; // Diving header!
  1355. }
  1356. }
  1357. else
  1358. {
  1359. teams[p-1].tm_xdis=-teams[p-1].tm_xdis;
  1360. teams[p-1].tm_ydis=-teams[p-1].tm_ydis; // Reverse face!
  1361. if (shoot_decide(&teams[p-1]))
  1362. {
  1363. pass_type=0;
  1364. allow+=32; // Overhead!
  1365. }
  1366. else
  1367. {
  1368. if (punt_decide(&teams[p-1])) // Overhead punt???
  1369. {
  1370. pass_type=0;
  1371. allow+=32; // Overhead!
  1372. }
  1373. else
  1374. {
  1375. teams[p-1].tm_xdis=-teams[p-1].tm_xdis;
  1376. teams[p-1].tm_ydis=-teams[p-1].tm_ydis; // Reverse face!
  1377. if (punt_decide(&teams[p-1]))
  1378. {
  1379. pass_type=0;
  1380. allow+=1+2+4+8+16; // Kick or volley or any header!
  1381. }
  1382. else
  1383. {
  1384. receiver=pass_decide(&teams[p-1],FALSE);
  1385. if (receiver)
  1386. {
  1387. if (pass_type==-1)
  1388. // Chip pass!
  1389. allow+=64+8+16; // Chip, S-head, J-head!
  1390. else
  1391. {
  1392. if (kick_straight())
  1393. allow+=8+16; // S-head, J-head!
  1394. }
  1395. }
  1396. }
  1397. }
  1398. }
  1399. }
  1400. }
  1401. else
  1402. allow=0;
  1403. restore_ball_poss();
  1404. teams[p-1].tm_srng=sr; // Restore range flag!
  1405. teams[p-1].tm_xdis=xpd;
  1406. teams[p-1].tm_ydis=ypd;
  1407. ballx=obx;
  1408. bally=oby;
  1409. return(allow);
  1410. }
  1411. /******************************************************************************
  1412. *****************************************************************************/
  1413. char user_pass_check(int p,float x,float y,float z,float px,float py)
  1414. {
  1415. float d;
  1416. float obx=ballx;
  1417. float oby=bally;
  1418. char sr=teams[p-1].tm_srng;
  1419. if (p<12)
  1420. d=calc_dist(pitch_len-x,cntspot_y-y);
  1421. else
  1422. d=calc_dist(x,cntspot_y-y);
  1423. if (d<(MIN_SHOOT_DIST+((float)teams[p-1].tm_pow*3)))
  1424. teams[p-1].tm_srng=TRUE;
  1425. else
  1426. teams[p-1].tm_srng=FALSE;
  1427. float xpd=teams[p-1].tm_xdis;
  1428. float ypd=teams[p-1].tm_ydis;
  1429. teams[p-1].tm_xdis=x_face;
  1430. teams[p-1].tm_ydis=y_face;
  1431. ballx=teams[p-1].tm_x;
  1432. bally=teams[p-1].tm_y;
  1433. pass_type=FALSE;
  1434. receiver=FALSE;
  1435. char allow=0;
  1436. float gx,gy;
  1437. if (p<12)
  1438. gx=pitch_len;
  1439. else
  1440. gx=0;
  1441. gy=cntspot_y;
  1442. gx-=x;
  1443. gy-=y;
  1444. d=calc_dist(gx,gy);
  1445. fake_ball_poss(p,x,y,z);
  1446. receiver=pass_decide(&teams[p-1],FALSE);
  1447. if (receiver)
  1448. {
  1449. if (pass_type==-1)
  1450. // Chip pass!
  1451. allow+=64+8+16; // Chip, S-head, J-head!
  1452. else
  1453. {
  1454. if (kick_straight())
  1455. allow+=8+16; // S-head, J-head!
  1456. }
  1457. }
  1458. else
  1459. allow=0;
  1460. restore_ball_poss();
  1461. teams[p-1].tm_srng=sr; // Restore range flag!
  1462. teams[p-1].tm_xdis=xpd;
  1463. teams[p-1].tm_ydis=ypd;
  1464. ballx=obx;
  1465. bally=oby;
  1466. return(allow);
  1467. }
  1468. /******************************************************************************
  1469. *****************************************************************************/
  1470. void decide_strike(match_player *p,short t,char c,char s)
  1471. {
  1472. float x=ball_pred_tab[t][0];
  1473. float y=ball_pred_tab[t][1];
  1474. float z=ball_pred_tab[t][1];
  1475. p->int_cnt=t; // Flair factor.
  1476. init_run_act(p,x,y,TRUE);
  1477. p->tm_strike=TRUE;
  1478. }
  1479. /******************************************************************************
  1480. *****************************************************************************/
  1481. void strike_and_control(match_player *player,intercept_data *s,short action)
  1482. {
  1483. player->tm_stime=s->atime+1;
  1484. // player->int_cnt=player->tm_stime+alarm+free+1; // Make sure he seems busy for the duration!
  1485. float x=s->x;
  1486. float y=s->y;
  1487. switch(action)
  1488. {
  1489. case(7):
  1490. case(9):
  1491. case(10):
  1492. if (player->tm_fpass_type=s->ptype)
  1493. // Equate pass type and test!
  1494. player->tm_fpass_to=s->pplr;
  1495. break;
  1496. }
  1497. short gt=get_there_time(player->tm_player,x,y);
  1498. player->tm_ftime=s->free;
  1499. player->tm_strike=action;
  1500. init_run_act(player,x,y,FALSE);
  1501. player->int_cnt=player->go_cnt+player->tm_ftime+player->tm_stime;
  1502. if (must_face)
  1503. player->int_cnt+=player->mface_time;
  1504. if (user_controlled)
  1505. {
  1506. player->special=-TRUE; // Special action decided!
  1507. /*
  1508. if (player->go_cnt>1)
  1509. {
  1510. player->go_cnt=1;
  1511. player->int_cnt=1;
  1512. }
  1513. */
  1514. }
  1515. }
  1516. /******************************************************************************
  1517. *****************************************************************************/
  1518. void cancel_int(int p)
  1519. {
  1520. // should never get here!
  1521. init_stand_act(&teams[p-1]);
  1522. }
  1523. /******************************************************************************
  1524. *****************************************************************************/
  1525. void intercept(int p)
  1526. {
  1527. action="Intercept";
  1528. reset_ideas(&teams[p-1]);
  1529. if (p<12)
  1530. interceptor_a=p;
  1531. else
  1532. interceptor_b=p;
  1533. // His intention is to intercept ball.
  1534. // Therefore his flair determines no. of turns before rethink!
  1535. int ff=33-(teams[p-1].tm_flair/4);
  1536. teams[p-1].int_move=I_INTERCEPT; // Intercept ball!
  1537. teams[p-1].int_cnt=ff; // Intercept ball!
  1538. float x,y;
  1539. if (special_move)
  1540. teams[p-1].special=TRUE;
  1541. else
  1542. teams[p-1].special=FALSE;
  1543. {
  1544. for (short i=10; i>=0; i--)
  1545. {
  1546. if (strike[i].t)
  1547. {
  1548. if (i>0)
  1549. {
  1550. if (user_controlled)
  1551. {
  1552. // uf1 = strike, uf2 = control!
  1553. if (uf1 && i>4)
  1554. {
  1555. strike_and_control(&teams[p-1],&strike[i],i);
  1556. break;
  1557. }
  1558. else
  1559. {
  1560. if (uf2 && i<=4 && i)
  1561. {
  1562. strike_and_control(&teams[p-1],&strike[i],i);
  1563. break;
  1564. }
  1565. }
  1566. }
  1567. else
  1568. {
  1569. strike_and_control(&teams[p-1],&strike[i],i);
  1570. break;
  1571. }
  1572. }
  1573. else
  1574. {
  1575. // Run onto ball...
  1576. if (strike[0].stop)
  1577. init_stop_act(&teams[p-1],strike[0].x,strike[0].y);
  1578. else
  1579. init_run_act(&teams[p-1],strike[0].x,strike[0].y,FALSE);
  1580. teams[p-1].go_cnt++;
  1581. break;
  1582. }
  1583. }
  1584. }
  1585. }
  1586. }
  1587. /******************************************************************************
  1588. *****************************************************************************/
  1589. float fstep_factor(short c)
  1590. {
  1591. // Returns a range of 0.6(c=0) to 1.6(c=128)
  1592. float f=0.6+((float)c/128);
  1593. return(f);
  1594. }
  1595. /******************************************************************************
  1596. *****************************************************************************/
  1597. #ifdef EURO96
  1598. // Euro 96 has first time pass implemented...
  1599. char can_i_intercept(int p_num,float x,float y,float z,float px,float py,short i)
  1600. {
  1601. if (z>=teams[p_num-1].tm_jump)
  1602. return(FALSE);
  1603. float cx,cy,cz,cx2,cy2,ang;
  1604. float rate=full_spd(&teams[p_num-1]);
  1605. float d=calc_dist(x-px,y-py);
  1606. char can_strike;
  1607. char do_it=FALSE;
  1608. char stand;
  1609. char strike_option=FALSE;
  1610. char trap_option=FALSE;
  1611. char pass_option=FALSE;
  1612. short ff=1+teams[p_num-1].tm_flair/16; // Reaction times.
  1613. short gt=get_there_time(p_num,x,y);
  1614. short t;
  1615. if (gt<=i)
  1616. {
  1617. // He can get to ball in time...
  1618. if (ball_poss)
  1619. {
  1620. // Opponent has ball... (No control or strike!)
  1621. /***** RUN ONTO BALL *****/
  1622. t=i-gt;
  1623. if (t>0 && t<strike[0].free && (teams[p_num-1].control || t<ff))
  1624. {
  1625. strike[0].t=i;
  1626. strike[0].free=t;
  1627. strike[0].x=x;
  1628. strike[0].y=y;
  1629. strike[0].stop=stop_and_face;
  1630. do_it=TRUE;
  1631. }
  1632. }
  1633. else
  1634. {
  1635. if (user_controlled)
  1636. {
  1637. can_strike=128+32+16+8+4+2+1;
  1638. pass_type=0;
  1639. strike_option=uf1&(!uf2);
  1640. trap_option=uf2&(!uf1);
  1641. pass_option=uf1&uf2;
  1642. if (pass_option)
  1643. can_strike=user_pass_check(p_num,x,y,z,px,py);
  1644. }
  1645. else
  1646. can_strike=first_time_strike(p_num,x,y,z,px,py);
  1647. /***** RUN ONTO BALL *****/
  1648. if (z<PLAYER_HEIGHT/3)
  1649. {
  1650. // Feet level...
  1651. ang=angle_to_xy(x-px,y-py,teams[p_num-1].tm_xdis,teams[p_num-1].tm_ydis);
  1652. if (ang>0 || user_controlled)
  1653. {
  1654. // Target is in front of player...
  1655. t=i-gt;
  1656. if (t>=0 && t<strike[0].free && (teams[p_num-1].control || t<ff))
  1657. {
  1658. strike[0].t=i;
  1659. strike[0].free=t;
  1660. strike[0].x=x;
  1661. strike[0].y=y;
  1662. strike[0].stop=stop_and_face;
  1663. do_it=TRUE;
  1664. }
  1665. }
  1666. }
  1667. // if (plr_facing(x-px,y-py,&teams[p_num-1]) && target_towards_ball(x,y,px,py)
  1668. // if ((target_towards_ball(x,y,px,py) || stop_and_face) &&
  1669. // if (
  1670. // teams[p_num-1].tm_act<=TURN_ACT)
  1671. if ((p_num!=KP_A && p_num!=KP_B)
  1672. || (p_num==KP_A && cannot_pick_up<12) || (p_num==KP_B && cannot_pick_up>11))
  1673. {
  1674. // Keeper cannot pick ball up...
  1675. // Player must be running or standing...
  1676. if (teams[p_num-1].tm_trap>=0)
  1677. {
  1678. // Must control ball or may hit it first time...
  1679. /***** TRAP AND CONTROL *****/
  1680. if (can_strike&128)
  1681. {
  1682. if (z<PLAYER_HEIGHT/2)
  1683. {
  1684. // Feet level...
  1685. rotate_offs(MC_TRAPL,cx,cy,cz,x_face,y_face);
  1686. rotate_offs(MC_TRAPR,cx2,cy2,cz,x_face,y_face);
  1687. cx=(cx+cx2)/2;
  1688. cy=(cy+cy2)/2;
  1689. gt=get_there_time(p_num,x-cx,y-cy);
  1690. t=i-(gt+ft_ttm);
  1691. if (t>=0 && t<strike[1].free && (teams[p_num-1].control || t<ff))
  1692. {
  1693. // He has time to animate...
  1694. // Best so far!
  1695. special_move=TRUE;
  1696. if (trap_option || !user_controlled)
  1697. {
  1698. strike[1].t=i;
  1699. strike[1].free=t;
  1700. strike[1].atime=ft_ttm;
  1701. strike[1].gt=gt;
  1702. strike[1].x=x-cx;
  1703. strike[1].y=y-cy;
  1704. strike[1].stop=stop_and_face;
  1705. do_it=TRUE;
  1706. }
  1707. }
  1708. }
  1709. else
  1710. {
  1711. if (z<(PLAYER_HEIGHT-2))
  1712. {
  1713. // Chest level...
  1714. rotate_offs(MC_CHEST,cx,cy,cz,x_face,y_face);
  1715. gt=get_there_time(p_num,x-cx,y-cy);
  1716. t=i-(gt+ft_ctm);
  1717. if (t>=0 && t<strike[2].free && (teams[p_num-1].control || t<ff))
  1718. {
  1719. // He has time to animate...
  1720. // Best so far!
  1721. special_move=TRUE;
  1722. if (trap_option || !user_controlled)
  1723. {
  1724. strike[2].t=i;
  1725. strike[2].free=t;
  1726. strike[2].atime=ft_ctm;
  1727. strike[2].gt=gt;
  1728. strike[2].x=x-cx;
  1729. strike[2].y=y-cy;
  1730. strike[2].stop=stop_and_face;
  1731. do_it=TRUE;
  1732. }
  1733. }
  1734. }
  1735. else
  1736. {
  1737. if (z<(PLAYER_HEIGHT+4))
  1738. {
  1739. // Head level...
  1740. rotate_offs(MC_D_HEAD,cx,cy,cz,x_face,y_face);
  1741. gt=get_there_time(p_num,x-cx,y-cy);
  1742. t=i-(gt+ft_utm);
  1743. if (t>=0 && t<strike[3].free && (teams[p_num-1].control || t<ff))
  1744. {
  1745. // He has time to animate...
  1746. // Best so far!
  1747. special_move=TRUE;
  1748. if (trap_option || !user_controlled)
  1749. {
  1750. strike[3].t=i;
  1751. strike[3].free=t;
  1752. strike[3].atime=ft_utm;
  1753. strike[3].gt=gt;
  1754. strike[3].x=x-cx;
  1755. strike[3].y=y-cy;
  1756. strike[3].stop=stop_and_face;
  1757. do_it=TRUE;
  1758. }
  1759. }
  1760. }
  1761. }
  1762. }
  1763. }
  1764. }
  1765. if (teams[p_num-1].tm_trap<=0)
  1766. {
  1767. // May hit it first time...
  1768. /***** FIRST TIME STRIKE *****/
  1769. if (z<PLAYER_HEIGHT/4)
  1770. {
  1771. if (can_strike&1)
  1772. {
  1773. // Feet level...
  1774. rotate_offs(MC_SHOOTL,cx,cy,cz,x_face,y_face);
  1775. rotate_offs(MC_SHOOTR,cx2,cy2,cz,x_face,y_face);
  1776. cx=(cx+cx2)/2;
  1777. cy=(cy+cy2)/2;
  1778. gt=get_there_time(p_num,x-cx,y-cy);
  1779. t=i-(gt+ft_ktm);
  1780. if (t>=0 && t<strike[8].free && (teams[p_num-1].control || t<ff))
  1781. {
  1782. // He has time to animate...
  1783. // Best so far!
  1784. special_move=TRUE;
  1785. if (strike_option || !user_controlled)
  1786. {
  1787. strike[8].t=i;
  1788. strike[8].free=t;
  1789. strike[8].atime=ft_ktm;
  1790. strike[8].gt=gt;
  1791. strike[8].x=x-cx;
  1792. strike[8].y=y-cy;
  1793. strike[8].stop=stop_and_face;
  1794. do_it=TRUE;
  1795. }
  1796. }
  1797. }
  1798. if (can_strike&64)
  1799. {
  1800. // Feet level...
  1801. rotate_offs(MC_CHIPL,cx,cy,cz,x_face,y_face);
  1802. rotate_offs(MC_CHIPR,cx2,cy2,cz,x_face,y_face);
  1803. cx=(cx+cx2)/2;
  1804. cy=(cy+cy2)/2;
  1805. gt=get_there_time(p_num,x-cx,y-cy);
  1806. t=i-(gt+ft_ctm);
  1807. if (t>=0 && t<strike[10].free && (teams[p_num-1].control || t<ff))
  1808. {
  1809. // He has time to animate...
  1810. // Best so far!
  1811. special_move=TRUE;
  1812. if (strike_option || !user_controlled)
  1813. {
  1814. strike[10].t=i;
  1815. strike[10].free=t;
  1816. strike[10].ptype=pass_type;
  1817. strike[10].pplr=receiver;
  1818. strike[10].atime=ft_ctm;
  1819. strike[10].gt=gt;
  1820. strike[10].x=x-cx;
  1821. strike[10].y=y-cy;
  1822. strike[10].stop=stop_and_face;
  1823. do_it=TRUE;
  1824. }
  1825. }
  1826. }
  1827. }
  1828. else
  1829. {
  1830. if (z<PLAYER_HEIGHT*.5)
  1831. {
  1832. // volley level...
  1833. if (can_strike&2)
  1834. {
  1835. rotate_offs(MC_VOLLEYL,cx,cy,cz,x_face,y_face);
  1836. gt=get_there_time(p_num,x-cx,y-cy);
  1837. t=i-(gt+ft_vtm);
  1838. if (t>=0 && t<strike[5].free && (teams[p_num-1].control || t<ff))
  1839. {
  1840. // He has time to animate...
  1841. // Best so far!
  1842. special_move=TRUE;
  1843. if (strike_option || !user_controlled)
  1844. {
  1845. strike[5].t=i;
  1846. strike[5].free=t;
  1847. strike[5].atime=ft_vtm;
  1848. strike[5].gt=gt;
  1849. strike[5].x=x-cx;
  1850. strike[5].y=y-cy;
  1851. strike[5].stop=stop_and_face;
  1852. do_it=TRUE;
  1853. }
  1854. }
  1855. }
  1856. }
  1857. else
  1858. {
  1859. if (z<PLAYER_HEIGHT*.67)
  1860. {
  1861. if (can_strike&4)
  1862. {
  1863. rotate_offs(MC_DV_HEAD,cx,cy,cz,x_face,y_face);
  1864. gt=get_there_time(p_num,x-cx,y-cy);
  1865. t=i-(gt+ft_dtm);
  1866. if (t>=0 && t<strike[6].free && (teams[p_num-1].control || t<ff))
  1867. {
  1868. // He has time to animate...
  1869. // Best so far!
  1870. special_move=TRUE;
  1871. if (strike_option || !user_controlled)
  1872. {
  1873. strike[6].t=i;
  1874. strike[6].free=t;
  1875. strike[6].atime=ft_dtm;
  1876. strike[6].gt=gt;
  1877. strike[6].x=x-cx;
  1878. strike[6].y=y-cy;
  1879. strike[6].stop=stop_and_face;
  1880. do_it=TRUE;
  1881. }
  1882. }
  1883. }
  1884. }
  1885. else
  1886. {
  1887. if (z<PLAYER_HEIGHT+2)
  1888. {
  1889. // head level...
  1890. if (can_strike&32)
  1891. {
  1892. rotate_offs(MC_OVERHEAD,cx,cy,cz,x_face,y_face);
  1893. gt=get_there_time(p_num,x-cx,y-cy);
  1894. t=i-(gt+ft_otm);
  1895. if (t>=0 && t<strike[4].free && (teams[p_num-1].control || t<ff))
  1896. {
  1897. // He has time to animate...
  1898. // Best so far!
  1899. special_move=TRUE;
  1900. if (strike_option || !user_controlled)
  1901. {
  1902. strike[4].t=i;
  1903. strike[4].free=t;
  1904. strike[4].atime=ft_otm;
  1905. strike[4].gt=gt;
  1906. strike[4].x=x-cx;
  1907. strike[4].y=y-cy;
  1908. strike[4].stop=stop_and_face;
  1909. do_it=TRUE;
  1910. }
  1911. }
  1912. }
  1913. if (can_strike&8)
  1914. {
  1915. // He has time...
  1916. rotate_offs(MC_S_HEAD,cx,cy,cz,x_face,y_face);
  1917. gt=get_there_time(p_num,x-cx,y-cy);
  1918. t=i-(gt+ft_stm);
  1919. if (t>=0 && t<strike[9].free && (teams[p_num-1].control || t<ff))
  1920. {
  1921. // He has time to animate...
  1922. // Best so far!
  1923. special_move=TRUE;
  1924. if (strike_option || !user_controlled)
  1925. {
  1926. strike[9].t=i;
  1927. strike[9].free=t;
  1928. strike[9].ptype=pass_type;
  1929. strike[9].pplr=receiver;
  1930. strike[9].atime=ft_stm;
  1931. strike[9].gt=gt;
  1932. strike[9].x=x-cx;
  1933. strike[9].y=y-cy;
  1934. strike[9].stop=stop_and_face;
  1935. do_it=TRUE;
  1936. }
  1937. }
  1938. }
  1939. }
  1940. else
  1941. {
  1942. if (z<teams[p_num-1].tm_jump)
  1943. {
  1944. // Jump level...
  1945. if (can_strike&16)
  1946. {
  1947. // He has time...
  1948. rotate_offs(MC_J_HEAD,cx,cy,cz,x_face,y_face);
  1949. gt=get_there_time(p_num,x-cx,y-cy);
  1950. t=i-(gt+ft_jtm);
  1951. if (ABS(cz+prat-z)<8 && t>=0 && t<strike[7].free && (teams[p_num-1].control || t<ff))
  1952. {
  1953. // He has time to animate...
  1954. // Best so far!
  1955. special_move=TRUE;
  1956. if (strike_option || !user_controlled)
  1957. {
  1958. strike[7].t=i;
  1959. strike[7].free=t;
  1960. strike[7].ptype=pass_type;
  1961. strike[7].pplr=receiver;
  1962. strike[7].atime=ft_jtm;
  1963. strike[7].gt=gt;
  1964. strike[7].x=x-cx;
  1965. strike[7].y=y-cy;
  1966. strike[7].stop=stop_and_face;
  1967. do_it=TRUE;
  1968. }
  1969. }
  1970. }
  1971. }
  1972. }
  1973. }
  1974. }
  1975. }
  1976. }
  1977. }
  1978. }
  1979. }
  1980. return(do_it);
  1981. }
  1982. #else
  1983. // No first-time passing...
  1984. char can_i_intercept(int p_num,float x,float y,float z,float px,float py,short i)
  1985. {
  1986. if (z>=teams[p_num-1].tm_jump)
  1987. return(FALSE);
  1988. float cx,cy,cz,cx2,cy2,ang;
  1989. float rate=full_spd(&teams[p_num-1]);
  1990. float d=calc_dist(x-px,y-py);
  1991. char can_strike;
  1992. char do_it=FALSE;
  1993. char stand;
  1994. short ff=1+teams[p_num-1].tm_flair/16; // Reaction times.
  1995. short gt=get_there_time(p_num,x,y);
  1996. short t;
  1997. if (gt<=i)
  1998. {
  1999. // He can get to ball in time...
  2000. if (ball_poss)
  2001. {
  2002. // Opponent has ball... (No control or strike!)
  2003. /***** RUN ONTO BALL *****/
  2004. t=i-gt;
  2005. if (t>0 && t<strike[0].free && (teams[p_num-1].control || t<ff))
  2006. {
  2007. strike[0].t=i;
  2008. strike[0].free=t;
  2009. strike[0].x=x;
  2010. strike[0].y=y;
  2011. strike[0].stop=stop_and_face;
  2012. do_it=TRUE;
  2013. }
  2014. }
  2015. else
  2016. {
  2017. if (user_controlled)
  2018. {
  2019. can_strike=128+32+16+8+4+2+1;
  2020. pass_type=0;
  2021. }
  2022. else
  2023. can_strike=first_time_strike(p_num,x,y,z,px,py);
  2024. /***** RUN ONTO BALL *****/
  2025. if (z<PLAYER_HEIGHT/3)
  2026. {
  2027. // Feet level...
  2028. ang=angle_to_xy(x-px,y-py,teams[p_num-1].tm_xdis,teams[p_num-1].tm_ydis);
  2029. if (ang>0 || user_controlled)
  2030. {
  2031. // Target is in front of player...
  2032. t=i-gt;
  2033. if (t>=0 && t<strike[0].free && (teams[p_num-1].control || t<ff))
  2034. {
  2035. strike[0].t=i;
  2036. strike[0].free=t;
  2037. strike[0].x=x;
  2038. strike[0].y=y;
  2039. strike[0].stop=stop_and_face;
  2040. do_it=TRUE;
  2041. }
  2042. }
  2043. }
  2044. // if (plr_facing(x-px,y-py,&teams[p_num-1]) && target_towards_ball(x,y,px,py)
  2045. // if ((target_towards_ball(x,y,px,py) || stop_and_face) &&
  2046. // if (
  2047. // teams[p_num-1].tm_act<=TURN_ACT)
  2048. if ((p_num!=KP_A && p_num!=KP_B)
  2049. || (p_num==KP_A && cannot_pick_up<12) || (p_num==KP_B && cannot_pick_up>11))
  2050. {
  2051. // Keeper cannot pick ball up...
  2052. // Player must be running or standing...
  2053. if (teams[p_num-1].tm_trap>=0)
  2054. {
  2055. // Must control ball or may hit it first time...
  2056. /***** TRAP AND CONTROL *****/
  2057. if (can_strike&128)
  2058. {
  2059. if (z<PLAYER_HEIGHT/2)
  2060. {
  2061. // Feet level...
  2062. rotate_offs(MC_TRAPL,cx,cy,cz,x_face,y_face);
  2063. rotate_offs(MC_TRAPR,cx2,cy2,cz,x_face,y_face);
  2064. cx=(cx+cx2)/2;
  2065. cy=(cy+cy2)/2;
  2066. gt=get_there_time(p_num,x-cx,y-cy);
  2067. t=i-(gt+ft_ttm);
  2068. if (t>=0 && t<strike[1].free && (teams[p_num-1].control || t<ff))
  2069. {
  2070. // He has time to animate...
  2071. // Best so far!
  2072. special_move=TRUE;
  2073. if ((user_controlled && uf2) || !user_controlled)
  2074. {
  2075. strike[1].t=i;
  2076. strike[1].free=t;
  2077. strike[1].atime=ft_ttm;
  2078. strike[1].gt=gt;
  2079. strike[1].x=x-cx;
  2080. strike[1].y=y-cy;
  2081. strike[1].stop=stop_and_face;
  2082. do_it=TRUE;
  2083. }
  2084. }
  2085. }
  2086. else
  2087. {
  2088. if (z<(PLAYER_HEIGHT-2))
  2089. {
  2090. // Chest level...
  2091. rotate_offs(MC_CHEST,cx,cy,cz,x_face,y_face);
  2092. gt=get_there_time(p_num,x-cx,y-cy);
  2093. t=i-(gt+ft_ctm);
  2094. if (t>=0 && t<strike[2].free && (teams[p_num-1].control || t<ff))
  2095. {
  2096. // He has time to animate...
  2097. // Best so far!
  2098. special_move=TRUE;
  2099. if ((user_controlled && uf2) || !user_controlled)
  2100. {
  2101. strike[2].t=i;
  2102. strike[2].free=t;
  2103. strike[2].atime=ft_ctm;
  2104. strike[2].gt=gt;
  2105. strike[2].x=x-cx;
  2106. strike[2].y=y-cy;
  2107. strike[2].stop=stop_and_face;
  2108. do_it=TRUE;
  2109. }
  2110. }
  2111. }
  2112. else
  2113. {
  2114. if (z<(PLAYER_HEIGHT+4))
  2115. {
  2116. // Head level...
  2117. rotate_offs(MC_D_HEAD,cx,cy,cz,x_face,y_face);
  2118. gt=get_there_time(p_num,x-cx,y-cy);
  2119. t=i-(gt+ft_utm);
  2120. if (t>=0 && t<strike[3].free && (teams[p_num-1].control || t<ff))
  2121. {
  2122. // He has time to animate...
  2123. // Best so far!
  2124. special_move=TRUE;
  2125. if ((user_controlled && uf2) || !user_controlled)
  2126. {
  2127. strike[3].t=i;
  2128. strike[3].free=t;
  2129. strike[3].atime=ft_utm;
  2130. strike[3].gt=gt;
  2131. strike[3].x=x-cx;
  2132. strike[3].y=y-cy;
  2133. strike[3].stop=stop_and_face;
  2134. do_it=TRUE;
  2135. }
  2136. }
  2137. }
  2138. }
  2139. }
  2140. }
  2141. }
  2142. if (teams[p_num-1].tm_trap<=0)
  2143. {
  2144. // May hit it first time...
  2145. /***** FIRST TIME STRIKE *****/
  2146. if (z<PLAYER_HEIGHT/4)
  2147. {
  2148. if (can_strike&1)
  2149. {
  2150. // Feet level...
  2151. rotate_offs(MC_SHOOTL,cx,cy,cz,x_face,y_face);
  2152. rotate_offs(MC_SHOOTR,cx2,cy2,cz,x_face,y_face);
  2153. cx=(cx+cx2)/2;
  2154. cy=(cy+cy2)/2;
  2155. gt=get_there_time(p_num,x-cx,y-cy);
  2156. t=i-(gt+ft_ktm);
  2157. if (t>=0 && t<strike[8].free && (teams[p_num-1].control || t<ff))
  2158. {
  2159. // He has time to animate...
  2160. // Best so far!
  2161. special_move=TRUE;
  2162. if ((user_controlled && uf1) || !user_controlled)
  2163. {
  2164. strike[8].t=i;
  2165. strike[8].free=t;
  2166. strike[8].atime=ft_ktm;
  2167. strike[8].gt=gt;
  2168. strike[8].x=x-cx;
  2169. strike[8].y=y-cy;
  2170. strike[8].stop=stop_and_face;
  2171. do_it=TRUE;
  2172. }
  2173. }
  2174. }
  2175. if (can_strike&64)
  2176. {
  2177. // Feet level...
  2178. rotate_offs(MC_CHIPL,cx,cy,cz,x_face,y_face);
  2179. rotate_offs(MC_CHIPR,cx2,cy2,cz,x_face,y_face);
  2180. cx=(cx+cx2)/2;
  2181. cy=(cy+cy2)/2;
  2182. gt=get_there_time(p_num,x-cx,y-cy);
  2183. t=i-(gt+ft_ctm);
  2184. if (t>=0 && t<strike[10].free && (teams[p_num-1].control || t<ff))
  2185. {
  2186. // He has time to animate...
  2187. // Best so far!
  2188. special_move=TRUE;
  2189. if ((user_controlled && uf1) || !user_controlled)
  2190. {
  2191. strike[10].t=i;
  2192. strike[10].free=t;
  2193. strike[10].ptype=pass_type;
  2194. strike[10].pplr=receiver;
  2195. strike[10].atime=ft_ctm;
  2196. strike[10].gt=gt;
  2197. strike[10].x=x-cx;
  2198. strike[10].y=y-cy;
  2199. strike[10].stop=stop_and_face;
  2200. do_it=TRUE;
  2201. }
  2202. }
  2203. }
  2204. }
  2205. else
  2206. {
  2207. if (z<PLAYER_HEIGHT*.5)
  2208. {
  2209. // volley level...
  2210. if (can_strike&2)
  2211. {
  2212. rotate_offs(MC_VOLLEYL,cx,cy,cz,x_face,y_face);
  2213. gt=get_there_time(p_num,x-cx,y-cy);
  2214. t=i-(gt+ft_vtm);
  2215. if (t>=0 && t<strike[5].free && (teams[p_num-1].control || t<ff))
  2216. {
  2217. // He has time to animate...
  2218. // Best so far!
  2219. special_move=TRUE;
  2220. if ((user_controlled && uf1) || !user_controlled)
  2221. {
  2222. strike[5].t=i;
  2223. strike[5].free=t;
  2224. strike[5].atime=ft_vtm;
  2225. strike[5].gt=gt;
  2226. strike[5].x=x-cx;
  2227. strike[5].y=y-cy;
  2228. strike[5].stop=stop_and_face;
  2229. do_it=TRUE;
  2230. }
  2231. }
  2232. }
  2233. }
  2234. else
  2235. {
  2236. if (z<PLAYER_HEIGHT*.67)
  2237. {
  2238. if (can_strike&4)
  2239. {
  2240. rotate_offs(MC_DV_HEAD,cx,cy,cz,x_face,y_face);
  2241. gt=get_there_time(p_num,x-cx,y-cy);
  2242. t=i-(gt+ft_dtm);
  2243. if (t>=0 && t<strike[6].free && (teams[p_num-1].control || t<ff))
  2244. {
  2245. // He has time to animate...
  2246. // Best so far!
  2247. special_move=TRUE;
  2248. if ((user_controlled && uf1) || !user_controlled)
  2249. {
  2250. strike[6].t=i;
  2251. strike[6].free=t;
  2252. strike[6].atime=ft_dtm;
  2253. strike[6].gt=gt;
  2254. strike[6].x=x-cx;
  2255. strike[6].y=y-cy;
  2256. strike[6].stop=stop_and_face;
  2257. do_it=TRUE;
  2258. }
  2259. }
  2260. }
  2261. }
  2262. else
  2263. {
  2264. if (z<PLAYER_HEIGHT+2)
  2265. {
  2266. // head level...
  2267. if (can_strike&32)
  2268. {
  2269. rotate_offs(MC_OVERHEAD,cx,cy,cz,x_face,y_face);
  2270. gt=get_there_time(p_num,x-cx,y-cy);
  2271. t=i-(gt+ft_otm);
  2272. if (t>=0 && t<strike[4].free && (teams[p_num-1].control || t<ff))
  2273. {
  2274. // He has time to animate...
  2275. // Best so far!
  2276. special_move=TRUE;
  2277. if ((user_controlled && uf1) || !user_controlled)
  2278. {
  2279. strike[4].t=i;
  2280. strike[4].free=t;
  2281. strike[4].atime=ft_otm;
  2282. strike[4].gt=gt;
  2283. strike[4].x=x-cx;
  2284. strike[4].y=y-cy;
  2285. strike[4].stop=stop_and_face;
  2286. do_it=TRUE;
  2287. }
  2288. }
  2289. }
  2290. if (can_strike&8)
  2291. {
  2292. // He has time...
  2293. rotate_offs(MC_S_HEAD,cx,cy,cz,x_face,y_face);
  2294. gt=get_there_time(p_num,x-cx,y-cy);
  2295. t=i-(gt+ft_stm);
  2296. if (t>=0 && t<strike[9].free && (teams[p_num-1].control || t<ff))
  2297. {
  2298. // He has time to animate...
  2299. // Best so far!
  2300. special_move=TRUE;
  2301. if ((user_controlled && uf1) || !user_controlled)
  2302. {
  2303. strike[9].t=i;
  2304. strike[9].free=t;
  2305. strike[9].ptype=pass_type;
  2306. strike[9].pplr=receiver;
  2307. strike[9].atime=ft_stm;
  2308. strike[9].gt=gt;
  2309. strike[9].x=x-cx;
  2310. strike[9].y=y-cy;
  2311. strike[9].stop=stop_and_face;
  2312. do_it=TRUE;
  2313. }
  2314. }
  2315. }
  2316. }
  2317. else
  2318. {
  2319. if (z<teams[p_num-1].tm_jump)
  2320. {
  2321. // Jump level...
  2322. if (can_strike&16)
  2323. {
  2324. // He has time...
  2325. rotate_offs(MC_J_HEAD,cx,cy,cz,x_face,y_face);
  2326. gt=get_there_time(p_num,x-cx,y-cy);
  2327. t=i-(gt+ft_jtm);
  2328. if (ABS(cz+prat-z)<8 && t>=0 && t<strike[7].free && (teams[p_num-1].control || t<ff))
  2329. {
  2330. // He has time to animate...
  2331. // Best so far!
  2332. special_move=TRUE;
  2333. if ((user_controlled && uf1) || !user_controlled)
  2334. {
  2335. strike[7].t=i;
  2336. strike[7].free=t;
  2337. strike[7].ptype=pass_type;
  2338. strike[7].pplr=receiver;
  2339. strike[7].atime=ft_jtm;
  2340. strike[7].gt=gt;
  2341. strike[7].x=x-cx;
  2342. strike[7].y=y-cy;
  2343. strike[7].stop=stop_and_face;
  2344. do_it=TRUE;
  2345. }
  2346. }
  2347. }
  2348. }
  2349. }
  2350. }
  2351. }
  2352. }
  2353. }
  2354. }
  2355. }
  2356. }
  2357. return(do_it);
  2358. }
  2359. #endif
  2360. /*******************************************************************************
  2361. *****************************************************************************/
  2362. void clear_strike()
  2363. {
  2364. // Clear first time animation array...
  2365. for (short i=0; i<11; i++)
  2366. {
  2367. strike[i].t=0; // Init start time.
  2368. strike[i].free=1000; // Init wait time.
  2369. strike[i].ptype=0;
  2370. strike[i].pplr=0;
  2371. }
  2372. }
  2373. /*******************************************************************************
  2374. *****************************************************************************/
  2375. void decide_on_face(match_player *p)
  2376. {
  2377. float gx,gy,x,y,d;
  2378. if (p->tm_player<12)
  2379. // Team A...
  2380. gx=0; // His goal...
  2381. else
  2382. gx=pitch_len; // His goal...
  2383. gy=cntspot_y;
  2384. gx=gx-p->tm_x;
  2385. gy=gy-p->tm_y;
  2386. d=calc_dist(gx,gy);
  2387. if (d<prat*30)
  2388. {
  2389. // In Defense...
  2390. if (p->tm_player<12)
  2391. must_face_x=1;
  2392. else
  2393. must_face_x=-1;
  2394. must_face=TRUE;
  2395. }
  2396. else
  2397. {
  2398. // Not in defense...
  2399. if (p->tm_player<12)
  2400. gx=pitch_len;
  2401. else
  2402. gx=0;
  2403. gx=gx-p->tm_x;
  2404. d=calc_dist(gx,gy);
  2405. if (d<(MIN_SHOOT_DIST+((float)p->tm_pow*3)))
  2406. {
  2407. // In Shooting Range...
  2408. must_face_x=gx/d;
  2409. must_face_y=gy/d;
  2410. must_face=TRUE;
  2411. }
  2412. }
  2413. }
  2414. /*******************************************************************************
  2415. *****************************************************************************/
  2416. char go_to_path(int p_num)
  2417. // Send player(p_num) to intersection with ball path.
  2418. // If he cannot meet ball then best try!
  2419. {
  2420. float spd_up;
  2421. special_move=FALSE;
  2422. teams[p_num-1].tm_fpass_type=0;
  2423. teams[p_num-1].tm_fpass_to=0;
  2424. float x,y,z;
  2425. float px=teams[p_num-1].tm_x;
  2426. float py=teams[p_num-1].tm_y;
  2427. short i;
  2428. char do_it=FALSE;
  2429. first_time_it=TRUE;
  2430. clear_strike();
  2431. /*** Capture Timings ***/
  2432. /* Release Ball */
  2433. if (user_controlled)
  2434. // Allow user to animate faster for responsiveness...
  2435. spd_up=1.3;
  2436. else
  2437. spd_up=1;
  2438. // Kick time...
  2439. ft_ktm=MCC_SHOOT/(MC_SHOOT_FS*spd_up*fstep_factor(teams[p_num-1].tm_flair));
  2440. // Volley time...
  2441. ft_vtm=MCC_VOLLEY/(MC_VOLLEY_FS*spd_up*fstep_factor(teams[p_num-1].tm_flair));
  2442. // Diving time...
  2443. ft_dtm=MCC_DV_HEAD/(MC_DV_HEAD_FS*spd_up*fstep_factor(teams[p_num-1].tm_flair));
  2444. // Overhead time...
  2445. ft_otm=MCC_OVERHEAD/(MC_OVERHEAD_FS*spd_up*fstep_factor(teams[p_num-1].tm_flair));
  2446. // Standing time...
  2447. ft_stm=MCC_S_HEAD/(MC_S_HEAD_FS*spd_up*fstep_factor(teams[p_num-1].tm_flair));
  2448. // Jumping time...
  2449. ft_jtm=MCC_J_HEAD/(MC_J_HEAD_FS*spd_up*fstep_factor(teams[p_num-1].tm_flair));
  2450. // ft_jtm=MCC_J_HEAD/MC_J_HEAD_FS;
  2451. /* Keep Ball */
  2452. // Trapping time...
  2453. ft_ttm=MCC_TRAP/(MC_TRAP_FS*spd_up*fstep_factor(teams[p_num-1].tm_cont));
  2454. // Chesting time...
  2455. ft_ctm=MCC_CHEST/(MC_CHEST_FS*spd_up*fstep_factor(teams[p_num-1].tm_cont));
  2456. // Up head time...
  2457. ft_utm=MCC_D_HEAD/(MC_D_HEAD_FS*spd_up*fstep_factor(teams[p_num-1].tm_cont));
  2458. must_face=FALSE;
  2459. auto_select=FALSE;
  2460. if (user_controlled)
  2461. {
  2462. if (um && (uf1 || uf2))
  2463. // User.. Directional control...
  2464. {
  2465. must_face=TRUE; // Forced to face in a particular dir...
  2466. must_face_x=ux;
  2467. must_face_y=uy;
  2468. }
  2469. else
  2470. if (uf1 || uf2)
  2471. {
  2472. // User.. No directional control...
  2473. decide_on_face(&teams[p_num-1]);
  2474. }
  2475. }
  2476. else
  2477. {
  2478. if ((p_num<12 && !auto_users_a) || p_num==KP_A
  2479. || (p_num>11 && !auto_users_b) || p_num==KP_B)
  2480. {
  2481. // Computer player will try to face goal or away from defense...
  2482. auto_select=TRUE;
  2483. if (p_num==receiver_a || p_num==receiver_b)
  2484. {
  2485. decide_on_face(&teams[p_num-1]);
  2486. }
  2487. }
  2488. else
  2489. {
  2490. // Should be a user...
  2491. auto_select=FALSE; // Don't allow computer to select a move!
  2492. }
  2493. }
  2494. for (i=1; i<50; i+=2)
  2495. {
  2496. x=ball_pred_tab[i][0];
  2497. y=ball_pred_tab[i][1];
  2498. z=ball_pred_tab[i][2];
  2499. ball_int_speed=ABS(x-ball_pred_tab[i-1][0])
  2500. +ABS(y-ball_pred_tab[i-1][1])
  2501. +(ABS(z-ball_pred_tab[i-1][2])*2);
  2502. if ((x<0) || (x>=pitch_len) || (y<0) || (y>=pitch_wid))
  2503. // Ball out of bounds
  2504. {
  2505. x=ball_pred_tab[i-1][0];
  2506. y=ball_pred_tab[i-1][1];
  2507. i=60;
  2508. }
  2509. else
  2510. {
  2511. do_it+=can_i_intercept(p_num,x,y,z,px,py,i);
  2512. }
  2513. }
  2514. if (do_it)
  2515. {
  2516. /*
  2517. if ((p_num<12 && auto_users_a && !teams[p_num-1].control)
  2518. || (p_num>11 && auto_users_b && !teams[p_num-1].control))
  2519. {
  2520. reselect();
  2521. user_conts(&teams[p_num-1]);
  2522. user_controlled=teams[p_num-1].control;
  2523. }
  2524. */
  2525. intercept(p_num);
  2526. if (ball_poss)
  2527. teams[p_num-1].ball_state=-ball_poss;
  2528. else
  2529. teams[p_num-1].ball_state=last_touch;
  2530. }
  2531. must_face=FALSE;
  2532. first_time_it=FALSE;
  2533. return(do_it);
  2534. }
  2535. /******************************************************************************
  2536. *****************************************************************************/
  2537. void ogo_to_path(int p_num,char header_only)
  2538. // Send player(p_num) to intersection with ball path.
  2539. // If he cannot meet ball then best try!
  2540. {
  2541. float x,y,z,d;
  2542. float px=teams[p_num-1].tm_x;
  2543. float py=teams[p_num-1].tm_y;
  2544. float rate=actual_spd(&teams[p_num-1]);
  2545. action="Intercept";
  2546. reset_ideas(&teams[p_num-1]);
  2547. if (p_num<12)
  2548. interceptor_a=p_num;
  2549. else
  2550. interceptor_b=p_num;
  2551. // His intention is to intercept ball.
  2552. // Therefore his flair determines no. of turns before rethink!
  2553. int ff=33-(teams[p_num-1].tm_flair/4);
  2554. teams[p_num-1].int_move=I_INTERCEPT; // Intercept ball!
  2555. teams[p_num-1].int_cnt=ff; // Flair factor.
  2556. char feet_hit=FALSE;
  2557. char body_hit=FALSE;
  2558. char head_hit=FALSE;
  2559. float feet_x,feet_y,body_x,body_y,head_x,head_y;
  2560. for (int i=1; i<50; i++)
  2561. {
  2562. x=ball_pred_tab[i][0];
  2563. y=ball_pred_tab[i][1];
  2564. z=ball_pred_tab[i][2];
  2565. if ((x<0) || (x>=pitch_len) || (y<0) || (y>=pitch_wid))
  2566. // Ball out of bounds
  2567. {
  2568. x=ball_pred_tab[i-1][0];
  2569. y=ball_pred_tab[i-1][1];
  2570. i=60;
  2571. }
  2572. else
  2573. {
  2574. if (z<PLAYER_HEIGHT/2)
  2575. {
  2576. d=calc_dist(x-px,y-py);
  2577. d=(int)(((float)d)/rate); //How many steps?
  2578. if (d<=i)
  2579. // He can get there in time!
  2580. // At feet...
  2581. {
  2582. feet_x=x;
  2583. feet_y=y;
  2584. feet_hit=TRUE;
  2585. i=60;
  2586. }
  2587. }
  2588. else
  2589. {
  2590. if ((z<=PLAYER_HEIGHT-4) && (!body_hit))
  2591. {
  2592. d=calc_dist(x-px,y-py);
  2593. d=(int)(((float)d)/rate); //How many steps?
  2594. if (d<=i)
  2595. // He can get there in time!
  2596. // On body...
  2597. {
  2598. body_x=x;
  2599. body_y=y;
  2600. body_hit=TRUE;
  2601. }
  2602. // init_run_act(&teams[p_num-1],x,y,TRUE); //Go to path point!
  2603. // i=60; // End For Loop!
  2604. }
  2605. else
  2606. {
  2607. if ((z>PLAYER_HEIGHT-4) && (z<=teams[p_num-1].tm_jump) && (!head_hit))
  2608. {
  2609. d=calc_dist(x-px,y-py);
  2610. d=(int)(((float)d)/rate); //How many steps?
  2611. if (d+(sqrt(z-PLAYER_HEIGHT+5)/gravity)<=i)
  2612. // He can get there in time!
  2613. // On head...
  2614. {
  2615. head_x=x;
  2616. head_y=y;
  2617. head_hit=TRUE;
  2618. }
  2619. // init_run_act(&teams[p_num-1],x,y,TRUE); //Go to path point!
  2620. // i=60;
  2621. }
  2622. }
  2623. }
  2624. }
  2625. }
  2626. if ((!feet_hit) && (!head_hit) && (!body_hit))
  2627. // He cant intersect!
  2628. {
  2629. init_run_act(&teams[p_num-1],x,y,TRUE); // run toward last.
  2630. }
  2631. else
  2632. {
  2633. if (header_only)
  2634. {
  2635. if (head_hit)
  2636. {
  2637. init_run_act(&teams[p_num-1],head_x,head_y,TRUE); //Go to path point!
  2638. }
  2639. }
  2640. else
  2641. {
  2642. if (feet_hit)
  2643. {
  2644. init_run_act(&teams[p_num-1],feet_x,feet_y,TRUE); //pitch line point
  2645. }
  2646. else
  2647. if (head_hit)
  2648. {
  2649. init_run_act(&teams[p_num-1],head_x,head_y,TRUE); //Go to path point!
  2650. }
  2651. else
  2652. if (body_hit)
  2653. {
  2654. init_run_act(&teams[p_num-1],body_x,body_y,TRUE); //Go to path point!
  2655. }
  2656. }
  2657. }
  2658. }
  2659. /******************************************************************************
  2660. *****************************************************************************/
  2661. void get_tack_path(match_player *player)
  2662. // Find players intersection with ball path.
  2663. // When tackling!
  2664. {
  2665. if (teams[ball_poss-1].tm_poss>4)
  2666. {
  2667. // Opponent has ball for a bit...
  2668. flag=FALSE;
  2669. float x,y,z;
  2670. float d,s;
  2671. float px=player->tm_x;
  2672. float py=player->tm_y;
  2673. float rate=player->tm_rate+player->tm_pow;
  2674. float last_diff=2000;
  2675. if (((ball_poss) && (teams[ball_poss-1].tm_act==STAND_ACT))
  2676. || ((!ball_poss) && (ball_still)))
  2677. // Ball is not moving!
  2678. if (plr_facing(ballx,bally,player))
  2679. init_tackle_act(player,ballx,bally); //Go to path point!
  2680. else
  2681. go_to_path(player->tm_player);
  2682. else
  2683. {
  2684. for (int i=1; i<TACKLE_TURNS/2; i++)
  2685. {
  2686. x=ball_pred_tab[i][0];
  2687. y=ball_pred_tab[i][1];
  2688. z=ball_pred_tab[i][2];
  2689. if ((x<0) || (x>=pitch_len) || (y<0) || (y>=pitch_wid))
  2690. // Ball out of bounds (So don't tackle!)
  2691. i=60;
  2692. if (z<=PLAYER_HEIGHT/2)
  2693. // Tackling player is half height.
  2694. {
  2695. d=calc_dist(x-px,y-py);
  2696. // Now the tricky bit...
  2697. // Using S=a(1-r^n)/(1-r) (S=tackle distance over time (n))
  2698. // a=(rate/8), r=tackle_decel...
  2699. s=(rate/20)*(1-pow(TACKLE_DECEL,i))/(1-TACKLE_DECEL); //How far in time (i)!
  2700. if (d-s>last_diff)
  2701. // Ball getting further away!
  2702. i=60; // End For Loop!
  2703. else
  2704. last_diff=d-s;
  2705. if (last_diff<=0)
  2706. // He can get there in time!
  2707. {
  2708. // Take accuracy into account...
  2709. float acc_xoff=(seed*(128-player->tm_ac)/4)/128;
  2710. af_randomize();
  2711. float acc_yoff=(seed*(128-player->tm_ac)/4)/128;
  2712. if (seed&32)
  2713. acc_xoff=-acc_xoff;
  2714. if (seed&16)
  2715. acc_yoff=-acc_yoff;
  2716. if (player->tm_player!=KP_A && player->tm_player!=KP_B)
  2717. // init_tackle_act(player,x+acc_xoff,y+acc_yoff); //Go to path point!
  2718. init_tackle_act(player,x,y);
  2719. else
  2720. // Keeper more accurate to provide better defense...
  2721. init_tackle_act(player,x,y);
  2722. flag=TRUE;
  2723. i=60; // End For Loop!
  2724. }
  2725. }
  2726. }
  2727. }
  2728. }
  2729. }
  2730. /******************************************************************************
  2731. *****************************************************************************/
  2732. void set_there_flags(short taker)
  2733. {
  2734. #ifdef EURO96
  2735. if ((teams[taker-1].tm_act==STAND_ACT && plr_facing(ballx-teams[taker-1].tm_x,bally-teams[taker-1].tm_y,&teams[taker-1]))
  2736. && (teams[taker-1].tm_dist<BESIDE_BALL*3
  2737. || ((match_mode==PEN_KICK_A || match_mode==PEN_KICK_B) && teams[taker-1].tm_dist<(PEN_RUNUP_DIST+4))))
  2738. #else
  2739. if ((teams[taker-1].tm_act==STAND_ACT && plr_facing(ballx-teams[taker-1].tm_x,bally-teams[taker-1].tm_y,&teams[taker-1]))
  2740. && (teams[taker-1].tm_dist<BESIDE_BALL*3))
  2741. #endif
  2742. {
  2743. if (!already_there)
  2744. {
  2745. reselection=TRUE;
  2746. already_there=TRUE;
  2747. }
  2748. }
  2749. }
  2750. /******************************************************************************
  2751. *****************************************************************************/
  2752. void centre_pos(char flag,int pn,char &flag2,float &x,float &y)
  2753. {
  2754. // Taking centre!
  2755. {
  2756. if (((pn+1==centre_guy_1) && (flag==1))
  2757. || ((pn+1==centre_guy_1-11) && (flag==2)))
  2758. {
  2759. x=cntspot_x;
  2760. y=cntspot_y-10;
  2761. flag2=TRUE;
  2762. set_there_flags(centre_guy_1);
  2763. }
  2764. if (((pn+1==centre_guy_2) && (flag==1))
  2765. || ((pn+1==centre_guy_2-11) && (flag==2)))
  2766. {
  2767. if (flag==1)
  2768. x=cntspot_x+5;
  2769. else
  2770. x=cntspot_x-5; // Receiver stands over line...
  2771. y=cntspot_y+10;
  2772. flag2=TRUE;
  2773. }
  2774. }
  2775. }
  2776. /******************************************************************************
  2777. *****************************************************************************/
  2778. void gkick_pos(char flag,int pn,char &flag2,float &x,float &y,char &taker)
  2779. {
  2780. // Taking Goal kick!
  2781. {
  2782. if (((pn+1==gkick_taker) && (flag==1))
  2783. || ((pn+1==gkick_taker-11) && (flag==2)))
  2784. {
  2785. x=taker_x;
  2786. y=taker_y;
  2787. taker=TRUE;
  2788. flag2=TRUE;
  2789. if (flag==2)
  2790. {
  2791. x=pitch_len-x;
  2792. y=pitch_wid-y;
  2793. }
  2794. set_there_flags(gkick_taker);
  2795. }
  2796. }
  2797. }
  2798. /******************************************************************************
  2799. *****************************************************************************/
  2800. void corner_pos(char flag,int pn,char &flag2,float &x,float &y,char &taker)
  2801. {
  2802. // Taking Corner!
  2803. {
  2804. if (((pn+1==corner_taker) && (flag==1))
  2805. || ((pn+1==corner_taker-11) && (flag==2)))
  2806. {
  2807. x=incident_x;
  2808. y=incident_y;
  2809. taker=TRUE;
  2810. flag2=TRUE;
  2811. if (flag==2)
  2812. {
  2813. x=pitch_len-x;
  2814. y=pitch_wid-y;
  2815. }
  2816. set_there_flags(corner_taker);
  2817. }
  2818. }
  2819. }
  2820. /******************************************************************************
  2821. *****************************************************************************/
  2822. void throw_in_pos(char flag,int pn,char &flag2,float &x,float &y,char &taker)
  2823. {
  2824. // Taking throw!
  2825. {
  2826. if (flag==2)
  2827. pn=pn+11;
  2828. if (pn+1==throw_in_taker)
  2829. {
  2830. x=incident_x;
  2831. y=incident_y+((incident_y<cntspot_y) ? -8:8);
  2832. taker=TRUE;
  2833. flag2=TRUE;
  2834. if (flag==2)
  2835. {
  2836. x=pitch_len-x;
  2837. y=pitch_wid-y;
  2838. }
  2839. set_there_flags(throw_in_taker);
  2840. }
  2841. }
  2842. }
  2843. /******************************************************************************
  2844. *****************************************************************************/
  2845. void dfkick_pos(char flag,int pn,char &flag2,float &x,float &y,char &taker)
  2846. {
  2847. // Taking F.K.!
  2848. {
  2849. if (flag==2)
  2850. pn=pn+11;
  2851. if (pn+1==fkick_taker)
  2852. {
  2853. x=taker_x;
  2854. y=taker_y;
  2855. taker=TRUE;
  2856. flag2=TRUE;
  2857. if (flag==2)
  2858. {
  2859. x=pitch_len-x;
  2860. y=pitch_wid-y;
  2861. }
  2862. set_there_flags(fkick_taker);
  2863. }
  2864. else
  2865. {
  2866. if (teams[pn].tm_wall)
  2867. {
  2868. for (int i=0; i<men_in_wall; i++)
  2869. {
  2870. if (wguys[i].guy==pn+1)
  2871. {
  2872. x=wguys[i].x;
  2873. y=wguys[i].y;
  2874. flag2=TRUE;
  2875. i=men_in_wall;
  2876. if (flag==2)
  2877. {
  2878. x=pitch_len-x;
  2879. y=pitch_wid-y;
  2880. }
  2881. }
  2882. }
  2883. }
  2884. }
  2885. }
  2886. }
  2887. /******************************************************************************
  2888. *****************************************************************************/
  2889. void fkick_pos(char flag,int pn,char &flag2,float &x,float &y,char &taker)
  2890. {
  2891. // Taking F.K.!
  2892. {
  2893. if (flag==2)
  2894. pn=pn+11;
  2895. if (pn+1==fkick_taker)
  2896. {
  2897. x=taker_x;
  2898. y=taker_y;
  2899. taker=TRUE;
  2900. flag2=TRUE;
  2901. if (flag==2)
  2902. {
  2903. x=pitch_len-x;
  2904. y=pitch_wid-y;
  2905. }
  2906. set_there_flags(fkick_taker);
  2907. }
  2908. }
  2909. }
  2910. /******************************************************************************
  2911. *****************************************************************************/
  2912. void penalty_pos(char flag,int pn,char &flag2,float &x,float &y,char &taker)
  2913. {
  2914. // Taking F.K.!
  2915. {
  2916. if (flag==2)
  2917. pn=pn+11;
  2918. if (pn+1==penalty_taker)
  2919. {
  2920. x=taker_x;
  2921. y=taker_y;
  2922. taker=TRUE;
  2923. flag2=TRUE;
  2924. if (flag==2)
  2925. {
  2926. x=pitch_len-x;
  2927. y=pitch_wid-y;
  2928. }
  2929. set_there_flags(penalty_taker);
  2930. }
  2931. }
  2932. }
  2933. /******************************************************************************
  2934. *****************************************************************************/
  2935. void tunnel_pos(char flag,int pn,float &x,float &y)
  2936. {
  2937. float tx=stadlist[setup.stadium].tunlx;
  2938. float ty=-stadlist[setup.stadium].tunlz;
  2939. float tz=stadlist[setup.stadium].tunly;
  2940. float d=GO_TO_POS_DIST;
  2941. if (flag==2)
  2942. {
  2943. // Team B...
  2944. pn+=11;
  2945. if (ABS(teams[pn].go_ty-ty)<prat ||
  2946. (teams[pn].tm_x>=(tx+prat-d) && teams[pn].tm_x<=(tx+prat+d)))
  2947. {
  2948. // In line with tunnel...
  2949. x=pitch_len-(tx+prat);
  2950. y=pitch_wid-(ty);
  2951. if (ABS(teams[pn].tm_y-(pitch_wid-y))<prat*2)
  2952. {
  2953. // At end of tunnel...(don't draw him!)
  2954. teams[pn].draw_me=FALSE;
  2955. }
  2956. }
  2957. else
  2958. {
  2959. x=pitch_len-(tx+prat);
  2960. if (ty>cntspot_y)
  2961. // Which goal-line...
  2962. y=0;
  2963. else
  2964. y=pitch_wid;
  2965. }
  2966. }
  2967. else
  2968. {
  2969. // Team A...
  2970. if (ABS(teams[pn].go_ty-ty)<prat ||
  2971. (teams[pn].tm_x>=(tx-prat-d) && teams[pn].tm_x<=(tx-prat+d)))
  2972. {
  2973. // In line with tunnel...
  2974. x=tx-prat;
  2975. y=ty;
  2976. if (ABS(teams[pn].tm_y-y)<prat*2)
  2977. {
  2978. // At end of tunnel...(don't draw him!)
  2979. teams[pn].draw_me=FALSE;
  2980. }
  2981. }
  2982. else
  2983. {
  2984. x=tx-prat;
  2985. if (ty>cntspot_y)
  2986. // Which goal-line...
  2987. y=pitch_wid;
  2988. else
  2989. y=0;
  2990. }
  2991. }
  2992. set_there_flags(pn+1);
  2993. }
  2994. /******************************************************************************
  2995. *****************************************************************************/
  2996. int get_tac(int *t)
  2997. {
  2998. // (*t)++;
  2999. // (*t)--;
  3000. return(*t);
  3001. }
  3002. /******************************************************************************
  3003. *****************************************************************************/
  3004. void get_target(char flag,int bz,int zx,int zy,int pn,float &x,float &y,int tac[(32*2)+6][10][2])
  3005. {
  3006. float ox,oy;
  3007. char flag2=FALSE;
  3008. char taker=FALSE;
  3009. if (dead_ball_cnt)
  3010. {
  3011. if (match_mode==SWAP_ENDS)
  3012. // Into tunnel...
  3013. {
  3014. tunnel_pos(flag,pn,x,y);
  3015. flag2=TRUE;
  3016. }
  3017. if (((match_mode==CENTRE_A) && (flag==1))
  3018. || ((match_mode==CENTRE_B) && (flag==2)))
  3019. // Centre takers...
  3020. centre_pos(flag,pn,flag2,x,y);
  3021. if (((match_mode==GOAL_KICK_TL) || (match_mode==GOAL_KICK_BL) && (flag==1))
  3022. || ((match_mode==GOAL_KICK_TR) || (match_mode==GOAL_KICK_BR) && (flag==2)))
  3023. // Goal kick takers...
  3024. gkick_pos(flag,pn,flag2,x,y,taker);
  3025. if (((match_mode==CORNER_TL) || (match_mode==CORNER_BL) && (flag==2))
  3026. || ((match_mode==CORNER_TR) || (match_mode==CORNER_BR) && (flag==1)))
  3027. // Corner takers...
  3028. corner_pos(flag,pn,flag2,x,y,taker);
  3029. if ((match_mode==THROW_IN_A) || (match_mode==THROW_IN_B))
  3030. // Throw-in taker...
  3031. throw_in_pos(flag,pn,flag2,x,y,taker);
  3032. if ((match_mode==DF_KICK_A) || (match_mode==DF_KICK_B))
  3033. // Direct F.K....
  3034. dfkick_pos(flag,pn,flag2,x,y,taker);
  3035. if ((match_mode==IF_KICK_A) || (match_mode==IF_KICK_B))
  3036. // In-direct F.K....
  3037. fkick_pos(flag,pn,flag2,x,y,taker);
  3038. if ((match_mode==PEN_KICK_A) || (match_mode==PEN_KICK_B))
  3039. // Penalty Kick....
  3040. penalty_pos(flag,pn,flag2,x,y,taker);
  3041. }
  3042. if (!flag2)
  3043. /**************************/
  3044. // Normal match play!
  3045. {
  3046. if ((man2man_b) && (flag==2) && (teams[pn+11].tm_mark))
  3047. {
  3048. // Team B defends man-to-man...
  3049. x=pitch_len-man2man[pn-1][0];
  3050. y=pitch_wid-man2man[pn-1][1];
  3051. }
  3052. else
  3053. {
  3054. if ((man2man_a) && (flag==1) && (teams[pn].tm_mark))
  3055. {
  3056. // Team A defends man-to-man...
  3057. x=man2man[pn-1][0];
  3058. y=man2man[pn-1][1];
  3059. }
  3060. else
  3061. {
  3062. // Normal Zonal Position...
  3063. x=get_tac(&tac[bz][pn-1][0]);
  3064. y=get_tac(&tac[bz][pn-1][1]);
  3065. if (flag==1 && bz==68 && pn==centre_guy_2-1)
  3066. {
  3067. x=cntspot_x+80;
  3068. y=cntspot_y+10;
  3069. flag=0;
  3070. }
  3071. if (flag==2 && bz==69 && pn==centre_guy_2-12)
  3072. {
  3073. x=cntspot_x-80;
  3074. y=cntspot_y+10;
  3075. flag=0;
  3076. }
  3077. if (flag)
  3078. {
  3079. float bx=LIMIT(ballx,0,pitch_len);
  3080. float by=LIMIT(bally,0,pitch_wid);
  3081. if ((analogue) && (!ball_out_of_play) &&
  3082. ((!dead_ball_cnt) || (match_mode<CORNER_TL) || (match_mode>THROW_IN_B)))
  3083. {
  3084. if (flag==1)
  3085. {
  3086. ox=bx-zx; // offset from centre of zone!
  3087. oy=by-zy;
  3088. }
  3089. else
  3090. {
  3091. ox=(pitch_len-bx)-zx; // offset from centre of zone!
  3092. oy=(pitch_wid-by)-zy;
  3093. }
  3094. float xa,xb,xc,ya,yb,yc;
  3095. if (ox<=0)
  3096. {
  3097. int b=bz-1;
  3098. if (b<0)
  3099. b=0;
  3100. xa=get_tac(&tac[b][pn-1][0]); //left zone
  3101. ya=get_tac(&tac[b][pn-1][1]); //left zone
  3102. if (oy<=0)
  3103. {
  3104. b=bz-8-1;
  3105. if (b<0)
  3106. b=0;
  3107. xb=get_tac(&tac[b][pn-1][0]); //top left zone
  3108. yb=get_tac(&tac[b][pn-1][1]); //top left zone
  3109. xc=get_tac(&tac[b+1][pn-1][0]); //top zone
  3110. yc=get_tac(&tac[b+1][pn-1][1]); //top zone
  3111. }
  3112. else
  3113. {
  3114. b=bz+8;
  3115. if (b>31)
  3116. b=31;
  3117. xb=get_tac(&tac[b-1][pn-1][0]); //bot left zone
  3118. yb=get_tac(&tac[b-1][pn-1][1]); //bot left zone
  3119. xc=get_tac(&tac[b][pn-1][0]); //bot zone
  3120. yc=get_tac(&tac[b][pn-1][1]); //bot zone
  3121. }
  3122. }
  3123. else
  3124. {
  3125. int b=bz+1;
  3126. if (b>31)
  3127. b=31;
  3128. xa=get_tac(&tac[b][pn-1][0]); //right zone
  3129. ya=get_tac(&tac[b][pn-1][1]); //right zone
  3130. if (oy<=0)
  3131. {
  3132. b=bz-8;
  3133. if (b<0)
  3134. b=0;
  3135. xb=get_tac(&tac[b+1][pn-1][0]); //top right zone
  3136. yb=get_tac(&tac[b+1][pn-1][1]); //top right zone
  3137. xc=get_tac(&tac[b][pn-1][0]); //top zone
  3138. yc=get_tac(&tac[b][pn-1][1]); //top zone
  3139. }
  3140. else
  3141. {
  3142. b=bz+8+1;
  3143. if (b>31)
  3144. b=31;
  3145. xb=get_tac(&tac[b][pn-1][0]); //bot right zone
  3146. yb=get_tac(&tac[b][pn-1][1]); //bot right zone
  3147. xc=get_tac(&tac[b-1][pn-1][0]); //bot zone
  3148. yc=get_tac(&tac[b-1][pn-1][1]); //bot zone
  3149. }
  3150. }
  3151. float xint_ab=xa+((xb-xa)*ABS(oy)/zone_hgt);
  3152. float xint_hc=x+((xc-x)*ABS(oy)/zone_hgt);
  3153. float yint_cb=yc+((yb-yc)*ABS(ox)/zone_wid);
  3154. float yint_ha=y+((ya-y)*ABS(ox)/zone_wid);
  3155. x=xint_hc+((xint_ab-xint_hc)*ABS(ox)/zone_wid);
  3156. y=yint_ha+((yint_cb-yint_ha)*ABS(oy)/zone_hgt);
  3157. }
  3158. }
  3159. }
  3160. }
  3161. float xoff,yoff;
  3162. if (flag)
  3163. {
  3164. if (flag==1)
  3165. {
  3166. xoff=x-incident_x;
  3167. yoff=y-incident_y;
  3168. }
  3169. else
  3170. {
  3171. xoff=(pitch_len-x)-incident_x;
  3172. yoff=(pitch_wid-y)-incident_y;
  3173. }
  3174. }
  3175. switch(game_action)
  3176. {
  3177. float dist;
  3178. // Team A and B must be 10 yards away from ball!
  3179. case(-1):
  3180. case(1):
  3181. dist=calc_dist(xoff,yoff);
  3182. if (dist<prat*10)
  3183. {
  3184. if (flag==1)
  3185. {
  3186. x=incident_x+(xoff*(INCIDENT_DIST)/dist);
  3187. y=incident_y+(yoff*(INCIDENT_DIST)/dist);
  3188. }
  3189. else
  3190. {
  3191. x=pitch_len-(incident_x+(xoff*(INCIDENT_DIST)/dist));
  3192. y=pitch_wid-(incident_y+(yoff*(INCIDENT_DIST)/dist));
  3193. }
  3194. }
  3195. break;
  3196. // Team A and B must be 10 yards away from ball and outside penalty box!
  3197. case(2):
  3198. if (ballx<cntspot_x)
  3199. if (flag==1)
  3200. x=prat*19;
  3201. else
  3202. x=pitch_len-(prat*19);
  3203. else
  3204. if (flag==1)
  3205. x=pitch_len-(prat*19); // On edge of 18 yard box!
  3206. else
  3207. x=prat*19;
  3208. if (flag==1)
  3209. {
  3210. xoff=x-incident_x;
  3211. yoff=y-incident_y;
  3212. }
  3213. else
  3214. {
  3215. xoff=(pitch_len-x)-incident_x;
  3216. yoff=(pitch_wid-y)-incident_y;
  3217. }
  3218. dist=calc_dist(xoff,yoff);
  3219. if (dist<prat*10)
  3220. {
  3221. if (flag==1)
  3222. {
  3223. x=incident_x+(xoff*(INCIDENT_DIST)/dist);
  3224. y=incident_y+(yoff*(INCIDENT_DIST)/dist);
  3225. }
  3226. else
  3227. {
  3228. x=pitch_len-(incident_x+(xoff*(INCIDENT_DIST)/dist));
  3229. y=pitch_wid-(incident_y+(yoff*(INCIDENT_DIST)/dist));
  3230. }
  3231. }
  3232. break;
  3233. }
  3234. }
  3235. }
  3236. /******************************************************************************
  3237. *****************************************************************************/
  3238. void find_zonal_target(match_player *player,float px,float py)
  3239. {
  3240. if (!player->draw_me && player->tm_y>0 && player->tm_y<pitch_wid)
  3241. player->draw_me=TRUE;
  3242. int ball_zn;
  3243. char f;
  3244. float tx,ty,sx,sy;
  3245. if ((player->tm_player==KP_A) || (player->tm_player==KP_B))
  3246. {
  3247. /****************
  3248. ** Goal-Keeper **
  3249. ****************/
  3250. if (player->tm_player==KP_A)
  3251. {
  3252. if ((dead_ball_cnt) && (gkick_taker==KP_A) &&
  3253. ((match_mode==GOAL_KICK_TL) || (match_mode==GOAL_KICK_BL)))
  3254. {
  3255. // Taking Goal Kick!
  3256. tx=taker_x;
  3257. ty=taker_y;
  3258. set_there_flags(gkick_taker);
  3259. }
  3260. else
  3261. {
  3262. if (match_mode==DF_KICK_B && men_in_wall>2)
  3263. {
  3264. // Get keeper in position behind last man in wall...
  3265. tx=keeper_pos_x;
  3266. ty=keeper_pos_y;
  3267. }
  3268. else
  3269. {
  3270. if (match_mode==SWAP_ENDS)
  3271. {
  3272. get_target(1,ball_zn,zone1_x,zone1_y,(player->tm_player)-1,tx,ty,match_tactics1);
  3273. }
  3274. else
  3275. {
  3276. if (ball_poss>=12 && match_mode!=PEN_KICK_B && !penalty_shot)
  3277. {
  3278. // Opponent_has ball...
  3279. float d=calc_dist(ballx,bally-cntspot_y); // distance of centre of goal to ball!
  3280. if ((keeper_a_in_box) && (d<CLOSE_ANG_DIST+(prat*player->tm_vis)/8))
  3281. // Shut the door...
  3282. close_angle(player,d,tx,ty); // Close down the angle of shot.
  3283. else
  3284. {
  3285. tx=KP_OFFLINE;
  3286. ty=cntspot_y-1;
  3287. }
  3288. }
  3289. else
  3290. {
  3291. if (match_mode==PEN_KICK_B)
  3292. tx=0;
  3293. else
  3294. if (shot_pending && penalty_shot)
  3295. tx=0;
  3296. else
  3297. tx=KP_OFFLINE;
  3298. ty=cntspot_y-1;
  3299. }
  3300. }
  3301. }
  3302. }
  3303. }
  3304. else
  3305. {
  3306. if ((dead_ball_cnt) && (gkick_taker==KP_B) &&
  3307. ((match_mode==GOAL_KICK_TR) || (match_mode==GOAL_KICK_BR)))
  3308. {
  3309. // Taking Goal Kick!
  3310. tx=taker_x;
  3311. ty=taker_y;
  3312. set_there_flags(gkick_taker);
  3313. }
  3314. else
  3315. {
  3316. if (match_mode==DF_KICK_A && men_in_wall>2)
  3317. {
  3318. // Get keeper in position behind last man in wall...
  3319. tx=keeper_pos_x;
  3320. ty=keeper_pos_y;
  3321. }
  3322. else
  3323. {
  3324. if (match_mode==SWAP_ENDS)
  3325. {
  3326. get_target(2,ball_zn,zone2_x,zone2_y,(player->tm_player)-12,tx,ty,match_tactics2);
  3327. tx=pitch_len-tx;
  3328. ty=pitch_wid-ty;
  3329. }
  3330. else
  3331. {
  3332. if (ball_poss && ball_poss<12 && match_mode!=PEN_KICK_A && !penalty_shot)
  3333. {
  3334. // Opponent_has ball...
  3335. float d=calc_dist(pitch_len-ballx,bally-cntspot_y); // distance of centre of goal to ball!
  3336. if ((keeper_b_in_box) && (d<CLOSE_ANG_DIST+(prat*player->tm_vis)/8))
  3337. // Shut the door...
  3338. close_angle(player,d,tx,ty); // Close down the angle of shot.
  3339. else
  3340. {
  3341. tx=pitch_len-KP_OFFLINE;
  3342. ty=cntspot_y-1;
  3343. }
  3344. }
  3345. else
  3346. {
  3347. if (match_mode==PEN_KICK_A)
  3348. tx=pitch_len-1;
  3349. else
  3350. if (shot_pending && penalty_shot)
  3351. tx=pitch_len-1;
  3352. else
  3353. tx=pitch_len-KP_OFFLINE;
  3354. ty=cntspot_y-1;
  3355. }
  3356. }
  3357. }
  3358. }
  3359. }
  3360. tx=tx-px;
  3361. ty=ty-py;
  3362. char s;
  3363. float d=calc_dist(tx,ty);
  3364. if ((player->face_dir!=get_dir(tx,ty)) &&
  3365. (((player->go_step) && (d<STEP_RANGE*2))
  3366. || ((!player->go_step) && (d<STEP_RANGE))))
  3367. // Calculate single move.
  3368. {
  3369. s=TRUE;
  3370. if (player->tm_rate>=d*32)
  3371. {
  3372. sx=tx;
  3373. sy=ty;
  3374. }
  3375. else
  3376. {
  3377. sx=(player->tm_rate/(d*32))*tx;
  3378. sy=(player->tm_rate/(d*32))*ty;
  3379. }
  3380. }
  3381. else
  3382. {
  3383. // Calculate single move.
  3384. if (player->tm_rate>=d*16)
  3385. {
  3386. sx=tx;
  3387. sy=ty;
  3388. }
  3389. else
  3390. {
  3391. sx=(player->tm_rate/(d*16))*tx;
  3392. sy=(player->tm_rate/(d*16))*ty;
  3393. }
  3394. }
  3395. init_run_act(player,tx+px,ty+py,TRUE);
  3396. if (player->tm_act==RUN_ACT)
  3397. {
  3398. go_forward(player);
  3399. player->go_cnt=0;
  3400. }
  3401. }
  3402. else
  3403. {
  3404. /***********
  3405. ** PLAYER **
  3406. ***********/
  3407. if (!player->int_cnt)
  3408. {
  3409. if (player->tm_player<12) // Team A?
  3410. {
  3411. if ((ball_zone1<32) && (last_touch<12) && (last_touch!=0)) // Team A. in possession?
  3412. ball_zn=32;
  3413. else
  3414. ball_zn=0;
  3415. ball_zn+=ball_zone1;
  3416. get_target(1,ball_zn,zone1_x,zone1_y,(player->tm_player)-1,tx,ty,match_tactics1);
  3417. tx=tx-px;
  3418. ty=ty-py;
  3419. float d=calc_dist(tx,ty);
  3420. if ((player->tm_act==RUN_ACT) ||
  3421. (d>GO_TO_POS_DIST && player->tm_act!=RUN_ACT))
  3422. {
  3423. char s;
  3424. float d=calc_dist(tx,ty);
  3425. if ((player->face_dir!=get_dir(tx,ty)) &&
  3426. (((player->go_step) && (d<STEP_RANGE*2))
  3427. || ((!player->go_step) && (d<STEP_RANGE))))
  3428. {
  3429. s=TRUE;
  3430. }
  3431. else
  3432. {
  3433. s=FALSE;
  3434. }
  3435. init_run_act(player,tx+px,ty+py,TRUE);
  3436. if (player->tm_act==RUN_ACT)
  3437. {
  3438. go_forward(player);
  3439. player->go_cnt=0;
  3440. }
  3441. }
  3442. else
  3443. {
  3444. // There already!
  3445. if (player->int_move==I_THROW)
  3446. {
  3447. player->int_cnt=1;
  3448. reset_ideas(player);
  3449. }
  3450. }
  3451. }
  3452. else
  3453. {
  3454. if ((ball_zone2<32) && last_touch>11) // Team B. in possession?
  3455. ball_zn=32;
  3456. else
  3457. ball_zn=0;
  3458. ball_zn+=ball_zone2;
  3459. get_target(2,ball_zn,zone2_x,zone2_y,(player->tm_player)-12,tx,ty,match_tactics2);
  3460. tx=(pitch_len-tx)-px;
  3461. ty=(pitch_wid-ty)-py;
  3462. float d=calc_dist(tx,ty);
  3463. if ((player->tm_act==RUN_ACT) ||
  3464. (d>GO_TO_POS_DIST && player->tm_act!=RUN_ACT))
  3465. {
  3466. char s;
  3467. float d=calc_dist(tx,ty);
  3468. if ((player->face_dir!=get_dir(tx,ty)) &&
  3469. ((player->go_step) && (d<STEP_RANGE*2))
  3470. || ((!player->go_step) && (d<STEP_RANGE)))
  3471. // Calculate single move.
  3472. {
  3473. s=TRUE;
  3474. }
  3475. else
  3476. {
  3477. s=FALSE;
  3478. }
  3479. init_run_act(player,tx+px,ty+py,TRUE);
  3480. if (player->tm_act==RUN_ACT)
  3481. {
  3482. go_forward(player);
  3483. player->go_cnt=0;
  3484. }
  3485. }
  3486. else
  3487. {
  3488. // There already!
  3489. if (player->int_move==I_THROW)
  3490. {
  3491. player->int_cnt=1;
  3492. reset_ideas(player);
  3493. }
  3494. }
  3495. }
  3496. }
  3497. }
  3498. }
  3499. /******************************************************************************
  3500. *****************************************************************************/
  3501. // Return closest guy to the predicted path of ball who is not busy!
  3502. // p_num = first player in team.
  3503. int get_near_path(int p_num,int not_busy)
  3504. {
  3505. int near_guy=0, closest=10000;
  3506. int t=0;
  3507. // Get average position of ball...
  3508. float x1=ball_pred_tab[t][0];
  3509. float y1=ball_pred_tab[t][1];
  3510. float z1=ball_pred_tab[t][2];
  3511. float px,py;
  3512. short points=0;
  3513. float x=-1000;
  3514. float y=0;
  3515. float z=0;
  3516. float d;
  3517. for (int b=1; b<40; b++)
  3518. {
  3519. if (x<-999 && ball_pred_tab[b][2]<PLAYER_HEIGHT+4)
  3520. {
  3521. x=ball_pred_tab[b][0]-x1;
  3522. y=ball_pred_tab[b][1]-y1;
  3523. }
  3524. else
  3525. {
  3526. if (x>-999)
  3527. {
  3528. x+=ball_pred_tab[b][0]-x1;
  3529. y+=ball_pred_tab[b][1]-y1;
  3530. points++;
  3531. }
  3532. }
  3533. }
  3534. if (points)
  3535. {
  3536. x=x/points;
  3537. y=y/points;
  3538. x+=x1;
  3539. y+=y1;
  3540. }
  3541. else
  3542. {
  3543. x=ball_pred_tab[40][0];
  3544. y=ball_pred_tab[40][1];
  3545. }
  3546. for (int i=p_num+10; i>=p_num; i--)
  3547. {
  3548. if (teams[i].tm_notme)
  3549. teams[i].tm_notme--; // he can't get there!
  3550. else
  3551. {
  3552. if ((teams[i].tm_act<=TURN_ACT || (teams[i].tm_act==TACKLE_ACT && teams[i].control))
  3553. && ball_poss!=p_num+1) //player is not busy!
  3554. {
  3555. if ((!(teams[i].int_cnt)) || (not_busy))
  3556. {
  3557. px=teams[i].tm_x;
  3558. py=teams[i].tm_y;
  3559. d=calc_dist(px-x,py-y);
  3560. if (i==(KP_A-1) || i==(KP_B-1))
  3561. {
  3562. // Keeper only intercept if half as close as defender!
  3563. if (d*2<closest && closest>prat*2)
  3564. {
  3565. near_guy=i+1; //This guy is closer!
  3566. closest=d;
  3567. }
  3568. }
  3569. else
  3570. {
  3571. if (d<closest)
  3572. {
  3573. near_guy=i+1; //This guy is closer!
  3574. closest=d;
  3575. }
  3576. }
  3577. }
  3578. }
  3579. }
  3580. }
  3581. return(near_guy);
  3582. }
  3583. /******************************************************************************
  3584. *****************************************************************************/
  3585. // Return closest guy to the predicted path of ball who is not busy!
  3586. // p_num = first player in team.
  3587. int oget_near_path(int p_num,int not_busy)
  3588. {
  3589. int near_guy=0, closest=10000;
  3590. int t=first_bounce;
  3591. if (t<0)
  3592. t=0;
  3593. // Get average position of ball...
  3594. float x1=ball_pred_tab[t][0];
  3595. float y1=ball_pred_tab[t][1];
  3596. float z1=ball_pred_tab[t][2];
  3597. float px,py;
  3598. short points=0;
  3599. float x=0;
  3600. float y=0;
  3601. float z=0;
  3602. float d;
  3603. for (int b=t+1; b<40; b++)
  3604. {
  3605. if (ball_pred_tab[b][2]<PLAYER_HEIGHT+4)
  3606. {
  3607. x+=ball_pred_tab[b][0]-x1;
  3608. y+=ball_pred_tab[b][1]-y1;
  3609. points++;
  3610. }
  3611. }
  3612. if (points)
  3613. {
  3614. x=x/points;
  3615. y=y/points;
  3616. x+=x1;
  3617. y+=y1;
  3618. }
  3619. else
  3620. {
  3621. x=ball_pred_tab[40][0];
  3622. y=ball_pred_tab[40][1];
  3623. }
  3624. for (int i=p_num+10; i>=p_num; i--)
  3625. {
  3626. if (teams[i].tm_notme)
  3627. teams[i].tm_notme--; // he can't get there!
  3628. else
  3629. {
  3630. if (teams[i].tm_act<=TURN_ACT && ball_poss!=p_num+1) //player is not busy!
  3631. {
  3632. if ((!(teams[i].int_cnt)) || (not_busy))
  3633. {
  3634. px=teams[i].tm_x;
  3635. py=teams[i].tm_y;
  3636. d=calc_dist(px-x,py-y);
  3637. if (i==(KP_A-1) || i==(KP_B-1))
  3638. {
  3639. // Keeper only intercept if half as close as defender!
  3640. if (d*2<closest && closest>prat*2)
  3641. {
  3642. near_guy=i+1; //This guy is closer!
  3643. closest=d;
  3644. }
  3645. }
  3646. else
  3647. {
  3648. if (d<closest)
  3649. {
  3650. near_guy=i+1; //This guy is closer!
  3651. closest=d;
  3652. }
  3653. }
  3654. }
  3655. }
  3656. }
  3657. }
  3658. return(near_guy);
  3659. }
  3660. /******************************************************************************
  3661. *****************************************************************************/
  3662. void forward_joystick(match_player *p,float &x,float &y)
  3663. {
  3664. x=p->go_txdis;
  3665. y=p->go_tydis;
  3666. if (ux)
  3667. {
  3668. // Turn!
  3669. float ta=(PI/12)*ux;
  3670. float nx=x*cos(ta)-y*sin(ta);
  3671. float ny=y*cos(ta)+x*sin(ta);
  3672. x=nx;
  3673. y=ny;
  3674. }
  3675. }
  3676. /******************************************************************************
  3677. *****************************************************************************/
  3678. void get_face_xy(int d,float &x,float &y)
  3679. {
  3680. switch(d)
  3681. {
  3682. case(0):
  3683. x=-UNIT;
  3684. y=0;
  3685. break;
  3686. case(1):
  3687. x=-DIAG;
  3688. y=DIAG;
  3689. break;
  3690. case(2):
  3691. x=0;
  3692. y=UNIT;
  3693. break;
  3694. case(3):
  3695. x=DIAG;
  3696. y=DIAG;
  3697. break;
  3698. case(4):
  3699. x=UNIT;
  3700. y=0;
  3701. break;
  3702. case(5):
  3703. x=DIAG;
  3704. y=-DIAG;
  3705. break;
  3706. case(6):
  3707. x=0;
  3708. y=-UNIT;
  3709. break;
  3710. case(7):
  3711. x=-DIAG;
  3712. y=-DIAG;
  3713. break;
  3714. }
  3715. }
  3716. /******************************************************************************
  3717. *****************************************************************************/
  3718. int get_dir(float x,float y)
  3719. {
  3720. int d=0;
  3721. if (y>=0)
  3722. {
  3723. if (x>=0)
  3724. {
  3725. if (x>y)
  3726. {
  3727. if (x>(y*2))
  3728. d=4;
  3729. else
  3730. d=3;
  3731. }
  3732. else
  3733. {
  3734. if (y>(x*2))
  3735. d=2;
  3736. else
  3737. d=3;
  3738. }
  3739. }
  3740. else
  3741. {
  3742. if (-x>y)
  3743. {
  3744. if (-x>(y*2))
  3745. d=0;
  3746. else
  3747. d=1;
  3748. }
  3749. else
  3750. {
  3751. if (y>(-x*2))
  3752. d=2;
  3753. else
  3754. d=1;
  3755. }
  3756. }
  3757. }
  3758. else
  3759. {
  3760. if (x>=0)
  3761. {
  3762. if (x>-y)
  3763. {
  3764. if (x>(-y*2))
  3765. d=4;
  3766. else
  3767. d=5;
  3768. }
  3769. else
  3770. {
  3771. if (-y>(x*2))
  3772. d=6;
  3773. else
  3774. d=5;
  3775. }
  3776. }
  3777. else
  3778. {
  3779. if (-x>-y)
  3780. {
  3781. if (-x>(-y*2))
  3782. d=0;
  3783. else
  3784. d=7;
  3785. }
  3786. else
  3787. {
  3788. if (-y>(-x*2))
  3789. d=6;
  3790. else
  3791. d=7;
  3792. }
  3793. }
  3794. }
  3795. return(d);
  3796. }
  3797. /******************************************************************************
  3798. *****************************************************************************/
  3799. int angle_of_vis(match_player *player,int x,int y,float d,char cross=FALSE)
  3800. {
  3801. float a;
  3802. float xd=player->tm_xdis;
  3803. float yd=player->tm_ydis;
  3804. float d2=calc_dist(xd,yd);
  3805. xd=xd/d2;
  3806. yd=yd/d2;
  3807. if (cross)
  3808. {
  3809. if (player->tm_player<12)
  3810. // Team A...
  3811. {
  3812. if ((d/2>(MIN_PASS_DIST+(float)player->tm_pow/3.6)) && (x+player->tm_x>pitch_len-(prat*18)))
  3813. return(TRUE);
  3814. else
  3815. return(FALSE);
  3816. }
  3817. else
  3818. // Team B...
  3819. {
  3820. if ((d/2>(MIN_PASS_DIST+(float)player->tm_pow/3.6)) && (x+player->tm_x<(prat*18)))
  3821. return(TRUE);
  3822. else
  3823. return(FALSE);
  3824. }
  3825. }
  3826. if (set_piece_on)
  3827. a=((x*setp_kick_x)+(y*setp_kick_y))/d; // Joystick dir.
  3828. else
  3829. a=((x*xd)+(y*yd))/d; // facing...
  3830. if (a>=DIAG)
  3831. return(TRUE);
  3832. else
  3833. return(FALSE);
  3834. }
  3835. /******************************************************************************
  3836. *****************************************************************************/
  3837. // Creates table of opponents round player within DRIB_DANGER_AREA.
  3838. void get_opp_dir_tab(int pnum)
  3839. {
  3840. float dist=DRIB_DANGER_AREA+(prat*(((128-teams[pnum-1].tm_flair)/12)-5));
  3841. drib_opps=0;
  3842. int op=1;
  3843. if (pnum<12)
  3844. op=12;
  3845. float x,y,d,dif;
  3846. for (int p=op; p<op+11; p++)
  3847. {
  3848. // Vectors for opp. to ball...
  3849. x=(teams[p-1].tm_x-ballx)/teams[p-1].tm_dist;
  3850. y=(teams[p-1].tm_y-bally)/teams[p-1].tm_dist;
  3851. // Calculate difference range of 2(ahead) to 0(behind)...
  3852. dif=1+((teams[pnum-1].tm_xdis*x)+(teams[pnum-1].tm_ydis*y));
  3853. d=dist/4+(dist*dif*3/8);
  3854. if (teams[p-1].guy_on && teams[p-1].tm_dist<=d && teams[p-1].tm_act<TURN_ACT)
  3855. {
  3856. // if (!(teams[p-1].tm_act==TACKLE_ACT && ((teams[p-1].go_txdis*teams[p-1].go_tydis)<4)))
  3857. {
  3858. opp_dir_tab[drib_opps][0]=teams[p-1].tm_x;
  3859. opp_dir_tab[drib_opps][1]=teams[p-1].tm_y;
  3860. opp_dir_tab[drib_opps][2]=1-(teams[pnum-1].tm_dist/d); // Attack potential
  3861. drib_opps++;
  3862. }
  3863. }
  3864. }
  3865. }
  3866. /******************************************************************************
  3867. *****************************************************************************/
  3868. // Count the number of opponents around player (pnum)!
  3869. int opp_around(int x,int y,int pnum)
  3870. {
  3871. int op=1;
  3872. int d;
  3873. int opponents=0;
  3874. if (pnum<12)
  3875. op=12;
  3876. for (int p=op; p<op+11; p++)
  3877. {
  3878. if (teams[p-1].guy_on)
  3879. {
  3880. d=calc_dist(teams[p-1].tm_x-x,teams[p-1].tm_y-y);
  3881. if (ball_poss==KP_A || ball_poss==KP_B)
  3882. {
  3883. if (d<=(DANGER_AREA*1.6))
  3884. opponents++;
  3885. }
  3886. else
  3887. {
  3888. if (d<=DANGER_AREA)
  3889. opponents++;
  3890. }
  3891. }
  3892. }
  3893. return(opponents);
  3894. }
  3895. /******************************************************************************
  3896. *****************************************************************************/
  3897. // Count the number of opponents around player (pnum)!
  3898. // This function specific to keeper passing out...
  3899. int kopp_around(int x,int y,int pnum)
  3900. {
  3901. int op=1;
  3902. int d;
  3903. int opponents=0;
  3904. if (pnum<12)
  3905. op=12;
  3906. for (int p=op; p<op+11; p++)
  3907. {
  3908. if (teams[p-1].guy_on)
  3909. {
  3910. d=calc_dist(teams[p-1].tm_x-x,teams[p-1].tm_y-y);
  3911. if (d<=(DANGER_AREA*2))
  3912. opponents++;
  3913. }
  3914. }
  3915. return(opponents);
  3916. }
  3917. /******************************************************************************
  3918. *****************************************************************************/
  3919. float facing_opp(match_player *player,short opp)
  3920. {
  3921. float xd=player->tm_xdis;
  3922. float yd=player->tm_ydis;
  3923. float xo=teams[opp-1].tm_xdis;
  3924. float yo=teams[opp-1].tm_ydis;
  3925. float a=((xo*xd)+(yo*yd));
  3926. return(a);
  3927. }
  3928. /******************************************************************************
  3929. *****************************************************************************/
  3930. void player_ints(match_player *player)
  3931. {
  3932. if (((player->tm_act==TACKLE_ACT && player->go_cnt>EFFECTIVE_TACK)
  3933. || (player->tm_act==STEAL_ACT && player->tm_frm>0.4 && player->tm_frm<0.6))
  3934. && (!dead_ball_cnt) && (!just_scored))
  3935. {
  3936. float x,y,z;
  3937. float dir;
  3938. short chance;
  3939. for (int i=1; i<=players; i++)
  3940. {
  3941. if (teams[i-1].tm_act<=TURN_ACT)
  3942. {
  3943. x=player->tm_x-teams[i-1].tm_x;
  3944. y=player->tm_y-teams[i-1].tm_y;
  3945. z=player->tm_y-teams[i-1].tm_y;
  3946. if ((calc_dist(x,y)<=PLAYER_SIZE) && (z<PLAYER_HEIGHT/3))
  3947. {
  3948. // If the tackling player comes in from behind or the side
  3949. // then he has a greater chance of bringing the opponent down!
  3950. dir=facing_opp(player,i);
  3951. chance=seed/(dir+2);
  3952. if (chance<(42+((player->tm_pow-teams[i-1].tm_pow)/3)))
  3953. {
  3954. // Crunching tackle...
  3955. init_fall(&teams[i-1]);
  3956. // if ((!player->go_step) && ((player_num<12 && i>11) || (player_num>11 && i<12)))
  3957. if (((player_num<12 && i>11) || (player_num>11 && i<12)))
  3958. {
  3959. // He is in opposing team!
  3960. // He hasn't made contact with ball...
  3961. // Therefore a foul has been commited...
  3962. man_down=calc_dist(player->go_txdis,
  3963. player->go_tydis);
  3964. init_foul(player->tm_player,TRUE); // pass no. of fouler.
  3965. // Man appeals for f.k...
  3966. init_speech(i,SAY_REF,REAL_SPEED);
  3967. }
  3968. }
  3969. else
  3970. // Ride over tackle...
  3971. if (player->tm_act!=STEAL_ACT)
  3972. init_jump_act(&teams[i-1],TRUE,TRUE);
  3973. }
  3974. }
  3975. }
  3976. }
  3977. }
  3978. /*****************************************************************************
  3979. *****************************************************************************/
  3980. char cross_angle(float xd,float yd,float x,float y)
  3981. {
  3982. float a=angle_to_xy(xd,yd,x,y);
  3983. if (a>-0.174 && a<0.707)
  3984. // In 55 degree threshold (100 -> 45)...
  3985. {
  3986. if ((xd*y)>(yd*x))
  3987. return(1);
  3988. else
  3989. return(2);
  3990. }
  3991. else
  3992. return(0);
  3993. }
  3994. /*****************************************************************************
  3995. *****************************************************************************/
  3996. void new_interceptor(int p)
  3997. {
  3998. if (p<12)
  3999. {
  4000. // Team A...
  4001. if (interceptor_a)
  4002. {
  4003. reset_ideas(&teams[interceptor_a-1]);
  4004. }
  4005. receiver_a=p;
  4006. near_path_a=p; // Fake passee as nearest!
  4007. }
  4008. else
  4009. {
  4010. // Team B...
  4011. if (interceptor_b)
  4012. {
  4013. reset_ideas(&teams[interceptor_b-1]);
  4014. }
  4015. receiver_b=p;
  4016. near_path_b=p; // Fake passee as nearest!
  4017. }
  4018. #ifdef EURO96 // 1-2 Pass.
  4019. if (uf1)
  4020. // Force receiver to return ball again to complete 1-2!
  4021. {
  4022. return_12=p;
  4023. }
  4024. else
  4025. {
  4026. return_12=FALSE;
  4027. reselect(); // Can control receiver.
  4028. }
  4029. #else
  4030. reselect();
  4031. #endif
  4032. }
  4033. /*****************************************************************************
  4034. *****************************************************************************/
  4035. int pass_ahead(int ps,float &x,float &y,float &pass_speed,float &end_speed,char cross)
  4036. {
  4037. int i=0;
  4038. int t;
  4039. float a,b,s;
  4040. a=x;
  4041. b=y;
  4042. float xd,yd,dd;
  4043. int extra;
  4044. if (ball_limbo_on)
  4045. extra=((ball_limbo_c-teams[ball_limbo_p-1].tm_frm)/teams[ball_limbo_p-1].tm_fstep)-1;
  4046. else
  4047. extra=0;
  4048. // Get Targets movement...
  4049. xd=teams[ps-1].go_txdis;
  4050. yd=teams[ps-1].go_tydis;
  4051. for (i=1; i<40; i++)
  4052. {
  4053. a+=xd;
  4054. b+=yd; // Inc running time
  4055. dd=calc_dist(a,b);
  4056. if (cross || dd>LOW_PASS_DIST || chip_pass)
  4057. {
  4058. // In air...
  4059. pass_speed=end_speed+4+(dd*(1-AIR_FRICTION));
  4060. t=(log((end_speed+4)/pass_speed))/(log(AIR_FRICTION));
  4061. }
  4062. else
  4063. {
  4064. // On grnd...
  4065. pass_speed=end_speed+(dd*(1-GRND_FRICTION));
  4066. t=(log(end_speed/pass_speed))/(log(GRND_FRICTION));
  4067. }
  4068. if (t<=(i-extra))
  4069. i=1000; // Intersection with run here...
  4070. }
  4071. if (i>=1000)
  4072. {
  4073. // successfull intersection....
  4074. x=a+xd;
  4075. y=b+yd; // new offsets...
  4076. if ((x+ballx)<0)
  4077. x=prat-ballx;
  4078. if ((x+ballx)>pitch_len)
  4079. x=(pitch_len-prat)-ballx;
  4080. if ((y+bally)<0)
  4081. y=prat-bally;
  4082. if ((y+bally)>pitch_wid)
  4083. y=(pitch_wid-prat)-bally;
  4084. if (dd>LOW_PASS_DIST)
  4085. ball_inair=TRUE;
  4086. }
  4087. return(t);
  4088. }
  4089. /*****************************************************************************
  4090. *****************************************************************************/
  4091. void choose_pass(int ps,float &x,float &y,float &pass_speed,float &end_speed,char cross)
  4092. {
  4093. float tx,ty,d;
  4094. if (cross)
  4095. {
  4096. // Cross it ahead of him towards opponents goal...
  4097. if (ps<12)
  4098. // Team B's Goal!
  4099. {
  4100. tx=pitch_len-teams[ps-1].tm_x;
  4101. ty=cntspot_y-teams[ps-1].tm_y;
  4102. }
  4103. else
  4104. // Team A's Goal!
  4105. {
  4106. tx=-teams[ps-1].tm_x;
  4107. ty=cntspot_y-teams[ps-1].tm_y;
  4108. }
  4109. if ((tx<=prat && ps<12) || (tx>-prat && ps>11))
  4110. {
  4111. // Close to goal-line (straight to him instead!)...
  4112. init_stand_act(&teams[ps-1]);
  4113. int t=pass_ahead(ps,x,y,pass_speed,end_speed,cross); // Obviously he isn't moving so it will go straight to him!
  4114. }
  4115. else
  4116. {
  4117. // Target aimed ahead of player towards goal...
  4118. d=calc_dist(tx,ty);
  4119. x+=tx*prat/d;
  4120. y+=ty*prat/d;
  4121. init_stand_act(&teams[ps-1]);
  4122. pass_ahead(ps,x,y,pass_speed,end_speed,cross);
  4123. }
  4124. }
  4125. else
  4126. {
  4127. if (((((ps<12 && teams[ps-1].go_txdis>0) || (ps>11 && teams[ps-1].go_txdis<0))
  4128. && teams[ps-1].tm_act==RUN_ACT)))
  4129. {
  4130. // Pass ahead...
  4131. pass_ahead(ps,x,y,pass_speed,end_speed,cross);
  4132. }
  4133. else
  4134. {
  4135. init_stand_act(&teams[ps-1]);
  4136. int t=pass_ahead(ps,x,y,pass_speed,end_speed,cross); // Obviously he isn't moving so it will go straight to him!
  4137. }
  4138. }
  4139. }
  4140. /*****************************************************************************
  4141. *****************************************************************************/
  4142. void pass_ball(int ps,char cross)
  4143. {
  4144. inc_pass(ball_poss);
  4145. receiver_a=FALSE;
  4146. receiver_b=FALSE;
  4147. float x,y;
  4148. float d;
  4149. int t;
  4150. // Speed of ball at target!
  4151. float end_speed;
  4152. float pass_speed;
  4153. if (cross)
  4154. {
  4155. new_shot(ball_poss); // Treat crosses as shots at goal!
  4156. // Hit it harder to cross it in...
  4157. end_speed=7;
  4158. }
  4159. else
  4160. end_speed=5;
  4161. if (ps<=0)
  4162. {
  4163. comm_pass=0; // Default short pass...
  4164. // Must pass but no-one to pass to!
  4165. if (teams[ball_poss-1].tm_act==THROW_ACT)
  4166. {
  4167. x=teams[ball_poss-1].tm_xdis*140; // Far forward!
  4168. y=teams[ball_poss-1].tm_ydis*140;
  4169. }
  4170. else
  4171. {
  4172. if (!user_controlled)
  4173. {
  4174. switch(must_pass)
  4175. {
  4176. case(NORMAL_PLAY):
  4177. x=teams[ball_poss-1].tm_xdis*10; // Tap forward!
  4178. y=teams[ball_poss-1].tm_ydis*10;
  4179. end_speed=(actual_spd(&teams[ball_poss-1]))+0.8;
  4180. break;
  4181. case(CORNER_TR):
  4182. case(CORNER_BR):
  4183. x=pitch_len-(prat*15)-ballx;
  4184. y=cntspot_y-bally;
  4185. break;
  4186. case(CORNER_TL):
  4187. case(CORNER_BL):
  4188. x=(prat*15)-ballx;
  4189. y=cntspot_y-bally;
  4190. break;
  4191. case(CENTRE_A):
  4192. case(CENTRE_B):
  4193. x=cntspot_x-ballx;
  4194. y=cntspot_y-bally;
  4195. break;
  4196. case(IF_KICK_A):
  4197. case(IF_KICK_B):
  4198. case(DF_KICK_A):
  4199. case(DF_KICK_B):
  4200. x=setp_kick_x*160; // Pass forward!
  4201. y=setp_kick_y*160;
  4202. break;
  4203. }
  4204. }
  4205. else
  4206. {
  4207. if (spec_kick_type==SPACT_HPASS || spec_kick_type==SPACT_DPASS
  4208. || spec_kick_type==SPACT_FPASS || spec_kick_type==SPACT_TEE_UP)
  4209. {
  4210. // User set-piece actions which should have been for team-mates...
  4211. if (chip_pass)
  4212. {
  4213. x=setp_kick_x*(prat*16);
  4214. y=setp_kick_y*(prat*16);
  4215. }
  4216. else
  4217. {
  4218. x=setp_kick_x*(prat*14);
  4219. y=setp_kick_y*(prat*14);
  4220. }
  4221. d=calc_dist(x,y);
  4222. }
  4223. if (spec_kick_type==SPACT_GRND)
  4224. {
  4225. x=setp_kick_x*(f2_down*prat);
  4226. y=setp_kick_y*(f2_down*prat);
  4227. d=calc_dist(x,y);
  4228. }
  4229. }
  4230. }
  4231. d=calc_dist(x,y);
  4232. }
  4233. if (ps>0)
  4234. {
  4235. x=teams[ps-1].tm_x-ballx;
  4236. y=teams[ps-1].tm_y-bally;
  4237. d=calc_dist(x,y);
  4238. comm_pass=(int)(d/(LONG_PASS_DIST));
  4239. if (want_pass==ps)
  4240. {
  4241. // team-mate cannot stop!
  4242. pass_ahead(ps,x,y,pass_speed,end_speed,cross);
  4243. }
  4244. else
  4245. {
  4246. choose_pass(ps,x,y,pass_speed,end_speed,cross);
  4247. }
  4248. d=calc_dist(x,y);
  4249. }
  4250. // Get acuracy offsets!
  4251. float ac1,ac2;
  4252. af_randomize();
  4253. if ((ps>0) && (ps!=KP_A) && (ps!=KP_B) && want_pass!=ps)
  4254. // He is passing to an on-the-field player...
  4255. {
  4256. // ac1=Direction offset!
  4257. ac1=((rand_range(128-teams[ball_poss-1].tm_ac))*PASS_ACC_ARC)*D2RAD;
  4258. // ac2=Power offset!
  4259. ac2=((float)(rand_range(128-teams[ball_poss-1].tm_ac)))/32;
  4260. if (seed&64)
  4261. ac1=-ac1;
  4262. }
  4263. else
  4264. {
  4265. ac1=0;
  4266. ac2=0;
  4267. }
  4268. if (!match_info.GameType)
  4269. {
  4270. // Arcade Mode...(Passing is always accurate!)
  4271. ac1=0;
  4272. ac2=0;
  4273. }
  4274. float nx,ny,ox,oy;
  4275. ox=x/d;
  4276. oy=y/d;
  4277. nx=(ox*cos(ac1))-(oy*sin(ac1));
  4278. ny=(oy*cos(ac1))+(ox*sin(ac1));
  4279. // New Target (x,y)!
  4280. x=nx*d;
  4281. y=ny*d;
  4282. end_speed-=ac2;
  4283. ball_zspin=0;
  4284. ball_xyspin=0;
  4285. full_xyspin=0;
  4286. swerve=FALSE;
  4287. if ((pass_type!=9) && ((ball_in_hands) || (heading_ball)))
  4288. {
  4289. // need to throw ball!
  4290. heading_ball=FALSE;
  4291. ball_inair=TRUE;
  4292. pass_speed=end_speed+2+(d*(1-AIR_FRICTION));
  4293. ballxdis=pass_speed*x/d;
  4294. ballydis=pass_speed*y/d;
  4295. t=(log((end_speed+2)/pass_speed))/(log(AIR_FRICTION));
  4296. if (!t)
  4297. t=1;
  4298. if (chip_pass)
  4299. // Aim for head...
  4300. ballzdis=((PLAYER_HEIGHT-ballz)/t)+(t/2)*gravity;
  4301. else
  4302. ballzdis=(t/2)*gravity-(ballz/t);
  4303. ball_in_hands=FALSE;
  4304. // Stop run!
  4305. if (teams[ball_poss-1].tm_act==RUN_ACT)
  4306. teams[ball_poss-1].go_cnt=0;
  4307. launch_ball(1); // Set up spin vector.
  4308. cannot_pick_up=-ball_poss;
  4309. }
  4310. else
  4311. {
  4312. if (pass_type==-1 || pass_type==16 || pass_type==17 ||
  4313. chip_pass)
  4314. {
  4315. // need to chip ball!
  4316. ball_inair=TRUE;
  4317. if ((ps<=0) && (chip_pass))
  4318. // Forced chip forward...
  4319. {
  4320. if (spec_kick_type==SPACT_CHIP)
  4321. {
  4322. // Use user power setting...
  4323. ballxdis=setp_bxd;
  4324. ballydis=setp_byd;
  4325. ballzdis=setp_bzd;
  4326. }
  4327. else
  4328. {
  4329. ballxdis=4*x/d;
  4330. ballydis=4*y/d;
  4331. ballzdis=6;
  4332. }
  4333. cannot_pick_up=ball_poss;
  4334. }
  4335. else
  4336. {
  4337. // In air to team-mate...
  4338. pass_speed=end_speed+4+(d*(1-AIR_FRICTION));
  4339. t=(log((end_speed+4)/pass_speed))/(log(AIR_FRICTION));
  4340. ballxdis=pass_speed*x/d;
  4341. ballydis=pass_speed*y/d;
  4342. if (t<0.1)
  4343. t=1;
  4344. cannot_pick_up=ball_poss;
  4345. if (chip_pass)
  4346. // Aim for head...
  4347. ballzdis=((PLAYER_HEIGHT-ballz)/t)+(t/2)*gravity;
  4348. else
  4349. ballzdis=(t/2)*gravity-(ballz/t);
  4350. if (cross)
  4351. {
  4352. ballzdis=((PLAYER_HEIGHT-6-ballz)/t)+(t/2)*gravity;
  4353. }
  4354. if (ballzdis>14)
  4355. ballzdis=14;
  4356. }
  4357. char angle=0;
  4358. launch_ball(seed&1 ? -1:1); // Set up spin vector.
  4359. }
  4360. else
  4361. {
  4362. ball_inair=FALSE;
  4363. pass_speed=end_speed+(d*(1-GRND_FRICTION));
  4364. ballxdis=pass_speed*x/d;
  4365. ballydis=pass_speed*y/d;
  4366. cannot_pick_up=ball_poss;
  4367. ballzdis=0;
  4368. ballz=ball_diam/2;
  4369. ball_xyspin=0;
  4370. ball_zspin=0;
  4371. }
  4372. }
  4373. holder_lose_ball();
  4374. must_pass=FALSE;
  4375. if (ps>0)
  4376. new_interceptor(ps);
  4377. }
  4378. /******************************************************************************
  4379. *****************************************************************************/
  4380. void make_pass(match_player *player,int p,char cross=FALSE)
  4381. {
  4382. kick_type=KT_PASS;
  4383. float sx,sy,sz;
  4384. cross_now=cross;
  4385. receiver=p;
  4386. comm_pass_type=0;
  4387. switch(pass_type)
  4388. {
  4389. // Player kick along ground, ball tweens to contact point and is then released...
  4390. case(3):
  4391. init_kick_act(&teams[ball_poss-1],MC_SIDEPASSL,MCC_SIDEPASS);
  4392. break;
  4393. case(2):
  4394. init_kick_act(&teams[ball_poss-1],MC_DIAGBACKL,MCC_DIAGBACK);
  4395. comm_pass_type=1;
  4396. break;
  4397. case(1):
  4398. init_kick_act(&teams[ball_poss-1],MC_BACKHEELL,MCC_BACKHEEL);
  4399. comm_pass_type=1;
  4400. break;
  4401. case(8):
  4402. init_kick_act(&teams[ball_poss-1],MC_DIAGBACKR,MCC_DIAGBACK);
  4403. comm_pass_type=1;
  4404. break;
  4405. case(7):
  4406. init_kick_act(&teams[ball_poss-1],MC_SIDEPASSR,MCC_SIDEPASS);
  4407. break;
  4408. case(6):
  4409. init_kick_act(&teams[ball_poss-1],MC_DIAGPASSR,MCC_DIAGPASS);
  4410. break;
  4411. case(5):
  4412. init_kick_act(&teams[ball_poss-1],MC_PASSL,MCC_PASS);
  4413. break;
  4414. case(4):
  4415. init_kick_act(&teams[ball_poss-1],MC_DIAGPASSL,MCC_DIAGPASS);
  4416. break;
  4417. case(-1):
  4418. init_kick_act(&teams[ball_poss-1],MC_CHIPL,MCC_CHIP);
  4419. comm_pass_type=2;
  4420. break;
  4421. case(16):
  4422. init_kick_act(&teams[ball_poss-1],MC_CROSSL,MCC_CROSS);
  4423. comm_pass_type=2;
  4424. break;
  4425. case(17):
  4426. init_kick_act(&teams[ball_poss-1],MC_CROSSR,MCC_CROSS);
  4427. comm_pass_type=2;
  4428. break;
  4429. /*
  4430. case(12):
  4431. init_kick_act(&teams[ball_poss-1],MC_THROWL,MCC_THROWL);
  4432. comm_pass_type=2;
  4433. break;
  4434. case(13):
  4435. init_kick_act(&teams[ball_poss-1],MC_THROWS,MCC_THROWS);
  4436. break;
  4437. */
  4438. // Keeper new animation start, ball in limbo until contact...
  4439. case(11):
  4440. init_anim(&teams[ball_poss-1],MC_HALFVOLL);
  4441. // Point at which ball leaves hand!
  4442. // Calculate current mcap offsets for given direction (newdx,newdy)!
  4443. rotate_offs(MC_HALFVOLL,sx,sy,sz,teams[ball_poss-1].tm_xdis,teams[ball_poss-1].tm_ydis);
  4444. ballx=teams[ball_poss-1].tm_x+sx;
  4445. bally=teams[ball_poss-1].tm_y+sy;
  4446. ballz=teams[ball_poss-1].tm_z+sz;
  4447. ball_limbo(teams[ball_poss-1].tm_player,MCC_HALFVOLL);
  4448. teams[ball_poss-1].tm_limbo=1/MC_HALFVOLL_FS;
  4449. pass_ball(receiver,FALSE);
  4450. comm_pass_type=2;
  4451. break;
  4452. case(10):
  4453. init_anim(&teams[ball_poss-1],MC_THROW);
  4454. // Point at which ball leaves hand!
  4455. // Calculate current mcap offsets for given direction (newdx,newdy)!
  4456. rotate_offs(MC_THROW,sx,sy,sz,teams[ball_poss-1].tm_xdis,teams[ball_poss-1].tm_ydis);
  4457. ballx=teams[ball_poss-1].tm_x+sx;
  4458. bally=teams[ball_poss-1].tm_y+sy;
  4459. ballz=teams[ball_poss-1].tm_z+sz;
  4460. ball_limbo(teams[ball_poss-1].tm_player,MCC_THROW);
  4461. teams[ball_poss-1].tm_limbo=1/MC_THROW_FS;
  4462. pass_ball(receiver,FALSE);
  4463. break;
  4464. case(9):
  4465. init_anim(&teams[ball_poss-1],MC_ROLL);
  4466. // Point at which ball leaves hand!
  4467. // Calculate current mcap offsets for given direction (newdx,newdy)!
  4468. rotate_offs(MC_ROLL,sx,sy,sz,teams[ball_poss-1].tm_xdis,teams[ball_poss-1].tm_ydis);
  4469. ballx=teams[ball_poss-1].tm_x+sx;
  4470. bally=teams[ball_poss-1].tm_y+sy;
  4471. ballz=teams[ball_poss-1].tm_z+sz;
  4472. ball_limbo(teams[ball_poss-1].tm_player,MCC_ROLL);
  4473. teams[ball_poss-1].tm_limbo=1/MC_ROLL_FS;
  4474. pass_ball(receiver,FALSE);
  4475. break;
  4476. case(12):
  4477. init_anim(&teams[ball_poss-1],MC_THROWS);
  4478. // Point at which ball leaves hand!
  4479. // Calculate current mcap offsets for given direction (newdx,newdy)!
  4480. rotate_offs(MC_THROWS,sx,sy,sz,teams[ball_poss-1].tm_xdis,teams[ball_poss-1].tm_ydis);
  4481. ballx=teams[ball_poss-1].tm_x+sx;
  4482. bally=teams[ball_poss-1].tm_y+sy;
  4483. ballz=teams[ball_poss-1].tm_z+sz;
  4484. ball_limbo(teams[ball_poss-1].tm_player,MCC_THROWS);
  4485. teams[ball_poss-1].tm_limbo=1/MC_THROWS_FS;
  4486. pass_ball(receiver,FALSE);
  4487. break;
  4488. case(13):
  4489. init_anim(&teams[ball_poss-1],MC_THROWL);
  4490. // Point at which ball leaves hand!
  4491. // Calculate current mcap offsets for given direction (newdx,newdy)!
  4492. rotate_offs(MC_THROWL,sx,sy,sz,teams[ball_poss-1].tm_xdis,teams[ball_poss-1].tm_ydis);
  4493. ballx=teams[ball_poss-1].tm_x+sx;
  4494. bally=teams[ball_poss-1].tm_y+sy;
  4495. ballz=teams[ball_poss-1].tm_z+sz;
  4496. ball_limbo(teams[ball_poss-1].tm_player,MCC_THROWL);
  4497. teams[ball_poss-1].tm_limbo=1/MC_THROWL_FS;
  4498. pass_ball(receiver,FALSE);
  4499. break;
  4500. // Already in appropriate animation...
  4501. case(15):
  4502. // Header!
  4503. fire_ball_off();
  4504. PlayCommentaryMessage(CP_HEAD);
  4505. break;
  4506. case(14):
  4507. // Volley!
  4508. fire_ball_off();
  4509. break;
  4510. }
  4511. }
  4512. /******************************************************************************
  4513. *****************************************************************************/
  4514. void dribble_dir(match_player *player,float &xd,float &yd)
  4515. {
  4516. float x,y,d;
  4517. float rate=actual_spd(player);
  4518. int i;
  4519. char go_that_way=FALSE;
  4520. char a=((seed<64) ? TRUE:FALSE);
  4521. float sina=sin(0.174); // approx. 10 degrees!
  4522. float cosa=cos(0.174);
  4523. float xd1=xd;
  4524. float yd1=yd;
  4525. float xd2=xd;
  4526. float yd2=yd;
  4527. float xo,yo,dif;
  4528. int cnt=0;
  4529. while((!go_that_way) && (drib_opps))
  4530. {
  4531. // Coords of future ball.
  4532. x=ballx+(xd*DRIB_DANGER_AREA/4);
  4533. y=bally+(yd*DRIB_DANGER_AREA/4);
  4534. go_that_way=TRUE;
  4535. for (i=0; i<drib_opps; i++)
  4536. {
  4537. xo=x-opp_dir_tab[i][0];
  4538. yo=y-opp_dir_tab[i][1]; // offset to future ball!
  4539. d=calc_dist(xo,yo);
  4540. dif=(player->tm_xdis*xo/d)+(player->tm_ydis*yo/d);
  4541. d=d*(2-dif);
  4542. if (d<DRIB_DANGER_AREA/2)
  4543. {
  4544. go_that_way=FALSE;
  4545. break;
  4546. }
  4547. }
  4548. if ((x<16) || (x>pitch_len-16) || (y<16) || (y>pitch_wid-16) || (!go_that_way))
  4549. {
  4550. go_that_way=FALSE;
  4551. if (a)
  4552. {
  4553. xd=(xd1*cosa)-(yd1*sina);
  4554. yd=(yd1*cosa)+(xd1*sina);
  4555. xd1=xd;
  4556. yd1=yd;
  4557. a=!a;
  4558. }
  4559. else
  4560. {
  4561. xd=(xd2*cosa)+(yd2*sina);
  4562. yd=(yd2*cosa)-(xd2*sina);
  4563. xd2=xd;
  4564. yd2=yd;
  4565. a=!a;
  4566. }
  4567. if (cnt++==36)
  4568. {
  4569. // No-where to go, so go toward centre!
  4570. xd=cntspot_x-ballx;
  4571. yd=cntspot_y-bally;
  4572. d=calc_dist(xd,yd);
  4573. xd=xd/d;
  4574. yd=yd/d;
  4575. must_pass=TRUE;
  4576. break;
  4577. }
  4578. }
  4579. }
  4580. }
  4581. /******************************************************************************
  4582. *****************************************************************************/
  4583. /*
  4584. int omake_run_a(match_player *player)
  4585. {
  4586. if (player->tm_y>=cntspot_y)
  4587. {
  4588. // DIR 4
  4589. if (ballx<pitch_len-32)
  4590. {
  4591. if ((opp_dir_tab[3]>=0) && (opp_dir_tab[5]>=0))
  4592. {
  4593. if (!opp_dir_tab[4])
  4594. return(4);
  4595. }
  4596. }
  4597. // DIR 5
  4598. if ((ballx<pitch_len-32) && (bally>32))
  4599. {
  4600. if ((opp_dir_tab[6]>=0) && (opp_dir_tab[4]>=0))
  4601. {
  4602. if (!opp_dir_tab[5])
  4603. return(5);
  4604. }
  4605. }
  4606. // DIR 3
  4607. if ((bally<pitch_wid-32) && (ballx<pitch_len-32))
  4608. {
  4609. if ((opp_dir_tab[2]>=0) && (opp_dir_tab[4]>=0))
  4610. {
  4611. if (!opp_dir_tab[3])
  4612. return(3);
  4613. }
  4614. }
  4615. // DIR 6
  4616. if (bally>32)
  4617. {
  4618. if ((opp_dir_tab[7]>=0) && (opp_dir_tab[5]>=0))
  4619. {
  4620. if (!opp_dir_tab[6])
  4621. return(6);
  4622. }
  4623. }
  4624. // DIR 2
  4625. if (bally<pitch_wid-32)
  4626. {
  4627. if ((opp_dir_tab[3]>=0) && (opp_dir_tab[1]>=0))
  4628. {
  4629. if (!opp_dir_tab[2])
  4630. return(2);
  4631. }
  4632. }
  4633. // DIR 7
  4634. if ((bally>32) && (ballx>32))
  4635. {
  4636. if ((opp_dir_tab[0]>=0) && (opp_dir_tab[6]>=0))
  4637. {
  4638. if (!opp_dir_tab[7])
  4639. return(7);
  4640. }
  4641. }
  4642. // DIR 1
  4643. if ((bally<pitch_wid-32) && (ballx>32))
  4644. {
  4645. if ((opp_dir_tab[2]>=0) && (opp_dir_tab[5]>=0))
  4646. {
  4647. if (!opp_dir_tab[1])
  4648. return(1);
  4649. }
  4650. }
  4651. // DIR 0
  4652. if (ballx>32)
  4653. {
  4654. if ((opp_dir_tab[1]>=0) && (opp_dir_tab[7]>=0))
  4655. {
  4656. if (!opp_dir_tab[0])
  4657. return(0);
  4658. }
  4659. }
  4660. }
  4661. else
  4662. {
  4663. // DIR 4
  4664. if (ballx<pitch_len-32)
  4665. {
  4666. if ((opp_dir_tab[3]>=0) && (opp_dir_tab[5]>=0))
  4667. {
  4668. if (!opp_dir_tab[4])
  4669. return(4);
  4670. }
  4671. }
  4672. // DIR 3
  4673. if ((bally<pitch_wid-32) && (ballx<pitch_len-32))
  4674. {
  4675. if ((opp_dir_tab[2]>=0) && (opp_dir_tab[4]>=0))
  4676. {
  4677. if (!opp_dir_tab[3])
  4678. return(3);
  4679. }
  4680. }
  4681. // DIR 5
  4682. if ((ballx<pitch_len-32) && (bally>32))
  4683. {
  4684. if ((opp_dir_tab[6]>=0) && (opp_dir_tab[4]>=0))
  4685. {
  4686. if (!opp_dir_tab[5])
  4687. return(5);
  4688. }
  4689. }
  4690. // DIR 2
  4691. if (bally<pitch_wid-32)
  4692. {
  4693. if ((opp_dir_tab[3]>=0) && (opp_dir_tab[1]>=0))
  4694. {
  4695. if (!opp_dir_tab[2])
  4696. return(2);
  4697. }
  4698. }
  4699. // DIR 6
  4700. if (bally>32)
  4701. {
  4702. if ((opp_dir_tab[7]>=0) && (opp_dir_tab[5]>=0))
  4703. {
  4704. if (!opp_dir_tab[6])
  4705. return(6);
  4706. }
  4707. }
  4708. // DIR 1
  4709. if ((bally<pitch_wid-32) && (ballx>32))
  4710. {
  4711. if ((opp_dir_tab[2]>=0) && (opp_dir_tab[5]>=0))
  4712. {
  4713. if (!opp_dir_tab[1])
  4714. return(1);
  4715. }
  4716. }
  4717. // DIR 7
  4718. if ((bally>32) && (ballx>32))
  4719. {
  4720. if ((opp_dir_tab[0]>=0) && (opp_dir_tab[6]>=0))
  4721. {
  4722. if (!opp_dir_tab[7])
  4723. return(7);
  4724. }
  4725. }
  4726. // DIR 0
  4727. if (ballx>32)
  4728. {
  4729. if ((opp_dir_tab[1]>=0) && (opp_dir_tab[7]>=0))
  4730. {
  4731. if (!opp_dir_tab[0])
  4732. return(0);
  4733. }
  4734. }
  4735. }
  4736. // Go to right corners...
  4737. int y;
  4738. int x=(pitch_len-(prat*5))-ballx;
  4739. if (bally>cntspot_y)
  4740. y=(pitch_wid-(prat*5))-bally;
  4741. else
  4742. y=((prat*5))-bally;
  4743. return(get_dir(x,y));
  4744. }
  4745. */
  4746. /******************************************************************************
  4747. *****************************************************************************/
  4748. /*
  4749. int make_run_b(match_player *player)
  4750. {
  4751. if (player->tm_y>=cntspot_y)
  4752. {
  4753. // DIR 0
  4754. if (ballx>32)
  4755. {
  4756. if ((opp_dir_tab[1]>=0) && (opp_dir_tab[7]>=0))
  4757. {
  4758. if (!opp_dir_tab[0])
  4759. return(0);
  4760. }
  4761. }
  4762. // DIR 7
  4763. if ((bally>32) && (ballx>32))
  4764. {
  4765. if ((opp_dir_tab[0]>=0) && (opp_dir_tab[6]>=0))
  4766. {
  4767. if (!opp_dir_tab[7])
  4768. return(7);
  4769. }
  4770. }
  4771. // DIR 1
  4772. if ((bally<pitch_wid-32) && (ballx>32))
  4773. {
  4774. if ((opp_dir_tab[2]>=0) && (opp_dir_tab[5]>=0))
  4775. {
  4776. if (!opp_dir_tab[1])
  4777. return(1);
  4778. }
  4779. }
  4780. // DIR 6
  4781. if (bally>32)
  4782. {
  4783. if ((opp_dir_tab[7]>=0) && (opp_dir_tab[5]>=0))
  4784. {
  4785. if (!opp_dir_tab[6])
  4786. return(6);
  4787. }
  4788. }
  4789. // DIR 2
  4790. if (bally<pitch_wid-32)
  4791. {
  4792. if ((opp_dir_tab[3]>=0) && (opp_dir_tab[1]>=0))
  4793. {
  4794. if (!opp_dir_tab[2])
  4795. return(2);
  4796. }
  4797. }
  4798. // DIR 5
  4799. if ((ballx<pitch_len-32) && (bally>32))
  4800. {
  4801. if ((opp_dir_tab[6]>=0) && (opp_dir_tab[4]>=0))
  4802. {
  4803. if (!opp_dir_tab[5])
  4804. return(5);
  4805. }
  4806. }
  4807. // DIR 3
  4808. if ((bally<pitch_wid-32) && (ballx<pitch_len-32))
  4809. {
  4810. if ((opp_dir_tab[2]>=0) && (opp_dir_tab[4]>=0))
  4811. {
  4812. if (!opp_dir_tab[3])
  4813. return(3);
  4814. }
  4815. }
  4816. // DIR 4
  4817. if (ballx<pitch_len-32)
  4818. {
  4819. if ((opp_dir_tab[3]>=0) && (opp_dir_tab[5]>=0))
  4820. {
  4821. if (!opp_dir_tab[4])
  4822. return(4);
  4823. }
  4824. }
  4825. }
  4826. else
  4827. {
  4828. // DIR 0
  4829. if (ballx>32)
  4830. {
  4831. if ((opp_dir_tab[1]>=0) && (opp_dir_tab[7]>=0))
  4832. {
  4833. if (!opp_dir_tab[0])
  4834. return(0);
  4835. }
  4836. }
  4837. // DIR 1
  4838. if ((bally<pitch_wid-32) && (ballx>32))
  4839. {
  4840. if ((opp_dir_tab[2]>=0) && (opp_dir_tab[5]>=0))
  4841. {
  4842. if (!opp_dir_tab[1])
  4843. return(1);
  4844. }
  4845. }
  4846. // DIR 7
  4847. if ((bally>32) && (ballx>32))
  4848. {
  4849. if ((opp_dir_tab[0]>=0) && (opp_dir_tab[6]>=0))
  4850. {
  4851. if (!opp_dir_tab[7])
  4852. return(7);
  4853. }
  4854. }
  4855. // DIR 2
  4856. if (bally<pitch_wid-32)
  4857. {
  4858. if ((opp_dir_tab[3]>=0) && (opp_dir_tab[1]>=0))
  4859. {
  4860. if (!opp_dir_tab[2])
  4861. return(2);
  4862. }
  4863. }
  4864. // DIR 6
  4865. if (bally>32)
  4866. {
  4867. if ((opp_dir_tab[7]>=0) && (opp_dir_tab[5]>=0))
  4868. {
  4869. if (!opp_dir_tab[6])
  4870. return(6);
  4871. }
  4872. }
  4873. // DIR 3
  4874. if ((bally<pitch_wid-32) && (ballx<pitch_len-32))
  4875. {
  4876. if ((opp_dir_tab[2]>=0) && (opp_dir_tab[4]>=0))
  4877. {
  4878. if (!opp_dir_tab[3])
  4879. return(3);
  4880. }
  4881. }
  4882. // DIR 5
  4883. if ((ballx<pitch_len-32) && (bally>32))
  4884. {
  4885. if ((opp_dir_tab[6]>=0) && (opp_dir_tab[4]>=0))
  4886. {
  4887. if (!opp_dir_tab[5])
  4888. return(5);
  4889. }
  4890. }
  4891. // DIR 4
  4892. if (ballx<pitch_len-32)
  4893. {
  4894. if ((opp_dir_tab[3]>=0) && (opp_dir_tab[5]>=0))
  4895. {
  4896. if (!opp_dir_tab[4])
  4897. return(4);
  4898. }
  4899. }
  4900. }
  4901. // Go to left corners...
  4902. int y;
  4903. int x=(prat*5)-ballx;
  4904. if (bally>cntspot_y)
  4905. y=(pitch_wid-(prat*5))-bally;
  4906. else
  4907. y=((prat*5))-bally;
  4908. return(get_dir(x,y));
  4909. }
  4910. */
  4911. /******************************************************************************
  4912. *****************************************************************************/
  4913. void avoid_boundary(match_player *player)
  4914. {
  4915. // Just run toward opponents goal...
  4916. float x;
  4917. float y=cntspot_y;
  4918. if (player->tm_player<12)
  4919. // Goal B...
  4920. x=pitch_len;
  4921. else
  4922. // Goal A...
  4923. x=0;
  4924. init_run_act(player,x,y,TRUE);
  4925. action="Dribble";
  4926. }
  4927. /******************************************************************************
  4928. *****************************************************************************/
  4929. void go_dribble(match_player *player,float x,float y)
  4930. {
  4931. x=player->tm_x+(x*500);
  4932. y=player->tm_y+(y*500);
  4933. // Make target (x,y) greater than intention range!
  4934. init_run_act(player,x,y,TRUE);
  4935. action="Dribble";
  4936. }
  4937. /******************************************************************************
  4938. *****************************************************************************/
  4939. void make_run(match_player *player)
  4940. {
  4941. float x,y,px;
  4942. if (player->tm_player<12)
  4943. // Team A
  4944. {
  4945. px=player->tm_x-(pitch_len-prat*10);
  4946. if (px>0)
  4947. {
  4948. if (px<prat*10)
  4949. x=cos(px*PI/(prat*20));
  4950. else
  4951. x=0;
  4952. y=sqrt(1-(x*x));
  4953. if (player->tm_y>cntspot_y)
  4954. y=-y;
  4955. }
  4956. else
  4957. {
  4958. x=1;
  4959. y=0;
  4960. }
  4961. get_opp_dir_tab(player->tm_player);
  4962. dribble_dir(player,x,y);
  4963. go_dribble(player,x,y);
  4964. }
  4965. else
  4966. // Team B
  4967. {
  4968. px=(prat*10)-player->tm_x;
  4969. if (px>0)
  4970. {
  4971. if (px<prat*10)
  4972. x=-cos(px*PI/(prat*20));
  4973. else
  4974. x=0;
  4975. y=sqrt(1-(x*x));
  4976. if (player->tm_y>cntspot_y)
  4977. y=-y;
  4978. }
  4979. else
  4980. {
  4981. x=-1;
  4982. y=0;
  4983. }
  4984. get_opp_dir_tab(player->tm_player);
  4985. dribble_dir(player,x,y);
  4986. go_dribble(player,x,y);
  4987. }
  4988. reset_ideas(player);
  4989. player->int_move=I_DRIBBLE;
  4990. player->int_cnt=18-(player->tm_flair/8);
  4991. player->go_cnt=19-(player->tm_flair/8);
  4992. // Where will he be at end of run!
  4993. x=player->tm_x+(player->go_txdis*player->go_cnt);
  4994. y=player->tm_y+(player->go_tydis*player->go_cnt);
  4995. if (x>pitch_len || x<0 || y<0 || y>pitch_wid)
  4996. {
  4997. // Running off pitch!!!
  4998. avoid_boundary(player);
  4999. }
  5000. }
  5001. /******************************************************************************
  5002. *****************************************************************************/
  5003. int run_decide(match_player *player)
  5004. {
  5005. int opps=(player->tm_flair)-(opponents_near_holder*16);
  5006. if (opps<=0)
  5007. opps=MIN_RUN_PROB;
  5008. if (seed<opps)
  5009. return(TRUE);
  5010. else
  5011. return(FALSE);
  5012. }
  5013. /******************************************************************************
  5014. *****************************************************************************/
  5015. void make_punt(match_player *player)
  5016. {
  5017. if (ball_in_hands && (player->tm_player==KP_A || player->tm_player==KP_B))
  5018. {
  5019. punt_ball(player);
  5020. }
  5021. else
  5022. {
  5023. kick_type=KT_PUNT;
  5024. pass_type=100;
  5025. init_kick_act(player,MC_SHOOTL,MCC_SHOOT);
  5026. }
  5027. }
  5028. /*****************************************************************************
  5029. *****************************************************************************/
  5030. void punt_ball(match_player *player)
  5031. {
  5032. inc_pass(ball_poss);
  5033. receiver_a=FALSE;
  5034. receiver_b=FALSE;
  5035. cannot_pick_up=ball_poss;
  5036. must_punt=FALSE;
  5037. char inh=ball_in_hands;
  5038. ball_inair=TRUE;
  5039. int r=rand_range(129-player->tm_ac);
  5040. ballxdis=player->tm_xdis*(6+player->tm_pow/8);
  5041. ballydis=player->tm_ydis*(6+player->tm_pow/8);
  5042. if (heading_ball==2)
  5043. ballzdis=4; // Diving Header!
  5044. else
  5045. if (heading_ball==1)
  5046. ballzdis=6; // Standing or jumping header!
  5047. else
  5048. if (heading_ball==3)
  5049. ballzdis=8;
  5050. else
  5051. {
  5052. if (player->tm_player!=KP_A && player->tm_player!=KP_B)
  5053. ballzdis=10; // Kick!
  5054. else
  5055. ballzdis=12; // Kick!
  5056. }
  5057. action="Punt";
  5058. new_shot(player->tm_player); // Treat as shot just in case!
  5059. if (inh && (player->tm_player==KP_A || player->tm_player==KP_B))
  5060. {
  5061. init_anim(player,MC_KICKOUT);
  5062. // Kick out ball from hands!
  5063. // Calculate current mcap offsets for given direction (newdx,newdy)!
  5064. float sx,sy,sz;
  5065. rotate_offs(MC_KICKOUT,sx,sy,sz,player->tm_xdis,player->tm_ydis);
  5066. ballx=player->tm_x+sx;
  5067. bally=player->tm_y+sy;
  5068. ballz=player->tm_z+sz;
  5069. ball_limbo(player->tm_player,MCC_KICKOUT);
  5070. player->tm_limbo=1/MC_KICKOUT_FS;
  5071. launch_ball(1); // Set up spin vector.
  5072. }
  5073. holder_lose_ball();
  5074. }
  5075. /******************************************************************************
  5076. *****************************************************************************/
  5077. int punt_decide(match_player *player)
  5078. {
  5079. float x,y,x_factor;
  5080. int def;
  5081. x=player->tm_xdis;
  5082. y=player->tm_ydis;
  5083. if (player->tm_player>11)
  5084. {
  5085. if (x<0 && (ballx<pitch_len && ballx>cntspot_x) && ((seed<-(x*128)) || must_punt))
  5086. def=ballx-cntspot_x;
  5087. else
  5088. return(FALSE);
  5089. }
  5090. else
  5091. {
  5092. if (x>0 && (ballx>0 && ballx<cntspot_x) && ((seed<(x*128)) || must_punt))
  5093. def=cntspot_x-ballx;
  5094. else
  5095. return(FALSE);
  5096. }
  5097. if (def>(cntspot_x-(10*prat)))
  5098. def+=128;
  5099. // if (((user_player1==player->tm_player) || (user_player2==player->tm_player)) && (def>prat*20))
  5100. if (((player->control) && (def>prat*20)) || must_punt)
  5101. def=128*4;
  5102. // User must punt!
  5103. if (def/3>seed || (first_time_it && (def*((float)player->tm_cont/64)>seed)))
  5104. // His position is defensive.
  5105. {
  5106. int opps=(opponents_near_holder*40)-(player->tm_flair);
  5107. if (opps<MIN_PUNT_PROB)
  5108. opps=MIN_PUNT_PROB;
  5109. if (user_controlled)
  5110. // User must punt!
  5111. opps=128;
  5112. // Facing away from goal would help...
  5113. if (player->tm_player<12)
  5114. x_factor=(1+x)/2;
  5115. else
  5116. x_factor=-(x-1)/2;
  5117. if (((seed<opps*x_factor) && (x_factor>0.5)) || must_punt)
  5118. return(TRUE);
  5119. }
  5120. return(FALSE);
  5121. }
  5122. /******************************************************************************
  5123. *****************************************************************************/
  5124. int head_punt_decide(match_player *player)
  5125. {
  5126. float x,y;
  5127. int def;
  5128. x=player->tm_xdis;
  5129. y=player->tm_ydis;
  5130. if (player->tm_player>11)
  5131. {
  5132. if (x<0)
  5133. def=ballx-cntspot_x;
  5134. else
  5135. return(FALSE);
  5136. }
  5137. else
  5138. {
  5139. if (x>0)
  5140. def=cntspot_x-ballx;
  5141. else
  5142. return(FALSE);
  5143. }
  5144. if (def>(cntspot_x-(10*prat)))
  5145. def+=128;
  5146. if (def/4>seed)
  5147. // His position is defensive.
  5148. {
  5149. cannot_pick_up=-player->tm_player;
  5150. holder_lose_ball();
  5151. ball_inair=TRUE;
  5152. ballxdis=(((float)(player->tm_pow))/32.0)*x+(x*6);
  5153. ballydis=0;
  5154. ballzdis=10;
  5155. action="Punt";
  5156. init_anim(player,MC_S_HEAD);
  5157. launch_ball(1); // Set up spin vector.
  5158. play_fx(PS_HARDHEAD,ballx,bally);
  5159. return(TRUE);
  5160. }
  5161. return(FALSE);
  5162. }
  5163. /******************************************************************************
  5164. *****************************************************************************/
  5165. float get_power()
  5166. {
  5167. return ((float)(setp_power+16)/2);
  5168. }
  5169. /******************************************************************************
  5170. *****************************************************************************/
  5171. float get_traj()
  5172. {
  5173. return ((float)setp_hgt/3);
  5174. }
  5175. /******************************************************************************
  5176. *****************************************************************************/
  5177. void aim_shot_at_goal(match_player *player,float &xoff,float &yoff,int rng)
  5178. {
  5179. float x,y,d;
  5180. float gx,gy,area;
  5181. int side;
  5182. if (player->control && pass_type==-1)
  5183. {
  5184. // User selects direction!
  5185. x=player->tm_xdis;
  5186. y=player->tm_ydis;
  5187. float d=calc_dist(x*128,y*128);
  5188. xoff=(x*rng*128)/d;
  5189. yoff=(y*rng*128)/d;
  5190. }
  5191. else
  5192. {
  5193. // Auto direction select based on (accuracy)!
  5194. int keeper;
  5195. if (player->tm_player<12)
  5196. {
  5197. keeper=12;
  5198. gx=pitch_len;
  5199. }
  5200. else
  5201. {
  5202. keeper=1;
  5203. gx=0;
  5204. }
  5205. // get offset to keeper (x,y)!
  5206. x=teams[keeper-1].tm_x-ballx;
  5207. y=teams[keeper-1].tm_y-bally;
  5208. // get offset to goal line through keeper (gx,gy)!
  5209. gx=gx-ballx;
  5210. gy=y*gx/x;
  5211. area=gy+bally-cntspot_y;
  5212. if (area>0)
  5213. // More area above keeper!
  5214. {
  5215. if ((player->tm_flair/2)+63>seed)
  5216. // Aim above!
  5217. {
  5218. area=(cntspot_y+area)-top_post_y;
  5219. side=-1;
  5220. }
  5221. else
  5222. // Aim below!
  5223. {
  5224. area=0; // Doesn't aim for large gap!
  5225. side=1;
  5226. }
  5227. }
  5228. else
  5229. // More area below keeper!
  5230. {
  5231. if ((player->tm_flair/2)+63>seed)
  5232. // Aim below!
  5233. {
  5234. area=bot_post_y-(cntspot_y+area);
  5235. side=1;
  5236. }
  5237. else
  5238. // Aim above!
  5239. {
  5240. area=0; // Doesn't aim for large gap!
  5241. side=-1;
  5242. }
  5243. }
  5244. xoff=gx;
  5245. // Calculate Accuracy offset!
  5246. int acc_off=(seed*(8+(128-player->tm_ac)))/128;
  5247. if (seed&4)
  5248. acc_off=-(acc_off*rng/(20.0*prat));
  5249. else
  5250. acc_off=(acc_off*rng/(20.0*prat));
  5251. // Now. Direct at chosen target.
  5252. if (side>0)
  5253. yoff=bot_post_y-bally-16+acc_off;
  5254. else
  5255. yoff=top_post_y-bally+16+acc_off;
  5256. }
  5257. // Shot Speed...
  5258. int shot_var=seed;
  5259. af_randomize();
  5260. shot_var=(shot_var+seed)/2; // Favour 64.
  5261. shot_speed=6+(4*rng/(prat*60))+(9.0*(player->tm_pow+shot_var)/150);
  5262. if (pass_type>0 && pass_type<5 && pass_type>5)
  5263. // Just a tap in...
  5264. shot_speed/=2;
  5265. // Initialise swerve on ball!
  5266. af_randomize();
  5267. ball_zspin=0;
  5268. // full_zspin=(float)player->tm_ac/(rng-sqrt(rng*4));
  5269. swerve=0;
  5270. spin_ball=0;
  5271. max_sw_factor=0;
  5272. #ifdef EURO96
  5273. if (rng>=10.0*prat && !user_controlled && !penalty_shot)
  5274. #else
  5275. if ((rng>=10.0*prat) && (!user_controlled))
  5276. #endif
  5277. {
  5278. af_randomize();
  5279. full_xyspin=(float)(seed)/128*MAX_XY_CSW*player->tm_flair/128;
  5280. full_zspin=((float)(seed)/128*MAX_Z_CSW*player->tm_flair/128);
  5281. spin_ball=0;
  5282. float d=calc_dist(xoff,yoff);
  5283. af_randomize();
  5284. // Time to reach (xoff,yoff)...
  5285. float t=(d/shot_speed*(1-AIR_FRICTION));
  5286. if (t>=1)
  5287. t=0.9998;
  5288. t=(log(1.0-t))/(log(AIR_FRICTION)); // How long to go (d) dist!
  5289. if (xoff<0)
  5290. // Going Left
  5291. {
  5292. if (side<0)
  5293. // Left top.
  5294. {
  5295. if (xoff<yoff)
  5296. swerve=-1;
  5297. else
  5298. swerve=1;
  5299. }
  5300. // Left bot.
  5301. else
  5302. {
  5303. if (xoff<yoff)
  5304. swerve=1;
  5305. else
  5306. swerve=-1;
  5307. }
  5308. }
  5309. else
  5310. // Going Right
  5311. {
  5312. if (side<0)
  5313. // Right top.
  5314. {
  5315. if (xoff>yoff)
  5316. swerve=1;
  5317. else
  5318. swerve=-1;
  5319. }
  5320. // Right bot.
  5321. else
  5322. {
  5323. if (xoff>yoff)
  5324. swerve=-1;
  5325. else
  5326. swerve=1;
  5327. }
  5328. }
  5329. // Calculate Offset swerve angle...
  5330. float a=0;
  5331. for (int n=1; n<=t; n++)
  5332. {
  5333. a+=full_xyspin*(SW_HOLD_FACTOR/(SW_HOLD_FACTOR+n));
  5334. }
  5335. a=(a/2.2)+(d/4800);
  5336. x=xoff/d;
  5337. y=yoff/d;
  5338. if (swerve<0)
  5339. {
  5340. xoff=d*((x*cos(a))-(y*sin(a)));
  5341. yoff=d*((y*cos(a))+(x*sin(a)));
  5342. }
  5343. else
  5344. {
  5345. xoff=d*((x*cos(a))+(y*sin(a)));
  5346. yoff=d*((y*cos(a))-(x*sin(a)));
  5347. }
  5348. ballzdis=7.2+(rng/180)+(((float)seed/64)*(128-player->tm_ac)/128)
  5349. +((float)(full_zspin)/2);
  5350. spin_cnt=((ballzdis/gravity))+(ABS(full_zspin));
  5351. }
  5352. else
  5353. {
  5354. if (newk_shot)
  5355. {
  5356. shot_speed=get_power();
  5357. ballzdis=get_traj();
  5358. xoff=player->tm_xdis*10;
  5359. yoff=player->tm_ydis*10;
  5360. ballxdis=xoff;
  5361. ballydis=yoff;
  5362. }
  5363. else
  5364. {
  5365. if (drive_shot)
  5366. {
  5367. shot_speed+=5;
  5368. ballzdis=7-(shot_speed/10);
  5369. }
  5370. else
  5371. {
  5372. if ((area>prat*6) && (rng<prat*15))
  5373. // Goal-keeper has left a large gap and attacker is close in!
  5374. ballzdis=1.8+(rng/180)+(((float)seed/64)*(128-player->tm_ac)/128); // Place it low!
  5375. else
  5376. ballzdis=5.2+(rng/180)+(((float)seed/64)*(128-player->tm_ac)/128);
  5377. }
  5378. }
  5379. }
  5380. if (user_controlled)
  5381. {
  5382. if (drive_shot)
  5383. after_touch_on=FALSE;
  5384. else
  5385. after_touch_on=user_controlled;
  5386. full_xyspin=MAX_XY_USW*player->tm_flair/128;
  5387. full_zspin=MAX_Z_USW*player->tm_flair/128;
  5388. d=calc_dist(ballxdis,ballydis);
  5389. shoot_x=ballxdis/d;
  5390. shoot_y=ballydis/d; // Shoot direction vectors(for after-touch).
  5391. }
  5392. spin_cnt=0;
  5393. }
  5394. /******************************************************************************
  5395. *****************************************************************************/
  5396. void make_shoot(match_player *player)
  5397. {
  5398. kick_type=KT_SHOOT;
  5399. switch(pass_type)
  5400. {
  5401. // Straight-forward shot!
  5402. case(-1):
  5403. init_kick_act(player,MC_SHOOTL,MCC_SHOOT);
  5404. break;
  5405. // Player kick along ground, ball tweens to contact point and is then released...
  5406. case(3):
  5407. init_kick_act(&teams[ball_poss-1],MC_SIDEPASSL,MCC_SIDEPASS);
  5408. break;
  5409. case(2):
  5410. init_kick_act(&teams[ball_poss-1],MC_DIAGBACKL,MCC_DIAGBACK);
  5411. break;
  5412. case(1):
  5413. init_kick_act(&teams[ball_poss-1],MC_BACKHEELL,MCC_BACKHEEL);
  5414. break;
  5415. case(8):
  5416. init_kick_act(&teams[ball_poss-1],MC_DIAGBACKR,MCC_DIAGBACK);
  5417. break;
  5418. case(7):
  5419. init_kick_act(&teams[ball_poss-1],MC_SIDEPASSR,MCC_SIDEPASS);
  5420. break;
  5421. case(6):
  5422. init_kick_act(&teams[ball_poss-1],MC_DIAGPASSR,MCC_DIAGPASS);
  5423. break;
  5424. case(5):
  5425. init_kick_act(&teams[ball_poss-1],MC_PASSL,MCC_PASS);
  5426. break;
  5427. case(4):
  5428. init_kick_act(&teams[ball_poss-1],MC_DIAGPASSL,MCC_DIAGPASS);
  5429. break;
  5430. }
  5431. }
  5432. /******************************************************************************
  5433. *****************************************************************************/
  5434. void shoot_ball(match_player *player)
  5435. {
  5436. receiver_a=FALSE;
  5437. receiver_b=FALSE;
  5438. if (say_names)
  5439. {
  5440. if (!ball_poss)
  5441. PlayTeamSample(real_player(last_touch),2);
  5442. else
  5443. PlayTeamSample(real_player(ball_poss),2);
  5444. }
  5445. // Fire shot!
  5446. float goal_x;
  5447. if (ball_poss<=11)
  5448. goal_x=pitch_len;
  5449. else
  5450. goal_x=0;
  5451. float xoff=goal_x-ballx;
  5452. float yoff=cntspot_y-bally;
  5453. float range=calc_dist(xoff,yoff);
  5454. if (range<1)
  5455. range=1;
  5456. holder_lose_ball();
  5457. ball_inair=TRUE;
  5458. new_shot(player->tm_player);
  5459. real_shot=TRUE;
  5460. af_randomize();
  5461. aim_shot_at_goal(player,xoff,yoff,range);
  5462. if (heading_ball==2)
  5463. ballzdis=ballzdis*.5; // Diving Header!
  5464. else
  5465. if (heading_ball==3)
  5466. ballzdis=1;
  5467. if (ballzdis>0.6)
  5468. ball_inair=TRUE;
  5469. float d=calc_dist(xoff,yoff);
  5470. ballxdis=shot_speed*xoff/d;
  5471. ballydis=shot_speed*yoff/d;
  5472. action="Shoot";
  5473. cannot_pick_up=player->tm_player;
  5474. drive_shot=FALSE;
  5475. newk_shot=FALSE;
  5476. launch_ball(0); // Set up spin vector.
  5477. inc_shot(player->tm_player);
  5478. user_scorer=player->control;
  5479. }
  5480. /******************************************************************************
  5481. *****************************************************************************/
  5482. int shoot_decide(match_player *player)
  5483. {
  5484. flag=FALSE;
  5485. float goal_x;
  5486. if (ball_poss<=11)
  5487. goal_x=pitch_len;
  5488. else
  5489. goal_x=0;
  5490. float xoff=goal_x-ballx;
  5491. float yoff=cntspot_y-bally;
  5492. int range=calc_dist(xoff,yoff);
  5493. if (range<1)
  5494. range=1;
  5495. if (player->tm_srng)
  5496. {
  5497. if (user_controlled)
  5498. {
  5499. // Big shot!
  5500. flag=TRUE; // in shooting range!
  5501. pass_type=-1;
  5502. }
  5503. else
  5504. {
  5505. if (plr_facing_goal(xoff,yoff,player))
  5506. {
  5507. // Big shot!
  5508. flag=TRUE; // in shooting range!
  5509. pass_type=-1;
  5510. }
  5511. else
  5512. {
  5513. pass_type=in_kicking_range(player,xoff,yoff);
  5514. if (user_controlled && pass_type==5)
  5515. pass_type=-1;
  5516. if (!pass_type)
  5517. flag=FALSE;
  5518. else
  5519. flag=TRUE; // any dir shot.
  5520. }
  5521. }
  5522. }
  5523. if (flag)
  5524. {
  5525. // He's in range!
  5526. if ((!user_controlled) && (!must_shoot))
  5527. {
  5528. int opps=(10000/range)+(opponents_near_holder*(16+((128-player->tm_flair)/4)))-(16+(player->tm_flair/3));
  5529. if (opps<MIN_SHOOT_PROB)
  5530. opps=MIN_SHOOT_PROB;
  5531. if (seed>opps && !first_time_it)
  5532. return(FALSE);
  5533. }
  5534. return(TRUE);
  5535. }
  5536. if (player->tm_leave) // He cannot touch ball again!
  5537. must_pass=TRUE;
  5538. return(FALSE);
  5539. }
  5540. /******************************************************************************
  5541. *****************************************************************************/
  5542. int head_shoot_decide(match_player *player)
  5543. {
  5544. flag=FALSE;
  5545. float goal_x;
  5546. if (player->tm_player<=11)
  5547. goal_x=pitch_len;
  5548. else
  5549. goal_x=0;
  5550. float xoff=goal_x-ballx;
  5551. float yoff=cntspot_y-bally;
  5552. int range=calc_dist(xoff,yoff);
  5553. if (range<1)
  5554. range=1;
  5555. if (in_header_rng)
  5556. {
  5557. // He's in range!
  5558. int opps=(5000/range)+(opponents_near_holder*32);
  5559. if (opps<MIN_SHOOT_PROB)
  5560. opps=MIN_SHOOT_PROB;
  5561. if (seed>opps)
  5562. return(FALSE);
  5563. // Fire shot!
  5564. cannot_pick_up=-ball_poss;
  5565. holder_lose_ball();
  5566. ball_inair=TRUE;
  5567. new_shot(player->tm_player);
  5568. aim_shot_at_goal(player,xoff,yoff,range);
  5569. float d=calc_dist(xoff,yoff);
  5570. stop_ball_spin();
  5571. ballzdis=ballzdis-1.4;
  5572. ballxdis=(xoff*(12+(player->tm_pow)/4))/(d*3.4);
  5573. ballydis=(yoff*(12+(player->tm_pow)/4))/(d*3.4);
  5574. init_anim(player,MC_S_HEAD);
  5575. launch_ball(0); // Set up spin vector.
  5576. play_fx(PS_HARDHEAD,ballx,bally);
  5577. return(TRUE);
  5578. }
  5579. return(FALSE);
  5580. }
  5581. /******************************************************************************
  5582. *****************************************************************************/
  5583. int sort_less_than(const void *op1, const void *op2)
  5584. {
  5585. const int p1=*(const int *)op1;
  5586. const int p2=*(const int *)op2;
  5587. return(p1-p2);
  5588. }
  5589. /******************************************************************************
  5590. *****************************************************************************/
  5591. int sort_greater_than(const void *op1, const void *op2)
  5592. {
  5593. const int p1=*(const int *)op1;
  5594. const int p2=*(const int *)op2;
  5595. return(p2-p1);
  5596. }
  5597. /******************************************************************************
  5598. *****************************************************************************/
  5599. int sort_soonest(const void *op1, const void *op2)
  5600. {
  5601. const short p1=*(const short *)op1;
  5602. const short p2=*(const short *)op2;
  5603. return(p1-p2);
  5604. }
  5605. /******************************************************************************
  5606. *****************************************************************************/
  5607. float kicking_dist(match_player *player,float x,float y,float d)
  5608. {
  5609. // Calculate back-heel distance...
  5610. float dist=MIN_PASS_DIST+(float)player->tm_pow/3.6;
  5611. // Calculate difference range of 2(ahead) to 1(behind)...
  5612. float dif=(player->tm_xdis*x/d)+(player->tm_ydis*y/d);
  5613. float kd=dist*(2.0+dif)/2;
  5614. return(kd);
  5615. }
  5616. /******************************************************************************
  5617. *****************************************************************************/
  5618. int in_kicking_range(match_player *player,float x,float y)
  5619. {
  5620. float d=calc_dist(x,y);
  5621. x=x/d;
  5622. y=y/d;
  5623. // Calculate back-heel distance...
  5624. float dist=MIN_PASS_DIST+(float)player->tm_pow/3.6;
  5625. // Calculate difference range of 2(ahead) to 1(behind)...
  5626. float dif=(player->tm_xdis*x)+(player->tm_ydis*y);
  5627. float kd=dist*(1.5+(dif/2));
  5628. if (dif>KICK_AHEAD_ANG)
  5629. {
  5630. // Straight ahead...
  5631. if (d>dist*4)
  5632. return(0);
  5633. else
  5634. if (d>dist*2)
  5635. return(-1);
  5636. else
  5637. return(5);
  5638. }
  5639. else
  5640. {
  5641. // Different dir...
  5642. if (d>kd)
  5643. return(FALSE);
  5644. else
  5645. {
  5646. float nx=(x*player->tm_xdis)+(y*player->tm_ydis);
  5647. float ny=(y*player->tm_xdis)-(x*player->tm_ydis);
  5648. return(1+get_dir(nx,ny));
  5649. }
  5650. }
  5651. }
  5652. /******************************************************************************
  5653. *****************************************************************************/
  5654. int can_i_pass(match_player *player)
  5655. {
  5656. int p=pass_type;
  5657. if (p>6 && p<9)
  5658. p=p-6;
  5659. else
  5660. if (p>0 && p<4)
  5661. p=4-p;
  5662. else
  5663. return(pass_type); // Forward or diagonal pass requires no special ability!
  5664. if (player->tm_flair>(p*seed*0.5))
  5665. return(pass_type); // Skillfull enough to see move!
  5666. else
  5667. return(FALSE);
  5668. }
  5669. /******************************************************************************
  5670. *****************************************************************************/
  5671. int pass_decide(match_player *player,char cross=FALSE)
  5672. {
  5673. char angle;
  5674. int passee_tab[10][3];
  5675. int passees=0;
  5676. int vm;
  5677. if ((!player->tm_act==THROW_ACT) && (ball_inair))
  5678. vm=VISION_MULT*2/3;
  5679. else
  5680. vm=VISION_MULT;
  5681. int x,y,d,t;
  5682. if (player->tm_player>11)
  5683. t=22-1; //team B
  5684. else
  5685. t=11-1; //team A
  5686. /************/
  5687. if (want_pass)
  5688. {
  5689. // Try guy shouting for pass...
  5690. int i=want_pass-1;
  5691. if ((ball_poss!=KP_A && ball_poss!=KP_B)
  5692. || !kopp_around(teams[want_pass-1].tm_x,teams[want_pass-1].tm_y,want_pass))
  5693. {
  5694. if ((teams[i].control)
  5695. || (plr_facing(teams[i].tm_x-ballx,teams[i].tm_y-bally,player))
  5696. || (set_piece_on && player->tm_act!=THROW_ACT))
  5697. {
  5698. x=teams[i].tm_x-ballx;
  5699. y=teams[i].tm_y-bally;
  5700. d=calc_dist(x,y);
  5701. if ((ball_in_hands) && (d<30.0*prat))
  5702. // In throwing range!
  5703. {
  5704. passee_tab[passees][1]=i+1;
  5705. passee_tab[passees++][2]=pass_type;
  5706. // Add prospective passee!
  5707. }
  5708. else
  5709. {
  5710. pass_type=in_kicking_range(player,x,y);
  5711. pass_type=can_i_pass(player);
  5712. if ((pass_type) && (!ball_in_hands))
  5713. // Can kick that distance...
  5714. {
  5715. passee_tab[passees][1]=i+1;
  5716. passee_tab[passees++][2]=pass_type;
  5717. // Add prospective passee!
  5718. }
  5719. else
  5720. {
  5721. if (cross && !ball_in_hands &&
  5722. d<=(player->tm_vis*vm*1.4) && d>(prat*8))
  5723. {
  5724. if ((ball_poss<12 && (teams[i].tm_x)>pitch_len-(prat*18))
  5725. || (ball_poss>11 && (teams[i].tm_x)<prat*18))
  5726. {
  5727. // In eighteen yard box!
  5728. angle=cross_angle(teams[ball_poss-1].tm_xdis,
  5729. teams[ball_poss-1].tm_ydis,x,y);
  5730. if (angle==1)
  5731. // Kicking at 90 degrees left...
  5732. {
  5733. pass_type=16;
  5734. passee_tab[passees][1]=i+1;
  5735. passee_tab[passees++][2]=pass_type;
  5736. }
  5737. else
  5738. {
  5739. if (angle==2)
  5740. // Kicking at 90 degrees right...
  5741. {
  5742. pass_type=17;
  5743. passee_tab[passees][1]=i+1;
  5744. passee_tab[passees++][2]=pass_type;
  5745. }
  5746. }
  5747. }
  5748. }
  5749. }
  5750. }
  5751. }
  5752. }
  5753. }
  5754. /************/
  5755. for (int i=t; i>t-11; i--)
  5756. {
  5757. if (player->tm_player!=i+1)
  5758. // Not man on ball!
  5759. {
  5760. if ((ball_poss!=KP_A && ball_poss!=KP_B)
  5761. || !kopp_around(teams[i].tm_x,teams[i].tm_y,i))
  5762. {
  5763. if ((teams[i].tm_act<=TURN_ACT) && (teams[i].guy_on>0) && (want_pass-1!=i))
  5764. // Not Busy!
  5765. {
  5766. x=teams[i].tm_x-ballx;
  5767. y=teams[i].tm_y-bally;
  5768. d=calc_dist(x,y);
  5769. pass_type=in_kicking_range(player,x,y);
  5770. pass_type=can_i_pass(player);
  5771. if ((pass_type && !ball_in_hands) || ((ball_in_hands) && (d<20.0*prat)))
  5772. // Can kick reach him...
  5773. {
  5774. if (d<=(player->tm_vis*vm))
  5775. // In visible range!
  5776. {
  5777. if ((d/2<(MIN_PASS_DIST+(float)player->tm_pow/3.6) && !ball_in_hands) || angle_of_vis(player,x,y,teams[i].tm_dist,cross))
  5778. // Within angle of vision 90!
  5779. {
  5780. if (!(((i==KP_A-1) || (i==KP_B-1)) && (teams[i].tm_dist<KP_MIN_PASS_DIST)))
  5781. {
  5782. passee_tab[passees][1]=i+1;
  5783. passee_tab[passees++][2]=pass_type;
  5784. }
  5785. // Add prospective passee!
  5786. }
  5787. }
  5788. }
  5789. else
  5790. {
  5791. if (cross && !ball_in_hands &&
  5792. d<=(player->tm_vis*vm*1.4) && d>(prat*8))
  5793. {
  5794. if ((ball_poss<12 && (teams[i].tm_x)>pitch_len-(prat*18))
  5795. || (ball_poss>11 && (teams[i].tm_x)<prat*18))
  5796. {
  5797. angle=cross_angle(teams[ball_poss-1].tm_xdis,
  5798. teams[ball_poss-1].tm_ydis,x,y);
  5799. if (angle==1)
  5800. // Kicking at 90 degrees left...
  5801. {
  5802. pass_type=16;
  5803. passee_tab[passees][1]=i+1;
  5804. passee_tab[passees++][2]=pass_type;
  5805. }
  5806. else
  5807. {
  5808. if (angle==2)
  5809. // Kicking at 90 degrees right...
  5810. {
  5811. pass_type=17;
  5812. passee_tab[passees][1]=i+1;
  5813. passee_tab[passees++][2]=pass_type;
  5814. }
  5815. }
  5816. }
  5817. }
  5818. }
  5819. }
  5820. }
  5821. }
  5822. }
  5823. //********************************//
  5824. // Passee table has been created. //
  5825. //********************************//
  5826. // Give preference values to each candidate...
  5827. // Low being best!
  5828. int pas=0;
  5829. if (passees)
  5830. {
  5831. int team_mate;
  5832. if (!user_controlled)
  5833. {
  5834. // Computer decision only...
  5835. int opps;
  5836. float tmx;
  5837. float px=player->tm_x;
  5838. for (int p=0; p<passees; p++)
  5839. {
  5840. team_mate=passee_tab[p][1]-1;
  5841. // Get opponents near team-mate...
  5842. opps=opp_around((int)teams[team_mate].tm_x,
  5843. (int)teams[team_mate].tm_y,team_mate);
  5844. // Passer takes this into consideration...
  5845. opps=64+(opps*(64+(player->tm_flair/2)));
  5846. // Optimum passing distance is around 10 yards...
  5847. // Anything below should start to lessen likelyhood of passing...
  5848. if (teams[team_mate].tm_dist<OPTIMUM_PASS)
  5849. opps+=(OPTIMUM_PASS-teams[team_mate].tm_dist);
  5850. // But, am I under threat and have to get rid of ball???
  5851. if (!set_piece_on && match_mode>GOAL_KICK_BR && match_mode<GOAL_KICK_TL)
  5852. opps-=opponents_near_holder*(32+(player->tm_flair/2));
  5853. else
  5854. opps-=64;
  5855. // Is he making run???
  5856. if (want_pass==(team_mate+1))
  5857. opps-=teams[team_mate].tm_flair;
  5858. // If in shooting range then less chance of passing...(greed factor)!
  5859. if (player->tm_srng)
  5860. opps+=GREED_FACTOR;
  5861. tmx=teams[team_mate].tm_x;
  5862. if (team_mate>11)
  5863. // Team B...
  5864. if (tmx>px)
  5865. // Passing back...
  5866. opps+=(tmx-px)*player->tm_flair/128;
  5867. else
  5868. // Passing forward, less difference...
  5869. opps+=((tmx-px)/5)*player->tm_flair/128;
  5870. else
  5871. // Team A...
  5872. if (tmx<px)
  5873. // Passing back...
  5874. opps+=(px-tmx)*player->tm_flair/128;
  5875. else
  5876. // Passing forward, less difference...
  5877. opps+=((px-tmx)/5)*player->tm_flair/128;
  5878. // The more flair less likelyhood of passing especially if opps near passee!
  5879. int op_p;
  5880. if (team_mate<11)
  5881. op_p=11;
  5882. else
  5883. op_p=0;
  5884. // Get vectors for pass!
  5885. float tx=teams[team_mate].tm_x-ballx;
  5886. float ty=teams[team_mate].tm_y-bally;
  5887. float td=teams[team_mate].tm_dist;
  5888. float ang=0;
  5889. float ox,oy,od,a;
  5890. tx=tx/td;
  5891. ty=ty/td;
  5892. // Any opponents in path off prospective passed ball?
  5893. for (int o=op_p; o<op_p+11; o++)
  5894. {
  5895. if ((teams[o].guy_on) && (teams[o].tm_dist<td*1.25)) // Inside pass range!
  5896. {
  5897. ox=teams[o].tm_x-ballx;
  5898. oy=teams[o].tm_y-bally;
  5899. od=teams[o].tm_dist;
  5900. ox=ox/od;
  5901. oy=oy/od;
  5902. a=((tx*ox)+(ty*oy));
  5903. if (a>0)
  5904. {
  5905. a=a*a*(96+(player->tm_flair/2))*td/od;
  5906. // ang+=a*(player->tm_flair/64);
  5907. ang+=a*(player->tm_flair/32);
  5908. }
  5909. }
  5910. }
  5911. if (passee_tab[p][2]==16 || passee_tab[p][2]==17)
  5912. // Crossing over opps...
  5913. {
  5914. opps+=ang/5;
  5915. opps=opps/4;
  5916. }
  5917. else
  5918. opps+=ang;
  5919. passee_tab[p][0]=opps; // Set preference level!
  5920. af_randomize();
  5921. // If straight ahead pass and need to chip...
  5922. {
  5923. if (passee_tab[p][2]==5 && (ang>seed/2 || (user_controlled && chip_pass)))
  5924. // Chip over...
  5925. passee_tab[p][2]=-1;
  5926. }
  5927. }
  5928. }
  5929. else
  5930. {
  5931. // User preference is for distance in facing direction only...
  5932. float tx,ty,dif;
  5933. float px=player->tm_x;
  5934. float py=player->tm_y;
  5935. float xf=player->tm_xdis;
  5936. float yf=player->tm_ydis;
  5937. float min_d=2000;
  5938. short pr=-1;
  5939. for (int p=0; p<passees; p++)
  5940. {
  5941. passee_tab[p][0]=100;
  5942. team_mate=passee_tab[p][1]-1;
  5943. tx=teams[team_mate].tm_x-px;
  5944. ty=teams[team_mate].tm_y-py;
  5945. if (plr_facing(tx,ty,player))
  5946. {
  5947. // Facing towards team-mate...
  5948. d=calc_dist(tx,ty);
  5949. if (d<min_d)
  5950. {
  5951. // Closest...
  5952. min_d=d;
  5953. pr=p;
  5954. }
  5955. }
  5956. }
  5957. if (pr>=0)
  5958. passee_tab[pr][0]=0;
  5959. }
  5960. // Sort passee table in order of preference...
  5961. qsort(passee_tab,passees,sizeof(int)*3,sort_less_than);
  5962. if (user_controlled)
  5963. {
  5964. // Take first team-mate on table...
  5965. pas=passee_tab[0][1];
  5966. pass_type=passee_tab[0][2];
  5967. }
  5968. else
  5969. {
  5970. // Random selection weighted towards first in table...
  5971. int chance;
  5972. pas=0;
  5973. for (int p=0; p<passees; p++)
  5974. {
  5975. af_randomize();
  5976. chance=passee_tab[p][0];
  5977. if (chance<MAX_PASS_PROB)
  5978. chance=MAX_PASS_PROB;
  5979. else
  5980. if (chance>MIN_PASS_PROB)
  5981. chance=MIN_PASS_PROB;
  5982. if (set_piece_on)
  5983. chance=chance/2;
  5984. if (seed>chance)
  5985. {
  5986. // Choose this guy to pass to!
  5987. pas=passee_tab[p][1];
  5988. pass_type=passee_tab[p][2];
  5989. p=passees+1;
  5990. }
  5991. }
  5992. }
  5993. if (!pas && (must_pass || user_controlled))
  5994. // Must choose!
  5995. {
  5996. pas=passee_tab[0][1];
  5997. pass_type=passee_tab[0][2];
  5998. }
  5999. }
  6000. else
  6001. // Absolutely no one to pass to...
  6002. {
  6003. if ((must_pass) || (user_controlled))
  6004. pas=0;
  6005. }
  6006. must_pass=FALSE;
  6007. if (pas>0)
  6008. {
  6009. // He is passing to someone...
  6010. d=calc_dist(teams[pas-1].tm_x-ballx,teams[pas-1].tm_y-bally);
  6011. if (ball_in_hands && (player->tm_player==KP_A || player->tm_player==KP_B))
  6012. {
  6013. if (opp_around(teams[pas-1].tm_x,teams[pas-1].tm_y,pas))
  6014. // Don't pass it out... (opponents around!)
  6015. pas=0;
  6016. else
  6017. // Keeper must throw or something...
  6018. if (d<prat*10)
  6019. pass_type=9; // Roll it.
  6020. else
  6021. if (d<prat*20)
  6022. pass_type=10; // Throw it.
  6023. else
  6024. pass_type=11; // Halfvoll it.
  6025. }
  6026. else
  6027. {
  6028. if ((ball_in_hands) && (teams[ball_poss-1].tm_act==THROW_ACT))
  6029. {
  6030. // Player must throw...
  6031. if (d<prat*15)
  6032. pass_type=12; // Throw short.
  6033. else
  6034. pass_type=13; // Throw Long.
  6035. }
  6036. else
  6037. {
  6038. if (heading_ball)
  6039. pass_type=15;
  6040. }
  6041. }
  6042. }
  6043. return(pas);
  6044. }
  6045. /******************************************************************************
  6046. *****************************************************************************/
  6047. void process_comments()
  6048. {
  6049. if (want_pass_stat!=last_touch)
  6050. {
  6051. // His team_mate does not have ball anymore...
  6052. if (want_pass)
  6053. {
  6054. teams[want_pass-1].tm_comm=0;
  6055. teams[want_pass-1].tm_ccnt=0;
  6056. reset_ideas(&teams[want_pass-1]);
  6057. }
  6058. }
  6059. }
  6060. /******************************************************************************
  6061. *****************************************************************************/
  6062. void init_speech(int p,int comm,int t)
  6063. {
  6064. speech_tab[p-1].say=comm;
  6065. if (t)
  6066. speech_tab[p-1].cnt=t;
  6067. else
  6068. speech_tab[p-1].cnt=SPEECH_SECS*game_speed;
  6069. }
  6070. /******************************************************************************
  6071. *****************************************************************************/
  6072. void process_speech()
  6073. {
  6074. for (int i=1; i<players+3; i++)
  6075. {
  6076. if (speech_tab[i-1].cnt)
  6077. {
  6078. speech_tab[i-1].cnt--;
  6079. }
  6080. }
  6081. }
  6082. /******************************************************************************
  6083. *****************************************************************************/
  6084. void player_comment(match_player *player)
  6085. {
  6086. if (player->tm_comm)
  6087. {
  6088. if ((!(--player->tm_ccnt)) || (player->tm_act>TURN_ACT))
  6089. {
  6090. player->tm_comm=0;
  6091. if (want_pass==player->tm_player)
  6092. want_pass=0;
  6093. }
  6094. }
  6095. }
  6096. /******************************************************************************
  6097. *****************************************************************************/
  6098. void tackle_decide(match_player *player)
  6099. {
  6100. }
  6101. /******************************************************************************
  6102. *****************************************************************************/
  6103. void steal_decide(match_player *player)
  6104. {
  6105. }
  6106. /******************************************************************************
  6107. *****************************************************************************/
  6108. void block_decide(match_player *player)
  6109. {
  6110. }
  6111. /******************************************************************************
  6112. *****************************************************************************/
  6113. void user_free_ball(match_player *player)
  6114. {
  6115. player->tm_stopped=FALSE;
  6116. }
  6117. /******************************************************************************
  6118. *****************************************************************************/
  6119. void other_interceptor(match_player *player)
  6120. {
  6121. if (receiver_a==player->tm_player)
  6122. receiver_a=FALSE;
  6123. if (receiver_b==player->tm_player)
  6124. receiver_b=FALSE;
  6125. player->tm_notme=1+player->tm_flair/16;
  6126. }
  6127. /******************************************************************************
  6128. *****************************************************************************/
  6129. void free_ball(match_player *player)
  6130. {
  6131. player->tm_stopped=FALSE;
  6132. if ((!dead_ball_cnt) && (!player->tm_leave))
  6133. {
  6134. if (!ball_out_of_play)
  6135. {
  6136. if ((player->tm_player==KP_A) || (player->tm_player==KP_B))
  6137. {
  6138. // Goal Keeper...
  6139. if ((player->tm_player==KP_A && keeper_a_in_box)
  6140. || (player->tm_player==KP_B && keeper_b_in_box))
  6141. if (shot_pending>0 && !shot_acknowledged && player->tm_dist<prat*50)
  6142. {
  6143. if (cannot_pick_up<=0 || ((player->tm_player<12 && cannot_pick_up>11)
  6144. || (player->tm_player>11 && cannot_pick_up<12)))
  6145. #ifdef EURO96
  6146. // This looks silly but leave for time being...
  6147. if (penalty_shot && user_controlled)
  6148. {
  6149. if (uf1 || uf2)
  6150. go_to_save_path(player);
  6151. }
  6152. else
  6153. go_to_save_path(player);
  6154. #else
  6155. go_to_save_path(player);
  6156. #endif
  6157. }
  6158. else
  6159. {
  6160. if (player->tm_dist<80 && ball_inair)
  6161. {
  6162. // Ball is quite close...
  6163. go_to_save_path(player);
  6164. }
  6165. }
  6166. }
  6167. if ((!penalty_game) && (player->tm_act!=SAVE_ACT) && (player->int_move!=I_SAVE_WAIT))
  6168. {
  6169. if ((thinking(player)) && (player->tm_act<=TURN_ACT))
  6170. {
  6171. if (player->tm_off)
  6172. // In offside position, must get out...
  6173. {
  6174. run_back(player);
  6175. }
  6176. }
  6177. if (!interceptor_a)
  6178. {
  6179. if (near_path_a==player->tm_player)
  6180. {
  6181. if (go_to_path(near_path_a))
  6182. // other_interceptor(player);
  6183. // else
  6184. {
  6185. if (auto_users_a && !player->control)
  6186. {
  6187. {
  6188. reselect_a();
  6189. user_conts(player);
  6190. }
  6191. }
  6192. }
  6193. }
  6194. }
  6195. if (!interceptor_b)
  6196. {
  6197. if (near_path_b==player->tm_player)
  6198. {
  6199. if (go_to_path(near_path_b))
  6200. // other_interceptor(player);
  6201. // else
  6202. {
  6203. if (auto_users_b && !player->control)
  6204. {
  6205. {
  6206. reselect_b();
  6207. user_conts(player);
  6208. }
  6209. }
  6210. }
  6211. }
  6212. }
  6213. }
  6214. }
  6215. }
  6216. }
  6217. /******************************************************************************
  6218. *****************************************************************************/
  6219. void out_of_vis(match_player *player)
  6220. {
  6221. }
  6222. /******************************************************************************
  6223. *****************************************************************************/
  6224. void range_flags(match_player *player)
  6225. {
  6226. float x=player->tm_x;
  6227. float y=player->tm_y;
  6228. float d;
  6229. if (player->tm_player>11)
  6230. // B
  6231. {
  6232. d=calc_dist(x,cntspot_y-y);
  6233. }
  6234. else
  6235. // A
  6236. {
  6237. d=calc_dist(pitch_len-x,cntspot_y-y);
  6238. }
  6239. if (d<MIN_HEADER_RNG+(prat*player->tm_pow/8))
  6240. in_header_rng=TRUE;
  6241. else
  6242. in_header_rng=FALSE;
  6243. if (d<(MIN_SHOOT_DIST+((float)player->tm_pow*3)))
  6244. in_shot_rng=TRUE;
  6245. else
  6246. in_shot_rng=FALSE;
  6247. }
  6248. /******************************************************************************
  6249. *****************************************************************************/
  6250. // Is guy with ball in "crossing area".
  6251. // Which is a diagonal line from goal post to nearest sideline.
  6252. void cross_pos(match_player *player)
  6253. {
  6254. in_cross_area=FALSE;
  6255. if (bally>bot_post_y)
  6256. {
  6257. if (player->tm_player>11)
  6258. {
  6259. if (ballx<(bally-bot_post_y))
  6260. // Within diagonal from bot. left post to sideline!
  6261. in_cross_area=TRUE;
  6262. }
  6263. else
  6264. {
  6265. if ((pitch_len-ballx)<(bally-bot_post_y))
  6266. // Within diagonal from bot. right post to sideline!
  6267. in_cross_area=TRUE;
  6268. }
  6269. }
  6270. else
  6271. {
  6272. if (bally<top_post_y)
  6273. {
  6274. if (player->tm_player>11)
  6275. {
  6276. if (ballx<(top_post_y-bally))
  6277. // Within diagonal from top left post to sideline!
  6278. in_cross_area=TRUE;
  6279. }
  6280. else
  6281. {
  6282. if ((pitch_len-ballx)<(top_post_y-bally))
  6283. // Within diagonal from top right post to sideline!
  6284. in_cross_area=TRUE;
  6285. }
  6286. }
  6287. }
  6288. }
  6289. /******************************************************************************
  6290. *****************************************************************************/
  6291. void set_pos_flags(match_player *player)
  6292. {
  6293. cross_pos(player);
  6294. range_flags(player);
  6295. }
  6296. /******************************************************************************
  6297. *****************************************************************************/
  6298. void user_got_ball(match_player *player)
  6299. {
  6300. int p=0;
  6301. set_pos_flags(player);
  6302. if (player->tm_act==STAND_ACT)
  6303. user_spec_kick(player);
  6304. else
  6305. {
  6306. if (uf2 && um)
  6307. // Pass in dir!
  6308. {
  6309. int p=(pass_decide(player,in_cross_area));
  6310. if (pass_type==16 || pass_type==17)
  6311. make_pass(player,p,TRUE);
  6312. else
  6313. {
  6314. if (!p)
  6315. pass_type=5; // Forward tap...
  6316. spec_kick_type=SPACT_FPASS;
  6317. setp_kick_x=player->tm_xdis;
  6318. setp_kick_y=player->tm_ydis;
  6319. make_pass(player,p,FALSE);
  6320. }
  6321. }
  6322. else
  6323. {
  6324. if (uf1 && um)
  6325. // Try shooting...
  6326. {
  6327. if (shoot_decide(player))
  6328. make_shoot(player);
  6329. else
  6330. // Try punt...
  6331. {
  6332. if (punt_decide(player))
  6333. make_punt(player);
  6334. else
  6335. // Try high pass to head...
  6336. {
  6337. chip_pass=TRUE;
  6338. int p=(pass_decide(player,FALSE));
  6339. if (p && (pass_type==16 || pass_type==17 || pass_type==-1))
  6340. make_pass(player,p,TRUE);
  6341. else
  6342. {
  6343. p=0;
  6344. chip_pass=FALSE;
  6345. pass_type=-1; // Forward tap...
  6346. spec_kick_type=SPACT_FPASS;
  6347. setp_kick_x=player->tm_xdis;
  6348. setp_kick_y=player->tm_ydis;
  6349. make_pass(player,p,FALSE);
  6350. }
  6351. }
  6352. }
  6353. }
  6354. }
  6355. }
  6356. /*
  6357. else
  6358. {
  6359. if (must_punt)
  6360. if (punt_decide(player))
  6361. make_punt(player);
  6362. else
  6363. {
  6364. if (uf1)
  6365. {
  6366. // He has pressed front fire button (1)!
  6367. // PUNT!
  6368. if (punt_decide(player))
  6369. make_punt(player);
  6370. else
  6371. {
  6372. // SHOOT!
  6373. if (player->tm_srng)
  6374. {
  6375. shoot_decide(player);
  6376. make_shoot(player);
  6377. }
  6378. else
  6379. {
  6380. must_pass=TRUE;
  6381. chip_pass=TRUE;
  6382. int p=pass_decide(player,FALSE);
  6383. make_pass(player,p,FALSE);
  6384. }
  6385. }
  6386. }
  6387. else
  6388. {
  6389. if (uf2)
  6390. {
  6391. // He has pressed top fire button (2)!
  6392. must_pass=TRUE;
  6393. // CROSS!
  6394. if (in_cross_area)
  6395. {
  6396. p=(pass_decide(player,TRUE));
  6397. if (p)
  6398. make_pass(player,p,TRUE);
  6399. }
  6400. if (!p)
  6401. {
  6402. // PASS!
  6403. p=(pass_decide(player,FALSE));
  6404. if (p)
  6405. make_pass(player,p,FALSE);
  6406. }
  6407. }
  6408. }
  6409. }
  6410. }
  6411. }
  6412. */
  6413. set_piece_on=FALSE;
  6414. }
  6415. /******************************************************************************
  6416. *****************************************************************************/
  6417. void got_ball(match_player *player)
  6418. {
  6419. int p=0;
  6420. if ((player->tm_player==KP_A) || (player->tm_player==KP_B))
  6421. {
  6422. /****************
  6423. ** Goal-Keeper **
  6424. ****************/
  6425. // PUNT!
  6426. if (punt_decide(player))
  6427. make_punt(player);
  6428. else
  6429. {
  6430. // PASS!
  6431. int p=(pass_decide(player));
  6432. if (p)
  6433. make_pass(player,p);
  6434. else
  6435. {
  6436. if ((player->tm_player==KP_A && keeper_a_in_box)
  6437. || (player->tm_player==KP_B && keeper_b_in_box))
  6438. {
  6439. // Can pick ball up...
  6440. if (!ball_in_hands)
  6441. {
  6442. if ((cannot_pick_up<=0)
  6443. || (cannot_pick_up<12 && ball_poss>11 && keeper_b_in_box)
  6444. || (cannot_pick_up>11 && ball_poss<12 && keeper_a_in_box))
  6445. {
  6446. if (opp_around(ballx,bally,player->tm_player))
  6447. {
  6448. holder_lose_ball();
  6449. keep_dive=TRUE;
  6450. go_to_save_path(player,TRUE);
  6451. }
  6452. else
  6453. init_pickup_act(player);
  6454. }
  6455. else
  6456. {
  6457. if (player->tm_poss)
  6458. must_punt=TRUE;
  6459. if (punt_decide(player))
  6460. make_punt(player);
  6461. else
  6462. // RUN!
  6463. make_run(player);
  6464. }
  6465. }
  6466. }
  6467. else
  6468. {
  6469. // Can't touch ball with hands...
  6470. must_punt=TRUE;
  6471. }
  6472. }
  6473. }
  6474. }
  6475. else
  6476. {
  6477. /***********
  6478. ** PLAYER **
  6479. ***********/
  6480. // Not taking throw!
  6481. set_pos_flags(player);
  6482. // SHOOT!
  6483. if (shoot_decide(player))
  6484. make_shoot(player);
  6485. else
  6486. {
  6487. // CROSS!
  6488. if (in_cross_area)
  6489. {
  6490. p=(pass_decide(player,TRUE));
  6491. if (p)
  6492. if (pass_type==16 || pass_type==17)
  6493. make_pass(player,p,TRUE);
  6494. else
  6495. make_pass(player,p,FALSE);
  6496. }
  6497. if (!p)
  6498. {
  6499. // PASS!
  6500. p=(pass_decide(player));
  6501. if (p)
  6502. make_pass(player,p);
  6503. else
  6504. {
  6505. // PUNT!
  6506. if (punt_decide(player))
  6507. make_punt(player);
  6508. else
  6509. {
  6510. // RUN!
  6511. make_run(player);
  6512. }
  6513. }
  6514. }
  6515. }
  6516. }
  6517. set_piece_on=FALSE;
  6518. }
  6519. /******************************************************************************
  6520. *****************************************************************************/
  6521. int help_chance(match_player *player)
  6522. {
  6523. int f=64+(player->tm_flair/2);
  6524. float r,xd;
  6525. // Less calculated range if pass is to be made up-field...
  6526. if (player->tm_player>11)
  6527. // Team B...
  6528. {
  6529. xd=player->tm_x-ballx;
  6530. if (xd>0)
  6531. xd=xd*2;
  6532. }
  6533. else
  6534. // Team A...
  6535. {
  6536. xd=player->tm_x-ballx;
  6537. if (xd<0)
  6538. xd=xd*2;
  6539. }
  6540. r=calc_dist(xd,bally-player->tm_y)/(prat*2);
  6541. int help;
  6542. if (support_me)
  6543. help=512-(r*r);
  6544. else
  6545. help=32+(opponents_near_holder*80*f/128)
  6546. -(opp_around(player->tm_x,player->tm_y,player->tm_player)*64*f/128)
  6547. -(r*r);
  6548. // Dead ball situation...
  6549. return(help);
  6550. }
  6551. /******************************************************************************
  6552. *****************************************************************************/
  6553. void we_have_ball(match_player *player)
  6554. {
  6555. if (player->tm_player!=KP_A && player->tm_player!=KP_B && !player->tm_stopped
  6556. && match_mode!=PEN_KICK_A && match_mode!=PEN_KICK_B)
  6557. {
  6558. if ((thinking(player)) && (player->tm_act<=TURN_ACT))
  6559. {
  6560. if (player->tm_off)
  6561. // In offside position, must get out...
  6562. {
  6563. run_back(player);
  6564. }
  6565. else
  6566. {
  6567. if (!want_pass)
  6568. {
  6569. int help=help_chance(player);
  6570. if (help<MIN_HELP_CHANCE)
  6571. help=MIN_HELP_CHANCE;
  6572. if (seed<=help)
  6573. // Ask for Pass!
  6574. {
  6575. if (player->tm_dist<CALL_DIST)
  6576. // if (angle_of_vis(player,ballx-player->tm_x,bally-player->tm_y,player->tm_dist,FALSE))
  6577. {
  6578. want_pass=player->tm_player;
  6579. want_pass_stat=ball_poss;
  6580. player->tm_ccnt=40;
  6581. player->tm_comm=-SAY_PASS;
  6582. reset_ideas(player);
  6583. player->int_move=I_RUN_ON;
  6584. player->int_cnt=40;
  6585. if (in_cross_area)
  6586. {
  6587. float x=player->tm_x;
  6588. float y=player->tm_y;
  6589. int i=player->tm_player;
  6590. if ((i<12) && (x>(pitch_len-(prat*15))) && (y>(cntspot_y-(prat*18)))
  6591. && (y<(cntspot_y+(prat*18)))
  6592. && (teams[i].tm_dist>(prat*20)))
  6593. player->tm_comm=-SAY_CROSS;
  6594. if ((i>11) && (x<(prat*15)) && (y>(cntspot_y-(prat*18)))
  6595. && (y<(cntspot_y+(prat*18)))
  6596. && (teams[i].tm_dist>(prat*20)))
  6597. player->tm_comm=-SAY_CROSS;
  6598. }
  6599. // Run towards opponents penalty spot...
  6600. float x,y,d;
  6601. if (player->tm_player<12)
  6602. x=pitch_len-ballx;
  6603. else
  6604. x=-ballx;
  6605. y=cntspot_y-bally;
  6606. d=calc_dist(x,y);
  6607. // How far is half way to goal...
  6608. float kd=kicking_dist(&teams[ball_poss-1],x,y,d)-(prat*2);
  6609. if (d/2<kd)
  6610. init_run_act(player,ballx+x/2,bally+y/2,FALSE);
  6611. else
  6612. init_run_act(player,ballx+(x/d*kd),bally+(y/d*kd),FALSE);
  6613. player->int_cnt=player->go_cnt;
  6614. player->tm_ccnt=player->go_cnt;
  6615. }
  6616. else
  6617. {
  6618. if (!support_me)
  6619. {
  6620. player->tm_ccnt=40;
  6621. player->tm_comm=-SAY_GIVE;
  6622. }
  6623. }
  6624. }
  6625. }
  6626. }
  6627. }
  6628. }
  6629. }
  6630. /******************************************************************************
  6631. *****************************************************************************/
  6632. int in_close(match_player *player)
  6633. {
  6634. if (player->tm_dist<DRIB_DANGER_AREA)
  6635. return(TRUE);
  6636. else
  6637. return(FALSE);
  6638. }
  6639. /*****************************************************************************
  6640. *****************************************************************************/
  6641. int can_close_down(match_player *player)
  6642. {
  6643. int p=player->tm_player;
  6644. if ((nearest_a==p) || (nearest_b==p))
  6645. return(TRUE);
  6646. else
  6647. return(FALSE);
  6648. }
  6649. /*****************************************************************************
  6650. *****************************************************************************/
  6651. void close_him_down(match_player *player)
  6652. {
  6653. player->int_move=I_CLOSE_DOWN;
  6654. player->int_cnt=(player->tm_flair/4);
  6655. if (!go_to_path(player->tm_player))
  6656. other_interceptor(player);
  6657. action="Close Down";
  6658. }
  6659. /*****************************************************************************
  6660. *****************************************************************************/
  6661. void force_error(match_player *player)
  6662. {
  6663. if ((player->tm_player<12 && !auto_users_a)
  6664. || (player->tm_player>11 && !auto_users_b))
  6665. {
  6666. // No team users so computer must control this guy...
  6667. if (player->tm_dist<STEAL_DIST || teams[ball_poss-1].tm_act==TACKLE_ACT)
  6668. {
  6669. if (!go_to_path(player->tm_player))
  6670. other_interceptor(player);
  6671. // else
  6672. // player->int_move=I_STEAL;
  6673. }
  6674. else
  6675. {
  6676. int chance=32;
  6677. if (player->tm_player<12)
  6678. // The further up the park, the more chance of direct tackling!
  6679. chance-=((pitch_len-player->tm_x)/48);
  6680. else
  6681. chance-=(player->tm_x/48);
  6682. if (chance<=seed && teams[ball_poss-1].tm_act!=TACKLE_ACT
  6683. && teams[ball_poss-1].int_move!=I_GET_UP)
  6684. get_tack_path(player);
  6685. else
  6686. go_to_between(player->tm_player); // get yourself between him and goal!
  6687. }
  6688. }
  6689. }
  6690. /*****************************************************************************
  6691. *****************************************************************************/
  6692. void forceful_retrieve(match_player *player)
  6693. {
  6694. if ((player->tm_player<12 && !auto_users_a)
  6695. || (player->tm_player>11 && !auto_users_b))
  6696. {
  6697. // No team users so computer must control this guy...
  6698. get_tack_path(player);
  6699. }
  6700. }
  6701. /******************************************************************************
  6702. *****************************************************************************/
  6703. void go_to_side(match_player *player)
  6704. // Send player to the side off opponent with ball...
  6705. {
  6706. // His intention is to intercept ball.
  6707. // Therefore his flair determines no. of turns before rethink!
  6708. int ff=33-(player->tm_flair/4);
  6709. player->int_move=I_INTERCEPT; // Intercept ball!
  6710. player->int_cnt=ff; // Flair factor.
  6711. float dx=teams[ball_poss-1].tm_xdis;
  6712. float dy=teams[ball_poss-1].tm_ydis;
  6713. float x=(ballx-player->tm_x)/player->tm_dist; // vector to ball...
  6714. float y=(bally-player->tm_y)/player->tm_dist;
  6715. // Which side to go to...???
  6716. if ((x*dy)>(y*dx))
  6717. {
  6718. x=-dy; // 90 degrees clockwise...
  6719. y=dx;
  6720. }
  6721. else
  6722. {
  6723. x=dy; // 90 degrees anti-clockwise...
  6724. y=-dx;
  6725. }
  6726. x=ballx+(x*prat);
  6727. y=bally+(y*prat);
  6728. init_run_act(player,x,y,TRUE); //Go to path point!
  6729. }
  6730. /******************************************************************************
  6731. *****************************************************************************/
  6732. void go_to_between(int p_num)
  6733. // Send player(p_num) to intersection point between ball path and goal centre.
  6734. // If he cannot meet ball then best try!
  6735. {
  6736. int x,y,z,d;
  6737. float px=teams[p_num-1].tm_x;
  6738. float py=teams[p_num-1].tm_y;
  6739. float goal_x;
  6740. int rate=actual_spd(&teams[p_num-1]);
  6741. action="Between";
  6742. if (p_num<12)
  6743. goal_x=0;
  6744. else
  6745. goal_x=pitch_len;
  6746. // His intention is to intercept ball.
  6747. // Therefore his flair determines no. of turns before rethink!
  6748. int ff=33-(teams[p_num-1].tm_flair/4);
  6749. teams[p_num-1].int_move=I_INTERCEPT; // Intercept ball!
  6750. teams[p_num-1].int_cnt=ff; // Flair factor.
  6751. for (int i=1; i<50; i++)
  6752. {
  6753. x=ball_pred_tab[i][0];
  6754. y=ball_pred_tab[i][1];
  6755. z=ball_pred_tab[i][2];
  6756. d=calc_dist(goal_x-x,cntspot_y-y);
  6757. if (d<1)
  6758. d=1;
  6759. x=x+(((goal_x-x)*BETWEEN_DIST)/d);
  6760. y=y+(((cntspot_y-y)*BETWEEN_DIST)/d);
  6761. if (z<=PLAYER_HEIGHT)
  6762. {
  6763. d=calc_dist(x-px,y-py);
  6764. // d=(int)(((float)d)/rate); //How many steps?
  6765. d=get_there_time(p_num,x,y); //How many steps?
  6766. if (d<=i)
  6767. // He can get there in time!
  6768. {
  6769. init_run_act(&teams[p_num-1],x,y,TRUE); //Go to path point!
  6770. i=60; // End For Loop!
  6771. }
  6772. }
  6773. }
  6774. if (i<60)
  6775. // He cant intersect!
  6776. init_run_act(&teams[p_num-1],x,y,FALSE); // run toward last.
  6777. }
  6778. /******************************************************************************
  6779. *****************************************************************************/
  6780. void user_opp_has_ball(match_player *player)
  6781. {
  6782. if (uf1)
  6783. // Tackle opp.
  6784. {
  6785. user_init_tackle(player);
  6786. }
  6787. else
  6788. {
  6789. if (uf2)
  6790. // Steal from opp.
  6791. {
  6792. if (player->tm_dist<(STEAL_DIST/4))
  6793. {
  6794. init_steal_act(player);
  6795. }
  6796. #ifdef EURO96
  6797. else
  6798. // Burst_of_speed...
  6799. {
  6800. if (!burst_timer[user_controlled-1]--)
  6801. burst_timer[user_controlled-1]=REAL_SPEED;
  6802. else
  6803. if (!burst_timer[user_controlled-1])
  6804. burst_timer[user_controlled-1]=-1;
  6805. }
  6806. #endif
  6807. }
  6808. else
  6809. burst_timer[user_controlled-1]=0;
  6810. }
  6811. }
  6812. /******************************************************************************
  6813. *****************************************************************************/
  6814. void opp_has_ball(match_player *player)
  6815. {
  6816. if ((player->tm_player==KP_A) || (player->tm_player==KP_B))
  6817. {
  6818. /****************
  6819. ** Goal-Keeper **
  6820. ****************/
  6821. if (player->tm_player<12)
  6822. // KP_A...
  6823. {
  6824. if ((keeper_a_in_box) && (player->tm_dist<DIVE_FEET_DIST) && (seed>player->tm_flair))
  6825. // Can dive for ball...
  6826. {
  6827. keep_dive=TRUE;
  6828. go_to_save_path(player,TRUE);
  6829. }
  6830. }
  6831. else
  6832. // KP_B...
  6833. {
  6834. if ((keeper_b_in_box) && (player->tm_dist<DIVE_FEET_DIST) && (seed>player->tm_flair))
  6835. // Can dive for ball...
  6836. {
  6837. keep_dive=TRUE;
  6838. go_to_save_path(player,TRUE);
  6839. }
  6840. }
  6841. }
  6842. {
  6843. /***********
  6844. ** PLAYER **
  6845. ***********/
  6846. if ((ball_in_hands) || (ball_out_of_play))
  6847. // Don't tackle keeper directly!
  6848. {
  6849. }
  6850. else
  6851. {
  6852. if ((player->tm_pos) && (player->tm_pos<=close_in_number)
  6853. && ((player->tm_player!=KP_A) && (player->tm_player!=KP_B))
  6854. || (player->tm_pos==1))
  6855. {
  6856. // There's not too many guys going for opponent with ball!
  6857. if (in_close(player))
  6858. // I am close enough to hassle!
  6859. {
  6860. short d=get_facing_opp_dir(player);
  6861. if (d==-1)
  6862. {
  6863. // He has his back to me!
  6864. if ((ball_speed<1) && ((seed&4)
  6865. || (player->tm_player>11 && ballx<cntspot_x)
  6866. || (player->tm_player<12 && ballx>cntspot_x)))
  6867. // Try and go round a bit...
  6868. go_to_side(player);
  6869. else
  6870. if ((teams[ball_poss-1].tm_act==TACKLE_ACT && teams[ball_poss-1].go_cnt>EFFECTIVE_TACK)
  6871. || teams[ball_poss-1].int_move==I_GET_UP)
  6872. force_error(player);
  6873. else
  6874. go_to_between(player->tm_player); // get yourself between him and goal!
  6875. }
  6876. else
  6877. // He is not shielding ball!
  6878. {
  6879. if (d==1)
  6880. {
  6881. // He has his side to me!
  6882. if (seed&8 && (teams[ball_poss-1].tm_act==TACKLE_ACT || teams[ball_poss-1].int_move==I_GET_UP))
  6883. // Opponent is not able to turn and avoid... (So go directly to ball!)
  6884. force_error(player);
  6885. else
  6886. if ((player->tm_player!=KP_A) && (player->tm_player!=KP_B))
  6887. // Not the keeper!
  6888. forceful_retrieve(player); // Tackle directly!
  6889. else
  6890. force_error(player);
  6891. }
  6892. else
  6893. // He is facing towards me!
  6894. force_error(player); // More patient style of attack!
  6895. }
  6896. }
  6897. else
  6898. // Not in close enough!
  6899. {
  6900. if (can_close_down(player))
  6901. // I can close him down!
  6902. close_him_down(player);
  6903. }
  6904. }
  6905. }
  6906. }
  6907. }
  6908. /******************************************************************************
  6909. *****************************************************************************/
  6910. void user_intelligence(match_player *player)
  6911. {
  6912. if (match_mode || !ball_poss)
  6913. intelligence(player);
  6914. else
  6915. {
  6916. char busy=0;
  6917. if (player->int_cnt) //Is he busy?
  6918. {
  6919. if (--(player->int_cnt))
  6920. busy=1;
  6921. else
  6922. {
  6923. player->int_cnt=-1;
  6924. reset_ideas(player);
  6925. }
  6926. }
  6927. if (player->tm_act<=TURN_ACT) // Player is standing or running or turning!
  6928. {
  6929. if (!busy)
  6930. {
  6931. if (!ball_poss)
  6932. user_free_ball(player);
  6933. else
  6934. {
  6935. if (ball_poss==player->tm_player)
  6936. user_got_ball(player);
  6937. else
  6938. {
  6939. if (((ball_poss<12) && (player->tm_player>11))
  6940. || ((ball_poss>11) && (player->tm_player<12)))
  6941. user_opp_has_ball(player);
  6942. }
  6943. }
  6944. }
  6945. }
  6946. }
  6947. }
  6948. /******************************************************************************
  6949. *****************************************************************************/
  6950. void offside_rule(match_player *player)
  6951. {
  6952. if (player->tm_player<12)
  6953. // Team A...
  6954. {
  6955. if ((!match_mode) && (!ball_poss && ball_released>0) && (last_touch<12)
  6956. && (last_touch!=player->tm_player) && (player->tm_off) && (!just_scored)
  6957. && (ballx<player->tm_x))
  6958. // && (ballx<player->tm_x) && receiver_a==player->tm_player)
  6959. // His team-mate has released ball and he is in an offside pos...
  6960. init_offside(player); // Does Linesman see it!
  6961. else
  6962. if ((ball_poss<12) && (player->tm_x>cntspot_x)
  6963. && (can_be_offside) && (player->tm_x>(defense_b+prat)) && (!just_scored))
  6964. // Player is in opponents half, his opponent doesn't have ball and
  6965. // in normal play, and no defenders behind.
  6966. {
  6967. if (!player->tm_off)
  6968. player->tm_off=-1; // Potential Offside (get back).
  6969. }
  6970. else
  6971. player->tm_off=FALSE; // Not offside.
  6972. }
  6973. else
  6974. // Team B...
  6975. {
  6976. if ((!match_mode) && (!ball_poss && ball_released<0) && (last_touch>11)
  6977. && (last_touch!=player->tm_player) && (player->tm_off) && (!just_scored)
  6978. && (ballx>=player->tm_x))
  6979. // && (ballx>=player->tm_x) && receiver_b==player->tm_player)
  6980. // His team-mate has released ball and he is in an offside pos...
  6981. init_offside(player); // Does Linesman see it!
  6982. else
  6983. if ((ball_poss>11 || !ball_poss) && (player->tm_x<cntspot_x)
  6984. && (can_be_offside) && (player->tm_x<(defense_a-prat)) && (!just_scored))
  6985. // Player is in opponents half, his team mate has the ball
  6986. // in normal play, and no defenders behind.
  6987. {
  6988. if (!player->tm_off)
  6989. player->tm_off=-1; // Potential Offside (get back).
  6990. }
  6991. else
  6992. player->tm_off=FALSE; // Not offside.
  6993. }
  6994. if ((player->tm_off==TRUE) && (!match_mode) && (!just_scored))
  6995. // Linesman has indicated offside...
  6996. {
  6997. // Is he interfering with play...
  6998. if (player->tm_dist<ref_strictness*1.1)
  6999. {
  7000. offside_now=TRUE;
  7001. init_foul(player->tm_player,FALSE,TRUE); // Indirect F.K. for offside!
  7002. player->tm_off=FALSE;
  7003. }
  7004. }
  7005. }
  7006. /******************************************************************************
  7007. *****************************************************************************/
  7008. void override(match_player *player)
  7009. {
  7010. if (offside_on)
  7011. offside_rule(player);
  7012. }
  7013. /******************************************************************************
  7014. *****************************************************************************/
  7015. void remove_player(match_player *player)
  7016. {
  7017. player->guy_on=FALSE;
  7018. if (!player_being_subbed)
  7019. {
  7020. hold_up_play=4*REAL_SPEED;
  7021. camera=sub_camera;
  7022. player_on_off=FALSE;
  7023. ref_wait=(160-ref_strictness)*REAL_SPEED/8;
  7024. }
  7025. }
  7026. /******************************************************************************
  7027. *****************************************************************************/
  7028. void init_off_int(match_player *player)
  7029. {
  7030. allow_replay=FALSE;
  7031. float tx=stadlist[setup.stadium].tunlx;
  7032. float ty=-stadlist[setup.stadium].tunlz;
  7033. float tly;
  7034. if (ty>cntspot_y)
  7035. ty+=60;
  7036. else
  7037. ty-=60;
  7038. if (player_on_off>0 && calc_dist(tx-player->tm_x,ty-player->tm_y)<prat*2)
  7039. {
  7040. // In tunnel! (get off)!
  7041. remove_player(player);
  7042. player->tm_trap=0;
  7043. }
  7044. else
  7045. {
  7046. player->draw_me=TRUE;
  7047. player->int_cnt=600;
  7048. player->int_move=I_OFF;
  7049. if (ty>cntspot_y)
  7050. tly=pitch_wid;
  7051. else
  7052. tly=0;
  7053. if (player->tm_trap || calc_dist(tx-player->tm_x,tly-player->tm_y)<prat*2)
  7054. // At touch-line...(send him into tunnel)!
  7055. {
  7056. if (player_on_off<0)
  7057. {
  7058. // Coming on...
  7059. player->int_move=0;
  7060. reset_ideas(player);
  7061. player_on_off=FALSE;
  7062. camera=sub_camera;
  7063. allow_replay=TRUE;
  7064. }
  7065. else
  7066. {
  7067. player->tm_trap=TRUE;
  7068. init_run_act(player,tx,ty,0);
  7069. }
  7070. }
  7071. else
  7072. // send him to touch-line...
  7073. init_run_act(player,tx,tly,0);
  7074. }
  7075. }
  7076. /******************************************************************************
  7077. *****************************************************************************/
  7078. void intelligence(match_player *player)
  7079. {
  7080. if ((player->control) && (!match_mode) && (ball_poss))
  7081. {
  7082. // Player has just collected ball and been auto selected...
  7083. user_controlled=player->control;
  7084. user_intelligence(player);
  7085. }
  7086. else
  7087. {
  7088. char busy=0;
  7089. int pnum=player->tm_player;
  7090. if ((player->tm_leave) && (last_touch!=player->tm_player))
  7091. player->tm_leave=FALSE; // he can touch ball again!
  7092. if (player->int_cnt) //Is he busy?
  7093. {
  7094. if (--(player->int_cnt))
  7095. {
  7096. if (((pnum==KP_A) || (pnum==KP_B)) && (player->int_move==I_INTERCEPT)
  7097. && (shot_pending>0))
  7098. busy=0;
  7099. else
  7100. {
  7101. busy=1;
  7102. /*
  7103. if (player->int_move==I_INTERCEPT && user_controlled && player->tm_strike>0)
  7104. // User player is interecpting ball but hasn't chosen special move...
  7105. go_to_path(player->tm_player);
  7106. */
  7107. if (player->int_move==I_OFF)
  7108. {
  7109. // He is going off!
  7110. if (player->tm_act==STAND_ACT)
  7111. init_off_int(player);
  7112. }
  7113. else
  7114. {
  7115. if (player->int_move==I_RUN_ON)
  7116. // Calling for pass ahead...
  7117. {
  7118. if (plr_facing(player->go_xoff,player->go_yoff,player))
  7119. {
  7120. if (player->tm_comm<0)
  7121. player->tm_comm=-player->tm_comm;
  7122. }
  7123. else
  7124. {
  7125. if (player->tm_comm>0)
  7126. {
  7127. player->tm_comm=FALSE;
  7128. player->tm_ccnt=0;
  7129. reset_ideas(player);
  7130. }
  7131. }
  7132. }
  7133. else
  7134. {
  7135. if (player->int_move==I_STEAL)
  7136. {
  7137. if (player->tm_dist<STEAL_BODY_DIST)
  7138. {
  7139. reset_ideas(player);
  7140. init_steal_act(player);
  7141. }
  7142. }
  7143. }
  7144. }
  7145. }
  7146. }
  7147. else
  7148. {
  7149. player->int_cnt=-1;
  7150. if (player->int_move==I_SAVE_WAIT)
  7151. {
  7152. if (player->tm_act==RUN_ACT)
  7153. player->int_cnt=player->go_cnt+2;
  7154. if (player->int_cnt>0)
  7155. {
  7156. player->int_move=I_INTERCEPT;
  7157. busy=1;
  7158. }
  7159. else
  7160. reset_ideas(player);
  7161. }
  7162. else
  7163. reset_ideas(player);
  7164. }
  7165. }
  7166. if (player->tm_act<=TURN_ACT) // Player is standing or running or turning!
  7167. {
  7168. if (!busy && !just_scored)
  7169. {
  7170. if (player->guy_on<0)
  7171. {
  7172. // He has to be sent off!
  7173. init_off_int(player);
  7174. }
  7175. if (dead_ball_cnt==0)
  7176. // Are we in normal play...
  7177. {
  7178. if (!ball_poss)
  7179. free_ball(player);
  7180. else
  7181. {
  7182. if (ball_poss==pnum)
  7183. got_ball(player);
  7184. else
  7185. {
  7186. if ((pnum<12) && (ball_poss<12))
  7187. // My team A has ball!
  7188. we_have_ball(player);
  7189. else
  7190. {
  7191. if ((pnum>11) && (ball_poss>11))
  7192. // My team B has ball!
  7193. we_have_ball(player);
  7194. else
  7195. opp_has_ball(player);
  7196. }
  7197. }
  7198. }
  7199. }
  7200. else
  7201. {
  7202. // Is ball holder looking for support...
  7203. if (ball_poss!=pnum && support_me)
  7204. {
  7205. if ((pnum<12) && (ball_poss<12))
  7206. // My team A has ball!
  7207. we_have_ball(player);
  7208. else
  7209. if ((pnum>11) && (ball_poss>11))
  7210. // My team B has ball!
  7211. we_have_ball(player);
  7212. }
  7213. }
  7214. }
  7215. }
  7216. }
  7217. }
  7218. /******************************************************************************
  7219. *****************************************************************************/
  7220. /*
  7221. void cant_block_opp(match_player *player,match_player *oplayer)
  7222. {
  7223. int vx=(int)(ballx+(oplayer->go_txdis*8)); //look 8 turns ahead
  7224. int vy=(int)(bally+(oplayer->go_tydis*8));
  7225. vx-=player->tm_x;
  7226. vy-=player->tm_y;
  7227. if (calc_dist(vx,vy)<=tackle_range)
  7228. // In tackling range!
  7229. {
  7230. tackle_decide(player);
  7231. if (flag)
  7232. go_tackle(player,oplayer);
  7233. else
  7234. cant_tack_opp(player);
  7235. }
  7236. else
  7237. cant_tack_opp(player);
  7238. }
  7239. */