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;
265 FPreferredTeam
: Byte;
268 FWantsInGame
: Boolean;
273 FActualModelName
: string;
280 FSpawnInvul
: Integer;
282 FWaitForFirstSpawn
: Boolean; // set to `true` in server, used to spawn a player on first full state request
285 // debug: viewport offset
286 viewPortX
, viewPortY
, viewPortW
, viewPortH
: Integer;
288 function isValidViewPort (): Boolean; inline;
290 constructor Create(); virtual;
291 destructor Destroy(); override;
292 procedure Respawn(Silent
: Boolean; Force
: Boolean = False); virtual;
293 function GetRespawnPoint(): Byte;
294 procedure PressKey(Key
: Byte; Time
: Word = 1);
295 procedure ReleaseKeys();
296 procedure SetModel(ModelName
: String);
297 procedure SetColor(Color
: TRGB
);
298 function GetColor(): TRGB
;
299 procedure SetWeapon(W
: Byte);
300 function IsKeyPressed(K
: Byte): Boolean;
301 function GetKeys(): Byte;
302 function PickItem(ItemType
: Byte; arespawn
: Boolean; var remove
: Boolean): Boolean; virtual;
303 procedure SetWeaponPrefs(Prefs
: Array of Byte);
304 procedure SetWeaponPref(Weapon
, Pref
: Byte);
305 function GetWeaponPref(Weapon
: Byte) : Byte;
306 function GetMorePrefered() : Byte;
307 function Collide(X
, Y
: Integer; Width
, Height
: Word): Boolean; overload
;
308 function Collide(Panel
: TPanel
): Boolean; overload
;
309 function Collide(X
, Y
: Integer): Boolean; overload
;
310 procedure SetDirection(Direction
: TDirection
);
311 procedure GetSecret();
312 function TeleportTo(X
, Y
: Integer; silent
: Boolean; dir
: Byte): Boolean;
314 procedure Push(vx
, vy
: Integer);
315 procedure ChangeModel(ModelName
: String);
316 procedure SwitchTeam
;
317 procedure ChangeTeam(Team
: Byte);
319 function GetFlag(Flag
: Byte): Boolean;
320 procedure SetFlag(Flag
: Byte);
321 function DropFlag(Silent
: Boolean = True; DoThrow
: Boolean = False): Boolean;
322 function TryDropFlag(): Boolean;
323 procedure AllRulez(Health
: Boolean);
324 procedure RestoreHealthArmor();
325 procedure FragCombo();
326 procedure GiveItem(ItemType
: Byte);
327 procedure Damage(value
: Word; SpawnerUID
: Word; vx
, vy
: Integer; t
: Byte); virtual;
328 function Heal(value
: Word; Soft
: Boolean): Boolean; virtual;
329 procedure MakeBloodVector(Count
: Word; VelX
, VelY
: Integer);
330 procedure MakeBloodSimple(Count
: Word);
331 procedure Kill(KillType
: Byte; SpawnerUID
: Word; t
: Byte);
332 procedure Reset(Force
: Boolean);
333 procedure Spectate(NoMove
: Boolean = False);
334 procedure SwitchNoClip
;
335 procedure SoftReset();
336 procedure Draw(); virtual;
337 procedure DrawPain();
338 procedure DrawPickup();
339 procedure DrawRulez();
341 procedure DrawIndicator(Color
: TRGB
);
342 procedure DrawBubble();
344 procedure PreUpdate();
345 procedure Update(); virtual;
346 procedure RememberState();
347 procedure RecallState();
348 procedure SaveState (st
: TStream
); virtual;
349 procedure LoadState (st
: TStream
); virtual;
350 procedure PauseSounds(Enable
: Boolean);
351 procedure NetFire(Wpn
: Byte; X
, Y
, AX
, AY
: Integer; WID
: Integer = -1);
352 procedure DoLerp(Level
: Integer = 2);
353 procedure SetLerp(XTo
, YTo
: Integer);
354 procedure ProcessWeaponAction(Action
: Byte);
355 procedure QueueWeaponSwitch(Weapon
: Byte);
356 procedure RealizeCurrentWeapon();
360 procedure JetpackOff
;
361 procedure CatchFire(Attacker
: Word; Timeout
: Integer = PLAYER_BURN_TIME
);
363 //WARNING! this does nothing for now, but still call it!
364 procedure positionChanged (); //WARNING! call this after entity position was changed, or coldet will not work right!
366 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
367 procedure moveBy (dx
, dy
: Integer); inline;
369 function getCameraObj(): TObj
;
372 property Vel
: TPoint2i read FObj
.Vel
;
373 property Obj
: TObj read FObj
;
375 property Name
: String read FName write FName
;
376 property Model
: TPlayerModel read FModel
;
377 property Health
: Integer read FHealth write FHealth
;
378 property Lives
: Byte read FLives write FLives
;
379 property Armor
: Integer read FArmor write FArmor
;
380 property Air
: Integer read FAir write FAir
;
381 property JetFuel
: Integer read FJetFuel write FJetFuel
;
382 property Frags
: Integer read FFrags write FFrags
;
383 property Death
: Integer read FDeath write FDeath
;
384 property Kills
: Integer read FKills write FKills
;
385 property CurrWeap
: Byte read FCurrWeap write FCurrWeap
;
386 property WeapSwitchMode
: Byte read FWeapSwitchMode write FWeapSwitchMode
;
387 property SwitchToEmpty
: Byte read FSwitchToEmpty write FSwitchToEmpty
;
388 property MonsterKills
: Integer read FMonsterKills write FMonsterKills
;
389 property Secrets
: Integer read FSecrets
;
390 property GodMode
: Boolean read FGodMode write FGodMode
;
391 property NoTarget
: Boolean read FNoTarget write FNoTarget
;
392 property NoReload
: Boolean read FNoReload write FNoReload
;
393 property alive
: Boolean read FAlive write FAlive
;
394 property Flag
: Byte read FFlag
;
395 property Team
: Byte read FTeam write FTeam
;
396 property Direction
: TDirection read FDirection
;
397 property GameX
: Integer read FObj
.X write FObj
.X
;
398 property GameY
: Integer read FObj
.Y write FObj
.Y
;
399 property GameVelX
: Integer read FObj
.Vel
.X write FObj
.Vel
.X
;
400 property GameVelY
: Integer read FObj
.Vel
.Y write FObj
.Vel
.Y
;
401 property GameAccelX
: Integer read FObj
.Accel
.X write FObj
.Accel
.X
;
402 property GameAccelY
: Integer read FObj
.Accel
.Y write FObj
.Accel
.Y
;
403 property IncCam
: Integer read FIncCam write FIncCam
;
404 property IncCamOld
: Integer read FIncCamOld write FIncCamOld
;
405 property SlopeOld
: Integer read FSlopeOld write FSlopeOld
;
406 property UID
: Word read FUID write FUID
;
407 property JustTeleported
: Boolean read FJustTeleported write FJustTeleported
;
408 property NetTime
: LongWord read FNetTime write FNetTime
;
411 property eName
: String read FName write FName
;
412 property eHealth
: Integer read FHealth write FHealth
;
413 property eLives
: Byte read FLives write FLives
;
414 property eArmor
: Integer read FArmor write FArmor
;
415 property eAir
: Integer read FAir write FAir
;
416 property eJetFuel
: Integer read FJetFuel write FJetFuel
;
417 property eFrags
: Integer read FFrags write FFrags
;
418 property eDeath
: Integer read FDeath write FDeath
;
419 property eKills
: Integer read FKills write FKills
;
420 property eCurrWeap
: Byte read FCurrWeap write FCurrWeap
;
421 property eMonsterKills
: Integer read FMonsterKills write FMonsterKills
;
422 property eSecrets
: Integer read FSecrets write FSecrets
;
423 property eGodMode
: Boolean read FGodMode write FGodMode
;
424 property eNoTarget
: Boolean read FNoTarget write FNoTarget
;
425 property eNoReload
: Boolean read FNoReload write FNoReload
;
426 property eAlive
: Boolean read FAlive write FAlive
;
427 property eFlag
: Byte read FFlag
;
428 property eTeam
: Byte read FTeam write FTeam
;
429 property eDirection
: TDirection read FDirection
;
430 property eGameX
: Integer read FObj
.X write FObj
.X
;
431 property eGameY
: Integer read FObj
.Y write FObj
.Y
;
432 property eGameVelX
: Integer read FObj
.Vel
.X write FObj
.Vel
.X
;
433 property eGameVelY
: Integer read FObj
.Vel
.Y write FObj
.Vel
.Y
;
434 property eGameAccelX
: Integer read FObj
.Accel
.X write FObj
.Accel
.X
;
435 property eGameAccelY
: Integer read FObj
.Accel
.Y write FObj
.Accel
.Y
;
436 property eIncCam
: Integer read FIncCam write FIncCam
;
437 property eUID
: Word read FUID
;
438 property eJustTeleported
: Boolean read FJustTeleported
;
439 property eNetTime
: LongWord read FNetTime
;
441 // set this before assigning something to `eDamage`
442 property eDamageType
: Integer read mEDamageType write mEDamageType
;
443 property eDamage
: Integer write doDamage
;
454 WeaponPrior
: packed array [WP_FIRST
..WP_LAST
] of Byte;
455 CloseWeaponPrior
: packed array [WP_FIRST
..WP_LAST
] of Byte;
456 //SafeWeaponPrior: Array [WP_FIRST..WP_LAST] of Byte;
459 procedure save (st
: TStream
);
460 procedure load (st
: TStream
);
468 TBot
= class(TPlayer
)
470 FSelectedWeapon
: Byte;
473 FAIFlags
: Array of TAIFlag
;
474 FDifficult
: TDifficult
;
476 function GetRnd(a
: Byte): Boolean;
477 function GetInterval(a
: Byte; radius
: SmallInt): SmallInt;
478 function RunDirection(): TDirection
;
479 function FullInStep(XInc
, YInc
: Integer): Boolean;
480 //function NeedItem(Item: Byte): Byte;
481 procedure SelectWeapon(Dist
: Integer);
482 procedure SetAIFlag(aName
, fValue
: String20
);
483 function GetAIFlag(aName
: String20
): String20
;
484 procedure RemoveAIFlag(aName
: String20
);
485 function Healthy(): Byte;
486 procedure UpdateMove();
487 procedure UpdateCombat();
488 function KeyPressed(Key
: Word): Boolean;
489 procedure ReleaseKey(Key
: Byte);
490 function TargetOnScreen(TX
, TY
: Integer): Boolean;
491 procedure OnDamage(Angle
: SmallInt); override;
494 procedure Respawn(Silent
: Boolean; Force
: Boolean = False); override;
495 constructor Create(); override;
496 destructor Destroy(); override;
497 procedure Draw(); override;
498 function PickItem(ItemType
: Byte; force
: Boolean; var remove
: Boolean): Boolean; override;
499 function Heal(value
: Word; Soft
: Boolean): Boolean; override;
500 procedure Update(); override;
501 procedure SaveState (st
: TStream
); override;
502 procedure LoadState (st
: TStream
); override;
514 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
515 procedure moveBy (dx
, dy
: Integer); inline;
517 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
531 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
532 procedure moveBy (dx
, dy
: Integer); inline;
534 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
537 TCorpse
= class{$IFDEF USE_MEMPOOL}(TPoolObject
){$ENDIF}
546 FAnimation
: TAnimation
;
547 FAnimationMask
: TAnimation
;
550 constructor Create(X
, Y
: Integer; ModelName
: String; aMess
: Boolean);
551 destructor Destroy(); override;
552 procedure Damage(Value
: Word; SpawnerUID
: Word; vx
, vy
: Integer);
555 procedure SaveState (st
: TStream
);
556 procedure LoadState (st
: TStream
);
558 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
559 procedure moveBy (dx
, dy
: Integer); inline;
561 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
563 function ObjPtr (): PObj
; inline;
565 property Obj
: TObj read FObj
; // copies object
566 property State
: Byte read FState
;
567 property Mess
: Boolean read FMess
;
570 TTeamStat
= Array [TEAM_RED
..TEAM_BLUE
] of
576 gPlayers
: Array of TPlayer
;
577 gCorpses
: Array of TCorpse
;
578 gGibs
: Array of TGib
;
579 gShells
: Array of TShell
;
580 gTeamStat
: TTeamStat
;
581 gFly
: Boolean = False;
582 gAimLine
: Boolean = False;
583 gChatBubble
: Integer = 0;
584 gPlayerIndicator
: Integer = 1;
585 gPlayerIndicatorStyle
: Integer = 0;
587 gSpectLatchPID1
: Word = 0;
588 gSpectLatchPID2
: Word = 0;
589 MAX_RUNVEL
: Integer = 8;
590 VEL_JUMP
: Integer = 10;
591 SHELL_TIMEOUT
: Cardinal = 60000;
593 function Lerp(X
, Y
, Factor
: Integer): Integer;
595 procedure g_Gibs_SetMax(Count
: Word);
596 function g_Gibs_GetMax(): Word;
597 procedure g_Corpses_SetMax(Count
: Word);
598 function g_Corpses_GetMax(): Word;
599 procedure g_Shells_SetMax(Count
: Word);
600 function g_Shells_GetMax(): Word;
602 procedure g_Player_Init();
603 procedure g_Player_Free();
604 function g_Player_Create(ModelName
: String; Color
: TRGB
; Team
: Byte; Bot
: Boolean): Word;
605 function g_Player_CreateFromState (st
: TStream
): Word;
606 procedure g_Player_Remove(UID
: Word);
607 procedure g_Player_ResetTeams();
608 procedure g_Player_PreUpdate();
609 procedure g_Player_UpdateAll();
610 procedure g_Player_DrawAll();
611 procedure g_Player_DrawDebug(p
: TPlayer
);
612 procedure g_Player_DrawHealth();
613 procedure g_Player_RememberAll();
614 procedure g_Player_ResetAll(Force
, Silent
: Boolean);
615 function g_Player_Get(UID
: Word): TPlayer
;
616 function g_Player_GetCount(): Byte;
617 function g_Player_GetStats(): TPlayerStatArray
;
618 function g_Player_ValidName(Name
: String): Boolean;
619 function g_Player_CreateCorpse(Player
: TPlayer
): Integer;
620 procedure g_Player_CreateGibs(fX
, fY
: Integer; ModelName
: String; fColor
: TRGB
);
621 procedure g_Player_CreateShell(fX
, fY
, dX
, dY
: Integer; T
: Byte);
622 procedure g_Player_UpdatePhysicalObjects();
623 procedure g_Player_DrawCorpses();
624 procedure g_Player_DrawShells();
625 procedure g_Player_RemoveAllCorpses();
626 procedure g_Player_Corpses_SaveState (st
: TStream
);
627 procedure g_Player_Corpses_LoadState (st
: TStream
);
628 procedure g_Player_ResetReady();
629 procedure g_Bot_Add(Team
, Difficult
: Byte; Handicap
: Integer = 100);
630 procedure g_Bot_AddList(Team
: Byte; lname
: ShortString; num
: Integer = -1; Handicap
: Integer = 100);
631 procedure g_Bot_MixNames();
632 procedure g_Bot_RemoveAll();
637 {$INCLUDE ../nogl/noGLuses.inc}
638 {$IFDEF ENABLE_HOLMES}
641 e_log
, g_map
, g_items
, g_console
, g_gfx
, Math
,
642 g_options
, g_triggers
, g_menu
, g_game
, g_grid
, e_res
,
643 wadreader
, g_main
, g_monsters
, CONFIG
, g_language
,
644 g_net
, g_netmsg
, g_window
,
647 const PLR_SAVE_VERSION
= 0;
657 diag_precision
: Byte;
661 w_prior1
: Array [WP_FIRST
..WP_LAST
] of Byte;
662 w_prior2
: Array [WP_FIRST
..WP_LAST
] of Byte;
663 w_prior3
: Array [WP_FIRST
..WP_LAST
] of Byte;
667 TIME_RESPAWN1
= 1500;
668 TIME_RESPAWN2
= 2000;
669 TIME_RESPAWN3
= 3000;
672 JET_MAX
= 540; // ~30 sec
673 PLAYER_SUIT_TIME
= 30000;
674 PLAYER_INVUL_TIME
= 30000;
675 PLAYER_INVIS_TIME
= 35000;
676 FRAG_COMBO_TIME
= 3000;
680 ANGLE_RIGHTDOWN
= -35;
682 ANGLE_LEFTDOWN
= -145;
683 PLAYER_HEADRECT
: TRectWH
= (X
:24; Y
:12; Width
:20; Height
:12);
684 WEAPONPOINT
: Array [TDirection
] of TDFPoint
= ((X
:16; Y
:32), (X
:47; Y
:32));
687 BOT_UNSAFEDIST
= 128;
688 TEAMCOLOR
: Array [TEAM_RED
..TEAM_BLUE
] of TRGB
= ((R
:255; G
:0; B
:0),
690 DIFFICULT_EASY
: TDifficult
= (DiagFire
: 32; InvisFire
: 32; DiagPrecision
: 32;
691 FlyPrecision
: 32; Cover
: 32; CloseJump
: 32;
692 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
693 DIFFICULT_MEDIUM
: TDifficult
= (DiagFire
: 127; InvisFire
: 127; DiagPrecision
: 127;
694 FlyPrecision
: 127; Cover
: 127; CloseJump
: 127;
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_HARD
: TDifficult
= (DiagFire
: 255; InvisFire
: 255; DiagPrecision
: 255;
697 FlyPrecision
: 255; Cover
: 255; CloseJump
: 255;
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 WEAPON_PRIOR1
: Array [WP_FIRST
..WP_LAST
] of Byte =
700 (WEAPON_FLAMETHROWER
, WEAPON_SUPERPULEMET
,
701 WEAPON_SHOTGUN2
, WEAPON_SHOTGUN1
,
702 WEAPON_CHAINGUN
, WEAPON_PLASMA
, WEAPON_ROCKETLAUNCHER
,
703 WEAPON_BFG
, WEAPON_PISTOL
, WEAPON_SAW
, WEAPON_KASTET
);
704 WEAPON_PRIOR2
: Array [WP_FIRST
..WP_LAST
] of Byte =
705 (WEAPON_FLAMETHROWER
, WEAPON_SUPERPULEMET
,
706 WEAPON_BFG
, WEAPON_ROCKETLAUNCHER
,
707 WEAPON_SHOTGUN2
, WEAPON_PLASMA
, WEAPON_SHOTGUN1
,
708 WEAPON_CHAINGUN
, WEAPON_PISTOL
, WEAPON_SAW
, WEAPON_KASTET
);
709 //WEAPON_PRIOR3: Array [WP_FIRST..WP_LAST] of Byte =
710 // (WEAPON_FLAMETHROWER, WEAPON_SUPERPULEMET,
711 // WEAPON_BFG, WEAPON_PLASMA, WEAPON_SHOTGUN2,
712 // WEAPON_CHAINGUN, WEAPON_SHOTGUN1, WEAPON_SAW,
713 // WEAPON_ROCKETLAUNCHER, WEAPON_PISTOL, WEAPON_KASTET);
714 WEAPON_RELOAD
: Array [WP_FIRST
..WP_LAST
] of Byte =
715 (5, 2, 6, 18, 36, 2, 12, 2, 14, 2, 2);
717 PLAYER_SIGNATURE
= $52594C50; // 'PLYR'
718 CORPSE_SIGNATURE
= $50524F43; // 'CORP'
720 BOTNAMES_FILENAME
= 'botnames.txt';
721 BOTLIST_FILENAME
= 'botlist.txt';
725 MaxCorpses
: Word = 20;
726 MaxShells
: Word = 300;
727 CurrentGib
: Integer = 0;
728 CurrentShell
: Integer = 0;
729 BotNames
: Array of String;
730 BotList
: Array of TBotProfile
;
731 SavedStates
: Array of TPlayerSavedState
;
734 function Lerp(X
, Y
, Factor
: Integer): Integer;
736 Result
:= X
+ ((Y
- X
) div Factor
);
739 function SameTeam(UID1
, UID2
: Word): Boolean;
743 if (UID1
> UID_MAX_PLAYER
) or (UID1
<= UID_MAX_GAME
) or
744 (UID2
> UID_MAX_PLAYER
) or (UID2
<= UID_MAX_GAME
) then Exit
;
746 if (g_Player_Get(UID1
) = nil) or (g_Player_Get(UID2
) = nil) then Exit
;
748 if ((g_Player_Get(UID1
).Team
= TEAM_NONE
) or
749 (g_Player_Get(UID2
).Team
= TEAM_NONE
)) then Exit
;
751 Result
:= g_Player_Get(UID1
).FTeam
= g_Player_Get(UID2
).FTeam
;
754 procedure g_Gibs_SetMax(Count
: Word);
757 SetLength(gGibs
, Count
);
759 if CurrentGib
>= Count
then
763 function g_Gibs_GetMax(): Word;
768 procedure g_Shells_SetMax(Count
: Word);
771 SetLength(gShells
, Count
);
773 if CurrentShell
>= Count
then
777 function g_Shells_GetMax(): Word;
783 procedure g_Corpses_SetMax(Count
: Word);
786 SetLength(gCorpses
, Count
);
789 function g_Corpses_GetMax(): Word;
791 Result
:= MaxCorpses
;
794 function g_Player_Create(ModelName
: String; Color
: TRGB
; Team
: Byte; Bot
: Boolean): Word;
804 // Åñòü ëè ìåñòî â gPlayers:
805 if gPlayers
<> nil then
806 for a
:= 0 to High(gPlayers
) do
807 if gPlayers
[a
] = nil then
813 // Íåò ìåñòà - ðàñøèðÿåì gPlayers:
816 SetLength(gPlayers
, Length(gPlayers
)+1);
820 // Ñîçäàåì îáúåêò èãðîêà:
822 gPlayers
[a
] := TBot
.Create()
824 gPlayers
[a
] := TPlayer
.Create();
827 gPlayers
[a
].FActualModelName
:= ModelName
;
828 gPlayers
[a
].SetModel(ModelName
);
830 // Íåò ìîäåëè - ñîçäàíèå íå âîçìîæíî:
831 if gPlayers
[a
].FModel
= nil then
835 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], [ModelName
]));
839 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
840 if Random(2) = 0 then
844 gPlayers
[a
].FPreferredTeam
:= Team
;
846 case gGameSettings
.GameMode
of
847 GM_DM
: gPlayers
[a
].FTeam
:= TEAM_NONE
;
849 GM_CTF
: gPlayers
[a
].FTeam
:= gPlayers
[a
].FPreferredTeam
;
851 GM_COOP
: gPlayers
[a
].FTeam
:= TEAM_COOP
;
854 // Åñëè êîìàíäíàÿ èãðà - êðàñèì ìîäåëü â öâåò êîìàíäû:
855 gPlayers
[a
].FColor
:= Color
;
856 if gPlayers
[a
].FTeam
in [TEAM_RED
, TEAM_BLUE
] then
857 gPlayers
[a
].FModel
.Color
:= TEAMCOLOR
[gPlayers
[a
].FTeam
]
859 gPlayers
[a
].FModel
.Color
:= Color
;
861 gPlayers
[a
].FUID
:= g_CreateUID(UID_PLAYER
);
862 gPlayers
[a
].FAlive
:= False;
864 Result
:= gPlayers
[a
].FUID
;
867 function g_Player_CreateFromState (st
: TStream
): Word;
868 var a
: Integer; ok
, Bot
: Boolean; pos
: Int64;
872 // check signature and entity type
874 if not utils
.checkSign(st
, 'PLYR') then raise XStreamError
.Create('invalid player signature');
875 if (utils
.readByte(st
) <> PLR_SAVE_VERSION
) then raise XStreamError
.Create('invalid player version');
876 Bot
:= utils
.readBool(st
);
879 // find free player slot
881 for a
:= 0 to High(gPlayers
) do
882 if gPlayers
[a
] = nil then
888 // allocate player slot
891 SetLength(gPlayers
, Length(gPlayers
)+1);
895 // create entity and load state
897 gPlayers
[a
] := TBot
.Create()
899 gPlayers
[a
] := TPlayer
.Create();
900 gPlayers
[a
].FPhysics
:= True; // ???
901 gPlayers
[a
].LoadState(st
);
903 result
:= gPlayers
[a
].FUID
;
907 procedure g_Player_ResetTeams();
911 if g_Game_IsClient
then
913 if gPlayers
= nil then
915 for a
:= Low(gPlayers
) to High(gPlayers
) do
916 if gPlayers
[a
] <> nil then
917 case gGameSettings
.GameMode
of
919 gPlayers
[a
].ChangeTeam(TEAM_NONE
);
921 if not (gPlayers
[a
].Team
in [TEAM_RED
, TEAM_BLUE
]) then
922 if gPlayers
[a
].FPreferredTeam
in [TEAM_RED
, TEAM_BLUE
] then
923 gPlayers
[a
].ChangeTeam(gPlayers
[a
].FPreferredTeam
)
926 gPlayers
[a
].ChangeTeam(TEAM_RED
)
928 gPlayers
[a
].ChangeTeam(TEAM_BLUE
);
931 gPlayers
[a
].ChangeTeam(TEAM_COOP
);
935 procedure g_Bot_Add(Team
, Difficult
: Byte; Handicap
: Integer = 100);
938 _name
, _model
: String;
941 if not g_Game_IsServer
then Exit
;
943 // Ñïèñîê íàçâàíèé ìîäåëåé:
944 m
:= g_PlayerModel_GetNames();
949 if (gGameSettings
.GameType
= GT_SINGLE
) or (gGameSettings
.GameMode
= GM_COOP
) then
950 Team
:= TEAM_COOP
// COOP
952 if gGameSettings
.GameMode
= GM_DM
then
953 Team
:= TEAM_NONE
// DM
955 if Team
= TEAM_NONE
then // CTF / TDM
957 // Àâòîáàëàíñ êîìàíä:
961 for a
:= 0 to High(gPlayers
) do
962 if gPlayers
[a
] <> nil then
964 if gPlayers
[a
].Team
= TEAM_RED
then
967 if gPlayers
[a
].Team
= TEAM_BLUE
then
977 if Random(2) = 0 then
983 // Âûáèðàåì áîòó èìÿ:
985 if BotNames
<> nil then
986 for a
:= 0 to High(BotNames
) do
987 if g_Player_ValidName(BotNames
[a
]) then
989 _name
:= BotNames
[a
];
993 // Âûáèðàåì ñëó÷àéíóþ ìîäåëü:
994 _model
:= m
[Random(Length(m
))];
997 with g_Player_Get(g_Player_Create(_model
,
998 _RGB(Min(Random(9)*32, 255),
999 Min(Random(9)*32, 255),
1000 Min(Random(9)*32, 255)),
1001 Team
, True)) as TBot
do
1003 // Åñëè èìåíè íåò, äåëàåì åãî èç UID áîòà
1005 Name
:= Format('DFBOT%.5d', [UID
])
1010 1: FDifficult
:= DIFFICULT_EASY
;
1011 2: FDifficult
:= DIFFICULT_MEDIUM
;
1012 else FDifficult
:= DIFFICULT_HARD
;
1015 for a
:= WP_FIRST
to WP_LAST
do
1017 FDifficult
.WeaponPrior
[a
] := WEAPON_PRIOR1
[a
];
1018 FDifficult
.CloseWeaponPrior
[a
] := WEAPON_PRIOR2
[a
];
1019 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
1022 FHandicap
:= Handicap
;
1024 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [Name
]), True);
1026 if g_Game_IsNet
then MH_SEND_PlayerCreate(UID
);
1027 if g_Game_IsServer
and (gGameSettings
.MaxLives
> 0) then
1032 procedure g_Bot_AddList(Team
: Byte; lName
: ShortString; num
: Integer = -1; Handicap
: Integer = 100);
1035 _name
, _model
: String;
1038 if not g_Game_IsServer
then Exit
;
1040 // Ñïèñîê íàçâàíèé ìîäåëåé:
1041 m
:= g_PlayerModel_GetNames();
1046 if (gGameSettings
.GameType
= GT_SINGLE
) or (gGameSettings
.GameMode
= GM_COOP
) then
1047 Team
:= TEAM_COOP
// COOP
1049 if gGameSettings
.GameMode
= GM_DM
then
1050 Team
:= TEAM_NONE
// DM
1052 if Team
= TEAM_NONE
then
1053 Team
:= BotList
[num
].team
; // CTF / TDM
1055 // Âûáèðàåì íàñòðîéêè áîòà èç ñïèñêà ïî íîìåðó èëè èìåíè:
1056 lName
:= AnsiLowerCase(lName
);
1057 if (num
< 0) or (num
> Length(BotList
)-1) then
1059 if (num
= -1) and (lName
<> '') and (BotList
<> nil) then
1060 for a
:= 0 to High(BotList
) do
1061 if AnsiLowerCase(BotList
[a
].name
) = lName
then
1070 _name
:= BotList
[num
].name
;
1071 // Çàíÿòî - âûáèðàåì ñëó÷àéíîå:
1072 if not g_Player_ValidName(_name
) then
1074 _name
:= Format('DFBOT%.2d', [Random(100)]);
1075 until g_Player_ValidName(_name
);
1078 _model
:= BotList
[num
].model
;
1079 // Íåò òàêîé - âûáèðàåì ñëó÷àéíóþ:
1080 if not InSArray(_model
, m
) then
1081 _model
:= m
[Random(Length(m
))];
1084 with g_Player_Get(g_Player_Create(_model
, BotList
[num
].color
, Team
, True)) as TBot
do
1088 FDifficult
.DiagFire
:= BotList
[num
].diag_fire
;
1089 FDifficult
.InvisFire
:= BotList
[num
].invis_fire
;
1090 FDifficult
.DiagPrecision
:= BotList
[num
].diag_precision
;
1091 FDifficult
.FlyPrecision
:= BotList
[num
].fly_precision
;
1092 FDifficult
.Cover
:= BotList
[num
].cover
;
1093 FDifficult
.CloseJump
:= BotList
[num
].close_jump
;
1095 FHandicap
:= Handicap
;
1097 for a
:= WP_FIRST
to WP_LAST
do
1099 FDifficult
.WeaponPrior
[a
] := BotList
[num
].w_prior1
[a
];
1100 FDifficult
.CloseWeaponPrior
[a
] := BotList
[num
].w_prior2
[a
];
1101 //FDifficult.SafeWeaponPrior[a] := BotList[num].w_prior3[a];
1104 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [Name
]), True);
1106 if g_Game_IsNet
then MH_SEND_PlayerCreate(UID
);
1110 procedure g_Bot_RemoveAll();
1114 if not g_Game_IsServer
then Exit
;
1115 if gPlayers
= nil then Exit
;
1117 for a
:= 0 to High(gPlayers
) do
1118 if gPlayers
[a
] <> nil then
1119 if gPlayers
[a
] is TBot
then
1121 gPlayers
[a
].Lives
:= 0;
1122 gPlayers
[a
].Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
1123 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [gPlayers
[a
].Name
]), True);
1124 g_Player_Remove(gPlayers
[a
].FUID
);
1130 procedure g_Bot_MixNames();
1135 if BotNames
<> nil then
1136 for a
:= 0 to High(BotNames
) do
1138 b
:= Random(Length(BotNames
));
1140 Botnames
[a
] := BotNames
[b
];
1145 procedure g_Player_Remove(UID
: Word);
1149 if gPlayers
= nil then Exit
;
1151 if g_Game_IsServer
and g_Game_IsNet
then
1152 MH_SEND_PlayerDelete(UID
);
1154 for i
:= 0 to High(gPlayers
) do
1155 if gPlayers
[i
] <> nil then
1156 if gPlayers
[i
].FUID
= UID
then
1158 if gPlayers
[i
] is TPlayer
then
1159 TPlayer(gPlayers
[i
]).Free()
1161 TBot(gPlayers
[i
]).Free();
1167 procedure g_Player_Init();
1178 path
:= BOTNAMES_FILENAME
;
1179 if e_FindResource(DataDirs
, path
) = false then
1182 // ×èòàåì âîçìîæíûå èìåíà áîòîâ èç ôàéëà:
1183 AssignFile(F
, path
);
1194 SetLength(BotNames
, Length(BotNames
)+1);
1195 BotNames
[High(BotNames
)] := s
;
1203 // ×èòàåì ôàéë ñ ïàðàìåòðàìè áîòîâ:
1204 config
:= TConfig
.CreateFile(path
);
1208 while config
.SectionExists(IntToStr(a
)) do
1210 SetLength(BotList
, Length(BotList
)+1);
1212 with BotList
[High(BotList
)] do
1215 name
:= config
.ReadStr(IntToStr(a
), 'name', '');
1217 model
:= config
.ReadStr(IntToStr(a
), 'model', '');
1219 if config
.ReadStr(IntToStr(a
), 'team', 'red') = 'red' then
1224 sa
:= parse(config
.ReadStr(IntToStr(a
), 'color', ''));
1225 color
.R
:= StrToIntDef(sa
[0], 0);
1226 color
.G
:= StrToIntDef(sa
[1], 0);
1227 color
.B
:= StrToIntDef(sa
[2], 0);
1228 // Âåðîÿòíîñòü ñòðåëüáû ïîä óãëîì:
1229 diag_fire
:= config
.ReadInt(IntToStr(a
), 'diag_fire', 0);
1230 // Âåðîÿòíîñòü îòâåòíîãî îãíÿ ïî íåâèäèìîìó ñîïåðíèêó:
1231 invis_fire
:= config
.ReadInt(IntToStr(a
), 'invis_fire', 0);
1232 // Òî÷íîñòü ñòðåëüáû ïîä óãëîì:
1233 diag_precision
:= config
.ReadInt(IntToStr(a
), 'diag_precision', 0);
1234 // Òî÷íîñòü ñòðåëüáû â ïîëåòå:
1235 fly_precision
:= config
.ReadInt(IntToStr(a
), 'fly_precision', 0);
1236 // Òî÷íîñòü óêëîíåíèÿ îò ñíàðÿäîâ:
1237 cover
:= config
.ReadInt(IntToStr(a
), 'cover', 0);
1238 // Âåðîÿòíîñòü ïðûæêà ïðè ïðèáëèæåíèè ñîïåðíèêà:
1239 close_jump
:= config
.ReadInt(IntToStr(a
), 'close_jump', 0);
1240 // Ïðèîðèòåòû îðóæèÿ äëÿ äàëüíåãî áîÿ:
1241 sa
:= parse(config
.ReadStr(IntToStr(a
), 'w_prior1', ''));
1242 if Length(sa
) = 10 then
1244 w_prior1
[b
] := EnsureRange(StrToInt(sa
[b
]), 0, 9);
1245 // Ïðèîðèòåòû îðóæèÿ äëÿ áëèæíåãî áîÿ:
1246 sa
:= parse(config
.ReadStr(IntToStr(a
), 'w_prior2', ''));
1247 if Length(sa
) = 10 then
1249 w_prior2
[b
] := EnsureRange(StrToInt(sa
[b
]), 0, 9);
1251 {sa := parse(config.ReadStr(IntToStr(a), 'w_prior3', ''));
1252 if Length(sa) = 10 then
1254 w_prior3[b] := EnsureRange(StrToInt(sa[b]), 0, 9);}
1261 SetLength(SavedStates
, 0);
1264 procedure g_Player_Free();
1268 if gPlayers
<> nil then
1270 for i
:= 0 to High(gPlayers
) do
1271 if gPlayers
[i
] <> nil then
1273 if gPlayers
[i
] is TPlayer
then
1274 TPlayer(gPlayers
[i
]).Free()
1276 TBot(gPlayers
[i
]).Free();
1285 SetLength(SavedStates
, 0);
1288 procedure g_Player_PreUpdate();
1292 if gPlayers
= nil then Exit
;
1293 for i
:= 0 to High(gPlayers
) do
1294 if gPlayers
[i
] <> nil then
1295 gPlayers
[i
].PreUpdate();
1298 procedure g_Player_UpdateAll();
1302 if gPlayers
= nil then Exit
;
1304 //e_WriteLog('***g_Player_UpdateAll: ENTER', MSG_WARNING);
1305 for i
:= 0 to High(gPlayers
) do
1307 if gPlayers
[i
] <> nil then
1309 if gPlayers
[i
] is TPlayer
then
1311 gPlayers
[i
].Update();
1312 gPlayers
[i
].RealizeCurrentWeapon(); // WARNING! DO NOT MOVE THIS INTO `Update()`!
1316 // bot updates weapons in `UpdateCombat()`
1317 TBot(gPlayers
[i
]).Update();
1321 //e_WriteLog('***g_Player_UpdateAll: EXIT', MSG_WARNING);
1324 procedure g_Player_DrawAll();
1328 if gPlayers
= nil then Exit
;
1330 for i
:= 0 to High(gPlayers
) do
1331 if gPlayers
[i
] <> nil then
1332 if gPlayers
[i
] is TPlayer
then gPlayers
[i
].Draw()
1333 else TBot(gPlayers
[i
]).Draw();
1336 procedure g_Player_DrawDebug(p
: TPlayer
);
1340 if p
= nil then Exit
;
1341 if (@p
.FObj
) = nil then Exit
;
1343 e_TextureFontGetSize(gStdFont
, fW
, fH
);
1345 e_TextureFontPrint(0, 0 , 'Pos X: ' + IntToStr(p
.FObj
.X
), gStdFont
);
1346 e_TextureFontPrint(0, fH
, 'Pos Y: ' + IntToStr(p
.FObj
.Y
), gStdFont
);
1347 e_TextureFontPrint(0, fH
* 2, 'Vel X: ' + IntToStr(p
.FObj
.Vel
.X
), gStdFont
);
1348 e_TextureFontPrint(0, fH
* 3, 'Vel Y: ' + IntToStr(p
.FObj
.Vel
.Y
), gStdFont
);
1349 e_TextureFontPrint(0, fH
* 4, 'Acc X: ' + IntToStr(p
.FObj
.Accel
.X
), gStdFont
);
1350 e_TextureFontPrint(0, fH
* 5, 'Acc Y: ' + IntToStr(p
.FObj
.Accel
.Y
), gStdFont
);
1351 e_TextureFontPrint(0, fH
* 6, 'Old X: ' + IntToStr(p
.FObj
.oldX
), gStdFont
);
1352 e_TextureFontPrint(0, fH
* 7, 'Old Y: ' + IntToStr(p
.FObj
.oldY
), gStdFont
);
1355 procedure g_Player_DrawHealth();
1360 if gPlayers
= nil then Exit
;
1361 e_TextureFontGetSize(gStdFont
, fW
, fH
);
1363 for i
:= 0 to High(gPlayers
) do
1364 if gPlayers
[i
] <> nil then
1366 e_TextureFontPrint(gPlayers
[i
].FObj
.X
+ gPlayers
[i
].FObj
.Rect
.X
,
1367 gPlayers
[i
].FObj
.Y
+ gPlayers
[i
].FObj
.Rect
.Y
+ gPlayers
[i
].FObj
.Rect
.Height
- fH
* 2,
1368 IntToStr(gPlayers
[i
].FHealth
), gStdFont
);
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
,
1371 IntToStr(gPlayers
[i
].FArmor
), gStdFont
);
1375 function g_Player_Get(UID
: Word): TPlayer
;
1381 if gPlayers
= nil then
1384 for a
:= 0 to High(gPlayers
) do
1385 if gPlayers
[a
] <> nil then
1386 if gPlayers
[a
].FUID
= UID
then
1388 Result
:= gPlayers
[a
];
1393 function g_Player_GetCount(): Byte;
1399 if gPlayers
= nil then
1402 for a
:= 0 to High(gPlayers
) do
1403 if gPlayers
[a
] <> nil then
1404 Result
:= Result
+ 1;
1407 function g_Player_GetStats(): TPlayerStatArray
;
1413 if gPlayers
= nil then Exit
;
1415 for a
:= 0 to High(gPlayers
) do
1416 if gPlayers
[a
] <> nil then
1418 SetLength(Result
, Length(Result
)+1);
1419 with Result
[High(Result
)] do
1422 Ping
:= gPlayers
[a
].FPing
;
1423 Loss
:= gPlayers
[a
].FLoss
;
1424 Name
:= gPlayers
[a
].FName
;
1425 Team
:= gPlayers
[a
].FTeam
;
1426 Frags
:= gPlayers
[a
].FFrags
;
1427 Deaths
:= gPlayers
[a
].FDeath
;
1428 Kills
:= gPlayers
[a
].FKills
;
1429 Color
:= gPlayers
[a
].FModel
.Color
;
1430 Lives
:= gPlayers
[a
].FLives
;
1431 Spectator
:= gPlayers
[a
].FSpectator
;
1432 UID
:= gPlayers
[a
].FUID
;
1437 procedure g_Player_ResetReady();
1441 if not g_Game_IsServer
then Exit
;
1442 if gPlayers
= nil then Exit
;
1444 for a
:= 0 to High(gPlayers
) do
1445 if gPlayers
[a
] <> nil then
1447 gPlayers
[a
].FReady
:= False;
1448 if g_Game_IsNet
then
1449 MH_SEND_GameEvent(NET_EV_INTER_READY
, gPlayers
[a
].UID
, 'N');
1453 procedure g_Player_RememberAll
;
1457 for i
:= Low(gPlayers
) to High(gPlayers
) do
1458 if (gPlayers
[i
] <> nil) and gPlayers
[i
].alive
then
1459 gPlayers
[i
].RememberState
;
1462 procedure g_Player_ResetAll(Force
, Silent
: Boolean);
1466 gTeamStat
[TEAM_RED
].Goals
:= 0;
1467 gTeamStat
[TEAM_BLUE
].Goals
:= 0;
1469 if gPlayers
<> nil then
1470 for i
:= 0 to High(gPlayers
) do
1471 if gPlayers
[i
] <> nil then
1473 gPlayers
[i
].Reset(Force
);
1475 if gPlayers
[i
] is TPlayer
then
1477 if (not gPlayers
[i
].FSpectator
) or gPlayers
[i
].FWantsInGame
then
1478 gPlayers
[i
].Respawn(Silent
)
1480 gPlayers
[i
].Spectate();
1483 TBot(gPlayers
[i
]).Respawn(Silent
);
1487 function g_Player_CreateCorpse(Player
: TPlayer
): Integer;
1495 if Player
.alive
then
1498 // Ðàçðûâàåì ñâÿçü ñ ïðåæíèì òðóïîì:
1499 i
:= Player
.FCorpse
;
1500 if (i
>= 0) and (i
< Length(gCorpses
)) then
1502 if (gCorpses
[i
] <> nil) and (gCorpses
[i
].FPlayerUID
= Player
.FUID
) then
1503 gCorpses
[i
].FPlayerUID
:= 0;
1506 if Player
.FObj
.Y
>= gMapInfo
.Height
+128 then
1511 if (FHealth
>= -50) or (gGibsCount
= 0) then
1513 if (gCorpses
= nil) or (Length(gCorpses
) = 0) then
1517 for find_id
:= 0 to High(gCorpses
) do
1518 if gCorpses
[find_id
] = nil then
1525 find_id
:= Random(Length(gCorpses
));
1527 gCorpses
[find_id
] := TCorpse
.Create(FObj
.X
, FObj
.Y
, FModel
.Name
, FHealth
< -20);
1528 gCorpses
[find_id
].FColor
:= FModel
.Color
;
1529 gCorpses
[find_id
].FObj
.Vel
:= FObj
.Vel
;
1530 gCorpses
[find_id
].FObj
.Accel
:= FObj
.Accel
;
1531 gCorpses
[find_id
].FPlayerUID
:= FUID
;
1536 g_Player_CreateGibs(FObj
.X
+ PLAYER_RECT_CX
,
1537 FObj
.Y
+ PLAYER_RECT_CY
,
1538 FModel
.Name
, FModel
.Color
);
1542 procedure g_Player_CreateShell(fX
, fY
, dX
, dY
: Integer; T
: Byte);
1546 if (gShells
= nil) or (Length(gShells
) = 0) then
1549 with gShells
[CurrentShell
] do
1555 if T
= SHELL_BULLET
then
1557 if g_Texture_Get('TEXTURE_SHELL_BULLET', SID
) then
1561 Obj
.Rect
.Width
:= 4;
1562 Obj
.Rect
.Height
:= 2;
1566 if g_Texture_Get('TEXTURE_SHELL_SHELL', SID
) then
1570 Obj
.Rect
.Width
:= 7;
1571 Obj
.Rect
.Height
:= 3;
1577 g_Obj_Push(@Obj
, dX
+ Random(4)-Random(4), dY
-Random(4));
1578 positionChanged(); // this updates spatial accelerators
1579 RAngle
:= Random(360);
1580 Timeout
:= gTime
+ SHELL_TIMEOUT
;
1582 if CurrentShell
>= High(gShells
) then
1589 procedure g_Player_CreateGibs(fX
, fY
: Integer; ModelName
: string; fColor
: TRGB
);
1592 GibsArray
: TGibsArray
;
1595 if (gGibs
= nil) or (Length(gGibs
) = 0) then
1597 if not g_PlayerModel_GetGibs(ModelName
, GibsArray
) then
1599 Blood
:= g_PlayerModel_GetBlood(ModelName
);
1601 for a
:= 0 to High(GibsArray
) do
1602 with gGibs
[CurrentGib
] do
1605 ID
:= GibsArray
[a
].ID
;
1606 MaskID
:= GibsArray
[a
].MaskID
;
1609 Obj
.Rect
:= GibsArray
[a
].Rect
;
1610 Obj
.X
:= fX
-GibsArray
[a
].Rect
.X
-(GibsArray
[a
].Rect
.Width
div 2);
1611 Obj
.Y
:= fY
-GibsArray
[a
].Rect
.Y
-(GibsArray
[a
].Rect
.Height
div 2);
1612 g_Obj_PushA(@Obj
, 25 + Random(10), Random(361));
1613 positionChanged(); // this updates spatial accelerators
1614 RAngle
:= Random(360);
1616 if gBloodCount
> 0 then
1617 g_GFX_Blood(fX
, fY
, 16*gBloodCount
+Random(5*gBloodCount
), -16+Random(33), -16+Random(33),
1618 Random(48), Random(48), Blood
.R
, Blood
.G
, Blood
.B
, Blood
.Kind
);
1620 if CurrentGib
>= High(gGibs
) then
1627 procedure g_Player_UpdatePhysicalObjects();
1633 procedure ShellSound_Bounce(X
, Y
: Integer; T
: Byte);
1638 if T
= SHELL_BULLET
then
1639 g_Sound_PlayExAt('SOUND_PLAYER_CASING' + IntToStr(k
), X
, Y
)
1641 g_Sound_PlayExAt('SOUND_PLAYER_SHELL' + IntToStr(k
), X
, Y
);
1646 if gGibs
<> nil then
1647 for i
:= 0 to High(gGibs
) do
1648 if gGibs
[i
].alive
then
1655 mr
:= g_Obj_Move(@Obj
, True, False, True);
1656 positionChanged(); // this updates spatial accelerators
1658 if WordBool(mr
and MOVE_FALLOUT
) then
1664 // Îòëåòàåò îò óäàðà î ñòåíó/ïîòîëîê/ïîë:
1665 if WordBool(mr
and MOVE_HITWALL
) then
1666 Obj
.Vel
.X
:= -(vel
.X
div 2);
1667 if WordBool(mr
and (MOVE_HITCEIL
or MOVE_HITLAND
)) then
1668 Obj
.Vel
.Y
:= -(vel
.Y
div 2);
1670 if (Obj
.Vel
.X
>= 0) then
1672 RAngle
:= RAngle
+ Abs(Obj
.Vel
.X
)*6 + Abs(Obj
.Vel
.Y
);
1673 if RAngle
>= 360 then
1674 RAngle
:= RAngle
mod 360;
1675 end else begin // Counter-clockwise
1676 RAngle
:= RAngle
- Abs(Obj
.Vel
.X
)*6 - Abs(Obj
.Vel
.Y
);
1678 RAngle
:= (360 - (Abs(RAngle
) mod 360)) mod 360;
1681 // Ñîïðîòèâëåíèå âîçäóõà äëÿ êóñêà òðóïà:
1682 if gTime
mod (GAME_TICK
*3) = 0 then
1683 Obj
.Vel
.X
:= z_dec(Obj
.Vel
.X
, 1);
1687 if gCorpses
<> nil then
1688 for i
:= 0 to High(gCorpses
) do
1689 if gCorpses
[i
] <> nil then
1690 if gCorpses
[i
].State
= CORPSE_STATE_REMOVEME
then
1696 gCorpses
[i
].Update();
1699 if gShells
<> nil then
1700 for i
:= 0 to High(gShells
) do
1701 if gShells
[i
].alive
then
1708 mr
:= g_Obj_Move(@Obj
, True, False, True);
1709 positionChanged(); // this updates spatial accelerators
1711 if WordBool(mr
and MOVE_FALLOUT
) or (gShells
[i
].Timeout
< gTime
) then
1717 // Îòëåòàåò îò óäàðà î ñòåíó/ïîòîëîê/ïîë:
1718 if WordBool(mr
and MOVE_HITWALL
) then
1720 Obj
.Vel
.X
:= -(vel
.X
div 2);
1721 if not WordBool(mr
and MOVE_INWATER
) then
1722 ShellSound_Bounce(Obj
.X
, Obj
.Y
, SType
);
1724 if WordBool(mr
and (MOVE_HITCEIL
or MOVE_HITLAND
)) then
1726 Obj
.Vel
.Y
:= -(vel
.Y
div 2);
1727 if Obj
.Vel
.X
<> 0 then Obj
.Vel
.X
:= Obj
.Vel
.X
div 2;
1728 if (Obj
.Vel
.X
= 0) and (Obj
.Vel
.Y
= 0) then
1730 if RAngle
mod 90 <> 0 then
1731 RAngle
:= (RAngle
div 90) * 90;
1733 else if not WordBool(mr
and MOVE_INWATER
) then
1734 ShellSound_Bounce(Obj
.X
, Obj
.Y
, SType
);
1737 if (Obj
.Vel
.X
>= 0) then
1739 RAngle
:= RAngle
+ Abs(Obj
.Vel
.X
)*8 + Abs(Obj
.Vel
.Y
);
1740 if RAngle
>= 360 then
1741 RAngle
:= RAngle
mod 360;
1742 end else begin // Counter-clockwise
1743 RAngle
:= RAngle
- Abs(Obj
.Vel
.X
)*8 - Abs(Obj
.Vel
.Y
);
1745 RAngle
:= (360 - (Abs(RAngle
) mod 360)) mod 360;
1751 procedure TGib
.getMapBox (out x
, y
, w
, h
: Integer); inline;
1753 x
:= Obj
.X
+Obj
.Rect
.X
;
1754 y
:= Obj
.Y
+Obj
.Rect
.Y
;
1755 w
:= Obj
.Rect
.Width
;
1756 h
:= Obj
.Rect
.Height
;
1759 procedure TGib
.moveBy (dx
, dy
: Integer); inline;
1761 if (dx
<> 0) or (dy
<> 0) then
1770 procedure TShell
.getMapBox (out x
, y
, w
, h
: Integer); inline;
1774 w
:= Obj
.Rect
.Width
;
1775 h
:= Obj
.Rect
.Height
;
1778 procedure TShell
.moveBy (dx
, dy
: Integer); inline;
1780 if (dx
<> 0) or (dy
<> 0) then
1789 procedure TGib
.positionChanged (); inline; begin end;
1790 procedure TShell
.positionChanged (); inline; begin end;
1793 procedure g_Player_DrawCorpses();
1798 if gGibs
<> nil then
1799 for i
:= 0 to High(gGibs
) do
1800 if gGibs
[i
].alive
then
1803 if not g_Obj_Collide(sX
, sY
, sWidth
, sHeight
, @Obj
) then
1806 Obj
.lerp(gLerpFactor
, fX
, fY
);
1808 a
.X
:= Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2);
1809 a
.y
:= Obj
.Rect
.Y
+(Obj
.Rect
.Height
div 2);
1811 e_DrawAdv(ID
, fX
, fY
, 0, True, False, RAngle
, @a
, TMirrorType
.None
);
1814 e_DrawAdv(MaskID
, fX
, fY
, 0, True, False, RAngle
, @a
, TMirrorType
.None
);
1820 if gCorpses
<> nil then
1821 for i
:= 0 to High(gCorpses
) do
1822 if gCorpses
[i
] <> nil then
1826 procedure g_Player_DrawShells();
1831 if gShells
<> nil then
1832 for i
:= 0 to High(gShells
) do
1833 if gShells
[i
].alive
then
1836 if not g_Obj_Collide(sX
, sY
, sWidth
, sHeight
, @Obj
) then
1839 Obj
.lerp(gLerpFactor
, fX
, fY
);
1844 e_DrawAdv(SpriteID
, fX
, fY
, 0, True, False, RAngle
, @a
, TMirrorType
.None
);
1848 procedure g_Player_RemoveAllCorpses();
1854 SetLength(gGibs
, MaxGibs
);
1855 SetLength(gShells
, MaxGibs
);
1859 if gCorpses
<> nil then
1860 for i
:= 0 to High(gCorpses
) do
1864 SetLength(gCorpses
, MaxCorpses
);
1867 procedure g_Player_Corpses_SaveState (st
: TStream
);
1871 // Ñ÷èòàåì êîëè÷åñòâî ñóùåñòâóþùèõ òðóïîâ
1873 for i
:= 0 to High(gCorpses
) do if (gCorpses
[i
] <> nil) then Inc(count
);
1875 // Êîëè÷åñòâî òðóïîâ
1876 utils
.writeInt(st
, LongInt(count
));
1878 if (count
= 0) then exit
;
1881 for i
:= 0 to High(gCorpses
) do
1883 if gCorpses
[i
] <> nil then
1886 utils
.writeStr(st
, gCorpses
[i
].FModelName
);
1888 utils
.writeBool(st
, gCorpses
[i
].Mess
);
1889 // Ñîõðàíÿåì äàííûå òðóïà:
1890 gCorpses
[i
].SaveState(st
);
1896 procedure g_Player_Corpses_LoadState (st
: TStream
);
1904 g_Player_RemoveAllCorpses();
1906 // Êîëè÷åñòâî òðóïîâ:
1907 count
:= utils
.readLongInt(st
);
1908 if (count
< 0) or (count
> Length(gCorpses
)) then raise XStreamError
.Create('invalid number of corpses');
1910 if (count
= 0) then exit
;
1913 for i
:= 0 to count
-1 do
1916 str
:= utils
.readStr(st
);
1918 b
:= utils
.readBool(st
);
1920 gCorpses
[i
] := TCorpse
.Create(0, 0, str
, b
);
1921 // Çàãðóæàåì äàííûå òðóïà
1922 gCorpses
[i
].LoadState(st
);
1929 function TPlayer
.isValidViewPort (): Boolean; inline; begin result
:= (viewPortW
> 0) and (viewPortH
> 0); end;
1931 procedure TPlayer
.BFGHit();
1933 g_Weapon_BFGHit(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
1934 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2));
1935 if g_Game_IsServer
and g_Game_IsNet
then
1936 MH_SEND_Effect(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
1937 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2),
1941 procedure TPlayer
.ChangeModel(ModelName
: string);
1943 locModel
: TPlayerModel
;
1945 locModel
:= g_PlayerModel_Get(ModelName
);
1946 if locModel
= nil then Exit
;
1952 procedure TPlayer
.SetModel(ModelName
: string);
1956 m
:= g_PlayerModel_Get(ModelName
);
1959 g_SimpleError(Format(_lc
[I_GAME_ERROR_MODEL_FALLBACK
], [ModelName
]));
1960 m
:= g_PlayerModel_Get('doomer');
1963 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], ['doomer']));
1968 if FModel
<> nil then
1973 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
1974 FModel
.Color
:= FColor
1976 FModel
.Color
:= TEAMCOLOR
[FTeam
];
1977 FModel
.SetWeapon(FCurrWeap
);
1978 FModel
.SetFlag(FFlag
);
1979 SetDirection(FDirection
);
1982 procedure TPlayer
.SetColor(Color
: TRGB
);
1985 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
1986 if FModel
<> nil then FModel
.Color
:= Color
;
1991 function TPlayer
.GetColor(): TRGB
;
1993 result
:= FModel
.Color
;
1996 procedure TPlayer
.SetWeaponPrefs(Prefs
: Array of Byte);
1999 for i
:= WP_FIRST
to WP_LAST
+ 1 do
2001 if (Prefs
[i
] < 0) or (Prefs
[i
] > WP_LAST
+ 1) then
2002 FWeapPreferences
[i
] := 0
2003 else FWeapPreferences
[i
] := Prefs
[i
];
2007 procedure TPlayer
.SetWeaponPref(Weapon
, Pref
: Byte);
2009 if (Weapon
< 0) or (Weapon
> WP_LAST
+ 1) then
2011 else if (Pref
>= 0) and (Pref
<= WP_LAST
+ 1) and (Weapon
>= 0) and (Weapon
<= WP_LAST
+ 1) then
2012 FWeapPreferences
[Weapon
] := Pref
2013 else if (Weapon
>= 0) and (Weapon
<= WP_LAST
+ 1) and ((Pref
< 0) or (Pref
> WP_LAST
+ 1)) then
2014 FWeapPreferences
[Weapon
] := 0;
2017 function TPlayer
.GetWeaponPref(Weapon
: Byte) : Byte;
2019 if (Weapon
< 0) or (Weapon
> WP_LAST
+ 1) then
2021 else if (FWeapPreferences
[Weapon
] < 0) or (FWeapPreferences
[Weapon
] > WP_LAST
+ 1) then
2024 result
:= FWeapPreferences
[Weapon
];
2027 function TPlayer
.GetMorePrefered() : Byte;
2028 var testedWeap
, i
: Byte;
2030 testedWeap
:= FCurrWeap
;
2031 for i
:= WP_FIRST
to WP_LAST
do
2032 if FWeapon
[i
] and (FWeapPreferences
[i
] > FWeapPreferences
[testedWeap
]) then
2034 if (R_BERSERK
in FRulez
) and (FWeapPreferences
[WP_LAST
+ 1] > FWeapPreferences
[testedWeap
]) then
2035 testedWeap
:= WEAPON_KASTET
;
2036 result
:= testedWeap
;
2039 procedure TPlayer
.SwitchTeam
;
2041 if g_Game_IsClient
then
2043 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then Exit
;
2045 if gGameOn
and FAlive
then
2046 Kill(K_SIMPLEKILL
, FUID
, HIT_SELF
);
2048 if FTeam
= TEAM_RED
then
2050 ChangeTeam(TEAM_BLUE
);
2051 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_BLUE
], [FName
]), True);
2052 if g_Game_IsNet
then
2053 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM
, TEAM_BLUE
, FName
);
2057 ChangeTeam(TEAM_RED
);
2058 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_RED
], [FName
]), True);
2059 if g_Game_IsNet
then
2060 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM
, TEAM_RED
, FName
);
2062 FPreferredTeam
:= FTeam
;
2065 procedure TPlayer
.ChangeTeam(Team
: Byte);
2072 TEAM_RED
, TEAM_BLUE
:
2073 FModel
.Color
:= TEAMCOLOR
[Team
];
2075 FModel
.Color
:= FColor
;
2077 if (FTeam
<> OldTeam
) and g_Game_IsNet
and g_Game_IsServer
then
2078 MH_SEND_PlayerStats(FUID
);
2082 procedure TPlayer.CollideItem();
2087 if gItems = nil then Exit;
2088 if not FAlive then Exit;
2090 for i := 0 to High(gItems) do
2093 if (ItemType <> ITEM_NONE) and alive then
2094 if g_Obj_Collide(FObj.X+PLAYER_RECT.X, FObj.Y+PLAYER_RECT.Y, PLAYER_RECT.Width,
2095 PLAYER_RECT.Height, @Obj) then
2097 if not PickItem(ItemType, gItems[i].Respawnable, r) then Continue;
2099 if ItemType in [ITEM_SPHERE_BLUE, ITEM_SPHERE_WHITE, ITEM_INVUL] then
2100 g_Sound_PlayExAt('SOUND_ITEM_GETRULEZ', FObj.X, FObj.Y)
2101 else if ItemType in [ITEM_MEDKIT_SMALL, ITEM_MEDKIT_LARGE, ITEM_MEDKIT_BLACK] then
2102 g_Sound_PlayExAt('SOUND_ITEM_GETMED', FObj.X, FObj.Y)
2103 else g_Sound_PlayExAt('SOUND_ITEM_GETITEM', FObj.X, FObj.Y);
2105 // Íàäî óáðàòü ñ êàðòû, åñëè ýòî íå êëþ÷, êîòîðûì íóæíî ïîäåëèòñÿ ñ äðóãèì èãðîêîì:
2106 if r and not ((ItemType in [ITEM_KEY_RED, ITEM_KEY_GREEN, ITEM_KEY_BLUE]) and
2107 (gGameSettings.GameType = GT_SINGLE) and
2108 (g_Player_GetCount() > 1)) then
2109 if not Respawnable then g_Items_Remove(i) else g_Items_Pick(i);
2115 function TPlayer
.CollideLevel(XInc
, YInc
: Integer): Boolean;
2117 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
2118 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_WALL
,
2122 constructor TPlayer
.Create();
2128 mEDamageType
:= HIT_SOME
;
2134 FSawSound
:= TPlayableSound
.Create();
2135 FSawSoundIdle
:= TPlayableSound
.Create();
2136 FSawSoundHit
:= TPlayableSound
.Create();
2137 FSawSoundSelect
:= TPlayableSound
.Create();
2138 FFlameSoundOn
:= TPlayableSound
.Create();
2139 FFlameSoundOff
:= TPlayableSound
.Create();
2140 FFlameSoundWork
:= TPlayableSound
.Create();
2141 FJetSoundFly
:= TPlayableSound
.Create();
2142 FJetSoundOn
:= TPlayableSound
.Create();
2143 FJetSoundOff
:= TPlayableSound
.Create();
2145 FSawSound
.SetByName('SOUND_WEAPON_FIRESAW');
2146 FSawSoundIdle
.SetByName('SOUND_WEAPON_IDLESAW');
2147 FSawSoundHit
.SetByName('SOUND_WEAPON_HITSAW');
2148 FSawSoundSelect
.SetByName('SOUND_WEAPON_SELECTSAW');
2149 FFlameSoundOn
.SetByName('SOUND_WEAPON_FLAMEON');
2150 FFlameSoundOff
.SetByName('SOUND_WEAPON_FLAMEOFF');
2151 FFlameSoundWork
.SetByName('SOUND_WEAPON_FLAMEWORK');
2152 FJetSoundFly
.SetByName('SOUND_PLAYER_JETFLY');
2153 FJetSoundOn
.SetByName('SOUND_PLAYER_JETON');
2154 FJetSoundOff
.SetByName('SOUND_PLAYER_JETOFF');
2156 FSpectatePlayer
:= -1;
2160 FSavedStateNum
:= -1;
2168 FActualModelName
:= 'doomer';
2171 FObj
.Rect
:= PLAYER_RECT
;
2173 FBFGFireCounter
:= -1;
2174 FJustTeleported
:= False;
2177 FWaitForFirstSpawn
:= false;
2182 procedure TPlayer
.positionChanged (); inline;
2186 procedure TPlayer
.doDamage (v
: Integer);
2188 if (v
<= 0) then exit
;
2189 if (v
> 32767) then v
:= 32767;
2190 Damage(v
, 0, 0, 0, mEDamageType
);
2193 procedure TPlayer
.Damage(value
: Word; SpawnerUID
: Word; vx
, vy
: Integer; t
: Byte);
2197 if (not g_Game_IsClient
) and (not FAlive
) then
2202 // Íåóÿçâèìîñòü íå ñïàñàåò îò ëîâóøåê:
2203 if ((t
= HIT_TRAP
) or (t
= HIT_SELF
)) and (not FGodMode
) then
2205 if not g_Game_IsClient
then
2208 if t
= HIT_TRAP
then
2210 // Ëîâóøêà óáèâàåò ñðàçó:
2212 Kill(K_EXTRAHARDKILL
, SpawnerUID
, t
);
2214 if t
= HIT_SELF
then
2218 Kill(K_SIMPLEKILL
, SpawnerUID
, t
);
2221 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
2222 FMegaRulez
[MR_SUIT
] := 0;
2223 FMegaRulez
[MR_INVUL
] := 0;
2224 FMegaRulez
[MR_INVIS
] := 0;
2229 // Íî îò îñòàëüíîãî ñïàñàåò:
2230 if FMegaRulez
[MR_INVUL
] >= gTime
then
2237 // Åñëè åñòü óðîí ñâîèì, èëè ðàíèë ñàì ñåáÿ, èëè òåáÿ ðàíèë ïðîòèâíèê:
2238 if LongBool(gGameSettings
.Options
and GAME_OPTION_TEAMDAMAGE
) or
2239 (SpawnerUID
= FUID
) or
2240 (not SameTeam(FUID
, SpawnerUID
)) then
2242 FLastSpawnerUID
:= SpawnerUID
;
2244 // Êðîâü (ïóçûðüêè, åñëè â âîäå):
2245 if gBloodCount
> 0 then
2247 c
:= Min(value
, 200)*gBloodCount
+ Random(Min(value
, 200) div 2);
2248 if value
div 4 <= c
then
2249 c
:= c
- (value
div 4)
2253 if (t
= HIT_SOME
) and (vx
= 0) and (vy
= 0) then
2257 HIT_TRAP
, HIT_ACID
, HIT_FLAME
, HIT_SELF
: MakeBloodSimple(c
);
2258 HIT_BFG
, HIT_ROCKET
, HIT_SOME
: MakeBloodVector(c
, vx
, vy
);
2261 if t
= HIT_WATER
then
2262 g_GFX_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
2263 FObj
.Y
+PLAYER_RECT
.Y
-4, value
div 2, 8, 4);
2268 Inc(FDamageBuffer
, value
);
2272 FPain
:= FPain
+ value
;
2275 if g_Game_IsServer
and g_Game_IsNet
then
2277 MH_SEND_PlayerDamage(FUID
, t
, SpawnerUID
, value
, vx
, vy
);
2278 MH_SEND_PlayerStats(FUID
);
2279 MH_SEND_PlayerPos(False, FUID
);
2283 function TPlayer
.Heal(value
: Word; Soft
: Boolean): Boolean;
2286 if g_Game_IsClient
then
2291 if Soft
and (FHealth
< PLAYER_HP_SOFT
) then
2293 IncMax(FHealth
, value
, PLAYER_HP_SOFT
);
2296 if (not Soft
) and (FHealth
< PLAYER_HP_LIMIT
) then
2298 IncMax(FHealth
, value
, PLAYER_HP_LIMIT
);
2302 if Result
and g_Game_IsServer
and g_Game_IsNet
then
2303 MH_SEND_PlayerStats(FUID
);
2306 destructor TPlayer
.Destroy();
2308 if (gPlayer1
<> nil) and (gPlayer1
.FUID
= FUID
) then
2310 if (gPlayer2
<> nil) and (gPlayer2
.FUID
= FUID
) then
2314 FSawSoundIdle
.Free();
2315 FSawSoundHit
.Free();
2316 FSawSoundSelect
.Free();
2317 FFlameSoundOn
.Free();
2318 FFlameSoundOff
.Free();
2319 FFlameSoundWork
.Free();
2320 FJetSoundFly
.Free();
2322 FJetSoundOff
.Free();
2324 if FPunchAnim
<> nil then
2330 procedure TPlayer
.DrawIndicator(Color
: TRGB
);
2332 indX
, indY
, fX
, fY
, fSlope
: Integer;
2342 FObj
.lerp(gLerpFactor
, fX
, fY
);
2343 fSlope
:= nlerp(FSlopeOld
, FObj
.slopeUpLeft
, gLerpFactor
);
2345 case gPlayerIndicatorStyle
of
2348 if g_Texture_Get('TEXTURE_PLAYER_INDICATOR', ID
) then
2350 e_GetTextureSize(ID
, @indW
, @indH
);
2354 if (FObj
.X
+ FObj
.Rect
.X
) < 0 then
2357 indX
:= fX
+ FObj
.Rect
.X
+ FObj
.Rect
.Width
;
2358 indY
:= fY
+ FObj
.Rect
.Y
+ (FObj
.Rect
.Height
- indW
) div 2;
2361 else if (FObj
.X
+ FObj
.Rect
.X
+ FObj
.Rect
.Width
) > Max(gMapInfo
.Width
, gPlayerScreenSize
.X
) then
2364 indX
:= fX
+ FObj
.Rect
.X
- indH
;
2365 indY
:= fY
+ FObj
.Rect
.Y
+ (FObj
.Rect
.Height
- indW
) div 2;
2368 else if (FObj
.Y
- indH
) < 0 then
2371 indX
:= fX
+ FObj
.Rect
.X
+ (FObj
.Rect
.Width
- indW
) div 2;
2372 indY
:= fY
+ FObj
.Rect
.Y
+ FObj
.Rect
.Height
;
2378 indX
:= fX
+ FObj
.Rect
.X
+ (FObj
.Rect
.Width
- indW
) div 2;
2382 indY
:= indY
+ fSlope
;
2383 indX
:= EnsureRange(indX
, 0, Max(gMapInfo
.Width
, gPlayerScreenSize
.X
) - indW
);
2384 indY
:= EnsureRange(indY
, 0, Max(gMapInfo
.Height
, gPlayerScreenSize
.Y
) - indH
);
2388 e_DrawAdv(ID
, indX
, indY
, 0, True, False, indA
, @a
);
2395 e_TextureFontGetSize(gStdFont
, nW
, nH
);
2396 indX
:= fX
+ FObj
.Rect
.X
+ (FObj
.Rect
.Width
- Length(FName
) * nW
) div 2;
2397 indY
:= fY
- nH
+ fSlope
;
2398 e_TextureFontPrintEx(indX
, indY
, FName
, gStdFont
, Color
.R
, Color
.G
, Color
.B
, 1.0, True);
2404 procedure TPlayer
.DrawBubble();
2406 bubX
, bubY
, fX
, fY
: Integer;
2409 Rw
, Gw
, Bw
: SmallInt;
2413 CObj
:= getCameraObj();
2414 CObj
.lerp(gLerpFactor
, fX
, fY
);
2415 // NB: _F_Obj.Rect is used to keep the bubble higher; this is not a mistake
2416 bubX
:= fX
+FObj
.Rect
.X
+ IfThen(FDirection
= TDirection
.D_LEFT
, -4, 18);
2417 bubY
:= fY
+FObj
.Rect
.Y
- 18;
2425 1: // simple textual non-bubble
2427 bubX
:= fX
+FObj
.Rect
.X
- 11;
2428 bubY
:= fY
+FObj
.Rect
.Y
- 17;
2429 e_TextureFontPrint(bubX
, bubY
, '[...]', gStdFont
);
2432 2: // advanced pixel-perfect bubble
2434 if FTeam
= TEAM_RED
then
2437 if FTeam
= TEAM_BLUE
then
2440 3: // colored bubble
2442 Rb
:= FModel
.Color
.R
;
2443 Gb
:= FModel
.Color
.G
;
2444 Bb
:= FModel
.Color
.B
;
2445 Rw
:= Min(Rb
* 2 + 64, 255);
2446 Gw
:= Min(Gb
* 2 + 64, 255);
2447 Bw
:= Min(Bb
* 2 + 64, 255);
2448 if (Abs(Rw
- Rb
) < 32)
2449 or (Abs(Gw
- Gb
) < 32)
2450 or (Abs(Bw
- Bb
) < 32) then
2452 Rb
:= Max(Rw
div 2 - 16, 0);
2453 Gb
:= Max(Gw
div 2 - 16, 0);
2454 Bb
:= Max(Bw
div 2 - 16, 0);
2457 4: // custom textured bubble
2459 if g_Texture_Get('TEXTURE_PLAYER_TALKBUBBLE', ID
) then
2460 if FDirection
= TDirection
.D_RIGHT
then
2461 e_Draw(ID
, bubX
- 6, bubY
- 7, 0, True, False)
2463 e_Draw(ID
, bubX
- 6, bubY
- 7, 0, True, False, TMirrorType
.Horizontal
);
2469 e_DrawQuad(bubX
+ 1, bubY
, bubX
+ 18, bubY
+ 13, Rb
, Gb
, Bb
);
2470 e_DrawQuad(bubX
, bubY
+ 1, bubX
+ 19, bubY
+ 12, Rb
, Gb
, Bb
);
2472 e_DrawFillQuad(bubX
+ 1, bubY
+ 1, bubX
+ 18, bubY
+ 12, Rw
, Gw
, Bw
, 0);
2475 Dot
:= IfThen(FDirection
= TDirection
.D_LEFT
, 14, 5);
2476 e_DrawLine(1, bubX
+ Dot
, bubY
+ 14, bubX
+ Dot
, bubY
+ 16, Rb
, Gb
, Bb
);
2477 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
);
2478 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
);
2479 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
);
2480 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
);
2484 e_DrawFillQuad(bubX
+ Dot
, bubY
+ 8, bubX
+ Dot
+ 1, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2485 e_DrawFillQuad(bubX
+ Dot
+ 3, bubY
+ 8, bubX
+ Dot
+ 4, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2486 e_DrawFillQuad(bubX
+ Dot
+ 6, bubY
+ 8, bubX
+ Dot
+ 7, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2489 procedure TPlayer
.Draw();
2494 Mirror
: TMirrorType
;
2495 fX
, fY
, fSlope
: Integer;
2497 FObj
.lerp(gLerpFactor
, fX
, fY
);
2498 fSlope
:= nlerp(FSlopeOld
, FObj
.slopeUpLeft
, gLerpFactor
);
2502 if Direction
= TDirection
.D_RIGHT
then
2503 Mirror
:= TMirrorType
.None
2505 Mirror
:= TMirrorType
.Horizontal
;
2507 if FPunchAnim
<> nil then
2509 FPunchAnim
.Draw(fX
+IfThen(Direction
= TDirection
.D_LEFT
, 15-FObj
.Rect
.X
, FObj
.Rect
.X
-15),
2510 fY
+fSlope
+FObj
.Rect
.Y
-11, Mirror
);
2511 if FPunchAnim
.played
then
2518 if (FMegaRulez
[MR_INVUL
] > gTime
) and ((gPlayerDrawn
<> Self
) or (FSpawnInvul
>= gTime
)) then
2519 if g_Texture_Get('TEXTURE_PLAYER_INVULPENTA', ID
) then
2521 e_GetTextureSize(ID
, @w
, @h
);
2522 if FDirection
= TDirection
.D_LEFT
then
2523 e_Draw(ID
, fX
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2)-(w
div 2)+4,
2524 fY
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2)-(h
div 2)-7+fSlope
, 0, True, False)
2526 e_Draw(ID
, fX
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2)-(w
div 2)-2,
2527 fY
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2)-(h
div 2)-7+fSlope
, 0, True, False);
2530 if FMegaRulez
[MR_INVIS
] > gTime
then
2532 if (gPlayerDrawn
<> nil) and ((Self
= gPlayerDrawn
) or
2533 ((FTeam
= gPlayerDrawn
.Team
) and (gGameSettings
.GameMode
<> GM_DM
))) then
2535 if (FMegaRulez
[MR_INVIS
] - gTime
) <= 2100 then
2536 dr
:= not Odd((FMegaRulez
[MR_INVIS
] - gTime
) div 300)
2540 FModel
.Draw(fX
, fY
+fSlope
, 200)
2542 FModel
.Draw(fX
, fY
+fSlope
);
2545 FModel
.Draw(fX
, fY
+fSlope
, 254);
2548 FModel
.Draw(fX
, fY
+fSlope
);
2551 if g_debug_Frames
then
2553 e_DrawQuad(FObj
.X
+FObj
.Rect
.X
,
2555 FObj
.X
+FObj
.Rect
.X
+FObj
.Rect
.Width
-1,
2556 FObj
.Y
+FObj
.Rect
.Y
+FObj
.Rect
.Height
-1,
2560 if (gChatBubble
> 0) and (FKeys
[KEY_CHAT
].Pressed
) and not FGhost
then
2561 if (FMegaRulez
[MR_INVIS
] <= gTime
) or ((gPlayerDrawn
<> nil) and ((Self
= gPlayerDrawn
) or
2562 ((FTeam
= gPlayerDrawn
.Team
) and (gGameSettings
.GameMode
<> GM_DM
)))) then
2564 // e_DrawPoint(5, 335, 288, 255, 0, 0); // DL, UR, DL, UR
2565 if gAimLine
and alive
and
2566 ((Self
= gPlayer1
) or (Self
= gPlayer2
)) then
2571 procedure TPlayer
.DrawAim();
2572 procedure drawCast (sz
: Integer; ax0
, ay0
, ax1
, ay1
: Integer);
2577 {$IFDEF ENABLE_HOLMES}
2578 if isValidViewPort
and (self
= gPlayer1
) then
2580 g_Holmes_plrLaser(ax0
, ay0
, ax1
, ay1
);
2584 e_DrawLine(sz
, ax0
, ay0
, ax1
, ay1
, 255, 0, 0, 96);
2585 if (g_Map_traceToNearestWall(ax0
, ay0
, ax1
, ay1
, @ex
, @ey
) <> nil) then
2587 e_DrawLine(sz
, ax0
, ay0
, ex
, ey
, 0, 255, 0, 96);
2591 e_DrawLine(sz
, ax0
, ay0
, ex
, ey
, 0, 0, 255, 96);
2596 wx
, wy
, xx
, yy
: Integer;
2600 wx
:= FObj
.X
+ WEAPONPOINT
[FDirection
].X
+ IfThen(FDirection
= TDirection
.D_LEFT
, 7, -7);
2601 wy
:= FObj
.Y
+ WEAPONPOINT
[FDirection
].Y
;
2610 1: begin // Chainsaw
2617 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2618 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2619 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2620 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2625 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2626 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2627 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2628 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2630 4: begin // Double Shotgun
2633 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2634 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2635 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2636 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2638 5: begin // Chaingun
2641 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2642 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2643 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2644 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2646 6: begin // Rocket Launcher
2649 if angle
= ANGLE_RIGHTUP
then Inc(angle
, 2);
2650 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2651 if angle
= ANGLE_LEFTUP
then Dec(angle
, 2);
2652 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2654 7: begin // Plasmagun
2657 if angle
= ANGLE_RIGHTUP
then Inc(angle
);
2658 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 3);
2659 if angle
= ANGLE_LEFTUP
then Dec(angle
);
2660 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 3);
2665 if angle
= ANGLE_RIGHTUP
then Inc(angle
, 1);
2666 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 2);
2667 if angle
= ANGLE_LEFTUP
then Dec(angle
, 1);
2668 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 2);
2670 9: begin // Super Chaingun
2673 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2674 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2675 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2676 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2679 xx
:= Trunc(Cos(-DegToRad(angle
)) * len
) + wx
;
2680 yy
:= Trunc(Sin(-DegToRad(angle
)) * len
) + wy
;
2681 {$IF DEFINED(D2F_DEBUG)}
2682 drawCast(sz
, wx
, wy
, xx
, yy
);
2684 e_DrawLine(sz
, wx
, wy
, xx
, yy
, 255, 0, 0, 96);
2688 procedure TPlayer
.DrawGUI();
2691 X
, Y
, SY
, a
, p
, m
: Integer;
2695 stat
: TPlayerStatArray
;
2697 X
:= gPlayerScreenSize
.X
;
2698 SY
:= gPlayerScreenSize
.Y
;
2701 if gShowGoals
and (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
2703 if gGameSettings
.GameMode
= GM_CTF
then
2707 if gGameSettings
.GameMode
= GM_CTF
then
2709 s
:= 'TEXTURE_PLAYER_REDFLAG';
2710 if gFlags
[FLAG_RED
].State
= FLAG_STATE_CAPTURED
then
2711 s
:= 'TEXTURE_PLAYER_REDFLAG_S';
2712 if gFlags
[FLAG_RED
].State
= FLAG_STATE_DROPPED
then
2713 s
:= 'TEXTURE_PLAYER_REDFLAG_D';
2714 if g_Texture_Get(s
, ID
) then
2715 e_Draw(ID
, X
-16-32, 240-72-4, 0, True, False);
2718 s
:= IntToStr(gTeamStat
[TEAM_RED
].Goals
);
2719 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2720 e_CharFont_PrintEx(gMenuFont
, X
-16-a
-tw
, 240-72-4, s
, TEAMCOLOR
[TEAM_RED
]);
2722 if gGameSettings
.GameMode
= GM_CTF
then
2724 s
:= 'TEXTURE_PLAYER_BLUEFLAG';
2725 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_CAPTURED
then
2726 s
:= 'TEXTURE_PLAYER_BLUEFLAG_S';
2727 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_DROPPED
then
2728 s
:= 'TEXTURE_PLAYER_BLUEFLAG_D';
2729 if g_Texture_Get(s
, ID
) then
2730 e_Draw(ID
, X
-16-32, 240-32-4, 0, True, False);
2733 s
:= IntToStr(gTeamStat
[TEAM_BLUE
].Goals
);
2734 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2735 e_CharFont_PrintEx(gMenuFont
, X
-16-a
-tw
, 240-32-4, s
, TEAMCOLOR
[TEAM_BLUE
]);
2738 if g_Texture_Get('TEXTURE_PLAYER_HUDBG', ID
) then
2739 e_DrawFill(ID
, X
, 0, 1, (gPlayerScreenSize
.Y
div 256)+IfThen(gPlayerScreenSize
.Y
mod 256 > 0, 1, 0),
2742 if g_Texture_Get('TEXTURE_PLAYER_HUD', ID
) then
2743 e_Draw(ID
, X
+2, Y
, 0, True, False);
2745 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
2749 s
:= IntToStr(Frags
);
2750 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2751 e_CharFont_PrintEx(gMenuFont
, X
-16-tw
, Y
, s
, _RGB(255, 0, 0));
2756 stat
:= g_Player_GetStats();
2761 for a
:= 0 to High(stat
) do
2762 if stat
[a
].Name
<> Name
then
2764 if stat
[a
].Frags
> m
then m
:= stat
[a
].Frags
;
2765 if stat
[a
].Frags
> Frags
then p
:= p
+1;
2769 s
:= IntToStr(p
)+' / '+IntToStr(Length(stat
))+' ';
2770 if Frags
>= m
then s
:= s
+'+' else s
:= s
+'-';
2771 s
:= s
+IntToStr(Abs(Frags
-m
));
2773 e_CharFont_GetSize(gMenuSmallFont
, s
, tw
, th
);
2774 e_CharFont_PrintEx(gMenuSmallFont
, X
-16-tw
, Y
+32, s
, _RGB(255, 0, 0));
2777 if gLMSRespawn
> LMS_RESPAWN_NONE
then
2779 s
:= _lc
[I_GAME_WARMUP
];
2780 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2781 s
:= s
+ ': ' + IntToStr((gLMSRespawnTime
- gTime
) div 1000);
2782 e_CharFont_PrintEx(gMenuFont
, X
-64-tw
, SY
-32, s
, _RGB(0, 255, 0));
2784 else if gShowLives
and (gGameSettings
.MaxLives
> 0) then
2786 s
:= IntToStr(Lives
);
2787 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2788 e_CharFont_PrintEx(gMenuFont
, X
-16-tw
, SY
-32, s
, _RGB(0, 255, 0));
2792 e_CharFont_GetSize(gMenuSmallFont
, FName
, tw
, th
);
2793 e_CharFont_PrintEx(gMenuSmallFont
, X
+98-(tw
div 2), Y
+8, FName
, _RGB(255, 0, 0));
2795 if R_BERSERK
in FRulez
then
2796 e_Draw(gItemsTexturesID
[ITEM_MEDKIT_BLACK
], X
+37, Y
+45, 0, True, False)
2798 e_Draw(gItemsTexturesID
[ITEM_MEDKIT_LARGE
], X
+37, Y
+45, 0, True, False);
2800 if g_Texture_Get('TEXTURE_PLAYER_ARMORHUD', ID
) then
2801 e_Draw(ID
, X
+36, Y
+77, 0, True, False);
2803 s
:= IntToStr(IfThen(FHealth
> 0, FHealth
, 0));
2804 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2805 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+40, s
, _RGB(255, 0, 0));
2807 s
:= IntToStr(FArmor
);
2808 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2809 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+68, s
, _RGB(255, 0, 0));
2811 s
:= IntToStr(GetAmmoByWeapon(FCurrWeap
));
2817 ID
:= gItemsTexturesID
[ITEM_WEAPON_KASTET
];
2822 ID
:= gItemsTexturesID
[ITEM_WEAPON_SAW
];
2824 WEAPON_PISTOL
: ID
:= gItemsTexturesID
[ITEM_WEAPON_PISTOL
];
2825 WEAPON_CHAINGUN
: ID
:= gItemsTexturesID
[ITEM_WEAPON_CHAINGUN
];
2826 WEAPON_SHOTGUN1
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SHOTGUN1
];
2827 WEAPON_SHOTGUN2
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SHOTGUN2
];
2828 WEAPON_SUPERPULEMET
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SUPERPULEMET
];
2829 WEAPON_ROCKETLAUNCHER
: ID
:= gItemsTexturesID
[ITEM_WEAPON_ROCKETLAUNCHER
];
2830 WEAPON_PLASMA
: ID
:= gItemsTexturesID
[ITEM_WEAPON_PLASMA
];
2831 WEAPON_BFG
: ID
:= gItemsTexturesID
[ITEM_WEAPON_BFG
];
2832 WEAPON_FLAMETHROWER
: ID
:= gItemsTexturesID
[ITEM_WEAPON_FLAMETHROWER
];
2835 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2836 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+158, s
, _RGB(255, 0, 0));
2837 e_Draw(ID
, X
+20, Y
+160, 0, True, False);
2839 if R_KEY_RED
in FRulez
then
2840 e_Draw(gItemsTexturesID
[ITEM_KEY_RED
], X
+78, Y
+214, 0, True, False);
2842 if R_KEY_GREEN
in FRulez
then
2843 e_Draw(gItemsTexturesID
[ITEM_KEY_GREEN
], X
+95, Y
+214, 0, True, False);
2845 if R_KEY_BLUE
in FRulez
then
2846 e_Draw(gItemsTexturesID
[ITEM_KEY_BLUE
], X
+112, Y
+214, 0, True, False);
2848 if FJetFuel
> 0 then
2850 if g_Texture_Get('TEXTURE_PLAYER_HUDAIR', ID
) then
2851 e_Draw(ID
, X
+2, Y
+116, 0, True, False);
2852 if g_Texture_Get('TEXTURE_PLAYER_HUDJET', ID
) then
2853 e_Draw(ID
, X
+2, Y
+126, 0, True, False);
2854 e_DrawLine(4, X
+16, Y
+122, X
+16+Trunc(168*IfThen(FAir
> 0, FAir
, 0)/AIR_MAX
), Y
+122, 0, 0, 196);
2855 e_DrawLine(4, X
+16, Y
+132, X
+16+Trunc(168*FJetFuel
/JET_MAX
), Y
+132, 208, 0, 0);
2859 if g_Texture_Get('TEXTURE_PLAYER_HUDAIR', ID
) then
2860 e_Draw(ID
, X
+2, Y
+124, 0, True, False);
2861 e_DrawLine(4, X
+16, Y
+130, X
+16+Trunc(168*IfThen(FAir
> 0, FAir
, 0)/AIR_MAX
), Y
+130, 0, 0, 196);
2864 if gShowPing
and g_Game_IsClient
then
2866 s
:= _lc
[I_GAME_PING_HUD
] + IntToStr(NetPeer
.lastRoundTripTime
) + _lc
[I_NET_SLIST_PING_MS
];
2867 e_TextureFontPrint(X
+ 4, Y
+ 242, s
, gStdFont
);
2873 e_TextureFontPrint(X
+ 4, Y
+ 242, _lc
[I_PLAYER_SPECT
], gStdFont
);
2874 e_TextureFontPrint(X
+ 4, Y
+ 258, _lc
[I_PLAYER_SPECT2
], gStdFont
);
2875 e_TextureFontPrint(X
+ 4, Y
+ 274, _lc
[I_PLAYER_SPECT1
], gStdFont
);
2878 e_TextureFontGetSize(gStdFont
, cw
, ch
);
2879 s
:= _lc
[I_PLAYER_SPECT4
];
2880 e_TextureFontPrintEx(gScreenWidth
div 2 - cw
*(Length(s
) div 2),
2881 gScreenHeight
-4-ch
, s
, gStdFont
, 255, 255, 255, 1, True);
2882 e_TextureFontPrint(X
+ 4, Y
+ 290, _lc
[I_PLAYER_SPECT1S
], gStdFont
);
2888 procedure TPlayer
.DrawRulez();
2892 // Ïðè âçÿòèè íåóÿçâèìîñòè ðèñóåòñÿ èíâåðñèîííûé áåëûé ôîí
2893 if (FMegaRulez
[MR_INVUL
] >= gTime
) and (FSpawnInvul
< gTime
) then
2895 if (FMegaRulez
[MR_INVUL
]-gTime
) <= 2100 then
2896 dr
:= not Odd((FMegaRulez
[MR_INVUL
]-gTime
) div 300)
2901 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2902 191, 191, 191, 0, TBlending
.Invert
);
2905 // Ïðè âçÿòèè çàùèòíîãî êîñòþìà ðèñóåòñÿ çåëåíîâàòûé ôîí
2906 if FMegaRulez
[MR_SUIT
] >= gTime
then
2908 if (FMegaRulez
[MR_SUIT
]-gTime
) <= 2100 then
2909 dr
:= not Odd((FMegaRulez
[MR_SUIT
]-gTime
) div 300)
2914 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2915 0, 96, 0, 200, TBlending
.None
);
2918 // Ïðè âçÿòèè áåðñåðêà ðèñóåòñÿ êðàñíîâàòûé ôîí
2919 if (FBerserk
>= 0) and (LongWord(FBerserk
) >= gTime
) and (gFlash
= 2) then
2921 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2922 255, 0, 0, 200, TBlending
.None
);
2926 procedure TPlayer
.DrawPain();
2930 if FPain
= 0 then Exit
;
2934 if a
< 15 then h
:= 0
2935 else if a
< 35 then h
:= 1
2936 else if a
< 55 then h
:= 2
2937 else if a
< 75 then h
:= 3
2938 else if a
< 95 then h
:= 4
2941 //if a > 255 then a := 255;
2943 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1, 255, 0, 0, 255-h
*50);
2944 //e_DrawFillQuad(0, 0, gPlayerScreenSize.X-1, gPlayerScreenSize.Y-1, 255-min(128, a), 255-a, 255-a, 0, B_FILTER);
2947 procedure TPlayer
.DrawPickup();
2951 if FPickup
= 0 then Exit
;
2955 if a
< 15 then h
:= 1
2956 else if a
< 35 then h
:= 2
2957 else if a
< 55 then h
:= 3
2958 else if a
< 75 then h
:= 4
2961 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1, 150, 200, 150, 255-h
*50);
2964 procedure TPlayer
.DoPunch();
2969 if FPunchAnim
<> nil then begin
2974 st
:= 'FRAMES_PUNCH';
2975 if R_BERSERK
in FRulez
then
2976 st
:= st
+ '_BERSERK';
2977 if FKeys
[KEY_UP
].Pressed
then
2979 else if FKeys
[KEY_DOWN
].Pressed
then
2981 g_Frames_Get(id
, st
);
2982 FPunchAnim
:= TAnimation
.Create(id
, False, 1);
2985 procedure TPlayer
.Fire();
2987 f
, DidFire
: Boolean;
2988 wx
, wy
, xd
, yd
: Integer;
2991 if g_Game_IsClient
then Exit
;
2992 // FBFGFireCounter - âðåìÿ ïåðåä âûñòðåëîì (äëÿ BFG)
2993 // FReloading - âðåìÿ ïîñëå âûñòðåëà (äëÿ âñåãî)
3001 if FReloading
[FCurrWeap
] <> 0 then Exit
;
3006 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
3007 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
3008 xd
:= wx
+IfThen(FDirection
= TDirection
.D_LEFT
, -30, 30);
3009 yd
:= wy
+firediry();
3015 if R_BERSERK
in FRulez
then
3017 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
3018 locobj
.X
:= FObj
.X
+FObj
.Rect
.X
;
3019 locobj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
3022 locobj
.rect
.Width
:= 39;
3023 locobj
.rect
.Height
:= 52;
3024 locobj
.Vel
.X
:= (xd
-wx
) div 2;
3025 locobj
.Vel
.Y
:= (yd
-wy
) div 2;
3026 locobj
.Accel
.X
:= xd
-wx
;
3027 locobj
.Accel
.y
:= yd
-wy
;
3029 if g_Weapon_Hit(@locobj
, 50, FUID
, HIT_SOME
) <> 0 then
3030 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
3032 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
3034 if (gFlash
= 1) and (FPain
< 50) then FPain
:= min(FPain
+ 25, 50);
3038 g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
3042 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3047 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
3048 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
3050 FSawSoundSelect
.Stop();
3052 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
3054 else if not FSawSoundHit
.IsPlaying() then
3056 FSawSoundSelect
.Stop();
3057 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
3060 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3066 if FAmmo
[A_BULLETS
] > 0 then
3068 g_Weapon_pistol(wx
, wy
, xd
, yd
, FUID
);
3069 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3070 Dec(FAmmo
[A_BULLETS
]);
3071 FFireAngle
:= FAngle
;
3074 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
3075 GameVelX
, GameVelY
-2, SHELL_BULLET
);
3079 if FAmmo
[A_SHELLS
] > 0 then
3081 g_Weapon_shotgun(wx
, wy
, xd
, yd
, FUID
);
3082 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', wx
, wy
);
3083 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3084 Dec(FAmmo
[A_SHELLS
]);
3085 FFireAngle
:= FAngle
;
3089 FShellType
:= SHELL_SHELL
;
3093 if FAmmo
[A_SHELLS
] >= 2 then
3095 g_Weapon_dshotgun(wx
, wy
, xd
, yd
, FUID
);
3096 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3097 Dec(FAmmo
[A_SHELLS
], 2);
3098 FFireAngle
:= FAngle
;
3102 FShellType
:= SHELL_DBLSHELL
;
3106 if FAmmo
[A_BULLETS
] > 0 then
3108 g_Weapon_mgun(wx
, wy
, xd
, yd
, FUID
);
3109 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', wx
, wy
);
3110 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3111 Dec(FAmmo
[A_BULLETS
]);
3112 FFireAngle
:= FAngle
;
3115 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
3116 GameVelX
, GameVelY
-2, SHELL_BULLET
);
3119 WEAPON_ROCKETLAUNCHER
:
3120 if FAmmo
[A_ROCKETS
] > 0 then
3122 g_Weapon_rocket(wx
, wy
, xd
, yd
, FUID
);
3123 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3124 Dec(FAmmo
[A_ROCKETS
]);
3125 FFireAngle
:= FAngle
;
3131 if FAmmo
[A_CELLS
] > 0 then
3133 g_Weapon_plasma(wx
, wy
, xd
, yd
, FUID
);
3134 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3135 Dec(FAmmo
[A_CELLS
]);
3136 FFireAngle
:= FAngle
;
3142 if (FAmmo
[A_CELLS
] >= 40) and (FBFGFireCounter
= -1) then
3144 FBFGFireCounter
:= 17;
3145 if not FNoReload
then
3146 g_Sound_PlayExAt('SOUND_WEAPON_STARTFIREBFG', FObj
.X
, FObj
.Y
);
3147 Dec(FAmmo
[A_CELLS
], 40);
3151 WEAPON_SUPERPULEMET
:
3152 if FAmmo
[A_SHELLS
] > 0 then
3154 g_Weapon_shotgun(wx
, wy
, xd
, yd
, FUID
);
3155 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', wx
, wy
);
3156 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3157 Dec(FAmmo
[A_SHELLS
]);
3158 FFireAngle
:= FAngle
;
3161 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
3162 GameVelX
, GameVelY
-2, SHELL_SHELL
);
3165 WEAPON_FLAMETHROWER
:
3166 if FAmmo
[A_FUEL
] > 0 then
3168 g_Weapon_flame(wx
, wy
, xd
, yd
, FUID
);
3170 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3172 FFireAngle
:= FAngle
;
3179 if g_Game_IsNet
and g_Game_IsServer
then MH_SEND_PlayerStats(FUID
);
3183 if g_Game_IsNet
then
3187 if FCurrWeap
<> WEAPON_BFG
then
3188 MH_SEND_PlayerFire(FUID
, FCurrWeap
, wx
, wy
, xd
, yd
, LastShotID
)
3190 if not FNoReload
then
3191 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_WEAPON_STARTFIREBFG');
3194 MH_SEND_PlayerStats(FUID
);
3199 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
3200 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
3201 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
3204 function TPlayer
.GetAmmoByWeapon(Weapon
: Byte): Word;
3207 WEAPON_PISTOL
, WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
];
3208 WEAPON_SHOTGUN1
, WEAPON_SHOTGUN2
, WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
];
3209 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
];
3210 WEAPON_PLASMA
, WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
];
3211 WEAPON_FLAMETHROWER
: Result
:= FAmmo
[A_FUEL
];
3216 function TPlayer
.HeadInLiquid(XInc
, YInc
: Integer): Boolean;
3218 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
+XInc
, FObj
.Y
+PLAYER_HEADRECT
.Y
+YInc
,
3219 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
3220 PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, True);
3223 procedure TPlayer
.FlamerOn
;
3225 FFlameSoundOff
.Stop();
3226 FFlameSoundOff
.SetPosition(0);
3229 if (not FFlameSoundOn
.IsPlaying()) and (not FFlameSoundWork
.IsPlaying()) then
3230 FFlameSoundWork
.PlayAt(FObj
.X
, FObj
.Y
);
3234 FFlameSoundOn
.PlayAt(FObj
.X
, FObj
.Y
);
3239 procedure TPlayer
.FlamerOff
;
3243 FFlameSoundOn
.Stop();
3244 FFlameSoundOn
.SetPosition(0);
3245 FFlameSoundWork
.Stop();
3246 FFlameSoundWork
.SetPosition(0);
3247 FFlameSoundOff
.PlayAt(FObj
.X
, FObj
.Y
);
3252 procedure TPlayer
.JetpackOn
;
3256 FJetSoundOn
.SetPosition(0);
3257 FJetSoundOn
.PlayAt(FObj
.X
, FObj
.Y
);
3261 procedure TPlayer
.JetpackOff
;
3265 FJetSoundOff
.SetPosition(0);
3266 FJetSoundOff
.PlayAt(FObj
.X
, FObj
.Y
);
3269 procedure TPlayer
.CatchFire(Attacker
: Word; Timeout
: Integer = PLAYER_BURN_TIME
);
3271 if Timeout
<= 0 then
3273 if (FMegaRulez
[MR_SUIT
] > gTime
) or (FMegaRulez
[MR_INVUL
] > gTime
) then
3274 exit
; // Íå çàãîðàåìñÿ êîãäà åñòü çàùèòà
3275 if g_Obj_CollidePanel(@FObj
, 0, 0, PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
) then
3276 exit
; // Íå ïîäãîðàåì â âîäå íà âñÿêèé ñëó÷àé
3277 if FFireTime
<= 0 then
3278 g_Sound_PlayExAt('SOUND_IGNITE', FObj
.X
, FObj
.Y
);
3279 FFireTime
:= Timeout
;
3280 FFireAttacker
:= Attacker
;
3281 if g_Game_IsNet
and g_Game_IsServer
then
3282 MH_SEND_PlayerStats(FUID
);
3285 procedure TPlayer
.Jump();
3287 if gFly
or FJetpack
then
3289 // Ïîëåò (÷èò-êîä èëè äæåòïàê):
3290 if FObj
.Vel
.Y
> -VEL_FLY
then
3291 FObj
.Vel
.Y
:= FObj
.Vel
.Y
- 3;
3294 if FJetFuel
> 0 then
3296 if (FJetFuel
< 1) and g_Game_IsServer
then
3300 if g_Game_IsNet
then
3301 MH_SEND_PlayerStats(FUID
);
3307 // Íå âêëþ÷àòü äæåòïàê â ðåæèìå ïðîõîæäåíèÿ ñêâîçü ñòåíû
3309 FCanJetpack
:= False;
3311 // Ïðûãàåì èëè âñïëûâàåì:
3312 if (CollideLevel(0, 1) or
3313 g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
+36, PLAYER_RECT
.Width
,
3314 PLAYER_RECT
.Height
-33, PANEL_STEP
, False)
3315 ) and (FObj
.Accel
.Y
= 0) then // Íå ïðûãàòü, åñëè åñòü âåðòèêàëüíîå óñêîðåíèå
3317 FObj
.Vel
.Y
:= -VEL_JUMP
;
3318 FCanJetpack
:= False;
3322 if BodyInLiquid(0, 0) then
3323 FObj
.Vel
.Y
:= -VEL_SW
3324 else if (FJetFuel
> 0) and FCanJetpack
and
3325 g_Game_IsServer
and (not g_Obj_CollideLiquid(@FObj
, 0, 0)) then
3329 if g_Game_IsNet
then
3330 MH_SEND_PlayerStats(FUID
);
3335 procedure TPlayer
.Kill(KillType
: Byte; SpawnerUID
: Word; t
: Byte);
3337 a
, i
, k
, ab
, ar
: Byte;
3341 srv
, netsrv
: Boolean;
3347 procedure PushItem(t
: Byte);
3351 id
:= g_Items_Create(FObj
.X
, FObj
.Y
, t
, True, False);
3352 it
:= g_Items_ByIdx(id
);
3353 if KillType
= K_EXTRAHARDKILL
then // -7..+7; -8..0
3355 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-7+Random(15),
3356 (FObj
.Vel
.Y
div 2)-Random(9));
3357 it
.positionChanged(); // this updates spatial accelerators
3361 if KillType
= K_HARDKILL
then // -5..+5; -5..0
3363 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-5+Random(11),
3364 (FObj
.Vel
.Y
div 2)-Random(6));
3366 else // -3..+3; -3..0
3368 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-3+Random(7),
3369 (FObj
.Vel
.Y
div 2)-Random(4));
3371 it
.positionChanged(); // this updates spatial accelerators
3374 if g_Game_IsNet
and g_Game_IsServer
then
3375 MH_SEND_ItemSpawn(True, id
);
3379 DoFrags
:= (gGameSettings
.MaxLives
= 0) or (gGameSettings
.GameMode
= GM_COOP
);
3380 Srv
:= g_Game_IsServer
;
3381 Netsrv
:= g_Game_IsServer
and g_Game_IsNet
;
3382 if Srv
then FDeath
:= FDeath
+ 1;
3387 if not FPhysics
then
3393 if (gGameSettings
.MaxLives
> 0) and Srv
and (gLMSRespawn
= LMS_RESPAWN_NONE
) then
3395 if FLives
> 0 then FLives
:= FLives
- 1;
3396 if FLives
= 0 then FNoRespawn
:= True;
3399 // Íîìåð òèïà ñìåðòè:
3402 K_SIMPLEKILL
: a
:= 1;
3404 K_EXTRAHARDKILL
: a
:= 3;
3409 if not FModel
.PlaySound(MODELSOUND_DIE
, a
, FObj
.X
, FObj
.Y
) then
3411 if FModel
.PlaySound(MODELSOUND_DIE
, i
, FObj
.X
, FObj
.Y
) then
3418 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN1
;
3420 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN2
;
3421 K_EXTRAHARDKILL
, K_FALLKILL
:
3422 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN3
;
3425 // Ïåðåêëþ÷àåì ñîñòîÿíèå:
3429 K_HARDKILL
, K_EXTRAHARDKILL
:
3433 // Ðåàêöèÿ ìîíñòðîâ íà ñìåðòü èãðîêà:
3434 if (KillType
<> K_FALLKILL
) and (Srv
) then
3435 g_Monsters_killedp();
3437 if SpawnerUID
= FUID
then
3441 if gGameSettings
.GameMode
= GM_TDM
then
3442 Dec(gTeamStat
[FTeam
].Goals
);
3443 if DoFrags
or (gGameSettings
.GameMode
= GM_TDM
) then
3449 g_Console_Add(Format(_lc
[I_PLAYER_KILL_SELF
], [FName
]), True);
3452 if g_GetUIDType(SpawnerUID
) = UID_PLAYER
then
3453 begin // Óáèò äðóãèì èãðîêîì
3454 KP
:= g_Player_Get(SpawnerUID
);
3455 if (KP
<> nil) and Srv
then
3457 if (DoFrags
or (gGameSettings
.GameMode
= GM_TDM
)) then
3458 if SameTeam(FUID
, SpawnerUID
) then
3468 if (gGameSettings
.GameMode
= GM_TDM
) and DoFrags
then
3469 Inc(gTeamStat
[KP
.Team
].Goals
,
3470 IfThen(SameTeam(FUID
, SpawnerUID
), -1, 1));
3472 if netsrv
then MH_SEND_PlayerStats(SpawnerUID
);
3475 plr
:= g_Player_Get(SpawnerUID
);
3483 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_2
],
3487 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_1
],
3491 g_Console_Add(Format(_lc
[I_PLAYER_KILL
],
3496 else if g_GetUIDType(SpawnerUID
) = UID_MONSTER
then
3497 begin // Óáèò ìîíñòðîì
3498 mon
:= g_Monsters_ByUID(SpawnerUID
);
3502 s
:= g_Mons_GetKilledByTypeId(mon
.MonsterType
);
3506 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_2
],
3510 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_1
],
3514 g_Console_Add(Format(_lc
[I_PLAYER_KILL
],
3519 else // Îñîáûå òèïû ñìåðòè
3522 HIT_SELF
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_SELF
], [FName
]), True);
3523 HIT_FALL
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_FALL
], [FName
]), True);
3524 HIT_WATER
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_WATER
], [FName
]), True);
3525 HIT_ACID
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_ACID
], [FName
]), True);
3526 HIT_TRAP
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_TRAP
], [FName
]), True);
3527 else g_Console_Add(Format(_lc
[I_PLAYER_DIED
], [FName
]), True);
3533 for a
:= WP_FIRST
to WP_LAST
do
3537 WEAPON_SAW
: i
:= ITEM_WEAPON_SAW
;
3538 WEAPON_SHOTGUN1
: i
:= ITEM_WEAPON_SHOTGUN1
;
3539 WEAPON_SHOTGUN2
: i
:= ITEM_WEAPON_SHOTGUN2
;
3540 WEAPON_CHAINGUN
: i
:= ITEM_WEAPON_CHAINGUN
;
3541 WEAPON_ROCKETLAUNCHER
: i
:= ITEM_WEAPON_ROCKETLAUNCHER
;
3542 WEAPON_PLASMA
: i
:= ITEM_WEAPON_PLASMA
;
3543 WEAPON_BFG
: i
:= ITEM_WEAPON_BFG
;
3544 WEAPON_SUPERPULEMET
: i
:= ITEM_WEAPON_SUPERPULEMET
;
3545 WEAPON_FLAMETHROWER
: i
:= ITEM_WEAPON_FLAMETHROWER
;
3554 if R_ITEM_BACKPACK
in FRulez
then
3555 PushItem(ITEM_AMMO_BACKPACK
);
3557 // Âûáðîñ ðàêåòíîãî ðàíöà:
3558 if FJetFuel
> 0 then
3559 PushItem(ITEM_JETPACK
);
3562 if (not (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
])) or
3563 (not LongBool(gGameSettings
.Options
and GAME_OPTION_DMKEYS
)) then
3565 if R_KEY_RED
in FRulez
then
3566 PushItem(ITEM_KEY_RED
);
3568 if R_KEY_GREEN
in FRulez
then
3569 PushItem(ITEM_KEY_GREEN
);
3571 if R_KEY_BLUE
in FRulez
then
3572 PushItem(ITEM_KEY_BLUE
);
3576 DropFlag(KillType
= K_FALLKILL
);
3579 FCorpse
:= g_Player_CreateCorpse(Self
);
3581 if Srv
and (gGameSettings
.MaxLives
> 0) and FNoRespawn
and
3582 (gLMSRespawn
= LMS_RESPAWN_NONE
) then
3588 for i
:= Low(gPlayers
) to High(gPlayers
) do
3590 if gPlayers
[i
] = nil then continue
;
3591 if (not gPlayers
[i
].FNoRespawn
) and (not gPlayers
[i
].FSpectator
) then
3594 if gPlayers
[i
].FTeam
= TEAM_RED
then Inc(ar
)
3595 else if gPlayers
[i
].FTeam
= TEAM_BLUE
then Inc(ab
);
3600 OldLR
:= gLMSRespawn
;
3601 if (gGameSettings
.GameMode
= GM_COOP
) then
3605 // everyone is dead, restart the map
3606 g_Game_Message(_lc
[I_MESSAGE_LMS_LOSE
], 144);
3608 MH_SEND_GameEvent(NET_EV_LMS_LOSE
);
3609 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3610 gLMSRespawnTime
:= gTime
+ 5000;
3612 else if (a
= 1) then
3614 if (gPlayers
[k
] <> nil) and not (gPlayers
[k
] is TBot
) then
3615 if (gPlayers
[k
] = gPlayer1
) or
3616 (gPlayers
[k
] = gPlayer2
) then
3617 g_Console_Add('*** ' + _lc
[I_MESSAGE_LMS_SURVIVOR
] + ' ***', True)
3618 else if Netsrv
and (gPlayers
[k
].FClientID
>= 0) then
3619 MH_SEND_GameEvent(NET_EV_LMS_SURVIVOR
, 0, 'N', gPlayers
[k
].FClientID
);
3622 else if (gGameSettings
.GameMode
= GM_TDM
) then
3624 if (ab
= 0) and (ar
<> 0) then
3627 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 144);
3629 MH_SEND_GameEvent(NET_EV_TLMS_WIN
, TEAM_RED
);
3630 Inc(gTeamStat
[TEAM_RED
].Goals
);
3631 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3632 gLMSRespawnTime
:= gTime
+ 5000;
3634 else if (ar
= 0) and (ab
<> 0) then
3637 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 144);
3639 MH_SEND_GameEvent(NET_EV_TLMS_WIN
, TEAM_BLUE
);
3640 Inc(gTeamStat
[TEAM_BLUE
].Goals
);
3641 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3642 gLMSRespawnTime
:= gTime
+ 5000;
3644 else if (ar
= 0) and (ab
= 0) then
3647 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
3649 MH_SEND_GameEvent(NET_EV_LMS_DRAW
, 0, FName
);
3650 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3651 gLMSRespawnTime
:= gTime
+ 5000;
3654 else if (gGameSettings
.GameMode
= GM_DM
) then
3658 if gPlayers
[k
] <> nil then
3661 // survivor is the winner
3662 g_Game_Message(Format(_lc
[I_MESSAGE_LMS_WIN
], [AnsiUpperCase(FName
)]), 144);
3664 MH_SEND_GameEvent(NET_EV_LMS_WIN
, 0, FName
);
3667 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3668 gLMSRespawnTime
:= gTime
+ 5000;
3670 else if (a
= 0) then
3672 // everyone is dead, restart the map
3673 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
3675 MH_SEND_GameEvent(NET_EV_LMS_DRAW
, 0, FName
);
3676 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3677 gLMSRespawnTime
:= gTime
+ 5000;
3680 if srv
and (OldLR
= LMS_RESPAWN_NONE
) and (gLMSRespawn
> LMS_RESPAWN_NONE
) then
3682 if NetMode
= NET_SERVER
then
3683 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
)
3685 g_Console_Add(Format(_lc
[I_MSG_WARMUP_START
], [(gLMSRespawnTime
- gTime
) div 1000]), True);
3691 MH_SEND_PlayerStats(FUID
);
3692 MH_SEND_PlayerDeath(FUID
, KillType
, t
, SpawnerUID
);
3693 if gGameSettings
.GameMode
= GM_TDM
then MH_SEND_GameStats
;
3696 if srv
and FNoRespawn
then Spectate(True);
3697 FWantsInGame
:= True;
3700 function TPlayer
.BodyInLiquid(XInc
, YInc
: Integer): Boolean;
3702 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
, PLAYER_RECT
.Width
,
3703 PLAYER_RECT
.Height
-20, PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, False);
3706 function TPlayer
.BodyInAcid(XInc
, YInc
: Integer): Boolean;
3708 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
, PLAYER_RECT
.Width
,
3709 PLAYER_RECT
.Height
-20, PANEL_ACID1
or PANEL_ACID2
, False);
3712 procedure TPlayer
.MakeBloodSimple(Count
: Word);
3714 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)+8,
3715 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3716 Count
div 2, 3, -1, 16, (PLAYER_RECT
.Height
*2 div 3),
3717 FModel
.Blood
.R
, FModel
.Blood
.G
, FModel
.Blood
.B
, FModel
.Blood
.Kind
);
3718 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-8,
3719 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3720 Count
div 2, -3, -1, 16, (PLAYER_RECT
.Height
*2) div 3,
3721 FModel
.Blood
.R
, FModel
.Blood
.G
, FModel
.Blood
.B
, FModel
.Blood
.Kind
);
3724 procedure TPlayer
.MakeBloodVector(Count
: Word; VelX
, VelY
: Integer);
3726 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
3727 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3728 Count
, VelX
, VelY
, 16, (PLAYER_RECT
.Height
*2) div 3,
3729 FModel
.Blood
.R
, FModel
.Blood
.G
, FModel
.Blood
.B
, FModel
.Blood
.Kind
);
3732 procedure TPlayer
.ProcessWeaponAction(Action
: Byte);
3734 if g_Game_IsClient
then Exit
;
3736 WP_PREV
: PrevWeapon();
3737 WP_NEXT
: NextWeapon();
3741 procedure TPlayer
.QueueWeaponSwitch(Weapon
: Byte);
3743 if g_Game_IsClient
then Exit
;
3744 if Weapon
> High(FWeapon
) then Exit
;
3745 FNextWeap
:= FNextWeap
or (1 shl Weapon
);
3748 procedure TPlayer
.resetWeaponQueue ();
3751 FNextWeapDelay
:= 0;
3754 function TPlayer
.hasAmmoForWeapon (weapon
: Byte): Boolean;
3758 WEAPON_KASTET
, WEAPON_SAW
: result
:= true;
3759 WEAPON_SHOTGUN1
, WEAPON_SHOTGUN2
, WEAPON_SUPERPULEMET
: result
:= (FAmmo
[A_SHELLS
] > 0);
3760 WEAPON_PISTOL
, WEAPON_CHAINGUN
: result
:= (FAmmo
[A_BULLETS
] > 0);
3761 WEAPON_ROCKETLAUNCHER
: result
:= (FAmmo
[A_ROCKETS
] > 0);
3762 WEAPON_PLASMA
, WEAPON_BFG
: result
:= (FAmmo
[A_CELLS
] > 0);
3763 WEAPON_FLAMETHROWER
: result
:= (FAmmo
[A_FUEL
] > 0);
3764 else result
:= (weapon
< length(FWeapon
));
3768 function TPlayer
.shouldSwitch (weapon
: Byte; hadWeapon
: Boolean): Boolean;
3771 if (weapon
< 0) or (weapon
> WP_LAST
+ 1) then
3776 if (FWeapSwitchMode
= 1) and not hadWeapon
then
3778 else if (FWeapSwitchMode
= 2) then
3779 result
:= (FWeapPreferences
[weapon
] > FWeapPreferences
[FCurrWeap
]);
3782 // return 255 for "no switch"
3783 function TPlayer
.getNextWeaponIndex (): Byte;
3786 wantThisWeapon
: array[0..64] of Boolean;
3787 wwc
: Integer = 0; //HACK!
3790 result
:= 255; // default result: "no switch"
3791 //e_LogWriteFln('FSWITCHTOEMPTY: %s', [FSwitchToEmpty], TMsgType.Notify);
3792 // had weapon cycling on previous frame? remove that flag
3793 if (FNextWeap
and $2000) <> 0 then
3795 FNextWeap
:= FNextWeap
and $1FFF;
3796 FNextWeapDelay
:= 0;
3798 // cycling has priority
3799 if (FNextWeap
and $C000) <> 0 then
3801 if (FNextWeap
and $8000) <> 0 then
3805 FNextWeap
:= FNextWeap
or $2000; // we need this
3806 if FNextWeapDelay
> 0 then
3807 exit
; // cooldown time
3809 for i
:= 0 to High(FWeapon
) do
3811 cwi
:= (cwi
+length(FWeapon
)+dir
) mod length(FWeapon
);
3812 if FWeapon
[cwi
] and ((FSwitchToEmpty
= 1) or hasAmmoForWeapon(cwi
)) then
3814 //e_LogWriteFln(' SWITCH: cur=%d; new=%d %s %s', [FCurrWeap, cwi, FSwitchToEmpty, hasAmmoForWeapon(cwi)], TMsgType.Notify);
3815 result
:= Byte(cwi
);
3816 FNextWeapDelay
:= WEAPON_DELAY
;
3824 for i
:= 0 to High(wantThisWeapon
) do
3825 wantThisWeapon
[i
] := false;
3826 for i
:= 0 to High(FWeapon
) do
3827 if (FNextWeap
and (1 shl i
)) <> 0 then
3829 wantThisWeapon
[i
] := true;
3833 // exclude currently selected weapon from the set
3834 wantThisWeapon
[FCurrWeap
] := false;
3835 // slow down alterations a little
3838 //e_WriteLog(Format(' FNextWeap=%x; delay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
3839 // more than one weapon requested, assume "alteration" and check alteration delay
3840 if FNextWeapDelay
> 0 then
3846 // do not reset weapon queue, it will be done in `RealizeCurrentWeapon()`
3847 // but clear all counters if no weapon should be switched
3853 //e_WriteLog(Format('wwc=%d', [wwc]), MSG_WARNING);
3854 // try weapons in descending order
3855 for i
:= High(FWeapon
) downto 0 do
3857 if wantThisWeapon
[i
] and FWeapon
[i
] and ((wwc
= 1) or hasAmmoForWeapon(i
)) then
3862 FNextWeapDelay
:= WEAPON_DELAY
* 2; // anyway, 'cause why not
3863 //e_LogWriteFln('FOUND %s %s %s', [result, FSwitchToEmpty, hasAmmoForWeapon(i)], TMsgType.Notify);
3867 // no suitable weapon found, so reset the queue, to avoid accidental "queuing" of weapon w/o ammo
3871 procedure TPlayer
.RealizeCurrentWeapon();
3872 function switchAllowed (): Boolean;
3877 if FBFGFireCounter
<> -1 then
3879 if FTime
[T_SWITCH
] > gTime
then
3881 for i
:= WP_FIRST
to WP_LAST
do
3882 if FReloading
[i
] > 0 then
3890 //e_WriteLog(Format('***RealizeCurrentWeapon: FNextWeap=%x; FNextWeapDelay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
3891 //FNextWeap := FNextWeap and $1FFF;
3892 if FNextWeapDelay
> 0 then Dec(FNextWeapDelay
); // "alteration delay"
3894 if not switchAllowed
then
3896 //HACK for weapon cycling
3897 if (FNextWeap
and $E000) <> 0 then FNextWeap
:= 0;
3901 nw
:= getNextWeaponIndex();
3903 if nw
= 255 then exit
; // don't reset anything here
3904 if nw
> High(FWeapon
) then
3906 // don't forget to reset queue here!
3907 //e_WriteLog(' RealizeCurrentWeapon: WUTAFUUUU', MSG_WARNING);
3915 FTime
[T_SWITCH
] := gTime
+156;
3916 if FCurrWeap
= WEAPON_SAW
then FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3917 FModel
.SetWeapon(FCurrWeap
);
3918 if g_Game_IsNet
then MH_SEND_PlayerStats(FUID
);
3922 procedure TPlayer
.NextWeapon();
3924 if g_Game_IsClient
then Exit
;
3928 procedure TPlayer
.PrevWeapon();
3930 if g_Game_IsClient
then Exit
;
3934 procedure TPlayer
.SetWeapon(W
: Byte);
3936 if FCurrWeap
<> W
then
3937 if W
= WEAPON_SAW
then
3938 FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3941 FModel
.SetWeapon(CurrWeap
);
3945 function TPlayer
.PickItem(ItemType
: Byte; arespawn
: Boolean; var remove
: Boolean): Boolean;
3947 function allowBerserkSwitching (): Boolean;
3949 if (FBFGFireCounter
<> -1) then begin result
:= false; exit
; end;
3951 if gBerserkAutoswitch
then exit
;
3952 if not conIsCheatsEnabled
then exit
;
3958 switchWeapon
: Byte = -1;
3959 hadWeapon
: Boolean = False;
3962 if g_Game_IsClient
then Exit
;
3964 // a = true - ìåñòî ñïàâíà ïðåäìåòà:
3965 a
:= LongBool(gGameSettings
.Options
and GAME_OPTION_WEAPONSTAY
) and arespawn
;
3969 if (FHealth
< PLAYER_HP_SOFT
) or (FFireTime
> 0) then
3971 if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
3975 if gFlash
= 2 then Inc(FPickup
, 5);
3979 if (FHealth
< PLAYER_HP_SOFT
) or (FFireTime
> 0) then
3981 if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
3985 if gFlash
= 2 then Inc(FPickup
, 5);
3989 if FArmor
< PLAYER_AP_SOFT
then
3991 FArmor
:= PLAYER_AP_SOFT
;
3994 if gFlash
= 2 then Inc(FPickup
, 5);
3998 if FArmor
< PLAYER_AP_LIMIT
then
4000 FArmor
:= PLAYER_AP_LIMIT
;
4003 if gFlash
= 2 then Inc(FPickup
, 5);
4007 if (FHealth
< PLAYER_HP_LIMIT
) or (FFireTime
> 0) then
4009 if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
4013 if gFlash
= 2 then Inc(FPickup
, 5);
4017 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) or (FFireTime
> 0) then
4019 if FHealth
< PLAYER_HP_LIMIT
then
4020 FHealth
:= PLAYER_HP_LIMIT
;
4021 if FArmor
< PLAYER_AP_LIMIT
then
4022 FArmor
:= PLAYER_AP_LIMIT
;
4026 if gFlash
= 2 then Inc(FPickup
, 5);
4030 if (not FWeapon
[WEAPON_SAW
]) or ((not arespawn
) and (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
])) then
4032 hadWeapon
:= FWeapon
[WEAPON_SAW
];
4033 switchWeapon
:= WEAPON_SAW
;
4034 FWeapon
[WEAPON_SAW
] := True;
4036 if gFlash
= 2 then Inc(FPickup
, 5);
4037 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4040 ITEM_WEAPON_SHOTGUN1
:
4041 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN1
] then
4043 // Íóæíî, ÷òîáû íå âçÿòü âñå ïóëè ñðàçó:
4044 if a
and FWeapon
[WEAPON_SHOTGUN1
] then Exit
;
4045 hadWeapon
:= FWeapon
[WEAPON_SHOTGUN1
];
4046 switchWeapon
:= WEAPON_SHOTGUN1
;
4047 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4048 FWeapon
[WEAPON_SHOTGUN1
] := True;
4050 if gFlash
= 2 then Inc(FPickup
, 5);
4051 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4054 ITEM_WEAPON_SHOTGUN2
:
4055 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN2
] then
4057 if a
and FWeapon
[WEAPON_SHOTGUN2
] then Exit
;
4058 hadWeapon
:= FWeapon
[WEAPON_SHOTGUN2
];
4059 switchWeapon
:= WEAPON_SHOTGUN2
;
4060 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4061 FWeapon
[WEAPON_SHOTGUN2
] := True;
4063 if gFlash
= 2 then Inc(FPickup
, 5);
4064 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4067 ITEM_WEAPON_CHAINGUN
:
4068 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or not FWeapon
[WEAPON_CHAINGUN
] then
4070 if a
and FWeapon
[WEAPON_CHAINGUN
] then Exit
;
4071 hadWeapon
:= FWeapon
[WEAPON_CHAINGUN
];
4072 switchWeapon
:= WEAPON_CHAINGUN
;
4073 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
4074 FWeapon
[WEAPON_CHAINGUN
] := True;
4076 if gFlash
= 2 then Inc(FPickup
, 5);
4077 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4080 ITEM_WEAPON_ROCKETLAUNCHER
:
4081 if (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or not FWeapon
[WEAPON_ROCKETLAUNCHER
] then
4083 if a
and FWeapon
[WEAPON_ROCKETLAUNCHER
] then Exit
;
4084 switchWeapon
:= WEAPON_ROCKETLAUNCHER
;
4085 hadWeapon
:= FWeapon
[WEAPON_ROCKETLAUNCHER
];
4086 IncMax(FAmmo
[A_ROCKETS
], 2, FMaxAmmo
[A_ROCKETS
]);
4087 FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
4089 if gFlash
= 2 then Inc(FPickup
, 5);
4090 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4094 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_PLASMA
] then
4096 if a
and FWeapon
[WEAPON_PLASMA
] then Exit
;
4097 switchWeapon
:= WEAPON_PLASMA
;
4098 hadWeapon
:= FWeapon
[WEAPON_PLASMA
];
4099 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
4100 FWeapon
[WEAPON_PLASMA
] := True;
4102 if gFlash
= 2 then Inc(FPickup
, 5);
4103 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4107 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_BFG
] then
4109 if a
and FWeapon
[WEAPON_BFG
] then Exit
;
4110 switchWeapon
:= WEAPON_BFG
;
4111 hadWeapon
:= FWeapon
[WEAPON_BFG
];
4112 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
4113 FWeapon
[WEAPON_BFG
] := True;
4115 if gFlash
= 2 then Inc(FPickup
, 5);
4116 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4119 ITEM_WEAPON_SUPERPULEMET
:
4120 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SUPERPULEMET
] then
4122 if a
and FWeapon
[WEAPON_SUPERPULEMET
] then Exit
;
4123 switchWeapon
:= WEAPON_SUPERPULEMET
;
4124 hadWeapon
:= FWeapon
[WEAPON_SUPERPULEMET
];
4125 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4126 FWeapon
[WEAPON_SUPERPULEMET
] := True;
4128 if gFlash
= 2 then Inc(FPickup
, 5);
4129 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4132 ITEM_WEAPON_FLAMETHROWER
:
4133 if (FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
]) or not FWeapon
[WEAPON_FLAMETHROWER
] then
4135 if a
and FWeapon
[WEAPON_FLAMETHROWER
] then Exit
;
4136 switchWeapon
:= WEAPON_FLAMETHROWER
;
4137 hadWeapon
:= FWeapon
[WEAPON_FLAMETHROWER
];
4138 IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
4139 FWeapon
[WEAPON_FLAMETHROWER
] := True;
4141 if gFlash
= 2 then Inc(FPickup
, 5);
4142 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4146 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
4148 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
4151 if gFlash
= 2 then Inc(FPickup
, 5);
4154 ITEM_AMMO_BULLETS_BOX
:
4155 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
4157 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
4160 if gFlash
= 2 then Inc(FPickup
, 5);
4164 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
4166 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4169 if gFlash
= 2 then Inc(FPickup
, 5);
4172 ITEM_AMMO_SHELLS_BOX
:
4173 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
4175 IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
4178 if gFlash
= 2 then Inc(FPickup
, 5);
4182 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
4184 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
4187 if gFlash
= 2 then Inc(FPickup
, 5);
4190 ITEM_AMMO_ROCKET_BOX
:
4191 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
4193 IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
4196 if gFlash
= 2 then Inc(FPickup
, 5);
4200 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
4202 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
4205 if gFlash
= 2 then Inc(FPickup
, 5);
4209 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
4211 IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
4214 if gFlash
= 2 then Inc(FPickup
, 5);
4218 if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then
4220 IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
4223 if gFlash
= 2 then Inc(FPickup
, 5);
4227 if not(R_ITEM_BACKPACK
in FRulez
) or
4228 (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
4229 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
4230 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
4231 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or
4232 (FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
]) then
4234 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[1, A_BULLETS
];
4235 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[1, A_SHELLS
];
4236 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[1, A_ROCKETS
];
4237 FMaxAmmo
[A_CELLS
] := AmmoLimits
[1, A_CELLS
];
4238 FMaxAmmo
[A_FUEL
] := AmmoLimits
[1, A_FUEL
];
4240 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
4241 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
4242 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
4243 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4244 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
4245 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
4246 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
4247 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
4248 if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then
4249 IncMax(FAmmo
[A_FUEL
], 50, FMaxAmmo
[A_FUEL
]);
4251 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
4254 if gFlash
= 2 then Inc(FPickup
, 5);
4258 if not(R_KEY_RED
in FRulez
) then
4260 Include(FRulez
, R_KEY_RED
);
4262 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
4263 if gFlash
= 2 then Inc(FPickup
, 5);
4264 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
4268 if not(R_KEY_GREEN
in FRulez
) then
4270 Include(FRulez
, R_KEY_GREEN
);
4272 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
4273 if gFlash
= 2 then Inc(FPickup
, 5);
4274 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
4278 if not(R_KEY_BLUE
in FRulez
) then
4280 Include(FRulez
, R_KEY_BLUE
);
4282 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
4283 if gFlash
= 2 then Inc(FPickup
, 5);
4284 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
4288 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
4290 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
4294 if gFlash
= 2 then Inc(FPickup
, 5);
4298 if FAir
< AIR_MAX
then
4303 if gFlash
= 2 then Inc(FPickup
, 5);
4308 if not (R_BERSERK
in FRulez
) then
4310 Include(FRulez
, R_BERSERK
);
4311 if (shouldSwitch(WP_LAST
+ 1, false)) then
4312 QueueWeaponSwitch(WEAPON_KASTET
);
4316 if gFlash
= 2 then Inc(FPickup
, 5);
4318 FBerserk
:= gTime
+30000;
4323 if (FHealth
< PLAYER_HP_SOFT
) or (FFireTime
> 0) then
4325 if FHealth
< PLAYER_HP_SOFT
then FHealth
:= PLAYER_HP_SOFT
;
4326 FBerserk
:= gTime
+30000;
4334 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
4336 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
4340 if gFlash
= 2 then Inc(FPickup
, 5);
4344 if (FHealth
< PLAYER_HP_LIMIT
) or (FFireTime
> 0) then
4346 if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
4350 if gFlash
= 2 then Inc(FPickup
, 5);
4354 if FArmor
< PLAYER_AP_LIMIT
then
4356 IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
4359 if gFlash
= 2 then Inc(FPickup
, 5);
4363 if FJetFuel
< JET_MAX
then
4365 FJetFuel
:= JET_MAX
;
4368 if gFlash
= 2 then Inc(FPickup
, 5);
4372 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
4374 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
4377 if gFlash
= 2 then Inc(FPickup
, 5);
4381 if (shouldSwitch(switchWeapon
, hadWeapon
)) then
4382 QueueWeaponSwitch(switchWeapon
);
4385 procedure TPlayer
.Touch();
4389 //FModel.PlaySound(MODELSOUND_PAIN, 1, FObj.X, FObj.Y);
4392 // Áðîñèòü ôëàã òîâàðèùó:
4393 if gGameSettings
.GameMode
= GM_CTF
then
4398 procedure TPlayer
.Push(vx
, vy
: Integer);
4400 if (not FPhysics
) and FGhost
then
4402 FObj
.Accel
.X
:= FObj
.Accel
.X
+ vx
;
4403 FObj
.Accel
.Y
:= FObj
.Accel
.Y
+ vy
;
4404 if g_Game_IsNet
and g_Game_IsServer
then
4405 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
4408 procedure TPlayer
.Reset(Force
: Boolean);
4414 FTime
[T_RESPAWN
] := 0;
4415 FTime
[T_FLAGCAP
] := 0;
4431 FSpectator
:= False;
4434 FSpectatePlayer
:= -1;
4435 FNoRespawn
:= False;
4437 FLives
:= gGameSettings
.MaxLives
;
4442 procedure TPlayer
.SoftReset();
4450 FBFGFireCounter
:= -1;
4458 SetAction(A_STAND
, True);
4461 function TPlayer
.GetRespawnPoint(): Byte;
4466 // Íà áóäóùåå: FSpawn - èãðîê óæå èãðàë è ïåðåðîæäàåòñÿ
4468 // Îäèíî÷íàÿ èãðà/êîîïåðàòèâ
4469 if gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
] then
4471 if Self
= gPlayer1
then
4473 // player 1 should try to spawn on the player 1 point
4474 if g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) > 0 then
4475 Exit(RESPAWNPOINT_PLAYER1
)
4476 else if g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) > 0 then
4477 Exit(RESPAWNPOINT_PLAYER2
);
4479 else if Self
= gPlayer2
then
4481 // player 2 should try to spawn on the player 2 point
4482 if g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) > 0 then
4483 Exit(RESPAWNPOINT_PLAYER2
)
4484 else if g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) > 0 then
4485 Exit(RESPAWNPOINT_PLAYER1
);
4489 // other players randomly pick either the first or the second point
4490 c
:= IfThen((Random(2) = 0), RESPAWNPOINT_PLAYER1
, RESPAWNPOINT_PLAYER2
);
4491 if g_Map_GetPointCount(c
) > 0 then
4493 // try the other one
4494 c
:= IfThen((c
= RESPAWNPOINT_PLAYER1
), RESPAWNPOINT_PLAYER2
, RESPAWNPOINT_PLAYER1
);
4495 if g_Map_GetPointCount(c
) > 0 then
4501 if gGameSettings
.GameMode
= GM_DM
then
4503 // try DM points first
4504 if g_Map_GetPointCount(RESPAWNPOINT_DM
) > 0 then
4505 Exit(RESPAWNPOINT_DM
);
4509 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
4511 // try team points first
4512 c
:= RESPAWNPOINT_DM
;
4513 if FTeam
= TEAM_RED
then
4514 c
:= RESPAWNPOINT_RED
4515 else if FTeam
= TEAM_BLUE
then
4516 c
:= RESPAWNPOINT_BLUE
;
4517 if g_Map_GetPointCount(c
) > 0 then
4521 // still haven't found a spawnpoint, try random shit
4522 Result
:= g_Map_GetRandomPointType();
4525 procedure TPlayer
.Respawn(Silent
: Boolean; Force
: Boolean = False);
4527 RespawnPoint
: TRespawnPoint
;
4535 FBFGFireCounter
:= -1;
4542 if not g_Game_IsServer
then
4546 FWantsInGame
:= True;
4547 FJustTeleported
:= True;
4550 FTime
[T_RESPAWN
] := 0;
4554 // if server changes MaxLives we gotta be ready
4555 if gGameSettings
.MaxLives
= 0 then FNoRespawn
:= False;
4557 // Åùå íåëüçÿ âîçðîäèòüñÿ:
4558 if FTime
[T_RESPAWN
] > gTime
then
4561 // Ïðîñðàë âñå æèçíè:
4564 if not FSpectator
then Spectate(True);
4565 FWantsInGame
:= True;
4569 if (gGameSettings
.GameType
<> GT_SINGLE
) and (gGameSettings
.GameMode
<> GM_COOP
) then
4570 begin // "Ñâîÿ èãðà"
4571 // Áåðñåðê íå ñîõðàíÿåòñÿ ìåæäó óðîâíÿìè:
4572 FRulez
:= FRulez
-[R_BERSERK
];
4574 else // "Îäèíî÷íàÿ èãðà"/"Êîîï"
4576 // Áåðñåðê è êëþ÷è íå ñîõðàíÿþòñÿ ìåæäó óðîâíÿìè:
4577 FRulez
:= FRulez
-[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
, R_BERSERK
];
4580 // Ïîëó÷àåì òî÷êó ñïàóíà èãðîêà:
4581 c
:= GetRespawnPoint();
4586 // Âîñêðåøåíèå áåç îðóæèÿ:
4589 FHealth
:= Round(PLAYER_HP_SOFT
* (FHandicap
/ 100));
4595 for a
:= WP_FIRST
to WP_LAST
do
4597 FWeapon
[a
] := False;
4601 FWeapon
[WEAPON_PISTOL
] := True;
4602 FWeapon
[WEAPON_KASTET
] := True;
4603 FCurrWeap
:= WEAPON_PISTOL
;
4606 FModel
.SetWeapon(FCurrWeap
);
4608 for b
:= A_BULLETS
to A_HIGH
do
4611 FAmmo
[A_BULLETS
] := 50;
4613 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[0, A_BULLETS
];
4614 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[0, A_SHELLS
];
4615 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[0, A_SHELLS
];
4616 FMaxAmmo
[A_CELLS
] := AmmoLimits
[0, A_CELLS
];
4617 FMaxAmmo
[A_FUEL
] := AmmoLimits
[0, A_FUEL
];
4619 if (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
]) and
4620 LongBool(gGameSettings
.Options
and GAME_OPTION_DMKEYS
) then
4621 FRulez
:= [R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
]
4626 // Ïîëó÷àåì êîîðäèíàòû òî÷êè âîçðîæäåíèÿ:
4627 if not g_Map_GetPoint(c
, RespawnPoint
) then
4629 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
4633 // Óñòàíîâêà êîîðäèíàò è ñáðîñ âñåõ ïàðàìåòðîâ:
4634 FObj
.X
:= RespawnPoint
.X
-PLAYER_RECT
.X
;
4635 FObj
.Y
:= RespawnPoint
.Y
-PLAYER_RECT
.Y
;
4636 FObj
.oldX
:= FObj
.X
; // don't interpolate after respawn
4637 FObj
.oldY
:= FObj
.Y
;
4643 FDirection
:= RespawnPoint
.Direction
;
4644 if FDirection
= TDirection
.D_LEFT
then
4649 SetAction(A_STAND
, True);
4650 FModel
.Direction
:= FDirection
;
4652 for a
:= Low(FTime
) to High(FTime
) do
4655 for a
:= Low(FMegaRulez
) to High(FMegaRulez
) do
4658 // Respawn invulnerability
4659 if (gGameSettings
.GameType
<> GT_SINGLE
) and (gGameSettings
.SpawnInvul
> 0) then
4661 FMegaRulez
[MR_INVUL
] := gTime
+ gGameSettings
.SpawnInvul
* 1000;
4662 FSpawnInvul
:= FMegaRulez
[MR_INVUL
];
4667 FCanJetpack
:= False;
4673 // Àíèìàöèÿ âîçðîæäåíèÿ:
4674 if (not gLoadGameMode
) and (not Silent
) then
4675 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
4677 Anim
:= TAnimation
.Create(ID
, False, 3);
4678 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4679 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4683 FSpectator
:= False;
4686 FSpectatePlayer
:= -1;
4689 if (gPlayer1
= nil) and (gSpectLatchPID1
= FUID
) then
4691 if (gPlayer2
= nil) and (gSpectLatchPID2
= FUID
) then
4694 if g_Game_IsNet
then
4696 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
4697 MH_SEND_PlayerStats(FUID
, NET_EVERYONE
);
4699 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4700 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32,
4705 procedure TPlayer
.Spectate(NoMove
: Boolean = False);
4708 Kill(K_EXTRAHARDKILL
, FUID
, HIT_SOME
)
4709 else if (not NoMove
) then
4711 GameX
:= gMapInfo
.Width
div 2;
4712 GameY
:= gMapInfo
.Height
div 2;
4721 FWantsInGame
:= False;
4727 if Self
= gPlayer1
then
4729 gSpectLatchPID1
:= FUID
;
4732 else if Self
= gPlayer2
then
4734 gSpectLatchPID2
:= FUID
;
4739 if g_Game_IsNet
then
4740 MH_SEND_PlayerStats(FUID
);
4743 procedure TPlayer
.SwitchNoClip
;
4747 FGhost
:= not FGhost
;
4748 FPhysics
:= not FGhost
;
4760 procedure TPlayer
.Run(Direction
: TDirection
);
4764 if MAX_RUNVEL
> 8 then
4768 if Direction
= TDirection
.D_LEFT
then
4770 if FObj
.Vel
.X
> -MAX_RUNVEL
then
4771 FObj
.Vel
.X
:= FObj
.Vel
.X
- (MAX_RUNVEL
shr 3);
4774 if FObj
.Vel
.X
< MAX_RUNVEL
then
4775 FObj
.Vel
.X
:= FObj
.Vel
.X
+ (MAX_RUNVEL
shr 3);
4777 // Âîçìîæíî, ïèíàåì êóñêè:
4778 if (FObj
.Vel
.X
<> 0) and (gGibs
<> nil) then
4780 b
:= Abs(FObj
.Vel
.X
);
4781 if b
> 1 then b
:= b
* (Random(8 div b
) + 1);
4782 for a
:= 0 to High(gGibs
) do
4784 if gGibs
[a
].alive
and
4785 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
+FObj
.Rect
.Height
-4,
4786 FObj
.Rect
.Width
, 8, @gGibs
[a
].Obj
) and (Random(3) = 0) then
4789 if FObj
.Vel
.X
< 0 then
4791 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)+120) // íàëåâî
4795 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)); // íàïðàâî
4797 gGibs
[a
].positionChanged(); // this updates spatial accelerators
4805 procedure TPlayer
.SeeDown();
4807 SetAction(A_SEEDOWN
);
4809 if FDirection
= TDirection
.D_LEFT
then FAngle
:= ANGLE_LEFTDOWN
else FAngle
:= ANGLE_RIGHTDOWN
;
4811 if FIncCam
> -120 then DecMin(FIncCam
, 5, -120);
4814 procedure TPlayer
.SeeUp();
4818 if FDirection
= TDirection
.D_LEFT
then FAngle
:= ANGLE_LEFTUP
else FAngle
:= ANGLE_RIGHTUP
;
4820 if FIncCam
< 120 then IncMax(FIncCam
, 5, 120);
4823 procedure TPlayer
.SetAction(Action
: Byte; Force
: Boolean = False);
4831 A_ATTACK
: Prior
:= 2;
4832 A_SEEUP
: Prior
:= 1;
4833 A_SEEDOWN
: Prior
:= 1;
4834 A_ATTACKUP
: Prior
:= 2;
4835 A_ATTACKDOWN
: Prior
:= 2;
4840 if (Prior
> FActionPrior
) or Force
then
4841 if not ((Prior
= 2) and (FCurrWeap
= WEAPON_SAW
)) then
4843 FActionPrior
:= Prior
;
4844 FActionAnim
:= Action
;
4845 FActionForce
:= Force
;
4846 FActionChanged
:= True;
4849 if Action
in [A_ATTACK
, A_ATTACKUP
, A_ATTACKDOWN
] then FModel
.SetFire(True);
4852 function TPlayer
.StayOnStep(XInc
, YInc
: Integer): Boolean;
4854 Result
:= not g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
-1,
4855 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False)
4856 and g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
,
4857 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False);
4860 function TPlayer
.TeleportTo(X
, Y
: Integer; silent
: Boolean; dir
: Byte): Boolean;
4867 if g_CollideLevel(X
, Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
) then
4869 g_Sound_PlayExAt('SOUND_GAME_NOTELEPORT', FObj
.X
, FObj
.Y
);
4870 if g_Game_IsServer
and g_Game_IsNet
then
4871 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_GAME_NOTELEPORT');
4875 FJustTeleported
:= True;
4880 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
4882 Anim
:= TAnimation
.Create(ID
, False, 3);
4885 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', FObj
.X
, FObj
.Y
);
4886 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4887 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4888 if g_Game_IsServer
and g_Game_IsNet
then
4889 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4890 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 1,
4894 FObj
.X
:= X
-PLAYER_RECT
.X
;
4895 FObj
.Y
:= Y
-PLAYER_RECT
.Y
;
4896 FObj
.oldX
:= FObj
.X
; // don't interpolate after respawn
4897 FObj
.oldY
:= FObj
.Y
;
4898 if FAlive
and FGhost
then
4904 if not g_Game_IsNet
then
4908 SetDirection(TDirection
.D_LEFT
);
4914 SetDirection(TDirection
.D_RIGHT
);
4920 if FDirection
= TDirection
.D_RIGHT
then
4922 SetDirection(TDirection
.D_LEFT
);
4927 SetDirection(TDirection
.D_RIGHT
);
4933 if not silent
and (Anim
<> nil) then
4935 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4936 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4939 if g_Game_IsServer
and g_Game_IsNet
then
4940 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4941 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 0,
4948 function nonz(a
: Single): Single;
4956 function TPlayer
.refreshCorpse(): Boolean;
4962 if FAlive
or FSpectator
then
4964 if (gCorpses
= nil) or (Length(gCorpses
) = 0) then
4966 for i
:= 0 to High(gCorpses
) do
4967 if gCorpses
[i
] <> nil then
4968 if gCorpses
[i
].FPlayerUID
= FUID
then
4976 function TPlayer
.getCameraObj(): TObj
;
4978 if (not FAlive
) and (not FSpectator
) and
4979 (FCorpse
>= 0) and (FCorpse
< Length(gCorpses
)) and
4980 (gCorpses
[FCorpse
] <> nil) and (gCorpses
[FCorpse
].FPlayerUID
= FUID
) then
4982 gCorpses
[FCorpse
].FObj
.slopeUpLeft
:= FObj
.slopeUpLeft
;
4983 Result
:= gCorpses
[FCorpse
].FObj
;
4991 procedure TPlayer
.PreUpdate();
4993 FSlopeOld
:= FObj
.slopeUpLeft
;
4994 FIncCamOld
:= FIncCam
;
4995 FObj
.oldX
:= FObj
.X
;
4996 FObj
.oldY
:= FObj
.Y
;
4999 procedure TPlayer
.Update();
5002 i
, ii
, wx
, wy
, xd
, yd
, k
: Integer;
5003 blockmon
, headwater
, dospawn
: Boolean;
5008 NetServer
:= g_Game_IsNet
and g_Game_IsServer
;
5009 AnyServer
:= g_Game_IsServer
;
5011 if g_Game_IsClient
and (NetInterpLevel
> 0) then
5012 DoLerp(NetInterpLevel
+ 1)
5018 if (FClientID
>= 0) and (NetClients
[FClientID
].Peer
<> nil) then
5020 FPing
:= NetClients
[FClientID
].Peer
^.lastRoundTripTime
;
5021 if NetClients
[FClientID
].Peer
^.packetsSent
> 0 then
5022 FLoss
:= Round(100*NetClients
[FClientID
].Peer
^.packetsLost
/NetClients
[FClientID
].Peer
^.packetsSent
)
5031 if FAlive
and (FPunchAnim
<> nil) then
5032 FPunchAnim
.Update();
5034 if FAlive
and (gFly
or FJetpack
) then
5037 if FDirection
= TDirection
.D_LEFT
then
5042 if FAlive
and (not FGhost
) then
5044 if FKeys
[KEY_UP
].Pressed
then
5046 if FKeys
[KEY_DOWN
].Pressed
then
5050 if (not (FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_DOWN
].Pressed
)) and
5053 i
:= g_basic
.Sign(FIncCam
);
5054 FIncCam
:= Abs(FIncCam
);
5055 DecMin(FIncCam
, 5, 0);
5056 FIncCam
:= FIncCam
*i
;
5059 if gTime
mod (GAME_TICK
*2) <> 0 then
5061 if (FObj
.Vel
.X
= 0) and FAlive
then
5063 if FKeys
[KEY_LEFT
].Pressed
then
5064 Run(TDirection
.D_LEFT
);
5065 if FKeys
[KEY_RIGHT
].Pressed
then
5066 Run(TDirection
.D_RIGHT
);
5071 g_Obj_Move(@FObj
, True, True, True);
5072 positionChanged(); // this updates spatial accelerators
5078 FActionChanged
:= False;
5082 // Let alive player do some actions
5083 if FKeys
[KEY_LEFT
].Pressed
then Run(TDirection
.D_LEFT
);
5084 if FKeys
[KEY_RIGHT
].Pressed
then Run(TDirection
.D_RIGHT
);
5085 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then Fire()
5091 if NetServer
then MH_SEND_PlayerStats(FUID
);
5094 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Use();
5095 if FKeys
[KEY_JUMP
].Pressed
then Jump()
5098 if AnyServer
and FJetpack
then
5102 if NetServer
then MH_SEND_PlayerStats(FUID
);
5104 FCanJetpack
:= True;
5111 for k
:= Low(FKeys
) to KEY_CHAT
-1 do
5113 if FKeys
[k
].Pressed
then
5121 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
5124 if (FTime
[T_RESPAWN
] <= gTime
) and
5125 gGameOn
and (not FAlive
) then
5127 if (g_Player_GetCount() > 1) then
5131 gExit
:= EXIT_RESTART
;
5136 // Dead spectator actions
5139 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Fire();
5140 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then
5144 if (FSpectatePlayer
>= High(gPlayers
)) then
5145 FSpectatePlayer
:= -1
5149 for I
:= FSpectatePlayer
+ 1 to High(gPlayers
) do
5150 if gPlayers
[I
] <> nil then
5151 if gPlayers
[I
].alive
then
5152 if gPlayers
[I
].UID
<> FUID
then
5154 FSpectatePlayer
:= I
;
5159 if not SetSpect
then FSpectatePlayer
:= -1;
5170 if FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_JUMP
].Pressed
then
5172 FYTo
:= FObj
.Y
- 32;
5173 FSpectatePlayer
:= -1;
5175 if FKeys
[KEY_DOWN
].Pressed
then
5177 FYTo
:= FObj
.Y
+ 32;
5178 FSpectatePlayer
:= -1;
5180 if FKeys
[KEY_LEFT
].Pressed
then
5182 FXTo
:= FObj
.X
- 32;
5183 FSpectatePlayer
:= -1;
5185 if FKeys
[KEY_RIGHT
].Pressed
then
5187 FXTo
:= FObj
.X
+ 32;
5188 FSpectatePlayer
:= -1;
5191 if (FXTo
< -64) then
5193 else if (FXTo
> gMapInfo
.Width
+ 32) then
5194 FXTo
:= gMapInfo
.Width
+ 32;
5195 if (FYTo
< -72) then
5197 else if (FYTo
> gMapInfo
.Height
+ 32) then
5198 FYTo
:= gMapInfo
.Height
+ 32;
5203 g_Obj_Move(@FObj
, True, True, True);
5204 positionChanged(); // this updates spatial accelerators
5211 if (FSpectatePlayer
<= High(gPlayers
)) and (FSpectatePlayer
>= 0) then
5212 if gPlayers
[FSpectatePlayer
] <> nil then
5213 if gPlayers
[FSpectatePlayer
].alive
then
5215 FXTo
:= gPlayers
[FSpectatePlayer
].GameX
;
5216 FYTo
:= gPlayers
[FSpectatePlayer
].GameY
;
5220 blockmon
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
, FObj
.Y
+PLAYER_HEADRECT
.Y
,
5221 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
5222 PANEL_BLOCKMON
, True);
5223 headwater
:= HeadInLiquid(0, 0);
5225 // Ñîïðîòèâëåíèå âîçäóõà:
5226 if (not FAlive
) or not (FKeys
[KEY_LEFT
].Pressed
or FKeys
[KEY_RIGHT
].Pressed
) then
5227 if FObj
.Vel
.X
<> 0 then
5228 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
5230 if (FLastHit
= HIT_TRAP
) and (FPain
> 90) then FPain
:= 90;
5231 DecMin(FPain
, 5, 0);
5232 DecMin(FPickup
, 1, 0);
5234 if FAlive
and (FObj
.Y
> Integer(gMapInfo
.Height
)+128) and AnyServer
then
5236 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
5237 FMegaRulez
[MR_SUIT
] := 0;
5238 FMegaRulez
[MR_INVUL
] := 0;
5239 FMegaRulez
[MR_INVIS
] := 0;
5240 Kill(K_FALLKILL
, 0, HIT_FALL
);
5247 if FCurrWeap
= WEAPON_SAW
then
5248 if not (FSawSound
.IsPlaying() or FSawSoundHit
.IsPlaying() or
5249 FSawSoundSelect
.IsPlaying()) then
5250 FSawSoundIdle
.PlayAt(FObj
.X
, FObj
.Y
);
5253 if (not FJetSoundFly
.IsPlaying()) and (not FJetSoundOn
.IsPlaying()) and
5254 (not FJetSoundOff
.IsPlaying()) then
5256 FJetSoundFly
.SetPosition(0);
5257 FJetSoundFly
.PlayAt(FObj
.X
, FObj
.Y
);
5260 for b
:= WP_FIRST
to WP_LAST
do
5261 if FReloading
[b
] > 0 then
5267 if FShellTimer
> -1 then
5268 if FShellTimer
= 0 then
5270 if FShellType
= SHELL_SHELL
then
5271 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5272 GameVelX
, GameVelY
-2, SHELL_SHELL
)
5273 else if FShellType
= SHELL_DBLSHELL
then
5275 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5276 GameVelX
+1, GameVelY
-2, SHELL_SHELL
);
5277 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5278 GameVelX
-1, GameVelY
-2, SHELL_SHELL
);
5281 end else Dec(FShellTimer
);
5283 if (FBFGFireCounter
> -1) then
5284 if FBFGFireCounter
= 0 then
5288 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
5289 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
5290 xd
:= wx
+IfThen(FDirection
= TDirection
.D_LEFT
, -30, 30);
5291 yd
:= wy
+firediry();
5292 g_Weapon_bfgshot(wx
, wy
, xd
, yd
, FUID
);
5293 if NetServer
then MH_SEND_PlayerFire(FUID
, WEAPON_BFG
, wx
, wy
, xd
, yd
);
5294 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
5295 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
5296 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
5299 FReloading
[WEAPON_BFG
] := WEAPON_RELOAD
[WEAPON_BFG
];
5300 FBFGFireCounter
:= -1;
5303 FBFGFireCounter
:= 0
5305 Dec(FBFGFireCounter
);
5307 if (FMegaRulez
[MR_SUIT
] < gTime
) and AnyServer
then
5309 b
:= g_GetAcidHit(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
);
5311 if (b
> 0) and (gTime
mod (15*GAME_TICK
) = 0) then Damage(b
, 0, 0, 0, HIT_ACID
);
5314 if (headwater
or blockmon
) then
5320 if AnyServer
then Damage(10, 0, 0, 0, HIT_WATER
);
5323 else if (FAir
mod 31 = 0) and not blockmon
then
5325 g_GFX_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2), FObj
.Y
+PLAYER_RECT
.Y
-4, 5+Random(6), 8, 4);
5326 if Random(2) = 0 then
5327 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
5329 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
5331 end else if FAir
< AIR_DEF
then
5334 if FFireTime
> 0 then
5336 if BodyInLiquid(0, 0) then
5341 else if FMegaRulez
[MR_SUIT
] >= gTime
then
5343 if FMegaRulez
[MR_SUIT
] = gTime
then
5350 if FFirePainTime
<= 0 then
5352 if g_Game_IsServer
then
5353 Damage(2, FFireAttacker
, 0, 0, HIT_FLAME
);
5354 FFirePainTime
:= 12 - FFireTime
div 12;
5356 FFirePainTime
:= FFirePainTime
- 1;
5357 FFireTime
:= FFireTime
- 1;
5358 if ((FFireTime
mod 33) = 0) and (FMegaRulez
[MR_INVUL
] < gTime
) then
5359 FModel
.PlaySound(MODELSOUND_PAIN
, 1, FObj
.X
, FObj
.Y
);
5360 if (FFireTime
= 0) and g_Game_IsNet
and g_Game_IsServer
then
5361 MH_SEND_PlayerStats(FUID
);
5365 if FDamageBuffer
> 0 then
5367 if FDamageBuffer
>= 9 then
5371 if FDamageBuffer
< 30 then i
:= 9
5372 else if FDamageBuffer
< 100 then i
:= 18
5376 ii
:= Round(FDamageBuffer
*FHealth
/ nonz(FArmor
*(3/4)+FHealth
));
5377 FArmor
:= FArmor
-(FDamageBuffer
-ii
);
5378 FHealth
:= FHealth
-ii
;
5381 FHealth
:= FHealth
+FArmor
;
5386 if FHealth
<= 0 then
5387 if FHealth
> -30 then Kill(K_SIMPLEKILL
, FLastSpawnerUID
, FLastHit
)
5388 else if FHealth
> -50 then Kill(K_HARDKILL
, FLastSpawnerUID
, FLastHit
)
5389 else Kill(K_EXTRAHARDKILL
, FLastSpawnerUID
, FLastHit
);
5391 if FAlive
and ((FLastHit
<> HIT_FLAME
) or (FFireTime
<= 0)) then
5393 if FDamageBuffer
<= 20 then FModel
.PlaySound(MODELSOUND_PAIN
, 1, FObj
.X
, FObj
.Y
)
5394 else if FDamageBuffer
<= 55 then FModel
.PlaySound(MODELSOUND_PAIN
, 2, FObj
.X
, FObj
.Y
)
5395 else if FDamageBuffer
<= 120 then FModel
.PlaySound(MODELSOUND_PAIN
, 3, FObj
.X
, FObj
.Y
)
5396 else FModel
.PlaySound(MODELSOUND_PAIN
, 4, FObj
.X
, FObj
.Y
);
5403 end; // if FAlive then ...
5405 if (FActionAnim
= A_PAIN
) and (FModel
.Animation
<> A_PAIN
) then
5407 FModel
.ChangeAnimation(FActionAnim
, FActionForce
);
5408 FModel
.GetCurrentAnimation
.MinLength
:= i
;
5409 FModel
.GetCurrentAnimationMask
.MinLength
:= i
;
5410 end else FModel
.ChangeAnimation(FActionAnim
, FActionForce
and (FModel
.Animation
<> A_STAND
));
5412 if (FModel
.GetCurrentAnimation
.Played
or ((not FActionChanged
) and (FModel
.Animation
= A_WALK
)))
5413 then SetAction(A_STAND
, True);
5415 if not ((FModel
.Animation
= A_WALK
) and (Abs(FObj
.Vel
.X
) < 4) and not FModel
.Fire
) then FModel
.Update
;
5417 for b
:= Low(FKeys
) to High(FKeys
) do
5418 if FKeys
[b
].Time
= 0 then FKeys
[b
].Pressed
:= False else Dec(FKeys
[b
].Time
);
5422 procedure TPlayer
.getMapBox (out x
, y
, w
, h
: Integer); inline;
5424 x
:= FObj
.X
+PLAYER_RECT
.X
;
5425 y
:= FObj
.Y
+PLAYER_RECT
.Y
;
5426 w
:= PLAYER_RECT
.Width
;
5427 h
:= PLAYER_RECT
.Height
;
5431 procedure TPlayer
.moveBy (dx
, dy
: Integer); inline;
5433 if (dx
<> 0) or (dy
<> 0) then
5442 function TPlayer
.Collide(X
, Y
: Integer; Width
, Height
: Word): Boolean;
5444 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
5445 FObj
.Y
+PLAYER_RECT
.Y
,
5452 function TPlayer
.Collide(Panel
: TPanel
): Boolean;
5454 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
5455 FObj
.Y
+PLAYER_RECT
.Y
,
5459 Panel
.Width
, Panel
.Height
);
5462 function TPlayer
.Collide(X
, Y
: Integer): Boolean;
5464 X
:= X
-FObj
.X
-PLAYER_RECT
.X
;
5465 Y
:= Y
-FObj
.Y
-PLAYER_RECT
.Y
;
5466 Result
:= (x
>= 0) and (x
<= PLAYER_RECT
.Width
) and
5467 (y
>= 0) and (y
<= PLAYER_RECT
.Height
);
5470 function g_Player_ValidName(Name
: string): Boolean;
5476 if gPlayers
= nil then Exit
;
5478 for a
:= 0 to High(gPlayers
) do
5479 if gPlayers
[a
] <> nil then
5480 if LowerCase(Name
) = LowerCase(gPlayers
[a
].FName
) then
5487 procedure TPlayer
.SetDirection(Direction
: TDirection
);
5491 d
:= FModel
.Direction
;
5493 FModel
.Direction
:= Direction
;
5494 if d
<> Direction
then FModel
.ChangeAnimation(FModel
.Animation
, True);
5496 FDirection
:= Direction
;
5499 function TPlayer
.GetKeys(): Byte;
5503 if R_KEY_RED
in FRulez
then Result
:= KEY_RED
;
5504 if R_KEY_GREEN
in FRulez
then Result
:= Result
or KEY_GREEN
;
5505 if R_KEY_BLUE
in FRulez
then Result
:= Result
or KEY_BLUE
;
5507 if FTeam
= TEAM_RED
then Result
:= Result
or KEY_REDTEAM
;
5508 if FTeam
= TEAM_BLUE
then Result
:= Result
or KEY_BLUETEAM
;
5511 procedure TPlayer
.Use();
5515 if FTime
[T_USE
] > gTime
then Exit
;
5517 g_Triggers_PressR(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
,
5518 PLAYER_RECT
.Height
, FUID
, ACTIVATE_PLAYERPRESS
);
5520 for a
:= 0 to High(gPlayers
) do
5521 if (gPlayers
[a
] <> nil) and (gPlayers
[a
] <> Self
) and
5522 gPlayers
[a
].alive
and SameTeam(FUID
, gPlayers
[a
].FUID
) and
5523 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
5524 FObj
.Rect
.Width
, FObj
.Rect
.Height
, @gPlayers
[a
].FObj
) then
5526 gPlayers
[a
].Touch();
5527 if g_Game_IsNet
and g_Game_IsServer
then
5528 MH_SEND_GameEvent(NET_EV_PLAYER_TOUCH
, gPlayers
[a
].FUID
);
5531 FTime
[T_USE
] := gTime
+120;
5534 procedure TPlayer
.NetFire(Wpn
: Byte; X
, Y
, AX
, AY
: Integer; WID
: Integer = -1);
5538 WX
, WY
, XD
, YD
: Integer;
5550 if R_BERSERK
in FRulez
then
5552 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
5553 locobj
.X
:= FObj
.X
+FObj
.Rect
.X
;
5554 locobj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
5557 locobj
.rect
.Width
:= 39;
5558 locobj
.rect
.Height
:= 52;
5559 locobj
.Vel
.X
:= (xd
-wx
) div 2;
5560 locobj
.Vel
.Y
:= (yd
-wy
) div 2;
5561 locobj
.Accel
.X
:= xd
-wx
;
5562 locobj
.Accel
.y
:= yd
-wy
;
5564 if g_Weapon_Hit(@locobj
, 50, FUID
, HIT_SOME
) <> 0 then
5565 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
5567 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
5571 FPain
:= min(FPain
+ 25, 50);
5573 g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
5578 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
5579 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
5581 FSawSoundSelect
.Stop();
5583 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
5585 else if not FSawSoundHit
.IsPlaying() then
5587 FSawSoundSelect
.Stop();
5588 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
5595 g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', GameX
, Gamey
);
5596 FFireAngle
:= FAngle
;
5598 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5599 GameVelX
, GameVelY
-2, SHELL_BULLET
);
5604 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
5605 FFireAngle
:= FAngle
;
5608 FShellType
:= SHELL_SHELL
;
5613 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN2', Gamex
, Gamey
);
5614 FFireAngle
:= FAngle
;
5617 FShellType
:= SHELL_DBLSHELL
;
5622 g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', Gamex
, Gamey
);
5623 FFireAngle
:= FAngle
;
5625 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5626 GameVelX
, GameVelY
-2, SHELL_BULLET
);
5629 WEAPON_ROCKETLAUNCHER
:
5631 g_Weapon_Rocket(wx
, wy
, xd
, yd
, FUID
, WID
);
5632 FFireAngle
:= FAngle
;
5638 g_Weapon_Plasma(wx
, wy
, xd
, yd
, FUID
, WID
);
5639 FFireAngle
:= FAngle
;
5645 g_Weapon_BFGShot(wx
, wy
, xd
, yd
, FUID
, WID
);
5646 FFireAngle
:= FAngle
;
5650 WEAPON_SUPERPULEMET
:
5652 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
5653 FFireAngle
:= FAngle
;
5655 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5656 GameVelX
, GameVelY
-2, SHELL_SHELL
);
5659 WEAPON_FLAMETHROWER
:
5661 g_Weapon_flame(wx
, wy
, xd
, yd
, FUID
, WID
);
5663 FFireAngle
:= FAngle
;
5670 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
5671 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
5672 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
5675 procedure TPlayer
.DoLerp(Level
: Integer = 2);
5677 if FObj
.X
<> FXTo
then FObj
.X
:= Lerp(FObj
.X
, FXTo
, Level
);
5678 if FObj
.Y
<> FYTo
then FObj
.Y
:= Lerp(FObj
.Y
, FYTo
, Level
);
5681 procedure TPlayer
.SetLerp(XTo
, YTo
: Integer);
5687 if FJustTeleported
or (NetInterpLevel
< 1) then
5691 if FJustTeleported
then
5693 FObj
.oldX
:= FObj
.X
;
5694 FObj
.oldY
:= FObj
.Y
;
5699 AX
:= Abs(FXTo
- FObj
.X
);
5700 AY
:= Abs(FYTo
- FObj
.Y
);
5701 if (AX
> 32) or (AX
<= NetInterpLevel
) then
5703 if (AY
> 32) or (AY
<= NetInterpLevel
) then
5708 function TPlayer
.FullInLift(XInc
, YInc
: Integer): Integer;
5710 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5711 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5712 PANEL_LIFTUP
, False) then Result
:= -1
5714 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5715 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5716 PANEL_LIFTDOWN
, False) then Result
:= 1
5720 function TPlayer
.GetFlag(Flag
: Byte): Boolean;
5727 if Flag
= FLAG_NONE
then
5730 if not g_Game_IsServer
then Exit
;
5732 // Ïðèíåñ ÷óæîé ôëàã íà ñâîþ áàçó:
5733 if (Flag
= FTeam
) and
5734 (gFlags
[Flag
].State
= FLAG_STATE_NORMAL
) and
5735 (FFlag
<> FLAG_NONE
) then
5737 if FFlag
= FLAG_RED
then
5738 s
:= _lc
[I_PLAYER_FLAG_RED
]
5740 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5742 evtype
:= FLAG_STATE_SCORED
;
5744 ts
:= Format('%.4d', [gFlags
[FFlag
].CaptureTime
]);
5745 Insert('.', ts
, Length(ts
) + 1 - 3);
5746 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_CAPTURE
], [FName
, s
, ts
]), True);
5748 g_Map_ResetFlag(FFlag
);
5749 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_CAPTURE
], [AnsiUpperCase(s
)]), 144);
5751 if ((Self
= gPlayer1
) or (Self
= gPlayer2
)
5752 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= FTeam
))
5753 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= FTeam
))) then
5758 if not sound_cap_flag
[a
].IsPlaying() then
5759 sound_cap_flag
[a
].Play();
5761 gTeamStat
[FTeam
].Goals
:= gTeamStat
[FTeam
].Goals
+ 1;
5764 if g_Game_IsNet
then
5766 MH_SEND_FlagEvent(evtype
, FFlag
, FUID
, False);
5770 gFlags
[FFlag
].CaptureTime
:= 0;
5775 // Ïîäîáðàë ñâîé ôëàã - âåðíóë åãî íà áàçó:
5776 if (Flag
= FTeam
) and
5777 (gFlags
[Flag
].State
= FLAG_STATE_DROPPED
) then
5779 if Flag
= FLAG_RED
then
5780 s
:= _lc
[I_PLAYER_FLAG_RED
]
5782 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5784 evtype
:= FLAG_STATE_RETURNED
;
5785 gFlags
[Flag
].CaptureTime
:= 0;
5787 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_RETURN
], [FName
, s
]), True);
5789 g_Map_ResetFlag(Flag
);
5790 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
5792 if ((Self
= gPlayer1
) or (Self
= gPlayer2
)
5793 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= FTeam
))
5794 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= FTeam
))) then
5799 if not sound_ret_flag
[a
].IsPlaying() then
5800 sound_ret_flag
[a
].Play();
5803 if g_Game_IsNet
then
5805 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5811 // Ïîäîáðàë ÷óæîé ôëàã:
5812 if (Flag
<> FTeam
) and (FTime
[T_FLAGCAP
] <= gTime
) then
5816 if Flag
= FLAG_RED
then
5817 s
:= _lc
[I_PLAYER_FLAG_RED
]
5819 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5821 evtype
:= FLAG_STATE_CAPTURED
;
5823 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_GET
], [FName
, s
]), True);
5825 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_GET
], [AnsiUpperCase(s
)]), 144);
5827 gFlags
[Flag
].State
:= FLAG_STATE_CAPTURED
;
5829 if ((Self
= gPlayer1
) or (Self
= gPlayer2
)
5830 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= FTeam
))
5831 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= FTeam
))) then
5836 if not sound_get_flag
[a
].IsPlaying() then
5837 sound_get_flag
[a
].Play();
5840 if g_Game_IsNet
then
5842 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5848 procedure TPlayer
.SetFlag(Flag
: Byte);
5851 if FModel
<> nil then
5852 FModel
.SetFlag(FFlag
);
5855 function TPlayer
.TryDropFlag(): Boolean;
5857 if LongBool(gGameSettings
.Options
and GAME_OPTION_ALLOWDROPFLAG
) then
5858 Result
:= DropFlag(False, LongBool(gGameSettings
.Options
and GAME_OPTION_THROWFLAG
))
5863 function TPlayer
.DropFlag(Silent
: Boolean = True; DoThrow
: Boolean = False): Boolean;
5870 if (not g_Game_IsServer
) or (FFlag
= FLAG_NONE
) then
5872 FTime
[T_FLAGCAP
] := gTime
+ 2000;
5873 with gFlags
[FFlag
] do
5877 Direction
:= FDirection
;
5878 State
:= FLAG_STATE_DROPPED
;
5882 xv
:= FObj
.Vel
.X
+ IfThen(Direction
= TDirection
.D_RIGHT
, 10, -10);
5883 yv
:= FObj
.Vel
.Y
- 2;
5887 xv
:= (FObj
.Vel
.X
div 2);
5888 yv
:= (FObj
.Vel
.Y
div 2) - 2;
5890 g_Obj_Push(@Obj
, xv
, yv
);
5892 positionChanged(); // this updates spatial accelerators
5894 if FFlag
= FLAG_RED
then
5895 s
:= _lc
[I_PLAYER_FLAG_RED
]
5897 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5899 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_DROP
], [FName
, s
]), True);
5900 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_DROP
], [AnsiUpperCase(s
)]), 144);
5902 if ((Self
= gPlayer1
) or (Self
= gPlayer2
)
5903 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= FTeam
))
5904 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= FTeam
))) then
5909 if (not Silent
) and (not sound_lost_flag
[a
].IsPlaying()) then
5910 sound_lost_flag
[a
].Play();
5912 if g_Game_IsNet
then
5913 MH_SEND_FlagEvent(FLAG_STATE_DROPPED
, Flag
, FUID
, False);
5919 procedure TPlayer
.GetSecret();
5921 if (self
= gPlayer1
) or (self
= gPlayer2
) then
5923 g_Console_Add(Format(_lc
[I_PLAYER_SECRET
], [FName
]), True);
5924 g_Sound_PlayEx('SOUND_GAME_SECRET');
5929 procedure TPlayer
.PressKey(Key
: Byte; Time
: Word = 1);
5931 Assert(Key
<= High(FKeys
));
5933 FKeys
[Key
].Pressed
:= True;
5934 FKeys
[Key
].Time
:= Time
;
5937 function TPlayer
.IsKeyPressed(K
: Byte): Boolean;
5939 Result
:= FKeys
[K
].Pressed
;
5942 procedure TPlayer
.ReleaseKeys();
5946 for a
:= Low(FKeys
) to High(FKeys
) do
5948 FKeys
[a
].Pressed
:= False;
5953 procedure TPlayer
.OnDamage(Angle
: SmallInt);
5957 function TPlayer
.firediry(): Integer;
5959 if FKeys
[KEY_UP
].Pressed
then Result
:= -42
5960 else if FKeys
[KEY_DOWN
].Pressed
then Result
:= 19
5964 procedure TPlayer
.RememberState();
5967 SavedState
: TPlayerSavedState
;
5969 SavedState
.Health
:= FHealth
;
5970 SavedState
.Armor
:= FArmor
;
5971 SavedState
.Air
:= FAir
;
5972 SavedState
.JetFuel
:= FJetFuel
;
5973 SavedState
.CurrWeap
:= FCurrWeap
;
5974 SavedState
.NextWeap
:= FNextWeap
;
5975 SavedState
.NextWeapDelay
:= FNextWeapDelay
;
5976 for i
:= Low(FWeapon
) to High(FWeapon
) do
5977 SavedState
.Weapon
[i
] := FWeapon
[i
];
5978 for i
:= Low(FAmmo
) to High(FAmmo
) do
5979 SavedState
.Ammo
[i
] := FAmmo
[i
];
5980 for i
:= Low(FMaxAmmo
) to High(FMaxAmmo
) do
5981 SavedState
.MaxAmmo
[i
] := FMaxAmmo
[i
];
5982 SavedState
.Rulez
:= FRulez
- [R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
];
5984 FSavedStateNum
:= -1;
5985 for i
:= Low(SavedStates
) to High(SavedStates
) do
5986 if not SavedStates
[i
].Used
then
5988 FSavedStateNum
:= i
;
5991 if FSavedStateNum
< 0 then
5993 SetLength(SavedStates
, Length(SavedStates
) + 1);
5994 FSavedStateNum
:= High(SavedStates
);
5997 SavedState
.Used
:= True;
5998 SavedStates
[FSavedStateNum
] := SavedState
;
6001 procedure TPlayer
.RecallState();
6004 SavedState
: TPlayerSavedState
;
6006 if(FSavedStateNum
< 0) or (FSavedStateNum
> High(SavedStates
)) then
6009 SavedState
:= SavedStates
[FSavedStateNum
];
6010 SavedStates
[FSavedStateNum
].Used
:= False;
6011 FSavedStateNum
:= -1;
6013 FHealth
:= SavedState
.Health
;
6014 FArmor
:= SavedState
.Armor
;
6015 FAir
:= SavedState
.Air
;
6016 FJetFuel
:= SavedState
.JetFuel
;
6017 FCurrWeap
:= SavedState
.CurrWeap
;
6018 FNextWeap
:= SavedState
.NextWeap
;
6019 FNextWeapDelay
:= SavedState
.NextWeapDelay
;
6020 for i
:= Low(FWeapon
) to High(FWeapon
) do
6021 FWeapon
[i
] := SavedState
.Weapon
[i
];
6022 for i
:= Low(FAmmo
) to High(FAmmo
) do
6023 FAmmo
[i
] := SavedState
.Ammo
[i
];
6024 for i
:= Low(FMaxAmmo
) to High(FMaxAmmo
) do
6025 FMaxAmmo
[i
] := SavedState
.MaxAmmo
[i
];
6026 FRulez
:= SavedState
.Rulez
;
6028 if gGameSettings
.GameType
= GT_SERVER
then
6029 MH_SEND_PlayerStats(FUID
);
6032 procedure TPlayer
.SaveState (st
: TStream
);
6038 utils
.writeSign(st
, 'PLYR');
6039 utils
.writeInt(st
, Byte(PLR_SAVE_VERSION
)); // version
6041 utils
.writeBool(st
, FIamBot
);
6043 utils
.writeInt(st
, Word(FUID
));
6045 utils
.writeStr(st
, FName
);
6047 utils
.writeInt(st
, Byte(FTeam
));
6049 utils
.writeBool(st
, FAlive
);
6050 // Èçðàñõîäîâàë ëè âñå æèçíè
6051 utils
.writeBool(st
, FNoRespawn
);
6053 if FDirection
= TDirection
.D_LEFT
then b
:= 1 else b
:= 2; // D_RIGHT
6054 utils
.writeInt(st
, Byte(b
));
6056 utils
.writeInt(st
, LongInt(FHealth
));
6057 // Êîýôôèöèåíò èíâàëèäíîñòè
6058 utils
.writeInt(st
, LongInt(FHandicap
));
6060 utils
.writeInt(st
, Byte(FLives
));
6062 utils
.writeInt(st
, LongInt(FArmor
));
6064 utils
.writeInt(st
, LongInt(FAir
));
6066 utils
.writeInt(st
, LongInt(FJetFuel
));
6068 utils
.writeInt(st
, LongInt(FPain
));
6070 utils
.writeInt(st
, LongInt(FKills
));
6072 utils
.writeInt(st
, LongInt(FMonsterKills
));
6074 utils
.writeInt(st
, LongInt(FFrags
));
6076 utils
.writeInt(st
, Byte(FFragCombo
));
6077 // Âðåìÿ ïîñëåäíåãî ôðàãà
6078 utils
.writeInt(st
, LongWord(FLastFrag
));
6080 utils
.writeInt(st
, LongInt(FDeath
));
6082 utils
.writeInt(st
, Byte(FFlag
));
6084 utils
.writeInt(st
, LongInt(FSecrets
));
6086 utils
.writeInt(st
, Byte(FCurrWeap
));
6088 utils
.writeInt(st
, Word(FNextWeap
));
6090 utils
.writeInt(st
, Byte(FNextWeapDelay
));
6091 // Âðåìÿ çàðÿäêè BFG
6092 utils
.writeInt(st
, SmallInt(FBFGFireCounter
));
6094 utils
.writeInt(st
, LongInt(FDamageBuffer
));
6095 // Ïîñëåäíèé óäàðèâøèé
6096 utils
.writeInt(st
, Word(FLastSpawnerUID
));
6097 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà
6098 utils
.writeInt(st
, Byte(FLastHit
));
6100 Obj_SaveState(st
, @FObj
);
6101 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ
6102 for i
:= A_BULLETS
to A_HIGH
do utils
.writeInt(st
, Word(FAmmo
[i
]));
6103 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ
6104 for i
:= A_BULLETS
to A_HIGH
do utils
.writeInt(st
, Word(FMaxAmmo
[i
]));
6106 for i
:= WP_FIRST
to WP_LAST
do utils
.writeBool(st
, FWeapon
[i
]);
6107 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ
6108 for i
:= WP_FIRST
to WP_LAST
do utils
.writeInt(st
, Word(FReloading
[i
]));
6110 utils
.writeBool(st
, (R_ITEM_BACKPACK
in FRulez
));
6111 // Íàëè÷èå êðàñíîãî êëþ÷à
6112 utils
.writeBool(st
, (R_KEY_RED
in FRulez
));
6113 // Íàëè÷èå çåëåíîãî êëþ÷à
6114 utils
.writeBool(st
, (R_KEY_GREEN
in FRulez
));
6115 // Íàëè÷èå ñèíåãî êëþ÷à
6116 utils
.writeBool(st
, (R_KEY_BLUE
in FRulez
));
6118 utils
.writeBool(st
, (R_BERSERK
in FRulez
));
6119 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ
6120 for i
:= MR_SUIT
to MR_MAX
do utils
.writeInt(st
, LongWord(FMegaRulez
[i
]));
6121 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà
6122 for i
:= T_RESPAWN
to T_FLAGCAP
do utils
.writeInt(st
, LongWord(FTime
[i
]));
6124 utils
.writeStr(st
, FModel
.Name
);
6126 utils
.writeInt(st
, Byte(FColor
.R
));
6127 utils
.writeInt(st
, Byte(FColor
.G
));
6128 utils
.writeInt(st
, Byte(FColor
.B
));
6132 procedure TPlayer
.LoadState (st
: TStream
);
6141 if not utils
.checkSign(st
, 'PLYR') then raise XStreamError
.Create('invalid player signature');
6142 if (utils
.readByte(st
) <> PLR_SAVE_VERSION
) then raise XStreamError
.Create('invalid player version');
6144 FIamBot
:= utils
.readBool(st
);
6146 FUID
:= utils
.readWord(st
);
6148 str
:= utils
.readStr(st
);
6149 if (self
<> gPlayer1
) and (self
<> gPlayer2
) then FName
:= str
;
6151 FTeam
:= utils
.readByte(st
);
6153 FAlive
:= utils
.readBool(st
);
6154 // Èçðàñõîäîâàë ëè âñå æèçíè
6155 FNoRespawn
:= utils
.readBool(st
);
6157 b
:= utils
.readByte(st
);
6158 if b
= 1 then FDirection
:= TDirection
.D_LEFT
else FDirection
:= TDirection
.D_RIGHT
; // b = 2
6160 FHealth
:= utils
.readLongInt(st
);
6161 // Êîýôôèöèåíò èíâàëèäíîñòè
6162 FHandicap
:= utils
.readLongInt(st
);
6164 FLives
:= utils
.readByte(st
);
6166 FArmor
:= utils
.readLongInt(st
);
6168 FAir
:= utils
.readLongInt(st
);
6170 FJetFuel
:= utils
.readLongInt(st
);
6172 FPain
:= utils
.readLongInt(st
);
6174 FKills
:= utils
.readLongInt(st
);
6176 FMonsterKills
:= utils
.readLongInt(st
);
6178 FFrags
:= utils
.readLongInt(st
);
6180 FFragCombo
:= utils
.readByte(st
);
6181 // Âðåìÿ ïîñëåäíåãî ôðàãà
6182 FLastFrag
:= utils
.readLongWord(st
);
6184 FDeath
:= utils
.readLongInt(st
);
6186 FFlag
:= utils
.readByte(st
);
6188 FSecrets
:= utils
.readLongInt(st
);
6190 FCurrWeap
:= utils
.readByte(st
);
6192 FNextWeap
:= utils
.readWord(st
);
6194 FNextWeapDelay
:= utils
.readByte(st
);
6195 // Âðåìÿ çàðÿäêè BFG
6196 FBFGFireCounter
:= utils
.readSmallInt(st
);
6198 FDamageBuffer
:= utils
.readLongInt(st
);
6199 // Ïîñëåäíèé óäàðèâøèé
6200 FLastSpawnerUID
:= utils
.readWord(st
);
6201 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà
6202 FLastHit
:= utils
.readByte(st
);
6204 Obj_LoadState(@FObj
, st
);
6205 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ
6206 for i
:= A_BULLETS
to A_HIGH
do FAmmo
[i
] := utils
.readWord(st
);
6207 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ
6208 for i
:= A_BULLETS
to A_HIGH
do FMaxAmmo
[i
] := utils
.readWord(st
);
6210 for i
:= WP_FIRST
to WP_LAST
do FWeapon
[i
] := utils
.readBool(st
);
6211 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ
6212 for i
:= WP_FIRST
to WP_LAST
do FReloading
[i
] := utils
.readWord(st
);
6214 if utils
.readBool(st
) then Include(FRulez
, R_ITEM_BACKPACK
);
6215 // Íàëè÷èå êðàñíîãî êëþ÷à
6216 if utils
.readBool(st
) then Include(FRulez
, R_KEY_RED
);
6217 // Íàëè÷èå çåëåíîãî êëþ÷à
6218 if utils
.readBool(st
) then Include(FRulez
, R_KEY_GREEN
);
6219 // Íàëè÷èå ñèíåãî êëþ÷à
6220 if utils
.readBool(st
) then Include(FRulez
, R_KEY_BLUE
);
6222 if utils
.readBool(st
) then Include(FRulez
, R_BERSERK
);
6223 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ
6224 for i
:= MR_SUIT
to MR_MAX
do FMegaRulez
[i
] := utils
.readLongWord(st
);
6225 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà
6226 for i
:= T_RESPAWN
to T_FLAGCAP
do FTime
[i
] := utils
.readLongWord(st
);
6228 str
:= utils
.readStr(st
);
6230 FColor
.R
:= utils
.readByte(st
);
6231 FColor
.G
:= utils
.readByte(st
);
6232 FColor
.B
:= utils
.readByte(st
);
6233 if (self
= gPlayer1
) then
6235 str
:= gPlayer1Settings
.Model
;
6236 FColor
:= gPlayer1Settings
.Color
;
6238 else if (self
= gPlayer2
) then
6240 str
:= gPlayer2Settings
.Model
;
6241 FColor
:= gPlayer2Settings
.Color
;
6243 // Îáíîâëÿåì ìîäåëü èãðîêà
6245 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
6246 FModel
.Color
:= TEAMCOLOR
[FTeam
]
6248 FModel
.Color
:= FColor
;
6252 procedure TPlayer
.AllRulez(Health
: Boolean);
6258 FHealth
:= PLAYER_HP_LIMIT
;
6259 FArmor
:= PLAYER_AP_LIMIT
;
6263 for a
:= WP_FIRST
to WP_LAST
do FWeapon
[a
] := True;
6264 for a
:= A_BULLETS
to A_HIGH
do FAmmo
[a
] := 30000;
6265 FRulez
:= FRulez
+[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
];
6268 procedure TPlayer
.RestoreHealthArmor();
6270 FHealth
:= PLAYER_HP_LIMIT
;
6271 FArmor
:= PLAYER_AP_LIMIT
;
6274 procedure TPlayer
.FragCombo();
6278 if (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) or g_Game_IsClient
then
6280 if gTime
- FLastFrag
< FRAG_COMBO_TIME
then
6282 if FFragCombo
< 5 then
6284 Param
:= FUID
or (FFragCombo
shl 16);
6285 if (FComboEvnt
>= Low(gDelayedEvents
)) and
6286 (FComboEvnt
<= High(gDelayedEvents
)) and
6287 gDelayedEvents
[FComboEvnt
].Pending
and
6288 (gDelayedEvents
[FComboEvnt
].DEType
= DE_KILLCOMBO
) and
6289 (gDelayedEvents
[FComboEvnt
].DENum
and $FFFF = FUID
) then
6291 gDelayedEvents
[FComboEvnt
].Time
:= gTime
+ 500;
6292 gDelayedEvents
[FComboEvnt
].DENum
:= Param
;
6295 FComboEvnt
:= g_Game_DelayEvent(DE_KILLCOMBO
, 500, Param
);
6303 procedure TPlayer
.GiveItem(ItemType
: Byte);
6307 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
6309 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
6313 if FAir
< AIR_MAX
then
6320 if not (R_BERSERK
in FRulez
) then
6322 Include(FRulez
, R_BERSERK
);
6323 if FBFGFireCounter
< 1 then
6325 FCurrWeap
:= WEAPON_KASTET
;
6327 FModel
.SetWeapon(WEAPON_KASTET
);
6331 FBerserk
:= gTime
+30000;
6333 if FHealth
< PLAYER_HP_SOFT
then
6335 FHealth
:= PLAYER_HP_SOFT
;
6336 FBerserk
:= gTime
+30000;
6341 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
6343 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
6348 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
6350 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
6354 if FJetFuel
< JET_MAX
then
6356 FJetFuel
:= JET_MAX
;
6359 ITEM_MEDKIT_SMALL
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
6360 ITEM_MEDKIT_LARGE
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
6362 ITEM_ARMOR_GREEN
: if FArmor
< PLAYER_AP_SOFT
then FArmor
:= PLAYER_AP_SOFT
;
6363 ITEM_ARMOR_BLUE
: if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
6365 ITEM_SPHERE_BLUE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
6367 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) then
6369 if FHealth
< PLAYER_HP_LIMIT
then FHealth
:= PLAYER_HP_LIMIT
;
6370 if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
6373 ITEM_WEAPON_SAW
: FWeapon
[WEAPON_SAW
] := True;
6374 ITEM_WEAPON_SHOTGUN1
: FWeapon
[WEAPON_SHOTGUN1
] := True;
6375 ITEM_WEAPON_SHOTGUN2
: FWeapon
[WEAPON_SHOTGUN2
] := True;
6376 ITEM_WEAPON_CHAINGUN
: FWeapon
[WEAPON_CHAINGUN
] := True;
6377 ITEM_WEAPON_ROCKETLAUNCHER
: FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
6378 ITEM_WEAPON_PLASMA
: FWeapon
[WEAPON_PLASMA
] := True;
6379 ITEM_WEAPON_BFG
: FWeapon
[WEAPON_BFG
] := True;
6380 ITEM_WEAPON_SUPERPULEMET
: FWeapon
[WEAPON_SUPERPULEMET
] := True;
6381 ITEM_WEAPON_FLAMETHROWER
: FWeapon
[WEAPON_FLAMETHROWER
] := True;
6383 ITEM_AMMO_BULLETS
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
6384 ITEM_AMMO_BULLETS_BOX
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
6385 ITEM_AMMO_SHELLS
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
6386 ITEM_AMMO_SHELLS_BOX
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
6387 ITEM_AMMO_ROCKET
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
6388 ITEM_AMMO_ROCKET_BOX
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
6389 ITEM_AMMO_CELL
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
6390 ITEM_AMMO_CELL_BIG
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
6391 ITEM_AMMO_FUELCAN
: if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
6394 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
6395 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
6396 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
6397 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or
6398 (FMaxAmmo
[A_FUEL
] < AmmoLimits
[1, A_FUEL
]) then
6400 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[1, A_BULLETS
];
6401 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[1, A_SHELLS
];
6402 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[1, A_ROCKETS
];
6403 FMaxAmmo
[A_CELLS
] := AmmoLimits
[1, A_CELLS
];
6404 FMaxAmmo
[A_FUEL
] := AmmoLimits
[1, A_FUEL
];
6406 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
6407 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
6408 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
6409 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
6411 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
6414 ITEM_KEY_RED
: if not (R_KEY_RED
in FRulez
) then Include(FRulez
, R_KEY_RED
);
6415 ITEM_KEY_GREEN
: if not (R_KEY_GREEN
in FRulez
) then Include(FRulez
, R_KEY_GREEN
);
6416 ITEM_KEY_BLUE
: if not (R_KEY_BLUE
in FRulez
) then Include(FRulez
, R_KEY_BLUE
);
6418 ITEM_BOTTLE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
6419 ITEM_HELMET
: if FArmor
< PLAYER_AP_LIMIT
then IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
6424 if g_Game_IsNet
and g_Game_IsServer
then
6425 MH_SEND_PlayerStats(FUID
);
6428 procedure TPlayer
.FlySmoke(Times
: DWORD
= 1);
6433 if (Random(5) = 1) and (Times
= 1) then
6436 if BodyInLiquid(0, 0) then
6438 g_GFX_Bubbles(Obj
.X
+Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2)+Random(3)-1,
6439 Obj
.Y
+Obj
.Rect
.Height
+8, 1, 8, 4);
6440 if Random(2) = 0 then
6441 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
6443 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
6447 if g_Frames_Get(id
, 'FRAMES_SMOKE') then
6449 for i
:= 1 to Times
do
6451 Anim
:= TAnimation
.Create(id
, False, 3);
6453 g_GFX_OnceAnim(Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(Anim
.Width
div 2),
6454 Obj
.Y
+Obj
.Rect
.Height
-4+Random(8+Times
*2), Anim
, ONCEANIM_SMOKE
);
6460 procedure TPlayer
.OnFireFlame(Times
: DWORD
= 1);
6465 if (Random(10) = 1) and (Times
= 1) then
6468 if g_Frames_Get(id
, 'FRAMES_FLAME') then
6470 for i
:= 1 to Times
do
6472 Anim
:= TAnimation
.Create(id
, False, 3);
6474 g_GFX_OnceAnim(Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(Anim
.Width
div 2),
6475 Obj
.Y
+8+Random(8+Times
*2), Anim
, ONCEANIM_SMOKE
);
6481 procedure TPlayer
.PauseSounds(Enable
: Boolean);
6483 FSawSound
.Pause(Enable
);
6484 FSawSoundIdle
.Pause(Enable
);
6485 FSawSoundHit
.Pause(Enable
);
6486 FSawSoundSelect
.Pause(Enable
);
6487 FFlameSoundOn
.Pause(Enable
);
6488 FFlameSoundOff
.Pause(Enable
);
6489 FFlameSoundWork
.Pause(Enable
);
6490 FJetSoundFly
.Pause(Enable
);
6491 FJetSoundOn
.Pause(Enable
);
6492 FJetSoundOff
.Pause(Enable
);
6497 constructor TCorpse
.Create(X
, Y
: Integer; ModelName
: String; aMess
: Boolean);
6502 FObj
.Rect
:= PLAYER_CORPSERECT
;
6503 FModelName
:= ModelName
;
6508 FState
:= CORPSE_STATE_MESS
;
6509 g_PlayerModel_GetAnim(ModelName
, A_DIE2
, FAnimation
, FAnimationMask
);
6513 FState
:= CORPSE_STATE_NORMAL
;
6514 g_PlayerModel_GetAnim(ModelName
, A_DIE1
, FAnimation
, FAnimationMask
);
6518 destructor TCorpse
.Destroy();
6525 function TCorpse
.ObjPtr (): PObj
; inline; begin result
:= @FObj
; end;
6527 procedure TCorpse
.positionChanged (); inline; begin end;
6529 procedure TCorpse
.moveBy (dx
, dy
: Integer); inline;
6531 if (dx
<> 0) or (dy
<> 0) then
6540 procedure TCorpse
.getMapBox (out x
, y
, w
, h
: Integer); inline;
6542 x
:= FObj
.X
+PLAYER_CORPSERECT
.X
;
6543 y
:= FObj
.Y
+PLAYER_CORPSERECT
.Y
;
6544 w
:= PLAYER_CORPSERECT
.Width
;
6545 h
:= PLAYER_CORPSERECT
.Height
;
6549 procedure TCorpse
.Damage(Value
: Word; SpawnerUID
: Word; vx
, vy
: Integer);
6554 if FState
= CORPSE_STATE_REMOVEME
then
6557 FDamage
:= FDamage
+ Value
;
6559 if FDamage
> 150 then
6561 if FAnimation
<> nil then
6566 FState
:= CORPSE_STATE_REMOVEME
;
6568 g_Player_CreateGibs(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
6569 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2),
6570 FModelName
, FColor
);
6571 // Çâóê ìÿñà îò òðóïà:
6572 pm
:= g_PlayerModel_Get(FModelName
);
6573 pm
.PlaySound(MODELSOUND_DIE
, 5, FObj
.X
, FObj
.Y
);
6577 if (gBodyKillEvent
<> -1)
6578 and gDelayedEvents
[gBodyKillEvent
].Pending
then
6579 gDelayedEvents
[gBodyKillEvent
].Pending
:= False;
6580 gBodyKillEvent
:= g_Game_DelayEvent(DE_BODYKILL
, 1050, SpawnerUID
);
6585 Blood
:= g_PlayerModel_GetBlood(FModelName
);
6586 FObj
.Vel
.X
:= FObj
.Vel
.X
+ vx
;
6587 FObj
.Vel
.Y
:= FObj
.Vel
.Y
+ vy
;
6588 g_GFX_Blood(FObj
.X
+PLAYER_CORPSERECT
.X
+(PLAYER_CORPSERECT
.Width
div 2),
6589 FObj
.Y
+PLAYER_CORPSERECT
.Y
+(PLAYER_CORPSERECT
.Height
div 2),
6590 Value
, vx
, vy
, 16, (PLAYER_CORPSERECT
.Height
*2) div 3,
6591 Blood
.R
, Blood
.G
, Blood
.B
, Blood
.Kind
);
6595 procedure TCorpse
.Draw();
6599 if FState
= CORPSE_STATE_REMOVEME
then
6602 FObj
.lerp(gLerpFactor
, fX
, fY
);
6604 if FAnimation
<> nil then
6605 FAnimation
.Draw(fX
, fY
, TMirrorType
.None
);
6607 if FAnimationMask
<> nil then
6610 FAnimationMask
.Draw(fX
, fY
, TMirrorType
.None
);
6617 procedure TCorpse
.Update();
6621 if FState
= CORPSE_STATE_REMOVEME
then
6624 FObj
.oldX
:= FObj
.X
;
6625 FObj
.oldY
:= FObj
.Y
;
6627 if gTime
mod (GAME_TICK
*2) <> 0 then
6629 g_Obj_Move(@FObj
, True, True, True);
6630 positionChanged(); // this updates spatial accelerators
6634 // Ñîïðîòèâëåíèå âîçäóõà äëÿ òðóïà:
6635 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
6637 st
:= g_Obj_Move(@FObj
, True, True, True);
6638 positionChanged(); // this updates spatial accelerators
6640 if WordBool(st
and MOVE_FALLOUT
) then
6642 FState
:= CORPSE_STATE_REMOVEME
;
6646 if FAnimation
<> nil then
6647 FAnimation
.Update();
6648 if FAnimationMask
<> nil then
6649 FAnimationMask
.Update();
6653 procedure TCorpse
.SaveState (st
: TStream
);
6660 utils
.writeSign(st
, 'CORP');
6661 utils
.writeInt(st
, Byte(0));
6663 utils
.writeInt(st
, Byte(FState
));
6665 utils
.writeInt(st
, Byte(FDamage
));
6667 utils
.writeInt(st
, Byte(FColor
.R
));
6668 utils
.writeInt(st
, Byte(FColor
.G
));
6669 utils
.writeInt(st
, Byte(FColor
.B
));
6671 Obj_SaveState(st
, @FObj
);
6672 utils
.writeInt(st
, Word(FPlayerUID
));
6674 anim
:= (FAnimation
<> nil);
6675 utils
.writeBool(st
, anim
);
6676 // Åñëè åñòü - ñîõðàíÿåì
6677 if anim
then FAnimation
.SaveState(st
);
6678 // Åñòü ëè ìàñêà àíèìàöèè
6679 anim
:= (FAnimationMask
<> nil);
6680 utils
.writeBool(st
, anim
);
6681 // Åñëè åñòü - ñîõðàíÿåì
6682 if anim
then FAnimationMask
.SaveState(st
);
6686 procedure TCorpse
.LoadState (st
: TStream
);
6693 if not utils
.checkSign(st
, 'CORP') then raise XStreamError
.Create('invalid corpse signature');
6694 if (utils
.readByte(st
) <> 0) then raise XStreamError
.Create('invalid corpse version');
6696 FState
:= utils
.readByte(st
);
6698 FDamage
:= utils
.readByte(st
);
6700 FColor
.R
:= utils
.readByte(st
);
6701 FColor
.G
:= utils
.readByte(st
);
6702 FColor
.B
:= utils
.readByte(st
);
6704 Obj_LoadState(@FObj
, st
);
6705 FPlayerUID
:= utils
.readWord(st
);
6707 anim
:= utils
.readBool(st
);
6708 // Åñëè åñòü - çàãðóæàåì
6711 Assert(FAnimation
<> nil, 'TCorpse.LoadState: no FAnimation');
6712 FAnimation
.LoadState(st
);
6714 // Åñòü ëè ìàñêà àíèìàöèè
6715 anim
:= utils
.readBool(st
);
6716 // Åñëè åñòü - çàãðóæàåì
6719 Assert(FAnimationMask
<> nil, 'TCorpse.LoadState: no FAnimationMask');
6720 FAnimationMask
.LoadState(st
);
6726 constructor TBot
.Create();
6733 FSpectator
:= False;
6740 for a
:= WP_FIRST
to WP_LAST
do
6742 FDifficult
.WeaponPrior
[a
] := WEAPON_PRIOR1
[a
];
6743 FDifficult
.CloseWeaponPrior
[a
] := WEAPON_PRIOR2
[a
];
6744 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
6748 destructor TBot
.Destroy();
6751 inherited Destroy();
6754 procedure TBot
.Draw();
6758 //if FTargetUID <> 0 then e_DrawLine(1, FObj.X, FObj.Y, g_Player_Get(FTargetUID).FObj.X,
6759 // g_Player_Get(FTargetUID).FObj.Y, 255, 0, 0);
6762 procedure TBot
.Respawn(Silent
: Boolean; Force
: Boolean = False);
6764 inherited Respawn(Silent
, Force
);
6767 FSelectedWeapon
:= FCurrWeap
;
6772 procedure TBot
.UpdateCombat();
6785 TTargetRecord
= array of TTarget
;
6787 function Compare(a
, b
: TTarget
): Integer;
6789 if a
.Line
and not b
.Line
then // A íà ëèíèè îãíÿ
6792 if not a
.Line
and b
.Line
then // B íà ëèíèè îãíÿ
6794 else // È A, è B íà ëèíèè èëè íå íà ëèíèè îãíÿ
6795 if (a
.Line
and b
.Line
) or ((not a
.Line
) and (not b
.Line
)) then
6797 if a
.Dist
> b
.Dist
then // B áëèæå
6799 else // A áëèæå èëè ðàâíîóäàëåííî ñ B
6802 else // Ñòðàííî -> A
6807 a
, x1
, y1
, x2
, y2
: Integer;
6808 targets
: TTargetRecord
;
6810 Target
, BestTarget
: TTarget
;
6811 firew
, fireh
: Integer;
6815 vsPlayer
, vsMonster
, ok
: Boolean;
6818 function monsUpdate (mon
: TMonster
): Boolean;
6820 result
:= false; // don't stop
6821 if mon
.alive
and (mon
.MonsterType
<> MONSTER_BARREL
) then
6823 if not TargetOnScreen(mon
.Obj
.X
+mon
.Obj
.Rect
.X
, mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
) then exit
;
6825 x2
:= mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2);
6826 y2
:= mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+(mon
.Obj
.Rect
.Height
div 2);
6828 // Åñëè ìîíñòð íà ýêðàíå è íå ïðèêðûò ñòåíîé
6829 if g_TraceVector(x1
, y1
, x2
, y2
) then
6831 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé
6832 SetLength(targets
, Length(targets
)+1);
6833 with targets
[High(targets
)] do
6840 Rect
:= mon
.Obj
.Rect
;
6841 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6842 Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6843 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6852 vsPlayer
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
);
6853 vsMonster
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
);
6855 // Åñëè òåêóùåå îðóæèå íå òî, ÷òî íóæíî, òî ìåíÿåì:
6856 if FCurrWeap
<> FSelectedWeapon
then
6859 // Åñëè íóæíî ñòðåëÿòü è íóæíîå îðóæèå, òî íàæàòü "Ñòðåëÿòü":
6860 if (GetAIFlag('NEEDFIRE') <> '') and (FCurrWeap
= FSelectedWeapon
) then
6862 RemoveAIFlag('NEEDFIRE');
6865 WEAPON_PLASMA
, WEAPON_SUPERPULEMET
, WEAPON_CHAINGUN
: PressKey(KEY_FIRE
, 20);
6866 WEAPON_SAW
, WEAPON_KASTET
, WEAPON_FLAMETHROWER
: PressKey(KEY_FIRE
, 40);
6867 else PressKey(KEY_FIRE
);
6871 // Êîîðäèíàòû ñòâîëà:
6872 x1
:= FObj
.X
+ WEAPONPOINT
[FDirection
].X
;
6873 y1
:= FObj
.Y
+ WEAPONPOINT
[FDirection
].Y
;
6875 Target
.UID
:= FTargetUID
;
6878 if Target
.UID
<> 0 then
6879 begin // Öåëü åñòü - íàñòðàèâàåì
6880 if (g_GetUIDType(Target
.UID
) = UID_PLAYER
) and
6883 tpla
:= g_Player_Get(Target
.UID
);
6887 if (@FObj
) <> nil then
6894 Target
.cX
:= Target
.X
+ PLAYER_RECT_CX
;
6895 Target
.cY
:= Target
.Y
+ PLAYER_RECT_CY
;
6896 Target
.Rect
:= PLAYER_RECT
;
6897 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6898 Target
.Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6899 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6900 Target
.IsPlayer
:= True;
6904 if (g_GetUIDType(Target
.UID
) = UID_MONSTER
) and
6907 mon
:= g_Monsters_ByUID(Target
.UID
);
6910 Target
.X
:= mon
.Obj
.X
;
6911 Target
.Y
:= mon
.Obj
.Y
;
6913 Target
.cX
:= Target
.X
+ mon
.Obj
.Rect
.X
+ (mon
.Obj
.Rect
.Width
div 2);
6914 Target
.cY
:= Target
.Y
+ mon
.Obj
.Rect
.Y
+ (mon
.Obj
.Rect
.Height
div 2);
6915 Target
.Rect
:= mon
.Obj
.Rect
;
6916 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6917 Target
.Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6918 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6919 Target
.IsPlayer
:= False;
6926 begin // Öåëè íåò - îáíóëÿåì
6931 Target
.Visible
:= False;
6932 Target
.Line
:= False;
6933 Target
.IsPlayer
:= False;
6938 // Åñëè öåëü íå âèäèìà èëè íå íà ëèíèè îãíÿ, òî èùåì âñå âîçìîæíûå öåëè:
6939 if (not Target
.Line
) or (not Target
.Visible
) then
6943 for a
:= 0 to High(gPlayers
) do
6944 if (gPlayers
[a
] <> nil) and (gPlayers
[a
].alive
) and
6945 (gPlayers
[a
].FUID
<> FUID
) and
6946 (not SameTeam(FUID
, gPlayers
[a
].FUID
)) and
6947 (not gPlayers
[a
].NoTarget
) and
6948 (gPlayers
[a
].FMegaRulez
[MR_INVIS
] < gTime
) then
6950 if not TargetOnScreen(gPlayers
[a
].FObj
.X
+ PLAYER_RECT
.X
,
6951 gPlayers
[a
].FObj
.Y
+ PLAYER_RECT
.Y
) then
6954 x2
:= gPlayers
[a
].FObj
.X
+ PLAYER_RECT_CX
;
6955 y2
:= gPlayers
[a
].FObj
.Y
+ PLAYER_RECT_CY
;
6957 // Åñëè èãðîê íà ýêðàíå è íå ïðèêðûò ñòåíîé:
6958 if g_TraceVector(x1
, y1
, x2
, y2
) then
6960 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé:
6961 SetLength(targets
, Length(targets
)+1);
6962 with targets
[High(targets
)] do
6964 UID
:= gPlayers
[a
].FUID
;
6965 X
:= gPlayers
[a
].FObj
.X
;
6966 Y
:= gPlayers
[a
].FObj
.Y
;
6969 Rect
:= PLAYER_RECT
;
6970 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6971 Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6972 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6980 if vsMonster
then g_Mons_ForEach(monsUpdate
);
6983 // Åñëè åñòü âîçìîæíûå öåëè:
6984 // (Âûáèðàåì ëó÷øóþ, ìåíÿåì îðóæèå è áåæèì ê íåé/îò íåå)
6985 if targets
<> nil then
6987 // Âûáèðàåì íàèëó÷øóþ öåëü:
6988 BestTarget
:= targets
[0];
6989 if Length(targets
) > 1 then
6990 for a
:= 1 to High(targets
) do
6991 if Compare(BestTarget
, targets
[a
]) = 1 then
6992 BestTarget
:= targets
[a
];
6994 // Åñëè ëó÷øàÿ öåëü "âèäíåå" òåêóùåé, òî òåêóùàÿ := ëó÷øàÿ:
6995 if ((not Target
.Visible
) and BestTarget
.Visible
and (Target
.UID
<> BestTarget
.UID
)) or
6996 ((not Target
.Line
) and BestTarget
.Line
and BestTarget
.Visible
) then
6998 Target
:= BestTarget
;
7000 if (Healthy() = 3) or ((Healthy() = 2)) then
7001 begin // Åñëè çäîðîâû - äîãîíÿåì
7002 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
7003 SetAIFlag('GORIGHT', '1');
7004 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
7005 SetAIFlag('GOLEFT', '1');
7008 begin // Åñëè ïîáèòû - óáåãàåì
7009 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) then
7010 SetAIFlag('GORIGHT', '1');
7011 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
7012 SetAIFlag('GOLEFT', '1');
7015 // Âûáèðàåì îðóæèå íà îñíîâå ðàññòîÿíèÿ è ïðèîðèòåòîâ:
7016 SelectWeapon(Abs(x1
-Target
.cX
));
7021 // (Äîãîíÿåì/óáåãàåì, ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëè)
7022 // (Åñëè öåëü äàëåêî, òî õâàòèò ñëåäèòü çà íåé)
7023 if Target
.UID
<> 0 then
7025 if not TargetOnScreen(Target
.X
+ Target
.Rect
.X
,
7026 Target
.Y
+ Target
.Rect
.Y
) then
7027 begin // Öåëü ñáåæàëà ñ "ýêðàíà"
7028 if (Healthy() = 3) or ((Healthy() = 2)) then
7029 begin // Åñëè çäîðîâû - äîãîíÿåì
7030 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
7031 SetAIFlag('GORIGHT', '1');
7032 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
7033 SetAIFlag('GOLEFT', '1');
7036 begin // Åñëè ïîáèòû - çàáûâàåì î öåëè è óáåãàåì
7038 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) then
7039 SetAIFlag('GORIGHT', '1');
7040 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
7041 SetAIFlag('GOLEFT', '1');
7045 begin // Öåëü ïîêà íà "ýêðàíå"
7046 // Åñëè öåëü íå çàãîðîæåíà ñòåíîé, òî îòìå÷àåì, êîãäà åå âèäåëè:
7047 if g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
7048 FLastVisible
:= gTime
;
7049 // Åñëè ðàçíèöà âûñîò íå âåëèêà, òî äîãîíÿåì:
7050 if (Abs(FObj
.Y
-Target
.Y
) <= 128) then
7052 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
7053 SetAIFlag('GORIGHT', '1');
7054 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
7055 SetAIFlag('GOLEFT', '1');
7059 // Âûáèðàåì óãîë ââåðõ:
7060 if FDirection
= TDirection
.D_LEFT
then
7061 angle
:= ANGLE_LEFTUP
7063 angle
:= ANGLE_RIGHTUP
;
7065 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7066 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7068 // Åñëè ïðè óãëå ââåðõ ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
7069 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
7070 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128), //96
7071 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
7072 Target
.Rect
.Width
, Target
.Rect
.Height
) and
7073 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
7074 begin // òî íóæíî ñòðåëÿòü ââåðõ
7075 SetAIFlag('NEEDFIRE', '1');
7076 SetAIFlag('NEEDSEEUP', '1');
7079 // Âûáèðàåì óãîë âíèç:
7080 if FDirection
= TDirection
.D_LEFT
then
7081 angle
:= ANGLE_LEFTDOWN
7083 angle
:= ANGLE_RIGHTDOWN
;
7085 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7086 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7088 // Åñëè ïðè óãëå âíèç ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
7089 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
7090 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
7091 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
7092 Target
.Rect
.Width
, Target
.Rect
.Height
) and
7093 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
7094 begin // òî íóæíî ñòðåëÿòü âíèç
7095 SetAIFlag('NEEDFIRE', '1');
7096 SetAIFlag('NEEDSEEDOWN', '1');
7099 // Åñëè öåëü âèäíî è îíà íà òàêîé æå âûñîòå:
7100 if Target
.Visible
and
7101 (y1
+4 < Target
.Y
+Target
.Rect
.Y
+Target
.Rect
.Height
) and
7102 (y1
-4 > Target
.Y
+Target
.Rect
.Y
) then
7104 // Åñëè èäåì â ñòîðîíó öåëè, òî íàäî ñòðåëÿòü:
7105 if ((FDirection
= TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) or
7106 ((FDirection
= TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
7107 begin // òî íóæíî ñòðåëÿòü âïåðåä
7108 SetAIFlag('NEEDFIRE', '1');
7109 SetAIFlag('NEEDSEEDOWN', '');
7110 SetAIFlag('NEEDSEEUP', '');
7112 // Åñëè öåëü â ïðåäåëàõ "ýêðàíà" è ñëîæíîñòü ïîçâîëÿåò ïðûæêè ñáëèæåíèÿ:
7113 if Abs(FObj
.X
-Target
.X
) < Trunc(gPlayerScreenSize
.X
*0.75) then
7114 if GetRnd(FDifficult
.CloseJump
) then
7115 begin // òî åñëè ïîâåçåò - ïðûãàåì (îñîáåííî, åñëè áëèçêî)
7116 if Abs(FObj
.X
-Target
.X
) < 128 then
7120 if Random(a
) = 0 then
7121 SetAIFlag('NEEDJUMP', '1');
7125 // Åñëè öåëü âñå åùå åñòü:
7126 if Target
.UID
<> 0 then
7127 if gTime
-FLastVisible
> 2000 then // Åñëè âèäåëè äàâíî
7128 Target
.UID
:= 0 // òî çàáûòü öåëü
7129 else // Åñëè âèäåëè íåäàâíî
7130 begin // íî öåëü óáèëè
7131 if Target
.IsPlayer
then
7132 begin // Öåëü - èãðîê
7133 pla
:= g_Player_Get(Target
.UID
);
7134 if (pla
= nil) or (not pla
.alive
) or pla
.NoTarget
or
7135 (pla
.FMegaRulez
[MR_INVIS
] >= gTime
) then
7136 Target
.UID
:= 0; // òî çàáûòü öåëü
7139 begin // Öåëü - ìîíñòð
7140 mon
:= g_Monsters_ByUID(Target
.UID
);
7141 if (mon
= nil) or (not mon
.alive
) then
7142 Target
.UID
:= 0; // òî çàáûòü öåëü
7145 end; // if Target.UID <> 0
7147 FTargetUID
:= Target
.UID
;
7149 // Åñëè âîçìîæíûõ öåëåé íåò:
7150 // (Àòàêà ÷åãî-íèáóäü ñëåâà èëè ñïðàâà)
7151 if targets
= nil then
7152 if GetAIFlag('ATTACKLEFT') <> '' then
7153 begin // Åñëè íóæíî àòàêîâàòü íàëåâî
7154 RemoveAIFlag('ATTACKLEFT');
7156 SetAIFlag('NEEDJUMP', '1');
7158 if RunDirection() = TDirection
.D_RIGHT
then
7159 begin // Èäåì íå â òó ñòîðîíó
7160 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
7161 begin // Åñëè çäîðîâû, òî, âîçìîæíî, ñòðåëÿåì áåæèì âëåâî è ñòðåëÿåì
7162 SetAIFlag('NEEDFIRE', '1');
7163 SetAIFlag('GOLEFT', '1');
7167 begin // Èäåì â íóæíóþ ñòîðîíó
7168 if GetRnd(FDifficult
.InvisFire
) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
7169 SetAIFlag('NEEDFIRE', '1');
7170 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
7171 SetAIFlag('GORIGHT', '1');
7175 if GetAIFlag('ATTACKRIGHT') <> '' then
7176 begin // Åñëè íóæíî àòàêîâàòü íàïðàâî
7177 RemoveAIFlag('ATTACKRIGHT');
7179 SetAIFlag('NEEDJUMP', '1');
7181 if RunDirection() = TDirection
.D_LEFT
then
7182 begin // Èäåì íå â òó ñòîðîíó
7183 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
7184 begin // Åñëè çäîðîâû, òî, âîçìîæíî, áåæèì âïðàâî è ñòðåëÿåì
7185 SetAIFlag('NEEDFIRE', '1');
7186 SetAIFlag('GORIGHT', '1');
7191 if GetRnd(FDifficult
.InvisFire
) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
7192 SetAIFlag('NEEDFIRE', '1');
7193 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
7194 SetAIFlag('GOLEFT', '1');
7198 //HACK! (does it belongs there?)
7199 RealizeCurrentWeapon();
7201 // Åñëè åñòü âîçìîæíûå öåëè:
7202 // (Ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëÿì)
7203 if (targets
<> nil) and (GetAIFlag('NEEDFIRE') <> '') then
7204 for a
:= 0 to High(targets
) do
7206 // Åñëè ìîæåì ñòðåëÿòü ïî äèàãîíàëè:
7207 if GetRnd(FDifficult
.DiagFire
) then
7209 // Èùåì öåëü ñâåðõó è ñòðåëÿåì, åñëè åñòü:
7210 if FDirection
= TDirection
.D_LEFT
then
7211 angle
:= ANGLE_LEFTUP
7213 angle
:= ANGLE_RIGHTUP
;
7215 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7216 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7218 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
7219 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
7220 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
7221 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
7222 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
7224 SetAIFlag('NEEDFIRE', '1');
7225 SetAIFlag('NEEDSEEUP', '1');
7228 // Èùåì öåëü ñíèçó è ñòðåëÿåì, åñëè åñòü:
7229 if FDirection
= TDirection
.D_LEFT
then
7230 angle
:= ANGLE_LEFTDOWN
7232 angle
:= ANGLE_RIGHTDOWN
;
7234 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7235 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7237 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
7238 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
7239 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
7240 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
7241 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
7243 SetAIFlag('NEEDFIRE', '1');
7244 SetAIFlag('NEEDSEEDOWN', '1');
7248 // Åñëè öåëü "ïåðåä íîñîì", òî ñòðåëÿåì:
7249 if targets
[a
].Line
and targets
[a
].Visible
and
7250 (((FDirection
= TDirection
.D_LEFT
) and (targets
[a
].X
< FObj
.X
)) or
7251 ((FDirection
= TDirection
.D_RIGHT
) and (targets
[a
].X
> FObj
.X
))) then
7253 SetAIFlag('NEEDFIRE', '1');
7258 // Åñëè ëåòèò ïóëÿ, òî, âîçìîæíî, ïîäïðûãèâàåì:
7259 if g_Weapon_Danger(FUID
, FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
,
7260 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
,
7261 40+GetInterval(FDifficult
.Cover
, 40)) then
7262 SetAIFlag('NEEDJUMP', '1');
7264 // Åñëè êîí÷èëèñü ïàòîðíû, òî íóæíî ñìåíèòü îðóæèå:
7265 ammo
:= GetAmmoByWeapon(FCurrWeap
);
7266 if ((FCurrWeap
= WEAPON_SHOTGUN2
) and (ammo
< 2)) or
7267 ((FCurrWeap
= WEAPON_BFG
) and (ammo
< 40)) or
7269 SetAIFlag('SELECTWEAPON', '1');
7271 // Åñëè íóæíî ñìåíèòü îðóæèå, òî âûáèðàåì íóæíîå:
7272 if GetAIFlag('SELECTWEAPON') = '1' then
7275 RemoveAIFlag('SELECTWEAPON');
7279 procedure TBot
.Update();
7292 // Ïðîâåðÿåì, îòêëþ÷¸í ëè AI áîòîâ
7293 if (g_debug_BotAIOff
= 1) and (Team
= TEAM_RED
) then
7295 if (g_debug_BotAIOff
= 2) and (Team
= TEAM_BLUE
) then
7297 if g_debug_BotAIOff
= 3 then
7307 RealizeCurrentWeapon();
7314 procedure TBot
.ReleaseKey(Key
: Byte);
7323 function TBot
.KeyPressed(Key
: Word): Boolean;
7325 Result
:= FKeys
[Key
].Pressed
;
7328 function TBot
.GetAIFlag(aName
: String20
): String20
;
7334 aName
:= LowerCase(aName
);
7336 if FAIFlags
<> nil then
7337 for a
:= 0 to High(FAIFlags
) do
7338 if LowerCase(FAIFlags
[a
].Name
) = aName
then
7340 Result
:= FAIFlags
[a
].Value
;
7345 procedure TBot
.RemoveAIFlag(aName
: String20
);
7349 if FAIFlags
= nil then Exit
;
7351 aName
:= LowerCase(aName
);
7353 for a
:= 0 to High(FAIFlags
) do
7354 if LowerCase(FAIFlags
[a
].Name
) = aName
then
7356 if a
<> High(FAIFlags
) then
7357 for b
:= a
to High(FAIFlags
)-1 do
7358 FAIFlags
[b
] := FAIFlags
[b
+1];
7360 SetLength(FAIFlags
, Length(FAIFlags
)-1);
7365 procedure TBot
.SetAIFlag(aName
, fValue
: String20
);
7373 aName
:= LowerCase(aName
);
7375 if FAIFlags
<> nil then
7376 for a
:= 0 to High(FAIFlags
) do
7377 if LowerCase(FAIFlags
[a
].Name
) = aName
then
7383 if ok
then FAIFlags
[a
].Value
:= fValue
7386 SetLength(FAIFlags
, Length(FAIFlags
)+1);
7387 with FAIFlags
[High(FAIFlags
)] do
7395 procedure TBot
.UpdateMove
;
7397 procedure GoLeft(Time
: Word = 1);
7399 ReleaseKey(KEY_LEFT
);
7400 ReleaseKey(KEY_RIGHT
);
7401 PressKey(KEY_LEFT
, Time
);
7402 SetDirection(TDirection
.D_LEFT
);
7405 procedure GoRight(Time
: Word = 1);
7407 ReleaseKey(KEY_LEFT
);
7408 ReleaseKey(KEY_RIGHT
);
7409 PressKey(KEY_RIGHT
, Time
);
7410 SetDirection(TDirection
.D_RIGHT
);
7413 function Rnd(a
: Word): Boolean;
7415 Result
:= Random(a
) = 0;
7418 procedure Turn(Time
: Word = 1200);
7420 if RunDirection() = TDirection
.D_LEFT
then GoRight(Time
) else GoLeft(Time
);
7425 ReleaseKey(KEY_LEFT
);
7426 ReleaseKey(KEY_RIGHT
);
7429 function CanRunLeft(): Boolean;
7431 Result
:= not CollideLevel(-1, 0);
7434 function CanRunRight(): Boolean;
7436 Result
:= not CollideLevel(1, 0);
7439 function CanRun(): Boolean;
7441 if RunDirection() = TDirection
.D_LEFT
then Result
:= CanRunLeft() else Result
:= CanRunRight();
7444 procedure Jump(Time
: Word = 30);
7446 PressKey(KEY_JUMP
, Time
);
7449 function NearHole(): Boolean;
7453 { TODO 5 : Ëåñòíèöû }
7454 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7455 for x
:= 1 to PLAYER_RECT
.Width
do
7456 if (not StayOnStep(x
*sx
, 0)) and
7457 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7458 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7467 function BorderHole(): Boolean;
7471 { TODO 5 : Ëåñòíèöû }
7472 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7473 for x
:= 1 to PLAYER_RECT
.Width
do
7474 if (not StayOnStep(x
*sx
, 0)) and
7475 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7476 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7478 for xx
:= x
to x
+32 do
7479 if CollideLevel(xx
*sx
, PLAYER_RECT
.Height
) then
7489 function NearDeepHole(): Boolean;
7495 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7498 for x
:= 1 to PLAYER_RECT
.Width
do
7499 if (not StayOnStep(x
*sx
, 0)) and
7500 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7501 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7503 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
7505 if CollideLevel(x
*sx
, PLAYER_RECT
.Height
*y
) then Exit
;
7510 end else Result
:= False;
7513 function OverDeepHole(): Boolean;
7520 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
7522 if CollideLevel(0, PLAYER_RECT
.Height
*y
) then Exit
;
7529 function OnGround(): Boolean;
7531 Result
:= StayOnStep(0, 0) or CollideLevel(0, 1);
7534 function OnLadder(): Boolean;
7536 Result
:= FullInStep(0, 0);
7539 function BelowLadder(): Boolean;
7541 Result
:= (FullInStep(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) and
7542 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
7543 (FullInStep(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) and
7544 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
7547 function BelowLiftUp(): Boolean;
7549 Result
:= ((FullInLift(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) = -1) and
7550 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
7551 ((FullInLift(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) = -1) and
7552 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
7555 function OnTopLift(): Boolean;
7557 Result
:= (FullInLift(0, 0) = -1) and (FullInLift(0, -32) = 0);
7560 function CanJumpOver(): Boolean;
7564 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7568 if not CollideLevel(sx
, 0) then Exit
;
7570 for y
:= 1 to BOT_MAXJUMP
do
7571 if CollideLevel(0, -y
) then Exit
else
7572 if not CollideLevel(sx
, -y
) then
7579 function CanJumpUp(Dist
: ShortInt): Boolean;
7586 if CollideLevel(Dist
, 0) then Exit
;
7589 for y
:= 0 to BOT_MAXJUMP
do
7590 if CollideLevel(Dist
, -y
) then
7599 for yy
:= y
+1 to BOT_MAXJUMP
do
7600 if not CollideLevel(Dist
, -yy
) then
7609 for y
:= 0 to BOT_MAXJUMP
do
7610 if CollideLevel(0, -y
) then
7618 if y
< yy
then Exit
;
7623 function IsSafeTrigger(): Boolean;
7628 if gTriggers
= nil then
7630 for a
:= 0 to High(gTriggers
) do
7631 if Collide(gTriggers
[a
].X
,
7634 gTriggers
[a
].Height
) and
7635 (gTriggers
[a
].TriggerType
in [TRIGGER_EXIT
, TRIGGER_CLOSEDOOR
,
7636 TRIGGER_CLOSETRAP
, TRIGGER_TRAP
,
7637 TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
,
7638 TRIGGER_ONOFF
, TRIGGER_SPAWNMONSTER
,
7639 TRIGGER_DAMAGE
, TRIGGER_SHOT
]) then
7644 // Âîçìîæíî, íàæèìàåì êíîïêó:
7645 if Rnd(16) and IsSafeTrigger() then
7648 // Åñëè ïîä ëèôòîì èëè ñòóïåíüêàìè, òî, âîçìîæíî, ïðûãàåì:
7649 if OnLadder() or ((BelowLadder() or BelowLiftUp()) and Rnd(8)) then
7651 ReleaseKey(KEY_LEFT
);
7652 ReleaseKey(KEY_RIGHT
);
7656 // Èäåì âëåâî, åñëè íàäî áûëî:
7657 if GetAIFlag('GOLEFT') <> '' then
7659 RemoveAIFlag('GOLEFT');
7660 if CanRunLeft() then
7664 // Èäåì âïðàâî, åñëè íàäî áûëî:
7665 if GetAIFlag('GORIGHT') <> '' then
7667 RemoveAIFlag('GORIGHT');
7668 if CanRunRight() then
7672 // Åñëè âûëåòåëè çà êàðòó, òî ïðîáóåì âåðíóòüñÿ:
7673 if FObj
.X
< -32 then
7676 if FObj
.X
+32 > gMapInfo
.Width
then
7679 // Ïðûãàåì, åñëè íàäî áûëî:
7680 if GetAIFlag('NEEDJUMP') <> '' then
7683 RemoveAIFlag('NEEDJUMP');
7686 // Ñìîòðèì ââåðõ, åñëè íàäî áûëî:
7687 if GetAIFlag('NEEDSEEUP') <> '' then
7690 ReleaseKey(KEY_DOWN
);
7691 PressKey(KEY_UP
, 20);
7692 RemoveAIFlag('NEEDSEEUP');
7695 // Ñìîòðèì âíèç, åñëè íàäî áûëî:
7696 if GetAIFlag('NEEDSEEDOWN') <> '' then
7699 ReleaseKey(KEY_DOWN
);
7700 PressKey(KEY_DOWN
, 20);
7701 RemoveAIFlag('NEEDSEEDOWN');
7704 // Åñëè íóæíî áûëî â äûðó è ìû íå íà çåìëå, òî ïîêîðíî ëåòèì:
7705 if GetAIFlag('GOINHOLE') <> '' then
7706 if not OnGround() then
7708 ReleaseKey(KEY_LEFT
);
7709 ReleaseKey(KEY_RIGHT
);
7710 RemoveAIFlag('GOINHOLE');
7711 SetAIFlag('FALLINHOLE', '1');
7714 // Åñëè ïàäàëè è äîñòèãëè çåìëè, òî õâàòèò ïàäàòü:
7715 if GetAIFlag('FALLINHOLE') <> '' then
7717 RemoveAIFlag('FALLINHOLE');
7719 // Åñëè ëåòåëè ïðÿìî è ñåé÷àñ íå íà ëåñòíèöå èëè íà âåðøèíå ëèôòà, òî îòõîäèì â ñòîðîíó:
7720 if not (KeyPressed(KEY_LEFT
) or KeyPressed(KEY_RIGHT
)) then
7721 if GetAIFlag('FALLINHOLE') = '' then
7722 if (not OnLadder()) or (FObj
.Vel
.Y
>= 0) or (OnTopLift()) then
7728 // Åñëè íà çåìëå è ìîæíî ïîäïðûãíóòü, òî, âîçìîæíî, ïðûãàåì:
7730 CanJumpUp(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*32) and
7734 // Åñëè íà çåìëå è âîçëå äûðû (ãëóáèíà > 2 ðîñòîâ èãðîêà):
7735 if OnGround() and NearHole() then
7736 if NearDeepHole() then // Åñëè ýòî áåçäíà
7738 0..3: Turn(); // Áåæèì îáðàòíî
7739 4: Jump(); // Ïðûãàåì
7740 5: begin // Ïðûãàåì îáðàòíî
7745 else // Ýòî íå áåçäíà è ìû åùå íå ëåòèì òóäà
7746 if GetAIFlag('GOINHOLE') = '' then
7748 0: Turn(); // Íå íóæíî òóäà
7749 1: Jump(); // Âäðóã ïîâåçåò - ïðûãàåì
7750 else // Åñëè ÿìà ñ ãðàíèöåé, òî ïðè ñëó÷àå ìîæíî òóäà ïðûãíóòü
7751 if BorderHole() then
7752 SetAIFlag('GOINHOLE', '1');
7755 // Åñëè íà çåìëå, íî íåêóäà èäòè:
7756 if (not CanRun()) and OnGround() then
7758 // Åñëè ìû íà ëåñòíèöå èëè ìîæíî ïåðåïðûãíóòü, òî ïðûãàåì:
7759 if CanJumpOver() or OnLadder() then
7761 else // èíà÷å ïîïûòàåìñÿ â äðóãóþ ñòîðîíó
7762 if Random(2) = 0 then
7764 if IsSafeTrigger() then
7770 // Îñòàëîñü ìàëî âîçäóõà:
7771 if FAir
< 36 * 2 then
7774 // Âûáèðàåìñÿ èç êèñëîòû, åñëè íåò êîñòþìà, îáîæãëèñü, èëè ìàëî çäîðîâüÿ:
7775 if (FMegaRulez
[MR_SUIT
] < gTime
) and ((FLastHit
= HIT_ACID
) or (Healthy() <= 1)) then
7776 if BodyInAcid(0, 0) then
7780 function TBot
.FullInStep(XInc
, YInc
: Integer): Boolean;
7782 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
7783 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_STEP
, False);
7786 {function TBot.NeedItem(Item: Byte): Byte;
7791 procedure TBot
.SelectWeapon(Dist
: Integer);
7795 function HaveAmmo(weapon
: Byte): Boolean;
7798 WEAPON_PISTOL
: Result
:= FAmmo
[A_BULLETS
] >= 1;
7799 WEAPON_SHOTGUN1
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7800 WEAPON_SHOTGUN2
: Result
:= FAmmo
[A_SHELLS
] >= 2;
7801 WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
] >= 10;
7802 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
] >= 1;
7803 WEAPON_PLASMA
: Result
:= FAmmo
[A_CELLS
] >= 10;
7804 WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
] >= 40;
7805 WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7806 WEAPON_FLAMETHROWER
: Result
:= FAmmo
[A_FUEL
] >= 1;
7807 else Result
:= True;
7812 if Dist
= -1 then Dist
:= BOT_LONGDIST
;
7814 if Dist
> BOT_LONGDIST
then
7815 begin // Äàëüíèé áîé
7817 if FWeapon
[FDifficult
.WeaponPrior
[a
]] and HaveAmmo(FDifficult
.WeaponPrior
[a
]) then
7819 FSelectedWeapon
:= FDifficult
.WeaponPrior
[a
];
7823 else //if Dist > BOT_UNSAFEDIST then
7824 begin // Áëèæíèé áîé
7826 if FWeapon
[FDifficult
.CloseWeaponPrior
[a
]] and HaveAmmo(FDifficult
.CloseWeaponPrior
[a
]) then
7828 FSelectedWeapon
:= FDifficult
.CloseWeaponPrior
[a
];
7835 if FWeapon[FDifficult.SafeWeaponPrior[a]] and HaveAmmo(FDifficult.SafeWeaponPrior[a]) then
7837 FSelectedWeapon := FDifficult.SafeWeaponPrior[a];
7843 function TBot
.PickItem(ItemType
: Byte; force
: Boolean; var remove
: Boolean): Boolean;
7845 Result
:= inherited PickItem(ItemType
, force
, remove
);
7847 if Result
then SetAIFlag('SELECTWEAPON', '1');
7850 function TBot
.Heal(value
: Word; Soft
: Boolean): Boolean;
7852 Result
:= inherited Heal(value
, Soft
);
7855 function TBot
.Healthy(): Byte;
7857 if FMegaRulez
[MR_INVUL
] >= gTime
then Result
:= 3
7858 else if (FHealth
> 80) or ((FHealth
> 50) and (FArmor
> 20)) then Result
:= 3
7859 else if (FHealth
> 50) then Result
:= 2
7860 else if (FHealth
> 20) then Result
:= 1
7864 function TBot
.TargetOnScreen(TX
, TY
: Integer): Boolean;
7866 Result
:= (Abs(FObj
.X
-TX
) <= Trunc(gPlayerScreenSize
.X
*0.6)) and
7867 (Abs(FObj
.Y
-TY
) <= Trunc(gPlayerScreenSize
.Y
*0.6));
7870 procedure TBot
.OnDamage(Angle
: SmallInt);
7878 if (Angle
= 0) or (Angle
= 180) then
7881 if (g_GetUIDType(FLastSpawnerUID
) = UID_PLAYER
) and
7882 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
) then
7884 pla
:= g_Player_Get(FLastSpawnerUID
);
7885 ok
:= not TargetOnScreen(pla
.FObj
.X
+ PLAYER_RECT
.X
,
7886 pla
.FObj
.Y
+ PLAYER_RECT
.Y
);
7889 if (g_GetUIDType(FLastSpawnerUID
) = UID_MONSTER
) and
7890 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
) then
7892 mon
:= g_Monsters_ByUID(FLastSpawnerUID
);
7893 ok
:= not TargetOnScreen(mon
.Obj
.X
+ mon
.Obj
.Rect
.X
,
7894 mon
.Obj
.Y
+ mon
.Obj
.Rect
.Y
);
7899 SetAIFlag('ATTACKLEFT', '1')
7901 SetAIFlag('ATTACKRIGHT', '1');
7905 function TBot
.RunDirection(): TDirection
;
7907 if Abs(Vel
.X
) >= 1 then
7909 if Vel
.X
> 0 then Result
:= TDirection
.D_RIGHT
else Result
:= TDirection
.D_LEFT
;
7911 Result
:= FDirection
;
7914 function TBot
.GetRnd(a
: Byte): Boolean;
7916 if a
= 0 then Result
:= False
7917 else if a
= 255 then Result
:= True
7918 else Result
:= Random(256) > 255-a
;
7921 function TBot
.GetInterval(a
: Byte; radius
: SmallInt): SmallInt;
7923 Result
:= Round((255-a
)/255*radius
*(Random(2)-1));
7927 procedure TDifficult
.save (st
: TStream
);
7929 utils
.writeInt(st
, Byte(DiagFire
));
7930 utils
.writeInt(st
, Byte(InvisFire
));
7931 utils
.writeInt(st
, Byte(DiagPrecision
));
7932 utils
.writeInt(st
, Byte(FlyPrecision
));
7933 utils
.writeInt(st
, Byte(Cover
));
7934 utils
.writeInt(st
, Byte(CloseJump
));
7935 st
.WriteBuffer(WeaponPrior
[Low(WeaponPrior
)], sizeof(WeaponPrior
));
7936 st
.WriteBuffer(CloseWeaponPrior
[Low(CloseWeaponPrior
)], sizeof(CloseWeaponPrior
));
7939 procedure TDifficult
.load (st
: TStream
);
7941 DiagFire
:= utils
.readByte(st
);
7942 InvisFire
:= utils
.readByte(st
);
7943 DiagPrecision
:= utils
.readByte(st
);
7944 FlyPrecision
:= utils
.readByte(st
);
7945 Cover
:= utils
.readByte(st
);
7946 CloseJump
:= utils
.readByte(st
);
7947 st
.ReadBuffer(WeaponPrior
[Low(WeaponPrior
)], sizeof(WeaponPrior
));
7948 st
.ReadBuffer(CloseWeaponPrior
[Low(CloseWeaponPrior
)], sizeof(CloseWeaponPrior
));
7952 procedure TBot
.SaveState (st
: TStream
);
7957 inherited SaveState(st
);
7958 utils
.writeSign(st
, 'BOT0');
7960 utils
.writeInt(st
, Byte(FSelectedWeapon
));
7962 utils
.writeInt(st
, Word(FTargetUID
));
7963 // Âðåìÿ ïîòåðè öåëè
7964 utils
.writeInt(st
, LongWord(FLastVisible
));
7965 // Êîëè÷åñòâî ôëàãîâ ÈÈ
7966 dw
:= Length(FAIFlags
);
7967 utils
.writeInt(st
, LongInt(dw
));
7969 for i
:= 0 to dw
-1 do
7971 utils
.writeStr(st
, FAIFlags
[i
].Name
, 20);
7972 utils
.writeStr(st
, FAIFlags
[i
].Value
, 20);
7974 // Íàñòðîéêè ñëîæíîñòè
7975 FDifficult
.save(st
);
7979 procedure TBot
.LoadState (st
: TStream
);
7984 inherited LoadState(st
);
7985 if not utils
.checkSign(st
, 'BOT0') then raise XStreamError
.Create('invalid bot signature');
7987 FSelectedWeapon
:= utils
.readByte(st
);
7989 FTargetUID
:= utils
.readWord(st
);
7990 // Âðåìÿ ïîòåðè öåëè
7991 FLastVisible
:= utils
.readLongWord(st
);
7992 // Êîëè÷åñòâî ôëàãîâ ÈÈ
7993 dw
:= utils
.readLongInt(st
);
7994 if (dw
< 0) or (dw
> 16384) then raise XStreamError
.Create('invalid number of bot AI flags');
7995 SetLength(FAIFlags
, dw
);
7997 for i
:= 0 to dw
-1 do
7999 FAIFlags
[i
].Name
:= utils
.readStr(st
, 20);
8000 FAIFlags
[i
].Value
:= utils
.readStr(st
, 20);
8002 // Íàñòðîéêè ñëîæíîñòè
8003 FDifficult
.load(st
);
8008 conRegVar('cheat_berserk_autoswitch', @gBerserkAutoswitch
, 'autoswitch to fist when berserk pack taken', '', true, true);
8009 conRegVar('player_indicator', @gPlayerIndicator
, 'Draw indicator only for current player, also for teammates, or not at all', 'Draw indicator only for current player, also for teammates, or not at all');
8010 conRegVar('player_indicator_style', @gPlayerIndicatorStyle
, 'Visual appearance of indicator', 'Visual appearance of indicator');