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 |
//============================================================================= // Monster Controller - simple AI that always has and hunts down player enemy //============================================================================= class MonsterController extends ScriptedController; // AI Magic numbers - distance based, so scale to bot speed/weapon range const MAXSTAKEOUTDIST = 2000; const ENEMYLOCATIONFUZZ = 1200; const TACTICALHEIGHTADVANTAGE = 320; const MINSTRAFEDIST = 200; const MINVIEWDIST = 200; //AI flags var bool bCanFire; // used by TacticalMove and Charging states var bool bStrafeDir; var bool bLeadTarget; // lead target with projectile attack var bool bChangeDir; // tactical move boolean var bool bEnemyIsVisible; var bool bMustCharge; var bool bJustLanded; var bool bRecommendFastMove; var bool bHasFired; var bool bForcedDirection; // Advanced AI attributes. var float AcquireTime; // time at which current enemy was acquired var float LoseEnemyCheckTime; var float StartTacticalTime; var vector HidingSpot; var float ChallengeTime; // modifiable AI attributes var float Accuracy; // -1 to 1 (0 is default, higher is more accurate) var float StrafingAbility; // -1 to 1 (higher uses strafing more) var float CombatStyle; // -1 to 1 = low means tends to stay off and snipe, high means tends to charge and melee var float ReactionTime; // Team AI attributes var string GoalString; // for debugging - used to show what bot is thinking (with 'ShowDebug') var string SoakString; // for debugging - shows problem when soaking // ChooseAttackMode() state var int ChoosingAttackLevel; var float ChooseAttackTime; var int ChooseAttackCounter; var float EnemyVisibilityTime; var pawn VisibleEnemy; var pawn OldEnemy; var float StopStartTime; var float LastRespawnTime; var float FailedHuntTime; var Pawn FailedHuntEnemy; var int NumRandomJumps; // attempts to free monster from being stuck function PostBeginPlay() { Super.PostBeginPlay(); SetCombatTimer(); if ( UnrealMPGameInfo(Level.Game).bSoaking ) bSoaking = true; } function FearThisSpot(AvoidMarker aSpot) { if ( Skill > 1 + 4.5 * FRand() ) Super.FearThisSpot(aSpot); } function SetCombatTimer() { SetTimer(1.2 - 0.09 * FMin(10,Skill+ReactionTime), True); } function WaitForMover(Mover M) { Super.WaitForMover(M); StopStartTime = Level.TimeSeconds; } function TimedFireWeaponAtEnemy() { if ( (Enemy == None) || FireWeaponAt(Enemy) ) SetCombatTimer(); else SetTimer(0.1, True); } function bool FireWeaponAt(Actor A) { if ( A == None ) A = Enemy; if ( (A == None) || (Focus != A) ) return false; Target = A; Monster(Pawn).RangedAttack(Target); return false; } function bool CanAttack(Actor Other) { // return true if in range of current weapon return Monster(Pawn).CanAttack(Other); } function StopFiring() { Monster(Pawn).StopFiring(); bCanFire = false; bFire = 0; bAltFire = 0; } //=========================================================================== function DisplayDebug(Canvas Canvas, out float YL, out float YPos) { local string S; Super.DisplayDebug(Canvas,YL, YPos); Canvas.SetDrawColor(255,255,255); Canvas.DrawText(" "$GoalString, false); YPos += 2*YL; Canvas.SetPos(4,YPos); if ( Enemy != None ) { Canvas.DrawText("Enemy Dist "$VSize(Enemy.Location - Pawn.Location)$" Acquired "$bEnemyAcquired); YPos += YL; Canvas.SetPos(4,YPos); } Canvas.DrawText("Weapons: "$S, false); YPos += YL; Canvas.SetPos(4,YPos); Canvas.DrawText("PERSONALITY: CombatStyle "$CombatStyle$" Strafing "$StrafingAbility); YPos += YL; Canvas.SetPos(4,YPos); } function bool FindNewEnemy() { local Pawn BestEnemy; local bool bSeeNew, bSeeBest; local float BestDist, NewDist; local Controller C; if ( Level.Game.bGameEnded ) return false; for ( C=Level.ControllerList; C!=None; C=C.NextController ) if ( C.bIsPlayer && (C.Pawn != None) ) { if ( BestEnemy == None ) { BestEnemy = C.Pawn; BestDist = VSize(BestEnemy.Location - Pawn.Location); bSeeBest = CanSee(BestEnemy); } else { NewDist = VSize(C.Pawn.Location - Pawn.Location); if ( !bSeeBest || (NewDist < BestDist) ) { bSeeNew = CanSee(C.Pawn); if ( bSeeNew || (!bSeeBest && (NewDist < BestDist)) ) { BestEnemy = C.Pawn; BestDist = NewDist; bSeeBest = bSeeNew; } } } } if ( BestEnemy == Enemy ) return false; if ( BestEnemy != None ) { ChangeEnemy(BestEnemy,CanSee(BestEnemy)); return true; } return false; } function ChangeEnemy(Pawn NewEnemy, bool bCanSeeNewEnemy) { OldEnemy = Enemy; Enemy = NewEnemy; EnemyChanged(bCanSeeNewEnemy); } function bool SetEnemy( Pawn NewEnemy, optional bool bHateMonster ) { local float EnemyDist; local bool bNewMonsterEnemy; if ( (NewEnemy == None) || (NewEnemy.Health <= 0) || (NewEnemy.Controller == None) || (NewEnemy == Enemy) ) return false; bNewMonsterEnemy = bHateMonster && (Level.Game.NumPlayers < 4) && !Monster(Pawn).SameSpeciesAs(NewEnemy) && !NewEnemy.Controller.bIsPlayer; if ( !NewEnemy.Controller.bIsPlayer && !bNewMonsterEnemy ) return false; if ( (bNewMonsterEnemy && LineOfSightTo(NewEnemy)) || (Enemy == None) || !EnemyVisible() ) { ChangeEnemy(NewEnemy,CanSee(NewEnemy)); return true; } if ( !CanSee(NewEnemy) ) return false; if ( !bHateMonster && (Monster(Enemy) != None) && NewEnemy.Controller.bIsPlayer ) return false; EnemyDist = VSize(Enemy.Location - Pawn.Location); if ( EnemyDist < Pawn.MeleeRange ) return false; if ( EnemyDist > 1.7 * VSize(NewEnemy.Location - Pawn.Location)) { ChangeEnemy(NewEnemy,CanSee(NewEnemy)); return true; } return false; } function HearNoise(float Loudness, Actor NoiseMaker) { if ( ((ChooseAttackCounter < 2) || (ChooseAttackTime != Level.TimeSeconds)) && SetEnemy(NoiseMaker.instigator) ) WhatToDoNext(2); } event SeePlayer(Pawn SeenPlayer) { if ( ((ChooseAttackCounter < 2) || (ChooseAttackTime != Level.TimeSeconds)) && SetEnemy(SeenPlayer) ) WhatToDoNext(3); if ( Enemy == SeenPlayer ) { VisibleEnemy = Enemy; EnemyVisibilityTime = Level.TimeSeconds; bEnemyIsVisible = true; } } function bool ClearShot(Vector TargetLoc, bool bImmediateFire) { local bool bSeeTarget; if ( VSize(Enemy.Location - TargetLoc) > MAXSTAKEOUTDIST ) return false; bSeeTarget = FastTrace(TargetLoc, Pawn.Location + Pawn.EyeHeight * vect(0,0,1)); // if pawn is crouched, check if standing would provide clear shot if ( !bImmediateFire && !bSeeTarget && Pawn.bIsCrouched ) bSeeTarget = FastTrace(TargetLoc, Pawn.Location + (Pawn.Default.EyeHeight + Pawn.Default.CollisionHeight - Pawn.CollisionHeight) * vect(0,0,1)); if ( !bSeeTarget || !FastTrace(TargetLoc , Enemy.Location + Enemy.BaseEyeHeight * vect(0,0,1)) ); return false; if ( (Monster(Pawn).SplashDamage() && (VSize(Pawn.Location - TargetLoc) < Monster(Pawn).GetDamageRadius())) || !FastTrace(TargetLoc + vect(0,0,0.9) * Enemy.CollisionHeight, Pawn.Location) ) { StopFiring(); return false; } return true; } /* CheckIfShouldCrouch() returns true if target position still can be shot from crouched position, or if couldn't hit it from standing position either */ function CheckIfShouldCrouch(vector StartPosition, vector TargetPosition, float probability) { local actor HitActor; local vector HitNormal,HitLocation, X,Y,Z, projstart; if ( !Pawn.bCanCrouch || (!Pawn.bIsCrouched && (FRand() > probability)) || (Skill < 3 * FRand()) || Monster(Pawn).RecommendSplashDamage() ) { Pawn.bWantsToCrouch = false; return; } GetAxes(Rotation,X,Y,Z); projStart = Monster(Pawn).GetFireStart(X,Y,Z); projStart = projStart + StartPosition - Pawn.Location; projStart.Z = projStart.Z - 1.8 * (Pawn.CollisionHeight - Pawn.CrouchHeight); HitActor = Trace(HitLocation, HitNormal, TargetPosition , projStart, false); if ( HitActor == None ) { Pawn.bWantsToCrouch = true; return; } projStart.Z = projStart.Z + 1.8 * (Pawn.Default.CollisionHeight - Pawn.CrouchHeight); HitActor = Trace(HitLocation, HitNormal, TargetPosition , projStart, false); if ( HitActor == None ) { Pawn.bWantsToCrouch = false; return; } Pawn.bWantsToCrouch = true; } function Trigger( actor Other, pawn EventInstigator ) { if ( (Other == Pawn) || (Pawn.Health <= 0) ) return; SetEnemy(EventInstigator,true); } function SetEnemyInfo(bool bNewEnemyVisible) { AcquireTime = Level.TimeSeconds; if ( bNewEnemyVisible ) { LastSeenTime = Level.TimeSeconds; LastSeenPos = Enemy.Location; LastSeeingPos = Pawn.Location; bEnemyInfoValid = true; } else { LastSeenTime = -1000; bEnemyInfoValid = false; } } // EnemyChanged() called when current enemy changes function EnemyChanged(bool bNewEnemyVisible) { bEnemyAcquired = false; SetEnemyInfo(bNewEnemyVisible); Monster(Pawn).PlayChallengeSound(); } function bool StrafeFromDamage(float Damage, class<DamageType> DamageType, bool bFindDest); //********************************************************************** function 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); } } return false; } event NotifyMissedJump() { if ( Pawn.bCanFly ) Pawn.SetPhysics(PHYS_Flying); } function Possess(Pawn aPawn) { Super.Possess(aPawn); InitializeSkill(DeathMatch(Level.Game).AdjustedDifficulty); Pawn.MaxFallSpeed = 1.1 * Pawn.default.MaxFallSpeed; // so bots will accept a little falling damage for shorter routes Pawn.SetMovementPhysics(); if (Pawn.Physics == PHYS_Walking) Pawn.SetPhysics(PHYS_Falling); WhatToDoNext(1); enable('NotifyBump'); } function InitializeSkill(float InSkill) { Skill = FClamp(InSkill, 0, 7); ReSetSkill(); } function ResetSkill() { local float AdjustedYaw; bLeadTarget = ( Skill >= 4 ); SetCombatTimer(); SetPeripheralVision(); if ( Skill + ReactionTime > 7 ) RotationRate.Yaw = 90000; else if ( Skill + ReactionTime >= 4 ) RotationRate.Yaw = 20000 + 7000 * (skill + ReactionTime); else RotationRate.Yaw = 30000 + 4000 * (skill + ReactionTime); AdjustedYaw = (0.75 + 0.05 * ReactionTime) * RotationRate.Yaw; AcquisitionYawRate = AdjustedYaw; SetMaxDesiredSpeed(); } function SetMaxDesiredSpeed() { if ( Pawn != None ) { if ( Skill > 3 ) Pawn.MaxDesiredSpeed = 1; else Pawn.MaxDesiredSpeed = 0.6 + 0.1 * Skill; } } function SetPeripheralVision() { if ( Pawn == None ) return; if ( Skill < 2 ) Pawn.PeripheralVision = 0.7; else if ( Skill > 5 ) Pawn.PeripheralVision = 0; else Pawn.PeripheralVision = 1.0 - 0.2 * skill; Pawn.SightRadius = Pawn.Default.SightRadius; } //============================================================================= function WhatToDoNext(byte CallingByte) { if ( ChoosingAttackLevel > 0 ) log("CHOOSEATTACKAGAIN in state "$GetStateName()$" enemy "$GetEnemyName()$" old enemy "$GetOldEnemyName()$" CALLING BYTE "$CallingByte); if ( ChooseAttackTime == Level.TimeSeconds ) { ChooseAttackCounter++; if ( ChooseAttackCounter > 3 ) log("CHOOSEATTACKSERIAL in state "$GetStateName()$" enemy "$GetEnemyName()$" old enemy "$GetOldEnemyName()$" CALLING BYTE "$CallingByte); } else { ChooseAttackTime = Level.TimeSeconds; ChooseAttackCounter = 0; } if ( Monster(Pawn).bTryToWalk && (Pawn.Physics == PHYS_Flying) && (ChoosingAttackLevel == 0) && (ChooseAttackCounter == 0) ) TryToWalk(); ChoosingAttackLevel++; ExecuteWhatToDoNext(); ChoosingAttackLevel--; } /* Check if just above ground - if so land */ function TryToWalk() { local vector HitLocation, HitNormal, Extent; local actor HitActor; if ( Pawn.PhysicsVolume.bWaterVolume ) return; Extent = Pawn.GetCollisionExtent(); HitActor = Trace(HitLocation, HitNormal, Pawn.Location - vect(0,0,100), Pawn.Location, false, Extent); if ( (HitActor != None) && HitActor.bWorldGeometry && (HitNormal.Z > MINFLOORZ) ) Pawn.SetPhysics(PHYS_Falling); } function string GetOldEnemyName() { if ( OldEnemy == None ) return "NONE"; else return OldEnemy.GetHumanReadableName(); } function string GetEnemyName() { if ( Enemy == None ) return "NONE"; else return Enemy.GetHumanReadableName(); } function ExecuteWhatToDoNext() { bHasFired = false; GoalString = "WhatToDoNext at "$Level.TimeSeconds; if ( Pawn == None ) { warn(GetHumanReadableName()$" WhatToDoNext with no pawn"); return; } if ( bPreparingMove && Monster(Pawn).bShotAnim ) { Pawn.Acceleration = vect(0,0,0); GotoState('WaitForAnim'); return; } if (Pawn.Physics == PHYS_None) Pawn.SetMovementPhysics(); if ( (Pawn.Physics == PHYS_Falling) && DoWaitForLanding() ) return; if ( (Enemy != None) && ((Enemy.Health <= 0) || (Enemy.Controller == None)) ) Enemy = None; if ( Level.Game.bGameEnded && (Enemy != None) && Enemy.Controller.bIsPlayer ) Enemy = None; if ( (Enemy == None) || !EnemyVisible() ) FindNewEnemy(); if ( Enemy != None ) ChooseAttackMode(); else { GoalString = "WhatToDoNext Wander or Camp at "$Level.TimeSeconds; WanderOrCamp(true); } } function bool DoWaitForLanding() { GotoState('WaitingForLanding'); return true; } function bool EnemyVisible() { if ( (EnemyVisibilityTime == Level.TimeSeconds) && (VisibleEnemy == Enemy) ) return bEnemyIsVisible; VisibleEnemy = Enemy; EnemyVisibilityTime = Level.TimeSeconds; bEnemyIsVisible = LineOfSightTo(Enemy); return bEnemyIsVisible; } function FightEnemy(bool bCanCharge) { local vector X,Y,Z; local float enemyDist; local float AdjustedCombatStyle, Aggression; local bool bFarAway, bOldForcedCharge; local NavigationPoint N; if ( (Enemy == None) || (Pawn == None) ) log("HERE 3 Enemy "$Enemy$" pawn "$Pawn); if ( (Enemy == FailedHuntEnemy) && (Level.TimeSeconds == FailedHuntTime) ) { if ( !Enemy.Controller.bIsPlayer ) FindNewEnemy(); if ( Enemy == FailedHuntEnemy ) { GoalString = "FAILED HUNT - HANG OUT"; if ( EnemyVisible() ) bCanCharge = false; else if ( (LastRespawnTime != Level.TimeSeconds) && ((LastSeenTime == 0) || (Level.TimeSeconds - LastSeenTime) > 15) && !Pawn.PlayerCanSeeMe() ) { LastRespawnTime = Level.TimeSeconds; EnemyVisibilityTime = 0; N = Level.Game.FindPlayerStart(self,1); Pawn.SetLocation(N.Location+(Pawn.CollisionHeight - N.CollisionHeight) * vect(0,0,1)); } if ( !EnemyVisible() ) { WanderOrCamp(true); return; } } } bOldForcedCharge = bMustCharge; bMustCharge = false; enemyDist = VSize(Pawn.Location - Enemy.Location); AdjustedCombatStyle = CombatStyle; Aggression = 1.5 * FRand() - 0.8 + 2 * AdjustedCombatStyle + FRand() * (Normal(Enemy.Velocity - Pawn.Velocity) Dot Normal(Enemy.Location - Pawn.Location)); if ( Enemy.Weapon != None ) Aggression += 2 * Enemy.Weapon.SuggestDefenseStyle(); if ( enemyDist > MAXSTAKEOUTDIST ) Aggression += 0.5; if ( (Pawn.Physics == PHYS_Walking) || (Pawn.Physics == PHYS_Falling) ) { if (Pawn.Location.Z > Enemy.Location.Z + TACTICALHEIGHTADVANTAGE) Aggression = FMax(0.0, Aggression - 1.0 + AdjustedCombatStyle); else if ( (Skill < 4) && (enemyDist > 0.65 * MAXSTAKEOUTDIST) ) { bFarAway = true; Aggression += 0.5; } else if (Pawn.Location.Z < Enemy.Location.Z - Pawn.CollisionHeight) // below enemy Aggression += CombatStyle; } if ( !EnemyVisible() ) { GoalString = "Enemy not visible"; if ( !bCanCharge ) { GoalString = "Stake Out"; DoStakeOut(); } else { GoalString = "Hunt"; GotoState('Hunting'); } return; } // see enemy - decide whether to charge it or strafe around/stand and fire Target = Enemy; if( Monster(Pawn).PreferMelee() || (bCanCharge && bOldForcedCharge) ) { GoalString = "Charge"; DoCharge(); return; } if ( bCanCharge && (Skill < 5) && bFarAway && (Aggression > 1) && (FRand() < 0.5) ) { GoalString = "Charge closer"; DoCharge(); return; } if ( !Monster(Pawn).PreferMelee() && (FRand() > 0.17 * (skill - 1)) && !DefendMelee(enemyDist) ) { GoalString = "Ranged Attack"; DoRangedAttackOn(Enemy); return; } if ( bCanCharge ) { if ( Aggression > 1 ) { GoalString = "Charge 2"; DoCharge(); return; } } if ( !Pawn.bCanStrafe ) { GoalString = "Ranged Attack"; DoRangedAttackOn(Enemy); return; } GoalString = "Do tactical move"; if ( !Monster(Pawn).RecommendSplashDamage() && Monster(Pawn).bCanDodge && (FRand() < 0.7) && (FRand()*Skill > 3) ) { GetAxes(Pawn.Rotation,X,Y,Z); GoalString = "Try to Duck "; if ( FRand() < 0.5 ) { Y *= -1; TryToDuck(Y, true); } else TryToDuck(Y, false); } DoTacticalMove(); } function DoRangedAttackOn(Actor A) { Target = A; GotoState('RangedAttack'); } /* ChooseAttackMode() Handles tactical attacking state selection - choose which type of attack to do from here */ function ChooseAttackMode() { GoalString = " ChooseAttackMode last seen "$(Level.TimeSeconds - LastSeenTime); // should I run away? if ( (Enemy == None) || (Pawn == None) ) log("HERE 1 Enemy "$Enemy$" pawn "$Pawn); GoalString = "ChooseAttackMode FightEnemy"; FightEnemy(true); } event SoakStop(string problem) { local UnrealPlayer PC; log(problem); SoakString = problem; GoalString = SoakString@GoalString; ForEach DynamicActors(class'UnrealPlayer',PC) { PC.SoakPause(Pawn); break; } } function bool FindRoamDest() { local actor BestPath; if ( Pawn.FindAnchorFailedTime == Level.TimeSeconds ) { // couldn't find an anchor. GoalString = "No anchor "$Level.TimeSeconds; if ( Pawn.LastValidAnchorTime > 5 ) { if ( bSoaking ) SoakStop("NO PATH AVAILABLE!!!"); else { if ( NumRandomJumps > 4 ) { Pawn.Health = 0; Pawn.Died( self, class'Suicided', Pawn.Location ); return true; } else { // jump NumRandomJumps++; if ( Physics != PHYS_Falling ) { Pawn.SetPhysics(PHYS_Falling); Pawn.Velocity = 0.5 * Pawn.GroundSpeed * VRand(); Pawn.Velocity.Z = Pawn.JumpZ; } } } } //log(self$" Find Anchor failed!"); return false; } NumRandomJumps = 0; GoalString = "Find roam dest "$Level.TimeSeconds; // find random NavigationPoint to roam to if ( (RouteGoal == None) || (Pawn.Anchor == RouteGoal) || Pawn.ReachedDestination(RouteGoal) ) { RouteGoal = FindRandomDest(); BestPath = RouteCache[0]; if ( RouteGoal == None ) { if ( bSoaking && (Physics != PHYS_Falling) ) SoakStop("COULDN'T FIND ROAM DESTINATION"); return false; } } if ( BestPath == None ) BestPath = FindPathToward(RouteGoal,false); if ( BestPath != None ) { MoveTarget = BestPath; GotoState('Roaming'); return true; } if ( bSoaking && (Physics != PHYS_Falling) ) SoakStop("COULDN'T FIND ROAM PATH TO "$RouteGoal); RouteGoal = None; return false; } function bool TestDirection(vector dir, out vector pick) { local vector HitLocation, HitNormal, dist; local actor HitActor; pick = dir * (MINSTRAFEDIST + 2 * MINSTRAFEDIST * FRand()); HitActor = Trace(HitLocation, HitNormal, Pawn.Location + pick + 1.5 * Pawn.CollisionRadius * dir , Pawn.Location, false); if (HitActor != None) { pick = HitLocation + (HitNormal - dir) * 2 * Pawn.CollisionRadius; if ( !FastTrace(pick, Pawn.Location) ) return false; } else pick = Pawn.Location + pick; dist = pick - Pawn.Location; if (Pawn.Physics == PHYS_Walking) dist.Z = 0; return (VSize(dist) > MINSTRAFEDIST); } function Restart() { Super.Restart(); ReSetSkill(); GotoState('Roaming','DoneRoaming'); } function CancelCampFor(Controller C); function bool AdjustAround(Pawn Other) { local float speed; local vector VelDir, OtherDir, SideDir; speed = VSize(Pawn.Acceleration); if ( speed < Pawn.WalkingPct * Pawn.GroundSpeed ) return false; VelDir = Pawn.Acceleration/speed; VelDir.Z = 0; OtherDir = Other.Location - Pawn.Location; OtherDir.Z = 0; OtherDir = Normal(OtherDir); if ( (VelDir Dot OtherDir) > 0.8 ) { bAdjusting = true; SideDir.X = VelDir.Y; SideDir.Y = -1 * VelDir.X; if ( (SideDir Dot OtherDir) > 0 ) SideDir *= -1; AdjustLoc = Pawn.Location + 1.5 * Other.CollisionRadius * (0.5 * VelDir + SideDir); } } function DirectedWander(vector WanderDir) { GoalString = "DIRECTED WANDER "$GoalString; Pawn.bWantsToCrouch = Pawn.bIsCrouched; if ( TestDirection(WanderDir,Destination) ) GotoState('RestFormation', 'Moving'); else GotoState('RestFormation', 'Begin'); } event bool NotifyBump(actor Other) { local Pawn P; Disable('NotifyBump'); P = Pawn(Other); if ( (P == None) || (P.Controller == None) || (Enemy == P) ) return false; if ( SetEnemy(P) ) { WhatToDoNext(4); return false; } if ( Enemy == P ) return false; if ( !AdjustAround(P) ) CancelCampFor(P.Controller); return false; } function SetFall() { if (Pawn.bCanFly) { Pawn.SetPhysics(PHYS_Flying); return; } if ( Pawn.bNoJumpAdjust ) { Pawn.bNoJumpAdjust = false; return; } else { Pawn.Velocity = EAdjustJump(Pawn.Velocity.Z,Pawn.GroundSpeed); Pawn.Acceleration = vect(0,0,0); } } function bool NotifyLanded(vector HitNormal) { local vector Vel2D; if ( MoveTarget != None ) { Vel2D = Pawn.Velocity; Vel2D.Z = 0; if ( (Vel2D Dot (MoveTarget.Location - Pawn.Location)) < 0 ) { Pawn.Acceleration = vect(0,0,0); if ( NavigationPoint(MoveTarget) != None ) Pawn.Anchor = NavigationPoint(MoveTarget); MoveTimer = -1; } } return false; } /* FindBestPathToward() Assumes the desired destination is not directly reachable. It tries to set Destination to the location of the best waypoint, and returns true if successful */ function bool FindBestPathToward(Actor A, bool bCheckedReach, bool bAllowDetour) { if ( !bCheckedReach && ActorReachable(A) ) MoveTarget = A; else MoveTarget = FindPathToward(A,false); if ( MoveTarget != None ) return true; else { if ( (A == Enemy) && (A != None) ) { FailedHuntTime = Level.TimeSeconds; FailedHuntEnemy = Enemy; } if ( bSoaking && (Physics != PHYS_Falling) ) SoakStop("COULDN'T FIND BEST PATH TO "$A); } return false; } function bool NeedToTurn(vector targ) { local vector LookDir,AimDir; LookDir = Vector(Pawn.Rotation); LookDir.Z = 0; LookDir = Normal(LookDir); AimDir = targ - Pawn.Location; AimDir.Z = 0; AimDir = Normal(AimDir); return ((LookDir Dot AimDir) < 0.93); } /* NearWall() returns true if there is a nearby barrier at eyeheight, and changes FocalPoint to a suggested place to look */ function bool NearWall(float walldist) { local actor HitActor; local vector HitLocation, HitNormal, ViewSpot, ViewDist, LookDir; LookDir = vector(Rotation); ViewSpot = Pawn.Location + Pawn.BaseEyeHeight * vect(0,0,1); ViewDist = LookDir * walldist; HitActor = Trace(HitLocation, HitNormal, ViewSpot + ViewDist, ViewSpot, false); if ( HitActor == None ) return false; ViewDist = Normal(HitNormal Cross vect(0,0,1)) * walldist; if (FRand() < 0.5) ViewDist *= -1; Focus = None; if ( FastTrace(ViewSpot + ViewDist, ViewSpot) ) { FocalPoint = Pawn.Location + ViewDist; return true; } if ( FastTrace(ViewSpot - ViewDist, ViewSpot) ) { FocalPoint = Pawn.Location - ViewDist; return true; } FocalPoint = Pawn.Location - LookDir * 300; return true; } // check for line of sight to target deltatime from now. function bool CheckFutureSight(float deltatime) { local vector FutureLoc; if ( Target == None ) Target = Enemy; if ( Target == None ) return false; if ( Pawn.Acceleration == vect(0,0,0) ) FutureLoc = Pawn.Location; else FutureLoc = Pawn.Location + Pawn.GroundSpeed * Normal(Pawn.Acceleration) * deltaTime; if ( Pawn.Base != None ) FutureLoc += Pawn.Base.Velocity * deltaTime; //make sure won't run into something if ( !FastTrace(FutureLoc, Pawn.Location) && (Pawn.Physics != PHYS_Falling) ) return false; //check if can still see target if ( FastTrace(Target.Location + Target.Velocity * deltatime, FutureLoc) ) return true; return false; } function float AdjustAimError(float aimerror, float TargetDist, bool bDefendMelee, bool bInstantProj, bool bLeadTargetNow ) { if ( (Pawn(Target) != None) && (Pawn(Target).Visibility < 2) ) aimerror *= 2.5; // figure out the relative motion of the target across the bots view, and adjust aim error // based on magnitude of relative motion aimerror = aimerror * FMin(5,(12 - 11 * (Normal(Target.Location - Pawn.Location) Dot Normal((Target.Location + 1.2 * Target.Velocity) - (Pawn.Location + Pawn.Velocity))))); // if enemy is charging straight at bot with a melee weapon, improve aim if ( bDefendMelee ) aimerror *= 0.5; if ( Target.Velocity == vect(0,0,0) ) aimerror *= 0.6; // aiming improves over time if stopped if ( Stopped() && (Level.TimeSeconds > StopStartTime) ) { if ( (Skill+Accuracy) > 4 ) aimerror *= 0.9; aimerror *= FClamp((2 - 0.08 * FMin(skill,7) - FRand())/(Level.TimeSeconds - StopStartTime + 0.4),0.7,1.0); } // adjust aim error based on skill if ( !bDefendMelee ) aimerror *= (3.3 - 0.37 * (FClamp(skill+Accuracy,0,8.5) + 0.5 * FRand())); // Bots don't aim as well if recently hit, or if they or their target is flying through the air if ( ((skill < 7) || (FRand()<0.5)) && (Level.TimeSeconds - Pawn.LastPainTime < 0.2) ) aimerror *= 1.3; if ( (Pawn.Physics == PHYS_Falling) || (Target.Physics == PHYS_Falling) ) aimerror *= 1.6; // Bots don't aim as well at recently acquired targets (because they haven't had a chance to lock in to the target) if ( AcquireTime > Level.TimeSeconds - 0.5 - 0.6 * (7 - skill) ) { aimerror *= 1.5; if ( bInstantProj ) aimerror *= 1.5; } return (Rand(2 * aimerror) - aimerror); } /* AdjustAim() Returns a rotation which is the direction the bot should aim - after introducing the appropriate aiming error */ function rotator AdjustAim(FireProperties FiredAmmunition, vector projStart, int aimerror) { local rotator FireRotation, TargetLook; local float FireDist, TargetDist, ProjSpeed; local actor HitActor; local vector FireSpot, FireDir, TargetVel, HitLocation, HitNormal; local int realYaw; local bool bDefendMelee, bClean, bLeadTargetNow; if ( FiredAmmunition.ProjectileClass != None ) projspeed = FiredAmmunition.ProjectileClass.default.speed; // make sure bot has a valid target if ( Target == None ) { Target = Enemy; if ( Target == None ) return Rotation; } FireSpot = Target.Location; TargetDist = VSize(Target.Location - Pawn.Location); // perfect aim at stationary objects if ( Pawn(Target) == None ) { if ( !FiredAmmunition.bTossed ) return rotator(Target.Location - projstart); else { FireDir = AdjustToss(projspeed,ProjStart,Target.Location,true); SetRotation(Rotator(FireDir)); return Rotation; } } bLeadTargetNow = FiredAmmunition.bLeadTarget && bLeadTarget; bDefendMelee = ( (Target == Enemy) && DefendMelee(TargetDist) ); aimerror = AdjustAimError(aimerror,TargetDist,bDefendMelee,FiredAmmunition.bInstantHit, bLeadTargetNow); // lead target with non instant hit projectiles if ( bLeadTargetNow ) { TargetVel = Target.Velocity; // hack guess at projecting falling velocity of target if ( Target.Physics == PHYS_Falling ) { if ( Target.PhysicsVolume.Gravity.Z <= Target.PhysicsVolume.Default.Gravity.Z ) TargetVel.Z = FMin(TargetVel.Z + FMax(-400, Target.PhysicsVolume.Gravity.Z * FMin(1,TargetDist/projSpeed)),0); else TargetVel.Z = FMin(0, TargetVel.Z); } // more or less lead target (with some random variation) FireSpot += FMin(1, 0.7 + 0.6 * FRand()) * TargetVel * TargetDist/projSpeed; FireSpot.Z = FMin(Target.Location.Z, FireSpot.Z); if ( (Target.Physics != PHYS_Falling) && (FRand() < 0.55) && (VSize(FireSpot - ProjStart) > 1000) ) { // don't always lead far away targets, especially if they are moving sideways with respect to the bot TargetLook = Target.Rotation; if ( Target.Physics == PHYS_Walking ) TargetLook.Pitch = 0; bClean = ( ((Vector(TargetLook) Dot Normal(Target.Velocity)) >= 0.71) && FastTrace(FireSpot, ProjStart) ); } else // make sure that bot isn't leading into a wall bClean = FastTrace(FireSpot, ProjStart); if ( !bClean) { // reduce amount of leading if ( FRand() < 0.3 ) FireSpot = Target.Location; else FireSpot = 0.5 * (FireSpot + Target.Location); } } bClean = false; //so will fail first check unless shooting at feet if ( FiredAmmunition.bTrySplash && (Pawn(Target) != None) && ((Skill >=4) || bDefendMelee) && (((Target.Physics == PHYS_Falling) && (Pawn.Location.Z + 80 >= Target.Location.Z)) || ((Pawn.Location.Z + 19 >= Target.Location.Z) && (bDefendMelee || (skill > 6.5 * FRand() - 0.5)))) ) { HitActor = Trace(HitLocation, HitNormal, FireSpot - vect(0,0,1) * (Target.CollisionHeight + 6), FireSpot, false); bClean = (HitActor == None); if ( !bClean ) { FireSpot = HitLocation + vect(0,0,3); bClean = FastTrace(FireSpot, ProjStart); } else bClean = ( (Target.Physics == PHYS_Falling) && FastTrace(FireSpot, ProjStart) ); } if ( !bClean ) { //try middle FireSpot.Z = Target.Location.Z; bClean = FastTrace(FireSpot, ProjStart); } if ( FiredAmmunition.bTossed && !bClean && bEnemyInfoValid ) { FireSpot = LastSeenPos; HitActor = Trace(HitLocation, HitNormal, FireSpot, ProjStart, false); if ( HitActor != None ) { bCanFire = false; FireSpot += 2 * Target.CollisionHeight * HitNormal; } bClean = true; } if( !bClean ) { // try head FireSpot.Z = Target.Location.Z + 0.9 * Target.CollisionHeight; bClean = FastTrace(FireSpot, ProjStart); } if ( !bClean && (Target == Enemy) && bEnemyInfoValid ) { FireSpot = LastSeenPos; if ( Pawn.Location.Z >= LastSeenPos.Z ) FireSpot.Z -= 0.4 * Enemy.CollisionHeight; HitActor = Trace(HitLocation, HitNormal, FireSpot, ProjStart, false); if ( HitActor != None ) { FireSpot = LastSeenPos + 2 * Enemy.CollisionHeight * HitNormal; if ( Monster(Pawn).SplashDamage() && (Skill >= 4) ) { HitActor = Trace(HitLocation, HitNormal, FireSpot, ProjStart, false); if ( HitActor != None ) FireSpot += 2 * Enemy.CollisionHeight * HitNormal; } bCanFire = false; } } // adjust for toss distance if ( FiredAmmunition.bTossed ) FireDir = AdjustToss(projspeed,ProjStart,FireSpot,true); else FireDir = FireSpot - ProjStart; FireRotation = Rotator(FireDir); realYaw = FireRotation.Yaw; InstantWarnTarget(Target,FiredAmmunition,vector(FireRotation)); FireRotation.Yaw = SetFireYaw(FireRotation.Yaw + aimerror); FireDir = vector(FireRotation); // avoid shooting into wall FireDist = FMin(VSize(FireSpot-ProjStart), 400); FireSpot = ProjStart + FireDist * FireDir; HitActor = Trace(HitLocation, HitNormal, FireSpot, ProjStart, false); if ( HitActor != None ) { if ( HitNormal.Z < 0.7 ) { FireRotation.Yaw = SetFireYaw(realYaw - aimerror); FireDir = vector(FireRotation); FireSpot = ProjStart + FireDist * FireDir; HitActor = Trace(HitLocation, HitNormal, FireSpot, ProjStart, false); } if ( HitActor != None ) { FireSpot += HitNormal * 2 * Target.CollisionHeight; if ( Skill >= 4 ) { HitActor = Trace(HitLocation, HitNormal, FireSpot, ProjStart, false); if ( HitActor != None ) FireSpot += Target.CollisionHeight * HitNormal; } FireDir = Normal(FireSpot - ProjStart); FireRotation = rotator(FireDir); } } SetRotation(FireRotation); return FireRotation; } function ReceiveWarning(Pawn shooter, float projSpeed, vector FireDir) { local float enemyDist, DodgeSkill; local vector X,Y,Z, enemyDir; // AI controlled creatures may duck if not falling DodgeSkill = Skill + Monster(Pawn).DodgeSkillAdjust; if ( (Pawn.health <= 0) || (DodgeSkill < 4) || (Enemy == None) || !Monster(Pawn).bCanDodge || (Pawn.Physics == PHYS_Falling) || (Pawn.Physics == PHYS_Swimming) || (FRand() > 0.2 * DodgeSkill - 0.4) ) return; // and projectile time is long enough enemyDist = VSize(shooter.Location - Pawn.Location); if (enemyDist/projSpeed < 0.11 + 0.15 * FRand()) return; // only if tight FOV GetAxes(Pawn.Rotation,X,Y,Z); enemyDir = (shooter.Location - Pawn.Location)/enemyDist; if ((enemyDir Dot X) < 0.8) return; if ( (FireDir Dot Y) > 0 ) { Y *= -1; TryToDuck(Y, true); } else TryToDuck(Y, false); } function bool TryToDuck(vector duckDir, bool bReversed) { local vector HitLocation, HitNormal, Extent; local actor HitActor; local bool bSuccess, bDuckLeft; if ( Pawn.PhysicsVolume.bWaterVolume || (Pawn.PhysicsVolume.Gravity.Z > Pawn.PhysicsVolume.Default.Gravity.Z) ) return false; duckDir.Z = 0; bDuckLeft = !bReversed; Extent = Pawn.GetCollisionExtent(); HitActor = Trace(HitLocation, HitNormal, Pawn.Location + 240 * duckDir, Pawn.Location, false, Extent); bSuccess = ( (HitActor == None) || (VSize(HitLocation - Pawn.Location) > 150) ); if ( !bSuccess ) { bDuckLeft = !bDuckLeft; duckDir *= -1; HitActor = Trace(HitLocation, HitNormal, Pawn.Location + 240 * duckDir, Pawn.Location, false, Extent); bSuccess = ( (HitActor == None) || (VSize(HitLocation - Pawn.Location) > 150) ); } if ( !bSuccess ) return false; if ( HitActor == None ) HitLocation = Pawn.Location + 240 * duckDir; HitActor = Trace(HitLocation, HitNormal, HitLocation - MAXSTEPHEIGHT * vect(0,0,1), HitLocation, false, Extent); if (HitActor == None) return false; if ( bDuckLeft ) UnrealPawn(Pawn).CurrentDir = DCLICK_Left; else UnrealPawn(Pawn).CurrentDir = DCLICK_Right; UnrealPawn(Pawn).Dodge(UnrealPawn(Pawn).CurrentDir); return true; } function NotifyKilled(Controller Killer, Controller Killed, pawn KilledPawn) { if ( Killer == self ) Celebrate(); if ( (KilledPawn == Enemy) || (Killed != None && Killed.bIsPlayer && (Enemy == None)) ) { Enemy = None; FindNewEnemy(); } } function Actor FaceMoveTarget() { if ( MoveTarget != Enemy ) StopFiring(); return MoveTarget; } function bool ShouldStrafeTo(Actor WayPoint) { local NavigationPoint N; if ( Monster(Pawn).bAlwaysStrafe ) return true; if ( Skill + StrafingAbility < 3 ) return false; if ( WayPoint == Enemy ) { if ( Monster(Pawn).PreferMelee() ) return false; return ( Skill + StrafingAbility < 5 * FRand() - 1 ); } else if ( Pickup(WayPoint) == None ) { N = NavigationPoint(WayPoint); if ( (N == None) || N.bNeverUseStrafing ) return false; if ( N.FearCost > 200 ) return true; if ( N.bAlwaysUseStrafing && (FRand() < 0.8) ) return true; } if ( Pawn(WayPoint) != None ) return ( Skill + StrafingAbility < 5 * FRand() - 1 ); if ( Skill + StrafingAbility < 7 * FRand() - 1 ) return false; if ( Enemy == None ) return ( FRand() < 0.4 ); if ( EnemyVisible() ) return ( FRand() < 0.85 ); return ( FRand() < 0.6 ); } function Actor FaceActor(float StrafingModifier) { local float RelativeDir; bRecommendFastMove = false; if ( (Enemy == None) || (Level.TimeSeconds - LastSeenTime > 6 - StrafingModifier) ) return FaceMoveTarget(); if ( MoveTarget == Enemy ) return Enemy; if ( Level.TimeSeconds - LastSeenTime > 4 - StrafingModifier) return FaceMoveTarget(); if ( (Skill > 2.5) && (GameObject(MoveTarget) != None) ) return Enemy; RelativeDir = Normal(Enemy.Location - Pawn.Location - vect(0,0,1) * (Enemy.Location.Z - Pawn.Location.Z)) Dot Normal(MoveTarget.Location - Pawn.Location - vect(0,0,1) * (MoveTarget.Location.Z - Pawn.Location.Z)); if ( RelativeDir > 0.85 ) return Enemy; if ( (RelativeDir > 0.3) && (Bot(Enemy.Controller) != None) && (MoveTarget == Enemy.Controller.MoveTarget) ) return Enemy; if ( skill + StrafingAbility < 2 + FRand() ) return FaceMoveTarget(); if ( (RelativeDir < 0.3) || (Skill + StrafingAbility < (5 + StrafingModifier) * FRand()) || (0.4*RelativeDir + 0.8 < FRand()) ) return FaceMoveTarget(); return Enemy; } function WanderOrCamp(bool bMayCrouch) { GotoState('RestFormation'); } event float Desireability(Pickup P) { return -1; } function DamageAttitudeTo(Pawn Other, float Damage) { if ( (Pawn.health > 0) && (Damage > 0) && SetEnemy(Other,true) ) WhatToDoNext(5); } //********************************************************************************** // AI States //======================================================================================================= // No goal/no enemy states state NoGoal { } function bool Formation() { return false; } state RestFormation extends NoGoal { ignores EnemyNotVisible; function CancelCampFor(Controller C) { DirectedWander(Normal(Pawn.Location - C.Pawn.Location)); } function bool Formation() { return true; } function Timer() { SetCombatTimer(); enable('NotifyBump'); } function PickDestination() { if ( TestDirection(VRand(),Destination) ) return; TestDirection(VRand(),Destination); } function BeginState() { Enemy = None; Pawn.bCanJump = false; Pawn.bAvoidLedges = true; Pawn.bStopAtLedges = true; Pawn.SetWalking(true); MinHitWall += 0.15; } function EndState() { MonitoredPawn = None; MinHitWall -= 0.15; if ( Pawn != None ) { Pawn.bStopAtLedges = false; Pawn.bAvoidLedges = false; Pawn.SetWalking(false); if (Pawn.JumpZ > 0) Pawn.bCanJump = true; } } event MonitoredPawnAlert() { WhatToDoNext(6); } Begin: WaitForLanding(); Camping: Pawn.Acceleration = vect(0,0,0); Focus = None; FocalPoint = VRand(); NearWall(MINVIEWDIST); FinishRotation(); Sleep(3 + FRand()); Moving: WaitForLanding(); PickDestination(); WaitForAnim: if ( Monster(Pawn).bShotAnim ) { Sleep(0.5); Goto('WaitForAnim'); } MoveTo(Destination,,true); if ( Pawn.bCanFly && (Physics == PHYS_Walking) ) SetPhysics(PHYS_Flying); WhatToDoNext(8); Goto('Begin'); } function Celebrate() { Pawn.PlayVictoryAnimation(); } //======================================================================================================= // Move To Goal states state MoveToGoal { function Timer() { SetCombatTimer(); enable('NotifyBump'); } } state MoveToGoalNoEnemy extends MoveToGoal { } state MoveToGoalWithEnemy extends MoveToGoal { function Timer() { TimedFireWeaponAtEnemy(); } } state Roaming extends MoveToGoalNoEnemy { ignores EnemyNotVisible; function MayFall() { Pawn.bCanJump = ( (MoveTarget != None) && ((MoveTarget.Physics != PHYS_Falling) || !MoveTarget.IsA('Pickup')) ); } Begin: SwitchToBestWeapon(); WaitForLanding(); MoveToward(MoveTarget,FaceActor(1),,ShouldStrafeTo(MoveTarget)); DoneRoaming: WaitForLanding(); WhatToDoNext(12); if ( bSoaking ) SoakStop("STUCK IN ROAMING!"); } //======================================================================================================================= // Tactical Combat states function DoStakeOut() { GotoState('StakeOut'); } function DoCharge() { if ( Enemy.PhysicsVolume.bWaterVolume ) { if ( !Pawn.bCanSwim ) { DoTacticalMove(); return; } } else if ( !Pawn.bCanFly && !Pawn.bCanWalk ) { DoTacticalMove(); return; } GotoState('Charging'); } function DoTacticalMove() { GotoState('TacticalMove'); } /* DefendMelee() return true if defending against melee attack */ function bool DefendMelee(float Dist) { return ( (Enemy.Weapon != None) && Enemy.Weapon.bMeleeWeapon && (Dist < 1000) ); } state Charging extends MoveToGoalWithEnemy { ignores SeePlayer, HearNoise; /* MayFall() called by engine physics if walking and bCanJump, and is about to go off a ledge. Pawn has opportunity (by setting bCanJump to false) to avoid fall */ function MayFall() { if ( MoveTarget != Enemy ) return; Pawn.bCanJump = ActorReachable(Enemy); if ( !Pawn.bCanJump ) MoveTimer = -1.0; } function bool TryToDuck(vector duckDir, bool bReversed) { if ( FRand() < 0.6 ) return Global.TryToDuck(duckDir, bReversed); if ( MoveTarget == Enemy ) return TryStrafe(duckDir); } function bool StrafeFromDamage(float Damage, class<DamageType> DamageType, bool bFindDest) { local vector sideDir; if ( FRand() * Damage < 0.15 * CombatStyle * Pawn.Health ) return false; if ( !bFindDest ) return true; sideDir = Normal( Normal(Enemy.Location - Pawn.Location) Cross vect(0,0,1) ); if ( (Pawn.Velocity Dot sidedir) > 0 ) sidedir *= -1; return TryStrafe(sideDir); } function bool TryStrafe(vector sideDir) { local vector extent, HitLocation, HitNormal; local actor HitActor; Extent = Pawn.GetCollisionExtent(); HitActor = Trace(HitLocation, HitNormal, Pawn.Location + MINSTRAFEDIST * sideDir, Pawn.Location, false, Extent); if (HitActor != None) { sideDir *= -1; HitActor = Trace(HitLocation, HitNormal, Pawn.Location + MINSTRAFEDIST * sideDir, Pawn.Location, false, Extent); } if (HitActor != None) return false; if ( Pawn.Physics == PHYS_Walking ) { HitActor = Trace(HitLocation, HitNormal, Pawn.Location + MINSTRAFEDIST * sideDir - MAXSTEPHEIGHT * vect(0,0,1), Pawn.Location + MINSTRAFEDIST * sideDir, false, Extent); if ( HitActor == None ) return false; } Destination = Pawn.Location + 2 * MINSTRAFEDIST * sideDir; GotoState('TacticalMove', 'DoStrafeMove'); return true; } function NotifyTakeHit(pawn InstigatedBy, vector HitLocation, int Damage, class<DamageType> damageType, vector Momentum) { local float pick; local vector sideDir; local bool bWasOnGround; Super.NotifyTakeHit(InstigatedBy,HitLocation, Damage,DamageType,Momentum); bWasOnGround = (Pawn.Physics == PHYS_Walking); if ( Pawn.health <= 0 ) return; if ( StrafeFromDamage(damage, damageType, true) ) return; else if ( bWasOnGround && (MoveTarget == Enemy) && (Pawn.Physics == PHYS_Falling) ) //weave { pick = 1.0; if ( bStrafeDir ) pick = -1.0; sideDir = Normal( Normal(Enemy.Location - Pawn.Location) Cross vect(0,0,1) ); sideDir.Z = 0; Pawn.Velocity += pick * Pawn.GroundSpeed * 0.7 * sideDir; if ( FRand() < 0.2 ) bStrafeDir = !bStrafeDir; } } event bool NotifyBump(actor Other) { if ( Other == Enemy ) { DoRangedAttackOn(Enemy); return false; } return Global.NotifyBump(Other); } function Timer() { enable('NotifyBump'); Target = Enemy; TimedFireWeaponAtEnemy(); } function EnemyNotVisible() { WhatToDoNext(15); } function EndState() { if ( (Pawn != None) && Pawn.JumpZ > 0 ) Pawn.bCanJump = true; } Begin: if (Pawn.Physics == PHYS_Falling) { Focus = Enemy; Destination = Enemy.Location; WaitForLanding(); } if ( Enemy == None ) WhatToDoNext(16); WaitForAnim: if ( Monster(Pawn).bShotAnim ) { Sleep(0.35); Goto('WaitForAnim'); } if ( !FindBestPathToward(Enemy, false,true) ) GotoState('TacticalMove'); Moving: MoveToward(MoveTarget,FaceActor(1),,ShouldStrafeTo(MoveTarget)); WhatToDoNext(17); if ( bSoaking ) SoakStop("STUCK IN CHARGING!"); } function bool IsStrafing() { return false; } state TacticalMove { ignores SeePlayer, HearNoise; function bool IsStrafing() { return true; } function ReceiveWarning(Pawn shooter, float projSpeed, vector FireDir) { if ( bCanFire && (FRand() < 0.4) ) return; Super.ReceiveWarning(shooter, projSpeed, FireDir); } function SetFall() { Pawn.Acceleration = vect(0,0,0); Destination = Pawn.Location; Global.SetFall(); } function bool NotifyHitWall(vector HitNormal, actor Wall) { if (Pawn.Physics == PHYS_Falling) return false; if ( Enemy == None ) { WhatToDoNext(18); return false; } if ( bChangeDir || (FRand() < 0.5) || (((Enemy.Location - Pawn.Location) Dot HitNormal) < 0) ) { Focus = Enemy; WhatToDoNext(19); } else { bChangeDir = true; Destination = Pawn.Location - HitNormal * FRand() * 500; } return true; } function Timer() { enable('NotifyBump'); Target = Enemy; if ( Enemy != None ) TimedFireWeaponAtEnemy(); else SetCombatTimer(); } function EnemyNotVisible() { StopFiring(); if ( FastTrace(Enemy.Location, LastSeeingPos) ) GotoState('TacticalMove','RecoverEnemy'); else WhatToDoNext(20); Disable('EnemyNotVisible'); } function PawnIsInPain(PhysicsVolume PainVolume) { Destination = Pawn.Location - MINSTRAFEDIST * Normal(Pawn.Velocity); } /* PickDestination() Choose a destination for the tactical move, based on aggressiveness and the tactical situation. Make sure destination is reachable */ function PickDestination() { local vector pickdir, enemydir, enemyPart, Y; local float strafeSize; if ( Pawn == None ) { warn(self$" Tactical move pick destination with no pawn"); return; } bChangeDir = false; if ( Pawn.PhysicsVolume.bWaterVolume && !Pawn.bCanSwim && Pawn.bCanFly) { Destination = Pawn.Location + 75 * (VRand() + vect(0,0,1)); Destination.Z += 100; return; } enemydir = Normal(Enemy.Location - Pawn.Location); Y = (enemydir Cross vect(0,0,1)); if ( Pawn.Physics == PHYS_Walking ) { Y.Z = 0; enemydir.Z = 0; } else enemydir.Z = FMax(0,enemydir.Z); strafeSize = FClamp((2 * FRand() - 0.65),-0.7,0.7); strafeSize = FMax(0.4 * FRand() - 0.2,strafeSize); enemyPart = enemydir * strafeSize; if ( Pawn.bCanFly ) { if ( Pawn.Location.Z - Enemy.Location.Z < 1000 ) enemyPart = enemyPart + FRand() * vect(0,0,1); else enemyPart = enemyPart - FRand() * vect(0,0,0.7); } strafeSize = FMax(0.0, 1 - Abs(strafeSize)); pickdir = strafeSize * Y; if ( bStrafeDir ) pickdir *= -1; bStrafeDir = !bStrafeDir; if ( EngageDirection(enemyPart + pickdir, false) ) return; if ( EngageDirection(enemyPart - pickdir,false) ) return; bForcedDirection = true; StartTacticalTime = Level.TimeSeconds; EngageDirection(EnemyPart + PickDir, true); } function bool EngageDirection(vector StrafeDir, bool bForced) { local actor HitActor; local vector HitLocation, collspec, MinDest, HitNormal; // successfully engage direction if can trace out and down MinDest = Pawn.Location + MINSTRAFEDIST * StrafeDir; if ( !bForced ) { collSpec = Pawn.GetCollisionExtent(); collSpec.Z = FMax(6, Pawn.CollisionHeight - Pawn.CollisionRadius); HitActor = Trace(HitLocation, HitNormal, MinDest, Pawn.Location, false, collSpec); if ( HitActor != None ) return false; if ( Pawn.Physics == PHYS_Walking ) { collSpec.X = FMin(14, 0.5 * Pawn.CollisionRadius); collSpec.Y = collSpec.X; HitActor = Trace(HitLocation, HitNormal, minDest - (Pawn.CollisionRadius + MAXSTEPHEIGHT) * vect(0,0,1), minDest, false, collSpec); if ( HitActor == None ) { HitNormal = -1 * StrafeDir; return false; } } } Destination = MinDest + StrafeDir * (0.5 * MINSTRAFEDIST + FMin(VSize(Enemy.Location - Pawn.Location), MINSTRAFEDIST * (FRand() + FRand()))); return true; } function BeginState() { bForcedDirection = false; if ( Skill < 4 ) Pawn.MaxDesiredSpeed = 0.4 + 0.08 * skill; MinHitWall += 0.15; Pawn.bAvoidLedges = true; Pawn.bStopAtLedges = true; Pawn.bCanJump = false; bAdjustFromWalls = false; } function EndState() { bAdjustFromWalls = true; if ( Pawn == None ) return; SetMaxDesiredSpeed(); Pawn.bAvoidLedges = false; Pawn.bStopAtLedges = false; MinHitWall -= 0.15; if (Pawn.JumpZ > 0) Pawn.bCanJump = true; } TacticalTick: Sleep(0.02); Begin: if (Pawn.Physics == PHYS_Falling) { Focus = Enemy; Destination = Enemy.Location; WaitForLanding(); } PickDestination(); DoMove: if ( !Pawn.bCanStrafe ) { StopFiring(); WaitForAnim: if ( Monster(Pawn).bShotAnim ) { Sleep(0.5); Goto('WaitForAnim'); } MoveTo(Destination); } else { DoStrafeMove: MoveTo(Destination, Enemy); } if ( bForcedDirection && (Level.TimeSeconds - StartTacticalTime < 0.2) ) { if ( Skill > 2 + 3 * FRand() ) { bMustCharge = true; WhatToDoNext(51); } GoalString = "RangedAttack from failed tactical"; DoRangedAttackOn(Enemy); } if ( (Enemy == None) || EnemyVisible() || !FastTrace(Enemy.Location, LastSeeingPos) || Monster(Pawn).PreferMelee() || !Pawn.bCanStrafe ) Goto('FinishedStrafe'); //CheckIfShouldCrouch(LastSeeingPos,Enemy.Location, 0.5); RecoverEnemy: GoalString = "Recover Enemy"; HidingSpot = Pawn.Location; StopFiring(); Sleep(0.1 + 0.2 * FRand()); Destination = LastSeeingPos + 4 * Pawn.CollisionRadius * Normal(LastSeeingPos - Pawn.Location); MoveTo(Destination, Enemy); if ( FireWeaponAt(Enemy) ) { Pawn.Acceleration = vect(0,0,0); if ( Monster(Pawn).SplashDamage() ) { StopFiring(); Sleep(0.05); } else Sleep(0.1 + 0.3 * FRand() + 0.06 * (7 - FMin(7,Skill))); if ( FRand() > 0.5 ) { Enable('EnemyNotVisible'); Destination = HidingSpot + 4 * Pawn.CollisionRadius * Normal(HidingSpot - Pawn.Location); Goto('DoMove'); } } FinishedStrafe: WhatToDoNext(21); if ( bSoaking ) SoakStop("STUCK IN TACTICAL MOVE!"); } function bool IsHunting() { return false; } state Hunting extends MoveToGoalWithEnemy { ignores EnemyNotVisible; /* MayFall() called by] engine physics if walking and bCanJump, and is about to go off a ledge. Pawn has opportunity (by setting bCanJump to false) to avoid fall */ function bool IsHunting() { return true; } function MayFall() { Pawn.bCanJump = ( (MoveTarget == None) || (MoveTarget.Physics != PHYS_Falling) || !MoveTarget.IsA('Pickup') ); } function SeePlayer(Pawn SeenPlayer) { if ( SeenPlayer == Enemy ) { if ( Level.timeseconds - ChallengeTime > 7 ) { ChallengeTime = Level.TimeSeconds; Monster(Pawn).PlayChallengeSound(); } VisibleEnemy = Enemy; EnemyVisibilityTime = Level.TimeSeconds; bEnemyIsVisible = true; Focus = Enemy; WhatToDoNext(22); } else Global.SeePlayer(SeenPlayer); } function Timer() { SetCombatTimer(); StopFiring(); } function PickDestination() { local vector nextSpot, ViewSpot,Dir; local float posZ; local bool bCanSeeLastSeen; // If no enemy, or I should see him but don't, then give up if ( (Enemy == None) || (Enemy.Health <= 0) ) { Enemy = None; WhatToDoNext(23); return; } if ( Pawn.JumpZ > 0 ) Pawn.bCanJump = true; if ( ActorReachable(Enemy) ) { Destination = Enemy.Location; MoveTarget = None; return; } ViewSpot = Pawn.Location + Pawn.BaseEyeHeight * vect(0,0,1); bCanSeeLastSeen = bEnemyInfoValid && FastTrace(LastSeenPos, ViewSpot); if ( FindBestPathToward(Enemy, true,true) ) return; if ( bSoaking && (Physics != PHYS_Falling) ) SoakStop("COULDN'T FIND PATH TO ENEMY "$Enemy); MoveTarget = None; if ( !bEnemyInfoValid ) { Enemy = None; WhatToDoNext(26); return; } Destination = LastSeeingPos; bEnemyInfoValid = false; if ( FastTrace(Enemy.Location, ViewSpot) && VSize(Pawn.Location - Destination) > Pawn.CollisionRadius ) { SeePlayer(Enemy); return; } posZ = LastSeenPos.Z + Pawn.CollisionHeight - Enemy.CollisionHeight; nextSpot = LastSeenPos - Normal(Enemy.Velocity) * Pawn.CollisionRadius; nextSpot.Z = posZ; if ( FastTrace(nextSpot, ViewSpot) ) Destination = nextSpot; else if ( bCanSeeLastSeen ) { Dir = Pawn.Location - LastSeenPos; Dir.Z = 0; if ( VSize(Dir) < Pawn.CollisionRadius ) { GoalString = "Stakeout 3 from hunt"; GotoState('StakeOut'); return; } Destination = LastSeenPos; } else { Destination = LastSeenPos; if ( !FastTrace(LastSeenPos, ViewSpot) ) { // check if could adjust and see it if ( PickWallAdjust(Normal(LastSeenPos - ViewSpot)) || FindViewSpot() ) { if ( Pawn.Physics == PHYS_Falling ) SetFall(); else GotoState('Hunting', 'AdjustFromWall'); } else { GoalString = "Stakeout 2 from hunt"; GotoState('StakeOut'); return; } } } } function bool FindViewSpot() { local vector X,Y,Z; GetAxes(Rotation,X,Y,Z); // try left and right if ( FastTrace(Enemy.Location, Pawn.Location + 2 * Y * Pawn.CollisionRadius) ) { Destination = Pawn.Location + 2.5 * Y * Pawn.CollisionRadius; return true; } if ( FastTrace(Enemy.Location, Pawn.Location - 2 * Y * Pawn.CollisionRadius) ) { Destination = Pawn.Location - 2.5 * Y * Pawn.CollisionRadius; return true; } if ( FRand() < 0.5 ) Destination = Pawn.Location - 2.5 * Y * Pawn.CollisionRadius; else Destination = Pawn.Location - 2.5 * Y * Pawn.CollisionRadius; return true; } function EndState() { if ( (Pawn != None) && (Pawn.JumpZ > 0) ) Pawn.bCanJump = true; } AdjustFromWall: MoveTo(Destination, MoveTarget); Begin: WaitForLanding(); if ( CanSee(Enemy) ) SeePlayer(Enemy); WaitForAnim: if ( Monster(Pawn).bShotAnim ) { Sleep(0.35); Goto('WaitForAnim'); } PickDestination(); if ( Level.timeseconds - ChallengeTime > 10 ) { ChallengeTime = Level.TimeSeconds; Monster(Pawn).PlayChallengeSound(); } SpecialNavig: if (MoveTarget == None) MoveTo(Destination); else MoveToward(MoveTarget,FaceActor(10),,(FRand() < 0.75) && ShouldStrafeTo(MoveTarget)); WhatToDoNext(27); if ( bSoaking ) SoakStop("STUCK IN HUNTING!"); } function bool Stopped() { return bPreparingMove; } state StakeOut { ignores EnemyNotVisible; function bool CanAttack(Actor Other) { return true; } function bool Stopped() { return true; } event SeePlayer(Pawn SeenPlayer) { if ( SeenPlayer == Enemy ) { VisibleEnemy = Enemy; EnemyVisibilityTime = Level.TimeSeconds; bEnemyIsVisible = true; if ( FRand() < 0.5 ) { Focus = Enemy; FireWeaponAt(Enemy); } WhatToDoNext(28); } else if ( SetEnemy(SeenPlayer) ) { if ( Enemy == SeenPlayer ) { VisibleEnemy = Enemy; EnemyVisibilityTime = Level.TimeSeconds; bEnemyIsVisible = true; } WhatToDoNext(29); } } /* DoStakeOut() called by ChooseAttackMode - if called in this state, means stake out twice in a row */ function DoStakeOut() { SetFocus(); if ( (FRand() < 0.3) || !FastTrace(FocalPoint + vect(0,0,0.9) * Enemy.CollisionHeight, Pawn.Location + vect(0,0,0.8) * Pawn.CollisionHeight) ) FindNewStakeOutDir(); GotoState('StakeOut','Begin'); } function NotifyTakeHit(pawn InstigatedBy, vector HitLocation, int Damage, class<DamageType> damageType, vector Momentum) { Super.NotifyTakeHit(InstigatedBy,HitLocation, Damage,DamageType,Momentum); if ( (Pawn.Health > 0) && (Damage > 0) ) { if ( InstigatedBy == Enemy ) AcquireTime = Level.TimeSeconds; WhatToDoNext(30); } } function Timer() { enable('NotifyBump'); SetCombatTimer(); } function rotator AdjustAim(FireProperties FiredAmmunition, vector projStart, int aimerror) { local vector FireSpot; local actor HitActor; local vector HitLocation, HitNormal; FireSpot = FocalPoint; HitActor = Trace(HitLocation, HitNormal, FireSpot, ProjStart, false); if( HitActor != None ) { FireSpot += 2 * Enemy.CollisionHeight * HitNormal; if ( !FastTrace(FireSpot, ProjStart) ) { FireSpot = FocalPoint; StopFiring(); } } SetRotation(Rotator(FireSpot - ProjStart)); return Rotation; } function FindNewStakeOutDir() { local NavigationPoint N, Best; local vector Dir, EnemyDir; local float Dist, BestVal, Val; EnemyDir = Normal(Enemy.Location - Pawn.Location); for ( N=Level.NavigationPointList; N!=None; N=N.NextNavigationPoint ) { Dir = N.Location - Pawn.Location; Dist = VSize(Dir); if ( (Dist < MAXSTAKEOUTDIST) && (Dist > MINSTRAFEDIST) ) { Val = (EnemyDir Dot Dir/Dist); if ( Level.Game.bTeamgame ) Val += FRand(); if ( (Val > BestVal) && LineOfSightTo(N) ) { BestVal = Val; Best = N; } } } if ( Best != None ) FocalPoint = Best.Location + 0.5 * Pawn.CollisionHeight * vect(0,0,1); } function SetFocus() { if ( bEnemyInfoValid ) FocalPoint = LastSeenPos; else FocalPoint = Enemy.Location; } function BeginState() { StopStartTime = Level.TimeSeconds; Pawn.Acceleration = vect(0,0,0); Pawn.bCanJump = false; SetFocus(); if ( !bEnemyInfoValid || !ClearShot(FocalPoint,false) || ((Level.TimeSeconds - LastSeenTime > 6) && (FRand() < 0.5)) ) FindNewStakeOutDir(); } function EndState() { if ( (Pawn != None) && (Pawn.JumpZ > 0) ) Pawn.bCanJump = true; } Begin: Pawn.Acceleration = vect(0,0,0); Focus = None; CheckIfShouldCrouch(Pawn.Location,FocalPoint, 1); FinishRotation(); if ( Monster(Pawn).HasRangedAttack() && (FRand() < 0.5) && (VSize(Enemy.Location - FocalPoint) < 150) && (Level.TimeSeconds - LastSeenTime < 4) && ClearShot(FocalPoint,true) ) { FireWeaponAt(Enemy); } else StopFiring(); Sleep(1 + FRand()); // check if uncrouching would help if ( Pawn.bIsCrouched && !FastTrace(FocalPoint, Pawn.Location + Pawn.EyeHeight * vect(0,0,1)) && FastTrace(FocalPoint, Pawn.Location + (Pawn.Default.EyeHeight + Pawn.Default.CollisionHeight - Pawn.CollisionHeight) * vect(0,0,1)) ) { Pawn.bWantsToCrouch = false; Sleep(0.15 + 0.05 * (1 + FRand()) * (10 - skill)); } WhatToDoNext(31); if ( bSoaking ) SoakStop("STUCK IN STAKEOUT!"); } state RangedAttack { ignores SeePlayer, HearNoise, Bump; function bool Stopped() { return true; } function CancelCampFor(Controller C) { DoTacticalMove(); } function StopFiring() { Global.StopFiring(); if ( bHasFired ) { bHasFired = false; WhatToDoNext(32); } } function EnemyNotVisible() { //let attack animation complete WhatToDoNext(33); } function Timer() { if ( Monster(Pawn).PreferMelee() ) { SetCombatTimer(); StopFiring(); WhatToDoNext(34); } else TimedFireWeaponAtEnemy(); } function DoRangedAttackOn(Actor A) { Target = A; GotoState('RangedAttack'); } function BeginState() { StopStartTime = Level.TimeSeconds; bHasFired = false; Pawn.Acceleration = vect(0,0,0); //stop if ( Target == None ) Target = Enemy; if ( Target == None ) log(GetHumanReadableName()$" no target in ranged attack"); } Begin: bHasFired = false; GoalString = "Ranged attack"; Focus = Target; Sleep(0.0); if ( Enemy != None ) CheckIfShouldCrouch(Pawn.Location,Enemy.Location, 1); if ( NeedToTurn(Target.Location) ) { Focus = Target; FinishRotation(); } bHasFired = true; if ( Target == Enemy ) TimedFireWeaponAtEnemy(); else FireWeaponAt(Target); Sleep(0.1); if ( Monster(Pawn).PreferMelee() || (Target == None) || (Target != Enemy) || Monster(Pawn).bBoss ) WhatToDoNext(35); if ( Enemy != None ) CheckIfShouldCrouch(Pawn.Location,Enemy.Location, 1); Focus = Target; Sleep(FMax(Monster(Pawn).RangedAttackTime(),0.2 + (0.5 + 0.5 * FRand()) * 0.4 * (7 - Skill))); WhatToDoNext(36); if ( bSoaking ) SoakStop("STUCK IN RANGEDATTACK!"); } function GameHasEnded() { } State WaitForAnim { ignores SeePlayer, HearNoise, KilledBy, NotifyBump, HitWall, NotifyPhysicsVolumeChange, NotifyHeadVolumeChange, Falling, TakeDamage, ReceiveWarning; event AnimEnd(int Channel) { Pawn.AnimEnd(Channel); if ( !Monster(Pawn).bShotAnim ) WhatToDoNext(99); } } State WaitingForLanding { function bool DoWaitForLanding() { if ( bJustLanded ) return false; BeginState(); return true; } function bool NotifyLanded(vector HitNormal) { bJustLanded = true; Super.NotifyLanded(HitNormal); WhatToDoNext(50); return false; } function Timer() { if ( Focus == Enemy ) TimedFireWeaponAtEnemy(); else SetCombatTimer(); } function BeginState() { bJustLanded = false; if ( (MoveTarget != None) && ((Enemy == None) ||(Focus != Enemy)) ) FaceActor(1.5); if ( (Enemy == None) || (Focus != Enemy) ) StopFiring(); } } defaultproperties { FovAngle=+00085.000000 bCanOpenDoors=true bCanDoSpecial=true bIsPlayer=false bLeadTarget=True CombatStyle=+00000.20000 bStasis=false RotationRate=(Pitch=3072,Yaw=30000,Roll=2048) RemoteRole=ROLE_None } |
Overview | Package | Class | Source | Class tree | Glossary | UnrealScript Documentation |
previous class next class | frames no frames |