1 (* Copyright (C) Doom 2D: Forever Developers
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, version 3 of the License ONLY.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 {$INCLUDE ../shared/a_modes.inc}
23 {$IFDEF USE_MEMPOOL}mempool
,{$ENDIF}
24 e_graphics
, g_playermodel
, g_basic
, g_textures
,
25 g_weapons
, g_phys
, g_sound
, g_saveload
, MAPDEF
,
61 AmmoLimits
: Array [0..1] of Array [A_BULLETS
..A_HIGH
] of Word =
62 ((200, 50, 50, 300, 100),
63 (400, 100, 100, 600, 200));
84 ANGLE_NONE
= Low(SmallInt);
86 CORPSE_STATE_REMOVEME
= 0;
87 CORPSE_STATE_NORMAL
= 1;
88 CORPSE_STATE_MESS
= 2;
90 PLAYER_RECT
: TRectWH
= (X
:15; Y
:12; Width
:34; Height
:52);
91 PLAYER_RECT_CX
= 15+(34 div 2);
92 PLAYER_RECT_CY
= 12+(52 div 2);
93 PLAYER_CORPSERECT
: TRectWH
= (X
:15; Y
:48; Width
:34; Height
:16);
96 PLAYER_HP_LIMIT
= 200;
98 PLAYER_AP_LIMIT
= 200;
102 PLAYER_BURN_TIME
= 110;
104 PLAYER1_DEF_COLOR
: TRGB
= (R
:64; G
:175; B
:48);
105 PLAYER2_DEF_COLOR
: TRGB
= (R
:96; G
:96; B
:96);
123 TPlayerStatArray
= Array of TPlayerStat
;
125 TPlayerSavedState
= record
133 Ammo
: Array [A_BULLETS
..A_HIGH
] of Word;
134 MaxAmmo
: Array [A_BULLETS
..A_HIGH
] of Word;
135 Weapon
: Array [WP_FIRST
..WP_LAST
] of Boolean;
136 Rulez
: Set of R_ITEM_BACKPACK
..R_BERSERK
;
145 TPlayer
= class{$IFDEF USE_MEMPOOL}(TPoolObject
){$ENDIF}
153 FDirection
: TDirection
;
161 FMonsterKills
: Integer;
167 FCanJetpack
: Boolean;
173 FNextWeapDelay
: Byte; // frames
174 FBFGFireCounter
: SmallInt;
175 FLastSpawnerUID
: Word;
179 FSpectatePlayer
: Integer;
180 FFirePainTime
: Integer;
183 FSavedStateNum
: Integer;
185 FModel
: TPlayerModel
;
186 FPunchAnim
: TAnimation
;
189 FActionForce
: Boolean;
190 FActionChanged
: Boolean;
192 FFireAngle
: SmallInt;
196 FShellTimer
: Integer;
198 FSawSound
: TPlayableSound
;
199 FSawSoundIdle
: TPlayableSound
;
200 FSawSoundHit
: TPlayableSound
;
201 FSawSoundSelect
: TPlayableSound
;
202 FFlameSoundOn
: TPlayableSound
;
203 FFlameSoundOff
: TPlayableSound
;
204 FFlameSoundWork
: TPlayableSound
;
205 FJetSoundOn
: TPlayableSound
;
206 FJetSoundOff
: TPlayableSound
;
207 FJetSoundFly
: TPlayableSound
;
211 FJustTeleported
: Boolean;
213 mEDamageType
: Integer;
216 function CollideLevel(XInc
, YInc
: Integer): Boolean;
217 function StayOnStep(XInc
, YInc
: Integer): Boolean;
218 function HeadInLiquid(XInc
, YInc
: Integer): Boolean;
219 function BodyInLiquid(XInc
, YInc
: Integer): Boolean;
220 function BodyInAcid(XInc
, YInc
: Integer): Boolean;
221 function FullInLift(XInc
, YInc
: Integer): Integer;
222 {procedure CollideItem();}
223 procedure FlySmoke(Times
: DWORD
= 1);
224 procedure OnFireFlame(Times
: DWORD
= 1);
225 function GetAmmoByWeapon(Weapon
: Byte): Word;
226 procedure SetAction(Action
: Byte; Force
: Boolean = False);
227 procedure OnDamage(Angle
: SmallInt); virtual;
228 function firediry(): Integer;
231 procedure Run(Direction
: TDirection
);
232 procedure NextWeapon();
233 procedure PrevWeapon();
240 function getNextWeaponIndex (): Byte; // return 255 for "no switch"
241 procedure resetWeaponQueue ();
242 function hasAmmoForWeapon (weapon
: Byte): Boolean;
243 function shouldSwitch (weapon
: Byte; hadWeapon
: Boolean) : Boolean;
245 procedure doDamage (v
: Integer);
247 function refreshCorpse(): Boolean;
250 FDamageBuffer
: Integer;
252 FAmmo
: Array [A_BULLETS
..A_HIGH
] of Word;
253 FMaxAmmo
: Array [A_BULLETS
..A_HIGH
] of Word;
254 FWeapon
: Array [WP_FIRST
..WP_LAST
] of Boolean;
255 FRulez
: Set of R_ITEM_BACKPACK
..R_BERSERK
;
257 FMegaRulez
: Array [MR_SUIT
..MR_MAX
] of DWORD
;
258 FReloading
: Array [WP_FIRST
..WP_LAST
] of Word;
259 FTime
: Array [T_RESPAWN
..T_FLAGCAP
] of DWORD
;
260 FKeys
: Array [KEY_LEFT
..KEY_CHAT
] of TKeyState
;
261 FWeapSwitchMode
: Byte;
262 FWeapPreferences
: Array [WP_FIRST
.. WP_LAST
+1] of Byte;
263 FSwitchToEmpty
: Byte;
266 FPreferredTeam
: Byte;
269 FWantsInGame
: Boolean;
274 FActualModelName
: string;
281 FSpawnInvul
: Integer;
283 FWaitForFirstSpawn
: Boolean; // set to `true` in server, used to spawn a player on first full state request
286 // debug: viewport offset
287 viewPortX
, viewPortY
, viewPortW
, viewPortH
: Integer;
289 function isValidViewPort (): Boolean; inline;
291 constructor Create(); virtual;
292 destructor Destroy(); override;
293 procedure Respawn(Silent
: Boolean; Force
: Boolean = False); virtual;
294 function GetRespawnPoint(): Byte;
295 procedure PressKey(Key
: Byte; Time
: Word = 1);
296 procedure ReleaseKeys();
297 procedure SetModel(ModelName
: String);
298 procedure SetColor(Color
: TRGB
);
299 function GetColor(): TRGB
;
300 procedure SetWeapon(W
: Byte);
301 function IsKeyPressed(K
: Byte): Boolean;
302 function GetKeys(): Byte;
303 function PickItem(ItemType
: Byte; arespawn
: Boolean; var remove
: Boolean): Boolean; virtual;
304 procedure SetWeaponPrefs(Prefs
: Array of Byte);
305 procedure SetWeaponPref(Weapon
, Pref
: Byte);
306 function GetWeaponPref(Weapon
: Byte) : Byte;
307 function GetMorePrefered() : Byte;
308 function MaySwitch(Weapon
: Byte) : Boolean;
309 function Collide(X
, Y
: Integer; Width
, Height
: Word): Boolean; overload
;
310 function Collide(Panel
: TPanel
): Boolean; overload
;
311 function Collide(X
, Y
: Integer): Boolean; overload
;
312 procedure SetDirection(Direction
: TDirection
);
313 procedure GetSecret();
314 function TeleportTo(X
, Y
: Integer; silent
: Boolean; dir
: Byte): Boolean;
316 procedure Push(vx
, vy
: Integer);
317 procedure ChangeModel(ModelName
: String);
318 procedure SwitchTeam
;
319 procedure ChangeTeam(Team
: Byte);
321 function GetFlag(Flag
: Byte): Boolean;
322 procedure SetFlag(Flag
: Byte);
323 function DropFlag(Silent
: Boolean = True; DoThrow
: Boolean = False): Boolean;
324 function TryDropFlag(): Boolean;
325 procedure AllRulez(Health
: Boolean);
326 procedure RestoreHealthArmor();
327 procedure FragCombo();
328 procedure GiveItem(ItemType
: Byte);
329 procedure Damage(value
: Word; SpawnerUID
: Word; vx
, vy
: Integer; t
: Byte); virtual;
330 function Heal(value
: Word; Soft
: Boolean): Boolean; virtual;
331 procedure MakeBloodVector(Count
: Word; VelX
, VelY
: Integer);
332 procedure MakeBloodSimple(Count
: Word);
333 procedure Kill(KillType
: Byte; SpawnerUID
: Word; t
: Byte);
334 procedure Reset(Force
: Boolean);
335 procedure Spectate(NoMove
: Boolean = False);
336 procedure SwitchNoClip
;
337 procedure SoftReset();
338 procedure Draw(); virtual;
339 procedure DrawPain();
340 procedure DrawPickup();
341 procedure DrawRulez();
343 procedure DrawIndicator(Color
: TRGB
);
344 procedure DrawBubble();
346 procedure PreUpdate();
347 procedure Update(); virtual;
348 procedure RememberState();
349 procedure RecallState();
350 procedure SaveState (st
: TStream
); virtual;
351 procedure LoadState (st
: TStream
); virtual;
352 procedure PauseSounds(Enable
: Boolean);
353 procedure NetFire(Wpn
: Byte; X
, Y
, AX
, AY
: Integer; WID
: Integer = -1);
354 procedure DoLerp(Level
: Integer = 2);
355 procedure SetLerp(XTo
, YTo
: Integer);
356 procedure ProcessWeaponAction(Action
: Byte);
357 procedure QueueWeaponSwitch(Weapon
: Byte);
358 procedure RealizeCurrentWeapon();
362 procedure JetpackOff
;
363 procedure CatchFire(Attacker
: Word; Timeout
: Integer = PLAYER_BURN_TIME
);
365 //WARNING! this does nothing for now, but still call it!
366 procedure positionChanged (); //WARNING! call this after entity position was changed, or coldet will not work right!
368 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
369 procedure moveBy (dx
, dy
: Integer); inline;
371 function getCameraObj(): TObj
;
374 property Vel
: TPoint2i read FObj
.Vel
;
375 property Obj
: TObj read FObj
;
377 property Name
: String read FName write FName
;
378 property Model
: TPlayerModel read FModel
;
379 property Health
: Integer read FHealth write FHealth
;
380 property Lives
: Byte read FLives write FLives
;
381 property Armor
: Integer read FArmor write FArmor
;
382 property Air
: Integer read FAir write FAir
;
383 property JetFuel
: Integer read FJetFuel write FJetFuel
;
384 property Frags
: Integer read FFrags write FFrags
;
385 property Death
: Integer read FDeath write FDeath
;
386 property Kills
: Integer read FKills write FKills
;
387 property CurrWeap
: Byte read FCurrWeap write FCurrWeap
;
388 property WeapSwitchMode
: Byte read FWeapSwitchMode write FWeapSwitchMode
;
389 property SwitchToEmpty
: Byte read FSwitchToEmpty write FSwitchToEmpty
;
390 property SkipFist
: Byte read FSkipFist write FSkipFist
;
391 property MonsterKills
: Integer read FMonsterKills write FMonsterKills
;
392 property Secrets
: Integer read FSecrets
;
393 property GodMode
: Boolean read FGodMode write FGodMode
;
394 property NoTarget
: Boolean read FNoTarget write FNoTarget
;
395 property NoReload
: Boolean read FNoReload write FNoReload
;
396 property alive
: Boolean read FAlive write FAlive
;
397 property Flag
: Byte read FFlag
;
398 property Team
: Byte read FTeam write FTeam
;
399 property Direction
: TDirection read FDirection
;
400 property GameX
: Integer read FObj
.X write FObj
.X
;
401 property GameY
: Integer read FObj
.Y write FObj
.Y
;
402 property GameVelX
: Integer read FObj
.Vel
.X write FObj
.Vel
.X
;
403 property GameVelY
: Integer read FObj
.Vel
.Y write FObj
.Vel
.Y
;
404 property GameAccelX
: Integer read FObj
.Accel
.X write FObj
.Accel
.X
;
405 property GameAccelY
: Integer read FObj
.Accel
.Y write FObj
.Accel
.Y
;
406 property IncCam
: Integer read FIncCam write FIncCam
;
407 property IncCamOld
: Integer read FIncCamOld write FIncCamOld
;
408 property SlopeOld
: Integer read FSlopeOld write FSlopeOld
;
409 property UID
: Word read FUID write FUID
;
410 property JustTeleported
: Boolean read FJustTeleported write FJustTeleported
;
411 property NetTime
: LongWord read FNetTime write FNetTime
;
414 property eName
: String read FName write FName
;
415 property eHealth
: Integer read FHealth write FHealth
;
416 property eLives
: Byte read FLives write FLives
;
417 property eArmor
: Integer read FArmor write FArmor
;
418 property eAir
: Integer read FAir write FAir
;
419 property eJetFuel
: Integer read FJetFuel write FJetFuel
;
420 property eFrags
: Integer read FFrags write FFrags
;
421 property eDeath
: Integer read FDeath write FDeath
;
422 property eKills
: Integer read FKills write FKills
;
423 property eCurrWeap
: Byte read FCurrWeap write FCurrWeap
;
424 property eMonsterKills
: Integer read FMonsterKills write FMonsterKills
;
425 property eSecrets
: Integer read FSecrets write FSecrets
;
426 property eGodMode
: Boolean read FGodMode write FGodMode
;
427 property eNoTarget
: Boolean read FNoTarget write FNoTarget
;
428 property eNoReload
: Boolean read FNoReload write FNoReload
;
429 property eAlive
: Boolean read FAlive write FAlive
;
430 property eFlag
: Byte read FFlag
;
431 property eTeam
: Byte read FTeam write FTeam
;
432 property eDirection
: TDirection read FDirection
;
433 property eGameX
: Integer read FObj
.X write FObj
.X
;
434 property eGameY
: Integer read FObj
.Y write FObj
.Y
;
435 property eGameVelX
: Integer read FObj
.Vel
.X write FObj
.Vel
.X
;
436 property eGameVelY
: Integer read FObj
.Vel
.Y write FObj
.Vel
.Y
;
437 property eGameAccelX
: Integer read FObj
.Accel
.X write FObj
.Accel
.X
;
438 property eGameAccelY
: Integer read FObj
.Accel
.Y write FObj
.Accel
.Y
;
439 property eIncCam
: Integer read FIncCam write FIncCam
;
440 property eUID
: Word read FUID
;
441 property eJustTeleported
: Boolean read FJustTeleported
;
442 property eNetTime
: LongWord read FNetTime
;
444 // set this before assigning something to `eDamage`
445 property eDamageType
: Integer read mEDamageType write mEDamageType
;
446 property eDamage
: Integer write doDamage
;
457 WeaponPrior
: packed array [WP_FIRST
..WP_LAST
] of Byte;
458 CloseWeaponPrior
: packed array [WP_FIRST
..WP_LAST
] of Byte;
459 //SafeWeaponPrior: Array [WP_FIRST..WP_LAST] of Byte;
462 procedure save (st
: TStream
);
463 procedure load (st
: TStream
);
471 TBot
= class(TPlayer
)
473 FSelectedWeapon
: Byte;
476 FAIFlags
: Array of TAIFlag
;
477 FDifficult
: TDifficult
;
479 function GetRnd(a
: Byte): Boolean;
480 function GetInterval(a
: Byte; radius
: SmallInt): SmallInt;
481 function RunDirection(): TDirection
;
482 function FullInStep(XInc
, YInc
: Integer): Boolean;
483 //function NeedItem(Item: Byte): Byte;
484 procedure SelectWeapon(Dist
: Integer);
485 procedure SetAIFlag(aName
, fValue
: String20
);
486 function GetAIFlag(aName
: String20
): String20
;
487 procedure RemoveAIFlag(aName
: String20
);
488 function Healthy(): Byte;
489 procedure UpdateMove();
490 procedure UpdateCombat();
491 function KeyPressed(Key
: Word): Boolean;
492 procedure ReleaseKey(Key
: Byte);
493 function TargetOnScreen(TX
, TY
: Integer): Boolean;
494 procedure OnDamage(Angle
: SmallInt); override;
497 procedure Respawn(Silent
: Boolean; Force
: Boolean = False); override;
498 constructor Create(); override;
499 destructor Destroy(); override;
500 procedure Draw(); override;
501 function PickItem(ItemType
: Byte; force
: Boolean; var remove
: Boolean): Boolean; override;
502 function Heal(value
: Word; Soft
: Boolean): Boolean; override;
503 procedure Update(); override;
504 procedure SaveState (st
: TStream
); override;
505 procedure LoadState (st
: TStream
); override;
517 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
518 procedure moveBy (dx
, dy
: Integer); inline;
520 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
534 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
535 procedure moveBy (dx
, dy
: Integer); inline;
537 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
540 TCorpse
= class{$IFDEF USE_MEMPOOL}(TPoolObject
){$ENDIF}
549 FAnimation
: TAnimation
;
550 FAnimationMask
: TAnimation
;
553 constructor Create(X
, Y
: Integer; ModelName
: String; aMess
: Boolean);
554 destructor Destroy(); override;
555 procedure Damage(Value
: Word; SpawnerUID
: Word; vx
, vy
: Integer);
558 procedure SaveState (st
: TStream
);
559 procedure LoadState (st
: TStream
);
561 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
562 procedure moveBy (dx
, dy
: Integer); inline;
564 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
566 function ObjPtr (): PObj
; inline;
568 property Obj
: TObj read FObj
; // copies object
569 property State
: Byte read FState
;
570 property Mess
: Boolean read FMess
;
573 TTeamStat
= Array [TEAM_RED
..TEAM_BLUE
] of
579 gPlayers
: Array of TPlayer
;
580 gCorpses
: Array of TCorpse
;
581 gGibs
: Array of TGib
;
582 gShells
: Array of TShell
;
583 gTeamStat
: TTeamStat
;
584 gFly
: Boolean = False;
585 gAimLine
: Boolean = False;
586 gChatBubble
: Integer = 0;
587 gPlayerIndicator
: Integer = 1;
588 gPlayerIndicatorStyle
: Integer = 0;
590 gSpectLatchPID1
: Word = 0;
591 gSpectLatchPID2
: Word = 0;
592 MAX_RUNVEL
: Integer = 8;
593 VEL_JUMP
: Integer = 10;
594 SHELL_TIMEOUT
: Cardinal = 60000;
596 function Lerp(X
, Y
, Factor
: Integer): Integer;
598 procedure g_Gibs_SetMax(Count
: Word);
599 function g_Gibs_GetMax(): Word;
600 procedure g_Corpses_SetMax(Count
: Word);
601 function g_Corpses_GetMax(): Word;
602 procedure g_Shells_SetMax(Count
: Word);
603 function g_Shells_GetMax(): Word;
605 procedure g_Player_Init();
606 procedure g_Player_Free();
607 function g_Player_Create(ModelName
: String; Color
: TRGB
; Team
: Byte; Bot
: Boolean): Word;
608 function g_Player_CreateFromState (st
: TStream
): Word;
609 procedure g_Player_Remove(UID
: Word);
610 procedure g_Player_ResetTeams();
611 procedure g_Player_PreUpdate();
612 procedure g_Player_UpdateAll();
613 procedure g_Player_DrawAll();
614 procedure g_Player_DrawDebug(p
: TPlayer
);
615 procedure g_Player_DrawHealth();
616 procedure g_Player_RememberAll();
617 procedure g_Player_ResetAll(Force
, Silent
: Boolean);
618 function g_Player_Get(UID
: Word): TPlayer
;
619 function g_Player_GetCount(): Byte;
620 function g_Player_GetStats(): TPlayerStatArray
;
621 function g_Player_ValidName(Name
: String): Boolean;
622 function g_Player_CreateCorpse(Player
: TPlayer
): Integer;
623 procedure g_Player_CreateGibs(fX
, fY
: Integer; ModelName
: String; fColor
: TRGB
);
624 procedure g_Player_CreateShell(fX
, fY
, dX
, dY
: Integer; T
: Byte);
625 procedure g_Player_UpdatePhysicalObjects();
626 procedure g_Player_DrawCorpses();
627 procedure g_Player_DrawShells();
628 procedure g_Player_RemoveAllCorpses();
629 procedure g_Player_Corpses_SaveState (st
: TStream
);
630 procedure g_Player_Corpses_LoadState (st
: TStream
);
631 procedure g_Player_ResetReady();
632 procedure g_Bot_Add(Team
, Difficult
: Byte; Handicap
: Integer = 100);
633 procedure g_Bot_AddList(Team
: Byte; lname
: ShortString; num
: Integer = -1; Handicap
: Integer = 100);
634 procedure g_Bot_MixNames();
635 procedure g_Bot_RemoveAll();
640 {$INCLUDE ../nogl/noGLuses.inc}
641 {$IFDEF ENABLE_HOLMES}
644 e_log
, g_map
, g_items
, g_console
, g_gfx
, Math
,
645 g_options
, g_triggers
, g_menu
, g_game
, g_grid
, e_res
,
646 wadreader
, g_main
, g_monsters
, CONFIG
, g_language
,
647 g_net
, g_netmsg
, g_window
,
650 const PLR_SAVE_VERSION
= 0;
660 diag_precision
: Byte;
664 w_prior1
: Array [WP_FIRST
..WP_LAST
] of Byte;
665 w_prior2
: Array [WP_FIRST
..WP_LAST
] of Byte;
666 w_prior3
: Array [WP_FIRST
..WP_LAST
] of Byte;
670 TIME_RESPAWN1
= 1500;
671 TIME_RESPAWN2
= 2000;
672 TIME_RESPAWN3
= 3000;
675 JET_MAX
= 540; // ~30 sec
676 PLAYER_SUIT_TIME
= 30000;
677 PLAYER_INVUL_TIME
= 30000;
678 PLAYER_INVIS_TIME
= 35000;
679 FRAG_COMBO_TIME
= 3000;
683 ANGLE_RIGHTDOWN
= -35;
685 ANGLE_LEFTDOWN
= -145;
686 PLAYER_HEADRECT
: TRectWH
= (X
:24; Y
:12; Width
:20; Height
:12);
687 WEAPONPOINT
: Array [TDirection
] of TDFPoint
= ((X
:16; Y
:32), (X
:47; Y
:32));
690 BOT_UNSAFEDIST
= 128;
691 TEAMCOLOR
: Array [TEAM_RED
..TEAM_BLUE
] of TRGB
= ((R
:255; G
:0; B
:0),
693 DIFFICULT_EASY
: TDifficult
= (DiagFire
: 32; InvisFire
: 32; DiagPrecision
: 32;
694 FlyPrecision
: 32; Cover
: 32; CloseJump
: 32;
695 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
696 DIFFICULT_MEDIUM
: TDifficult
= (DiagFire
: 127; InvisFire
: 127; DiagPrecision
: 127;
697 FlyPrecision
: 127; Cover
: 127; CloseJump
: 127;
698 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
699 DIFFICULT_HARD
: TDifficult
= (DiagFire
: 255; InvisFire
: 255; DiagPrecision
: 255;
700 FlyPrecision
: 255; Cover
: 255; CloseJump
: 255;
701 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
702 WEAPON_PRIOR1
: Array [WP_FIRST
..WP_LAST
] of Byte =
703 (WEAPON_FLAMETHROWER
, WEAPON_SUPERPULEMET
,
704 WEAPON_SHOTGUN2
, WEAPON_SHOTGUN1
,
705 WEAPON_CHAINGUN
, WEAPON_PLASMA
, WEAPON_ROCKETLAUNCHER
,
706 WEAPON_BFG
, WEAPON_PISTOL
, WEAPON_SAW
, WEAPON_KASTET
);
707 WEAPON_PRIOR2
: Array [WP_FIRST
..WP_LAST
] of Byte =
708 (WEAPON_FLAMETHROWER
, WEAPON_SUPERPULEMET
,
709 WEAPON_BFG
, WEAPON_ROCKETLAUNCHER
,
710 WEAPON_SHOTGUN2
, WEAPON_PLASMA
, WEAPON_SHOTGUN1
,
711 WEAPON_CHAINGUN
, WEAPON_PISTOL
, WEAPON_SAW
, WEAPON_KASTET
);
712 //WEAPON_PRIOR3: Array [WP_FIRST..WP_LAST] of Byte =
713 // (WEAPON_FLAMETHROWER, WEAPON_SUPERPULEMET,
714 // WEAPON_BFG, WEAPON_PLASMA, WEAPON_SHOTGUN2,
715 // WEAPON_CHAINGUN, WEAPON_SHOTGUN1, WEAPON_SAW,
716 // WEAPON_ROCKETLAUNCHER, WEAPON_PISTOL, WEAPON_KASTET);
717 WEAPON_RELOAD
: Array [WP_FIRST
..WP_LAST
] of Byte =
718 (5, 2, 6, 18, 36, 2, 12, 2, 14, 2, 2);
720 PLAYER_SIGNATURE
= $52594C50; // 'PLYR'
721 CORPSE_SIGNATURE
= $50524F43; // 'CORP'
723 BOTNAMES_FILENAME
= 'botnames.txt';
724 BOTLIST_FILENAME
= 'botlist.txt';
728 MaxCorpses
: Word = 20;
729 MaxShells
: Word = 300;
730 CurrentGib
: Integer = 0;
731 CurrentShell
: Integer = 0;
732 BotNames
: Array of String;
733 BotList
: Array of TBotProfile
;
734 SavedStates
: Array of TPlayerSavedState
;
737 function Lerp(X
, Y
, Factor
: Integer): Integer;
739 Result
:= X
+ ((Y
- X
) div Factor
);
742 function SameTeam(UID1
, UID2
: Word): Boolean;
746 if (UID1
> UID_MAX_PLAYER
) or (UID1
<= UID_MAX_GAME
) or
747 (UID2
> UID_MAX_PLAYER
) or (UID2
<= UID_MAX_GAME
) then Exit
;
749 if (g_Player_Get(UID1
) = nil) or (g_Player_Get(UID2
) = nil) then Exit
;
751 if ((g_Player_Get(UID1
).Team
= TEAM_NONE
) or
752 (g_Player_Get(UID2
).Team
= TEAM_NONE
)) then Exit
;
754 Result
:= g_Player_Get(UID1
).FTeam
= g_Player_Get(UID2
).FTeam
;
757 procedure g_Gibs_SetMax(Count
: Word);
760 SetLength(gGibs
, Count
);
762 if CurrentGib
>= Count
then
766 function g_Gibs_GetMax(): Word;
771 procedure g_Shells_SetMax(Count
: Word);
774 SetLength(gShells
, Count
);
776 if CurrentShell
>= Count
then
780 function g_Shells_GetMax(): Word;
786 procedure g_Corpses_SetMax(Count
: Word);
789 SetLength(gCorpses
, Count
);
792 function g_Corpses_GetMax(): Word;
794 Result
:= MaxCorpses
;
797 function g_Player_Create(ModelName
: String; Color
: TRGB
; Team
: Byte; Bot
: Boolean): Word;
807 // Åñòü ëè ìåñòî â gPlayers:
808 if gPlayers
<> nil then
809 for a
:= 0 to High(gPlayers
) do
810 if gPlayers
[a
] = nil then
816 // Íåò ìåñòà - ðàñøèðÿåì gPlayers:
819 SetLength(gPlayers
, Length(gPlayers
)+1);
823 // Ñîçäàåì îáúåêò èãðîêà:
825 gPlayers
[a
] := TBot
.Create()
827 gPlayers
[a
] := TPlayer
.Create();
830 gPlayers
[a
].FActualModelName
:= ModelName
;
831 gPlayers
[a
].SetModel(ModelName
);
833 // Íåò ìîäåëè - ñîçäàíèå íå âîçìîæíî:
834 if gPlayers
[a
].FModel
= nil then
838 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], [ModelName
]));
842 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
843 if Random(2) = 0 then
847 gPlayers
[a
].FPreferredTeam
:= Team
;
849 case gGameSettings
.GameMode
of
850 GM_DM
: gPlayers
[a
].FTeam
:= TEAM_NONE
;
852 GM_CTF
: gPlayers
[a
].FTeam
:= gPlayers
[a
].FPreferredTeam
;
854 GM_COOP
: gPlayers
[a
].FTeam
:= TEAM_COOP
;
857 // Åñëè êîìàíäíàÿ èãðà - êðàñèì ìîäåëü â öâåò êîìàíäû:
858 gPlayers
[a
].FColor
:= Color
;
859 if gPlayers
[a
].FTeam
in [TEAM_RED
, TEAM_BLUE
] then
860 gPlayers
[a
].FModel
.Color
:= TEAMCOLOR
[gPlayers
[a
].FTeam
]
862 gPlayers
[a
].FModel
.Color
:= Color
;
864 gPlayers
[a
].FUID
:= g_CreateUID(UID_PLAYER
);
865 gPlayers
[a
].FAlive
:= False;
867 Result
:= gPlayers
[a
].FUID
;
870 function g_Player_CreateFromState (st
: TStream
): Word;
871 var a
: Integer; ok
, Bot
: Boolean; pos
: Int64;
875 // check signature and entity type
877 if not utils
.checkSign(st
, 'PLYR') then raise XStreamError
.Create('invalid player signature');
878 if (utils
.readByte(st
) <> PLR_SAVE_VERSION
) then raise XStreamError
.Create('invalid player version');
879 Bot
:= utils
.readBool(st
);
882 // find free player slot
884 for a
:= 0 to High(gPlayers
) do
885 if gPlayers
[a
] = nil then
891 // allocate player slot
894 SetLength(gPlayers
, Length(gPlayers
)+1);
898 // create entity and load state
900 gPlayers
[a
] := TBot
.Create()
902 gPlayers
[a
] := TPlayer
.Create();
903 gPlayers
[a
].FPhysics
:= True; // ???
904 gPlayers
[a
].LoadState(st
);
906 result
:= gPlayers
[a
].FUID
;
910 procedure g_Player_ResetTeams();
914 if g_Game_IsClient
then
916 if gPlayers
= nil then
918 for a
:= Low(gPlayers
) to High(gPlayers
) do
919 if gPlayers
[a
] <> nil then
920 case gGameSettings
.GameMode
of
922 gPlayers
[a
].ChangeTeam(TEAM_NONE
);
924 if not (gPlayers
[a
].Team
in [TEAM_RED
, TEAM_BLUE
]) then
925 if gPlayers
[a
].FPreferredTeam
in [TEAM_RED
, TEAM_BLUE
] then
926 gPlayers
[a
].ChangeTeam(gPlayers
[a
].FPreferredTeam
)
929 gPlayers
[a
].ChangeTeam(TEAM_RED
)
931 gPlayers
[a
].ChangeTeam(TEAM_BLUE
);
934 gPlayers
[a
].ChangeTeam(TEAM_COOP
);
938 procedure g_Bot_Add(Team
, Difficult
: Byte; Handicap
: Integer = 100);
941 _name
, _model
: String;
944 if not g_Game_IsServer
then Exit
;
946 // Ñïèñîê íàçâàíèé ìîäåëåé:
947 m
:= g_PlayerModel_GetNames();
952 if (gGameSettings
.GameType
= GT_SINGLE
) or (gGameSettings
.GameMode
= GM_COOP
) then
953 Team
:= TEAM_COOP
// COOP
955 if gGameSettings
.GameMode
= GM_DM
then
956 Team
:= TEAM_NONE
// DM
958 if Team
= TEAM_NONE
then // CTF / TDM
960 // Àâòîáàëàíñ êîìàíä:
964 for a
:= 0 to High(gPlayers
) do
965 if gPlayers
[a
] <> nil then
967 if gPlayers
[a
].Team
= TEAM_RED
then
970 if gPlayers
[a
].Team
= TEAM_BLUE
then
980 if Random(2) = 0 then
986 // Âûáèðàåì áîòó èìÿ:
988 if BotNames
<> nil then
989 for a
:= 0 to High(BotNames
) do
990 if g_Player_ValidName(BotNames
[a
]) then
992 _name
:= BotNames
[a
];
996 // Âûáèðàåì ñëó÷àéíóþ ìîäåëü:
997 _model
:= m
[Random(Length(m
))];
1000 with g_Player_Get(g_Player_Create(_model
,
1001 _RGB(Min(Random(9)*32, 255),
1002 Min(Random(9)*32, 255),
1003 Min(Random(9)*32, 255)),
1004 Team
, True)) as TBot
do
1006 // Åñëè èìåíè íåò, äåëàåì åãî èç UID áîòà
1008 Name
:= Format('DFBOT%.5d', [UID
])
1013 1: FDifficult
:= DIFFICULT_EASY
;
1014 2: FDifficult
:= DIFFICULT_MEDIUM
;
1015 else FDifficult
:= DIFFICULT_HARD
;
1018 for a
:= WP_FIRST
to WP_LAST
do
1020 FDifficult
.WeaponPrior
[a
] := WEAPON_PRIOR1
[a
];
1021 FDifficult
.CloseWeaponPrior
[a
] := WEAPON_PRIOR2
[a
];
1022 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
1025 FHandicap
:= Handicap
;
1027 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [Name
]), True);
1029 if g_Game_IsNet
then MH_SEND_PlayerCreate(UID
);
1030 if g_Game_IsServer
and (gGameSettings
.MaxLives
> 0) then
1035 procedure g_Bot_AddList(Team
: Byte; lName
: ShortString; num
: Integer = -1; Handicap
: Integer = 100);
1038 _name
, _model
: String;
1041 if not g_Game_IsServer
then Exit
;
1043 // Ñïèñîê íàçâàíèé ìîäåëåé:
1044 m
:= g_PlayerModel_GetNames();
1049 if (gGameSettings
.GameType
= GT_SINGLE
) or (gGameSettings
.GameMode
= GM_COOP
) then
1050 Team
:= TEAM_COOP
// COOP
1052 if gGameSettings
.GameMode
= GM_DM
then
1053 Team
:= TEAM_NONE
// DM
1055 if Team
= TEAM_NONE
then
1056 Team
:= BotList
[num
].team
; // CTF / TDM
1058 // Âûáèðàåì íàñòðîéêè áîòà èç ñïèñêà ïî íîìåðó èëè èìåíè:
1059 lName
:= AnsiLowerCase(lName
);
1060 if (num
< 0) or (num
> Length(BotList
)-1) then
1062 if (num
= -1) and (lName
<> '') and (BotList
<> nil) then
1063 for a
:= 0 to High(BotList
) do
1064 if AnsiLowerCase(BotList
[a
].name
) = lName
then
1073 _name
:= BotList
[num
].name
;
1074 // Çàíÿòî - âûáèðàåì ñëó÷àéíîå:
1075 if not g_Player_ValidName(_name
) then
1077 _name
:= Format('DFBOT%.2d', [Random(100)]);
1078 until g_Player_ValidName(_name
);
1081 _model
:= BotList
[num
].model
;
1082 // Íåò òàêîé - âûáèðàåì ñëó÷àéíóþ:
1083 if not InSArray(_model
, m
) then
1084 _model
:= m
[Random(Length(m
))];
1087 with g_Player_Get(g_Player_Create(_model
, BotList
[num
].color
, Team
, True)) as TBot
do
1091 FDifficult
.DiagFire
:= BotList
[num
].diag_fire
;
1092 FDifficult
.InvisFire
:= BotList
[num
].invis_fire
;
1093 FDifficult
.DiagPrecision
:= BotList
[num
].diag_precision
;
1094 FDifficult
.FlyPrecision
:= BotList
[num
].fly_precision
;
1095 FDifficult
.Cover
:= BotList
[num
].cover
;
1096 FDifficult
.CloseJump
:= BotList
[num
].close_jump
;
1098 FHandicap
:= Handicap
;
1100 for a
:= WP_FIRST
to WP_LAST
do
1102 FDifficult
.WeaponPrior
[a
] := BotList
[num
].w_prior1
[a
];
1103 FDifficult
.CloseWeaponPrior
[a
] := BotList
[num
].w_prior2
[a
];
1104 //FDifficult.SafeWeaponPrior[a] := BotList[num].w_prior3[a];
1107 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [Name
]), True);
1109 if g_Game_IsNet
then MH_SEND_PlayerCreate(UID
);
1113 procedure g_Bot_RemoveAll();
1117 if not g_Game_IsServer
then Exit
;
1118 if gPlayers
= nil then Exit
;
1120 for a
:= 0 to High(gPlayers
) do
1121 if gPlayers
[a
] <> nil then
1122 if gPlayers
[a
] is TBot
then
1124 gPlayers
[a
].Lives
:= 0;
1125 gPlayers
[a
].Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
1126 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [gPlayers
[a
].Name
]), True);
1127 g_Player_Remove(gPlayers
[a
].FUID
);
1133 procedure g_Bot_MixNames();
1138 if BotNames
<> nil then
1139 for a
:= 0 to High(BotNames
) do
1141 b
:= Random(Length(BotNames
));
1143 Botnames
[a
] := BotNames
[b
];
1148 procedure g_Player_Remove(UID
: Word);
1152 if gPlayers
= nil then Exit
;
1154 if g_Game_IsServer
and g_Game_IsNet
then
1155 MH_SEND_PlayerDelete(UID
);
1157 for i
:= 0 to High(gPlayers
) do
1158 if gPlayers
[i
] <> nil then
1159 if gPlayers
[i
].FUID
= UID
then
1161 if gPlayers
[i
] is TPlayer
then
1162 TPlayer(gPlayers
[i
]).Free()
1164 TBot(gPlayers
[i
]).Free();
1170 procedure g_Player_Init();
1181 path
:= BOTNAMES_FILENAME
;
1182 if e_FindResource(DataDirs
, path
) = false then
1185 // ×èòàåì âîçìîæíûå èìåíà áîòîâ èç ôàéëà:
1186 AssignFile(F
, path
);
1197 SetLength(BotNames
, Length(BotNames
)+1);
1198 BotNames
[High(BotNames
)] := s
;
1206 // ×èòàåì ôàéë ñ ïàðàìåòðàìè áîòîâ:
1207 config
:= TConfig
.CreateFile(path
);
1211 while config
.SectionExists(IntToStr(a
)) do
1213 SetLength(BotList
, Length(BotList
)+1);
1215 with BotList
[High(BotList
)] do
1218 name
:= config
.ReadStr(IntToStr(a
), 'name', '');
1220 model
:= config
.ReadStr(IntToStr(a
), 'model', '');
1222 if config
.ReadStr(IntToStr(a
), 'team', 'red') = 'red' then
1227 sa
:= parse(config
.ReadStr(IntToStr(a
), 'color', ''));
1228 color
.R
:= StrToIntDef(sa
[0], 0);
1229 color
.G
:= StrToIntDef(sa
[1], 0);
1230 color
.B
:= StrToIntDef(sa
[2], 0);
1231 // Âåðîÿòíîñòü ñòðåëüáû ïîä óãëîì:
1232 diag_fire
:= config
.ReadInt(IntToStr(a
), 'diag_fire', 0);
1233 // Âåðîÿòíîñòü îòâåòíîãî îãíÿ ïî íåâèäèìîìó ñîïåðíèêó:
1234 invis_fire
:= config
.ReadInt(IntToStr(a
), 'invis_fire', 0);
1235 // Òî÷íîñòü ñòðåëüáû ïîä óãëîì:
1236 diag_precision
:= config
.ReadInt(IntToStr(a
), 'diag_precision', 0);
1237 // Òî÷íîñòü ñòðåëüáû â ïîëåòå:
1238 fly_precision
:= config
.ReadInt(IntToStr(a
), 'fly_precision', 0);
1239 // Òî÷íîñòü óêëîíåíèÿ îò ñíàðÿäîâ:
1240 cover
:= config
.ReadInt(IntToStr(a
), 'cover', 0);
1241 // Âåðîÿòíîñòü ïðûæêà ïðè ïðèáëèæåíèè ñîïåðíèêà:
1242 close_jump
:= config
.ReadInt(IntToStr(a
), 'close_jump', 0);
1243 // Ïðèîðèòåòû îðóæèÿ äëÿ äàëüíåãî áîÿ:
1244 sa
:= parse(config
.ReadStr(IntToStr(a
), 'w_prior1', ''));
1245 if Length(sa
) = 10 then
1247 w_prior1
[b
] := EnsureRange(StrToInt(sa
[b
]), 0, 9);
1248 // Ïðèîðèòåòû îðóæèÿ äëÿ áëèæíåãî áîÿ:
1249 sa
:= parse(config
.ReadStr(IntToStr(a
), 'w_prior2', ''));
1250 if Length(sa
) = 10 then
1252 w_prior2
[b
] := EnsureRange(StrToInt(sa
[b
]), 0, 9);
1254 {sa := parse(config.ReadStr(IntToStr(a), 'w_prior3', ''));
1255 if Length(sa) = 10 then
1257 w_prior3[b] := EnsureRange(StrToInt(sa[b]), 0, 9);}
1264 SetLength(SavedStates
, 0);
1267 procedure g_Player_Free();
1271 if gPlayers
<> nil then
1273 for i
:= 0 to High(gPlayers
) do
1274 if gPlayers
[i
] <> nil then
1276 if gPlayers
[i
] is TPlayer
then
1277 TPlayer(gPlayers
[i
]).Free()
1279 TBot(gPlayers
[i
]).Free();
1288 SetLength(SavedStates
, 0);
1291 procedure g_Player_PreUpdate();
1295 if gPlayers
= nil then Exit
;
1296 for i
:= 0 to High(gPlayers
) do
1297 if gPlayers
[i
] <> nil then
1298 gPlayers
[i
].PreUpdate();
1301 procedure g_Player_UpdateAll();
1305 if gPlayers
= nil then Exit
;
1307 //e_WriteLog('***g_Player_UpdateAll: ENTER', MSG_WARNING);
1308 for i
:= 0 to High(gPlayers
) do
1310 if gPlayers
[i
] <> nil then
1312 if gPlayers
[i
] is TPlayer
then
1314 gPlayers
[i
].Update();
1315 gPlayers
[i
].RealizeCurrentWeapon(); // WARNING! DO NOT MOVE THIS INTO `Update()`!
1319 // bot updates weapons in `UpdateCombat()`
1320 TBot(gPlayers
[i
]).Update();
1324 //e_WriteLog('***g_Player_UpdateAll: EXIT', MSG_WARNING);
1327 procedure g_Player_DrawAll();
1331 if gPlayers
= nil then Exit
;
1333 for i
:= 0 to High(gPlayers
) do
1334 if gPlayers
[i
] <> nil then
1335 if gPlayers
[i
] is TPlayer
then gPlayers
[i
].Draw()
1336 else TBot(gPlayers
[i
]).Draw();
1339 procedure g_Player_DrawDebug(p
: TPlayer
);
1343 if p
= nil then Exit
;
1344 if (@p
.FObj
) = nil then Exit
;
1346 e_TextureFontGetSize(gStdFont
, fW
, fH
);
1348 e_TextureFontPrint(0, 0 , 'Pos X: ' + IntToStr(p
.FObj
.X
), gStdFont
);
1349 e_TextureFontPrint(0, fH
, 'Pos Y: ' + IntToStr(p
.FObj
.Y
), gStdFont
);
1350 e_TextureFontPrint(0, fH
* 2, 'Vel X: ' + IntToStr(p
.FObj
.Vel
.X
), gStdFont
);
1351 e_TextureFontPrint(0, fH
* 3, 'Vel Y: ' + IntToStr(p
.FObj
.Vel
.Y
), gStdFont
);
1352 e_TextureFontPrint(0, fH
* 4, 'Acc X: ' + IntToStr(p
.FObj
.Accel
.X
), gStdFont
);
1353 e_TextureFontPrint(0, fH
* 5, 'Acc Y: ' + IntToStr(p
.FObj
.Accel
.Y
), gStdFont
);
1354 e_TextureFontPrint(0, fH
* 6, 'Old X: ' + IntToStr(p
.FObj
.oldX
), gStdFont
);
1355 e_TextureFontPrint(0, fH
* 7, 'Old Y: ' + IntToStr(p
.FObj
.oldY
), gStdFont
);
1358 procedure g_Player_DrawHealth();
1363 if gPlayers
= nil then Exit
;
1364 e_TextureFontGetSize(gStdFont
, fW
, fH
);
1366 for i
:= 0 to High(gPlayers
) do
1367 if gPlayers
[i
] <> nil then
1369 e_TextureFontPrint(gPlayers
[i
].FObj
.X
+ gPlayers
[i
].FObj
.Rect
.X
,
1370 gPlayers
[i
].FObj
.Y
+ gPlayers
[i
].FObj
.Rect
.Y
+ gPlayers
[i
].FObj
.Rect
.Height
- fH
* 2,
1371 IntToStr(gPlayers
[i
].FHealth
), gStdFont
);
1372 e_TextureFontPrint(gPlayers
[i
].FObj
.X
+ gPlayers
[i
].FObj
.Rect
.X
,
1373 gPlayers
[i
].FObj
.Y
+ gPlayers
[i
].FObj
.Rect
.Y
+ gPlayers
[i
].FObj
.Rect
.Height
- fH
,
1374 IntToStr(gPlayers
[i
].FArmor
), gStdFont
);
1378 function g_Player_Get(UID
: Word): TPlayer
;
1384 if gPlayers
= nil then
1387 for a
:= 0 to High(gPlayers
) do
1388 if gPlayers
[a
] <> nil then
1389 if gPlayers
[a
].FUID
= UID
then
1391 Result
:= gPlayers
[a
];
1396 function g_Player_GetCount(): Byte;
1402 if gPlayers
= nil then
1405 for a
:= 0 to High(gPlayers
) do
1406 if gPlayers
[a
] <> nil then
1407 Result
:= Result
+ 1;
1410 function g_Player_GetStats(): TPlayerStatArray
;
1416 if gPlayers
= nil then Exit
;
1418 for a
:= 0 to High(gPlayers
) do
1419 if gPlayers
[a
] <> nil then
1421 SetLength(Result
, Length(Result
)+1);
1422 with Result
[High(Result
)] do
1425 Ping
:= gPlayers
[a
].FPing
;
1426 Loss
:= gPlayers
[a
].FLoss
;
1427 Name
:= gPlayers
[a
].FName
;
1428 Team
:= gPlayers
[a
].FTeam
;
1429 Frags
:= gPlayers
[a
].FFrags
;
1430 Deaths
:= gPlayers
[a
].FDeath
;
1431 Kills
:= gPlayers
[a
].FKills
;
1432 Color
:= gPlayers
[a
].FModel
.Color
;
1433 Lives
:= gPlayers
[a
].FLives
;
1434 Spectator
:= gPlayers
[a
].FSpectator
;
1435 UID
:= gPlayers
[a
].FUID
;
1440 procedure g_Player_ResetReady();
1444 if not g_Game_IsServer
then Exit
;
1445 if gPlayers
= nil then Exit
;
1447 for a
:= 0 to High(gPlayers
) do
1448 if gPlayers
[a
] <> nil then
1450 gPlayers
[a
].FReady
:= False;
1451 if g_Game_IsNet
then
1452 MH_SEND_GameEvent(NET_EV_INTER_READY
, gPlayers
[a
].UID
, 'N');
1456 procedure g_Player_RememberAll
;
1460 for i
:= Low(gPlayers
) to High(gPlayers
) do
1461 if (gPlayers
[i
] <> nil) and gPlayers
[i
].alive
then
1462 gPlayers
[i
].RememberState
;
1465 procedure g_Player_ResetAll(Force
, Silent
: Boolean);
1469 gTeamStat
[TEAM_RED
].Goals
:= 0;
1470 gTeamStat
[TEAM_BLUE
].Goals
:= 0;
1472 if gPlayers
<> nil then
1473 for i
:= 0 to High(gPlayers
) do
1474 if gPlayers
[i
] <> nil then
1476 gPlayers
[i
].Reset(Force
);
1478 if gPlayers
[i
] is TPlayer
then
1480 if (not gPlayers
[i
].FSpectator
) or gPlayers
[i
].FWantsInGame
then
1481 gPlayers
[i
].Respawn(Silent
)
1483 gPlayers
[i
].Spectate();
1486 TBot(gPlayers
[i
]).Respawn(Silent
);
1490 function g_Player_CreateCorpse(Player
: TPlayer
): Integer;
1498 if Player
.alive
then
1501 // Ðàçðûâàåì ñâÿçü ñ ïðåæíèì òðóïîì:
1502 i
:= Player
.FCorpse
;
1503 if (i
>= 0) and (i
< Length(gCorpses
)) then
1505 if (gCorpses
[i
] <> nil) and (gCorpses
[i
].FPlayerUID
= Player
.FUID
) then
1506 gCorpses
[i
].FPlayerUID
:= 0;
1509 if Player
.FObj
.Y
>= gMapInfo
.Height
+128 then
1514 if (FHealth
>= -50) or (gGibsCount
= 0) then
1516 if (gCorpses
= nil) or (Length(gCorpses
) = 0) then
1520 for find_id
:= 0 to High(gCorpses
) do
1521 if gCorpses
[find_id
] = nil then
1528 find_id
:= Random(Length(gCorpses
));
1530 gCorpses
[find_id
] := TCorpse
.Create(FObj
.X
, FObj
.Y
, FModel
.Name
, FHealth
< -20);
1531 gCorpses
[find_id
].FColor
:= FModel
.Color
;
1532 gCorpses
[find_id
].FObj
.Vel
:= FObj
.Vel
;
1533 gCorpses
[find_id
].FObj
.Accel
:= FObj
.Accel
;
1534 gCorpses
[find_id
].FPlayerUID
:= FUID
;
1539 g_Player_CreateGibs(FObj
.X
+ PLAYER_RECT_CX
,
1540 FObj
.Y
+ PLAYER_RECT_CY
,
1541 FModel
.Name
, FModel
.Color
);
1545 procedure g_Player_CreateShell(fX
, fY
, dX
, dY
: Integer; T
: Byte);
1549 if (gShells
= nil) or (Length(gShells
) = 0) then
1552 with gShells
[CurrentShell
] do
1558 if T
= SHELL_BULLET
then
1560 if g_Texture_Get('TEXTURE_SHELL_BULLET', SID
) then
1564 Obj
.Rect
.Width
:= 4;
1565 Obj
.Rect
.Height
:= 2;
1569 if g_Texture_Get('TEXTURE_SHELL_SHELL', SID
) then
1573 Obj
.Rect
.Width
:= 7;
1574 Obj
.Rect
.Height
:= 3;
1580 g_Obj_Push(@Obj
, dX
+ Random(4)-Random(4), dY
-Random(4));
1581 positionChanged(); // this updates spatial accelerators
1582 RAngle
:= Random(360);
1583 Timeout
:= gTime
+ SHELL_TIMEOUT
;
1585 if CurrentShell
>= High(gShells
) then
1592 procedure g_Player_CreateGibs(fX
, fY
: Integer; ModelName
: string; fColor
: TRGB
);
1595 GibsArray
: TGibsArray
;
1598 if (gGibs
= nil) or (Length(gGibs
) = 0) then
1600 if not g_PlayerModel_GetGibs(ModelName
, GibsArray
) then
1602 Blood
:= g_PlayerModel_GetBlood(ModelName
);
1604 for a
:= 0 to High(GibsArray
) do
1605 with gGibs
[CurrentGib
] do
1608 ID
:= GibsArray
[a
].ID
;
1609 MaskID
:= GibsArray
[a
].MaskID
;
1612 Obj
.Rect
:= GibsArray
[a
].Rect
;
1613 Obj
.X
:= fX
-GibsArray
[a
].Rect
.X
-(GibsArray
[a
].Rect
.Width
div 2);
1614 Obj
.Y
:= fY
-GibsArray
[a
].Rect
.Y
-(GibsArray
[a
].Rect
.Height
div 2);
1615 g_Obj_PushA(@Obj
, 25 + Random(10), Random(361));
1616 positionChanged(); // this updates spatial accelerators
1617 RAngle
:= Random(360);
1619 if gBloodCount
> 0 then
1620 g_GFX_Blood(fX
, fY
, 16*gBloodCount
+Random(5*gBloodCount
), -16+Random(33), -16+Random(33),
1621 Random(48), Random(48), Blood
.R
, Blood
.G
, Blood
.B
, Blood
.Kind
);
1623 if CurrentGib
>= High(gGibs
) then
1630 procedure g_Player_UpdatePhysicalObjects();
1636 procedure ShellSound_Bounce(X
, Y
: Integer; T
: Byte);
1641 if T
= SHELL_BULLET
then
1642 g_Sound_PlayExAt('SOUND_PLAYER_CASING' + IntToStr(k
), X
, Y
)
1644 g_Sound_PlayExAt('SOUND_PLAYER_SHELL' + IntToStr(k
), X
, Y
);
1649 if gGibs
<> nil then
1650 for i
:= 0 to High(gGibs
) do
1651 if gGibs
[i
].alive
then
1658 mr
:= g_Obj_Move(@Obj
, True, False, True);
1659 positionChanged(); // this updates spatial accelerators
1661 if WordBool(mr
and MOVE_FALLOUT
) then
1667 // Îòëåòàåò îò óäàðà î ñòåíó/ïîòîëîê/ïîë:
1668 if WordBool(mr
and MOVE_HITWALL
) then
1669 Obj
.Vel
.X
:= -(vel
.X
div 2);
1670 if WordBool(mr
and (MOVE_HITCEIL
or MOVE_HITLAND
)) then
1671 Obj
.Vel
.Y
:= -(vel
.Y
div 2);
1673 if (Obj
.Vel
.X
>= 0) then
1675 RAngle
:= RAngle
+ Abs(Obj
.Vel
.X
)*6 + Abs(Obj
.Vel
.Y
);
1676 if RAngle
>= 360 then
1677 RAngle
:= RAngle
mod 360;
1678 end else begin // Counter-clockwise
1679 RAngle
:= RAngle
- Abs(Obj
.Vel
.X
)*6 - Abs(Obj
.Vel
.Y
);
1681 RAngle
:= (360 - (Abs(RAngle
) mod 360)) mod 360;
1684 // Ñîïðîòèâëåíèå âîçäóõà äëÿ êóñêà òðóïà:
1685 if gTime
mod (GAME_TICK
*3) = 0 then
1686 Obj
.Vel
.X
:= z_dec(Obj
.Vel
.X
, 1);
1690 if gCorpses
<> nil then
1691 for i
:= 0 to High(gCorpses
) do
1692 if gCorpses
[i
] <> nil then
1693 if gCorpses
[i
].State
= CORPSE_STATE_REMOVEME
then
1699 gCorpses
[i
].Update();
1702 if gShells
<> nil then
1703 for i
:= 0 to High(gShells
) do
1704 if gShells
[i
].alive
then
1711 mr
:= g_Obj_Move(@Obj
, True, False, True);
1712 positionChanged(); // this updates spatial accelerators
1714 if WordBool(mr
and MOVE_FALLOUT
) or (gShells
[i
].Timeout
< gTime
) then
1720 // Îòëåòàåò îò óäàðà î ñòåíó/ïîòîëîê/ïîë:
1721 if WordBool(mr
and MOVE_HITWALL
) then
1723 Obj
.Vel
.X
:= -(vel
.X
div 2);
1724 if not WordBool(mr
and MOVE_INWATER
) then
1725 ShellSound_Bounce(Obj
.X
, Obj
.Y
, SType
);
1727 if WordBool(mr
and (MOVE_HITCEIL
or MOVE_HITLAND
)) then
1729 Obj
.Vel
.Y
:= -(vel
.Y
div 2);
1730 if Obj
.Vel
.X
<> 0 then Obj
.Vel
.X
:= Obj
.Vel
.X
div 2;
1731 if (Obj
.Vel
.X
= 0) and (Obj
.Vel
.Y
= 0) then
1733 if RAngle
mod 90 <> 0 then
1734 RAngle
:= (RAngle
div 90) * 90;
1736 else if not WordBool(mr
and MOVE_INWATER
) then
1737 ShellSound_Bounce(Obj
.X
, Obj
.Y
, SType
);
1740 if (Obj
.Vel
.X
>= 0) then
1742 RAngle
:= RAngle
+ Abs(Obj
.Vel
.X
)*8 + Abs(Obj
.Vel
.Y
);
1743 if RAngle
>= 360 then
1744 RAngle
:= RAngle
mod 360;
1745 end else begin // Counter-clockwise
1746 RAngle
:= RAngle
- Abs(Obj
.Vel
.X
)*8 - Abs(Obj
.Vel
.Y
);
1748 RAngle
:= (360 - (Abs(RAngle
) mod 360)) mod 360;
1754 procedure TGib
.getMapBox (out x
, y
, w
, h
: Integer); inline;
1756 x
:= Obj
.X
+Obj
.Rect
.X
;
1757 y
:= Obj
.Y
+Obj
.Rect
.Y
;
1758 w
:= Obj
.Rect
.Width
;
1759 h
:= Obj
.Rect
.Height
;
1762 procedure TGib
.moveBy (dx
, dy
: Integer); inline;
1764 if (dx
<> 0) or (dy
<> 0) then
1773 procedure TShell
.getMapBox (out x
, y
, w
, h
: Integer); inline;
1777 w
:= Obj
.Rect
.Width
;
1778 h
:= Obj
.Rect
.Height
;
1781 procedure TShell
.moveBy (dx
, dy
: Integer); inline;
1783 if (dx
<> 0) or (dy
<> 0) then
1792 procedure TGib
.positionChanged (); inline; begin end;
1793 procedure TShell
.positionChanged (); inline; begin end;
1796 procedure g_Player_DrawCorpses();
1801 if gGibs
<> nil then
1802 for i
:= 0 to High(gGibs
) do
1803 if gGibs
[i
].alive
then
1806 if not g_Obj_Collide(sX
, sY
, sWidth
, sHeight
, @Obj
) then
1809 Obj
.lerp(gLerpFactor
, fX
, fY
);
1811 a
.X
:= Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2);
1812 a
.y
:= Obj
.Rect
.Y
+(Obj
.Rect
.Height
div 2);
1814 e_DrawAdv(ID
, fX
, fY
, 0, True, False, RAngle
, @a
, TMirrorType
.None
);
1817 e_DrawAdv(MaskID
, fX
, fY
, 0, True, False, RAngle
, @a
, TMirrorType
.None
);
1823 if gCorpses
<> nil then
1824 for i
:= 0 to High(gCorpses
) do
1825 if gCorpses
[i
] <> nil then
1829 procedure g_Player_DrawShells();
1834 if gShells
<> nil then
1835 for i
:= 0 to High(gShells
) do
1836 if gShells
[i
].alive
then
1839 if not g_Obj_Collide(sX
, sY
, sWidth
, sHeight
, @Obj
) then
1842 Obj
.lerp(gLerpFactor
, fX
, fY
);
1847 e_DrawAdv(SpriteID
, fX
, fY
, 0, True, False, RAngle
, @a
, TMirrorType
.None
);
1851 procedure g_Player_RemoveAllCorpses();
1857 SetLength(gGibs
, MaxGibs
);
1858 SetLength(gShells
, MaxGibs
);
1862 if gCorpses
<> nil then
1863 for i
:= 0 to High(gCorpses
) do
1867 SetLength(gCorpses
, MaxCorpses
);
1870 procedure g_Player_Corpses_SaveState (st
: TStream
);
1874 // Ñ÷èòàåì êîëè÷åñòâî ñóùåñòâóþùèõ òðóïîâ
1876 for i
:= 0 to High(gCorpses
) do if (gCorpses
[i
] <> nil) then Inc(count
);
1878 // Êîëè÷åñòâî òðóïîâ
1879 utils
.writeInt(st
, LongInt(count
));
1881 if (count
= 0) then exit
;
1884 for i
:= 0 to High(gCorpses
) do
1886 if gCorpses
[i
] <> nil then
1889 utils
.writeStr(st
, gCorpses
[i
].FModelName
);
1891 utils
.writeBool(st
, gCorpses
[i
].Mess
);
1892 // Ñîõðàíÿåì äàííûå òðóïà:
1893 gCorpses
[i
].SaveState(st
);
1899 procedure g_Player_Corpses_LoadState (st
: TStream
);
1907 g_Player_RemoveAllCorpses();
1909 // Êîëè÷åñòâî òðóïîâ:
1910 count
:= utils
.readLongInt(st
);
1911 if (count
< 0) or (count
> Length(gCorpses
)) then raise XStreamError
.Create('invalid number of corpses');
1913 if (count
= 0) then exit
;
1916 for i
:= 0 to count
-1 do
1919 str
:= utils
.readStr(st
);
1921 b
:= utils
.readBool(st
);
1923 gCorpses
[i
] := TCorpse
.Create(0, 0, str
, b
);
1924 // Çàãðóæàåì äàííûå òðóïà
1925 gCorpses
[i
].LoadState(st
);
1932 function TPlayer
.isValidViewPort (): Boolean; inline; begin result
:= (viewPortW
> 0) and (viewPortH
> 0); end;
1934 procedure TPlayer
.BFGHit();
1936 g_Weapon_BFGHit(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
1937 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2));
1938 if g_Game_IsServer
and g_Game_IsNet
then
1939 MH_SEND_Effect(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
1940 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2),
1944 procedure TPlayer
.ChangeModel(ModelName
: string);
1946 locModel
: TPlayerModel
;
1948 locModel
:= g_PlayerModel_Get(ModelName
);
1949 if locModel
= nil then Exit
;
1955 procedure TPlayer
.SetModel(ModelName
: string);
1959 m
:= g_PlayerModel_Get(ModelName
);
1962 g_SimpleError(Format(_lc
[I_GAME_ERROR_MODEL_FALLBACK
], [ModelName
]));
1963 m
:= g_PlayerModel_Get('doomer');
1966 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], ['doomer']));
1971 if FModel
<> nil then
1976 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
1977 FModel
.Color
:= FColor
1979 FModel
.Color
:= TEAMCOLOR
[FTeam
];
1980 FModel
.SetWeapon(FCurrWeap
);
1981 FModel
.SetFlag(FFlag
);
1982 SetDirection(FDirection
);
1985 procedure TPlayer
.SetColor(Color
: TRGB
);
1988 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
1989 if FModel
<> nil then FModel
.Color
:= Color
;
1994 function TPlayer
.GetColor(): TRGB
;
1996 result
:= FModel
.Color
;
1999 procedure TPlayer
.SetWeaponPrefs(Prefs
: Array of Byte);
2002 for i
:= WP_FIRST
to WP_LAST
+ 1 do
2004 if (Prefs
[i
] < 0) or (Prefs
[i
] > WP_LAST
+ 1) then
2005 FWeapPreferences
[i
] := 0
2006 else FWeapPreferences
[i
] := Prefs
[i
];
2010 procedure TPlayer
.SetWeaponPref(Weapon
, Pref
: Byte);
2012 if (Weapon
< 0) or (Weapon
> WP_LAST
+ 1) then
2014 else if (Pref
>= 0) and (Pref
<= WP_LAST
+ 1) and (Weapon
>= 0) and (Weapon
<= WP_LAST
+ 1) then
2015 FWeapPreferences
[Weapon
] := Pref
2016 else if (Weapon
>= 0) and (Weapon
<= WP_LAST
+ 1) and ((Pref
< 0) or (Pref
> WP_LAST
+ 1)) then
2017 FWeapPreferences
[Weapon
] := 0;
2020 function TPlayer
.GetWeaponPref(Weapon
: Byte) : Byte;
2022 if (Weapon
< 0) or (Weapon
> WP_LAST
+ 1) then
2024 else if (FWeapPreferences
[Weapon
] < 0) or (FWeapPreferences
[Weapon
] > WP_LAST
+ 1) then
2027 result
:= FWeapPreferences
[Weapon
];
2030 function TPlayer
.GetMorePrefered() : Byte;
2031 var testedWeap
, i
: Byte;
2033 testedWeap
:= FCurrWeap
;
2034 for i
:= WP_FIRST
to WP_LAST
do
2035 if FWeapon
[i
] and (FWeapPreferences
[i
] > FWeapPreferences
[testedWeap
]) then
2037 if (R_BERSERK
in FRulez
) and (FWeapPreferences
[WP_LAST
+ 1] > FWeapPreferences
[testedWeap
]) then
2038 testedWeap
:= WEAPON_KASTET
;
2039 result
:= testedWeap
;
2042 function TPlayer
.maySwitch(Weapon
: Byte) : Boolean;
2045 if (Weapon
= WEAPON_KASTET
) and (FSkipFist
<> 0) then
2047 if (FSkipFist
= 1) and (not (R_BERSERK
in FRulez
)) then
2050 else if (FSwitchToEmpty
= 0) and (not hasAmmoForWeapon(Weapon
)) then
2054 procedure TPlayer
.SwitchTeam
;
2056 if g_Game_IsClient
then
2058 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then Exit
;
2060 if gGameOn
and FAlive
then
2061 Kill(K_SIMPLEKILL
, FUID
, HIT_SELF
);
2063 if FTeam
= TEAM_RED
then
2065 ChangeTeam(TEAM_BLUE
);
2066 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_BLUE
], [FName
]), True);
2067 if g_Game_IsNet
then
2068 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM
, TEAM_BLUE
, FName
);
2072 ChangeTeam(TEAM_RED
);
2073 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_RED
], [FName
]), True);
2074 if g_Game_IsNet
then
2075 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM
, TEAM_RED
, FName
);
2077 FPreferredTeam
:= FTeam
;
2080 procedure TPlayer
.ChangeTeam(Team
: Byte);
2087 TEAM_RED
, TEAM_BLUE
:
2088 FModel
.Color
:= TEAMCOLOR
[Team
];
2090 FModel
.Color
:= FColor
;
2092 if (FTeam
<> OldTeam
) and g_Game_IsNet
and g_Game_IsServer
then
2093 MH_SEND_PlayerStats(FUID
);
2097 procedure TPlayer.CollideItem();
2102 if gItems = nil then Exit;
2103 if not FAlive then Exit;
2105 for i := 0 to High(gItems) do
2108 if (ItemType <> ITEM_NONE) and alive then
2109 if g_Obj_Collide(FObj.X+PLAYER_RECT.X, FObj.Y+PLAYER_RECT.Y, PLAYER_RECT.Width,
2110 PLAYER_RECT.Height, @Obj) then
2112 if not PickItem(ItemType, gItems[i].Respawnable, r) then Continue;
2114 if ItemType in [ITEM_SPHERE_BLUE, ITEM_SPHERE_WHITE, ITEM_INVUL] then
2115 g_Sound_PlayExAt('SOUND_ITEM_GETRULEZ', FObj.X, FObj.Y)
2116 else if ItemType in [ITEM_MEDKIT_SMALL, ITEM_MEDKIT_LARGE, ITEM_MEDKIT_BLACK] then
2117 g_Sound_PlayExAt('SOUND_ITEM_GETMED', FObj.X, FObj.Y)
2118 else g_Sound_PlayExAt('SOUND_ITEM_GETITEM', FObj.X, FObj.Y);
2120 // Íàäî óáðàòü ñ êàðòû, åñëè ýòî íå êëþ÷, êîòîðûì íóæíî ïîäåëèòñÿ ñ äðóãèì èãðîêîì:
2121 if r and not ((ItemType in [ITEM_KEY_RED, ITEM_KEY_GREEN, ITEM_KEY_BLUE]) and
2122 (gGameSettings.GameType = GT_SINGLE) and
2123 (g_Player_GetCount() > 1)) then
2124 if not Respawnable then g_Items_Remove(i) else g_Items_Pick(i);
2130 function TPlayer
.CollideLevel(XInc
, YInc
: Integer): Boolean;
2132 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
2133 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_WALL
,
2137 constructor TPlayer
.Create();
2143 mEDamageType
:= HIT_SOME
;
2149 FSawSound
:= TPlayableSound
.Create();
2150 FSawSoundIdle
:= TPlayableSound
.Create();
2151 FSawSoundHit
:= TPlayableSound
.Create();
2152 FSawSoundSelect
:= TPlayableSound
.Create();
2153 FFlameSoundOn
:= TPlayableSound
.Create();
2154 FFlameSoundOff
:= TPlayableSound
.Create();
2155 FFlameSoundWork
:= TPlayableSound
.Create();
2156 FJetSoundFly
:= TPlayableSound
.Create();
2157 FJetSoundOn
:= TPlayableSound
.Create();
2158 FJetSoundOff
:= TPlayableSound
.Create();
2160 FSawSound
.SetByName('SOUND_WEAPON_FIRESAW');
2161 FSawSoundIdle
.SetByName('SOUND_WEAPON_IDLESAW');
2162 FSawSoundHit
.SetByName('SOUND_WEAPON_HITSAW');
2163 FSawSoundSelect
.SetByName('SOUND_WEAPON_SELECTSAW');
2164 FFlameSoundOn
.SetByName('SOUND_WEAPON_FLAMEON');
2165 FFlameSoundOff
.SetByName('SOUND_WEAPON_FLAMEOFF');
2166 FFlameSoundWork
.SetByName('SOUND_WEAPON_FLAMEWORK');
2167 FJetSoundFly
.SetByName('SOUND_PLAYER_JETFLY');
2168 FJetSoundOn
.SetByName('SOUND_PLAYER_JETON');
2169 FJetSoundOff
.SetByName('SOUND_PLAYER_JETOFF');
2171 FSpectatePlayer
:= -1;
2175 FSavedStateNum
:= -1;
2183 FActualModelName
:= 'doomer';
2186 FObj
.Rect
:= PLAYER_RECT
;
2188 FBFGFireCounter
:= -1;
2189 FJustTeleported
:= False;
2192 FWaitForFirstSpawn
:= false;
2197 procedure TPlayer
.positionChanged (); inline;
2201 procedure TPlayer
.doDamage (v
: Integer);
2203 if (v
<= 0) then exit
;
2204 if (v
> 32767) then v
:= 32767;
2205 Damage(v
, 0, 0, 0, mEDamageType
);
2208 procedure TPlayer
.Damage(value
: Word; SpawnerUID
: Word; vx
, vy
: Integer; t
: Byte);
2212 if (not g_Game_IsClient
) and (not FAlive
) then
2217 // Íåóÿçâèìîñòü íå ñïàñàåò îò ëîâóøåê:
2218 if ((t
= HIT_TRAP
) or (t
= HIT_SELF
)) and (not FGodMode
) then
2220 if not g_Game_IsClient
then
2223 if t
= HIT_TRAP
then
2225 // Ëîâóøêà óáèâàåò ñðàçó:
2227 Kill(K_EXTRAHARDKILL
, SpawnerUID
, t
);
2229 if t
= HIT_SELF
then
2233 Kill(K_SIMPLEKILL
, SpawnerUID
, t
);
2236 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
2237 FMegaRulez
[MR_SUIT
] := 0;
2238 FMegaRulez
[MR_INVUL
] := 0;
2239 FMegaRulez
[MR_INVIS
] := 0;
2244 // Íî îò îñòàëüíîãî ñïàñàåò:
2245 if FMegaRulez
[MR_INVUL
] >= gTime
then
2252 // Åñëè åñòü óðîí ñâîèì, èëè ðàíèë ñàì ñåáÿ, èëè òåáÿ ðàíèë ïðîòèâíèê:
2253 if LongBool(gGameSettings
.Options
and GAME_OPTION_TEAMDAMAGE
) or
2254 (SpawnerUID
= FUID
) or
2255 (not SameTeam(FUID
, SpawnerUID
)) then
2257 FLastSpawnerUID
:= SpawnerUID
;
2259 // Êðîâü (ïóçûðüêè, åñëè â âîäå):
2260 if gBloodCount
> 0 then
2262 c
:= Min(value
, 200)*gBloodCount
+ Random(Min(value
, 200) div 2);
2263 if value
div 4 <= c
then
2264 c
:= c
- (value
div 4)
2268 if (t
= HIT_SOME
) and (vx
= 0) and (vy
= 0) then
2272 HIT_TRAP
, HIT_ACID
, HIT_FLAME
, HIT_SELF
: MakeBloodSimple(c
);
2273 HIT_BFG
, HIT_ROCKET
, HIT_SOME
: MakeBloodVector(c
, vx
, vy
);
2276 if t
= HIT_WATER
then
2277 g_GFX_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
2278 FObj
.Y
+PLAYER_RECT
.Y
-4, value
div 2, 8, 4);
2283 Inc(FDamageBuffer
, value
);
2287 FPain
:= FPain
+ value
;
2290 if g_Game_IsServer
and g_Game_IsNet
then
2292 MH_SEND_PlayerDamage(FUID
, t
, SpawnerUID
, value
, vx
, vy
);
2293 MH_SEND_PlayerStats(FUID
);
2294 MH_SEND_PlayerPos(False, FUID
);
2298 function TPlayer
.Heal(value
: Word; Soft
: Boolean): Boolean;
2301 if g_Game_IsClient
then
2306 if Soft
and (FHealth
< PLAYER_HP_SOFT
) then
2308 IncMax(FHealth
, value
, PLAYER_HP_SOFT
);
2311 if (not Soft
) and (FHealth
< PLAYER_HP_LIMIT
) then
2313 IncMax(FHealth
, value
, PLAYER_HP_LIMIT
);
2317 if Result
and g_Game_IsServer
and g_Game_IsNet
then
2318 MH_SEND_PlayerStats(FUID
);
2321 destructor TPlayer
.Destroy();
2323 if (gPlayer1
<> nil) and (gPlayer1
.FUID
= FUID
) then
2325 if (gPlayer2
<> nil) and (gPlayer2
.FUID
= FUID
) then
2329 FSawSoundIdle
.Free();
2330 FSawSoundHit
.Free();
2331 FSawSoundSelect
.Free();
2332 FFlameSoundOn
.Free();
2333 FFlameSoundOff
.Free();
2334 FFlameSoundWork
.Free();
2335 FJetSoundFly
.Free();
2337 FJetSoundOff
.Free();
2339 if FPunchAnim
<> nil then
2345 procedure TPlayer
.DrawIndicator(Color
: TRGB
);
2347 indX
, indY
, fX
, fY
, fSlope
: Integer;
2357 FObj
.lerp(gLerpFactor
, fX
, fY
);
2358 fSlope
:= nlerp(FSlopeOld
, FObj
.slopeUpLeft
, gLerpFactor
);
2360 case gPlayerIndicatorStyle
of
2363 if g_Texture_Get('TEXTURE_PLAYER_INDICATOR', ID
) then
2365 e_GetTextureSize(ID
, @indW
, @indH
);
2369 if (FObj
.X
+ FObj
.Rect
.X
) < 0 then
2372 indX
:= fX
+ FObj
.Rect
.X
+ FObj
.Rect
.Width
;
2373 indY
:= fY
+ FObj
.Rect
.Y
+ (FObj
.Rect
.Height
- indW
) div 2;
2376 else if (FObj
.X
+ FObj
.Rect
.X
+ FObj
.Rect
.Width
) > Max(gMapInfo
.Width
, gPlayerScreenSize
.X
) then
2379 indX
:= fX
+ FObj
.Rect
.X
- indH
;
2380 indY
:= fY
+ FObj
.Rect
.Y
+ (FObj
.Rect
.Height
- indW
) div 2;
2383 else if (FObj
.Y
- indH
) < 0 then
2386 indX
:= fX
+ FObj
.Rect
.X
+ (FObj
.Rect
.Width
- indW
) div 2;
2387 indY
:= fY
+ FObj
.Rect
.Y
+ FObj
.Rect
.Height
;
2393 indX
:= fX
+ FObj
.Rect
.X
+ (FObj
.Rect
.Width
- indW
) div 2;
2397 indY
:= indY
+ fSlope
;
2398 indX
:= EnsureRange(indX
, 0, Max(gMapInfo
.Width
, gPlayerScreenSize
.X
) - indW
);
2399 indY
:= EnsureRange(indY
, 0, Max(gMapInfo
.Height
, gPlayerScreenSize
.Y
) - indH
);
2403 e_DrawAdv(ID
, indX
, indY
, 0, True, False, indA
, @a
);
2410 e_TextureFontGetSize(gStdFont
, nW
, nH
);
2411 indX
:= fX
+ FObj
.Rect
.X
+ (FObj
.Rect
.Width
- Length(FName
) * nW
) div 2;
2412 indY
:= fY
- nH
+ fSlope
;
2413 e_TextureFontPrintEx(indX
, indY
, FName
, gStdFont
, Color
.R
, Color
.G
, Color
.B
, 1.0, True);
2419 procedure TPlayer
.DrawBubble();
2421 bubX
, bubY
, fX
, fY
: Integer;
2424 Rw
, Gw
, Bw
: SmallInt;
2428 CObj
:= getCameraObj();
2429 CObj
.lerp(gLerpFactor
, fX
, fY
);
2430 // NB: _F_Obj.Rect is used to keep the bubble higher; this is not a mistake
2431 bubX
:= fX
+FObj
.Rect
.X
+ IfThen(FDirection
= TDirection
.D_LEFT
, -4, 18);
2432 bubY
:= fY
+FObj
.Rect
.Y
- 18;
2440 1: // simple textual non-bubble
2442 bubX
:= fX
+FObj
.Rect
.X
- 11;
2443 bubY
:= fY
+FObj
.Rect
.Y
- 17;
2444 e_TextureFontPrint(bubX
, bubY
, '[...]', gStdFont
);
2447 2: // advanced pixel-perfect bubble
2449 if FTeam
= TEAM_RED
then
2452 if FTeam
= TEAM_BLUE
then
2455 3: // colored bubble
2457 Rb
:= FModel
.Color
.R
;
2458 Gb
:= FModel
.Color
.G
;
2459 Bb
:= FModel
.Color
.B
;
2460 Rw
:= Min(Rb
* 2 + 64, 255);
2461 Gw
:= Min(Gb
* 2 + 64, 255);
2462 Bw
:= Min(Bb
* 2 + 64, 255);
2463 if (Abs(Rw
- Rb
) < 32)
2464 or (Abs(Gw
- Gb
) < 32)
2465 or (Abs(Bw
- Bb
) < 32) then
2467 Rb
:= Max(Rw
div 2 - 16, 0);
2468 Gb
:= Max(Gw
div 2 - 16, 0);
2469 Bb
:= Max(Bw
div 2 - 16, 0);
2472 4: // custom textured bubble
2474 if g_Texture_Get('TEXTURE_PLAYER_TALKBUBBLE', ID
) then
2475 if FDirection
= TDirection
.D_RIGHT
then
2476 e_Draw(ID
, bubX
- 6, bubY
- 7, 0, True, False)
2478 e_Draw(ID
, bubX
- 6, bubY
- 7, 0, True, False, TMirrorType
.Horizontal
);
2484 e_DrawQuad(bubX
+ 1, bubY
, bubX
+ 18, bubY
+ 13, Rb
, Gb
, Bb
);
2485 e_DrawQuad(bubX
, bubY
+ 1, bubX
+ 19, bubY
+ 12, Rb
, Gb
, Bb
);
2487 e_DrawFillQuad(bubX
+ 1, bubY
+ 1, bubX
+ 18, bubY
+ 12, Rw
, Gw
, Bw
, 0);
2490 Dot
:= IfThen(FDirection
= TDirection
.D_LEFT
, 14, 5);
2491 e_DrawLine(1, bubX
+ Dot
, bubY
+ 14, bubX
+ Dot
, bubY
+ 16, Rb
, Gb
, Bb
);
2492 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
);
2493 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
);
2494 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
);
2495 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
);
2499 e_DrawFillQuad(bubX
+ Dot
, bubY
+ 8, bubX
+ Dot
+ 1, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2500 e_DrawFillQuad(bubX
+ Dot
+ 3, bubY
+ 8, bubX
+ Dot
+ 4, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2501 e_DrawFillQuad(bubX
+ Dot
+ 6, bubY
+ 8, bubX
+ Dot
+ 7, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2504 procedure TPlayer
.Draw();
2509 Mirror
: TMirrorType
;
2510 fX
, fY
, fSlope
: Integer;
2512 FObj
.lerp(gLerpFactor
, fX
, fY
);
2513 fSlope
:= nlerp(FSlopeOld
, FObj
.slopeUpLeft
, gLerpFactor
);
2517 if Direction
= TDirection
.D_RIGHT
then
2518 Mirror
:= TMirrorType
.None
2520 Mirror
:= TMirrorType
.Horizontal
;
2522 if FPunchAnim
<> nil then
2524 FPunchAnim
.Draw(fX
+IfThen(Direction
= TDirection
.D_LEFT
, 15-FObj
.Rect
.X
, FObj
.Rect
.X
-15),
2525 fY
+fSlope
+FObj
.Rect
.Y
-11, Mirror
);
2526 if FPunchAnim
.played
then
2533 if (FMegaRulez
[MR_INVUL
] > gTime
) and ((gPlayerDrawn
<> Self
) or (FSpawnInvul
>= gTime
)) then
2534 if g_Texture_Get('TEXTURE_PLAYER_INVULPENTA', ID
) then
2536 e_GetTextureSize(ID
, @w
, @h
);
2537 if FDirection
= TDirection
.D_LEFT
then
2538 e_Draw(ID
, fX
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2)-(w
div 2)+4,
2539 fY
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2)-(h
div 2)-7+fSlope
, 0, True, False)
2541 e_Draw(ID
, fX
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2)-(w
div 2)-2,
2542 fY
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2)-(h
div 2)-7+fSlope
, 0, True, False);
2545 if FMegaRulez
[MR_INVIS
] > gTime
then
2547 if (gPlayerDrawn
<> nil) and ((Self
= gPlayerDrawn
) or
2548 ((FTeam
= gPlayerDrawn
.Team
) and (gGameSettings
.GameMode
<> GM_DM
))) then
2550 if (FMegaRulez
[MR_INVIS
] - gTime
) <= 2100 then
2551 dr
:= not Odd((FMegaRulez
[MR_INVIS
] - gTime
) div 300)
2555 FModel
.Draw(fX
, fY
+fSlope
, 200)
2557 FModel
.Draw(fX
, fY
+fSlope
);
2560 FModel
.Draw(fX
, fY
+fSlope
, 254);
2563 FModel
.Draw(fX
, fY
+fSlope
);
2566 if g_debug_Frames
then
2568 e_DrawQuad(FObj
.X
+FObj
.Rect
.X
,
2570 FObj
.X
+FObj
.Rect
.X
+FObj
.Rect
.Width
-1,
2571 FObj
.Y
+FObj
.Rect
.Y
+FObj
.Rect
.Height
-1,
2575 if (gChatBubble
> 0) and (FKeys
[KEY_CHAT
].Pressed
) and not FGhost
then
2576 if (FMegaRulez
[MR_INVIS
] <= gTime
) or ((gPlayerDrawn
<> nil) and ((Self
= gPlayerDrawn
) or
2577 ((FTeam
= gPlayerDrawn
.Team
) and (gGameSettings
.GameMode
<> GM_DM
)))) then
2579 // e_DrawPoint(5, 335, 288, 255, 0, 0); // DL, UR, DL, UR
2580 if gAimLine
and alive
and
2581 ((Self
= gPlayer1
) or (Self
= gPlayer2
)) then
2586 procedure TPlayer
.DrawAim();
2587 procedure drawCast (sz
: Integer; ax0
, ay0
, ax1
, ay1
: Integer);
2592 {$IFDEF ENABLE_HOLMES}
2593 if isValidViewPort
and (self
= gPlayer1
) then
2595 g_Holmes_plrLaser(ax0
, ay0
, ax1
, ay1
);
2599 e_DrawLine(sz
, ax0
, ay0
, ax1
, ay1
, 255, 0, 0, 96);
2600 if (g_Map_traceToNearestWall(ax0
, ay0
, ax1
, ay1
, @ex
, @ey
) <> nil) then
2602 e_DrawLine(sz
, ax0
, ay0
, ex
, ey
, 0, 255, 0, 96);
2606 e_DrawLine(sz
, ax0
, ay0
, ex
, ey
, 0, 0, 255, 96);
2611 wx
, wy
, xx
, yy
: Integer;
2615 wx
:= FObj
.X
+ WEAPONPOINT
[FDirection
].X
+ IfThen(FDirection
= TDirection
.D_LEFT
, 7, -7);
2616 wy
:= FObj
.Y
+ WEAPONPOINT
[FDirection
].Y
;
2625 1: begin // Chainsaw
2632 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2633 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2634 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2635 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2640 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2641 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2642 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2643 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2645 4: begin // Double Shotgun
2648 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2649 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2650 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2651 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2653 5: begin // Chaingun
2656 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2657 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2658 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2659 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2661 6: begin // Rocket Launcher
2664 if angle
= ANGLE_RIGHTUP
then Inc(angle
, 2);
2665 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2666 if angle
= ANGLE_LEFTUP
then Dec(angle
, 2);
2667 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2669 7: begin // Plasmagun
2672 if angle
= ANGLE_RIGHTUP
then Inc(angle
);
2673 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 3);
2674 if angle
= ANGLE_LEFTUP
then Dec(angle
);
2675 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 3);
2680 if angle
= ANGLE_RIGHTUP
then Inc(angle
, 1);
2681 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 2);
2682 if angle
= ANGLE_LEFTUP
then Dec(angle
, 1);
2683 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 2);
2685 9: begin // Super Chaingun
2688 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2689 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2690 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2691 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2694 xx
:= Trunc(Cos(-DegToRad(angle
)) * len
) + wx
;
2695 yy
:= Trunc(Sin(-DegToRad(angle
)) * len
) + wy
;
2696 {$IF DEFINED(D2F_DEBUG)}
2697 drawCast(sz
, wx
, wy
, xx
, yy
);
2699 e_DrawLine(sz
, wx
, wy
, xx
, yy
, 255, 0, 0, 96);
2703 procedure TPlayer
.DrawGUI();
2706 X
, Y
, SY
, a
, p
, m
: Integer;
2710 stat
: TPlayerStatArray
;
2712 X
:= gPlayerScreenSize
.X
;
2713 SY
:= gPlayerScreenSize
.Y
;
2716 if gShowGoals
and (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
2718 if gGameSettings
.GameMode
= GM_CTF
then
2722 if gGameSettings
.GameMode
= GM_CTF
then
2724 s
:= 'TEXTURE_PLAYER_REDFLAG';
2725 if gFlags
[FLAG_RED
].State
= FLAG_STATE_CAPTURED
then
2726 s
:= 'TEXTURE_PLAYER_REDFLAG_S';
2727 if gFlags
[FLAG_RED
].State
= FLAG_STATE_DROPPED
then
2728 s
:= 'TEXTURE_PLAYER_REDFLAG_D';
2729 if g_Texture_Get(s
, ID
) then
2730 e_Draw(ID
, X
-16-32, 240-72-4, 0, True, False);
2733 s
:= IntToStr(gTeamStat
[TEAM_RED
].Goals
);
2734 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2735 e_CharFont_PrintEx(gMenuFont
, X
-16-a
-tw
, 240-72-4, s
, TEAMCOLOR
[TEAM_RED
]);
2737 if gGameSettings
.GameMode
= GM_CTF
then
2739 s
:= 'TEXTURE_PLAYER_BLUEFLAG';
2740 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_CAPTURED
then
2741 s
:= 'TEXTURE_PLAYER_BLUEFLAG_S';
2742 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_DROPPED
then
2743 s
:= 'TEXTURE_PLAYER_BLUEFLAG_D';
2744 if g_Texture_Get(s
, ID
) then
2745 e_Draw(ID
, X
-16-32, 240-32-4, 0, True, False);
2748 s
:= IntToStr(gTeamStat
[TEAM_BLUE
].Goals
);
2749 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2750 e_CharFont_PrintEx(gMenuFont
, X
-16-a
-tw
, 240-32-4, s
, TEAMCOLOR
[TEAM_BLUE
]);
2753 if g_Texture_Get('TEXTURE_PLAYER_HUDBG', ID
) then
2754 e_DrawFill(ID
, X
, 0, 1, (gPlayerScreenSize
.Y
div 256)+IfThen(gPlayerScreenSize
.Y
mod 256 > 0, 1, 0),
2757 if g_Texture_Get('TEXTURE_PLAYER_HUD', ID
) then
2758 e_Draw(ID
, X
+2, Y
, 0, True, False);
2760 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
2764 s
:= IntToStr(Frags
);
2765 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2766 e_CharFont_PrintEx(gMenuFont
, X
-16-tw
, Y
, s
, _RGB(255, 0, 0));
2771 stat
:= g_Player_GetStats();
2776 for a
:= 0 to High(stat
) do
2777 if stat
[a
].Name
<> Name
then
2779 if stat
[a
].Frags
> m
then m
:= stat
[a
].Frags
;
2780 if stat
[a
].Frags
> Frags
then p
:= p
+1;
2784 s
:= IntToStr(p
)+' / '+IntToStr(Length(stat
))+' ';
2785 if Frags
>= m
then s
:= s
+'+' else s
:= s
+'-';
2786 s
:= s
+IntToStr(Abs(Frags
-m
));
2788 e_CharFont_GetSize(gMenuSmallFont
, s
, tw
, th
);
2789 e_CharFont_PrintEx(gMenuSmallFont
, X
-16-tw
, Y
+32, s
, _RGB(255, 0, 0));
2792 if gLMSRespawn
> LMS_RESPAWN_NONE
then
2794 s
:= _lc
[I_GAME_WARMUP
];
2795 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2796 s
:= s
+ ': ' + IntToStr((gLMSRespawnTime
- gTime
) div 1000);
2797 e_CharFont_PrintEx(gMenuFont
, X
-64-tw
, SY
-32, s
, _RGB(0, 255, 0));
2799 else if gShowLives
and (gGameSettings
.MaxLives
> 0) then
2801 s
:= IntToStr(Lives
);
2802 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2803 e_CharFont_PrintEx(gMenuFont
, X
-16-tw
, SY
-32, s
, _RGB(0, 255, 0));
2807 e_CharFont_GetSize(gMenuSmallFont
, FName
, tw
, th
);
2808 e_CharFont_PrintEx(gMenuSmallFont
, X
+98-(tw
div 2), Y
+8, FName
, _RGB(255, 0, 0));
2810 if R_BERSERK
in FRulez
then
2811 e_Draw(gItemsTexturesID
[ITEM_MEDKIT_BLACK
], X
+37, Y
+45, 0, True, False)
2813 e_Draw(gItemsTexturesID
[ITEM_MEDKIT_LARGE
], X
+37, Y
+45, 0, True, False);
2815 if g_Texture_Get('TEXTURE_PLAYER_ARMORHUD', ID
) then
2816 e_Draw(ID
, X
+36, Y
+77, 0, True, False);
2818 s
:= IntToStr(IfThen(FHealth
> 0, FHealth
, 0));
2819 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2820 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+40, s
, _RGB(255, 0, 0));
2822 s
:= IntToStr(FArmor
);
2823 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2824 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+68, s
, _RGB(255, 0, 0));
2826 s
:= IntToStr(GetAmmoByWeapon(FCurrWeap
));
2832 ID
:= gItemsTexturesID
[ITEM_WEAPON_KASTET
];
2837 ID
:= gItemsTexturesID
[ITEM_WEAPON_SAW
];
2839 WEAPON_PISTOL
: ID
:= gItemsTexturesID
[ITEM_WEAPON_PISTOL
];
2840 WEAPON_CHAINGUN
: ID
:= gItemsTexturesID
[ITEM_WEAPON_CHAINGUN
];
2841 WEAPON_SHOTGUN1
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SHOTGUN1
];
2842 WEAPON_SHOTGUN2
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SHOTGUN2
];
2843 WEAPON_SUPERPULEMET
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SUPERPULEMET
];
2844 WEAPON_ROCKETLAUNCHER
: ID
:= gItemsTexturesID
[ITEM_WEAPON_ROCKETLAUNCHER
];
2845 WEAPON_PLASMA
: ID
:= gItemsTexturesID
[ITEM_WEAPON_PLASMA
];
2846 WEAPON_BFG
: ID
:= gItemsTexturesID
[ITEM_WEAPON_BFG
];
2847 WEAPON_FLAMETHROWER
: ID
:= gItemsTexturesID
[ITEM_WEAPON_FLAMETHROWER
];
2850 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2851 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+158, s
, _RGB(255, 0, 0));
2852 e_Draw(ID
, X
+20, Y
+160, 0, True, False);
2854 if R_KEY_RED
in FRulez
then
2855 e_Draw(gItemsTexturesID
[ITEM_KEY_RED
], X
+78, Y
+214, 0, True, False);
2857 if R_KEY_GREEN
in FRulez
then
2858 e_Draw(gItemsTexturesID
[ITEM_KEY_GREEN
], X
+95, Y
+214, 0, True, False);
2860 if R_KEY_BLUE
in FRulez
then
2861 e_Draw(gItemsTexturesID
[ITEM_KEY_BLUE
], X
+112, Y
+214, 0, True, False);
2863 if FJetFuel
> 0 then
2865 if g_Texture_Get('TEXTURE_PLAYER_HUDAIR', ID
) then
2866 e_Draw(ID
, X
+2, Y
+116, 0, True, False);
2867 if g_Texture_Get('TEXTURE_PLAYER_HUDJET', ID
) then
2868 e_Draw(ID
, X
+2, Y
+126, 0, True, False);
2869 e_DrawLine(4, X
+16, Y
+122, X
+16+Trunc(168*IfThen(FAir
> 0, FAir
, 0)/AIR_MAX
), Y
+122, 0, 0, 196);
2870 e_DrawLine(4, X
+16, Y
+132, X
+16+Trunc(168*FJetFuel
/JET_MAX
), Y
+132, 208, 0, 0);
2874 if g_Texture_Get('TEXTURE_PLAYER_HUDAIR', ID
) then
2875 e_Draw(ID
, X
+2, Y
+124, 0, True, False);
2876 e_DrawLine(4, X
+16, Y
+130, X
+16+Trunc(168*IfThen(FAir
> 0, FAir
, 0)/AIR_MAX
), Y
+130, 0, 0, 196);
2879 if gShowPing
and g_Game_IsClient
then
2881 s
:= _lc
[I_GAME_PING_HUD
] + IntToStr(NetPeer
.lastRoundTripTime
) + _lc
[I_NET_SLIST_PING_MS
];
2882 e_TextureFontPrint(X
+ 4, Y
+ 242, s
, gStdFont
);
2888 e_TextureFontPrint(X
+ 4, Y
+ 242, _lc
[I_PLAYER_SPECT
], gStdFont
);
2889 e_TextureFontPrint(X
+ 4, Y
+ 258, _lc
[I_PLAYER_SPECT2
], gStdFont
);
2890 e_TextureFontPrint(X
+ 4, Y
+ 274, _lc
[I_PLAYER_SPECT1
], gStdFont
);
2893 e_TextureFontGetSize(gStdFont
, cw
, ch
);
2894 s
:= _lc
[I_PLAYER_SPECT4
];
2895 e_TextureFontPrintEx(gScreenWidth
div 2 - cw
*(Length(s
) div 2),
2896 gScreenHeight
-4-ch
, s
, gStdFont
, 255, 255, 255, 1, True);
2897 e_TextureFontPrint(X
+ 4, Y
+ 290, _lc
[I_PLAYER_SPECT1S
], gStdFont
);
2903 procedure TPlayer
.DrawRulez();
2907 // Ïðè âçÿòèè íåóÿçâèìîñòè ðèñóåòñÿ èíâåðñèîííûé áåëûé ôîí
2908 if (FMegaRulez
[MR_INVUL
] >= gTime
) and (FSpawnInvul
< gTime
) then
2910 if (FMegaRulez
[MR_INVUL
]-gTime
) <= 2100 then
2911 dr
:= not Odd((FMegaRulez
[MR_INVUL
]-gTime
) div 300)
2916 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2917 191, 191, 191, 0, TBlending
.Invert
);
2920 // Ïðè âçÿòèè çàùèòíîãî êîñòþìà ðèñóåòñÿ çåëåíîâàòûé ôîí
2921 if FMegaRulez
[MR_SUIT
] >= gTime
then
2923 if (FMegaRulez
[MR_SUIT
]-gTime
) <= 2100 then
2924 dr
:= not Odd((FMegaRulez
[MR_SUIT
]-gTime
) div 300)
2929 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2930 0, 96, 0, 200, TBlending
.None
);
2933 // Ïðè âçÿòèè áåðñåðêà ðèñóåòñÿ êðàñíîâàòûé ôîí
2934 if (FBerserk
>= 0) and (LongWord(FBerserk
) >= gTime
) and (gFlash
= 2) then
2936 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2937 255, 0, 0, 200, TBlending
.None
);
2941 procedure TPlayer
.DrawPain();
2945 if FPain
= 0 then Exit
;
2949 if a
< 15 then h
:= 0
2950 else if a
< 35 then h
:= 1
2951 else if a
< 55 then h
:= 2
2952 else if a
< 75 then h
:= 3
2953 else if a
< 95 then h
:= 4
2956 //if a > 255 then a := 255;
2958 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1, 255, 0, 0, 255-h
*50);
2959 //e_DrawFillQuad(0, 0, gPlayerScreenSize.X-1, gPlayerScreenSize.Y-1, 255-min(128, a), 255-a, 255-a, 0, B_FILTER);
2962 procedure TPlayer
.DrawPickup();
2966 if FPickup
= 0 then Exit
;
2970 if a
< 15 then h
:= 1
2971 else if a
< 35 then h
:= 2
2972 else if a
< 55 then h
:= 3
2973 else if a
< 75 then h
:= 4
2976 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1, 150, 200, 150, 255-h
*50);
2979 procedure TPlayer
.DoPunch();
2984 if FPunchAnim
<> nil then begin
2989 st
:= 'FRAMES_PUNCH';
2990 if R_BERSERK
in FRulez
then
2991 st
:= st
+ '_BERSERK';
2992 if FKeys
[KEY_UP
].Pressed
then
2994 else if FKeys
[KEY_DOWN
].Pressed
then
2996 g_Frames_Get(id
, st
);
2997 FPunchAnim
:= TAnimation
.Create(id
, False, 1);
3000 procedure TPlayer
.Fire();
3002 f
, DidFire
: Boolean;
3003 wx
, wy
, xd
, yd
: Integer;
3006 if g_Game_IsClient
then Exit
;
3007 // FBFGFireCounter - âðåìÿ ïåðåä âûñòðåëîì (äëÿ BFG)
3008 // FReloading - âðåìÿ ïîñëå âûñòðåëà (äëÿ âñåãî)
3016 if FReloading
[FCurrWeap
] <> 0 then Exit
;
3021 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
3022 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
3023 xd
:= wx
+IfThen(FDirection
= TDirection
.D_LEFT
, -30, 30);
3024 yd
:= wy
+firediry();
3030 if R_BERSERK
in FRulez
then
3032 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
3033 locobj
.X
:= FObj
.X
+FObj
.Rect
.X
;
3034 locobj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
3037 locobj
.rect
.Width
:= 39;
3038 locobj
.rect
.Height
:= 52;
3039 locobj
.Vel
.X
:= (xd
-wx
) div 2;
3040 locobj
.Vel
.Y
:= (yd
-wy
) div 2;
3041 locobj
.Accel
.X
:= xd
-wx
;
3042 locobj
.Accel
.y
:= yd
-wy
;
3044 if g_Weapon_Hit(@locobj
, 50, FUID
, HIT_SOME
) <> 0 then
3045 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
3047 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
3049 if (gFlash
= 1) and (FPain
< 50) then FPain
:= min(FPain
+ 25, 50);
3053 g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
3057 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3062 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
3063 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
3065 FSawSoundSelect
.Stop();
3067 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
3069 else if not FSawSoundHit
.IsPlaying() then
3071 FSawSoundSelect
.Stop();
3072 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
3075 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3081 if FAmmo
[A_BULLETS
] > 0 then
3083 g_Weapon_pistol(wx
, wy
, xd
, yd
, FUID
);
3084 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3085 Dec(FAmmo
[A_BULLETS
]);
3086 FFireAngle
:= FAngle
;
3089 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
3090 GameVelX
, GameVelY
-2, SHELL_BULLET
);
3094 if FAmmo
[A_SHELLS
] > 0 then
3096 g_Weapon_shotgun(wx
, wy
, xd
, yd
, FUID
);
3097 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', wx
, wy
);
3098 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3099 Dec(FAmmo
[A_SHELLS
]);
3100 FFireAngle
:= FAngle
;
3104 FShellType
:= SHELL_SHELL
;
3108 if FAmmo
[A_SHELLS
] >= 2 then
3110 g_Weapon_dshotgun(wx
, wy
, xd
, yd
, FUID
);
3111 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3112 Dec(FAmmo
[A_SHELLS
], 2);
3113 FFireAngle
:= FAngle
;
3117 FShellType
:= SHELL_DBLSHELL
;
3121 if FAmmo
[A_BULLETS
] > 0 then
3123 g_Weapon_mgun(wx
, wy
, xd
, yd
, FUID
);
3124 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', wx
, wy
);
3125 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3126 Dec(FAmmo
[A_BULLETS
]);
3127 FFireAngle
:= FAngle
;
3130 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
3131 GameVelX
, GameVelY
-2, SHELL_BULLET
);
3134 WEAPON_ROCKETLAUNCHER
:
3135 if FAmmo
[A_ROCKETS
] > 0 then
3137 g_Weapon_rocket(wx
, wy
, xd
, yd
, FUID
);
3138 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3139 Dec(FAmmo
[A_ROCKETS
]);
3140 FFireAngle
:= FAngle
;
3146 if FAmmo
[A_CELLS
] > 0 then
3148 g_Weapon_plasma(wx
, wy
, xd
, yd
, FUID
);
3149 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3150 Dec(FAmmo
[A_CELLS
]);
3151 FFireAngle
:= FAngle
;
3157 if (FAmmo
[A_CELLS
] >= 40) and (FBFGFireCounter
= -1) then
3159 FBFGFireCounter
:= 17;
3160 if not FNoReload
then
3161 g_Sound_PlayExAt('SOUND_WEAPON_STARTFIREBFG', FObj
.X
, FObj
.Y
);
3162 Dec(FAmmo
[A_CELLS
], 40);
3166 WEAPON_SUPERPULEMET
:
3167 if FAmmo
[A_SHELLS
] > 0 then
3169 g_Weapon_shotgun(wx
, wy
, xd
, yd
, FUID
);
3170 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', wx
, wy
);
3171 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3172 Dec(FAmmo
[A_SHELLS
]);
3173 FFireAngle
:= FAngle
;
3176 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
3177 GameVelX
, GameVelY
-2, SHELL_SHELL
);
3180 WEAPON_FLAMETHROWER
:
3181 if FAmmo
[A_FUEL
] > 0 then
3183 g_Weapon_flame(wx
, wy
, xd
, yd
, FUID
);
3185 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3187 FFireAngle
:= FAngle
;
3194 if g_Game_IsNet
and g_Game_IsServer
then MH_SEND_PlayerStats(FUID
);
3198 if g_Game_IsNet
then
3202 if FCurrWeap
<> WEAPON_BFG
then
3203 MH_SEND_PlayerFire(FUID
, FCurrWeap
, wx
, wy
, xd
, yd
, LastShotID
)
3205 if not FNoReload
then
3206 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_WEAPON_STARTFIREBFG');
3209 MH_SEND_PlayerStats(FUID
);
3214 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
3215 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
3216 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
3219 function TPlayer
.GetAmmoByWeapon(Weapon
: Byte): Word;
3222 WEAPON_PISTOL
, WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
];
3223 WEAPON_SHOTGUN1
, WEAPON_SHOTGUN2
, WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
];
3224 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
];
3225 WEAPON_PLASMA
, WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
];
3226 WEAPON_FLAMETHROWER
: Result
:= FAmmo
[A_FUEL
];
3231 function TPlayer
.HeadInLiquid(XInc
, YInc
: Integer): Boolean;
3233 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
+XInc
, FObj
.Y
+PLAYER_HEADRECT
.Y
+YInc
,
3234 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
3235 PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, True);
3238 procedure TPlayer
.FlamerOn
;
3240 FFlameSoundOff
.Stop();
3241 FFlameSoundOff
.SetPosition(0);
3244 if (not FFlameSoundOn
.IsPlaying()) and (not FFlameSoundWork
.IsPlaying()) then
3245 FFlameSoundWork
.PlayAt(FObj
.X
, FObj
.Y
);
3249 FFlameSoundOn
.PlayAt(FObj
.X
, FObj
.Y
);
3254 procedure TPlayer
.FlamerOff
;
3258 FFlameSoundOn
.Stop();
3259 FFlameSoundOn
.SetPosition(0);
3260 FFlameSoundWork
.Stop();
3261 FFlameSoundWork
.SetPosition(0);
3262 FFlameSoundOff
.PlayAt(FObj
.X
, FObj
.Y
);
3267 procedure TPlayer
.JetpackOn
;
3271 FJetSoundOn
.SetPosition(0);
3272 FJetSoundOn
.PlayAt(FObj
.X
, FObj
.Y
);
3276 procedure TPlayer
.JetpackOff
;
3280 FJetSoundOff
.SetPosition(0);
3281 FJetSoundOff
.PlayAt(FObj
.X
, FObj
.Y
);
3284 procedure TPlayer
.CatchFire(Attacker
: Word; Timeout
: Integer = PLAYER_BURN_TIME
);
3286 if Timeout
<= 0 then
3288 if (FMegaRulez
[MR_SUIT
] > gTime
) or (FMegaRulez
[MR_INVUL
] > gTime
) then
3289 exit
; // Íå çàãîðàåìñÿ êîãäà åñòü çàùèòà
3290 if g_Obj_CollidePanel(@FObj
, 0, 0, PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
) then
3291 exit
; // Íå ïîäãîðàåì â âîäå íà âñÿêèé ñëó÷àé
3292 if FFireTime
<= 0 then
3293 g_Sound_PlayExAt('SOUND_IGNITE', FObj
.X
, FObj
.Y
);
3294 FFireTime
:= Timeout
;
3295 FFireAttacker
:= Attacker
;
3296 if g_Game_IsNet
and g_Game_IsServer
then
3297 MH_SEND_PlayerStats(FUID
);
3300 procedure TPlayer
.Jump();
3302 if gFly
or FJetpack
then
3304 // Ïîëåò (÷èò-êîä èëè äæåòïàê):
3305 if FObj
.Vel
.Y
> -VEL_FLY
then
3306 FObj
.Vel
.Y
:= FObj
.Vel
.Y
- 3;
3309 if FJetFuel
> 0 then
3311 if (FJetFuel
< 1) and g_Game_IsServer
then
3315 if g_Game_IsNet
then
3316 MH_SEND_PlayerStats(FUID
);
3322 // Íå âêëþ÷àòü äæåòïàê â ðåæèìå ïðîõîæäåíèÿ ñêâîçü ñòåíû
3324 FCanJetpack
:= False;
3326 // Ïðûãàåì èëè âñïëûâàåì:
3327 if (CollideLevel(0, 1) or
3328 g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
+36, PLAYER_RECT
.Width
,
3329 PLAYER_RECT
.Height
-33, PANEL_STEP
, False)
3330 ) and (FObj
.Accel
.Y
= 0) then // Íå ïðûãàòü, åñëè åñòü âåðòèêàëüíîå óñêîðåíèå
3332 FObj
.Vel
.Y
:= -VEL_JUMP
;
3333 FCanJetpack
:= False;
3337 if BodyInLiquid(0, 0) then
3338 FObj
.Vel
.Y
:= -VEL_SW
3339 else if (FJetFuel
> 0) and FCanJetpack
and
3340 g_Game_IsServer
and (not g_Obj_CollideLiquid(@FObj
, 0, 0)) then
3344 if g_Game_IsNet
then
3345 MH_SEND_PlayerStats(FUID
);
3350 procedure TPlayer
.Kill(KillType
: Byte; SpawnerUID
: Word; t
: Byte);
3352 a
, i
, k
, ab
, ar
: Byte;
3356 srv
, netsrv
: Boolean;
3362 procedure PushItem(t
: Byte);
3366 id
:= g_Items_Create(FObj
.X
, FObj
.Y
, t
, True, False);
3367 it
:= g_Items_ByIdx(id
);
3368 if KillType
= K_EXTRAHARDKILL
then // -7..+7; -8..0
3370 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-7+Random(15),
3371 (FObj
.Vel
.Y
div 2)-Random(9));
3372 it
.positionChanged(); // this updates spatial accelerators
3376 if KillType
= K_HARDKILL
then // -5..+5; -5..0
3378 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-5+Random(11),
3379 (FObj
.Vel
.Y
div 2)-Random(6));
3381 else // -3..+3; -3..0
3383 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-3+Random(7),
3384 (FObj
.Vel
.Y
div 2)-Random(4));
3386 it
.positionChanged(); // this updates spatial accelerators
3389 if g_Game_IsNet
and g_Game_IsServer
then
3390 MH_SEND_ItemSpawn(True, id
);
3394 DoFrags
:= (gGameSettings
.MaxLives
= 0) or (gGameSettings
.GameMode
= GM_COOP
);
3395 Srv
:= g_Game_IsServer
;
3396 Netsrv
:= g_Game_IsServer
and g_Game_IsNet
;
3397 if Srv
then FDeath
:= FDeath
+ 1;
3402 if not FPhysics
then
3408 if (gGameSettings
.MaxLives
> 0) and Srv
and (gLMSRespawn
= LMS_RESPAWN_NONE
) then
3410 if FLives
> 0 then FLives
:= FLives
- 1;
3411 if FLives
= 0 then FNoRespawn
:= True;
3414 // Íîìåð òèïà ñìåðòè:
3417 K_SIMPLEKILL
: a
:= 1;
3419 K_EXTRAHARDKILL
: a
:= 3;
3424 if not FModel
.PlaySound(MODELSOUND_DIE
, a
, FObj
.X
, FObj
.Y
) then
3426 if FModel
.PlaySound(MODELSOUND_DIE
, i
, FObj
.X
, FObj
.Y
) then
3433 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN1
;
3435 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN2
;
3436 K_EXTRAHARDKILL
, K_FALLKILL
:
3437 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN3
;
3440 // Ïåðåêëþ÷àåì ñîñòîÿíèå:
3444 K_HARDKILL
, K_EXTRAHARDKILL
:
3448 // Ðåàêöèÿ ìîíñòðîâ íà ñìåðòü èãðîêà:
3449 if (KillType
<> K_FALLKILL
) and (Srv
) then
3450 g_Monsters_killedp();
3452 if SpawnerUID
= FUID
then
3456 if gGameSettings
.GameMode
= GM_TDM
then
3457 Dec(gTeamStat
[FTeam
].Goals
);
3458 if DoFrags
or (gGameSettings
.GameMode
= GM_TDM
) then
3464 g_Console_Add(Format(_lc
[I_PLAYER_KILL_SELF
], [FName
]), True);
3467 if g_GetUIDType(SpawnerUID
) = UID_PLAYER
then
3468 begin // Óáèò äðóãèì èãðîêîì
3469 KP
:= g_Player_Get(SpawnerUID
);
3470 if (KP
<> nil) and Srv
then
3472 if (DoFrags
or (gGameSettings
.GameMode
= GM_TDM
)) then
3473 if SameTeam(FUID
, SpawnerUID
) then
3483 if (gGameSettings
.GameMode
= GM_TDM
) and DoFrags
then
3484 Inc(gTeamStat
[KP
.Team
].Goals
,
3485 IfThen(SameTeam(FUID
, SpawnerUID
), -1, 1));
3487 if netsrv
then MH_SEND_PlayerStats(SpawnerUID
);
3490 plr
:= g_Player_Get(SpawnerUID
);
3498 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_2
],
3502 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_1
],
3506 g_Console_Add(Format(_lc
[I_PLAYER_KILL
],
3511 else if g_GetUIDType(SpawnerUID
) = UID_MONSTER
then
3512 begin // Óáèò ìîíñòðîì
3513 mon
:= g_Monsters_ByUID(SpawnerUID
);
3517 s
:= g_Mons_GetKilledByTypeId(mon
.MonsterType
);
3521 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_2
],
3525 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_1
],
3529 g_Console_Add(Format(_lc
[I_PLAYER_KILL
],
3534 else // Îñîáûå òèïû ñìåðòè
3537 HIT_SELF
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_SELF
], [FName
]), True);
3538 HIT_FALL
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_FALL
], [FName
]), True);
3539 HIT_WATER
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_WATER
], [FName
]), True);
3540 HIT_ACID
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_ACID
], [FName
]), True);
3541 HIT_TRAP
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_TRAP
], [FName
]), True);
3542 else g_Console_Add(Format(_lc
[I_PLAYER_DIED
], [FName
]), True);
3548 for a
:= WP_FIRST
to WP_LAST
do
3552 WEAPON_SAW
: i
:= ITEM_WEAPON_SAW
;
3553 WEAPON_SHOTGUN1
: i
:= ITEM_WEAPON_SHOTGUN1
;
3554 WEAPON_SHOTGUN2
: i
:= ITEM_WEAPON_SHOTGUN2
;
3555 WEAPON_CHAINGUN
: i
:= ITEM_WEAPON_CHAINGUN
;
3556 WEAPON_ROCKETLAUNCHER
: i
:= ITEM_WEAPON_ROCKETLAUNCHER
;
3557 WEAPON_PLASMA
: i
:= ITEM_WEAPON_PLASMA
;
3558 WEAPON_BFG
: i
:= ITEM_WEAPON_BFG
;
3559 WEAPON_SUPERPULEMET
: i
:= ITEM_WEAPON_SUPERPULEMET
;
3560 WEAPON_FLAMETHROWER
: i
:= ITEM_WEAPON_FLAMETHROWER
;
3569 if R_ITEM_BACKPACK
in FRulez
then
3570 PushItem(ITEM_AMMO_BACKPACK
);
3572 // Âûáðîñ ðàêåòíîãî ðàíöà:
3573 if FJetFuel
> 0 then
3574 PushItem(ITEM_JETPACK
);
3577 if (not (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
])) or
3578 (not LongBool(gGameSettings
.Options
and GAME_OPTION_DMKEYS
)) then
3580 if R_KEY_RED
in FRulez
then
3581 PushItem(ITEM_KEY_RED
);
3583 if R_KEY_GREEN
in FRulez
then
3584 PushItem(ITEM_KEY_GREEN
);
3586 if R_KEY_BLUE
in FRulez
then
3587 PushItem(ITEM_KEY_BLUE
);
3591 DropFlag(KillType
= K_FALLKILL
);
3594 FCorpse
:= g_Player_CreateCorpse(Self
);
3596 if Srv
and (gGameSettings
.MaxLives
> 0) and FNoRespawn
and
3597 (gLMSRespawn
= LMS_RESPAWN_NONE
) then
3603 for i
:= Low(gPlayers
) to High(gPlayers
) do
3605 if gPlayers
[i
] = nil then continue
;
3606 if (not gPlayers
[i
].FNoRespawn
) and (not gPlayers
[i
].FSpectator
) then
3609 if gPlayers
[i
].FTeam
= TEAM_RED
then Inc(ar
)
3610 else if gPlayers
[i
].FTeam
= TEAM_BLUE
then Inc(ab
);
3615 OldLR
:= gLMSRespawn
;
3616 if (gGameSettings
.GameMode
= GM_COOP
) then
3620 // everyone is dead, restart the map
3621 g_Game_Message(_lc
[I_MESSAGE_LMS_LOSE
], 144);
3623 MH_SEND_GameEvent(NET_EV_LMS_LOSE
);
3624 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3625 gLMSRespawnTime
:= gTime
+ 5000;
3627 else if (a
= 1) then
3629 if (gPlayers
[k
] <> nil) and not (gPlayers
[k
] is TBot
) then
3630 if (gPlayers
[k
] = gPlayer1
) or
3631 (gPlayers
[k
] = gPlayer2
) then
3632 g_Console_Add('*** ' + _lc
[I_MESSAGE_LMS_SURVIVOR
] + ' ***', True)
3633 else if Netsrv
and (gPlayers
[k
].FClientID
>= 0) then
3634 MH_SEND_GameEvent(NET_EV_LMS_SURVIVOR
, 0, 'N', gPlayers
[k
].FClientID
);
3637 else if (gGameSettings
.GameMode
= GM_TDM
) then
3639 if (ab
= 0) and (ar
<> 0) then
3642 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 144);
3644 MH_SEND_GameEvent(NET_EV_TLMS_WIN
, TEAM_RED
);
3645 Inc(gTeamStat
[TEAM_RED
].Goals
);
3646 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3647 gLMSRespawnTime
:= gTime
+ 5000;
3649 else if (ar
= 0) and (ab
<> 0) then
3652 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 144);
3654 MH_SEND_GameEvent(NET_EV_TLMS_WIN
, TEAM_BLUE
);
3655 Inc(gTeamStat
[TEAM_BLUE
].Goals
);
3656 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3657 gLMSRespawnTime
:= gTime
+ 5000;
3659 else if (ar
= 0) and (ab
= 0) then
3662 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
3664 MH_SEND_GameEvent(NET_EV_LMS_DRAW
, 0, FName
);
3665 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3666 gLMSRespawnTime
:= gTime
+ 5000;
3669 else if (gGameSettings
.GameMode
= GM_DM
) then
3673 if gPlayers
[k
] <> nil then
3676 // survivor is the winner
3677 g_Game_Message(Format(_lc
[I_MESSAGE_LMS_WIN
], [AnsiUpperCase(FName
)]), 144);
3679 MH_SEND_GameEvent(NET_EV_LMS_WIN
, 0, FName
);
3682 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3683 gLMSRespawnTime
:= gTime
+ 5000;
3685 else if (a
= 0) then
3687 // everyone is dead, restart the map
3688 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
3690 MH_SEND_GameEvent(NET_EV_LMS_DRAW
, 0, FName
);
3691 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3692 gLMSRespawnTime
:= gTime
+ 5000;
3695 if srv
and (OldLR
= LMS_RESPAWN_NONE
) and (gLMSRespawn
> LMS_RESPAWN_NONE
) then
3697 if NetMode
= NET_SERVER
then
3698 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
)
3700 g_Console_Add(Format(_lc
[I_MSG_WARMUP_START
], [(gLMSRespawnTime
- gTime
) div 1000]), True);
3706 MH_SEND_PlayerStats(FUID
);
3707 MH_SEND_PlayerDeath(FUID
, KillType
, t
, SpawnerUID
);
3708 if gGameSettings
.GameMode
= GM_TDM
then MH_SEND_GameStats
;
3711 if srv
and FNoRespawn
then Spectate(True);
3712 FWantsInGame
:= True;
3715 function TPlayer
.BodyInLiquid(XInc
, YInc
: Integer): Boolean;
3717 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
, PLAYER_RECT
.Width
,
3718 PLAYER_RECT
.Height
-20, PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, False);
3721 function TPlayer
.BodyInAcid(XInc
, YInc
: Integer): Boolean;
3723 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
, PLAYER_RECT
.Width
,
3724 PLAYER_RECT
.Height
-20, PANEL_ACID1
or PANEL_ACID2
, False);
3727 procedure TPlayer
.MakeBloodSimple(Count
: Word);
3729 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)+8,
3730 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3731 Count
div 2, 3, -1, 16, (PLAYER_RECT
.Height
*2 div 3),
3732 FModel
.Blood
.R
, FModel
.Blood
.G
, FModel
.Blood
.B
, FModel
.Blood
.Kind
);
3733 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-8,
3734 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3735 Count
div 2, -3, -1, 16, (PLAYER_RECT
.Height
*2) div 3,
3736 FModel
.Blood
.R
, FModel
.Blood
.G
, FModel
.Blood
.B
, FModel
.Blood
.Kind
);
3739 procedure TPlayer
.MakeBloodVector(Count
: Word; VelX
, VelY
: Integer);
3741 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
3742 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3743 Count
, VelX
, VelY
, 16, (PLAYER_RECT
.Height
*2) div 3,
3744 FModel
.Blood
.R
, FModel
.Blood
.G
, FModel
.Blood
.B
, FModel
.Blood
.Kind
);
3747 procedure TPlayer
.ProcessWeaponAction(Action
: Byte);
3749 if g_Game_IsClient
then Exit
;
3751 WP_PREV
: PrevWeapon();
3752 WP_NEXT
: NextWeapon();
3756 procedure TPlayer
.QueueWeaponSwitch(Weapon
: Byte);
3758 if g_Game_IsClient
then Exit
;
3759 if Weapon
> High(FWeapon
) then Exit
;
3760 FNextWeap
:= FNextWeap
or (1 shl Weapon
);
3763 procedure TPlayer
.resetWeaponQueue ();
3766 FNextWeapDelay
:= 0;
3769 function TPlayer
.hasAmmoForWeapon (weapon
: Byte): Boolean;
3773 WEAPON_KASTET
, WEAPON_SAW
: result
:= true;
3774 WEAPON_SHOTGUN1
, WEAPON_SHOTGUN2
, WEAPON_SUPERPULEMET
: result
:= (FAmmo
[A_SHELLS
] > 0);
3775 WEAPON_PISTOL
, WEAPON_CHAINGUN
: result
:= (FAmmo
[A_BULLETS
] > 0);
3776 WEAPON_ROCKETLAUNCHER
: result
:= (FAmmo
[A_ROCKETS
] > 0);
3777 WEAPON_PLASMA
, WEAPON_BFG
: result
:= (FAmmo
[A_CELLS
] > 0);
3778 WEAPON_FLAMETHROWER
: result
:= (FAmmo
[A_FUEL
] > 0);
3779 else result
:= (weapon
< length(FWeapon
));
3783 function TPlayer
.shouldSwitch (weapon
: Byte; hadWeapon
: Boolean): Boolean;
3786 if (weapon
< 0) or (weapon
> WP_LAST
+ 1) then
3791 if (FWeapSwitchMode
= 1) and not hadWeapon
then
3793 else if (FWeapSwitchMode
= 2) then
3794 result
:= (FWeapPreferences
[weapon
] > FWeapPreferences
[FCurrWeap
]);
3797 // return 255 for "no switch"
3798 function TPlayer
.getNextWeaponIndex (): Byte;
3801 wantThisWeapon
: array[0..64] of Boolean;
3802 wwc
: Integer = 0; //HACK!
3805 result
:= 255; // default result: "no switch"
3806 //e_LogWriteFln('FSWITCHTOEMPTY: %s', [FSwitchToEmpty], TMsgType.Notify);
3807 // had weapon cycling on previous frame? remove that flag
3808 if (FNextWeap
and $2000) <> 0 then
3810 FNextWeap
:= FNextWeap
and $1FFF;
3811 FNextWeapDelay
:= 0;
3813 // cycling has priority
3814 if (FNextWeap
and $C000) <> 0 then
3816 if (FNextWeap
and $8000) <> 0 then
3820 FNextWeap
:= FNextWeap
or $2000; // we need this
3821 if FNextWeapDelay
> 0 then
3822 exit
; // cooldown time
3824 for i
:= 0 to High(FWeapon
) do
3826 cwi
:= (cwi
+length(FWeapon
)+dir
) mod length(FWeapon
);
3827 if FWeapon
[cwi
] and maySwitch(cwi
) then
3829 //e_LogWriteFln(' SWITCH: cur=%d; new=%d %s %s', [FCurrWeap, cwi, FSwitchToEmpty, hasAmmoForWeapon(cwi)], TMsgType.Notify);
3830 result
:= Byte(cwi
);
3831 FNextWeapDelay
:= WEAPON_DELAY
;
3839 for i
:= 0 to High(wantThisWeapon
) do
3840 wantThisWeapon
[i
] := false;
3841 for i
:= 0 to High(FWeapon
) do
3842 if (FNextWeap
and (1 shl i
)) <> 0 then
3844 wantThisWeapon
[i
] := true;
3848 // exclude currently selected weapon from the set
3849 wantThisWeapon
[FCurrWeap
] := false;
3850 // slow down alterations a little
3853 //e_WriteLog(Format(' FNextWeap=%x; delay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
3854 // more than one weapon requested, assume "alteration" and check alteration delay
3855 if FNextWeapDelay
> 0 then
3861 // do not reset weapon queue, it will be done in `RealizeCurrentWeapon()`
3862 // but clear all counters if no weapon should be switched
3868 //e_WriteLog(Format('wwc=%d', [wwc]), MSG_WARNING);
3869 // try weapons in descending order
3870 for i
:= High(FWeapon
) downto 0 do
3872 if wantThisWeapon
[i
] and FWeapon
[i
] and ((wwc
= 1) or hasAmmoForWeapon(i
)) then
3877 FNextWeapDelay
:= WEAPON_DELAY
* 2; // anyway, 'cause why not
3878 //e_LogWriteFln('FOUND %s %s %s', [result, FSwitchToEmpty, hasAmmoForWeapon(i)], TMsgType.Notify);
3882 // no suitable weapon found, so reset the queue, to avoid accidental "queuing" of weapon w/o ammo
3886 procedure TPlayer
.RealizeCurrentWeapon();
3887 function switchAllowed (): Boolean;
3892 if FBFGFireCounter
<> -1 then
3894 if FTime
[T_SWITCH
] > gTime
then
3896 for i
:= WP_FIRST
to WP_LAST
do
3897 if FReloading
[i
] > 0 then
3905 //e_WriteLog(Format('***RealizeCurrentWeapon: FNextWeap=%x; FNextWeapDelay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
3906 //FNextWeap := FNextWeap and $1FFF;
3907 if FNextWeapDelay
> 0 then Dec(FNextWeapDelay
); // "alteration delay"
3909 if not switchAllowed
then
3911 //HACK for weapon cycling
3912 if (FNextWeap
and $E000) <> 0 then FNextWeap
:= 0;
3916 nw
:= getNextWeaponIndex();
3918 if nw
= 255 then exit
; // don't reset anything here
3919 if nw
> High(FWeapon
) then
3921 // don't forget to reset queue here!
3922 //e_WriteLog(' RealizeCurrentWeapon: WUTAFUUUU', MSG_WARNING);
3930 FTime
[T_SWITCH
] := gTime
+156;
3931 if FCurrWeap
= WEAPON_SAW
then FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3932 FModel
.SetWeapon(FCurrWeap
);
3933 if g_Game_IsNet
then MH_SEND_PlayerStats(FUID
);
3937 procedure TPlayer
.NextWeapon();
3939 if g_Game_IsClient
then Exit
;
3943 procedure TPlayer
.PrevWeapon();
3945 if g_Game_IsClient
then Exit
;
3949 procedure TPlayer
.SetWeapon(W
: Byte);
3951 if FCurrWeap
<> W
then
3952 if W
= WEAPON_SAW
then
3953 FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3956 FModel
.SetWeapon(CurrWeap
);
3960 function TPlayer
.PickItem(ItemType
: Byte; arespawn
: Boolean; var remove
: Boolean): Boolean;
3962 function allowBerserkSwitching (): Boolean;
3964 if (FBFGFireCounter
<> -1) then begin result
:= false; exit
; end;
3966 if gBerserkAutoswitch
then exit
;
3967 if not conIsCheatsEnabled
then exit
;
3973 switchWeapon
: Byte = -1;
3974 hadWeapon
: Boolean = False;
3977 if g_Game_IsClient
then Exit
;
3979 // a = true - ìåñòî ñïàâíà ïðåäìåòà:
3980 a
:= LongBool(gGameSettings
.Options
and GAME_OPTION_WEAPONSTAY
) and arespawn
;
3984 if (FHealth
< PLAYER_HP_SOFT
) or (FFireTime
> 0) then
3986 if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
3990 if gFlash
= 2 then Inc(FPickup
, 5);
3994 if (FHealth
< PLAYER_HP_SOFT
) or (FFireTime
> 0) then
3996 if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
4000 if gFlash
= 2 then Inc(FPickup
, 5);
4004 if FArmor
< PLAYER_AP_SOFT
then
4006 FArmor
:= PLAYER_AP_SOFT
;
4009 if gFlash
= 2 then Inc(FPickup
, 5);
4013 if FArmor
< PLAYER_AP_LIMIT
then
4015 FArmor
:= PLAYER_AP_LIMIT
;
4018 if gFlash
= 2 then Inc(FPickup
, 5);
4022 if (FHealth
< PLAYER_HP_LIMIT
) or (FFireTime
> 0) then
4024 if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
4028 if gFlash
= 2 then Inc(FPickup
, 5);
4032 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) or (FFireTime
> 0) then
4034 if FHealth
< PLAYER_HP_LIMIT
then
4035 FHealth
:= PLAYER_HP_LIMIT
;
4036 if FArmor
< PLAYER_AP_LIMIT
then
4037 FArmor
:= PLAYER_AP_LIMIT
;
4041 if gFlash
= 2 then Inc(FPickup
, 5);
4045 if (not FWeapon
[WEAPON_SAW
]) or ((not arespawn
) and (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
])) then
4047 hadWeapon
:= FWeapon
[WEAPON_SAW
];
4048 switchWeapon
:= WEAPON_SAW
;
4049 FWeapon
[WEAPON_SAW
] := True;
4051 if gFlash
= 2 then Inc(FPickup
, 5);
4052 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4055 ITEM_WEAPON_SHOTGUN1
:
4056 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN1
] then
4058 // Íóæíî, ÷òîáû íå âçÿòü âñå ïóëè ñðàçó:
4059 if a
and FWeapon
[WEAPON_SHOTGUN1
] then Exit
;
4060 hadWeapon
:= FWeapon
[WEAPON_SHOTGUN1
];
4061 switchWeapon
:= WEAPON_SHOTGUN1
;
4062 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4063 FWeapon
[WEAPON_SHOTGUN1
] := True;
4065 if gFlash
= 2 then Inc(FPickup
, 5);
4066 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4069 ITEM_WEAPON_SHOTGUN2
:
4070 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN2
] then
4072 if a
and FWeapon
[WEAPON_SHOTGUN2
] then Exit
;
4073 hadWeapon
:= FWeapon
[WEAPON_SHOTGUN2
];
4074 switchWeapon
:= WEAPON_SHOTGUN2
;
4075 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4076 FWeapon
[WEAPON_SHOTGUN2
] := True;
4078 if gFlash
= 2 then Inc(FPickup
, 5);
4079 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4082 ITEM_WEAPON_CHAINGUN
:
4083 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or not FWeapon
[WEAPON_CHAINGUN
] then
4085 if a
and FWeapon
[WEAPON_CHAINGUN
] then Exit
;
4086 hadWeapon
:= FWeapon
[WEAPON_CHAINGUN
];
4087 switchWeapon
:= WEAPON_CHAINGUN
;
4088 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
4089 FWeapon
[WEAPON_CHAINGUN
] := True;
4091 if gFlash
= 2 then Inc(FPickup
, 5);
4092 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4095 ITEM_WEAPON_ROCKETLAUNCHER
:
4096 if (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or not FWeapon
[WEAPON_ROCKETLAUNCHER
] then
4098 if a
and FWeapon
[WEAPON_ROCKETLAUNCHER
] then Exit
;
4099 switchWeapon
:= WEAPON_ROCKETLAUNCHER
;
4100 hadWeapon
:= FWeapon
[WEAPON_ROCKETLAUNCHER
];
4101 IncMax(FAmmo
[A_ROCKETS
], 2, FMaxAmmo
[A_ROCKETS
]);
4102 FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
4104 if gFlash
= 2 then Inc(FPickup
, 5);
4105 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4109 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_PLASMA
] then
4111 if a
and FWeapon
[WEAPON_PLASMA
] then Exit
;
4112 switchWeapon
:= WEAPON_PLASMA
;
4113 hadWeapon
:= FWeapon
[WEAPON_PLASMA
];
4114 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
4115 FWeapon
[WEAPON_PLASMA
] := True;
4117 if gFlash
= 2 then Inc(FPickup
, 5);
4118 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4122 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_BFG
] then
4124 if a
and FWeapon
[WEAPON_BFG
] then Exit
;
4125 switchWeapon
:= WEAPON_BFG
;
4126 hadWeapon
:= FWeapon
[WEAPON_BFG
];
4127 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
4128 FWeapon
[WEAPON_BFG
] := True;
4130 if gFlash
= 2 then Inc(FPickup
, 5);
4131 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4134 ITEM_WEAPON_SUPERPULEMET
:
4135 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SUPERPULEMET
] then
4137 if a
and FWeapon
[WEAPON_SUPERPULEMET
] then Exit
;
4138 switchWeapon
:= WEAPON_SUPERPULEMET
;
4139 hadWeapon
:= FWeapon
[WEAPON_SUPERPULEMET
];
4140 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4141 FWeapon
[WEAPON_SUPERPULEMET
] := True;
4143 if gFlash
= 2 then Inc(FPickup
, 5);
4144 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4147 ITEM_WEAPON_FLAMETHROWER
:
4148 if (FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
]) or not FWeapon
[WEAPON_FLAMETHROWER
] then
4150 if a
and FWeapon
[WEAPON_FLAMETHROWER
] then Exit
;
4151 switchWeapon
:= WEAPON_FLAMETHROWER
;
4152 hadWeapon
:= FWeapon
[WEAPON_FLAMETHROWER
];
4153 IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
4154 FWeapon
[WEAPON_FLAMETHROWER
] := True;
4156 if gFlash
= 2 then Inc(FPickup
, 5);
4157 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4161 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
4163 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
4166 if gFlash
= 2 then Inc(FPickup
, 5);
4169 ITEM_AMMO_BULLETS_BOX
:
4170 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
4172 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
4175 if gFlash
= 2 then Inc(FPickup
, 5);
4179 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
4181 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4184 if gFlash
= 2 then Inc(FPickup
, 5);
4187 ITEM_AMMO_SHELLS_BOX
:
4188 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
4190 IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
4193 if gFlash
= 2 then Inc(FPickup
, 5);
4197 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
4199 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
4202 if gFlash
= 2 then Inc(FPickup
, 5);
4205 ITEM_AMMO_ROCKET_BOX
:
4206 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
4208 IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
4211 if gFlash
= 2 then Inc(FPickup
, 5);
4215 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
4217 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
4220 if gFlash
= 2 then Inc(FPickup
, 5);
4224 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
4226 IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
4229 if gFlash
= 2 then Inc(FPickup
, 5);
4233 if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then
4235 IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
4238 if gFlash
= 2 then Inc(FPickup
, 5);
4242 if not(R_ITEM_BACKPACK
in FRulez
) or
4243 (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
4244 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
4245 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
4246 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or
4247 (FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
]) then
4249 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[1, A_BULLETS
];
4250 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[1, A_SHELLS
];
4251 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[1, A_ROCKETS
];
4252 FMaxAmmo
[A_CELLS
] := AmmoLimits
[1, A_CELLS
];
4253 FMaxAmmo
[A_FUEL
] := AmmoLimits
[1, A_FUEL
];
4255 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
4256 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
4257 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
4258 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4259 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
4260 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
4261 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
4262 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
4263 if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then
4264 IncMax(FAmmo
[A_FUEL
], 50, FMaxAmmo
[A_FUEL
]);
4266 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
4269 if gFlash
= 2 then Inc(FPickup
, 5);
4273 if not(R_KEY_RED
in FRulez
) then
4275 Include(FRulez
, R_KEY_RED
);
4277 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
4278 if gFlash
= 2 then Inc(FPickup
, 5);
4279 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
4283 if not(R_KEY_GREEN
in FRulez
) then
4285 Include(FRulez
, R_KEY_GREEN
);
4287 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
4288 if gFlash
= 2 then Inc(FPickup
, 5);
4289 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
4293 if not(R_KEY_BLUE
in FRulez
) then
4295 Include(FRulez
, R_KEY_BLUE
);
4297 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
4298 if gFlash
= 2 then Inc(FPickup
, 5);
4299 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
4303 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
4305 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
4309 if gFlash
= 2 then Inc(FPickup
, 5);
4313 if FAir
< AIR_MAX
then
4318 if gFlash
= 2 then Inc(FPickup
, 5);
4323 if not (R_BERSERK
in FRulez
) then
4325 Include(FRulez
, R_BERSERK
);
4326 if (shouldSwitch(WP_LAST
+ 1, false)) then
4327 QueueWeaponSwitch(WEAPON_KASTET
);
4331 if gFlash
= 2 then Inc(FPickup
, 5);
4333 FBerserk
:= gTime
+30000;
4338 if (FHealth
< PLAYER_HP_SOFT
) or (FFireTime
> 0) then
4340 if FHealth
< PLAYER_HP_SOFT
then FHealth
:= PLAYER_HP_SOFT
;
4341 FBerserk
:= gTime
+30000;
4349 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
4351 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
4355 if gFlash
= 2 then Inc(FPickup
, 5);
4359 if (FHealth
< PLAYER_HP_LIMIT
) or (FFireTime
> 0) then
4361 if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
4365 if gFlash
= 2 then Inc(FPickup
, 5);
4369 if FArmor
< PLAYER_AP_LIMIT
then
4371 IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
4374 if gFlash
= 2 then Inc(FPickup
, 5);
4378 if FJetFuel
< JET_MAX
then
4380 FJetFuel
:= JET_MAX
;
4383 if gFlash
= 2 then Inc(FPickup
, 5);
4387 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
4389 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
4392 if gFlash
= 2 then Inc(FPickup
, 5);
4396 if (shouldSwitch(switchWeapon
, hadWeapon
)) then
4397 QueueWeaponSwitch(switchWeapon
);
4400 procedure TPlayer
.Touch();
4404 //FModel.PlaySound(MODELSOUND_PAIN, 1, FObj.X, FObj.Y);
4407 // Áðîñèòü ôëàã òîâàðèùó:
4408 if gGameSettings
.GameMode
= GM_CTF
then
4413 procedure TPlayer
.Push(vx
, vy
: Integer);
4415 if (not FPhysics
) and FGhost
then
4417 FObj
.Accel
.X
:= FObj
.Accel
.X
+ vx
;
4418 FObj
.Accel
.Y
:= FObj
.Accel
.Y
+ vy
;
4419 if g_Game_IsNet
and g_Game_IsServer
then
4420 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
4423 procedure TPlayer
.Reset(Force
: Boolean);
4429 FTime
[T_RESPAWN
] := 0;
4430 FTime
[T_FLAGCAP
] := 0;
4446 FSpectator
:= False;
4449 FSpectatePlayer
:= -1;
4450 FNoRespawn
:= False;
4452 FLives
:= gGameSettings
.MaxLives
;
4457 procedure TPlayer
.SoftReset();
4465 FBFGFireCounter
:= -1;
4473 SetAction(A_STAND
, True);
4476 function TPlayer
.GetRespawnPoint(): Byte;
4481 // Íà áóäóùåå: FSpawn - èãðîê óæå èãðàë è ïåðåðîæäàåòñÿ
4483 // Îäèíî÷íàÿ èãðà/êîîïåðàòèâ
4484 if gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
] then
4486 if Self
= gPlayer1
then
4488 // player 1 should try to spawn on the player 1 point
4489 if g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) > 0 then
4490 Exit(RESPAWNPOINT_PLAYER1
)
4491 else if g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) > 0 then
4492 Exit(RESPAWNPOINT_PLAYER2
);
4494 else if Self
= gPlayer2
then
4496 // player 2 should try to spawn on the player 2 point
4497 if g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) > 0 then
4498 Exit(RESPAWNPOINT_PLAYER2
)
4499 else if g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) > 0 then
4500 Exit(RESPAWNPOINT_PLAYER1
);
4504 // other players randomly pick either the first or the second point
4505 c
:= IfThen((Random(2) = 0), RESPAWNPOINT_PLAYER1
, RESPAWNPOINT_PLAYER2
);
4506 if g_Map_GetPointCount(c
) > 0 then
4508 // try the other one
4509 c
:= IfThen((c
= RESPAWNPOINT_PLAYER1
), RESPAWNPOINT_PLAYER2
, RESPAWNPOINT_PLAYER1
);
4510 if g_Map_GetPointCount(c
) > 0 then
4516 if gGameSettings
.GameMode
= GM_DM
then
4518 // try DM points first
4519 if g_Map_GetPointCount(RESPAWNPOINT_DM
) > 0 then
4520 Exit(RESPAWNPOINT_DM
);
4524 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
4526 // try team points first
4527 c
:= RESPAWNPOINT_DM
;
4528 if FTeam
= TEAM_RED
then
4529 c
:= RESPAWNPOINT_RED
4530 else if FTeam
= TEAM_BLUE
then
4531 c
:= RESPAWNPOINT_BLUE
;
4532 if g_Map_GetPointCount(c
) > 0 then
4536 // still haven't found a spawnpoint, try random shit
4537 Result
:= g_Map_GetRandomPointType();
4540 procedure TPlayer
.Respawn(Silent
: Boolean; Force
: Boolean = False);
4542 RespawnPoint
: TRespawnPoint
;
4550 FBFGFireCounter
:= -1;
4557 if not g_Game_IsServer
then
4561 FWantsInGame
:= True;
4562 FJustTeleported
:= True;
4565 FTime
[T_RESPAWN
] := 0;
4569 // if server changes MaxLives we gotta be ready
4570 if gGameSettings
.MaxLives
= 0 then FNoRespawn
:= False;
4572 // Åùå íåëüçÿ âîçðîäèòüñÿ:
4573 if FTime
[T_RESPAWN
] > gTime
then
4576 // Ïðîñðàë âñå æèçíè:
4579 if not FSpectator
then Spectate(True);
4580 FWantsInGame
:= True;
4584 if (gGameSettings
.GameType
<> GT_SINGLE
) and (gGameSettings
.GameMode
<> GM_COOP
) then
4585 begin // "Ñâîÿ èãðà"
4586 // Áåðñåðê íå ñîõðàíÿåòñÿ ìåæäó óðîâíÿìè:
4587 FRulez
:= FRulez
-[R_BERSERK
];
4589 else // "Îäèíî÷íàÿ èãðà"/"Êîîï"
4591 // Áåðñåðê è êëþ÷è íå ñîõðàíÿþòñÿ ìåæäó óðîâíÿìè:
4592 FRulez
:= FRulez
-[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
, R_BERSERK
];
4595 // Ïîëó÷àåì òî÷êó ñïàóíà èãðîêà:
4596 c
:= GetRespawnPoint();
4601 // Âîñêðåøåíèå áåç îðóæèÿ:
4604 FHealth
:= Round(PLAYER_HP_SOFT
* (FHandicap
/ 100));
4610 for a
:= WP_FIRST
to WP_LAST
do
4612 FWeapon
[a
] := False;
4616 FWeapon
[WEAPON_PISTOL
] := True;
4617 FWeapon
[WEAPON_KASTET
] := True;
4618 FCurrWeap
:= WEAPON_PISTOL
;
4621 FModel
.SetWeapon(FCurrWeap
);
4623 for b
:= A_BULLETS
to A_HIGH
do
4626 FAmmo
[A_BULLETS
] := 50;
4628 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[0, A_BULLETS
];
4629 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[0, A_SHELLS
];
4630 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[0, A_SHELLS
];
4631 FMaxAmmo
[A_CELLS
] := AmmoLimits
[0, A_CELLS
];
4632 FMaxAmmo
[A_FUEL
] := AmmoLimits
[0, A_FUEL
];
4634 if (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
]) and
4635 LongBool(gGameSettings
.Options
and GAME_OPTION_DMKEYS
) then
4636 FRulez
:= [R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
]
4641 // Ïîëó÷àåì êîîðäèíàòû òî÷êè âîçðîæäåíèÿ:
4642 if not g_Map_GetPoint(c
, RespawnPoint
) then
4644 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
4648 // Óñòàíîâêà êîîðäèíàò è ñáðîñ âñåõ ïàðàìåòðîâ:
4649 FObj
.X
:= RespawnPoint
.X
-PLAYER_RECT
.X
;
4650 FObj
.Y
:= RespawnPoint
.Y
-PLAYER_RECT
.Y
;
4651 FObj
.oldX
:= FObj
.X
; // don't interpolate after respawn
4652 FObj
.oldY
:= FObj
.Y
;
4658 FDirection
:= RespawnPoint
.Direction
;
4659 if FDirection
= TDirection
.D_LEFT
then
4664 SetAction(A_STAND
, True);
4665 FModel
.Direction
:= FDirection
;
4667 for a
:= Low(FTime
) to High(FTime
) do
4670 for a
:= Low(FMegaRulez
) to High(FMegaRulez
) do
4673 // Respawn invulnerability
4674 if (gGameSettings
.GameType
<> GT_SINGLE
) and (gGameSettings
.SpawnInvul
> 0) then
4676 FMegaRulez
[MR_INVUL
] := gTime
+ gGameSettings
.SpawnInvul
* 1000;
4677 FSpawnInvul
:= FMegaRulez
[MR_INVUL
];
4682 FCanJetpack
:= False;
4688 // Àíèìàöèÿ âîçðîæäåíèÿ:
4689 if (not gLoadGameMode
) and (not Silent
) then
4690 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
4692 Anim
:= TAnimation
.Create(ID
, False, 3);
4693 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4694 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4698 FSpectator
:= False;
4701 FSpectatePlayer
:= -1;
4704 if (gPlayer1
= nil) and (gSpectLatchPID1
= FUID
) then
4706 if (gPlayer2
= nil) and (gSpectLatchPID2
= FUID
) then
4709 if g_Game_IsNet
then
4711 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
4712 MH_SEND_PlayerStats(FUID
, NET_EVERYONE
);
4714 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4715 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32,
4720 procedure TPlayer
.Spectate(NoMove
: Boolean = False);
4723 Kill(K_EXTRAHARDKILL
, FUID
, HIT_SOME
)
4724 else if (not NoMove
) then
4726 GameX
:= gMapInfo
.Width
div 2;
4727 GameY
:= gMapInfo
.Height
div 2;
4736 FWantsInGame
:= False;
4742 if Self
= gPlayer1
then
4744 gSpectLatchPID1
:= FUID
;
4747 else if Self
= gPlayer2
then
4749 gSpectLatchPID2
:= FUID
;
4754 if g_Game_IsNet
then
4755 MH_SEND_PlayerStats(FUID
);
4758 procedure TPlayer
.SwitchNoClip
;
4762 FGhost
:= not FGhost
;
4763 FPhysics
:= not FGhost
;
4775 procedure TPlayer
.Run(Direction
: TDirection
);
4779 if MAX_RUNVEL
> 8 then
4783 if Direction
= TDirection
.D_LEFT
then
4785 if FObj
.Vel
.X
> -MAX_RUNVEL
then
4786 FObj
.Vel
.X
:= FObj
.Vel
.X
- (MAX_RUNVEL
shr 3);
4789 if FObj
.Vel
.X
< MAX_RUNVEL
then
4790 FObj
.Vel
.X
:= FObj
.Vel
.X
+ (MAX_RUNVEL
shr 3);
4792 // Âîçìîæíî, ïèíàåì êóñêè:
4793 if (FObj
.Vel
.X
<> 0) and (gGibs
<> nil) then
4795 b
:= Abs(FObj
.Vel
.X
);
4796 if b
> 1 then b
:= b
* (Random(8 div b
) + 1);
4797 for a
:= 0 to High(gGibs
) do
4799 if gGibs
[a
].alive
and
4800 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
+FObj
.Rect
.Height
-4,
4801 FObj
.Rect
.Width
, 8, @gGibs
[a
].Obj
) and (Random(3) = 0) then
4804 if FObj
.Vel
.X
< 0 then
4806 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)+120) // íàëåâî
4810 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)); // íàïðàâî
4812 gGibs
[a
].positionChanged(); // this updates spatial accelerators
4820 procedure TPlayer
.SeeDown();
4822 SetAction(A_SEEDOWN
);
4824 if FDirection
= TDirection
.D_LEFT
then FAngle
:= ANGLE_LEFTDOWN
else FAngle
:= ANGLE_RIGHTDOWN
;
4826 if FIncCam
> -120 then DecMin(FIncCam
, 5, -120);
4829 procedure TPlayer
.SeeUp();
4833 if FDirection
= TDirection
.D_LEFT
then FAngle
:= ANGLE_LEFTUP
else FAngle
:= ANGLE_RIGHTUP
;
4835 if FIncCam
< 120 then IncMax(FIncCam
, 5, 120);
4838 procedure TPlayer
.SetAction(Action
: Byte; Force
: Boolean = False);
4846 A_ATTACK
: Prior
:= 2;
4847 A_SEEUP
: Prior
:= 1;
4848 A_SEEDOWN
: Prior
:= 1;
4849 A_ATTACKUP
: Prior
:= 2;
4850 A_ATTACKDOWN
: Prior
:= 2;
4855 if (Prior
> FActionPrior
) or Force
then
4856 if not ((Prior
= 2) and (FCurrWeap
= WEAPON_SAW
)) then
4858 FActionPrior
:= Prior
;
4859 FActionAnim
:= Action
;
4860 FActionForce
:= Force
;
4861 FActionChanged
:= True;
4864 if Action
in [A_ATTACK
, A_ATTACKUP
, A_ATTACKDOWN
] then FModel
.SetFire(True);
4867 function TPlayer
.StayOnStep(XInc
, YInc
: Integer): Boolean;
4869 Result
:= not g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
-1,
4870 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False)
4871 and g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
,
4872 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False);
4875 function TPlayer
.TeleportTo(X
, Y
: Integer; silent
: Boolean; dir
: Byte): Boolean;
4882 if g_CollideLevel(X
, Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
) then
4884 g_Sound_PlayExAt('SOUND_GAME_NOTELEPORT', FObj
.X
, FObj
.Y
);
4885 if g_Game_IsServer
and g_Game_IsNet
then
4886 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_GAME_NOTELEPORT');
4890 FJustTeleported
:= True;
4895 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
4897 Anim
:= TAnimation
.Create(ID
, False, 3);
4900 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', FObj
.X
, FObj
.Y
);
4901 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4902 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4903 if g_Game_IsServer
and g_Game_IsNet
then
4904 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4905 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 1,
4909 FObj
.X
:= X
-PLAYER_RECT
.X
;
4910 FObj
.Y
:= Y
-PLAYER_RECT
.Y
;
4911 FObj
.oldX
:= FObj
.X
; // don't interpolate after respawn
4912 FObj
.oldY
:= FObj
.Y
;
4913 if FAlive
and FGhost
then
4919 if not g_Game_IsNet
then
4923 SetDirection(TDirection
.D_LEFT
);
4929 SetDirection(TDirection
.D_RIGHT
);
4935 if FDirection
= TDirection
.D_RIGHT
then
4937 SetDirection(TDirection
.D_LEFT
);
4942 SetDirection(TDirection
.D_RIGHT
);
4948 if not silent
and (Anim
<> nil) then
4950 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4951 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4954 if g_Game_IsServer
and g_Game_IsNet
then
4955 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4956 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 0,
4963 function nonz(a
: Single): Single;
4971 function TPlayer
.refreshCorpse(): Boolean;
4977 if FAlive
or FSpectator
then
4979 if (gCorpses
= nil) or (Length(gCorpses
) = 0) then
4981 for i
:= 0 to High(gCorpses
) do
4982 if gCorpses
[i
] <> nil then
4983 if gCorpses
[i
].FPlayerUID
= FUID
then
4991 function TPlayer
.getCameraObj(): TObj
;
4993 if (not FAlive
) and (not FSpectator
) and
4994 (FCorpse
>= 0) and (FCorpse
< Length(gCorpses
)) and
4995 (gCorpses
[FCorpse
] <> nil) and (gCorpses
[FCorpse
].FPlayerUID
= FUID
) then
4997 gCorpses
[FCorpse
].FObj
.slopeUpLeft
:= FObj
.slopeUpLeft
;
4998 Result
:= gCorpses
[FCorpse
].FObj
;
5006 procedure TPlayer
.PreUpdate();
5008 FSlopeOld
:= FObj
.slopeUpLeft
;
5009 FIncCamOld
:= FIncCam
;
5010 FObj
.oldX
:= FObj
.X
;
5011 FObj
.oldY
:= FObj
.Y
;
5014 procedure TPlayer
.Update();
5017 i
, ii
, wx
, wy
, xd
, yd
, k
: Integer;
5018 blockmon
, headwater
, dospawn
: Boolean;
5023 NetServer
:= g_Game_IsNet
and g_Game_IsServer
;
5024 AnyServer
:= g_Game_IsServer
;
5026 if g_Game_IsClient
and (NetInterpLevel
> 0) then
5027 DoLerp(NetInterpLevel
+ 1)
5033 if (FClientID
>= 0) and (NetClients
[FClientID
].Peer
<> nil) then
5035 FPing
:= NetClients
[FClientID
].Peer
^.lastRoundTripTime
;
5036 if NetClients
[FClientID
].Peer
^.packetsSent
> 0 then
5037 FLoss
:= Round(100*NetClients
[FClientID
].Peer
^.packetsLost
/NetClients
[FClientID
].Peer
^.packetsSent
)
5046 if FAlive
and (FPunchAnim
<> nil) then
5047 FPunchAnim
.Update();
5049 if FAlive
and (gFly
or FJetpack
) then
5052 if FDirection
= TDirection
.D_LEFT
then
5057 if FAlive
and (not FGhost
) then
5059 if FKeys
[KEY_UP
].Pressed
then
5061 if FKeys
[KEY_DOWN
].Pressed
then
5065 if (not (FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_DOWN
].Pressed
)) and
5068 i
:= g_basic
.Sign(FIncCam
);
5069 FIncCam
:= Abs(FIncCam
);
5070 DecMin(FIncCam
, 5, 0);
5071 FIncCam
:= FIncCam
*i
;
5074 if gTime
mod (GAME_TICK
*2) <> 0 then
5076 if (FObj
.Vel
.X
= 0) and FAlive
then
5078 if FKeys
[KEY_LEFT
].Pressed
then
5079 Run(TDirection
.D_LEFT
);
5080 if FKeys
[KEY_RIGHT
].Pressed
then
5081 Run(TDirection
.D_RIGHT
);
5086 g_Obj_Move(@FObj
, True, True, True);
5087 positionChanged(); // this updates spatial accelerators
5093 FActionChanged
:= False;
5097 // Let alive player do some actions
5098 if FKeys
[KEY_LEFT
].Pressed
then Run(TDirection
.D_LEFT
);
5099 if FKeys
[KEY_RIGHT
].Pressed
then Run(TDirection
.D_RIGHT
);
5100 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then Fire()
5106 if NetServer
then MH_SEND_PlayerStats(FUID
);
5109 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Use();
5110 if FKeys
[KEY_JUMP
].Pressed
then Jump()
5113 if AnyServer
and FJetpack
then
5117 if NetServer
then MH_SEND_PlayerStats(FUID
);
5119 FCanJetpack
:= True;
5126 for k
:= Low(FKeys
) to KEY_CHAT
-1 do
5128 if FKeys
[k
].Pressed
then
5136 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
5139 if (FTime
[T_RESPAWN
] <= gTime
) and
5140 gGameOn
and (not FAlive
) then
5142 if (g_Player_GetCount() > 1) then
5146 gExit
:= EXIT_RESTART
;
5151 // Dead spectator actions
5154 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Fire();
5155 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then
5159 if (FSpectatePlayer
>= High(gPlayers
)) then
5160 FSpectatePlayer
:= -1
5164 for I
:= FSpectatePlayer
+ 1 to High(gPlayers
) do
5165 if gPlayers
[I
] <> nil then
5166 if gPlayers
[I
].alive
then
5167 if gPlayers
[I
].UID
<> FUID
then
5169 FSpectatePlayer
:= I
;
5174 if not SetSpect
then FSpectatePlayer
:= -1;
5185 if FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_JUMP
].Pressed
then
5187 FYTo
:= FObj
.Y
- 32;
5188 FSpectatePlayer
:= -1;
5190 if FKeys
[KEY_DOWN
].Pressed
then
5192 FYTo
:= FObj
.Y
+ 32;
5193 FSpectatePlayer
:= -1;
5195 if FKeys
[KEY_LEFT
].Pressed
then
5197 FXTo
:= FObj
.X
- 32;
5198 FSpectatePlayer
:= -1;
5200 if FKeys
[KEY_RIGHT
].Pressed
then
5202 FXTo
:= FObj
.X
+ 32;
5203 FSpectatePlayer
:= -1;
5206 if (FXTo
< -64) then
5208 else if (FXTo
> gMapInfo
.Width
+ 32) then
5209 FXTo
:= gMapInfo
.Width
+ 32;
5210 if (FYTo
< -72) then
5212 else if (FYTo
> gMapInfo
.Height
+ 32) then
5213 FYTo
:= gMapInfo
.Height
+ 32;
5218 g_Obj_Move(@FObj
, True, True, True);
5219 positionChanged(); // this updates spatial accelerators
5226 if (FSpectatePlayer
<= High(gPlayers
)) and (FSpectatePlayer
>= 0) then
5227 if gPlayers
[FSpectatePlayer
] <> nil then
5228 if gPlayers
[FSpectatePlayer
].alive
then
5230 FXTo
:= gPlayers
[FSpectatePlayer
].GameX
;
5231 FYTo
:= gPlayers
[FSpectatePlayer
].GameY
;
5235 blockmon
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
, FObj
.Y
+PLAYER_HEADRECT
.Y
,
5236 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
5237 PANEL_BLOCKMON
, True);
5238 headwater
:= HeadInLiquid(0, 0);
5240 // Ñîïðîòèâëåíèå âîçäóõà:
5241 if (not FAlive
) or not (FKeys
[KEY_LEFT
].Pressed
or FKeys
[KEY_RIGHT
].Pressed
) then
5242 if FObj
.Vel
.X
<> 0 then
5243 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
5245 if (FLastHit
= HIT_TRAP
) and (FPain
> 90) then FPain
:= 90;
5246 DecMin(FPain
, 5, 0);
5247 DecMin(FPickup
, 1, 0);
5249 if FAlive
and (FObj
.Y
> Integer(gMapInfo
.Height
)+128) and AnyServer
then
5251 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
5252 FMegaRulez
[MR_SUIT
] := 0;
5253 FMegaRulez
[MR_INVUL
] := 0;
5254 FMegaRulez
[MR_INVIS
] := 0;
5255 Kill(K_FALLKILL
, 0, HIT_FALL
);
5262 if FCurrWeap
= WEAPON_SAW
then
5263 if not (FSawSound
.IsPlaying() or FSawSoundHit
.IsPlaying() or
5264 FSawSoundSelect
.IsPlaying()) then
5265 FSawSoundIdle
.PlayAt(FObj
.X
, FObj
.Y
);
5268 if (not FJetSoundFly
.IsPlaying()) and (not FJetSoundOn
.IsPlaying()) and
5269 (not FJetSoundOff
.IsPlaying()) then
5271 FJetSoundFly
.SetPosition(0);
5272 FJetSoundFly
.PlayAt(FObj
.X
, FObj
.Y
);
5275 for b
:= WP_FIRST
to WP_LAST
do
5276 if FReloading
[b
] > 0 then
5282 if FShellTimer
> -1 then
5283 if FShellTimer
= 0 then
5285 if FShellType
= SHELL_SHELL
then
5286 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5287 GameVelX
, GameVelY
-2, SHELL_SHELL
)
5288 else if FShellType
= SHELL_DBLSHELL
then
5290 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5291 GameVelX
+1, GameVelY
-2, SHELL_SHELL
);
5292 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5293 GameVelX
-1, GameVelY
-2, SHELL_SHELL
);
5296 end else Dec(FShellTimer
);
5298 if (FBFGFireCounter
> -1) then
5299 if FBFGFireCounter
= 0 then
5303 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
5304 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
5305 xd
:= wx
+IfThen(FDirection
= TDirection
.D_LEFT
, -30, 30);
5306 yd
:= wy
+firediry();
5307 g_Weapon_bfgshot(wx
, wy
, xd
, yd
, FUID
);
5308 if NetServer
then MH_SEND_PlayerFire(FUID
, WEAPON_BFG
, wx
, wy
, xd
, yd
);
5309 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
5310 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
5311 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
5314 FReloading
[WEAPON_BFG
] := WEAPON_RELOAD
[WEAPON_BFG
];
5315 FBFGFireCounter
:= -1;
5318 FBFGFireCounter
:= 0
5320 Dec(FBFGFireCounter
);
5322 if (FMegaRulez
[MR_SUIT
] < gTime
) and AnyServer
then
5324 b
:= g_GetAcidHit(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
);
5326 if (b
> 0) and (gTime
mod (15*GAME_TICK
) = 0) then Damage(b
, 0, 0, 0, HIT_ACID
);
5329 if (headwater
or blockmon
) then
5335 if AnyServer
then Damage(10, 0, 0, 0, HIT_WATER
);
5338 else if (FAir
mod 31 = 0) and not blockmon
then
5340 g_GFX_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2), FObj
.Y
+PLAYER_RECT
.Y
-4, 5+Random(6), 8, 4);
5341 if Random(2) = 0 then
5342 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
5344 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
5346 end else if FAir
< AIR_DEF
then
5349 if FFireTime
> 0 then
5351 if BodyInLiquid(0, 0) then
5356 else if FMegaRulez
[MR_SUIT
] >= gTime
then
5358 if FMegaRulez
[MR_SUIT
] = gTime
then
5365 if FFirePainTime
<= 0 then
5367 if g_Game_IsServer
then
5368 Damage(2, FFireAttacker
, 0, 0, HIT_FLAME
);
5369 FFirePainTime
:= 12 - FFireTime
div 12;
5371 FFirePainTime
:= FFirePainTime
- 1;
5372 FFireTime
:= FFireTime
- 1;
5373 if ((FFireTime
mod 33) = 0) and (FMegaRulez
[MR_INVUL
] < gTime
) then
5374 FModel
.PlaySound(MODELSOUND_PAIN
, 1, FObj
.X
, FObj
.Y
);
5375 if (FFireTime
= 0) and g_Game_IsNet
and g_Game_IsServer
then
5376 MH_SEND_PlayerStats(FUID
);
5380 if FDamageBuffer
> 0 then
5382 if FDamageBuffer
>= 9 then
5386 if FDamageBuffer
< 30 then i
:= 9
5387 else if FDamageBuffer
< 100 then i
:= 18
5391 ii
:= Round(FDamageBuffer
*FHealth
/ nonz(FArmor
*(3/4)+FHealth
));
5392 FArmor
:= FArmor
-(FDamageBuffer
-ii
);
5393 FHealth
:= FHealth
-ii
;
5396 FHealth
:= FHealth
+FArmor
;
5401 if FHealth
<= 0 then
5402 if FHealth
> -30 then Kill(K_SIMPLEKILL
, FLastSpawnerUID
, FLastHit
)
5403 else if FHealth
> -50 then Kill(K_HARDKILL
, FLastSpawnerUID
, FLastHit
)
5404 else Kill(K_EXTRAHARDKILL
, FLastSpawnerUID
, FLastHit
);
5406 if FAlive
and ((FLastHit
<> HIT_FLAME
) or (FFireTime
<= 0)) then
5408 if FDamageBuffer
<= 20 then FModel
.PlaySound(MODELSOUND_PAIN
, 1, FObj
.X
, FObj
.Y
)
5409 else if FDamageBuffer
<= 55 then FModel
.PlaySound(MODELSOUND_PAIN
, 2, FObj
.X
, FObj
.Y
)
5410 else if FDamageBuffer
<= 120 then FModel
.PlaySound(MODELSOUND_PAIN
, 3, FObj
.X
, FObj
.Y
)
5411 else FModel
.PlaySound(MODELSOUND_PAIN
, 4, FObj
.X
, FObj
.Y
);
5418 end; // if FAlive then ...
5420 if (FActionAnim
= A_PAIN
) and (FModel
.Animation
<> A_PAIN
) then
5422 FModel
.ChangeAnimation(FActionAnim
, FActionForce
);
5423 FModel
.GetCurrentAnimation
.MinLength
:= i
;
5424 FModel
.GetCurrentAnimationMask
.MinLength
:= i
;
5425 end else FModel
.ChangeAnimation(FActionAnim
, FActionForce
and (FModel
.Animation
<> A_STAND
));
5427 if (FModel
.GetCurrentAnimation
.Played
or ((not FActionChanged
) and (FModel
.Animation
= A_WALK
)))
5428 then SetAction(A_STAND
, True);
5430 if not ((FModel
.Animation
= A_WALK
) and (Abs(FObj
.Vel
.X
) < 4) and not FModel
.Fire
) then FModel
.Update
;
5432 for b
:= Low(FKeys
) to High(FKeys
) do
5433 if FKeys
[b
].Time
= 0 then FKeys
[b
].Pressed
:= False else Dec(FKeys
[b
].Time
);
5437 procedure TPlayer
.getMapBox (out x
, y
, w
, h
: Integer); inline;
5439 x
:= FObj
.X
+PLAYER_RECT
.X
;
5440 y
:= FObj
.Y
+PLAYER_RECT
.Y
;
5441 w
:= PLAYER_RECT
.Width
;
5442 h
:= PLAYER_RECT
.Height
;
5446 procedure TPlayer
.moveBy (dx
, dy
: Integer); inline;
5448 if (dx
<> 0) or (dy
<> 0) then
5457 function TPlayer
.Collide(X
, Y
: Integer; Width
, Height
: Word): Boolean;
5459 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
5460 FObj
.Y
+PLAYER_RECT
.Y
,
5467 function TPlayer
.Collide(Panel
: TPanel
): Boolean;
5469 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
5470 FObj
.Y
+PLAYER_RECT
.Y
,
5474 Panel
.Width
, Panel
.Height
);
5477 function TPlayer
.Collide(X
, Y
: Integer): Boolean;
5479 X
:= X
-FObj
.X
-PLAYER_RECT
.X
;
5480 Y
:= Y
-FObj
.Y
-PLAYER_RECT
.Y
;
5481 Result
:= (x
>= 0) and (x
<= PLAYER_RECT
.Width
) and
5482 (y
>= 0) and (y
<= PLAYER_RECT
.Height
);
5485 function g_Player_ValidName(Name
: string): Boolean;
5491 if gPlayers
= nil then Exit
;
5493 for a
:= 0 to High(gPlayers
) do
5494 if gPlayers
[a
] <> nil then
5495 if LowerCase(Name
) = LowerCase(gPlayers
[a
].FName
) then
5502 procedure TPlayer
.SetDirection(Direction
: TDirection
);
5506 d
:= FModel
.Direction
;
5508 FModel
.Direction
:= Direction
;
5509 if d
<> Direction
then FModel
.ChangeAnimation(FModel
.Animation
, True);
5511 FDirection
:= Direction
;
5514 function TPlayer
.GetKeys(): Byte;
5518 if R_KEY_RED
in FRulez
then Result
:= KEY_RED
;
5519 if R_KEY_GREEN
in FRulez
then Result
:= Result
or KEY_GREEN
;
5520 if R_KEY_BLUE
in FRulez
then Result
:= Result
or KEY_BLUE
;
5522 if FTeam
= TEAM_RED
then Result
:= Result
or KEY_REDTEAM
;
5523 if FTeam
= TEAM_BLUE
then Result
:= Result
or KEY_BLUETEAM
;
5526 procedure TPlayer
.Use();
5530 if FTime
[T_USE
] > gTime
then Exit
;
5532 g_Triggers_PressR(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
,
5533 PLAYER_RECT
.Height
, FUID
, ACTIVATE_PLAYERPRESS
);
5535 for a
:= 0 to High(gPlayers
) do
5536 if (gPlayers
[a
] <> nil) and (gPlayers
[a
] <> Self
) and
5537 gPlayers
[a
].alive
and SameTeam(FUID
, gPlayers
[a
].FUID
) and
5538 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
5539 FObj
.Rect
.Width
, FObj
.Rect
.Height
, @gPlayers
[a
].FObj
) then
5541 gPlayers
[a
].Touch();
5542 if g_Game_IsNet
and g_Game_IsServer
then
5543 MH_SEND_GameEvent(NET_EV_PLAYER_TOUCH
, gPlayers
[a
].FUID
);
5546 FTime
[T_USE
] := gTime
+120;
5549 procedure TPlayer
.NetFire(Wpn
: Byte; X
, Y
, AX
, AY
: Integer; WID
: Integer = -1);
5553 WX
, WY
, XD
, YD
: Integer;
5565 if R_BERSERK
in FRulez
then
5567 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
5568 locobj
.X
:= FObj
.X
+FObj
.Rect
.X
;
5569 locobj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
5572 locobj
.rect
.Width
:= 39;
5573 locobj
.rect
.Height
:= 52;
5574 locobj
.Vel
.X
:= (xd
-wx
) div 2;
5575 locobj
.Vel
.Y
:= (yd
-wy
) div 2;
5576 locobj
.Accel
.X
:= xd
-wx
;
5577 locobj
.Accel
.y
:= yd
-wy
;
5579 if g_Weapon_Hit(@locobj
, 50, FUID
, HIT_SOME
) <> 0 then
5580 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
5582 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
5586 FPain
:= min(FPain
+ 25, 50);
5588 g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
5593 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
5594 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
5596 FSawSoundSelect
.Stop();
5598 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
5600 else if not FSawSoundHit
.IsPlaying() then
5602 FSawSoundSelect
.Stop();
5603 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
5610 g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', GameX
, Gamey
);
5611 FFireAngle
:= FAngle
;
5613 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5614 GameVelX
, GameVelY
-2, SHELL_BULLET
);
5619 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
5620 FFireAngle
:= FAngle
;
5623 FShellType
:= SHELL_SHELL
;
5628 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN2', Gamex
, Gamey
);
5629 FFireAngle
:= FAngle
;
5632 FShellType
:= SHELL_DBLSHELL
;
5637 g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', Gamex
, Gamey
);
5638 FFireAngle
:= FAngle
;
5640 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5641 GameVelX
, GameVelY
-2, SHELL_BULLET
);
5644 WEAPON_ROCKETLAUNCHER
:
5646 g_Weapon_Rocket(wx
, wy
, xd
, yd
, FUID
, WID
);
5647 FFireAngle
:= FAngle
;
5653 g_Weapon_Plasma(wx
, wy
, xd
, yd
, FUID
, WID
);
5654 FFireAngle
:= FAngle
;
5660 g_Weapon_BFGShot(wx
, wy
, xd
, yd
, FUID
, WID
);
5661 FFireAngle
:= FAngle
;
5665 WEAPON_SUPERPULEMET
:
5667 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
5668 FFireAngle
:= FAngle
;
5670 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5671 GameVelX
, GameVelY
-2, SHELL_SHELL
);
5674 WEAPON_FLAMETHROWER
:
5676 g_Weapon_flame(wx
, wy
, xd
, yd
, FUID
, WID
);
5678 FFireAngle
:= FAngle
;
5685 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
5686 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
5687 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
5690 procedure TPlayer
.DoLerp(Level
: Integer = 2);
5692 if FObj
.X
<> FXTo
then FObj
.X
:= Lerp(FObj
.X
, FXTo
, Level
);
5693 if FObj
.Y
<> FYTo
then FObj
.Y
:= Lerp(FObj
.Y
, FYTo
, Level
);
5696 procedure TPlayer
.SetLerp(XTo
, YTo
: Integer);
5702 if FJustTeleported
or (NetInterpLevel
< 1) then
5706 if FJustTeleported
then
5708 FObj
.oldX
:= FObj
.X
;
5709 FObj
.oldY
:= FObj
.Y
;
5714 AX
:= Abs(FXTo
- FObj
.X
);
5715 AY
:= Abs(FYTo
- FObj
.Y
);
5716 if (AX
> 32) or (AX
<= NetInterpLevel
) then
5718 if (AY
> 32) or (AY
<= NetInterpLevel
) then
5723 function TPlayer
.FullInLift(XInc
, YInc
: Integer): Integer;
5725 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5726 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5727 PANEL_LIFTUP
, False) then Result
:= -1
5729 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5730 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5731 PANEL_LIFTDOWN
, False) then Result
:= 1
5735 function TPlayer
.GetFlag(Flag
: Byte): Boolean;
5742 if Flag
= FLAG_NONE
then
5745 if not g_Game_IsServer
then Exit
;
5747 // Ïðèíåñ ÷óæîé ôëàã íà ñâîþ áàçó:
5748 if (Flag
= FTeam
) and
5749 (gFlags
[Flag
].State
= FLAG_STATE_NORMAL
) and
5750 (FFlag
<> FLAG_NONE
) then
5752 if FFlag
= FLAG_RED
then
5753 s
:= _lc
[I_PLAYER_FLAG_RED
]
5755 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5757 evtype
:= FLAG_STATE_SCORED
;
5759 ts
:= Format('%.4d', [gFlags
[FFlag
].CaptureTime
]);
5760 Insert('.', ts
, Length(ts
) + 1 - 3);
5761 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_CAPTURE
], [FName
, s
, ts
]), True);
5763 g_Map_ResetFlag(FFlag
);
5764 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_CAPTURE
], [AnsiUpperCase(s
)]), 144);
5766 if ((Self
= gPlayer1
) or (Self
= gPlayer2
)
5767 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= FTeam
))
5768 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= FTeam
))) then
5773 if not sound_cap_flag
[a
].IsPlaying() then
5774 sound_cap_flag
[a
].Play();
5776 gTeamStat
[FTeam
].Goals
:= gTeamStat
[FTeam
].Goals
+ 1;
5779 if g_Game_IsNet
then
5781 MH_SEND_FlagEvent(evtype
, FFlag
, FUID
, False);
5785 gFlags
[FFlag
].CaptureTime
:= 0;
5790 // Ïîäîáðàë ñâîé ôëàã - âåðíóë åãî íà áàçó:
5791 if (Flag
= FTeam
) and
5792 (gFlags
[Flag
].State
= FLAG_STATE_DROPPED
) then
5794 if Flag
= FLAG_RED
then
5795 s
:= _lc
[I_PLAYER_FLAG_RED
]
5797 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5799 evtype
:= FLAG_STATE_RETURNED
;
5800 gFlags
[Flag
].CaptureTime
:= 0;
5802 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_RETURN
], [FName
, s
]), True);
5804 g_Map_ResetFlag(Flag
);
5805 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
5807 if ((Self
= gPlayer1
) or (Self
= gPlayer2
)
5808 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= FTeam
))
5809 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= FTeam
))) then
5814 if not sound_ret_flag
[a
].IsPlaying() then
5815 sound_ret_flag
[a
].Play();
5818 if g_Game_IsNet
then
5820 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5826 // Ïîäîáðàë ÷óæîé ôëàã:
5827 if (Flag
<> FTeam
) and (FTime
[T_FLAGCAP
] <= gTime
) then
5831 if Flag
= FLAG_RED
then
5832 s
:= _lc
[I_PLAYER_FLAG_RED
]
5834 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5836 evtype
:= FLAG_STATE_CAPTURED
;
5838 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_GET
], [FName
, s
]), True);
5840 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_GET
], [AnsiUpperCase(s
)]), 144);
5842 gFlags
[Flag
].State
:= FLAG_STATE_CAPTURED
;
5844 if ((Self
= gPlayer1
) or (Self
= gPlayer2
)
5845 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= FTeam
))
5846 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= FTeam
))) then
5851 if not sound_get_flag
[a
].IsPlaying() then
5852 sound_get_flag
[a
].Play();
5855 if g_Game_IsNet
then
5857 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5863 procedure TPlayer
.SetFlag(Flag
: Byte);
5866 if FModel
<> nil then
5867 FModel
.SetFlag(FFlag
);
5870 function TPlayer
.TryDropFlag(): Boolean;
5872 if LongBool(gGameSettings
.Options
and GAME_OPTION_ALLOWDROPFLAG
) then
5873 Result
:= DropFlag(False, LongBool(gGameSettings
.Options
and GAME_OPTION_THROWFLAG
))
5878 function TPlayer
.DropFlag(Silent
: Boolean = True; DoThrow
: Boolean = False): Boolean;
5885 if (not g_Game_IsServer
) or (FFlag
= FLAG_NONE
) then
5887 FTime
[T_FLAGCAP
] := gTime
+ 2000;
5888 with gFlags
[FFlag
] do
5892 Direction
:= FDirection
;
5893 State
:= FLAG_STATE_DROPPED
;
5897 xv
:= FObj
.Vel
.X
+ IfThen(Direction
= TDirection
.D_RIGHT
, 10, -10);
5898 yv
:= FObj
.Vel
.Y
- 2;
5902 xv
:= (FObj
.Vel
.X
div 2);
5903 yv
:= (FObj
.Vel
.Y
div 2) - 2;
5905 g_Obj_Push(@Obj
, xv
, yv
);
5907 positionChanged(); // this updates spatial accelerators
5909 if FFlag
= FLAG_RED
then
5910 s
:= _lc
[I_PLAYER_FLAG_RED
]
5912 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5914 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_DROP
], [FName
, s
]), True);
5915 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_DROP
], [AnsiUpperCase(s
)]), 144);
5917 if ((Self
= gPlayer1
) or (Self
= gPlayer2
)
5918 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= FTeam
))
5919 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= FTeam
))) then
5924 if (not Silent
) and (not sound_lost_flag
[a
].IsPlaying()) then
5925 sound_lost_flag
[a
].Play();
5927 if g_Game_IsNet
then
5928 MH_SEND_FlagEvent(FLAG_STATE_DROPPED
, Flag
, FUID
, False);
5934 procedure TPlayer
.GetSecret();
5936 if (self
= gPlayer1
) or (self
= gPlayer2
) then
5938 g_Console_Add(Format(_lc
[I_PLAYER_SECRET
], [FName
]), True);
5939 g_Sound_PlayEx('SOUND_GAME_SECRET');
5944 procedure TPlayer
.PressKey(Key
: Byte; Time
: Word = 1);
5946 Assert(Key
<= High(FKeys
));
5948 FKeys
[Key
].Pressed
:= True;
5949 FKeys
[Key
].Time
:= Time
;
5952 function TPlayer
.IsKeyPressed(K
: Byte): Boolean;
5954 Result
:= FKeys
[K
].Pressed
;
5957 procedure TPlayer
.ReleaseKeys();
5961 for a
:= Low(FKeys
) to High(FKeys
) do
5963 FKeys
[a
].Pressed
:= False;
5968 procedure TPlayer
.OnDamage(Angle
: SmallInt);
5972 function TPlayer
.firediry(): Integer;
5974 if FKeys
[KEY_UP
].Pressed
then Result
:= -42
5975 else if FKeys
[KEY_DOWN
].Pressed
then Result
:= 19
5979 procedure TPlayer
.RememberState();
5982 SavedState
: TPlayerSavedState
;
5984 SavedState
.Health
:= FHealth
;
5985 SavedState
.Armor
:= FArmor
;
5986 SavedState
.Air
:= FAir
;
5987 SavedState
.JetFuel
:= FJetFuel
;
5988 SavedState
.CurrWeap
:= FCurrWeap
;
5989 SavedState
.NextWeap
:= FNextWeap
;
5990 SavedState
.NextWeapDelay
:= FNextWeapDelay
;
5991 for i
:= Low(FWeapon
) to High(FWeapon
) do
5992 SavedState
.Weapon
[i
] := FWeapon
[i
];
5993 for i
:= Low(FAmmo
) to High(FAmmo
) do
5994 SavedState
.Ammo
[i
] := FAmmo
[i
];
5995 for i
:= Low(FMaxAmmo
) to High(FMaxAmmo
) do
5996 SavedState
.MaxAmmo
[i
] := FMaxAmmo
[i
];
5997 SavedState
.Rulez
:= FRulez
- [R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
];
5999 FSavedStateNum
:= -1;
6000 for i
:= Low(SavedStates
) to High(SavedStates
) do
6001 if not SavedStates
[i
].Used
then
6003 FSavedStateNum
:= i
;
6006 if FSavedStateNum
< 0 then
6008 SetLength(SavedStates
, Length(SavedStates
) + 1);
6009 FSavedStateNum
:= High(SavedStates
);
6012 SavedState
.Used
:= True;
6013 SavedStates
[FSavedStateNum
] := SavedState
;
6016 procedure TPlayer
.RecallState();
6019 SavedState
: TPlayerSavedState
;
6021 if(FSavedStateNum
< 0) or (FSavedStateNum
> High(SavedStates
)) then
6024 SavedState
:= SavedStates
[FSavedStateNum
];
6025 SavedStates
[FSavedStateNum
].Used
:= False;
6026 FSavedStateNum
:= -1;
6028 FHealth
:= SavedState
.Health
;
6029 FArmor
:= SavedState
.Armor
;
6030 FAir
:= SavedState
.Air
;
6031 FJetFuel
:= SavedState
.JetFuel
;
6032 FCurrWeap
:= SavedState
.CurrWeap
;
6033 FNextWeap
:= SavedState
.NextWeap
;
6034 FNextWeapDelay
:= SavedState
.NextWeapDelay
;
6035 for i
:= Low(FWeapon
) to High(FWeapon
) do
6036 FWeapon
[i
] := SavedState
.Weapon
[i
];
6037 for i
:= Low(FAmmo
) to High(FAmmo
) do
6038 FAmmo
[i
] := SavedState
.Ammo
[i
];
6039 for i
:= Low(FMaxAmmo
) to High(FMaxAmmo
) do
6040 FMaxAmmo
[i
] := SavedState
.MaxAmmo
[i
];
6041 FRulez
:= SavedState
.Rulez
;
6043 if gGameSettings
.GameType
= GT_SERVER
then
6044 MH_SEND_PlayerStats(FUID
);
6047 procedure TPlayer
.SaveState (st
: TStream
);
6053 utils
.writeSign(st
, 'PLYR');
6054 utils
.writeInt(st
, Byte(PLR_SAVE_VERSION
)); // version
6056 utils
.writeBool(st
, FIamBot
);
6058 utils
.writeInt(st
, Word(FUID
));
6060 utils
.writeStr(st
, FName
);
6062 utils
.writeInt(st
, Byte(FTeam
));
6064 utils
.writeBool(st
, FAlive
);
6065 // Èçðàñõîäîâàë ëè âñå æèçíè
6066 utils
.writeBool(st
, FNoRespawn
);
6068 if FDirection
= TDirection
.D_LEFT
then b
:= 1 else b
:= 2; // D_RIGHT
6069 utils
.writeInt(st
, Byte(b
));
6071 utils
.writeInt(st
, LongInt(FHealth
));
6072 // Êîýôôèöèåíò èíâàëèäíîñòè
6073 utils
.writeInt(st
, LongInt(FHandicap
));
6075 utils
.writeInt(st
, Byte(FLives
));
6077 utils
.writeInt(st
, LongInt(FArmor
));
6079 utils
.writeInt(st
, LongInt(FAir
));
6081 utils
.writeInt(st
, LongInt(FJetFuel
));
6083 utils
.writeInt(st
, LongInt(FPain
));
6085 utils
.writeInt(st
, LongInt(FKills
));
6087 utils
.writeInt(st
, LongInt(FMonsterKills
));
6089 utils
.writeInt(st
, LongInt(FFrags
));
6091 utils
.writeInt(st
, Byte(FFragCombo
));
6092 // Âðåìÿ ïîñëåäíåãî ôðàãà
6093 utils
.writeInt(st
, LongWord(FLastFrag
));
6095 utils
.writeInt(st
, LongInt(FDeath
));
6097 utils
.writeInt(st
, Byte(FFlag
));
6099 utils
.writeInt(st
, LongInt(FSecrets
));
6101 utils
.writeInt(st
, Byte(FCurrWeap
));
6103 utils
.writeInt(st
, Word(FNextWeap
));
6105 utils
.writeInt(st
, Byte(FNextWeapDelay
));
6106 // Âðåìÿ çàðÿäêè BFG
6107 utils
.writeInt(st
, SmallInt(FBFGFireCounter
));
6109 utils
.writeInt(st
, LongInt(FDamageBuffer
));
6110 // Ïîñëåäíèé óäàðèâøèé
6111 utils
.writeInt(st
, Word(FLastSpawnerUID
));
6112 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà
6113 utils
.writeInt(st
, Byte(FLastHit
));
6115 Obj_SaveState(st
, @FObj
);
6116 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ
6117 for i
:= A_BULLETS
to A_HIGH
do utils
.writeInt(st
, Word(FAmmo
[i
]));
6118 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ
6119 for i
:= A_BULLETS
to A_HIGH
do utils
.writeInt(st
, Word(FMaxAmmo
[i
]));
6121 for i
:= WP_FIRST
to WP_LAST
do utils
.writeBool(st
, FWeapon
[i
]);
6122 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ
6123 for i
:= WP_FIRST
to WP_LAST
do utils
.writeInt(st
, Word(FReloading
[i
]));
6125 utils
.writeBool(st
, (R_ITEM_BACKPACK
in FRulez
));
6126 // Íàëè÷èå êðàñíîãî êëþ÷à
6127 utils
.writeBool(st
, (R_KEY_RED
in FRulez
));
6128 // Íàëè÷èå çåëåíîãî êëþ÷à
6129 utils
.writeBool(st
, (R_KEY_GREEN
in FRulez
));
6130 // Íàëè÷èå ñèíåãî êëþ÷à
6131 utils
.writeBool(st
, (R_KEY_BLUE
in FRulez
));
6133 utils
.writeBool(st
, (R_BERSERK
in FRulez
));
6134 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ
6135 for i
:= MR_SUIT
to MR_MAX
do utils
.writeInt(st
, LongWord(FMegaRulez
[i
]));
6136 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà
6137 for i
:= T_RESPAWN
to T_FLAGCAP
do utils
.writeInt(st
, LongWord(FTime
[i
]));
6139 utils
.writeStr(st
, FModel
.Name
);
6141 utils
.writeInt(st
, Byte(FColor
.R
));
6142 utils
.writeInt(st
, Byte(FColor
.G
));
6143 utils
.writeInt(st
, Byte(FColor
.B
));
6147 procedure TPlayer
.LoadState (st
: TStream
);
6156 if not utils
.checkSign(st
, 'PLYR') then raise XStreamError
.Create('invalid player signature');
6157 if (utils
.readByte(st
) <> PLR_SAVE_VERSION
) then raise XStreamError
.Create('invalid player version');
6159 FIamBot
:= utils
.readBool(st
);
6161 FUID
:= utils
.readWord(st
);
6163 str
:= utils
.readStr(st
);
6164 if (self
<> gPlayer1
) and (self
<> gPlayer2
) then FName
:= str
;
6166 FTeam
:= utils
.readByte(st
);
6168 FAlive
:= utils
.readBool(st
);
6169 // Èçðàñõîäîâàë ëè âñå æèçíè
6170 FNoRespawn
:= utils
.readBool(st
);
6172 b
:= utils
.readByte(st
);
6173 if b
= 1 then FDirection
:= TDirection
.D_LEFT
else FDirection
:= TDirection
.D_RIGHT
; // b = 2
6175 FHealth
:= utils
.readLongInt(st
);
6176 // Êîýôôèöèåíò èíâàëèäíîñòè
6177 FHandicap
:= utils
.readLongInt(st
);
6179 FLives
:= utils
.readByte(st
);
6181 FArmor
:= utils
.readLongInt(st
);
6183 FAir
:= utils
.readLongInt(st
);
6185 FJetFuel
:= utils
.readLongInt(st
);
6187 FPain
:= utils
.readLongInt(st
);
6189 FKills
:= utils
.readLongInt(st
);
6191 FMonsterKills
:= utils
.readLongInt(st
);
6193 FFrags
:= utils
.readLongInt(st
);
6195 FFragCombo
:= utils
.readByte(st
);
6196 // Âðåìÿ ïîñëåäíåãî ôðàãà
6197 FLastFrag
:= utils
.readLongWord(st
);
6199 FDeath
:= utils
.readLongInt(st
);
6201 FFlag
:= utils
.readByte(st
);
6203 FSecrets
:= utils
.readLongInt(st
);
6205 FCurrWeap
:= utils
.readByte(st
);
6207 FNextWeap
:= utils
.readWord(st
);
6209 FNextWeapDelay
:= utils
.readByte(st
);
6210 // Âðåìÿ çàðÿäêè BFG
6211 FBFGFireCounter
:= utils
.readSmallInt(st
);
6213 FDamageBuffer
:= utils
.readLongInt(st
);
6214 // Ïîñëåäíèé óäàðèâøèé
6215 FLastSpawnerUID
:= utils
.readWord(st
);
6216 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà
6217 FLastHit
:= utils
.readByte(st
);
6219 Obj_LoadState(@FObj
, st
);
6220 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ
6221 for i
:= A_BULLETS
to A_HIGH
do FAmmo
[i
] := utils
.readWord(st
);
6222 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ
6223 for i
:= A_BULLETS
to A_HIGH
do FMaxAmmo
[i
] := utils
.readWord(st
);
6225 for i
:= WP_FIRST
to WP_LAST
do FWeapon
[i
] := utils
.readBool(st
);
6226 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ
6227 for i
:= WP_FIRST
to WP_LAST
do FReloading
[i
] := utils
.readWord(st
);
6229 if utils
.readBool(st
) then Include(FRulez
, R_ITEM_BACKPACK
);
6230 // Íàëè÷èå êðàñíîãî êëþ÷à
6231 if utils
.readBool(st
) then Include(FRulez
, R_KEY_RED
);
6232 // Íàëè÷èå çåëåíîãî êëþ÷à
6233 if utils
.readBool(st
) then Include(FRulez
, R_KEY_GREEN
);
6234 // Íàëè÷èå ñèíåãî êëþ÷à
6235 if utils
.readBool(st
) then Include(FRulez
, R_KEY_BLUE
);
6237 if utils
.readBool(st
) then Include(FRulez
, R_BERSERK
);
6238 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ
6239 for i
:= MR_SUIT
to MR_MAX
do FMegaRulez
[i
] := utils
.readLongWord(st
);
6240 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà
6241 for i
:= T_RESPAWN
to T_FLAGCAP
do FTime
[i
] := utils
.readLongWord(st
);
6243 str
:= utils
.readStr(st
);
6245 FColor
.R
:= utils
.readByte(st
);
6246 FColor
.G
:= utils
.readByte(st
);
6247 FColor
.B
:= utils
.readByte(st
);
6248 if (self
= gPlayer1
) then
6250 str
:= gPlayer1Settings
.Model
;
6251 FColor
:= gPlayer1Settings
.Color
;
6253 else if (self
= gPlayer2
) then
6255 str
:= gPlayer2Settings
.Model
;
6256 FColor
:= gPlayer2Settings
.Color
;
6258 // Îáíîâëÿåì ìîäåëü èãðîêà
6260 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
6261 FModel
.Color
:= TEAMCOLOR
[FTeam
]
6263 FModel
.Color
:= FColor
;
6267 procedure TPlayer
.AllRulez(Health
: Boolean);
6273 FHealth
:= PLAYER_HP_LIMIT
;
6274 FArmor
:= PLAYER_AP_LIMIT
;
6278 for a
:= WP_FIRST
to WP_LAST
do FWeapon
[a
] := True;
6279 for a
:= A_BULLETS
to A_HIGH
do FAmmo
[a
] := 30000;
6280 FRulez
:= FRulez
+[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
];
6283 procedure TPlayer
.RestoreHealthArmor();
6285 FHealth
:= PLAYER_HP_LIMIT
;
6286 FArmor
:= PLAYER_AP_LIMIT
;
6289 procedure TPlayer
.FragCombo();
6293 if (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) or g_Game_IsClient
then
6295 if gTime
- FLastFrag
< FRAG_COMBO_TIME
then
6297 if FFragCombo
< 5 then
6299 Param
:= FUID
or (FFragCombo
shl 16);
6300 if (FComboEvnt
>= Low(gDelayedEvents
)) and
6301 (FComboEvnt
<= High(gDelayedEvents
)) and
6302 gDelayedEvents
[FComboEvnt
].Pending
and
6303 (gDelayedEvents
[FComboEvnt
].DEType
= DE_KILLCOMBO
) and
6304 (gDelayedEvents
[FComboEvnt
].DENum
and $FFFF = FUID
) then
6306 gDelayedEvents
[FComboEvnt
].Time
:= gTime
+ 500;
6307 gDelayedEvents
[FComboEvnt
].DENum
:= Param
;
6310 FComboEvnt
:= g_Game_DelayEvent(DE_KILLCOMBO
, 500, Param
);
6318 procedure TPlayer
.GiveItem(ItemType
: Byte);
6322 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
6324 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
6328 if FAir
< AIR_MAX
then
6335 if not (R_BERSERK
in FRulez
) then
6337 Include(FRulez
, R_BERSERK
);
6338 if FBFGFireCounter
< 1 then
6340 FCurrWeap
:= WEAPON_KASTET
;
6342 FModel
.SetWeapon(WEAPON_KASTET
);
6346 FBerserk
:= gTime
+30000;
6348 if FHealth
< PLAYER_HP_SOFT
then
6350 FHealth
:= PLAYER_HP_SOFT
;
6351 FBerserk
:= gTime
+30000;
6356 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
6358 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
6363 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
6365 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
6369 if FJetFuel
< JET_MAX
then
6371 FJetFuel
:= JET_MAX
;
6374 ITEM_MEDKIT_SMALL
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
6375 ITEM_MEDKIT_LARGE
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
6377 ITEM_ARMOR_GREEN
: if FArmor
< PLAYER_AP_SOFT
then FArmor
:= PLAYER_AP_SOFT
;
6378 ITEM_ARMOR_BLUE
: if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
6380 ITEM_SPHERE_BLUE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
6382 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) then
6384 if FHealth
< PLAYER_HP_LIMIT
then FHealth
:= PLAYER_HP_LIMIT
;
6385 if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
6388 ITEM_WEAPON_SAW
: FWeapon
[WEAPON_SAW
] := True;
6389 ITEM_WEAPON_SHOTGUN1
: FWeapon
[WEAPON_SHOTGUN1
] := True;
6390 ITEM_WEAPON_SHOTGUN2
: FWeapon
[WEAPON_SHOTGUN2
] := True;
6391 ITEM_WEAPON_CHAINGUN
: FWeapon
[WEAPON_CHAINGUN
] := True;
6392 ITEM_WEAPON_ROCKETLAUNCHER
: FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
6393 ITEM_WEAPON_PLASMA
: FWeapon
[WEAPON_PLASMA
] := True;
6394 ITEM_WEAPON_BFG
: FWeapon
[WEAPON_BFG
] := True;
6395 ITEM_WEAPON_SUPERPULEMET
: FWeapon
[WEAPON_SUPERPULEMET
] := True;
6396 ITEM_WEAPON_FLAMETHROWER
: FWeapon
[WEAPON_FLAMETHROWER
] := True;
6398 ITEM_AMMO_BULLETS
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
6399 ITEM_AMMO_BULLETS_BOX
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
6400 ITEM_AMMO_SHELLS
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
6401 ITEM_AMMO_SHELLS_BOX
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
6402 ITEM_AMMO_ROCKET
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
6403 ITEM_AMMO_ROCKET_BOX
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
6404 ITEM_AMMO_CELL
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
6405 ITEM_AMMO_CELL_BIG
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
6406 ITEM_AMMO_FUELCAN
: if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
6409 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
6410 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
6411 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
6412 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or
6413 (FMaxAmmo
[A_FUEL
] < AmmoLimits
[1, A_FUEL
]) then
6415 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[1, A_BULLETS
];
6416 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[1, A_SHELLS
];
6417 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[1, A_ROCKETS
];
6418 FMaxAmmo
[A_CELLS
] := AmmoLimits
[1, A_CELLS
];
6419 FMaxAmmo
[A_FUEL
] := AmmoLimits
[1, A_FUEL
];
6421 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
6422 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
6423 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
6424 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
6426 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
6429 ITEM_KEY_RED
: if not (R_KEY_RED
in FRulez
) then Include(FRulez
, R_KEY_RED
);
6430 ITEM_KEY_GREEN
: if not (R_KEY_GREEN
in FRulez
) then Include(FRulez
, R_KEY_GREEN
);
6431 ITEM_KEY_BLUE
: if not (R_KEY_BLUE
in FRulez
) then Include(FRulez
, R_KEY_BLUE
);
6433 ITEM_BOTTLE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
6434 ITEM_HELMET
: if FArmor
< PLAYER_AP_LIMIT
then IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
6439 if g_Game_IsNet
and g_Game_IsServer
then
6440 MH_SEND_PlayerStats(FUID
);
6443 procedure TPlayer
.FlySmoke(Times
: DWORD
= 1);
6448 if (Random(5) = 1) and (Times
= 1) then
6451 if BodyInLiquid(0, 0) then
6453 g_GFX_Bubbles(Obj
.X
+Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2)+Random(3)-1,
6454 Obj
.Y
+Obj
.Rect
.Height
+8, 1, 8, 4);
6455 if Random(2) = 0 then
6456 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
6458 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
6462 if g_Frames_Get(id
, 'FRAMES_SMOKE') then
6464 for i
:= 1 to Times
do
6466 Anim
:= TAnimation
.Create(id
, False, 3);
6468 g_GFX_OnceAnim(Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(Anim
.Width
div 2),
6469 Obj
.Y
+Obj
.Rect
.Height
-4+Random(8+Times
*2), Anim
, ONCEANIM_SMOKE
);
6475 procedure TPlayer
.OnFireFlame(Times
: DWORD
= 1);
6480 if (Random(10) = 1) and (Times
= 1) then
6483 if g_Frames_Get(id
, 'FRAMES_FLAME') then
6485 for i
:= 1 to Times
do
6487 Anim
:= TAnimation
.Create(id
, False, 3);
6489 g_GFX_OnceAnim(Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(Anim
.Width
div 2),
6490 Obj
.Y
+8+Random(8+Times
*2), Anim
, ONCEANIM_SMOKE
);
6496 procedure TPlayer
.PauseSounds(Enable
: Boolean);
6498 FSawSound
.Pause(Enable
);
6499 FSawSoundIdle
.Pause(Enable
);
6500 FSawSoundHit
.Pause(Enable
);
6501 FSawSoundSelect
.Pause(Enable
);
6502 FFlameSoundOn
.Pause(Enable
);
6503 FFlameSoundOff
.Pause(Enable
);
6504 FFlameSoundWork
.Pause(Enable
);
6505 FJetSoundFly
.Pause(Enable
);
6506 FJetSoundOn
.Pause(Enable
);
6507 FJetSoundOff
.Pause(Enable
);
6512 constructor TCorpse
.Create(X
, Y
: Integer; ModelName
: String; aMess
: Boolean);
6517 FObj
.Rect
:= PLAYER_CORPSERECT
;
6518 FModelName
:= ModelName
;
6523 FState
:= CORPSE_STATE_MESS
;
6524 g_PlayerModel_GetAnim(ModelName
, A_DIE2
, FAnimation
, FAnimationMask
);
6528 FState
:= CORPSE_STATE_NORMAL
;
6529 g_PlayerModel_GetAnim(ModelName
, A_DIE1
, FAnimation
, FAnimationMask
);
6533 destructor TCorpse
.Destroy();
6540 function TCorpse
.ObjPtr (): PObj
; inline; begin result
:= @FObj
; end;
6542 procedure TCorpse
.positionChanged (); inline; begin end;
6544 procedure TCorpse
.moveBy (dx
, dy
: Integer); inline;
6546 if (dx
<> 0) or (dy
<> 0) then
6555 procedure TCorpse
.getMapBox (out x
, y
, w
, h
: Integer); inline;
6557 x
:= FObj
.X
+PLAYER_CORPSERECT
.X
;
6558 y
:= FObj
.Y
+PLAYER_CORPSERECT
.Y
;
6559 w
:= PLAYER_CORPSERECT
.Width
;
6560 h
:= PLAYER_CORPSERECT
.Height
;
6564 procedure TCorpse
.Damage(Value
: Word; SpawnerUID
: Word; vx
, vy
: Integer);
6569 if FState
= CORPSE_STATE_REMOVEME
then
6572 FDamage
:= FDamage
+ Value
;
6574 if FDamage
> 150 then
6576 if FAnimation
<> nil then
6581 FState
:= CORPSE_STATE_REMOVEME
;
6583 g_Player_CreateGibs(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
6584 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2),
6585 FModelName
, FColor
);
6586 // Çâóê ìÿñà îò òðóïà:
6587 pm
:= g_PlayerModel_Get(FModelName
);
6588 pm
.PlaySound(MODELSOUND_DIE
, 5, FObj
.X
, FObj
.Y
);
6592 if (gBodyKillEvent
<> -1)
6593 and gDelayedEvents
[gBodyKillEvent
].Pending
then
6594 gDelayedEvents
[gBodyKillEvent
].Pending
:= False;
6595 gBodyKillEvent
:= g_Game_DelayEvent(DE_BODYKILL
, 1050, SpawnerUID
);
6600 Blood
:= g_PlayerModel_GetBlood(FModelName
);
6601 FObj
.Vel
.X
:= FObj
.Vel
.X
+ vx
;
6602 FObj
.Vel
.Y
:= FObj
.Vel
.Y
+ vy
;
6603 g_GFX_Blood(FObj
.X
+PLAYER_CORPSERECT
.X
+(PLAYER_CORPSERECT
.Width
div 2),
6604 FObj
.Y
+PLAYER_CORPSERECT
.Y
+(PLAYER_CORPSERECT
.Height
div 2),
6605 Value
, vx
, vy
, 16, (PLAYER_CORPSERECT
.Height
*2) div 3,
6606 Blood
.R
, Blood
.G
, Blood
.B
, Blood
.Kind
);
6610 procedure TCorpse
.Draw();
6614 if FState
= CORPSE_STATE_REMOVEME
then
6617 FObj
.lerp(gLerpFactor
, fX
, fY
);
6619 if FAnimation
<> nil then
6620 FAnimation
.Draw(fX
, fY
, TMirrorType
.None
);
6622 if FAnimationMask
<> nil then
6625 FAnimationMask
.Draw(fX
, fY
, TMirrorType
.None
);
6632 procedure TCorpse
.Update();
6636 if FState
= CORPSE_STATE_REMOVEME
then
6639 FObj
.oldX
:= FObj
.X
;
6640 FObj
.oldY
:= FObj
.Y
;
6642 if gTime
mod (GAME_TICK
*2) <> 0 then
6644 g_Obj_Move(@FObj
, True, True, True);
6645 positionChanged(); // this updates spatial accelerators
6649 // Ñîïðîòèâëåíèå âîçäóõà äëÿ òðóïà:
6650 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
6652 st
:= g_Obj_Move(@FObj
, True, True, True);
6653 positionChanged(); // this updates spatial accelerators
6655 if WordBool(st
and MOVE_FALLOUT
) then
6657 FState
:= CORPSE_STATE_REMOVEME
;
6661 if FAnimation
<> nil then
6662 FAnimation
.Update();
6663 if FAnimationMask
<> nil then
6664 FAnimationMask
.Update();
6668 procedure TCorpse
.SaveState (st
: TStream
);
6675 utils
.writeSign(st
, 'CORP');
6676 utils
.writeInt(st
, Byte(0));
6678 utils
.writeInt(st
, Byte(FState
));
6680 utils
.writeInt(st
, Byte(FDamage
));
6682 utils
.writeInt(st
, Byte(FColor
.R
));
6683 utils
.writeInt(st
, Byte(FColor
.G
));
6684 utils
.writeInt(st
, Byte(FColor
.B
));
6686 Obj_SaveState(st
, @FObj
);
6687 utils
.writeInt(st
, Word(FPlayerUID
));
6689 anim
:= (FAnimation
<> nil);
6690 utils
.writeBool(st
, anim
);
6691 // Åñëè åñòü - ñîõðàíÿåì
6692 if anim
then FAnimation
.SaveState(st
);
6693 // Åñòü ëè ìàñêà àíèìàöèè
6694 anim
:= (FAnimationMask
<> nil);
6695 utils
.writeBool(st
, anim
);
6696 // Åñëè åñòü - ñîõðàíÿåì
6697 if anim
then FAnimationMask
.SaveState(st
);
6701 procedure TCorpse
.LoadState (st
: TStream
);
6708 if not utils
.checkSign(st
, 'CORP') then raise XStreamError
.Create('invalid corpse signature');
6709 if (utils
.readByte(st
) <> 0) then raise XStreamError
.Create('invalid corpse version');
6711 FState
:= utils
.readByte(st
);
6713 FDamage
:= utils
.readByte(st
);
6715 FColor
.R
:= utils
.readByte(st
);
6716 FColor
.G
:= utils
.readByte(st
);
6717 FColor
.B
:= utils
.readByte(st
);
6719 Obj_LoadState(@FObj
, st
);
6720 FPlayerUID
:= utils
.readWord(st
);
6722 anim
:= utils
.readBool(st
);
6723 // Åñëè åñòü - çàãðóæàåì
6726 Assert(FAnimation
<> nil, 'TCorpse.LoadState: no FAnimation');
6727 FAnimation
.LoadState(st
);
6729 // Åñòü ëè ìàñêà àíèìàöèè
6730 anim
:= utils
.readBool(st
);
6731 // Åñëè åñòü - çàãðóæàåì
6734 Assert(FAnimationMask
<> nil, 'TCorpse.LoadState: no FAnimationMask');
6735 FAnimationMask
.LoadState(st
);
6741 constructor TBot
.Create();
6748 FSpectator
:= False;
6755 for a
:= WP_FIRST
to WP_LAST
do
6757 FDifficult
.WeaponPrior
[a
] := WEAPON_PRIOR1
[a
];
6758 FDifficult
.CloseWeaponPrior
[a
] := WEAPON_PRIOR2
[a
];
6759 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
6763 destructor TBot
.Destroy();
6766 inherited Destroy();
6769 procedure TBot
.Draw();
6773 //if FTargetUID <> 0 then e_DrawLine(1, FObj.X, FObj.Y, g_Player_Get(FTargetUID).FObj.X,
6774 // g_Player_Get(FTargetUID).FObj.Y, 255, 0, 0);
6777 procedure TBot
.Respawn(Silent
: Boolean; Force
: Boolean = False);
6779 inherited Respawn(Silent
, Force
);
6782 FSelectedWeapon
:= FCurrWeap
;
6787 procedure TBot
.UpdateCombat();
6800 TTargetRecord
= array of TTarget
;
6802 function Compare(a
, b
: TTarget
): Integer;
6804 if a
.Line
and not b
.Line
then // A íà ëèíèè îãíÿ
6807 if not a
.Line
and b
.Line
then // B íà ëèíèè îãíÿ
6809 else // È A, è B íà ëèíèè èëè íå íà ëèíèè îãíÿ
6810 if (a
.Line
and b
.Line
) or ((not a
.Line
) and (not b
.Line
)) then
6812 if a
.Dist
> b
.Dist
then // B áëèæå
6814 else // A áëèæå èëè ðàâíîóäàëåííî ñ B
6817 else // Ñòðàííî -> A
6822 a
, x1
, y1
, x2
, y2
: Integer;
6823 targets
: TTargetRecord
;
6825 Target
, BestTarget
: TTarget
;
6826 firew
, fireh
: Integer;
6830 vsPlayer
, vsMonster
, ok
: Boolean;
6833 function monsUpdate (mon
: TMonster
): Boolean;
6835 result
:= false; // don't stop
6836 if mon
.alive
and (mon
.MonsterType
<> MONSTER_BARREL
) then
6838 if not TargetOnScreen(mon
.Obj
.X
+mon
.Obj
.Rect
.X
, mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
) then exit
;
6840 x2
:= mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2);
6841 y2
:= mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+(mon
.Obj
.Rect
.Height
div 2);
6843 // Åñëè ìîíñòð íà ýêðàíå è íå ïðèêðûò ñòåíîé
6844 if g_TraceVector(x1
, y1
, x2
, y2
) then
6846 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé
6847 SetLength(targets
, Length(targets
)+1);
6848 with targets
[High(targets
)] do
6855 Rect
:= mon
.Obj
.Rect
;
6856 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6857 Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6858 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6867 vsPlayer
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
);
6868 vsMonster
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
);
6870 // Åñëè òåêóùåå îðóæèå íå òî, ÷òî íóæíî, òî ìåíÿåì:
6871 if FCurrWeap
<> FSelectedWeapon
then
6874 // Åñëè íóæíî ñòðåëÿòü è íóæíîå îðóæèå, òî íàæàòü "Ñòðåëÿòü":
6875 if (GetAIFlag('NEEDFIRE') <> '') and (FCurrWeap
= FSelectedWeapon
) then
6877 RemoveAIFlag('NEEDFIRE');
6880 WEAPON_PLASMA
, WEAPON_SUPERPULEMET
, WEAPON_CHAINGUN
: PressKey(KEY_FIRE
, 20);
6881 WEAPON_SAW
, WEAPON_KASTET
, WEAPON_FLAMETHROWER
: PressKey(KEY_FIRE
, 40);
6882 else PressKey(KEY_FIRE
);
6886 // Êîîðäèíàòû ñòâîëà:
6887 x1
:= FObj
.X
+ WEAPONPOINT
[FDirection
].X
;
6888 y1
:= FObj
.Y
+ WEAPONPOINT
[FDirection
].Y
;
6890 Target
.UID
:= FTargetUID
;
6893 if Target
.UID
<> 0 then
6894 begin // Öåëü åñòü - íàñòðàèâàåì
6895 if (g_GetUIDType(Target
.UID
) = UID_PLAYER
) and
6898 tpla
:= g_Player_Get(Target
.UID
);
6902 if (@FObj
) <> nil then
6909 Target
.cX
:= Target
.X
+ PLAYER_RECT_CX
;
6910 Target
.cY
:= Target
.Y
+ PLAYER_RECT_CY
;
6911 Target
.Rect
:= PLAYER_RECT
;
6912 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6913 Target
.Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6914 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6915 Target
.IsPlayer
:= True;
6919 if (g_GetUIDType(Target
.UID
) = UID_MONSTER
) and
6922 mon
:= g_Monsters_ByUID(Target
.UID
);
6925 Target
.X
:= mon
.Obj
.X
;
6926 Target
.Y
:= mon
.Obj
.Y
;
6928 Target
.cX
:= Target
.X
+ mon
.Obj
.Rect
.X
+ (mon
.Obj
.Rect
.Width
div 2);
6929 Target
.cY
:= Target
.Y
+ mon
.Obj
.Rect
.Y
+ (mon
.Obj
.Rect
.Height
div 2);
6930 Target
.Rect
:= mon
.Obj
.Rect
;
6931 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6932 Target
.Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6933 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6934 Target
.IsPlayer
:= False;
6941 begin // Öåëè íåò - îáíóëÿåì
6946 Target
.Visible
:= False;
6947 Target
.Line
:= False;
6948 Target
.IsPlayer
:= False;
6953 // Åñëè öåëü íå âèäèìà èëè íå íà ëèíèè îãíÿ, òî èùåì âñå âîçìîæíûå öåëè:
6954 if (not Target
.Line
) or (not Target
.Visible
) then
6958 for a
:= 0 to High(gPlayers
) do
6959 if (gPlayers
[a
] <> nil) and (gPlayers
[a
].alive
) and
6960 (gPlayers
[a
].FUID
<> FUID
) and
6961 (not SameTeam(FUID
, gPlayers
[a
].FUID
)) and
6962 (not gPlayers
[a
].NoTarget
) and
6963 (gPlayers
[a
].FMegaRulez
[MR_INVIS
] < gTime
) then
6965 if not TargetOnScreen(gPlayers
[a
].FObj
.X
+ PLAYER_RECT
.X
,
6966 gPlayers
[a
].FObj
.Y
+ PLAYER_RECT
.Y
) then
6969 x2
:= gPlayers
[a
].FObj
.X
+ PLAYER_RECT_CX
;
6970 y2
:= gPlayers
[a
].FObj
.Y
+ PLAYER_RECT_CY
;
6972 // Åñëè èãðîê íà ýêðàíå è íå ïðèêðûò ñòåíîé:
6973 if g_TraceVector(x1
, y1
, x2
, y2
) then
6975 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé:
6976 SetLength(targets
, Length(targets
)+1);
6977 with targets
[High(targets
)] do
6979 UID
:= gPlayers
[a
].FUID
;
6980 X
:= gPlayers
[a
].FObj
.X
;
6981 Y
:= gPlayers
[a
].FObj
.Y
;
6984 Rect
:= PLAYER_RECT
;
6985 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6986 Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6987 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6995 if vsMonster
then g_Mons_ForEach(monsUpdate
);
6998 // Åñëè åñòü âîçìîæíûå öåëè:
6999 // (Âûáèðàåì ëó÷øóþ, ìåíÿåì îðóæèå è áåæèì ê íåé/îò íåå)
7000 if targets
<> nil then
7002 // Âûáèðàåì íàèëó÷øóþ öåëü:
7003 BestTarget
:= targets
[0];
7004 if Length(targets
) > 1 then
7005 for a
:= 1 to High(targets
) do
7006 if Compare(BestTarget
, targets
[a
]) = 1 then
7007 BestTarget
:= targets
[a
];
7009 // Åñëè ëó÷øàÿ öåëü "âèäíåå" òåêóùåé, òî òåêóùàÿ := ëó÷øàÿ:
7010 if ((not Target
.Visible
) and BestTarget
.Visible
and (Target
.UID
<> BestTarget
.UID
)) or
7011 ((not Target
.Line
) and BestTarget
.Line
and BestTarget
.Visible
) then
7013 Target
:= BestTarget
;
7015 if (Healthy() = 3) or ((Healthy() = 2)) then
7016 begin // Åñëè çäîðîâû - äîãîíÿåì
7017 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
7018 SetAIFlag('GORIGHT', '1');
7019 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
7020 SetAIFlag('GOLEFT', '1');
7023 begin // Åñëè ïîáèòû - óáåãàåì
7024 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) then
7025 SetAIFlag('GORIGHT', '1');
7026 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
7027 SetAIFlag('GOLEFT', '1');
7030 // Âûáèðàåì îðóæèå íà îñíîâå ðàññòîÿíèÿ è ïðèîðèòåòîâ:
7031 SelectWeapon(Abs(x1
-Target
.cX
));
7036 // (Äîãîíÿåì/óáåãàåì, ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëè)
7037 // (Åñëè öåëü äàëåêî, òî õâàòèò ñëåäèòü çà íåé)
7038 if Target
.UID
<> 0 then
7040 if not TargetOnScreen(Target
.X
+ Target
.Rect
.X
,
7041 Target
.Y
+ Target
.Rect
.Y
) then
7042 begin // Öåëü ñáåæàëà ñ "ýêðàíà"
7043 if (Healthy() = 3) or ((Healthy() = 2)) then
7044 begin // Åñëè çäîðîâû - äîãîíÿåì
7045 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
7046 SetAIFlag('GORIGHT', '1');
7047 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
7048 SetAIFlag('GOLEFT', '1');
7051 begin // Åñëè ïîáèòû - çàáûâàåì î öåëè è óáåãàåì
7053 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) then
7054 SetAIFlag('GORIGHT', '1');
7055 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
7056 SetAIFlag('GOLEFT', '1');
7060 begin // Öåëü ïîêà íà "ýêðàíå"
7061 // Åñëè öåëü íå çàãîðîæåíà ñòåíîé, òî îòìå÷àåì, êîãäà åå âèäåëè:
7062 if g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
7063 FLastVisible
:= gTime
;
7064 // Åñëè ðàçíèöà âûñîò íå âåëèêà, òî äîãîíÿåì:
7065 if (Abs(FObj
.Y
-Target
.Y
) <= 128) then
7067 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
7068 SetAIFlag('GORIGHT', '1');
7069 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
7070 SetAIFlag('GOLEFT', '1');
7074 // Âûáèðàåì óãîë ââåðõ:
7075 if FDirection
= TDirection
.D_LEFT
then
7076 angle
:= ANGLE_LEFTUP
7078 angle
:= ANGLE_RIGHTUP
;
7080 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7081 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7083 // Åñëè ïðè óãëå ââåðõ ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
7084 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
7085 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128), //96
7086 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
7087 Target
.Rect
.Width
, Target
.Rect
.Height
) and
7088 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
7089 begin // òî íóæíî ñòðåëÿòü ââåðõ
7090 SetAIFlag('NEEDFIRE', '1');
7091 SetAIFlag('NEEDSEEUP', '1');
7094 // Âûáèðàåì óãîë âíèç:
7095 if FDirection
= TDirection
.D_LEFT
then
7096 angle
:= ANGLE_LEFTDOWN
7098 angle
:= ANGLE_RIGHTDOWN
;
7100 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7101 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7103 // Åñëè ïðè óãëå âíèç ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
7104 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
7105 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
7106 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
7107 Target
.Rect
.Width
, Target
.Rect
.Height
) and
7108 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
7109 begin // òî íóæíî ñòðåëÿòü âíèç
7110 SetAIFlag('NEEDFIRE', '1');
7111 SetAIFlag('NEEDSEEDOWN', '1');
7114 // Åñëè öåëü âèäíî è îíà íà òàêîé æå âûñîòå:
7115 if Target
.Visible
and
7116 (y1
+4 < Target
.Y
+Target
.Rect
.Y
+Target
.Rect
.Height
) and
7117 (y1
-4 > Target
.Y
+Target
.Rect
.Y
) then
7119 // Åñëè èäåì â ñòîðîíó öåëè, òî íàäî ñòðåëÿòü:
7120 if ((FDirection
= TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) or
7121 ((FDirection
= TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
7122 begin // òî íóæíî ñòðåëÿòü âïåðåä
7123 SetAIFlag('NEEDFIRE', '1');
7124 SetAIFlag('NEEDSEEDOWN', '');
7125 SetAIFlag('NEEDSEEUP', '');
7127 // Åñëè öåëü â ïðåäåëàõ "ýêðàíà" è ñëîæíîñòü ïîçâîëÿåò ïðûæêè ñáëèæåíèÿ:
7128 if Abs(FObj
.X
-Target
.X
) < Trunc(gPlayerScreenSize
.X
*0.75) then
7129 if GetRnd(FDifficult
.CloseJump
) then
7130 begin // òî åñëè ïîâåçåò - ïðûãàåì (îñîáåííî, åñëè áëèçêî)
7131 if Abs(FObj
.X
-Target
.X
) < 128 then
7135 if Random(a
) = 0 then
7136 SetAIFlag('NEEDJUMP', '1');
7140 // Åñëè öåëü âñå åùå åñòü:
7141 if Target
.UID
<> 0 then
7142 if gTime
-FLastVisible
> 2000 then // Åñëè âèäåëè äàâíî
7143 Target
.UID
:= 0 // òî çàáûòü öåëü
7144 else // Åñëè âèäåëè íåäàâíî
7145 begin // íî öåëü óáèëè
7146 if Target
.IsPlayer
then
7147 begin // Öåëü - èãðîê
7148 pla
:= g_Player_Get(Target
.UID
);
7149 if (pla
= nil) or (not pla
.alive
) or pla
.NoTarget
or
7150 (pla
.FMegaRulez
[MR_INVIS
] >= gTime
) then
7151 Target
.UID
:= 0; // òî çàáûòü öåëü
7154 begin // Öåëü - ìîíñòð
7155 mon
:= g_Monsters_ByUID(Target
.UID
);
7156 if (mon
= nil) or (not mon
.alive
) then
7157 Target
.UID
:= 0; // òî çàáûòü öåëü
7160 end; // if Target.UID <> 0
7162 FTargetUID
:= Target
.UID
;
7164 // Åñëè âîçìîæíûõ öåëåé íåò:
7165 // (Àòàêà ÷åãî-íèáóäü ñëåâà èëè ñïðàâà)
7166 if targets
= nil then
7167 if GetAIFlag('ATTACKLEFT') <> '' then
7168 begin // Åñëè íóæíî àòàêîâàòü íàëåâî
7169 RemoveAIFlag('ATTACKLEFT');
7171 SetAIFlag('NEEDJUMP', '1');
7173 if RunDirection() = TDirection
.D_RIGHT
then
7174 begin // Èäåì íå â òó ñòîðîíó
7175 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
7176 begin // Åñëè çäîðîâû, òî, âîçìîæíî, ñòðåëÿåì áåæèì âëåâî è ñòðåëÿåì
7177 SetAIFlag('NEEDFIRE', '1');
7178 SetAIFlag('GOLEFT', '1');
7182 begin // Èäåì â íóæíóþ ñòîðîíó
7183 if GetRnd(FDifficult
.InvisFire
) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
7184 SetAIFlag('NEEDFIRE', '1');
7185 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
7186 SetAIFlag('GORIGHT', '1');
7190 if GetAIFlag('ATTACKRIGHT') <> '' then
7191 begin // Åñëè íóæíî àòàêîâàòü íàïðàâî
7192 RemoveAIFlag('ATTACKRIGHT');
7194 SetAIFlag('NEEDJUMP', '1');
7196 if RunDirection() = TDirection
.D_LEFT
then
7197 begin // Èäåì íå â òó ñòîðîíó
7198 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
7199 begin // Åñëè çäîðîâû, òî, âîçìîæíî, áåæèì âïðàâî è ñòðåëÿåì
7200 SetAIFlag('NEEDFIRE', '1');
7201 SetAIFlag('GORIGHT', '1');
7206 if GetRnd(FDifficult
.InvisFire
) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
7207 SetAIFlag('NEEDFIRE', '1');
7208 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
7209 SetAIFlag('GOLEFT', '1');
7213 //HACK! (does it belongs there?)
7214 RealizeCurrentWeapon();
7216 // Åñëè åñòü âîçìîæíûå öåëè:
7217 // (Ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëÿì)
7218 if (targets
<> nil) and (GetAIFlag('NEEDFIRE') <> '') then
7219 for a
:= 0 to High(targets
) do
7221 // Åñëè ìîæåì ñòðåëÿòü ïî äèàãîíàëè:
7222 if GetRnd(FDifficult
.DiagFire
) then
7224 // Èùåì öåëü ñâåðõó è ñòðåëÿåì, åñëè åñòü:
7225 if FDirection
= TDirection
.D_LEFT
then
7226 angle
:= ANGLE_LEFTUP
7228 angle
:= ANGLE_RIGHTUP
;
7230 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7231 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7233 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
7234 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
7235 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
7236 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
7237 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
7239 SetAIFlag('NEEDFIRE', '1');
7240 SetAIFlag('NEEDSEEUP', '1');
7243 // Èùåì öåëü ñíèçó è ñòðåëÿåì, åñëè åñòü:
7244 if FDirection
= TDirection
.D_LEFT
then
7245 angle
:= ANGLE_LEFTDOWN
7247 angle
:= ANGLE_RIGHTDOWN
;
7249 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7250 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7252 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
7253 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
7254 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
7255 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
7256 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
7258 SetAIFlag('NEEDFIRE', '1');
7259 SetAIFlag('NEEDSEEDOWN', '1');
7263 // Åñëè öåëü "ïåðåä íîñîì", òî ñòðåëÿåì:
7264 if targets
[a
].Line
and targets
[a
].Visible
and
7265 (((FDirection
= TDirection
.D_LEFT
) and (targets
[a
].X
< FObj
.X
)) or
7266 ((FDirection
= TDirection
.D_RIGHT
) and (targets
[a
].X
> FObj
.X
))) then
7268 SetAIFlag('NEEDFIRE', '1');
7273 // Åñëè ëåòèò ïóëÿ, òî, âîçìîæíî, ïîäïðûãèâàåì:
7274 if g_Weapon_Danger(FUID
, FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
,
7275 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
,
7276 40+GetInterval(FDifficult
.Cover
, 40)) then
7277 SetAIFlag('NEEDJUMP', '1');
7279 // Åñëè êîí÷èëèñü ïàòîðíû, òî íóæíî ñìåíèòü îðóæèå:
7280 ammo
:= GetAmmoByWeapon(FCurrWeap
);
7281 if ((FCurrWeap
= WEAPON_SHOTGUN2
) and (ammo
< 2)) or
7282 ((FCurrWeap
= WEAPON_BFG
) and (ammo
< 40)) or
7284 SetAIFlag('SELECTWEAPON', '1');
7286 // Åñëè íóæíî ñìåíèòü îðóæèå, òî âûáèðàåì íóæíîå:
7287 if GetAIFlag('SELECTWEAPON') = '1' then
7290 RemoveAIFlag('SELECTWEAPON');
7294 procedure TBot
.Update();
7307 // Ïðîâåðÿåì, îòêëþ÷¸í ëè AI áîòîâ
7308 if (g_debug_BotAIOff
= 1) and (Team
= TEAM_RED
) then
7310 if (g_debug_BotAIOff
= 2) and (Team
= TEAM_BLUE
) then
7312 if g_debug_BotAIOff
= 3 then
7322 RealizeCurrentWeapon();
7329 procedure TBot
.ReleaseKey(Key
: Byte);
7338 function TBot
.KeyPressed(Key
: Word): Boolean;
7340 Result
:= FKeys
[Key
].Pressed
;
7343 function TBot
.GetAIFlag(aName
: String20
): String20
;
7349 aName
:= LowerCase(aName
);
7351 if FAIFlags
<> nil then
7352 for a
:= 0 to High(FAIFlags
) do
7353 if LowerCase(FAIFlags
[a
].Name
) = aName
then
7355 Result
:= FAIFlags
[a
].Value
;
7360 procedure TBot
.RemoveAIFlag(aName
: String20
);
7364 if FAIFlags
= nil then Exit
;
7366 aName
:= LowerCase(aName
);
7368 for a
:= 0 to High(FAIFlags
) do
7369 if LowerCase(FAIFlags
[a
].Name
) = aName
then
7371 if a
<> High(FAIFlags
) then
7372 for b
:= a
to High(FAIFlags
)-1 do
7373 FAIFlags
[b
] := FAIFlags
[b
+1];
7375 SetLength(FAIFlags
, Length(FAIFlags
)-1);
7380 procedure TBot
.SetAIFlag(aName
, fValue
: String20
);
7388 aName
:= LowerCase(aName
);
7390 if FAIFlags
<> nil then
7391 for a
:= 0 to High(FAIFlags
) do
7392 if LowerCase(FAIFlags
[a
].Name
) = aName
then
7398 if ok
then FAIFlags
[a
].Value
:= fValue
7401 SetLength(FAIFlags
, Length(FAIFlags
)+1);
7402 with FAIFlags
[High(FAIFlags
)] do
7410 procedure TBot
.UpdateMove
;
7412 procedure GoLeft(Time
: Word = 1);
7414 ReleaseKey(KEY_LEFT
);
7415 ReleaseKey(KEY_RIGHT
);
7416 PressKey(KEY_LEFT
, Time
);
7417 SetDirection(TDirection
.D_LEFT
);
7420 procedure GoRight(Time
: Word = 1);
7422 ReleaseKey(KEY_LEFT
);
7423 ReleaseKey(KEY_RIGHT
);
7424 PressKey(KEY_RIGHT
, Time
);
7425 SetDirection(TDirection
.D_RIGHT
);
7428 function Rnd(a
: Word): Boolean;
7430 Result
:= Random(a
) = 0;
7433 procedure Turn(Time
: Word = 1200);
7435 if RunDirection() = TDirection
.D_LEFT
then GoRight(Time
) else GoLeft(Time
);
7440 ReleaseKey(KEY_LEFT
);
7441 ReleaseKey(KEY_RIGHT
);
7444 function CanRunLeft(): Boolean;
7446 Result
:= not CollideLevel(-1, 0);
7449 function CanRunRight(): Boolean;
7451 Result
:= not CollideLevel(1, 0);
7454 function CanRun(): Boolean;
7456 if RunDirection() = TDirection
.D_LEFT
then Result
:= CanRunLeft() else Result
:= CanRunRight();
7459 procedure Jump(Time
: Word = 30);
7461 PressKey(KEY_JUMP
, Time
);
7464 function NearHole(): Boolean;
7468 { TODO 5 : Ëåñòíèöû }
7469 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7470 for x
:= 1 to PLAYER_RECT
.Width
do
7471 if (not StayOnStep(x
*sx
, 0)) and
7472 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7473 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7482 function BorderHole(): Boolean;
7486 { TODO 5 : Ëåñòíèöû }
7487 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7488 for x
:= 1 to PLAYER_RECT
.Width
do
7489 if (not StayOnStep(x
*sx
, 0)) and
7490 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7491 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7493 for xx
:= x
to x
+32 do
7494 if CollideLevel(xx
*sx
, PLAYER_RECT
.Height
) then
7504 function NearDeepHole(): Boolean;
7510 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7513 for x
:= 1 to PLAYER_RECT
.Width
do
7514 if (not StayOnStep(x
*sx
, 0)) and
7515 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7516 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7518 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
7520 if CollideLevel(x
*sx
, PLAYER_RECT
.Height
*y
) then Exit
;
7525 end else Result
:= False;
7528 function OverDeepHole(): Boolean;
7535 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
7537 if CollideLevel(0, PLAYER_RECT
.Height
*y
) then Exit
;
7544 function OnGround(): Boolean;
7546 Result
:= StayOnStep(0, 0) or CollideLevel(0, 1);
7549 function OnLadder(): Boolean;
7551 Result
:= FullInStep(0, 0);
7554 function BelowLadder(): Boolean;
7556 Result
:= (FullInStep(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) and
7557 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
7558 (FullInStep(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) and
7559 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
7562 function BelowLiftUp(): Boolean;
7564 Result
:= ((FullInLift(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) = -1) and
7565 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
7566 ((FullInLift(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) = -1) and
7567 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
7570 function OnTopLift(): Boolean;
7572 Result
:= (FullInLift(0, 0) = -1) and (FullInLift(0, -32) = 0);
7575 function CanJumpOver(): Boolean;
7579 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7583 if not CollideLevel(sx
, 0) then Exit
;
7585 for y
:= 1 to BOT_MAXJUMP
do
7586 if CollideLevel(0, -y
) then Exit
else
7587 if not CollideLevel(sx
, -y
) then
7594 function CanJumpUp(Dist
: ShortInt): Boolean;
7601 if CollideLevel(Dist
, 0) then Exit
;
7604 for y
:= 0 to BOT_MAXJUMP
do
7605 if CollideLevel(Dist
, -y
) then
7614 for yy
:= y
+1 to BOT_MAXJUMP
do
7615 if not CollideLevel(Dist
, -yy
) then
7624 for y
:= 0 to BOT_MAXJUMP
do
7625 if CollideLevel(0, -y
) then
7633 if y
< yy
then Exit
;
7638 function IsSafeTrigger(): Boolean;
7643 if gTriggers
= nil then
7645 for a
:= 0 to High(gTriggers
) do
7646 if Collide(gTriggers
[a
].X
,
7649 gTriggers
[a
].Height
) and
7650 (gTriggers
[a
].TriggerType
in [TRIGGER_EXIT
, TRIGGER_CLOSEDOOR
,
7651 TRIGGER_CLOSETRAP
, TRIGGER_TRAP
,
7652 TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
,
7653 TRIGGER_ONOFF
, TRIGGER_SPAWNMONSTER
,
7654 TRIGGER_DAMAGE
, TRIGGER_SHOT
]) then
7659 // Âîçìîæíî, íàæèìàåì êíîïêó:
7660 if Rnd(16) and IsSafeTrigger() then
7663 // Åñëè ïîä ëèôòîì èëè ñòóïåíüêàìè, òî, âîçìîæíî, ïðûãàåì:
7664 if OnLadder() or ((BelowLadder() or BelowLiftUp()) and Rnd(8)) then
7666 ReleaseKey(KEY_LEFT
);
7667 ReleaseKey(KEY_RIGHT
);
7671 // Èäåì âëåâî, åñëè íàäî áûëî:
7672 if GetAIFlag('GOLEFT') <> '' then
7674 RemoveAIFlag('GOLEFT');
7675 if CanRunLeft() then
7679 // Èäåì âïðàâî, åñëè íàäî áûëî:
7680 if GetAIFlag('GORIGHT') <> '' then
7682 RemoveAIFlag('GORIGHT');
7683 if CanRunRight() then
7687 // Åñëè âûëåòåëè çà êàðòó, òî ïðîáóåì âåðíóòüñÿ:
7688 if FObj
.X
< -32 then
7691 if FObj
.X
+32 > gMapInfo
.Width
then
7694 // Ïðûãàåì, åñëè íàäî áûëî:
7695 if GetAIFlag('NEEDJUMP') <> '' then
7698 RemoveAIFlag('NEEDJUMP');
7701 // Ñìîòðèì ââåðõ, åñëè íàäî áûëî:
7702 if GetAIFlag('NEEDSEEUP') <> '' then
7705 ReleaseKey(KEY_DOWN
);
7706 PressKey(KEY_UP
, 20);
7707 RemoveAIFlag('NEEDSEEUP');
7710 // Ñìîòðèì âíèç, åñëè íàäî áûëî:
7711 if GetAIFlag('NEEDSEEDOWN') <> '' then
7714 ReleaseKey(KEY_DOWN
);
7715 PressKey(KEY_DOWN
, 20);
7716 RemoveAIFlag('NEEDSEEDOWN');
7719 // Åñëè íóæíî áûëî â äûðó è ìû íå íà çåìëå, òî ïîêîðíî ëåòèì:
7720 if GetAIFlag('GOINHOLE') <> '' then
7721 if not OnGround() then
7723 ReleaseKey(KEY_LEFT
);
7724 ReleaseKey(KEY_RIGHT
);
7725 RemoveAIFlag('GOINHOLE');
7726 SetAIFlag('FALLINHOLE', '1');
7729 // Åñëè ïàäàëè è äîñòèãëè çåìëè, òî õâàòèò ïàäàòü:
7730 if GetAIFlag('FALLINHOLE') <> '' then
7732 RemoveAIFlag('FALLINHOLE');
7734 // Åñëè ëåòåëè ïðÿìî è ñåé÷àñ íå íà ëåñòíèöå èëè íà âåðøèíå ëèôòà, òî îòõîäèì â ñòîðîíó:
7735 if not (KeyPressed(KEY_LEFT
) or KeyPressed(KEY_RIGHT
)) then
7736 if GetAIFlag('FALLINHOLE') = '' then
7737 if (not OnLadder()) or (FObj
.Vel
.Y
>= 0) or (OnTopLift()) then
7743 // Åñëè íà çåìëå è ìîæíî ïîäïðûãíóòü, òî, âîçìîæíî, ïðûãàåì:
7745 CanJumpUp(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*32) and
7749 // Åñëè íà çåìëå è âîçëå äûðû (ãëóáèíà > 2 ðîñòîâ èãðîêà):
7750 if OnGround() and NearHole() then
7751 if NearDeepHole() then // Åñëè ýòî áåçäíà
7753 0..3: Turn(); // Áåæèì îáðàòíî
7754 4: Jump(); // Ïðûãàåì
7755 5: begin // Ïðûãàåì îáðàòíî
7760 else // Ýòî íå áåçäíà è ìû åùå íå ëåòèì òóäà
7761 if GetAIFlag('GOINHOLE') = '' then
7763 0: Turn(); // Íå íóæíî òóäà
7764 1: Jump(); // Âäðóã ïîâåçåò - ïðûãàåì
7765 else // Åñëè ÿìà ñ ãðàíèöåé, òî ïðè ñëó÷àå ìîæíî òóäà ïðûãíóòü
7766 if BorderHole() then
7767 SetAIFlag('GOINHOLE', '1');
7770 // Åñëè íà çåìëå, íî íåêóäà èäòè:
7771 if (not CanRun()) and OnGround() then
7773 // Åñëè ìû íà ëåñòíèöå èëè ìîæíî ïåðåïðûãíóòü, òî ïðûãàåì:
7774 if CanJumpOver() or OnLadder() then
7776 else // èíà÷å ïîïûòàåìñÿ â äðóãóþ ñòîðîíó
7777 if Random(2) = 0 then
7779 if IsSafeTrigger() then
7785 // Îñòàëîñü ìàëî âîçäóõà:
7786 if FAir
< 36 * 2 then
7789 // Âûáèðàåìñÿ èç êèñëîòû, åñëè íåò êîñòþìà, îáîæãëèñü, èëè ìàëî çäîðîâüÿ:
7790 if (FMegaRulez
[MR_SUIT
] < gTime
) and ((FLastHit
= HIT_ACID
) or (Healthy() <= 1)) then
7791 if BodyInAcid(0, 0) then
7795 function TBot
.FullInStep(XInc
, YInc
: Integer): Boolean;
7797 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
7798 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_STEP
, False);
7801 {function TBot.NeedItem(Item: Byte): Byte;
7806 procedure TBot
.SelectWeapon(Dist
: Integer);
7810 function HaveAmmo(weapon
: Byte): Boolean;
7813 WEAPON_PISTOL
: Result
:= FAmmo
[A_BULLETS
] >= 1;
7814 WEAPON_SHOTGUN1
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7815 WEAPON_SHOTGUN2
: Result
:= FAmmo
[A_SHELLS
] >= 2;
7816 WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
] >= 10;
7817 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
] >= 1;
7818 WEAPON_PLASMA
: Result
:= FAmmo
[A_CELLS
] >= 10;
7819 WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
] >= 40;
7820 WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7821 WEAPON_FLAMETHROWER
: Result
:= FAmmo
[A_FUEL
] >= 1;
7822 else Result
:= True;
7827 if Dist
= -1 then Dist
:= BOT_LONGDIST
;
7829 if Dist
> BOT_LONGDIST
then
7830 begin // Äàëüíèé áîé
7832 if FWeapon
[FDifficult
.WeaponPrior
[a
]] and HaveAmmo(FDifficult
.WeaponPrior
[a
]) then
7834 FSelectedWeapon
:= FDifficult
.WeaponPrior
[a
];
7838 else //if Dist > BOT_UNSAFEDIST then
7839 begin // Áëèæíèé áîé
7841 if FWeapon
[FDifficult
.CloseWeaponPrior
[a
]] and HaveAmmo(FDifficult
.CloseWeaponPrior
[a
]) then
7843 FSelectedWeapon
:= FDifficult
.CloseWeaponPrior
[a
];
7850 if FWeapon[FDifficult.SafeWeaponPrior[a]] and HaveAmmo(FDifficult.SafeWeaponPrior[a]) then
7852 FSelectedWeapon := FDifficult.SafeWeaponPrior[a];
7858 function TBot
.PickItem(ItemType
: Byte; force
: Boolean; var remove
: Boolean): Boolean;
7860 Result
:= inherited PickItem(ItemType
, force
, remove
);
7862 if Result
then SetAIFlag('SELECTWEAPON', '1');
7865 function TBot
.Heal(value
: Word; Soft
: Boolean): Boolean;
7867 Result
:= inherited Heal(value
, Soft
);
7870 function TBot
.Healthy(): Byte;
7872 if FMegaRulez
[MR_INVUL
] >= gTime
then Result
:= 3
7873 else if (FHealth
> 80) or ((FHealth
> 50) and (FArmor
> 20)) then Result
:= 3
7874 else if (FHealth
> 50) then Result
:= 2
7875 else if (FHealth
> 20) then Result
:= 1
7879 function TBot
.TargetOnScreen(TX
, TY
: Integer): Boolean;
7881 Result
:= (Abs(FObj
.X
-TX
) <= Trunc(gPlayerScreenSize
.X
*0.6)) and
7882 (Abs(FObj
.Y
-TY
) <= Trunc(gPlayerScreenSize
.Y
*0.6));
7885 procedure TBot
.OnDamage(Angle
: SmallInt);
7893 if (Angle
= 0) or (Angle
= 180) then
7896 if (g_GetUIDType(FLastSpawnerUID
) = UID_PLAYER
) and
7897 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
) then
7899 pla
:= g_Player_Get(FLastSpawnerUID
);
7900 ok
:= not TargetOnScreen(pla
.FObj
.X
+ PLAYER_RECT
.X
,
7901 pla
.FObj
.Y
+ PLAYER_RECT
.Y
);
7904 if (g_GetUIDType(FLastSpawnerUID
) = UID_MONSTER
) and
7905 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
) then
7907 mon
:= g_Monsters_ByUID(FLastSpawnerUID
);
7908 ok
:= not TargetOnScreen(mon
.Obj
.X
+ mon
.Obj
.Rect
.X
,
7909 mon
.Obj
.Y
+ mon
.Obj
.Rect
.Y
);
7914 SetAIFlag('ATTACKLEFT', '1')
7916 SetAIFlag('ATTACKRIGHT', '1');
7920 function TBot
.RunDirection(): TDirection
;
7922 if Abs(Vel
.X
) >= 1 then
7924 if Vel
.X
> 0 then Result
:= TDirection
.D_RIGHT
else Result
:= TDirection
.D_LEFT
;
7926 Result
:= FDirection
;
7929 function TBot
.GetRnd(a
: Byte): Boolean;
7931 if a
= 0 then Result
:= False
7932 else if a
= 255 then Result
:= True
7933 else Result
:= Random(256) > 255-a
;
7936 function TBot
.GetInterval(a
: Byte; radius
: SmallInt): SmallInt;
7938 Result
:= Round((255-a
)/255*radius
*(Random(2)-1));
7942 procedure TDifficult
.save (st
: TStream
);
7944 utils
.writeInt(st
, Byte(DiagFire
));
7945 utils
.writeInt(st
, Byte(InvisFire
));
7946 utils
.writeInt(st
, Byte(DiagPrecision
));
7947 utils
.writeInt(st
, Byte(FlyPrecision
));
7948 utils
.writeInt(st
, Byte(Cover
));
7949 utils
.writeInt(st
, Byte(CloseJump
));
7950 st
.WriteBuffer(WeaponPrior
[Low(WeaponPrior
)], sizeof(WeaponPrior
));
7951 st
.WriteBuffer(CloseWeaponPrior
[Low(CloseWeaponPrior
)], sizeof(CloseWeaponPrior
));
7954 procedure TDifficult
.load (st
: TStream
);
7956 DiagFire
:= utils
.readByte(st
);
7957 InvisFire
:= utils
.readByte(st
);
7958 DiagPrecision
:= utils
.readByte(st
);
7959 FlyPrecision
:= utils
.readByte(st
);
7960 Cover
:= utils
.readByte(st
);
7961 CloseJump
:= utils
.readByte(st
);
7962 st
.ReadBuffer(WeaponPrior
[Low(WeaponPrior
)], sizeof(WeaponPrior
));
7963 st
.ReadBuffer(CloseWeaponPrior
[Low(CloseWeaponPrior
)], sizeof(CloseWeaponPrior
));
7967 procedure TBot
.SaveState (st
: TStream
);
7972 inherited SaveState(st
);
7973 utils
.writeSign(st
, 'BOT0');
7975 utils
.writeInt(st
, Byte(FSelectedWeapon
));
7977 utils
.writeInt(st
, Word(FTargetUID
));
7978 // Âðåìÿ ïîòåðè öåëè
7979 utils
.writeInt(st
, LongWord(FLastVisible
));
7980 // Êîëè÷åñòâî ôëàãîâ ÈÈ
7981 dw
:= Length(FAIFlags
);
7982 utils
.writeInt(st
, LongInt(dw
));
7984 for i
:= 0 to dw
-1 do
7986 utils
.writeStr(st
, FAIFlags
[i
].Name
, 20);
7987 utils
.writeStr(st
, FAIFlags
[i
].Value
, 20);
7989 // Íàñòðîéêè ñëîæíîñòè
7990 FDifficult
.save(st
);
7994 procedure TBot
.LoadState (st
: TStream
);
7999 inherited LoadState(st
);
8000 if not utils
.checkSign(st
, 'BOT0') then raise XStreamError
.Create('invalid bot signature');
8002 FSelectedWeapon
:= utils
.readByte(st
);
8004 FTargetUID
:= utils
.readWord(st
);
8005 // Âðåìÿ ïîòåðè öåëè
8006 FLastVisible
:= utils
.readLongWord(st
);
8007 // Êîëè÷åñòâî ôëàãîâ ÈÈ
8008 dw
:= utils
.readLongInt(st
);
8009 if (dw
< 0) or (dw
> 16384) then raise XStreamError
.Create('invalid number of bot AI flags');
8010 SetLength(FAIFlags
, dw
);
8012 for i
:= 0 to dw
-1 do
8014 FAIFlags
[i
].Name
:= utils
.readStr(st
, 20);
8015 FAIFlags
[i
].Value
:= utils
.readStr(st
, 20);
8017 // Íàñòðîéêè ñëîæíîñòè
8018 FDifficult
.load(st
);
8023 conRegVar('cheat_berserk_autoswitch', @gBerserkAutoswitch
, 'autoswitch to fist when berserk pack taken', '', true, true);
8024 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');
8025 conRegVar('player_indicator_style', @gPlayerIndicatorStyle
, 'Visual appearance of indicator', 'Visual appearance of indicator');