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
,
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
: TAnimation
;
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
: TAnimation 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;
513 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
514 procedure moveBy (dx
, dy
: Integer); inline;
516 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
530 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
531 procedure moveBy (dx
, dy
: Integer); inline;
533 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
536 TCorpse
= class{$IFDEF USE_MEMPOOL}(TPoolObject
){$ENDIF}
545 FAnimation
: TAnimation
;
546 FAnimationMask
: TAnimation
;
549 constructor Create(X
, Y
: Integer; ModelName
: String; aMess
: Boolean);
550 destructor Destroy(); override;
551 procedure Damage(Value
: Word; SpawnerUID
: Word; vx
, vy
: Integer);
553 procedure SaveState (st
: TStream
);
554 procedure LoadState (st
: TStream
);
556 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
557 procedure moveBy (dx
, dy
: Integer); inline;
559 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
561 function ObjPtr (): PObj
; inline;
563 property Obj
: TObj read FObj
; // copies object
564 property State
: Byte read FState
;
565 property Mess
: Boolean read FMess
;
568 property Color
: TRGB read FColor
;
569 property Animation
: TAnimation read FAnimation
;
570 property AnimationMask
: TAnimation read FAnimationMask
;
573 TTeamStat
= Array [TEAM_RED
..TEAM_BLUE
] of
579 gPlayers
: Array of TPlayer
;
580 gCorpses
: Array of TCorpse
;
581 gGibs
: Array of TGib
;
582 gShells
: Array of TShell
;
583 gTeamStat
: TTeamStat
;
584 gFly
: Boolean = False;
585 gAimLine
: Boolean = False;
586 gChatBubble
: Integer = 0;
587 gPlayerIndicator
: Integer = 1;
588 gPlayerIndicatorStyle
: Integer = 0;
590 gSpectLatchPID1
: Word = 0;
591 gSpectLatchPID2
: Word = 0;
592 MAX_RUNVEL
: Integer = 8;
593 VEL_JUMP
: Integer = 10;
594 SHELL_TIMEOUT
: Cardinal = 60000;
596 function Lerp(X
, Y
, Factor
: Integer): Integer;
598 procedure g_Gibs_SetMax(Count
: Word);
599 function g_Gibs_GetMax(): Word;
600 procedure g_Corpses_SetMax(Count
: Word);
601 function g_Corpses_GetMax(): Word;
602 procedure g_Shells_SetMax(Count
: Word);
603 function g_Shells_GetMax(): Word;
605 procedure g_Player_Init();
606 procedure g_Player_Free();
607 function g_Player_Create(ModelName
: String; Color
: TRGB
; Team
: Byte; Bot
: Boolean): Word;
608 function g_Player_CreateFromState (st
: TStream
): Word;
609 procedure g_Player_Remove(UID
: Word);
610 procedure g_Player_ResetTeams();
611 procedure g_Player_PreUpdate();
612 procedure g_Player_UpdateAll();
613 procedure g_Player_RememberAll();
614 procedure g_Player_ResetAll(Force
, Silent
: Boolean);
615 function g_Player_Get(UID
: Word): TPlayer
;
616 function g_Player_GetCount(): Byte;
617 function g_Player_GetStats(): TPlayerStatArray
;
618 function g_Player_ValidName(Name
: String): Boolean;
619 function g_Player_CreateCorpse(Player
: TPlayer
): Integer;
620 procedure g_Player_CreateGibs(fX
, fY
: Integer; ModelName
: String; fColor
: TRGB
);
621 procedure g_Player_CreateShell(fX
, fY
, dX
, dY
: Integer; T
: Byte);
622 procedure g_Player_UpdatePhysicalObjects();
623 procedure g_Player_RemoveAllCorpses();
624 procedure g_Player_Corpses_SaveState (st
: TStream
);
625 procedure g_Player_Corpses_LoadState (st
: TStream
);
626 procedure g_Player_ResetReady();
627 procedure g_Bot_Add(Team
, Difficult
: Byte; Handicap
: Integer = 100);
628 procedure g_Bot_AddList(Team
: Byte; lname
: ShortString; num
: Integer = -1; Handicap
: Integer = 100);
629 procedure g_Bot_MixNames();
630 procedure g_Bot_RemoveAll();
635 {$IFDEF ENABLE_HOLMES}
638 e_log
, g_map
, g_items
, g_console
, g_gfx
, Math
,
639 g_options
, g_triggers
, g_menu
, g_game
, g_grid
, e_res
,
640 wadreader
, g_monsters
, CONFIG
, g_language
,
644 const PLR_SAVE_VERSION
= 0;
654 diag_precision
: Byte;
658 w_prior1
: Array [WP_FIRST
..WP_LAST
] of Byte;
659 w_prior2
: Array [WP_FIRST
..WP_LAST
] of Byte;
660 w_prior3
: Array [WP_FIRST
..WP_LAST
] of Byte;
664 TIME_RESPAWN1
= 1500;
665 TIME_RESPAWN2
= 2000;
666 TIME_RESPAWN3
= 3000;
667 PLAYER_SUIT_TIME
= 30000;
668 PLAYER_INVUL_TIME
= 30000;
669 PLAYER_INVIS_TIME
= 35000;
670 FRAG_COMBO_TIME
= 3000;
673 PLAYER_HEADRECT
: TRectWH
= (X
:24; Y
:12; Width
:20; Height
:12);
676 BOT_UNSAFEDIST
= 128;
677 DIFFICULT_EASY
: TDifficult
= (DiagFire
: 32; InvisFire
: 32; DiagPrecision
: 32;
678 FlyPrecision
: 32; Cover
: 32; CloseJump
: 32;
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 DIFFICULT_MEDIUM
: TDifficult
= (DiagFire
: 127; InvisFire
: 127; DiagPrecision
: 127;
681 FlyPrecision
: 127; Cover
: 127; CloseJump
: 127;
682 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
683 DIFFICULT_HARD
: TDifficult
= (DiagFire
: 255; InvisFire
: 255; DiagPrecision
: 255;
684 FlyPrecision
: 255; Cover
: 255; CloseJump
: 255;
685 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
686 WEAPON_PRIOR1
: Array [WP_FIRST
..WP_LAST
] of Byte =
687 (WEAPON_FLAMETHROWER
, WEAPON_SUPERPULEMET
,
688 WEAPON_SHOTGUN2
, WEAPON_SHOTGUN1
,
689 WEAPON_CHAINGUN
, WEAPON_PLASMA
, WEAPON_ROCKETLAUNCHER
,
690 WEAPON_BFG
, WEAPON_PISTOL
, WEAPON_SAW
, WEAPON_KASTET
);
691 WEAPON_PRIOR2
: Array [WP_FIRST
..WP_LAST
] of Byte =
692 (WEAPON_FLAMETHROWER
, WEAPON_SUPERPULEMET
,
693 WEAPON_BFG
, WEAPON_ROCKETLAUNCHER
,
694 WEAPON_SHOTGUN2
, WEAPON_PLASMA
, WEAPON_SHOTGUN1
,
695 WEAPON_CHAINGUN
, WEAPON_PISTOL
, WEAPON_SAW
, WEAPON_KASTET
);
696 //WEAPON_PRIOR3: Array [WP_FIRST..WP_LAST] of Byte =
697 // (WEAPON_FLAMETHROWER, WEAPON_SUPERPULEMET,
698 // WEAPON_BFG, WEAPON_PLASMA, WEAPON_SHOTGUN2,
699 // WEAPON_CHAINGUN, WEAPON_SHOTGUN1, WEAPON_SAW,
700 // WEAPON_ROCKETLAUNCHER, WEAPON_PISTOL, WEAPON_KASTET);
701 WEAPON_RELOAD
: Array [WP_FIRST
..WP_LAST
] of Byte =
702 (5, 2, 6, 18, 36, 2, 12, 2, 14, 2, 2);
704 PLAYER_SIGNATURE
= $52594C50; // 'PLYR'
705 CORPSE_SIGNATURE
= $50524F43; // 'CORP'
707 BOTNAMES_FILENAME
= 'botnames.txt';
708 BOTLIST_FILENAME
= 'botlist.txt';
712 MaxCorpses
: Word = 20;
713 MaxShells
: Word = 300;
714 CurrentGib
: Integer = 0;
715 CurrentShell
: Integer = 0;
716 BotNames
: Array of String;
717 BotList
: Array of TBotProfile
;
718 SavedStates
: Array of TPlayerSavedState
;
721 function Lerp(X
, Y
, Factor
: Integer): Integer;
723 Result
:= X
+ ((Y
- X
) div Factor
);
726 function SameTeam(UID1
, UID2
: Word): Boolean;
730 if (UID1
> UID_MAX_PLAYER
) or (UID1
<= UID_MAX_GAME
) or
731 (UID2
> UID_MAX_PLAYER
) or (UID2
<= UID_MAX_GAME
) then Exit
;
733 if (g_Player_Get(UID1
) = nil) or (g_Player_Get(UID2
) = nil) then Exit
;
735 if ((g_Player_Get(UID1
).Team
= TEAM_NONE
) or
736 (g_Player_Get(UID2
).Team
= TEAM_NONE
)) then Exit
;
738 Result
:= g_Player_Get(UID1
).FTeam
= g_Player_Get(UID2
).FTeam
;
741 procedure g_Gibs_SetMax(Count
: Word);
744 SetLength(gGibs
, Count
);
746 if CurrentGib
>= Count
then
750 function g_Gibs_GetMax(): Word;
755 procedure g_Shells_SetMax(Count
: Word);
758 SetLength(gShells
, Count
);
760 if CurrentShell
>= Count
then
764 function g_Shells_GetMax(): Word;
770 procedure g_Corpses_SetMax(Count
: Word);
773 SetLength(gCorpses
, Count
);
776 function g_Corpses_GetMax(): Word;
778 Result
:= MaxCorpses
;
781 function g_Player_Create(ModelName
: String; Color
: TRGB
; Team
: Byte; Bot
: Boolean): Word;
791 // Есть ли место в gPlayers:
792 if gPlayers
<> nil then
793 for a
:= 0 to High(gPlayers
) do
794 if gPlayers
[a
] = nil then
800 // Нет места - расширяем gPlayers:
803 SetLength(gPlayers
, Length(gPlayers
)+1);
807 // Создаем объект игрока:
809 gPlayers
[a
] := TBot
.Create()
811 gPlayers
[a
] := TPlayer
.Create();
814 gPlayers
[a
].FActualModelName
:= ModelName
;
815 gPlayers
[a
].SetModel(ModelName
);
817 // Нет модели - создание не возможно:
818 if gPlayers
[a
].FModel
= nil then
822 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], [ModelName
]));
826 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
827 if Random(2) = 0 then
831 gPlayers
[a
].FPreferredTeam
:= Team
;
833 case gGameSettings
.GameMode
of
834 GM_DM
: gPlayers
[a
].FTeam
:= TEAM_NONE
;
836 GM_CTF
: gPlayers
[a
].FTeam
:= gPlayers
[a
].FPreferredTeam
;
838 GM_COOP
: gPlayers
[a
].FTeam
:= TEAM_COOP
;
841 // Если командная игра - красим модель в цвет команды:
842 gPlayers
[a
].FColor
:= Color
;
843 if gPlayers
[a
].FTeam
in [TEAM_RED
, TEAM_BLUE
] then
844 gPlayers
[a
].FModel
.Color
:= TEAMCOLOR
[gPlayers
[a
].FTeam
]
846 gPlayers
[a
].FModel
.Color
:= Color
;
848 gPlayers
[a
].FUID
:= g_CreateUID(UID_PLAYER
);
849 gPlayers
[a
].FAlive
:= False;
851 Result
:= gPlayers
[a
].FUID
;
854 function g_Player_CreateFromState (st
: TStream
): Word;
861 if (st
= nil) then exit
; //???
864 if not utils
.checkSign(st
, 'PLYR') then raise XStreamError
.Create('invalid player signature');
865 if (utils
.readByte(st
) <> PLR_SAVE_VERSION
) then raise XStreamError
.Create('invalid player version');
868 Bot
:= utils
.readBool(st
);
873 // Есть ли место в gPlayers:
874 for a
:= 0 to High(gPlayers
) do if (gPlayers
[a
] = nil) then begin ok
:= true; break
; end;
876 // Нет места - расширяем gPlayers
879 SetLength(gPlayers
, Length(gPlayers
)+1);
883 // Создаем объект игрока
885 gPlayers
[a
] := TBot
.Create()
887 gPlayers
[a
] := TPlayer
.Create();
888 gPlayers
[a
].FIamBot
:= Bot
;
889 gPlayers
[a
].FPhysics
:= True;
892 gPlayers
[a
].FUID
:= utils
.readWord(st
);
894 gPlayers
[a
].FName
:= utils
.readStr(st
);
896 gPlayers
[a
].FTeam
:= utils
.readByte(st
);
897 gPlayers
[a
].FPreferredTeam
:= gPlayers
[a
].FTeam
;
899 gPlayers
[a
].FAlive
:= utils
.readBool(st
);
900 // Израсходовал ли все жизни
901 gPlayers
[a
].FNoRespawn
:= utils
.readBool(st
);
903 b
:= utils
.readByte(st
);
904 if b
= 1 then gPlayers
[a
].FDirection
:= TDirection
.D_LEFT
else gPlayers
[a
].FDirection
:= TDirection
.D_RIGHT
; // b = 2
906 gPlayers
[a
].FHealth
:= utils
.readLongInt(st
);
908 gPlayers
[a
].FHandicap
:= utils
.readLongInt(st
);
910 gPlayers
[a
].FLives
:= utils
.readByte(st
);
912 gPlayers
[a
].FArmor
:= utils
.readLongInt(st
);
914 gPlayers
[a
].FAir
:= utils
.readLongInt(st
);
916 gPlayers
[a
].FJetFuel
:= utils
.readLongInt(st
);
918 gPlayers
[a
].FPain
:= utils
.readLongInt(st
);
920 gPlayers
[a
].FKills
:= utils
.readLongInt(st
);
922 gPlayers
[a
].FMonsterKills
:= utils
.readLongInt(st
);
924 gPlayers
[a
].FFrags
:= utils
.readLongInt(st
);
926 gPlayers
[a
].FFragCombo
:= utils
.readByte(st
);
927 // Время последнего фрага
928 gPlayers
[a
].FLastFrag
:= utils
.readLongWord(st
);
930 gPlayers
[a
].FDeath
:= utils
.readLongInt(st
);
932 gPlayers
[a
].FFlag
:= utils
.readByte(st
);
934 gPlayers
[a
].FSecrets
:= utils
.readLongInt(st
);
936 gPlayers
[a
].FCurrWeap
:= utils
.readByte(st
);
937 // Следующее желаемое оружие
938 gPlayers
[a
].FNextWeap
:= utils
.readWord(st
);
940 gPlayers
[a
].FNextWeapDelay
:= utils
.readByte(st
);
942 gPlayers
[a
].FBFGFireCounter
:= utils
.readSmallInt(st
);
944 gPlayers
[a
].FDamageBuffer
:= utils
.readLongInt(st
);
945 // Последний ударивший
946 gPlayers
[a
].FLastSpawnerUID
:= utils
.readWord(st
);
947 // Тип последнего полученного урона
948 gPlayers
[a
].FLastHit
:= utils
.readByte(st
);
950 Obj_LoadState(@gPlayers
[a
].FObj
, st
);
951 // Текущее количество патронов
952 for i
:= A_BULLETS
to A_HIGH
do gPlayers
[a
].FAmmo
[i
] := utils
.readWord(st
);
953 // Максимальное количество патронов
954 for i
:= A_BULLETS
to A_HIGH
do gPlayers
[a
].FMaxAmmo
[i
] := utils
.readWord(st
);
956 for i
:= WP_FIRST
to WP_LAST
do gPlayers
[a
].FWeapon
[i
] := utils
.readBool(st
);
957 // Время перезарядки оружия
958 for i
:= WP_FIRST
to WP_LAST
do gPlayers
[a
].FReloading
[i
] := utils
.readWord(st
);
960 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_ITEM_BACKPACK
);
961 // Наличие красного ключа
962 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_KEY_RED
);
963 // Наличие зеленого ключа
964 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_KEY_GREEN
);
965 // Наличие синего ключа
966 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_KEY_BLUE
);
968 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_BERSERK
);
969 // Время действия специальных предметов
970 for i
:= MR_SUIT
to MR_MAX
do gPlayers
[a
].FMegaRulez
[i
] := utils
.readLongWord(st
);
971 // Время до повторного респауна, смены оружия, исользования, захвата флага
972 for i
:= T_RESPAWN
to T_FLAGCAP
do gPlayers
[a
].FTime
[i
] := utils
.readLongWord(st
);
975 gPlayers
[a
].FActualModelName
:= utils
.readStr(st
);
977 gPlayers
[a
].FColor
.R
:= utils
.readByte(st
);
978 gPlayers
[a
].FColor
.G
:= utils
.readByte(st
);
979 gPlayers
[a
].FColor
.B
:= utils
.readByte(st
);
980 // Обновляем модель игрока
981 gPlayers
[a
].SetModel(gPlayers
[a
].FActualModelName
);
983 // Нет модели - создание невозможно
984 if (gPlayers
[a
].FModel
= nil) then
988 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], [gPlayers
[a
].FActualModelName
]));
992 // Если командная игра - красим модель в цвет команды
993 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
994 gPlayers
[a
].FModel
.Color
:= TEAMCOLOR
[gPlayers
[a
].FTeam
]
996 gPlayers
[a
].FModel
.Color
:= gPlayers
[a
].FColor
;
998 result
:= gPlayers
[a
].FUID
;
1002 procedure g_Player_ResetTeams();
1006 if g_Game_IsClient
then
1008 if gPlayers
= nil then
1010 for a
:= Low(gPlayers
) to High(gPlayers
) do
1011 if gPlayers
[a
] <> nil then
1012 case gGameSettings
.GameMode
of
1014 gPlayers
[a
].ChangeTeam(TEAM_NONE
);
1016 if not (gPlayers
[a
].Team
in [TEAM_RED
, TEAM_BLUE
]) then
1017 if gPlayers
[a
].FPreferredTeam
in [TEAM_RED
, TEAM_BLUE
] then
1018 gPlayers
[a
].ChangeTeam(gPlayers
[a
].FPreferredTeam
)
1021 gPlayers
[a
].ChangeTeam(TEAM_RED
)
1023 gPlayers
[a
].ChangeTeam(TEAM_BLUE
);
1026 gPlayers
[a
].ChangeTeam(TEAM_COOP
);
1030 procedure g_Bot_Add(Team
, Difficult
: Byte; Handicap
: Integer = 100);
1033 _name
, _model
: String;
1036 if not g_Game_IsServer
then Exit
;
1038 // Список названий моделей:
1039 m
:= g_PlayerModel_GetNames();
1044 if (gGameSettings
.GameType
= GT_SINGLE
) or (gGameSettings
.GameMode
= GM_COOP
) then
1045 Team
:= TEAM_COOP
// COOP
1047 if gGameSettings
.GameMode
= GM_DM
then
1048 Team
:= TEAM_NONE
// DM
1050 if Team
= TEAM_NONE
then // CTF / TDM
1052 // Автобаланс команд:
1056 for a
:= 0 to High(gPlayers
) do
1057 if gPlayers
[a
] <> nil then
1059 if gPlayers
[a
].Team
= TEAM_RED
then
1062 if gPlayers
[a
].Team
= TEAM_BLUE
then
1072 if Random(2) = 0 then
1078 // Выбираем боту имя:
1080 if BotNames
<> nil then
1081 for a
:= 0 to High(BotNames
) do
1082 if g_Player_ValidName(BotNames
[a
]) then
1084 _name
:= BotNames
[a
];
1088 // Выбираем случайную модель:
1089 _model
:= m
[Random(Length(m
))];
1092 with g_Player_Get(g_Player_Create(_model
,
1093 _RGB(Min(Random(9)*32, 255),
1094 Min(Random(9)*32, 255),
1095 Min(Random(9)*32, 255)),
1096 Team
, True)) as TBot
do
1098 // Если имени нет, делаем его из UID бота
1100 Name
:= Format('DFBOT%.5d', [UID
])
1105 1: FDifficult
:= DIFFICULT_EASY
;
1106 2: FDifficult
:= DIFFICULT_MEDIUM
;
1107 else FDifficult
:= DIFFICULT_HARD
;
1110 for a
:= WP_FIRST
to WP_LAST
do
1112 FDifficult
.WeaponPrior
[a
] := WEAPON_PRIOR1
[a
];
1113 FDifficult
.CloseWeaponPrior
[a
] := WEAPON_PRIOR2
[a
];
1114 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
1117 FHandicap
:= Handicap
;
1119 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [Name
]), True);
1121 if g_Game_IsNet
then MH_SEND_PlayerCreate(UID
);
1122 if g_Game_IsServer
and (gGameSettings
.MaxLives
> 0) then
1127 procedure g_Bot_AddList(Team
: Byte; lName
: ShortString; num
: Integer = -1; Handicap
: Integer = 100);
1130 _name
, _model
: String;
1133 if not g_Game_IsServer
then Exit
;
1135 // Список названий моделей:
1136 m
:= g_PlayerModel_GetNames();
1141 if (gGameSettings
.GameType
= GT_SINGLE
) or (gGameSettings
.GameMode
= GM_COOP
) then
1142 Team
:= TEAM_COOP
// COOP
1144 if gGameSettings
.GameMode
= GM_DM
then
1145 Team
:= TEAM_NONE
// DM
1147 if Team
= TEAM_NONE
then
1148 Team
:= BotList
[num
].team
; // CTF / TDM
1150 // Выбираем настройки бота из списка по номеру или имени:
1151 lName
:= AnsiLowerCase(lName
);
1152 if (num
< 0) or (num
> Length(BotList
)-1) then
1154 if (num
= -1) and (lName
<> '') and (BotList
<> nil) then
1155 for a
:= 0 to High(BotList
) do
1156 if AnsiLowerCase(BotList
[a
].name
) = lName
then
1165 _name
:= BotList
[num
].name
;
1166 // Занято - выбираем случайное:
1167 if not g_Player_ValidName(_name
) then
1169 _name
:= Format('DFBOT%.2d', [Random(100)]);
1170 until g_Player_ValidName(_name
);
1173 _model
:= BotList
[num
].model
;
1174 // Нет такой - выбираем случайную:
1175 if not InSArray(_model
, m
) then
1176 _model
:= m
[Random(Length(m
))];
1179 with g_Player_Get(g_Player_Create(_model
, BotList
[num
].color
, Team
, True)) as TBot
do
1183 FDifficult
.DiagFire
:= BotList
[num
].diag_fire
;
1184 FDifficult
.InvisFire
:= BotList
[num
].invis_fire
;
1185 FDifficult
.DiagPrecision
:= BotList
[num
].diag_precision
;
1186 FDifficult
.FlyPrecision
:= BotList
[num
].fly_precision
;
1187 FDifficult
.Cover
:= BotList
[num
].cover
;
1188 FDifficult
.CloseJump
:= BotList
[num
].close_jump
;
1190 FHandicap
:= Handicap
;
1192 for a
:= WP_FIRST
to WP_LAST
do
1194 FDifficult
.WeaponPrior
[a
] := BotList
[num
].w_prior1
[a
];
1195 FDifficult
.CloseWeaponPrior
[a
] := BotList
[num
].w_prior2
[a
];
1196 //FDifficult.SafeWeaponPrior[a] := BotList[num].w_prior3[a];
1199 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [Name
]), True);
1201 if g_Game_IsNet
then MH_SEND_PlayerCreate(UID
);
1205 procedure g_Bot_RemoveAll();
1209 if not g_Game_IsServer
then Exit
;
1210 if gPlayers
= nil then Exit
;
1212 for a
:= 0 to High(gPlayers
) do
1213 if gPlayers
[a
] <> nil then
1214 if gPlayers
[a
] is TBot
then
1216 gPlayers
[a
].Lives
:= 0;
1217 gPlayers
[a
].Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
1218 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [gPlayers
[a
].Name
]), True);
1219 g_Player_Remove(gPlayers
[a
].FUID
);
1225 procedure g_Bot_MixNames();
1230 if BotNames
<> nil then
1231 for a
:= 0 to High(BotNames
) do
1233 b
:= Random(Length(BotNames
));
1235 Botnames
[a
] := BotNames
[b
];
1240 procedure g_Player_Remove(UID
: Word);
1244 if gPlayers
= nil then Exit
;
1246 if g_Game_IsServer
and g_Game_IsNet
then
1247 MH_SEND_PlayerDelete(UID
);
1249 for i
:= 0 to High(gPlayers
) do
1250 if gPlayers
[i
] <> nil then
1251 if gPlayers
[i
].FUID
= UID
then
1253 if gPlayers
[i
] is TPlayer
then
1254 TPlayer(gPlayers
[i
]).Free()
1256 TBot(gPlayers
[i
]).Free();
1262 procedure g_Player_Init();
1273 path
:= BOTNAMES_FILENAME
;
1274 if e_FindResource(DataDirs
, path
) = false then
1277 // Читаем возможные имена ботов из файла:
1278 AssignFile(F
, path
);
1289 SetLength(BotNames
, Length(BotNames
)+1);
1290 BotNames
[High(BotNames
)] := s
;
1298 // Читаем файл с параметрами ботов:
1299 config
:= TConfig
.CreateFile(path
);
1303 while config
.SectionExists(IntToStr(a
)) do
1305 SetLength(BotList
, Length(BotList
)+1);
1307 with BotList
[High(BotList
)] do
1310 name
:= config
.ReadStr(IntToStr(a
), 'name', '');
1312 model
:= config
.ReadStr(IntToStr(a
), 'model', '');
1314 if config
.ReadStr(IntToStr(a
), 'team', 'red') = 'red' then
1319 sa
:= parse(config
.ReadStr(IntToStr(a
), 'color', ''));
1320 color
.R
:= StrToIntDef(sa
[0], 0);
1321 color
.G
:= StrToIntDef(sa
[1], 0);
1322 color
.B
:= StrToIntDef(sa
[2], 0);
1323 // Вероятность стрельбы под углом:
1324 diag_fire
:= config
.ReadInt(IntToStr(a
), 'diag_fire', 0);
1325 // Вероятность ответного огня по невидимому сопернику:
1326 invis_fire
:= config
.ReadInt(IntToStr(a
), 'invis_fire', 0);
1327 // Точность стрельбы под углом:
1328 diag_precision
:= config
.ReadInt(IntToStr(a
), 'diag_precision', 0);
1329 // Точность стрельбы в полете:
1330 fly_precision
:= config
.ReadInt(IntToStr(a
), 'fly_precision', 0);
1331 // Точность уклонения от снарядов:
1332 cover
:= config
.ReadInt(IntToStr(a
), 'cover', 0);
1333 // Вероятность прыжка при приближении соперника:
1334 close_jump
:= config
.ReadInt(IntToStr(a
), 'close_jump', 0);
1335 // Приоритеты оружия для дальнего боя:
1336 sa
:= parse(config
.ReadStr(IntToStr(a
), 'w_prior1', ''));
1337 if Length(sa
) = 10 then
1339 w_prior1
[b
] := EnsureRange(StrToInt(sa
[b
]), 0, 9);
1340 // Приоритеты оружия для ближнего боя:
1341 sa
:= parse(config
.ReadStr(IntToStr(a
), 'w_prior2', ''));
1342 if Length(sa
) = 10 then
1344 w_prior2
[b
] := EnsureRange(StrToInt(sa
[b
]), 0, 9);
1346 {sa := parse(config.ReadStr(IntToStr(a), 'w_prior3', ''));
1347 if Length(sa) = 10 then
1349 w_prior3[b] := EnsureRange(StrToInt(sa[b]), 0, 9);}
1356 SetLength(SavedStates
, 0);
1359 procedure g_Player_Free();
1363 if gPlayers
<> nil then
1365 for i
:= 0 to High(gPlayers
) do
1366 if gPlayers
[i
] <> nil then
1368 if gPlayers
[i
] is TPlayer
then
1369 TPlayer(gPlayers
[i
]).Free()
1371 TBot(gPlayers
[i
]).Free();
1380 SetLength(SavedStates
, 0);
1383 procedure g_Player_PreUpdate();
1387 if gPlayers
= nil then Exit
;
1388 for i
:= 0 to High(gPlayers
) do
1389 if gPlayers
[i
] <> nil then
1390 gPlayers
[i
].PreUpdate();
1393 procedure g_Player_UpdateAll();
1397 if gPlayers
= nil then Exit
;
1399 //e_WriteLog('***g_Player_UpdateAll: ENTER', MSG_WARNING);
1400 for i
:= 0 to High(gPlayers
) do
1402 if gPlayers
[i
] <> nil then
1404 if gPlayers
[i
] is TPlayer
then
1406 gPlayers
[i
].Update();
1407 gPlayers
[i
].RealizeCurrentWeapon(); // WARNING! DO NOT MOVE THIS INTO `Update()`!
1411 // bot updates weapons in `UpdateCombat()`
1412 TBot(gPlayers
[i
]).Update();
1416 //e_WriteLog('***g_Player_UpdateAll: EXIT', MSG_WARNING);
1419 function g_Player_Get(UID
: Word): TPlayer
;
1425 if gPlayers
= nil then
1428 for a
:= 0 to High(gPlayers
) do
1429 if gPlayers
[a
] <> nil then
1430 if gPlayers
[a
].FUID
= UID
then
1432 Result
:= gPlayers
[a
];
1437 function g_Player_GetCount(): Byte;
1443 if gPlayers
= nil then
1446 for a
:= 0 to High(gPlayers
) do
1447 if gPlayers
[a
] <> nil then
1448 Result
:= Result
+ 1;
1451 function g_Player_GetStats(): TPlayerStatArray
;
1457 if gPlayers
= nil then Exit
;
1459 for a
:= 0 to High(gPlayers
) do
1460 if gPlayers
[a
] <> nil then
1462 SetLength(Result
, Length(Result
)+1);
1463 with Result
[High(Result
)] do
1466 Ping
:= gPlayers
[a
].FPing
;
1467 Loss
:= gPlayers
[a
].FLoss
;
1468 Name
:= gPlayers
[a
].FName
;
1469 Team
:= gPlayers
[a
].FTeam
;
1470 Frags
:= gPlayers
[a
].FFrags
;
1471 Deaths
:= gPlayers
[a
].FDeath
;
1472 Kills
:= gPlayers
[a
].FKills
;
1473 Color
:= gPlayers
[a
].FModel
.Color
;
1474 Lives
:= gPlayers
[a
].FLives
;
1475 Spectator
:= gPlayers
[a
].FSpectator
;
1476 UID
:= gPlayers
[a
].FUID
;
1481 procedure g_Player_ResetReady();
1485 if not g_Game_IsServer
then Exit
;
1486 if gPlayers
= nil then Exit
;
1488 for a
:= 0 to High(gPlayers
) do
1489 if gPlayers
[a
] <> nil then
1491 gPlayers
[a
].FReady
:= False;
1492 if g_Game_IsNet
then
1493 MH_SEND_GameEvent(NET_EV_INTER_READY
, gPlayers
[a
].UID
, 'N');
1497 procedure g_Player_RememberAll
;
1501 for i
:= Low(gPlayers
) to High(gPlayers
) do
1502 if (gPlayers
[i
] <> nil) and gPlayers
[i
].alive
then
1503 gPlayers
[i
].RememberState
;
1506 procedure g_Player_ResetAll(Force
, Silent
: Boolean);
1510 gTeamStat
[TEAM_RED
].Goals
:= 0;
1511 gTeamStat
[TEAM_BLUE
].Goals
:= 0;
1513 if gPlayers
<> nil then
1514 for i
:= 0 to High(gPlayers
) do
1515 if gPlayers
[i
] <> nil then
1517 gPlayers
[i
].Reset(Force
);
1519 if gPlayers
[i
] is TPlayer
then
1521 if (not gPlayers
[i
].FSpectator
) or gPlayers
[i
].FWantsInGame
then
1522 gPlayers
[i
].Respawn(Silent
)
1524 gPlayers
[i
].Spectate();
1527 TBot(gPlayers
[i
]).Respawn(Silent
);
1531 function g_Player_CreateCorpse(Player
: TPlayer
): Integer;
1539 if Player
.alive
then
1542 // Разрываем связь с прежним трупом:
1543 i
:= Player
.FCorpse
;
1544 if (i
>= 0) and (i
< Length(gCorpses
)) then
1546 if (gCorpses
[i
] <> nil) and (gCorpses
[i
].FPlayerUID
= Player
.FUID
) then
1547 gCorpses
[i
].FPlayerUID
:= 0;
1550 if Player
.FObj
.Y
>= gMapInfo
.Height
+128 then
1555 if (FHealth
>= -50) or (gGibsCount
= 0) then
1557 if (gCorpses
= nil) or (Length(gCorpses
) = 0) then
1561 for find_id
:= 0 to High(gCorpses
) do
1562 if gCorpses
[find_id
] = nil then
1569 find_id
:= Random(Length(gCorpses
));
1571 gCorpses
[find_id
] := TCorpse
.Create(FObj
.X
, FObj
.Y
, FModel
.Name
, FHealth
< -20);
1572 gCorpses
[find_id
].FColor
:= FModel
.Color
;
1573 gCorpses
[find_id
].FObj
.Vel
:= FObj
.Vel
;
1574 gCorpses
[find_id
].FObj
.Accel
:= FObj
.Accel
;
1575 gCorpses
[find_id
].FPlayerUID
:= FUID
;
1580 g_Player_CreateGibs(FObj
.X
+ PLAYER_RECT_CX
,
1581 FObj
.Y
+ PLAYER_RECT_CY
,
1582 FModel
.Name
, FModel
.Color
);
1586 procedure g_Player_CreateShell(fX
, fY
, dX
, dY
: Integer; T
: Byte);
1590 if (gShells
= nil) or (Length(gShells
) = 0) then
1593 with gShells
[CurrentShell
] do
1599 if T
= SHELL_BULLET
then
1601 if g_Texture_Get('TEXTURE_SHELL_BULLET', SID
) then
1605 Obj
.Rect
.Width
:= 4;
1606 Obj
.Rect
.Height
:= 2;
1610 if g_Texture_Get('TEXTURE_SHELL_SHELL', SID
) then
1614 Obj
.Rect
.Width
:= 7;
1615 Obj
.Rect
.Height
:= 3;
1621 g_Obj_Push(@Obj
, dX
+ Random(4)-Random(4), dY
-Random(4));
1622 positionChanged(); // this updates spatial accelerators
1623 RAngle
:= Random(360);
1624 Timeout
:= gTime
+ SHELL_TIMEOUT
;
1626 if CurrentShell
>= High(gShells
) then
1633 procedure g_Player_CreateGibs(fX
, fY
: Integer; ModelName
: string; fColor
: TRGB
);
1636 GibsArray
: TGibsArray
;
1639 if (gGibs
= nil) or (Length(gGibs
) = 0) then
1641 if not g_PlayerModel_GetGibs(ModelName
, GibsArray
) then
1643 Blood
:= g_PlayerModel_GetBlood(ModelName
);
1645 for a
:= 0 to High(GibsArray
) do
1646 with gGibs
[CurrentGib
] do
1649 ID
:= GibsArray
[a
].ID
;
1650 MaskID
:= GibsArray
[a
].MaskID
;
1653 Obj
.Rect
:= GibsArray
[a
].Rect
;
1654 Obj
.X
:= fX
-GibsArray
[a
].Rect
.X
-(GibsArray
[a
].Rect
.Width
div 2);
1655 Obj
.Y
:= fY
-GibsArray
[a
].Rect
.Y
-(GibsArray
[a
].Rect
.Height
div 2);
1656 g_Obj_PushA(@Obj
, 25 + Random(10), Random(361));
1657 positionChanged(); // this updates spatial accelerators
1658 RAngle
:= Random(360);
1660 if gBloodCount
> 0 then
1661 g_GFX_Blood(fX
, fY
, 16*gBloodCount
+Random(5*gBloodCount
), -16+Random(33), -16+Random(33),
1662 Random(48), Random(48), Blood
.R
, Blood
.G
, Blood
.B
, Blood
.Kind
);
1664 if CurrentGib
>= High(gGibs
) then
1671 procedure g_Player_UpdatePhysicalObjects();
1677 procedure ShellSound_Bounce(X
, Y
: Integer; T
: Byte);
1682 if T
= SHELL_BULLET
then
1683 g_Sound_PlayExAt('SOUND_PLAYER_CASING' + IntToStr(k
), X
, Y
)
1685 g_Sound_PlayExAt('SOUND_PLAYER_SHELL' + IntToStr(k
), X
, Y
);
1690 if gGibs
<> nil then
1691 for i
:= 0 to High(gGibs
) do
1692 if gGibs
[i
].alive
then
1699 mr
:= g_Obj_Move(@Obj
, True, False, True);
1700 positionChanged(); // this updates spatial accelerators
1702 if WordBool(mr
and MOVE_FALLOUT
) then
1708 // Отлетает от удара о стену/потолок/пол:
1709 if WordBool(mr
and MOVE_HITWALL
) then
1710 Obj
.Vel
.X
:= -(vel
.X
div 2);
1711 if WordBool(mr
and (MOVE_HITCEIL
or MOVE_HITLAND
)) then
1712 Obj
.Vel
.Y
:= -(vel
.Y
div 2);
1714 if (Obj
.Vel
.X
>= 0) then
1716 RAngle
:= RAngle
+ Abs(Obj
.Vel
.X
)*6 + Abs(Obj
.Vel
.Y
);
1717 if RAngle
>= 360 then
1718 RAngle
:= RAngle
mod 360;
1719 end else begin // Counter-clockwise
1720 RAngle
:= RAngle
- Abs(Obj
.Vel
.X
)*6 - Abs(Obj
.Vel
.Y
);
1722 RAngle
:= (360 - (Abs(RAngle
) mod 360)) mod 360;
1725 // Сопротивление воздуха для куска трупа:
1726 if gTime
mod (GAME_TICK
*3) = 0 then
1727 Obj
.Vel
.X
:= z_dec(Obj
.Vel
.X
, 1);
1731 if gCorpses
<> nil then
1732 for i
:= 0 to High(gCorpses
) do
1733 if gCorpses
[i
] <> nil then
1734 if gCorpses
[i
].State
= CORPSE_STATE_REMOVEME
then
1740 gCorpses
[i
].Update();
1743 if gShells
<> nil then
1744 for i
:= 0 to High(gShells
) do
1745 if gShells
[i
].alive
then
1752 mr
:= g_Obj_Move(@Obj
, True, False, True);
1753 positionChanged(); // this updates spatial accelerators
1755 if WordBool(mr
and MOVE_FALLOUT
) or (gShells
[i
].Timeout
< gTime
) then
1761 // Отлетает от удара о стену/потолок/пол:
1762 if WordBool(mr
and MOVE_HITWALL
) then
1764 Obj
.Vel
.X
:= -(vel
.X
div 2);
1765 if not WordBool(mr
and MOVE_INWATER
) then
1766 ShellSound_Bounce(Obj
.X
, Obj
.Y
, SType
);
1768 if WordBool(mr
and (MOVE_HITCEIL
or MOVE_HITLAND
)) then
1770 Obj
.Vel
.Y
:= -(vel
.Y
div 2);
1771 if Obj
.Vel
.X
<> 0 then Obj
.Vel
.X
:= Obj
.Vel
.X
div 2;
1772 if (Obj
.Vel
.X
= 0) and (Obj
.Vel
.Y
= 0) then
1774 if RAngle
mod 90 <> 0 then
1775 RAngle
:= (RAngle
div 90) * 90;
1777 else if not WordBool(mr
and MOVE_INWATER
) then
1778 ShellSound_Bounce(Obj
.X
, Obj
.Y
, SType
);
1781 if (Obj
.Vel
.X
>= 0) then
1783 RAngle
:= RAngle
+ Abs(Obj
.Vel
.X
)*8 + Abs(Obj
.Vel
.Y
);
1784 if RAngle
>= 360 then
1785 RAngle
:= RAngle
mod 360;
1786 end else begin // Counter-clockwise
1787 RAngle
:= RAngle
- Abs(Obj
.Vel
.X
)*8 - Abs(Obj
.Vel
.Y
);
1789 RAngle
:= (360 - (Abs(RAngle
) mod 360)) mod 360;
1795 procedure TGib
.getMapBox (out x
, y
, w
, h
: Integer); inline;
1797 x
:= Obj
.X
+Obj
.Rect
.X
;
1798 y
:= Obj
.Y
+Obj
.Rect
.Y
;
1799 w
:= Obj
.Rect
.Width
;
1800 h
:= Obj
.Rect
.Height
;
1803 procedure TGib
.moveBy (dx
, dy
: Integer); inline;
1805 if (dx
<> 0) or (dy
<> 0) then
1814 procedure TShell
.getMapBox (out x
, y
, w
, h
: Integer); inline;
1818 w
:= Obj
.Rect
.Width
;
1819 h
:= Obj
.Rect
.Height
;
1822 procedure TShell
.moveBy (dx
, dy
: Integer); inline;
1824 if (dx
<> 0) or (dy
<> 0) then
1833 procedure TGib
.positionChanged (); inline; begin end;
1834 procedure TShell
.positionChanged (); inline; begin end;
1837 procedure g_Player_RemoveAllCorpses();
1843 SetLength(gGibs
, MaxGibs
);
1844 SetLength(gShells
, MaxGibs
);
1848 if gCorpses
<> nil then
1849 for i
:= 0 to High(gCorpses
) do
1853 SetLength(gCorpses
, MaxCorpses
);
1856 procedure g_Player_Corpses_SaveState (st
: TStream
);
1860 // Считаем количество существующих трупов
1862 for i
:= 0 to High(gCorpses
) do if (gCorpses
[i
] <> nil) then Inc(count
);
1864 // Количество трупов
1865 utils
.writeInt(st
, LongInt(count
));
1867 if (count
= 0) then exit
;
1870 for i
:= 0 to High(gCorpses
) do
1872 if gCorpses
[i
] <> nil then
1875 utils
.writeStr(st
, gCorpses
[i
].FModelName
);
1877 utils
.writeBool(st
, gCorpses
[i
].Mess
);
1878 // Сохраняем данные трупа:
1879 gCorpses
[i
].SaveState(st
);
1885 procedure g_Player_Corpses_LoadState (st
: TStream
);
1893 g_Player_RemoveAllCorpses();
1895 // Количество трупов:
1896 count
:= utils
.readLongInt(st
);
1897 if (count
< 0) or (count
> Length(gCorpses
)) then raise XStreamError
.Create('invalid number of corpses');
1899 if (count
= 0) then exit
;
1902 for i
:= 0 to count
-1 do
1905 str
:= utils
.readStr(st
);
1907 b
:= utils
.readBool(st
);
1909 gCorpses
[i
] := TCorpse
.Create(0, 0, str
, b
);
1910 // Загружаем данные трупа
1911 gCorpses
[i
].LoadState(st
);
1918 function TPlayer
.isValidViewPort (): Boolean; inline; begin result
:= (viewPortW
> 0) and (viewPortH
> 0); end;
1920 procedure TPlayer
.BFGHit();
1922 g_Weapon_BFGHit(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
1923 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2));
1924 if g_Game_IsServer
and g_Game_IsNet
then
1925 MH_SEND_Effect(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
1926 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2),
1930 procedure TPlayer
.ChangeModel(ModelName
: string);
1932 locModel
: TPlayerModel
;
1934 locModel
:= g_PlayerModel_Get(ModelName
);
1935 if locModel
= nil then Exit
;
1941 procedure TPlayer
.SetModel(ModelName
: string);
1945 m
:= g_PlayerModel_Get(ModelName
);
1948 g_SimpleError(Format(_lc
[I_GAME_ERROR_MODEL_FALLBACK
], [ModelName
]));
1949 m
:= g_PlayerModel_Get('doomer');
1952 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], ['doomer']));
1957 if FModel
<> nil then
1962 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
1963 FModel
.Color
:= FColor
1965 FModel
.Color
:= TEAMCOLOR
[FTeam
];
1966 FModel
.SetWeapon(FCurrWeap
);
1967 FModel
.SetFlag(FFlag
);
1968 SetDirection(FDirection
);
1971 procedure TPlayer
.SetColor(Color
: TRGB
);
1974 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
1975 if FModel
<> nil then FModel
.Color
:= Color
;
1978 function TPlayer
.GetColor(): TRGB
;
1980 result
:= FModel
.Color
;
1983 procedure TPlayer
.SwitchTeam
;
1985 if g_Game_IsClient
then
1987 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then Exit
;
1989 if gGameOn
and FAlive
then
1990 Kill(K_SIMPLEKILL
, FUID
, HIT_SELF
);
1992 if FTeam
= TEAM_RED
then
1994 ChangeTeam(TEAM_BLUE
);
1995 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_BLUE
], [FName
]), True);
1996 if g_Game_IsNet
then
1997 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM
, TEAM_BLUE
, FName
);
2001 ChangeTeam(TEAM_RED
);
2002 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_RED
], [FName
]), True);
2003 if g_Game_IsNet
then
2004 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM
, TEAM_RED
, FName
);
2006 FPreferredTeam
:= FTeam
;
2009 procedure TPlayer
.ChangeTeam(Team
: Byte);
2016 TEAM_RED
, TEAM_BLUE
:
2017 FModel
.Color
:= TEAMCOLOR
[Team
];
2019 FModel
.Color
:= FColor
;
2021 if (FTeam
<> OldTeam
) and g_Game_IsNet
and g_Game_IsServer
then
2022 MH_SEND_PlayerStats(FUID
);
2026 procedure TPlayer.CollideItem();
2031 if gItems = nil then Exit;
2032 if not FAlive then Exit;
2034 for i := 0 to High(gItems) do
2037 if (ItemType <> ITEM_NONE) and alive then
2038 if g_Obj_Collide(FObj.X+PLAYER_RECT.X, FObj.Y+PLAYER_RECT.Y, PLAYER_RECT.Width,
2039 PLAYER_RECT.Height, @Obj) then
2041 if not PickItem(ItemType, gItems[i].Respawnable, r) then Continue;
2043 if ItemType in [ITEM_SPHERE_BLUE, ITEM_SPHERE_WHITE, ITEM_INVUL] then
2044 g_Sound_PlayExAt('SOUND_ITEM_GETRULEZ', FObj.X, FObj.Y)
2045 else if ItemType in [ITEM_MEDKIT_SMALL, ITEM_MEDKIT_LARGE, ITEM_MEDKIT_BLACK] then
2046 g_Sound_PlayExAt('SOUND_ITEM_GETMED', FObj.X, FObj.Y)
2047 else g_Sound_PlayExAt('SOUND_ITEM_GETITEM', FObj.X, FObj.Y);
2049 // Надо убрать с карты, если это не ключ, которым нужно поделится с другим игроком:
2050 if r and not ((ItemType in [ITEM_KEY_RED, ITEM_KEY_GREEN, ITEM_KEY_BLUE]) and
2051 (gGameSettings.GameType = GT_SINGLE) and
2052 (g_Player_GetCount() > 1)) then
2053 if not Respawnable then g_Items_Remove(i) else g_Items_Pick(i);
2059 function TPlayer
.CollideLevel(XInc
, YInc
: Integer): Boolean;
2061 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
2062 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_WALL
,
2066 constructor TPlayer
.Create();
2072 mEDamageType
:= HIT_SOME
;
2078 FSawSound
:= TPlayableSound
.Create();
2079 FSawSoundIdle
:= TPlayableSound
.Create();
2080 FSawSoundHit
:= TPlayableSound
.Create();
2081 FSawSoundSelect
:= TPlayableSound
.Create();
2082 FFlameSoundOn
:= TPlayableSound
.Create();
2083 FFlameSoundOff
:= TPlayableSound
.Create();
2084 FFlameSoundWork
:= TPlayableSound
.Create();
2085 FJetSoundFly
:= TPlayableSound
.Create();
2086 FJetSoundOn
:= TPlayableSound
.Create();
2087 FJetSoundOff
:= TPlayableSound
.Create();
2089 FSawSound
.SetByName('SOUND_WEAPON_FIRESAW');
2090 FSawSoundIdle
.SetByName('SOUND_WEAPON_IDLESAW');
2091 FSawSoundHit
.SetByName('SOUND_WEAPON_HITSAW');
2092 FSawSoundSelect
.SetByName('SOUND_WEAPON_SELECTSAW');
2093 FFlameSoundOn
.SetByName('SOUND_WEAPON_FLAMEON');
2094 FFlameSoundOff
.SetByName('SOUND_WEAPON_FLAMEOFF');
2095 FFlameSoundWork
.SetByName('SOUND_WEAPON_FLAMEWORK');
2096 FJetSoundFly
.SetByName('SOUND_PLAYER_JETFLY');
2097 FJetSoundOn
.SetByName('SOUND_PLAYER_JETON');
2098 FJetSoundOff
.SetByName('SOUND_PLAYER_JETOFF');
2100 FSpectatePlayer
:= -1;
2104 FSavedStateNum
:= -1;
2112 FActualModelName
:= 'doomer';
2115 FObj
.Rect
:= PLAYER_RECT
;
2117 FBFGFireCounter
:= -1;
2118 FJustTeleported
:= False;
2121 FWaitForFirstSpawn
:= false;
2126 procedure TPlayer
.positionChanged (); inline;
2130 procedure TPlayer
.doDamage (v
: Integer);
2132 if (v
<= 0) then exit
;
2133 if (v
> 32767) then v
:= 32767;
2134 Damage(v
, 0, 0, 0, mEDamageType
);
2137 procedure TPlayer
.Damage(value
: Word; SpawnerUID
: Word; vx
, vy
: Integer; t
: Byte);
2141 if (not g_Game_IsClient
) and (not FAlive
) then
2146 // Неуязвимость не спасает от ловушек:
2147 if ((t
= HIT_TRAP
) or (t
= HIT_SELF
)) and (not FGodMode
) then
2149 if not g_Game_IsClient
then
2152 if t
= HIT_TRAP
then
2154 // Ловушка убивает сразу:
2156 Kill(K_EXTRAHARDKILL
, SpawnerUID
, t
);
2158 if t
= HIT_SELF
then
2162 Kill(K_SIMPLEKILL
, SpawnerUID
, t
);
2165 // Обнулить действия примочек, чтобы фон пропал
2166 FMegaRulez
[MR_SUIT
] := 0;
2167 FMegaRulez
[MR_INVUL
] := 0;
2168 FMegaRulez
[MR_INVIS
] := 0;
2173 // Но от остального спасает:
2174 if FMegaRulez
[MR_INVUL
] >= gTime
then
2181 // Если есть урон своим, или ранил сам себя, или тебя ранил противник:
2182 if LongBool(gGameSettings
.Options
and GAME_OPTION_TEAMDAMAGE
) or
2183 (SpawnerUID
= FUID
) or
2184 (not SameTeam(FUID
, SpawnerUID
)) then
2186 FLastSpawnerUID
:= SpawnerUID
;
2188 // Кровь (пузырьки, если в воде):
2189 if gBloodCount
> 0 then
2191 c
:= Min(value
, 200)*gBloodCount
+ Random(Min(value
, 200) div 2);
2192 if value
div 4 <= c
then
2193 c
:= c
- (value
div 4)
2197 if (t
= HIT_SOME
) and (vx
= 0) and (vy
= 0) then
2201 HIT_TRAP
, HIT_ACID
, HIT_FLAME
, HIT_SELF
: MakeBloodSimple(c
);
2202 HIT_BFG
, HIT_ROCKET
, HIT_SOME
: MakeBloodVector(c
, vx
, vy
);
2205 if t
= HIT_WATER
then
2206 g_GFX_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
2207 FObj
.Y
+PLAYER_RECT
.Y
-4, value
div 2, 8, 4);
2212 Inc(FDamageBuffer
, value
);
2216 FPain
:= FPain
+ value
;
2219 if g_Game_IsServer
and g_Game_IsNet
then
2221 MH_SEND_PlayerDamage(FUID
, t
, SpawnerUID
, value
, vx
, vy
);
2222 MH_SEND_PlayerStats(FUID
);
2223 MH_SEND_PlayerPos(False, FUID
);
2227 function TPlayer
.Heal(value
: Word; Soft
: Boolean): Boolean;
2230 if g_Game_IsClient
then
2235 if Soft
and (FHealth
< PLAYER_HP_SOFT
) then
2237 IncMax(FHealth
, value
, PLAYER_HP_SOFT
);
2240 if (not Soft
) and (FHealth
< PLAYER_HP_LIMIT
) then
2242 IncMax(FHealth
, value
, PLAYER_HP_LIMIT
);
2246 if Result
and g_Game_IsServer
and g_Game_IsNet
then
2247 MH_SEND_PlayerStats(FUID
);
2250 destructor TPlayer
.Destroy();
2252 if (gPlayer1
<> nil) and (gPlayer1
.FUID
= FUID
) then
2254 if (gPlayer2
<> nil) and (gPlayer2
.FUID
= FUID
) then
2258 FSawSoundIdle
.Free();
2259 FSawSoundHit
.Free();
2260 FSawSoundSelect
.Free();
2261 FFlameSoundOn
.Free();
2262 FFlameSoundOff
.Free();
2263 FFlameSoundWork
.Free();
2264 FJetSoundFly
.Free();
2266 FJetSoundOff
.Free();
2268 if FPunchAnim
<> nil then
2274 procedure TPlayer
.DoPunch();
2279 if FPunchAnim
<> nil then begin
2284 st
:= 'FRAMES_PUNCH';
2285 if R_BERSERK
in FRulez
then
2286 st
:= st
+ '_BERSERK';
2287 if FKeys
[KEY_UP
].Pressed
then
2289 else if FKeys
[KEY_DOWN
].Pressed
then
2291 g_Frames_Get(id
, st
);
2292 FPunchAnim
:= TAnimation
.Create(id
, False, 1);
2295 procedure TPlayer
.Fire();
2297 f
, DidFire
: Boolean;
2298 wx
, wy
, xd
, yd
: Integer;
2301 if g_Game_IsClient
then Exit
;
2302 // FBFGFireCounter - время перед выстрелом (для BFG)
2303 // FReloading - время после выстрела (для всего)
2311 if FReloading
[FCurrWeap
] <> 0 then Exit
;
2316 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
2317 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
2318 xd
:= wx
+IfThen(FDirection
= TDirection
.D_LEFT
, -30, 30);
2319 yd
:= wy
+firediry();
2325 if R_BERSERK
in FRulez
then
2327 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
2328 locobj
.X
:= FObj
.X
+FObj
.Rect
.X
;
2329 locobj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
2332 locobj
.rect
.Width
:= 39;
2333 locobj
.rect
.Height
:= 52;
2334 locobj
.Vel
.X
:= (xd
-wx
) div 2;
2335 locobj
.Vel
.Y
:= (yd
-wy
) div 2;
2336 locobj
.Accel
.X
:= xd
-wx
;
2337 locobj
.Accel
.y
:= yd
-wy
;
2339 if g_Weapon_Hit(@locobj
, 50, FUID
, HIT_SOME
) <> 0 then
2340 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
2342 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
2344 if (gFlash
= 1) and (FPain
< 50) then FPain
:= min(FPain
+ 25, 50);
2348 g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
2352 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2357 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
2358 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
2360 FSawSoundSelect
.Stop();
2362 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
2364 else if not FSawSoundHit
.IsPlaying() then
2366 FSawSoundSelect
.Stop();
2367 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
2370 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2376 if FAmmo
[A_BULLETS
] > 0 then
2378 g_Weapon_pistol(wx
, wy
, xd
, yd
, FUID
);
2379 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2380 Dec(FAmmo
[A_BULLETS
]);
2381 FFireAngle
:= FAngle
;
2384 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
2385 GameVelX
, GameVelY
-2, SHELL_BULLET
);
2389 if FAmmo
[A_SHELLS
] > 0 then
2391 g_Weapon_shotgun(wx
, wy
, xd
, yd
, FUID
);
2392 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', wx
, wy
);
2393 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2394 Dec(FAmmo
[A_SHELLS
]);
2395 FFireAngle
:= FAngle
;
2399 FShellType
:= SHELL_SHELL
;
2403 if FAmmo
[A_SHELLS
] >= 2 then
2405 g_Weapon_dshotgun(wx
, wy
, xd
, yd
, FUID
);
2406 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2407 Dec(FAmmo
[A_SHELLS
], 2);
2408 FFireAngle
:= FAngle
;
2412 FShellType
:= SHELL_DBLSHELL
;
2416 if FAmmo
[A_BULLETS
] > 0 then
2418 g_Weapon_mgun(wx
, wy
, xd
, yd
, FUID
);
2419 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', wx
, wy
);
2420 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2421 Dec(FAmmo
[A_BULLETS
]);
2422 FFireAngle
:= FAngle
;
2425 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
2426 GameVelX
, GameVelY
-2, SHELL_BULLET
);
2429 WEAPON_ROCKETLAUNCHER
:
2430 if FAmmo
[A_ROCKETS
] > 0 then
2432 g_Weapon_rocket(wx
, wy
, xd
, yd
, FUID
);
2433 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2434 Dec(FAmmo
[A_ROCKETS
]);
2435 FFireAngle
:= FAngle
;
2441 if FAmmo
[A_CELLS
] > 0 then
2443 g_Weapon_plasma(wx
, wy
, xd
, yd
, FUID
);
2444 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2445 Dec(FAmmo
[A_CELLS
]);
2446 FFireAngle
:= FAngle
;
2452 if (FAmmo
[A_CELLS
] >= 40) and (FBFGFireCounter
= -1) then
2454 FBFGFireCounter
:= 17;
2455 if not FNoReload
then
2456 g_Sound_PlayExAt('SOUND_WEAPON_STARTFIREBFG', FObj
.X
, FObj
.Y
);
2457 Dec(FAmmo
[A_CELLS
], 40);
2461 WEAPON_SUPERPULEMET
:
2462 if FAmmo
[A_SHELLS
] > 0 then
2464 g_Weapon_shotgun(wx
, wy
, xd
, yd
, FUID
);
2465 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', wx
, wy
);
2466 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2467 Dec(FAmmo
[A_SHELLS
]);
2468 FFireAngle
:= FAngle
;
2471 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
2472 GameVelX
, GameVelY
-2, SHELL_SHELL
);
2475 WEAPON_FLAMETHROWER
:
2476 if FAmmo
[A_FUEL
] > 0 then
2478 g_Weapon_flame(wx
, wy
, xd
, yd
, FUID
);
2480 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2482 FFireAngle
:= FAngle
;
2489 if g_Game_IsNet
and g_Game_IsServer
then MH_SEND_PlayerStats(FUID
);
2493 if g_Game_IsNet
then
2497 if FCurrWeap
<> WEAPON_BFG
then
2498 MH_SEND_PlayerFire(FUID
, FCurrWeap
, wx
, wy
, xd
, yd
, LastShotID
)
2500 if not FNoReload
then
2501 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_WEAPON_STARTFIREBFG');
2504 MH_SEND_PlayerStats(FUID
);
2509 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
2510 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
2511 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
2514 function TPlayer
.GetAmmoByWeapon(Weapon
: Byte): Word;
2517 WEAPON_PISTOL
, WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
];
2518 WEAPON_SHOTGUN1
, WEAPON_SHOTGUN2
, WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
];
2519 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
];
2520 WEAPON_PLASMA
, WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
];
2521 WEAPON_FLAMETHROWER
: Result
:= FAmmo
[A_FUEL
];
2526 function TPlayer
.HeadInLiquid(XInc
, YInc
: Integer): Boolean;
2528 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
+XInc
, FObj
.Y
+PLAYER_HEADRECT
.Y
+YInc
,
2529 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
2530 PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, True);
2533 procedure TPlayer
.FlamerOn
;
2535 FFlameSoundOff
.Stop();
2536 FFlameSoundOff
.SetPosition(0);
2539 if (not FFlameSoundOn
.IsPlaying()) and (not FFlameSoundWork
.IsPlaying()) then
2540 FFlameSoundWork
.PlayAt(FObj
.X
, FObj
.Y
);
2544 FFlameSoundOn
.PlayAt(FObj
.X
, FObj
.Y
);
2549 procedure TPlayer
.FlamerOff
;
2553 FFlameSoundOn
.Stop();
2554 FFlameSoundOn
.SetPosition(0);
2555 FFlameSoundWork
.Stop();
2556 FFlameSoundWork
.SetPosition(0);
2557 FFlameSoundOff
.PlayAt(FObj
.X
, FObj
.Y
);
2562 procedure TPlayer
.JetpackOn
;
2566 FJetSoundOn
.SetPosition(0);
2567 FJetSoundOn
.PlayAt(FObj
.X
, FObj
.Y
);
2571 procedure TPlayer
.JetpackOff
;
2575 FJetSoundOff
.SetPosition(0);
2576 FJetSoundOff
.PlayAt(FObj
.X
, FObj
.Y
);
2579 procedure TPlayer
.CatchFire(Attacker
: Word; Timeout
: Integer = PLAYER_BURN_TIME
);
2581 if Timeout
<= 0 then
2583 if (FMegaRulez
[MR_SUIT
] > gTime
) or (FMegaRulez
[MR_INVUL
] > gTime
) then
2584 exit
; // Не загораемся когда есть защита
2585 if g_Obj_CollidePanel(@FObj
, 0, 0, PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
) then
2586 exit
; // Не подгораем в воде на всякий случай
2587 if FFireTime
<= 0 then
2588 g_Sound_PlayExAt('SOUND_IGNITE', FObj
.X
, FObj
.Y
);
2589 FFireTime
:= Timeout
;
2590 FFireAttacker
:= Attacker
;
2591 if g_Game_IsNet
and g_Game_IsServer
then
2592 MH_SEND_PlayerStats(FUID
);
2595 procedure TPlayer
.Jump();
2597 if gFly
or FJetpack
then
2599 // Полет (чит-код или джетпак):
2600 if FObj
.Vel
.Y
> -VEL_FLY
then
2601 FObj
.Vel
.Y
:= FObj
.Vel
.Y
- 3;
2604 if FJetFuel
> 0 then
2606 if (FJetFuel
< 1) and g_Game_IsServer
then
2610 if g_Game_IsNet
then
2611 MH_SEND_PlayerStats(FUID
);
2617 // Не включать джетпак в режиме прохождения сквозь стены
2619 FCanJetpack
:= False;
2621 // Прыгаем или всплываем:
2622 if (CollideLevel(0, 1) or
2623 g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
+36, PLAYER_RECT
.Width
,
2624 PLAYER_RECT
.Height
-33, PANEL_STEP
, False)
2625 ) and (FObj
.Accel
.Y
= 0) then // Не прыгать, если есть вертикальное ускорение
2627 FObj
.Vel
.Y
:= -VEL_JUMP
;
2628 FCanJetpack
:= False;
2632 if BodyInLiquid(0, 0) then
2633 FObj
.Vel
.Y
:= -VEL_SW
2634 else if (FJetFuel
> 0) and FCanJetpack
and
2635 g_Game_IsServer
and (not g_Obj_CollideLiquid(@FObj
, 0, 0)) then
2639 if g_Game_IsNet
then
2640 MH_SEND_PlayerStats(FUID
);
2645 procedure TPlayer
.Kill(KillType
: Byte; SpawnerUID
: Word; t
: Byte);
2647 a
, i
, k
, ab
, ar
: Byte;
2651 srv
, netsrv
: Boolean;
2657 procedure PushItem(t
: Byte);
2661 id
:= g_Items_Create(FObj
.X
, FObj
.Y
, t
, True, False);
2662 it
:= g_Items_ByIdx(id
);
2663 if KillType
= K_EXTRAHARDKILL
then // -7..+7; -8..0
2665 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-7+Random(15),
2666 (FObj
.Vel
.Y
div 2)-Random(9));
2667 it
.positionChanged(); // this updates spatial accelerators
2671 if KillType
= K_HARDKILL
then // -5..+5; -5..0
2673 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-5+Random(11),
2674 (FObj
.Vel
.Y
div 2)-Random(6));
2676 else // -3..+3; -3..0
2678 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-3+Random(7),
2679 (FObj
.Vel
.Y
div 2)-Random(4));
2681 it
.positionChanged(); // this updates spatial accelerators
2684 if g_Game_IsNet
and g_Game_IsServer
then
2685 MH_SEND_ItemSpawn(True, id
);
2689 DoFrags
:= (gGameSettings
.MaxLives
= 0) or (gGameSettings
.GameMode
= GM_COOP
);
2690 Srv
:= g_Game_IsServer
;
2691 Netsrv
:= g_Game_IsServer
and g_Game_IsNet
;
2692 if Srv
then FDeath
:= FDeath
+ 1;
2697 if not FPhysics
then
2703 if (gGameSettings
.MaxLives
> 0) and Srv
and (gLMSRespawn
= LMS_RESPAWN_NONE
) then
2705 if FLives
> 0 then FLives
:= FLives
- 1;
2706 if FLives
= 0 then FNoRespawn
:= True;
2709 // Номер типа смерти:
2712 K_SIMPLEKILL
: a
:= 1;
2714 K_EXTRAHARDKILL
: a
:= 3;
2719 if not FModel
.PlaySound(MODELSOUND_DIE
, a
, FObj
.X
, FObj
.Y
) then
2721 if FModel
.PlaySound(MODELSOUND_DIE
, i
, FObj
.X
, FObj
.Y
) then
2728 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN1
;
2730 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN2
;
2731 K_EXTRAHARDKILL
, K_FALLKILL
:
2732 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN3
;
2735 // Переключаем состояние:
2739 K_HARDKILL
, K_EXTRAHARDKILL
:
2743 // Реакция монстров на смерть игрока:
2744 if (KillType
<> K_FALLKILL
) and (Srv
) then
2745 g_Monsters_killedp();
2747 if SpawnerUID
= FUID
then
2749 if Srv
and (DoFrags
or (gGameSettings
.GameMode
= GM_TDM
)) then
2754 g_Console_Add(Format(_lc
[I_PLAYER_KILL_SELF
], [FName
]), True);
2757 if g_GetUIDType(SpawnerUID
) = UID_PLAYER
then
2758 begin // Убит другим игроком
2759 KP
:= g_Player_Get(SpawnerUID
);
2760 if (KP
<> nil) and Srv
then
2762 if (DoFrags
or (gGameSettings
.GameMode
= GM_TDM
)) then
2763 if SameTeam(FUID
, SpawnerUID
) then
2773 if (gGameSettings
.GameMode
= GM_TDM
) and DoFrags
then
2774 Inc(gTeamStat
[KP
.Team
].Goals
,
2775 IfThen(SameTeam(FUID
, SpawnerUID
), -1, 1));
2777 if netsrv
then MH_SEND_PlayerStats(SpawnerUID
);
2780 plr
:= g_Player_Get(SpawnerUID
);
2788 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_2
],
2792 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_1
],
2796 g_Console_Add(Format(_lc
[I_PLAYER_KILL
],
2801 else if g_GetUIDType(SpawnerUID
) = UID_MONSTER
then
2802 begin // Убит монстром
2803 mon
:= g_Monsters_ByUID(SpawnerUID
);
2807 s
:= g_Mons_GetKilledByTypeId(mon
.MonsterType
);
2811 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_2
],
2815 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_1
],
2819 g_Console_Add(Format(_lc
[I_PLAYER_KILL
],
2824 else // Особые типы смерти
2827 HIT_SELF
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_SELF
], [FName
]), True);
2828 HIT_FALL
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_FALL
], [FName
]), True);
2829 HIT_WATER
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_WATER
], [FName
]), True);
2830 HIT_ACID
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_ACID
], [FName
]), True);
2831 HIT_TRAP
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_TRAP
], [FName
]), True);
2832 else g_Console_Add(Format(_lc
[I_PLAYER_DIED
], [FName
]), True);
2838 for a
:= WP_FIRST
to WP_LAST
do
2842 WEAPON_SAW
: i
:= ITEM_WEAPON_SAW
;
2843 WEAPON_SHOTGUN1
: i
:= ITEM_WEAPON_SHOTGUN1
;
2844 WEAPON_SHOTGUN2
: i
:= ITEM_WEAPON_SHOTGUN2
;
2845 WEAPON_CHAINGUN
: i
:= ITEM_WEAPON_CHAINGUN
;
2846 WEAPON_ROCKETLAUNCHER
: i
:= ITEM_WEAPON_ROCKETLAUNCHER
;
2847 WEAPON_PLASMA
: i
:= ITEM_WEAPON_PLASMA
;
2848 WEAPON_BFG
: i
:= ITEM_WEAPON_BFG
;
2849 WEAPON_SUPERPULEMET
: i
:= ITEM_WEAPON_SUPERPULEMET
;
2850 WEAPON_FLAMETHROWER
: i
:= ITEM_WEAPON_FLAMETHROWER
;
2859 if R_ITEM_BACKPACK
in FRulez
then
2860 PushItem(ITEM_AMMO_BACKPACK
);
2862 // Выброс ракетного ранца:
2863 if FJetFuel
> 0 then
2864 PushItem(ITEM_JETPACK
);
2867 if (not (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
])) or
2868 (not LongBool(gGameSettings
.Options
and GAME_OPTION_DMKEYS
)) then
2870 if R_KEY_RED
in FRulez
then
2871 PushItem(ITEM_KEY_RED
);
2873 if R_KEY_GREEN
in FRulez
then
2874 PushItem(ITEM_KEY_GREEN
);
2876 if R_KEY_BLUE
in FRulez
then
2877 PushItem(ITEM_KEY_BLUE
);
2881 DropFlag(KillType
= K_FALLKILL
);
2884 FCorpse
:= g_Player_CreateCorpse(Self
);
2886 if Srv
and (gGameSettings
.MaxLives
> 0) and FNoRespawn
and
2887 (gLMSRespawn
= LMS_RESPAWN_NONE
) then
2893 for i
:= Low(gPlayers
) to High(gPlayers
) do
2895 if gPlayers
[i
] = nil then continue
;
2896 if (not gPlayers
[i
].FNoRespawn
) and (not gPlayers
[i
].FSpectator
) then
2899 if gPlayers
[i
].FTeam
= TEAM_RED
then Inc(ar
)
2900 else if gPlayers
[i
].FTeam
= TEAM_BLUE
then Inc(ab
);
2905 OldLR
:= gLMSRespawn
;
2906 if (gGameSettings
.GameMode
= GM_COOP
) then
2910 // everyone is dead, restart the map
2911 g_Game_Message(_lc
[I_MESSAGE_LMS_LOSE
], 144);
2913 MH_SEND_GameEvent(NET_EV_LMS_LOSE
);
2914 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
2915 gLMSRespawnTime
:= gTime
+ 5000;
2917 else if (a
= 1) then
2919 if (gPlayers
[k
] <> nil) and not (gPlayers
[k
] is TBot
) then
2920 if (gPlayers
[k
] = gPlayer1
) or
2921 (gPlayers
[k
] = gPlayer2
) then
2922 g_Console_Add('*** ' + _lc
[I_MESSAGE_LMS_SURVIVOR
] + ' ***', True)
2923 else if Netsrv
and (gPlayers
[k
].FClientID
>= 0) then
2924 MH_SEND_GameEvent(NET_EV_LMS_SURVIVOR
, 0, 'N', gPlayers
[k
].FClientID
);
2927 else if (gGameSettings
.GameMode
= GM_TDM
) then
2929 if (ab
= 0) and (ar
<> 0) then
2932 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 144);
2934 MH_SEND_GameEvent(NET_EV_TLMS_WIN
, TEAM_RED
);
2935 Inc(gTeamStat
[TEAM_RED
].Goals
);
2936 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
2937 gLMSRespawnTime
:= gTime
+ 5000;
2939 else if (ar
= 0) and (ab
<> 0) then
2942 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 144);
2944 MH_SEND_GameEvent(NET_EV_TLMS_WIN
, TEAM_BLUE
);
2945 Inc(gTeamStat
[TEAM_BLUE
].Goals
);
2946 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
2947 gLMSRespawnTime
:= gTime
+ 5000;
2949 else if (ar
= 0) and (ab
= 0) then
2952 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
2954 MH_SEND_GameEvent(NET_EV_LMS_DRAW
, 0, FName
);
2955 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
2956 gLMSRespawnTime
:= gTime
+ 5000;
2959 else if (gGameSettings
.GameMode
= GM_DM
) then
2963 if gPlayers
[k
] <> nil then
2966 // survivor is the winner
2967 g_Game_Message(Format(_lc
[I_MESSAGE_LMS_WIN
], [AnsiUpperCase(FName
)]), 144);
2969 MH_SEND_GameEvent(NET_EV_LMS_WIN
, 0, FName
);
2972 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
2973 gLMSRespawnTime
:= gTime
+ 5000;
2975 else if (a
= 0) then
2977 // everyone is dead, restart the map
2978 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
2980 MH_SEND_GameEvent(NET_EV_LMS_DRAW
, 0, FName
);
2981 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
2982 gLMSRespawnTime
:= gTime
+ 5000;
2985 if srv
and (OldLR
= LMS_RESPAWN_NONE
) and (gLMSRespawn
> LMS_RESPAWN_NONE
) then
2987 if NetMode
= NET_SERVER
then
2988 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
)
2990 g_Console_Add(Format(_lc
[I_MSG_WARMUP_START
], [(gLMSRespawnTime
- gTime
) div 1000]), True);
2996 MH_SEND_PlayerStats(FUID
);
2997 MH_SEND_PlayerDeath(FUID
, KillType
, t
, SpawnerUID
);
2998 if gGameSettings
.GameMode
= GM_TDM
then MH_SEND_GameStats
;
3001 if srv
and FNoRespawn
then Spectate(True);
3002 FWantsInGame
:= True;
3005 function TPlayer
.BodyInLiquid(XInc
, YInc
: Integer): Boolean;
3007 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
, PLAYER_RECT
.Width
,
3008 PLAYER_RECT
.Height
-20, PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, False);
3011 function TPlayer
.BodyInAcid(XInc
, YInc
: Integer): Boolean;
3013 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
, PLAYER_RECT
.Width
,
3014 PLAYER_RECT
.Height
-20, PANEL_ACID1
or PANEL_ACID2
, False);
3017 procedure TPlayer
.MakeBloodSimple(Count
: Word);
3019 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)+8,
3020 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3021 Count
div 2, 3, -1, 16, (PLAYER_RECT
.Height
*2 div 3),
3022 FModel
.Blood
.R
, FModel
.Blood
.G
, FModel
.Blood
.B
, FModel
.Blood
.Kind
);
3023 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-8,
3024 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3025 Count
div 2, -3, -1, 16, (PLAYER_RECT
.Height
*2) div 3,
3026 FModel
.Blood
.R
, FModel
.Blood
.G
, FModel
.Blood
.B
, FModel
.Blood
.Kind
);
3029 procedure TPlayer
.MakeBloodVector(Count
: Word; VelX
, VelY
: Integer);
3031 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
3032 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3033 Count
, VelX
, VelY
, 16, (PLAYER_RECT
.Height
*2) div 3,
3034 FModel
.Blood
.R
, FModel
.Blood
.G
, FModel
.Blood
.B
, FModel
.Blood
.Kind
);
3037 procedure TPlayer
.QueueWeaponSwitch(Weapon
: Byte);
3039 if g_Game_IsClient
then Exit
;
3040 if Weapon
> High(FWeapon
) then Exit
;
3041 FNextWeap
:= FNextWeap
or (1 shl Weapon
);
3044 procedure TPlayer
.resetWeaponQueue ();
3047 FNextWeapDelay
:= 0;
3050 function TPlayer
.hasAmmoForWeapon (weapon
: Byte): Boolean;
3054 WEAPON_KASTET
, WEAPON_SAW
: result
:= true;
3055 WEAPON_SHOTGUN1
, WEAPON_SHOTGUN2
, WEAPON_SUPERPULEMET
: result
:= (FAmmo
[A_SHELLS
] > 0);
3056 WEAPON_PISTOL
, WEAPON_CHAINGUN
: result
:= (FAmmo
[A_BULLETS
] > 0);
3057 WEAPON_ROCKETLAUNCHER
: result
:= (FAmmo
[A_ROCKETS
] > 0);
3058 WEAPON_PLASMA
, WEAPON_BFG
: result
:= (FAmmo
[A_CELLS
] > 0);
3059 WEAPON_FLAMETHROWER
: result
:= (FAmmo
[A_FUEL
] > 0);
3060 else result
:= (weapon
< length(FWeapon
));
3064 // return 255 for "no switch"
3065 function TPlayer
.getNextWeaponIndex (): Byte;
3068 wantThisWeapon
: array[0..64] of Boolean;
3069 wwc
: Integer = 0; //HACK!
3072 result
:= 255; // default result: "no switch"
3073 // had weapon cycling on previous frame? remove that flag
3074 if (FNextWeap
and $2000) <> 0 then
3076 FNextWeap
:= FNextWeap
and $1FFF;
3077 FNextWeapDelay
:= 0;
3079 // cycling has priority
3080 if (FNextWeap
and $C000) <> 0 then
3082 if (FNextWeap
and $8000) <> 0 then
3086 FNextWeap
:= FNextWeap
or $2000; // we need this
3087 if FNextWeapDelay
> 0 then
3088 exit
; // cooldown time
3090 for i
:= 0 to High(FWeapon
) do
3092 cwi
:= (cwi
+length(FWeapon
)+dir
) mod length(FWeapon
);
3093 if FWeapon
[cwi
] then
3095 //e_WriteLog(Format(' SWITCH: cur=%d; new=%d', [FCurrWeap, cwi]), MSG_WARNING);
3096 result
:= Byte(cwi
);
3097 FNextWeapDelay
:= WEAPON_DELAY
;
3105 for i
:= 0 to High(wantThisWeapon
) do
3106 wantThisWeapon
[i
] := false;
3107 for i
:= 0 to High(FWeapon
) do
3108 if (FNextWeap
and (1 shl i
)) <> 0 then
3110 wantThisWeapon
[i
] := true;
3113 // exclude currently selected weapon from the set
3114 wantThisWeapon
[FCurrWeap
] := false;
3115 // slow down alterations a little
3118 //e_WriteLog(Format(' FNextWeap=%x; delay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
3119 // more than one weapon requested, assume "alteration" and check alteration delay
3120 if FNextWeapDelay
> 0 then
3126 // do not reset weapon queue, it will be done in `RealizeCurrentWeapon()`
3127 // but clear all counters if no weapon should be switched
3133 //e_WriteLog(Format('wwc=%d', [wwc]), MSG_WARNING);
3134 // try weapons in descending order
3135 for i
:= High(FWeapon
) downto 0 do
3137 if wantThisWeapon
[i
] and FWeapon
[i
] and ((wwc
= 1) or hasAmmoForWeapon(i
)) then
3142 FNextWeapDelay
:= WEAPON_DELAY
* 2; // anyway, 'cause why not
3146 // no suitable weapon found, so reset the queue, to avoid accidental "queuing" of weapon w/o ammo
3150 procedure TPlayer
.RealizeCurrentWeapon();
3151 function switchAllowed (): Boolean;
3156 if FBFGFireCounter
<> -1 then
3158 if FTime
[T_SWITCH
] > gTime
then
3160 for i
:= WP_FIRST
to WP_LAST
do
3161 if FReloading
[i
] > 0 then
3169 //e_WriteLog(Format('***RealizeCurrentWeapon: FNextWeap=%x; FNextWeapDelay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
3170 //FNextWeap := FNextWeap and $1FFF;
3171 if FNextWeapDelay
> 0 then Dec(FNextWeapDelay
); // "alteration delay"
3173 if not switchAllowed
then
3175 //HACK for weapon cycling
3176 if (FNextWeap
and $E000) <> 0 then FNextWeap
:= 0;
3180 nw
:= getNextWeaponIndex();
3181 if nw
= 255 then exit
; // don't reset anything here
3182 if nw
> High(FWeapon
) then
3184 // don't forget to reset queue here!
3185 //e_WriteLog(' RealizeCurrentWeapon: WUTAFUUUU', MSG_WARNING);
3193 FTime
[T_SWITCH
] := gTime
+156;
3194 if FCurrWeap
= WEAPON_SAW
then FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3195 FModel
.SetWeapon(FCurrWeap
);
3196 if g_Game_IsNet
then MH_SEND_PlayerStats(FUID
);
3200 procedure TPlayer
.NextWeapon();
3202 if g_Game_IsClient
then Exit
;
3206 procedure TPlayer
.PrevWeapon();
3208 if g_Game_IsClient
then Exit
;
3212 procedure TPlayer
.SetWeapon(W
: Byte);
3214 if FCurrWeap
<> W
then
3215 if W
= WEAPON_SAW
then
3216 FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3219 FModel
.SetWeapon(CurrWeap
);
3223 function TPlayer
.PickItem(ItemType
: Byte; arespawn
: Boolean; var remove
: Boolean): Boolean;
3225 function allowBerserkSwitching (): Boolean;
3227 if (FBFGFireCounter
<> -1) then begin result
:= false; exit
; end;
3229 if gBerserkAutoswitch
then exit
;
3230 if not conIsCheatsEnabled
then exit
;
3238 if g_Game_IsClient
then Exit
;
3240 // a = true - место спавна предмета:
3241 a
:= LongBool(gGameSettings
.Options
and GAME_OPTION_WEAPONSTAY
) and arespawn
;
3246 if (FHealth
< PLAYER_HP_SOFT
) or (FFireTime
> 0) then
3248 if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
3252 if gFlash
= 2 then Inc(FPickup
, 5);
3256 if (FHealth
< PLAYER_HP_SOFT
) or (FFireTime
> 0) then
3258 if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
3262 if gFlash
= 2 then Inc(FPickup
, 5);
3266 if FArmor
< PLAYER_AP_SOFT
then
3268 FArmor
:= PLAYER_AP_SOFT
;
3271 if gFlash
= 2 then Inc(FPickup
, 5);
3275 if FArmor
< PLAYER_AP_LIMIT
then
3277 FArmor
:= PLAYER_AP_LIMIT
;
3280 if gFlash
= 2 then Inc(FPickup
, 5);
3284 if (FHealth
< PLAYER_HP_LIMIT
) or (FFireTime
> 0) then
3286 if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
3290 if gFlash
= 2 then Inc(FPickup
, 5);
3294 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) or (FFireTime
> 0) then
3296 if FHealth
< PLAYER_HP_LIMIT
then
3297 FHealth
:= PLAYER_HP_LIMIT
;
3298 if FArmor
< PLAYER_AP_LIMIT
then
3299 FArmor
:= PLAYER_AP_LIMIT
;
3303 if gFlash
= 2 then Inc(FPickup
, 5);
3307 if (not FWeapon
[WEAPON_SAW
]) or ((not arespawn
) and (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
])) then
3309 FWeapon
[WEAPON_SAW
] := True;
3311 if gFlash
= 2 then Inc(FPickup
, 5);
3312 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3315 ITEM_WEAPON_SHOTGUN1
:
3316 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN1
] then
3318 // Нужно, чтобы не взять все пули сразу:
3319 if a
and FWeapon
[WEAPON_SHOTGUN1
] then Exit
;
3321 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3322 FWeapon
[WEAPON_SHOTGUN1
] := True;
3324 if gFlash
= 2 then Inc(FPickup
, 5);
3325 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3328 ITEM_WEAPON_SHOTGUN2
:
3329 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN2
] then
3331 if a
and FWeapon
[WEAPON_SHOTGUN2
] then Exit
;
3333 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3334 FWeapon
[WEAPON_SHOTGUN2
] := True;
3336 if gFlash
= 2 then Inc(FPickup
, 5);
3337 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3340 ITEM_WEAPON_CHAINGUN
:
3341 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or not FWeapon
[WEAPON_CHAINGUN
] then
3343 if a
and FWeapon
[WEAPON_CHAINGUN
] then Exit
;
3345 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
3346 FWeapon
[WEAPON_CHAINGUN
] := True;
3348 if gFlash
= 2 then Inc(FPickup
, 5);
3349 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3352 ITEM_WEAPON_ROCKETLAUNCHER
:
3353 if (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or not FWeapon
[WEAPON_ROCKETLAUNCHER
] then
3355 if a
and FWeapon
[WEAPON_ROCKETLAUNCHER
] then Exit
;
3357 IncMax(FAmmo
[A_ROCKETS
], 2, FMaxAmmo
[A_ROCKETS
]);
3358 FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
3360 if gFlash
= 2 then Inc(FPickup
, 5);
3361 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3365 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_PLASMA
] then
3367 if a
and FWeapon
[WEAPON_PLASMA
] then Exit
;
3369 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3370 FWeapon
[WEAPON_PLASMA
] := True;
3372 if gFlash
= 2 then Inc(FPickup
, 5);
3373 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3377 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_BFG
] then
3379 if a
and FWeapon
[WEAPON_BFG
] then Exit
;
3381 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3382 FWeapon
[WEAPON_BFG
] := True;
3384 if gFlash
= 2 then Inc(FPickup
, 5);
3385 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3388 ITEM_WEAPON_SUPERPULEMET
:
3389 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SUPERPULEMET
] then
3391 if a
and FWeapon
[WEAPON_SUPERPULEMET
] then Exit
;
3393 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3394 FWeapon
[WEAPON_SUPERPULEMET
] := True;
3396 if gFlash
= 2 then Inc(FPickup
, 5);
3397 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3400 ITEM_WEAPON_FLAMETHROWER
:
3401 if (FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
]) or not FWeapon
[WEAPON_FLAMETHROWER
] then
3403 if a
and FWeapon
[WEAPON_FLAMETHROWER
] then Exit
;
3405 IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
3406 FWeapon
[WEAPON_FLAMETHROWER
] := True;
3408 if gFlash
= 2 then Inc(FPickup
, 5);
3409 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3413 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
3415 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
3418 if gFlash
= 2 then Inc(FPickup
, 5);
3421 ITEM_AMMO_BULLETS_BOX
:
3422 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
3424 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
3427 if gFlash
= 2 then Inc(FPickup
, 5);
3431 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
3433 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3436 if gFlash
= 2 then Inc(FPickup
, 5);
3439 ITEM_AMMO_SHELLS_BOX
:
3440 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
3442 IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
3445 if gFlash
= 2 then Inc(FPickup
, 5);
3449 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
3451 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
3454 if gFlash
= 2 then Inc(FPickup
, 5);
3457 ITEM_AMMO_ROCKET_BOX
:
3458 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
3460 IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
3463 if gFlash
= 2 then Inc(FPickup
, 5);
3467 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
3469 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3472 if gFlash
= 2 then Inc(FPickup
, 5);
3476 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
3478 IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
3481 if gFlash
= 2 then Inc(FPickup
, 5);
3485 if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then
3487 IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
3490 if gFlash
= 2 then Inc(FPickup
, 5);
3494 if not(R_ITEM_BACKPACK
in FRulez
) or
3495 (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
3496 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
3497 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
3498 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or
3499 (FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
]) then
3501 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[1, A_BULLETS
];
3502 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[1, A_SHELLS
];
3503 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[1, A_ROCKETS
];
3504 FMaxAmmo
[A_CELLS
] := AmmoLimits
[1, A_CELLS
];
3505 FMaxAmmo
[A_FUEL
] := AmmoLimits
[1, A_FUEL
];
3507 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
3508 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
3509 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
3510 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3511 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
3512 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
3513 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
3514 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3515 if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then
3516 IncMax(FAmmo
[A_FUEL
], 50, FMaxAmmo
[A_FUEL
]);
3518 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
3521 if gFlash
= 2 then Inc(FPickup
, 5);
3525 if not(R_KEY_RED
in FRulez
) then
3527 Include(FRulez
, R_KEY_RED
);
3529 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
3530 if gFlash
= 2 then Inc(FPickup
, 5);
3531 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
3535 if not(R_KEY_GREEN
in FRulez
) then
3537 Include(FRulez
, R_KEY_GREEN
);
3539 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
3540 if gFlash
= 2 then Inc(FPickup
, 5);
3541 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
3545 if not(R_KEY_BLUE
in FRulez
) then
3547 Include(FRulez
, R_KEY_BLUE
);
3549 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
3550 if gFlash
= 2 then Inc(FPickup
, 5);
3551 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
3555 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
3557 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
3561 if gFlash
= 2 then Inc(FPickup
, 5);
3565 if FAir
< AIR_MAX
then
3570 if gFlash
= 2 then Inc(FPickup
, 5);
3575 if not (R_BERSERK
in FRulez
) then
3577 Include(FRulez
, R_BERSERK
);
3578 if allowBerserkSwitching
then
3580 FCurrWeap
:= WEAPON_KASTET
;
3582 FModel
.SetWeapon(WEAPON_KASTET
);
3587 if gFlash
= 2 then Inc(FPickup
, 5);
3589 FBerserk
:= gTime
+30000;
3594 if (FHealth
< PLAYER_HP_SOFT
) or (FFireTime
> 0) then
3596 if FHealth
< PLAYER_HP_SOFT
then FHealth
:= PLAYER_HP_SOFT
;
3597 FBerserk
:= gTime
+30000;
3605 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
3607 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
3611 if gFlash
= 2 then Inc(FPickup
, 5);
3615 if (FHealth
< PLAYER_HP_LIMIT
) or (FFireTime
> 0) then
3617 if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
3621 if gFlash
= 2 then Inc(FPickup
, 5);
3625 if FArmor
< PLAYER_AP_LIMIT
then
3627 IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
3630 if gFlash
= 2 then Inc(FPickup
, 5);
3634 if FJetFuel
< JET_MAX
then
3636 FJetFuel
:= JET_MAX
;
3639 if gFlash
= 2 then Inc(FPickup
, 5);
3643 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
3645 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
3648 if gFlash
= 2 then Inc(FPickup
, 5);
3653 procedure TPlayer
.Touch();
3657 //FModel.PlaySound(MODELSOUND_PAIN, 1, FObj.X, FObj.Y);
3660 // Бросить флаг товарищу:
3661 if gGameSettings
.GameMode
= GM_CTF
then
3666 procedure TPlayer
.Push(vx
, vy
: Integer);
3668 if (not FPhysics
) and FGhost
then
3670 FObj
.Accel
.X
:= FObj
.Accel
.X
+ vx
;
3671 FObj
.Accel
.Y
:= FObj
.Accel
.Y
+ vy
;
3672 if g_Game_IsNet
and g_Game_IsServer
then
3673 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
3676 procedure TPlayer
.Reset(Force
: Boolean);
3682 FTime
[T_RESPAWN
] := 0;
3683 FTime
[T_FLAGCAP
] := 0;
3699 FSpectator
:= False;
3702 FSpectatePlayer
:= -1;
3703 FNoRespawn
:= False;
3705 FLives
:= gGameSettings
.MaxLives
;
3710 procedure TPlayer
.SoftReset();
3718 FBFGFireCounter
:= -1;
3726 SetAction(A_STAND
, True);
3729 function TPlayer
.GetRespawnPoint(): Byte;
3734 // На будущее: FSpawn - игрок уже играл и перерождается
3736 // Одиночная игра/кооператив
3737 if gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
] then
3739 if Self
= gPlayer1
then
3741 // player 1 should try to spawn on the player 1 point
3742 if g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) > 0 then
3743 Exit(RESPAWNPOINT_PLAYER1
)
3744 else if g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) > 0 then
3745 Exit(RESPAWNPOINT_PLAYER2
);
3747 else if Self
= gPlayer2
then
3749 // player 2 should try to spawn on the player 2 point
3750 if g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) > 0 then
3751 Exit(RESPAWNPOINT_PLAYER2
)
3752 else if g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) > 0 then
3753 Exit(RESPAWNPOINT_PLAYER1
);
3757 // other players randomly pick either the first or the second point
3758 c
:= IfThen((Random(2) = 0), RESPAWNPOINT_PLAYER1
, RESPAWNPOINT_PLAYER2
);
3759 if g_Map_GetPointCount(c
) > 0 then
3761 // try the other one
3762 c
:= IfThen((c
= RESPAWNPOINT_PLAYER1
), RESPAWNPOINT_PLAYER2
, RESPAWNPOINT_PLAYER1
);
3763 if g_Map_GetPointCount(c
) > 0 then
3769 if gGameSettings
.GameMode
= GM_DM
then
3771 // try DM points first
3772 if g_Map_GetPointCount(RESPAWNPOINT_DM
) > 0 then
3773 Exit(RESPAWNPOINT_DM
);
3777 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
3779 // try team points first
3780 c
:= RESPAWNPOINT_DM
;
3781 if FTeam
= TEAM_RED
then
3782 c
:= RESPAWNPOINT_RED
3783 else if FTeam
= TEAM_BLUE
then
3784 c
:= RESPAWNPOINT_BLUE
;
3785 if g_Map_GetPointCount(c
) > 0 then
3789 // still haven't found a spawnpoint, try random shit
3790 Result
:= g_Map_GetRandomPointType();
3793 procedure TPlayer
.Respawn(Silent
: Boolean; Force
: Boolean = False);
3795 RespawnPoint
: TRespawnPoint
;
3803 FBFGFireCounter
:= -1;
3810 if not g_Game_IsServer
then
3814 FWantsInGame
:= True;
3815 FJustTeleported
:= True;
3818 FTime
[T_RESPAWN
] := 0;
3822 // if server changes MaxLives we gotta be ready
3823 if gGameSettings
.MaxLives
= 0 then FNoRespawn
:= False;
3825 // Еще нельзя возродиться:
3826 if FTime
[T_RESPAWN
] > gTime
then
3829 // Просрал все жизни:
3832 if not FSpectator
then Spectate(True);
3833 FWantsInGame
:= True;
3837 if (gGameSettings
.GameType
<> GT_SINGLE
) and (gGameSettings
.GameMode
<> GM_COOP
) then
3838 begin // "Своя игра"
3839 // Берсерк не сохраняется между уровнями:
3840 FRulez
:= FRulez
-[R_BERSERK
];
3842 else // "Одиночная игра"/"Кооп"
3844 // Берсерк и ключи не сохраняются между уровнями:
3845 FRulez
:= FRulez
-[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
, R_BERSERK
];
3848 // Получаем точку спауна игрока:
3849 c
:= GetRespawnPoint();
3854 // Воскрешение без оружия:
3857 FHealth
:= Round(PLAYER_HP_SOFT
* (FHandicap
/ 100));
3863 for a
:= WP_FIRST
to WP_LAST
do
3865 FWeapon
[a
] := False;
3869 FWeapon
[WEAPON_PISTOL
] := True;
3870 FWeapon
[WEAPON_KASTET
] := True;
3871 FCurrWeap
:= WEAPON_PISTOL
;
3874 FModel
.SetWeapon(FCurrWeap
);
3876 for b
:= A_BULLETS
to A_HIGH
do
3879 FAmmo
[A_BULLETS
] := 50;
3881 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[0, A_BULLETS
];
3882 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[0, A_SHELLS
];
3883 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[0, A_SHELLS
];
3884 FMaxAmmo
[A_CELLS
] := AmmoLimits
[0, A_CELLS
];
3885 FMaxAmmo
[A_FUEL
] := AmmoLimits
[0, A_FUEL
];
3887 if (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
]) and
3888 LongBool(gGameSettings
.Options
and GAME_OPTION_DMKEYS
) then
3889 FRulez
:= [R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
]
3894 // Получаем координаты точки возрождения:
3895 if not g_Map_GetPoint(c
, RespawnPoint
) then
3897 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
3901 // Установка координат и сброс всех параметров:
3902 FObj
.X
:= RespawnPoint
.X
-PLAYER_RECT
.X
;
3903 FObj
.Y
:= RespawnPoint
.Y
-PLAYER_RECT
.Y
;
3904 FObj
.oldX
:= FObj
.X
; // don't interpolate after respawn
3905 FObj
.oldY
:= FObj
.Y
;
3911 FDirection
:= RespawnPoint
.Direction
;
3912 if FDirection
= TDirection
.D_LEFT
then
3917 SetAction(A_STAND
, True);
3918 FModel
.Direction
:= FDirection
;
3920 for a
:= Low(FTime
) to High(FTime
) do
3923 for a
:= Low(FMegaRulez
) to High(FMegaRulez
) do
3926 // Respawn invulnerability
3927 if (gGameSettings
.GameType
<> GT_SINGLE
) and (gGameSettings
.SpawnInvul
> 0) then
3929 FMegaRulez
[MR_INVUL
] := gTime
+ gGameSettings
.SpawnInvul
* 1000;
3930 FSpawnInvul
:= FMegaRulez
[MR_INVUL
];
3935 FCanJetpack
:= False;
3941 // Анимация возрождения:
3942 if (not gLoadGameMode
) and (not Silent
) then
3943 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
3945 Anim
:= TAnimation
.Create(ID
, False, 3);
3946 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
3947 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
3951 FSpectator
:= False;
3954 FSpectatePlayer
:= -1;
3957 if (gPlayer1
= nil) and (gSpectLatchPID1
= FUID
) then
3959 if (gPlayer2
= nil) and (gSpectLatchPID2
= FUID
) then
3962 if g_Game_IsNet
then
3964 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
3965 MH_SEND_PlayerStats(FUID
, NET_EVERYONE
);
3967 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
3968 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32,
3973 procedure TPlayer
.Spectate(NoMove
: Boolean = False);
3976 Kill(K_EXTRAHARDKILL
, FUID
, HIT_SOME
)
3977 else if (not NoMove
) then
3979 GameX
:= gMapInfo
.Width
div 2;
3980 GameY
:= gMapInfo
.Height
div 2;
3989 FWantsInGame
:= False;
3995 if Self
= gPlayer1
then
3997 gSpectLatchPID1
:= FUID
;
4000 else if Self
= gPlayer2
then
4002 gSpectLatchPID2
:= FUID
;
4007 if g_Game_IsNet
then
4008 MH_SEND_PlayerStats(FUID
);
4011 procedure TPlayer
.SwitchNoClip
;
4015 FGhost
:= not FGhost
;
4016 FPhysics
:= not FGhost
;
4028 procedure TPlayer
.Run(Direction
: TDirection
);
4032 if MAX_RUNVEL
> 8 then
4036 if Direction
= TDirection
.D_LEFT
then
4038 if FObj
.Vel
.X
> -MAX_RUNVEL
then
4039 FObj
.Vel
.X
:= FObj
.Vel
.X
- (MAX_RUNVEL
shr 3);
4042 if FObj
.Vel
.X
< MAX_RUNVEL
then
4043 FObj
.Vel
.X
:= FObj
.Vel
.X
+ (MAX_RUNVEL
shr 3);
4045 // Возможно, пинаем куски:
4046 if (FObj
.Vel
.X
<> 0) and (gGibs
<> nil) then
4048 b
:= Abs(FObj
.Vel
.X
);
4049 if b
> 1 then b
:= b
* (Random(8 div b
) + 1);
4050 for a
:= 0 to High(gGibs
) do
4052 if gGibs
[a
].alive
and
4053 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
+FObj
.Rect
.Height
-4,
4054 FObj
.Rect
.Width
, 8, @gGibs
[a
].Obj
) and (Random(3) = 0) then
4057 if FObj
.Vel
.X
< 0 then
4059 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)+120) // налево
4063 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)); // направо
4065 gGibs
[a
].positionChanged(); // this updates spatial accelerators
4073 procedure TPlayer
.SeeDown();
4075 SetAction(A_SEEDOWN
);
4077 if FDirection
= TDirection
.D_LEFT
then FAngle
:= ANGLE_LEFTDOWN
else FAngle
:= ANGLE_RIGHTDOWN
;
4079 if FIncCam
> -120 then DecMin(FIncCam
, 5, -120);
4082 procedure TPlayer
.SeeUp();
4086 if FDirection
= TDirection
.D_LEFT
then FAngle
:= ANGLE_LEFTUP
else FAngle
:= ANGLE_RIGHTUP
;
4088 if FIncCam
< 120 then IncMax(FIncCam
, 5, 120);
4091 procedure TPlayer
.SetAction(Action
: Byte; Force
: Boolean = False);
4099 A_ATTACK
: Prior
:= 2;
4100 A_SEEUP
: Prior
:= 1;
4101 A_SEEDOWN
: Prior
:= 1;
4102 A_ATTACKUP
: Prior
:= 2;
4103 A_ATTACKDOWN
: Prior
:= 2;
4108 if (Prior
> FActionPrior
) or Force
then
4109 if not ((Prior
= 2) and (FCurrWeap
= WEAPON_SAW
)) then
4111 FActionPrior
:= Prior
;
4112 FActionAnim
:= Action
;
4113 FActionForce
:= Force
;
4114 FActionChanged
:= True;
4117 if Action
in [A_ATTACK
, A_ATTACKUP
, A_ATTACKDOWN
] then FModel
.SetFire(True);
4120 function TPlayer
.StayOnStep(XInc
, YInc
: Integer): Boolean;
4122 Result
:= not g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
-1,
4123 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False)
4124 and g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
,
4125 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False);
4128 function TPlayer
.TeleportTo(X
, Y
: Integer; silent
: Boolean; dir
: Byte): Boolean;
4135 if g_CollideLevel(X
, Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
) then
4137 g_Sound_PlayExAt('SOUND_GAME_NOTELEPORT', FObj
.X
, FObj
.Y
);
4138 if g_Game_IsServer
and g_Game_IsNet
then
4139 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_GAME_NOTELEPORT');
4143 FJustTeleported
:= True;
4148 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
4150 Anim
:= TAnimation
.Create(ID
, False, 3);
4153 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', FObj
.X
, FObj
.Y
);
4154 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4155 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4156 if g_Game_IsServer
and g_Game_IsNet
then
4157 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4158 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 1,
4162 FObj
.X
:= X
-PLAYER_RECT
.X
;
4163 FObj
.Y
:= Y
-PLAYER_RECT
.Y
;
4164 FObj
.oldX
:= FObj
.X
; // don't interpolate after respawn
4165 FObj
.oldY
:= FObj
.Y
;
4166 if FAlive
and FGhost
then
4172 if not g_Game_IsNet
then
4176 SetDirection(TDirection
.D_LEFT
);
4182 SetDirection(TDirection
.D_RIGHT
);
4188 if FDirection
= TDirection
.D_RIGHT
then
4190 SetDirection(TDirection
.D_LEFT
);
4195 SetDirection(TDirection
.D_RIGHT
);
4201 if not silent
and (Anim
<> nil) then
4203 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4204 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4207 if g_Game_IsServer
and g_Game_IsNet
then
4208 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4209 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 0,
4216 function nonz(a
: Single): Single;
4224 function TPlayer
.refreshCorpse(): Boolean;
4230 if FAlive
or FSpectator
then
4232 if (gCorpses
= nil) or (Length(gCorpses
) = 0) then
4234 for i
:= 0 to High(gCorpses
) do
4235 if gCorpses
[i
] <> nil then
4236 if gCorpses
[i
].FPlayerUID
= FUID
then
4244 function TPlayer
.getCameraObj(): TObj
;
4246 if (not FAlive
) and (not FSpectator
) and
4247 (FCorpse
>= 0) and (FCorpse
< Length(gCorpses
)) and
4248 (gCorpses
[FCorpse
] <> nil) and (gCorpses
[FCorpse
].FPlayerUID
= FUID
) then
4250 gCorpses
[FCorpse
].FObj
.slopeUpLeft
:= FObj
.slopeUpLeft
;
4251 Result
:= gCorpses
[FCorpse
].FObj
;
4259 procedure TPlayer
.PreUpdate();
4261 FSlopeOld
:= FObj
.slopeUpLeft
;
4262 FIncCamOld
:= FIncCam
;
4263 FObj
.oldX
:= FObj
.X
;
4264 FObj
.oldY
:= FObj
.Y
;
4267 procedure TPlayer
.Update();
4270 i
, ii
, wx
, wy
, xd
, yd
, k
: Integer;
4271 blockmon
, headwater
, dospawn
: Boolean;
4276 NetServer
:= g_Game_IsNet
and g_Game_IsServer
;
4277 AnyServer
:= g_Game_IsServer
;
4279 if g_Game_IsClient
and (NetInterpLevel
> 0) then
4280 DoLerp(NetInterpLevel
+ 1)
4286 if FClientID
>= 0 then
4288 FPing
:= NetClients
[FClientID
].Peer
^.lastRoundTripTime
;
4289 if NetClients
[FClientID
].Peer
^.packetsSent
> 0 then
4290 FLoss
:= Round(100*NetClients
[FClientID
].Peer
^.packetsLost
/NetClients
[FClientID
].Peer
^.packetsSent
)
4299 if FAlive
and (FPunchAnim
<> nil) then
4300 FPunchAnim
.Update();
4302 if FAlive
and (gFly
or FJetpack
) then
4305 if FDirection
= TDirection
.D_LEFT
then
4310 if FAlive
and (not FGhost
) then
4312 if FKeys
[KEY_UP
].Pressed
then
4314 if FKeys
[KEY_DOWN
].Pressed
then
4318 if (not (FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_DOWN
].Pressed
)) and
4321 i
:= g_basic
.Sign(FIncCam
);
4322 FIncCam
:= Abs(FIncCam
);
4323 DecMin(FIncCam
, 5, 0);
4324 FIncCam
:= FIncCam
*i
;
4327 // no need to do that each second frame, weapon queue will take care of it
4328 if FAlive
and FKeys
[KEY_NEXTWEAPON
].Pressed
and AnyServer
then NextWeapon();
4329 if FAlive
and FKeys
[KEY_PREVWEAPON
].Pressed
and AnyServer
then PrevWeapon();
4331 if gTime
mod (GAME_TICK
*2) <> 0 then
4333 if (FObj
.Vel
.X
= 0) and FAlive
then
4335 if FKeys
[KEY_LEFT
].Pressed
then
4336 Run(TDirection
.D_LEFT
);
4337 if FKeys
[KEY_RIGHT
].Pressed
then
4338 Run(TDirection
.D_RIGHT
);
4343 g_Obj_Move(@FObj
, True, True, True);
4344 positionChanged(); // this updates spatial accelerators
4350 FActionChanged
:= False;
4354 // Let alive player do some actions
4355 if FKeys
[KEY_LEFT
].Pressed
then Run(TDirection
.D_LEFT
);
4356 if FKeys
[KEY_RIGHT
].Pressed
then Run(TDirection
.D_RIGHT
);
4357 //if FKeys[KEY_NEXTWEAPON].Pressed and AnyServer then NextWeapon();
4358 //if FKeys[KEY_PREVWEAPON].Pressed and AnyServer then PrevWeapon();
4359 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then Fire()
4365 if NetServer
then MH_SEND_PlayerStats(FUID
);
4368 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Use();
4369 if FKeys
[KEY_JUMP
].Pressed
then Jump()
4372 if AnyServer
and FJetpack
then
4376 if NetServer
then MH_SEND_PlayerStats(FUID
);
4378 FCanJetpack
:= True;
4385 for k
:= Low(FKeys
) to KEY_CHAT
-1 do
4387 if FKeys
[k
].Pressed
then
4395 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
4398 if (FTime
[T_RESPAWN
] <= gTime
) and
4399 gGameOn
and (not FAlive
) then
4401 if (g_Player_GetCount() > 1) then
4405 gExit
:= EXIT_RESTART
;
4410 // Dead spectator actions
4413 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Fire();
4414 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then
4418 if (FSpectatePlayer
>= High(gPlayers
)) then
4419 FSpectatePlayer
:= -1
4423 for I
:= FSpectatePlayer
+ 1 to High(gPlayers
) do
4424 if gPlayers
[I
] <> nil then
4425 if gPlayers
[I
].alive
then
4426 if gPlayers
[I
].UID
<> FUID
then
4428 FSpectatePlayer
:= I
;
4433 if not SetSpect
then FSpectatePlayer
:= -1;
4444 if FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_JUMP
].Pressed
then
4446 FYTo
:= FObj
.Y
- 32;
4447 FSpectatePlayer
:= -1;
4449 if FKeys
[KEY_DOWN
].Pressed
then
4451 FYTo
:= FObj
.Y
+ 32;
4452 FSpectatePlayer
:= -1;
4454 if FKeys
[KEY_LEFT
].Pressed
then
4456 FXTo
:= FObj
.X
- 32;
4457 FSpectatePlayer
:= -1;
4459 if FKeys
[KEY_RIGHT
].Pressed
then
4461 FXTo
:= FObj
.X
+ 32;
4462 FSpectatePlayer
:= -1;
4465 if (FXTo
< -64) then
4467 else if (FXTo
> gMapInfo
.Width
+ 32) then
4468 FXTo
:= gMapInfo
.Width
+ 32;
4469 if (FYTo
< -72) then
4471 else if (FYTo
> gMapInfo
.Height
+ 32) then
4472 FYTo
:= gMapInfo
.Height
+ 32;
4477 g_Obj_Move(@FObj
, True, True, True);
4478 positionChanged(); // this updates spatial accelerators
4485 if (FSpectatePlayer
<= High(gPlayers
)) and (FSpectatePlayer
>= 0) then
4486 if gPlayers
[FSpectatePlayer
] <> nil then
4487 if gPlayers
[FSpectatePlayer
].alive
then
4489 FXTo
:= gPlayers
[FSpectatePlayer
].GameX
;
4490 FYTo
:= gPlayers
[FSpectatePlayer
].GameY
;
4494 blockmon
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
, FObj
.Y
+PLAYER_HEADRECT
.Y
,
4495 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
4496 PANEL_BLOCKMON
, True);
4497 headwater
:= HeadInLiquid(0, 0);
4499 // Сопротивление воздуха:
4500 if (not FAlive
) or not (FKeys
[KEY_LEFT
].Pressed
or FKeys
[KEY_RIGHT
].Pressed
) then
4501 if FObj
.Vel
.X
<> 0 then
4502 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
4504 if (FLastHit
= HIT_TRAP
) and (FPain
> 90) then FPain
:= 90;
4505 DecMin(FPain
, 5, 0);
4506 DecMin(FPickup
, 1, 0);
4508 if FAlive
and (FObj
.Y
> Integer(gMapInfo
.Height
)+128) and AnyServer
then
4510 // Обнулить действия примочек, чтобы фон пропал
4511 FMegaRulez
[MR_SUIT
] := 0;
4512 FMegaRulez
[MR_INVUL
] := 0;
4513 FMegaRulez
[MR_INVIS
] := 0;
4514 Kill(K_FALLKILL
, 0, HIT_FALL
);
4521 if FCurrWeap
= WEAPON_SAW
then
4522 if not (FSawSound
.IsPlaying() or FSawSoundHit
.IsPlaying() or
4523 FSawSoundSelect
.IsPlaying()) then
4524 FSawSoundIdle
.PlayAt(FObj
.X
, FObj
.Y
);
4527 if (not FJetSoundFly
.IsPlaying()) and (not FJetSoundOn
.IsPlaying()) and
4528 (not FJetSoundOff
.IsPlaying()) then
4530 FJetSoundFly
.SetPosition(0);
4531 FJetSoundFly
.PlayAt(FObj
.X
, FObj
.Y
);
4534 for b
:= WP_FIRST
to WP_LAST
do
4535 if FReloading
[b
] > 0 then
4541 if FShellTimer
> -1 then
4542 if FShellTimer
= 0 then
4544 if FShellType
= SHELL_SHELL
then
4545 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
4546 GameVelX
, GameVelY
-2, SHELL_SHELL
)
4547 else if FShellType
= SHELL_DBLSHELL
then
4549 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
4550 GameVelX
+1, GameVelY
-2, SHELL_SHELL
);
4551 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
4552 GameVelX
-1, GameVelY
-2, SHELL_SHELL
);
4555 end else Dec(FShellTimer
);
4557 if (FBFGFireCounter
> -1) then
4558 if FBFGFireCounter
= 0 then
4562 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
4563 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
4564 xd
:= wx
+IfThen(FDirection
= TDirection
.D_LEFT
, -30, 30);
4565 yd
:= wy
+firediry();
4566 g_Weapon_bfgshot(wx
, wy
, xd
, yd
, FUID
);
4567 if NetServer
then MH_SEND_PlayerFire(FUID
, WEAPON_BFG
, wx
, wy
, xd
, yd
);
4568 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
4569 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
4570 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
4573 FReloading
[WEAPON_BFG
] := WEAPON_RELOAD
[WEAPON_BFG
];
4574 FBFGFireCounter
:= -1;
4577 FBFGFireCounter
:= 0
4579 Dec(FBFGFireCounter
);
4581 if (FMegaRulez
[MR_SUIT
] < gTime
) and AnyServer
then
4583 b
:= g_GetAcidHit(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
);
4585 if (b
> 0) and (gTime
mod (15*GAME_TICK
) = 0) then Damage(b
, 0, 0, 0, HIT_ACID
);
4588 if (headwater
or blockmon
) then
4594 if AnyServer
then Damage(10, 0, 0, 0, HIT_WATER
);
4597 else if (FAir
mod 31 = 0) and not blockmon
then
4599 g_GFX_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2), FObj
.Y
+PLAYER_RECT
.Y
-4, 5+Random(6), 8, 4);
4600 if Random(2) = 0 then
4601 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
4603 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
4605 end else if FAir
< AIR_DEF
then
4608 if FFireTime
> 0 then
4610 if BodyInLiquid(0, 0) then
4615 else if FMegaRulez
[MR_SUIT
] >= gTime
then
4617 if FMegaRulez
[MR_SUIT
] = gTime
then
4624 if FFirePainTime
<= 0 then
4626 if g_Game_IsServer
then
4627 Damage(2, FFireAttacker
, 0, 0, HIT_FLAME
);
4628 FFirePainTime
:= 12 - FFireTime
div 12;
4630 FFirePainTime
:= FFirePainTime
- 1;
4631 FFireTime
:= FFireTime
- 1;
4632 if ((FFireTime
mod 33) = 0) and (FMegaRulez
[MR_INVUL
] < gTime
) then
4633 FModel
.PlaySound(MODELSOUND_PAIN
, 1, FObj
.X
, FObj
.Y
);
4634 if (FFireTime
= 0) and g_Game_IsNet
and g_Game_IsServer
then
4635 MH_SEND_PlayerStats(FUID
);
4639 if FDamageBuffer
> 0 then
4641 if FDamageBuffer
>= 9 then
4645 if FDamageBuffer
< 30 then i
:= 9
4646 else if FDamageBuffer
< 100 then i
:= 18
4650 ii
:= Round(FDamageBuffer
*FHealth
/ nonz(FArmor
*(3/4)+FHealth
));
4651 FArmor
:= FArmor
-(FDamageBuffer
-ii
);
4652 FHealth
:= FHealth
-ii
;
4655 FHealth
:= FHealth
+FArmor
;
4660 if FHealth
<= 0 then
4661 if FHealth
> -30 then Kill(K_SIMPLEKILL
, FLastSpawnerUID
, FLastHit
)
4662 else if FHealth
> -50 then Kill(K_HARDKILL
, FLastSpawnerUID
, FLastHit
)
4663 else Kill(K_EXTRAHARDKILL
, FLastSpawnerUID
, FLastHit
);
4665 if FAlive
and ((FLastHit
<> HIT_FLAME
) or (FFireTime
<= 0)) then
4667 if FDamageBuffer
<= 20 then FModel
.PlaySound(MODELSOUND_PAIN
, 1, FObj
.X
, FObj
.Y
)
4668 else if FDamageBuffer
<= 55 then FModel
.PlaySound(MODELSOUND_PAIN
, 2, FObj
.X
, FObj
.Y
)
4669 else if FDamageBuffer
<= 120 then FModel
.PlaySound(MODELSOUND_PAIN
, 3, FObj
.X
, FObj
.Y
)
4670 else FModel
.PlaySound(MODELSOUND_PAIN
, 4, FObj
.X
, FObj
.Y
);
4677 end; // if FAlive then ...
4679 if (FActionAnim
= A_PAIN
) and (FModel
.Animation
<> A_PAIN
) then
4681 FModel
.ChangeAnimation(FActionAnim
, FActionForce
);
4682 FModel
.GetCurrentAnimation
.MinLength
:= i
;
4683 FModel
.GetCurrentAnimationMask
.MinLength
:= i
;
4684 end else FModel
.ChangeAnimation(FActionAnim
, FActionForce
and (FModel
.Animation
<> A_STAND
));
4686 if (FModel
.GetCurrentAnimation
.Played
or ((not FActionChanged
) and (FModel
.Animation
= A_WALK
)))
4687 then SetAction(A_STAND
, True);
4689 if not ((FModel
.Animation
= A_WALK
) and (Abs(FObj
.Vel
.X
) < 4) and not FModel
.Fire
) then FModel
.Update
;
4691 for b
:= Low(FKeys
) to High(FKeys
) do
4692 if FKeys
[b
].Time
= 0 then FKeys
[b
].Pressed
:= False else Dec(FKeys
[b
].Time
);
4696 procedure TPlayer
.getMapBox (out x
, y
, w
, h
: Integer); inline;
4698 x
:= FObj
.X
+PLAYER_RECT
.X
;
4699 y
:= FObj
.Y
+PLAYER_RECT
.Y
;
4700 w
:= PLAYER_RECT
.Width
;
4701 h
:= PLAYER_RECT
.Height
;
4705 procedure TPlayer
.moveBy (dx
, dy
: Integer); inline;
4707 if (dx
<> 0) or (dy
<> 0) then
4716 function TPlayer
.Collide(X
, Y
: Integer; Width
, Height
: Word): Boolean;
4718 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
4719 FObj
.Y
+PLAYER_RECT
.Y
,
4726 function TPlayer
.Collide(Panel
: TPanel
): Boolean;
4728 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
4729 FObj
.Y
+PLAYER_RECT
.Y
,
4733 Panel
.Width
, Panel
.Height
);
4736 function TPlayer
.Collide(X
, Y
: Integer): Boolean;
4738 X
:= X
-FObj
.X
-PLAYER_RECT
.X
;
4739 Y
:= Y
-FObj
.Y
-PLAYER_RECT
.Y
;
4740 Result
:= (x
>= 0) and (x
<= PLAYER_RECT
.Width
) and
4741 (y
>= 0) and (y
<= PLAYER_RECT
.Height
);
4744 function g_Player_ValidName(Name
: string): Boolean;
4750 if gPlayers
= nil then Exit
;
4752 for a
:= 0 to High(gPlayers
) do
4753 if gPlayers
[a
] <> nil then
4754 if LowerCase(Name
) = LowerCase(gPlayers
[a
].FName
) then
4761 procedure TPlayer
.SetDirection(Direction
: TDirection
);
4765 d
:= FModel
.Direction
;
4767 FModel
.Direction
:= Direction
;
4768 if d
<> Direction
then FModel
.ChangeAnimation(FModel
.Animation
, True);
4770 FDirection
:= Direction
;
4773 function TPlayer
.GetKeys(): Byte;
4777 if R_KEY_RED
in FRulez
then Result
:= KEY_RED
;
4778 if R_KEY_GREEN
in FRulez
then Result
:= Result
or KEY_GREEN
;
4779 if R_KEY_BLUE
in FRulez
then Result
:= Result
or KEY_BLUE
;
4781 if FTeam
= TEAM_RED
then Result
:= Result
or KEY_REDTEAM
;
4782 if FTeam
= TEAM_BLUE
then Result
:= Result
or KEY_BLUETEAM
;
4785 procedure TPlayer
.Use();
4789 if FTime
[T_USE
] > gTime
then Exit
;
4791 g_Triggers_PressR(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
,
4792 PLAYER_RECT
.Height
, FUID
, ACTIVATE_PLAYERPRESS
);
4794 for a
:= 0 to High(gPlayers
) do
4795 if (gPlayers
[a
] <> nil) and (gPlayers
[a
] <> Self
) and
4796 gPlayers
[a
].alive
and SameTeam(FUID
, gPlayers
[a
].FUID
) and
4797 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
4798 FObj
.Rect
.Width
, FObj
.Rect
.Height
, @gPlayers
[a
].FObj
) then
4800 gPlayers
[a
].Touch();
4801 if g_Game_IsNet
and g_Game_IsServer
then
4802 MH_SEND_GameEvent(NET_EV_PLAYER_TOUCH
, gPlayers
[a
].FUID
);
4805 FTime
[T_USE
] := gTime
+120;
4808 procedure TPlayer
.NetFire(Wpn
: Byte; X
, Y
, AX
, AY
: Integer; WID
: Integer = -1);
4812 WX
, WY
, XD
, YD
: Integer;
4824 if R_BERSERK
in FRulez
then
4826 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
4827 locobj
.X
:= FObj
.X
+FObj
.Rect
.X
;
4828 locobj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
4831 locobj
.rect
.Width
:= 39;
4832 locobj
.rect
.Height
:= 52;
4833 locobj
.Vel
.X
:= (xd
-wx
) div 2;
4834 locobj
.Vel
.Y
:= (yd
-wy
) div 2;
4835 locobj
.Accel
.X
:= xd
-wx
;
4836 locobj
.Accel
.y
:= yd
-wy
;
4838 if g_Weapon_Hit(@locobj
, 50, FUID
, HIT_SOME
) <> 0 then
4839 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
4841 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
4845 FPain
:= min(FPain
+ 25, 50);
4847 g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
4852 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
4853 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
4855 FSawSoundSelect
.Stop();
4857 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
4859 else if not FSawSoundHit
.IsPlaying() then
4861 FSawSoundSelect
.Stop();
4862 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
4869 g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', GameX
, Gamey
);
4870 FFireAngle
:= FAngle
;
4872 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
4873 GameVelX
, GameVelY
-2, SHELL_BULLET
);
4878 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
4879 FFireAngle
:= FAngle
;
4882 FShellType
:= SHELL_SHELL
;
4887 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN2', Gamex
, Gamey
);
4888 FFireAngle
:= FAngle
;
4891 FShellType
:= SHELL_DBLSHELL
;
4896 g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', Gamex
, Gamey
);
4897 FFireAngle
:= FAngle
;
4899 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
4900 GameVelX
, GameVelY
-2, SHELL_BULLET
);
4903 WEAPON_ROCKETLAUNCHER
:
4905 g_Weapon_Rocket(wx
, wy
, xd
, yd
, FUID
, WID
);
4906 FFireAngle
:= FAngle
;
4912 g_Weapon_Plasma(wx
, wy
, xd
, yd
, FUID
, WID
);
4913 FFireAngle
:= FAngle
;
4919 g_Weapon_BFGShot(wx
, wy
, xd
, yd
, FUID
, WID
);
4920 FFireAngle
:= FAngle
;
4924 WEAPON_SUPERPULEMET
:
4926 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
4927 FFireAngle
:= FAngle
;
4929 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
4930 GameVelX
, GameVelY
-2, SHELL_SHELL
);
4933 WEAPON_FLAMETHROWER
:
4935 g_Weapon_flame(wx
, wy
, xd
, yd
, FUID
, WID
);
4937 FFireAngle
:= FAngle
;
4944 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
4945 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
4946 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
4949 procedure TPlayer
.DoLerp(Level
: Integer = 2);
4951 if FObj
.X
<> FXTo
then FObj
.X
:= Lerp(FObj
.X
, FXTo
, Level
);
4952 if FObj
.Y
<> FYTo
then FObj
.Y
:= Lerp(FObj
.Y
, FYTo
, Level
);
4955 procedure TPlayer
.SetLerp(XTo
, YTo
: Integer);
4961 if FJustTeleported
or (NetInterpLevel
< 1) then
4965 if FJustTeleported
then
4967 FObj
.oldX
:= FObj
.X
;
4968 FObj
.oldY
:= FObj
.Y
;
4973 AX
:= Abs(FXTo
- FObj
.X
);
4974 AY
:= Abs(FYTo
- FObj
.Y
);
4975 if (AX
> 32) or (AX
<= NetInterpLevel
) then
4977 if (AY
> 32) or (AY
<= NetInterpLevel
) then
4982 function TPlayer
.FullInLift(XInc
, YInc
: Integer): Integer;
4984 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
4985 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
4986 PANEL_LIFTUP
, False) then Result
:= -1
4988 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
4989 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
4990 PANEL_LIFTDOWN
, False) then Result
:= 1
4994 function TPlayer
.GetFlag(Flag
: Byte): Boolean;
5001 if Flag
= FLAG_NONE
then
5004 if not g_Game_IsServer
then Exit
;
5006 // Принес чужой флаг на свою базу:
5007 if (Flag
= FTeam
) and
5008 (gFlags
[Flag
].State
= FLAG_STATE_NORMAL
) and
5009 (FFlag
<> FLAG_NONE
) then
5011 if FFlag
= FLAG_RED
then
5012 s
:= _lc
[I_PLAYER_FLAG_RED
]
5014 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5016 evtype
:= FLAG_STATE_SCORED
;
5018 ts
:= Format('%.4d', [gFlags
[FFlag
].CaptureTime
]);
5019 Insert('.', ts
, Length(ts
) + 1 - 3);
5020 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_CAPTURE
], [FName
, s
, ts
]), True);
5022 g_Map_ResetFlag(FFlag
);
5023 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_CAPTURE
], [AnsiUpperCase(s
)]), 144);
5025 if ((Self
= gPlayer1
) or (Self
= gPlayer2
)
5026 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= FTeam
))
5027 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= FTeam
))) then
5032 if not sound_cap_flag
[a
].IsPlaying() then
5033 sound_cap_flag
[a
].Play();
5035 gTeamStat
[FTeam
].Goals
:= gTeamStat
[FTeam
].Goals
+ 1;
5038 if g_Game_IsNet
then
5040 MH_SEND_FlagEvent(evtype
, FFlag
, FUID
, False);
5044 gFlags
[FFlag
].CaptureTime
:= 0;
5049 // Подобрал свой флаг - вернул его на базу:
5050 if (Flag
= FTeam
) and
5051 (gFlags
[Flag
].State
= FLAG_STATE_DROPPED
) then
5053 if Flag
= FLAG_RED
then
5054 s
:= _lc
[I_PLAYER_FLAG_RED
]
5056 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5058 evtype
:= FLAG_STATE_RETURNED
;
5059 gFlags
[Flag
].CaptureTime
:= 0;
5061 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_RETURN
], [FName
, s
]), True);
5063 g_Map_ResetFlag(Flag
);
5064 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
5066 if ((Self
= gPlayer1
) or (Self
= gPlayer2
)
5067 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= FTeam
))
5068 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= FTeam
))) then
5073 if not sound_ret_flag
[a
].IsPlaying() then
5074 sound_ret_flag
[a
].Play();
5077 if g_Game_IsNet
then
5079 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5085 // Подобрал чужой флаг:
5086 if (Flag
<> FTeam
) and (FTime
[T_FLAGCAP
] <= gTime
) then
5090 if Flag
= FLAG_RED
then
5091 s
:= _lc
[I_PLAYER_FLAG_RED
]
5093 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5095 evtype
:= FLAG_STATE_CAPTURED
;
5097 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_GET
], [FName
, s
]), True);
5099 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_GET
], [AnsiUpperCase(s
)]), 144);
5101 gFlags
[Flag
].State
:= FLAG_STATE_CAPTURED
;
5103 if ((Self
= gPlayer1
) or (Self
= gPlayer2
)
5104 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= FTeam
))
5105 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= FTeam
))) then
5110 if not sound_get_flag
[a
].IsPlaying() then
5111 sound_get_flag
[a
].Play();
5114 if g_Game_IsNet
then
5116 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5122 procedure TPlayer
.SetFlag(Flag
: Byte);
5125 if FModel
<> nil then
5126 FModel
.SetFlag(FFlag
);
5129 function TPlayer
.DropFlag(Silent
: Boolean = True): Boolean;
5135 if (not g_Game_IsServer
) or (FFlag
= FLAG_NONE
) then
5137 FTime
[T_FLAGCAP
] := gTime
+ 2000;
5138 with gFlags
[FFlag
] do
5142 Direction
:= FDirection
;
5143 State
:= FLAG_STATE_DROPPED
;
5145 g_Obj_Push(@Obj
, (FObj
.Vel
.X
div 2)-2+Random(5),
5146 (FObj
.Vel
.Y
div 2)-2+Random(5));
5147 positionChanged(); // this updates spatial accelerators
5149 if FFlag
= FLAG_RED
then
5150 s
:= _lc
[I_PLAYER_FLAG_RED
]
5152 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5154 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_DROP
], [FName
, s
]), True);
5155 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_DROP
], [AnsiUpperCase(s
)]), 144);
5157 if ((Self
= gPlayer1
) or (Self
= gPlayer2
)
5158 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= FTeam
))
5159 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= FTeam
))) then
5164 if (not Silent
) and (not sound_lost_flag
[a
].IsPlaying()) then
5165 sound_lost_flag
[a
].Play();
5167 if g_Game_IsNet
then
5168 MH_SEND_FlagEvent(FLAG_STATE_DROPPED
, Flag
, FUID
, False);
5174 procedure TPlayer
.GetSecret();
5176 if (self
= gPlayer1
) or (self
= gPlayer2
) then
5178 g_Console_Add(Format(_lc
[I_PLAYER_SECRET
], [FName
]), True);
5179 g_Sound_PlayEx('SOUND_GAME_SECRET');
5184 procedure TPlayer
.PressKey(Key
: Byte; Time
: Word = 1);
5186 Assert(Key
<= High(FKeys
));
5188 FKeys
[Key
].Pressed
:= True;
5189 FKeys
[Key
].Time
:= Time
;
5192 function TPlayer
.IsKeyPressed(K
: Byte): Boolean;
5194 Result
:= FKeys
[K
].Pressed
;
5197 procedure TPlayer
.ReleaseKeys();
5201 for a
:= Low(FKeys
) to High(FKeys
) do
5203 FKeys
[a
].Pressed
:= False;
5208 procedure TPlayer
.OnDamage(Angle
: SmallInt);
5212 function TPlayer
.firediry(): Integer;
5214 if FKeys
[KEY_UP
].Pressed
then Result
:= -42
5215 else if FKeys
[KEY_DOWN
].Pressed
then Result
:= 19
5219 procedure TPlayer
.RememberState();
5222 SavedState
: TPlayerSavedState
;
5224 SavedState
.Health
:= FHealth
;
5225 SavedState
.Armor
:= FArmor
;
5226 SavedState
.Air
:= FAir
;
5227 SavedState
.JetFuel
:= FJetFuel
;
5228 SavedState
.CurrWeap
:= FCurrWeap
;
5229 SavedState
.NextWeap
:= FNextWeap
;
5230 SavedState
.NextWeapDelay
:= FNextWeapDelay
;
5231 for i
:= Low(FWeapon
) to High(FWeapon
) do
5232 SavedState
.Weapon
[i
] := FWeapon
[i
];
5233 for i
:= Low(FAmmo
) to High(FAmmo
) do
5234 SavedState
.Ammo
[i
] := FAmmo
[i
];
5235 for i
:= Low(FMaxAmmo
) to High(FMaxAmmo
) do
5236 SavedState
.MaxAmmo
[i
] := FMaxAmmo
[i
];
5237 SavedState
.Rulez
:= FRulez
- [R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
];
5239 FSavedStateNum
:= -1;
5240 for i
:= Low(SavedStates
) to High(SavedStates
) do
5241 if not SavedStates
[i
].Used
then
5243 FSavedStateNum
:= i
;
5246 if FSavedStateNum
< 0 then
5248 SetLength(SavedStates
, Length(SavedStates
) + 1);
5249 FSavedStateNum
:= High(SavedStates
);
5252 SavedState
.Used
:= True;
5253 SavedStates
[FSavedStateNum
] := SavedState
;
5256 procedure TPlayer
.RecallState();
5259 SavedState
: TPlayerSavedState
;
5261 if(FSavedStateNum
< 0) or (FSavedStateNum
> High(SavedStates
)) then
5264 SavedState
:= SavedStates
[FSavedStateNum
];
5265 SavedStates
[FSavedStateNum
].Used
:= False;
5266 FSavedStateNum
:= -1;
5268 FHealth
:= SavedState
.Health
;
5269 FArmor
:= SavedState
.Armor
;
5270 FAir
:= SavedState
.Air
;
5271 FJetFuel
:= SavedState
.JetFuel
;
5272 FCurrWeap
:= SavedState
.CurrWeap
;
5273 FNextWeap
:= SavedState
.NextWeap
;
5274 FNextWeapDelay
:= SavedState
.NextWeapDelay
;
5275 for i
:= Low(FWeapon
) to High(FWeapon
) do
5276 FWeapon
[i
] := SavedState
.Weapon
[i
];
5277 for i
:= Low(FAmmo
) to High(FAmmo
) do
5278 FAmmo
[i
] := SavedState
.Ammo
[i
];
5279 for i
:= Low(FMaxAmmo
) to High(FMaxAmmo
) do
5280 FMaxAmmo
[i
] := SavedState
.MaxAmmo
[i
];
5281 FRulez
:= SavedState
.Rulez
;
5283 if gGameSettings
.GameType
= GT_SERVER
then
5284 MH_SEND_PlayerStats(FUID
);
5287 procedure TPlayer
.SaveState (st
: TStream
);
5293 utils
.writeSign(st
, 'PLYR');
5294 utils
.writeInt(st
, Byte(PLR_SAVE_VERSION
)); // version
5296 utils
.writeBool(st
, FIamBot
);
5298 utils
.writeInt(st
, Word(FUID
));
5300 utils
.writeStr(st
, FName
);
5302 utils
.writeInt(st
, Byte(FTeam
));
5304 utils
.writeBool(st
, FAlive
);
5305 // Израсходовал ли все жизни
5306 utils
.writeBool(st
, FNoRespawn
);
5308 if FDirection
= TDirection
.D_LEFT
then b
:= 1 else b
:= 2; // D_RIGHT
5309 utils
.writeInt(st
, Byte(b
));
5311 utils
.writeInt(st
, LongInt(FHealth
));
5312 // Коэффициент инвалидности
5313 utils
.writeInt(st
, LongInt(FHandicap
));
5315 utils
.writeInt(st
, Byte(FLives
));
5317 utils
.writeInt(st
, LongInt(FArmor
));
5319 utils
.writeInt(st
, LongInt(FAir
));
5321 utils
.writeInt(st
, LongInt(FJetFuel
));
5323 utils
.writeInt(st
, LongInt(FPain
));
5325 utils
.writeInt(st
, LongInt(FKills
));
5327 utils
.writeInt(st
, LongInt(FMonsterKills
));
5329 utils
.writeInt(st
, LongInt(FFrags
));
5331 utils
.writeInt(st
, Byte(FFragCombo
));
5332 // Время последнего фрага
5333 utils
.writeInt(st
, LongWord(FLastFrag
));
5335 utils
.writeInt(st
, LongInt(FDeath
));
5337 utils
.writeInt(st
, Byte(FFlag
));
5339 utils
.writeInt(st
, LongInt(FSecrets
));
5341 utils
.writeInt(st
, Byte(FCurrWeap
));
5343 utils
.writeInt(st
, Word(FNextWeap
));
5345 utils
.writeInt(st
, Byte(FNextWeapDelay
));
5346 // Время зарядки BFG
5347 utils
.writeInt(st
, SmallInt(FBFGFireCounter
));
5349 utils
.writeInt(st
, LongInt(FDamageBuffer
));
5350 // Последний ударивший
5351 utils
.writeInt(st
, Word(FLastSpawnerUID
));
5352 // Тип последнего полученного урона
5353 utils
.writeInt(st
, Byte(FLastHit
));
5355 Obj_SaveState(st
, @FObj
);
5356 // Текущее количество патронов
5357 for i
:= A_BULLETS
to A_HIGH
do utils
.writeInt(st
, Word(FAmmo
[i
]));
5358 // Максимальное количество патронов
5359 for i
:= A_BULLETS
to A_HIGH
do utils
.writeInt(st
, Word(FMaxAmmo
[i
]));
5361 for i
:= WP_FIRST
to WP_LAST
do utils
.writeBool(st
, FWeapon
[i
]);
5362 // Время перезарядки оружия
5363 for i
:= WP_FIRST
to WP_LAST
do utils
.writeInt(st
, Word(FReloading
[i
]));
5365 utils
.writeBool(st
, (R_ITEM_BACKPACK
in FRulez
));
5366 // Наличие красного ключа
5367 utils
.writeBool(st
, (R_KEY_RED
in FRulez
));
5368 // Наличие зеленого ключа
5369 utils
.writeBool(st
, (R_KEY_GREEN
in FRulez
));
5370 // Наличие синего ключа
5371 utils
.writeBool(st
, (R_KEY_BLUE
in FRulez
));
5373 utils
.writeBool(st
, (R_BERSERK
in FRulez
));
5374 // Время действия специальных предметов
5375 for i
:= MR_SUIT
to MR_MAX
do utils
.writeInt(st
, LongWord(FMegaRulez
[i
]));
5376 // Время до повторного респауна, смены оружия, исользования, захвата флага
5377 for i
:= T_RESPAWN
to T_FLAGCAP
do utils
.writeInt(st
, LongWord(FTime
[i
]));
5379 utils
.writeStr(st
, FModel
.Name
);
5381 utils
.writeInt(st
, Byte(FColor
.R
));
5382 utils
.writeInt(st
, Byte(FColor
.G
));
5383 utils
.writeInt(st
, Byte(FColor
.B
));
5387 procedure TPlayer
.LoadState (st
: TStream
);
5396 if not utils
.checkSign(st
, 'PLYR') then raise XStreamError
.Create('invalid player signature');
5397 if (utils
.readByte(st
) <> PLR_SAVE_VERSION
) then raise XStreamError
.Create('invalid player version');
5399 FIamBot
:= utils
.readBool(st
);
5401 FUID
:= utils
.readWord(st
);
5403 str
:= utils
.readStr(st
);
5404 if (self
<> gPlayer1
) and (self
<> gPlayer2
) then FName
:= str
;
5406 FTeam
:= utils
.readByte(st
);
5408 FAlive
:= utils
.readBool(st
);
5409 // Израсходовал ли все жизни
5410 FNoRespawn
:= utils
.readBool(st
);
5412 b
:= utils
.readByte(st
);
5413 if b
= 1 then FDirection
:= TDirection
.D_LEFT
else FDirection
:= TDirection
.D_RIGHT
; // b = 2
5415 FHealth
:= utils
.readLongInt(st
);
5416 // Коэффициент инвалидности
5417 FHandicap
:= utils
.readLongInt(st
);
5419 FLives
:= utils
.readByte(st
);
5421 FArmor
:= utils
.readLongInt(st
);
5423 FAir
:= utils
.readLongInt(st
);
5425 FJetFuel
:= utils
.readLongInt(st
);
5427 FPain
:= utils
.readLongInt(st
);
5429 FKills
:= utils
.readLongInt(st
);
5431 FMonsterKills
:= utils
.readLongInt(st
);
5433 FFrags
:= utils
.readLongInt(st
);
5435 FFragCombo
:= utils
.readByte(st
);
5436 // Время последнего фрага
5437 FLastFrag
:= utils
.readLongWord(st
);
5439 FDeath
:= utils
.readLongInt(st
);
5441 FFlag
:= utils
.readByte(st
);
5443 FSecrets
:= utils
.readLongInt(st
);
5445 FCurrWeap
:= utils
.readByte(st
);
5447 FNextWeap
:= utils
.readWord(st
);
5449 FNextWeapDelay
:= utils
.readByte(st
);
5450 // Время зарядки BFG
5451 FBFGFireCounter
:= utils
.readSmallInt(st
);
5453 FDamageBuffer
:= utils
.readLongInt(st
);
5454 // Последний ударивший
5455 FLastSpawnerUID
:= utils
.readWord(st
);
5456 // Тип последнего полученного урона
5457 FLastHit
:= utils
.readByte(st
);
5459 Obj_LoadState(@FObj
, st
);
5460 // Текущее количество патронов
5461 for i
:= A_BULLETS
to A_HIGH
do FAmmo
[i
] := utils
.readWord(st
);
5462 // Максимальное количество патронов
5463 for i
:= A_BULLETS
to A_HIGH
do FMaxAmmo
[i
] := utils
.readWord(st
);
5465 for i
:= WP_FIRST
to WP_LAST
do FWeapon
[i
] := utils
.readBool(st
);
5466 // Время перезарядки оружия
5467 for i
:= WP_FIRST
to WP_LAST
do FReloading
[i
] := utils
.readWord(st
);
5469 if utils
.readBool(st
) then Include(FRulez
, R_ITEM_BACKPACK
);
5470 // Наличие красного ключа
5471 if utils
.readBool(st
) then Include(FRulez
, R_KEY_RED
);
5472 // Наличие зеленого ключа
5473 if utils
.readBool(st
) then Include(FRulez
, R_KEY_GREEN
);
5474 // Наличие синего ключа
5475 if utils
.readBool(st
) then Include(FRulez
, R_KEY_BLUE
);
5477 if utils
.readBool(st
) then Include(FRulez
, R_BERSERK
);
5478 // Время действия специальных предметов
5479 for i
:= MR_SUIT
to MR_MAX
do FMegaRulez
[i
] := utils
.readLongWord(st
);
5480 // Время до повторного респауна, смены оружия, исользования, захвата флага
5481 for i
:= T_RESPAWN
to T_FLAGCAP
do FTime
[i
] := utils
.readLongWord(st
);
5483 str
:= utils
.readStr(st
);
5485 FColor
.R
:= utils
.readByte(st
);
5486 FColor
.G
:= utils
.readByte(st
);
5487 FColor
.B
:= utils
.readByte(st
);
5488 if (self
= gPlayer1
) then
5490 str
:= gPlayer1Settings
.Model
;
5491 FColor
:= gPlayer1Settings
.Color
;
5493 else if (self
= gPlayer2
) then
5495 str
:= gPlayer2Settings
.Model
;
5496 FColor
:= gPlayer2Settings
.Color
;
5498 // Обновляем модель игрока
5500 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
5501 FModel
.Color
:= TEAMCOLOR
[FTeam
]
5503 FModel
.Color
:= FColor
;
5507 procedure TPlayer
.AllRulez(Health
: Boolean);
5513 FHealth
:= PLAYER_HP_LIMIT
;
5514 FArmor
:= PLAYER_AP_LIMIT
;
5518 for a
:= WP_FIRST
to WP_LAST
do FWeapon
[a
] := True;
5519 for a
:= A_BULLETS
to A_HIGH
do FAmmo
[a
] := 30000;
5520 FRulez
:= FRulez
+[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
];
5523 procedure TPlayer
.RestoreHealthArmor();
5525 FHealth
:= PLAYER_HP_LIMIT
;
5526 FArmor
:= PLAYER_AP_LIMIT
;
5529 procedure TPlayer
.FragCombo();
5533 if (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) or g_Game_IsClient
then
5535 if gTime
- FLastFrag
< FRAG_COMBO_TIME
then
5537 if FFragCombo
< 5 then
5539 Param
:= FUID
or (FFragCombo
shl 16);
5540 if (FComboEvnt
>= Low(gDelayedEvents
)) and
5541 (FComboEvnt
<= High(gDelayedEvents
)) and
5542 gDelayedEvents
[FComboEvnt
].Pending
and
5543 (gDelayedEvents
[FComboEvnt
].DEType
= DE_KILLCOMBO
) and
5544 (gDelayedEvents
[FComboEvnt
].DENum
and $FFFF = FUID
) then
5546 gDelayedEvents
[FComboEvnt
].Time
:= gTime
+ 500;
5547 gDelayedEvents
[FComboEvnt
].DENum
:= Param
;
5550 FComboEvnt
:= g_Game_DelayEvent(DE_KILLCOMBO
, 500, Param
);
5558 procedure TPlayer
.GiveItem(ItemType
: Byte);
5562 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
5564 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
5568 if FAir
< AIR_MAX
then
5575 if not (R_BERSERK
in FRulez
) then
5577 Include(FRulez
, R_BERSERK
);
5578 if FBFGFireCounter
< 1 then
5580 FCurrWeap
:= WEAPON_KASTET
;
5582 FModel
.SetWeapon(WEAPON_KASTET
);
5586 FBerserk
:= gTime
+30000;
5588 if FHealth
< PLAYER_HP_SOFT
then
5590 FHealth
:= PLAYER_HP_SOFT
;
5591 FBerserk
:= gTime
+30000;
5596 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
5598 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
5603 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
5605 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
5609 if FJetFuel
< JET_MAX
then
5611 FJetFuel
:= JET_MAX
;
5614 ITEM_MEDKIT_SMALL
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
5615 ITEM_MEDKIT_LARGE
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
5617 ITEM_ARMOR_GREEN
: if FArmor
< PLAYER_AP_SOFT
then FArmor
:= PLAYER_AP_SOFT
;
5618 ITEM_ARMOR_BLUE
: if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
5620 ITEM_SPHERE_BLUE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
5622 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) then
5624 if FHealth
< PLAYER_HP_LIMIT
then FHealth
:= PLAYER_HP_LIMIT
;
5625 if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
5628 ITEM_WEAPON_SAW
: FWeapon
[WEAPON_SAW
] := True;
5629 ITEM_WEAPON_SHOTGUN1
: FWeapon
[WEAPON_SHOTGUN1
] := True;
5630 ITEM_WEAPON_SHOTGUN2
: FWeapon
[WEAPON_SHOTGUN2
] := True;
5631 ITEM_WEAPON_CHAINGUN
: FWeapon
[WEAPON_CHAINGUN
] := True;
5632 ITEM_WEAPON_ROCKETLAUNCHER
: FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
5633 ITEM_WEAPON_PLASMA
: FWeapon
[WEAPON_PLASMA
] := True;
5634 ITEM_WEAPON_BFG
: FWeapon
[WEAPON_BFG
] := True;
5635 ITEM_WEAPON_SUPERPULEMET
: FWeapon
[WEAPON_SUPERPULEMET
] := True;
5636 ITEM_WEAPON_FLAMETHROWER
: FWeapon
[WEAPON_FLAMETHROWER
] := True;
5638 ITEM_AMMO_BULLETS
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
5639 ITEM_AMMO_BULLETS_BOX
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
5640 ITEM_AMMO_SHELLS
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
5641 ITEM_AMMO_SHELLS_BOX
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
5642 ITEM_AMMO_ROCKET
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
5643 ITEM_AMMO_ROCKET_BOX
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
5644 ITEM_AMMO_CELL
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
5645 ITEM_AMMO_CELL_BIG
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
5646 ITEM_AMMO_FUELCAN
: if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
5649 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
5650 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
5651 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
5652 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or
5653 (FMaxAmmo
[A_FUEL
] < AmmoLimits
[1, A_FUEL
]) then
5655 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[1, A_BULLETS
];
5656 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[1, A_SHELLS
];
5657 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[1, A_ROCKETS
];
5658 FMaxAmmo
[A_CELLS
] := AmmoLimits
[1, A_CELLS
];
5659 FMaxAmmo
[A_FUEL
] := AmmoLimits
[1, A_FUEL
];
5661 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
5662 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
5663 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
5664 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
5666 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
5669 ITEM_KEY_RED
: if not (R_KEY_RED
in FRulez
) then Include(FRulez
, R_KEY_RED
);
5670 ITEM_KEY_GREEN
: if not (R_KEY_GREEN
in FRulez
) then Include(FRulez
, R_KEY_GREEN
);
5671 ITEM_KEY_BLUE
: if not (R_KEY_BLUE
in FRulez
) then Include(FRulez
, R_KEY_BLUE
);
5673 ITEM_BOTTLE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
5674 ITEM_HELMET
: if FArmor
< PLAYER_AP_LIMIT
then IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
5679 if g_Game_IsNet
and g_Game_IsServer
then
5680 MH_SEND_PlayerStats(FUID
);
5683 procedure TPlayer
.FlySmoke(Times
: DWORD
= 1);
5688 if (Random(5) = 1) and (Times
= 1) then
5691 if BodyInLiquid(0, 0) then
5693 g_GFX_Bubbles(Obj
.X
+Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2)+Random(3)-1,
5694 Obj
.Y
+Obj
.Rect
.Height
+8, 1, 8, 4);
5695 if Random(2) = 0 then
5696 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
5698 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
5702 if g_Frames_Get(id
, 'FRAMES_SMOKE') then
5704 for i
:= 1 to Times
do
5706 Anim
:= TAnimation
.Create(id
, False, 3);
5708 g_GFX_OnceAnim(Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(Anim
.Width
div 2),
5709 Obj
.Y
+Obj
.Rect
.Height
-4+Random(8+Times
*2), Anim
, ONCEANIM_SMOKE
);
5715 procedure TPlayer
.OnFireFlame(Times
: DWORD
= 1);
5720 if (Random(10) = 1) and (Times
= 1) then
5723 if g_Frames_Get(id
, 'FRAMES_FLAME') then
5725 for i
:= 1 to Times
do
5727 Anim
:= TAnimation
.Create(id
, False, 3);
5729 g_GFX_OnceAnim(Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(Anim
.Width
div 2),
5730 Obj
.Y
+8+Random(8+Times
*2), Anim
, ONCEANIM_SMOKE
);
5736 procedure TPlayer
.PauseSounds(Enable
: Boolean);
5738 FSawSound
.Pause(Enable
);
5739 FSawSoundIdle
.Pause(Enable
);
5740 FSawSoundHit
.Pause(Enable
);
5741 FSawSoundSelect
.Pause(Enable
);
5742 FFlameSoundOn
.Pause(Enable
);
5743 FFlameSoundOff
.Pause(Enable
);
5744 FFlameSoundWork
.Pause(Enable
);
5745 FJetSoundFly
.Pause(Enable
);
5746 FJetSoundOn
.Pause(Enable
);
5747 FJetSoundOff
.Pause(Enable
);
5752 constructor TCorpse
.Create(X
, Y
: Integer; ModelName
: String; aMess
: Boolean);
5757 FObj
.Rect
:= PLAYER_CORPSERECT
;
5758 FModelName
:= ModelName
;
5763 FState
:= CORPSE_STATE_MESS
;
5764 g_PlayerModel_GetAnim(ModelName
, A_DIE2
, FAnimation
, FAnimationMask
);
5768 FState
:= CORPSE_STATE_NORMAL
;
5769 g_PlayerModel_GetAnim(ModelName
, A_DIE1
, FAnimation
, FAnimationMask
);
5773 destructor TCorpse
.Destroy();
5780 function TCorpse
.ObjPtr (): PObj
; inline; begin result
:= @FObj
; end;
5782 procedure TCorpse
.positionChanged (); inline; begin end;
5784 procedure TCorpse
.moveBy (dx
, dy
: Integer); inline;
5786 if (dx
<> 0) or (dy
<> 0) then
5795 procedure TCorpse
.getMapBox (out x
, y
, w
, h
: Integer); inline;
5797 x
:= FObj
.X
+PLAYER_CORPSERECT
.X
;
5798 y
:= FObj
.Y
+PLAYER_CORPSERECT
.Y
;
5799 w
:= PLAYER_CORPSERECT
.Width
;
5800 h
:= PLAYER_CORPSERECT
.Height
;
5804 procedure TCorpse
.Damage(Value
: Word; SpawnerUID
: Word; vx
, vy
: Integer);
5809 if FState
= CORPSE_STATE_REMOVEME
then
5812 FDamage
:= FDamage
+ Value
;
5814 if FDamage
> 150 then
5816 if FAnimation
<> nil then
5821 FState
:= CORPSE_STATE_REMOVEME
;
5823 g_Player_CreateGibs(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
5824 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2),
5825 FModelName
, FColor
);
5826 // Звук мяса от трупа:
5827 pm
:= g_PlayerModel_Get(FModelName
);
5828 pm
.PlaySound(MODELSOUND_DIE
, 5, FObj
.X
, FObj
.Y
);
5832 if (gBodyKillEvent
<> -1)
5833 and gDelayedEvents
[gBodyKillEvent
].Pending
then
5834 gDelayedEvents
[gBodyKillEvent
].Pending
:= False;
5835 gBodyKillEvent
:= g_Game_DelayEvent(DE_BODYKILL
, 1050, SpawnerUID
);
5840 Blood
:= g_PlayerModel_GetBlood(FModelName
);
5841 FObj
.Vel
.X
:= FObj
.Vel
.X
+ vx
;
5842 FObj
.Vel
.Y
:= FObj
.Vel
.Y
+ vy
;
5843 g_GFX_Blood(FObj
.X
+PLAYER_CORPSERECT
.X
+(PLAYER_CORPSERECT
.Width
div 2),
5844 FObj
.Y
+PLAYER_CORPSERECT
.Y
+(PLAYER_CORPSERECT
.Height
div 2),
5845 Value
, vx
, vy
, 16, (PLAYER_CORPSERECT
.Height
*2) div 3,
5846 Blood
.R
, Blood
.G
, Blood
.B
, Blood
.Kind
);
5850 procedure TCorpse
.Update();
5854 if FState
= CORPSE_STATE_REMOVEME
then
5857 FObj
.oldX
:= FObj
.X
;
5858 FObj
.oldY
:= FObj
.Y
;
5860 if gTime
mod (GAME_TICK
*2) <> 0 then
5862 g_Obj_Move(@FObj
, True, True, True);
5863 positionChanged(); // this updates spatial accelerators
5867 // Сопротивление воздуха для трупа:
5868 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
5870 st
:= g_Obj_Move(@FObj
, True, True, True);
5871 positionChanged(); // this updates spatial accelerators
5873 if WordBool(st
and MOVE_FALLOUT
) then
5875 FState
:= CORPSE_STATE_REMOVEME
;
5879 if FAnimation
<> nil then
5880 FAnimation
.Update();
5881 if FAnimationMask
<> nil then
5882 FAnimationMask
.Update();
5886 procedure TCorpse
.SaveState (st
: TStream
);
5893 utils
.writeSign(st
, 'CORP');
5894 utils
.writeInt(st
, Byte(0));
5896 utils
.writeInt(st
, Byte(FState
));
5898 utils
.writeInt(st
, Byte(FDamage
));
5900 utils
.writeInt(st
, Byte(FColor
.R
));
5901 utils
.writeInt(st
, Byte(FColor
.G
));
5902 utils
.writeInt(st
, Byte(FColor
.B
));
5904 Obj_SaveState(st
, @FObj
);
5905 utils
.writeInt(st
, Word(FPlayerUID
));
5907 anim
:= (FAnimation
<> nil);
5908 utils
.writeBool(st
, anim
);
5909 // Если есть - сохраняем
5910 if anim
then FAnimation
.SaveState(st
);
5911 // Есть ли маска анимации
5912 anim
:= (FAnimationMask
<> nil);
5913 utils
.writeBool(st
, anim
);
5914 // Если есть - сохраняем
5915 if anim
then FAnimationMask
.SaveState(st
);
5919 procedure TCorpse
.LoadState (st
: TStream
);
5926 if not utils
.checkSign(st
, 'CORP') then raise XStreamError
.Create('invalid corpse signature');
5927 if (utils
.readByte(st
) <> 0) then raise XStreamError
.Create('invalid corpse version');
5929 FState
:= utils
.readByte(st
);
5931 FDamage
:= utils
.readByte(st
);
5933 FColor
.R
:= utils
.readByte(st
);
5934 FColor
.G
:= utils
.readByte(st
);
5935 FColor
.B
:= utils
.readByte(st
);
5937 Obj_LoadState(@FObj
, st
);
5938 FPlayerUID
:= utils
.readWord(st
);
5940 anim
:= utils
.readBool(st
);
5941 // Если есть - загружаем
5944 Assert(FAnimation
<> nil, 'TCorpse.LoadState: no FAnimation');
5945 FAnimation
.LoadState(st
);
5947 // Есть ли маска анимации
5948 anim
:= utils
.readBool(st
);
5949 // Если есть - загружаем
5952 Assert(FAnimationMask
<> nil, 'TCorpse.LoadState: no FAnimationMask');
5953 FAnimationMask
.LoadState(st
);
5959 constructor TBot
.Create();
5966 FSpectator
:= False;
5973 for a
:= WP_FIRST
to WP_LAST
do
5975 FDifficult
.WeaponPrior
[a
] := WEAPON_PRIOR1
[a
];
5976 FDifficult
.CloseWeaponPrior
[a
] := WEAPON_PRIOR2
[a
];
5977 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
5981 destructor TBot
.Destroy();
5984 inherited Destroy();
5987 procedure TBot
.Respawn(Silent
: Boolean; Force
: Boolean = False);
5989 inherited Respawn(Silent
, Force
);
5992 FSelectedWeapon
:= FCurrWeap
;
5997 procedure TBot
.UpdateCombat();
6010 TTargetRecord
= array of TTarget
;
6012 function Compare(a
, b
: TTarget
): Integer;
6014 if a
.Line
and not b
.Line
then // A на линии огня
6017 if not a
.Line
and b
.Line
then // B на линии огня
6019 else // И A, и B на линии или не на линии огня
6020 if (a
.Line
and b
.Line
) or ((not a
.Line
) and (not b
.Line
)) then
6022 if a
.Dist
> b
.Dist
then // B ближе
6024 else // A ближе или равноудаленно с B
6027 else // Странно -> A
6032 a
, x1
, y1
, x2
, y2
: Integer;
6033 targets
: TTargetRecord
;
6035 Target
, BestTarget
: TTarget
;
6036 firew
, fireh
: Integer;
6040 vsPlayer
, vsMonster
, ok
: Boolean;
6043 function monsUpdate (mon
: TMonster
): Boolean;
6045 result
:= false; // don't stop
6046 if mon
.alive
and (mon
.MonsterType
<> MONSTER_BARREL
) then
6048 if not TargetOnScreen(mon
.Obj
.X
+mon
.Obj
.Rect
.X
, mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
) then exit
;
6050 x2
:= mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2);
6051 y2
:= mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+(mon
.Obj
.Rect
.Height
div 2);
6053 // Если монстр на экране и не прикрыт стеной
6054 if g_TraceVector(x1
, y1
, x2
, y2
) then
6056 // Добавляем к списку возможных целей
6057 SetLength(targets
, Length(targets
)+1);
6058 with targets
[High(targets
)] do
6065 Rect
:= mon
.Obj
.Rect
;
6066 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6067 Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6068 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6077 vsPlayer
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
);
6078 vsMonster
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
);
6080 // Если текущее оружие не то, что нужно, то меняем:
6081 if FCurrWeap
<> FSelectedWeapon
then
6084 // Если нужно стрелять и нужное оружие, то нажать "Стрелять":
6085 if (GetAIFlag('NEEDFIRE') <> '') and (FCurrWeap
= FSelectedWeapon
) then
6087 RemoveAIFlag('NEEDFIRE');
6090 WEAPON_PLASMA
, WEAPON_SUPERPULEMET
, WEAPON_CHAINGUN
: PressKey(KEY_FIRE
, 20);
6091 WEAPON_SAW
, WEAPON_KASTET
, WEAPON_FLAMETHROWER
: PressKey(KEY_FIRE
, 40);
6092 else PressKey(KEY_FIRE
);
6096 // Координаты ствола:
6097 x1
:= FObj
.X
+ WEAPONPOINT
[FDirection
].X
;
6098 y1
:= FObj
.Y
+ WEAPONPOINT
[FDirection
].Y
;
6100 Target
.UID
:= FTargetUID
;
6103 if Target
.UID
<> 0 then
6104 begin // Цель есть - настраиваем
6105 if (g_GetUIDType(Target
.UID
) = UID_PLAYER
) and
6108 tpla
:= g_Player_Get(Target
.UID
);
6112 if (@FObj
) <> nil then
6119 Target
.cX
:= Target
.X
+ PLAYER_RECT_CX
;
6120 Target
.cY
:= Target
.Y
+ PLAYER_RECT_CY
;
6121 Target
.Rect
:= PLAYER_RECT
;
6122 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6123 Target
.Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6124 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6125 Target
.IsPlayer
:= True;
6129 if (g_GetUIDType(Target
.UID
) = UID_MONSTER
) and
6132 mon
:= g_Monsters_ByUID(Target
.UID
);
6135 Target
.X
:= mon
.Obj
.X
;
6136 Target
.Y
:= mon
.Obj
.Y
;
6138 Target
.cX
:= Target
.X
+ mon
.Obj
.Rect
.X
+ (mon
.Obj
.Rect
.Width
div 2);
6139 Target
.cY
:= Target
.Y
+ mon
.Obj
.Rect
.Y
+ (mon
.Obj
.Rect
.Height
div 2);
6140 Target
.Rect
:= mon
.Obj
.Rect
;
6141 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6142 Target
.Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6143 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6144 Target
.IsPlayer
:= False;
6151 begin // Цели нет - обнуляем
6156 Target
.Visible
:= False;
6157 Target
.Line
:= False;
6158 Target
.IsPlayer
:= False;
6163 // Если цель не видима или не на линии огня, то ищем все возможные цели:
6164 if (not Target
.Line
) or (not Target
.Visible
) then
6168 for a
:= 0 to High(gPlayers
) do
6169 if (gPlayers
[a
] <> nil) and (gPlayers
[a
].alive
) and
6170 (gPlayers
[a
].FUID
<> FUID
) and
6171 (not SameTeam(FUID
, gPlayers
[a
].FUID
)) and
6172 (not gPlayers
[a
].NoTarget
) and
6173 (gPlayers
[a
].FMegaRulez
[MR_INVIS
] < gTime
) then
6175 if not TargetOnScreen(gPlayers
[a
].FObj
.X
+ PLAYER_RECT
.X
,
6176 gPlayers
[a
].FObj
.Y
+ PLAYER_RECT
.Y
) then
6179 x2
:= gPlayers
[a
].FObj
.X
+ PLAYER_RECT_CX
;
6180 y2
:= gPlayers
[a
].FObj
.Y
+ PLAYER_RECT_CY
;
6182 // Если игрок на экране и не прикрыт стеной:
6183 if g_TraceVector(x1
, y1
, x2
, y2
) then
6185 // Добавляем к списку возможных целей:
6186 SetLength(targets
, Length(targets
)+1);
6187 with targets
[High(targets
)] do
6189 UID
:= gPlayers
[a
].FUID
;
6190 X
:= gPlayers
[a
].FObj
.X
;
6191 Y
:= gPlayers
[a
].FObj
.Y
;
6194 Rect
:= PLAYER_RECT
;
6195 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6196 Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6197 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6205 if vsMonster
then g_Mons_ForEach(monsUpdate
);
6208 // Если есть возможные цели:
6209 // (Выбираем лучшую, меняем оружие и бежим к ней/от нее)
6210 if targets
<> nil then
6212 // Выбираем наилучшую цель:
6213 BestTarget
:= targets
[0];
6214 if Length(targets
) > 1 then
6215 for a
:= 1 to High(targets
) do
6216 if Compare(BestTarget
, targets
[a
]) = 1 then
6217 BestTarget
:= targets
[a
];
6219 // Если лучшая цель "виднее" текущей, то текущая := лучшая:
6220 if ((not Target
.Visible
) and BestTarget
.Visible
and (Target
.UID
<> BestTarget
.UID
)) or
6221 ((not Target
.Line
) and BestTarget
.Line
and BestTarget
.Visible
) then
6223 Target
:= BestTarget
;
6225 if (Healthy() = 3) or ((Healthy() = 2)) then
6226 begin // Если здоровы - догоняем
6227 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
6228 SetAIFlag('GORIGHT', '1');
6229 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6230 SetAIFlag('GOLEFT', '1');
6233 begin // Если побиты - убегаем
6234 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) then
6235 SetAIFlag('GORIGHT', '1');
6236 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6237 SetAIFlag('GOLEFT', '1');
6240 // Выбираем оружие на основе расстояния и приоритетов:
6241 SelectWeapon(Abs(x1
-Target
.cX
));
6246 // (Догоняем/убегаем, стреляем по направлению к цели)
6247 // (Если цель далеко, то хватит следить за ней)
6248 if Target
.UID
<> 0 then
6250 if not TargetOnScreen(Target
.X
+ Target
.Rect
.X
,
6251 Target
.Y
+ Target
.Rect
.Y
) then
6252 begin // Цель сбежала с "экрана"
6253 if (Healthy() = 3) or ((Healthy() = 2)) then
6254 begin // Если здоровы - догоняем
6255 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
6256 SetAIFlag('GORIGHT', '1');
6257 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6258 SetAIFlag('GOLEFT', '1');
6261 begin // Если побиты - забываем о цели и убегаем
6263 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) then
6264 SetAIFlag('GORIGHT', '1');
6265 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6266 SetAIFlag('GOLEFT', '1');
6270 begin // Цель пока на "экране"
6271 // Если цель не загорожена стеной, то отмечаем, когда ее видели:
6272 if g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6273 FLastVisible
:= gTime
;
6274 // Если разница высот не велика, то догоняем:
6275 if (Abs(FObj
.Y
-Target
.Y
) <= 128) then
6277 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
6278 SetAIFlag('GORIGHT', '1');
6279 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6280 SetAIFlag('GOLEFT', '1');
6284 // Выбираем угол вверх:
6285 if FDirection
= TDirection
.D_LEFT
then
6286 angle
:= ANGLE_LEFTUP
6288 angle
:= ANGLE_RIGHTUP
;
6290 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6291 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6293 // Если при угле вверх можно попасть в приблизительное положение цели:
6294 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6295 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128), //96
6296 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6297 Target
.Rect
.Width
, Target
.Rect
.Height
) and
6298 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6299 begin // то нужно стрелять вверх
6300 SetAIFlag('NEEDFIRE', '1');
6301 SetAIFlag('NEEDSEEUP', '1');
6304 // Выбираем угол вниз:
6305 if FDirection
= TDirection
.D_LEFT
then
6306 angle
:= ANGLE_LEFTDOWN
6308 angle
:= ANGLE_RIGHTDOWN
;
6310 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6311 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6313 // Если при угле вниз можно попасть в приблизительное положение цели:
6314 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6315 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
6316 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6317 Target
.Rect
.Width
, Target
.Rect
.Height
) and
6318 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6319 begin // то нужно стрелять вниз
6320 SetAIFlag('NEEDFIRE', '1');
6321 SetAIFlag('NEEDSEEDOWN', '1');
6324 // Если цель видно и она на такой же высоте:
6325 if Target
.Visible
and
6326 (y1
+4 < Target
.Y
+Target
.Rect
.Y
+Target
.Rect
.Height
) and
6327 (y1
-4 > Target
.Y
+Target
.Rect
.Y
) then
6329 // Если идем в сторону цели, то надо стрелять:
6330 if ((FDirection
= TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) or
6331 ((FDirection
= TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6332 begin // то нужно стрелять вперед
6333 SetAIFlag('NEEDFIRE', '1');
6334 SetAIFlag('NEEDSEEDOWN', '');
6335 SetAIFlag('NEEDSEEUP', '');
6337 // Если цель в пределах "экрана" и сложность позволяет прыжки сближения:
6338 if Abs(FObj
.X
-Target
.X
) < Trunc(gPlayerScreenSize
.X
*0.75) then
6339 if GetRnd(FDifficult
.CloseJump
) then
6340 begin // то если повезет - прыгаем (особенно, если близко)
6341 if Abs(FObj
.X
-Target
.X
) < 128 then
6345 if Random(a
) = 0 then
6346 SetAIFlag('NEEDJUMP', '1');
6350 // Если цель все еще есть:
6351 if Target
.UID
<> 0 then
6352 if gTime
-FLastVisible
> 2000 then // Если видели давно
6353 Target
.UID
:= 0 // то забыть цель
6354 else // Если видели недавно
6355 begin // но цель убили
6356 if Target
.IsPlayer
then
6357 begin // Цель - игрок
6358 pla
:= g_Player_Get(Target
.UID
);
6359 if (pla
= nil) or (not pla
.alive
) or pla
.NoTarget
or
6360 (pla
.FMegaRulez
[MR_INVIS
] >= gTime
) then
6361 Target
.UID
:= 0; // то забыть цель
6364 begin // Цель - монстр
6365 mon
:= g_Monsters_ByUID(Target
.UID
);
6366 if (mon
= nil) or (not mon
.alive
) then
6367 Target
.UID
:= 0; // то забыть цель
6370 end; // if Target.UID <> 0
6372 FTargetUID
:= Target
.UID
;
6374 // Если возможных целей нет:
6375 // (Атака чего-нибудь слева или справа)
6376 if targets
= nil then
6377 if GetAIFlag('ATTACKLEFT') <> '' then
6378 begin // Если нужно атаковать налево
6379 RemoveAIFlag('ATTACKLEFT');
6381 SetAIFlag('NEEDJUMP', '1');
6383 if RunDirection() = TDirection
.D_RIGHT
then
6384 begin // Идем не в ту сторону
6385 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
6386 begin // Если здоровы, то, возможно, стреляем бежим влево и стреляем
6387 SetAIFlag('NEEDFIRE', '1');
6388 SetAIFlag('GOLEFT', '1');
6392 begin // Идем в нужную сторону
6393 if GetRnd(FDifficult
.InvisFire
) then // Возможно, стреляем вслепую
6394 SetAIFlag('NEEDFIRE', '1');
6395 if Healthy() <= 1 then // Побиты - убегаем
6396 SetAIFlag('GORIGHT', '1');
6400 if GetAIFlag('ATTACKRIGHT') <> '' then
6401 begin // Если нужно атаковать направо
6402 RemoveAIFlag('ATTACKRIGHT');
6404 SetAIFlag('NEEDJUMP', '1');
6406 if RunDirection() = TDirection
.D_LEFT
then
6407 begin // Идем не в ту сторону
6408 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
6409 begin // Если здоровы, то, возможно, бежим вправо и стреляем
6410 SetAIFlag('NEEDFIRE', '1');
6411 SetAIFlag('GORIGHT', '1');
6416 if GetRnd(FDifficult
.InvisFire
) then // Возможно, стреляем вслепую
6417 SetAIFlag('NEEDFIRE', '1');
6418 if Healthy() <= 1 then // Побиты - убегаем
6419 SetAIFlag('GOLEFT', '1');
6423 //HACK! (does it belongs there?)
6424 RealizeCurrentWeapon();
6426 // Если есть возможные цели:
6427 // (Стреляем по направлению к целям)
6428 if (targets
<> nil) and (GetAIFlag('NEEDFIRE') <> '') then
6429 for a
:= 0 to High(targets
) do
6431 // Если можем стрелять по диагонали:
6432 if GetRnd(FDifficult
.DiagFire
) then
6434 // Ищем цель сверху и стреляем, если есть:
6435 if FDirection
= TDirection
.D_LEFT
then
6436 angle
:= ANGLE_LEFTUP
6438 angle
:= ANGLE_RIGHTUP
;
6440 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6441 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6443 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6444 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
6445 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6446 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
6447 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
6449 SetAIFlag('NEEDFIRE', '1');
6450 SetAIFlag('NEEDSEEUP', '1');
6453 // Ищем цель снизу и стреляем, если есть:
6454 if FDirection
= TDirection
.D_LEFT
then
6455 angle
:= ANGLE_LEFTDOWN
6457 angle
:= ANGLE_RIGHTDOWN
;
6459 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6460 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6462 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6463 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
6464 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6465 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
6466 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
6468 SetAIFlag('NEEDFIRE', '1');
6469 SetAIFlag('NEEDSEEDOWN', '1');
6473 // Если цель "перед носом", то стреляем:
6474 if targets
[a
].Line
and targets
[a
].Visible
and
6475 (((FDirection
= TDirection
.D_LEFT
) and (targets
[a
].X
< FObj
.X
)) or
6476 ((FDirection
= TDirection
.D_RIGHT
) and (targets
[a
].X
> FObj
.X
))) then
6478 SetAIFlag('NEEDFIRE', '1');
6483 // Если летит пуля, то, возможно, подпрыгиваем:
6484 if g_Weapon_Danger(FUID
, FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
,
6485 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
,
6486 40+GetInterval(FDifficult
.Cover
, 40)) then
6487 SetAIFlag('NEEDJUMP', '1');
6489 // Если кончились паторны, то нужно сменить оружие:
6490 ammo
:= GetAmmoByWeapon(FCurrWeap
);
6491 if ((FCurrWeap
= WEAPON_SHOTGUN2
) and (ammo
< 2)) or
6492 ((FCurrWeap
= WEAPON_BFG
) and (ammo
< 40)) or
6494 SetAIFlag('SELECTWEAPON', '1');
6496 // Если нужно сменить оружие, то выбираем нужное:
6497 if GetAIFlag('SELECTWEAPON') = '1' then
6500 RemoveAIFlag('SELECTWEAPON');
6504 procedure TBot
.Update();
6517 // Проверяем, отключён ли AI ботов
6518 if (g_debug_BotAIOff
= 1) and (Team
= TEAM_RED
) then
6520 if (g_debug_BotAIOff
= 2) and (Team
= TEAM_BLUE
) then
6522 if g_debug_BotAIOff
= 3 then
6532 RealizeCurrentWeapon();
6539 procedure TBot
.ReleaseKey(Key
: Byte);
6548 function TBot
.KeyPressed(Key
: Word): Boolean;
6550 Result
:= FKeys
[Key
].Pressed
;
6553 function TBot
.GetAIFlag(aName
: String20
): String20
;
6559 aName
:= LowerCase(aName
);
6561 if FAIFlags
<> nil then
6562 for a
:= 0 to High(FAIFlags
) do
6563 if LowerCase(FAIFlags
[a
].Name
) = aName
then
6565 Result
:= FAIFlags
[a
].Value
;
6570 procedure TBot
.RemoveAIFlag(aName
: String20
);
6574 if FAIFlags
= nil then Exit
;
6576 aName
:= LowerCase(aName
);
6578 for a
:= 0 to High(FAIFlags
) do
6579 if LowerCase(FAIFlags
[a
].Name
) = aName
then
6581 if a
<> High(FAIFlags
) then
6582 for b
:= a
to High(FAIFlags
)-1 do
6583 FAIFlags
[b
] := FAIFlags
[b
+1];
6585 SetLength(FAIFlags
, Length(FAIFlags
)-1);
6590 procedure TBot
.SetAIFlag(aName
, fValue
: String20
);
6598 aName
:= LowerCase(aName
);
6600 if FAIFlags
<> nil then
6601 for a
:= 0 to High(FAIFlags
) do
6602 if LowerCase(FAIFlags
[a
].Name
) = aName
then
6608 if ok
then FAIFlags
[a
].Value
:= fValue
6611 SetLength(FAIFlags
, Length(FAIFlags
)+1);
6612 with FAIFlags
[High(FAIFlags
)] do
6620 procedure TBot
.UpdateMove
;
6622 procedure GoLeft(Time
: Word = 1);
6624 ReleaseKey(KEY_LEFT
);
6625 ReleaseKey(KEY_RIGHT
);
6626 PressKey(KEY_LEFT
, Time
);
6627 SetDirection(TDirection
.D_LEFT
);
6630 procedure GoRight(Time
: Word = 1);
6632 ReleaseKey(KEY_LEFT
);
6633 ReleaseKey(KEY_RIGHT
);
6634 PressKey(KEY_RIGHT
, Time
);
6635 SetDirection(TDirection
.D_RIGHT
);
6638 function Rnd(a
: Word): Boolean;
6640 Result
:= Random(a
) = 0;
6643 procedure Turn(Time
: Word = 1200);
6645 if RunDirection() = TDirection
.D_LEFT
then GoRight(Time
) else GoLeft(Time
);
6650 ReleaseKey(KEY_LEFT
);
6651 ReleaseKey(KEY_RIGHT
);
6654 function CanRunLeft(): Boolean;
6656 Result
:= not CollideLevel(-1, 0);
6659 function CanRunRight(): Boolean;
6661 Result
:= not CollideLevel(1, 0);
6664 function CanRun(): Boolean;
6666 if RunDirection() = TDirection
.D_LEFT
then Result
:= CanRunLeft() else Result
:= CanRunRight();
6669 procedure Jump(Time
: Word = 30);
6671 PressKey(KEY_JUMP
, Time
);
6674 function NearHole(): Boolean;
6678 { TODO 5 : Лестницы }
6679 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
6680 for x
:= 1 to PLAYER_RECT
.Width
do
6681 if (not StayOnStep(x
*sx
, 0)) and
6682 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
6683 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
6692 function BorderHole(): Boolean;
6696 { TODO 5 : Лестницы }
6697 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
6698 for x
:= 1 to PLAYER_RECT
.Width
do
6699 if (not StayOnStep(x
*sx
, 0)) and
6700 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
6701 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
6703 for xx
:= x
to x
+32 do
6704 if CollideLevel(xx
*sx
, PLAYER_RECT
.Height
) then
6714 function NearDeepHole(): Boolean;
6720 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
6723 for x
:= 1 to PLAYER_RECT
.Width
do
6724 if (not StayOnStep(x
*sx
, 0)) and
6725 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
6726 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
6728 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
6730 if CollideLevel(x
*sx
, PLAYER_RECT
.Height
*y
) then Exit
;
6735 end else Result
:= False;
6738 function OverDeepHole(): Boolean;
6745 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
6747 if CollideLevel(0, PLAYER_RECT
.Height
*y
) then Exit
;
6754 function OnGround(): Boolean;
6756 Result
:= StayOnStep(0, 0) or CollideLevel(0, 1);
6759 function OnLadder(): Boolean;
6761 Result
:= FullInStep(0, 0);
6764 function BelowLadder(): Boolean;
6766 Result
:= (FullInStep(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) and
6767 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
6768 (FullInStep(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) and
6769 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
6772 function BelowLiftUp(): Boolean;
6774 Result
:= ((FullInLift(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) = -1) and
6775 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
6776 ((FullInLift(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) = -1) and
6777 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
6780 function OnTopLift(): Boolean;
6782 Result
:= (FullInLift(0, 0) = -1) and (FullInLift(0, -32) = 0);
6785 function CanJumpOver(): Boolean;
6789 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
6793 if not CollideLevel(sx
, 0) then Exit
;
6795 for y
:= 1 to BOT_MAXJUMP
do
6796 if CollideLevel(0, -y
) then Exit
else
6797 if not CollideLevel(sx
, -y
) then
6804 function CanJumpUp(Dist
: ShortInt): Boolean;
6811 if CollideLevel(Dist
, 0) then Exit
;
6814 for y
:= 0 to BOT_MAXJUMP
do
6815 if CollideLevel(Dist
, -y
) then
6824 for yy
:= y
+1 to BOT_MAXJUMP
do
6825 if not CollideLevel(Dist
, -yy
) then
6834 for y
:= 0 to BOT_MAXJUMP
do
6835 if CollideLevel(0, -y
) then
6843 if y
< yy
then Exit
;
6848 function IsSafeTrigger(): Boolean;
6853 if gTriggers
= nil then
6855 for a
:= 0 to High(gTriggers
) do
6856 if Collide(gTriggers
[a
].X
,
6859 gTriggers
[a
].Height
) and
6860 (gTriggers
[a
].TriggerType
in [TRIGGER_EXIT
, TRIGGER_CLOSEDOOR
,
6861 TRIGGER_CLOSETRAP
, TRIGGER_TRAP
,
6862 TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
,
6863 TRIGGER_ONOFF
, TRIGGER_SPAWNMONSTER
,
6864 TRIGGER_DAMAGE
, TRIGGER_SHOT
]) then
6869 // Возможно, нажимаем кнопку:
6870 if Rnd(16) and IsSafeTrigger() then
6873 // Если под лифтом или ступеньками, то, возможно, прыгаем:
6874 if OnLadder() or ((BelowLadder() or BelowLiftUp()) and Rnd(8)) then
6876 ReleaseKey(KEY_LEFT
);
6877 ReleaseKey(KEY_RIGHT
);
6881 // Идем влево, если надо было:
6882 if GetAIFlag('GOLEFT') <> '' then
6884 RemoveAIFlag('GOLEFT');
6885 if CanRunLeft() then
6889 // Идем вправо, если надо было:
6890 if GetAIFlag('GORIGHT') <> '' then
6892 RemoveAIFlag('GORIGHT');
6893 if CanRunRight() then
6897 // Если вылетели за карту, то пробуем вернуться:
6898 if FObj
.X
< -32 then
6901 if FObj
.X
+32 > gMapInfo
.Width
then
6904 // Прыгаем, если надо было:
6905 if GetAIFlag('NEEDJUMP') <> '' then
6908 RemoveAIFlag('NEEDJUMP');
6911 // Смотрим вверх, если надо было:
6912 if GetAIFlag('NEEDSEEUP') <> '' then
6915 ReleaseKey(KEY_DOWN
);
6916 PressKey(KEY_UP
, 20);
6917 RemoveAIFlag('NEEDSEEUP');
6920 // Смотрим вниз, если надо было:
6921 if GetAIFlag('NEEDSEEDOWN') <> '' then
6924 ReleaseKey(KEY_DOWN
);
6925 PressKey(KEY_DOWN
, 20);
6926 RemoveAIFlag('NEEDSEEDOWN');
6929 // Если нужно было в дыру и мы не на земле, то покорно летим:
6930 if GetAIFlag('GOINHOLE') <> '' then
6931 if not OnGround() then
6933 ReleaseKey(KEY_LEFT
);
6934 ReleaseKey(KEY_RIGHT
);
6935 RemoveAIFlag('GOINHOLE');
6936 SetAIFlag('FALLINHOLE', '1');
6939 // Если падали и достигли земли, то хватит падать:
6940 if GetAIFlag('FALLINHOLE') <> '' then
6942 RemoveAIFlag('FALLINHOLE');
6944 // Если летели прямо и сейчас не на лестнице или на вершине лифта, то отходим в сторону:
6945 if not (KeyPressed(KEY_LEFT
) or KeyPressed(KEY_RIGHT
)) then
6946 if GetAIFlag('FALLINHOLE') = '' then
6947 if (not OnLadder()) or (FObj
.Vel
.Y
>= 0) or (OnTopLift()) then
6953 // Если на земле и можно подпрыгнуть, то, возможно, прыгаем:
6955 CanJumpUp(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*32) and
6959 // Если на земле и возле дыры (глубина > 2 ростов игрока):
6960 if OnGround() and NearHole() then
6961 if NearDeepHole() then // Если это бездна
6963 0..3: Turn(); // Бежим обратно
6964 4: Jump(); // Прыгаем
6965 5: begin // Прыгаем обратно
6970 else // Это не бездна и мы еще не летим туда
6971 if GetAIFlag('GOINHOLE') = '' then
6973 0: Turn(); // Не нужно туда
6974 1: Jump(); // Вдруг повезет - прыгаем
6975 else // Если яма с границей, то при случае можно туда прыгнуть
6976 if BorderHole() then
6977 SetAIFlag('GOINHOLE', '1');
6980 // Если на земле, но некуда идти:
6981 if (not CanRun()) and OnGround() then
6983 // Если мы на лестнице или можно перепрыгнуть, то прыгаем:
6984 if CanJumpOver() or OnLadder() then
6986 else // иначе попытаемся в другую сторону
6987 if Random(2) = 0 then
6989 if IsSafeTrigger() then
6995 // Осталось мало воздуха:
6996 if FAir
< 36 * 2 then
6999 // Выбираемся из кислоты, если нет костюма, обожглись, или мало здоровья:
7000 if (FMegaRulez
[MR_SUIT
] < gTime
) and ((FLastHit
= HIT_ACID
) or (Healthy() <= 1)) then
7001 if BodyInAcid(0, 0) then
7005 function TBot
.FullInStep(XInc
, YInc
: Integer): Boolean;
7007 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
7008 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_STEP
, False);
7011 {function TBot.NeedItem(Item: Byte): Byte;
7016 procedure TBot
.SelectWeapon(Dist
: Integer);
7020 function HaveAmmo(weapon
: Byte): Boolean;
7023 WEAPON_PISTOL
: Result
:= FAmmo
[A_BULLETS
] >= 1;
7024 WEAPON_SHOTGUN1
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7025 WEAPON_SHOTGUN2
: Result
:= FAmmo
[A_SHELLS
] >= 2;
7026 WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
] >= 10;
7027 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
] >= 1;
7028 WEAPON_PLASMA
: Result
:= FAmmo
[A_CELLS
] >= 10;
7029 WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
] >= 40;
7030 WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7031 WEAPON_FLAMETHROWER
: Result
:= FAmmo
[A_FUEL
] >= 1;
7032 else Result
:= True;
7037 if Dist
= -1 then Dist
:= BOT_LONGDIST
;
7039 if Dist
> BOT_LONGDIST
then
7040 begin // Дальний бой
7042 if FWeapon
[FDifficult
.WeaponPrior
[a
]] and HaveAmmo(FDifficult
.WeaponPrior
[a
]) then
7044 FSelectedWeapon
:= FDifficult
.WeaponPrior
[a
];
7048 else //if Dist > BOT_UNSAFEDIST then
7049 begin // Ближний бой
7051 if FWeapon
[FDifficult
.CloseWeaponPrior
[a
]] and HaveAmmo(FDifficult
.CloseWeaponPrior
[a
]) then
7053 FSelectedWeapon
:= FDifficult
.CloseWeaponPrior
[a
];
7060 if FWeapon[FDifficult.SafeWeaponPrior[a]] and HaveAmmo(FDifficult.SafeWeaponPrior[a]) then
7062 FSelectedWeapon := FDifficult.SafeWeaponPrior[a];
7068 function TBot
.PickItem(ItemType
: Byte; force
: Boolean; var remove
: Boolean): Boolean;
7070 Result
:= inherited PickItem(ItemType
, force
, remove
);
7072 if Result
then SetAIFlag('SELECTWEAPON', '1');
7075 function TBot
.Heal(value
: Word; Soft
: Boolean): Boolean;
7077 Result
:= inherited Heal(value
, Soft
);
7080 function TBot
.Healthy(): Byte;
7082 if FMegaRulez
[MR_INVUL
] >= gTime
then Result
:= 3
7083 else if (FHealth
> 80) or ((FHealth
> 50) and (FArmor
> 20)) then Result
:= 3
7084 else if (FHealth
> 50) then Result
:= 2
7085 else if (FHealth
> 20) then Result
:= 1
7089 function TBot
.TargetOnScreen(TX
, TY
: Integer): Boolean;
7091 Result
:= (Abs(FObj
.X
-TX
) <= Trunc(gPlayerScreenSize
.X
*0.6)) and
7092 (Abs(FObj
.Y
-TY
) <= Trunc(gPlayerScreenSize
.Y
*0.6));
7095 procedure TBot
.OnDamage(Angle
: SmallInt);
7103 if (Angle
= 0) or (Angle
= 180) then
7106 if (g_GetUIDType(FLastSpawnerUID
) = UID_PLAYER
) and
7107 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
) then
7109 pla
:= g_Player_Get(FLastSpawnerUID
);
7110 ok
:= not TargetOnScreen(pla
.FObj
.X
+ PLAYER_RECT
.X
,
7111 pla
.FObj
.Y
+ PLAYER_RECT
.Y
);
7114 if (g_GetUIDType(FLastSpawnerUID
) = UID_MONSTER
) and
7115 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
) then
7117 mon
:= g_Monsters_ByUID(FLastSpawnerUID
);
7118 ok
:= not TargetOnScreen(mon
.Obj
.X
+ mon
.Obj
.Rect
.X
,
7119 mon
.Obj
.Y
+ mon
.Obj
.Rect
.Y
);
7124 SetAIFlag('ATTACKLEFT', '1')
7126 SetAIFlag('ATTACKRIGHT', '1');
7130 function TBot
.RunDirection(): TDirection
;
7132 if Abs(Vel
.X
) >= 1 then
7134 if Vel
.X
> 0 then Result
:= TDirection
.D_RIGHT
else Result
:= TDirection
.D_LEFT
;
7136 Result
:= FDirection
;
7139 function TBot
.GetRnd(a
: Byte): Boolean;
7141 if a
= 0 then Result
:= False
7142 else if a
= 255 then Result
:= True
7143 else Result
:= Random(256) > 255-a
;
7146 function TBot
.GetInterval(a
: Byte; radius
: SmallInt): SmallInt;
7148 Result
:= Round((255-a
)/255*radius
*(Random(2)-1));
7152 procedure TDifficult
.save (st
: TStream
);
7154 utils
.writeInt(st
, Byte(DiagFire
));
7155 utils
.writeInt(st
, Byte(InvisFire
));
7156 utils
.writeInt(st
, Byte(DiagPrecision
));
7157 utils
.writeInt(st
, Byte(FlyPrecision
));
7158 utils
.writeInt(st
, Byte(Cover
));
7159 utils
.writeInt(st
, Byte(CloseJump
));
7160 st
.WriteBuffer(WeaponPrior
[Low(WeaponPrior
)], sizeof(WeaponPrior
));
7161 st
.WriteBuffer(CloseWeaponPrior
[Low(CloseWeaponPrior
)], sizeof(CloseWeaponPrior
));
7164 procedure TDifficult
.load (st
: TStream
);
7166 DiagFire
:= utils
.readByte(st
);
7167 InvisFire
:= utils
.readByte(st
);
7168 DiagPrecision
:= utils
.readByte(st
);
7169 FlyPrecision
:= utils
.readByte(st
);
7170 Cover
:= utils
.readByte(st
);
7171 CloseJump
:= utils
.readByte(st
);
7172 st
.ReadBuffer(WeaponPrior
[Low(WeaponPrior
)], sizeof(WeaponPrior
));
7173 st
.ReadBuffer(CloseWeaponPrior
[Low(CloseWeaponPrior
)], sizeof(CloseWeaponPrior
));
7177 procedure TBot
.SaveState (st
: TStream
);
7182 inherited SaveState(st
);
7183 utils
.writeSign(st
, 'BOT0');
7185 utils
.writeInt(st
, Byte(FSelectedWeapon
));
7187 utils
.writeInt(st
, Word(FTargetUID
));
7188 // Время потери цели
7189 utils
.writeInt(st
, LongWord(FLastVisible
));
7190 // Количество флагов ИИ
7191 dw
:= Length(FAIFlags
);
7192 utils
.writeInt(st
, LongInt(dw
));
7194 for i
:= 0 to dw
-1 do
7196 utils
.writeStr(st
, FAIFlags
[i
].Name
, 20);
7197 utils
.writeStr(st
, FAIFlags
[i
].Value
, 20);
7199 // Настройки сложности
7200 FDifficult
.save(st
);
7204 procedure TBot
.LoadState (st
: TStream
);
7209 inherited LoadState(st
);
7210 if not utils
.checkSign(st
, 'BOT0') then raise XStreamError
.Create('invalid bot signature');
7212 FSelectedWeapon
:= utils
.readByte(st
);
7214 FTargetUID
:= utils
.readWord(st
);
7215 // Время потери цели
7216 FLastVisible
:= utils
.readLongWord(st
);
7217 // Количество флагов ИИ
7218 dw
:= utils
.readLongInt(st
);
7219 if (dw
< 0) or (dw
> 16384) then raise XStreamError
.Create('invalid number of bot AI flags');
7220 SetLength(FAIFlags
, dw
);
7222 for i
:= 0 to dw
-1 do
7224 FAIFlags
[i
].Name
:= utils
.readStr(st
, 20);
7225 FAIFlags
[i
].Value
:= utils
.readStr(st
, 20);
7227 // Настройки сложности
7228 FDifficult
.load(st
);
7233 conRegVar('cheat_berserk_autoswitch', @gBerserkAutoswitch
, 'autoswitch to fist when berserk pack taken', '', true, true);
7234 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');
7235 conRegVar('player_indicator_style', @gPlayerIndicatorStyle
, 'Visual appearance of indicator', 'Visual appearance of indicator');