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 g_base
, g_playermodel
, g_basic
, g_textures
,
25 g_weapons
, g_phys
, g_sound
, g_saveload
, MAPDEF
,
26 g_panel
, r_playermodel
;
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);
106 JET_MAX
= 540; // ~30 sec
108 ANGLE_RIGHTDOWN
= -35;
110 ANGLE_LEFTDOWN
= -145;
111 WEAPONPOINT
: Array [TDirection
] of TDFPoint
= ((X
:16; Y
:32), (X
:47; Y
:32));
112 TEAMCOLOR
: Array [TEAM_RED
..TEAM_BLUE
] of TRGB
= ((R
:255; G
:0; B
:0),
131 TPlayerStatArray
= Array of TPlayerStat
;
133 TPlayerSavedState
= record
141 Ammo
: Array [A_BULLETS
..A_HIGH
] of Word;
142 MaxAmmo
: Array [A_BULLETS
..A_HIGH
] of Word;
143 Weapon
: Array [WP_FIRST
..WP_LAST
] of Boolean;
144 Rulez
: Set of R_ITEM_BACKPACK
..R_BERSERK
;
153 TPlayer
= class{$IFDEF USE_MEMPOOL}(TPoolObject
){$ENDIF}
161 FDirection
: TDirection
;
169 FMonsterKills
: Integer;
175 FCanJetpack
: Boolean;
181 FNextWeapDelay
: Byte; // frames
182 FBFGFireCounter
: SmallInt;
183 FLastSpawnerUID
: Word;
187 FSpectatePlayer
: Integer;
188 FFirePainTime
: Integer;
191 FSavedStateNum
: Integer;
193 FModel
: TPlayerModel
;
194 FPunchAnim
: TAnimationState
;
197 FActionForce
: Boolean;
198 FActionChanged
: Boolean;
200 FFireAngle
: SmallInt;
204 FShellTimer
: Integer;
206 FSawSound
: TPlayableSound
;
207 FSawSoundIdle
: TPlayableSound
;
208 FSawSoundHit
: TPlayableSound
;
209 FSawSoundSelect
: TPlayableSound
;
210 FFlameSoundOn
: TPlayableSound
;
211 FFlameSoundOff
: TPlayableSound
;
212 FFlameSoundWork
: TPlayableSound
;
213 FJetSoundOn
: TPlayableSound
;
214 FJetSoundOff
: TPlayableSound
;
215 FJetSoundFly
: TPlayableSound
;
219 FJustTeleported
: Boolean;
221 mEDamageType
: Integer;
224 function CollideLevel(XInc
, YInc
: Integer): Boolean;
225 function StayOnStep(XInc
, YInc
: Integer): Boolean;
226 function HeadInLiquid(XInc
, YInc
: Integer): Boolean;
227 function BodyInLiquid(XInc
, YInc
: Integer): Boolean;
228 function BodyInAcid(XInc
, YInc
: Integer): Boolean;
229 function FullInLift(XInc
, YInc
: Integer): Integer;
230 {procedure CollideItem();}
231 procedure FlySmoke(Times
: DWORD
= 1);
232 procedure OnFireFlame(Times
: DWORD
= 1);
233 procedure SetAction(Action
: Byte; Force
: Boolean = False);
234 procedure OnDamage(Angle
: SmallInt); virtual;
235 function firediry(): Integer;
238 procedure Run(Direction
: TDirection
);
239 procedure NextWeapon();
240 procedure PrevWeapon();
247 function getNextWeaponIndex (): Byte; // return 255 for "no switch"
248 procedure resetWeaponQueue ();
249 function hasAmmoForWeapon (weapon
: Byte): Boolean;
251 procedure doDamage (v
: Integer);
253 function refreshCorpse(): Boolean;
256 FDamageBuffer
: Integer;
258 FAmmo
: Array [A_BULLETS
..A_HIGH
] of Word;
259 FMaxAmmo
: Array [A_BULLETS
..A_HIGH
] of Word;
260 FWeapon
: Array [WP_FIRST
..WP_LAST
] of Boolean;
261 FRulez
: Set of R_ITEM_BACKPACK
..R_BERSERK
;
263 FMegaRulez
: Array [MR_SUIT
..MR_MAX
] of DWORD
;
264 FReloading
: Array [WP_FIRST
..WP_LAST
] of Word;
265 FTime
: Array [T_RESPAWN
..T_FLAGCAP
] of DWORD
;
266 FKeys
: Array [KEY_LEFT
..KEY_CHAT
] of TKeyState
;
268 FPreferredTeam
: Byte;
271 FWantsInGame
: Boolean;
276 FActualModelName
: string;
283 FSpawnInvul
: Integer;
285 FWaitForFirstSpawn
: Boolean; // set to `true` in server, used to spawn a player on first full state request
288 // debug: viewport offset
289 viewPortX
, viewPortY
, viewPortW
, viewPortH
: Integer;
291 function isValidViewPort (): Boolean; inline;
293 constructor Create(); virtual;
294 destructor Destroy(); override;
295 procedure Respawn(Silent
: Boolean; Force
: Boolean = False); virtual;
296 function GetRespawnPoint(): Byte;
297 procedure PressKey(Key
: Byte; Time
: Word = 1);
298 procedure ReleaseKeys();
299 procedure SetModel(ModelName
: String);
300 procedure SetColor(Color
: TRGB
);
301 function GetColor(): TRGB
;
302 procedure SetWeapon(W
: Byte);
303 function IsKeyPressed(K
: Byte): Boolean;
304 function GetKeys(): Byte;
305 function PickItem(ItemType
: Byte; arespawn
: Boolean; var remove
: Boolean): Boolean; virtual;
306 function Collide(X
, Y
: Integer; Width
, Height
: Word): Boolean; overload
;
307 function Collide(Panel
: TPanel
): Boolean; overload
;
308 function Collide(X
, Y
: Integer): Boolean; overload
;
309 procedure SetDirection(Direction
: TDirection
);
310 procedure GetSecret();
311 function TeleportTo(X
, Y
: Integer; silent
: Boolean; dir
: Byte): Boolean;
313 procedure Push(vx
, vy
: Integer);
314 procedure ChangeModel(ModelName
: String);
315 procedure SwitchTeam
;
316 procedure ChangeTeam(Team
: Byte);
318 function GetFlag(Flag
: Byte): Boolean;
319 procedure SetFlag(Flag
: Byte);
320 function DropFlag(Silent
: Boolean = True): Boolean;
321 procedure AllRulez(Health
: Boolean);
322 procedure RestoreHealthArmor();
323 procedure FragCombo();
324 procedure GiveItem(ItemType
: Byte);
325 procedure Damage(value
: Word; SpawnerUID
: Word; vx
, vy
: Integer; t
: Byte); virtual;
326 function Heal(value
: Word; Soft
: Boolean): Boolean; virtual;
327 procedure MakeBloodVector(Count
: Word; VelX
, VelY
: Integer);
328 procedure MakeBloodSimple(Count
: Word);
329 procedure Kill(KillType
: Byte; SpawnerUID
: Word; t
: Byte);
330 procedure Reset(Force
: Boolean);
331 procedure Spectate(NoMove
: Boolean = False);
332 procedure SwitchNoClip
;
333 procedure SoftReset();
334 procedure PreUpdate();
335 procedure Update(); virtual;
336 procedure RememberState();
337 procedure RecallState();
338 procedure SaveState (st
: TStream
); virtual;
339 procedure LoadState (st
: TStream
); virtual;
340 procedure PauseSounds(Enable
: Boolean);
341 procedure NetFire(Wpn
: Byte; X
, Y
, AX
, AY
: Integer; WID
: Integer = -1);
342 procedure DoLerp(Level
: Integer = 2);
343 procedure SetLerp(XTo
, YTo
: Integer);
344 procedure QueueWeaponSwitch(Weapon
: Byte);
345 procedure RealizeCurrentWeapon();
349 procedure JetpackOff
;
350 procedure CatchFire(Attacker
: Word; Timeout
: Integer = PLAYER_BURN_TIME
);
352 //WARNING! this does nothing for now, but still call it!
353 procedure positionChanged (); //WARNING! call this after entity position was changed, or coldet will not work right!
355 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
356 procedure moveBy (dx
, dy
: Integer); inline;
358 function getCameraObj(): TObj
;
360 function GetAmmoByWeapon(Weapon
: Byte): Word; // private state
363 property Vel
: TPoint2i read FObj
.Vel
;
364 property Obj
: TObj read FObj
;
366 property Name
: String read FName write FName
;
367 property Model
: TPlayerModel read FModel
;
368 property Health
: Integer read FHealth write FHealth
;
369 property Lives
: Byte read FLives write FLives
;
370 property Armor
: Integer read FArmor write FArmor
;
371 property Air
: Integer read FAir write FAir
;
372 property JetFuel
: Integer read FJetFuel write FJetFuel
;
373 property Frags
: Integer read FFrags write FFrags
;
374 property Death
: Integer read FDeath write FDeath
;
375 property Kills
: Integer read FKills write FKills
;
376 property CurrWeap
: Byte read FCurrWeap write FCurrWeap
;
377 property MonsterKills
: Integer read FMonsterKills write FMonsterKills
;
378 property Secrets
: Integer read FSecrets
;
379 property GodMode
: Boolean read FGodMode write FGodMode
;
380 property NoTarget
: Boolean read FNoTarget write FNoTarget
;
381 property NoReload
: Boolean read FNoReload write FNoReload
;
382 property alive
: Boolean read FAlive write FAlive
;
383 property Flag
: Byte read FFlag
;
384 property Team
: Byte read FTeam write FTeam
;
385 property Direction
: TDirection read FDirection
;
386 property GameX
: Integer read FObj
.X write FObj
.X
;
387 property GameY
: Integer read FObj
.Y write FObj
.Y
;
388 property GameVelX
: Integer read FObj
.Vel
.X write FObj
.Vel
.X
;
389 property GameVelY
: Integer read FObj
.Vel
.Y write FObj
.Vel
.Y
;
390 property GameAccelX
: Integer read FObj
.Accel
.X write FObj
.Accel
.X
;
391 property GameAccelY
: Integer read FObj
.Accel
.Y write FObj
.Accel
.Y
;
392 property IncCam
: Integer read FIncCam write FIncCam
;
393 property IncCamOld
: Integer read FIncCamOld write FIncCamOld
;
394 property SlopeOld
: Integer read FSlopeOld write FSlopeOld
;
395 property UID
: Word read FUID write FUID
;
396 property JustTeleported
: Boolean read FJustTeleported write FJustTeleported
;
397 property NetTime
: LongWord read FNetTime write FNetTime
;
400 property Angle_
: SmallInt read FAngle
;
401 property Spectator
: Boolean read FSpectator
;
402 property NoRespawn
: Boolean read FNoRespawn
;
403 property Berserk
: Integer read FBerserk
;
404 property Pain
: Integer read FPain
;
405 property Pickup
: Integer read FPickup
;
406 property PunchAnim
: TAnimationState read FPunchAnim write FPunchAnim
;
407 property SpawnInvul
: Integer read FSpawnInvul
;
408 property Ghost
: Boolean read FGhost
;
411 property eName
: String read FName write FName
;
412 property eHealth
: Integer read FHealth write FHealth
;
413 property eLives
: Byte read FLives write FLives
;
414 property eArmor
: Integer read FArmor write FArmor
;
415 property eAir
: Integer read FAir write FAir
;
416 property eJetFuel
: Integer read FJetFuel write FJetFuel
;
417 property eFrags
: Integer read FFrags write FFrags
;
418 property eDeath
: Integer read FDeath write FDeath
;
419 property eKills
: Integer read FKills write FKills
;
420 property eCurrWeap
: Byte read FCurrWeap write FCurrWeap
;
421 property eMonsterKills
: Integer read FMonsterKills write FMonsterKills
;
422 property eSecrets
: Integer read FSecrets write FSecrets
;
423 property eGodMode
: Boolean read FGodMode write FGodMode
;
424 property eNoTarget
: Boolean read FNoTarget write FNoTarget
;
425 property eNoReload
: Boolean read FNoReload write FNoReload
;
426 property eAlive
: Boolean read FAlive write FAlive
;
427 property eFlag
: Byte read FFlag
;
428 property eTeam
: Byte read FTeam write FTeam
;
429 property eDirection
: TDirection read FDirection
;
430 property eGameX
: Integer read FObj
.X write FObj
.X
;
431 property eGameY
: Integer read FObj
.Y write FObj
.Y
;
432 property eGameVelX
: Integer read FObj
.Vel
.X write FObj
.Vel
.X
;
433 property eGameVelY
: Integer read FObj
.Vel
.Y write FObj
.Vel
.Y
;
434 property eGameAccelX
: Integer read FObj
.Accel
.X write FObj
.Accel
.X
;
435 property eGameAccelY
: Integer read FObj
.Accel
.Y write FObj
.Accel
.Y
;
436 property eIncCam
: Integer read FIncCam write FIncCam
;
437 property eUID
: Word read FUID
;
438 property eJustTeleported
: Boolean read FJustTeleported
;
439 property eNetTime
: LongWord read FNetTime
;
441 // set this before assigning something to `eDamage`
442 property eDamageType
: Integer read mEDamageType write mEDamageType
;
443 property eDamage
: Integer write doDamage
;
454 WeaponPrior
: packed array [WP_FIRST
..WP_LAST
] of Byte;
455 CloseWeaponPrior
: packed array [WP_FIRST
..WP_LAST
] of Byte;
456 //SafeWeaponPrior: Array [WP_FIRST..WP_LAST] of Byte;
459 procedure save (st
: TStream
);
460 procedure load (st
: TStream
);
468 TBot
= class(TPlayer
)
470 FSelectedWeapon
: Byte;
473 FAIFlags
: Array of TAIFlag
;
474 FDifficult
: TDifficult
;
476 function GetRnd(a
: Byte): Boolean;
477 function GetInterval(a
: Byte; radius
: SmallInt): SmallInt;
478 function RunDirection(): TDirection
;
479 function FullInStep(XInc
, YInc
: Integer): Boolean;
480 //function NeedItem(Item: Byte): Byte;
481 procedure SelectWeapon(Dist
: Integer);
482 procedure SetAIFlag(aName
, fValue
: String20
);
483 function GetAIFlag(aName
: String20
): String20
;
484 procedure RemoveAIFlag(aName
: String20
);
485 function Healthy(): Byte;
486 procedure UpdateMove();
487 procedure UpdateCombat();
488 function KeyPressed(Key
: Word): Boolean;
489 procedure ReleaseKey(Key
: Byte);
490 function TargetOnScreen(TX
, TY
: Integer): Boolean;
491 procedure OnDamage(Angle
: SmallInt); override;
494 procedure Respawn(Silent
: Boolean; Force
: Boolean = False); override;
495 constructor Create(); override;
496 destructor Destroy(); override;
497 function PickItem(ItemType
: Byte; force
: Boolean; var remove
: Boolean): Boolean; override;
498 function Heal(value
: Word; Soft
: Boolean): Boolean; override;
499 procedure Update(); override;
500 procedure SaveState (st
: TStream
); override;
501 procedure LoadState (st
: TStream
); override;
514 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
515 procedure moveBy (dx
, dy
: Integer); inline;
517 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
531 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
532 procedure moveBy (dx
, dy
: Integer); inline;
534 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
537 TCorpse
= class{$IFDEF USE_MEMPOOL}(TPoolObject
){$ENDIF}
544 FModel
: TPlayerModel
;
547 constructor Create(X
, Y
: Integer; ModelName
: String; aMess
: Boolean);
548 destructor Destroy(); override;
549 procedure Damage(Value
: Word; SpawnerUID
: Word; vx
, vy
: Integer);
551 procedure SaveState (st
: TStream
);
552 procedure LoadState (st
: TStream
);
554 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
555 procedure moveBy (dx
, dy
: Integer); inline;
557 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
559 function ObjPtr (): PObj
; inline;
561 property Obj
: TObj read FObj
; // copies object
562 property State
: Byte read FState
;
563 property Mess
: Boolean read FMess
;
564 property Model
: TPlayerModel read FModel
;
567 TTeamStat
= Array [TEAM_RED
..TEAM_BLUE
] of
573 gPlayers
: Array of TPlayer
;
574 gCorpses
: Array of TCorpse
;
575 gGibs
: Array of TGib
;
576 gShells
: Array of TShell
;
577 gTeamStat
: TTeamStat
;
578 gFly
: Boolean = False;
579 gAimLine
: Boolean = False;
580 gChatBubble
: Integer = 0;
581 gPlayerIndicator
: Integer = 1;
582 gPlayerIndicatorStyle
: Integer = 0;
584 gSpectLatchPID1
: Word = 0;
585 gSpectLatchPID2
: Word = 0;
586 MAX_RUNVEL
: Integer = 8;
587 VEL_JUMP
: Integer = 10;
588 SHELL_TIMEOUT
: Cardinal = 60000;
590 function Lerp(X
, Y
, Factor
: Integer): Integer;
592 procedure g_Gibs_SetMax(Count
: Word);
593 function g_Gibs_GetMax(): Word;
594 procedure g_Corpses_SetMax(Count
: Word);
595 function g_Corpses_GetMax(): Word;
596 procedure g_Shells_SetMax(Count
: Word);
597 function g_Shells_GetMax(): Word;
599 procedure g_Player_Init();
600 procedure g_Player_Free();
601 function g_Player_Create(ModelName
: String; Color
: TRGB
; Team
: Byte; Bot
: Boolean): Word;
602 function g_Player_CreateFromState (st
: TStream
): Word;
603 procedure g_Player_Remove(UID
: Word);
604 procedure g_Player_ResetTeams();
605 procedure g_Player_PreUpdate();
606 procedure g_Player_UpdateAll();
607 procedure g_Player_RememberAll();
608 procedure g_Player_ResetAll(Force
, Silent
: Boolean);
609 function g_Player_Get(UID
: Word): TPlayer
;
610 function g_Player_GetCount(): Byte;
611 function g_Player_GetStats(): TPlayerStatArray
;
612 function g_Player_ValidName(Name
: String): Boolean;
613 function g_Player_CreateCorpse(Player
: TPlayer
): Integer;
614 procedure g_Player_CreateGibs (fX
, fY
, mid
: Integer; fColor
: TRGB
);
615 procedure g_Player_CreateShell(fX
, fY
, dX
, dY
: Integer; T
: Byte);
616 procedure g_Player_UpdatePhysicalObjects();
617 procedure g_Player_RemoveAllCorpses();
618 procedure g_Player_Corpses_SaveState (st
: TStream
);
619 procedure g_Player_Corpses_LoadState (st
: TStream
);
620 procedure g_Player_ResetReady();
621 procedure g_Bot_Add(Team
, Difficult
: Byte; Handicap
: Integer = 100);
622 procedure g_Bot_AddList(Team
: Byte; lname
: ShortString; num
: Integer = -1; Handicap
: Integer = 100);
623 procedure g_Bot_MixNames();
624 procedure g_Bot_RemoveAll();
629 {$IFDEF ENABLE_HOLMES}
632 e_log
, g_map
, g_items
, g_console
, g_gfx
, Math
, r_textures
, r_animations
, r_gfx
,
633 g_options
, g_triggers
, g_menu
, g_game
, g_grid
, e_res
,
634 wadreader
, g_monsters
, CONFIG
, g_language
,
638 const PLR_SAVE_VERSION
= 0;
648 diag_precision
: Byte;
652 w_prior1
: Array [WP_FIRST
..WP_LAST
] of Byte;
653 w_prior2
: Array [WP_FIRST
..WP_LAST
] of Byte;
654 w_prior3
: Array [WP_FIRST
..WP_LAST
] of Byte;
658 TIME_RESPAWN1
= 1500;
659 TIME_RESPAWN2
= 2000;
660 TIME_RESPAWN3
= 3000;
661 PLAYER_SUIT_TIME
= 30000;
662 PLAYER_INVUL_TIME
= 30000;
663 PLAYER_INVIS_TIME
= 35000;
664 FRAG_COMBO_TIME
= 3000;
667 PLAYER_HEADRECT
: TRectWH
= (X
:24; Y
:12; Width
:20; Height
:12);
670 BOT_UNSAFEDIST
= 128;
671 DIFFICULT_EASY
: TDifficult
= (DiagFire
: 32; InvisFire
: 32; DiagPrecision
: 32;
672 FlyPrecision
: 32; Cover
: 32; CloseJump
: 32;
673 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
674 DIFFICULT_MEDIUM
: TDifficult
= (DiagFire
: 127; InvisFire
: 127; DiagPrecision
: 127;
675 FlyPrecision
: 127; Cover
: 127; CloseJump
: 127;
676 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
677 DIFFICULT_HARD
: TDifficult
= (DiagFire
: 255; InvisFire
: 255; DiagPrecision
: 255;
678 FlyPrecision
: 255; Cover
: 255; CloseJump
: 255;
679 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
680 WEAPON_PRIOR1
: Array [WP_FIRST
..WP_LAST
] of Byte =
681 (WEAPON_FLAMETHROWER
, WEAPON_SUPERPULEMET
,
682 WEAPON_SHOTGUN2
, WEAPON_SHOTGUN1
,
683 WEAPON_CHAINGUN
, WEAPON_PLASMA
, WEAPON_ROCKETLAUNCHER
,
684 WEAPON_BFG
, WEAPON_PISTOL
, WEAPON_SAW
, WEAPON_KASTET
);
685 WEAPON_PRIOR2
: Array [WP_FIRST
..WP_LAST
] of Byte =
686 (WEAPON_FLAMETHROWER
, WEAPON_SUPERPULEMET
,
687 WEAPON_BFG
, WEAPON_ROCKETLAUNCHER
,
688 WEAPON_SHOTGUN2
, WEAPON_PLASMA
, WEAPON_SHOTGUN1
,
689 WEAPON_CHAINGUN
, WEAPON_PISTOL
, WEAPON_SAW
, WEAPON_KASTET
);
690 //WEAPON_PRIOR3: Array [WP_FIRST..WP_LAST] of Byte =
691 // (WEAPON_FLAMETHROWER, WEAPON_SUPERPULEMET,
692 // WEAPON_BFG, WEAPON_PLASMA, WEAPON_SHOTGUN2,
693 // WEAPON_CHAINGUN, WEAPON_SHOTGUN1, WEAPON_SAW,
694 // WEAPON_ROCKETLAUNCHER, WEAPON_PISTOL, WEAPON_KASTET);
695 WEAPON_RELOAD
: Array [WP_FIRST
..WP_LAST
] of Byte =
696 (5, 2, 6, 18, 36, 2, 12, 2, 14, 2, 2);
698 PLAYER_SIGNATURE
= $52594C50; // 'PLYR'
699 CORPSE_SIGNATURE
= $50524F43; // 'CORP'
701 BOTNAMES_FILENAME
= 'botnames.txt';
702 BOTLIST_FILENAME
= 'botlist.txt';
706 MaxCorpses
: Word = 20;
707 MaxShells
: Word = 300;
708 CurrentGib
: Integer = 0;
709 CurrentShell
: Integer = 0;
710 BotNames
: Array of String;
711 BotList
: Array of TBotProfile
;
712 SavedStates
: Array of TPlayerSavedState
;
715 function Lerp(X
, Y
, Factor
: Integer): Integer;
717 Result
:= X
+ ((Y
- X
) div Factor
);
720 function SameTeam(UID1
, UID2
: Word): Boolean;
724 if (UID1
> UID_MAX_PLAYER
) or (UID1
<= UID_MAX_GAME
) or
725 (UID2
> UID_MAX_PLAYER
) or (UID2
<= UID_MAX_GAME
) then Exit
;
727 if (g_Player_Get(UID1
) = nil) or (g_Player_Get(UID2
) = nil) then Exit
;
729 if ((g_Player_Get(UID1
).Team
= TEAM_NONE
) or
730 (g_Player_Get(UID2
).Team
= TEAM_NONE
)) then Exit
;
732 Result
:= g_Player_Get(UID1
).FTeam
= g_Player_Get(UID2
).FTeam
;
735 procedure g_Gibs_SetMax(Count
: Word);
738 SetLength(gGibs
, Count
);
740 if CurrentGib
>= Count
then
744 function g_Gibs_GetMax(): Word;
749 procedure g_Shells_SetMax(Count
: Word);
752 SetLength(gShells
, Count
);
754 if CurrentShell
>= Count
then
758 function g_Shells_GetMax(): Word;
764 procedure g_Corpses_SetMax(Count
: Word);
767 SetLength(gCorpses
, Count
);
770 function g_Corpses_GetMax(): Word;
772 Result
:= MaxCorpses
;
775 function g_Player_Create(ModelName
: String; Color
: TRGB
; Team
: Byte; Bot
: Boolean): Word;
785 // Есть ли место в gPlayers:
786 if gPlayers
<> nil then
787 for a
:= 0 to High(gPlayers
) do
788 if gPlayers
[a
] = nil then
794 // Нет места - расширяем gPlayers:
797 SetLength(gPlayers
, Length(gPlayers
)+1);
801 // Создаем объект игрока:
803 gPlayers
[a
] := TBot
.Create()
805 gPlayers
[a
] := TPlayer
.Create();
808 gPlayers
[a
].FActualModelName
:= ModelName
;
809 gPlayers
[a
].SetModel(ModelName
);
811 // Нет модели - создание не возможно:
812 if gPlayers
[a
].FModel
= nil then
816 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], [ModelName
]));
820 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
821 if Random(2) = 0 then
825 gPlayers
[a
].FPreferredTeam
:= Team
;
827 case gGameSettings
.GameMode
of
828 GM_DM
: gPlayers
[a
].FTeam
:= TEAM_NONE
;
830 GM_CTF
: gPlayers
[a
].FTeam
:= gPlayers
[a
].FPreferredTeam
;
832 GM_COOP
: gPlayers
[a
].FTeam
:= TEAM_COOP
;
835 // Если командная игра - красим модель в цвет команды:
836 gPlayers
[a
].FColor
:= Color
;
837 if gPlayers
[a
].FTeam
in [TEAM_RED
, TEAM_BLUE
] then
838 gPlayers
[a
].FModel
.Color
:= TEAMCOLOR
[gPlayers
[a
].FTeam
]
840 gPlayers
[a
].FModel
.Color
:= Color
;
842 gPlayers
[a
].FUID
:= g_CreateUID(UID_PLAYER
);
843 gPlayers
[a
].FAlive
:= False;
845 Result
:= gPlayers
[a
].FUID
;
848 function g_Player_CreateFromState (st
: TStream
): Word;
855 if (st
= nil) then exit
; //???
858 if not utils
.checkSign(st
, 'PLYR') then raise XStreamError
.Create('invalid player signature');
859 if (utils
.readByte(st
) <> PLR_SAVE_VERSION
) then raise XStreamError
.Create('invalid player version');
862 Bot
:= utils
.readBool(st
);
867 // Есть ли место в gPlayers:
868 for a
:= 0 to High(gPlayers
) do if (gPlayers
[a
] = nil) then begin ok
:= true; break
; end;
870 // Нет места - расширяем gPlayers
873 SetLength(gPlayers
, Length(gPlayers
)+1);
877 // Создаем объект игрока
879 gPlayers
[a
] := TBot
.Create()
881 gPlayers
[a
] := TPlayer
.Create();
882 gPlayers
[a
].FIamBot
:= Bot
;
883 gPlayers
[a
].FPhysics
:= True;
886 gPlayers
[a
].FUID
:= utils
.readWord(st
);
888 gPlayers
[a
].FName
:= utils
.readStr(st
);
890 gPlayers
[a
].FTeam
:= utils
.readByte(st
);
891 gPlayers
[a
].FPreferredTeam
:= gPlayers
[a
].FTeam
;
893 gPlayers
[a
].FAlive
:= utils
.readBool(st
);
894 // Израсходовал ли все жизни
895 gPlayers
[a
].FNoRespawn
:= utils
.readBool(st
);
897 b
:= utils
.readByte(st
);
898 if b
= 1 then gPlayers
[a
].FDirection
:= TDirection
.D_LEFT
else gPlayers
[a
].FDirection
:= TDirection
.D_RIGHT
; // b = 2
900 gPlayers
[a
].FHealth
:= utils
.readLongInt(st
);
902 gPlayers
[a
].FHandicap
:= utils
.readLongInt(st
);
904 gPlayers
[a
].FLives
:= utils
.readByte(st
);
906 gPlayers
[a
].FArmor
:= utils
.readLongInt(st
);
908 gPlayers
[a
].FAir
:= utils
.readLongInt(st
);
910 gPlayers
[a
].FJetFuel
:= utils
.readLongInt(st
);
912 gPlayers
[a
].FPain
:= utils
.readLongInt(st
);
914 gPlayers
[a
].FKills
:= utils
.readLongInt(st
);
916 gPlayers
[a
].FMonsterKills
:= utils
.readLongInt(st
);
918 gPlayers
[a
].FFrags
:= utils
.readLongInt(st
);
920 gPlayers
[a
].FFragCombo
:= utils
.readByte(st
);
921 // Время последнего фрага
922 gPlayers
[a
].FLastFrag
:= utils
.readLongWord(st
);
924 gPlayers
[a
].FDeath
:= utils
.readLongInt(st
);
926 gPlayers
[a
].FFlag
:= utils
.readByte(st
);
928 gPlayers
[a
].FSecrets
:= utils
.readLongInt(st
);
930 gPlayers
[a
].FCurrWeap
:= utils
.readByte(st
);
931 // Следующее желаемое оружие
932 gPlayers
[a
].FNextWeap
:= utils
.readWord(st
);
934 gPlayers
[a
].FNextWeapDelay
:= utils
.readByte(st
);
936 gPlayers
[a
].FBFGFireCounter
:= utils
.readSmallInt(st
);
938 gPlayers
[a
].FDamageBuffer
:= utils
.readLongInt(st
);
939 // Последний ударивший
940 gPlayers
[a
].FLastSpawnerUID
:= utils
.readWord(st
);
941 // Тип последнего полученного урона
942 gPlayers
[a
].FLastHit
:= utils
.readByte(st
);
944 Obj_LoadState(@gPlayers
[a
].FObj
, st
);
945 // Текущее количество патронов
946 for i
:= A_BULLETS
to A_HIGH
do gPlayers
[a
].FAmmo
[i
] := utils
.readWord(st
);
947 // Максимальное количество патронов
948 for i
:= A_BULLETS
to A_HIGH
do gPlayers
[a
].FMaxAmmo
[i
] := utils
.readWord(st
);
950 for i
:= WP_FIRST
to WP_LAST
do gPlayers
[a
].FWeapon
[i
] := utils
.readBool(st
);
951 // Время перезарядки оружия
952 for i
:= WP_FIRST
to WP_LAST
do gPlayers
[a
].FReloading
[i
] := utils
.readWord(st
);
954 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_ITEM_BACKPACK
);
955 // Наличие красного ключа
956 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_KEY_RED
);
957 // Наличие зеленого ключа
958 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_KEY_GREEN
);
959 // Наличие синего ключа
960 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_KEY_BLUE
);
962 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_BERSERK
);
963 // Время действия специальных предметов
964 for i
:= MR_SUIT
to MR_MAX
do gPlayers
[a
].FMegaRulez
[i
] := utils
.readLongWord(st
);
965 // Время до повторного респауна, смены оружия, исользования, захвата флага
966 for i
:= T_RESPAWN
to T_FLAGCAP
do gPlayers
[a
].FTime
[i
] := utils
.readLongWord(st
);
969 gPlayers
[a
].FActualModelName
:= utils
.readStr(st
);
971 gPlayers
[a
].FColor
.R
:= utils
.readByte(st
);
972 gPlayers
[a
].FColor
.G
:= utils
.readByte(st
);
973 gPlayers
[a
].FColor
.B
:= utils
.readByte(st
);
974 // Обновляем модель игрока
975 gPlayers
[a
].SetModel(gPlayers
[a
].FActualModelName
);
977 // Нет модели - создание невозможно
978 if (gPlayers
[a
].FModel
= nil) then
982 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], [gPlayers
[a
].FActualModelName
]));
986 // Если командная игра - красим модель в цвет команды
987 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
988 gPlayers
[a
].FModel
.Color
:= TEAMCOLOR
[gPlayers
[a
].FTeam
]
990 gPlayers
[a
].FModel
.Color
:= gPlayers
[a
].FColor
;
992 result
:= gPlayers
[a
].FUID
;
996 procedure g_Player_ResetTeams();
1000 if g_Game_IsClient
then
1002 if gPlayers
= nil then
1004 for a
:= Low(gPlayers
) to High(gPlayers
) do
1005 if gPlayers
[a
] <> nil then
1006 case gGameSettings
.GameMode
of
1008 gPlayers
[a
].ChangeTeam(TEAM_NONE
);
1010 if not (gPlayers
[a
].Team
in [TEAM_RED
, TEAM_BLUE
]) then
1011 if gPlayers
[a
].FPreferredTeam
in [TEAM_RED
, TEAM_BLUE
] then
1012 gPlayers
[a
].ChangeTeam(gPlayers
[a
].FPreferredTeam
)
1015 gPlayers
[a
].ChangeTeam(TEAM_RED
)
1017 gPlayers
[a
].ChangeTeam(TEAM_BLUE
);
1020 gPlayers
[a
].ChangeTeam(TEAM_COOP
);
1024 procedure g_Bot_Add(Team
, Difficult
: Byte; Handicap
: Integer = 100);
1027 _name
, _model
: String;
1030 if not g_Game_IsServer
then Exit
;
1032 // Список названий моделей:
1033 m
:= g_PlayerModel_GetNames();
1038 if (gGameSettings
.GameType
= GT_SINGLE
) or (gGameSettings
.GameMode
= GM_COOP
) then
1039 Team
:= TEAM_COOP
// COOP
1041 if gGameSettings
.GameMode
= GM_DM
then
1042 Team
:= TEAM_NONE
// DM
1044 if Team
= TEAM_NONE
then // CTF / TDM
1046 // Автобаланс команд:
1050 for a
:= 0 to High(gPlayers
) do
1051 if gPlayers
[a
] <> nil then
1053 if gPlayers
[a
].Team
= TEAM_RED
then
1056 if gPlayers
[a
].Team
= TEAM_BLUE
then
1066 if Random(2) = 0 then
1072 // Выбираем боту имя:
1074 if BotNames
<> nil then
1075 for a
:= 0 to High(BotNames
) do
1076 if g_Player_ValidName(BotNames
[a
]) then
1078 _name
:= BotNames
[a
];
1082 // Выбираем случайную модель:
1083 _model
:= m
[Random(Length(m
))];
1086 with g_Player_Get(g_Player_Create(_model
,
1087 _RGB(Min(Random(9)*32, 255),
1088 Min(Random(9)*32, 255),
1089 Min(Random(9)*32, 255)),
1090 Team
, True)) as TBot
do
1092 // Если имени нет, делаем его из UID бота
1094 Name
:= Format('DFBOT%.5d', [UID
])
1099 1: FDifficult
:= DIFFICULT_EASY
;
1100 2: FDifficult
:= DIFFICULT_MEDIUM
;
1101 else FDifficult
:= DIFFICULT_HARD
;
1104 for a
:= WP_FIRST
to WP_LAST
do
1106 FDifficult
.WeaponPrior
[a
] := WEAPON_PRIOR1
[a
];
1107 FDifficult
.CloseWeaponPrior
[a
] := WEAPON_PRIOR2
[a
];
1108 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
1111 FHandicap
:= Handicap
;
1113 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [Name
]), True);
1115 if g_Game_IsNet
then MH_SEND_PlayerCreate(UID
);
1116 if g_Game_IsServer
and (gGameSettings
.MaxLives
> 0) then
1121 procedure g_Bot_AddList(Team
: Byte; lName
: ShortString; num
: Integer = -1; Handicap
: Integer = 100);
1124 _name
, _model
: String;
1127 if not g_Game_IsServer
then Exit
;
1129 // Список названий моделей:
1130 m
:= g_PlayerModel_GetNames();
1135 if (gGameSettings
.GameType
= GT_SINGLE
) or (gGameSettings
.GameMode
= GM_COOP
) then
1136 Team
:= TEAM_COOP
// COOP
1138 if gGameSettings
.GameMode
= GM_DM
then
1139 Team
:= TEAM_NONE
// DM
1141 if Team
= TEAM_NONE
then
1142 Team
:= BotList
[num
].team
; // CTF / TDM
1144 // Выбираем настройки бота из списка по номеру или имени:
1145 lName
:= AnsiLowerCase(lName
);
1146 if (num
< 0) or (num
> Length(BotList
)-1) then
1148 if (num
= -1) and (lName
<> '') and (BotList
<> nil) then
1149 for a
:= 0 to High(BotList
) do
1150 if AnsiLowerCase(BotList
[a
].name
) = lName
then
1159 _name
:= BotList
[num
].name
;
1160 // Занято - выбираем случайное:
1161 if not g_Player_ValidName(_name
) then
1163 _name
:= Format('DFBOT%.2d', [Random(100)]);
1164 until g_Player_ValidName(_name
);
1167 _model
:= BotList
[num
].model
;
1168 // Нет такой - выбираем случайную:
1169 if not InSArray(_model
, m
) then
1170 _model
:= m
[Random(Length(m
))];
1173 with g_Player_Get(g_Player_Create(_model
, BotList
[num
].color
, Team
, True)) as TBot
do
1177 FDifficult
.DiagFire
:= BotList
[num
].diag_fire
;
1178 FDifficult
.InvisFire
:= BotList
[num
].invis_fire
;
1179 FDifficult
.DiagPrecision
:= BotList
[num
].diag_precision
;
1180 FDifficult
.FlyPrecision
:= BotList
[num
].fly_precision
;
1181 FDifficult
.Cover
:= BotList
[num
].cover
;
1182 FDifficult
.CloseJump
:= BotList
[num
].close_jump
;
1184 FHandicap
:= Handicap
;
1186 for a
:= WP_FIRST
to WP_LAST
do
1188 FDifficult
.WeaponPrior
[a
] := BotList
[num
].w_prior1
[a
];
1189 FDifficult
.CloseWeaponPrior
[a
] := BotList
[num
].w_prior2
[a
];
1190 //FDifficult.SafeWeaponPrior[a] := BotList[num].w_prior3[a];
1193 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [Name
]), True);
1195 if g_Game_IsNet
then MH_SEND_PlayerCreate(UID
);
1199 procedure g_Bot_RemoveAll();
1203 if not g_Game_IsServer
then Exit
;
1204 if gPlayers
= nil then Exit
;
1206 for a
:= 0 to High(gPlayers
) do
1207 if gPlayers
[a
] <> nil then
1208 if gPlayers
[a
] is TBot
then
1210 gPlayers
[a
].Lives
:= 0;
1211 gPlayers
[a
].Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
1212 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [gPlayers
[a
].Name
]), True);
1213 g_Player_Remove(gPlayers
[a
].FUID
);
1219 procedure g_Bot_MixNames();
1224 if BotNames
<> nil then
1225 for a
:= 0 to High(BotNames
) do
1227 b
:= Random(Length(BotNames
));
1229 Botnames
[a
] := BotNames
[b
];
1234 procedure g_Player_Remove(UID
: Word);
1238 if gPlayers
= nil then Exit
;
1240 if g_Game_IsServer
and g_Game_IsNet
then
1241 MH_SEND_PlayerDelete(UID
);
1243 for i
:= 0 to High(gPlayers
) do
1244 if gPlayers
[i
] <> nil then
1245 if gPlayers
[i
].FUID
= UID
then
1247 if gPlayers
[i
] is TPlayer
then
1248 TPlayer(gPlayers
[i
]).Free()
1250 TBot(gPlayers
[i
]).Free();
1256 procedure g_Player_Init();
1267 path
:= BOTNAMES_FILENAME
;
1268 if e_FindResource(DataDirs
, path
) = false then
1271 // Читаем возможные имена ботов из файла:
1272 AssignFile(F
, path
);
1283 SetLength(BotNames
, Length(BotNames
)+1);
1284 BotNames
[High(BotNames
)] := s
;
1292 // Читаем файл с параметрами ботов:
1293 config
:= TConfig
.CreateFile(path
);
1297 while config
.SectionExists(IntToStr(a
)) do
1299 SetLength(BotList
, Length(BotList
)+1);
1301 with BotList
[High(BotList
)] do
1304 name
:= config
.ReadStr(IntToStr(a
), 'name', '');
1306 model
:= config
.ReadStr(IntToStr(a
), 'model', '');
1308 if config
.ReadStr(IntToStr(a
), 'team', 'red') = 'red' then
1313 sa
:= parse(config
.ReadStr(IntToStr(a
), 'color', ''));
1314 color
.R
:= StrToIntDef(sa
[0], 0);
1315 color
.G
:= StrToIntDef(sa
[1], 0);
1316 color
.B
:= StrToIntDef(sa
[2], 0);
1317 // Вероятность стрельбы под углом:
1318 diag_fire
:= config
.ReadInt(IntToStr(a
), 'diag_fire', 0);
1319 // Вероятность ответного огня по невидимому сопернику:
1320 invis_fire
:= config
.ReadInt(IntToStr(a
), 'invis_fire', 0);
1321 // Точность стрельбы под углом:
1322 diag_precision
:= config
.ReadInt(IntToStr(a
), 'diag_precision', 0);
1323 // Точность стрельбы в полете:
1324 fly_precision
:= config
.ReadInt(IntToStr(a
), 'fly_precision', 0);
1325 // Точность уклонения от снарядов:
1326 cover
:= config
.ReadInt(IntToStr(a
), 'cover', 0);
1327 // Вероятность прыжка при приближении соперника:
1328 close_jump
:= config
.ReadInt(IntToStr(a
), 'close_jump', 0);
1329 // Приоритеты оружия для дальнего боя:
1330 sa
:= parse(config
.ReadStr(IntToStr(a
), 'w_prior1', ''));
1331 if Length(sa
) = 10 then
1333 w_prior1
[b
] := EnsureRange(StrToInt(sa
[b
]), 0, 9);
1334 // Приоритеты оружия для ближнего боя:
1335 sa
:= parse(config
.ReadStr(IntToStr(a
), 'w_prior2', ''));
1336 if Length(sa
) = 10 then
1338 w_prior2
[b
] := EnsureRange(StrToInt(sa
[b
]), 0, 9);
1340 {sa := parse(config.ReadStr(IntToStr(a), 'w_prior3', ''));
1341 if Length(sa) = 10 then
1343 w_prior3[b] := EnsureRange(StrToInt(sa[b]), 0, 9);}
1350 SetLength(SavedStates
, 0);
1353 procedure g_Player_Free();
1357 if gPlayers
<> nil then
1359 for i
:= 0 to High(gPlayers
) do
1360 if gPlayers
[i
] <> nil then
1362 if gPlayers
[i
] is TPlayer
then
1363 TPlayer(gPlayers
[i
]).Free()
1365 TBot(gPlayers
[i
]).Free();
1374 SetLength(SavedStates
, 0);
1377 procedure g_Player_PreUpdate();
1381 if gPlayers
= nil then Exit
;
1382 for i
:= 0 to High(gPlayers
) do
1383 if gPlayers
[i
] <> nil then
1384 gPlayers
[i
].PreUpdate();
1387 procedure g_Player_UpdateAll();
1391 if gPlayers
= nil then Exit
;
1393 //e_WriteLog('***g_Player_UpdateAll: ENTER', MSG_WARNING);
1394 for i
:= 0 to High(gPlayers
) do
1396 if gPlayers
[i
] <> nil then
1398 if gPlayers
[i
] is TPlayer
then
1400 gPlayers
[i
].Update();
1401 gPlayers
[i
].RealizeCurrentWeapon(); // WARNING! DO NOT MOVE THIS INTO `Update()`!
1405 // bot updates weapons in `UpdateCombat()`
1406 TBot(gPlayers
[i
]).Update();
1410 //e_WriteLog('***g_Player_UpdateAll: EXIT', MSG_WARNING);
1413 function g_Player_Get(UID
: Word): TPlayer
;
1419 if gPlayers
= nil then
1422 for a
:= 0 to High(gPlayers
) do
1423 if gPlayers
[a
] <> nil then
1424 if gPlayers
[a
].FUID
= UID
then
1426 Result
:= gPlayers
[a
];
1431 function g_Player_GetCount(): Byte;
1437 if gPlayers
= nil then
1440 for a
:= 0 to High(gPlayers
) do
1441 if gPlayers
[a
] <> nil then
1442 Result
:= Result
+ 1;
1445 function g_Player_GetStats(): TPlayerStatArray
;
1451 if gPlayers
= nil then Exit
;
1453 for a
:= 0 to High(gPlayers
) do
1454 if gPlayers
[a
] <> nil then
1456 SetLength(Result
, Length(Result
)+1);
1457 with Result
[High(Result
)] do
1460 Ping
:= gPlayers
[a
].FPing
;
1461 Loss
:= gPlayers
[a
].FLoss
;
1462 Name
:= gPlayers
[a
].FName
;
1463 Team
:= gPlayers
[a
].FTeam
;
1464 Frags
:= gPlayers
[a
].FFrags
;
1465 Deaths
:= gPlayers
[a
].FDeath
;
1466 Kills
:= gPlayers
[a
].FKills
;
1467 Color
:= gPlayers
[a
].FModel
.Color
;
1468 Lives
:= gPlayers
[a
].FLives
;
1469 Spectator
:= gPlayers
[a
].FSpectator
;
1470 UID
:= gPlayers
[a
].FUID
;
1475 procedure g_Player_ResetReady();
1479 if not g_Game_IsServer
then Exit
;
1480 if gPlayers
= nil then Exit
;
1482 for a
:= 0 to High(gPlayers
) do
1483 if gPlayers
[a
] <> nil then
1485 gPlayers
[a
].FReady
:= False;
1486 if g_Game_IsNet
then
1487 MH_SEND_GameEvent(NET_EV_INTER_READY
, gPlayers
[a
].UID
, 'N');
1491 procedure g_Player_RememberAll
;
1495 for i
:= Low(gPlayers
) to High(gPlayers
) do
1496 if (gPlayers
[i
] <> nil) and gPlayers
[i
].alive
then
1497 gPlayers
[i
].RememberState
;
1500 procedure g_Player_ResetAll(Force
, Silent
: Boolean);
1504 gTeamStat
[TEAM_RED
].Goals
:= 0;
1505 gTeamStat
[TEAM_BLUE
].Goals
:= 0;
1507 if gPlayers
<> nil then
1508 for i
:= 0 to High(gPlayers
) do
1509 if gPlayers
[i
] <> nil then
1511 gPlayers
[i
].Reset(Force
);
1513 if gPlayers
[i
] is TPlayer
then
1515 if (not gPlayers
[i
].FSpectator
) or gPlayers
[i
].FWantsInGame
then
1516 gPlayers
[i
].Respawn(Silent
)
1518 gPlayers
[i
].Spectate();
1521 TBot(gPlayers
[i
]).Respawn(Silent
);
1525 function g_Player_CreateCorpse(Player
: TPlayer
): Integer;
1533 if Player
.alive
then
1536 // Разрываем связь с прежним трупом:
1537 i
:= Player
.FCorpse
;
1538 if (i
>= 0) and (i
< Length(gCorpses
)) then
1540 if (gCorpses
[i
] <> nil) and (gCorpses
[i
].FPlayerUID
= Player
.FUID
) then
1541 gCorpses
[i
].FPlayerUID
:= 0;
1544 if Player
.FObj
.Y
>= gMapInfo
.Height
+128 then
1549 if (FHealth
>= -50) or (gGibsCount
= 0) then
1551 if (gCorpses
= nil) or (Length(gCorpses
) = 0) then
1555 for find_id
:= 0 to High(gCorpses
) do
1556 if gCorpses
[find_id
] = nil then
1563 find_id
:= Random(Length(gCorpses
));
1565 gCorpses
[find_id
] := TCorpse
.Create(FObj
.X
, FObj
.Y
, FModel
.GetName(), FHealth
< -20);
1566 gCorpses
[find_id
].FModel
.Color
:= FModel
.Color
;
1567 gCorpses
[find_id
].FObj
.Vel
:= FObj
.Vel
;
1568 gCorpses
[find_id
].FObj
.Accel
:= FObj
.Accel
;
1569 gCorpses
[find_id
].FPlayerUID
:= FUID
;
1574 g_Player_CreateGibs(FObj
.X
+ PLAYER_RECT_CX
, FObj
.Y
+ PLAYER_RECT_CY
, FModel
.id
, FModel
.Color
);
1578 procedure g_Player_CreateShell(fX
, fY
, dX
, dY
: Integer; T
: Byte);
1582 if (gShells
= nil) or (Length(gShells
) = 0) then
1585 with gShells
[CurrentShell
] do
1591 if T
= SHELL_BULLET
then
1593 if g_Texture_Get('TEXTURE_SHELL_BULLET', SID
) then
1597 Obj
.Rect
.Width
:= 4;
1598 Obj
.Rect
.Height
:= 2;
1602 if g_Texture_Get('TEXTURE_SHELL_SHELL', SID
) then
1606 Obj
.Rect
.Width
:= 7;
1607 Obj
.Rect
.Height
:= 3;
1613 g_Obj_Push(@Obj
, dX
+ Random(4)-Random(4), dY
-Random(4));
1614 positionChanged(); // this updates spatial accelerators
1615 RAngle
:= Random(360);
1616 Timeout
:= gTime
+ SHELL_TIMEOUT
;
1618 if CurrentShell
>= High(gShells
) then
1625 procedure g_Player_CreateGibs (fX
, fY
, mid
: Integer; fColor
: TRGB
);
1628 GibsArray
: TGibsArray
;
1633 if (gGibs
= nil) or (Length(gGibs
) = 0) then
1635 if not g_PlayerModel_GetGibs(mid
, GibsArray
) then
1637 Blood
:= PlayerModelsArray
[mid
].Blood
;
1639 for a
:= 0 to High(GibsArray
) do
1640 with gGibs
[CurrentGib
] do
1643 GibID
:= GibsArray
[a
];
1647 Obj
.Rect
:= r_PlayerModel_GetGibRect(ModelID
, GibID
);
1648 Obj
.X
:= fX
- Obj
.Rect
.X
- (Obj
.Rect
.Width
div 2);
1649 Obj
.Y
:= fY
- Obj
.Rect
.Y
- (Obj
.Rect
.Height
div 2);
1650 g_Obj_PushA(@Obj
, 25 + Random(10), Random(361));
1651 positionChanged(); // this updates spatial accelerators
1652 RAngle
:= Random(360);
1654 if gBloodCount
> 0 then
1655 g_GFX_Blood(fX
, fY
, 16*gBloodCount
+Random(5*gBloodCount
), -16+Random(33), -16+Random(33),
1656 Random(48), Random(48), Blood
.R
, Blood
.G
, Blood
.B
, Blood
.Kind
);
1658 if CurrentGib
>= High(gGibs
) then
1665 procedure g_Player_UpdatePhysicalObjects();
1671 procedure ShellSound_Bounce(X
, Y
: Integer; T
: Byte);
1676 if T
= SHELL_BULLET
then
1677 g_Sound_PlayExAt('SOUND_PLAYER_CASING' + IntToStr(k
), X
, Y
)
1679 g_Sound_PlayExAt('SOUND_PLAYER_SHELL' + IntToStr(k
), X
, Y
);
1684 if gGibs
<> nil then
1685 for i
:= 0 to High(gGibs
) do
1686 if gGibs
[i
].alive
then
1693 mr
:= g_Obj_Move(@Obj
, True, False, True);
1694 positionChanged(); // this updates spatial accelerators
1696 if WordBool(mr
and MOVE_FALLOUT
) then
1702 // Отлетает от удара о стену/потолок/пол:
1703 if WordBool(mr
and MOVE_HITWALL
) then
1704 Obj
.Vel
.X
:= -(vel
.X
div 2);
1705 if WordBool(mr
and (MOVE_HITCEIL
or MOVE_HITLAND
)) then
1706 Obj
.Vel
.Y
:= -(vel
.Y
div 2);
1708 if (Obj
.Vel
.X
>= 0) then
1710 RAngle
:= RAngle
+ Abs(Obj
.Vel
.X
)*6 + Abs(Obj
.Vel
.Y
);
1711 if RAngle
>= 360 then
1712 RAngle
:= RAngle
mod 360;
1713 end else begin // Counter-clockwise
1714 RAngle
:= RAngle
- Abs(Obj
.Vel
.X
)*6 - Abs(Obj
.Vel
.Y
);
1716 RAngle
:= (360 - (Abs(RAngle
) mod 360)) mod 360;
1719 // Сопротивление воздуха для куска трупа:
1720 if gTime
mod (GAME_TICK
*3) = 0 then
1721 Obj
.Vel
.X
:= z_dec(Obj
.Vel
.X
, 1);
1725 if gCorpses
<> nil then
1726 for i
:= 0 to High(gCorpses
) do
1727 if gCorpses
[i
] <> nil then
1728 if gCorpses
[i
].State
= CORPSE_STATE_REMOVEME
then
1734 gCorpses
[i
].Update();
1737 if gShells
<> nil then
1738 for i
:= 0 to High(gShells
) do
1739 if gShells
[i
].alive
then
1746 mr
:= g_Obj_Move(@Obj
, True, False, True);
1747 positionChanged(); // this updates spatial accelerators
1749 if WordBool(mr
and MOVE_FALLOUT
) or (gShells
[i
].Timeout
< gTime
) then
1755 // Отлетает от удара о стену/потолок/пол:
1756 if WordBool(mr
and MOVE_HITWALL
) then
1758 Obj
.Vel
.X
:= -(vel
.X
div 2);
1759 if not WordBool(mr
and MOVE_INWATER
) then
1760 ShellSound_Bounce(Obj
.X
, Obj
.Y
, SType
);
1762 if WordBool(mr
and (MOVE_HITCEIL
or MOVE_HITLAND
)) then
1764 Obj
.Vel
.Y
:= -(vel
.Y
div 2);
1765 if Obj
.Vel
.X
<> 0 then Obj
.Vel
.X
:= Obj
.Vel
.X
div 2;
1766 if (Obj
.Vel
.X
= 0) and (Obj
.Vel
.Y
= 0) then
1768 if RAngle
mod 90 <> 0 then
1769 RAngle
:= (RAngle
div 90) * 90;
1771 else if not WordBool(mr
and MOVE_INWATER
) then
1772 ShellSound_Bounce(Obj
.X
, Obj
.Y
, SType
);
1775 if (Obj
.Vel
.X
>= 0) then
1777 RAngle
:= RAngle
+ Abs(Obj
.Vel
.X
)*8 + Abs(Obj
.Vel
.Y
);
1778 if RAngle
>= 360 then
1779 RAngle
:= RAngle
mod 360;
1780 end else begin // Counter-clockwise
1781 RAngle
:= RAngle
- Abs(Obj
.Vel
.X
)*8 - Abs(Obj
.Vel
.Y
);
1783 RAngle
:= (360 - (Abs(RAngle
) mod 360)) mod 360;
1789 procedure TGib
.getMapBox (out x
, y
, w
, h
: Integer); inline;
1791 x
:= Obj
.X
+Obj
.Rect
.X
;
1792 y
:= Obj
.Y
+Obj
.Rect
.Y
;
1793 w
:= Obj
.Rect
.Width
;
1794 h
:= Obj
.Rect
.Height
;
1797 procedure TGib
.moveBy (dx
, dy
: Integer); inline;
1799 if (dx
<> 0) or (dy
<> 0) then
1808 procedure TShell
.getMapBox (out x
, y
, w
, h
: Integer); inline;
1812 w
:= Obj
.Rect
.Width
;
1813 h
:= Obj
.Rect
.Height
;
1816 procedure TShell
.moveBy (dx
, dy
: Integer); inline;
1818 if (dx
<> 0) or (dy
<> 0) then
1827 procedure TGib
.positionChanged (); inline; begin end;
1828 procedure TShell
.positionChanged (); inline; begin end;
1831 procedure g_Player_RemoveAllCorpses();
1837 SetLength(gGibs
, MaxGibs
);
1838 SetLength(gShells
, MaxGibs
);
1842 if gCorpses
<> nil then
1843 for i
:= 0 to High(gCorpses
) do
1847 SetLength(gCorpses
, MaxCorpses
);
1850 procedure g_Player_Corpses_SaveState (st
: TStream
);
1854 // Считаем количество существующих трупов
1856 for i
:= 0 to High(gCorpses
) do if (gCorpses
[i
] <> nil) then Inc(count
);
1858 // Количество трупов
1859 utils
.writeInt(st
, LongInt(count
));
1861 if (count
= 0) then exit
;
1864 for i
:= 0 to High(gCorpses
) do
1866 if gCorpses
[i
] <> nil then
1869 utils
.writeStr(st
, gCorpses
[i
].FModel
.GetName());
1871 utils
.writeBool(st
, gCorpses
[i
].Mess
);
1872 // Сохраняем данные трупа:
1873 gCorpses
[i
].SaveState(st
);
1879 procedure g_Player_Corpses_LoadState (st
: TStream
);
1887 g_Player_RemoveAllCorpses();
1889 // Количество трупов:
1890 count
:= utils
.readLongInt(st
);
1891 if (count
< 0) or (count
> Length(gCorpses
)) then raise XStreamError
.Create('invalid number of corpses');
1893 if (count
= 0) then exit
;
1896 for i
:= 0 to count
-1 do
1899 str
:= utils
.readStr(st
);
1901 b
:= utils
.readBool(st
);
1903 gCorpses
[i
] := TCorpse
.Create(0, 0, str
, b
);
1904 // Загружаем данные трупа
1905 gCorpses
[i
].LoadState(st
);
1912 function TPlayer
.isValidViewPort (): Boolean; inline; begin result
:= (viewPortW
> 0) and (viewPortH
> 0); end;
1914 procedure TPlayer
.BFGHit();
1916 g_Weapon_BFGHit(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
1917 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2));
1918 if g_Game_IsServer
and g_Game_IsNet
then
1919 MH_SEND_Effect(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
1920 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2),
1924 procedure TPlayer
.ChangeModel(ModelName
: string);
1926 locModel
: TPlayerModel
;
1928 locModel
:= g_PlayerModel_Get(ModelName
);
1929 if locModel
= nil then Exit
;
1935 procedure TPlayer
.SetModel(ModelName
: string);
1939 m
:= g_PlayerModel_Get(ModelName
);
1942 g_SimpleError(Format(_lc
[I_GAME_ERROR_MODEL_FALLBACK
], [ModelName
]));
1943 m
:= g_PlayerModel_Get('doomer');
1946 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], ['doomer']));
1951 if FModel
<> nil then
1956 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
1957 FModel
.Color
:= FColor
1959 FModel
.Color
:= TEAMCOLOR
[FTeam
];
1960 FModel
.SetWeapon(FCurrWeap
);
1961 FModel
.SetFlag(FFlag
);
1962 SetDirection(FDirection
);
1965 procedure TPlayer
.SetColor(Color
: TRGB
);
1968 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
1969 if FModel
<> nil then FModel
.Color
:= Color
;
1972 function TPlayer
.GetColor(): TRGB
;
1974 result
:= FModel
.Color
;
1977 procedure TPlayer
.SwitchTeam
;
1979 if g_Game_IsClient
then
1981 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then Exit
;
1983 if gGameOn
and FAlive
then
1984 Kill(K_SIMPLEKILL
, FUID
, HIT_SELF
);
1986 if FTeam
= TEAM_RED
then
1988 ChangeTeam(TEAM_BLUE
);
1989 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_BLUE
], [FName
]), True);
1990 if g_Game_IsNet
then
1991 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM
, TEAM_BLUE
, FName
);
1995 ChangeTeam(TEAM_RED
);
1996 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_RED
], [FName
]), True);
1997 if g_Game_IsNet
then
1998 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM
, TEAM_RED
, FName
);
2000 FPreferredTeam
:= FTeam
;
2003 procedure TPlayer
.ChangeTeam(Team
: Byte);
2010 TEAM_RED
, TEAM_BLUE
:
2011 FModel
.Color
:= TEAMCOLOR
[Team
];
2013 FModel
.Color
:= FColor
;
2015 if (FTeam
<> OldTeam
) and g_Game_IsNet
and g_Game_IsServer
then
2016 MH_SEND_PlayerStats(FUID
);
2020 procedure TPlayer.CollideItem();
2025 if gItems = nil then Exit;
2026 if not FAlive then Exit;
2028 for i := 0 to High(gItems) do
2031 if (ItemType <> ITEM_NONE) and alive then
2032 if g_Obj_Collide(FObj.X+PLAYER_RECT.X, FObj.Y+PLAYER_RECT.Y, PLAYER_RECT.Width,
2033 PLAYER_RECT.Height, @Obj) then
2035 if not PickItem(ItemType, gItems[i].Respawnable, r) then Continue;
2037 if ItemType in [ITEM_SPHERE_BLUE, ITEM_SPHERE_WHITE, ITEM_INVUL] then
2038 g_Sound_PlayExAt('SOUND_ITEM_GETRULEZ', FObj.X, FObj.Y)
2039 else if ItemType in [ITEM_MEDKIT_SMALL, ITEM_MEDKIT_LARGE, ITEM_MEDKIT_BLACK] then
2040 g_Sound_PlayExAt('SOUND_ITEM_GETMED', FObj.X, FObj.Y)
2041 else g_Sound_PlayExAt('SOUND_ITEM_GETITEM', FObj.X, FObj.Y);
2043 // Надо убрать с карты, если это не ключ, которым нужно поделится с другим игроком:
2044 if r and not ((ItemType in [ITEM_KEY_RED, ITEM_KEY_GREEN, ITEM_KEY_BLUE]) and
2045 (gGameSettings.GameType = GT_SINGLE) and
2046 (g_Player_GetCount() > 1)) then
2047 if not Respawnable then g_Items_Remove(i) else g_Items_Pick(i);
2053 function TPlayer
.CollideLevel(XInc
, YInc
: Integer): Boolean;
2055 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
2056 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_WALL
,
2060 constructor TPlayer
.Create();
2066 mEDamageType
:= HIT_SOME
;
2072 FSawSound
:= TPlayableSound
.Create();
2073 FSawSoundIdle
:= TPlayableSound
.Create();
2074 FSawSoundHit
:= TPlayableSound
.Create();
2075 FSawSoundSelect
:= TPlayableSound
.Create();
2076 FFlameSoundOn
:= TPlayableSound
.Create();
2077 FFlameSoundOff
:= TPlayableSound
.Create();
2078 FFlameSoundWork
:= TPlayableSound
.Create();
2079 FJetSoundFly
:= TPlayableSound
.Create();
2080 FJetSoundOn
:= TPlayableSound
.Create();
2081 FJetSoundOff
:= TPlayableSound
.Create();
2083 FSawSound
.SetByName('SOUND_WEAPON_FIRESAW');
2084 FSawSoundIdle
.SetByName('SOUND_WEAPON_IDLESAW');
2085 FSawSoundHit
.SetByName('SOUND_WEAPON_HITSAW');
2086 FSawSoundSelect
.SetByName('SOUND_WEAPON_SELECTSAW');
2087 FFlameSoundOn
.SetByName('SOUND_WEAPON_FLAMEON');
2088 FFlameSoundOff
.SetByName('SOUND_WEAPON_FLAMEOFF');
2089 FFlameSoundWork
.SetByName('SOUND_WEAPON_FLAMEWORK');
2090 FJetSoundFly
.SetByName('SOUND_PLAYER_JETFLY');
2091 FJetSoundOn
.SetByName('SOUND_PLAYER_JETON');
2092 FJetSoundOff
.SetByName('SOUND_PLAYER_JETOFF');
2094 FSpectatePlayer
:= -1;
2098 FSavedStateNum
:= -1;
2106 FActualModelName
:= 'doomer';
2109 FObj
.Rect
:= PLAYER_RECT
;
2111 FBFGFireCounter
:= -1;
2112 FJustTeleported
:= False;
2115 FWaitForFirstSpawn
:= false;
2116 FPunchAnim
:= TAnimationState
.Create(False, 1, 4);
2122 procedure TPlayer
.positionChanged (); inline;
2126 procedure TPlayer
.doDamage (v
: Integer);
2128 if (v
<= 0) then exit
;
2129 if (v
> 32767) then v
:= 32767;
2130 Damage(v
, 0, 0, 0, mEDamageType
);
2133 procedure TPlayer
.Damage(value
: Word; SpawnerUID
: Word; vx
, vy
: Integer; t
: Byte);
2137 if (not g_Game_IsClient
) and (not FAlive
) then
2142 // Неуязвимость не спасает от ловушек:
2143 if ((t
= HIT_TRAP
) or (t
= HIT_SELF
)) and (not FGodMode
) then
2145 if not g_Game_IsClient
then
2148 if t
= HIT_TRAP
then
2150 // Ловушка убивает сразу:
2152 Kill(K_EXTRAHARDKILL
, SpawnerUID
, t
);
2154 if t
= HIT_SELF
then
2158 Kill(K_SIMPLEKILL
, SpawnerUID
, t
);
2161 // Обнулить действия примочек, чтобы фон пропал
2162 FMegaRulez
[MR_SUIT
] := 0;
2163 FMegaRulez
[MR_INVUL
] := 0;
2164 FMegaRulez
[MR_INVIS
] := 0;
2169 // Но от остального спасает:
2170 if FMegaRulez
[MR_INVUL
] >= gTime
then
2177 // Если есть урон своим, или ранил сам себя, или тебя ранил противник:
2178 if LongBool(gGameSettings
.Options
and GAME_OPTION_TEAMDAMAGE
) or
2179 (SpawnerUID
= FUID
) or
2180 (not SameTeam(FUID
, SpawnerUID
)) then
2182 FLastSpawnerUID
:= SpawnerUID
;
2184 // Кровь (пузырьки, если в воде):
2185 if gBloodCount
> 0 then
2187 c
:= Min(value
, 200)*gBloodCount
+ Random(Min(value
, 200) div 2);
2188 if value
div 4 <= c
then
2189 c
:= c
- (value
div 4)
2193 if (t
= HIT_SOME
) and (vx
= 0) and (vy
= 0) then
2197 HIT_TRAP
, HIT_ACID
, HIT_FLAME
, HIT_SELF
: MakeBloodSimple(c
);
2198 HIT_BFG
, HIT_ROCKET
, HIT_SOME
: MakeBloodVector(c
, vx
, vy
);
2201 if t
= HIT_WATER
then
2202 g_GFX_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
2203 FObj
.Y
+PLAYER_RECT
.Y
-4, value
div 2, 8, 4);
2208 Inc(FDamageBuffer
, value
);
2212 FPain
:= FPain
+ value
;
2215 if g_Game_IsServer
and g_Game_IsNet
then
2217 MH_SEND_PlayerDamage(FUID
, t
, SpawnerUID
, value
, vx
, vy
);
2218 MH_SEND_PlayerStats(FUID
);
2219 MH_SEND_PlayerPos(False, FUID
);
2223 function TPlayer
.Heal(value
: Word; Soft
: Boolean): Boolean;
2226 if g_Game_IsClient
then
2231 if Soft
and (FHealth
< PLAYER_HP_SOFT
) then
2233 IncMax(FHealth
, value
, PLAYER_HP_SOFT
);
2236 if (not Soft
) and (FHealth
< PLAYER_HP_LIMIT
) then
2238 IncMax(FHealth
, value
, PLAYER_HP_LIMIT
);
2242 if Result
and g_Game_IsServer
and g_Game_IsNet
then
2243 MH_SEND_PlayerStats(FUID
);
2246 destructor TPlayer
.Destroy();
2248 if (gPlayer1
<> nil) and (gPlayer1
.FUID
= FUID
) then
2250 if (gPlayer2
<> nil) and (gPlayer2
.FUID
= FUID
) then
2254 FSawSoundIdle
.Free();
2255 FSawSoundHit
.Free();
2256 FSawSoundSelect
.Free();
2257 FFlameSoundOn
.Free();
2258 FFlameSoundOff
.Free();
2259 FFlameSoundWork
.Free();
2260 FJetSoundFly
.Free();
2262 FJetSoundOff
.Free();
2269 procedure TPlayer
.DoPunch();
2275 procedure TPlayer
.Fire();
2277 f
, DidFire
: Boolean;
2278 wx
, wy
, xd
, yd
: Integer;
2281 if g_Game_IsClient
then Exit
;
2282 // FBFGFireCounter - время перед выстрелом (для BFG)
2283 // FReloading - время после выстрела (для всего)
2291 if FReloading
[FCurrWeap
] <> 0 then Exit
;
2296 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
2297 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
2298 xd
:= wx
+IfThen(FDirection
= TDirection
.D_LEFT
, -30, 30);
2299 yd
:= wy
+firediry();
2305 if R_BERSERK
in FRulez
then
2307 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
2308 locobj
.X
:= FObj
.X
+FObj
.Rect
.X
;
2309 locobj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
2312 locobj
.rect
.Width
:= 39;
2313 locobj
.rect
.Height
:= 52;
2314 locobj
.Vel
.X
:= (xd
-wx
) div 2;
2315 locobj
.Vel
.Y
:= (yd
-wy
) div 2;
2316 locobj
.Accel
.X
:= xd
-wx
;
2317 locobj
.Accel
.y
:= yd
-wy
;
2319 if g_Weapon_Hit(@locobj
, 50, FUID
, HIT_SOME
) <> 0 then
2320 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
2322 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
2324 if (gFlash
= 1) and (FPain
< 50) then FPain
:= min(FPain
+ 25, 50);
2328 g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
2332 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2337 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
2338 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
2340 FSawSoundSelect
.Stop();
2342 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
2344 else if not FSawSoundHit
.IsPlaying() then
2346 FSawSoundSelect
.Stop();
2347 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
2350 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2356 if FAmmo
[A_BULLETS
] > 0 then
2358 g_Weapon_pistol(wx
, wy
, xd
, yd
, FUID
);
2359 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2360 Dec(FAmmo
[A_BULLETS
]);
2361 FFireAngle
:= FAngle
;
2364 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
2365 GameVelX
, GameVelY
-2, SHELL_BULLET
);
2369 if FAmmo
[A_SHELLS
] > 0 then
2371 g_Weapon_shotgun(wx
, wy
, xd
, yd
, FUID
);
2372 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', wx
, wy
);
2373 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2374 Dec(FAmmo
[A_SHELLS
]);
2375 FFireAngle
:= FAngle
;
2379 FShellType
:= SHELL_SHELL
;
2383 if FAmmo
[A_SHELLS
] >= 2 then
2385 g_Weapon_dshotgun(wx
, wy
, xd
, yd
, FUID
);
2386 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2387 Dec(FAmmo
[A_SHELLS
], 2);
2388 FFireAngle
:= FAngle
;
2392 FShellType
:= SHELL_DBLSHELL
;
2396 if FAmmo
[A_BULLETS
] > 0 then
2398 g_Weapon_mgun(wx
, wy
, xd
, yd
, FUID
);
2399 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', wx
, wy
);
2400 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2401 Dec(FAmmo
[A_BULLETS
]);
2402 FFireAngle
:= FAngle
;
2405 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
2406 GameVelX
, GameVelY
-2, SHELL_BULLET
);
2409 WEAPON_ROCKETLAUNCHER
:
2410 if FAmmo
[A_ROCKETS
] > 0 then
2412 g_Weapon_rocket(wx
, wy
, xd
, yd
, FUID
);
2413 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2414 Dec(FAmmo
[A_ROCKETS
]);
2415 FFireAngle
:= FAngle
;
2421 if FAmmo
[A_CELLS
] > 0 then
2423 g_Weapon_plasma(wx
, wy
, xd
, yd
, FUID
);
2424 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2425 Dec(FAmmo
[A_CELLS
]);
2426 FFireAngle
:= FAngle
;
2432 if (FAmmo
[A_CELLS
] >= 40) and (FBFGFireCounter
= -1) then
2434 FBFGFireCounter
:= 17;
2435 if not FNoReload
then
2436 g_Sound_PlayExAt('SOUND_WEAPON_STARTFIREBFG', FObj
.X
, FObj
.Y
);
2437 Dec(FAmmo
[A_CELLS
], 40);
2441 WEAPON_SUPERPULEMET
:
2442 if FAmmo
[A_SHELLS
] > 0 then
2444 g_Weapon_shotgun(wx
, wy
, xd
, yd
, FUID
);
2445 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', wx
, wy
);
2446 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2447 Dec(FAmmo
[A_SHELLS
]);
2448 FFireAngle
:= FAngle
;
2451 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
2452 GameVelX
, GameVelY
-2, SHELL_SHELL
);
2455 WEAPON_FLAMETHROWER
:
2456 if FAmmo
[A_FUEL
] > 0 then
2458 g_Weapon_flame(wx
, wy
, xd
, yd
, FUID
);
2460 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2462 FFireAngle
:= FAngle
;
2469 if g_Game_IsNet
and g_Game_IsServer
then MH_SEND_PlayerStats(FUID
);
2473 if g_Game_IsNet
then
2477 if FCurrWeap
<> WEAPON_BFG
then
2478 MH_SEND_PlayerFire(FUID
, FCurrWeap
, wx
, wy
, xd
, yd
, LastShotID
)
2480 if not FNoReload
then
2481 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_WEAPON_STARTFIREBFG');
2484 MH_SEND_PlayerStats(FUID
);
2489 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
2490 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
2491 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
2494 function TPlayer
.GetAmmoByWeapon(Weapon
: Byte): Word;
2497 WEAPON_PISTOL
, WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
];
2498 WEAPON_SHOTGUN1
, WEAPON_SHOTGUN2
, WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
];
2499 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
];
2500 WEAPON_PLASMA
, WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
];
2501 WEAPON_FLAMETHROWER
: Result
:= FAmmo
[A_FUEL
];
2506 function TPlayer
.HeadInLiquid(XInc
, YInc
: Integer): Boolean;
2508 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
+XInc
, FObj
.Y
+PLAYER_HEADRECT
.Y
+YInc
,
2509 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
2510 PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, True);
2513 procedure TPlayer
.FlamerOn
;
2515 FFlameSoundOff
.Stop();
2516 FFlameSoundOff
.SetPosition(0);
2519 if (not FFlameSoundOn
.IsPlaying()) and (not FFlameSoundWork
.IsPlaying()) then
2520 FFlameSoundWork
.PlayAt(FObj
.X
, FObj
.Y
);
2524 FFlameSoundOn
.PlayAt(FObj
.X
, FObj
.Y
);
2529 procedure TPlayer
.FlamerOff
;
2533 FFlameSoundOn
.Stop();
2534 FFlameSoundOn
.SetPosition(0);
2535 FFlameSoundWork
.Stop();
2536 FFlameSoundWork
.SetPosition(0);
2537 FFlameSoundOff
.PlayAt(FObj
.X
, FObj
.Y
);
2542 procedure TPlayer
.JetpackOn
;
2546 FJetSoundOn
.SetPosition(0);
2547 FJetSoundOn
.PlayAt(FObj
.X
, FObj
.Y
);
2551 procedure TPlayer
.JetpackOff
;
2555 FJetSoundOff
.SetPosition(0);
2556 FJetSoundOff
.PlayAt(FObj
.X
, FObj
.Y
);
2559 procedure TPlayer
.CatchFire(Attacker
: Word; Timeout
: Integer = PLAYER_BURN_TIME
);
2561 if Timeout
<= 0 then
2563 if (FMegaRulez
[MR_SUIT
] > gTime
) or (FMegaRulez
[MR_INVUL
] > gTime
) then
2564 exit
; // Не загораемся когда есть защита
2565 if g_Obj_CollidePanel(@FObj
, 0, 0, PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
) then
2566 exit
; // Не подгораем в воде на всякий случай
2567 if FFireTime
<= 0 then
2568 g_Sound_PlayExAt('SOUND_IGNITE', FObj
.X
, FObj
.Y
);
2569 FFireTime
:= Timeout
;
2570 FFireAttacker
:= Attacker
;
2571 if g_Game_IsNet
and g_Game_IsServer
then
2572 MH_SEND_PlayerStats(FUID
);
2575 procedure TPlayer
.Jump();
2577 if gFly
or FJetpack
then
2579 // Полет (чит-код или джетпак):
2580 if FObj
.Vel
.Y
> -VEL_FLY
then
2581 FObj
.Vel
.Y
:= FObj
.Vel
.Y
- 3;
2584 if FJetFuel
> 0 then
2586 if (FJetFuel
< 1) and g_Game_IsServer
then
2590 if g_Game_IsNet
then
2591 MH_SEND_PlayerStats(FUID
);
2597 // Не включать джетпак в режиме прохождения сквозь стены
2599 FCanJetpack
:= False;
2601 // Прыгаем или всплываем:
2602 if (CollideLevel(0, 1) or
2603 g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
+36, PLAYER_RECT
.Width
,
2604 PLAYER_RECT
.Height
-33, PANEL_STEP
, False)
2605 ) and (FObj
.Accel
.Y
= 0) then // Не прыгать, если есть вертикальное ускорение
2607 FObj
.Vel
.Y
:= -VEL_JUMP
;
2608 FCanJetpack
:= False;
2612 if BodyInLiquid(0, 0) then
2613 FObj
.Vel
.Y
:= -VEL_SW
2614 else if (FJetFuel
> 0) and FCanJetpack
and
2615 g_Game_IsServer
and (not g_Obj_CollideLiquid(@FObj
, 0, 0)) then
2619 if g_Game_IsNet
then
2620 MH_SEND_PlayerStats(FUID
);
2625 procedure TPlayer
.Kill(KillType
: Byte; SpawnerUID
: Word; t
: Byte);
2627 a
, i
, k
, ab
, ar
: Byte;
2631 srv
, netsrv
: Boolean;
2637 procedure PushItem(t
: Byte);
2641 id
:= g_Items_Create(FObj
.X
, FObj
.Y
, t
, True, False);
2642 it
:= g_Items_ByIdx(id
);
2643 if KillType
= K_EXTRAHARDKILL
then // -7..+7; -8..0
2645 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-7+Random(15),
2646 (FObj
.Vel
.Y
div 2)-Random(9));
2647 it
.positionChanged(); // this updates spatial accelerators
2651 if KillType
= K_HARDKILL
then // -5..+5; -5..0
2653 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-5+Random(11),
2654 (FObj
.Vel
.Y
div 2)-Random(6));
2656 else // -3..+3; -3..0
2658 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-3+Random(7),
2659 (FObj
.Vel
.Y
div 2)-Random(4));
2661 it
.positionChanged(); // this updates spatial accelerators
2664 if g_Game_IsNet
and g_Game_IsServer
then
2665 MH_SEND_ItemSpawn(True, id
);
2669 DoFrags
:= (gGameSettings
.MaxLives
= 0) or (gGameSettings
.GameMode
= GM_COOP
);
2670 Srv
:= g_Game_IsServer
;
2671 Netsrv
:= g_Game_IsServer
and g_Game_IsNet
;
2672 if Srv
then FDeath
:= FDeath
+ 1;
2677 if not FPhysics
then
2683 if (gGameSettings
.MaxLives
> 0) and Srv
and (gLMSRespawn
= LMS_RESPAWN_NONE
) then
2685 if FLives
> 0 then FLives
:= FLives
- 1;
2686 if FLives
= 0 then FNoRespawn
:= True;
2689 // Номер типа смерти:
2692 K_SIMPLEKILL
: a
:= 1;
2694 K_EXTRAHARDKILL
: a
:= 3;
2699 if not FModel
.PlaySound(MODELSOUND_DIE
, a
, FObj
.X
, FObj
.Y
) then
2701 if FModel
.PlaySound(MODELSOUND_DIE
, i
, FObj
.X
, FObj
.Y
) then
2708 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN1
;
2710 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN2
;
2711 K_EXTRAHARDKILL
, K_FALLKILL
:
2712 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN3
;
2715 // Переключаем состояние:
2719 K_HARDKILL
, K_EXTRAHARDKILL
:
2723 // Реакция монстров на смерть игрока:
2724 if (KillType
<> K_FALLKILL
) and (Srv
) then
2725 g_Monsters_killedp();
2727 if SpawnerUID
= FUID
then
2729 if Srv
and (DoFrags
or (gGameSettings
.GameMode
= GM_TDM
)) then
2734 g_Console_Add(Format(_lc
[I_PLAYER_KILL_SELF
], [FName
]), True);
2737 if g_GetUIDType(SpawnerUID
) = UID_PLAYER
then
2738 begin // Убит другим игроком
2739 KP
:= g_Player_Get(SpawnerUID
);
2740 if (KP
<> nil) and Srv
then
2742 if (DoFrags
or (gGameSettings
.GameMode
= GM_TDM
)) then
2743 if SameTeam(FUID
, SpawnerUID
) then
2753 if (gGameSettings
.GameMode
= GM_TDM
) and DoFrags
then
2754 Inc(gTeamStat
[KP
.Team
].Goals
,
2755 IfThen(SameTeam(FUID
, SpawnerUID
), -1, 1));
2757 if netsrv
then MH_SEND_PlayerStats(SpawnerUID
);
2760 plr
:= g_Player_Get(SpawnerUID
);
2768 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_2
],
2772 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_1
],
2776 g_Console_Add(Format(_lc
[I_PLAYER_KILL
],
2781 else if g_GetUIDType(SpawnerUID
) = UID_MONSTER
then
2782 begin // Убит монстром
2783 mon
:= g_Monsters_ByUID(SpawnerUID
);
2787 s
:= g_Mons_GetKilledByTypeId(mon
.MonsterType
);
2791 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_2
],
2795 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_1
],
2799 g_Console_Add(Format(_lc
[I_PLAYER_KILL
],
2804 else // Особые типы смерти
2807 HIT_SELF
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_SELF
], [FName
]), True);
2808 HIT_FALL
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_FALL
], [FName
]), True);
2809 HIT_WATER
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_WATER
], [FName
]), True);
2810 HIT_ACID
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_ACID
], [FName
]), True);
2811 HIT_TRAP
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_TRAP
], [FName
]), True);
2812 else g_Console_Add(Format(_lc
[I_PLAYER_DIED
], [FName
]), True);
2818 for a
:= WP_FIRST
to WP_LAST
do
2822 WEAPON_SAW
: i
:= ITEM_WEAPON_SAW
;
2823 WEAPON_SHOTGUN1
: i
:= ITEM_WEAPON_SHOTGUN1
;
2824 WEAPON_SHOTGUN2
: i
:= ITEM_WEAPON_SHOTGUN2
;
2825 WEAPON_CHAINGUN
: i
:= ITEM_WEAPON_CHAINGUN
;
2826 WEAPON_ROCKETLAUNCHER
: i
:= ITEM_WEAPON_ROCKETLAUNCHER
;
2827 WEAPON_PLASMA
: i
:= ITEM_WEAPON_PLASMA
;
2828 WEAPON_BFG
: i
:= ITEM_WEAPON_BFG
;
2829 WEAPON_SUPERPULEMET
: i
:= ITEM_WEAPON_SUPERPULEMET
;
2830 WEAPON_FLAMETHROWER
: i
:= ITEM_WEAPON_FLAMETHROWER
;
2839 if R_ITEM_BACKPACK
in FRulez
then
2840 PushItem(ITEM_AMMO_BACKPACK
);
2842 // Выброс ракетного ранца:
2843 if FJetFuel
> 0 then
2844 PushItem(ITEM_JETPACK
);
2847 if (not (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
])) or
2848 (not LongBool(gGameSettings
.Options
and GAME_OPTION_DMKEYS
)) then
2850 if R_KEY_RED
in FRulez
then
2851 PushItem(ITEM_KEY_RED
);
2853 if R_KEY_GREEN
in FRulez
then
2854 PushItem(ITEM_KEY_GREEN
);
2856 if R_KEY_BLUE
in FRulez
then
2857 PushItem(ITEM_KEY_BLUE
);
2861 DropFlag(KillType
= K_FALLKILL
);
2864 FCorpse
:= g_Player_CreateCorpse(Self
);
2866 if Srv
and (gGameSettings
.MaxLives
> 0) and FNoRespawn
and
2867 (gLMSRespawn
= LMS_RESPAWN_NONE
) then
2873 for i
:= Low(gPlayers
) to High(gPlayers
) do
2875 if gPlayers
[i
] = nil then continue
;
2876 if (not gPlayers
[i
].FNoRespawn
) and (not gPlayers
[i
].FSpectator
) then
2879 if gPlayers
[i
].FTeam
= TEAM_RED
then Inc(ar
)
2880 else if gPlayers
[i
].FTeam
= TEAM_BLUE
then Inc(ab
);
2885 OldLR
:= gLMSRespawn
;
2886 if (gGameSettings
.GameMode
= GM_COOP
) then
2890 // everyone is dead, restart the map
2891 g_Game_Message(_lc
[I_MESSAGE_LMS_LOSE
], 144);
2893 MH_SEND_GameEvent(NET_EV_LMS_LOSE
);
2894 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
2895 gLMSRespawnTime
:= gTime
+ 5000;
2897 else if (a
= 1) then
2899 if (gPlayers
[k
] <> nil) and not (gPlayers
[k
] is TBot
) then
2900 if (gPlayers
[k
] = gPlayer1
) or
2901 (gPlayers
[k
] = gPlayer2
) then
2902 g_Console_Add('*** ' + _lc
[I_MESSAGE_LMS_SURVIVOR
] + ' ***', True)
2903 else if Netsrv
and (gPlayers
[k
].FClientID
>= 0) then
2904 MH_SEND_GameEvent(NET_EV_LMS_SURVIVOR
, 0, 'N', gPlayers
[k
].FClientID
);
2907 else if (gGameSettings
.GameMode
= GM_TDM
) then
2909 if (ab
= 0) and (ar
<> 0) then
2912 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 144);
2914 MH_SEND_GameEvent(NET_EV_TLMS_WIN
, TEAM_RED
);
2915 Inc(gTeamStat
[TEAM_RED
].Goals
);
2916 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
2917 gLMSRespawnTime
:= gTime
+ 5000;
2919 else if (ar
= 0) and (ab
<> 0) then
2922 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 144);
2924 MH_SEND_GameEvent(NET_EV_TLMS_WIN
, TEAM_BLUE
);
2925 Inc(gTeamStat
[TEAM_BLUE
].Goals
);
2926 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
2927 gLMSRespawnTime
:= gTime
+ 5000;
2929 else if (ar
= 0) and (ab
= 0) then
2932 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
2934 MH_SEND_GameEvent(NET_EV_LMS_DRAW
, 0, FName
);
2935 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
2936 gLMSRespawnTime
:= gTime
+ 5000;
2939 else if (gGameSettings
.GameMode
= GM_DM
) then
2943 if gPlayers
[k
] <> nil then
2946 // survivor is the winner
2947 g_Game_Message(Format(_lc
[I_MESSAGE_LMS_WIN
], [AnsiUpperCase(FName
)]), 144);
2949 MH_SEND_GameEvent(NET_EV_LMS_WIN
, 0, FName
);
2952 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
2953 gLMSRespawnTime
:= gTime
+ 5000;
2955 else if (a
= 0) then
2957 // everyone is dead, restart the map
2958 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
2960 MH_SEND_GameEvent(NET_EV_LMS_DRAW
, 0, FName
);
2961 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
2962 gLMSRespawnTime
:= gTime
+ 5000;
2965 if srv
and (OldLR
= LMS_RESPAWN_NONE
) and (gLMSRespawn
> LMS_RESPAWN_NONE
) then
2967 if NetMode
= NET_SERVER
then
2968 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
)
2970 g_Console_Add(Format(_lc
[I_MSG_WARMUP_START
], [(gLMSRespawnTime
- gTime
) div 1000]), True);
2976 MH_SEND_PlayerStats(FUID
);
2977 MH_SEND_PlayerDeath(FUID
, KillType
, t
, SpawnerUID
);
2978 if gGameSettings
.GameMode
= GM_TDM
then MH_SEND_GameStats
;
2981 if srv
and FNoRespawn
then Spectate(True);
2982 FWantsInGame
:= True;
2985 function TPlayer
.BodyInLiquid(XInc
, YInc
: Integer): Boolean;
2987 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
, PLAYER_RECT
.Width
,
2988 PLAYER_RECT
.Height
-20, PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, False);
2991 function TPlayer
.BodyInAcid(XInc
, YInc
: Integer): Boolean;
2993 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
, PLAYER_RECT
.Width
,
2994 PLAYER_RECT
.Height
-20, PANEL_ACID1
or PANEL_ACID2
, False);
2997 procedure TPlayer
.MakeBloodSimple(Count
: Word);
2998 var Blood
: TModelBlood
;
3000 Blood
:= SELF
.FModel
.GetBlood();
3001 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)+8,
3002 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3003 Count
div 2, 3, -1, 16, (PLAYER_RECT
.Height
*2 div 3),
3004 Blood
.R
, Blood
.G
, Blood
.B
, Blood
.Kind
);
3005 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-8,
3006 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3007 Count
div 2, -3, -1, 16, (PLAYER_RECT
.Height
*2) div 3,
3008 Blood
.R
, Blood
.G
, Blood
.B
, Blood
.Kind
);
3011 procedure TPlayer
.MakeBloodVector(Count
: Word; VelX
, VelY
: Integer);
3012 var Blood
: TModelBlood
;
3014 Blood
:= SELF
.FModel
.GetBlood();
3015 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
3016 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3017 Count
, VelX
, VelY
, 16, (PLAYER_RECT
.Height
*2) div 3,
3018 Blood
.R
, Blood
.G
, Blood
.B
, Blood
.Kind
);
3021 procedure TPlayer
.QueueWeaponSwitch(Weapon
: Byte);
3023 if g_Game_IsClient
then Exit
;
3024 if Weapon
> High(FWeapon
) then Exit
;
3025 FNextWeap
:= FNextWeap
or (1 shl Weapon
);
3028 procedure TPlayer
.resetWeaponQueue ();
3031 FNextWeapDelay
:= 0;
3034 function TPlayer
.hasAmmoForWeapon (weapon
: Byte): Boolean;
3038 WEAPON_KASTET
, WEAPON_SAW
: result
:= true;
3039 WEAPON_SHOTGUN1
, WEAPON_SHOTGUN2
, WEAPON_SUPERPULEMET
: result
:= (FAmmo
[A_SHELLS
] > 0);
3040 WEAPON_PISTOL
, WEAPON_CHAINGUN
: result
:= (FAmmo
[A_BULLETS
] > 0);
3041 WEAPON_ROCKETLAUNCHER
: result
:= (FAmmo
[A_ROCKETS
] > 0);
3042 WEAPON_PLASMA
, WEAPON_BFG
: result
:= (FAmmo
[A_CELLS
] > 0);
3043 WEAPON_FLAMETHROWER
: result
:= (FAmmo
[A_FUEL
] > 0);
3044 else result
:= (weapon
< length(FWeapon
));
3048 // return 255 for "no switch"
3049 function TPlayer
.getNextWeaponIndex (): Byte;
3052 wantThisWeapon
: array[0..64] of Boolean;
3053 wwc
: Integer = 0; //HACK!
3056 result
:= 255; // default result: "no switch"
3057 // had weapon cycling on previous frame? remove that flag
3058 if (FNextWeap
and $2000) <> 0 then
3060 FNextWeap
:= FNextWeap
and $1FFF;
3061 FNextWeapDelay
:= 0;
3063 // cycling has priority
3064 if (FNextWeap
and $C000) <> 0 then
3066 if (FNextWeap
and $8000) <> 0 then
3070 FNextWeap
:= FNextWeap
or $2000; // we need this
3071 if FNextWeapDelay
> 0 then
3072 exit
; // cooldown time
3074 for i
:= 0 to High(FWeapon
) do
3076 cwi
:= (cwi
+length(FWeapon
)+dir
) mod length(FWeapon
);
3077 if FWeapon
[cwi
] then
3079 //e_WriteLog(Format(' SWITCH: cur=%d; new=%d', [FCurrWeap, cwi]), MSG_WARNING);
3080 result
:= Byte(cwi
);
3081 FNextWeapDelay
:= WEAPON_DELAY
;
3089 for i
:= 0 to High(wantThisWeapon
) do
3090 wantThisWeapon
[i
] := false;
3091 for i
:= 0 to High(FWeapon
) do
3092 if (FNextWeap
and (1 shl i
)) <> 0 then
3094 wantThisWeapon
[i
] := true;
3097 // exclude currently selected weapon from the set
3098 wantThisWeapon
[FCurrWeap
] := false;
3099 // slow down alterations a little
3102 //e_WriteLog(Format(' FNextWeap=%x; delay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
3103 // more than one weapon requested, assume "alteration" and check alteration delay
3104 if FNextWeapDelay
> 0 then
3110 // do not reset weapon queue, it will be done in `RealizeCurrentWeapon()`
3111 // but clear all counters if no weapon should be switched
3117 //e_WriteLog(Format('wwc=%d', [wwc]), MSG_WARNING);
3118 // try weapons in descending order
3119 for i
:= High(FWeapon
) downto 0 do
3121 if wantThisWeapon
[i
] and FWeapon
[i
] and ((wwc
= 1) or hasAmmoForWeapon(i
)) then
3126 FNextWeapDelay
:= WEAPON_DELAY
* 2; // anyway, 'cause why not
3130 // no suitable weapon found, so reset the queue, to avoid accidental "queuing" of weapon w/o ammo
3134 procedure TPlayer
.RealizeCurrentWeapon();
3135 function switchAllowed (): Boolean;
3140 if FBFGFireCounter
<> -1 then
3142 if FTime
[T_SWITCH
] > gTime
then
3144 for i
:= WP_FIRST
to WP_LAST
do
3145 if FReloading
[i
] > 0 then
3153 //e_WriteLog(Format('***RealizeCurrentWeapon: FNextWeap=%x; FNextWeapDelay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
3154 //FNextWeap := FNextWeap and $1FFF;
3155 if FNextWeapDelay
> 0 then Dec(FNextWeapDelay
); // "alteration delay"
3157 if not switchAllowed
then
3159 //HACK for weapon cycling
3160 if (FNextWeap
and $E000) <> 0 then FNextWeap
:= 0;
3164 nw
:= getNextWeaponIndex();
3165 if nw
= 255 then exit
; // don't reset anything here
3166 if nw
> High(FWeapon
) then
3168 // don't forget to reset queue here!
3169 //e_WriteLog(' RealizeCurrentWeapon: WUTAFUUUU', MSG_WARNING);
3177 FTime
[T_SWITCH
] := gTime
+156;
3178 if FCurrWeap
= WEAPON_SAW
then FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3179 FModel
.SetWeapon(FCurrWeap
);
3180 if g_Game_IsNet
then MH_SEND_PlayerStats(FUID
);
3184 procedure TPlayer
.NextWeapon();
3186 if g_Game_IsClient
then Exit
;
3190 procedure TPlayer
.PrevWeapon();
3192 if g_Game_IsClient
then Exit
;
3196 procedure TPlayer
.SetWeapon(W
: Byte);
3198 if FCurrWeap
<> W
then
3199 if W
= WEAPON_SAW
then
3200 FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3203 FModel
.SetWeapon(CurrWeap
);
3207 function TPlayer
.PickItem(ItemType
: Byte; arespawn
: Boolean; var remove
: Boolean): Boolean;
3209 function allowBerserkSwitching (): Boolean;
3211 if (FBFGFireCounter
<> -1) then begin result
:= false; exit
; end;
3213 if gBerserkAutoswitch
then exit
;
3214 if not conIsCheatsEnabled
then exit
;
3222 if g_Game_IsClient
then Exit
;
3224 // a = true - место спавна предмета:
3225 a
:= LongBool(gGameSettings
.Options
and GAME_OPTION_WEAPONSTAY
) and arespawn
;
3230 if (FHealth
< PLAYER_HP_SOFT
) or (FFireTime
> 0) then
3232 if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
3236 if gFlash
= 2 then Inc(FPickup
, 5);
3240 if (FHealth
< PLAYER_HP_SOFT
) or (FFireTime
> 0) then
3242 if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
3246 if gFlash
= 2 then Inc(FPickup
, 5);
3250 if FArmor
< PLAYER_AP_SOFT
then
3252 FArmor
:= PLAYER_AP_SOFT
;
3255 if gFlash
= 2 then Inc(FPickup
, 5);
3259 if FArmor
< PLAYER_AP_LIMIT
then
3261 FArmor
:= PLAYER_AP_LIMIT
;
3264 if gFlash
= 2 then Inc(FPickup
, 5);
3268 if (FHealth
< PLAYER_HP_LIMIT
) or (FFireTime
> 0) then
3270 if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
3274 if gFlash
= 2 then Inc(FPickup
, 5);
3278 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) or (FFireTime
> 0) then
3280 if FHealth
< PLAYER_HP_LIMIT
then
3281 FHealth
:= PLAYER_HP_LIMIT
;
3282 if FArmor
< PLAYER_AP_LIMIT
then
3283 FArmor
:= PLAYER_AP_LIMIT
;
3287 if gFlash
= 2 then Inc(FPickup
, 5);
3291 if (not FWeapon
[WEAPON_SAW
]) or ((not arespawn
) and (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
])) then
3293 FWeapon
[WEAPON_SAW
] := True;
3295 if gFlash
= 2 then Inc(FPickup
, 5);
3296 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3299 ITEM_WEAPON_SHOTGUN1
:
3300 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN1
] then
3302 // Нужно, чтобы не взять все пули сразу:
3303 if a
and FWeapon
[WEAPON_SHOTGUN1
] then Exit
;
3305 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3306 FWeapon
[WEAPON_SHOTGUN1
] := True;
3308 if gFlash
= 2 then Inc(FPickup
, 5);
3309 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3312 ITEM_WEAPON_SHOTGUN2
:
3313 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN2
] then
3315 if a
and FWeapon
[WEAPON_SHOTGUN2
] then Exit
;
3317 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3318 FWeapon
[WEAPON_SHOTGUN2
] := True;
3320 if gFlash
= 2 then Inc(FPickup
, 5);
3321 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3324 ITEM_WEAPON_CHAINGUN
:
3325 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or not FWeapon
[WEAPON_CHAINGUN
] then
3327 if a
and FWeapon
[WEAPON_CHAINGUN
] then Exit
;
3329 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
3330 FWeapon
[WEAPON_CHAINGUN
] := True;
3332 if gFlash
= 2 then Inc(FPickup
, 5);
3333 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3336 ITEM_WEAPON_ROCKETLAUNCHER
:
3337 if (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or not FWeapon
[WEAPON_ROCKETLAUNCHER
] then
3339 if a
and FWeapon
[WEAPON_ROCKETLAUNCHER
] then Exit
;
3341 IncMax(FAmmo
[A_ROCKETS
], 2, FMaxAmmo
[A_ROCKETS
]);
3342 FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
3344 if gFlash
= 2 then Inc(FPickup
, 5);
3345 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3349 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_PLASMA
] then
3351 if a
and FWeapon
[WEAPON_PLASMA
] then Exit
;
3353 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3354 FWeapon
[WEAPON_PLASMA
] := True;
3356 if gFlash
= 2 then Inc(FPickup
, 5);
3357 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3361 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_BFG
] then
3363 if a
and FWeapon
[WEAPON_BFG
] then Exit
;
3365 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3366 FWeapon
[WEAPON_BFG
] := True;
3368 if gFlash
= 2 then Inc(FPickup
, 5);
3369 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3372 ITEM_WEAPON_SUPERPULEMET
:
3373 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SUPERPULEMET
] then
3375 if a
and FWeapon
[WEAPON_SUPERPULEMET
] then Exit
;
3377 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3378 FWeapon
[WEAPON_SUPERPULEMET
] := True;
3380 if gFlash
= 2 then Inc(FPickup
, 5);
3381 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3384 ITEM_WEAPON_FLAMETHROWER
:
3385 if (FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
]) or not FWeapon
[WEAPON_FLAMETHROWER
] then
3387 if a
and FWeapon
[WEAPON_FLAMETHROWER
] then Exit
;
3389 IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
3390 FWeapon
[WEAPON_FLAMETHROWER
] := True;
3392 if gFlash
= 2 then Inc(FPickup
, 5);
3393 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3397 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
3399 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
3402 if gFlash
= 2 then Inc(FPickup
, 5);
3405 ITEM_AMMO_BULLETS_BOX
:
3406 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
3408 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
3411 if gFlash
= 2 then Inc(FPickup
, 5);
3415 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
3417 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3420 if gFlash
= 2 then Inc(FPickup
, 5);
3423 ITEM_AMMO_SHELLS_BOX
:
3424 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
3426 IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
3429 if gFlash
= 2 then Inc(FPickup
, 5);
3433 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
3435 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
3438 if gFlash
= 2 then Inc(FPickup
, 5);
3441 ITEM_AMMO_ROCKET_BOX
:
3442 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
3444 IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
3447 if gFlash
= 2 then Inc(FPickup
, 5);
3451 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
3453 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3456 if gFlash
= 2 then Inc(FPickup
, 5);
3460 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
3462 IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
3465 if gFlash
= 2 then Inc(FPickup
, 5);
3469 if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then
3471 IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
3474 if gFlash
= 2 then Inc(FPickup
, 5);
3478 if not(R_ITEM_BACKPACK
in FRulez
) or
3479 (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
3480 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
3481 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
3482 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or
3483 (FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
]) then
3485 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[1, A_BULLETS
];
3486 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[1, A_SHELLS
];
3487 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[1, A_ROCKETS
];
3488 FMaxAmmo
[A_CELLS
] := AmmoLimits
[1, A_CELLS
];
3489 FMaxAmmo
[A_FUEL
] := AmmoLimits
[1, A_FUEL
];
3491 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
3492 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
3493 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
3494 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3495 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
3496 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
3497 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
3498 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3499 if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then
3500 IncMax(FAmmo
[A_FUEL
], 50, FMaxAmmo
[A_FUEL
]);
3502 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
3505 if gFlash
= 2 then Inc(FPickup
, 5);
3509 if not(R_KEY_RED
in FRulez
) then
3511 Include(FRulez
, R_KEY_RED
);
3513 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
3514 if gFlash
= 2 then Inc(FPickup
, 5);
3515 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
3519 if not(R_KEY_GREEN
in FRulez
) then
3521 Include(FRulez
, R_KEY_GREEN
);
3523 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
3524 if gFlash
= 2 then Inc(FPickup
, 5);
3525 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
3529 if not(R_KEY_BLUE
in FRulez
) then
3531 Include(FRulez
, R_KEY_BLUE
);
3533 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
3534 if gFlash
= 2 then Inc(FPickup
, 5);
3535 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
3539 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
3541 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
3545 if gFlash
= 2 then Inc(FPickup
, 5);
3549 if FAir
< AIR_MAX
then
3554 if gFlash
= 2 then Inc(FPickup
, 5);
3559 if not (R_BERSERK
in FRulez
) then
3561 Include(FRulez
, R_BERSERK
);
3562 if allowBerserkSwitching
then
3564 FCurrWeap
:= WEAPON_KASTET
;
3566 FModel
.SetWeapon(WEAPON_KASTET
);
3571 if gFlash
= 2 then Inc(FPickup
, 5);
3573 FBerserk
:= gTime
+30000;
3578 if (FHealth
< PLAYER_HP_SOFT
) or (FFireTime
> 0) then
3580 if FHealth
< PLAYER_HP_SOFT
then FHealth
:= PLAYER_HP_SOFT
;
3581 FBerserk
:= gTime
+30000;
3589 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
3591 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
3595 if gFlash
= 2 then Inc(FPickup
, 5);
3599 if (FHealth
< PLAYER_HP_LIMIT
) or (FFireTime
> 0) then
3601 if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
3605 if gFlash
= 2 then Inc(FPickup
, 5);
3609 if FArmor
< PLAYER_AP_LIMIT
then
3611 IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
3614 if gFlash
= 2 then Inc(FPickup
, 5);
3618 if FJetFuel
< JET_MAX
then
3620 FJetFuel
:= JET_MAX
;
3623 if gFlash
= 2 then Inc(FPickup
, 5);
3627 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
3629 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
3632 if gFlash
= 2 then Inc(FPickup
, 5);
3637 procedure TPlayer
.Touch();
3641 //FModel.PlaySound(MODELSOUND_PAIN, 1, FObj.X, FObj.Y);
3644 // Бросить флаг товарищу:
3645 if gGameSettings
.GameMode
= GM_CTF
then
3650 procedure TPlayer
.Push(vx
, vy
: Integer);
3652 if (not FPhysics
) and FGhost
then
3654 FObj
.Accel
.X
:= FObj
.Accel
.X
+ vx
;
3655 FObj
.Accel
.Y
:= FObj
.Accel
.Y
+ vy
;
3656 if g_Game_IsNet
and g_Game_IsServer
then
3657 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
3660 procedure TPlayer
.Reset(Force
: Boolean);
3666 FTime
[T_RESPAWN
] := 0;
3667 FTime
[T_FLAGCAP
] := 0;
3683 FSpectator
:= False;
3686 FSpectatePlayer
:= -1;
3687 FNoRespawn
:= False;
3689 FLives
:= gGameSettings
.MaxLives
;
3694 procedure TPlayer
.SoftReset();
3702 FBFGFireCounter
:= -1;
3710 SetAction(A_STAND
, True);
3713 function TPlayer
.GetRespawnPoint(): Byte;
3718 // На будущее: FSpawn - игрок уже играл и перерождается
3720 // Одиночная игра/кооператив
3721 if gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
] then
3723 if Self
= gPlayer1
then
3725 // player 1 should try to spawn on the player 1 point
3726 if g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) > 0 then
3727 Exit(RESPAWNPOINT_PLAYER1
)
3728 else if g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) > 0 then
3729 Exit(RESPAWNPOINT_PLAYER2
);
3731 else if Self
= gPlayer2
then
3733 // player 2 should try to spawn on the player 2 point
3734 if g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) > 0 then
3735 Exit(RESPAWNPOINT_PLAYER2
)
3736 else if g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) > 0 then
3737 Exit(RESPAWNPOINT_PLAYER1
);
3741 // other players randomly pick either the first or the second point
3742 c
:= IfThen((Random(2) = 0), RESPAWNPOINT_PLAYER1
, RESPAWNPOINT_PLAYER2
);
3743 if g_Map_GetPointCount(c
) > 0 then
3745 // try the other one
3746 c
:= IfThen((c
= RESPAWNPOINT_PLAYER1
), RESPAWNPOINT_PLAYER2
, RESPAWNPOINT_PLAYER1
);
3747 if g_Map_GetPointCount(c
) > 0 then
3753 if gGameSettings
.GameMode
= GM_DM
then
3755 // try DM points first
3756 if g_Map_GetPointCount(RESPAWNPOINT_DM
) > 0 then
3757 Exit(RESPAWNPOINT_DM
);
3761 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
3763 // try team points first
3764 c
:= RESPAWNPOINT_DM
;
3765 if FTeam
= TEAM_RED
then
3766 c
:= RESPAWNPOINT_RED
3767 else if FTeam
= TEAM_BLUE
then
3768 c
:= RESPAWNPOINT_BLUE
;
3769 if g_Map_GetPointCount(c
) > 0 then
3773 // still haven't found a spawnpoint, try random shit
3774 Result
:= g_Map_GetRandomPointType();
3777 procedure TPlayer
.Respawn(Silent
: Boolean; Force
: Boolean = False);
3779 RespawnPoint
: TRespawnPoint
;
3785 FBFGFireCounter
:= -1;
3792 if not g_Game_IsServer
then
3796 FWantsInGame
:= True;
3797 FJustTeleported
:= True;
3800 FTime
[T_RESPAWN
] := 0;
3804 // if server changes MaxLives we gotta be ready
3805 if gGameSettings
.MaxLives
= 0 then FNoRespawn
:= False;
3807 // Еще нельзя возродиться:
3808 if FTime
[T_RESPAWN
] > gTime
then
3811 // Просрал все жизни:
3814 if not FSpectator
then Spectate(True);
3815 FWantsInGame
:= True;
3819 if (gGameSettings
.GameType
<> GT_SINGLE
) and (gGameSettings
.GameMode
<> GM_COOP
) then
3820 begin // "Своя игра"
3821 // Берсерк не сохраняется между уровнями:
3822 FRulez
:= FRulez
-[R_BERSERK
];
3824 else // "Одиночная игра"/"Кооп"
3826 // Берсерк и ключи не сохраняются между уровнями:
3827 FRulez
:= FRulez
-[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
, R_BERSERK
];
3830 // Получаем точку спауна игрока:
3831 c
:= GetRespawnPoint();
3836 // Воскрешение без оружия:
3839 FHealth
:= Round(PLAYER_HP_SOFT
* (FHandicap
/ 100));
3845 for a
:= WP_FIRST
to WP_LAST
do
3847 FWeapon
[a
] := False;
3851 FWeapon
[WEAPON_PISTOL
] := True;
3852 FWeapon
[WEAPON_KASTET
] := True;
3853 FCurrWeap
:= WEAPON_PISTOL
;
3856 FModel
.SetWeapon(FCurrWeap
);
3858 for b
:= A_BULLETS
to A_HIGH
do
3861 FAmmo
[A_BULLETS
] := 50;
3863 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[0, A_BULLETS
];
3864 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[0, A_SHELLS
];
3865 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[0, A_SHELLS
];
3866 FMaxAmmo
[A_CELLS
] := AmmoLimits
[0, A_CELLS
];
3867 FMaxAmmo
[A_FUEL
] := AmmoLimits
[0, A_FUEL
];
3869 if (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
]) and
3870 LongBool(gGameSettings
.Options
and GAME_OPTION_DMKEYS
) then
3871 FRulez
:= [R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
]
3876 // Получаем координаты точки возрождения:
3877 if not g_Map_GetPoint(c
, RespawnPoint
) then
3879 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
3883 // Установка координат и сброс всех параметров:
3884 FObj
.X
:= RespawnPoint
.X
-PLAYER_RECT
.X
;
3885 FObj
.Y
:= RespawnPoint
.Y
-PLAYER_RECT
.Y
;
3886 FObj
.oldX
:= FObj
.X
; // don't interpolate after respawn
3887 FObj
.oldY
:= FObj
.Y
;
3893 FDirection
:= RespawnPoint
.Direction
;
3894 if FDirection
= TDirection
.D_LEFT
then
3899 SetAction(A_STAND
, True);
3900 FModel
.Direction
:= FDirection
;
3902 for a
:= Low(FTime
) to High(FTime
) do
3905 for a
:= Low(FMegaRulez
) to High(FMegaRulez
) do
3908 // Respawn invulnerability
3909 if (gGameSettings
.GameType
<> GT_SINGLE
) and (gGameSettings
.SpawnInvul
> 0) then
3911 FMegaRulez
[MR_INVUL
] := gTime
+ gGameSettings
.SpawnInvul
* 1000;
3912 FSpawnInvul
:= FMegaRulez
[MR_INVUL
];
3917 FCanJetpack
:= False;
3923 // Анимация возрождения:
3924 if (not gLoadGameMode
) and (not Silent
) then
3926 R_GFX_TELEPORT_FAST
,
3927 FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
3928 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32
3931 FSpectator
:= False;
3934 FSpectatePlayer
:= -1;
3937 if (gPlayer1
= nil) and (gSpectLatchPID1
= FUID
) then
3939 if (gPlayer2
= nil) and (gSpectLatchPID2
= FUID
) then
3942 if g_Game_IsNet
then
3944 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
3945 MH_SEND_PlayerStats(FUID
, NET_EVERYONE
);
3947 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
3948 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32,
3953 procedure TPlayer
.Spectate(NoMove
: Boolean = False);
3956 Kill(K_EXTRAHARDKILL
, FUID
, HIT_SOME
)
3957 else if (not NoMove
) then
3959 GameX
:= gMapInfo
.Width
div 2;
3960 GameY
:= gMapInfo
.Height
div 2;
3969 FWantsInGame
:= False;
3975 if Self
= gPlayer1
then
3977 gSpectLatchPID1
:= FUID
;
3980 else if Self
= gPlayer2
then
3982 gSpectLatchPID2
:= FUID
;
3987 if g_Game_IsNet
then
3988 MH_SEND_PlayerStats(FUID
);
3991 procedure TPlayer
.SwitchNoClip
;
3995 FGhost
:= not FGhost
;
3996 FPhysics
:= not FGhost
;
4008 procedure TPlayer
.Run(Direction
: TDirection
);
4012 if MAX_RUNVEL
> 8 then
4016 if Direction
= TDirection
.D_LEFT
then
4018 if FObj
.Vel
.X
> -MAX_RUNVEL
then
4019 FObj
.Vel
.X
:= FObj
.Vel
.X
- (MAX_RUNVEL
shr 3);
4022 if FObj
.Vel
.X
< MAX_RUNVEL
then
4023 FObj
.Vel
.X
:= FObj
.Vel
.X
+ (MAX_RUNVEL
shr 3);
4025 // Возможно, пинаем куски:
4026 if (FObj
.Vel
.X
<> 0) and (gGibs
<> nil) then
4028 b
:= Abs(FObj
.Vel
.X
);
4029 if b
> 1 then b
:= b
* (Random(8 div b
) + 1);
4030 for a
:= 0 to High(gGibs
) do
4032 if gGibs
[a
].alive
and
4033 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
+FObj
.Rect
.Height
-4,
4034 FObj
.Rect
.Width
, 8, @gGibs
[a
].Obj
) and (Random(3) = 0) then
4037 if FObj
.Vel
.X
< 0 then
4039 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)+120) // налево
4043 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)); // направо
4045 gGibs
[a
].positionChanged(); // this updates spatial accelerators
4053 procedure TPlayer
.SeeDown();
4055 SetAction(A_SEEDOWN
);
4057 if FDirection
= TDirection
.D_LEFT
then FAngle
:= ANGLE_LEFTDOWN
else FAngle
:= ANGLE_RIGHTDOWN
;
4059 if FIncCam
> -120 then DecMin(FIncCam
, 5, -120);
4062 procedure TPlayer
.SeeUp();
4066 if FDirection
= TDirection
.D_LEFT
then FAngle
:= ANGLE_LEFTUP
else FAngle
:= ANGLE_RIGHTUP
;
4068 if FIncCam
< 120 then IncMax(FIncCam
, 5, 120);
4071 procedure TPlayer
.SetAction(Action
: Byte; Force
: Boolean = False);
4079 A_ATTACK
: Prior
:= 2;
4080 A_SEEUP
: Prior
:= 1;
4081 A_SEEDOWN
: Prior
:= 1;
4082 A_ATTACKUP
: Prior
:= 2;
4083 A_ATTACKDOWN
: Prior
:= 2;
4088 if (Prior
> FActionPrior
) or Force
then
4089 if not ((Prior
= 2) and (FCurrWeap
= WEAPON_SAW
)) then
4091 FActionPrior
:= Prior
;
4092 FActionAnim
:= Action
;
4093 FActionForce
:= Force
;
4094 FActionChanged
:= True;
4097 if Action
in [A_ATTACK
, A_ATTACKUP
, A_ATTACKDOWN
] then FModel
.SetFire(True);
4100 function TPlayer
.StayOnStep(XInc
, YInc
: Integer): Boolean;
4102 Result
:= not g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
-1,
4103 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False)
4104 and g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
,
4105 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False);
4108 function TPlayer
.TeleportTo(X
, Y
: Integer; silent
: Boolean; dir
: Byte): Boolean;
4112 if g_CollideLevel(X
, Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
) then
4114 g_Sound_PlayExAt('SOUND_GAME_NOTELEPORT', FObj
.X
, FObj
.Y
);
4115 if g_Game_IsServer
and g_Game_IsNet
then
4116 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_GAME_NOTELEPORT');
4120 FJustTeleported
:= True;
4124 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', FObj
.X
, FObj
.Y
);
4126 R_GFX_TELEPORT_FAST
,
4127 FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4128 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32
4130 if g_Game_IsServer
and g_Game_IsNet
then
4131 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4132 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 1,
4136 FObj
.X
:= X
-PLAYER_RECT
.X
;
4137 FObj
.Y
:= Y
-PLAYER_RECT
.Y
;
4138 FObj
.oldX
:= FObj
.X
; // don't interpolate after respawn
4139 FObj
.oldY
:= FObj
.Y
;
4140 if FAlive
and FGhost
then
4146 if not g_Game_IsNet
then
4150 SetDirection(TDirection
.D_LEFT
);
4156 SetDirection(TDirection
.D_RIGHT
);
4162 if FDirection
= TDirection
.D_RIGHT
then
4164 SetDirection(TDirection
.D_LEFT
);
4169 SetDirection(TDirection
.D_RIGHT
);
4178 R_GFX_TELEPORT_FAST
,
4179 FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4180 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32
4182 if g_Game_IsServer
and g_Game_IsNet
then
4183 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4184 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 0,
4191 function nonz(a
: Single): Single;
4199 function TPlayer
.refreshCorpse(): Boolean;
4205 if FAlive
or FSpectator
then
4207 if (gCorpses
= nil) or (Length(gCorpses
) = 0) then
4209 for i
:= 0 to High(gCorpses
) do
4210 if gCorpses
[i
] <> nil then
4211 if gCorpses
[i
].FPlayerUID
= FUID
then
4219 function TPlayer
.getCameraObj(): TObj
;
4221 if (not FAlive
) and (not FSpectator
) and
4222 (FCorpse
>= 0) and (FCorpse
< Length(gCorpses
)) and
4223 (gCorpses
[FCorpse
] <> nil) and (gCorpses
[FCorpse
].FPlayerUID
= FUID
) then
4225 gCorpses
[FCorpse
].FObj
.slopeUpLeft
:= FObj
.slopeUpLeft
;
4226 Result
:= gCorpses
[FCorpse
].FObj
;
4234 procedure TPlayer
.PreUpdate();
4236 FSlopeOld
:= FObj
.slopeUpLeft
;
4237 FIncCamOld
:= FIncCam
;
4238 FObj
.oldX
:= FObj
.X
;
4239 FObj
.oldY
:= FObj
.Y
;
4242 procedure TPlayer
.Update();
4245 i
, ii
, wx
, wy
, xd
, yd
, k
: Integer;
4246 blockmon
, headwater
, dospawn
: Boolean;
4251 NetServer
:= g_Game_IsNet
and g_Game_IsServer
;
4252 AnyServer
:= g_Game_IsServer
;
4254 if g_Game_IsClient
and (NetInterpLevel
> 0) then
4255 DoLerp(NetInterpLevel
+ 1)
4261 if FClientID
>= 0 then
4263 FPing
:= NetClients
[FClientID
].Peer
^.lastRoundTripTime
;
4264 if NetClients
[FClientID
].Peer
^.packetsSent
> 0 then
4265 FLoss
:= Round(100*NetClients
[FClientID
].Peer
^.packetsLost
/NetClients
[FClientID
].Peer
^.packetsSent
)
4276 if FPunchAnim
.played
then
4279 if FAlive
and (gFly
or FJetpack
) then
4282 if FDirection
= TDirection
.D_LEFT
then
4287 if FAlive
and (not FGhost
) then
4289 if FKeys
[KEY_UP
].Pressed
then
4291 if FKeys
[KEY_DOWN
].Pressed
then
4295 if (not (FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_DOWN
].Pressed
)) and
4298 i
:= g_basic
.Sign(FIncCam
);
4299 FIncCam
:= Abs(FIncCam
);
4300 DecMin(FIncCam
, 5, 0);
4301 FIncCam
:= FIncCam
*i
;
4304 // no need to do that each second frame, weapon queue will take care of it
4305 if FAlive
and FKeys
[KEY_NEXTWEAPON
].Pressed
and AnyServer
then NextWeapon();
4306 if FAlive
and FKeys
[KEY_PREVWEAPON
].Pressed
and AnyServer
then PrevWeapon();
4308 if gTime
mod (GAME_TICK
*2) <> 0 then
4310 if (FObj
.Vel
.X
= 0) and FAlive
then
4312 if FKeys
[KEY_LEFT
].Pressed
then
4313 Run(TDirection
.D_LEFT
);
4314 if FKeys
[KEY_RIGHT
].Pressed
then
4315 Run(TDirection
.D_RIGHT
);
4320 g_Obj_Move(@FObj
, True, True, True);
4321 positionChanged(); // this updates spatial accelerators
4327 FActionChanged
:= False;
4331 // Let alive player do some actions
4332 if FKeys
[KEY_LEFT
].Pressed
then Run(TDirection
.D_LEFT
);
4333 if FKeys
[KEY_RIGHT
].Pressed
then Run(TDirection
.D_RIGHT
);
4334 //if FKeys[KEY_NEXTWEAPON].Pressed and AnyServer then NextWeapon();
4335 //if FKeys[KEY_PREVWEAPON].Pressed and AnyServer then PrevWeapon();
4336 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then Fire()
4342 if NetServer
then MH_SEND_PlayerStats(FUID
);
4345 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Use();
4346 if FKeys
[KEY_JUMP
].Pressed
then Jump()
4349 if AnyServer
and FJetpack
then
4353 if NetServer
then MH_SEND_PlayerStats(FUID
);
4355 FCanJetpack
:= True;
4362 for k
:= Low(FKeys
) to KEY_CHAT
-1 do
4364 if FKeys
[k
].Pressed
then
4372 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
4375 if (FTime
[T_RESPAWN
] <= gTime
) and
4376 gGameOn
and (not FAlive
) then
4378 if (g_Player_GetCount() > 1) then
4382 gExit
:= EXIT_RESTART
;
4387 // Dead spectator actions
4390 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Fire();
4391 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then
4395 if (FSpectatePlayer
>= High(gPlayers
)) then
4396 FSpectatePlayer
:= -1
4400 for I
:= FSpectatePlayer
+ 1 to High(gPlayers
) do
4401 if gPlayers
[I
] <> nil then
4402 if gPlayers
[I
].alive
then
4403 if gPlayers
[I
].UID
<> FUID
then
4405 FSpectatePlayer
:= I
;
4410 if not SetSpect
then FSpectatePlayer
:= -1;
4421 if FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_JUMP
].Pressed
then
4423 FYTo
:= FObj
.Y
- 32;
4424 FSpectatePlayer
:= -1;
4426 if FKeys
[KEY_DOWN
].Pressed
then
4428 FYTo
:= FObj
.Y
+ 32;
4429 FSpectatePlayer
:= -1;
4431 if FKeys
[KEY_LEFT
].Pressed
then
4433 FXTo
:= FObj
.X
- 32;
4434 FSpectatePlayer
:= -1;
4436 if FKeys
[KEY_RIGHT
].Pressed
then
4438 FXTo
:= FObj
.X
+ 32;
4439 FSpectatePlayer
:= -1;
4442 if (FXTo
< -64) then
4444 else if (FXTo
> gMapInfo
.Width
+ 32) then
4445 FXTo
:= gMapInfo
.Width
+ 32;
4446 if (FYTo
< -72) then
4448 else if (FYTo
> gMapInfo
.Height
+ 32) then
4449 FYTo
:= gMapInfo
.Height
+ 32;
4454 g_Obj_Move(@FObj
, True, True, True);
4455 positionChanged(); // this updates spatial accelerators
4462 if (FSpectatePlayer
<= High(gPlayers
)) and (FSpectatePlayer
>= 0) then
4463 if gPlayers
[FSpectatePlayer
] <> nil then
4464 if gPlayers
[FSpectatePlayer
].alive
then
4466 FXTo
:= gPlayers
[FSpectatePlayer
].GameX
;
4467 FYTo
:= gPlayers
[FSpectatePlayer
].GameY
;
4471 blockmon
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
, FObj
.Y
+PLAYER_HEADRECT
.Y
,
4472 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
4473 PANEL_BLOCKMON
, True);
4474 headwater
:= HeadInLiquid(0, 0);
4476 // Сопротивление воздуха:
4477 if (not FAlive
) or not (FKeys
[KEY_LEFT
].Pressed
or FKeys
[KEY_RIGHT
].Pressed
) then
4478 if FObj
.Vel
.X
<> 0 then
4479 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
4481 if (FLastHit
= HIT_TRAP
) and (FPain
> 90) then FPain
:= 90;
4482 DecMin(FPain
, 5, 0);
4483 DecMin(FPickup
, 1, 0);
4485 if FAlive
and (FObj
.Y
> Integer(gMapInfo
.Height
)+128) and AnyServer
then
4487 // Обнулить действия примочек, чтобы фон пропал
4488 FMegaRulez
[MR_SUIT
] := 0;
4489 FMegaRulez
[MR_INVUL
] := 0;
4490 FMegaRulez
[MR_INVIS
] := 0;
4491 Kill(K_FALLKILL
, 0, HIT_FALL
);
4498 if FCurrWeap
= WEAPON_SAW
then
4499 if not (FSawSound
.IsPlaying() or FSawSoundHit
.IsPlaying() or
4500 FSawSoundSelect
.IsPlaying()) then
4501 FSawSoundIdle
.PlayAt(FObj
.X
, FObj
.Y
);
4504 if (not FJetSoundFly
.IsPlaying()) and (not FJetSoundOn
.IsPlaying()) and
4505 (not FJetSoundOff
.IsPlaying()) then
4507 FJetSoundFly
.SetPosition(0);
4508 FJetSoundFly
.PlayAt(FObj
.X
, FObj
.Y
);
4511 for b
:= WP_FIRST
to WP_LAST
do
4512 if FReloading
[b
] > 0 then
4518 if FShellTimer
> -1 then
4519 if FShellTimer
= 0 then
4521 if FShellType
= SHELL_SHELL
then
4522 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
4523 GameVelX
, GameVelY
-2, SHELL_SHELL
)
4524 else if FShellType
= SHELL_DBLSHELL
then
4526 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
4527 GameVelX
+1, GameVelY
-2, SHELL_SHELL
);
4528 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
4529 GameVelX
-1, GameVelY
-2, SHELL_SHELL
);
4532 end else Dec(FShellTimer
);
4534 if (FBFGFireCounter
> -1) then
4535 if FBFGFireCounter
= 0 then
4539 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
4540 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
4541 xd
:= wx
+IfThen(FDirection
= TDirection
.D_LEFT
, -30, 30);
4542 yd
:= wy
+firediry();
4543 g_Weapon_bfgshot(wx
, wy
, xd
, yd
, FUID
);
4544 if NetServer
then MH_SEND_PlayerFire(FUID
, WEAPON_BFG
, wx
, wy
, xd
, yd
);
4545 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
4546 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
4547 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
4550 FReloading
[WEAPON_BFG
] := WEAPON_RELOAD
[WEAPON_BFG
];
4551 FBFGFireCounter
:= -1;
4554 FBFGFireCounter
:= 0
4556 Dec(FBFGFireCounter
);
4558 if (FMegaRulez
[MR_SUIT
] < gTime
) and AnyServer
then
4560 b
:= g_GetAcidHit(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
);
4562 if (b
> 0) and (gTime
mod (15*GAME_TICK
) = 0) then Damage(b
, 0, 0, 0, HIT_ACID
);
4565 if (headwater
or blockmon
) then
4571 if AnyServer
then Damage(10, 0, 0, 0, HIT_WATER
);
4574 else if (FAir
mod 31 = 0) and not blockmon
then
4576 g_GFX_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2), FObj
.Y
+PLAYER_RECT
.Y
-4, 5+Random(6), 8, 4);
4577 if Random(2) = 0 then
4578 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
4580 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
4582 end else if FAir
< AIR_DEF
then
4585 if FFireTime
> 0 then
4587 if BodyInLiquid(0, 0) then
4592 else if FMegaRulez
[MR_SUIT
] >= gTime
then
4594 if FMegaRulez
[MR_SUIT
] = gTime
then
4601 if FFirePainTime
<= 0 then
4603 if g_Game_IsServer
then
4604 Damage(2, FFireAttacker
, 0, 0, HIT_FLAME
);
4605 FFirePainTime
:= 12 - FFireTime
div 12;
4607 FFirePainTime
:= FFirePainTime
- 1;
4608 FFireTime
:= FFireTime
- 1;
4609 if ((FFireTime
mod 33) = 0) and (FMegaRulez
[MR_INVUL
] < gTime
) then
4610 FModel
.PlaySound(MODELSOUND_PAIN
, 1, FObj
.X
, FObj
.Y
);
4611 if (FFireTime
= 0) and g_Game_IsNet
and g_Game_IsServer
then
4612 MH_SEND_PlayerStats(FUID
);
4616 if FDamageBuffer
> 0 then
4618 if FDamageBuffer
>= 9 then
4622 if FDamageBuffer
< 30 then i
:= 9
4623 else if FDamageBuffer
< 100 then i
:= 18
4627 ii
:= Round(FDamageBuffer
*FHealth
/ nonz(FArmor
*(3/4)+FHealth
));
4628 FArmor
:= FArmor
-(FDamageBuffer
-ii
);
4629 FHealth
:= FHealth
-ii
;
4632 FHealth
:= FHealth
+FArmor
;
4637 if FHealth
<= 0 then
4638 if FHealth
> -30 then Kill(K_SIMPLEKILL
, FLastSpawnerUID
, FLastHit
)
4639 else if FHealth
> -50 then Kill(K_HARDKILL
, FLastSpawnerUID
, FLastHit
)
4640 else Kill(K_EXTRAHARDKILL
, FLastSpawnerUID
, FLastHit
);
4642 if FAlive
and ((FLastHit
<> HIT_FLAME
) or (FFireTime
<= 0)) then
4644 if FDamageBuffer
<= 20 then FModel
.PlaySound(MODELSOUND_PAIN
, 1, FObj
.X
, FObj
.Y
)
4645 else if FDamageBuffer
<= 55 then FModel
.PlaySound(MODELSOUND_PAIN
, 2, FObj
.X
, FObj
.Y
)
4646 else if FDamageBuffer
<= 120 then FModel
.PlaySound(MODELSOUND_PAIN
, 3, FObj
.X
, FObj
.Y
)
4647 else FModel
.PlaySound(MODELSOUND_PAIN
, 4, FObj
.X
, FObj
.Y
);
4654 end; // if FAlive then ...
4656 if (FActionAnim
= A_PAIN
) and (FModel
.Animation
<> A_PAIN
) then
4658 FModel
.ChangeAnimation(FActionAnim
, FActionForce
);
4659 FModel
.AnimState
.MinLength
:= i
;
4660 end else FModel
.ChangeAnimation(FActionAnim
, FActionForce
and (FModel
.Animation
<> A_STAND
));
4662 if (FModel
.AnimState
.Played
or ((not FActionChanged
) and (FModel
.Animation
= A_WALK
)))
4663 then SetAction(A_STAND
, True);
4665 if not ((FModel
.Animation
= A_WALK
) and (Abs(FObj
.Vel
.X
) < 4) and not FModel
.GetFire()) then FModel
.Update
;
4667 for b
:= Low(FKeys
) to High(FKeys
) do
4668 if FKeys
[b
].Time
= 0 then FKeys
[b
].Pressed
:= False else Dec(FKeys
[b
].Time
);
4672 procedure TPlayer
.getMapBox (out x
, y
, w
, h
: Integer); inline;
4674 x
:= FObj
.X
+PLAYER_RECT
.X
;
4675 y
:= FObj
.Y
+PLAYER_RECT
.Y
;
4676 w
:= PLAYER_RECT
.Width
;
4677 h
:= PLAYER_RECT
.Height
;
4681 procedure TPlayer
.moveBy (dx
, dy
: Integer); inline;
4683 if (dx
<> 0) or (dy
<> 0) then
4692 function TPlayer
.Collide(X
, Y
: Integer; Width
, Height
: Word): Boolean;
4694 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
4695 FObj
.Y
+PLAYER_RECT
.Y
,
4702 function TPlayer
.Collide(Panel
: TPanel
): Boolean;
4704 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
4705 FObj
.Y
+PLAYER_RECT
.Y
,
4709 Panel
.Width
, Panel
.Height
);
4712 function TPlayer
.Collide(X
, Y
: Integer): Boolean;
4714 X
:= X
-FObj
.X
-PLAYER_RECT
.X
;
4715 Y
:= Y
-FObj
.Y
-PLAYER_RECT
.Y
;
4716 Result
:= (x
>= 0) and (x
<= PLAYER_RECT
.Width
) and
4717 (y
>= 0) and (y
<= PLAYER_RECT
.Height
);
4720 function g_Player_ValidName(Name
: string): Boolean;
4726 if gPlayers
= nil then Exit
;
4728 for a
:= 0 to High(gPlayers
) do
4729 if gPlayers
[a
] <> nil then
4730 if LowerCase(Name
) = LowerCase(gPlayers
[a
].FName
) then
4737 procedure TPlayer
.SetDirection(Direction
: TDirection
);
4741 d
:= FModel
.Direction
;
4743 FModel
.Direction
:= Direction
;
4744 if d
<> Direction
then FModel
.ChangeAnimation(FModel
.Animation
, True);
4746 FDirection
:= Direction
;
4749 function TPlayer
.GetKeys(): Byte;
4753 if R_KEY_RED
in FRulez
then Result
:= KEY_RED
;
4754 if R_KEY_GREEN
in FRulez
then Result
:= Result
or KEY_GREEN
;
4755 if R_KEY_BLUE
in FRulez
then Result
:= Result
or KEY_BLUE
;
4757 if FTeam
= TEAM_RED
then Result
:= Result
or KEY_REDTEAM
;
4758 if FTeam
= TEAM_BLUE
then Result
:= Result
or KEY_BLUETEAM
;
4761 procedure TPlayer
.Use();
4765 if FTime
[T_USE
] > gTime
then Exit
;
4767 g_Triggers_PressR(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
,
4768 PLAYER_RECT
.Height
, FUID
, ACTIVATE_PLAYERPRESS
);
4770 for a
:= 0 to High(gPlayers
) do
4771 if (gPlayers
[a
] <> nil) and (gPlayers
[a
] <> Self
) and
4772 gPlayers
[a
].alive
and SameTeam(FUID
, gPlayers
[a
].FUID
) and
4773 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
4774 FObj
.Rect
.Width
, FObj
.Rect
.Height
, @gPlayers
[a
].FObj
) then
4776 gPlayers
[a
].Touch();
4777 if g_Game_IsNet
and g_Game_IsServer
then
4778 MH_SEND_GameEvent(NET_EV_PLAYER_TOUCH
, gPlayers
[a
].FUID
);
4781 FTime
[T_USE
] := gTime
+120;
4784 procedure TPlayer
.NetFire(Wpn
: Byte; X
, Y
, AX
, AY
: Integer; WID
: Integer = -1);
4788 WX
, WY
, XD
, YD
: Integer;
4800 if R_BERSERK
in FRulez
then
4802 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
4803 locobj
.X
:= FObj
.X
+FObj
.Rect
.X
;
4804 locobj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
4807 locobj
.rect
.Width
:= 39;
4808 locobj
.rect
.Height
:= 52;
4809 locobj
.Vel
.X
:= (xd
-wx
) div 2;
4810 locobj
.Vel
.Y
:= (yd
-wy
) div 2;
4811 locobj
.Accel
.X
:= xd
-wx
;
4812 locobj
.Accel
.y
:= yd
-wy
;
4814 if g_Weapon_Hit(@locobj
, 50, FUID
, HIT_SOME
) <> 0 then
4815 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
4817 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
4821 FPain
:= min(FPain
+ 25, 50);
4823 g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
4828 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
4829 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
4831 FSawSoundSelect
.Stop();
4833 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
4835 else if not FSawSoundHit
.IsPlaying() then
4837 FSawSoundSelect
.Stop();
4838 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
4845 g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', GameX
, Gamey
);
4846 FFireAngle
:= FAngle
;
4848 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
4849 GameVelX
, GameVelY
-2, SHELL_BULLET
);
4854 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
4855 FFireAngle
:= FAngle
;
4858 FShellType
:= SHELL_SHELL
;
4863 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN2', Gamex
, Gamey
);
4864 FFireAngle
:= FAngle
;
4867 FShellType
:= SHELL_DBLSHELL
;
4872 g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', Gamex
, Gamey
);
4873 FFireAngle
:= FAngle
;
4875 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
4876 GameVelX
, GameVelY
-2, SHELL_BULLET
);
4879 WEAPON_ROCKETLAUNCHER
:
4881 g_Weapon_Rocket(wx
, wy
, xd
, yd
, FUID
, WID
);
4882 FFireAngle
:= FAngle
;
4888 g_Weapon_Plasma(wx
, wy
, xd
, yd
, FUID
, WID
);
4889 FFireAngle
:= FAngle
;
4895 g_Weapon_BFGShot(wx
, wy
, xd
, yd
, FUID
, WID
);
4896 FFireAngle
:= FAngle
;
4900 WEAPON_SUPERPULEMET
:
4902 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
4903 FFireAngle
:= FAngle
;
4905 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
4906 GameVelX
, GameVelY
-2, SHELL_SHELL
);
4909 WEAPON_FLAMETHROWER
:
4911 g_Weapon_flame(wx
, wy
, xd
, yd
, FUID
, WID
);
4913 FFireAngle
:= FAngle
;
4920 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
4921 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
4922 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
4925 procedure TPlayer
.DoLerp(Level
: Integer = 2);
4927 if FObj
.X
<> FXTo
then FObj
.X
:= Lerp(FObj
.X
, FXTo
, Level
);
4928 if FObj
.Y
<> FYTo
then FObj
.Y
:= Lerp(FObj
.Y
, FYTo
, Level
);
4931 procedure TPlayer
.SetLerp(XTo
, YTo
: Integer);
4937 if FJustTeleported
or (NetInterpLevel
< 1) then
4941 if FJustTeleported
then
4943 FObj
.oldX
:= FObj
.X
;
4944 FObj
.oldY
:= FObj
.Y
;
4949 AX
:= Abs(FXTo
- FObj
.X
);
4950 AY
:= Abs(FYTo
- FObj
.Y
);
4951 if (AX
> 32) or (AX
<= NetInterpLevel
) then
4953 if (AY
> 32) or (AY
<= NetInterpLevel
) then
4958 function TPlayer
.FullInLift(XInc
, YInc
: Integer): Integer;
4960 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
4961 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
4962 PANEL_LIFTUP
, False) then Result
:= -1
4964 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
4965 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
4966 PANEL_LIFTDOWN
, False) then Result
:= 1
4970 function TPlayer
.GetFlag(Flag
: Byte): Boolean;
4977 if Flag
= FLAG_NONE
then
4980 if not g_Game_IsServer
then Exit
;
4982 // Принес чужой флаг на свою базу:
4983 if (Flag
= FTeam
) and
4984 (gFlags
[Flag
].State
= FLAG_STATE_NORMAL
) and
4985 (FFlag
<> FLAG_NONE
) then
4987 if FFlag
= FLAG_RED
then
4988 s
:= _lc
[I_PLAYER_FLAG_RED
]
4990 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
4992 evtype
:= FLAG_STATE_SCORED
;
4994 ts
:= Format('%.4d', [gFlags
[FFlag
].CaptureTime
]);
4995 Insert('.', ts
, Length(ts
) + 1 - 3);
4996 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_CAPTURE
], [FName
, s
, ts
]), True);
4998 g_Map_ResetFlag(FFlag
);
4999 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_CAPTURE
], [AnsiUpperCase(s
)]), 144);
5001 if ((Self
= gPlayer1
) or (Self
= gPlayer2
)
5002 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= FTeam
))
5003 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= FTeam
))) then
5008 if not sound_cap_flag
[a
].IsPlaying() then
5009 sound_cap_flag
[a
].Play();
5011 gTeamStat
[FTeam
].Goals
:= gTeamStat
[FTeam
].Goals
+ 1;
5014 if g_Game_IsNet
then
5016 MH_SEND_FlagEvent(evtype
, FFlag
, FUID
, False);
5020 gFlags
[FFlag
].CaptureTime
:= 0;
5025 // Подобрал свой флаг - вернул его на базу:
5026 if (Flag
= FTeam
) and
5027 (gFlags
[Flag
].State
= FLAG_STATE_DROPPED
) then
5029 if Flag
= FLAG_RED
then
5030 s
:= _lc
[I_PLAYER_FLAG_RED
]
5032 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5034 evtype
:= FLAG_STATE_RETURNED
;
5035 gFlags
[Flag
].CaptureTime
:= 0;
5037 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_RETURN
], [FName
, s
]), True);
5039 g_Map_ResetFlag(Flag
);
5040 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
5042 if ((Self
= gPlayer1
) or (Self
= gPlayer2
)
5043 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= FTeam
))
5044 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= FTeam
))) then
5049 if not sound_ret_flag
[a
].IsPlaying() then
5050 sound_ret_flag
[a
].Play();
5053 if g_Game_IsNet
then
5055 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5061 // Подобрал чужой флаг:
5062 if (Flag
<> FTeam
) and (FTime
[T_FLAGCAP
] <= gTime
) then
5066 if Flag
= FLAG_RED
then
5067 s
:= _lc
[I_PLAYER_FLAG_RED
]
5069 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5071 evtype
:= FLAG_STATE_CAPTURED
;
5073 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_GET
], [FName
, s
]), True);
5075 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_GET
], [AnsiUpperCase(s
)]), 144);
5077 gFlags
[Flag
].State
:= FLAG_STATE_CAPTURED
;
5079 if ((Self
= gPlayer1
) or (Self
= gPlayer2
)
5080 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= FTeam
))
5081 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= FTeam
))) then
5086 if not sound_get_flag
[a
].IsPlaying() then
5087 sound_get_flag
[a
].Play();
5090 if g_Game_IsNet
then
5092 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5098 procedure TPlayer
.SetFlag(Flag
: Byte);
5101 if FModel
<> nil then
5102 FModel
.SetFlag(FFlag
);
5105 function TPlayer
.DropFlag(Silent
: Boolean = True): Boolean;
5111 if (not g_Game_IsServer
) or (FFlag
= FLAG_NONE
) then
5113 FTime
[T_FLAGCAP
] := gTime
+ 2000;
5114 with gFlags
[FFlag
] do
5118 Direction
:= FDirection
;
5119 State
:= FLAG_STATE_DROPPED
;
5121 g_Obj_Push(@Obj
, (FObj
.Vel
.X
div 2)-2+Random(5),
5122 (FObj
.Vel
.Y
div 2)-2+Random(5));
5123 positionChanged(); // this updates spatial accelerators
5125 if FFlag
= FLAG_RED
then
5126 s
:= _lc
[I_PLAYER_FLAG_RED
]
5128 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5130 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_DROP
], [FName
, s
]), True);
5131 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_DROP
], [AnsiUpperCase(s
)]), 144);
5133 if ((Self
= gPlayer1
) or (Self
= gPlayer2
)
5134 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= FTeam
))
5135 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= FTeam
))) then
5140 if (not Silent
) and (not sound_lost_flag
[a
].IsPlaying()) then
5141 sound_lost_flag
[a
].Play();
5143 if g_Game_IsNet
then
5144 MH_SEND_FlagEvent(FLAG_STATE_DROPPED
, Flag
, FUID
, False);
5150 procedure TPlayer
.GetSecret();
5152 if (self
= gPlayer1
) or (self
= gPlayer2
) then
5154 g_Console_Add(Format(_lc
[I_PLAYER_SECRET
], [FName
]), True);
5155 g_Sound_PlayEx('SOUND_GAME_SECRET');
5160 procedure TPlayer
.PressKey(Key
: Byte; Time
: Word = 1);
5162 Assert(Key
<= High(FKeys
));
5164 FKeys
[Key
].Pressed
:= True;
5165 FKeys
[Key
].Time
:= Time
;
5168 function TPlayer
.IsKeyPressed(K
: Byte): Boolean;
5170 Result
:= FKeys
[K
].Pressed
;
5173 procedure TPlayer
.ReleaseKeys();
5177 for a
:= Low(FKeys
) to High(FKeys
) do
5179 FKeys
[a
].Pressed
:= False;
5184 procedure TPlayer
.OnDamage(Angle
: SmallInt);
5188 function TPlayer
.firediry(): Integer;
5190 if FKeys
[KEY_UP
].Pressed
then Result
:= -42
5191 else if FKeys
[KEY_DOWN
].Pressed
then Result
:= 19
5195 procedure TPlayer
.RememberState();
5198 SavedState
: TPlayerSavedState
;
5200 SavedState
.Health
:= FHealth
;
5201 SavedState
.Armor
:= FArmor
;
5202 SavedState
.Air
:= FAir
;
5203 SavedState
.JetFuel
:= FJetFuel
;
5204 SavedState
.CurrWeap
:= FCurrWeap
;
5205 SavedState
.NextWeap
:= FNextWeap
;
5206 SavedState
.NextWeapDelay
:= FNextWeapDelay
;
5207 for i
:= Low(FWeapon
) to High(FWeapon
) do
5208 SavedState
.Weapon
[i
] := FWeapon
[i
];
5209 for i
:= Low(FAmmo
) to High(FAmmo
) do
5210 SavedState
.Ammo
[i
] := FAmmo
[i
];
5211 for i
:= Low(FMaxAmmo
) to High(FMaxAmmo
) do
5212 SavedState
.MaxAmmo
[i
] := FMaxAmmo
[i
];
5213 SavedState
.Rulez
:= FRulez
- [R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
];
5215 FSavedStateNum
:= -1;
5216 for i
:= Low(SavedStates
) to High(SavedStates
) do
5217 if not SavedStates
[i
].Used
then
5219 FSavedStateNum
:= i
;
5222 if FSavedStateNum
< 0 then
5224 SetLength(SavedStates
, Length(SavedStates
) + 1);
5225 FSavedStateNum
:= High(SavedStates
);
5228 SavedState
.Used
:= True;
5229 SavedStates
[FSavedStateNum
] := SavedState
;
5232 procedure TPlayer
.RecallState();
5235 SavedState
: TPlayerSavedState
;
5237 if(FSavedStateNum
< 0) or (FSavedStateNum
> High(SavedStates
)) then
5240 SavedState
:= SavedStates
[FSavedStateNum
];
5241 SavedStates
[FSavedStateNum
].Used
:= False;
5242 FSavedStateNum
:= -1;
5244 FHealth
:= SavedState
.Health
;
5245 FArmor
:= SavedState
.Armor
;
5246 FAir
:= SavedState
.Air
;
5247 FJetFuel
:= SavedState
.JetFuel
;
5248 FCurrWeap
:= SavedState
.CurrWeap
;
5249 FNextWeap
:= SavedState
.NextWeap
;
5250 FNextWeapDelay
:= SavedState
.NextWeapDelay
;
5251 for i
:= Low(FWeapon
) to High(FWeapon
) do
5252 FWeapon
[i
] := SavedState
.Weapon
[i
];
5253 for i
:= Low(FAmmo
) to High(FAmmo
) do
5254 FAmmo
[i
] := SavedState
.Ammo
[i
];
5255 for i
:= Low(FMaxAmmo
) to High(FMaxAmmo
) do
5256 FMaxAmmo
[i
] := SavedState
.MaxAmmo
[i
];
5257 FRulez
:= SavedState
.Rulez
;
5259 if gGameSettings
.GameType
= GT_SERVER
then
5260 MH_SEND_PlayerStats(FUID
);
5263 procedure TPlayer
.SaveState (st
: TStream
);
5269 utils
.writeSign(st
, 'PLYR');
5270 utils
.writeInt(st
, Byte(PLR_SAVE_VERSION
)); // version
5272 utils
.writeBool(st
, FIamBot
);
5274 utils
.writeInt(st
, Word(FUID
));
5276 utils
.writeStr(st
, FName
);
5278 utils
.writeInt(st
, Byte(FTeam
));
5280 utils
.writeBool(st
, FAlive
);
5281 // Израсходовал ли все жизни
5282 utils
.writeBool(st
, FNoRespawn
);
5284 if FDirection
= TDirection
.D_LEFT
then b
:= 1 else b
:= 2; // D_RIGHT
5285 utils
.writeInt(st
, Byte(b
));
5287 utils
.writeInt(st
, LongInt(FHealth
));
5288 // Коэффициент инвалидности
5289 utils
.writeInt(st
, LongInt(FHandicap
));
5291 utils
.writeInt(st
, Byte(FLives
));
5293 utils
.writeInt(st
, LongInt(FArmor
));
5295 utils
.writeInt(st
, LongInt(FAir
));
5297 utils
.writeInt(st
, LongInt(FJetFuel
));
5299 utils
.writeInt(st
, LongInt(FPain
));
5301 utils
.writeInt(st
, LongInt(FKills
));
5303 utils
.writeInt(st
, LongInt(FMonsterKills
));
5305 utils
.writeInt(st
, LongInt(FFrags
));
5307 utils
.writeInt(st
, Byte(FFragCombo
));
5308 // Время последнего фрага
5309 utils
.writeInt(st
, LongWord(FLastFrag
));
5311 utils
.writeInt(st
, LongInt(FDeath
));
5313 utils
.writeInt(st
, Byte(FFlag
));
5315 utils
.writeInt(st
, LongInt(FSecrets
));
5317 utils
.writeInt(st
, Byte(FCurrWeap
));
5319 utils
.writeInt(st
, Word(FNextWeap
));
5321 utils
.writeInt(st
, Byte(FNextWeapDelay
));
5322 // Время зарядки BFG
5323 utils
.writeInt(st
, SmallInt(FBFGFireCounter
));
5325 utils
.writeInt(st
, LongInt(FDamageBuffer
));
5326 // Последний ударивший
5327 utils
.writeInt(st
, Word(FLastSpawnerUID
));
5328 // Тип последнего полученного урона
5329 utils
.writeInt(st
, Byte(FLastHit
));
5331 Obj_SaveState(st
, @FObj
);
5332 // Текущее количество патронов
5333 for i
:= A_BULLETS
to A_HIGH
do utils
.writeInt(st
, Word(FAmmo
[i
]));
5334 // Максимальное количество патронов
5335 for i
:= A_BULLETS
to A_HIGH
do utils
.writeInt(st
, Word(FMaxAmmo
[i
]));
5337 for i
:= WP_FIRST
to WP_LAST
do utils
.writeBool(st
, FWeapon
[i
]);
5338 // Время перезарядки оружия
5339 for i
:= WP_FIRST
to WP_LAST
do utils
.writeInt(st
, Word(FReloading
[i
]));
5341 utils
.writeBool(st
, (R_ITEM_BACKPACK
in FRulez
));
5342 // Наличие красного ключа
5343 utils
.writeBool(st
, (R_KEY_RED
in FRulez
));
5344 // Наличие зеленого ключа
5345 utils
.writeBool(st
, (R_KEY_GREEN
in FRulez
));
5346 // Наличие синего ключа
5347 utils
.writeBool(st
, (R_KEY_BLUE
in FRulez
));
5349 utils
.writeBool(st
, (R_BERSERK
in FRulez
));
5350 // Время действия специальных предметов
5351 for i
:= MR_SUIT
to MR_MAX
do utils
.writeInt(st
, LongWord(FMegaRulez
[i
]));
5352 // Время до повторного респауна, смены оружия, исользования, захвата флага
5353 for i
:= T_RESPAWN
to T_FLAGCAP
do utils
.writeInt(st
, LongWord(FTime
[i
]));
5355 utils
.writeStr(st
, FModel
.GetName());
5357 utils
.writeInt(st
, Byte(FColor
.R
));
5358 utils
.writeInt(st
, Byte(FColor
.G
));
5359 utils
.writeInt(st
, Byte(FColor
.B
));
5363 procedure TPlayer
.LoadState (st
: TStream
);
5372 if not utils
.checkSign(st
, 'PLYR') then raise XStreamError
.Create('invalid player signature');
5373 if (utils
.readByte(st
) <> PLR_SAVE_VERSION
) then raise XStreamError
.Create('invalid player version');
5375 FIamBot
:= utils
.readBool(st
);
5377 FUID
:= utils
.readWord(st
);
5379 str
:= utils
.readStr(st
);
5380 if (self
<> gPlayer1
) and (self
<> gPlayer2
) then FName
:= str
;
5382 FTeam
:= utils
.readByte(st
);
5384 FAlive
:= utils
.readBool(st
);
5385 // Израсходовал ли все жизни
5386 FNoRespawn
:= utils
.readBool(st
);
5388 b
:= utils
.readByte(st
);
5389 if b
= 1 then FDirection
:= TDirection
.D_LEFT
else FDirection
:= TDirection
.D_RIGHT
; // b = 2
5391 FHealth
:= utils
.readLongInt(st
);
5392 // Коэффициент инвалидности
5393 FHandicap
:= utils
.readLongInt(st
);
5395 FLives
:= utils
.readByte(st
);
5397 FArmor
:= utils
.readLongInt(st
);
5399 FAir
:= utils
.readLongInt(st
);
5401 FJetFuel
:= utils
.readLongInt(st
);
5403 FPain
:= utils
.readLongInt(st
);
5405 FKills
:= utils
.readLongInt(st
);
5407 FMonsterKills
:= utils
.readLongInt(st
);
5409 FFrags
:= utils
.readLongInt(st
);
5411 FFragCombo
:= utils
.readByte(st
);
5412 // Время последнего фрага
5413 FLastFrag
:= utils
.readLongWord(st
);
5415 FDeath
:= utils
.readLongInt(st
);
5417 FFlag
:= utils
.readByte(st
);
5419 FSecrets
:= utils
.readLongInt(st
);
5421 FCurrWeap
:= utils
.readByte(st
);
5423 FNextWeap
:= utils
.readWord(st
);
5425 FNextWeapDelay
:= utils
.readByte(st
);
5426 // Время зарядки BFG
5427 FBFGFireCounter
:= utils
.readSmallInt(st
);
5429 FDamageBuffer
:= utils
.readLongInt(st
);
5430 // Последний ударивший
5431 FLastSpawnerUID
:= utils
.readWord(st
);
5432 // Тип последнего полученного урона
5433 FLastHit
:= utils
.readByte(st
);
5435 Obj_LoadState(@FObj
, st
);
5436 // Текущее количество патронов
5437 for i
:= A_BULLETS
to A_HIGH
do FAmmo
[i
] := utils
.readWord(st
);
5438 // Максимальное количество патронов
5439 for i
:= A_BULLETS
to A_HIGH
do FMaxAmmo
[i
] := utils
.readWord(st
);
5441 for i
:= WP_FIRST
to WP_LAST
do FWeapon
[i
] := utils
.readBool(st
);
5442 // Время перезарядки оружия
5443 for i
:= WP_FIRST
to WP_LAST
do FReloading
[i
] := utils
.readWord(st
);
5445 if utils
.readBool(st
) then Include(FRulez
, R_ITEM_BACKPACK
);
5446 // Наличие красного ключа
5447 if utils
.readBool(st
) then Include(FRulez
, R_KEY_RED
);
5448 // Наличие зеленого ключа
5449 if utils
.readBool(st
) then Include(FRulez
, R_KEY_GREEN
);
5450 // Наличие синего ключа
5451 if utils
.readBool(st
) then Include(FRulez
, R_KEY_BLUE
);
5453 if utils
.readBool(st
) then Include(FRulez
, R_BERSERK
);
5454 // Время действия специальных предметов
5455 for i
:= MR_SUIT
to MR_MAX
do FMegaRulez
[i
] := utils
.readLongWord(st
);
5456 // Время до повторного респауна, смены оружия, исользования, захвата флага
5457 for i
:= T_RESPAWN
to T_FLAGCAP
do FTime
[i
] := utils
.readLongWord(st
);
5459 str
:= utils
.readStr(st
);
5461 FColor
.R
:= utils
.readByte(st
);
5462 FColor
.G
:= utils
.readByte(st
);
5463 FColor
.B
:= utils
.readByte(st
);
5464 if (self
= gPlayer1
) then
5466 str
:= gPlayer1Settings
.Model
;
5467 FColor
:= gPlayer1Settings
.Color
;
5469 else if (self
= gPlayer2
) then
5471 str
:= gPlayer2Settings
.Model
;
5472 FColor
:= gPlayer2Settings
.Color
;
5474 // Обновляем модель игрока
5476 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
5477 FModel
.Color
:= TEAMCOLOR
[FTeam
]
5479 FModel
.Color
:= FColor
;
5483 procedure TPlayer
.AllRulez(Health
: Boolean);
5489 FHealth
:= PLAYER_HP_LIMIT
;
5490 FArmor
:= PLAYER_AP_LIMIT
;
5494 for a
:= WP_FIRST
to WP_LAST
do FWeapon
[a
] := True;
5495 for a
:= A_BULLETS
to A_HIGH
do FAmmo
[a
] := 30000;
5496 FRulez
:= FRulez
+[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
];
5499 procedure TPlayer
.RestoreHealthArmor();
5501 FHealth
:= PLAYER_HP_LIMIT
;
5502 FArmor
:= PLAYER_AP_LIMIT
;
5505 procedure TPlayer
.FragCombo();
5509 if (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) or g_Game_IsClient
then
5511 if gTime
- FLastFrag
< FRAG_COMBO_TIME
then
5513 if FFragCombo
< 5 then
5515 Param
:= FUID
or (FFragCombo
shl 16);
5516 if (FComboEvnt
>= Low(gDelayedEvents
)) and
5517 (FComboEvnt
<= High(gDelayedEvents
)) and
5518 gDelayedEvents
[FComboEvnt
].Pending
and
5519 (gDelayedEvents
[FComboEvnt
].DEType
= DE_KILLCOMBO
) and
5520 (gDelayedEvents
[FComboEvnt
].DENum
and $FFFF = FUID
) then
5522 gDelayedEvents
[FComboEvnt
].Time
:= gTime
+ 500;
5523 gDelayedEvents
[FComboEvnt
].DENum
:= Param
;
5526 FComboEvnt
:= g_Game_DelayEvent(DE_KILLCOMBO
, 500, Param
);
5534 procedure TPlayer
.GiveItem(ItemType
: Byte);
5538 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
5540 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
5544 if FAir
< AIR_MAX
then
5551 if not (R_BERSERK
in FRulez
) then
5553 Include(FRulez
, R_BERSERK
);
5554 if FBFGFireCounter
< 1 then
5556 FCurrWeap
:= WEAPON_KASTET
;
5558 FModel
.SetWeapon(WEAPON_KASTET
);
5562 FBerserk
:= gTime
+30000;
5564 if FHealth
< PLAYER_HP_SOFT
then
5566 FHealth
:= PLAYER_HP_SOFT
;
5567 FBerserk
:= gTime
+30000;
5572 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
5574 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
5579 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
5581 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
5585 if FJetFuel
< JET_MAX
then
5587 FJetFuel
:= JET_MAX
;
5590 ITEM_MEDKIT_SMALL
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
5591 ITEM_MEDKIT_LARGE
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
5593 ITEM_ARMOR_GREEN
: if FArmor
< PLAYER_AP_SOFT
then FArmor
:= PLAYER_AP_SOFT
;
5594 ITEM_ARMOR_BLUE
: if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
5596 ITEM_SPHERE_BLUE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
5598 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) then
5600 if FHealth
< PLAYER_HP_LIMIT
then FHealth
:= PLAYER_HP_LIMIT
;
5601 if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
5604 ITEM_WEAPON_SAW
: FWeapon
[WEAPON_SAW
] := True;
5605 ITEM_WEAPON_SHOTGUN1
: FWeapon
[WEAPON_SHOTGUN1
] := True;
5606 ITEM_WEAPON_SHOTGUN2
: FWeapon
[WEAPON_SHOTGUN2
] := True;
5607 ITEM_WEAPON_CHAINGUN
: FWeapon
[WEAPON_CHAINGUN
] := True;
5608 ITEM_WEAPON_ROCKETLAUNCHER
: FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
5609 ITEM_WEAPON_PLASMA
: FWeapon
[WEAPON_PLASMA
] := True;
5610 ITEM_WEAPON_BFG
: FWeapon
[WEAPON_BFG
] := True;
5611 ITEM_WEAPON_SUPERPULEMET
: FWeapon
[WEAPON_SUPERPULEMET
] := True;
5612 ITEM_WEAPON_FLAMETHROWER
: FWeapon
[WEAPON_FLAMETHROWER
] := True;
5614 ITEM_AMMO_BULLETS
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
5615 ITEM_AMMO_BULLETS_BOX
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
5616 ITEM_AMMO_SHELLS
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
5617 ITEM_AMMO_SHELLS_BOX
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
5618 ITEM_AMMO_ROCKET
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
5619 ITEM_AMMO_ROCKET_BOX
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
5620 ITEM_AMMO_CELL
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
5621 ITEM_AMMO_CELL_BIG
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
5622 ITEM_AMMO_FUELCAN
: if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
5625 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
5626 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
5627 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
5628 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or
5629 (FMaxAmmo
[A_FUEL
] < AmmoLimits
[1, A_FUEL
]) then
5631 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[1, A_BULLETS
];
5632 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[1, A_SHELLS
];
5633 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[1, A_ROCKETS
];
5634 FMaxAmmo
[A_CELLS
] := AmmoLimits
[1, A_CELLS
];
5635 FMaxAmmo
[A_FUEL
] := AmmoLimits
[1, A_FUEL
];
5637 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
5638 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
5639 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
5640 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
5642 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
5645 ITEM_KEY_RED
: if not (R_KEY_RED
in FRulez
) then Include(FRulez
, R_KEY_RED
);
5646 ITEM_KEY_GREEN
: if not (R_KEY_GREEN
in FRulez
) then Include(FRulez
, R_KEY_GREEN
);
5647 ITEM_KEY_BLUE
: if not (R_KEY_BLUE
in FRulez
) then Include(FRulez
, R_KEY_BLUE
);
5649 ITEM_BOTTLE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
5650 ITEM_HELMET
: if FArmor
< PLAYER_AP_LIMIT
then IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
5655 if g_Game_IsNet
and g_Game_IsServer
then
5656 MH_SEND_PlayerStats(FUID
);
5659 procedure TPlayer
.FlySmoke(Times
: DWORD
= 1);
5662 if (Random(5) = 1) and (Times
= 1) then
5665 if BodyInLiquid(0, 0) then
5667 g_GFX_Bubbles(Obj
.X
+Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2)+Random(3)-1,
5668 Obj
.Y
+Obj
.Rect
.Height
+8, 1, 8, 4);
5669 if Random(2) = 0 then
5670 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
5672 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
5676 for i
:= 1 to Times
do
5680 Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(R_GFX_SMOKE_WIDTH
div 2),
5681 Obj
.Y
+Obj
.Rect
.Height
-4+Random(8+Times
*2)
5686 procedure TPlayer
.OnFireFlame(Times
: DWORD
= 1);
5689 if (Random(10) = 1) and (Times
= 1) then
5692 for i
:= 1 to Times
do
5696 Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(R_GFX_FLAME_WIDTH
div 2),
5697 Obj
.Y
+8+Random(8+Times
*2)
5702 procedure TPlayer
.PauseSounds(Enable
: Boolean);
5704 FSawSound
.Pause(Enable
);
5705 FSawSoundIdle
.Pause(Enable
);
5706 FSawSoundHit
.Pause(Enable
);
5707 FSawSoundSelect
.Pause(Enable
);
5708 FFlameSoundOn
.Pause(Enable
);
5709 FFlameSoundOff
.Pause(Enable
);
5710 FFlameSoundWork
.Pause(Enable
);
5711 FJetSoundFly
.Pause(Enable
);
5712 FJetSoundOn
.Pause(Enable
);
5713 FJetSoundOff
.Pause(Enable
);
5718 constructor TCorpse
.Create(X
, Y
: Integer; ModelName
: String; aMess
: Boolean);
5723 FObj
.Rect
:= PLAYER_CORPSERECT
;
5725 FModel
:= g_PlayerModel_Get(ModelName
);
5729 FState
:= CORPSE_STATE_MESS
;
5730 FModel
.ChangeAnimation(A_DIE2
);
5734 FState
:= CORPSE_STATE_NORMAL
;
5735 FModel
.ChangeAnimation(A_DIE1
);
5739 destructor TCorpse
.Destroy();
5745 function TCorpse
.ObjPtr (): PObj
; inline; begin result
:= @FObj
; end;
5747 procedure TCorpse
.positionChanged (); inline; begin end;
5749 procedure TCorpse
.moveBy (dx
, dy
: Integer); inline;
5751 if (dx
<> 0) or (dy
<> 0) then
5760 procedure TCorpse
.getMapBox (out x
, y
, w
, h
: Integer); inline;
5762 x
:= FObj
.X
+PLAYER_CORPSERECT
.X
;
5763 y
:= FObj
.Y
+PLAYER_CORPSERECT
.Y
;
5764 w
:= PLAYER_CORPSERECT
.Width
;
5765 h
:= PLAYER_CORPSERECT
.Height
;
5769 procedure TCorpse
.Damage(Value
: Word; SpawnerUID
: Word; vx
, vy
: Integer);
5770 var Blood
: TModelBlood
;
5772 if FState
= CORPSE_STATE_REMOVEME
then
5775 FDamage
:= FDamage
+ Value
;
5777 if FDamage
> 150 then
5779 if FModel
<> nil then
5781 FState
:= CORPSE_STATE_REMOVEME
;
5783 g_Player_CreateGibs(
5784 FObj
.X
+ FObj
.Rect
.X
+ (FObj
.Rect
.Width
div 2),
5785 FObj
.Y
+ FObj
.Rect
.Y
+ (FObj
.Rect
.Height
div 2),
5790 // Звук мяса от трупа:
5791 FModel
.PlaySound(MODELSOUND_DIE
, 5, FObj
.X
, FObj
.Y
);
5794 if (gBodyKillEvent
<> -1) and gDelayedEvents
[gBodyKillEvent
].Pending
then
5795 gDelayedEvents
[gBodyKillEvent
].Pending
:= False;
5796 gBodyKillEvent
:= g_Game_DelayEvent(DE_BODYKILL
, 1050, SpawnerUID
);
5804 Blood
:= FModel
.GetBlood();
5805 FObj
.Vel
.X
:= FObj
.Vel
.X
+ vx
;
5806 FObj
.Vel
.Y
:= FObj
.Vel
.Y
+ vy
;
5807 g_GFX_Blood(FObj
.X
+PLAYER_CORPSERECT
.X
+(PLAYER_CORPSERECT
.Width
div 2),
5808 FObj
.Y
+PLAYER_CORPSERECT
.Y
+(PLAYER_CORPSERECT
.Height
div 2),
5809 Value
, vx
, vy
, 16, (PLAYER_CORPSERECT
.Height
*2) div 3,
5810 Blood
.R
, Blood
.G
, Blood
.B
, Blood
.Kind
);
5814 procedure TCorpse
.Update();
5818 if FState
= CORPSE_STATE_REMOVEME
then
5821 FObj
.oldX
:= FObj
.X
;
5822 FObj
.oldY
:= FObj
.Y
;
5824 if gTime
mod (GAME_TICK
*2) <> 0 then
5826 g_Obj_Move(@FObj
, True, True, True);
5827 positionChanged(); // this updates spatial accelerators
5831 // Сопротивление воздуха для трупа:
5832 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
5834 st
:= g_Obj_Move(@FObj
, True, True, True);
5835 positionChanged(); // this updates spatial accelerators
5837 if WordBool(st
and MOVE_FALLOUT
) then
5839 FState
:= CORPSE_STATE_REMOVEME
;
5843 if FModel
<> nil then
5848 procedure TCorpse
.SaveState (st
: TStream
);
5854 utils
.writeSign(st
, 'CORP');
5855 utils
.writeInt(st
, Byte(0));
5857 utils
.writeInt(st
, Byte(FState
));
5859 utils
.writeInt(st
, Byte(FDamage
));
5861 utils
.writeInt(st
, Byte(FModel
.Color
.R
));
5862 utils
.writeInt(st
, Byte(FModel
.Color
.G
));
5863 utils
.writeInt(st
, Byte(FModel
.Color
.B
));
5865 Obj_SaveState(st
, @FObj
);
5866 utils
.writeInt(st
, Word(FPlayerUID
));
5868 anim
:= (FModel
<> nil);
5869 utils
.writeBool(st
, anim
);
5870 if anim
then FModel
.AnimState
.SaveState(st
);
5871 // animation for mask (same as animation, compat with older saves)
5872 anim
:= (FModel
<> nil);
5873 utils
.writeBool(st
, anim
);
5874 if anim
then FModel
.AnimState
.SaveState(st
);
5878 procedure TCorpse
.LoadState (st
: TStream
);
5879 var anim
: Boolean; r
, g
, b
: Byte; stub
: TAnimationState
;
5884 if not utils
.checkSign(st
, 'CORP') then raise XStreamError
.Create('invalid corpse signature');
5885 if (utils
.readByte(st
) <> 0) then raise XStreamError
.Create('invalid corpse version');
5887 FState
:= utils
.readByte(st
);
5889 FDamage
:= utils
.readByte(st
);
5891 r
:= utils
.readByte(st
);
5892 g
:= utils
.readByte(st
);
5893 b
:= utils
.readByte(st
);
5894 FModel
.SetColor(r
, g
, b
);
5896 Obj_LoadState(@FObj
, st
);
5897 FPlayerUID
:= utils
.readWord(st
);
5899 stub
:= TAnimationState
.Create(False, 0, 0);
5900 anim
:= utils
.readBool(st
);
5904 FModel
.AnimState
.CurrentFrame
:= Min(stub
.CurrentFrame
, FModel
.AnimState
.Length
);
5911 // animation for mask (same as animation, compat with older saves)
5912 anim
:= utils
.readBool(st
);
5913 if anim
then stub
.LoadState(st
);
5919 constructor TBot
.Create();
5926 FSpectator
:= False;
5933 for a
:= WP_FIRST
to WP_LAST
do
5935 FDifficult
.WeaponPrior
[a
] := WEAPON_PRIOR1
[a
];
5936 FDifficult
.CloseWeaponPrior
[a
] := WEAPON_PRIOR2
[a
];
5937 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
5941 destructor TBot
.Destroy();
5944 inherited Destroy();
5947 procedure TBot
.Respawn(Silent
: Boolean; Force
: Boolean = False);
5949 inherited Respawn(Silent
, Force
);
5952 FSelectedWeapon
:= FCurrWeap
;
5957 procedure TBot
.UpdateCombat();
5970 TTargetRecord
= array of TTarget
;
5972 function Compare(a
, b
: TTarget
): Integer;
5974 if a
.Line
and not b
.Line
then // A на линии огня
5977 if not a
.Line
and b
.Line
then // B на линии огня
5979 else // И A, и B на линии или не на линии огня
5980 if (a
.Line
and b
.Line
) or ((not a
.Line
) and (not b
.Line
)) then
5982 if a
.Dist
> b
.Dist
then // B ближе
5984 else // A ближе или равноудаленно с B
5987 else // Странно -> A
5992 a
, x1
, y1
, x2
, y2
: Integer;
5993 targets
: TTargetRecord
;
5995 Target
, BestTarget
: TTarget
;
5996 firew
, fireh
: Integer;
6000 vsPlayer
, vsMonster
, ok
: Boolean;
6003 function monsUpdate (mon
: TMonster
): Boolean;
6005 result
:= false; // don't stop
6006 if mon
.alive
and (mon
.MonsterType
<> MONSTER_BARREL
) then
6008 if not TargetOnScreen(mon
.Obj
.X
+mon
.Obj
.Rect
.X
, mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
) then exit
;
6010 x2
:= mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2);
6011 y2
:= mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+(mon
.Obj
.Rect
.Height
div 2);
6013 // Если монстр на экране и не прикрыт стеной
6014 if g_TraceVector(x1
, y1
, x2
, y2
) then
6016 // Добавляем к списку возможных целей
6017 SetLength(targets
, Length(targets
)+1);
6018 with targets
[High(targets
)] do
6025 Rect
:= mon
.Obj
.Rect
;
6026 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6027 Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6028 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6037 vsPlayer
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
);
6038 vsMonster
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
);
6040 // Если текущее оружие не то, что нужно, то меняем:
6041 if FCurrWeap
<> FSelectedWeapon
then
6044 // Если нужно стрелять и нужное оружие, то нажать "Стрелять":
6045 if (GetAIFlag('NEEDFIRE') <> '') and (FCurrWeap
= FSelectedWeapon
) then
6047 RemoveAIFlag('NEEDFIRE');
6050 WEAPON_PLASMA
, WEAPON_SUPERPULEMET
, WEAPON_CHAINGUN
: PressKey(KEY_FIRE
, 20);
6051 WEAPON_SAW
, WEAPON_KASTET
, WEAPON_FLAMETHROWER
: PressKey(KEY_FIRE
, 40);
6052 else PressKey(KEY_FIRE
);
6056 // Координаты ствола:
6057 x1
:= FObj
.X
+ WEAPONPOINT
[FDirection
].X
;
6058 y1
:= FObj
.Y
+ WEAPONPOINT
[FDirection
].Y
;
6060 Target
.UID
:= FTargetUID
;
6063 if Target
.UID
<> 0 then
6064 begin // Цель есть - настраиваем
6065 if (g_GetUIDType(Target
.UID
) = UID_PLAYER
) and
6068 tpla
:= g_Player_Get(Target
.UID
);
6072 if (@FObj
) <> nil then
6079 Target
.cX
:= Target
.X
+ PLAYER_RECT_CX
;
6080 Target
.cY
:= Target
.Y
+ PLAYER_RECT_CY
;
6081 Target
.Rect
:= PLAYER_RECT
;
6082 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6083 Target
.Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6084 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6085 Target
.IsPlayer
:= True;
6089 if (g_GetUIDType(Target
.UID
) = UID_MONSTER
) and
6092 mon
:= g_Monsters_ByUID(Target
.UID
);
6095 Target
.X
:= mon
.Obj
.X
;
6096 Target
.Y
:= mon
.Obj
.Y
;
6098 Target
.cX
:= Target
.X
+ mon
.Obj
.Rect
.X
+ (mon
.Obj
.Rect
.Width
div 2);
6099 Target
.cY
:= Target
.Y
+ mon
.Obj
.Rect
.Y
+ (mon
.Obj
.Rect
.Height
div 2);
6100 Target
.Rect
:= mon
.Obj
.Rect
;
6101 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6102 Target
.Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6103 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6104 Target
.IsPlayer
:= False;
6111 begin // Цели нет - обнуляем
6116 Target
.Visible
:= False;
6117 Target
.Line
:= False;
6118 Target
.IsPlayer
:= False;
6123 // Если цель не видима или не на линии огня, то ищем все возможные цели:
6124 if (not Target
.Line
) or (not Target
.Visible
) then
6128 for a
:= 0 to High(gPlayers
) do
6129 if (gPlayers
[a
] <> nil) and (gPlayers
[a
].alive
) and
6130 (gPlayers
[a
].FUID
<> FUID
) and
6131 (not SameTeam(FUID
, gPlayers
[a
].FUID
)) and
6132 (not gPlayers
[a
].NoTarget
) and
6133 (gPlayers
[a
].FMegaRulez
[MR_INVIS
] < gTime
) then
6135 if not TargetOnScreen(gPlayers
[a
].FObj
.X
+ PLAYER_RECT
.X
,
6136 gPlayers
[a
].FObj
.Y
+ PLAYER_RECT
.Y
) then
6139 x2
:= gPlayers
[a
].FObj
.X
+ PLAYER_RECT_CX
;
6140 y2
:= gPlayers
[a
].FObj
.Y
+ PLAYER_RECT_CY
;
6142 // Если игрок на экране и не прикрыт стеной:
6143 if g_TraceVector(x1
, y1
, x2
, y2
) then
6145 // Добавляем к списку возможных целей:
6146 SetLength(targets
, Length(targets
)+1);
6147 with targets
[High(targets
)] do
6149 UID
:= gPlayers
[a
].FUID
;
6150 X
:= gPlayers
[a
].FObj
.X
;
6151 Y
:= gPlayers
[a
].FObj
.Y
;
6154 Rect
:= PLAYER_RECT
;
6155 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6156 Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6157 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6165 if vsMonster
then g_Mons_ForEach(monsUpdate
);
6168 // Если есть возможные цели:
6169 // (Выбираем лучшую, меняем оружие и бежим к ней/от нее)
6170 if targets
<> nil then
6172 // Выбираем наилучшую цель:
6173 BestTarget
:= targets
[0];
6174 if Length(targets
) > 1 then
6175 for a
:= 1 to High(targets
) do
6176 if Compare(BestTarget
, targets
[a
]) = 1 then
6177 BestTarget
:= targets
[a
];
6179 // Если лучшая цель "виднее" текущей, то текущая := лучшая:
6180 if ((not Target
.Visible
) and BestTarget
.Visible
and (Target
.UID
<> BestTarget
.UID
)) or
6181 ((not Target
.Line
) and BestTarget
.Line
and BestTarget
.Visible
) then
6183 Target
:= BestTarget
;
6185 if (Healthy() = 3) or ((Healthy() = 2)) then
6186 begin // Если здоровы - догоняем
6187 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
6188 SetAIFlag('GORIGHT', '1');
6189 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6190 SetAIFlag('GOLEFT', '1');
6193 begin // Если побиты - убегаем
6194 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) then
6195 SetAIFlag('GORIGHT', '1');
6196 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6197 SetAIFlag('GOLEFT', '1');
6200 // Выбираем оружие на основе расстояния и приоритетов:
6201 SelectWeapon(Abs(x1
-Target
.cX
));
6206 // (Догоняем/убегаем, стреляем по направлению к цели)
6207 // (Если цель далеко, то хватит следить за ней)
6208 if Target
.UID
<> 0 then
6210 if not TargetOnScreen(Target
.X
+ Target
.Rect
.X
,
6211 Target
.Y
+ Target
.Rect
.Y
) then
6212 begin // Цель сбежала с "экрана"
6213 if (Healthy() = 3) or ((Healthy() = 2)) then
6214 begin // Если здоровы - догоняем
6215 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
6216 SetAIFlag('GORIGHT', '1');
6217 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6218 SetAIFlag('GOLEFT', '1');
6221 begin // Если побиты - забываем о цели и убегаем
6223 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) then
6224 SetAIFlag('GORIGHT', '1');
6225 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6226 SetAIFlag('GOLEFT', '1');
6230 begin // Цель пока на "экране"
6231 // Если цель не загорожена стеной, то отмечаем, когда ее видели:
6232 if g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6233 FLastVisible
:= gTime
;
6234 // Если разница высот не велика, то догоняем:
6235 if (Abs(FObj
.Y
-Target
.Y
) <= 128) then
6237 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
6238 SetAIFlag('GORIGHT', '1');
6239 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6240 SetAIFlag('GOLEFT', '1');
6244 // Выбираем угол вверх:
6245 if FDirection
= TDirection
.D_LEFT
then
6246 angle
:= ANGLE_LEFTUP
6248 angle
:= ANGLE_RIGHTUP
;
6250 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6251 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6253 // Если при угле вверх можно попасть в приблизительное положение цели:
6254 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6255 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128), //96
6256 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6257 Target
.Rect
.Width
, Target
.Rect
.Height
) and
6258 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6259 begin // то нужно стрелять вверх
6260 SetAIFlag('NEEDFIRE', '1');
6261 SetAIFlag('NEEDSEEUP', '1');
6264 // Выбираем угол вниз:
6265 if FDirection
= TDirection
.D_LEFT
then
6266 angle
:= ANGLE_LEFTDOWN
6268 angle
:= ANGLE_RIGHTDOWN
;
6270 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6271 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6273 // Если при угле вниз можно попасть в приблизительное положение цели:
6274 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6275 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
6276 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6277 Target
.Rect
.Width
, Target
.Rect
.Height
) and
6278 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6279 begin // то нужно стрелять вниз
6280 SetAIFlag('NEEDFIRE', '1');
6281 SetAIFlag('NEEDSEEDOWN', '1');
6284 // Если цель видно и она на такой же высоте:
6285 if Target
.Visible
and
6286 (y1
+4 < Target
.Y
+Target
.Rect
.Y
+Target
.Rect
.Height
) and
6287 (y1
-4 > Target
.Y
+Target
.Rect
.Y
) then
6289 // Если идем в сторону цели, то надо стрелять:
6290 if ((FDirection
= TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) or
6291 ((FDirection
= TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6292 begin // то нужно стрелять вперед
6293 SetAIFlag('NEEDFIRE', '1');
6294 SetAIFlag('NEEDSEEDOWN', '');
6295 SetAIFlag('NEEDSEEUP', '');
6297 // Если цель в пределах "экрана" и сложность позволяет прыжки сближения:
6298 if Abs(FObj
.X
-Target
.X
) < Trunc(gPlayerScreenSize
.X
*0.75) then
6299 if GetRnd(FDifficult
.CloseJump
) then
6300 begin // то если повезет - прыгаем (особенно, если близко)
6301 if Abs(FObj
.X
-Target
.X
) < 128 then
6305 if Random(a
) = 0 then
6306 SetAIFlag('NEEDJUMP', '1');
6310 // Если цель все еще есть:
6311 if Target
.UID
<> 0 then
6312 if gTime
-FLastVisible
> 2000 then // Если видели давно
6313 Target
.UID
:= 0 // то забыть цель
6314 else // Если видели недавно
6315 begin // но цель убили
6316 if Target
.IsPlayer
then
6317 begin // Цель - игрок
6318 pla
:= g_Player_Get(Target
.UID
);
6319 if (pla
= nil) or (not pla
.alive
) or pla
.NoTarget
or
6320 (pla
.FMegaRulez
[MR_INVIS
] >= gTime
) then
6321 Target
.UID
:= 0; // то забыть цель
6324 begin // Цель - монстр
6325 mon
:= g_Monsters_ByUID(Target
.UID
);
6326 if (mon
= nil) or (not mon
.alive
) then
6327 Target
.UID
:= 0; // то забыть цель
6330 end; // if Target.UID <> 0
6332 FTargetUID
:= Target
.UID
;
6334 // Если возможных целей нет:
6335 // (Атака чего-нибудь слева или справа)
6336 if targets
= nil then
6337 if GetAIFlag('ATTACKLEFT') <> '' then
6338 begin // Если нужно атаковать налево
6339 RemoveAIFlag('ATTACKLEFT');
6341 SetAIFlag('NEEDJUMP', '1');
6343 if RunDirection() = TDirection
.D_RIGHT
then
6344 begin // Идем не в ту сторону
6345 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
6346 begin // Если здоровы, то, возможно, стреляем бежим влево и стреляем
6347 SetAIFlag('NEEDFIRE', '1');
6348 SetAIFlag('GOLEFT', '1');
6352 begin // Идем в нужную сторону
6353 if GetRnd(FDifficult
.InvisFire
) then // Возможно, стреляем вслепую
6354 SetAIFlag('NEEDFIRE', '1');
6355 if Healthy() <= 1 then // Побиты - убегаем
6356 SetAIFlag('GORIGHT', '1');
6360 if GetAIFlag('ATTACKRIGHT') <> '' then
6361 begin // Если нужно атаковать направо
6362 RemoveAIFlag('ATTACKRIGHT');
6364 SetAIFlag('NEEDJUMP', '1');
6366 if RunDirection() = TDirection
.D_LEFT
then
6367 begin // Идем не в ту сторону
6368 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
6369 begin // Если здоровы, то, возможно, бежим вправо и стреляем
6370 SetAIFlag('NEEDFIRE', '1');
6371 SetAIFlag('GORIGHT', '1');
6376 if GetRnd(FDifficult
.InvisFire
) then // Возможно, стреляем вслепую
6377 SetAIFlag('NEEDFIRE', '1');
6378 if Healthy() <= 1 then // Побиты - убегаем
6379 SetAIFlag('GOLEFT', '1');
6383 //HACK! (does it belongs there?)
6384 RealizeCurrentWeapon();
6386 // Если есть возможные цели:
6387 // (Стреляем по направлению к целям)
6388 if (targets
<> nil) and (GetAIFlag('NEEDFIRE') <> '') then
6389 for a
:= 0 to High(targets
) do
6391 // Если можем стрелять по диагонали:
6392 if GetRnd(FDifficult
.DiagFire
) then
6394 // Ищем цель сверху и стреляем, если есть:
6395 if FDirection
= TDirection
.D_LEFT
then
6396 angle
:= ANGLE_LEFTUP
6398 angle
:= ANGLE_RIGHTUP
;
6400 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6401 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6403 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6404 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
6405 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6406 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
6407 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
6409 SetAIFlag('NEEDFIRE', '1');
6410 SetAIFlag('NEEDSEEUP', '1');
6413 // Ищем цель снизу и стреляем, если есть:
6414 if FDirection
= TDirection
.D_LEFT
then
6415 angle
:= ANGLE_LEFTDOWN
6417 angle
:= ANGLE_RIGHTDOWN
;
6419 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6420 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6422 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6423 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
6424 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6425 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
6426 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
6428 SetAIFlag('NEEDFIRE', '1');
6429 SetAIFlag('NEEDSEEDOWN', '1');
6433 // Если цель "перед носом", то стреляем:
6434 if targets
[a
].Line
and targets
[a
].Visible
and
6435 (((FDirection
= TDirection
.D_LEFT
) and (targets
[a
].X
< FObj
.X
)) or
6436 ((FDirection
= TDirection
.D_RIGHT
) and (targets
[a
].X
> FObj
.X
))) then
6438 SetAIFlag('NEEDFIRE', '1');
6443 // Если летит пуля, то, возможно, подпрыгиваем:
6444 if g_Weapon_Danger(FUID
, FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
,
6445 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
,
6446 40+GetInterval(FDifficult
.Cover
, 40)) then
6447 SetAIFlag('NEEDJUMP', '1');
6449 // Если кончились паторны, то нужно сменить оружие:
6450 ammo
:= GetAmmoByWeapon(FCurrWeap
);
6451 if ((FCurrWeap
= WEAPON_SHOTGUN2
) and (ammo
< 2)) or
6452 ((FCurrWeap
= WEAPON_BFG
) and (ammo
< 40)) or
6454 SetAIFlag('SELECTWEAPON', '1');
6456 // Если нужно сменить оружие, то выбираем нужное:
6457 if GetAIFlag('SELECTWEAPON') = '1' then
6460 RemoveAIFlag('SELECTWEAPON');
6464 procedure TBot
.Update();
6477 // Проверяем, отключён ли AI ботов
6478 if (g_debug_BotAIOff
= 1) and (Team
= TEAM_RED
) then
6480 if (g_debug_BotAIOff
= 2) and (Team
= TEAM_BLUE
) then
6482 if g_debug_BotAIOff
= 3 then
6492 RealizeCurrentWeapon();
6499 procedure TBot
.ReleaseKey(Key
: Byte);
6508 function TBot
.KeyPressed(Key
: Word): Boolean;
6510 Result
:= FKeys
[Key
].Pressed
;
6513 function TBot
.GetAIFlag(aName
: String20
): String20
;
6519 aName
:= LowerCase(aName
);
6521 if FAIFlags
<> nil then
6522 for a
:= 0 to High(FAIFlags
) do
6523 if LowerCase(FAIFlags
[a
].Name
) = aName
then
6525 Result
:= FAIFlags
[a
].Value
;
6530 procedure TBot
.RemoveAIFlag(aName
: String20
);
6534 if FAIFlags
= nil then Exit
;
6536 aName
:= LowerCase(aName
);
6538 for a
:= 0 to High(FAIFlags
) do
6539 if LowerCase(FAIFlags
[a
].Name
) = aName
then
6541 if a
<> High(FAIFlags
) then
6542 for b
:= a
to High(FAIFlags
)-1 do
6543 FAIFlags
[b
] := FAIFlags
[b
+1];
6545 SetLength(FAIFlags
, Length(FAIFlags
)-1);
6550 procedure TBot
.SetAIFlag(aName
, fValue
: String20
);
6558 aName
:= LowerCase(aName
);
6560 if FAIFlags
<> nil then
6561 for a
:= 0 to High(FAIFlags
) do
6562 if LowerCase(FAIFlags
[a
].Name
) = aName
then
6568 if ok
then FAIFlags
[a
].Value
:= fValue
6571 SetLength(FAIFlags
, Length(FAIFlags
)+1);
6572 with FAIFlags
[High(FAIFlags
)] do
6580 procedure TBot
.UpdateMove
;
6582 procedure GoLeft(Time
: Word = 1);
6584 ReleaseKey(KEY_LEFT
);
6585 ReleaseKey(KEY_RIGHT
);
6586 PressKey(KEY_LEFT
, Time
);
6587 SetDirection(TDirection
.D_LEFT
);
6590 procedure GoRight(Time
: Word = 1);
6592 ReleaseKey(KEY_LEFT
);
6593 ReleaseKey(KEY_RIGHT
);
6594 PressKey(KEY_RIGHT
, Time
);
6595 SetDirection(TDirection
.D_RIGHT
);
6598 function Rnd(a
: Word): Boolean;
6600 Result
:= Random(a
) = 0;
6603 procedure Turn(Time
: Word = 1200);
6605 if RunDirection() = TDirection
.D_LEFT
then GoRight(Time
) else GoLeft(Time
);
6610 ReleaseKey(KEY_LEFT
);
6611 ReleaseKey(KEY_RIGHT
);
6614 function CanRunLeft(): Boolean;
6616 Result
:= not CollideLevel(-1, 0);
6619 function CanRunRight(): Boolean;
6621 Result
:= not CollideLevel(1, 0);
6624 function CanRun(): Boolean;
6626 if RunDirection() = TDirection
.D_LEFT
then Result
:= CanRunLeft() else Result
:= CanRunRight();
6629 procedure Jump(Time
: Word = 30);
6631 PressKey(KEY_JUMP
, Time
);
6634 function NearHole(): Boolean;
6638 { TODO 5 : Лестницы }
6639 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
6640 for x
:= 1 to PLAYER_RECT
.Width
do
6641 if (not StayOnStep(x
*sx
, 0)) and
6642 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
6643 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
6652 function BorderHole(): Boolean;
6656 { TODO 5 : Лестницы }
6657 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
6658 for x
:= 1 to PLAYER_RECT
.Width
do
6659 if (not StayOnStep(x
*sx
, 0)) and
6660 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
6661 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
6663 for xx
:= x
to x
+32 do
6664 if CollideLevel(xx
*sx
, PLAYER_RECT
.Height
) then
6674 function NearDeepHole(): Boolean;
6680 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
6683 for x
:= 1 to PLAYER_RECT
.Width
do
6684 if (not StayOnStep(x
*sx
, 0)) and
6685 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
6686 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
6688 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
6690 if CollideLevel(x
*sx
, PLAYER_RECT
.Height
*y
) then Exit
;
6695 end else Result
:= False;
6698 function OverDeepHole(): Boolean;
6705 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
6707 if CollideLevel(0, PLAYER_RECT
.Height
*y
) then Exit
;
6714 function OnGround(): Boolean;
6716 Result
:= StayOnStep(0, 0) or CollideLevel(0, 1);
6719 function OnLadder(): Boolean;
6721 Result
:= FullInStep(0, 0);
6724 function BelowLadder(): Boolean;
6726 Result
:= (FullInStep(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) and
6727 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
6728 (FullInStep(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) and
6729 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
6732 function BelowLiftUp(): Boolean;
6734 Result
:= ((FullInLift(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) = -1) and
6735 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
6736 ((FullInLift(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) = -1) and
6737 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
6740 function OnTopLift(): Boolean;
6742 Result
:= (FullInLift(0, 0) = -1) and (FullInLift(0, -32) = 0);
6745 function CanJumpOver(): Boolean;
6749 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
6753 if not CollideLevel(sx
, 0) then Exit
;
6755 for y
:= 1 to BOT_MAXJUMP
do
6756 if CollideLevel(0, -y
) then Exit
else
6757 if not CollideLevel(sx
, -y
) then
6764 function CanJumpUp(Dist
: ShortInt): Boolean;
6771 if CollideLevel(Dist
, 0) then Exit
;
6774 for y
:= 0 to BOT_MAXJUMP
do
6775 if CollideLevel(Dist
, -y
) then
6784 for yy
:= y
+1 to BOT_MAXJUMP
do
6785 if not CollideLevel(Dist
, -yy
) then
6794 for y
:= 0 to BOT_MAXJUMP
do
6795 if CollideLevel(0, -y
) then
6803 if y
< yy
then Exit
;
6808 function IsSafeTrigger(): Boolean;
6813 if gTriggers
= nil then
6815 for a
:= 0 to High(gTriggers
) do
6816 if Collide(gTriggers
[a
].X
,
6819 gTriggers
[a
].Height
) and
6820 (gTriggers
[a
].TriggerType
in [TRIGGER_EXIT
, TRIGGER_CLOSEDOOR
,
6821 TRIGGER_CLOSETRAP
, TRIGGER_TRAP
,
6822 TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
,
6823 TRIGGER_ONOFF
, TRIGGER_SPAWNMONSTER
,
6824 TRIGGER_DAMAGE
, TRIGGER_SHOT
]) then
6829 // Возможно, нажимаем кнопку:
6830 if Rnd(16) and IsSafeTrigger() then
6833 // Если под лифтом или ступеньками, то, возможно, прыгаем:
6834 if OnLadder() or ((BelowLadder() or BelowLiftUp()) and Rnd(8)) then
6836 ReleaseKey(KEY_LEFT
);
6837 ReleaseKey(KEY_RIGHT
);
6841 // Идем влево, если надо было:
6842 if GetAIFlag('GOLEFT') <> '' then
6844 RemoveAIFlag('GOLEFT');
6845 if CanRunLeft() then
6849 // Идем вправо, если надо было:
6850 if GetAIFlag('GORIGHT') <> '' then
6852 RemoveAIFlag('GORIGHT');
6853 if CanRunRight() then
6857 // Если вылетели за карту, то пробуем вернуться:
6858 if FObj
.X
< -32 then
6861 if FObj
.X
+32 > gMapInfo
.Width
then
6864 // Прыгаем, если надо было:
6865 if GetAIFlag('NEEDJUMP') <> '' then
6868 RemoveAIFlag('NEEDJUMP');
6871 // Смотрим вверх, если надо было:
6872 if GetAIFlag('NEEDSEEUP') <> '' then
6875 ReleaseKey(KEY_DOWN
);
6876 PressKey(KEY_UP
, 20);
6877 RemoveAIFlag('NEEDSEEUP');
6880 // Смотрим вниз, если надо было:
6881 if GetAIFlag('NEEDSEEDOWN') <> '' then
6884 ReleaseKey(KEY_DOWN
);
6885 PressKey(KEY_DOWN
, 20);
6886 RemoveAIFlag('NEEDSEEDOWN');
6889 // Если нужно было в дыру и мы не на земле, то покорно летим:
6890 if GetAIFlag('GOINHOLE') <> '' then
6891 if not OnGround() then
6893 ReleaseKey(KEY_LEFT
);
6894 ReleaseKey(KEY_RIGHT
);
6895 RemoveAIFlag('GOINHOLE');
6896 SetAIFlag('FALLINHOLE', '1');
6899 // Если падали и достигли земли, то хватит падать:
6900 if GetAIFlag('FALLINHOLE') <> '' then
6902 RemoveAIFlag('FALLINHOLE');
6904 // Если летели прямо и сейчас не на лестнице или на вершине лифта, то отходим в сторону:
6905 if not (KeyPressed(KEY_LEFT
) or KeyPressed(KEY_RIGHT
)) then
6906 if GetAIFlag('FALLINHOLE') = '' then
6907 if (not OnLadder()) or (FObj
.Vel
.Y
>= 0) or (OnTopLift()) then
6913 // Если на земле и можно подпрыгнуть, то, возможно, прыгаем:
6915 CanJumpUp(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*32) and
6919 // Если на земле и возле дыры (глубина > 2 ростов игрока):
6920 if OnGround() and NearHole() then
6921 if NearDeepHole() then // Если это бездна
6923 0..3: Turn(); // Бежим обратно
6924 4: Jump(); // Прыгаем
6925 5: begin // Прыгаем обратно
6930 else // Это не бездна и мы еще не летим туда
6931 if GetAIFlag('GOINHOLE') = '' then
6933 0: Turn(); // Не нужно туда
6934 1: Jump(); // Вдруг повезет - прыгаем
6935 else // Если яма с границей, то при случае можно туда прыгнуть
6936 if BorderHole() then
6937 SetAIFlag('GOINHOLE', '1');
6940 // Если на земле, но некуда идти:
6941 if (not CanRun()) and OnGround() then
6943 // Если мы на лестнице или можно перепрыгнуть, то прыгаем:
6944 if CanJumpOver() or OnLadder() then
6946 else // иначе попытаемся в другую сторону
6947 if Random(2) = 0 then
6949 if IsSafeTrigger() then
6955 // Осталось мало воздуха:
6956 if FAir
< 36 * 2 then
6959 // Выбираемся из кислоты, если нет костюма, обожглись, или мало здоровья:
6960 if (FMegaRulez
[MR_SUIT
] < gTime
) and ((FLastHit
= HIT_ACID
) or (Healthy() <= 1)) then
6961 if BodyInAcid(0, 0) then
6965 function TBot
.FullInStep(XInc
, YInc
: Integer): Boolean;
6967 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
6968 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_STEP
, False);
6971 {function TBot.NeedItem(Item: Byte): Byte;
6976 procedure TBot
.SelectWeapon(Dist
: Integer);
6980 function HaveAmmo(weapon
: Byte): Boolean;
6983 WEAPON_PISTOL
: Result
:= FAmmo
[A_BULLETS
] >= 1;
6984 WEAPON_SHOTGUN1
: Result
:= FAmmo
[A_SHELLS
] >= 1;
6985 WEAPON_SHOTGUN2
: Result
:= FAmmo
[A_SHELLS
] >= 2;
6986 WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
] >= 10;
6987 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
] >= 1;
6988 WEAPON_PLASMA
: Result
:= FAmmo
[A_CELLS
] >= 10;
6989 WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
] >= 40;
6990 WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
] >= 1;
6991 WEAPON_FLAMETHROWER
: Result
:= FAmmo
[A_FUEL
] >= 1;
6992 else Result
:= True;
6997 if Dist
= -1 then Dist
:= BOT_LONGDIST
;
6999 if Dist
> BOT_LONGDIST
then
7000 begin // Дальний бой
7002 if FWeapon
[FDifficult
.WeaponPrior
[a
]] and HaveAmmo(FDifficult
.WeaponPrior
[a
]) then
7004 FSelectedWeapon
:= FDifficult
.WeaponPrior
[a
];
7008 else //if Dist > BOT_UNSAFEDIST then
7009 begin // Ближний бой
7011 if FWeapon
[FDifficult
.CloseWeaponPrior
[a
]] and HaveAmmo(FDifficult
.CloseWeaponPrior
[a
]) then
7013 FSelectedWeapon
:= FDifficult
.CloseWeaponPrior
[a
];
7020 if FWeapon[FDifficult.SafeWeaponPrior[a]] and HaveAmmo(FDifficult.SafeWeaponPrior[a]) then
7022 FSelectedWeapon := FDifficult.SafeWeaponPrior[a];
7028 function TBot
.PickItem(ItemType
: Byte; force
: Boolean; var remove
: Boolean): Boolean;
7030 Result
:= inherited PickItem(ItemType
, force
, remove
);
7032 if Result
then SetAIFlag('SELECTWEAPON', '1');
7035 function TBot
.Heal(value
: Word; Soft
: Boolean): Boolean;
7037 Result
:= inherited Heal(value
, Soft
);
7040 function TBot
.Healthy(): Byte;
7042 if FMegaRulez
[MR_INVUL
] >= gTime
then Result
:= 3
7043 else if (FHealth
> 80) or ((FHealth
> 50) and (FArmor
> 20)) then Result
:= 3
7044 else if (FHealth
> 50) then Result
:= 2
7045 else if (FHealth
> 20) then Result
:= 1
7049 function TBot
.TargetOnScreen(TX
, TY
: Integer): Boolean;
7051 Result
:= (Abs(FObj
.X
-TX
) <= Trunc(gPlayerScreenSize
.X
*0.6)) and
7052 (Abs(FObj
.Y
-TY
) <= Trunc(gPlayerScreenSize
.Y
*0.6));
7055 procedure TBot
.OnDamage(Angle
: SmallInt);
7063 if (Angle
= 0) or (Angle
= 180) then
7066 if (g_GetUIDType(FLastSpawnerUID
) = UID_PLAYER
) and
7067 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
) then
7069 pla
:= g_Player_Get(FLastSpawnerUID
);
7070 ok
:= not TargetOnScreen(pla
.FObj
.X
+ PLAYER_RECT
.X
,
7071 pla
.FObj
.Y
+ PLAYER_RECT
.Y
);
7074 if (g_GetUIDType(FLastSpawnerUID
) = UID_MONSTER
) and
7075 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
) then
7077 mon
:= g_Monsters_ByUID(FLastSpawnerUID
);
7078 ok
:= not TargetOnScreen(mon
.Obj
.X
+ mon
.Obj
.Rect
.X
,
7079 mon
.Obj
.Y
+ mon
.Obj
.Rect
.Y
);
7084 SetAIFlag('ATTACKLEFT', '1')
7086 SetAIFlag('ATTACKRIGHT', '1');
7090 function TBot
.RunDirection(): TDirection
;
7092 if Abs(Vel
.X
) >= 1 then
7094 if Vel
.X
> 0 then Result
:= TDirection
.D_RIGHT
else Result
:= TDirection
.D_LEFT
;
7096 Result
:= FDirection
;
7099 function TBot
.GetRnd(a
: Byte): Boolean;
7101 if a
= 0 then Result
:= False
7102 else if a
= 255 then Result
:= True
7103 else Result
:= Random(256) > 255-a
;
7106 function TBot
.GetInterval(a
: Byte; radius
: SmallInt): SmallInt;
7108 Result
:= Round((255-a
)/255*radius
*(Random(2)-1));
7112 procedure TDifficult
.save (st
: TStream
);
7114 utils
.writeInt(st
, Byte(DiagFire
));
7115 utils
.writeInt(st
, Byte(InvisFire
));
7116 utils
.writeInt(st
, Byte(DiagPrecision
));
7117 utils
.writeInt(st
, Byte(FlyPrecision
));
7118 utils
.writeInt(st
, Byte(Cover
));
7119 utils
.writeInt(st
, Byte(CloseJump
));
7120 st
.WriteBuffer(WeaponPrior
[Low(WeaponPrior
)], sizeof(WeaponPrior
));
7121 st
.WriteBuffer(CloseWeaponPrior
[Low(CloseWeaponPrior
)], sizeof(CloseWeaponPrior
));
7124 procedure TDifficult
.load (st
: TStream
);
7126 DiagFire
:= utils
.readByte(st
);
7127 InvisFire
:= utils
.readByte(st
);
7128 DiagPrecision
:= utils
.readByte(st
);
7129 FlyPrecision
:= utils
.readByte(st
);
7130 Cover
:= utils
.readByte(st
);
7131 CloseJump
:= utils
.readByte(st
);
7132 st
.ReadBuffer(WeaponPrior
[Low(WeaponPrior
)], sizeof(WeaponPrior
));
7133 st
.ReadBuffer(CloseWeaponPrior
[Low(CloseWeaponPrior
)], sizeof(CloseWeaponPrior
));
7137 procedure TBot
.SaveState (st
: TStream
);
7142 inherited SaveState(st
);
7143 utils
.writeSign(st
, 'BOT0');
7145 utils
.writeInt(st
, Byte(FSelectedWeapon
));
7147 utils
.writeInt(st
, Word(FTargetUID
));
7148 // Время потери цели
7149 utils
.writeInt(st
, LongWord(FLastVisible
));
7150 // Количество флагов ИИ
7151 dw
:= Length(FAIFlags
);
7152 utils
.writeInt(st
, LongInt(dw
));
7154 for i
:= 0 to dw
-1 do
7156 utils
.writeStr(st
, FAIFlags
[i
].Name
, 20);
7157 utils
.writeStr(st
, FAIFlags
[i
].Value
, 20);
7159 // Настройки сложности
7160 FDifficult
.save(st
);
7164 procedure TBot
.LoadState (st
: TStream
);
7169 inherited LoadState(st
);
7170 if not utils
.checkSign(st
, 'BOT0') then raise XStreamError
.Create('invalid bot signature');
7172 FSelectedWeapon
:= utils
.readByte(st
);
7174 FTargetUID
:= utils
.readWord(st
);
7175 // Время потери цели
7176 FLastVisible
:= utils
.readLongWord(st
);
7177 // Количество флагов ИИ
7178 dw
:= utils
.readLongInt(st
);
7179 if (dw
< 0) or (dw
> 16384) then raise XStreamError
.Create('invalid number of bot AI flags');
7180 SetLength(FAIFlags
, dw
);
7182 for i
:= 0 to dw
-1 do
7184 FAIFlags
[i
].Name
:= utils
.readStr(st
, 20);
7185 FAIFlags
[i
].Value
:= utils
.readStr(st
, 20);
7187 // Настройки сложности
7188 FDifficult
.load(st
);
7193 conRegVar('cheat_berserk_autoswitch', @gBerserkAutoswitch
, 'autoswitch to fist when berserk pack taken', '', true, true);
7194 conRegVar('player_indicator', @gPlayerIndicator
, 'Draw indicator only for current player, also for teammates, or not at all', 'Draw indicator only for current player, also for teammates, or not at all');
7195 conRegVar('player_indicator_style', @gPlayerIndicatorStyle
, 'Visual appearance of indicator', 'Visual appearance of indicator');