1 (* Copyright (C) Doom 2D: Forever Developers
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, version 3 of the License ONLY.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 {$INCLUDE ../shared/a_modes.inc}
23 {$IFDEF USE_MEMPOOL}mempool
,{$ENDIF}
24 e_graphics
, g_playermodel
, g_basic
, g_textures
,
25 g_weapons
, g_phys
, g_sound
, g_saveload
, MAPDEF
,
61 AmmoLimits
: Array [0..1] of Array [A_BULLETS
..A_HIGH
] of Word =
62 ((200, 50, 50, 300, 100),
63 (400, 100, 100, 600, 200));
84 ANGLE_NONE
= Low(SmallInt);
86 CORPSE_STATE_REMOVEME
= 0;
87 CORPSE_STATE_NORMAL
= 1;
88 CORPSE_STATE_MESS
= 2;
90 PLAYER_RECT
: TRectWH
= (X
:15; Y
:12; Width
:34; Height
:52);
91 PLAYER_RECT_CX
= 15+(34 div 2);
92 PLAYER_RECT_CY
= 12+(52 div 2);
93 PLAYER_CORPSERECT
: TRectWH
= (X
:15; Y
:48; Width
:34; Height
:16);
96 PLAYER_HP_LIMIT
= 200;
98 PLAYER_AP_LIMIT
= 200;
102 PLAYER_BURN_TIME
= 110;
104 PLAYER1_DEF_COLOR
: TRGB
= (R
:64; G
:175; B
:48);
105 PLAYER2_DEF_COLOR
: TRGB
= (R
:96; G
:96; B
:96);
123 TPlayerStatArray
= Array of TPlayerStat
;
125 TPlayerSavedState
= record
133 Ammo
: Array [A_BULLETS
..A_HIGH
] of Word;
134 MaxAmmo
: Array [A_BULLETS
..A_HIGH
] of Word;
135 Weapon
: Array [WP_FIRST
..WP_LAST
] of Boolean;
136 Rulez
: Set of R_ITEM_BACKPACK
..R_BERSERK
;
145 TPlayer
= class{$IFDEF USE_MEMPOOL}(TPoolObject
){$ENDIF}
153 FDirection
: TDirection
;
161 FMonsterKills
: Integer;
167 FCanJetpack
: Boolean;
173 FNextWeapDelay
: Byte; // frames
174 FBFGFireCounter
: SmallInt;
175 FLastSpawnerUID
: Word;
179 FSpectatePlayer
: Integer;
180 FFirePainTime
: Integer;
183 FSavedStateNum
: Integer;
185 FModel
: TPlayerModel
;
186 FPunchAnim
: TAnimation
;
189 FActionForce
: Boolean;
190 FActionChanged
: Boolean;
192 FFireAngle
: SmallInt;
196 FShellTimer
: Integer;
198 FSawSound
: TPlayableSound
;
199 FSawSoundIdle
: TPlayableSound
;
200 FSawSoundHit
: TPlayableSound
;
201 FSawSoundSelect
: TPlayableSound
;
202 FFlameSoundOn
: TPlayableSound
;
203 FFlameSoundOff
: TPlayableSound
;
204 FFlameSoundWork
: TPlayableSound
;
205 FJetSoundOn
: TPlayableSound
;
206 FJetSoundOff
: TPlayableSound
;
207 FJetSoundFly
: TPlayableSound
;
211 FJustTeleported
: Boolean;
213 mEDamageType
: Integer;
216 function CollideLevel(XInc
, YInc
: Integer): Boolean;
217 function StayOnStep(XInc
, YInc
: Integer): Boolean;
218 function HeadInLiquid(XInc
, YInc
: Integer): Boolean;
219 function BodyInLiquid(XInc
, YInc
: Integer): Boolean;
220 function BodyInAcid(XInc
, YInc
: Integer): Boolean;
221 function FullInLift(XInc
, YInc
: Integer): Integer;
222 {procedure CollideItem();}
223 procedure FlySmoke(Times
: DWORD
= 1);
224 procedure OnFireFlame(Times
: DWORD
= 1);
225 function GetAmmoByWeapon(Weapon
: Byte): Word;
226 procedure SetAction(Action
: Byte; Force
: Boolean = False);
227 procedure OnDamage(Angle
: SmallInt); virtual;
228 function firediry(): Integer;
231 procedure Run(Direction
: TDirection
);
232 procedure NextWeapon();
233 procedure PrevWeapon();
240 function getNextWeaponIndex (): Byte; // return 255 for "no switch"
241 procedure resetWeaponQueue ();
242 function hasAmmoForWeapon (weapon
: Byte): Boolean;
244 procedure doDamage (v
: Integer);
246 function refreshCorpse(): Boolean;
249 FDamageBuffer
: Integer;
251 FAmmo
: Array [A_BULLETS
..A_HIGH
] of Word;
252 FMaxAmmo
: Array [A_BULLETS
..A_HIGH
] of Word;
253 FWeapon
: Array [WP_FIRST
..WP_LAST
] of Boolean;
254 FRulez
: Set of R_ITEM_BACKPACK
..R_BERSERK
;
256 FMegaRulez
: Array [MR_SUIT
..MR_MAX
] of DWORD
;
257 FReloading
: Array [WP_FIRST
..WP_LAST
] of Word;
258 FTime
: Array [T_RESPAWN
..T_FLAGCAP
] of DWORD
;
259 FKeys
: Array [KEY_LEFT
..KEY_CHAT
] of TKeyState
;
261 FPreferredTeam
: Byte;
264 FWantsInGame
: Boolean;
269 FActualModelName
: string;
276 FSpawnInvul
: Integer;
278 FWaitForFirstSpawn
: Boolean; // set to `true` in server, used to spawn a player on first full state request
281 // debug: viewport offset
282 viewPortX
, viewPortY
, viewPortW
, viewPortH
: Integer;
284 function isValidViewPort (): Boolean; inline;
286 constructor Create(); virtual;
287 destructor Destroy(); override;
288 procedure Respawn(Silent
: Boolean; Force
: Boolean = False); virtual;
289 function GetRespawnPoint(): Byte;
290 procedure PressKey(Key
: Byte; Time
: Word = 1);
291 procedure ReleaseKeys();
292 procedure SetModel(ModelName
: String);
293 procedure SetColor(Color
: TRGB
);
294 function GetColor(): TRGB
;
295 procedure SetWeapon(W
: Byte);
296 function IsKeyPressed(K
: Byte): Boolean;
297 function GetKeys(): Byte;
298 function PickItem(ItemType
: Byte; arespawn
: Boolean; var remove
: Boolean): Boolean; virtual;
299 function Collide(X
, Y
: Integer; Width
, Height
: Word): Boolean; overload
;
300 function Collide(Panel
: TPanel
): Boolean; overload
;
301 function Collide(X
, Y
: Integer): Boolean; overload
;
302 procedure SetDirection(Direction
: TDirection
);
303 procedure GetSecret();
304 function TeleportTo(X
, Y
: Integer; silent
: Boolean; dir
: Byte): Boolean;
306 procedure Push(vx
, vy
: Integer);
307 procedure ChangeModel(ModelName
: String);
308 procedure SwitchTeam
;
309 procedure ChangeTeam(Team
: Byte);
311 function GetFlag(Flag
: Byte): Boolean;
312 procedure SetFlag(Flag
: Byte);
313 function DropFlag(Silent
: Boolean = True): Boolean;
314 procedure AllRulez(Health
: Boolean);
315 procedure RestoreHealthArmor();
316 procedure FragCombo();
317 procedure GiveItem(ItemType
: Byte);
318 procedure Damage(value
: Word; SpawnerUID
: Word; vx
, vy
: Integer; t
: Byte); virtual;
319 function Heal(value
: Word; Soft
: Boolean): Boolean; virtual;
320 procedure MakeBloodVector(Count
: Word; VelX
, VelY
: Integer);
321 procedure MakeBloodSimple(Count
: Word);
322 procedure Kill(KillType
: Byte; SpawnerUID
: Word; t
: Byte);
323 procedure Reset(Force
: Boolean);
324 procedure Spectate(NoMove
: Boolean = False);
325 procedure SwitchNoClip
;
326 procedure SoftReset();
327 procedure Draw(); virtual;
328 procedure DrawPain();
329 procedure DrawPickup();
330 procedure DrawRulez();
332 procedure DrawIndicator(Color
: TRGB
);
333 procedure DrawBubble();
335 procedure PreUpdate();
336 procedure Update(); virtual;
337 procedure RememberState();
338 procedure RecallState();
339 procedure SaveState (st
: TStream
); virtual;
340 procedure LoadState (st
: TStream
); virtual;
341 procedure PauseSounds(Enable
: Boolean);
342 procedure NetFire(Wpn
: Byte; X
, Y
, AX
, AY
: Integer; WID
: Integer = -1);
343 procedure DoLerp(Level
: Integer = 2);
344 procedure SetLerp(XTo
, YTo
: Integer);
345 procedure ProcessWeaponAction(Action
: Byte);
346 procedure QueueWeaponSwitch(Weapon
: Byte);
347 procedure RealizeCurrentWeapon();
351 procedure JetpackOff
;
352 procedure CatchFire(Attacker
: Word; Timeout
: Integer = PLAYER_BURN_TIME
);
354 //WARNING! this does nothing for now, but still call it!
355 procedure positionChanged (); //WARNING! call this after entity position was changed, or coldet will not work right!
357 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
358 procedure moveBy (dx
, dy
: Integer); inline;
360 function getCameraObj(): TObj
;
363 property Vel
: TPoint2i read FObj
.Vel
;
364 property Obj
: TObj read FObj
;
366 property Name
: String read FName write FName
;
367 property Model
: TPlayerModel read FModel
;
368 property Health
: Integer read FHealth write FHealth
;
369 property Lives
: Byte read FLives write FLives
;
370 property Armor
: Integer read FArmor write FArmor
;
371 property Air
: Integer read FAir write FAir
;
372 property JetFuel
: Integer read FJetFuel write FJetFuel
;
373 property Frags
: Integer read FFrags write FFrags
;
374 property Death
: Integer read FDeath write FDeath
;
375 property Kills
: Integer read FKills write FKills
;
376 property CurrWeap
: Byte read FCurrWeap write FCurrWeap
;
377 property MonsterKills
: Integer read FMonsterKills write FMonsterKills
;
378 property Secrets
: Integer read FSecrets
;
379 property GodMode
: Boolean read FGodMode write FGodMode
;
380 property NoTarget
: Boolean read FNoTarget write FNoTarget
;
381 property NoReload
: Boolean read FNoReload write FNoReload
;
382 property alive
: Boolean read FAlive write FAlive
;
383 property Flag
: Byte read FFlag
;
384 property Team
: Byte read FTeam write FTeam
;
385 property Direction
: TDirection read FDirection
;
386 property GameX
: Integer read FObj
.X write FObj
.X
;
387 property GameY
: Integer read FObj
.Y write FObj
.Y
;
388 property GameVelX
: Integer read FObj
.Vel
.X write FObj
.Vel
.X
;
389 property GameVelY
: Integer read FObj
.Vel
.Y write FObj
.Vel
.Y
;
390 property GameAccelX
: Integer read FObj
.Accel
.X write FObj
.Accel
.X
;
391 property GameAccelY
: Integer read FObj
.Accel
.Y write FObj
.Accel
.Y
;
392 property IncCam
: Integer read FIncCam write FIncCam
;
393 property IncCamOld
: Integer read FIncCamOld write FIncCamOld
;
394 property SlopeOld
: Integer read FSlopeOld write FSlopeOld
;
395 property UID
: Word read FUID write FUID
;
396 property JustTeleported
: Boolean read FJustTeleported write FJustTeleported
;
397 property NetTime
: LongWord read FNetTime write FNetTime
;
400 property eName
: String read FName write FName
;
401 property eHealth
: Integer read FHealth write FHealth
;
402 property eLives
: Byte read FLives write FLives
;
403 property eArmor
: Integer read FArmor write FArmor
;
404 property eAir
: Integer read FAir write FAir
;
405 property eJetFuel
: Integer read FJetFuel write FJetFuel
;
406 property eFrags
: Integer read FFrags write FFrags
;
407 property eDeath
: Integer read FDeath write FDeath
;
408 property eKills
: Integer read FKills write FKills
;
409 property eCurrWeap
: Byte read FCurrWeap write FCurrWeap
;
410 property eMonsterKills
: Integer read FMonsterKills write FMonsterKills
;
411 property eSecrets
: Integer read FSecrets write FSecrets
;
412 property eGodMode
: Boolean read FGodMode write FGodMode
;
413 property eNoTarget
: Boolean read FNoTarget write FNoTarget
;
414 property eNoReload
: Boolean read FNoReload write FNoReload
;
415 property eAlive
: Boolean read FAlive write FAlive
;
416 property eFlag
: Byte read FFlag
;
417 property eTeam
: Byte read FTeam write FTeam
;
418 property eDirection
: TDirection read FDirection
;
419 property eGameX
: Integer read FObj
.X write FObj
.X
;
420 property eGameY
: Integer read FObj
.Y write FObj
.Y
;
421 property eGameVelX
: Integer read FObj
.Vel
.X write FObj
.Vel
.X
;
422 property eGameVelY
: Integer read FObj
.Vel
.Y write FObj
.Vel
.Y
;
423 property eGameAccelX
: Integer read FObj
.Accel
.X write FObj
.Accel
.X
;
424 property eGameAccelY
: Integer read FObj
.Accel
.Y write FObj
.Accel
.Y
;
425 property eIncCam
: Integer read FIncCam write FIncCam
;
426 property eUID
: Word read FUID
;
427 property eJustTeleported
: Boolean read FJustTeleported
;
428 property eNetTime
: LongWord read FNetTime
;
430 // set this before assigning something to `eDamage`
431 property eDamageType
: Integer read mEDamageType write mEDamageType
;
432 property eDamage
: Integer write doDamage
;
443 WeaponPrior
: packed array [WP_FIRST
..WP_LAST
] of Byte;
444 CloseWeaponPrior
: packed array [WP_FIRST
..WP_LAST
] of Byte;
445 //SafeWeaponPrior: Array [WP_FIRST..WP_LAST] of Byte;
448 procedure save (st
: TStream
);
449 procedure load (st
: TStream
);
457 TBot
= class(TPlayer
)
459 FSelectedWeapon
: Byte;
462 FAIFlags
: Array of TAIFlag
;
463 FDifficult
: TDifficult
;
465 function GetRnd(a
: Byte): Boolean;
466 function GetInterval(a
: Byte; radius
: SmallInt): SmallInt;
467 function RunDirection(): TDirection
;
468 function FullInStep(XInc
, YInc
: Integer): Boolean;
469 //function NeedItem(Item: Byte): Byte;
470 procedure SelectWeapon(Dist
: Integer);
471 procedure SetAIFlag(aName
, fValue
: String20
);
472 function GetAIFlag(aName
: String20
): String20
;
473 procedure RemoveAIFlag(aName
: String20
);
474 function Healthy(): Byte;
475 procedure UpdateMove();
476 procedure UpdateCombat();
477 function KeyPressed(Key
: Word): Boolean;
478 procedure ReleaseKey(Key
: Byte);
479 function TargetOnScreen(TX
, TY
: Integer): Boolean;
480 procedure OnDamage(Angle
: SmallInt); override;
483 procedure Respawn(Silent
: Boolean; Force
: Boolean = False); override;
484 constructor Create(); override;
485 destructor Destroy(); override;
486 procedure Draw(); override;
487 function PickItem(ItemType
: Byte; force
: Boolean; var remove
: Boolean): Boolean; override;
488 function Heal(value
: Word; Soft
: Boolean): Boolean; override;
489 procedure Update(); override;
490 procedure SaveState (st
: TStream
); override;
491 procedure LoadState (st
: TStream
); override;
503 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
504 procedure moveBy (dx
, dy
: Integer); inline;
506 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
520 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
521 procedure moveBy (dx
, dy
: Integer); inline;
523 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
526 TCorpse
= class{$IFDEF USE_MEMPOOL}(TPoolObject
){$ENDIF}
535 FAnimation
: TAnimation
;
536 FAnimationMask
: TAnimation
;
539 constructor Create(X
, Y
: Integer; ModelName
: String; aMess
: Boolean);
540 destructor Destroy(); override;
541 procedure Damage(Value
: Word; SpawnerUID
: Word; vx
, vy
: Integer);
544 procedure SaveState (st
: TStream
);
545 procedure LoadState (st
: TStream
);
547 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
548 procedure moveBy (dx
, dy
: Integer); inline;
550 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
552 function ObjPtr (): PObj
; inline;
554 property Obj
: TObj read FObj
; // copies object
555 property State
: Byte read FState
;
556 property Mess
: Boolean read FMess
;
559 TTeamStat
= Array [TEAM_RED
..TEAM_BLUE
] of
565 gPlayers
: Array of TPlayer
;
566 gCorpses
: Array of TCorpse
;
567 gGibs
: Array of TGib
;
568 gShells
: Array of TShell
;
569 gTeamStat
: TTeamStat
;
570 gFly
: Boolean = False;
571 gAimLine
: Boolean = False;
572 gChatBubble
: Integer = 0;
573 gPlayerIndicator
: Integer = 1;
574 gPlayerIndicatorStyle
: Integer = 0;
576 gSpectLatchPID1
: Word = 0;
577 gSpectLatchPID2
: Word = 0;
578 MAX_RUNVEL
: Integer = 8;
579 VEL_JUMP
: Integer = 10;
580 SHELL_TIMEOUT
: Cardinal = 60000;
582 function Lerp(X
, Y
, Factor
: Integer): Integer;
584 procedure g_Gibs_SetMax(Count
: Word);
585 function g_Gibs_GetMax(): Word;
586 procedure g_Corpses_SetMax(Count
: Word);
587 function g_Corpses_GetMax(): Word;
588 procedure g_Shells_SetMax(Count
: Word);
589 function g_Shells_GetMax(): Word;
591 procedure g_Player_Init();
592 procedure g_Player_Free();
593 function g_Player_Create(ModelName
: String; Color
: TRGB
; Team
: Byte; Bot
: Boolean): Word;
594 function g_Player_CreateFromState (st
: TStream
): Word;
595 procedure g_Player_Remove(UID
: Word);
596 procedure g_Player_ResetTeams();
597 procedure g_Player_PreUpdate();
598 procedure g_Player_UpdateAll();
599 procedure g_Player_DrawAll();
600 procedure g_Player_DrawDebug(p
: TPlayer
);
601 procedure g_Player_DrawHealth();
602 procedure g_Player_RememberAll();
603 procedure g_Player_ResetAll(Force
, Silent
: Boolean);
604 function g_Player_Get(UID
: Word): TPlayer
;
605 function g_Player_GetCount(): Byte;
606 function g_Player_GetStats(): TPlayerStatArray
;
607 function g_Player_ValidName(Name
: String): Boolean;
608 function g_Player_CreateCorpse(Player
: TPlayer
): Integer;
609 procedure g_Player_CreateGibs(fX
, fY
: Integer; ModelName
: String; fColor
: TRGB
);
610 procedure g_Player_CreateShell(fX
, fY
, dX
, dY
: Integer; T
: Byte);
611 procedure g_Player_UpdatePhysicalObjects();
612 procedure g_Player_DrawCorpses();
613 procedure g_Player_DrawShells();
614 procedure g_Player_RemoveAllCorpses();
615 procedure g_Player_Corpses_SaveState (st
: TStream
);
616 procedure g_Player_Corpses_LoadState (st
: TStream
);
617 procedure g_Player_ResetReady();
618 procedure g_Bot_Add(Team
, Difficult
: Byte; Handicap
: Integer = 100);
619 procedure g_Bot_AddList(Team
: Byte; lname
: ShortString; num
: Integer = -1; Handicap
: Integer = 100);
620 procedure g_Bot_MixNames();
621 procedure g_Bot_RemoveAll();
626 {$INCLUDE ../nogl/noGLuses.inc}
627 {$IFDEF ENABLE_HOLMES}
630 e_log
, g_map
, g_items
, g_console
, g_gfx
, Math
,
631 g_options
, g_triggers
, g_menu
, g_game
, g_grid
, e_res
,
632 wadreader
, g_main
, g_monsters
, CONFIG
, g_language
,
633 g_net
, g_netmsg
, g_window
,
636 const PLR_SAVE_VERSION
= 0;
646 diag_precision
: Byte;
650 w_prior1
: Array [WP_FIRST
..WP_LAST
] of Byte;
651 w_prior2
: Array [WP_FIRST
..WP_LAST
] of Byte;
652 w_prior3
: Array [WP_FIRST
..WP_LAST
] of Byte;
656 TIME_RESPAWN1
= 1500;
657 TIME_RESPAWN2
= 2000;
658 TIME_RESPAWN3
= 3000;
661 JET_MAX
= 540; // ~30 sec
662 PLAYER_SUIT_TIME
= 30000;
663 PLAYER_INVUL_TIME
= 30000;
664 PLAYER_INVIS_TIME
= 35000;
665 FRAG_COMBO_TIME
= 3000;
669 ANGLE_RIGHTDOWN
= -35;
671 ANGLE_LEFTDOWN
= -145;
672 PLAYER_HEADRECT
: TRectWH
= (X
:24; Y
:12; Width
:20; Height
:12);
673 WEAPONPOINT
: Array [TDirection
] of TDFPoint
= ((X
:16; Y
:32), (X
:47; Y
:32));
676 BOT_UNSAFEDIST
= 128;
677 TEAMCOLOR
: Array [TEAM_RED
..TEAM_BLUE
] of TRGB
= ((R
:255; G
:0; B
:0),
679 DIFFICULT_EASY
: TDifficult
= (DiagFire
: 32; InvisFire
: 32; DiagPrecision
: 32;
680 FlyPrecision
: 32; Cover
: 32; CloseJump
: 32;
681 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
682 DIFFICULT_MEDIUM
: TDifficult
= (DiagFire
: 127; InvisFire
: 127; DiagPrecision
: 127;
683 FlyPrecision
: 127; Cover
: 127; CloseJump
: 127;
684 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
685 DIFFICULT_HARD
: TDifficult
= (DiagFire
: 255; InvisFire
: 255; DiagPrecision
: 255;
686 FlyPrecision
: 255; Cover
: 255; CloseJump
: 255;
687 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
688 WEAPON_PRIOR1
: Array [WP_FIRST
..WP_LAST
] of Byte =
689 (WEAPON_FLAMETHROWER
, WEAPON_SUPERPULEMET
,
690 WEAPON_SHOTGUN2
, WEAPON_SHOTGUN1
,
691 WEAPON_CHAINGUN
, WEAPON_PLASMA
, WEAPON_ROCKETLAUNCHER
,
692 WEAPON_BFG
, WEAPON_PISTOL
, WEAPON_SAW
, WEAPON_KASTET
);
693 WEAPON_PRIOR2
: Array [WP_FIRST
..WP_LAST
] of Byte =
694 (WEAPON_FLAMETHROWER
, WEAPON_SUPERPULEMET
,
695 WEAPON_BFG
, WEAPON_ROCKETLAUNCHER
,
696 WEAPON_SHOTGUN2
, WEAPON_PLASMA
, WEAPON_SHOTGUN1
,
697 WEAPON_CHAINGUN
, WEAPON_PISTOL
, WEAPON_SAW
, WEAPON_KASTET
);
698 //WEAPON_PRIOR3: Array [WP_FIRST..WP_LAST] of Byte =
699 // (WEAPON_FLAMETHROWER, WEAPON_SUPERPULEMET,
700 // WEAPON_BFG, WEAPON_PLASMA, WEAPON_SHOTGUN2,
701 // WEAPON_CHAINGUN, WEAPON_SHOTGUN1, WEAPON_SAW,
702 // WEAPON_ROCKETLAUNCHER, WEAPON_PISTOL, WEAPON_KASTET);
703 WEAPON_RELOAD
: Array [WP_FIRST
..WP_LAST
] of Byte =
704 (5, 2, 6, 18, 36, 2, 12, 2, 14, 2, 2);
706 PLAYER_SIGNATURE
= $52594C50; // 'PLYR'
707 CORPSE_SIGNATURE
= $50524F43; // 'CORP'
709 BOTNAMES_FILENAME
= 'botnames.txt';
710 BOTLIST_FILENAME
= 'botlist.txt';
714 MaxCorpses
: Word = 20;
715 MaxShells
: Word = 300;
716 CurrentGib
: Integer = 0;
717 CurrentShell
: Integer = 0;
718 BotNames
: Array of String;
719 BotList
: Array of TBotProfile
;
720 SavedStates
: Array of TPlayerSavedState
;
723 function Lerp(X
, Y
, Factor
: Integer): Integer;
725 Result
:= X
+ ((Y
- X
) div Factor
);
728 function SameTeam(UID1
, UID2
: Word): Boolean;
732 if (UID1
> UID_MAX_PLAYER
) or (UID1
<= UID_MAX_GAME
) or
733 (UID2
> UID_MAX_PLAYER
) or (UID2
<= UID_MAX_GAME
) then Exit
;
735 if (g_Player_Get(UID1
) = nil) or (g_Player_Get(UID2
) = nil) then Exit
;
737 if ((g_Player_Get(UID1
).Team
= TEAM_NONE
) or
738 (g_Player_Get(UID2
).Team
= TEAM_NONE
)) then Exit
;
740 Result
:= g_Player_Get(UID1
).FTeam
= g_Player_Get(UID2
).FTeam
;
743 procedure g_Gibs_SetMax(Count
: Word);
746 SetLength(gGibs
, Count
);
748 if CurrentGib
>= Count
then
752 function g_Gibs_GetMax(): Word;
757 procedure g_Shells_SetMax(Count
: Word);
760 SetLength(gShells
, Count
);
762 if CurrentShell
>= Count
then
766 function g_Shells_GetMax(): Word;
772 procedure g_Corpses_SetMax(Count
: Word);
775 SetLength(gCorpses
, Count
);
778 function g_Corpses_GetMax(): Word;
780 Result
:= MaxCorpses
;
783 function g_Player_Create(ModelName
: String; Color
: TRGB
; Team
: Byte; Bot
: Boolean): Word;
793 // Åñòü ëè ìåñòî â gPlayers:
794 if gPlayers
<> nil then
795 for a
:= 0 to High(gPlayers
) do
796 if gPlayers
[a
] = nil then
802 // Íåò ìåñòà - ðàñøèðÿåì gPlayers:
805 SetLength(gPlayers
, Length(gPlayers
)+1);
809 // Ñîçäàåì îáúåêò èãðîêà:
811 gPlayers
[a
] := TBot
.Create()
813 gPlayers
[a
] := TPlayer
.Create();
816 gPlayers
[a
].FActualModelName
:= ModelName
;
817 gPlayers
[a
].SetModel(ModelName
);
819 // Íåò ìîäåëè - ñîçäàíèå íå âîçìîæíî:
820 if gPlayers
[a
].FModel
= nil then
824 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], [ModelName
]));
828 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
829 if Random(2) = 0 then
833 gPlayers
[a
].FPreferredTeam
:= Team
;
835 case gGameSettings
.GameMode
of
836 GM_DM
: gPlayers
[a
].FTeam
:= TEAM_NONE
;
838 GM_CTF
: gPlayers
[a
].FTeam
:= gPlayers
[a
].FPreferredTeam
;
840 GM_COOP
: gPlayers
[a
].FTeam
:= TEAM_COOP
;
843 // Åñëè êîìàíäíàÿ èãðà - êðàñèì ìîäåëü â öâåò êîìàíäû:
844 gPlayers
[a
].FColor
:= Color
;
845 if gPlayers
[a
].FTeam
in [TEAM_RED
, TEAM_BLUE
] then
846 gPlayers
[a
].FModel
.Color
:= TEAMCOLOR
[gPlayers
[a
].FTeam
]
848 gPlayers
[a
].FModel
.Color
:= Color
;
850 gPlayers
[a
].FUID
:= g_CreateUID(UID_PLAYER
);
851 gPlayers
[a
].FAlive
:= False;
853 Result
:= gPlayers
[a
].FUID
;
856 function g_Player_CreateFromState (st
: TStream
): Word;
863 if (st
= nil) then exit
; //???
866 if not utils
.checkSign(st
, 'PLYR') then raise XStreamError
.Create('invalid player signature');
867 if (utils
.readByte(st
) <> PLR_SAVE_VERSION
) then raise XStreamError
.Create('invalid player version');
870 Bot
:= utils
.readBool(st
);
875 // Åñòü ëè ìåñòî â gPlayers:
876 for a
:= 0 to High(gPlayers
) do if (gPlayers
[a
] = nil) then begin ok
:= true; break
; end;
878 // Íåò ìåñòà - ðàñøèðÿåì gPlayers
881 SetLength(gPlayers
, Length(gPlayers
)+1);
885 // Ñîçäàåì îáúåêò èãðîêà
887 gPlayers
[a
] := TBot
.Create()
889 gPlayers
[a
] := TPlayer
.Create();
890 gPlayers
[a
].FIamBot
:= Bot
;
891 gPlayers
[a
].FPhysics
:= True;
894 gPlayers
[a
].FUID
:= utils
.readWord(st
);
896 gPlayers
[a
].FName
:= utils
.readStr(st
);
898 gPlayers
[a
].FTeam
:= utils
.readByte(st
);
899 gPlayers
[a
].FPreferredTeam
:= gPlayers
[a
].FTeam
;
901 gPlayers
[a
].FAlive
:= utils
.readBool(st
);
902 // Èçðàñõîäîâàë ëè âñå æèçíè
903 gPlayers
[a
].FNoRespawn
:= utils
.readBool(st
);
905 b
:= utils
.readByte(st
);
906 if b
= 1 then gPlayers
[a
].FDirection
:= TDirection
.D_LEFT
else gPlayers
[a
].FDirection
:= TDirection
.D_RIGHT
; // b = 2
908 gPlayers
[a
].FHealth
:= utils
.readLongInt(st
);
910 gPlayers
[a
].FHandicap
:= utils
.readLongInt(st
);
912 gPlayers
[a
].FLives
:= utils
.readByte(st
);
914 gPlayers
[a
].FArmor
:= utils
.readLongInt(st
);
916 gPlayers
[a
].FAir
:= utils
.readLongInt(st
);
918 gPlayers
[a
].FJetFuel
:= utils
.readLongInt(st
);
920 gPlayers
[a
].FPain
:= utils
.readLongInt(st
);
922 gPlayers
[a
].FKills
:= utils
.readLongInt(st
);
924 gPlayers
[a
].FMonsterKills
:= utils
.readLongInt(st
);
926 gPlayers
[a
].FFrags
:= utils
.readLongInt(st
);
928 gPlayers
[a
].FFragCombo
:= utils
.readByte(st
);
929 // Âðåìÿ ïîñëåäíåãî ôðàãà
930 gPlayers
[a
].FLastFrag
:= utils
.readLongWord(st
);
932 gPlayers
[a
].FDeath
:= utils
.readLongInt(st
);
934 gPlayers
[a
].FFlag
:= utils
.readByte(st
);
936 gPlayers
[a
].FSecrets
:= utils
.readLongInt(st
);
938 gPlayers
[a
].FCurrWeap
:= utils
.readByte(st
);
939 // Ñëåäóþùåå æåëàåìîå îðóæèå
940 gPlayers
[a
].FNextWeap
:= utils
.readWord(st
);
942 gPlayers
[a
].FNextWeapDelay
:= utils
.readByte(st
);
944 gPlayers
[a
].FBFGFireCounter
:= utils
.readSmallInt(st
);
946 gPlayers
[a
].FDamageBuffer
:= utils
.readLongInt(st
);
947 // Ïîñëåäíèé óäàðèâøèé
948 gPlayers
[a
].FLastSpawnerUID
:= utils
.readWord(st
);
949 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà
950 gPlayers
[a
].FLastHit
:= utils
.readByte(st
);
952 Obj_LoadState(@gPlayers
[a
].FObj
, st
);
953 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ
954 for i
:= A_BULLETS
to A_HIGH
do gPlayers
[a
].FAmmo
[i
] := utils
.readWord(st
);
955 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ
956 for i
:= A_BULLETS
to A_HIGH
do gPlayers
[a
].FMaxAmmo
[i
] := utils
.readWord(st
);
958 for i
:= WP_FIRST
to WP_LAST
do gPlayers
[a
].FWeapon
[i
] := utils
.readBool(st
);
959 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ
960 for i
:= WP_FIRST
to WP_LAST
do gPlayers
[a
].FReloading
[i
] := utils
.readWord(st
);
962 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_ITEM_BACKPACK
);
963 // Íàëè÷èå êðàñíîãî êëþ÷à
964 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_KEY_RED
);
965 // Íàëè÷èå çåëåíîãî êëþ÷à
966 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_KEY_GREEN
);
967 // Íàëè÷èå ñèíåãî êëþ÷à
968 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_KEY_BLUE
);
970 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_BERSERK
);
971 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ
972 for i
:= MR_SUIT
to MR_MAX
do gPlayers
[a
].FMegaRulez
[i
] := utils
.readLongWord(st
);
973 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà
974 for i
:= T_RESPAWN
to T_FLAGCAP
do gPlayers
[a
].FTime
[i
] := utils
.readLongWord(st
);
977 gPlayers
[a
].FActualModelName
:= utils
.readStr(st
);
979 gPlayers
[a
].FColor
.R
:= utils
.readByte(st
);
980 gPlayers
[a
].FColor
.G
:= utils
.readByte(st
);
981 gPlayers
[a
].FColor
.B
:= utils
.readByte(st
);
982 // Îáíîâëÿåì ìîäåëü èãðîêà
983 gPlayers
[a
].SetModel(gPlayers
[a
].FActualModelName
);
985 // Íåò ìîäåëè - ñîçäàíèå íåâîçìîæíî
986 if (gPlayers
[a
].FModel
= nil) then
990 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], [gPlayers
[a
].FActualModelName
]));
994 // Åñëè êîìàíäíàÿ èãðà - êðàñèì ìîäåëü â öâåò êîìàíäû
995 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
996 gPlayers
[a
].FModel
.Color
:= TEAMCOLOR
[gPlayers
[a
].FTeam
]
998 gPlayers
[a
].FModel
.Color
:= gPlayers
[a
].FColor
;
1000 result
:= gPlayers
[a
].FUID
;
1004 procedure g_Player_ResetTeams();
1008 if g_Game_IsClient
then
1010 if gPlayers
= nil then
1012 for a
:= Low(gPlayers
) to High(gPlayers
) do
1013 if gPlayers
[a
] <> nil then
1014 case gGameSettings
.GameMode
of
1016 gPlayers
[a
].ChangeTeam(TEAM_NONE
);
1018 if not (gPlayers
[a
].Team
in [TEAM_RED
, TEAM_BLUE
]) then
1019 if gPlayers
[a
].FPreferredTeam
in [TEAM_RED
, TEAM_BLUE
] then
1020 gPlayers
[a
].ChangeTeam(gPlayers
[a
].FPreferredTeam
)
1023 gPlayers
[a
].ChangeTeam(TEAM_RED
)
1025 gPlayers
[a
].ChangeTeam(TEAM_BLUE
);
1028 gPlayers
[a
].ChangeTeam(TEAM_COOP
);
1032 procedure g_Bot_Add(Team
, Difficult
: Byte; Handicap
: Integer = 100);
1035 _name
, _model
: String;
1038 if not g_Game_IsServer
then Exit
;
1040 // Ñïèñîê íàçâàíèé ìîäåëåé:
1041 m
:= g_PlayerModel_GetNames();
1046 if (gGameSettings
.GameType
= GT_SINGLE
) or (gGameSettings
.GameMode
= GM_COOP
) then
1047 Team
:= TEAM_COOP
// COOP
1049 if gGameSettings
.GameMode
= GM_DM
then
1050 Team
:= TEAM_NONE
// DM
1052 if Team
= TEAM_NONE
then // CTF / TDM
1054 // Àâòîáàëàíñ êîìàíä:
1058 for a
:= 0 to High(gPlayers
) do
1059 if gPlayers
[a
] <> nil then
1061 if gPlayers
[a
].Team
= TEAM_RED
then
1064 if gPlayers
[a
].Team
= TEAM_BLUE
then
1074 if Random(2) = 0 then
1080 // Âûáèðàåì áîòó èìÿ:
1082 if BotNames
<> nil then
1083 for a
:= 0 to High(BotNames
) do
1084 if g_Player_ValidName(BotNames
[a
]) then
1086 _name
:= BotNames
[a
];
1090 // Âûáèðàåì ñëó÷àéíóþ ìîäåëü:
1091 _model
:= m
[Random(Length(m
))];
1094 with g_Player_Get(g_Player_Create(_model
,
1095 _RGB(Min(Random(9)*32, 255),
1096 Min(Random(9)*32, 255),
1097 Min(Random(9)*32, 255)),
1098 Team
, True)) as TBot
do
1100 // Åñëè èìåíè íåò, äåëàåì åãî èç UID áîòà
1102 Name
:= Format('DFBOT%.5d', [UID
])
1107 1: FDifficult
:= DIFFICULT_EASY
;
1108 2: FDifficult
:= DIFFICULT_MEDIUM
;
1109 else FDifficult
:= DIFFICULT_HARD
;
1112 for a
:= WP_FIRST
to WP_LAST
do
1114 FDifficult
.WeaponPrior
[a
] := WEAPON_PRIOR1
[a
];
1115 FDifficult
.CloseWeaponPrior
[a
] := WEAPON_PRIOR2
[a
];
1116 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
1119 FHandicap
:= Handicap
;
1121 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [Name
]), True);
1123 if g_Game_IsNet
then MH_SEND_PlayerCreate(UID
);
1124 if g_Game_IsServer
and (gGameSettings
.MaxLives
> 0) then
1129 procedure g_Bot_AddList(Team
: Byte; lName
: ShortString; num
: Integer = -1; Handicap
: Integer = 100);
1132 _name
, _model
: String;
1135 if not g_Game_IsServer
then Exit
;
1137 // Ñïèñîê íàçâàíèé ìîäåëåé:
1138 m
:= g_PlayerModel_GetNames();
1143 if (gGameSettings
.GameType
= GT_SINGLE
) or (gGameSettings
.GameMode
= GM_COOP
) then
1144 Team
:= TEAM_COOP
// COOP
1146 if gGameSettings
.GameMode
= GM_DM
then
1147 Team
:= TEAM_NONE
// DM
1149 if Team
= TEAM_NONE
then
1150 Team
:= BotList
[num
].team
; // CTF / TDM
1152 // Âûáèðàåì íàñòðîéêè áîòà èç ñïèñêà ïî íîìåðó èëè èìåíè:
1153 lName
:= AnsiLowerCase(lName
);
1154 if (num
< 0) or (num
> Length(BotList
)-1) then
1156 if (num
= -1) and (lName
<> '') and (BotList
<> nil) then
1157 for a
:= 0 to High(BotList
) do
1158 if AnsiLowerCase(BotList
[a
].name
) = lName
then
1167 _name
:= BotList
[num
].name
;
1168 // Çàíÿòî - âûáèðàåì ñëó÷àéíîå:
1169 if not g_Player_ValidName(_name
) then
1171 _name
:= Format('DFBOT%.2d', [Random(100)]);
1172 until g_Player_ValidName(_name
);
1175 _model
:= BotList
[num
].model
;
1176 // Íåò òàêîé - âûáèðàåì ñëó÷àéíóþ:
1177 if not InSArray(_model
, m
) then
1178 _model
:= m
[Random(Length(m
))];
1181 with g_Player_Get(g_Player_Create(_model
, BotList
[num
].color
, Team
, True)) as TBot
do
1185 FDifficult
.DiagFire
:= BotList
[num
].diag_fire
;
1186 FDifficult
.InvisFire
:= BotList
[num
].invis_fire
;
1187 FDifficult
.DiagPrecision
:= BotList
[num
].diag_precision
;
1188 FDifficult
.FlyPrecision
:= BotList
[num
].fly_precision
;
1189 FDifficult
.Cover
:= BotList
[num
].cover
;
1190 FDifficult
.CloseJump
:= BotList
[num
].close_jump
;
1192 FHandicap
:= Handicap
;
1194 for a
:= WP_FIRST
to WP_LAST
do
1196 FDifficult
.WeaponPrior
[a
] := BotList
[num
].w_prior1
[a
];
1197 FDifficult
.CloseWeaponPrior
[a
] := BotList
[num
].w_prior2
[a
];
1198 //FDifficult.SafeWeaponPrior[a] := BotList[num].w_prior3[a];
1201 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [Name
]), True);
1203 if g_Game_IsNet
then MH_SEND_PlayerCreate(UID
);
1207 procedure g_Bot_RemoveAll();
1211 if not g_Game_IsServer
then Exit
;
1212 if gPlayers
= nil then Exit
;
1214 for a
:= 0 to High(gPlayers
) do
1215 if gPlayers
[a
] <> nil then
1216 if gPlayers
[a
] is TBot
then
1218 gPlayers
[a
].Lives
:= 0;
1219 gPlayers
[a
].Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
1220 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [gPlayers
[a
].Name
]), True);
1221 g_Player_Remove(gPlayers
[a
].FUID
);
1227 procedure g_Bot_MixNames();
1232 if BotNames
<> nil then
1233 for a
:= 0 to High(BotNames
) do
1235 b
:= Random(Length(BotNames
));
1237 Botnames
[a
] := BotNames
[b
];
1242 procedure g_Player_Remove(UID
: Word);
1246 if gPlayers
= nil then Exit
;
1248 if g_Game_IsServer
and g_Game_IsNet
then
1249 MH_SEND_PlayerDelete(UID
);
1251 for i
:= 0 to High(gPlayers
) do
1252 if gPlayers
[i
] <> nil then
1253 if gPlayers
[i
].FUID
= UID
then
1255 if gPlayers
[i
] is TPlayer
then
1256 TPlayer(gPlayers
[i
]).Free()
1258 TBot(gPlayers
[i
]).Free();
1264 procedure g_Player_Init();
1275 path
:= BOTNAMES_FILENAME
;
1276 if e_FindResource(DataDirs
, path
) = false then
1279 // ×èòàåì âîçìîæíûå èìåíà áîòîâ èç ôàéëà:
1280 AssignFile(F
, path
);
1291 SetLength(BotNames
, Length(BotNames
)+1);
1292 BotNames
[High(BotNames
)] := s
;
1300 // ×èòàåì ôàéë ñ ïàðàìåòðàìè áîòîâ:
1301 config
:= TConfig
.CreateFile(path
);
1305 while config
.SectionExists(IntToStr(a
)) do
1307 SetLength(BotList
, Length(BotList
)+1);
1309 with BotList
[High(BotList
)] do
1312 name
:= config
.ReadStr(IntToStr(a
), 'name', '');
1314 model
:= config
.ReadStr(IntToStr(a
), 'model', '');
1316 if config
.ReadStr(IntToStr(a
), 'team', 'red') = 'red' then
1321 sa
:= parse(config
.ReadStr(IntToStr(a
), 'color', ''));
1322 color
.R
:= StrToIntDef(sa
[0], 0);
1323 color
.G
:= StrToIntDef(sa
[1], 0);
1324 color
.B
:= StrToIntDef(sa
[2], 0);
1325 // Âåðîÿòíîñòü ñòðåëüáû ïîä óãëîì:
1326 diag_fire
:= config
.ReadInt(IntToStr(a
), 'diag_fire', 0);
1327 // Âåðîÿòíîñòü îòâåòíîãî îãíÿ ïî íåâèäèìîìó ñîïåðíèêó:
1328 invis_fire
:= config
.ReadInt(IntToStr(a
), 'invis_fire', 0);
1329 // Òî÷íîñòü ñòðåëüáû ïîä óãëîì:
1330 diag_precision
:= config
.ReadInt(IntToStr(a
), 'diag_precision', 0);
1331 // Òî÷íîñòü ñòðåëüáû â ïîëåòå:
1332 fly_precision
:= config
.ReadInt(IntToStr(a
), 'fly_precision', 0);
1333 // Òî÷íîñòü óêëîíåíèÿ îò ñíàðÿäîâ:
1334 cover
:= config
.ReadInt(IntToStr(a
), 'cover', 0);
1335 // Âåðîÿòíîñòü ïðûæêà ïðè ïðèáëèæåíèè ñîïåðíèêà:
1336 close_jump
:= config
.ReadInt(IntToStr(a
), 'close_jump', 0);
1337 // Ïðèîðèòåòû îðóæèÿ äëÿ äàëüíåãî áîÿ:
1338 sa
:= parse(config
.ReadStr(IntToStr(a
), 'w_prior1', ''));
1339 if Length(sa
) = 10 then
1341 w_prior1
[b
] := EnsureRange(StrToInt(sa
[b
]), 0, 9);
1342 // Ïðèîðèòåòû îðóæèÿ äëÿ áëèæíåãî áîÿ:
1343 sa
:= parse(config
.ReadStr(IntToStr(a
), 'w_prior2', ''));
1344 if Length(sa
) = 10 then
1346 w_prior2
[b
] := EnsureRange(StrToInt(sa
[b
]), 0, 9);
1348 {sa := parse(config.ReadStr(IntToStr(a), 'w_prior3', ''));
1349 if Length(sa) = 10 then
1351 w_prior3[b] := EnsureRange(StrToInt(sa[b]), 0, 9);}
1358 SetLength(SavedStates
, 0);
1361 procedure g_Player_Free();
1365 if gPlayers
<> nil then
1367 for i
:= 0 to High(gPlayers
) do
1368 if gPlayers
[i
] <> nil then
1370 if gPlayers
[i
] is TPlayer
then
1371 TPlayer(gPlayers
[i
]).Free()
1373 TBot(gPlayers
[i
]).Free();
1382 SetLength(SavedStates
, 0);
1385 procedure g_Player_PreUpdate();
1389 if gPlayers
= nil then Exit
;
1390 for i
:= 0 to High(gPlayers
) do
1391 if gPlayers
[i
] <> nil then
1392 gPlayers
[i
].PreUpdate();
1395 procedure g_Player_UpdateAll();
1399 if gPlayers
= nil then Exit
;
1401 //e_WriteLog('***g_Player_UpdateAll: ENTER', MSG_WARNING);
1402 for i
:= 0 to High(gPlayers
) do
1404 if gPlayers
[i
] <> nil then
1406 if gPlayers
[i
] is TPlayer
then
1408 gPlayers
[i
].Update();
1409 gPlayers
[i
].RealizeCurrentWeapon(); // WARNING! DO NOT MOVE THIS INTO `Update()`!
1413 // bot updates weapons in `UpdateCombat()`
1414 TBot(gPlayers
[i
]).Update();
1418 //e_WriteLog('***g_Player_UpdateAll: EXIT', MSG_WARNING);
1421 procedure g_Player_DrawAll();
1425 if gPlayers
= nil then Exit
;
1427 for i
:= 0 to High(gPlayers
) do
1428 if gPlayers
[i
] <> nil then
1429 if gPlayers
[i
] is TPlayer
then gPlayers
[i
].Draw()
1430 else TBot(gPlayers
[i
]).Draw();
1433 procedure g_Player_DrawDebug(p
: TPlayer
);
1437 if p
= nil then Exit
;
1438 if (@p
.FObj
) = nil then Exit
;
1440 e_TextureFontGetSize(gStdFont
, fW
, fH
);
1442 e_TextureFontPrint(0, 0 , 'Pos X: ' + IntToStr(p
.FObj
.X
), gStdFont
);
1443 e_TextureFontPrint(0, fH
, 'Pos Y: ' + IntToStr(p
.FObj
.Y
), gStdFont
);
1444 e_TextureFontPrint(0, fH
* 2, 'Vel X: ' + IntToStr(p
.FObj
.Vel
.X
), gStdFont
);
1445 e_TextureFontPrint(0, fH
* 3, 'Vel Y: ' + IntToStr(p
.FObj
.Vel
.Y
), gStdFont
);
1446 e_TextureFontPrint(0, fH
* 4, 'Acc X: ' + IntToStr(p
.FObj
.Accel
.X
), gStdFont
);
1447 e_TextureFontPrint(0, fH
* 5, 'Acc Y: ' + IntToStr(p
.FObj
.Accel
.Y
), gStdFont
);
1448 e_TextureFontPrint(0, fH
* 6, 'Old X: ' + IntToStr(p
.FObj
.oldX
), gStdFont
);
1449 e_TextureFontPrint(0, fH
* 7, 'Old Y: ' + IntToStr(p
.FObj
.oldY
), gStdFont
);
1452 procedure g_Player_DrawHealth();
1457 if gPlayers
= nil then Exit
;
1458 e_TextureFontGetSize(gStdFont
, fW
, fH
);
1460 for i
:= 0 to High(gPlayers
) do
1461 if gPlayers
[i
] <> nil then
1463 e_TextureFontPrint(gPlayers
[i
].FObj
.X
+ gPlayers
[i
].FObj
.Rect
.X
,
1464 gPlayers
[i
].FObj
.Y
+ gPlayers
[i
].FObj
.Rect
.Y
+ gPlayers
[i
].FObj
.Rect
.Height
- fH
* 2,
1465 IntToStr(gPlayers
[i
].FHealth
), gStdFont
);
1466 e_TextureFontPrint(gPlayers
[i
].FObj
.X
+ gPlayers
[i
].FObj
.Rect
.X
,
1467 gPlayers
[i
].FObj
.Y
+ gPlayers
[i
].FObj
.Rect
.Y
+ gPlayers
[i
].FObj
.Rect
.Height
- fH
,
1468 IntToStr(gPlayers
[i
].FArmor
), gStdFont
);
1472 function g_Player_Get(UID
: Word): TPlayer
;
1478 if gPlayers
= nil then
1481 for a
:= 0 to High(gPlayers
) do
1482 if gPlayers
[a
] <> nil then
1483 if gPlayers
[a
].FUID
= UID
then
1485 Result
:= gPlayers
[a
];
1490 function g_Player_GetCount(): Byte;
1496 if gPlayers
= nil then
1499 for a
:= 0 to High(gPlayers
) do
1500 if gPlayers
[a
] <> nil then
1501 Result
:= Result
+ 1;
1504 function g_Player_GetStats(): TPlayerStatArray
;
1510 if gPlayers
= nil then Exit
;
1512 for a
:= 0 to High(gPlayers
) do
1513 if gPlayers
[a
] <> nil then
1515 SetLength(Result
, Length(Result
)+1);
1516 with Result
[High(Result
)] do
1519 Ping
:= gPlayers
[a
].FPing
;
1520 Loss
:= gPlayers
[a
].FLoss
;
1521 Name
:= gPlayers
[a
].FName
;
1522 Team
:= gPlayers
[a
].FTeam
;
1523 Frags
:= gPlayers
[a
].FFrags
;
1524 Deaths
:= gPlayers
[a
].FDeath
;
1525 Kills
:= gPlayers
[a
].FKills
;
1526 Color
:= gPlayers
[a
].FModel
.Color
;
1527 Lives
:= gPlayers
[a
].FLives
;
1528 Spectator
:= gPlayers
[a
].FSpectator
;
1529 UID
:= gPlayers
[a
].FUID
;
1534 procedure g_Player_ResetReady();
1538 if not g_Game_IsServer
then Exit
;
1539 if gPlayers
= nil then Exit
;
1541 for a
:= 0 to High(gPlayers
) do
1542 if gPlayers
[a
] <> nil then
1544 gPlayers
[a
].FReady
:= False;
1545 if g_Game_IsNet
then
1546 MH_SEND_GameEvent(NET_EV_INTER_READY
, gPlayers
[a
].UID
, 'N');
1550 procedure g_Player_RememberAll
;
1554 for i
:= Low(gPlayers
) to High(gPlayers
) do
1555 if (gPlayers
[i
] <> nil) and gPlayers
[i
].alive
then
1556 gPlayers
[i
].RememberState
;
1559 procedure g_Player_ResetAll(Force
, Silent
: Boolean);
1563 gTeamStat
[TEAM_RED
].Goals
:= 0;
1564 gTeamStat
[TEAM_BLUE
].Goals
:= 0;
1566 if gPlayers
<> nil then
1567 for i
:= 0 to High(gPlayers
) do
1568 if gPlayers
[i
] <> nil then
1570 gPlayers
[i
].Reset(Force
);
1572 if gPlayers
[i
] is TPlayer
then
1574 if (not gPlayers
[i
].FSpectator
) or gPlayers
[i
].FWantsInGame
then
1575 gPlayers
[i
].Respawn(Silent
)
1577 gPlayers
[i
].Spectate();
1580 TBot(gPlayers
[i
]).Respawn(Silent
);
1584 function g_Player_CreateCorpse(Player
: TPlayer
): Integer;
1592 if Player
.alive
then
1595 // Ðàçðûâàåì ñâÿçü ñ ïðåæíèì òðóïîì:
1596 i
:= Player
.FCorpse
;
1597 if (i
>= 0) and (i
< Length(gCorpses
)) then
1599 if (gCorpses
[i
] <> nil) and (gCorpses
[i
].FPlayerUID
= Player
.FUID
) then
1600 gCorpses
[i
].FPlayerUID
:= 0;
1603 if Player
.FObj
.Y
>= gMapInfo
.Height
+128 then
1608 if (FHealth
>= -50) or (gGibsCount
= 0) then
1610 if (gCorpses
= nil) or (Length(gCorpses
) = 0) then
1614 for find_id
:= 0 to High(gCorpses
) do
1615 if gCorpses
[find_id
] = nil then
1622 find_id
:= Random(Length(gCorpses
));
1624 gCorpses
[find_id
] := TCorpse
.Create(FObj
.X
, FObj
.Y
, FModel
.Name
, FHealth
< -20);
1625 gCorpses
[find_id
].FColor
:= FModel
.Color
;
1626 gCorpses
[find_id
].FObj
.Vel
:= FObj
.Vel
;
1627 gCorpses
[find_id
].FObj
.Accel
:= FObj
.Accel
;
1628 gCorpses
[find_id
].FPlayerUID
:= FUID
;
1633 g_Player_CreateGibs(FObj
.X
+ PLAYER_RECT_CX
,
1634 FObj
.Y
+ PLAYER_RECT_CY
,
1635 FModel
.Name
, FModel
.Color
);
1639 procedure g_Player_CreateShell(fX
, fY
, dX
, dY
: Integer; T
: Byte);
1643 if (gShells
= nil) or (Length(gShells
) = 0) then
1646 with gShells
[CurrentShell
] do
1652 if T
= SHELL_BULLET
then
1654 if g_Texture_Get('TEXTURE_SHELL_BULLET', SID
) then
1658 Obj
.Rect
.Width
:= 4;
1659 Obj
.Rect
.Height
:= 2;
1663 if g_Texture_Get('TEXTURE_SHELL_SHELL', SID
) then
1667 Obj
.Rect
.Width
:= 7;
1668 Obj
.Rect
.Height
:= 3;
1674 g_Obj_Push(@Obj
, dX
+ Random(4)-Random(4), dY
-Random(4));
1675 positionChanged(); // this updates spatial accelerators
1676 RAngle
:= Random(360);
1677 Timeout
:= gTime
+ SHELL_TIMEOUT
;
1679 if CurrentShell
>= High(gShells
) then
1686 procedure g_Player_CreateGibs(fX
, fY
: Integer; ModelName
: string; fColor
: TRGB
);
1689 GibsArray
: TGibsArray
;
1692 if (gGibs
= nil) or (Length(gGibs
) = 0) then
1694 if not g_PlayerModel_GetGibs(ModelName
, GibsArray
) then
1696 Blood
:= g_PlayerModel_GetBlood(ModelName
);
1698 for a
:= 0 to High(GibsArray
) do
1699 with gGibs
[CurrentGib
] do
1702 ID
:= GibsArray
[a
].ID
;
1703 MaskID
:= GibsArray
[a
].MaskID
;
1706 Obj
.Rect
:= GibsArray
[a
].Rect
;
1707 Obj
.X
:= fX
-GibsArray
[a
].Rect
.X
-(GibsArray
[a
].Rect
.Width
div 2);
1708 Obj
.Y
:= fY
-GibsArray
[a
].Rect
.Y
-(GibsArray
[a
].Rect
.Height
div 2);
1709 g_Obj_PushA(@Obj
, 25 + Random(10), Random(361));
1710 positionChanged(); // this updates spatial accelerators
1711 RAngle
:= Random(360);
1713 if gBloodCount
> 0 then
1714 g_GFX_Blood(fX
, fY
, 16*gBloodCount
+Random(5*gBloodCount
), -16+Random(33), -16+Random(33),
1715 Random(48), Random(48), Blood
.R
, Blood
.G
, Blood
.B
, Blood
.Kind
);
1717 if CurrentGib
>= High(gGibs
) then
1724 procedure g_Player_UpdatePhysicalObjects();
1730 procedure ShellSound_Bounce(X
, Y
: Integer; T
: Byte);
1735 if T
= SHELL_BULLET
then
1736 g_Sound_PlayExAt('SOUND_PLAYER_CASING' + IntToStr(k
), X
, Y
)
1738 g_Sound_PlayExAt('SOUND_PLAYER_SHELL' + IntToStr(k
), X
, Y
);
1743 if gGibs
<> nil then
1744 for i
:= 0 to High(gGibs
) do
1745 if gGibs
[i
].alive
then
1752 mr
:= g_Obj_Move(@Obj
, True, False, True);
1753 positionChanged(); // this updates spatial accelerators
1755 if WordBool(mr
and MOVE_FALLOUT
) then
1761 // Îòëåòàåò îò óäàðà î ñòåíó/ïîòîëîê/ïîë:
1762 if WordBool(mr
and MOVE_HITWALL
) then
1763 Obj
.Vel
.X
:= -(vel
.X
div 2);
1764 if WordBool(mr
and (MOVE_HITCEIL
or MOVE_HITLAND
)) then
1765 Obj
.Vel
.Y
:= -(vel
.Y
div 2);
1767 if (Obj
.Vel
.X
>= 0) then
1769 RAngle
:= RAngle
+ Abs(Obj
.Vel
.X
)*6 + Abs(Obj
.Vel
.Y
);
1770 if RAngle
>= 360 then
1771 RAngle
:= RAngle
mod 360;
1772 end else begin // Counter-clockwise
1773 RAngle
:= RAngle
- Abs(Obj
.Vel
.X
)*6 - Abs(Obj
.Vel
.Y
);
1775 RAngle
:= (360 - (Abs(RAngle
) mod 360)) mod 360;
1778 // Ñîïðîòèâëåíèå âîçäóõà äëÿ êóñêà òðóïà:
1779 if gTime
mod (GAME_TICK
*3) = 0 then
1780 Obj
.Vel
.X
:= z_dec(Obj
.Vel
.X
, 1);
1784 if gCorpses
<> nil then
1785 for i
:= 0 to High(gCorpses
) do
1786 if gCorpses
[i
] <> nil then
1787 if gCorpses
[i
].State
= CORPSE_STATE_REMOVEME
then
1793 gCorpses
[i
].Update();
1796 if gShells
<> nil then
1797 for i
:= 0 to High(gShells
) do
1798 if gShells
[i
].alive
then
1805 mr
:= g_Obj_Move(@Obj
, True, False, True);
1806 positionChanged(); // this updates spatial accelerators
1808 if WordBool(mr
and MOVE_FALLOUT
) or (gShells
[i
].Timeout
< gTime
) then
1814 // Îòëåòàåò îò óäàðà î ñòåíó/ïîòîëîê/ïîë:
1815 if WordBool(mr
and MOVE_HITWALL
) then
1817 Obj
.Vel
.X
:= -(vel
.X
div 2);
1818 if not WordBool(mr
and MOVE_INWATER
) then
1819 ShellSound_Bounce(Obj
.X
, Obj
.Y
, SType
);
1821 if WordBool(mr
and (MOVE_HITCEIL
or MOVE_HITLAND
)) then
1823 Obj
.Vel
.Y
:= -(vel
.Y
div 2);
1824 if Obj
.Vel
.X
<> 0 then Obj
.Vel
.X
:= Obj
.Vel
.X
div 2;
1825 if (Obj
.Vel
.X
= 0) and (Obj
.Vel
.Y
= 0) then
1827 if RAngle
mod 90 <> 0 then
1828 RAngle
:= (RAngle
div 90) * 90;
1830 else if not WordBool(mr
and MOVE_INWATER
) then
1831 ShellSound_Bounce(Obj
.X
, Obj
.Y
, SType
);
1834 if (Obj
.Vel
.X
>= 0) then
1836 RAngle
:= RAngle
+ Abs(Obj
.Vel
.X
)*8 + Abs(Obj
.Vel
.Y
);
1837 if RAngle
>= 360 then
1838 RAngle
:= RAngle
mod 360;
1839 end else begin // Counter-clockwise
1840 RAngle
:= RAngle
- Abs(Obj
.Vel
.X
)*8 - Abs(Obj
.Vel
.Y
);
1842 RAngle
:= (360 - (Abs(RAngle
) mod 360)) mod 360;
1848 procedure TGib
.getMapBox (out x
, y
, w
, h
: Integer); inline;
1850 x
:= Obj
.X
+Obj
.Rect
.X
;
1851 y
:= Obj
.Y
+Obj
.Rect
.Y
;
1852 w
:= Obj
.Rect
.Width
;
1853 h
:= Obj
.Rect
.Height
;
1856 procedure TGib
.moveBy (dx
, dy
: Integer); inline;
1858 if (dx
<> 0) or (dy
<> 0) then
1867 procedure TShell
.getMapBox (out x
, y
, w
, h
: Integer); inline;
1871 w
:= Obj
.Rect
.Width
;
1872 h
:= Obj
.Rect
.Height
;
1875 procedure TShell
.moveBy (dx
, dy
: Integer); inline;
1877 if (dx
<> 0) or (dy
<> 0) then
1886 procedure TGib
.positionChanged (); inline; begin end;
1887 procedure TShell
.positionChanged (); inline; begin end;
1890 procedure g_Player_DrawCorpses();
1895 if gGibs
<> nil then
1896 for i
:= 0 to High(gGibs
) do
1897 if gGibs
[i
].alive
then
1900 if not g_Obj_Collide(sX
, sY
, sWidth
, sHeight
, @Obj
) then
1903 Obj
.lerp(gLerpFactor
, fX
, fY
);
1905 a
.X
:= Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2);
1906 a
.y
:= Obj
.Rect
.Y
+(Obj
.Rect
.Height
div 2);
1908 e_DrawAdv(ID
, fX
, fY
, 0, True, False, RAngle
, @a
, TMirrorType
.None
);
1911 e_DrawAdv(MaskID
, fX
, fY
, 0, True, False, RAngle
, @a
, TMirrorType
.None
);
1917 if gCorpses
<> nil then
1918 for i
:= 0 to High(gCorpses
) do
1919 if gCorpses
[i
] <> nil then
1923 procedure g_Player_DrawShells();
1928 if gShells
<> nil then
1929 for i
:= 0 to High(gShells
) do
1930 if gShells
[i
].alive
then
1933 if not g_Obj_Collide(sX
, sY
, sWidth
, sHeight
, @Obj
) then
1936 Obj
.lerp(gLerpFactor
, fX
, fY
);
1941 e_DrawAdv(SpriteID
, fX
, fY
, 0, True, False, RAngle
, @a
, TMirrorType
.None
);
1945 procedure g_Player_RemoveAllCorpses();
1951 SetLength(gGibs
, MaxGibs
);
1952 SetLength(gShells
, MaxGibs
);
1956 if gCorpses
<> nil then
1957 for i
:= 0 to High(gCorpses
) do
1961 SetLength(gCorpses
, MaxCorpses
);
1964 procedure g_Player_Corpses_SaveState (st
: TStream
);
1968 // Ñ÷èòàåì êîëè÷åñòâî ñóùåñòâóþùèõ òðóïîâ
1970 for i
:= 0 to High(gCorpses
) do if (gCorpses
[i
] <> nil) then Inc(count
);
1972 // Êîëè÷åñòâî òðóïîâ
1973 utils
.writeInt(st
, LongInt(count
));
1975 if (count
= 0) then exit
;
1978 for i
:= 0 to High(gCorpses
) do
1980 if gCorpses
[i
] <> nil then
1983 utils
.writeStr(st
, gCorpses
[i
].FModelName
);
1985 utils
.writeBool(st
, gCorpses
[i
].Mess
);
1986 // Ñîõðàíÿåì äàííûå òðóïà:
1987 gCorpses
[i
].SaveState(st
);
1993 procedure g_Player_Corpses_LoadState (st
: TStream
);
2001 g_Player_RemoveAllCorpses();
2003 // Êîëè÷åñòâî òðóïîâ:
2004 count
:= utils
.readLongInt(st
);
2005 if (count
< 0) or (count
> Length(gCorpses
)) then raise XStreamError
.Create('invalid number of corpses');
2007 if (count
= 0) then exit
;
2010 for i
:= 0 to count
-1 do
2013 str
:= utils
.readStr(st
);
2015 b
:= utils
.readBool(st
);
2017 gCorpses
[i
] := TCorpse
.Create(0, 0, str
, b
);
2018 // Çàãðóæàåì äàííûå òðóïà
2019 gCorpses
[i
].LoadState(st
);
2026 function TPlayer
.isValidViewPort (): Boolean; inline; begin result
:= (viewPortW
> 0) and (viewPortH
> 0); end;
2028 procedure TPlayer
.BFGHit();
2030 g_Weapon_BFGHit(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
2031 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2));
2032 if g_Game_IsServer
and g_Game_IsNet
then
2033 MH_SEND_Effect(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
2034 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2),
2038 procedure TPlayer
.ChangeModel(ModelName
: string);
2040 locModel
: TPlayerModel
;
2042 locModel
:= g_PlayerModel_Get(ModelName
);
2043 if locModel
= nil then Exit
;
2049 procedure TPlayer
.SetModel(ModelName
: string);
2053 m
:= g_PlayerModel_Get(ModelName
);
2056 g_SimpleError(Format(_lc
[I_GAME_ERROR_MODEL_FALLBACK
], [ModelName
]));
2057 m
:= g_PlayerModel_Get('doomer');
2060 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], ['doomer']));
2065 if FModel
<> nil then
2070 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
2071 FModel
.Color
:= FColor
2073 FModel
.Color
:= TEAMCOLOR
[FTeam
];
2074 FModel
.SetWeapon(FCurrWeap
);
2075 FModel
.SetFlag(FFlag
);
2076 SetDirection(FDirection
);
2079 procedure TPlayer
.SetColor(Color
: TRGB
);
2082 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
2083 if FModel
<> nil then FModel
.Color
:= Color
;
2086 function TPlayer
.GetColor(): TRGB
;
2088 result
:= FModel
.Color
;
2091 procedure TPlayer
.SwitchTeam
;
2093 if g_Game_IsClient
then
2095 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then Exit
;
2097 if gGameOn
and FAlive
then
2098 Kill(K_SIMPLEKILL
, FUID
, HIT_SELF
);
2100 if FTeam
= TEAM_RED
then
2102 ChangeTeam(TEAM_BLUE
);
2103 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_BLUE
], [FName
]), True);
2104 if g_Game_IsNet
then
2105 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM
, TEAM_BLUE
, FName
);
2109 ChangeTeam(TEAM_RED
);
2110 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_RED
], [FName
]), True);
2111 if g_Game_IsNet
then
2112 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM
, TEAM_RED
, FName
);
2114 FPreferredTeam
:= FTeam
;
2117 procedure TPlayer
.ChangeTeam(Team
: Byte);
2124 TEAM_RED
, TEAM_BLUE
:
2125 FModel
.Color
:= TEAMCOLOR
[Team
];
2127 FModel
.Color
:= FColor
;
2129 if (FTeam
<> OldTeam
) and g_Game_IsNet
and g_Game_IsServer
then
2130 MH_SEND_PlayerStats(FUID
);
2134 procedure TPlayer.CollideItem();
2139 if gItems = nil then Exit;
2140 if not FAlive then Exit;
2142 for i := 0 to High(gItems) do
2145 if (ItemType <> ITEM_NONE) and alive then
2146 if g_Obj_Collide(FObj.X+PLAYER_RECT.X, FObj.Y+PLAYER_RECT.Y, PLAYER_RECT.Width,
2147 PLAYER_RECT.Height, @Obj) then
2149 if not PickItem(ItemType, gItems[i].Respawnable, r) then Continue;
2151 if ItemType in [ITEM_SPHERE_BLUE, ITEM_SPHERE_WHITE, ITEM_INVUL] then
2152 g_Sound_PlayExAt('SOUND_ITEM_GETRULEZ', FObj.X, FObj.Y)
2153 else if ItemType in [ITEM_MEDKIT_SMALL, ITEM_MEDKIT_LARGE, ITEM_MEDKIT_BLACK] then
2154 g_Sound_PlayExAt('SOUND_ITEM_GETMED', FObj.X, FObj.Y)
2155 else g_Sound_PlayExAt('SOUND_ITEM_GETITEM', FObj.X, FObj.Y);
2157 // Íàäî óáðàòü ñ êàðòû, åñëè ýòî íå êëþ÷, êîòîðûì íóæíî ïîäåëèòñÿ ñ äðóãèì èãðîêîì:
2158 if r and not ((ItemType in [ITEM_KEY_RED, ITEM_KEY_GREEN, ITEM_KEY_BLUE]) and
2159 (gGameSettings.GameType = GT_SINGLE) and
2160 (g_Player_GetCount() > 1)) then
2161 if not Respawnable then g_Items_Remove(i) else g_Items_Pick(i);
2167 function TPlayer
.CollideLevel(XInc
, YInc
: Integer): Boolean;
2169 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
2170 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_WALL
,
2174 constructor TPlayer
.Create();
2180 mEDamageType
:= HIT_SOME
;
2186 FSawSound
:= TPlayableSound
.Create();
2187 FSawSoundIdle
:= TPlayableSound
.Create();
2188 FSawSoundHit
:= TPlayableSound
.Create();
2189 FSawSoundSelect
:= TPlayableSound
.Create();
2190 FFlameSoundOn
:= TPlayableSound
.Create();
2191 FFlameSoundOff
:= TPlayableSound
.Create();
2192 FFlameSoundWork
:= TPlayableSound
.Create();
2193 FJetSoundFly
:= TPlayableSound
.Create();
2194 FJetSoundOn
:= TPlayableSound
.Create();
2195 FJetSoundOff
:= TPlayableSound
.Create();
2197 FSawSound
.SetByName('SOUND_WEAPON_FIRESAW');
2198 FSawSoundIdle
.SetByName('SOUND_WEAPON_IDLESAW');
2199 FSawSoundHit
.SetByName('SOUND_WEAPON_HITSAW');
2200 FSawSoundSelect
.SetByName('SOUND_WEAPON_SELECTSAW');
2201 FFlameSoundOn
.SetByName('SOUND_WEAPON_FLAMEON');
2202 FFlameSoundOff
.SetByName('SOUND_WEAPON_FLAMEOFF');
2203 FFlameSoundWork
.SetByName('SOUND_WEAPON_FLAMEWORK');
2204 FJetSoundFly
.SetByName('SOUND_PLAYER_JETFLY');
2205 FJetSoundOn
.SetByName('SOUND_PLAYER_JETON');
2206 FJetSoundOff
.SetByName('SOUND_PLAYER_JETOFF');
2208 FSpectatePlayer
:= -1;
2212 FSavedStateNum
:= -1;
2220 FActualModelName
:= 'doomer';
2223 FObj
.Rect
:= PLAYER_RECT
;
2225 FBFGFireCounter
:= -1;
2226 FJustTeleported
:= False;
2229 FWaitForFirstSpawn
:= false;
2234 procedure TPlayer
.positionChanged (); inline;
2238 procedure TPlayer
.doDamage (v
: Integer);
2240 if (v
<= 0) then exit
;
2241 if (v
> 32767) then v
:= 32767;
2242 Damage(v
, 0, 0, 0, mEDamageType
);
2245 procedure TPlayer
.Damage(value
: Word; SpawnerUID
: Word; vx
, vy
: Integer; t
: Byte);
2249 if (not g_Game_IsClient
) and (not FAlive
) then
2254 // Íåóÿçâèìîñòü íå ñïàñàåò îò ëîâóøåê:
2255 if ((t
= HIT_TRAP
) or (t
= HIT_SELF
)) and (not FGodMode
) then
2257 if not g_Game_IsClient
then
2260 if t
= HIT_TRAP
then
2262 // Ëîâóøêà óáèâàåò ñðàçó:
2264 Kill(K_EXTRAHARDKILL
, SpawnerUID
, t
);
2266 if t
= HIT_SELF
then
2270 Kill(K_SIMPLEKILL
, SpawnerUID
, t
);
2273 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
2274 FMegaRulez
[MR_SUIT
] := 0;
2275 FMegaRulez
[MR_INVUL
] := 0;
2276 FMegaRulez
[MR_INVIS
] := 0;
2281 // Íî îò îñòàëüíîãî ñïàñàåò:
2282 if FMegaRulez
[MR_INVUL
] >= gTime
then
2289 // Åñëè åñòü óðîí ñâîèì, èëè ðàíèë ñàì ñåáÿ, èëè òåáÿ ðàíèë ïðîòèâíèê:
2290 if LongBool(gGameSettings
.Options
and GAME_OPTION_TEAMDAMAGE
) or
2291 (SpawnerUID
= FUID
) or
2292 (not SameTeam(FUID
, SpawnerUID
)) then
2294 FLastSpawnerUID
:= SpawnerUID
;
2296 // Êðîâü (ïóçûðüêè, åñëè â âîäå):
2297 if gBloodCount
> 0 then
2299 c
:= Min(value
, 200)*gBloodCount
+ Random(Min(value
, 200) div 2);
2300 if value
div 4 <= c
then
2301 c
:= c
- (value
div 4)
2305 if (t
= HIT_SOME
) and (vx
= 0) and (vy
= 0) then
2309 HIT_TRAP
, HIT_ACID
, HIT_FLAME
, HIT_SELF
: MakeBloodSimple(c
);
2310 HIT_BFG
, HIT_ROCKET
, HIT_SOME
: MakeBloodVector(c
, vx
, vy
);
2313 if t
= HIT_WATER
then
2314 g_GFX_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
2315 FObj
.Y
+PLAYER_RECT
.Y
-4, value
div 2, 8, 4);
2320 Inc(FDamageBuffer
, value
);
2324 FPain
:= FPain
+ value
;
2327 if g_Game_IsServer
and g_Game_IsNet
then
2329 MH_SEND_PlayerDamage(FUID
, t
, SpawnerUID
, value
, vx
, vy
);
2330 MH_SEND_PlayerStats(FUID
);
2331 MH_SEND_PlayerPos(False, FUID
);
2335 function TPlayer
.Heal(value
: Word; Soft
: Boolean): Boolean;
2338 if g_Game_IsClient
then
2343 if Soft
and (FHealth
< PLAYER_HP_SOFT
) then
2345 IncMax(FHealth
, value
, PLAYER_HP_SOFT
);
2348 if (not Soft
) and (FHealth
< PLAYER_HP_LIMIT
) then
2350 IncMax(FHealth
, value
, PLAYER_HP_LIMIT
);
2354 if Result
and g_Game_IsServer
and g_Game_IsNet
then
2355 MH_SEND_PlayerStats(FUID
);
2358 destructor TPlayer
.Destroy();
2360 if (gPlayer1
<> nil) and (gPlayer1
.FUID
= FUID
) then
2362 if (gPlayer2
<> nil) and (gPlayer2
.FUID
= FUID
) then
2366 FSawSoundIdle
.Free();
2367 FSawSoundHit
.Free();
2368 FSawSoundSelect
.Free();
2369 FFlameSoundOn
.Free();
2370 FFlameSoundOff
.Free();
2371 FFlameSoundWork
.Free();
2372 FJetSoundFly
.Free();
2374 FJetSoundOff
.Free();
2376 if FPunchAnim
<> nil then
2382 procedure TPlayer
.DrawIndicator(Color
: TRGB
);
2384 indX
, indY
, fX
, fY
, fSlope
: Integer;
2394 FObj
.lerp(gLerpFactor
, fX
, fY
);
2395 fSlope
:= nlerp(FSlopeOld
, FObj
.slopeUpLeft
, gLerpFactor
);
2397 case gPlayerIndicatorStyle
of
2400 if g_Texture_Get('TEXTURE_PLAYER_INDICATOR', ID
) then
2402 e_GetTextureSize(ID
, @indW
, @indH
);
2406 if (FObj
.X
+ FObj
.Rect
.X
) < 0 then
2409 indX
:= fX
+ FObj
.Rect
.X
+ FObj
.Rect
.Width
;
2410 indY
:= fY
+ FObj
.Rect
.Y
+ (FObj
.Rect
.Height
- indW
) div 2;
2413 else if (FObj
.X
+ FObj
.Rect
.X
+ FObj
.Rect
.Width
) > Max(gMapInfo
.Width
, gPlayerScreenSize
.X
) then
2416 indX
:= fX
+ FObj
.Rect
.X
- indH
;
2417 indY
:= fY
+ FObj
.Rect
.Y
+ (FObj
.Rect
.Height
- indW
) div 2;
2420 else if (FObj
.Y
- indH
) < 0 then
2423 indX
:= fX
+ FObj
.Rect
.X
+ (FObj
.Rect
.Width
- indW
) div 2;
2424 indY
:= fY
+ FObj
.Rect
.Y
+ FObj
.Rect
.Height
;
2430 indX
:= fX
+ FObj
.Rect
.X
+ (FObj
.Rect
.Width
- indW
) div 2;
2434 indY
:= indY
+ fSlope
;
2435 indX
:= EnsureRange(indX
, 0, Max(gMapInfo
.Width
, gPlayerScreenSize
.X
) - indW
);
2436 indY
:= EnsureRange(indY
, 0, Max(gMapInfo
.Height
, gPlayerScreenSize
.Y
) - indH
);
2440 e_DrawAdv(ID
, indX
, indY
, 0, True, False, indA
, @a
);
2447 e_TextureFontGetSize(gStdFont
, nW
, nH
);
2448 indX
:= fX
+ FObj
.Rect
.X
+ (FObj
.Rect
.Width
- Length(FName
) * nW
) div 2;
2449 indY
:= fY
- nH
+ fSlope
;
2450 e_TextureFontPrintEx(indX
, indY
, FName
, gStdFont
, Color
.R
, Color
.G
, Color
.B
, 1.0, True);
2456 procedure TPlayer
.DrawBubble();
2458 bubX
, bubY
, fX
, fY
: Integer;
2461 Rw
, Gw
, Bw
: SmallInt;
2465 CObj
:= getCameraObj();
2466 CObj
.lerp(gLerpFactor
, fX
, fY
);
2467 // NB: _F_Obj.Rect is used to keep the bubble higher; this is not a mistake
2468 bubX
:= fX
+FObj
.Rect
.X
+ IfThen(FDirection
= TDirection
.D_LEFT
, -4, 18);
2469 bubY
:= fY
+FObj
.Rect
.Y
- 18;
2477 1: // simple textual non-bubble
2479 bubX
:= fX
+FObj
.Rect
.X
- 11;
2480 bubY
:= fY
+FObj
.Rect
.Y
- 17;
2481 e_TextureFontPrint(bubX
, bubY
, '[...]', gStdFont
);
2484 2: // advanced pixel-perfect bubble
2486 if FTeam
= TEAM_RED
then
2489 if FTeam
= TEAM_BLUE
then
2492 3: // colored bubble
2494 Rb
:= FModel
.Color
.R
;
2495 Gb
:= FModel
.Color
.G
;
2496 Bb
:= FModel
.Color
.B
;
2497 Rw
:= Min(Rb
* 2 + 64, 255);
2498 Gw
:= Min(Gb
* 2 + 64, 255);
2499 Bw
:= Min(Bb
* 2 + 64, 255);
2500 if (Abs(Rw
- Rb
) < 32)
2501 or (Abs(Gw
- Gb
) < 32)
2502 or (Abs(Bw
- Bb
) < 32) then
2504 Rb
:= Max(Rw
div 2 - 16, 0);
2505 Gb
:= Max(Gw
div 2 - 16, 0);
2506 Bb
:= Max(Bw
div 2 - 16, 0);
2509 4: // custom textured bubble
2511 if g_Texture_Get('TEXTURE_PLAYER_TALKBUBBLE', ID
) then
2512 if FDirection
= TDirection
.D_RIGHT
then
2513 e_Draw(ID
, bubX
- 6, bubY
- 7, 0, True, False)
2515 e_Draw(ID
, bubX
- 6, bubY
- 7, 0, True, False, TMirrorType
.Horizontal
);
2521 e_DrawQuad(bubX
+ 1, bubY
, bubX
+ 18, bubY
+ 13, Rb
, Gb
, Bb
);
2522 e_DrawQuad(bubX
, bubY
+ 1, bubX
+ 19, bubY
+ 12, Rb
, Gb
, Bb
);
2524 e_DrawFillQuad(bubX
+ 1, bubY
+ 1, bubX
+ 18, bubY
+ 12, Rw
, Gw
, Bw
, 0);
2527 Dot
:= IfThen(FDirection
= TDirection
.D_LEFT
, 14, 5);
2528 e_DrawLine(1, bubX
+ Dot
, bubY
+ 14, bubX
+ Dot
, bubY
+ 16, Rb
, Gb
, Bb
);
2529 e_DrawLine(1, bubX
+ IfThen(FDirection
= TDirection
.D_LEFT
, Dot
- 1, Dot
+ 1), bubY
+ 13, bubX
+ IfThen(FDirection
= TDirection
.D_LEFT
, Dot
- 1, Dot
+ 1), bubY
+ 15, Rw
, Gw
, Bw
);
2530 e_DrawLine(1, bubX
+ IfThen(FDirection
= TDirection
.D_LEFT
, Dot
- 2, Dot
+ 2), bubY
+ 13, bubX
+ IfThen(FDirection
= TDirection
.D_LEFT
, Dot
- 2, Dot
+ 2), bubY
+ 14, Rw
, Gw
, Bw
);
2531 e_DrawLine(1, bubX
+ IfThen(FDirection
= TDirection
.D_LEFT
, Dot
- 3, Dot
+ 3), bubY
+ 13, bubX
+ IfThen(FDirection
= TDirection
.D_LEFT
, Dot
- 3, Dot
+ 3), bubY
+ 13, Rw
, Gw
, Bw
);
2532 e_DrawLine(1, bubX
+ IfThen(FDirection
= TDirection
.D_LEFT
, Dot
- 3, Dot
+ 3), bubY
+ 14, bubX
+ IfThen(FDirection
= TDirection
.D_LEFT
, Dot
- 1, Dot
+ 1), bubY
+ 16, Rb
, Gb
, Bb
);
2536 e_DrawFillQuad(bubX
+ Dot
, bubY
+ 8, bubX
+ Dot
+ 1, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2537 e_DrawFillQuad(bubX
+ Dot
+ 3, bubY
+ 8, bubX
+ Dot
+ 4, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2538 e_DrawFillQuad(bubX
+ Dot
+ 6, bubY
+ 8, bubX
+ Dot
+ 7, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2541 procedure TPlayer
.Draw();
2546 Mirror
: TMirrorType
;
2547 fX
, fY
, fSlope
: Integer;
2549 FObj
.lerp(gLerpFactor
, fX
, fY
);
2550 fSlope
:= nlerp(FSlopeOld
, FObj
.slopeUpLeft
, gLerpFactor
);
2554 if Direction
= TDirection
.D_RIGHT
then
2555 Mirror
:= TMirrorType
.None
2557 Mirror
:= TMirrorType
.Horizontal
;
2559 if FPunchAnim
<> nil then
2561 FPunchAnim
.Draw(fX
+IfThen(Direction
= TDirection
.D_LEFT
, 15-FObj
.Rect
.X
, FObj
.Rect
.X
-15),
2562 fY
+fSlope
+FObj
.Rect
.Y
-11, Mirror
);
2563 if FPunchAnim
.played
then
2570 if (FMegaRulez
[MR_INVUL
] > gTime
) and ((gPlayerDrawn
<> Self
) or (FSpawnInvul
>= gTime
)) then
2571 if g_Texture_Get('TEXTURE_PLAYER_INVULPENTA', ID
) then
2573 e_GetTextureSize(ID
, @w
, @h
);
2574 if FDirection
= TDirection
.D_LEFT
then
2575 e_Draw(ID
, fX
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2)-(w
div 2)+4,
2576 fY
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2)-(h
div 2)-7+fSlope
, 0, True, False)
2578 e_Draw(ID
, fX
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2)-(w
div 2)-2,
2579 fY
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2)-(h
div 2)-7+fSlope
, 0, True, False);
2582 if FMegaRulez
[MR_INVIS
] > gTime
then
2584 if (gPlayerDrawn
<> nil) and ((Self
= gPlayerDrawn
) or
2585 ((FTeam
= gPlayerDrawn
.Team
) and (gGameSettings
.GameMode
<> GM_DM
))) then
2587 if (FMegaRulez
[MR_INVIS
] - gTime
) <= 2100 then
2588 dr
:= not Odd((FMegaRulez
[MR_INVIS
] - gTime
) div 300)
2592 FModel
.Draw(fX
, fY
+fSlope
, 200)
2594 FModel
.Draw(fX
, fY
+fSlope
);
2597 FModel
.Draw(fX
, fY
+fSlope
, 254);
2600 FModel
.Draw(fX
, fY
+fSlope
);
2603 if g_debug_Frames
then
2605 e_DrawQuad(FObj
.X
+FObj
.Rect
.X
,
2607 FObj
.X
+FObj
.Rect
.X
+FObj
.Rect
.Width
-1,
2608 FObj
.Y
+FObj
.Rect
.Y
+FObj
.Rect
.Height
-1,
2612 if (gChatBubble
> 0) and (FKeys
[KEY_CHAT
].Pressed
) and not FGhost
then
2613 if (FMegaRulez
[MR_INVIS
] <= gTime
) or ((gPlayerDrawn
<> nil) and ((Self
= gPlayerDrawn
) or
2614 ((FTeam
= gPlayerDrawn
.Team
) and (gGameSettings
.GameMode
<> GM_DM
)))) then
2616 // e_DrawPoint(5, 335, 288, 255, 0, 0); // DL, UR, DL, UR
2617 if gAimLine
and alive
and
2618 ((Self
= gPlayer1
) or (Self
= gPlayer2
)) then
2623 procedure TPlayer
.DrawAim();
2624 procedure drawCast (sz
: Integer; ax0
, ay0
, ax1
, ay1
: Integer);
2629 {$IFDEF ENABLE_HOLMES}
2630 if isValidViewPort
and (self
= gPlayer1
) then
2632 g_Holmes_plrLaser(ax0
, ay0
, ax1
, ay1
);
2636 e_DrawLine(sz
, ax0
, ay0
, ax1
, ay1
, 255, 0, 0, 96);
2637 if (g_Map_traceToNearestWall(ax0
, ay0
, ax1
, ay1
, @ex
, @ey
) <> nil) then
2639 e_DrawLine(sz
, ax0
, ay0
, ex
, ey
, 0, 255, 0, 96);
2643 e_DrawLine(sz
, ax0
, ay0
, ex
, ey
, 0, 0, 255, 96);
2648 wx
, wy
, xx
, yy
: Integer;
2652 wx
:= FObj
.X
+ WEAPONPOINT
[FDirection
].X
+ IfThen(FDirection
= TDirection
.D_LEFT
, 7, -7);
2653 wy
:= FObj
.Y
+ WEAPONPOINT
[FDirection
].Y
;
2662 1: begin // Chainsaw
2669 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2670 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2671 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2672 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2677 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2678 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2679 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2680 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2682 4: begin // Double Shotgun
2685 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2686 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2687 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2688 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2690 5: begin // Chaingun
2693 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2694 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2695 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2696 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2698 6: begin // Rocket Launcher
2701 if angle
= ANGLE_RIGHTUP
then Inc(angle
, 2);
2702 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2703 if angle
= ANGLE_LEFTUP
then Dec(angle
, 2);
2704 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2706 7: begin // Plasmagun
2709 if angle
= ANGLE_RIGHTUP
then Inc(angle
);
2710 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 3);
2711 if angle
= ANGLE_LEFTUP
then Dec(angle
);
2712 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 3);
2717 if angle
= ANGLE_RIGHTUP
then Inc(angle
, 1);
2718 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 2);
2719 if angle
= ANGLE_LEFTUP
then Dec(angle
, 1);
2720 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 2);
2722 9: begin // Super Chaingun
2725 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2726 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2727 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2728 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2731 xx
:= Trunc(Cos(-DegToRad(angle
)) * len
) + wx
;
2732 yy
:= Trunc(Sin(-DegToRad(angle
)) * len
) + wy
;
2733 {$IF DEFINED(D2F_DEBUG)}
2734 drawCast(sz
, wx
, wy
, xx
, yy
);
2736 e_DrawLine(sz
, wx
, wy
, xx
, yy
, 255, 0, 0, 96);
2740 procedure TPlayer
.DrawGUI();
2743 X
, Y
, SY
, a
, p
, m
: Integer;
2747 stat
: TPlayerStatArray
;
2749 X
:= gPlayerScreenSize
.X
;
2750 SY
:= gPlayerScreenSize
.Y
;
2753 if gShowGoals
and (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
2755 if gGameSettings
.GameMode
= GM_CTF
then
2759 if gGameSettings
.GameMode
= GM_CTF
then
2761 s
:= 'TEXTURE_PLAYER_REDFLAG';
2762 if gFlags
[FLAG_RED
].State
= FLAG_STATE_CAPTURED
then
2763 s
:= 'TEXTURE_PLAYER_REDFLAG_S';
2764 if gFlags
[FLAG_RED
].State
= FLAG_STATE_DROPPED
then
2765 s
:= 'TEXTURE_PLAYER_REDFLAG_D';
2766 if g_Texture_Get(s
, ID
) then
2767 e_Draw(ID
, X
-16-32, 240-72-4, 0, True, False);
2770 s
:= IntToStr(gTeamStat
[TEAM_RED
].Goals
);
2771 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2772 e_CharFont_PrintEx(gMenuFont
, X
-16-a
-tw
, 240-72-4, s
, TEAMCOLOR
[TEAM_RED
]);
2774 if gGameSettings
.GameMode
= GM_CTF
then
2776 s
:= 'TEXTURE_PLAYER_BLUEFLAG';
2777 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_CAPTURED
then
2778 s
:= 'TEXTURE_PLAYER_BLUEFLAG_S';
2779 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_DROPPED
then
2780 s
:= 'TEXTURE_PLAYER_BLUEFLAG_D';
2781 if g_Texture_Get(s
, ID
) then
2782 e_Draw(ID
, X
-16-32, 240-32-4, 0, True, False);
2785 s
:= IntToStr(gTeamStat
[TEAM_BLUE
].Goals
);
2786 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2787 e_CharFont_PrintEx(gMenuFont
, X
-16-a
-tw
, 240-32-4, s
, TEAMCOLOR
[TEAM_BLUE
]);
2790 if g_Texture_Get('TEXTURE_PLAYER_HUDBG', ID
) then
2791 e_DrawFill(ID
, X
, 0, 1, (gPlayerScreenSize
.Y
div 256)+IfThen(gPlayerScreenSize
.Y
mod 256 > 0, 1, 0),
2794 if g_Texture_Get('TEXTURE_PLAYER_HUD', ID
) then
2795 e_Draw(ID
, X
+2, Y
, 0, True, False);
2797 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
2801 s
:= IntToStr(Frags
);
2802 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2803 e_CharFont_PrintEx(gMenuFont
, X
-16-tw
, Y
, s
, _RGB(255, 0, 0));
2808 stat
:= g_Player_GetStats();
2813 for a
:= 0 to High(stat
) do
2814 if stat
[a
].Name
<> Name
then
2816 if stat
[a
].Frags
> m
then m
:= stat
[a
].Frags
;
2817 if stat
[a
].Frags
> Frags
then p
:= p
+1;
2821 s
:= IntToStr(p
)+' / '+IntToStr(Length(stat
))+' ';
2822 if Frags
>= m
then s
:= s
+'+' else s
:= s
+'-';
2823 s
:= s
+IntToStr(Abs(Frags
-m
));
2825 e_CharFont_GetSize(gMenuSmallFont
, s
, tw
, th
);
2826 e_CharFont_PrintEx(gMenuSmallFont
, X
-16-tw
, Y
+32, s
, _RGB(255, 0, 0));
2829 if gLMSRespawn
> LMS_RESPAWN_NONE
then
2831 s
:= _lc
[I_GAME_WARMUP
];
2832 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2833 s
:= s
+ ': ' + IntToStr((gLMSRespawnTime
- gTime
) div 1000);
2834 e_CharFont_PrintEx(gMenuFont
, X
-64-tw
, SY
-32, s
, _RGB(0, 255, 0));
2836 else if gShowLives
and (gGameSettings
.MaxLives
> 0) then
2838 s
:= IntToStr(Lives
);
2839 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2840 e_CharFont_PrintEx(gMenuFont
, X
-16-tw
, SY
-32, s
, _RGB(0, 255, 0));
2844 e_CharFont_GetSize(gMenuSmallFont
, FName
, tw
, th
);
2845 e_CharFont_PrintEx(gMenuSmallFont
, X
+98-(tw
div 2), Y
+8, FName
, _RGB(255, 0, 0));
2847 if R_BERSERK
in FRulez
then
2848 e_Draw(gItemsTexturesID
[ITEM_MEDKIT_BLACK
], X
+37, Y
+45, 0, True, False)
2850 e_Draw(gItemsTexturesID
[ITEM_MEDKIT_LARGE
], X
+37, Y
+45, 0, True, False);
2852 if g_Texture_Get('TEXTURE_PLAYER_ARMORHUD', ID
) then
2853 e_Draw(ID
, X
+36, Y
+77, 0, True, False);
2855 s
:= IntToStr(IfThen(FHealth
> 0, FHealth
, 0));
2856 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2857 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+40, s
, _RGB(255, 0, 0));
2859 s
:= IntToStr(FArmor
);
2860 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2861 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+68, s
, _RGB(255, 0, 0));
2863 s
:= IntToStr(GetAmmoByWeapon(FCurrWeap
));
2869 ID
:= gItemsTexturesID
[ITEM_WEAPON_KASTET
];
2874 ID
:= gItemsTexturesID
[ITEM_WEAPON_SAW
];
2876 WEAPON_PISTOL
: ID
:= gItemsTexturesID
[ITEM_WEAPON_PISTOL
];
2877 WEAPON_CHAINGUN
: ID
:= gItemsTexturesID
[ITEM_WEAPON_CHAINGUN
];
2878 WEAPON_SHOTGUN1
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SHOTGUN1
];
2879 WEAPON_SHOTGUN2
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SHOTGUN2
];
2880 WEAPON_SUPERPULEMET
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SUPERPULEMET
];
2881 WEAPON_ROCKETLAUNCHER
: ID
:= gItemsTexturesID
[ITEM_WEAPON_ROCKETLAUNCHER
];
2882 WEAPON_PLASMA
: ID
:= gItemsTexturesID
[ITEM_WEAPON_PLASMA
];
2883 WEAPON_BFG
: ID
:= gItemsTexturesID
[ITEM_WEAPON_BFG
];
2884 WEAPON_FLAMETHROWER
: ID
:= gItemsTexturesID
[ITEM_WEAPON_FLAMETHROWER
];
2887 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2888 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+158, s
, _RGB(255, 0, 0));
2889 e_Draw(ID
, X
+20, Y
+160, 0, True, False);
2891 if R_KEY_RED
in FRulez
then
2892 e_Draw(gItemsTexturesID
[ITEM_KEY_RED
], X
+78, Y
+214, 0, True, False);
2894 if R_KEY_GREEN
in FRulez
then
2895 e_Draw(gItemsTexturesID
[ITEM_KEY_GREEN
], X
+95, Y
+214, 0, True, False);
2897 if R_KEY_BLUE
in FRulez
then
2898 e_Draw(gItemsTexturesID
[ITEM_KEY_BLUE
], X
+112, Y
+214, 0, True, False);
2900 if FJetFuel
> 0 then
2902 if g_Texture_Get('TEXTURE_PLAYER_HUDAIR', ID
) then
2903 e_Draw(ID
, X
+2, Y
+116, 0, True, False);
2904 if g_Texture_Get('TEXTURE_PLAYER_HUDJET', ID
) then
2905 e_Draw(ID
, X
+2, Y
+126, 0, True, False);
2906 e_DrawLine(4, X
+16, Y
+122, X
+16+Trunc(168*IfThen(FAir
> 0, FAir
, 0)/AIR_MAX
), Y
+122, 0, 0, 196);
2907 e_DrawLine(4, X
+16, Y
+132, X
+16+Trunc(168*FJetFuel
/JET_MAX
), Y
+132, 208, 0, 0);
2911 if g_Texture_Get('TEXTURE_PLAYER_HUDAIR', ID
) then
2912 e_Draw(ID
, X
+2, Y
+124, 0, True, False);
2913 e_DrawLine(4, X
+16, Y
+130, X
+16+Trunc(168*IfThen(FAir
> 0, FAir
, 0)/AIR_MAX
), Y
+130, 0, 0, 196);
2916 if gShowPing
and g_Game_IsClient
then
2918 s
:= _lc
[I_GAME_PING_HUD
] + IntToStr(NetPeer
.lastRoundTripTime
) + _lc
[I_NET_SLIST_PING_MS
];
2919 e_TextureFontPrint(X
+ 4, Y
+ 242, s
, gStdFont
);
2925 e_TextureFontPrint(X
+ 4, Y
+ 242, _lc
[I_PLAYER_SPECT
], gStdFont
);
2926 e_TextureFontPrint(X
+ 4, Y
+ 258, _lc
[I_PLAYER_SPECT2
], gStdFont
);
2927 e_TextureFontPrint(X
+ 4, Y
+ 274, _lc
[I_PLAYER_SPECT1
], gStdFont
);
2930 e_TextureFontGetSize(gStdFont
, cw
, ch
);
2931 s
:= _lc
[I_PLAYER_SPECT4
];
2932 e_TextureFontPrintEx(gScreenWidth
div 2 - cw
*(Length(s
) div 2),
2933 gScreenHeight
-4-ch
, s
, gStdFont
, 255, 255, 255, 1, True);
2934 e_TextureFontPrint(X
+ 4, Y
+ 290, _lc
[I_PLAYER_SPECT1S
], gStdFont
);
2940 procedure TPlayer
.DrawRulez();
2944 // Ïðè âçÿòèè íåóÿçâèìîñòè ðèñóåòñÿ èíâåðñèîííûé áåëûé ôîí
2945 if (FMegaRulez
[MR_INVUL
] >= gTime
) and (FSpawnInvul
< gTime
) then
2947 if (FMegaRulez
[MR_INVUL
]-gTime
) <= 2100 then
2948 dr
:= not Odd((FMegaRulez
[MR_INVUL
]-gTime
) div 300)
2953 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2954 191, 191, 191, 0, TBlending
.Invert
);
2957 // Ïðè âçÿòèè çàùèòíîãî êîñòþìà ðèñóåòñÿ çåëåíîâàòûé ôîí
2958 if FMegaRulez
[MR_SUIT
] >= gTime
then
2960 if (FMegaRulez
[MR_SUIT
]-gTime
) <= 2100 then
2961 dr
:= not Odd((FMegaRulez
[MR_SUIT
]-gTime
) div 300)
2966 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2967 0, 96, 0, 200, TBlending
.None
);
2970 // Ïðè âçÿòèè áåðñåðêà ðèñóåòñÿ êðàñíîâàòûé ôîí
2971 if (FBerserk
>= 0) and (LongWord(FBerserk
) >= gTime
) and (gFlash
= 2) then
2973 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2974 255, 0, 0, 200, TBlending
.None
);
2978 procedure TPlayer
.DrawPain();
2982 if FPain
= 0 then Exit
;
2986 if a
< 15 then h
:= 0
2987 else if a
< 35 then h
:= 1
2988 else if a
< 55 then h
:= 2
2989 else if a
< 75 then h
:= 3
2990 else if a
< 95 then h
:= 4
2993 //if a > 255 then a := 255;
2995 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1, 255, 0, 0, 255-h
*50);
2996 //e_DrawFillQuad(0, 0, gPlayerScreenSize.X-1, gPlayerScreenSize.Y-1, 255-min(128, a), 255-a, 255-a, 0, B_FILTER);
2999 procedure TPlayer
.DrawPickup();
3003 if FPickup
= 0 then Exit
;
3007 if a
< 15 then h
:= 1
3008 else if a
< 35 then h
:= 2
3009 else if a
< 55 then h
:= 3
3010 else if a
< 75 then h
:= 4
3013 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1, 150, 200, 150, 255-h
*50);
3016 procedure TPlayer
.DoPunch();
3021 if FPunchAnim
<> nil then begin
3026 st
:= 'FRAMES_PUNCH';
3027 if R_BERSERK
in FRulez
then
3028 st
:= st
+ '_BERSERK';
3029 if FKeys
[KEY_UP
].Pressed
then
3031 else if FKeys
[KEY_DOWN
].Pressed
then
3033 g_Frames_Get(id
, st
);
3034 FPunchAnim
:= TAnimation
.Create(id
, False, 1);
3037 procedure TPlayer
.Fire();
3039 f
, DidFire
: Boolean;
3040 wx
, wy
, xd
, yd
: Integer;
3043 if g_Game_IsClient
then Exit
;
3044 // FBFGFireCounter - âðåìÿ ïåðåä âûñòðåëîì (äëÿ BFG)
3045 // FReloading - âðåìÿ ïîñëå âûñòðåëà (äëÿ âñåãî)
3053 if FReloading
[FCurrWeap
] <> 0 then Exit
;
3058 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
3059 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
3060 xd
:= wx
+IfThen(FDirection
= TDirection
.D_LEFT
, -30, 30);
3061 yd
:= wy
+firediry();
3067 if R_BERSERK
in FRulez
then
3069 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
3070 locobj
.X
:= FObj
.X
+FObj
.Rect
.X
;
3071 locobj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
3074 locobj
.rect
.Width
:= 39;
3075 locobj
.rect
.Height
:= 52;
3076 locobj
.Vel
.X
:= (xd
-wx
) div 2;
3077 locobj
.Vel
.Y
:= (yd
-wy
) div 2;
3078 locobj
.Accel
.X
:= xd
-wx
;
3079 locobj
.Accel
.y
:= yd
-wy
;
3081 if g_Weapon_Hit(@locobj
, 50, FUID
, HIT_SOME
) <> 0 then
3082 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
3084 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
3086 if (gFlash
= 1) and (FPain
< 50) then FPain
:= min(FPain
+ 25, 50);
3090 g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
3094 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3099 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
3100 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
3102 FSawSoundSelect
.Stop();
3104 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
3106 else if not FSawSoundHit
.IsPlaying() then
3108 FSawSoundSelect
.Stop();
3109 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
3112 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3118 if FAmmo
[A_BULLETS
] > 0 then
3120 g_Weapon_pistol(wx
, wy
, xd
, yd
, FUID
);
3121 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3122 Dec(FAmmo
[A_BULLETS
]);
3123 FFireAngle
:= FAngle
;
3126 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
3127 GameVelX
, GameVelY
-2, SHELL_BULLET
);
3131 if FAmmo
[A_SHELLS
] > 0 then
3133 g_Weapon_shotgun(wx
, wy
, xd
, yd
, FUID
);
3134 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', wx
, wy
);
3135 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3136 Dec(FAmmo
[A_SHELLS
]);
3137 FFireAngle
:= FAngle
;
3141 FShellType
:= SHELL_SHELL
;
3145 if FAmmo
[A_SHELLS
] >= 2 then
3147 g_Weapon_dshotgun(wx
, wy
, xd
, yd
, FUID
);
3148 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3149 Dec(FAmmo
[A_SHELLS
], 2);
3150 FFireAngle
:= FAngle
;
3154 FShellType
:= SHELL_DBLSHELL
;
3158 if FAmmo
[A_BULLETS
] > 0 then
3160 g_Weapon_mgun(wx
, wy
, xd
, yd
, FUID
);
3161 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', wx
, wy
);
3162 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3163 Dec(FAmmo
[A_BULLETS
]);
3164 FFireAngle
:= FAngle
;
3167 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
3168 GameVelX
, GameVelY
-2, SHELL_BULLET
);
3171 WEAPON_ROCKETLAUNCHER
:
3172 if FAmmo
[A_ROCKETS
] > 0 then
3174 g_Weapon_rocket(wx
, wy
, xd
, yd
, FUID
);
3175 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3176 Dec(FAmmo
[A_ROCKETS
]);
3177 FFireAngle
:= FAngle
;
3183 if FAmmo
[A_CELLS
] > 0 then
3185 g_Weapon_plasma(wx
, wy
, xd
, yd
, FUID
);
3186 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3187 Dec(FAmmo
[A_CELLS
]);
3188 FFireAngle
:= FAngle
;
3194 if (FAmmo
[A_CELLS
] >= 40) and (FBFGFireCounter
= -1) then
3196 FBFGFireCounter
:= 17;
3197 if not FNoReload
then
3198 g_Sound_PlayExAt('SOUND_WEAPON_STARTFIREBFG', FObj
.X
, FObj
.Y
);
3199 Dec(FAmmo
[A_CELLS
], 40);
3203 WEAPON_SUPERPULEMET
:
3204 if FAmmo
[A_SHELLS
] > 0 then
3206 g_Weapon_shotgun(wx
, wy
, xd
, yd
, FUID
);
3207 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', wx
, wy
);
3208 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3209 Dec(FAmmo
[A_SHELLS
]);
3210 FFireAngle
:= FAngle
;
3213 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
3214 GameVelX
, GameVelY
-2, SHELL_SHELL
);
3217 WEAPON_FLAMETHROWER
:
3218 if FAmmo
[A_FUEL
] > 0 then
3220 g_Weapon_flame(wx
, wy
, xd
, yd
, FUID
);
3222 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3224 FFireAngle
:= FAngle
;
3231 if g_Game_IsNet
and g_Game_IsServer
then MH_SEND_PlayerStats(FUID
);
3235 if g_Game_IsNet
then
3239 if FCurrWeap
<> WEAPON_BFG
then
3240 MH_SEND_PlayerFire(FUID
, FCurrWeap
, wx
, wy
, xd
, yd
, LastShotID
)
3242 if not FNoReload
then
3243 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_WEAPON_STARTFIREBFG');
3246 MH_SEND_PlayerStats(FUID
);
3251 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
3252 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
3253 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
3256 function TPlayer
.GetAmmoByWeapon(Weapon
: Byte): Word;
3259 WEAPON_PISTOL
, WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
];
3260 WEAPON_SHOTGUN1
, WEAPON_SHOTGUN2
, WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
];
3261 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
];
3262 WEAPON_PLASMA
, WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
];
3263 WEAPON_FLAMETHROWER
: Result
:= FAmmo
[A_FUEL
];
3268 function TPlayer
.HeadInLiquid(XInc
, YInc
: Integer): Boolean;
3270 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
+XInc
, FObj
.Y
+PLAYER_HEADRECT
.Y
+YInc
,
3271 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
3272 PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, True);
3275 procedure TPlayer
.FlamerOn
;
3277 FFlameSoundOff
.Stop();
3278 FFlameSoundOff
.SetPosition(0);
3281 if (not FFlameSoundOn
.IsPlaying()) and (not FFlameSoundWork
.IsPlaying()) then
3282 FFlameSoundWork
.PlayAt(FObj
.X
, FObj
.Y
);
3286 FFlameSoundOn
.PlayAt(FObj
.X
, FObj
.Y
);
3291 procedure TPlayer
.FlamerOff
;
3295 FFlameSoundOn
.Stop();
3296 FFlameSoundOn
.SetPosition(0);
3297 FFlameSoundWork
.Stop();
3298 FFlameSoundWork
.SetPosition(0);
3299 FFlameSoundOff
.PlayAt(FObj
.X
, FObj
.Y
);
3304 procedure TPlayer
.JetpackOn
;
3308 FJetSoundOn
.SetPosition(0);
3309 FJetSoundOn
.PlayAt(FObj
.X
, FObj
.Y
);
3313 procedure TPlayer
.JetpackOff
;
3317 FJetSoundOff
.SetPosition(0);
3318 FJetSoundOff
.PlayAt(FObj
.X
, FObj
.Y
);
3321 procedure TPlayer
.CatchFire(Attacker
: Word; Timeout
: Integer = PLAYER_BURN_TIME
);
3323 if Timeout
<= 0 then
3325 if (FMegaRulez
[MR_SUIT
] > gTime
) or (FMegaRulez
[MR_INVUL
] > gTime
) then
3326 exit
; // Íå çàãîðàåìñÿ êîãäà åñòü çàùèòà
3327 if g_Obj_CollidePanel(@FObj
, 0, 0, PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
) then
3328 exit
; // Íå ïîäãîðàåì â âîäå íà âñÿêèé ñëó÷àé
3329 if FFireTime
<= 0 then
3330 g_Sound_PlayExAt('SOUND_IGNITE', FObj
.X
, FObj
.Y
);
3331 FFireTime
:= Timeout
;
3332 FFireAttacker
:= Attacker
;
3333 if g_Game_IsNet
and g_Game_IsServer
then
3334 MH_SEND_PlayerStats(FUID
);
3337 procedure TPlayer
.Jump();
3339 if gFly
or FJetpack
then
3341 // Ïîëåò (÷èò-êîä èëè äæåòïàê):
3342 if FObj
.Vel
.Y
> -VEL_FLY
then
3343 FObj
.Vel
.Y
:= FObj
.Vel
.Y
- 3;
3346 if FJetFuel
> 0 then
3348 if (FJetFuel
< 1) and g_Game_IsServer
then
3352 if g_Game_IsNet
then
3353 MH_SEND_PlayerStats(FUID
);
3359 // Íå âêëþ÷àòü äæåòïàê â ðåæèìå ïðîõîæäåíèÿ ñêâîçü ñòåíû
3361 FCanJetpack
:= False;
3363 // Ïðûãàåì èëè âñïëûâàåì:
3364 if (CollideLevel(0, 1) or
3365 g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
+36, PLAYER_RECT
.Width
,
3366 PLAYER_RECT
.Height
-33, PANEL_STEP
, False)
3367 ) and (FObj
.Accel
.Y
= 0) then // Íå ïðûãàòü, åñëè åñòü âåðòèêàëüíîå óñêîðåíèå
3369 FObj
.Vel
.Y
:= -VEL_JUMP
;
3370 FCanJetpack
:= False;
3374 if BodyInLiquid(0, 0) then
3375 FObj
.Vel
.Y
:= -VEL_SW
3376 else if (FJetFuel
> 0) and FCanJetpack
and
3377 g_Game_IsServer
and (not g_Obj_CollideLiquid(@FObj
, 0, 0)) then
3381 if g_Game_IsNet
then
3382 MH_SEND_PlayerStats(FUID
);
3387 procedure TPlayer
.Kill(KillType
: Byte; SpawnerUID
: Word; t
: Byte);
3389 a
, i
, k
, ab
, ar
: Byte;
3393 srv
, netsrv
: Boolean;
3399 procedure PushItem(t
: Byte);
3403 id
:= g_Items_Create(FObj
.X
, FObj
.Y
, t
, True, False);
3404 it
:= g_Items_ByIdx(id
);
3405 if KillType
= K_EXTRAHARDKILL
then // -7..+7; -8..0
3407 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-7+Random(15),
3408 (FObj
.Vel
.Y
div 2)-Random(9));
3409 it
.positionChanged(); // this updates spatial accelerators
3413 if KillType
= K_HARDKILL
then // -5..+5; -5..0
3415 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-5+Random(11),
3416 (FObj
.Vel
.Y
div 2)-Random(6));
3418 else // -3..+3; -3..0
3420 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-3+Random(7),
3421 (FObj
.Vel
.Y
div 2)-Random(4));
3423 it
.positionChanged(); // this updates spatial accelerators
3426 if g_Game_IsNet
and g_Game_IsServer
then
3427 MH_SEND_ItemSpawn(True, id
);
3431 DoFrags
:= (gGameSettings
.MaxLives
= 0) or (gGameSettings
.GameMode
= GM_COOP
);
3432 Srv
:= g_Game_IsServer
;
3433 Netsrv
:= g_Game_IsServer
and g_Game_IsNet
;
3434 if Srv
then FDeath
:= FDeath
+ 1;
3439 if not FPhysics
then
3445 if (gGameSettings
.MaxLives
> 0) and Srv
and (gLMSRespawn
= LMS_RESPAWN_NONE
) then
3447 if FLives
> 0 then FLives
:= FLives
- 1;
3448 if FLives
= 0 then FNoRespawn
:= True;
3451 // Íîìåð òèïà ñìåðòè:
3454 K_SIMPLEKILL
: a
:= 1;
3456 K_EXTRAHARDKILL
: a
:= 3;
3461 if not FModel
.PlaySound(MODELSOUND_DIE
, a
, FObj
.X
, FObj
.Y
) then
3463 if FModel
.PlaySound(MODELSOUND_DIE
, i
, FObj
.X
, FObj
.Y
) then
3470 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN1
;
3472 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN2
;
3473 K_EXTRAHARDKILL
, K_FALLKILL
:
3474 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN3
;
3477 // Ïåðåêëþ÷àåì ñîñòîÿíèå:
3481 K_HARDKILL
, K_EXTRAHARDKILL
:
3485 // Ðåàêöèÿ ìîíñòðîâ íà ñìåðòü èãðîêà:
3486 if (KillType
<> K_FALLKILL
) and (Srv
) then
3487 g_Monsters_killedp();
3489 if SpawnerUID
= FUID
then
3491 if Srv
and (DoFrags
or (gGameSettings
.GameMode
= GM_TDM
)) then
3496 g_Console_Add(Format(_lc
[I_PLAYER_KILL_SELF
], [FName
]), True);
3499 if g_GetUIDType(SpawnerUID
) = UID_PLAYER
then
3500 begin // Óáèò äðóãèì èãðîêîì
3501 KP
:= g_Player_Get(SpawnerUID
);
3502 if (KP
<> nil) and Srv
then
3504 if (DoFrags
or (gGameSettings
.GameMode
= GM_TDM
)) then
3505 if SameTeam(FUID
, SpawnerUID
) then
3515 if (gGameSettings
.GameMode
= GM_TDM
) and DoFrags
then
3516 Inc(gTeamStat
[KP
.Team
].Goals
,
3517 IfThen(SameTeam(FUID
, SpawnerUID
), -1, 1));
3519 if netsrv
then MH_SEND_PlayerStats(SpawnerUID
);
3522 plr
:= g_Player_Get(SpawnerUID
);
3530 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_2
],
3534 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_1
],
3538 g_Console_Add(Format(_lc
[I_PLAYER_KILL
],
3543 else if g_GetUIDType(SpawnerUID
) = UID_MONSTER
then
3544 begin // Óáèò ìîíñòðîì
3545 mon
:= g_Monsters_ByUID(SpawnerUID
);
3549 s
:= g_Mons_GetKilledByTypeId(mon
.MonsterType
);
3553 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_2
],
3557 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_1
],
3561 g_Console_Add(Format(_lc
[I_PLAYER_KILL
],
3566 else // Îñîáûå òèïû ñìåðòè
3569 HIT_SELF
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_SELF
], [FName
]), True);
3570 HIT_FALL
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_FALL
], [FName
]), True);
3571 HIT_WATER
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_WATER
], [FName
]), True);
3572 HIT_ACID
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_ACID
], [FName
]), True);
3573 HIT_TRAP
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_TRAP
], [FName
]), True);
3574 else g_Console_Add(Format(_lc
[I_PLAYER_DIED
], [FName
]), True);
3580 for a
:= WP_FIRST
to WP_LAST
do
3584 WEAPON_SAW
: i
:= ITEM_WEAPON_SAW
;
3585 WEAPON_SHOTGUN1
: i
:= ITEM_WEAPON_SHOTGUN1
;
3586 WEAPON_SHOTGUN2
: i
:= ITEM_WEAPON_SHOTGUN2
;
3587 WEAPON_CHAINGUN
: i
:= ITEM_WEAPON_CHAINGUN
;
3588 WEAPON_ROCKETLAUNCHER
: i
:= ITEM_WEAPON_ROCKETLAUNCHER
;
3589 WEAPON_PLASMA
: i
:= ITEM_WEAPON_PLASMA
;
3590 WEAPON_BFG
: i
:= ITEM_WEAPON_BFG
;
3591 WEAPON_SUPERPULEMET
: i
:= ITEM_WEAPON_SUPERPULEMET
;
3592 WEAPON_FLAMETHROWER
: i
:= ITEM_WEAPON_FLAMETHROWER
;
3601 if R_ITEM_BACKPACK
in FRulez
then
3602 PushItem(ITEM_AMMO_BACKPACK
);
3604 // Âûáðîñ ðàêåòíîãî ðàíöà:
3605 if FJetFuel
> 0 then
3606 PushItem(ITEM_JETPACK
);
3609 if (not (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
])) or
3610 (not LongBool(gGameSettings
.Options
and GAME_OPTION_DMKEYS
)) then
3612 if R_KEY_RED
in FRulez
then
3613 PushItem(ITEM_KEY_RED
);
3615 if R_KEY_GREEN
in FRulez
then
3616 PushItem(ITEM_KEY_GREEN
);
3618 if R_KEY_BLUE
in FRulez
then
3619 PushItem(ITEM_KEY_BLUE
);
3623 DropFlag(KillType
= K_FALLKILL
);
3626 FCorpse
:= g_Player_CreateCorpse(Self
);
3628 if Srv
and (gGameSettings
.MaxLives
> 0) and FNoRespawn
and
3629 (gLMSRespawn
= LMS_RESPAWN_NONE
) then
3635 for i
:= Low(gPlayers
) to High(gPlayers
) do
3637 if gPlayers
[i
] = nil then continue
;
3638 if (not gPlayers
[i
].FNoRespawn
) and (not gPlayers
[i
].FSpectator
) then
3641 if gPlayers
[i
].FTeam
= TEAM_RED
then Inc(ar
)
3642 else if gPlayers
[i
].FTeam
= TEAM_BLUE
then Inc(ab
);
3647 OldLR
:= gLMSRespawn
;
3648 if (gGameSettings
.GameMode
= GM_COOP
) then
3652 // everyone is dead, restart the map
3653 g_Game_Message(_lc
[I_MESSAGE_LMS_LOSE
], 144);
3655 MH_SEND_GameEvent(NET_EV_LMS_LOSE
);
3656 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3657 gLMSRespawnTime
:= gTime
+ 5000;
3659 else if (a
= 1) then
3661 if (gPlayers
[k
] <> nil) and not (gPlayers
[k
] is TBot
) then
3662 if (gPlayers
[k
] = gPlayer1
) or
3663 (gPlayers
[k
] = gPlayer2
) then
3664 g_Console_Add('*** ' + _lc
[I_MESSAGE_LMS_SURVIVOR
] + ' ***', True)
3665 else if Netsrv
and (gPlayers
[k
].FClientID
>= 0) then
3666 MH_SEND_GameEvent(NET_EV_LMS_SURVIVOR
, 0, 'N', gPlayers
[k
].FClientID
);
3669 else if (gGameSettings
.GameMode
= GM_TDM
) then
3671 if (ab
= 0) and (ar
<> 0) then
3674 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 144);
3676 MH_SEND_GameEvent(NET_EV_TLMS_WIN
, TEAM_RED
);
3677 Inc(gTeamStat
[TEAM_RED
].Goals
);
3678 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3679 gLMSRespawnTime
:= gTime
+ 5000;
3681 else if (ar
= 0) and (ab
<> 0) then
3684 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 144);
3686 MH_SEND_GameEvent(NET_EV_TLMS_WIN
, TEAM_BLUE
);
3687 Inc(gTeamStat
[TEAM_BLUE
].Goals
);
3688 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3689 gLMSRespawnTime
:= gTime
+ 5000;
3691 else if (ar
= 0) and (ab
= 0) then
3694 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
3696 MH_SEND_GameEvent(NET_EV_LMS_DRAW
, 0, FName
);
3697 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3698 gLMSRespawnTime
:= gTime
+ 5000;
3701 else if (gGameSettings
.GameMode
= GM_DM
) then
3705 if gPlayers
[k
] <> nil then
3708 // survivor is the winner
3709 g_Game_Message(Format(_lc
[I_MESSAGE_LMS_WIN
], [AnsiUpperCase(FName
)]), 144);
3711 MH_SEND_GameEvent(NET_EV_LMS_WIN
, 0, FName
);
3714 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3715 gLMSRespawnTime
:= gTime
+ 5000;
3717 else if (a
= 0) then
3719 // everyone is dead, restart the map
3720 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
3722 MH_SEND_GameEvent(NET_EV_LMS_DRAW
, 0, FName
);
3723 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3724 gLMSRespawnTime
:= gTime
+ 5000;
3727 if srv
and (OldLR
= LMS_RESPAWN_NONE
) and (gLMSRespawn
> LMS_RESPAWN_NONE
) then
3729 if NetMode
= NET_SERVER
then
3730 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
)
3732 g_Console_Add(Format(_lc
[I_MSG_WARMUP_START
], [(gLMSRespawnTime
- gTime
) div 1000]), True);
3738 MH_SEND_PlayerStats(FUID
);
3739 MH_SEND_PlayerDeath(FUID
, KillType
, t
, SpawnerUID
);
3740 if gGameSettings
.GameMode
= GM_TDM
then MH_SEND_GameStats
;
3743 if srv
and FNoRespawn
then Spectate(True);
3744 FWantsInGame
:= True;
3747 function TPlayer
.BodyInLiquid(XInc
, YInc
: Integer): Boolean;
3749 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
, PLAYER_RECT
.Width
,
3750 PLAYER_RECT
.Height
-20, PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, False);
3753 function TPlayer
.BodyInAcid(XInc
, YInc
: Integer): Boolean;
3755 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
, PLAYER_RECT
.Width
,
3756 PLAYER_RECT
.Height
-20, PANEL_ACID1
or PANEL_ACID2
, False);
3759 procedure TPlayer
.MakeBloodSimple(Count
: Word);
3761 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)+8,
3762 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3763 Count
div 2, 3, -1, 16, (PLAYER_RECT
.Height
*2 div 3),
3764 FModel
.Blood
.R
, FModel
.Blood
.G
, FModel
.Blood
.B
, FModel
.Blood
.Kind
);
3765 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-8,
3766 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3767 Count
div 2, -3, -1, 16, (PLAYER_RECT
.Height
*2) div 3,
3768 FModel
.Blood
.R
, FModel
.Blood
.G
, FModel
.Blood
.B
, FModel
.Blood
.Kind
);
3771 procedure TPlayer
.MakeBloodVector(Count
: Word; VelX
, VelY
: Integer);
3773 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
3774 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3775 Count
, VelX
, VelY
, 16, (PLAYER_RECT
.Height
*2) div 3,
3776 FModel
.Blood
.R
, FModel
.Blood
.G
, FModel
.Blood
.B
, FModel
.Blood
.Kind
);
3779 procedure TPlayer
.ProcessWeaponAction(Action
: Byte);
3781 if g_Game_IsClient
then Exit
;
3783 WP_PREV
: PrevWeapon();
3784 WP_NEXT
: NextWeapon();
3788 procedure TPlayer
.QueueWeaponSwitch(Weapon
: Byte);
3790 if g_Game_IsClient
then Exit
;
3791 if Weapon
> High(FWeapon
) then Exit
;
3792 FNextWeap
:= FNextWeap
or (1 shl Weapon
);
3795 procedure TPlayer
.resetWeaponQueue ();
3798 FNextWeapDelay
:= 0;
3801 function TPlayer
.hasAmmoForWeapon (weapon
: Byte): Boolean;
3805 WEAPON_KASTET
, WEAPON_SAW
: result
:= true;
3806 WEAPON_SHOTGUN1
, WEAPON_SHOTGUN2
, WEAPON_SUPERPULEMET
: result
:= (FAmmo
[A_SHELLS
] > 0);
3807 WEAPON_PISTOL
, WEAPON_CHAINGUN
: result
:= (FAmmo
[A_BULLETS
] > 0);
3808 WEAPON_ROCKETLAUNCHER
: result
:= (FAmmo
[A_ROCKETS
] > 0);
3809 WEAPON_PLASMA
, WEAPON_BFG
: result
:= (FAmmo
[A_CELLS
] > 0);
3810 WEAPON_FLAMETHROWER
: result
:= (FAmmo
[A_FUEL
] > 0);
3811 else result
:= (weapon
< length(FWeapon
));
3815 // return 255 for "no switch"
3816 function TPlayer
.getNextWeaponIndex (): Byte;
3819 wantThisWeapon
: array[0..64] of Boolean;
3820 wwc
: Integer = 0; //HACK!
3823 result
:= 255; // default result: "no switch"
3824 // had weapon cycling on previous frame? remove that flag
3825 if (FNextWeap
and $2000) <> 0 then
3827 FNextWeap
:= FNextWeap
and $1FFF;
3828 FNextWeapDelay
:= 0;
3830 // cycling has priority
3831 if (FNextWeap
and $C000) <> 0 then
3833 if (FNextWeap
and $8000) <> 0 then
3837 FNextWeap
:= FNextWeap
or $2000; // we need this
3838 if FNextWeapDelay
> 0 then
3839 exit
; // cooldown time
3841 for i
:= 0 to High(FWeapon
) do
3843 cwi
:= (cwi
+length(FWeapon
)+dir
) mod length(FWeapon
);
3844 if FWeapon
[cwi
] then
3846 //e_WriteLog(Format(' SWITCH: cur=%d; new=%d', [FCurrWeap, cwi]), MSG_WARNING);
3847 result
:= Byte(cwi
);
3848 FNextWeapDelay
:= WEAPON_DELAY
;
3856 for i
:= 0 to High(wantThisWeapon
) do
3857 wantThisWeapon
[i
] := false;
3858 for i
:= 0 to High(FWeapon
) do
3859 if (FNextWeap
and (1 shl i
)) <> 0 then
3861 wantThisWeapon
[i
] := true;
3864 // exclude currently selected weapon from the set
3865 wantThisWeapon
[FCurrWeap
] := false;
3866 // slow down alterations a little
3869 //e_WriteLog(Format(' FNextWeap=%x; delay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
3870 // more than one weapon requested, assume "alteration" and check alteration delay
3871 if FNextWeapDelay
> 0 then
3877 // do not reset weapon queue, it will be done in `RealizeCurrentWeapon()`
3878 // but clear all counters if no weapon should be switched
3884 //e_WriteLog(Format('wwc=%d', [wwc]), MSG_WARNING);
3885 // try weapons in descending order
3886 for i
:= High(FWeapon
) downto 0 do
3888 if wantThisWeapon
[i
] and FWeapon
[i
] and ((wwc
= 1) or hasAmmoForWeapon(i
)) then
3893 FNextWeapDelay
:= WEAPON_DELAY
* 2; // anyway, 'cause why not
3897 // no suitable weapon found, so reset the queue, to avoid accidental "queuing" of weapon w/o ammo
3901 procedure TPlayer
.RealizeCurrentWeapon();
3902 function switchAllowed (): Boolean;
3907 if FBFGFireCounter
<> -1 then
3909 if FTime
[T_SWITCH
] > gTime
then
3911 for i
:= WP_FIRST
to WP_LAST
do
3912 if FReloading
[i
] > 0 then
3920 //e_WriteLog(Format('***RealizeCurrentWeapon: FNextWeap=%x; FNextWeapDelay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
3921 //FNextWeap := FNextWeap and $1FFF;
3922 if FNextWeapDelay
> 0 then Dec(FNextWeapDelay
); // "alteration delay"
3924 if not switchAllowed
then
3926 //HACK for weapon cycling
3927 if (FNextWeap
and $E000) <> 0 then FNextWeap
:= 0;
3931 nw
:= getNextWeaponIndex();
3932 if nw
= 255 then exit
; // don't reset anything here
3933 if nw
> High(FWeapon
) then
3935 // don't forget to reset queue here!
3936 //e_WriteLog(' RealizeCurrentWeapon: WUTAFUUUU', MSG_WARNING);
3944 FTime
[T_SWITCH
] := gTime
+156;
3945 if FCurrWeap
= WEAPON_SAW
then FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3946 FModel
.SetWeapon(FCurrWeap
);
3947 if g_Game_IsNet
then MH_SEND_PlayerStats(FUID
);
3951 procedure TPlayer
.NextWeapon();
3953 if g_Game_IsClient
then Exit
;
3957 procedure TPlayer
.PrevWeapon();
3959 if g_Game_IsClient
then Exit
;
3963 procedure TPlayer
.SetWeapon(W
: Byte);
3965 if FCurrWeap
<> W
then
3966 if W
= WEAPON_SAW
then
3967 FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3970 FModel
.SetWeapon(CurrWeap
);
3974 function TPlayer
.PickItem(ItemType
: Byte; arespawn
: Boolean; var remove
: Boolean): Boolean;
3976 function allowBerserkSwitching (): Boolean;
3978 if (FBFGFireCounter
<> -1) then begin result
:= false; exit
; end;
3980 if gBerserkAutoswitch
then exit
;
3981 if not conIsCheatsEnabled
then exit
;
3989 if g_Game_IsClient
then Exit
;
3991 // a = true - ìåñòî ñïàâíà ïðåäìåòà:
3992 a
:= LongBool(gGameSettings
.Options
and GAME_OPTION_WEAPONSTAY
) and arespawn
;
3997 if (FHealth
< PLAYER_HP_SOFT
) or (FFireTime
> 0) then
3999 if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
4003 if gFlash
= 2 then Inc(FPickup
, 5);
4007 if (FHealth
< PLAYER_HP_SOFT
) or (FFireTime
> 0) then
4009 if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
4013 if gFlash
= 2 then Inc(FPickup
, 5);
4017 if FArmor
< PLAYER_AP_SOFT
then
4019 FArmor
:= PLAYER_AP_SOFT
;
4022 if gFlash
= 2 then Inc(FPickup
, 5);
4026 if FArmor
< PLAYER_AP_LIMIT
then
4028 FArmor
:= PLAYER_AP_LIMIT
;
4031 if gFlash
= 2 then Inc(FPickup
, 5);
4035 if (FHealth
< PLAYER_HP_LIMIT
) or (FFireTime
> 0) then
4037 if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
4041 if gFlash
= 2 then Inc(FPickup
, 5);
4045 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) or (FFireTime
> 0) then
4047 if FHealth
< PLAYER_HP_LIMIT
then
4048 FHealth
:= PLAYER_HP_LIMIT
;
4049 if FArmor
< PLAYER_AP_LIMIT
then
4050 FArmor
:= PLAYER_AP_LIMIT
;
4054 if gFlash
= 2 then Inc(FPickup
, 5);
4058 if (not FWeapon
[WEAPON_SAW
]) or ((not arespawn
) and (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
])) then
4060 FWeapon
[WEAPON_SAW
] := True;
4062 if gFlash
= 2 then Inc(FPickup
, 5);
4063 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4066 ITEM_WEAPON_SHOTGUN1
:
4067 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN1
] then
4069 // Íóæíî, ÷òîáû íå âçÿòü âñå ïóëè ñðàçó:
4070 if a
and FWeapon
[WEAPON_SHOTGUN1
] then Exit
;
4072 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4073 FWeapon
[WEAPON_SHOTGUN1
] := True;
4075 if gFlash
= 2 then Inc(FPickup
, 5);
4076 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4079 ITEM_WEAPON_SHOTGUN2
:
4080 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN2
] then
4082 if a
and FWeapon
[WEAPON_SHOTGUN2
] then Exit
;
4084 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4085 FWeapon
[WEAPON_SHOTGUN2
] := True;
4087 if gFlash
= 2 then Inc(FPickup
, 5);
4088 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4091 ITEM_WEAPON_CHAINGUN
:
4092 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or not FWeapon
[WEAPON_CHAINGUN
] then
4094 if a
and FWeapon
[WEAPON_CHAINGUN
] then Exit
;
4096 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
4097 FWeapon
[WEAPON_CHAINGUN
] := True;
4099 if gFlash
= 2 then Inc(FPickup
, 5);
4100 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4103 ITEM_WEAPON_ROCKETLAUNCHER
:
4104 if (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or not FWeapon
[WEAPON_ROCKETLAUNCHER
] then
4106 if a
and FWeapon
[WEAPON_ROCKETLAUNCHER
] then Exit
;
4108 IncMax(FAmmo
[A_ROCKETS
], 2, FMaxAmmo
[A_ROCKETS
]);
4109 FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
4111 if gFlash
= 2 then Inc(FPickup
, 5);
4112 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4116 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_PLASMA
] then
4118 if a
and FWeapon
[WEAPON_PLASMA
] then Exit
;
4120 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
4121 FWeapon
[WEAPON_PLASMA
] := True;
4123 if gFlash
= 2 then Inc(FPickup
, 5);
4124 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4128 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_BFG
] then
4130 if a
and FWeapon
[WEAPON_BFG
] then Exit
;
4132 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
4133 FWeapon
[WEAPON_BFG
] := True;
4135 if gFlash
= 2 then Inc(FPickup
, 5);
4136 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4139 ITEM_WEAPON_SUPERPULEMET
:
4140 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SUPERPULEMET
] then
4142 if a
and FWeapon
[WEAPON_SUPERPULEMET
] then Exit
;
4144 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4145 FWeapon
[WEAPON_SUPERPULEMET
] := True;
4147 if gFlash
= 2 then Inc(FPickup
, 5);
4148 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4151 ITEM_WEAPON_FLAMETHROWER
:
4152 if (FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
]) or not FWeapon
[WEAPON_FLAMETHROWER
] then
4154 if a
and FWeapon
[WEAPON_FLAMETHROWER
] then Exit
;
4156 IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
4157 FWeapon
[WEAPON_FLAMETHROWER
] := True;
4159 if gFlash
= 2 then Inc(FPickup
, 5);
4160 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4164 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
4166 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
4169 if gFlash
= 2 then Inc(FPickup
, 5);
4172 ITEM_AMMO_BULLETS_BOX
:
4173 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
4175 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
4178 if gFlash
= 2 then Inc(FPickup
, 5);
4182 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
4184 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4187 if gFlash
= 2 then Inc(FPickup
, 5);
4190 ITEM_AMMO_SHELLS_BOX
:
4191 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
4193 IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
4196 if gFlash
= 2 then Inc(FPickup
, 5);
4200 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
4202 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
4205 if gFlash
= 2 then Inc(FPickup
, 5);
4208 ITEM_AMMO_ROCKET_BOX
:
4209 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
4211 IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
4214 if gFlash
= 2 then Inc(FPickup
, 5);
4218 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
4220 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
4223 if gFlash
= 2 then Inc(FPickup
, 5);
4227 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
4229 IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
4232 if gFlash
= 2 then Inc(FPickup
, 5);
4236 if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then
4238 IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
4241 if gFlash
= 2 then Inc(FPickup
, 5);
4245 if not(R_ITEM_BACKPACK
in FRulez
) or
4246 (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
4247 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
4248 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
4249 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or
4250 (FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
]) then
4252 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[1, A_BULLETS
];
4253 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[1, A_SHELLS
];
4254 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[1, A_ROCKETS
];
4255 FMaxAmmo
[A_CELLS
] := AmmoLimits
[1, A_CELLS
];
4256 FMaxAmmo
[A_FUEL
] := AmmoLimits
[1, A_FUEL
];
4258 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
4259 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
4260 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
4261 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4262 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
4263 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
4264 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
4265 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
4266 if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then
4267 IncMax(FAmmo
[A_FUEL
], 50, FMaxAmmo
[A_FUEL
]);
4269 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
4272 if gFlash
= 2 then Inc(FPickup
, 5);
4276 if not(R_KEY_RED
in FRulez
) then
4278 Include(FRulez
, R_KEY_RED
);
4280 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
4281 if gFlash
= 2 then Inc(FPickup
, 5);
4282 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
4286 if not(R_KEY_GREEN
in FRulez
) then
4288 Include(FRulez
, R_KEY_GREEN
);
4290 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
4291 if gFlash
= 2 then Inc(FPickup
, 5);
4292 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
4296 if not(R_KEY_BLUE
in FRulez
) then
4298 Include(FRulez
, R_KEY_BLUE
);
4300 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
4301 if gFlash
= 2 then Inc(FPickup
, 5);
4302 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
4306 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
4308 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
4312 if gFlash
= 2 then Inc(FPickup
, 5);
4316 if FAir
< AIR_MAX
then
4321 if gFlash
= 2 then Inc(FPickup
, 5);
4326 if not (R_BERSERK
in FRulez
) then
4328 Include(FRulez
, R_BERSERK
);
4329 if allowBerserkSwitching
then
4331 FCurrWeap
:= WEAPON_KASTET
;
4333 FModel
.SetWeapon(WEAPON_KASTET
);
4338 if gFlash
= 2 then Inc(FPickup
, 5);
4340 FBerserk
:= gTime
+30000;
4345 if (FHealth
< PLAYER_HP_SOFT
) or (FFireTime
> 0) then
4347 if FHealth
< PLAYER_HP_SOFT
then FHealth
:= PLAYER_HP_SOFT
;
4348 FBerserk
:= gTime
+30000;
4356 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
4358 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
4362 if gFlash
= 2 then Inc(FPickup
, 5);
4366 if (FHealth
< PLAYER_HP_LIMIT
) or (FFireTime
> 0) then
4368 if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
4372 if gFlash
= 2 then Inc(FPickup
, 5);
4376 if FArmor
< PLAYER_AP_LIMIT
then
4378 IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
4381 if gFlash
= 2 then Inc(FPickup
, 5);
4385 if FJetFuel
< JET_MAX
then
4387 FJetFuel
:= JET_MAX
;
4390 if gFlash
= 2 then Inc(FPickup
, 5);
4394 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
4396 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
4399 if gFlash
= 2 then Inc(FPickup
, 5);
4404 procedure TPlayer
.Touch();
4408 //FModel.PlaySound(MODELSOUND_PAIN, 1, FObj.X, FObj.Y);
4411 // Áðîñèòü ôëàã òîâàðèùó:
4412 if gGameSettings
.GameMode
= GM_CTF
then
4417 procedure TPlayer
.Push(vx
, vy
: Integer);
4419 if (not FPhysics
) and FGhost
then
4421 FObj
.Accel
.X
:= FObj
.Accel
.X
+ vx
;
4422 FObj
.Accel
.Y
:= FObj
.Accel
.Y
+ vy
;
4423 if g_Game_IsNet
and g_Game_IsServer
then
4424 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
4427 procedure TPlayer
.Reset(Force
: Boolean);
4433 FTime
[T_RESPAWN
] := 0;
4434 FTime
[T_FLAGCAP
] := 0;
4450 FSpectator
:= False;
4453 FSpectatePlayer
:= -1;
4454 FNoRespawn
:= False;
4456 FLives
:= gGameSettings
.MaxLives
;
4461 procedure TPlayer
.SoftReset();
4469 FBFGFireCounter
:= -1;
4477 SetAction(A_STAND
, True);
4480 function TPlayer
.GetRespawnPoint(): Byte;
4485 // Íà áóäóùåå: FSpawn - èãðîê óæå èãðàë è ïåðåðîæäàåòñÿ
4487 // Îäèíî÷íàÿ èãðà/êîîïåðàòèâ
4488 if gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
] then
4490 if Self
= gPlayer1
then
4492 // player 1 should try to spawn on the player 1 point
4493 if g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) > 0 then
4494 Exit(RESPAWNPOINT_PLAYER1
)
4495 else if g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) > 0 then
4496 Exit(RESPAWNPOINT_PLAYER2
);
4498 else if Self
= gPlayer2
then
4500 // player 2 should try to spawn on the player 2 point
4501 if g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) > 0 then
4502 Exit(RESPAWNPOINT_PLAYER2
)
4503 else if g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) > 0 then
4504 Exit(RESPAWNPOINT_PLAYER1
);
4508 // other players randomly pick either the first or the second point
4509 c
:= IfThen((Random(2) = 0), RESPAWNPOINT_PLAYER1
, RESPAWNPOINT_PLAYER2
);
4510 if g_Map_GetPointCount(c
) > 0 then
4512 // try the other one
4513 c
:= IfThen((c
= RESPAWNPOINT_PLAYER1
), RESPAWNPOINT_PLAYER2
, RESPAWNPOINT_PLAYER1
);
4514 if g_Map_GetPointCount(c
) > 0 then
4520 if gGameSettings
.GameMode
= GM_DM
then
4522 // try DM points first
4523 if g_Map_GetPointCount(RESPAWNPOINT_DM
) > 0 then
4524 Exit(RESPAWNPOINT_DM
);
4528 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
4530 // try team points first
4531 c
:= RESPAWNPOINT_DM
;
4532 if FTeam
= TEAM_RED
then
4533 c
:= RESPAWNPOINT_RED
4534 else if FTeam
= TEAM_BLUE
then
4535 c
:= RESPAWNPOINT_BLUE
;
4536 if g_Map_GetPointCount(c
) > 0 then
4540 // still haven't found a spawnpoint, try random shit
4541 Result
:= g_Map_GetRandomPointType();
4544 procedure TPlayer
.Respawn(Silent
: Boolean; Force
: Boolean = False);
4546 RespawnPoint
: TRespawnPoint
;
4554 FBFGFireCounter
:= -1;
4561 if not g_Game_IsServer
then
4565 FWantsInGame
:= True;
4566 FJustTeleported
:= True;
4569 FTime
[T_RESPAWN
] := 0;
4573 // if server changes MaxLives we gotta be ready
4574 if gGameSettings
.MaxLives
= 0 then FNoRespawn
:= False;
4576 // Åùå íåëüçÿ âîçðîäèòüñÿ:
4577 if FTime
[T_RESPAWN
] > gTime
then
4580 // Ïðîñðàë âñå æèçíè:
4583 if not FSpectator
then Spectate(True);
4584 FWantsInGame
:= True;
4588 if (gGameSettings
.GameType
<> GT_SINGLE
) and (gGameSettings
.GameMode
<> GM_COOP
) then
4589 begin // "Ñâîÿ èãðà"
4590 // Áåðñåðê íå ñîõðàíÿåòñÿ ìåæäó óðîâíÿìè:
4591 FRulez
:= FRulez
-[R_BERSERK
];
4593 else // "Îäèíî÷íàÿ èãðà"/"Êîîï"
4595 // Áåðñåðê è êëþ÷è íå ñîõðàíÿþòñÿ ìåæäó óðîâíÿìè:
4596 FRulez
:= FRulez
-[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
, R_BERSERK
];
4599 // Ïîëó÷àåì òî÷êó ñïàóíà èãðîêà:
4600 c
:= GetRespawnPoint();
4605 // Âîñêðåøåíèå áåç îðóæèÿ:
4608 FHealth
:= Round(PLAYER_HP_SOFT
* (FHandicap
/ 100));
4614 for a
:= WP_FIRST
to WP_LAST
do
4616 FWeapon
[a
] := False;
4620 FWeapon
[WEAPON_PISTOL
] := True;
4621 FWeapon
[WEAPON_KASTET
] := True;
4622 FCurrWeap
:= WEAPON_PISTOL
;
4625 FModel
.SetWeapon(FCurrWeap
);
4627 for b
:= A_BULLETS
to A_HIGH
do
4630 FAmmo
[A_BULLETS
] := 50;
4632 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[0, A_BULLETS
];
4633 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[0, A_SHELLS
];
4634 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[0, A_SHELLS
];
4635 FMaxAmmo
[A_CELLS
] := AmmoLimits
[0, A_CELLS
];
4636 FMaxAmmo
[A_FUEL
] := AmmoLimits
[0, A_FUEL
];
4638 if (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
]) and
4639 LongBool(gGameSettings
.Options
and GAME_OPTION_DMKEYS
) then
4640 FRulez
:= [R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
]
4645 // Ïîëó÷àåì êîîðäèíàòû òî÷êè âîçðîæäåíèÿ:
4646 if not g_Map_GetPoint(c
, RespawnPoint
) then
4648 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
4652 // Óñòàíîâêà êîîðäèíàò è ñáðîñ âñåõ ïàðàìåòðîâ:
4653 FObj
.X
:= RespawnPoint
.X
-PLAYER_RECT
.X
;
4654 FObj
.Y
:= RespawnPoint
.Y
-PLAYER_RECT
.Y
;
4655 FObj
.oldX
:= FObj
.X
; // don't interpolate after respawn
4656 FObj
.oldY
:= FObj
.Y
;
4662 FDirection
:= RespawnPoint
.Direction
;
4663 if FDirection
= TDirection
.D_LEFT
then
4668 SetAction(A_STAND
, True);
4669 FModel
.Direction
:= FDirection
;
4671 for a
:= Low(FTime
) to High(FTime
) do
4674 for a
:= Low(FMegaRulez
) to High(FMegaRulez
) do
4677 // Respawn invulnerability
4678 if (gGameSettings
.GameType
<> GT_SINGLE
) and (gGameSettings
.SpawnInvul
> 0) then
4680 FMegaRulez
[MR_INVUL
] := gTime
+ gGameSettings
.SpawnInvul
* 1000;
4681 FSpawnInvul
:= FMegaRulez
[MR_INVUL
];
4686 FCanJetpack
:= False;
4692 // Àíèìàöèÿ âîçðîæäåíèÿ:
4693 if (not gLoadGameMode
) and (not Silent
) then
4694 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
4696 Anim
:= TAnimation
.Create(ID
, False, 3);
4697 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4698 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4702 FSpectator
:= False;
4705 FSpectatePlayer
:= -1;
4708 if (gPlayer1
= nil) and (gSpectLatchPID1
= FUID
) then
4710 if (gPlayer2
= nil) and (gSpectLatchPID2
= FUID
) then
4713 if g_Game_IsNet
then
4715 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
4716 MH_SEND_PlayerStats(FUID
, NET_EVERYONE
);
4718 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4719 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32,
4724 procedure TPlayer
.Spectate(NoMove
: Boolean = False);
4727 Kill(K_EXTRAHARDKILL
, FUID
, HIT_SOME
)
4728 else if (not NoMove
) then
4730 GameX
:= gMapInfo
.Width
div 2;
4731 GameY
:= gMapInfo
.Height
div 2;
4740 FWantsInGame
:= False;
4746 if Self
= gPlayer1
then
4748 gSpectLatchPID1
:= FUID
;
4751 else if Self
= gPlayer2
then
4753 gSpectLatchPID2
:= FUID
;
4758 if g_Game_IsNet
then
4759 MH_SEND_PlayerStats(FUID
);
4762 procedure TPlayer
.SwitchNoClip
;
4766 FGhost
:= not FGhost
;
4767 FPhysics
:= not FGhost
;
4779 procedure TPlayer
.Run(Direction
: TDirection
);
4783 if MAX_RUNVEL
> 8 then
4787 if Direction
= TDirection
.D_LEFT
then
4789 if FObj
.Vel
.X
> -MAX_RUNVEL
then
4790 FObj
.Vel
.X
:= FObj
.Vel
.X
- (MAX_RUNVEL
shr 3);
4793 if FObj
.Vel
.X
< MAX_RUNVEL
then
4794 FObj
.Vel
.X
:= FObj
.Vel
.X
+ (MAX_RUNVEL
shr 3);
4796 // Âîçìîæíî, ïèíàåì êóñêè:
4797 if (FObj
.Vel
.X
<> 0) and (gGibs
<> nil) then
4799 b
:= Abs(FObj
.Vel
.X
);
4800 if b
> 1 then b
:= b
* (Random(8 div b
) + 1);
4801 for a
:= 0 to High(gGibs
) do
4803 if gGibs
[a
].alive
and
4804 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
+FObj
.Rect
.Height
-4,
4805 FObj
.Rect
.Width
, 8, @gGibs
[a
].Obj
) and (Random(3) = 0) then
4808 if FObj
.Vel
.X
< 0 then
4810 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)+120) // íàëåâî
4814 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)); // íàïðàâî
4816 gGibs
[a
].positionChanged(); // this updates spatial accelerators
4824 procedure TPlayer
.SeeDown();
4826 SetAction(A_SEEDOWN
);
4828 if FDirection
= TDirection
.D_LEFT
then FAngle
:= ANGLE_LEFTDOWN
else FAngle
:= ANGLE_RIGHTDOWN
;
4830 if FIncCam
> -120 then DecMin(FIncCam
, 5, -120);
4833 procedure TPlayer
.SeeUp();
4837 if FDirection
= TDirection
.D_LEFT
then FAngle
:= ANGLE_LEFTUP
else FAngle
:= ANGLE_RIGHTUP
;
4839 if FIncCam
< 120 then IncMax(FIncCam
, 5, 120);
4842 procedure TPlayer
.SetAction(Action
: Byte; Force
: Boolean = False);
4850 A_ATTACK
: Prior
:= 2;
4851 A_SEEUP
: Prior
:= 1;
4852 A_SEEDOWN
: Prior
:= 1;
4853 A_ATTACKUP
: Prior
:= 2;
4854 A_ATTACKDOWN
: Prior
:= 2;
4859 if (Prior
> FActionPrior
) or Force
then
4860 if not ((Prior
= 2) and (FCurrWeap
= WEAPON_SAW
)) then
4862 FActionPrior
:= Prior
;
4863 FActionAnim
:= Action
;
4864 FActionForce
:= Force
;
4865 FActionChanged
:= True;
4868 if Action
in [A_ATTACK
, A_ATTACKUP
, A_ATTACKDOWN
] then FModel
.SetFire(True);
4871 function TPlayer
.StayOnStep(XInc
, YInc
: Integer): Boolean;
4873 Result
:= not g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
-1,
4874 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False)
4875 and g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
,
4876 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False);
4879 function TPlayer
.TeleportTo(X
, Y
: Integer; silent
: Boolean; dir
: Byte): Boolean;
4886 if g_CollideLevel(X
, Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
) then
4888 g_Sound_PlayExAt('SOUND_GAME_NOTELEPORT', FObj
.X
, FObj
.Y
);
4889 if g_Game_IsServer
and g_Game_IsNet
then
4890 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_GAME_NOTELEPORT');
4894 FJustTeleported
:= True;
4899 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
4901 Anim
:= TAnimation
.Create(ID
, False, 3);
4904 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', FObj
.X
, FObj
.Y
);
4905 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4906 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4907 if g_Game_IsServer
and g_Game_IsNet
then
4908 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4909 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 1,
4913 FObj
.X
:= X
-PLAYER_RECT
.X
;
4914 FObj
.Y
:= Y
-PLAYER_RECT
.Y
;
4915 FObj
.oldX
:= FObj
.X
; // don't interpolate after respawn
4916 FObj
.oldY
:= FObj
.Y
;
4917 if FAlive
and FGhost
then
4923 if not g_Game_IsNet
then
4927 SetDirection(TDirection
.D_LEFT
);
4933 SetDirection(TDirection
.D_RIGHT
);
4939 if FDirection
= TDirection
.D_RIGHT
then
4941 SetDirection(TDirection
.D_LEFT
);
4946 SetDirection(TDirection
.D_RIGHT
);
4952 if not silent
and (Anim
<> nil) then
4954 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4955 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4958 if g_Game_IsServer
and g_Game_IsNet
then
4959 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4960 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 0,
4967 function nonz(a
: Single): Single;
4975 function TPlayer
.refreshCorpse(): Boolean;
4981 if FAlive
or FSpectator
then
4983 if (gCorpses
= nil) or (Length(gCorpses
) = 0) then
4985 for i
:= 0 to High(gCorpses
) do
4986 if gCorpses
[i
] <> nil then
4987 if gCorpses
[i
].FPlayerUID
= FUID
then
4995 function TPlayer
.getCameraObj(): TObj
;
4997 if (not FAlive
) and (not FSpectator
) and
4998 (FCorpse
>= 0) and (FCorpse
< Length(gCorpses
)) and
4999 (gCorpses
[FCorpse
] <> nil) and (gCorpses
[FCorpse
].FPlayerUID
= FUID
) then
5001 gCorpses
[FCorpse
].FObj
.slopeUpLeft
:= FObj
.slopeUpLeft
;
5002 Result
:= gCorpses
[FCorpse
].FObj
;
5010 procedure TPlayer
.PreUpdate();
5012 FSlopeOld
:= FObj
.slopeUpLeft
;
5013 FIncCamOld
:= FIncCam
;
5014 FObj
.oldX
:= FObj
.X
;
5015 FObj
.oldY
:= FObj
.Y
;
5018 procedure TPlayer
.Update();
5021 i
, ii
, wx
, wy
, xd
, yd
, k
: Integer;
5022 blockmon
, headwater
, dospawn
: Boolean;
5027 NetServer
:= g_Game_IsNet
and g_Game_IsServer
;
5028 AnyServer
:= g_Game_IsServer
;
5030 if g_Game_IsClient
and (NetInterpLevel
> 0) then
5031 DoLerp(NetInterpLevel
+ 1)
5037 if FClientID
>= 0 then
5039 FPing
:= NetClients
[FClientID
].Peer
^.lastRoundTripTime
;
5040 if NetClients
[FClientID
].Peer
^.packetsSent
> 0 then
5041 FLoss
:= Round(100*NetClients
[FClientID
].Peer
^.packetsLost
/NetClients
[FClientID
].Peer
^.packetsSent
)
5050 if FAlive
and (FPunchAnim
<> nil) then
5051 FPunchAnim
.Update();
5053 if FAlive
and (gFly
or FJetpack
) then
5056 if FDirection
= TDirection
.D_LEFT
then
5061 if FAlive
and (not FGhost
) then
5063 if FKeys
[KEY_UP
].Pressed
then
5065 if FKeys
[KEY_DOWN
].Pressed
then
5069 if (not (FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_DOWN
].Pressed
)) and
5072 i
:= g_basic
.Sign(FIncCam
);
5073 FIncCam
:= Abs(FIncCam
);
5074 DecMin(FIncCam
, 5, 0);
5075 FIncCam
:= FIncCam
*i
;
5078 if gTime
mod (GAME_TICK
*2) <> 0 then
5080 if (FObj
.Vel
.X
= 0) and FAlive
then
5082 if FKeys
[KEY_LEFT
].Pressed
then
5083 Run(TDirection
.D_LEFT
);
5084 if FKeys
[KEY_RIGHT
].Pressed
then
5085 Run(TDirection
.D_RIGHT
);
5090 g_Obj_Move(@FObj
, True, True, True);
5091 positionChanged(); // this updates spatial accelerators
5097 FActionChanged
:= False;
5101 // Let alive player do some actions
5102 if FKeys
[KEY_LEFT
].Pressed
then Run(TDirection
.D_LEFT
);
5103 if FKeys
[KEY_RIGHT
].Pressed
then Run(TDirection
.D_RIGHT
);
5104 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then Fire()
5110 if NetServer
then MH_SEND_PlayerStats(FUID
);
5113 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Use();
5114 if FKeys
[KEY_JUMP
].Pressed
then Jump()
5117 if AnyServer
and FJetpack
then
5121 if NetServer
then MH_SEND_PlayerStats(FUID
);
5123 FCanJetpack
:= True;
5130 for k
:= Low(FKeys
) to KEY_CHAT
-1 do
5132 if FKeys
[k
].Pressed
then
5140 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
5143 if (FTime
[T_RESPAWN
] <= gTime
) and
5144 gGameOn
and (not FAlive
) then
5146 if (g_Player_GetCount() > 1) then
5150 gExit
:= EXIT_RESTART
;
5155 // Dead spectator actions
5158 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Fire();
5159 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then
5163 if (FSpectatePlayer
>= High(gPlayers
)) then
5164 FSpectatePlayer
:= -1
5168 for I
:= FSpectatePlayer
+ 1 to High(gPlayers
) do
5169 if gPlayers
[I
] <> nil then
5170 if gPlayers
[I
].alive
then
5171 if gPlayers
[I
].UID
<> FUID
then
5173 FSpectatePlayer
:= I
;
5178 if not SetSpect
then FSpectatePlayer
:= -1;
5189 if FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_JUMP
].Pressed
then
5191 FYTo
:= FObj
.Y
- 32;
5192 FSpectatePlayer
:= -1;
5194 if FKeys
[KEY_DOWN
].Pressed
then
5196 FYTo
:= FObj
.Y
+ 32;
5197 FSpectatePlayer
:= -1;
5199 if FKeys
[KEY_LEFT
].Pressed
then
5201 FXTo
:= FObj
.X
- 32;
5202 FSpectatePlayer
:= -1;
5204 if FKeys
[KEY_RIGHT
].Pressed
then
5206 FXTo
:= FObj
.X
+ 32;
5207 FSpectatePlayer
:= -1;
5210 if (FXTo
< -64) then
5212 else if (FXTo
> gMapInfo
.Width
+ 32) then
5213 FXTo
:= gMapInfo
.Width
+ 32;
5214 if (FYTo
< -72) then
5216 else if (FYTo
> gMapInfo
.Height
+ 32) then
5217 FYTo
:= gMapInfo
.Height
+ 32;
5222 g_Obj_Move(@FObj
, True, True, True);
5223 positionChanged(); // this updates spatial accelerators
5230 if (FSpectatePlayer
<= High(gPlayers
)) and (FSpectatePlayer
>= 0) then
5231 if gPlayers
[FSpectatePlayer
] <> nil then
5232 if gPlayers
[FSpectatePlayer
].alive
then
5234 FXTo
:= gPlayers
[FSpectatePlayer
].GameX
;
5235 FYTo
:= gPlayers
[FSpectatePlayer
].GameY
;
5239 blockmon
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
, FObj
.Y
+PLAYER_HEADRECT
.Y
,
5240 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
5241 PANEL_BLOCKMON
, True);
5242 headwater
:= HeadInLiquid(0, 0);
5244 // Ñîïðîòèâëåíèå âîçäóõà:
5245 if (not FAlive
) or not (FKeys
[KEY_LEFT
].Pressed
or FKeys
[KEY_RIGHT
].Pressed
) then
5246 if FObj
.Vel
.X
<> 0 then
5247 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
5249 if (FLastHit
= HIT_TRAP
) and (FPain
> 90) then FPain
:= 90;
5250 DecMin(FPain
, 5, 0);
5251 DecMin(FPickup
, 1, 0);
5253 if FAlive
and (FObj
.Y
> Integer(gMapInfo
.Height
)+128) and AnyServer
then
5255 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
5256 FMegaRulez
[MR_SUIT
] := 0;
5257 FMegaRulez
[MR_INVUL
] := 0;
5258 FMegaRulez
[MR_INVIS
] := 0;
5259 Kill(K_FALLKILL
, 0, HIT_FALL
);
5266 if FCurrWeap
= WEAPON_SAW
then
5267 if not (FSawSound
.IsPlaying() or FSawSoundHit
.IsPlaying() or
5268 FSawSoundSelect
.IsPlaying()) then
5269 FSawSoundIdle
.PlayAt(FObj
.X
, FObj
.Y
);
5272 if (not FJetSoundFly
.IsPlaying()) and (not FJetSoundOn
.IsPlaying()) and
5273 (not FJetSoundOff
.IsPlaying()) then
5275 FJetSoundFly
.SetPosition(0);
5276 FJetSoundFly
.PlayAt(FObj
.X
, FObj
.Y
);
5279 for b
:= WP_FIRST
to WP_LAST
do
5280 if FReloading
[b
] > 0 then
5286 if FShellTimer
> -1 then
5287 if FShellTimer
= 0 then
5289 if FShellType
= SHELL_SHELL
then
5290 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5291 GameVelX
, GameVelY
-2, SHELL_SHELL
)
5292 else if FShellType
= SHELL_DBLSHELL
then
5294 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5295 GameVelX
+1, GameVelY
-2, SHELL_SHELL
);
5296 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5297 GameVelX
-1, GameVelY
-2, SHELL_SHELL
);
5300 end else Dec(FShellTimer
);
5302 if (FBFGFireCounter
> -1) then
5303 if FBFGFireCounter
= 0 then
5307 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
5308 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
5309 xd
:= wx
+IfThen(FDirection
= TDirection
.D_LEFT
, -30, 30);
5310 yd
:= wy
+firediry();
5311 g_Weapon_bfgshot(wx
, wy
, xd
, yd
, FUID
);
5312 if NetServer
then MH_SEND_PlayerFire(FUID
, WEAPON_BFG
, wx
, wy
, xd
, yd
);
5313 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
5314 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
5315 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
5318 FReloading
[WEAPON_BFG
] := WEAPON_RELOAD
[WEAPON_BFG
];
5319 FBFGFireCounter
:= -1;
5322 FBFGFireCounter
:= 0
5324 Dec(FBFGFireCounter
);
5326 if (FMegaRulez
[MR_SUIT
] < gTime
) and AnyServer
then
5328 b
:= g_GetAcidHit(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
);
5330 if (b
> 0) and (gTime
mod (15*GAME_TICK
) = 0) then Damage(b
, 0, 0, 0, HIT_ACID
);
5333 if (headwater
or blockmon
) then
5339 if AnyServer
then Damage(10, 0, 0, 0, HIT_WATER
);
5342 else if (FAir
mod 31 = 0) and not blockmon
then
5344 g_GFX_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2), FObj
.Y
+PLAYER_RECT
.Y
-4, 5+Random(6), 8, 4);
5345 if Random(2) = 0 then
5346 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
5348 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
5350 end else if FAir
< AIR_DEF
then
5353 if FFireTime
> 0 then
5355 if BodyInLiquid(0, 0) then
5360 else if FMegaRulez
[MR_SUIT
] >= gTime
then
5362 if FMegaRulez
[MR_SUIT
] = gTime
then
5369 if FFirePainTime
<= 0 then
5371 if g_Game_IsServer
then
5372 Damage(2, FFireAttacker
, 0, 0, HIT_FLAME
);
5373 FFirePainTime
:= 12 - FFireTime
div 12;
5375 FFirePainTime
:= FFirePainTime
- 1;
5376 FFireTime
:= FFireTime
- 1;
5377 if ((FFireTime
mod 33) = 0) and (FMegaRulez
[MR_INVUL
] < gTime
) then
5378 FModel
.PlaySound(MODELSOUND_PAIN
, 1, FObj
.X
, FObj
.Y
);
5379 if (FFireTime
= 0) and g_Game_IsNet
and g_Game_IsServer
then
5380 MH_SEND_PlayerStats(FUID
);
5384 if FDamageBuffer
> 0 then
5386 if FDamageBuffer
>= 9 then
5390 if FDamageBuffer
< 30 then i
:= 9
5391 else if FDamageBuffer
< 100 then i
:= 18
5395 ii
:= Round(FDamageBuffer
*FHealth
/ nonz(FArmor
*(3/4)+FHealth
));
5396 FArmor
:= FArmor
-(FDamageBuffer
-ii
);
5397 FHealth
:= FHealth
-ii
;
5400 FHealth
:= FHealth
+FArmor
;
5405 if FHealth
<= 0 then
5406 if FHealth
> -30 then Kill(K_SIMPLEKILL
, FLastSpawnerUID
, FLastHit
)
5407 else if FHealth
> -50 then Kill(K_HARDKILL
, FLastSpawnerUID
, FLastHit
)
5408 else Kill(K_EXTRAHARDKILL
, FLastSpawnerUID
, FLastHit
);
5410 if FAlive
and ((FLastHit
<> HIT_FLAME
) or (FFireTime
<= 0)) then
5412 if FDamageBuffer
<= 20 then FModel
.PlaySound(MODELSOUND_PAIN
, 1, FObj
.X
, FObj
.Y
)
5413 else if FDamageBuffer
<= 55 then FModel
.PlaySound(MODELSOUND_PAIN
, 2, FObj
.X
, FObj
.Y
)
5414 else if FDamageBuffer
<= 120 then FModel
.PlaySound(MODELSOUND_PAIN
, 3, FObj
.X
, FObj
.Y
)
5415 else FModel
.PlaySound(MODELSOUND_PAIN
, 4, FObj
.X
, FObj
.Y
);
5422 end; // if FAlive then ...
5424 if (FActionAnim
= A_PAIN
) and (FModel
.Animation
<> A_PAIN
) then
5426 FModel
.ChangeAnimation(FActionAnim
, FActionForce
);
5427 FModel
.GetCurrentAnimation
.MinLength
:= i
;
5428 FModel
.GetCurrentAnimationMask
.MinLength
:= i
;
5429 end else FModel
.ChangeAnimation(FActionAnim
, FActionForce
and (FModel
.Animation
<> A_STAND
));
5431 if (FModel
.GetCurrentAnimation
.Played
or ((not FActionChanged
) and (FModel
.Animation
= A_WALK
)))
5432 then SetAction(A_STAND
, True);
5434 if not ((FModel
.Animation
= A_WALK
) and (Abs(FObj
.Vel
.X
) < 4) and not FModel
.Fire
) then FModel
.Update
;
5436 for b
:= Low(FKeys
) to High(FKeys
) do
5437 if FKeys
[b
].Time
= 0 then FKeys
[b
].Pressed
:= False else Dec(FKeys
[b
].Time
);
5441 procedure TPlayer
.getMapBox (out x
, y
, w
, h
: Integer); inline;
5443 x
:= FObj
.X
+PLAYER_RECT
.X
;
5444 y
:= FObj
.Y
+PLAYER_RECT
.Y
;
5445 w
:= PLAYER_RECT
.Width
;
5446 h
:= PLAYER_RECT
.Height
;
5450 procedure TPlayer
.moveBy (dx
, dy
: Integer); inline;
5452 if (dx
<> 0) or (dy
<> 0) then
5461 function TPlayer
.Collide(X
, Y
: Integer; Width
, Height
: Word): Boolean;
5463 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
5464 FObj
.Y
+PLAYER_RECT
.Y
,
5471 function TPlayer
.Collide(Panel
: TPanel
): Boolean;
5473 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
5474 FObj
.Y
+PLAYER_RECT
.Y
,
5478 Panel
.Width
, Panel
.Height
);
5481 function TPlayer
.Collide(X
, Y
: Integer): Boolean;
5483 X
:= X
-FObj
.X
-PLAYER_RECT
.X
;
5484 Y
:= Y
-FObj
.Y
-PLAYER_RECT
.Y
;
5485 Result
:= (x
>= 0) and (x
<= PLAYER_RECT
.Width
) and
5486 (y
>= 0) and (y
<= PLAYER_RECT
.Height
);
5489 function g_Player_ValidName(Name
: string): Boolean;
5495 if gPlayers
= nil then Exit
;
5497 for a
:= 0 to High(gPlayers
) do
5498 if gPlayers
[a
] <> nil then
5499 if LowerCase(Name
) = LowerCase(gPlayers
[a
].FName
) then
5506 procedure TPlayer
.SetDirection(Direction
: TDirection
);
5510 d
:= FModel
.Direction
;
5512 FModel
.Direction
:= Direction
;
5513 if d
<> Direction
then FModel
.ChangeAnimation(FModel
.Animation
, True);
5515 FDirection
:= Direction
;
5518 function TPlayer
.GetKeys(): Byte;
5522 if R_KEY_RED
in FRulez
then Result
:= KEY_RED
;
5523 if R_KEY_GREEN
in FRulez
then Result
:= Result
or KEY_GREEN
;
5524 if R_KEY_BLUE
in FRulez
then Result
:= Result
or KEY_BLUE
;
5526 if FTeam
= TEAM_RED
then Result
:= Result
or KEY_REDTEAM
;
5527 if FTeam
= TEAM_BLUE
then Result
:= Result
or KEY_BLUETEAM
;
5530 procedure TPlayer
.Use();
5534 if FTime
[T_USE
] > gTime
then Exit
;
5536 g_Triggers_PressR(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
,
5537 PLAYER_RECT
.Height
, FUID
, ACTIVATE_PLAYERPRESS
);
5539 for a
:= 0 to High(gPlayers
) do
5540 if (gPlayers
[a
] <> nil) and (gPlayers
[a
] <> Self
) and
5541 gPlayers
[a
].alive
and SameTeam(FUID
, gPlayers
[a
].FUID
) and
5542 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
5543 FObj
.Rect
.Width
, FObj
.Rect
.Height
, @gPlayers
[a
].FObj
) then
5545 gPlayers
[a
].Touch();
5546 if g_Game_IsNet
and g_Game_IsServer
then
5547 MH_SEND_GameEvent(NET_EV_PLAYER_TOUCH
, gPlayers
[a
].FUID
);
5550 FTime
[T_USE
] := gTime
+120;
5553 procedure TPlayer
.NetFire(Wpn
: Byte; X
, Y
, AX
, AY
: Integer; WID
: Integer = -1);
5557 WX
, WY
, XD
, YD
: Integer;
5569 if R_BERSERK
in FRulez
then
5571 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
5572 locobj
.X
:= FObj
.X
+FObj
.Rect
.X
;
5573 locobj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
5576 locobj
.rect
.Width
:= 39;
5577 locobj
.rect
.Height
:= 52;
5578 locobj
.Vel
.X
:= (xd
-wx
) div 2;
5579 locobj
.Vel
.Y
:= (yd
-wy
) div 2;
5580 locobj
.Accel
.X
:= xd
-wx
;
5581 locobj
.Accel
.y
:= yd
-wy
;
5583 if g_Weapon_Hit(@locobj
, 50, FUID
, HIT_SOME
) <> 0 then
5584 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
5586 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
5590 FPain
:= min(FPain
+ 25, 50);
5592 g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
5597 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
5598 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
5600 FSawSoundSelect
.Stop();
5602 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
5604 else if not FSawSoundHit
.IsPlaying() then
5606 FSawSoundSelect
.Stop();
5607 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
5614 g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', GameX
, Gamey
);
5615 FFireAngle
:= FAngle
;
5617 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5618 GameVelX
, GameVelY
-2, SHELL_BULLET
);
5623 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
5624 FFireAngle
:= FAngle
;
5627 FShellType
:= SHELL_SHELL
;
5632 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN2', Gamex
, Gamey
);
5633 FFireAngle
:= FAngle
;
5636 FShellType
:= SHELL_DBLSHELL
;
5641 g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', Gamex
, Gamey
);
5642 FFireAngle
:= FAngle
;
5644 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5645 GameVelX
, GameVelY
-2, SHELL_BULLET
);
5648 WEAPON_ROCKETLAUNCHER
:
5650 g_Weapon_Rocket(wx
, wy
, xd
, yd
, FUID
, WID
);
5651 FFireAngle
:= FAngle
;
5657 g_Weapon_Plasma(wx
, wy
, xd
, yd
, FUID
, WID
);
5658 FFireAngle
:= FAngle
;
5664 g_Weapon_BFGShot(wx
, wy
, xd
, yd
, FUID
, WID
);
5665 FFireAngle
:= FAngle
;
5669 WEAPON_SUPERPULEMET
:
5671 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
5672 FFireAngle
:= FAngle
;
5674 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5675 GameVelX
, GameVelY
-2, SHELL_SHELL
);
5678 WEAPON_FLAMETHROWER
:
5680 g_Weapon_flame(wx
, wy
, xd
, yd
, FUID
, WID
);
5682 FFireAngle
:= FAngle
;
5689 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
5690 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
5691 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
5694 procedure TPlayer
.DoLerp(Level
: Integer = 2);
5696 if FObj
.X
<> FXTo
then FObj
.X
:= Lerp(FObj
.X
, FXTo
, Level
);
5697 if FObj
.Y
<> FYTo
then FObj
.Y
:= Lerp(FObj
.Y
, FYTo
, Level
);
5700 procedure TPlayer
.SetLerp(XTo
, YTo
: Integer);
5706 if FJustTeleported
or (NetInterpLevel
< 1) then
5710 if FJustTeleported
then
5712 FObj
.oldX
:= FObj
.X
;
5713 FObj
.oldY
:= FObj
.Y
;
5718 AX
:= Abs(FXTo
- FObj
.X
);
5719 AY
:= Abs(FYTo
- FObj
.Y
);
5720 if (AX
> 32) or (AX
<= NetInterpLevel
) then
5722 if (AY
> 32) or (AY
<= NetInterpLevel
) then
5727 function TPlayer
.FullInLift(XInc
, YInc
: Integer): Integer;
5729 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5730 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5731 PANEL_LIFTUP
, False) then Result
:= -1
5733 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5734 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5735 PANEL_LIFTDOWN
, False) then Result
:= 1
5739 function TPlayer
.GetFlag(Flag
: Byte): Boolean;
5746 if Flag
= FLAG_NONE
then
5749 if not g_Game_IsServer
then Exit
;
5751 // Ïðèíåñ ÷óæîé ôëàã íà ñâîþ áàçó:
5752 if (Flag
= FTeam
) and
5753 (gFlags
[Flag
].State
= FLAG_STATE_NORMAL
) and
5754 (FFlag
<> FLAG_NONE
) then
5756 if FFlag
= FLAG_RED
then
5757 s
:= _lc
[I_PLAYER_FLAG_RED
]
5759 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5761 evtype
:= FLAG_STATE_SCORED
;
5763 ts
:= Format('%.4d', [gFlags
[FFlag
].CaptureTime
]);
5764 Insert('.', ts
, Length(ts
) + 1 - 3);
5765 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_CAPTURE
], [FName
, s
, ts
]), True);
5767 g_Map_ResetFlag(FFlag
);
5768 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_CAPTURE
], [AnsiUpperCase(s
)]), 144);
5770 if ((Self
= gPlayer1
) or (Self
= gPlayer2
)
5771 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= FTeam
))
5772 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= FTeam
))) then
5777 if not sound_cap_flag
[a
].IsPlaying() then
5778 sound_cap_flag
[a
].Play();
5780 gTeamStat
[FTeam
].Goals
:= gTeamStat
[FTeam
].Goals
+ 1;
5783 if g_Game_IsNet
then
5785 MH_SEND_FlagEvent(evtype
, FFlag
, FUID
, False);
5789 gFlags
[FFlag
].CaptureTime
:= 0;
5794 // Ïîäîáðàë ñâîé ôëàã - âåðíóë åãî íà áàçó:
5795 if (Flag
= FTeam
) and
5796 (gFlags
[Flag
].State
= FLAG_STATE_DROPPED
) then
5798 if Flag
= FLAG_RED
then
5799 s
:= _lc
[I_PLAYER_FLAG_RED
]
5801 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5803 evtype
:= FLAG_STATE_RETURNED
;
5804 gFlags
[Flag
].CaptureTime
:= 0;
5806 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_RETURN
], [FName
, s
]), True);
5808 g_Map_ResetFlag(Flag
);
5809 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
5811 if ((Self
= gPlayer1
) or (Self
= gPlayer2
)
5812 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= FTeam
))
5813 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= FTeam
))) then
5818 if not sound_ret_flag
[a
].IsPlaying() then
5819 sound_ret_flag
[a
].Play();
5822 if g_Game_IsNet
then
5824 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5830 // Ïîäîáðàë ÷óæîé ôëàã:
5831 if (Flag
<> FTeam
) and (FTime
[T_FLAGCAP
] <= gTime
) then
5835 if Flag
= FLAG_RED
then
5836 s
:= _lc
[I_PLAYER_FLAG_RED
]
5838 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5840 evtype
:= FLAG_STATE_CAPTURED
;
5842 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_GET
], [FName
, s
]), True);
5844 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_GET
], [AnsiUpperCase(s
)]), 144);
5846 gFlags
[Flag
].State
:= FLAG_STATE_CAPTURED
;
5848 if ((Self
= gPlayer1
) or (Self
= gPlayer2
)
5849 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= FTeam
))
5850 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= FTeam
))) then
5855 if not sound_get_flag
[a
].IsPlaying() then
5856 sound_get_flag
[a
].Play();
5859 if g_Game_IsNet
then
5861 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5867 procedure TPlayer
.SetFlag(Flag
: Byte);
5870 if FModel
<> nil then
5871 FModel
.SetFlag(FFlag
);
5874 function TPlayer
.DropFlag(Silent
: Boolean = True): Boolean;
5880 if (not g_Game_IsServer
) or (FFlag
= FLAG_NONE
) then
5882 FTime
[T_FLAGCAP
] := gTime
+ 2000;
5883 with gFlags
[FFlag
] do
5887 Direction
:= FDirection
;
5888 State
:= FLAG_STATE_DROPPED
;
5890 g_Obj_Push(@Obj
, (FObj
.Vel
.X
div 2)-2+Random(5),
5891 (FObj
.Vel
.Y
div 2)-2+Random(5));
5892 positionChanged(); // this updates spatial accelerators
5894 if FFlag
= FLAG_RED
then
5895 s
:= _lc
[I_PLAYER_FLAG_RED
]
5897 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5899 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_DROP
], [FName
, s
]), True);
5900 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_DROP
], [AnsiUpperCase(s
)]), 144);
5902 if ((Self
= gPlayer1
) or (Self
= gPlayer2
)
5903 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= FTeam
))
5904 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= FTeam
))) then
5909 if (not Silent
) and (not sound_lost_flag
[a
].IsPlaying()) then
5910 sound_lost_flag
[a
].Play();
5912 if g_Game_IsNet
then
5913 MH_SEND_FlagEvent(FLAG_STATE_DROPPED
, Flag
, FUID
, False);
5919 procedure TPlayer
.GetSecret();
5921 if (self
= gPlayer1
) or (self
= gPlayer2
) then
5923 g_Console_Add(Format(_lc
[I_PLAYER_SECRET
], [FName
]), True);
5924 g_Sound_PlayEx('SOUND_GAME_SECRET');
5929 procedure TPlayer
.PressKey(Key
: Byte; Time
: Word = 1);
5931 Assert(Key
<= High(FKeys
));
5933 FKeys
[Key
].Pressed
:= True;
5934 FKeys
[Key
].Time
:= Time
;
5937 function TPlayer
.IsKeyPressed(K
: Byte): Boolean;
5939 Result
:= FKeys
[K
].Pressed
;
5942 procedure TPlayer
.ReleaseKeys();
5946 for a
:= Low(FKeys
) to High(FKeys
) do
5948 FKeys
[a
].Pressed
:= False;
5953 procedure TPlayer
.OnDamage(Angle
: SmallInt);
5957 function TPlayer
.firediry(): Integer;
5959 if FKeys
[KEY_UP
].Pressed
then Result
:= -42
5960 else if FKeys
[KEY_DOWN
].Pressed
then Result
:= 19
5964 procedure TPlayer
.RememberState();
5967 SavedState
: TPlayerSavedState
;
5969 SavedState
.Health
:= FHealth
;
5970 SavedState
.Armor
:= FArmor
;
5971 SavedState
.Air
:= FAir
;
5972 SavedState
.JetFuel
:= FJetFuel
;
5973 SavedState
.CurrWeap
:= FCurrWeap
;
5974 SavedState
.NextWeap
:= FNextWeap
;
5975 SavedState
.NextWeapDelay
:= FNextWeapDelay
;
5976 for i
:= Low(FWeapon
) to High(FWeapon
) do
5977 SavedState
.Weapon
[i
] := FWeapon
[i
];
5978 for i
:= Low(FAmmo
) to High(FAmmo
) do
5979 SavedState
.Ammo
[i
] := FAmmo
[i
];
5980 for i
:= Low(FMaxAmmo
) to High(FMaxAmmo
) do
5981 SavedState
.MaxAmmo
[i
] := FMaxAmmo
[i
];
5982 SavedState
.Rulez
:= FRulez
- [R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
];
5984 FSavedStateNum
:= -1;
5985 for i
:= Low(SavedStates
) to High(SavedStates
) do
5986 if not SavedStates
[i
].Used
then
5988 FSavedStateNum
:= i
;
5991 if FSavedStateNum
< 0 then
5993 SetLength(SavedStates
, Length(SavedStates
) + 1);
5994 FSavedStateNum
:= High(SavedStates
);
5997 SavedState
.Used
:= True;
5998 SavedStates
[FSavedStateNum
] := SavedState
;
6001 procedure TPlayer
.RecallState();
6004 SavedState
: TPlayerSavedState
;
6006 if(FSavedStateNum
< 0) or (FSavedStateNum
> High(SavedStates
)) then
6009 SavedState
:= SavedStates
[FSavedStateNum
];
6010 SavedStates
[FSavedStateNum
].Used
:= False;
6011 FSavedStateNum
:= -1;
6013 FHealth
:= SavedState
.Health
;
6014 FArmor
:= SavedState
.Armor
;
6015 FAir
:= SavedState
.Air
;
6016 FJetFuel
:= SavedState
.JetFuel
;
6017 FCurrWeap
:= SavedState
.CurrWeap
;
6018 FNextWeap
:= SavedState
.NextWeap
;
6019 FNextWeapDelay
:= SavedState
.NextWeapDelay
;
6020 for i
:= Low(FWeapon
) to High(FWeapon
) do
6021 FWeapon
[i
] := SavedState
.Weapon
[i
];
6022 for i
:= Low(FAmmo
) to High(FAmmo
) do
6023 FAmmo
[i
] := SavedState
.Ammo
[i
];
6024 for i
:= Low(FMaxAmmo
) to High(FMaxAmmo
) do
6025 FMaxAmmo
[i
] := SavedState
.MaxAmmo
[i
];
6026 FRulez
:= SavedState
.Rulez
;
6028 if gGameSettings
.GameType
= GT_SERVER
then
6029 MH_SEND_PlayerStats(FUID
);
6032 procedure TPlayer
.SaveState (st
: TStream
);
6038 utils
.writeSign(st
, 'PLYR');
6039 utils
.writeInt(st
, Byte(PLR_SAVE_VERSION
)); // version
6041 utils
.writeBool(st
, FIamBot
);
6043 utils
.writeInt(st
, Word(FUID
));
6045 utils
.writeStr(st
, FName
);
6047 utils
.writeInt(st
, Byte(FTeam
));
6049 utils
.writeBool(st
, FAlive
);
6050 // Èçðàñõîäîâàë ëè âñå æèçíè
6051 utils
.writeBool(st
, FNoRespawn
);
6053 if FDirection
= TDirection
.D_LEFT
then b
:= 1 else b
:= 2; // D_RIGHT
6054 utils
.writeInt(st
, Byte(b
));
6056 utils
.writeInt(st
, LongInt(FHealth
));
6057 // Êîýôôèöèåíò èíâàëèäíîñòè
6058 utils
.writeInt(st
, LongInt(FHandicap
));
6060 utils
.writeInt(st
, Byte(FLives
));
6062 utils
.writeInt(st
, LongInt(FArmor
));
6064 utils
.writeInt(st
, LongInt(FAir
));
6066 utils
.writeInt(st
, LongInt(FJetFuel
));
6068 utils
.writeInt(st
, LongInt(FPain
));
6070 utils
.writeInt(st
, LongInt(FKills
));
6072 utils
.writeInt(st
, LongInt(FMonsterKills
));
6074 utils
.writeInt(st
, LongInt(FFrags
));
6076 utils
.writeInt(st
, Byte(FFragCombo
));
6077 // Âðåìÿ ïîñëåäíåãî ôðàãà
6078 utils
.writeInt(st
, LongWord(FLastFrag
));
6080 utils
.writeInt(st
, LongInt(FDeath
));
6082 utils
.writeInt(st
, Byte(FFlag
));
6084 utils
.writeInt(st
, LongInt(FSecrets
));
6086 utils
.writeInt(st
, Byte(FCurrWeap
));
6088 utils
.writeInt(st
, Word(FNextWeap
));
6090 utils
.writeInt(st
, Byte(FNextWeapDelay
));
6091 // Âðåìÿ çàðÿäêè BFG
6092 utils
.writeInt(st
, SmallInt(FBFGFireCounter
));
6094 utils
.writeInt(st
, LongInt(FDamageBuffer
));
6095 // Ïîñëåäíèé óäàðèâøèé
6096 utils
.writeInt(st
, Word(FLastSpawnerUID
));
6097 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà
6098 utils
.writeInt(st
, Byte(FLastHit
));
6100 Obj_SaveState(st
, @FObj
);
6101 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ
6102 for i
:= A_BULLETS
to A_HIGH
do utils
.writeInt(st
, Word(FAmmo
[i
]));
6103 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ
6104 for i
:= A_BULLETS
to A_HIGH
do utils
.writeInt(st
, Word(FMaxAmmo
[i
]));
6106 for i
:= WP_FIRST
to WP_LAST
do utils
.writeBool(st
, FWeapon
[i
]);
6107 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ
6108 for i
:= WP_FIRST
to WP_LAST
do utils
.writeInt(st
, Word(FReloading
[i
]));
6110 utils
.writeBool(st
, (R_ITEM_BACKPACK
in FRulez
));
6111 // Íàëè÷èå êðàñíîãî êëþ÷à
6112 utils
.writeBool(st
, (R_KEY_RED
in FRulez
));
6113 // Íàëè÷èå çåëåíîãî êëþ÷à
6114 utils
.writeBool(st
, (R_KEY_GREEN
in FRulez
));
6115 // Íàëè÷èå ñèíåãî êëþ÷à
6116 utils
.writeBool(st
, (R_KEY_BLUE
in FRulez
));
6118 utils
.writeBool(st
, (R_BERSERK
in FRulez
));
6119 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ
6120 for i
:= MR_SUIT
to MR_MAX
do utils
.writeInt(st
, LongWord(FMegaRulez
[i
]));
6121 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà
6122 for i
:= T_RESPAWN
to T_FLAGCAP
do utils
.writeInt(st
, LongWord(FTime
[i
]));
6124 utils
.writeStr(st
, FModel
.Name
);
6126 utils
.writeInt(st
, Byte(FColor
.R
));
6127 utils
.writeInt(st
, Byte(FColor
.G
));
6128 utils
.writeInt(st
, Byte(FColor
.B
));
6132 procedure TPlayer
.LoadState (st
: TStream
);
6141 if not utils
.checkSign(st
, 'PLYR') then raise XStreamError
.Create('invalid player signature');
6142 if (utils
.readByte(st
) <> PLR_SAVE_VERSION
) then raise XStreamError
.Create('invalid player version');
6144 FIamBot
:= utils
.readBool(st
);
6146 FUID
:= utils
.readWord(st
);
6148 str
:= utils
.readStr(st
);
6149 if (self
<> gPlayer1
) and (self
<> gPlayer2
) then FName
:= str
;
6151 FTeam
:= utils
.readByte(st
);
6153 FAlive
:= utils
.readBool(st
);
6154 // Èçðàñõîäîâàë ëè âñå æèçíè
6155 FNoRespawn
:= utils
.readBool(st
);
6157 b
:= utils
.readByte(st
);
6158 if b
= 1 then FDirection
:= TDirection
.D_LEFT
else FDirection
:= TDirection
.D_RIGHT
; // b = 2
6160 FHealth
:= utils
.readLongInt(st
);
6161 // Êîýôôèöèåíò èíâàëèäíîñòè
6162 FHandicap
:= utils
.readLongInt(st
);
6164 FLives
:= utils
.readByte(st
);
6166 FArmor
:= utils
.readLongInt(st
);
6168 FAir
:= utils
.readLongInt(st
);
6170 FJetFuel
:= utils
.readLongInt(st
);
6172 FPain
:= utils
.readLongInt(st
);
6174 FKills
:= utils
.readLongInt(st
);
6176 FMonsterKills
:= utils
.readLongInt(st
);
6178 FFrags
:= utils
.readLongInt(st
);
6180 FFragCombo
:= utils
.readByte(st
);
6181 // Âðåìÿ ïîñëåäíåãî ôðàãà
6182 FLastFrag
:= utils
.readLongWord(st
);
6184 FDeath
:= utils
.readLongInt(st
);
6186 FFlag
:= utils
.readByte(st
);
6188 FSecrets
:= utils
.readLongInt(st
);
6190 FCurrWeap
:= utils
.readByte(st
);
6192 FNextWeap
:= utils
.readWord(st
);
6194 FNextWeapDelay
:= utils
.readByte(st
);
6195 // Âðåìÿ çàðÿäêè BFG
6196 FBFGFireCounter
:= utils
.readSmallInt(st
);
6198 FDamageBuffer
:= utils
.readLongInt(st
);
6199 // Ïîñëåäíèé óäàðèâøèé
6200 FLastSpawnerUID
:= utils
.readWord(st
);
6201 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà
6202 FLastHit
:= utils
.readByte(st
);
6204 Obj_LoadState(@FObj
, st
);
6205 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ
6206 for i
:= A_BULLETS
to A_HIGH
do FAmmo
[i
] := utils
.readWord(st
);
6207 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ
6208 for i
:= A_BULLETS
to A_HIGH
do FMaxAmmo
[i
] := utils
.readWord(st
);
6210 for i
:= WP_FIRST
to WP_LAST
do FWeapon
[i
] := utils
.readBool(st
);
6211 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ
6212 for i
:= WP_FIRST
to WP_LAST
do FReloading
[i
] := utils
.readWord(st
);
6214 if utils
.readBool(st
) then Include(FRulez
, R_ITEM_BACKPACK
);
6215 // Íàëè÷èå êðàñíîãî êëþ÷à
6216 if utils
.readBool(st
) then Include(FRulez
, R_KEY_RED
);
6217 // Íàëè÷èå çåëåíîãî êëþ÷à
6218 if utils
.readBool(st
) then Include(FRulez
, R_KEY_GREEN
);
6219 // Íàëè÷èå ñèíåãî êëþ÷à
6220 if utils
.readBool(st
) then Include(FRulez
, R_KEY_BLUE
);
6222 if utils
.readBool(st
) then Include(FRulez
, R_BERSERK
);
6223 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ
6224 for i
:= MR_SUIT
to MR_MAX
do FMegaRulez
[i
] := utils
.readLongWord(st
);
6225 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà
6226 for i
:= T_RESPAWN
to T_FLAGCAP
do FTime
[i
] := utils
.readLongWord(st
);
6228 str
:= utils
.readStr(st
);
6230 FColor
.R
:= utils
.readByte(st
);
6231 FColor
.G
:= utils
.readByte(st
);
6232 FColor
.B
:= utils
.readByte(st
);
6233 if (self
= gPlayer1
) then
6235 str
:= gPlayer1Settings
.Model
;
6236 FColor
:= gPlayer1Settings
.Color
;
6238 else if (self
= gPlayer2
) then
6240 str
:= gPlayer2Settings
.Model
;
6241 FColor
:= gPlayer2Settings
.Color
;
6243 // Îáíîâëÿåì ìîäåëü èãðîêà
6245 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
6246 FModel
.Color
:= TEAMCOLOR
[FTeam
]
6248 FModel
.Color
:= FColor
;
6252 procedure TPlayer
.AllRulez(Health
: Boolean);
6258 FHealth
:= PLAYER_HP_LIMIT
;
6259 FArmor
:= PLAYER_AP_LIMIT
;
6263 for a
:= WP_FIRST
to WP_LAST
do FWeapon
[a
] := True;
6264 for a
:= A_BULLETS
to A_HIGH
do FAmmo
[a
] := 30000;
6265 FRulez
:= FRulez
+[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
];
6268 procedure TPlayer
.RestoreHealthArmor();
6270 FHealth
:= PLAYER_HP_LIMIT
;
6271 FArmor
:= PLAYER_AP_LIMIT
;
6274 procedure TPlayer
.FragCombo();
6278 if (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) or g_Game_IsClient
then
6280 if gTime
- FLastFrag
< FRAG_COMBO_TIME
then
6282 if FFragCombo
< 5 then
6284 Param
:= FUID
or (FFragCombo
shl 16);
6285 if (FComboEvnt
>= Low(gDelayedEvents
)) and
6286 (FComboEvnt
<= High(gDelayedEvents
)) and
6287 gDelayedEvents
[FComboEvnt
].Pending
and
6288 (gDelayedEvents
[FComboEvnt
].DEType
= DE_KILLCOMBO
) and
6289 (gDelayedEvents
[FComboEvnt
].DENum
and $FFFF = FUID
) then
6291 gDelayedEvents
[FComboEvnt
].Time
:= gTime
+ 500;
6292 gDelayedEvents
[FComboEvnt
].DENum
:= Param
;
6295 FComboEvnt
:= g_Game_DelayEvent(DE_KILLCOMBO
, 500, Param
);
6303 procedure TPlayer
.GiveItem(ItemType
: Byte);
6307 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
6309 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
6313 if FAir
< AIR_MAX
then
6320 if not (R_BERSERK
in FRulez
) then
6322 Include(FRulez
, R_BERSERK
);
6323 if FBFGFireCounter
< 1 then
6325 FCurrWeap
:= WEAPON_KASTET
;
6327 FModel
.SetWeapon(WEAPON_KASTET
);
6331 FBerserk
:= gTime
+30000;
6333 if FHealth
< PLAYER_HP_SOFT
then
6335 FHealth
:= PLAYER_HP_SOFT
;
6336 FBerserk
:= gTime
+30000;
6341 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
6343 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
6348 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
6350 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
6354 if FJetFuel
< JET_MAX
then
6356 FJetFuel
:= JET_MAX
;
6359 ITEM_MEDKIT_SMALL
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
6360 ITEM_MEDKIT_LARGE
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
6362 ITEM_ARMOR_GREEN
: if FArmor
< PLAYER_AP_SOFT
then FArmor
:= PLAYER_AP_SOFT
;
6363 ITEM_ARMOR_BLUE
: if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
6365 ITEM_SPHERE_BLUE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
6367 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) then
6369 if FHealth
< PLAYER_HP_LIMIT
then FHealth
:= PLAYER_HP_LIMIT
;
6370 if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
6373 ITEM_WEAPON_SAW
: FWeapon
[WEAPON_SAW
] := True;
6374 ITEM_WEAPON_SHOTGUN1
: FWeapon
[WEAPON_SHOTGUN1
] := True;
6375 ITEM_WEAPON_SHOTGUN2
: FWeapon
[WEAPON_SHOTGUN2
] := True;
6376 ITEM_WEAPON_CHAINGUN
: FWeapon
[WEAPON_CHAINGUN
] := True;
6377 ITEM_WEAPON_ROCKETLAUNCHER
: FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
6378 ITEM_WEAPON_PLASMA
: FWeapon
[WEAPON_PLASMA
] := True;
6379 ITEM_WEAPON_BFG
: FWeapon
[WEAPON_BFG
] := True;
6380 ITEM_WEAPON_SUPERPULEMET
: FWeapon
[WEAPON_SUPERPULEMET
] := True;
6381 ITEM_WEAPON_FLAMETHROWER
: FWeapon
[WEAPON_FLAMETHROWER
] := True;
6383 ITEM_AMMO_BULLETS
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
6384 ITEM_AMMO_BULLETS_BOX
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
6385 ITEM_AMMO_SHELLS
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
6386 ITEM_AMMO_SHELLS_BOX
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
6387 ITEM_AMMO_ROCKET
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
6388 ITEM_AMMO_ROCKET_BOX
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
6389 ITEM_AMMO_CELL
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
6390 ITEM_AMMO_CELL_BIG
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
6391 ITEM_AMMO_FUELCAN
: if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
6394 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
6395 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
6396 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
6397 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or
6398 (FMaxAmmo
[A_FUEL
] < AmmoLimits
[1, A_FUEL
]) then
6400 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[1, A_BULLETS
];
6401 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[1, A_SHELLS
];
6402 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[1, A_ROCKETS
];
6403 FMaxAmmo
[A_CELLS
] := AmmoLimits
[1, A_CELLS
];
6404 FMaxAmmo
[A_FUEL
] := AmmoLimits
[1, A_FUEL
];
6406 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
6407 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
6408 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
6409 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
6411 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
6414 ITEM_KEY_RED
: if not (R_KEY_RED
in FRulez
) then Include(FRulez
, R_KEY_RED
);
6415 ITEM_KEY_GREEN
: if not (R_KEY_GREEN
in FRulez
) then Include(FRulez
, R_KEY_GREEN
);
6416 ITEM_KEY_BLUE
: if not (R_KEY_BLUE
in FRulez
) then Include(FRulez
, R_KEY_BLUE
);
6418 ITEM_BOTTLE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
6419 ITEM_HELMET
: if FArmor
< PLAYER_AP_LIMIT
then IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
6424 if g_Game_IsNet
and g_Game_IsServer
then
6425 MH_SEND_PlayerStats(FUID
);
6428 procedure TPlayer
.FlySmoke(Times
: DWORD
= 1);
6433 if (Random(5) = 1) and (Times
= 1) then
6436 if BodyInLiquid(0, 0) then
6438 g_GFX_Bubbles(Obj
.X
+Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2)+Random(3)-1,
6439 Obj
.Y
+Obj
.Rect
.Height
+8, 1, 8, 4);
6440 if Random(2) = 0 then
6441 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
6443 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
6447 if g_Frames_Get(id
, 'FRAMES_SMOKE') then
6449 for i
:= 1 to Times
do
6451 Anim
:= TAnimation
.Create(id
, False, 3);
6453 g_GFX_OnceAnim(Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(Anim
.Width
div 2),
6454 Obj
.Y
+Obj
.Rect
.Height
-4+Random(8+Times
*2), Anim
, ONCEANIM_SMOKE
);
6460 procedure TPlayer
.OnFireFlame(Times
: DWORD
= 1);
6465 if (Random(10) = 1) and (Times
= 1) then
6468 if g_Frames_Get(id
, 'FRAMES_FLAME') then
6470 for i
:= 1 to Times
do
6472 Anim
:= TAnimation
.Create(id
, False, 3);
6474 g_GFX_OnceAnim(Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(Anim
.Width
div 2),
6475 Obj
.Y
+8+Random(8+Times
*2), Anim
, ONCEANIM_SMOKE
);
6481 procedure TPlayer
.PauseSounds(Enable
: Boolean);
6483 FSawSound
.Pause(Enable
);
6484 FSawSoundIdle
.Pause(Enable
);
6485 FSawSoundHit
.Pause(Enable
);
6486 FSawSoundSelect
.Pause(Enable
);
6487 FFlameSoundOn
.Pause(Enable
);
6488 FFlameSoundOff
.Pause(Enable
);
6489 FFlameSoundWork
.Pause(Enable
);
6490 FJetSoundFly
.Pause(Enable
);
6491 FJetSoundOn
.Pause(Enable
);
6492 FJetSoundOff
.Pause(Enable
);
6497 constructor TCorpse
.Create(X
, Y
: Integer; ModelName
: String; aMess
: Boolean);
6502 FObj
.Rect
:= PLAYER_CORPSERECT
;
6503 FModelName
:= ModelName
;
6508 FState
:= CORPSE_STATE_MESS
;
6509 g_PlayerModel_GetAnim(ModelName
, A_DIE2
, FAnimation
, FAnimationMask
);
6513 FState
:= CORPSE_STATE_NORMAL
;
6514 g_PlayerModel_GetAnim(ModelName
, A_DIE1
, FAnimation
, FAnimationMask
);
6518 destructor TCorpse
.Destroy();
6525 function TCorpse
.ObjPtr (): PObj
; inline; begin result
:= @FObj
; end;
6527 procedure TCorpse
.positionChanged (); inline; begin end;
6529 procedure TCorpse
.moveBy (dx
, dy
: Integer); inline;
6531 if (dx
<> 0) or (dy
<> 0) then
6540 procedure TCorpse
.getMapBox (out x
, y
, w
, h
: Integer); inline;
6542 x
:= FObj
.X
+PLAYER_CORPSERECT
.X
;
6543 y
:= FObj
.Y
+PLAYER_CORPSERECT
.Y
;
6544 w
:= PLAYER_CORPSERECT
.Width
;
6545 h
:= PLAYER_CORPSERECT
.Height
;
6549 procedure TCorpse
.Damage(Value
: Word; SpawnerUID
: Word; vx
, vy
: Integer);
6554 if FState
= CORPSE_STATE_REMOVEME
then
6557 FDamage
:= FDamage
+ Value
;
6559 if FDamage
> 150 then
6561 if FAnimation
<> nil then
6566 FState
:= CORPSE_STATE_REMOVEME
;
6568 g_Player_CreateGibs(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
6569 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2),
6570 FModelName
, FColor
);
6571 // Çâóê ìÿñà îò òðóïà:
6572 pm
:= g_PlayerModel_Get(FModelName
);
6573 pm
.PlaySound(MODELSOUND_DIE
, 5, FObj
.X
, FObj
.Y
);
6577 if (gBodyKillEvent
<> -1)
6578 and gDelayedEvents
[gBodyKillEvent
].Pending
then
6579 gDelayedEvents
[gBodyKillEvent
].Pending
:= False;
6580 gBodyKillEvent
:= g_Game_DelayEvent(DE_BODYKILL
, 1050, SpawnerUID
);
6585 Blood
:= g_PlayerModel_GetBlood(FModelName
);
6586 FObj
.Vel
.X
:= FObj
.Vel
.X
+ vx
;
6587 FObj
.Vel
.Y
:= FObj
.Vel
.Y
+ vy
;
6588 g_GFX_Blood(FObj
.X
+PLAYER_CORPSERECT
.X
+(PLAYER_CORPSERECT
.Width
div 2),
6589 FObj
.Y
+PLAYER_CORPSERECT
.Y
+(PLAYER_CORPSERECT
.Height
div 2),
6590 Value
, vx
, vy
, 16, (PLAYER_CORPSERECT
.Height
*2) div 3,
6591 Blood
.R
, Blood
.G
, Blood
.B
, Blood
.Kind
);
6595 procedure TCorpse
.Draw();
6599 if FState
= CORPSE_STATE_REMOVEME
then
6602 FObj
.lerp(gLerpFactor
, fX
, fY
);
6604 if FAnimation
<> nil then
6605 FAnimation
.Draw(fX
, fY
, TMirrorType
.None
);
6607 if FAnimationMask
<> nil then
6610 FAnimationMask
.Draw(fX
, fY
, TMirrorType
.None
);
6617 procedure TCorpse
.Update();
6621 if FState
= CORPSE_STATE_REMOVEME
then
6624 FObj
.oldX
:= FObj
.X
;
6625 FObj
.oldY
:= FObj
.Y
;
6627 if gTime
mod (GAME_TICK
*2) <> 0 then
6629 g_Obj_Move(@FObj
, True, True, True);
6630 positionChanged(); // this updates spatial accelerators
6634 // Ñîïðîòèâëåíèå âîçäóõà äëÿ òðóïà:
6635 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
6637 st
:= g_Obj_Move(@FObj
, True, True, True);
6638 positionChanged(); // this updates spatial accelerators
6640 if WordBool(st
and MOVE_FALLOUT
) then
6642 FState
:= CORPSE_STATE_REMOVEME
;
6646 if FAnimation
<> nil then
6647 FAnimation
.Update();
6648 if FAnimationMask
<> nil then
6649 FAnimationMask
.Update();
6653 procedure TCorpse
.SaveState (st
: TStream
);
6660 utils
.writeSign(st
, 'CORP');
6661 utils
.writeInt(st
, Byte(0));
6663 utils
.writeInt(st
, Byte(FState
));
6665 utils
.writeInt(st
, Byte(FDamage
));
6667 utils
.writeInt(st
, Byte(FColor
.R
));
6668 utils
.writeInt(st
, Byte(FColor
.G
));
6669 utils
.writeInt(st
, Byte(FColor
.B
));
6671 Obj_SaveState(st
, @FObj
);
6672 utils
.writeInt(st
, Word(FPlayerUID
));
6674 anim
:= (FAnimation
<> nil);
6675 utils
.writeBool(st
, anim
);
6676 // Åñëè åñòü - ñîõðàíÿåì
6677 if anim
then FAnimation
.SaveState(st
);
6678 // Åñòü ëè ìàñêà àíèìàöèè
6679 anim
:= (FAnimationMask
<> nil);
6680 utils
.writeBool(st
, anim
);
6681 // Åñëè åñòü - ñîõðàíÿåì
6682 if anim
then FAnimationMask
.SaveState(st
);
6686 procedure TCorpse
.LoadState (st
: TStream
);
6693 if not utils
.checkSign(st
, 'CORP') then raise XStreamError
.Create('invalid corpse signature');
6694 if (utils
.readByte(st
) <> 0) then raise XStreamError
.Create('invalid corpse version');
6696 FState
:= utils
.readByte(st
);
6698 FDamage
:= utils
.readByte(st
);
6700 FColor
.R
:= utils
.readByte(st
);
6701 FColor
.G
:= utils
.readByte(st
);
6702 FColor
.B
:= utils
.readByte(st
);
6704 Obj_LoadState(@FObj
, st
);
6705 FPlayerUID
:= utils
.readWord(st
);
6707 anim
:= utils
.readBool(st
);
6708 // Åñëè åñòü - çàãðóæàåì
6711 Assert(FAnimation
<> nil, 'TCorpse.LoadState: no FAnimation');
6712 FAnimation
.LoadState(st
);
6714 // Åñòü ëè ìàñêà àíèìàöèè
6715 anim
:= utils
.readBool(st
);
6716 // Åñëè åñòü - çàãðóæàåì
6719 Assert(FAnimationMask
<> nil, 'TCorpse.LoadState: no FAnimationMask');
6720 FAnimationMask
.LoadState(st
);
6726 constructor TBot
.Create();
6733 FSpectator
:= False;
6740 for a
:= WP_FIRST
to WP_LAST
do
6742 FDifficult
.WeaponPrior
[a
] := WEAPON_PRIOR1
[a
];
6743 FDifficult
.CloseWeaponPrior
[a
] := WEAPON_PRIOR2
[a
];
6744 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
6748 destructor TBot
.Destroy();
6751 inherited Destroy();
6754 procedure TBot
.Draw();
6758 //if FTargetUID <> 0 then e_DrawLine(1, FObj.X, FObj.Y, g_Player_Get(FTargetUID).FObj.X,
6759 // g_Player_Get(FTargetUID).FObj.Y, 255, 0, 0);
6762 procedure TBot
.Respawn(Silent
: Boolean; Force
: Boolean = False);
6764 inherited Respawn(Silent
, Force
);
6767 FSelectedWeapon
:= FCurrWeap
;
6772 procedure TBot
.UpdateCombat();
6785 TTargetRecord
= array of TTarget
;
6787 function Compare(a
, b
: TTarget
): Integer;
6789 if a
.Line
and not b
.Line
then // A íà ëèíèè îãíÿ
6792 if not a
.Line
and b
.Line
then // B íà ëèíèè îãíÿ
6794 else // È A, è B íà ëèíèè èëè íå íà ëèíèè îãíÿ
6795 if (a
.Line
and b
.Line
) or ((not a
.Line
) and (not b
.Line
)) then
6797 if a
.Dist
> b
.Dist
then // B áëèæå
6799 else // A áëèæå èëè ðàâíîóäàëåííî ñ B
6802 else // Ñòðàííî -> A
6807 a
, x1
, y1
, x2
, y2
: Integer;
6808 targets
: TTargetRecord
;
6810 Target
, BestTarget
: TTarget
;
6811 firew
, fireh
: Integer;
6815 vsPlayer
, vsMonster
, ok
: Boolean;
6818 function monsUpdate (mon
: TMonster
): Boolean;
6820 result
:= false; // don't stop
6821 if mon
.alive
and (mon
.MonsterType
<> MONSTER_BARREL
) then
6823 if not TargetOnScreen(mon
.Obj
.X
+mon
.Obj
.Rect
.X
, mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
) then exit
;
6825 x2
:= mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2);
6826 y2
:= mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+(mon
.Obj
.Rect
.Height
div 2);
6828 // Åñëè ìîíñòð íà ýêðàíå è íå ïðèêðûò ñòåíîé
6829 if g_TraceVector(x1
, y1
, x2
, y2
) then
6831 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé
6832 SetLength(targets
, Length(targets
)+1);
6833 with targets
[High(targets
)] do
6840 Rect
:= mon
.Obj
.Rect
;
6841 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6842 Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6843 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6852 vsPlayer
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
);
6853 vsMonster
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
);
6855 // Åñëè òåêóùåå îðóæèå íå òî, ÷òî íóæíî, òî ìåíÿåì:
6856 if FCurrWeap
<> FSelectedWeapon
then
6859 // Åñëè íóæíî ñòðåëÿòü è íóæíîå îðóæèå, òî íàæàòü "Ñòðåëÿòü":
6860 if (GetAIFlag('NEEDFIRE') <> '') and (FCurrWeap
= FSelectedWeapon
) then
6862 RemoveAIFlag('NEEDFIRE');
6865 WEAPON_PLASMA
, WEAPON_SUPERPULEMET
, WEAPON_CHAINGUN
: PressKey(KEY_FIRE
, 20);
6866 WEAPON_SAW
, WEAPON_KASTET
, WEAPON_FLAMETHROWER
: PressKey(KEY_FIRE
, 40);
6867 else PressKey(KEY_FIRE
);
6871 // Êîîðäèíàòû ñòâîëà:
6872 x1
:= FObj
.X
+ WEAPONPOINT
[FDirection
].X
;
6873 y1
:= FObj
.Y
+ WEAPONPOINT
[FDirection
].Y
;
6875 Target
.UID
:= FTargetUID
;
6878 if Target
.UID
<> 0 then
6879 begin // Öåëü åñòü - íàñòðàèâàåì
6880 if (g_GetUIDType(Target
.UID
) = UID_PLAYER
) and
6883 tpla
:= g_Player_Get(Target
.UID
);
6887 if (@FObj
) <> nil then
6894 Target
.cX
:= Target
.X
+ PLAYER_RECT_CX
;
6895 Target
.cY
:= Target
.Y
+ PLAYER_RECT_CY
;
6896 Target
.Rect
:= PLAYER_RECT
;
6897 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6898 Target
.Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6899 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6900 Target
.IsPlayer
:= True;
6904 if (g_GetUIDType(Target
.UID
) = UID_MONSTER
) and
6907 mon
:= g_Monsters_ByUID(Target
.UID
);
6910 Target
.X
:= mon
.Obj
.X
;
6911 Target
.Y
:= mon
.Obj
.Y
;
6913 Target
.cX
:= Target
.X
+ mon
.Obj
.Rect
.X
+ (mon
.Obj
.Rect
.Width
div 2);
6914 Target
.cY
:= Target
.Y
+ mon
.Obj
.Rect
.Y
+ (mon
.Obj
.Rect
.Height
div 2);
6915 Target
.Rect
:= mon
.Obj
.Rect
;
6916 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6917 Target
.Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6918 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6919 Target
.IsPlayer
:= False;
6926 begin // Öåëè íåò - îáíóëÿåì
6931 Target
.Visible
:= False;
6932 Target
.Line
:= False;
6933 Target
.IsPlayer
:= False;
6938 // Åñëè öåëü íå âèäèìà èëè íå íà ëèíèè îãíÿ, òî èùåì âñå âîçìîæíûå öåëè:
6939 if (not Target
.Line
) or (not Target
.Visible
) then
6943 for a
:= 0 to High(gPlayers
) do
6944 if (gPlayers
[a
] <> nil) and (gPlayers
[a
].alive
) and
6945 (gPlayers
[a
].FUID
<> FUID
) and
6946 (not SameTeam(FUID
, gPlayers
[a
].FUID
)) and
6947 (not gPlayers
[a
].NoTarget
) and
6948 (gPlayers
[a
].FMegaRulez
[MR_INVIS
] < gTime
) then
6950 if not TargetOnScreen(gPlayers
[a
].FObj
.X
+ PLAYER_RECT
.X
,
6951 gPlayers
[a
].FObj
.Y
+ PLAYER_RECT
.Y
) then
6954 x2
:= gPlayers
[a
].FObj
.X
+ PLAYER_RECT_CX
;
6955 y2
:= gPlayers
[a
].FObj
.Y
+ PLAYER_RECT_CY
;
6957 // Åñëè èãðîê íà ýêðàíå è íå ïðèêðûò ñòåíîé:
6958 if g_TraceVector(x1
, y1
, x2
, y2
) then
6960 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé:
6961 SetLength(targets
, Length(targets
)+1);
6962 with targets
[High(targets
)] do
6964 UID
:= gPlayers
[a
].FUID
;
6965 X
:= gPlayers
[a
].FObj
.X
;
6966 Y
:= gPlayers
[a
].FObj
.Y
;
6969 Rect
:= PLAYER_RECT
;
6970 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6971 Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6972 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6980 if vsMonster
then g_Mons_ForEach(monsUpdate
);
6983 // Åñëè åñòü âîçìîæíûå öåëè:
6984 // (Âûáèðàåì ëó÷øóþ, ìåíÿåì îðóæèå è áåæèì ê íåé/îò íåå)
6985 if targets
<> nil then
6987 // Âûáèðàåì íàèëó÷øóþ öåëü:
6988 BestTarget
:= targets
[0];
6989 if Length(targets
) > 1 then
6990 for a
:= 1 to High(targets
) do
6991 if Compare(BestTarget
, targets
[a
]) = 1 then
6992 BestTarget
:= targets
[a
];
6994 // Åñëè ëó÷øàÿ öåëü "âèäíåå" òåêóùåé, òî òåêóùàÿ := ëó÷øàÿ:
6995 if ((not Target
.Visible
) and BestTarget
.Visible
and (Target
.UID
<> BestTarget
.UID
)) or
6996 ((not Target
.Line
) and BestTarget
.Line
and BestTarget
.Visible
) then
6998 Target
:= BestTarget
;
7000 if (Healthy() = 3) or ((Healthy() = 2)) then
7001 begin // Åñëè çäîðîâû - äîãîíÿåì
7002 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
7003 SetAIFlag('GORIGHT', '1');
7004 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
7005 SetAIFlag('GOLEFT', '1');
7008 begin // Åñëè ïîáèòû - óáåãàåì
7009 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) then
7010 SetAIFlag('GORIGHT', '1');
7011 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
7012 SetAIFlag('GOLEFT', '1');
7015 // Âûáèðàåì îðóæèå íà îñíîâå ðàññòîÿíèÿ è ïðèîðèòåòîâ:
7016 SelectWeapon(Abs(x1
-Target
.cX
));
7021 // (Äîãîíÿåì/óáåãàåì, ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëè)
7022 // (Åñëè öåëü äàëåêî, òî õâàòèò ñëåäèòü çà íåé)
7023 if Target
.UID
<> 0 then
7025 if not TargetOnScreen(Target
.X
+ Target
.Rect
.X
,
7026 Target
.Y
+ Target
.Rect
.Y
) then
7027 begin // Öåëü ñáåæàëà ñ "ýêðàíà"
7028 if (Healthy() = 3) or ((Healthy() = 2)) then
7029 begin // Åñëè çäîðîâû - äîãîíÿåì
7030 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
7031 SetAIFlag('GORIGHT', '1');
7032 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
7033 SetAIFlag('GOLEFT', '1');
7036 begin // Åñëè ïîáèòû - çàáûâàåì î öåëè è óáåãàåì
7038 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) then
7039 SetAIFlag('GORIGHT', '1');
7040 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
7041 SetAIFlag('GOLEFT', '1');
7045 begin // Öåëü ïîêà íà "ýêðàíå"
7046 // Åñëè öåëü íå çàãîðîæåíà ñòåíîé, òî îòìå÷àåì, êîãäà åå âèäåëè:
7047 if g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
7048 FLastVisible
:= gTime
;
7049 // Åñëè ðàçíèöà âûñîò íå âåëèêà, òî äîãîíÿåì:
7050 if (Abs(FObj
.Y
-Target
.Y
) <= 128) then
7052 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
7053 SetAIFlag('GORIGHT', '1');
7054 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
7055 SetAIFlag('GOLEFT', '1');
7059 // Âûáèðàåì óãîë ââåðõ:
7060 if FDirection
= TDirection
.D_LEFT
then
7061 angle
:= ANGLE_LEFTUP
7063 angle
:= ANGLE_RIGHTUP
;
7065 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7066 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7068 // Åñëè ïðè óãëå ââåðõ ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
7069 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
7070 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128), //96
7071 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
7072 Target
.Rect
.Width
, Target
.Rect
.Height
) and
7073 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
7074 begin // òî íóæíî ñòðåëÿòü ââåðõ
7075 SetAIFlag('NEEDFIRE', '1');
7076 SetAIFlag('NEEDSEEUP', '1');
7079 // Âûáèðàåì óãîë âíèç:
7080 if FDirection
= TDirection
.D_LEFT
then
7081 angle
:= ANGLE_LEFTDOWN
7083 angle
:= ANGLE_RIGHTDOWN
;
7085 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7086 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7088 // Åñëè ïðè óãëå âíèç ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
7089 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
7090 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
7091 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
7092 Target
.Rect
.Width
, Target
.Rect
.Height
) and
7093 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
7094 begin // òî íóæíî ñòðåëÿòü âíèç
7095 SetAIFlag('NEEDFIRE', '1');
7096 SetAIFlag('NEEDSEEDOWN', '1');
7099 // Åñëè öåëü âèäíî è îíà íà òàêîé æå âûñîòå:
7100 if Target
.Visible
and
7101 (y1
+4 < Target
.Y
+Target
.Rect
.Y
+Target
.Rect
.Height
) and
7102 (y1
-4 > Target
.Y
+Target
.Rect
.Y
) then
7104 // Åñëè èäåì â ñòîðîíó öåëè, òî íàäî ñòðåëÿòü:
7105 if ((FDirection
= TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) or
7106 ((FDirection
= TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
7107 begin // òî íóæíî ñòðåëÿòü âïåðåä
7108 SetAIFlag('NEEDFIRE', '1');
7109 SetAIFlag('NEEDSEEDOWN', '');
7110 SetAIFlag('NEEDSEEUP', '');
7112 // Åñëè öåëü â ïðåäåëàõ "ýêðàíà" è ñëîæíîñòü ïîçâîëÿåò ïðûæêè ñáëèæåíèÿ:
7113 if Abs(FObj
.X
-Target
.X
) < Trunc(gPlayerScreenSize
.X
*0.75) then
7114 if GetRnd(FDifficult
.CloseJump
) then
7115 begin // òî åñëè ïîâåçåò - ïðûãàåì (îñîáåííî, åñëè áëèçêî)
7116 if Abs(FObj
.X
-Target
.X
) < 128 then
7120 if Random(a
) = 0 then
7121 SetAIFlag('NEEDJUMP', '1');
7125 // Åñëè öåëü âñå åùå åñòü:
7126 if Target
.UID
<> 0 then
7127 if gTime
-FLastVisible
> 2000 then // Åñëè âèäåëè äàâíî
7128 Target
.UID
:= 0 // òî çàáûòü öåëü
7129 else // Åñëè âèäåëè íåäàâíî
7130 begin // íî öåëü óáèëè
7131 if Target
.IsPlayer
then
7132 begin // Öåëü - èãðîê
7133 pla
:= g_Player_Get(Target
.UID
);
7134 if (pla
= nil) or (not pla
.alive
) or pla
.NoTarget
or
7135 (pla
.FMegaRulez
[MR_INVIS
] >= gTime
) then
7136 Target
.UID
:= 0; // òî çàáûòü öåëü
7139 begin // Öåëü - ìîíñòð
7140 mon
:= g_Monsters_ByUID(Target
.UID
);
7141 if (mon
= nil) or (not mon
.alive
) then
7142 Target
.UID
:= 0; // òî çàáûòü öåëü
7145 end; // if Target.UID <> 0
7147 FTargetUID
:= Target
.UID
;
7149 // Åñëè âîçìîæíûõ öåëåé íåò:
7150 // (Àòàêà ÷åãî-íèáóäü ñëåâà èëè ñïðàâà)
7151 if targets
= nil then
7152 if GetAIFlag('ATTACKLEFT') <> '' then
7153 begin // Åñëè íóæíî àòàêîâàòü íàëåâî
7154 RemoveAIFlag('ATTACKLEFT');
7156 SetAIFlag('NEEDJUMP', '1');
7158 if RunDirection() = TDirection
.D_RIGHT
then
7159 begin // Èäåì íå â òó ñòîðîíó
7160 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
7161 begin // Åñëè çäîðîâû, òî, âîçìîæíî, ñòðåëÿåì áåæèì âëåâî è ñòðåëÿåì
7162 SetAIFlag('NEEDFIRE', '1');
7163 SetAIFlag('GOLEFT', '1');
7167 begin // Èäåì â íóæíóþ ñòîðîíó
7168 if GetRnd(FDifficult
.InvisFire
) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
7169 SetAIFlag('NEEDFIRE', '1');
7170 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
7171 SetAIFlag('GORIGHT', '1');
7175 if GetAIFlag('ATTACKRIGHT') <> '' then
7176 begin // Åñëè íóæíî àòàêîâàòü íàïðàâî
7177 RemoveAIFlag('ATTACKRIGHT');
7179 SetAIFlag('NEEDJUMP', '1');
7181 if RunDirection() = TDirection
.D_LEFT
then
7182 begin // Èäåì íå â òó ñòîðîíó
7183 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
7184 begin // Åñëè çäîðîâû, òî, âîçìîæíî, áåæèì âïðàâî è ñòðåëÿåì
7185 SetAIFlag('NEEDFIRE', '1');
7186 SetAIFlag('GORIGHT', '1');
7191 if GetRnd(FDifficult
.InvisFire
) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
7192 SetAIFlag('NEEDFIRE', '1');
7193 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
7194 SetAIFlag('GOLEFT', '1');
7198 //HACK! (does it belongs there?)
7199 RealizeCurrentWeapon();
7201 // Åñëè åñòü âîçìîæíûå öåëè:
7202 // (Ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëÿì)
7203 if (targets
<> nil) and (GetAIFlag('NEEDFIRE') <> '') then
7204 for a
:= 0 to High(targets
) do
7206 // Åñëè ìîæåì ñòðåëÿòü ïî äèàãîíàëè:
7207 if GetRnd(FDifficult
.DiagFire
) then
7209 // Èùåì öåëü ñâåðõó è ñòðåëÿåì, åñëè åñòü:
7210 if FDirection
= TDirection
.D_LEFT
then
7211 angle
:= ANGLE_LEFTUP
7213 angle
:= ANGLE_RIGHTUP
;
7215 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7216 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7218 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
7219 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
7220 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
7221 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
7222 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
7224 SetAIFlag('NEEDFIRE', '1');
7225 SetAIFlag('NEEDSEEUP', '1');
7228 // Èùåì öåëü ñíèçó è ñòðåëÿåì, åñëè åñòü:
7229 if FDirection
= TDirection
.D_LEFT
then
7230 angle
:= ANGLE_LEFTDOWN
7232 angle
:= ANGLE_RIGHTDOWN
;
7234 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7235 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7237 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
7238 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
7239 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
7240 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
7241 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
7243 SetAIFlag('NEEDFIRE', '1');
7244 SetAIFlag('NEEDSEEDOWN', '1');
7248 // Åñëè öåëü "ïåðåä íîñîì", òî ñòðåëÿåì:
7249 if targets
[a
].Line
and targets
[a
].Visible
and
7250 (((FDirection
= TDirection
.D_LEFT
) and (targets
[a
].X
< FObj
.X
)) or
7251 ((FDirection
= TDirection
.D_RIGHT
) and (targets
[a
].X
> FObj
.X
))) then
7253 SetAIFlag('NEEDFIRE', '1');
7258 // Åñëè ëåòèò ïóëÿ, òî, âîçìîæíî, ïîäïðûãèâàåì:
7259 if g_Weapon_Danger(FUID
, FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
,
7260 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
,
7261 40+GetInterval(FDifficult
.Cover
, 40)) then
7262 SetAIFlag('NEEDJUMP', '1');
7264 // Åñëè êîí÷èëèñü ïàòîðíû, òî íóæíî ñìåíèòü îðóæèå:
7265 ammo
:= GetAmmoByWeapon(FCurrWeap
);
7266 if ((FCurrWeap
= WEAPON_SHOTGUN2
) and (ammo
< 2)) or
7267 ((FCurrWeap
= WEAPON_BFG
) and (ammo
< 40)) or
7269 SetAIFlag('SELECTWEAPON', '1');
7271 // Åñëè íóæíî ñìåíèòü îðóæèå, òî âûáèðàåì íóæíîå:
7272 if GetAIFlag('SELECTWEAPON') = '1' then
7275 RemoveAIFlag('SELECTWEAPON');
7279 procedure TBot
.Update();
7292 // Ïðîâåðÿåì, îòêëþ÷¸í ëè AI áîòîâ
7293 if (g_debug_BotAIOff
= 1) and (Team
= TEAM_RED
) then
7295 if (g_debug_BotAIOff
= 2) and (Team
= TEAM_BLUE
) then
7297 if g_debug_BotAIOff
= 3 then
7307 RealizeCurrentWeapon();
7314 procedure TBot
.ReleaseKey(Key
: Byte);
7323 function TBot
.KeyPressed(Key
: Word): Boolean;
7325 Result
:= FKeys
[Key
].Pressed
;
7328 function TBot
.GetAIFlag(aName
: String20
): String20
;
7334 aName
:= LowerCase(aName
);
7336 if FAIFlags
<> nil then
7337 for a
:= 0 to High(FAIFlags
) do
7338 if LowerCase(FAIFlags
[a
].Name
) = aName
then
7340 Result
:= FAIFlags
[a
].Value
;
7345 procedure TBot
.RemoveAIFlag(aName
: String20
);
7349 if FAIFlags
= nil then Exit
;
7351 aName
:= LowerCase(aName
);
7353 for a
:= 0 to High(FAIFlags
) do
7354 if LowerCase(FAIFlags
[a
].Name
) = aName
then
7356 if a
<> High(FAIFlags
) then
7357 for b
:= a
to High(FAIFlags
)-1 do
7358 FAIFlags
[b
] := FAIFlags
[b
+1];
7360 SetLength(FAIFlags
, Length(FAIFlags
)-1);
7365 procedure TBot
.SetAIFlag(aName
, fValue
: String20
);
7373 aName
:= LowerCase(aName
);
7375 if FAIFlags
<> nil then
7376 for a
:= 0 to High(FAIFlags
) do
7377 if LowerCase(FAIFlags
[a
].Name
) = aName
then
7383 if ok
then FAIFlags
[a
].Value
:= fValue
7386 SetLength(FAIFlags
, Length(FAIFlags
)+1);
7387 with FAIFlags
[High(FAIFlags
)] do
7395 procedure TBot
.UpdateMove
;
7397 procedure GoLeft(Time
: Word = 1);
7399 ReleaseKey(KEY_LEFT
);
7400 ReleaseKey(KEY_RIGHT
);
7401 PressKey(KEY_LEFT
, Time
);
7402 SetDirection(TDirection
.D_LEFT
);
7405 procedure GoRight(Time
: Word = 1);
7407 ReleaseKey(KEY_LEFT
);
7408 ReleaseKey(KEY_RIGHT
);
7409 PressKey(KEY_RIGHT
, Time
);
7410 SetDirection(TDirection
.D_RIGHT
);
7413 function Rnd(a
: Word): Boolean;
7415 Result
:= Random(a
) = 0;
7418 procedure Turn(Time
: Word = 1200);
7420 if RunDirection() = TDirection
.D_LEFT
then GoRight(Time
) else GoLeft(Time
);
7425 ReleaseKey(KEY_LEFT
);
7426 ReleaseKey(KEY_RIGHT
);
7429 function CanRunLeft(): Boolean;
7431 Result
:= not CollideLevel(-1, 0);
7434 function CanRunRight(): Boolean;
7436 Result
:= not CollideLevel(1, 0);
7439 function CanRun(): Boolean;
7441 if RunDirection() = TDirection
.D_LEFT
then Result
:= CanRunLeft() else Result
:= CanRunRight();
7444 procedure Jump(Time
: Word = 30);
7446 PressKey(KEY_JUMP
, Time
);
7449 function NearHole(): Boolean;
7453 { TODO 5 : Ëåñòíèöû }
7454 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7455 for x
:= 1 to PLAYER_RECT
.Width
do
7456 if (not StayOnStep(x
*sx
, 0)) and
7457 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7458 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7467 function BorderHole(): Boolean;
7471 { TODO 5 : Ëåñòíèöû }
7472 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7473 for x
:= 1 to PLAYER_RECT
.Width
do
7474 if (not StayOnStep(x
*sx
, 0)) and
7475 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7476 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7478 for xx
:= x
to x
+32 do
7479 if CollideLevel(xx
*sx
, PLAYER_RECT
.Height
) then
7489 function NearDeepHole(): Boolean;
7495 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7498 for x
:= 1 to PLAYER_RECT
.Width
do
7499 if (not StayOnStep(x
*sx
, 0)) and
7500 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7501 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7503 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
7505 if CollideLevel(x
*sx
, PLAYER_RECT
.Height
*y
) then Exit
;
7510 end else Result
:= False;
7513 function OverDeepHole(): Boolean;
7520 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
7522 if CollideLevel(0, PLAYER_RECT
.Height
*y
) then Exit
;
7529 function OnGround(): Boolean;
7531 Result
:= StayOnStep(0, 0) or CollideLevel(0, 1);
7534 function OnLadder(): Boolean;
7536 Result
:= FullInStep(0, 0);
7539 function BelowLadder(): Boolean;
7541 Result
:= (FullInStep(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) and
7542 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
7543 (FullInStep(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) and
7544 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
7547 function BelowLiftUp(): Boolean;
7549 Result
:= ((FullInLift(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) = -1) and
7550 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
7551 ((FullInLift(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) = -1) and
7552 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
7555 function OnTopLift(): Boolean;
7557 Result
:= (FullInLift(0, 0) = -1) and (FullInLift(0, -32) = 0);
7560 function CanJumpOver(): Boolean;
7564 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7568 if not CollideLevel(sx
, 0) then Exit
;
7570 for y
:= 1 to BOT_MAXJUMP
do
7571 if CollideLevel(0, -y
) then Exit
else
7572 if not CollideLevel(sx
, -y
) then
7579 function CanJumpUp(Dist
: ShortInt): Boolean;
7586 if CollideLevel(Dist
, 0) then Exit
;
7589 for y
:= 0 to BOT_MAXJUMP
do
7590 if CollideLevel(Dist
, -y
) then
7599 for yy
:= y
+1 to BOT_MAXJUMP
do
7600 if not CollideLevel(Dist
, -yy
) then
7609 for y
:= 0 to BOT_MAXJUMP
do
7610 if CollideLevel(0, -y
) then
7618 if y
< yy
then Exit
;
7623 function IsSafeTrigger(): Boolean;
7628 if gTriggers
= nil then
7630 for a
:= 0 to High(gTriggers
) do
7631 if Collide(gTriggers
[a
].X
,
7634 gTriggers
[a
].Height
) and
7635 (gTriggers
[a
].TriggerType
in [TRIGGER_EXIT
, TRIGGER_CLOSEDOOR
,
7636 TRIGGER_CLOSETRAP
, TRIGGER_TRAP
,
7637 TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
,
7638 TRIGGER_ONOFF
, TRIGGER_SPAWNMONSTER
,
7639 TRIGGER_DAMAGE
, TRIGGER_SHOT
]) then
7644 // Âîçìîæíî, íàæèìàåì êíîïêó:
7645 if Rnd(16) and IsSafeTrigger() then
7648 // Åñëè ïîä ëèôòîì èëè ñòóïåíüêàìè, òî, âîçìîæíî, ïðûãàåì:
7649 if OnLadder() or ((BelowLadder() or BelowLiftUp()) and Rnd(8)) then
7651 ReleaseKey(KEY_LEFT
);
7652 ReleaseKey(KEY_RIGHT
);
7656 // Èäåì âëåâî, åñëè íàäî áûëî:
7657 if GetAIFlag('GOLEFT') <> '' then
7659 RemoveAIFlag('GOLEFT');
7660 if CanRunLeft() then
7664 // Èäåì âïðàâî, åñëè íàäî áûëî:
7665 if GetAIFlag('GORIGHT') <> '' then
7667 RemoveAIFlag('GORIGHT');
7668 if CanRunRight() then
7672 // Åñëè âûëåòåëè çà êàðòó, òî ïðîáóåì âåðíóòüñÿ:
7673 if FObj
.X
< -32 then
7676 if FObj
.X
+32 > gMapInfo
.Width
then
7679 // Ïðûãàåì, åñëè íàäî áûëî:
7680 if GetAIFlag('NEEDJUMP') <> '' then
7683 RemoveAIFlag('NEEDJUMP');
7686 // Ñìîòðèì ââåðõ, åñëè íàäî áûëî:
7687 if GetAIFlag('NEEDSEEUP') <> '' then
7690 ReleaseKey(KEY_DOWN
);
7691 PressKey(KEY_UP
, 20);
7692 RemoveAIFlag('NEEDSEEUP');
7695 // Ñìîòðèì âíèç, åñëè íàäî áûëî:
7696 if GetAIFlag('NEEDSEEDOWN') <> '' then
7699 ReleaseKey(KEY_DOWN
);
7700 PressKey(KEY_DOWN
, 20);
7701 RemoveAIFlag('NEEDSEEDOWN');
7704 // Åñëè íóæíî áûëî â äûðó è ìû íå íà çåìëå, òî ïîêîðíî ëåòèì:
7705 if GetAIFlag('GOINHOLE') <> '' then
7706 if not OnGround() then
7708 ReleaseKey(KEY_LEFT
);
7709 ReleaseKey(KEY_RIGHT
);
7710 RemoveAIFlag('GOINHOLE');
7711 SetAIFlag('FALLINHOLE', '1');
7714 // Åñëè ïàäàëè è äîñòèãëè çåìëè, òî õâàòèò ïàäàòü:
7715 if GetAIFlag('FALLINHOLE') <> '' then
7717 RemoveAIFlag('FALLINHOLE');
7719 // Åñëè ëåòåëè ïðÿìî è ñåé÷àñ íå íà ëåñòíèöå èëè íà âåðøèíå ëèôòà, òî îòõîäèì â ñòîðîíó:
7720 if not (KeyPressed(KEY_LEFT
) or KeyPressed(KEY_RIGHT
)) then
7721 if GetAIFlag('FALLINHOLE') = '' then
7722 if (not OnLadder()) or (FObj
.Vel
.Y
>= 0) or (OnTopLift()) then
7728 // Åñëè íà çåìëå è ìîæíî ïîäïðûãíóòü, òî, âîçìîæíî, ïðûãàåì:
7730 CanJumpUp(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*32) and
7734 // Åñëè íà çåìëå è âîçëå äûðû (ãëóáèíà > 2 ðîñòîâ èãðîêà):
7735 if OnGround() and NearHole() then
7736 if NearDeepHole() then // Åñëè ýòî áåçäíà
7738 0..3: Turn(); // Áåæèì îáðàòíî
7739 4: Jump(); // Ïðûãàåì
7740 5: begin // Ïðûãàåì îáðàòíî
7745 else // Ýòî íå áåçäíà è ìû åùå íå ëåòèì òóäà
7746 if GetAIFlag('GOINHOLE') = '' then
7748 0: Turn(); // Íå íóæíî òóäà
7749 1: Jump(); // Âäðóã ïîâåçåò - ïðûãàåì
7750 else // Åñëè ÿìà ñ ãðàíèöåé, òî ïðè ñëó÷àå ìîæíî òóäà ïðûãíóòü
7751 if BorderHole() then
7752 SetAIFlag('GOINHOLE', '1');
7755 // Åñëè íà çåìëå, íî íåêóäà èäòè:
7756 if (not CanRun()) and OnGround() then
7758 // Åñëè ìû íà ëåñòíèöå èëè ìîæíî ïåðåïðûãíóòü, òî ïðûãàåì:
7759 if CanJumpOver() or OnLadder() then
7761 else // èíà÷å ïîïûòàåìñÿ â äðóãóþ ñòîðîíó
7762 if Random(2) = 0 then
7764 if IsSafeTrigger() then
7770 // Îñòàëîñü ìàëî âîçäóõà:
7771 if FAir
< 36 * 2 then
7774 // Âûáèðàåìñÿ èç êèñëîòû, åñëè íåò êîñòþìà, îáîæãëèñü, èëè ìàëî çäîðîâüÿ:
7775 if (FMegaRulez
[MR_SUIT
] < gTime
) and ((FLastHit
= HIT_ACID
) or (Healthy() <= 1)) then
7776 if BodyInAcid(0, 0) then
7780 function TBot
.FullInStep(XInc
, YInc
: Integer): Boolean;
7782 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
7783 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_STEP
, False);
7786 {function TBot.NeedItem(Item: Byte): Byte;
7791 procedure TBot
.SelectWeapon(Dist
: Integer);
7795 function HaveAmmo(weapon
: Byte): Boolean;
7798 WEAPON_PISTOL
: Result
:= FAmmo
[A_BULLETS
] >= 1;
7799 WEAPON_SHOTGUN1
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7800 WEAPON_SHOTGUN2
: Result
:= FAmmo
[A_SHELLS
] >= 2;
7801 WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
] >= 10;
7802 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
] >= 1;
7803 WEAPON_PLASMA
: Result
:= FAmmo
[A_CELLS
] >= 10;
7804 WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
] >= 40;
7805 WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7806 WEAPON_FLAMETHROWER
: Result
:= FAmmo
[A_FUEL
] >= 1;
7807 else Result
:= True;
7812 if Dist
= -1 then Dist
:= BOT_LONGDIST
;
7814 if Dist
> BOT_LONGDIST
then
7815 begin // Äàëüíèé áîé
7817 if FWeapon
[FDifficult
.WeaponPrior
[a
]] and HaveAmmo(FDifficult
.WeaponPrior
[a
]) then
7819 FSelectedWeapon
:= FDifficult
.WeaponPrior
[a
];
7823 else //if Dist > BOT_UNSAFEDIST then
7824 begin // Áëèæíèé áîé
7826 if FWeapon
[FDifficult
.CloseWeaponPrior
[a
]] and HaveAmmo(FDifficult
.CloseWeaponPrior
[a
]) then
7828 FSelectedWeapon
:= FDifficult
.CloseWeaponPrior
[a
];
7835 if FWeapon[FDifficult.SafeWeaponPrior[a]] and HaveAmmo(FDifficult.SafeWeaponPrior[a]) then
7837 FSelectedWeapon := FDifficult.SafeWeaponPrior[a];
7843 function TBot
.PickItem(ItemType
: Byte; force
: Boolean; var remove
: Boolean): Boolean;
7845 Result
:= inherited PickItem(ItemType
, force
, remove
);
7847 if Result
then SetAIFlag('SELECTWEAPON', '1');
7850 function TBot
.Heal(value
: Word; Soft
: Boolean): Boolean;
7852 Result
:= inherited Heal(value
, Soft
);
7855 function TBot
.Healthy(): Byte;
7857 if FMegaRulez
[MR_INVUL
] >= gTime
then Result
:= 3
7858 else if (FHealth
> 80) or ((FHealth
> 50) and (FArmor
> 20)) then Result
:= 3
7859 else if (FHealth
> 50) then Result
:= 2
7860 else if (FHealth
> 20) then Result
:= 1
7864 function TBot
.TargetOnScreen(TX
, TY
: Integer): Boolean;
7866 Result
:= (Abs(FObj
.X
-TX
) <= Trunc(gPlayerScreenSize
.X
*0.6)) and
7867 (Abs(FObj
.Y
-TY
) <= Trunc(gPlayerScreenSize
.Y
*0.6));
7870 procedure TBot
.OnDamage(Angle
: SmallInt);
7878 if (Angle
= 0) or (Angle
= 180) then
7881 if (g_GetUIDType(FLastSpawnerUID
) = UID_PLAYER
) and
7882 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
) then
7884 pla
:= g_Player_Get(FLastSpawnerUID
);
7885 ok
:= not TargetOnScreen(pla
.FObj
.X
+ PLAYER_RECT
.X
,
7886 pla
.FObj
.Y
+ PLAYER_RECT
.Y
);
7889 if (g_GetUIDType(FLastSpawnerUID
) = UID_MONSTER
) and
7890 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
) then
7892 mon
:= g_Monsters_ByUID(FLastSpawnerUID
);
7893 ok
:= not TargetOnScreen(mon
.Obj
.X
+ mon
.Obj
.Rect
.X
,
7894 mon
.Obj
.Y
+ mon
.Obj
.Rect
.Y
);
7899 SetAIFlag('ATTACKLEFT', '1')
7901 SetAIFlag('ATTACKRIGHT', '1');
7905 function TBot
.RunDirection(): TDirection
;
7907 if Abs(Vel
.X
) >= 1 then
7909 if Vel
.X
> 0 then Result
:= TDirection
.D_RIGHT
else Result
:= TDirection
.D_LEFT
;
7911 Result
:= FDirection
;
7914 function TBot
.GetRnd(a
: Byte): Boolean;
7916 if a
= 0 then Result
:= False
7917 else if a
= 255 then Result
:= True
7918 else Result
:= Random(256) > 255-a
;
7921 function TBot
.GetInterval(a
: Byte; radius
: SmallInt): SmallInt;
7923 Result
:= Round((255-a
)/255*radius
*(Random(2)-1));
7927 procedure TDifficult
.save (st
: TStream
);
7929 utils
.writeInt(st
, Byte(DiagFire
));
7930 utils
.writeInt(st
, Byte(InvisFire
));
7931 utils
.writeInt(st
, Byte(DiagPrecision
));
7932 utils
.writeInt(st
, Byte(FlyPrecision
));
7933 utils
.writeInt(st
, Byte(Cover
));
7934 utils
.writeInt(st
, Byte(CloseJump
));
7935 st
.WriteBuffer(WeaponPrior
[Low(WeaponPrior
)], sizeof(WeaponPrior
));
7936 st
.WriteBuffer(CloseWeaponPrior
[Low(CloseWeaponPrior
)], sizeof(CloseWeaponPrior
));
7939 procedure TDifficult
.load (st
: TStream
);
7941 DiagFire
:= utils
.readByte(st
);
7942 InvisFire
:= utils
.readByte(st
);
7943 DiagPrecision
:= utils
.readByte(st
);
7944 FlyPrecision
:= utils
.readByte(st
);
7945 Cover
:= utils
.readByte(st
);
7946 CloseJump
:= utils
.readByte(st
);
7947 st
.ReadBuffer(WeaponPrior
[Low(WeaponPrior
)], sizeof(WeaponPrior
));
7948 st
.ReadBuffer(CloseWeaponPrior
[Low(CloseWeaponPrior
)], sizeof(CloseWeaponPrior
));
7952 procedure TBot
.SaveState (st
: TStream
);
7957 inherited SaveState(st
);
7958 utils
.writeSign(st
, 'BOT0');
7960 utils
.writeInt(st
, Byte(FSelectedWeapon
));
7962 utils
.writeInt(st
, Word(FTargetUID
));
7963 // Âðåìÿ ïîòåðè öåëè
7964 utils
.writeInt(st
, LongWord(FLastVisible
));
7965 // Êîëè÷åñòâî ôëàãîâ ÈÈ
7966 dw
:= Length(FAIFlags
);
7967 utils
.writeInt(st
, LongInt(dw
));
7969 for i
:= 0 to dw
-1 do
7971 utils
.writeStr(st
, FAIFlags
[i
].Name
, 20);
7972 utils
.writeStr(st
, FAIFlags
[i
].Value
, 20);
7974 // Íàñòðîéêè ñëîæíîñòè
7975 FDifficult
.save(st
);
7979 procedure TBot
.LoadState (st
: TStream
);
7984 inherited LoadState(st
);
7985 if not utils
.checkSign(st
, 'BOT0') then raise XStreamError
.Create('invalid bot signature');
7987 FSelectedWeapon
:= utils
.readByte(st
);
7989 FTargetUID
:= utils
.readWord(st
);
7990 // Âðåìÿ ïîòåðè öåëè
7991 FLastVisible
:= utils
.readLongWord(st
);
7992 // Êîëè÷åñòâî ôëàãîâ ÈÈ
7993 dw
:= utils
.readLongInt(st
);
7994 if (dw
< 0) or (dw
> 16384) then raise XStreamError
.Create('invalid number of bot AI flags');
7995 SetLength(FAIFlags
, dw
);
7997 for i
:= 0 to dw
-1 do
7999 FAIFlags
[i
].Name
:= utils
.readStr(st
, 20);
8000 FAIFlags
[i
].Value
:= utils
.readStr(st
, 20);
8002 // Íàñòðîéêè ñëîæíîñòè
8003 FDifficult
.load(st
);
8008 conRegVar('cheat_berserk_autoswitch', @gBerserkAutoswitch
, 'autoswitch to fist when berserk pack taken', '', true, true);
8009 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');
8010 conRegVar('player_indicator_style', @gPlayerIndicatorStyle
, 'Visual appearance of indicator', 'Visual appearance of indicator');