Overview | Package | Class | Source | Class tree | Glossary | UnrealScript Documentation |
previous class next class | frames no frames |
00001 00002 00003 00004 00005 00006 00007 00008 00009 00010 00011 00012 00013 00014 00015 00016 00017 00018 00019 00020 00021 00022 00023 00024 00025 00026 00027 00028 00029 00030 00031 00032 00033 00034 00035 00036 00037 00038 00039 00040 00041 00042 00043 00044 00045 00046 00047 00048 00049 00050 00051 00052 00053 00054 00055 00056 00057 00058 00059 00060 00061 00062 00063 00064 00065 00066 00067 00068 00069 00070 00071 00072 00073 00074 00075 00076 00077 00078 00079 00080 00081 00082 00083 00084 00085 00086 00087 00088 00089 00090 00091 00092 00093 00094 00095 00096 00097 00098 00099 00100 00101 00102 00103 00104 00105 00106 00107 00108 00109 00110 00111 00112 00113 00114 00115 00116 00117 00118 00119 00120 00121 00122 00123 00124 00125 00126 00127 00128 00129 00130 00131 00132 00133 00134 00135 00136 00137 00138 00139 00140 00141 00142 00143 00144 00145 00146 00147 00148 00149 00150 00151 00152 00153 00154 00155 00156 00157 00158 00159 00160 00161 00162 00163 00164 00165 00166 00167 00168 00169 00170 00171 00172 00173 00174 00175 00176 00177 00178 00179 00180 00181 00182 00183 00184 00185 00186 00187 00188 00189 00190 00191 00192 00193 00194 00195 00196 00197 00198 00199 00200 00201 00202 00203 00204 00205 00206 00207 00208 00209 00210 00211 00212 00213 00214 00215 00216 00217 00218 00219 00220 00221 00222 00223 00224 00225 00226 00227 00228 00229 00230 00231 00232 00233 00234 00235 00236 00237 00238 00239 00240 00241 00242 00243 00244 00245 00246 00247 00248 00249 00250 00251 00252 00253 00254 00255 00256 00257 00258 00259 00260 00261 00262 00263 00264 00265 00266 00267 00268 00269 00270 00271 00272 00273 00274 00275 00276 00277 00278 00279 00280 00281 00282 00283 00284 00285 00286 00287 00288 00289 00290 00291 00292 00293 00294 00295 00296 00297 00298 00299 00300 00301 00302 00303 00304 00305 00306 00307 00308 00309 00310 00311 00312 00313 00314 00315 00316 00317 00318 00319 00320 00321 00322 00323 00324 00325 00326 00327 00328 00329 00330 00331 00332 00333 00334 00335 00336 00337 00338 00339 00340 00341 00342 00343 00344 00345 00346 00347 00348 00349 00350 00351 00352 00353 00354 00355 00356 00357 00358 00359 00360 00361 00362 00363 00364 00365 00366 00367 00368 00369 00370 00371 00372 00373 00374 00375 00376 00377 00378 00379 00380 00381 00382 00383 00384 00385 00386 00387 00388 00389 00390 00391 00392 00393 00394 00395 00396 00397 00398 00399 00400 00401 00402 00403 00404 00405 00406 00407 00408 00409 00410 00411 00412 00413 00414 00415 00416 00417 00418 00419 00420 00421 00422 00423 00424 00425 00426 00427 00428 00429 00430 00431 00432 00433 00434 00435 00436 00437 00438 00439 00440 00441 00442 00443 00444 00445 00446 00447 00448 00449 00450 00451 00452 00453 00454 00455 00456 00457 00458 00459 00460 00461 00462 00463 00464 00465 00466 00467 00468 00469 00470 00471 00472 00473 00474 00475 00476 00477 00478 00479 00480 00481 00482 00483 00484 00485 00486 00487 00488 00489 00490 00491 00492 00493 00494 00495 00496 00497 00498 00499 00500 00501 00502 00503 00504 00505 00506 00507 00508 00509 00510 00511 00512 00513 00514 00515 00516 00517 00518 00519 00520 00521 00522 00523 00524 00525 00526 00527 00528 00529 00530 00531 00532 00533 00534 00535 00536 00537 00538 00539 00540 00541 00542 00543 00544 00545 00546 00547 00548 00549 00550 00551 00552 00553 00554 00555 00556 00557 00558 00559 00560 00561 00562 00563 00564 00565 00566 00567 00568 00569 00570 00571 00572 00573 00574 00575 00576 00577 00578 00579 00580 00581 00582 00583 00584 00585 00586 00587 00588 00589 00590 00591 00592 00593 00594 00595 00596 00597 00598 00599 00600 00601 00602 00603 00604 00605 00606 00607 00608 00609 00610 00611 00612 00613 00614 00615 00616 00617 00618 00619 00620 00621 00622 00623 00624 00625 00626 00627 00628 00629 00630 00631 00632 00633 00634 00635 00636 00637 00638 00639 00640 00641 00642 00643 00644 00645 00646 00647 00648 00649 00650 00651 00652 00653 00654 00655 00656 00657 00658 00659 00660 00661 00662 00663 00664 00665 00666 00667 00668 00669 00670 00671 00672 00673 00674 00675 00676 00677 00678 00679 00680 00681 00682 00683 00684 00685 00686 00687 00688 00689 00690 00691 00692 00693 00694 00695 00696 00697 00698 00699 00700 00701 00702 00703 00704 00705 00706 00707 00708 00709 00710 00711 00712 00713 00714 00715 00716 00717 00718 00719 00720 00721 00722 00723 00724 00725 00726 00727 00728 00729 00730 00731 00732 00733 00734 00735 00736 00737 00738 00739 00740 00741 00742 00743 00744 00745 00746 00747 00748 00749 00750 00751 00752 00753 00754 00755 00756 00757 00758 00759 00760 00761 00762 00763 00764 00765 00766 00767 00768 00769 00770 00771 00772 00773 00774 00775 00776 00777 00778 00779 00780 00781 00782 00783 00784 00785 00786 00787 00788 00789 00790 00791 00792 00793 00794 00795 00796 00797 00798 00799 00800 00801 00802 00803 00804 00805 00806 00807 00808 00809 00810 00811 00812 00813 00814 00815 00816 00817 00818 00819 00820 00821 00822 00823 00824 00825 00826 00827 00828 00829 00830 00831 00832 00833 00834 00835 00836 00837 00838 00839 00840 00841 00842 00843 00844 00845 00846 00847 00848 00849 00850 00851 00852 00853 00854 00855 00856 00857 00858 00859 00860 00861 00862 00863 00864 00865 00866 00867 00868 00869 00870 00871 00872 00873 00874 00875 00876 00877 00878 00879 00880 00881 00882 00883 00884 00885 00886 00887 00888 00889 00890 00891 00892 00893 00894 00895 00896 00897 00898 00899 00900 00901 00902 00903 00904 00905 00906 00907 00908 00909 00910 00911 00912 00913 00914 00915 00916 00917 00918 00919 00920 00921 00922 00923 00924 00925 00926 00927 00928 00929 00930 00931 00932 00933 00934 00935 00936 00937 00938 00939 00940 00941 00942 00943 00944 00945 00946 00947 00948 00949 00950 00951 00952 00953 00954 00955 00956 00957 00958 00959 00960 00961 00962 00963 00964 00965 00966 00967 00968 00969 00970 00971 00972 00973 00974 00975 00976 00977 00978 00979 00980 00981 00982 00983 00984 00985 00986 00987 00988 00989 00990 00991 00992 00993 00994 00995 00996 00997 00998 00999 01000 01001 01002 01003 01004 01005 01006 01007 01008 01009 01010 01011 01012 01013 01014 01015 01016 01017 01018 01019 01020 01021 01022 01023 01024 01025 01026 01027 01028 01029 01030 01031 01032 01033 01034 01035 01036 01037 01038 01039 01040 01041 01042 01043 01044 01045 01046 01047 01048 01049 01050 01051 01052 01053 01054 01055 01056 01057 01058 01059 01060 01061 01062 01063 01064 01065 01066 01067 01068 01069 01070 01071 01072 01073 01074 01075 01076 01077 01078 01079 01080 01081 01082 01083 01084 01085 01086 01087 01088 01089 01090 01091 01092 01093 01094 01095 01096 01097 01098 01099 01100 01101 01102 01103 01104 01105 01106 01107 01108 01109 01110 01111 01112 01113 01114 01115 01116 01117 01118 01119 01120 01121 01122 01123 01124 01125 01126 01127 01128 01129 01130 01131 01132 01133 01134 01135 01136 01137 01138 01139 01140 01141 01142 01143 01144 01145 01146 01147 01148 01149 01150 01151 01152 01153 01154 01155 01156 01157 01158 01159 01160 01161 01162 01163 01164 01165 01166 01167 01168 01169 01170 01171 01172 01173 01174 01175 01176 01177 01178 01179 01180 01181 01182 01183 01184 01185 01186 01187 01188 01189 01190 01191 01192 01193 01194 01195 01196 01197 01198 01199 01200 01201 01202 01203 01204 01205 01206 01207 01208 01209 01210 01211 01212 01213 01214 01215 01216 01217 01218 01219 01220 01221 01222 01223 01224 01225 01226 01227 01228 01229 01230 01231 01232 01233 01234 01235 01236 01237 01238 01239 01240 01241 01242 01243 01244 01245 01246 01247 01248 01249 01250 01251 01252 01253 01254 01255 01256 01257 01258 01259 01260 01261 01262 01263 01264 01265 01266 01267 01268 01269 01270 01271 01272 01273 01274 01275 01276 01277 01278 01279 01280 01281 01282 01283 01284 01285 01286 01287 01288 01289 01290 01291 01292 01293 01294 01295 01296 01297 01298 01299 01300 01301 01302 01303 01304 01305 01306 01307 01308 01309 01310 01311 01312 01313 01314 01315 01316 01317 01318 01319 01320 01321 01322 01323 01324 01325 01326 01327 01328 01329 01330 01331 01332 01333 01334 01335 01336 01337 01338 01339 01340 01341 01342 01343 01344 01345 01346 01347 01348 01349 01350 01351 01352 01353 01354 01355 01356 01357 01358 01359 01360 01361 01362 01363 01364 01365 01366 01367 01368 01369 01370 01371 01372 01373 01374 01375 01376 01377 01378 01379 01380 01381 01382 01383 01384 01385 01386 01387 01388 01389 01390 01391 01392 01393 01394 01395 01396 01397 01398 01399 01400 01401 01402 01403 01404 01405 01406 01407 01408 01409 01410 01411 01412 01413 01414 01415 01416 01417 01418 01419 01420 01421 01422 01423 01424 01425 01426 01427 01428 01429 01430 01431 01432 01433 01434 01435 01436 01437 01438 01439 01440 01441 01442 01443 01444 01445 01446 01447 01448 01449 01450 01451 01452 01453 01454 01455 01456 01457 01458 01459 01460 01461 01462 01463 01464 01465 01466 01467 01468 01469 01470 01471 01472 01473 01474 01475 01476 01477 01478 01479 01480 01481 01482 01483 01484 01485 01486 01487 01488 01489 01490 01491 01492 01493 01494 01495 01496 01497 01498 01499 01500 01501 01502 01503 01504 01505 01506 01507 01508 01509 01510 01511 01512 01513 01514 01515 01516 01517 01518 01519 01520 01521 01522 01523 01524 01525 01526 01527 01528 01529 01530 01531 01532 01533 01534 01535 01536 01537 01538 01539 01540 01541 01542 01543 01544 01545 01546 01547 01548 01549 01550 01551 01552 01553 01554 01555 01556 01557 01558 01559 01560 01561 01562 01563 01564 01565 01566 01567 01568 01569 01570 01571 01572 01573 01574 01575 01576 01577 01578 01579 01580 01581 01582 01583 01584 01585 01586 01587 01588 01589 01590 01591 01592 01593 01594 01595 01596 01597 01598 01599 01600 01601 01602 01603 01604 01605 01606 01607 01608 01609 01610 01611 01612 01613 01614 01615 01616 01617 01618 01619 01620 01621 01622 01623 01624 01625 01626 01627 01628 01629 01630 01631 01632 01633 01634 01635 01636 01637 01638 01639 01640 01641 01642 01643 01644 01645 01646 01647 01648 01649 01650 01651 01652 01653 01654 01655 01656 01657 01658 01659 01660 01661 01662 01663 01664 01665 01666 01667 01668 01669 01670 01671 01672 01673 01674 01675 01676 01677 01678 01679 01680 01681 01682 01683 01684 01685 01686 01687 01688 01689 01690 01691 01692 01693 01694 01695 01696 01697 01698 01699 01700 01701 01702 01703 01704 01705 01706 01707 01708 01709 01710 01711 01712 01713 01714 01715 01716 01717 01718 01719 01720 01721 01722 01723 01724 01725 01726 01727 01728 01729 01730 01731 01732 01733 01734 01735 01736 01737 01738 01739 01740 01741 01742 01743 01744 01745 01746 01747 01748 01749 01750 01751 01752 01753 01754 01755 01756 01757 01758 01759 01760 01761 01762 01763 01764 01765 01766 01767 01768 01769 01770 01771 01772 01773 01774 01775 01776 01777 01778 01779 01780 01781 01782 01783 01784 01785 01786 01787 01788 01789 01790 01791 01792 01793 01794 01795 01796 01797 01798 01799 01800 01801 01802 01803 01804 01805 01806 01807 01808 01809 01810 01811 01812 01813 01814 01815 01816 01817 01818 01819 01820 01821 01822 01823 01824 01825 01826 01827 01828 01829 01830 01831 01832 01833 01834 01835 01836 01837 01838 01839 01840 01841 01842 01843 01844 01845 01846 01847 01848 01849 01850 01851 01852 01853 01854 01855 01856 01857 01858 01859 01860 01861 01862 01863 01864 01865 01866 01867 01868 01869 01870 01871 01872 01873 01874 01875 01876 01877 01878 01879 01880 01881 01882 01883 01884 01885 01886 01887 01888 01889 01890 01891 01892 01893 01894 01895 01896 01897 01898 01899 01900 01901 01902 01903 01904 01905 01906 01907 01908 01909 01910 01911 01912 01913 01914 01915 01916 01917 01918 01919 01920 01921 01922 01923 01924 01925 01926 01927 01928 01929 01930 01931 01932 01933 01934 01935 01936 01937 01938 01939 01940 01941 01942 01943 01944 01945 01946 01947 01948 01949 01950 01951 01952 01953 01954 01955 01956 01957 01958 01959 01960 01961 01962 01963 01964 01965 01966 01967 01968 01969 01970 01971 01972 01973 01974 01975 01976 01977 01978 01979 01980 01981 01982 01983 01984 01985 01986 01987 01988 01989 01990 01991 01992 01993 01994 01995 01996 01997 01998 01999 02000 02001 02002 02003 02004 02005 02006 02007 02008 02009 02010 02011 02012 02013 02014 02015 02016 02017 02018 02019 02020 02021 02022 02023 02024 02025 02026 02027 02028 02029 02030 02031 02032 02033 02034 02035 02036 02037 02038 02039 02040 02041 02042 02043 02044 02045 02046 02047 02048 02049 02050 02051 02052 02053 02054 02055 02056 02057 02058 02059 02060 02061 02062 02063 02064 02065 02066 02067 02068 02069 02070 02071 02072 02073 02074 02075 02076 02077 02078 02079 02080 02081 02082 02083 02084 02085 02086 02087 02088 02089 02090 02091 02092 02093 02094 02095 02096 02097 02098 02099 02100 02101 02102 02103 02104 02105 02106 02107 02108 02109 02110 02111 02112 02113 02114 02115 02116 02117 02118 02119 02120 02121 02122 02123 02124 02125 02126 02127 02128 02129 02130 02131 02132 02133 02134 02135 02136 02137 02138 02139 02140 02141 02142 02143 02144 02145 02146 02147 02148 02149 02150 02151 02152 02153 02154 02155 02156 02157 02158 02159 02160 02161 02162 02163 02164 02165 02166 02167 02168 02169 02170 02171 02172 02173 02174 02175 02176 02177 02178 02179 02180 02181 02182 02183 02184 02185 02186 02187 02188 02189 02190 02191 02192 02193 02194 02195 02196 02197 02198 02199 02200 02201 02202 02203 02204 02205 02206 02207 02208 02209 02210 02211 02212 02213 02214 02215 02216 02217 02218 02219 02220 02221 02222 02223 02224 02225 02226 02227 02228 02229 02230 02231 02232 02233 02234 02235 02236 02237 02238 02239 02240 02241 02242 02243 02244 02245 02246 02247 02248 02249 02250 02251 02252 02253 02254 02255 02256 02257 02258 02259 02260 02261 02262 02263 02264 02265 02266 02267 02268 02269 02270 02271 02272 02273 02274 02275 02276 02277 02278 02279 02280 02281 02282 02283 02284 02285 02286 02287 02288 02289 02290 02291 02292 02293 02294 02295 02296 02297 02298 02299 02300 02301 02302 02303 02304 02305 02306 02307 02308 02309 02310 02311 02312 02313 02314 02315 02316 02317 02318 02319 02320 02321 02322 02323 02324 02325 02326 02327 02328 02329 02330 02331 02332 02333 02334 02335 02336 02337 02338 02339 02340 02341 02342 02343 02344 02345 02346 02347 02348 02349 02350 02351 02352 02353 02354 02355 02356 02357 02358 02359 02360 02361 02362 02363 02364 02365 02366 02367 02368 02369 02370 02371 02372 02373 02374 02375 02376 02377 02378 02379 02380 02381 02382 02383 02384 02385 02386 02387 02388 02389 02390 02391 02392 02393 02394 02395 02396 02397 02398 02399 02400 02401 02402 02403 02404 02405 02406 02407 02408 02409 02410 02411 02412 02413 02414 02415 02416 02417 02418 02419 02420 02421 02422 02423 02424 02425 02426 02427 02428 02429 02430 02431 02432 02433 02434 02435 02436 02437 02438 02439 02440 02441 02442 02443 02444 02445 02446 02447 02448 02449 02450 02451 02452 02453 02454 02455 02456 02457 02458 02459 02460 02461 02462 02463 02464 02465 02466 02467 02468 02469 02470 02471 02472 02473 02474 02475 02476 02477 02478 02479 02480 02481 02482 02483 02484 02485 02486 02487 02488 02489 02490 02491 02492 02493 02494 02495 02496 02497 02498 02499 02500 02501 02502 02503 02504 02505 02506 02507 02508 02509 02510 02511 02512 02513 02514 02515 02516 02517 02518 02519 02520 02521 02522 02523 02524 02525 02526 02527 02528 02529 02530 02531 02532 02533 02534 02535 02536 02537 02538 02539 02540 02541 02542 02543 02544 02545 02546 02547 02548 02549 02550 02551 02552 02553 02554 02555 02556 02557 02558 02559 02560 02561 02562 02563 02564 02565 02566 02567 02568 02569 02570 02571 02572 02573 02574 02575 02576 02577 02578 02579 02580 02581 02582 02583 02584 02585 02586 02587 02588 02589 02590 02591 02592 02593 02594 02595 02596 02597 02598 02599 02600 02601 02602 02603 02604 02605 02606 02607 02608 02609 02610 02611 02612 02613 02614 02615 02616 02617 02618 02619 02620 02621 02622 02623 02624 02625 02626 02627 02628 02629 02630 02631 02632 02633 02634 02635 02636 02637 02638 02639 02640 02641 02642 02643 02644 02645 02646 02647 02648 02649 02650 02651 02652 02653 02654 02655 02656 02657 02658 02659 02660 02661 02662 02663 02664 02665 02666 02667 02668 02669 02670 02671 02672 02673 02674 02675 02676 02677 02678 02679 02680 02681 02682 02683 02684 02685 02686 02687 02688 02689 02690 02691 02692 02693 02694 02695 02696 02697 02698 02699 02700 02701 02702 02703 02704 02705 02706 02707 02708 02709 02710 02711 02712 02713 02714 02715 02716 02717 02718 02719 02720 02721 02722 02723 02724 02725 02726 02727 02728 02729 02730 02731 02732 02733 02734 02735 02736 02737 02738 02739 02740 02741 02742 02743 02744 02745 02746 02747 02748 02749 02750 02751 02752 02753 02754 02755 02756 02757 02758 02759 02760 02761 02762 02763 02764 02765 02766 02767 02768 02769 02770 02771 02772 02773 02774 02775 02776 02777 02778 02779 02780 02781 02782 02783 02784 02785 02786 02787 02788 02789 02790 02791 02792 02793 02794 02795 02796 02797 02798 02799 02800 02801 02802 02803 02804 02805 02806 02807 02808 02809 02810 02811 02812 02813 02814 02815 02816 02817 02818 02819 02820 02821 02822 02823 02824 02825 02826 02827 02828 02829 02830 02831 02832 02833 02834 02835 02836 02837 02838 02839 02840 02841 02842 02843 02844 02845 02846 02847 02848 02849 02850 02851 02852 02853 02854 02855 02856 02857 02858 02859 02860 02861 02862 02863 02864 02865 02866 02867 02868 02869 02870 02871 02872 02873 02874 02875 02876 02877 02878 02879 02880 02881 02882 02883 02884 02885 02886 02887 02888 02889 02890 02891 02892 02893 02894 02895 02896 02897 02898 02899 02900 02901 02902 02903 02904 02905 02906 02907 02908 02909 02910 02911 02912 02913 02914 02915 02916 02917 02918 02919 02920 02921 02922 02923 02924 02925 02926 02927 02928 02929 02930 02931 02932 02933 02934 02935 02936 02937 02938 02939 02940 02941 02942 02943 02944 02945 02946 02947 02948 02949 02950 02951 02952 02953 02954 02955 02956 02957 02958 02959 02960 02961 02962 02963 02964 02965 02966 02967 02968 02969 02970 02971 02972 02973 02974 02975 02976 02977 02978 02979 02980 02981 02982 02983 02984 02985 02986 02987 02988 02989 02990 02991 02992 02993 02994 02995 02996 02997 02998 02999 03000 03001 03002 03003 03004 03005 03006 03007 03008 03009 03010 03011 03012 03013 03014 03015 03016 03017 03018 03019 03020 03021 03022 03023 03024 03025 03026 03027 03028 03029 03030 03031 03032 03033 03034 03035 03036 03037 03038 03039 03040 03041 03042 03043 03044 03045 03046 03047 03048 03049 03050 03051 03052 03053 03054 03055 03056 03057 03058 03059 03060 03061 03062 03063 03064 03065 03066 03067 03068 03069 03070 03071 03072 03073 03074 03075 03076 03077 03078 03079 03080 03081 03082 03083 03084 03085 03086 03087 03088 03089 03090 03091 03092 03093 03094 03095 03096 03097 03098 03099 03100 03101 03102 03103 03104 03105 03106 03107 03108 03109 03110 03111 03112 03113 03114 03115 03116 03117 03118 03119 03120 03121 03122 03123 03124 03125 03126 03127 03128 03129 03130 03131 03132 03133 03134 03135 03136 03137 03138 03139 03140 03141 03142 03143 03144 03145 03146 03147 03148 03149 03150 03151 03152 03153 03154 03155 03156 03157 03158 03159 03160 03161 03162 03163 03164 03165 03166 03167 03168 03169 03170 03171 03172 03173 03174 03175 03176 03177 03178 03179 03180 03181 03182 03183 03184 03185 03186 03187 03188 03189 03190 03191 03192 03193 03194 03195 03196 03197 03198 03199 03200 03201 03202 03203 03204 03205 03206 03207 03208 03209 03210 03211 03212 03213 03214 03215 03216 03217 03218 03219 03220 03221 03222 03223 03224 03225 03226 03227 03228 03229 03230 03231 03232 03233 03234 03235 03236 03237 03238 03239 03240 03241 03242 03243 03244 03245 03246 03247 03248 03249 03250 03251 03252 03253 03254 03255 03256 03257 03258 03259 03260 03261 03262 03263 03264 03265 03266 03267 03268 03269 03270 03271 03272 03273 03274 03275 03276 03277 03278 03279 03280 03281 03282 03283 03284 03285 03286 03287 03288 03289 03290 03291 03292 03293 03294 03295 03296 03297 03298 03299 03300 03301 03302 03303 03304 03305 03306 03307 03308 03309 03310 03311 03312 03313 03314 03315 03316 03317 03318 03319 03320 03321 03322 03323 03324 03325 03326 03327 03328 03329 03330 03331 03332 03333 03334 03335 03336 03337 03338 03339 03340 03341 03342 03343 03344 03345 03346 03347 03348 03349 03350 03351 03352 03353 03354 03355 03356 03357 03358 03359 03360 03361 03362 03363 03364 03365 03366 03367 03368 03369 03370 03371 03372 03373 03374 03375 03376 03377 03378 03379 03380 03381 03382 03383 03384 03385 03386 03387 03388 03389 03390 03391 03392 03393 03394 03395 03396 03397 03398 03399 03400 03401 03402 03403 03404 03405 03406 03407 03408 03409 03410 03411 03412 03413 03414 03415 03416 03417 03418 03419 03420 03421 03422 03423 03424 03425 03426 03427 03428 03429 03430 03431 03432 03433 03434 03435 03436 03437 03438 03439 03440 03441 03442 03443 03444 03445 03446 03447 03448 03449 03450 03451 03452 03453 03454 03455 03456 03457 03458 03459 03460 03461 03462 03463 03464 03465 03466 03467 03468 03469 03470 03471 03472 03473 03474 03475 03476 03477 03478 03479 03480 03481 03482 03483 03484 03485 03486 03487 03488 03489 03490 03491 03492 03493 03494 03495 03496 03497 03498 03499 03500 03501 03502 03503 03504 03505 03506 03507 03508 03509 03510 03511 03512 03513 03514 03515 03516 03517 03518 03519 03520 03521 03522 03523 03524 03525 03526 03527 03528 03529 03530 03531 03532 03533 03534 03535 03536 03537 03538 03539 03540 03541 03542 03543 03544 03545 03546 03547 03548 03549 03550 03551 03552 03553 03554 03555 03556 03557 03558 03559 03560 03561 03562 03563 03564 03565 03566 03567 03568 03569 03570 03571 03572 03573 03574 03575 03576 03577 03578 03579 03580 03581 03582 03583 03584 03585 03586 03587 03588 03589 03590 03591 03592 03593 03594 03595 03596 03597 03598 03599 03600 03601 03602 03603 03604 03605 03606 03607 03608 03609 03610 03611 03612 03613 03614 03615 03616 03617 03618 03619 03620 03621 03622 03623 03624 03625 03626 03627 03628 03629 03630 03631 03632 03633 03634 03635 03636 03637 03638 03639 03640 03641 03642 03643 03644 03645 03646 03647 03648 03649 03650 03651 03652 03653 03654 03655 03656 03657 03658 03659 03660 03661 03662 03663 03664 03665 03666 03667 03668 03669 03670 03671 03672 03673 03674 03675 03676 03677 03678 03679 03680 03681 03682 03683 03684 03685 03686 03687 03688 03689 03690 03691 03692 03693 03694 03695 03696 03697 03698 03699 03700 03701 03702 03703 03704 03705 03706 03707 03708 03709 03710 03711 03712 03713 03714 03715 03716 03717 03718 03719 03720 03721 03722 03723 03724 03725 03726 03727 03728 03729 03730 03731 03732 03733 03734 03735 03736 03737 03738 03739 03740 03741 03742 03743 03744 03745 03746 03747 03748 03749 03750 03751 03752 03753 03754 03755 03756 03757 03758 03759 03760 03761 03762 03763 03764 03765 03766 03767 03768 03769 03770 03771 03772 03773 03774 03775 03776 03777 03778 03779 03780 03781 03782 03783 03784 03785 03786 03787 03788 03789 03790 03791 03792 03793 03794 03795 03796 03797 03798 03799 03800 03801 03802 03803 03804 03805 03806 03807 03808 03809 03810 03811 03812 03813 03814 03815 03816 03817 03818 03819 03820 03821 03822 03823 03824 03825 03826 03827 03828 03829 03830 03831 03832 03833 03834 03835 03836 03837 03838 03839 03840 03841 03842 03843 03844 03845 03846 03847 03848 03849 03850 03851 03852 03853 03854 03855 03856 03857 03858 03859 03860 03861 03862 03863 03864 03865 03866 03867 03868 03869 03870 03871 03872 03873 03874 03875 03876 03877 03878 03879 03880 03881 03882 03883 03884 03885 03886 03887 03888 03889 03890 03891 03892 03893 03894 03895 03896 03897 03898 03899 03900 03901 03902 03903 03904 03905 03906 03907 03908 03909 03910 03911 03912 03913 03914 03915 03916 03917 03918 03919 03920 03921 03922 03923 03924 03925 03926 03927 03928 03929 03930 03931 03932 03933 03934 03935 03936 03937 03938 03939 03940 03941 03942 03943 03944 03945 03946 03947 03948 03949 03950 03951 03952 03953 03954 03955 03956 03957 03958 03959 03960 03961 03962 03963 03964 03965 03966 03967 03968 03969 03970 03971 03972 03973 03974 03975 03976 03977 03978 03979 03980 03981 03982 03983 03984 03985 03986 03987 03988 03989 03990 03991 03992 03993 03994 03995 03996 03997 03998 03999 04000 04001 04002 04003 04004 04005 04006 04007 04008 04009 04010 04011 04012 04013 04014 04015 04016 04017 04018 04019 04020 04021 04022 04023 04024 04025 04026 04027 04028 04029 04030 04031 04032 04033 04034 04035 04036 04037 04038 04039 04040 04041 04042 04043 04044 04045 04046 04047 04048 04049 04050 04051 04052 04053 04054 04055 04056 04057 04058 04059 04060 04061 04062 04063 04064 04065 04066 04067 04068 04069 04070 04071 04072 04073 04074 04075 04076 04077 04078 04079 04080 04081 04082 04083 04084 04085 04086 04087 04088 04089 04090 04091 04092 04093 04094 04095 04096 04097 04098 04099 04100 04101 04102 04103 04104 04105 04106 04107 04108 04109 04110 04111 04112 04113 04114 04115 04116 04117 04118 04119 04120 04121 04122 04123 04124 04125 04126 04127 04128 04129 04130 04131 04132 04133 04134 04135 04136 04137 04138 04139 04140 04141 04142 04143 04144 04145 04146 04147 04148 04149 04150 04151 04152 04153 04154 04155 04156 04157 04158 04159 04160 04161 04162 04163 04164 04165 04166 04167 04168 04169 04170 04171 04172 04173 04174 04175 04176 04177 04178 04179 04180 04181 04182 04183 04184 04185 04186 04187 04188 04189 04190 04191 04192 04193 04194 04195 04196 04197 04198 04199 04200 04201 04202 04203 04204 04205 04206 04207 04208 04209 04210 04211 04212 04213 04214 04215 04216 04217 04218 04219 04220 04221 04222 04223 04224 04225 04226 04227 04228 04229 04230 04231 04232 04233 04234 04235 04236 04237 04238 04239 04240 04241 04242 04243 04244 04245 04246 04247 04248 04249 04250 04251 04252 04253 04254 04255 04256 04257 04258 04259 04260 04261 04262 04263 04264 04265 04266 04267 04268 04269 04270 04271 04272 04273 04274 04275 04276 04277 04278 04279 04280 04281 04282 04283 04284 04285 04286 04287 04288 04289 04290 04291 04292 04293 04294 04295 04296 04297 04298 04299 04300 04301 04302 04303 04304 04305 04306 04307 04308 04309 04310 04311 04312 04313 04314 04315 04316 04317 04318 04319 04320 04321 04322 04323 04324 04325 04326 04327 04328 04329 04330 04331 04332 04333 04334 04335 04336 04337 04338 04339 04340 04341 04342 04343 04344 04345 04346 04347 04348 04349 04350 04351 04352 04353 04354 04355 04356 04357 04358 04359 04360 04361 04362 04363 04364 04365 04366 04367 04368 04369 04370 04371 04372 04373 04374 04375 04376 04377 04378 04379 04380 04381 04382 04383 04384 04385 04386 04387 04388 04389 04390 04391 04392 04393 04394 04395 04396 04397 04398 04399 04400 04401 04402 04403 04404 04405 04406 04407 04408 04409 04410 04411 04412 04413 04414 04415 04416 04417 04418 04419 04420 04421 04422 04423 04424 04425 04426 04427 04428 04429 04430 04431 04432 04433 04434 04435 04436 04437 04438 04439 04440 04441 04442 04443 04444 04445 04446 04447 04448 04449 04450 04451 04452 04453 04454 04455 04456 04457 04458 04459 04460 04461 04462 04463 04464 04465 04466 04467 04468 04469 04470 04471 04472 04473 04474 04475 04476 04477 04478 04479 04480 04481 04482 04483 04484 04485 04486 04487 04488 04489 04490 04491 04492 04493 04494 04495 04496 04497 04498 04499 04500 04501 04502 04503 04504 04505 04506 04507 04508 04509 04510 04511 04512 04513 04514 04515 04516 04517 04518 04519 04520 04521 04522 04523 04524 04525 04526 04527 04528 04529 04530 04531 04532 04533 04534 04535 04536 04537 04538 04539 04540 04541 04542 04543 04544 04545 04546 04547 04548 04549 04550 04551 04552 04553 04554 04555 04556 04557 04558 04559 04560 04561 04562 04563 04564 04565 04566 04567 04568 04569 04570 04571 04572 04573 04574 04575 04576 04577 04578 04579 04580 04581 04582 04583 04584 04585 04586 04587 04588 04589 04590 04591 04592 04593 |
//============================================================================= // U2NPCControllerShared.uc // Created By: Steve Polge, Mike Fox // Created On: 8/01/00 // $Author: Mfox $ // $Date: 1/29/03 4:24p $ // $Revision: 150 $ //============================================================================= class U2NPCControllerShared extends U2NPCControllerScriptable config(User) abstract; // state name consts -- see U2AI.doc const AcquisitionState = 'Acquisition'; // just acquired an enemy const AttackCloseState = 'AttackClose'; // closing in on enemy const AttackCloseChargeState = 'AttackCloseCharge'; // charge at enemy and possibly overshoot if enemy moves out of the way const AttackFallbackState = 'AttackFallback'; // going to an item while engaged, and remaining engaged const AttackHideState = 'AttackHide'; // remain waiting in safe spot (maybe use attackstakeout?) const AttackHuntState = 'AttackHunt'; // hunting for an enemy const AttackLeapState = 'AttackLeap'; // leap towards enemy (push state) const AttackMeleeState = 'AttackMelee'; // attempting to perform melee attack against enemy const AttackMoveToCoverBaseState = 'AttackMoveToCoverBase'; // base state for AttackMoveToCoverCombat/Flee const AttackMoveToCoverCombatState = 'AttackMoveToCoverCombat'; // try to find/move to a cover spot while remaining engaged with enemy const AttackMoveToCoverFleeState = 'AttackMoveToCoverFlee'; // try to find/move to a cover spot while fearing enemy const AttackRecoverEnemyState = 'AttackRecoverEnemy'; // recover enemy after losing LOS to enemy (might not necessarily ever reach cover spot) const AttackStakeOutState = 'AttackStakeOut'; // waiting for enemy to reappear const AttackStakeOutCoverState = 'AttackStakeOutCover'; // waiting for enemy to reappear at cover spot const AttackStationaryState = 'AttackStationary'; // stationary and attacking from a distance using projectiles const AttackRetreatState = 'AttackRetreat'; // go toward item while engaged with an enemy and fearing that enemy const AttackTacticalMoveState = 'AttackTacticalMove'; // performing a tactical move while handling an enemy const AttackTacticalMoveMeleeState = 'AttackTacticalMoveMelee'; // performing a tactical move while handling an enemy within melee metastate const AttackTacticalRetreatState = 'AttackTacticalRetreat'; // back away from enemy const AttackTacticalRetreatMeleeState = 'AttackTacticalRetreatMelee'; // back away from enemy within melee metastate const AttackTauntState = 'AttackTaunt'; // taunt enemy const CoweringState = 'Cowering'; // immobile and playing a cower animation const DeadlockedState = 'DeadLocked'; // used to wait a few ticks when behavior is deadlocked const DodgingState = 'Dodging'; // performing a dodging maneuver const DodgingWithAttackState = 'DodgingWithAttack'; // performing a dodging maneuver into an attack const EnemyKilledState = 'EnemyKilled'; // for performing any special "enemy killed" behavior const FindAirState = 'FindAir'; // search for surface when in water in order to breathe const HandleInvalidLandingState = 'HandleInvalidLanding'; // state for getting off railings and such const HoldState = 'Hold'; // NPC is trying to get to a holdspot const HoldingState = 'Holding'; // NPC is at the holdspot const KnockDownState = 'KnockDown'; // NPC knocked down by damage const ImpalingState = 'Impaling'; // Impaling melee attack state const MoveToGoalBaseState = 'MoveToGoalBase'; // base state for moving to a goal const MoveToGoalNoEnemyState = 'MoveToNoEnemyGoal'; // extends MoveToGoalBase -- no enemy const MoveToGoalWithEnemyState = 'MoveToGoalWithEnemy'; // extends MoveToGoalBase -- enemy const RoamingState = 'Roaming'; // going to items with no enemy const UsingState = 'Using'; // using a usable item const VictoryDanceState = 'VictoryDance'; // celebrate kill const WanderingState = 'Wandering'; // picking random locations (vectors) to move to const WanderingPanicState = 'WanderingPanic'; // NPC is panicking (e.g. on fire) const FrozenState = 'Frozen'; // testing: NPC can't move, can't rotate, can't shoot const TestMoveState = 'TestMove'; // testing: NPC immediately heads to TestMoveTarget // label name consts (some only used in subclasses) const AdjustFromWallLabel = 'AdjustFromWall'; const AdjustPositionLabel = 'AdjustPosition'; const AdjustPositionAgainLabel = 'AdjustPositionAgain'; const AdjustRotationLabel = 'AdjustRotation'; const AttackOngoingLabel = 'AttackOngoing'; // used to maintain focus/rotation, check target etc. during ranged/melee attack const AttackDoneLabel = 'AttackDone'; // current melee/ranged attack ended const AutoEndLabel = 'AutoEnd'; const CampLabel = 'Camp'; const CampAgainLabel = 'CampAgain'; const CampLongLabel = 'CampLong'; const CantReachLabel = 'CantReach'; const ChallengeLabel = 'Challenge'; const CloseLabel = 'Close'; const DelayLabel = 'Delay'; const DialogBeginLabel = 'DialogBegin'; const DialogEndLabel = 'DialogEnd'; const DialogFocusRestoreLabel = 'DialogFocusRestore'; const DialogFocusSetLabel = 'DialogFocusSet'; const DialogPauseLabel = 'DialogPause'; const DialogUnPauseLabel = 'DialogUnPause'; const DodgeFinishedLabel = 'DodgeFinished'; const DontCloseLabel = 'DontClose'; const DoneLabel = 'Done'; const DuckingLabel = 'Ducking'; const ErrorLabel = 'Error'; const FaceTargetLabel = 'FaceTarget'; const FireLabel = 'FireFalling'; const GiveUpLabel = 'GiveUp'; const GiveWayLabel = 'GiveWay'; const HuntLabel = 'Hunt'; const IdleLabel = 'Idle'; const LandLabel = 'Land'; const MoveActiveLabel = 'MoveActive'; const MoveActiveStrafeLabel = 'MoveActiveStrafe'; const MoveCheckLabel = 'MoveCheck'; const MoveDoneLabel = 'MoveDone'; const MoveFailedLabel = 'MoveFailed'; const MoveFallingLabel = 'MoveFalling'; const MoveNoDestLabel = 'MoveNoDest'; const MovePickDestLabel = 'MovePickDest'; const MovePickDestLoopLabel = 'MovePickDestLoop'; const MoveSpecialLabel = 'MoveSpecial'; const MoveTestLabel = 'MoveTest'; const PauseLabel = 'Pause'; const PostBeginLabel = 'PostBegin'; const PreBeginLabel = 'PreBegin'; const ReachedDestinationLabel = 'ReachedDestination'; const ReadyToAttackLabel = 'ReadyToAttack'; const RecoverEnemyLabel = 'RecoverEnemy'; const ResumePatrolLabel = 'ResumePatrol'; const ShootDecorationLabel = 'ShootDecoration'; const StanceChangeDelayLabel = 'StanceChangeDelay'; const StartLeapLabel = 'StartLeap'; const StartupDelayLabel = 'StartupDelay'; const TacticalTickLabel = 'TacticalTick'; const TrackFocusLabel = 'TrackFocus'; const TryAgainLabel = 'TryAgain'; const TurnLabel = 'Turn'; const WaitingForStartLabel = 'WaitingForStart'; const WavingLabel = 'Waving'; const UnuseEvent = 'unuse'; const NeedToTurnAngleCos = 0.990; // NOTE: should be at least as large as CosMinFacingTargetAngle const NeedToTurnDialogAngleCos = 0.350; //----------------------------------------------------------------------------- const DefaultIsCloseToDynamicGoalDistance = 128.0; // distance to use if no distance specified when checking if close to a moving goal const MaxNoLOSFollowDistance = 16.0; // if no LOS to follow target, use this distance instead of default const MinFollowDistance = 1;//16.0; // never try to move closer than this to a followed goal (e.g. Pawn) const MinGoalDistance = 1;//16.0; // never try to move closer than this to a non-follow goal (engine could fail to reach it otherwise) const MaxRadiusEnemiesDistance = 1600.0; // max distance used to find nearby enemies const INCOMINGCOLLISIONFUDGE = 2.0; enum EMoveType { // in order of decreasing "severity" MT_Error, // pathing error MT_None, // no current destination (caller can decide whether this is an error or not?) MT_Wait, // can't currently get to destination -- try again in a bit MT_Near, // near or at destination (no need to move) MT_Success, // can move towards destination }; enum EDestinationResult { DR_Predicted, // using a predicted destination DR_Raw, // using a raw (direct) destination DR_Wait, // wait a bit... }; var int MaxMoveToPointAttempts; // caps number of failed attempts to reach same goal var int MaxMoveToActorAttempts; // caps number of failed attempts to reach same goal var int MaxMoveRecoverAttempts; // caps number of failed attempts to reach same goal //----------------------------------------------------------------------------- // AI flags // AI internal - misc var float LastAcquireTime; // set as NPC acquires enemy var bool bTargetObscured; // set when checking odds of hitting enemy with shot // set in Possess var U2PawnBase U2PBase; var U2PawnBasic U2PBasic; var U2PawnAdvanced U2PAdvanced; // AI internal - movement var EMoveType GMoveType; // holds result of last call to SetMoveTarget etc. var int NumMoveAttempts; // number of failed attempts to reach current destination var int NumMoveRecoverAttempts; // number of failed attempts to reach current destination var vector WanderDirectionExternal; // used for resolving friendly interactions (clustering, defer to etc.) var vector OldMoveLocation; var float ReduceStanceAgainTime; // used to lock out going standing -> crouching/prone or crouching -> prone for a while // for testing movement/pathing var Actor TestMoveTarget; var float TestMoveSpeed; var ETacticalMoveType TestTacticalMoveType; var float DodgeEnableTime; // used in some cases to block dodging for a while (e.g. right after a knockdown/panic) var Actor SpecialGoal; // special goal (scripted, flag, replicator, gotoactor destination etc.) var float SpecialGoalDistance; // used with special goal command to control "destination reached" distance (-1.0 means not used) var bool bFaceSpecialGoal; // whether to try to face goal actor var bool bLastAimLocationHitFriendly; // set to true when last adjustaim trace hits a friendly NPC/XMP item var float TemporaryGoalDistance; // used to temporarily override special goal distance var float CloseEnoughDistance; // if NPC following a Pawn which isn't currently reachable, stay put if at least this close var float GetCloserThreshold; // if NPC following a Pawn which isn't currently reachable, stay put unless can get this much closer // dialog //NOTE (MIB): Are 2 focii needed? (mdf): probably not -- we should be able to use Focus for this? //NOTE (MIB): Are there scenarios where it be useful for the AI to decide whether to face the Focus or the DialogFocus? var protected Actor OldFocus; var protected vector OldFocalPoint; var protected Actor DialogFocus; var protected bool bDialogSetFocus; // set if a dialog session sets NPC rotation var float StopFiringAtEnemyTime; var float MaxAffectedByHitTime; // (secs) var float MaxAffectedByAcquisitionTime; // (secs) // odds of trying to hit target at min..max difficulty var float TryToHitInstantBaseOddsMin; var float TryToHitInstantBaseOddsMax; var float TryToHitProjectileBaseOddsMin; var float TryToHitProjectileBaseOddsMax; var float TryToHitTossedBaseOddsMin; var float TryToHitTossedBaseOddsMax; // distance around which base odds are based var float TryToHitInstantBaseDistance; var float TryToHitProjectileBaseDistance; var float TryToHitTossedBaseDistance; // don't try to miss if distance < min var float TryToHitInstantMinMissDistance; var float TryToHitProjectileMinMissDistance; var float TryToHitTossedMinMissDistance; // always try to miss if distance > max var float TryToHitProjectileMaxHitDistance; var float TryToHitInstantMaxHitDistance; var float TryToHitTossedMaxHitDistance; var float TryToHitBaseSpeed; // speed around which try to hit odds scaled var float TryToHitBaseSpeedOdds; // odds used at this speed var float BlockedByCoverHitOdds; var float MaxAlwaysLeadDistance; // if enemy distance > this, sometimes don't lead var float MaxHitMissMultiplier; var float MaxAcquireMissMultiplier; var int MaxHitPitchError; var int MinHitPitchError; var int MaxAcquirePitchError; var int MinAcquirePitchError; var int Hits, Misses; //!!mdf-tmp testing / stat gathering const MaxDistanceActors = 32; struct TDistanceInfo { var() float Distance; var() Actor TargetActor; }; var float MinTeleportRangeMoveError, MaxTeleportRangeMoveError; var float MinTeleportRangeMinZError, MaxTeleportRangeMinZError; var float MinTeleportRangeStuckError, MaxTeleportRangeStuckError; var float MinLastRenderedTeleportDelay; var int DefaultRotationThreshold; var int ScriptedRotationThreshold; var name DefaultState; // default state when NPC initialized (usually Roaming/Wandering etc.) //----------------------------------------------------------------------------- // interface function HandleBumpedByEnemy(); function bool StrafeFromDamage( float Damage, class<DamageType> DamageType, bool bFindDest ); //----------------------------------------------------------------------------- // Completely freezes NPC -- won't be able to shoot or rotate. Useful for doing // various testing. function SetFrozen( bool bVal ) { if( bVal ) { GotoState( FrozenState ); } else { #debug WhatToDoNext( GetContext() ); #release WhatToDoNext(); } } //----------------------------------------------------------------------------- //@ _INIT/RESTART //----------------------------------------------------------------------------- function Possess( Pawn P ) { // helpers U2PBase = U2PawnBase(P); U2PBasic = U2PawnBasic(P); U2PAdvanced = U2PawnAdvanced(P); OldMoveLocation = P.Location; #debug DMAI( "U2PBase: " $ U2PBase ); #debug DMAI( "U2PBasic: " $ U2PBasic ); #debug DMAI( "U2PAdvanced: " $ U2PAdvanced ); Super.Possess( P ); } //----------------------------------------------------------------------------- event PreBeginPlay() { Super.PreBeginPlay(); // or else NPCs might not turn towards what they want to fire at assert( NeedToTurnAngleCos >= CosMinFacingTargetAngle ); } //----------------------------------------------------------------------------- function SetPeripheralVision() { U2PBase.RestoreSightRadius(); } //----------------------------------------------------------------------------- function Shutdown( bool bVal ) { if( bVal ) { U2PBase.Visibility = 0.0; U2PBase.HearingThreshold = 0.0; U2PBase.Alertness = -1.0; U2PBase.AirControl = 0.0; U2PBase.SetSightRadius( 0.0 ); } else { U2PBase.HearingThreshold = U2PBase.InitialHearingThreshold; U2PBase.Alertness = U2PBase.InitialAlertness; U2PBase.AirControl = U2PBase.default.AirControl; U2PBase.Visibility = U2PBase.default.Visibility; U2PBase.RestoreSightRadius(); } } //----------------------------------------------------------------------------- function LockAnimationController( int LockLevel ) { if( U2P != None && U2P.AnimationController != None ) U2P.AnimationController.LockAnimationController( LockLevel ); } //----------------------------------------------------------------------------- function UnlockAnimationController( optional bool bClear ) { if( U2P != None && U2P.AnimationController != None ) { U2P.AnimationController.UnlockAnimationController(); if( bClear ) U2P.AnimationController.SpecialAnimationClear(); } } //----------------------------------------------------------------------------- //@ INPUT -- RAW ENGINE EVENTS //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- // Map HearNoise event to HearNoiseFriendly/Other/Threat. // mdf-tbi: Do we need to pass on the Loudness param? event final HearNoise( float Loudness, Actor NoiseMaker ) { local Pawn NoiseInstigator; local EAttitude AttitudeToOther; // mdf-tbr: should only be called with Actors/Pawns -- fix callers if any passing in a Controller // otherwise do if( Controller(Instigator) != None ) Instigator = Controller(Instigator).Pawn; //DMAssert( Controller(NoiseMaker) == None, "HearNoise" ); // need to check the Instigator, not the source of the noise itself NoiseInstigator = NoiseMaker.Instigator; //mdf-tbd: seems this can happen? This means engine isn't filtering these out // unless we ever plan to have NPCs react to noises which they instigated // might be best to make engine filter these out. Only case I can think of // where we might want these events is for a projectile that the NPC fired // (NPC follows projectile via its MakeNoise events?) #debug DMAssert( NoiseInstigator != Pawn, GetContext() ); if( NoiseInstigator != None ) { if( ValidPawn( NoiseInstigator ) ) { // Pawn is alive and well and visible etc. // NOTE: engine currently only sends HearNoise for enemies #debug DMAssert( GetAttitudeTo( NoiseInstigator ) == ATTITUDE_Enemy, GetContext() ); if( StationaryPawn(NoiseInstigator) == None || StationaryPawn(NoiseInstigator).ConsiderAttacking( NoiseInstigator, Self ) ) HearNoiseThreat( Loudness, NoiseMaker ); /* AttitudeToOther = GetAttitudeTo( NoiseInstigator ); if( AttitudeToOther == ATTITUDE_Enemy ) { // mdf-tbd: be reasonable about whether should set Instigator as ControllerEnemy -- could be miles away) // unless ControllerEnemy = Instigator (already the NPC's enemy) or CanSee Instigator (taking // peripheral vision, sightrange into account), don't pass as NoiseThreat -- pass as NoiseOther // and NPC should *investigate* the noise -- only set ControllerEnemy if sees him & gets close enough HearNoiseThreat( Loudness, NoiseMaker ); } else if( AttitudeToOther == ATTITUDE_Friend ) { // mdf-tbd: filter a lot of these for performance reasons? //HearNoiseFriendly( Loudness, NoiseMaker ); } */ } } else { // and allow for reactions to noises with no Instigator (need to fix engine code though -- won't send these currently) // mdf-tbd: how to handle non-Pawn sources of noise (or no Instigator? // mdf-tbd: filter a lot of these for performance reasons? //HearNoiseOther( Loudness, NoiseMaker ); } } //----------------------------------------------------------------------------- function MaybeAvoidFriendlyBump( Pawn Other ); //----------------------------------------------------------------------------- // Map bump event to BumpFriendly/Other/Threat. event final bool NotifyBump( Actor Other ) { local EAttitude AttitudeToOther; //DMAssert( Controller(Other) == None, "NotifyBump" ); #debug DMAI( "NotifyBump: " $ Other ); //DMTNS( "NotifyBump: " $ Other ); //mdf-tbr: #debug DMAssert( Other != Pawn, GetContext() ); if( Pawn(Other) != None ) { if( ValidPawn( Pawn(Other) ) ) { // Pawn is alive and well and visible etc. AttitudeToOther = GetAttitudeTo( Pawn(Other) ); if( AttitudeToOther == ATTITUDE_Enemy ) { //DMTNS( " (enemy)" ); BumpEnemy( Pawn(Other) ); } else if( AttitudeToOther == ATTITUDE_Friend ) { // mdf-tbd: filter a lot of these for performance reasons? BumpFriend( Pawn(Other) ); // allow for special handling of friendly bumps regardless of // whether bump events are being filtered by the script MaybeAvoidFriendlyBump( Pawn(Other) ); } } } else { // mdf-tbd: how to handle non-Pawn sources of noise (or no Instigator? // mdf-tbd: filter a lot of these for performance reasons? //BumpOther( Other ); } // never pass this on to the Pawn? return true; } //----------------------------------------------------------------------------- event bool NotifyPhysicsVolumeChange( PhysicsVolume NewVolume ) { local vector JumpDir; if( NewVolume.bWaterVolume ) { if( !Pawn.bCanSwim ) { MoveTimer = -1.0; } else if( Pawn.Physics != PHYS_Swimming ) { Pawn.SetPhysics( PHYS_Swimming ); } } else if( Pawn.Physics == PHYS_Swimming ) { if( Pawn.bCanFly ) { Pawn.SetPhysics( PHYS_Flying ); } else { Pawn.SetPhysics( PHYS_Falling ); if( Pawn.bCanWalk && ( Abs( Pawn.Acceleration.X ) + Abs( Pawn.Acceleration.Y ) > 0 ) && ( Destination.Z >= Pawn.Location.Z ) && Pawn.CheckWaterJump( JumpDir ) ) Pawn.JumpOutOfWater( JumpDir ); } } //DMTNS( "Global.NotifyPhysicsVolumeChange Physics: " $ Pawn.Physics ); return false; } /*----------------------------------------------------------------------------- A number of states override SetFall to specify the state and label to return to after going to the falling state. */ function SetFall() { //local float OldJumpZ; if( Pawn.bCanFly ) { Pawn.SetPhysics( PHYS_Flying ); } else if( !Pawn.bBlockAdjustJump ) { if( Pawn.bCanAdjustJump ) { // allow full adjust jump StopMovement( true, false ); Pawn.Velocity = EAdjustJump( Destination, Pawn.Velocity.Z, Pawn.GroundSpeed ); StartFalling(); } else { // recuce / eliminate jump adjust? /* // reduce JumpZ used for adjusting jump StopMovement( true, false ); OldJumpZ = Pawn.JumpZ; Pawn.JumpZ = 10; //tbd: using a low JumpZ seemed to work well in-game Pawn.Velocity = EAdjustJump( Destination, Pawn.Velocity.Z, Pawn.GroundSpeed ); Pawn.JumpZ = OldJumpZ; */ StartFalling(); } } // always clear for next call Pawn.bBlockAdjustJump = false; } //----------------------------------------------------------------------------- //@ INPUT -- PROCESSED EVENTS //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- // mdf-tbd: we need to be very careful about how often this function is called // e.g. due to texture sounds etc. -- short-circuit this as much as possible. function eventHearNoiseThreat( float Loudness, Actor NoiseMaker ) { #debug DMAIE( "Global eventHearNoiseThreat" ); //log( class$" heard noise by "$NoiseMaker.class ); // mdf-tbd: see HearNoise -- at this point we can assume that NoiseMaker is a valid ControllerEnemy if( MaybeSetEnemy( NoiseMaker.Instigator ) && NoiseMaker.Instigator == ControllerEnemy ) { // mdf-tbd: without above check, this assumes NoiseMaker is the NPC's enemy which // may not be the case in Unreal2 (e.g. NPC reacting to explosion or projectile // in a situation where the Instigator is unknown. HandleEnemyNoise( NoiseMaker ); } } //----------------------------------------------------------------------------- function eventHearNoiseFriendly( float Loudness, Actor NoiseMaker ) { // mdf-tbd: do nothing / if no enemy occasionally look at source? } //----------------------------------------------------------------------------- function eventHearNoiseOther( float Loudness, Actor NoiseMaker ) { // mdf-tbd: go into a higher state of alert / search the area? } //----------------------------------------------------------------------------- function eventSeeAlertFriend( Pawn Seen ) { #debug DMAIE( "Global.eventSeeAlertFriend" ); ReactToAlertFriend( Seen ); } //----------------------------------------------------------------------------- function eventSeeEnemy( Pawn Seen ) { #debug DMAIE( "Global eventSeeEnemy" ); MaybeSetEnemy( Seen ); } //----------------------------------------------------------------------------- function eventSeeFriend( Pawn Seen ) { #debug DMAIE( "Global eventSeeFriend" ); ReactToFriend( Seen ); } //----------------------------------------------------------------------------- function eventSeeOther( Actor Seen ) { #debug DMAIE( "Global eventSeeOther" ); // NPCs default to not reacting to seeing "other" ? // I should be able to uncomment this -- events aren't enabled so "see" never happens //mdf-tbd: ambients & such //tbd: enemies can only be Pawns currently //MaybeSetEnemy( Seen ); } //----------------------------------------------------------------------------- // Called by eventBumpEnemy/Friend/Other for use in situations where code wants // to know about *any* bumps. function eventBumpAll( Actor Other ) { } //----------------------------------------------------------------------------- function eventBumpEnemy( Pawn Other ) { local Pawn OldControllerEnemy; #debugbegin if( !ValidPawn( Other ) ) DMAssert( false, Other $ " is invalid " $ GetContext() ); #debugend eventBumpAll( Other ); OldControllerEnemy = ControllerEnemy; //DMTNS( "eventBumpEnemy calling MaybeSetEnemy: " $ Other ); MaybeSetEnemy( Other ); if( ControllerEnemy == Other && IsPreparedToFire( true, true, U2Weapon.RatingIneffective ) ) { //DMTNS( "calling HandleBumpEnemy" ); HandleBumpedByEnemy(); } else { //DMTNS( "restoring OldControllerEneny" ); #debug SetControllerEnemy( OldControllerEnemy, GetContext() ); #release SetControllerEnemy( OldControllerEnemy ); } //DMTNS( "eventBumpEnemy called MaybeSetEnemy ControllerEnemy: " $ ControllerEnemy ); } //----------------------------------------------------------------------------- // refactoring hacks function bool WanderAfterFriendlyBumpExtra() { return false; } function bool FriendlyBumpSpecial() { return false; } //----------------------------------------------------------------------------- // NOTE (mdf): instrumental in helping to resolve clustering between friendly // NPCs. function eventBumpFriend( Pawn Other ) { local vector VelDir, OtherDir; local float Speed, Dist, OldVelocityZ; local Controller C; local bool bDestinationObstructed, bAmLeader; local int Num; eventBumpAll( Other ); // mdf-tbd: clean up this crapola if( HandleFriendlyBumps() && Other != None && Other.Controller != None && MoveTarget != None ) { OtherDir = Other.Location - MoveTarget.Location; if( Abs( OtherDir.Z ) < Other.CollisionHeight ) { OtherDir.Z = 0; Dist = VSize( OtherDir ); bDestinationObstructed = ( VSize( OtherDir ) < Other.CollisionRadius ); bAmLeader = Other.Controller.DeferTo( Self ); // check if someone else is on destination or within 3 * collisionradius for( C=Level.ControllerList; C!=None; C=C.NextController ) if( C != Self && C.Pawn != None ) { Dist = VSize( C.Pawn.Location - MoveTarget.Location ); if( Dist < C.Pawn.CollisionRadius ) { bDestinationObstructed = true; bAmLeader = bAmLeader || C.DeferTo( Self ); } if( Dist < 3 * C.Pawn.CollisionRadius ) { Num++; if( Num >= 2 ) { bDestinationObstructed = true; bAmLeader = bAmLeader || C.DeferTo( Self ); } } } if( bDestinationObstructed && !bAmLeader ) { // Other is standing on my destination MoveTimer = -1.0; if( !FriendlyBumpSpecial() && Pawn.Health > 0 && (!IsInState( WanderingState ) || Pawn.Acceleration == vect(0,0,0)) ) { if( AllowFriendlyBumpStateChanges() ) { WanderDirectionExternal = Other.CollisionRadius*2.0*Normal( Pawn.Location - Other.Location ); GotoState( WanderingState, BeginLabel ); } } } } } Speed = VSize( Pawn.Velocity ); if( Speed > 10 ) { VelDir = Pawn.Velocity/Speed; VelDir.Z = 0; OtherDir = Other.Location - Pawn.Location; OtherDir.Z = 0; OtherDir = Normal( OtherDir ); if( ( VelDir dot OtherDir ) > 0.8 ) { OldVelocityZ = Pawn.Velocity.Z; Pawn.Velocity.X = VelDir.Y; Pawn.Velocity.Y = -1 * VelDir.X; Pawn.Velocity *= FMax( Speed, 280 ); // mdf-tbd: don't scale Z velocity for falling/walking NPCs or NPC can get slammed into the ground and take damage if( Pawn.Physics == PHYS_Falling || Pawn.Physics == PHYS_Walking ) Pawn.Velocity.Z = OldVelocityZ; } } else if( WanderAfterFriendlyBumpExtra() ) { GotoState( WanderingState, BeginLabel ); } // basically an error situation? if( AllowFriendlyBumpStateChanges() ) Pawn.GotoState( NoState ); } //----------------------------------------------------------------------------- function eventBumpOther( Actor Other ) { eventBumpAll( Other ); } //----------------------------------------------------------------------------- //@ INTERACTIONS //----------------------------------------------------------------------------- #if0 // mdf-tbd: make native so GetAttitudeTo can hook into this? // which maintains a list of Pawns that this NPC is annoyed at? function bool AnnoyedAt( Pawn Other ) { // hacked in for now -- generalize // turn into an annoyance factor which can be modified by several things // also annoyance should fade with time return false; // mdf-tbd: ( (AttackBumpLimit >= 0) && (PlayerBumpedMeCount > AttackBumpLimit) ); } #endif0 /*----------------------------------------------------------------------------- Returns a value indicating the relative strength of other: < 0 ==> weaker 0.0 ==> equal > 0 ==> stronger Since the result will be compared to the creature's aggressiveness, it should be on the same order of magnitude (-1 to 1) */ function float RelativeStrength( Pawn Other ) { local float Compare; local int AdjustedOtherHealth; //2002.12.15 (mdf) basically a hack to prevent skaarj from concentrating on McMillan in M10): if( U2PawnBasic(Other) != None && U2PawnBasic(Other).bIgnoreRelativeHealth ) AdjustedOtherHealth = 0.5 * Other.default.Health; else AdjustedOtherHealth = 0.5 * (Other.Health + Other.default.Health); if( U2PBasic != None && U2PBasic.bIgnoreRelativeHealth ) Compare = 0.01 * float( AdjustedOtherHealth - Pawn.default.Health ); else Compare = 0.01 * float( AdjustedOtherHealth - Pawn.Health ); Compare -= Pawn.DamageScaling * (GetAttackRating( Other ) - 0.3); if( GetFireRating() < 0.5 ) { Compare += 0.3; if( Other.Controller.GetFireRating() > 0.5 ) Compare += 0.35; } Compare += Other.DamageScaling * (Other.Controller.GetAttackRating( Pawn ) - 0.3); if( Other.Location.Z > Pawn.Location.Z + 400 ) Compare -= 0.2; else if( Pawn.Location.Z > Other.Location.Z + 400 ) Compare += 0.15; //DMTNS( "RelativeStrength of " $ Other $ " to " $ Pawn $ " is " $ Compare ); return Compare; } //----------------------------------------------------------------------------- function float AddedHumanThreat() { return 0.15; } //----------------------------------------------------------------------------- function bool ReduceThreat() { return false; } //----------------------------------------------------------------------------- function float AssessThreat( Pawn Other ) { local float ThreatValue, OtherStrength, OtherDistance; local Pawn CurrentEnemy; OtherStrength = RelativeStrength( Other ); //!!mdf-tbd whether this makes sense ThreatValue = FMax( 0, OtherStrength ); if( Other.Health < 20 ) ThreatValue += 0.3; //!!mdf-tbd whether this makes sense OtherDistance = VSize( Other.Location - Pawn.Location ); if( OtherDistance < 800 ) ThreatValue += 0.3; //!!mdf-tbd whether this makes sense CurrentEnemy = ControllerEnemy; if( Other != CurrentEnemy && CurrentEnemy != None ) { if( OtherDistance > 0.7 * VSize( ControllerEnemy.Location - Pawn.Location ) ) ThreatValue -= 0.25; ThreatValue -= 0.2; if( !LineOfSightTo( Other ) ) { if( OtherDistance < 1200 ) ThreatValue += 0.2; if( bPreparingMove ) ThreatValue += 5; if( ReduceThreat() && OtherStrength < 0.2 && (Level.TimeSeconds - GetLastEnemySeenTime()) < 3 && RelativeStrength( CurrentEnemy ) < FMin( 0, OtherStrength ) ) { ThreatValue -= 0.3; } } } // NOTE: this will make NPCs tend to go after (real) players all things being equal if( Other.IsHumanControlled() ) ThreatValue += AddedHumanThreat(); //DMTNS( "AssessThreat for " $ Other $ ": " $ ThreatValue ); return ThreatValue; } //----------------------------------------------------------------------------- // Returns: // P1 > P2 : X > 0.0 // P1 = P2 : X = 0.0 // P1 < P2 : X < 0.0 function float CompareThreat( Pawn P1, Pawn P2 ) { local float ThreatP1, ThreatP2; local Controller C; local float P1Distance, P2Distance, DistanceDifference, MinDist; if( P1 == P2 ) return 0.0; //!!mdf-tbd: should prefer to attack stationary pawn (aggresive even more so) //if other is an NPC/player which already has N (2 might work) enemies if( StationaryPawn(P1) != None && StationaryPawn(P2) == None ) { // P1 is a stationary pawn, P2 is an NPC //!! make sure NPC can be hit (e.g. not through a force field) ThreatP2 = 1.0; // NPC P2 is greater threat than stationary pawn P1 } //2002.12.10 (mdf) bug? //else if( StationaryPawn(P1) == None || StationaryPawn(P2) != None ) else if( StationaryPawn(P1) == None && StationaryPawn(P2) != None ) { // P1 is an NPC, P2 is a stationary pawn //!! make sure NPC can be hit (e.g. not through a force field) ThreatP1 = 1.0; // NPC P1 is greater threat than stationary pawn P2 } else if( StationaryPawn(P1) != None && StationaryPawn(P2) != None ) { // P1 and P2 are both stationary pawns - if either has an attack that one is more dangerous if( StationaryPawn(P1).bHasAttack ) ThreatP1 = 1.0; // P1 can attack else if( StationaryPawn(P2).bHasAttack ) ThreatP2 = 1.0; // P2 can attack } else if( P1.bIsRealPlayer != P2.bIsRealPlayer && (U2PBasic.bFearPlayersMoreThanNPCs || U2PBasic.bFearNPCsMoreThanPlayers) ) { // one Pawn is a player if( U2PBasic.bFearPlayersMoreThanNPCs ) { if( P1.bIsRealPlayer ) { ThreatP1 = 1.0; ThreatP2 = -1.0; } else { ThreatP1 = -1.0; ThreatP2 = 1.0; } } else { if( P1.bIsRealPlayer ) { ThreatP1 = -1.0; ThreatP2 = 1.0; } else { ThreatP1 = 1.0; ThreatP2 = -1.0; } } } //!!mdf: complete hack so NPC won't consider health if either enemy has bIgnoreRelativeHealth // (in general NPCs seem to almost never switch from one enemy to another currently) else if( (U2PawnBasic(P1) != None && U2PawnBasic(P1).bIgnoreRelativeHealth) || (U2PawnBasic(P2) != None && U2PawnBasic(P2).bIgnoreRelativeHealth) ) { // attack P1 if closer, P2 otherwise P1Distance = VSize( Pawn.Location - P1.Location ); P2Distance = VSize( Pawn.Location - P2.Location ); DistanceDifference = P2Distance - P1Distance; MinDist = FMin( P1Distance, P2Distance ); if( DistanceDifference > 256.0 || (MinDist < 256.0 && DistanceDifference > 32.0) || MinDist < 64.0 ) return DistanceDifference; else return 0.0; // keep current enemy } else { // evaluate relative strength of non-StationaryPawns ThreatP1 = AssessThreat( P1 ); ThreatP2 = AssessThreat( P2 ); } if( ThreatP1 == ThreatP2 ) { // decrease threat relative to number of enemies each Pawn already has that I can see? for( C=Level.ControllerList; C!=None; C=C.NextController ) { if( C != Self ) { if( C.ControllerEnemy == P1 && LineOfSightTo( C.Pawn ) ) ThreatP1 -= 1.0; else if( C.ControllerEnemy == P2 && LineOfSightTo( C.Pawn ) ) ThreatP2 -= 1.0; } } } if( ThreatP1 == ThreatP2 ) { // increase threat of closer one if( VSize( Pawn.Location - P1.Location ) <= VSize( Pawn.Location - P2.Location ) ) ThreatP1 += 1.0; else ThreatP2 += 1.0; } //DMTNS( "CompareThreat " $ P1 $ " (" $ ThreatP1 $ ") " $ P2 $ " (" $ ThreatP2 $ ")" ); return ( ThreatP1 - ThreatP2 ); } //----------------------------------------------------------------------------- function bool HandleFriendlyBumps() { return true; } //----------------------------------------------------------------------------- function bool AllowFriendlyBumpStateChanges() { return true; } //----------------------------------------------------------------------------- function ReactToAlertFriend( Pawn P ) { local Controller Friend; DMAI( "Global.ReactToAlertFriend" ); Friend = P.Controller; if( ValidPawn( Friend.ControllerEnemy ) && Pawn.SameTeam( P ) ) MaybeInheritEnemy( P, Friend.ControllerEnemy, true ); else LPawn.SetAlert( true ); } //----------------------------------------------------------------------------- function ReactToFriend( Pawn P ) { // make sure friend isn't alert (in case SeeFriend enabled without SeeAlertFriend) if( ValidPawn( P.Controller.ControllerEnemy ) || LPawn.GetAlert() ) ReactToAlertFriend( P ); /* local Controller Friend; !!mdf-tbd: "react to "calm" friend stuff? local bool bNotSeen; local EReaction NewReaction; #1: GetReactionToEnemy only returns attack/fear currently #2: this code appears to be trying to let this NPC inherit the friend's enemy but if( Friend.GetTimeSinceEnemyLastDetected() > 5 ) */ } //----------------------------------------------------------------------------- function EnemyAcquired() { DMTNS( "WARNING: EnemyAcquired not implemented for " $ Name $ " (" $ Pawn.Name $ ")" ); } //----------------------------------------------------------------------------- function MaybeAlertOthers( Pawn PotentialEnemy ); //----------------------------------------------------------------------------- function eventInheritEnemy( Pawn NewEnemy ) { MaybeSetEnemy( NewEnemy, true ); } //----------------------------------------------------------------------------- // Note: caller should verify on same team (if desired). function MaybeInheritEnemy( Pawn Other, Pawn NewEnemy, optional bool bCanSee ) { //DMTNS( "MaybeInheritEnemy: " $ NewEnemy $ " from " $ Other ); if( ControllerEnemy == None && StationaryPawn(NewEnemy) == None && // 2002.12.12 (mdf) don't inherit XMP item enemies? U2PawnBase(Other) != None && VSize( Pawn.Location - Other.Location ) <= U2PawnBase(Other).AlertOthersRadius && (bCanSee || !U2PawnBase(Other).bAlertOthersRequiresLOS || CanSee( Other )) ) { #debug DMAIA( "MaybeInheritEnemy calling InheritEnemy" ); //DMTNS( "MaybeInheritEnemy calling InheritEnemy for " $ NewEnemy ); U2PBase.bAmbientCreature = false; InheritEnemy( NewEnemy ); } } //----------------------------------------------------------------------------- // Note: most Base NPCs don't track an OldControllerEnemy and if they react at all to // enemies they'll just run away (or have special behavior which doesn't make // use of Basic+ code). function bool MaybeAcquireEnemy( Pawn NewEnemy ) { if( ControllerEnemy == None || (U2PBasic != None && U2PBasic.bAlwaysAttackNewEnemy) ) { #debug SetControllerEnemy( NewEnemy, GetContext() ); #release SetControllerEnemy( NewEnemy ); return true; } return false; } //----------------------------------------------------------------------------- // Returns true if NewEnemy became (or already was) the current enemy. Note: // the reason we return true if NewEnemy already was the NPC's enemy is because // input is often used to update/inform the NPC's current behavior. For example // and NPC might have X as the enemy but might not currently have LOS to the // enemy and might be hunting it. Seeing or hearing X might cause the NPC to // change states. Note also that EnemyAcquired is only called when enemy // *becomes* NewEnemy. // // Callers should ensure that NewEnemy is valid enemy (e.g. this is often done // early in the event handling stage and it would be inefficient to do this // again here given that events can occur so frequently). function bool MaybeSetEnemy( Pawn NewEnemy, optional bool bAlertingOthers ) { local bool bResult; #debug DMAI( "MaybeSetEnemy NewEnemy=" $ NewEnemy ); //DMTNS( "MaybeSetEnemy NewEnemy: " $ NewEnemy $ " Distance: " $ VSize( NewEnemy.Location - Pawn.Location ) ); #debugbegin // mdf-tbr: if this asserts fix the caller -- remove prior to release if( !ValidPawn( NewEnemy ) || GetAttitudeTo( NewEnemy ) != ATTITUDE_Enemy ) { DMTNS( "Warning: invalid situation in" @ GetContext() ); DMTNS( " Pawn: " $ Pawn ); DMTNS( " AttitudeTo: " $ EnumStr( Enum'EAttitude', GetAttitudeTo( NewEnemy ) ) ); DMTNS( " Enemy: " $ ControllerEnemy ); DMTNS( " NewEnemy: " $ NewEnemy ); DMTNS( " ValidPawn: " $ ValidPawn( NewEnemy ) ); DMTNS( " NewEnemy.bDeleteMe: " $ NewEnemy.bDeleteMe ); DMTNS( " NewEnemy.Health: " $ NewEnemy.Health ); //!!mdf-tbd: stationary pawns not calling notifykilled? DMTNS( " NewEnemy.bHidden: " $ NewEnemy.bHidden ); } #debugend if( ControllerEnemy == NewEnemy ) { bResult = true; } else { if( MaybeAcquireEnemy( NewEnemy ) ) { bResult = true; EnemyAcquired(); // NOTE: this is pretty much *the* hook that states should use to handle acquiring an enemy if( !bAlertingOthers ) MaybeAlertOthers( NewEnemy ); } } // mdf-tbd: I'm not sure this makes sense -- we don't shouldn't necessarily // know where the enemy is, no? if( bResult ) EnemyDetected( ControllerEnemy.Location ); return bResult; } //----------------------------------------------------------------------------- // Maybe update last detected location due to noise from or originated by // enemy? function HandleEnemyNoise( Actor NoiseMaker ) { local vector NewEnemyDetectedLocation; //NOTE (mdf) - don't necessarily have LOS to enemy... if( NoiseMaker.Instigator == ControllerEnemy ) { // sound was instigated by enemy -- use point half way between noisemaker location and where NPC is looking at same distance NewEnemyDetectedLocation = 0.5 * (NoiseMaker.Location + VSize( NoiseMaker.Location - Pawn.Location ) * vector(Pawn.Rotation)); } /*!!mdf-tbr: isn't this the same as checking whether the noisemaker is the enemy? else if( Pawn(NoiseMaker) != None && Pawn(NoiseMaker).Controller != None && Pawn(NoiseMaker).Controller.ControllerEnemy == enemy ) */ else if( NoiseMaker == ControllerEnemy ) { // sound is from enemy -- use point half way between enemy location and where NPC is looking at same distance NewEnemyDetectedLocation = 0.5 * (ControllerEnemy.Location + VSize( ControllerEnemy.Location - Pawn.Location ) * vector(Pawn.Rotation)); } if( VSize( NewEnemyDetectedLocation - ControllerEnemy.Location ) < VSize( GetLastEnemySeenLocation() - ControllerEnemy.Location ) ) EnemyDetected( NewEnemyDetectedLocation ); } //----------------------------------------------------------------------------- function Pawn FindLocalEnemy( float MaxDistance ) { local Controller C; // look for a nearby enemy for( C=Level.ControllerList; C!=None; C=C.NextController ) { if( StationaryPawn( C.Pawn ) == None && //2002.12.08 mdf-tbd: don't pick up nearby XMP items? ValidEnemy( C.Pawn ) && (VSize(Pawn.Location - C.Pawn.Location) < MaxDistance) && CanSee( C.Pawn ) ) { return C.Pawn; } } return None; } //----------------------------------------------------------------------------- //@ MISC //----------------------------------------------------------------------------- function bool ShouldBounceProjectile() { return FDecision( U2PBasic.BounceProjectileOdds ); } //----------------------------------------------------------------------------- function float GetBounceLifespan() { return U2PBasic.BounceLifespan + 2.0 * (1.0 - Level.Game.GetNormalizedDifficulty()); } //----------------------------------------------------------------------------- // maybe make mobile? function VerifyMobility( float EnemyDistance ) { if( !bStayStationary && !IsMobile() ) { //!!mdf-tbd: move health check into damage handling if( Pawn.Health < U2PBasic.MinStationaryHealth || EnemyDistance < U2PBasic.MinStationaryDistance ) { SetStationary( false ); } } } //----------------------------------------------------------------------------- // maybe change stance due to enemy being too close? // !!mdf-tbd: how to coordinate with transition animation (might not be in // attackstationary etc.? function bool UpdateStance( byte TargetStance, optional float EnemyDistance ) { local byte CurrentStance; // force crouching/standing if enemy is close CurrentStance = LPawn.GetDesiredStance(); // use desired stance in case it hasn't been set yet //DMTNS( "UpdateStance: " $ CurrentStance $ " --> " $ TargetStance $ "?" ); if( (TargetStance == ST_Prone || TargetStance == ST_Crouching) && EnemyDistance <= 0.0 ) { if( ControllerEnemy != None ) EnemyDistance = VSize( Pawn.Location - ControllerEnemy.Location ); else EnemyDistance = 99999.0; // default to handling as if far away } if( (TargetStance == ST_Prone || CurrentStance == ST_Prone) && EnemyDistance < U2PBasic.MinProneDistance ) { //DMTNS( "too close for prone" ); TargetStance = ST_Crouching; } if( (TargetStance == ST_Crouching || CurrentStance == ST_Crouching) && EnemyDistance < U2PBasic.MinCrouchDistance ) { //DMTNS( "too close for crouch" ); TargetStance = ST_Standing; } //DMTNS( " Setting stance to: " $ TargetStance $ " result: " $ (LPawn.GetStance() != CurrentStance) ); LPawn.SetStance( TargetStance ); // note: its possible for this to fail (e.g. no room for new stance) return ( TargetStance != CurrentStance ); } //----------------------------------------------------------------------------- // tbd: call for moving states also (need a more realistic crouch walk/run) function bool SelectStance( bool bAvoidProne ) { local bool bResult; local float TotalOdds, RandVal; local byte CurrentStance, TargetStance; local float EnemyDistance; local float StandOdds, CrouchOdds, ProneOdds; if( !U2PBasic.bCanCrouch && !U2PBasic.bCanCrawl ) return false; //DMTNS( "SelectStance current stance: " $ LPawn.GetStance() ); // only consider changing stance if none was specified (e.g. via a script) if( StationaryStance == ST_None ) { if( ControllerEnemy != None ) EnemyDistance = VSize( ControllerEnemy.Location - Pawn.Location ); else EnemyDistance = 9999999.999; CurrentStance = LPawn.GetStance(); StandOdds = U2PBasic.StationaryStandOdds; if( Pawn.bCanCrouch && EnemyDistance >= U2PBasic.MinCrouchDistance && Level.TimeSeconds >= ReduceStanceAgainTime ) { CrouchOdds = U2PBasic.StationaryCrouchOdds; if( Pawn.Weapon != None ) CrouchOdds *= Pawn.Weapon.GetPreferCrouchingMultiplier(); } if( !bAvoidProne && Pawn.bCanCrawl && EnemyDistance >= U2PBasic.MinProneDistance && Level.TimeSeconds >= ReduceStanceAgainTime ) { ProneOdds = U2PBasic.default.StationaryProneOdds; if( Pawn.Weapon != None ) ProneOdds *= Pawn.Weapon.GetPreferProneMultiplier(); } TotalOdds = StandOdds + CrouchOdds + ProneOdds; //DMTNS( " StandOdds: " $ StandOdds ); //DMTNS( " CrouchOdds: " $ CrouchOdds ); //DMTNS( " ProneOdds: " $ ProneOdds ); //DMTNS( " TotalOdds: " $ TotalOdds ); if( TotalOdds > 0.0 ) { // in most cases NPC will tend to stay crouching/prone (as long as enemy doesn't // get too close or NPC isn't taking damange). if( (CurrentStance == ST_Crouching && FDecision( U2PBasic.StationaryStayCrouchingOdds )) || (CurrentStance == ST_Prone && FDecision( U2PBasic.StationaryStayProneOdds )) ) { //DMTNS( "Keeping stance: " $ CurrentStance ); TargetStance = CurrentStance; } else { RandVal = FRand()*TotalOdds; //DMTNS( " RandVal: " $ RandVal ); if( RandVal < StandOdds ) TargetStance = ST_Standing; else if( RandVal < (StandOdds + CrouchOdds) ) TargetStance = ST_Crouching; else TargetStance = ST_Prone; //DMTNS( " TargetStance: " $ TargetStance ); } bResult = UpdateStance( TargetStance ); } } return bResult; } //----------------------------------------------------------------------------- // Returns true if stance being changed. function bool RestoreStance() { // mdf-tbd: odds of keeping stance for movement (crouching only) //if( Pawn != None && Pawn.Health > 0 && StationaryStance == ST_None ) if( Pawn != None && Pawn.Health > 0 ) { //DMTNS( "RestoreStance calling UpdateStance" ); return UpdateStance( ST_Standing ); //!!mdf-tbd: animation issues } return false; } //----------------------------------------------------------------------------- //mdf-tbd: not currently used -- outside code can call this to have NPC avoid //given location. function FearThisSpot( Actor aSpot ) { StopMovement( true, false ); MoveTimer = -1.0; } /*----------------------------------------------------------------------------- SetAlertness() Change creature's alertness, and appropriately modify attributes used by engine for determining seeing and hearing. SeeEnemy() is affected by PeripheralVision, and also by SightRadius and the target's visibility HearNoise() is affected by HearingThreshold */ function SetAlertness( float NewAlertness ) { if( Pawn != None ) Pawn.Alertness = NewAlertness; } //----------------------------------------------------------------------------- function RestoreAlertness() { if( Pawn != None ) Pawn.Alertness = Pawn.default.Alertness; } //----------------------------------------------------------------------------- function bool CanRespawn() { return false; } //----------------------------------------------------------------------------- //@ PATHING/MOVEMENT //----------------------------------------------------------------------------- function TeleportedPawn( vector OldLocation, Actor TargetActor ) { if( !U2P.bDisableErrorMessages ) DMTNS( "Teleported " $ Pawn $ " from " $ class'Util'.static.GetVectorString( OldLocation ) $ " to " $ class'Util'.static.GetVectorString( Pawn.Location ) $ " TargetActor: " $ TargetActor $ "!" ); if( !U2P.bDisableErrorColors ) { AddArrow( OldLocation, Pawn.Location, ColorGreen() ); AddActor( Pawn, ColorGreen() ); } } //----------------------------------------------------------------------------- function bool TeleportPawn( Actor TargetActor ) { local vector OldLocation; local vector TargetLocation; TargetLocation = class'Util'.static.GetLocationAtActor( TargetActor, Pawn.CollisionRadius, Pawn.CollisionHeight ); OldLocation = Pawn.Location; if( Pawn.SetLocation( TargetLocation ) ) { TeleportedPawn( OldLocation, TargetActor ); return true; } else if( !U2P.bDisableErrorMessages ) { DMTNS( "TeleportPawn failed for " $ Pawn $ " from " $ class'Util'.static.GetVectorString( OldLocation ) $ " to " $ class'Util'.static.GetVectorString( TargetLocation ) $ " TargetActor: " $ TargetActor $ "!" ); } return false; } //----------------------------------------------------------------------------- static function GetNearbyPathNodes( Actor SourceActor, out TDistanceInfo DistanceList[ MaxDistanceActors ], float MinDistance, float MaxDistance, bool bIgnoreZ ) { local int ii, jj, Len; local float Distance; local NavigationPoint NP; // collect valid pathnodes in MinTeleportRange..MaxTeleportRange Len = 0; for( NP=SourceActor.Level.NavigationPointList; NP!=None; NP=NP.NextNavigationPoint ) { if( PathNode(NP) == None ) continue; if( SourceActor.Physics == PHYS_Walking && !NP.bFindBase ) continue; if( SourceActor.Physics == PHYS_Swimming && !NP.PhysicsVolume.bWaterVolume ) continue; if( SourceActor.Physics != PHYS_Swimming && NP.PhysicsVolume.bWaterVolume ) continue; if( bIgnoreZ ) Distance = VSize2D( NP.Location - SourceActor.Location ); else Distance = VSize( NP.Location - SourceActor.Location ); if( Distance < MinDistance ) continue; if( Distance > MaxDistance ) continue; // sorted insert for( ii=0; ii<Len; ii++ ) { if( DistanceList[ ii ].Distance >= Distance ) break; } // shift everything else down for( jj=Len; jj>ii; jj-- ) { if( jj < MaxDistanceActors ) { DistanceList[ jj ] = DistanceList[ jj-1 ]; if( jj == Len ) Len++; } } if( ii < MaxDistanceActors ) { DistanceList[ ii ].Distance = Distance ; DistanceList[ ii ].TargetActor = NP; if( ii == Len ) Len++; //SourceActor.DMTNS( "Added " $ NP $ " at " $ ii $ " Len: " $ Len ); } } //SourceActor.DMTNS( "DistanceList: " ); //for( ii=0; ii<Len; ii++ ) // SourceActor.DMTNS( ii $ " " $ DistanceList[ii].TargetActor $ " : " $ DistanceList[ii].Distance ); } //----------------------------------------------------------------------------- //!!mdf-refactor after gold static function GetNearbyPathNodesRelativeTo( Actor SourceActor, Actor RelativeActor, out TDistanceInfo DistanceList[ MaxDistanceActors ], float MinDistance, float MaxDistance, bool bIgnoreZ ) { local int ii, jj, Len; local float Distance; local NavigationPoint NP; // collect valid pathnodes in MinTeleportRange..MaxTeleportRange Len = 0; for( NP=SourceActor.Level.NavigationPointList; NP!=None; NP=NP.NextNavigationPoint ) { if( PathNode(NP) == None ) continue; if( SourceActor.Physics == PHYS_Walking && !NP.bFindBase ) continue; if( SourceActor.Physics == PHYS_Swimming && !NP.PhysicsVolume.bWaterVolume ) continue; if( SourceActor.Physics != PHYS_Swimming && NP.PhysicsVolume.bWaterVolume ) continue; if( bIgnoreZ ) Distance = VSize2D( NP.Location - SourceActor.Location ); else Distance = VSize( NP.Location - SourceActor.Location ); if( Distance < MinDistance ) continue; if( Distance > MaxDistance ) continue; if( bIgnoreZ ) Distance = VSize2D( NP.Location - RelativeActor.Location ); else Distance = VSize( NP.Location - RelativeActor.Location ); // sorted insert for( ii=0; ii<Len; ii++ ) { if( DistanceList[ ii ].Distance >= Distance ) break; } // shift everything else down for( jj=Len; jj>ii; jj-- ) { if( jj < MaxDistanceActors ) { DistanceList[ jj ] = DistanceList[ jj-1 ]; if( jj == Len ) Len++; } } if( ii < MaxDistanceActors ) { DistanceList[ ii ].Distance = Distance ; DistanceList[ ii ].TargetActor = NP; if( ii == Len ) Len++; //SourceActor.DMTNS( "Added " $ NP $ " at " $ ii $ " Len: " $ Len ); } } //SourceActor.DMTNS( "DistanceList: " ); //for( ii=0; ii<Len; ii++ ) // SourceActor.DMTNS( ii $ " " $ DistanceList[ii].TargetActor $ " : " $ DistanceList[ii].Distance ); } //----------------------------------------------------------------------------- // Traces staight down and attempts to move the pawn to the hit location. If // TargetActor is valid (can move NPC there and can build a path to the GoalActor // from there or is actually within the specified GoalDistance from the // GoalActor), the NPC is left at TargetActor's location, otherwise its location // will be unchanged when the call returns. function EMoveType CheckNavigationFrom( Actor TargetActor, Actor GoalActor, float GoalDistance ) { local EMoveType ReturnedMoveType; local vector SavedLocation, TargetLocation; ReturnedMoveType = MT_None; if( TargetActor != None ) { SavedLocation = Pawn.Location; TargetLocation = class'Util'.static.GetLocationAtActor( TargetActor, Pawn.CollisionRadius, Pawn.CollisionHeight ); if( Pawn.SetLocation( TargetLocation ) ) { ReturnedMoveType = GetPathTo( GoalActor, MoveTarget, GoalDistance ); if( ReturnedMoveType != MT_Success && ReturnedMoveType != MT_Near ) { Pawn.SetLocation( SavedLocation ); } else { TeleportedPawn( SavedLocation, TargetActor ); } } } return ReturnedMoveType; } //----------------------------------------------------------------------------- // Searches in a 2d radius for navigation points and tries to teleport the // npc there. It checks first for navigation points that are of out of view // of the player, but will resort to those in sight if necessary. // // !!mdf-tbd: CanSee seems to be a little too conservative (says player can see // targets when these are actually out of range of peripheral vision)? function EMoveType RecoverFromNavigationError( Actor GoalActor, float GoalDistance, bool bConsiderMoveTarget ) { local EMoveType ReturnedMoveType; local PlayerController PC; local Actor TargetActor; local int ii; local TDistanceInfo NPList[ MaxDistanceActors ]; PC = Level.PlayerControllerList; if( PC == None ) return MT_Wait; // player is dead so it don't matter... //DMTNS( "time since last rendered: " $ Level.TimeSeconds - Pawn.LastRenderTime ); // if we've been rendered fairly recently (i.e. a player was looking at us) wait // (unless player is viewing through this NPC then go ahead and teleport... if( PC.ViewTarget != Self && PC.ViewTarget != Pawn && (Level.TimeSeconds - Pawn.LastRenderTime) < MinLastRenderedTeleportDelay ) { //DMTNS( "rendered recently -- wait..." ); return MT_Wait; } /*!!tbd: not needed? if( PC!=None && Pawn.PlayerCanSeeMe() ) return MT_Wait; */ ReturnedMoveType = MT_None; if( bConsiderMoveTarget ) { // first, try the move target if it's out of player's sight if( MoveTarget != None && !PC.CanSee( MoveTarget ) ) { //DMTNS( "trying MoveTarget: " $ MoveTarget $ " CanSee: " $ PC.CanSee( TargetActor ) ); ReturnedMoveType = CheckNavigationFrom( MoveTarget, GoalActor, GoalDistance ); } /* not sure about this -- if NPC is stuck pbly better to forge ahead and teleport to some other location -- we've already established that the player isn't looking at the NPC itself above via LastRenderedTime. else { ReturnedMoveType = MT_Wait; } */ } //DMTNS( "ReturnedMoveType #1: " $ EnumStr( enum'EMoveType', ReturnedMoveType ) ); if( ReturnedMoveType <= MT_None ) { GetNearbyPathNodes( Pawn, NPList, MinTeleportRangeMoveError, MaxTeleportRangeMoveError, false ); // try pathnodes out of player's sight //DMTNS( "try out of sight targets" ); for( ii=0; ii<ArrayCount(NPList); ii++ ) { TargetActor = NPList[ii].TargetActor; if( TargetActor == None ) break; if( !PC.CanSee( TargetActor ) ) { ReturnedMoveType = CheckNavigationFrom( TargetActor, GoalActor, GoalDistance ); if( ReturnedMoveType == MT_Success || ReturnedMoveType == MT_Near ) break; else NPList[ii].TargetActor = None; // no point considering this actor in the "can see" test below } } //DMTNS( "ReturnedMoveType #2: " $ EnumStr( enum'EMoveType', ReturnedMoveType ) ); if( ReturnedMoveType <= MT_None ) { //DMTNS( "try in sight targets" ); // try pathnodes even if player can see them for( ii=0; ii<ArrayCount(NPList); ii++ ) { TargetActor = NPList[ii].TargetActor; if( TargetActor == None ) break; ReturnedMoveType = CheckNavigationFrom( TargetActor, GoalActor, GoalDistance ); if( ReturnedMoveType == MT_Success || ReturnedMoveType == MT_Near ) break; } } } //DMTNS( "ReturnedMoveType #3: " $ EnumStr( enum'EMoveType', ReturnedMoveType ) ); return ReturnedMoveType; } //----------------------------------------------------------------------------- function bool RecoverFromMinZError() { local PlayerController PC; local Actor TargetActor; local vector TargetLocation; local int ii; local TDistanceInfo NPList[ MaxDistanceActors ]; PC = Level.PlayerControllerList; if( PC == None ) return false; // player is dead so it don't matter... GetNearbyPathNodes( Pawn, NPList, MinTeleportRangeMinZError, MaxTeleportRangeMinZError, true ); // try pathnodes out of player's sight for( ii=0; ii<ArrayCount(NPList); ii++ ) { TargetActor = NPList[ii].TargetActor; if( TargetActor == None ) break; if( !PC.CanSee( TargetActor ) ) { if( TeleportPawn( TargetActor ) ) { return true; } else { NPList[ii].TargetActor = None; // no point considering this actor in the "can see" test below } } } // try pathnodes even if player can see them for( ii=0; ii<ArrayCount(NPList); ii++ ) { TargetActor = NPList[ii].TargetActor; if( TargetActor == None ) break; if( TeleportPawn( TargetActor ) ) return true; } return false; } //----------------------------------------------------------------------------- function bool RecoverFromStuckError() { local PlayerController PC; local Actor TargetActor; local vector TargetLocation; local int ii; local TDistanceInfo NPList[ MaxDistanceActors ]; PC = Level.PlayerControllerList; if( PC == None ) return false; // player is dead so it don't matter... GetNearbyPathNodes( Pawn, NPList, MinTeleportRangeStuckError, MaxTeleportRangeStuckError, true ); // only try pathnodes out of player's sight for( ii=0; ii<ArrayCount(NPList); ii++ ) { TargetActor = NPList[ii].TargetActor; if( TargetActor == None ) break; if( !PC.CanSee( TargetActor ) ) { if( TeleportPawn( TargetActor ) ) { return true; } } } return false; } //----------------------------------------------------------------------------- function bool RandomizeStakeOutDir() { return false; } //----------------------------------------------------------------------------- // Pick a navigation point to look at that won't require looking too far away // from the given TargetActor. Useful when staking out and waiting for the // enemy to appear, not terribly useful if using cover and about to go hunting // to reacquire the enemy. function FindNewStakeOutDir( Actor TargetActor ) { local NavigationPoint N, Best; local vector Dir, EnemyDir; local float Dist, BestVal, Val; EnemyDir = Normal( TargetActor.Location - Pawn.Location ); for ( N=Level.NavigationPointList; N!=None; N=N.NextNavigationPoint ) { Dir = N.Location - Pawn.Location; Dist = VSize( Dir ); if( Dist < 800 && Dist > 100 ) { Val = ( EnemyDir dot Dir/Dist ); if( RandomizeStakeOutDir() ) Val += FRand(); if( Val > BestVal && LineOfSightTo( N ) ) { BestVal = Val; Best = N; } } } if( Best != None ) EnemyDetected( Best.Location + 0.5 * Pawn.CollisionHeight * vect(0,0,1) ); } //----------------------------------------------------------------------------- function ClearMoveAttempts() { NumMoveAttempts = 0; NumMoveRecoverAttempts = 0; } //----------------------------------------------------------------------------- function bool MoveAgain() { NumMoveAttempts++; return ( NumMoveAttempts < MaxMoveToActorAttempts ); } //----------------------------------------------------------------------------- function HoldSpot GetHoldSpot( Actor LocationActor ) { local HoldSpot HS; HS = LocationActor.Spawn( class'HoldSpot' ); if( HS != None ) { if( !HS.PhysicsVolume.bWaterVolume ) { // !!mdf-tbd: make sure the hold spot is on the ground if the NPC can't // fly (in case LocationActor was above the ground) class'UtilGame'.static.PlaceActorOnFloor( HS ); } } else { DMTN( "Warning: Can't create holdspot at given location" ); } //DMTNS( "GetHoldSpot returning" $ HS ); return HS; } //----------------------------------------------------------------------------- function ClearHoldSpot( out Actor HS ) { //DMTNS( "ClearHoldSpot clearing " $ HS ); if( HoldSpot(HS) != None ) { HS.Destroy(); HS = None; } } //----------------------------------------------------------------------------- // Called when all holdspots associated with this controller should be // destroyed and cleared, e.g. when NPC dies. function ClearHoldSpots() { //DMTNS( "ClearHoldSpots" ); ClearHoldSpot( TestMoveTarget ); } //----------------------------------------------------------------------------- function Actor GetSpecialGoal() { if( SpecialGoal != None && SpecialGoal.bDeleteMe ) SpecialGoal = None; return SpecialGoal; } //----------------------------------------------------------------------------- function float GetSpecialGoalDistance() { local float ReturnedDistance; if( TemporaryGoalDistance > 0.0 ) { ReturnedDistance = TemporaryGoalDistance; TemporaryGoalDistance = -1.0; } else { ReturnedDistance = SpecialGoalDistance; } return ReturnedDistance; } //----------------------------------------------------------------------------- function bool GetFaceSpecialGoal() { return bFaceSpecialGoal; } //----------------------------------------------------------------------------- // Mover has notifies controller that Pawn is underneath it function UnderLift( Mover M ) { local NavigationPoint N; // find nearest lift exit and go for that if( MoveTarget != None && LiftCenter(MoveTarget) != None ) for ( N=Level.NavigationPointList; N!=None; N=N.NextNavigationPoint ) if( LiftExit(N) != None && ( LiftExit( N ).LiftTag == M.Tag ) && ActorReachable( N ) ) { MoveTarget = N; return; } } //----------------------------------------------------------------------------- function HandleDestinationReached() { MoveTarget = None; Destination = Pawn.Location; } /* mdf-tbd: interface changed and base code does nothing now -- is this still needed? //----------------------------------------------------------------------------- // mdf-tbd: overridden so that NPCs won't duck until they actually hit // obstructions. tbd: event PrepareForMove( NavigationPoint Goal, int MaxRadius, int MaxHeight ) --> event PrepareForMove(NavigationPoint Goal, ReachSpec Path); { Goal.SuggestMovePreparation( Pawn ); } */ //----------------------------------------------------------------------------- function bool ShouldClearSpecialColliders() { return ( ControllerEnemy == None || StationaryPawn(ControllerEnemy) != None ); } //----------------------------------------------------------------------------- // Wrapper for FindPathToActor which calls ShouldClearSpecialColliders. function EPathResult GetPathToActor( Actor TargetActor, optional out Actor ReturnedActor, optional bool bIncludeDirect ) { return FindPathToActor( TargetActor, ReturnedActor, bIncludeDirect, true, ShouldClearSpecialColliders() ); } //----------------------------------------------------------------------------- // Sets Path to the given TargetActor if this is directly reachable, otherwise // tries to build a path to the target and sets Path to that. function EMoveType GetPathTo( Actor TargetActor, out Actor Path, optional float GoalDistance ) { local EMoveType ReturnedMoveType; //2002.11.23 !!mdf-tbd: check if at destination even if no goal distance given? //if( GoalDistance > 0.0 && AtDestinationActor( TargetActor, GoalDistance ) ) //DMTNS( "GetPathTo -- " $ TargetActor $ " calling AtDestinationActor" ); if( AtDestinationActor( TargetActor, GoalDistance ) ) { ReturnedMoveType = MT_Near; } else { #debug DMAIM( "GetPathTo -- " $ TargetActor $ " calling GetPathToActor" ); GetPathToActor( TargetActor, Path, true ); if( Path != None ) ReturnedMoveType = MT_Success; else ReturnedMoveType = MT_Error; } #debug DMAIM( "GetPathTo -- Path: " $ Path ); return ReturnedMoveType; } //----------------------------------------------------------------------------- // Used when moving towards a destination which could be moving (e.g. when // following another Pawn) to check if "close" to destination. function bool IsCloseToDynamicGoal( Actor Other, optional float DesiredDistance, optional bool bHasLineOfSightTo ) { local float PredictedDistance; local vector PredictedGoalLocation; local float PawnSpeed; if( Pawn.Base != None && Other.Base != None && Other.Base != Pawn.Base ) return false; if( DesiredDistance <= 0.0 ) DesiredDistance = DefaultIsCloseToDynamicGoalDistance; // compensate for target moving: use predicted intercept location if possible, otherwise default to other's current location PawnSpeed = VSize( Pawn.Velocity ); if( PawnSpeed ~= 0.0 || !class'UtilGame'.static.GetAimingDestination( Pawn, PawnSpeed, 0.0, Other, PredictedGoalLocation ) ) PredictedGoalLocation = Other.Location; // note: DesiredDistance assumed to imply the 2D CC to CC distance PredictedDistance = VSize2D( Pawn.Location - PredictedGoalLocation ) - Pawn.CollisionRadius - Other.CollisionRadius; //DMTNS( "IsCloseToDynamicGoal PredictedDistance: " $ PredictedDistance $ " DesiredDistance: " $ DesiredDistance ); if( PredictedDistance > DesiredDistance ) return false; // LOS to other? return bHasLineOfSightTo || LineOfSightTo( Other ); } /*----------------------------------------------------------------------------- Try to move to within GoalDistance units of the GoalActor (with reachability) if possible. Otherwise, move to the closest location from which the GoalActor can be seen. Don't bother moving if the move won't bring the NPC significantly closer to the GoalActor. !!mdf-tbd: also check RouteCache distance so that NPC doesn't go "miles" out of its way when it could stay where it is or move to a seeing (but not reachable) location instead? */ function EMoveType GetMoveTargetFollow( Actor GoalActor, out Actor Path, float GoalDistance ) { local TDistanceInfo NPList[ MaxDistanceActors ]; local Actor TargetActor; local EMoveType ReturnedMoveType; local EPathResult PathResult; local float CurDistance, NewDistance; local Actor FinalPath; local bool bHasLineOfSightTo; local int ii; #debug DMAIM( "GetMoveTargetFollow: " $ GoalActor ); if( GoalActor != None ) { bHasLineOfSightTo = LineOfSightTo( GoalActor ); //2002.11.23 !!mdf-tbd: line of sight takes precendence over distance if( !bHasLineOfSightTo ) { GoalDistance = FMin( MaxNoLOSFollowDistance, GoalDistance ); TemporaryGoalDistance = GoalDistance; } //2002.11.23 !!mdf-tbd: I don't think that using the predicted location to //possibly return MT_Near (which will stop the NPC) makes sense //if( !IsCloseToDynamicGoal( GoalActor, GoalDistance, bHasLineOfSightTo ) ) //DMTNS( " GetMoveTargetFollow checking if at GoalActor " $ GoalActor $ " using distance " $ GoalDistance ); if( AtDestinationActor( GoalActor, GoalDistance ) ) { //DMTNS( " close to " $ GoalActor ); // SendMessageNearPoint( GoalActor, 10.0 ); ReturnedMoveType = MT_Near; } else { // can we build a path to the goal? //DMTNS( " Path should be None here: " $ Path ); //ReturnedMoveType = GetPathToActor( GoalActor, Path, GoalDistance ); PathResult = GetPathToActor( GoalActor, Path, true ); //DMTNS( " GetMoveTargetFollow Path: " $ Path $ " PathResult: " $ EnumStr( enum'EPathResult', PathResult ) ); CurDistance = VSize( Pawn.Location - GoalActor.Location ); //!!mdf-tbd: this is already being done more-or-less in FindPathToward... // hmm, not really -- seeing plenty of cases where GetPathTo fails where this can succeed? if( PathResult == PR_None && (CurDistance > CloseEnoughDistance || !bHasLineOfSightTo) ) { // couldn't build a path to it -- try picking closest visible navigation point to target? //DMTNS( " no path to " $ GoalActor $ " -- trying to build path to closest NP" ); GetNearbyPathNodes( GoalActor, NPList, MinTeleportRangeMoveError, MaxTeleportRangeMoveError, false ); for( ii=0; ii<Min(16, ArrayCount(NPList)); ii++ ) { TargetActor = NPList[ii].TargetActor; if( TargetActor == None ) break; // can our goal actor see the navigation point (not taking fov into account) if( class'UtilGame'.static.ActorCanSeeActor( GoalActor, TargetActor, -1.0 ) ) { // make sure we can get there (we know that GoalActor isn't currently pathable...) ReturnedMoveType = GetPathTo( TargetActor, Path, GoalDistance ); if( Path != None ) { PathResult = PR_Visible; break; // found one } } } } if( Path != None ) { ReturnedMoveType = MT_Success; //DMTNS( "found path to " $ GoalActor $ ":" $ Path ); FinalPath = Path; for( ii=0; ii<ArrayCount(RouteCache); ii++ ) { if( RouteCache[ ii ] == None ) { FinalPath = RouteCache[ ii-1 ]; break; } //DMTNS( " " $ ii $ ": " $ RouteCache[ ii ] ); } //DMTNS( "checking if AtDestination " $ Path ); //NOTE: we don't pass in the destination distance here since that is relative to the goal actor if( AtDestinationActor( Path ) ) { //DMTNS( " yes" ); ReturnedMoveType = MT_Wait; } else if( Path != GoalActor && FinalPath != GoalActor && PathResult < PR_Reachable ) { //DMTNS( " no" ); NewDistance = VSize( FinalPath.Location - GoalActor.Location ); //DMTNS( "CurDistance: " $ CurDistance ); //DMTNS( "NewDistance: " $ NewDistance ); if( (CurDistance < CloseEnoughDistance || (CurDistance - NewDistance) < GetCloserThreshold) && bHasLineOfSightTo ) { // !!mdf-tbd: // already fairly close to goal OR path won't bring NPC // that much close to goal and goal is currently visible, // so just chill out at current location? ReturnedMoveType = MT_Wait; } } } else { // try again in a bit // /*~~*/ !!mdf-tbd: what to do now...? // NOTE: we could try finding the closest reachable/pathable location // but this could be expensive -- lets see how well this works for now // teleport? // if there is no pathnode (anchor) around the NPC, we pbly need to teleport him... //DMTNS( " found no Path to " $ GoalActor ); ReturnedMoveType = MT_Wait; } } } #debug DMAIM( "GetMoveTargetFollow returning Path: " $ Path $ " ReturnedMoveType: " $ EnumStr( enum'EMoveType', ReturnedMoveType ) ); //DMTNS( "GetMoveTargetFollow returning Path: " $ Path $ " ReturnedMoveType: " $ EnumStr( enum'EMoveType', ReturnedMoveType ) ); return ReturnedMoveType; } //----------------------------------------------------------------------------- function EMoveType HandleSetMoveTargetError( Actor GoalActor, float GoalDistance ) { local EMoveType ReturnedMoveType; NavigationError( ET_ExternalPath, "SetMoveTarget -- can't build path to destination " $ GoalActor ); // try to recover by teleporting if( UnderScriptControl() ) { U2P.MakeErrorObvious( ET_ExternalPath ); if( !U2P.bDisableErrorColors ) AddActor( Pawn, ColorBlue() ); ReturnedMoveType = RecoverFromNavigationError( GoalActor, GoalDistance, false ); if( !U2P.bDisableErrorColors && (ReturnedMoveType == MT_Success || ReturnedMoveType == MT_Near) ) AddCylinder( Pawn.Location, 4, 4, ColorBlue() ); } else { U2P.MakeErrorObvious( ET_InternalPath ); } return ReturnedMoveType; } //----------------------------------------------------------------------------- // mdf-tbi: generalize this and similar functions (all pathing/movement). function EMoveType SetMoveTarget( Actor GoalActor, optional float GoalDistance, optional bool bWaitForLanding ) { local Actor OldMoveTarget; local EMoveType ReturnedMoveType; // DMN( "Physics: " $ class'Util'.static.GetPhysicsString( Self ) ); // DMN( "Radius: " $ Pawn.CollisionRadius ); // DMN( "Height: " $ Pawn.CollisionHeight ); #debug DMAIM( "SetMoveTarget GoalActor:" $ GoalActor ); OldMoveTarget = MoveTarget; #debugbegin if( bVisibleAI ) HideActor( MoveTarget ); #debugend ReturnedMoveType = MT_None; MoveTarget = None; if( GoalActor != None && !GoalActor.bDeleteMe ) { if( bWaitForLanding && !GoalActor.bStatic && GoalActor.Physics == PHYS_Falling ) { //DMTNS( " SetMoveTarget: goal is falling!" ); ReturnedMoveType = MT_Wait; } else if( Pawn(GoalActor) == None ) { //DMTNS( " SetMoveTarget: goal is a non-Pawn!" ); ReturnedMoveType = GetPathTo( GoalActor, MoveTarget, GoalDistance ); } else { //DMTNS( " SetMoveTarget: goal is a Pawn!" ); ReturnedMoveType = GetMoveTargetFollow( GoalActor, MoveTarget, GoalDistance ); } // testing support if( U2P.bCauseMoveTargetNavError ) { #debug DMAIM( "testing navigation error recovery -- causing the move target to be MT_Error" ); U2P.bCauseMoveTargetNavError = false; ReturnedMoveType = MT_Error; } if( ReturnedMoveType == MT_Error ) ReturnedMoveType = HandleSetMoveTargetError( GoalActor, GoalDistance ); if( ReturnedMoveType != MT_Error ) { // MoveTarget might be none if already at / near goal #debugbegin if( bVisibleAI && MoveTarget != None ) ShowActor( MoveTarget ); #debugend // mdf-tbd: isn't it safer to reset NumMoveAttempts at BeginLabel? // NO -- NumMoveAttempts also needs to be reset here everytime the MoveTarget // changes since it is used to limit # times NPC tries to reach a given target. // We clear NumMoveAttempts here since any call to MoveToActor is preceeded with a // call to SetMoveTarget but we should also clear it whenever a new (final) // destination is specified in case the new and old MoveTarget happen to match if( ReturnedMoveType == MT_Wait || MoveTarget != OldMoveTarget || VSize( Pawn.Location - OldMoveLocation ) > Pawn.CollisionRadius ) ClearMoveAttempts(); OldMoveLocation = Pawn.Location; //2002.12.11 (mdf) why was I doing this? -- Destination is always set during/near //calls to MoveTarget etc. and shouldn't be set otherwise? /* if( MoveTarget != None ) Destination = MoveTarget.Location; else Destination = Pawn.Location; */ //2002.12.11 (mdf) why was I doing this? -- Focus is always set during/near //calls to MoveToward etc. and setting it here is borking turntoactor because //NPC might try to turn to an actor that its already facing. /* // determines which movement animation is used if( ScriptedFocus == None ) { if( Focus == None ) Focus = GoalActor; //? else Focus = MoveTarget; } else Focus = ScriptedFocus; */ } } // NOTE (mdf): we still return MT_None if given GoalActor was None (orders rescinded?) which will be treated // as an error by callers -- should callers not be flagging an error in this case? #debug DMAIM( "SetMoveTarget returning MoveTarget: " $ MoveTarget $ " ReturnedMoveType: " $ EnumStr( enum'EMoveType', ReturnedMoveType ) ); return ReturnedMoveType; } //----------------------------------------------------------------------------- function bool SetTestMoveTarget( Actor TargetActor, optional float MoveSpeed, optional ETacticalMoveType TMT ) { local bool bResult; local Actor NewMoveTarget; NewMoveTarget = TargetActor; if( Controller(TargetActor) != None ) NewMoveTarget = Controller(TargetActor).Pawn; if( Pawn(NewMoveTarget) != None ) NewMoveTarget = GetHoldSpot( NewMoveTarget ); if( NewMoveTarget != None ) { NewMoveTarget.bHidden = false; GotoState( TestMoveState ); bResult = true; } else if( TargetActor != None ) { #debug DMAI( "SetTestMoveTarget failed: " $ GetContext() ); } else { #debug WhatToDoNext( GetContext() ); #release WhatToDoNext(); bResult = true; } #debug DMAIM( "SetTestMoveTarget - bResult: " $ bResult $ " NewMoveTarget: " $ NewMoveTarget ); if( bResult ) { ClearHoldSpot( TestMoveTarget ); TestMoveTarget = NewMoveTarget; if( MoveSpeed <= 0.0 ) MoveSpeed = 1.0; TestMoveSpeed = MoveSpeed; TestTacticalMoveType = TMT; } return bResult; } //----------------------------------------------------------------------------- /* Assumes the desired destination is not directly reachable. Tries to set Destination to the location of the best waypoint, and returns true if successful. */ function bool FindBestPathToward( Actor TargetActor, bool bClearPaths ) { local Actor Path; local bool bSuccess; FindPathToActor( TargetActor, Path, false, bClearPaths, ShouldClearSpecialColliders() ); bSuccess = ( Path != None ); if( bSuccess ) { /* AddActor( Pawn, ColorOrange() ); AddActorAt( Pawn, MoveTarget.Location, ColorOrange() ); AddArrow( Pawn.Location, MoveTarget.Location, ColorOrange() ); */ MoveTarget = Path; Destination = Path.Location; } return bSuccess; } //----------------------------------------------------------------------------- // Find an inventory spot destination. function NavigationPoint SelectInventorySpotDestination() { local NavigationPoint N, ReturnedInventorySpot; local int ii; if( Pawn.bCanPickupInventory ) { ii = 0; for ( N=Level.NavigationPointList; N!=None; N=N.NextNavigationPoint ) { //NEW (mdf) -- temp (?) fix for massive terrain slowdown when tracing/pathing over large distances //if( InventorySpot(N) != None && VSize(Pawn.Location - N.Location) < 1200 ) //OLD if( InventorySpot(N) != None ) { //mdf-tbd: is this really what is wanted here -- this has a 50% chance //of sticking with the first IS. The odds of ever picking the last IS are //going to be something like 0.5 * 0.33 * 0.25 * ... Does this give even // odds to all inventory spots? ii++; if( ReturnedInventorySpot == None || Rand( ii ) == 0 ) ReturnedInventorySpot = N; } } #debug DMAIM( "SelectInventorySpotDestination iterated InventorySpots: " $ ReturnedInventorySpot ); } if( ReturnedInventorySpot == None ) { #debug DMAIM( "SelectInventorySpotDestination ReturnedInventorySpot=" $ ReturnedInventorySpot ); } else { #debug DMAIM( "SelectInventorySpotDestination ReturnedInventorySpot=" $ ReturnedInventorySpot $ " Dist=" $ VSize(Pawn.Location - ReturnedInventorySpot.Location)); } return ReturnedInventorySpot; } //----------------------------------------------------------------------------- // Force NPCs to either not get their move targets, or fail to reach their // destinations function ForceNavigationError( bool bScriptedStateMoves, bool bMoveTarget, bool bMinZ ) { if( U2P != None ) { U2P.bCauseMoveTargetNavError = false; U2P.bCauseScriptedNavError = false; if( bMinZ ) { U2P.FellOutOfWorld(); } else { U2P.bCauseMoveTargetNavError = bMoveTarget; U2P.bCauseScriptedNavError = bScriptedStateMoves; MoveTimer = -1.0; } } } //----------------------------------------------------------------------------- //@ COMBAT //----------------------------------------------------------------------------- function bool SplashDamageAttack() { return false; } function ImpalePawn(); function UnImpalePawn(); function NotifyMeleeDamagedEnemy( int Damage, Pawn Instigator, vector HitLocation, vector Momentum, class<DamageType> DamageType ); //----------------------------------------------------------------------------- // Given that we have an enemy and we are updating the attack behavior, check // for things like the enemy being too close to remain in the current stance or // to remain immobile. function CheckEnemyDistance( float EnemyDistance ) { local byte CurrentStance; VerifyMobility( EnemyDistance ); // maybe change stance due to enemy being too close? CurrentStance = LPawn.GetStance(); UpdateStance( CurrentStance, EnemyDistance ); } //----------------------------------------------------------------------------- function float GetLookedAtCos( Actor SeeingActor ) { if( Pawn(SeeingActor) != None ) return Pawn(SeeingActor).PeripheralVision; else return U2PBasic.DefaultLookedAtCos; } //----------------------------------------------------------------------------- function vector GetFireOffset( vector SourceLocation, vector TargetLocation ) { return class'UtilGame'.static.GetRotatedFireStart( Pawn, SourceLocation, rotator(TargetLocation - SourceLocation), U2PBasic.FireOffset ); } //----------------------------------------------------------------------------- function bool IgnoreTargetRange() { return false; } //----------------------------------------------------------------------------- function bool CheckMaxAttackRanges( float EnemyDistance, Actor TargetActor ) { //!!mdf-tbd: add special checks for TargetActor being a stationary Pawn? if( IsMobile() ) { if( U2PBasic.RangeMaxAttackMobileNoLOS == U2PBasic.RangeMaxAttackMobile || class'UtilGame'.static.ActorLookingAt( TargetActor, Pawn, GetLookedAtCos( TargetActor ) ) ) return ( EnemyDistance <= U2PBasic.RangeMaxAttackMobile ); else return ( EnemyDistance <= U2PBasic.RangeMaxAttackMobileNoLOS ); } else { if( U2PBasic.RangeMaxAttackStationaryNoLOS == U2PBasic.RangeMaxAttackStationary || class'UtilGame'.static.ActorLookingAt( TargetActor, Pawn, GetLookedAtCos( TargetActor ) ) ) return ( EnemyDistance <= U2PBasic.RangeMaxAttackStationary ); else return ( EnemyDistance <= U2PBasic.RangeMaxAttackStationaryNoLOS ); } } //----------------------------------------------------------------------------- function bool CheckTargetInAttackRange( bool bTest ) { local float EnemyDistance; local Actor TargetActor; local Actor HitActor; local vector HitLocation, HitNormal; local bool bResult; TargetActor = GetTarget(); if( Pawn == None || TargetActor == None ) { bResult = false; } else if( IgnoreTargetRange() ) { bResult = true; } else if( U2PBasic.RangeMinAttack > 0.0 || U2PBasic.bHasMaxAttackRanges ) { bResult = true; //if( !bTest ) // DMTNS( "CheckTargetInAttackRange TargetActor: " $ TargetActor ); // NOTE: we don't even need to do this trace if there are no active force fields in the level... if( Level.HasSpecialColliders() ) { // see if firing through an enemy XMP item? HitActor = Pawn.Trace( HitLocation, HitNormal, TargetActor.Location, GetFireOffset( Pawn.Location, TargetActor.Location ), true ); if( HitActor != None && HitActor != TargetActor && !HitActor.bWorldGeometry && !HitActor.bStatic && // could be a ForceWallCollider? StationaryPawn(HitActor) != None && OKToHit( HitActor, HitLocation, HitNormal ) ) { //if( !bTest ) // DMTNS( " trace hit " $ HitActor ); //TargetActor = HitActor; // !!mdf-tbd: temp hack fix so NPCs will always shoot at an enemy through a force field // regardless of the distance. What we *should* pbly be doing here is changing the TargetActor and // using the distance to that but there are other issues -- the izarians won't close properly // currently (pbly applies to other NPCs too). I'll check this hack fix in then look into the // other issues. TargetActor = None; } } if( TargetActor != None ) { EnemyDistance = VSize( TargetActor.Location - Pawn.Location ); if( EnemyDistance < U2PBasic.RangeMinAttack ) { bResult = false; } else if( U2PBasic.bHasMaxAttackRanges ) { bResult = CheckMaxAttackRanges( EnemyDistance, TargetActor ); } } } else { bResult = true; } //if( !bTest ) // DMTNS( "CheckTargetInAttackRange bResult: " $ bResult ); return bResult; } //----------------------------------------------------------------------------- function UpdateAcceleration( Actor TargetActor, float AccelerationChangeLimit, float MeleeAccelRate, float MeleeSpeed ) { local vector OldAccelerationNormal, NewAccelerationNormal; local vector Axis; local float CosAngle; if( TargetActor != None && VSize( TargetActor.Velocity ) > 10.0 ) { OldAccelerationNormal = Normal( Pawn.Acceleration ); NewAccelerationNormal = Normal( TargetActor.Location - Pawn.Location ); CosAngle = NewAccelerationNormal dot OldAccelerationNormal; if( Abs(CosAngle) < AccelerationChangeLimit ) { // constrain acceleration change Axis = Normal( OldAccelerationNormal cross NewAccelerationNormal ); NewAccelerationNormal = Normal( RotateAngleAxis( OldAccelerationNormal, Axis, ACos(AccelerationChangeLimit)*RadiansToDegrees*DegreesToRotationUnits ) ); } // apply new acceleration if( MeleeAccelRate <= 0.0 ) MeleeAccelRate = Pawn.default.AccelRate; Pawn.Acceleration = MeleeAccelRate * NewAccelerationNormal; /* if( MeleeSpeed > 0.0 )\ Pawn.Velocity = MeleeSpeed * Normal(Pawn.Velocity) * Pawn.default.GroundSpeed; */ } else if( Pawn.Physics == PHYS_Walking ) StopMovement( true, false ); // don't push-move around a more-or-less stationary target if walking //DMTNS( "UpdateAcceleration Speed: " $ VSize( Pawn.Velocity ) $ " Acceleration: " $ VSize( Pawn.Acceleration ) ); } //----------------------------------------------------------------------------- function float GetAttackRating( Pawn Other ) { return 0.3; // mdf-tbd: add property for this for tweaking various basic NPCs } //----------------------------------------------------------------------------- function float GetFireRating() { return 0.3; } //----------------------------------------------------------------------------- function bool CanDodge( optional bool bIgnoreFalling ) { return ( U2PBasic != None && Level.TimeSeconds > DodgeEnableTime && U2PBasic.IsStanding() && U2PBasic.Health > 0 && (U2PBasic.Physics == PHYS_Walking || (bIgnoreFalling && U2PBasic.Physics == PHYS_Falling)) ); } //----------------------------------------------------------------------------- function ExecuteDodge( bool bLeft, vector DodgeDestination ) { //DMTNS( "ExecuteDodge bLeft: " $ bLeft $ " Distance: " $ VSize( DodgeDestination - Pawn.Location ) ); //AddArrow( Pawn.Location, DodgeDestination, ColorGreen() ); U2PBasic.DodgeDestination = DodgeDestination; Destination = Pawn.Location; MoveTarget = None; if( bLeft ) U2P.Dodge( DCLICK_Left, U2PBasic.bJumpDodges ); else U2P.Dodge( DCLICK_Right, U2PBasic.bJumpDodges ); } //----------------------------------------------------------------------------- // !!mdf-tbd: this still seems like a pretty flaky test if the NPC is on uneven // ground for example. // NOTE: hard-coded currently to try dodging between 150 and 240 units. function bool VerifyJumpDodgeVector( vector DuckDir, out vector DodgeDestination ) { local vector HitLocation, HitNormal, Extent; local Actor HitActor; local float HitDistance; Extent.X = Pawn.CollisionRadius; Extent.Y = Pawn.CollisionRadius; Extent.Z = Pawn.CollisionHeight; DodgeDestination = Pawn.Location + U2PBasic.DodgeDistance*DuckDir; //AddArrow( Pawn.Location, DodgeDestination ); HitActor = Pawn.Trace( HitLocation, HitNormal, DodgeDestination, Pawn.Location, false, Extent ); if( HitActor != None ) { //AddCylinder( HitLocation, 4, 4, ColorRed() ); HitDistance = VSize( HitLocation - Pawn.Location ); //DMTNS( "VerifyJumpDodgeVector hit " $ HitActor $ "Distance: " $ VSize( HitLocation - Pawn.Location ) ); if( HitDistance < 150 ) { //DMTNS( "VerifyJumpDodgeVector return false " $ GetContext() ); return false; } DodgeDestination = Pawn.Location + HitDistance*DuckDir; } // make sure didn't dodge off a ledge HitActor = Pawn.Trace( HitLocation, HitNormal, DodgeDestination - Pawn.MaxStepHeight * vect(0,0,1), DodgeDestination, false, Extent ); if( HitActor == None ) { //DMTNS( "VerifyJumpDodgeVector return false " $ GetContext() ); return false; } return true; } //----------------------------------------------------------------------------- // We will use MoveToPoint to move the cylinder so do a reachability test. // !!mdf-tbd: should we always use this test? function bool VerifyRollDodgeVector( vector DuckDir, out vector DodgeDestination ) { local vector HitLocation, HitNormal, Extent; local Actor HitActor; local bool bOldCanJump; local bool bResult; // assume that the ground is sloped at no more than 45 degrees and find // point above ground where NPC should end up DuckDir.Z = 0; DodgeDestination = Pawn.Location + U2PBasic.DodgeDistance*DuckDir; // move up by same amount + padding DodgeDestination.Z += 1.25*U2PBasic.DodgeDistance; // trace down until we hit the ground (allow for ground falling away) //!!mdf-tbd: use extents? -- pbly best to expose MoveActor HitActor = Pawn.Trace( HitLocation, HitNormal, DodgeDestination - vect(0,0,1024), DodgeDestination, false ); if( HitActor == None ) return false; DodgeDestination = HitLocation + vect(0,0,1) * Pawn.CollisionHeight; //AddCylinder( DodgeDestination, 4, 4, ColorMagenta() ); bOldCanJump = Pawn.bCanJump; Pawn.bCanJump = false; bResult = PointReachable( DodgeDestination ); Pawn.bCanJump = bOldCanJump; return bResult; } //----------------------------------------------------------------------------- function TryToDodge( vector DuckDir, bool bDuckLeft ) { local vector DodgeDestination; local bool bSuccess; //DMTNS( "TryToDodge" ); if( Pawn.PhysicsVolume.bWaterVolume || Pawn.PhysicsVolume.Gravity.Z > Pawn.PhysicsVolume.default.Gravity.Z ) { //DMTNS( "TryToDodge return " $ GetContext() ); return; } // try in desired direction if( U2PBasic.bJumpDodges ) bSuccess = VerifyJumpDodgeVector( DuckDir, DodgeDestination ); else bSuccess = VerifyRollDodgeVector( DuckDir, DodgeDestination ); if( !bSuccess ) { // try in opposite direction //DMTNS( " failed -- reverse direction" ); bDuckLeft = !bDuckLeft; DuckDir *= -1; if( U2PBasic.bJumpDodges ) bSuccess = VerifyJumpDodgeVector( DuckDir, DodgeDestination ); else bSuccess = VerifyRollDodgeVector( DuckDir, DodgeDestination ); if( !bSuccess ) { //DMTNS( "TryToDodge return " $ GetContext() ); return; } } //DMTNS( "calling ExecuteDodge" ); ExecuteDodge( bDuckLeft, DodgeDestination ); } //----------------------------------------------------------------------------- // Assumes IncomingDirection is normalized. function HandleIncoming( Actor IncomingActor, vector IncomingDirection, float IncomingSpeed ) { local vector PawnToIncomingVector, PawnToIncomingNormal, LeftVector; local vector FuturePawnPosition, FutureIncomingPosition; local float IncomingDistance, FutureMissDistance; local float ApproximateIntersectTime, CosToIntersect; local bool bDodgeRight; //AddCylinder( IncomingActor.Location, 4, 4, ColorRed() ); //DMTNS( "HandleIncoming : " $ IncomingActor $ " projectile speed: " $ IncomingSpeed $ " Pawn speed: " $ VSize( Pawn.Velocity ) ); if( U2PBasic == None || !FDecision( U2PBasic.DodgeProjectileOdds ) ) return; // doesn't dodge incoming projectiles if( !CanDodge() ) return; /* tbd: if( GetSkill() < FRand() ) return; */ PawnToIncomingVector = IncomingActor.Location - Pawn.Location; //tbd: what's the best approach, add properties for all of these, //support dodging by ducking, jumping up etc. PawnToIncomingNormal = Normal( PawnToIncomingVector ); if( PawnToIncomingNormal dot vector(Pawn.Rotation) < 0.10 ) { //DMTNS( "NPC not facing incoming" ); return; // NPC isn't looking enough towards incoming actor } // if close/fast decrease odds of reacting IncomingDistance = VSize( PawnToIncomingVector ); //DMTNS( "IncomingDistance: " $ IncomingDistance ); // see if projectile is likely to hit NPC // assumes projectile speed much higher than NPC speed and assumes NPC won't change velocity ApproximateIntersectTime = IncomingDistance / VSize( IncomingSpeed*IncomingDirection - Pawn.Velocity ); // where will projectile, NPC be at that time? FuturePawnPosition = Pawn.Location + ApproximateIntersectTime * Pawn.Velocity; FutureIncomingPosition = IncomingActor.Location + ApproximateIntersectTime * IncomingDirection * IncomingSpeed; //AddCylinder( FuturePawnPosition, 6, 6, ColorCyan() ); //AddCylinder( FutureIncomingPosition, 8, 8, ColorOrange() ); FutureMissDistance = VSize( FuturePawnPosition - FutureIncomingPosition ); //DMTNS( "FutureMissDistance: " $ FutureMissDistance ); if( FutureMissDistance < (FMax( Pawn.CollisionRadius, Pawn.CollisionHeight ) + INCOMINGCOLLISIONFUDGE) ) { // tbd: decrease odds as angle to actor relative to NPC's view direction increases LeftVector = Normal( vector(Pawn.Rotation) cross vect(0,0,1) ); //AddArrow( Pawn.Location, FutureIncomingPosition, ColorRed() ); //AddArrow( Pawn.Location, Pawn.Location + 256.0*LeftVector, ColorGreen() ); //AddArrow( Pawn.Location, Pawn.Location + 256.0*vector(Pawn.Rotation), ColorYellow() ); CosToIntersect = Normal( FutureIncomingPosition - Pawn.Location) dot LeftVector; //DMTNS( "Cos: " $ CosToIntersect ); bDodgeRight = false; if( CosToIntersect < -0.1 ) bDodgeRight = true; // intercept point to right else if( CosToIntersect < 0.1 && FRand() < 0.50 ) bDodgeRight = true; // intercept point not to left //DMTNS( " calling TryToDodge: " $ bDodgeRight ); if( bDodgeRight ) // note: LeftVector is wrt Pawn, TryToDodge uses wrt viewer in front of NPC TryToDodge( LeftVector, false ); else TryToDodge( -LeftVector, true ); } } //----------------------------------------------------------------------------- function ShotFiredNotification( Pawn Shooter, vector FireDir, class<Projectile> ProjectileClass, float ProjSpeed ) { HandleIncoming( Shooter, Normal( FireDir ), ProjSpeed ); } //----------------------------------------------------------------------------- // Returns true if NPC should face enemy/target while heading towards next // MoveTarget based on how recently the enemy was seen and whether the NPC is // ready to fire etc. function bool FaceTarget( float F ) { local float RelativeDir; local float TimeSinceEnemyLastSeen; if( !Pawn.bCanStrafe ) return false; TimeSinceEnemyLastSeen = GetTimeSinceEnemyLastSeen(); if( TimeSinceEnemyLastSeen > 7.5 - F ) return false; //2002.12.18 (mdf) NPCs having trouble attacking turrets because they aren't facing them? //Why would we ever not want them to face an enemy just because its a StationaryPawn which isn't in sight? //if( !IsPreparedToAttack( true ) || ControllerEnemy == None || (StationaryPawn(ControllerEnemy) != None && !LineOfSightTo( ControllerEnemy )) ) if( !IsPreparedToAttack( true ) || ControllerEnemy == None ) return false; if( GetSkill() > 0.75 && IsPreparedToFire( true ) ) return true; if( TimeSinceEnemyLastSeen > 4 - F ) return false; RelativeDir = Normal( ControllerEnemy.Location - Pawn.Location - vect(0,0,1) * (ControllerEnemy.Location.Z - Pawn.Location.Z) ) dot Normal( MoveTarget.Location - Pawn.Location - vect(0,0,1) * (MoveTarget.Location.Z - Pawn.Location.Z) ); if( RelativeDir > NeedToTurnAngleCos ) return true; if( IsPreparedToMelee( true ) && RelativeDir < 0 ) return false; if( FRand() < 0.2 * (2 - F) ) return true; if( 0.5 * 8*GetSkill() - F * FRand() + RelativeDir + 0.6 + U2PBase.StrafingAbility < 0 ) return false; return true; } //----------------------------------------------------------------------------- function bool NeedToTurn( vector TargetLocation, float CosAngle ) { local vector LookDir, AimDir; LookDir = vector(Pawn.Rotation); LookDir.Z = 0; LookDir = Normal( LookDir ); AimDir = TargetLocation - Pawn.Location; AimDir.Z = 0; AimDir = Normal( AimDir ); #debug DMAIA( "NeedToTurn: " $ TargetLocation $ " returning " $ ((LookDir dot AimDir) < CosAngle) ); return ((LookDir dot AimDir) < CosAngle); } //----------------------------------------------------------------------------- // Returns true if there is a nearby barrier at eyeheight, and changes // FocalPoint to a suggested place to look. function bool ViewObstructed( float CheckWallDistance ) { local Actor HitActor; local vector HitLocation, HitNormal, ViewSpot, ViewDist, LookDir; if( Pawn == None ) return false; LookDir = vector( Rotation ); ViewSpot = Pawn.Location + Pawn.BaseEyeHeight * vect(0,0,1); ViewDist = LookDir * CheckWallDistance; HitActor = Pawn.Trace( HitLocation, HitNormal, ViewSpot + ViewDist, ViewSpot, false ); if( HitActor == None ) return false; ViewDist = Normal( HitNormal cross vect(0,0,1) ) * CheckWallDistance; if( FRand() < 0.5 ) ViewDist *= -1; Focus = None; if( Pawn.FastTrace( ViewSpot + ViewDist, ViewSpot ) ) { FocalPoint = Pawn.Location + ViewDist; return true; } if( Pawn.FastTrace( ViewSpot - ViewDist, ViewSpot ) ) { FocalPoint = Pawn.Location - ViewDist; return true; } FocalPoint = Pawn.Location - LookDir * 300; return true; } //----------------------------------------------------------------------------- function final SetSharedTimer( float DelaySeconds, bool bLoop ) { #debug DMAIA( "SetSharedTimer -- DelaySeconds: " $ DelaySeconds $ " bLoop: " $ bLoop ); SetTimer( DelaySeconds, bLoop ); } //----------------------------------------------------------------------------- // This should never be called for the new AI. Overridden to not assert for // the old AI since this still makes use of global shared timers. function SharedTimerEvent() { #debug DMAIA( "SharedTimerEvent" ); DMAssert( false, GetContext() $ " Global.SharedTimerEvent called -- should never happen" ); } /*----------------------------------------------------------------------------- The (new) AI code doesn't generally make use of the global timer, preferring instead to use AddTimer to map timers to specific functions. In a few cases, its convenient to simply use a global timer within a specific state (the timer should be cleared before leaving that state). If the above global SharedTimerEvent gets called (because a state didn't clean up after itself), an assertion will be logged (the old AI won't assert). */ event final Timer() { SharedTimerEvent(); } //----------------------------------------------------------------------------- //@ AIMING //----------------------------------------------------------------------------- function bool TryToHit( Actor TargetActor, float TargetDistance, float SpreadDegrees, bool bLOSToTarget, float TryToHitBaseOddsMin, float TryToHitBaseOddsMax, float TryToHitBaseDistance, float TryToHitMinMissDistance, float TryToHitMaxHitDistance ) { local Actor HitActor; local vector HitNormal, HitLocation; local int ii; local bool bFoundBlockingActors, bResult; //bResult = true; goto skipcheck; // uncomment to always try to hit for testing //bResult = false; goto skipcheck; // uncomment to always try to miss for testing // first check for any smoke etc. in the way bTargetObscured = false; if( bLOSToTarget ) { // flip trace flags temporarily so a trace will hit CoverProxy actors for( ii=0; ii<Level.CoverActorList.Length; ii++ ) { if( CoverProxy(Level.CoverActorList[ ii ]) != None ) { Level.CoverActorList[ ii ].SetCollision( true, true, true ); bFoundBlockingActors = true; } } if( bFoundBlockingActors ) { // do the trace //AddArrow( Pawn.Location, TargetActor.Location, ColorOrange() ); HitActor = Pawn.Trace( HitLocation, HitNormal, TargetActor.Location, Pawn.Location, true ); bTargetObscured = (CoverProxy(HitActor) != None ); //!!mdf-tbr: //assert( bTargetObscured || HitActor == None || HitActor == TargetActor ); // restore trace flags temporarily so a trace will hit CoverProxy actors for( ii=0; ii<Level.CoverActorList.Length; ii++ ) { if( CoverProxy(Level.CoverActorList[ ii ]) != None ) { Level.CoverActorList[ ii ].SetCollision( false, false, false ); } } } } //DMTNS( "Blocked by smoke: " $ bTargetObscured ); if( bTargetObscured ) { bResult = FDecision( BlockedByCoverHitOdds ); } else { bResult = class'UtilGame'.static.TryToHit( Pawn, TargetActor, TargetDistance, SpreadDegrees, Pawn.LastPainAnimTime, MaxAffectedByHitTime, LastAcquireTime, MaxAffectedByAcquisitionTime, TryToHitBaseOddsMin, TryToHitBaseOddsMax, TryToHitBaseDistance, TryToHitMinMissDistance, TryToHitMaxHitDistance, TryToHitBaseSpeed, TryToHitBaseSpeedOdds ); } skipcheck: #debugbegin /* if( bResult ) { Hits++; DMT( "Hits: " $ class'Util'.static.PadString( Hits, 4, true ) $ " Misses: " $ class'Util'.static.PadString( Misses, 4, true ) $ " (" $ class'Util'.static.GetFloatString( float(Hits)/float(Hits+Misses), 3 ) $ ") hit!" ); } else { Misses++; DMT( "Hits: " $ class'Util'.static.PadString( Hits, 4, true ) $ " Misses: " $ class'Util'.static.PadString( Misses, 4, true ) $ " (" $ class'Util'.static.GetFloatString( float(Hits)/float(Hits+Misses), 3 ) $ ") miss!" ); } */ #debugend return bResult; } // TryToHit /*----------------------------------------------------------------------------- ProjStart: location from which shot will be fired ProjSpeed: projectile speed TargetActor: actor we're trying to hit AimLocation: location at which we are aiming (e.g. could be at last seen position) MaxMissTargetDistance: if trace to target blocked, max distance by which NPC can miss bCanHitOtherActors: if true, succeeds even if trace hits a Pawn which isn't the TargetActor as long as its ok to hit it (e.g. another enemy, an enemy force field etc.) Returns true if the NPC can shoot from the ProjStart at the given AimLocation and will either hit the given target actor or won't miss it by much or (if bCanHitOtherActors=true) will hit an Actor which is ok to hit anyway). */ function bool TestAimLocation( vector ProjStart, float ProjSpeed, Actor TargetActor, vector AimLocation, float MaxMissTargetDistance, bool bCanHitOtherActors ) { local bool bResult; local Actor HitActor; local vector HitNormal, HitLocation; local float HitDistance, HitTime, HitActorSpeed; HitActor = Pawn.Trace( HitLocation, HitNormal, AimLocation, ProjStart, true ); bLastAimLocationHitFriendly = false; if( HitActor == None || HitActor == TargetActor ) { // didn't hit anything bResult = true; } else { HitDistance = VSize( HitLocation - AimLocation ); //DMTNS( " TestAimLocation hit " $ HitActor $ " at " $ HitDistance $ " bCanHitOtherActors: " $ bCanHitOtherActors ); // 2002.12.05 (mdf) fix so that hitting non-Pawn actors (e.g. // ForceWallColliders) is handled correctly. if( HitActor.bWorldGeometry || HitActor.bStatic ) { // trace hit world geometry / static actor -- return true if hit location fairly close to aim location //DMTNS( " hit geometry / static actor" ); bResult = ( HitDistance <= MaxMissTargetDistance ); } else { // trace hit dynamic, non-geometry actor (not the TargetActor) -- see if ok to hit if( bCanHitOtherActors ) { if( OKToHit( HitActor, HitLocation, HitNormal ) ) { // not a friend -- fire away //DMTNS( " not a friend" ); bResult = true; } else { if( Pawn(HitActor) != None && StationaryPawn(HitActor) == None && !HitActor.IsA( 'ForceWallCollider') ) //!!mdf: refactor IsA { // friendly pawn -- return true if we're not likely to hit it HitTime = HitDistance / ProjSpeed; //DMTNS( " HitTime: " $ HitTime ); HitActorSpeed = VSize( HitActor.Velocity ); //2002.12.08 (mdf) friendly Pawn could be moving in line with enemy so //check vs its collision radius doesn't really make sense and there's //pbly no point in checking the perpendicular component since the friend //could change direction or another friend could run in the way -- just //go off the HitTime? //DMTNS( " HitTime: " $ HitTime $ " HitActorSpeed: " $ HitActorSpeed ); //HitActorSpeed = VSize( HitActor.Velocity ); //bResult = ( HitTime > 0.5 && (HitActorSpeed > 4*HitActor.CollisionRadius || HitTime > 2.0) ); bResult = (HitTime > 2.0); } if( !bResult ) bLastAimLocationHitFriendly = true; } } } } //DMTNS( " TestAimLocation ProjSpeed: " $ ProjSpeed ); //DMTNS( " TestAimLocation bResult: " $ bResult ); //if( bResult ) // AddArrow( ProjStart, AimLocation, ColorGreen() ); //else // AddArrow( ProjStart, AimLocation, ColorRed() ); return bResult; } // TestAimLocation /*----------------------------------------------------------------------------- ProjStart: location from which shot will be fired ProjSpeed: projectile speed TargetActor: actor we're trying to hit AimLocation: location at which we are aiming (e.g. could be at last seen position) MaxMissDistance: if trace to target blocked, max distance by which NPC can miss Returns true if the NPC can shoot from the ProjStart at the given AimLocation and won't hit anything close by itself. TestAimLocation (above) is used when trying to find a good location to aim at whereas this function checks whether the location at which we are aiming in order to intentionally miss will cause the NPC to blow itself up or look stupid (e.g. by shooting into a wall at close range). If this test fails, the NPC will probably move to a different location. */ function bool TestMissLocation( vector ProjStart, float ProjSpeed, Actor TargetActor, vector AimLocation, float MinAvoidSelfDistance ) { local bool bResult; local Actor HitActor; local vector HitNormal, HitLocation; local float HitDistance, HitTime;//, HitActorSpeed; //DMTNS( "ProjSpeed: " $ ProjSpeed ); //AddArrow( ProjStart, AimLocation, ColorGreen() ); //HitActor = Pawn.Trace( HitLocation, HitNormal, AimLocation, ProjStart, false ); //bResult = ( HitActor == None || HitActor.bWorldGeometry || MaxDistance <= 0.0 || VSize( HitLocation - TargetLocation ) < MaxDistance ); HitActor = Pawn.Trace( HitLocation, HitNormal, AimLocation, ProjStart, true ); bLastAimLocationHitFriendly = false; if( HitActor == None || HitActor == TargetActor ) { // didn't hit anything bResult = true; } else { HitDistance = VSize( HitLocation - Pawn.Location ); //DMTNS( " TestMissLocation hit " $ HitActor $ " at " $ HitDistance ); if( HitDistance >= MinAvoidSelfDistance ) { // we didn't hit something too close to self // 2002.12.05 (mdf) fix so that hitting non-Pawn actors (e.g. // ForceWallColliders) is handled correctly. if( HitActor.bWorldGeometry || HitActor.bStatic ) { // trace hit world geometry / static actor //DMTNS( " hit geometry / static actor" ); bResult = true; } else { // trace hit dynamic, non-geometry actor (not the TargetActor) -- see if ok to hit if( OKToHit( HitActor, HitLocation, HitNormal ) ) { // not a friend -- fire away //DMTNS( " not a friend" ); bResult = true; } else { if( Pawn(HitActor) != None && StationaryPawn(HitActor) == None && !HitActor.IsA( 'ForceWallCollider') ) //!!mdf: refactor IsA { // friendly pawn -- return true if we're not likely to hit it HitTime = HitDistance / ProjSpeed; //DMTNS( " HitTime: " $ HitTime ); //2002.12.08 (mdf) friendly Pawn could be moving in line with enemy so //check vs its collision radius doesn't really make sense and there's //pbly no point in checking the perpendicular component since the friend //could change direction or another friend could run in the way -- just //go off the HitTime? //DMTNS( " HitTime: " $ HitTime $ " HitActorSpeed: " $ HitActorSpeed ); //HitActorSpeed = VSize( HitActor.Velocity ); //bResult = ( HitTime > 0.5 && (HitActorSpeed > 4*HitActor.CollisionRadius || HitTime > 2.0) ); bResult = (HitTime > 2.0); } if( !bResult ) bLastAimLocationHitFriendly = true; } } } } //DMTNS( " TestMissLocation bResult: " $ bResult ); return bResult; } // TestMissLocation //----------------------------------------------------------------------------- function vector GetMissVector( Actor TargetActor, int PitchError ) { return class'UtilGame'.static.GetMissVector( Pawn, TargetActor, Pawn.LastPainAnimTime, MaxAffectedByHitTime, MaxHitMissMultiplier, MinHitPitchError, MaxHitPitchError, LastAcquireTime, MaxAffectedByAcquisitionTime, MaxAcquireMissMultiplier, MinAcquirePitchError, MaxAcquirePitchError, bTargetObscured, PitchError ); } // GetMissVector //----------------------------------------------------------------------------- function float GetDamageRadius( class<Projectile> ProjectileClass ) { if( ProjectileClass != None ) return ProjectileClass.default.DamageRadius; else return 0.0; } //----------------------------------------------------------------------------- function float GetTimeOutTolerance( class<Projectile> ProjectileClass ) { if( ProjectileClass != None ) return 4.0 * GetDamageRadius( ProjectileClass ); else return 0.0; } // GetTimeOutTolerance //----------------------------------------------------------------------------- function bool GetTossedAim( class<Projectile> ProjectileClass, float ProjSpeed, vector ProjStart, float WeaponFireSpread, Actor TargetActor, out vector TargetLocation, float TargetDistance, bool bLOSToTarget, out rotator ReturnedRotation ) { local float Theta, InterceptTime; local bool bUseHigh; local bool bSuccess; local vector MissVector; local float MissDistance; local int PitchError; local float UseHighOdds; local float MaxRange; //DMTNS( " BEGIN GetTossedAim TargetActor: " $ TargetActor ); // maybe use high trajectory if target not too close and projectile will get there within some delta before it explodes UseHighOdds = U2PBasic.PreferHighTrajectoryOdds; if( bLOSToTarget ) { // don't use high if target is visible & within 50% of max range (looks bad // having grenade aimed way high in these situatios) MaxRange = class'UtilGame'.static.GetMaxRange( Pawn, ProjectileClass, ProjSpeed ); if( TargetDistance < (0.5 * MaxRange) ) UseHighOdds = 0.0; } //DMT( " UseHighOdds: " $ UseHighOdds ); bUseHigh = FDecision( UseHighOdds ); if( bLOSToTarget ) { // try to predict target's location since we can see it class'UtilGame'.static.GetBestPredictedProjectileLocation( Pawn, TargetActor, ProjectileClass, ProjSpeed, 0.0, ProjStart, TargetDistance, bUseHigh, TargetLocation ); //AddActorAt( TargetActor, TargetLocation, ColorMagenta() ); } if( bUseHigh ) { //DMT( " GetTossedAim: prefering high trajectory" ); bSuccess = class'UtilGame'.static.GetVerifiedInverseTrajectory( Pawn, ProjectileClass, ProjSpeed, ProjStart, TargetLocation, TargetActor, TRAJ_PreferHigh, Theta, InterceptTime, /*Extents*/, GetTimeOutTolerance( ProjectileClass ) ); } else { //DMT( " GetTossedAim: prefering low trajectory" ); bSuccess = class'UtilGame'.static.GetVerifiedInverseTrajectory( Pawn, ProjectileClass, ProjSpeed, ProjStart, TargetLocation, TargetActor, TRAJ_PreferLow, Theta, InterceptTime, /*Extents*/, GetTimeOutTolerance( ProjectileClass ) ); } if( !bSuccess ) { //DMT( " GetTossedAim: no solution -- trying 45 degrees" ); // try firing at 45 degrees to achieve max range? Theta = -UtilGame.Radians45; bSuccess = class'UtilGame'.static.VerifyTrajectory( Pawn, ProjectileClass, ProjSpeed, ProjStart, TargetLocation, TargetActor, Theta, /*InterceptTime*/, /*Extents*/, GetTimeOutTolerance( ProjectileClass ) ); } if( bSuccess ) { if( !TryToHit( TargetActor, TargetDistance, WeaponFireSpread, bLOSToTarget, TryToHitTossedBaseOddsMin, TryToHitTossedBaseOddsMax, TryToHitTossedBaseDistance, TryToHitTossedMinMissDistance, TryToHitTossedMaxHitDistance ) ) { //DMT( " Trying to miss" ); // muck with pitch and/or rotation so NPC will probably miss MissVector = GetMissVector( TargetActor, PitchError ); MissDistance = 2*TargetActor.CollisionRadius + GetDamageRadius( ProjectileClass ) * TargetDistance / TryToHitTossedMaxHitDistance; TargetLocation += MissVector * MissDistance; TargetLocation.Z += TargetActor.CollisionHeight - 2*FRand() * TargetActor.CollisionHeight; } //#debug DMAIA( " calling AdjustToss #1: " $ ProjectileClass ); ReturnedRotation = rotator(TargetLocation - ProjStart); // set the pitch if( Theta < 0 ) ReturnedRotation.Pitch = RadiansToDegrees * -Theta * DegreesToRotationUnits; else ReturnedRotation.Pitch = 65535 - RadiansToDegrees * Theta * DegreesToRotationUnits; if( PitchError != 0 ) class'Util'.static.IncrementRotatorParam( ReturnedRotation.Pitch, PitchError ); } #debug DMAIA( " GetTossedAim: " $ bSuccess ); return bSuccess; } // GetTossedAim //----------------------------------------------------------------------------- function bool GetLastSeenAimLocation( class<Projectile> ProjectileClass, float ProjSpeed, vector ProjStart, float WeaponFireSpread, Actor TargetActor, float TargetDistance, out vector TargetLocation ) { local bool bAimingAtFeet; local bool bSuccess; local float RandVal, MissDistance, ZShift; local vector SavedTargetLocation, OriginalTargetLocation; local vector MissVector2D; //DMTNS( "Aiming at last seen position" ); OriginalTargetLocation = TargetLocation; // in case the target was falling when last seen, check whether the target // location should be moved to the ground (but don't trace too far) TargetLocation = TargetActor.FallLanding( TargetLocation, vect(0,0,-450) ); if( (OriginalTargetLocation.Z - TargetLocation.Z) > 1024 ) TargetLocation = OriginalTargetLocation; // shift some random distance away from the target actor (which is hidden) MissVector2D = Normal( (TargetLocation - ProjStart) cross vect(0,0,1) ); if( MissVector2D dot (TargetActor.Location - TargetLocation) > 0 ) MissVector2D *= -1.0; // make most shots miss close to last seen location RandVal = FRand(); if( RandVal < 0.25 ) MissDistance = 128.0; else if( RandVal < 0.67 ) MissDistance = 64.0; else MissDistance = 32.0; TargetLocation = TargetLocation + MissDistance*FRand() * MissVector2D; //AddArrow( OriginalTargetLocation, OriginalTargetLocation + 128.0*MissVector2D, ColorCyan() ); // shift away/towards the projstart somewhat //TargetLocation.Z += (16.0 - 32.0*FRand()); ZShift = ((8.0 * TargetDistance/4096.0) - 32.0*FRand()); //DMTNS( "ZShift: " $ ZShift ); TargetLocation.Z += ZShift; // aiming at last seen position - i.e. we're probably not going to hit the // enemy (at least not with an instant hit shot) so try to pick an effective // "miss" location where the enemy is likely to see it. if( TargetActor == ControllerEnemy && ProjStart.Z >= (TargetLocation.Z - ControllerEnemy.CollisionHeight) ) { // NPC is firing from above the last seen position -- try to hit // ground near last seen position (for greater effect) //DMTNS( " Aiming at feet" ); bAimingAtFeet = true; TargetLocation.Z -= TargetActor.CollisionHeight; TargetLocation.Z -= CCFloatHeight; // account for float height of CC above ground } SavedTargetLocation = TargetLocation; bSuccess = TestAimLocation( ProjStart, ProjSpeed, TargetActor, TargetLocation, 512.0, false ); //DMTNS( " bSuccess #0: " $ bSuccess ); /* if( bSuccess ) { AddCylinder( TargetLocation, 4, 4, ColorGreen() ); AddArrow( ProjStart, ProjStart + 8192*Normal( TargetLocation - ProjStart), ColorGreen() ); } else { AddCylinder( TargetLocation, 4, 4, ColorRed() ); AddArrow( ProjStart, ProjStart + 8192*Normal( TargetLocation - ProjStart), ColorRed() ); } */ if( !bSuccess && bAimingAtFeet ) { // try middle (if bAimingAtFeet is false, we already tried this) TargetLocation.Z += TargetActor.CollisionHeight; bSuccess = TestAimLocation( ProjStart, ProjSpeed, TargetActor, TargetLocation, 512.0, false ); //DMTNS( " bSuccess #1: " $ bSuccess ); } if( !bSuccess ) { // try head TargetLocation.Z += 0.9*TargetActor.CollisionHeight; bSuccess = TestAimLocation( ProjStart, ProjSpeed, TargetActor, TargetLocation, 512.0, false ); //DMTNS( " bSuccess #2: " $ bSuccess ); } if( !bSuccess ) { // try saved location from above, allowing Pawns to be hit TargetLocation = SavedTargetLocation; bSuccess = TestAimLocation( ProjStart, ProjSpeed, TargetActor, TargetLocation, 512.0, true ); //DMTNS( " bSuccess #3: " $ bSuccess ); } if( !bSuccess ) { // try original location, allowing Pawns to be hit TargetLocation = OriginalTargetLocation; bSuccess = TestAimLocation( ProjStart, ProjSpeed, TargetActor, TargetLocation, 512.0, true ); //DMTNS( " bSuccess #4: " $ bSuccess ); } //if( bSuccess ) // AddCylinder( TargetLocation, 4, 4, ColorOrange() ); #debug DMAIA( "GetLastSeenAimLocation: " $ bSuccess ); return bSuccess; } // GetLastSeenAimLocation //----------------------------------------------------------------------------- function bool GetSplashLocation( class<Projectile> ProjectileClass, vector ProjStart, Actor TargetActor, float TargetDistance, out vector TargetLocation ) { local Actor HitActor; local vector HitLocation, HitNormal; local vector AdjustedLocation; local bool bDefendMelee; local bool bSuccess; //DMTNS( "GetSplashLocation" ); // don't use splash damage against non-pawns? if( Pawn(TargetActor) == None ) goto GetSplashLocationFailed; // don't use splash damage if firing from below or close to below NPC's feet if( ProjStart.Z <= TargetLocation.Z + 16.0 ) goto GetSplashLocationFailed; // defending against a charging enemy? bDefendMelee = ( TargetActor == ControllerEnemy && ControllerEnemy.Controller.ControllerEnemy == Self && FRand() < GetSkill() && // don't defend melee as much at lower skills ControllerEnemy.Controller.IsPreparedToMelee( false ) && TargetDistance < 700 ); // use splash damage less at lower skills if( !bDefendMelee && FRand() > GetSkill() ) goto GetSplashLocationFailed; // if geometry just behind target location, just aim at target location? HitActor = Pawn.Trace( HitLocation, HitNormal, TargetLocation + GetDamageRadius( ProjectileClass ) * Normal( TargetLocation-ProjStart ), TargetLocation, false ); if( HitActor != None ) { //DMTNS( "Aiming at geometry behind target" ); goto GetSplashLocationNoAdjust; } // try feet AdjustedLocation = TargetLocation; AdjustedLocation.Z -= TargetActor.CollisionHeight; AdjustedLocation.Z -= CCFloatHeight; // account for float height of CC above ground HitActor = Pawn.Trace( HitLocation, HitNormal, AdjustedLocation, TargetLocation, false ); bSuccess = ( HitActor == None ); if( !bSuccess ) { //DMTNS( "feet no good -- trying just above hit location" ); AdjustedLocation = HitLocation + vect(0,0,3); bSuccess = Pawn.FastTrace( TargetLocation, ProjStart ); } if( bSuccess ) TargetLocation = AdjustedLocation; GetSplashLocationNoAdjust: GetSplashLocationFailed: #debug DMAIA( "GetSplashLocation returning " $ bSuccess ); return bSuccess; } // GetSplashLocation //----------------------------------------------------------------------------- function bool ShouldTryToLead( Actor TargetActor, float TargetDistance, bool bTrySplash ) { local rotator TargetLook; local bool bResult; bResult = true; if( TargetActor.Physics != PHYS_Falling && VSize( TargetActor.Velocity ) ~= 0.0 ) { // not moving bResult = false; } // don't always lead far away targets, especially if they are moving sideways with respect to the NPC else if( FRand() < 0.55 && bTrySplash && // always lead with non-splash damage projectiles? MaxAlwaysLeadDistance > 0.0 && TargetDistance > MaxAlwaysLeadDistance ) // was 1024 { TargetLook = TargetActor.Rotation; if( TargetActor.Physics == PHYS_Walking ) TargetLook.Pitch = 0; if( (vector(TargetLook) dot Normal( TargetActor.Velocity )) < 0.71 ) bResult = false; } #debug DMAIA( "ShouldTryToLead returning " $ bResult ); return bResult; } // ShouldTryToLead //----------------------------------------------------------------------------- function bool GetSlowProjectileAim( class<Projectile> ProjectileClass, float ProjSpeed, vector ProjStart, float WeaponFireSpread, Actor TargetActor, out vector TargetLocation, float TargetDistance, bool bTrySplash, bool bLOSToTarget, out rotator ReturnedRotation ) { local vector OriginalTargetLocation; local vector OriginalPredictedTargetLocation; local vector MissVector; local float MissDistance; local float DamageRadius; local int PitchError; local bool bSuccess; #debug DMAIA( "GetSlowProjectileAim" ); //DMTNS( "GetSlowProjectileAim" ); OriginalTargetLocation = TargetLocation; if( !bLOSToTarget ) { bSuccess = GetLastSeenAimLocation( ProjectileClass, ProjSpeed, ProjStart, WeaponFireSpread, TargetActor, TargetDistance, TargetLocation ); //if( !bSuccess ) // DMTNS( "!bLOSToTarget failed" ); } else { // lead target? if( ShouldTryToLead( TargetActor, TargetDistance, bTrySplash ) ) { //DMTNS( "Leading" ); class'UtilGame'.static.GetBestPredictedLocation( Pawn, TargetActor, ProjSpeed, 0.0, TargetLocation ); //AddCylinder( TargetLocation, 16, 16, ColorBlue() ); } // aim at feet? OriginalPredictedTargetLocation = TargetLocation; if( bTrySplash ) bTrySplash = GetSplashLocation( ProjectileClass, ProjStart, TargetActor, TargetDistance, TargetLocation ); DamageRadius = GetDamageRadius( ProjectileClass ); // check initial target location bSuccess = TestAimLocation( ProjStart, ProjSpeed, TargetActor, TargetLocation, DamageRadius, false ); //DMTNS( "TestAimLocation #1 bSuccess: " $ bSuccess ); //if( !bSuccess ) // AddArrow( ProjStart, TargetLocation, ColorRed() ); if( !bSuccess && bTrySplash ) { // try aiming at middle TargetLocation = OriginalPredictedTargetLocation; bSuccess = TestAimLocation( ProjStart, ProjSpeed, TargetActor, TargetLocation, DamageRadius, false ); //DMTNS( "TestAimLocation #2 bSuccess: " $ bSuccess ); //if( !bSuccess ) // AddArrow( ProjStart, TargetLocation, ColorRed() ); } if( !bSuccess ) { // try aiming at head TargetLocation.Z += 0.9 * TargetActor.CollisionHeight; bSuccess = TestAimLocation( ProjStart, ProjSpeed, TargetActor, TargetLocation, DamageRadius, false ); //DMTNS( "TestAimLocation #3 bSuccess: " $ bSuccess ); //if( !bSuccess ) // AddArrow( ProjStart, TargetLocation, ColorRed() ); } if( !bSuccess ) { // try aiming at middle, allow Pawns to be hit TargetLocation = OriginalPredictedTargetLocation; bSuccess = TestAimLocation( ProjStart, ProjSpeed, TargetActor, TargetLocation, DamageRadius, true ); //DMTNS( "TestAimLocation #4 bSuccess: " $ bSuccess ); //if( !bSuccess ) // AddArrow( ProjStart, TargetLocation, ColorRed() ); } if( bSuccess ) { if( !TryToHit( TargetActor, TargetDistance, WeaponFireSpread, bLOSToTarget, TryToHitProjectileBaseOddsMin, TryToHitProjectileBaseOddsMax, TryToHitProjectileBaseDistance, TryToHitProjectileMinMissDistance, TryToHitProjectileMaxHitDistance ) ) { MissVector = GetMissVector( TargetActor, PitchError ); // looks bad because NPC will miss by too much... //MissDistance = (1 + 2*FRand()) * TargetActor.CollisionRadius + GetDamageRadius( ProjectileClass ); MissDistance = (2 + 3*FRand()) * TargetActor.CollisionRadius; TargetLocation += MissVector * MissDistance; // aim around chest height +/- collision height when missing? TargetLocation.Z = OriginalPredictedTargetLocation.Z + 0.5*CollisionHeight; TargetLocation.Z += (1 - 2*FRand()) * TargetActor.CollisionHeight; // mdf-tbd: final check for hitting wall close by self or hitting a friendly? bSuccess = TestMissLocation( ProjStart, ProjSpeed, TargetActor, TargetLocation, 512.0 + GetDamageRadius( ProjectileClass ) ); //DMTNS( "TestMissLocation #4: " $ bSuccess ); //if( !bSuccess ) // AddArrow( ProjStart, TargetLocation, ColorRed() ); } } } if( bSuccess ) { ReturnedRotation = rotator( TargetLocation - ProjStart ); if( PitchError != 0 ) { // NOTE: add pitch error after call to TestMissLocation above since that // shouldn't take pitch error into account (pitch error, if any *should* // possibly allow NPC to shoot into walls & such. class'Util'.static.IncrementRotatorParam( ReturnedRotation.Pitch, PitchError ); } } //DMTNS( " GetSlowProjectileAim final bSuccess: " $ bSuccess ); return bSuccess; } // GetSlowProjectileAim //----------------------------------------------------------------------------- function bool GetInstantProjectileAim( class<Projectile> ProjectileClass, float ProjSpeed, vector ProjStart, float WeaponFireSpread, Actor TargetActor, out vector TargetLocation, float TargetDistance, bool bLOSToTarget, out rotator ReturnedRotation ) { local vector OriginalTargetLocation; local bool bTryFeet; local vector MissVector; local float MissDistance; local int PitchError; local bool bSuccess; //DMTNS( "GetInstantProjectileAim TargetActor.Location: " $ TargetActor.Location $ " TargetLocation: " $ TargetLocation ); bSuccess = false; OriginalTargetLocation = TargetLocation; if( !bLOSToTarget ) { //DMTNS( " using last seen location" ); bSuccess = GetLastSeenAimLocation( ProjectileClass, ProjSpeed, ProjStart, WeaponFireSpread, TargetActor, TargetDistance, TargetLocation ); } else { // aiming at enemy // try aiming directly at target location bSuccess = TestAimLocation( ProjStart, ProjSpeed, TargetActor, TargetLocation, 0.0, false ); //DMTNS( " tried middle take #1-- bSuccess: " $ bSuccess ); if( !bSuccess ) { // try head TargetLocation.Z = TargetLocation.Z + 0.9 * TargetActor.CollisionHeight; bSuccess = TestAimLocation( ProjStart, ProjSpeed, TargetActor, TargetLocation, 2.0*TargetActor.CollisionRadius, false ); //DMTNS( GetContext() $ " try head -- bSuccess: " $ bSuccess ); // don't try feet -- having NPCs nailing you in the feet with // instant hit weapons when you can't see them would be unfun? } if( !bSuccess ) { // try original location again, but now allow missing by X units TargetLocation = OriginalTargetLocation; bSuccess = TestAimLocation( ProjStart, ProjSpeed, TargetActor, TargetLocation, 8.0*TargetActor.CollisionRadius, true ); //DMTNS( GetContext() $ " try middle take #2 -- bSuccess: " $ bSuccess ); // don't try feet -- having NPCs nailing you in the feet with // instant hit weapons when you can't see them would be unfun? } if( bSuccess ) { // possibly adjust target location to miss intentionally if( !TryToHit( TargetActor, TargetDistance, WeaponFireSpread, bLOSToTarget, TryToHitInstantBaseOddsMin, TryToHitInstantBaseOddsMax, TryToHitInstantBaseDistance, TryToHitInstantMinMissDistance, TryToHitInstantMaxHitDistance ) ) { //DMTNS( "trying to miss" ); MissVector = GetMissVector( TargetActor, PitchError ); // looks bad because NPC will miss by too much... //MissDistance = TargetActor.CollisionRadius + FRand() * TargetActor.CollisionRadius + GetDamageRadius( ProjectileClass ) + 4.0; MissDistance = TargetActor.CollisionRadius + FRand() * TargetActor.CollisionRadius + 4.0; if( WeaponFireSpread > 0.0 ) { //DMTNS( "Increasing MissDistance from " $ MissDistance $ " to " $ MissDistance + TargetDistance * sin( 0.5*DegreesToRadians*WeaponFireSpread ) ); MissDistance += TargetDistance * sin( 0.5*DegreesToRadians*WeaponFireSpread ); } TargetLocation += MissDistance * MissVector; // aim around chest height +/- collision height when missing? TargetLocation.Z = OriginalTargetLocation.Z + 0.5*CollisionHeight; TargetLocation.Z += (1 - 2*FRand()) * TargetActor.CollisionHeight; // mdf-tbd: don't shoot if hitting wall close by self or if hitting a friendly? bSuccess = TestMissLocation( ProjStart, ProjSpeed, TargetActor, TargetLocation, 512.0 ); } } } if( bSuccess ) { ReturnedRotation = rotator( TargetLocation - ProjStart ); if( PitchError != 0 ) { // NOTE: add pitch error after call to TestMissLocation above since that // shouldn't take pitch error into account (pitch error, if any *should* // possibly allow NPC to shoot into walls & such. //DMTNS( "mucking with pitch" ); //AddArrow( ProjStart, ProjStart + 128.0*vector(ReturnedRotation), ColorRed() ); class'Util'.static.IncrementRotatorParam( ReturnedRotation.Pitch, PitchError ); //AddArrow( ProjStart, ProjStart + 128.0*vector(ReturnedRotation), ColorGreen() ); } } //DMTNS( "ProjStart: " $ ProjStart $ " Pawn.Location: " $ Pawn.Location $ " Pawn.Rotation: " $ Pawn.Rotation $ " ReturnedRotation: " $ ReturnedRotation ); //AddArrow( ProjStart, ProjStart + 4096.0*vector(ReturnedRotation), ColorGreen() ); //DMTNS( " GetInstantProjectileAim final bSuccess: " $ bSuccess ); return bSuccess; } // GetInstantProjectileAim //----------------------------------------------------------------------------- function vector GetTargetLocation( Actor TargetActor, bool bLOSToTarget, bool bTossed, vector LastEnemySeenLocation, float TimeSinceLastSeen ) { local float MinGuessDistance, MaxGuessDistance; local vector GuessLocationVector; local vector ReturnedLocation; if( !bLOSToTarget ) { #debug DMAIA( "===> GetTargetLocation - no LOS to enemy -- will aim at LastEnemySeenLocation" ); if( bTossed ) { // try to guess where enemy might be now (cheat a bit by peeking at target's actual location...) GuessLocationVector = Normal( TargetActor.Location - LastEnemySeenLocation ); if( Pawn(TargetActor) != None ) { // guess at min/max distance target may have moved (max "location") MinGuessDistance = 0.2*Pawn(TargetActor).GroundSpeed; MaxGuessDistance = FMin( TimeSinceLastSeen, 3.0 ) * Pawn(TargetActor).GroundSpeed; // now pick a location somewhere between min and max ReturnedLocation = LastEnemySeenLocation + RandRange( MinGuessDistance, MaxGuessDistance ) * GuessLocationVector; } else { // stationary target? ReturnedLocation = LastEnemySeenLocation; } } else { ReturnedLocation = LastEnemySeenLocation; } } else { ReturnedLocation = TargetActor.Location; } return ReturnedLocation; } // GetTargetLocation //----------------------------------------------------------------------------- function bool StopFiringAtEnemy( Actor TargetActor, bool bTossed ) { local float SkillMultiplier; local float TimeSinceLastSeen; local float NewStopFiringAtEnemyDelay; TimeSinceLastSeen = TimeSinceTargetLastSeen( TargetActor ); if( TimeSinceLastSeen <= 1.0 ) { // reset timer SkillMultiplier = 0.5 + Level.Game.GetNormalizedDifficulty(); if( bTossed ) NewStopFiringAtEnemyDelay = (4.0 + 4.0*FRand()) * SkillMultiplier; // Difficulty 0: 2-4 secs, 1: 4-8 secs, 2: 6-12 secs else NewStopFiringAtEnemyDelay = (2.0 + 2.0*FRand()) * SkillMultiplier; // Difficulty 0: 1-2 secs, 1: 2-4 secs, 2: 3-6 secs StopFiringAtEnemyTime = Level.TimeSeconds + NewStopFiringAtEnemyDelay; } if( TimeSinceLastSeen <= 0.2 ) return false; else return ( Level.TimeSeconds > StopFiringAtEnemyTime ); } /*----------------------------------------------------------------------------- Determines the rotation which the NPC should use to aim for the given projectile type, speed, target location etc. If a solution is found, sets the NPC's rotation and returns true, returns false otherwise (and possibly calls StopFiring to abort the firing of the projectile). The code generally first determines the ideal aiming direction then decides whether to try to miss the target (intentionally) based on the game difficulty, target speed, how recently the target was acquired etc. If a miss is called for, a "good" miss direction is selected such that shots will often pass near and in front of the target for greater effect. If the target isn't in sight currently, but was recently seen, NPCs will fire at the last seen location (generally on the ground) for some time. Grenades can be lobbed over obstacles (using either of the 0/1/2 possible trajectories, checked for obstructions) at an enemy who is known but hidden (NPC "guesses" actual location based on last seen location, velocity with the error increasing with the amount of time that has passed). */ function bool AdjustAim( class<Projectile> ProjectileClass, float ProjSpeed, vector ProjStart, float WeaponFireSpread, bool bLeadTarget, bool bWarnTarget, bool bTossed, bool bTrySplash ) { local rotator ReturnedRotation; local vector TargetLocation; local vector LastEnemySeenLocation; local float TargetDistance; local Actor TargetActor; local float TimeSinceLastSeen; local bool bLOSToTarget; //debug //local Actor HitActor; //local vector HitLocation, HitNormal; #debug DMAIA( "===> AdjustAim -- BEGIN Enemy: " $ ControllerEnemy $ " ControllerTarget: " $ ControllerTarget ); //DMTNS( "===> AdjustAim -- BEGIN Enemy: " $ ControllerEnemy $ " ControllerTarget: " $ ControllerTarget ); //------------------------------------------------------------------------- // VERIFY TARGET //------------------------------------------------------------------------- TargetActor = GetTarget(); if( TargetActor == None ) { #debug DMAIA( "===> AdjustAim - StopFiring: no target -- called StopFiring and returning false" ); #debug StopFiring( 0.0, SFI_TargetInvalid, GetContext() ); #release StopFiring( 0.0, SFI_TargetInvalid ); return false; } if( StopFiringAtEnemy( TargetActor, bTossed ) ) // stop firing after 5-10 secs of not seeing enemy { #debug DMAIA( "===> AdjustAim - StopFiring: too long since target was last seen" ); #debug StopFiring( 0.5, SFI_TimeOut, GetContext() ); #release StopFiring( 0.5, SFI_TimeOut ); return false; } // assume we have LOS to target if seen within last 0.2 secs TimeSinceLastSeen = TimeSinceTargetLastSeen( TargetActor ); bLOSToTarget = ( TimeSinceLastSeen < 0.2 ); if( bLOSToTarget && !IsFacingTarget( TargetActor, CosMinFacingTargetAngle ) ) { #debug DMAIA( "===> AdjustAim - StopFiring: facing too far away from target (" $ TargetActor $ ") to aim" ); //AddArrow( Pawn.Location, Pawn.Location + 128.0*vector(Pawn.Rotation), ColorOrange() ); //AddArrow( Pawn.Location, TargetActor.Location, ColorYellow() ); #debug StopFiring( 0.1, SFI_Orientation, GetContext() ); #release StopFiring( 0.1, SFI_Orientation ); return false; } if( !bLOSToTarget ) { bLeadTarget = false; LastEnemySeenLocation = GetLastEnemySeenLocation(); if( !bTossed && !Pawn.FastTrace( Pawn.Location, LastEnemySeenLocation ) ) { #debug DMAIA( "===> AdjustAim - StopFiring: no LOS to target and no LOS to last seen location" ); #debug StopFiring( 0.1, SFI_NoLOS, GetContext() ); #release StopFiring( 0.1, SFI_NoLOS ); return false; } } //------------------------------------------------------------------------- // SET AIMING PARAMETERS //------------------------------------------------------------------------- TargetLocation = GetTargetLocation( TargetActor, bLOSToTarget, bTossed, LastEnemySeenLocation, TimeSinceLastSeen ); TargetDistance = VSize( TargetLocation - ProjStart ); //2002.12.15 hack to *force* NPCs to not fire outside min/max ranges if( U2PBasic.bForceRanges ) { if( TargetDistance < U2PBasic.RangeMinAttack ) { #debug StopFiring( 0.1, SFI_OutOfRange, GetContext() ); #release StopFiring( 0.1, SFI_OutOfRange ); return false; } if( U2PBasic.bHasMaxAttackRanges && !CheckMaxAttackRanges( TargetDistance, TargetActor ) ) { #debug StopFiring( 0.1, SFI_OutOfRange, GetContext() ); #release StopFiring( 0.1, SFI_OutOfRange ); return false; } } if( ProjSpeed <= 0 ) { bTossed = false; bLeadTarget = false; } /* #debugbegin DMTNS( " Target: " $ TargetActor ); DMTNS( " ProjClass: " $ ProjectileClass ); DMTNS( " ProjSpeed: " $ ProjSpeed ); DMTNS( " ProjStart: " $ class'Util'.static.GetVectorString(ProjStart) ); DMTNS( " bLeadTarget: " $ bLeadTarget ); DMTNS( " bWarnTarget: " $ bWarnTarget ); DMTNS( " bTossed: " $ bTossed ); DMTNS( " bTrySplash: " $ bTrySplash ); //AddCylinder( ProjStart, 2, 2, ColorCyan() ); #debugend */ /* if( !bLOSToTarget ) AddActorAt( TargetActor, TargetLocation, ColorRed() ); else AddActorAt( TargetActor, TargetLocation, ColorGreen() ); */ //AddArrow( ProjStart, TargetLocation, ColorOrange() ); //#debug DMAIA( " Target: " $ TargetActor $ " Pawn(TargetActor).IsMobile(): " $ Pawn(TargetActor).IsMobile() ); //------------------------------------------------------------------------- // ATTEMPT TO AIM //------------------------------------------------------------------------- if( bTossed ) { if( !GetTossedAim( ProjectileClass, ProjSpeed, ProjStart, WeaponFireSpread, TargetActor, TargetLocation, TargetDistance, bLOSToTarget, ReturnedRotation ) ) { #debug StopFiring( 0.1, SFI_NoShot, GetContext() ); #release StopFiring( 0.1, SFI_NoShot ); return false; } } else if( bLeadTarget ) { if( !GetSlowProjectileAim( ProjectileClass, ProjSpeed, ProjStart, WeaponFireSpread, TargetActor, TargetLocation, TargetDistance, bTrySplash, bLOSToTarget, ReturnedRotation ) ) { #debug StopFiring( 0.1, SFI_NoShot, GetContext() ); #release StopFiring( 0.1, SFI_NoShot ); return false; } } else { if( !GetInstantProjectileAim( ProjectileClass, ProjSpeed, ProjStart, WeaponFireSpread, TargetActor, TargetLocation, TargetDistance, bLOSToTarget, ReturnedRotation ) ) { #debug StopFiring( 0.1, SFI_NoShot, GetContext() ); #release StopFiring( 0.1, SFI_NoShot ); return false; } } #debugbegin //AddArrow( ProjStart, ProjStart + 16384.0*vector(ReturnedRotation), ColorRed() ); /* //DMTNS( "===> AdjustAim -- END ReturnedRotation=" $ ReturnedRotation ); //AddCylinder( ProjStart, 4, 4, ColorOrange() ); HitActor = Pawn.Trace( HitLocation, HitNormal, ProjStart + 16384.0*vector(ReturnedRotation), ProjStart, true ); //DMTNS( "Hit " $ HitActor ); //AddCylinder( HitLocation, 4, 4, ColorOrange() ); if( HitActor == TargetActor ) AddArrow( ProjStart, HitLocation, ColorGreen() ); else if( HitActor != None ) AddArrow( ProjStart, HitLocation, ColorRed() ); else AddArrow( ProjStart, ProjStart + 16384.0*vector(ReturnedRotation), ColorRed() ); */ #debugend //------------------------------------------------------------------------- // WRAPUP //------------------------------------------------------------------------- if( bWarnTarget && Pawn(TargetActor) != None && Pawn(TargetActor).Controller != None ) Pawn(TargetActor).Controller.ShotFiredNotification( Pawn, vector(ReturnedRotation), ProjectileClass, ProjSpeed ); SetRotation( ReturnedRotation ); AimRotation = ReturnedRotation; //DMTNS( "==> AdjustAim returning true Rotation Pitch: " $ Rotation.Pitch $ " Roll: " $ Rotation.Roll $ " Yaw: " $ Rotation.Yaw ); //DMTNS( "bRotateToDesired: " $ bRotateToDesired ); //DMTNS( "Pawn.bRotateToDesired: " $ Pawn.bRotateToDesired ); //AddArrow( Pawn.Location, Pawn.Location + 4096.0*vector(Rotation), ColorGreen() ); return true; } // AdjustAim //----------------------------------------------------------------------------- //@ DIALOG STUFF //----------------------------------------------------------------------------- function bool DialogAllowed( Actor Other ) { local Pawn P; if ( Controller(Other) != None ) Other = Controller(Other).Pawn; P = Pawn(Other); return( ValidPawn( P ) && ControllerEnemy == None && Pawn.Physics == PHYS_Walking && GetAttitudeTo( P ) != ATTITUDE_Enemy && class'DialogEngine'.static.HasDialog(Pawn,P) && !class'DialogEngine'.static.IsAlreadyTalking(P) ); } //----------------------------------------------------------------------------- function DialogInitiate( Actor Other, optional name Topic, optional Actor WaitingActor ) { if( Pawn != None ) class'DialogEngine'.static.Initiate( Pawn, Other, Topic, WaitingActor ); } //----------------------------------------------------------------------------- function DialogTerminate() { if( Pawn != None ) class'DialogEngine'.static.NotifyDialogScriptedAbort( Pawn ); } //----------------------------------------------------------------------------- function bool IsUsable( Actor Other ) { // 2003.01.29 (mdf) fix for adding timers (etc.) to invalid (e.g. deleted) actors if( bDeleteMe ) return false; return DialogAllowed( Other ); } //----------------------------------------------------------------------------- function OnUse( Actor Other ) { if( Other? && Pawn? ) { if ( Controller(Other)? ) Other = Controller(Other).Pawn; // reverse the initiator / target since we're being "used" class'DialogEngine'.static.Initiate( Other, Pawn ); } } //----------------------------------------------------------------------------- function OnUnuse( Actor Other ) { } //----------------------------------------------------------------------------- event DialogBegin( Actor Other ) { if( Pawn(Other) != None ) { U2P.bHeadtrackingEnabled = false; //!!Fix (mw): this is an ugly place for this ScriptController.eventSCDialogBegin( Self ); GotoState( ScriptedDialogState, DialogBeginLabel ); } } //----------------------------------------------------------------------------- //@ SCRIPTING SUPPORT //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- // Called by AI to explicitely use the Actor which is currently in front of the // NPC (must be within correct FOV and distance), e.g. when NPC is scripted to // use/unuse something, when autonomous AI decides to use something etc. // tbd: drop parameter -- use manager should ensure that only usuable actor in range/fov is used function UseActor( Actor A ) { class'U2UseManager'.static.UseTarget( U2PBase, A ); GotoState( UsingState ); } //----------------------------------------------------------------------------- // Called by AI to explicitely unuse actor being used (if any), e.g. when NPC // is scripted to use/unuse something, when autonomous AI decides to stop using // something which was being used. // tbd: drop parameter -- use manager should ensure that only usuable actor in range/fov is used function UnuseActor( optional Actor A ) { // currently, unless we are scripted or in using state, nothing to do (we can't be using something) } //----------------------------------------------------------------------------- // Called when a Pawn dies or when actor being used can no longer be used (e.g. // if a health station runs out of health). exec function Unuse() { UnuseActor( None ); } //----------------------------------------------------------------------------- // Called when use stops because the NPC has walked away or stopped looking at // the actor being used. No longer used currently now that power/health // stations don't go through the use manager (you just walk on 'em). function NotifyUnuse( Actor A ) { // global should never be called? DMAssert( false, GetContext() @ A ); } //----------------------------------------------------------------------------- function SetSpecialGoal( Actor NewSpecialGoal, optional float NewSpecialGoalDistance, optional bool bFaceSpecialGoalNew ) { #debug DMAI( "SetSpecialGoal: " $ NewSpecialGoal ); SpecialGoal = NewSpecialGoal; // note: SpecialGoalDistance implies the 2D CC to CC distance for a Pawn Target, actual distance otherwise if( NewSpecialGoalDistance > 0.0 ) { if( Pawn(NewSpecialGoal) != None ) SpecialGoalDistance = FMax( MinFollowDistance, NewSpecialGoalDistance ); else SpecialGoalDistance = FMax( MinGoalDistance, NewSpecialGoalDistance ); } else SpecialGoalDistance = -1.0; // not used bFaceSpecialGoal = bFaceSpecialGoalNew; } //----------------------------------------------------------------------------- function SetDirectionalPatrol( bool bNewVal ) { bDirectionalPatrol = bNewVal; } //----------------------------------------------------------------------------- function bool GetDirectionalPatrol() { return bDirectionalPatrol; } //----------------------------------------------------------------------------- simulated function SetScriptedFocus( Actor A ) { ScriptedFocus = A; } //----------------------------------------------------------------------------- function SetScriptedIdleAnims( bool bNewVal ) { bScriptedIdleAnims = bNewVal; if( !bNewVal ) UnlockAnimationController(); GotoState( ScriptedState, IdleLabel ); } //----------------------------------------------------------------------------- function float GetMoveSpeed( optional vector TargetLocation ) { return DefaultMoveSpeed; } //----------------------------------------------------------------------------- // Rotation <-->degrees: // // 32 = 0.18 // 64 = 0.35 // 128 = 0.70 // 256 = 1.41 // 512 = 2.81 // 1024 = 5.63 // 2048 = 11.25 // 4096 = 22.50 // 8192 = 45.00 // 16384 = 90.00 // 32768 = 180.00 defaultproperties { MaxMoveToPointAttempts=2 MaxMoveToActorAttempts=10 MaxMoveRecoverAttempts=5 CloseEnoughDistance=512.000000 GetCloserThreshold=256.000000 MaxAffectedByHitTime=0.500000 MaxAffectedByAcquisitionTime=1.000000 TryToHitInstantBaseOddsMin=0.125000 TryToHitInstantBaseOddsMax=0.625000 TryToHitProjectileBaseOddsMin=0.250000 TryToHitProjectileBaseOddsMax=1.000000 TryToHitTossedBaseOddsMin=0.250000 TryToHitTossedBaseOddsMax=1.000000 TryToHitInstantBaseDistance=1024.000000 TryToHitProjectileBaseDistance=1024.000000 TryToHitTossedBaseDistance=1024.000000 TryToHitInstantMinMissDistance=256.000000 TryToHitProjectileMinMissDistance=256.000000 TryToHitTossedMinMissDistance=256.000000 TryToHitProjectileMaxHitDistance=4096.000000 TryToHitInstantMaxHitDistance=9999999.000000 TryToHitTossedMaxHitDistance=3000.000000 TryToHitBaseSpeed=300.000000 TryToHitBaseSpeedOdds=0.500000 BlockedByCoverHitOdds=0.020000 MaxHitMissMultiplier=1.000000 MaxAcquireMissMultiplier=1.000000 MaxHitPitchError=2048 MinHitPitchError=512 MaxAcquirePitchError=2048 MinAcquirePitchError=512 MinTeleportRangeMoveError=256.000000 MaxTeleportRangeMoveError=4096.000000 MinTeleportRangeMinZError=64.000000 MaxTeleportRangeMinZError=4096.000000 MinTeleportRangeStuckError=128.000000 MaxTeleportRangeStuckError=1280.000000 MinLastRenderedTeleportDelay=2.000000 DefaultRotationThreshold=910 ScriptedRotationThreshold=182 UseReticleOnEvents(0)="UseReticleText" UseReticleOnEvents(1)="UseReticleCorners" UseReticleOnEvents(2)="UseReticleTopBars" ProximityReticleOnEvents(0)="ProximityReticleCorners" ProximityReticleOnEvents(1)="ProximityReticleTopBars" } |
Overview | Package | Class | Source | Class tree | Glossary | UnrealScript Documentation |
previous class next class | frames no frames |