1 (* Copyright (C) Doom 2D: Forever Developers
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, version 3 of the License ONLY.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 {$INCLUDE ../shared/a_modes.inc}
23 {$IFDEF USE_MEMPOOL}mempool
,{$ENDIF}
24 e_graphics
, g_playermodel
, g_basic
, g_textures
,
25 g_weapons
, g_phys
, g_sound
, g_saveload
, MAPDEF
,
58 AmmoLimits
: Array [0..1] of Array [A_BULLETS
..A_HIGH
] of Word =
59 ((200, 50, 50, 300, 100),
60 (400, 100, 100, 600, 200));
81 ANGLE_NONE
= Low(SmallInt);
83 CORPSE_STATE_REMOVEME
= 0;
84 CORPSE_STATE_NORMAL
= 1;
85 CORPSE_STATE_MESS
= 2;
87 PLAYER_RECT
: TRectWH
= (X
:15; Y
:12; Width
:34; Height
:52);
88 PLAYER_RECT_CX
= 15+(34 div 2);
89 PLAYER_RECT_CY
= 12+(52 div 2);
90 PLAYER_CORPSERECT
: TRectWH
= (X
:15; Y
:48; Width
:34; Height
:16);
93 PLAYER_HP_LIMIT
= 200;
95 PLAYER_AP_LIMIT
= 200;
99 PLAYER_BURN_TIME
= 110;
101 PLAYER1_DEF_COLOR
: TRGB
= (R
:64; G
:175; B
:48);
102 PLAYER2_DEF_COLOR
: TRGB
= (R
:96; G
:96; B
:96);
119 TPlayerStatArray
= Array of TPlayerStat
;
121 TPlayerSavedState
= record
129 Ammo
: Array [A_BULLETS
..A_HIGH
] of Word;
130 MaxAmmo
: Array [A_BULLETS
..A_HIGH
] of Word;
131 Weapon
: Array [WP_FIRST
..WP_LAST
] of Boolean;
132 Rulez
: Set of R_ITEM_BACKPACK
..R_BERSERK
;
141 TPlayer
= class{$IFDEF USE_MEMPOOL}(TPoolObject
){$ENDIF}
149 FDirection
: TDirection
;
157 FMonsterKills
: Integer;
163 FCanJetpack
: Boolean;
169 FNextWeapDelay
: Byte; // frames
170 FBFGFireCounter
: SmallInt;
171 FLastSpawnerUID
: Word;
175 FSpectatePlayer
: Integer;
176 FFirePainTime
: Integer;
179 FSavedState
: TPlayerSavedState
;
181 FModel
: TPlayerModel
;
182 FPunchAnim
: TAnimation
;
185 FActionForce
: Boolean;
186 FActionChanged
: Boolean;
188 FFireAngle
: SmallInt;
190 FShellTimer
: Integer;
192 FSawSound
: TPlayableSound
;
193 FSawSoundIdle
: TPlayableSound
;
194 FSawSoundHit
: TPlayableSound
;
195 FSawSoundSelect
: TPlayableSound
;
196 FFlameSoundOn
: TPlayableSound
;
197 FFlameSoundOff
: TPlayableSound
;
198 FFlameSoundWork
: TPlayableSound
;
199 FJetSoundOn
: TPlayableSound
;
200 FJetSoundOff
: TPlayableSound
;
201 FJetSoundFly
: TPlayableSound
;
205 FJustTeleported
: Boolean;
207 mEDamageType
: Integer;
210 function CollideLevel(XInc
, YInc
: Integer): Boolean;
211 function StayOnStep(XInc
, YInc
: Integer): Boolean;
212 function HeadInLiquid(XInc
, YInc
: Integer): Boolean;
213 function BodyInLiquid(XInc
, YInc
: Integer): Boolean;
214 function BodyInAcid(XInc
, YInc
: Integer): Boolean;
215 function FullInLift(XInc
, YInc
: Integer): Integer;
216 {procedure CollideItem();}
217 procedure FlySmoke(Times
: DWORD
= 1);
218 procedure OnFireFlame(Times
: DWORD
= 1);
219 function GetAmmoByWeapon(Weapon
: Byte): Word;
220 procedure SetAction(Action
: Byte; Force
: Boolean = False);
221 procedure OnDamage(Angle
: SmallInt); virtual;
222 function firediry(): Integer;
225 procedure Run(Direction
: TDirection
);
226 procedure NextWeapon();
227 procedure PrevWeapon();
234 function getNextWeaponIndex (): Byte; // return 255 for "no switch"
235 procedure resetWeaponQueue ();
236 function hasAmmoForWeapon (weapon
: Byte): Boolean;
238 procedure doDamage (v
: Integer);
240 function followCorpse(): Boolean;
243 FDamageBuffer
: Integer;
245 FAmmo
: Array [A_BULLETS
..A_HIGH
] of Word;
246 FMaxAmmo
: Array [A_BULLETS
..A_HIGH
] of Word;
247 FWeapon
: Array [WP_FIRST
..WP_LAST
] of Boolean;
248 FRulez
: Set of R_ITEM_BACKPACK
..R_BERSERK
;
250 FMegaRulez
: Array [MR_SUIT
..MR_MAX
] of DWORD
;
251 FReloading
: Array [WP_FIRST
..WP_LAST
] of Word;
252 FTime
: Array [T_RESPAWN
..T_FLAGCAP
] of DWORD
;
253 FKeys
: Array [KEY_LEFT
..KEY_CHAT
] of TKeyState
;
255 FPreferredTeam
: Byte;
258 FWantsInGame
: Boolean;
263 FActualModelName
: string;
272 // debug: viewport offset
273 viewPortX
, viewPortY
, viewPortW
, viewPortH
: Integer;
275 function isValidViewPort (): Boolean; inline;
277 constructor Create(); virtual;
278 destructor Destroy(); override;
279 procedure Respawn(Silent
: Boolean; Force
: Boolean = False); virtual;
280 function GetRespawnPoint(): Byte;
281 procedure PressKey(Key
: Byte; Time
: Word = 1);
282 procedure ReleaseKeys();
283 procedure SetModel(ModelName
: String);
284 procedure SetColor(Color
: TRGB
);
285 function GetColor(): TRGB
;
286 procedure SetWeapon(W
: Byte);
287 function IsKeyPressed(K
: Byte): Boolean;
288 function GetKeys(): Byte;
289 function PickItem(ItemType
: Byte; arespawn
: Boolean; var remove
: Boolean): Boolean; virtual;
290 function Collide(X
, Y
: Integer; Width
, Height
: Word): Boolean; overload
;
291 function Collide(Panel
: TPanel
): Boolean; overload
;
292 function Collide(X
, Y
: Integer): Boolean; overload
;
293 procedure SetDirection(Direction
: TDirection
);
294 procedure GetSecret();
295 function TeleportTo(X
, Y
: Integer; silent
: Boolean; dir
: Byte): Boolean;
297 procedure Push(vx
, vy
: Integer);
298 procedure ChangeModel(ModelName
: String);
299 procedure SwitchTeam
;
300 procedure ChangeTeam(Team
: Byte);
302 function GetFlag(Flag
: Byte): Boolean;
303 procedure SetFlag(Flag
: Byte);
304 function DropFlag(Silent
: Boolean = True): Boolean;
305 procedure AllRulez(Health
: Boolean);
306 procedure RestoreHealthArmor();
307 procedure FragCombo();
308 procedure GiveItem(ItemType
: Byte);
309 procedure Damage(value
: Word; SpawnerUID
: Word; vx
, vy
: Integer; t
: Byte); virtual;
310 function Heal(value
: Word; Soft
: Boolean): Boolean; virtual;
311 procedure MakeBloodVector(Count
: Word; VelX
, VelY
: Integer);
312 procedure MakeBloodSimple(Count
: Word);
313 procedure Kill(KillType
: Byte; SpawnerUID
: Word; t
: Byte);
314 procedure Reset(Force
: Boolean);
315 procedure Spectate(NoMove
: Boolean = False);
316 procedure SwitchNoClip
;
317 procedure SoftReset();
318 procedure Draw(); virtual;
319 procedure DrawPain();
320 procedure DrawPickup();
321 procedure DrawRulez();
323 procedure DrawIndicator(Color
: TRGB
);
324 procedure DrawBubble();
326 procedure Update(); virtual;
327 procedure RememberState();
328 procedure RecallState();
329 procedure SaveState (st
: TStream
); virtual;
330 procedure LoadState (st
: TStream
); virtual;
331 procedure PauseSounds(Enable
: Boolean);
332 procedure NetFire(Wpn
: Byte; X
, Y
, AX
, AY
: Integer; WID
: Integer = -1);
333 procedure DoLerp(Level
: Integer = 2);
334 procedure SetLerp(XTo
, YTo
: Integer);
335 procedure QueueWeaponSwitch(Weapon
: Byte);
336 procedure RealizeCurrentWeapon();
340 procedure JetpackOff
;
341 procedure CatchFire(Attacker
: Word; Timeout
: Integer = PLAYER_BURN_TIME
);
343 //WARNING! this does nothing for now, but still call it!
344 procedure positionChanged (); //WARNING! call this after entity position was changed, or coldet will not work right!
346 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
347 procedure moveBy (dx
, dy
: Integer); inline;
350 property Vel
: TPoint2i read FObj
.Vel
;
351 property Obj
: TObj read FObj
;
353 property Name
: String read FName write FName
;
354 property Model
: TPlayerModel read FModel
;
355 property Health
: Integer read FHealth write FHealth
;
356 property Lives
: Byte read FLives write FLives
;
357 property Armor
: Integer read FArmor write FArmor
;
358 property Air
: Integer read FAir write FAir
;
359 property JetFuel
: Integer read FJetFuel write FJetFuel
;
360 property Frags
: Integer read FFrags write FFrags
;
361 property Death
: Integer read FDeath write FDeath
;
362 property Kills
: Integer read FKills write FKills
;
363 property CurrWeap
: Byte read FCurrWeap write FCurrWeap
;
364 property MonsterKills
: Integer read FMonsterKills write FMonsterKills
;
365 property Secrets
: Integer read FSecrets
;
366 property GodMode
: Boolean read FGodMode write FGodMode
;
367 property NoTarget
: Boolean read FNoTarget write FNoTarget
;
368 property NoReload
: Boolean read FNoReload write FNoReload
;
369 property alive
: Boolean read FAlive write FAlive
;
370 property Flag
: Byte read FFlag
;
371 property Team
: Byte read FTeam write FTeam
;
372 property Direction
: TDirection read FDirection
;
373 property GameX
: Integer read FObj
.X write FObj
.X
;
374 property GameY
: Integer read FObj
.Y write FObj
.Y
;
375 property GameVelX
: Integer read FObj
.Vel
.X write FObj
.Vel
.X
;
376 property GameVelY
: Integer read FObj
.Vel
.Y write FObj
.Vel
.Y
;
377 property GameAccelX
: Integer read FObj
.Accel
.X write FObj
.Accel
.X
;
378 property GameAccelY
: Integer read FObj
.Accel
.Y write FObj
.Accel
.Y
;
379 property IncCam
: Integer read FIncCam write FIncCam
;
380 property UID
: Word read FUID write FUID
;
381 property JustTeleported
: Boolean read FJustTeleported write FJustTeleported
;
382 property NetTime
: LongWord read FNetTime write FNetTime
;
385 property eName
: String read FName write FName
;
386 property eHealth
: Integer read FHealth write FHealth
;
387 property eLives
: Byte read FLives write FLives
;
388 property eArmor
: Integer read FArmor write FArmor
;
389 property eAir
: Integer read FAir write FAir
;
390 property eJetFuel
: Integer read FJetFuel write FJetFuel
;
391 property eFrags
: Integer read FFrags write FFrags
;
392 property eDeath
: Integer read FDeath write FDeath
;
393 property eKills
: Integer read FKills write FKills
;
394 property eCurrWeap
: Byte read FCurrWeap write FCurrWeap
;
395 property eMonsterKills
: Integer read FMonsterKills write FMonsterKills
;
396 property eSecrets
: Integer read FSecrets write FSecrets
;
397 property eGodMode
: Boolean read FGodMode write FGodMode
;
398 property eNoTarget
: Boolean read FNoTarget write FNoTarget
;
399 property eNoReload
: Boolean read FNoReload write FNoReload
;
400 property eAlive
: Boolean read FAlive write FAlive
;
401 property eFlag
: Byte read FFlag
;
402 property eTeam
: Byte read FTeam write FTeam
;
403 property eDirection
: TDirection read FDirection
;
404 property eGameX
: Integer read FObj
.X write FObj
.X
;
405 property eGameY
: Integer read FObj
.Y write FObj
.Y
;
406 property eGameVelX
: Integer read FObj
.Vel
.X write FObj
.Vel
.X
;
407 property eGameVelY
: Integer read FObj
.Vel
.Y write FObj
.Vel
.Y
;
408 property eGameAccelX
: Integer read FObj
.Accel
.X write FObj
.Accel
.X
;
409 property eGameAccelY
: Integer read FObj
.Accel
.Y write FObj
.Accel
.Y
;
410 property eIncCam
: Integer read FIncCam write FIncCam
;
411 property eUID
: Word read FUID
;
412 property eJustTeleported
: Boolean read FJustTeleported
;
413 property eNetTime
: LongWord read FNetTime
;
415 // set this before assigning something to `eDamage`
416 property eDamageType
: Integer read mEDamageType write mEDamageType
;
417 property eDamage
: Integer write doDamage
;
428 WeaponPrior
: packed array [WP_FIRST
..WP_LAST
] of Byte;
429 CloseWeaponPrior
: packed array [WP_FIRST
..WP_LAST
] of Byte;
430 //SafeWeaponPrior: Array [WP_FIRST..WP_LAST] of Byte;
433 procedure save (st
: TStream
);
434 procedure load (st
: TStream
);
442 TBot
= class(TPlayer
)
444 FSelectedWeapon
: Byte;
447 FAIFlags
: Array of TAIFlag
;
448 FDifficult
: TDifficult
;
450 function GetRnd(a
: Byte): Boolean;
451 function GetInterval(a
: Byte; radius
: SmallInt): SmallInt;
452 function RunDirection(): TDirection
;
453 function FullInStep(XInc
, YInc
: Integer): Boolean;
454 //function NeedItem(Item: Byte): Byte;
455 procedure SelectWeapon(Dist
: Integer);
456 procedure SetAIFlag(aName
, fValue
: String20
);
457 function GetAIFlag(aName
: String20
): String20
;
458 procedure RemoveAIFlag(aName
: String20
);
459 function Healthy(): Byte;
460 procedure UpdateMove();
461 procedure UpdateCombat();
462 function KeyPressed(Key
: Word): Boolean;
463 procedure ReleaseKey(Key
: Byte);
464 function TargetOnScreen(TX
, TY
: Integer): Boolean;
465 procedure OnDamage(Angle
: SmallInt); override;
468 procedure Respawn(Silent
: Boolean; Force
: Boolean = False); override;
469 constructor Create(); override;
470 destructor Destroy(); override;
471 procedure Draw(); override;
472 function PickItem(ItemType
: Byte; force
: Boolean; var remove
: Boolean): Boolean; override;
473 function Heal(value
: Word; Soft
: Boolean): Boolean; override;
474 procedure Update(); override;
475 procedure SaveState (st
: TStream
); override;
476 procedure LoadState (st
: TStream
); override;
488 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
489 procedure moveBy (dx
, dy
: Integer); inline;
491 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
505 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
506 procedure moveBy (dx
, dy
: Integer); inline;
508 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
511 TCorpse
= class{$IFDEF USE_MEMPOOL}(TPoolObject
){$ENDIF}
520 FAnimation
: TAnimation
;
521 FAnimationMask
: TAnimation
;
524 constructor Create(X
, Y
: Integer; ModelName
: String; aMess
: Boolean);
525 destructor Destroy(); override;
526 procedure Damage(Value
: Word; vx
, vy
: Integer);
529 procedure SaveState (st
: TStream
);
530 procedure LoadState (st
: TStream
);
532 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
533 procedure moveBy (dx
, dy
: Integer); inline;
535 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
537 function ObjPtr (): PObj
; inline;
539 property Obj
: TObj read FObj
; // copies object
540 property State
: Byte read FState
;
541 property Mess
: Boolean read FMess
;
544 TTeamStat
= Array [TEAM_RED
..TEAM_BLUE
] of
550 gPlayers
: Array of TPlayer
;
551 gCorpses
: Array of TCorpse
;
552 gGibs
: Array of TGib
;
553 gShells
: Array of TShell
;
554 gTeamStat
: TTeamStat
;
555 gFly
: Boolean = False;
556 gAimLine
: Boolean = False;
557 gChatBubble
: Byte = 0;
558 gPlayerIndicator
: Byte = 1;
562 MAX_RUNVEL
: Integer = 8;
563 VEL_JUMP
: Integer = 10;
564 SHELL_TIMEOUT
: Cardinal = 60000;
566 function Lerp(X
, Y
, Factor
: Integer): Integer;
568 procedure g_Gibs_SetMax(Count
: Word);
569 function g_Gibs_GetMax(): Word;
570 procedure g_Corpses_SetMax(Count
: Word);
571 function g_Corpses_GetMax(): Word;
572 procedure g_Shells_SetMax(Count
: Word);
573 function g_Shells_GetMax(): Word;
575 procedure g_Player_Init();
576 procedure g_Player_Free();
577 function g_Player_Create(ModelName
: String; Color
: TRGB
; Team
: Byte; Bot
: Boolean): Word;
578 function g_Player_CreateFromState (st
: TStream
): Word;
579 procedure g_Player_Remove(UID
: Word);
580 procedure g_Player_ResetTeams();
581 procedure g_Player_UpdateAll();
582 procedure g_Player_DrawAll();
583 procedure g_Player_DrawDebug(p
: TPlayer
);
584 procedure g_Player_DrawHealth();
585 procedure g_Player_RememberAll();
586 procedure g_Player_ResetAll(Force
, Silent
: Boolean);
587 function g_Player_Get(UID
: Word): TPlayer
;
588 function g_Player_GetCount(): Byte;
589 function g_Player_GetStats(): TPlayerStatArray
;
590 function g_Player_ValidName(Name
: String): Boolean;
591 procedure g_Player_CreateCorpse(Player
: TPlayer
);
592 procedure g_Player_CreateGibs(fX
, fY
: Integer; ModelName
: String; fColor
: TRGB
);
593 procedure g_Player_CreateShell(fX
, fY
, dX
, dY
: Integer; T
: Byte);
594 procedure g_Player_UpdatePhysicalObjects();
595 procedure g_Player_DrawCorpses();
596 procedure g_Player_DrawShells();
597 procedure g_Player_RemoveAllCorpses();
598 procedure g_Player_Corpses_SaveState (st
: TStream
);
599 procedure g_Player_Corpses_LoadState (st
: TStream
);
600 procedure g_Player_ResetReady();
601 procedure g_Bot_Add(Team
, Difficult
: Byte; Handicap
: Integer = 100);
602 procedure g_Bot_AddList(Team
: Byte; lname
: ShortString; num
: Integer = -1; Handicap
: Integer = 100);
603 procedure g_Bot_MixNames();
604 procedure g_Bot_RemoveAll();
609 {$INCLUDE ../nogl/noGLuses.inc}
610 {$IFDEF ENABLE_HOLMES}
613 e_log
, g_map
, g_items
, g_console
, g_gfx
, Math
,
614 g_options
, g_triggers
, g_menu
, g_game
, g_grid
,
615 wadreader
, g_main
, g_monsters
, CONFIG
, g_language
,
616 g_net
, g_netmsg
, g_window
,
619 const PLR_SAVE_VERSION
= 0;
629 diag_precision
: Byte;
633 w_prior1
: Array [WP_FIRST
..WP_LAST
] of Byte;
634 w_prior2
: Array [WP_FIRST
..WP_LAST
] of Byte;
635 w_prior3
: Array [WP_FIRST
..WP_LAST
] of Byte;
639 TIME_RESPAWN1
= 1500;
640 TIME_RESPAWN2
= 2000;
641 TIME_RESPAWN3
= 3000;
644 JET_MAX
= 540; // ~30 sec
645 PLAYER_SUIT_TIME
= 30000;
646 PLAYER_INVUL_TIME
= 30000;
647 PLAYER_INVIS_TIME
= 35000;
648 FRAG_COMBO_TIME
= 3000;
652 ANGLE_RIGHTDOWN
= -35;
654 ANGLE_LEFTDOWN
= -145;
655 PLAYER_HEADRECT
: TRectWH
= (X
:24; Y
:12; Width
:20; Height
:12);
656 WEAPONPOINT
: Array [TDirection
] of TDFPoint
= ((X
:16; Y
:32), (X
:47; Y
:32));
659 BOT_UNSAFEDIST
= 128;
660 TEAMCOLOR
: Array [TEAM_RED
..TEAM_BLUE
] of TRGB
= ((R
:255; G
:0; B
:0),
662 DIFFICULT_EASY
: TDifficult
= (DiagFire
: 32; InvisFire
: 32; DiagPrecision
: 32;
663 FlyPrecision
: 32; Cover
: 32; CloseJump
: 32;
664 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
665 DIFFICULT_MEDIUM
: TDifficult
= (DiagFire
: 127; InvisFire
: 127; DiagPrecision
: 127;
666 FlyPrecision
: 127; Cover
: 127; CloseJump
: 127;
667 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
668 DIFFICULT_HARD
: TDifficult
= (DiagFire
: 255; InvisFire
: 255; DiagPrecision
: 255;
669 FlyPrecision
: 255; Cover
: 255; CloseJump
: 255;
670 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
671 WEAPON_PRIOR1
: Array [WP_FIRST
..WP_LAST
] of Byte =
672 (WEAPON_FLAMETHROWER
, WEAPON_SUPERPULEMET
,
673 WEAPON_SHOTGUN2
, WEAPON_SHOTGUN1
,
674 WEAPON_CHAINGUN
, WEAPON_PLASMA
, WEAPON_ROCKETLAUNCHER
,
675 WEAPON_BFG
, WEAPON_PISTOL
, WEAPON_SAW
, WEAPON_KASTET
);
676 WEAPON_PRIOR2
: Array [WP_FIRST
..WP_LAST
] of Byte =
677 (WEAPON_FLAMETHROWER
, WEAPON_SUPERPULEMET
,
678 WEAPON_BFG
, WEAPON_ROCKETLAUNCHER
,
679 WEAPON_SHOTGUN2
, WEAPON_PLASMA
, WEAPON_SHOTGUN1
,
680 WEAPON_CHAINGUN
, WEAPON_PISTOL
, WEAPON_SAW
, WEAPON_KASTET
);
681 //WEAPON_PRIOR3: Array [WP_FIRST..WP_LAST] of Byte =
682 // (WEAPON_FLAMETHROWER, WEAPON_SUPERPULEMET,
683 // WEAPON_BFG, WEAPON_PLASMA, WEAPON_SHOTGUN2,
684 // WEAPON_CHAINGUN, WEAPON_SHOTGUN1, WEAPON_SAW,
685 // WEAPON_ROCKETLAUNCHER, WEAPON_PISTOL, WEAPON_KASTET);
686 WEAPON_RELOAD
: Array [WP_FIRST
..WP_LAST
] of Byte =
687 (5, 2, 6, 18, 36, 2, 12, 2, 14, 2, 2);
689 PLAYER_SIGNATURE
= $52594C50; // 'PLYR'
690 CORPSE_SIGNATURE
= $50524F43; // 'CORP'
692 BOTNAMES_FILENAME
= 'botnames.txt';
693 BOTLIST_FILENAME
= 'botlist.txt';
697 MaxCorpses
: Word = 20;
698 MaxShells
: Word = 300;
699 CurrentGib
: Integer = 0;
700 CurrentShell
: Integer = 0;
701 BotNames
: Array of String;
702 BotList
: Array of TBotProfile
;
705 function Lerp(X
, Y
, Factor
: Integer): Integer;
707 Result
:= X
+ ((Y
- X
) div Factor
);
710 function SameTeam(UID1
, UID2
: Word): Boolean;
714 if (UID1
> UID_MAX_PLAYER
) or (UID1
<= UID_MAX_GAME
) or
715 (UID2
> UID_MAX_PLAYER
) or (UID2
<= UID_MAX_GAME
) then Exit
;
717 if (g_Player_Get(UID1
) = nil) or (g_Player_Get(UID2
) = nil) then Exit
;
719 if ((g_Player_Get(UID1
).Team
= TEAM_NONE
) or
720 (g_Player_Get(UID2
).Team
= TEAM_NONE
)) then Exit
;
722 Result
:= g_Player_Get(UID1
).FTeam
= g_Player_Get(UID2
).FTeam
;
725 procedure g_Gibs_SetMax(Count
: Word);
728 SetLength(gGibs
, Count
);
730 if CurrentGib
>= Count
then
734 function g_Gibs_GetMax(): Word;
739 procedure g_Shells_SetMax(Count
: Word);
742 SetLength(gShells
, Count
);
744 if CurrentShell
>= Count
then
748 function g_Shells_GetMax(): Word;
754 procedure g_Corpses_SetMax(Count
: Word);
757 SetLength(gCorpses
, Count
);
760 function g_Corpses_GetMax(): Word;
762 Result
:= MaxCorpses
;
765 function g_Player_Create(ModelName
: String; Color
: TRGB
; Team
: Byte; Bot
: Boolean): Word;
775 // Åñòü ëè ìåñòî â gPlayers:
776 if gPlayers
<> nil then
777 for a
:= 0 to High(gPlayers
) do
778 if gPlayers
[a
] = nil then
784 // Íåò ìåñòà - ðàñøèðÿåì gPlayers:
787 SetLength(gPlayers
, Length(gPlayers
)+1);
791 // Ñîçäàåì îáúåêò èãðîêà:
793 gPlayers
[a
] := TBot
.Create()
795 gPlayers
[a
] := TPlayer
.Create();
798 gPlayers
[a
].FActualModelName
:= ModelName
;
799 gPlayers
[a
].SetModel(ModelName
);
801 // Íåò ìîäåëè - ñîçäàíèå íå âîçìîæíî:
802 if gPlayers
[a
].FModel
= nil then
806 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], [ModelName
]));
810 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
811 if Random(2) = 0 then
815 gPlayers
[a
].FPreferredTeam
:= Team
;
817 case gGameSettings
.GameMode
of
818 GM_DM
: gPlayers
[a
].FTeam
:= TEAM_NONE
;
820 GM_CTF
: gPlayers
[a
].FTeam
:= gPlayers
[a
].FPreferredTeam
;
822 GM_COOP
: gPlayers
[a
].FTeam
:= TEAM_COOP
;
825 // Åñëè êîìàíäíàÿ èãðà - êðàñèì ìîäåëü â öâåò êîìàíäû:
826 gPlayers
[a
].FColor
:= Color
;
827 if gPlayers
[a
].FTeam
in [TEAM_RED
, TEAM_BLUE
] then
828 gPlayers
[a
].FModel
.Color
:= TEAMCOLOR
[gPlayers
[a
].FTeam
]
830 gPlayers
[a
].FModel
.Color
:= Color
;
832 gPlayers
[a
].FUID
:= g_CreateUID(UID_PLAYER
);
833 gPlayers
[a
].FAlive
:= False;
835 Result
:= gPlayers
[a
].FUID
;
838 function g_Player_CreateFromState (st
: TStream
): Word;
845 if (st
= nil) then exit
; //???
848 if not utils
.checkSign(st
, 'PLYR') then raise XStreamError
.Create('invalid player signature');
849 if (utils
.readByte(st
) <> PLR_SAVE_VERSION
) then raise XStreamError
.Create('invalid player version');
852 Bot
:= utils
.readBool(st
);
857 // Åñòü ëè ìåñòî â gPlayers:
858 for a
:= 0 to High(gPlayers
) do if (gPlayers
[a
] = nil) then begin ok
:= true; break
; end;
860 // Íåò ìåñòà - ðàñøèðÿåì gPlayers
863 SetLength(gPlayers
, Length(gPlayers
)+1);
867 // Ñîçäàåì îáúåêò èãðîêà
869 gPlayers
[a
] := TBot
.Create()
871 gPlayers
[a
] := TPlayer
.Create();
872 gPlayers
[a
].FIamBot
:= Bot
;
873 gPlayers
[a
].FPhysics
:= True;
876 gPlayers
[a
].FUID
:= utils
.readWord(st
);
878 gPlayers
[a
].FName
:= utils
.readStr(st
);
880 gPlayers
[a
].FTeam
:= utils
.readByte(st
);
881 gPlayers
[a
].FPreferredTeam
:= gPlayers
[a
].FTeam
;
883 gPlayers
[a
].FAlive
:= utils
.readBool(st
);
884 // Èçðàñõîäîâàë ëè âñå æèçíè
885 gPlayers
[a
].FNoRespawn
:= utils
.readBool(st
);
887 b
:= utils
.readByte(st
);
888 if b
= 1 then gPlayers
[a
].FDirection
:= TDirection
.D_LEFT
else gPlayers
[a
].FDirection
:= TDirection
.D_RIGHT
; // b = 2
890 gPlayers
[a
].FHealth
:= utils
.readLongInt(st
);
892 gPlayers
[a
].FHandicap
:= utils
.readLongInt(st
);
894 gPlayers
[a
].FLives
:= utils
.readByte(st
);
896 gPlayers
[a
].FArmor
:= utils
.readLongInt(st
);
898 gPlayers
[a
].FAir
:= utils
.readLongInt(st
);
900 gPlayers
[a
].FJetFuel
:= utils
.readLongInt(st
);
902 gPlayers
[a
].FPain
:= utils
.readLongInt(st
);
904 gPlayers
[a
].FKills
:= utils
.readLongInt(st
);
906 gPlayers
[a
].FMonsterKills
:= utils
.readLongInt(st
);
908 gPlayers
[a
].FFrags
:= utils
.readLongInt(st
);
910 gPlayers
[a
].FFragCombo
:= utils
.readByte(st
);
911 // Âðåìÿ ïîñëåäíåãî ôðàãà
912 gPlayers
[a
].FLastFrag
:= utils
.readLongWord(st
);
914 gPlayers
[a
].FDeath
:= utils
.readLongInt(st
);
916 gPlayers
[a
].FFlag
:= utils
.readByte(st
);
918 gPlayers
[a
].FSecrets
:= utils
.readLongInt(st
);
920 gPlayers
[a
].FCurrWeap
:= utils
.readByte(st
);
921 // Ñëåäóþùåå æåëàåìîå îðóæèå
922 gPlayers
[a
].FNextWeap
:= utils
.readWord(st
);
924 gPlayers
[a
].FNextWeapDelay
:= utils
.readByte(st
);
926 gPlayers
[a
].FBFGFireCounter
:= utils
.readSmallInt(st
);
928 gPlayers
[a
].FDamageBuffer
:= utils
.readLongInt(st
);
929 // Ïîñëåäíèé óäàðèâøèé
930 gPlayers
[a
].FLastSpawnerUID
:= utils
.readWord(st
);
931 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà
932 gPlayers
[a
].FLastHit
:= utils
.readByte(st
);
934 Obj_LoadState(@gPlayers
[a
].FObj
, st
);
935 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ
936 for i
:= A_BULLETS
to A_HIGH
do gPlayers
[a
].FAmmo
[i
] := utils
.readWord(st
);
937 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ
938 for i
:= A_BULLETS
to A_HIGH
do gPlayers
[a
].FMaxAmmo
[i
] := utils
.readWord(st
);
940 for i
:= WP_FIRST
to WP_LAST
do gPlayers
[a
].FWeapon
[i
] := utils
.readBool(st
);
941 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ
942 for i
:= WP_FIRST
to WP_LAST
do gPlayers
[a
].FReloading
[i
] := utils
.readWord(st
);
944 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_ITEM_BACKPACK
);
945 // Íàëè÷èå êðàñíîãî êëþ÷à
946 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_KEY_RED
);
947 // Íàëè÷èå çåëåíîãî êëþ÷à
948 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_KEY_GREEN
);
949 // Íàëè÷èå ñèíåãî êëþ÷à
950 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_KEY_BLUE
);
952 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_BERSERK
);
953 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ
954 for i
:= MR_SUIT
to MR_MAX
do gPlayers
[a
].FMegaRulez
[i
] := utils
.readLongWord(st
);
955 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà
956 for i
:= T_RESPAWN
to T_FLAGCAP
do gPlayers
[a
].FTime
[i
] := utils
.readLongWord(st
);
959 gPlayers
[a
].FActualModelName
:= utils
.readStr(st
);
961 gPlayers
[a
].FColor
.R
:= utils
.readByte(st
);
962 gPlayers
[a
].FColor
.G
:= utils
.readByte(st
);
963 gPlayers
[a
].FColor
.B
:= utils
.readByte(st
);
964 // Îáíîâëÿåì ìîäåëü èãðîêà
965 gPlayers
[a
].SetModel(gPlayers
[a
].FActualModelName
);
967 // Íåò ìîäåëè - ñîçäàíèå íåâîçìîæíî
968 if (gPlayers
[a
].FModel
= nil) then
972 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], [gPlayers
[a
].FActualModelName
]));
976 // Åñëè êîìàíäíàÿ èãðà - êðàñèì ìîäåëü â öâåò êîìàíäû
977 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
978 gPlayers
[a
].FModel
.Color
:= TEAMCOLOR
[gPlayers
[a
].FTeam
]
980 gPlayers
[a
].FModel
.Color
:= gPlayers
[a
].FColor
;
982 result
:= gPlayers
[a
].FUID
;
986 procedure g_Player_ResetTeams();
990 if g_Game_IsClient
then
992 if gPlayers
= nil then
994 for a
:= Low(gPlayers
) to High(gPlayers
) do
995 if gPlayers
[a
] <> nil then
996 case gGameSettings
.GameMode
of
998 gPlayers
[a
].ChangeTeam(TEAM_NONE
);
1000 if not (gPlayers
[a
].Team
in [TEAM_RED
, TEAM_BLUE
]) then
1001 if gPlayers
[a
].FPreferredTeam
in [TEAM_RED
, TEAM_BLUE
] then
1002 gPlayers
[a
].ChangeTeam(gPlayers
[a
].FPreferredTeam
)
1005 gPlayers
[a
].ChangeTeam(TEAM_RED
)
1007 gPlayers
[a
].ChangeTeam(TEAM_BLUE
);
1010 gPlayers
[a
].ChangeTeam(TEAM_COOP
);
1014 procedure g_Bot_Add(Team
, Difficult
: Byte; Handicap
: Integer = 100);
1017 _name
, _model
: String;
1020 if not g_Game_IsServer
then Exit
;
1022 // Ñïèñîê íàçâàíèé ìîäåëåé:
1023 m
:= g_PlayerModel_GetNames();
1028 if (gGameSettings
.GameType
= GT_SINGLE
) or (gGameSettings
.GameMode
= GM_COOP
) then
1029 Team
:= TEAM_COOP
// COOP
1031 if gGameSettings
.GameMode
= GM_DM
then
1032 Team
:= TEAM_NONE
// DM
1034 if Team
= TEAM_NONE
then // CTF / TDM
1036 // Àâòîáàëàíñ êîìàíä:
1040 for a
:= 0 to High(gPlayers
) do
1041 if gPlayers
[a
] <> nil then
1043 if gPlayers
[a
].Team
= TEAM_RED
then
1046 if gPlayers
[a
].Team
= TEAM_BLUE
then
1056 if Random(2) = 0 then
1062 // Âûáèðàåì áîòó èìÿ:
1064 if BotNames
<> nil then
1065 for a
:= 0 to High(BotNames
) do
1066 if g_Player_ValidName(BotNames
[a
]) then
1068 _name
:= BotNames
[a
];
1072 // Èìåíè íåò, çàäàåì ñëó÷àéíîå:
1075 _name
:= Format('DFBOT%.2d', [Random(100)]);
1076 until g_Player_ValidName(_name
);
1078 // Âûáèðàåì ñëó÷àéíóþ ìîäåëü:
1079 _model
:= m
[Random(Length(m
))];
1082 with g_Player_Get(g_Player_Create(_model
,
1083 _RGB(Min(Random(9)*32, 255),
1084 Min(Random(9)*32, 255),
1085 Min(Random(9)*32, 255)),
1086 Team
, True)) as TBot
do
1091 1: FDifficult
:= DIFFICULT_EASY
;
1092 2: FDifficult
:= DIFFICULT_MEDIUM
;
1093 else FDifficult
:= DIFFICULT_HARD
;
1096 for a
:= WP_FIRST
to WP_LAST
do
1098 FDifficult
.WeaponPrior
[a
] := WEAPON_PRIOR1
[a
];
1099 FDifficult
.CloseWeaponPrior
[a
] := WEAPON_PRIOR2
[a
];
1100 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
1103 FHandicap
:= Handicap
;
1105 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [Name
]), True);
1107 if g_Game_IsNet
then MH_SEND_PlayerCreate(UID
);
1108 if g_Game_IsServer
and (gGameSettings
.MaxLives
> 0) then
1113 procedure g_Bot_AddList(Team
: Byte; lName
: ShortString; num
: Integer = -1; Handicap
: Integer = 100);
1116 _name
, _model
: String;
1119 if not g_Game_IsServer
then Exit
;
1121 // Ñïèñîê íàçâàíèé ìîäåëåé:
1122 m
:= g_PlayerModel_GetNames();
1127 if (gGameSettings
.GameType
= GT_SINGLE
) or (gGameSettings
.GameMode
= GM_COOP
) then
1128 Team
:= TEAM_COOP
// COOP
1130 if gGameSettings
.GameMode
= GM_DM
then
1131 Team
:= TEAM_NONE
// DM
1133 if Team
= TEAM_NONE
then
1134 Team
:= BotList
[num
].team
; // CTF / TDM
1136 // Âûáèðàåì íàñòðîéêè áîòà èç ñïèñêà ïî íîìåðó èëè èìåíè:
1137 lName
:= AnsiLowerCase(lName
);
1138 if (num
< 0) or (num
> Length(BotList
)-1) then
1140 if (num
= -1) and (lName
<> '') and (BotList
<> nil) then
1141 for a
:= 0 to High(BotList
) do
1142 if AnsiLowerCase(BotList
[a
].name
) = lName
then
1151 _name
:= BotList
[num
].name
;
1152 // Çàíÿòî - âûáèðàåì ñëó÷àéíîå:
1153 if not g_Player_ValidName(_name
) then
1155 _name
:= Format('DFBOT%.2d', [Random(100)]);
1156 until g_Player_ValidName(_name
);
1159 _model
:= BotList
[num
].model
;
1160 // Íåò òàêîé - âûáèðàåì ñëó÷àéíóþ:
1161 if not InSArray(_model
, m
) then
1162 _model
:= m
[Random(Length(m
))];
1165 with g_Player_Get(g_Player_Create(_model
, BotList
[num
].color
, Team
, True)) as TBot
do
1169 FDifficult
.DiagFire
:= BotList
[num
].diag_fire
;
1170 FDifficult
.InvisFire
:= BotList
[num
].invis_fire
;
1171 FDifficult
.DiagPrecision
:= BotList
[num
].diag_precision
;
1172 FDifficult
.FlyPrecision
:= BotList
[num
].fly_precision
;
1173 FDifficult
.Cover
:= BotList
[num
].cover
;
1174 FDifficult
.CloseJump
:= BotList
[num
].close_jump
;
1176 FHandicap
:= Handicap
;
1178 for a
:= WP_FIRST
to WP_LAST
do
1180 FDifficult
.WeaponPrior
[a
] := BotList
[num
].w_prior1
[a
];
1181 FDifficult
.CloseWeaponPrior
[a
] := BotList
[num
].w_prior2
[a
];
1182 //FDifficult.SafeWeaponPrior[a] := BotList[num].w_prior3[a];
1185 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [Name
]), True);
1187 if g_Game_IsNet
then MH_SEND_PlayerCreate(UID
);
1191 procedure g_Bot_RemoveAll();
1195 if not g_Game_IsServer
then Exit
;
1196 if gPlayers
= nil then Exit
;
1198 for a
:= 0 to High(gPlayers
) do
1199 if gPlayers
[a
] <> nil then
1200 if gPlayers
[a
] is TBot
then
1202 gPlayers
[a
].Lives
:= 0;
1203 gPlayers
[a
].Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
1204 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [gPlayers
[a
].Name
]), True);
1205 g_Player_Remove(gPlayers
[a
].FUID
);
1211 procedure g_Bot_MixNames();
1216 if BotNames
<> nil then
1217 for a
:= 0 to High(BotNames
) do
1219 b
:= Random(Length(BotNames
));
1221 Botnames
[a
] := BotNames
[b
];
1226 procedure g_Player_Remove(UID
: Word);
1230 if gPlayers
= nil then Exit
;
1232 if g_Game_IsServer
and g_Game_IsNet
then
1233 MH_SEND_PlayerDelete(UID
);
1235 for i
:= 0 to High(gPlayers
) do
1236 if gPlayers
[i
] <> nil then
1237 if gPlayers
[i
].FUID
= UID
then
1239 if gPlayers
[i
] is TPlayer
then
1240 TPlayer(gPlayers
[i
]).Free()
1242 TBot(gPlayers
[i
]).Free();
1248 procedure g_Player_Init();
1258 if not FileExists(DataDir
+ BOTNAMES_FILENAME
) then
1261 // ×èòàåì âîçìîæíûå èìåíà áîòîâ èç ôàéëà:
1262 AssignFile(F
, DataDir
+ BOTNAMES_FILENAME
);
1273 SetLength(BotNames
, Length(BotNames
)+1);
1274 BotNames
[High(BotNames
)] := s
;
1282 // ×èòàåì ôàéë ñ ïàðàìåòðàìè áîòîâ:
1283 config
:= TConfig
.CreateFile(DataDir
+ BOTLIST_FILENAME
);
1287 while config
.SectionExists(IntToStr(a
)) do
1289 SetLength(BotList
, Length(BotList
)+1);
1291 with BotList
[High(BotList
)] do
1294 name
:= config
.ReadStr(IntToStr(a
), 'name', '');
1296 model
:= config
.ReadStr(IntToStr(a
), 'model', '');
1298 if config
.ReadStr(IntToStr(a
), 'team', 'red') = 'red' then
1303 sa
:= parse(config
.ReadStr(IntToStr(a
), 'color', ''));
1304 color
.R
:= StrToIntDef(sa
[0], 0);
1305 color
.G
:= StrToIntDef(sa
[1], 0);
1306 color
.B
:= StrToIntDef(sa
[2], 0);
1307 // Âåðîÿòíîñòü ñòðåëüáû ïîä óãëîì:
1308 diag_fire
:= config
.ReadInt(IntToStr(a
), 'diag_fire', 0);
1309 // Âåðîÿòíîñòü îòâåòíîãî îãíÿ ïî íåâèäèìîìó ñîïåðíèêó:
1310 invis_fire
:= config
.ReadInt(IntToStr(a
), 'invis_fire', 0);
1311 // Òî÷íîñòü ñòðåëüáû ïîä óãëîì:
1312 diag_precision
:= config
.ReadInt(IntToStr(a
), 'diag_precision', 0);
1313 // Òî÷íîñòü ñòðåëüáû â ïîëåòå:
1314 fly_precision
:= config
.ReadInt(IntToStr(a
), 'fly_precision', 0);
1315 // Òî÷íîñòü óêëîíåíèÿ îò ñíàðÿäîâ:
1316 cover
:= config
.ReadInt(IntToStr(a
), 'cover', 0);
1317 // Âåðîÿòíîñòü ïðûæêà ïðè ïðèáëèæåíèè ñîïåðíèêà:
1318 close_jump
:= config
.ReadInt(IntToStr(a
), 'close_jump', 0);
1319 // Ïðèîðèòåòû îðóæèÿ äëÿ äàëüíåãî áîÿ:
1320 sa
:= parse(config
.ReadStr(IntToStr(a
), 'w_prior1', ''));
1321 if Length(sa
) = 10 then
1323 w_prior1
[b
] := EnsureRange(StrToInt(sa
[b
]), 0, 9);
1324 // Ïðèîðèòåòû îðóæèÿ äëÿ áëèæíåãî áîÿ:
1325 sa
:= parse(config
.ReadStr(IntToStr(a
), 'w_prior2', ''));
1326 if Length(sa
) = 10 then
1328 w_prior2
[b
] := EnsureRange(StrToInt(sa
[b
]), 0, 9);
1330 {sa := parse(config.ReadStr(IntToStr(a), 'w_prior3', ''));
1331 if Length(sa) = 10 then
1333 w_prior3[b] := EnsureRange(StrToInt(sa[b]), 0, 9);}
1342 procedure g_Player_Free();
1346 if gPlayers
<> nil then
1348 for i
:= 0 to High(gPlayers
) do
1349 if gPlayers
[i
] <> nil then
1351 if gPlayers
[i
] is TPlayer
then
1352 TPlayer(gPlayers
[i
]).Free()
1354 TBot(gPlayers
[i
]).Free();
1365 procedure g_Player_UpdateAll();
1369 if gPlayers
= nil then Exit
;
1371 //e_WriteLog('***g_Player_UpdateAll: ENTER', MSG_WARNING);
1372 for i
:= 0 to High(gPlayers
) do
1374 if gPlayers
[i
] <> nil then
1376 if gPlayers
[i
] is TPlayer
then
1378 gPlayers
[i
].Update();
1379 gPlayers
[i
].RealizeCurrentWeapon(); // WARNING! DO NOT MOVE THIS INTO `Update()`!
1383 // bot updates weapons in `UpdateCombat()`
1384 TBot(gPlayers
[i
]).Update();
1388 //e_WriteLog('***g_Player_UpdateAll: EXIT', MSG_WARNING);
1391 procedure g_Player_DrawAll();
1395 if gPlayers
= nil then Exit
;
1397 for i
:= 0 to High(gPlayers
) do
1398 if gPlayers
[i
] <> nil then
1399 if gPlayers
[i
] is TPlayer
then gPlayers
[i
].Draw()
1400 else TBot(gPlayers
[i
]).Draw();
1403 procedure g_Player_DrawDebug(p
: TPlayer
);
1407 if p
= nil then Exit
;
1408 if (@p
.FObj
) = nil then Exit
;
1410 e_TextureFontGetSize(gStdFont
, fW
, fH
);
1412 e_TextureFontPrint(0, 0 , 'Pos X: ' + IntToStr(p
.FObj
.X
), gStdFont
);
1413 e_TextureFontPrint(0, fH
, 'Pos Y: ' + IntToStr(p
.FObj
.Y
), gStdFont
);
1414 e_TextureFontPrint(0, fH
* 2, 'Vel X: ' + IntToStr(p
.FObj
.Vel
.X
), gStdFont
);
1415 e_TextureFontPrint(0, fH
* 3, 'Vel Y: ' + IntToStr(p
.FObj
.Vel
.Y
), gStdFont
);
1416 e_TextureFontPrint(0, fH
* 4, 'Acc X: ' + IntToStr(p
.FObj
.Accel
.X
), gStdFont
);
1417 e_TextureFontPrint(0, fH
* 5, 'Acc Y: ' + IntToStr(p
.FObj
.Accel
.Y
), gStdFont
);
1420 procedure g_Player_DrawHealth();
1425 if gPlayers
= nil then Exit
;
1426 e_TextureFontGetSize(gStdFont
, fW
, fH
);
1428 for i
:= 0 to High(gPlayers
) do
1429 if gPlayers
[i
] <> nil then
1431 e_TextureFontPrint(gPlayers
[i
].FObj
.X
+ gPlayers
[i
].FObj
.Rect
.X
,
1432 gPlayers
[i
].FObj
.Y
+ gPlayers
[i
].FObj
.Rect
.Y
+ gPlayers
[i
].FObj
.Rect
.Height
- fH
* 2,
1433 IntToStr(gPlayers
[i
].FHealth
), gStdFont
);
1434 e_TextureFontPrint(gPlayers
[i
].FObj
.X
+ gPlayers
[i
].FObj
.Rect
.X
,
1435 gPlayers
[i
].FObj
.Y
+ gPlayers
[i
].FObj
.Rect
.Y
+ gPlayers
[i
].FObj
.Rect
.Height
- fH
,
1436 IntToStr(gPlayers
[i
].FArmor
), gStdFont
);
1440 function g_Player_Get(UID
: Word): TPlayer
;
1446 if gPlayers
= nil then
1449 for a
:= 0 to High(gPlayers
) do
1450 if gPlayers
[a
] <> nil then
1451 if gPlayers
[a
].FUID
= UID
then
1453 Result
:= gPlayers
[a
];
1458 function g_Player_GetCount(): Byte;
1464 if gPlayers
= nil then
1467 for a
:= 0 to High(gPlayers
) do
1468 if gPlayers
[a
] <> nil then
1469 Result
:= Result
+ 1;
1472 function g_Player_GetStats(): TPlayerStatArray
;
1478 if gPlayers
= nil then Exit
;
1480 for a
:= 0 to High(gPlayers
) do
1481 if gPlayers
[a
] <> nil then
1483 SetLength(Result
, Length(Result
)+1);
1484 with Result
[High(Result
)] do
1487 Ping
:= gPlayers
[a
].FPing
;
1488 Loss
:= gPlayers
[a
].FLoss
;
1489 Name
:= gPlayers
[a
].FName
;
1490 Team
:= gPlayers
[a
].FTeam
;
1491 Frags
:= gPlayers
[a
].FFrags
;
1492 Deaths
:= gPlayers
[a
].FDeath
;
1493 Kills
:= gPlayers
[a
].FKills
;
1494 Color
:= gPlayers
[a
].FModel
.Color
;
1495 Lives
:= gPlayers
[a
].FLives
;
1496 Spectator
:= gPlayers
[a
].FSpectator
;
1501 procedure g_Player_ResetReady();
1505 if not g_Game_IsServer
then Exit
;
1506 if gPlayers
= nil then Exit
;
1508 for a
:= 0 to High(gPlayers
) do
1509 if gPlayers
[a
] <> nil then
1511 gPlayers
[a
].FReady
:= False;
1512 if g_Game_IsNet
then
1513 MH_SEND_GameEvent(NET_EV_INTER_READY
, gPlayers
[a
].UID
, 'N');
1517 procedure g_Player_RememberAll
;
1521 for i
:= Low(gPlayers
) to High(gPlayers
) do
1522 if (gPlayers
[i
] <> nil) and gPlayers
[i
].alive
then
1523 gPlayers
[i
].RememberState
;
1526 procedure g_Player_ResetAll(Force
, Silent
: Boolean);
1530 gTeamStat
[TEAM_RED
].Goals
:= 0;
1531 gTeamStat
[TEAM_BLUE
].Goals
:= 0;
1533 if gPlayers
<> nil then
1534 for i
:= 0 to High(gPlayers
) do
1535 if gPlayers
[i
] <> nil then
1537 gPlayers
[i
].Reset(Force
);
1539 if gPlayers
[i
] is TPlayer
then
1541 if (not gPlayers
[i
].FSpectator
) or gPlayers
[i
].FWantsInGame
then
1542 gPlayers
[i
].Respawn(Silent
)
1544 gPlayers
[i
].Spectate();
1547 TBot(gPlayers
[i
]).Respawn(Silent
);
1551 procedure g_Player_CreateCorpse(Player
: TPlayer
);
1557 if Player
.alive
then
1560 // Ðàçðûâàåì ñâÿçü ñ ïðåæíèì òðóïîì:
1561 if gCorpses
<> nil then
1562 for i
:= 0 to High(gCorpses
) do
1563 if gCorpses
[i
] <> nil then
1564 if gCorpses
[i
].FPlayerUID
= Player
.FUID
then
1565 gCorpses
[i
].FPlayerUID
:= 0;
1567 if Player
.FObj
.Y
>= gMapInfo
.Height
+128 then
1572 if (FHealth
>= -50) or (gGibsCount
= 0) then
1574 if (gCorpses
= nil) or (Length(gCorpses
) = 0) then
1578 for find_id
:= 0 to High(gCorpses
) do
1579 if gCorpses
[find_id
] = nil then
1586 find_id
:= Random(Length(gCorpses
));
1588 gCorpses
[find_id
] := TCorpse
.Create(FObj
.X
, FObj
.Y
, FModel
.Name
, FHealth
< -20);
1589 gCorpses
[find_id
].FColor
:= FModel
.Color
;
1590 gCorpses
[find_id
].FObj
.Vel
:= FObj
.Vel
;
1591 gCorpses
[find_id
].FObj
.Accel
:= FObj
.Accel
;
1592 gCorpses
[find_id
].FPlayerUID
:= FUID
;
1595 g_Player_CreateGibs(FObj
.X
+ PLAYER_RECT_CX
,
1596 FObj
.Y
+ PLAYER_RECT_CY
,
1597 FModel
.Name
, FModel
.Color
);
1601 procedure g_Player_CreateShell(fX
, fY
, dX
, dY
: Integer; T
: Byte);
1605 if (gShells
= nil) or (Length(gShells
) = 0) then
1608 with gShells
[CurrentShell
] do
1614 if T
= SHELL_BULLET
then
1616 if g_Texture_Get('TEXTURE_SHELL_BULLET', SID
) then
1620 Obj
.Rect
.Width
:= 4;
1621 Obj
.Rect
.Height
:= 2;
1625 if g_Texture_Get('TEXTURE_SHELL_SHELL', SID
) then
1629 Obj
.Rect
.Width
:= 7;
1630 Obj
.Rect
.Height
:= 3;
1636 g_Obj_Push(@Obj
, dX
+ Random(4)-Random(4), dY
-Random(4));
1637 positionChanged(); // this updates spatial accelerators
1638 RAngle
:= Random(360);
1639 Timeout
:= gTime
+ SHELL_TIMEOUT
;
1641 if CurrentShell
>= High(gShells
) then
1648 procedure g_Player_CreateGibs(fX
, fY
: Integer; ModelName
: string; fColor
: TRGB
);
1651 GibsArray
: TGibsArray
;
1654 if (gGibs
= nil) or (Length(gGibs
) = 0) then
1656 if not g_PlayerModel_GetGibs(ModelName
, GibsArray
) then
1658 Blood
:= g_PlayerModel_GetBlood(ModelName
);
1660 for a
:= 0 to High(GibsArray
) do
1661 with gGibs
[CurrentGib
] do
1664 ID
:= GibsArray
[a
].ID
;
1665 MaskID
:= GibsArray
[a
].MaskID
;
1668 Obj
.Rect
:= GibsArray
[a
].Rect
;
1669 Obj
.X
:= fX
-GibsArray
[a
].Rect
.X
-(GibsArray
[a
].Rect
.Width
div 2);
1670 Obj
.Y
:= fY
-GibsArray
[a
].Rect
.Y
-(GibsArray
[a
].Rect
.Height
div 2);
1671 g_Obj_PushA(@Obj
, 25 + Random(10), Random(361));
1672 positionChanged(); // this updates spatial accelerators
1673 RAngle
:= Random(360);
1675 if gBloodCount
> 0 then
1676 g_GFX_Blood(fX
, fY
, 16*gBloodCount
+Random(5*gBloodCount
), -16+Random(33), -16+Random(33),
1677 Random(48), Random(48), Blood
.R
, Blood
.G
, Blood
.B
, Blood
.Kind
);
1679 if CurrentGib
>= High(gGibs
) then
1686 procedure g_Player_UpdatePhysicalObjects();
1692 procedure ShellSound_Bounce(X
, Y
: Integer; T
: Byte);
1697 if T
= SHELL_BULLET
then
1698 g_Sound_PlayExAt('SOUND_PLAYER_CASING' + IntToStr(k
), X
, Y
)
1700 g_Sound_PlayExAt('SOUND_PLAYER_SHELL' + IntToStr(k
), X
, Y
);
1705 if gGibs
<> nil then
1706 for i
:= 0 to High(gGibs
) do
1707 if gGibs
[i
].alive
then
1711 mr
:= g_Obj_Move(@Obj
, True, False, True);
1712 positionChanged(); // this updates spatial accelerators
1714 if WordBool(mr
and MOVE_FALLOUT
) then
1720 // Îòëåòàåò îò óäàðà î ñòåíó/ïîòîëîê/ïîë:
1721 if WordBool(mr
and MOVE_HITWALL
) then
1722 Obj
.Vel
.X
:= -(vel
.X
div 2);
1723 if WordBool(mr
and (MOVE_HITCEIL
or MOVE_HITLAND
)) then
1724 Obj
.Vel
.Y
:= -(vel
.Y
div 2);
1726 if (Obj
.Vel
.X
>= 0) then
1728 RAngle
:= RAngle
+ Abs(Obj
.Vel
.X
)*6 + Abs(Obj
.Vel
.Y
);
1729 if RAngle
>= 360 then
1730 RAngle
:= RAngle
mod 360;
1731 end else begin // Counter-clockwise
1732 RAngle
:= RAngle
- Abs(Obj
.Vel
.X
)*6 - Abs(Obj
.Vel
.Y
);
1734 RAngle
:= (360 - (Abs(RAngle
) mod 360)) mod 360;
1737 // Ñîïðîòèâëåíèå âîçäóõà äëÿ êóñêà òðóïà:
1738 if gTime
mod (GAME_TICK
*3) = 0 then
1739 Obj
.Vel
.X
:= z_dec(Obj
.Vel
.X
, 1);
1743 if gCorpses
<> nil then
1744 for i
:= 0 to High(gCorpses
) do
1745 if gCorpses
[i
] <> nil then
1746 if gCorpses
[i
].State
= CORPSE_STATE_REMOVEME
then
1752 gCorpses
[i
].Update();
1755 if gShells
<> nil then
1756 for i
:= 0 to High(gShells
) do
1757 if gShells
[i
].alive
then
1761 mr
:= g_Obj_Move(@Obj
, True, False, True);
1762 positionChanged(); // this updates spatial accelerators
1764 if WordBool(mr
and MOVE_FALLOUT
) or (gShells
[i
].Timeout
< gTime
) then
1770 // Îòëåòàåò îò óäàðà î ñòåíó/ïîòîëîê/ïîë:
1771 if WordBool(mr
and MOVE_HITWALL
) then
1773 Obj
.Vel
.X
:= -(vel
.X
div 2);
1774 if not WordBool(mr
and MOVE_INWATER
) then
1775 ShellSound_Bounce(Obj
.X
, Obj
.Y
, SType
);
1777 if WordBool(mr
and (MOVE_HITCEIL
or MOVE_HITLAND
)) then
1779 Obj
.Vel
.Y
:= -(vel
.Y
div 2);
1780 if Obj
.Vel
.X
<> 0 then Obj
.Vel
.X
:= Obj
.Vel
.X
div 2;
1781 if (Obj
.Vel
.X
= 0) and (Obj
.Vel
.Y
= 0) then
1783 if RAngle
mod 90 <> 0 then
1784 RAngle
:= (RAngle
div 90) * 90;
1786 else if not WordBool(mr
and MOVE_INWATER
) then
1787 ShellSound_Bounce(Obj
.X
, Obj
.Y
, SType
);
1790 if (Obj
.Vel
.X
>= 0) then
1792 RAngle
:= RAngle
+ Abs(Obj
.Vel
.X
)*8 + Abs(Obj
.Vel
.Y
);
1793 if RAngle
>= 360 then
1794 RAngle
:= RAngle
mod 360;
1795 end else begin // Counter-clockwise
1796 RAngle
:= RAngle
- Abs(Obj
.Vel
.X
)*8 - Abs(Obj
.Vel
.Y
);
1798 RAngle
:= (360 - (Abs(RAngle
) mod 360)) mod 360;
1804 procedure TGib
.getMapBox (out x
, y
, w
, h
: Integer); inline;
1806 x
:= Obj
.X
+Obj
.Rect
.X
;
1807 y
:= Obj
.Y
+Obj
.Rect
.Y
;
1808 w
:= Obj
.Rect
.Width
;
1809 h
:= Obj
.Rect
.Height
;
1812 procedure TGib
.moveBy (dx
, dy
: Integer); inline;
1814 if (dx
<> 0) or (dy
<> 0) then
1823 procedure TShell
.getMapBox (out x
, y
, w
, h
: Integer); inline;
1827 w
:= Obj
.Rect
.Width
;
1828 h
:= Obj
.Rect
.Height
;
1831 procedure TShell
.moveBy (dx
, dy
: Integer); inline;
1833 if (dx
<> 0) or (dy
<> 0) then
1842 procedure TGib
.positionChanged (); inline; begin end;
1843 procedure TShell
.positionChanged (); inline; begin end;
1846 procedure g_Player_DrawCorpses();
1851 if gGibs
<> nil then
1852 for i
:= 0 to High(gGibs
) do
1853 if gGibs
[i
].alive
then
1856 if not g_Obj_Collide(sX
, sY
, sWidth
, sHeight
, @Obj
) then
1859 a
.X
:= Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2);
1860 a
.y
:= Obj
.Rect
.Y
+(Obj
.Rect
.Height
div 2);
1862 e_DrawAdv(ID
, Obj
.X
, Obj
.Y
, 0, True, False, RAngle
, @a
, TMirrorType
.None
);
1865 e_DrawAdv(MaskID
, Obj
.X
, Obj
.Y
, 0, True, False, RAngle
, @a
, TMirrorType
.None
);
1871 if gCorpses
<> nil then
1872 for i
:= 0 to High(gCorpses
) do
1873 if gCorpses
[i
] <> nil then
1877 procedure g_Player_DrawShells();
1882 if gShells
<> nil then
1883 for i
:= 0 to High(gShells
) do
1884 if gShells
[i
].alive
then
1887 if not g_Obj_Collide(sX
, sY
, sWidth
, sHeight
, @Obj
) then
1893 e_DrawAdv(SpriteID
, Obj
.X
, Obj
.Y
, 0, True, False, RAngle
, @a
, TMirrorType
.None
);
1897 procedure g_Player_RemoveAllCorpses();
1903 SetLength(gGibs
, MaxGibs
);
1904 SetLength(gShells
, MaxGibs
);
1908 if gCorpses
<> nil then
1909 for i
:= 0 to High(gCorpses
) do
1913 SetLength(gCorpses
, MaxCorpses
);
1916 procedure g_Player_Corpses_SaveState (st
: TStream
);
1920 // Ñ÷èòàåì êîëè÷åñòâî ñóùåñòâóþùèõ òðóïîâ
1922 for i
:= 0 to High(gCorpses
) do if (gCorpses
[i
] <> nil) then Inc(count
);
1924 // Êîëè÷åñòâî òðóïîâ
1925 utils
.writeInt(st
, LongInt(count
));
1927 if (count
= 0) then exit
;
1930 for i
:= 0 to High(gCorpses
) do
1932 if gCorpses
[i
] <> nil then
1935 utils
.writeStr(st
, gCorpses
[i
].FModelName
);
1937 utils
.writeBool(st
, gCorpses
[i
].Mess
);
1938 // Ñîõðàíÿåì äàííûå òðóïà:
1939 gCorpses
[i
].SaveState(st
);
1945 procedure g_Player_Corpses_LoadState (st
: TStream
);
1953 g_Player_RemoveAllCorpses();
1955 // Êîëè÷åñòâî òðóïîâ:
1956 count
:= utils
.readLongInt(st
);
1957 if (count
< 0) or (count
> Length(gCorpses
)) then raise XStreamError
.Create('invalid number of corpses');
1959 if (count
= 0) then exit
;
1962 for i
:= 0 to count
-1 do
1965 str
:= utils
.readStr(st
);
1967 b
:= utils
.readBool(st
);
1969 gCorpses
[i
] := TCorpse
.Create(0, 0, str
, b
);
1970 // Çàãðóæàåì äàííûå òðóïà
1971 gCorpses
[i
].LoadState(st
);
1978 function TPlayer
.isValidViewPort (): Boolean; inline; begin result
:= (viewPortW
> 0) and (viewPortH
> 0); end;
1980 procedure TPlayer
.BFGHit();
1982 g_Weapon_BFGHit(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
1983 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2));
1984 if g_Game_IsServer
and g_Game_IsNet
then
1985 MH_SEND_Effect(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
1986 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2),
1990 procedure TPlayer
.ChangeModel(ModelName
: string);
1992 locModel
: TPlayerModel
;
1994 locModel
:= g_PlayerModel_Get(ModelName
);
1995 if locModel
= nil then Exit
;
2001 procedure TPlayer
.SetModel(ModelName
: string);
2005 m
:= g_PlayerModel_Get(ModelName
);
2008 g_SimpleError(Format(_lc
[I_GAME_ERROR_MODEL_FALLBACK
], [ModelName
]));
2009 m
:= g_PlayerModel_Get('doomer');
2012 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], ['doomer']));
2017 if FModel
<> nil then
2022 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
2023 FModel
.Color
:= FColor
2025 FModel
.Color
:= TEAMCOLOR
[FTeam
];
2026 FModel
.SetWeapon(FCurrWeap
);
2027 FModel
.SetFlag(FFlag
);
2028 SetDirection(FDirection
);
2031 procedure TPlayer
.SetColor(Color
: TRGB
);
2034 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
2035 if FModel
<> nil then FModel
.Color
:= Color
;
2038 function TPlayer
.GetColor(): TRGB
;
2040 result
:= FModel
.Color
;
2043 procedure TPlayer
.SwitchTeam
;
2045 if g_Game_IsClient
then
2047 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then Exit
;
2049 if gGameOn
and FAlive
then
2050 Kill(K_SIMPLEKILL
, FUID
, HIT_SELF
);
2052 if FTeam
= TEAM_RED
then
2054 ChangeTeam(TEAM_BLUE
);
2055 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_BLUE
], [FName
]), True);
2056 if g_Game_IsNet
then
2057 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM
, TEAM_BLUE
, FName
);
2061 ChangeTeam(TEAM_RED
);
2062 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_RED
], [FName
]), True);
2063 if g_Game_IsNet
then
2064 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM
, TEAM_RED
, FName
);
2066 FPreferredTeam
:= FTeam
;
2069 procedure TPlayer
.ChangeTeam(Team
: Byte);
2076 TEAM_RED
, TEAM_BLUE
:
2077 FModel
.Color
:= TEAMCOLOR
[Team
];
2079 FModel
.Color
:= FColor
;
2081 if (FTeam
<> OldTeam
) and g_Game_IsNet
and g_Game_IsServer
then
2082 MH_SEND_PlayerStats(FUID
);
2086 procedure TPlayer.CollideItem();
2091 if gItems = nil then Exit;
2092 if not FAlive then Exit;
2094 for i := 0 to High(gItems) do
2097 if (ItemType <> ITEM_NONE) and alive then
2098 if g_Obj_Collide(FObj.X+PLAYER_RECT.X, FObj.Y+PLAYER_RECT.Y, PLAYER_RECT.Width,
2099 PLAYER_RECT.Height, @Obj) then
2101 if not PickItem(ItemType, gItems[i].Respawnable, r) then Continue;
2103 if ItemType in [ITEM_SPHERE_BLUE, ITEM_SPHERE_WHITE, ITEM_INVUL] then
2104 g_Sound_PlayExAt('SOUND_ITEM_GETRULEZ', FObj.X, FObj.Y)
2105 else if ItemType in [ITEM_MEDKIT_SMALL, ITEM_MEDKIT_LARGE, ITEM_MEDKIT_BLACK] then
2106 g_Sound_PlayExAt('SOUND_ITEM_GETMED', FObj.X, FObj.Y)
2107 else g_Sound_PlayExAt('SOUND_ITEM_GETITEM', FObj.X, FObj.Y);
2109 // Íàäî óáðàòü ñ êàðòû, åñëè ýòî íå êëþ÷, êîòîðûì íóæíî ïîäåëèòñÿ ñ äðóãèì èãðîêîì:
2110 if r and not ((ItemType in [ITEM_KEY_RED, ITEM_KEY_GREEN, ITEM_KEY_BLUE]) and
2111 (gGameSettings.GameType = GT_SINGLE) and
2112 (g_Player_GetCount() > 1)) then
2113 if not Respawnable then g_Items_Remove(i) else g_Items_Pick(i);
2119 function TPlayer
.CollideLevel(XInc
, YInc
: Integer): Boolean;
2121 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
2122 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_WALL
,
2126 constructor TPlayer
.Create();
2132 mEDamageType
:= HIT_SOME
;
2138 FSawSound
:= TPlayableSound
.Create();
2139 FSawSoundIdle
:= TPlayableSound
.Create();
2140 FSawSoundHit
:= TPlayableSound
.Create();
2141 FSawSoundSelect
:= TPlayableSound
.Create();
2142 FFlameSoundOn
:= TPlayableSound
.Create();
2143 FFlameSoundOff
:= TPlayableSound
.Create();
2144 FFlameSoundWork
:= TPlayableSound
.Create();
2145 FJetSoundFly
:= TPlayableSound
.Create();
2146 FJetSoundOn
:= TPlayableSound
.Create();
2147 FJetSoundOff
:= TPlayableSound
.Create();
2149 FSawSound
.SetByName('SOUND_WEAPON_FIRESAW');
2150 FSawSoundIdle
.SetByName('SOUND_WEAPON_IDLESAW');
2151 FSawSoundHit
.SetByName('SOUND_WEAPON_HITSAW');
2152 FSawSoundSelect
.SetByName('SOUND_WEAPON_SELECTSAW');
2153 FFlameSoundOn
.SetByName('SOUND_WEAPON_FLAMEON');
2154 FFlameSoundOff
.SetByName('SOUND_WEAPON_FLAMEOFF');
2155 FFlameSoundWork
.SetByName('SOUND_WEAPON_FLAMEWORK');
2156 FJetSoundFly
.SetByName('SOUND_PLAYER_JETFLY');
2157 FJetSoundOn
.SetByName('SOUND_PLAYER_JETON');
2158 FJetSoundOff
.SetByName('SOUND_PLAYER_JETOFF');
2160 FSpectatePlayer
:= -1;
2164 FSavedState
.WaitRecall
:= False;
2171 FActualModelName
:= 'doomer';
2174 FObj
.Rect
:= PLAYER_RECT
;
2176 FBFGFireCounter
:= -1;
2177 FJustTeleported
:= False;
2183 procedure TPlayer
.positionChanged (); inline;
2187 procedure TPlayer
.doDamage (v
: Integer);
2189 if (v
<= 0) then exit
;
2190 if (v
> 32767) then v
:= 32767;
2191 Damage(v
, 0, 0, 0, mEDamageType
);
2194 procedure TPlayer
.Damage(value
: Word; SpawnerUID
: Word; vx
, vy
: Integer; t
: Byte);
2198 if (not g_Game_IsClient
) and (not FAlive
) then
2203 // Íåóÿçâèìîñòü íå ñïàñàåò îò ëîâóøåê:
2204 if ((t
= HIT_TRAP
) or (t
= HIT_SELF
)) and (not FGodMode
) then
2206 if not g_Game_IsClient
then
2209 if t
= HIT_TRAP
then
2211 // Ëîâóøêà óáèâàåò ñðàçó:
2213 Kill(K_EXTRAHARDKILL
, SpawnerUID
, t
);
2215 if t
= HIT_SELF
then
2219 Kill(K_SIMPLEKILL
, SpawnerUID
, t
);
2222 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
2223 FMegaRulez
[MR_SUIT
] := 0;
2224 FMegaRulez
[MR_INVUL
] := 0;
2225 FMegaRulez
[MR_INVIS
] := 0;
2229 // Íî îò îñòàëüíîãî ñïàñàåò:
2230 if FMegaRulez
[MR_INVUL
] >= gTime
then
2237 // Åñëè åñòü óðîí ñâîèì, èëè ðàíèë ñàì ñåáÿ, èëè òåáÿ ðàíèë ïðîòèâíèê:
2238 if LongBool(gGameSettings
.Options
and GAME_OPTION_TEAMDAMAGE
) or
2239 (SpawnerUID
= FUID
) or
2240 (not SameTeam(FUID
, SpawnerUID
)) then
2242 FLastSpawnerUID
:= SpawnerUID
;
2244 // Êðîâü (ïóçûðüêè, åñëè â âîäå):
2245 if gBloodCount
> 0 then
2247 c
:= Min(value
, 200)*gBloodCount
+ Random(Min(value
, 200) div 2);
2248 if value
div 4 <= c
then
2249 c
:= c
- (value
div 4)
2253 if (t
= HIT_SOME
) and (vx
= 0) and (vy
= 0) then
2257 HIT_TRAP
, HIT_ACID
, HIT_FLAME
, HIT_SELF
: MakeBloodSimple(c
);
2258 HIT_BFG
, HIT_ROCKET
, HIT_SOME
: MakeBloodVector(c
, vx
, vy
);
2261 if t
= HIT_WATER
then
2262 g_GFX_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
2263 FObj
.Y
+PLAYER_RECT
.Y
-4, value
div 2, 8, 4);
2268 Inc(FDamageBuffer
, value
);
2272 FPain
:= FPain
+ value
;
2275 if g_Game_IsServer
and g_Game_IsNet
then
2277 MH_SEND_PlayerDamage(FUID
, t
, SpawnerUID
, value
, vx
, vy
);
2278 MH_SEND_PlayerStats(FUID
);
2279 MH_SEND_PlayerPos(False, FUID
);
2283 function TPlayer
.Heal(value
: Word; Soft
: Boolean): Boolean;
2286 if g_Game_IsClient
then
2291 if Soft
and (FHealth
< PLAYER_HP_SOFT
) then
2293 IncMax(FHealth
, value
, PLAYER_HP_SOFT
);
2296 if (not Soft
) and (FHealth
< PLAYER_HP_LIMIT
) then
2298 IncMax(FHealth
, value
, PLAYER_HP_LIMIT
);
2302 if Result
and g_Game_IsServer
and g_Game_IsNet
then
2303 MH_SEND_PlayerStats(FUID
);
2306 destructor TPlayer
.Destroy();
2308 if (gPlayer1
<> nil) and (gPlayer1
.FUID
= FUID
) then
2310 if (gPlayer2
<> nil) and (gPlayer2
.FUID
= FUID
) then
2314 FSawSoundIdle
.Free();
2315 FSawSoundHit
.Free();
2316 FSawSoundSelect
.Free();
2317 FFlameSoundOn
.Free();
2318 FFlameSoundOff
.Free();
2319 FFlameSoundWork
.Free();
2320 FJetSoundFly
.Free();
2322 FJetSoundOff
.Free();
2324 if FPunchAnim
<> nil then
2330 procedure TPlayer
.DrawIndicator(Color
: TRGB
);
2332 indX
, indY
: Integer;
2339 if g_Texture_Get('TEXTURE_PLAYER_INDICATOR', ID
) then
2341 e_GetTextureSize(ID
, @indW
, @indH
);
2342 indX
:= FObj
.X
+ FObj
.Rect
.X
+ (FObj
.Rect
.Width
- indW
) div 2;
2347 e_Draw(ID
, indX
, indY
- indH
, 0, True, False);
2351 //e_TextureFontPrintEx(indX, indY, FName, gStdFont, 0, 0, 255, 1.0, true); // Shows player name overhead
2354 procedure TPlayer
.DrawBubble();
2356 bubX
, bubY
: Integer;
2359 Rw
, Gw
, Bw
: SmallInt;
2362 bubX
:= FObj
.X
+FObj
.Rect
.X
+ IfThen(FDirection
= TDirection
.D_LEFT
, -4, 18);
2363 bubY
:= FObj
.Y
+FObj
.Rect
.Y
- 18;
2371 1: // simple textual non-bubble
2373 bubX
:= FObj
.X
+FObj
.Rect
.X
- 11;
2374 bubY
:= FObj
.Y
+FObj
.Rect
.Y
- 17;
2375 e_TextureFontPrint(bubX
, bubY
, '[...]', gStdFont
);
2378 2: // advanced pixel-perfect bubble
2380 if FTeam
= TEAM_RED
then
2383 if FTeam
= TEAM_BLUE
then
2386 3: // colored bubble
2388 Rb
:= FModel
.Color
.R
;
2389 Gb
:= FModel
.Color
.G
;
2390 Bb
:= FModel
.Color
.B
;
2391 Rw
:= Min(Rb
* 2 + 64, 255);
2392 Gw
:= Min(Gb
* 2 + 64, 255);
2393 Bw
:= Min(Bb
* 2 + 64, 255);
2394 if (Abs(Rw
- Rb
) < 32)
2395 or (Abs(Gw
- Gb
) < 32)
2396 or (Abs(Bw
- Bb
) < 32) then
2398 Rb
:= Max(Rw
div 2 - 16, 0);
2399 Gb
:= Max(Gw
div 2 - 16, 0);
2400 Bb
:= Max(Bw
div 2 - 16, 0);
2403 4: // custom textured bubble
2405 if g_Texture_Get('TEXTURE_PLAYER_TALKBUBBLE', ID
) then
2406 if FDirection
= TDirection
.D_RIGHT
then
2407 e_Draw(ID
, bubX
- 6, bubY
- 7, 0, True, False)
2409 e_Draw(ID
, bubX
- 6, bubY
- 7, 0, True, False, TMirrorType
.Horizontal
);
2415 e_DrawQuad(bubX
+ 1, bubY
, bubX
+ 18, bubY
+ 13, Rb
, Gb
, Bb
);
2416 e_DrawQuad(bubX
, bubY
+ 1, bubX
+ 19, bubY
+ 12, Rb
, Gb
, Bb
);
2418 e_DrawFillQuad(bubX
+ 1, bubY
+ 1, bubX
+ 18, bubY
+ 12, Rw
, Gw
, Bw
, 0);
2421 Dot
:= IfThen(FDirection
= TDirection
.D_LEFT
, 14, 5);
2422 e_DrawLine(1, bubX
+ Dot
, bubY
+ 14, bubX
+ Dot
, bubY
+ 16, Rb
, Gb
, Bb
);
2423 e_DrawLine(1, bubX
+ IfThen(FDirection
= TDirection
.D_LEFT
, Dot
- 1, Dot
+ 1), bubY
+ 13, bubX
+ IfThen(FDirection
= TDirection
.D_LEFT
, Dot
- 1, Dot
+ 1), bubY
+ 15, Rw
, Gw
, Bw
);
2424 e_DrawLine(1, bubX
+ IfThen(FDirection
= TDirection
.D_LEFT
, Dot
- 2, Dot
+ 2), bubY
+ 13, bubX
+ IfThen(FDirection
= TDirection
.D_LEFT
, Dot
- 2, Dot
+ 2), bubY
+ 14, Rw
, Gw
, Bw
);
2425 e_DrawLine(1, bubX
+ IfThen(FDirection
= TDirection
.D_LEFT
, Dot
- 3, Dot
+ 3), bubY
+ 13, bubX
+ IfThen(FDirection
= TDirection
.D_LEFT
, Dot
- 3, Dot
+ 3), bubY
+ 13, Rw
, Gw
, Bw
);
2426 e_DrawLine(1, bubX
+ IfThen(FDirection
= TDirection
.D_LEFT
, Dot
- 3, Dot
+ 3), bubY
+ 14, bubX
+ IfThen(FDirection
= TDirection
.D_LEFT
, Dot
- 1, Dot
+ 1), bubY
+ 16, Rb
, Gb
, Bb
);
2430 e_DrawFillQuad(bubX
+ Dot
, bubY
+ 8, bubX
+ Dot
+ 1, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2431 e_DrawFillQuad(bubX
+ Dot
+ 3, bubY
+ 8, bubX
+ Dot
+ 4, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2432 e_DrawFillQuad(bubX
+ Dot
+ 6, bubY
+ 8, bubX
+ Dot
+ 7, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2435 procedure TPlayer
.Draw();
2440 Mirror
: TMirrorType
;
2444 if Direction
= TDirection
.D_RIGHT
then
2445 Mirror
:= TMirrorType
.None
2447 Mirror
:= TMirrorType
.Horizontal
;
2449 if FPunchAnim
<> nil then
2451 FPunchAnim
.Draw(FObj
.X
+IfThen(Direction
= TDirection
.D_LEFT
, 15-FObj
.Rect
.X
, FObj
.Rect
.X
-15),
2452 FObj
.Y
+FObj
.Rect
.Y
-11, Mirror
);
2453 if FPunchAnim
.played
then
2460 if (FMegaRulez
[MR_INVUL
] > gTime
) and (gPlayerDrawn
<> Self
) then
2461 if g_Texture_Get('TEXTURE_PLAYER_INVULPENTA', ID
) then
2463 e_GetTextureSize(ID
, @w
, @h
);
2464 if FDirection
= TDirection
.D_LEFT
then
2465 e_Draw(ID
, FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2)-(w
div 2)+4,
2466 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2)-(h
div 2)-7+FObj
.slopeUpLeft
, 0, True, False)
2468 e_Draw(ID
, FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2)-(w
div 2)-2,
2469 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2)-(h
div 2)-7+FObj
.slopeUpLeft
, 0, True, False);
2472 if FMegaRulez
[MR_INVIS
] > gTime
then
2474 if (gPlayerDrawn
<> nil) and ((Self
= gPlayerDrawn
) or
2475 ((FTeam
= gPlayerDrawn
.Team
) and (gGameSettings
.GameMode
<> GM_DM
))) then
2477 if (FMegaRulez
[MR_INVIS
] - gTime
) <= 2100 then
2478 dr
:= not Odd((FMegaRulez
[MR_INVIS
] - gTime
) div 300)
2482 FModel
.Draw(FObj
.X
, FObj
.Y
+FObj
.slopeUpLeft
, 200)
2484 FModel
.Draw(FObj
.X
, FObj
.Y
+FObj
.slopeUpLeft
);
2487 FModel
.Draw(FObj
.X
, FObj
.Y
+FObj
.slopeUpLeft
, 254);
2490 FModel
.Draw(FObj
.X
, FObj
.Y
+FObj
.slopeUpLeft
);
2493 if g_debug_Frames
then
2495 e_DrawQuad(FObj
.X
+FObj
.Rect
.X
,
2497 FObj
.X
+FObj
.Rect
.X
+FObj
.Rect
.Width
-1,
2498 FObj
.Y
+FObj
.Rect
.Y
+FObj
.Rect
.Height
-1,
2502 if (gChatBubble
> 0) and (FKeys
[KEY_CHAT
].Pressed
) and not FGhost
then
2503 if (FMegaRulez
[MR_INVIS
] <= gTime
) or ((gPlayerDrawn
<> nil) and ((Self
= gPlayerDrawn
) or
2504 ((FTeam
= gPlayerDrawn
.Team
) and (gGameSettings
.GameMode
<> GM_DM
)))) then
2506 // e_DrawPoint(5, 335, 288, 255, 0, 0); // DL, UR, DL, UR
2507 if gAimLine
and alive
and
2508 ((Self
= gPlayer1
) or (Self
= gPlayer2
)) then
2513 procedure TPlayer
.DrawAim();
2514 procedure drawCast (sz
: Integer; ax0
, ay0
, ax1
, ay1
: Integer);
2519 {$IFDEF ENABLE_HOLMES}
2520 if isValidViewPort
and (self
= gPlayer1
) then
2522 g_Holmes_plrLaser(ax0
, ay0
, ax1
, ay1
);
2526 e_DrawLine(sz
, ax0
, ay0
, ax1
, ay1
, 255, 0, 0, 96);
2527 if (g_Map_traceToNearestWall(ax0
, ay0
, ax1
, ay1
, @ex
, @ey
) <> nil) then
2529 e_DrawLine(sz
, ax0
, ay0
, ex
, ey
, 0, 255, 0, 96);
2533 e_DrawLine(sz
, ax0
, ay0
, ex
, ey
, 0, 0, 255, 96);
2538 wx
, wy
, xx
, yy
: Integer;
2542 wx
:= FObj
.X
+ WEAPONPOINT
[FDirection
].X
+ IfThen(FDirection
= TDirection
.D_LEFT
, 7, -7);
2543 wy
:= FObj
.Y
+ WEAPONPOINT
[FDirection
].Y
;
2552 1: begin // Chainsaw
2559 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2560 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2561 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2562 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2567 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2568 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2569 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2570 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2572 4: begin // Double Shotgun
2575 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2576 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2577 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2578 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2580 5: begin // Chaingun
2583 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2584 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2585 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2586 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2588 6: begin // Rocket Launcher
2591 if angle
= ANGLE_RIGHTUP
then Inc(angle
, 2);
2592 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2593 if angle
= ANGLE_LEFTUP
then Dec(angle
, 2);
2594 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2596 7: begin // Plasmagun
2599 if angle
= ANGLE_RIGHTUP
then Inc(angle
);
2600 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 3);
2601 if angle
= ANGLE_LEFTUP
then Dec(angle
);
2602 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 3);
2607 if angle
= ANGLE_RIGHTUP
then Inc(angle
, 1);
2608 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 2);
2609 if angle
= ANGLE_LEFTUP
then Dec(angle
, 1);
2610 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 2);
2612 9: begin // Super Chaingun
2615 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2616 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2617 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2618 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2621 xx
:= Trunc(Cos(-DegToRad(angle
)) * len
) + wx
;
2622 yy
:= Trunc(Sin(-DegToRad(angle
)) * len
) + wy
;
2623 {$IF DEFINED(D2F_DEBUG)}
2624 drawCast(sz
, wx
, wy
, xx
, yy
);
2626 e_DrawLine(sz
, wx
, wy
, xx
, yy
, 255, 0, 0, 96);
2630 procedure TPlayer
.DrawGUI();
2633 X
, Y
, SY
, a
, p
, m
: Integer;
2637 stat
: TPlayerStatArray
;
2639 X
:= gPlayerScreenSize
.X
;
2640 SY
:= gPlayerScreenSize
.Y
;
2643 if gShowGoals
and (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
2645 if gGameSettings
.GameMode
= GM_CTF
then
2649 if gGameSettings
.GameMode
= GM_CTF
then
2651 s
:= 'TEXTURE_PLAYER_REDFLAG';
2652 if gFlags
[FLAG_RED
].State
= FLAG_STATE_CAPTURED
then
2653 s
:= 'TEXTURE_PLAYER_REDFLAG_S';
2654 if gFlags
[FLAG_RED
].State
= FLAG_STATE_DROPPED
then
2655 s
:= 'TEXTURE_PLAYER_REDFLAG_D';
2656 if g_Texture_Get(s
, ID
) then
2657 e_Draw(ID
, X
-16-32, 240-72-4, 0, True, False);
2660 s
:= IntToStr(gTeamStat
[TEAM_RED
].Goals
);
2661 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2662 e_CharFont_PrintEx(gMenuFont
, X
-16-a
-tw
, 240-72-4, s
, TEAMCOLOR
[TEAM_RED
]);
2664 if gGameSettings
.GameMode
= GM_CTF
then
2666 s
:= 'TEXTURE_PLAYER_BLUEFLAG';
2667 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_CAPTURED
then
2668 s
:= 'TEXTURE_PLAYER_BLUEFLAG_S';
2669 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_DROPPED
then
2670 s
:= 'TEXTURE_PLAYER_BLUEFLAG_D';
2671 if g_Texture_Get(s
, ID
) then
2672 e_Draw(ID
, X
-16-32, 240-32-4, 0, True, False);
2675 s
:= IntToStr(gTeamStat
[TEAM_BLUE
].Goals
);
2676 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2677 e_CharFont_PrintEx(gMenuFont
, X
-16-a
-tw
, 240-32-4, s
, TEAMCOLOR
[TEAM_BLUE
]);
2680 if g_Texture_Get('TEXTURE_PLAYER_HUDBG', ID
) then
2681 e_DrawFill(ID
, X
, 0, 1, (gPlayerScreenSize
.Y
div 256)+IfThen(gPlayerScreenSize
.Y
mod 256 > 0, 1, 0),
2684 if g_Texture_Get('TEXTURE_PLAYER_HUD', ID
) then
2685 e_Draw(ID
, X
+2, Y
, 0, True, False);
2687 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
2691 s
:= IntToStr(Frags
);
2692 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2693 e_CharFont_PrintEx(gMenuFont
, X
-16-tw
, Y
, s
, _RGB(255, 0, 0));
2698 stat
:= g_Player_GetStats();
2703 for a
:= 0 to High(stat
) do
2704 if stat
[a
].Name
<> Name
then
2706 if stat
[a
].Frags
> m
then m
:= stat
[a
].Frags
;
2707 if stat
[a
].Frags
> Frags
then p
:= p
+1;
2711 s
:= IntToStr(p
)+' / '+IntToStr(Length(stat
))+' ';
2712 if Frags
>= m
then s
:= s
+'+' else s
:= s
+'-';
2713 s
:= s
+IntToStr(Abs(Frags
-m
));
2715 e_CharFont_GetSize(gMenuSmallFont
, s
, tw
, th
);
2716 e_CharFont_PrintEx(gMenuSmallFont
, X
-16-tw
, Y
+32, s
, _RGB(255, 0, 0));
2719 if gShowLives
and (gGameSettings
.MaxLives
> 0) then
2721 s
:= IntToStr(Lives
);
2722 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2723 e_CharFont_PrintEx(gMenuFont
, X
-16-tw
, SY
-32, s
, _RGB(0, 255, 0));
2727 e_CharFont_GetSize(gMenuSmallFont
, FName
, tw
, th
);
2728 e_CharFont_PrintEx(gMenuSmallFont
, X
+98-(tw
div 2), Y
+8, FName
, _RGB(255, 0, 0));
2730 if R_BERSERK
in FRulez
then
2731 e_Draw(gItemsTexturesID
[ITEM_MEDKIT_BLACK
], X
+37, Y
+45, 0, True, False)
2733 e_Draw(gItemsTexturesID
[ITEM_MEDKIT_LARGE
], X
+37, Y
+45, 0, True, False);
2735 if g_Texture_Get('TEXTURE_PLAYER_ARMORHUD', ID
) then
2736 e_Draw(ID
, X
+36, Y
+77, 0, True, False);
2738 s
:= IntToStr(IfThen(FHealth
> 0, FHealth
, 0));
2739 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2740 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+40, s
, _RGB(255, 0, 0));
2742 s
:= IntToStr(FArmor
);
2743 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2744 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+68, s
, _RGB(255, 0, 0));
2746 s
:= IntToStr(GetAmmoByWeapon(FCurrWeap
));
2752 ID
:= gItemsTexturesID
[ITEM_WEAPON_KASTET
];
2757 ID
:= gItemsTexturesID
[ITEM_WEAPON_SAW
];
2759 WEAPON_PISTOL
: ID
:= gItemsTexturesID
[ITEM_WEAPON_PISTOL
];
2760 WEAPON_CHAINGUN
: ID
:= gItemsTexturesID
[ITEM_WEAPON_CHAINGUN
];
2761 WEAPON_SHOTGUN1
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SHOTGUN1
];
2762 WEAPON_SHOTGUN2
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SHOTGUN2
];
2763 WEAPON_SUPERPULEMET
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SUPERPULEMET
];
2764 WEAPON_ROCKETLAUNCHER
: ID
:= gItemsTexturesID
[ITEM_WEAPON_ROCKETLAUNCHER
];
2765 WEAPON_PLASMA
: ID
:= gItemsTexturesID
[ITEM_WEAPON_PLASMA
];
2766 WEAPON_BFG
: ID
:= gItemsTexturesID
[ITEM_WEAPON_BFG
];
2767 WEAPON_FLAMETHROWER
: ID
:= gItemsTexturesID
[ITEM_WEAPON_FLAMETHROWER
];
2770 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2771 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+158, s
, _RGB(255, 0, 0));
2772 e_Draw(ID
, X
+20, Y
+160, 0, True, False);
2774 if R_KEY_RED
in FRulez
then
2775 e_Draw(gItemsTexturesID
[ITEM_KEY_RED
], X
+78, Y
+214, 0, True, False);
2777 if R_KEY_GREEN
in FRulez
then
2778 e_Draw(gItemsTexturesID
[ITEM_KEY_GREEN
], X
+95, Y
+214, 0, True, False);
2780 if R_KEY_BLUE
in FRulez
then
2781 e_Draw(gItemsTexturesID
[ITEM_KEY_BLUE
], X
+112, Y
+214, 0, True, False);
2783 if FJetFuel
> 0 then
2785 if g_Texture_Get('TEXTURE_PLAYER_HUDAIR', ID
) then
2786 e_Draw(ID
, X
+2, Y
+116, 0, True, False);
2787 if g_Texture_Get('TEXTURE_PLAYER_HUDJET', ID
) then
2788 e_Draw(ID
, X
+2, Y
+126, 0, True, False);
2789 e_DrawLine(4, X
+16, Y
+122, X
+16+Trunc(168*IfThen(FAir
> 0, FAir
, 0)/AIR_MAX
), Y
+122, 0, 0, 196);
2790 e_DrawLine(4, X
+16, Y
+132, X
+16+Trunc(168*FJetFuel
/JET_MAX
), Y
+132, 208, 0, 0);
2794 if g_Texture_Get('TEXTURE_PLAYER_HUDAIR', ID
) then
2795 e_Draw(ID
, X
+2, Y
+124, 0, True, False);
2796 e_DrawLine(4, X
+16, Y
+130, X
+16+Trunc(168*IfThen(FAir
> 0, FAir
, 0)/AIR_MAX
), Y
+130, 0, 0, 196);
2799 if gShowPing
and g_Game_IsClient
then
2801 s
:= _lc
[I_GAME_PING_HUD
] + IntToStr(NetPeer
.lastRoundTripTime
) + _lc
[I_NET_SLIST_PING_MS
];
2802 e_TextureFontPrint(X
+ 4, Y
+ 242, s
, gStdFont
);
2808 e_TextureFontPrint(X
+ 4, Y
+ 242, _lc
[I_PLAYER_SPECT
], gStdFont
);
2809 e_TextureFontPrint(X
+ 4, Y
+ 258, _lc
[I_PLAYER_SPECT2
], gStdFont
);
2810 e_TextureFontPrint(X
+ 4, Y
+ 274, _lc
[I_PLAYER_SPECT1
], gStdFont
);
2813 e_TextureFontGetSize(gStdFont
, cw
, ch
);
2814 s
:= _lc
[I_PLAYER_SPECT4
];
2815 e_TextureFontPrintEx(gScreenWidth
div 2 - cw
*(Length(s
) div 2),
2816 gScreenHeight
-4-ch
, s
, gStdFont
, 255, 255, 255, 1, True);
2817 e_TextureFontPrint(X
+ 4, Y
+ 290, _lc
[I_PLAYER_SPECT1S
], gStdFont
);
2823 procedure TPlayer
.DrawRulez();
2827 // Ïðè âçÿòèè íåóÿçâèìîñòè ðèñóåòñÿ èíâåðñèîííûé áåëûé ôîí
2828 if FMegaRulez
[MR_INVUL
] >= gTime
then
2830 if (FMegaRulez
[MR_INVUL
]-gTime
) <= 2100 then
2831 dr
:= not Odd((FMegaRulez
[MR_INVUL
]-gTime
) div 300)
2836 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2837 191, 191, 191, 0, TBlending
.Invert
);
2840 // Ïðè âçÿòèè çàùèòíîãî êîñòþìà ðèñóåòñÿ çåëåíîâàòûé ôîí
2841 if FMegaRulez
[MR_SUIT
] >= gTime
then
2843 if (FMegaRulez
[MR_SUIT
]-gTime
) <= 2100 then
2844 dr
:= not Odd((FMegaRulez
[MR_SUIT
]-gTime
) div 300)
2849 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2850 0, 96, 0, 200, TBlending
.None
);
2853 // Ïðè âçÿòèè áåðñåðêà ðèñóåòñÿ êðàñíîâàòûé ôîí
2854 if (FBerserk
>= 0) and (LongWord(FBerserk
) >= gTime
) and (gFlash
= 2) then
2856 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2857 255, 0, 0, 200, TBlending
.None
);
2861 procedure TPlayer
.DrawPain();
2865 if FPain
= 0 then Exit
;
2869 if a
< 15 then h
:= 0
2870 else if a
< 35 then h
:= 1
2871 else if a
< 55 then h
:= 2
2872 else if a
< 75 then h
:= 3
2873 else if a
< 95 then h
:= 4
2876 //if a > 255 then a := 255;
2878 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1, 255, 0, 0, 255-h
*50);
2879 //e_DrawFillQuad(0, 0, gPlayerScreenSize.X-1, gPlayerScreenSize.Y-1, 255-min(128, a), 255-a, 255-a, 0, B_FILTER);
2882 procedure TPlayer
.DrawPickup();
2886 if FPickup
= 0 then Exit
;
2890 if a
< 15 then h
:= 1
2891 else if a
< 35 then h
:= 2
2892 else if a
< 55 then h
:= 3
2893 else if a
< 75 then h
:= 4
2896 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1, 150, 200, 150, 255-h
*50);
2899 procedure TPlayer
.DoPunch();
2904 if FPunchAnim
<> nil then begin
2909 st
:= 'FRAMES_PUNCH';
2910 if R_BERSERK
in FRulez
then
2911 st
:= st
+ '_BERSERK';
2912 if FKeys
[KEY_UP
].Pressed
then
2914 else if FKeys
[KEY_DOWN
].Pressed
then
2916 g_Frames_Get(id
, st
);
2917 FPunchAnim
:= TAnimation
.Create(id
, False, 1);
2920 procedure TPlayer
.Fire();
2922 f
, DidFire
: Boolean;
2923 wx
, wy
, xd
, yd
: Integer;
2926 if g_Game_IsClient
then Exit
;
2927 // FBFGFireCounter - âðåìÿ ïåðåä âûñòðåëîì (äëÿ BFG)
2928 // FReloading - âðåìÿ ïîñëå âûñòðåëà (äëÿ âñåãî)
2936 if FReloading
[FCurrWeap
] <> 0 then Exit
;
2941 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
2942 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
2943 xd
:= wx
+IfThen(FDirection
= TDirection
.D_LEFT
, -30, 30);
2944 yd
:= wy
+firediry();
2950 if R_BERSERK
in FRulez
then
2952 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
2953 locobj
.X
:= FObj
.X
+FObj
.Rect
.X
;
2954 locobj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
2957 locobj
.rect
.Width
:= 39;
2958 locobj
.rect
.Height
:= 52;
2959 locobj
.Vel
.X
:= (xd
-wx
) div 2;
2960 locobj
.Vel
.Y
:= (yd
-wy
) div 2;
2961 locobj
.Accel
.X
:= xd
-wx
;
2962 locobj
.Accel
.y
:= yd
-wy
;
2964 if g_Weapon_Hit(@locobj
, 50, FUID
, HIT_SOME
) <> 0 then
2965 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
2967 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
2969 if (gFlash
= 1) and (FPain
< 50) then FPain
:= min(FPain
+ 25, 50);
2973 g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
2977 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2982 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
2983 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
2985 FSawSoundSelect
.Stop();
2987 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
2989 else if not FSawSoundHit
.IsPlaying() then
2991 FSawSoundSelect
.Stop();
2992 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
2995 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3001 if FAmmo
[A_BULLETS
] > 0 then
3003 g_Weapon_pistol(wx
, wy
, xd
, yd
, FUID
);
3004 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3005 Dec(FAmmo
[A_BULLETS
]);
3006 FFireAngle
:= FAngle
;
3009 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
3010 GameVelX
, GameVelY
-2, SHELL_BULLET
);
3014 if FAmmo
[A_SHELLS
] > 0 then
3016 g_Weapon_shotgun(wx
, wy
, xd
, yd
, FUID
);
3017 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', wx
, wy
);
3018 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3019 Dec(FAmmo
[A_SHELLS
]);
3020 FFireAngle
:= FAngle
;
3024 FShellType
:= SHELL_SHELL
;
3028 if FAmmo
[A_SHELLS
] >= 2 then
3030 g_Weapon_dshotgun(wx
, wy
, xd
, yd
, FUID
);
3031 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3032 Dec(FAmmo
[A_SHELLS
], 2);
3033 FFireAngle
:= FAngle
;
3037 FShellType
:= SHELL_DBLSHELL
;
3041 if FAmmo
[A_BULLETS
] > 0 then
3043 g_Weapon_mgun(wx
, wy
, xd
, yd
, FUID
);
3044 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', wx
, wy
);
3045 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3046 Dec(FAmmo
[A_BULLETS
]);
3047 FFireAngle
:= FAngle
;
3050 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
3051 GameVelX
, GameVelY
-2, SHELL_BULLET
);
3054 WEAPON_ROCKETLAUNCHER
:
3055 if FAmmo
[A_ROCKETS
] > 0 then
3057 g_Weapon_rocket(wx
, wy
, xd
, yd
, FUID
);
3058 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3059 Dec(FAmmo
[A_ROCKETS
]);
3060 FFireAngle
:= FAngle
;
3066 if FAmmo
[A_CELLS
] > 0 then
3068 g_Weapon_plasma(wx
, wy
, xd
, yd
, FUID
);
3069 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3070 Dec(FAmmo
[A_CELLS
]);
3071 FFireAngle
:= FAngle
;
3077 if (FAmmo
[A_CELLS
] >= 40) and (FBFGFireCounter
= -1) then
3079 FBFGFireCounter
:= 17;
3080 if not FNoReload
then
3081 g_Sound_PlayExAt('SOUND_WEAPON_STARTFIREBFG', FObj
.X
, FObj
.Y
);
3082 Dec(FAmmo
[A_CELLS
], 40);
3086 WEAPON_SUPERPULEMET
:
3087 if FAmmo
[A_SHELLS
] > 0 then
3089 g_Weapon_shotgun(wx
, wy
, xd
, yd
, FUID
);
3090 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', wx
, wy
);
3091 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3092 Dec(FAmmo
[A_SHELLS
]);
3093 FFireAngle
:= FAngle
;
3096 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
3097 GameVelX
, GameVelY
-2, SHELL_SHELL
);
3100 WEAPON_FLAMETHROWER
:
3101 if FAmmo
[A_FUEL
] > 0 then
3103 g_Weapon_flame(wx
, wy
, xd
, yd
, FUID
);
3105 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3107 FFireAngle
:= FAngle
;
3114 if g_Game_IsNet
and g_Game_IsServer
then MH_SEND_PlayerStats(FUID
);
3118 if g_Game_IsNet
then
3122 if FCurrWeap
<> WEAPON_BFG
then
3123 MH_SEND_PlayerFire(FUID
, FCurrWeap
, wx
, wy
, xd
, yd
, LastShotID
)
3125 if not FNoReload
then
3126 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_WEAPON_STARTFIREBFG');
3129 MH_SEND_PlayerStats(FUID
);
3134 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
3135 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
3136 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
3139 function TPlayer
.GetAmmoByWeapon(Weapon
: Byte): Word;
3142 WEAPON_PISTOL
, WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
];
3143 WEAPON_SHOTGUN1
, WEAPON_SHOTGUN2
, WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
];
3144 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
];
3145 WEAPON_PLASMA
, WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
];
3146 WEAPON_FLAMETHROWER
: Result
:= FAmmo
[A_FUEL
];
3151 function TPlayer
.HeadInLiquid(XInc
, YInc
: Integer): Boolean;
3153 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
+XInc
, FObj
.Y
+PLAYER_HEADRECT
.Y
+YInc
,
3154 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
3155 PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, True);
3158 procedure TPlayer
.FlamerOn
;
3160 FFlameSoundOff
.Stop();
3161 FFlameSoundOff
.SetPosition(0);
3164 if (not FFlameSoundOn
.IsPlaying()) and (not FFlameSoundWork
.IsPlaying()) then
3165 FFlameSoundWork
.PlayAt(FObj
.X
, FObj
.Y
);
3169 FFlameSoundOn
.PlayAt(FObj
.X
, FObj
.Y
);
3174 procedure TPlayer
.FlamerOff
;
3178 FFlameSoundOn
.Stop();
3179 FFlameSoundOn
.SetPosition(0);
3180 FFlameSoundWork
.Stop();
3181 FFlameSoundWork
.SetPosition(0);
3182 FFlameSoundOff
.PlayAt(FObj
.X
, FObj
.Y
);
3187 procedure TPlayer
.JetpackOn
;
3191 FJetSoundOn
.SetPosition(0);
3192 FJetSoundOn
.PlayAt(FObj
.X
, FObj
.Y
);
3196 procedure TPlayer
.JetpackOff
;
3200 FJetSoundOff
.SetPosition(0);
3201 FJetSoundOff
.PlayAt(FObj
.X
, FObj
.Y
);
3204 procedure TPlayer
.CatchFire(Attacker
: Word; Timeout
: Integer = PLAYER_BURN_TIME
);
3206 if Timeout
<= 0 then
3208 if (FMegaRulez
[MR_SUIT
] > gTime
) or (FMegaRulez
[MR_INVUL
] > gTime
) then
3209 exit
; // Íå çàãîðàåìñÿ êîãäà åñòü çàùèòà
3210 if g_Obj_CollidePanel(@FObj
, 0, 0, PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
) then
3211 exit
; // Íå ïîäãîðàåì â âîäå íà âñÿêèé ñëó÷àé
3212 if FFireTime
<= 0 then
3213 g_Sound_PlayExAt('SOUND_IGNITE', FObj
.X
, FObj
.Y
);
3214 FFireTime
:= Timeout
;
3215 FFireAttacker
:= Attacker
;
3216 if g_Game_IsNet
and g_Game_IsServer
then
3217 MH_SEND_PlayerStats(FUID
);
3220 procedure TPlayer
.Jump();
3222 if gFly
or FJetpack
then
3224 // Ïîëåò (÷èò-êîä èëè äæåòïàê):
3225 if FObj
.Vel
.Y
> -VEL_FLY
then
3226 FObj
.Vel
.Y
:= FObj
.Vel
.Y
- 3;
3229 if FJetFuel
> 0 then
3231 if (FJetFuel
< 1) and g_Game_IsServer
then
3235 if g_Game_IsNet
then
3236 MH_SEND_PlayerStats(FUID
);
3242 // Íå âêëþ÷àòü äæåòïàê â ðåæèìå ïðîõîæäåíèÿ ñêâîçü ñòåíû
3244 FCanJetpack
:= False;
3246 // Ïðûãàåì èëè âñïëûâàåì:
3247 if (CollideLevel(0, 1) or
3248 g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
+36, PLAYER_RECT
.Width
,
3249 PLAYER_RECT
.Height
-33, PANEL_STEP
, False)
3250 ) and (FObj
.Accel
.Y
= 0) then // Íå ïðûãàòü, åñëè åñòü âåðòèêàëüíîå óñêîðåíèå
3252 FObj
.Vel
.Y
:= -VEL_JUMP
;
3253 FCanJetpack
:= False;
3257 if BodyInLiquid(0, 0) then
3258 FObj
.Vel
.Y
:= -VEL_SW
3259 else if (FJetFuel
> 0) and FCanJetpack
and
3260 g_Game_IsServer
and (not g_Obj_CollideLiquid(@FObj
, 0, 0)) then
3264 if g_Game_IsNet
then
3265 MH_SEND_PlayerStats(FUID
);
3270 procedure TPlayer
.Kill(KillType
: Byte; SpawnerUID
: Word; t
: Byte);
3272 a
, i
, k
, ab
, ar
: Byte;
3276 srv
, netsrv
: Boolean;
3282 procedure PushItem(t
: Byte);
3286 id
:= g_Items_Create(FObj
.X
, FObj
.Y
, t
, True, False);
3287 it
:= g_Items_ByIdx(id
);
3288 if KillType
= K_EXTRAHARDKILL
then // -7..+7; -8..0
3290 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-7+Random(15),
3291 (FObj
.Vel
.Y
div 2)-Random(9));
3292 it
.positionChanged(); // this updates spatial accelerators
3296 if KillType
= K_HARDKILL
then // -5..+5; -5..0
3298 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-5+Random(11),
3299 (FObj
.Vel
.Y
div 2)-Random(6));
3301 else // -3..+3; -3..0
3303 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-3+Random(7),
3304 (FObj
.Vel
.Y
div 2)-Random(4));
3306 it
.positionChanged(); // this updates spatial accelerators
3309 if g_Game_IsNet
and g_Game_IsServer
then
3310 MH_SEND_ItemSpawn(True, id
);
3314 DoFrags
:= (gGameSettings
.MaxLives
= 0) or (gGameSettings
.GameMode
= GM_COOP
);
3315 Srv
:= g_Game_IsServer
;
3316 Netsrv
:= g_Game_IsServer
and g_Game_IsNet
;
3317 if Srv
then FDeath
:= FDeath
+ 1;
3322 if not FPhysics
then
3328 if (gGameSettings
.MaxLives
> 0) and Srv
and (gLMSRespawn
= LMS_RESPAWN_NONE
) then
3330 if FLives
> 0 then FLives
:= FLives
- 1;
3331 if FLives
= 0 then FNoRespawn
:= True;
3334 // Íîìåð òèïà ñìåðòè:
3337 K_SIMPLEKILL
: a
:= 1;
3339 K_EXTRAHARDKILL
: a
:= 3;
3344 if not FModel
.PlaySound(MODELSOUND_DIE
, a
, FObj
.X
, FObj
.Y
) then
3346 if FModel
.PlaySound(MODELSOUND_DIE
, i
, FObj
.X
, FObj
.Y
) then
3353 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN1
;
3355 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN2
;
3356 K_EXTRAHARDKILL
, K_FALLKILL
:
3357 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN3
;
3360 // Ïåðåêëþ÷àåì ñîñòîÿíèå:
3364 K_HARDKILL
, K_EXTRAHARDKILL
:
3368 // Ðåàêöèÿ ìîíñòðîâ íà ñìåðòü èãðîêà:
3369 if (KillType
<> K_FALLKILL
) and (Srv
) then
3370 g_Monsters_killedp();
3372 if SpawnerUID
= FUID
then
3374 if Srv
and (DoFrags
or (gGameSettings
.GameMode
= GM_TDM
)) then
3379 g_Console_Add(Format(_lc
[I_PLAYER_KILL_SELF
], [FName
]), True);
3382 if g_GetUIDType(SpawnerUID
) = UID_PLAYER
then
3383 begin // Óáèò äðóãèì èãðîêîì
3384 KP
:= g_Player_Get(SpawnerUID
);
3385 if (KP
<> nil) and Srv
then
3387 if (DoFrags
or (gGameSettings
.GameMode
= GM_TDM
)) then
3388 if SameTeam(FUID
, SpawnerUID
) then
3398 if (gGameSettings
.GameMode
= GM_TDM
) and DoFrags
then
3399 Inc(gTeamStat
[KP
.Team
].Goals
,
3400 IfThen(SameTeam(FUID
, SpawnerUID
), -1, 1));
3402 if netsrv
then MH_SEND_PlayerStats(SpawnerUID
);
3405 plr
:= g_Player_Get(SpawnerUID
);
3413 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_2
],
3417 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_1
],
3421 g_Console_Add(Format(_lc
[I_PLAYER_KILL
],
3426 else if g_GetUIDType(SpawnerUID
) = UID_MONSTER
then
3427 begin // Óáèò ìîíñòðîì
3428 mon
:= g_Monsters_ByUID(SpawnerUID
);
3432 s
:= g_Mons_GetKilledByTypeId(mon
.MonsterType
);
3436 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_2
],
3440 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_1
],
3444 g_Console_Add(Format(_lc
[I_PLAYER_KILL
],
3449 else // Îñîáûå òèïû ñìåðòè
3452 HIT_SELF
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_SELF
], [FName
]), True);
3453 HIT_FALL
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_FALL
], [FName
]), True);
3454 HIT_WATER
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_WATER
], [FName
]), True);
3455 HIT_ACID
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_ACID
], [FName
]), True);
3456 HIT_TRAP
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_TRAP
], [FName
]), True);
3457 else g_Console_Add(Format(_lc
[I_PLAYER_DIED
], [FName
]), True);
3463 for a
:= WP_FIRST
to WP_LAST
do
3467 WEAPON_SAW
: i
:= ITEM_WEAPON_SAW
;
3468 WEAPON_SHOTGUN1
: i
:= ITEM_WEAPON_SHOTGUN1
;
3469 WEAPON_SHOTGUN2
: i
:= ITEM_WEAPON_SHOTGUN2
;
3470 WEAPON_CHAINGUN
: i
:= ITEM_WEAPON_CHAINGUN
;
3471 WEAPON_ROCKETLAUNCHER
: i
:= ITEM_WEAPON_ROCKETLAUNCHER
;
3472 WEAPON_PLASMA
: i
:= ITEM_WEAPON_PLASMA
;
3473 WEAPON_BFG
: i
:= ITEM_WEAPON_BFG
;
3474 WEAPON_SUPERPULEMET
: i
:= ITEM_WEAPON_SUPERPULEMET
;
3475 WEAPON_FLAMETHROWER
: i
:= ITEM_WEAPON_FLAMETHROWER
;
3484 if R_ITEM_BACKPACK
in FRulez
then
3485 PushItem(ITEM_AMMO_BACKPACK
);
3487 // Âûáðîñ ðàêåòíîãî ðàíöà:
3488 if FJetFuel
> 0 then
3489 PushItem(ITEM_JETPACK
);
3492 if not (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
]) then
3494 if R_KEY_RED
in FRulez
then
3495 PushItem(ITEM_KEY_RED
);
3497 if R_KEY_GREEN
in FRulez
then
3498 PushItem(ITEM_KEY_GREEN
);
3500 if R_KEY_BLUE
in FRulez
then
3501 PushItem(ITEM_KEY_BLUE
);
3505 DropFlag(KillType
= K_FALLKILL
);
3508 g_Player_CreateCorpse(Self
);
3510 if Srv
and (gGameSettings
.MaxLives
> 0) and FNoRespawn
and
3511 (gLMSRespawn
= LMS_RESPAWN_NONE
) then
3517 for i
:= Low(gPlayers
) to High(gPlayers
) do
3519 if gPlayers
[i
] = nil then continue
;
3520 if (not gPlayers
[i
].FNoRespawn
) and (not gPlayers
[i
].FSpectator
) then
3523 if gPlayers
[i
].FTeam
= TEAM_RED
then Inc(ar
)
3524 else if gPlayers
[i
].FTeam
= TEAM_BLUE
then Inc(ab
);
3529 OldLR
:= gLMSRespawn
;
3530 if (gGameSettings
.GameMode
= GM_COOP
) then
3534 // everyone is dead, restart the map
3535 g_Game_Message(_lc
[I_MESSAGE_LMS_LOSE
], 144);
3537 MH_SEND_GameEvent(NET_EV_LMS_LOSE
);
3538 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3539 gLMSRespawnTime
:= gTime
+ 5000;
3541 else if (a
= 1) then
3543 if (gPlayers
[k
] <> nil) and not (gPlayers
[k
] is TBot
) then
3544 if (gPlayers
[k
] = gPlayer1
) or
3545 (gPlayers
[k
] = gPlayer2
) then
3546 g_Console_Add('*** ' + _lc
[I_MESSAGE_LMS_SURVIVOR
] + ' ***', True)
3547 else if Netsrv
and (gPlayers
[k
].FClientID
>= 0) then
3548 MH_SEND_GameEvent(NET_EV_LMS_SURVIVOR
, 0, 'N', gPlayers
[k
].FClientID
);
3551 else if (gGameSettings
.GameMode
= GM_TDM
) then
3553 if (ab
= 0) and (ar
<> 0) then
3556 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 144);
3558 MH_SEND_GameEvent(NET_EV_TLMS_WIN
, TEAM_RED
);
3559 Inc(gTeamStat
[TEAM_RED
].Goals
);
3560 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3561 gLMSRespawnTime
:= gTime
+ 5000;
3563 else if (ar
= 0) and (ab
<> 0) then
3566 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 144);
3568 MH_SEND_GameEvent(NET_EV_TLMS_WIN
, TEAM_BLUE
);
3569 Inc(gTeamStat
[TEAM_BLUE
].Goals
);
3570 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3571 gLMSRespawnTime
:= gTime
+ 5000;
3573 else if (ar
= 0) and (ab
= 0) then
3576 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
3578 MH_SEND_GameEvent(NET_EV_LMS_DRAW
, 0, FName
);
3579 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3580 gLMSRespawnTime
:= gTime
+ 5000;
3583 else if (gGameSettings
.GameMode
= GM_DM
) then
3587 if gPlayers
[k
] <> nil then
3590 // survivor is the winner
3591 g_Game_Message(Format(_lc
[I_MESSAGE_LMS_WIN
], [AnsiUpperCase(FName
)]), 144);
3593 MH_SEND_GameEvent(NET_EV_LMS_WIN
, 0, FName
);
3596 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3597 gLMSRespawnTime
:= gTime
+ 5000;
3599 else if (a
= 0) then
3601 // everyone is dead, restart the map
3602 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
3604 MH_SEND_GameEvent(NET_EV_LMS_DRAW
, 0, FName
);
3605 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3606 gLMSRespawnTime
:= gTime
+ 5000;
3609 if srv
and (OldLR
= LMS_RESPAWN_NONE
) and (gLMSRespawn
> LMS_RESPAWN_NONE
) then
3611 if NetMode
= NET_SERVER
then
3612 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, (gLMSRespawnTime
- gTime
) div 1000)
3614 g_Console_Add(Format(_lc
[I_MSG_WARMUP_START
], [(gLMSRespawnTime
- gTime
) div 1000]), True);
3620 MH_SEND_PlayerStats(FUID
);
3621 MH_SEND_PlayerDeath(FUID
, KillType
, t
, SpawnerUID
);
3622 if gGameSettings
.GameMode
= GM_TDM
then MH_SEND_GameStats
;
3625 if srv
and FNoRespawn
then Spectate(True);
3626 FWantsInGame
:= True;
3629 function TPlayer
.BodyInLiquid(XInc
, YInc
: Integer): Boolean;
3631 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
, PLAYER_RECT
.Width
,
3632 PLAYER_RECT
.Height
-20, PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, False);
3635 function TPlayer
.BodyInAcid(XInc
, YInc
: Integer): Boolean;
3637 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
, PLAYER_RECT
.Width
,
3638 PLAYER_RECT
.Height
-20, PANEL_ACID1
or PANEL_ACID2
, False);
3641 procedure TPlayer
.MakeBloodSimple(Count
: Word);
3643 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)+8,
3644 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3645 Count
div 2, 3, -1, 16, (PLAYER_RECT
.Height
*2 div 3),
3646 FModel
.Blood
.R
, FModel
.Blood
.G
, FModel
.Blood
.B
, FModel
.Blood
.Kind
);
3647 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-8,
3648 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3649 Count
div 2, -3, -1, 16, (PLAYER_RECT
.Height
*2) div 3,
3650 FModel
.Blood
.R
, FModel
.Blood
.G
, FModel
.Blood
.B
, FModel
.Blood
.Kind
);
3653 procedure TPlayer
.MakeBloodVector(Count
: Word; VelX
, VelY
: Integer);
3655 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
3656 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3657 Count
, VelX
, VelY
, 16, (PLAYER_RECT
.Height
*2) div 3,
3658 FModel
.Blood
.R
, FModel
.Blood
.G
, FModel
.Blood
.B
, FModel
.Blood
.Kind
);
3661 procedure TPlayer
.QueueWeaponSwitch(Weapon
: Byte);
3663 if g_Game_IsClient
then Exit
;
3664 if Weapon
> High(FWeapon
) then Exit
;
3665 FNextWeap
:= FNextWeap
or (1 shl Weapon
);
3668 procedure TPlayer
.resetWeaponQueue ();
3671 FNextWeapDelay
:= 0;
3674 function TPlayer
.hasAmmoForWeapon (weapon
: Byte): Boolean;
3678 WEAPON_KASTET
, WEAPON_SAW
: result
:= true;
3679 WEAPON_SHOTGUN1
, WEAPON_SHOTGUN2
: result
:= (FAmmo
[A_SHELLS
] > 0);
3680 WEAPON_PISTOL
, WEAPON_CHAINGUN
, WEAPON_SUPERPULEMET
: result
:= (FAmmo
[A_BULLETS
] > 0);
3681 WEAPON_ROCKETLAUNCHER
: result
:= (FAmmo
[A_ROCKETS
] > 0);
3682 WEAPON_PLASMA
, WEAPON_BFG
: result
:= (FAmmo
[A_CELLS
] > 0);
3683 WEAPON_FLAMETHROWER
: result
:= (FAmmo
[A_FUEL
] > 0);
3684 else result
:= (weapon
< length(FWeapon
));
3688 // return 255 for "no switch"
3689 function TPlayer
.getNextWeaponIndex (): Byte;
3692 wantThisWeapon
: array[0..64] of Boolean;
3693 wwc
: Integer = 0; //HACK!
3696 result
:= 255; // default result: "no switch"
3697 // had weapon cycling on previous frame? remove that flag
3698 if (FNextWeap
and $2000) <> 0 then
3700 FNextWeap
:= FNextWeap
and $1FFF;
3701 FNextWeapDelay
:= 0;
3703 // cycling has priority
3704 if (FNextWeap
and $C000) <> 0 then
3706 if (FNextWeap
and $8000) <> 0 then
3710 FNextWeap
:= FNextWeap
or $2000; // we need this
3711 if FNextWeapDelay
> 0 then
3712 exit
; // cooldown time
3714 for i
:= 0 to High(FWeapon
) do
3716 cwi
:= (cwi
+length(FWeapon
)+dir
) mod length(FWeapon
);
3717 if FWeapon
[cwi
] then
3719 //e_WriteLog(Format(' SWITCH: cur=%d; new=%d', [FCurrWeap, cwi]), MSG_WARNING);
3720 result
:= Byte(cwi
);
3721 FNextWeapDelay
:= WEAPON_DELAY
;
3729 for i
:= 0 to High(wantThisWeapon
) do
3730 wantThisWeapon
[i
] := false;
3731 for i
:= 0 to High(FWeapon
) do
3732 if (FNextWeap
and (1 shl i
)) <> 0 then
3734 wantThisWeapon
[i
] := true;
3737 // exclude currently selected weapon from the set
3738 wantThisWeapon
[FCurrWeap
] := false;
3739 // slow down alterations a little
3742 //e_WriteLog(Format(' FNextWeap=%x; delay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
3743 // more than one weapon requested, assume "alteration" and check alteration delay
3744 if FNextWeapDelay
> 0 then
3750 // do not reset weapon queue, it will be done in `RealizeCurrentWeapon()`
3751 // but clear all counters if no weapon should be switched
3757 //e_WriteLog(Format('wwc=%d', [wwc]), MSG_WARNING);
3758 // try weapons in descending order
3759 for i
:= High(FWeapon
) downto 0 do
3761 if wantThisWeapon
[i
] and FWeapon
[i
] and ((wwc
= 1) or hasAmmoForWeapon(i
)) then
3766 FNextWeapDelay
:= WEAPON_DELAY
* 2; // anyway, 'cause why not
3770 // no suitable weapon found, so reset the queue, to avoid accidental "queuing" of weapon w/o ammo
3774 procedure TPlayer
.RealizeCurrentWeapon();
3775 function switchAllowed (): Boolean;
3780 if FBFGFireCounter
<> -1 then
3782 if FTime
[T_SWITCH
] > gTime
then
3784 for i
:= WP_FIRST
to WP_LAST
do
3785 if FReloading
[i
] > 0 then
3793 //e_WriteLog(Format('***RealizeCurrentWeapon: FNextWeap=%x; FNextWeapDelay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
3794 //FNextWeap := FNextWeap and $1FFF;
3795 if FNextWeapDelay
> 0 then Dec(FNextWeapDelay
); // "alteration delay"
3797 if not switchAllowed
then
3799 //HACK for weapon cycling
3800 if (FNextWeap
and $E000) <> 0 then FNextWeap
:= 0;
3804 nw
:= getNextWeaponIndex();
3805 if nw
= 255 then exit
; // don't reset anything here
3806 if nw
> High(FWeapon
) then
3808 // don't forget to reset queue here!
3809 //e_WriteLog(' RealizeCurrentWeapon: WUTAFUUUU', MSG_WARNING);
3817 FTime
[T_SWITCH
] := gTime
+156;
3818 if FCurrWeap
= WEAPON_SAW
then FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3819 FModel
.SetWeapon(FCurrWeap
);
3820 if g_Game_IsNet
then MH_SEND_PlayerStats(FUID
);
3824 procedure TPlayer
.NextWeapon();
3826 if g_Game_IsClient
then Exit
;
3830 procedure TPlayer
.PrevWeapon();
3832 if g_Game_IsClient
then Exit
;
3836 procedure TPlayer
.SetWeapon(W
: Byte);
3838 if FCurrWeap
<> W
then
3839 if W
= WEAPON_SAW
then
3840 FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3843 FModel
.SetWeapon(CurrWeap
);
3847 function TPlayer
.PickItem(ItemType
: Byte; arespawn
: Boolean; var remove
: Boolean): Boolean;
3849 function allowBerserkSwitching (): Boolean;
3851 if (FBFGFireCounter
<> -1) then begin result
:= false; exit
; end;
3853 if gBerserkAutoswitch
then exit
;
3854 if not conIsCheatsEnabled
then exit
;
3862 if g_Game_IsClient
then Exit
;
3864 // a = true - ìåñòî ñïàâíà ïðåäìåòà:
3865 a
:= LongBool(gGameSettings
.Options
and GAME_OPTION_WEAPONSTAY
) and arespawn
;
3870 if (FHealth
< PLAYER_HP_SOFT
) or (FFireTime
> 0) then
3872 if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
3876 if gFlash
= 2 then Inc(FPickup
, 5);
3880 if (FHealth
< PLAYER_HP_SOFT
) or (FFireTime
> 0) then
3882 if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
3886 if gFlash
= 2 then Inc(FPickup
, 5);
3890 if FArmor
< PLAYER_AP_SOFT
then
3892 FArmor
:= PLAYER_AP_SOFT
;
3895 if gFlash
= 2 then Inc(FPickup
, 5);
3899 if FArmor
< PLAYER_AP_LIMIT
then
3901 FArmor
:= PLAYER_AP_LIMIT
;
3904 if gFlash
= 2 then Inc(FPickup
, 5);
3908 if (FHealth
< PLAYER_HP_LIMIT
) or (FFireTime
> 0) then
3910 if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
3914 if gFlash
= 2 then Inc(FPickup
, 5);
3918 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) or (FFireTime
> 0) then
3920 if FHealth
< PLAYER_HP_LIMIT
then
3921 FHealth
:= PLAYER_HP_LIMIT
;
3922 if FArmor
< PLAYER_AP_LIMIT
then
3923 FArmor
:= PLAYER_AP_LIMIT
;
3927 if gFlash
= 2 then Inc(FPickup
, 5);
3931 if (not FWeapon
[WEAPON_SAW
]) or ((not arespawn
) and (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
])) then
3933 FWeapon
[WEAPON_SAW
] := True;
3935 if gFlash
= 2 then Inc(FPickup
, 5);
3936 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3939 ITEM_WEAPON_SHOTGUN1
:
3940 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN1
] then
3942 // Íóæíî, ÷òîáû íå âçÿòü âñå ïóëè ñðàçó:
3943 if a
and FWeapon
[WEAPON_SHOTGUN1
] then Exit
;
3945 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3946 FWeapon
[WEAPON_SHOTGUN1
] := True;
3948 if gFlash
= 2 then Inc(FPickup
, 5);
3949 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3952 ITEM_WEAPON_SHOTGUN2
:
3953 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN2
] then
3955 if a
and FWeapon
[WEAPON_SHOTGUN2
] then Exit
;
3957 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3958 FWeapon
[WEAPON_SHOTGUN2
] := True;
3960 if gFlash
= 2 then Inc(FPickup
, 5);
3961 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3964 ITEM_WEAPON_CHAINGUN
:
3965 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or not FWeapon
[WEAPON_CHAINGUN
] then
3967 if a
and FWeapon
[WEAPON_CHAINGUN
] then Exit
;
3969 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
3970 FWeapon
[WEAPON_CHAINGUN
] := True;
3972 if gFlash
= 2 then Inc(FPickup
, 5);
3973 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3976 ITEM_WEAPON_ROCKETLAUNCHER
:
3977 if (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or not FWeapon
[WEAPON_ROCKETLAUNCHER
] then
3979 if a
and FWeapon
[WEAPON_ROCKETLAUNCHER
] then Exit
;
3981 IncMax(FAmmo
[A_ROCKETS
], 2, FMaxAmmo
[A_ROCKETS
]);
3982 FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
3984 if gFlash
= 2 then Inc(FPickup
, 5);
3985 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3989 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_PLASMA
] then
3991 if a
and FWeapon
[WEAPON_PLASMA
] then Exit
;
3993 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3994 FWeapon
[WEAPON_PLASMA
] := True;
3996 if gFlash
= 2 then Inc(FPickup
, 5);
3997 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4001 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_BFG
] then
4003 if a
and FWeapon
[WEAPON_BFG
] then Exit
;
4005 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
4006 FWeapon
[WEAPON_BFG
] := True;
4008 if gFlash
= 2 then Inc(FPickup
, 5);
4009 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4012 ITEM_WEAPON_SUPERPULEMET
:
4013 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SUPERPULEMET
] then
4015 if a
and FWeapon
[WEAPON_SUPERPULEMET
] then Exit
;
4017 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4018 FWeapon
[WEAPON_SUPERPULEMET
] := True;
4020 if gFlash
= 2 then Inc(FPickup
, 5);
4021 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4024 ITEM_WEAPON_FLAMETHROWER
:
4025 if (FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
]) or not FWeapon
[WEAPON_FLAMETHROWER
] then
4027 if a
and FWeapon
[WEAPON_FLAMETHROWER
] then Exit
;
4029 IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
4030 FWeapon
[WEAPON_FLAMETHROWER
] := True;
4032 if gFlash
= 2 then Inc(FPickup
, 5);
4033 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4037 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
4039 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
4042 if gFlash
= 2 then Inc(FPickup
, 5);
4045 ITEM_AMMO_BULLETS_BOX
:
4046 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
4048 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
4051 if gFlash
= 2 then Inc(FPickup
, 5);
4055 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
4057 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4060 if gFlash
= 2 then Inc(FPickup
, 5);
4063 ITEM_AMMO_SHELLS_BOX
:
4064 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
4066 IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
4069 if gFlash
= 2 then Inc(FPickup
, 5);
4073 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
4075 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
4078 if gFlash
= 2 then Inc(FPickup
, 5);
4081 ITEM_AMMO_ROCKET_BOX
:
4082 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
4084 IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
4087 if gFlash
= 2 then Inc(FPickup
, 5);
4091 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
4093 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
4096 if gFlash
= 2 then Inc(FPickup
, 5);
4100 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
4102 IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
4105 if gFlash
= 2 then Inc(FPickup
, 5);
4109 if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then
4111 IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
4114 if gFlash
= 2 then Inc(FPickup
, 5);
4118 if not(R_ITEM_BACKPACK
in FRulez
) or
4119 (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
4120 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
4121 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
4122 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or
4123 (FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
]) then
4125 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[1, A_BULLETS
];
4126 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[1, A_SHELLS
];
4127 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[1, A_ROCKETS
];
4128 FMaxAmmo
[A_CELLS
] := AmmoLimits
[1, A_CELLS
];
4129 FMaxAmmo
[A_FUEL
] := AmmoLimits
[1, A_FUEL
];
4131 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
4132 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
4133 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
4134 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4135 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
4136 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
4137 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
4138 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
4139 if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then
4140 IncMax(FAmmo
[A_FUEL
], 50, FMaxAmmo
[A_FUEL
]);
4142 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
4145 if gFlash
= 2 then Inc(FPickup
, 5);
4149 if not(R_KEY_RED
in FRulez
) then
4151 Include(FRulez
, R_KEY_RED
);
4153 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
4154 if gFlash
= 2 then Inc(FPickup
, 5);
4155 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
4159 if not(R_KEY_GREEN
in FRulez
) then
4161 Include(FRulez
, R_KEY_GREEN
);
4163 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
4164 if gFlash
= 2 then Inc(FPickup
, 5);
4165 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
4169 if not(R_KEY_BLUE
in FRulez
) then
4171 Include(FRulez
, R_KEY_BLUE
);
4173 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
4174 if gFlash
= 2 then Inc(FPickup
, 5);
4175 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
4179 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
4181 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
4185 if gFlash
= 2 then Inc(FPickup
, 5);
4189 if FAir
< AIR_MAX
then
4194 if gFlash
= 2 then Inc(FPickup
, 5);
4199 if not (R_BERSERK
in FRulez
) then
4201 Include(FRulez
, R_BERSERK
);
4202 if allowBerserkSwitching
then
4204 FCurrWeap
:= WEAPON_KASTET
;
4206 FModel
.SetWeapon(WEAPON_KASTET
);
4211 if gFlash
= 2 then Inc(FPickup
, 5);
4213 FBerserk
:= gTime
+30000;
4218 if (FHealth
< PLAYER_HP_SOFT
) or (FFireTime
> 0) then
4220 if FHealth
< PLAYER_HP_SOFT
then FHealth
:= PLAYER_HP_SOFT
;
4221 FBerserk
:= gTime
+30000;
4229 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
4231 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
4234 if gFlash
= 2 then Inc(FPickup
, 5);
4238 if (FHealth
< PLAYER_HP_LIMIT
) or (FFireTime
> 0) then
4240 if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
4244 if gFlash
= 2 then Inc(FPickup
, 5);
4248 if FArmor
< PLAYER_AP_LIMIT
then
4250 IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
4253 if gFlash
= 2 then Inc(FPickup
, 5);
4257 if FJetFuel
< JET_MAX
then
4259 FJetFuel
:= JET_MAX
;
4262 if gFlash
= 2 then Inc(FPickup
, 5);
4266 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
4268 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
4271 if gFlash
= 2 then Inc(FPickup
, 5);
4276 procedure TPlayer
.Touch();
4280 //FModel.PlaySound(MODELSOUND_PAIN, 1, FObj.X, FObj.Y);
4283 // Áðîñèòü ôëàã òîâàðèùó:
4284 if gGameSettings
.GameMode
= GM_CTF
then
4289 procedure TPlayer
.Push(vx
, vy
: Integer);
4291 if (not FPhysics
) and FGhost
then
4293 FObj
.Accel
.X
:= FObj
.Accel
.X
+ vx
;
4294 FObj
.Accel
.Y
:= FObj
.Accel
.Y
+ vy
;
4295 if g_Game_IsNet
and g_Game_IsServer
then
4296 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
4299 procedure TPlayer
.Reset(Force
: Boolean);
4305 FTime
[T_RESPAWN
] := 0;
4306 FTime
[T_FLAGCAP
] := 0;
4320 FSpectator
:= False;
4323 FSpectatePlayer
:= -1;
4324 FNoRespawn
:= False;
4326 FLives
:= gGameSettings
.MaxLives
;
4331 procedure TPlayer
.SoftReset();
4337 FBFGFireCounter
:= -1;
4345 SetAction(A_STAND
, True);
4348 function TPlayer
.GetRespawnPoint(): Byte;
4353 // Íà áóäóùåå: FSpawn - èãðîê óæå èãðàë è ïåðåðîæäàåòñÿ
4355 // Îäèíî÷íàÿ èãðà/êîîïåðàòèâ
4356 if gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
] then
4358 if (Self
= gPlayer1
) or (Self
= gPlayer2
) then
4360 // Òî÷êà ïîÿâëåíèÿ ñâîåãî èãðîêà
4361 if Self
= gPlayer1
then
4362 c
:= RESPAWNPOINT_PLAYER1
4364 c
:= RESPAWNPOINT_PLAYER2
;
4365 if g_Map_GetPointCount(c
) > 0 then
4371 // Òî÷êà ïîÿâëåíèÿ äðóãîãî èãðîêà
4372 if Self
= gPlayer1
then
4373 c
:= RESPAWNPOINT_PLAYER2
4375 c
:= RESPAWNPOINT_PLAYER1
;
4376 if g_Map_GetPointCount(c
) > 0 then
4383 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà (áîòà)
4384 if Random(2) = 0 then
4385 c
:= RESPAWNPOINT_PLAYER1
4387 c
:= RESPAWNPOINT_PLAYER2
;
4388 if g_Map_GetPointCount(c
) > 0 then
4395 // Òî÷êà ëþáîé èç êîìàíä
4396 if Random(2) = 0 then
4397 c
:= RESPAWNPOINT_RED
4399 c
:= RESPAWNPOINT_BLUE
;
4400 if g_Map_GetPointCount(c
) > 0 then
4407 c
:= RESPAWNPOINT_DM
;
4408 if g_Map_GetPointCount(c
) > 0 then
4416 if gGameSettings
.GameMode
= GM_DM
then
4419 c
:= RESPAWNPOINT_DM
;
4420 if g_Map_GetPointCount(c
) > 0 then
4426 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà
4427 if Random(2) = 0 then
4428 c
:= RESPAWNPOINT_PLAYER1
4430 c
:= RESPAWNPOINT_PLAYER2
;
4431 if g_Map_GetPointCount(c
) > 0 then
4437 // Òî÷êà ëþáîé èç êîìàíä
4438 if Random(2) = 0 then
4439 c
:= RESPAWNPOINT_RED
4441 c
:= RESPAWNPOINT_BLUE
;
4442 if g_Map_GetPointCount(c
) > 0 then
4450 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
4452 // Òî÷êà ñâîåé êîìàíäû
4453 c
:= RESPAWNPOINT_DM
;
4454 if FTeam
= TEAM_RED
then
4455 c
:= RESPAWNPOINT_RED
;
4456 if FTeam
= TEAM_BLUE
then
4457 c
:= RESPAWNPOINT_BLUE
;
4458 if g_Map_GetPointCount(c
) > 0 then
4465 c
:= RESPAWNPOINT_DM
;
4466 if g_Map_GetPointCount(c
) > 0 then
4472 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà
4473 if Random(2) = 0 then
4474 c
:= RESPAWNPOINT_PLAYER1
4476 c
:= RESPAWNPOINT_PLAYER2
;
4477 if g_Map_GetPointCount(c
) > 0 then
4483 // Òî÷êà äðóãîé êîìàíäû
4484 c
:= RESPAWNPOINT_DM
;
4485 if FTeam
= TEAM_RED
then
4486 c
:= RESPAWNPOINT_BLUE
;
4487 if FTeam
= TEAM_BLUE
then
4488 c
:= RESPAWNPOINT_RED
;
4489 if g_Map_GetPointCount(c
) > 0 then
4497 procedure TPlayer
.Respawn(Silent
: Boolean; Force
: Boolean = False);
4499 RespawnPoint
: TRespawnPoint
;
4505 FBFGFireCounter
:= -1;
4510 if not g_Game_IsServer
then
4514 FWantsInGame
:= True;
4515 FJustTeleported
:= True;
4518 FTime
[T_RESPAWN
] := 0;
4522 // if server changes MaxLives we gotta be ready
4523 if gGameSettings
.MaxLives
= 0 then FNoRespawn
:= False;
4525 // Åùå íåëüçÿ âîçðîäèòüñÿ:
4526 if FTime
[T_RESPAWN
] > gTime
then
4529 // Ïðîñðàë âñå æèçíè:
4532 if not FSpectator
then Spectate(True);
4533 FWantsInGame
:= True;
4537 if (gGameSettings
.GameType
<> GT_SINGLE
) and (gGameSettings
.GameMode
<> GM_COOP
) then
4538 begin // "Ñâîÿ èãðà"
4539 // Áåðñåðê íå ñîõðàíÿåòñÿ ìåæäó óðîâíÿìè:
4540 FRulez
:= FRulez
-[R_BERSERK
];
4542 else // "Îäèíî÷íàÿ èãðà"/"Êîîï"
4544 // Áåðñåðê è êëþ÷è íå ñîõðàíÿþòñÿ ìåæäó óðîâíÿìè:
4545 FRulez
:= FRulez
-[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
, R_BERSERK
];
4548 // Ïîëó÷àåì òî÷êó ñïàóíà èãðîêà:
4549 c
:= GetRespawnPoint();
4554 // Âîñêðåøåíèå áåç îðóæèÿ:
4557 FHealth
:= Round(PLAYER_HP_SOFT
* (FHandicap
/ 100));
4563 for a
:= WP_FIRST
to WP_LAST
do
4565 FWeapon
[a
] := False;
4569 FWeapon
[WEAPON_PISTOL
] := True;
4570 FWeapon
[WEAPON_KASTET
] := True;
4571 FCurrWeap
:= WEAPON_PISTOL
;
4574 FModel
.SetWeapon(FCurrWeap
);
4576 for b
:= A_BULLETS
to A_HIGH
do
4579 FAmmo
[A_BULLETS
] := 50;
4581 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[0, A_BULLETS
];
4582 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[0, A_SHELLS
];
4583 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[0, A_SHELLS
];
4584 FMaxAmmo
[A_CELLS
] := AmmoLimits
[0, A_CELLS
];
4585 FMaxAmmo
[A_FUEL
] := AmmoLimits
[0, A_FUEL
];
4587 if gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
] then
4588 FRulez
:= [R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
]
4593 // Ïîëó÷àåì êîîðäèíàòû òî÷êè âîçðîæäåíèÿ:
4594 if not g_Map_GetPoint(c
, RespawnPoint
) then
4596 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
4600 // Óñòàíîâêà êîîðäèíàò è ñáðîñ âñåõ ïàðàìåòðîâ:
4601 FObj
.X
:= RespawnPoint
.X
-PLAYER_RECT
.X
;
4602 FObj
.Y
:= RespawnPoint
.Y
-PLAYER_RECT
.Y
;
4608 FDirection
:= RespawnPoint
.Direction
;
4609 if FDirection
= TDirection
.D_LEFT
then
4614 SetAction(A_STAND
, True);
4615 FModel
.Direction
:= FDirection
;
4617 for a
:= Low(FTime
) to High(FTime
) do
4620 for a
:= Low(FMegaRulez
) to High(FMegaRulez
) do
4625 FCanJetpack
:= False;
4631 // Àíèìàöèÿ âîçðîæäåíèÿ:
4632 if (not gLoadGameMode
) and (not Silent
) then
4633 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
4635 Anim
:= TAnimation
.Create(ID
, False, 3);
4636 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4637 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4641 FSpectator
:= False;
4644 FSpectatePlayer
:= -1;
4647 if (gPlayer1
= nil) and (gLMSPID1
= FUID
) then
4649 if (gPlayer2
= nil) and (gLMSPID2
= FUID
) then
4652 if g_Game_IsNet
then
4654 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
4655 MH_SEND_PlayerStats(FUID
, NET_EVERYONE
);
4657 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4658 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32,
4663 procedure TPlayer
.Spectate(NoMove
: Boolean = False);
4666 Kill(K_EXTRAHARDKILL
, FUID
, HIT_SOME
)
4667 else if (not NoMove
) then
4669 GameX
:= gMapInfo
.Width
div 2;
4670 GameY
:= gMapInfo
.Height
div 2;
4679 FWantsInGame
:= False;
4684 if Self
= gPlayer1
then
4689 if Self
= gPlayer2
then
4696 if g_Game_IsNet
then
4697 MH_SEND_PlayerStats(FUID
);
4700 procedure TPlayer
.SwitchNoClip
;
4704 FGhost
:= not FGhost
;
4705 FPhysics
:= not FGhost
;
4717 procedure TPlayer
.Run(Direction
: TDirection
);
4721 if MAX_RUNVEL
> 8 then
4725 if Direction
= TDirection
.D_LEFT
then
4727 if FObj
.Vel
.X
> -MAX_RUNVEL
then
4728 FObj
.Vel
.X
:= FObj
.Vel
.X
- (MAX_RUNVEL
shr 3);
4731 if FObj
.Vel
.X
< MAX_RUNVEL
then
4732 FObj
.Vel
.X
:= FObj
.Vel
.X
+ (MAX_RUNVEL
shr 3);
4734 // Âîçìîæíî, ïèíàåì êóñêè:
4735 if (FObj
.Vel
.X
<> 0) and (gGibs
<> nil) then
4737 b
:= Abs(FObj
.Vel
.X
);
4738 if b
> 1 then b
:= b
* (Random(8 div b
) + 1);
4739 for a
:= 0 to High(gGibs
) do
4741 if gGibs
[a
].alive
and
4742 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
+FObj
.Rect
.Height
-4,
4743 FObj
.Rect
.Width
, 8, @gGibs
[a
].Obj
) and (Random(3) = 0) then
4746 if FObj
.Vel
.X
< 0 then
4748 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)+120) // íàëåâî
4752 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)); // íàïðàâî
4754 gGibs
[a
].positionChanged(); // this updates spatial accelerators
4762 procedure TPlayer
.SeeDown();
4764 SetAction(A_SEEDOWN
);
4766 if FDirection
= TDirection
.D_LEFT
then FAngle
:= ANGLE_LEFTDOWN
else FAngle
:= ANGLE_RIGHTDOWN
;
4768 if FIncCam
> -120 then DecMin(FIncCam
, 5, -120);
4771 procedure TPlayer
.SeeUp();
4775 if FDirection
= TDirection
.D_LEFT
then FAngle
:= ANGLE_LEFTUP
else FAngle
:= ANGLE_RIGHTUP
;
4777 if FIncCam
< 120 then IncMax(FIncCam
, 5, 120);
4780 procedure TPlayer
.SetAction(Action
: Byte; Force
: Boolean = False);
4788 A_ATTACK
: Prior
:= 2;
4789 A_SEEUP
: Prior
:= 1;
4790 A_SEEDOWN
: Prior
:= 1;
4791 A_ATTACKUP
: Prior
:= 2;
4792 A_ATTACKDOWN
: Prior
:= 2;
4797 if (Prior
> FActionPrior
) or Force
then
4798 if not ((Prior
= 2) and (FCurrWeap
= WEAPON_SAW
)) then
4800 FActionPrior
:= Prior
;
4801 FActionAnim
:= Action
;
4802 FActionForce
:= Force
;
4803 FActionChanged
:= True;
4806 if Action
in [A_ATTACK
, A_ATTACKUP
, A_ATTACKDOWN
] then FModel
.SetFire(True);
4809 function TPlayer
.StayOnStep(XInc
, YInc
: Integer): Boolean;
4811 Result
:= not g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
-1,
4812 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False)
4813 and g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
,
4814 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False);
4817 function TPlayer
.TeleportTo(X
, Y
: Integer; silent
: Boolean; dir
: Byte): Boolean;
4824 if g_CollideLevel(X
, Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
) then
4826 g_Sound_PlayExAt('SOUND_GAME_NOTELEPORT', FObj
.X
, FObj
.Y
);
4827 if g_Game_IsServer
and g_Game_IsNet
then
4828 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_GAME_NOTELEPORT');
4832 FJustTeleported
:= True;
4837 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
4839 Anim
:= TAnimation
.Create(ID
, False, 3);
4842 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', FObj
.X
, FObj
.Y
);
4843 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4844 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4845 if g_Game_IsServer
and g_Game_IsNet
then
4846 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4847 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 1,
4851 FObj
.X
:= X
-PLAYER_RECT
.X
;
4852 FObj
.Y
:= Y
-PLAYER_RECT
.Y
;
4853 if FAlive
and FGhost
then
4859 if not g_Game_IsNet
then
4863 SetDirection(TDirection
.D_LEFT
);
4869 SetDirection(TDirection
.D_RIGHT
);
4875 if FDirection
= TDirection
.D_RIGHT
then
4877 SetDirection(TDirection
.D_LEFT
);
4882 SetDirection(TDirection
.D_RIGHT
);
4888 if not silent
and (Anim
<> nil) then
4890 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4891 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4894 if g_Game_IsServer
and g_Game_IsNet
then
4895 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4896 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 0,
4903 function nonz(a
: Single): Single;
4911 function TPlayer
.followCorpse(): Boolean;
4916 if FAlive
or FSpectator
then
4918 if (gCorpses
= nil) or (Length(gCorpses
) = 0) then
4920 for i
:= 0 to High(gCorpses
) do
4921 if gCorpses
[i
] <> nil then
4922 if gCorpses
[i
].FPlayerUID
= FUID
then
4925 FObj
.X
:= gCorpses
[i
].FObj
.X
;
4926 FObj
.Y
:= gCorpses
[i
].FObj
.Y
;
4927 FObj
.Vel
.X
:= gCorpses
[i
].FObj
.Vel
.X
;
4928 FObj
.Vel
.Y
:= gCorpses
[i
].FObj
.Vel
.Y
;
4929 FObj
.Accel
.X
:= gCorpses
[i
].FObj
.Accel
.X
;
4930 FObj
.Accel
.Y
:= gCorpses
[i
].FObj
.Accel
.Y
;
4935 procedure TPlayer
.Update();
4938 i
, ii
, wx
, wy
, xd
, yd
, k
: Integer;
4939 blockmon
, headwater
, dospawn
: Boolean;
4944 NetServer
:= g_Game_IsNet
and g_Game_IsServer
;
4945 AnyServer
:= g_Game_IsServer
;
4947 if g_Game_IsClient
and (NetInterpLevel
> 0) then
4948 DoLerp(NetInterpLevel
+ 1)
4954 if FClientID
>= 0 then
4956 FPing
:= NetClients
[FClientID
].Peer
^.lastRoundTripTime
;
4957 if NetClients
[FClientID
].Peer
^.packetsSent
> 0 then
4958 FLoss
:= Round(100*NetClients
[FClientID
].Peer
^.packetsLost
/NetClients
[FClientID
].Peer
^.packetsSent
)
4967 if FAlive
and (FPunchAnim
<> nil) then
4968 FPunchAnim
.Update();
4970 if FAlive
and (gFly
or FJetpack
) then
4973 if FDirection
= TDirection
.D_LEFT
then
4978 if FAlive
and (not FGhost
) then
4980 if FKeys
[KEY_UP
].Pressed
then
4982 if FKeys
[KEY_DOWN
].Pressed
then
4986 if (not (FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_DOWN
].Pressed
)) and
4989 i
:= g_basic
.Sign(FIncCam
);
4990 FIncCam
:= Abs(FIncCam
);
4991 DecMin(FIncCam
, 5, 0);
4992 FIncCam
:= FIncCam
*i
;
4995 // no need to do that each second frame, weapon queue will take care of it
4996 if FAlive
and FKeys
[KEY_NEXTWEAPON
].Pressed
and AnyServer
then NextWeapon();
4997 if FAlive
and FKeys
[KEY_PREVWEAPON
].Pressed
and AnyServer
then PrevWeapon();
4999 if gTime
mod (GAME_TICK
*2) <> 0 then
5001 if (FObj
.Vel
.X
= 0) and FAlive
then
5003 if FKeys
[KEY_LEFT
].Pressed
then
5004 Run(TDirection
.D_LEFT
);
5005 if FKeys
[KEY_RIGHT
].Pressed
then
5006 Run(TDirection
.D_RIGHT
);
5011 if not followCorpse() then
5012 g_Obj_Move(@FObj
, True, True, True);
5013 positionChanged(); // this updates spatial accelerators
5019 FActionChanged
:= False;
5023 // Let alive player do some actions
5024 if FKeys
[KEY_LEFT
].Pressed
then Run(TDirection
.D_LEFT
);
5025 if FKeys
[KEY_RIGHT
].Pressed
then Run(TDirection
.D_RIGHT
);
5026 //if FKeys[KEY_NEXTWEAPON].Pressed and AnyServer then NextWeapon();
5027 //if FKeys[KEY_PREVWEAPON].Pressed and AnyServer then PrevWeapon();
5028 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then Fire()
5034 if NetServer
then MH_SEND_PlayerStats(FUID
);
5037 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Use();
5038 if FKeys
[KEY_JUMP
].Pressed
then Jump()
5041 if AnyServer
and FJetpack
then
5045 if NetServer
then MH_SEND_PlayerStats(FUID
);
5047 FCanJetpack
:= True;
5054 for k
:= Low(FKeys
) to KEY_CHAT
-1 do
5056 if FKeys
[k
].Pressed
then
5064 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
5067 if (FTime
[T_RESPAWN
] <= gTime
) and
5068 gGameOn
and (not FAlive
) then
5070 if (g_Player_GetCount() > 1) then
5074 gExit
:= EXIT_RESTART
;
5079 // Dead spectator actions
5082 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Fire();
5083 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then
5087 if (FSpectatePlayer
>= High(gPlayers
)) then
5088 FSpectatePlayer
:= -1
5092 for I
:= FSpectatePlayer
+ 1 to High(gPlayers
) do
5093 if gPlayers
[I
] <> nil then
5094 if gPlayers
[I
].alive
then
5095 if gPlayers
[I
].UID
<> FUID
then
5097 FSpectatePlayer
:= I
;
5102 if not SetSpect
then FSpectatePlayer
:= -1;
5113 if FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_JUMP
].Pressed
then
5115 FYTo
:= FObj
.Y
- 32;
5116 FSpectatePlayer
:= -1;
5118 if FKeys
[KEY_DOWN
].Pressed
then
5120 FYTo
:= FObj
.Y
+ 32;
5121 FSpectatePlayer
:= -1;
5123 if FKeys
[KEY_LEFT
].Pressed
then
5125 FXTo
:= FObj
.X
- 32;
5126 FSpectatePlayer
:= -1;
5128 if FKeys
[KEY_RIGHT
].Pressed
then
5130 FXTo
:= FObj
.X
+ 32;
5131 FSpectatePlayer
:= -1;
5134 if (FXTo
< -64) then
5136 else if (FXTo
> gMapInfo
.Width
+ 32) then
5137 FXTo
:= gMapInfo
.Width
+ 32;
5138 if (FYTo
< -72) then
5140 else if (FYTo
> gMapInfo
.Height
+ 32) then
5141 FYTo
:= gMapInfo
.Height
+ 32;
5146 if not followCorpse() then
5147 g_Obj_Move(@FObj
, True, True, True);
5148 positionChanged(); // this updates spatial accelerators
5155 if (FSpectatePlayer
<= High(gPlayers
)) and (FSpectatePlayer
>= 0) then
5156 if gPlayers
[FSpectatePlayer
] <> nil then
5157 if gPlayers
[FSpectatePlayer
].alive
then
5159 FXTo
:= gPlayers
[FSpectatePlayer
].GameX
;
5160 FYTo
:= gPlayers
[FSpectatePlayer
].GameY
;
5164 blockmon
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
, FObj
.Y
+PLAYER_HEADRECT
.Y
,
5165 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
5166 PANEL_BLOCKMON
, True);
5167 headwater
:= HeadInLiquid(0, 0);
5169 // Ñîïðîòèâëåíèå âîçäóõà:
5170 if (not FAlive
) or not (FKeys
[KEY_LEFT
].Pressed
or FKeys
[KEY_RIGHT
].Pressed
) then
5171 if FObj
.Vel
.X
<> 0 then
5172 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
5174 if (FLastHit
= HIT_TRAP
) and (FPain
> 90) then FPain
:= 90;
5175 DecMin(FPain
, 5, 0);
5176 DecMin(FPickup
, 1, 0);
5178 if FAlive
and (FObj
.Y
> Integer(gMapInfo
.Height
)+128) and AnyServer
then
5180 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
5181 FMegaRulez
[MR_SUIT
] := 0;
5182 FMegaRulez
[MR_INVUL
] := 0;
5183 FMegaRulez
[MR_INVIS
] := 0;
5184 Kill(K_FALLKILL
, 0, HIT_FALL
);
5191 if FCurrWeap
= WEAPON_SAW
then
5192 if not (FSawSound
.IsPlaying() or FSawSoundHit
.IsPlaying() or
5193 FSawSoundSelect
.IsPlaying()) then
5194 FSawSoundIdle
.PlayAt(FObj
.X
, FObj
.Y
);
5197 if (not FJetSoundFly
.IsPlaying()) and (not FJetSoundOn
.IsPlaying()) and
5198 (not FJetSoundOff
.IsPlaying()) then
5200 FJetSoundFly
.SetPosition(0);
5201 FJetSoundFly
.PlayAt(FObj
.X
, FObj
.Y
);
5204 for b
:= WP_FIRST
to WP_LAST
do
5205 if FReloading
[b
] > 0 then
5211 if FShellTimer
> -1 then
5212 if FShellTimer
= 0 then
5214 if FShellType
= SHELL_SHELL
then
5215 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5216 GameVelX
, GameVelY
-2, SHELL_SHELL
)
5217 else if FShellType
= SHELL_DBLSHELL
then
5219 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5220 GameVelX
+1, GameVelY
-2, SHELL_SHELL
);
5221 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5222 GameVelX
-1, GameVelY
-2, SHELL_SHELL
);
5225 end else Dec(FShellTimer
);
5227 if (FBFGFireCounter
> -1) then
5228 if FBFGFireCounter
= 0 then
5232 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
5233 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
5234 xd
:= wx
+IfThen(FDirection
= TDirection
.D_LEFT
, -30, 30);
5235 yd
:= wy
+firediry();
5236 g_Weapon_bfgshot(wx
, wy
, xd
, yd
, FUID
);
5237 if NetServer
then MH_SEND_PlayerFire(FUID
, WEAPON_BFG
, wx
, wy
, xd
, yd
);
5238 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
5239 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
5240 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
5243 FReloading
[WEAPON_BFG
] := WEAPON_RELOAD
[WEAPON_BFG
];
5244 FBFGFireCounter
:= -1;
5247 FBFGFireCounter
:= 0
5249 Dec(FBFGFireCounter
);
5251 if (FMegaRulez
[MR_SUIT
] < gTime
) and AnyServer
then
5253 b
:= g_GetAcidHit(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
);
5255 if (b
> 0) and (gTime
mod (15*GAME_TICK
) = 0) then Damage(b
, 0, 0, 0, HIT_ACID
);
5258 if (headwater
or blockmon
) then
5264 if AnyServer
then Damage(10, 0, 0, 0, HIT_WATER
);
5267 else if (FAir
mod 31 = 0) and not blockmon
then
5269 g_GFX_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2), FObj
.Y
+PLAYER_RECT
.Y
-4, 5+Random(6), 8, 4);
5270 if Random(2) = 0 then
5271 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
5273 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
5275 end else if FAir
< AIR_DEF
then
5278 if FFireTime
> 0 then
5280 if BodyInLiquid(0, 0) then
5285 else if FMegaRulez
[MR_SUIT
] >= gTime
then
5287 if FMegaRulez
[MR_SUIT
] = gTime
then
5294 if FFirePainTime
<= 0 then
5296 if g_Game_IsServer
then
5297 Damage(2, FFireAttacker
, 0, 0, HIT_FLAME
);
5298 FFirePainTime
:= 12 - FFireTime
div 12;
5300 FFirePainTime
:= FFirePainTime
- 1;
5301 FFireTime
:= FFireTime
- 1;
5302 if ((FFireTime
mod 33) = 0) and (FMegaRulez
[MR_INVUL
] < gTime
) then
5303 FModel
.PlaySound(MODELSOUND_PAIN
, 1, FObj
.X
, FObj
.Y
);
5304 if (FFireTime
= 0) and g_Game_IsNet
and g_Game_IsServer
then
5305 MH_SEND_PlayerStats(FUID
);
5309 if FDamageBuffer
> 0 then
5311 if FDamageBuffer
>= 9 then
5315 if FDamageBuffer
< 30 then i
:= 9
5316 else if FDamageBuffer
< 100 then i
:= 18
5320 ii
:= Round(FDamageBuffer
*FHealth
/ nonz(FArmor
*(3/4)+FHealth
));
5321 FArmor
:= FArmor
-(FDamageBuffer
-ii
);
5322 FHealth
:= FHealth
-ii
;
5325 FHealth
:= FHealth
+FArmor
;
5330 if FHealth
<= 0 then
5331 if FHealth
> -30 then Kill(K_SIMPLEKILL
, FLastSpawnerUID
, FLastHit
)
5332 else if FHealth
> -50 then Kill(K_HARDKILL
, FLastSpawnerUID
, FLastHit
)
5333 else Kill(K_EXTRAHARDKILL
, FLastSpawnerUID
, FLastHit
);
5335 if FAlive
and ((FLastHit
<> HIT_FLAME
) or (FFireTime
<= 0)) then
5337 if FDamageBuffer
<= 20 then FModel
.PlaySound(MODELSOUND_PAIN
, 1, FObj
.X
, FObj
.Y
)
5338 else if FDamageBuffer
<= 55 then FModel
.PlaySound(MODELSOUND_PAIN
, 2, FObj
.X
, FObj
.Y
)
5339 else if FDamageBuffer
<= 120 then FModel
.PlaySound(MODELSOUND_PAIN
, 3, FObj
.X
, FObj
.Y
)
5340 else FModel
.PlaySound(MODELSOUND_PAIN
, 4, FObj
.X
, FObj
.Y
);
5347 end; // if FAlive then ...
5349 if (FActionAnim
= A_PAIN
) and (FModel
.Animation
<> A_PAIN
) then
5351 FModel
.ChangeAnimation(FActionAnim
, FActionForce
);
5352 FModel
.GetCurrentAnimation
.MinLength
:= i
;
5353 FModel
.GetCurrentAnimationMask
.MinLength
:= i
;
5354 end else FModel
.ChangeAnimation(FActionAnim
, FActionForce
and (FModel
.Animation
<> A_STAND
));
5356 if (FModel
.GetCurrentAnimation
.Played
or ((not FActionChanged
) and (FModel
.Animation
= A_WALK
)))
5357 then SetAction(A_STAND
, True);
5359 if not ((FModel
.Animation
= A_WALK
) and (Abs(FObj
.Vel
.X
) < 4) and not FModel
.Fire
) then FModel
.Update
;
5361 for b
:= Low(FKeys
) to High(FKeys
) do
5362 if FKeys
[b
].Time
= 0 then FKeys
[b
].Pressed
:= False else Dec(FKeys
[b
].Time
);
5366 procedure TPlayer
.getMapBox (out x
, y
, w
, h
: Integer); inline;
5368 x
:= FObj
.X
+PLAYER_RECT
.X
;
5369 y
:= FObj
.Y
+PLAYER_RECT
.Y
;
5370 w
:= PLAYER_RECT
.Width
;
5371 h
:= PLAYER_RECT
.Height
;
5375 procedure TPlayer
.moveBy (dx
, dy
: Integer); inline;
5377 if (dx
<> 0) or (dy
<> 0) then
5386 function TPlayer
.Collide(X
, Y
: Integer; Width
, Height
: Word): Boolean;
5388 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
5389 FObj
.Y
+PLAYER_RECT
.Y
,
5396 function TPlayer
.Collide(Panel
: TPanel
): Boolean;
5398 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
5399 FObj
.Y
+PLAYER_RECT
.Y
,
5403 Panel
.Width
, Panel
.Height
);
5406 function TPlayer
.Collide(X
, Y
: Integer): Boolean;
5408 X
:= X
-FObj
.X
-PLAYER_RECT
.X
;
5409 Y
:= Y
-FObj
.Y
-PLAYER_RECT
.Y
;
5410 Result
:= (x
>= 0) and (x
<= PLAYER_RECT
.Width
) and
5411 (y
>= 0) and (y
<= PLAYER_RECT
.Height
);
5414 function g_Player_ValidName(Name
: string): Boolean;
5420 if gPlayers
= nil then Exit
;
5422 for a
:= 0 to High(gPlayers
) do
5423 if gPlayers
[a
] <> nil then
5424 if LowerCase(Name
) = LowerCase(gPlayers
[a
].FName
) then
5431 procedure TPlayer
.SetDirection(Direction
: TDirection
);
5435 d
:= FModel
.Direction
;
5437 FModel
.Direction
:= Direction
;
5438 if d
<> Direction
then FModel
.ChangeAnimation(FModel
.Animation
, True);
5440 FDirection
:= Direction
;
5443 function TPlayer
.GetKeys(): Byte;
5447 if R_KEY_RED
in FRulez
then Result
:= KEY_RED
;
5448 if R_KEY_GREEN
in FRulez
then Result
:= Result
or KEY_GREEN
;
5449 if R_KEY_BLUE
in FRulez
then Result
:= Result
or KEY_BLUE
;
5451 if FTeam
= TEAM_RED
then Result
:= Result
or KEY_REDTEAM
;
5452 if FTeam
= TEAM_BLUE
then Result
:= Result
or KEY_BLUETEAM
;
5455 procedure TPlayer
.Use();
5459 if FTime
[T_USE
] > gTime
then Exit
;
5461 g_Triggers_PressR(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
,
5462 PLAYER_RECT
.Height
, FUID
, ACTIVATE_PLAYERPRESS
);
5464 for a
:= 0 to High(gPlayers
) do
5465 if (gPlayers
[a
] <> nil) and (gPlayers
[a
] <> Self
) and
5466 gPlayers
[a
].alive
and SameTeam(FUID
, gPlayers
[a
].FUID
) and
5467 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
5468 FObj
.Rect
.Width
, FObj
.Rect
.Height
, @gPlayers
[a
].FObj
) then
5470 gPlayers
[a
].Touch();
5471 if g_Game_IsNet
and g_Game_IsServer
then
5472 MH_SEND_GameEvent(NET_EV_PLAYER_TOUCH
, gPlayers
[a
].FUID
);
5475 FTime
[T_USE
] := gTime
+120;
5478 procedure TPlayer
.NetFire(Wpn
: Byte; X
, Y
, AX
, AY
: Integer; WID
: Integer = -1);
5482 WX
, WY
, XD
, YD
: Integer;
5494 if R_BERSERK
in FRulez
then
5496 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
5497 locobj
.X
:= FObj
.X
+FObj
.Rect
.X
;
5498 locobj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
5501 locobj
.rect
.Width
:= 39;
5502 locobj
.rect
.Height
:= 52;
5503 locobj
.Vel
.X
:= (xd
-wx
) div 2;
5504 locobj
.Vel
.Y
:= (yd
-wy
) div 2;
5505 locobj
.Accel
.X
:= xd
-wx
;
5506 locobj
.Accel
.y
:= yd
-wy
;
5508 if g_Weapon_Hit(@locobj
, 50, FUID
, HIT_SOME
) <> 0 then
5509 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
5511 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
5515 FPain
:= min(FPain
+ 25, 50);
5517 g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
5522 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
5523 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
5525 FSawSoundSelect
.Stop();
5527 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
5529 else if not FSawSoundHit
.IsPlaying() then
5531 FSawSoundSelect
.Stop();
5532 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
5539 g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', GameX
, Gamey
);
5540 FFireAngle
:= FAngle
;
5542 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5543 GameVelX
, GameVelY
-2, SHELL_BULLET
);
5548 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
5549 FFireAngle
:= FAngle
;
5552 FShellType
:= SHELL_SHELL
;
5557 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN2', Gamex
, Gamey
);
5558 FFireAngle
:= FAngle
;
5561 FShellType
:= SHELL_DBLSHELL
;
5566 g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', Gamex
, Gamey
);
5567 FFireAngle
:= FAngle
;
5569 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5570 GameVelX
, GameVelY
-2, SHELL_BULLET
);
5573 WEAPON_ROCKETLAUNCHER
:
5575 g_Weapon_Rocket(wx
, wy
, xd
, yd
, FUID
, WID
);
5576 FFireAngle
:= FAngle
;
5582 g_Weapon_Plasma(wx
, wy
, xd
, yd
, FUID
, WID
);
5583 FFireAngle
:= FAngle
;
5589 g_Weapon_BFGShot(wx
, wy
, xd
, yd
, FUID
, WID
);
5590 FFireAngle
:= FAngle
;
5594 WEAPON_SUPERPULEMET
:
5596 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
5597 FFireAngle
:= FAngle
;
5599 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5600 GameVelX
, GameVelY
-2, SHELL_SHELL
);
5603 WEAPON_FLAMETHROWER
:
5605 g_Weapon_flame(wx
, wy
, xd
, yd
, FUID
, WID
);
5607 FFireAngle
:= FAngle
;
5614 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
5615 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
5616 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
5619 procedure TPlayer
.DoLerp(Level
: Integer = 2);
5621 if FObj
.X
<> FXTo
then FObj
.X
:= Lerp(FObj
.X
, FXTo
, Level
);
5622 if FObj
.Y
<> FYTo
then FObj
.Y
:= Lerp(FObj
.Y
, FYTo
, Level
);
5625 procedure TPlayer
.SetLerp(XTo
, YTo
: Integer);
5629 if NetInterpLevel
< 1 then
5639 AX
:= Abs(FXTo
- FObj
.X
);
5640 AY
:= Abs(FYTo
- FObj
.Y
);
5641 if (AX
> 32) or (AX
<= NetInterpLevel
) then
5643 if (AY
> 32) or (AY
<= NetInterpLevel
) then
5648 function TPlayer
.FullInLift(XInc
, YInc
: Integer): Integer;
5650 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5651 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5652 PANEL_LIFTUP
, False) then Result
:= -1
5654 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5655 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5656 PANEL_LIFTDOWN
, False) then Result
:= 1
5660 function TPlayer
.GetFlag(Flag
: Byte): Boolean;
5667 if Flag
= FLAG_NONE
then
5670 if not g_Game_IsServer
then Exit
;
5672 // Ïðèíåñ ÷óæîé ôëàã íà ñâîþ áàçó:
5673 if (Flag
= FTeam
) and
5674 (gFlags
[Flag
].State
= FLAG_STATE_NORMAL
) and
5675 (FFlag
<> FLAG_NONE
) then
5677 if FFlag
= FLAG_RED
then
5678 s
:= _lc
[I_PLAYER_FLAG_RED
]
5680 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5682 evtype
:= FLAG_STATE_SCORED
;
5684 ts
:= Format('%.4d', [gFlags
[FFlag
].CaptureTime
]);
5685 Insert('.', ts
, Length(ts
) + 1 - 3);
5686 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_CAPTURE
], [FName
, s
, ts
]), True);
5688 g_Map_ResetFlag(FFlag
);
5689 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_CAPTURE
], [AnsiUpperCase(s
)]), 144);
5691 if ((Self
= gPlayer1
) or (Self
= gPlayer2
)
5692 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= FTeam
))
5693 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= FTeam
))) then
5698 if not sound_cap_flag
[a
].IsPlaying() then
5699 sound_cap_flag
[a
].Play();
5701 gTeamStat
[FTeam
].Goals
:= gTeamStat
[FTeam
].Goals
+ 1;
5704 if g_Game_IsNet
then
5706 MH_SEND_FlagEvent(evtype
, FFlag
, FUID
, False);
5710 gFlags
[FFlag
].CaptureTime
:= 0;
5715 // Ïîäîáðàë ñâîé ôëàã - âåðíóë åãî íà áàçó:
5716 if (Flag
= FTeam
) and
5717 (gFlags
[Flag
].State
= FLAG_STATE_DROPPED
) then
5719 if Flag
= FLAG_RED
then
5720 s
:= _lc
[I_PLAYER_FLAG_RED
]
5722 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5724 evtype
:= FLAG_STATE_RETURNED
;
5725 gFlags
[Flag
].CaptureTime
:= 0;
5727 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_RETURN
], [FName
, s
]), True);
5729 g_Map_ResetFlag(Flag
);
5730 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
5732 if ((Self
= gPlayer1
) or (Self
= gPlayer2
)
5733 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= FTeam
))
5734 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= FTeam
))) then
5739 if not sound_ret_flag
[a
].IsPlaying() then
5740 sound_ret_flag
[a
].Play();
5743 if g_Game_IsNet
then
5745 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5751 // Ïîäîáðàë ÷óæîé ôëàã:
5752 if (Flag
<> FTeam
) and (FTime
[T_FLAGCAP
] <= gTime
) then
5756 if Flag
= FLAG_RED
then
5757 s
:= _lc
[I_PLAYER_FLAG_RED
]
5759 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5761 evtype
:= FLAG_STATE_CAPTURED
;
5763 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_GET
], [FName
, s
]), True);
5765 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_GET
], [AnsiUpperCase(s
)]), 144);
5767 gFlags
[Flag
].State
:= FLAG_STATE_CAPTURED
;
5769 if ((Self
= gPlayer1
) or (Self
= gPlayer2
)
5770 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= FTeam
))
5771 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= FTeam
))) then
5776 if not sound_get_flag
[a
].IsPlaying() then
5777 sound_get_flag
[a
].Play();
5780 if g_Game_IsNet
then
5782 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5788 procedure TPlayer
.SetFlag(Flag
: Byte);
5791 if FModel
<> nil then
5792 FModel
.SetFlag(FFlag
);
5795 function TPlayer
.DropFlag(Silent
: Boolean = True): Boolean;
5801 if (not g_Game_IsServer
) or (FFlag
= FLAG_NONE
) then
5803 FTime
[T_FLAGCAP
] := gTime
+ 2000;
5804 with gFlags
[FFlag
] do
5808 Direction
:= FDirection
;
5809 State
:= FLAG_STATE_DROPPED
;
5811 g_Obj_Push(@Obj
, (FObj
.Vel
.X
div 2)-2+Random(5),
5812 (FObj
.Vel
.Y
div 2)-2+Random(5));
5813 positionChanged(); // this updates spatial accelerators
5815 if FFlag
= FLAG_RED
then
5816 s
:= _lc
[I_PLAYER_FLAG_RED
]
5818 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5820 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_DROP
], [FName
, s
]), True);
5821 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_DROP
], [AnsiUpperCase(s
)]), 144);
5823 if ((Self
= gPlayer1
) or (Self
= gPlayer2
)
5824 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= FTeam
))
5825 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= FTeam
))) then
5830 if (not Silent
) and (not sound_lost_flag
[a
].IsPlaying()) then
5831 sound_lost_flag
[a
].Play();
5833 if g_Game_IsNet
then
5834 MH_SEND_FlagEvent(FLAG_STATE_DROPPED
, Flag
, FUID
, False);
5840 procedure TPlayer
.GetSecret();
5842 if (self
= gPlayer1
) or (self
= gPlayer2
) then
5844 g_Console_Add(Format(_lc
[I_PLAYER_SECRET
], [FName
]), True);
5845 g_Sound_PlayEx('SOUND_GAME_SECRET');
5850 procedure TPlayer
.PressKey(Key
: Byte; Time
: Word = 1);
5852 Assert(Key
<= High(FKeys
));
5854 FKeys
[Key
].Pressed
:= True;
5855 FKeys
[Key
].Time
:= Time
;
5858 function TPlayer
.IsKeyPressed(K
: Byte): Boolean;
5860 Result
:= FKeys
[K
].Pressed
;
5863 procedure TPlayer
.ReleaseKeys();
5867 for a
:= Low(FKeys
) to High(FKeys
) do
5869 FKeys
[a
].Pressed
:= False;
5874 procedure TPlayer
.OnDamage(Angle
: SmallInt);
5878 function TPlayer
.firediry(): Integer;
5880 if FKeys
[KEY_UP
].Pressed
then Result
:= -42
5881 else if FKeys
[KEY_DOWN
].Pressed
then Result
:= 19
5885 procedure TPlayer
.RememberState();
5889 FSavedState
.Health
:= FHealth
;
5890 FSavedState
.Armor
:= FArmor
;
5891 FSavedState
.Air
:= FAir
;
5892 FSavedState
.JetFuel
:= FJetFuel
;
5893 FSavedState
.CurrWeap
:= FCurrWeap
;
5894 FSavedState
.NextWeap
:= FNextWeap
;
5895 FSavedState
.NextWeapDelay
:= FNextWeapDelay
;
5898 FSavedState
.Ammo
[i
] := FAmmo
[i
];
5900 FSavedState
.MaxAmmo
[i
] := FMaxAmmo
[i
];
5902 FSavedState
.Rulez
:= FRulez
;
5903 FSavedState
.WaitRecall
:= True;
5906 procedure TPlayer
.RecallState();
5910 if not FSavedState
.WaitRecall
then Exit
;
5912 FHealth
:= FSavedState
.Health
;
5913 FArmor
:= FSavedState
.Armor
;
5914 FAir
:= FSavedState
.Air
;
5915 FJetFuel
:= FSavedState
.JetFuel
;
5916 FCurrWeap
:= FSavedState
.CurrWeap
;
5917 FNextWeap
:= FSavedState
.NextWeap
;
5918 FNextWeapDelay
:= FSavedState
.NextWeapDelay
;
5921 FAmmo
[i
] := FSavedState
.Ammo
[i
];
5923 FMaxAmmo
[i
] := FSavedState
.MaxAmmo
[i
];
5925 FRulez
:= FSavedState
.Rulez
;
5926 FSavedState
.WaitRecall
:= False;
5928 if gGameSettings
.GameType
= GT_SERVER
then
5929 MH_SEND_PlayerStats(FUID
);
5932 procedure TPlayer
.SaveState (st
: TStream
);
5938 utils
.writeSign(st
, 'PLYR');
5939 utils
.writeInt(st
, Byte(PLR_SAVE_VERSION
)); // version
5941 utils
.writeBool(st
, FIamBot
);
5943 utils
.writeInt(st
, Word(FUID
));
5945 utils
.writeStr(st
, FName
);
5947 utils
.writeInt(st
, Byte(FTeam
));
5949 utils
.writeBool(st
, FAlive
);
5950 // Èçðàñõîäîâàë ëè âñå æèçíè
5951 utils
.writeBool(st
, FNoRespawn
);
5953 if FDirection
= TDirection
.D_LEFT
then b
:= 1 else b
:= 2; // D_RIGHT
5954 utils
.writeInt(st
, Byte(b
));
5956 utils
.writeInt(st
, LongInt(FHealth
));
5957 // Êîýôôèöèåíò èíâàëèäíîñòè
5958 utils
.writeInt(st
, LongInt(FHandicap
));
5960 utils
.writeInt(st
, Byte(FLives
));
5962 utils
.writeInt(st
, LongInt(FArmor
));
5964 utils
.writeInt(st
, LongInt(FAir
));
5966 utils
.writeInt(st
, LongInt(FJetFuel
));
5968 utils
.writeInt(st
, LongInt(FPain
));
5970 utils
.writeInt(st
, LongInt(FKills
));
5972 utils
.writeInt(st
, LongInt(FMonsterKills
));
5974 utils
.writeInt(st
, LongInt(FFrags
));
5976 utils
.writeInt(st
, Byte(FFragCombo
));
5977 // Âðåìÿ ïîñëåäíåãî ôðàãà
5978 utils
.writeInt(st
, LongWord(FLastFrag
));
5980 utils
.writeInt(st
, LongInt(FDeath
));
5982 utils
.writeInt(st
, Byte(FFlag
));
5984 utils
.writeInt(st
, LongInt(FSecrets
));
5986 utils
.writeInt(st
, Byte(FCurrWeap
));
5988 utils
.writeInt(st
, Word(FNextWeap
));
5990 utils
.writeInt(st
, Byte(FNextWeapDelay
));
5991 // Âðåìÿ çàðÿäêè BFG
5992 utils
.writeInt(st
, SmallInt(FBFGFireCounter
));
5994 utils
.writeInt(st
, LongInt(FDamageBuffer
));
5995 // Ïîñëåäíèé óäàðèâøèé
5996 utils
.writeInt(st
, Word(FLastSpawnerUID
));
5997 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà
5998 utils
.writeInt(st
, Byte(FLastHit
));
6000 Obj_SaveState(st
, @FObj
);
6001 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ
6002 for i
:= A_BULLETS
to A_HIGH
do utils
.writeInt(st
, Word(FAmmo
[i
]));
6003 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ
6004 for i
:= A_BULLETS
to A_HIGH
do utils
.writeInt(st
, Word(FMaxAmmo
[i
]));
6006 for i
:= WP_FIRST
to WP_LAST
do utils
.writeBool(st
, FWeapon
[i
]);
6007 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ
6008 for i
:= WP_FIRST
to WP_LAST
do utils
.writeInt(st
, Word(FReloading
[i
]));
6010 utils
.writeBool(st
, (R_ITEM_BACKPACK
in FRulez
));
6011 // Íàëè÷èå êðàñíîãî êëþ÷à
6012 utils
.writeBool(st
, (R_KEY_RED
in FRulez
));
6013 // Íàëè÷èå çåëåíîãî êëþ÷à
6014 utils
.writeBool(st
, (R_KEY_GREEN
in FRulez
));
6015 // Íàëè÷èå ñèíåãî êëþ÷à
6016 utils
.writeBool(st
, (R_KEY_BLUE
in FRulez
));
6018 utils
.writeBool(st
, (R_BERSERK
in FRulez
));
6019 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ
6020 for i
:= MR_SUIT
to MR_MAX
do utils
.writeInt(st
, LongWord(FMegaRulez
[i
]));
6021 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà
6022 for i
:= T_RESPAWN
to T_FLAGCAP
do utils
.writeInt(st
, LongWord(FTime
[i
]));
6024 utils
.writeStr(st
, FModel
.Name
);
6026 utils
.writeInt(st
, Byte(FColor
.R
));
6027 utils
.writeInt(st
, Byte(FColor
.G
));
6028 utils
.writeInt(st
, Byte(FColor
.B
));
6032 procedure TPlayer
.LoadState (st
: TStream
);
6041 if not utils
.checkSign(st
, 'PLYR') then raise XStreamError
.Create('invalid player signature');
6042 if (utils
.readByte(st
) <> PLR_SAVE_VERSION
) then raise XStreamError
.Create('invalid player version');
6044 FIamBot
:= utils
.readBool(st
);
6046 FUID
:= utils
.readWord(st
);
6048 str
:= utils
.readStr(st
);
6049 if (self
<> gPlayer1
) and (self
<> gPlayer2
) then FName
:= str
;
6051 FTeam
:= utils
.readByte(st
);
6053 FAlive
:= utils
.readBool(st
);
6054 // Èçðàñõîäîâàë ëè âñå æèçíè
6055 FNoRespawn
:= utils
.readBool(st
);
6057 b
:= utils
.readByte(st
);
6058 if b
= 1 then FDirection
:= TDirection
.D_LEFT
else FDirection
:= TDirection
.D_RIGHT
; // b = 2
6060 FHealth
:= utils
.readLongInt(st
);
6061 // Êîýôôèöèåíò èíâàëèäíîñòè
6062 FHandicap
:= utils
.readLongInt(st
);
6064 FLives
:= utils
.readByte(st
);
6066 FArmor
:= utils
.readLongInt(st
);
6068 FAir
:= utils
.readLongInt(st
);
6070 FJetFuel
:= utils
.readLongInt(st
);
6072 FPain
:= utils
.readLongInt(st
);
6074 FKills
:= utils
.readLongInt(st
);
6076 FMonsterKills
:= utils
.readLongInt(st
);
6078 FFrags
:= utils
.readLongInt(st
);
6080 FFragCombo
:= utils
.readByte(st
);
6081 // Âðåìÿ ïîñëåäíåãî ôðàãà
6082 FLastFrag
:= utils
.readLongWord(st
);
6084 FDeath
:= utils
.readLongInt(st
);
6086 FFlag
:= utils
.readByte(st
);
6088 FSecrets
:= utils
.readLongInt(st
);
6090 FCurrWeap
:= utils
.readByte(st
);
6092 FNextWeap
:= utils
.readWord(st
);
6094 FNextWeapDelay
:= utils
.readByte(st
);
6095 // Âðåìÿ çàðÿäêè BFG
6096 FBFGFireCounter
:= utils
.readSmallInt(st
);
6098 FDamageBuffer
:= utils
.readLongInt(st
);
6099 // Ïîñëåäíèé óäàðèâøèé
6100 FLastSpawnerUID
:= utils
.readWord(st
);
6101 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà
6102 FLastHit
:= utils
.readByte(st
);
6104 Obj_LoadState(@FObj
, st
);
6105 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ
6106 for i
:= A_BULLETS
to A_HIGH
do FAmmo
[i
] := utils
.readWord(st
);
6107 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ
6108 for i
:= A_BULLETS
to A_HIGH
do FMaxAmmo
[i
] := utils
.readWord(st
);
6110 for i
:= WP_FIRST
to WP_LAST
do FWeapon
[i
] := utils
.readBool(st
);
6111 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ
6112 for i
:= WP_FIRST
to WP_LAST
do FReloading
[i
] := utils
.readWord(st
);
6114 if utils
.readBool(st
) then Include(FRulez
, R_ITEM_BACKPACK
);
6115 // Íàëè÷èå êðàñíîãî êëþ÷à
6116 if utils
.readBool(st
) then Include(FRulez
, R_KEY_RED
);
6117 // Íàëè÷èå çåëåíîãî êëþ÷à
6118 if utils
.readBool(st
) then Include(FRulez
, R_KEY_GREEN
);
6119 // Íàëè÷èå ñèíåãî êëþ÷à
6120 if utils
.readBool(st
) then Include(FRulez
, R_KEY_BLUE
);
6122 if utils
.readBool(st
) then Include(FRulez
, R_BERSERK
);
6123 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ
6124 for i
:= MR_SUIT
to MR_MAX
do FMegaRulez
[i
] := utils
.readLongWord(st
);
6125 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà
6126 for i
:= T_RESPAWN
to T_FLAGCAP
do FTime
[i
] := utils
.readLongWord(st
);
6128 str
:= utils
.readStr(st
);
6130 FColor
.R
:= utils
.readByte(st
);
6131 FColor
.G
:= utils
.readByte(st
);
6132 FColor
.B
:= utils
.readByte(st
);
6133 if (self
= gPlayer1
) then
6135 str
:= gPlayer1Settings
.Model
;
6136 FColor
:= gPlayer1Settings
.Color
;
6138 else if (self
= gPlayer2
) then
6140 str
:= gPlayer2Settings
.Model
;
6141 FColor
:= gPlayer2Settings
.Color
;
6143 // Îáíîâëÿåì ìîäåëü èãðîêà
6145 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
6146 FModel
.Color
:= TEAMCOLOR
[FTeam
]
6148 FModel
.Color
:= FColor
;
6152 procedure TPlayer
.AllRulez(Health
: Boolean);
6158 FHealth
:= PLAYER_HP_LIMIT
;
6159 FArmor
:= PLAYER_AP_LIMIT
;
6163 for a
:= WP_FIRST
to WP_LAST
do FWeapon
[a
] := True;
6164 for a
:= A_BULLETS
to A_HIGH
do FAmmo
[a
] := 30000;
6165 FRulez
:= FRulez
+[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
];
6168 procedure TPlayer
.RestoreHealthArmor();
6170 FHealth
:= PLAYER_HP_LIMIT
;
6171 FArmor
:= PLAYER_AP_LIMIT
;
6174 procedure TPlayer
.FragCombo();
6178 if (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) or g_Game_IsClient
then
6180 if gTime
- FLastFrag
< FRAG_COMBO_TIME
then
6182 if FFragCombo
< 5 then
6184 Param
:= FUID
or (FFragCombo
shl 16);
6185 if (FComboEvnt
>= Low(gDelayedEvents
)) and
6186 (FComboEvnt
<= High(gDelayedEvents
)) and
6187 gDelayedEvents
[FComboEvnt
].Pending
and
6188 (gDelayedEvents
[FComboEvnt
].DEType
= DE_KILLCOMBO
) and
6189 (gDelayedEvents
[FComboEvnt
].DENum
and $FFFF = FUID
) then
6191 gDelayedEvents
[FComboEvnt
].Time
:= gTime
+ 500;
6192 gDelayedEvents
[FComboEvnt
].DENum
:= Param
;
6195 FComboEvnt
:= g_Game_DelayEvent(DE_KILLCOMBO
, 500, Param
);
6203 procedure TPlayer
.GiveItem(ItemType
: Byte);
6207 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
6209 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
6213 if FAir
< AIR_MAX
then
6220 if not (R_BERSERK
in FRulez
) then
6222 Include(FRulez
, R_BERSERK
);
6223 if FBFGFireCounter
< 1 then
6225 FCurrWeap
:= WEAPON_KASTET
;
6227 FModel
.SetWeapon(WEAPON_KASTET
);
6231 FBerserk
:= gTime
+30000;
6233 if FHealth
< PLAYER_HP_SOFT
then
6235 FHealth
:= PLAYER_HP_SOFT
;
6236 FBerserk
:= gTime
+30000;
6241 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
6243 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
6247 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
6249 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
6253 if FJetFuel
< JET_MAX
then
6255 FJetFuel
:= JET_MAX
;
6258 ITEM_MEDKIT_SMALL
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
6259 ITEM_MEDKIT_LARGE
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
6261 ITEM_ARMOR_GREEN
: if FArmor
< PLAYER_AP_SOFT
then FArmor
:= PLAYER_AP_SOFT
;
6262 ITEM_ARMOR_BLUE
: if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
6264 ITEM_SPHERE_BLUE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
6266 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) then
6268 if FHealth
< PLAYER_HP_LIMIT
then FHealth
:= PLAYER_HP_LIMIT
;
6269 if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
6272 ITEM_WEAPON_SAW
: FWeapon
[WEAPON_SAW
] := True;
6273 ITEM_WEAPON_SHOTGUN1
: FWeapon
[WEAPON_SHOTGUN1
] := True;
6274 ITEM_WEAPON_SHOTGUN2
: FWeapon
[WEAPON_SHOTGUN2
] := True;
6275 ITEM_WEAPON_CHAINGUN
: FWeapon
[WEAPON_CHAINGUN
] := True;
6276 ITEM_WEAPON_ROCKETLAUNCHER
: FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
6277 ITEM_WEAPON_PLASMA
: FWeapon
[WEAPON_PLASMA
] := True;
6278 ITEM_WEAPON_BFG
: FWeapon
[WEAPON_BFG
] := True;
6279 ITEM_WEAPON_SUPERPULEMET
: FWeapon
[WEAPON_SUPERPULEMET
] := True;
6280 ITEM_WEAPON_FLAMETHROWER
: FWeapon
[WEAPON_FLAMETHROWER
] := True;
6282 ITEM_AMMO_BULLETS
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
6283 ITEM_AMMO_BULLETS_BOX
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
6284 ITEM_AMMO_SHELLS
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
6285 ITEM_AMMO_SHELLS_BOX
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
6286 ITEM_AMMO_ROCKET
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
6287 ITEM_AMMO_ROCKET_BOX
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
6288 ITEM_AMMO_CELL
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
6289 ITEM_AMMO_CELL_BIG
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
6290 ITEM_AMMO_FUELCAN
: if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
6293 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
6294 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
6295 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
6296 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or
6297 (FMaxAmmo
[A_FUEL
] < AmmoLimits
[1, A_FUEL
]) then
6299 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[1, A_BULLETS
];
6300 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[1, A_SHELLS
];
6301 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[1, A_ROCKETS
];
6302 FMaxAmmo
[A_CELLS
] := AmmoLimits
[1, A_CELLS
];
6303 FMaxAmmo
[A_FUEL
] := AmmoLimits
[1, A_FUEL
];
6305 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
6306 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
6307 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
6308 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
6310 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
6313 ITEM_KEY_RED
: if not (R_KEY_RED
in FRulez
) then Include(FRulez
, R_KEY_RED
);
6314 ITEM_KEY_GREEN
: if not (R_KEY_GREEN
in FRulez
) then Include(FRulez
, R_KEY_GREEN
);
6315 ITEM_KEY_BLUE
: if not (R_KEY_BLUE
in FRulez
) then Include(FRulez
, R_KEY_BLUE
);
6317 ITEM_BOTTLE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
6318 ITEM_HELMET
: if FArmor
< PLAYER_AP_LIMIT
then IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
6323 if g_Game_IsNet
and g_Game_IsServer
then
6324 MH_SEND_PlayerStats(FUID
);
6327 procedure TPlayer
.FlySmoke(Times
: DWORD
= 1);
6332 if (Random(5) = 1) and (Times
= 1) then
6335 if BodyInLiquid(0, 0) then
6337 g_GFX_Bubbles(Obj
.X
+Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2)+Random(3)-1,
6338 Obj
.Y
+Obj
.Rect
.Height
+8, 1, 8, 4);
6339 if Random(2) = 0 then
6340 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
6342 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
6346 if g_Frames_Get(id
, 'FRAMES_SMOKE') then
6348 for i
:= 1 to Times
do
6350 Anim
:= TAnimation
.Create(id
, False, 3);
6352 g_GFX_OnceAnim(Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(Anim
.Width
div 2),
6353 Obj
.Y
+Obj
.Rect
.Height
-4+Random(8+Times
*2), Anim
, ONCEANIM_SMOKE
);
6359 procedure TPlayer
.OnFireFlame(Times
: DWORD
= 1);
6364 if (Random(10) = 1) and (Times
= 1) then
6367 if g_Frames_Get(id
, 'FRAMES_FLAME') then
6369 for i
:= 1 to Times
do
6371 Anim
:= TAnimation
.Create(id
, False, 3);
6373 g_GFX_OnceAnim(Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(Anim
.Width
div 2),
6374 Obj
.Y
+8+Random(8+Times
*2), Anim
, ONCEANIM_SMOKE
);
6380 procedure TPlayer
.PauseSounds(Enable
: Boolean);
6382 FSawSound
.Pause(Enable
);
6383 FSawSoundIdle
.Pause(Enable
);
6384 FSawSoundHit
.Pause(Enable
);
6385 FSawSoundSelect
.Pause(Enable
);
6386 FFlameSoundOn
.Pause(Enable
);
6387 FFlameSoundOff
.Pause(Enable
);
6388 FFlameSoundWork
.Pause(Enable
);
6389 FJetSoundFly
.Pause(Enable
);
6390 FJetSoundOn
.Pause(Enable
);
6391 FJetSoundOff
.Pause(Enable
);
6396 constructor TCorpse
.Create(X
, Y
: Integer; ModelName
: String; aMess
: Boolean);
6401 FObj
.Rect
:= PLAYER_CORPSERECT
;
6402 FModelName
:= ModelName
;
6407 FState
:= CORPSE_STATE_MESS
;
6408 g_PlayerModel_GetAnim(ModelName
, A_DIE2
, FAnimation
, FAnimationMask
);
6412 FState
:= CORPSE_STATE_NORMAL
;
6413 g_PlayerModel_GetAnim(ModelName
, A_DIE1
, FAnimation
, FAnimationMask
);
6417 destructor TCorpse
.Destroy();
6424 function TCorpse
.ObjPtr (): PObj
; inline; begin result
:= @FObj
; end;
6426 procedure TCorpse
.positionChanged (); inline; begin end;
6428 procedure TCorpse
.moveBy (dx
, dy
: Integer); inline;
6430 if (dx
<> 0) or (dy
<> 0) then
6439 procedure TCorpse
.getMapBox (out x
, y
, w
, h
: Integer); inline;
6441 x
:= FObj
.X
+PLAYER_CORPSERECT
.X
;
6442 y
:= FObj
.Y
+PLAYER_CORPSERECT
.Y
;
6443 w
:= PLAYER_CORPSERECT
.Width
;
6444 h
:= PLAYER_CORPSERECT
.Height
;
6448 procedure TCorpse
.Damage(Value
: Word; vx
, vy
: Integer);
6453 if FState
= CORPSE_STATE_REMOVEME
then
6456 FDamage
:= FDamage
+ Value
;
6458 if FDamage
> 150 then
6460 if FAnimation
<> nil then
6465 FState
:= CORPSE_STATE_REMOVEME
;
6467 g_Player_CreateGibs(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
6468 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2),
6469 FModelName
, FColor
);
6470 // Çâóê ìÿñà îò òðóïà:
6471 pm
:= g_PlayerModel_Get(FModelName
);
6472 pm
.PlaySound(MODELSOUND_DIE
, 5, FObj
.X
, FObj
.Y
);
6476 if (gBodyKillEvent
<> -1)
6477 and gDelayedEvents
[gBodyKillEvent
].Pending
then
6478 gDelayedEvents
[gBodyKillEvent
].Pending
:= False;
6479 gBodyKillEvent
:= g_Game_DelayEvent(DE_BODYKILL
, 1050, 0);
6484 Blood
:= g_PlayerModel_GetBlood(FModelName
);
6485 FObj
.Vel
.X
:= FObj
.Vel
.X
+ vx
;
6486 FObj
.Vel
.Y
:= FObj
.Vel
.Y
+ vy
;
6487 g_GFX_Blood(FObj
.X
+PLAYER_CORPSERECT
.X
+(PLAYER_CORPSERECT
.Width
div 2),
6488 FObj
.Y
+PLAYER_CORPSERECT
.Y
+(PLAYER_CORPSERECT
.Height
div 2),
6489 Value
, vx
, vy
, 16, (PLAYER_CORPSERECT
.Height
*2) div 3,
6490 Blood
.R
, Blood
.G
, Blood
.B
, Blood
.Kind
);
6494 procedure TCorpse
.Draw();
6496 if FState
= CORPSE_STATE_REMOVEME
then
6499 if FAnimation
<> nil then
6500 FAnimation
.Draw(FObj
.X
, FObj
.Y
, TMirrorType
.None
);
6502 if FAnimationMask
<> nil then
6505 FAnimationMask
.Draw(FObj
.X
, FObj
.Y
, TMirrorType
.None
);
6512 procedure TCorpse
.Update();
6516 if FState
= CORPSE_STATE_REMOVEME
then
6519 if gTime
mod (GAME_TICK
*2) <> 0 then
6521 g_Obj_Move(@FObj
, True, True, True);
6522 positionChanged(); // this updates spatial accelerators
6526 // Ñîïðîòèâëåíèå âîçäóõà äëÿ òðóïà:
6527 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
6529 st
:= g_Obj_Move(@FObj
, True, True, True);
6530 positionChanged(); // this updates spatial accelerators
6532 if WordBool(st
and MOVE_FALLOUT
) then
6534 FState
:= CORPSE_STATE_REMOVEME
;
6538 if FAnimation
<> nil then
6539 FAnimation
.Update();
6540 if FAnimationMask
<> nil then
6541 FAnimationMask
.Update();
6545 procedure TCorpse
.SaveState (st
: TStream
);
6552 utils
.writeSign(st
, 'CORP');
6553 utils
.writeInt(st
, Byte(0));
6555 utils
.writeInt(st
, Byte(FState
));
6557 utils
.writeInt(st
, Byte(FDamage
));
6559 utils
.writeInt(st
, Byte(FColor
.R
));
6560 utils
.writeInt(st
, Byte(FColor
.G
));
6561 utils
.writeInt(st
, Byte(FColor
.B
));
6563 Obj_SaveState(st
, @FObj
);
6564 utils
.writeInt(st
, Word(FPlayerUID
));
6566 anim
:= (FAnimation
<> nil);
6567 utils
.writeBool(st
, anim
);
6568 // Åñëè åñòü - ñîõðàíÿåì
6569 if anim
then FAnimation
.SaveState(st
);
6570 // Åñòü ëè ìàñêà àíèìàöèè
6571 anim
:= (FAnimationMask
<> nil);
6572 utils
.writeBool(st
, anim
);
6573 // Åñëè åñòü - ñîõðàíÿåì
6574 if anim
then FAnimationMask
.SaveState(st
);
6578 procedure TCorpse
.LoadState (st
: TStream
);
6585 if not utils
.checkSign(st
, 'CORP') then raise XStreamError
.Create('invalid corpse signature');
6586 if (utils
.readByte(st
) <> 0) then raise XStreamError
.Create('invalid corpse version');
6588 FState
:= utils
.readByte(st
);
6590 FDamage
:= utils
.readByte(st
);
6592 FColor
.R
:= utils
.readByte(st
);
6593 FColor
.G
:= utils
.readByte(st
);
6594 FColor
.B
:= utils
.readByte(st
);
6596 Obj_LoadState(@FObj
, st
);
6597 FPlayerUID
:= utils
.readWord(st
);
6599 anim
:= utils
.readBool(st
);
6600 // Åñëè åñòü - çàãðóæàåì
6603 Assert(FAnimation
<> nil, 'TCorpse.LoadState: no FAnimation');
6604 FAnimation
.LoadState(st
);
6606 // Åñòü ëè ìàñêà àíèìàöèè
6607 anim
:= utils
.readBool(st
);
6608 // Åñëè åñòü - çàãðóæàåì
6611 Assert(FAnimationMask
<> nil, 'TCorpse.LoadState: no FAnimationMask');
6612 FAnimationMask
.LoadState(st
);
6618 constructor TBot
.Create();
6625 FSpectator
:= False;
6632 for a
:= WP_FIRST
to WP_LAST
do
6634 FDifficult
.WeaponPrior
[a
] := WEAPON_PRIOR1
[a
];
6635 FDifficult
.CloseWeaponPrior
[a
] := WEAPON_PRIOR2
[a
];
6636 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
6640 destructor TBot
.Destroy();
6643 inherited Destroy();
6646 procedure TBot
.Draw();
6650 //if FTargetUID <> 0 then e_DrawLine(1, FObj.X, FObj.Y, g_Player_Get(FTargetUID).FObj.X,
6651 // g_Player_Get(FTargetUID).FObj.Y, 255, 0, 0);
6654 procedure TBot
.Respawn(Silent
: Boolean; Force
: Boolean = False);
6656 inherited Respawn(Silent
, Force
);
6659 FSelectedWeapon
:= FCurrWeap
;
6664 procedure TBot
.UpdateCombat();
6677 TTargetRecord
= array of TTarget
;
6679 function Compare(a
, b
: TTarget
): Integer;
6681 if a
.Line
and not b
.Line
then // A íà ëèíèè îãíÿ
6684 if not a
.Line
and b
.Line
then // B íà ëèíèè îãíÿ
6686 else // È A, è B íà ëèíèè èëè íå íà ëèíèè îãíÿ
6687 if (a
.Line
and b
.Line
) or ((not a
.Line
) and (not b
.Line
)) then
6689 if a
.Dist
> b
.Dist
then // B áëèæå
6691 else // A áëèæå èëè ðàâíîóäàëåííî ñ B
6694 else // Ñòðàííî -> A
6699 a
, x1
, y1
, x2
, y2
: Integer;
6700 targets
: TTargetRecord
;
6702 Target
, BestTarget
: TTarget
;
6703 firew
, fireh
: Integer;
6707 vsPlayer
, vsMonster
, ok
: Boolean;
6710 function monsUpdate (mon
: TMonster
): Boolean;
6712 result
:= false; // don't stop
6713 if mon
.alive
and (mon
.MonsterType
<> MONSTER_BARREL
) then
6715 if not TargetOnScreen(mon
.Obj
.X
+mon
.Obj
.Rect
.X
, mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
) then exit
;
6717 x2
:= mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2);
6718 y2
:= mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+(mon
.Obj
.Rect
.Height
div 2);
6720 // Åñëè ìîíñòð íà ýêðàíå è íå ïðèêðûò ñòåíîé
6721 if g_TraceVector(x1
, y1
, x2
, y2
) then
6723 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé
6724 SetLength(targets
, Length(targets
)+1);
6725 with targets
[High(targets
)] do
6732 Rect
:= mon
.Obj
.Rect
;
6733 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6734 Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6735 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6744 vsPlayer
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
);
6745 vsMonster
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
);
6747 // Åñëè òåêóùåå îðóæèå íå òî, ÷òî íóæíî, òî ìåíÿåì:
6748 if FCurrWeap
<> FSelectedWeapon
then
6751 // Åñëè íóæíî ñòðåëÿòü è íóæíîå îðóæèå, òî íàæàòü "Ñòðåëÿòü":
6752 if (GetAIFlag('NEEDFIRE') <> '') and (FCurrWeap
= FSelectedWeapon
) then
6754 RemoveAIFlag('NEEDFIRE');
6757 WEAPON_PLASMA
, WEAPON_SUPERPULEMET
, WEAPON_CHAINGUN
: PressKey(KEY_FIRE
, 20);
6758 WEAPON_SAW
, WEAPON_KASTET
, WEAPON_FLAMETHROWER
: PressKey(KEY_FIRE
, 40);
6759 else PressKey(KEY_FIRE
);
6763 // Êîîðäèíàòû ñòâîëà:
6764 x1
:= FObj
.X
+ WEAPONPOINT
[FDirection
].X
;
6765 y1
:= FObj
.Y
+ WEAPONPOINT
[FDirection
].Y
;
6767 Target
.UID
:= FTargetUID
;
6770 if Target
.UID
<> 0 then
6771 begin // Öåëü åñòü - íàñòðàèâàåì
6772 if (g_GetUIDType(Target
.UID
) = UID_PLAYER
) and
6775 tpla
:= g_Player_Get(Target
.UID
);
6779 if (@FObj
) <> nil then
6786 Target
.cX
:= Target
.X
+ PLAYER_RECT_CX
;
6787 Target
.cY
:= Target
.Y
+ PLAYER_RECT_CY
;
6788 Target
.Rect
:= PLAYER_RECT
;
6789 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6790 Target
.Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6791 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6792 Target
.IsPlayer
:= True;
6796 if (g_GetUIDType(Target
.UID
) = UID_MONSTER
) and
6799 mon
:= g_Monsters_ByUID(Target
.UID
);
6802 Target
.X
:= mon
.Obj
.X
;
6803 Target
.Y
:= mon
.Obj
.Y
;
6805 Target
.cX
:= Target
.X
+ mon
.Obj
.Rect
.X
+ (mon
.Obj
.Rect
.Width
div 2);
6806 Target
.cY
:= Target
.Y
+ mon
.Obj
.Rect
.Y
+ (mon
.Obj
.Rect
.Height
div 2);
6807 Target
.Rect
:= mon
.Obj
.Rect
;
6808 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6809 Target
.Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6810 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6811 Target
.IsPlayer
:= False;
6818 begin // Öåëè íåò - îáíóëÿåì
6823 Target
.Visible
:= False;
6824 Target
.Line
:= False;
6825 Target
.IsPlayer
:= False;
6830 // Åñëè öåëü íå âèäèìà èëè íå íà ëèíèè îãíÿ, òî èùåì âñå âîçìîæíûå öåëè:
6831 if (not Target
.Line
) or (not Target
.Visible
) then
6835 for a
:= 0 to High(gPlayers
) do
6836 if (gPlayers
[a
] <> nil) and (gPlayers
[a
].alive
) and
6837 (gPlayers
[a
].FUID
<> FUID
) and
6838 (not SameTeam(FUID
, gPlayers
[a
].FUID
)) and
6839 (not gPlayers
[a
].NoTarget
) and
6840 (gPlayers
[a
].FMegaRulez
[MR_INVIS
] < gTime
) then
6842 if not TargetOnScreen(gPlayers
[a
].FObj
.X
+ PLAYER_RECT
.X
,
6843 gPlayers
[a
].FObj
.Y
+ PLAYER_RECT
.Y
) then
6846 x2
:= gPlayers
[a
].FObj
.X
+ PLAYER_RECT_CX
;
6847 y2
:= gPlayers
[a
].FObj
.Y
+ PLAYER_RECT_CY
;
6849 // Åñëè èãðîê íà ýêðàíå è íå ïðèêðûò ñòåíîé:
6850 if g_TraceVector(x1
, y1
, x2
, y2
) then
6852 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé:
6853 SetLength(targets
, Length(targets
)+1);
6854 with targets
[High(targets
)] do
6856 UID
:= gPlayers
[a
].FUID
;
6857 X
:= gPlayers
[a
].FObj
.X
;
6858 Y
:= gPlayers
[a
].FObj
.Y
;
6861 Rect
:= PLAYER_RECT
;
6862 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6863 Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6864 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6872 if vsMonster
then g_Mons_ForEach(monsUpdate
);
6875 // Åñëè åñòü âîçìîæíûå öåëè:
6876 // (Âûáèðàåì ëó÷øóþ, ìåíÿåì îðóæèå è áåæèì ê íåé/îò íåå)
6877 if targets
<> nil then
6879 // Âûáèðàåì íàèëó÷øóþ öåëü:
6880 BestTarget
:= targets
[0];
6881 if Length(targets
) > 1 then
6882 for a
:= 1 to High(targets
) do
6883 if Compare(BestTarget
, targets
[a
]) = 1 then
6884 BestTarget
:= targets
[a
];
6886 // Åñëè ëó÷øàÿ öåëü "âèäíåå" òåêóùåé, òî òåêóùàÿ := ëó÷øàÿ:
6887 if ((not Target
.Visible
) and BestTarget
.Visible
and (Target
.UID
<> BestTarget
.UID
)) or
6888 ((not Target
.Line
) and BestTarget
.Line
and BestTarget
.Visible
) then
6890 Target
:= BestTarget
;
6892 if (Healthy() = 3) or ((Healthy() = 2)) then
6893 begin // Åñëè çäîðîâû - äîãîíÿåì
6894 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
6895 SetAIFlag('GORIGHT', '1');
6896 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6897 SetAIFlag('GOLEFT', '1');
6900 begin // Åñëè ïîáèòû - óáåãàåì
6901 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) then
6902 SetAIFlag('GORIGHT', '1');
6903 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6904 SetAIFlag('GOLEFT', '1');
6907 // Âûáèðàåì îðóæèå íà îñíîâå ðàññòîÿíèÿ è ïðèîðèòåòîâ:
6908 SelectWeapon(Abs(x1
-Target
.cX
));
6913 // (Äîãîíÿåì/óáåãàåì, ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëè)
6914 // (Åñëè öåëü äàëåêî, òî õâàòèò ñëåäèòü çà íåé)
6915 if Target
.UID
<> 0 then
6917 if not TargetOnScreen(Target
.X
+ Target
.Rect
.X
,
6918 Target
.Y
+ Target
.Rect
.Y
) then
6919 begin // Öåëü ñáåæàëà ñ "ýêðàíà"
6920 if (Healthy() = 3) or ((Healthy() = 2)) then
6921 begin // Åñëè çäîðîâû - äîãîíÿåì
6922 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
6923 SetAIFlag('GORIGHT', '1');
6924 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6925 SetAIFlag('GOLEFT', '1');
6928 begin // Åñëè ïîáèòû - çàáûâàåì î öåëè è óáåãàåì
6930 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) then
6931 SetAIFlag('GORIGHT', '1');
6932 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6933 SetAIFlag('GOLEFT', '1');
6937 begin // Öåëü ïîêà íà "ýêðàíå"
6938 // Åñëè öåëü íå çàãîðîæåíà ñòåíîé, òî îòìå÷àåì, êîãäà åå âèäåëè:
6939 if g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6940 FLastVisible
:= gTime
;
6941 // Åñëè ðàçíèöà âûñîò íå âåëèêà, òî äîãîíÿåì:
6942 if (Abs(FObj
.Y
-Target
.Y
) <= 128) then
6944 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
6945 SetAIFlag('GORIGHT', '1');
6946 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6947 SetAIFlag('GOLEFT', '1');
6951 // Âûáèðàåì óãîë ââåðõ:
6952 if FDirection
= TDirection
.D_LEFT
then
6953 angle
:= ANGLE_LEFTUP
6955 angle
:= ANGLE_RIGHTUP
;
6957 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6958 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6960 // Åñëè ïðè óãëå ââåðõ ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
6961 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6962 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128), //96
6963 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6964 Target
.Rect
.Width
, Target
.Rect
.Height
) and
6965 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6966 begin // òî íóæíî ñòðåëÿòü ââåðõ
6967 SetAIFlag('NEEDFIRE', '1');
6968 SetAIFlag('NEEDSEEUP', '1');
6971 // Âûáèðàåì óãîë âíèç:
6972 if FDirection
= TDirection
.D_LEFT
then
6973 angle
:= ANGLE_LEFTDOWN
6975 angle
:= ANGLE_RIGHTDOWN
;
6977 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6978 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6980 // Åñëè ïðè óãëå âíèç ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
6981 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6982 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
6983 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6984 Target
.Rect
.Width
, Target
.Rect
.Height
) and
6985 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6986 begin // òî íóæíî ñòðåëÿòü âíèç
6987 SetAIFlag('NEEDFIRE', '1');
6988 SetAIFlag('NEEDSEEDOWN', '1');
6991 // Åñëè öåëü âèäíî è îíà íà òàêîé æå âûñîòå:
6992 if Target
.Visible
and
6993 (y1
+4 < Target
.Y
+Target
.Rect
.Y
+Target
.Rect
.Height
) and
6994 (y1
-4 > Target
.Y
+Target
.Rect
.Y
) then
6996 // Åñëè èäåì â ñòîðîíó öåëè, òî íàäî ñòðåëÿòü:
6997 if ((FDirection
= TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) or
6998 ((FDirection
= TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6999 begin // òî íóæíî ñòðåëÿòü âïåðåä
7000 SetAIFlag('NEEDFIRE', '1');
7001 SetAIFlag('NEEDSEEDOWN', '');
7002 SetAIFlag('NEEDSEEUP', '');
7004 // Åñëè öåëü â ïðåäåëàõ "ýêðàíà" è ñëîæíîñòü ïîçâîëÿåò ïðûæêè ñáëèæåíèÿ:
7005 if Abs(FObj
.X
-Target
.X
) < Trunc(gPlayerScreenSize
.X
*0.75) then
7006 if GetRnd(FDifficult
.CloseJump
) then
7007 begin // òî åñëè ïîâåçåò - ïðûãàåì (îñîáåííî, åñëè áëèçêî)
7008 if Abs(FObj
.X
-Target
.X
) < 128 then
7012 if Random(a
) = 0 then
7013 SetAIFlag('NEEDJUMP', '1');
7017 // Åñëè öåëü âñå åùå åñòü:
7018 if Target
.UID
<> 0 then
7019 if gTime
-FLastVisible
> 2000 then // Åñëè âèäåëè äàâíî
7020 Target
.UID
:= 0 // òî çàáûòü öåëü
7021 else // Åñëè âèäåëè íåäàâíî
7022 begin // íî öåëü óáèëè
7023 if Target
.IsPlayer
then
7024 begin // Öåëü - èãðîê
7025 pla
:= g_Player_Get(Target
.UID
);
7026 if (pla
= nil) or (not pla
.alive
) or pla
.NoTarget
or
7027 (pla
.FMegaRulez
[MR_INVIS
] >= gTime
) then
7028 Target
.UID
:= 0; // òî çàáûòü öåëü
7031 begin // Öåëü - ìîíñòð
7032 mon
:= g_Monsters_ByUID(Target
.UID
);
7033 if (mon
= nil) or (not mon
.alive
) then
7034 Target
.UID
:= 0; // òî çàáûòü öåëü
7037 end; // if Target.UID <> 0
7039 FTargetUID
:= Target
.UID
;
7041 // Åñëè âîçìîæíûõ öåëåé íåò:
7042 // (Àòàêà ÷åãî-íèáóäü ñëåâà èëè ñïðàâà)
7043 if targets
= nil then
7044 if GetAIFlag('ATTACKLEFT') <> '' then
7045 begin // Åñëè íóæíî àòàêîâàòü íàëåâî
7046 RemoveAIFlag('ATTACKLEFT');
7048 SetAIFlag('NEEDJUMP', '1');
7050 if RunDirection() = TDirection
.D_RIGHT
then
7051 begin // Èäåì íå â òó ñòîðîíó
7052 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
7053 begin // Åñëè çäîðîâû, òî, âîçìîæíî, ñòðåëÿåì áåæèì âëåâî è ñòðåëÿåì
7054 SetAIFlag('NEEDFIRE', '1');
7055 SetAIFlag('GOLEFT', '1');
7059 begin // Èäåì â íóæíóþ ñòîðîíó
7060 if GetRnd(FDifficult
.InvisFire
) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
7061 SetAIFlag('NEEDFIRE', '1');
7062 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
7063 SetAIFlag('GORIGHT', '1');
7067 if GetAIFlag('ATTACKRIGHT') <> '' then
7068 begin // Åñëè íóæíî àòàêîâàòü íàïðàâî
7069 RemoveAIFlag('ATTACKRIGHT');
7071 SetAIFlag('NEEDJUMP', '1');
7073 if RunDirection() = TDirection
.D_LEFT
then
7074 begin // Èäåì íå â òó ñòîðîíó
7075 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
7076 begin // Åñëè çäîðîâû, òî, âîçìîæíî, áåæèì âïðàâî è ñòðåëÿåì
7077 SetAIFlag('NEEDFIRE', '1');
7078 SetAIFlag('GORIGHT', '1');
7083 if GetRnd(FDifficult
.InvisFire
) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
7084 SetAIFlag('NEEDFIRE', '1');
7085 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
7086 SetAIFlag('GOLEFT', '1');
7090 //HACK! (does it belongs there?)
7091 RealizeCurrentWeapon();
7093 // Åñëè åñòü âîçìîæíûå öåëè:
7094 // (Ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëÿì)
7095 if (targets
<> nil) and (GetAIFlag('NEEDFIRE') <> '') then
7096 for a
:= 0 to High(targets
) do
7098 // Åñëè ìîæåì ñòðåëÿòü ïî äèàãîíàëè:
7099 if GetRnd(FDifficult
.DiagFire
) then
7101 // Èùåì öåëü ñâåðõó è ñòðåëÿåì, åñëè åñòü:
7102 if FDirection
= TDirection
.D_LEFT
then
7103 angle
:= ANGLE_LEFTUP
7105 angle
:= ANGLE_RIGHTUP
;
7107 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7108 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7110 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
7111 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
7112 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
7113 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
7114 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
7116 SetAIFlag('NEEDFIRE', '1');
7117 SetAIFlag('NEEDSEEUP', '1');
7120 // Èùåì öåëü ñíèçó è ñòðåëÿåì, åñëè åñòü:
7121 if FDirection
= TDirection
.D_LEFT
then
7122 angle
:= ANGLE_LEFTDOWN
7124 angle
:= ANGLE_RIGHTDOWN
;
7126 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7127 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7129 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
7130 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
7131 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
7132 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
7133 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
7135 SetAIFlag('NEEDFIRE', '1');
7136 SetAIFlag('NEEDSEEDOWN', '1');
7140 // Åñëè öåëü "ïåðåä íîñîì", òî ñòðåëÿåì:
7141 if targets
[a
].Line
and targets
[a
].Visible
and
7142 (((FDirection
= TDirection
.D_LEFT
) and (targets
[a
].X
< FObj
.X
)) or
7143 ((FDirection
= TDirection
.D_RIGHT
) and (targets
[a
].X
> FObj
.X
))) then
7145 SetAIFlag('NEEDFIRE', '1');
7150 // Åñëè ëåòèò ïóëÿ, òî, âîçìîæíî, ïîäïðûãèâàåì:
7151 if g_Weapon_Danger(FUID
, FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
,
7152 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
,
7153 40+GetInterval(FDifficult
.Cover
, 40)) then
7154 SetAIFlag('NEEDJUMP', '1');
7156 // Åñëè êîí÷èëèñü ïàòîðíû, òî íóæíî ñìåíèòü îðóæèå:
7157 ammo
:= GetAmmoByWeapon(FCurrWeap
);
7158 if ((FCurrWeap
= WEAPON_SHOTGUN2
) and (ammo
< 2)) or
7159 ((FCurrWeap
= WEAPON_BFG
) and (ammo
< 40)) or
7161 SetAIFlag('SELECTWEAPON', '1');
7163 // Åñëè íóæíî ñìåíèòü îðóæèå, òî âûáèðàåì íóæíîå:
7164 if GetAIFlag('SELECTWEAPON') = '1' then
7167 RemoveAIFlag('SELECTWEAPON');
7171 procedure TBot
.Update();
7184 // Ïðîâåðÿåì, îòêëþ÷¸í ëè AI áîòîâ
7185 if (g_debug_BotAIOff
= 1) and (Team
= TEAM_RED
) then
7187 if (g_debug_BotAIOff
= 2) and (Team
= TEAM_BLUE
) then
7189 if g_debug_BotAIOff
= 3 then
7199 RealizeCurrentWeapon();
7206 procedure TBot
.ReleaseKey(Key
: Byte);
7215 function TBot
.KeyPressed(Key
: Word): Boolean;
7217 Result
:= FKeys
[Key
].Pressed
;
7220 function TBot
.GetAIFlag(aName
: String20
): String20
;
7226 aName
:= LowerCase(aName
);
7228 if FAIFlags
<> nil then
7229 for a
:= 0 to High(FAIFlags
) do
7230 if LowerCase(FAIFlags
[a
].Name
) = aName
then
7232 Result
:= FAIFlags
[a
].Value
;
7237 procedure TBot
.RemoveAIFlag(aName
: String20
);
7241 if FAIFlags
= nil then Exit
;
7243 aName
:= LowerCase(aName
);
7245 for a
:= 0 to High(FAIFlags
) do
7246 if LowerCase(FAIFlags
[a
].Name
) = aName
then
7248 if a
<> High(FAIFlags
) then
7249 for b
:= a
to High(FAIFlags
)-1 do
7250 FAIFlags
[b
] := FAIFlags
[b
+1];
7252 SetLength(FAIFlags
, Length(FAIFlags
)-1);
7257 procedure TBot
.SetAIFlag(aName
, fValue
: String20
);
7265 aName
:= LowerCase(aName
);
7267 if FAIFlags
<> nil then
7268 for a
:= 0 to High(FAIFlags
) do
7269 if LowerCase(FAIFlags
[a
].Name
) = aName
then
7275 if ok
then FAIFlags
[a
].Value
:= fValue
7278 SetLength(FAIFlags
, Length(FAIFlags
)+1);
7279 with FAIFlags
[High(FAIFlags
)] do
7287 procedure TBot
.UpdateMove
;
7289 procedure GoLeft(Time
: Word = 1);
7291 ReleaseKey(KEY_LEFT
);
7292 ReleaseKey(KEY_RIGHT
);
7293 PressKey(KEY_LEFT
, Time
);
7294 SetDirection(TDirection
.D_LEFT
);
7297 procedure GoRight(Time
: Word = 1);
7299 ReleaseKey(KEY_LEFT
);
7300 ReleaseKey(KEY_RIGHT
);
7301 PressKey(KEY_RIGHT
, Time
);
7302 SetDirection(TDirection
.D_RIGHT
);
7305 function Rnd(a
: Word): Boolean;
7307 Result
:= Random(a
) = 0;
7310 procedure Turn(Time
: Word = 1200);
7312 if RunDirection() = TDirection
.D_LEFT
then GoRight(Time
) else GoLeft(Time
);
7317 ReleaseKey(KEY_LEFT
);
7318 ReleaseKey(KEY_RIGHT
);
7321 function CanRunLeft(): Boolean;
7323 Result
:= not CollideLevel(-1, 0);
7326 function CanRunRight(): Boolean;
7328 Result
:= not CollideLevel(1, 0);
7331 function CanRun(): Boolean;
7333 if RunDirection() = TDirection
.D_LEFT
then Result
:= CanRunLeft() else Result
:= CanRunRight();
7336 procedure Jump(Time
: Word = 30);
7338 PressKey(KEY_JUMP
, Time
);
7341 function NearHole(): Boolean;
7345 { TODO 5 : Ëåñòíèöû }
7346 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7347 for x
:= 1 to PLAYER_RECT
.Width
do
7348 if (not StayOnStep(x
*sx
, 0)) and
7349 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7350 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7359 function BorderHole(): Boolean;
7363 { TODO 5 : Ëåñòíèöû }
7364 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7365 for x
:= 1 to PLAYER_RECT
.Width
do
7366 if (not StayOnStep(x
*sx
, 0)) and
7367 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7368 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7370 for xx
:= x
to x
+32 do
7371 if CollideLevel(xx
*sx
, PLAYER_RECT
.Height
) then
7381 function NearDeepHole(): Boolean;
7387 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7390 for x
:= 1 to PLAYER_RECT
.Width
do
7391 if (not StayOnStep(x
*sx
, 0)) and
7392 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7393 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7395 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
7397 if CollideLevel(x
*sx
, PLAYER_RECT
.Height
*y
) then Exit
;
7402 end else Result
:= False;
7405 function OverDeepHole(): Boolean;
7412 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
7414 if CollideLevel(0, PLAYER_RECT
.Height
*y
) then Exit
;
7421 function OnGround(): Boolean;
7423 Result
:= StayOnStep(0, 0) or CollideLevel(0, 1);
7426 function OnLadder(): Boolean;
7428 Result
:= FullInStep(0, 0);
7431 function BelowLadder(): Boolean;
7433 Result
:= (FullInStep(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) and
7434 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
7435 (FullInStep(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) and
7436 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
7439 function BelowLiftUp(): Boolean;
7441 Result
:= ((FullInLift(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) = -1) and
7442 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
7443 ((FullInLift(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) = -1) and
7444 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
7447 function OnTopLift(): Boolean;
7449 Result
:= (FullInLift(0, 0) = -1) and (FullInLift(0, -32) = 0);
7452 function CanJumpOver(): Boolean;
7456 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7460 if not CollideLevel(sx
, 0) then Exit
;
7462 for y
:= 1 to BOT_MAXJUMP
do
7463 if CollideLevel(0, -y
) then Exit
else
7464 if not CollideLevel(sx
, -y
) then
7471 function CanJumpUp(Dist
: ShortInt): Boolean;
7478 if CollideLevel(Dist
, 0) then Exit
;
7481 for y
:= 0 to BOT_MAXJUMP
do
7482 if CollideLevel(Dist
, -y
) then
7491 for yy
:= y
+1 to BOT_MAXJUMP
do
7492 if not CollideLevel(Dist
, -yy
) then
7501 for y
:= 0 to BOT_MAXJUMP
do
7502 if CollideLevel(0, -y
) then
7510 if y
< yy
then Exit
;
7515 function IsSafeTrigger(): Boolean;
7520 if gTriggers
= nil then
7522 for a
:= 0 to High(gTriggers
) do
7523 if Collide(gTriggers
[a
].X
,
7526 gTriggers
[a
].Height
) and
7527 (gTriggers
[a
].TriggerType
in [TRIGGER_EXIT
, TRIGGER_CLOSEDOOR
,
7528 TRIGGER_CLOSETRAP
, TRIGGER_TRAP
,
7529 TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
,
7530 TRIGGER_ONOFF
, TRIGGER_SPAWNMONSTER
,
7531 TRIGGER_DAMAGE
, TRIGGER_SHOT
]) then
7536 // Âîçìîæíî, íàæèìàåì êíîïêó:
7537 if Rnd(16) and IsSafeTrigger() then
7540 // Åñëè ïîä ëèôòîì èëè ñòóïåíüêàìè, òî, âîçìîæíî, ïðûãàåì:
7541 if OnLadder() or ((BelowLadder() or BelowLiftUp()) and Rnd(8)) then
7543 ReleaseKey(KEY_LEFT
);
7544 ReleaseKey(KEY_RIGHT
);
7548 // Èäåì âëåâî, åñëè íàäî áûëî:
7549 if GetAIFlag('GOLEFT') <> '' then
7551 RemoveAIFlag('GOLEFT');
7552 if CanRunLeft() then
7556 // Èäåì âïðàâî, åñëè íàäî áûëî:
7557 if GetAIFlag('GORIGHT') <> '' then
7559 RemoveAIFlag('GORIGHT');
7560 if CanRunRight() then
7564 // Åñëè âûëåòåëè çà êàðòó, òî ïðîáóåì âåðíóòüñÿ:
7565 if FObj
.X
< -32 then
7568 if FObj
.X
+32 > gMapInfo
.Width
then
7571 // Ïðûãàåì, åñëè íàäî áûëî:
7572 if GetAIFlag('NEEDJUMP') <> '' then
7575 RemoveAIFlag('NEEDJUMP');
7578 // Ñìîòðèì ââåðõ, åñëè íàäî áûëî:
7579 if GetAIFlag('NEEDSEEUP') <> '' then
7582 ReleaseKey(KEY_DOWN
);
7583 PressKey(KEY_UP
, 20);
7584 RemoveAIFlag('NEEDSEEUP');
7587 // Ñìîòðèì âíèç, åñëè íàäî áûëî:
7588 if GetAIFlag('NEEDSEEDOWN') <> '' then
7591 ReleaseKey(KEY_DOWN
);
7592 PressKey(KEY_DOWN
, 20);
7593 RemoveAIFlag('NEEDSEEDOWN');
7596 // Åñëè íóæíî áûëî â äûðó è ìû íå íà çåìëå, òî ïîêîðíî ëåòèì:
7597 if GetAIFlag('GOINHOLE') <> '' then
7598 if not OnGround() then
7600 ReleaseKey(KEY_LEFT
);
7601 ReleaseKey(KEY_RIGHT
);
7602 RemoveAIFlag('GOINHOLE');
7603 SetAIFlag('FALLINHOLE', '1');
7606 // Åñëè ïàäàëè è äîñòèãëè çåìëè, òî õâàòèò ïàäàòü:
7607 if GetAIFlag('FALLINHOLE') <> '' then
7609 RemoveAIFlag('FALLINHOLE');
7611 // Åñëè ëåòåëè ïðÿìî è ñåé÷àñ íå íà ëåñòíèöå èëè íà âåðøèíå ëèôòà, òî îòõîäèì â ñòîðîíó:
7612 if not (KeyPressed(KEY_LEFT
) or KeyPressed(KEY_RIGHT
)) then
7613 if GetAIFlag('FALLINHOLE') = '' then
7614 if (not OnLadder()) or (FObj
.Vel
.Y
>= 0) or (OnTopLift()) then
7620 // Åñëè íà çåìëå è ìîæíî ïîäïðûãíóòü, òî, âîçìîæíî, ïðûãàåì:
7622 CanJumpUp(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*32) and
7626 // Åñëè íà çåìëå è âîçëå äûðû (ãëóáèíà > 2 ðîñòîâ èãðîêà):
7627 if OnGround() and NearHole() then
7628 if NearDeepHole() then // Åñëè ýòî áåçäíà
7630 0..3: Turn(); // Áåæèì îáðàòíî
7631 4: Jump(); // Ïðûãàåì
7632 5: begin // Ïðûãàåì îáðàòíî
7637 else // Ýòî íå áåçäíà è ìû åùå íå ëåòèì òóäà
7638 if GetAIFlag('GOINHOLE') = '' then
7640 0: Turn(); // Íå íóæíî òóäà
7641 1: Jump(); // Âäðóã ïîâåçåò - ïðûãàåì
7642 else // Åñëè ÿìà ñ ãðàíèöåé, òî ïðè ñëó÷àå ìîæíî òóäà ïðûãíóòü
7643 if BorderHole() then
7644 SetAIFlag('GOINHOLE', '1');
7647 // Åñëè íà çåìëå, íî íåêóäà èäòè:
7648 if (not CanRun()) and OnGround() then
7650 // Åñëè ìû íà ëåñòíèöå èëè ìîæíî ïåðåïðûãíóòü, òî ïðûãàåì:
7651 if CanJumpOver() or OnLadder() then
7653 else // èíà÷å ïîïûòàåìñÿ â äðóãóþ ñòîðîíó
7654 if Random(2) = 0 then
7656 if IsSafeTrigger() then
7662 // Îñòàëîñü ìàëî âîçäóõà:
7663 if FAir
< 36 * 2 then
7666 // Âûáèðàåìñÿ èç êèñëîòû, åñëè íåò êîñòþìà, îáîæãëèñü, èëè ìàëî çäîðîâüÿ:
7667 if (FMegaRulez
[MR_SUIT
] < gTime
) and ((FLastHit
= HIT_ACID
) or (Healthy() <= 1)) then
7668 if BodyInAcid(0, 0) then
7672 function TBot
.FullInStep(XInc
, YInc
: Integer): Boolean;
7674 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
7675 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_STEP
, False);
7678 {function TBot.NeedItem(Item: Byte): Byte;
7683 procedure TBot
.SelectWeapon(Dist
: Integer);
7687 function HaveAmmo(weapon
: Byte): Boolean;
7690 WEAPON_PISTOL
: Result
:= FAmmo
[A_BULLETS
] >= 1;
7691 WEAPON_SHOTGUN1
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7692 WEAPON_SHOTGUN2
: Result
:= FAmmo
[A_SHELLS
] >= 2;
7693 WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
] >= 10;
7694 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
] >= 1;
7695 WEAPON_PLASMA
: Result
:= FAmmo
[A_CELLS
] >= 10;
7696 WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
] >= 40;
7697 WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7698 WEAPON_FLAMETHROWER
: Result
:= FAmmo
[A_FUEL
] >= 1;
7699 else Result
:= True;
7704 if Dist
= -1 then Dist
:= BOT_LONGDIST
;
7706 if Dist
> BOT_LONGDIST
then
7707 begin // Äàëüíèé áîé
7709 if FWeapon
[FDifficult
.WeaponPrior
[a
]] and HaveAmmo(FDifficult
.WeaponPrior
[a
]) then
7711 FSelectedWeapon
:= FDifficult
.WeaponPrior
[a
];
7715 else //if Dist > BOT_UNSAFEDIST then
7716 begin // Áëèæíèé áîé
7718 if FWeapon
[FDifficult
.CloseWeaponPrior
[a
]] and HaveAmmo(FDifficult
.CloseWeaponPrior
[a
]) then
7720 FSelectedWeapon
:= FDifficult
.CloseWeaponPrior
[a
];
7727 if FWeapon[FDifficult.SafeWeaponPrior[a]] and HaveAmmo(FDifficult.SafeWeaponPrior[a]) then
7729 FSelectedWeapon := FDifficult.SafeWeaponPrior[a];
7735 function TBot
.PickItem(ItemType
: Byte; force
: Boolean; var remove
: Boolean): Boolean;
7737 Result
:= inherited PickItem(ItemType
, force
, remove
);
7739 if Result
then SetAIFlag('SELECTWEAPON', '1');
7742 function TBot
.Heal(value
: Word; Soft
: Boolean): Boolean;
7744 Result
:= inherited Heal(value
, Soft
);
7747 function TBot
.Healthy(): Byte;
7749 if FMegaRulez
[MR_INVUL
] >= gTime
then Result
:= 3
7750 else if (FHealth
> 80) or ((FHealth
> 50) and (FArmor
> 20)) then Result
:= 3
7751 else if (FHealth
> 50) then Result
:= 2
7752 else if (FHealth
> 20) then Result
:= 1
7756 function TBot
.TargetOnScreen(TX
, TY
: Integer): Boolean;
7758 Result
:= (Abs(FObj
.X
-TX
) <= Trunc(gPlayerScreenSize
.X
*0.6)) and
7759 (Abs(FObj
.Y
-TY
) <= Trunc(gPlayerScreenSize
.Y
*0.6));
7762 procedure TBot
.OnDamage(Angle
: SmallInt);
7770 if (Angle
= 0) or (Angle
= 180) then
7773 if (g_GetUIDType(FLastSpawnerUID
) = UID_PLAYER
) and
7774 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
) then
7776 pla
:= g_Player_Get(FLastSpawnerUID
);
7777 ok
:= not TargetOnScreen(pla
.FObj
.X
+ PLAYER_RECT
.X
,
7778 pla
.FObj
.Y
+ PLAYER_RECT
.Y
);
7781 if (g_GetUIDType(FLastSpawnerUID
) = UID_MONSTER
) and
7782 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
) then
7784 mon
:= g_Monsters_ByUID(FLastSpawnerUID
);
7785 ok
:= not TargetOnScreen(mon
.Obj
.X
+ mon
.Obj
.Rect
.X
,
7786 mon
.Obj
.Y
+ mon
.Obj
.Rect
.Y
);
7791 SetAIFlag('ATTACKLEFT', '1')
7793 SetAIFlag('ATTACKRIGHT', '1');
7797 function TBot
.RunDirection(): TDirection
;
7799 if Abs(Vel
.X
) >= 1 then
7801 if Vel
.X
> 0 then Result
:= TDirection
.D_RIGHT
else Result
:= TDirection
.D_LEFT
;
7803 Result
:= FDirection
;
7806 function TBot
.GetRnd(a
: Byte): Boolean;
7808 if a
= 0 then Result
:= False
7809 else if a
= 255 then Result
:= True
7810 else Result
:= Random(256) > 255-a
;
7813 function TBot
.GetInterval(a
: Byte; radius
: SmallInt): SmallInt;
7815 Result
:= Round((255-a
)/255*radius
*(Random(2)-1));
7819 procedure TDifficult
.save (st
: TStream
);
7821 utils
.writeInt(st
, Byte(DiagFire
));
7822 utils
.writeInt(st
, Byte(InvisFire
));
7823 utils
.writeInt(st
, Byte(DiagPrecision
));
7824 utils
.writeInt(st
, Byte(FlyPrecision
));
7825 utils
.writeInt(st
, Byte(Cover
));
7826 utils
.writeInt(st
, Byte(CloseJump
));
7827 st
.WriteBuffer(WeaponPrior
[Low(WeaponPrior
)], sizeof(WeaponPrior
));
7828 st
.WriteBuffer(CloseWeaponPrior
[Low(CloseWeaponPrior
)], sizeof(CloseWeaponPrior
));
7831 procedure TDifficult
.load (st
: TStream
);
7833 DiagFire
:= utils
.readByte(st
);
7834 InvisFire
:= utils
.readByte(st
);
7835 DiagPrecision
:= utils
.readByte(st
);
7836 FlyPrecision
:= utils
.readByte(st
);
7837 Cover
:= utils
.readByte(st
);
7838 CloseJump
:= utils
.readByte(st
);
7839 st
.ReadBuffer(WeaponPrior
[Low(WeaponPrior
)], sizeof(WeaponPrior
));
7840 st
.ReadBuffer(CloseWeaponPrior
[Low(CloseWeaponPrior
)], sizeof(CloseWeaponPrior
));
7844 procedure TBot
.SaveState (st
: TStream
);
7849 inherited SaveState(st
);
7850 utils
.writeSign(st
, 'BOT0');
7852 utils
.writeInt(st
, Byte(FSelectedWeapon
));
7854 utils
.writeInt(st
, Word(FTargetUID
));
7855 // Âðåìÿ ïîòåðè öåëè
7856 utils
.writeInt(st
, LongWord(FLastVisible
));
7857 // Êîëè÷åñòâî ôëàãîâ ÈÈ
7858 dw
:= Length(FAIFlags
);
7859 utils
.writeInt(st
, LongInt(dw
));
7861 for i
:= 0 to dw
-1 do
7863 utils
.writeStr(st
, FAIFlags
[i
].Name
, 20);
7864 utils
.writeStr(st
, FAIFlags
[i
].Value
, 20);
7866 // Íàñòðîéêè ñëîæíîñòè
7867 FDifficult
.save(st
);
7871 procedure TBot
.LoadState (st
: TStream
);
7876 inherited LoadState(st
);
7877 if not utils
.checkSign(st
, 'BOT0') then raise XStreamError
.Create('invalid bot signature');
7879 FSelectedWeapon
:= utils
.readByte(st
);
7881 FTargetUID
:= utils
.readWord(st
);
7882 // Âðåìÿ ïîòåðè öåëè
7883 FLastVisible
:= utils
.readLongWord(st
);
7884 // Êîëè÷åñòâî ôëàãîâ ÈÈ
7885 dw
:= utils
.readLongInt(st
);
7886 if (dw
< 0) or (dw
> 16384) then raise XStreamError
.Create('invalid number of bot AI flags');
7887 SetLength(FAIFlags
, dw
);
7889 for i
:= 0 to dw
-1 do
7891 FAIFlags
[i
].Name
:= utils
.readStr(st
, 20);
7892 FAIFlags
[i
].Value
:= utils
.readStr(st
, 20);
7894 // Íàñòðîéêè ñëîæíîñòè
7895 FDifficult
.load(st
);
7900 conRegVar('cheat_berserk_autoswitch', @gBerserkAutoswitch
, 'autoswitch to fist when berserk pack taken', '', true, true);