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));
77 ANGLE_NONE
= Low(SmallInt);
79 CORPSE_STATE_REMOVEME
= 0;
80 CORPSE_STATE_NORMAL
= 1;
81 CORPSE_STATE_MESS
= 2;
83 PLAYER_RECT
: TRectWH
= (X
:15; Y
:12; Width
:34; Height
:52);
84 PLAYER_RECT_CX
= 15+(34 div 2);
85 PLAYER_RECT_CY
= 12+(52 div 2);
86 PLAYER_CORPSERECT
: TRectWH
= (X
:15; Y
:48; Width
:34; Height
:16);
89 PLAYER_HP_LIMIT
= 200;
91 PLAYER_AP_LIMIT
= 200;
95 PLAYER_BURN_TIME
= 110;
97 PLAYER1_DEF_COLOR
: TRGB
= (R
:64; G
:175; B
:48);
98 PLAYER2_DEF_COLOR
: TRGB
= (R
:96; G
:96; B
:96);
102 JET_MAX
= 540; // ~30 sec
104 ANGLE_RIGHTDOWN
= -35;
106 ANGLE_LEFTDOWN
= -145;
107 WEAPONPOINT
: Array [TDirection
] of TDFPoint
= ((X
:16; Y
:32), (X
:47; Y
:32));
108 TEAMCOLOR
: Array [TEAM_RED
..TEAM_BLUE
] of TRGB
= ((R
:255; G
:0; B
:0),
127 TPlayerStatArray
= Array of TPlayerStat
;
129 TPlayerSavedState
= record
137 Ammo
: Array [A_BULLETS
..A_HIGH
] of Word;
138 MaxAmmo
: Array [A_BULLETS
..A_HIGH
] of Word;
139 Weapon
: Array [WP_FIRST
..WP_LAST
] of Boolean;
140 Rulez
: Set of R_ITEM_BACKPACK
..R_BERSERK
;
149 TPlayer
= class{$IFDEF USE_MEMPOOL}(TPoolObject
){$ENDIF}
157 FDirection
: TDirection
;
165 FMonsterKills
: Integer;
171 FCanJetpack
: Boolean;
177 FNextWeapDelay
: Byte; // frames
178 FBFGFireCounter
: SmallInt;
179 FLastSpawnerUID
: Word;
183 FSpectatePlayer
: Integer;
184 FFirePainTime
: Integer;
187 FSavedStateNum
: Integer;
189 FModel
: TPlayerModel
;
190 FPunchAnim
: TAnimationState
;
193 FActionForce
: Boolean;
194 FActionChanged
: Boolean;
196 FFireAngle
: SmallInt;
200 {$IFDEF ENABLE_SHELLS}
201 FShellTimer
: Integer;
204 FSawSound
: TPlayableSound
;
205 FSawSoundIdle
: TPlayableSound
;
206 FSawSoundHit
: TPlayableSound
;
207 FSawSoundSelect
: TPlayableSound
;
208 FFlameSoundOn
: TPlayableSound
;
209 FFlameSoundOff
: TPlayableSound
;
210 FFlameSoundWork
: TPlayableSound
;
211 FJetSoundOn
: TPlayableSound
;
212 FJetSoundOff
: TPlayableSound
;
213 FJetSoundFly
: TPlayableSound
;
217 FJustTeleported
: Boolean;
219 mEDamageType
: Integer;
222 function CollideLevel(XInc
, YInc
: Integer): Boolean;
223 function StayOnStep(XInc
, YInc
: Integer): Boolean;
224 function HeadInLiquid(XInc
, YInc
: Integer): Boolean;
225 function BodyInLiquid(XInc
, YInc
: Integer): Boolean;
226 function BodyInAcid(XInc
, YInc
: Integer): Boolean;
227 function FullInLift(XInc
, YInc
: Integer): Integer;
228 {procedure CollideItem();}
229 procedure FlySmoke(Times
: DWORD
= 1);
230 procedure OnFireFlame(Times
: DWORD
= 1);
231 procedure SetAction(Action
: Byte; Force
: Boolean = False);
232 procedure OnDamage(Angle
: SmallInt); virtual;
233 function firediry(): Integer;
236 procedure Run(Direction
: TDirection
);
237 procedure NextWeapon();
238 procedure PrevWeapon();
245 function getNextWeaponIndex (): Byte; // return 255 for "no switch"
246 procedure resetWeaponQueue ();
247 function hasAmmoForWeapon (weapon
: Byte): Boolean;
249 procedure doDamage (v
: Integer);
251 function refreshCorpse(): Boolean;
254 FDamageBuffer
: Integer;
256 FAmmo
: Array [A_BULLETS
..A_HIGH
] of Word;
257 FMaxAmmo
: Array [A_BULLETS
..A_HIGH
] of Word;
258 FWeapon
: Array [WP_FIRST
..WP_LAST
] of Boolean;
259 FRulez
: Set of R_ITEM_BACKPACK
..R_BERSERK
;
261 FMegaRulez
: Array [MR_SUIT
..MR_MAX
] of DWORD
;
262 FReloading
: Array [WP_FIRST
..WP_LAST
] of Word;
263 FTime
: Array [T_RESPAWN
..T_FLAGCAP
] of DWORD
;
264 FKeys
: Array [KEY_LEFT
..KEY_CHAT
] of TKeyState
;
266 FPreferredTeam
: Byte;
269 FWantsInGame
: Boolean;
274 FActualModelName
: string;
281 FSpawnInvul
: Integer;
283 FWaitForFirstSpawn
: Boolean; // set to `true` in server, used to spawn a player on first full state request
286 // debug: viewport offset
287 viewPortX
, viewPortY
, viewPortW
, viewPortH
: Integer;
289 function isValidViewPort (): Boolean; inline;
291 constructor Create(); virtual;
292 destructor Destroy(); override;
293 procedure Respawn(Silent
: Boolean; Force
: Boolean = False); virtual;
294 function GetRespawnPoint(): Byte;
295 procedure PressKey(Key
: Byte; Time
: Word = 1);
296 procedure ReleaseKeys();
297 procedure SetModel(ModelName
: String);
298 procedure SetColor(Color
: TRGB
);
299 function GetColor(): TRGB
;
300 procedure SetWeapon(W
: Byte);
301 function IsKeyPressed(K
: Byte): Boolean;
302 function GetKeys(): Byte;
303 function PickItem(ItemType
: Byte; arespawn
: Boolean; var remove
: Boolean): Boolean; virtual;
304 function Collide(X
, Y
: Integer; Width
, Height
: Word): Boolean; overload
;
305 function Collide(Panel
: TPanel
): Boolean; overload
;
306 function Collide(X
, Y
: Integer): Boolean; overload
;
307 procedure SetDirection(Direction
: TDirection
);
308 procedure GetSecret();
309 function TeleportTo(X
, Y
: Integer; silent
: Boolean; dir
: Byte): Boolean;
311 procedure Push(vx
, vy
: Integer);
312 procedure ChangeModel(ModelName
: String);
313 procedure SwitchTeam
;
314 procedure ChangeTeam(Team
: Byte);
316 function GetFlag(Flag
: Byte): Boolean;
317 procedure SetFlag(Flag
: Byte);
318 function DropFlag(Silent
: Boolean = True): Boolean;
319 procedure AllRulez(Health
: Boolean);
320 procedure RestoreHealthArmor();
321 procedure FragCombo();
322 procedure GiveItem(ItemType
: Byte);
323 procedure Damage(value
: Word; SpawnerUID
: Word; vx
, vy
: Integer; t
: Byte); virtual;
324 function Heal(value
: Word; Soft
: Boolean): Boolean; virtual;
325 procedure MakeBloodVector(Count
: Word; VelX
, VelY
: Integer);
326 procedure MakeBloodSimple(Count
: Word);
327 procedure Kill(KillType
: Byte; SpawnerUID
: Word; t
: Byte);
328 procedure Reset(Force
: Boolean);
329 procedure Spectate(NoMove
: Boolean = False);
330 procedure SwitchNoClip
;
331 procedure SoftReset();
332 procedure PreUpdate();
333 procedure Update(); virtual;
334 procedure RememberState();
335 procedure RecallState();
336 procedure SaveState (st
: TStream
); virtual;
337 procedure LoadState (st
: TStream
); virtual;
338 procedure PauseSounds(Enable
: Boolean);
339 procedure NetFire(Wpn
: Byte; X
, Y
, AX
, AY
: Integer; WID
: Integer = -1);
340 procedure DoLerp(Level
: Integer = 2);
341 procedure SetLerp(XTo
, YTo
: Integer);
342 procedure QueueWeaponSwitch(Weapon
: Byte);
343 procedure RealizeCurrentWeapon();
347 procedure JetpackOff
;
348 procedure CatchFire(Attacker
: Word; Timeout
: Integer = PLAYER_BURN_TIME
);
350 //WARNING! this does nothing for now, but still call it!
351 procedure positionChanged (); //WARNING! call this after entity position was changed, or coldet will not work right!
353 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
354 procedure moveBy (dx
, dy
: Integer); inline;
356 function getCameraObj(): TObj
;
358 function GetAmmoByWeapon(Weapon
: Byte): Word; // private state
361 property Vel
: TPoint2i read FObj
.Vel
;
362 property Obj
: TObj read FObj
;
364 property Name
: String read FName write FName
;
365 property Model
: TPlayerModel read FModel
;
366 property Health
: Integer read FHealth write FHealth
;
367 property Lives
: Byte read FLives write FLives
;
368 property Armor
: Integer read FArmor write FArmor
;
369 property Air
: Integer read FAir write FAir
;
370 property JetFuel
: Integer read FJetFuel write FJetFuel
;
371 property Frags
: Integer read FFrags write FFrags
;
372 property Death
: Integer read FDeath write FDeath
;
373 property Kills
: Integer read FKills write FKills
;
374 property CurrWeap
: Byte read FCurrWeap write FCurrWeap
;
375 property MonsterKills
: Integer read FMonsterKills write FMonsterKills
;
376 property Secrets
: Integer read FSecrets
;
377 property GodMode
: Boolean read FGodMode write FGodMode
;
378 property NoTarget
: Boolean read FNoTarget write FNoTarget
;
379 property NoReload
: Boolean read FNoReload write FNoReload
;
380 property alive
: Boolean read FAlive write FAlive
;
381 property Flag
: Byte read FFlag
;
382 property Team
: Byte read FTeam write FTeam
;
383 property Direction
: TDirection read FDirection
;
384 property GameX
: Integer read FObj
.X write FObj
.X
;
385 property GameY
: Integer read FObj
.Y write FObj
.Y
;
386 property GameVelX
: Integer read FObj
.Vel
.X write FObj
.Vel
.X
;
387 property GameVelY
: Integer read FObj
.Vel
.Y write FObj
.Vel
.Y
;
388 property GameAccelX
: Integer read FObj
.Accel
.X write FObj
.Accel
.X
;
389 property GameAccelY
: Integer read FObj
.Accel
.Y write FObj
.Accel
.Y
;
390 property IncCam
: Integer read FIncCam write FIncCam
;
391 property IncCamOld
: Integer read FIncCamOld write FIncCamOld
;
392 property SlopeOld
: Integer read FSlopeOld write FSlopeOld
;
393 property UID
: Word read FUID write FUID
;
394 property JustTeleported
: Boolean read FJustTeleported write FJustTeleported
;
395 property NetTime
: LongWord read FNetTime write FNetTime
;
398 property Angle_
: SmallInt read FAngle
;
399 property Spectator
: Boolean read FSpectator
;
400 property NoRespawn
: Boolean read FNoRespawn
;
401 property Berserk
: Integer read FBerserk
;
402 property Pain
: Integer read FPain
;
403 property Pickup
: Integer read FPickup
;
404 property PunchAnim
: TAnimationState read FPunchAnim write FPunchAnim
;
405 property SpawnInvul
: Integer read FSpawnInvul
;
406 property Ghost
: Boolean read FGhost
;
409 property eName
: String read FName write FName
;
410 property eHealth
: Integer read FHealth write FHealth
;
411 property eLives
: Byte read FLives write FLives
;
412 property eArmor
: Integer read FArmor write FArmor
;
413 property eAir
: Integer read FAir write FAir
;
414 property eJetFuel
: Integer read FJetFuel write FJetFuel
;
415 property eFrags
: Integer read FFrags write FFrags
;
416 property eDeath
: Integer read FDeath write FDeath
;
417 property eKills
: Integer read FKills write FKills
;
418 property eCurrWeap
: Byte read FCurrWeap write FCurrWeap
;
419 property eMonsterKills
: Integer read FMonsterKills write FMonsterKills
;
420 property eSecrets
: Integer read FSecrets write FSecrets
;
421 property eGodMode
: Boolean read FGodMode write FGodMode
;
422 property eNoTarget
: Boolean read FNoTarget write FNoTarget
;
423 property eNoReload
: Boolean read FNoReload write FNoReload
;
424 property eAlive
: Boolean read FAlive write FAlive
;
425 property eFlag
: Byte read FFlag
;
426 property eTeam
: Byte read FTeam write FTeam
;
427 property eDirection
: TDirection read FDirection
;
428 property eGameX
: Integer read FObj
.X write FObj
.X
;
429 property eGameY
: Integer read FObj
.Y write FObj
.Y
;
430 property eGameVelX
: Integer read FObj
.Vel
.X write FObj
.Vel
.X
;
431 property eGameVelY
: Integer read FObj
.Vel
.Y write FObj
.Vel
.Y
;
432 property eGameAccelX
: Integer read FObj
.Accel
.X write FObj
.Accel
.X
;
433 property eGameAccelY
: Integer read FObj
.Accel
.Y write FObj
.Accel
.Y
;
434 property eIncCam
: Integer read FIncCam write FIncCam
;
435 property eUID
: Word read FUID
;
436 property eJustTeleported
: Boolean read FJustTeleported
;
437 property eNetTime
: LongWord read FNetTime
;
439 // set this before assigning something to `eDamage`
440 property eDamageType
: Integer read mEDamageType write mEDamageType
;
441 property eDamage
: Integer write doDamage
;
452 WeaponPrior
: packed array [WP_FIRST
..WP_LAST
] of Byte;
453 CloseWeaponPrior
: packed array [WP_FIRST
..WP_LAST
] of Byte;
454 //SafeWeaponPrior: Array [WP_FIRST..WP_LAST] of Byte;
457 procedure save (st
: TStream
);
458 procedure load (st
: TStream
);
466 TBot
= class(TPlayer
)
468 FSelectedWeapon
: Byte;
471 FAIFlags
: Array of TAIFlag
;
472 FDifficult
: TDifficult
;
474 function GetRnd(a
: Byte): Boolean;
475 function GetInterval(a
: Byte; radius
: SmallInt): SmallInt;
476 function RunDirection(): TDirection
;
477 function FullInStep(XInc
, YInc
: Integer): Boolean;
478 //function NeedItem(Item: Byte): Byte;
479 procedure SelectWeapon(Dist
: Integer);
480 procedure SetAIFlag(aName
, fValue
: String20
);
481 function GetAIFlag(aName
: String20
): String20
;
482 procedure RemoveAIFlag(aName
: String20
);
483 function Healthy(): Byte;
484 procedure UpdateMove();
485 procedure UpdateCombat();
486 function KeyPressed(Key
: Word): Boolean;
487 procedure ReleaseKey(Key
: Byte);
488 function TargetOnScreen(TX
, TY
: Integer): Boolean;
489 procedure OnDamage(Angle
: SmallInt); override;
492 procedure Respawn(Silent
: Boolean; Force
: Boolean = False); override;
493 constructor Create(); override;
494 destructor Destroy(); override;
495 function PickItem(ItemType
: Byte; force
: Boolean; var remove
: Boolean): Boolean; override;
496 function Heal(value
: Word; Soft
: Boolean): Boolean; override;
497 procedure Update(); override;
498 procedure SaveState (st
: TStream
); override;
499 procedure LoadState (st
: TStream
); override;
502 TCorpse
= class{$IFDEF USE_MEMPOOL}(TPoolObject
){$ENDIF}
509 FModel
: TPlayerModel
;
512 constructor Create(X
, Y
: Integer; ModelName
: String; aMess
: Boolean);
513 destructor Destroy(); override;
514 procedure Damage(Value
: Word; SpawnerUID
: Word; vx
, vy
: Integer);
516 procedure SaveState (st
: TStream
);
517 procedure LoadState (st
: TStream
);
519 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
520 procedure moveBy (dx
, dy
: Integer); inline;
522 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
524 function ObjPtr (): PObj
; inline;
526 property Obj
: TObj read FObj
; // copies object
527 property State
: Byte read FState
;
528 property Mess
: Boolean read FMess
;
529 property Model
: TPlayerModel read FModel
;
532 TTeamStat
= Array [TEAM_RED
..TEAM_BLUE
] of
538 gPlayers
: Array of TPlayer
;
539 gCorpses
: Array of TCorpse
;
540 gTeamStat
: TTeamStat
;
541 gFly
: Boolean = False;
542 gAimLine
: Boolean = False;
543 gChatBubble
: Integer = 0;
544 gPlayerIndicator
: Integer = 1;
545 gPlayerIndicatorStyle
: Integer = 0;
547 gSpectLatchPID1
: Word = 0;
548 gSpectLatchPID2
: Word = 0;
549 MAX_RUNVEL
: Integer = 8;
550 VEL_JUMP
: Integer = 10;
552 function Lerp(X
, Y
, Factor
: Integer): Integer;
554 procedure g_Corpses_SetMax(Count
: Word);
555 function g_Corpses_GetMax(): Word;
557 procedure g_Player_Init();
558 procedure g_Player_Free();
559 function g_Player_Create(ModelName
: String; Color
: TRGB
; Team
: Byte; Bot
: Boolean): Word;
560 function g_Player_CreateFromState (st
: TStream
): Word;
561 procedure g_Player_Remove(UID
: Word);
562 procedure g_Player_ResetTeams();
563 procedure g_Player_PreUpdate();
564 procedure g_Player_UpdateAll();
565 procedure g_Player_RememberAll();
566 procedure g_Player_ResetAll(Force
, Silent
: Boolean);
567 function g_Player_Get(UID
: Word): TPlayer
;
568 function g_Player_GetCount(): Byte;
569 function g_Player_GetStats(): TPlayerStatArray
;
570 function g_Player_ValidName(Name
: String): Boolean;
571 function g_Player_CreateCorpse(Player
: TPlayer
): Integer;
572 procedure g_Player_UpdatePhysicalObjects();
573 procedure g_Player_RemoveAllCorpses();
574 procedure g_Player_Corpses_SaveState (st
: TStream
);
575 procedure g_Player_Corpses_LoadState (st
: TStream
);
576 procedure g_Player_ResetReady();
577 procedure g_Bot_Add(Team
, Difficult
: Byte; Handicap
: Integer = 100);
578 procedure g_Bot_AddList(Team
: Byte; lname
: ShortString; num
: Integer = -1; Handicap
: Integer = 100);
579 procedure g_Bot_MixNames();
580 procedure g_Bot_RemoveAll();
585 {$IFDEF ENABLE_HOLMES}
600 {$IFDEF ENABLE_SHELLS}
603 e_log
, g_map
, g_items
, g_console
, Math
,
604 g_options
, g_triggers
, g_game
, g_grid
, e_res
,
605 wadreader
, g_monsters
, CONFIG
, g_language
,
609 const PLR_SAVE_VERSION
= 0;
619 diag_precision
: Byte;
623 w_prior1
: Array [WP_FIRST
..WP_LAST
] of Byte;
624 w_prior2
: Array [WP_FIRST
..WP_LAST
] of Byte;
625 w_prior3
: Array [WP_FIRST
..WP_LAST
] of Byte;
629 TIME_RESPAWN1
= 1500;
630 TIME_RESPAWN2
= 2000;
631 TIME_RESPAWN3
= 3000;
632 PLAYER_SUIT_TIME
= 30000;
633 PLAYER_INVUL_TIME
= 30000;
634 PLAYER_INVIS_TIME
= 35000;
635 FRAG_COMBO_TIME
= 3000;
638 PLAYER_HEADRECT
: TRectWH
= (X
:24; Y
:12; Width
:20; Height
:12);
641 BOT_UNSAFEDIST
= 128;
642 DIFFICULT_EASY
: TDifficult
= (DiagFire
: 32; InvisFire
: 32; DiagPrecision
: 32;
643 FlyPrecision
: 32; Cover
: 32; CloseJump
: 32;
644 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
645 DIFFICULT_MEDIUM
: TDifficult
= (DiagFire
: 127; InvisFire
: 127; DiagPrecision
: 127;
646 FlyPrecision
: 127; Cover
: 127; CloseJump
: 127;
647 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
648 DIFFICULT_HARD
: TDifficult
= (DiagFire
: 255; InvisFire
: 255; DiagPrecision
: 255;
649 FlyPrecision
: 255; Cover
: 255; CloseJump
: 255;
650 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
651 WEAPON_PRIOR1
: Array [WP_FIRST
..WP_LAST
] of Byte =
652 (WEAPON_FLAMETHROWER
, WEAPON_SUPERPULEMET
,
653 WEAPON_SHOTGUN2
, WEAPON_SHOTGUN1
,
654 WEAPON_CHAINGUN
, WEAPON_PLASMA
, WEAPON_ROCKETLAUNCHER
,
655 WEAPON_BFG
, WEAPON_PISTOL
, WEAPON_SAW
, WEAPON_KASTET
);
656 WEAPON_PRIOR2
: Array [WP_FIRST
..WP_LAST
] of Byte =
657 (WEAPON_FLAMETHROWER
, WEAPON_SUPERPULEMET
,
658 WEAPON_BFG
, WEAPON_ROCKETLAUNCHER
,
659 WEAPON_SHOTGUN2
, WEAPON_PLASMA
, WEAPON_SHOTGUN1
,
660 WEAPON_CHAINGUN
, WEAPON_PISTOL
, WEAPON_SAW
, WEAPON_KASTET
);
661 //WEAPON_PRIOR3: Array [WP_FIRST..WP_LAST] of Byte =
662 // (WEAPON_FLAMETHROWER, WEAPON_SUPERPULEMET,
663 // WEAPON_BFG, WEAPON_PLASMA, WEAPON_SHOTGUN2,
664 // WEAPON_CHAINGUN, WEAPON_SHOTGUN1, WEAPON_SAW,
665 // WEAPON_ROCKETLAUNCHER, WEAPON_PISTOL, WEAPON_KASTET);
666 WEAPON_RELOAD
: Array [WP_FIRST
..WP_LAST
] of Byte =
667 (5, 2, 6, 18, 36, 2, 12, 2, 14, 2, 2);
669 PLAYER_SIGNATURE
= $52594C50; // 'PLYR'
670 CORPSE_SIGNATURE
= $50524F43; // 'CORP'
672 BOTNAMES_FILENAME
= 'botnames.txt';
673 BOTLIST_FILENAME
= 'botlist.txt';
676 MaxCorpses
: Word = 20;
677 BotNames
: Array of String;
678 BotList
: Array of TBotProfile
;
679 SavedStates
: Array of TPlayerSavedState
;
682 function Lerp(X
, Y
, Factor
: Integer): Integer;
684 Result
:= X
+ ((Y
- X
) div Factor
);
687 function SameTeam(UID1
, UID2
: Word): Boolean;
691 if (UID1
> UID_MAX_PLAYER
) or (UID1
<= UID_MAX_GAME
) or
692 (UID2
> UID_MAX_PLAYER
) or (UID2
<= UID_MAX_GAME
) then Exit
;
694 if (g_Player_Get(UID1
) = nil) or (g_Player_Get(UID2
) = nil) then Exit
;
696 if ((g_Player_Get(UID1
).Team
= TEAM_NONE
) or
697 (g_Player_Get(UID2
).Team
= TEAM_NONE
)) then Exit
;
699 Result
:= g_Player_Get(UID1
).FTeam
= g_Player_Get(UID2
).FTeam
;
702 procedure g_Corpses_SetMax(Count
: Word);
705 SetLength(gCorpses
, Count
);
708 function g_Corpses_GetMax(): Word;
710 Result
:= MaxCorpses
;
713 function g_Player_Create(ModelName
: String; Color
: TRGB
; Team
: Byte; Bot
: Boolean): Word;
723 // Есть ли место в gPlayers:
724 if gPlayers
<> nil then
725 for a
:= 0 to High(gPlayers
) do
726 if gPlayers
[a
] = nil then
732 // Нет места - расширяем gPlayers:
735 SetLength(gPlayers
, Length(gPlayers
)+1);
739 // Создаем объект игрока:
741 gPlayers
[a
] := TBot
.Create()
743 gPlayers
[a
] := TPlayer
.Create();
746 gPlayers
[a
].FActualModelName
:= ModelName
;
747 gPlayers
[a
].SetModel(ModelName
);
749 // Нет модели - создание не возможно:
750 if gPlayers
[a
].FModel
= nil then
754 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], [ModelName
]));
758 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
759 if Random(2) = 0 then
763 gPlayers
[a
].FPreferredTeam
:= Team
;
765 case gGameSettings
.GameMode
of
766 GM_DM
: gPlayers
[a
].FTeam
:= TEAM_NONE
;
768 GM_CTF
: gPlayers
[a
].FTeam
:= gPlayers
[a
].FPreferredTeam
;
770 GM_COOP
: gPlayers
[a
].FTeam
:= TEAM_COOP
;
773 // Если командная игра - красим модель в цвет команды:
774 gPlayers
[a
].FColor
:= Color
;
775 if gPlayers
[a
].FTeam
in [TEAM_RED
, TEAM_BLUE
] then
776 gPlayers
[a
].FModel
.Color
:= TEAMCOLOR
[gPlayers
[a
].FTeam
]
778 gPlayers
[a
].FModel
.Color
:= Color
;
780 gPlayers
[a
].FUID
:= g_CreateUID(UID_PLAYER
);
781 gPlayers
[a
].FAlive
:= False;
783 Result
:= gPlayers
[a
].FUID
;
786 function g_Player_CreateFromState (st
: TStream
): Word;
793 if (st
= nil) then exit
; //???
796 if not utils
.checkSign(st
, 'PLYR') then raise XStreamError
.Create('invalid player signature');
797 if (utils
.readByte(st
) <> PLR_SAVE_VERSION
) then raise XStreamError
.Create('invalid player version');
800 Bot
:= utils
.readBool(st
);
805 // Есть ли место в gPlayers:
806 for a
:= 0 to High(gPlayers
) do if (gPlayers
[a
] = nil) then begin ok
:= true; break
; end;
808 // Нет места - расширяем gPlayers
811 SetLength(gPlayers
, Length(gPlayers
)+1);
815 // Создаем объект игрока
817 gPlayers
[a
] := TBot
.Create()
819 gPlayers
[a
] := TPlayer
.Create();
820 gPlayers
[a
].FIamBot
:= Bot
;
821 gPlayers
[a
].FPhysics
:= True;
824 gPlayers
[a
].FUID
:= utils
.readWord(st
);
826 gPlayers
[a
].FName
:= utils
.readStr(st
);
828 gPlayers
[a
].FTeam
:= utils
.readByte(st
);
829 gPlayers
[a
].FPreferredTeam
:= gPlayers
[a
].FTeam
;
831 gPlayers
[a
].FAlive
:= utils
.readBool(st
);
832 // Израсходовал ли все жизни
833 gPlayers
[a
].FNoRespawn
:= utils
.readBool(st
);
835 b
:= utils
.readByte(st
);
836 if b
= 1 then gPlayers
[a
].FDirection
:= TDirection
.D_LEFT
else gPlayers
[a
].FDirection
:= TDirection
.D_RIGHT
; // b = 2
838 gPlayers
[a
].FHealth
:= utils
.readLongInt(st
);
840 gPlayers
[a
].FHandicap
:= utils
.readLongInt(st
);
842 gPlayers
[a
].FLives
:= utils
.readByte(st
);
844 gPlayers
[a
].FArmor
:= utils
.readLongInt(st
);
846 gPlayers
[a
].FAir
:= utils
.readLongInt(st
);
848 gPlayers
[a
].FJetFuel
:= utils
.readLongInt(st
);
850 gPlayers
[a
].FPain
:= utils
.readLongInt(st
);
852 gPlayers
[a
].FKills
:= utils
.readLongInt(st
);
854 gPlayers
[a
].FMonsterKills
:= utils
.readLongInt(st
);
856 gPlayers
[a
].FFrags
:= utils
.readLongInt(st
);
858 gPlayers
[a
].FFragCombo
:= utils
.readByte(st
);
859 // Время последнего фрага
860 gPlayers
[a
].FLastFrag
:= utils
.readLongWord(st
);
862 gPlayers
[a
].FDeath
:= utils
.readLongInt(st
);
864 gPlayers
[a
].FFlag
:= utils
.readByte(st
);
866 gPlayers
[a
].FSecrets
:= utils
.readLongInt(st
);
868 gPlayers
[a
].FCurrWeap
:= utils
.readByte(st
);
869 // Следующее желаемое оружие
870 gPlayers
[a
].FNextWeap
:= utils
.readWord(st
);
872 gPlayers
[a
].FNextWeapDelay
:= utils
.readByte(st
);
874 gPlayers
[a
].FBFGFireCounter
:= utils
.readSmallInt(st
);
876 gPlayers
[a
].FDamageBuffer
:= utils
.readLongInt(st
);
877 // Последний ударивший
878 gPlayers
[a
].FLastSpawnerUID
:= utils
.readWord(st
);
879 // Тип последнего полученного урона
880 gPlayers
[a
].FLastHit
:= utils
.readByte(st
);
882 Obj_LoadState(@gPlayers
[a
].FObj
, st
);
883 // Текущее количество патронов
884 for i
:= A_BULLETS
to A_HIGH
do gPlayers
[a
].FAmmo
[i
] := utils
.readWord(st
);
885 // Максимальное количество патронов
886 for i
:= A_BULLETS
to A_HIGH
do gPlayers
[a
].FMaxAmmo
[i
] := utils
.readWord(st
);
888 for i
:= WP_FIRST
to WP_LAST
do gPlayers
[a
].FWeapon
[i
] := utils
.readBool(st
);
889 // Время перезарядки оружия
890 for i
:= WP_FIRST
to WP_LAST
do gPlayers
[a
].FReloading
[i
] := utils
.readWord(st
);
892 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_ITEM_BACKPACK
);
893 // Наличие красного ключа
894 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_KEY_RED
);
895 // Наличие зеленого ключа
896 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_KEY_GREEN
);
897 // Наличие синего ключа
898 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_KEY_BLUE
);
900 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_BERSERK
);
901 // Время действия специальных предметов
902 for i
:= MR_SUIT
to MR_MAX
do gPlayers
[a
].FMegaRulez
[i
] := utils
.readLongWord(st
);
903 // Время до повторного респауна, смены оружия, исользования, захвата флага
904 for i
:= T_RESPAWN
to T_FLAGCAP
do gPlayers
[a
].FTime
[i
] := utils
.readLongWord(st
);
907 gPlayers
[a
].FActualModelName
:= utils
.readStr(st
);
909 gPlayers
[a
].FColor
.R
:= utils
.readByte(st
);
910 gPlayers
[a
].FColor
.G
:= utils
.readByte(st
);
911 gPlayers
[a
].FColor
.B
:= utils
.readByte(st
);
912 // Обновляем модель игрока
913 gPlayers
[a
].SetModel(gPlayers
[a
].FActualModelName
);
915 // Нет модели - создание невозможно
916 if (gPlayers
[a
].FModel
= nil) then
920 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], [gPlayers
[a
].FActualModelName
]));
924 // Если командная игра - красим модель в цвет команды
925 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
926 gPlayers
[a
].FModel
.Color
:= TEAMCOLOR
[gPlayers
[a
].FTeam
]
928 gPlayers
[a
].FModel
.Color
:= gPlayers
[a
].FColor
;
930 result
:= gPlayers
[a
].FUID
;
934 procedure g_Player_ResetTeams();
938 if g_Game_IsClient
then
940 if gPlayers
= nil then
942 for a
:= Low(gPlayers
) to High(gPlayers
) do
943 if gPlayers
[a
] <> nil then
944 case gGameSettings
.GameMode
of
946 gPlayers
[a
].ChangeTeam(TEAM_NONE
);
948 if not (gPlayers
[a
].Team
in [TEAM_RED
, TEAM_BLUE
]) then
949 if gPlayers
[a
].FPreferredTeam
in [TEAM_RED
, TEAM_BLUE
] then
950 gPlayers
[a
].ChangeTeam(gPlayers
[a
].FPreferredTeam
)
953 gPlayers
[a
].ChangeTeam(TEAM_RED
)
955 gPlayers
[a
].ChangeTeam(TEAM_BLUE
);
958 gPlayers
[a
].ChangeTeam(TEAM_COOP
);
962 procedure g_Bot_Add(Team
, Difficult
: Byte; Handicap
: Integer = 100);
965 _name
, _model
: String;
968 if not g_Game_IsServer
then Exit
;
970 // Список названий моделей:
971 m
:= g_PlayerModel_GetNames();
976 if (gGameSettings
.GameType
= GT_SINGLE
) or (gGameSettings
.GameMode
= GM_COOP
) then
977 Team
:= TEAM_COOP
// COOP
979 if gGameSettings
.GameMode
= GM_DM
then
980 Team
:= TEAM_NONE
// DM
982 if Team
= TEAM_NONE
then // CTF / TDM
984 // Автобаланс команд:
988 for a
:= 0 to High(gPlayers
) do
989 if gPlayers
[a
] <> nil then
991 if gPlayers
[a
].Team
= TEAM_RED
then
994 if gPlayers
[a
].Team
= TEAM_BLUE
then
1004 if Random(2) = 0 then
1010 // Выбираем боту имя:
1012 if BotNames
<> nil then
1013 for a
:= 0 to High(BotNames
) do
1014 if g_Player_ValidName(BotNames
[a
]) then
1016 _name
:= BotNames
[a
];
1020 // Выбираем случайную модель:
1021 _model
:= m
[Random(Length(m
))];
1024 with g_Player_Get(g_Player_Create(_model
,
1025 _RGB(Min(Random(9)*32, 255),
1026 Min(Random(9)*32, 255),
1027 Min(Random(9)*32, 255)),
1028 Team
, True)) as TBot
do
1030 // Если имени нет, делаем его из UID бота
1032 Name
:= Format('DFBOT%.5d', [UID
])
1037 1: FDifficult
:= DIFFICULT_EASY
;
1038 2: FDifficult
:= DIFFICULT_MEDIUM
;
1039 else FDifficult
:= DIFFICULT_HARD
;
1042 for a
:= WP_FIRST
to WP_LAST
do
1044 FDifficult
.WeaponPrior
[a
] := WEAPON_PRIOR1
[a
];
1045 FDifficult
.CloseWeaponPrior
[a
] := WEAPON_PRIOR2
[a
];
1046 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
1049 FHandicap
:= Handicap
;
1051 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [Name
]), True);
1053 if g_Game_IsNet
then MH_SEND_PlayerCreate(UID
);
1054 if g_Game_IsServer
and (gGameSettings
.MaxLives
> 0) then
1059 procedure g_Bot_AddList(Team
: Byte; lName
: ShortString; num
: Integer = -1; Handicap
: Integer = 100);
1062 _name
, _model
: String;
1065 if not g_Game_IsServer
then Exit
;
1067 // Список названий моделей:
1068 m
:= g_PlayerModel_GetNames();
1073 if (gGameSettings
.GameType
= GT_SINGLE
) or (gGameSettings
.GameMode
= GM_COOP
) then
1074 Team
:= TEAM_COOP
// COOP
1076 if gGameSettings
.GameMode
= GM_DM
then
1077 Team
:= TEAM_NONE
// DM
1079 if Team
= TEAM_NONE
then
1080 Team
:= BotList
[num
].team
; // CTF / TDM
1082 // Выбираем настройки бота из списка по номеру или имени:
1083 lName
:= AnsiLowerCase(lName
);
1084 if (num
< 0) or (num
> Length(BotList
)-1) then
1086 if (num
= -1) and (lName
<> '') and (BotList
<> nil) then
1087 for a
:= 0 to High(BotList
) do
1088 if AnsiLowerCase(BotList
[a
].name
) = lName
then
1097 _name
:= BotList
[num
].name
;
1098 // Занято - выбираем случайное:
1099 if not g_Player_ValidName(_name
) then
1101 _name
:= Format('DFBOT%.2d', [Random(100)]);
1102 until g_Player_ValidName(_name
);
1105 _model
:= BotList
[num
].model
;
1106 // Нет такой - выбираем случайную:
1107 if not InSArray(_model
, m
) then
1108 _model
:= m
[Random(Length(m
))];
1111 with g_Player_Get(g_Player_Create(_model
, BotList
[num
].color
, Team
, True)) as TBot
do
1115 FDifficult
.DiagFire
:= BotList
[num
].diag_fire
;
1116 FDifficult
.InvisFire
:= BotList
[num
].invis_fire
;
1117 FDifficult
.DiagPrecision
:= BotList
[num
].diag_precision
;
1118 FDifficult
.FlyPrecision
:= BotList
[num
].fly_precision
;
1119 FDifficult
.Cover
:= BotList
[num
].cover
;
1120 FDifficult
.CloseJump
:= BotList
[num
].close_jump
;
1122 FHandicap
:= Handicap
;
1124 for a
:= WP_FIRST
to WP_LAST
do
1126 FDifficult
.WeaponPrior
[a
] := BotList
[num
].w_prior1
[a
];
1127 FDifficult
.CloseWeaponPrior
[a
] := BotList
[num
].w_prior2
[a
];
1128 //FDifficult.SafeWeaponPrior[a] := BotList[num].w_prior3[a];
1131 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [Name
]), True);
1133 if g_Game_IsNet
then MH_SEND_PlayerCreate(UID
);
1137 procedure g_Bot_RemoveAll();
1141 if not g_Game_IsServer
then Exit
;
1142 if gPlayers
= nil then Exit
;
1144 for a
:= 0 to High(gPlayers
) do
1145 if gPlayers
[a
] <> nil then
1146 if gPlayers
[a
] is TBot
then
1148 gPlayers
[a
].Lives
:= 0;
1149 gPlayers
[a
].Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
1150 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [gPlayers
[a
].Name
]), True);
1151 g_Player_Remove(gPlayers
[a
].FUID
);
1157 procedure g_Bot_MixNames();
1162 if BotNames
<> nil then
1163 for a
:= 0 to High(BotNames
) do
1165 b
:= Random(Length(BotNames
));
1167 Botnames
[a
] := BotNames
[b
];
1172 procedure g_Player_Remove(UID
: Word);
1176 if gPlayers
= nil then Exit
;
1178 if g_Game_IsServer
and g_Game_IsNet
then
1179 MH_SEND_PlayerDelete(UID
);
1181 for i
:= 0 to High(gPlayers
) do
1182 if gPlayers
[i
] <> nil then
1183 if gPlayers
[i
].FUID
= UID
then
1185 if gPlayers
[i
] is TPlayer
then
1186 TPlayer(gPlayers
[i
]).Free()
1188 TBot(gPlayers
[i
]).Free();
1194 procedure g_Player_Init();
1205 path
:= BOTNAMES_FILENAME
;
1206 if e_FindResource(DataDirs
, path
) = false then
1209 // Читаем возможные имена ботов из файла:
1210 AssignFile(F
, path
);
1221 SetLength(BotNames
, Length(BotNames
)+1);
1222 BotNames
[High(BotNames
)] := s
;
1230 // Читаем файл с параметрами ботов:
1231 config
:= TConfig
.CreateFile(path
);
1235 while config
.SectionExists(IntToStr(a
)) do
1237 SetLength(BotList
, Length(BotList
)+1);
1239 with BotList
[High(BotList
)] do
1242 name
:= config
.ReadStr(IntToStr(a
), 'name', '');
1244 model
:= config
.ReadStr(IntToStr(a
), 'model', '');
1246 if config
.ReadStr(IntToStr(a
), 'team', 'red') = 'red' then
1251 sa
:= parse(config
.ReadStr(IntToStr(a
), 'color', ''));
1252 color
.R
:= StrToIntDef(sa
[0], 0);
1253 color
.G
:= StrToIntDef(sa
[1], 0);
1254 color
.B
:= StrToIntDef(sa
[2], 0);
1255 // Вероятность стрельбы под углом:
1256 diag_fire
:= config
.ReadInt(IntToStr(a
), 'diag_fire', 0);
1257 // Вероятность ответного огня по невидимому сопернику:
1258 invis_fire
:= config
.ReadInt(IntToStr(a
), 'invis_fire', 0);
1259 // Точность стрельбы под углом:
1260 diag_precision
:= config
.ReadInt(IntToStr(a
), 'diag_precision', 0);
1261 // Точность стрельбы в полете:
1262 fly_precision
:= config
.ReadInt(IntToStr(a
), 'fly_precision', 0);
1263 // Точность уклонения от снарядов:
1264 cover
:= config
.ReadInt(IntToStr(a
), 'cover', 0);
1265 // Вероятность прыжка при приближении соперника:
1266 close_jump
:= config
.ReadInt(IntToStr(a
), 'close_jump', 0);
1267 // Приоритеты оружия для дальнего боя:
1268 sa
:= parse(config
.ReadStr(IntToStr(a
), 'w_prior1', ''));
1269 if Length(sa
) = 10 then
1271 w_prior1
[b
] := EnsureRange(StrToInt(sa
[b
]), 0, 9);
1272 // Приоритеты оружия для ближнего боя:
1273 sa
:= parse(config
.ReadStr(IntToStr(a
), 'w_prior2', ''));
1274 if Length(sa
) = 10 then
1276 w_prior2
[b
] := EnsureRange(StrToInt(sa
[b
]), 0, 9);
1278 {sa := parse(config.ReadStr(IntToStr(a), 'w_prior3', ''));
1279 if Length(sa) = 10 then
1281 w_prior3[b] := EnsureRange(StrToInt(sa[b]), 0, 9);}
1288 SetLength(SavedStates
, 0);
1291 procedure g_Player_Free();
1295 if gPlayers
<> nil then
1297 for i
:= 0 to High(gPlayers
) do
1298 if gPlayers
[i
] <> nil then
1300 if gPlayers
[i
] is TPlayer
then
1301 TPlayer(gPlayers
[i
]).Free()
1303 TBot(gPlayers
[i
]).Free();
1312 SetLength(SavedStates
, 0);
1315 procedure g_Player_PreUpdate();
1319 if gPlayers
= nil then Exit
;
1320 for i
:= 0 to High(gPlayers
) do
1321 if gPlayers
[i
] <> nil then
1322 gPlayers
[i
].PreUpdate();
1325 procedure g_Player_UpdateAll();
1329 if gPlayers
= nil then Exit
;
1331 //e_WriteLog('***g_Player_UpdateAll: ENTER', MSG_WARNING);
1332 for i
:= 0 to High(gPlayers
) do
1334 if gPlayers
[i
] <> nil then
1336 if gPlayers
[i
] is TPlayer
then
1338 gPlayers
[i
].Update();
1339 gPlayers
[i
].RealizeCurrentWeapon(); // WARNING! DO NOT MOVE THIS INTO `Update()`!
1343 // bot updates weapons in `UpdateCombat()`
1344 TBot(gPlayers
[i
]).Update();
1348 //e_WriteLog('***g_Player_UpdateAll: EXIT', MSG_WARNING);
1351 function g_Player_Get(UID
: Word): TPlayer
;
1357 if gPlayers
= nil then
1360 for a
:= 0 to High(gPlayers
) do
1361 if gPlayers
[a
] <> nil then
1362 if gPlayers
[a
].FUID
= UID
then
1364 Result
:= gPlayers
[a
];
1369 function g_Player_GetCount(): Byte;
1375 if gPlayers
= nil then
1378 for a
:= 0 to High(gPlayers
) do
1379 if gPlayers
[a
] <> nil then
1380 Result
:= Result
+ 1;
1383 function g_Player_GetStats(): TPlayerStatArray
;
1389 if gPlayers
= nil then Exit
;
1391 for a
:= 0 to High(gPlayers
) do
1392 if gPlayers
[a
] <> nil then
1394 SetLength(Result
, Length(Result
)+1);
1395 with Result
[High(Result
)] do
1398 Ping
:= gPlayers
[a
].FPing
;
1399 Loss
:= gPlayers
[a
].FLoss
;
1400 Name
:= gPlayers
[a
].FName
;
1401 Team
:= gPlayers
[a
].FTeam
;
1402 Frags
:= gPlayers
[a
].FFrags
;
1403 Deaths
:= gPlayers
[a
].FDeath
;
1404 Kills
:= gPlayers
[a
].FKills
;
1405 Color
:= gPlayers
[a
].FModel
.Color
;
1406 Lives
:= gPlayers
[a
].FLives
;
1407 Spectator
:= gPlayers
[a
].FSpectator
;
1408 UID
:= gPlayers
[a
].FUID
;
1413 procedure g_Player_ResetReady();
1417 if not g_Game_IsServer
then Exit
;
1418 if gPlayers
= nil then Exit
;
1420 for a
:= 0 to High(gPlayers
) do
1421 if gPlayers
[a
] <> nil then
1423 gPlayers
[a
].FReady
:= False;
1424 if g_Game_IsNet
then
1425 MH_SEND_GameEvent(NET_EV_INTER_READY
, gPlayers
[a
].UID
, 'N');
1429 procedure g_Player_RememberAll
;
1433 for i
:= Low(gPlayers
) to High(gPlayers
) do
1434 if (gPlayers
[i
] <> nil) and gPlayers
[i
].alive
then
1435 gPlayers
[i
].RememberState
;
1438 procedure g_Player_ResetAll(Force
, Silent
: Boolean);
1442 gTeamStat
[TEAM_RED
].Goals
:= 0;
1443 gTeamStat
[TEAM_BLUE
].Goals
:= 0;
1445 if gPlayers
<> nil then
1446 for i
:= 0 to High(gPlayers
) do
1447 if gPlayers
[i
] <> nil then
1449 gPlayers
[i
].Reset(Force
);
1451 if gPlayers
[i
] is TPlayer
then
1453 if (not gPlayers
[i
].FSpectator
) or gPlayers
[i
].FWantsInGame
then
1454 gPlayers
[i
].Respawn(Silent
)
1456 gPlayers
[i
].Spectate();
1459 TBot(gPlayers
[i
]).Respawn(Silent
);
1463 function g_Player_CreateCorpse(Player
: TPlayer
): Integer;
1471 if Player
.alive
then
1474 // Разрываем связь с прежним трупом:
1475 i
:= Player
.FCorpse
;
1476 if (i
>= 0) and (i
< Length(gCorpses
)) then
1478 if (gCorpses
[i
] <> nil) and (gCorpses
[i
].FPlayerUID
= Player
.FUID
) then
1479 gCorpses
[i
].FPlayerUID
:= 0;
1482 if Player
.FObj
.Y
>= gMapInfo
.Height
+128 then
1487 {$IFDEF ENABLE_GIBS}
1488 if (FHealth
< -50) and (gGibsCount
> 0) then
1490 g_Gibs_Create(FObj
.X
+ PLAYER_RECT_CX
, FObj
.Y
+ PLAYER_RECT_CY
, FModel
.id
, FModel
.Color
);
1495 if (gCorpses
= nil) or (Length(gCorpses
) = 0) then
1499 for find_id
:= 0 to High(gCorpses
) do
1500 if gCorpses
[find_id
] = nil then
1507 find_id
:= Random(Length(gCorpses
));
1509 gCorpses
[find_id
] := TCorpse
.Create(FObj
.X
, FObj
.Y
, FModel
.GetName(), FHealth
< -20);
1510 gCorpses
[find_id
].FModel
.Color
:= FModel
.Color
;
1511 gCorpses
[find_id
].FObj
.Vel
:= FObj
.Vel
;
1512 gCorpses
[find_id
].FObj
.Accel
:= FObj
.Accel
;
1513 gCorpses
[find_id
].FPlayerUID
:= FUID
;
1520 procedure g_Player_UpdatePhysicalObjects();
1523 if gCorpses
<> nil then
1524 for i
:= 0 to High(gCorpses
) do
1525 if gCorpses
[i
] <> nil then
1526 if gCorpses
[i
].State
= CORPSE_STATE_REMOVEME
then
1532 gCorpses
[i
].Update();
1535 procedure g_Player_RemoveAllCorpses();
1538 {$IFDEF ENABLE_GIBS}
1539 i
:= g_Gibs_GetMax();
1543 {$IFDEF ENABLE_SHELLS}
1544 i
:= g_Shells_GetMax();
1549 if gCorpses
<> nil then
1550 for i
:= 0 to High(gCorpses
) do
1554 SetLength(gCorpses
, MaxCorpses
);
1557 procedure g_Player_Corpses_SaveState (st
: TStream
);
1561 // Считаем количество существующих трупов
1563 for i
:= 0 to High(gCorpses
) do if (gCorpses
[i
] <> nil) then Inc(count
);
1565 // Количество трупов
1566 utils
.writeInt(st
, LongInt(count
));
1568 if (count
= 0) then exit
;
1571 for i
:= 0 to High(gCorpses
) do
1573 if gCorpses
[i
] <> nil then
1576 utils
.writeStr(st
, gCorpses
[i
].FModel
.GetName());
1578 utils
.writeBool(st
, gCorpses
[i
].Mess
);
1579 // Сохраняем данные трупа:
1580 gCorpses
[i
].SaveState(st
);
1586 procedure g_Player_Corpses_LoadState (st
: TStream
);
1594 g_Player_RemoveAllCorpses();
1596 // Количество трупов:
1597 count
:= utils
.readLongInt(st
);
1598 if (count
< 0) or (count
> Length(gCorpses
)) then raise XStreamError
.Create('invalid number of corpses');
1600 if (count
= 0) then exit
;
1603 for i
:= 0 to count
-1 do
1606 str
:= utils
.readStr(st
);
1608 b
:= utils
.readBool(st
);
1610 gCorpses
[i
] := TCorpse
.Create(0, 0, str
, b
);
1611 // Загружаем данные трупа
1612 gCorpses
[i
].LoadState(st
);
1619 function TPlayer
.isValidViewPort (): Boolean; inline; begin result
:= (viewPortW
> 0) and (viewPortH
> 0); end;
1621 procedure TPlayer
.BFGHit();
1623 g_Weapon_BFGHit(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
1624 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2));
1625 if g_Game_IsServer
and g_Game_IsNet
then
1626 MH_SEND_Effect(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
1627 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2),
1631 procedure TPlayer
.ChangeModel(ModelName
: string);
1633 locModel
: TPlayerModel
;
1635 locModel
:= g_PlayerModel_Get(ModelName
);
1636 if locModel
= nil then Exit
;
1642 procedure TPlayer
.SetModel(ModelName
: string);
1646 m
:= g_PlayerModel_Get(ModelName
);
1649 g_SimpleError(Format(_lc
[I_GAME_ERROR_MODEL_FALLBACK
], [ModelName
]));
1650 m
:= g_PlayerModel_Get('doomer');
1653 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], ['doomer']));
1658 if FModel
<> nil then
1663 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
1664 FModel
.Color
:= FColor
1666 FModel
.Color
:= TEAMCOLOR
[FTeam
];
1667 FModel
.SetWeapon(FCurrWeap
);
1668 FModel
.SetFlag(FFlag
);
1669 SetDirection(FDirection
);
1672 procedure TPlayer
.SetColor(Color
: TRGB
);
1675 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
1676 if FModel
<> nil then FModel
.Color
:= Color
;
1679 function TPlayer
.GetColor(): TRGB
;
1681 result
:= FModel
.Color
;
1684 procedure TPlayer
.SwitchTeam
;
1686 if g_Game_IsClient
then
1688 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then Exit
;
1690 if gGameOn
and FAlive
then
1691 Kill(K_SIMPLEKILL
, FUID
, HIT_SELF
);
1693 if FTeam
= TEAM_RED
then
1695 ChangeTeam(TEAM_BLUE
);
1696 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_BLUE
], [FName
]), True);
1697 if g_Game_IsNet
then
1698 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM
, TEAM_BLUE
, FName
);
1702 ChangeTeam(TEAM_RED
);
1703 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_RED
], [FName
]), True);
1704 if g_Game_IsNet
then
1705 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM
, TEAM_RED
, FName
);
1707 FPreferredTeam
:= FTeam
;
1710 procedure TPlayer
.ChangeTeam(Team
: Byte);
1717 TEAM_RED
, TEAM_BLUE
:
1718 FModel
.Color
:= TEAMCOLOR
[Team
];
1720 FModel
.Color
:= FColor
;
1722 if (FTeam
<> OldTeam
) and g_Game_IsNet
and g_Game_IsServer
then
1723 MH_SEND_PlayerStats(FUID
);
1727 procedure TPlayer.CollideItem();
1732 if gItems = nil then Exit;
1733 if not FAlive then Exit;
1735 for i := 0 to High(gItems) do
1738 if (ItemType <> ITEM_NONE) and alive then
1739 if g_Obj_Collide(FObj.X+PLAYER_RECT.X, FObj.Y+PLAYER_RECT.Y, PLAYER_RECT.Width,
1740 PLAYER_RECT.Height, @Obj) then
1742 if not PickItem(ItemType, gItems[i].Respawnable, r) then Continue;
1744 if ItemType in [ITEM_SPHERE_BLUE, ITEM_SPHERE_WHITE, ITEM_INVUL] then
1745 g_Sound_PlayExAt('SOUND_ITEM_GETRULEZ', FObj.X, FObj.Y)
1746 else if ItemType in [ITEM_MEDKIT_SMALL, ITEM_MEDKIT_LARGE, ITEM_MEDKIT_BLACK] then
1747 g_Sound_PlayExAt('SOUND_ITEM_GETMED', FObj.X, FObj.Y)
1748 else g_Sound_PlayExAt('SOUND_ITEM_GETITEM', FObj.X, FObj.Y);
1750 // Надо убрать с карты, если это не ключ, которым нужно поделится с другим игроком:
1751 if r and not ((ItemType in [ITEM_KEY_RED, ITEM_KEY_GREEN, ITEM_KEY_BLUE]) and
1752 (gGameSettings.GameType = GT_SINGLE) and
1753 (g_Player_GetCount() > 1)) then
1754 if not Respawnable then g_Items_Remove(i) else g_Items_Pick(i);
1760 function TPlayer
.CollideLevel(XInc
, YInc
: Integer): Boolean;
1762 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
1763 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_WALL
,
1767 constructor TPlayer
.Create();
1773 mEDamageType
:= HIT_SOME
;
1779 FSawSound
:= TPlayableSound
.Create();
1780 FSawSoundIdle
:= TPlayableSound
.Create();
1781 FSawSoundHit
:= TPlayableSound
.Create();
1782 FSawSoundSelect
:= TPlayableSound
.Create();
1783 FFlameSoundOn
:= TPlayableSound
.Create();
1784 FFlameSoundOff
:= TPlayableSound
.Create();
1785 FFlameSoundWork
:= TPlayableSound
.Create();
1786 FJetSoundFly
:= TPlayableSound
.Create();
1787 FJetSoundOn
:= TPlayableSound
.Create();
1788 FJetSoundOff
:= TPlayableSound
.Create();
1790 FSawSound
.SetByName('SOUND_WEAPON_FIRESAW');
1791 FSawSoundIdle
.SetByName('SOUND_WEAPON_IDLESAW');
1792 FSawSoundHit
.SetByName('SOUND_WEAPON_HITSAW');
1793 FSawSoundSelect
.SetByName('SOUND_WEAPON_SELECTSAW');
1794 FFlameSoundOn
.SetByName('SOUND_WEAPON_FLAMEON');
1795 FFlameSoundOff
.SetByName('SOUND_WEAPON_FLAMEOFF');
1796 FFlameSoundWork
.SetByName('SOUND_WEAPON_FLAMEWORK');
1797 FJetSoundFly
.SetByName('SOUND_PLAYER_JETFLY');
1798 FJetSoundOn
.SetByName('SOUND_PLAYER_JETON');
1799 FJetSoundOff
.SetByName('SOUND_PLAYER_JETOFF');
1801 FSpectatePlayer
:= -1;
1805 FSavedStateNum
:= -1;
1806 {$IFDEF ENABLE_SHELLS}
1815 FActualModelName
:= 'doomer';
1818 FObj
.Rect
:= PLAYER_RECT
;
1820 FBFGFireCounter
:= -1;
1821 FJustTeleported
:= False;
1824 FWaitForFirstSpawn
:= false;
1825 FPunchAnim
:= TAnimationState
.Create(False, 1, 4);
1831 procedure TPlayer
.positionChanged (); inline;
1835 procedure TPlayer
.doDamage (v
: Integer);
1837 if (v
<= 0) then exit
;
1838 if (v
> 32767) then v
:= 32767;
1839 Damage(v
, 0, 0, 0, mEDamageType
);
1842 procedure TPlayer
.Damage(value
: Word; SpawnerUID
: Word; vx
, vy
: Integer; t
: Byte);
1846 if (not g_Game_IsClient
) and (not FAlive
) then
1851 // Неуязвимость не спасает от ловушек:
1852 if ((t
= HIT_TRAP
) or (t
= HIT_SELF
)) and (not FGodMode
) then
1854 if not g_Game_IsClient
then
1857 if t
= HIT_TRAP
then
1859 // Ловушка убивает сразу:
1861 Kill(K_EXTRAHARDKILL
, SpawnerUID
, t
);
1863 if t
= HIT_SELF
then
1867 Kill(K_SIMPLEKILL
, SpawnerUID
, t
);
1870 // Обнулить действия примочек, чтобы фон пропал
1871 FMegaRulez
[MR_SUIT
] := 0;
1872 FMegaRulez
[MR_INVUL
] := 0;
1873 FMegaRulez
[MR_INVIS
] := 0;
1878 // Но от остального спасает:
1879 if FMegaRulez
[MR_INVUL
] >= gTime
then
1886 // Если есть урон своим, или ранил сам себя, или тебя ранил противник:
1887 if LongBool(gGameSettings
.Options
and GAME_OPTION_TEAMDAMAGE
) or
1888 (SpawnerUID
= FUID
) or
1889 (not SameTeam(FUID
, SpawnerUID
)) then
1891 FLastSpawnerUID
:= SpawnerUID
;
1893 // Кровь (пузырьки, если в воде):
1894 if gBloodCount
> 0 then
1896 c
:= Min(value
, 200)*gBloodCount
+ Random(Min(value
, 200) div 2);
1897 if value
div 4 <= c
then
1898 c
:= c
- (value
div 4)
1902 if (t
= HIT_SOME
) and (vx
= 0) and (vy
= 0) then
1906 HIT_TRAP
, HIT_ACID
, HIT_FLAME
, HIT_SELF
: MakeBloodSimple(c
);
1907 HIT_BFG
, HIT_ROCKET
, HIT_SOME
: MakeBloodVector(c
, vx
, vy
);
1911 if t
= HIT_WATER
then
1913 g_GFX_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
1914 FObj
.Y
+PLAYER_RECT
.Y
-4, value
div 2, 8, 4);
1921 Inc(FDamageBuffer
, value
);
1925 FPain
:= FPain
+ value
;
1928 if g_Game_IsServer
and g_Game_IsNet
then
1930 MH_SEND_PlayerDamage(FUID
, t
, SpawnerUID
, value
, vx
, vy
);
1931 MH_SEND_PlayerStats(FUID
);
1932 MH_SEND_PlayerPos(False, FUID
);
1936 function TPlayer
.Heal(value
: Word; Soft
: Boolean): Boolean;
1939 if g_Game_IsClient
then
1944 if Soft
and (FHealth
< PLAYER_HP_SOFT
) then
1946 IncMax(FHealth
, value
, PLAYER_HP_SOFT
);
1949 if (not Soft
) and (FHealth
< PLAYER_HP_LIMIT
) then
1951 IncMax(FHealth
, value
, PLAYER_HP_LIMIT
);
1955 if Result
and g_Game_IsServer
and g_Game_IsNet
then
1956 MH_SEND_PlayerStats(FUID
);
1959 destructor TPlayer
.Destroy();
1961 if (gPlayer1
<> nil) and (gPlayer1
.FUID
= FUID
) then
1963 if (gPlayer2
<> nil) and (gPlayer2
.FUID
= FUID
) then
1967 FSawSoundIdle
.Free();
1968 FSawSoundHit
.Free();
1969 FSawSoundSelect
.Free();
1970 FFlameSoundOn
.Free();
1971 FFlameSoundOff
.Free();
1972 FFlameSoundWork
.Free();
1973 FJetSoundFly
.Free();
1975 FJetSoundOff
.Free();
1982 procedure TPlayer
.DoPunch();
1988 procedure TPlayer
.Fire();
1990 f
, DidFire
: Boolean;
1991 wx
, wy
, xd
, yd
: Integer;
1994 if g_Game_IsClient
then Exit
;
1995 // FBFGFireCounter - время перед выстрелом (для BFG)
1996 // FReloading - время после выстрела (для всего)
2004 if FReloading
[FCurrWeap
] <> 0 then Exit
;
2009 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
2010 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
2011 xd
:= wx
+IfThen(FDirection
= TDirection
.D_LEFT
, -30, 30);
2012 yd
:= wy
+firediry();
2018 if R_BERSERK
in FRulez
then
2020 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
2021 locobj
.X
:= FObj
.X
+FObj
.Rect
.X
;
2022 locobj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
2025 locobj
.rect
.Width
:= 39;
2026 locobj
.rect
.Height
:= 52;
2027 locobj
.Vel
.X
:= (xd
-wx
) div 2;
2028 locobj
.Vel
.Y
:= (yd
-wy
) div 2;
2029 locobj
.Accel
.X
:= xd
-wx
;
2030 locobj
.Accel
.y
:= yd
-wy
;
2032 if g_Weapon_Hit(@locobj
, 50, FUID
, HIT_SOME
) <> 0 then
2033 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
2035 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
2037 if (gFlash
= 1) and (FPain
< 50) then FPain
:= min(FPain
+ 25, 50);
2041 g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
2045 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2050 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
2051 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
2053 FSawSoundSelect
.Stop();
2055 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
2057 else if not FSawSoundHit
.IsPlaying() then
2059 FSawSoundSelect
.Stop();
2060 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
2063 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2069 if FAmmo
[A_BULLETS
] > 0 then
2071 g_Weapon_pistol(wx
, wy
, xd
, yd
, FUID
);
2072 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2073 Dec(FAmmo
[A_BULLETS
]);
2074 FFireAngle
:= FAngle
;
2077 {$IFDEF ENABLE_SHELLS}
2078 g_Shells_Create(GameX
+ PLAYER_RECT_CX
, GameY
+ PLAYER_RECT_CX
, GameVelX
, GameVelY
- 2, SHELL_BULLET
);
2083 if FAmmo
[A_SHELLS
] > 0 then
2085 g_Weapon_shotgun(wx
, wy
, xd
, yd
, FUID
);
2086 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', wx
, wy
);
2087 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2088 Dec(FAmmo
[A_SHELLS
]);
2089 FFireAngle
:= FAngle
;
2092 {$IFDEF ENABLE_SHELLS}
2094 FShellType
:= SHELL_SHELL
;
2099 if FAmmo
[A_SHELLS
] >= 2 then
2101 g_Weapon_dshotgun(wx
, wy
, xd
, yd
, FUID
);
2102 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2103 Dec(FAmmo
[A_SHELLS
], 2);
2104 FFireAngle
:= FAngle
;
2107 {$IFDEF ENABLE_SHELLS}
2109 FShellType
:= SHELL_DBLSHELL
;
2114 if FAmmo
[A_BULLETS
] > 0 then
2116 g_Weapon_mgun(wx
, wy
, xd
, yd
, FUID
);
2117 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', wx
, wy
);
2118 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2119 Dec(FAmmo
[A_BULLETS
]);
2120 FFireAngle
:= FAngle
;
2123 {$IFDEF ENABLE_SHELLS}
2124 g_Shells_Create(GameX
+ PLAYER_RECT_CX
, GameY
+ PLAYER_RECT_CX
, GameVelX
, GameVelY
- 2, SHELL_BULLET
);
2128 WEAPON_ROCKETLAUNCHER
:
2129 if FAmmo
[A_ROCKETS
] > 0 then
2131 g_Weapon_rocket(wx
, wy
, xd
, yd
, FUID
);
2132 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2133 Dec(FAmmo
[A_ROCKETS
]);
2134 FFireAngle
:= FAngle
;
2140 if FAmmo
[A_CELLS
] > 0 then
2142 g_Weapon_plasma(wx
, wy
, xd
, yd
, FUID
);
2143 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2144 Dec(FAmmo
[A_CELLS
]);
2145 FFireAngle
:= FAngle
;
2151 if (FAmmo
[A_CELLS
] >= 40) and (FBFGFireCounter
= -1) then
2153 FBFGFireCounter
:= 17;
2154 if not FNoReload
then
2155 g_Sound_PlayExAt('SOUND_WEAPON_STARTFIREBFG', FObj
.X
, FObj
.Y
);
2156 Dec(FAmmo
[A_CELLS
], 40);
2160 WEAPON_SUPERPULEMET
:
2161 if FAmmo
[A_SHELLS
] > 0 then
2163 g_Weapon_shotgun(wx
, wy
, xd
, yd
, FUID
);
2164 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', wx
, wy
);
2165 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2166 Dec(FAmmo
[A_SHELLS
]);
2167 FFireAngle
:= FAngle
;
2170 {$IFDEF ENABLE_SHELLS}
2171 g_Shells_Create(GameX
+ PLAYER_RECT_CX
, GameY
+ PLAYER_RECT_CX
, GameVelX
, GameVelY
- 2, SHELL_SHELL
);
2175 WEAPON_FLAMETHROWER
:
2176 if FAmmo
[A_FUEL
] > 0 then
2178 g_Weapon_flame(wx
, wy
, xd
, yd
, FUID
);
2180 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2182 FFireAngle
:= FAngle
;
2189 if g_Game_IsNet
and g_Game_IsServer
then MH_SEND_PlayerStats(FUID
);
2193 if g_Game_IsNet
then
2197 if FCurrWeap
<> WEAPON_BFG
then
2198 MH_SEND_PlayerFire(FUID
, FCurrWeap
, wx
, wy
, xd
, yd
, LastShotID
)
2200 if not FNoReload
then
2201 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_WEAPON_STARTFIREBFG');
2204 MH_SEND_PlayerStats(FUID
);
2209 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
2210 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
2211 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
2214 function TPlayer
.GetAmmoByWeapon(Weapon
: Byte): Word;
2217 WEAPON_PISTOL
, WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
];
2218 WEAPON_SHOTGUN1
, WEAPON_SHOTGUN2
, WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
];
2219 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
];
2220 WEAPON_PLASMA
, WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
];
2221 WEAPON_FLAMETHROWER
: Result
:= FAmmo
[A_FUEL
];
2226 function TPlayer
.HeadInLiquid(XInc
, YInc
: Integer): Boolean;
2228 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
+XInc
, FObj
.Y
+PLAYER_HEADRECT
.Y
+YInc
,
2229 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
2230 PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, True);
2233 procedure TPlayer
.FlamerOn
;
2235 FFlameSoundOff
.Stop();
2236 FFlameSoundOff
.SetPosition(0);
2239 if (not FFlameSoundOn
.IsPlaying()) and (not FFlameSoundWork
.IsPlaying()) then
2240 FFlameSoundWork
.PlayAt(FObj
.X
, FObj
.Y
);
2244 FFlameSoundOn
.PlayAt(FObj
.X
, FObj
.Y
);
2249 procedure TPlayer
.FlamerOff
;
2253 FFlameSoundOn
.Stop();
2254 FFlameSoundOn
.SetPosition(0);
2255 FFlameSoundWork
.Stop();
2256 FFlameSoundWork
.SetPosition(0);
2257 FFlameSoundOff
.PlayAt(FObj
.X
, FObj
.Y
);
2262 procedure TPlayer
.JetpackOn
;
2266 FJetSoundOn
.SetPosition(0);
2267 FJetSoundOn
.PlayAt(FObj
.X
, FObj
.Y
);
2271 procedure TPlayer
.JetpackOff
;
2275 FJetSoundOff
.SetPosition(0);
2276 FJetSoundOff
.PlayAt(FObj
.X
, FObj
.Y
);
2279 procedure TPlayer
.CatchFire(Attacker
: Word; Timeout
: Integer = PLAYER_BURN_TIME
);
2281 if Timeout
<= 0 then
2283 if (FMegaRulez
[MR_SUIT
] > gTime
) or (FMegaRulez
[MR_INVUL
] > gTime
) then
2284 exit
; // Не загораемся когда есть защита
2285 if g_Obj_CollidePanel(@FObj
, 0, 0, PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
) then
2286 exit
; // Не подгораем в воде на всякий случай
2287 if FFireTime
<= 0 then
2288 g_Sound_PlayExAt('SOUND_IGNITE', FObj
.X
, FObj
.Y
);
2289 FFireTime
:= Timeout
;
2290 FFireAttacker
:= Attacker
;
2291 if g_Game_IsNet
and g_Game_IsServer
then
2292 MH_SEND_PlayerStats(FUID
);
2295 procedure TPlayer
.Jump();
2297 if gFly
or FJetpack
then
2299 // Полет (чит-код или джетпак):
2300 if FObj
.Vel
.Y
> -VEL_FLY
then
2301 FObj
.Vel
.Y
:= FObj
.Vel
.Y
- 3;
2304 if FJetFuel
> 0 then
2306 if (FJetFuel
< 1) and g_Game_IsServer
then
2310 if g_Game_IsNet
then
2311 MH_SEND_PlayerStats(FUID
);
2317 // Не включать джетпак в режиме прохождения сквозь стены
2319 FCanJetpack
:= False;
2321 // Прыгаем или всплываем:
2322 if (CollideLevel(0, 1) or
2323 g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
+36, PLAYER_RECT
.Width
,
2324 PLAYER_RECT
.Height
-33, PANEL_STEP
, False)
2325 ) and (FObj
.Accel
.Y
= 0) then // Не прыгать, если есть вертикальное ускорение
2327 FObj
.Vel
.Y
:= -VEL_JUMP
;
2328 FCanJetpack
:= False;
2332 if BodyInLiquid(0, 0) then
2333 FObj
.Vel
.Y
:= -VEL_SW
2334 else if (FJetFuel
> 0) and FCanJetpack
and
2335 g_Game_IsServer
and (not g_Obj_CollideLiquid(@FObj
, 0, 0)) then
2339 if g_Game_IsNet
then
2340 MH_SEND_PlayerStats(FUID
);
2345 procedure TPlayer
.Kill(KillType
: Byte; SpawnerUID
: Word; t
: Byte);
2347 a
, i
, k
, ab
, ar
: Byte;
2351 srv
, netsrv
: Boolean;
2357 procedure PushItem(t
: Byte);
2361 id
:= g_Items_Create(FObj
.X
, FObj
.Y
, t
, True, False);
2362 it
:= g_Items_ByIdx(id
);
2363 if KillType
= K_EXTRAHARDKILL
then // -7..+7; -8..0
2365 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-7+Random(15),
2366 (FObj
.Vel
.Y
div 2)-Random(9));
2367 it
.positionChanged(); // this updates spatial accelerators
2371 if KillType
= K_HARDKILL
then // -5..+5; -5..0
2373 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-5+Random(11),
2374 (FObj
.Vel
.Y
div 2)-Random(6));
2376 else // -3..+3; -3..0
2378 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-3+Random(7),
2379 (FObj
.Vel
.Y
div 2)-Random(4));
2381 it
.positionChanged(); // this updates spatial accelerators
2384 if g_Game_IsNet
and g_Game_IsServer
then
2385 MH_SEND_ItemSpawn(True, id
);
2389 DoFrags
:= (gGameSettings
.MaxLives
= 0) or (gGameSettings
.GameMode
= GM_COOP
);
2390 Srv
:= g_Game_IsServer
;
2391 Netsrv
:= g_Game_IsServer
and g_Game_IsNet
;
2392 if Srv
then FDeath
:= FDeath
+ 1;
2397 if not FPhysics
then
2402 {$IFDEF ENABLE_SHELLS}
2406 if (gGameSettings
.MaxLives
> 0) and Srv
and (gLMSRespawn
= LMS_RESPAWN_NONE
) then
2408 if FLives
> 0 then FLives
:= FLives
- 1;
2409 if FLives
= 0 then FNoRespawn
:= True;
2412 // Номер типа смерти:
2415 K_SIMPLEKILL
: a
:= 1;
2417 K_EXTRAHARDKILL
: a
:= 3;
2422 if not FModel
.PlaySound(MODELSOUND_DIE
, a
, FObj
.X
, FObj
.Y
) then
2424 if FModel
.PlaySound(MODELSOUND_DIE
, i
, FObj
.X
, FObj
.Y
) then
2431 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN1
;
2433 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN2
;
2434 K_EXTRAHARDKILL
, K_FALLKILL
:
2435 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN3
;
2438 // Переключаем состояние:
2442 K_HARDKILL
, K_EXTRAHARDKILL
:
2446 // Реакция монстров на смерть игрока:
2447 if (KillType
<> K_FALLKILL
) and (Srv
) then
2448 g_Monsters_killedp();
2450 if SpawnerUID
= FUID
then
2452 if Srv
and (DoFrags
or (gGameSettings
.GameMode
= GM_TDM
)) then
2457 g_Console_Add(Format(_lc
[I_PLAYER_KILL_SELF
], [FName
]), True);
2460 if g_GetUIDType(SpawnerUID
) = UID_PLAYER
then
2461 begin // Убит другим игроком
2462 KP
:= g_Player_Get(SpawnerUID
);
2463 if (KP
<> nil) and Srv
then
2465 if (DoFrags
or (gGameSettings
.GameMode
= GM_TDM
)) then
2466 if SameTeam(FUID
, SpawnerUID
) then
2476 if (gGameSettings
.GameMode
= GM_TDM
) and DoFrags
then
2477 Inc(gTeamStat
[KP
.Team
].Goals
,
2478 IfThen(SameTeam(FUID
, SpawnerUID
), -1, 1));
2480 if netsrv
then MH_SEND_PlayerStats(SpawnerUID
);
2483 plr
:= g_Player_Get(SpawnerUID
);
2491 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_2
],
2495 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_1
],
2499 g_Console_Add(Format(_lc
[I_PLAYER_KILL
],
2504 else if g_GetUIDType(SpawnerUID
) = UID_MONSTER
then
2505 begin // Убит монстром
2506 mon
:= g_Monsters_ByUID(SpawnerUID
);
2510 s
:= g_Mons_GetKilledByTypeId(mon
.MonsterType
);
2514 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_2
],
2518 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_1
],
2522 g_Console_Add(Format(_lc
[I_PLAYER_KILL
],
2527 else // Особые типы смерти
2530 HIT_SELF
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_SELF
], [FName
]), True);
2531 HIT_FALL
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_FALL
], [FName
]), True);
2532 HIT_WATER
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_WATER
], [FName
]), True);
2533 HIT_ACID
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_ACID
], [FName
]), True);
2534 HIT_TRAP
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_TRAP
], [FName
]), True);
2535 else g_Console_Add(Format(_lc
[I_PLAYER_DIED
], [FName
]), True);
2541 for a
:= WP_FIRST
to WP_LAST
do
2545 WEAPON_SAW
: i
:= ITEM_WEAPON_SAW
;
2546 WEAPON_SHOTGUN1
: i
:= ITEM_WEAPON_SHOTGUN1
;
2547 WEAPON_SHOTGUN2
: i
:= ITEM_WEAPON_SHOTGUN2
;
2548 WEAPON_CHAINGUN
: i
:= ITEM_WEAPON_CHAINGUN
;
2549 WEAPON_ROCKETLAUNCHER
: i
:= ITEM_WEAPON_ROCKETLAUNCHER
;
2550 WEAPON_PLASMA
: i
:= ITEM_WEAPON_PLASMA
;
2551 WEAPON_BFG
: i
:= ITEM_WEAPON_BFG
;
2552 WEAPON_SUPERPULEMET
: i
:= ITEM_WEAPON_SUPERPULEMET
;
2553 WEAPON_FLAMETHROWER
: i
:= ITEM_WEAPON_FLAMETHROWER
;
2562 if R_ITEM_BACKPACK
in FRulez
then
2563 PushItem(ITEM_AMMO_BACKPACK
);
2565 // Выброс ракетного ранца:
2566 if FJetFuel
> 0 then
2567 PushItem(ITEM_JETPACK
);
2570 if (not (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
])) or
2571 (not LongBool(gGameSettings
.Options
and GAME_OPTION_DMKEYS
)) then
2573 if R_KEY_RED
in FRulez
then
2574 PushItem(ITEM_KEY_RED
);
2576 if R_KEY_GREEN
in FRulez
then
2577 PushItem(ITEM_KEY_GREEN
);
2579 if R_KEY_BLUE
in FRulez
then
2580 PushItem(ITEM_KEY_BLUE
);
2584 DropFlag(KillType
= K_FALLKILL
);
2587 FCorpse
:= g_Player_CreateCorpse(Self
);
2589 if Srv
and (gGameSettings
.MaxLives
> 0) and FNoRespawn
and
2590 (gLMSRespawn
= LMS_RESPAWN_NONE
) then
2596 for i
:= Low(gPlayers
) to High(gPlayers
) do
2598 if gPlayers
[i
] = nil then continue
;
2599 if (not gPlayers
[i
].FNoRespawn
) and (not gPlayers
[i
].FSpectator
) then
2602 if gPlayers
[i
].FTeam
= TEAM_RED
then Inc(ar
)
2603 else if gPlayers
[i
].FTeam
= TEAM_BLUE
then Inc(ab
);
2608 OldLR
:= gLMSRespawn
;
2609 if (gGameSettings
.GameMode
= GM_COOP
) then
2613 // everyone is dead, restart the map
2614 g_Game_Message(_lc
[I_MESSAGE_LMS_LOSE
], 144);
2616 MH_SEND_GameEvent(NET_EV_LMS_LOSE
);
2617 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
2618 gLMSRespawnTime
:= gTime
+ 5000;
2620 else if (a
= 1) then
2622 if (gPlayers
[k
] <> nil) and not (gPlayers
[k
] is TBot
) then
2623 if (gPlayers
[k
] = gPlayer1
) or
2624 (gPlayers
[k
] = gPlayer2
) then
2625 g_Console_Add('*** ' + _lc
[I_MESSAGE_LMS_SURVIVOR
] + ' ***', True)
2626 else if Netsrv
and (gPlayers
[k
].FClientID
>= 0) then
2627 MH_SEND_GameEvent(NET_EV_LMS_SURVIVOR
, 0, 'N', gPlayers
[k
].FClientID
);
2630 else if (gGameSettings
.GameMode
= GM_TDM
) then
2632 if (ab
= 0) and (ar
<> 0) then
2635 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 144);
2637 MH_SEND_GameEvent(NET_EV_TLMS_WIN
, TEAM_RED
);
2638 Inc(gTeamStat
[TEAM_RED
].Goals
);
2639 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
2640 gLMSRespawnTime
:= gTime
+ 5000;
2642 else if (ar
= 0) and (ab
<> 0) then
2645 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 144);
2647 MH_SEND_GameEvent(NET_EV_TLMS_WIN
, TEAM_BLUE
);
2648 Inc(gTeamStat
[TEAM_BLUE
].Goals
);
2649 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
2650 gLMSRespawnTime
:= gTime
+ 5000;
2652 else if (ar
= 0) and (ab
= 0) then
2655 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
2657 MH_SEND_GameEvent(NET_EV_LMS_DRAW
, 0, FName
);
2658 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
2659 gLMSRespawnTime
:= gTime
+ 5000;
2662 else if (gGameSettings
.GameMode
= GM_DM
) then
2666 if gPlayers
[k
] <> nil then
2669 // survivor is the winner
2670 g_Game_Message(Format(_lc
[I_MESSAGE_LMS_WIN
], [AnsiUpperCase(FName
)]), 144);
2672 MH_SEND_GameEvent(NET_EV_LMS_WIN
, 0, FName
);
2675 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
2676 gLMSRespawnTime
:= gTime
+ 5000;
2678 else if (a
= 0) then
2680 // everyone is dead, restart the map
2681 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
2683 MH_SEND_GameEvent(NET_EV_LMS_DRAW
, 0, FName
);
2684 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
2685 gLMSRespawnTime
:= gTime
+ 5000;
2688 if srv
and (OldLR
= LMS_RESPAWN_NONE
) and (gLMSRespawn
> LMS_RESPAWN_NONE
) then
2690 if NetMode
= NET_SERVER
then
2691 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
)
2693 g_Console_Add(Format(_lc
[I_MSG_WARMUP_START
], [(gLMSRespawnTime
- gTime
) div 1000]), True);
2699 MH_SEND_PlayerStats(FUID
);
2700 MH_SEND_PlayerDeath(FUID
, KillType
, t
, SpawnerUID
);
2701 if gGameSettings
.GameMode
= GM_TDM
then MH_SEND_GameStats
;
2704 if srv
and FNoRespawn
then Spectate(True);
2705 FWantsInGame
:= True;
2708 function TPlayer
.BodyInLiquid(XInc
, YInc
: Integer): Boolean;
2710 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
, PLAYER_RECT
.Width
,
2711 PLAYER_RECT
.Height
-20, PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, False);
2714 function TPlayer
.BodyInAcid(XInc
, YInc
: Integer): Boolean;
2716 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
, PLAYER_RECT
.Width
,
2717 PLAYER_RECT
.Height
-20, PANEL_ACID1
or PANEL_ACID2
, False);
2720 procedure TPlayer
.MakeBloodSimple(Count
: Word);
2722 var Blood
: TModelBlood
;
2726 Blood
:= SELF
.FModel
.GetBlood();
2727 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)+8,
2728 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
2729 Count
div 2, 3, -1, 16, (PLAYER_RECT
.Height
*2 div 3),
2730 Blood
.R
, Blood
.G
, Blood
.B
, Blood
.Kind
);
2731 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-8,
2732 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
2733 Count
div 2, -3, -1, 16, (PLAYER_RECT
.Height
*2) div 3,
2734 Blood
.R
, Blood
.G
, Blood
.B
, Blood
.Kind
);
2738 procedure TPlayer
.MakeBloodVector(Count
: Word; VelX
, VelY
: Integer);
2740 var Blood
: TModelBlood
;
2744 Blood
:= SELF
.FModel
.GetBlood();
2745 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
2746 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
2747 Count
, VelX
, VelY
, 16, (PLAYER_RECT
.Height
*2) div 3,
2748 Blood
.R
, Blood
.G
, Blood
.B
, Blood
.Kind
);
2752 procedure TPlayer
.QueueWeaponSwitch(Weapon
: Byte);
2754 if g_Game_IsClient
then Exit
;
2755 if Weapon
> High(FWeapon
) then Exit
;
2756 FNextWeap
:= FNextWeap
or (1 shl Weapon
);
2759 procedure TPlayer
.resetWeaponQueue ();
2762 FNextWeapDelay
:= 0;
2765 function TPlayer
.hasAmmoForWeapon (weapon
: Byte): Boolean;
2769 WEAPON_KASTET
, WEAPON_SAW
: result
:= true;
2770 WEAPON_SHOTGUN1
, WEAPON_SHOTGUN2
, WEAPON_SUPERPULEMET
: result
:= (FAmmo
[A_SHELLS
] > 0);
2771 WEAPON_PISTOL
, WEAPON_CHAINGUN
: result
:= (FAmmo
[A_BULLETS
] > 0);
2772 WEAPON_ROCKETLAUNCHER
: result
:= (FAmmo
[A_ROCKETS
] > 0);
2773 WEAPON_PLASMA
, WEAPON_BFG
: result
:= (FAmmo
[A_CELLS
] > 0);
2774 WEAPON_FLAMETHROWER
: result
:= (FAmmo
[A_FUEL
] > 0);
2775 else result
:= (weapon
< length(FWeapon
));
2779 // return 255 for "no switch"
2780 function TPlayer
.getNextWeaponIndex (): Byte;
2783 wantThisWeapon
: array[0..64] of Boolean;
2784 wwc
: Integer = 0; //HACK!
2787 result
:= 255; // default result: "no switch"
2788 // had weapon cycling on previous frame? remove that flag
2789 if (FNextWeap
and $2000) <> 0 then
2791 FNextWeap
:= FNextWeap
and $1FFF;
2792 FNextWeapDelay
:= 0;
2794 // cycling has priority
2795 if (FNextWeap
and $C000) <> 0 then
2797 if (FNextWeap
and $8000) <> 0 then
2801 FNextWeap
:= FNextWeap
or $2000; // we need this
2802 if FNextWeapDelay
> 0 then
2803 exit
; // cooldown time
2805 for i
:= 0 to High(FWeapon
) do
2807 cwi
:= (cwi
+length(FWeapon
)+dir
) mod length(FWeapon
);
2808 if FWeapon
[cwi
] then
2810 //e_WriteLog(Format(' SWITCH: cur=%d; new=%d', [FCurrWeap, cwi]), MSG_WARNING);
2811 result
:= Byte(cwi
);
2812 FNextWeapDelay
:= WEAPON_DELAY
;
2820 for i
:= 0 to High(wantThisWeapon
) do
2821 wantThisWeapon
[i
] := false;
2822 for i
:= 0 to High(FWeapon
) do
2823 if (FNextWeap
and (1 shl i
)) <> 0 then
2825 wantThisWeapon
[i
] := true;
2828 // exclude currently selected weapon from the set
2829 wantThisWeapon
[FCurrWeap
] := false;
2830 // slow down alterations a little
2833 //e_WriteLog(Format(' FNextWeap=%x; delay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
2834 // more than one weapon requested, assume "alteration" and check alteration delay
2835 if FNextWeapDelay
> 0 then
2841 // do not reset weapon queue, it will be done in `RealizeCurrentWeapon()`
2842 // but clear all counters if no weapon should be switched
2848 //e_WriteLog(Format('wwc=%d', [wwc]), MSG_WARNING);
2849 // try weapons in descending order
2850 for i
:= High(FWeapon
) downto 0 do
2852 if wantThisWeapon
[i
] and FWeapon
[i
] and ((wwc
= 1) or hasAmmoForWeapon(i
)) then
2857 FNextWeapDelay
:= WEAPON_DELAY
* 2; // anyway, 'cause why not
2861 // no suitable weapon found, so reset the queue, to avoid accidental "queuing" of weapon w/o ammo
2865 procedure TPlayer
.RealizeCurrentWeapon();
2866 function switchAllowed (): Boolean;
2871 if FBFGFireCounter
<> -1 then
2873 if FTime
[T_SWITCH
] > gTime
then
2875 for i
:= WP_FIRST
to WP_LAST
do
2876 if FReloading
[i
] > 0 then
2884 //e_WriteLog(Format('***RealizeCurrentWeapon: FNextWeap=%x; FNextWeapDelay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
2885 //FNextWeap := FNextWeap and $1FFF;
2886 if FNextWeapDelay
> 0 then Dec(FNextWeapDelay
); // "alteration delay"
2888 if not switchAllowed
then
2890 //HACK for weapon cycling
2891 if (FNextWeap
and $E000) <> 0 then FNextWeap
:= 0;
2895 nw
:= getNextWeaponIndex();
2896 if nw
= 255 then exit
; // don't reset anything here
2897 if nw
> High(FWeapon
) then
2899 // don't forget to reset queue here!
2900 //e_WriteLog(' RealizeCurrentWeapon: WUTAFUUUU', MSG_WARNING);
2908 FTime
[T_SWITCH
] := gTime
+156;
2909 if FCurrWeap
= WEAPON_SAW
then FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
2910 FModel
.SetWeapon(FCurrWeap
);
2911 if g_Game_IsNet
then MH_SEND_PlayerStats(FUID
);
2915 procedure TPlayer
.NextWeapon();
2917 if g_Game_IsClient
then Exit
;
2921 procedure TPlayer
.PrevWeapon();
2923 if g_Game_IsClient
then Exit
;
2927 procedure TPlayer
.SetWeapon(W
: Byte);
2929 if FCurrWeap
<> W
then
2930 if W
= WEAPON_SAW
then
2931 FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
2934 FModel
.SetWeapon(CurrWeap
);
2938 function TPlayer
.PickItem(ItemType
: Byte; arespawn
: Boolean; var remove
: Boolean): Boolean;
2940 function allowBerserkSwitching (): Boolean;
2942 if (FBFGFireCounter
<> -1) then begin result
:= false; exit
; end;
2944 if gBerserkAutoswitch
then exit
;
2945 if not conIsCheatsEnabled
then exit
;
2953 if g_Game_IsClient
then Exit
;
2955 // a = true - место спавна предмета:
2956 a
:= LongBool(gGameSettings
.Options
and GAME_OPTION_WEAPONSTAY
) and arespawn
;
2961 if (FHealth
< PLAYER_HP_SOFT
) or (FFireTime
> 0) then
2963 if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
2967 if gFlash
= 2 then Inc(FPickup
, 5);
2971 if (FHealth
< PLAYER_HP_SOFT
) or (FFireTime
> 0) then
2973 if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
2977 if gFlash
= 2 then Inc(FPickup
, 5);
2981 if FArmor
< PLAYER_AP_SOFT
then
2983 FArmor
:= PLAYER_AP_SOFT
;
2986 if gFlash
= 2 then Inc(FPickup
, 5);
2990 if FArmor
< PLAYER_AP_LIMIT
then
2992 FArmor
:= PLAYER_AP_LIMIT
;
2995 if gFlash
= 2 then Inc(FPickup
, 5);
2999 if (FHealth
< PLAYER_HP_LIMIT
) or (FFireTime
> 0) then
3001 if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
3005 if gFlash
= 2 then Inc(FPickup
, 5);
3009 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) or (FFireTime
> 0) then
3011 if FHealth
< PLAYER_HP_LIMIT
then
3012 FHealth
:= PLAYER_HP_LIMIT
;
3013 if FArmor
< PLAYER_AP_LIMIT
then
3014 FArmor
:= PLAYER_AP_LIMIT
;
3018 if gFlash
= 2 then Inc(FPickup
, 5);
3022 if (not FWeapon
[WEAPON_SAW
]) or ((not arespawn
) and (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
])) then
3024 FWeapon
[WEAPON_SAW
] := True;
3026 if gFlash
= 2 then Inc(FPickup
, 5);
3027 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3030 ITEM_WEAPON_SHOTGUN1
:
3031 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN1
] then
3033 // Нужно, чтобы не взять все пули сразу:
3034 if a
and FWeapon
[WEAPON_SHOTGUN1
] then Exit
;
3036 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3037 FWeapon
[WEAPON_SHOTGUN1
] := True;
3039 if gFlash
= 2 then Inc(FPickup
, 5);
3040 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3043 ITEM_WEAPON_SHOTGUN2
:
3044 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN2
] then
3046 if a
and FWeapon
[WEAPON_SHOTGUN2
] then Exit
;
3048 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3049 FWeapon
[WEAPON_SHOTGUN2
] := True;
3051 if gFlash
= 2 then Inc(FPickup
, 5);
3052 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3055 ITEM_WEAPON_CHAINGUN
:
3056 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or not FWeapon
[WEAPON_CHAINGUN
] then
3058 if a
and FWeapon
[WEAPON_CHAINGUN
] then Exit
;
3060 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
3061 FWeapon
[WEAPON_CHAINGUN
] := True;
3063 if gFlash
= 2 then Inc(FPickup
, 5);
3064 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3067 ITEM_WEAPON_ROCKETLAUNCHER
:
3068 if (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or not FWeapon
[WEAPON_ROCKETLAUNCHER
] then
3070 if a
and FWeapon
[WEAPON_ROCKETLAUNCHER
] then Exit
;
3072 IncMax(FAmmo
[A_ROCKETS
], 2, FMaxAmmo
[A_ROCKETS
]);
3073 FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
3075 if gFlash
= 2 then Inc(FPickup
, 5);
3076 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3080 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_PLASMA
] then
3082 if a
and FWeapon
[WEAPON_PLASMA
] then Exit
;
3084 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3085 FWeapon
[WEAPON_PLASMA
] := True;
3087 if gFlash
= 2 then Inc(FPickup
, 5);
3088 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3092 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_BFG
] then
3094 if a
and FWeapon
[WEAPON_BFG
] then Exit
;
3096 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3097 FWeapon
[WEAPON_BFG
] := True;
3099 if gFlash
= 2 then Inc(FPickup
, 5);
3100 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3103 ITEM_WEAPON_SUPERPULEMET
:
3104 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SUPERPULEMET
] then
3106 if a
and FWeapon
[WEAPON_SUPERPULEMET
] then Exit
;
3108 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3109 FWeapon
[WEAPON_SUPERPULEMET
] := True;
3111 if gFlash
= 2 then Inc(FPickup
, 5);
3112 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3115 ITEM_WEAPON_FLAMETHROWER
:
3116 if (FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
]) or not FWeapon
[WEAPON_FLAMETHROWER
] then
3118 if a
and FWeapon
[WEAPON_FLAMETHROWER
] then Exit
;
3120 IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
3121 FWeapon
[WEAPON_FLAMETHROWER
] := True;
3123 if gFlash
= 2 then Inc(FPickup
, 5);
3124 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3128 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
3130 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
3133 if gFlash
= 2 then Inc(FPickup
, 5);
3136 ITEM_AMMO_BULLETS_BOX
:
3137 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
3139 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
3142 if gFlash
= 2 then Inc(FPickup
, 5);
3146 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
3148 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3151 if gFlash
= 2 then Inc(FPickup
, 5);
3154 ITEM_AMMO_SHELLS_BOX
:
3155 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
3157 IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
3160 if gFlash
= 2 then Inc(FPickup
, 5);
3164 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
3166 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
3169 if gFlash
= 2 then Inc(FPickup
, 5);
3172 ITEM_AMMO_ROCKET_BOX
:
3173 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
3175 IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
3178 if gFlash
= 2 then Inc(FPickup
, 5);
3182 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
3184 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3187 if gFlash
= 2 then Inc(FPickup
, 5);
3191 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
3193 IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
3196 if gFlash
= 2 then Inc(FPickup
, 5);
3200 if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then
3202 IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
3205 if gFlash
= 2 then Inc(FPickup
, 5);
3209 if not(R_ITEM_BACKPACK
in FRulez
) or
3210 (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
3211 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
3212 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
3213 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or
3214 (FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
]) then
3216 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[1, A_BULLETS
];
3217 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[1, A_SHELLS
];
3218 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[1, A_ROCKETS
];
3219 FMaxAmmo
[A_CELLS
] := AmmoLimits
[1, A_CELLS
];
3220 FMaxAmmo
[A_FUEL
] := AmmoLimits
[1, A_FUEL
];
3222 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
3223 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
3224 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
3225 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3226 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
3227 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
3228 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
3229 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3230 if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then
3231 IncMax(FAmmo
[A_FUEL
], 50, FMaxAmmo
[A_FUEL
]);
3233 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
3236 if gFlash
= 2 then Inc(FPickup
, 5);
3240 if not(R_KEY_RED
in FRulez
) then
3242 Include(FRulez
, R_KEY_RED
);
3244 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
3245 if gFlash
= 2 then Inc(FPickup
, 5);
3246 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
3250 if not(R_KEY_GREEN
in FRulez
) then
3252 Include(FRulez
, R_KEY_GREEN
);
3254 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
3255 if gFlash
= 2 then Inc(FPickup
, 5);
3256 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
3260 if not(R_KEY_BLUE
in FRulez
) then
3262 Include(FRulez
, R_KEY_BLUE
);
3264 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
3265 if gFlash
= 2 then Inc(FPickup
, 5);
3266 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
3270 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
3272 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
3276 if gFlash
= 2 then Inc(FPickup
, 5);
3280 if FAir
< AIR_MAX
then
3285 if gFlash
= 2 then Inc(FPickup
, 5);
3290 if not (R_BERSERK
in FRulez
) then
3292 Include(FRulez
, R_BERSERK
);
3293 if allowBerserkSwitching
then
3295 FCurrWeap
:= WEAPON_KASTET
;
3297 FModel
.SetWeapon(WEAPON_KASTET
);
3302 if gFlash
= 2 then Inc(FPickup
, 5);
3304 FBerserk
:= gTime
+30000;
3309 if (FHealth
< PLAYER_HP_SOFT
) or (FFireTime
> 0) then
3311 if FHealth
< PLAYER_HP_SOFT
then FHealth
:= PLAYER_HP_SOFT
;
3312 FBerserk
:= gTime
+30000;
3320 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
3322 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
3326 if gFlash
= 2 then Inc(FPickup
, 5);
3330 if (FHealth
< PLAYER_HP_LIMIT
) or (FFireTime
> 0) then
3332 if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
3336 if gFlash
= 2 then Inc(FPickup
, 5);
3340 if FArmor
< PLAYER_AP_LIMIT
then
3342 IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
3345 if gFlash
= 2 then Inc(FPickup
, 5);
3349 if FJetFuel
< JET_MAX
then
3351 FJetFuel
:= JET_MAX
;
3354 if gFlash
= 2 then Inc(FPickup
, 5);
3358 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
3360 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
3363 if gFlash
= 2 then Inc(FPickup
, 5);
3368 procedure TPlayer
.Touch();
3372 //FModel.PlaySound(MODELSOUND_PAIN, 1, FObj.X, FObj.Y);
3375 // Бросить флаг товарищу:
3376 if gGameSettings
.GameMode
= GM_CTF
then
3381 procedure TPlayer
.Push(vx
, vy
: Integer);
3383 if (not FPhysics
) and FGhost
then
3385 FObj
.Accel
.X
:= FObj
.Accel
.X
+ vx
;
3386 FObj
.Accel
.Y
:= FObj
.Accel
.Y
+ vy
;
3387 if g_Game_IsNet
and g_Game_IsServer
then
3388 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
3391 procedure TPlayer
.Reset(Force
: Boolean);
3397 FTime
[T_RESPAWN
] := 0;
3398 FTime
[T_FLAGCAP
] := 0;
3414 FSpectator
:= False;
3417 FSpectatePlayer
:= -1;
3418 FNoRespawn
:= False;
3420 FLives
:= gGameSettings
.MaxLives
;
3425 procedure TPlayer
.SoftReset();
3433 FBFGFireCounter
:= -1;
3434 {$IFDEF ENABLE_SHELLS}
3443 SetAction(A_STAND
, True);
3446 function TPlayer
.GetRespawnPoint(): Byte;
3451 // На будущее: FSpawn - игрок уже играл и перерождается
3453 // Одиночная игра/кооператив
3454 if gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
] then
3456 if Self
= gPlayer1
then
3458 // player 1 should try to spawn on the player 1 point
3459 if g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) > 0 then
3460 Exit(RESPAWNPOINT_PLAYER1
)
3461 else if g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) > 0 then
3462 Exit(RESPAWNPOINT_PLAYER2
);
3464 else if Self
= gPlayer2
then
3466 // player 2 should try to spawn on the player 2 point
3467 if g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) > 0 then
3468 Exit(RESPAWNPOINT_PLAYER2
)
3469 else if g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) > 0 then
3470 Exit(RESPAWNPOINT_PLAYER1
);
3474 // other players randomly pick either the first or the second point
3475 c
:= IfThen((Random(2) = 0), RESPAWNPOINT_PLAYER1
, RESPAWNPOINT_PLAYER2
);
3476 if g_Map_GetPointCount(c
) > 0 then
3478 // try the other one
3479 c
:= IfThen((c
= RESPAWNPOINT_PLAYER1
), RESPAWNPOINT_PLAYER2
, RESPAWNPOINT_PLAYER1
);
3480 if g_Map_GetPointCount(c
) > 0 then
3486 if gGameSettings
.GameMode
= GM_DM
then
3488 // try DM points first
3489 if g_Map_GetPointCount(RESPAWNPOINT_DM
) > 0 then
3490 Exit(RESPAWNPOINT_DM
);
3494 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
3496 // try team points first
3497 c
:= RESPAWNPOINT_DM
;
3498 if FTeam
= TEAM_RED
then
3499 c
:= RESPAWNPOINT_RED
3500 else if FTeam
= TEAM_BLUE
then
3501 c
:= RESPAWNPOINT_BLUE
;
3502 if g_Map_GetPointCount(c
) > 0 then
3506 // still haven't found a spawnpoint, try random shit
3507 Result
:= g_Map_GetRandomPointType();
3510 procedure TPlayer
.Respawn(Silent
: Boolean; Force
: Boolean = False);
3512 RespawnPoint
: TRespawnPoint
;
3518 FBFGFireCounter
:= -1;
3519 {$IFDEF ENABLE_SHELLS}
3527 if not g_Game_IsServer
then
3531 FWantsInGame
:= True;
3532 FJustTeleported
:= True;
3535 FTime
[T_RESPAWN
] := 0;
3539 // if server changes MaxLives we gotta be ready
3540 if gGameSettings
.MaxLives
= 0 then FNoRespawn
:= False;
3542 // Еще нельзя возродиться:
3543 if FTime
[T_RESPAWN
] > gTime
then
3546 // Просрал все жизни:
3549 if not FSpectator
then Spectate(True);
3550 FWantsInGame
:= True;
3554 if (gGameSettings
.GameType
<> GT_SINGLE
) and (gGameSettings
.GameMode
<> GM_COOP
) then
3555 begin // "Своя игра"
3556 // Берсерк не сохраняется между уровнями:
3557 FRulez
:= FRulez
-[R_BERSERK
];
3559 else // "Одиночная игра"/"Кооп"
3561 // Берсерк и ключи не сохраняются между уровнями:
3562 FRulez
:= FRulez
-[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
, R_BERSERK
];
3565 // Получаем точку спауна игрока:
3566 c
:= GetRespawnPoint();
3571 // Воскрешение без оружия:
3574 FHealth
:= Round(PLAYER_HP_SOFT
* (FHandicap
/ 100));
3580 for a
:= WP_FIRST
to WP_LAST
do
3582 FWeapon
[a
] := False;
3586 FWeapon
[WEAPON_PISTOL
] := True;
3587 FWeapon
[WEAPON_KASTET
] := True;
3588 FCurrWeap
:= WEAPON_PISTOL
;
3591 FModel
.SetWeapon(FCurrWeap
);
3593 for b
:= A_BULLETS
to A_HIGH
do
3596 FAmmo
[A_BULLETS
] := 50;
3598 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[0, A_BULLETS
];
3599 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[0, A_SHELLS
];
3600 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[0, A_SHELLS
];
3601 FMaxAmmo
[A_CELLS
] := AmmoLimits
[0, A_CELLS
];
3602 FMaxAmmo
[A_FUEL
] := AmmoLimits
[0, A_FUEL
];
3604 if (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
]) and
3605 LongBool(gGameSettings
.Options
and GAME_OPTION_DMKEYS
) then
3606 FRulez
:= [R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
]
3611 // Получаем координаты точки возрождения:
3612 if not g_Map_GetPoint(c
, RespawnPoint
) then
3614 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
3618 // Установка координат и сброс всех параметров:
3619 FObj
.X
:= RespawnPoint
.X
-PLAYER_RECT
.X
;
3620 FObj
.Y
:= RespawnPoint
.Y
-PLAYER_RECT
.Y
;
3621 FObj
.oldX
:= FObj
.X
; // don't interpolate after respawn
3622 FObj
.oldY
:= FObj
.Y
;
3628 FDirection
:= RespawnPoint
.Direction
;
3629 if FDirection
= TDirection
.D_LEFT
then
3634 SetAction(A_STAND
, True);
3635 FModel
.Direction
:= FDirection
;
3637 for a
:= Low(FTime
) to High(FTime
) do
3640 for a
:= Low(FMegaRulez
) to High(FMegaRulez
) do
3643 // Respawn invulnerability
3644 if (gGameSettings
.GameType
<> GT_SINGLE
) and (gGameSettings
.SpawnInvul
> 0) then
3646 FMegaRulez
[MR_INVUL
] := gTime
+ gGameSettings
.SpawnInvul
* 1000;
3647 FSpawnInvul
:= FMegaRulez
[MR_INVUL
];
3652 FCanJetpack
:= False;
3659 // Анимация возрождения:
3660 if (not gLoadGameMode
) and (not Silent
) then
3663 R_GFX_TELEPORT_FAST
,
3664 FObj
.X
+ PLAYER_RECT
.X
+ (PLAYER_RECT
.Width
div 2) - 32,
3665 FObj
.Y
+ PLAYER_RECT
.Y
+ (PLAYER_RECT
.Height
div 2) - 32
3670 FSpectator
:= False;
3673 FSpectatePlayer
:= -1;
3676 if (gPlayer1
= nil) and (gSpectLatchPID1
= FUID
) then
3678 if (gPlayer2
= nil) and (gSpectLatchPID2
= FUID
) then
3681 if g_Game_IsNet
then
3683 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
3684 MH_SEND_PlayerStats(FUID
, NET_EVERYONE
);
3686 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
3687 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32,
3692 procedure TPlayer
.Spectate(NoMove
: Boolean = False);
3695 Kill(K_EXTRAHARDKILL
, FUID
, HIT_SOME
)
3696 else if (not NoMove
) then
3698 GameX
:= gMapInfo
.Width
div 2;
3699 GameY
:= gMapInfo
.Height
div 2;
3708 FWantsInGame
:= False;
3714 if Self
= gPlayer1
then
3716 gSpectLatchPID1
:= FUID
;
3719 else if Self
= gPlayer2
then
3721 gSpectLatchPID2
:= FUID
;
3726 if g_Game_IsNet
then
3727 MH_SEND_PlayerStats(FUID
);
3730 procedure TPlayer
.SwitchNoClip
;
3734 FGhost
:= not FGhost
;
3735 FPhysics
:= not FGhost
;
3747 procedure TPlayer
.Run(Direction
: TDirection
);
3748 {$IFDEF ENABLE_GIBS}
3752 if MAX_RUNVEL
> 8 then
3756 if Direction
= TDirection
.D_LEFT
then
3758 if FObj
.Vel
.X
> -MAX_RUNVEL
then
3759 FObj
.Vel
.X
:= FObj
.Vel
.X
- (MAX_RUNVEL
shr 3);
3762 if FObj
.Vel
.X
< MAX_RUNVEL
then
3763 FObj
.Vel
.X
:= FObj
.Vel
.X
+ (MAX_RUNVEL
shr 3);
3765 {$IFDEF ENABLE_GIBS}
3766 // Возможно, пинаем куски:
3767 if (FObj
.Vel
.X
<> 0) and (gGibs
<> nil) then
3769 b
:= Abs(FObj
.Vel
.X
);
3770 if b
> 1 then b
:= b
* (Random(8 div b
) + 1);
3771 for a
:= 0 to High(gGibs
) do
3773 if gGibs
[a
].alive
and
3774 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
+FObj
.Rect
.Height
-4,
3775 FObj
.Rect
.Width
, 8, @gGibs
[a
].Obj
) and (Random(3) = 0) then
3778 if FObj
.Vel
.X
< 0 then
3780 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)+120) // налево
3784 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)); // направо
3786 gGibs
[a
].positionChanged(); // this updates spatial accelerators
3795 procedure TPlayer
.SeeDown();
3797 SetAction(A_SEEDOWN
);
3799 if FDirection
= TDirection
.D_LEFT
then FAngle
:= ANGLE_LEFTDOWN
else FAngle
:= ANGLE_RIGHTDOWN
;
3801 if FIncCam
> -120 then DecMin(FIncCam
, 5, -120);
3804 procedure TPlayer
.SeeUp();
3808 if FDirection
= TDirection
.D_LEFT
then FAngle
:= ANGLE_LEFTUP
else FAngle
:= ANGLE_RIGHTUP
;
3810 if FIncCam
< 120 then IncMax(FIncCam
, 5, 120);
3813 procedure TPlayer
.SetAction(Action
: Byte; Force
: Boolean = False);
3821 A_ATTACK
: Prior
:= 2;
3822 A_SEEUP
: Prior
:= 1;
3823 A_SEEDOWN
: Prior
:= 1;
3824 A_ATTACKUP
: Prior
:= 2;
3825 A_ATTACKDOWN
: Prior
:= 2;
3830 if (Prior
> FActionPrior
) or Force
then
3831 if not ((Prior
= 2) and (FCurrWeap
= WEAPON_SAW
)) then
3833 FActionPrior
:= Prior
;
3834 FActionAnim
:= Action
;
3835 FActionForce
:= Force
;
3836 FActionChanged
:= True;
3839 if Action
in [A_ATTACK
, A_ATTACKUP
, A_ATTACKDOWN
] then FModel
.SetFire(True);
3842 function TPlayer
.StayOnStep(XInc
, YInc
: Integer): Boolean;
3844 Result
:= not g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
-1,
3845 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False)
3846 and g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
,
3847 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False);
3850 function TPlayer
.TeleportTo(X
, Y
: Integer; silent
: Boolean; dir
: Byte): Boolean;
3854 if g_CollideLevel(X
, Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
) then
3856 g_Sound_PlayExAt('SOUND_GAME_NOTELEPORT', FObj
.X
, FObj
.Y
);
3857 if g_Game_IsServer
and g_Game_IsNet
then
3858 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_GAME_NOTELEPORT');
3862 FJustTeleported
:= True;
3866 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', FObj
.X
, FObj
.Y
);
3869 R_GFX_TELEPORT_FAST
,
3870 FObj
.X
+ PLAYER_RECT
.X
+ (PLAYER_RECT
.Width
div 2) - 32,
3871 FObj
.Y
+ PLAYER_RECT
.Y
+ (PLAYER_RECT
.Height
div 2) - 32
3874 if g_Game_IsServer
and g_Game_IsNet
then
3875 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
3876 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 1,
3880 FObj
.X
:= X
-PLAYER_RECT
.X
;
3881 FObj
.Y
:= Y
-PLAYER_RECT
.Y
;
3882 FObj
.oldX
:= FObj
.X
; // don't interpolate after respawn
3883 FObj
.oldY
:= FObj
.Y
;
3884 if FAlive
and FGhost
then
3890 if not g_Game_IsNet
then
3894 SetDirection(TDirection
.D_LEFT
);
3900 SetDirection(TDirection
.D_RIGHT
);
3906 if FDirection
= TDirection
.D_RIGHT
then
3908 SetDirection(TDirection
.D_LEFT
);
3913 SetDirection(TDirection
.D_RIGHT
);
3923 R_GFX_TELEPORT_FAST
,
3924 FObj
.X
+ PLAYER_RECT
.X
+ (PLAYER_RECT
.Width
div 2) - 32,
3925 FObj
.Y
+ PLAYER_RECT
.Y
+ (PLAYER_RECT
.Height
div 2) - 32
3928 if g_Game_IsServer
and g_Game_IsNet
then
3929 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
3930 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 0,
3937 function nonz(a
: Single): Single;
3945 function TPlayer
.refreshCorpse(): Boolean;
3951 if FAlive
or FSpectator
then
3953 if (gCorpses
= nil) or (Length(gCorpses
) = 0) then
3955 for i
:= 0 to High(gCorpses
) do
3956 if gCorpses
[i
] <> nil then
3957 if gCorpses
[i
].FPlayerUID
= FUID
then
3965 function TPlayer
.getCameraObj(): TObj
;
3967 if (not FAlive
) and (not FSpectator
) and
3968 (FCorpse
>= 0) and (FCorpse
< Length(gCorpses
)) and
3969 (gCorpses
[FCorpse
] <> nil) and (gCorpses
[FCorpse
].FPlayerUID
= FUID
) then
3971 gCorpses
[FCorpse
].FObj
.slopeUpLeft
:= FObj
.slopeUpLeft
;
3972 Result
:= gCorpses
[FCorpse
].FObj
;
3980 procedure TPlayer
.PreUpdate();
3982 FSlopeOld
:= FObj
.slopeUpLeft
;
3983 FIncCamOld
:= FIncCam
;
3984 FObj
.oldX
:= FObj
.X
;
3985 FObj
.oldY
:= FObj
.Y
;
3988 procedure TPlayer
.Update();
3991 i
, ii
, wx
, wy
, xd
, yd
, k
: Integer;
3992 blockmon
, headwater
, dospawn
: Boolean;
3997 NetServer
:= g_Game_IsNet
and g_Game_IsServer
;
3998 AnyServer
:= g_Game_IsServer
;
4000 if g_Game_IsClient
and (NetInterpLevel
> 0) then
4001 DoLerp(NetInterpLevel
+ 1)
4007 if FClientID
>= 0 then
4009 FPing
:= NetClients
[FClientID
].Peer
^.lastRoundTripTime
;
4010 if NetClients
[FClientID
].Peer
^.packetsSent
> 0 then
4011 FLoss
:= Round(100*NetClients
[FClientID
].Peer
^.packetsLost
/NetClients
[FClientID
].Peer
^.packetsSent
)
4022 if FPunchAnim
.played
then
4025 if FAlive
and (gFly
or FJetpack
) then
4028 if FDirection
= TDirection
.D_LEFT
then
4033 if FAlive
and (not FGhost
) then
4035 if FKeys
[KEY_UP
].Pressed
then
4037 if FKeys
[KEY_DOWN
].Pressed
then
4041 if (not (FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_DOWN
].Pressed
)) and
4044 i
:= g_basic
.Sign(FIncCam
);
4045 FIncCam
:= Abs(FIncCam
);
4046 DecMin(FIncCam
, 5, 0);
4047 FIncCam
:= FIncCam
*i
;
4050 // no need to do that each second frame, weapon queue will take care of it
4051 if FAlive
and FKeys
[KEY_NEXTWEAPON
].Pressed
and AnyServer
then NextWeapon();
4052 if FAlive
and FKeys
[KEY_PREVWEAPON
].Pressed
and AnyServer
then PrevWeapon();
4054 if gTime
mod (GAME_TICK
*2) <> 0 then
4056 if (FObj
.Vel
.X
= 0) and FAlive
then
4058 if FKeys
[KEY_LEFT
].Pressed
then
4059 Run(TDirection
.D_LEFT
);
4060 if FKeys
[KEY_RIGHT
].Pressed
then
4061 Run(TDirection
.D_RIGHT
);
4066 g_Obj_Move(@FObj
, True, True, True);
4067 positionChanged(); // this updates spatial accelerators
4073 FActionChanged
:= False;
4077 // Let alive player do some actions
4078 if FKeys
[KEY_LEFT
].Pressed
then Run(TDirection
.D_LEFT
);
4079 if FKeys
[KEY_RIGHT
].Pressed
then Run(TDirection
.D_RIGHT
);
4080 //if FKeys[KEY_NEXTWEAPON].Pressed and AnyServer then NextWeapon();
4081 //if FKeys[KEY_PREVWEAPON].Pressed and AnyServer then PrevWeapon();
4082 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then Fire()
4088 if NetServer
then MH_SEND_PlayerStats(FUID
);
4091 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Use();
4092 if FKeys
[KEY_JUMP
].Pressed
then Jump()
4095 if AnyServer
and FJetpack
then
4099 if NetServer
then MH_SEND_PlayerStats(FUID
);
4101 FCanJetpack
:= True;
4108 for k
:= Low(FKeys
) to KEY_CHAT
-1 do
4110 if FKeys
[k
].Pressed
then
4118 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
4121 if (FTime
[T_RESPAWN
] <= gTime
) and
4122 gGameOn
and (not FAlive
) then
4124 if (g_Player_GetCount() > 1) then
4128 gExit
:= EXIT_RESTART
;
4133 // Dead spectator actions
4136 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Fire();
4137 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then
4141 if (FSpectatePlayer
>= High(gPlayers
)) then
4142 FSpectatePlayer
:= -1
4146 for I
:= FSpectatePlayer
+ 1 to High(gPlayers
) do
4147 if gPlayers
[I
] <> nil then
4148 if gPlayers
[I
].alive
then
4149 if gPlayers
[I
].UID
<> FUID
then
4151 FSpectatePlayer
:= I
;
4156 if not SetSpect
then FSpectatePlayer
:= -1;
4167 if FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_JUMP
].Pressed
then
4169 FYTo
:= FObj
.Y
- 32;
4170 FSpectatePlayer
:= -1;
4172 if FKeys
[KEY_DOWN
].Pressed
then
4174 FYTo
:= FObj
.Y
+ 32;
4175 FSpectatePlayer
:= -1;
4177 if FKeys
[KEY_LEFT
].Pressed
then
4179 FXTo
:= FObj
.X
- 32;
4180 FSpectatePlayer
:= -1;
4182 if FKeys
[KEY_RIGHT
].Pressed
then
4184 FXTo
:= FObj
.X
+ 32;
4185 FSpectatePlayer
:= -1;
4188 if (FXTo
< -64) then
4190 else if (FXTo
> gMapInfo
.Width
+ 32) then
4191 FXTo
:= gMapInfo
.Width
+ 32;
4192 if (FYTo
< -72) then
4194 else if (FYTo
> gMapInfo
.Height
+ 32) then
4195 FYTo
:= gMapInfo
.Height
+ 32;
4200 g_Obj_Move(@FObj
, True, True, True);
4201 positionChanged(); // this updates spatial accelerators
4208 if (FSpectatePlayer
<= High(gPlayers
)) and (FSpectatePlayer
>= 0) then
4209 if gPlayers
[FSpectatePlayer
] <> nil then
4210 if gPlayers
[FSpectatePlayer
].alive
then
4212 FXTo
:= gPlayers
[FSpectatePlayer
].GameX
;
4213 FYTo
:= gPlayers
[FSpectatePlayer
].GameY
;
4217 blockmon
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
, FObj
.Y
+PLAYER_HEADRECT
.Y
,
4218 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
4219 PANEL_BLOCKMON
, True);
4220 headwater
:= HeadInLiquid(0, 0);
4222 // Сопротивление воздуха:
4223 if (not FAlive
) or not (FKeys
[KEY_LEFT
].Pressed
or FKeys
[KEY_RIGHT
].Pressed
) then
4224 if FObj
.Vel
.X
<> 0 then
4225 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
4227 if (FLastHit
= HIT_TRAP
) and (FPain
> 90) then FPain
:= 90;
4228 DecMin(FPain
, 5, 0);
4229 DecMin(FPickup
, 1, 0);
4231 if FAlive
and (FObj
.Y
> Integer(gMapInfo
.Height
)+128) and AnyServer
then
4233 // Обнулить действия примочек, чтобы фон пропал
4234 FMegaRulez
[MR_SUIT
] := 0;
4235 FMegaRulez
[MR_INVUL
] := 0;
4236 FMegaRulez
[MR_INVIS
] := 0;
4237 Kill(K_FALLKILL
, 0, HIT_FALL
);
4244 if FCurrWeap
= WEAPON_SAW
then
4245 if not (FSawSound
.IsPlaying() or FSawSoundHit
.IsPlaying() or
4246 FSawSoundSelect
.IsPlaying()) then
4247 FSawSoundIdle
.PlayAt(FObj
.X
, FObj
.Y
);
4250 if (not FJetSoundFly
.IsPlaying()) and (not FJetSoundOn
.IsPlaying()) and
4251 (not FJetSoundOff
.IsPlaying()) then
4253 FJetSoundFly
.SetPosition(0);
4254 FJetSoundFly
.PlayAt(FObj
.X
, FObj
.Y
);
4257 for b
:= WP_FIRST
to WP_LAST
do
4258 if FReloading
[b
] > 0 then
4264 {$IFDEF ENABLE_SHELLS}
4265 if FShellTimer
> -1 then
4266 if FShellTimer
= 0 then
4268 if FShellType
= SHELL_SHELL
then
4269 g_Shells_Create(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
4270 GameVelX
, GameVelY
-2, SHELL_SHELL
)
4271 else if FShellType
= SHELL_DBLSHELL
then
4273 g_Shells_Create(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
4274 GameVelX
+1, GameVelY
-2, SHELL_SHELL
);
4275 g_Shells_Create(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
4276 GameVelX
-1, GameVelY
-2, SHELL_SHELL
);
4279 end else Dec(FShellTimer
);
4282 if (FBFGFireCounter
> -1) then
4283 if FBFGFireCounter
= 0 then
4287 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
4288 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
4289 xd
:= wx
+IfThen(FDirection
= TDirection
.D_LEFT
, -30, 30);
4290 yd
:= wy
+firediry();
4291 g_Weapon_bfgshot(wx
, wy
, xd
, yd
, FUID
);
4292 if NetServer
then MH_SEND_PlayerFire(FUID
, WEAPON_BFG
, wx
, wy
, xd
, yd
);
4293 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
4294 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
4295 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
4298 FReloading
[WEAPON_BFG
] := WEAPON_RELOAD
[WEAPON_BFG
];
4299 FBFGFireCounter
:= -1;
4302 FBFGFireCounter
:= 0
4304 Dec(FBFGFireCounter
);
4306 if (FMegaRulez
[MR_SUIT
] < gTime
) and AnyServer
then
4308 b
:= g_GetAcidHit(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
);
4310 if (b
> 0) and (gTime
mod (15*GAME_TICK
) = 0) then Damage(b
, 0, 0, 0, HIT_ACID
);
4313 if (headwater
or blockmon
) then
4319 if AnyServer
then Damage(10, 0, 0, 0, HIT_WATER
);
4322 else if (FAir
mod 31 = 0) and not blockmon
then
4325 g_GFX_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2), FObj
.Y
+PLAYER_RECT
.Y
-4, 5+Random(6), 8, 4);
4327 if Random(2) = 0 then
4328 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
4330 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
4332 end else if FAir
< AIR_DEF
then
4335 if FFireTime
> 0 then
4337 if BodyInLiquid(0, 0) then
4342 else if FMegaRulez
[MR_SUIT
] >= gTime
then
4344 if FMegaRulez
[MR_SUIT
] = gTime
then
4351 if FFirePainTime
<= 0 then
4353 if g_Game_IsServer
then
4354 Damage(2, FFireAttacker
, 0, 0, HIT_FLAME
);
4355 FFirePainTime
:= 12 - FFireTime
div 12;
4357 FFirePainTime
:= FFirePainTime
- 1;
4358 FFireTime
:= FFireTime
- 1;
4359 if ((FFireTime
mod 33) = 0) and (FMegaRulez
[MR_INVUL
] < gTime
) then
4360 FModel
.PlaySound(MODELSOUND_PAIN
, 1, FObj
.X
, FObj
.Y
);
4361 if (FFireTime
= 0) and g_Game_IsNet
and g_Game_IsServer
then
4362 MH_SEND_PlayerStats(FUID
);
4366 if FDamageBuffer
> 0 then
4368 if FDamageBuffer
>= 9 then
4372 if FDamageBuffer
< 30 then i
:= 9
4373 else if FDamageBuffer
< 100 then i
:= 18
4377 ii
:= Round(FDamageBuffer
*FHealth
/ nonz(FArmor
*(3/4)+FHealth
));
4378 FArmor
:= FArmor
-(FDamageBuffer
-ii
);
4379 FHealth
:= FHealth
-ii
;
4382 FHealth
:= FHealth
+FArmor
;
4387 if FHealth
<= 0 then
4388 if FHealth
> -30 then Kill(K_SIMPLEKILL
, FLastSpawnerUID
, FLastHit
)
4389 else if FHealth
> -50 then Kill(K_HARDKILL
, FLastSpawnerUID
, FLastHit
)
4390 else Kill(K_EXTRAHARDKILL
, FLastSpawnerUID
, FLastHit
);
4392 if FAlive
and ((FLastHit
<> HIT_FLAME
) or (FFireTime
<= 0)) then
4394 if FDamageBuffer
<= 20 then FModel
.PlaySound(MODELSOUND_PAIN
, 1, FObj
.X
, FObj
.Y
)
4395 else if FDamageBuffer
<= 55 then FModel
.PlaySound(MODELSOUND_PAIN
, 2, FObj
.X
, FObj
.Y
)
4396 else if FDamageBuffer
<= 120 then FModel
.PlaySound(MODELSOUND_PAIN
, 3, FObj
.X
, FObj
.Y
)
4397 else FModel
.PlaySound(MODELSOUND_PAIN
, 4, FObj
.X
, FObj
.Y
);
4404 end; // if FAlive then ...
4406 if (FActionAnim
= A_PAIN
) and (FModel
.Animation
<> A_PAIN
) then
4408 FModel
.ChangeAnimation(FActionAnim
, FActionForce
);
4409 FModel
.AnimState
.MinLength
:= i
;
4410 end else FModel
.ChangeAnimation(FActionAnim
, FActionForce
and (FModel
.Animation
<> A_STAND
));
4412 if (FModel
.AnimState
.Played
or ((not FActionChanged
) and (FModel
.Animation
= A_WALK
)))
4413 then SetAction(A_STAND
, True);
4415 if not ((FModel
.Animation
= A_WALK
) and (Abs(FObj
.Vel
.X
) < 4) and not FModel
.GetFire()) then FModel
.Update
;
4417 for b
:= Low(FKeys
) to High(FKeys
) do
4418 if FKeys
[b
].Time
= 0 then FKeys
[b
].Pressed
:= False else Dec(FKeys
[b
].Time
);
4422 procedure TPlayer
.getMapBox (out x
, y
, w
, h
: Integer); inline;
4424 x
:= FObj
.X
+PLAYER_RECT
.X
;
4425 y
:= FObj
.Y
+PLAYER_RECT
.Y
;
4426 w
:= PLAYER_RECT
.Width
;
4427 h
:= PLAYER_RECT
.Height
;
4431 procedure TPlayer
.moveBy (dx
, dy
: Integer); inline;
4433 if (dx
<> 0) or (dy
<> 0) then
4442 function TPlayer
.Collide(X
, Y
: Integer; Width
, Height
: Word): Boolean;
4444 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
4445 FObj
.Y
+PLAYER_RECT
.Y
,
4452 function TPlayer
.Collide(Panel
: TPanel
): Boolean;
4454 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
4455 FObj
.Y
+PLAYER_RECT
.Y
,
4459 Panel
.Width
, Panel
.Height
);
4462 function TPlayer
.Collide(X
, Y
: Integer): Boolean;
4464 X
:= X
-FObj
.X
-PLAYER_RECT
.X
;
4465 Y
:= Y
-FObj
.Y
-PLAYER_RECT
.Y
;
4466 Result
:= (x
>= 0) and (x
<= PLAYER_RECT
.Width
) and
4467 (y
>= 0) and (y
<= PLAYER_RECT
.Height
);
4470 function g_Player_ValidName(Name
: string): Boolean;
4476 if gPlayers
= nil then Exit
;
4478 for a
:= 0 to High(gPlayers
) do
4479 if gPlayers
[a
] <> nil then
4480 if LowerCase(Name
) = LowerCase(gPlayers
[a
].FName
) then
4487 procedure TPlayer
.SetDirection(Direction
: TDirection
);
4491 d
:= FModel
.Direction
;
4493 FModel
.Direction
:= Direction
;
4494 if d
<> Direction
then FModel
.ChangeAnimation(FModel
.Animation
, True);
4496 FDirection
:= Direction
;
4499 function TPlayer
.GetKeys(): Byte;
4503 if R_KEY_RED
in FRulez
then Result
:= KEY_RED
;
4504 if R_KEY_GREEN
in FRulez
then Result
:= Result
or KEY_GREEN
;
4505 if R_KEY_BLUE
in FRulez
then Result
:= Result
or KEY_BLUE
;
4507 if FTeam
= TEAM_RED
then Result
:= Result
or KEY_REDTEAM
;
4508 if FTeam
= TEAM_BLUE
then Result
:= Result
or KEY_BLUETEAM
;
4511 procedure TPlayer
.Use();
4515 if FTime
[T_USE
] > gTime
then Exit
;
4517 g_Triggers_PressR(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
,
4518 PLAYER_RECT
.Height
, FUID
, ACTIVATE_PLAYERPRESS
);
4520 for a
:= 0 to High(gPlayers
) do
4521 if (gPlayers
[a
] <> nil) and (gPlayers
[a
] <> Self
) and
4522 gPlayers
[a
].alive
and SameTeam(FUID
, gPlayers
[a
].FUID
) and
4523 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
4524 FObj
.Rect
.Width
, FObj
.Rect
.Height
, @gPlayers
[a
].FObj
) then
4526 gPlayers
[a
].Touch();
4527 if g_Game_IsNet
and g_Game_IsServer
then
4528 MH_SEND_GameEvent(NET_EV_PLAYER_TOUCH
, gPlayers
[a
].FUID
);
4531 FTime
[T_USE
] := gTime
+120;
4534 procedure TPlayer
.NetFire(Wpn
: Byte; X
, Y
, AX
, AY
: Integer; WID
: Integer = -1);
4538 WX
, WY
, XD
, YD
: Integer;
4550 if R_BERSERK
in FRulez
then
4552 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
4553 locobj
.X
:= FObj
.X
+FObj
.Rect
.X
;
4554 locobj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
4557 locobj
.rect
.Width
:= 39;
4558 locobj
.rect
.Height
:= 52;
4559 locobj
.Vel
.X
:= (xd
-wx
) div 2;
4560 locobj
.Vel
.Y
:= (yd
-wy
) div 2;
4561 locobj
.Accel
.X
:= xd
-wx
;
4562 locobj
.Accel
.y
:= yd
-wy
;
4564 if g_Weapon_Hit(@locobj
, 50, FUID
, HIT_SOME
) <> 0 then
4565 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
4567 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
4571 FPain
:= min(FPain
+ 25, 50);
4573 g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
4578 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
4579 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
4581 FSawSoundSelect
.Stop();
4583 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
4585 else if not FSawSoundHit
.IsPlaying() then
4587 FSawSoundSelect
.Stop();
4588 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
4595 g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', GameX
, Gamey
);
4596 FFireAngle
:= FAngle
;
4598 {$IFDEF ENABLE_SHELLS}
4599 g_Shells_Create(GameX
+ PLAYER_RECT_CX
, GameY
+ PLAYER_RECT_CX
, GameVelX
, GameVelY
- 2, SHELL_BULLET
);
4605 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
4606 FFireAngle
:= FAngle
;
4608 {$IFDEF ENABLE_SHELLS}
4610 FShellType
:= SHELL_SHELL
;
4616 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN2', Gamex
, Gamey
);
4617 FFireAngle
:= FAngle
;
4619 {$IFDEF ENABLE_SHELLS}
4621 FShellType
:= SHELL_DBLSHELL
;
4627 g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', Gamex
, Gamey
);
4628 FFireAngle
:= FAngle
;
4630 {$IFDEF ENABLE_SHELLS}
4631 g_Shells_Create(GameX
+ PLAYER_RECT_CX
, GameY
+ PLAYER_RECT_CX
, GameVelX
, GameVelY
- 2, SHELL_BULLET
);
4635 WEAPON_ROCKETLAUNCHER
:
4637 g_Weapon_Rocket(wx
, wy
, xd
, yd
, FUID
, WID
);
4638 FFireAngle
:= FAngle
;
4644 g_Weapon_Plasma(wx
, wy
, xd
, yd
, FUID
, WID
);
4645 FFireAngle
:= FAngle
;
4651 g_Weapon_BFGShot(wx
, wy
, xd
, yd
, FUID
, WID
);
4652 FFireAngle
:= FAngle
;
4656 WEAPON_SUPERPULEMET
:
4658 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
4659 FFireAngle
:= FAngle
;
4661 {$IFDEF ENABLE_SHELLS}
4662 g_Shells_Create(GameX
+ PLAYER_RECT_CX
, GameY
+ PLAYER_RECT_CX
, GameVelX
, GameVelY
- 2, SHELL_SHELL
);
4666 WEAPON_FLAMETHROWER
:
4668 g_Weapon_flame(wx
, wy
, xd
, yd
, FUID
, WID
);
4670 FFireAngle
:= FAngle
;
4677 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
4678 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
4679 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
4682 procedure TPlayer
.DoLerp(Level
: Integer = 2);
4684 if FObj
.X
<> FXTo
then FObj
.X
:= Lerp(FObj
.X
, FXTo
, Level
);
4685 if FObj
.Y
<> FYTo
then FObj
.Y
:= Lerp(FObj
.Y
, FYTo
, Level
);
4688 procedure TPlayer
.SetLerp(XTo
, YTo
: Integer);
4694 if FJustTeleported
or (NetInterpLevel
< 1) then
4698 if FJustTeleported
then
4700 FObj
.oldX
:= FObj
.X
;
4701 FObj
.oldY
:= FObj
.Y
;
4706 AX
:= Abs(FXTo
- FObj
.X
);
4707 AY
:= Abs(FYTo
- FObj
.Y
);
4708 if (AX
> 32) or (AX
<= NetInterpLevel
) then
4710 if (AY
> 32) or (AY
<= NetInterpLevel
) then
4715 function TPlayer
.FullInLift(XInc
, YInc
: Integer): Integer;
4717 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
4718 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
4719 PANEL_LIFTUP
, False) then Result
:= -1
4721 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
4722 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
4723 PANEL_LIFTDOWN
, False) then Result
:= 1
4727 function TPlayer
.GetFlag(Flag
: Byte): Boolean;
4734 if Flag
= FLAG_NONE
then
4737 if not g_Game_IsServer
then Exit
;
4739 // Принес чужой флаг на свою базу:
4740 if (Flag
= FTeam
) and
4741 (gFlags
[Flag
].State
= FLAG_STATE_NORMAL
) and
4742 (FFlag
<> FLAG_NONE
) then
4744 if FFlag
= FLAG_RED
then
4745 s
:= _lc
[I_PLAYER_FLAG_RED
]
4747 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
4749 evtype
:= FLAG_STATE_SCORED
;
4751 ts
:= Format('%.4d', [gFlags
[FFlag
].CaptureTime
]);
4752 Insert('.', ts
, Length(ts
) + 1 - 3);
4753 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_CAPTURE
], [FName
, s
, ts
]), True);
4755 g_Map_ResetFlag(FFlag
);
4756 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_CAPTURE
], [AnsiUpperCase(s
)]), 144);
4758 if ((Self
= gPlayer1
) or (Self
= gPlayer2
)
4759 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= FTeam
))
4760 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= FTeam
))) then
4765 if not sound_cap_flag
[a
].IsPlaying() then
4766 sound_cap_flag
[a
].Play();
4768 gTeamStat
[FTeam
].Goals
:= gTeamStat
[FTeam
].Goals
+ 1;
4771 if g_Game_IsNet
then
4773 MH_SEND_FlagEvent(evtype
, FFlag
, FUID
, False);
4777 gFlags
[FFlag
].CaptureTime
:= 0;
4782 // Подобрал свой флаг - вернул его на базу:
4783 if (Flag
= FTeam
) and
4784 (gFlags
[Flag
].State
= FLAG_STATE_DROPPED
) then
4786 if Flag
= FLAG_RED
then
4787 s
:= _lc
[I_PLAYER_FLAG_RED
]
4789 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
4791 evtype
:= FLAG_STATE_RETURNED
;
4792 gFlags
[Flag
].CaptureTime
:= 0;
4794 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_RETURN
], [FName
, s
]), True);
4796 g_Map_ResetFlag(Flag
);
4797 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
4799 if ((Self
= gPlayer1
) or (Self
= gPlayer2
)
4800 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= FTeam
))
4801 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= FTeam
))) then
4806 if not sound_ret_flag
[a
].IsPlaying() then
4807 sound_ret_flag
[a
].Play();
4810 if g_Game_IsNet
then
4812 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
4818 // Подобрал чужой флаг:
4819 if (Flag
<> FTeam
) and (FTime
[T_FLAGCAP
] <= gTime
) then
4823 if Flag
= FLAG_RED
then
4824 s
:= _lc
[I_PLAYER_FLAG_RED
]
4826 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
4828 evtype
:= FLAG_STATE_CAPTURED
;
4830 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_GET
], [FName
, s
]), True);
4832 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_GET
], [AnsiUpperCase(s
)]), 144);
4834 gFlags
[Flag
].State
:= FLAG_STATE_CAPTURED
;
4836 if ((Self
= gPlayer1
) or (Self
= gPlayer2
)
4837 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= FTeam
))
4838 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= FTeam
))) then
4843 if not sound_get_flag
[a
].IsPlaying() then
4844 sound_get_flag
[a
].Play();
4847 if g_Game_IsNet
then
4849 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
4855 procedure TPlayer
.SetFlag(Flag
: Byte);
4858 if FModel
<> nil then
4859 FModel
.SetFlag(FFlag
);
4862 function TPlayer
.DropFlag(Silent
: Boolean = True): Boolean;
4868 if (not g_Game_IsServer
) or (FFlag
= FLAG_NONE
) then
4870 FTime
[T_FLAGCAP
] := gTime
+ 2000;
4871 with gFlags
[FFlag
] do
4875 Direction
:= FDirection
;
4876 State
:= FLAG_STATE_DROPPED
;
4878 g_Obj_Push(@Obj
, (FObj
.Vel
.X
div 2)-2+Random(5),
4879 (FObj
.Vel
.Y
div 2)-2+Random(5));
4880 positionChanged(); // this updates spatial accelerators
4882 if FFlag
= FLAG_RED
then
4883 s
:= _lc
[I_PLAYER_FLAG_RED
]
4885 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
4887 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_DROP
], [FName
, s
]), True);
4888 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_DROP
], [AnsiUpperCase(s
)]), 144);
4890 if ((Self
= gPlayer1
) or (Self
= gPlayer2
)
4891 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= FTeam
))
4892 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= FTeam
))) then
4897 if (not Silent
) and (not sound_lost_flag
[a
].IsPlaying()) then
4898 sound_lost_flag
[a
].Play();
4900 if g_Game_IsNet
then
4901 MH_SEND_FlagEvent(FLAG_STATE_DROPPED
, Flag
, FUID
, False);
4907 procedure TPlayer
.GetSecret();
4909 if (self
= gPlayer1
) or (self
= gPlayer2
) then
4911 g_Console_Add(Format(_lc
[I_PLAYER_SECRET
], [FName
]), True);
4912 g_Sound_PlayEx('SOUND_GAME_SECRET');
4917 procedure TPlayer
.PressKey(Key
: Byte; Time
: Word = 1);
4919 Assert(Key
<= High(FKeys
));
4921 FKeys
[Key
].Pressed
:= True;
4922 FKeys
[Key
].Time
:= Time
;
4925 function TPlayer
.IsKeyPressed(K
: Byte): Boolean;
4927 Result
:= FKeys
[K
].Pressed
;
4930 procedure TPlayer
.ReleaseKeys();
4934 for a
:= Low(FKeys
) to High(FKeys
) do
4936 FKeys
[a
].Pressed
:= False;
4941 procedure TPlayer
.OnDamage(Angle
: SmallInt);
4945 function TPlayer
.firediry(): Integer;
4947 if FKeys
[KEY_UP
].Pressed
then Result
:= -42
4948 else if FKeys
[KEY_DOWN
].Pressed
then Result
:= 19
4952 procedure TPlayer
.RememberState();
4955 SavedState
: TPlayerSavedState
;
4957 SavedState
.Health
:= FHealth
;
4958 SavedState
.Armor
:= FArmor
;
4959 SavedState
.Air
:= FAir
;
4960 SavedState
.JetFuel
:= FJetFuel
;
4961 SavedState
.CurrWeap
:= FCurrWeap
;
4962 SavedState
.NextWeap
:= FNextWeap
;
4963 SavedState
.NextWeapDelay
:= FNextWeapDelay
;
4964 for i
:= Low(FWeapon
) to High(FWeapon
) do
4965 SavedState
.Weapon
[i
] := FWeapon
[i
];
4966 for i
:= Low(FAmmo
) to High(FAmmo
) do
4967 SavedState
.Ammo
[i
] := FAmmo
[i
];
4968 for i
:= Low(FMaxAmmo
) to High(FMaxAmmo
) do
4969 SavedState
.MaxAmmo
[i
] := FMaxAmmo
[i
];
4970 SavedState
.Rulez
:= FRulez
- [R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
];
4972 FSavedStateNum
:= -1;
4973 for i
:= Low(SavedStates
) to High(SavedStates
) do
4974 if not SavedStates
[i
].Used
then
4976 FSavedStateNum
:= i
;
4979 if FSavedStateNum
< 0 then
4981 SetLength(SavedStates
, Length(SavedStates
) + 1);
4982 FSavedStateNum
:= High(SavedStates
);
4985 SavedState
.Used
:= True;
4986 SavedStates
[FSavedStateNum
] := SavedState
;
4989 procedure TPlayer
.RecallState();
4992 SavedState
: TPlayerSavedState
;
4994 if(FSavedStateNum
< 0) or (FSavedStateNum
> High(SavedStates
)) then
4997 SavedState
:= SavedStates
[FSavedStateNum
];
4998 SavedStates
[FSavedStateNum
].Used
:= False;
4999 FSavedStateNum
:= -1;
5001 FHealth
:= SavedState
.Health
;
5002 FArmor
:= SavedState
.Armor
;
5003 FAir
:= SavedState
.Air
;
5004 FJetFuel
:= SavedState
.JetFuel
;
5005 FCurrWeap
:= SavedState
.CurrWeap
;
5006 FNextWeap
:= SavedState
.NextWeap
;
5007 FNextWeapDelay
:= SavedState
.NextWeapDelay
;
5008 for i
:= Low(FWeapon
) to High(FWeapon
) do
5009 FWeapon
[i
] := SavedState
.Weapon
[i
];
5010 for i
:= Low(FAmmo
) to High(FAmmo
) do
5011 FAmmo
[i
] := SavedState
.Ammo
[i
];
5012 for i
:= Low(FMaxAmmo
) to High(FMaxAmmo
) do
5013 FMaxAmmo
[i
] := SavedState
.MaxAmmo
[i
];
5014 FRulez
:= SavedState
.Rulez
;
5016 if gGameSettings
.GameType
= GT_SERVER
then
5017 MH_SEND_PlayerStats(FUID
);
5020 procedure TPlayer
.SaveState (st
: TStream
);
5026 utils
.writeSign(st
, 'PLYR');
5027 utils
.writeInt(st
, Byte(PLR_SAVE_VERSION
)); // version
5029 utils
.writeBool(st
, FIamBot
);
5031 utils
.writeInt(st
, Word(FUID
));
5033 utils
.writeStr(st
, FName
);
5035 utils
.writeInt(st
, Byte(FTeam
));
5037 utils
.writeBool(st
, FAlive
);
5038 // Израсходовал ли все жизни
5039 utils
.writeBool(st
, FNoRespawn
);
5041 if FDirection
= TDirection
.D_LEFT
then b
:= 1 else b
:= 2; // D_RIGHT
5042 utils
.writeInt(st
, Byte(b
));
5044 utils
.writeInt(st
, LongInt(FHealth
));
5045 // Коэффициент инвалидности
5046 utils
.writeInt(st
, LongInt(FHandicap
));
5048 utils
.writeInt(st
, Byte(FLives
));
5050 utils
.writeInt(st
, LongInt(FArmor
));
5052 utils
.writeInt(st
, LongInt(FAir
));
5054 utils
.writeInt(st
, LongInt(FJetFuel
));
5056 utils
.writeInt(st
, LongInt(FPain
));
5058 utils
.writeInt(st
, LongInt(FKills
));
5060 utils
.writeInt(st
, LongInt(FMonsterKills
));
5062 utils
.writeInt(st
, LongInt(FFrags
));
5064 utils
.writeInt(st
, Byte(FFragCombo
));
5065 // Время последнего фрага
5066 utils
.writeInt(st
, LongWord(FLastFrag
));
5068 utils
.writeInt(st
, LongInt(FDeath
));
5070 utils
.writeInt(st
, Byte(FFlag
));
5072 utils
.writeInt(st
, LongInt(FSecrets
));
5074 utils
.writeInt(st
, Byte(FCurrWeap
));
5076 utils
.writeInt(st
, Word(FNextWeap
));
5078 utils
.writeInt(st
, Byte(FNextWeapDelay
));
5079 // Время зарядки BFG
5080 utils
.writeInt(st
, SmallInt(FBFGFireCounter
));
5082 utils
.writeInt(st
, LongInt(FDamageBuffer
));
5083 // Последний ударивший
5084 utils
.writeInt(st
, Word(FLastSpawnerUID
));
5085 // Тип последнего полученного урона
5086 utils
.writeInt(st
, Byte(FLastHit
));
5088 Obj_SaveState(st
, @FObj
);
5089 // Текущее количество патронов
5090 for i
:= A_BULLETS
to A_HIGH
do utils
.writeInt(st
, Word(FAmmo
[i
]));
5091 // Максимальное количество патронов
5092 for i
:= A_BULLETS
to A_HIGH
do utils
.writeInt(st
, Word(FMaxAmmo
[i
]));
5094 for i
:= WP_FIRST
to WP_LAST
do utils
.writeBool(st
, FWeapon
[i
]);
5095 // Время перезарядки оружия
5096 for i
:= WP_FIRST
to WP_LAST
do utils
.writeInt(st
, Word(FReloading
[i
]));
5098 utils
.writeBool(st
, (R_ITEM_BACKPACK
in FRulez
));
5099 // Наличие красного ключа
5100 utils
.writeBool(st
, (R_KEY_RED
in FRulez
));
5101 // Наличие зеленого ключа
5102 utils
.writeBool(st
, (R_KEY_GREEN
in FRulez
));
5103 // Наличие синего ключа
5104 utils
.writeBool(st
, (R_KEY_BLUE
in FRulez
));
5106 utils
.writeBool(st
, (R_BERSERK
in FRulez
));
5107 // Время действия специальных предметов
5108 for i
:= MR_SUIT
to MR_MAX
do utils
.writeInt(st
, LongWord(FMegaRulez
[i
]));
5109 // Время до повторного респауна, смены оружия, исользования, захвата флага
5110 for i
:= T_RESPAWN
to T_FLAGCAP
do utils
.writeInt(st
, LongWord(FTime
[i
]));
5112 utils
.writeStr(st
, FModel
.GetName());
5114 utils
.writeInt(st
, Byte(FColor
.R
));
5115 utils
.writeInt(st
, Byte(FColor
.G
));
5116 utils
.writeInt(st
, Byte(FColor
.B
));
5120 procedure TPlayer
.LoadState (st
: TStream
);
5129 if not utils
.checkSign(st
, 'PLYR') then raise XStreamError
.Create('invalid player signature');
5130 if (utils
.readByte(st
) <> PLR_SAVE_VERSION
) then raise XStreamError
.Create('invalid player version');
5132 FIamBot
:= utils
.readBool(st
);
5134 FUID
:= utils
.readWord(st
);
5136 str
:= utils
.readStr(st
);
5137 if (self
<> gPlayer1
) and (self
<> gPlayer2
) then FName
:= str
;
5139 FTeam
:= utils
.readByte(st
);
5141 FAlive
:= utils
.readBool(st
);
5142 // Израсходовал ли все жизни
5143 FNoRespawn
:= utils
.readBool(st
);
5145 b
:= utils
.readByte(st
);
5146 if b
= 1 then FDirection
:= TDirection
.D_LEFT
else FDirection
:= TDirection
.D_RIGHT
; // b = 2
5148 FHealth
:= utils
.readLongInt(st
);
5149 // Коэффициент инвалидности
5150 FHandicap
:= utils
.readLongInt(st
);
5152 FLives
:= utils
.readByte(st
);
5154 FArmor
:= utils
.readLongInt(st
);
5156 FAir
:= utils
.readLongInt(st
);
5158 FJetFuel
:= utils
.readLongInt(st
);
5160 FPain
:= utils
.readLongInt(st
);
5162 FKills
:= utils
.readLongInt(st
);
5164 FMonsterKills
:= utils
.readLongInt(st
);
5166 FFrags
:= utils
.readLongInt(st
);
5168 FFragCombo
:= utils
.readByte(st
);
5169 // Время последнего фрага
5170 FLastFrag
:= utils
.readLongWord(st
);
5172 FDeath
:= utils
.readLongInt(st
);
5174 FFlag
:= utils
.readByte(st
);
5176 FSecrets
:= utils
.readLongInt(st
);
5178 FCurrWeap
:= utils
.readByte(st
);
5180 FNextWeap
:= utils
.readWord(st
);
5182 FNextWeapDelay
:= utils
.readByte(st
);
5183 // Время зарядки BFG
5184 FBFGFireCounter
:= utils
.readSmallInt(st
);
5186 FDamageBuffer
:= utils
.readLongInt(st
);
5187 // Последний ударивший
5188 FLastSpawnerUID
:= utils
.readWord(st
);
5189 // Тип последнего полученного урона
5190 FLastHit
:= utils
.readByte(st
);
5192 Obj_LoadState(@FObj
, st
);
5193 // Текущее количество патронов
5194 for i
:= A_BULLETS
to A_HIGH
do FAmmo
[i
] := utils
.readWord(st
);
5195 // Максимальное количество патронов
5196 for i
:= A_BULLETS
to A_HIGH
do FMaxAmmo
[i
] := utils
.readWord(st
);
5198 for i
:= WP_FIRST
to WP_LAST
do FWeapon
[i
] := utils
.readBool(st
);
5199 // Время перезарядки оружия
5200 for i
:= WP_FIRST
to WP_LAST
do FReloading
[i
] := utils
.readWord(st
);
5202 if utils
.readBool(st
) then Include(FRulez
, R_ITEM_BACKPACK
);
5203 // Наличие красного ключа
5204 if utils
.readBool(st
) then Include(FRulez
, R_KEY_RED
);
5205 // Наличие зеленого ключа
5206 if utils
.readBool(st
) then Include(FRulez
, R_KEY_GREEN
);
5207 // Наличие синего ключа
5208 if utils
.readBool(st
) then Include(FRulez
, R_KEY_BLUE
);
5210 if utils
.readBool(st
) then Include(FRulez
, R_BERSERK
);
5211 // Время действия специальных предметов
5212 for i
:= MR_SUIT
to MR_MAX
do FMegaRulez
[i
] := utils
.readLongWord(st
);
5213 // Время до повторного респауна, смены оружия, исользования, захвата флага
5214 for i
:= T_RESPAWN
to T_FLAGCAP
do FTime
[i
] := utils
.readLongWord(st
);
5216 str
:= utils
.readStr(st
);
5218 FColor
.R
:= utils
.readByte(st
);
5219 FColor
.G
:= utils
.readByte(st
);
5220 FColor
.B
:= utils
.readByte(st
);
5221 if (self
= gPlayer1
) then
5223 str
:= gPlayer1Settings
.Model
;
5224 FColor
:= gPlayer1Settings
.Color
;
5226 else if (self
= gPlayer2
) then
5228 str
:= gPlayer2Settings
.Model
;
5229 FColor
:= gPlayer2Settings
.Color
;
5231 // Обновляем модель игрока
5233 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
5234 FModel
.Color
:= TEAMCOLOR
[FTeam
]
5236 FModel
.Color
:= FColor
;
5240 procedure TPlayer
.AllRulez(Health
: Boolean);
5246 FHealth
:= PLAYER_HP_LIMIT
;
5247 FArmor
:= PLAYER_AP_LIMIT
;
5251 for a
:= WP_FIRST
to WP_LAST
do FWeapon
[a
] := True;
5252 for a
:= A_BULLETS
to A_HIGH
do FAmmo
[a
] := 30000;
5253 FRulez
:= FRulez
+[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
];
5256 procedure TPlayer
.RestoreHealthArmor();
5258 FHealth
:= PLAYER_HP_LIMIT
;
5259 FArmor
:= PLAYER_AP_LIMIT
;
5262 procedure TPlayer
.FragCombo();
5266 if (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) or g_Game_IsClient
then
5268 if gTime
- FLastFrag
< FRAG_COMBO_TIME
then
5270 if FFragCombo
< 5 then
5272 Param
:= FUID
or (FFragCombo
shl 16);
5273 if (FComboEvnt
>= Low(gDelayedEvents
)) and
5274 (FComboEvnt
<= High(gDelayedEvents
)) and
5275 gDelayedEvents
[FComboEvnt
].Pending
and
5276 (gDelayedEvents
[FComboEvnt
].DEType
= DE_KILLCOMBO
) and
5277 (gDelayedEvents
[FComboEvnt
].DENum
and $FFFF = FUID
) then
5279 gDelayedEvents
[FComboEvnt
].Time
:= gTime
+ 500;
5280 gDelayedEvents
[FComboEvnt
].DENum
:= Param
;
5283 FComboEvnt
:= g_Game_DelayEvent(DE_KILLCOMBO
, 500, Param
);
5291 procedure TPlayer
.GiveItem(ItemType
: Byte);
5295 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
5297 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
5301 if FAir
< AIR_MAX
then
5308 if not (R_BERSERK
in FRulez
) then
5310 Include(FRulez
, R_BERSERK
);
5311 if FBFGFireCounter
< 1 then
5313 FCurrWeap
:= WEAPON_KASTET
;
5315 FModel
.SetWeapon(WEAPON_KASTET
);
5319 FBerserk
:= gTime
+30000;
5321 if FHealth
< PLAYER_HP_SOFT
then
5323 FHealth
:= PLAYER_HP_SOFT
;
5324 FBerserk
:= gTime
+30000;
5329 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
5331 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
5336 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
5338 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
5342 if FJetFuel
< JET_MAX
then
5344 FJetFuel
:= JET_MAX
;
5347 ITEM_MEDKIT_SMALL
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
5348 ITEM_MEDKIT_LARGE
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
5350 ITEM_ARMOR_GREEN
: if FArmor
< PLAYER_AP_SOFT
then FArmor
:= PLAYER_AP_SOFT
;
5351 ITEM_ARMOR_BLUE
: if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
5353 ITEM_SPHERE_BLUE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
5355 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) then
5357 if FHealth
< PLAYER_HP_LIMIT
then FHealth
:= PLAYER_HP_LIMIT
;
5358 if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
5361 ITEM_WEAPON_SAW
: FWeapon
[WEAPON_SAW
] := True;
5362 ITEM_WEAPON_SHOTGUN1
: FWeapon
[WEAPON_SHOTGUN1
] := True;
5363 ITEM_WEAPON_SHOTGUN2
: FWeapon
[WEAPON_SHOTGUN2
] := True;
5364 ITEM_WEAPON_CHAINGUN
: FWeapon
[WEAPON_CHAINGUN
] := True;
5365 ITEM_WEAPON_ROCKETLAUNCHER
: FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
5366 ITEM_WEAPON_PLASMA
: FWeapon
[WEAPON_PLASMA
] := True;
5367 ITEM_WEAPON_BFG
: FWeapon
[WEAPON_BFG
] := True;
5368 ITEM_WEAPON_SUPERPULEMET
: FWeapon
[WEAPON_SUPERPULEMET
] := True;
5369 ITEM_WEAPON_FLAMETHROWER
: FWeapon
[WEAPON_FLAMETHROWER
] := True;
5371 ITEM_AMMO_BULLETS
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
5372 ITEM_AMMO_BULLETS_BOX
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
5373 ITEM_AMMO_SHELLS
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
5374 ITEM_AMMO_SHELLS_BOX
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
5375 ITEM_AMMO_ROCKET
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
5376 ITEM_AMMO_ROCKET_BOX
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
5377 ITEM_AMMO_CELL
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
5378 ITEM_AMMO_CELL_BIG
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
5379 ITEM_AMMO_FUELCAN
: if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
5382 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
5383 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
5384 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
5385 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or
5386 (FMaxAmmo
[A_FUEL
] < AmmoLimits
[1, A_FUEL
]) then
5388 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[1, A_BULLETS
];
5389 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[1, A_SHELLS
];
5390 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[1, A_ROCKETS
];
5391 FMaxAmmo
[A_CELLS
] := AmmoLimits
[1, A_CELLS
];
5392 FMaxAmmo
[A_FUEL
] := AmmoLimits
[1, A_FUEL
];
5394 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
5395 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
5396 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
5397 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
5399 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
5402 ITEM_KEY_RED
: if not (R_KEY_RED
in FRulez
) then Include(FRulez
, R_KEY_RED
);
5403 ITEM_KEY_GREEN
: if not (R_KEY_GREEN
in FRulez
) then Include(FRulez
, R_KEY_GREEN
);
5404 ITEM_KEY_BLUE
: if not (R_KEY_BLUE
in FRulez
) then Include(FRulez
, R_KEY_BLUE
);
5406 ITEM_BOTTLE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
5407 ITEM_HELMET
: if FArmor
< PLAYER_AP_LIMIT
then IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
5412 if g_Game_IsNet
and g_Game_IsServer
then
5413 MH_SEND_PlayerStats(FUID
);
5416 procedure TPlayer
.FlySmoke(Times
: DWORD
= 1);
5419 if (Random(5) = 1) and (Times
= 1) then
5422 if BodyInLiquid(0, 0) then
5425 g_GFX_Bubbles(Obj
.X
+Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2)+Random(3)-1,
5426 Obj
.Y
+Obj
.Rect
.Height
+8, 1, 8, 4);
5428 if Random(2) = 0 then
5429 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
5431 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
5435 for i
:= 1 to Times
do
5440 Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(R_GFX_SMOKE_WIDTH
div 2),
5441 Obj
.Y
+Obj
.Rect
.Height
-4+Random(8+Times
*2)
5447 procedure TPlayer
.OnFireFlame(Times
: DWORD
= 1);
5450 if (Random(10) = 1) and (Times
= 1) then
5453 for i
:= 1 to Times
do
5458 Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(R_GFX_FLAME_WIDTH
div 2),
5459 Obj
.Y
+8+Random(8+Times
*2)
5465 procedure TPlayer
.PauseSounds(Enable
: Boolean);
5467 FSawSound
.Pause(Enable
);
5468 FSawSoundIdle
.Pause(Enable
);
5469 FSawSoundHit
.Pause(Enable
);
5470 FSawSoundSelect
.Pause(Enable
);
5471 FFlameSoundOn
.Pause(Enable
);
5472 FFlameSoundOff
.Pause(Enable
);
5473 FFlameSoundWork
.Pause(Enable
);
5474 FJetSoundFly
.Pause(Enable
);
5475 FJetSoundOn
.Pause(Enable
);
5476 FJetSoundOff
.Pause(Enable
);
5481 constructor TCorpse
.Create(X
, Y
: Integer; ModelName
: String; aMess
: Boolean);
5486 FObj
.Rect
:= PLAYER_CORPSERECT
;
5488 FModel
:= g_PlayerModel_Get(ModelName
);
5492 FState
:= CORPSE_STATE_MESS
;
5493 FModel
.ChangeAnimation(A_DIE2
);
5497 FState
:= CORPSE_STATE_NORMAL
;
5498 FModel
.ChangeAnimation(A_DIE1
);
5502 destructor TCorpse
.Destroy();
5508 function TCorpse
.ObjPtr (): PObj
; inline; begin result
:= @FObj
; end;
5510 procedure TCorpse
.positionChanged (); inline; begin end;
5512 procedure TCorpse
.moveBy (dx
, dy
: Integer); inline;
5514 if (dx
<> 0) or (dy
<> 0) then
5523 procedure TCorpse
.getMapBox (out x
, y
, w
, h
: Integer); inline;
5525 x
:= FObj
.X
+PLAYER_CORPSERECT
.X
;
5526 y
:= FObj
.Y
+PLAYER_CORPSERECT
.Y
;
5527 w
:= PLAYER_CORPSERECT
.Width
;
5528 h
:= PLAYER_CORPSERECT
.Height
;
5532 procedure TCorpse
.Damage(Value
: Word; SpawnerUID
: Word; vx
, vy
: Integer);
5534 var Blood
: TModelBlood
;
5537 if FState
= CORPSE_STATE_REMOVEME
then
5540 FDamage
:= FDamage
+ Value
;
5542 {$IFDEF ENABLE_GIBS}
5543 if FDamage
> 150 then
5545 if FModel
<> nil then
5547 FState
:= CORPSE_STATE_REMOVEME
;
5550 FObj
.X
+ FObj
.Rect
.X
+ (FObj
.Rect
.Width
div 2),
5551 FObj
.Y
+ FObj
.Rect
.Y
+ (FObj
.Rect
.Height
div 2),
5556 // Звук мяса от трупа:
5557 FModel
.PlaySound(MODELSOUND_DIE
, 5, FObj
.X
, FObj
.Y
);
5560 if (gBodyKillEvent
<> -1) and gDelayedEvents
[gBodyKillEvent
].Pending
then
5561 gDelayedEvents
[gBodyKillEvent
].Pending
:= False;
5562 gBodyKillEvent
:= g_Game_DelayEvent(DE_BODYKILL
, 1050, SpawnerUID
);
5571 FObj
.Vel
.X
:= FObj
.Vel
.X
+ vx
;
5572 FObj
.Vel
.Y
:= FObj
.Vel
.Y
+ vy
;
5574 Blood
:= FModel
.GetBlood();
5575 g_GFX_Blood(FObj
.X
+PLAYER_CORPSERECT
.X
+(PLAYER_CORPSERECT
.Width
div 2),
5576 FObj
.Y
+PLAYER_CORPSERECT
.Y
+(PLAYER_CORPSERECT
.Height
div 2),
5577 Value
, vx
, vy
, 16, (PLAYER_CORPSERECT
.Height
*2) div 3,
5578 Blood
.R
, Blood
.G
, Blood
.B
, Blood
.Kind
);
5583 procedure TCorpse
.Update();
5587 if FState
= CORPSE_STATE_REMOVEME
then
5590 FObj
.oldX
:= FObj
.X
;
5591 FObj
.oldY
:= FObj
.Y
;
5593 if gTime
mod (GAME_TICK
*2) <> 0 then
5595 g_Obj_Move(@FObj
, True, True, True);
5596 positionChanged(); // this updates spatial accelerators
5600 // Сопротивление воздуха для трупа:
5601 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
5603 st
:= g_Obj_Move(@FObj
, True, True, True);
5604 positionChanged(); // this updates spatial accelerators
5606 if WordBool(st
and MOVE_FALLOUT
) then
5608 FState
:= CORPSE_STATE_REMOVEME
;
5612 if FModel
<> nil then
5617 procedure TCorpse
.SaveState (st
: TStream
);
5623 utils
.writeSign(st
, 'CORP');
5624 utils
.writeInt(st
, Byte(0));
5626 utils
.writeInt(st
, Byte(FState
));
5628 utils
.writeInt(st
, Byte(FDamage
));
5630 utils
.writeInt(st
, Byte(FModel
.Color
.R
));
5631 utils
.writeInt(st
, Byte(FModel
.Color
.G
));
5632 utils
.writeInt(st
, Byte(FModel
.Color
.B
));
5634 Obj_SaveState(st
, @FObj
);
5635 utils
.writeInt(st
, Word(FPlayerUID
));
5637 anim
:= (FModel
<> nil);
5638 utils
.writeBool(st
, anim
);
5639 if anim
then FModel
.AnimState
.SaveState(st
, 0, False);
5640 // animation for mask (same as animation, compat with older saves)
5641 anim
:= (FModel
<> nil);
5642 utils
.writeBool(st
, anim
);
5643 if anim
then FModel
.AnimState
.SaveState(st
, 0, False);
5647 procedure TCorpse
.LoadState (st
: TStream
);
5648 var anim
, blending
: Boolean; r
, g
, b
, alpha
: Byte; stub
: TAnimationState
;
5653 if not utils
.checkSign(st
, 'CORP') then raise XStreamError
.Create('invalid corpse signature');
5654 if (utils
.readByte(st
) <> 0) then raise XStreamError
.Create('invalid corpse version');
5656 FState
:= utils
.readByte(st
);
5658 FDamage
:= utils
.readByte(st
);
5660 r
:= utils
.readByte(st
);
5661 g
:= utils
.readByte(st
);
5662 b
:= utils
.readByte(st
);
5663 FModel
.SetColor(r
, g
, b
);
5665 Obj_LoadState(@FObj
, st
);
5666 FPlayerUID
:= utils
.readWord(st
);
5668 stub
:= TAnimationState
.Create(False, 0, 0);
5669 anim
:= utils
.readBool(st
);
5672 stub
.LoadState(st
, alpha
, blending
);
5673 FModel
.AnimState
.CurrentFrame
:= Min(stub
.CurrentFrame
, FModel
.AnimState
.Length
);
5680 // animation for mask (same as animation, compat with older saves)
5681 anim
:= utils
.readBool(st
);
5682 if anim
then stub
.LoadState(st
, alpha
, blending
);
5688 constructor TBot
.Create();
5695 FSpectator
:= False;
5702 for a
:= WP_FIRST
to WP_LAST
do
5704 FDifficult
.WeaponPrior
[a
] := WEAPON_PRIOR1
[a
];
5705 FDifficult
.CloseWeaponPrior
[a
] := WEAPON_PRIOR2
[a
];
5706 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
5710 destructor TBot
.Destroy();
5713 inherited Destroy();
5716 procedure TBot
.Respawn(Silent
: Boolean; Force
: Boolean = False);
5718 inherited Respawn(Silent
, Force
);
5721 FSelectedWeapon
:= FCurrWeap
;
5726 procedure TBot
.UpdateCombat();
5739 TTargetRecord
= array of TTarget
;
5741 function Compare(a
, b
: TTarget
): Integer;
5743 if a
.Line
and not b
.Line
then // A на линии огня
5746 if not a
.Line
and b
.Line
then // B на линии огня
5748 else // И A, и B на линии или не на линии огня
5749 if (a
.Line
and b
.Line
) or ((not a
.Line
) and (not b
.Line
)) then
5751 if a
.Dist
> b
.Dist
then // B ближе
5753 else // A ближе или равноудаленно с B
5756 else // Странно -> A
5761 a
, x1
, y1
, x2
, y2
: Integer;
5762 targets
: TTargetRecord
;
5764 Target
, BestTarget
: TTarget
;
5765 firew
, fireh
: Integer;
5769 vsPlayer
, vsMonster
, ok
: Boolean;
5772 function monsUpdate (mon
: TMonster
): Boolean;
5774 result
:= false; // don't stop
5775 if mon
.alive
and (mon
.MonsterType
<> MONSTER_BARREL
) then
5777 if not TargetOnScreen(mon
.Obj
.X
+mon
.Obj
.Rect
.X
, mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
) then exit
;
5779 x2
:= mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2);
5780 y2
:= mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+(mon
.Obj
.Rect
.Height
div 2);
5782 // Если монстр на экране и не прикрыт стеной
5783 if g_TraceVector(x1
, y1
, x2
, y2
) then
5785 // Добавляем к списку возможных целей
5786 SetLength(targets
, Length(targets
)+1);
5787 with targets
[High(targets
)] do
5794 Rect
:= mon
.Obj
.Rect
;
5795 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
5796 Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
5797 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
5806 vsPlayer
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
);
5807 vsMonster
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
);
5809 // Если текущее оружие не то, что нужно, то меняем:
5810 if FCurrWeap
<> FSelectedWeapon
then
5813 // Если нужно стрелять и нужное оружие, то нажать "Стрелять":
5814 if (GetAIFlag('NEEDFIRE') <> '') and (FCurrWeap
= FSelectedWeapon
) then
5816 RemoveAIFlag('NEEDFIRE');
5819 WEAPON_PLASMA
, WEAPON_SUPERPULEMET
, WEAPON_CHAINGUN
: PressKey(KEY_FIRE
, 20);
5820 WEAPON_SAW
, WEAPON_KASTET
, WEAPON_FLAMETHROWER
: PressKey(KEY_FIRE
, 40);
5821 else PressKey(KEY_FIRE
);
5825 // Координаты ствола:
5826 x1
:= FObj
.X
+ WEAPONPOINT
[FDirection
].X
;
5827 y1
:= FObj
.Y
+ WEAPONPOINT
[FDirection
].Y
;
5829 Target
.UID
:= FTargetUID
;
5832 if Target
.UID
<> 0 then
5833 begin // Цель есть - настраиваем
5834 if (g_GetUIDType(Target
.UID
) = UID_PLAYER
) and
5837 tpla
:= g_Player_Get(Target
.UID
);
5841 if (@FObj
) <> nil then
5848 Target
.cX
:= Target
.X
+ PLAYER_RECT_CX
;
5849 Target
.cY
:= Target
.Y
+ PLAYER_RECT_CY
;
5850 Target
.Rect
:= PLAYER_RECT
;
5851 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
5852 Target
.Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
5853 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
5854 Target
.IsPlayer
:= True;
5858 if (g_GetUIDType(Target
.UID
) = UID_MONSTER
) and
5861 mon
:= g_Monsters_ByUID(Target
.UID
);
5864 Target
.X
:= mon
.Obj
.X
;
5865 Target
.Y
:= mon
.Obj
.Y
;
5867 Target
.cX
:= Target
.X
+ mon
.Obj
.Rect
.X
+ (mon
.Obj
.Rect
.Width
div 2);
5868 Target
.cY
:= Target
.Y
+ mon
.Obj
.Rect
.Y
+ (mon
.Obj
.Rect
.Height
div 2);
5869 Target
.Rect
:= mon
.Obj
.Rect
;
5870 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
5871 Target
.Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
5872 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
5873 Target
.IsPlayer
:= False;
5880 begin // Цели нет - обнуляем
5885 Target
.Visible
:= False;
5886 Target
.Line
:= False;
5887 Target
.IsPlayer
:= False;
5892 // Если цель не видима или не на линии огня, то ищем все возможные цели:
5893 if (not Target
.Line
) or (not Target
.Visible
) then
5897 for a
:= 0 to High(gPlayers
) do
5898 if (gPlayers
[a
] <> nil) and (gPlayers
[a
].alive
) and
5899 (gPlayers
[a
].FUID
<> FUID
) and
5900 (not SameTeam(FUID
, gPlayers
[a
].FUID
)) and
5901 (not gPlayers
[a
].NoTarget
) and
5902 (gPlayers
[a
].FMegaRulez
[MR_INVIS
] < gTime
) then
5904 if not TargetOnScreen(gPlayers
[a
].FObj
.X
+ PLAYER_RECT
.X
,
5905 gPlayers
[a
].FObj
.Y
+ PLAYER_RECT
.Y
) then
5908 x2
:= gPlayers
[a
].FObj
.X
+ PLAYER_RECT_CX
;
5909 y2
:= gPlayers
[a
].FObj
.Y
+ PLAYER_RECT_CY
;
5911 // Если игрок на экране и не прикрыт стеной:
5912 if g_TraceVector(x1
, y1
, x2
, y2
) then
5914 // Добавляем к списку возможных целей:
5915 SetLength(targets
, Length(targets
)+1);
5916 with targets
[High(targets
)] do
5918 UID
:= gPlayers
[a
].FUID
;
5919 X
:= gPlayers
[a
].FObj
.X
;
5920 Y
:= gPlayers
[a
].FObj
.Y
;
5923 Rect
:= PLAYER_RECT
;
5924 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
5925 Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
5926 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
5934 if vsMonster
then g_Mons_ForEach(monsUpdate
);
5937 // Если есть возможные цели:
5938 // (Выбираем лучшую, меняем оружие и бежим к ней/от нее)
5939 if targets
<> nil then
5941 // Выбираем наилучшую цель:
5942 BestTarget
:= targets
[0];
5943 if Length(targets
) > 1 then
5944 for a
:= 1 to High(targets
) do
5945 if Compare(BestTarget
, targets
[a
]) = 1 then
5946 BestTarget
:= targets
[a
];
5948 // Если лучшая цель "виднее" текущей, то текущая := лучшая:
5949 if ((not Target
.Visible
) and BestTarget
.Visible
and (Target
.UID
<> BestTarget
.UID
)) or
5950 ((not Target
.Line
) and BestTarget
.Line
and BestTarget
.Visible
) then
5952 Target
:= BestTarget
;
5954 if (Healthy() = 3) or ((Healthy() = 2)) then
5955 begin // Если здоровы - догоняем
5956 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
5957 SetAIFlag('GORIGHT', '1');
5958 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
5959 SetAIFlag('GOLEFT', '1');
5962 begin // Если побиты - убегаем
5963 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) then
5964 SetAIFlag('GORIGHT', '1');
5965 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
5966 SetAIFlag('GOLEFT', '1');
5969 // Выбираем оружие на основе расстояния и приоритетов:
5970 SelectWeapon(Abs(x1
-Target
.cX
));
5975 // (Догоняем/убегаем, стреляем по направлению к цели)
5976 // (Если цель далеко, то хватит следить за ней)
5977 if Target
.UID
<> 0 then
5979 if not TargetOnScreen(Target
.X
+ Target
.Rect
.X
,
5980 Target
.Y
+ Target
.Rect
.Y
) then
5981 begin // Цель сбежала с "экрана"
5982 if (Healthy() = 3) or ((Healthy() = 2)) then
5983 begin // Если здоровы - догоняем
5984 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
5985 SetAIFlag('GORIGHT', '1');
5986 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
5987 SetAIFlag('GOLEFT', '1');
5990 begin // Если побиты - забываем о цели и убегаем
5992 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) then
5993 SetAIFlag('GORIGHT', '1');
5994 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
5995 SetAIFlag('GOLEFT', '1');
5999 begin // Цель пока на "экране"
6000 // Если цель не загорожена стеной, то отмечаем, когда ее видели:
6001 if g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6002 FLastVisible
:= gTime
;
6003 // Если разница высот не велика, то догоняем:
6004 if (Abs(FObj
.Y
-Target
.Y
) <= 128) then
6006 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
6007 SetAIFlag('GORIGHT', '1');
6008 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6009 SetAIFlag('GOLEFT', '1');
6013 // Выбираем угол вверх:
6014 if FDirection
= TDirection
.D_LEFT
then
6015 angle
:= ANGLE_LEFTUP
6017 angle
:= ANGLE_RIGHTUP
;
6019 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6020 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6022 // Если при угле вверх можно попасть в приблизительное положение цели:
6023 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6024 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128), //96
6025 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6026 Target
.Rect
.Width
, Target
.Rect
.Height
) and
6027 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6028 begin // то нужно стрелять вверх
6029 SetAIFlag('NEEDFIRE', '1');
6030 SetAIFlag('NEEDSEEUP', '1');
6033 // Выбираем угол вниз:
6034 if FDirection
= TDirection
.D_LEFT
then
6035 angle
:= ANGLE_LEFTDOWN
6037 angle
:= ANGLE_RIGHTDOWN
;
6039 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6040 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6042 // Если при угле вниз можно попасть в приблизительное положение цели:
6043 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6044 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
6045 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6046 Target
.Rect
.Width
, Target
.Rect
.Height
) and
6047 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6048 begin // то нужно стрелять вниз
6049 SetAIFlag('NEEDFIRE', '1');
6050 SetAIFlag('NEEDSEEDOWN', '1');
6053 // Если цель видно и она на такой же высоте:
6054 if Target
.Visible
and
6055 (y1
+4 < Target
.Y
+Target
.Rect
.Y
+Target
.Rect
.Height
) and
6056 (y1
-4 > Target
.Y
+Target
.Rect
.Y
) then
6058 // Если идем в сторону цели, то надо стрелять:
6059 if ((FDirection
= TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) or
6060 ((FDirection
= TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6061 begin // то нужно стрелять вперед
6062 SetAIFlag('NEEDFIRE', '1');
6063 SetAIFlag('NEEDSEEDOWN', '');
6064 SetAIFlag('NEEDSEEUP', '');
6066 // Если цель в пределах "экрана" и сложность позволяет прыжки сближения:
6067 if Abs(FObj
.X
-Target
.X
) < Trunc(gPlayerScreenSize
.X
*0.75) then
6068 if GetRnd(FDifficult
.CloseJump
) then
6069 begin // то если повезет - прыгаем (особенно, если близко)
6070 if Abs(FObj
.X
-Target
.X
) < 128 then
6074 if Random(a
) = 0 then
6075 SetAIFlag('NEEDJUMP', '1');
6079 // Если цель все еще есть:
6080 if Target
.UID
<> 0 then
6081 if gTime
-FLastVisible
> 2000 then // Если видели давно
6082 Target
.UID
:= 0 // то забыть цель
6083 else // Если видели недавно
6084 begin // но цель убили
6085 if Target
.IsPlayer
then
6086 begin // Цель - игрок
6087 pla
:= g_Player_Get(Target
.UID
);
6088 if (pla
= nil) or (not pla
.alive
) or pla
.NoTarget
or
6089 (pla
.FMegaRulez
[MR_INVIS
] >= gTime
) then
6090 Target
.UID
:= 0; // то забыть цель
6093 begin // Цель - монстр
6094 mon
:= g_Monsters_ByUID(Target
.UID
);
6095 if (mon
= nil) or (not mon
.alive
) then
6096 Target
.UID
:= 0; // то забыть цель
6099 end; // if Target.UID <> 0
6101 FTargetUID
:= Target
.UID
;
6103 // Если возможных целей нет:
6104 // (Атака чего-нибудь слева или справа)
6105 if targets
= nil then
6106 if GetAIFlag('ATTACKLEFT') <> '' then
6107 begin // Если нужно атаковать налево
6108 RemoveAIFlag('ATTACKLEFT');
6110 SetAIFlag('NEEDJUMP', '1');
6112 if RunDirection() = TDirection
.D_RIGHT
then
6113 begin // Идем не в ту сторону
6114 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
6115 begin // Если здоровы, то, возможно, стреляем бежим влево и стреляем
6116 SetAIFlag('NEEDFIRE', '1');
6117 SetAIFlag('GOLEFT', '1');
6121 begin // Идем в нужную сторону
6122 if GetRnd(FDifficult
.InvisFire
) then // Возможно, стреляем вслепую
6123 SetAIFlag('NEEDFIRE', '1');
6124 if Healthy() <= 1 then // Побиты - убегаем
6125 SetAIFlag('GORIGHT', '1');
6129 if GetAIFlag('ATTACKRIGHT') <> '' then
6130 begin // Если нужно атаковать направо
6131 RemoveAIFlag('ATTACKRIGHT');
6133 SetAIFlag('NEEDJUMP', '1');
6135 if RunDirection() = TDirection
.D_LEFT
then
6136 begin // Идем не в ту сторону
6137 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
6138 begin // Если здоровы, то, возможно, бежим вправо и стреляем
6139 SetAIFlag('NEEDFIRE', '1');
6140 SetAIFlag('GORIGHT', '1');
6145 if GetRnd(FDifficult
.InvisFire
) then // Возможно, стреляем вслепую
6146 SetAIFlag('NEEDFIRE', '1');
6147 if Healthy() <= 1 then // Побиты - убегаем
6148 SetAIFlag('GOLEFT', '1');
6152 //HACK! (does it belongs there?)
6153 RealizeCurrentWeapon();
6155 // Если есть возможные цели:
6156 // (Стреляем по направлению к целям)
6157 if (targets
<> nil) and (GetAIFlag('NEEDFIRE') <> '') then
6158 for a
:= 0 to High(targets
) do
6160 // Если можем стрелять по диагонали:
6161 if GetRnd(FDifficult
.DiagFire
) then
6163 // Ищем цель сверху и стреляем, если есть:
6164 if FDirection
= TDirection
.D_LEFT
then
6165 angle
:= ANGLE_LEFTUP
6167 angle
:= ANGLE_RIGHTUP
;
6169 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6170 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6172 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6173 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
6174 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6175 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
6176 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
6178 SetAIFlag('NEEDFIRE', '1');
6179 SetAIFlag('NEEDSEEUP', '1');
6182 // Ищем цель снизу и стреляем, если есть:
6183 if FDirection
= TDirection
.D_LEFT
then
6184 angle
:= ANGLE_LEFTDOWN
6186 angle
:= ANGLE_RIGHTDOWN
;
6188 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6189 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6191 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6192 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
6193 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6194 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
6195 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
6197 SetAIFlag('NEEDFIRE', '1');
6198 SetAIFlag('NEEDSEEDOWN', '1');
6202 // Если цель "перед носом", то стреляем:
6203 if targets
[a
].Line
and targets
[a
].Visible
and
6204 (((FDirection
= TDirection
.D_LEFT
) and (targets
[a
].X
< FObj
.X
)) or
6205 ((FDirection
= TDirection
.D_RIGHT
) and (targets
[a
].X
> FObj
.X
))) then
6207 SetAIFlag('NEEDFIRE', '1');
6212 // Если летит пуля, то, возможно, подпрыгиваем:
6213 if g_Weapon_Danger(FUID
, FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
,
6214 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
,
6215 40+GetInterval(FDifficult
.Cover
, 40)) then
6216 SetAIFlag('NEEDJUMP', '1');
6218 // Если кончились паторны, то нужно сменить оружие:
6219 ammo
:= GetAmmoByWeapon(FCurrWeap
);
6220 if ((FCurrWeap
= WEAPON_SHOTGUN2
) and (ammo
< 2)) or
6221 ((FCurrWeap
= WEAPON_BFG
) and (ammo
< 40)) or
6223 SetAIFlag('SELECTWEAPON', '1');
6225 // Если нужно сменить оружие, то выбираем нужное:
6226 if GetAIFlag('SELECTWEAPON') = '1' then
6229 RemoveAIFlag('SELECTWEAPON');
6233 procedure TBot
.Update();
6246 // Проверяем, отключён ли AI ботов
6247 if (g_debug_BotAIOff
= 1) and (Team
= TEAM_RED
) then
6249 if (g_debug_BotAIOff
= 2) and (Team
= TEAM_BLUE
) then
6251 if g_debug_BotAIOff
= 3 then
6261 RealizeCurrentWeapon();
6268 procedure TBot
.ReleaseKey(Key
: Byte);
6277 function TBot
.KeyPressed(Key
: Word): Boolean;
6279 Result
:= FKeys
[Key
].Pressed
;
6282 function TBot
.GetAIFlag(aName
: String20
): String20
;
6288 aName
:= LowerCase(aName
);
6290 if FAIFlags
<> nil then
6291 for a
:= 0 to High(FAIFlags
) do
6292 if LowerCase(FAIFlags
[a
].Name
) = aName
then
6294 Result
:= FAIFlags
[a
].Value
;
6299 procedure TBot
.RemoveAIFlag(aName
: String20
);
6303 if FAIFlags
= nil then Exit
;
6305 aName
:= LowerCase(aName
);
6307 for a
:= 0 to High(FAIFlags
) do
6308 if LowerCase(FAIFlags
[a
].Name
) = aName
then
6310 if a
<> High(FAIFlags
) then
6311 for b
:= a
to High(FAIFlags
)-1 do
6312 FAIFlags
[b
] := FAIFlags
[b
+1];
6314 SetLength(FAIFlags
, Length(FAIFlags
)-1);
6319 procedure TBot
.SetAIFlag(aName
, fValue
: String20
);
6327 aName
:= LowerCase(aName
);
6329 if FAIFlags
<> nil then
6330 for a
:= 0 to High(FAIFlags
) do
6331 if LowerCase(FAIFlags
[a
].Name
) = aName
then
6337 if ok
then FAIFlags
[a
].Value
:= fValue
6340 SetLength(FAIFlags
, Length(FAIFlags
)+1);
6341 with FAIFlags
[High(FAIFlags
)] do
6349 procedure TBot
.UpdateMove
;
6351 procedure GoLeft(Time
: Word = 1);
6353 ReleaseKey(KEY_LEFT
);
6354 ReleaseKey(KEY_RIGHT
);
6355 PressKey(KEY_LEFT
, Time
);
6356 SetDirection(TDirection
.D_LEFT
);
6359 procedure GoRight(Time
: Word = 1);
6361 ReleaseKey(KEY_LEFT
);
6362 ReleaseKey(KEY_RIGHT
);
6363 PressKey(KEY_RIGHT
, Time
);
6364 SetDirection(TDirection
.D_RIGHT
);
6367 function Rnd(a
: Word): Boolean;
6369 Result
:= Random(a
) = 0;
6372 procedure Turn(Time
: Word = 1200);
6374 if RunDirection() = TDirection
.D_LEFT
then GoRight(Time
) else GoLeft(Time
);
6379 ReleaseKey(KEY_LEFT
);
6380 ReleaseKey(KEY_RIGHT
);
6383 function CanRunLeft(): Boolean;
6385 Result
:= not CollideLevel(-1, 0);
6388 function CanRunRight(): Boolean;
6390 Result
:= not CollideLevel(1, 0);
6393 function CanRun(): Boolean;
6395 if RunDirection() = TDirection
.D_LEFT
then Result
:= CanRunLeft() else Result
:= CanRunRight();
6398 procedure Jump(Time
: Word = 30);
6400 PressKey(KEY_JUMP
, Time
);
6403 function NearHole(): Boolean;
6407 { TODO 5 : Лестницы }
6408 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
6409 for x
:= 1 to PLAYER_RECT
.Width
do
6410 if (not StayOnStep(x
*sx
, 0)) and
6411 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
6412 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
6421 function BorderHole(): Boolean;
6425 { TODO 5 : Лестницы }
6426 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
6427 for x
:= 1 to PLAYER_RECT
.Width
do
6428 if (not StayOnStep(x
*sx
, 0)) and
6429 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
6430 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
6432 for xx
:= x
to x
+32 do
6433 if CollideLevel(xx
*sx
, PLAYER_RECT
.Height
) then
6443 function NearDeepHole(): Boolean;
6449 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
6452 for x
:= 1 to PLAYER_RECT
.Width
do
6453 if (not StayOnStep(x
*sx
, 0)) and
6454 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
6455 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
6457 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
6459 if CollideLevel(x
*sx
, PLAYER_RECT
.Height
*y
) then Exit
;
6464 end else Result
:= False;
6467 function OverDeepHole(): Boolean;
6474 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
6476 if CollideLevel(0, PLAYER_RECT
.Height
*y
) then Exit
;
6483 function OnGround(): Boolean;
6485 Result
:= StayOnStep(0, 0) or CollideLevel(0, 1);
6488 function OnLadder(): Boolean;
6490 Result
:= FullInStep(0, 0);
6493 function BelowLadder(): Boolean;
6495 Result
:= (FullInStep(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) and
6496 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
6497 (FullInStep(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) and
6498 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
6501 function BelowLiftUp(): Boolean;
6503 Result
:= ((FullInLift(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) = -1) and
6504 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
6505 ((FullInLift(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) = -1) and
6506 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
6509 function OnTopLift(): Boolean;
6511 Result
:= (FullInLift(0, 0) = -1) and (FullInLift(0, -32) = 0);
6514 function CanJumpOver(): Boolean;
6518 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
6522 if not CollideLevel(sx
, 0) then Exit
;
6524 for y
:= 1 to BOT_MAXJUMP
do
6525 if CollideLevel(0, -y
) then Exit
else
6526 if not CollideLevel(sx
, -y
) then
6533 function CanJumpUp(Dist
: ShortInt): Boolean;
6540 if CollideLevel(Dist
, 0) then Exit
;
6543 for y
:= 0 to BOT_MAXJUMP
do
6544 if CollideLevel(Dist
, -y
) then
6553 for yy
:= y
+1 to BOT_MAXJUMP
do
6554 if not CollideLevel(Dist
, -yy
) then
6563 for y
:= 0 to BOT_MAXJUMP
do
6564 if CollideLevel(0, -y
) then
6572 if y
< yy
then Exit
;
6577 function IsSafeTrigger(): Boolean;
6582 if gTriggers
= nil then
6584 for a
:= 0 to High(gTriggers
) do
6585 if Collide(gTriggers
[a
].X
,
6588 gTriggers
[a
].Height
) and
6589 (gTriggers
[a
].TriggerType
in [TRIGGER_EXIT
, TRIGGER_CLOSEDOOR
,
6590 TRIGGER_CLOSETRAP
, TRIGGER_TRAP
,
6591 TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
,
6592 TRIGGER_ONOFF
, TRIGGER_SPAWNMONSTER
,
6593 TRIGGER_DAMAGE
, TRIGGER_SHOT
]) then
6598 // Возможно, нажимаем кнопку:
6599 if Rnd(16) and IsSafeTrigger() then
6602 // Если под лифтом или ступеньками, то, возможно, прыгаем:
6603 if OnLadder() or ((BelowLadder() or BelowLiftUp()) and Rnd(8)) then
6605 ReleaseKey(KEY_LEFT
);
6606 ReleaseKey(KEY_RIGHT
);
6610 // Идем влево, если надо было:
6611 if GetAIFlag('GOLEFT') <> '' then
6613 RemoveAIFlag('GOLEFT');
6614 if CanRunLeft() then
6618 // Идем вправо, если надо было:
6619 if GetAIFlag('GORIGHT') <> '' then
6621 RemoveAIFlag('GORIGHT');
6622 if CanRunRight() then
6626 // Если вылетели за карту, то пробуем вернуться:
6627 if FObj
.X
< -32 then
6630 if FObj
.X
+32 > gMapInfo
.Width
then
6633 // Прыгаем, если надо было:
6634 if GetAIFlag('NEEDJUMP') <> '' then
6637 RemoveAIFlag('NEEDJUMP');
6640 // Смотрим вверх, если надо было:
6641 if GetAIFlag('NEEDSEEUP') <> '' then
6644 ReleaseKey(KEY_DOWN
);
6645 PressKey(KEY_UP
, 20);
6646 RemoveAIFlag('NEEDSEEUP');
6649 // Смотрим вниз, если надо было:
6650 if GetAIFlag('NEEDSEEDOWN') <> '' then
6653 ReleaseKey(KEY_DOWN
);
6654 PressKey(KEY_DOWN
, 20);
6655 RemoveAIFlag('NEEDSEEDOWN');
6658 // Если нужно было в дыру и мы не на земле, то покорно летим:
6659 if GetAIFlag('GOINHOLE') <> '' then
6660 if not OnGround() then
6662 ReleaseKey(KEY_LEFT
);
6663 ReleaseKey(KEY_RIGHT
);
6664 RemoveAIFlag('GOINHOLE');
6665 SetAIFlag('FALLINHOLE', '1');
6668 // Если падали и достигли земли, то хватит падать:
6669 if GetAIFlag('FALLINHOLE') <> '' then
6671 RemoveAIFlag('FALLINHOLE');
6673 // Если летели прямо и сейчас не на лестнице или на вершине лифта, то отходим в сторону:
6674 if not (KeyPressed(KEY_LEFT
) or KeyPressed(KEY_RIGHT
)) then
6675 if GetAIFlag('FALLINHOLE') = '' then
6676 if (not OnLadder()) or (FObj
.Vel
.Y
>= 0) or (OnTopLift()) then
6682 // Если на земле и можно подпрыгнуть, то, возможно, прыгаем:
6684 CanJumpUp(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*32) and
6688 // Если на земле и возле дыры (глубина > 2 ростов игрока):
6689 if OnGround() and NearHole() then
6690 if NearDeepHole() then // Если это бездна
6692 0..3: Turn(); // Бежим обратно
6693 4: Jump(); // Прыгаем
6694 5: begin // Прыгаем обратно
6699 else // Это не бездна и мы еще не летим туда
6700 if GetAIFlag('GOINHOLE') = '' then
6702 0: Turn(); // Не нужно туда
6703 1: Jump(); // Вдруг повезет - прыгаем
6704 else // Если яма с границей, то при случае можно туда прыгнуть
6705 if BorderHole() then
6706 SetAIFlag('GOINHOLE', '1');
6709 // Если на земле, но некуда идти:
6710 if (not CanRun()) and OnGround() then
6712 // Если мы на лестнице или можно перепрыгнуть, то прыгаем:
6713 if CanJumpOver() or OnLadder() then
6715 else // иначе попытаемся в другую сторону
6716 if Random(2) = 0 then
6718 if IsSafeTrigger() then
6724 // Осталось мало воздуха:
6725 if FAir
< 36 * 2 then
6728 // Выбираемся из кислоты, если нет костюма, обожглись, или мало здоровья:
6729 if (FMegaRulez
[MR_SUIT
] < gTime
) and ((FLastHit
= HIT_ACID
) or (Healthy() <= 1)) then
6730 if BodyInAcid(0, 0) then
6734 function TBot
.FullInStep(XInc
, YInc
: Integer): Boolean;
6736 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
6737 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_STEP
, False);
6740 {function TBot.NeedItem(Item: Byte): Byte;
6745 procedure TBot
.SelectWeapon(Dist
: Integer);
6749 function HaveAmmo(weapon
: Byte): Boolean;
6752 WEAPON_PISTOL
: Result
:= FAmmo
[A_BULLETS
] >= 1;
6753 WEAPON_SHOTGUN1
: Result
:= FAmmo
[A_SHELLS
] >= 1;
6754 WEAPON_SHOTGUN2
: Result
:= FAmmo
[A_SHELLS
] >= 2;
6755 WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
] >= 10;
6756 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
] >= 1;
6757 WEAPON_PLASMA
: Result
:= FAmmo
[A_CELLS
] >= 10;
6758 WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
] >= 40;
6759 WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
] >= 1;
6760 WEAPON_FLAMETHROWER
: Result
:= FAmmo
[A_FUEL
] >= 1;
6761 else Result
:= True;
6766 if Dist
= -1 then Dist
:= BOT_LONGDIST
;
6768 if Dist
> BOT_LONGDIST
then
6769 begin // Дальний бой
6771 if FWeapon
[FDifficult
.WeaponPrior
[a
]] and HaveAmmo(FDifficult
.WeaponPrior
[a
]) then
6773 FSelectedWeapon
:= FDifficult
.WeaponPrior
[a
];
6777 else //if Dist > BOT_UNSAFEDIST then
6778 begin // Ближний бой
6780 if FWeapon
[FDifficult
.CloseWeaponPrior
[a
]] and HaveAmmo(FDifficult
.CloseWeaponPrior
[a
]) then
6782 FSelectedWeapon
:= FDifficult
.CloseWeaponPrior
[a
];
6789 if FWeapon[FDifficult.SafeWeaponPrior[a]] and HaveAmmo(FDifficult.SafeWeaponPrior[a]) then
6791 FSelectedWeapon := FDifficult.SafeWeaponPrior[a];
6797 function TBot
.PickItem(ItemType
: Byte; force
: Boolean; var remove
: Boolean): Boolean;
6799 Result
:= inherited PickItem(ItemType
, force
, remove
);
6801 if Result
then SetAIFlag('SELECTWEAPON', '1');
6804 function TBot
.Heal(value
: Word; Soft
: Boolean): Boolean;
6806 Result
:= inherited Heal(value
, Soft
);
6809 function TBot
.Healthy(): Byte;
6811 if FMegaRulez
[MR_INVUL
] >= gTime
then Result
:= 3
6812 else if (FHealth
> 80) or ((FHealth
> 50) and (FArmor
> 20)) then Result
:= 3
6813 else if (FHealth
> 50) then Result
:= 2
6814 else if (FHealth
> 20) then Result
:= 1
6818 function TBot
.TargetOnScreen(TX
, TY
: Integer): Boolean;
6820 Result
:= (Abs(FObj
.X
-TX
) <= Trunc(gPlayerScreenSize
.X
*0.6)) and
6821 (Abs(FObj
.Y
-TY
) <= Trunc(gPlayerScreenSize
.Y
*0.6));
6824 procedure TBot
.OnDamage(Angle
: SmallInt);
6832 if (Angle
= 0) or (Angle
= 180) then
6835 if (g_GetUIDType(FLastSpawnerUID
) = UID_PLAYER
) and
6836 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
) then
6838 pla
:= g_Player_Get(FLastSpawnerUID
);
6839 ok
:= not TargetOnScreen(pla
.FObj
.X
+ PLAYER_RECT
.X
,
6840 pla
.FObj
.Y
+ PLAYER_RECT
.Y
);
6843 if (g_GetUIDType(FLastSpawnerUID
) = UID_MONSTER
) and
6844 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
) then
6846 mon
:= g_Monsters_ByUID(FLastSpawnerUID
);
6847 ok
:= not TargetOnScreen(mon
.Obj
.X
+ mon
.Obj
.Rect
.X
,
6848 mon
.Obj
.Y
+ mon
.Obj
.Rect
.Y
);
6853 SetAIFlag('ATTACKLEFT', '1')
6855 SetAIFlag('ATTACKRIGHT', '1');
6859 function TBot
.RunDirection(): TDirection
;
6861 if Abs(Vel
.X
) >= 1 then
6863 if Vel
.X
> 0 then Result
:= TDirection
.D_RIGHT
else Result
:= TDirection
.D_LEFT
;
6865 Result
:= FDirection
;
6868 function TBot
.GetRnd(a
: Byte): Boolean;
6870 if a
= 0 then Result
:= False
6871 else if a
= 255 then Result
:= True
6872 else Result
:= Random(256) > 255-a
;
6875 function TBot
.GetInterval(a
: Byte; radius
: SmallInt): SmallInt;
6877 Result
:= Round((255-a
)/255*radius
*(Random(2)-1));
6881 procedure TDifficult
.save (st
: TStream
);
6883 utils
.writeInt(st
, Byte(DiagFire
));
6884 utils
.writeInt(st
, Byte(InvisFire
));
6885 utils
.writeInt(st
, Byte(DiagPrecision
));
6886 utils
.writeInt(st
, Byte(FlyPrecision
));
6887 utils
.writeInt(st
, Byte(Cover
));
6888 utils
.writeInt(st
, Byte(CloseJump
));
6889 st
.WriteBuffer(WeaponPrior
[Low(WeaponPrior
)], sizeof(WeaponPrior
));
6890 st
.WriteBuffer(CloseWeaponPrior
[Low(CloseWeaponPrior
)], sizeof(CloseWeaponPrior
));
6893 procedure TDifficult
.load (st
: TStream
);
6895 DiagFire
:= utils
.readByte(st
);
6896 InvisFire
:= utils
.readByte(st
);
6897 DiagPrecision
:= utils
.readByte(st
);
6898 FlyPrecision
:= utils
.readByte(st
);
6899 Cover
:= utils
.readByte(st
);
6900 CloseJump
:= utils
.readByte(st
);
6901 st
.ReadBuffer(WeaponPrior
[Low(WeaponPrior
)], sizeof(WeaponPrior
));
6902 st
.ReadBuffer(CloseWeaponPrior
[Low(CloseWeaponPrior
)], sizeof(CloseWeaponPrior
));
6906 procedure TBot
.SaveState (st
: TStream
);
6911 inherited SaveState(st
);
6912 utils
.writeSign(st
, 'BOT0');
6914 utils
.writeInt(st
, Byte(FSelectedWeapon
));
6916 utils
.writeInt(st
, Word(FTargetUID
));
6917 // Время потери цели
6918 utils
.writeInt(st
, LongWord(FLastVisible
));
6919 // Количество флагов ИИ
6920 dw
:= Length(FAIFlags
);
6921 utils
.writeInt(st
, LongInt(dw
));
6923 for i
:= 0 to dw
-1 do
6925 utils
.writeStr(st
, FAIFlags
[i
].Name
, 20);
6926 utils
.writeStr(st
, FAIFlags
[i
].Value
, 20);
6928 // Настройки сложности
6929 FDifficult
.save(st
);
6933 procedure TBot
.LoadState (st
: TStream
);
6938 inherited LoadState(st
);
6939 if not utils
.checkSign(st
, 'BOT0') then raise XStreamError
.Create('invalid bot signature');
6941 FSelectedWeapon
:= utils
.readByte(st
);
6943 FTargetUID
:= utils
.readWord(st
);
6944 // Время потери цели
6945 FLastVisible
:= utils
.readLongWord(st
);
6946 // Количество флагов ИИ
6947 dw
:= utils
.readLongInt(st
);
6948 if (dw
< 0) or (dw
> 16384) then raise XStreamError
.Create('invalid number of bot AI flags');
6949 SetLength(FAIFlags
, dw
);
6951 for i
:= 0 to dw
-1 do
6953 FAIFlags
[i
].Name
:= utils
.readStr(st
, 20);
6954 FAIFlags
[i
].Value
:= utils
.readStr(st
, 20);
6956 // Настройки сложности
6957 FDifficult
.load(st
);
6962 conRegVar('cheat_berserk_autoswitch', @gBerserkAutoswitch
, 'autoswitch to fist when berserk pack taken', '', true, true);
6963 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');
6964 conRegVar('player_indicator_style', @gPlayerIndicatorStyle
, 'Visual appearance of indicator', 'Visual appearance of indicator');