1 (* Copyright (C) 2016 - The Doom2D.org team & involved community members <http://www.doom2d.org>.
2 * This file is part of Doom2D Forever.
4 * This program is free software: you can redistribute it and/or modify it under the terms of
5 * the GNU General Public License as published by the Free Software Foundation, version 3 of
8 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
9 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 * See the GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License along with this program.
13 * If not, see <http://www.gnu.org/licenses/>.
16 {$INCLUDE ../shared/a_modes.inc}
24 {$IFDEF USE_MEMPOOL}mempool
,{$ENDIF}
28 e_graphics
, g_playermodel
, g_basic
, g_textures
,
29 g_weapons
, g_phys
, g_saveload
, MAPDEF
,
65 AmmoLimits
: Array [0..1] of Array [A_BULLETS
..A_HIGH
] of Word =
66 ((200, 50, 50, 300, 100),
67 (400, 100, 100, 600, 200));
88 ANGLE_NONE
= Low(SmallInt
);
90 CORPSE_STATE_REMOVEME
= 0;
91 CORPSE_STATE_NORMAL
= 1;
92 CORPSE_STATE_MESS
= 2;
94 PLAYER_RECT
: TRectWH
= (X
:15; Y
:12; Width
:34; Height
:52);
95 PLAYER_RECT_CX
= 15+(34 div 2);
96 PLAYER_RECT_CY
= 12+(52 div 2);
97 PLAYER_CORPSERECT
: TRectWH
= (X
:15; Y
:48; Width
:34; Height
:16);
100 PLAYER_HP_LIMIT
= 200;
101 PLAYER_AP_SOFT
= 100;
102 PLAYER_AP_LIMIT
= 200;
103 SUICIDE_DAMAGE
= 112;
106 PLAYER_BURN_TIME
= 110;
108 PLAYER1_DEF_COLOR
: TRGB
= (R
:64; G
:175; B
:48);
109 PLAYER2_DEF_COLOR
: TRGB
= (R
:96; G
:96; B
:96);
127 TPlayerStatArray
= Array of TPlayerStat
;
129 TPlayerSavedState
= record
137 Ammo
: Array [A_BULLETS
..A_HIGH
] of Word;
138 MaxAmmo
: Array [A_BULLETS
..A_HIGH
] of Word;
139 Weapon
: Array [WP_FIRST
..WP_LAST
] of Boolean;
140 Inventory
: Set of R_ITEM_BACKPACK
..R_BERSERK
;
149 TPlayer
= class{$IFDEF USE_MEMPOOL}(TPoolObject
){$ENDIF}
157 FDirection
: TDirection
;
165 FMonsterKills
: Integer;
171 FCanJetpack
: Boolean;
177 FNextWeapDelay
: Byte; // frames
178 FBFGFireCounter
: SmallInt
;
179 FLastSpawnerUID
: Word;
183 FSpectatePlayer
: Integer;
184 FFirePainTime
: Integer;
187 FSavedStateNum
: Integer;
189 FModel
: TPlayerModel
;
190 FPunchAnim
: TAnimation
;
193 FActionForce
: Boolean;
194 FActionChanged
: Boolean;
196 FFireAngle
: SmallInt
;
200 FShellTimer
: Integer;
202 {$IFDEF ENABLE_SOUND}
203 FSawSound
: TPlayableSound
;
204 FSawSoundIdle
: TPlayableSound
;
205 FSawSoundHit
: TPlayableSound
;
206 FSawSoundSelect
: TPlayableSound
;
207 FFlameSoundOn
: TPlayableSound
;
208 FFlameSoundOff
: TPlayableSound
;
209 FFlameSoundWork
: TPlayableSound
;
210 FJetSoundOn
: TPlayableSound
;
211 FJetSoundOff
: TPlayableSound
;
212 FJetSoundFly
: TPlayableSound
;
217 FJustTeleported
: Boolean;
219 mEDamageType
: Integer;
222 function CollideLevel(XInc
, YInc
: Integer): Boolean;
223 function StayOnStep(XInc
, YInc
: Integer): Boolean;
224 function HeadInLiquid(XInc
, YInc
: Integer): Boolean;
225 function BodyInLiquid(XInc
, YInc
: Integer): Boolean;
226 function BodyInAcid(XInc
, YInc
: Integer): Boolean;
227 function FullInLift(XInc
, YInc
: Integer): Integer;
228 {procedure CollideItem();}
229 procedure FlySmoke(Times
: DWORD
= 1);
230 procedure OnFireFlame(Times
: DWORD
= 1);
231 function GetAmmoByWeapon(Weapon
: Byte): Word;
232 procedure SetAction(Action
: Byte; Force
: Boolean = False);
233 procedure OnDamage(Angle
: SmallInt
); virtual;
234 function firediry(): Integer;
237 procedure Run(Direction
: TDirection
);
238 procedure NextWeapon();
239 procedure PrevWeapon();
246 function getNextWeaponIndex (): Byte; // returns 255 for "no switch"
247 procedure resetWeaponQueue ();
248 function hasAmmoForWeapon (weapon
: Byte): Boolean;
249 function hasAmmoForShooting (weapon
: Byte): Boolean;
250 function shouldSwitch (weapon
: Byte; hadWeapon
: Boolean) : Boolean;
252 procedure doDamage (v
: Integer);
254 function refreshCorpse(): Boolean;
257 FDamageBuffer
: Integer;
259 FAmmo
: Array [A_BULLETS
..A_HIGH
] of Word;
260 FMaxAmmo
: Array [A_BULLETS
..A_HIGH
] of Word;
261 FWeapon
: Array [WP_FIRST
..WP_LAST
] of Boolean;
262 FInventory
: Set of R_ITEM_BACKPACK
..R_BERSERK
;
264 FPowerups
: Array [MR_SUIT
..MR_MAX
] of DWORD
;
265 FReloading
: Array [WP_FIRST
..WP_LAST
] of Word;
266 FTime
: Array [T_RESPAWN
..T_FLAGCAP
] of DWORD
;
267 FKeys
: Array [KEY_LEFT
..KEY_CHAT
] of TKeyState
;
268 FWeapSwitchMode
: Byte;
269 FWeapPreferences
: Array [WP_FIRST
.. WP_LAST
+1] of Byte;
270 FSwitchToEmpty
: Byte;
273 FPreferredTeam
: Byte;
276 FWantsInGame
: Boolean;
281 FActualModelName
: string;
288 FSpawnInvul
: Integer;
290 FWaitForFirstSpawn
: Boolean; // set to `true` in server, used to spawn a player on first full state request
293 // debug: viewport offset
294 viewPortX
, viewPortY
, viewPortW
, viewPortH
: Integer;
296 function isValidViewPort (): Boolean; inline;
298 constructor Create(); virtual;
299 destructor Destroy(); override;
300 procedure Respawn(Silent
: Boolean; Force
: Boolean = False); virtual;
301 function GetRespawnPoint(): Byte;
302 procedure PressKey(Key
: Byte; Time
: Word = 1);
303 procedure ReleaseKeys();
304 procedure SetModel(ModelName
: String);
305 procedure SetColor(Color
: TRGB
);
306 function GetColor(): TRGB
;
307 procedure SetWeapon(W
: Byte);
308 function IsKeyPressed(K
: Byte): Boolean;
309 function GetKeys(): Byte;
310 function PickItem(ItemType
: Byte; arespawn
: Boolean; var remove
: Boolean): Boolean; virtual;
311 procedure SetWeaponPrefs(Prefs
: Array of Byte);
312 procedure SetWeaponPref(Weapon
, Pref
: Byte);
313 function GetWeaponPref(Weapon
: Byte) : Byte;
314 function GetMorePrefered() : Byte;
315 function MaySwitch(Weapon
: Byte) : Boolean;
316 function Collide(X
, Y
: Integer; Width
, Height
: Word): Boolean; overload
;
317 function Collide(Panel
: TPanel
): Boolean; overload
;
318 function Collide(X
, Y
: Integer): Boolean; overload
;
319 procedure SetDirection(Direction
: TDirection
);
320 procedure GetSecret();
321 function TeleportTo(X
, Y
: Integer; silent
: Boolean; dir
: Byte): Boolean;
323 procedure Push(vx
, vy
: Integer);
324 procedure ChangeModel(ModelName
: String);
325 procedure SwitchTeam
;
326 procedure ChangeTeam(Team
: Byte);
328 function GetFlag(Flag
: Byte): Boolean;
329 procedure SetFlag(Flag
: Byte);
330 function DropFlag(Silent
: Boolean = True; DoThrow
: Boolean = False): Boolean;
331 function TryDropFlag(): Boolean;
332 procedure TankRamboCheats(Health
: Boolean);
333 procedure RestoreHealthArmor();
334 procedure FragCombo();
335 procedure GiveItem(ItemType
: Byte);
336 procedure Damage(value
: Word; SpawnerUID
: Word; vx
, vy
: Integer; t
: Byte); virtual;
337 function Heal(value
: Word; Soft
: Boolean): Boolean; virtual;
338 procedure MakeBloodVector(Count
: Word; VelX
, VelY
: Integer);
339 procedure MakeBloodSimple(Count
: Word);
340 procedure Kill(KillType
: Byte; SpawnerUID
: Word; t
: Byte);
341 procedure Reset(Force
: Boolean);
342 procedure Spectate(NoMove
: Boolean = False);
343 procedure SwitchNoClip
;
344 procedure SoftReset();
345 procedure Draw(); virtual;
346 procedure DrawPain();
347 procedure DrawPickup();
348 procedure DrawOverlay();
350 procedure DrawIndicator(Color
: TRGB
);
351 procedure DrawBubble();
353 procedure PreUpdate();
354 procedure Update(); virtual;
355 procedure PreserveState();
356 procedure RestoreState();
357 procedure SaveState (st
: TStream
); virtual;
358 procedure LoadState (st
: TStream
); virtual;
359 {$IFDEF ENABLE_SOUND}
360 procedure PauseSounds(Enable
: Boolean);
362 procedure NetFire(Wpn
: Byte; X
, Y
, AX
, AY
: Integer; WID
: Integer = -1);
363 procedure DoLerp(Level
: Integer = 2);
364 procedure SetLerp(XTo
, YTo
: Integer);
365 procedure ProcessWeaponAction(Action
: Byte);
366 procedure QueueWeaponSwitch(Weapon
: Byte);
367 procedure RealizeCurrentWeapon();
371 procedure JetpackOff
;
372 procedure CatchFire(Attacker
: Word; Timeout
: Integer = PLAYER_BURN_TIME
);
374 //WARNING! this does nothing for now, but still call it!
375 procedure positionChanged (); //WARNING! call this after entity position was changed, or coldet will not work right!
377 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
378 procedure moveBy (dx
, dy
: Integer); inline;
380 function getCameraObj(): TObj
;
383 property Vel
: TPoint2i read FObj
.Vel
;
384 property Obj
: TObj read FObj
;
386 property Name
: String read FName write FName
;
387 property Model
: TPlayerModel read FModel
;
388 property Health
: Integer read FHealth write FHealth
;
389 property Lives
: Byte read FLives write FLives
;
390 property Armor
: Integer read FArmor write FArmor
;
391 property Air
: Integer read FAir write FAir
;
392 property JetFuel
: Integer read FJetFuel write FJetFuel
;
393 property Frags
: Integer read FFrags write FFrags
;
394 property Death
: Integer read FDeath write FDeath
;
395 property Kills
: Integer read FKills write FKills
;
396 property CurrWeap
: Byte read FCurrWeap write FCurrWeap
;
397 property WeapSwitchMode
: Byte read FWeapSwitchMode write FWeapSwitchMode
;
398 property SwitchToEmpty
: Byte read FSwitchToEmpty write FSwitchToEmpty
;
399 property SkipIronFist
: Byte read FSkipIronFist write FSkipIronFist
;
400 property MonsterKills
: Integer read FMonsterKills write FMonsterKills
;
401 property Secrets
: Integer read FSecrets
;
402 property GodMode
: Boolean read FGodMode write FGodMode
;
403 property NoTarget
: Boolean read FNoTarget write FNoTarget
;
404 property NoReload
: Boolean read FNoReload write FNoReload
;
405 property alive
: Boolean read FAlive write FAlive
;
406 property Flag
: Byte read FFlag
;
407 property Team
: Byte read FTeam write FTeam
;
408 property Direction
: TDirection read FDirection
;
409 property GameX
: Integer read FObj
.X write FObj
.X
;
410 property GameY
: Integer read FObj
.Y write FObj
.Y
;
411 property GameVelX
: Integer read FObj
.Vel
.X write FObj
.Vel
.X
;
412 property GameVelY
: Integer read FObj
.Vel
.Y write FObj
.Vel
.Y
;
413 property GameAccelX
: Integer read FObj
.Accel
.X write FObj
.Accel
.X
;
414 property GameAccelY
: Integer read FObj
.Accel
.Y write FObj
.Accel
.Y
;
415 property IncCam
: Integer read FIncCam write FIncCam
;
416 property IncCamOld
: Integer read FIncCamOld write FIncCamOld
;
417 property SlopeOld
: Integer read FSlopeOld write FSlopeOld
;
418 property UID
: Word read FUID write FUID
;
419 property JustTeleported
: Boolean read FJustTeleported write FJustTeleported
;
420 property NetTime
: LongWord read FNetTime write FNetTime
;
423 property eName
: String read FName write FName
;
424 property eHealth
: Integer read FHealth write FHealth
;
425 property eLives
: Byte read FLives write FLives
;
426 property eArmor
: Integer read FArmor write FArmor
;
427 property eAir
: Integer read FAir write FAir
;
428 property eJetFuel
: Integer read FJetFuel write FJetFuel
;
429 property eFrags
: Integer read FFrags write FFrags
;
430 property eDeath
: Integer read FDeath write FDeath
;
431 property eKills
: Integer read FKills write FKills
;
432 property eCurrWeap
: Byte read FCurrWeap write FCurrWeap
;
433 property eMonsterKills
: Integer read FMonsterKills write FMonsterKills
;
434 property eSecrets
: Integer read FSecrets write FSecrets
;
435 property eGodMode
: Boolean read FGodMode write FGodMode
;
436 property eNoTarget
: Boolean read FNoTarget write FNoTarget
;
437 property eNoReload
: Boolean read FNoReload write FNoReload
;
438 property eAlive
: Boolean read FAlive write FAlive
;
439 property eFlag
: Byte read FFlag
;
440 property eTeam
: Byte read FTeam write FTeam
;
441 property eDirection
: TDirection read FDirection
;
442 property eGameX
: Integer read FObj
.X write FObj
.X
;
443 property eGameY
: Integer read FObj
.Y write FObj
.Y
;
444 property eGameVelX
: Integer read FObj
.Vel
.X write FObj
.Vel
.X
;
445 property eGameVelY
: Integer read FObj
.Vel
.Y write FObj
.Vel
.Y
;
446 property eGameAccelX
: Integer read FObj
.Accel
.X write FObj
.Accel
.X
;
447 property eGameAccelY
: Integer read FObj
.Accel
.Y write FObj
.Accel
.Y
;
448 property eIncCam
: Integer read FIncCam write FIncCam
;
449 property eUID
: Word read FUID
;
450 property eJustTeleported
: Boolean read FJustTeleported
;
451 property eNetTime
: LongWord read FNetTime
;
453 // set this before assigning something to `eDamage`
454 property eDamageType
: Integer read mEDamageType write mEDamageType
;
455 property eDamage
: Integer write doDamage
;
466 WeaponPrior
: packed array [WP_FIRST
..WP_LAST
] of Byte;
467 CloseWeaponPrior
: packed array [WP_FIRST
..WP_LAST
] of Byte;
468 //SafeWeaponPrior: Array [WP_FIRST..WP_LAST] of Byte;
471 procedure save (st
: TStream
);
472 procedure load (st
: TStream
);
480 TBot
= class(TPlayer
)
482 FSelectedWeapon
: Byte;
485 FAIFlags
: Array of TAIFlag
;
486 FDifficult
: TDifficult
;
488 function GetRnd(a
: Byte): Boolean;
489 function GetInterval(a
: Byte; radius
: SmallInt
): SmallInt
;
490 function RunDirection(): TDirection
;
491 function FullInStep(XInc
, YInc
: Integer): Boolean;
492 //function NeedItem(Item: Byte): Byte;
493 procedure SelectWeapon(Dist
: Integer);
494 procedure SetAIFlag(const aName
, fValue
: String);
495 function GetAIFlag(const aName
: String): String;
496 procedure RemoveAIFlag(const aName
: String);
497 function Healthy(): Byte;
498 procedure UpdateMove();
499 procedure UpdateCombat();
500 function KeyPressed(Key
: Word): Boolean;
501 procedure ReleaseKey(Key
: Byte);
502 function TargetOnScreen(TX
, TY
: Integer): Boolean;
503 procedure OnDamage(Angle
: SmallInt
); override;
506 procedure Respawn(Silent
: Boolean; Force
: Boolean = False); override;
507 constructor Create(); override;
508 destructor Destroy(); override;
509 procedure Draw(); override;
510 function PickItem(ItemType
: Byte; force
: Boolean; var remove
: Boolean): Boolean; override;
511 function Heal(value
: Word; Soft
: Boolean): Boolean; override;
512 procedure Update(); override;
513 procedure SaveState (st
: TStream
); override;
514 procedure LoadState (st
: TStream
); override;
526 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
527 procedure moveBy (dx
, dy
: Integer); inline;
529 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
543 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
544 procedure moveBy (dx
, dy
: Integer); inline;
546 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
549 TCorpse
= class{$IFDEF USE_MEMPOOL}(TPoolObject
){$ENDIF}
558 FAnimation
: TAnimation
;
559 FAnimationMask
: TAnimation
;
562 constructor Create(X
, Y
: Integer; ModelName
: String; aMess
: Boolean);
563 destructor Destroy(); override;
564 procedure Damage(Value
: Word; SpawnerUID
: Word; vx
, vy
: Integer);
567 procedure SaveState (st
: TStream
);
568 procedure LoadState (st
: TStream
);
570 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
571 procedure moveBy (dx
, dy
: Integer); inline;
573 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
575 function ObjPtr (): PObj
; inline;
577 property Obj
: TObj read FObj
; // copies object
578 property State
: Byte read FState
;
579 property Mess
: Boolean read FMess
;
582 TTeamStat
= Array [TEAM_RED
..TEAM_BLUE
] of
588 gPlayers
: Array of TPlayer
;
589 gCorpses
: Array of TCorpse
;
590 gGibs
: Array of TGib
;
591 gShells
: Array of TShell
;
592 gTeamStat
: TTeamStat
;
595 gChatBubble
: Integer;
596 gPlayerIndicator
: Integer = 1;
597 gPlayerIndicatorStyle
: Integer;
599 gSpectLatchPID1
: Word;
600 gSpectLatchPID2
: Word;
601 MAX_RUNVEL
: Integer = 8;
602 VEL_JUMP
: Integer = 10;
603 SHELL_TIMEOUT
: Cardinal = 60000;
605 function Lerp(X
, Y
, Factor
: Integer): Integer;
607 procedure g_Gibs_SetMax(Count
: Word);
608 function g_Gibs_GetMax(): Word;
609 procedure g_Corpses_SetMax(Count
: Word);
610 function g_Corpses_GetMax(): Word;
611 procedure g_Force_Model_Set(Mode
: Word);
612 function g_Force_Model_Get(): Word;
613 procedure g_Forced_Model_SetName(Model
: String);
614 function g_Forced_Model_GetName(): String;
615 procedure g_Shells_SetMax(Count
: Word);
616 function g_Shells_GetMax(): Word;
618 procedure g_Player_Init();
619 procedure g_Player_Free();
620 function g_Player_Create(ModelName
: String; Color
: TRGB
; Team
: Byte; Bot
: Boolean): Word;
621 function g_Player_CreateFromState (st
: TStream
): Word;
622 procedure g_Player_Remove(UID
: Word);
623 procedure g_Player_ResetTeams();
624 procedure g_Player_PreUpdate();
625 procedure g_Player_UpdateAll();
626 procedure g_Player_DrawAll();
627 procedure g_Player_DrawDebug(p
: TPlayer
);
628 procedure g_Player_DrawHealth();
629 procedure g_Player_RememberAll();
630 procedure g_Player_ResetAll(Force
, Silent
: Boolean);
631 function g_Player_Get(UID
: Word): TPlayer
;
632 function g_Player_GetCount(): Byte;
633 function g_Player_GetStats(): TPlayerStatArray
;
634 function g_Player_ExistingName(Name
: String): Boolean;
635 function g_Player_CreateCorpse(Player
: TPlayer
): Integer;
636 procedure g_Player_CreateGibs(fX
, fY
: Integer; ModelName
: String; fColor
: TRGB
);
637 procedure g_Player_CreateShell(fX
, fY
, dX
, dY
: Integer; T
: Byte);
638 procedure g_Player_UpdatePhysicalObjects();
639 procedure g_Player_DrawCorpses();
640 procedure g_Player_DrawShells();
641 procedure g_Player_RemoveAllCorpses();
642 procedure g_Player_Corpses_SaveState (st
: TStream
);
643 procedure g_Player_Corpses_LoadState (st
: TStream
);
644 procedure g_Player_ResetReady();
645 procedure g_Bot_Add(Team
, Difficult
: Byte; Handicap
: Integer = 100);
646 procedure g_Bot_AddList(Team
: Byte; lname
: ShortString
; num
: Integer = -1; Handicap
: Integer = 100);
647 procedure g_Bot_MixNames();
648 procedure g_Bot_RemoveAll();
649 function g_Bot_GetCount(): Integer;
654 {$INCLUDE ../nogl/noGLuses.inc}
655 {$IFDEF ENABLE_HOLMES}
658 e_log
, g_map
, g_items
, g_console
, g_gfx
, Math
,
659 g_options
, g_triggers
, g_menu
, g_game
, g_grid
, e_res
,
660 wadreader
, g_main
, g_monsters
, CONFIG
, g_language
,
661 g_net
, g_netmsg
, g_window
,
664 const PLR_SAVE_VERSION
= 0;
674 diag_precision
: Byte;
678 w_prior1
: Array [WP_FIRST
..WP_LAST
] of Byte;
679 w_prior2
: Array [WP_FIRST
..WP_LAST
] of Byte;
680 w_prior3
: Array [WP_FIRST
..WP_LAST
] of Byte;
684 TIME_RESPAWN1
= 1500;
685 TIME_RESPAWN2
= 2000;
686 TIME_RESPAWN3
= 3000;
689 JET_MAX
= 540; // ~30 sec
690 PLAYER_SUIT_TIME
= 30000;
691 PLAYER_INVUL_TIME
= 30000;
692 PLAYER_INVIS_TIME
= 35000;
693 FRAG_COMBO_TIME
= 3000;
697 ANGLE_RIGHTDOWN
= -35;
699 ANGLE_LEFTDOWN
= -145;
700 PLAYER_HEADRECT
: TRectWH
= (X
:24; Y
:12; Width
:20; Height
:12);
701 WEAPONPOINT
: Array [TDirection
] of TDFPoint
= ((X
:16; Y
:32), (X
:47; Y
:32));
704 BOT_UNSAFEDIST
= 128;
705 TEAMCOLOR
: Array [TEAM_RED
..TEAM_BLUE
] of TRGB
= ((R
:255; G
:0; B
:0),
707 DIFFICULT_EASY
: TDifficult
= (DiagFire
: 32; InvisFire
: 32; DiagPrecision
: 32;
708 FlyPrecision
: 32; Cover
: 32; CloseJump
: 32;
709 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
710 DIFFICULT_MEDIUM
: TDifficult
= (DiagFire
: 127; InvisFire
: 127; DiagPrecision
: 127;
711 FlyPrecision
: 127; Cover
: 127; CloseJump
: 127;
712 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
713 DIFFICULT_HARD
: TDifficult
= (DiagFire
: 255; InvisFire
: 255; DiagPrecision
: 255;
714 FlyPrecision
: 255; Cover
: 255; CloseJump
: 255;
715 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
716 WEAPON_PRIOR1
: Array [WP_FIRST
..WP_LAST
] of Byte =
717 (WEAPON_FLAMETHROWER
, WEAPON_SUPERCHAINGUN
,
718 WEAPON_SHOTGUN2
, WEAPON_SHOTGUN1
,
719 WEAPON_CHAINGUN
, WEAPON_PLASMA
, WEAPON_ROCKETLAUNCHER
,
720 WEAPON_BFG
, WEAPON_PISTOL
, WEAPON_SAW
, WEAPON_IRONFIST
);
721 WEAPON_PRIOR2
: Array [WP_FIRST
..WP_LAST
] of Byte =
722 (WEAPON_FLAMETHROWER
, WEAPON_SUPERCHAINGUN
,
723 WEAPON_BFG
, WEAPON_ROCKETLAUNCHER
,
724 WEAPON_SHOTGUN2
, WEAPON_PLASMA
, WEAPON_SHOTGUN1
,
725 WEAPON_CHAINGUN
, WEAPON_PISTOL
, WEAPON_SAW
, WEAPON_IRONFIST
);
726 //WEAPON_PRIOR3: Array [WP_FIRST..WP_LAST] of Byte =
727 // (WEAPON_FLAMETHROWER, WEAPON_SUPERCHAINGUN,
728 // WEAPON_BFG, WEAPON_PLASMA, WEAPON_SHOTGUN2,
729 // WEAPON_CHAINGUN, WEAPON_SHOTGUN1, WEAPON_SAW,
730 // WEAPON_ROCKETLAUNCHER, WEAPON_PISTOL, WEAPON_IRONFIST);
731 WEAPON_RELOAD
: Array [WP_FIRST
..WP_LAST
] of Byte =
732 (5, 2, 6, 18, 36, 2, 12, 2, 14, 2, 2);
734 PLAYER_SIGNATURE
= $52594C50; // 'PLYR'
735 CORPSE_SIGNATURE
= $50524F43; // 'CORP'
737 BOTNAMES_FILENAME
= 'botnames.txt';
738 BOTLIST_FILENAME
= 'botlist.txt';
742 MaxCorpses
: Word = 20;
743 MaxShells
: Word = 300;
744 ForceModel
: Word = 0;
745 ForcedModelName
: String = STD_PLAYER_MODEL
;
746 CurrentGib
: Integer = 0;
747 CurrentShell
: Integer = 0;
748 BotNames
: Array of String;
749 BotList
: Array of TBotProfile
;
750 SavedStates
: Array of TPlayerSavedState
;
753 function Lerp(X
, Y
, Factor
: Integer): Integer;
755 Result
:= X
+ ((Y
- X
) div Factor
);
758 function SameTeam(UID1
, UID2
: Word): Boolean;
762 if (UID1
> UID_MAX_PLAYER
) or (UID1
<= UID_MAX_GAME
) or
763 (UID2
> UID_MAX_PLAYER
) or (UID2
<= UID_MAX_GAME
) then Exit
;
765 if (g_Player_Get(UID1
) = nil) or (g_Player_Get(UID2
) = nil) then Exit
;
767 if ((g_Player_Get(UID1
).Team
= TEAM_NONE
) or
768 (g_Player_Get(UID2
).Team
= TEAM_NONE
)) then Exit
;
770 Result
:= g_Player_Get(UID1
).FTeam
= g_Player_Get(UID2
).FTeam
;
773 procedure g_Gibs_SetMax(Count
: Word);
776 SetLength(gGibs
, Count
);
778 if CurrentGib
>= Count
then
782 function g_Gibs_GetMax(): Word;
787 procedure g_Shells_SetMax(Count
: Word);
790 SetLength(gShells
, Count
);
792 if CurrentShell
>= Count
then
796 function g_Shells_GetMax(): Word;
802 procedure g_Corpses_SetMax(Count
: Word);
805 SetLength(gCorpses
, Count
);
808 function g_Corpses_GetMax(): Word;
810 Result
:= MaxCorpses
;
813 procedure g_Force_Model_Set(Mode
: Word);
818 function g_Force_Model_Get(): Word;
820 Result
:= ForceModel
;
823 procedure g_Forced_Model_SetName(Model
: String);
825 ForcedModelName
:= Model
;
828 function g_Forced_Model_GetName(): String;
830 Result
:= ForcedModelName
;
833 function g_Player_Create(ModelName
: String; Color
: TRGB
; Team
: Byte; Bot
: Boolean): Word;
840 // Åñòü ëè ìåñòî â gPlayers:
841 for a
:= 0 to High(gPlayers
) do
842 if gPlayers
[a
] = nil then
848 // Íåò ìåñòà - ðàñøèðÿåì gPlayers:
851 SetLength(gPlayers
, Length(gPlayers
)+1);
855 // Ñîçäàåì îáúåêò èãðîêà:
857 then gPlayers
[a
] := TBot
.Create()
858 else gPlayers
[a
] := TPlayer
.Create();
860 gPlayers
[a
].FActualModelName
:= ModelName
;
861 gPlayers
[a
].SetModel(ModelName
);
862 if Bot
and (g_Force_Model_Get() <> 0) then
863 gPlayers
[a
].SetModel(g_Forced_Model_GetName());
865 // Íåò ìîäåëè - ñîçäàíèå íåâîçìîæíî:
866 if gPlayers
[a
].FModel
= nil then
868 FreeAndNil(gPlayers
[a
]);
869 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], [ModelName
]));
873 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
875 then Team
:= TEAM_RED
876 else Team
:= TEAM_BLUE
;
877 gPlayers
[a
].FPreferredTeam
:= Team
;
879 case gGameSettings
.GameMode
of
880 GM_DM
: gPlayers
[a
].FTeam
:= TEAM_NONE
;
881 GM_TDM
, GM_CTF
: gPlayers
[a
].FTeam
:= gPlayers
[a
].FPreferredTeam
;
882 GM_SINGLE
, GM_COOP
: gPlayers
[a
].FTeam
:= TEAM_COOP
;
885 // Åñëè êîìàíäíàÿ èãðà - êðàñèì ìîäåëü â öâåò êîìàíäû:
886 gPlayers
[a
].FColor
:= Color
;
887 if gPlayers
[a
].FTeam
in [TEAM_RED
, TEAM_BLUE
]
888 then gPlayers
[a
].FModel
.Color
:= TEAMCOLOR
[gPlayers
[a
].FTeam
]
889 else gPlayers
[a
].FModel
.Color
:= Color
;
891 gPlayers
[a
].FUID
:= g_CreateUID(UID_PLAYER
);
892 gPlayers
[a
].FAlive
:= False;
894 Result
:= gPlayers
[a
].FUID
;
897 function g_Player_CreateFromState (st
: TStream
): Word;
905 // check signature and entity type
907 if not utils
.checkSign(st
, 'PLYR') then
908 Raise XStreamError
.Create('invalid player signature');
909 if st
.ReadByte() <> PLR_SAVE_VERSION
then
910 Raise XStreamError
.Create('invalid player version');
912 Bot
:= st
.ReadBool();
915 // find free player slot
917 for i
:= 0 to High(gPlayers
) do
918 if gPlayers
[i
] = nil then
924 // allocate player slot
927 SetLength(gPlayers
, Length(gPlayers
)+1);
931 // create entity and load state
934 gPlayers
[i
] := TBot
.Create();
935 if g_Force_Model_Get() <> 0 then
936 gPlayers
[i
].SetModel(g_Forced_Model_GetName());
939 gPlayers
[i
] := TPlayer
.Create();
941 gPlayers
[i
].FPhysics
:= True; // ???
942 gPlayers
[i
].LoadState(st
);
944 Result
:= gPlayers
[i
].FUID
;
948 procedure g_Player_ResetTeams();
952 if g_Game_IsClient
then
954 if gPlayers
= nil then
956 for a
:= Low(gPlayers
) to High(gPlayers
) do
957 if gPlayers
[a
] <> nil then
958 case gGameSettings
.GameMode
of
960 gPlayers
[a
].ChangeTeam(TEAM_NONE
);
962 if not (gPlayers
[a
].Team
in [TEAM_RED
, TEAM_BLUE
]) then
963 if gPlayers
[a
].FPreferredTeam
in [TEAM_RED
, TEAM_BLUE
] then
964 gPlayers
[a
].ChangeTeam(gPlayers
[a
].FPreferredTeam
)
967 then gPlayers
[a
].ChangeTeam(TEAM_RED
)
968 else gPlayers
[a
].ChangeTeam(TEAM_BLUE
);
971 gPlayers
[a
].ChangeTeam(TEAM_COOP
);
975 procedure g_Bot_Add(Team
, Difficult
: Byte; Handicap
: Integer = 100);
978 _name
, _model
: String;
981 if not g_Game_IsServer
then Exit
;
983 // Íå äîáàâëÿåì áîòîâ åñëè ëèìèò óæå äîñòèãíóò
984 if (g_Bot_GetCount() >= gMaxBots
) then Exit
;
986 // Ñïèñîê íàçâàíèé ìîäåëåé:
987 m
:= g_PlayerModel_GetNames();
992 if (gGameSettings
.GameType
= GT_SINGLE
) or (gGameSettings
.GameMode
= GM_COOP
) then
993 Team
:= TEAM_COOP
// COOP
995 if gGameSettings
.GameMode
= GM_DM
then
996 Team
:= TEAM_NONE
// DM
998 if Team
= TEAM_NONE
then // CTF / TDM
1000 // Àâòîáàëàíñ êîìàíä:
1004 for a
:= 0 to High(gPlayers
) do
1005 if gPlayers
[a
] <> nil then
1007 if gPlayers
[a
].Team
= TEAM_RED
then
1010 if gPlayers
[a
].Team
= TEAM_BLUE
then
1020 if Random(2) = 0 then
1026 // Âûáèðàåì áîòó èìÿ:
1028 if BotNames
<> nil then
1029 for a
:= 0 to High(BotNames
) do
1030 if g_Player_ExistingName(BotNames
[a
]) then
1032 _name
:= BotNames
[a
];
1036 // Âûáèðàåì ñëó÷àéíóþ ìîäåëü:
1037 _model
:= m
[Random(Length(m
))];
1040 with g_Player_Get(g_Player_Create(_model
,
1041 _RGB(Min(Random(9)*32, 255),
1042 Min(Random(9)*32, 255),
1043 Min(Random(9)*32, 255)),
1044 Team
, True)) as TBot
do
1046 // Åñëè èìåíè íåò, äåëàåì åãî èç UID áîòà
1048 Name
:= Format('DFBOT%.5d', [UID
])
1053 1: FDifficult
:= DIFFICULT_EASY
;
1054 2: FDifficult
:= DIFFICULT_MEDIUM
;
1055 else FDifficult
:= DIFFICULT_HARD
;
1058 for a
:= WP_FIRST
to WP_LAST
do
1060 FDifficult
.WeaponPrior
[a
] := WEAPON_PRIOR1
[a
];
1061 FDifficult
.CloseWeaponPrior
[a
] := WEAPON_PRIOR2
[a
];
1062 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
1065 FHandicap
:= Handicap
;
1067 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [Name
]), True);
1069 if g_Game_IsNet
then MH_SEND_PlayerCreate(UID
);
1070 if g_Game_IsServer
and (gGameSettings
.MaxLives
> 0) then
1075 procedure g_Bot_AddList(Team
: Byte; lName
: ShortString
; num
: Integer = -1; Handicap
: Integer = 100);
1078 _name
, _model
: String;
1081 if not g_Game_IsServer
then Exit
;
1083 // Íå äîáàâëÿåì áîòîâ åñëè ëèìèò óæå äîñòèãíóò
1084 if (g_Bot_GetCount() >= gMaxBots
) then Exit
;
1086 // Ñïèñîê íàçâàíèé ìîäåëåé:
1087 m
:= g_PlayerModel_GetNames();
1092 if (gGameSettings
.GameType
= GT_SINGLE
) or (gGameSettings
.GameMode
= GM_COOP
) then
1093 Team
:= TEAM_COOP
// COOP
1095 if gGameSettings
.GameMode
= GM_DM
then
1096 Team
:= TEAM_NONE
// DM
1098 if Team
= TEAM_NONE
then
1099 Team
:= BotList
[num
].team
; // CTF / TDM
1101 // Âûáèðàåì íàñòðîéêè áîòà èç ñïèñêà ïî íîìåðó èëè èìåíè:
1103 num
:= Random(Length(BotList
))
1106 if (num
< 0) or (num
> Length(BotList
)-1) then
1108 if (num
= -1) and (BotList
<> nil) then
1109 lName
:= AnsiLowerCase(lName
);
1110 for a
:= 0 to High(BotList
) do
1111 if AnsiLowerCase(BotList
[a
].name
) = lName
then
1121 _name
:= BotList
[num
].name
;
1122 if (_name
= '') and (BotNames
<> nil) then
1123 for a
:= 0 to High(BotNames
) do
1124 if g_Player_ExistingName(BotNames
[a
]) then
1126 _name
:= BotNames
[a
];
1131 _model
:= BotList
[num
].model
;
1132 // Íåò òàêîé - âûáèðàåì ñëó÷àéíóþ:
1133 if not InSArray(_model
, m
) then
1134 _model
:= m
[Random(Length(m
))];
1137 with g_Player_Get(g_Player_Create(_model
, BotList
[num
].color
, Team
, True)) as TBot
do
1139 // Åñëè èìåíè íåò, äåëàåì åãî èç UID áîòà
1141 then Name
:= Format('DFBOT%.5d', [UID
])
1144 FDifficult
.DiagFire
:= BotList
[num
].diag_fire
;
1145 FDifficult
.InvisFire
:= BotList
[num
].invis_fire
;
1146 FDifficult
.DiagPrecision
:= BotList
[num
].diag_precision
;
1147 FDifficult
.FlyPrecision
:= BotList
[num
].fly_precision
;
1148 FDifficult
.Cover
:= BotList
[num
].cover
;
1149 FDifficult
.CloseJump
:= BotList
[num
].close_jump
;
1151 FHandicap
:= Handicap
;
1153 for a
:= WP_FIRST
to WP_LAST
do
1155 FDifficult
.WeaponPrior
[a
] := BotList
[num
].w_prior1
[a
];
1156 FDifficult
.CloseWeaponPrior
[a
] := BotList
[num
].w_prior2
[a
];
1157 //FDifficult.SafeWeaponPrior[a] := BotList[num].w_prior3[a];
1160 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [Name
]), True);
1162 if g_Game_IsNet
then MH_SEND_PlayerCreate(UID
);
1166 procedure g_Bot_RemoveAll();
1170 if not g_Game_IsServer
then Exit
;
1171 if gPlayers
= nil then Exit
;
1173 for a
:= 0 to High(gPlayers
) do
1174 if gPlayers
[a
] <> nil then
1175 if gPlayers
[a
] is TBot
then
1177 gPlayers
[a
].Lives
:= 0;
1178 gPlayers
[a
].Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
1179 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [gPlayers
[a
].Name
]), True);
1180 g_Player_Remove(gPlayers
[a
].FUID
);
1186 procedure g_Bot_MixNames();
1191 if BotNames
<> nil then
1192 for a
:= 0 to High(BotNames
) do
1194 b
:= Random(Length(BotNames
));
1196 Botnames
[a
] := BotNames
[b
];
1201 procedure g_Player_Remove(UID
: Word);
1205 if gPlayers
= nil then Exit
;
1207 if g_Game_IsServer
and g_Game_IsNet
then
1208 MH_SEND_PlayerDelete(UID
);
1210 for i
:= 0 to High(gPlayers
) do
1211 if gPlayers
[i
] <> nil then
1212 if gPlayers
[i
].FUID
= UID
then
1214 if gPlayers
[i
] is TPlayer
then
1215 TPlayer(gPlayers
[i
]).Free()
1217 TBot(gPlayers
[i
]).Free();
1223 procedure g_Player_Init();
1235 path
:= BOTNAMES_FILENAME
;
1236 if e_FindResource(DataDirs
, path
) then
1238 // ×èòàåì âîçìîæíûå èìåíà áîòîâ èç ôàéëà:
1239 AssignFile(F
, path
);
1250 SetLength(BotNames
, Length(BotNames
)+1);
1251 BotNames
[High(BotNames
)] := s
;
1260 path
:= BOTLIST_FILENAME
;
1261 if e_FindResource(DataDirs
, path
) then
1263 // ×èòàåì ôàéë ñ ïàðàìåòðàìè áîòîâ:
1264 config
:= TConfig
.CreateFile(path
);
1267 while config
.SectionExists(IntToStr(a
)) do
1269 SetLength(BotList
, Length(BotList
)+1);
1271 with BotList
[High(BotList
)] do
1273 name
:= config
.ReadStr(IntToStr(a
), 'name', ''); // Èìÿ áîòà
1274 model
:= config
.ReadStr(IntToStr(a
), 'model', ''); // Ìîäåëü
1277 s
:= config
.ReadStr(IntToStr(a
), 'team', '');
1280 else if s
= 'blue' then
1286 sa
:= parse(config
.ReadStr(IntToStr(a
), 'color', ''));
1288 color
.R
:= StrToIntDef(sa
[0], 0);
1289 color
.G
:= StrToIntDef(sa
[1], 0);
1290 color
.B
:= StrToIntDef(sa
[2], 0);
1292 diag_fire
:= config
.ReadInt(IntToStr(a
), 'diag_fire', 0); // Âåðîÿòíîñòü ñòðåëüáû ïîä óãëîì
1293 invis_fire
:= config
.ReadInt(IntToStr(a
), 'invis_fire', 0); // Âåðîÿòíîñòü îòâåòíîãî îãíÿ ïî íåâèäèìîìó ñîïåðíèêó
1294 diag_precision
:= config
.ReadInt(IntToStr(a
), 'diag_precision', 0); // Òî÷íîñòü ñòðåëüáû ïîä óãëîì
1295 fly_precision
:= config
.ReadInt(IntToStr(a
), 'fly_precision', 0); // Òî÷íîñòü ñòðåëüáû â ïîëåòå
1296 cover
:= config
.ReadInt(IntToStr(a
), 'cover', 0); // Òî÷íîñòü óêëîíåíèÿ îò ñíàðÿäîâ
1297 close_jump
:= config
.ReadInt(IntToStr(a
), 'close_jump', 0); // Âåðîÿòíîñòü ïðûæêà ïðè ïðèáëèæåíèè ñîïåðíèêà
1299 // Ïðèîðèòåòû îðóæèÿ äëÿ äàëüíåãî áîÿ
1300 sa
:= parse(config
.ReadStr(IntToStr(a
), 'w_prior1', ''));
1301 if Length(sa
) = 10 then
1303 w_prior1
[b
] := EnsureRange(StrToInt(sa
[b
]), 0, 9);
1305 // Ïðèîðèòåòû îðóæèÿ äëÿ áëèæíåãî áîÿ
1306 sa
:= parse(config
.ReadStr(IntToStr(a
), 'w_prior2', ''));
1307 if Length(sa
) = 10 then
1309 w_prior2
[b
] := EnsureRange(StrToInt(sa
[b
]), 0, 9);
1311 {sa := parse(config.ReadStr(IntToStr(a), 'w_prior3', ''));
1312 if Length(sa) = 10 then
1314 w_prior3[b] := EnsureRange(StrToInt(sa[b]), 0, 9);}
1323 SetLength(SavedStates
, 0);
1326 procedure g_Player_Free();
1330 if gPlayers
<> nil then
1332 for i
:= 0 to High(gPlayers
) do
1333 if gPlayers
[i
] <> nil then
1335 if gPlayers
[i
] is TPlayer
then
1336 TPlayer(gPlayers
[i
]).Free()
1338 TBot(gPlayers
[i
]).Free();
1347 SetLength(SavedStates
, 0);
1350 procedure g_Player_PreUpdate();
1354 if gPlayers
= nil then Exit
;
1355 for i
:= 0 to High(gPlayers
) do
1356 if gPlayers
[i
] <> nil then
1357 gPlayers
[i
].PreUpdate();
1360 procedure g_Player_UpdateAll();
1364 if gPlayers
= nil then Exit
;
1366 //e_WriteLog('***g_Player_UpdateAll: ENTER', MSG_WARNING);
1367 for i
:= 0 to High(gPlayers
) do
1369 if gPlayers
[i
] <> nil then
1371 if gPlayers
[i
] is TPlayer
then
1373 gPlayers
[i
].Update();
1374 gPlayers
[i
].RealizeCurrentWeapon(); // WARNING! DO NOT MOVE THIS INTO `Update()`!
1378 // bot updates weapons in `UpdateCombat()`
1379 TBot(gPlayers
[i
]).Update();
1383 //e_WriteLog('***g_Player_UpdateAll: EXIT', MSG_WARNING);
1386 procedure g_Player_DrawAll();
1390 if gPlayers
= nil then Exit
;
1392 for i
:= 0 to High(gPlayers
) do
1393 if gPlayers
[i
] <> nil then
1394 if gPlayers
[i
] is TPlayer
then gPlayers
[i
].Draw()
1395 else TBot(gPlayers
[i
]).Draw();
1398 procedure g_Player_DrawDebug(p
: TPlayer
);
1402 if p
= nil then Exit
;
1403 if (@p
.FObj
) = nil then Exit
;
1405 e_TextureFontGetSize(gStdFont
, fW
, fH
);
1407 e_TextureFontPrint(0, 0 , 'Pos X: ' + IntToStr(p
.FObj
.X
), gStdFont
);
1408 e_TextureFontPrint(0, fH
, 'Pos Y: ' + IntToStr(p
.FObj
.Y
), gStdFont
);
1409 e_TextureFontPrint(0, fH
* 2, 'Vel X: ' + IntToStr(p
.FObj
.Vel
.X
), gStdFont
);
1410 e_TextureFontPrint(0, fH
* 3, 'Vel Y: ' + IntToStr(p
.FObj
.Vel
.Y
), gStdFont
);
1411 e_TextureFontPrint(0, fH
* 4, 'Acc X: ' + IntToStr(p
.FObj
.Accel
.X
), gStdFont
);
1412 e_TextureFontPrint(0, fH
* 5, 'Acc Y: ' + IntToStr(p
.FObj
.Accel
.Y
), gStdFont
);
1413 e_TextureFontPrint(0, fH
* 6, 'Old X: ' + IntToStr(p
.FObj
.oldX
), gStdFont
);
1414 e_TextureFontPrint(0, fH
* 7, 'Old Y: ' + IntToStr(p
.FObj
.oldY
), gStdFont
);
1417 procedure g_Player_DrawHealth();
1422 if gPlayers
= nil then Exit
;
1423 e_TextureFontGetSize(gStdFont
, fW
, fH
);
1425 for i
:= 0 to High(gPlayers
) do
1426 if gPlayers
[i
] <> nil then
1428 e_TextureFontPrint(gPlayers
[i
].FObj
.X
+ gPlayers
[i
].FObj
.Rect
.X
,
1429 gPlayers
[i
].FObj
.Y
+ gPlayers
[i
].FObj
.Rect
.Y
+ gPlayers
[i
].FObj
.Rect
.Height
- fH
* 2,
1430 IntToStr(gPlayers
[i
].FHealth
), gStdFont
);
1431 e_TextureFontPrint(gPlayers
[i
].FObj
.X
+ gPlayers
[i
].FObj
.Rect
.X
,
1432 gPlayers
[i
].FObj
.Y
+ gPlayers
[i
].FObj
.Rect
.Y
+ gPlayers
[i
].FObj
.Rect
.Height
- fH
,
1433 IntToStr(gPlayers
[i
].FArmor
), gStdFont
);
1437 function g_Player_Get(UID
: Word): TPlayer
;
1443 if gPlayers
= nil then
1446 for a
:= 0 to High(gPlayers
) do
1447 if gPlayers
[a
] <> nil then
1448 if gPlayers
[a
].FUID
= UID
then
1450 Result
:= gPlayers
[a
];
1455 function g_Player_GetCount(): Byte;
1461 if gPlayers
= nil then
1464 for a
:= 0 to High(gPlayers
) do
1465 if gPlayers
[a
] <> nil then
1466 Result
:= Result
+ 1;
1469 function g_Bot_GetCount(): Integer;
1475 if gPlayers
= nil then
1478 for a
:= 0 to High(gPlayers
) do
1479 if (gPlayers
[a
] <> nil) and (gPlayers
[a
] is TBot
) then
1480 Result
:= Result
+ 1;
1483 function g_Player_GetStats(): TPlayerStatArray
;
1489 if gPlayers
= nil then Exit
;
1491 for a
:= 0 to High(gPlayers
) do
1492 if gPlayers
[a
] <> nil then
1494 SetLength(Result
, Length(Result
)+1);
1495 with Result
[High(Result
)] do
1498 Ping
:= gPlayers
[a
].FPing
;
1499 Loss
:= gPlayers
[a
].FLoss
;
1500 Name
:= gPlayers
[a
].FName
;
1501 Team
:= gPlayers
[a
].FTeam
;
1502 Frags
:= gPlayers
[a
].FFrags
;
1503 Deaths
:= gPlayers
[a
].FDeath
;
1504 Kills
:= gPlayers
[a
].FKills
;
1505 Color
:= gPlayers
[a
].FModel
.Color
;
1506 Lives
:= gPlayers
[a
].FLives
;
1507 Spectator
:= gPlayers
[a
].FSpectator
;
1508 UID
:= gPlayers
[a
].FUID
;
1513 procedure g_Player_ResetReady();
1517 if not g_Game_IsServer
then Exit
;
1518 if gPlayers
= nil then Exit
;
1520 for a
:= 0 to High(gPlayers
) do
1521 if gPlayers
[a
] <> nil then
1523 gPlayers
[a
].FReady
:= False;
1524 if g_Game_IsNet
then
1525 MH_SEND_GameEvent(NET_EV_INTER_READY
, gPlayers
[a
].UID
, 'N');
1529 procedure g_Player_RememberAll
;
1533 for i
:= Low(gPlayers
) to High(gPlayers
) do
1534 if (gPlayers
[i
] <> nil) and gPlayers
[i
].alive
then
1535 gPlayers
[i
].PreserveState
;
1538 procedure g_Player_ResetAll(Force
, Silent
: Boolean);
1542 gTeamStat
[TEAM_RED
].Score
:= 0;
1543 gTeamStat
[TEAM_BLUE
].Score
:= 0;
1545 if gPlayers
<> nil then
1546 for i
:= 0 to High(gPlayers
) do
1547 if gPlayers
[i
] <> nil then
1549 gPlayers
[i
].Reset(Force
);
1551 if gPlayers
[i
] is TPlayer
then
1553 if (not gPlayers
[i
].FSpectator
) or gPlayers
[i
].FWantsInGame
then
1554 gPlayers
[i
].Respawn(Silent
)
1556 gPlayers
[i
].Spectate();
1559 TBot(gPlayers
[i
]).Respawn(Silent
);
1563 function g_Player_CreateCorpse(Player
: TPlayer
): Integer;
1571 if Player
.alive
then
1574 // Ðàçðûâàåì ñâÿçü ñ ïðåæíèì òðóïîì:
1575 i
:= Player
.FCorpse
;
1576 if (Low(gCorpses
) <= i
) and (High(gCorpses
) >= i
) then
1578 if (gCorpses
[i
] <> nil) and (gCorpses
[i
].FPlayerUID
= Player
.FUID
) then
1579 gCorpses
[i
].FPlayerUID
:= 0;
1582 if Player
.FObj
.Y
>= gMapInfo
.Height
+128 then
1587 if (FHealth
>= -50) or (gGibsCount
= 0) then
1589 if Length(gCorpses
) = 0 then
1593 for find_id
:= 0 to High(gCorpses
) do
1594 if gCorpses
[find_id
] = nil then
1602 find_id
:= Random(Length(gCorpses
));
1603 gCorpses
[find_id
].Destroy();
1606 gCorpses
[find_id
] := TCorpse
.Create(FObj
.X
, FObj
.Y
, FModel
.Name
, FHealth
< -20);
1607 gCorpses
[find_id
].FColor
:= FModel
.Color
;
1608 gCorpses
[find_id
].FObj
.Vel
:= FObj
.Vel
;
1609 gCorpses
[find_id
].FObj
.Accel
:= FObj
.Accel
;
1610 gCorpses
[find_id
].FPlayerUID
:= FUID
;
1615 g_Player_CreateGibs(FObj
.X
+ PLAYER_RECT_CX
,
1616 FObj
.Y
+ PLAYER_RECT_CY
,
1617 FModel
.Name
, FModel
.Color
);
1621 procedure g_Player_CreateShell(fX
, fY
, dX
, dY
: Integer; T
: Byte);
1625 if (gShells
= nil) or (Length(gShells
) = 0) then
1628 with gShells
[CurrentShell
] do
1634 if T
= SHELL_BULLET
then
1636 if g_Texture_Get('TEXTURE_SHELL_BULLET', SID
) then
1640 Obj
.Rect
.Width
:= 4;
1641 Obj
.Rect
.Height
:= 2;
1645 if g_Texture_Get('TEXTURE_SHELL_SHELL', SID
) then
1649 Obj
.Rect
.Width
:= 7;
1650 Obj
.Rect
.Height
:= 3;
1656 g_Obj_Push(@Obj
, dX
+ Random(4)-Random(4), dY
-Random(4));
1657 positionChanged(); // this updates spatial accelerators
1658 RAngle
:= Random(360);
1659 Timeout
:= gTime
+ SHELL_TIMEOUT
;
1661 if CurrentShell
>= High(gShells
) then
1668 procedure g_Player_CreateGibs(fX
, fY
: Integer; ModelName
: string; fColor
: TRGB
);
1671 GibsArray
: TGibsArray
;
1674 if (gGibs
= nil) or (Length(gGibs
) = 0) then
1676 if not g_PlayerModel_GetGibs(ModelName
, GibsArray
) then
1678 Blood
:= g_PlayerModel_GetBlood(ModelName
);
1680 for a
:= 0 to High(GibsArray
) do
1681 with gGibs
[CurrentGib
] do
1684 ID
:= GibsArray
[a
].ID
;
1685 MaskID
:= GibsArray
[a
].MaskID
;
1688 Obj
.Rect
:= GibsArray
[a
].Rect
;
1689 Obj
.X
:= fX
-GibsArray
[a
].Rect
.X
-(GibsArray
[a
].Rect
.Width
div 2);
1690 Obj
.Y
:= fY
-GibsArray
[a
].Rect
.Y
-(GibsArray
[a
].Rect
.Height
div 2);
1691 g_Obj_PushA(@Obj
, 25 + Random(10), Random(361));
1692 positionChanged(); // this updates spatial accelerators
1693 RAngle
:= Random(360);
1695 if gBloodCount
> 0 then
1696 g_GFX_Blood(fX
, fY
, 16*gBloodCount
+Random(5*gBloodCount
), -16+Random(33), -16+Random(33),
1697 Random(48), Random(48), Blood
.R
, Blood
.G
, Blood
.B
, Blood
.Kind
);
1699 if CurrentGib
>= High(gGibs
) then
1706 procedure g_Player_UpdatePhysicalObjects();
1712 procedure ShellSound_Bounce(X
, Y
: Integer; T
: Byte);
1717 {$IFDEF ENABLE_SOUND}
1719 then g_Sound_PlayExAt('SOUND_PLAYER_CASING' + IntToStr(k
), X
, Y
)
1720 else g_Sound_PlayExAt('SOUND_PLAYER_SHELL' + IntToStr(k
), X
, Y
);
1726 for i
:= 0 to High(gGibs
) do
1727 if gGibs
[i
].alive
then
1734 mr
:= g_Obj_Move(@Obj
, True, False, True);
1735 positionChanged(); // this updates spatial accelerators
1737 if WordBool(mr
and MOVE_FALLOUT
) then
1743 // Îòëåòàåò îò óäàðà î ñòåíó/ïîòîëîê/ïîë:
1744 if WordBool(mr
and MOVE_HITWALL
) then
1745 Obj
.Vel
.X
:= -(vel
.X
div 2);
1746 if WordBool(mr
and (MOVE_HITCEIL
or MOVE_HITLAND
)) then
1747 Obj
.Vel
.Y
:= -(vel
.Y
div 2);
1749 if (Obj
.Vel
.X
>= 0) then
1751 RAngle
:= RAngle
+ Abs(Obj
.Vel
.X
)*6 + Abs(Obj
.Vel
.Y
);
1752 if RAngle
>= 360 then
1753 RAngle
:= RAngle
mod 360;
1756 begin // Counter-clockwise
1757 RAngle
:= RAngle
- Abs(Obj
.Vel
.X
)*6 - Abs(Obj
.Vel
.Y
);
1759 RAngle
:= (360 - (Abs(RAngle
) mod 360)) mod 360;
1762 // Ñîïðîòèâëåíèå âîçäóõà äëÿ êóñêà òðóïà:
1763 if gTime
mod (GAME_TICK
*3) = 0 then
1764 Obj
.Vel
.X
:= z_dec(Obj
.Vel
.X
, 1);
1768 for i
:= 0 to High(gCorpses
) do
1769 if gCorpses
[i
] <> nil then
1770 if gCorpses
[i
].State
= CORPSE_STATE_REMOVEME
1771 then FreeAndNil(gCorpses
[i
])
1772 else gCorpses
[i
].Update();
1775 for i
:= 0 to High(gShells
) do
1776 if gShells
[i
].alive
then
1783 mr
:= g_Obj_Move(@Obj
, True, False, True);
1784 positionChanged(); // this updates spatial accelerators
1786 if WordBool(mr
and MOVE_FALLOUT
) or (gShells
[i
].Timeout
< gTime
) then
1792 // Îòëåòàåò îò óäàðà î ñòåíó/ïîòîëîê/ïîë:
1793 if WordBool(mr
and MOVE_HITWALL
) then
1795 Obj
.Vel
.X
:= -(vel
.X
div 2);
1796 if not WordBool(mr
and MOVE_INWATER
) then
1797 ShellSound_Bounce(Obj
.X
, Obj
.Y
, SType
);
1799 if WordBool(mr
and (MOVE_HITCEIL
or MOVE_HITLAND
)) then
1801 Obj
.Vel
.Y
:= -(vel
.Y
div 2);
1802 if Obj
.Vel
.X
<> 0 then Obj
.Vel
.X
:= Obj
.Vel
.X
div 2;
1803 if (Obj
.Vel
.X
= 0) and (Obj
.Vel
.Y
= 0) then
1805 if RAngle
mod 90 <> 0 then
1806 RAngle
:= (RAngle
div 90) * 90;
1808 else if not WordBool(mr
and MOVE_INWATER
) then
1809 ShellSound_Bounce(Obj
.X
, Obj
.Y
, SType
);
1812 if (Obj
.Vel
.X
>= 0) then
1814 RAngle
:= RAngle
+ Abs(Obj
.Vel
.X
)*8 + Abs(Obj
.Vel
.Y
);
1815 if RAngle
>= 360 then
1816 RAngle
:= RAngle
mod 360;
1819 begin // Counter-clockwise
1820 RAngle
:= RAngle
- Abs(Obj
.Vel
.X
)*8 - Abs(Obj
.Vel
.Y
);
1822 RAngle
:= (360 - (Abs(RAngle
) mod 360)) mod 360;
1828 procedure TGib
.getMapBox (out x
, y
, w
, h
: Integer); inline;
1830 x
:= Obj
.X
+Obj
.Rect
.X
;
1831 y
:= Obj
.Y
+Obj
.Rect
.Y
;
1832 w
:= Obj
.Rect
.Width
;
1833 h
:= Obj
.Rect
.Height
;
1836 procedure TGib
.moveBy (dx
, dy
: Integer); inline;
1838 if (dx
<> 0) or (dy
<> 0) then
1847 procedure TShell
.getMapBox (out x
, y
, w
, h
: Integer); inline;
1851 w
:= Obj
.Rect
.Width
;
1852 h
:= Obj
.Rect
.Height
;
1855 procedure TShell
.moveBy (dx
, dy
: Integer); inline;
1857 if (dx
<> 0) or (dy
<> 0) then
1866 procedure TGib
.positionChanged (); inline; begin end;
1867 procedure TShell
.positionChanged (); inline; begin end;
1870 procedure g_Player_DrawCorpses();
1875 for i
:= 0 to High(gGibs
) do
1876 if gGibs
[i
].alive
then
1879 if not g_Obj_Collide(sX
, sY
, sWidth
, sHeight
, @Obj
) then
1882 Obj
.lerp(gLerpFactor
, fX
, fY
);
1884 a
.X
:= Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2);
1885 a
.y
:= Obj
.Rect
.Y
+(Obj
.Rect
.Height
div 2);
1887 e_DrawAdv(ID
, fX
, fY
, 0, True, False, RAngle
, @a
, TMirrorType
.None
);
1890 e_DrawAdv(MaskID
, fX
, fY
, 0, True, False, RAngle
, @a
, TMirrorType
.None
);
1896 for i
:= 0 to High(gCorpses
) do
1897 if gCorpses
[i
] <> nil then
1901 procedure g_Player_DrawShells();
1906 for i
:= 0 to High(gShells
) do
1907 if gShells
[i
].alive
then
1910 if not g_Obj_Collide(sX
, sY
, sWidth
, sHeight
, @Obj
) then
1913 Obj
.lerp(gLerpFactor
, fX
, fY
);
1918 e_DrawAdv(SpriteID
, fX
, fY
, 0, True, False, RAngle
, @a
, TMirrorType
.None
);
1922 procedure g_Player_RemoveAllCorpses();
1927 SetLength(gGibs
, MaxGibs
);
1930 SetLength(gShells
, MaxGibs
);
1935 for i
:= 0 to High(gCorpses
) do
1936 FreeAndNil(gCorpses
[i
]);
1937 SetLength(gCorpses
, MaxCorpses
);
1940 procedure g_Player_Corpses_SaveState (st
: TStream
);
1945 // Ñ÷èòàåì êîëè÷åñòâî ñóùåñòâóþùèõ òðóïîâ
1947 for i
:= 0 to High(gCorpses
) do
1948 if gCorpses
[i
] <> nil then
1951 // Êîëè÷åñòâî òðóïîâ
1952 st
.WriteDWordLE(count
);
1953 if count
= 0 then Exit
;
1956 for i
:= 0 to High(gCorpses
) do
1958 if gCorpses
[i
] <> nil then
1960 utils
.writeStr(st
, gCorpses
[i
].FModelName
); // Íàçâàíèå ìîäåëè
1961 st
.WriteBool(gCorpses
[i
].Mess
); // Òèï ñìåðòè
1962 gCorpses
[i
].SaveState(st
); // Ñîõðàíÿåì äàííûå òðóïà:
1968 procedure g_Player_Corpses_LoadState (st
: TStream
);
1975 g_Player_RemoveAllCorpses();
1977 // Êîëè÷åñòâî òðóïîâ:
1978 count
:= st
.ReadDWordLE();
1979 if count
= 0 then Exit
;
1980 if Length(gCorpses
) < count
then
1981 raise XStreamError
.Create('invalid number of corpses');
1984 for i
:= 0 to count
-1 do
1986 str
:= utils
.readStr(st
); // Íàçâàíèå ìîäåëè:
1987 b
:= st
.ReadBool(); // Òèï ñìåðòè
1990 gCorpses
[i
] := TCorpse
.Create(0, 0, str
, b
);
1991 gCorpses
[i
].LoadState(st
); // Çàãðóæàåì äàííûå òðóïà
1998 function TPlayer
.isValidViewPort (): Boolean; inline;
2000 Result
:= (viewPortW
> 0) and (viewPortH
> 0);
2003 procedure TPlayer
.BFGHit();
2005 g_Weapon_BFGHit(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
2006 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2));
2007 if g_Game_IsServer
and g_Game_IsNet
then
2008 MH_SEND_Effect(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
2009 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2),
2013 procedure TPlayer
.ChangeModel(ModelName
: string);
2015 locModel
: TPlayerModel
;
2017 locModel
:= g_PlayerModel_Get(ModelName
);
2018 if locModel
= nil then Exit
;
2024 procedure TPlayer
.SetModel(ModelName
: string);
2028 m
:= g_PlayerModel_Get(ModelName
);
2031 g_SimpleError(Format(_lc
[I_GAME_ERROR_MODEL_FALLBACK
], [ModelName
]));
2032 m
:= g_PlayerModel_Get('doomer');
2035 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], ['doomer']));
2040 if FModel
<> nil then
2045 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
])
2046 then FModel
.Color
:= FColor
2047 else FModel
.Color
:= TEAMCOLOR
[FTeam
];
2049 FModel
.SetWeapon(FCurrWeap
);
2050 FModel
.SetFlag(FFlag
);
2051 SetDirection(FDirection
);
2054 procedure TPlayer
.SetColor(Color
: TRGB
);
2057 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
2058 if FModel
<> nil then FModel
.Color
:= Color
;
2063 function TPlayer
.GetColor(): TRGB
;
2065 result
:= FModel
.Color
;
2068 procedure TPlayer
.SetWeaponPrefs(Prefs
: Array of Byte);
2072 for i
:= WP_FIRST
to WP_LAST
+ 1 do
2074 if (Prefs
[i
] > WP_LAST
+ 1) then
2075 FWeapPreferences
[i
] := 0
2077 FWeapPreferences
[i
] := Prefs
[i
];
2081 procedure TPlayer
.SetWeaponPref(Weapon
, Pref
: Byte);
2083 if (Weapon
> WP_LAST
+ 1) then
2085 else if (Pref
<= WP_LAST
+ 1) and (Weapon
<= WP_LAST
+ 1) then
2086 FWeapPreferences
[Weapon
] := Pref
2087 else if (Weapon
<= WP_LAST
+ 1) and (Pref
> WP_LAST
+ 1) then
2088 FWeapPreferences
[Weapon
] := 0;
2091 function TPlayer
.GetWeaponPref(Weapon
: Byte) : Byte;
2093 if (Weapon
> WP_LAST
+ 1) then
2095 else if (FWeapPreferences
[Weapon
] > WP_LAST
+ 1) then
2098 result
:= FWeapPreferences
[Weapon
];
2101 function TPlayer
.GetMorePrefered() : Byte;
2103 testedWeap
, i
: Byte;
2105 testedWeap
:= FCurrWeap
;
2106 for i
:= WP_FIRST
to WP_LAST
do
2107 if FWeapon
[i
] and maySwitch(i
) and (FWeapPreferences
[i
] > FWeapPreferences
[testedWeap
]) then
2109 if (R_BERSERK
in FInventory
) and (FWeapPreferences
[WP_LAST
+ 1] > FWeapPreferences
[testedWeap
]) then
2110 testedWeap
:= WEAPON_IRONFIST
;
2111 result
:= testedWeap
;
2114 function TPlayer
.maySwitch(Weapon
: Byte) : Boolean;
2117 if (Weapon
= WEAPON_IRONFIST
) and (FSkipIronFist
<> 0) then
2119 if (FSkipIronFist
= 1) and (not (R_BERSERK
in FInventory
)) then
2122 else if (FSwitchToEmpty
= 0) and (not hasAmmoForShooting(Weapon
)) then
2126 procedure TPlayer
.SwitchTeam
;
2128 if g_Game_IsClient
then
2130 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then Exit
;
2132 if gGameOn
and FAlive
then
2133 Kill(K_SIMPLEKILL
, FUID
, HIT_SELF
);
2135 if FTeam
= TEAM_RED
then
2137 ChangeTeam(TEAM_BLUE
);
2138 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_BLUE
], [FName
]), True);
2139 if g_Game_IsNet
then
2140 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM
, TEAM_BLUE
, FName
);
2144 ChangeTeam(TEAM_RED
);
2145 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_RED
], [FName
]), True);
2146 if g_Game_IsNet
then
2147 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM
, TEAM_RED
, FName
);
2149 FPreferredTeam
:= FTeam
;
2152 procedure TPlayer
.ChangeTeam(Team
: Byte);
2159 TEAM_RED
, TEAM_BLUE
:
2160 FModel
.Color
:= TEAMCOLOR
[Team
];
2162 FModel
.Color
:= FColor
;
2164 if (FTeam
<> OldTeam
) and g_Game_IsNet
and g_Game_IsServer
then
2165 MH_SEND_PlayerStats(FUID
);
2169 procedure TPlayer.CollideItem();
2174 if gItems = nil then Exit;
2175 if not FAlive then Exit;
2177 for i := 0 to High(gItems) do
2180 if (ItemType <> ITEM_NONE) and alive then
2181 if g_Obj_Collide(FObj.X+PLAYER_RECT.X, FObj.Y+PLAYER_RECT.Y, PLAYER_RECT.Width,
2182 PLAYER_RECT.Height, @Obj) then
2184 if not PickItem(ItemType, gItems[i].Respawnable, r) then Continue;
2186 if ItemType in [ITEM_SPHERE_BLUE, ITEM_SPHERE_WHITE, ITEM_INVUL] then
2187 g_Sound_PlayExAt('SOUND_ITEM_GETPOWERUP', FObj.X, FObj.Y)
2188 else if ItemType in [ITEM_MEDKIT_SMALL, ITEM_MEDKIT_LARGE, ITEM_MEDKIT_BLACK] then
2189 g_Sound_PlayExAt('SOUND_ITEM_GETMED', FObj.X, FObj.Y)
2190 else g_Sound_PlayExAt('SOUND_ITEM_GETITEM', FObj.X, FObj.Y);
2192 // Íàäî óáðàòü ñ êàðòû, åñëè ýòî íå êëþ÷, êîòîðûì íóæíî ïîäåëèòüñÿ ñ äðóãèì èãðîêîì:
2193 if r and not ((ItemType in [ITEM_KEY_RED, ITEM_KEY_GREEN, ITEM_KEY_BLUE]) and
2194 (gGameSettings.GameType = GT_SINGLE) and
2195 (g_Player_GetCount() > 1)) then
2196 if not Respawnable then g_Items_Remove(i) else g_Items_Pick(i);
2202 function TPlayer
.CollideLevel(XInc
, YInc
: Integer): Boolean;
2204 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
2205 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_WALL
,
2209 constructor TPlayer
.Create();
2215 mEDamageType
:= HIT_SOME
;
2221 {$IFDEF ENABLE_SOUND}
2222 FSawSound
:= TPlayableSound
.Create();
2223 FSawSoundIdle
:= TPlayableSound
.Create();
2224 FSawSoundHit
:= TPlayableSound
.Create();
2225 FSawSoundSelect
:= TPlayableSound
.Create();
2226 FFlameSoundOn
:= TPlayableSound
.Create();
2227 FFlameSoundOff
:= TPlayableSound
.Create();
2228 FFlameSoundWork
:= TPlayableSound
.Create();
2229 FJetSoundFly
:= TPlayableSound
.Create();
2230 FJetSoundOn
:= TPlayableSound
.Create();
2231 FJetSoundOff
:= TPlayableSound
.Create();
2233 FSawSound
.SetByName('SOUND_WEAPON_FIRESAW');
2234 FSawSoundIdle
.SetByName('SOUND_WEAPON_IDLESAW');
2235 FSawSoundHit
.SetByName('SOUND_WEAPON_HITSAW');
2236 FSawSoundSelect
.SetByName('SOUND_WEAPON_SELECTSAW');
2237 FFlameSoundOn
.SetByName('SOUND_WEAPON_FLAMEON');
2238 FFlameSoundOff
.SetByName('SOUND_WEAPON_FLAMEOFF');
2239 FFlameSoundWork
.SetByName('SOUND_WEAPON_FLAMEWORK');
2240 FJetSoundFly
.SetByName('SOUND_PLAYER_JETFLY');
2241 FJetSoundOn
.SetByName('SOUND_PLAYER_JETON');
2242 FJetSoundOff
.SetByName('SOUND_PLAYER_JETOFF');
2245 FSpectatePlayer
:= -1;
2249 FSavedStateNum
:= -1;
2257 FActualModelName
:= 'doomer';
2260 FObj
.Rect
:= PLAYER_RECT
;
2262 FBFGFireCounter
:= -1;
2263 FJustTeleported
:= False;
2266 FWaitForFirstSpawn
:= false;
2271 procedure TPlayer
.positionChanged (); inline;
2275 procedure TPlayer
.doDamage (v
: Integer);
2277 if (v
<= 0) then exit
;
2278 if (v
> 32767) then v
:= 32767;
2279 Damage(v
, 0, 0, 0, mEDamageType
);
2282 procedure TPlayer
.Damage(value
: Word; SpawnerUID
: Word; vx
, vy
: Integer; t
: Byte);
2286 if (not g_Game_IsClient
) and (not FAlive
) then
2291 // Íåóÿçâèìîñòü íå ñïàñàåò îò ëîâóøåê:
2292 if ((t
= HIT_TRAP
) or (t
= HIT_SELF
)) and (not FGodMode
) then
2294 if not g_Game_IsClient
then
2297 if t
= HIT_TRAP
then
2299 // Ëîâóøêà óáèâàåò ñðàçó:
2301 Kill(K_EXTRAHARDKILL
, SpawnerUID
, t
);
2303 if t
= HIT_SELF
then
2307 Kill(K_SIMPLEKILL
, SpawnerUID
, t
);
2310 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
2311 FPowerups
[MR_SUIT
] := 0;
2312 FPowerups
[MR_INVUL
] := 0;
2313 FPowerups
[MR_INVIS
] := 0;
2318 // Íî îò îñòàëüíîãî ñïàñàåò:
2319 if FPowerups
[MR_INVUL
] >= gTime
then
2326 // Åñëè åñòü óðîí ñâîèì, èëè ðàíèë ñàì ñåáÿ, èëè òåáÿ ðàíèë ïðîòèâíèê:
2327 if (TGameOption
.FRIENDLY_FIRE
in gGameSettings
.Options
) or
2328 (SpawnerUID
= FUID
) or
2329 (not SameTeam(FUID
, SpawnerUID
)) then
2331 FLastSpawnerUID
:= SpawnerUID
;
2333 // Êðîâü (ïóçûðüêè, åñëè â âîäå):
2334 if gBloodCount
> 0 then
2336 c
:= Min(value
, 200)*gBloodCount
+ Random(Min(value
, 200) div 2);
2337 if value
div 4 <= c
then
2338 c
:= c
- (value
div 4)
2342 if (t
= HIT_SOME
) and (vx
= 0) and (vy
= 0) then
2346 HIT_TRAP
, HIT_ACID
, HIT_FLAME
, HIT_SELF
: MakeBloodSimple(c
);
2347 HIT_BFG
, HIT_ROCKET
, HIT_SOME
: MakeBloodVector(c
, vx
, vy
);
2350 if t
= HIT_WATER
then
2351 g_Game_Effect_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
2352 FObj
.Y
+PLAYER_RECT
.Y
-4, value
div 2, 8, 4);
2357 Inc(FDamageBuffer
, value
);
2361 FPain
:= FPain
+ value
;
2364 if g_Game_IsServer
and g_Game_IsNet
then
2366 MH_SEND_PlayerDamage(FUID
, t
, SpawnerUID
, value
, vx
, vy
);
2367 MH_SEND_PlayerStats(FUID
);
2368 MH_SEND_PlayerPos(False, FUID
);
2372 function TPlayer
.Heal(value
: Word; Soft
: Boolean): Boolean;
2375 if g_Game_IsClient
then
2380 if Soft
and (FHealth
< PLAYER_HP_SOFT
) then
2382 IncMax(FHealth
, value
, PLAYER_HP_SOFT
);
2385 if (not Soft
) and (FHealth
< PLAYER_HP_LIMIT
) then
2387 IncMax(FHealth
, value
, PLAYER_HP_LIMIT
);
2391 if Result
and g_Game_IsServer
and g_Game_IsNet
then
2392 MH_SEND_PlayerStats(FUID
);
2395 destructor TPlayer
.Destroy();
2397 if (gPlayer1
<> nil) and (gPlayer1
.FUID
= FUID
) then
2399 if (gPlayer2
<> nil) and (gPlayer2
.FUID
= FUID
) then
2402 {$IFDEF ENABLE_SOUND}
2404 FSawSoundIdle
.Free();
2405 FSawSoundHit
.Free();
2406 FSawSoundSelect
.Free();
2407 FFlameSoundOn
.Free();
2408 FFlameSoundOff
.Free();
2409 FFlameSoundWork
.Free();
2410 FJetSoundFly
.Free();
2412 FJetSoundOff
.Free();
2421 procedure TPlayer
.DrawIndicator(Color
: TRGB
);
2423 indX
, indY
, fX
, fY
, fSlope
: Integer;
2433 FObj
.lerp(gLerpFactor
, fX
, fY
);
2434 fSlope
:= nlerp(FSlopeOld
, FObj
.slopeUpLeft
, gLerpFactor
);
2436 case gPlayerIndicatorStyle
of
2439 if g_Texture_Get('TEXTURE_PLAYER_INDICATOR', ID
) then
2441 e_GetTextureSize(ID
, @indW
, @indH
);
2445 if (FObj
.X
+ FObj
.Rect
.X
) < 0 then
2448 indX
:= fX
+ FObj
.Rect
.X
+ FObj
.Rect
.Width
;
2449 indY
:= fY
+ FObj
.Rect
.Y
+ (FObj
.Rect
.Height
- indW
) div 2;
2452 else if (FObj
.X
+ FObj
.Rect
.X
+ FObj
.Rect
.Width
) > Max(gMapInfo
.Width
, gPlayerScreenSize
.X
) then
2455 indX
:= fX
+ FObj
.Rect
.X
- indH
;
2456 indY
:= fY
+ FObj
.Rect
.Y
+ (FObj
.Rect
.Height
- indW
) div 2;
2459 else if (FObj
.Y
- indH
) < 0 then
2462 indX
:= fX
+ FObj
.Rect
.X
+ (FObj
.Rect
.Width
- indW
) div 2;
2463 indY
:= fY
+ FObj
.Rect
.Y
+ FObj
.Rect
.Height
;
2469 indX
:= fX
+ FObj
.Rect
.X
+ (FObj
.Rect
.Width
- indW
) div 2;
2473 indY
:= indY
+ fSlope
;
2474 indX
:= EnsureRange(indX
, 0, Max(gMapInfo
.Width
, gPlayerScreenSize
.X
) - indW
);
2475 indY
:= EnsureRange(indY
, 0, Max(gMapInfo
.Height
, gPlayerScreenSize
.Y
) - indH
);
2479 e_DrawAdv(ID
, indX
, indY
, 0, True, False, indA
, @a
);
2486 e_TextureFontGetSize(gStdFont
, nW
, nH
);
2487 indX
:= fX
+ FObj
.Rect
.X
+ (FObj
.Rect
.Width
- Length(FName
) * nW
) div 2;
2488 indY
:= fY
- nH
+ fSlope
;
2489 e_TextureFontPrintEx(indX
, indY
, FName
, gStdFont
, Color
.R
, Color
.G
, Color
.B
, 1.0, True);
2495 procedure TPlayer
.DrawBubble();
2497 bubX
, bubY
, fX
, fY
: Integer;
2500 Rw
, Gw
, Bw
: SmallInt
;
2504 CObj
:= getCameraObj();
2505 CObj
.lerp(gLerpFactor
, fX
, fY
);
2506 // NB: _F_Obj.Rect is used to keep the bubble higher; this is not a mistake
2507 bubX
:= fX
+FObj
.Rect
.X
+ IfThen(FDirection
= TDirection
.D_LEFT
, -4, 18);
2508 bubY
:= fY
+FObj
.Rect
.Y
- 18;
2516 1: // simple textual non-bubble
2518 bubX
:= fX
+FObj
.Rect
.X
- 11;
2519 bubY
:= fY
+FObj
.Rect
.Y
- 17;
2520 e_TextureFontPrint(bubX
, bubY
, '[...]', gStdFont
);
2523 2: // advanced pixel-perfect bubble
2525 if FTeam
= TEAM_RED
then
2528 if FTeam
= TEAM_BLUE
then
2531 3: // colored bubble
2533 Rb
:= FModel
.Color
.R
;
2534 Gb
:= FModel
.Color
.G
;
2535 Bb
:= FModel
.Color
.B
;
2536 Rw
:= Min(Rb
* 2 + 64, 255);
2537 Gw
:= Min(Gb
* 2 + 64, 255);
2538 Bw
:= Min(Bb
* 2 + 64, 255);
2539 if (Abs(Rw
- Rb
) < 32)
2540 or (Abs(Gw
- Gb
) < 32)
2541 or (Abs(Bw
- Bb
) < 32) then
2543 Rb
:= Max(Rw
div 2 - 16, 0);
2544 Gb
:= Max(Gw
div 2 - 16, 0);
2545 Bb
:= Max(Bw
div 2 - 16, 0);
2548 4: // custom textured bubble
2550 if g_Texture_Get('TEXTURE_PLAYER_TALKBUBBLE', ID
) then
2551 if FDirection
= TDirection
.D_RIGHT
then
2552 e_Draw(ID
, bubX
- 6, bubY
- 7, 0, True, False)
2554 e_Draw(ID
, bubX
- 6, bubY
- 7, 0, True, False, TMirrorType
.Horizontal
);
2560 e_DrawQuad(bubX
+ 1, bubY
, bubX
+ 18, bubY
+ 13, Rb
, Gb
, Bb
);
2561 e_DrawQuad(bubX
, bubY
+ 1, bubX
+ 19, bubY
+ 12, Rb
, Gb
, Bb
);
2563 e_DrawFillQuad(bubX
+ 1, bubY
+ 1, bubX
+ 18, bubY
+ 12, Rw
, Gw
, Bw
, 0);
2566 Dot
:= IfThen(FDirection
= TDirection
.D_LEFT
, 14, 5);
2567 e_DrawLine(1, bubX
+ Dot
, bubY
+ 14, bubX
+ Dot
, bubY
+ 16, Rb
, Gb
, Bb
);
2568 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
);
2569 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
);
2570 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
);
2571 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
);
2575 e_DrawFillQuad(bubX
+ Dot
, bubY
+ 8, bubX
+ Dot
+ 1, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2576 e_DrawFillQuad(bubX
+ Dot
+ 3, bubY
+ 8, bubX
+ Dot
+ 4, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2577 e_DrawFillQuad(bubX
+ Dot
+ 6, bubY
+ 8, bubX
+ Dot
+ 7, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2580 procedure TPlayer
.Draw();
2585 Mirror
: TMirrorType
;
2586 fX
, fY
, fSlope
: Integer;
2588 FObj
.lerp(gLerpFactor
, fX
, fY
);
2589 fSlope
:= nlerp(FSlopeOld
, FObj
.slopeUpLeft
, gLerpFactor
);
2593 if Direction
= TDirection
.D_RIGHT
then
2594 Mirror
:= TMirrorType
.None
2596 Mirror
:= TMirrorType
.Horizontal
;
2598 if FPunchAnim
<> nil then
2600 FPunchAnim
.Draw(fX
+IfThen(Direction
= TDirection
.D_LEFT
, 15-FObj
.Rect
.X
, FObj
.Rect
.X
-15),
2601 fY
+fSlope
+FObj
.Rect
.Y
-11, Mirror
);
2602 if FPunchAnim
.played
then
2603 FreeAndNil(FPunchAnim
);
2606 if (FPowerups
[MR_INVUL
] > gTime
) and ((gPlayerDrawn
<> Self
) or (FSpawnInvul
>= gTime
)) then
2607 if g_Texture_Get('TEXTURE_PLAYER_INVULPENTA', ID
) then
2609 e_GetTextureSize(ID
, @w
, @h
);
2610 if FDirection
= TDirection
.D_LEFT
then
2611 e_Draw(ID
, fX
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2)-(w
div 2)+4,
2612 fY
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2)-(h
div 2)-7+fSlope
, 0, True, False)
2614 e_Draw(ID
, fX
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2)-(w
div 2)-2,
2615 fY
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2)-(h
div 2)-7+fSlope
, 0, True, False);
2618 if FPowerups
[MR_INVIS
] > gTime
then
2620 if (gPlayerDrawn
<> nil) and ((Self
= gPlayerDrawn
) or
2621 ((FTeam
= gPlayerDrawn
.Team
) and (gGameSettings
.GameMode
<> GM_DM
))) then
2623 if (FPowerups
[MR_INVIS
] - gTime
) <= 2100
2624 then dr
:= not Odd((FPowerups
[MR_INVIS
] - gTime
) div 300)
2627 then FModel
.Draw(fX
, fY
+fSlope
, 200)
2628 else FModel
.Draw(fX
, fY
+fSlope
);
2631 FModel
.Draw(fX
, fY
+fSlope
, 255);
2634 FModel
.Draw(fX
, fY
+fSlope
);
2637 if g_debug_Frames
then
2639 e_DrawQuad(FObj
.X
+FObj
.Rect
.X
,
2641 FObj
.X
+FObj
.Rect
.X
+FObj
.Rect
.Width
-1,
2642 FObj
.Y
+FObj
.Rect
.Y
+FObj
.Rect
.Height
-1,
2646 if (gChatBubble
> 0) and (FKeys
[KEY_CHAT
].Pressed
) and not FGhost
then
2647 if (FPowerups
[MR_INVIS
] <= gTime
) or ((gPlayerDrawn
<> nil) and ((Self
= gPlayerDrawn
) or
2648 ((FTeam
= gPlayerDrawn
.Team
) and (gGameSettings
.GameMode
<> GM_DM
)))) then
2650 // e_DrawPoint(5, 335, 288, 255, 0, 0); // DL, UR, DL, UR
2651 if gAimLine
and alive
and
2652 ((Self
= gPlayer1
) or (Self
= gPlayer2
)) then
2657 procedure TPlayer
.DrawAim();
2658 procedure drawCast (sz
: Integer; ax0
, ay0
, ax1
, ay1
: Integer);
2663 {$IFDEF ENABLE_HOLMES}
2664 if isValidViewPort
and (self
= gPlayer1
) then
2666 g_Holmes_plrLaser(ax0
, ay0
, ax1
, ay1
);
2670 e_DrawLine(sz
, ax0
, ay0
, ax1
, ay1
, 255, 0, 0, 96);
2671 if (g_Map_traceToNearestWall(ax0
, ay0
, ax1
, ay1
, @ex
, @ey
) <> nil) then
2673 e_DrawLine(sz
, ax0
, ay0
, ex
, ey
, 0, 255, 0, 96);
2677 e_DrawLine(sz
, ax0
, ay0
, ex
, ey
, 0, 0, 255, 96);
2682 wx
, wy
, xx
, yy
: Integer;
2686 wx
:= FObj
.X
+ WEAPONPOINT
[FDirection
].X
+ IfThen(FDirection
= TDirection
.D_LEFT
, 7, -7);
2687 wy
:= FObj
.Y
+ WEAPONPOINT
[FDirection
].Y
;
2696 1: begin // Chainsaw
2703 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2704 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2705 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2706 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2711 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2712 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2713 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2714 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2716 4: begin // Double Shotgun
2719 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2720 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2721 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2722 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2724 5: begin // Chaingun
2727 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2728 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2729 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2730 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2732 6: begin // Rocket Launcher
2735 if angle
= ANGLE_RIGHTUP
then Inc(angle
, 2);
2736 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2737 if angle
= ANGLE_LEFTUP
then Dec(angle
, 2);
2738 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2740 7: begin // Plasmagun
2743 if angle
= ANGLE_RIGHTUP
then Inc(angle
);
2744 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 3);
2745 if angle
= ANGLE_LEFTUP
then Dec(angle
);
2746 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 3);
2751 if angle
= ANGLE_RIGHTUP
then Inc(angle
, 1);
2752 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 2);
2753 if angle
= ANGLE_LEFTUP
then Dec(angle
, 1);
2754 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 2);
2756 9: begin // Super Chaingun
2759 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2760 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2761 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2762 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2765 xx
:= Trunc(Cos(-DegToRad(angle
)) * len
) + wx
;
2766 yy
:= Trunc(Sin(-DegToRad(angle
)) * len
) + wy
;
2767 {$IF DEFINED(D2F_DEBUG)}
2768 drawCast(sz
, wx
, wy
, xx
, yy
);
2770 e_DrawLine(sz
, wx
, wy
, xx
, yy
, 255, 0, 0, 96);
2774 procedure TPlayer
.DrawGUI();
2777 X
, Y
, SY
, a
, p
, m
: Integer;
2781 stat
: TPlayerStatArray
;
2783 X
:= gPlayerScreenSize
.X
;
2784 SY
:= gPlayerScreenSize
.Y
;
2787 if gShowScore
and (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
2789 if gGameSettings
.GameMode
= GM_CTF
2793 if gGameSettings
.GameMode
= GM_CTF
then
2795 s
:= 'TEXTURE_PLAYER_REDFLAG';
2796 if gFlags
[FLAG_RED
].State
= FLAG_STATE_CAPTURED
then
2797 s
:= 'TEXTURE_PLAYER_REDFLAG_S';
2798 if gFlags
[FLAG_RED
].State
= FLAG_STATE_DROPPED
then
2799 s
:= 'TEXTURE_PLAYER_REDFLAG_D';
2800 if g_Texture_Get(s
, ID
) then
2801 e_Draw(ID
, X
-16-32, 240-72-4, 0, True, False);
2804 s
:= IntToStr(gTeamStat
[TEAM_RED
].Score
);
2805 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2806 e_CharFont_PrintEx(gMenuFont
, X
-16-a
-tw
, 240-72-4, s
, TEAMCOLOR
[TEAM_RED
]);
2808 if gGameSettings
.GameMode
= GM_CTF
then
2810 s
:= 'TEXTURE_PLAYER_BLUEFLAG';
2811 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_CAPTURED
then
2812 s
:= 'TEXTURE_PLAYER_BLUEFLAG_S';
2813 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_DROPPED
then
2814 s
:= 'TEXTURE_PLAYER_BLUEFLAG_D';
2815 if g_Texture_Get(s
, ID
) then
2816 e_Draw(ID
, X
-16-32, 240-32-4, 0, True, False);
2819 s
:= IntToStr(gTeamStat
[TEAM_BLUE
].Score
);
2820 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2821 e_CharFont_PrintEx(gMenuFont
, X
-16-a
-tw
, 240-32-4, s
, TEAMCOLOR
[TEAM_BLUE
]);
2824 if g_Texture_Get('TEXTURE_PLAYER_HUDBG', ID
) then
2825 e_DrawFill(ID
, X
, 0, 1, (gPlayerScreenSize
.Y
div 256)+IfThen(gPlayerScreenSize
.Y
mod 256 > 0, 1, 0),
2828 if g_Texture_Get('TEXTURE_PLAYER_HUD', ID
) then
2829 e_Draw(ID
, X
+2, Y
, 0, True, False);
2831 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
2835 s
:= IntToStr(Frags
);
2836 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2837 e_CharFont_PrintEx(gMenuFont
, X
-16-tw
, Y
, s
, _RGB(255, 0, 0));
2842 stat
:= g_Player_GetStats();
2847 for a
:= 0 to High(stat
) do
2848 if stat
[a
].Name
<> Name
then
2850 if stat
[a
].Frags
> m
then m
:= stat
[a
].Frags
;
2851 if stat
[a
].Frags
> Frags
then p
:= p
+1;
2855 s
:= IntToStr(p
)+' / '+IntToStr(Length(stat
))+' ';
2856 if Frags
>= m
then s
:= s
+'+' else s
:= s
+'-';
2857 s
:= s
+IntToStr(Abs(Frags
-m
));
2859 e_CharFont_GetSize(gMenuSmallFont
, s
, tw
, th
);
2860 e_CharFont_PrintEx(gMenuSmallFont
, X
-16-tw
, Y
+32, s
, _RGB(255, 0, 0));
2863 if gLMSRespawn
> LMS_RESPAWN_NONE
then
2865 s
:= _lc
[I_GAME_WARMUP
];
2866 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2867 s
:= s
+ ': ' + IntToStr((gLMSRespawnTime
- gTime
) div 1000);
2868 e_CharFont_PrintEx(gMenuFont
, X
-64-tw
, SY
-32, s
, _RGB(0, 255, 0));
2870 else if gShowLives
and (gGameSettings
.MaxLives
> 0) then
2872 s
:= IntToStr(Lives
);
2873 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2874 e_CharFont_PrintEx(gMenuFont
, X
-16-tw
, SY
-32, s
, _RGB(0, 255, 0));
2878 e_CharFont_GetSize(gMenuSmallFont
, FName
, tw
, th
);
2879 e_CharFont_PrintEx(gMenuSmallFont
, X
+98-(tw
div 2), Y
+8, FName
, _RGB(255, 0, 0));
2881 if R_BERSERK
in FInventory
2882 then e_Draw(gItemsTexturesID
[ITEM_MEDKIT_BLACK
], X
+37, Y
+45, 0, True, False)
2883 else e_Draw(gItemsTexturesID
[ITEM_MEDKIT_LARGE
], X
+37, Y
+45, 0, True, False);
2885 if g_Texture_Get('TEXTURE_PLAYER_ARMORHUD', ID
) then
2886 e_Draw(ID
, X
+36, Y
+77, 0, True, False);
2888 s
:= IntToStr(IfThen(FHealth
> 0, FHealth
, 0));
2889 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2890 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+40, s
, _RGB(255, 0, 0));
2892 s
:= IntToStr(FArmor
);
2893 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2894 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+68, s
, _RGB(255, 0, 0));
2896 s
:= IntToStr(GetAmmoByWeapon(FCurrWeap
));
2902 ID
:= gItemsTexturesID
[ITEM_WEAPON_IRONFIST
];
2907 ID
:= gItemsTexturesID
[ITEM_WEAPON_SAW
];
2909 WEAPON_PISTOL
: ID
:= gItemsTexturesID
[ITEM_WEAPON_PISTOL
];
2910 WEAPON_CHAINGUN
: ID
:= gItemsTexturesID
[ITEM_WEAPON_CHAINGUN
];
2911 WEAPON_SHOTGUN1
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SHOTGUN1
];
2912 WEAPON_SHOTGUN2
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SHOTGUN2
];
2913 WEAPON_SUPERCHAINGUN
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SUPERCHAINGUN
];
2914 WEAPON_ROCKETLAUNCHER
: ID
:= gItemsTexturesID
[ITEM_WEAPON_ROCKETLAUNCHER
];
2915 WEAPON_PLASMA
: ID
:= gItemsTexturesID
[ITEM_WEAPON_PLASMA
];
2916 WEAPON_BFG
: ID
:= gItemsTexturesID
[ITEM_WEAPON_BFG
];
2917 WEAPON_FLAMETHROWER
: ID
:= gItemsTexturesID
[ITEM_WEAPON_FLAMETHROWER
];
2920 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2921 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+158, s
, _RGB(255, 0, 0));
2922 e_Draw(ID
, X
+20, Y
+160, 0, True, False);
2924 if R_KEY_RED
in FInventory
then
2925 e_Draw(gItemsTexturesID
[ITEM_KEY_RED
], X
+78, Y
+214, 0, True, False);
2927 if R_KEY_GREEN
in FInventory
then
2928 e_Draw(gItemsTexturesID
[ITEM_KEY_GREEN
], X
+95, Y
+214, 0, True, False);
2930 if R_KEY_BLUE
in FInventory
then
2931 e_Draw(gItemsTexturesID
[ITEM_KEY_BLUE
], X
+112, Y
+214, 0, True, False);
2933 if FJetFuel
> 0 then
2935 if g_Texture_Get('TEXTURE_PLAYER_HUDAIR', ID
) then
2936 e_Draw(ID
, X
+2, Y
+116, 0, True, False);
2937 if g_Texture_Get('TEXTURE_PLAYER_HUDJET', ID
) then
2938 e_Draw(ID
, X
+2, Y
+126, 0, True, False);
2939 e_DrawLine(4, X
+16, Y
+122, X
+16+Trunc(168*IfThen(FAir
> 0, FAir
, 0)/AIR_MAX
), Y
+122, 0, 0, 196);
2940 e_DrawLine(4, X
+16, Y
+132, X
+16+Trunc(168*FJetFuel
/JET_MAX
), Y
+132, 208, 0, 0);
2944 if g_Texture_Get('TEXTURE_PLAYER_HUDAIR', ID
) then
2945 e_Draw(ID
, X
+2, Y
+124, 0, True, False);
2946 e_DrawLine(4, X
+16, Y
+130, X
+16+Trunc(168*IfThen(FAir
> 0, FAir
, 0)/AIR_MAX
), Y
+130, 0, 0, 196);
2949 if gShowPing
and g_Game_IsClient
then
2951 s
:= _lc
[I_GAME_PING_HUD
] + IntToStr(NetPeer
.lastRoundTripTime
) + _lc
[I_NET_SLIST_PING_MS
];
2952 e_TextureFontPrint(X
+ 4, Y
+ 242, s
, gStdFont
);
2958 e_TextureFontPrint(X
+ 4, Y
+ 242, _lc
[I_PLAYER_SPECT
], gStdFont
);
2959 e_TextureFontPrint(X
+ 4, Y
+ 258, _lc
[I_PLAYER_SPECT2
], gStdFont
);
2960 e_TextureFontPrint(X
+ 4, Y
+ 274, _lc
[I_PLAYER_SPECT1
], gStdFont
);
2963 e_TextureFontGetSize(gStdFont
, cw
, ch
);
2964 s
:= _lc
[I_PLAYER_SPECT4
];
2965 e_TextureFontPrintEx(gScreenWidth
div 2 - cw
*(Length(s
) div 2),
2966 gScreenHeight
-4-ch
, s
, gStdFont
, 255, 255, 255, 1, True);
2967 e_TextureFontPrint(X
+ 4, Y
+ 290, _lc
[I_PLAYER_SPECT1S
], gStdFont
);
2973 procedure TPlayer
.DrawOverlay();
2977 // Ïðè âçÿòèè íåóÿçâèìîñòè ðèñóåòñÿ èíâåðñèîííûé áåëûé ôîí
2978 if (FPowerups
[MR_INVUL
] >= gTime
) and (FSpawnInvul
< gTime
) then
2980 if (FPowerups
[MR_INVUL
]-gTime
) <= 2100 then
2981 dr
:= not Odd((FPowerups
[MR_INVUL
]-gTime
) div 300)
2986 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2987 191, 191, 191, 0, TBlending
.Invert
);
2990 // Ïðè âçÿòèè çàùèòíîãî êîñòþìà ðèñóåòñÿ çåëåíîâàòûé ôîí
2991 if FPowerups
[MR_SUIT
] >= gTime
then
2993 if (FPowerups
[MR_SUIT
]-gTime
) <= 2100 then
2994 dr
:= not Odd((FPowerups
[MR_SUIT
]-gTime
) div 300)
2999 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
3000 0, 96, 0, 200, TBlending
.None
);
3003 // Ïðè âçÿòèè áåðñåðêà ðèñóåòñÿ êðàñíîâàòûé ôîí
3004 if (FBerserk
>= 0) and (LongWord(FBerserk
) >= gTime
) and (gFlash
= 2) then
3006 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
3007 255, 0, 0, 200, TBlending
.None
);
3011 procedure TPlayer
.DrawPain();
3015 if FPain
= 0 then Exit
;
3019 if a
< 15 then h
:= 0
3020 else if a
< 35 then h
:= 1
3021 else if a
< 55 then h
:= 2
3022 else if a
< 75 then h
:= 3
3023 else if a
< 95 then h
:= 4
3026 //if a > 255 then a := 255;
3028 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1, 255, 0, 0, 255-h
*50);
3029 //e_DrawFillQuad(0, 0, gPlayerScreenSize.X-1, gPlayerScreenSize.Y-1, 255-min(128, a), 255-a, 255-a, 0, B_FILTER);
3032 procedure TPlayer
.DrawPickup();
3036 if FPickup
= 0 then Exit
;
3040 if a
< 15 then h
:= 1
3041 else if a
< 35 then h
:= 2
3042 else if a
< 55 then h
:= 3
3043 else if a
< 75 then h
:= 4
3046 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1, 150, 200, 150, 255-h
*50);
3049 procedure TPlayer
.DoPunch();
3054 if FPunchAnim
<> nil then
3057 FPunchAnim
.Destroy();
3059 st
:= 'FRAMES_PUNCH';
3060 if R_BERSERK
in FInventory
then
3061 st
:= st
+ '_BERSERK';
3062 if FKeys
[KEY_UP
].Pressed
then
3064 else if FKeys
[KEY_DOWN
].Pressed
then
3066 g_Frames_Get(id
, st
);
3067 FPunchAnim
:= TAnimation
.Create(id
, False, 1);
3070 procedure TPlayer
.Fire();
3072 f
, DidFire
: Boolean;
3073 wx
, wy
, xd
, yd
: Integer;
3075 ProjID
: SizeInt
= -1;
3077 if g_Game_IsClient
then Exit
;
3078 // FBFGFireCounter - âðåìÿ ïåðåä âûñòðåëîì (äëÿ BFG)
3079 // FReloading - âðåìÿ ïîñëå âûñòðåëà (äëÿ âñåãî)
3087 if FReloading
[FCurrWeap
] <> 0 then Exit
;
3092 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
3093 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
3094 xd
:= wx
+IfThen(FDirection
= TDirection
.D_LEFT
, -30, 30);
3095 yd
:= wy
+firediry();
3101 if R_BERSERK
in FInventory
then
3103 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
3104 locobj
.X
:= FObj
.X
+FObj
.Rect
.X
;
3105 locobj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
3108 locobj
.rect
.Width
:= 39;
3109 locobj
.rect
.Height
:= 52;
3110 locobj
.Vel
.X
:= (xd
-wx
) div 2;
3111 locobj
.Vel
.Y
:= (yd
-wy
) div 2;
3112 locobj
.Accel
.X
:= xd
-wx
;
3113 locobj
.Accel
.y
:= yd
-wy
;
3115 if g_Weapon_Hit(@locobj
, 50, FUID
, HIT_SOME
) <> 0 then
3117 {$IFDEF ENABLE_SOUND}
3118 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
3123 {$IFDEF ENABLE_SOUND}
3124 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
3128 if (gFlash
= 1) and (FPain
< 50) then FPain
:= min(FPain
+ 25, 50);
3131 g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
3134 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3139 {$IFDEF ENABLE_SOUND}
3140 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
3141 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
3143 FSawSoundSelect
.Stop();
3145 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
3147 else if not FSawSoundHit
.IsPlaying() then
3149 FSawSoundSelect
.Stop();
3150 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
3153 g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
3154 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
);
3157 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3163 if FAmmo
[A_BULLETS
] > 0 then
3165 g_Weapon_pistol(wx
, wy
, xd
, yd
, FUID
);
3166 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3167 Dec(FAmmo
[A_BULLETS
]);
3168 FFireAngle
:= FAngle
;
3171 g_Player_CreateShell(
3172 GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
3173 GameVelX
, GameVelY
-2,
3179 if FAmmo
[A_SHELLS
] > 0 then
3181 g_Weapon_shotgun(wx
, wy
, xd
, yd
, FUID
);
3182 {$IFDEF ENABLE_SOUND}
3183 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', wx
, wy
);
3185 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3186 Dec(FAmmo
[A_SHELLS
]);
3187 FFireAngle
:= FAngle
;
3191 FShellType
:= SHELL_SHELL
;
3195 if FAmmo
[A_SHELLS
] >= 2 then
3197 g_Weapon_dshotgun(wx
, wy
, xd
, yd
, FUID
);
3198 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3199 Dec(FAmmo
[A_SHELLS
], 2);
3200 FFireAngle
:= FAngle
;
3204 FShellType
:= SHELL_DBLSHELL
;
3208 if FAmmo
[A_BULLETS
] > 0 then
3210 g_Weapon_mgun(wx
, wy
, xd
, yd
, FUID
);
3211 {$IFDEF ENABLE_SOUND}
3212 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', wx
, wy
);
3214 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3215 Dec(FAmmo
[A_BULLETS
]);
3216 FFireAngle
:= FAngle
;
3219 g_Player_CreateShell(
3220 GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
3221 GameVelX
, GameVelY
-2,
3226 WEAPON_ROCKETLAUNCHER
:
3227 if FAmmo
[A_ROCKETS
] > 0 then
3229 ProjID
:= g_Weapon_rocket(wx
, wy
, xd
, yd
, FUID
);
3230 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3231 Dec(FAmmo
[A_ROCKETS
]);
3232 FFireAngle
:= FAngle
;
3238 if FAmmo
[A_CELLS
] > 0 then
3240 ProjID
:= g_Weapon_plasma(wx
, wy
, xd
, yd
, FUID
);
3241 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3242 Dec(FAmmo
[A_CELLS
]);
3243 FFireAngle
:= FAngle
;
3249 if (FAmmo
[A_CELLS
] >= 40) and (FBFGFireCounter
= -1) then
3251 FBFGFireCounter
:= 17;
3252 {$IFDEF ENABLE_SOUND}
3253 if not FNoReload
then
3254 g_Sound_PlayExAt('SOUND_WEAPON_STARTFIREBFG', FObj
.X
, FObj
.Y
);
3256 Dec(FAmmo
[A_CELLS
], 40);
3260 WEAPON_SUPERCHAINGUN
:
3261 if FAmmo
[A_SHELLS
] > 0 then
3263 g_Weapon_shotgun(wx
, wy
, xd
, yd
, FUID
);
3264 {$IFDEF ENABLE_SOUND}
3265 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', wx
, wy
);
3267 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3268 Dec(FAmmo
[A_SHELLS
]);
3269 FFireAngle
:= FAngle
;
3272 g_Player_CreateShell(
3273 GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
3274 GameVelX
, GameVelY
-2,
3279 WEAPON_FLAMETHROWER
:
3280 if FAmmo
[A_FUEL
] > 0 then
3282 ProjID
:= g_Weapon_flame(wx
, wy
, xd
, yd
, FUID
);
3284 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3286 FFireAngle
:= FAngle
;
3293 if g_Game_IsNet
and g_Game_IsServer
then MH_SEND_PlayerStats(FUID
);
3297 if g_Game_IsNet
then
3301 if FCurrWeap
<> WEAPON_BFG
then
3302 MH_SEND_PlayerFire(FUID
, FCurrWeap
, wx
, wy
, xd
, yd
, ProjID
)
3304 if not FNoReload
then
3305 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_WEAPON_STARTFIREBFG');
3308 MH_SEND_PlayerStats(FUID
);
3314 0, 180: SetAction(A_ATTACK
);
3315 ANGLE_LEFTDOWN
, ANGLE_RIGHTDOWN
: SetAction(A_ATTACKDOWN
);
3316 ANGLE_LEFTUP
, ANGLE_RIGHTUP
: SetAction(A_ATTACKUP
);
3320 function TPlayer
.GetAmmoByWeapon(Weapon
: Byte): Word;
3323 WEAPON_PISTOL
, WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
];
3324 WEAPON_SHOTGUN1
, WEAPON_SHOTGUN2
, WEAPON_SUPERCHAINGUN
: Result
:= FAmmo
[A_SHELLS
];
3325 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
];
3326 WEAPON_PLASMA
, WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
];
3327 WEAPON_FLAMETHROWER
: Result
:= FAmmo
[A_FUEL
];
3332 function TPlayer
.HeadInLiquid(XInc
, YInc
: Integer): Boolean;
3334 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
+XInc
, FObj
.Y
+PLAYER_HEADRECT
.Y
+YInc
,
3335 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
3336 PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, True);
3339 procedure TPlayer
.FlamerOn
;
3341 {$IFDEF ENABLE_SOUND}
3342 FFlameSoundOff
.Stop();
3343 FFlameSoundOff
.SetPosition(0);
3346 if (not FFlameSoundOn
.IsPlaying()) and (not FFlameSoundWork
.IsPlaying()) then
3347 FFlameSoundWork
.PlayAt(FObj
.X
, FObj
.Y
);
3351 FFlameSoundOn
.PlayAt(FObj
.X
, FObj
.Y
);
3357 procedure TPlayer
.FlamerOff
;
3359 {$IFDEF ENABLE_SOUND}
3362 FFlameSoundOn
.Stop();
3363 FFlameSoundOn
.SetPosition(0);
3364 FFlameSoundWork
.Stop();
3365 FFlameSoundWork
.SetPosition(0);
3366 FFlameSoundOff
.PlayAt(FObj
.X
, FObj
.Y
);
3372 procedure TPlayer
.JetpackOn
;
3374 {$IFDEF ENABLE_SOUND}
3377 FJetSoundOn
.SetPosition(0);
3378 FJetSoundOn
.PlayAt(FObj
.X
, FObj
.Y
);
3383 procedure TPlayer
.JetpackOff
;
3385 {$IFDEF ENABLE_SOUND}
3388 FJetSoundOff
.SetPosition(0);
3389 FJetSoundOff
.PlayAt(FObj
.X
, FObj
.Y
);
3393 procedure TPlayer
.CatchFire(Attacker
: Word; Timeout
: Integer = PLAYER_BURN_TIME
);
3395 if Timeout
<= 0 then
3397 if (FPowerups
[MR_SUIT
] > gTime
) or (FPowerups
[MR_INVUL
] > gTime
) then
3398 exit
; // Íå çàãîðàåìñÿ êîãäà åñòü çàùèòà
3399 if g_Obj_CollidePanel(@FObj
, 0, 0, PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
) then
3400 exit
; // Íå ïîäãîðàåì â âîäå íà âñÿêèé ñëó÷àé
3401 {$IFDEF ENABLE_SOUND}
3402 if FFireTime
<= 0 then
3403 g_Sound_PlayExAt('SOUND_IGNITE', FObj
.X
, FObj
.Y
);
3405 FFireTime
:= Timeout
;
3406 FFireAttacker
:= Attacker
;
3407 if g_Game_IsNet
and g_Game_IsServer
then
3408 MH_SEND_PlayerStats(FUID
);
3411 procedure TPlayer
.Jump();
3413 if gFly
or FJetpack
then
3415 // Ïîëåò (÷èò-êîä èëè äæåòïàê):
3416 if FObj
.Vel
.Y
> -VEL_FLY
then
3417 FObj
.Vel
.Y
:= FObj
.Vel
.Y
- 3;
3420 if FJetFuel
> 0 then
3422 if (FJetFuel
< 1) and g_Game_IsServer
then
3426 if g_Game_IsNet
then
3427 MH_SEND_PlayerStats(FUID
);
3433 // Íå âêëþ÷àòü äæåòïàê â ðåæèìå ïðîõîæäåíèÿ ñêâîçü ñòåíû
3435 FCanJetpack
:= False;
3437 // Ïðûãàåì èëè âñïëûâàåì:
3438 if (CollideLevel(0, 1) or
3439 g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
+36, PLAYER_RECT
.Width
,
3440 PLAYER_RECT
.Height
-33, PANEL_STEP
, False)
3441 ) and (FObj
.Accel
.Y
= 0) then // Íå ïðûãàòü, åñëè åñòü âåðòèêàëüíîå óñêîðåíèå
3443 FObj
.Vel
.Y
:= -VEL_JUMP
;
3444 FCanJetpack
:= False;
3448 if BodyInLiquid(0, 0) then
3449 FObj
.Vel
.Y
:= -VEL_SW
3450 else if (FJetFuel
> 0) and FCanJetpack
and
3451 g_Game_IsServer
and (not g_Obj_CollideLiquid(@FObj
, 0, 0)) then
3455 if g_Game_IsNet
then
3456 MH_SEND_PlayerStats(FUID
);
3461 procedure TPlayer
.Kill(KillType
: Byte; SpawnerUID
: Word; t
: Byte);
3463 a
, i
, k
, ab
, ar
: Byte;
3467 srv
, netsrv
: Boolean;
3473 procedure PushItem(t
: Byte);
3477 id
:= g_Items_Create(FObj
.X
, FObj
.Y
, t
, True, False);
3478 it
:= g_Items_ByIdx(id
);
3479 if KillType
= K_EXTRAHARDKILL
then // -7..+7; -8..0
3481 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-7+Random(15),
3482 (FObj
.Vel
.Y
div 2)-Random(9));
3483 it
.positionChanged(); // this updates spatial accelerators
3487 if KillType
= K_HARDKILL
then // -5..+5; -5..0
3489 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-5+Random(11),
3490 (FObj
.Vel
.Y
div 2)-Random(6));
3492 else // -3..+3; -3..0
3494 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-3+Random(7),
3495 (FObj
.Vel
.Y
div 2)-Random(4));
3497 it
.positionChanged(); // this updates spatial accelerators
3500 if g_Game_IsNet
and g_Game_IsServer
then
3501 MH_SEND_ItemSpawn(True, id
);
3505 DoFrags
:= (gGameSettings
.MaxLives
= 0) or (gGameSettings
.GameMode
= GM_COOP
);
3506 Srv
:= g_Game_IsServer
;
3507 Netsrv
:= g_Game_IsServer
and g_Game_IsNet
;
3508 if Srv
then FDeath
:= FDeath
+ 1;
3513 if not FPhysics
then
3519 if (gGameSettings
.MaxLives
> 0) and Srv
and (gLMSRespawn
= LMS_RESPAWN_NONE
) then
3521 if FLives
> 0 then FLives
:= FLives
- 1;
3522 if FLives
= 0 then FNoRespawn
:= True;
3525 // Íîìåð òèïà ñìåðòè:
3528 K_SIMPLEKILL
: a
:= 1;
3530 K_EXTRAHARDKILL
: a
:= 3;
3535 {$IFDEF ENABLE_SOUND}
3536 if not FModel
.PlaySound(MODELSOUND_DIE
, a
, FObj
.X
, FObj
.Y
) then
3538 if FModel
.PlaySound(MODELSOUND_DIE
, i
, FObj
.X
, FObj
.Y
) then
3546 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN1
;
3548 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN2
;
3549 K_EXTRAHARDKILL
, K_FALLKILL
:
3550 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN3
;
3553 // Ïåðåêëþ÷àåì ñîñòîÿíèå:
3557 K_HARDKILL
, K_EXTRAHARDKILL
:
3561 // Ðåàêöèÿ ìîíñòðîâ íà ñìåðòü èãðîêà:
3562 if (KillType
<> K_FALLKILL
) and (Srv
) then
3563 g_Monsters_killedp();
3565 if SpawnerUID
= FUID
then
3569 if gGameSettings
.GameMode
= GM_TDM
then
3570 Dec(gTeamStat
[FTeam
].Score
);
3571 if DoFrags
or (gGameSettings
.GameMode
= GM_TDM
) then
3577 g_Console_Add(Format(_lc
[I_PLAYER_KILL_SELF
], [FName
]), True);
3580 if g_GetUIDType(SpawnerUID
) = UID_PLAYER
then
3581 begin // Óáèò äðóãèì èãðîêîì
3582 KP
:= g_Player_Get(SpawnerUID
);
3583 if (KP
<> nil) and Srv
then
3585 if (DoFrags
or (gGameSettings
.GameMode
= GM_TDM
)) then
3586 if SameTeam(FUID
, SpawnerUID
) then
3596 if (gGameSettings
.GameMode
= GM_TDM
) and DoFrags
then
3597 Inc(gTeamStat
[KP
.Team
].Score
,
3598 IfThen(SameTeam(FUID
, SpawnerUID
), -1, 1));
3600 if netsrv
then MH_SEND_PlayerStats(SpawnerUID
);
3603 plr
:= g_Player_Get(SpawnerUID
);
3611 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_2
],
3615 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_1
],
3619 g_Console_Add(Format(_lc
[I_PLAYER_KILL
],
3624 else if g_GetUIDType(SpawnerUID
) = UID_MONSTER
then
3625 begin // Óáèò ìîíñòðîì
3626 mon
:= g_Monsters_ByUID(SpawnerUID
);
3630 s
:= g_Mons_GetKilledByTypeId(mon
.MonsterType
);
3634 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_2
],
3638 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_1
],
3642 g_Console_Add(Format(_lc
[I_PLAYER_KILL
],
3647 else // Îñîáûå òèïû ñìåðòè
3650 HIT_SELF
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_SELF
], [FName
]), True);
3651 HIT_FALL
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_FALL
], [FName
]), True);
3652 HIT_WATER
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_WATER
], [FName
]), True);
3653 HIT_ACID
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_ACID
], [FName
]), True);
3654 HIT_TRAP
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_TRAP
], [FName
]), True);
3655 else g_Console_Add(Format(_lc
[I_PLAYER_DIED
], [FName
]), True);
3661 for a
:= WP_FIRST
to WP_LAST
do
3665 WEAPON_SAW
: i
:= ITEM_WEAPON_SAW
;
3666 WEAPON_SHOTGUN1
: i
:= ITEM_WEAPON_SHOTGUN1
;
3667 WEAPON_SHOTGUN2
: i
:= ITEM_WEAPON_SHOTGUN2
;
3668 WEAPON_CHAINGUN
: i
:= ITEM_WEAPON_CHAINGUN
;
3669 WEAPON_ROCKETLAUNCHER
: i
:= ITEM_WEAPON_ROCKETLAUNCHER
;
3670 WEAPON_PLASMA
: i
:= ITEM_WEAPON_PLASMA
;
3671 WEAPON_BFG
: i
:= ITEM_WEAPON_BFG
;
3672 WEAPON_SUPERCHAINGUN
: i
:= ITEM_WEAPON_SUPERCHAINGUN
;
3673 WEAPON_FLAMETHROWER
: i
:= ITEM_WEAPON_FLAMETHROWER
;
3682 if R_ITEM_BACKPACK
in FInventory
then
3683 PushItem(ITEM_AMMO_BACKPACK
);
3685 // Âûáðîñ ðàêåòíîãî ðàíöà:
3686 if FJetFuel
> 0 then
3687 PushItem(ITEM_JETPACK
);
3690 if (not (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
])) or
3691 (not (TGameOption
.DM_KEYS
in gGameSettings
.Options
)) then
3693 if R_KEY_RED
in FInventory
then
3694 PushItem(ITEM_KEY_RED
);
3696 if R_KEY_GREEN
in FInventory
then
3697 PushItem(ITEM_KEY_GREEN
);
3699 if R_KEY_BLUE
in FInventory
then
3700 PushItem(ITEM_KEY_BLUE
);
3704 DropFlag(KillType
= K_FALLKILL
);
3707 FCorpse
:= g_Player_CreateCorpse(Self
);
3709 if Srv
and (gGameSettings
.MaxLives
> 0) and FNoRespawn
and
3710 (gLMSRespawn
= LMS_RESPAWN_NONE
) then
3716 for i
:= Low(gPlayers
) to High(gPlayers
) do
3718 if gPlayers
[i
] = nil then continue
;
3719 if (not gPlayers
[i
].FNoRespawn
) and (not gPlayers
[i
].FSpectator
) then
3722 if gPlayers
[i
].FTeam
= TEAM_RED
then Inc(ar
)
3723 else if gPlayers
[i
].FTeam
= TEAM_BLUE
then Inc(ab
);
3728 OldLR
:= gLMSRespawn
;
3729 if (gGameSettings
.GameMode
= GM_COOP
) then
3733 // everyone is dead, restart the map
3734 g_Game_Message(_lc
[I_MESSAGE_LMS_LOSE
], 144);
3736 MH_SEND_GameEvent(NET_EV_LMS_LOSE
);
3737 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3738 gLMSRespawnTime
:= gTime
+ 5000;
3740 else if (a
= 1) then
3742 if (gPlayers
[k
] <> nil) and not (gPlayers
[k
] is TBot
) then
3743 if (gPlayers
[k
] = gPlayer1
) or
3744 (gPlayers
[k
] = gPlayer2
) then
3745 g_Console_Add('*** ' + _lc
[I_MESSAGE_LMS_SURVIVOR
] + ' ***', True)
3746 else if Netsrv
and (gPlayers
[k
].FClientID
>= 0) then
3747 MH_SEND_GameEvent(NET_EV_LMS_SURVIVOR
, 0, 'N', gPlayers
[k
].FClientID
);
3750 else if (gGameSettings
.GameMode
= GM_TDM
) then
3752 if (ab
= 0) and (ar
<> 0) then
3755 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 144);
3757 MH_SEND_GameEvent(NET_EV_TLMS_WIN
, TEAM_RED
);
3758 Inc(gTeamStat
[TEAM_RED
].Score
);
3759 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3760 gLMSRespawnTime
:= gTime
+ 5000;
3762 else if (ar
= 0) and (ab
<> 0) then
3765 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 144);
3767 MH_SEND_GameEvent(NET_EV_TLMS_WIN
, TEAM_BLUE
);
3768 Inc(gTeamStat
[TEAM_BLUE
].Score
);
3769 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3770 gLMSRespawnTime
:= gTime
+ 5000;
3772 else if (ar
= 0) and (ab
= 0) then
3775 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
3777 MH_SEND_GameEvent(NET_EV_LMS_DRAW
, 0, FName
);
3778 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3779 gLMSRespawnTime
:= gTime
+ 5000;
3782 else if (gGameSettings
.GameMode
= GM_DM
) then
3786 if gPlayers
[k
] <> nil then
3789 // survivor is the winner
3790 g_Game_Message(Format(_lc
[I_MESSAGE_LMS_WIN
], [AnsiUpperCase(FName
)]), 144);
3792 MH_SEND_GameEvent(NET_EV_LMS_WIN
, 0, FName
);
3795 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3796 gLMSRespawnTime
:= gTime
+ 5000;
3798 else if (a
= 0) then
3800 // everyone is dead, restart the map
3801 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
3803 MH_SEND_GameEvent(NET_EV_LMS_DRAW
, 0, FName
);
3804 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3805 gLMSRespawnTime
:= gTime
+ 5000;
3808 if srv
and (OldLR
= LMS_RESPAWN_NONE
) and (gLMSRespawn
> LMS_RESPAWN_NONE
) then
3810 if NetMode
= NET_SERVER
then
3811 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
)
3813 g_Console_Add(Format(_lc
[I_MSG_WARMUP_START
], [(gLMSRespawnTime
- gTime
) div 1000]), True);
3819 MH_SEND_PlayerStats(FUID
);
3820 MH_SEND_PlayerDeath(FUID
, KillType
, t
, SpawnerUID
);
3821 if gGameSettings
.GameMode
= GM_TDM
then MH_SEND_GameStats
;
3824 if srv
and FNoRespawn
then Spectate(True);
3825 FWantsInGame
:= True;
3828 function TPlayer
.BodyInLiquid(XInc
, YInc
: Integer): Boolean;
3830 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
, PLAYER_RECT
.Width
,
3831 PLAYER_RECT
.Height
-20, PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, False);
3834 function TPlayer
.BodyInAcid(XInc
, YInc
: Integer): Boolean;
3836 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
, PLAYER_RECT
.Width
,
3837 PLAYER_RECT
.Height
-20, PANEL_ACID1
or PANEL_ACID2
, False);
3840 procedure TPlayer
.MakeBloodSimple(Count
: Word);
3842 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)+8,
3843 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3844 Count
div 2, 3, -1, 16, (PLAYER_RECT
.Height
*2 div 3),
3845 FModel
.Blood
.R
, FModel
.Blood
.G
, FModel
.Blood
.B
, FModel
.Blood
.Kind
);
3846 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-8,
3847 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3848 Count
div 2, -3, -1, 16, (PLAYER_RECT
.Height
*2) div 3,
3849 FModel
.Blood
.R
, FModel
.Blood
.G
, FModel
.Blood
.B
, FModel
.Blood
.Kind
);
3852 procedure TPlayer
.MakeBloodVector(Count
: Word; VelX
, VelY
: Integer);
3854 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
3855 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3856 Count
, VelX
, VelY
, 16, (PLAYER_RECT
.Height
*2) div 3,
3857 FModel
.Blood
.R
, FModel
.Blood
.G
, FModel
.Blood
.B
, FModel
.Blood
.Kind
);
3860 procedure TPlayer
.ProcessWeaponAction(Action
: Byte);
3862 if g_Game_IsClient
then Exit
;
3864 WP_PREV
: PrevWeapon();
3865 WP_NEXT
: NextWeapon();
3869 procedure TPlayer
.QueueWeaponSwitch(Weapon
: Byte);
3871 if g_Game_IsClient
then Exit
;
3872 if Weapon
> High(FWeapon
) then Exit
;
3873 FNextWeap
:= FNextWeap
or (1 shl Weapon
);
3876 procedure TPlayer
.resetWeaponQueue ();
3879 FNextWeapDelay
:= 0;
3882 function TPlayer
.hasAmmoForWeapon (weapon
: Byte): Boolean;
3886 WEAPON_IRONFIST
, WEAPON_SAW
: result
:= true;
3887 WEAPON_SHOTGUN1
, WEAPON_SHOTGUN2
, WEAPON_SUPERCHAINGUN
: result
:= (FAmmo
[A_SHELLS
] > 0);
3888 WEAPON_PISTOL
, WEAPON_CHAINGUN
: result
:= (FAmmo
[A_BULLETS
] > 0);
3889 WEAPON_ROCKETLAUNCHER
: result
:= (FAmmo
[A_ROCKETS
] > 0);
3890 WEAPON_PLASMA
, WEAPON_BFG
: result
:= (FAmmo
[A_CELLS
] > 0);
3891 WEAPON_FLAMETHROWER
: result
:= (FAmmo
[A_FUEL
] > 0);
3892 else result
:= (weapon
< length(FWeapon
));
3896 function TPlayer
.hasAmmoForShooting (weapon
: Byte): Boolean;
3900 WEAPON_IRONFIST
, WEAPON_SAW
: result
:= true;
3901 WEAPON_SHOTGUN1
, WEAPON_SUPERCHAINGUN
: result
:= (FAmmo
[A_SHELLS
] > 0);
3902 WEAPON_SHOTGUN2
: result
:= (FAmmo
[A_SHELLS
] > 1);
3903 WEAPON_PISTOL
, WEAPON_CHAINGUN
: result
:= (FAmmo
[A_BULLETS
] > 0);
3904 WEAPON_ROCKETLAUNCHER
: result
:= (FAmmo
[A_ROCKETS
] > 0);
3905 WEAPON_PLASMA
: result
:= (FAmmo
[A_CELLS
] > 0);
3906 WEAPON_BFG
: result
:= (FAmmo
[A_CELLS
] >= 40);
3907 WEAPON_FLAMETHROWER
: result
:= (FAmmo
[A_FUEL
] > 0);
3908 else result
:= (weapon
< length(FWeapon
));
3912 function TPlayer
.shouldSwitch (weapon
: Byte; hadWeapon
: Boolean): Boolean;
3915 if (weapon
> WP_LAST
+ 1) then
3920 if (FWeapSwitchMode
= 1) and not hadWeapon
then
3922 else if (FWeapSwitchMode
= 2) then
3923 result
:= (FWeapPreferences
[weapon
] > FWeapPreferences
[FCurrWeap
]);
3926 // return 255 for "no switch"
3927 function TPlayer
.getNextWeaponIndex (): Byte;
3930 wantThisWeapon
: array[0..64] of Boolean;
3931 wwc
: Integer = 0; //HACK!
3934 result
:= 255; // default result: "no switch"
3935 //e_LogWriteFln('FSWITCHTOEMPTY: %s', [FSwitchToEmpty], TMsgType.Notify);
3936 // had weapon cycling on previous frame? remove that flag
3937 if (FNextWeap
and $2000) <> 0 then
3939 FNextWeap
:= FNextWeap
and $1FFF;
3940 FNextWeapDelay
:= 0;
3942 // cycling has priority
3943 if (FNextWeap
and $C000) <> 0 then
3945 if (FNextWeap
and $8000) <> 0 then
3949 FNextWeap
:= FNextWeap
or $2000; // we need this
3950 if FNextWeapDelay
> 0 then
3951 exit
; // cooldown time
3953 for i
:= 0 to High(FWeapon
) do
3955 cwi
:= (cwi
+length(FWeapon
)+dir
) mod length(FWeapon
);
3956 if FWeapon
[cwi
] and maySwitch(cwi
) then
3958 //e_LogWriteFln(' SWITCH: cur=%d; new=%d %s %s', [FCurrWeap, cwi, FSwitchToEmpty, hasAmmoForWeapon(cwi)], TMsgType.Notify);
3959 result
:= Byte(cwi
);
3960 FNextWeapDelay
:= WEAPON_DELAY
;
3968 for i
:= 0 to High(wantThisWeapon
) do
3969 wantThisWeapon
[i
] := false;
3970 for i
:= 0 to High(FWeapon
) do
3971 if (FNextWeap
and (1 shl i
)) <> 0 then
3973 wantThisWeapon
[i
] := true;
3977 // exclude currently selected weapon from the set
3978 wantThisWeapon
[FCurrWeap
] := false;
3979 // slow down alterations a little
3982 //e_WriteLog(Format(' FNextWeap=%x; delay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
3983 // more than one weapon requested, assume "alteration" and check alteration delay
3984 if FNextWeapDelay
> 0 then
3990 // do not reset weapon queue, it will be done in `RealizeCurrentWeapon()`
3991 // but clear all counters if no weapon should be switched
3997 //e_WriteLog(Format('wwc=%d', [wwc]), MSG_WARNING);
3998 // try weapons in descending order
3999 for i
:= High(FWeapon
) downto 0 do
4001 if wantThisWeapon
[i
] and FWeapon
[i
] and ((wwc
= 1) or hasAmmoForWeapon(i
)) then
4006 FNextWeapDelay
:= WEAPON_DELAY
* 2; // anyway, 'cause why not
4007 //e_LogWriteFln('FOUND %s %s %s', [result, FSwitchToEmpty, hasAmmoForWeapon(i)], TMsgType.Notify);
4011 // no suitable weapon found, so reset the queue, to avoid accidental "queuing" of weapon w/o ammo
4015 procedure TPlayer
.RealizeCurrentWeapon();
4016 function switchAllowed (): Boolean;
4021 if FBFGFireCounter
<> -1 then
4023 if FTime
[T_SWITCH
] > gTime
then
4025 for i
:= WP_FIRST
to WP_LAST
do
4026 if FReloading
[i
] > 0 then
4034 //e_WriteLog(Format('***RealizeCurrentWeapon: FNextWeap=%x; FNextWeapDelay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
4035 //FNextWeap := FNextWeap and $1FFF;
4036 if FNextWeapDelay
> 0 then Dec(FNextWeapDelay
); // "alteration delay"
4038 if not switchAllowed
then
4040 //HACK for weapon cycling
4041 if (FNextWeap
and $E000) <> 0 then FNextWeap
:= 0;
4045 nw
:= getNextWeaponIndex();
4047 if nw
= 255 then exit
; // don't reset anything here
4048 if nw
> High(FWeapon
) then
4050 // don't forget to reset queue here!
4051 //e_WriteLog(' RealizeCurrentWeapon: WUTAFUUUU', MSG_WARNING);
4059 FTime
[T_SWITCH
] := gTime
+156;
4060 {$IFDEF ENABLE_SOUND}
4061 if FCurrWeap
= WEAPON_SAW
then FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
4063 FModel
.SetWeapon(FCurrWeap
);
4064 if g_Game_IsNet
then MH_SEND_PlayerStats(FUID
);
4068 procedure TPlayer
.NextWeapon();
4070 if g_Game_IsClient
then Exit
;
4074 procedure TPlayer
.PrevWeapon();
4076 if g_Game_IsClient
then Exit
;
4080 procedure TPlayer
.SetWeapon(W
: Byte);
4082 {$IFDEF ENABLE_SOUND}
4083 if FCurrWeap
<> W
then
4084 if W
= WEAPON_SAW
then
4085 FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
4089 FModel
.SetWeapon(CurrWeap
);
4093 function TPlayer
.PickItem(ItemType
: Byte; arespawn
: Boolean; var remove
: Boolean): Boolean;
4096 switchWeapon
: Byte = 255;
4097 hadWeapon
: Boolean = False;
4100 if g_Game_IsClient
then Exit
;
4102 // a = true - ìåñòî ñïàâíà ïðåäìåòà:
4103 a
:= (TGameOption
.WEAPONS_STAY
in gGameSettings
.Options
) and arespawn
;
4107 if (FHealth
< PLAYER_HP_SOFT
) or (FFireTime
> 0) then
4109 if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
4113 if gFlash
= 2 then Inc(FPickup
, 5);
4117 if (FHealth
< PLAYER_HP_SOFT
) or (FFireTime
> 0) then
4119 if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
4123 if gFlash
= 2 then Inc(FPickup
, 5);
4127 if FArmor
< PLAYER_AP_SOFT
then
4129 FArmor
:= PLAYER_AP_SOFT
;
4132 if gFlash
= 2 then Inc(FPickup
, 5);
4136 if FArmor
< PLAYER_AP_LIMIT
then
4138 FArmor
:= PLAYER_AP_LIMIT
;
4141 if gFlash
= 2 then Inc(FPickup
, 5);
4145 if (FHealth
< PLAYER_HP_LIMIT
) or (FFireTime
> 0) then
4147 if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
4151 if gFlash
= 2 then Inc(FPickup
, 5);
4155 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) or (FFireTime
> 0) then
4157 if FHealth
< PLAYER_HP_LIMIT
then
4158 FHealth
:= PLAYER_HP_LIMIT
;
4159 if FArmor
< PLAYER_AP_LIMIT
then
4160 FArmor
:= PLAYER_AP_LIMIT
;
4164 if gFlash
= 2 then Inc(FPickup
, 5);
4168 if (not FWeapon
[WEAPON_SAW
]) or ((not arespawn
) and (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
])) then
4170 hadWeapon
:= FWeapon
[WEAPON_SAW
];
4171 switchWeapon
:= WEAPON_SAW
;
4172 FWeapon
[WEAPON_SAW
] := True;
4174 if gFlash
= 2 then Inc(FPickup
, 5);
4175 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4178 ITEM_WEAPON_SHOTGUN1
:
4179 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN1
] then
4181 // Íóæíî, ÷òîáû íå âçÿòü âñå ïóëè ñðàçó:
4182 if a
and FWeapon
[WEAPON_SHOTGUN1
] then Exit
;
4183 hadWeapon
:= FWeapon
[WEAPON_SHOTGUN1
];
4184 switchWeapon
:= WEAPON_SHOTGUN1
;
4185 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4186 FWeapon
[WEAPON_SHOTGUN1
] := True;
4188 if gFlash
= 2 then Inc(FPickup
, 5);
4189 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4192 ITEM_WEAPON_SHOTGUN2
:
4193 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN2
] then
4195 if a
and FWeapon
[WEAPON_SHOTGUN2
] then Exit
;
4196 hadWeapon
:= FWeapon
[WEAPON_SHOTGUN2
];
4197 switchWeapon
:= WEAPON_SHOTGUN2
;
4198 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4199 FWeapon
[WEAPON_SHOTGUN2
] := True;
4201 if gFlash
= 2 then Inc(FPickup
, 5);
4202 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4205 ITEM_WEAPON_CHAINGUN
:
4206 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or not FWeapon
[WEAPON_CHAINGUN
] then
4208 if a
and FWeapon
[WEAPON_CHAINGUN
] then Exit
;
4209 hadWeapon
:= FWeapon
[WEAPON_CHAINGUN
];
4210 switchWeapon
:= WEAPON_CHAINGUN
;
4211 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
4212 FWeapon
[WEAPON_CHAINGUN
] := True;
4214 if gFlash
= 2 then Inc(FPickup
, 5);
4215 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4218 ITEM_WEAPON_ROCKETLAUNCHER
:
4219 if (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or not FWeapon
[WEAPON_ROCKETLAUNCHER
] then
4221 if a
and FWeapon
[WEAPON_ROCKETLAUNCHER
] then Exit
;
4222 switchWeapon
:= WEAPON_ROCKETLAUNCHER
;
4223 hadWeapon
:= FWeapon
[WEAPON_ROCKETLAUNCHER
];
4224 IncMax(FAmmo
[A_ROCKETS
], 2, FMaxAmmo
[A_ROCKETS
]);
4225 FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
4227 if gFlash
= 2 then Inc(FPickup
, 5);
4228 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4232 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_PLASMA
] then
4234 if a
and FWeapon
[WEAPON_PLASMA
] then Exit
;
4235 switchWeapon
:= WEAPON_PLASMA
;
4236 hadWeapon
:= FWeapon
[WEAPON_PLASMA
];
4237 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
4238 FWeapon
[WEAPON_PLASMA
] := True;
4240 if gFlash
= 2 then Inc(FPickup
, 5);
4241 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4245 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_BFG
] then
4247 if a
and FWeapon
[WEAPON_BFG
] then Exit
;
4248 switchWeapon
:= WEAPON_BFG
;
4249 hadWeapon
:= FWeapon
[WEAPON_BFG
];
4250 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
4251 FWeapon
[WEAPON_BFG
] := True;
4253 if gFlash
= 2 then Inc(FPickup
, 5);
4254 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4257 ITEM_WEAPON_SUPERCHAINGUN
:
4258 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SUPERCHAINGUN
] then
4260 if a
and FWeapon
[WEAPON_SUPERCHAINGUN
] then Exit
;
4261 switchWeapon
:= WEAPON_SUPERCHAINGUN
;
4262 hadWeapon
:= FWeapon
[WEAPON_SUPERCHAINGUN
];
4263 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4264 FWeapon
[WEAPON_SUPERCHAINGUN
] := True;
4266 if gFlash
= 2 then Inc(FPickup
, 5);
4267 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4270 ITEM_WEAPON_FLAMETHROWER
:
4271 if (FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
]) or not FWeapon
[WEAPON_FLAMETHROWER
] then
4273 if a
and FWeapon
[WEAPON_FLAMETHROWER
] then Exit
;
4274 switchWeapon
:= WEAPON_FLAMETHROWER
;
4275 hadWeapon
:= FWeapon
[WEAPON_FLAMETHROWER
];
4276 IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
4277 FWeapon
[WEAPON_FLAMETHROWER
] := True;
4279 if gFlash
= 2 then Inc(FPickup
, 5);
4280 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4284 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
4286 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
4289 if gFlash
= 2 then Inc(FPickup
, 5);
4292 ITEM_AMMO_BULLETS_BOX
:
4293 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
4295 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
4298 if gFlash
= 2 then Inc(FPickup
, 5);
4302 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
4304 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4307 if gFlash
= 2 then Inc(FPickup
, 5);
4310 ITEM_AMMO_SHELLS_BOX
:
4311 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
4313 IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
4316 if gFlash
= 2 then Inc(FPickup
, 5);
4320 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
4322 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
4325 if gFlash
= 2 then Inc(FPickup
, 5);
4328 ITEM_AMMO_ROCKET_BOX
:
4329 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
4331 IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
4334 if gFlash
= 2 then Inc(FPickup
, 5);
4338 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
4340 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
4343 if gFlash
= 2 then Inc(FPickup
, 5);
4347 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
4349 IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
4352 if gFlash
= 2 then Inc(FPickup
, 5);
4356 if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then
4358 IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
4361 if gFlash
= 2 then Inc(FPickup
, 5);
4365 if not(R_ITEM_BACKPACK
in FInventory
) or
4366 (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
4367 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
4368 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
4369 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or
4370 (FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
]) then
4372 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[1, A_BULLETS
];
4373 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[1, A_SHELLS
];
4374 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[1, A_ROCKETS
];
4375 FMaxAmmo
[A_CELLS
] := AmmoLimits
[1, A_CELLS
];
4376 FMaxAmmo
[A_FUEL
] := AmmoLimits
[1, A_FUEL
];
4378 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
4379 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
4380 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
4381 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4382 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
4383 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
4384 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
4385 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
4386 if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then
4387 IncMax(FAmmo
[A_FUEL
], 50, FMaxAmmo
[A_FUEL
]);
4389 FInventory
+= [R_ITEM_BACKPACK
];
4392 if gFlash
= 2 then FPickup
+= 5;
4396 if not(R_KEY_RED
in FInventory
) then
4398 FInventory
+= [R_KEY_RED
];
4400 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
4401 if gFlash
= 2 then Inc(FPickup
, 5);
4402 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
4406 if not(R_KEY_GREEN
in FInventory
) then
4408 FInventory
+= [R_KEY_GREEN
];
4410 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
4411 if gFlash
= 2 then Inc(FPickup
, 5);
4412 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
4416 if not(R_KEY_BLUE
in FInventory
) then
4418 FInventory
+= [R_KEY_BLUE
];
4420 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
4421 if gFlash
= 2 then Inc(FPickup
, 5);
4422 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
4426 if FPowerups
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
4428 FPowerups
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
4432 if gFlash
= 2 then Inc(FPickup
, 5);
4436 if FAir
< AIR_MAX
then
4441 if gFlash
= 2 then Inc(FPickup
, 5);
4446 if not (R_BERSERK
in FInventory
) then
4448 FInventory
+= [R_BERSERK
];
4449 if (FBFGFireCounter
= -1) then
4451 FCurrWeap
:= WEAPON_IRONFIST
;
4453 FModel
.SetWeapon(WEAPON_IRONFIST
);
4458 if gFlash
= 2 then Inc(FPickup
, 5);
4460 FBerserk
:= gTime
+30000;
4465 if (FHealth
< PLAYER_HP_SOFT
) or (FFireTime
> 0) then
4467 if FHealth
< PLAYER_HP_SOFT
then FHealth
:= PLAYER_HP_SOFT
;
4468 FBerserk
:= gTime
+30000;
4476 if FPowerups
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
4478 FPowerups
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
4482 if gFlash
= 2 then Inc(FPickup
, 5);
4486 if (FHealth
< PLAYER_HP_LIMIT
) or (FFireTime
> 0) then
4488 if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
4492 if gFlash
= 2 then Inc(FPickup
, 5);
4496 if FArmor
< PLAYER_AP_LIMIT
then
4498 IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
4501 if gFlash
= 2 then Inc(FPickup
, 5);
4505 if FJetFuel
< JET_MAX
then
4507 FJetFuel
:= JET_MAX
;
4510 if gFlash
= 2 then Inc(FPickup
, 5);
4514 if FPowerups
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
4516 FPowerups
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
4519 if gFlash
= 2 then Inc(FPickup
, 5);
4523 if (shouldSwitch(switchWeapon
, hadWeapon
)) then
4524 QueueWeaponSwitch(switchWeapon
);
4527 procedure TPlayer
.Touch();
4531 //FModel.PlaySound(MODELSOUND_PAIN, 1, FObj.X, FObj.Y);
4534 // Áðîñèòü ôëàã òîâàðèùó:
4535 if gGameSettings
.GameMode
= GM_CTF
then
4540 procedure TPlayer
.Push(vx
, vy
: Integer);
4542 if (not FPhysics
) and FGhost
then
4544 FObj
.Accel
.X
:= FObj
.Accel
.X
+ vx
;
4545 FObj
.Accel
.Y
:= FObj
.Accel
.Y
+ vy
;
4546 if g_Game_IsNet
and g_Game_IsServer
then
4547 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
4550 procedure TPlayer
.Reset(Force
: Boolean);
4556 FTime
[T_RESPAWN
] := 0;
4557 FTime
[T_FLAGCAP
] := 0;
4573 FSpectator
:= False;
4576 FSpectatePlayer
:= -1;
4577 FNoRespawn
:= False;
4579 FLives
:= gGameSettings
.MaxLives
;
4584 procedure TPlayer
.SoftReset();
4592 FBFGFireCounter
:= -1;
4600 SetAction(A_STAND
, True);
4603 function TPlayer
.GetRespawnPoint(): Byte;
4608 // Íà áóäóùåå: FSpawn - èãðîê óæå èãðàë è ïåðåðîæäàåòñÿ
4610 // Îäèíî÷íàÿ èãðà/êîîïåðàòèâ
4611 if gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
] then
4613 if Self
= gPlayer1
then
4615 // player 1 should try to spawn on the player 1 point
4616 if g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) > 0 then
4617 Exit(RESPAWNPOINT_PLAYER1
)
4618 else if g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) > 0 then
4619 Exit(RESPAWNPOINT_PLAYER2
);
4621 else if Self
= gPlayer2
then
4623 // player 2 should try to spawn on the player 2 point
4624 if g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) > 0 then
4625 Exit(RESPAWNPOINT_PLAYER2
)
4626 else if g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) > 0 then
4627 Exit(RESPAWNPOINT_PLAYER1
);
4631 // other players randomly pick either the first or the second point
4632 c
:= IfThen((Random(2) = 0), RESPAWNPOINT_PLAYER1
, RESPAWNPOINT_PLAYER2
);
4633 if g_Map_GetPointCount(c
) > 0 then
4635 // try the other one
4636 c
:= IfThen((c
= RESPAWNPOINT_PLAYER1
), RESPAWNPOINT_PLAYER2
, RESPAWNPOINT_PLAYER1
);
4637 if g_Map_GetPointCount(c
) > 0 then
4643 if gGameSettings
.GameMode
= GM_DM
then
4645 // try DM points first
4646 if g_Map_GetPointCount(RESPAWNPOINT_DM
) > 0 then
4647 Exit(RESPAWNPOINT_DM
);
4651 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
4653 // try team points first
4654 c
:= RESPAWNPOINT_DM
;
4655 if FTeam
= TEAM_RED
then
4656 c
:= RESPAWNPOINT_RED
4657 else if FTeam
= TEAM_BLUE
then
4658 c
:= RESPAWNPOINT_BLUE
;
4659 if g_Map_GetPointCount(c
) > 0 then
4663 // still haven't found a spawnpoint, try random shit
4664 Result
:= g_Map_GetRandomPointType();
4667 procedure TPlayer
.Respawn(Silent
: Boolean; Force
: Boolean = False);
4669 RespawnPoint
: TRespawnPoint
;
4677 FBFGFireCounter
:= -1;
4684 if not g_Game_IsServer
then
4688 FWantsInGame
:= True;
4689 FJustTeleported
:= True;
4692 FTime
[T_RESPAWN
] := 0;
4696 // if server changes MaxLives we gotta be ready
4697 if gGameSettings
.MaxLives
= 0 then FNoRespawn
:= False;
4699 // Åùå íåëüçÿ âîçðîäèòüñÿ:
4700 if FTime
[T_RESPAWN
] > gTime
then
4703 // Ïðîñðàë âñå æèçíè:
4706 if not FSpectator
then Spectate(True);
4707 FWantsInGame
:= True;
4711 if (gGameSettings
.GameType
<> GT_SINGLE
) and (gGameSettings
.GameMode
<> GM_COOP
) then
4712 begin // "Ñâîÿ èãðà"
4713 // Áåðñåðê íå ñîõðàíÿåòñÿ ìåæäó óðîâíÿìè:
4714 FInventory
-= [R_BERSERK
];
4716 else // "Îäèíî÷íàÿ èãðà"/"Êîîï"
4718 // Áåðñåðê è êëþ÷è íå ñîõðàíÿþòñÿ ìåæäó óðîâíÿìè:
4719 FInventory
-= [R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
, R_BERSERK
];
4722 // Ïîëó÷àåì òî÷êó ñïàóíà èãðîêà:
4723 c
:= GetRespawnPoint();
4728 // Âîñêðåøåíèå áåç îðóæèÿ:
4731 FHealth
:= Round(PLAYER_HP_SOFT
* (FHandicap
/ 100));
4737 for a
:= WP_FIRST
to WP_LAST
do
4739 FWeapon
[a
] := False;
4743 FWeapon
[WEAPON_PISTOL
] := True;
4744 FWeapon
[WEAPON_IRONFIST
] := True;
4745 FCurrWeap
:= WEAPON_PISTOL
;
4748 FModel
.SetWeapon(FCurrWeap
);
4750 for b
:= A_BULLETS
to A_HIGH
do
4753 FAmmo
[A_BULLETS
] := 50;
4755 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[0, A_BULLETS
];
4756 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[0, A_SHELLS
];
4757 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[0, A_SHELLS
];
4758 FMaxAmmo
[A_CELLS
] := AmmoLimits
[0, A_CELLS
];
4759 FMaxAmmo
[A_FUEL
] := AmmoLimits
[0, A_FUEL
];
4761 if (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
]) and
4762 (TGameOption
.DM_KEYS
in gGameSettings
.Options
)
4763 then FInventory
:= [R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
]
4764 else FInventory
:= [];
4767 // Ïîëó÷àåì êîîðäèíàòû òî÷êè âîçðîæäåíèÿ:
4768 if not g_Map_GetPoint(c
, RespawnPoint
) then
4770 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
4774 // Óñòàíîâêà êîîðäèíàò è ñáðîñ âñåõ ïàðàìåòðîâ:
4775 FObj
.X
:= RespawnPoint
.X
-PLAYER_RECT
.X
;
4776 FObj
.Y
:= RespawnPoint
.Y
-PLAYER_RECT
.Y
;
4777 FObj
.oldX
:= FObj
.X
; // don't interpolate after respawn
4778 FObj
.oldY
:= FObj
.Y
;
4784 FDirection
:= RespawnPoint
.Direction
;
4785 if FDirection
= TDirection
.D_LEFT
then
4790 SetAction(A_STAND
, True);
4791 FModel
.Direction
:= FDirection
;
4793 for a
:= Low(FTime
) to High(FTime
) do
4796 for a
:= Low(FPowerups
) to High(FPowerups
) do
4799 // Respawn invulnerability
4800 if (gGameSettings
.GameType
<> GT_SINGLE
) and (gGameSettings
.SpawnInvul
> 0) then
4802 FPowerups
[MR_INVUL
] := gTime
+ gGameSettings
.SpawnInvul
* 1000;
4803 FSpawnInvul
:= FPowerups
[MR_INVUL
];
4808 FCanJetpack
:= False;
4814 // Àíèìàöèÿ âîçðîæäåíèÿ:
4815 if (not gLoadGameMode
) and (not Silent
) then
4816 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
4818 Anim
:= TAnimation
.Create(ID
, False, 3);
4819 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4820 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4824 FSpectator
:= False;
4827 FSpectatePlayer
:= -1;
4830 if (gPlayer1
= nil) and (gSpectLatchPID1
= FUID
) then
4832 if (gPlayer2
= nil) and (gSpectLatchPID2
= FUID
) then
4835 if g_Game_IsNet
then
4837 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
4838 MH_SEND_PlayerStats(FUID
, NET_EVERYONE
);
4840 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4841 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32,
4846 procedure TPlayer
.Spectate(NoMove
: Boolean = False);
4849 Kill(K_EXTRAHARDKILL
, FUID
, HIT_SOME
)
4850 else if (not NoMove
) then
4852 GameX
:= gMapInfo
.Width
div 2;
4853 GameY
:= gMapInfo
.Height
div 2;
4862 FWantsInGame
:= False;
4868 if Self
= gPlayer1
then
4870 gSpectLatchPID1
:= FUID
;
4873 else if Self
= gPlayer2
then
4875 gSpectLatchPID2
:= FUID
;
4880 if g_Game_IsNet
then
4881 MH_SEND_PlayerStats(FUID
);
4884 procedure TPlayer
.SwitchNoClip
;
4888 FGhost
:= not FGhost
;
4889 FPhysics
:= not FGhost
;
4901 procedure TPlayer
.Run(Direction
: TDirection
);
4905 if MAX_RUNVEL
> 8 then
4909 if Direction
= TDirection
.D_LEFT
then
4911 if FObj
.Vel
.X
> -MAX_RUNVEL
then
4912 FObj
.Vel
.X
:= FObj
.Vel
.X
- (MAX_RUNVEL
shr 3);
4915 if FObj
.Vel
.X
< MAX_RUNVEL
then
4916 FObj
.Vel
.X
:= FObj
.Vel
.X
+ (MAX_RUNVEL
shr 3);
4918 // Âîçìîæíî, ïèíàåì êóñêè:
4919 if (FObj
.Vel
.X
<> 0) and (gGibs
<> nil) then
4921 b
:= Abs(FObj
.Vel
.X
);
4922 if b
> 1 then b
:= b
* (Random(8 div b
) + 1);
4923 for a
:= 0 to High(gGibs
) do
4925 if gGibs
[a
].alive
and
4926 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
+FObj
.Rect
.Height
-4,
4927 FObj
.Rect
.Width
, 8, @gGibs
[a
].Obj
) and (Random(3) = 0) then
4930 if FObj
.Vel
.X
< 0 then
4932 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)+120) // íàëåâî
4936 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)); // íàïðàâî
4938 gGibs
[a
].positionChanged(); // this updates spatial accelerators
4946 procedure TPlayer
.SeeDown();
4948 SetAction(A_SEEDOWN
);
4950 if FDirection
= TDirection
.D_LEFT
then FAngle
:= ANGLE_LEFTDOWN
else FAngle
:= ANGLE_RIGHTDOWN
;
4952 if FIncCam
> -120 then DecMin(FIncCam
, 5, -120);
4955 procedure TPlayer
.SeeUp();
4959 if FDirection
= TDirection
.D_LEFT
then FAngle
:= ANGLE_LEFTUP
else FAngle
:= ANGLE_RIGHTUP
;
4961 if FIncCam
< 120 then IncMax(FIncCam
, 5, 120);
4964 procedure TPlayer
.SetAction(Action
: Byte; Force
: Boolean = False);
4972 A_ATTACK
: Prior
:= 2;
4973 A_SEEUP
: Prior
:= 1;
4974 A_SEEDOWN
: Prior
:= 1;
4975 A_ATTACKUP
: Prior
:= 2;
4976 A_ATTACKDOWN
: Prior
:= 2;
4981 if (Prior
> FActionPrior
) or Force
then
4982 if not ((Prior
= 2) and (FCurrWeap
= WEAPON_SAW
)) then
4984 FActionPrior
:= Prior
;
4985 FActionAnim
:= Action
;
4986 FActionForce
:= Force
;
4987 FActionChanged
:= True;
4990 if Action
in [A_ATTACK
, A_ATTACKUP
, A_ATTACKDOWN
] then FModel
.SetFire(True);
4993 function TPlayer
.StayOnStep(XInc
, YInc
: Integer): Boolean;
4995 Result
:= not g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
-1,
4996 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False)
4997 and g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
,
4998 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False);
5001 function TPlayer
.TeleportTo(X
, Y
: Integer; silent
: Boolean; dir
: Byte): Boolean;
5008 if g_CollideLevel(X
, Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
) then
5010 {$IFDEF ENABLE_SOUND}
5011 g_Sound_PlayExAt('SOUND_GAME_NOTELEPORT', FObj
.X
, FObj
.Y
);
5013 if g_Game_IsServer
and g_Game_IsNet
then
5014 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_GAME_NOTELEPORT');
5018 FJustTeleported
:= True;
5023 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
5025 Anim
:= TAnimation
.Create(ID
, False, 3);
5028 {$IFDEF ENABLE_SOUND}
5029 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', FObj
.X
, FObj
.Y
);
5031 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
5032 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
5033 if g_Game_IsServer
and g_Game_IsNet
then
5034 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
5035 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 1,
5039 FObj
.X
:= X
-PLAYER_RECT
.X
;
5040 FObj
.Y
:= Y
-PLAYER_RECT
.Y
;
5041 FObj
.oldX
:= FObj
.X
; // don't interpolate after respawn
5042 FObj
.oldY
:= FObj
.Y
;
5043 if FAlive
and FGhost
then
5049 if not g_Game_IsNet
then
5053 SetDirection(TDirection
.D_LEFT
);
5059 SetDirection(TDirection
.D_RIGHT
);
5065 if FDirection
= TDirection
.D_RIGHT
then
5067 SetDirection(TDirection
.D_LEFT
);
5072 SetDirection(TDirection
.D_RIGHT
);
5078 if not silent
and (Anim
<> nil) then
5080 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
5081 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
5084 if g_Game_IsServer
and g_Game_IsNet
then
5085 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
5086 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 0,
5093 function nonz(a
: Single): Single;
5100 function TPlayer
.refreshCorpse(): Boolean;
5106 if FAlive
or FSpectator
then
5109 for i
:= 0 to High(gCorpses
) do
5110 if gCorpses
[i
] <> nil then
5111 if gCorpses
[i
].FPlayerUID
= FUID
then
5119 function TPlayer
.getCameraObj(): TObj
;
5121 if (not FAlive
) and (not FSpectator
) and
5122 (Low(gCorpses
) <= FCorpse
) and (High(gCorpses
) >= FCorpse
) and
5123 (gCorpses
[FCorpse
] <> nil) and (gCorpses
[FCorpse
].FPlayerUID
= FUID
) then
5125 gCorpses
[FCorpse
].FObj
.slopeUpLeft
:= FObj
.slopeUpLeft
;
5126 Result
:= gCorpses
[FCorpse
].FObj
;
5134 procedure TPlayer
.PreUpdate();
5136 FSlopeOld
:= FObj
.slopeUpLeft
;
5137 FIncCamOld
:= FIncCam
;
5138 FObj
.oldX
:= FObj
.X
;
5139 FObj
.oldY
:= FObj
.Y
;
5142 procedure TPlayer
.Update();
5145 i
, ii
, wx
, wy
, xd
, yd
, k
: Integer;
5146 blockmon
, headwater
, dospawn
: Boolean;
5152 NetServer
:= g_Game_IsNet
and g_Game_IsServer
;
5153 AnyServer
:= g_Game_IsServer
;
5155 if g_Game_IsClient
and (NetInterpLevel
> 0) then
5156 DoLerp(NetInterpLevel
+ 1)
5162 if (FClientID
>= 0) and (NetClients
[FClientID
].Peer
<> nil) then
5164 FPing
:= NetClients
[FClientID
].Peer
^.lastRoundTripTime
;
5165 if NetClients
[FClientID
].Peer
^.packetsSent
> 0 then
5166 FLoss
:= Round(100*NetClients
[FClientID
].Peer
^.packetsLost
/NetClients
[FClientID
].Peer
^.packetsSent
)
5175 if FAlive
and (FPunchAnim
<> nil) then
5176 FPunchAnim
.Update();
5178 if FAlive
and (gFly
or FJetpack
) then
5181 if FDirection
= TDirection
.D_LEFT
then
5186 if FAlive
and (not FGhost
) then
5188 if FKeys
[KEY_UP
].Pressed
then
5190 if FKeys
[KEY_DOWN
].Pressed
then
5194 if (not (FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_DOWN
].Pressed
)) and
5197 i
:= g_basic
.Sign(FIncCam
);
5198 FIncCam
:= Abs(FIncCam
);
5199 DecMin(FIncCam
, 5, 0);
5200 FIncCam
:= FIncCam
*i
;
5203 if gTime
mod (GAME_TICK
*2) <> 0 then
5205 if (FObj
.Vel
.X
= 0) and FAlive
then
5207 if FKeys
[KEY_LEFT
].Pressed
then
5208 Run(TDirection
.D_LEFT
);
5209 if FKeys
[KEY_RIGHT
].Pressed
then
5210 Run(TDirection
.D_RIGHT
);
5215 g_Obj_Move(@FObj
, True, True, True);
5216 positionChanged(); // this updates spatial accelerators
5222 FActionChanged
:= False;
5226 // Let alive player do some actions
5227 if FKeys
[KEY_LEFT
].Pressed
then Run(TDirection
.D_LEFT
);
5228 if FKeys
[KEY_RIGHT
].Pressed
then Run(TDirection
.D_RIGHT
);
5229 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then Fire()
5235 if NetServer
then MH_SEND_PlayerStats(FUID
);
5238 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Use();
5239 if FKeys
[KEY_JUMP
].Pressed
then Jump()
5242 if AnyServer
and FJetpack
then
5246 if NetServer
then MH_SEND_PlayerStats(FUID
);
5248 FCanJetpack
:= True;
5255 for k
:= Low(FKeys
) to KEY_CHAT
-1 do
5257 if FKeys
[k
].Pressed
then
5265 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
5268 if (FTime
[T_RESPAWN
] <= gTime
) and
5269 gGameOn
and (not FAlive
) then
5271 if (g_Player_GetCount() > 1) then
5275 gExit
:= EXIT_RESTART
;
5280 // Dead spectator actions
5283 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Fire();
5284 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then
5288 if (FSpectatePlayer
>= High(gPlayers
)) then
5289 FSpectatePlayer
:= -1
5293 for I
:= FSpectatePlayer
+ 1 to High(gPlayers
) do
5294 if gPlayers
[I
] <> nil then
5295 if gPlayers
[I
].alive
then
5296 if gPlayers
[I
].UID
<> FUID
then
5298 FSpectatePlayer
:= I
;
5303 if not SetSpect
then FSpectatePlayer
:= -1;
5314 if FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_JUMP
].Pressed
then
5316 FYTo
:= FObj
.Y
- 32;
5317 FSpectatePlayer
:= -1;
5319 if FKeys
[KEY_DOWN
].Pressed
then
5321 FYTo
:= FObj
.Y
+ 32;
5322 FSpectatePlayer
:= -1;
5324 if FKeys
[KEY_LEFT
].Pressed
then
5326 FXTo
:= FObj
.X
- 32;
5327 FSpectatePlayer
:= -1;
5329 if FKeys
[KEY_RIGHT
].Pressed
then
5331 FXTo
:= FObj
.X
+ 32;
5332 FSpectatePlayer
:= -1;
5335 if (FXTo
< -64) then
5337 else if (FXTo
> gMapInfo
.Width
+ 32) then
5338 FXTo
:= gMapInfo
.Width
+ 32;
5339 if (FYTo
< -72) then
5341 else if (FYTo
> gMapInfo
.Height
+ 32) then
5342 FYTo
:= gMapInfo
.Height
+ 32;
5347 g_Obj_Move(@FObj
, True, True, True);
5348 positionChanged(); // this updates spatial accelerators
5355 if (FSpectatePlayer
<= High(gPlayers
)) and (FSpectatePlayer
>= 0) then
5356 if gPlayers
[FSpectatePlayer
] <> nil then
5357 if gPlayers
[FSpectatePlayer
].alive
then
5359 FXTo
:= gPlayers
[FSpectatePlayer
].GameX
;
5360 FYTo
:= gPlayers
[FSpectatePlayer
].GameY
;
5364 blockmon
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
, FObj
.Y
+PLAYER_HEADRECT
.Y
,
5365 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
5366 PANEL_BLOCKMON
, True);
5367 headwater
:= HeadInLiquid(0, 0);
5369 // Ñîïðîòèâëåíèå âîçäóõà:
5370 if (not FAlive
) or not (FKeys
[KEY_LEFT
].Pressed
or FKeys
[KEY_RIGHT
].Pressed
) then
5371 if FObj
.Vel
.X
<> 0 then
5372 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
5374 if (FLastHit
= HIT_TRAP
) and (FPain
> 90) then FPain
:= 90;
5375 DecMin(FPain
, 5, 0);
5376 DecMin(FPickup
, 1, 0);
5378 if FAlive
and (FObj
.Y
> Integer(gMapInfo
.Height
)+128) and AnyServer
then
5380 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
5381 FPowerups
[MR_SUIT
] := 0;
5382 FPowerups
[MR_INVUL
] := 0;
5383 FPowerups
[MR_INVIS
] := 0;
5384 Kill(K_FALLKILL
, 0, HIT_FALL
);
5391 {$IFDEF ENABLE_SOUND}
5392 if FCurrWeap
= WEAPON_SAW
then
5393 if not (FSawSound
.IsPlaying() or FSawSoundHit
.IsPlaying() or
5394 FSawSoundSelect
.IsPlaying()) then
5395 FSawSoundIdle
.PlayAt(FObj
.X
, FObj
.Y
);
5398 if (not FJetSoundFly
.IsPlaying()) and (not FJetSoundOn
.IsPlaying()) and
5399 (not FJetSoundOff
.IsPlaying()) then
5401 FJetSoundFly
.SetPosition(0);
5402 FJetSoundFly
.PlayAt(FObj
.X
, FObj
.Y
);
5406 for b
:= WP_FIRST
to WP_LAST
do
5407 if FReloading
[b
] > 0 then
5409 then FReloading
[b
] := 0
5410 else FReloading
[b
] -= 1;
5412 if FShellTimer
> -1 then
5413 if FShellTimer
= 0 then
5415 if FShellType
= SHELL_SHELL
then
5416 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5417 GameVelX
, GameVelY
-2, SHELL_SHELL
)
5418 else if FShellType
= SHELL_DBLSHELL
then
5420 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5421 GameVelX
+1, GameVelY
-2, SHELL_SHELL
);
5422 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5423 GameVelX
-1, GameVelY
-2, SHELL_SHELL
);
5426 end else Dec(FShellTimer
);
5428 if (FBFGFireCounter
> -1) then
5429 if FBFGFireCounter
= 0 then
5433 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
5434 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
5435 xd
:= wx
+IfThen(FDirection
= TDirection
.D_LEFT
, -30, 30);
5436 yd
:= wy
+firediry();
5437 ProjID
:= g_Weapon_bfgshot(wx
, wy
, xd
, yd
, FUID
);
5438 if NetServer
then MH_SEND_PlayerFire(FUID
, WEAPON_BFG
, wx
, wy
, xd
, yd
, ProjID
);
5440 0, 180: SetAction(A_ATTACK
);
5441 ANGLE_LEFTDOWN
, ANGLE_RIGHTDOWN
: SetAction(A_ATTACKDOWN
);
5442 ANGLE_LEFTUP
, ANGLE_RIGHTUP
: SetAction(A_ATTACKUP
);
5446 FReloading
[WEAPON_BFG
] := WEAPON_RELOAD
[WEAPON_BFG
];
5447 FBFGFireCounter
:= -1;
5450 then FBFGFireCounter
:= 0
5451 else FBFGFireCounter
-= 1;
5453 if (FPowerups
[MR_SUIT
] < gTime
) and AnyServer
then
5455 b
:= g_GetAcidHit(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
);
5457 if (b
> 0) and (gTime
mod (15*GAME_TICK
) = 0) then Damage(b
, 0, 0, 0, HIT_ACID
);
5460 if (headwater
or blockmon
) then
5466 if AnyServer
then Damage(10, 0, 0, 0, HIT_WATER
);
5469 else if (FAir
mod 31 = 0) and not blockmon
then
5470 g_Game_Effect_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
5471 FObj
.Y
+PLAYER_RECT
.Y
-4, 5+Random(6), 8, 4);
5472 end else if FAir
< AIR_DEF
then
5475 if FFireTime
> 0 then
5477 if BodyInLiquid(0, 0) then
5482 else if FPowerups
[MR_SUIT
] >= gTime
then
5484 if FPowerups
[MR_SUIT
] = gTime
then
5491 if FFirePainTime
<= 0 then
5493 if g_Game_IsServer
then
5494 Damage(2, FFireAttacker
, 0, 0, HIT_FLAME
);
5495 FFirePainTime
:= 12 - FFireTime
div 12;
5497 FFirePainTime
:= FFirePainTime
- 1;
5498 FFireTime
:= FFireTime
- 1;
5499 {$IFDEF ENABLE_SOUND}
5500 if ((FFireTime
mod 33) = 0) and (FPowerups
[MR_INVUL
] < gTime
) then
5501 FModel
.PlaySound(MODELSOUND_PAIN
, 1, FObj
.X
, FObj
.Y
);
5503 if (FFireTime
= 0) and g_Game_IsNet
and g_Game_IsServer
then
5504 MH_SEND_PlayerStats(FUID
);
5508 if FDamageBuffer
> 0 then
5510 if FDamageBuffer
>= 9 then
5514 if FDamageBuffer
< 30 then i
:= 9
5515 else if FDamageBuffer
< 100 then i
:= 18
5519 ii
:= Round(FDamageBuffer
*FHealth
/ nonz(FArmor
*(3/4)+FHealth
));
5520 FArmor
:= FArmor
-(FDamageBuffer
-ii
);
5521 FHealth
:= FHealth
-ii
;
5524 FHealth
:= FHealth
+FArmor
;
5529 if FHealth
<= 0 then
5530 if FHealth
> -30 then Kill(K_SIMPLEKILL
, FLastSpawnerUID
, FLastHit
)
5531 else if FHealth
> -50 then Kill(K_HARDKILL
, FLastSpawnerUID
, FLastHit
)
5532 else Kill(K_EXTRAHARDKILL
, FLastSpawnerUID
, FLastHit
);
5534 {$IFDEF ENABLE_SOUND}
5535 if FAlive
and ((FLastHit
<> HIT_FLAME
) or (FFireTime
<= 0)) then
5537 if FDamageBuffer
<= 20 then FModel
.PlaySound(MODELSOUND_PAIN
, 1, FObj
.X
, FObj
.Y
)
5538 else if FDamageBuffer
<= 55 then FModel
.PlaySound(MODELSOUND_PAIN
, 2, FObj
.X
, FObj
.Y
)
5539 else if FDamageBuffer
<= 120 then FModel
.PlaySound(MODELSOUND_PAIN
, 3, FObj
.X
, FObj
.Y
)
5540 else FModel
.PlaySound(MODELSOUND_PAIN
, 4, FObj
.X
, FObj
.Y
);
5548 end; // if FAlive then ...
5550 if (FActionAnim
= A_PAIN
) and (FModel
.Animation
<> A_PAIN
) then
5552 FModel
.ChangeAnimation(FActionAnim
, FActionForce
);
5553 FModel
.GetCurrentAnimation
.MinLength
:= i
;
5554 FModel
.GetCurrentAnimationMask
.MinLength
:= i
;
5555 end else FModel
.ChangeAnimation(FActionAnim
, FActionForce
and (FModel
.Animation
<> A_STAND
));
5557 if (FModel
.GetCurrentAnimation
.Played
or ((not FActionChanged
) and (FModel
.Animation
= A_WALK
)))
5558 then SetAction(A_STAND
, True);
5560 if not ((FModel
.Animation
= A_WALK
) and (Abs(FObj
.Vel
.X
) < 4) and not FModel
.Fire
) then FModel
.Update
;
5562 for b
:= Low(FKeys
) to High(FKeys
) do
5563 if FKeys
[b
].Time
= 0 then FKeys
[b
].Pressed
:= False else Dec(FKeys
[b
].Time
);
5567 procedure TPlayer
.getMapBox (out x
, y
, w
, h
: Integer); inline;
5569 x
:= FObj
.X
+PLAYER_RECT
.X
;
5570 y
:= FObj
.Y
+PLAYER_RECT
.Y
;
5571 w
:= PLAYER_RECT
.Width
;
5572 h
:= PLAYER_RECT
.Height
;
5576 procedure TPlayer
.moveBy (dx
, dy
: Integer); inline;
5578 if (dx
<> 0) or (dy
<> 0) then
5587 function TPlayer
.Collide(X
, Y
: Integer; Width
, Height
: Word): Boolean;
5589 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
5590 FObj
.Y
+PLAYER_RECT
.Y
,
5597 function TPlayer
.Collide(Panel
: TPanel
): Boolean;
5599 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
5600 FObj
.Y
+PLAYER_RECT
.Y
,
5604 Panel
.Width
, Panel
.Height
);
5607 function TPlayer
.Collide(X
, Y
: Integer): Boolean;
5609 X
:= X
-FObj
.X
-PLAYER_RECT
.X
;
5610 Y
:= Y
-FObj
.Y
-PLAYER_RECT
.Y
;
5611 Result
:= (x
>= 0) and (x
<= PLAYER_RECT
.Width
) and
5612 (y
>= 0) and (y
<= PLAYER_RECT
.Height
);
5615 function g_Player_ExistingName(Name
: string): Boolean;
5621 if gPlayers
= nil then Exit
;
5623 for a
:= 0 to High(gPlayers
) do
5624 if gPlayers
[a
] <> nil then
5625 if LowerCase(Name
) = LowerCase(gPlayers
[a
].FName
) then
5632 procedure TPlayer
.SetDirection(Direction
: TDirection
);
5636 d
:= FModel
.Direction
;
5638 FModel
.Direction
:= Direction
;
5639 if d
<> Direction
then FModel
.ChangeAnimation(FModel
.Animation
, True);
5641 FDirection
:= Direction
;
5644 function TPlayer
.GetKeys(): Byte;
5648 if R_KEY_RED
in FInventory
then Result
:= Result
or KEY_RED
;
5649 if R_KEY_GREEN
in FInventory
then Result
:= Result
or KEY_GREEN
;
5650 if R_KEY_BLUE
in FInventory
then Result
:= Result
or KEY_BLUE
;
5652 if FTeam
= TEAM_RED
then Result
:= Result
or KEY_REDTEAM
;
5653 if FTeam
= TEAM_BLUE
then Result
:= Result
or KEY_BLUETEAM
;
5656 procedure TPlayer
.Use();
5660 if FTime
[T_USE
] > gTime
then Exit
;
5662 g_Triggers_PressR(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
,
5663 PLAYER_RECT
.Height
, FUID
, ACTIVATE_PLAYERPRESS
);
5665 for a
:= 0 to High(gPlayers
) do
5666 if (gPlayers
[a
] <> nil) and (gPlayers
[a
] <> Self
) and
5667 gPlayers
[a
].alive
and SameTeam(FUID
, gPlayers
[a
].FUID
) and
5668 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
5669 FObj
.Rect
.Width
, FObj
.Rect
.Height
, @gPlayers
[a
].FObj
) then
5671 gPlayers
[a
].Touch();
5672 if g_Game_IsNet
and g_Game_IsServer
then
5673 MH_SEND_GameEvent(NET_EV_PLAYER_TOUCH
, gPlayers
[a
].FUID
);
5676 FTime
[T_USE
] := gTime
+120;
5679 procedure TPlayer
.NetFire(Wpn
: Byte; X
, Y
, AX
, AY
: Integer; WID
: Integer);
5682 visible
: Boolean = True;
5683 WX
, WY
, XD
, YD
: Integer;
5695 if R_BERSERK
in FInventory
then
5697 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
5698 locobj
.X
:= FObj
.X
+FObj
.Rect
.X
;
5699 locobj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
5702 locobj
.rect
.Width
:= 39;
5703 locobj
.rect
.Height
:= 52;
5704 locobj
.Vel
.X
:= (xd
-wx
) div 2;
5705 locobj
.Vel
.Y
:= (yd
-wy
) div 2;
5706 locobj
.Accel
.X
:= xd
-wx
;
5707 locobj
.Accel
.y
:= yd
-wy
;
5709 if g_Weapon_Hit(@locobj
, 50, FUID
, HIT_SOME
) <> 0 then
5711 {$IFDEF ENABLE_SOUND}
5712 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
5717 {$IFDEF ENABLE_SOUND}
5718 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
5722 if (gFlash
= 1) and (FPain
< 50) then
5723 FPain
:= min(FPain
+ 25, 50);
5725 g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
5730 {$IFDEF ENABLE_SOUND}
5731 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
5732 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
5734 FSawSoundSelect
.Stop();
5736 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
5738 else if not FSawSoundHit
.IsPlaying() then
5740 FSawSoundSelect
.Stop();
5741 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
5744 g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
5745 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
);
5751 {$IFDEF ENABLE_SOUND}
5752 g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', GameX
, Gamey
);
5754 FFireAngle
:= FAngle
;
5755 g_Player_CreateShell(
5756 GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5757 GameVelX
, GameVelY
-2,
5764 {$IFDEF ENABLE_SOUND}
5765 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
5767 FFireAngle
:= FAngle
;
5769 FShellType
:= SHELL_SHELL
;
5774 {$IFDEF ENABLE_SOUND}
5775 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN2', Gamex
, Gamey
);
5777 FFireAngle
:= FAngle
;
5779 FShellType
:= SHELL_DBLSHELL
;
5784 {$IFDEF ENABLE_SOUND}
5785 g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', Gamex
, Gamey
);
5787 FFireAngle
:= FAngle
;
5788 g_Player_CreateShell(
5789 GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5790 GameVelX
, GameVelY
-2,
5795 WEAPON_ROCKETLAUNCHER
:
5797 g_Weapon_Rocket(wx
, wy
, xd
, yd
, FUID
, WID
);
5798 FFireAngle
:= FAngle
;
5803 g_Weapon_Plasma(wx
, wy
, xd
, yd
, FUID
, WID
);
5804 FFireAngle
:= FAngle
;
5809 g_Weapon_BFGShot(wx
, wy
, xd
, yd
, FUID
, WID
);
5810 FFireAngle
:= FAngle
;
5813 WEAPON_SUPERCHAINGUN
:
5815 {$IFDEF ENABLE_SOUND}
5816 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
5818 FFireAngle
:= FAngle
;
5819 g_Player_CreateShell(
5820 GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5821 GameVelX
, GameVelY
-2,
5826 WEAPON_FLAMETHROWER
:
5828 g_Weapon_flame(wx
, wy
, xd
, yd
, FUID
, WID
);
5830 FFireAngle
:= FAngle
;
5834 if not visible
then Exit
;
5837 0, 180: SetAction(A_ATTACK
);
5838 ANGLE_LEFTDOWN
, ANGLE_RIGHTDOWN
: SetAction(A_ATTACKDOWN
);
5839 ANGLE_LEFTUP
, ANGLE_RIGHTUP
: SetAction(A_ATTACKUP
);
5843 procedure TPlayer
.DoLerp(Level
: Integer = 2);
5845 if FObj
.X
<> FXTo
then FObj
.X
:= Lerp(FObj
.X
, FXTo
, Level
);
5846 if FObj
.Y
<> FYTo
then FObj
.Y
:= Lerp(FObj
.Y
, FYTo
, Level
);
5849 procedure TPlayer
.SetLerp(XTo
, YTo
: Integer);
5855 if FJustTeleported
or (NetInterpLevel
< 1) then
5859 if FJustTeleported
then
5861 FObj
.oldX
:= FObj
.X
;
5862 FObj
.oldY
:= FObj
.Y
;
5867 AX
:= Abs(FXTo
- FObj
.X
);
5868 AY
:= Abs(FYTo
- FObj
.Y
);
5869 if (AX
> 32) or (AX
<= NetInterpLevel
) then
5871 if (AY
> 32) or (AY
<= NetInterpLevel
) then
5876 function TPlayer
.FullInLift(XInc
, YInc
: Integer): Integer;
5878 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5879 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5880 PANEL_LIFTUP
, False) then Result
:= -1
5882 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5883 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5884 PANEL_LIFTDOWN
, False) then Result
:= 1
5888 function TPlayer
.GetFlag(Flag
: Byte): Boolean;
5892 {$IFDEF ENABLE_SOUND}
5898 if Flag
= FLAG_NONE
then
5901 if not g_Game_IsServer
then Exit
;
5903 // Ïðèíåñ ÷óæîé ôëàã íà ñâîþ áàçó:
5904 if (Flag
= FTeam
) and (gFlags
[Flag
].State
= FLAG_STATE_NORMAL
) and (FFlag
<> FLAG_NONE
) then
5907 then s
:= _lc
[I_PLAYER_FLAG_RED
]
5908 else s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5910 evtype
:= FLAG_STATE_SCORED
;
5912 ts
:= Format('%.4d', [gFlags
[FFlag
].CaptureTime
]);
5913 Insert('.', ts
, Length(ts
) + 1 - 3);
5914 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_CAPTURE
], [FName
, s
, ts
]), True);
5916 g_Map_ResetFlag(FFlag
);
5917 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_CAPTURE
], [AnsiUpperCase(s
)]), 144);
5919 {$IFDEF ENABLE_SOUND}
5920 if ((Self
= gPlayer1
) or (Self
= gPlayer2
)
5921 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= FTeam
))
5922 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= FTeam
)))
5926 if not sound_cap_flag
[a
].IsPlaying() then
5927 sound_cap_flag
[a
].Play();
5930 gTeamStat
[FTeam
].Score
+= 1;
5933 if g_Game_IsNet
then
5935 MH_SEND_FlagEvent(evtype
, FFlag
, FUID
, False);
5939 gFlags
[FFlag
].CaptureTime
:= 0;
5944 // Ïîäîáðàë ñâîé ôëàã - âåðíóë åãî íà áàçó:
5945 if (Flag
= FTeam
) and (gFlags
[Flag
].State
= FLAG_STATE_DROPPED
) then
5948 then s
:= _lc
[I_PLAYER_FLAG_RED
]
5949 else s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5951 evtype
:= FLAG_STATE_RETURNED
;
5952 gFlags
[Flag
].CaptureTime
:= 0;
5954 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_RETURN
], [FName
, s
]), True);
5956 g_Map_ResetFlag(Flag
);
5957 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
5959 {$IFDEF ENABLE_SOUND}
5960 if ((Self
= gPlayer1
) or (Self
= gPlayer2
)
5961 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= FTeam
))
5962 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= FTeam
)))
5966 if not sound_ret_flag
[a
].IsPlaying() then
5967 sound_ret_flag
[a
].Play();
5971 if g_Game_IsNet
then
5973 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5979 // Ïîäîáðàë ÷óæîé ôëàã:
5980 if (Flag
<> FTeam
) and (FTime
[T_FLAGCAP
] <= gTime
) then
5985 then s
:= _lc
[I_PLAYER_FLAG_RED
]
5986 else s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5988 evtype
:= FLAG_STATE_CAPTURED
;
5990 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_GET
], [FName
, s
]), True);
5992 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_GET
], [AnsiUpperCase(s
)]), 144);
5994 gFlags
[Flag
].State
:= FLAG_STATE_CAPTURED
;
5996 {$IFDEF ENABLE_SOUND}
5997 if ((Self
= gPlayer1
) or (Self
= gPlayer2
)
5998 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= FTeam
))
5999 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= FTeam
)))
6003 if not sound_get_flag
[a
].IsPlaying() then
6004 sound_get_flag
[a
].Play();
6008 if g_Game_IsNet
then
6010 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
6016 procedure TPlayer
.SetFlag(Flag
: Byte);
6019 if FModel
<> nil then
6020 FModel
.SetFlag(FFlag
);
6023 function TPlayer
.TryDropFlag(): Boolean;
6025 if (TGameOption
.ALLOW_DROP_FLAG
in gGameSettings
.Options
)
6026 then Result
:= DropFlag(False, TGameOption
.THROW_FLAG
in gGameSettings
.Options
)
6027 else Result
:= False;
6030 function TPlayer
.DropFlag(Silent
: Boolean; DoThrow
: Boolean): Boolean;
6037 if (not g_Game_IsServer
) or (FFlag
= FLAG_NONE
) then
6039 FTime
[T_FLAGCAP
] := gTime
+ 2000;
6040 with gFlags
[FFlag
] do
6044 Direction
:= FDirection
;
6045 State
:= FLAG_STATE_DROPPED
;
6049 xv
:= FObj
.Vel
.X
+ IfThen(Direction
= TDirection
.D_RIGHT
, 10, -10);
6050 yv
:= FObj
.Vel
.Y
- 2;
6054 xv
:= (FObj
.Vel
.X
div 2);
6055 yv
:= (FObj
.Vel
.Y
div 2) - 2;
6057 g_Obj_Push(@Obj
, xv
, yv
);
6059 positionChanged(); // this updates spatial accelerators
6062 then s
:= _lc
[I_PLAYER_FLAG_RED
]
6063 else s
:= _lc
[I_PLAYER_FLAG_BLUE
];
6065 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_DROP
], [FName
, s
]), True);
6066 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_DROP
], [AnsiUpperCase(s
)]), 144);
6068 {$IFDEF ENABLE_SOUND}
6069 if ((Self
= gPlayer1
) or (Self
= gPlayer2
)
6070 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= FTeam
))
6071 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= FTeam
)))
6075 if (not Silent
) and (not sound_lost_flag
[a
].IsPlaying()) then
6076 sound_lost_flag
[a
].Play();
6079 if g_Game_IsNet
then
6080 MH_SEND_FlagEvent(FLAG_STATE_DROPPED
, Flag
, FUID
, False);
6086 procedure TPlayer
.GetSecret();
6088 if (self
= gPlayer1
) or (self
= gPlayer2
) then
6090 g_Console_Add(Format(_lc
[I_PLAYER_SECRET
], [FName
]), True);
6091 {$IFDEF ENABLE_SOUND}
6092 g_Sound_PlayEx('SOUND_GAME_SECRET');
6098 procedure TPlayer
.PressKey(Key
: Byte; Time
: Word);
6100 Assert(Key
<= High(FKeys
));
6102 FKeys
[Key
].Pressed
:= True;
6103 FKeys
[Key
].Time
:= Time
;
6106 function TPlayer
.IsKeyPressed(K
: Byte): Boolean;
6108 Result
:= FKeys
[K
].Pressed
;
6111 procedure TPlayer
.ReleaseKeys();
6115 for a
:= Low(FKeys
) to High(FKeys
) do
6117 FKeys
[a
].Pressed
:= False;
6122 procedure TPlayer
.OnDamage(Angle
: SmallInt
);
6126 function TPlayer
.firediry(): Integer;
6128 if FKeys
[KEY_UP
].Pressed
then Result
:= -42
6129 else if FKeys
[KEY_DOWN
].Pressed
then Result
:= 19
6133 procedure TPlayer
.PreserveState();
6136 SavedState
: TPlayerSavedState
;
6138 SavedState
.Health
:= FHealth
;
6139 SavedState
.Armor
:= FArmor
;
6140 SavedState
.Air
:= FAir
;
6141 SavedState
.JetFuel
:= FJetFuel
;
6142 SavedState
.CurrWeap
:= FCurrWeap
;
6143 SavedState
.NextWeap
:= FNextWeap
;
6144 SavedState
.NextWeapDelay
:= FNextWeapDelay
;
6145 for i
:= Low(FWeapon
) to High(FWeapon
) do
6146 SavedState
.Weapon
[i
] := FWeapon
[i
];
6147 for i
:= Low(FAmmo
) to High(FAmmo
) do
6148 SavedState
.Ammo
[i
] := FAmmo
[i
];
6149 for i
:= Low(FMaxAmmo
) to High(FMaxAmmo
) do
6150 SavedState
.MaxAmmo
[i
] := FMaxAmmo
[i
];
6151 SavedState
.Inventory
:= FInventory
- [R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
];
6153 FSavedStateNum
:= -1;
6154 for i
:= Low(SavedStates
) to High(SavedStates
) do
6155 if not SavedStates
[i
].Used
then
6157 FSavedStateNum
:= i
;
6160 if FSavedStateNum
< 0 then
6162 SetLength(SavedStates
, Length(SavedStates
) + 1);
6163 FSavedStateNum
:= High(SavedStates
);
6166 SavedState
.Used
:= True;
6167 SavedStates
[FSavedStateNum
] := SavedState
;
6170 procedure TPlayer
.RestoreState();
6173 SavedState
: TPlayerSavedState
;
6175 if(FSavedStateNum
< 0) or (FSavedStateNum
> High(SavedStates
)) then
6178 SavedState
:= SavedStates
[FSavedStateNum
];
6179 SavedStates
[FSavedStateNum
].Used
:= False;
6180 FSavedStateNum
:= -1;
6182 FHealth
:= SavedState
.Health
;
6183 FArmor
:= SavedState
.Armor
;
6184 FAir
:= SavedState
.Air
;
6185 FJetFuel
:= SavedState
.JetFuel
;
6186 FCurrWeap
:= SavedState
.CurrWeap
;
6187 FNextWeap
:= SavedState
.NextWeap
;
6188 FNextWeapDelay
:= SavedState
.NextWeapDelay
;
6189 for i
:= Low(FWeapon
) to High(FWeapon
) do
6190 FWeapon
[i
] := SavedState
.Weapon
[i
];
6191 for i
:= Low(FAmmo
) to High(FAmmo
) do
6192 FAmmo
[i
] := SavedState
.Ammo
[i
];
6193 for i
:= Low(FMaxAmmo
) to High(FMaxAmmo
) do
6194 FMaxAmmo
[i
] := SavedState
.MaxAmmo
[i
];
6195 FInventory
:= SavedState
.Inventory
;
6197 if gGameSettings
.GameType
= GT_SERVER
then
6198 MH_SEND_PlayerStats(FUID
);
6201 procedure TPlayer
.SaveState (st
: TStream
);
6206 utils
.writeSign(st
, 'PLYR');
6207 st
.WriteByte(PLR_SAVE_VERSION
); // version
6209 st
.WriteBool(FIamBot
); // Áîò èëè ÷åëîâåê
6210 st
.WriteWordLE(FUID
); // UID èãðîêà
6211 utils
.writeStr(st
, FName
); // Èìÿ èãðîêà
6212 st
.WriteByte(FTeam
); // Êîìàíäà
6213 st
.WriteBool(FAlive
); // Æèâ ëè
6214 st
.WriteBool(FNoRespawn
); // Èçðàñõîäîâàë ëè âñå æèçíè
6217 if FDirection
= TDirection
.D_LEFT
6218 then st
.WriteByte(1)
6219 else st
.WriteByte(2); // D_RIGHT
6221 st
.WriteInt32LE(FHealth
); // Çäîðîâüå
6222 st
.WriteInt32LE(FHandicap
); // Êîýôôèöèåíò èíâàëèäíîñòè
6223 st
.WriteByte(FLives
); // Æèçíè
6224 st
.WriteInt32LE(FArmor
); // Áðîíÿ
6225 st
.WriteInt32LE(FAir
); // Çàïàñ âîçäóõà
6226 st
.WriteInt32LE(FJetFuel
); // Çàïàñ ãîðþ÷åãî
6227 st
.WriteInt32LE(FPain
); // Áîëü
6228 st
.WriteInt32LE(FKills
); // Óáèë
6229 st
.WriteInt32LE(FMonsterKills
); // Óáèë ìîíñòðîâ
6230 st
.WriteInt32LE(FFrags
); // Ôðàãîâ
6231 st
.WriteByte(FFragCombo
); // Ôðàãîâ ïîäðÿä
6232 st
.WriteDWordLE(FLastFrag
); // Âðåìÿ ïîñëåäíåãî ôðàãà
6233 st
.WriteInt32LE(FDeath
); // Ñìåðòåé
6234 st
.WriteByte(FFlag
); // Êàêîé ôëàã íåñåò
6235 st
.WriteInt32LE(FSecrets
); // Íàøåë ñåêðåòîâ
6236 st
.WriteByte(FCurrWeap
); // Òåêóùåå îðóæèå
6237 st
.WriteWordLE(FNextWeap
); // Æåëàåìîå îðóæèå
6238 st
.WriteByte(FNextWeapDelay
); // ...è ïàóçà
6239 st
.WriteInt16LE(FBFGFireCounter
); // Âðåìÿ çàðÿäêè BFG
6240 st
.WriteInt32LE(FDamageBuffer
); // Áóôåð óðîíà
6241 st
.WriteWordLE(FLastSpawnerUID
); // Ïîñëåäíèé óäàðèâøèé
6242 st
.WriteByte(FLastHit
); // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà
6243 Obj_SaveState(st
, @FObj
); // Îáúåêò èãðîêà
6245 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ
6246 for i
:= A_BULLETS
to A_HIGH
do
6247 st
.WriteWordLE(FAmmo
[i
]);
6249 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ
6250 for i
:= A_BULLETS
to A_HIGH
do
6251 st
.WriteWordLE(FMaxAmmo
[i
]);
6254 for i
:= WP_FIRST
to WP_LAST
do
6255 st
.WriteBool(FWeapon
[i
]);
6257 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ
6258 for i
:= WP_FIRST
to WP_LAST
do
6259 st
.WriteWordLE(FReloading
[i
]);
6261 st
.WriteBool(R_ITEM_BACKPACK
in FInventory
); // Íàëè÷èå ðþêçàêà
6262 st
.WriteBool(R_KEY_RED
in FInventory
); // Íàëè÷èå êðàñíîãî êëþ÷à
6263 st
.WriteBool(R_KEY_GREEN
in FInventory
); // Íàëè÷èå çåëåíîãî êëþ÷à
6264 st
.WriteBool(R_KEY_BLUE
in FInventory
); // Íàëè÷èå ñèíåãî êëþ÷à
6265 st
.WriteBool(R_BERSERK
in FInventory
); // Íàëè÷èå áåðñåðêà
6267 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ
6268 for i
:= MR_SUIT
to MR_MAX
do
6269 st
.WriteDWordLE(FPowerups
[i
]);
6271 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà
6272 for i
:= T_RESPAWN
to T_FLAGCAP
do
6273 st
.WriteDWordLE(FTime
[i
]);
6276 utils
.writeStr(st
, FModel
.Name
);
6278 st
.WriteByte(FColor
.R
);
6279 st
.WriteByte(FColor
.G
);
6280 st
.WriteByte(FColor
.B
);
6284 procedure TPlayer
.LoadState (st
: TStream
);
6292 if not utils
.checkSign(st
, 'PLYR') then
6293 Raise XStreamError
.Create('invalid player signature');
6294 if st
.ReadByte() <> PLR_SAVE_VERSION
then
6295 Raise XStreamError
.Create('invalid player version');
6297 FIamBot
:= st
.ReadBool(); // Áîò èëè ÷åëîâåê:
6298 FUID
:= st
.ReadWordLE(); // UID èãðîêà
6301 str
:= utils
.readStr(st
);
6302 if (self
<> gPlayer1
) and (self
<> gPlayer2
) then
6305 FTeam
:= st
.ReadByte(); // Êîìàíäà
6306 FAlive
:= st
.ReadBool(); // Æèâ ëè
6307 FNoRespawn
:= st
.ReadBool(); // Èçðàñõîäîâàë ëè âñå æèçíè
6310 if st
.ReadByte() = 1
6311 then FDirection
:= TDirection
.D_LEFT
6312 else FDirection
:= TDirection
.D_RIGHT
; // b = 2
6314 FHealth
:= st
.ReadInt32LE(); // Çäîðîâüå
6315 FHandicap
:= st
.ReadInt32LE(); // Êîýôôèöèåíò èíâàëèäíîñòè
6316 FLives
:= st
.ReadByte(); // Æèçíè
6317 FArmor
:= st
.ReadInt32LE(); // Áðîíÿ
6318 FAir
:= st
.ReadInt32LE(); // Çàïàñ âîçäóõà
6319 FJetFuel
:= st
.ReadInt32LE(); // Çàïàñ ãîðþ÷åãî
6320 FPain
:= st
.ReadInt32LE(); // Áîëü
6321 FKills
:= st
.ReadInt32LE(); // Óáèë
6322 FMonsterKills
:= st
.ReadInt32LE(); // Óáèë ìîíñòðîâ
6323 FFrags
:= st
.ReadInt32LE(); // Ôðàãîâ
6324 FFragCombo
:= st
.ReadByte(); // Ôðàãîâ ïîäðÿä
6325 FLastFrag
:= st
.ReadDWordLE(); // Âðåìÿ ïîñëåäíåãî ôðàãà
6326 FDeath
:= st
.ReadInt32LE(); // Ñìåðòåé
6327 FFlag
:= st
.ReadByte(); // Êàêîé ôëàã íåñåò
6328 FSecrets
:= st
.ReadInt32LE(); // Íàøåë ñåêðåòîâ
6329 FCurrWeap
:= st
.ReadByte(); // Òåêóùåå îðóæèå
6330 FNextWeap
:= st
.ReadWordLE(); // Æåëàåìîå îðóæèå
6331 FNextWeapDelay
:= st
.ReadByte(); // ...è ïàóçà
6332 FBFGFireCounter
:= st
.ReadInt16LE(); // Âðåìÿ çàðÿäêè BFG
6333 FDamageBuffer
:= st
.ReadInt32LE(); // Áóôåð óðîíà
6334 FLastSpawnerUID
:= st
.ReadWordLE(); // Ïîñëåäíèé óäàðèâøèé
6335 FLastHit
:= st
.ReadByte(); // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà
6336 Obj_LoadState(@FObj
, st
); // Îáúåêò èãðîêà
6338 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ
6339 for i
:= A_BULLETS
to A_HIGH
do
6340 FAmmo
[i
] := st
.ReadWordLE();
6342 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ
6343 for i
:= A_BULLETS
to A_HIGH
do
6344 FMaxAmmo
[i
] := st
.ReadWordLE();
6347 for i
:= WP_FIRST
to WP_LAST
do
6348 FWeapon
[i
] := st
.ReadBool();
6350 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ
6351 for i
:= WP_FIRST
to WP_LAST
do
6352 FReloading
[i
] := st
.ReadWordLE();
6354 if st
.ReadBool() then FInventory
+= [R_ITEM_BACKPACK
]; // Íàëè÷èå ðþêçàêà
6355 if st
.ReadBool() then FInventory
+= [R_KEY_RED
]; // Íàëè÷èå êðàñíîãî êëþ÷à
6356 if st
.ReadBool() then FInventory
+= [R_KEY_GREEN
]; // Íàëè÷èå çåëåíîãî êëþ÷à
6357 if st
.ReadBool() then FInventory
+= [R_KEY_BLUE
]; // Íàëè÷èå ñèíåãî êëþ÷à
6358 if st
.ReadBool() then FInventory
+= [R_BERSERK
]; // Íàëè÷èå áåðñåðêà
6360 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ
6361 for i
:= MR_SUIT
to MR_MAX
do
6362 FPowerups
[i
] := st
.ReadDWordLE();
6364 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà
6365 for i
:= T_RESPAWN
to T_FLAGCAP
do
6366 FTime
[i
] := st
.ReadDWordLE();
6369 str
:= utils
.readStr(st
);
6371 FColor
.R
:= st
.ReadByte();
6372 FColor
.G
:= st
.ReadByte();
6373 FColor
.B
:= st
.ReadByte();
6375 // Îáíîâëÿåì ìîäåëü èãðîêà
6376 if self
= gPlayer1
then
6378 str
:= gPlayer1Settings
.Model
;
6379 FColor
:= gPlayer1Settings
.Color
;
6381 else if self
= gPlayer2
then
6383 str
:= gPlayer2Settings
.Model
;
6384 FColor
:= gPlayer2Settings
.Color
;
6388 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]
6389 then FModel
.Color
:= TEAMCOLOR
[FTeam
]
6390 else FModel
.Color
:= FColor
;
6394 procedure TPlayer
.TankRamboCheats(Health
: Boolean);
6400 FHealth
:= PLAYER_HP_LIMIT
;
6401 FArmor
:= PLAYER_AP_LIMIT
;
6405 for a
:= WP_FIRST
to WP_LAST
do FWeapon
[a
] := True;
6406 for a
:= A_BULLETS
to A_HIGH
do FAmmo
[a
] := 30000;
6407 FInventory
+= [R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
];
6410 procedure TPlayer
.RestoreHealthArmor();
6412 FHealth
:= PLAYER_HP_LIMIT
;
6413 FArmor
:= PLAYER_AP_LIMIT
;
6416 procedure TPlayer
.FragCombo();
6420 if (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) or g_Game_IsClient
then
6422 if gTime
- FLastFrag
< FRAG_COMBO_TIME
then
6424 if FFragCombo
< 5 then
6426 Param
:= FUID
or (FFragCombo
shl 16);
6427 if (FComboEvnt
>= Low(gDelayedEvents
)) and
6428 (FComboEvnt
<= High(gDelayedEvents
)) and
6429 gDelayedEvents
[FComboEvnt
].Pending
and
6430 (gDelayedEvents
[FComboEvnt
].DEType
= DE_KILLCOMBO
) and
6431 (gDelayedEvents
[FComboEvnt
].DENum
and $FFFF = FUID
) then
6433 gDelayedEvents
[FComboEvnt
].Time
:= gTime
+ 500;
6434 gDelayedEvents
[FComboEvnt
].DENum
:= Param
;
6437 FComboEvnt
:= g_Game_DelayEvent(DE_KILLCOMBO
, 500, Param
);
6445 procedure TPlayer
.GiveItem(ItemType
: Byte);
6449 if FPowerups
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
6450 FPowerups
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
6453 if FAir
< AIR_MAX
then FAir
:= AIR_MAX
;
6457 if not (R_BERSERK
in FInventory
) then
6459 FInventory
+= [R_BERSERK
];
6460 if FBFGFireCounter
< 1 then
6462 FCurrWeap
:= WEAPON_IRONFIST
;
6464 FModel
.SetWeapon(WEAPON_IRONFIST
);
6466 if gFlash
<> 0 then FPain
+= 100;
6467 FBerserk
:= gTime
+30000;
6469 if FHealth
< PLAYER_HP_SOFT
then
6471 FHealth
:= PLAYER_HP_SOFT
;
6472 FBerserk
:= gTime
+30000;
6477 if FPowerups
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
6479 FPowerups
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
6484 if FPowerups
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
6485 FPowerups
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
6488 if FJetFuel
< JET_MAX
then FJetFuel
:= JET_MAX
;
6490 ITEM_MEDKIT_SMALL
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
6491 ITEM_MEDKIT_LARGE
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
6493 ITEM_ARMOR_GREEN
: if FArmor
< PLAYER_AP_SOFT
then FArmor
:= PLAYER_AP_SOFT
;
6494 ITEM_ARMOR_BLUE
: if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
6496 ITEM_SPHERE_BLUE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
6498 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) then
6500 if FHealth
< PLAYER_HP_LIMIT
then FHealth
:= PLAYER_HP_LIMIT
;
6501 if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
6504 ITEM_WEAPON_SAW
: FWeapon
[WEAPON_SAW
] := True;
6505 ITEM_WEAPON_SHOTGUN1
: FWeapon
[WEAPON_SHOTGUN1
] := True;
6506 ITEM_WEAPON_SHOTGUN2
: FWeapon
[WEAPON_SHOTGUN2
] := True;
6507 ITEM_WEAPON_CHAINGUN
: FWeapon
[WEAPON_CHAINGUN
] := True;
6508 ITEM_WEAPON_ROCKETLAUNCHER
: FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
6509 ITEM_WEAPON_PLASMA
: FWeapon
[WEAPON_PLASMA
] := True;
6510 ITEM_WEAPON_BFG
: FWeapon
[WEAPON_BFG
] := True;
6511 ITEM_WEAPON_SUPERCHAINGUN
: FWeapon
[WEAPON_SUPERCHAINGUN
] := True;
6512 ITEM_WEAPON_FLAMETHROWER
: FWeapon
[WEAPON_FLAMETHROWER
] := True;
6514 ITEM_AMMO_BULLETS
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
6515 ITEM_AMMO_BULLETS_BOX
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
6516 ITEM_AMMO_SHELLS
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
6517 ITEM_AMMO_SHELLS_BOX
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
6518 ITEM_AMMO_ROCKET
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
6519 ITEM_AMMO_ROCKET_BOX
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
6520 ITEM_AMMO_CELL
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
6521 ITEM_AMMO_CELL_BIG
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
6522 ITEM_AMMO_FUELCAN
: if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
6525 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
6526 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
6527 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
6528 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or
6529 (FMaxAmmo
[A_FUEL
] < AmmoLimits
[1, A_FUEL
]) then
6531 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[1, A_BULLETS
];
6532 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[1, A_SHELLS
];
6533 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[1, A_ROCKETS
];
6534 FMaxAmmo
[A_CELLS
] := AmmoLimits
[1, A_CELLS
];
6535 FMaxAmmo
[A_FUEL
] := AmmoLimits
[1, A_FUEL
];
6537 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
6538 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
6539 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
6540 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
6542 FInventory
+= [R_ITEM_BACKPACK
];
6545 ITEM_KEY_RED
: if not (R_KEY_RED
in FInventory
) then FInventory
+= [R_KEY_RED
];
6546 ITEM_KEY_GREEN
: if not (R_KEY_GREEN
in FInventory
) then FInventory
+= [R_KEY_GREEN
];
6547 ITEM_KEY_BLUE
: if not (R_KEY_BLUE
in FInventory
) then FInventory
+= [R_KEY_BLUE
];
6549 ITEM_BOTTLE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
6550 ITEM_HELMET
: if FArmor
< PLAYER_AP_LIMIT
then IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
6555 if g_Game_IsNet
and g_Game_IsServer
then
6556 MH_SEND_PlayerStats(FUID
);
6559 procedure TPlayer
.FlySmoke(Times
: DWORD
= 1);
6564 if (Random(5) = 1) and (Times
= 1) then
6567 if BodyInLiquid(0, 0) then
6569 g_Game_Effect_Bubbles(Obj
.X
+Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2)+Random(3)-1,
6570 Obj
.Y
+Obj
.Rect
.Height
+8, 1, 8, 4);
6574 if g_Frames_Get(id
, 'FRAMES_SMOKE') then
6576 for i
:= 1 to Times
do
6578 Anim
:= TAnimation
.Create(id
, False, 3);
6580 g_GFX_OnceAnim(Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(Anim
.Width
div 2),
6581 Obj
.Y
+Obj
.Rect
.Height
-4+Random(8+Times
*2), Anim
, ONCEANIM_SMOKE
);
6587 procedure TPlayer
.OnFireFlame(Times
: DWORD
= 1);
6592 if (Random(10) = 1) and (Times
= 1) then
6595 if g_Frames_Get(id
, 'FRAMES_FLAME') then
6597 for i
:= 1 to Times
do
6599 Anim
:= TAnimation
.Create(id
, False, 3);
6601 g_GFX_OnceAnim(Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(Anim
.Width
div 2),
6602 Obj
.Y
+8+Random(8+Times
*2), Anim
, ONCEANIM_SMOKE
);
6608 {$IFDEF ENABLE_SOUND}
6609 procedure TPlayer
.PauseSounds(Enable
: Boolean);
6611 FSawSound
.Pause(Enable
);
6612 FSawSoundIdle
.Pause(Enable
);
6613 FSawSoundHit
.Pause(Enable
);
6614 FSawSoundSelect
.Pause(Enable
);
6615 FFlameSoundOn
.Pause(Enable
);
6616 FFlameSoundOff
.Pause(Enable
);
6617 FFlameSoundWork
.Pause(Enable
);
6618 FJetSoundFly
.Pause(Enable
);
6619 FJetSoundOn
.Pause(Enable
);
6620 FJetSoundOff
.Pause(Enable
);
6626 constructor TCorpse
.Create(X
, Y
: Integer; ModelName
: String; aMess
: Boolean);
6631 FObj
.Rect
:= PLAYER_CORPSERECT
;
6632 FModelName
:= ModelName
;
6637 FState
:= CORPSE_STATE_MESS
;
6638 g_PlayerModel_GetAnim(ModelName
, A_DIE2
, FAnimation
, FAnimationMask
);
6642 FState
:= CORPSE_STATE_NORMAL
;
6643 g_PlayerModel_GetAnim(ModelName
, A_DIE1
, FAnimation
, FAnimationMask
);
6647 destructor TCorpse
.Destroy();
6650 FAnimationMask
.Free();
6655 function TCorpse
.ObjPtr (): PObj
; inline;
6660 procedure TCorpse
.positionChanged (); inline;
6664 procedure TCorpse
.moveBy (dx
, dy
: Integer); inline;
6666 if (dx
<> 0) or (dy
<> 0) then
6675 procedure TCorpse
.getMapBox (out x
, y
, w
, h
: Integer); inline;
6677 x
:= FObj
.X
+PLAYER_CORPSERECT
.X
;
6678 y
:= FObj
.Y
+PLAYER_CORPSERECT
.Y
;
6679 w
:= PLAYER_CORPSERECT
.Width
;
6680 h
:= PLAYER_CORPSERECT
.Height
;
6684 procedure TCorpse
.Damage(Value
: Word; SpawnerUID
: Word; vx
, vy
: Integer);
6689 if FState
= CORPSE_STATE_REMOVEME
then
6692 FDamage
:= FDamage
+ Value
;
6694 if FDamage
> 150 then
6696 if FAnimation
<> nil then
6701 FState
:= CORPSE_STATE_REMOVEME
;
6703 g_Player_CreateGibs(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
6704 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2),
6705 FModelName
, FColor
);
6707 {$IFDEF ENABLE_SOUND}
6708 // Çâóê ìÿñà îò òðóïà:
6709 pm
:= g_PlayerModel_Get(FModelName
);
6710 pm
.PlaySound(MODELSOUND_DIE
, 5, FObj
.X
, FObj
.Y
);
6715 if (gBodyKillEvent
<> -1)
6716 and gDelayedEvents
[gBodyKillEvent
].Pending
then
6717 gDelayedEvents
[gBodyKillEvent
].Pending
:= False;
6718 gBodyKillEvent
:= g_Game_DelayEvent(DE_BODYKILL
, 1050, SpawnerUID
);
6723 Blood
:= g_PlayerModel_GetBlood(FModelName
);
6724 FObj
.Vel
.X
:= FObj
.Vel
.X
+ vx
;
6725 FObj
.Vel
.Y
:= FObj
.Vel
.Y
+ vy
;
6726 g_GFX_Blood(FObj
.X
+PLAYER_CORPSERECT
.X
+(PLAYER_CORPSERECT
.Width
div 2),
6727 FObj
.Y
+PLAYER_CORPSERECT
.Y
+(PLAYER_CORPSERECT
.Height
div 2),
6728 Value
, vx
, vy
, 16, (PLAYER_CORPSERECT
.Height
*2) div 3,
6729 Blood
.R
, Blood
.G
, Blood
.B
, Blood
.Kind
);
6733 procedure TCorpse
.Draw();
6737 if FState
= CORPSE_STATE_REMOVEME
then
6740 FObj
.lerp(gLerpFactor
, fX
, fY
);
6742 if FAnimation
<> nil then
6743 FAnimation
.Draw(fX
, fY
, TMirrorType
.None
);
6745 if FAnimationMask
<> nil then
6748 FAnimationMask
.Draw(fX
, fY
, TMirrorType
.None
);
6755 procedure TCorpse
.Update();
6759 if FState
= CORPSE_STATE_REMOVEME
then
6762 FObj
.oldX
:= FObj
.X
;
6763 FObj
.oldY
:= FObj
.Y
;
6765 if gTime
mod (GAME_TICK
*2) <> 0 then
6767 g_Obj_Move(@FObj
, True, True, True);
6768 positionChanged(); // this updates spatial accelerators
6772 // Ñîïðîòèâëåíèå âîçäóõà äëÿ òðóïà:
6773 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
6775 st
:= g_Obj_Move(@FObj
, True, True, True);
6776 positionChanged(); // this updates spatial accelerators
6778 if WordBool(st
and MOVE_FALLOUT
) then
6780 FState
:= CORPSE_STATE_REMOVEME
;
6784 if FAnimation
<> nil then
6785 FAnimation
.Update();
6786 if FAnimationMask
<> nil then
6787 FAnimationMask
.Update();
6791 procedure TCorpse
.SaveState (st
: TStream
);
6798 utils
.writeSign(st
, 'CORP');
6801 st
.WriteByte(FState
); // Ñîñòîÿíèå
6802 st
.WriteByte(FDamage
); // Íàêîïëåííûé óðîí
6805 st
.WriteByte(FColor
.R
);
6806 st
.WriteByte(FColor
.G
);
6807 st
.WriteByte(FColor
.B
);
6810 Obj_SaveState(st
, @FObj
);
6811 st
.WriteWordLE(FPlayerUID
);
6814 anim
:= FAnimation
<> nil;
6816 // Åñëè åñòü - ñîõðàíÿåì
6817 if anim
then FAnimation
.SaveState(st
);
6819 // Åñòü ëè ìàñêà àíèìàöèè
6820 anim
:= FAnimationMask
<> nil;
6822 // Åñëè åñòü - ñîõðàíÿåì
6823 if anim
then FAnimationMask
.SaveState(st
);
6827 procedure TCorpse
.LoadState (st
: TStream
);
6834 if not utils
.checkSign(st
, 'CORP') then
6835 Raise XStreamError
.Create('invalid corpse signature');
6836 if st
.ReadByte() <> 0 then
6837 Raise XStreamError
.Create('invalid corpse version');
6839 FState
:= st
.ReadByte(); // Ñîñòîÿíèå
6840 FDamage
:= st
.ReadByte(); // Íàêîïëåííûé óðîí
6843 FColor
.R
:= st
.ReadByte();
6844 FColor
.G
:= st
.ReadByte();
6845 FColor
.B
:= st
.ReadByte();
6848 Obj_LoadState(@FObj
, st
);
6849 FPlayerUID
:= st
.ReadWordLE();
6852 anim
:= st
.ReadBool();
6853 // Åñëè åñòü - çàãðóæàåì
6856 Assert(FAnimation
<> nil, 'TCorpse.LoadState: no FAnimation');
6857 FAnimation
.LoadState(st
);
6860 // Åñòü ëè ìàñêà àíèìàöèè
6861 anim
:= st
.ReadBool();
6862 // Åñëè åñòü - çàãðóæàåì
6865 Assert(FAnimationMask
<> nil, 'TCorpse.LoadState: no FAnimationMask');
6866 FAnimationMask
.LoadState(st
);
6872 constructor TBot
.Create();
6879 FSpectator
:= False;
6886 for a
:= WP_FIRST
to WP_LAST
do
6888 FDifficult
.WeaponPrior
[a
] := WEAPON_PRIOR1
[a
];
6889 FDifficult
.CloseWeaponPrior
[a
] := WEAPON_PRIOR2
[a
];
6890 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
6894 destructor TBot
.Destroy();
6897 inherited Destroy();
6900 procedure TBot
.Draw();
6904 //if FTargetUID <> 0 then e_DrawLine(1, FObj.X, FObj.Y, g_Player_Get(FTargetUID).FObj.X,
6905 // g_Player_Get(FTargetUID).FObj.Y, 255, 0, 0);
6908 procedure TBot
.Respawn(Silent
: Boolean; Force
: Boolean = False);
6910 inherited Respawn(Silent
, Force
);
6913 FSelectedWeapon
:= FCurrWeap
;
6918 procedure TBot
.UpdateCombat();
6931 TTargetRecord
= array of TTarget
;
6933 function Compare(a
, b
: TTarget
): Integer;
6935 if a
.Line
and not b
.Line
then // A íà ëèíèè îãíÿ
6938 if not a
.Line
and b
.Line
then // B íà ëèíèè îãíÿ
6940 else // È A, è B íà ëèíèè èëè íå íà ëèíèè îãíÿ
6941 if (a
.Line
and b
.Line
) or ((not a
.Line
) and (not b
.Line
)) then
6943 if a
.Dist
> b
.Dist
then // B áëèæå
6945 else // A áëèæå èëè ðàâíîóäàëåííî ñ B
6948 else // Ñòðàííî -> A
6953 a
, x1
, y1
, x2
, y2
: Integer;
6954 targets
: TTargetRecord
;
6956 Target
, BestTarget
: TTarget
;
6957 firew
, fireh
: Integer;
6961 vsPlayer
, vsMonster
, ok
: Boolean;
6964 function monsUpdate (mon
: TMonster
): Boolean;
6966 result
:= false; // don't stop
6967 if mon
.alive
and (mon
.MonsterType
<> MONSTER_BARREL
) then
6969 if not TargetOnScreen(mon
.Obj
.X
+mon
.Obj
.Rect
.X
, mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
) then exit
;
6971 x2
:= mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2);
6972 y2
:= mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+(mon
.Obj
.Rect
.Height
div 2);
6974 // Åñëè ìîíñòð íà ýêðàíå è íå ïðèêðûò ñòåíîé
6975 if g_TraceVector(x1
, y1
, x2
, y2
) then
6977 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé
6978 SetLength(targets
, Length(targets
)+1);
6979 with targets
[High(targets
)] do
6986 Rect
:= mon
.Obj
.Rect
;
6987 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6988 Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6989 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6998 vsPlayer
:= TGameOption
.BOTS_VS_PLAYERS
in gGameSettings
.Options
;
6999 vsMonster
:= TGameOption
.BOTS_VS_MONSTERS
in gGameSettings
.Options
;
7001 // Åñëè òåêóùåå îðóæèå íå òî, ÷òî íóæíî, òî ìåíÿåì:
7002 if FCurrWeap
<> FSelectedWeapon
then
7005 // Åñëè íóæíî ñòðåëÿòü è íóæíîå îðóæèå, òî íàæàòü "Ñòðåëÿòü":
7006 if (GetAIFlag('NEEDFIRE') <> '') and (FCurrWeap
= FSelectedWeapon
) then
7008 RemoveAIFlag('NEEDFIRE');
7011 WEAPON_PLASMA
, WEAPON_SUPERCHAINGUN
, WEAPON_CHAINGUN
: PressKey(KEY_FIRE
, 20);
7012 WEAPON_SAW
, WEAPON_IRONFIST
, WEAPON_FLAMETHROWER
: PressKey(KEY_FIRE
, 40);
7013 else PressKey(KEY_FIRE
);
7017 // Êîîðäèíàòû ñòâîëà:
7018 x1
:= FObj
.X
+ WEAPONPOINT
[FDirection
].X
;
7019 y1
:= FObj
.Y
+ WEAPONPOINT
[FDirection
].Y
;
7021 Target
.UID
:= FTargetUID
;
7024 if Target
.UID
<> 0 then
7025 begin // Öåëü åñòü - íàñòðàèâàåì
7026 if (g_GetUIDType(Target
.UID
) = UID_PLAYER
) and
7029 tpla
:= g_Player_Get(Target
.UID
);
7033 if (@FObj
) <> nil then
7040 Target
.cX
:= Target
.X
+ PLAYER_RECT_CX
;
7041 Target
.cY
:= Target
.Y
+ PLAYER_RECT_CY
;
7042 Target
.Rect
:= PLAYER_RECT
;
7043 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
7044 Target
.Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
7045 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
7046 Target
.IsPlayer
:= True;
7050 if (g_GetUIDType(Target
.UID
) = UID_MONSTER
) and
7053 mon
:= g_Monsters_ByUID(Target
.UID
);
7056 Target
.X
:= mon
.Obj
.X
;
7057 Target
.Y
:= mon
.Obj
.Y
;
7059 Target
.cX
:= Target
.X
+ mon
.Obj
.Rect
.X
+ (mon
.Obj
.Rect
.Width
div 2);
7060 Target
.cY
:= Target
.Y
+ mon
.Obj
.Rect
.Y
+ (mon
.Obj
.Rect
.Height
div 2);
7061 Target
.Rect
:= mon
.Obj
.Rect
;
7062 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
7063 Target
.Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
7064 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
7065 Target
.IsPlayer
:= False;
7072 begin // Öåëè íåò - îáíóëÿåì
7077 Target
.Visible
:= False;
7078 Target
.Line
:= False;
7079 Target
.IsPlayer
:= False;
7084 // Åñëè öåëü íå âèäèìà èëè íå íà ëèíèè îãíÿ, òî èùåì âñå âîçìîæíûå öåëè:
7085 if (not Target
.Line
) or (not Target
.Visible
) then
7089 for a
:= 0 to High(gPlayers
) do
7090 if (gPlayers
[a
] <> nil) and (gPlayers
[a
].alive
) and
7091 (gPlayers
[a
].FUID
<> FUID
) and
7092 (not SameTeam(FUID
, gPlayers
[a
].FUID
)) and
7093 (not gPlayers
[a
].NoTarget
) and
7094 (gPlayers
[a
].FPowerups
[MR_INVIS
] < gTime
) then
7096 if not TargetOnScreen(gPlayers
[a
].FObj
.X
+ PLAYER_RECT
.X
,
7097 gPlayers
[a
].FObj
.Y
+ PLAYER_RECT
.Y
) then
7100 x2
:= gPlayers
[a
].FObj
.X
+ PLAYER_RECT_CX
;
7101 y2
:= gPlayers
[a
].FObj
.Y
+ PLAYER_RECT_CY
;
7103 // Åñëè èãðîê íà ýêðàíå è íå ïðèêðûò ñòåíîé:
7104 if g_TraceVector(x1
, y1
, x2
, y2
) then
7106 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé:
7107 SetLength(targets
, Length(targets
)+1);
7108 with targets
[High(targets
)] do
7110 UID
:= gPlayers
[a
].FUID
;
7111 X
:= gPlayers
[a
].FObj
.X
;
7112 Y
:= gPlayers
[a
].FObj
.Y
;
7115 Rect
:= PLAYER_RECT
;
7116 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
7117 Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
7118 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
7126 if vsMonster
then g_Mons_ForEach(monsUpdate
);
7129 // Åñëè åñòü âîçìîæíûå öåëè:
7130 // (Âûáèðàåì ëó÷øóþ, ìåíÿåì îðóæèå è áåæèì ê íåé/îò íåå)
7131 if targets
<> nil then
7133 // Âûáèðàåì íàèëó÷øóþ öåëü:
7134 BestTarget
:= targets
[0];
7135 if Length(targets
) > 1 then
7136 for a
:= 1 to High(targets
) do
7137 if Compare(BestTarget
, targets
[a
]) = 1 then
7138 BestTarget
:= targets
[a
];
7140 // Åñëè ëó÷øàÿ öåëü "âèäíåå" òåêóùåé, òî òåêóùàÿ := ëó÷øàÿ:
7141 if ((not Target
.Visible
) and BestTarget
.Visible
and (Target
.UID
<> BestTarget
.UID
)) or
7142 ((not Target
.Line
) and BestTarget
.Line
and BestTarget
.Visible
) then
7144 Target
:= BestTarget
;
7146 if (Healthy() = 3) or ((Healthy() = 2)) then
7147 begin // Åñëè çäîðîâû - äîãîíÿåì
7148 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
7149 SetAIFlag('GORIGHT', '1');
7150 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
7151 SetAIFlag('GOLEFT', '1');
7154 begin // Åñëè ïîáèòû - óáåãàåì
7155 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) then
7156 SetAIFlag('GORIGHT', '1');
7157 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
7158 SetAIFlag('GOLEFT', '1');
7161 // Âûáèðàåì îðóæèå íà îñíîâå ðàññòîÿíèÿ è ïðèîðèòåòîâ:
7162 SelectWeapon(Abs(x1
-Target
.cX
));
7167 // (Äîãîíÿåì/óáåãàåì, ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëè)
7168 // (Åñëè öåëü äàëåêî, òî õâàòèò ñëåäèòü çà íåé)
7169 if Target
.UID
<> 0 then
7171 if not TargetOnScreen(Target
.X
+ Target
.Rect
.X
,
7172 Target
.Y
+ Target
.Rect
.Y
) then
7173 begin // Öåëü ñáåæàëà ñ "ýêðàíà"
7174 if (Healthy() = 3) or ((Healthy() = 2)) then
7175 begin // Åñëè çäîðîâû - äîãîíÿåì
7176 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
7177 SetAIFlag('GORIGHT', '1');
7178 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
7179 SetAIFlag('GOLEFT', '1');
7182 begin // Åñëè ïîáèòû - çàáûâàåì î öåëè è óáåãàåì
7184 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) then
7185 SetAIFlag('GORIGHT', '1');
7186 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
7187 SetAIFlag('GOLEFT', '1');
7191 begin // Öåëü ïîêà íà "ýêðàíå"
7192 // Åñëè öåëü íå çàãîðîæåíà ñòåíîé, òî îòìå÷àåì, êîãäà åå âèäåëè:
7193 if g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
7194 FLastVisible
:= gTime
;
7195 // Åñëè ðàçíèöà âûñîò íå âåëèêà, òî äîãîíÿåì:
7196 if (Abs(FObj
.Y
-Target
.Y
) <= 128) then
7198 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
7199 SetAIFlag('GORIGHT', '1');
7200 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
7201 SetAIFlag('GOLEFT', '1');
7205 // Âûáèðàåì óãîë ââåðõ:
7206 if FDirection
= TDirection
.D_LEFT
then
7207 angle
:= ANGLE_LEFTUP
7209 angle
:= ANGLE_RIGHTUP
;
7211 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7212 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7214 // Åñëè ïðè óãëå ââåðõ ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
7215 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
7216 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128), //96
7217 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
7218 Target
.Rect
.Width
, Target
.Rect
.Height
) and
7219 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
7220 begin // òî íóæíî ñòðåëÿòü ââåðõ
7221 SetAIFlag('NEEDFIRE', '1');
7222 SetAIFlag('NEEDSEEUP', '1');
7225 // Âûáèðàåì óãîë âíèç:
7226 if FDirection
= TDirection
.D_LEFT
then
7227 angle
:= ANGLE_LEFTDOWN
7229 angle
:= ANGLE_RIGHTDOWN
;
7231 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7232 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7234 // Åñëè ïðè óãëå âíèç ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
7235 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
7236 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
7237 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
7238 Target
.Rect
.Width
, Target
.Rect
.Height
) and
7239 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
7240 begin // òî íóæíî ñòðåëÿòü âíèç
7241 SetAIFlag('NEEDFIRE', '1');
7242 SetAIFlag('NEEDSEEDOWN', '1');
7245 // Åñëè öåëü âèäíî è îíà íà òàêîé æå âûñîòå:
7246 if Target
.Visible
and
7247 (y1
+4 < Target
.Y
+Target
.Rect
.Y
+Target
.Rect
.Height
) and
7248 (y1
-4 > Target
.Y
+Target
.Rect
.Y
) then
7250 // Åñëè èäåì â ñòîðîíó öåëè, òî íàäî ñòðåëÿòü:
7251 if ((FDirection
= TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) or
7252 ((FDirection
= TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
7253 begin // òî íóæíî ñòðåëÿòü âïåðåä
7254 SetAIFlag('NEEDFIRE', '1');
7255 SetAIFlag('NEEDSEEDOWN', '');
7256 SetAIFlag('NEEDSEEUP', '');
7258 // Åñëè öåëü â ïðåäåëàõ "ýêðàíà" è ñëîæíîñòü ïîçâîëÿåò ïðûæêè ñáëèæåíèÿ:
7259 if Abs(FObj
.X
-Target
.X
) < Trunc(gPlayerScreenSize
.X
*0.75) then
7260 if GetRnd(FDifficult
.CloseJump
) then
7261 begin // òî åñëè ïîâåçåò - ïðûãàåì (îñîáåííî, åñëè áëèçêî)
7262 if Abs(FObj
.X
-Target
.X
) < 128 then
7266 if Random(a
) = 0 then
7267 SetAIFlag('NEEDJUMP', '1');
7271 // Åñëè öåëü âñå åùå åñòü:
7272 if Target
.UID
<> 0 then
7273 if gTime
-FLastVisible
> 2000 then // Åñëè âèäåëè äàâíî
7274 Target
.UID
:= 0 // òî çàáûòü öåëü
7275 else // Åñëè âèäåëè íåäàâíî
7276 begin // íî öåëü óáèëè
7277 if Target
.IsPlayer
then
7278 begin // Öåëü - èãðîê
7279 pla
:= g_Player_Get(Target
.UID
);
7280 if (pla
= nil) or (not pla
.alive
) or pla
.NoTarget
or
7281 (pla
.FPowerups
[MR_INVIS
] >= gTime
) then
7282 Target
.UID
:= 0; // òî çàáûòü öåëü
7285 begin // Öåëü - ìîíñòð
7286 mon
:= g_Monsters_ByUID(Target
.UID
);
7287 if (mon
= nil) or (not mon
.alive
) then
7288 Target
.UID
:= 0; // òî çàáûòü öåëü
7291 end; // if Target.UID <> 0
7293 FTargetUID
:= Target
.UID
;
7295 // Åñëè âîçìîæíûõ öåëåé íåò:
7296 // (Àòàêà ÷åãî-íèáóäü ñëåâà èëè ñïðàâà)
7297 if targets
= nil then
7298 if GetAIFlag('ATTACKLEFT') <> '' then
7299 begin // Åñëè íóæíî àòàêîâàòü íàëåâî
7300 RemoveAIFlag('ATTACKLEFT');
7302 SetAIFlag('NEEDJUMP', '1');
7304 if RunDirection() = TDirection
.D_RIGHT
then
7305 begin // Èäåì íå â òó ñòîðîíó
7306 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
7307 begin // Åñëè çäîðîâû, òî, âîçìîæíî, ñòðåëÿåì áåæèì âëåâî è ñòðåëÿåì
7308 SetAIFlag('NEEDFIRE', '1');
7309 SetAIFlag('GOLEFT', '1');
7313 begin // Èäåì â íóæíóþ ñòîðîíó
7314 if GetRnd(FDifficult
.InvisFire
) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
7315 SetAIFlag('NEEDFIRE', '1');
7316 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
7317 SetAIFlag('GORIGHT', '1');
7321 if GetAIFlag('ATTACKRIGHT') <> '' then
7322 begin // Åñëè íóæíî àòàêîâàòü íàïðàâî
7323 RemoveAIFlag('ATTACKRIGHT');
7325 SetAIFlag('NEEDJUMP', '1');
7327 if RunDirection() = TDirection
.D_LEFT
then
7328 begin // Èäåì íå â òó ñòîðîíó
7329 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
7330 begin // Åñëè çäîðîâû, òî, âîçìîæíî, áåæèì âïðàâî è ñòðåëÿåì
7331 SetAIFlag('NEEDFIRE', '1');
7332 SetAIFlag('GORIGHT', '1');
7337 if GetRnd(FDifficult
.InvisFire
) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
7338 SetAIFlag('NEEDFIRE', '1');
7339 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
7340 SetAIFlag('GOLEFT', '1');
7344 //HACK! (does it belongs there?)
7345 RealizeCurrentWeapon();
7347 // Åñëè åñòü âîçìîæíûå öåëè:
7348 // (Ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëÿì)
7349 if (targets
<> nil) and (GetAIFlag('NEEDFIRE') <> '') then
7350 for a
:= 0 to High(targets
) do
7352 // Åñëè ìîæåì ñòðåëÿòü ïî äèàãîíàëè:
7353 if GetRnd(FDifficult
.DiagFire
) then
7355 // Èùåì öåëü ñâåðõó è ñòðåëÿåì, åñëè åñòü:
7356 if FDirection
= TDirection
.D_LEFT
then
7357 angle
:= ANGLE_LEFTUP
7359 angle
:= ANGLE_RIGHTUP
;
7361 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7362 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7364 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
7365 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
7366 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
7367 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
7368 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
7370 SetAIFlag('NEEDFIRE', '1');
7371 SetAIFlag('NEEDSEEUP', '1');
7374 // Èùåì öåëü ñíèçó è ñòðåëÿåì, åñëè åñòü:
7375 if FDirection
= TDirection
.D_LEFT
then
7376 angle
:= ANGLE_LEFTDOWN
7378 angle
:= ANGLE_RIGHTDOWN
;
7380 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7381 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7383 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
7384 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
7385 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
7386 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
7387 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
7389 SetAIFlag('NEEDFIRE', '1');
7390 SetAIFlag('NEEDSEEDOWN', '1');
7394 // Åñëè öåëü "ïåðåä íîñîì", òî ñòðåëÿåì:
7395 if targets
[a
].Line
and targets
[a
].Visible
and
7396 (((FDirection
= TDirection
.D_LEFT
) and (targets
[a
].X
< FObj
.X
)) or
7397 ((FDirection
= TDirection
.D_RIGHT
) and (targets
[a
].X
> FObj
.X
))) then
7399 SetAIFlag('NEEDFIRE', '1');
7404 // Åñëè ëåòèò ïóëÿ, òî, âîçìîæíî, ïîäïðûãèâàåì:
7405 if g_Weapon_Danger(FUID
, FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
,
7406 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
,
7407 40+GetInterval(FDifficult
.Cover
, 40)) then
7408 SetAIFlag('NEEDJUMP', '1');
7410 // Åñëè êîí÷èëèñü ïàòîðíû, òî íóæíî ñìåíèòü îðóæèå:
7411 ammo
:= GetAmmoByWeapon(FCurrWeap
);
7412 if ((FCurrWeap
= WEAPON_SHOTGUN2
) and (ammo
< 2)) or
7413 ((FCurrWeap
= WEAPON_BFG
) and (ammo
< 40)) or
7415 SetAIFlag('SELECTWEAPON', '1');
7417 // Åñëè íóæíî ñìåíèòü îðóæèå, òî âûáèðàåì íóæíîå:
7418 if GetAIFlag('SELECTWEAPON') = '1' then
7421 RemoveAIFlag('SELECTWEAPON');
7425 procedure TBot
.Update();
7438 // Ïðîâåðÿåì, îòêëþ÷¸í ëè AI áîòîâ
7439 if (g_debug_BotAIOff
= 1) and (Team
= TEAM_RED
) then
7441 if (g_debug_BotAIOff
= 2) and (Team
= TEAM_BLUE
) then
7443 if g_debug_BotAIOff
= 3 then
7453 RealizeCurrentWeapon();
7460 procedure TBot
.ReleaseKey(Key
: Byte);
7469 function TBot
.KeyPressed(Key
: Word): Boolean;
7471 Result
:= FKeys
[Key
].Pressed
;
7474 function TBot
.GetAIFlag(const aName
: String): String;
7479 if FAIFlags
= nil then Exit
;
7481 for i
:= 0 to High(FAIFlags
) do
7482 if CompareText(aName
, FAIFlags
[i
].Name
) = 0 then
7483 Exit(FAIFlags
[i
].Value
);
7486 procedure TBot
.RemoveAIFlag(const aName
: String);
7490 if FAIFlags
= nil then Exit
;
7492 for a
:= 0 to High(FAIFlags
) do
7493 if CompareText(aName
, FAIFlags
[a
].Name
) = 0 then
7495 if a
<> High(FAIFlags
) then
7496 for b
:= a
to High(FAIFlags
)-1 do
7497 FAIFlags
[b
] := FAIFlags
[b
+1];
7499 SetLength(FAIFlags
, Length(FAIFlags
)-1);
7504 procedure TBot
.SetAIFlag(const aName
, fValue
: String);
7512 if FAIFlags
<> nil then
7513 for a
:= 0 to High(FAIFlags
) do
7514 if CompareText(aName
, FAIFlags
[a
].Name
) = 0 then
7520 if ok
then FAIFlags
[a
].Value
:= fValue
7523 SetLength(FAIFlags
, Length(FAIFlags
)+1);
7524 with FAIFlags
[High(FAIFlags
)] do
7532 procedure TBot
.UpdateMove
;
7534 procedure GoLeft(Time
: Word = 1);
7536 ReleaseKey(KEY_LEFT
);
7537 ReleaseKey(KEY_RIGHT
);
7538 PressKey(KEY_LEFT
, Time
);
7539 SetDirection(TDirection
.D_LEFT
);
7542 procedure GoRight(Time
: Word = 1);
7544 ReleaseKey(KEY_LEFT
);
7545 ReleaseKey(KEY_RIGHT
);
7546 PressKey(KEY_RIGHT
, Time
);
7547 SetDirection(TDirection
.D_RIGHT
);
7550 function Rnd(a
: Word): Boolean; inline;
7552 Result
:= Random(a
) = 0;
7555 procedure Turn(Time
: Word = 1200);
7557 if RunDirection() = TDirection
.D_LEFT
7564 ReleaseKey(KEY_LEFT
);
7565 ReleaseKey(KEY_RIGHT
);
7568 function CanRunLeft(): Boolean;
7570 Result
:= not CollideLevel(-1, 0);
7573 function CanRunRight(): Boolean;
7575 Result
:= not CollideLevel(1, 0);
7578 function CanRun(): Boolean;
7580 if RunDirection() = TDirection
.D_LEFT
then Result
:= CanRunLeft() else Result
:= CanRunRight();
7583 procedure Jump(Time
: Word = 30);
7585 PressKey(KEY_JUMP
, Time
);
7588 function NearHole(): Boolean;
7592 { TODO 5 : Ëåñòíèöû }
7593 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7594 for x
:= 1 to PLAYER_RECT
.Width
do
7595 if (not StayOnStep(x
*sx
, 0)) and
7596 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7597 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7606 function BorderHole(): Boolean;
7610 { TODO 5 : Ëåñòíèöû }
7611 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7612 for x
:= 1 to PLAYER_RECT
.Width
do
7613 if (not StayOnStep(x
*sx
, 0)) and
7614 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7615 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7617 for xx
:= x
to x
+32 do
7618 if CollideLevel(xx
*sx
, PLAYER_RECT
.Height
) then
7628 function NearDeepHole(): Boolean;
7634 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7637 for x
:= 1 to PLAYER_RECT
.Width
do
7638 if (not StayOnStep(x
*sx
, 0)) and
7639 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7640 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7642 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
7644 if CollideLevel(x
*sx
, PLAYER_RECT
.Height
*y
) then Exit
;
7649 end else Result
:= False;
7652 function OverDeepHole(): Boolean;
7659 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
7661 if CollideLevel(0, PLAYER_RECT
.Height
*y
) then Exit
;
7668 function OnGround(): Boolean;
7670 Result
:= StayOnStep(0, 0) or CollideLevel(0, 1);
7673 function OnLadder(): Boolean;
7675 Result
:= FullInStep(0, 0);
7678 function BelowLadder(): Boolean;
7680 Result
:= (FullInStep(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) and
7681 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
7682 (FullInStep(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) and
7683 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
7686 function BelowLiftUp(): Boolean;
7688 Result
:= ((FullInLift(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) = -1) and
7689 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
7690 ((FullInLift(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) = -1) and
7691 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
7694 function OnTopLift(): Boolean;
7696 Result
:= (FullInLift(0, 0) = -1) and (FullInLift(0, -32) = 0);
7699 function CanJumpOver(): Boolean;
7703 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7707 if not CollideLevel(sx
, 0) then Exit
;
7709 for y
:= 1 to BOT_MAXJUMP
do
7710 if CollideLevel(0, -y
) then Exit
else
7711 if not CollideLevel(sx
, -y
) then
7718 function CanJumpUp(Dist
: ShortInt
): Boolean;
7725 if CollideLevel(Dist
, 0) then Exit
;
7728 for y
:= 0 to BOT_MAXJUMP
do
7729 if CollideLevel(Dist
, -y
) then
7738 for yy
:= y
+1 to BOT_MAXJUMP
do
7739 if not CollideLevel(Dist
, -yy
) then
7748 for y
:= 0 to BOT_MAXJUMP
do
7749 if CollideLevel(0, -y
) then
7757 if y
< yy
then Exit
;
7762 function IsSafeTrigger(): Boolean;
7767 for a
:= 0 to High(gTriggers
) do
7768 if Collide(gTriggers
[a
].X
, gTriggers
[a
].Y
, gTriggers
[a
].Width
, gTriggers
[a
].Height
)
7769 and (gTriggers
[a
].TriggerType
in [TRIGGER_EXIT
, TRIGGER_CLOSEDOOR
, TRIGGER_CLOSETRAP
,
7770 TRIGGER_TRAP
, TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
, TRIGGER_ONOFF
,
7771 TRIGGER_SPAWNMONSTER
, TRIGGER_DAMAGE
, TRIGGER_SHOT
]) then Exit(False);
7775 // Âîçìîæíî, íàæèìàåì êíîïêó:
7776 if Rnd(16) and IsSafeTrigger() then
7779 // Åñëè ïîä ëèôòîì èëè ñòóïåíüêàìè, òî, âîçìîæíî, ïðûãàåì:
7780 if OnLadder() or ((BelowLadder() or BelowLiftUp()) and Rnd(8)) then
7782 ReleaseKey(KEY_LEFT
);
7783 ReleaseKey(KEY_RIGHT
);
7787 // Èäåì âëåâî, åñëè íàäî áûëî:
7788 if GetAIFlag('GOLEFT') <> '' then
7790 RemoveAIFlag('GOLEFT');
7791 if CanRunLeft() then
7795 // Èäåì âïðàâî, åñëè íàäî áûëî:
7796 if GetAIFlag('GORIGHT') <> '' then
7798 RemoveAIFlag('GORIGHT');
7799 if CanRunRight() then
7803 // Åñëè âûëåòåëè çà êàðòó, òî ïðîáóåì âåðíóòüñÿ:
7804 if FObj
.X
< -32 then
7807 if FObj
.X
+32 > gMapInfo
.Width
then
7810 // Ïðûãàåì, åñëè íàäî áûëî:
7811 if GetAIFlag('NEEDJUMP') <> '' then
7814 RemoveAIFlag('NEEDJUMP');
7817 // Ñìîòðèì ââåðõ, åñëè íàäî áûëî:
7818 if GetAIFlag('NEEDSEEUP') <> '' then
7821 ReleaseKey(KEY_DOWN
);
7822 PressKey(KEY_UP
, 20);
7823 RemoveAIFlag('NEEDSEEUP');
7826 // Ñìîòðèì âíèç, åñëè íàäî áûëî:
7827 if GetAIFlag('NEEDSEEDOWN') <> '' then
7830 ReleaseKey(KEY_DOWN
);
7831 PressKey(KEY_DOWN
, 20);
7832 RemoveAIFlag('NEEDSEEDOWN');
7835 // Åñëè íóæíî áûëî â äûðó è ìû íå íà çåìëå, òî ïîêîðíî ëåòèì:
7836 if GetAIFlag('GOINHOLE') <> '' then
7837 if not OnGround() then
7839 ReleaseKey(KEY_LEFT
);
7840 ReleaseKey(KEY_RIGHT
);
7841 RemoveAIFlag('GOINHOLE');
7842 SetAIFlag('FALLINHOLE', '1');
7845 // Åñëè ïàäàëè è äîñòèãëè çåìëè, òî õâàòèò ïàäàòü:
7846 if GetAIFlag('FALLINHOLE') <> '' then
7848 RemoveAIFlag('FALLINHOLE');
7850 // Åñëè ëåòåëè ïðÿìî è ñåé÷àñ íå íà ëåñòíèöå èëè íà âåðøèíå ëèôòà, òî îòõîäèì â ñòîðîíó:
7851 if not (KeyPressed(KEY_LEFT
) or KeyPressed(KEY_RIGHT
)) then
7852 if GetAIFlag('FALLINHOLE') = '' then
7853 if (not OnLadder()) or (FObj
.Vel
.Y
>= 0) or (OnTopLift()) then
7859 // Åñëè íà çåìëå è ìîæíî ïîäïðûãíóòü, òî, âîçìîæíî, ïðûãàåì:
7861 CanJumpUp(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*32) and
7865 // Åñëè íà çåìëå è âîçëå äûðû (ãëóáèíà > 2 ðîñòîâ èãðîêà):
7866 if OnGround() and NearHole() then
7867 if NearDeepHole() then // Åñëè ýòî áåçäíà
7869 0..3: Turn(); // Áåæèì îáðàòíî
7870 4: Jump(); // Ïðûãàåì
7871 5: begin // Ïðûãàåì îáðàòíî
7876 else // Ýòî íå áåçäíà è ìû åùå íå ëåòèì òóäà
7877 if GetAIFlag('GOINHOLE') = '' then
7879 0: Turn(); // Íå íóæíî òóäà
7880 1: Jump(); // Âäðóã ïîâåçåò - ïðûãàåì
7881 else // Åñëè ÿìà ñ ãðàíèöåé, òî ïðè ñëó÷àå ìîæíî òóäà ïðûãíóòü
7882 if BorderHole() then
7883 SetAIFlag('GOINHOLE', '1');
7886 // Åñëè íà çåìëå, íî íåêóäà èäòè:
7887 if (not CanRun()) and OnGround() then
7889 // Åñëè ìû íà ëåñòíèöå èëè ìîæíî ïåðåïðûãíóòü, òî ïðûãàåì:
7890 if CanJumpOver() or OnLadder() then
7892 else // èíà÷å ïîïûòàåìñÿ â äðóãóþ ñòîðîíó
7893 if Random(2) = 0 then
7895 if IsSafeTrigger() then
7901 // Îñòàëîñü ìàëî âîçäóõà:
7902 if FAir
< 36 * 2 then
7905 // Âûáèðàåìñÿ èç êèñëîòû, åñëè íåò êîñòþìà, îáîæãëèñü, èëè ìàëî çäîðîâüÿ:
7906 if (FPowerups
[MR_SUIT
] < gTime
) and ((FLastHit
= HIT_ACID
) or (Healthy() <= 1)) then
7907 if BodyInAcid(0, 0) then
7911 function TBot
.FullInStep(XInc
, YInc
: Integer): Boolean;
7913 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
7914 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_STEP
, False);
7917 {function TBot.NeedItem(Item: Byte): Byte;
7922 procedure TBot
.SelectWeapon(Dist
: Integer);
7926 function HaveAmmo(weapon
: Byte): Boolean;
7929 WEAPON_PISTOL
: Result
:= FAmmo
[A_BULLETS
] >= 1;
7930 WEAPON_SHOTGUN1
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7931 WEAPON_SHOTGUN2
: Result
:= FAmmo
[A_SHELLS
] >= 2;
7932 WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
] >= 10;
7933 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
] >= 1;
7934 WEAPON_PLASMA
: Result
:= FAmmo
[A_CELLS
] >= 10;
7935 WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
] >= 40;
7936 WEAPON_SUPERCHAINGUN
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7937 WEAPON_FLAMETHROWER
: Result
:= FAmmo
[A_FUEL
] >= 1;
7938 else Result
:= True;
7943 if Dist
= -1 then Dist
:= BOT_LONGDIST
;
7945 if Dist
> BOT_LONGDIST
then
7946 begin // Äàëüíèé áîé
7948 if FWeapon
[FDifficult
.WeaponPrior
[a
]] and HaveAmmo(FDifficult
.WeaponPrior
[a
]) then
7950 FSelectedWeapon
:= FDifficult
.WeaponPrior
[a
];
7954 else //if Dist > BOT_UNSAFEDIST then
7955 begin // Áëèæíèé áîé
7957 if FWeapon
[FDifficult
.CloseWeaponPrior
[a
]] and HaveAmmo(FDifficult
.CloseWeaponPrior
[a
]) then
7959 FSelectedWeapon
:= FDifficult
.CloseWeaponPrior
[a
];
7966 if FWeapon[FDifficult.SafeWeaponPrior[a]] and HaveAmmo(FDifficult.SafeWeaponPrior[a]) then
7968 FSelectedWeapon := FDifficult.SafeWeaponPrior[a];
7974 function TBot
.PickItem(ItemType
: Byte; force
: Boolean; var remove
: Boolean): Boolean;
7976 Result
:= inherited PickItem(ItemType
, force
, remove
);
7978 if Result
then SetAIFlag('SELECTWEAPON', '1');
7981 function TBot
.Heal(value
: Word; Soft
: Boolean): Boolean;
7983 Result
:= inherited Heal(value
, Soft
);
7986 function TBot
.Healthy(): Byte;
7988 if FPowerups
[MR_INVUL
] >= gTime
then Result
:= 3
7989 else if (FHealth
> 80) or ((FHealth
> 50) and (FArmor
> 20)) then Result
:= 3
7990 else if (FHealth
> 50) then Result
:= 2
7991 else if (FHealth
> 20) then Result
:= 1
7995 function TBot
.TargetOnScreen(TX
, TY
: Integer): Boolean;
7997 Result
:= (Abs(FObj
.X
-TX
) <= Trunc(gPlayerScreenSize
.X
*0.6)) and
7998 (Abs(FObj
.Y
-TY
) <= Trunc(gPlayerScreenSize
.Y
*0.6));
8001 procedure TBot
.OnDamage(Angle
: SmallInt
);
8009 if (Angle
= 0) or (Angle
= 180) then
8012 if (g_GetUIDType(FLastSpawnerUID
) = UID_PLAYER
) and
8013 (TGameOption
.BOTS_VS_PLAYERS
in gGameSettings
.Options
) then
8015 pla
:= g_Player_Get(FLastSpawnerUID
);
8016 ok
:= not TargetOnScreen(pla
.FObj
.X
+ PLAYER_RECT
.X
,
8017 pla
.FObj
.Y
+ PLAYER_RECT
.Y
);
8020 if (g_GetUIDType(FLastSpawnerUID
) = UID_MONSTER
) and
8021 (TGameOption
.BOTS_VS_MONSTERS
in gGameSettings
.Options
) then
8023 mon
:= g_Monsters_ByUID(FLastSpawnerUID
);
8024 ok
:= not TargetOnScreen(mon
.Obj
.X
+ mon
.Obj
.Rect
.X
,
8025 mon
.Obj
.Y
+ mon
.Obj
.Rect
.Y
);
8030 SetAIFlag('ATTACKLEFT', '1')
8032 SetAIFlag('ATTACKRIGHT', '1');
8036 function TBot
.RunDirection(): TDirection
;
8038 if Abs(Vel
.X
) >= 1 then
8040 if Vel
.X
> 0 then Result
:= TDirection
.D_RIGHT
else Result
:= TDirection
.D_LEFT
;
8042 Result
:= FDirection
;
8045 function TBot
.GetRnd(a
: Byte): Boolean;
8047 if a
= 0 then Result
:= False
8048 else if a
= 255 then Result
:= True
8049 else Result
:= Random(256) > 255-a
;
8052 function TBot
.GetInterval(a
: Byte; radius
: SmallInt
): SmallInt
;
8054 Result
:= Round((255-a
)/255*radius
*(Random(2)-1));
8058 procedure TDifficult
.save (st
: TStream
);
8060 st
.WriteByte(DiagFire
);
8061 st
.WriteByte(InvisFire
);
8062 st
.WriteByte(DiagPrecision
);
8063 st
.WriteByte(FlyPrecision
);
8064 st
.WriteByte(Cover
);
8065 st
.WriteByte(CloseJump
);
8066 st
.WriteBuffer(WeaponPrior
[Low(WeaponPrior
)], SizeOf(WeaponPrior
));
8067 st
.WriteBuffer(CloseWeaponPrior
[Low(CloseWeaponPrior
)], SizeOf(CloseWeaponPrior
));
8070 procedure TDifficult
.load (st
: TStream
);
8072 DiagFire
:= st
.ReadByte();
8073 InvisFire
:= st
.ReadByte();
8074 DiagPrecision
:= st
.ReadByte();
8075 FlyPrecision
:= st
.ReadByte();
8076 Cover
:= st
.ReadByte();
8077 CloseJump
:= st
.ReadByte();
8078 st
.ReadBuffer(WeaponPrior
[Low(WeaponPrior
)], SizeOf(WeaponPrior
));
8079 st
.ReadBuffer(CloseWeaponPrior
[Low(CloseWeaponPrior
)], SizeOf(CloseWeaponPrior
));
8083 procedure TBot
.SaveState (st
: TStream
);
8088 inherited SaveState(st
);
8089 utils
.writeSign(st
, 'BOT0');
8091 st
.WriteByte(FSelectedWeapon
); // Âûáðàííîå îðóæèå
8092 st
.WriteWordLE(FTargetUID
); // UID öåëè
8093 st
.WriteDWordLE(FLastVisible
); // Âðåìÿ ïîòåðè öåëè
8095 // Êîëè÷åñòâî ôëàãîâ ÈÈ
8096 dw
:= Length(FAIFlags
);
8097 st
.WriteDWordLE(dw
);
8100 for i
:= 0 to dw
-1 do
8102 utils
.writeStr(st
, FAIFlags
[i
].Name
, 20);
8103 utils
.writeStr(st
, FAIFlags
[i
].Value
, 20);
8106 // Íàñòðîéêè ñëîæíîñòè
8107 FDifficult
.save(st
);
8111 procedure TBot
.LoadState (st
: TStream
);
8116 inherited LoadState(st
);
8117 if not utils
.checkSign(st
, 'BOT0') then
8118 Raise XStreamError
.Create('invalid bot signature');
8120 FSelectedWeapon
:= st
.ReadByte(); // Âûáðàííîå îðóæèå
8121 FTargetUID
:= st
.ReadWordLE(); // UID öåëè
8122 FLastVisible
:= st
.ReadDWordLE(); // Âðåìÿ ïîòåðè öåëè
8124 // Êîëè÷åñòâî ôëàãîâ ÈÈ
8125 dw
:= st
.ReadDWordLE();
8127 Raise XStreamError
.Create('invalid number of bot AI flags');
8128 SetLength(FAIFlags
, dw
);
8131 for i
:= 0 to dw
-1 do
8133 FAIFlags
[i
].Name
:= utils
.readStr(st
, 20);
8134 FAIFlags
[i
].Value
:= utils
.readStr(st
, 20);
8137 // Íàñòðîéêè ñëîæíîñòè
8138 FDifficult
.load(st
);
8143 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');
8144 conRegVar('player_indicator_style', @gPlayerIndicatorStyle
, 'Visual appearance of indicator', 'Visual appearance of indicator');