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;
2864 s
:= IntToStr(p
)+' / '+IntToStr(Length(stat
))+' ';
2865 if Frags
>= m
then s
:= s
+'+' else s
:= s
+'-';
2866 s
:= s
+IntToStr(Abs(Frags
-m
));
2868 t
:= IntToStr(p
)+' / '+IntToStr(Length(stat
))+' ';
2869 if Assists
>= m
then t
:= t
+'+' else t
:= t
+'-';
2870 t
:= t
+IntToStr(Abs(Assists
-m
));
2872 e_CharFont_GetSize(gMenuSmallFont
, s
, tw
, th
);
2873 e_CharFont_PrintEx(gMenuSmallFont
, X
-16-tw
, Y
+32, s
, _RGB(255, 0, 0));
2876 if gLMSRespawn
> LMS_RESPAWN_NONE
then
2878 s
:= _lc
[I_GAME_WARMUP
];
2879 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2880 s
:= s
+ ': ' + IntToStr((gLMSRespawnTime
- gTime
) div 1000);
2881 e_CharFont_PrintEx(gMenuFont
, X
-64-tw
, SY
-32, s
, _RGB(0, 255, 0));
2883 else if gShowLives
and (gGameSettings
.MaxLives
> 0) then
2885 s
:= IntToStr(Lives
);
2886 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2887 e_CharFont_PrintEx(gMenuFont
, X
-16-tw
, SY
-32, s
, _RGB(0, 255, 0));
2891 e_CharFont_GetSize(gMenuSmallFont
, FName
, tw
, th
);
2892 e_CharFont_PrintEx(gMenuSmallFont
, X
+98-(tw
div 2), Y
+8, FName
, _RGB(255, 0, 0));
2894 if R_BERSERK
in FRulez
then
2895 e_Draw(gItemsTexturesID
[ITEM_MEDKIT_BLACK
], X
+37, Y
+45, 0, True, False)
2897 e_Draw(gItemsTexturesID
[ITEM_MEDKIT_LARGE
], X
+37, Y
+45, 0, True, False);
2899 if g_Texture_Get('TEXTURE_PLAYER_ARMORHUD', ID
) then
2900 e_Draw(ID
, X
+36, Y
+77, 0, True, False);
2902 s
:= IntToStr(IfThen(FHealth
> 0, FHealth
, 0));
2903 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2904 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+40, s
, _RGB(255, 0, 0));
2906 s
:= IntToStr(FArmor
);
2907 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2908 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+68, s
, _RGB(255, 0, 0));
2910 s
:= IntToStr(GetAmmoByWeapon(FCurrWeap
));
2916 ID
:= gItemsTexturesID
[ITEM_WEAPON_KASTET
];
2921 ID
:= gItemsTexturesID
[ITEM_WEAPON_SAW
];
2923 WEAPON_PISTOL
: ID
:= gItemsTexturesID
[ITEM_WEAPON_PISTOL
];
2924 WEAPON_CHAINGUN
: ID
:= gItemsTexturesID
[ITEM_WEAPON_CHAINGUN
];
2925 WEAPON_SHOTGUN1
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SHOTGUN1
];
2926 WEAPON_SHOTGUN2
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SHOTGUN2
];
2927 WEAPON_SUPERPULEMET
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SUPERPULEMET
];
2928 WEAPON_ROCKETLAUNCHER
: ID
:= gItemsTexturesID
[ITEM_WEAPON_ROCKETLAUNCHER
];
2929 WEAPON_PLASMA
: ID
:= gItemsTexturesID
[ITEM_WEAPON_PLASMA
];
2930 WEAPON_BFG
: ID
:= gItemsTexturesID
[ITEM_WEAPON_BFG
];
2931 WEAPON_FLAMETHROWER
: ID
:= gItemsTexturesID
[ITEM_WEAPON_FLAMETHROWER
];
2934 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2935 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+158, s
, _RGB(255, 0, 0));
2936 e_Draw(ID
, X
+20, Y
+160, 0, True, False);
2938 if R_KEY_RED
in FRulez
then
2939 e_Draw(gItemsTexturesID
[ITEM_KEY_RED
], X
+78, Y
+214, 0, True, False);
2941 if R_KEY_GREEN
in FRulez
then
2942 e_Draw(gItemsTexturesID
[ITEM_KEY_GREEN
], X
+95, Y
+214, 0, True, False);
2944 if R_KEY_BLUE
in FRulez
then
2945 e_Draw(gItemsTexturesID
[ITEM_KEY_BLUE
], X
+112, Y
+214, 0, True, False);
2947 if FJetFuel
> 0 then
2949 if g_Texture_Get('TEXTURE_PLAYER_HUDAIR', ID
) then
2950 e_Draw(ID
, X
+2, Y
+116, 0, True, False);
2951 if g_Texture_Get('TEXTURE_PLAYER_HUDJET', ID
) then
2952 e_Draw(ID
, X
+2, Y
+126, 0, True, False);
2953 e_DrawLine(4, X
+16, Y
+122, X
+16+Trunc(168*IfThen(FAir
> 0, FAir
, 0)/AIR_MAX
), Y
+122, 0, 0, 196);
2954 e_DrawLine(4, X
+16, Y
+132, X
+16+Trunc(168*FJetFuel
/JET_MAX
), Y
+132, 208, 0, 0);
2958 if g_Texture_Get('TEXTURE_PLAYER_HUDAIR', ID
) then
2959 e_Draw(ID
, X
+2, Y
+124, 0, True, False);
2960 e_DrawLine(4, X
+16, Y
+130, X
+16+Trunc(168*IfThen(FAir
> 0, FAir
, 0)/AIR_MAX
), Y
+130, 0, 0, 196);
2963 if gShowPing
and g_Game_IsClient
then
2965 s
:= _lc
[I_GAME_PING_HUD
] + IntToStr(NetPeer
.lastRoundTripTime
) + _lc
[I_NET_SLIST_PING_MS
];
2966 e_TextureFontPrint(X
+ 4, Y
+ 242, s
, gStdFont
);
2972 e_TextureFontPrint(X
+ 4, Y
+ 242, _lc
[I_PLAYER_SPECT
], gStdFont
);
2973 e_TextureFontPrint(X
+ 4, Y
+ 258, _lc
[I_PLAYER_SPECT2
], gStdFont
);
2974 e_TextureFontPrint(X
+ 4, Y
+ 274, _lc
[I_PLAYER_SPECT1
], gStdFont
);
2977 e_TextureFontGetSize(gStdFont
, cw
, ch
);
2978 s
:= _lc
[I_PLAYER_SPECT4
];
2979 e_TextureFontPrintEx(gScreenWidth
div 2 - cw
*(Length(s
) div 2),
2980 gScreenHeight
-4-ch
, s
, gStdFont
, 255, 255, 255, 1, True);
2981 e_TextureFontPrint(X
+ 4, Y
+ 290, _lc
[I_PLAYER_SPECT1S
], gStdFont
);
2987 procedure TPlayer
.DrawRulez();
2991 // Ïðè âçÿòèè íåóÿçâèìîñòè ðèñóåòñÿ èíâåðñèîííûé áåëûé ôîí
2992 if (FMegaRulez
[MR_INVUL
] >= gTime
) and (FSpawnInvul
< gTime
) then
2994 if (FMegaRulez
[MR_INVUL
]-gTime
) <= 2100 then
2995 dr
:= not Odd((FMegaRulez
[MR_INVUL
]-gTime
) div 300)
3000 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
3001 191, 191, 191, 0, TBlending
.Invert
);
3004 // Ïðè âçÿòèè çàùèòíîãî êîñòþìà ðèñóåòñÿ çåëåíîâàòûé ôîí
3005 if FMegaRulez
[MR_SUIT
] >= gTime
then
3007 if (FMegaRulez
[MR_SUIT
]-gTime
) <= 2100 then
3008 dr
:= not Odd((FMegaRulez
[MR_SUIT
]-gTime
) div 300)
3013 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
3014 0, 96, 0, 200, TBlending
.None
);
3017 // Ïðè âçÿòèè áåðñåðêà ðèñóåòñÿ êðàñíîâàòûé ôîí
3018 if (FBerserk
>= 0) and (LongWord(FBerserk
) >= gTime
) and (gFlash
= 2) then
3020 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
3021 255, 0, 0, 200, TBlending
.None
);
3025 procedure TPlayer
.DrawPain();
3029 if FPain
= 0 then Exit
;
3033 if a
< 15 then h
:= 0
3034 else if a
< 35 then h
:= 1
3035 else if a
< 55 then h
:= 2
3036 else if a
< 75 then h
:= 3
3037 else if a
< 95 then h
:= 4
3040 //if a > 255 then a := 255;
3042 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1, 255, 0, 0, 255-h
*50);
3043 //e_DrawFillQuad(0, 0, gPlayerScreenSize.X-1, gPlayerScreenSize.Y-1, 255-min(128, a), 255-a, 255-a, 0, B_FILTER);
3046 procedure TPlayer
.DrawPickup();
3050 if FPickup
= 0 then Exit
;
3054 if a
< 15 then h
:= 1
3055 else if a
< 35 then h
:= 2
3056 else if a
< 55 then h
:= 3
3057 else if a
< 75 then h
:= 4
3060 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1, 150, 200, 150, 255-h
*50);
3063 procedure TPlayer
.DoPunch();
3068 if FPunchAnim
<> nil then begin
3073 st
:= 'FRAMES_PUNCH';
3074 if R_BERSERK
in FRulez
then
3075 st
:= st
+ '_BERSERK';
3076 if FKeys
[KEY_UP
].Pressed
then
3078 else if FKeys
[KEY_DOWN
].Pressed
then
3080 g_Frames_Get(id
, st
);
3081 FPunchAnim
:= TAnimation
.Create(id
, False, 1);
3084 procedure TPlayer
.Fire();
3086 f
, DidFire
: Boolean;
3087 wx
, wy
, xd
, yd
: Integer;
3090 if g_Game_IsClient
then Exit
;
3091 // FBFGFireCounter - âðåìÿ ïåðåä âûñòðåëîì (äëÿ BFG)
3092 // FReloading - âðåìÿ ïîñëå âûñòðåëà (äëÿ âñåãî)
3100 if FReloading
[FCurrWeap
] <> 0 then Exit
;
3105 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
3106 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
3107 xd
:= wx
+IfThen(FDirection
= TDirection
.D_LEFT
, -30, 30);
3108 yd
:= wy
+firediry();
3114 if R_BERSERK
in FRulez
then
3116 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
3117 locobj
.X
:= FObj
.X
+FObj
.Rect
.X
;
3118 locobj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
3121 locobj
.rect
.Width
:= 39;
3122 locobj
.rect
.Height
:= 52;
3123 locobj
.Vel
.X
:= (xd
-wx
) div 2;
3124 locobj
.Vel
.Y
:= (yd
-wy
) div 2;
3125 locobj
.Accel
.X
:= xd
-wx
;
3126 locobj
.Accel
.y
:= yd
-wy
;
3128 if g_Weapon_Hit(@locobj
, 50, FUID
, HIT_SOME
) <> 0 then
3129 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
3131 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
3133 if (gFlash
= 1) and (FPain
< 50) then FPain
:= min(FPain
+ 25, 50);
3137 g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
3141 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3146 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
3147 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
3149 FSawSoundSelect
.Stop();
3151 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
3153 else if not FSawSoundHit
.IsPlaying() then
3155 FSawSoundSelect
.Stop();
3156 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
3159 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3165 if FAmmo
[A_BULLETS
] > 0 then
3167 g_Weapon_pistol(wx
, wy
, xd
, yd
, FUID
);
3168 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3169 Dec(FAmmo
[A_BULLETS
]);
3170 FFireAngle
:= FAngle
;
3173 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
3174 GameVelX
, GameVelY
-2, SHELL_BULLET
);
3178 if FAmmo
[A_SHELLS
] > 0 then
3180 g_Weapon_shotgun(wx
, wy
, xd
, yd
, FUID
);
3181 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', wx
, wy
);
3182 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3183 Dec(FAmmo
[A_SHELLS
]);
3184 FFireAngle
:= FAngle
;
3188 FShellType
:= SHELL_SHELL
;
3192 if FAmmo
[A_SHELLS
] >= 2 then
3194 g_Weapon_dshotgun(wx
, wy
, xd
, yd
, FUID
);
3195 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3196 Dec(FAmmo
[A_SHELLS
], 2);
3197 FFireAngle
:= FAngle
;
3201 FShellType
:= SHELL_DBLSHELL
;
3205 if FAmmo
[A_BULLETS
] > 0 then
3207 g_Weapon_mgun(wx
, wy
, xd
, yd
, FUID
);
3208 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', wx
, wy
);
3209 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3210 Dec(FAmmo
[A_BULLETS
]);
3211 FFireAngle
:= FAngle
;
3214 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
3215 GameVelX
, GameVelY
-2, SHELL_BULLET
);
3218 WEAPON_ROCKETLAUNCHER
:
3219 if FAmmo
[A_ROCKETS
] > 0 then
3221 g_Weapon_rocket(wx
, wy
, xd
, yd
, FUID
);
3222 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3223 Dec(FAmmo
[A_ROCKETS
]);
3224 FFireAngle
:= FAngle
;
3230 if FAmmo
[A_CELLS
] > 0 then
3232 g_Weapon_plasma(wx
, wy
, xd
, yd
, FUID
);
3233 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3234 Dec(FAmmo
[A_CELLS
]);
3235 FFireAngle
:= FAngle
;
3241 if (FAmmo
[A_CELLS
] >= 40) and (FBFGFireCounter
= -1) then
3243 FBFGFireCounter
:= 17;
3244 if not FNoReload
then
3245 g_Sound_PlayExAt('SOUND_WEAPON_STARTFIREBFG', FObj
.X
, FObj
.Y
);
3246 Dec(FAmmo
[A_CELLS
], 40);
3250 WEAPON_SUPERPULEMET
:
3251 if FAmmo
[A_SHELLS
] > 0 then
3253 g_Weapon_shotgun(wx
, wy
, xd
, yd
, FUID
);
3254 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', wx
, wy
);
3255 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3256 Dec(FAmmo
[A_SHELLS
]);
3257 FFireAngle
:= FAngle
;
3260 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
3261 GameVelX
, GameVelY
-2, SHELL_SHELL
);
3264 WEAPON_FLAMETHROWER
:
3265 if FAmmo
[A_FUEL
] > 0 then
3267 g_Weapon_flame(wx
, wy
, xd
, yd
, FUID
);
3269 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3271 FFireAngle
:= FAngle
;
3278 if g_Game_IsNet
and g_Game_IsServer
then MH_SEND_PlayerStats(FUID
);
3282 if g_Game_IsNet
then
3286 if FCurrWeap
<> WEAPON_BFG
then
3287 MH_SEND_PlayerFire(FUID
, FCurrWeap
, wx
, wy
, xd
, yd
, LastShotID
)
3289 if not FNoReload
then
3290 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_WEAPON_STARTFIREBFG');
3293 MH_SEND_PlayerStats(FUID
);
3298 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
3299 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
3300 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
3303 function TPlayer
.GetAmmoByWeapon(Weapon
: Byte): Word;
3306 WEAPON_PISTOL
, WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
];
3307 WEAPON_SHOTGUN1
, WEAPON_SHOTGUN2
, WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
];
3308 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
];
3309 WEAPON_PLASMA
, WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
];
3310 WEAPON_FLAMETHROWER
: Result
:= FAmmo
[A_FUEL
];
3315 function TPlayer
.HeadInLiquid(XInc
, YInc
: Integer): Boolean;
3317 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
+XInc
, FObj
.Y
+PLAYER_HEADRECT
.Y
+YInc
,
3318 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
3319 PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, True);
3322 procedure TPlayer
.FlamerOn
;
3324 FFlameSoundOff
.Stop();
3325 FFlameSoundOff
.SetPosition(0);
3328 if (not FFlameSoundOn
.IsPlaying()) and (not FFlameSoundWork
.IsPlaying()) then
3329 FFlameSoundWork
.PlayAt(FObj
.X
, FObj
.Y
);
3333 FFlameSoundOn
.PlayAt(FObj
.X
, FObj
.Y
);
3338 procedure TPlayer
.FlamerOff
;
3342 FFlameSoundOn
.Stop();
3343 FFlameSoundOn
.SetPosition(0);
3344 FFlameSoundWork
.Stop();
3345 FFlameSoundWork
.SetPosition(0);
3346 FFlameSoundOff
.PlayAt(FObj
.X
, FObj
.Y
);
3351 procedure TPlayer
.JetpackOn
;
3355 FJetSoundOn
.SetPosition(0);
3356 FJetSoundOn
.PlayAt(FObj
.X
, FObj
.Y
);
3360 procedure TPlayer
.JetpackOff
;
3364 FJetSoundOff
.SetPosition(0);
3365 FJetSoundOff
.PlayAt(FObj
.X
, FObj
.Y
);
3368 procedure TPlayer
.CatchFire(Attacker
: Word; Timeout
: Integer = PLAYER_BURN_TIME
);
3370 if Timeout
<= 0 then
3372 if (FMegaRulez
[MR_SUIT
] > gTime
) or (FMegaRulez
[MR_INVUL
] > gTime
) then
3373 exit
; // Íå çàãîðàåìñÿ êîãäà åñòü çàùèòà
3374 if g_Obj_CollidePanel(@FObj
, 0, 0, PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
) then
3375 exit
; // Íå ïîäãîðàåì â âîäå íà âñÿêèé ñëó÷àé
3376 if FFireTime
<= 0 then
3377 g_Sound_PlayExAt('SOUND_IGNITE', FObj
.X
, FObj
.Y
);
3378 FFireTime
:= Timeout
;
3379 FFireAttacker
:= Attacker
;
3380 if g_Game_IsNet
and g_Game_IsServer
then
3381 MH_SEND_PlayerStats(FUID
);
3384 procedure TPlayer
.Jump();
3386 if gFly
or FJetpack
then
3388 // Ïîëåò (÷èò-êîä èëè äæåòïàê):
3389 if FObj
.Vel
.Y
> -VEL_FLY
then
3390 FObj
.Vel
.Y
:= FObj
.Vel
.Y
- 3;
3393 if FJetFuel
> 0 then
3395 if (FJetFuel
< 1) and g_Game_IsServer
then
3399 if g_Game_IsNet
then
3400 MH_SEND_PlayerStats(FUID
);
3406 // Íå âêëþ÷àòü äæåòïàê â ðåæèìå ïðîõîæäåíèÿ ñêâîçü ñòåíû
3408 FCanJetpack
:= False;
3410 // Ïðûãàåì èëè âñïëûâàåì:
3411 if (CollideLevel(0, 1) or
3412 g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
+36, PLAYER_RECT
.Width
,
3413 PLAYER_RECT
.Height
-33, PANEL_STEP
, False)
3414 ) and (FObj
.Accel
.Y
= 0) then // Íå ïðûãàòü, åñëè åñòü âåðòèêàëüíîå óñêîðåíèå
3416 FObj
.Vel
.Y
:= -VEL_JUMP
;
3417 FCanJetpack
:= False;
3421 if BodyInLiquid(0, 0) then
3422 FObj
.Vel
.Y
:= -VEL_SW
3423 else if (FJetFuel
> 0) and FCanJetpack
and
3424 g_Game_IsServer
and (not g_Obj_CollideLiquid(@FObj
, 0, 0)) then
3428 if g_Game_IsNet
then
3429 MH_SEND_PlayerStats(FUID
);
3434 procedure TPlayer
.Kill(KillType
: Byte; SpawnerUID
: Word; t
: Byte);
3436 a
, i
, k
, ab
, ar
: Byte;
3440 srv
, netsrv
: Boolean;
3446 procedure PushItem(t
: Byte);
3450 id
:= g_Items_Create(FObj
.X
, FObj
.Y
, t
, True, False);
3451 it
:= g_Items_ByIdx(id
);
3452 if KillType
= K_EXTRAHARDKILL
then // -7..+7; -8..0
3454 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-7+Random(15),
3455 (FObj
.Vel
.Y
div 2)-Random(9));
3456 it
.positionChanged(); // this updates spatial accelerators
3460 if KillType
= K_HARDKILL
then // -5..+5; -5..0
3462 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-5+Random(11),
3463 (FObj
.Vel
.Y
div 2)-Random(6));
3465 else // -3..+3; -3..0
3467 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-3+Random(7),
3468 (FObj
.Vel
.Y
div 2)-Random(4));
3470 it
.positionChanged(); // this updates spatial accelerators
3473 if g_Game_IsNet
and g_Game_IsServer
then
3474 MH_SEND_ItemSpawn(True, id
);
3478 DoFrags
:= (gGameSettings
.MaxLives
= 0) or (gGameSettings
.GameMode
= GM_COOP
);
3479 Srv
:= g_Game_IsServer
;
3480 Netsrv
:= g_Game_IsServer
and g_Game_IsNet
;
3481 if Srv
then FDeath
:= FDeath
+ 1;
3486 if not FPhysics
then
3492 if (gGameSettings
.MaxLives
> 0) and Srv
and (gLMSRespawn
= LMS_RESPAWN_NONE
) then
3494 if FLives
> 0 then FLives
:= FLives
- 1;
3495 if FLives
= 0 then FNoRespawn
:= True;
3498 // Íîìåð òèïà ñìåðòè:
3501 K_SIMPLEKILL
: a
:= 1;
3503 K_EXTRAHARDKILL
: a
:= 3;
3508 if not FModel
.PlaySound(MODELSOUND_DIE
, a
, FObj
.X
, FObj
.Y
) then
3510 if FModel
.PlaySound(MODELSOUND_DIE
, i
, FObj
.X
, FObj
.Y
) then
3517 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN1
;
3519 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN2
;
3520 K_EXTRAHARDKILL
, K_FALLKILL
:
3521 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN3
;
3524 // Ïåðåêëþ÷àåì ñîñòîÿíèå:
3528 K_HARDKILL
, K_EXTRAHARDKILL
:
3532 // Ðåàêöèÿ ìîíñòðîâ íà ñìåðòü èãðîêà:
3533 if (KillType
<> K_FALLKILL
) and (Srv
) then
3534 g_Monsters_killedp();
3536 if SpawnerUID
= FUID
then
3540 if gGameSettings
.GameMode
= GM_TDM
then
3541 Dec(gTeamStat
[FTeam
].Score
);
3542 if DoFrags
or (gGameSettings
.GameMode
= GM_TDM
) then
3548 g_Console_Add(Format(_lc
[I_PLAYER_KILL_SELF
], [FName
]), True);
3551 if g_GetUIDType(SpawnerUID
) = UID_PLAYER
then
3552 begin // Óáèò äðóãèì èãðîêîì
3553 KP
:= g_Player_Get(SpawnerUID
);
3554 if (KP
<> nil) and Srv
then
3556 if (DoFrags
or (gGameSettings
.GameMode
= GM_TDM
)) then
3557 if SameTeam(FUID
, SpawnerUID
) then
3567 if (gGameSettings
.GameMode
= GM_TDM
) and DoFrags
then
3568 Inc(gTeamStat
[KP
.Team
].Score
,
3569 IfThen(SameTeam(FUID
, SpawnerUID
), -1, 1));
3571 if netsrv
then MH_SEND_PlayerStats(SpawnerUID
);
3574 plr
:= g_Player_Get(SpawnerUID
);
3582 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_2
],
3586 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_1
],
3590 g_Console_Add(Format(_lc
[I_PLAYER_KILL
],
3595 else if g_GetUIDType(SpawnerUID
) = UID_MONSTER
then
3596 begin // Óáèò ìîíñòðîì
3597 mon
:= g_Monsters_ByUID(SpawnerUID
);
3601 s
:= g_Mons_GetKilledByTypeId(mon
.MonsterType
);
3605 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_2
],
3609 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_1
],
3613 g_Console_Add(Format(_lc
[I_PLAYER_KILL
],
3618 else // Îñîáûå òèïû ñìåðòè
3621 HIT_SELF
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_SELF
], [FName
]), True);
3622 HIT_FALL
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_FALL
], [FName
]), True);
3623 HIT_WATER
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_WATER
], [FName
]), True);
3624 HIT_ACID
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_ACID
], [FName
]), True);
3625 HIT_TRAP
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_TRAP
], [FName
]), True);
3626 else g_Console_Add(Format(_lc
[I_PLAYER_DIED
], [FName
]), True);
3632 for a
:= WP_FIRST
to WP_LAST
do
3636 WEAPON_SAW
: i
:= ITEM_WEAPON_SAW
;
3637 WEAPON_SHOTGUN1
: i
:= ITEM_WEAPON_SHOTGUN1
;
3638 WEAPON_SHOTGUN2
: i
:= ITEM_WEAPON_SHOTGUN2
;
3639 WEAPON_CHAINGUN
: i
:= ITEM_WEAPON_CHAINGUN
;
3640 WEAPON_ROCKETLAUNCHER
: i
:= ITEM_WEAPON_ROCKETLAUNCHER
;
3641 WEAPON_PLASMA
: i
:= ITEM_WEAPON_PLASMA
;
3642 WEAPON_BFG
: i
:= ITEM_WEAPON_BFG
;
3643 WEAPON_SUPERPULEMET
: i
:= ITEM_WEAPON_SUPERPULEMET
;
3644 WEAPON_FLAMETHROWER
: i
:= ITEM_WEAPON_FLAMETHROWER
;
3653 if R_ITEM_BACKPACK
in FRulez
then
3654 PushItem(ITEM_AMMO_BACKPACK
);
3656 // Âûáðîñ ðàêåòíîãî ðàíöà:
3657 if FJetFuel
> 0 then
3658 PushItem(ITEM_JETPACK
);
3661 if (not (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
])) or
3662 (not LongBool(gGameSettings
.Options
and GAME_OPTION_DMKEYS
)) then
3664 if R_KEY_RED
in FRulez
then
3665 PushItem(ITEM_KEY_RED
);
3667 if R_KEY_GREEN
in FRulez
then
3668 PushItem(ITEM_KEY_GREEN
);
3670 if R_KEY_BLUE
in FRulez
then
3671 PushItem(ITEM_KEY_BLUE
);
3675 DropFlag(KillType
= K_FALLKILL
);
3678 FCorpse
:= g_Player_CreateCorpse(Self
);
3680 if Srv
and (gGameSettings
.MaxLives
> 0) and FNoRespawn
and
3681 (gLMSRespawn
= LMS_RESPAWN_NONE
) then
3687 for i
:= Low(gPlayers
) to High(gPlayers
) do
3689 if gPlayers
[i
] = nil then continue
;
3690 if (not gPlayers
[i
].FNoRespawn
) and (not gPlayers
[i
].FSpectator
) then
3693 if gPlayers
[i
].FTeam
= TEAM_RED
then Inc(ar
)
3694 else if gPlayers
[i
].FTeam
= TEAM_BLUE
then Inc(ab
);
3699 OldLR
:= gLMSRespawn
;
3700 if (gGameSettings
.GameMode
= GM_COOP
) then
3704 // everyone is dead, restart the map
3705 g_Game_Message(_lc
[I_MESSAGE_LMS_LOSE
], 144);
3707 MH_SEND_GameEvent(NET_EV_LMS_LOSE
);
3708 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3709 gLMSRespawnTime
:= gTime
+ 5000;
3711 else if (a
= 1) then
3713 if (gPlayers
[k
] <> nil) and not (gPlayers
[k
] is TBot
) then
3714 if (gPlayers
[k
] = gPlayer1
) or
3715 (gPlayers
[k
] = gPlayer2
) then
3716 g_Console_Add('*** ' + _lc
[I_MESSAGE_LMS_SURVIVOR
] + ' ***', True)
3717 else if Netsrv
and (gPlayers
[k
].FClientID
>= 0) then
3718 MH_SEND_GameEvent(NET_EV_LMS_SURVIVOR
, 0, 'N', gPlayers
[k
].FClientID
);
3721 else if (gGameSettings
.GameMode
= GM_TDM
) then
3723 if (ab
= 0) and (ar
<> 0) then
3726 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 144);
3728 MH_SEND_GameEvent(NET_EV_TLMS_WIN
, TEAM_RED
);
3729 Inc(gTeamStat
[TEAM_RED
].Score
);
3730 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3731 gLMSRespawnTime
:= gTime
+ 5000;
3733 else if (ar
= 0) and (ab
<> 0) then
3736 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 144);
3738 MH_SEND_GameEvent(NET_EV_TLMS_WIN
, TEAM_BLUE
);
3739 Inc(gTeamStat
[TEAM_BLUE
].Score
);
3740 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3741 gLMSRespawnTime
:= gTime
+ 5000;
3743 else if (ar
= 0) and (ab
= 0) then
3746 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
3748 MH_SEND_GameEvent(NET_EV_LMS_DRAW
, 0, FName
);
3749 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3750 gLMSRespawnTime
:= gTime
+ 5000;
3753 else if (gGameSettings
.GameMode
= GM_DM
) then
3757 if gPlayers
[k
] <> nil then
3760 // survivor is the winner
3761 g_Game_Message(Format(_lc
[I_MESSAGE_LMS_WIN
], [AnsiUpperCase(FName
)]), 144);
3763 MH_SEND_GameEvent(NET_EV_LMS_WIN
, 0, FName
);
3766 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3767 gLMSRespawnTime
:= gTime
+ 5000;
3769 else if (a
= 0) then
3771 // everyone is dead, restart the map
3772 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
3774 MH_SEND_GameEvent(NET_EV_LMS_DRAW
, 0, FName
);
3775 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3776 gLMSRespawnTime
:= gTime
+ 5000;
3779 if srv
and (OldLR
= LMS_RESPAWN_NONE
) and (gLMSRespawn
> LMS_RESPAWN_NONE
) then
3781 if NetMode
= NET_SERVER
then
3782 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
)
3784 g_Console_Add(Format(_lc
[I_MSG_WARMUP_START
], [(gLMSRespawnTime
- gTime
) div 1000]), True);
3790 MH_SEND_PlayerStats(FUID
);
3791 MH_SEND_PlayerDeath(FUID
, KillType
, t
, SpawnerUID
);
3792 if gGameSettings
.GameMode
= GM_TDM
then MH_SEND_GameStats
;
3795 if srv
and FNoRespawn
then Spectate(True);
3796 FWantsInGame
:= True;
3799 function TPlayer
.BodyInLiquid(XInc
, YInc
: Integer): Boolean;
3801 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
, PLAYER_RECT
.Width
,
3802 PLAYER_RECT
.Height
-20, PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, False);
3805 function TPlayer
.BodyInAcid(XInc
, YInc
: Integer): Boolean;
3807 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
, PLAYER_RECT
.Width
,
3808 PLAYER_RECT
.Height
-20, PANEL_ACID1
or PANEL_ACID2
, False);
3811 procedure TPlayer
.MakeBloodSimple(Count
: Word);
3813 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)+8,
3814 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3815 Count
div 2, 3, -1, 16, (PLAYER_RECT
.Height
*2 div 3),
3816 FModel
.Blood
.R
, FModel
.Blood
.G
, FModel
.Blood
.B
, FModel
.Blood
.Kind
);
3817 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-8,
3818 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3819 Count
div 2, -3, -1, 16, (PLAYER_RECT
.Height
*2) div 3,
3820 FModel
.Blood
.R
, FModel
.Blood
.G
, FModel
.Blood
.B
, FModel
.Blood
.Kind
);
3823 procedure TPlayer
.MakeBloodVector(Count
: Word; VelX
, VelY
: Integer);
3825 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
3826 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3827 Count
, VelX
, VelY
, 16, (PLAYER_RECT
.Height
*2) div 3,
3828 FModel
.Blood
.R
, FModel
.Blood
.G
, FModel
.Blood
.B
, FModel
.Blood
.Kind
);
3831 procedure TPlayer
.ProcessWeaponAction(Action
: Byte);
3833 if g_Game_IsClient
then Exit
;
3835 WP_PREV
: PrevWeapon();
3836 WP_NEXT
: NextWeapon();
3840 procedure TPlayer
.QueueWeaponSwitch(Weapon
: Byte);
3842 if g_Game_IsClient
then Exit
;
3843 if Weapon
> High(FWeapon
) then Exit
;
3844 FNextWeap
:= FNextWeap
or (1 shl Weapon
);
3847 procedure TPlayer
.resetWeaponQueue ();
3850 FNextWeapDelay
:= 0;
3854 procedure TPlayer
.Assist();
3858 DoAssists
:= (gGameSettings
.GameMode
= GM_TDM
) or (gGameSettings
.GameMode
= GM_CTF
);
3860 if (DoAssists
or (gGameSettings
.GameMode
= GM_TDM
)) then
3870 function TPlayer
.hasAmmoForWeapon (weapon
: Byte): Boolean;
3874 WEAPON_KASTET
, WEAPON_SAW
: result
:= true;
3875 WEAPON_SHOTGUN1
, WEAPON_SHOTGUN2
, WEAPON_SUPERPULEMET
: result
:= (FAmmo
[A_SHELLS
] > 0);
3876 WEAPON_PISTOL
, WEAPON_CHAINGUN
: result
:= (FAmmo
[A_BULLETS
] > 0);
3877 WEAPON_ROCKETLAUNCHER
: result
:= (FAmmo
[A_ROCKETS
] > 0);
3878 WEAPON_PLASMA
, WEAPON_BFG
: result
:= (FAmmo
[A_CELLS
] > 0);
3879 WEAPON_FLAMETHROWER
: result
:= (FAmmo
[A_FUEL
] > 0);
3880 else result
:= (weapon
< length(FWeapon
));
3884 function TPlayer
.hasAmmoForShooting (weapon
: Byte): Boolean;
3888 WEAPON_KASTET
, WEAPON_SAW
: result
:= true;
3889 WEAPON_SHOTGUN1
, WEAPON_SUPERPULEMET
: result
:= (FAmmo
[A_SHELLS
] > 0);
3890 WEAPON_SHOTGUN2
: result
:= (FAmmo
[A_SHELLS
] > 1);
3891 WEAPON_PISTOL
, WEAPON_CHAINGUN
: result
:= (FAmmo
[A_BULLETS
] > 0);
3892 WEAPON_ROCKETLAUNCHER
: result
:= (FAmmo
[A_ROCKETS
] > 0);
3893 WEAPON_PLASMA
: result
:= (FAmmo
[A_CELLS
] > 0);
3894 WEAPON_BFG
: result
:= (FAmmo
[A_CELLS
] >= 40);
3895 WEAPON_FLAMETHROWER
: result
:= (FAmmo
[A_FUEL
] > 0);
3896 else result
:= (weapon
< length(FWeapon
));
3900 function TPlayer
.shouldSwitch (weapon
: Byte; hadWeapon
: Boolean): Boolean;
3903 if (weapon
> WP_LAST
+ 1) then
3908 if (FWeapSwitchMode
= 1) and not hadWeapon
then
3910 else if (FWeapSwitchMode
= 2) then
3911 result
:= (FWeapPreferences
[weapon
] > FWeapPreferences
[FCurrWeap
]);
3914 // return 255 for "no switch"
3915 function TPlayer
.getNextWeaponIndex (): Byte;
3918 wantThisWeapon
: array[0..64] of Boolean;
3919 wwc
: Integer = 0; //HACK!
3922 result
:= 255; // default result: "no switch"
3923 //e_LogWriteFln('FSWITCHTOEMPTY: %s', [FSwitchToEmpty], TMsgType.Notify);
3924 // had weapon cycling on previous frame? remove that flag
3925 if (FNextWeap
and $2000) <> 0 then
3927 FNextWeap
:= FNextWeap
and $1FFF;
3928 FNextWeapDelay
:= 0;
3930 // cycling has priority
3931 if (FNextWeap
and $C000) <> 0 then
3933 if (FNextWeap
and $8000) <> 0 then
3937 FNextWeap
:= FNextWeap
or $2000; // we need this
3938 if FNextWeapDelay
> 0 then
3939 exit
; // cooldown time
3941 for i
:= 0 to High(FWeapon
) do
3943 cwi
:= (cwi
+length(FWeapon
)+dir
) mod length(FWeapon
);
3944 if FWeapon
[cwi
] and maySwitch(cwi
) then
3946 //e_LogWriteFln(' SWITCH: cur=%d; new=%d %s %s', [FCurrWeap, cwi, FSwitchToEmpty, hasAmmoForWeapon(cwi)], TMsgType.Notify);
3947 result
:= Byte(cwi
);
3948 FNextWeapDelay
:= WEAPON_DELAY
;
3956 for i
:= 0 to High(wantThisWeapon
) do
3957 wantThisWeapon
[i
] := false;
3958 for i
:= 0 to High(FWeapon
) do
3959 if (FNextWeap
and (1 shl i
)) <> 0 then
3961 wantThisWeapon
[i
] := true;
3965 // exclude currently selected weapon from the set
3966 wantThisWeapon
[FCurrWeap
] := false;
3967 // slow down alterations a little
3970 //e_WriteLog(Format(' FNextWeap=%x; delay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
3971 // more than one weapon requested, assume "alteration" and check alteration delay
3972 if FNextWeapDelay
> 0 then
3978 // do not reset weapon queue, it will be done in `RealizeCurrentWeapon()`
3979 // but clear all counters if no weapon should be switched
3985 //e_WriteLog(Format('wwc=%d', [wwc]), MSG_WARNING);
3986 // try weapons in descending order
3987 for i
:= High(FWeapon
) downto 0 do
3989 if wantThisWeapon
[i
] and FWeapon
[i
] and ((wwc
= 1) or hasAmmoForWeapon(i
)) then
3994 FNextWeapDelay
:= WEAPON_DELAY
* 2; // anyway, 'cause why not
3995 //e_LogWriteFln('FOUND %s %s %s', [result, FSwitchToEmpty, hasAmmoForWeapon(i)], TMsgType.Notify);
3999 // no suitable weapon found, so reset the queue, to avoid accidental "queuing" of weapon w/o ammo
4003 procedure TPlayer
.RealizeCurrentWeapon();
4004 function switchAllowed (): Boolean;
4009 if FBFGFireCounter
<> -1 then
4011 if FTime
[T_SWITCH
] > gTime
then
4013 for i
:= WP_FIRST
to WP_LAST
do
4014 if FReloading
[i
] > 0 then
4022 //e_WriteLog(Format('***RealizeCurrentWeapon: FNextWeap=%x; FNextWeapDelay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
4023 //FNextWeap := FNextWeap and $1FFF;
4024 if FNextWeapDelay
> 0 then Dec(FNextWeapDelay
); // "alteration delay"
4026 if not switchAllowed
then
4028 //HACK for weapon cycling
4029 if (FNextWeap
and $E000) <> 0 then FNextWeap
:= 0;
4033 nw
:= getNextWeaponIndex();
4035 if nw
= 255 then exit
; // don't reset anything here
4036 if nw
> High(FWeapon
) then
4038 // don't forget to reset queue here!
4039 //e_WriteLog(' RealizeCurrentWeapon: WUTAFUUUU', MSG_WARNING);
4047 FTime
[T_SWITCH
] := gTime
+156;
4048 if FCurrWeap
= WEAPON_SAW
then FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
4049 FModel
.SetWeapon(FCurrWeap
);
4050 if g_Game_IsNet
then MH_SEND_PlayerStats(FUID
);
4054 procedure TPlayer
.NextWeapon();
4056 if g_Game_IsClient
then Exit
;
4060 procedure TPlayer
.PrevWeapon();
4062 if g_Game_IsClient
then Exit
;
4066 procedure TPlayer
.SetWeapon(W
: Byte);
4068 if FCurrWeap
<> W
then
4069 if W
= WEAPON_SAW
then
4070 FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
4073 FModel
.SetWeapon(CurrWeap
);
4077 function TPlayer
.PickItem(ItemType
: Byte; arespawn
: Boolean; var remove
: Boolean): Boolean;
4080 switchWeapon
: Byte = 255;
4081 hadWeapon
: Boolean = False;
4084 if g_Game_IsClient
then Exit
;
4086 // a = true - ìåñòî ñïàâíà ïðåäìåòà:
4087 a
:= LongBool(gGameSettings
.Options
and GAME_OPTION_WEAPONSTAY
) and arespawn
;
4091 if (FHealth
< PLAYER_HP_SOFT
) or (FFireTime
> 0) then
4093 if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
4097 if gFlash
= 2 then Inc(FPickup
, 5);
4101 if (FHealth
< PLAYER_HP_SOFT
) or (FFireTime
> 0) then
4103 if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
4107 if gFlash
= 2 then Inc(FPickup
, 5);
4111 if FArmor
< PLAYER_AP_SOFT
then
4113 FArmor
:= PLAYER_AP_SOFT
;
4116 if gFlash
= 2 then Inc(FPickup
, 5);
4120 if FArmor
< PLAYER_AP_LIMIT
then
4122 FArmor
:= PLAYER_AP_LIMIT
;
4125 if gFlash
= 2 then Inc(FPickup
, 5);
4129 if (FHealth
< PLAYER_HP_LIMIT
) or (FFireTime
> 0) then
4131 if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
4135 if gFlash
= 2 then Inc(FPickup
, 5);
4139 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) or (FFireTime
> 0) then
4141 if FHealth
< PLAYER_HP_LIMIT
then
4142 FHealth
:= PLAYER_HP_LIMIT
;
4143 if FArmor
< PLAYER_AP_LIMIT
then
4144 FArmor
:= PLAYER_AP_LIMIT
;
4148 if gFlash
= 2 then Inc(FPickup
, 5);
4152 if (not FWeapon
[WEAPON_SAW
]) or ((not arespawn
) and (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
])) then
4154 hadWeapon
:= FWeapon
[WEAPON_SAW
];
4155 switchWeapon
:= WEAPON_SAW
;
4156 FWeapon
[WEAPON_SAW
] := True;
4158 if gFlash
= 2 then Inc(FPickup
, 5);
4159 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4162 ITEM_WEAPON_SHOTGUN1
:
4163 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN1
] then
4165 // Íóæíî, ÷òîáû íå âçÿòü âñå ïóëè ñðàçó:
4166 if a
and FWeapon
[WEAPON_SHOTGUN1
] then Exit
;
4167 hadWeapon
:= FWeapon
[WEAPON_SHOTGUN1
];
4168 switchWeapon
:= WEAPON_SHOTGUN1
;
4169 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4170 FWeapon
[WEAPON_SHOTGUN1
] := True;
4172 if gFlash
= 2 then Inc(FPickup
, 5);
4173 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4176 ITEM_WEAPON_SHOTGUN2
:
4177 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN2
] then
4179 if a
and FWeapon
[WEAPON_SHOTGUN2
] then Exit
;
4180 hadWeapon
:= FWeapon
[WEAPON_SHOTGUN2
];
4181 switchWeapon
:= WEAPON_SHOTGUN2
;
4182 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4183 FWeapon
[WEAPON_SHOTGUN2
] := True;
4185 if gFlash
= 2 then Inc(FPickup
, 5);
4186 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4189 ITEM_WEAPON_CHAINGUN
:
4190 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or not FWeapon
[WEAPON_CHAINGUN
] then
4192 if a
and FWeapon
[WEAPON_CHAINGUN
] then Exit
;
4193 hadWeapon
:= FWeapon
[WEAPON_CHAINGUN
];
4194 switchWeapon
:= WEAPON_CHAINGUN
;
4195 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
4196 FWeapon
[WEAPON_CHAINGUN
] := True;
4198 if gFlash
= 2 then Inc(FPickup
, 5);
4199 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4202 ITEM_WEAPON_ROCKETLAUNCHER
:
4203 if (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or not FWeapon
[WEAPON_ROCKETLAUNCHER
] then
4205 if a
and FWeapon
[WEAPON_ROCKETLAUNCHER
] then Exit
;
4206 switchWeapon
:= WEAPON_ROCKETLAUNCHER
;
4207 hadWeapon
:= FWeapon
[WEAPON_ROCKETLAUNCHER
];
4208 IncMax(FAmmo
[A_ROCKETS
], 2, FMaxAmmo
[A_ROCKETS
]);
4209 FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
4211 if gFlash
= 2 then Inc(FPickup
, 5);
4212 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4216 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_PLASMA
] then
4218 if a
and FWeapon
[WEAPON_PLASMA
] then Exit
;
4219 switchWeapon
:= WEAPON_PLASMA
;
4220 hadWeapon
:= FWeapon
[WEAPON_PLASMA
];
4221 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
4222 FWeapon
[WEAPON_PLASMA
] := True;
4224 if gFlash
= 2 then Inc(FPickup
, 5);
4225 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4229 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_BFG
] then
4231 if a
and FWeapon
[WEAPON_BFG
] then Exit
;
4232 switchWeapon
:= WEAPON_BFG
;
4233 hadWeapon
:= FWeapon
[WEAPON_BFG
];
4234 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
4235 FWeapon
[WEAPON_BFG
] := True;
4237 if gFlash
= 2 then Inc(FPickup
, 5);
4238 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4241 ITEM_WEAPON_SUPERPULEMET
:
4242 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SUPERPULEMET
] then
4244 if a
and FWeapon
[WEAPON_SUPERPULEMET
] then Exit
;
4245 switchWeapon
:= WEAPON_SUPERPULEMET
;
4246 hadWeapon
:= FWeapon
[WEAPON_SUPERPULEMET
];
4247 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4248 FWeapon
[WEAPON_SUPERPULEMET
] := True;
4250 if gFlash
= 2 then Inc(FPickup
, 5);
4251 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4254 ITEM_WEAPON_FLAMETHROWER
:
4255 if (FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
]) or not FWeapon
[WEAPON_FLAMETHROWER
] then
4257 if a
and FWeapon
[WEAPON_FLAMETHROWER
] then Exit
;
4258 switchWeapon
:= WEAPON_FLAMETHROWER
;
4259 hadWeapon
:= FWeapon
[WEAPON_FLAMETHROWER
];
4260 IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
4261 FWeapon
[WEAPON_FLAMETHROWER
] := True;
4263 if gFlash
= 2 then Inc(FPickup
, 5);
4264 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4268 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
4270 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
4273 if gFlash
= 2 then Inc(FPickup
, 5);
4276 ITEM_AMMO_BULLETS_BOX
:
4277 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
4279 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
4282 if gFlash
= 2 then Inc(FPickup
, 5);
4286 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
4288 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4291 if gFlash
= 2 then Inc(FPickup
, 5);
4294 ITEM_AMMO_SHELLS_BOX
:
4295 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
4297 IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
4300 if gFlash
= 2 then Inc(FPickup
, 5);
4304 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
4306 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
4309 if gFlash
= 2 then Inc(FPickup
, 5);
4312 ITEM_AMMO_ROCKET_BOX
:
4313 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
4315 IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
4318 if gFlash
= 2 then Inc(FPickup
, 5);
4322 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
4324 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
4327 if gFlash
= 2 then Inc(FPickup
, 5);
4331 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
4333 IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
4336 if gFlash
= 2 then Inc(FPickup
, 5);
4340 if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then
4342 IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
4345 if gFlash
= 2 then Inc(FPickup
, 5);
4349 if not(R_ITEM_BACKPACK
in FRulez
) or
4350 (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
4351 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
4352 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
4353 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or
4354 (FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
]) then
4356 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[1, A_BULLETS
];
4357 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[1, A_SHELLS
];
4358 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[1, A_ROCKETS
];
4359 FMaxAmmo
[A_CELLS
] := AmmoLimits
[1, A_CELLS
];
4360 FMaxAmmo
[A_FUEL
] := AmmoLimits
[1, A_FUEL
];
4362 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
4363 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
4364 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
4365 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4366 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
4367 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
4368 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
4369 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
4370 if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then
4371 IncMax(FAmmo
[A_FUEL
], 50, FMaxAmmo
[A_FUEL
]);
4373 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
4376 if gFlash
= 2 then Inc(FPickup
, 5);
4380 if not(R_KEY_RED
in FRulez
) then
4382 Include(FRulez
, R_KEY_RED
);
4384 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
4385 if gFlash
= 2 then Inc(FPickup
, 5);
4386 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
4390 if not(R_KEY_GREEN
in FRulez
) then
4392 Include(FRulez
, R_KEY_GREEN
);
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_BLUE
in FRulez
) then
4402 Include(FRulez
, R_KEY_BLUE
);
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 FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
4412 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
4416 if gFlash
= 2 then Inc(FPickup
, 5);
4420 if FAir
< AIR_MAX
then
4425 if gFlash
= 2 then Inc(FPickup
, 5);
4430 if not (R_BERSERK
in FRulez
) then
4432 Include(FRulez
, R_BERSERK
);
4433 if (FBFGFireCounter
= -1) then
4435 FCurrWeap
:= WEAPON_KASTET
;
4437 FModel
.SetWeapon(WEAPON_KASTET
);
4442 if gFlash
= 2 then Inc(FPickup
, 5);
4444 FBerserk
:= gTime
+30000;
4449 if (FHealth
< PLAYER_HP_SOFT
) or (FFireTime
> 0) then
4451 if FHealth
< PLAYER_HP_SOFT
then FHealth
:= PLAYER_HP_SOFT
;
4452 FBerserk
:= gTime
+30000;
4460 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
4462 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
4466 if gFlash
= 2 then Inc(FPickup
, 5);
4470 if (FHealth
< PLAYER_HP_LIMIT
) or (FFireTime
> 0) then
4472 if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
4476 if gFlash
= 2 then Inc(FPickup
, 5);
4480 if FArmor
< PLAYER_AP_LIMIT
then
4482 IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
4485 if gFlash
= 2 then Inc(FPickup
, 5);
4489 if FJetFuel
< JET_MAX
then
4491 FJetFuel
:= JET_MAX
;
4494 if gFlash
= 2 then Inc(FPickup
, 5);
4498 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
4500 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
4503 if gFlash
= 2 then Inc(FPickup
, 5);
4507 if (shouldSwitch(switchWeapon
, hadWeapon
)) then
4508 QueueWeaponSwitch(switchWeapon
);
4511 procedure TPlayer
.Touch();
4515 //FModel.PlaySound(MODELSOUND_PAIN, 1, FObj.X, FObj.Y);
4518 // Áðîñèòü ôëàã òîâàðèùó:
4519 if gGameSettings
.GameMode
= GM_CTF
then
4524 procedure TPlayer
.Push(vx
, vy
: Integer);
4526 if (not FPhysics
) and FGhost
then
4528 FObj
.Accel
.X
:= FObj
.Accel
.X
+ vx
;
4529 FObj
.Accel
.Y
:= FObj
.Accel
.Y
+ vy
;
4530 if g_Game_IsNet
and g_Game_IsServer
then
4531 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
4534 procedure TPlayer
.Reset(Force
: Boolean);
4540 FTime
[T_RESPAWN
] := 0;
4541 FTime
[T_FLAGCAP
] := 0;
4558 FSpectator
:= False;
4561 FSpectatePlayer
:= -1;
4562 FNoRespawn
:= False;
4564 FLives
:= gGameSettings
.MaxLives
;
4569 procedure TPlayer
.SoftReset();
4577 FBFGFireCounter
:= -1;
4585 SetAction(A_STAND
, True);
4588 function TPlayer
.GetRespawnPoint(): Byte;
4593 // Íà áóäóùåå: FSpawn - èãðîê óæå èãðàë è ïåðåðîæäàåòñÿ
4595 // Îäèíî÷íàÿ èãðà/êîîïåðàòèâ
4596 if gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
] then
4598 if Self
= gPlayer1
then
4600 // player 1 should try to spawn on the player 1 point
4601 if g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) > 0 then
4602 Exit(RESPAWNPOINT_PLAYER1
)
4603 else if g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) > 0 then
4604 Exit(RESPAWNPOINT_PLAYER2
);
4606 else if Self
= gPlayer2
then
4608 // player 2 should try to spawn on the player 2 point
4609 if g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) > 0 then
4610 Exit(RESPAWNPOINT_PLAYER2
)
4611 else if g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) > 0 then
4612 Exit(RESPAWNPOINT_PLAYER1
);
4616 // other players randomly pick either the first or the second point
4617 c
:= IfThen((Random(2) = 0), RESPAWNPOINT_PLAYER1
, RESPAWNPOINT_PLAYER2
);
4618 if g_Map_GetPointCount(c
) > 0 then
4620 // try the other one
4621 c
:= IfThen((c
= RESPAWNPOINT_PLAYER1
), RESPAWNPOINT_PLAYER2
, RESPAWNPOINT_PLAYER1
);
4622 if g_Map_GetPointCount(c
) > 0 then
4628 if gGameSettings
.GameMode
= GM_DM
then
4630 // try DM points first
4631 if g_Map_GetPointCount(RESPAWNPOINT_DM
) > 0 then
4632 Exit(RESPAWNPOINT_DM
);
4636 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
4638 // try team points first
4639 c
:= RESPAWNPOINT_DM
;
4640 if FTeam
= TEAM_RED
then
4641 c
:= RESPAWNPOINT_RED
4642 else if FTeam
= TEAM_BLUE
then
4643 c
:= RESPAWNPOINT_BLUE
;
4644 if g_Map_GetPointCount(c
) > 0 then
4648 // still haven't found a spawnpoint, try random shit
4649 Result
:= g_Map_GetRandomPointType();
4652 procedure TPlayer
.Respawn(Silent
: Boolean; Force
: Boolean = False);
4654 RespawnPoint
: TRespawnPoint
;
4662 FBFGFireCounter
:= -1;
4669 if not g_Game_IsServer
then
4673 FWantsInGame
:= True;
4674 FJustTeleported
:= True;
4677 FTime
[T_RESPAWN
] := 0;
4681 // if server changes MaxLives we gotta be ready
4682 if gGameSettings
.MaxLives
= 0 then FNoRespawn
:= False;
4684 // Åùå íåëüçÿ âîçðîäèòüñÿ:
4685 if FTime
[T_RESPAWN
] > gTime
then
4688 // Ïðîñðàë âñå æèçíè:
4691 if not FSpectator
then Spectate(True);
4692 FWantsInGame
:= True;
4696 if (gGameSettings
.GameType
<> GT_SINGLE
) and (gGameSettings
.GameMode
<> GM_COOP
) then
4697 begin // "Ñâîÿ èãðà"
4698 // Áåðñåðê íå ñîõðàíÿåòñÿ ìåæäó óðîâíÿìè:
4699 FRulez
:= FRulez
-[R_BERSERK
];
4701 else // "Îäèíî÷íàÿ èãðà"/"Êîîï"
4703 // Áåðñåðê è êëþ÷è íå ñîõðàíÿþòñÿ ìåæäó óðîâíÿìè:
4704 FRulez
:= FRulez
-[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
, R_BERSERK
];
4707 // Ïîëó÷àåì òî÷êó ñïàóíà èãðîêà:
4708 c
:= GetRespawnPoint();
4713 // Âîñêðåøåíèå áåç îðóæèÿ:
4716 FHealth
:= Round(PLAYER_HP_SOFT
* (FHandicap
/ 100));
4722 for a
:= WP_FIRST
to WP_LAST
do
4724 FWeapon
[a
] := False;
4728 FWeapon
[WEAPON_PISTOL
] := True;
4729 FWeapon
[WEAPON_KASTET
] := True;
4730 FCurrWeap
:= WEAPON_PISTOL
;
4733 FModel
.SetWeapon(FCurrWeap
);
4735 for b
:= A_BULLETS
to A_HIGH
do
4738 FAmmo
[A_BULLETS
] := 50;
4740 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[0, A_BULLETS
];
4741 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[0, A_SHELLS
];
4742 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[0, A_SHELLS
];
4743 FMaxAmmo
[A_CELLS
] := AmmoLimits
[0, A_CELLS
];
4744 FMaxAmmo
[A_FUEL
] := AmmoLimits
[0, A_FUEL
];
4746 if (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
]) and
4747 LongBool(gGameSettings
.Options
and GAME_OPTION_DMKEYS
) then
4748 FRulez
:= [R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
]
4753 // Ïîëó÷àåì êîîðäèíàòû òî÷êè âîçðîæäåíèÿ:
4754 if not g_Map_GetPoint(c
, RespawnPoint
) then
4756 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
4760 // Óñòàíîâêà êîîðäèíàò è ñáðîñ âñåõ ïàðàìåòðîâ:
4761 FObj
.X
:= RespawnPoint
.X
-PLAYER_RECT
.X
;
4762 FObj
.Y
:= RespawnPoint
.Y
-PLAYER_RECT
.Y
;
4763 FObj
.oldX
:= FObj
.X
; // don't interpolate after respawn
4764 FObj
.oldY
:= FObj
.Y
;
4770 FDirection
:= RespawnPoint
.Direction
;
4771 if FDirection
= TDirection
.D_LEFT
then
4776 SetAction(A_STAND
, True);
4777 FModel
.Direction
:= FDirection
;
4779 for a
:= Low(FTime
) to High(FTime
) do
4782 for a
:= Low(FMegaRulez
) to High(FMegaRulez
) do
4785 // Respawn invulnerability
4786 if (gGameSettings
.GameType
<> GT_SINGLE
) and (gGameSettings
.SpawnInvul
> 0) then
4788 FMegaRulez
[MR_INVUL
] := gTime
+ gGameSettings
.SpawnInvul
* 1000;
4789 FSpawnInvul
:= FMegaRulez
[MR_INVUL
];
4794 FCanJetpack
:= False;
4800 // Àíèìàöèÿ âîçðîæäåíèÿ:
4801 if (not gLoadGameMode
) and (not Silent
) then
4802 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
4804 Anim
:= TAnimation
.Create(ID
, False, 3);
4805 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4806 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4810 FSpectator
:= False;
4813 FSpectatePlayer
:= -1;
4816 if (gPlayer1
= nil) and (gSpectLatchPID1
= FUID
) then
4818 if (gPlayer2
= nil) and (gSpectLatchPID2
= FUID
) then
4821 if g_Game_IsNet
then
4823 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
4824 MH_SEND_PlayerStats(FUID
, NET_EVERYONE
);
4826 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4827 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32,
4832 procedure TPlayer
.Spectate(NoMove
: Boolean = False);
4835 Kill(K_EXTRAHARDKILL
, FUID
, HIT_SOME
)
4836 else if (not NoMove
) then
4838 GameX
:= gMapInfo
.Width
div 2;
4839 GameY
:= gMapInfo
.Height
div 2;
4848 FWantsInGame
:= False;
4854 if Self
= gPlayer1
then
4856 gSpectLatchPID1
:= FUID
;
4859 else if Self
= gPlayer2
then
4861 gSpectLatchPID2
:= FUID
;
4866 if g_Game_IsNet
then
4867 MH_SEND_PlayerStats(FUID
);
4870 procedure TPlayer
.SwitchNoClip
;
4874 FGhost
:= not FGhost
;
4875 FPhysics
:= not FGhost
;
4887 procedure TPlayer
.Run(Direction
: TDirection
);
4891 if MAX_RUNVEL
> 8 then
4895 if Direction
= TDirection
.D_LEFT
then
4897 if FObj
.Vel
.X
> -MAX_RUNVEL
then
4898 FObj
.Vel
.X
:= FObj
.Vel
.X
- (MAX_RUNVEL
shr 3);
4901 if FObj
.Vel
.X
< MAX_RUNVEL
then
4902 FObj
.Vel
.X
:= FObj
.Vel
.X
+ (MAX_RUNVEL
shr 3);
4904 // Âîçìîæíî, ïèíàåì êóñêè:
4905 if (FObj
.Vel
.X
<> 0) and (gGibs
<> nil) then
4907 b
:= Abs(FObj
.Vel
.X
);
4908 if b
> 1 then b
:= b
* (Random(8 div b
) + 1);
4909 for a
:= 0 to High(gGibs
) do
4911 if gGibs
[a
].alive
and
4912 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
+FObj
.Rect
.Height
-4,
4913 FObj
.Rect
.Width
, 8, @gGibs
[a
].Obj
) and (Random(3) = 0) then
4916 if FObj
.Vel
.X
< 0 then
4918 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)+120) // íàëåâî
4922 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)); // íàïðàâî
4924 gGibs
[a
].positionChanged(); // this updates spatial accelerators
4932 procedure TPlayer
.SeeDown();
4934 SetAction(A_SEEDOWN
);
4936 if FDirection
= TDirection
.D_LEFT
then FAngle
:= ANGLE_LEFTDOWN
else FAngle
:= ANGLE_RIGHTDOWN
;
4938 if FIncCam
> -120 then DecMin(FIncCam
, 5, -120);
4941 procedure TPlayer
.SeeUp();
4945 if FDirection
= TDirection
.D_LEFT
then FAngle
:= ANGLE_LEFTUP
else FAngle
:= ANGLE_RIGHTUP
;
4947 if FIncCam
< 120 then IncMax(FIncCam
, 5, 120);
4950 procedure TPlayer
.SetAction(Action
: Byte; Force
: Boolean = False);
4958 A_ATTACK
: Prior
:= 2;
4959 A_SEEUP
: Prior
:= 1;
4960 A_SEEDOWN
: Prior
:= 1;
4961 A_ATTACKUP
: Prior
:= 2;
4962 A_ATTACKDOWN
: Prior
:= 2;
4967 if (Prior
> FActionPrior
) or Force
then
4968 if not ((Prior
= 2) and (FCurrWeap
= WEAPON_SAW
)) then
4970 FActionPrior
:= Prior
;
4971 FActionAnim
:= Action
;
4972 FActionForce
:= Force
;
4973 FActionChanged
:= True;
4976 if Action
in [A_ATTACK
, A_ATTACKUP
, A_ATTACKDOWN
] then FModel
.SetFire(True);
4979 function TPlayer
.StayOnStep(XInc
, YInc
: Integer): Boolean;
4981 Result
:= not g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
-1,
4982 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False)
4983 and g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
,
4984 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False);
4987 function TPlayer
.TeleportTo(X
, Y
: Integer; silent
: Boolean; dir
: Byte): Boolean;
4994 if g_CollideLevel(X
, Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
) then
4996 g_Sound_PlayExAt('SOUND_GAME_NOTELEPORT', FObj
.X
, FObj
.Y
);
4997 if g_Game_IsServer
and g_Game_IsNet
then
4998 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_GAME_NOTELEPORT');
5002 FJustTeleported
:= True;
5007 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
5009 Anim
:= TAnimation
.Create(ID
, False, 3);
5012 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', FObj
.X
, FObj
.Y
);
5013 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
5014 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
5015 if g_Game_IsServer
and g_Game_IsNet
then
5016 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
5017 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 1,
5021 FObj
.X
:= X
-PLAYER_RECT
.X
;
5022 FObj
.Y
:= Y
-PLAYER_RECT
.Y
;
5023 FObj
.oldX
:= FObj
.X
; // don't interpolate after respawn
5024 FObj
.oldY
:= FObj
.Y
;
5025 if FAlive
and FGhost
then
5031 if not g_Game_IsNet
then
5035 SetDirection(TDirection
.D_LEFT
);
5041 SetDirection(TDirection
.D_RIGHT
);
5047 if FDirection
= TDirection
.D_RIGHT
then
5049 SetDirection(TDirection
.D_LEFT
);
5054 SetDirection(TDirection
.D_RIGHT
);
5060 if not silent
and (Anim
<> nil) then
5062 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
5063 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
5066 if g_Game_IsServer
and g_Game_IsNet
then
5067 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
5068 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 0,
5075 function nonz(a
: Single): Single;
5083 function TPlayer
.refreshCorpse(): Boolean;
5089 if FAlive
or FSpectator
then
5091 if (gCorpses
= nil) or (Length(gCorpses
) = 0) then
5093 for i
:= 0 to High(gCorpses
) do
5094 if gCorpses
[i
] <> nil then
5095 if gCorpses
[i
].FPlayerUID
= FUID
then
5103 function TPlayer
.getCameraObj(): TObj
;
5105 if (not FAlive
) and (not FSpectator
) and
5106 (FCorpse
>= 0) and (FCorpse
< Length(gCorpses
)) and
5107 (gCorpses
[FCorpse
] <> nil) and (gCorpses
[FCorpse
].FPlayerUID
= FUID
) then
5109 gCorpses
[FCorpse
].FObj
.slopeUpLeft
:= FObj
.slopeUpLeft
;
5110 Result
:= gCorpses
[FCorpse
].FObj
;
5118 procedure TPlayer
.PreUpdate();
5120 FSlopeOld
:= FObj
.slopeUpLeft
;
5121 FIncCamOld
:= FIncCam
;
5122 FObj
.oldX
:= FObj
.X
;
5123 FObj
.oldY
:= FObj
.Y
;
5126 procedure TPlayer
.Update();
5129 i
, ii
, wx
, wy
, xd
, yd
, k
: Integer;
5130 blockmon
, headwater
, dospawn
: Boolean;
5135 NetServer
:= g_Game_IsNet
and g_Game_IsServer
;
5136 AnyServer
:= g_Game_IsServer
;
5138 if g_Game_IsClient
and (NetInterpLevel
> 0) then
5139 DoLerp(NetInterpLevel
+ 1)
5145 if (FClientID
>= 0) and (NetClients
[FClientID
].Peer
<> nil) then
5147 FPing
:= NetClients
[FClientID
].Peer
^.lastRoundTripTime
;
5148 if NetClients
[FClientID
].Peer
^.packetsSent
> 0 then
5149 FLoss
:= Round(100*NetClients
[FClientID
].Peer
^.packetsLost
/NetClients
[FClientID
].Peer
^.packetsSent
)
5158 if FAlive
and (FPunchAnim
<> nil) then
5159 FPunchAnim
.Update();
5161 if FAlive
and (gFly
or FJetpack
) then
5164 if FDirection
= TDirection
.D_LEFT
then
5169 if FAlive
and (not FGhost
) then
5171 if FKeys
[KEY_UP
].Pressed
then
5173 if FKeys
[KEY_DOWN
].Pressed
then
5177 if (not (FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_DOWN
].Pressed
)) and
5180 i
:= g_basic
.Sign(FIncCam
);
5181 FIncCam
:= Abs(FIncCam
);
5182 DecMin(FIncCam
, 5, 0);
5183 FIncCam
:= FIncCam
*i
;
5186 if gTime
mod (GAME_TICK
*2) <> 0 then
5188 if (FObj
.Vel
.X
= 0) and FAlive
then
5190 if FKeys
[KEY_LEFT
].Pressed
then
5191 Run(TDirection
.D_LEFT
);
5192 if FKeys
[KEY_RIGHT
].Pressed
then
5193 Run(TDirection
.D_RIGHT
);
5198 g_Obj_Move(@FObj
, True, True, True);
5199 positionChanged(); // this updates spatial accelerators
5205 FActionChanged
:= False;
5209 // Let alive player do some actions
5210 if FKeys
[KEY_LEFT
].Pressed
then Run(TDirection
.D_LEFT
);
5211 if FKeys
[KEY_RIGHT
].Pressed
then Run(TDirection
.D_RIGHT
);
5212 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then Fire()
5218 if NetServer
then MH_SEND_PlayerStats(FUID
);
5221 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Use();
5222 if FKeys
[KEY_JUMP
].Pressed
then Jump()
5225 if AnyServer
and FJetpack
then
5229 if NetServer
then MH_SEND_PlayerStats(FUID
);
5231 FCanJetpack
:= True;
5238 for k
:= Low(FKeys
) to KEY_CHAT
-1 do
5240 if FKeys
[k
].Pressed
then
5248 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
5251 if (FTime
[T_RESPAWN
] <= gTime
) and
5252 gGameOn
and (not FAlive
) then
5254 if (g_Player_GetCount() > 1) then
5258 gExit
:= EXIT_RESTART
;
5263 // Dead spectator actions
5266 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Fire();
5267 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then
5271 if (FSpectatePlayer
>= High(gPlayers
)) then
5272 FSpectatePlayer
:= -1
5276 for I
:= FSpectatePlayer
+ 1 to High(gPlayers
) do
5277 if gPlayers
[I
] <> nil then
5278 if gPlayers
[I
].alive
then
5279 if gPlayers
[I
].UID
<> FUID
then
5281 FSpectatePlayer
:= I
;
5286 if not SetSpect
then FSpectatePlayer
:= -1;
5297 if FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_JUMP
].Pressed
then
5299 FYTo
:= FObj
.Y
- 32;
5300 FSpectatePlayer
:= -1;
5302 if FKeys
[KEY_DOWN
].Pressed
then
5304 FYTo
:= FObj
.Y
+ 32;
5305 FSpectatePlayer
:= -1;
5307 if FKeys
[KEY_LEFT
].Pressed
then
5309 FXTo
:= FObj
.X
- 32;
5310 FSpectatePlayer
:= -1;
5312 if FKeys
[KEY_RIGHT
].Pressed
then
5314 FXTo
:= FObj
.X
+ 32;
5315 FSpectatePlayer
:= -1;
5318 if (FXTo
< -64) then
5320 else if (FXTo
> gMapInfo
.Width
+ 32) then
5321 FXTo
:= gMapInfo
.Width
+ 32;
5322 if (FYTo
< -72) then
5324 else if (FYTo
> gMapInfo
.Height
+ 32) then
5325 FYTo
:= gMapInfo
.Height
+ 32;
5330 g_Obj_Move(@FObj
, True, True, True);
5331 positionChanged(); // this updates spatial accelerators
5338 if (FSpectatePlayer
<= High(gPlayers
)) and (FSpectatePlayer
>= 0) then
5339 if gPlayers
[FSpectatePlayer
] <> nil then
5340 if gPlayers
[FSpectatePlayer
].alive
then
5342 FXTo
:= gPlayers
[FSpectatePlayer
].GameX
;
5343 FYTo
:= gPlayers
[FSpectatePlayer
].GameY
;
5347 blockmon
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
, FObj
.Y
+PLAYER_HEADRECT
.Y
,
5348 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
5349 PANEL_BLOCKMON
, True);
5350 headwater
:= HeadInLiquid(0, 0);
5352 // Ñîïðîòèâëåíèå âîçäóõà:
5353 if (not FAlive
) or not (FKeys
[KEY_LEFT
].Pressed
or FKeys
[KEY_RIGHT
].Pressed
) then
5354 if FObj
.Vel
.X
<> 0 then
5355 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
5357 if (FLastHit
= HIT_TRAP
) and (FPain
> 90) then FPain
:= 90;
5358 DecMin(FPain
, 5, 0);
5359 DecMin(FPickup
, 1, 0);
5361 if FAlive
and (FObj
.Y
> Integer(gMapInfo
.Height
)+128) and AnyServer
then
5363 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
5364 FMegaRulez
[MR_SUIT
] := 0;
5365 FMegaRulez
[MR_INVUL
] := 0;
5366 FMegaRulez
[MR_INVIS
] := 0;
5367 Kill(K_FALLKILL
, 0, HIT_FALL
);
5374 if FCurrWeap
= WEAPON_SAW
then
5375 if not (FSawSound
.IsPlaying() or FSawSoundHit
.IsPlaying() or
5376 FSawSoundSelect
.IsPlaying()) then
5377 FSawSoundIdle
.PlayAt(FObj
.X
, FObj
.Y
);
5380 if (not FJetSoundFly
.IsPlaying()) and (not FJetSoundOn
.IsPlaying()) and
5381 (not FJetSoundOff
.IsPlaying()) then
5383 FJetSoundFly
.SetPosition(0);
5384 FJetSoundFly
.PlayAt(FObj
.X
, FObj
.Y
);
5387 for b
:= WP_FIRST
to WP_LAST
do
5388 if FReloading
[b
] > 0 then
5394 if FShellTimer
> -1 then
5395 if FShellTimer
= 0 then
5397 if FShellType
= SHELL_SHELL
then
5398 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5399 GameVelX
, GameVelY
-2, SHELL_SHELL
)
5400 else if FShellType
= SHELL_DBLSHELL
then
5402 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5403 GameVelX
+1, GameVelY
-2, SHELL_SHELL
);
5404 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5405 GameVelX
-1, GameVelY
-2, SHELL_SHELL
);
5408 end else Dec(FShellTimer
);
5410 if (FBFGFireCounter
> -1) then
5411 if FBFGFireCounter
= 0 then
5415 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
5416 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
5417 xd
:= wx
+IfThen(FDirection
= TDirection
.D_LEFT
, -30, 30);
5418 yd
:= wy
+firediry();
5419 g_Weapon_bfgshot(wx
, wy
, xd
, yd
, FUID
);
5420 if NetServer
then MH_SEND_PlayerFire(FUID
, WEAPON_BFG
, wx
, wy
, xd
, yd
);
5421 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
5422 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
5423 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
5426 FReloading
[WEAPON_BFG
] := WEAPON_RELOAD
[WEAPON_BFG
];
5427 FBFGFireCounter
:= -1;
5430 FBFGFireCounter
:= 0
5432 Dec(FBFGFireCounter
);
5434 if (FMegaRulez
[MR_SUIT
] < gTime
) and AnyServer
then
5436 b
:= g_GetAcidHit(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
);
5438 if (b
> 0) and (gTime
mod (15*GAME_TICK
) = 0) then Damage(b
, 0, 0, 0, HIT_ACID
);
5441 if (headwater
or blockmon
) then
5447 if AnyServer
then Damage(10, 0, 0, 0, HIT_WATER
);
5450 else if (FAir
mod 31 = 0) and not blockmon
then
5451 g_Game_Effect_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
5452 FObj
.Y
+PLAYER_RECT
.Y
-4, 5+Random(6), 8, 4);
5453 end else if FAir
< AIR_DEF
then
5456 if FFireTime
> 0 then
5458 if BodyInLiquid(0, 0) then
5463 else if FMegaRulez
[MR_SUIT
] >= gTime
then
5465 if FMegaRulez
[MR_SUIT
] = gTime
then
5472 if FFirePainTime
<= 0 then
5474 if g_Game_IsServer
then
5475 Damage(2, FFireAttacker
, 0, 0, HIT_FLAME
);
5476 FFirePainTime
:= 12 - FFireTime
div 12;
5478 FFirePainTime
:= FFirePainTime
- 1;
5479 FFireTime
:= FFireTime
- 1;
5480 if ((FFireTime
mod 33) = 0) and (FMegaRulez
[MR_INVUL
] < gTime
) then
5481 FModel
.PlaySound(MODELSOUND_PAIN
, 1, FObj
.X
, FObj
.Y
);
5482 if (FFireTime
= 0) and g_Game_IsNet
and g_Game_IsServer
then
5483 MH_SEND_PlayerStats(FUID
);
5487 if FDamageBuffer
> 0 then
5489 if FDamageBuffer
>= 9 then
5493 if FDamageBuffer
< 30 then i
:= 9
5494 else if FDamageBuffer
< 100 then i
:= 18
5498 ii
:= Round(FDamageBuffer
*FHealth
/ nonz(FArmor
*(3/4)+FHealth
));
5499 FArmor
:= FArmor
-(FDamageBuffer
-ii
);
5500 FHealth
:= FHealth
-ii
;
5503 FHealth
:= FHealth
+FArmor
;
5508 if FHealth
<= 0 then
5509 if FHealth
> -30 then Kill(K_SIMPLEKILL
, FLastSpawnerUID
, FLastHit
)
5510 else if FHealth
> -50 then Kill(K_HARDKILL
, FLastSpawnerUID
, FLastHit
)
5511 else Kill(K_EXTRAHARDKILL
, FLastSpawnerUID
, FLastHit
);
5513 if FAlive
and ((FLastHit
<> HIT_FLAME
) or (FFireTime
<= 0)) then
5515 if FDamageBuffer
<= 20 then FModel
.PlaySound(MODELSOUND_PAIN
, 1, FObj
.X
, FObj
.Y
)
5516 else if FDamageBuffer
<= 55 then FModel
.PlaySound(MODELSOUND_PAIN
, 2, FObj
.X
, FObj
.Y
)
5517 else if FDamageBuffer
<= 120 then FModel
.PlaySound(MODELSOUND_PAIN
, 3, FObj
.X
, FObj
.Y
)
5518 else FModel
.PlaySound(MODELSOUND_PAIN
, 4, FObj
.X
, FObj
.Y
);
5525 end; // if FAlive then ...
5527 if (FActionAnim
= A_PAIN
) and (FModel
.Animation
<> A_PAIN
) then
5529 FModel
.ChangeAnimation(FActionAnim
, FActionForce
);
5530 FModel
.GetCurrentAnimation
.MinLength
:= i
;
5531 FModel
.GetCurrentAnimationMask
.MinLength
:= i
;
5532 end else FModel
.ChangeAnimation(FActionAnim
, FActionForce
and (FModel
.Animation
<> A_STAND
));
5534 if (FModel
.GetCurrentAnimation
.Played
or ((not FActionChanged
) and (FModel
.Animation
= A_WALK
)))
5535 then SetAction(A_STAND
, True);
5537 if not ((FModel
.Animation
= A_WALK
) and (Abs(FObj
.Vel
.X
) < 4) and not FModel
.Fire
) then FModel
.Update
;
5539 for b
:= Low(FKeys
) to High(FKeys
) do
5540 if FKeys
[b
].Time
= 0 then FKeys
[b
].Pressed
:= False else Dec(FKeys
[b
].Time
);
5544 procedure TPlayer
.getMapBox (out x
, y
, w
, h
: Integer); inline;
5546 x
:= FObj
.X
+PLAYER_RECT
.X
;
5547 y
:= FObj
.Y
+PLAYER_RECT
.Y
;
5548 w
:= PLAYER_RECT
.Width
;
5549 h
:= PLAYER_RECT
.Height
;
5553 procedure TPlayer
.moveBy (dx
, dy
: Integer); inline;
5555 if (dx
<> 0) or (dy
<> 0) then
5564 function TPlayer
.Collide(X
, Y
: Integer; Width
, Height
: Word): Boolean;
5566 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
5567 FObj
.Y
+PLAYER_RECT
.Y
,
5574 function TPlayer
.Collide(Panel
: TPanel
): Boolean;
5576 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
5577 FObj
.Y
+PLAYER_RECT
.Y
,
5581 Panel
.Width
, Panel
.Height
);
5584 function TPlayer
.Collide(X
, Y
: Integer): Boolean;
5586 X
:= X
-FObj
.X
-PLAYER_RECT
.X
;
5587 Y
:= Y
-FObj
.Y
-PLAYER_RECT
.Y
;
5588 Result
:= (x
>= 0) and (x
<= PLAYER_RECT
.Width
) and
5589 (y
>= 0) and (y
<= PLAYER_RECT
.Height
);
5592 function g_Player_ExistingName(Name
: string): Boolean;
5598 if gPlayers
= nil then Exit
;
5600 for a
:= 0 to High(gPlayers
) do
5601 if gPlayers
[a
] <> nil then
5602 if LowerCase(Name
) = LowerCase(gPlayers
[a
].FName
) then
5609 procedure TPlayer
.SetDirection(Direction
: TDirection
);
5613 d
:= FModel
.Direction
;
5615 FModel
.Direction
:= Direction
;
5616 if d
<> Direction
then FModel
.ChangeAnimation(FModel
.Animation
, True);
5618 FDirection
:= Direction
;
5621 function TPlayer
.GetKeys(): Byte;
5625 if R_KEY_RED
in FRulez
then Result
:= KEY_RED
;
5626 if R_KEY_GREEN
in FRulez
then Result
:= Result
or KEY_GREEN
;
5627 if R_KEY_BLUE
in FRulez
then Result
:= Result
or KEY_BLUE
;
5629 if FTeam
= TEAM_RED
then Result
:= Result
or KEY_REDTEAM
;
5630 if FTeam
= TEAM_BLUE
then Result
:= Result
or KEY_BLUETEAM
;
5633 procedure TPlayer
.Use();
5637 if FTime
[T_USE
] > gTime
then Exit
;
5639 g_Triggers_PressR(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
,
5640 PLAYER_RECT
.Height
, FUID
, ACTIVATE_PLAYERPRESS
);
5642 for a
:= 0 to High(gPlayers
) do
5643 if (gPlayers
[a
] <> nil) and (gPlayers
[a
] <> Self
) and
5644 gPlayers
[a
].alive
and SameTeam(FUID
, gPlayers
[a
].FUID
) and
5645 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
5646 FObj
.Rect
.Width
, FObj
.Rect
.Height
, @gPlayers
[a
].FObj
) then
5648 gPlayers
[a
].Touch();
5649 if g_Game_IsNet
and g_Game_IsServer
then
5650 MH_SEND_GameEvent(NET_EV_PLAYER_TOUCH
, gPlayers
[a
].FUID
);
5653 FTime
[T_USE
] := gTime
+120;
5656 procedure TPlayer
.NetFire(Wpn
: Byte; X
, Y
, AX
, AY
: Integer; WID
: Integer = -1);
5659 visible
: Boolean = True;
5660 WX
, WY
, XD
, YD
: Integer;
5672 if R_BERSERK
in FRulez
then
5674 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
5675 locobj
.X
:= FObj
.X
+FObj
.Rect
.X
;
5676 locobj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
5679 locobj
.rect
.Width
:= 39;
5680 locobj
.rect
.Height
:= 52;
5681 locobj
.Vel
.X
:= (xd
-wx
) div 2;
5682 locobj
.Vel
.Y
:= (yd
-wy
) div 2;
5683 locobj
.Accel
.X
:= xd
-wx
;
5684 locobj
.Accel
.y
:= yd
-wy
;
5686 if g_Weapon_Hit(@locobj
, 50, FUID
, HIT_SOME
) <> 0 then
5687 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
5689 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
5693 FPain
:= min(FPain
+ 25, 50);
5695 g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
5700 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
5701 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
5703 FSawSoundSelect
.Stop();
5705 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
5707 else if not FSawSoundHit
.IsPlaying() then
5709 FSawSoundSelect
.Stop();
5710 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
5716 g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', GameX
, Gamey
);
5717 FFireAngle
:= FAngle
;
5718 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5719 GameVelX
, GameVelY
-2, SHELL_BULLET
);
5724 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
5725 FFireAngle
:= FAngle
;
5727 FShellType
:= SHELL_SHELL
;
5732 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN2', Gamex
, Gamey
);
5733 FFireAngle
:= FAngle
;
5735 FShellType
:= SHELL_DBLSHELL
;
5740 g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', Gamex
, Gamey
);
5741 FFireAngle
:= FAngle
;
5742 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5743 GameVelX
, GameVelY
-2, SHELL_BULLET
);
5746 WEAPON_ROCKETLAUNCHER
:
5748 g_Weapon_Rocket(wx
, wy
, xd
, yd
, FUID
, WID
);
5749 FFireAngle
:= FAngle
;
5754 g_Weapon_Plasma(wx
, wy
, xd
, yd
, FUID
, WID
);
5755 FFireAngle
:= FAngle
;
5760 g_Weapon_BFGShot(wx
, wy
, xd
, yd
, FUID
, WID
);
5761 FFireAngle
:= FAngle
;
5764 WEAPON_SUPERPULEMET
:
5766 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
5767 FFireAngle
:= FAngle
;
5768 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5769 GameVelX
, GameVelY
-2, SHELL_SHELL
);
5772 WEAPON_FLAMETHROWER
:
5774 g_Weapon_flame(wx
, wy
, xd
, yd
, FUID
, WID
);
5776 FFireAngle
:= FAngle
;
5780 if not visible
then Exit
;
5782 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
5783 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
5784 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
5787 procedure TPlayer
.DoLerp(Level
: Integer = 2);
5789 if FObj
.X
<> FXTo
then FObj
.X
:= Lerp(FObj
.X
, FXTo
, Level
);
5790 if FObj
.Y
<> FYTo
then FObj
.Y
:= Lerp(FObj
.Y
, FYTo
, Level
);
5793 procedure TPlayer
.SetLerp(XTo
, YTo
: Integer);
5799 if FJustTeleported
or (NetInterpLevel
< 1) then
5803 if FJustTeleported
then
5805 FObj
.oldX
:= FObj
.X
;
5806 FObj
.oldY
:= FObj
.Y
;
5811 AX
:= Abs(FXTo
- FObj
.X
);
5812 AY
:= Abs(FYTo
- FObj
.Y
);
5813 if (AX
> 32) or (AX
<= NetInterpLevel
) then
5815 if (AY
> 32) or (AY
<= NetInterpLevel
) then
5820 function TPlayer
.FullInLift(XInc
, YInc
: Integer): Integer;
5822 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5823 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5824 PANEL_LIFTUP
, False) then Result
:= -1
5826 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5827 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5828 PANEL_LIFTDOWN
, False) then Result
:= 1
5832 function TPlayer
.GetFlag(Flag
: Byte): Boolean;
5839 if Flag
= FLAG_NONE
then
5842 if not g_Game_IsServer
then Exit
;
5844 // Ïðèíåñ ÷óæîé ôëàã íà ñâîþ áàçó:
5845 if (Flag
= FTeam
) and
5846 (gFlags
[Flag
].State
= FLAG_STATE_NORMAL
) and
5847 (FFlag
<> FLAG_NONE
) then
5849 if FFlag
= FLAG_RED
then
5850 s
:= _lc
[I_PLAYER_FLAG_RED
]
5852 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5854 evtype
:= FLAG_STATE_SCORED
;
5856 ts
:= Format('%.4d', [gFlags
[FFlag
].CaptureTime
]);
5857 Insert('.', ts
, Length(ts
) + 1 - 3);
5858 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_CAPTURE
], [FName
, s
, ts
]), True);
5860 g_Map_ResetFlag(FFlag
);
5861 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_CAPTURE
], [AnsiUpperCase(s
)]), 144);
5863 if ((Self
= gPlayer1
) or (Self
= gPlayer2
)
5864 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= FTeam
))
5865 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= FTeam
))) then
5870 if not sound_cap_flag
[a
].IsPlaying() then
5871 sound_cap_flag
[a
].Play();
5873 gTeamStat
[FTeam
].Score
+= 1;
5876 if g_Game_IsNet
then
5878 MH_SEND_FlagEvent(evtype
, FFlag
, FUID
, False);
5882 gFlags
[FFlag
].CaptureTime
:= 0;
5887 // Ïîäîáðàë ñâîé ôëàã - âåðíóë åãî íà áàçó:
5888 if (Flag
= FTeam
) and
5889 (gFlags
[Flag
].State
= FLAG_STATE_DROPPED
) then
5891 if Flag
= FLAG_RED
then
5892 s
:= _lc
[I_PLAYER_FLAG_RED
]
5894 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5896 evtype
:= FLAG_STATE_RETURNED
;
5897 gFlags
[Flag
].CaptureTime
:= 0;
5899 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_RETURN
], [FName
, s
]), True);
5901 g_Map_ResetFlag(Flag
);
5902 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
5904 if ((Self
= gPlayer1
) or (Self
= gPlayer2
)
5905 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= FTeam
))
5906 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= FTeam
))) then
5911 if not sound_ret_flag
[a
].IsPlaying() then
5912 sound_ret_flag
[a
].Play();
5915 if g_Game_IsNet
then
5917 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5923 // Ïîäîáðàë ÷óæîé ôëàã:
5924 if (Flag
<> FTeam
) and (FTime
[T_FLAGCAP
] <= gTime
) then
5928 if Flag
= FLAG_RED
then
5929 s
:= _lc
[I_PLAYER_FLAG_RED
]
5931 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5933 evtype
:= FLAG_STATE_CAPTURED
;
5935 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_GET
], [FName
, s
]), True);
5937 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_GET
], [AnsiUpperCase(s
)]), 144);
5939 gFlags
[Flag
].State
:= FLAG_STATE_CAPTURED
;
5941 if ((Self
= gPlayer1
) or (Self
= gPlayer2
)
5942 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= FTeam
))
5943 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= FTeam
))) then
5948 if not sound_get_flag
[a
].IsPlaying() then
5949 sound_get_flag
[a
].Play();
5952 if g_Game_IsNet
then
5954 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5960 procedure TPlayer
.SetFlag(Flag
: Byte);
5963 if FModel
<> nil then
5964 FModel
.SetFlag(FFlag
);
5967 function TPlayer
.TryDropFlag(): Boolean;
5969 if LongBool(gGameSettings
.Options
and GAME_OPTION_ALLOWDROPFLAG
) then
5970 Result
:= DropFlag(False, LongBool(gGameSettings
.Options
and GAME_OPTION_THROWFLAG
))
5975 function TPlayer
.DropFlag(Silent
: Boolean = True; DoThrow
: Boolean = False): Boolean;
5982 if (not g_Game_IsServer
) or (FFlag
= FLAG_NONE
) then
5984 FTime
[T_FLAGCAP
] := gTime
+ 2000;
5985 with gFlags
[FFlag
] do
5989 Direction
:= FDirection
;
5990 State
:= FLAG_STATE_DROPPED
;
5994 xv
:= FObj
.Vel
.X
+ IfThen(Direction
= TDirection
.D_RIGHT
, 10, -10);
5995 yv
:= FObj
.Vel
.Y
- 2;
5999 xv
:= (FObj
.Vel
.X
div 2);
6000 yv
:= (FObj
.Vel
.Y
div 2) - 2;
6002 g_Obj_Push(@Obj
, xv
, yv
);
6004 positionChanged(); // this updates spatial accelerators
6006 if FFlag
= FLAG_RED
then
6007 s
:= _lc
[I_PLAYER_FLAG_RED
]
6009 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
6011 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_DROP
], [FName
, s
]), True);
6012 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_DROP
], [AnsiUpperCase(s
)]), 144);
6014 if ((Self
= gPlayer1
) or (Self
= gPlayer2
)
6015 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= FTeam
))
6016 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= FTeam
))) then
6021 if (not Silent
) and (not sound_lost_flag
[a
].IsPlaying()) then
6022 sound_lost_flag
[a
].Play();
6024 if g_Game_IsNet
then
6025 MH_SEND_FlagEvent(FLAG_STATE_DROPPED
, Flag
, FUID
, False);
6031 procedure TPlayer
.GetSecret();
6033 if (self
= gPlayer1
) or (self
= gPlayer2
) then
6035 g_Console_Add(Format(_lc
[I_PLAYER_SECRET
], [FName
]), True);
6036 g_Sound_PlayEx('SOUND_GAME_SECRET');
6041 procedure TPlayer
.PressKey(Key
: Byte; Time
: Word = 1);
6043 Assert(Key
<= High(FKeys
));
6045 FKeys
[Key
].Pressed
:= True;
6046 FKeys
[Key
].Time
:= Time
;
6049 function TPlayer
.IsKeyPressed(K
: Byte): Boolean;
6051 Result
:= FKeys
[K
].Pressed
;
6054 procedure TPlayer
.ReleaseKeys();
6058 for a
:= Low(FKeys
) to High(FKeys
) do
6060 FKeys
[a
].Pressed
:= False;
6065 procedure TPlayer
.OnDamage(Angle
: SmallInt);
6069 function TPlayer
.firediry(): Integer;
6071 if FKeys
[KEY_UP
].Pressed
then Result
:= -42
6072 else if FKeys
[KEY_DOWN
].Pressed
then Result
:= 19
6076 procedure TPlayer
.RememberState();
6079 SavedState
: TPlayerSavedState
;
6081 SavedState
.Health
:= FHealth
;
6082 SavedState
.Armor
:= FArmor
;
6083 SavedState
.Air
:= FAir
;
6084 SavedState
.JetFuel
:= FJetFuel
;
6085 SavedState
.CurrWeap
:= FCurrWeap
;
6086 SavedState
.NextWeap
:= FNextWeap
;
6087 SavedState
.NextWeapDelay
:= FNextWeapDelay
;
6088 for i
:= Low(FWeapon
) to High(FWeapon
) do
6089 SavedState
.Weapon
[i
] := FWeapon
[i
];
6090 for i
:= Low(FAmmo
) to High(FAmmo
) do
6091 SavedState
.Ammo
[i
] := FAmmo
[i
];
6092 for i
:= Low(FMaxAmmo
) to High(FMaxAmmo
) do
6093 SavedState
.MaxAmmo
[i
] := FMaxAmmo
[i
];
6094 SavedState
.Rulez
:= FRulez
- [R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
];
6096 FSavedStateNum
:= -1;
6097 for i
:= Low(SavedStates
) to High(SavedStates
) do
6098 if not SavedStates
[i
].Used
then
6100 FSavedStateNum
:= i
;
6103 if FSavedStateNum
< 0 then
6105 SetLength(SavedStates
, Length(SavedStates
) + 1);
6106 FSavedStateNum
:= High(SavedStates
);
6109 SavedState
.Used
:= True;
6110 SavedStates
[FSavedStateNum
] := SavedState
;
6113 procedure TPlayer
.RecallState();
6116 SavedState
: TPlayerSavedState
;
6118 if(FSavedStateNum
< 0) or (FSavedStateNum
> High(SavedStates
)) then
6121 SavedState
:= SavedStates
[FSavedStateNum
];
6122 SavedStates
[FSavedStateNum
].Used
:= False;
6123 FSavedStateNum
:= -1;
6125 FHealth
:= SavedState
.Health
;
6126 FArmor
:= SavedState
.Armor
;
6127 FAir
:= SavedState
.Air
;
6128 FJetFuel
:= SavedState
.JetFuel
;
6129 FCurrWeap
:= SavedState
.CurrWeap
;
6130 FNextWeap
:= SavedState
.NextWeap
;
6131 FNextWeapDelay
:= SavedState
.NextWeapDelay
;
6132 for i
:= Low(FWeapon
) to High(FWeapon
) do
6133 FWeapon
[i
] := SavedState
.Weapon
[i
];
6134 for i
:= Low(FAmmo
) to High(FAmmo
) do
6135 FAmmo
[i
] := SavedState
.Ammo
[i
];
6136 for i
:= Low(FMaxAmmo
) to High(FMaxAmmo
) do
6137 FMaxAmmo
[i
] := SavedState
.MaxAmmo
[i
];
6138 FRulez
:= SavedState
.Rulez
;
6140 if gGameSettings
.GameType
= GT_SERVER
then
6141 MH_SEND_PlayerStats(FUID
);
6144 procedure TPlayer
.SaveState (st
: TStream
);
6150 utils
.writeSign(st
, 'PLYR');
6151 utils
.writeInt(st
, Byte(PLR_SAVE_VERSION
)); // version
6153 utils
.writeBool(st
, FIamBot
);
6155 utils
.writeInt(st
, Word(FUID
));
6157 utils
.writeStr(st
, FName
);
6159 utils
.writeInt(st
, Byte(FTeam
));
6161 utils
.writeBool(st
, FAlive
);
6162 // Èçðàñõîäîâàë ëè âñå æèçíè
6163 utils
.writeBool(st
, FNoRespawn
);
6165 if FDirection
= TDirection
.D_LEFT
then b
:= 1 else b
:= 2; // D_RIGHT
6166 utils
.writeInt(st
, Byte(b
));
6168 utils
.writeInt(st
, LongInt(FHealth
));
6169 // Êîýôôèöèåíò èíâàëèäíîñòè
6170 utils
.writeInt(st
, LongInt(FHandicap
));
6172 utils
.writeInt(st
, Byte(FLives
));
6174 utils
.writeInt(st
, LongInt(FArmor
));
6176 utils
.writeInt(st
, LongInt(FAir
));
6178 utils
.writeInt(st
, LongInt(FJetFuel
));
6180 utils
.writeInt(st
, LongInt(FPain
));
6182 utils
.writeInt(st
, LongInt(FKills
));
6184 utils
.writeInt(st
, LongInt(FMonsterKills
));
6186 utils
.writeInt(st
, LongInt(FFrags
));
6188 utils
.writeInt(st
, LongInt(FAssists
));
6190 utils
.writeInt(st
, Byte(FFragCombo
));
6191 // Âðåìÿ ïîñëåäíåãî ôðàãà
6192 utils
.writeInt(st
, LongWord(FLastFrag
));
6194 utils
.writeInt(st
, LongInt(FDeath
));
6196 utils
.writeInt(st
, Byte(FFlag
));
6198 utils
.writeInt(st
, LongInt(FSecrets
));
6200 utils
.writeInt(st
, Byte(FCurrWeap
));
6202 utils
.writeInt(st
, Word(FNextWeap
));
6204 utils
.writeInt(st
, Byte(FNextWeapDelay
));
6205 // Âðåìÿ çàðÿäêè BFG
6206 utils
.writeInt(st
, SmallInt(FBFGFireCounter
));
6208 utils
.writeInt(st
, LongInt(FDamageBuffer
));
6209 // Ïîñëåäíèé óäàðèâøèé
6210 utils
.writeInt(st
, Word(FLastSpawnerUID
));
6211 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà
6212 utils
.writeInt(st
, Byte(FLastHit
));
6214 Obj_SaveState(st
, @FObj
);
6215 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ
6216 for i
:= A_BULLETS
to A_HIGH
do utils
.writeInt(st
, Word(FAmmo
[i
]));
6217 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ
6218 for i
:= A_BULLETS
to A_HIGH
do utils
.writeInt(st
, Word(FMaxAmmo
[i
]));
6220 for i
:= WP_FIRST
to WP_LAST
do utils
.writeBool(st
, FWeapon
[i
]);
6221 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ
6222 for i
:= WP_FIRST
to WP_LAST
do utils
.writeInt(st
, Word(FReloading
[i
]));
6224 utils
.writeBool(st
, (R_ITEM_BACKPACK
in FRulez
));
6225 // Íàëè÷èå êðàñíîãî êëþ÷à
6226 utils
.writeBool(st
, (R_KEY_RED
in FRulez
));
6227 // Íàëè÷èå çåëåíîãî êëþ÷à
6228 utils
.writeBool(st
, (R_KEY_GREEN
in FRulez
));
6229 // Íàëè÷èå ñèíåãî êëþ÷à
6230 utils
.writeBool(st
, (R_KEY_BLUE
in FRulez
));
6232 utils
.writeBool(st
, (R_BERSERK
in FRulez
));
6233 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ
6234 for i
:= MR_SUIT
to MR_MAX
do utils
.writeInt(st
, LongWord(FMegaRulez
[i
]));
6235 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà
6236 for i
:= T_RESPAWN
to T_FLAGCAP
do utils
.writeInt(st
, LongWord(FTime
[i
]));
6238 utils
.writeStr(st
, FModel
.Name
);
6240 utils
.writeInt(st
, Byte(FColor
.R
));
6241 utils
.writeInt(st
, Byte(FColor
.G
));
6242 utils
.writeInt(st
, Byte(FColor
.B
));
6246 procedure TPlayer
.LoadState (st
: TStream
);
6255 if not utils
.checkSign(st
, 'PLYR') then raise XStreamError
.Create('invalid player signature');
6256 if (utils
.readByte(st
) <> PLR_SAVE_VERSION
) then raise XStreamError
.Create('invalid player version');
6258 FIamBot
:= utils
.readBool(st
);
6260 FUID
:= utils
.readWord(st
);
6262 str
:= utils
.readStr(st
);
6263 if (self
<> gPlayer1
) and (self
<> gPlayer2
) then FName
:= str
;
6265 FTeam
:= utils
.readByte(st
);
6267 FAlive
:= utils
.readBool(st
);
6268 // Èçðàñõîäîâàë ëè âñå æèçíè
6269 FNoRespawn
:= utils
.readBool(st
);
6271 b
:= utils
.readByte(st
);
6272 if b
= 1 then FDirection
:= TDirection
.D_LEFT
else FDirection
:= TDirection
.D_RIGHT
; // b = 2
6274 FHealth
:= utils
.readLongInt(st
);
6275 // Êîýôôèöèåíò èíâàëèäíîñòè
6276 FHandicap
:= utils
.readLongInt(st
);
6278 FLives
:= utils
.readByte(st
);
6280 FArmor
:= utils
.readLongInt(st
);
6282 FAir
:= utils
.readLongInt(st
);
6284 FJetFuel
:= utils
.readLongInt(st
);
6286 FPain
:= utils
.readLongInt(st
);
6288 FKills
:= utils
.readLongInt(st
);
6290 FMonsterKills
:= utils
.readLongInt(st
);
6292 FFrags
:= utils
.readLongInt(st
);
6294 FAssists
:= utils
.readLongInt(st
);
6296 FFragCombo
:= utils
.readByte(st
);
6297 // Âðåìÿ ïîñëåäíåãî ôðàãà
6298 FLastFrag
:= utils
.readLongWord(st
);
6300 FDeath
:= utils
.readLongInt(st
);
6302 FFlag
:= utils
.readByte(st
);
6304 FSecrets
:= utils
.readLongInt(st
);
6306 FCurrWeap
:= utils
.readByte(st
);
6308 FNextWeap
:= utils
.readWord(st
);
6310 FNextWeapDelay
:= utils
.readByte(st
);
6311 // Âðåìÿ çàðÿäêè BFG
6312 FBFGFireCounter
:= utils
.readSmallInt(st
);
6314 FDamageBuffer
:= utils
.readLongInt(st
);
6315 // Ïîñëåäíèé óäàðèâøèé
6316 FLastSpawnerUID
:= utils
.readWord(st
);
6317 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà
6318 FLastHit
:= utils
.readByte(st
);
6320 Obj_LoadState(@FObj
, st
);
6321 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ
6322 for i
:= A_BULLETS
to A_HIGH
do FAmmo
[i
] := utils
.readWord(st
);
6323 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ
6324 for i
:= A_BULLETS
to A_HIGH
do FMaxAmmo
[i
] := utils
.readWord(st
);
6326 for i
:= WP_FIRST
to WP_LAST
do FWeapon
[i
] := utils
.readBool(st
);
6327 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ
6328 for i
:= WP_FIRST
to WP_LAST
do FReloading
[i
] := utils
.readWord(st
);
6330 if utils
.readBool(st
) then Include(FRulez
, R_ITEM_BACKPACK
);
6331 // Íàëè÷èå êðàñíîãî êëþ÷à
6332 if utils
.readBool(st
) then Include(FRulez
, R_KEY_RED
);
6333 // Íàëè÷èå çåëåíîãî êëþ÷à
6334 if utils
.readBool(st
) then Include(FRulez
, R_KEY_GREEN
);
6335 // Íàëè÷èå ñèíåãî êëþ÷à
6336 if utils
.readBool(st
) then Include(FRulez
, R_KEY_BLUE
);
6338 if utils
.readBool(st
) then Include(FRulez
, R_BERSERK
);
6339 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ
6340 for i
:= MR_SUIT
to MR_MAX
do FMegaRulez
[i
] := utils
.readLongWord(st
);
6341 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà
6342 for i
:= T_RESPAWN
to T_FLAGCAP
do FTime
[i
] := utils
.readLongWord(st
);
6344 str
:= utils
.readStr(st
);
6346 FColor
.R
:= utils
.readByte(st
);
6347 FColor
.G
:= utils
.readByte(st
);
6348 FColor
.B
:= utils
.readByte(st
);
6349 if (self
= gPlayer1
) then
6351 str
:= gPlayer1Settings
.Model
;
6352 FColor
:= gPlayer1Settings
.Color
;
6354 else if (self
= gPlayer2
) then
6356 str
:= gPlayer2Settings
.Model
;
6357 FColor
:= gPlayer2Settings
.Color
;
6359 // Îáíîâëÿåì ìîäåëü èãðîêà
6361 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
6362 FModel
.Color
:= TEAMCOLOR
[FTeam
]
6364 FModel
.Color
:= FColor
;
6368 procedure TPlayer
.AllRulez(Health
: Boolean);
6374 FHealth
:= PLAYER_HP_LIMIT
;
6375 FArmor
:= PLAYER_AP_LIMIT
;
6379 for a
:= WP_FIRST
to WP_LAST
do FWeapon
[a
] := True;
6380 for a
:= A_BULLETS
to A_HIGH
do FAmmo
[a
] := 30000;
6381 FRulez
:= FRulez
+[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
];
6384 procedure TPlayer
.RestoreHealthArmor();
6386 FHealth
:= PLAYER_HP_LIMIT
;
6387 FArmor
:= PLAYER_AP_LIMIT
;
6390 procedure TPlayer
.FragCombo();
6394 if (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) or g_Game_IsClient
then
6396 if gTime
- FLastFrag
< FRAG_COMBO_TIME
then
6398 if FFragCombo
< 5 then
6400 Param
:= FUID
or (FFragCombo
shl 16);
6401 if (FComboEvnt
>= Low(gDelayedEvents
)) and
6402 (FComboEvnt
<= High(gDelayedEvents
)) and
6403 gDelayedEvents
[FComboEvnt
].Pending
and
6404 (gDelayedEvents
[FComboEvnt
].DEType
= DE_KILLCOMBO
) and
6405 (gDelayedEvents
[FComboEvnt
].DENum
and $FFFF = FUID
) then
6407 gDelayedEvents
[FComboEvnt
].Time
:= gTime
+ 500;
6408 gDelayedEvents
[FComboEvnt
].DENum
:= Param
;
6411 FComboEvnt
:= g_Game_DelayEvent(DE_KILLCOMBO
, 500, Param
);
6419 procedure TPlayer
.GiveItem(ItemType
: Byte);
6423 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
6425 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
6429 if FAir
< AIR_MAX
then
6436 if not (R_BERSERK
in FRulez
) then
6438 Include(FRulez
, R_BERSERK
);
6439 if FBFGFireCounter
< 1 then
6441 FCurrWeap
:= WEAPON_KASTET
;
6443 FModel
.SetWeapon(WEAPON_KASTET
);
6447 FBerserk
:= gTime
+30000;
6449 if FHealth
< PLAYER_HP_SOFT
then
6451 FHealth
:= PLAYER_HP_SOFT
;
6452 FBerserk
:= gTime
+30000;
6457 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
6459 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
6464 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
6466 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
6470 if FJetFuel
< JET_MAX
then
6472 FJetFuel
:= JET_MAX
;
6475 ITEM_MEDKIT_SMALL
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
6476 ITEM_MEDKIT_LARGE
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
6478 ITEM_ARMOR_GREEN
: if FArmor
< PLAYER_AP_SOFT
then FArmor
:= PLAYER_AP_SOFT
;
6479 ITEM_ARMOR_BLUE
: if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
6481 ITEM_SPHERE_BLUE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
6483 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) then
6485 if FHealth
< PLAYER_HP_LIMIT
then FHealth
:= PLAYER_HP_LIMIT
;
6486 if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
6489 ITEM_WEAPON_SAW
: FWeapon
[WEAPON_SAW
] := True;
6490 ITEM_WEAPON_SHOTGUN1
: FWeapon
[WEAPON_SHOTGUN1
] := True;
6491 ITEM_WEAPON_SHOTGUN2
: FWeapon
[WEAPON_SHOTGUN2
] := True;
6492 ITEM_WEAPON_CHAINGUN
: FWeapon
[WEAPON_CHAINGUN
] := True;
6493 ITEM_WEAPON_ROCKETLAUNCHER
: FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
6494 ITEM_WEAPON_PLASMA
: FWeapon
[WEAPON_PLASMA
] := True;
6495 ITEM_WEAPON_BFG
: FWeapon
[WEAPON_BFG
] := True;
6496 ITEM_WEAPON_SUPERPULEMET
: FWeapon
[WEAPON_SUPERPULEMET
] := True;
6497 ITEM_WEAPON_FLAMETHROWER
: FWeapon
[WEAPON_FLAMETHROWER
] := True;
6499 ITEM_AMMO_BULLETS
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
6500 ITEM_AMMO_BULLETS_BOX
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
6501 ITEM_AMMO_SHELLS
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
6502 ITEM_AMMO_SHELLS_BOX
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
6503 ITEM_AMMO_ROCKET
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
6504 ITEM_AMMO_ROCKET_BOX
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
6505 ITEM_AMMO_CELL
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
6506 ITEM_AMMO_CELL_BIG
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
6507 ITEM_AMMO_FUELCAN
: if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
6510 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
6511 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
6512 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
6513 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or
6514 (FMaxAmmo
[A_FUEL
] < AmmoLimits
[1, A_FUEL
]) then
6516 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[1, A_BULLETS
];
6517 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[1, A_SHELLS
];
6518 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[1, A_ROCKETS
];
6519 FMaxAmmo
[A_CELLS
] := AmmoLimits
[1, A_CELLS
];
6520 FMaxAmmo
[A_FUEL
] := AmmoLimits
[1, A_FUEL
];
6522 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
6523 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
6524 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
6525 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
6527 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
6530 ITEM_KEY_RED
: if not (R_KEY_RED
in FRulez
) then Include(FRulez
, R_KEY_RED
);
6531 ITEM_KEY_GREEN
: if not (R_KEY_GREEN
in FRulez
) then Include(FRulez
, R_KEY_GREEN
);
6532 ITEM_KEY_BLUE
: if not (R_KEY_BLUE
in FRulez
) then Include(FRulez
, R_KEY_BLUE
);
6534 ITEM_BOTTLE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
6535 ITEM_HELMET
: if FArmor
< PLAYER_AP_LIMIT
then IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
6540 if g_Game_IsNet
and g_Game_IsServer
then
6541 MH_SEND_PlayerStats(FUID
);
6544 procedure TPlayer
.FlySmoke(Times
: DWORD
= 1);
6549 if (Random(5) = 1) and (Times
= 1) then
6552 if BodyInLiquid(0, 0) then
6554 g_Game_Effect_Bubbles(Obj
.X
+Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2)+Random(3)-1,
6555 Obj
.Y
+Obj
.Rect
.Height
+8, 1, 8, 4);
6559 if g_Frames_Get(id
, 'FRAMES_SMOKE') then
6561 for i
:= 1 to Times
do
6563 Anim
:= TAnimation
.Create(id
, False, 3);
6565 g_GFX_OnceAnim(Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(Anim
.Width
div 2),
6566 Obj
.Y
+Obj
.Rect
.Height
-4+Random(8+Times
*2), Anim
, ONCEANIM_SMOKE
);
6572 procedure TPlayer
.OnFireFlame(Times
: DWORD
= 1);
6577 if (Random(10) = 1) and (Times
= 1) then
6580 if g_Frames_Get(id
, 'FRAMES_FLAME') then
6582 for i
:= 1 to Times
do
6584 Anim
:= TAnimation
.Create(id
, False, 3);
6586 g_GFX_OnceAnim(Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(Anim
.Width
div 2),
6587 Obj
.Y
+8+Random(8+Times
*2), Anim
, ONCEANIM_SMOKE
);
6593 procedure TPlayer
.PauseSounds(Enable
: Boolean);
6595 FSawSound
.Pause(Enable
);
6596 FSawSoundIdle
.Pause(Enable
);
6597 FSawSoundHit
.Pause(Enable
);
6598 FSawSoundSelect
.Pause(Enable
);
6599 FFlameSoundOn
.Pause(Enable
);
6600 FFlameSoundOff
.Pause(Enable
);
6601 FFlameSoundWork
.Pause(Enable
);
6602 FJetSoundFly
.Pause(Enable
);
6603 FJetSoundOn
.Pause(Enable
);
6604 FJetSoundOff
.Pause(Enable
);
6609 constructor TCorpse
.Create(X
, Y
: Integer; ModelName
: String; aMess
: Boolean);
6614 FObj
.Rect
:= PLAYER_CORPSERECT
;
6615 FModelName
:= ModelName
;
6620 FState
:= CORPSE_STATE_MESS
;
6621 g_PlayerModel_GetAnim(ModelName
, A_DIE2
, FAnimation
, FAnimationMask
);
6625 FState
:= CORPSE_STATE_NORMAL
;
6626 g_PlayerModel_GetAnim(ModelName
, A_DIE1
, FAnimation
, FAnimationMask
);
6630 destructor TCorpse
.Destroy();
6637 function TCorpse
.ObjPtr (): PObj
; inline; begin result
:= @FObj
; end;
6639 procedure TCorpse
.positionChanged (); inline; begin end;
6641 procedure TCorpse
.moveBy (dx
, dy
: Integer); inline;
6643 if (dx
<> 0) or (dy
<> 0) then
6652 procedure TCorpse
.getMapBox (out x
, y
, w
, h
: Integer); inline;
6654 x
:= FObj
.X
+PLAYER_CORPSERECT
.X
;
6655 y
:= FObj
.Y
+PLAYER_CORPSERECT
.Y
;
6656 w
:= PLAYER_CORPSERECT
.Width
;
6657 h
:= PLAYER_CORPSERECT
.Height
;
6661 procedure TCorpse
.Damage(Value
: Word; SpawnerUID
: Word; vx
, vy
: Integer);
6666 if FState
= CORPSE_STATE_REMOVEME
then
6669 FDamage
:= FDamage
+ Value
;
6671 if FDamage
> 150 then
6673 if FAnimation
<> nil then
6678 FState
:= CORPSE_STATE_REMOVEME
;
6680 g_Player_CreateGibs(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
6681 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2),
6682 FModelName
, FColor
);
6683 // Çâóê ìÿñà îò òðóïà:
6684 pm
:= g_PlayerModel_Get(FModelName
);
6685 pm
.PlaySound(MODELSOUND_DIE
, 5, FObj
.X
, FObj
.Y
);
6689 if (gBodyKillEvent
<> -1)
6690 and gDelayedEvents
[gBodyKillEvent
].Pending
then
6691 gDelayedEvents
[gBodyKillEvent
].Pending
:= False;
6692 gBodyKillEvent
:= g_Game_DelayEvent(DE_BODYKILL
, 1050, SpawnerUID
);
6697 Blood
:= g_PlayerModel_GetBlood(FModelName
);
6698 FObj
.Vel
.X
:= FObj
.Vel
.X
+ vx
;
6699 FObj
.Vel
.Y
:= FObj
.Vel
.Y
+ vy
;
6700 g_GFX_Blood(FObj
.X
+PLAYER_CORPSERECT
.X
+(PLAYER_CORPSERECT
.Width
div 2),
6701 FObj
.Y
+PLAYER_CORPSERECT
.Y
+(PLAYER_CORPSERECT
.Height
div 2),
6702 Value
, vx
, vy
, 16, (PLAYER_CORPSERECT
.Height
*2) div 3,
6703 Blood
.R
, Blood
.G
, Blood
.B
, Blood
.Kind
);
6707 procedure TCorpse
.Draw();
6711 if FState
= CORPSE_STATE_REMOVEME
then
6714 FObj
.lerp(gLerpFactor
, fX
, fY
);
6716 if FAnimation
<> nil then
6717 FAnimation
.Draw(fX
, fY
, TMirrorType
.None
);
6719 if FAnimationMask
<> nil then
6722 FAnimationMask
.Draw(fX
, fY
, TMirrorType
.None
);
6729 procedure TCorpse
.Update();
6733 if FState
= CORPSE_STATE_REMOVEME
then
6736 FObj
.oldX
:= FObj
.X
;
6737 FObj
.oldY
:= FObj
.Y
;
6739 if gTime
mod (GAME_TICK
*2) <> 0 then
6741 g_Obj_Move(@FObj
, True, True, True);
6742 positionChanged(); // this updates spatial accelerators
6746 // Ñîïðîòèâëåíèå âîçäóõà äëÿ òðóïà:
6747 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
6749 st
:= g_Obj_Move(@FObj
, True, True, True);
6750 positionChanged(); // this updates spatial accelerators
6752 if WordBool(st
and MOVE_FALLOUT
) then
6754 FState
:= CORPSE_STATE_REMOVEME
;
6758 if FAnimation
<> nil then
6759 FAnimation
.Update();
6760 if FAnimationMask
<> nil then
6761 FAnimationMask
.Update();
6765 procedure TCorpse
.SaveState (st
: TStream
);
6772 utils
.writeSign(st
, 'CORP');
6773 utils
.writeInt(st
, Byte(0));
6775 utils
.writeInt(st
, Byte(FState
));
6777 utils
.writeInt(st
, Byte(FDamage
));
6779 utils
.writeInt(st
, Byte(FColor
.R
));
6780 utils
.writeInt(st
, Byte(FColor
.G
));
6781 utils
.writeInt(st
, Byte(FColor
.B
));
6783 Obj_SaveState(st
, @FObj
);
6784 utils
.writeInt(st
, Word(FPlayerUID
));
6786 anim
:= (FAnimation
<> nil);
6787 utils
.writeBool(st
, anim
);
6788 // Åñëè åñòü - ñîõðàíÿåì
6789 if anim
then FAnimation
.SaveState(st
);
6790 // Åñòü ëè ìàñêà àíèìàöèè
6791 anim
:= (FAnimationMask
<> nil);
6792 utils
.writeBool(st
, anim
);
6793 // Åñëè åñòü - ñîõðàíÿåì
6794 if anim
then FAnimationMask
.SaveState(st
);
6798 procedure TCorpse
.LoadState (st
: TStream
);
6805 if not utils
.checkSign(st
, 'CORP') then raise XStreamError
.Create('invalid corpse signature');
6806 if (utils
.readByte(st
) <> 0) then raise XStreamError
.Create('invalid corpse version');
6808 FState
:= utils
.readByte(st
);
6810 FDamage
:= utils
.readByte(st
);
6812 FColor
.R
:= utils
.readByte(st
);
6813 FColor
.G
:= utils
.readByte(st
);
6814 FColor
.B
:= utils
.readByte(st
);
6816 Obj_LoadState(@FObj
, st
);
6817 FPlayerUID
:= utils
.readWord(st
);
6819 anim
:= utils
.readBool(st
);
6820 // Åñëè åñòü - çàãðóæàåì
6823 Assert(FAnimation
<> nil, 'TCorpse.LoadState: no FAnimation');
6824 FAnimation
.LoadState(st
);
6826 // Åñòü ëè ìàñêà àíèìàöèè
6827 anim
:= utils
.readBool(st
);
6828 // Åñëè åñòü - çàãðóæàåì
6831 Assert(FAnimationMask
<> nil, 'TCorpse.LoadState: no FAnimationMask');
6832 FAnimationMask
.LoadState(st
);
6838 constructor TBot
.Create();
6845 FSpectator
:= False;
6852 for a
:= WP_FIRST
to WP_LAST
do
6854 FDifficult
.WeaponPrior
[a
] := WEAPON_PRIOR1
[a
];
6855 FDifficult
.CloseWeaponPrior
[a
] := WEAPON_PRIOR2
[a
];
6856 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
6860 destructor TBot
.Destroy();
6863 inherited Destroy();
6866 procedure TBot
.Draw();
6870 //if FTargetUID <> 0 then e_DrawLine(1, FObj.X, FObj.Y, g_Player_Get(FTargetUID).FObj.X,
6871 // g_Player_Get(FTargetUID).FObj.Y, 255, 0, 0);
6874 procedure TBot
.Respawn(Silent
: Boolean; Force
: Boolean = False);
6876 inherited Respawn(Silent
, Force
);
6879 FSelectedWeapon
:= FCurrWeap
;
6884 procedure TBot
.UpdateCombat();
6897 TTargetRecord
= array of TTarget
;
6899 function Compare(a
, b
: TTarget
): Integer;
6901 if a
.Line
and not b
.Line
then // A íà ëèíèè îãíÿ
6904 if not a
.Line
and b
.Line
then // B íà ëèíèè îãíÿ
6906 else // È A, è B íà ëèíèè èëè íå íà ëèíèè îãíÿ
6907 if (a
.Line
and b
.Line
) or ((not a
.Line
) and (not b
.Line
)) then
6909 if a
.Dist
> b
.Dist
then // B áëèæå
6911 else // A áëèæå èëè ðàâíîóäàëåííî ñ B
6914 else // Ñòðàííî -> A
6919 a
, x1
, y1
, x2
, y2
: Integer;
6920 targets
: TTargetRecord
;
6922 Target
, BestTarget
: TTarget
;
6923 firew
, fireh
: Integer;
6927 vsPlayer
, vsMonster
, ok
: Boolean;
6930 function monsUpdate (mon
: TMonster
): Boolean;
6932 result
:= false; // don't stop
6933 if mon
.alive
and (mon
.MonsterType
<> MONSTER_BARREL
) then
6935 if not TargetOnScreen(mon
.Obj
.X
+mon
.Obj
.Rect
.X
, mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
) then exit
;
6937 x2
:= mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2);
6938 y2
:= mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+(mon
.Obj
.Rect
.Height
div 2);
6940 // Åñëè ìîíñòð íà ýêðàíå è íå ïðèêðûò ñòåíîé
6941 if g_TraceVector(x1
, y1
, x2
, y2
) then
6943 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé
6944 SetLength(targets
, Length(targets
)+1);
6945 with targets
[High(targets
)] do
6952 Rect
:= mon
.Obj
.Rect
;
6953 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6954 Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6955 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6964 vsPlayer
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
);
6965 vsMonster
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
);
6967 // Åñëè òåêóùåå îðóæèå íå òî, ÷òî íóæíî, òî ìåíÿåì:
6968 if FCurrWeap
<> FSelectedWeapon
then
6971 // Åñëè íóæíî ñòðåëÿòü è íóæíîå îðóæèå, òî íàæàòü "Ñòðåëÿòü":
6972 if (GetAIFlag('NEEDFIRE') <> '') and (FCurrWeap
= FSelectedWeapon
) then
6974 RemoveAIFlag('NEEDFIRE');
6977 WEAPON_PLASMA
, WEAPON_SUPERPULEMET
, WEAPON_CHAINGUN
: PressKey(KEY_FIRE
, 20);
6978 WEAPON_SAW
, WEAPON_KASTET
, WEAPON_FLAMETHROWER
: PressKey(KEY_FIRE
, 40);
6979 else PressKey(KEY_FIRE
);
6983 // Êîîðäèíàòû ñòâîëà:
6984 x1
:= FObj
.X
+ WEAPONPOINT
[FDirection
].X
;
6985 y1
:= FObj
.Y
+ WEAPONPOINT
[FDirection
].Y
;
6987 Target
.UID
:= FTargetUID
;
6990 if Target
.UID
<> 0 then
6991 begin // Öåëü åñòü - íàñòðàèâàåì
6992 if (g_GetUIDType(Target
.UID
) = UID_PLAYER
) and
6995 tpla
:= g_Player_Get(Target
.UID
);
6999 if (@FObj
) <> nil then
7006 Target
.cX
:= Target
.X
+ PLAYER_RECT_CX
;
7007 Target
.cY
:= Target
.Y
+ PLAYER_RECT_CY
;
7008 Target
.Rect
:= PLAYER_RECT
;
7009 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
7010 Target
.Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
7011 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
7012 Target
.IsPlayer
:= True;
7016 if (g_GetUIDType(Target
.UID
) = UID_MONSTER
) and
7019 mon
:= g_Monsters_ByUID(Target
.UID
);
7022 Target
.X
:= mon
.Obj
.X
;
7023 Target
.Y
:= mon
.Obj
.Y
;
7025 Target
.cX
:= Target
.X
+ mon
.Obj
.Rect
.X
+ (mon
.Obj
.Rect
.Width
div 2);
7026 Target
.cY
:= Target
.Y
+ mon
.Obj
.Rect
.Y
+ (mon
.Obj
.Rect
.Height
div 2);
7027 Target
.Rect
:= mon
.Obj
.Rect
;
7028 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
7029 Target
.Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
7030 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
7031 Target
.IsPlayer
:= False;
7038 begin // Öåëè íåò - îáíóëÿåì
7043 Target
.Visible
:= False;
7044 Target
.Line
:= False;
7045 Target
.IsPlayer
:= False;
7050 // Åñëè öåëü íå âèäèìà èëè íå íà ëèíèè îãíÿ, òî èùåì âñå âîçìîæíûå öåëè:
7051 if (not Target
.Line
) or (not Target
.Visible
) then
7055 for a
:= 0 to High(gPlayers
) do
7056 if (gPlayers
[a
] <> nil) and (gPlayers
[a
].alive
) and
7057 (gPlayers
[a
].FUID
<> FUID
) and
7058 (not SameTeam(FUID
, gPlayers
[a
].FUID
)) and
7059 (not gPlayers
[a
].NoTarget
) and
7060 (gPlayers
[a
].FMegaRulez
[MR_INVIS
] < gTime
) then
7062 if not TargetOnScreen(gPlayers
[a
].FObj
.X
+ PLAYER_RECT
.X
,
7063 gPlayers
[a
].FObj
.Y
+ PLAYER_RECT
.Y
) then
7066 x2
:= gPlayers
[a
].FObj
.X
+ PLAYER_RECT_CX
;
7067 y2
:= gPlayers
[a
].FObj
.Y
+ PLAYER_RECT_CY
;
7069 // Åñëè èãðîê íà ýêðàíå è íå ïðèêðûò ñòåíîé:
7070 if g_TraceVector(x1
, y1
, x2
, y2
) then
7072 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé:
7073 SetLength(targets
, Length(targets
)+1);
7074 with targets
[High(targets
)] do
7076 UID
:= gPlayers
[a
].FUID
;
7077 X
:= gPlayers
[a
].FObj
.X
;
7078 Y
:= gPlayers
[a
].FObj
.Y
;
7081 Rect
:= PLAYER_RECT
;
7082 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
7083 Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
7084 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
7092 if vsMonster
then g_Mons_ForEach(monsUpdate
);
7095 // Åñëè åñòü âîçìîæíûå öåëè:
7096 // (Âûáèðàåì ëó÷øóþ, ìåíÿåì îðóæèå è áåæèì ê íåé/îò íåå)
7097 if targets
<> nil then
7099 // Âûáèðàåì íàèëó÷øóþ öåëü:
7100 BestTarget
:= targets
[0];
7101 if Length(targets
) > 1 then
7102 for a
:= 1 to High(targets
) do
7103 if Compare(BestTarget
, targets
[a
]) = 1 then
7104 BestTarget
:= targets
[a
];
7106 // Åñëè ëó÷øàÿ öåëü "âèäíåå" òåêóùåé, òî òåêóùàÿ := ëó÷øàÿ:
7107 if ((not Target
.Visible
) and BestTarget
.Visible
and (Target
.UID
<> BestTarget
.UID
)) or
7108 ((not Target
.Line
) and BestTarget
.Line
and BestTarget
.Visible
) then
7110 Target
:= BestTarget
;
7112 if (Healthy() = 3) or ((Healthy() = 2)) then
7113 begin // Åñëè çäîðîâû - äîãîíÿåì
7114 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
7115 SetAIFlag('GORIGHT', '1');
7116 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
7117 SetAIFlag('GOLEFT', '1');
7120 begin // Åñëè ïîáèòû - óáåãàåì
7121 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) then
7122 SetAIFlag('GORIGHT', '1');
7123 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
7124 SetAIFlag('GOLEFT', '1');
7127 // Âûáèðàåì îðóæèå íà îñíîâå ðàññòîÿíèÿ è ïðèîðèòåòîâ:
7128 SelectWeapon(Abs(x1
-Target
.cX
));
7133 // (Äîãîíÿåì/óáåãàåì, ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëè)
7134 // (Åñëè öåëü äàëåêî, òî õâàòèò ñëåäèòü çà íåé)
7135 if Target
.UID
<> 0 then
7137 if not TargetOnScreen(Target
.X
+ Target
.Rect
.X
,
7138 Target
.Y
+ Target
.Rect
.Y
) then
7139 begin // Öåëü ñáåæàëà ñ "ýêðàíà"
7140 if (Healthy() = 3) or ((Healthy() = 2)) then
7141 begin // Åñëè çäîðîâû - äîãîíÿåì
7142 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
7143 SetAIFlag('GORIGHT', '1');
7144 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
7145 SetAIFlag('GOLEFT', '1');
7148 begin // Åñëè ïîáèòû - çàáûâàåì î öåëè è óáåãàåì
7150 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) then
7151 SetAIFlag('GORIGHT', '1');
7152 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
7153 SetAIFlag('GOLEFT', '1');
7157 begin // Öåëü ïîêà íà "ýêðàíå"
7158 // Åñëè öåëü íå çàãîðîæåíà ñòåíîé, òî îòìå÷àåì, êîãäà åå âèäåëè:
7159 if g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
7160 FLastVisible
:= gTime
;
7161 // Åñëè ðàçíèöà âûñîò íå âåëèêà, òî äîãîíÿåì:
7162 if (Abs(FObj
.Y
-Target
.Y
) <= 128) then
7164 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
7165 SetAIFlag('GORIGHT', '1');
7166 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
7167 SetAIFlag('GOLEFT', '1');
7171 // Âûáèðàåì óãîë ââåðõ:
7172 if FDirection
= TDirection
.D_LEFT
then
7173 angle
:= ANGLE_LEFTUP
7175 angle
:= ANGLE_RIGHTUP
;
7177 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7178 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7180 // Åñëè ïðè óãëå ââåðõ ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
7181 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
7182 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128), //96
7183 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
7184 Target
.Rect
.Width
, Target
.Rect
.Height
) and
7185 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
7186 begin // òî íóæíî ñòðåëÿòü ââåðõ
7187 SetAIFlag('NEEDFIRE', '1');
7188 SetAIFlag('NEEDSEEUP', '1');
7191 // Âûáèðàåì óãîë âíèç:
7192 if FDirection
= TDirection
.D_LEFT
then
7193 angle
:= ANGLE_LEFTDOWN
7195 angle
:= ANGLE_RIGHTDOWN
;
7197 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7198 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7200 // Åñëè ïðè óãëå âíèç ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
7201 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
7202 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
7203 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
7204 Target
.Rect
.Width
, Target
.Rect
.Height
) and
7205 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
7206 begin // òî íóæíî ñòðåëÿòü âíèç
7207 SetAIFlag('NEEDFIRE', '1');
7208 SetAIFlag('NEEDSEEDOWN', '1');
7211 // Åñëè öåëü âèäíî è îíà íà òàêîé æå âûñîòå:
7212 if Target
.Visible
and
7213 (y1
+4 < Target
.Y
+Target
.Rect
.Y
+Target
.Rect
.Height
) and
7214 (y1
-4 > Target
.Y
+Target
.Rect
.Y
) then
7216 // Åñëè èäåì â ñòîðîíó öåëè, òî íàäî ñòðåëÿòü:
7217 if ((FDirection
= TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) or
7218 ((FDirection
= TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
7219 begin // òî íóæíî ñòðåëÿòü âïåðåä
7220 SetAIFlag('NEEDFIRE', '1');
7221 SetAIFlag('NEEDSEEDOWN', '');
7222 SetAIFlag('NEEDSEEUP', '');
7224 // Åñëè öåëü â ïðåäåëàõ "ýêðàíà" è ñëîæíîñòü ïîçâîëÿåò ïðûæêè ñáëèæåíèÿ:
7225 if Abs(FObj
.X
-Target
.X
) < Trunc(gPlayerScreenSize
.X
*0.75) then
7226 if GetRnd(FDifficult
.CloseJump
) then
7227 begin // òî åñëè ïîâåçåò - ïðûãàåì (îñîáåííî, åñëè áëèçêî)
7228 if Abs(FObj
.X
-Target
.X
) < 128 then
7232 if Random(a
) = 0 then
7233 SetAIFlag('NEEDJUMP', '1');
7237 // Åñëè öåëü âñå åùå åñòü:
7238 if Target
.UID
<> 0 then
7239 if gTime
-FLastVisible
> 2000 then // Åñëè âèäåëè äàâíî
7240 Target
.UID
:= 0 // òî çàáûòü öåëü
7241 else // Åñëè âèäåëè íåäàâíî
7242 begin // íî öåëü óáèëè
7243 if Target
.IsPlayer
then
7244 begin // Öåëü - èãðîê
7245 pla
:= g_Player_Get(Target
.UID
);
7246 if (pla
= nil) or (not pla
.alive
) or pla
.NoTarget
or
7247 (pla
.FMegaRulez
[MR_INVIS
] >= gTime
) then
7248 Target
.UID
:= 0; // òî çàáûòü öåëü
7251 begin // Öåëü - ìîíñòð
7252 mon
:= g_Monsters_ByUID(Target
.UID
);
7253 if (mon
= nil) or (not mon
.alive
) then
7254 Target
.UID
:= 0; // òî çàáûòü öåëü
7257 end; // if Target.UID <> 0
7259 FTargetUID
:= Target
.UID
;
7261 // Åñëè âîçìîæíûõ öåëåé íåò:
7262 // (Àòàêà ÷åãî-íèáóäü ñëåâà èëè ñïðàâà)
7263 if targets
= nil then
7264 if GetAIFlag('ATTACKLEFT') <> '' then
7265 begin // Åñëè íóæíî àòàêîâàòü íàëåâî
7266 RemoveAIFlag('ATTACKLEFT');
7268 SetAIFlag('NEEDJUMP', '1');
7270 if RunDirection() = TDirection
.D_RIGHT
then
7271 begin // Èäåì íå â òó ñòîðîíó
7272 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
7273 begin // Åñëè çäîðîâû, òî, âîçìîæíî, ñòðåëÿåì áåæèì âëåâî è ñòðåëÿåì
7274 SetAIFlag('NEEDFIRE', '1');
7275 SetAIFlag('GOLEFT', '1');
7279 begin // Èäåì â íóæíóþ ñòîðîíó
7280 if GetRnd(FDifficult
.InvisFire
) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
7281 SetAIFlag('NEEDFIRE', '1');
7282 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
7283 SetAIFlag('GORIGHT', '1');
7287 if GetAIFlag('ATTACKRIGHT') <> '' then
7288 begin // Åñëè íóæíî àòàêîâàòü íàïðàâî
7289 RemoveAIFlag('ATTACKRIGHT');
7291 SetAIFlag('NEEDJUMP', '1');
7293 if RunDirection() = TDirection
.D_LEFT
then
7294 begin // Èäåì íå â òó ñòîðîíó
7295 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
7296 begin // Åñëè çäîðîâû, òî, âîçìîæíî, áåæèì âïðàâî è ñòðåëÿåì
7297 SetAIFlag('NEEDFIRE', '1');
7298 SetAIFlag('GORIGHT', '1');
7303 if GetRnd(FDifficult
.InvisFire
) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
7304 SetAIFlag('NEEDFIRE', '1');
7305 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
7306 SetAIFlag('GOLEFT', '1');
7310 //HACK! (does it belongs there?)
7311 RealizeCurrentWeapon();
7313 // Åñëè åñòü âîçìîæíûå öåëè:
7314 // (Ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëÿì)
7315 if (targets
<> nil) and (GetAIFlag('NEEDFIRE') <> '') then
7316 for a
:= 0 to High(targets
) do
7318 // Åñëè ìîæåì ñòðåëÿòü ïî äèàãîíàëè:
7319 if GetRnd(FDifficult
.DiagFire
) then
7321 // Èùåì öåëü ñâåðõó è ñòðåëÿåì, åñëè åñòü:
7322 if FDirection
= TDirection
.D_LEFT
then
7323 angle
:= ANGLE_LEFTUP
7325 angle
:= ANGLE_RIGHTUP
;
7327 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7328 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7330 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
7331 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
7332 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
7333 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
7334 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
7336 SetAIFlag('NEEDFIRE', '1');
7337 SetAIFlag('NEEDSEEUP', '1');
7340 // Èùåì öåëü ñíèçó è ñòðåëÿåì, åñëè åñòü:
7341 if FDirection
= TDirection
.D_LEFT
then
7342 angle
:= ANGLE_LEFTDOWN
7344 angle
:= ANGLE_RIGHTDOWN
;
7346 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7347 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7349 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
7350 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
7351 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
7352 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
7353 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
7355 SetAIFlag('NEEDFIRE', '1');
7356 SetAIFlag('NEEDSEEDOWN', '1');
7360 // Åñëè öåëü "ïåðåä íîñîì", òî ñòðåëÿåì:
7361 if targets
[a
].Line
and targets
[a
].Visible
and
7362 (((FDirection
= TDirection
.D_LEFT
) and (targets
[a
].X
< FObj
.X
)) or
7363 ((FDirection
= TDirection
.D_RIGHT
) and (targets
[a
].X
> FObj
.X
))) then
7365 SetAIFlag('NEEDFIRE', '1');
7370 // Åñëè ëåòèò ïóëÿ, òî, âîçìîæíî, ïîäïðûãèâàåì:
7371 if g_Weapon_Danger(FUID
, FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
,
7372 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
,
7373 40+GetInterval(FDifficult
.Cover
, 40)) then
7374 SetAIFlag('NEEDJUMP', '1');
7376 // Åñëè êîí÷èëèñü ïàòîðíû, òî íóæíî ñìåíèòü îðóæèå:
7377 ammo
:= GetAmmoByWeapon(FCurrWeap
);
7378 if ((FCurrWeap
= WEAPON_SHOTGUN2
) and (ammo
< 2)) or
7379 ((FCurrWeap
= WEAPON_BFG
) and (ammo
< 40)) or
7381 SetAIFlag('SELECTWEAPON', '1');
7383 // Åñëè íóæíî ñìåíèòü îðóæèå, òî âûáèðàåì íóæíîå:
7384 if GetAIFlag('SELECTWEAPON') = '1' then
7387 RemoveAIFlag('SELECTWEAPON');
7391 procedure TBot
.Update();
7404 // Ïðîâåðÿåì, îòêëþ÷¸í ëè AI áîòîâ
7405 if (g_debug_BotAIOff
= 1) and (Team
= TEAM_RED
) then
7407 if (g_debug_BotAIOff
= 2) and (Team
= TEAM_BLUE
) then
7409 if g_debug_BotAIOff
= 3 then
7419 RealizeCurrentWeapon();
7426 procedure TBot
.ReleaseKey(Key
: Byte);
7435 function TBot
.KeyPressed(Key
: Word): Boolean;
7437 Result
:= FKeys
[Key
].Pressed
;
7440 function TBot
.GetAIFlag(aName
: String20
): String20
;
7446 aName
:= LowerCase(aName
);
7448 if FAIFlags
<> nil then
7449 for a
:= 0 to High(FAIFlags
) do
7450 if LowerCase(FAIFlags
[a
].Name
) = aName
then
7452 Result
:= FAIFlags
[a
].Value
;
7457 procedure TBot
.RemoveAIFlag(aName
: String20
);
7461 if FAIFlags
= nil then Exit
;
7463 aName
:= LowerCase(aName
);
7465 for a
:= 0 to High(FAIFlags
) do
7466 if LowerCase(FAIFlags
[a
].Name
) = aName
then
7468 if a
<> High(FAIFlags
) then
7469 for b
:= a
to High(FAIFlags
)-1 do
7470 FAIFlags
[b
] := FAIFlags
[b
+1];
7472 SetLength(FAIFlags
, Length(FAIFlags
)-1);
7477 procedure TBot
.SetAIFlag(aName
, fValue
: String20
);
7485 aName
:= LowerCase(aName
);
7487 if FAIFlags
<> nil then
7488 for a
:= 0 to High(FAIFlags
) do
7489 if LowerCase(FAIFlags
[a
].Name
) = aName
then
7495 if ok
then FAIFlags
[a
].Value
:= fValue
7498 SetLength(FAIFlags
, Length(FAIFlags
)+1);
7499 with FAIFlags
[High(FAIFlags
)] do
7507 procedure TBot
.UpdateMove
;
7509 procedure GoLeft(Time
: Word = 1);
7511 ReleaseKey(KEY_LEFT
);
7512 ReleaseKey(KEY_RIGHT
);
7513 PressKey(KEY_LEFT
, Time
);
7514 SetDirection(TDirection
.D_LEFT
);
7517 procedure GoRight(Time
: Word = 1);
7519 ReleaseKey(KEY_LEFT
);
7520 ReleaseKey(KEY_RIGHT
);
7521 PressKey(KEY_RIGHT
, Time
);
7522 SetDirection(TDirection
.D_RIGHT
);
7525 function Rnd(a
: Word): Boolean;
7527 Result
:= Random(a
) = 0;
7530 procedure Turn(Time
: Word = 1200);
7532 if RunDirection() = TDirection
.D_LEFT
then GoRight(Time
) else GoLeft(Time
);
7537 ReleaseKey(KEY_LEFT
);
7538 ReleaseKey(KEY_RIGHT
);
7541 function CanRunLeft(): Boolean;
7543 Result
:= not CollideLevel(-1, 0);
7546 function CanRunRight(): Boolean;
7548 Result
:= not CollideLevel(1, 0);
7551 function CanRun(): Boolean;
7553 if RunDirection() = TDirection
.D_LEFT
then Result
:= CanRunLeft() else Result
:= CanRunRight();
7556 procedure Jump(Time
: Word = 30);
7558 PressKey(KEY_JUMP
, Time
);
7561 function NearHole(): Boolean;
7565 { TODO 5 : Ëåñòíèöû }
7566 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7567 for x
:= 1 to PLAYER_RECT
.Width
do
7568 if (not StayOnStep(x
*sx
, 0)) and
7569 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7570 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7579 function BorderHole(): Boolean;
7583 { TODO 5 : Ëåñòíèöû }
7584 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7585 for x
:= 1 to PLAYER_RECT
.Width
do
7586 if (not StayOnStep(x
*sx
, 0)) and
7587 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7588 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7590 for xx
:= x
to x
+32 do
7591 if CollideLevel(xx
*sx
, PLAYER_RECT
.Height
) then
7601 function NearDeepHole(): Boolean;
7607 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7610 for x
:= 1 to PLAYER_RECT
.Width
do
7611 if (not StayOnStep(x
*sx
, 0)) and
7612 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7613 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7615 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
7617 if CollideLevel(x
*sx
, PLAYER_RECT
.Height
*y
) then Exit
;
7622 end else Result
:= False;
7625 function OverDeepHole(): Boolean;
7632 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
7634 if CollideLevel(0, PLAYER_RECT
.Height
*y
) then Exit
;
7641 function OnGround(): Boolean;
7643 Result
:= StayOnStep(0, 0) or CollideLevel(0, 1);
7646 function OnLadder(): Boolean;
7648 Result
:= FullInStep(0, 0);
7651 function BelowLadder(): Boolean;
7653 Result
:= (FullInStep(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) and
7654 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
7655 (FullInStep(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) and
7656 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
7659 function BelowLiftUp(): Boolean;
7661 Result
:= ((FullInLift(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) = -1) and
7662 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
7663 ((FullInLift(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) = -1) and
7664 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
7667 function OnTopLift(): Boolean;
7669 Result
:= (FullInLift(0, 0) = -1) and (FullInLift(0, -32) = 0);
7672 function CanJumpOver(): Boolean;
7676 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7680 if not CollideLevel(sx
, 0) then Exit
;
7682 for y
:= 1 to BOT_MAXJUMP
do
7683 if CollideLevel(0, -y
) then Exit
else
7684 if not CollideLevel(sx
, -y
) then
7691 function CanJumpUp(Dist
: ShortInt): Boolean;
7698 if CollideLevel(Dist
, 0) then Exit
;
7701 for y
:= 0 to BOT_MAXJUMP
do
7702 if CollideLevel(Dist
, -y
) then
7711 for yy
:= y
+1 to BOT_MAXJUMP
do
7712 if not CollideLevel(Dist
, -yy
) then
7721 for y
:= 0 to BOT_MAXJUMP
do
7722 if CollideLevel(0, -y
) then
7730 if y
< yy
then Exit
;
7735 function IsSafeTrigger(): Boolean;
7740 if gTriggers
= nil then
7742 for a
:= 0 to High(gTriggers
) do
7743 if Collide(gTriggers
[a
].X
,
7746 gTriggers
[a
].Height
) and
7747 (gTriggers
[a
].TriggerType
in [TRIGGER_EXIT
, TRIGGER_CLOSEDOOR
,
7748 TRIGGER_CLOSETRAP
, TRIGGER_TRAP
,
7749 TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
,
7750 TRIGGER_ONOFF
, TRIGGER_SPAWNMONSTER
,
7751 TRIGGER_DAMAGE
, TRIGGER_SHOT
]) then
7756 // Âîçìîæíî, íàæèìàåì êíîïêó:
7757 if Rnd(16) and IsSafeTrigger() then
7760 // Åñëè ïîä ëèôòîì èëè ñòóïåíüêàìè, òî, âîçìîæíî, ïðûãàåì:
7761 if OnLadder() or ((BelowLadder() or BelowLiftUp()) and Rnd(8)) then
7763 ReleaseKey(KEY_LEFT
);
7764 ReleaseKey(KEY_RIGHT
);
7768 // Èäåì âëåâî, åñëè íàäî áûëî:
7769 if GetAIFlag('GOLEFT') <> '' then
7771 RemoveAIFlag('GOLEFT');
7772 if CanRunLeft() then
7776 // Èäåì âïðàâî, åñëè íàäî áûëî:
7777 if GetAIFlag('GORIGHT') <> '' then
7779 RemoveAIFlag('GORIGHT');
7780 if CanRunRight() then
7784 // Åñëè âûëåòåëè çà êàðòó, òî ïðîáóåì âåðíóòüñÿ:
7785 if FObj
.X
< -32 then
7788 if FObj
.X
+32 > gMapInfo
.Width
then
7791 // Ïðûãàåì, åñëè íàäî áûëî:
7792 if GetAIFlag('NEEDJUMP') <> '' then
7795 RemoveAIFlag('NEEDJUMP');
7798 // Ñìîòðèì ââåðõ, åñëè íàäî áûëî:
7799 if GetAIFlag('NEEDSEEUP') <> '' then
7802 ReleaseKey(KEY_DOWN
);
7803 PressKey(KEY_UP
, 20);
7804 RemoveAIFlag('NEEDSEEUP');
7807 // Ñìîòðèì âíèç, åñëè íàäî áûëî:
7808 if GetAIFlag('NEEDSEEDOWN') <> '' then
7811 ReleaseKey(KEY_DOWN
);
7812 PressKey(KEY_DOWN
, 20);
7813 RemoveAIFlag('NEEDSEEDOWN');
7816 // Åñëè íóæíî áûëî â äûðó è ìû íå íà çåìëå, òî ïîêîðíî ëåòèì:
7817 if GetAIFlag('GOINHOLE') <> '' then
7818 if not OnGround() then
7820 ReleaseKey(KEY_LEFT
);
7821 ReleaseKey(KEY_RIGHT
);
7822 RemoveAIFlag('GOINHOLE');
7823 SetAIFlag('FALLINHOLE', '1');
7826 // Åñëè ïàäàëè è äîñòèãëè çåìëè, òî õâàòèò ïàäàòü:
7827 if GetAIFlag('FALLINHOLE') <> '' then
7829 RemoveAIFlag('FALLINHOLE');
7831 // Åñëè ëåòåëè ïðÿìî è ñåé÷àñ íå íà ëåñòíèöå èëè íà âåðøèíå ëèôòà, òî îòõîäèì â ñòîðîíó:
7832 if not (KeyPressed(KEY_LEFT
) or KeyPressed(KEY_RIGHT
)) then
7833 if GetAIFlag('FALLINHOLE') = '' then
7834 if (not OnLadder()) or (FObj
.Vel
.Y
>= 0) or (OnTopLift()) then
7840 // Åñëè íà çåìëå è ìîæíî ïîäïðûãíóòü, òî, âîçìîæíî, ïðûãàåì:
7842 CanJumpUp(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*32) and
7846 // Åñëè íà çåìëå è âîçëå äûðû (ãëóáèíà > 2 ðîñòîâ èãðîêà):
7847 if OnGround() and NearHole() then
7848 if NearDeepHole() then // Åñëè ýòî áåçäíà
7850 0..3: Turn(); // Áåæèì îáðàòíî
7851 4: Jump(); // Ïðûãàåì
7852 5: begin // Ïðûãàåì îáðàòíî
7857 else // Ýòî íå áåçäíà è ìû åùå íå ëåòèì òóäà
7858 if GetAIFlag('GOINHOLE') = '' then
7860 0: Turn(); // Íå íóæíî òóäà
7861 1: Jump(); // Âäðóã ïîâåçåò - ïðûãàåì
7862 else // Åñëè ÿìà ñ ãðàíèöåé, òî ïðè ñëó÷àå ìîæíî òóäà ïðûãíóòü
7863 if BorderHole() then
7864 SetAIFlag('GOINHOLE', '1');
7867 // Åñëè íà çåìëå, íî íåêóäà èäòè:
7868 if (not CanRun()) and OnGround() then
7870 // Åñëè ìû íà ëåñòíèöå èëè ìîæíî ïåðåïðûãíóòü, òî ïðûãàåì:
7871 if CanJumpOver() or OnLadder() then
7873 else // èíà÷å ïîïûòàåìñÿ â äðóãóþ ñòîðîíó
7874 if Random(2) = 0 then
7876 if IsSafeTrigger() then
7882 // Îñòàëîñü ìàëî âîçäóõà:
7883 if FAir
< 36 * 2 then
7886 // Âûáèðàåìñÿ èç êèñëîòû, åñëè íåò êîñòþìà, îáîæãëèñü, èëè ìàëî çäîðîâüÿ:
7887 if (FMegaRulez
[MR_SUIT
] < gTime
) and ((FLastHit
= HIT_ACID
) or (Healthy() <= 1)) then
7888 if BodyInAcid(0, 0) then
7892 function TBot
.FullInStep(XInc
, YInc
: Integer): Boolean;
7894 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
7895 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_STEP
, False);
7898 {function TBot.NeedItem(Item: Byte): Byte;
7903 procedure TBot
.SelectWeapon(Dist
: Integer);
7907 function HaveAmmo(weapon
: Byte): Boolean;
7910 WEAPON_PISTOL
: Result
:= FAmmo
[A_BULLETS
] >= 1;
7911 WEAPON_SHOTGUN1
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7912 WEAPON_SHOTGUN2
: Result
:= FAmmo
[A_SHELLS
] >= 2;
7913 WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
] >= 10;
7914 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
] >= 1;
7915 WEAPON_PLASMA
: Result
:= FAmmo
[A_CELLS
] >= 10;
7916 WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
] >= 40;
7917 WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7918 WEAPON_FLAMETHROWER
: Result
:= FAmmo
[A_FUEL
] >= 1;
7919 else Result
:= True;
7924 if Dist
= -1 then Dist
:= BOT_LONGDIST
;
7926 if Dist
> BOT_LONGDIST
then
7927 begin // Äàëüíèé áîé
7929 if FWeapon
[FDifficult
.WeaponPrior
[a
]] and HaveAmmo(FDifficult
.WeaponPrior
[a
]) then
7931 FSelectedWeapon
:= FDifficult
.WeaponPrior
[a
];
7935 else //if Dist > BOT_UNSAFEDIST then
7936 begin // Áëèæíèé áîé
7938 if FWeapon
[FDifficult
.CloseWeaponPrior
[a
]] and HaveAmmo(FDifficult
.CloseWeaponPrior
[a
]) then
7940 FSelectedWeapon
:= FDifficult
.CloseWeaponPrior
[a
];
7947 if FWeapon[FDifficult.SafeWeaponPrior[a]] and HaveAmmo(FDifficult.SafeWeaponPrior[a]) then
7949 FSelectedWeapon := FDifficult.SafeWeaponPrior[a];
7955 function TBot
.PickItem(ItemType
: Byte; force
: Boolean; var remove
: Boolean): Boolean;
7957 Result
:= inherited PickItem(ItemType
, force
, remove
);
7959 if Result
then SetAIFlag('SELECTWEAPON', '1');
7962 function TBot
.Heal(value
: Word; Soft
: Boolean): Boolean;
7964 Result
:= inherited Heal(value
, Soft
);
7967 function TBot
.Healthy(): Byte;
7969 if FMegaRulez
[MR_INVUL
] >= gTime
then Result
:= 3
7970 else if (FHealth
> 80) or ((FHealth
> 50) and (FArmor
> 20)) then Result
:= 3
7971 else if (FHealth
> 50) then Result
:= 2
7972 else if (FHealth
> 20) then Result
:= 1
7976 function TBot
.TargetOnScreen(TX
, TY
: Integer): Boolean;
7978 Result
:= (Abs(FObj
.X
-TX
) <= Trunc(gPlayerScreenSize
.X
*0.6)) and
7979 (Abs(FObj
.Y
-TY
) <= Trunc(gPlayerScreenSize
.Y
*0.6));
7982 procedure TBot
.OnDamage(Angle
: SmallInt);
7990 if (Angle
= 0) or (Angle
= 180) then
7993 if (g_GetUIDType(FLastSpawnerUID
) = UID_PLAYER
) and
7994 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
) then
7996 pla
:= g_Player_Get(FLastSpawnerUID
);
7997 ok
:= not TargetOnScreen(pla
.FObj
.X
+ PLAYER_RECT
.X
,
7998 pla
.FObj
.Y
+ PLAYER_RECT
.Y
);
8001 if (g_GetUIDType(FLastSpawnerUID
) = UID_MONSTER
) and
8002 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
) then
8004 mon
:= g_Monsters_ByUID(FLastSpawnerUID
);
8005 ok
:= not TargetOnScreen(mon
.Obj
.X
+ mon
.Obj
.Rect
.X
,
8006 mon
.Obj
.Y
+ mon
.Obj
.Rect
.Y
);
8011 SetAIFlag('ATTACKLEFT', '1')
8013 SetAIFlag('ATTACKRIGHT', '1');
8017 function TBot
.RunDirection(): TDirection
;
8019 if Abs(Vel
.X
) >= 1 then
8021 if Vel
.X
> 0 then Result
:= TDirection
.D_RIGHT
else Result
:= TDirection
.D_LEFT
;
8023 Result
:= FDirection
;
8026 function TBot
.GetRnd(a
: Byte): Boolean;
8028 if a
= 0 then Result
:= False
8029 else if a
= 255 then Result
:= True
8030 else Result
:= Random(256) > 255-a
;
8033 function TBot
.GetInterval(a
: Byte; radius
: SmallInt): SmallInt;
8035 Result
:= Round((255-a
)/255*radius
*(Random(2)-1));
8039 procedure TDifficult
.save (st
: TStream
);
8041 utils
.writeInt(st
, Byte(DiagFire
));
8042 utils
.writeInt(st
, Byte(InvisFire
));
8043 utils
.writeInt(st
, Byte(DiagPrecision
));
8044 utils
.writeInt(st
, Byte(FlyPrecision
));
8045 utils
.writeInt(st
, Byte(Cover
));
8046 utils
.writeInt(st
, Byte(CloseJump
));
8047 st
.WriteBuffer(WeaponPrior
[Low(WeaponPrior
)], sizeof(WeaponPrior
));
8048 st
.WriteBuffer(CloseWeaponPrior
[Low(CloseWeaponPrior
)], sizeof(CloseWeaponPrior
));
8051 procedure TDifficult
.load (st
: TStream
);
8053 DiagFire
:= utils
.readByte(st
);
8054 InvisFire
:= utils
.readByte(st
);
8055 DiagPrecision
:= utils
.readByte(st
);
8056 FlyPrecision
:= utils
.readByte(st
);
8057 Cover
:= utils
.readByte(st
);
8058 CloseJump
:= utils
.readByte(st
);
8059 st
.ReadBuffer(WeaponPrior
[Low(WeaponPrior
)], sizeof(WeaponPrior
));
8060 st
.ReadBuffer(CloseWeaponPrior
[Low(CloseWeaponPrior
)], sizeof(CloseWeaponPrior
));
8064 procedure TBot
.SaveState (st
: TStream
);
8069 inherited SaveState(st
);
8070 utils
.writeSign(st
, 'BOT0');
8072 utils
.writeInt(st
, Byte(FSelectedWeapon
));
8074 utils
.writeInt(st
, Word(FTargetUID
));
8075 // Âðåìÿ ïîòåðè öåëè
8076 utils
.writeInt(st
, LongWord(FLastVisible
));
8077 // Êîëè÷åñòâî ôëàãîâ ÈÈ
8078 dw
:= Length(FAIFlags
);
8079 utils
.writeInt(st
, LongInt(dw
));
8081 for i
:= 0 to dw
-1 do
8083 utils
.writeStr(st
, FAIFlags
[i
].Name
, 20);
8084 utils
.writeStr(st
, FAIFlags
[i
].Value
, 20);
8086 // Íàñòðîéêè ñëîæíîñòè
8087 FDifficult
.save(st
);
8091 procedure TBot
.LoadState (st
: TStream
);
8096 inherited LoadState(st
);
8097 if not utils
.checkSign(st
, 'BOT0') then raise XStreamError
.Create('invalid bot signature');
8099 FSelectedWeapon
:= utils
.readByte(st
);
8101 FTargetUID
:= utils
.readWord(st
);
8102 // Âðåìÿ ïîòåðè öåëè
8103 FLastVisible
:= utils
.readLongWord(st
);
8104 // Êîëè÷åñòâî ôëàãîâ ÈÈ
8105 dw
:= utils
.readLongInt(st
);
8106 if (dw
< 0) or (dw
> 16384) then raise XStreamError
.Create('invalid number of bot AI flags');
8107 SetLength(FAIFlags
, dw
);
8109 for i
:= 0 to dw
-1 do
8111 FAIFlags
[i
].Name
:= utils
.readStr(st
, 20);
8112 FAIFlags
[i
].Value
:= utils
.readStr(st
, 20);
8114 // Íàñòðîéêè ñëîæíîñòè
8115 FDifficult
.load(st
);
8120 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');
8121 conRegVar('player_indicator_style', @gPlayerIndicatorStyle
, 'Visual appearance of indicator', 'Visual appearance of indicator');