1 (* Copyright (C) Doom 2D: Forever Developers
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, version 3 of the License ONLY.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 {$INCLUDE ../shared/a_modes.inc}
23 {$IFDEF USE_MEMPOOL}mempool
,{$ENDIF}
24 e_graphics
, g_playermodel
, g_basic
, g_textures
,
25 g_weapons
, g_phys
, g_sound
, g_saveload
, MAPDEF
,
61 AmmoLimits
: Array [0..1] of Array [A_BULLETS
..A_HIGH
] of Word =
62 ((200, 50, 50, 300, 100),
63 (400, 100, 100, 600, 200));
84 ANGLE_NONE
= Low(SmallInt);
86 CORPSE_STATE_REMOVEME
= 0;
87 CORPSE_STATE_NORMAL
= 1;
88 CORPSE_STATE_MESS
= 2;
90 PLAYER_RECT
: TRectWH
= (X
:15; Y
:12; Width
:34; Height
:52);
91 PLAYER_RECT_CX
= 15+(34 div 2);
92 PLAYER_RECT_CY
= 12+(52 div 2);
93 PLAYER_CORPSERECT
: TRectWH
= (X
:15; Y
:48; Width
:34; Height
:16);
96 PLAYER_HP_LIMIT
= 200;
98 PLAYER_AP_LIMIT
= 200;
102 PLAYER_BURN_TIME
= 110;
104 PLAYER1_DEF_COLOR
: TRGB
= (R
:64; G
:175; B
:48);
105 PLAYER2_DEF_COLOR
: TRGB
= (R
:96; G
:96; B
:96);
124 TPlayerStatArray
= Array of TPlayerStat
;
126 TPlayerSavedState
= record
134 Ammo
: Array [A_BULLETS
..A_HIGH
] of Word;
135 MaxAmmo
: Array [A_BULLETS
..A_HIGH
] of Word;
136 Weapon
: Array [WP_FIRST
..WP_LAST
] of Boolean;
137 Rulez
: Set of R_ITEM_BACKPACK
..R_BERSERK
;
146 TPlayer
= class{$IFDEF USE_MEMPOOL}(TPoolObject
){$ENDIF}
154 FDirection
: TDirection
;
162 FMonsterKills
: Integer;
169 FCanJetpack
: Boolean;
175 FNextWeapDelay
: Byte; // frames
176 FBFGFireCounter
: SmallInt;
177 FLastSpawnerUID
: Word;
181 FSpectatePlayer
: Integer;
182 FFirePainTime
: Integer;
185 FSavedStateNum
: Integer;
187 FModel
: TPlayerModel
;
188 FPunchAnim
: TAnimation
;
191 FActionForce
: Boolean;
192 FActionChanged
: Boolean;
194 FFireAngle
: SmallInt;
198 FShellTimer
: Integer;
200 FSawSound
: TPlayableSound
;
201 FSawSoundIdle
: TPlayableSound
;
202 FSawSoundHit
: TPlayableSound
;
203 FSawSoundSelect
: TPlayableSound
;
204 FFlameSoundOn
: TPlayableSound
;
205 FFlameSoundOff
: TPlayableSound
;
206 FFlameSoundWork
: TPlayableSound
;
207 FJetSoundOn
: TPlayableSound
;
208 FJetSoundOff
: TPlayableSound
;
209 FJetSoundFly
: TPlayableSound
;
213 FJustTeleported
: Boolean;
215 mEDamageType
: Integer;
218 function CollideLevel(XInc
, YInc
: Integer): Boolean;
219 function StayOnStep(XInc
, YInc
: Integer): Boolean;
220 function HeadInLiquid(XInc
, YInc
: Integer): Boolean;
221 function BodyInLiquid(XInc
, YInc
: Integer): Boolean;
222 function BodyInAcid(XInc
, YInc
: Integer): Boolean;
223 function FullInLift(XInc
, YInc
: Integer): Integer;
224 {procedure CollideItem();}
225 procedure FlySmoke(Times
: DWORD
= 1);
226 procedure OnFireFlame(Times
: DWORD
= 1);
227 function GetAmmoByWeapon(Weapon
: Byte): Word;
228 procedure SetAction(Action
: Byte; Force
: Boolean = False);
229 procedure OnDamage(Angle
: SmallInt); virtual;
230 function firediry(): Integer;
233 procedure Run(Direction
: TDirection
);
234 procedure NextWeapon();
235 procedure PrevWeapon();
242 function getNextWeaponIndex (): Byte; // return 255 for "no switch"
243 procedure resetWeaponQueue ();
244 function hasAmmoForWeapon (weapon
: Byte): Boolean;
245 function hasAmmoForShooting (weapon
: Byte): Boolean;
246 function shouldSwitch (weapon
: Byte; hadWeapon
: Boolean) : Boolean;
248 procedure doDamage (v
: Integer);
250 function refreshCorpse(): Boolean;
253 FDamageBuffer
: Integer;
255 FAmmo
: Array [A_BULLETS
..A_HIGH
] of Word;
256 FMaxAmmo
: Array [A_BULLETS
..A_HIGH
] of Word;
257 FWeapon
: Array [WP_FIRST
..WP_LAST
] of Boolean;
258 FRulez
: Set of R_ITEM_BACKPACK
..R_BERSERK
;
260 FMegaRulez
: Array [MR_SUIT
..MR_MAX
] of DWORD
;
261 FReloading
: Array [WP_FIRST
..WP_LAST
] of Word;
262 FTime
: Array [T_RESPAWN
..T_FLAGCAP
] of DWORD
;
263 FKeys
: Array [KEY_LEFT
..KEY_CHAT
] of TKeyState
;
264 FWeapSwitchMode
: Byte;
265 FWeapPreferences
: Array [WP_FIRST
.. WP_LAST
+1] of Byte;
266 FSwitchToEmpty
: Byte;
269 FPreferredTeam
: Byte;
272 FWantsInGame
: Boolean;
277 FActualModelName
: string;
284 FSpawnInvul
: Integer;
286 FWaitForFirstSpawn
: Boolean; // set to `true` in server, used to spawn a player on first full state request
289 // debug: viewport offset
290 viewPortX
, viewPortY
, viewPortW
, viewPortH
: Integer;
292 function isValidViewPort (): Boolean; inline;
294 constructor Create(); virtual;
295 destructor Destroy(); override;
296 procedure Respawn(Silent
: Boolean; Force
: Boolean = False); virtual;
297 function GetRespawnPoint(): Byte;
298 procedure PressKey(Key
: Byte; Time
: Word = 1);
299 procedure ReleaseKeys();
300 procedure SetModel(ModelName
: String);
301 procedure SetColor(Color
: TRGB
);
302 function GetColor(): TRGB
;
303 procedure SetWeapon(W
: Byte);
304 function IsKeyPressed(K
: Byte): Boolean;
305 function GetKeys(): Byte;
306 function PickItem(ItemType
: Byte; arespawn
: Boolean; var remove
: Boolean): Boolean; virtual;
307 procedure SetWeaponPrefs(Prefs
: Array of Byte);
308 procedure SetWeaponPref(Weapon
, Pref
: Byte);
309 function GetWeaponPref(Weapon
: Byte) : Byte;
310 function GetMorePrefered() : Byte;
311 function MaySwitch(Weapon
: Byte) : Boolean;
312 function Collide(X
, Y
: Integer; Width
, Height
: Word): Boolean; overload
;
313 function Collide(Panel
: TPanel
): Boolean; overload
;
314 function Collide(X
, Y
: Integer): Boolean; overload
;
315 procedure SetDirection(Direction
: TDirection
);
316 procedure GetSecret();
317 function TeleportTo(X
, Y
: Integer; silent
: Boolean; dir
: Byte): Boolean;
319 procedure Push(vx
, vy
: Integer);
320 procedure ChangeModel(ModelName
: String);
321 procedure SwitchTeam
;
322 procedure ChangeTeam(Team
: Byte);
324 function GetFlag(Flag
: Byte): Boolean;
325 procedure SetFlag(Flag
: Byte);
326 function DropFlag(Silent
: Boolean = True; DoThrow
: Boolean = False): Boolean;
327 function TryDropFlag(): Boolean;
328 procedure AllRulez(Health
: Boolean);
329 procedure RestoreHealthArmor();
330 procedure FragCombo();
331 procedure GiveItem(ItemType
: Byte);
332 procedure Damage(value
: Word; SpawnerUID
: Word; vx
, vy
: Integer; t
: Byte); virtual;
333 function Heal(value
: Word; Soft
: Boolean): Boolean; virtual;
334 procedure MakeBloodVector(Count
: Word; VelX
, VelY
: Integer);
335 procedure MakeBloodSimple(Count
: Word);
336 procedure Kill(KillType
: Byte; SpawnerUID
: Word; t
: Byte);
337 procedure Reset(Force
: Boolean);
338 procedure Spectate(NoMove
: Boolean = False);
339 procedure SwitchNoClip
;
340 procedure SoftReset();
341 procedure Draw(); virtual;
342 procedure DrawPain();
343 procedure DrawPickup();
344 procedure DrawRulez();
346 procedure DrawIndicator(Color
: TRGB
);
347 procedure DrawBubble();
349 procedure PreUpdate();
350 procedure Update(); virtual;
351 procedure RememberState();
352 procedure RecallState();
353 procedure SaveState (st
: TStream
); virtual;
354 procedure LoadState (st
: TStream
); virtual;
355 procedure PauseSounds(Enable
: Boolean);
356 procedure NetFire(Wpn
: Byte; X
, Y
, AX
, AY
: Integer; WID
: Integer = -1);
357 procedure DoLerp(Level
: Integer = 2);
358 procedure SetLerp(XTo
, YTo
: Integer);
359 procedure ProcessWeaponAction(Action
: Byte);
360 procedure QueueWeaponSwitch(Weapon
: Byte);
361 procedure RealizeCurrentWeapon();
365 procedure JetpackOff
;
366 procedure CatchFire(Attacker
: Word; Timeout
: Integer = PLAYER_BURN_TIME
);
368 //WARNING! this does nothing for now, but still call it!
369 procedure positionChanged (); //WARNING! call this after entity position was changed, or coldet will not work right!
371 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
372 procedure moveBy (dx
, dy
: Integer); inline;
374 function getCameraObj(): TObj
;
377 property Vel
: TPoint2i read FObj
.Vel
;
378 property Obj
: TObj read FObj
;
380 property Name
: String read FName write FName
;
381 property Model
: TPlayerModel read FModel
;
382 property Health
: Integer read FHealth write FHealth
;
383 property Lives
: Byte read FLives write FLives
;
384 property Armor
: Integer read FArmor write FArmor
;
385 property Air
: Integer read FAir write FAir
;
386 property JetFuel
: Integer read FJetFuel write FJetFuel
;
387 property Frags
: Integer read FFrags write FFrags
;
388 property Assists
: Integer read FAssists write FAssists
;
389 property Death
: Integer read FDeath write FDeath
;
390 property Kills
: Integer read FKills write FKills
;
391 property CurrWeap
: Byte read FCurrWeap write FCurrWeap
;
392 property WeapSwitchMode
: Byte read FWeapSwitchMode write FWeapSwitchMode
;
393 property SwitchToEmpty
: Byte read FSwitchToEmpty write FSwitchToEmpty
;
394 property SkipFist
: Byte read FSkipFist write FSkipFist
;
395 property MonsterKills
: Integer read FMonsterKills write FMonsterKills
;
396 property Secrets
: Integer read FSecrets
;
397 property GodMode
: Boolean read FGodMode write FGodMode
;
398 property NoTarget
: Boolean read FNoTarget write FNoTarget
;
399 property NoReload
: Boolean read FNoReload write FNoReload
;
400 property alive
: Boolean read FAlive write FAlive
;
401 property Flag
: Byte read FFlag
;
402 property Team
: Byte read FTeam write FTeam
;
403 property Direction
: TDirection read FDirection
;
404 property GameX
: Integer read FObj
.X write FObj
.X
;
405 property GameY
: Integer read FObj
.Y write FObj
.Y
;
406 property GameVelX
: Integer read FObj
.Vel
.X write FObj
.Vel
.X
;
407 property GameVelY
: Integer read FObj
.Vel
.Y write FObj
.Vel
.Y
;
408 property GameAccelX
: Integer read FObj
.Accel
.X write FObj
.Accel
.X
;
409 property GameAccelY
: Integer read FObj
.Accel
.Y write FObj
.Accel
.Y
;
410 property IncCam
: Integer read FIncCam write FIncCam
;
411 property IncCamOld
: Integer read FIncCamOld write FIncCamOld
;
412 property SlopeOld
: Integer read FSlopeOld write FSlopeOld
;
413 property UID
: Word read FUID write FUID
;
414 property JustTeleported
: Boolean read FJustTeleported write FJustTeleported
;
415 property NetTime
: LongWord read FNetTime write FNetTime
;
418 property eName
: String read FName write FName
;
419 property eHealth
: Integer read FHealth write FHealth
;
420 property eLives
: Byte read FLives write FLives
;
421 property eArmor
: Integer read FArmor write FArmor
;
422 property eAir
: Integer read FAir write FAir
;
423 property eJetFuel
: Integer read FJetFuel write FJetFuel
;
424 property eFrags
: Integer read FFrags write FFrags
;
425 property eAssists
: Integer read FAssists write FAssists
;
426 property eDeath
: Integer read FDeath write FDeath
;
427 property eKills
: Integer read FKills write FKills
;
428 property eCurrWeap
: Byte read FCurrWeap write FCurrWeap
;
429 property eMonsterKills
: Integer read FMonsterKills write FMonsterKills
;
430 property eSecrets
: Integer read FSecrets write FSecrets
;
431 property eGodMode
: Boolean read FGodMode write FGodMode
;
432 property eNoTarget
: Boolean read FNoTarget write FNoTarget
;
433 property eNoReload
: Boolean read FNoReload write FNoReload
;
434 property eAlive
: Boolean read FAlive write FAlive
;
435 property eFlag
: Byte read FFlag
;
436 property eTeam
: Byte read FTeam write FTeam
;
437 property eDirection
: TDirection read FDirection
;
438 property eGameX
: Integer read FObj
.X write FObj
.X
;
439 property eGameY
: Integer read FObj
.Y write FObj
.Y
;
440 property eGameVelX
: Integer read FObj
.Vel
.X write FObj
.Vel
.X
;
441 property eGameVelY
: Integer read FObj
.Vel
.Y write FObj
.Vel
.Y
;
442 property eGameAccelX
: Integer read FObj
.Accel
.X write FObj
.Accel
.X
;
443 property eGameAccelY
: Integer read FObj
.Accel
.Y write FObj
.Accel
.Y
;
444 property eIncCam
: Integer read FIncCam write FIncCam
;
445 property eUID
: Word read FUID
;
446 property eJustTeleported
: Boolean read FJustTeleported
;
447 property eNetTime
: LongWord read FNetTime
;
449 // set this before assigning something to `eDamage`
450 property eDamageType
: Integer read mEDamageType write mEDamageType
;
451 property eDamage
: Integer write doDamage
;
462 WeaponPrior
: packed array [WP_FIRST
..WP_LAST
] of Byte;
463 CloseWeaponPrior
: packed array [WP_FIRST
..WP_LAST
] of Byte;
464 //SafeWeaponPrior: Array [WP_FIRST..WP_LAST] of Byte;
467 procedure save (st
: TStream
);
468 procedure load (st
: TStream
);
476 TBot
= class(TPlayer
)
478 FSelectedWeapon
: Byte;
481 FAIFlags
: Array of TAIFlag
;
482 FDifficult
: TDifficult
;
484 function GetRnd(a
: Byte): Boolean;
485 function GetInterval(a
: Byte; radius
: SmallInt): SmallInt;
486 function RunDirection(): TDirection
;
487 function FullInStep(XInc
, YInc
: Integer): Boolean;
488 //function NeedItem(Item: Byte): Byte;
489 procedure SelectWeapon(Dist
: Integer);
490 procedure SetAIFlag(aName
, fValue
: String20
);
491 function GetAIFlag(aName
: String20
): String20
;
492 procedure RemoveAIFlag(aName
: String20
);
493 function Healthy(): Byte;
494 procedure UpdateMove();
495 procedure UpdateCombat();
496 function KeyPressed(Key
: Word): Boolean;
497 procedure ReleaseKey(Key
: Byte);
498 function TargetOnScreen(TX
, TY
: Integer): Boolean;
499 procedure OnDamage(Angle
: SmallInt); override;
502 procedure Respawn(Silent
: Boolean; Force
: Boolean = False); override;
503 constructor Create(); override;
504 destructor Destroy(); override;
505 procedure Draw(); override;
506 function PickItem(ItemType
: Byte; force
: Boolean; var remove
: Boolean): Boolean; override;
507 function Heal(value
: Word; Soft
: Boolean): Boolean; override;
508 procedure Update(); override;
509 procedure SaveState (st
: TStream
); override;
510 procedure LoadState (st
: TStream
); override;
522 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
523 procedure moveBy (dx
, dy
: Integer); inline;
525 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
539 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
540 procedure moveBy (dx
, dy
: Integer); inline;
542 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
545 TCorpse
= class{$IFDEF USE_MEMPOOL}(TPoolObject
){$ENDIF}
554 FAnimation
: TAnimation
;
555 FAnimationMask
: TAnimation
;
558 constructor Create(X
, Y
: Integer; ModelName
: String; aMess
: Boolean);
559 destructor Destroy(); override;
560 procedure Damage(Value
: Word; SpawnerUID
: Word; vx
, vy
: Integer);
563 procedure SaveState (st
: TStream
);
564 procedure LoadState (st
: TStream
);
566 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
567 procedure moveBy (dx
, dy
: Integer); inline;
569 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
571 function ObjPtr (): PObj
; inline;
573 property Obj
: TObj read FObj
; // copies object
574 property State
: Byte read FState
;
575 property Mess
: Boolean read FMess
;
578 TTeamStat
= Array [TEAM_RED
..TEAM_BLUE
] of
584 gPlayers
: Array of TPlayer
;
585 gCorpses
: Array of TCorpse
;
586 gGibs
: Array of TGib
;
587 gShells
: Array of TShell
;
588 gTeamStat
: TTeamStat
;
589 gFly
: Boolean = False;
590 gAimLine
: Boolean = False;
591 gChatBubble
: Integer = 0;
592 gPlayerIndicator
: Integer = 1;
593 gPlayerIndicatorStyle
: Integer = 0;
595 gSpectLatchPID1
: Word = 0;
596 gSpectLatchPID2
: Word = 0;
597 MAX_RUNVEL
: Integer = 8;
598 VEL_JUMP
: Integer = 10;
599 SHELL_TIMEOUT
: Cardinal = 60000;
601 function Lerp(X
, Y
, Factor
: Integer): Integer;
603 procedure g_Gibs_SetMax(Count
: Word);
604 function g_Gibs_GetMax(): Word;
605 procedure g_Corpses_SetMax(Count
: Word);
606 function g_Corpses_GetMax(): Word;
607 procedure g_Force_Model_Set(Mode
: Word);
608 function g_Force_Model_Get(): Word;
609 procedure g_Forced_Model_SetName(Model
: String);
610 function g_Forced_Model_GetName(): String;
611 procedure g_Shells_SetMax(Count
: Word);
612 function g_Shells_GetMax(): Word;
614 procedure g_Player_Init();
615 procedure g_Player_Free();
616 function g_Player_Create(ModelName
: String; Color
: TRGB
; Team
: Byte; Bot
: Boolean): Word;
617 function g_Player_CreateFromState (st
: TStream
): Word;
618 procedure g_Player_Remove(UID
: Word);
619 procedure g_Player_ResetTeams();
620 procedure g_Player_PreUpdate();
621 procedure g_Player_UpdateAll();
622 procedure g_Player_DrawAll();
623 procedure g_Player_DrawDebug(p
: TPlayer
);
624 procedure g_Player_DrawHealth();
625 procedure g_Player_RememberAll();
626 procedure g_Player_ResetAll(Force
, Silent
: Boolean);
627 function g_Player_Get(UID
: Word): TPlayer
;
628 function g_Player_GetCount(): Byte;
629 function g_Player_GetStats(): TPlayerStatArray
;
630 function g_Player_ExistingName(Name
: String): Boolean;
631 function g_Player_CreateCorpse(Player
: TPlayer
): Integer;
632 procedure g_Player_CreateGibs(fX
, fY
: Integer; ModelName
: String; fColor
: TRGB
);
633 procedure g_Player_CreateShell(fX
, fY
, dX
, dY
: Integer; T
: Byte);
634 procedure g_Player_UpdatePhysicalObjects();
635 procedure g_Player_DrawCorpses();
636 procedure g_Player_DrawShells();
637 procedure g_Player_RemoveAllCorpses();
638 procedure g_Player_Corpses_SaveState (st
: TStream
);
639 procedure g_Player_Corpses_LoadState (st
: TStream
);
640 procedure g_Player_ResetReady();
641 procedure g_Bot_Add(Team
, Difficult
: Byte; Handicap
: Integer = 100);
642 procedure g_Bot_AddList(Team
: Byte; lname
: ShortString; num
: Integer = -1; Handicap
: Integer = 100);
643 procedure g_Bot_MixNames();
644 procedure g_Bot_RemoveAll();
645 function g_Bot_GetCount(): Integer;
650 {$INCLUDE ../nogl/noGLuses.inc}
651 {$IFDEF ENABLE_HOLMES}
654 e_log
, g_map
, g_items
, g_console
, g_gfx
, Math
,
655 g_options
, g_triggers
, g_menu
, g_game
, g_grid
, e_res
,
656 wadreader
, g_main
, g_monsters
, CONFIG
, g_language
,
657 g_net
, g_netmsg
, g_window
,
660 const PLR_SAVE_VERSION
= 0;
670 diag_precision
: Byte;
674 w_prior1
: Array [WP_FIRST
..WP_LAST
] of Byte;
675 w_prior2
: Array [WP_FIRST
..WP_LAST
] of Byte;
676 w_prior3
: Array [WP_FIRST
..WP_LAST
] of Byte;
680 TIME_RESPAWN1
= 1500;
681 TIME_RESPAWN2
= 2000;
682 TIME_RESPAWN3
= 3000;
685 JET_MAX
= 540; // ~30 sec
686 PLAYER_SUIT_TIME
= 30000;
687 PLAYER_INVUL_TIME
= 30000;
688 PLAYER_INVIS_TIME
= 35000;
689 FRAG_COMBO_TIME
= 3000;
693 ANGLE_RIGHTDOWN
= -35;
695 ANGLE_LEFTDOWN
= -145;
696 PLAYER_HEADRECT
: TRectWH
= (X
:24; Y
:12; Width
:20; Height
:12);
697 WEAPONPOINT
: Array [TDirection
] of TDFPoint
= ((X
:16; Y
:32), (X
:47; Y
:32));
700 BOT_UNSAFEDIST
= 128;
701 TEAMCOLOR
: Array [TEAM_RED
..TEAM_BLUE
] of TRGB
= ((R
:255; G
:0; B
:0),
703 DIFFICULT_EASY
: TDifficult
= (DiagFire
: 32; InvisFire
: 32; DiagPrecision
: 32;
704 FlyPrecision
: 32; Cover
: 32; CloseJump
: 32;
705 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
706 DIFFICULT_MEDIUM
: TDifficult
= (DiagFire
: 127; InvisFire
: 127; DiagPrecision
: 127;
707 FlyPrecision
: 127; Cover
: 127; CloseJump
: 127;
708 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
709 DIFFICULT_HARD
: TDifficult
= (DiagFire
: 255; InvisFire
: 255; DiagPrecision
: 255;
710 FlyPrecision
: 255; Cover
: 255; CloseJump
: 255;
711 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
712 WEAPON_PRIOR1
: Array [WP_FIRST
..WP_LAST
] of Byte =
713 (WEAPON_FLAMETHROWER
, WEAPON_SUPERPULEMET
,
714 WEAPON_SHOTGUN2
, WEAPON_SHOTGUN1
,
715 WEAPON_CHAINGUN
, WEAPON_PLASMA
, WEAPON_ROCKETLAUNCHER
,
716 WEAPON_BFG
, WEAPON_PISTOL
, WEAPON_SAW
, WEAPON_KASTET
);
717 WEAPON_PRIOR2
: Array [WP_FIRST
..WP_LAST
] of Byte =
718 (WEAPON_FLAMETHROWER
, WEAPON_SUPERPULEMET
,
719 WEAPON_BFG
, WEAPON_ROCKETLAUNCHER
,
720 WEAPON_SHOTGUN2
, WEAPON_PLASMA
, WEAPON_SHOTGUN1
,
721 WEAPON_CHAINGUN
, WEAPON_PISTOL
, WEAPON_SAW
, WEAPON_KASTET
);
722 //WEAPON_PRIOR3: Array [WP_FIRST..WP_LAST] of Byte =
723 // (WEAPON_FLAMETHROWER, WEAPON_SUPERPULEMET,
724 // WEAPON_BFG, WEAPON_PLASMA, WEAPON_SHOTGUN2,
725 // WEAPON_CHAINGUN, WEAPON_SHOTGUN1, WEAPON_SAW,
726 // WEAPON_ROCKETLAUNCHER, WEAPON_PISTOL, WEAPON_KASTET);
727 WEAPON_RELOAD
: Array [WP_FIRST
..WP_LAST
] of Byte =
728 (5, 2, 6, 18, 36, 2, 12, 2, 14, 2, 2);
730 PLAYER_SIGNATURE
= $52594C50; // 'PLYR'
731 CORPSE_SIGNATURE
= $50524F43; // 'CORP'
733 BOTNAMES_FILENAME
= 'botnames.txt';
734 BOTLIST_FILENAME
= 'botlist.txt';
738 MaxCorpses
: Word = 20;
739 MaxShells
: Word = 300;
740 ForceModel
: Word = 0;
741 ForcedModelName
: String = STD_PLAYER_MODEL
;
742 CurrentGib
: Integer = 0;
743 CurrentShell
: Integer = 0;
744 BotNames
: Array of String;
745 BotList
: Array of TBotProfile
;
746 SavedStates
: Array of TPlayerSavedState
;
749 function Lerp(X
, Y
, Factor
: Integer): Integer;
751 Result
:= X
+ ((Y
- X
) div Factor
);
754 function SameTeam(UID1
, UID2
: Word): Boolean;
758 if (UID1
> UID_MAX_PLAYER
) or (UID1
<= UID_MAX_GAME
) or
759 (UID2
> UID_MAX_PLAYER
) or (UID2
<= UID_MAX_GAME
) then Exit
;
761 if (g_Player_Get(UID1
) = nil) or (g_Player_Get(UID2
) = nil) then Exit
;
763 if ((g_Player_Get(UID1
).Team
= TEAM_NONE
) or
764 (g_Player_Get(UID2
).Team
= TEAM_NONE
)) then Exit
;
766 Result
:= g_Player_Get(UID1
).FTeam
= g_Player_Get(UID2
).FTeam
;
769 procedure g_Gibs_SetMax(Count
: Word);
772 SetLength(gGibs
, Count
);
774 if CurrentGib
>= Count
then
778 function g_Gibs_GetMax(): Word;
783 procedure g_Shells_SetMax(Count
: Word);
786 SetLength(gShells
, Count
);
788 if CurrentShell
>= Count
then
792 function g_Shells_GetMax(): Word;
798 procedure g_Corpses_SetMax(Count
: Word);
801 SetLength(gCorpses
, Count
);
804 function g_Corpses_GetMax(): Word;
806 Result
:= MaxCorpses
;
809 procedure g_Force_Model_Set(Mode
: Word);
814 function g_Force_Model_Get(): Word;
816 Result
:= ForceModel
;
819 procedure g_Forced_Model_SetName(Model
: String);
821 ForcedModelName
:= Model
;
824 function g_Forced_Model_GetName(): String;
826 Result
:= ForcedModelName
;
829 function g_Player_Create(ModelName
: String; Color
: TRGB
; Team
: Byte; Bot
: Boolean): Word;
839 // Åñòü ëè ìåñòî â gPlayers:
840 if gPlayers
<> nil then
841 for a
:= 0 to High(gPlayers
) do
842 if gPlayers
[a
] = nil then
848 // Íåò ìåñòà - ðàñøèðÿåì gPlayers:
851 SetLength(gPlayers
, Length(gPlayers
)+1);
855 // Ñîçäàåì îáúåêò èãðîêà:
857 gPlayers
[a
] := TBot
.Create()
859 gPlayers
[a
] := TPlayer
.Create();
862 gPlayers
[a
].FActualModelName
:= ModelName
;
863 gPlayers
[a
].SetModel(ModelName
);
864 if Bot
and (g_Force_Model_Get() <> 0) then
865 gPlayers
[a
].SetModel(g_Forced_Model_GetName());
867 // Íåò ìîäåëè - ñîçäàíèå íå âîçìîæíî:
868 if gPlayers
[a
].FModel
= nil then
872 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], [ModelName
]));
876 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
877 if Random(2) = 0 then
881 gPlayers
[a
].FPreferredTeam
:= Team
;
883 case gGameSettings
.GameMode
of
884 GM_DM
: gPlayers
[a
].FTeam
:= TEAM_NONE
;
886 GM_CTF
: gPlayers
[a
].FTeam
:= gPlayers
[a
].FPreferredTeam
;
888 GM_COOP
: gPlayers
[a
].FTeam
:= TEAM_COOP
;
891 // Åñëè êîìàíäíàÿ èãðà - êðàñèì ìîäåëü â öâåò êîìàíäû:
892 gPlayers
[a
].FColor
:= Color
;
893 if gPlayers
[a
].FTeam
in [TEAM_RED
, TEAM_BLUE
] then
894 gPlayers
[a
].FModel
.Color
:= TEAMCOLOR
[gPlayers
[a
].FTeam
]
896 gPlayers
[a
].FModel
.Color
:= Color
;
898 gPlayers
[a
].FUID
:= g_CreateUID(UID_PLAYER
);
899 gPlayers
[a
].FAlive
:= False;
901 Result
:= gPlayers
[a
].FUID
;
904 function g_Player_CreateFromState (st
: TStream
): Word;
905 var a
: Integer; ok
, Bot
: Boolean; pos
: Int64;
909 // check signature and entity type
911 if not utils
.checkSign(st
, 'PLYR') then raise XStreamError
.Create('invalid player signature');
912 if (utils
.readByte(st
) <> PLR_SAVE_VERSION
) then raise XStreamError
.Create('invalid player version');
913 Bot
:= utils
.readBool(st
);
916 // find free player slot
918 for a
:= 0 to High(gPlayers
) do
919 if gPlayers
[a
] = nil then
925 // allocate player slot
928 SetLength(gPlayers
, Length(gPlayers
)+1);
932 // create entity and load state
935 gPlayers
[a
] := TBot
.Create();
936 if (g_Force_Model_Get() <> 0) then
937 gPlayers
[a
].SetModel(g_Forced_Model_GetName());
940 gPlayers
[a
] := TPlayer
.Create();
941 gPlayers
[a
].FPhysics
:= True; // ???
942 gPlayers
[a
].LoadState(st
);
944 result
:= gPlayers
[a
].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 gPlayers
[a
].ChangeTeam(TEAM_RED
)
969 gPlayers
[a
].ChangeTeam(TEAM_BLUE
);
972 gPlayers
[a
].ChangeTeam(TEAM_COOP
);
976 procedure g_Bot_Add(Team
, Difficult
: Byte; Handicap
: Integer = 100);
979 _name
, _model
: String;
982 if not g_Game_IsServer
then Exit
;
984 // Íå äîáàâëÿåì áîòîâ åñëè ëèìèò óæå äîñòèãíóò
985 if (g_Bot_GetCount() >= gMaxBots
) then Exit
;
987 // Ñïèñîê íàçâàíèé ìîäåëåé:
988 m
:= g_PlayerModel_GetNames();
993 if (gGameSettings
.GameType
= GT_SINGLE
) or (gGameSettings
.GameMode
= GM_COOP
) then
994 Team
:= TEAM_COOP
// COOP
996 if gGameSettings
.GameMode
= GM_DM
then
997 Team
:= TEAM_NONE
// DM
999 if Team
= TEAM_NONE
then // CTF / TDM
1001 // Àâòîáàëàíñ êîìàíä:
1005 for a
:= 0 to High(gPlayers
) do
1006 if gPlayers
[a
] <> nil then
1008 if gPlayers
[a
].Team
= TEAM_RED
then
1011 if gPlayers
[a
].Team
= TEAM_BLUE
then
1021 if Random(2) = 0 then
1027 // Âûáèðàåì áîòó èìÿ:
1029 if BotNames
<> nil then
1030 for a
:= 0 to High(BotNames
) do
1031 if g_Player_ExistingName(BotNames
[a
]) then
1033 _name
:= BotNames
[a
];
1037 // Âûáèðàåì ñëó÷àéíóþ ìîäåëü:
1038 _model
:= m
[Random(Length(m
))];
1041 with g_Player_Get(g_Player_Create(_model
,
1042 _RGB(Min(Random(9)*32, 255),
1043 Min(Random(9)*32, 255),
1044 Min(Random(9)*32, 255)),
1045 Team
, True)) as TBot
do
1047 // Åñëè èìåíè íåò, äåëàåì åãî èç UID áîòà
1049 Name
:= Format('DFBOT%.5d', [UID
])
1054 1: FDifficult
:= DIFFICULT_EASY
;
1055 2: FDifficult
:= DIFFICULT_MEDIUM
;
1056 else FDifficult
:= DIFFICULT_HARD
;
1059 for a
:= WP_FIRST
to WP_LAST
do
1061 FDifficult
.WeaponPrior
[a
] := WEAPON_PRIOR1
[a
];
1062 FDifficult
.CloseWeaponPrior
[a
] := WEAPON_PRIOR2
[a
];
1063 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
1066 FHandicap
:= Handicap
;
1068 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [Name
]), True);
1070 if g_Game_IsNet
then MH_SEND_PlayerCreate(UID
);
1071 if g_Game_IsServer
and (gGameSettings
.MaxLives
> 0) then
1076 procedure g_Bot_AddList(Team
: Byte; lName
: ShortString; num
: Integer = -1; Handicap
: Integer = 100);
1079 _name
, _model
: String;
1082 if not g_Game_IsServer
then Exit
;
1084 // Íå äîáàâëÿåì áîòîâ åñëè ëèìèò óæå äîñòèãíóò
1085 if (g_Bot_GetCount() >= gMaxBots
) then Exit
;
1087 // Ñïèñîê íàçâàíèé ìîäåëåé:
1088 m
:= g_PlayerModel_GetNames();
1093 if (gGameSettings
.GameType
= GT_SINGLE
) or (gGameSettings
.GameMode
= GM_COOP
) then
1094 Team
:= TEAM_COOP
// COOP
1096 if gGameSettings
.GameMode
= GM_DM
then
1097 Team
:= TEAM_NONE
// DM
1099 if Team
= TEAM_NONE
then
1100 Team
:= BotList
[num
].team
; // CTF / TDM
1102 // Âûáèðàåì íàñòðîéêè áîòà èç ñïèñêà ïî íîìåðó èëè èìåíè:
1104 num
:= Random(Length(BotList
))
1107 if (num
< 0) or (num
> Length(BotList
)-1) then
1109 if (num
= -1) and (BotList
<> nil) then
1110 lName
:= AnsiLowerCase(lName
);
1111 for a
:= 0 to High(BotList
) do
1112 if AnsiLowerCase(BotList
[a
].name
) = lName
then
1122 _name
:= BotList
[num
].name
;
1123 if (_name
= '') and (BotNames
<> nil) then
1124 for a
:= 0 to High(BotNames
) do
1125 if g_Player_ExistingName(BotNames
[a
]) then
1127 _name
:= BotNames
[a
];
1132 _model
:= BotList
[num
].model
;
1133 // Íåò òàêîé - âûáèðàåì ñëó÷àéíóþ:
1134 if not InSArray(_model
, m
) then
1135 _model
:= m
[Random(Length(m
))];
1138 with g_Player_Get(g_Player_Create(_model
, BotList
[num
].color
, Team
, True)) as TBot
do
1140 // Åñëè èìåíè íåò, äåëàåì åãî èç UID áîòà
1142 then Name
:= Format('DFBOT%.5d', [UID
])
1145 FDifficult
.DiagFire
:= BotList
[num
].diag_fire
;
1146 FDifficult
.InvisFire
:= BotList
[num
].invis_fire
;
1147 FDifficult
.DiagPrecision
:= BotList
[num
].diag_precision
;
1148 FDifficult
.FlyPrecision
:= BotList
[num
].fly_precision
;
1149 FDifficult
.Cover
:= BotList
[num
].cover
;
1150 FDifficult
.CloseJump
:= BotList
[num
].close_jump
;
1152 FHandicap
:= Handicap
;
1154 for a
:= WP_FIRST
to WP_LAST
do
1156 FDifficult
.WeaponPrior
[a
] := BotList
[num
].w_prior1
[a
];
1157 FDifficult
.CloseWeaponPrior
[a
] := BotList
[num
].w_prior2
[a
];
1158 //FDifficult.SafeWeaponPrior[a] := BotList[num].w_prior3[a];
1161 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [Name
]), True);
1163 if g_Game_IsNet
then MH_SEND_PlayerCreate(UID
);
1167 procedure g_Bot_RemoveAll();
1171 if not g_Game_IsServer
then Exit
;
1172 if gPlayers
= nil then Exit
;
1174 for a
:= 0 to High(gPlayers
) do
1175 if gPlayers
[a
] <> nil then
1176 if gPlayers
[a
] is TBot
then
1178 gPlayers
[a
].Lives
:= 0;
1179 gPlayers
[a
].Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
1180 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [gPlayers
[a
].Name
]), True);
1181 g_Player_Remove(gPlayers
[a
].FUID
);
1187 procedure g_Bot_MixNames();
1192 if BotNames
<> nil then
1193 for a
:= 0 to High(BotNames
) do
1195 b
:= Random(Length(BotNames
));
1197 Botnames
[a
] := BotNames
[b
];
1202 procedure g_Player_Remove(UID
: Word);
1206 if gPlayers
= nil then Exit
;
1208 if g_Game_IsServer
and g_Game_IsNet
then
1209 MH_SEND_PlayerDelete(UID
);
1211 for i
:= 0 to High(gPlayers
) do
1212 if gPlayers
[i
] <> nil then
1213 if gPlayers
[i
].FUID
= UID
then
1215 if gPlayers
[i
] is TPlayer
then
1216 TPlayer(gPlayers
[i
]).Free()
1218 TBot(gPlayers
[i
]).Free();
1224 procedure g_Player_Init();
1236 path
:= BOTNAMES_FILENAME
;
1237 if e_FindResource(DataDirs
, path
) then
1239 // ×èòàåì âîçìîæíûå èìåíà áîòîâ èç ôàéëà:
1240 AssignFile(F
, path
);
1251 SetLength(BotNames
, Length(BotNames
)+1);
1252 BotNames
[High(BotNames
)] := s
;
1261 path
:= BOTLIST_FILENAME
;
1262 if e_FindResource(DataDirs
, path
) then
1264 // ×èòàåì ôàéë ñ ïàðàìåòðàìè áîòîâ:
1265 config
:= TConfig
.CreateFile(path
);
1268 while config
.SectionExists(IntToStr(a
)) do
1270 SetLength(BotList
, Length(BotList
)+1);
1272 with BotList
[High(BotList
)] do
1274 name
:= config
.ReadStr(IntToStr(a
), 'name', ''); // Èìÿ áîòà
1275 model
:= config
.ReadStr(IntToStr(a
), 'model', ''); // Ìîäåëü
1278 s
:= config
.ReadStr(IntToStr(a
), 'team', '');
1281 else if s
= 'blue' then
1287 sa
:= parse(config
.ReadStr(IntToStr(a
), 'color', ''));
1289 color
.R
:= StrToIntDef(sa
[0], 0);
1290 color
.G
:= StrToIntDef(sa
[1], 0);
1291 color
.B
:= StrToIntDef(sa
[2], 0);
1293 diag_fire
:= config
.ReadInt(IntToStr(a
), 'diag_fire', 0); // Âåðîÿòíîñòü ñòðåëüáû ïîä óãëîì
1294 invis_fire
:= config
.ReadInt(IntToStr(a
), 'invis_fire', 0); // Âåðîÿòíîñòü îòâåòíîãî îãíÿ ïî íåâèäèìîìó ñîïåðíèêó
1295 diag_precision
:= config
.ReadInt(IntToStr(a
), 'diag_precision', 0); // Òî÷íîñòü ñòðåëüáû ïîä óãëîì
1296 fly_precision
:= config
.ReadInt(IntToStr(a
), 'fly_precision', 0); // Òî÷íîñòü ñòðåëüáû â ïîëåòå
1297 cover
:= config
.ReadInt(IntToStr(a
), 'cover', 0); // Òî÷íîñòü óêëîíåíèÿ îò ñíàðÿäîâ
1298 close_jump
:= config
.ReadInt(IntToStr(a
), 'close_jump', 0); // Âåðîÿòíîñòü ïðûæêà ïðè ïðèáëèæåíèè ñîïåðíèêà
1300 // Ïðèîðèòåòû îðóæèÿ äëÿ äàëüíåãî áîÿ
1301 sa
:= parse(config
.ReadStr(IntToStr(a
), 'w_prior1', ''));
1302 if Length(sa
) = 10 then
1304 w_prior1
[b
] := EnsureRange(StrToInt(sa
[b
]), 0, 9);
1306 // Ïðèîðèòåòû îðóæèÿ äëÿ áëèæíåãî áîÿ
1307 sa
:= parse(config
.ReadStr(IntToStr(a
), 'w_prior2', ''));
1308 if Length(sa
) = 10 then
1310 w_prior2
[b
] := EnsureRange(StrToInt(sa
[b
]), 0, 9);
1312 {sa := parse(config.ReadStr(IntToStr(a), 'w_prior3', ''));
1313 if Length(sa) = 10 then
1315 w_prior3[b] := EnsureRange(StrToInt(sa[b]), 0, 9);}
1324 SetLength(SavedStates
, 0);
1327 procedure g_Player_Free();
1331 if gPlayers
<> nil then
1333 for i
:= 0 to High(gPlayers
) do
1334 if gPlayers
[i
] <> nil then
1336 if gPlayers
[i
] is TPlayer
then
1337 TPlayer(gPlayers
[i
]).Free()
1339 TBot(gPlayers
[i
]).Free();
1348 SetLength(SavedStates
, 0);
1351 procedure g_Player_PreUpdate();
1355 if gPlayers
= nil then Exit
;
1356 for i
:= 0 to High(gPlayers
) do
1357 if gPlayers
[i
] <> nil then
1358 gPlayers
[i
].PreUpdate();
1361 procedure g_Player_UpdateAll();
1365 if gPlayers
= nil then Exit
;
1367 //e_WriteLog('***g_Player_UpdateAll: ENTER', MSG_WARNING);
1368 for i
:= 0 to High(gPlayers
) do
1370 if gPlayers
[i
] <> nil then
1372 if gPlayers
[i
] is TPlayer
then
1374 gPlayers
[i
].Update();
1375 gPlayers
[i
].RealizeCurrentWeapon(); // WARNING! DO NOT MOVE THIS INTO `Update()`!
1379 // bot updates weapons in `UpdateCombat()`
1380 TBot(gPlayers
[i
]).Update();
1384 //e_WriteLog('***g_Player_UpdateAll: EXIT', MSG_WARNING);
1387 procedure g_Player_DrawAll();
1391 if gPlayers
= nil then Exit
;
1393 for i
:= 0 to High(gPlayers
) do
1394 if gPlayers
[i
] <> nil then
1395 if gPlayers
[i
] is TPlayer
then gPlayers
[i
].Draw()
1396 else TBot(gPlayers
[i
]).Draw();
1399 procedure g_Player_DrawDebug(p
: TPlayer
);
1403 if p
= nil then Exit
;
1404 if (@p
.FObj
) = nil then Exit
;
1406 e_TextureFontGetSize(gStdFont
, fW
, fH
);
1408 e_TextureFontPrint(0, 0 , 'Pos X: ' + IntToStr(p
.FObj
.X
), gStdFont
);
1409 e_TextureFontPrint(0, fH
, 'Pos Y: ' + IntToStr(p
.FObj
.Y
), gStdFont
);
1410 e_TextureFontPrint(0, fH
* 2, 'Vel X: ' + IntToStr(p
.FObj
.Vel
.X
), gStdFont
);
1411 e_TextureFontPrint(0, fH
* 3, 'Vel Y: ' + IntToStr(p
.FObj
.Vel
.Y
), gStdFont
);
1412 e_TextureFontPrint(0, fH
* 4, 'Acc X: ' + IntToStr(p
.FObj
.Accel
.X
), gStdFont
);
1413 e_TextureFontPrint(0, fH
* 5, 'Acc Y: ' + IntToStr(p
.FObj
.Accel
.Y
), gStdFont
);
1414 e_TextureFontPrint(0, fH
* 6, 'Old X: ' + IntToStr(p
.FObj
.oldX
), gStdFont
);
1415 e_TextureFontPrint(0, fH
* 7, 'Old Y: ' + IntToStr(p
.FObj
.oldY
), gStdFont
);
1418 procedure g_Player_DrawHealth();
1423 if gPlayers
= nil then Exit
;
1424 e_TextureFontGetSize(gStdFont
, fW
, fH
);
1426 for i
:= 0 to High(gPlayers
) do
1427 if gPlayers
[i
] <> nil then
1429 e_TextureFontPrint(gPlayers
[i
].FObj
.X
+ gPlayers
[i
].FObj
.Rect
.X
,
1430 gPlayers
[i
].FObj
.Y
+ gPlayers
[i
].FObj
.Rect
.Y
+ gPlayers
[i
].FObj
.Rect
.Height
- fH
* 2,
1431 IntToStr(gPlayers
[i
].FHealth
), gStdFont
);
1432 e_TextureFontPrint(gPlayers
[i
].FObj
.X
+ gPlayers
[i
].FObj
.Rect
.X
,
1433 gPlayers
[i
].FObj
.Y
+ gPlayers
[i
].FObj
.Rect
.Y
+ gPlayers
[i
].FObj
.Rect
.Height
- fH
,
1434 IntToStr(gPlayers
[i
].FArmor
), gStdFont
);
1438 function g_Player_Get(UID
: Word): TPlayer
;
1444 if gPlayers
= nil then
1447 for a
:= 0 to High(gPlayers
) do
1448 if gPlayers
[a
] <> nil then
1449 if gPlayers
[a
].FUID
= UID
then
1451 Result
:= gPlayers
[a
];
1456 function g_Player_GetCount(): Byte;
1462 if gPlayers
= nil then
1465 for a
:= 0 to High(gPlayers
) do
1466 if gPlayers
[a
] <> nil then
1467 Result
:= Result
+ 1;
1470 function g_Bot_GetCount(): Integer;
1476 if gPlayers
= nil then
1479 for a
:= 0 to High(gPlayers
) do
1480 if (gPlayers
[a
] <> nil) and (gPlayers
[a
] is TBot
) then
1481 Result
:= Result
+ 1;
1484 function g_Player_GetStats(): TPlayerStatArray
;
1490 if gPlayers
= nil then Exit
;
1492 for a
:= 0 to High(gPlayers
) do
1493 if gPlayers
[a
] <> nil then
1495 SetLength(Result
, Length(Result
)+1);
1496 with Result
[High(Result
)] do
1499 Ping
:= gPlayers
[a
].FPing
;
1500 Loss
:= gPlayers
[a
].FLoss
;
1501 Name
:= gPlayers
[a
].FName
;
1502 Team
:= gPlayers
[a
].FTeam
;
1503 Frags
:= gPlayers
[a
].FFrags
;
1504 Assists
:= gPlayers
[a
].FAssists
;
1505 Deaths
:= gPlayers
[a
].FDeath
;
1506 Kills
:= gPlayers
[a
].FKills
;
1507 Color
:= gPlayers
[a
].FModel
.Color
;
1508 Lives
:= gPlayers
[a
].FLives
;
1509 Spectator
:= gPlayers
[a
].FSpectator
;
1510 UID
:= gPlayers
[a
].FUID
;
1515 procedure g_Player_ResetReady();
1519 if not g_Game_IsServer
then Exit
;
1520 if gPlayers
= nil then Exit
;
1522 for a
:= 0 to High(gPlayers
) do
1523 if gPlayers
[a
] <> nil then
1525 gPlayers
[a
].FReady
:= False;
1526 if g_Game_IsNet
then
1527 MH_SEND_GameEvent(NET_EV_INTER_READY
, gPlayers
[a
].UID
, 'N');
1531 procedure g_Player_RememberAll
;
1535 for i
:= Low(gPlayers
) to High(gPlayers
) do
1536 if (gPlayers
[i
] <> nil) and gPlayers
[i
].alive
then
1537 gPlayers
[i
].RememberState
;
1540 procedure g_Player_ResetAll(Force
, Silent
: Boolean);
1544 gTeamStat
[TEAM_RED
].Score
:= 0;
1545 gTeamStat
[TEAM_BLUE
].Score
:= 0;
1547 if gPlayers
<> nil then
1548 for i
:= 0 to High(gPlayers
) do
1549 if gPlayers
[i
] <> nil then
1551 gPlayers
[i
].Reset(Force
);
1553 if gPlayers
[i
] is TPlayer
then
1555 if (not gPlayers
[i
].FSpectator
) or gPlayers
[i
].FWantsInGame
then
1556 gPlayers
[i
].Respawn(Silent
)
1558 gPlayers
[i
].Spectate();
1561 TBot(gPlayers
[i
]).Respawn(Silent
);
1565 function g_Player_CreateCorpse(Player
: TPlayer
): Integer;
1573 if Player
.alive
then
1576 // Ðàçðûâàåì ñâÿçü ñ ïðåæíèì òðóïîì:
1577 i
:= Player
.FCorpse
;
1578 if (i
>= 0) and (i
< Length(gCorpses
)) then
1580 if (gCorpses
[i
] <> nil) and (gCorpses
[i
].FPlayerUID
= Player
.FUID
) then
1581 gCorpses
[i
].FPlayerUID
:= 0;
1584 if Player
.FObj
.Y
>= gMapInfo
.Height
+128 then
1589 if (FHealth
>= -50) or (gGibsCount
= 0) then
1591 if (gCorpses
= nil) or (Length(gCorpses
) = 0) then
1595 for find_id
:= 0 to High(gCorpses
) do
1596 if gCorpses
[find_id
] = nil then
1603 find_id
:= Random(Length(gCorpses
));
1605 gCorpses
[find_id
] := TCorpse
.Create(FObj
.X
, FObj
.Y
, FModel
.Name
, FHealth
< -20);
1606 gCorpses
[find_id
].FColor
:= FModel
.Color
;
1607 gCorpses
[find_id
].FObj
.Vel
:= FObj
.Vel
;
1608 gCorpses
[find_id
].FObj
.Accel
:= FObj
.Accel
;
1609 gCorpses
[find_id
].FPlayerUID
:= FUID
;
1614 g_Player_CreateGibs(FObj
.X
+ PLAYER_RECT_CX
,
1615 FObj
.Y
+ PLAYER_RECT_CY
,
1616 FModel
.Name
, FModel
.Color
);
1620 procedure g_Player_CreateShell(fX
, fY
, dX
, dY
: Integer; T
: Byte);
1624 if (gShells
= nil) or (Length(gShells
) = 0) then
1627 with gShells
[CurrentShell
] do
1633 if T
= SHELL_BULLET
then
1635 if g_Texture_Get('TEXTURE_SHELL_BULLET', SID
) then
1639 Obj
.Rect
.Width
:= 4;
1640 Obj
.Rect
.Height
:= 2;
1644 if g_Texture_Get('TEXTURE_SHELL_SHELL', SID
) then
1648 Obj
.Rect
.Width
:= 7;
1649 Obj
.Rect
.Height
:= 3;
1655 g_Obj_Push(@Obj
, dX
+ Random(4)-Random(4), dY
-Random(4));
1656 positionChanged(); // this updates spatial accelerators
1657 RAngle
:= Random(360);
1658 Timeout
:= gTime
+ SHELL_TIMEOUT
;
1660 if CurrentShell
>= High(gShells
) then
1667 procedure g_Player_CreateGibs(fX
, fY
: Integer; ModelName
: string; fColor
: TRGB
);
1670 GibsArray
: TGibsArray
;
1673 if (gGibs
= nil) or (Length(gGibs
) = 0) then
1675 if not g_PlayerModel_GetGibs(ModelName
, GibsArray
) then
1677 Blood
:= g_PlayerModel_GetBlood(ModelName
);
1679 for a
:= 0 to High(GibsArray
) do
1680 with gGibs
[CurrentGib
] do
1683 ID
:= GibsArray
[a
].ID
;
1684 MaskID
:= GibsArray
[a
].MaskID
;
1687 Obj
.Rect
:= GibsArray
[a
].Rect
;
1688 Obj
.X
:= fX
-GibsArray
[a
].Rect
.X
-(GibsArray
[a
].Rect
.Width
div 2);
1689 Obj
.Y
:= fY
-GibsArray
[a
].Rect
.Y
-(GibsArray
[a
].Rect
.Height
div 2);
1690 g_Obj_PushA(@Obj
, 25 + Random(10), Random(361));
1691 positionChanged(); // this updates spatial accelerators
1692 RAngle
:= Random(360);
1694 if gBloodCount
> 0 then
1695 g_GFX_Blood(fX
, fY
, 16*gBloodCount
+Random(5*gBloodCount
), -16+Random(33), -16+Random(33),
1696 Random(48), Random(48), Blood
.R
, Blood
.G
, Blood
.B
, Blood
.Kind
);
1698 if CurrentGib
>= High(gGibs
) then
1705 procedure g_Player_UpdatePhysicalObjects();
1711 procedure ShellSound_Bounce(X
, Y
: Integer; T
: Byte);
1716 if T
= SHELL_BULLET
then
1717 g_Sound_PlayExAt('SOUND_PLAYER_CASING' + IntToStr(k
), X
, Y
)
1719 g_Sound_PlayExAt('SOUND_PLAYER_SHELL' + IntToStr(k
), X
, Y
);
1724 if gGibs
<> nil then
1725 for i
:= 0 to High(gGibs
) do
1726 if gGibs
[i
].alive
then
1733 mr
:= g_Obj_Move(@Obj
, True, False, True);
1734 positionChanged(); // this updates spatial accelerators
1736 if WordBool(mr
and MOVE_FALLOUT
) then
1742 // Îòëåòàåò îò óäàðà î ñòåíó/ïîòîëîê/ïîë:
1743 if WordBool(mr
and MOVE_HITWALL
) then
1744 Obj
.Vel
.X
:= -(vel
.X
div 2);
1745 if WordBool(mr
and (MOVE_HITCEIL
or MOVE_HITLAND
)) then
1746 Obj
.Vel
.Y
:= -(vel
.Y
div 2);
1748 if (Obj
.Vel
.X
>= 0) then
1750 RAngle
:= RAngle
+ Abs(Obj
.Vel
.X
)*6 + Abs(Obj
.Vel
.Y
);
1751 if RAngle
>= 360 then
1752 RAngle
:= RAngle
mod 360;
1753 end else begin // Counter-clockwise
1754 RAngle
:= RAngle
- Abs(Obj
.Vel
.X
)*6 - Abs(Obj
.Vel
.Y
);
1756 RAngle
:= (360 - (Abs(RAngle
) mod 360)) mod 360;
1759 // Ñîïðîòèâëåíèå âîçäóõà äëÿ êóñêà òðóïà:
1760 if gTime
mod (GAME_TICK
*3) = 0 then
1761 Obj
.Vel
.X
:= z_dec(Obj
.Vel
.X
, 1);
1765 if gCorpses
<> nil then
1766 for i
:= 0 to High(gCorpses
) do
1767 if gCorpses
[i
] <> nil then
1768 if gCorpses
[i
].State
= CORPSE_STATE_REMOVEME
then
1774 gCorpses
[i
].Update();
1777 if gShells
<> nil then
1778 for i
:= 0 to High(gShells
) do
1779 if gShells
[i
].alive
then
1786 mr
:= g_Obj_Move(@Obj
, True, False, True);
1787 positionChanged(); // this updates spatial accelerators
1789 if WordBool(mr
and MOVE_FALLOUT
) or (gShells
[i
].Timeout
< gTime
) then
1795 // Îòëåòàåò îò óäàðà î ñòåíó/ïîòîëîê/ïîë:
1796 if WordBool(mr
and MOVE_HITWALL
) then
1798 Obj
.Vel
.X
:= -(vel
.X
div 2);
1799 if not WordBool(mr
and MOVE_INWATER
) then
1800 ShellSound_Bounce(Obj
.X
, Obj
.Y
, SType
);
1802 if WordBool(mr
and (MOVE_HITCEIL
or MOVE_HITLAND
)) then
1804 Obj
.Vel
.Y
:= -(vel
.Y
div 2);
1805 if Obj
.Vel
.X
<> 0 then Obj
.Vel
.X
:= Obj
.Vel
.X
div 2;
1806 if (Obj
.Vel
.X
= 0) and (Obj
.Vel
.Y
= 0) then
1808 if RAngle
mod 90 <> 0 then
1809 RAngle
:= (RAngle
div 90) * 90;
1811 else if not WordBool(mr
and MOVE_INWATER
) then
1812 ShellSound_Bounce(Obj
.X
, Obj
.Y
, SType
);
1815 if (Obj
.Vel
.X
>= 0) then
1817 RAngle
:= RAngle
+ Abs(Obj
.Vel
.X
)*8 + Abs(Obj
.Vel
.Y
);
1818 if RAngle
>= 360 then
1819 RAngle
:= RAngle
mod 360;
1820 end else begin // Counter-clockwise
1821 RAngle
:= RAngle
- Abs(Obj
.Vel
.X
)*8 - Abs(Obj
.Vel
.Y
);
1823 RAngle
:= (360 - (Abs(RAngle
) mod 360)) mod 360;
1829 procedure TGib
.getMapBox (out x
, y
, w
, h
: Integer); inline;
1831 x
:= Obj
.X
+Obj
.Rect
.X
;
1832 y
:= Obj
.Y
+Obj
.Rect
.Y
;
1833 w
:= Obj
.Rect
.Width
;
1834 h
:= Obj
.Rect
.Height
;
1837 procedure TGib
.moveBy (dx
, dy
: Integer); inline;
1839 if (dx
<> 0) or (dy
<> 0) then
1848 procedure TShell
.getMapBox (out x
, y
, w
, h
: Integer); inline;
1852 w
:= Obj
.Rect
.Width
;
1853 h
:= Obj
.Rect
.Height
;
1856 procedure TShell
.moveBy (dx
, dy
: Integer); inline;
1858 if (dx
<> 0) or (dy
<> 0) then
1867 procedure TGib
.positionChanged (); inline; begin end;
1868 procedure TShell
.positionChanged (); inline; begin end;
1871 procedure g_Player_DrawCorpses();
1876 if gGibs
<> nil then
1877 for i
:= 0 to High(gGibs
) do
1878 if gGibs
[i
].alive
then
1881 if not g_Obj_Collide(sX
, sY
, sWidth
, sHeight
, @Obj
) then
1884 Obj
.lerp(gLerpFactor
, fX
, fY
);
1886 a
.X
:= Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2);
1887 a
.y
:= Obj
.Rect
.Y
+(Obj
.Rect
.Height
div 2);
1889 e_DrawAdv(ID
, fX
, fY
, 0, True, False, RAngle
, @a
, TMirrorType
.None
);
1892 e_DrawAdv(MaskID
, fX
, fY
, 0, True, False, RAngle
, @a
, TMirrorType
.None
);
1898 if gCorpses
<> nil then
1899 for i
:= 0 to High(gCorpses
) do
1900 if gCorpses
[i
] <> nil then
1904 procedure g_Player_DrawShells();
1909 if gShells
<> nil then
1910 for i
:= 0 to High(gShells
) do
1911 if gShells
[i
].alive
then
1914 if not g_Obj_Collide(sX
, sY
, sWidth
, sHeight
, @Obj
) then
1917 Obj
.lerp(gLerpFactor
, fX
, fY
);
1922 e_DrawAdv(SpriteID
, fX
, fY
, 0, True, False, RAngle
, @a
, TMirrorType
.None
);
1926 procedure g_Player_RemoveAllCorpses();
1932 SetLength(gGibs
, MaxGibs
);
1933 SetLength(gShells
, MaxGibs
);
1937 if gCorpses
<> nil then
1938 for i
:= 0 to High(gCorpses
) do
1942 SetLength(gCorpses
, MaxCorpses
);
1945 procedure g_Player_Corpses_SaveState (st
: TStream
);
1949 // Ñ÷èòàåì êîëè÷åñòâî ñóùåñòâóþùèõ òðóïîâ
1951 for i
:= 0 to High(gCorpses
) do if (gCorpses
[i
] <> nil) then Inc(count
);
1953 // Êîëè÷åñòâî òðóïîâ
1954 utils
.writeInt(st
, LongInt(count
));
1956 if (count
= 0) then exit
;
1959 for i
:= 0 to High(gCorpses
) do
1961 if gCorpses
[i
] <> nil then
1964 utils
.writeStr(st
, gCorpses
[i
].FModelName
);
1966 utils
.writeBool(st
, gCorpses
[i
].Mess
);
1967 // Ñîõðàíÿåì äàííûå òðóïà:
1968 gCorpses
[i
].SaveState(st
);
1974 procedure g_Player_Corpses_LoadState (st
: TStream
);
1982 g_Player_RemoveAllCorpses();
1984 // Êîëè÷åñòâî òðóïîâ:
1985 count
:= utils
.readLongInt(st
);
1986 if (count
< 0) or (count
> Length(gCorpses
)) then raise XStreamError
.Create('invalid number of corpses');
1988 if (count
= 0) then exit
;
1991 for i
:= 0 to count
-1 do
1994 str
:= utils
.readStr(st
);
1996 b
:= utils
.readBool(st
);
1998 gCorpses
[i
] := TCorpse
.Create(0, 0, str
, b
);
1999 // Çàãðóæàåì äàííûå òðóïà
2000 gCorpses
[i
].LoadState(st
);
2007 function TPlayer
.isValidViewPort (): Boolean; inline; begin result
:= (viewPortW
> 0) and (viewPortH
> 0); end;
2009 procedure TPlayer
.BFGHit();
2011 g_Weapon_BFGHit(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
2012 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2));
2013 if g_Game_IsServer
and g_Game_IsNet
then
2014 MH_SEND_Effect(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
2015 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2),
2019 procedure TPlayer
.ChangeModel(ModelName
: string);
2021 locModel
: TPlayerModel
;
2023 locModel
:= g_PlayerModel_Get(ModelName
);
2024 if locModel
= nil then Exit
;
2030 procedure TPlayer
.SetModel(ModelName
: string);
2034 m
:= g_PlayerModel_Get(ModelName
);
2037 g_SimpleError(Format(_lc
[I_GAME_ERROR_MODEL_FALLBACK
], [ModelName
]));
2038 m
:= g_PlayerModel_Get('doomer');
2041 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], ['doomer']));
2046 if FModel
<> nil then
2051 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
2052 FModel
.Color
:= FColor
2054 FModel
.Color
:= TEAMCOLOR
[FTeam
];
2055 FModel
.SetWeapon(FCurrWeap
);
2056 FModel
.SetFlag(FFlag
);
2057 SetDirection(FDirection
);
2060 procedure TPlayer
.SetColor(Color
: TRGB
);
2063 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
2064 if FModel
<> nil then FModel
.Color
:= Color
;
2069 function TPlayer
.GetColor(): TRGB
;
2071 result
:= FModel
.Color
;
2074 procedure TPlayer
.SetWeaponPrefs(Prefs
: Array of Byte);
2078 for i
:= WP_FIRST
to WP_LAST
+ 1 do
2080 if (Prefs
[i
] > WP_LAST
+ 1) then
2081 FWeapPreferences
[i
] := 0
2083 FWeapPreferences
[i
] := Prefs
[i
];
2087 procedure TPlayer
.SetWeaponPref(Weapon
, Pref
: Byte);
2089 if (Weapon
> WP_LAST
+ 1) then
2091 else if (Pref
<= WP_LAST
+ 1) and (Weapon
<= WP_LAST
+ 1) then
2092 FWeapPreferences
[Weapon
] := Pref
2093 else if (Weapon
<= WP_LAST
+ 1) and (Pref
> WP_LAST
+ 1) then
2094 FWeapPreferences
[Weapon
] := 0;
2097 function TPlayer
.GetWeaponPref(Weapon
: Byte) : Byte;
2099 if (Weapon
> WP_LAST
+ 1) then
2101 else if (FWeapPreferences
[Weapon
] > WP_LAST
+ 1) then
2104 result
:= FWeapPreferences
[Weapon
];
2107 function TPlayer
.GetMorePrefered() : Byte;
2109 testedWeap
, i
: Byte;
2111 testedWeap
:= FCurrWeap
;
2112 for i
:= WP_FIRST
to WP_LAST
do
2113 if FWeapon
[i
] and maySwitch(i
) and (FWeapPreferences
[i
] > FWeapPreferences
[testedWeap
]) then
2115 if (R_BERSERK
in FRulez
) and (FWeapPreferences
[WP_LAST
+ 1] > FWeapPreferences
[testedWeap
]) then
2116 testedWeap
:= WEAPON_KASTET
;
2117 result
:= testedWeap
;
2120 function TPlayer
.maySwitch(Weapon
: Byte) : Boolean;
2123 if (Weapon
= WEAPON_KASTET
) and (FSkipFist
<> 0) then
2125 if (FSkipFist
= 1) and (not (R_BERSERK
in FRulez
)) then
2128 else if (FSwitchToEmpty
= 0) and (not hasAmmoForShooting(Weapon
)) then
2132 procedure TPlayer
.SwitchTeam
;
2134 if g_Game_IsClient
then
2136 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then Exit
;
2138 if gGameOn
and FAlive
then
2139 Kill(K_SIMPLEKILL
, FUID
, HIT_SELF
);
2141 if FTeam
= TEAM_RED
then
2143 ChangeTeam(TEAM_BLUE
);
2144 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_BLUE
], [FName
]), True);
2145 if g_Game_IsNet
then
2146 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM
, TEAM_BLUE
, FName
);
2150 ChangeTeam(TEAM_RED
);
2151 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_RED
], [FName
]), True);
2152 if g_Game_IsNet
then
2153 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM
, TEAM_RED
, FName
);
2155 FPreferredTeam
:= FTeam
;
2158 procedure TPlayer
.ChangeTeam(Team
: Byte);
2165 TEAM_RED
, TEAM_BLUE
:
2166 FModel
.Color
:= TEAMCOLOR
[Team
];
2168 FModel
.Color
:= FColor
;
2170 if (FTeam
<> OldTeam
) and g_Game_IsNet
and g_Game_IsServer
then
2171 MH_SEND_PlayerStats(FUID
);
2175 procedure TPlayer.CollideItem();
2180 if gItems = nil then Exit;
2181 if not FAlive then Exit;
2183 for i := 0 to High(gItems) do
2186 if (ItemType <> ITEM_NONE) and alive then
2187 if g_Obj_Collide(FObj.X+PLAYER_RECT.X, FObj.Y+PLAYER_RECT.Y, PLAYER_RECT.Width,
2188 PLAYER_RECT.Height, @Obj) then
2190 if not PickItem(ItemType, gItems[i].Respawnable, r) then Continue;
2192 if ItemType in [ITEM_SPHERE_BLUE, ITEM_SPHERE_WHITE, ITEM_INVUL] then
2193 g_Sound_PlayExAt('SOUND_ITEM_GETRULEZ', FObj.X, FObj.Y)
2194 else if ItemType in [ITEM_MEDKIT_SMALL, ITEM_MEDKIT_LARGE, ITEM_MEDKIT_BLACK] then
2195 g_Sound_PlayExAt('SOUND_ITEM_GETMED', FObj.X, FObj.Y)
2196 else g_Sound_PlayExAt('SOUND_ITEM_GETITEM', FObj.X, FObj.Y);
2198 // Íàäî óáðàòü ñ êàðòû, åñëè ýòî íå êëþ÷, êîòîðûì íóæíî ïîäåëèòñÿ ñ äðóãèì èãðîêîì:
2199 if r and not ((ItemType in [ITEM_KEY_RED, ITEM_KEY_GREEN, ITEM_KEY_BLUE]) and
2200 (gGameSettings.GameType = GT_SINGLE) and
2201 (g_Player_GetCount() > 1)) then
2202 if not Respawnable then g_Items_Remove(i) else g_Items_Pick(i);
2208 function TPlayer
.CollideLevel(XInc
, YInc
: Integer): Boolean;
2210 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
2211 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_WALL
,
2215 constructor TPlayer
.Create();
2221 mEDamageType
:= HIT_SOME
;
2227 FSawSound
:= TPlayableSound
.Create();
2228 FSawSoundIdle
:= TPlayableSound
.Create();
2229 FSawSoundHit
:= TPlayableSound
.Create();
2230 FSawSoundSelect
:= TPlayableSound
.Create();
2231 FFlameSoundOn
:= TPlayableSound
.Create();
2232 FFlameSoundOff
:= TPlayableSound
.Create();
2233 FFlameSoundWork
:= TPlayableSound
.Create();
2234 FJetSoundFly
:= TPlayableSound
.Create();
2235 FJetSoundOn
:= TPlayableSound
.Create();
2236 FJetSoundOff
:= TPlayableSound
.Create();
2238 FSawSound
.SetByName('SOUND_WEAPON_FIRESAW');
2239 FSawSoundIdle
.SetByName('SOUND_WEAPON_IDLESAW');
2240 FSawSoundHit
.SetByName('SOUND_WEAPON_HITSAW');
2241 FSawSoundSelect
.SetByName('SOUND_WEAPON_SELECTSAW');
2242 FFlameSoundOn
.SetByName('SOUND_WEAPON_FLAMEON');
2243 FFlameSoundOff
.SetByName('SOUND_WEAPON_FLAMEOFF');
2244 FFlameSoundWork
.SetByName('SOUND_WEAPON_FLAMEWORK');
2245 FJetSoundFly
.SetByName('SOUND_PLAYER_JETFLY');
2246 FJetSoundOn
.SetByName('SOUND_PLAYER_JETON');
2247 FJetSoundOff
.SetByName('SOUND_PLAYER_JETOFF');
2249 FSpectatePlayer
:= -1;
2253 FSavedStateNum
:= -1;
2261 FActualModelName
:= 'doomer';
2264 FObj
.Rect
:= PLAYER_RECT
;
2266 FBFGFireCounter
:= -1;
2267 FJustTeleported
:= False;
2270 FWaitForFirstSpawn
:= false;
2275 procedure TPlayer
.positionChanged (); inline;
2279 procedure TPlayer
.doDamage (v
: Integer);
2281 if (v
<= 0) then exit
;
2282 if (v
> 32767) then v
:= 32767;
2283 Damage(v
, 0, 0, 0, mEDamageType
);
2286 procedure TPlayer
.Damage(value
: Word; SpawnerUID
: Word; vx
, vy
: Integer; t
: Byte);
2290 if (not g_Game_IsClient
) and (not FAlive
) then
2295 // Íåóÿçâèìîñòü íå ñïàñàåò îò ëîâóøåê:
2296 if ((t
= HIT_TRAP
) or (t
= HIT_SELF
)) and (not FGodMode
) then
2298 if not g_Game_IsClient
then
2301 if t
= HIT_TRAP
then
2303 // Ëîâóøêà óáèâàåò ñðàçó:
2305 Kill(K_EXTRAHARDKILL
, SpawnerUID
, t
);
2307 if t
= HIT_SELF
then
2311 Kill(K_SIMPLEKILL
, SpawnerUID
, t
);
2314 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
2315 FMegaRulez
[MR_SUIT
] := 0;
2316 FMegaRulez
[MR_INVUL
] := 0;
2317 FMegaRulez
[MR_INVIS
] := 0;
2322 // Íî îò îñòàëüíîãî ñïàñàåò:
2323 if FMegaRulez
[MR_INVUL
] >= gTime
then
2330 // Åñëè åñòü óðîí ñâîèì, èëè ðàíèë ñàì ñåáÿ, èëè òåáÿ ðàíèë ïðîòèâíèê:
2331 if LongBool(gGameSettings
.Options
and GAME_OPTION_TEAMDAMAGE
) or
2332 (SpawnerUID
= FUID
) or
2333 (not SameTeam(FUID
, SpawnerUID
)) then
2335 FLastSpawnerUID
:= SpawnerUID
;
2337 // Êðîâü (ïóçûðüêè, åñëè â âîäå):
2338 if gBloodCount
> 0 then
2340 c
:= Min(value
, 200)*gBloodCount
+ Random(Min(value
, 200) div 2);
2341 if value
div 4 <= c
then
2342 c
:= c
- (value
div 4)
2346 if (t
= HIT_SOME
) and (vx
= 0) and (vy
= 0) then
2350 HIT_TRAP
, HIT_ACID
, HIT_FLAME
, HIT_SELF
: MakeBloodSimple(c
);
2351 HIT_BFG
, HIT_ROCKET
, HIT_SOME
: MakeBloodVector(c
, vx
, vy
);
2354 if t
= HIT_WATER
then
2355 g_Game_Effect_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
2356 FObj
.Y
+PLAYER_RECT
.Y
-4, value
div 2, 8, 4);
2361 Inc(FDamageBuffer
, value
);
2365 FPain
:= FPain
+ value
;
2368 if g_Game_IsServer
and g_Game_IsNet
then
2370 MH_SEND_PlayerDamage(FUID
, t
, SpawnerUID
, value
, vx
, vy
);
2371 MH_SEND_PlayerStats(FUID
);
2372 MH_SEND_PlayerPos(False, FUID
);
2376 function TPlayer
.Heal(value
: Word; Soft
: Boolean): Boolean;
2379 if g_Game_IsClient
then
2384 if Soft
and (FHealth
< PLAYER_HP_SOFT
) then
2386 IncMax(FHealth
, value
, PLAYER_HP_SOFT
);
2389 if (not Soft
) and (FHealth
< PLAYER_HP_LIMIT
) then
2391 IncMax(FHealth
, value
, PLAYER_HP_LIMIT
);
2395 if Result
and g_Game_IsServer
and g_Game_IsNet
then
2396 MH_SEND_PlayerStats(FUID
);
2399 destructor TPlayer
.Destroy();
2401 if (gPlayer1
<> nil) and (gPlayer1
.FUID
= FUID
) then
2403 if (gPlayer2
<> nil) and (gPlayer2
.FUID
= FUID
) then
2407 FSawSoundIdle
.Free();
2408 FSawSoundHit
.Free();
2409 FSawSoundSelect
.Free();
2410 FFlameSoundOn
.Free();
2411 FFlameSoundOff
.Free();
2412 FFlameSoundWork
.Free();
2413 FJetSoundFly
.Free();
2415 FJetSoundOff
.Free();
2417 if FPunchAnim
<> nil then
2423 procedure TPlayer
.DrawIndicator(Color
: TRGB
);
2425 indX
, indY
, fX
, fY
, fSlope
: Integer;
2435 FObj
.lerp(gLerpFactor
, fX
, fY
);
2436 fSlope
:= nlerp(FSlopeOld
, FObj
.slopeUpLeft
, gLerpFactor
);
2438 case gPlayerIndicatorStyle
of
2441 if g_Texture_Get('TEXTURE_PLAYER_INDICATOR', ID
) then
2443 e_GetTextureSize(ID
, @indW
, @indH
);
2447 if (FObj
.X
+ FObj
.Rect
.X
) < 0 then
2450 indX
:= fX
+ FObj
.Rect
.X
+ FObj
.Rect
.Width
;
2451 indY
:= fY
+ FObj
.Rect
.Y
+ (FObj
.Rect
.Height
- indW
) div 2;
2454 else if (FObj
.X
+ FObj
.Rect
.X
+ FObj
.Rect
.Width
) > Max(gMapInfo
.Width
, gPlayerScreenSize
.X
) then
2457 indX
:= fX
+ FObj
.Rect
.X
- indH
;
2458 indY
:= fY
+ FObj
.Rect
.Y
+ (FObj
.Rect
.Height
- indW
) div 2;
2461 else if (FObj
.Y
- indH
) < 0 then
2464 indX
:= fX
+ FObj
.Rect
.X
+ (FObj
.Rect
.Width
- indW
) div 2;
2465 indY
:= fY
+ FObj
.Rect
.Y
+ FObj
.Rect
.Height
;
2471 indX
:= fX
+ FObj
.Rect
.X
+ (FObj
.Rect
.Width
- indW
) div 2;
2475 indY
:= indY
+ fSlope
;
2476 indX
:= EnsureRange(indX
, 0, Max(gMapInfo
.Width
, gPlayerScreenSize
.X
) - indW
);
2477 indY
:= EnsureRange(indY
, 0, Max(gMapInfo
.Height
, gPlayerScreenSize
.Y
) - indH
);
2481 e_DrawAdv(ID
, indX
, indY
, 0, True, False, indA
, @a
);
2488 e_TextureFontGetSize(gStdFont
, nW
, nH
);
2489 indX
:= fX
+ FObj
.Rect
.X
+ (FObj
.Rect
.Width
- Length(FName
) * nW
) div 2;
2490 indY
:= fY
- nH
+ fSlope
;
2491 e_TextureFontPrintEx(indX
, indY
, FName
, gStdFont
, Color
.R
, Color
.G
, Color
.B
, 1.0, True);
2497 procedure TPlayer
.DrawBubble();
2499 bubX
, bubY
, fX
, fY
: Integer;
2502 Rw
, Gw
, Bw
: SmallInt;
2506 CObj
:= getCameraObj();
2507 CObj
.lerp(gLerpFactor
, fX
, fY
);
2508 // NB: _F_Obj.Rect is used to keep the bubble higher; this is not a mistake
2509 bubX
:= fX
+FObj
.Rect
.X
+ IfThen(FDirection
= TDirection
.D_LEFT
, -4, 18);
2510 bubY
:= fY
+FObj
.Rect
.Y
- 18;
2518 1: // simple textual non-bubble
2520 bubX
:= fX
+FObj
.Rect
.X
- 11;
2521 bubY
:= fY
+FObj
.Rect
.Y
- 17;
2522 e_TextureFontPrint(bubX
, bubY
, '[...]', gStdFont
);
2525 2: // advanced pixel-perfect bubble
2527 if FTeam
= TEAM_RED
then
2530 if FTeam
= TEAM_BLUE
then
2533 3: // colored bubble
2535 Rb
:= FModel
.Color
.R
;
2536 Gb
:= FModel
.Color
.G
;
2537 Bb
:= FModel
.Color
.B
;
2538 Rw
:= Min(Rb
* 2 + 64, 255);
2539 Gw
:= Min(Gb
* 2 + 64, 255);
2540 Bw
:= Min(Bb
* 2 + 64, 255);
2541 if (Abs(Rw
- Rb
) < 32)
2542 or (Abs(Gw
- Gb
) < 32)
2543 or (Abs(Bw
- Bb
) < 32) then
2545 Rb
:= Max(Rw
div 2 - 16, 0);
2546 Gb
:= Max(Gw
div 2 - 16, 0);
2547 Bb
:= Max(Bw
div 2 - 16, 0);
2550 4: // custom textured bubble
2552 if g_Texture_Get('TEXTURE_PLAYER_TALKBUBBLE', ID
) then
2553 if FDirection
= TDirection
.D_RIGHT
then
2554 e_Draw(ID
, bubX
- 6, bubY
- 7, 0, True, False)
2556 e_Draw(ID
, bubX
- 6, bubY
- 7, 0, True, False, TMirrorType
.Horizontal
);
2562 e_DrawQuad(bubX
+ 1, bubY
, bubX
+ 18, bubY
+ 13, Rb
, Gb
, Bb
);
2563 e_DrawQuad(bubX
, bubY
+ 1, bubX
+ 19, bubY
+ 12, Rb
, Gb
, Bb
);
2565 e_DrawFillQuad(bubX
+ 1, bubY
+ 1, bubX
+ 18, bubY
+ 12, Rw
, Gw
, Bw
, 0);
2568 Dot
:= IfThen(FDirection
= TDirection
.D_LEFT
, 14, 5);
2569 e_DrawLine(1, bubX
+ Dot
, bubY
+ 14, bubX
+ Dot
, bubY
+ 16, Rb
, Gb
, Bb
);
2570 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
);
2571 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
);
2572 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
);
2573 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
);
2577 e_DrawFillQuad(bubX
+ Dot
, bubY
+ 8, bubX
+ Dot
+ 1, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2578 e_DrawFillQuad(bubX
+ Dot
+ 3, bubY
+ 8, bubX
+ Dot
+ 4, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2579 e_DrawFillQuad(bubX
+ Dot
+ 6, bubY
+ 8, bubX
+ Dot
+ 7, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2582 procedure TPlayer
.Draw();
2587 Mirror
: TMirrorType
;
2588 fX
, fY
, fSlope
: Integer;
2590 FObj
.lerp(gLerpFactor
, fX
, fY
);
2591 fSlope
:= nlerp(FSlopeOld
, FObj
.slopeUpLeft
, gLerpFactor
);
2595 if Direction
= TDirection
.D_RIGHT
then
2596 Mirror
:= TMirrorType
.None
2598 Mirror
:= TMirrorType
.Horizontal
;
2600 if FPunchAnim
<> nil then
2602 FPunchAnim
.Draw(fX
+IfThen(Direction
= TDirection
.D_LEFT
, 15-FObj
.Rect
.X
, FObj
.Rect
.X
-15),
2603 fY
+fSlope
+FObj
.Rect
.Y
-11, Mirror
);
2604 if FPunchAnim
.played
then
2611 if (FMegaRulez
[MR_INVUL
] > gTime
) and ((gPlayerDrawn
<> Self
) or (FSpawnInvul
>= gTime
)) then
2612 if g_Texture_Get('TEXTURE_PLAYER_INVULPENTA', ID
) then
2614 e_GetTextureSize(ID
, @w
, @h
);
2615 if FDirection
= TDirection
.D_LEFT
then
2616 e_Draw(ID
, fX
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2)-(w
div 2)+4,
2617 fY
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2)-(h
div 2)-7+fSlope
, 0, True, False)
2619 e_Draw(ID
, fX
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2)-(w
div 2)-2,
2620 fY
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2)-(h
div 2)-7+fSlope
, 0, True, False);
2623 if FMegaRulez
[MR_INVIS
] > gTime
then
2625 if (gPlayerDrawn
<> nil) and ((Self
= gPlayerDrawn
) or
2626 ((FTeam
= gPlayerDrawn
.Team
) and (gGameSettings
.GameMode
<> GM_DM
))) then
2628 if (FMegaRulez
[MR_INVIS
] - gTime
) <= 2100 then
2629 dr
:= not Odd((FMegaRulez
[MR_INVIS
] - gTime
) div 300)
2633 FModel
.Draw(fX
, fY
+fSlope
, 200)
2635 FModel
.Draw(fX
, fY
+fSlope
);
2638 FModel
.Draw(fX
, fY
+fSlope
, 254);
2641 FModel
.Draw(fX
, fY
+fSlope
);
2644 if g_debug_Frames
then
2646 e_DrawQuad(FObj
.X
+FObj
.Rect
.X
,
2648 FObj
.X
+FObj
.Rect
.X
+FObj
.Rect
.Width
-1,
2649 FObj
.Y
+FObj
.Rect
.Y
+FObj
.Rect
.Height
-1,
2653 if (gChatBubble
> 0) and (FKeys
[KEY_CHAT
].Pressed
) and not FGhost
then
2654 if (FMegaRulez
[MR_INVIS
] <= gTime
) or ((gPlayerDrawn
<> nil) and ((Self
= gPlayerDrawn
) or
2655 ((FTeam
= gPlayerDrawn
.Team
) and (gGameSettings
.GameMode
<> GM_DM
)))) then
2657 // e_DrawPoint(5, 335, 288, 255, 0, 0); // DL, UR, DL, UR
2658 if gAimLine
and alive
and
2659 ((Self
= gPlayer1
) or (Self
= gPlayer2
)) then
2664 procedure TPlayer
.DrawAim();
2665 procedure drawCast (sz
: Integer; ax0
, ay0
, ax1
, ay1
: Integer);
2670 {$IFDEF ENABLE_HOLMES}
2671 if isValidViewPort
and (self
= gPlayer1
) then
2673 g_Holmes_plrLaser(ax0
, ay0
, ax1
, ay1
);
2677 e_DrawLine(sz
, ax0
, ay0
, ax1
, ay1
, 255, 0, 0, 96);
2678 if (g_Map_traceToNearestWall(ax0
, ay0
, ax1
, ay1
, @ex
, @ey
) <> nil) then
2680 e_DrawLine(sz
, ax0
, ay0
, ex
, ey
, 0, 255, 0, 96);
2684 e_DrawLine(sz
, ax0
, ay0
, ex
, ey
, 0, 0, 255, 96);
2689 wx
, wy
, xx
, yy
: Integer;
2693 wx
:= FObj
.X
+ WEAPONPOINT
[FDirection
].X
+ IfThen(FDirection
= TDirection
.D_LEFT
, 7, -7);
2694 wy
:= FObj
.Y
+ WEAPONPOINT
[FDirection
].Y
;
2703 1: begin // Chainsaw
2710 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2711 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2712 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2713 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2718 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2719 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2720 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2721 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2723 4: begin // Double Shotgun
2726 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2727 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2728 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2729 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2731 5: begin // Chaingun
2734 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2735 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2736 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2737 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2739 6: begin // Rocket Launcher
2742 if angle
= ANGLE_RIGHTUP
then Inc(angle
, 2);
2743 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2744 if angle
= ANGLE_LEFTUP
then Dec(angle
, 2);
2745 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2747 7: begin // Plasmagun
2750 if angle
= ANGLE_RIGHTUP
then Inc(angle
);
2751 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 3);
2752 if angle
= ANGLE_LEFTUP
then Dec(angle
);
2753 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 3);
2758 if angle
= ANGLE_RIGHTUP
then Inc(angle
, 1);
2759 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 2);
2760 if angle
= ANGLE_LEFTUP
then Dec(angle
, 1);
2761 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 2);
2763 9: begin // Super Chaingun
2766 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2767 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2768 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2769 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2772 xx
:= Trunc(Cos(-DegToRad(angle
)) * len
) + wx
;
2773 yy
:= Trunc(Sin(-DegToRad(angle
)) * len
) + wy
;
2774 {$IF DEFINED(D2F_DEBUG)}
2775 drawCast(sz
, wx
, wy
, xx
, yy
);
2777 e_DrawLine(sz
, wx
, wy
, xx
, yy
, 255, 0, 0, 96);
2781 procedure TPlayer
.DrawGUI();
2784 X
, Y
, SY
, a
, p
, m
: Integer;
2788 stat
: TPlayerStatArray
;
2790 X
:= gPlayerScreenSize
.X
;
2791 SY
:= gPlayerScreenSize
.Y
;
2794 if gShowScore
and (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
2796 if gGameSettings
.GameMode
= GM_CTF
then
2800 if gGameSettings
.GameMode
= GM_CTF
then
2802 s
:= 'TEXTURE_PLAYER_REDFLAG';
2803 if gFlags
[FLAG_RED
].State
= FLAG_STATE_CAPTURED
then
2804 s
:= 'TEXTURE_PLAYER_REDFLAG_S';
2805 if gFlags
[FLAG_RED
].State
= FLAG_STATE_DROPPED
then
2806 s
:= 'TEXTURE_PLAYER_REDFLAG_D';
2807 if g_Texture_Get(s
, ID
) then
2808 e_Draw(ID
, X
-16-32, 240-72-4, 0, True, False);
2811 s
:= IntToStr(gTeamStat
[TEAM_RED
].Score
);
2812 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2813 e_CharFont_PrintEx(gMenuFont
, X
-16-a
-tw
, 240-72-4, s
, TEAMCOLOR
[TEAM_RED
]);
2815 if gGameSettings
.GameMode
= GM_CTF
then
2817 s
:= 'TEXTURE_PLAYER_BLUEFLAG';
2818 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_CAPTURED
then
2819 s
:= 'TEXTURE_PLAYER_BLUEFLAG_S';
2820 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_DROPPED
then
2821 s
:= 'TEXTURE_PLAYER_BLUEFLAG_D';
2822 if g_Texture_Get(s
, ID
) then
2823 e_Draw(ID
, X
-16-32, 240-32-4, 0, True, False);
2826 s
:= IntToStr(gTeamStat
[TEAM_BLUE
].Score
);
2827 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2828 e_CharFont_PrintEx(gMenuFont
, X
-16-a
-tw
, 240-32-4, s
, TEAMCOLOR
[TEAM_BLUE
]);
2831 if g_Texture_Get('TEXTURE_PLAYER_HUDBG', ID
) then
2832 e_DrawFill(ID
, X
, 0, 1, (gPlayerScreenSize
.Y
div 256)+IfThen(gPlayerScreenSize
.Y
mod 256 > 0, 1, 0),
2835 if g_Texture_Get('TEXTURE_PLAYER_HUD', ID
) then
2836 e_Draw(ID
, X
+2, Y
, 0, True, False);
2838 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
2842 s
:= IntToStr(Frags
);
2843 t
:= IntToStr(Assists
);
2844 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2845 e_CharFont_PrintEx(gMenuFont
, X
-16-tw
, Y
, s
, _RGB(255, 0, 0));
2851 stat
:= g_Player_GetStats();
2856 for a
:= 0 to High(stat
) do
2857 if stat
[a
].Name
<> Name
then
2859 if stat
[a
].Frags
> m
then m
:= stat
[a
].Frags
;
2860 if stat
[a
].Frags
> Frags
then p
:= p
+1;
2865 s
:= IntToStr(p
)+' / '+IntToStr(Length(stat
))+' ';
2866 if Frags
>= m
then s
:= s
+'+' else s
:= s
+'-';
2867 s
:= s
+IntToStr(Abs(Frags
-m
));
2870 t
:= IntToStr(p
)+' / '+IntToStr(Length(stat
))+' ';
2871 if Assists
>= m
then t
:= t
+'+' else t
:= t
+'-';
2872 t
:= t
+IntToStr(Abs(Assists
-m
));
2874 e_CharFont_GetSize(gMenuSmallFont
, s
, tw
, th
);
2875 e_CharFont_PrintEx(gMenuSmallFont
, X
-16-tw
, Y
+32, s
, _RGB(255, 0, 0));
2878 if gLMSRespawn
> LMS_RESPAWN_NONE
then
2880 s
:= _lc
[I_GAME_WARMUP
];
2881 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2882 s
:= s
+ ': ' + IntToStr((gLMSRespawnTime
- gTime
) div 1000);
2883 e_CharFont_PrintEx(gMenuFont
, X
-64-tw
, SY
-32, s
, _RGB(0, 255, 0));
2885 else if gShowLives
and (gGameSettings
.MaxLives
> 0) then
2887 s
:= IntToStr(Lives
);
2888 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2889 e_CharFont_PrintEx(gMenuFont
, X
-16-tw
, SY
-32, s
, _RGB(0, 255, 0));
2893 e_CharFont_GetSize(gMenuSmallFont
, FName
, tw
, th
);
2894 e_CharFont_PrintEx(gMenuSmallFont
, X
+98-(tw
div 2), Y
+8, FName
, _RGB(255, 0, 0));
2896 if R_BERSERK
in FRulez
then
2897 e_Draw(gItemsTexturesID
[ITEM_MEDKIT_BLACK
], X
+37, Y
+45, 0, True, False)
2899 e_Draw(gItemsTexturesID
[ITEM_MEDKIT_LARGE
], X
+37, Y
+45, 0, True, False);
2901 if g_Texture_Get('TEXTURE_PLAYER_ARMORHUD', ID
) then
2902 e_Draw(ID
, X
+36, Y
+77, 0, True, False);
2904 s
:= IntToStr(IfThen(FHealth
> 0, FHealth
, 0));
2905 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2906 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+40, s
, _RGB(255, 0, 0));
2908 s
:= IntToStr(FArmor
);
2909 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2910 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+68, s
, _RGB(255, 0, 0));
2912 s
:= IntToStr(GetAmmoByWeapon(FCurrWeap
));
2918 ID
:= gItemsTexturesID
[ITEM_WEAPON_KASTET
];
2923 ID
:= gItemsTexturesID
[ITEM_WEAPON_SAW
];
2925 WEAPON_PISTOL
: ID
:= gItemsTexturesID
[ITEM_WEAPON_PISTOL
];
2926 WEAPON_CHAINGUN
: ID
:= gItemsTexturesID
[ITEM_WEAPON_CHAINGUN
];
2927 WEAPON_SHOTGUN1
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SHOTGUN1
];
2928 WEAPON_SHOTGUN2
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SHOTGUN2
];
2929 WEAPON_SUPERPULEMET
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SUPERPULEMET
];
2930 WEAPON_ROCKETLAUNCHER
: ID
:= gItemsTexturesID
[ITEM_WEAPON_ROCKETLAUNCHER
];
2931 WEAPON_PLASMA
: ID
:= gItemsTexturesID
[ITEM_WEAPON_PLASMA
];
2932 WEAPON_BFG
: ID
:= gItemsTexturesID
[ITEM_WEAPON_BFG
];
2933 WEAPON_FLAMETHROWER
: ID
:= gItemsTexturesID
[ITEM_WEAPON_FLAMETHROWER
];
2936 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2937 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+158, s
, _RGB(255, 0, 0));
2938 e_Draw(ID
, X
+20, Y
+160, 0, True, False);
2940 if R_KEY_RED
in FRulez
then
2941 e_Draw(gItemsTexturesID
[ITEM_KEY_RED
], X
+78, Y
+214, 0, True, False);
2943 if R_KEY_GREEN
in FRulez
then
2944 e_Draw(gItemsTexturesID
[ITEM_KEY_GREEN
], X
+95, Y
+214, 0, True, False);
2946 if R_KEY_BLUE
in FRulez
then
2947 e_Draw(gItemsTexturesID
[ITEM_KEY_BLUE
], X
+112, Y
+214, 0, True, False);
2949 if FJetFuel
> 0 then
2951 if g_Texture_Get('TEXTURE_PLAYER_HUDAIR', ID
) then
2952 e_Draw(ID
, X
+2, Y
+116, 0, True, False);
2953 if g_Texture_Get('TEXTURE_PLAYER_HUDJET', ID
) then
2954 e_Draw(ID
, X
+2, Y
+126, 0, True, False);
2955 e_DrawLine(4, X
+16, Y
+122, X
+16+Trunc(168*IfThen(FAir
> 0, FAir
, 0)/AIR_MAX
), Y
+122, 0, 0, 196);
2956 e_DrawLine(4, X
+16, Y
+132, X
+16+Trunc(168*FJetFuel
/JET_MAX
), Y
+132, 208, 0, 0);
2960 if g_Texture_Get('TEXTURE_PLAYER_HUDAIR', ID
) then
2961 e_Draw(ID
, X
+2, Y
+124, 0, True, False);
2962 e_DrawLine(4, X
+16, Y
+130, X
+16+Trunc(168*IfThen(FAir
> 0, FAir
, 0)/AIR_MAX
), Y
+130, 0, 0, 196);
2965 if gShowPing
and g_Game_IsClient
then
2967 s
:= _lc
[I_GAME_PING_HUD
] + IntToStr(NetPeer
.lastRoundTripTime
) + _lc
[I_NET_SLIST_PING_MS
];
2968 e_TextureFontPrint(X
+ 4, Y
+ 242, s
, gStdFont
);
2974 e_TextureFontPrint(X
+ 4, Y
+ 242, _lc
[I_PLAYER_SPECT
], gStdFont
);
2975 e_TextureFontPrint(X
+ 4, Y
+ 258, _lc
[I_PLAYER_SPECT2
], gStdFont
);
2976 e_TextureFontPrint(X
+ 4, Y
+ 274, _lc
[I_PLAYER_SPECT1
], gStdFont
);
2979 e_TextureFontGetSize(gStdFont
, cw
, ch
);
2980 s
:= _lc
[I_PLAYER_SPECT4
];
2981 e_TextureFontPrintEx(gScreenWidth
div 2 - cw
*(Length(s
) div 2),
2982 gScreenHeight
-4-ch
, s
, gStdFont
, 255, 255, 255, 1, True);
2983 e_TextureFontPrint(X
+ 4, Y
+ 290, _lc
[I_PLAYER_SPECT1S
], gStdFont
);
2989 procedure TPlayer
.DrawRulez();
2993 // Ïðè âçÿòèè íåóÿçâèìîñòè ðèñóåòñÿ èíâåðñèîííûé áåëûé ôîí
2994 if (FMegaRulez
[MR_INVUL
] >= gTime
) and (FSpawnInvul
< gTime
) then
2996 if (FMegaRulez
[MR_INVUL
]-gTime
) <= 2100 then
2997 dr
:= not Odd((FMegaRulez
[MR_INVUL
]-gTime
) div 300)
3002 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
3003 191, 191, 191, 0, TBlending
.Invert
);
3006 // Ïðè âçÿòèè çàùèòíîãî êîñòþìà ðèñóåòñÿ çåëåíîâàòûé ôîí
3007 if FMegaRulez
[MR_SUIT
] >= gTime
then
3009 if (FMegaRulez
[MR_SUIT
]-gTime
) <= 2100 then
3010 dr
:= not Odd((FMegaRulez
[MR_SUIT
]-gTime
) div 300)
3015 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
3016 0, 96, 0, 200, TBlending
.None
);
3019 // Ïðè âçÿòèè áåðñåðêà ðèñóåòñÿ êðàñíîâàòûé ôîí
3020 if (FBerserk
>= 0) and (LongWord(FBerserk
) >= gTime
) and (gFlash
= 2) then
3022 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
3023 255, 0, 0, 200, TBlending
.None
);
3027 procedure TPlayer
.DrawPain();
3031 if FPain
= 0 then Exit
;
3035 if a
< 15 then h
:= 0
3036 else if a
< 35 then h
:= 1
3037 else if a
< 55 then h
:= 2
3038 else if a
< 75 then h
:= 3
3039 else if a
< 95 then h
:= 4
3042 //if a > 255 then a := 255;
3044 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1, 255, 0, 0, 255-h
*50);
3045 //e_DrawFillQuad(0, 0, gPlayerScreenSize.X-1, gPlayerScreenSize.Y-1, 255-min(128, a), 255-a, 255-a, 0, B_FILTER);
3048 procedure TPlayer
.DrawPickup();
3052 if FPickup
= 0 then Exit
;
3056 if a
< 15 then h
:= 1
3057 else if a
< 35 then h
:= 2
3058 else if a
< 55 then h
:= 3
3059 else if a
< 75 then h
:= 4
3062 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1, 150, 200, 150, 255-h
*50);
3065 procedure TPlayer
.DoPunch();
3070 if FPunchAnim
<> nil then begin
3075 st
:= 'FRAMES_PUNCH';
3076 if R_BERSERK
in FRulez
then
3077 st
:= st
+ '_BERSERK';
3078 if FKeys
[KEY_UP
].Pressed
then
3080 else if FKeys
[KEY_DOWN
].Pressed
then
3082 g_Frames_Get(id
, st
);
3083 FPunchAnim
:= TAnimation
.Create(id
, False, 1);
3086 procedure TPlayer
.Fire();
3088 f
, DidFire
: Boolean;
3089 wx
, wy
, xd
, yd
: Integer;
3092 if g_Game_IsClient
then Exit
;
3093 // FBFGFireCounter - âðåìÿ ïåðåä âûñòðåëîì (äëÿ BFG)
3094 // FReloading - âðåìÿ ïîñëå âûñòðåëà (äëÿ âñåãî)
3102 if FReloading
[FCurrWeap
] <> 0 then Exit
;
3107 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
3108 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
3109 xd
:= wx
+IfThen(FDirection
= TDirection
.D_LEFT
, -30, 30);
3110 yd
:= wy
+firediry();
3116 if R_BERSERK
in FRulez
then
3118 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
3119 locobj
.X
:= FObj
.X
+FObj
.Rect
.X
;
3120 locobj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
3123 locobj
.rect
.Width
:= 39;
3124 locobj
.rect
.Height
:= 52;
3125 locobj
.Vel
.X
:= (xd
-wx
) div 2;
3126 locobj
.Vel
.Y
:= (yd
-wy
) div 2;
3127 locobj
.Accel
.X
:= xd
-wx
;
3128 locobj
.Accel
.y
:= yd
-wy
;
3130 if g_Weapon_Hit(@locobj
, 50, FUID
, HIT_SOME
) <> 0 then
3131 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
3133 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
3135 if (gFlash
= 1) and (FPain
< 50) then FPain
:= min(FPain
+ 25, 50);
3139 g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
3143 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3148 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
3149 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
3151 FSawSoundSelect
.Stop();
3153 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
3155 else if not FSawSoundHit
.IsPlaying() then
3157 FSawSoundSelect
.Stop();
3158 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
3161 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3167 if FAmmo
[A_BULLETS
] > 0 then
3169 g_Weapon_pistol(wx
, wy
, xd
, yd
, FUID
);
3170 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3171 Dec(FAmmo
[A_BULLETS
]);
3172 FFireAngle
:= FAngle
;
3175 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
3176 GameVelX
, GameVelY
-2, SHELL_BULLET
);
3180 if FAmmo
[A_SHELLS
] > 0 then
3182 g_Weapon_shotgun(wx
, wy
, xd
, yd
, FUID
);
3183 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', wx
, wy
);
3184 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3185 Dec(FAmmo
[A_SHELLS
]);
3186 FFireAngle
:= FAngle
;
3190 FShellType
:= SHELL_SHELL
;
3194 if FAmmo
[A_SHELLS
] >= 2 then
3196 g_Weapon_dshotgun(wx
, wy
, xd
, yd
, FUID
);
3197 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3198 Dec(FAmmo
[A_SHELLS
], 2);
3199 FFireAngle
:= FAngle
;
3203 FShellType
:= SHELL_DBLSHELL
;
3207 if FAmmo
[A_BULLETS
] > 0 then
3209 g_Weapon_mgun(wx
, wy
, xd
, yd
, FUID
);
3210 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', wx
, wy
);
3211 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3212 Dec(FAmmo
[A_BULLETS
]);
3213 FFireAngle
:= FAngle
;
3216 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
3217 GameVelX
, GameVelY
-2, SHELL_BULLET
);
3220 WEAPON_ROCKETLAUNCHER
:
3221 if FAmmo
[A_ROCKETS
] > 0 then
3223 g_Weapon_rocket(wx
, wy
, xd
, yd
, FUID
);
3224 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3225 Dec(FAmmo
[A_ROCKETS
]);
3226 FFireAngle
:= FAngle
;
3232 if FAmmo
[A_CELLS
] > 0 then
3234 g_Weapon_plasma(wx
, wy
, xd
, yd
, FUID
);
3235 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3236 Dec(FAmmo
[A_CELLS
]);
3237 FFireAngle
:= FAngle
;
3243 if (FAmmo
[A_CELLS
] >= 40) and (FBFGFireCounter
= -1) then
3245 FBFGFireCounter
:= 17;
3246 if not FNoReload
then
3247 g_Sound_PlayExAt('SOUND_WEAPON_STARTFIREBFG', FObj
.X
, FObj
.Y
);
3248 Dec(FAmmo
[A_CELLS
], 40);
3252 WEAPON_SUPERPULEMET
:
3253 if FAmmo
[A_SHELLS
] > 0 then
3255 g_Weapon_shotgun(wx
, wy
, xd
, yd
, FUID
);
3256 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', wx
, wy
);
3257 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3258 Dec(FAmmo
[A_SHELLS
]);
3259 FFireAngle
:= FAngle
;
3262 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
3263 GameVelX
, GameVelY
-2, SHELL_SHELL
);
3266 WEAPON_FLAMETHROWER
:
3267 if FAmmo
[A_FUEL
] > 0 then
3269 g_Weapon_flame(wx
, wy
, xd
, yd
, FUID
);
3271 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3273 FFireAngle
:= FAngle
;
3280 if g_Game_IsNet
and g_Game_IsServer
then MH_SEND_PlayerStats(FUID
);
3284 if g_Game_IsNet
then
3288 if FCurrWeap
<> WEAPON_BFG
then
3289 MH_SEND_PlayerFire(FUID
, FCurrWeap
, wx
, wy
, xd
, yd
, LastShotID
)
3291 if not FNoReload
then
3292 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_WEAPON_STARTFIREBFG');
3295 MH_SEND_PlayerStats(FUID
);
3300 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
3301 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
3302 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
3305 function TPlayer
.GetAmmoByWeapon(Weapon
: Byte): Word;
3308 WEAPON_PISTOL
, WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
];
3309 WEAPON_SHOTGUN1
, WEAPON_SHOTGUN2
, WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
];
3310 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
];
3311 WEAPON_PLASMA
, WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
];
3312 WEAPON_FLAMETHROWER
: Result
:= FAmmo
[A_FUEL
];
3317 function TPlayer
.HeadInLiquid(XInc
, YInc
: Integer): Boolean;
3319 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
+XInc
, FObj
.Y
+PLAYER_HEADRECT
.Y
+YInc
,
3320 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
3321 PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, True);
3324 procedure TPlayer
.FlamerOn
;
3326 FFlameSoundOff
.Stop();
3327 FFlameSoundOff
.SetPosition(0);
3330 if (not FFlameSoundOn
.IsPlaying()) and (not FFlameSoundWork
.IsPlaying()) then
3331 FFlameSoundWork
.PlayAt(FObj
.X
, FObj
.Y
);
3335 FFlameSoundOn
.PlayAt(FObj
.X
, FObj
.Y
);
3340 procedure TPlayer
.FlamerOff
;
3344 FFlameSoundOn
.Stop();
3345 FFlameSoundOn
.SetPosition(0);
3346 FFlameSoundWork
.Stop();
3347 FFlameSoundWork
.SetPosition(0);
3348 FFlameSoundOff
.PlayAt(FObj
.X
, FObj
.Y
);
3353 procedure TPlayer
.JetpackOn
;
3357 FJetSoundOn
.SetPosition(0);
3358 FJetSoundOn
.PlayAt(FObj
.X
, FObj
.Y
);
3362 procedure TPlayer
.JetpackOff
;
3366 FJetSoundOff
.SetPosition(0);
3367 FJetSoundOff
.PlayAt(FObj
.X
, FObj
.Y
);
3370 procedure TPlayer
.CatchFire(Attacker
: Word; Timeout
: Integer = PLAYER_BURN_TIME
);
3372 if Timeout
<= 0 then
3374 if (FMegaRulez
[MR_SUIT
] > gTime
) or (FMegaRulez
[MR_INVUL
] > gTime
) then
3375 exit
; // Íå çàãîðàåìñÿ êîãäà åñòü çàùèòà
3376 if g_Obj_CollidePanel(@FObj
, 0, 0, PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
) then
3377 exit
; // Íå ïîäãîðàåì â âîäå íà âñÿêèé ñëó÷àé
3378 if FFireTime
<= 0 then
3379 g_Sound_PlayExAt('SOUND_IGNITE', FObj
.X
, FObj
.Y
);
3380 FFireTime
:= Timeout
;
3381 FFireAttacker
:= Attacker
;
3382 if g_Game_IsNet
and g_Game_IsServer
then
3383 MH_SEND_PlayerStats(FUID
);
3386 procedure TPlayer
.Jump();
3388 if gFly
or FJetpack
then
3390 // Ïîëåò (÷èò-êîä èëè äæåòïàê):
3391 if FObj
.Vel
.Y
> -VEL_FLY
then
3392 FObj
.Vel
.Y
:= FObj
.Vel
.Y
- 3;
3395 if FJetFuel
> 0 then
3397 if (FJetFuel
< 1) and g_Game_IsServer
then
3401 if g_Game_IsNet
then
3402 MH_SEND_PlayerStats(FUID
);
3408 // Íå âêëþ÷àòü äæåòïàê â ðåæèìå ïðîõîæäåíèÿ ñêâîçü ñòåíû
3410 FCanJetpack
:= False;
3412 // Ïðûãàåì èëè âñïëûâàåì:
3413 if (CollideLevel(0, 1) or
3414 g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
+36, PLAYER_RECT
.Width
,
3415 PLAYER_RECT
.Height
-33, PANEL_STEP
, False)
3416 ) and (FObj
.Accel
.Y
= 0) then // Íå ïðûãàòü, åñëè åñòü âåðòèêàëüíîå óñêîðåíèå
3418 FObj
.Vel
.Y
:= -VEL_JUMP
;
3419 FCanJetpack
:= False;
3423 if BodyInLiquid(0, 0) then
3424 FObj
.Vel
.Y
:= -VEL_SW
3425 else if (FJetFuel
> 0) and FCanJetpack
and
3426 g_Game_IsServer
and (not g_Obj_CollideLiquid(@FObj
, 0, 0)) then
3430 if g_Game_IsNet
then
3431 MH_SEND_PlayerStats(FUID
);
3436 procedure TPlayer
.Kill(KillType
: Byte; SpawnerUID
: Word; t
: Byte);
3438 a
, i
, k
, ab
, ar
: Byte;
3442 srv
, netsrv
: Boolean;
3448 procedure PushItem(t
: Byte);
3452 id
:= g_Items_Create(FObj
.X
, FObj
.Y
, t
, True, False);
3453 it
:= g_Items_ByIdx(id
);
3454 if KillType
= K_EXTRAHARDKILL
then // -7..+7; -8..0
3456 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-7+Random(15),
3457 (FObj
.Vel
.Y
div 2)-Random(9));
3458 it
.positionChanged(); // this updates spatial accelerators
3462 if KillType
= K_HARDKILL
then // -5..+5; -5..0
3464 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-5+Random(11),
3465 (FObj
.Vel
.Y
div 2)-Random(6));
3467 else // -3..+3; -3..0
3469 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-3+Random(7),
3470 (FObj
.Vel
.Y
div 2)-Random(4));
3472 it
.positionChanged(); // this updates spatial accelerators
3475 if g_Game_IsNet
and g_Game_IsServer
then
3476 MH_SEND_ItemSpawn(True, id
);
3480 DoFrags
:= (gGameSettings
.MaxLives
= 0) or (gGameSettings
.GameMode
= GM_COOP
);
3481 Srv
:= g_Game_IsServer
;
3482 Netsrv
:= g_Game_IsServer
and g_Game_IsNet
;
3483 if Srv
then FDeath
:= FDeath
+ 1;
3488 if not FPhysics
then
3494 if (gGameSettings
.MaxLives
> 0) and Srv
and (gLMSRespawn
= LMS_RESPAWN_NONE
) then
3496 if FLives
> 0 then FLives
:= FLives
- 1;
3497 if FLives
= 0 then FNoRespawn
:= True;
3500 // Íîìåð òèïà ñìåðòè:
3503 K_SIMPLEKILL
: a
:= 1;
3505 K_EXTRAHARDKILL
: a
:= 3;
3510 if not FModel
.PlaySound(MODELSOUND_DIE
, a
, FObj
.X
, FObj
.Y
) then
3512 if FModel
.PlaySound(MODELSOUND_DIE
, i
, FObj
.X
, FObj
.Y
) then
3519 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN1
;
3521 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN2
;
3522 K_EXTRAHARDKILL
, K_FALLKILL
:
3523 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN3
;
3526 // Ïåðåêëþ÷àåì ñîñòîÿíèå:
3530 K_HARDKILL
, K_EXTRAHARDKILL
:
3534 // Ðåàêöèÿ ìîíñòðîâ íà ñìåðòü èãðîêà:
3535 if (KillType
<> K_FALLKILL
) and (Srv
) then
3536 g_Monsters_killedp();
3538 if SpawnerUID
= FUID
then
3542 if gGameSettings
.GameMode
= GM_TDM
then
3543 Dec(gTeamStat
[FTeam
].Score
);
3544 if DoFrags
or (gGameSettings
.GameMode
= GM_TDM
) then
3550 g_Console_Add(Format(_lc
[I_PLAYER_KILL_SELF
], [FName
]), True);
3553 if g_GetUIDType(SpawnerUID
) = UID_PLAYER
then
3554 begin // Óáèò äðóãèì èãðîêîì
3555 KP
:= g_Player_Get(SpawnerUID
);
3556 if (KP
<> nil) and Srv
then
3558 if (DoFrags
or (gGameSettings
.GameMode
= GM_TDM
)) then
3559 if SameTeam(FUID
, SpawnerUID
) then
3569 if (gGameSettings
.GameMode
= GM_TDM
) and DoFrags
then
3570 Inc(gTeamStat
[KP
.Team
].Score
,
3571 IfThen(SameTeam(FUID
, SpawnerUID
), -1, 1));
3573 if netsrv
then MH_SEND_PlayerStats(SpawnerUID
);
3576 plr
:= g_Player_Get(SpawnerUID
);
3584 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_2
],
3588 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_1
],
3592 g_Console_Add(Format(_lc
[I_PLAYER_KILL
],
3597 else if g_GetUIDType(SpawnerUID
) = UID_MONSTER
then
3598 begin // Óáèò ìîíñòðîì
3599 mon
:= g_Monsters_ByUID(SpawnerUID
);
3603 s
:= g_Mons_GetKilledByTypeId(mon
.MonsterType
);
3607 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_2
],
3611 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_1
],
3615 g_Console_Add(Format(_lc
[I_PLAYER_KILL
],
3620 else // Îñîáûå òèïû ñìåðòè
3623 HIT_SELF
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_SELF
], [FName
]), True);
3624 HIT_FALL
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_FALL
], [FName
]), True);
3625 HIT_WATER
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_WATER
], [FName
]), True);
3626 HIT_ACID
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_ACID
], [FName
]), True);
3627 HIT_TRAP
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_TRAP
], [FName
]), True);
3628 else g_Console_Add(Format(_lc
[I_PLAYER_DIED
], [FName
]), True);
3634 for a
:= WP_FIRST
to WP_LAST
do
3638 WEAPON_SAW
: i
:= ITEM_WEAPON_SAW
;
3639 WEAPON_SHOTGUN1
: i
:= ITEM_WEAPON_SHOTGUN1
;
3640 WEAPON_SHOTGUN2
: i
:= ITEM_WEAPON_SHOTGUN2
;
3641 WEAPON_CHAINGUN
: i
:= ITEM_WEAPON_CHAINGUN
;
3642 WEAPON_ROCKETLAUNCHER
: i
:= ITEM_WEAPON_ROCKETLAUNCHER
;
3643 WEAPON_PLASMA
: i
:= ITEM_WEAPON_PLASMA
;
3644 WEAPON_BFG
: i
:= ITEM_WEAPON_BFG
;
3645 WEAPON_SUPERPULEMET
: i
:= ITEM_WEAPON_SUPERPULEMET
;
3646 WEAPON_FLAMETHROWER
: i
:= ITEM_WEAPON_FLAMETHROWER
;
3655 if R_ITEM_BACKPACK
in FRulez
then
3656 PushItem(ITEM_AMMO_BACKPACK
);
3658 // Âûáðîñ ðàêåòíîãî ðàíöà:
3659 if FJetFuel
> 0 then
3660 PushItem(ITEM_JETPACK
);
3663 if (not (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
])) or
3664 (not LongBool(gGameSettings
.Options
and GAME_OPTION_DMKEYS
)) then
3666 if R_KEY_RED
in FRulez
then
3667 PushItem(ITEM_KEY_RED
);
3669 if R_KEY_GREEN
in FRulez
then
3670 PushItem(ITEM_KEY_GREEN
);
3672 if R_KEY_BLUE
in FRulez
then
3673 PushItem(ITEM_KEY_BLUE
);
3677 DropFlag(KillType
= K_FALLKILL
);
3680 FCorpse
:= g_Player_CreateCorpse(Self
);
3682 if Srv
and (gGameSettings
.MaxLives
> 0) and FNoRespawn
and
3683 (gLMSRespawn
= LMS_RESPAWN_NONE
) then
3689 for i
:= Low(gPlayers
) to High(gPlayers
) do
3691 if gPlayers
[i
] = nil then continue
;
3692 if (not gPlayers
[i
].FNoRespawn
) and (not gPlayers
[i
].FSpectator
) then
3695 if gPlayers
[i
].FTeam
= TEAM_RED
then Inc(ar
)
3696 else if gPlayers
[i
].FTeam
= TEAM_BLUE
then Inc(ab
);
3701 OldLR
:= gLMSRespawn
;
3702 if (gGameSettings
.GameMode
= GM_COOP
) then
3706 // everyone is dead, restart the map
3707 g_Game_Message(_lc
[I_MESSAGE_LMS_LOSE
], 144);
3709 MH_SEND_GameEvent(NET_EV_LMS_LOSE
);
3710 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3711 gLMSRespawnTime
:= gTime
+ 5000;
3713 else if (a
= 1) then
3715 if (gPlayers
[k
] <> nil) and not (gPlayers
[k
] is TBot
) then
3716 if (gPlayers
[k
] = gPlayer1
) or
3717 (gPlayers
[k
] = gPlayer2
) then
3718 g_Console_Add('*** ' + _lc
[I_MESSAGE_LMS_SURVIVOR
] + ' ***', True)
3719 else if Netsrv
and (gPlayers
[k
].FClientID
>= 0) then
3720 MH_SEND_GameEvent(NET_EV_LMS_SURVIVOR
, 0, 'N', gPlayers
[k
].FClientID
);
3723 else if (gGameSettings
.GameMode
= GM_TDM
) then
3725 if (ab
= 0) and (ar
<> 0) then
3728 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 144);
3730 MH_SEND_GameEvent(NET_EV_TLMS_WIN
, TEAM_RED
);
3731 Inc(gTeamStat
[TEAM_RED
].Score
);
3732 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3733 gLMSRespawnTime
:= gTime
+ 5000;
3735 else if (ar
= 0) and (ab
<> 0) then
3738 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 144);
3740 MH_SEND_GameEvent(NET_EV_TLMS_WIN
, TEAM_BLUE
);
3741 Inc(gTeamStat
[TEAM_BLUE
].Score
);
3742 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3743 gLMSRespawnTime
:= gTime
+ 5000;
3745 else if (ar
= 0) and (ab
= 0) then
3748 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
3750 MH_SEND_GameEvent(NET_EV_LMS_DRAW
, 0, FName
);
3751 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3752 gLMSRespawnTime
:= gTime
+ 5000;
3755 else if (gGameSettings
.GameMode
= GM_DM
) then
3759 if gPlayers
[k
] <> nil then
3762 // survivor is the winner
3763 g_Game_Message(Format(_lc
[I_MESSAGE_LMS_WIN
], [AnsiUpperCase(FName
)]), 144);
3765 MH_SEND_GameEvent(NET_EV_LMS_WIN
, 0, FName
);
3768 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3769 gLMSRespawnTime
:= gTime
+ 5000;
3771 else if (a
= 0) then
3773 // everyone is dead, restart the map
3774 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
3776 MH_SEND_GameEvent(NET_EV_LMS_DRAW
, 0, FName
);
3777 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3778 gLMSRespawnTime
:= gTime
+ 5000;
3781 if srv
and (OldLR
= LMS_RESPAWN_NONE
) and (gLMSRespawn
> LMS_RESPAWN_NONE
) then
3783 if NetMode
= NET_SERVER
then
3784 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
)
3786 g_Console_Add(Format(_lc
[I_MSG_WARMUP_START
], [(gLMSRespawnTime
- gTime
) div 1000]), True);
3792 MH_SEND_PlayerStats(FUID
);
3793 MH_SEND_PlayerDeath(FUID
, KillType
, t
, SpawnerUID
);
3794 if gGameSettings
.GameMode
= GM_TDM
then MH_SEND_GameStats
;
3797 if srv
and FNoRespawn
then Spectate(True);
3798 FWantsInGame
:= True;
3801 function TPlayer
.BodyInLiquid(XInc
, YInc
: Integer): Boolean;
3803 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
, PLAYER_RECT
.Width
,
3804 PLAYER_RECT
.Height
-20, PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, False);
3807 function TPlayer
.BodyInAcid(XInc
, YInc
: Integer): Boolean;
3809 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
, PLAYER_RECT
.Width
,
3810 PLAYER_RECT
.Height
-20, PANEL_ACID1
or PANEL_ACID2
, False);
3813 procedure TPlayer
.MakeBloodSimple(Count
: Word);
3815 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)+8,
3816 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3817 Count
div 2, 3, -1, 16, (PLAYER_RECT
.Height
*2 div 3),
3818 FModel
.Blood
.R
, FModel
.Blood
.G
, FModel
.Blood
.B
, FModel
.Blood
.Kind
);
3819 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-8,
3820 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3821 Count
div 2, -3, -1, 16, (PLAYER_RECT
.Height
*2) div 3,
3822 FModel
.Blood
.R
, FModel
.Blood
.G
, FModel
.Blood
.B
, FModel
.Blood
.Kind
);
3825 procedure TPlayer
.MakeBloodVector(Count
: Word; VelX
, VelY
: Integer);
3827 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
3828 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3829 Count
, VelX
, VelY
, 16, (PLAYER_RECT
.Height
*2) div 3,
3830 FModel
.Blood
.R
, FModel
.Blood
.G
, FModel
.Blood
.B
, FModel
.Blood
.Kind
);
3833 procedure TPlayer
.ProcessWeaponAction(Action
: Byte);
3835 if g_Game_IsClient
then Exit
;
3837 WP_PREV
: PrevWeapon();
3838 WP_NEXT
: NextWeapon();
3842 procedure TPlayer
.QueueWeaponSwitch(Weapon
: Byte);
3844 if g_Game_IsClient
then Exit
;
3845 if Weapon
> High(FWeapon
) then Exit
;
3846 FNextWeap
:= FNextWeap
or (1 shl Weapon
);
3849 procedure TPlayer
.resetWeaponQueue ();
3852 FNextWeapDelay
:= 0;
3857 {procedure TPlayer.Assist(KillType: Byte; SpawnerUID: Word);
3862 procedure Accumulate(FDamage: Byte;);
3869 DoAssists := (gGameSettings.GameMode = GM_TDM) or (gGameSettings.GameMode = GM_CTF);
3872 if (FAccumulatedDamage >= 65) then
3880 function TPlayer
.hasAmmoForWeapon (weapon
: Byte): Boolean;
3884 WEAPON_KASTET
, WEAPON_SAW
: result
:= true;
3885 WEAPON_SHOTGUN1
, WEAPON_SHOTGUN2
, WEAPON_SUPERPULEMET
: result
:= (FAmmo
[A_SHELLS
] > 0);
3886 WEAPON_PISTOL
, WEAPON_CHAINGUN
: result
:= (FAmmo
[A_BULLETS
] > 0);
3887 WEAPON_ROCKETLAUNCHER
: result
:= (FAmmo
[A_ROCKETS
] > 0);
3888 WEAPON_PLASMA
, WEAPON_BFG
: result
:= (FAmmo
[A_CELLS
] > 0);
3889 WEAPON_FLAMETHROWER
: result
:= (FAmmo
[A_FUEL
] > 0);
3890 else result
:= (weapon
< length(FWeapon
));
3894 function TPlayer
.hasAmmoForShooting (weapon
: Byte): Boolean;
3898 WEAPON_KASTET
, WEAPON_SAW
: result
:= true;
3899 WEAPON_SHOTGUN1
, WEAPON_SUPERPULEMET
: result
:= (FAmmo
[A_SHELLS
] > 0);
3900 WEAPON_SHOTGUN2
: result
:= (FAmmo
[A_SHELLS
] > 1);
3901 WEAPON_PISTOL
, WEAPON_CHAINGUN
: result
:= (FAmmo
[A_BULLETS
] > 0);
3902 WEAPON_ROCKETLAUNCHER
: result
:= (FAmmo
[A_ROCKETS
] > 0);
3903 WEAPON_PLASMA
: result
:= (FAmmo
[A_CELLS
] > 0);
3904 WEAPON_BFG
: result
:= (FAmmo
[A_CELLS
] >= 40);
3905 WEAPON_FLAMETHROWER
: result
:= (FAmmo
[A_FUEL
] > 0);
3906 else result
:= (weapon
< length(FWeapon
));
3910 function TPlayer
.shouldSwitch (weapon
: Byte; hadWeapon
: Boolean): Boolean;
3913 if (weapon
> WP_LAST
+ 1) then
3918 if (FWeapSwitchMode
= 1) and not hadWeapon
then
3920 else if (FWeapSwitchMode
= 2) then
3921 result
:= (FWeapPreferences
[weapon
] > FWeapPreferences
[FCurrWeap
]);
3924 // return 255 for "no switch"
3925 function TPlayer
.getNextWeaponIndex (): Byte;
3928 wantThisWeapon
: array[0..64] of Boolean;
3929 wwc
: Integer = 0; //HACK!
3932 result
:= 255; // default result: "no switch"
3933 //e_LogWriteFln('FSWITCHTOEMPTY: %s', [FSwitchToEmpty], TMsgType.Notify);
3934 // had weapon cycling on previous frame? remove that flag
3935 if (FNextWeap
and $2000) <> 0 then
3937 FNextWeap
:= FNextWeap
and $1FFF;
3938 FNextWeapDelay
:= 0;
3940 // cycling has priority
3941 if (FNextWeap
and $C000) <> 0 then
3943 if (FNextWeap
and $8000) <> 0 then
3947 FNextWeap
:= FNextWeap
or $2000; // we need this
3948 if FNextWeapDelay
> 0 then
3949 exit
; // cooldown time
3951 for i
:= 0 to High(FWeapon
) do
3953 cwi
:= (cwi
+length(FWeapon
)+dir
) mod length(FWeapon
);
3954 if FWeapon
[cwi
] and maySwitch(cwi
) then
3956 //e_LogWriteFln(' SWITCH: cur=%d; new=%d %s %s', [FCurrWeap, cwi, FSwitchToEmpty, hasAmmoForWeapon(cwi)], TMsgType.Notify);
3957 result
:= Byte(cwi
);
3958 FNextWeapDelay
:= WEAPON_DELAY
;
3966 for i
:= 0 to High(wantThisWeapon
) do
3967 wantThisWeapon
[i
] := false;
3968 for i
:= 0 to High(FWeapon
) do
3969 if (FNextWeap
and (1 shl i
)) <> 0 then
3971 wantThisWeapon
[i
] := true;
3975 // exclude currently selected weapon from the set
3976 wantThisWeapon
[FCurrWeap
] := false;
3977 // slow down alterations a little
3980 //e_WriteLog(Format(' FNextWeap=%x; delay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
3981 // more than one weapon requested, assume "alteration" and check alteration delay
3982 if FNextWeapDelay
> 0 then
3988 // do not reset weapon queue, it will be done in `RealizeCurrentWeapon()`
3989 // but clear all counters if no weapon should be switched
3995 //e_WriteLog(Format('wwc=%d', [wwc]), MSG_WARNING);
3996 // try weapons in descending order
3997 for i
:= High(FWeapon
) downto 0 do
3999 if wantThisWeapon
[i
] and FWeapon
[i
] and ((wwc
= 1) or hasAmmoForWeapon(i
)) then
4004 FNextWeapDelay
:= WEAPON_DELAY
* 2; // anyway, 'cause why not
4005 //e_LogWriteFln('FOUND %s %s %s', [result, FSwitchToEmpty, hasAmmoForWeapon(i)], TMsgType.Notify);
4009 // no suitable weapon found, so reset the queue, to avoid accidental "queuing" of weapon w/o ammo
4013 procedure TPlayer
.RealizeCurrentWeapon();
4014 function switchAllowed (): Boolean;
4019 if FBFGFireCounter
<> -1 then
4021 if FTime
[T_SWITCH
] > gTime
then
4023 for i
:= WP_FIRST
to WP_LAST
do
4024 if FReloading
[i
] > 0 then
4032 //e_WriteLog(Format('***RealizeCurrentWeapon: FNextWeap=%x; FNextWeapDelay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
4033 //FNextWeap := FNextWeap and $1FFF;
4034 if FNextWeapDelay
> 0 then Dec(FNextWeapDelay
); // "alteration delay"
4036 if not switchAllowed
then
4038 //HACK for weapon cycling
4039 if (FNextWeap
and $E000) <> 0 then FNextWeap
:= 0;
4043 nw
:= getNextWeaponIndex();
4045 if nw
= 255 then exit
; // don't reset anything here
4046 if nw
> High(FWeapon
) then
4048 // don't forget to reset queue here!
4049 //e_WriteLog(' RealizeCurrentWeapon: WUTAFUUUU', MSG_WARNING);
4057 FTime
[T_SWITCH
] := gTime
+156;
4058 if FCurrWeap
= WEAPON_SAW
then FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
4059 FModel
.SetWeapon(FCurrWeap
);
4060 if g_Game_IsNet
then MH_SEND_PlayerStats(FUID
);
4064 procedure TPlayer
.NextWeapon();
4066 if g_Game_IsClient
then Exit
;
4070 procedure TPlayer
.PrevWeapon();
4072 if g_Game_IsClient
then Exit
;
4076 procedure TPlayer
.SetWeapon(W
: Byte);
4078 if FCurrWeap
<> W
then
4079 if W
= WEAPON_SAW
then
4080 FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
4083 FModel
.SetWeapon(CurrWeap
);
4087 function TPlayer
.PickItem(ItemType
: Byte; arespawn
: Boolean; var remove
: Boolean): Boolean;
4090 switchWeapon
: Byte = 255;
4091 hadWeapon
: Boolean = False;
4094 if g_Game_IsClient
then Exit
;
4096 // a = true - ìåñòî ñïàâíà ïðåäìåòà:
4097 a
:= LongBool(gGameSettings
.Options
and GAME_OPTION_WEAPONSTAY
) and arespawn
;
4101 if (FHealth
< PLAYER_HP_SOFT
) or (FFireTime
> 0) then
4103 if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
4107 if gFlash
= 2 then Inc(FPickup
, 5);
4111 if (FHealth
< PLAYER_HP_SOFT
) or (FFireTime
> 0) then
4113 if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
4117 if gFlash
= 2 then Inc(FPickup
, 5);
4121 if FArmor
< PLAYER_AP_SOFT
then
4123 FArmor
:= PLAYER_AP_SOFT
;
4126 if gFlash
= 2 then Inc(FPickup
, 5);
4130 if FArmor
< PLAYER_AP_LIMIT
then
4132 FArmor
:= PLAYER_AP_LIMIT
;
4135 if gFlash
= 2 then Inc(FPickup
, 5);
4139 if (FHealth
< PLAYER_HP_LIMIT
) or (FFireTime
> 0) then
4141 if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
4145 if gFlash
= 2 then Inc(FPickup
, 5);
4149 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) or (FFireTime
> 0) then
4151 if FHealth
< PLAYER_HP_LIMIT
then
4152 FHealth
:= PLAYER_HP_LIMIT
;
4153 if FArmor
< PLAYER_AP_LIMIT
then
4154 FArmor
:= PLAYER_AP_LIMIT
;
4158 if gFlash
= 2 then Inc(FPickup
, 5);
4162 if (not FWeapon
[WEAPON_SAW
]) or ((not arespawn
) and (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
])) then
4164 hadWeapon
:= FWeapon
[WEAPON_SAW
];
4165 switchWeapon
:= WEAPON_SAW
;
4166 FWeapon
[WEAPON_SAW
] := True;
4168 if gFlash
= 2 then Inc(FPickup
, 5);
4169 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4172 ITEM_WEAPON_SHOTGUN1
:
4173 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN1
] then
4175 // Íóæíî, ÷òîáû íå âçÿòü âñå ïóëè ñðàçó:
4176 if a
and FWeapon
[WEAPON_SHOTGUN1
] then Exit
;
4177 hadWeapon
:= FWeapon
[WEAPON_SHOTGUN1
];
4178 switchWeapon
:= WEAPON_SHOTGUN1
;
4179 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4180 FWeapon
[WEAPON_SHOTGUN1
] := True;
4182 if gFlash
= 2 then Inc(FPickup
, 5);
4183 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4186 ITEM_WEAPON_SHOTGUN2
:
4187 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN2
] then
4189 if a
and FWeapon
[WEAPON_SHOTGUN2
] then Exit
;
4190 hadWeapon
:= FWeapon
[WEAPON_SHOTGUN2
];
4191 switchWeapon
:= WEAPON_SHOTGUN2
;
4192 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4193 FWeapon
[WEAPON_SHOTGUN2
] := True;
4195 if gFlash
= 2 then Inc(FPickup
, 5);
4196 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4199 ITEM_WEAPON_CHAINGUN
:
4200 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or not FWeapon
[WEAPON_CHAINGUN
] then
4202 if a
and FWeapon
[WEAPON_CHAINGUN
] then Exit
;
4203 hadWeapon
:= FWeapon
[WEAPON_CHAINGUN
];
4204 switchWeapon
:= WEAPON_CHAINGUN
;
4205 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
4206 FWeapon
[WEAPON_CHAINGUN
] := True;
4208 if gFlash
= 2 then Inc(FPickup
, 5);
4209 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4212 ITEM_WEAPON_ROCKETLAUNCHER
:
4213 if (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or not FWeapon
[WEAPON_ROCKETLAUNCHER
] then
4215 if a
and FWeapon
[WEAPON_ROCKETLAUNCHER
] then Exit
;
4216 switchWeapon
:= WEAPON_ROCKETLAUNCHER
;
4217 hadWeapon
:= FWeapon
[WEAPON_ROCKETLAUNCHER
];
4218 IncMax(FAmmo
[A_ROCKETS
], 2, FMaxAmmo
[A_ROCKETS
]);
4219 FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
4221 if gFlash
= 2 then Inc(FPickup
, 5);
4222 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4226 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_PLASMA
] then
4228 if a
and FWeapon
[WEAPON_PLASMA
] then Exit
;
4229 switchWeapon
:= WEAPON_PLASMA
;
4230 hadWeapon
:= FWeapon
[WEAPON_PLASMA
];
4231 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
4232 FWeapon
[WEAPON_PLASMA
] := True;
4234 if gFlash
= 2 then Inc(FPickup
, 5);
4235 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4239 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_BFG
] then
4241 if a
and FWeapon
[WEAPON_BFG
] then Exit
;
4242 switchWeapon
:= WEAPON_BFG
;
4243 hadWeapon
:= FWeapon
[WEAPON_BFG
];
4244 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
4245 FWeapon
[WEAPON_BFG
] := True;
4247 if gFlash
= 2 then Inc(FPickup
, 5);
4248 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4251 ITEM_WEAPON_SUPERPULEMET
:
4252 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SUPERPULEMET
] then
4254 if a
and FWeapon
[WEAPON_SUPERPULEMET
] then Exit
;
4255 switchWeapon
:= WEAPON_SUPERPULEMET
;
4256 hadWeapon
:= FWeapon
[WEAPON_SUPERPULEMET
];
4257 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4258 FWeapon
[WEAPON_SUPERPULEMET
] := True;
4260 if gFlash
= 2 then Inc(FPickup
, 5);
4261 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4264 ITEM_WEAPON_FLAMETHROWER
:
4265 if (FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
]) or not FWeapon
[WEAPON_FLAMETHROWER
] then
4267 if a
and FWeapon
[WEAPON_FLAMETHROWER
] then Exit
;
4268 switchWeapon
:= WEAPON_FLAMETHROWER
;
4269 hadWeapon
:= FWeapon
[WEAPON_FLAMETHROWER
];
4270 IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
4271 FWeapon
[WEAPON_FLAMETHROWER
] := True;
4273 if gFlash
= 2 then Inc(FPickup
, 5);
4274 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4278 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
4280 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
4283 if gFlash
= 2 then Inc(FPickup
, 5);
4286 ITEM_AMMO_BULLETS_BOX
:
4287 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
4289 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
4292 if gFlash
= 2 then Inc(FPickup
, 5);
4296 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
4298 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4301 if gFlash
= 2 then Inc(FPickup
, 5);
4304 ITEM_AMMO_SHELLS_BOX
:
4305 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
4307 IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
4310 if gFlash
= 2 then Inc(FPickup
, 5);
4314 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
4316 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
4319 if gFlash
= 2 then Inc(FPickup
, 5);
4322 ITEM_AMMO_ROCKET_BOX
:
4323 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
4325 IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
4328 if gFlash
= 2 then Inc(FPickup
, 5);
4332 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
4334 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
4337 if gFlash
= 2 then Inc(FPickup
, 5);
4341 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
4343 IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
4346 if gFlash
= 2 then Inc(FPickup
, 5);
4350 if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then
4352 IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
4355 if gFlash
= 2 then Inc(FPickup
, 5);
4359 if not(R_ITEM_BACKPACK
in FRulez
) or
4360 (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
4361 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
4362 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
4363 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or
4364 (FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
]) then
4366 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[1, A_BULLETS
];
4367 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[1, A_SHELLS
];
4368 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[1, A_ROCKETS
];
4369 FMaxAmmo
[A_CELLS
] := AmmoLimits
[1, A_CELLS
];
4370 FMaxAmmo
[A_FUEL
] := AmmoLimits
[1, A_FUEL
];
4372 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
4373 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
4374 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
4375 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4376 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
4377 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
4378 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
4379 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
4380 if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then
4381 IncMax(FAmmo
[A_FUEL
], 50, FMaxAmmo
[A_FUEL
]);
4383 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
4386 if gFlash
= 2 then Inc(FPickup
, 5);
4390 if not(R_KEY_RED
in FRulez
) then
4392 Include(FRulez
, R_KEY_RED
);
4394 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
4395 if gFlash
= 2 then Inc(FPickup
, 5);
4396 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
4400 if not(R_KEY_GREEN
in FRulez
) then
4402 Include(FRulez
, R_KEY_GREEN
);
4404 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
4405 if gFlash
= 2 then Inc(FPickup
, 5);
4406 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
4410 if not(R_KEY_BLUE
in FRulez
) then
4412 Include(FRulez
, R_KEY_BLUE
);
4414 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
4415 if gFlash
= 2 then Inc(FPickup
, 5);
4416 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
4420 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
4422 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
4426 if gFlash
= 2 then Inc(FPickup
, 5);
4430 if FAir
< AIR_MAX
then
4435 if gFlash
= 2 then Inc(FPickup
, 5);
4440 if not (R_BERSERK
in FRulez
) then
4442 Include(FRulez
, R_BERSERK
);
4443 if (FBFGFireCounter
= -1) then
4445 FCurrWeap
:= WEAPON_KASTET
;
4447 FModel
.SetWeapon(WEAPON_KASTET
);
4452 if gFlash
= 2 then Inc(FPickup
, 5);
4454 FBerserk
:= gTime
+30000;
4459 if (FHealth
< PLAYER_HP_SOFT
) or (FFireTime
> 0) then
4461 if FHealth
< PLAYER_HP_SOFT
then FHealth
:= PLAYER_HP_SOFT
;
4462 FBerserk
:= gTime
+30000;
4470 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
4472 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
4476 if gFlash
= 2 then Inc(FPickup
, 5);
4480 if (FHealth
< PLAYER_HP_LIMIT
) or (FFireTime
> 0) then
4482 if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
4486 if gFlash
= 2 then Inc(FPickup
, 5);
4490 if FArmor
< PLAYER_AP_LIMIT
then
4492 IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
4495 if gFlash
= 2 then Inc(FPickup
, 5);
4499 if FJetFuel
< JET_MAX
then
4501 FJetFuel
:= JET_MAX
;
4504 if gFlash
= 2 then Inc(FPickup
, 5);
4508 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
4510 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
4513 if gFlash
= 2 then Inc(FPickup
, 5);
4517 if (shouldSwitch(switchWeapon
, hadWeapon
)) then
4518 QueueWeaponSwitch(switchWeapon
);
4521 procedure TPlayer
.Touch();
4525 //FModel.PlaySound(MODELSOUND_PAIN, 1, FObj.X, FObj.Y);
4528 // Áðîñèòü ôëàã òîâàðèùó:
4529 if gGameSettings
.GameMode
= GM_CTF
then
4534 procedure TPlayer
.Push(vx
, vy
: Integer);
4536 if (not FPhysics
) and FGhost
then
4538 FObj
.Accel
.X
:= FObj
.Accel
.X
+ vx
;
4539 FObj
.Accel
.Y
:= FObj
.Accel
.Y
+ vy
;
4540 if g_Game_IsNet
and g_Game_IsServer
then
4541 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
4544 procedure TPlayer
.Reset(Force
: Boolean);
4550 FTime
[T_RESPAWN
] := 0;
4551 FTime
[T_FLAGCAP
] := 0;
4568 FSpectator
:= False;
4571 FSpectatePlayer
:= -1;
4572 FNoRespawn
:= False;
4574 FLives
:= gGameSettings
.MaxLives
;
4579 procedure TPlayer
.SoftReset();
4587 FBFGFireCounter
:= -1;
4595 SetAction(A_STAND
, True);
4598 function TPlayer
.GetRespawnPoint(): Byte;
4603 // Íà áóäóùåå: FSpawn - èãðîê óæå èãðàë è ïåðåðîæäàåòñÿ
4605 // Îäèíî÷íàÿ èãðà/êîîïåðàòèâ
4606 if gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
] then
4608 if Self
= gPlayer1
then
4610 // player 1 should try to spawn on the player 1 point
4611 if g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) > 0 then
4612 Exit(RESPAWNPOINT_PLAYER1
)
4613 else if g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) > 0 then
4614 Exit(RESPAWNPOINT_PLAYER2
);
4616 else if Self
= gPlayer2
then
4618 // player 2 should try to spawn on the player 2 point
4619 if g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) > 0 then
4620 Exit(RESPAWNPOINT_PLAYER2
)
4621 else if g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) > 0 then
4622 Exit(RESPAWNPOINT_PLAYER1
);
4626 // other players randomly pick either the first or the second point
4627 c
:= IfThen((Random(2) = 0), RESPAWNPOINT_PLAYER1
, RESPAWNPOINT_PLAYER2
);
4628 if g_Map_GetPointCount(c
) > 0 then
4630 // try the other one
4631 c
:= IfThen((c
= RESPAWNPOINT_PLAYER1
), RESPAWNPOINT_PLAYER2
, RESPAWNPOINT_PLAYER1
);
4632 if g_Map_GetPointCount(c
) > 0 then
4638 if gGameSettings
.GameMode
= GM_DM
then
4640 // try DM points first
4641 if g_Map_GetPointCount(RESPAWNPOINT_DM
) > 0 then
4642 Exit(RESPAWNPOINT_DM
);
4646 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
4648 // try team points first
4649 c
:= RESPAWNPOINT_DM
;
4650 if FTeam
= TEAM_RED
then
4651 c
:= RESPAWNPOINT_RED
4652 else if FTeam
= TEAM_BLUE
then
4653 c
:= RESPAWNPOINT_BLUE
;
4654 if g_Map_GetPointCount(c
) > 0 then
4658 // still haven't found a spawnpoint, try random shit
4659 Result
:= g_Map_GetRandomPointType();
4662 procedure TPlayer
.Respawn(Silent
: Boolean; Force
: Boolean = False);
4664 RespawnPoint
: TRespawnPoint
;
4672 FBFGFireCounter
:= -1;
4679 if not g_Game_IsServer
then
4683 FWantsInGame
:= True;
4684 FJustTeleported
:= True;
4687 FTime
[T_RESPAWN
] := 0;
4691 // if server changes MaxLives we gotta be ready
4692 if gGameSettings
.MaxLives
= 0 then FNoRespawn
:= False;
4694 // Åùå íåëüçÿ âîçðîäèòüñÿ:
4695 if FTime
[T_RESPAWN
] > gTime
then
4698 // Ïðîñðàë âñå æèçíè:
4701 if not FSpectator
then Spectate(True);
4702 FWantsInGame
:= True;
4706 if (gGameSettings
.GameType
<> GT_SINGLE
) and (gGameSettings
.GameMode
<> GM_COOP
) then
4707 begin // "Ñâîÿ èãðà"
4708 // Áåðñåðê íå ñîõðàíÿåòñÿ ìåæäó óðîâíÿìè:
4709 FRulez
:= FRulez
-[R_BERSERK
];
4711 else // "Îäèíî÷íàÿ èãðà"/"Êîîï"
4713 // Áåðñåðê è êëþ÷è íå ñîõðàíÿþòñÿ ìåæäó óðîâíÿìè:
4714 FRulez
:= FRulez
-[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
, R_BERSERK
];
4717 // Ïîëó÷àåì òî÷êó ñïàóíà èãðîêà:
4718 c
:= GetRespawnPoint();
4723 // Âîñêðåøåíèå áåç îðóæèÿ:
4726 FHealth
:= Round(PLAYER_HP_SOFT
* (FHandicap
/ 100));
4732 for a
:= WP_FIRST
to WP_LAST
do
4734 FWeapon
[a
] := False;
4738 FWeapon
[WEAPON_PISTOL
] := True;
4739 FWeapon
[WEAPON_KASTET
] := True;
4740 FCurrWeap
:= WEAPON_PISTOL
;
4743 FModel
.SetWeapon(FCurrWeap
);
4745 for b
:= A_BULLETS
to A_HIGH
do
4748 FAmmo
[A_BULLETS
] := 50;
4750 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[0, A_BULLETS
];
4751 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[0, A_SHELLS
];
4752 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[0, A_SHELLS
];
4753 FMaxAmmo
[A_CELLS
] := AmmoLimits
[0, A_CELLS
];
4754 FMaxAmmo
[A_FUEL
] := AmmoLimits
[0, A_FUEL
];
4756 if (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
]) and
4757 LongBool(gGameSettings
.Options
and GAME_OPTION_DMKEYS
) then
4758 FRulez
:= [R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
]
4763 // Ïîëó÷àåì êîîðäèíàòû òî÷êè âîçðîæäåíèÿ:
4764 if not g_Map_GetPoint(c
, RespawnPoint
) then
4766 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
4770 // Óñòàíîâêà êîîðäèíàò è ñáðîñ âñåõ ïàðàìåòðîâ:
4771 FObj
.X
:= RespawnPoint
.X
-PLAYER_RECT
.X
;
4772 FObj
.Y
:= RespawnPoint
.Y
-PLAYER_RECT
.Y
;
4773 FObj
.oldX
:= FObj
.X
; // don't interpolate after respawn
4774 FObj
.oldY
:= FObj
.Y
;
4780 FDirection
:= RespawnPoint
.Direction
;
4781 if FDirection
= TDirection
.D_LEFT
then
4786 SetAction(A_STAND
, True);
4787 FModel
.Direction
:= FDirection
;
4789 for a
:= Low(FTime
) to High(FTime
) do
4792 for a
:= Low(FMegaRulez
) to High(FMegaRulez
) do
4795 // Respawn invulnerability
4796 if (gGameSettings
.GameType
<> GT_SINGLE
) and (gGameSettings
.SpawnInvul
> 0) then
4798 FMegaRulez
[MR_INVUL
] := gTime
+ gGameSettings
.SpawnInvul
* 1000;
4799 FSpawnInvul
:= FMegaRulez
[MR_INVUL
];
4804 FCanJetpack
:= False;
4810 // Àíèìàöèÿ âîçðîæäåíèÿ:
4811 if (not gLoadGameMode
) and (not Silent
) then
4812 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
4814 Anim
:= TAnimation
.Create(ID
, False, 3);
4815 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4816 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4820 FSpectator
:= False;
4823 FSpectatePlayer
:= -1;
4826 if (gPlayer1
= nil) and (gSpectLatchPID1
= FUID
) then
4828 if (gPlayer2
= nil) and (gSpectLatchPID2
= FUID
) then
4831 if g_Game_IsNet
then
4833 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
4834 MH_SEND_PlayerStats(FUID
, NET_EVERYONE
);
4836 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4837 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32,
4842 procedure TPlayer
.Spectate(NoMove
: Boolean = False);
4845 Kill(K_EXTRAHARDKILL
, FUID
, HIT_SOME
)
4846 else if (not NoMove
) then
4848 GameX
:= gMapInfo
.Width
div 2;
4849 GameY
:= gMapInfo
.Height
div 2;
4858 FWantsInGame
:= False;
4864 if Self
= gPlayer1
then
4866 gSpectLatchPID1
:= FUID
;
4869 else if Self
= gPlayer2
then
4871 gSpectLatchPID2
:= FUID
;
4876 if g_Game_IsNet
then
4877 MH_SEND_PlayerStats(FUID
);
4880 procedure TPlayer
.SwitchNoClip
;
4884 FGhost
:= not FGhost
;
4885 FPhysics
:= not FGhost
;
4897 procedure TPlayer
.Run(Direction
: TDirection
);
4901 if MAX_RUNVEL
> 8 then
4905 if Direction
= TDirection
.D_LEFT
then
4907 if FObj
.Vel
.X
> -MAX_RUNVEL
then
4908 FObj
.Vel
.X
:= FObj
.Vel
.X
- (MAX_RUNVEL
shr 3);
4911 if FObj
.Vel
.X
< MAX_RUNVEL
then
4912 FObj
.Vel
.X
:= FObj
.Vel
.X
+ (MAX_RUNVEL
shr 3);
4914 // Âîçìîæíî, ïèíàåì êóñêè:
4915 if (FObj
.Vel
.X
<> 0) and (gGibs
<> nil) then
4917 b
:= Abs(FObj
.Vel
.X
);
4918 if b
> 1 then b
:= b
* (Random(8 div b
) + 1);
4919 for a
:= 0 to High(gGibs
) do
4921 if gGibs
[a
].alive
and
4922 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
+FObj
.Rect
.Height
-4,
4923 FObj
.Rect
.Width
, 8, @gGibs
[a
].Obj
) and (Random(3) = 0) then
4926 if FObj
.Vel
.X
< 0 then
4928 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)+120) // íàëåâî
4932 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)); // íàïðàâî
4934 gGibs
[a
].positionChanged(); // this updates spatial accelerators
4942 procedure TPlayer
.SeeDown();
4944 SetAction(A_SEEDOWN
);
4946 if FDirection
= TDirection
.D_LEFT
then FAngle
:= ANGLE_LEFTDOWN
else FAngle
:= ANGLE_RIGHTDOWN
;
4948 if FIncCam
> -120 then DecMin(FIncCam
, 5, -120);
4951 procedure TPlayer
.SeeUp();
4955 if FDirection
= TDirection
.D_LEFT
then FAngle
:= ANGLE_LEFTUP
else FAngle
:= ANGLE_RIGHTUP
;
4957 if FIncCam
< 120 then IncMax(FIncCam
, 5, 120);
4960 procedure TPlayer
.SetAction(Action
: Byte; Force
: Boolean = False);
4968 A_ATTACK
: Prior
:= 2;
4969 A_SEEUP
: Prior
:= 1;
4970 A_SEEDOWN
: Prior
:= 1;
4971 A_ATTACKUP
: Prior
:= 2;
4972 A_ATTACKDOWN
: Prior
:= 2;
4977 if (Prior
> FActionPrior
) or Force
then
4978 if not ((Prior
= 2) and (FCurrWeap
= WEAPON_SAW
)) then
4980 FActionPrior
:= Prior
;
4981 FActionAnim
:= Action
;
4982 FActionForce
:= Force
;
4983 FActionChanged
:= True;
4986 if Action
in [A_ATTACK
, A_ATTACKUP
, A_ATTACKDOWN
] then FModel
.SetFire(True);
4989 function TPlayer
.StayOnStep(XInc
, YInc
: Integer): Boolean;
4991 Result
:= not g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
-1,
4992 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False)
4993 and g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
,
4994 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False);
4997 function TPlayer
.TeleportTo(X
, Y
: Integer; silent
: Boolean; dir
: Byte): Boolean;
5004 if g_CollideLevel(X
, Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
) then
5006 g_Sound_PlayExAt('SOUND_GAME_NOTELEPORT', FObj
.X
, FObj
.Y
);
5007 if g_Game_IsServer
and g_Game_IsNet
then
5008 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_GAME_NOTELEPORT');
5012 FJustTeleported
:= True;
5017 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
5019 Anim
:= TAnimation
.Create(ID
, False, 3);
5022 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', FObj
.X
, FObj
.Y
);
5023 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
5024 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
5025 if g_Game_IsServer
and g_Game_IsNet
then
5026 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
5027 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 1,
5031 FObj
.X
:= X
-PLAYER_RECT
.X
;
5032 FObj
.Y
:= Y
-PLAYER_RECT
.Y
;
5033 FObj
.oldX
:= FObj
.X
; // don't interpolate after respawn
5034 FObj
.oldY
:= FObj
.Y
;
5035 if FAlive
and FGhost
then
5041 if not g_Game_IsNet
then
5045 SetDirection(TDirection
.D_LEFT
);
5051 SetDirection(TDirection
.D_RIGHT
);
5057 if FDirection
= TDirection
.D_RIGHT
then
5059 SetDirection(TDirection
.D_LEFT
);
5064 SetDirection(TDirection
.D_RIGHT
);
5070 if not silent
and (Anim
<> nil) then
5072 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
5073 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
5076 if g_Game_IsServer
and g_Game_IsNet
then
5077 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
5078 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 0,
5085 function nonz(a
: Single): Single;
5093 function TPlayer
.refreshCorpse(): Boolean;
5099 if FAlive
or FSpectator
then
5101 if (gCorpses
= nil) or (Length(gCorpses
) = 0) then
5103 for i
:= 0 to High(gCorpses
) do
5104 if gCorpses
[i
] <> nil then
5105 if gCorpses
[i
].FPlayerUID
= FUID
then
5113 function TPlayer
.getCameraObj(): TObj
;
5115 if (not FAlive
) and (not FSpectator
) and
5116 (FCorpse
>= 0) and (FCorpse
< Length(gCorpses
)) and
5117 (gCorpses
[FCorpse
] <> nil) and (gCorpses
[FCorpse
].FPlayerUID
= FUID
) then
5119 gCorpses
[FCorpse
].FObj
.slopeUpLeft
:= FObj
.slopeUpLeft
;
5120 Result
:= gCorpses
[FCorpse
].FObj
;
5128 procedure TPlayer
.PreUpdate();
5130 FSlopeOld
:= FObj
.slopeUpLeft
;
5131 FIncCamOld
:= FIncCam
;
5132 FObj
.oldX
:= FObj
.X
;
5133 FObj
.oldY
:= FObj
.Y
;
5136 procedure TPlayer
.Update();
5139 i
, ii
, wx
, wy
, xd
, yd
, k
: Integer;
5140 blockmon
, headwater
, dospawn
: Boolean;
5145 NetServer
:= g_Game_IsNet
and g_Game_IsServer
;
5146 AnyServer
:= g_Game_IsServer
;
5148 if g_Game_IsClient
and (NetInterpLevel
> 0) then
5149 DoLerp(NetInterpLevel
+ 1)
5155 if (FClientID
>= 0) and (NetClients
[FClientID
].Peer
<> nil) then
5157 FPing
:= NetClients
[FClientID
].Peer
^.lastRoundTripTime
;
5158 if NetClients
[FClientID
].Peer
^.packetsSent
> 0 then
5159 FLoss
:= Round(100*NetClients
[FClientID
].Peer
^.packetsLost
/NetClients
[FClientID
].Peer
^.packetsSent
)
5168 if FAlive
and (FPunchAnim
<> nil) then
5169 FPunchAnim
.Update();
5171 if FAlive
and (gFly
or FJetpack
) then
5174 if FDirection
= TDirection
.D_LEFT
then
5179 if FAlive
and (not FGhost
) then
5181 if FKeys
[KEY_UP
].Pressed
then
5183 if FKeys
[KEY_DOWN
].Pressed
then
5187 if (not (FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_DOWN
].Pressed
)) and
5190 i
:= g_basic
.Sign(FIncCam
);
5191 FIncCam
:= Abs(FIncCam
);
5192 DecMin(FIncCam
, 5, 0);
5193 FIncCam
:= FIncCam
*i
;
5196 if gTime
mod (GAME_TICK
*2) <> 0 then
5198 if (FObj
.Vel
.X
= 0) and FAlive
then
5200 if FKeys
[KEY_LEFT
].Pressed
then
5201 Run(TDirection
.D_LEFT
);
5202 if FKeys
[KEY_RIGHT
].Pressed
then
5203 Run(TDirection
.D_RIGHT
);
5208 g_Obj_Move(@FObj
, True, True, True);
5209 positionChanged(); // this updates spatial accelerators
5215 FActionChanged
:= False;
5219 // Let alive player do some actions
5220 if FKeys
[KEY_LEFT
].Pressed
then Run(TDirection
.D_LEFT
);
5221 if FKeys
[KEY_RIGHT
].Pressed
then Run(TDirection
.D_RIGHT
);
5222 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then Fire()
5228 if NetServer
then MH_SEND_PlayerStats(FUID
);
5231 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Use();
5232 if FKeys
[KEY_JUMP
].Pressed
then Jump()
5235 if AnyServer
and FJetpack
then
5239 if NetServer
then MH_SEND_PlayerStats(FUID
);
5241 FCanJetpack
:= True;
5248 for k
:= Low(FKeys
) to KEY_CHAT
-1 do
5250 if FKeys
[k
].Pressed
then
5258 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
5261 if (FTime
[T_RESPAWN
] <= gTime
) and
5262 gGameOn
and (not FAlive
) then
5264 if (g_Player_GetCount() > 1) then
5268 gExit
:= EXIT_RESTART
;
5273 // Dead spectator actions
5276 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Fire();
5277 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then
5281 if (FSpectatePlayer
>= High(gPlayers
)) then
5282 FSpectatePlayer
:= -1
5286 for I
:= FSpectatePlayer
+ 1 to High(gPlayers
) do
5287 if gPlayers
[I
] <> nil then
5288 if gPlayers
[I
].alive
then
5289 if gPlayers
[I
].UID
<> FUID
then
5291 FSpectatePlayer
:= I
;
5296 if not SetSpect
then FSpectatePlayer
:= -1;
5307 if FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_JUMP
].Pressed
then
5309 FYTo
:= FObj
.Y
- 32;
5310 FSpectatePlayer
:= -1;
5312 if FKeys
[KEY_DOWN
].Pressed
then
5314 FYTo
:= FObj
.Y
+ 32;
5315 FSpectatePlayer
:= -1;
5317 if FKeys
[KEY_LEFT
].Pressed
then
5319 FXTo
:= FObj
.X
- 32;
5320 FSpectatePlayer
:= -1;
5322 if FKeys
[KEY_RIGHT
].Pressed
then
5324 FXTo
:= FObj
.X
+ 32;
5325 FSpectatePlayer
:= -1;
5328 if (FXTo
< -64) then
5330 else if (FXTo
> gMapInfo
.Width
+ 32) then
5331 FXTo
:= gMapInfo
.Width
+ 32;
5332 if (FYTo
< -72) then
5334 else if (FYTo
> gMapInfo
.Height
+ 32) then
5335 FYTo
:= gMapInfo
.Height
+ 32;
5340 g_Obj_Move(@FObj
, True, True, True);
5341 positionChanged(); // this updates spatial accelerators
5348 if (FSpectatePlayer
<= High(gPlayers
)) and (FSpectatePlayer
>= 0) then
5349 if gPlayers
[FSpectatePlayer
] <> nil then
5350 if gPlayers
[FSpectatePlayer
].alive
then
5352 FXTo
:= gPlayers
[FSpectatePlayer
].GameX
;
5353 FYTo
:= gPlayers
[FSpectatePlayer
].GameY
;
5357 blockmon
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
, FObj
.Y
+PLAYER_HEADRECT
.Y
,
5358 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
5359 PANEL_BLOCKMON
, True);
5360 headwater
:= HeadInLiquid(0, 0);
5362 // Ñîïðîòèâëåíèå âîçäóõà:
5363 if (not FAlive
) or not (FKeys
[KEY_LEFT
].Pressed
or FKeys
[KEY_RIGHT
].Pressed
) then
5364 if FObj
.Vel
.X
<> 0 then
5365 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
5367 if (FLastHit
= HIT_TRAP
) and (FPain
> 90) then FPain
:= 90;
5368 DecMin(FPain
, 5, 0);
5369 DecMin(FPickup
, 1, 0);
5371 if FAlive
and (FObj
.Y
> Integer(gMapInfo
.Height
)+128) and AnyServer
then
5373 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
5374 FMegaRulez
[MR_SUIT
] := 0;
5375 FMegaRulez
[MR_INVUL
] := 0;
5376 FMegaRulez
[MR_INVIS
] := 0;
5377 Kill(K_FALLKILL
, 0, HIT_FALL
);
5384 if FCurrWeap
= WEAPON_SAW
then
5385 if not (FSawSound
.IsPlaying() or FSawSoundHit
.IsPlaying() or
5386 FSawSoundSelect
.IsPlaying()) then
5387 FSawSoundIdle
.PlayAt(FObj
.X
, FObj
.Y
);
5390 if (not FJetSoundFly
.IsPlaying()) and (not FJetSoundOn
.IsPlaying()) and
5391 (not FJetSoundOff
.IsPlaying()) then
5393 FJetSoundFly
.SetPosition(0);
5394 FJetSoundFly
.PlayAt(FObj
.X
, FObj
.Y
);
5397 for b
:= WP_FIRST
to WP_LAST
do
5398 if FReloading
[b
] > 0 then
5404 if FShellTimer
> -1 then
5405 if FShellTimer
= 0 then
5407 if FShellType
= SHELL_SHELL
then
5408 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5409 GameVelX
, GameVelY
-2, SHELL_SHELL
)
5410 else if FShellType
= SHELL_DBLSHELL
then
5412 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5413 GameVelX
+1, GameVelY
-2, SHELL_SHELL
);
5414 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5415 GameVelX
-1, GameVelY
-2, SHELL_SHELL
);
5418 end else Dec(FShellTimer
);
5420 if (FBFGFireCounter
> -1) then
5421 if FBFGFireCounter
= 0 then
5425 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
5426 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
5427 xd
:= wx
+IfThen(FDirection
= TDirection
.D_LEFT
, -30, 30);
5428 yd
:= wy
+firediry();
5429 g_Weapon_bfgshot(wx
, wy
, xd
, yd
, FUID
);
5430 if NetServer
then MH_SEND_PlayerFire(FUID
, WEAPON_BFG
, wx
, wy
, xd
, yd
);
5431 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
5432 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
5433 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
5436 FReloading
[WEAPON_BFG
] := WEAPON_RELOAD
[WEAPON_BFG
];
5437 FBFGFireCounter
:= -1;
5440 FBFGFireCounter
:= 0
5442 Dec(FBFGFireCounter
);
5444 if (FMegaRulez
[MR_SUIT
] < gTime
) and AnyServer
then
5446 b
:= g_GetAcidHit(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
);
5448 if (b
> 0) and (gTime
mod (15*GAME_TICK
) = 0) then Damage(b
, 0, 0, 0, HIT_ACID
);
5451 if (headwater
or blockmon
) then
5457 if AnyServer
then Damage(10, 0, 0, 0, HIT_WATER
);
5460 else if (FAir
mod 31 = 0) and not blockmon
then
5461 g_Game_Effect_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
5462 FObj
.Y
+PLAYER_RECT
.Y
-4, 5+Random(6), 8, 4);
5463 end else if FAir
< AIR_DEF
then
5466 if FFireTime
> 0 then
5468 if BodyInLiquid(0, 0) then
5473 else if FMegaRulez
[MR_SUIT
] >= gTime
then
5475 if FMegaRulez
[MR_SUIT
] = gTime
then
5482 if FFirePainTime
<= 0 then
5484 if g_Game_IsServer
then
5485 Damage(2, FFireAttacker
, 0, 0, HIT_FLAME
);
5486 FFirePainTime
:= 12 - FFireTime
div 12;
5488 FFirePainTime
:= FFirePainTime
- 1;
5489 FFireTime
:= FFireTime
- 1;
5490 if ((FFireTime
mod 33) = 0) and (FMegaRulez
[MR_INVUL
] < gTime
) then
5491 FModel
.PlaySound(MODELSOUND_PAIN
, 1, FObj
.X
, FObj
.Y
);
5492 if (FFireTime
= 0) and g_Game_IsNet
and g_Game_IsServer
then
5493 MH_SEND_PlayerStats(FUID
);
5497 if FDamageBuffer
> 0 then
5499 if FDamageBuffer
>= 9 then
5503 if FDamageBuffer
< 30 then i
:= 9
5504 else if FDamageBuffer
< 100 then i
:= 18
5508 ii
:= Round(FDamageBuffer
*FHealth
/ nonz(FArmor
*(3/4)+FHealth
));
5509 FArmor
:= FArmor
-(FDamageBuffer
-ii
);
5510 FHealth
:= FHealth
-ii
;
5513 FHealth
:= FHealth
+FArmor
;
5518 if FHealth
<= 0 then
5519 if FHealth
> -30 then Kill(K_SIMPLEKILL
, FLastSpawnerUID
, FLastHit
)
5520 else if FHealth
> -50 then Kill(K_HARDKILL
, FLastSpawnerUID
, FLastHit
)
5521 else Kill(K_EXTRAHARDKILL
, FLastSpawnerUID
, FLastHit
);
5523 if FAlive
and ((FLastHit
<> HIT_FLAME
) or (FFireTime
<= 0)) then
5525 if FDamageBuffer
<= 20 then FModel
.PlaySound(MODELSOUND_PAIN
, 1, FObj
.X
, FObj
.Y
)
5526 else if FDamageBuffer
<= 55 then FModel
.PlaySound(MODELSOUND_PAIN
, 2, FObj
.X
, FObj
.Y
)
5527 else if FDamageBuffer
<= 120 then FModel
.PlaySound(MODELSOUND_PAIN
, 3, FObj
.X
, FObj
.Y
)
5528 else FModel
.PlaySound(MODELSOUND_PAIN
, 4, FObj
.X
, FObj
.Y
);
5535 end; // if FAlive then ...
5537 if (FActionAnim
= A_PAIN
) and (FModel
.Animation
<> A_PAIN
) then
5539 FModel
.ChangeAnimation(FActionAnim
, FActionForce
);
5540 FModel
.GetCurrentAnimation
.MinLength
:= i
;
5541 FModel
.GetCurrentAnimationMask
.MinLength
:= i
;
5542 end else FModel
.ChangeAnimation(FActionAnim
, FActionForce
and (FModel
.Animation
<> A_STAND
));
5544 if (FModel
.GetCurrentAnimation
.Played
or ((not FActionChanged
) and (FModel
.Animation
= A_WALK
)))
5545 then SetAction(A_STAND
, True);
5547 if not ((FModel
.Animation
= A_WALK
) and (Abs(FObj
.Vel
.X
) < 4) and not FModel
.Fire
) then FModel
.Update
;
5549 for b
:= Low(FKeys
) to High(FKeys
) do
5550 if FKeys
[b
].Time
= 0 then FKeys
[b
].Pressed
:= False else Dec(FKeys
[b
].Time
);
5554 procedure TPlayer
.getMapBox (out x
, y
, w
, h
: Integer); inline;
5556 x
:= FObj
.X
+PLAYER_RECT
.X
;
5557 y
:= FObj
.Y
+PLAYER_RECT
.Y
;
5558 w
:= PLAYER_RECT
.Width
;
5559 h
:= PLAYER_RECT
.Height
;
5563 procedure TPlayer
.moveBy (dx
, dy
: Integer); inline;
5565 if (dx
<> 0) or (dy
<> 0) then
5574 function TPlayer
.Collide(X
, Y
: Integer; Width
, Height
: Word): Boolean;
5576 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
5577 FObj
.Y
+PLAYER_RECT
.Y
,
5584 function TPlayer
.Collide(Panel
: TPanel
): Boolean;
5586 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
5587 FObj
.Y
+PLAYER_RECT
.Y
,
5591 Panel
.Width
, Panel
.Height
);
5594 function TPlayer
.Collide(X
, Y
: Integer): Boolean;
5596 X
:= X
-FObj
.X
-PLAYER_RECT
.X
;
5597 Y
:= Y
-FObj
.Y
-PLAYER_RECT
.Y
;
5598 Result
:= (x
>= 0) and (x
<= PLAYER_RECT
.Width
) and
5599 (y
>= 0) and (y
<= PLAYER_RECT
.Height
);
5602 function g_Player_ExistingName(Name
: string): Boolean;
5608 if gPlayers
= nil then Exit
;
5610 for a
:= 0 to High(gPlayers
) do
5611 if gPlayers
[a
] <> nil then
5612 if LowerCase(Name
) = LowerCase(gPlayers
[a
].FName
) then
5619 procedure TPlayer
.SetDirection(Direction
: TDirection
);
5623 d
:= FModel
.Direction
;
5625 FModel
.Direction
:= Direction
;
5626 if d
<> Direction
then FModel
.ChangeAnimation(FModel
.Animation
, True);
5628 FDirection
:= Direction
;
5631 function TPlayer
.GetKeys(): Byte;
5635 if R_KEY_RED
in FRulez
then Result
:= KEY_RED
;
5636 if R_KEY_GREEN
in FRulez
then Result
:= Result
or KEY_GREEN
;
5637 if R_KEY_BLUE
in FRulez
then Result
:= Result
or KEY_BLUE
;
5639 if FTeam
= TEAM_RED
then Result
:= Result
or KEY_REDTEAM
;
5640 if FTeam
= TEAM_BLUE
then Result
:= Result
or KEY_BLUETEAM
;
5643 procedure TPlayer
.Use();
5647 if FTime
[T_USE
] > gTime
then Exit
;
5649 g_Triggers_PressR(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
,
5650 PLAYER_RECT
.Height
, FUID
, ACTIVATE_PLAYERPRESS
);
5652 for a
:= 0 to High(gPlayers
) do
5653 if (gPlayers
[a
] <> nil) and (gPlayers
[a
] <> Self
) and
5654 gPlayers
[a
].alive
and SameTeam(FUID
, gPlayers
[a
].FUID
) and
5655 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
5656 FObj
.Rect
.Width
, FObj
.Rect
.Height
, @gPlayers
[a
].FObj
) then
5658 gPlayers
[a
].Touch();
5659 if g_Game_IsNet
and g_Game_IsServer
then
5660 MH_SEND_GameEvent(NET_EV_PLAYER_TOUCH
, gPlayers
[a
].FUID
);
5663 FTime
[T_USE
] := gTime
+120;
5666 procedure TPlayer
.NetFire(Wpn
: Byte; X
, Y
, AX
, AY
: Integer; WID
: Integer = -1);
5669 visible
: Boolean = True;
5670 WX
, WY
, XD
, YD
: Integer;
5682 if R_BERSERK
in FRulez
then
5684 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
5685 locobj
.X
:= FObj
.X
+FObj
.Rect
.X
;
5686 locobj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
5689 locobj
.rect
.Width
:= 39;
5690 locobj
.rect
.Height
:= 52;
5691 locobj
.Vel
.X
:= (xd
-wx
) div 2;
5692 locobj
.Vel
.Y
:= (yd
-wy
) div 2;
5693 locobj
.Accel
.X
:= xd
-wx
;
5694 locobj
.Accel
.y
:= yd
-wy
;
5696 if g_Weapon_Hit(@locobj
, 50, FUID
, HIT_SOME
) <> 0 then
5697 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
5699 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
5703 FPain
:= min(FPain
+ 25, 50);
5705 g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
5710 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
5711 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
5713 FSawSoundSelect
.Stop();
5715 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
5717 else if not FSawSoundHit
.IsPlaying() then
5719 FSawSoundSelect
.Stop();
5720 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
5726 g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', GameX
, Gamey
);
5727 FFireAngle
:= FAngle
;
5728 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5729 GameVelX
, GameVelY
-2, SHELL_BULLET
);
5734 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
5735 FFireAngle
:= FAngle
;
5737 FShellType
:= SHELL_SHELL
;
5742 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN2', Gamex
, Gamey
);
5743 FFireAngle
:= FAngle
;
5745 FShellType
:= SHELL_DBLSHELL
;
5750 g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', Gamex
, Gamey
);
5751 FFireAngle
:= FAngle
;
5752 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5753 GameVelX
, GameVelY
-2, SHELL_BULLET
);
5756 WEAPON_ROCKETLAUNCHER
:
5758 g_Weapon_Rocket(wx
, wy
, xd
, yd
, FUID
, WID
);
5759 FFireAngle
:= FAngle
;
5764 g_Weapon_Plasma(wx
, wy
, xd
, yd
, FUID
, WID
);
5765 FFireAngle
:= FAngle
;
5770 g_Weapon_BFGShot(wx
, wy
, xd
, yd
, FUID
, WID
);
5771 FFireAngle
:= FAngle
;
5774 WEAPON_SUPERPULEMET
:
5776 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
5777 FFireAngle
:= FAngle
;
5778 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5779 GameVelX
, GameVelY
-2, SHELL_SHELL
);
5782 WEAPON_FLAMETHROWER
:
5784 g_Weapon_flame(wx
, wy
, xd
, yd
, FUID
, WID
);
5786 FFireAngle
:= FAngle
;
5790 if not visible
then Exit
;
5792 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
5793 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
5794 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
5797 procedure TPlayer
.DoLerp(Level
: Integer = 2);
5799 if FObj
.X
<> FXTo
then FObj
.X
:= Lerp(FObj
.X
, FXTo
, Level
);
5800 if FObj
.Y
<> FYTo
then FObj
.Y
:= Lerp(FObj
.Y
, FYTo
, Level
);
5803 procedure TPlayer
.SetLerp(XTo
, YTo
: Integer);
5809 if FJustTeleported
or (NetInterpLevel
< 1) then
5813 if FJustTeleported
then
5815 FObj
.oldX
:= FObj
.X
;
5816 FObj
.oldY
:= FObj
.Y
;
5821 AX
:= Abs(FXTo
- FObj
.X
);
5822 AY
:= Abs(FYTo
- FObj
.Y
);
5823 if (AX
> 32) or (AX
<= NetInterpLevel
) then
5825 if (AY
> 32) or (AY
<= NetInterpLevel
) then
5830 function TPlayer
.FullInLift(XInc
, YInc
: Integer): Integer;
5832 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5833 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5834 PANEL_LIFTUP
, False) then Result
:= -1
5836 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5837 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5838 PANEL_LIFTDOWN
, False) then Result
:= 1
5842 function TPlayer
.GetFlag(Flag
: Byte): Boolean;
5849 if Flag
= FLAG_NONE
then
5852 if not g_Game_IsServer
then Exit
;
5854 // Ïðèíåñ ÷óæîé ôëàã íà ñâîþ áàçó:
5855 if (Flag
= FTeam
) and
5856 (gFlags
[Flag
].State
= FLAG_STATE_NORMAL
) and
5857 (FFlag
<> FLAG_NONE
) then
5859 if FFlag
= FLAG_RED
then
5860 s
:= _lc
[I_PLAYER_FLAG_RED
]
5862 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5864 evtype
:= FLAG_STATE_SCORED
;
5866 ts
:= Format('%.4d', [gFlags
[FFlag
].CaptureTime
]);
5867 Insert('.', ts
, Length(ts
) + 1 - 3);
5868 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_CAPTURE
], [FName
, s
, ts
]), True);
5870 g_Map_ResetFlag(FFlag
);
5871 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_CAPTURE
], [AnsiUpperCase(s
)]), 144);
5873 if ((Self
= gPlayer1
) or (Self
= gPlayer2
)
5874 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= FTeam
))
5875 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= FTeam
))) then
5880 if not sound_cap_flag
[a
].IsPlaying() then
5881 sound_cap_flag
[a
].Play();
5883 gTeamStat
[FTeam
].Score
+= 1;
5886 if g_Game_IsNet
then
5888 MH_SEND_FlagEvent(evtype
, FFlag
, FUID
, False);
5892 gFlags
[FFlag
].CaptureTime
:= 0;
5897 // Ïîäîáðàë ñâîé ôëàã - âåðíóë åãî íà áàçó:
5898 if (Flag
= FTeam
) and
5899 (gFlags
[Flag
].State
= FLAG_STATE_DROPPED
) then
5901 if Flag
= FLAG_RED
then
5902 s
:= _lc
[I_PLAYER_FLAG_RED
]
5904 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5906 evtype
:= FLAG_STATE_RETURNED
;
5907 gFlags
[Flag
].CaptureTime
:= 0;
5909 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_RETURN
], [FName
, s
]), True);
5911 g_Map_ResetFlag(Flag
);
5912 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
5914 if ((Self
= gPlayer1
) or (Self
= gPlayer2
)
5915 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= FTeam
))
5916 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= FTeam
))) then
5921 if not sound_ret_flag
[a
].IsPlaying() then
5922 sound_ret_flag
[a
].Play();
5925 if g_Game_IsNet
then
5927 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5933 // Ïîäîáðàë ÷óæîé ôëàã:
5934 if (Flag
<> FTeam
) and (FTime
[T_FLAGCAP
] <= gTime
) then
5938 if Flag
= FLAG_RED
then
5939 s
:= _lc
[I_PLAYER_FLAG_RED
]
5941 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5943 evtype
:= FLAG_STATE_CAPTURED
;
5945 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_GET
], [FName
, s
]), True);
5947 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_GET
], [AnsiUpperCase(s
)]), 144);
5949 gFlags
[Flag
].State
:= FLAG_STATE_CAPTURED
;
5951 if ((Self
= gPlayer1
) or (Self
= gPlayer2
)
5952 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= FTeam
))
5953 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= FTeam
))) then
5958 if not sound_get_flag
[a
].IsPlaying() then
5959 sound_get_flag
[a
].Play();
5962 if g_Game_IsNet
then
5964 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5970 procedure TPlayer
.SetFlag(Flag
: Byte);
5973 if FModel
<> nil then
5974 FModel
.SetFlag(FFlag
);
5977 function TPlayer
.TryDropFlag(): Boolean;
5979 if LongBool(gGameSettings
.Options
and GAME_OPTION_ALLOWDROPFLAG
) then
5980 Result
:= DropFlag(False, LongBool(gGameSettings
.Options
and GAME_OPTION_THROWFLAG
))
5985 function TPlayer
.DropFlag(Silent
: Boolean = True; DoThrow
: Boolean = False): Boolean;
5992 if (not g_Game_IsServer
) or (FFlag
= FLAG_NONE
) then
5994 FTime
[T_FLAGCAP
] := gTime
+ 2000;
5995 with gFlags
[FFlag
] do
5999 Direction
:= FDirection
;
6000 State
:= FLAG_STATE_DROPPED
;
6004 xv
:= FObj
.Vel
.X
+ IfThen(Direction
= TDirection
.D_RIGHT
, 10, -10);
6005 yv
:= FObj
.Vel
.Y
- 2;
6009 xv
:= (FObj
.Vel
.X
div 2);
6010 yv
:= (FObj
.Vel
.Y
div 2) - 2;
6012 g_Obj_Push(@Obj
, xv
, yv
);
6014 positionChanged(); // this updates spatial accelerators
6016 if FFlag
= FLAG_RED
then
6017 s
:= _lc
[I_PLAYER_FLAG_RED
]
6019 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
6021 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_DROP
], [FName
, s
]), True);
6022 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_DROP
], [AnsiUpperCase(s
)]), 144);
6024 if ((Self
= gPlayer1
) or (Self
= gPlayer2
)
6025 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= FTeam
))
6026 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= FTeam
))) then
6031 if (not Silent
) and (not sound_lost_flag
[a
].IsPlaying()) then
6032 sound_lost_flag
[a
].Play();
6034 if g_Game_IsNet
then
6035 MH_SEND_FlagEvent(FLAG_STATE_DROPPED
, Flag
, FUID
, False);
6041 procedure TPlayer
.GetSecret();
6043 if (self
= gPlayer1
) or (self
= gPlayer2
) then
6045 g_Console_Add(Format(_lc
[I_PLAYER_SECRET
], [FName
]), True);
6046 g_Sound_PlayEx('SOUND_GAME_SECRET');
6051 procedure TPlayer
.PressKey(Key
: Byte; Time
: Word = 1);
6053 Assert(Key
<= High(FKeys
));
6055 FKeys
[Key
].Pressed
:= True;
6056 FKeys
[Key
].Time
:= Time
;
6059 function TPlayer
.IsKeyPressed(K
: Byte): Boolean;
6061 Result
:= FKeys
[K
].Pressed
;
6064 procedure TPlayer
.ReleaseKeys();
6068 for a
:= Low(FKeys
) to High(FKeys
) do
6070 FKeys
[a
].Pressed
:= False;
6075 procedure TPlayer
.OnDamage(Angle
: SmallInt);
6079 function TPlayer
.firediry(): Integer;
6081 if FKeys
[KEY_UP
].Pressed
then Result
:= -42
6082 else if FKeys
[KEY_DOWN
].Pressed
then Result
:= 19
6086 procedure TPlayer
.RememberState();
6089 SavedState
: TPlayerSavedState
;
6091 SavedState
.Health
:= FHealth
;
6092 SavedState
.Armor
:= FArmor
;
6093 SavedState
.Air
:= FAir
;
6094 SavedState
.JetFuel
:= FJetFuel
;
6095 SavedState
.CurrWeap
:= FCurrWeap
;
6096 SavedState
.NextWeap
:= FNextWeap
;
6097 SavedState
.NextWeapDelay
:= FNextWeapDelay
;
6098 for i
:= Low(FWeapon
) to High(FWeapon
) do
6099 SavedState
.Weapon
[i
] := FWeapon
[i
];
6100 for i
:= Low(FAmmo
) to High(FAmmo
) do
6101 SavedState
.Ammo
[i
] := FAmmo
[i
];
6102 for i
:= Low(FMaxAmmo
) to High(FMaxAmmo
) do
6103 SavedState
.MaxAmmo
[i
] := FMaxAmmo
[i
];
6104 SavedState
.Rulez
:= FRulez
- [R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
];
6106 FSavedStateNum
:= -1;
6107 for i
:= Low(SavedStates
) to High(SavedStates
) do
6108 if not SavedStates
[i
].Used
then
6110 FSavedStateNum
:= i
;
6113 if FSavedStateNum
< 0 then
6115 SetLength(SavedStates
, Length(SavedStates
) + 1);
6116 FSavedStateNum
:= High(SavedStates
);
6119 SavedState
.Used
:= True;
6120 SavedStates
[FSavedStateNum
] := SavedState
;
6123 procedure TPlayer
.RecallState();
6126 SavedState
: TPlayerSavedState
;
6128 if(FSavedStateNum
< 0) or (FSavedStateNum
> High(SavedStates
)) then
6131 SavedState
:= SavedStates
[FSavedStateNum
];
6132 SavedStates
[FSavedStateNum
].Used
:= False;
6133 FSavedStateNum
:= -1;
6135 FHealth
:= SavedState
.Health
;
6136 FArmor
:= SavedState
.Armor
;
6137 FAir
:= SavedState
.Air
;
6138 FJetFuel
:= SavedState
.JetFuel
;
6139 FCurrWeap
:= SavedState
.CurrWeap
;
6140 FNextWeap
:= SavedState
.NextWeap
;
6141 FNextWeapDelay
:= SavedState
.NextWeapDelay
;
6142 for i
:= Low(FWeapon
) to High(FWeapon
) do
6143 FWeapon
[i
] := SavedState
.Weapon
[i
];
6144 for i
:= Low(FAmmo
) to High(FAmmo
) do
6145 FAmmo
[i
] := SavedState
.Ammo
[i
];
6146 for i
:= Low(FMaxAmmo
) to High(FMaxAmmo
) do
6147 FMaxAmmo
[i
] := SavedState
.MaxAmmo
[i
];
6148 FRulez
:= SavedState
.Rulez
;
6150 if gGameSettings
.GameType
= GT_SERVER
then
6151 MH_SEND_PlayerStats(FUID
);
6154 procedure TPlayer
.SaveState (st
: TStream
);
6160 utils
.writeSign(st
, 'PLYR');
6161 utils
.writeInt(st
, Byte(PLR_SAVE_VERSION
)); // version
6163 utils
.writeBool(st
, FIamBot
);
6165 utils
.writeInt(st
, Word(FUID
));
6167 utils
.writeStr(st
, FName
);
6169 utils
.writeInt(st
, Byte(FTeam
));
6171 utils
.writeBool(st
, FAlive
);
6172 // Èçðàñõîäîâàë ëè âñå æèçíè
6173 utils
.writeBool(st
, FNoRespawn
);
6175 if FDirection
= TDirection
.D_LEFT
then b
:= 1 else b
:= 2; // D_RIGHT
6176 utils
.writeInt(st
, Byte(b
));
6178 utils
.writeInt(st
, LongInt(FHealth
));
6179 // Êîýôôèöèåíò èíâàëèäíîñòè
6180 utils
.writeInt(st
, LongInt(FHandicap
));
6182 utils
.writeInt(st
, Byte(FLives
));
6184 utils
.writeInt(st
, LongInt(FArmor
));
6186 utils
.writeInt(st
, LongInt(FAir
));
6188 utils
.writeInt(st
, LongInt(FJetFuel
));
6190 utils
.writeInt(st
, LongInt(FPain
));
6192 utils
.writeInt(st
, LongInt(FKills
));
6194 utils
.writeInt(st
, LongInt(FMonsterKills
));
6196 utils
.writeInt(st
, LongInt(FFrags
));
6198 utils
.writeInt(st
, LongInt(FAssists
));
6200 utils
.writeInt(st
, Byte(FFragCombo
));
6201 // Âðåìÿ ïîñëåäíåãî ôðàãà
6202 utils
.writeInt(st
, LongWord(FLastFrag
));
6204 utils
.writeInt(st
, LongInt(FDeath
));
6206 utils
.writeInt(st
, Byte(FFlag
));
6208 utils
.writeInt(st
, LongInt(FSecrets
));
6210 utils
.writeInt(st
, Byte(FCurrWeap
));
6212 utils
.writeInt(st
, Word(FNextWeap
));
6214 utils
.writeInt(st
, Byte(FNextWeapDelay
));
6215 // Âðåìÿ çàðÿäêè BFG
6216 utils
.writeInt(st
, SmallInt(FBFGFireCounter
));
6218 utils
.writeInt(st
, LongInt(FDamageBuffer
));
6219 // Ïîñëåäíèé óäàðèâøèé
6220 utils
.writeInt(st
, Word(FLastSpawnerUID
));
6221 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà
6222 utils
.writeInt(st
, Byte(FLastHit
));
6224 Obj_SaveState(st
, @FObj
);
6225 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ
6226 for i
:= A_BULLETS
to A_HIGH
do utils
.writeInt(st
, Word(FAmmo
[i
]));
6227 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ
6228 for i
:= A_BULLETS
to A_HIGH
do utils
.writeInt(st
, Word(FMaxAmmo
[i
]));
6230 for i
:= WP_FIRST
to WP_LAST
do utils
.writeBool(st
, FWeapon
[i
]);
6231 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ
6232 for i
:= WP_FIRST
to WP_LAST
do utils
.writeInt(st
, Word(FReloading
[i
]));
6234 utils
.writeBool(st
, (R_ITEM_BACKPACK
in FRulez
));
6235 // Íàëè÷èå êðàñíîãî êëþ÷à
6236 utils
.writeBool(st
, (R_KEY_RED
in FRulez
));
6237 // Íàëè÷èå çåëåíîãî êëþ÷à
6238 utils
.writeBool(st
, (R_KEY_GREEN
in FRulez
));
6239 // Íàëè÷èå ñèíåãî êëþ÷à
6240 utils
.writeBool(st
, (R_KEY_BLUE
in FRulez
));
6242 utils
.writeBool(st
, (R_BERSERK
in FRulez
));
6243 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ
6244 for i
:= MR_SUIT
to MR_MAX
do utils
.writeInt(st
, LongWord(FMegaRulez
[i
]));
6245 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà
6246 for i
:= T_RESPAWN
to T_FLAGCAP
do utils
.writeInt(st
, LongWord(FTime
[i
]));
6248 utils
.writeStr(st
, FModel
.Name
);
6250 utils
.writeInt(st
, Byte(FColor
.R
));
6251 utils
.writeInt(st
, Byte(FColor
.G
));
6252 utils
.writeInt(st
, Byte(FColor
.B
));
6256 procedure TPlayer
.LoadState (st
: TStream
);
6265 if not utils
.checkSign(st
, 'PLYR') then raise XStreamError
.Create('invalid player signature');
6266 if (utils
.readByte(st
) <> PLR_SAVE_VERSION
) then raise XStreamError
.Create('invalid player version');
6268 FIamBot
:= utils
.readBool(st
);
6270 FUID
:= utils
.readWord(st
);
6272 str
:= utils
.readStr(st
);
6273 if (self
<> gPlayer1
) and (self
<> gPlayer2
) then FName
:= str
;
6275 FTeam
:= utils
.readByte(st
);
6277 FAlive
:= utils
.readBool(st
);
6278 // Èçðàñõîäîâàë ëè âñå æèçíè
6279 FNoRespawn
:= utils
.readBool(st
);
6281 b
:= utils
.readByte(st
);
6282 if b
= 1 then FDirection
:= TDirection
.D_LEFT
else FDirection
:= TDirection
.D_RIGHT
; // b = 2
6284 FHealth
:= utils
.readLongInt(st
);
6285 // Êîýôôèöèåíò èíâàëèäíîñòè
6286 FHandicap
:= utils
.readLongInt(st
);
6288 FLives
:= utils
.readByte(st
);
6290 FArmor
:= utils
.readLongInt(st
);
6292 FAir
:= utils
.readLongInt(st
);
6294 FJetFuel
:= utils
.readLongInt(st
);
6296 FPain
:= utils
.readLongInt(st
);
6298 FKills
:= utils
.readLongInt(st
);
6300 FMonsterKills
:= utils
.readLongInt(st
);
6302 FFrags
:= utils
.readLongInt(st
);
6304 FAssists
:= utils
.readLongInt(st
);
6306 FFragCombo
:= utils
.readByte(st
);
6307 // Âðåìÿ ïîñëåäíåãî ôðàãà
6308 FLastFrag
:= utils
.readLongWord(st
);
6310 FDeath
:= utils
.readLongInt(st
);
6312 FFlag
:= utils
.readByte(st
);
6314 FSecrets
:= utils
.readLongInt(st
);
6316 FCurrWeap
:= utils
.readByte(st
);
6318 FNextWeap
:= utils
.readWord(st
);
6320 FNextWeapDelay
:= utils
.readByte(st
);
6321 // Âðåìÿ çàðÿäêè BFG
6322 FBFGFireCounter
:= utils
.readSmallInt(st
);
6324 FDamageBuffer
:= utils
.readLongInt(st
);
6325 // Ïîñëåäíèé óäàðèâøèé
6326 FLastSpawnerUID
:= utils
.readWord(st
);
6327 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà
6328 FLastHit
:= utils
.readByte(st
);
6330 Obj_LoadState(@FObj
, st
);
6331 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ
6332 for i
:= A_BULLETS
to A_HIGH
do FAmmo
[i
] := utils
.readWord(st
);
6333 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ
6334 for i
:= A_BULLETS
to A_HIGH
do FMaxAmmo
[i
] := utils
.readWord(st
);
6336 for i
:= WP_FIRST
to WP_LAST
do FWeapon
[i
] := utils
.readBool(st
);
6337 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ
6338 for i
:= WP_FIRST
to WP_LAST
do FReloading
[i
] := utils
.readWord(st
);
6340 if utils
.readBool(st
) then Include(FRulez
, R_ITEM_BACKPACK
);
6341 // Íàëè÷èå êðàñíîãî êëþ÷à
6342 if utils
.readBool(st
) then Include(FRulez
, R_KEY_RED
);
6343 // Íàëè÷èå çåëåíîãî êëþ÷à
6344 if utils
.readBool(st
) then Include(FRulez
, R_KEY_GREEN
);
6345 // Íàëè÷èå ñèíåãî êëþ÷à
6346 if utils
.readBool(st
) then Include(FRulez
, R_KEY_BLUE
);
6348 if utils
.readBool(st
) then Include(FRulez
, R_BERSERK
);
6349 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ
6350 for i
:= MR_SUIT
to MR_MAX
do FMegaRulez
[i
] := utils
.readLongWord(st
);
6351 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà
6352 for i
:= T_RESPAWN
to T_FLAGCAP
do FTime
[i
] := utils
.readLongWord(st
);
6354 str
:= utils
.readStr(st
);
6356 FColor
.R
:= utils
.readByte(st
);
6357 FColor
.G
:= utils
.readByte(st
);
6358 FColor
.B
:= utils
.readByte(st
);
6359 if (self
= gPlayer1
) then
6361 str
:= gPlayer1Settings
.Model
;
6362 FColor
:= gPlayer1Settings
.Color
;
6364 else if (self
= gPlayer2
) then
6366 str
:= gPlayer2Settings
.Model
;
6367 FColor
:= gPlayer2Settings
.Color
;
6369 // Îáíîâëÿåì ìîäåëü èãðîêà
6371 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
6372 FModel
.Color
:= TEAMCOLOR
[FTeam
]
6374 FModel
.Color
:= FColor
;
6378 procedure TPlayer
.AllRulez(Health
: Boolean);
6384 FHealth
:= PLAYER_HP_LIMIT
;
6385 FArmor
:= PLAYER_AP_LIMIT
;
6389 for a
:= WP_FIRST
to WP_LAST
do FWeapon
[a
] := True;
6390 for a
:= A_BULLETS
to A_HIGH
do FAmmo
[a
] := 30000;
6391 FRulez
:= FRulez
+[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
];
6394 procedure TPlayer
.RestoreHealthArmor();
6396 FHealth
:= PLAYER_HP_LIMIT
;
6397 FArmor
:= PLAYER_AP_LIMIT
;
6400 procedure TPlayer
.FragCombo();
6404 if (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) or g_Game_IsClient
then
6406 if gTime
- FLastFrag
< FRAG_COMBO_TIME
then
6408 if FFragCombo
< 5 then
6410 Param
:= FUID
or (FFragCombo
shl 16);
6411 if (FComboEvnt
>= Low(gDelayedEvents
)) and
6412 (FComboEvnt
<= High(gDelayedEvents
)) and
6413 gDelayedEvents
[FComboEvnt
].Pending
and
6414 (gDelayedEvents
[FComboEvnt
].DEType
= DE_KILLCOMBO
) and
6415 (gDelayedEvents
[FComboEvnt
].DENum
and $FFFF = FUID
) then
6417 gDelayedEvents
[FComboEvnt
].Time
:= gTime
+ 500;
6418 gDelayedEvents
[FComboEvnt
].DENum
:= Param
;
6421 FComboEvnt
:= g_Game_DelayEvent(DE_KILLCOMBO
, 500, Param
);
6429 procedure TPlayer
.GiveItem(ItemType
: Byte);
6433 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
6435 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
6439 if FAir
< AIR_MAX
then
6446 if not (R_BERSERK
in FRulez
) then
6448 Include(FRulez
, R_BERSERK
);
6449 if FBFGFireCounter
< 1 then
6451 FCurrWeap
:= WEAPON_KASTET
;
6453 FModel
.SetWeapon(WEAPON_KASTET
);
6457 FBerserk
:= gTime
+30000;
6459 if FHealth
< PLAYER_HP_SOFT
then
6461 FHealth
:= PLAYER_HP_SOFT
;
6462 FBerserk
:= gTime
+30000;
6467 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
6469 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
6474 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
6476 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
6480 if FJetFuel
< JET_MAX
then
6482 FJetFuel
:= JET_MAX
;
6485 ITEM_MEDKIT_SMALL
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
6486 ITEM_MEDKIT_LARGE
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
6488 ITEM_ARMOR_GREEN
: if FArmor
< PLAYER_AP_SOFT
then FArmor
:= PLAYER_AP_SOFT
;
6489 ITEM_ARMOR_BLUE
: if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
6491 ITEM_SPHERE_BLUE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
6493 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) then
6495 if FHealth
< PLAYER_HP_LIMIT
then FHealth
:= PLAYER_HP_LIMIT
;
6496 if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
6499 ITEM_WEAPON_SAW
: FWeapon
[WEAPON_SAW
] := True;
6500 ITEM_WEAPON_SHOTGUN1
: FWeapon
[WEAPON_SHOTGUN1
] := True;
6501 ITEM_WEAPON_SHOTGUN2
: FWeapon
[WEAPON_SHOTGUN2
] := True;
6502 ITEM_WEAPON_CHAINGUN
: FWeapon
[WEAPON_CHAINGUN
] := True;
6503 ITEM_WEAPON_ROCKETLAUNCHER
: FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
6504 ITEM_WEAPON_PLASMA
: FWeapon
[WEAPON_PLASMA
] := True;
6505 ITEM_WEAPON_BFG
: FWeapon
[WEAPON_BFG
] := True;
6506 ITEM_WEAPON_SUPERPULEMET
: FWeapon
[WEAPON_SUPERPULEMET
] := True;
6507 ITEM_WEAPON_FLAMETHROWER
: FWeapon
[WEAPON_FLAMETHROWER
] := True;
6509 ITEM_AMMO_BULLETS
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
6510 ITEM_AMMO_BULLETS_BOX
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
6511 ITEM_AMMO_SHELLS
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
6512 ITEM_AMMO_SHELLS_BOX
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
6513 ITEM_AMMO_ROCKET
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
6514 ITEM_AMMO_ROCKET_BOX
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
6515 ITEM_AMMO_CELL
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
6516 ITEM_AMMO_CELL_BIG
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
6517 ITEM_AMMO_FUELCAN
: if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
6520 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
6521 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
6522 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
6523 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or
6524 (FMaxAmmo
[A_FUEL
] < AmmoLimits
[1, A_FUEL
]) then
6526 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[1, A_BULLETS
];
6527 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[1, A_SHELLS
];
6528 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[1, A_ROCKETS
];
6529 FMaxAmmo
[A_CELLS
] := AmmoLimits
[1, A_CELLS
];
6530 FMaxAmmo
[A_FUEL
] := AmmoLimits
[1, A_FUEL
];
6532 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
6533 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
6534 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
6535 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
6537 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
6540 ITEM_KEY_RED
: if not (R_KEY_RED
in FRulez
) then Include(FRulez
, R_KEY_RED
);
6541 ITEM_KEY_GREEN
: if not (R_KEY_GREEN
in FRulez
) then Include(FRulez
, R_KEY_GREEN
);
6542 ITEM_KEY_BLUE
: if not (R_KEY_BLUE
in FRulez
) then Include(FRulez
, R_KEY_BLUE
);
6544 ITEM_BOTTLE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
6545 ITEM_HELMET
: if FArmor
< PLAYER_AP_LIMIT
then IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
6550 if g_Game_IsNet
and g_Game_IsServer
then
6551 MH_SEND_PlayerStats(FUID
);
6554 procedure TPlayer
.FlySmoke(Times
: DWORD
= 1);
6559 if (Random(5) = 1) and (Times
= 1) then
6562 if BodyInLiquid(0, 0) then
6564 g_Game_Effect_Bubbles(Obj
.X
+Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2)+Random(3)-1,
6565 Obj
.Y
+Obj
.Rect
.Height
+8, 1, 8, 4);
6569 if g_Frames_Get(id
, 'FRAMES_SMOKE') then
6571 for i
:= 1 to Times
do
6573 Anim
:= TAnimation
.Create(id
, False, 3);
6575 g_GFX_OnceAnim(Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(Anim
.Width
div 2),
6576 Obj
.Y
+Obj
.Rect
.Height
-4+Random(8+Times
*2), Anim
, ONCEANIM_SMOKE
);
6582 procedure TPlayer
.OnFireFlame(Times
: DWORD
= 1);
6587 if (Random(10) = 1) and (Times
= 1) then
6590 if g_Frames_Get(id
, 'FRAMES_FLAME') then
6592 for i
:= 1 to Times
do
6594 Anim
:= TAnimation
.Create(id
, False, 3);
6596 g_GFX_OnceAnim(Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(Anim
.Width
div 2),
6597 Obj
.Y
+8+Random(8+Times
*2), Anim
, ONCEANIM_SMOKE
);
6603 procedure TPlayer
.PauseSounds(Enable
: Boolean);
6605 FSawSound
.Pause(Enable
);
6606 FSawSoundIdle
.Pause(Enable
);
6607 FSawSoundHit
.Pause(Enable
);
6608 FSawSoundSelect
.Pause(Enable
);
6609 FFlameSoundOn
.Pause(Enable
);
6610 FFlameSoundOff
.Pause(Enable
);
6611 FFlameSoundWork
.Pause(Enable
);
6612 FJetSoundFly
.Pause(Enable
);
6613 FJetSoundOn
.Pause(Enable
);
6614 FJetSoundOff
.Pause(Enable
);
6619 constructor TCorpse
.Create(X
, Y
: Integer; ModelName
: String; aMess
: Boolean);
6624 FObj
.Rect
:= PLAYER_CORPSERECT
;
6625 FModelName
:= ModelName
;
6630 FState
:= CORPSE_STATE_MESS
;
6631 g_PlayerModel_GetAnim(ModelName
, A_DIE2
, FAnimation
, FAnimationMask
);
6635 FState
:= CORPSE_STATE_NORMAL
;
6636 g_PlayerModel_GetAnim(ModelName
, A_DIE1
, FAnimation
, FAnimationMask
);
6640 destructor TCorpse
.Destroy();
6647 function TCorpse
.ObjPtr (): PObj
; inline; begin result
:= @FObj
; end;
6649 procedure TCorpse
.positionChanged (); inline; begin end;
6651 procedure TCorpse
.moveBy (dx
, dy
: Integer); inline;
6653 if (dx
<> 0) or (dy
<> 0) then
6662 procedure TCorpse
.getMapBox (out x
, y
, w
, h
: Integer); inline;
6664 x
:= FObj
.X
+PLAYER_CORPSERECT
.X
;
6665 y
:= FObj
.Y
+PLAYER_CORPSERECT
.Y
;
6666 w
:= PLAYER_CORPSERECT
.Width
;
6667 h
:= PLAYER_CORPSERECT
.Height
;
6671 procedure TCorpse
.Damage(Value
: Word; SpawnerUID
: Word; vx
, vy
: Integer);
6676 if FState
= CORPSE_STATE_REMOVEME
then
6679 FDamage
:= FDamage
+ Value
;
6681 if FDamage
> 150 then
6683 if FAnimation
<> nil then
6688 FState
:= CORPSE_STATE_REMOVEME
;
6690 g_Player_CreateGibs(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
6691 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2),
6692 FModelName
, FColor
);
6693 // Çâóê ìÿñà îò òðóïà:
6694 pm
:= g_PlayerModel_Get(FModelName
);
6695 pm
.PlaySound(MODELSOUND_DIE
, 5, FObj
.X
, FObj
.Y
);
6699 if (gBodyKillEvent
<> -1)
6700 and gDelayedEvents
[gBodyKillEvent
].Pending
then
6701 gDelayedEvents
[gBodyKillEvent
].Pending
:= False;
6702 gBodyKillEvent
:= g_Game_DelayEvent(DE_BODYKILL
, 1050, SpawnerUID
);
6707 Blood
:= g_PlayerModel_GetBlood(FModelName
);
6708 FObj
.Vel
.X
:= FObj
.Vel
.X
+ vx
;
6709 FObj
.Vel
.Y
:= FObj
.Vel
.Y
+ vy
;
6710 g_GFX_Blood(FObj
.X
+PLAYER_CORPSERECT
.X
+(PLAYER_CORPSERECT
.Width
div 2),
6711 FObj
.Y
+PLAYER_CORPSERECT
.Y
+(PLAYER_CORPSERECT
.Height
div 2),
6712 Value
, vx
, vy
, 16, (PLAYER_CORPSERECT
.Height
*2) div 3,
6713 Blood
.R
, Blood
.G
, Blood
.B
, Blood
.Kind
);
6717 procedure TCorpse
.Draw();
6721 if FState
= CORPSE_STATE_REMOVEME
then
6724 FObj
.lerp(gLerpFactor
, fX
, fY
);
6726 if FAnimation
<> nil then
6727 FAnimation
.Draw(fX
, fY
, TMirrorType
.None
);
6729 if FAnimationMask
<> nil then
6732 FAnimationMask
.Draw(fX
, fY
, TMirrorType
.None
);
6739 procedure TCorpse
.Update();
6743 if FState
= CORPSE_STATE_REMOVEME
then
6746 FObj
.oldX
:= FObj
.X
;
6747 FObj
.oldY
:= FObj
.Y
;
6749 if gTime
mod (GAME_TICK
*2) <> 0 then
6751 g_Obj_Move(@FObj
, True, True, True);
6752 positionChanged(); // this updates spatial accelerators
6756 // Ñîïðîòèâëåíèå âîçäóõà äëÿ òðóïà:
6757 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
6759 st
:= g_Obj_Move(@FObj
, True, True, True);
6760 positionChanged(); // this updates spatial accelerators
6762 if WordBool(st
and MOVE_FALLOUT
) then
6764 FState
:= CORPSE_STATE_REMOVEME
;
6768 if FAnimation
<> nil then
6769 FAnimation
.Update();
6770 if FAnimationMask
<> nil then
6771 FAnimationMask
.Update();
6775 procedure TCorpse
.SaveState (st
: TStream
);
6782 utils
.writeSign(st
, 'CORP');
6783 utils
.writeInt(st
, Byte(0));
6785 utils
.writeInt(st
, Byte(FState
));
6787 utils
.writeInt(st
, Byte(FDamage
));
6789 utils
.writeInt(st
, Byte(FColor
.R
));
6790 utils
.writeInt(st
, Byte(FColor
.G
));
6791 utils
.writeInt(st
, Byte(FColor
.B
));
6793 Obj_SaveState(st
, @FObj
);
6794 utils
.writeInt(st
, Word(FPlayerUID
));
6796 anim
:= (FAnimation
<> nil);
6797 utils
.writeBool(st
, anim
);
6798 // Åñëè åñòü - ñîõðàíÿåì
6799 if anim
then FAnimation
.SaveState(st
);
6800 // Åñòü ëè ìàñêà àíèìàöèè
6801 anim
:= (FAnimationMask
<> nil);
6802 utils
.writeBool(st
, anim
);
6803 // Åñëè åñòü - ñîõðàíÿåì
6804 if anim
then FAnimationMask
.SaveState(st
);
6808 procedure TCorpse
.LoadState (st
: TStream
);
6815 if not utils
.checkSign(st
, 'CORP') then raise XStreamError
.Create('invalid corpse signature');
6816 if (utils
.readByte(st
) <> 0) then raise XStreamError
.Create('invalid corpse version');
6818 FState
:= utils
.readByte(st
);
6820 FDamage
:= utils
.readByte(st
);
6822 FColor
.R
:= utils
.readByte(st
);
6823 FColor
.G
:= utils
.readByte(st
);
6824 FColor
.B
:= utils
.readByte(st
);
6826 Obj_LoadState(@FObj
, st
);
6827 FPlayerUID
:= utils
.readWord(st
);
6829 anim
:= utils
.readBool(st
);
6830 // Åñëè åñòü - çàãðóæàåì
6833 Assert(FAnimation
<> nil, 'TCorpse.LoadState: no FAnimation');
6834 FAnimation
.LoadState(st
);
6836 // Åñòü ëè ìàñêà àíèìàöèè
6837 anim
:= utils
.readBool(st
);
6838 // Åñëè åñòü - çàãðóæàåì
6841 Assert(FAnimationMask
<> nil, 'TCorpse.LoadState: no FAnimationMask');
6842 FAnimationMask
.LoadState(st
);
6848 constructor TBot
.Create();
6855 FSpectator
:= False;
6862 for a
:= WP_FIRST
to WP_LAST
do
6864 FDifficult
.WeaponPrior
[a
] := WEAPON_PRIOR1
[a
];
6865 FDifficult
.CloseWeaponPrior
[a
] := WEAPON_PRIOR2
[a
];
6866 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
6870 destructor TBot
.Destroy();
6873 inherited Destroy();
6876 procedure TBot
.Draw();
6880 //if FTargetUID <> 0 then e_DrawLine(1, FObj.X, FObj.Y, g_Player_Get(FTargetUID).FObj.X,
6881 // g_Player_Get(FTargetUID).FObj.Y, 255, 0, 0);
6884 procedure TBot
.Respawn(Silent
: Boolean; Force
: Boolean = False);
6886 inherited Respawn(Silent
, Force
);
6889 FSelectedWeapon
:= FCurrWeap
;
6894 procedure TBot
.UpdateCombat();
6907 TTargetRecord
= array of TTarget
;
6909 function Compare(a
, b
: TTarget
): Integer;
6911 if a
.Line
and not b
.Line
then // A íà ëèíèè îãíÿ
6914 if not a
.Line
and b
.Line
then // B íà ëèíèè îãíÿ
6916 else // È A, è B íà ëèíèè èëè íå íà ëèíèè îãíÿ
6917 if (a
.Line
and b
.Line
) or ((not a
.Line
) and (not b
.Line
)) then
6919 if a
.Dist
> b
.Dist
then // B áëèæå
6921 else // A áëèæå èëè ðàâíîóäàëåííî ñ B
6924 else // Ñòðàííî -> A
6929 a
, x1
, y1
, x2
, y2
: Integer;
6930 targets
: TTargetRecord
;
6932 Target
, BestTarget
: TTarget
;
6933 firew
, fireh
: Integer;
6937 vsPlayer
, vsMonster
, ok
: Boolean;
6940 function monsUpdate (mon
: TMonster
): Boolean;
6942 result
:= false; // don't stop
6943 if mon
.alive
and (mon
.MonsterType
<> MONSTER_BARREL
) then
6945 if not TargetOnScreen(mon
.Obj
.X
+mon
.Obj
.Rect
.X
, mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
) then exit
;
6947 x2
:= mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2);
6948 y2
:= mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+(mon
.Obj
.Rect
.Height
div 2);
6950 // Åñëè ìîíñòð íà ýêðàíå è íå ïðèêðûò ñòåíîé
6951 if g_TraceVector(x1
, y1
, x2
, y2
) then
6953 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé
6954 SetLength(targets
, Length(targets
)+1);
6955 with targets
[High(targets
)] do
6962 Rect
:= mon
.Obj
.Rect
;
6963 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6964 Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6965 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6974 vsPlayer
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
);
6975 vsMonster
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
);
6977 // Åñëè òåêóùåå îðóæèå íå òî, ÷òî íóæíî, òî ìåíÿåì:
6978 if FCurrWeap
<> FSelectedWeapon
then
6981 // Åñëè íóæíî ñòðåëÿòü è íóæíîå îðóæèå, òî íàæàòü "Ñòðåëÿòü":
6982 if (GetAIFlag('NEEDFIRE') <> '') and (FCurrWeap
= FSelectedWeapon
) then
6984 RemoveAIFlag('NEEDFIRE');
6987 WEAPON_PLASMA
, WEAPON_SUPERPULEMET
, WEAPON_CHAINGUN
: PressKey(KEY_FIRE
, 20);
6988 WEAPON_SAW
, WEAPON_KASTET
, WEAPON_FLAMETHROWER
: PressKey(KEY_FIRE
, 40);
6989 else PressKey(KEY_FIRE
);
6993 // Êîîðäèíàòû ñòâîëà:
6994 x1
:= FObj
.X
+ WEAPONPOINT
[FDirection
].X
;
6995 y1
:= FObj
.Y
+ WEAPONPOINT
[FDirection
].Y
;
6997 Target
.UID
:= FTargetUID
;
7000 if Target
.UID
<> 0 then
7001 begin // Öåëü åñòü - íàñòðàèâàåì
7002 if (g_GetUIDType(Target
.UID
) = UID_PLAYER
) and
7005 tpla
:= g_Player_Get(Target
.UID
);
7009 if (@FObj
) <> nil then
7016 Target
.cX
:= Target
.X
+ PLAYER_RECT_CX
;
7017 Target
.cY
:= Target
.Y
+ PLAYER_RECT_CY
;
7018 Target
.Rect
:= PLAYER_RECT
;
7019 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
7020 Target
.Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
7021 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
7022 Target
.IsPlayer
:= True;
7026 if (g_GetUIDType(Target
.UID
) = UID_MONSTER
) and
7029 mon
:= g_Monsters_ByUID(Target
.UID
);
7032 Target
.X
:= mon
.Obj
.X
;
7033 Target
.Y
:= mon
.Obj
.Y
;
7035 Target
.cX
:= Target
.X
+ mon
.Obj
.Rect
.X
+ (mon
.Obj
.Rect
.Width
div 2);
7036 Target
.cY
:= Target
.Y
+ mon
.Obj
.Rect
.Y
+ (mon
.Obj
.Rect
.Height
div 2);
7037 Target
.Rect
:= mon
.Obj
.Rect
;
7038 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
7039 Target
.Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
7040 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
7041 Target
.IsPlayer
:= False;
7048 begin // Öåëè íåò - îáíóëÿåì
7053 Target
.Visible
:= False;
7054 Target
.Line
:= False;
7055 Target
.IsPlayer
:= False;
7060 // Åñëè öåëü íå âèäèìà èëè íå íà ëèíèè îãíÿ, òî èùåì âñå âîçìîæíûå öåëè:
7061 if (not Target
.Line
) or (not Target
.Visible
) then
7065 for a
:= 0 to High(gPlayers
) do
7066 if (gPlayers
[a
] <> nil) and (gPlayers
[a
].alive
) and
7067 (gPlayers
[a
].FUID
<> FUID
) and
7068 (not SameTeam(FUID
, gPlayers
[a
].FUID
)) and
7069 (not gPlayers
[a
].NoTarget
) and
7070 (gPlayers
[a
].FMegaRulez
[MR_INVIS
] < gTime
) then
7072 if not TargetOnScreen(gPlayers
[a
].FObj
.X
+ PLAYER_RECT
.X
,
7073 gPlayers
[a
].FObj
.Y
+ PLAYER_RECT
.Y
) then
7076 x2
:= gPlayers
[a
].FObj
.X
+ PLAYER_RECT_CX
;
7077 y2
:= gPlayers
[a
].FObj
.Y
+ PLAYER_RECT_CY
;
7079 // Åñëè èãðîê íà ýêðàíå è íå ïðèêðûò ñòåíîé:
7080 if g_TraceVector(x1
, y1
, x2
, y2
) then
7082 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé:
7083 SetLength(targets
, Length(targets
)+1);
7084 with targets
[High(targets
)] do
7086 UID
:= gPlayers
[a
].FUID
;
7087 X
:= gPlayers
[a
].FObj
.X
;
7088 Y
:= gPlayers
[a
].FObj
.Y
;
7091 Rect
:= PLAYER_RECT
;
7092 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
7093 Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
7094 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
7102 if vsMonster
then g_Mons_ForEach(monsUpdate
);
7105 // Åñëè åñòü âîçìîæíûå öåëè:
7106 // (Âûáèðàåì ëó÷øóþ, ìåíÿåì îðóæèå è áåæèì ê íåé/îò íåå)
7107 if targets
<> nil then
7109 // Âûáèðàåì íàèëó÷øóþ öåëü:
7110 BestTarget
:= targets
[0];
7111 if Length(targets
) > 1 then
7112 for a
:= 1 to High(targets
) do
7113 if Compare(BestTarget
, targets
[a
]) = 1 then
7114 BestTarget
:= targets
[a
];
7116 // Åñëè ëó÷øàÿ öåëü "âèäíåå" òåêóùåé, òî òåêóùàÿ := ëó÷øàÿ:
7117 if ((not Target
.Visible
) and BestTarget
.Visible
and (Target
.UID
<> BestTarget
.UID
)) or
7118 ((not Target
.Line
) and BestTarget
.Line
and BestTarget
.Visible
) then
7120 Target
:= BestTarget
;
7122 if (Healthy() = 3) or ((Healthy() = 2)) then
7123 begin // Åñëè çäîðîâû - äîãîíÿåì
7124 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
7125 SetAIFlag('GORIGHT', '1');
7126 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
7127 SetAIFlag('GOLEFT', '1');
7130 begin // Åñëè ïîáèòû - óáåãàåì
7131 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) then
7132 SetAIFlag('GORIGHT', '1');
7133 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
7134 SetAIFlag('GOLEFT', '1');
7137 // Âûáèðàåì îðóæèå íà îñíîâå ðàññòîÿíèÿ è ïðèîðèòåòîâ:
7138 SelectWeapon(Abs(x1
-Target
.cX
));
7143 // (Äîãîíÿåì/óáåãàåì, ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëè)
7144 // (Åñëè öåëü äàëåêî, òî õâàòèò ñëåäèòü çà íåé)
7145 if Target
.UID
<> 0 then
7147 if not TargetOnScreen(Target
.X
+ Target
.Rect
.X
,
7148 Target
.Y
+ Target
.Rect
.Y
) then
7149 begin // Öåëü ñáåæàëà ñ "ýêðàíà"
7150 if (Healthy() = 3) or ((Healthy() = 2)) then
7151 begin // Åñëè çäîðîâû - äîãîíÿåì
7152 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
7153 SetAIFlag('GORIGHT', '1');
7154 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
7155 SetAIFlag('GOLEFT', '1');
7158 begin // Åñëè ïîáèòû - çàáûâàåì î öåëè è óáåãàåì
7160 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) then
7161 SetAIFlag('GORIGHT', '1');
7162 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
7163 SetAIFlag('GOLEFT', '1');
7167 begin // Öåëü ïîêà íà "ýêðàíå"
7168 // Åñëè öåëü íå çàãîðîæåíà ñòåíîé, òî îòìå÷àåì, êîãäà åå âèäåëè:
7169 if g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
7170 FLastVisible
:= gTime
;
7171 // Åñëè ðàçíèöà âûñîò íå âåëèêà, òî äîãîíÿåì:
7172 if (Abs(FObj
.Y
-Target
.Y
) <= 128) then
7174 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
7175 SetAIFlag('GORIGHT', '1');
7176 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
7177 SetAIFlag('GOLEFT', '1');
7181 // Âûáèðàåì óãîë ââåðõ:
7182 if FDirection
= TDirection
.D_LEFT
then
7183 angle
:= ANGLE_LEFTUP
7185 angle
:= ANGLE_RIGHTUP
;
7187 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7188 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7190 // Åñëè ïðè óãëå ââåðõ ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
7191 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
7192 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128), //96
7193 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
7194 Target
.Rect
.Width
, Target
.Rect
.Height
) and
7195 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
7196 begin // òî íóæíî ñòðåëÿòü ââåðõ
7197 SetAIFlag('NEEDFIRE', '1');
7198 SetAIFlag('NEEDSEEUP', '1');
7201 // Âûáèðàåì óãîë âíèç:
7202 if FDirection
= TDirection
.D_LEFT
then
7203 angle
:= ANGLE_LEFTDOWN
7205 angle
:= ANGLE_RIGHTDOWN
;
7207 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7208 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7210 // Åñëè ïðè óãëå âíèç ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
7211 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
7212 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
7213 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
7214 Target
.Rect
.Width
, Target
.Rect
.Height
) and
7215 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
7216 begin // òî íóæíî ñòðåëÿòü âíèç
7217 SetAIFlag('NEEDFIRE', '1');
7218 SetAIFlag('NEEDSEEDOWN', '1');
7221 // Åñëè öåëü âèäíî è îíà íà òàêîé æå âûñîòå:
7222 if Target
.Visible
and
7223 (y1
+4 < Target
.Y
+Target
.Rect
.Y
+Target
.Rect
.Height
) and
7224 (y1
-4 > Target
.Y
+Target
.Rect
.Y
) then
7226 // Åñëè èäåì â ñòîðîíó öåëè, òî íàäî ñòðåëÿòü:
7227 if ((FDirection
= TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) or
7228 ((FDirection
= TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
7229 begin // òî íóæíî ñòðåëÿòü âïåðåä
7230 SetAIFlag('NEEDFIRE', '1');
7231 SetAIFlag('NEEDSEEDOWN', '');
7232 SetAIFlag('NEEDSEEUP', '');
7234 // Åñëè öåëü â ïðåäåëàõ "ýêðàíà" è ñëîæíîñòü ïîçâîëÿåò ïðûæêè ñáëèæåíèÿ:
7235 if Abs(FObj
.X
-Target
.X
) < Trunc(gPlayerScreenSize
.X
*0.75) then
7236 if GetRnd(FDifficult
.CloseJump
) then
7237 begin // òî åñëè ïîâåçåò - ïðûãàåì (îñîáåííî, åñëè áëèçêî)
7238 if Abs(FObj
.X
-Target
.X
) < 128 then
7242 if Random(a
) = 0 then
7243 SetAIFlag('NEEDJUMP', '1');
7247 // Åñëè öåëü âñå åùå åñòü:
7248 if Target
.UID
<> 0 then
7249 if gTime
-FLastVisible
> 2000 then // Åñëè âèäåëè äàâíî
7250 Target
.UID
:= 0 // òî çàáûòü öåëü
7251 else // Åñëè âèäåëè íåäàâíî
7252 begin // íî öåëü óáèëè
7253 if Target
.IsPlayer
then
7254 begin // Öåëü - èãðîê
7255 pla
:= g_Player_Get(Target
.UID
);
7256 if (pla
= nil) or (not pla
.alive
) or pla
.NoTarget
or
7257 (pla
.FMegaRulez
[MR_INVIS
] >= gTime
) then
7258 Target
.UID
:= 0; // òî çàáûòü öåëü
7261 begin // Öåëü - ìîíñòð
7262 mon
:= g_Monsters_ByUID(Target
.UID
);
7263 if (mon
= nil) or (not mon
.alive
) then
7264 Target
.UID
:= 0; // òî çàáûòü öåëü
7267 end; // if Target.UID <> 0
7269 FTargetUID
:= Target
.UID
;
7271 // Åñëè âîçìîæíûõ öåëåé íåò:
7272 // (Àòàêà ÷åãî-íèáóäü ñëåâà èëè ñïðàâà)
7273 if targets
= nil then
7274 if GetAIFlag('ATTACKLEFT') <> '' then
7275 begin // Åñëè íóæíî àòàêîâàòü íàëåâî
7276 RemoveAIFlag('ATTACKLEFT');
7278 SetAIFlag('NEEDJUMP', '1');
7280 if RunDirection() = TDirection
.D_RIGHT
then
7281 begin // Èäåì íå â òó ñòîðîíó
7282 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
7283 begin // Åñëè çäîðîâû, òî, âîçìîæíî, ñòðåëÿåì áåæèì âëåâî è ñòðåëÿåì
7284 SetAIFlag('NEEDFIRE', '1');
7285 SetAIFlag('GOLEFT', '1');
7289 begin // Èäåì â íóæíóþ ñòîðîíó
7290 if GetRnd(FDifficult
.InvisFire
) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
7291 SetAIFlag('NEEDFIRE', '1');
7292 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
7293 SetAIFlag('GORIGHT', '1');
7297 if GetAIFlag('ATTACKRIGHT') <> '' then
7298 begin // Åñëè íóæíî àòàêîâàòü íàïðàâî
7299 RemoveAIFlag('ATTACKRIGHT');
7301 SetAIFlag('NEEDJUMP', '1');
7303 if RunDirection() = TDirection
.D_LEFT
then
7304 begin // Èäåì íå â òó ñòîðîíó
7305 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
7306 begin // Åñëè çäîðîâû, òî, âîçìîæíî, áåæèì âïðàâî è ñòðåëÿåì
7307 SetAIFlag('NEEDFIRE', '1');
7308 SetAIFlag('GORIGHT', '1');
7313 if GetRnd(FDifficult
.InvisFire
) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
7314 SetAIFlag('NEEDFIRE', '1');
7315 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
7316 SetAIFlag('GOLEFT', '1');
7320 //HACK! (does it belongs there?)
7321 RealizeCurrentWeapon();
7323 // Åñëè åñòü âîçìîæíûå öåëè:
7324 // (Ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëÿì)
7325 if (targets
<> nil) and (GetAIFlag('NEEDFIRE') <> '') then
7326 for a
:= 0 to High(targets
) do
7328 // Åñëè ìîæåì ñòðåëÿòü ïî äèàãîíàëè:
7329 if GetRnd(FDifficult
.DiagFire
) then
7331 // Èùåì öåëü ñâåðõó è ñòðåëÿåì, åñëè åñòü:
7332 if FDirection
= TDirection
.D_LEFT
then
7333 angle
:= ANGLE_LEFTUP
7335 angle
:= ANGLE_RIGHTUP
;
7337 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7338 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7340 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
7341 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
7342 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
7343 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
7344 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
7346 SetAIFlag('NEEDFIRE', '1');
7347 SetAIFlag('NEEDSEEUP', '1');
7350 // Èùåì öåëü ñíèçó è ñòðåëÿåì, åñëè åñòü:
7351 if FDirection
= TDirection
.D_LEFT
then
7352 angle
:= ANGLE_LEFTDOWN
7354 angle
:= ANGLE_RIGHTDOWN
;
7356 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7357 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7359 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
7360 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
7361 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
7362 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
7363 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
7365 SetAIFlag('NEEDFIRE', '1');
7366 SetAIFlag('NEEDSEEDOWN', '1');
7370 // Åñëè öåëü "ïåðåä íîñîì", òî ñòðåëÿåì:
7371 if targets
[a
].Line
and targets
[a
].Visible
and
7372 (((FDirection
= TDirection
.D_LEFT
) and (targets
[a
].X
< FObj
.X
)) or
7373 ((FDirection
= TDirection
.D_RIGHT
) and (targets
[a
].X
> FObj
.X
))) then
7375 SetAIFlag('NEEDFIRE', '1');
7380 // Åñëè ëåòèò ïóëÿ, òî, âîçìîæíî, ïîäïðûãèâàåì:
7381 if g_Weapon_Danger(FUID
, FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
,
7382 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
,
7383 40+GetInterval(FDifficult
.Cover
, 40)) then
7384 SetAIFlag('NEEDJUMP', '1');
7386 // Åñëè êîí÷èëèñü ïàòîðíû, òî íóæíî ñìåíèòü îðóæèå:
7387 ammo
:= GetAmmoByWeapon(FCurrWeap
);
7388 if ((FCurrWeap
= WEAPON_SHOTGUN2
) and (ammo
< 2)) or
7389 ((FCurrWeap
= WEAPON_BFG
) and (ammo
< 40)) or
7391 SetAIFlag('SELECTWEAPON', '1');
7393 // Åñëè íóæíî ñìåíèòü îðóæèå, òî âûáèðàåì íóæíîå:
7394 if GetAIFlag('SELECTWEAPON') = '1' then
7397 RemoveAIFlag('SELECTWEAPON');
7401 procedure TBot
.Update();
7414 // Ïðîâåðÿåì, îòêëþ÷¸í ëè AI áîòîâ
7415 if (g_debug_BotAIOff
= 1) and (Team
= TEAM_RED
) then
7417 if (g_debug_BotAIOff
= 2) and (Team
= TEAM_BLUE
) then
7419 if g_debug_BotAIOff
= 3 then
7429 RealizeCurrentWeapon();
7436 procedure TBot
.ReleaseKey(Key
: Byte);
7445 function TBot
.KeyPressed(Key
: Word): Boolean;
7447 Result
:= FKeys
[Key
].Pressed
;
7450 function TBot
.GetAIFlag(aName
: String20
): String20
;
7456 aName
:= LowerCase(aName
);
7458 if FAIFlags
<> nil then
7459 for a
:= 0 to High(FAIFlags
) do
7460 if LowerCase(FAIFlags
[a
].Name
) = aName
then
7462 Result
:= FAIFlags
[a
].Value
;
7467 procedure TBot
.RemoveAIFlag(aName
: String20
);
7471 if FAIFlags
= nil then Exit
;
7473 aName
:= LowerCase(aName
);
7475 for a
:= 0 to High(FAIFlags
) do
7476 if LowerCase(FAIFlags
[a
].Name
) = aName
then
7478 if a
<> High(FAIFlags
) then
7479 for b
:= a
to High(FAIFlags
)-1 do
7480 FAIFlags
[b
] := FAIFlags
[b
+1];
7482 SetLength(FAIFlags
, Length(FAIFlags
)-1);
7487 procedure TBot
.SetAIFlag(aName
, fValue
: String20
);
7495 aName
:= LowerCase(aName
);
7497 if FAIFlags
<> nil then
7498 for a
:= 0 to High(FAIFlags
) do
7499 if LowerCase(FAIFlags
[a
].Name
) = aName
then
7505 if ok
then FAIFlags
[a
].Value
:= fValue
7508 SetLength(FAIFlags
, Length(FAIFlags
)+1);
7509 with FAIFlags
[High(FAIFlags
)] do
7517 procedure TBot
.UpdateMove
;
7519 procedure GoLeft(Time
: Word = 1);
7521 ReleaseKey(KEY_LEFT
);
7522 ReleaseKey(KEY_RIGHT
);
7523 PressKey(KEY_LEFT
, Time
);
7524 SetDirection(TDirection
.D_LEFT
);
7527 procedure GoRight(Time
: Word = 1);
7529 ReleaseKey(KEY_LEFT
);
7530 ReleaseKey(KEY_RIGHT
);
7531 PressKey(KEY_RIGHT
, Time
);
7532 SetDirection(TDirection
.D_RIGHT
);
7535 function Rnd(a
: Word): Boolean;
7537 Result
:= Random(a
) = 0;
7540 procedure Turn(Time
: Word = 1200);
7542 if RunDirection() = TDirection
.D_LEFT
then GoRight(Time
) else GoLeft(Time
);
7547 ReleaseKey(KEY_LEFT
);
7548 ReleaseKey(KEY_RIGHT
);
7551 function CanRunLeft(): Boolean;
7553 Result
:= not CollideLevel(-1, 0);
7556 function CanRunRight(): Boolean;
7558 Result
:= not CollideLevel(1, 0);
7561 function CanRun(): Boolean;
7563 if RunDirection() = TDirection
.D_LEFT
then Result
:= CanRunLeft() else Result
:= CanRunRight();
7566 procedure Jump(Time
: Word = 30);
7568 PressKey(KEY_JUMP
, Time
);
7571 function NearHole(): Boolean;
7575 { TODO 5 : Ëåñòíèöû }
7576 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7577 for x
:= 1 to PLAYER_RECT
.Width
do
7578 if (not StayOnStep(x
*sx
, 0)) and
7579 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7580 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7589 function BorderHole(): Boolean;
7593 { TODO 5 : Ëåñòíèöû }
7594 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7595 for x
:= 1 to PLAYER_RECT
.Width
do
7596 if (not StayOnStep(x
*sx
, 0)) and
7597 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7598 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7600 for xx
:= x
to x
+32 do
7601 if CollideLevel(xx
*sx
, PLAYER_RECT
.Height
) then
7611 function NearDeepHole(): Boolean;
7617 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7620 for x
:= 1 to PLAYER_RECT
.Width
do
7621 if (not StayOnStep(x
*sx
, 0)) and
7622 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7623 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7625 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
7627 if CollideLevel(x
*sx
, PLAYER_RECT
.Height
*y
) then Exit
;
7632 end else Result
:= False;
7635 function OverDeepHole(): Boolean;
7642 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
7644 if CollideLevel(0, PLAYER_RECT
.Height
*y
) then Exit
;
7651 function OnGround(): Boolean;
7653 Result
:= StayOnStep(0, 0) or CollideLevel(0, 1);
7656 function OnLadder(): Boolean;
7658 Result
:= FullInStep(0, 0);
7661 function BelowLadder(): Boolean;
7663 Result
:= (FullInStep(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) and
7664 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
7665 (FullInStep(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) and
7666 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
7669 function BelowLiftUp(): Boolean;
7671 Result
:= ((FullInLift(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) = -1) and
7672 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
7673 ((FullInLift(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) = -1) and
7674 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
7677 function OnTopLift(): Boolean;
7679 Result
:= (FullInLift(0, 0) = -1) and (FullInLift(0, -32) = 0);
7682 function CanJumpOver(): Boolean;
7686 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7690 if not CollideLevel(sx
, 0) then Exit
;
7692 for y
:= 1 to BOT_MAXJUMP
do
7693 if CollideLevel(0, -y
) then Exit
else
7694 if not CollideLevel(sx
, -y
) then
7701 function CanJumpUp(Dist
: ShortInt): Boolean;
7708 if CollideLevel(Dist
, 0) then Exit
;
7711 for y
:= 0 to BOT_MAXJUMP
do
7712 if CollideLevel(Dist
, -y
) then
7721 for yy
:= y
+1 to BOT_MAXJUMP
do
7722 if not CollideLevel(Dist
, -yy
) then
7731 for y
:= 0 to BOT_MAXJUMP
do
7732 if CollideLevel(0, -y
) then
7740 if y
< yy
then Exit
;
7745 function IsSafeTrigger(): Boolean;
7750 if gTriggers
= nil then
7752 for a
:= 0 to High(gTriggers
) do
7753 if Collide(gTriggers
[a
].X
,
7756 gTriggers
[a
].Height
) and
7757 (gTriggers
[a
].TriggerType
in [TRIGGER_EXIT
, TRIGGER_CLOSEDOOR
,
7758 TRIGGER_CLOSETRAP
, TRIGGER_TRAP
,
7759 TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
,
7760 TRIGGER_ONOFF
, TRIGGER_SPAWNMONSTER
,
7761 TRIGGER_DAMAGE
, TRIGGER_SHOT
]) then
7766 // Âîçìîæíî, íàæèìàåì êíîïêó:
7767 if Rnd(16) and IsSafeTrigger() then
7770 // Åñëè ïîä ëèôòîì èëè ñòóïåíüêàìè, òî, âîçìîæíî, ïðûãàåì:
7771 if OnLadder() or ((BelowLadder() or BelowLiftUp()) and Rnd(8)) then
7773 ReleaseKey(KEY_LEFT
);
7774 ReleaseKey(KEY_RIGHT
);
7778 // Èäåì âëåâî, åñëè íàäî áûëî:
7779 if GetAIFlag('GOLEFT') <> '' then
7781 RemoveAIFlag('GOLEFT');
7782 if CanRunLeft() then
7786 // Èäåì âïðàâî, åñëè íàäî áûëî:
7787 if GetAIFlag('GORIGHT') <> '' then
7789 RemoveAIFlag('GORIGHT');
7790 if CanRunRight() then
7794 // Åñëè âûëåòåëè çà êàðòó, òî ïðîáóåì âåðíóòüñÿ:
7795 if FObj
.X
< -32 then
7798 if FObj
.X
+32 > gMapInfo
.Width
then
7801 // Ïðûãàåì, åñëè íàäî áûëî:
7802 if GetAIFlag('NEEDJUMP') <> '' then
7805 RemoveAIFlag('NEEDJUMP');
7808 // Ñìîòðèì ââåðõ, åñëè íàäî áûëî:
7809 if GetAIFlag('NEEDSEEUP') <> '' then
7812 ReleaseKey(KEY_DOWN
);
7813 PressKey(KEY_UP
, 20);
7814 RemoveAIFlag('NEEDSEEUP');
7817 // Ñìîòðèì âíèç, åñëè íàäî áûëî:
7818 if GetAIFlag('NEEDSEEDOWN') <> '' then
7821 ReleaseKey(KEY_DOWN
);
7822 PressKey(KEY_DOWN
, 20);
7823 RemoveAIFlag('NEEDSEEDOWN');
7826 // Åñëè íóæíî áûëî â äûðó è ìû íå íà çåìëå, òî ïîêîðíî ëåòèì:
7827 if GetAIFlag('GOINHOLE') <> '' then
7828 if not OnGround() then
7830 ReleaseKey(KEY_LEFT
);
7831 ReleaseKey(KEY_RIGHT
);
7832 RemoveAIFlag('GOINHOLE');
7833 SetAIFlag('FALLINHOLE', '1');
7836 // Åñëè ïàäàëè è äîñòèãëè çåìëè, òî õâàòèò ïàäàòü:
7837 if GetAIFlag('FALLINHOLE') <> '' then
7839 RemoveAIFlag('FALLINHOLE');
7841 // Åñëè ëåòåëè ïðÿìî è ñåé÷àñ íå íà ëåñòíèöå èëè íà âåðøèíå ëèôòà, òî îòõîäèì â ñòîðîíó:
7842 if not (KeyPressed(KEY_LEFT
) or KeyPressed(KEY_RIGHT
)) then
7843 if GetAIFlag('FALLINHOLE') = '' then
7844 if (not OnLadder()) or (FObj
.Vel
.Y
>= 0) or (OnTopLift()) then
7850 // Åñëè íà çåìëå è ìîæíî ïîäïðûãíóòü, òî, âîçìîæíî, ïðûãàåì:
7852 CanJumpUp(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*32) and
7856 // Åñëè íà çåìëå è âîçëå äûðû (ãëóáèíà > 2 ðîñòîâ èãðîêà):
7857 if OnGround() and NearHole() then
7858 if NearDeepHole() then // Åñëè ýòî áåçäíà
7860 0..3: Turn(); // Áåæèì îáðàòíî
7861 4: Jump(); // Ïðûãàåì
7862 5: begin // Ïðûãàåì îáðàòíî
7867 else // Ýòî íå áåçäíà è ìû åùå íå ëåòèì òóäà
7868 if GetAIFlag('GOINHOLE') = '' then
7870 0: Turn(); // Íå íóæíî òóäà
7871 1: Jump(); // Âäðóã ïîâåçåò - ïðûãàåì
7872 else // Åñëè ÿìà ñ ãðàíèöåé, òî ïðè ñëó÷àå ìîæíî òóäà ïðûãíóòü
7873 if BorderHole() then
7874 SetAIFlag('GOINHOLE', '1');
7877 // Åñëè íà çåìëå, íî íåêóäà èäòè:
7878 if (not CanRun()) and OnGround() then
7880 // Åñëè ìû íà ëåñòíèöå èëè ìîæíî ïåðåïðûãíóòü, òî ïðûãàåì:
7881 if CanJumpOver() or OnLadder() then
7883 else // èíà÷å ïîïûòàåìñÿ â äðóãóþ ñòîðîíó
7884 if Random(2) = 0 then
7886 if IsSafeTrigger() then
7892 // Îñòàëîñü ìàëî âîçäóõà:
7893 if FAir
< 36 * 2 then
7896 // Âûáèðàåìñÿ èç êèñëîòû, åñëè íåò êîñòþìà, îáîæãëèñü, èëè ìàëî çäîðîâüÿ:
7897 if (FMegaRulez
[MR_SUIT
] < gTime
) and ((FLastHit
= HIT_ACID
) or (Healthy() <= 1)) then
7898 if BodyInAcid(0, 0) then
7902 function TBot
.FullInStep(XInc
, YInc
: Integer): Boolean;
7904 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
7905 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_STEP
, False);
7908 {function TBot.NeedItem(Item: Byte): Byte;
7913 procedure TBot
.SelectWeapon(Dist
: Integer);
7917 function HaveAmmo(weapon
: Byte): Boolean;
7920 WEAPON_PISTOL
: Result
:= FAmmo
[A_BULLETS
] >= 1;
7921 WEAPON_SHOTGUN1
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7922 WEAPON_SHOTGUN2
: Result
:= FAmmo
[A_SHELLS
] >= 2;
7923 WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
] >= 10;
7924 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
] >= 1;
7925 WEAPON_PLASMA
: Result
:= FAmmo
[A_CELLS
] >= 10;
7926 WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
] >= 40;
7927 WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7928 WEAPON_FLAMETHROWER
: Result
:= FAmmo
[A_FUEL
] >= 1;
7929 else Result
:= True;
7934 if Dist
= -1 then Dist
:= BOT_LONGDIST
;
7936 if Dist
> BOT_LONGDIST
then
7937 begin // Äàëüíèé áîé
7939 if FWeapon
[FDifficult
.WeaponPrior
[a
]] and HaveAmmo(FDifficult
.WeaponPrior
[a
]) then
7941 FSelectedWeapon
:= FDifficult
.WeaponPrior
[a
];
7945 else //if Dist > BOT_UNSAFEDIST then
7946 begin // Áëèæíèé áîé
7948 if FWeapon
[FDifficult
.CloseWeaponPrior
[a
]] and HaveAmmo(FDifficult
.CloseWeaponPrior
[a
]) then
7950 FSelectedWeapon
:= FDifficult
.CloseWeaponPrior
[a
];
7957 if FWeapon[FDifficult.SafeWeaponPrior[a]] and HaveAmmo(FDifficult.SafeWeaponPrior[a]) then
7959 FSelectedWeapon := FDifficult.SafeWeaponPrior[a];
7965 function TBot
.PickItem(ItemType
: Byte; force
: Boolean; var remove
: Boolean): Boolean;
7967 Result
:= inherited PickItem(ItemType
, force
, remove
);
7969 if Result
then SetAIFlag('SELECTWEAPON', '1');
7972 function TBot
.Heal(value
: Word; Soft
: Boolean): Boolean;
7974 Result
:= inherited Heal(value
, Soft
);
7977 function TBot
.Healthy(): Byte;
7979 if FMegaRulez
[MR_INVUL
] >= gTime
then Result
:= 3
7980 else if (FHealth
> 80) or ((FHealth
> 50) and (FArmor
> 20)) then Result
:= 3
7981 else if (FHealth
> 50) then Result
:= 2
7982 else if (FHealth
> 20) then Result
:= 1
7986 function TBot
.TargetOnScreen(TX
, TY
: Integer): Boolean;
7988 Result
:= (Abs(FObj
.X
-TX
) <= Trunc(gPlayerScreenSize
.X
*0.6)) and
7989 (Abs(FObj
.Y
-TY
) <= Trunc(gPlayerScreenSize
.Y
*0.6));
7992 procedure TBot
.OnDamage(Angle
: SmallInt);
8000 if (Angle
= 0) or (Angle
= 180) then
8003 if (g_GetUIDType(FLastSpawnerUID
) = UID_PLAYER
) and
8004 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
) then
8006 pla
:= g_Player_Get(FLastSpawnerUID
);
8007 ok
:= not TargetOnScreen(pla
.FObj
.X
+ PLAYER_RECT
.X
,
8008 pla
.FObj
.Y
+ PLAYER_RECT
.Y
);
8011 if (g_GetUIDType(FLastSpawnerUID
) = UID_MONSTER
) and
8012 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
) then
8014 mon
:= g_Monsters_ByUID(FLastSpawnerUID
);
8015 ok
:= not TargetOnScreen(mon
.Obj
.X
+ mon
.Obj
.Rect
.X
,
8016 mon
.Obj
.Y
+ mon
.Obj
.Rect
.Y
);
8021 SetAIFlag('ATTACKLEFT', '1')
8023 SetAIFlag('ATTACKRIGHT', '1');
8027 function TBot
.RunDirection(): TDirection
;
8029 if Abs(Vel
.X
) >= 1 then
8031 if Vel
.X
> 0 then Result
:= TDirection
.D_RIGHT
else Result
:= TDirection
.D_LEFT
;
8033 Result
:= FDirection
;
8036 function TBot
.GetRnd(a
: Byte): Boolean;
8038 if a
= 0 then Result
:= False
8039 else if a
= 255 then Result
:= True
8040 else Result
:= Random(256) > 255-a
;
8043 function TBot
.GetInterval(a
: Byte; radius
: SmallInt): SmallInt;
8045 Result
:= Round((255-a
)/255*radius
*(Random(2)-1));
8049 procedure TDifficult
.save (st
: TStream
);
8051 utils
.writeInt(st
, Byte(DiagFire
));
8052 utils
.writeInt(st
, Byte(InvisFire
));
8053 utils
.writeInt(st
, Byte(DiagPrecision
));
8054 utils
.writeInt(st
, Byte(FlyPrecision
));
8055 utils
.writeInt(st
, Byte(Cover
));
8056 utils
.writeInt(st
, Byte(CloseJump
));
8057 st
.WriteBuffer(WeaponPrior
[Low(WeaponPrior
)], sizeof(WeaponPrior
));
8058 st
.WriteBuffer(CloseWeaponPrior
[Low(CloseWeaponPrior
)], sizeof(CloseWeaponPrior
));
8061 procedure TDifficult
.load (st
: TStream
);
8063 DiagFire
:= utils
.readByte(st
);
8064 InvisFire
:= utils
.readByte(st
);
8065 DiagPrecision
:= utils
.readByte(st
);
8066 FlyPrecision
:= utils
.readByte(st
);
8067 Cover
:= utils
.readByte(st
);
8068 CloseJump
:= utils
.readByte(st
);
8069 st
.ReadBuffer(WeaponPrior
[Low(WeaponPrior
)], sizeof(WeaponPrior
));
8070 st
.ReadBuffer(CloseWeaponPrior
[Low(CloseWeaponPrior
)], sizeof(CloseWeaponPrior
));
8074 procedure TBot
.SaveState (st
: TStream
);
8079 inherited SaveState(st
);
8080 utils
.writeSign(st
, 'BOT0');
8082 utils
.writeInt(st
, Byte(FSelectedWeapon
));
8084 utils
.writeInt(st
, Word(FTargetUID
));
8085 // Âðåìÿ ïîòåðè öåëè
8086 utils
.writeInt(st
, LongWord(FLastVisible
));
8087 // Êîëè÷åñòâî ôëàãîâ ÈÈ
8088 dw
:= Length(FAIFlags
);
8089 utils
.writeInt(st
, LongInt(dw
));
8091 for i
:= 0 to dw
-1 do
8093 utils
.writeStr(st
, FAIFlags
[i
].Name
, 20);
8094 utils
.writeStr(st
, FAIFlags
[i
].Value
, 20);
8096 // Íàñòðîéêè ñëîæíîñòè
8097 FDifficult
.save(st
);
8101 procedure TBot
.LoadState (st
: TStream
);
8106 inherited LoadState(st
);
8107 if not utils
.checkSign(st
, 'BOT0') then raise XStreamError
.Create('invalid bot signature');
8109 FSelectedWeapon
:= utils
.readByte(st
);
8111 FTargetUID
:= utils
.readWord(st
);
8112 // Âðåìÿ ïîòåðè öåëè
8113 FLastVisible
:= utils
.readLongWord(st
);
8114 // Êîëè÷åñòâî ôëàãîâ ÈÈ
8115 dw
:= utils
.readLongInt(st
);
8116 if (dw
< 0) or (dw
> 16384) then raise XStreamError
.Create('invalid number of bot AI flags');
8117 SetLength(FAIFlags
, dw
);
8119 for i
:= 0 to dw
-1 do
8121 FAIFlags
[i
].Name
:= utils
.readStr(st
, 20);
8122 FAIFlags
[i
].Value
:= utils
.readStr(st
, 20);
8124 // Íàñòðîéêè ñëîæíîñòè
8125 FDifficult
.load(st
);
8130 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');
8131 conRegVar('player_indicator_style', @gPlayerIndicatorStyle
, 'Visual appearance of indicator', 'Visual appearance of indicator');