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 Collide(X
, Y
: Integer; Width
, Height
: Word): Boolean; overload
;
307 function Collide(Panel
: TPanel
): Boolean; overload
;
308 function Collide(X
, Y
: Integer): Boolean; overload
;
309 procedure SetDirection(Direction
: TDirection
);
310 procedure GetSecret();
311 function TeleportTo(X
, Y
: Integer; silent
: Boolean; dir
: Byte): Boolean;
313 procedure Push(vx
, vy
: Integer);
314 procedure ChangeModel(ModelName
: String);
315 procedure SwitchTeam
;
316 procedure ChangeTeam(Team
: Byte);
318 function GetFlag(Flag
: Byte): Boolean;
319 procedure SetFlag(Flag
: Byte);
320 function DropFlag(Silent
: Boolean = True; DoThrow
: Boolean = False): Boolean;
321 function TryDropFlag(): Boolean;
322 procedure AllRulez(Health
: Boolean);
323 procedure RestoreHealthArmor();
324 procedure FragCombo();
325 procedure GiveItem(ItemType
: Byte);
326 procedure Damage(value
: Word; SpawnerUID
: Word; vx
, vy
: Integer; t
: Byte); virtual;
327 function Heal(value
: Word; Soft
: Boolean): Boolean; virtual;
328 procedure MakeBloodVector(Count
: Word; VelX
, VelY
: Integer);
329 procedure MakeBloodSimple(Count
: Word);
330 procedure Kill(KillType
: Byte; SpawnerUID
: Word; t
: Byte);
331 procedure Reset(Force
: Boolean);
332 procedure Spectate(NoMove
: Boolean = False);
333 procedure SwitchNoClip
;
334 procedure SoftReset();
335 procedure Draw(); virtual;
336 procedure DrawPain();
337 procedure DrawPickup();
338 procedure DrawRulez();
340 procedure DrawIndicator(Color
: TRGB
);
341 procedure DrawBubble();
343 procedure PreUpdate();
344 procedure Update(); virtual;
345 procedure RememberState();
346 procedure RecallState();
347 procedure SaveState (st
: TStream
); virtual;
348 procedure LoadState (st
: TStream
); virtual;
349 procedure PauseSounds(Enable
: Boolean);
350 procedure NetFire(Wpn
: Byte; X
, Y
, AX
, AY
: Integer; WID
: Integer = -1);
351 procedure DoLerp(Level
: Integer = 2);
352 procedure SetLerp(XTo
, YTo
: Integer);
353 procedure ProcessWeaponAction(Action
: Byte);
354 procedure QueueWeaponSwitch(Weapon
: Byte);
355 procedure RealizeCurrentWeapon();
359 procedure JetpackOff
;
360 procedure CatchFire(Attacker
: Word; Timeout
: Integer = PLAYER_BURN_TIME
);
362 //WARNING! this does nothing for now, but still call it!
363 procedure positionChanged (); //WARNING! call this after entity position was changed, or coldet will not work right!
365 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
366 procedure moveBy (dx
, dy
: Integer); inline;
368 function getCameraObj(): TObj
;
371 property Vel
: TPoint2i read FObj
.Vel
;
372 property Obj
: TObj read FObj
;
374 property Name
: String read FName write FName
;
375 property Model
: TPlayerModel read FModel
;
376 property Health
: Integer read FHealth write FHealth
;
377 property Lives
: Byte read FLives write FLives
;
378 property Armor
: Integer read FArmor write FArmor
;
379 property Air
: Integer read FAir write FAir
;
380 property JetFuel
: Integer read FJetFuel write FJetFuel
;
381 property Frags
: Integer read FFrags write FFrags
;
382 property Death
: Integer read FDeath write FDeath
;
383 property Kills
: Integer read FKills write FKills
;
384 property CurrWeap
: Byte read FCurrWeap write FCurrWeap
;
385 property WeapSwitchMode
: Byte read FWeapSwitchMode write FWeapSwitchMode
;
386 property SwitchToEmpty
: Byte read FSwitchToEmpty write FSwitchToEmpty
;
387 property MonsterKills
: Integer read FMonsterKills write FMonsterKills
;
388 property Secrets
: Integer read FSecrets
;
389 property GodMode
: Boolean read FGodMode write FGodMode
;
390 property NoTarget
: Boolean read FNoTarget write FNoTarget
;
391 property NoReload
: Boolean read FNoReload write FNoReload
;
392 property alive
: Boolean read FAlive write FAlive
;
393 property Flag
: Byte read FFlag
;
394 property Team
: Byte read FTeam write FTeam
;
395 property Direction
: TDirection read FDirection
;
396 property GameX
: Integer read FObj
.X write FObj
.X
;
397 property GameY
: Integer read FObj
.Y write FObj
.Y
;
398 property GameVelX
: Integer read FObj
.Vel
.X write FObj
.Vel
.X
;
399 property GameVelY
: Integer read FObj
.Vel
.Y write FObj
.Vel
.Y
;
400 property GameAccelX
: Integer read FObj
.Accel
.X write FObj
.Accel
.X
;
401 property GameAccelY
: Integer read FObj
.Accel
.Y write FObj
.Accel
.Y
;
402 property IncCam
: Integer read FIncCam write FIncCam
;
403 property IncCamOld
: Integer read FIncCamOld write FIncCamOld
;
404 property SlopeOld
: Integer read FSlopeOld write FSlopeOld
;
405 property UID
: Word read FUID write FUID
;
406 property JustTeleported
: Boolean read FJustTeleported write FJustTeleported
;
407 property NetTime
: LongWord read FNetTime write FNetTime
;
410 property eName
: String read FName write FName
;
411 property eHealth
: Integer read FHealth write FHealth
;
412 property eLives
: Byte read FLives write FLives
;
413 property eArmor
: Integer read FArmor write FArmor
;
414 property eAir
: Integer read FAir write FAir
;
415 property eJetFuel
: Integer read FJetFuel write FJetFuel
;
416 property eFrags
: Integer read FFrags write FFrags
;
417 property eDeath
: Integer read FDeath write FDeath
;
418 property eKills
: Integer read FKills write FKills
;
419 property eCurrWeap
: Byte read FCurrWeap write FCurrWeap
;
420 property eMonsterKills
: Integer read FMonsterKills write FMonsterKills
;
421 property eSecrets
: Integer read FSecrets write FSecrets
;
422 property eGodMode
: Boolean read FGodMode write FGodMode
;
423 property eNoTarget
: Boolean read FNoTarget write FNoTarget
;
424 property eNoReload
: Boolean read FNoReload write FNoReload
;
425 property eAlive
: Boolean read FAlive write FAlive
;
426 property eFlag
: Byte read FFlag
;
427 property eTeam
: Byte read FTeam write FTeam
;
428 property eDirection
: TDirection read FDirection
;
429 property eGameX
: Integer read FObj
.X write FObj
.X
;
430 property eGameY
: Integer read FObj
.Y write FObj
.Y
;
431 property eGameVelX
: Integer read FObj
.Vel
.X write FObj
.Vel
.X
;
432 property eGameVelY
: Integer read FObj
.Vel
.Y write FObj
.Vel
.Y
;
433 property eGameAccelX
: Integer read FObj
.Accel
.X write FObj
.Accel
.X
;
434 property eGameAccelY
: Integer read FObj
.Accel
.Y write FObj
.Accel
.Y
;
435 property eIncCam
: Integer read FIncCam write FIncCam
;
436 property eUID
: Word read FUID
;
437 property eJustTeleported
: Boolean read FJustTeleported
;
438 property eNetTime
: LongWord read FNetTime
;
440 // set this before assigning something to `eDamage`
441 property eDamageType
: Integer read mEDamageType write mEDamageType
;
442 property eDamage
: Integer write doDamage
;
453 WeaponPrior
: packed array [WP_FIRST
..WP_LAST
] of Byte;
454 CloseWeaponPrior
: packed array [WP_FIRST
..WP_LAST
] of Byte;
455 //SafeWeaponPrior: Array [WP_FIRST..WP_LAST] of Byte;
458 procedure save (st
: TStream
);
459 procedure load (st
: TStream
);
467 TBot
= class(TPlayer
)
469 FSelectedWeapon
: Byte;
472 FAIFlags
: Array of TAIFlag
;
473 FDifficult
: TDifficult
;
475 function GetRnd(a
: Byte): Boolean;
476 function GetInterval(a
: Byte; radius
: SmallInt): SmallInt;
477 function RunDirection(): TDirection
;
478 function FullInStep(XInc
, YInc
: Integer): Boolean;
479 //function NeedItem(Item: Byte): Byte;
480 procedure SelectWeapon(Dist
: Integer);
481 procedure SetAIFlag(aName
, fValue
: String20
);
482 function GetAIFlag(aName
: String20
): String20
;
483 procedure RemoveAIFlag(aName
: String20
);
484 function Healthy(): Byte;
485 procedure UpdateMove();
486 procedure UpdateCombat();
487 function KeyPressed(Key
: Word): Boolean;
488 procedure ReleaseKey(Key
: Byte);
489 function TargetOnScreen(TX
, TY
: Integer): Boolean;
490 procedure OnDamage(Angle
: SmallInt); override;
493 procedure Respawn(Silent
: Boolean; Force
: Boolean = False); override;
494 constructor Create(); override;
495 destructor Destroy(); override;
496 procedure Draw(); override;
497 function PickItem(ItemType
: Byte; force
: Boolean; var remove
: Boolean): Boolean; override;
498 function Heal(value
: Word; Soft
: Boolean): Boolean; override;
499 procedure Update(); override;
500 procedure SaveState (st
: TStream
); override;
501 procedure LoadState (st
: TStream
); override;
513 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
514 procedure moveBy (dx
, dy
: Integer); inline;
516 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
530 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
531 procedure moveBy (dx
, dy
: Integer); inline;
533 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
536 TCorpse
= class{$IFDEF USE_MEMPOOL}(TPoolObject
){$ENDIF}
545 FAnimation
: TAnimation
;
546 FAnimationMask
: TAnimation
;
549 constructor Create(X
, Y
: Integer; ModelName
: String; aMess
: Boolean);
550 destructor Destroy(); override;
551 procedure Damage(Value
: Word; SpawnerUID
: Word; vx
, vy
: Integer);
554 procedure SaveState (st
: TStream
);
555 procedure LoadState (st
: TStream
);
557 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
558 procedure moveBy (dx
, dy
: Integer); inline;
560 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
562 function ObjPtr (): PObj
; inline;
564 property Obj
: TObj read FObj
; // copies object
565 property State
: Byte read FState
;
566 property Mess
: Boolean read FMess
;
569 TTeamStat
= Array [TEAM_RED
..TEAM_BLUE
] of
575 gPlayers
: Array of TPlayer
;
576 gCorpses
: Array of TCorpse
;
577 gGibs
: Array of TGib
;
578 gShells
: Array of TShell
;
579 gTeamStat
: TTeamStat
;
580 gFly
: Boolean = False;
581 gAimLine
: Boolean = False;
582 gChatBubble
: Integer = 0;
583 gPlayerIndicator
: Integer = 1;
584 gPlayerIndicatorStyle
: Integer = 0;
586 gSpectLatchPID1
: Word = 0;
587 gSpectLatchPID2
: Word = 0;
588 MAX_RUNVEL
: Integer = 8;
589 VEL_JUMP
: Integer = 10;
590 SHELL_TIMEOUT
: Cardinal = 60000;
592 function Lerp(X
, Y
, Factor
: Integer): Integer;
594 procedure g_Gibs_SetMax(Count
: Word);
595 function g_Gibs_GetMax(): Word;
596 procedure g_Corpses_SetMax(Count
: Word);
597 function g_Corpses_GetMax(): Word;
598 procedure g_Shells_SetMax(Count
: Word);
599 function g_Shells_GetMax(): Word;
601 procedure g_Player_Init();
602 procedure g_Player_Free();
603 function g_Player_Create(ModelName
: String; Color
: TRGB
; Team
: Byte; Bot
: Boolean): Word;
604 function g_Player_CreateFromState (st
: TStream
): Word;
605 procedure g_Player_Remove(UID
: Word);
606 procedure g_Player_ResetTeams();
607 procedure g_Player_PreUpdate();
608 procedure g_Player_UpdateAll();
609 procedure g_Player_DrawAll();
610 procedure g_Player_DrawDebug(p
: TPlayer
);
611 procedure g_Player_DrawHealth();
612 procedure g_Player_RememberAll();
613 procedure g_Player_ResetAll(Force
, Silent
: Boolean);
614 function g_Player_Get(UID
: Word): TPlayer
;
615 function g_Player_GetCount(): Byte;
616 function g_Player_GetStats(): TPlayerStatArray
;
617 function g_Player_ValidName(Name
: String): Boolean;
618 function g_Player_CreateCorpse(Player
: TPlayer
): Integer;
619 procedure g_Player_CreateGibs(fX
, fY
: Integer; ModelName
: String; fColor
: TRGB
);
620 procedure g_Player_CreateShell(fX
, fY
, dX
, dY
: Integer; T
: Byte);
621 procedure g_Player_UpdatePhysicalObjects();
622 procedure g_Player_DrawCorpses();
623 procedure g_Player_DrawShells();
624 procedure g_Player_RemoveAllCorpses();
625 procedure g_Player_Corpses_SaveState (st
: TStream
);
626 procedure g_Player_Corpses_LoadState (st
: TStream
);
627 procedure g_Player_ResetReady();
628 procedure g_Bot_Add(Team
, Difficult
: Byte; Handicap
: Integer = 100);
629 procedure g_Bot_AddList(Team
: Byte; lname
: ShortString; num
: Integer = -1; Handicap
: Integer = 100);
630 procedure g_Bot_MixNames();
631 procedure g_Bot_RemoveAll();
636 {$INCLUDE ../nogl/noGLuses.inc}
637 {$IFDEF ENABLE_HOLMES}
640 e_log
, g_map
, g_items
, g_console
, g_gfx
, Math
,
641 g_options
, g_triggers
, g_menu
, g_game
, g_grid
, e_res
,
642 wadreader
, g_main
, g_monsters
, CONFIG
, g_language
,
643 g_net
, g_netmsg
, g_window
,
646 const PLR_SAVE_VERSION
= 0;
656 diag_precision
: Byte;
660 w_prior1
: Array [WP_FIRST
..WP_LAST
] of Byte;
661 w_prior2
: Array [WP_FIRST
..WP_LAST
] of Byte;
662 w_prior3
: Array [WP_FIRST
..WP_LAST
] of Byte;
666 TIME_RESPAWN1
= 1500;
667 TIME_RESPAWN2
= 2000;
668 TIME_RESPAWN3
= 3000;
671 JET_MAX
= 540; // ~30 sec
672 PLAYER_SUIT_TIME
= 30000;
673 PLAYER_INVUL_TIME
= 30000;
674 PLAYER_INVIS_TIME
= 35000;
675 FRAG_COMBO_TIME
= 3000;
679 ANGLE_RIGHTDOWN
= -35;
681 ANGLE_LEFTDOWN
= -145;
682 PLAYER_HEADRECT
: TRectWH
= (X
:24; Y
:12; Width
:20; Height
:12);
683 WEAPONPOINT
: Array [TDirection
] of TDFPoint
= ((X
:16; Y
:32), (X
:47; Y
:32));
686 BOT_UNSAFEDIST
= 128;
687 TEAMCOLOR
: Array [TEAM_RED
..TEAM_BLUE
] of TRGB
= ((R
:255; G
:0; B
:0),
689 DIFFICULT_EASY
: TDifficult
= (DiagFire
: 32; InvisFire
: 32; DiagPrecision
: 32;
690 FlyPrecision
: 32; Cover
: 32; CloseJump
: 32;
691 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
692 DIFFICULT_MEDIUM
: TDifficult
= (DiagFire
: 127; InvisFire
: 127; DiagPrecision
: 127;
693 FlyPrecision
: 127; Cover
: 127; CloseJump
: 127;
694 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
695 DIFFICULT_HARD
: TDifficult
= (DiagFire
: 255; InvisFire
: 255; DiagPrecision
: 255;
696 FlyPrecision
: 255; Cover
: 255; CloseJump
: 255;
697 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
698 WEAPON_PRIOR1
: Array [WP_FIRST
..WP_LAST
] of Byte =
699 (WEAPON_FLAMETHROWER
, WEAPON_SUPERPULEMET
,
700 WEAPON_SHOTGUN2
, WEAPON_SHOTGUN1
,
701 WEAPON_CHAINGUN
, WEAPON_PLASMA
, WEAPON_ROCKETLAUNCHER
,
702 WEAPON_BFG
, WEAPON_PISTOL
, WEAPON_SAW
, WEAPON_KASTET
);
703 WEAPON_PRIOR2
: Array [WP_FIRST
..WP_LAST
] of Byte =
704 (WEAPON_FLAMETHROWER
, WEAPON_SUPERPULEMET
,
705 WEAPON_BFG
, WEAPON_ROCKETLAUNCHER
,
706 WEAPON_SHOTGUN2
, WEAPON_PLASMA
, WEAPON_SHOTGUN1
,
707 WEAPON_CHAINGUN
, WEAPON_PISTOL
, WEAPON_SAW
, WEAPON_KASTET
);
708 //WEAPON_PRIOR3: Array [WP_FIRST..WP_LAST] of Byte =
709 // (WEAPON_FLAMETHROWER, WEAPON_SUPERPULEMET,
710 // WEAPON_BFG, WEAPON_PLASMA, WEAPON_SHOTGUN2,
711 // WEAPON_CHAINGUN, WEAPON_SHOTGUN1, WEAPON_SAW,
712 // WEAPON_ROCKETLAUNCHER, WEAPON_PISTOL, WEAPON_KASTET);
713 WEAPON_RELOAD
: Array [WP_FIRST
..WP_LAST
] of Byte =
714 (5, 2, 6, 18, 36, 2, 12, 2, 14, 2, 2);
716 PLAYER_SIGNATURE
= $52594C50; // 'PLYR'
717 CORPSE_SIGNATURE
= $50524F43; // 'CORP'
719 BOTNAMES_FILENAME
= 'botnames.txt';
720 BOTLIST_FILENAME
= 'botlist.txt';
724 MaxCorpses
: Word = 20;
725 MaxShells
: Word = 300;
726 CurrentGib
: Integer = 0;
727 CurrentShell
: Integer = 0;
728 BotNames
: Array of String;
729 BotList
: Array of TBotProfile
;
730 SavedStates
: Array of TPlayerSavedState
;
733 function Lerp(X
, Y
, Factor
: Integer): Integer;
735 Result
:= X
+ ((Y
- X
) div Factor
);
738 function SameTeam(UID1
, UID2
: Word): Boolean;
742 if (UID1
> UID_MAX_PLAYER
) or (UID1
<= UID_MAX_GAME
) or
743 (UID2
> UID_MAX_PLAYER
) or (UID2
<= UID_MAX_GAME
) then Exit
;
745 if (g_Player_Get(UID1
) = nil) or (g_Player_Get(UID2
) = nil) then Exit
;
747 if ((g_Player_Get(UID1
).Team
= TEAM_NONE
) or
748 (g_Player_Get(UID2
).Team
= TEAM_NONE
)) then Exit
;
750 Result
:= g_Player_Get(UID1
).FTeam
= g_Player_Get(UID2
).FTeam
;
753 procedure g_Gibs_SetMax(Count
: Word);
756 SetLength(gGibs
, Count
);
758 if CurrentGib
>= Count
then
762 function g_Gibs_GetMax(): Word;
767 procedure g_Shells_SetMax(Count
: Word);
770 SetLength(gShells
, Count
);
772 if CurrentShell
>= Count
then
776 function g_Shells_GetMax(): Word;
782 procedure g_Corpses_SetMax(Count
: Word);
785 SetLength(gCorpses
, Count
);
788 function g_Corpses_GetMax(): Word;
790 Result
:= MaxCorpses
;
793 function g_Player_Create(ModelName
: String; Color
: TRGB
; Team
: Byte; Bot
: Boolean): Word;
803 // Åñòü ëè ìåñòî â gPlayers:
804 if gPlayers
<> nil then
805 for a
:= 0 to High(gPlayers
) do
806 if gPlayers
[a
] = nil then
812 // Íåò ìåñòà - ðàñøèðÿåì gPlayers:
815 SetLength(gPlayers
, Length(gPlayers
)+1);
819 // Ñîçäàåì îáúåêò èãðîêà:
821 gPlayers
[a
] := TBot
.Create()
823 gPlayers
[a
] := TPlayer
.Create();
826 gPlayers
[a
].FActualModelName
:= ModelName
;
827 gPlayers
[a
].SetModel(ModelName
);
829 // Íåò ìîäåëè - ñîçäàíèå íå âîçìîæíî:
830 if gPlayers
[a
].FModel
= nil then
834 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], [ModelName
]));
838 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
839 if Random(2) = 0 then
843 gPlayers
[a
].FPreferredTeam
:= Team
;
845 case gGameSettings
.GameMode
of
846 GM_DM
: gPlayers
[a
].FTeam
:= TEAM_NONE
;
848 GM_CTF
: gPlayers
[a
].FTeam
:= gPlayers
[a
].FPreferredTeam
;
850 GM_COOP
: gPlayers
[a
].FTeam
:= TEAM_COOP
;
853 // Åñëè êîìàíäíàÿ èãðà - êðàñèì ìîäåëü â öâåò êîìàíäû:
854 gPlayers
[a
].FColor
:= Color
;
855 if gPlayers
[a
].FTeam
in [TEAM_RED
, TEAM_BLUE
] then
856 gPlayers
[a
].FModel
.Color
:= TEAMCOLOR
[gPlayers
[a
].FTeam
]
858 gPlayers
[a
].FModel
.Color
:= Color
;
860 gPlayers
[a
].FUID
:= g_CreateUID(UID_PLAYER
);
861 gPlayers
[a
].FAlive
:= False;
863 Result
:= gPlayers
[a
].FUID
;
866 function g_Player_CreateFromState (st
: TStream
): Word;
867 var a
: Integer; ok
, Bot
: Boolean; pos
: Int64;
871 // check signature and entity type
873 if not utils
.checkSign(st
, 'PLYR') then raise XStreamError
.Create('invalid player signature');
874 if (utils
.readByte(st
) <> PLR_SAVE_VERSION
) then raise XStreamError
.Create('invalid player version');
875 Bot
:= utils
.readBool(st
);
878 // find free player slot
880 for a
:= 0 to High(gPlayers
) do
881 if gPlayers
[a
] = nil then
887 // allocate player slot
890 SetLength(gPlayers
, Length(gPlayers
)+1);
894 // create entity and load state
896 gPlayers
[a
] := TBot
.Create()
898 gPlayers
[a
] := TPlayer
.Create();
899 gPlayers
[a
].FPhysics
:= True; // ???
900 gPlayers
[a
].LoadState(st
);
902 result
:= gPlayers
[a
].FUID
;
906 procedure g_Player_ResetTeams();
910 if g_Game_IsClient
then
912 if gPlayers
= nil then
914 for a
:= Low(gPlayers
) to High(gPlayers
) do
915 if gPlayers
[a
] <> nil then
916 case gGameSettings
.GameMode
of
918 gPlayers
[a
].ChangeTeam(TEAM_NONE
);
920 if not (gPlayers
[a
].Team
in [TEAM_RED
, TEAM_BLUE
]) then
921 if gPlayers
[a
].FPreferredTeam
in [TEAM_RED
, TEAM_BLUE
] then
922 gPlayers
[a
].ChangeTeam(gPlayers
[a
].FPreferredTeam
)
925 gPlayers
[a
].ChangeTeam(TEAM_RED
)
927 gPlayers
[a
].ChangeTeam(TEAM_BLUE
);
930 gPlayers
[a
].ChangeTeam(TEAM_COOP
);
934 procedure g_Bot_Add(Team
, Difficult
: Byte; Handicap
: Integer = 100);
937 _name
, _model
: String;
940 if not g_Game_IsServer
then Exit
;
942 // Ñïèñîê íàçâàíèé ìîäåëåé:
943 m
:= g_PlayerModel_GetNames();
948 if (gGameSettings
.GameType
= GT_SINGLE
) or (gGameSettings
.GameMode
= GM_COOP
) then
949 Team
:= TEAM_COOP
// COOP
951 if gGameSettings
.GameMode
= GM_DM
then
952 Team
:= TEAM_NONE
// DM
954 if Team
= TEAM_NONE
then // CTF / TDM
956 // Àâòîáàëàíñ êîìàíä:
960 for a
:= 0 to High(gPlayers
) do
961 if gPlayers
[a
] <> nil then
963 if gPlayers
[a
].Team
= TEAM_RED
then
966 if gPlayers
[a
].Team
= TEAM_BLUE
then
976 if Random(2) = 0 then
982 // Âûáèðàåì áîòó èìÿ:
984 if BotNames
<> nil then
985 for a
:= 0 to High(BotNames
) do
986 if g_Player_ValidName(BotNames
[a
]) then
988 _name
:= BotNames
[a
];
992 // Âûáèðàåì ñëó÷àéíóþ ìîäåëü:
993 _model
:= m
[Random(Length(m
))];
996 with g_Player_Get(g_Player_Create(_model
,
997 _RGB(Min(Random(9)*32, 255),
998 Min(Random(9)*32, 255),
999 Min(Random(9)*32, 255)),
1000 Team
, True)) as TBot
do
1002 // Åñëè èìåíè íåò, äåëàåì åãî èç UID áîòà
1004 Name
:= Format('DFBOT%.5d', [UID
])
1009 1: FDifficult
:= DIFFICULT_EASY
;
1010 2: FDifficult
:= DIFFICULT_MEDIUM
;
1011 else FDifficult
:= DIFFICULT_HARD
;
1014 for a
:= WP_FIRST
to WP_LAST
do
1016 FDifficult
.WeaponPrior
[a
] := WEAPON_PRIOR1
[a
];
1017 FDifficult
.CloseWeaponPrior
[a
] := WEAPON_PRIOR2
[a
];
1018 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
1021 FHandicap
:= Handicap
;
1023 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [Name
]), True);
1025 if g_Game_IsNet
then MH_SEND_PlayerCreate(UID
);
1026 if g_Game_IsServer
and (gGameSettings
.MaxLives
> 0) then
1031 procedure g_Bot_AddList(Team
: Byte; lName
: ShortString; num
: Integer = -1; Handicap
: Integer = 100);
1034 _name
, _model
: String;
1037 if not g_Game_IsServer
then Exit
;
1039 // Ñïèñîê íàçâàíèé ìîäåëåé:
1040 m
:= g_PlayerModel_GetNames();
1045 if (gGameSettings
.GameType
= GT_SINGLE
) or (gGameSettings
.GameMode
= GM_COOP
) then
1046 Team
:= TEAM_COOP
// COOP
1048 if gGameSettings
.GameMode
= GM_DM
then
1049 Team
:= TEAM_NONE
// DM
1051 if Team
= TEAM_NONE
then
1052 Team
:= BotList
[num
].team
; // CTF / TDM
1054 // Âûáèðàåì íàñòðîéêè áîòà èç ñïèñêà ïî íîìåðó èëè èìåíè:
1055 lName
:= AnsiLowerCase(lName
);
1056 if (num
< 0) or (num
> Length(BotList
)-1) then
1058 if (num
= -1) and (lName
<> '') and (BotList
<> nil) then
1059 for a
:= 0 to High(BotList
) do
1060 if AnsiLowerCase(BotList
[a
].name
) = lName
then
1069 _name
:= BotList
[num
].name
;
1070 // Çàíÿòî - âûáèðàåì ñëó÷àéíîå:
1071 if not g_Player_ValidName(_name
) then
1073 _name
:= Format('DFBOT%.2d', [Random(100)]);
1074 until g_Player_ValidName(_name
);
1077 _model
:= BotList
[num
].model
;
1078 // Íåò òàêîé - âûáèðàåì ñëó÷àéíóþ:
1079 if not InSArray(_model
, m
) then
1080 _model
:= m
[Random(Length(m
))];
1083 with g_Player_Get(g_Player_Create(_model
, BotList
[num
].color
, Team
, True)) as TBot
do
1087 FDifficult
.DiagFire
:= BotList
[num
].diag_fire
;
1088 FDifficult
.InvisFire
:= BotList
[num
].invis_fire
;
1089 FDifficult
.DiagPrecision
:= BotList
[num
].diag_precision
;
1090 FDifficult
.FlyPrecision
:= BotList
[num
].fly_precision
;
1091 FDifficult
.Cover
:= BotList
[num
].cover
;
1092 FDifficult
.CloseJump
:= BotList
[num
].close_jump
;
1094 FHandicap
:= Handicap
;
1096 for a
:= WP_FIRST
to WP_LAST
do
1098 FDifficult
.WeaponPrior
[a
] := BotList
[num
].w_prior1
[a
];
1099 FDifficult
.CloseWeaponPrior
[a
] := BotList
[num
].w_prior2
[a
];
1100 //FDifficult.SafeWeaponPrior[a] := BotList[num].w_prior3[a];
1103 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [Name
]), True);
1105 if g_Game_IsNet
then MH_SEND_PlayerCreate(UID
);
1109 procedure g_Bot_RemoveAll();
1113 if not g_Game_IsServer
then Exit
;
1114 if gPlayers
= nil then Exit
;
1116 for a
:= 0 to High(gPlayers
) do
1117 if gPlayers
[a
] <> nil then
1118 if gPlayers
[a
] is TBot
then
1120 gPlayers
[a
].Lives
:= 0;
1121 gPlayers
[a
].Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
1122 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [gPlayers
[a
].Name
]), True);
1123 g_Player_Remove(gPlayers
[a
].FUID
);
1129 procedure g_Bot_MixNames();
1134 if BotNames
<> nil then
1135 for a
:= 0 to High(BotNames
) do
1137 b
:= Random(Length(BotNames
));
1139 Botnames
[a
] := BotNames
[b
];
1144 procedure g_Player_Remove(UID
: Word);
1148 if gPlayers
= nil then Exit
;
1150 if g_Game_IsServer
and g_Game_IsNet
then
1151 MH_SEND_PlayerDelete(UID
);
1153 for i
:= 0 to High(gPlayers
) do
1154 if gPlayers
[i
] <> nil then
1155 if gPlayers
[i
].FUID
= UID
then
1157 if gPlayers
[i
] is TPlayer
then
1158 TPlayer(gPlayers
[i
]).Free()
1160 TBot(gPlayers
[i
]).Free();
1166 procedure g_Player_Init();
1177 path
:= BOTNAMES_FILENAME
;
1178 if e_FindResource(DataDirs
, path
) = false then
1181 // ×èòàåì âîçìîæíûå èìåíà áîòîâ èç ôàéëà:
1182 AssignFile(F
, path
);
1193 SetLength(BotNames
, Length(BotNames
)+1);
1194 BotNames
[High(BotNames
)] := s
;
1202 // ×èòàåì ôàéë ñ ïàðàìåòðàìè áîòîâ:
1203 config
:= TConfig
.CreateFile(path
);
1207 while config
.SectionExists(IntToStr(a
)) do
1209 SetLength(BotList
, Length(BotList
)+1);
1211 with BotList
[High(BotList
)] do
1214 name
:= config
.ReadStr(IntToStr(a
), 'name', '');
1216 model
:= config
.ReadStr(IntToStr(a
), 'model', '');
1218 if config
.ReadStr(IntToStr(a
), 'team', 'red') = 'red' then
1223 sa
:= parse(config
.ReadStr(IntToStr(a
), 'color', ''));
1224 color
.R
:= StrToIntDef(sa
[0], 0);
1225 color
.G
:= StrToIntDef(sa
[1], 0);
1226 color
.B
:= StrToIntDef(sa
[2], 0);
1227 // Âåðîÿòíîñòü ñòðåëüáû ïîä óãëîì:
1228 diag_fire
:= config
.ReadInt(IntToStr(a
), 'diag_fire', 0);
1229 // Âåðîÿòíîñòü îòâåòíîãî îãíÿ ïî íåâèäèìîìó ñîïåðíèêó:
1230 invis_fire
:= config
.ReadInt(IntToStr(a
), 'invis_fire', 0);
1231 // Òî÷íîñòü ñòðåëüáû ïîä óãëîì:
1232 diag_precision
:= config
.ReadInt(IntToStr(a
), 'diag_precision', 0);
1233 // Òî÷íîñòü ñòðåëüáû â ïîëåòå:
1234 fly_precision
:= config
.ReadInt(IntToStr(a
), 'fly_precision', 0);
1235 // Òî÷íîñòü óêëîíåíèÿ îò ñíàðÿäîâ:
1236 cover
:= config
.ReadInt(IntToStr(a
), 'cover', 0);
1237 // Âåðîÿòíîñòü ïðûæêà ïðè ïðèáëèæåíèè ñîïåðíèêà:
1238 close_jump
:= config
.ReadInt(IntToStr(a
), 'close_jump', 0);
1239 // Ïðèîðèòåòû îðóæèÿ äëÿ äàëüíåãî áîÿ:
1240 sa
:= parse(config
.ReadStr(IntToStr(a
), 'w_prior1', ''));
1241 if Length(sa
) = 10 then
1243 w_prior1
[b
] := EnsureRange(StrToInt(sa
[b
]), 0, 9);
1244 // Ïðèîðèòåòû îðóæèÿ äëÿ áëèæíåãî áîÿ:
1245 sa
:= parse(config
.ReadStr(IntToStr(a
), 'w_prior2', ''));
1246 if Length(sa
) = 10 then
1248 w_prior2
[b
] := EnsureRange(StrToInt(sa
[b
]), 0, 9);
1250 {sa := parse(config.ReadStr(IntToStr(a), 'w_prior3', ''));
1251 if Length(sa) = 10 then
1253 w_prior3[b] := EnsureRange(StrToInt(sa[b]), 0, 9);}
1260 SetLength(SavedStates
, 0);
1263 procedure g_Player_Free();
1267 if gPlayers
<> nil then
1269 for i
:= 0 to High(gPlayers
) do
1270 if gPlayers
[i
] <> nil then
1272 if gPlayers
[i
] is TPlayer
then
1273 TPlayer(gPlayers
[i
]).Free()
1275 TBot(gPlayers
[i
]).Free();
1284 SetLength(SavedStates
, 0);
1287 procedure g_Player_PreUpdate();
1291 if gPlayers
= nil then Exit
;
1292 for i
:= 0 to High(gPlayers
) do
1293 if gPlayers
[i
] <> nil then
1294 gPlayers
[i
].PreUpdate();
1297 procedure g_Player_UpdateAll();
1301 if gPlayers
= nil then Exit
;
1303 //e_WriteLog('***g_Player_UpdateAll: ENTER', MSG_WARNING);
1304 for i
:= 0 to High(gPlayers
) do
1306 if gPlayers
[i
] <> nil then
1308 if gPlayers
[i
] is TPlayer
then
1310 gPlayers
[i
].Update();
1311 gPlayers
[i
].RealizeCurrentWeapon(); // WARNING! DO NOT MOVE THIS INTO `Update()`!
1315 // bot updates weapons in `UpdateCombat()`
1316 TBot(gPlayers
[i
]).Update();
1320 //e_WriteLog('***g_Player_UpdateAll: EXIT', MSG_WARNING);
1323 procedure g_Player_DrawAll();
1327 if gPlayers
= nil then Exit
;
1329 for i
:= 0 to High(gPlayers
) do
1330 if gPlayers
[i
] <> nil then
1331 if gPlayers
[i
] is TPlayer
then gPlayers
[i
].Draw()
1332 else TBot(gPlayers
[i
]).Draw();
1335 procedure g_Player_DrawDebug(p
: TPlayer
);
1339 if p
= nil then Exit
;
1340 if (@p
.FObj
) = nil then Exit
;
1342 e_TextureFontGetSize(gStdFont
, fW
, fH
);
1344 e_TextureFontPrint(0, 0 , 'Pos X: ' + IntToStr(p
.FObj
.X
), gStdFont
);
1345 e_TextureFontPrint(0, fH
, 'Pos Y: ' + IntToStr(p
.FObj
.Y
), gStdFont
);
1346 e_TextureFontPrint(0, fH
* 2, 'Vel X: ' + IntToStr(p
.FObj
.Vel
.X
), gStdFont
);
1347 e_TextureFontPrint(0, fH
* 3, 'Vel Y: ' + IntToStr(p
.FObj
.Vel
.Y
), gStdFont
);
1348 e_TextureFontPrint(0, fH
* 4, 'Acc X: ' + IntToStr(p
.FObj
.Accel
.X
), gStdFont
);
1349 e_TextureFontPrint(0, fH
* 5, 'Acc Y: ' + IntToStr(p
.FObj
.Accel
.Y
), gStdFont
);
1350 e_TextureFontPrint(0, fH
* 6, 'Old X: ' + IntToStr(p
.FObj
.oldX
), gStdFont
);
1351 e_TextureFontPrint(0, fH
* 7, 'Old Y: ' + IntToStr(p
.FObj
.oldY
), gStdFont
);
1354 procedure g_Player_DrawHealth();
1359 if gPlayers
= nil then Exit
;
1360 e_TextureFontGetSize(gStdFont
, fW
, fH
);
1362 for i
:= 0 to High(gPlayers
) do
1363 if gPlayers
[i
] <> nil then
1365 e_TextureFontPrint(gPlayers
[i
].FObj
.X
+ gPlayers
[i
].FObj
.Rect
.X
,
1366 gPlayers
[i
].FObj
.Y
+ gPlayers
[i
].FObj
.Rect
.Y
+ gPlayers
[i
].FObj
.Rect
.Height
- fH
* 2,
1367 IntToStr(gPlayers
[i
].FHealth
), gStdFont
);
1368 e_TextureFontPrint(gPlayers
[i
].FObj
.X
+ gPlayers
[i
].FObj
.Rect
.X
,
1369 gPlayers
[i
].FObj
.Y
+ gPlayers
[i
].FObj
.Rect
.Y
+ gPlayers
[i
].FObj
.Rect
.Height
- fH
,
1370 IntToStr(gPlayers
[i
].FArmor
), gStdFont
);
1374 function g_Player_Get(UID
: Word): TPlayer
;
1380 if gPlayers
= nil then
1383 for a
:= 0 to High(gPlayers
) do
1384 if gPlayers
[a
] <> nil then
1385 if gPlayers
[a
].FUID
= UID
then
1387 Result
:= gPlayers
[a
];
1392 function g_Player_GetCount(): Byte;
1398 if gPlayers
= nil then
1401 for a
:= 0 to High(gPlayers
) do
1402 if gPlayers
[a
] <> nil then
1403 Result
:= Result
+ 1;
1406 function g_Player_GetStats(): TPlayerStatArray
;
1412 if gPlayers
= nil then Exit
;
1414 for a
:= 0 to High(gPlayers
) do
1415 if gPlayers
[a
] <> nil then
1417 SetLength(Result
, Length(Result
)+1);
1418 with Result
[High(Result
)] do
1421 Ping
:= gPlayers
[a
].FPing
;
1422 Loss
:= gPlayers
[a
].FLoss
;
1423 Name
:= gPlayers
[a
].FName
;
1424 Team
:= gPlayers
[a
].FTeam
;
1425 Frags
:= gPlayers
[a
].FFrags
;
1426 Deaths
:= gPlayers
[a
].FDeath
;
1427 Kills
:= gPlayers
[a
].FKills
;
1428 Color
:= gPlayers
[a
].FModel
.Color
;
1429 Lives
:= gPlayers
[a
].FLives
;
1430 Spectator
:= gPlayers
[a
].FSpectator
;
1431 UID
:= gPlayers
[a
].FUID
;
1436 procedure g_Player_ResetReady();
1440 if not g_Game_IsServer
then Exit
;
1441 if gPlayers
= nil then Exit
;
1443 for a
:= 0 to High(gPlayers
) do
1444 if gPlayers
[a
] <> nil then
1446 gPlayers
[a
].FReady
:= False;
1447 if g_Game_IsNet
then
1448 MH_SEND_GameEvent(NET_EV_INTER_READY
, gPlayers
[a
].UID
, 'N');
1452 procedure g_Player_RememberAll
;
1456 for i
:= Low(gPlayers
) to High(gPlayers
) do
1457 if (gPlayers
[i
] <> nil) and gPlayers
[i
].alive
then
1458 gPlayers
[i
].RememberState
;
1461 procedure g_Player_ResetAll(Force
, Silent
: Boolean);
1465 gTeamStat
[TEAM_RED
].Goals
:= 0;
1466 gTeamStat
[TEAM_BLUE
].Goals
:= 0;
1468 if gPlayers
<> nil then
1469 for i
:= 0 to High(gPlayers
) do
1470 if gPlayers
[i
] <> nil then
1472 gPlayers
[i
].Reset(Force
);
1474 if gPlayers
[i
] is TPlayer
then
1476 if (not gPlayers
[i
].FSpectator
) or gPlayers
[i
].FWantsInGame
then
1477 gPlayers
[i
].Respawn(Silent
)
1479 gPlayers
[i
].Spectate();
1482 TBot(gPlayers
[i
]).Respawn(Silent
);
1486 function g_Player_CreateCorpse(Player
: TPlayer
): Integer;
1494 if Player
.alive
then
1497 // Ðàçðûâàåì ñâÿçü ñ ïðåæíèì òðóïîì:
1498 i
:= Player
.FCorpse
;
1499 if (i
>= 0) and (i
< Length(gCorpses
)) then
1501 if (gCorpses
[i
] <> nil) and (gCorpses
[i
].FPlayerUID
= Player
.FUID
) then
1502 gCorpses
[i
].FPlayerUID
:= 0;
1505 if Player
.FObj
.Y
>= gMapInfo
.Height
+128 then
1510 if (FHealth
>= -50) or (gGibsCount
= 0) then
1512 if (gCorpses
= nil) or (Length(gCorpses
) = 0) then
1516 for find_id
:= 0 to High(gCorpses
) do
1517 if gCorpses
[find_id
] = nil then
1524 find_id
:= Random(Length(gCorpses
));
1526 gCorpses
[find_id
] := TCorpse
.Create(FObj
.X
, FObj
.Y
, FModel
.Name
, FHealth
< -20);
1527 gCorpses
[find_id
].FColor
:= FModel
.Color
;
1528 gCorpses
[find_id
].FObj
.Vel
:= FObj
.Vel
;
1529 gCorpses
[find_id
].FObj
.Accel
:= FObj
.Accel
;
1530 gCorpses
[find_id
].FPlayerUID
:= FUID
;
1535 g_Player_CreateGibs(FObj
.X
+ PLAYER_RECT_CX
,
1536 FObj
.Y
+ PLAYER_RECT_CY
,
1537 FModel
.Name
, FModel
.Color
);
1541 procedure g_Player_CreateShell(fX
, fY
, dX
, dY
: Integer; T
: Byte);
1545 if (gShells
= nil) or (Length(gShells
) = 0) then
1548 with gShells
[CurrentShell
] do
1554 if T
= SHELL_BULLET
then
1556 if g_Texture_Get('TEXTURE_SHELL_BULLET', SID
) then
1560 Obj
.Rect
.Width
:= 4;
1561 Obj
.Rect
.Height
:= 2;
1565 if g_Texture_Get('TEXTURE_SHELL_SHELL', SID
) then
1569 Obj
.Rect
.Width
:= 7;
1570 Obj
.Rect
.Height
:= 3;
1576 g_Obj_Push(@Obj
, dX
+ Random(4)-Random(4), dY
-Random(4));
1577 positionChanged(); // this updates spatial accelerators
1578 RAngle
:= Random(360);
1579 Timeout
:= gTime
+ SHELL_TIMEOUT
;
1581 if CurrentShell
>= High(gShells
) then
1588 procedure g_Player_CreateGibs(fX
, fY
: Integer; ModelName
: string; fColor
: TRGB
);
1591 GibsArray
: TGibsArray
;
1594 if (gGibs
= nil) or (Length(gGibs
) = 0) then
1596 if not g_PlayerModel_GetGibs(ModelName
, GibsArray
) then
1598 Blood
:= g_PlayerModel_GetBlood(ModelName
);
1600 for a
:= 0 to High(GibsArray
) do
1601 with gGibs
[CurrentGib
] do
1604 ID
:= GibsArray
[a
].ID
;
1605 MaskID
:= GibsArray
[a
].MaskID
;
1608 Obj
.Rect
:= GibsArray
[a
].Rect
;
1609 Obj
.X
:= fX
-GibsArray
[a
].Rect
.X
-(GibsArray
[a
].Rect
.Width
div 2);
1610 Obj
.Y
:= fY
-GibsArray
[a
].Rect
.Y
-(GibsArray
[a
].Rect
.Height
div 2);
1611 g_Obj_PushA(@Obj
, 25 + Random(10), Random(361));
1612 positionChanged(); // this updates spatial accelerators
1613 RAngle
:= Random(360);
1615 if gBloodCount
> 0 then
1616 g_GFX_Blood(fX
, fY
, 16*gBloodCount
+Random(5*gBloodCount
), -16+Random(33), -16+Random(33),
1617 Random(48), Random(48), Blood
.R
, Blood
.G
, Blood
.B
, Blood
.Kind
);
1619 if CurrentGib
>= High(gGibs
) then
1626 procedure g_Player_UpdatePhysicalObjects();
1632 procedure ShellSound_Bounce(X
, Y
: Integer; T
: Byte);
1637 if T
= SHELL_BULLET
then
1638 g_Sound_PlayExAt('SOUND_PLAYER_CASING' + IntToStr(k
), X
, Y
)
1640 g_Sound_PlayExAt('SOUND_PLAYER_SHELL' + IntToStr(k
), X
, Y
);
1645 if gGibs
<> nil then
1646 for i
:= 0 to High(gGibs
) do
1647 if gGibs
[i
].alive
then
1654 mr
:= g_Obj_Move(@Obj
, True, False, True);
1655 positionChanged(); // this updates spatial accelerators
1657 if WordBool(mr
and MOVE_FALLOUT
) then
1663 // Îòëåòàåò îò óäàðà î ñòåíó/ïîòîëîê/ïîë:
1664 if WordBool(mr
and MOVE_HITWALL
) then
1665 Obj
.Vel
.X
:= -(vel
.X
div 2);
1666 if WordBool(mr
and (MOVE_HITCEIL
or MOVE_HITLAND
)) then
1667 Obj
.Vel
.Y
:= -(vel
.Y
div 2);
1669 if (Obj
.Vel
.X
>= 0) then
1671 RAngle
:= RAngle
+ Abs(Obj
.Vel
.X
)*6 + Abs(Obj
.Vel
.Y
);
1672 if RAngle
>= 360 then
1673 RAngle
:= RAngle
mod 360;
1674 end else begin // Counter-clockwise
1675 RAngle
:= RAngle
- Abs(Obj
.Vel
.X
)*6 - Abs(Obj
.Vel
.Y
);
1677 RAngle
:= (360 - (Abs(RAngle
) mod 360)) mod 360;
1680 // Ñîïðîòèâëåíèå âîçäóõà äëÿ êóñêà òðóïà:
1681 if gTime
mod (GAME_TICK
*3) = 0 then
1682 Obj
.Vel
.X
:= z_dec(Obj
.Vel
.X
, 1);
1686 if gCorpses
<> nil then
1687 for i
:= 0 to High(gCorpses
) do
1688 if gCorpses
[i
] <> nil then
1689 if gCorpses
[i
].State
= CORPSE_STATE_REMOVEME
then
1695 gCorpses
[i
].Update();
1698 if gShells
<> nil then
1699 for i
:= 0 to High(gShells
) do
1700 if gShells
[i
].alive
then
1707 mr
:= g_Obj_Move(@Obj
, True, False, True);
1708 positionChanged(); // this updates spatial accelerators
1710 if WordBool(mr
and MOVE_FALLOUT
) or (gShells
[i
].Timeout
< gTime
) then
1716 // Îòëåòàåò îò óäàðà î ñòåíó/ïîòîëîê/ïîë:
1717 if WordBool(mr
and MOVE_HITWALL
) then
1719 Obj
.Vel
.X
:= -(vel
.X
div 2);
1720 if not WordBool(mr
and MOVE_INWATER
) then
1721 ShellSound_Bounce(Obj
.X
, Obj
.Y
, SType
);
1723 if WordBool(mr
and (MOVE_HITCEIL
or MOVE_HITLAND
)) then
1725 Obj
.Vel
.Y
:= -(vel
.Y
div 2);
1726 if Obj
.Vel
.X
<> 0 then Obj
.Vel
.X
:= Obj
.Vel
.X
div 2;
1727 if (Obj
.Vel
.X
= 0) and (Obj
.Vel
.Y
= 0) then
1729 if RAngle
mod 90 <> 0 then
1730 RAngle
:= (RAngle
div 90) * 90;
1732 else if not WordBool(mr
and MOVE_INWATER
) then
1733 ShellSound_Bounce(Obj
.X
, Obj
.Y
, SType
);
1736 if (Obj
.Vel
.X
>= 0) then
1738 RAngle
:= RAngle
+ Abs(Obj
.Vel
.X
)*8 + Abs(Obj
.Vel
.Y
);
1739 if RAngle
>= 360 then
1740 RAngle
:= RAngle
mod 360;
1741 end else begin // Counter-clockwise
1742 RAngle
:= RAngle
- Abs(Obj
.Vel
.X
)*8 - Abs(Obj
.Vel
.Y
);
1744 RAngle
:= (360 - (Abs(RAngle
) mod 360)) mod 360;
1750 procedure TGib
.getMapBox (out x
, y
, w
, h
: Integer); inline;
1752 x
:= Obj
.X
+Obj
.Rect
.X
;
1753 y
:= Obj
.Y
+Obj
.Rect
.Y
;
1754 w
:= Obj
.Rect
.Width
;
1755 h
:= Obj
.Rect
.Height
;
1758 procedure TGib
.moveBy (dx
, dy
: Integer); inline;
1760 if (dx
<> 0) or (dy
<> 0) then
1769 procedure TShell
.getMapBox (out x
, y
, w
, h
: Integer); inline;
1773 w
:= Obj
.Rect
.Width
;
1774 h
:= Obj
.Rect
.Height
;
1777 procedure TShell
.moveBy (dx
, dy
: Integer); inline;
1779 if (dx
<> 0) or (dy
<> 0) then
1788 procedure TGib
.positionChanged (); inline; begin end;
1789 procedure TShell
.positionChanged (); inline; begin end;
1792 procedure g_Player_DrawCorpses();
1797 if gGibs
<> nil then
1798 for i
:= 0 to High(gGibs
) do
1799 if gGibs
[i
].alive
then
1802 if not g_Obj_Collide(sX
, sY
, sWidth
, sHeight
, @Obj
) then
1805 Obj
.lerp(gLerpFactor
, fX
, fY
);
1807 a
.X
:= Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2);
1808 a
.y
:= Obj
.Rect
.Y
+(Obj
.Rect
.Height
div 2);
1810 e_DrawAdv(ID
, fX
, fY
, 0, True, False, RAngle
, @a
, TMirrorType
.None
);
1813 e_DrawAdv(MaskID
, fX
, fY
, 0, True, False, RAngle
, @a
, TMirrorType
.None
);
1819 if gCorpses
<> nil then
1820 for i
:= 0 to High(gCorpses
) do
1821 if gCorpses
[i
] <> nil then
1825 procedure g_Player_DrawShells();
1830 if gShells
<> nil then
1831 for i
:= 0 to High(gShells
) do
1832 if gShells
[i
].alive
then
1835 if not g_Obj_Collide(sX
, sY
, sWidth
, sHeight
, @Obj
) then
1838 Obj
.lerp(gLerpFactor
, fX
, fY
);
1843 e_DrawAdv(SpriteID
, fX
, fY
, 0, True, False, RAngle
, @a
, TMirrorType
.None
);
1847 procedure g_Player_RemoveAllCorpses();
1853 SetLength(gGibs
, MaxGibs
);
1854 SetLength(gShells
, MaxGibs
);
1858 if gCorpses
<> nil then
1859 for i
:= 0 to High(gCorpses
) do
1863 SetLength(gCorpses
, MaxCorpses
);
1866 procedure g_Player_Corpses_SaveState (st
: TStream
);
1870 // Ñ÷èòàåì êîëè÷åñòâî ñóùåñòâóþùèõ òðóïîâ
1872 for i
:= 0 to High(gCorpses
) do if (gCorpses
[i
] <> nil) then Inc(count
);
1874 // Êîëè÷åñòâî òðóïîâ
1875 utils
.writeInt(st
, LongInt(count
));
1877 if (count
= 0) then exit
;
1880 for i
:= 0 to High(gCorpses
) do
1882 if gCorpses
[i
] <> nil then
1885 utils
.writeStr(st
, gCorpses
[i
].FModelName
);
1887 utils
.writeBool(st
, gCorpses
[i
].Mess
);
1888 // Ñîõðàíÿåì äàííûå òðóïà:
1889 gCorpses
[i
].SaveState(st
);
1895 procedure g_Player_Corpses_LoadState (st
: TStream
);
1903 g_Player_RemoveAllCorpses();
1905 // Êîëè÷åñòâî òðóïîâ:
1906 count
:= utils
.readLongInt(st
);
1907 if (count
< 0) or (count
> Length(gCorpses
)) then raise XStreamError
.Create('invalid number of corpses');
1909 if (count
= 0) then exit
;
1912 for i
:= 0 to count
-1 do
1915 str
:= utils
.readStr(st
);
1917 b
:= utils
.readBool(st
);
1919 gCorpses
[i
] := TCorpse
.Create(0, 0, str
, b
);
1920 // Çàãðóæàåì äàííûå òðóïà
1921 gCorpses
[i
].LoadState(st
);
1928 function TPlayer
.isValidViewPort (): Boolean; inline; begin result
:= (viewPortW
> 0) and (viewPortH
> 0); end;
1930 procedure TPlayer
.BFGHit();
1932 g_Weapon_BFGHit(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
1933 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2));
1934 if g_Game_IsServer
and g_Game_IsNet
then
1935 MH_SEND_Effect(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
1936 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2),
1940 procedure TPlayer
.ChangeModel(ModelName
: string);
1942 locModel
: TPlayerModel
;
1944 locModel
:= g_PlayerModel_Get(ModelName
);
1945 if locModel
= nil then Exit
;
1951 procedure TPlayer
.SetModel(ModelName
: string);
1955 m
:= g_PlayerModel_Get(ModelName
);
1958 g_SimpleError(Format(_lc
[I_GAME_ERROR_MODEL_FALLBACK
], [ModelName
]));
1959 m
:= g_PlayerModel_Get('doomer');
1962 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], ['doomer']));
1967 if FModel
<> nil then
1972 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
1973 FModel
.Color
:= FColor
1975 FModel
.Color
:= TEAMCOLOR
[FTeam
];
1976 FModel
.SetWeapon(FCurrWeap
);
1977 FModel
.SetFlag(FFlag
);
1978 SetDirection(FDirection
);
1981 procedure TPlayer
.SetColor(Color
: TRGB
);
1984 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
1985 if FModel
<> nil then FModel
.Color
:= Color
;
1990 function TPlayer
.GetColor(): TRGB
;
1992 result
:= FModel
.Color
;
1995 procedure TPlayer
.SetWeaponPrefs(Prefs
: Array of Byte);
1998 for i
:= WP_FIRST
to WP_LAST
+ 1 do
2000 if (Prefs
[i
] < 0) or (Prefs
[i
] > WP_LAST
+ 1) then
2001 FWeapPreferences
[i
] := 0
2002 else FWeapPreferences
[i
] := Prefs
[i
];
2006 procedure TPlayer
.SetWeaponPref(Weapon
, Pref
: Byte);
2008 if (Weapon
< 0) or (Weapon
> WP_LAST
+ 1) then
2010 else if (Pref
>= 0) and (Pref
<= WP_LAST
+ 1) and (Weapon
>= 0) and (Weapon
<= WP_LAST
+ 1) then
2011 FWeapPreferences
[Weapon
] := Pref
2012 else if (Weapon
>= 0) and (Weapon
<= WP_LAST
+ 1) and ((Pref
< 0) or (Pref
> WP_LAST
+ 1)) then
2013 FWeapPreferences
[Weapon
] := 0;
2016 function TPlayer
.GetWeaponPref(Weapon
: Byte) : Byte;
2018 if (Weapon
< 0) or (Weapon
> WP_LAST
+ 1) then
2020 else if (FWeapPreferences
[Weapon
] < 0) or (FWeapPreferences
[Weapon
] > WP_LAST
+ 1) then
2023 result
:= FWeapPreferences
[Weapon
];
2026 procedure TPlayer
.SwitchTeam
;
2028 if g_Game_IsClient
then
2030 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then Exit
;
2032 if gGameOn
and FAlive
then
2033 Kill(K_SIMPLEKILL
, FUID
, HIT_SELF
);
2035 if FTeam
= TEAM_RED
then
2037 ChangeTeam(TEAM_BLUE
);
2038 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_BLUE
], [FName
]), True);
2039 if g_Game_IsNet
then
2040 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM
, TEAM_BLUE
, FName
);
2044 ChangeTeam(TEAM_RED
);
2045 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_RED
], [FName
]), True);
2046 if g_Game_IsNet
then
2047 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM
, TEAM_RED
, FName
);
2049 FPreferredTeam
:= FTeam
;
2052 procedure TPlayer
.ChangeTeam(Team
: Byte);
2059 TEAM_RED
, TEAM_BLUE
:
2060 FModel
.Color
:= TEAMCOLOR
[Team
];
2062 FModel
.Color
:= FColor
;
2064 if (FTeam
<> OldTeam
) and g_Game_IsNet
and g_Game_IsServer
then
2065 MH_SEND_PlayerStats(FUID
);
2069 procedure TPlayer.CollideItem();
2074 if gItems = nil then Exit;
2075 if not FAlive then Exit;
2077 for i := 0 to High(gItems) do
2080 if (ItemType <> ITEM_NONE) and alive then
2081 if g_Obj_Collide(FObj.X+PLAYER_RECT.X, FObj.Y+PLAYER_RECT.Y, PLAYER_RECT.Width,
2082 PLAYER_RECT.Height, @Obj) then
2084 if not PickItem(ItemType, gItems[i].Respawnable, r) then Continue;
2086 if ItemType in [ITEM_SPHERE_BLUE, ITEM_SPHERE_WHITE, ITEM_INVUL] then
2087 g_Sound_PlayExAt('SOUND_ITEM_GETRULEZ', FObj.X, FObj.Y)
2088 else if ItemType in [ITEM_MEDKIT_SMALL, ITEM_MEDKIT_LARGE, ITEM_MEDKIT_BLACK] then
2089 g_Sound_PlayExAt('SOUND_ITEM_GETMED', FObj.X, FObj.Y)
2090 else g_Sound_PlayExAt('SOUND_ITEM_GETITEM', FObj.X, FObj.Y);
2092 // Íàäî óáðàòü ñ êàðòû, åñëè ýòî íå êëþ÷, êîòîðûì íóæíî ïîäåëèòñÿ ñ äðóãèì èãðîêîì:
2093 if r and not ((ItemType in [ITEM_KEY_RED, ITEM_KEY_GREEN, ITEM_KEY_BLUE]) and
2094 (gGameSettings.GameType = GT_SINGLE) and
2095 (g_Player_GetCount() > 1)) then
2096 if not Respawnable then g_Items_Remove(i) else g_Items_Pick(i);
2102 function TPlayer
.CollideLevel(XInc
, YInc
: Integer): Boolean;
2104 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
2105 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_WALL
,
2109 constructor TPlayer
.Create();
2115 mEDamageType
:= HIT_SOME
;
2121 FSawSound
:= TPlayableSound
.Create();
2122 FSawSoundIdle
:= TPlayableSound
.Create();
2123 FSawSoundHit
:= TPlayableSound
.Create();
2124 FSawSoundSelect
:= TPlayableSound
.Create();
2125 FFlameSoundOn
:= TPlayableSound
.Create();
2126 FFlameSoundOff
:= TPlayableSound
.Create();
2127 FFlameSoundWork
:= TPlayableSound
.Create();
2128 FJetSoundFly
:= TPlayableSound
.Create();
2129 FJetSoundOn
:= TPlayableSound
.Create();
2130 FJetSoundOff
:= TPlayableSound
.Create();
2132 FSawSound
.SetByName('SOUND_WEAPON_FIRESAW');
2133 FSawSoundIdle
.SetByName('SOUND_WEAPON_IDLESAW');
2134 FSawSoundHit
.SetByName('SOUND_WEAPON_HITSAW');
2135 FSawSoundSelect
.SetByName('SOUND_WEAPON_SELECTSAW');
2136 FFlameSoundOn
.SetByName('SOUND_WEAPON_FLAMEON');
2137 FFlameSoundOff
.SetByName('SOUND_WEAPON_FLAMEOFF');
2138 FFlameSoundWork
.SetByName('SOUND_WEAPON_FLAMEWORK');
2139 FJetSoundFly
.SetByName('SOUND_PLAYER_JETFLY');
2140 FJetSoundOn
.SetByName('SOUND_PLAYER_JETON');
2141 FJetSoundOff
.SetByName('SOUND_PLAYER_JETOFF');
2143 FSpectatePlayer
:= -1;
2147 FSavedStateNum
:= -1;
2155 FActualModelName
:= 'doomer';
2158 FObj
.Rect
:= PLAYER_RECT
;
2160 FBFGFireCounter
:= -1;
2161 FJustTeleported
:= False;
2164 FWaitForFirstSpawn
:= false;
2169 procedure TPlayer
.positionChanged (); inline;
2173 procedure TPlayer
.doDamage (v
: Integer);
2175 if (v
<= 0) then exit
;
2176 if (v
> 32767) then v
:= 32767;
2177 Damage(v
, 0, 0, 0, mEDamageType
);
2180 procedure TPlayer
.Damage(value
: Word; SpawnerUID
: Word; vx
, vy
: Integer; t
: Byte);
2184 if (not g_Game_IsClient
) and (not FAlive
) then
2189 // Íåóÿçâèìîñòü íå ñïàñàåò îò ëîâóøåê:
2190 if ((t
= HIT_TRAP
) or (t
= HIT_SELF
)) and (not FGodMode
) then
2192 if not g_Game_IsClient
then
2195 if t
= HIT_TRAP
then
2197 // Ëîâóøêà óáèâàåò ñðàçó:
2199 Kill(K_EXTRAHARDKILL
, SpawnerUID
, t
);
2201 if t
= HIT_SELF
then
2205 Kill(K_SIMPLEKILL
, SpawnerUID
, t
);
2208 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
2209 FMegaRulez
[MR_SUIT
] := 0;
2210 FMegaRulez
[MR_INVUL
] := 0;
2211 FMegaRulez
[MR_INVIS
] := 0;
2216 // Íî îò îñòàëüíîãî ñïàñàåò:
2217 if FMegaRulez
[MR_INVUL
] >= gTime
then
2224 // Åñëè åñòü óðîí ñâîèì, èëè ðàíèë ñàì ñåáÿ, èëè òåáÿ ðàíèë ïðîòèâíèê:
2225 if LongBool(gGameSettings
.Options
and GAME_OPTION_TEAMDAMAGE
) or
2226 (SpawnerUID
= FUID
) or
2227 (not SameTeam(FUID
, SpawnerUID
)) then
2229 FLastSpawnerUID
:= SpawnerUID
;
2231 // Êðîâü (ïóçûðüêè, åñëè â âîäå):
2232 if gBloodCount
> 0 then
2234 c
:= Min(value
, 200)*gBloodCount
+ Random(Min(value
, 200) div 2);
2235 if value
div 4 <= c
then
2236 c
:= c
- (value
div 4)
2240 if (t
= HIT_SOME
) and (vx
= 0) and (vy
= 0) then
2244 HIT_TRAP
, HIT_ACID
, HIT_FLAME
, HIT_SELF
: MakeBloodSimple(c
);
2245 HIT_BFG
, HIT_ROCKET
, HIT_SOME
: MakeBloodVector(c
, vx
, vy
);
2248 if t
= HIT_WATER
then
2249 g_GFX_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
2250 FObj
.Y
+PLAYER_RECT
.Y
-4, value
div 2, 8, 4);
2255 Inc(FDamageBuffer
, value
);
2259 FPain
:= FPain
+ value
;
2262 if g_Game_IsServer
and g_Game_IsNet
then
2264 MH_SEND_PlayerDamage(FUID
, t
, SpawnerUID
, value
, vx
, vy
);
2265 MH_SEND_PlayerStats(FUID
);
2266 MH_SEND_PlayerPos(False, FUID
);
2270 function TPlayer
.Heal(value
: Word; Soft
: Boolean): Boolean;
2273 if g_Game_IsClient
then
2278 if Soft
and (FHealth
< PLAYER_HP_SOFT
) then
2280 IncMax(FHealth
, value
, PLAYER_HP_SOFT
);
2283 if (not Soft
) and (FHealth
< PLAYER_HP_LIMIT
) then
2285 IncMax(FHealth
, value
, PLAYER_HP_LIMIT
);
2289 if Result
and g_Game_IsServer
and g_Game_IsNet
then
2290 MH_SEND_PlayerStats(FUID
);
2293 destructor TPlayer
.Destroy();
2295 if (gPlayer1
<> nil) and (gPlayer1
.FUID
= FUID
) then
2297 if (gPlayer2
<> nil) and (gPlayer2
.FUID
= FUID
) then
2301 FSawSoundIdle
.Free();
2302 FSawSoundHit
.Free();
2303 FSawSoundSelect
.Free();
2304 FFlameSoundOn
.Free();
2305 FFlameSoundOff
.Free();
2306 FFlameSoundWork
.Free();
2307 FJetSoundFly
.Free();
2309 FJetSoundOff
.Free();
2311 if FPunchAnim
<> nil then
2317 procedure TPlayer
.DrawIndicator(Color
: TRGB
);
2319 indX
, indY
, fX
, fY
, fSlope
: Integer;
2329 FObj
.lerp(gLerpFactor
, fX
, fY
);
2330 fSlope
:= nlerp(FSlopeOld
, FObj
.slopeUpLeft
, gLerpFactor
);
2332 case gPlayerIndicatorStyle
of
2335 if g_Texture_Get('TEXTURE_PLAYER_INDICATOR', ID
) then
2337 e_GetTextureSize(ID
, @indW
, @indH
);
2341 if (FObj
.X
+ FObj
.Rect
.X
) < 0 then
2344 indX
:= fX
+ FObj
.Rect
.X
+ FObj
.Rect
.Width
;
2345 indY
:= fY
+ FObj
.Rect
.Y
+ (FObj
.Rect
.Height
- indW
) div 2;
2348 else if (FObj
.X
+ FObj
.Rect
.X
+ FObj
.Rect
.Width
) > Max(gMapInfo
.Width
, gPlayerScreenSize
.X
) then
2351 indX
:= fX
+ FObj
.Rect
.X
- indH
;
2352 indY
:= fY
+ FObj
.Rect
.Y
+ (FObj
.Rect
.Height
- indW
) div 2;
2355 else if (FObj
.Y
- indH
) < 0 then
2358 indX
:= fX
+ FObj
.Rect
.X
+ (FObj
.Rect
.Width
- indW
) div 2;
2359 indY
:= fY
+ FObj
.Rect
.Y
+ FObj
.Rect
.Height
;
2365 indX
:= fX
+ FObj
.Rect
.X
+ (FObj
.Rect
.Width
- indW
) div 2;
2369 indY
:= indY
+ fSlope
;
2370 indX
:= EnsureRange(indX
, 0, Max(gMapInfo
.Width
, gPlayerScreenSize
.X
) - indW
);
2371 indY
:= EnsureRange(indY
, 0, Max(gMapInfo
.Height
, gPlayerScreenSize
.Y
) - indH
);
2375 e_DrawAdv(ID
, indX
, indY
, 0, True, False, indA
, @a
);
2382 e_TextureFontGetSize(gStdFont
, nW
, nH
);
2383 indX
:= fX
+ FObj
.Rect
.X
+ (FObj
.Rect
.Width
- Length(FName
) * nW
) div 2;
2384 indY
:= fY
- nH
+ fSlope
;
2385 e_TextureFontPrintEx(indX
, indY
, FName
, gStdFont
, Color
.R
, Color
.G
, Color
.B
, 1.0, True);
2391 procedure TPlayer
.DrawBubble();
2393 bubX
, bubY
, fX
, fY
: Integer;
2396 Rw
, Gw
, Bw
: SmallInt;
2400 CObj
:= getCameraObj();
2401 CObj
.lerp(gLerpFactor
, fX
, fY
);
2402 // NB: _F_Obj.Rect is used to keep the bubble higher; this is not a mistake
2403 bubX
:= fX
+FObj
.Rect
.X
+ IfThen(FDirection
= TDirection
.D_LEFT
, -4, 18);
2404 bubY
:= fY
+FObj
.Rect
.Y
- 18;
2412 1: // simple textual non-bubble
2414 bubX
:= fX
+FObj
.Rect
.X
- 11;
2415 bubY
:= fY
+FObj
.Rect
.Y
- 17;
2416 e_TextureFontPrint(bubX
, bubY
, '[...]', gStdFont
);
2419 2: // advanced pixel-perfect bubble
2421 if FTeam
= TEAM_RED
then
2424 if FTeam
= TEAM_BLUE
then
2427 3: // colored bubble
2429 Rb
:= FModel
.Color
.R
;
2430 Gb
:= FModel
.Color
.G
;
2431 Bb
:= FModel
.Color
.B
;
2432 Rw
:= Min(Rb
* 2 + 64, 255);
2433 Gw
:= Min(Gb
* 2 + 64, 255);
2434 Bw
:= Min(Bb
* 2 + 64, 255);
2435 if (Abs(Rw
- Rb
) < 32)
2436 or (Abs(Gw
- Gb
) < 32)
2437 or (Abs(Bw
- Bb
) < 32) then
2439 Rb
:= Max(Rw
div 2 - 16, 0);
2440 Gb
:= Max(Gw
div 2 - 16, 0);
2441 Bb
:= Max(Bw
div 2 - 16, 0);
2444 4: // custom textured bubble
2446 if g_Texture_Get('TEXTURE_PLAYER_TALKBUBBLE', ID
) then
2447 if FDirection
= TDirection
.D_RIGHT
then
2448 e_Draw(ID
, bubX
- 6, bubY
- 7, 0, True, False)
2450 e_Draw(ID
, bubX
- 6, bubY
- 7, 0, True, False, TMirrorType
.Horizontal
);
2456 e_DrawQuad(bubX
+ 1, bubY
, bubX
+ 18, bubY
+ 13, Rb
, Gb
, Bb
);
2457 e_DrawQuad(bubX
, bubY
+ 1, bubX
+ 19, bubY
+ 12, Rb
, Gb
, Bb
);
2459 e_DrawFillQuad(bubX
+ 1, bubY
+ 1, bubX
+ 18, bubY
+ 12, Rw
, Gw
, Bw
, 0);
2462 Dot
:= IfThen(FDirection
= TDirection
.D_LEFT
, 14, 5);
2463 e_DrawLine(1, bubX
+ Dot
, bubY
+ 14, bubX
+ Dot
, bubY
+ 16, Rb
, Gb
, Bb
);
2464 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
);
2465 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
);
2466 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
);
2467 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
);
2471 e_DrawFillQuad(bubX
+ Dot
, bubY
+ 8, bubX
+ Dot
+ 1, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2472 e_DrawFillQuad(bubX
+ Dot
+ 3, bubY
+ 8, bubX
+ Dot
+ 4, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2473 e_DrawFillQuad(bubX
+ Dot
+ 6, bubY
+ 8, bubX
+ Dot
+ 7, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2476 procedure TPlayer
.Draw();
2481 Mirror
: TMirrorType
;
2482 fX
, fY
, fSlope
: Integer;
2484 FObj
.lerp(gLerpFactor
, fX
, fY
);
2485 fSlope
:= nlerp(FSlopeOld
, FObj
.slopeUpLeft
, gLerpFactor
);
2489 if Direction
= TDirection
.D_RIGHT
then
2490 Mirror
:= TMirrorType
.None
2492 Mirror
:= TMirrorType
.Horizontal
;
2494 if FPunchAnim
<> nil then
2496 FPunchAnim
.Draw(fX
+IfThen(Direction
= TDirection
.D_LEFT
, 15-FObj
.Rect
.X
, FObj
.Rect
.X
-15),
2497 fY
+fSlope
+FObj
.Rect
.Y
-11, Mirror
);
2498 if FPunchAnim
.played
then
2505 if (FMegaRulez
[MR_INVUL
] > gTime
) and ((gPlayerDrawn
<> Self
) or (FSpawnInvul
>= gTime
)) then
2506 if g_Texture_Get('TEXTURE_PLAYER_INVULPENTA', ID
) then
2508 e_GetTextureSize(ID
, @w
, @h
);
2509 if FDirection
= TDirection
.D_LEFT
then
2510 e_Draw(ID
, fX
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2)-(w
div 2)+4,
2511 fY
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2)-(h
div 2)-7+fSlope
, 0, True, False)
2513 e_Draw(ID
, fX
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2)-(w
div 2)-2,
2514 fY
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2)-(h
div 2)-7+fSlope
, 0, True, False);
2517 if FMegaRulez
[MR_INVIS
] > gTime
then
2519 if (gPlayerDrawn
<> nil) and ((Self
= gPlayerDrawn
) or
2520 ((FTeam
= gPlayerDrawn
.Team
) and (gGameSettings
.GameMode
<> GM_DM
))) then
2522 if (FMegaRulez
[MR_INVIS
] - gTime
) <= 2100 then
2523 dr
:= not Odd((FMegaRulez
[MR_INVIS
] - gTime
) div 300)
2527 FModel
.Draw(fX
, fY
+fSlope
, 200)
2529 FModel
.Draw(fX
, fY
+fSlope
);
2532 FModel
.Draw(fX
, fY
+fSlope
, 254);
2535 FModel
.Draw(fX
, fY
+fSlope
);
2538 if g_debug_Frames
then
2540 e_DrawQuad(FObj
.X
+FObj
.Rect
.X
,
2542 FObj
.X
+FObj
.Rect
.X
+FObj
.Rect
.Width
-1,
2543 FObj
.Y
+FObj
.Rect
.Y
+FObj
.Rect
.Height
-1,
2547 if (gChatBubble
> 0) and (FKeys
[KEY_CHAT
].Pressed
) and not FGhost
then
2548 if (FMegaRulez
[MR_INVIS
] <= gTime
) or ((gPlayerDrawn
<> nil) and ((Self
= gPlayerDrawn
) or
2549 ((FTeam
= gPlayerDrawn
.Team
) and (gGameSettings
.GameMode
<> GM_DM
)))) then
2551 // e_DrawPoint(5, 335, 288, 255, 0, 0); // DL, UR, DL, UR
2552 if gAimLine
and alive
and
2553 ((Self
= gPlayer1
) or (Self
= gPlayer2
)) then
2558 procedure TPlayer
.DrawAim();
2559 procedure drawCast (sz
: Integer; ax0
, ay0
, ax1
, ay1
: Integer);
2564 {$IFDEF ENABLE_HOLMES}
2565 if isValidViewPort
and (self
= gPlayer1
) then
2567 g_Holmes_plrLaser(ax0
, ay0
, ax1
, ay1
);
2571 e_DrawLine(sz
, ax0
, ay0
, ax1
, ay1
, 255, 0, 0, 96);
2572 if (g_Map_traceToNearestWall(ax0
, ay0
, ax1
, ay1
, @ex
, @ey
) <> nil) then
2574 e_DrawLine(sz
, ax0
, ay0
, ex
, ey
, 0, 255, 0, 96);
2578 e_DrawLine(sz
, ax0
, ay0
, ex
, ey
, 0, 0, 255, 96);
2583 wx
, wy
, xx
, yy
: Integer;
2587 wx
:= FObj
.X
+ WEAPONPOINT
[FDirection
].X
+ IfThen(FDirection
= TDirection
.D_LEFT
, 7, -7);
2588 wy
:= FObj
.Y
+ WEAPONPOINT
[FDirection
].Y
;
2597 1: begin // Chainsaw
2604 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2605 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2606 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2607 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2612 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2613 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2614 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2615 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2617 4: begin // Double Shotgun
2620 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2621 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2622 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2623 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2625 5: begin // Chaingun
2628 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2629 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2630 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2631 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2633 6: begin // Rocket Launcher
2636 if angle
= ANGLE_RIGHTUP
then Inc(angle
, 2);
2637 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2638 if angle
= ANGLE_LEFTUP
then Dec(angle
, 2);
2639 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2641 7: begin // Plasmagun
2644 if angle
= ANGLE_RIGHTUP
then Inc(angle
);
2645 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 3);
2646 if angle
= ANGLE_LEFTUP
then Dec(angle
);
2647 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 3);
2652 if angle
= ANGLE_RIGHTUP
then Inc(angle
, 1);
2653 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 2);
2654 if angle
= ANGLE_LEFTUP
then Dec(angle
, 1);
2655 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 2);
2657 9: begin // Super Chaingun
2660 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2661 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2662 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2663 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2666 xx
:= Trunc(Cos(-DegToRad(angle
)) * len
) + wx
;
2667 yy
:= Trunc(Sin(-DegToRad(angle
)) * len
) + wy
;
2668 {$IF DEFINED(D2F_DEBUG)}
2669 drawCast(sz
, wx
, wy
, xx
, yy
);
2671 e_DrawLine(sz
, wx
, wy
, xx
, yy
, 255, 0, 0, 96);
2675 procedure TPlayer
.DrawGUI();
2678 X
, Y
, SY
, a
, p
, m
: Integer;
2682 stat
: TPlayerStatArray
;
2684 X
:= gPlayerScreenSize
.X
;
2685 SY
:= gPlayerScreenSize
.Y
;
2688 if gShowGoals
and (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
2690 if gGameSettings
.GameMode
= GM_CTF
then
2694 if gGameSettings
.GameMode
= GM_CTF
then
2696 s
:= 'TEXTURE_PLAYER_REDFLAG';
2697 if gFlags
[FLAG_RED
].State
= FLAG_STATE_CAPTURED
then
2698 s
:= 'TEXTURE_PLAYER_REDFLAG_S';
2699 if gFlags
[FLAG_RED
].State
= FLAG_STATE_DROPPED
then
2700 s
:= 'TEXTURE_PLAYER_REDFLAG_D';
2701 if g_Texture_Get(s
, ID
) then
2702 e_Draw(ID
, X
-16-32, 240-72-4, 0, True, False);
2705 s
:= IntToStr(gTeamStat
[TEAM_RED
].Goals
);
2706 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2707 e_CharFont_PrintEx(gMenuFont
, X
-16-a
-tw
, 240-72-4, s
, TEAMCOLOR
[TEAM_RED
]);
2709 if gGameSettings
.GameMode
= GM_CTF
then
2711 s
:= 'TEXTURE_PLAYER_BLUEFLAG';
2712 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_CAPTURED
then
2713 s
:= 'TEXTURE_PLAYER_BLUEFLAG_S';
2714 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_DROPPED
then
2715 s
:= 'TEXTURE_PLAYER_BLUEFLAG_D';
2716 if g_Texture_Get(s
, ID
) then
2717 e_Draw(ID
, X
-16-32, 240-32-4, 0, True, False);
2720 s
:= IntToStr(gTeamStat
[TEAM_BLUE
].Goals
);
2721 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2722 e_CharFont_PrintEx(gMenuFont
, X
-16-a
-tw
, 240-32-4, s
, TEAMCOLOR
[TEAM_BLUE
]);
2725 if g_Texture_Get('TEXTURE_PLAYER_HUDBG', ID
) then
2726 e_DrawFill(ID
, X
, 0, 1, (gPlayerScreenSize
.Y
div 256)+IfThen(gPlayerScreenSize
.Y
mod 256 > 0, 1, 0),
2729 if g_Texture_Get('TEXTURE_PLAYER_HUD', ID
) then
2730 e_Draw(ID
, X
+2, Y
, 0, True, False);
2732 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
2736 s
:= IntToStr(Frags
);
2737 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2738 e_CharFont_PrintEx(gMenuFont
, X
-16-tw
, Y
, s
, _RGB(255, 0, 0));
2743 stat
:= g_Player_GetStats();
2748 for a
:= 0 to High(stat
) do
2749 if stat
[a
].Name
<> Name
then
2751 if stat
[a
].Frags
> m
then m
:= stat
[a
].Frags
;
2752 if stat
[a
].Frags
> Frags
then p
:= p
+1;
2756 s
:= IntToStr(p
)+' / '+IntToStr(Length(stat
))+' ';
2757 if Frags
>= m
then s
:= s
+'+' else s
:= s
+'-';
2758 s
:= s
+IntToStr(Abs(Frags
-m
));
2760 e_CharFont_GetSize(gMenuSmallFont
, s
, tw
, th
);
2761 e_CharFont_PrintEx(gMenuSmallFont
, X
-16-tw
, Y
+32, s
, _RGB(255, 0, 0));
2764 if gLMSRespawn
> LMS_RESPAWN_NONE
then
2766 s
:= _lc
[I_GAME_WARMUP
];
2767 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2768 s
:= s
+ ': ' + IntToStr((gLMSRespawnTime
- gTime
) div 1000);
2769 e_CharFont_PrintEx(gMenuFont
, X
-64-tw
, SY
-32, s
, _RGB(0, 255, 0));
2771 else if gShowLives
and (gGameSettings
.MaxLives
> 0) then
2773 s
:= IntToStr(Lives
);
2774 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2775 e_CharFont_PrintEx(gMenuFont
, X
-16-tw
, SY
-32, s
, _RGB(0, 255, 0));
2779 e_CharFont_GetSize(gMenuSmallFont
, FName
, tw
, th
);
2780 e_CharFont_PrintEx(gMenuSmallFont
, X
+98-(tw
div 2), Y
+8, FName
, _RGB(255, 0, 0));
2782 if R_BERSERK
in FRulez
then
2783 e_Draw(gItemsTexturesID
[ITEM_MEDKIT_BLACK
], X
+37, Y
+45, 0, True, False)
2785 e_Draw(gItemsTexturesID
[ITEM_MEDKIT_LARGE
], X
+37, Y
+45, 0, True, False);
2787 if g_Texture_Get('TEXTURE_PLAYER_ARMORHUD', ID
) then
2788 e_Draw(ID
, X
+36, Y
+77, 0, True, False);
2790 s
:= IntToStr(IfThen(FHealth
> 0, FHealth
, 0));
2791 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2792 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+40, s
, _RGB(255, 0, 0));
2794 s
:= IntToStr(FArmor
);
2795 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2796 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+68, s
, _RGB(255, 0, 0));
2798 s
:= IntToStr(GetAmmoByWeapon(FCurrWeap
));
2804 ID
:= gItemsTexturesID
[ITEM_WEAPON_KASTET
];
2809 ID
:= gItemsTexturesID
[ITEM_WEAPON_SAW
];
2811 WEAPON_PISTOL
: ID
:= gItemsTexturesID
[ITEM_WEAPON_PISTOL
];
2812 WEAPON_CHAINGUN
: ID
:= gItemsTexturesID
[ITEM_WEAPON_CHAINGUN
];
2813 WEAPON_SHOTGUN1
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SHOTGUN1
];
2814 WEAPON_SHOTGUN2
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SHOTGUN2
];
2815 WEAPON_SUPERPULEMET
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SUPERPULEMET
];
2816 WEAPON_ROCKETLAUNCHER
: ID
:= gItemsTexturesID
[ITEM_WEAPON_ROCKETLAUNCHER
];
2817 WEAPON_PLASMA
: ID
:= gItemsTexturesID
[ITEM_WEAPON_PLASMA
];
2818 WEAPON_BFG
: ID
:= gItemsTexturesID
[ITEM_WEAPON_BFG
];
2819 WEAPON_FLAMETHROWER
: ID
:= gItemsTexturesID
[ITEM_WEAPON_FLAMETHROWER
];
2822 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2823 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+158, s
, _RGB(255, 0, 0));
2824 e_Draw(ID
, X
+20, Y
+160, 0, True, False);
2826 if R_KEY_RED
in FRulez
then
2827 e_Draw(gItemsTexturesID
[ITEM_KEY_RED
], X
+78, Y
+214, 0, True, False);
2829 if R_KEY_GREEN
in FRulez
then
2830 e_Draw(gItemsTexturesID
[ITEM_KEY_GREEN
], X
+95, Y
+214, 0, True, False);
2832 if R_KEY_BLUE
in FRulez
then
2833 e_Draw(gItemsTexturesID
[ITEM_KEY_BLUE
], X
+112, Y
+214, 0, True, False);
2835 if FJetFuel
> 0 then
2837 if g_Texture_Get('TEXTURE_PLAYER_HUDAIR', ID
) then
2838 e_Draw(ID
, X
+2, Y
+116, 0, True, False);
2839 if g_Texture_Get('TEXTURE_PLAYER_HUDJET', ID
) then
2840 e_Draw(ID
, X
+2, Y
+126, 0, True, False);
2841 e_DrawLine(4, X
+16, Y
+122, X
+16+Trunc(168*IfThen(FAir
> 0, FAir
, 0)/AIR_MAX
), Y
+122, 0, 0, 196);
2842 e_DrawLine(4, X
+16, Y
+132, X
+16+Trunc(168*FJetFuel
/JET_MAX
), Y
+132, 208, 0, 0);
2846 if g_Texture_Get('TEXTURE_PLAYER_HUDAIR', ID
) then
2847 e_Draw(ID
, X
+2, Y
+124, 0, True, False);
2848 e_DrawLine(4, X
+16, Y
+130, X
+16+Trunc(168*IfThen(FAir
> 0, FAir
, 0)/AIR_MAX
), Y
+130, 0, 0, 196);
2851 if gShowPing
and g_Game_IsClient
then
2853 s
:= _lc
[I_GAME_PING_HUD
] + IntToStr(NetPeer
.lastRoundTripTime
) + _lc
[I_NET_SLIST_PING_MS
];
2854 e_TextureFontPrint(X
+ 4, Y
+ 242, s
, gStdFont
);
2860 e_TextureFontPrint(X
+ 4, Y
+ 242, _lc
[I_PLAYER_SPECT
], gStdFont
);
2861 e_TextureFontPrint(X
+ 4, Y
+ 258, _lc
[I_PLAYER_SPECT2
], gStdFont
);
2862 e_TextureFontPrint(X
+ 4, Y
+ 274, _lc
[I_PLAYER_SPECT1
], gStdFont
);
2865 e_TextureFontGetSize(gStdFont
, cw
, ch
);
2866 s
:= _lc
[I_PLAYER_SPECT4
];
2867 e_TextureFontPrintEx(gScreenWidth
div 2 - cw
*(Length(s
) div 2),
2868 gScreenHeight
-4-ch
, s
, gStdFont
, 255, 255, 255, 1, True);
2869 e_TextureFontPrint(X
+ 4, Y
+ 290, _lc
[I_PLAYER_SPECT1S
], gStdFont
);
2875 procedure TPlayer
.DrawRulez();
2879 // Ïðè âçÿòèè íåóÿçâèìîñòè ðèñóåòñÿ èíâåðñèîííûé áåëûé ôîí
2880 if (FMegaRulez
[MR_INVUL
] >= gTime
) and (FSpawnInvul
< gTime
) then
2882 if (FMegaRulez
[MR_INVUL
]-gTime
) <= 2100 then
2883 dr
:= not Odd((FMegaRulez
[MR_INVUL
]-gTime
) div 300)
2888 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2889 191, 191, 191, 0, TBlending
.Invert
);
2892 // Ïðè âçÿòèè çàùèòíîãî êîñòþìà ðèñóåòñÿ çåëåíîâàòûé ôîí
2893 if FMegaRulez
[MR_SUIT
] >= gTime
then
2895 if (FMegaRulez
[MR_SUIT
]-gTime
) <= 2100 then
2896 dr
:= not Odd((FMegaRulez
[MR_SUIT
]-gTime
) div 300)
2901 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2902 0, 96, 0, 200, TBlending
.None
);
2905 // Ïðè âçÿòèè áåðñåðêà ðèñóåòñÿ êðàñíîâàòûé ôîí
2906 if (FBerserk
>= 0) and (LongWord(FBerserk
) >= gTime
) and (gFlash
= 2) then
2908 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2909 255, 0, 0, 200, TBlending
.None
);
2913 procedure TPlayer
.DrawPain();
2917 if FPain
= 0 then Exit
;
2921 if a
< 15 then h
:= 0
2922 else if a
< 35 then h
:= 1
2923 else if a
< 55 then h
:= 2
2924 else if a
< 75 then h
:= 3
2925 else if a
< 95 then h
:= 4
2928 //if a > 255 then a := 255;
2930 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1, 255, 0, 0, 255-h
*50);
2931 //e_DrawFillQuad(0, 0, gPlayerScreenSize.X-1, gPlayerScreenSize.Y-1, 255-min(128, a), 255-a, 255-a, 0, B_FILTER);
2934 procedure TPlayer
.DrawPickup();
2938 if FPickup
= 0 then Exit
;
2942 if a
< 15 then h
:= 1
2943 else if a
< 35 then h
:= 2
2944 else if a
< 55 then h
:= 3
2945 else if a
< 75 then h
:= 4
2948 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1, 150, 200, 150, 255-h
*50);
2951 procedure TPlayer
.DoPunch();
2956 if FPunchAnim
<> nil then begin
2961 st
:= 'FRAMES_PUNCH';
2962 if R_BERSERK
in FRulez
then
2963 st
:= st
+ '_BERSERK';
2964 if FKeys
[KEY_UP
].Pressed
then
2966 else if FKeys
[KEY_DOWN
].Pressed
then
2968 g_Frames_Get(id
, st
);
2969 FPunchAnim
:= TAnimation
.Create(id
, False, 1);
2972 procedure TPlayer
.Fire();
2974 f
, DidFire
: Boolean;
2975 wx
, wy
, xd
, yd
: Integer;
2978 if g_Game_IsClient
then Exit
;
2979 // FBFGFireCounter - âðåìÿ ïåðåä âûñòðåëîì (äëÿ BFG)
2980 // FReloading - âðåìÿ ïîñëå âûñòðåëà (äëÿ âñåãî)
2988 if FReloading
[FCurrWeap
] <> 0 then Exit
;
2993 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
2994 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
2995 xd
:= wx
+IfThen(FDirection
= TDirection
.D_LEFT
, -30, 30);
2996 yd
:= wy
+firediry();
3002 if R_BERSERK
in FRulez
then
3004 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
3005 locobj
.X
:= FObj
.X
+FObj
.Rect
.X
;
3006 locobj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
3009 locobj
.rect
.Width
:= 39;
3010 locobj
.rect
.Height
:= 52;
3011 locobj
.Vel
.X
:= (xd
-wx
) div 2;
3012 locobj
.Vel
.Y
:= (yd
-wy
) div 2;
3013 locobj
.Accel
.X
:= xd
-wx
;
3014 locobj
.Accel
.y
:= yd
-wy
;
3016 if g_Weapon_Hit(@locobj
, 50, FUID
, HIT_SOME
) <> 0 then
3017 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
3019 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
3021 if (gFlash
= 1) and (FPain
< 50) then FPain
:= min(FPain
+ 25, 50);
3025 g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
3029 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3034 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
3035 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
3037 FSawSoundSelect
.Stop();
3039 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
3041 else if not FSawSoundHit
.IsPlaying() then
3043 FSawSoundSelect
.Stop();
3044 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
3047 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3053 if FAmmo
[A_BULLETS
] > 0 then
3055 g_Weapon_pistol(wx
, wy
, xd
, yd
, FUID
);
3056 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3057 Dec(FAmmo
[A_BULLETS
]);
3058 FFireAngle
:= FAngle
;
3061 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
3062 GameVelX
, GameVelY
-2, SHELL_BULLET
);
3066 if FAmmo
[A_SHELLS
] > 0 then
3068 g_Weapon_shotgun(wx
, wy
, xd
, yd
, FUID
);
3069 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', wx
, wy
);
3070 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3071 Dec(FAmmo
[A_SHELLS
]);
3072 FFireAngle
:= FAngle
;
3076 FShellType
:= SHELL_SHELL
;
3080 if FAmmo
[A_SHELLS
] >= 2 then
3082 g_Weapon_dshotgun(wx
, wy
, xd
, yd
, FUID
);
3083 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3084 Dec(FAmmo
[A_SHELLS
], 2);
3085 FFireAngle
:= FAngle
;
3089 FShellType
:= SHELL_DBLSHELL
;
3093 if FAmmo
[A_BULLETS
] > 0 then
3095 g_Weapon_mgun(wx
, wy
, xd
, yd
, FUID
);
3096 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', wx
, wy
);
3097 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3098 Dec(FAmmo
[A_BULLETS
]);
3099 FFireAngle
:= FAngle
;
3102 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
3103 GameVelX
, GameVelY
-2, SHELL_BULLET
);
3106 WEAPON_ROCKETLAUNCHER
:
3107 if FAmmo
[A_ROCKETS
] > 0 then
3109 g_Weapon_rocket(wx
, wy
, xd
, yd
, FUID
);
3110 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3111 Dec(FAmmo
[A_ROCKETS
]);
3112 FFireAngle
:= FAngle
;
3118 if FAmmo
[A_CELLS
] > 0 then
3120 g_Weapon_plasma(wx
, wy
, xd
, yd
, FUID
);
3121 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3122 Dec(FAmmo
[A_CELLS
]);
3123 FFireAngle
:= FAngle
;
3129 if (FAmmo
[A_CELLS
] >= 40) and (FBFGFireCounter
= -1) then
3131 FBFGFireCounter
:= 17;
3132 if not FNoReload
then
3133 g_Sound_PlayExAt('SOUND_WEAPON_STARTFIREBFG', FObj
.X
, FObj
.Y
);
3134 Dec(FAmmo
[A_CELLS
], 40);
3138 WEAPON_SUPERPULEMET
:
3139 if FAmmo
[A_SHELLS
] > 0 then
3141 g_Weapon_shotgun(wx
, wy
, xd
, yd
, FUID
);
3142 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', wx
, wy
);
3143 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3144 Dec(FAmmo
[A_SHELLS
]);
3145 FFireAngle
:= FAngle
;
3148 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
3149 GameVelX
, GameVelY
-2, SHELL_SHELL
);
3152 WEAPON_FLAMETHROWER
:
3153 if FAmmo
[A_FUEL
] > 0 then
3155 g_Weapon_flame(wx
, wy
, xd
, yd
, FUID
);
3157 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3159 FFireAngle
:= FAngle
;
3166 if g_Game_IsNet
and g_Game_IsServer
then MH_SEND_PlayerStats(FUID
);
3170 if g_Game_IsNet
then
3174 if FCurrWeap
<> WEAPON_BFG
then
3175 MH_SEND_PlayerFire(FUID
, FCurrWeap
, wx
, wy
, xd
, yd
, LastShotID
)
3177 if not FNoReload
then
3178 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_WEAPON_STARTFIREBFG');
3181 MH_SEND_PlayerStats(FUID
);
3186 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
3187 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
3188 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
3191 function TPlayer
.GetAmmoByWeapon(Weapon
: Byte): Word;
3194 WEAPON_PISTOL
, WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
];
3195 WEAPON_SHOTGUN1
, WEAPON_SHOTGUN2
, WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
];
3196 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
];
3197 WEAPON_PLASMA
, WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
];
3198 WEAPON_FLAMETHROWER
: Result
:= FAmmo
[A_FUEL
];
3203 function TPlayer
.HeadInLiquid(XInc
, YInc
: Integer): Boolean;
3205 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
+XInc
, FObj
.Y
+PLAYER_HEADRECT
.Y
+YInc
,
3206 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
3207 PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, True);
3210 procedure TPlayer
.FlamerOn
;
3212 FFlameSoundOff
.Stop();
3213 FFlameSoundOff
.SetPosition(0);
3216 if (not FFlameSoundOn
.IsPlaying()) and (not FFlameSoundWork
.IsPlaying()) then
3217 FFlameSoundWork
.PlayAt(FObj
.X
, FObj
.Y
);
3221 FFlameSoundOn
.PlayAt(FObj
.X
, FObj
.Y
);
3226 procedure TPlayer
.FlamerOff
;
3230 FFlameSoundOn
.Stop();
3231 FFlameSoundOn
.SetPosition(0);
3232 FFlameSoundWork
.Stop();
3233 FFlameSoundWork
.SetPosition(0);
3234 FFlameSoundOff
.PlayAt(FObj
.X
, FObj
.Y
);
3239 procedure TPlayer
.JetpackOn
;
3243 FJetSoundOn
.SetPosition(0);
3244 FJetSoundOn
.PlayAt(FObj
.X
, FObj
.Y
);
3248 procedure TPlayer
.JetpackOff
;
3252 FJetSoundOff
.SetPosition(0);
3253 FJetSoundOff
.PlayAt(FObj
.X
, FObj
.Y
);
3256 procedure TPlayer
.CatchFire(Attacker
: Word; Timeout
: Integer = PLAYER_BURN_TIME
);
3258 if Timeout
<= 0 then
3260 if (FMegaRulez
[MR_SUIT
] > gTime
) or (FMegaRulez
[MR_INVUL
] > gTime
) then
3261 exit
; // Íå çàãîðàåìñÿ êîãäà åñòü çàùèòà
3262 if g_Obj_CollidePanel(@FObj
, 0, 0, PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
) then
3263 exit
; // Íå ïîäãîðàåì â âîäå íà âñÿêèé ñëó÷àé
3264 if FFireTime
<= 0 then
3265 g_Sound_PlayExAt('SOUND_IGNITE', FObj
.X
, FObj
.Y
);
3266 FFireTime
:= Timeout
;
3267 FFireAttacker
:= Attacker
;
3268 if g_Game_IsNet
and g_Game_IsServer
then
3269 MH_SEND_PlayerStats(FUID
);
3272 procedure TPlayer
.Jump();
3274 if gFly
or FJetpack
then
3276 // Ïîëåò (÷èò-êîä èëè äæåòïàê):
3277 if FObj
.Vel
.Y
> -VEL_FLY
then
3278 FObj
.Vel
.Y
:= FObj
.Vel
.Y
- 3;
3281 if FJetFuel
> 0 then
3283 if (FJetFuel
< 1) and g_Game_IsServer
then
3287 if g_Game_IsNet
then
3288 MH_SEND_PlayerStats(FUID
);
3294 // Íå âêëþ÷àòü äæåòïàê â ðåæèìå ïðîõîæäåíèÿ ñêâîçü ñòåíû
3296 FCanJetpack
:= False;
3298 // Ïðûãàåì èëè âñïëûâàåì:
3299 if (CollideLevel(0, 1) or
3300 g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
+36, PLAYER_RECT
.Width
,
3301 PLAYER_RECT
.Height
-33, PANEL_STEP
, False)
3302 ) and (FObj
.Accel
.Y
= 0) then // Íå ïðûãàòü, åñëè åñòü âåðòèêàëüíîå óñêîðåíèå
3304 FObj
.Vel
.Y
:= -VEL_JUMP
;
3305 FCanJetpack
:= False;
3309 if BodyInLiquid(0, 0) then
3310 FObj
.Vel
.Y
:= -VEL_SW
3311 else if (FJetFuel
> 0) and FCanJetpack
and
3312 g_Game_IsServer
and (not g_Obj_CollideLiquid(@FObj
, 0, 0)) then
3316 if g_Game_IsNet
then
3317 MH_SEND_PlayerStats(FUID
);
3322 procedure TPlayer
.Kill(KillType
: Byte; SpawnerUID
: Word; t
: Byte);
3324 a
, i
, k
, ab
, ar
: Byte;
3328 srv
, netsrv
: Boolean;
3334 procedure PushItem(t
: Byte);
3338 id
:= g_Items_Create(FObj
.X
, FObj
.Y
, t
, True, False);
3339 it
:= g_Items_ByIdx(id
);
3340 if KillType
= K_EXTRAHARDKILL
then // -7..+7; -8..0
3342 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-7+Random(15),
3343 (FObj
.Vel
.Y
div 2)-Random(9));
3344 it
.positionChanged(); // this updates spatial accelerators
3348 if KillType
= K_HARDKILL
then // -5..+5; -5..0
3350 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-5+Random(11),
3351 (FObj
.Vel
.Y
div 2)-Random(6));
3353 else // -3..+3; -3..0
3355 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-3+Random(7),
3356 (FObj
.Vel
.Y
div 2)-Random(4));
3358 it
.positionChanged(); // this updates spatial accelerators
3361 if g_Game_IsNet
and g_Game_IsServer
then
3362 MH_SEND_ItemSpawn(True, id
);
3366 DoFrags
:= (gGameSettings
.MaxLives
= 0) or (gGameSettings
.GameMode
= GM_COOP
);
3367 Srv
:= g_Game_IsServer
;
3368 Netsrv
:= g_Game_IsServer
and g_Game_IsNet
;
3369 if Srv
then FDeath
:= FDeath
+ 1;
3374 if not FPhysics
then
3380 if (gGameSettings
.MaxLives
> 0) and Srv
and (gLMSRespawn
= LMS_RESPAWN_NONE
) then
3382 if FLives
> 0 then FLives
:= FLives
- 1;
3383 if FLives
= 0 then FNoRespawn
:= True;
3386 // Íîìåð òèïà ñìåðòè:
3389 K_SIMPLEKILL
: a
:= 1;
3391 K_EXTRAHARDKILL
: a
:= 3;
3396 if not FModel
.PlaySound(MODELSOUND_DIE
, a
, FObj
.X
, FObj
.Y
) then
3398 if FModel
.PlaySound(MODELSOUND_DIE
, i
, FObj
.X
, FObj
.Y
) then
3405 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN1
;
3407 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN2
;
3408 K_EXTRAHARDKILL
, K_FALLKILL
:
3409 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN3
;
3412 // Ïåðåêëþ÷àåì ñîñòîÿíèå:
3416 K_HARDKILL
, K_EXTRAHARDKILL
:
3420 // Ðåàêöèÿ ìîíñòðîâ íà ñìåðòü èãðîêà:
3421 if (KillType
<> K_FALLKILL
) and (Srv
) then
3422 g_Monsters_killedp();
3424 if SpawnerUID
= FUID
then
3428 if gGameSettings
.GameMode
= GM_TDM
then
3429 Dec(gTeamStat
[FTeam
].Goals
);
3430 if DoFrags
or (gGameSettings
.GameMode
= GM_TDM
) then
3436 g_Console_Add(Format(_lc
[I_PLAYER_KILL_SELF
], [FName
]), True);
3439 if g_GetUIDType(SpawnerUID
) = UID_PLAYER
then
3440 begin // Óáèò äðóãèì èãðîêîì
3441 KP
:= g_Player_Get(SpawnerUID
);
3442 if (KP
<> nil) and Srv
then
3444 if (DoFrags
or (gGameSettings
.GameMode
= GM_TDM
)) then
3445 if SameTeam(FUID
, SpawnerUID
) then
3455 if (gGameSettings
.GameMode
= GM_TDM
) and DoFrags
then
3456 Inc(gTeamStat
[KP
.Team
].Goals
,
3457 IfThen(SameTeam(FUID
, SpawnerUID
), -1, 1));
3459 if netsrv
then MH_SEND_PlayerStats(SpawnerUID
);
3462 plr
:= g_Player_Get(SpawnerUID
);
3470 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_2
],
3474 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_1
],
3478 g_Console_Add(Format(_lc
[I_PLAYER_KILL
],
3483 else if g_GetUIDType(SpawnerUID
) = UID_MONSTER
then
3484 begin // Óáèò ìîíñòðîì
3485 mon
:= g_Monsters_ByUID(SpawnerUID
);
3489 s
:= g_Mons_GetKilledByTypeId(mon
.MonsterType
);
3493 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_2
],
3497 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_1
],
3501 g_Console_Add(Format(_lc
[I_PLAYER_KILL
],
3506 else // Îñîáûå òèïû ñìåðòè
3509 HIT_SELF
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_SELF
], [FName
]), True);
3510 HIT_FALL
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_FALL
], [FName
]), True);
3511 HIT_WATER
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_WATER
], [FName
]), True);
3512 HIT_ACID
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_ACID
], [FName
]), True);
3513 HIT_TRAP
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_TRAP
], [FName
]), True);
3514 else g_Console_Add(Format(_lc
[I_PLAYER_DIED
], [FName
]), True);
3520 for a
:= WP_FIRST
to WP_LAST
do
3524 WEAPON_SAW
: i
:= ITEM_WEAPON_SAW
;
3525 WEAPON_SHOTGUN1
: i
:= ITEM_WEAPON_SHOTGUN1
;
3526 WEAPON_SHOTGUN2
: i
:= ITEM_WEAPON_SHOTGUN2
;
3527 WEAPON_CHAINGUN
: i
:= ITEM_WEAPON_CHAINGUN
;
3528 WEAPON_ROCKETLAUNCHER
: i
:= ITEM_WEAPON_ROCKETLAUNCHER
;
3529 WEAPON_PLASMA
: i
:= ITEM_WEAPON_PLASMA
;
3530 WEAPON_BFG
: i
:= ITEM_WEAPON_BFG
;
3531 WEAPON_SUPERPULEMET
: i
:= ITEM_WEAPON_SUPERPULEMET
;
3532 WEAPON_FLAMETHROWER
: i
:= ITEM_WEAPON_FLAMETHROWER
;
3541 if R_ITEM_BACKPACK
in FRulez
then
3542 PushItem(ITEM_AMMO_BACKPACK
);
3544 // Âûáðîñ ðàêåòíîãî ðàíöà:
3545 if FJetFuel
> 0 then
3546 PushItem(ITEM_JETPACK
);
3549 if (not (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
])) or
3550 (not LongBool(gGameSettings
.Options
and GAME_OPTION_DMKEYS
)) then
3552 if R_KEY_RED
in FRulez
then
3553 PushItem(ITEM_KEY_RED
);
3555 if R_KEY_GREEN
in FRulez
then
3556 PushItem(ITEM_KEY_GREEN
);
3558 if R_KEY_BLUE
in FRulez
then
3559 PushItem(ITEM_KEY_BLUE
);
3563 DropFlag(KillType
= K_FALLKILL
);
3566 FCorpse
:= g_Player_CreateCorpse(Self
);
3568 if Srv
and (gGameSettings
.MaxLives
> 0) and FNoRespawn
and
3569 (gLMSRespawn
= LMS_RESPAWN_NONE
) then
3575 for i
:= Low(gPlayers
) to High(gPlayers
) do
3577 if gPlayers
[i
] = nil then continue
;
3578 if (not gPlayers
[i
].FNoRespawn
) and (not gPlayers
[i
].FSpectator
) then
3581 if gPlayers
[i
].FTeam
= TEAM_RED
then Inc(ar
)
3582 else if gPlayers
[i
].FTeam
= TEAM_BLUE
then Inc(ab
);
3587 OldLR
:= gLMSRespawn
;
3588 if (gGameSettings
.GameMode
= GM_COOP
) then
3592 // everyone is dead, restart the map
3593 g_Game_Message(_lc
[I_MESSAGE_LMS_LOSE
], 144);
3595 MH_SEND_GameEvent(NET_EV_LMS_LOSE
);
3596 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3597 gLMSRespawnTime
:= gTime
+ 5000;
3599 else if (a
= 1) then
3601 if (gPlayers
[k
] <> nil) and not (gPlayers
[k
] is TBot
) then
3602 if (gPlayers
[k
] = gPlayer1
) or
3603 (gPlayers
[k
] = gPlayer2
) then
3604 g_Console_Add('*** ' + _lc
[I_MESSAGE_LMS_SURVIVOR
] + ' ***', True)
3605 else if Netsrv
and (gPlayers
[k
].FClientID
>= 0) then
3606 MH_SEND_GameEvent(NET_EV_LMS_SURVIVOR
, 0, 'N', gPlayers
[k
].FClientID
);
3609 else if (gGameSettings
.GameMode
= GM_TDM
) then
3611 if (ab
= 0) and (ar
<> 0) then
3614 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 144);
3616 MH_SEND_GameEvent(NET_EV_TLMS_WIN
, TEAM_RED
);
3617 Inc(gTeamStat
[TEAM_RED
].Goals
);
3618 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3619 gLMSRespawnTime
:= gTime
+ 5000;
3621 else if (ar
= 0) and (ab
<> 0) then
3624 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 144);
3626 MH_SEND_GameEvent(NET_EV_TLMS_WIN
, TEAM_BLUE
);
3627 Inc(gTeamStat
[TEAM_BLUE
].Goals
);
3628 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3629 gLMSRespawnTime
:= gTime
+ 5000;
3631 else if (ar
= 0) and (ab
= 0) then
3634 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
3636 MH_SEND_GameEvent(NET_EV_LMS_DRAW
, 0, FName
);
3637 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3638 gLMSRespawnTime
:= gTime
+ 5000;
3641 else if (gGameSettings
.GameMode
= GM_DM
) then
3645 if gPlayers
[k
] <> nil then
3648 // survivor is the winner
3649 g_Game_Message(Format(_lc
[I_MESSAGE_LMS_WIN
], [AnsiUpperCase(FName
)]), 144);
3651 MH_SEND_GameEvent(NET_EV_LMS_WIN
, 0, FName
);
3654 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3655 gLMSRespawnTime
:= gTime
+ 5000;
3657 else if (a
= 0) then
3659 // everyone is dead, restart the map
3660 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
3662 MH_SEND_GameEvent(NET_EV_LMS_DRAW
, 0, FName
);
3663 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3664 gLMSRespawnTime
:= gTime
+ 5000;
3667 if srv
and (OldLR
= LMS_RESPAWN_NONE
) and (gLMSRespawn
> LMS_RESPAWN_NONE
) then
3669 if NetMode
= NET_SERVER
then
3670 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
)
3672 g_Console_Add(Format(_lc
[I_MSG_WARMUP_START
], [(gLMSRespawnTime
- gTime
) div 1000]), True);
3678 MH_SEND_PlayerStats(FUID
);
3679 MH_SEND_PlayerDeath(FUID
, KillType
, t
, SpawnerUID
);
3680 if gGameSettings
.GameMode
= GM_TDM
then MH_SEND_GameStats
;
3683 if srv
and FNoRespawn
then Spectate(True);
3684 FWantsInGame
:= True;
3687 function TPlayer
.BodyInLiquid(XInc
, YInc
: Integer): Boolean;
3689 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
, PLAYER_RECT
.Width
,
3690 PLAYER_RECT
.Height
-20, PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, False);
3693 function TPlayer
.BodyInAcid(XInc
, YInc
: Integer): Boolean;
3695 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
, PLAYER_RECT
.Width
,
3696 PLAYER_RECT
.Height
-20, PANEL_ACID1
or PANEL_ACID2
, False);
3699 procedure TPlayer
.MakeBloodSimple(Count
: Word);
3701 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)+8,
3702 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3703 Count
div 2, 3, -1, 16, (PLAYER_RECT
.Height
*2 div 3),
3704 FModel
.Blood
.R
, FModel
.Blood
.G
, FModel
.Blood
.B
, FModel
.Blood
.Kind
);
3705 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-8,
3706 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3707 Count
div 2, -3, -1, 16, (PLAYER_RECT
.Height
*2) div 3,
3708 FModel
.Blood
.R
, FModel
.Blood
.G
, FModel
.Blood
.B
, FModel
.Blood
.Kind
);
3711 procedure TPlayer
.MakeBloodVector(Count
: Word; VelX
, VelY
: Integer);
3713 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
3714 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3715 Count
, VelX
, VelY
, 16, (PLAYER_RECT
.Height
*2) div 3,
3716 FModel
.Blood
.R
, FModel
.Blood
.G
, FModel
.Blood
.B
, FModel
.Blood
.Kind
);
3719 procedure TPlayer
.ProcessWeaponAction(Action
: Byte);
3721 if g_Game_IsClient
then Exit
;
3723 WP_PREV
: PrevWeapon();
3724 WP_NEXT
: NextWeapon();
3728 procedure TPlayer
.QueueWeaponSwitch(Weapon
: Byte);
3730 if g_Game_IsClient
then Exit
;
3731 if Weapon
> High(FWeapon
) then Exit
;
3732 FNextWeap
:= FNextWeap
or (1 shl Weapon
);
3735 procedure TPlayer
.resetWeaponQueue ();
3738 FNextWeapDelay
:= 0;
3741 function TPlayer
.hasAmmoForWeapon (weapon
: Byte): Boolean;
3745 WEAPON_KASTET
, WEAPON_SAW
: result
:= true;
3746 WEAPON_SHOTGUN1
, WEAPON_SHOTGUN2
, WEAPON_SUPERPULEMET
: result
:= (FAmmo
[A_SHELLS
] > 0);
3747 WEAPON_PISTOL
, WEAPON_CHAINGUN
: result
:= (FAmmo
[A_BULLETS
] > 0);
3748 WEAPON_ROCKETLAUNCHER
: result
:= (FAmmo
[A_ROCKETS
] > 0);
3749 WEAPON_PLASMA
, WEAPON_BFG
: result
:= (FAmmo
[A_CELLS
] > 0);
3750 WEAPON_FLAMETHROWER
: result
:= (FAmmo
[A_FUEL
] > 0);
3751 else result
:= (weapon
< length(FWeapon
));
3755 function TPlayer
.shouldSwitch (weapon
: Byte; hadWeapon
: Boolean): Boolean;
3758 if (weapon
< 0) or (weapon
> WP_LAST
+ 1) then
3763 if (FWeapSwitchMode
= 1) and not hadWeapon
then
3765 else if (FWeapSwitchMode
= 2) then
3766 result
:= (FWeapPreferences
[weapon
] > FWeapPreferences
[FCurrWeap
]);
3769 // return 255 for "no switch"
3770 function TPlayer
.getNextWeaponIndex (): Byte;
3773 wantThisWeapon
: array[0..64] of Boolean;
3774 wwc
: Integer = 0; //HACK!
3777 result
:= 255; // default result: "no switch"
3778 //e_LogWriteFln('FSWITCHTOEMPTY: %s', [FSwitchToEmpty], TMsgType.Notify);
3779 // had weapon cycling on previous frame? remove that flag
3780 if (FNextWeap
and $2000) <> 0 then
3782 FNextWeap
:= FNextWeap
and $1FFF;
3783 FNextWeapDelay
:= 0;
3785 // cycling has priority
3786 if (FNextWeap
and $C000) <> 0 then
3788 if (FNextWeap
and $8000) <> 0 then
3792 FNextWeap
:= FNextWeap
or $2000; // we need this
3793 if FNextWeapDelay
> 0 then
3794 exit
; // cooldown time
3796 for i
:= 0 to High(FWeapon
) do
3798 cwi
:= (cwi
+length(FWeapon
)+dir
) mod length(FWeapon
);
3799 if FWeapon
[cwi
] and ((FSwitchToEmpty
= 1) or hasAmmoForWeapon(cwi
)) then
3801 //e_LogWriteFln(' SWITCH: cur=%d; new=%d %s %s', [FCurrWeap, cwi, FSwitchToEmpty, hasAmmoForWeapon(cwi)], TMsgType.Notify);
3802 result
:= Byte(cwi
);
3803 FNextWeapDelay
:= WEAPON_DELAY
;
3811 for i
:= 0 to High(wantThisWeapon
) do
3812 wantThisWeapon
[i
] := false;
3813 for i
:= 0 to High(FWeapon
) do
3814 if (FNextWeap
and (1 shl i
)) <> 0 then
3816 wantThisWeapon
[i
] := true;
3820 // exclude currently selected weapon from the set
3821 wantThisWeapon
[FCurrWeap
] := false;
3822 // slow down alterations a little
3825 //e_WriteLog(Format(' FNextWeap=%x; delay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
3826 // more than one weapon requested, assume "alteration" and check alteration delay
3827 if FNextWeapDelay
> 0 then
3833 // do not reset weapon queue, it will be done in `RealizeCurrentWeapon()`
3834 // but clear all counters if no weapon should be switched
3840 //e_WriteLog(Format('wwc=%d', [wwc]), MSG_WARNING);
3841 // try weapons in descending order
3842 for i
:= High(FWeapon
) downto 0 do
3844 if wantThisWeapon
[i
] and FWeapon
[i
] and ((wwc
= 1) or hasAmmoForWeapon(i
)) then
3849 FNextWeapDelay
:= WEAPON_DELAY
* 2; // anyway, 'cause why not
3850 //e_LogWriteFln('FOUND %s %s %s', [result, FSwitchToEmpty, hasAmmoForWeapon(i)], TMsgType.Notify);
3854 // no suitable weapon found, so reset the queue, to avoid accidental "queuing" of weapon w/o ammo
3858 procedure TPlayer
.RealizeCurrentWeapon();
3859 function switchAllowed (): Boolean;
3864 if FBFGFireCounter
<> -1 then
3866 if FTime
[T_SWITCH
] > gTime
then
3868 for i
:= WP_FIRST
to WP_LAST
do
3869 if FReloading
[i
] > 0 then
3877 //e_WriteLog(Format('***RealizeCurrentWeapon: FNextWeap=%x; FNextWeapDelay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
3878 //FNextWeap := FNextWeap and $1FFF;
3879 if FNextWeapDelay
> 0 then Dec(FNextWeapDelay
); // "alteration delay"
3881 if not switchAllowed
then
3883 //HACK for weapon cycling
3884 if (FNextWeap
and $E000) <> 0 then FNextWeap
:= 0;
3888 nw
:= getNextWeaponIndex();
3890 if nw
= 255 then exit
; // don't reset anything here
3891 if nw
> High(FWeapon
) then
3893 // don't forget to reset queue here!
3894 //e_WriteLog(' RealizeCurrentWeapon: WUTAFUUUU', MSG_WARNING);
3902 FTime
[T_SWITCH
] := gTime
+156;
3903 if FCurrWeap
= WEAPON_SAW
then FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3904 FModel
.SetWeapon(FCurrWeap
);
3905 if g_Game_IsNet
then MH_SEND_PlayerStats(FUID
);
3909 procedure TPlayer
.NextWeapon();
3911 if g_Game_IsClient
then Exit
;
3915 procedure TPlayer
.PrevWeapon();
3917 if g_Game_IsClient
then Exit
;
3921 procedure TPlayer
.SetWeapon(W
: Byte);
3923 if FCurrWeap
<> W
then
3924 if W
= WEAPON_SAW
then
3925 FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3928 FModel
.SetWeapon(CurrWeap
);
3932 function TPlayer
.PickItem(ItemType
: Byte; arespawn
: Boolean; var remove
: Boolean): Boolean;
3934 function allowBerserkSwitching (): Boolean;
3936 if (FBFGFireCounter
<> -1) then begin result
:= false; exit
; end;
3938 if gBerserkAutoswitch
then exit
;
3939 if not conIsCheatsEnabled
then exit
;
3945 switchWeapon
: Byte = -1;
3946 hadWeapon
: Boolean = False;
3949 if g_Game_IsClient
then Exit
;
3951 // a = true - ìåñòî ñïàâíà ïðåäìåòà:
3952 a
:= LongBool(gGameSettings
.Options
and GAME_OPTION_WEAPONSTAY
) and arespawn
;
3956 if (FHealth
< PLAYER_HP_SOFT
) or (FFireTime
> 0) then
3958 if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
3962 if gFlash
= 2 then Inc(FPickup
, 5);
3966 if (FHealth
< PLAYER_HP_SOFT
) or (FFireTime
> 0) then
3968 if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
3972 if gFlash
= 2 then Inc(FPickup
, 5);
3976 if FArmor
< PLAYER_AP_SOFT
then
3978 FArmor
:= PLAYER_AP_SOFT
;
3981 if gFlash
= 2 then Inc(FPickup
, 5);
3985 if FArmor
< PLAYER_AP_LIMIT
then
3987 FArmor
:= PLAYER_AP_LIMIT
;
3990 if gFlash
= 2 then Inc(FPickup
, 5);
3994 if (FHealth
< PLAYER_HP_LIMIT
) or (FFireTime
> 0) then
3996 if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
4000 if gFlash
= 2 then Inc(FPickup
, 5);
4004 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) or (FFireTime
> 0) then
4006 if FHealth
< PLAYER_HP_LIMIT
then
4007 FHealth
:= PLAYER_HP_LIMIT
;
4008 if FArmor
< PLAYER_AP_LIMIT
then
4009 FArmor
:= PLAYER_AP_LIMIT
;
4013 if gFlash
= 2 then Inc(FPickup
, 5);
4017 if (not FWeapon
[WEAPON_SAW
]) or ((not arespawn
) and (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
])) then
4019 hadWeapon
:= FWeapon
[WEAPON_SAW
];
4020 switchWeapon
:= WEAPON_SAW
;
4021 FWeapon
[WEAPON_SAW
] := True;
4023 if gFlash
= 2 then Inc(FPickup
, 5);
4024 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4027 ITEM_WEAPON_SHOTGUN1
:
4028 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN1
] then
4030 // Íóæíî, ÷òîáû íå âçÿòü âñå ïóëè ñðàçó:
4031 if a
and FWeapon
[WEAPON_SHOTGUN1
] then Exit
;
4032 hadWeapon
:= FWeapon
[WEAPON_SHOTGUN1
];
4033 switchWeapon
:= WEAPON_SHOTGUN1
;
4034 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4035 FWeapon
[WEAPON_SHOTGUN1
] := True;
4037 if gFlash
= 2 then Inc(FPickup
, 5);
4038 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4041 ITEM_WEAPON_SHOTGUN2
:
4042 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN2
] then
4044 if a
and FWeapon
[WEAPON_SHOTGUN2
] then Exit
;
4045 hadWeapon
:= FWeapon
[WEAPON_SHOTGUN2
];
4046 switchWeapon
:= WEAPON_SHOTGUN2
;
4047 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4048 FWeapon
[WEAPON_SHOTGUN2
] := 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_CHAINGUN
:
4055 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or not FWeapon
[WEAPON_CHAINGUN
] then
4057 if a
and FWeapon
[WEAPON_CHAINGUN
] then Exit
;
4058 hadWeapon
:= FWeapon
[WEAPON_CHAINGUN
];
4059 switchWeapon
:= WEAPON_CHAINGUN
;
4060 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
4061 FWeapon
[WEAPON_CHAINGUN
] := 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_ROCKETLAUNCHER
:
4068 if (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or not FWeapon
[WEAPON_ROCKETLAUNCHER
] then
4070 if a
and FWeapon
[WEAPON_ROCKETLAUNCHER
] then Exit
;
4071 switchWeapon
:= WEAPON_ROCKETLAUNCHER
;
4072 hadWeapon
:= FWeapon
[WEAPON_ROCKETLAUNCHER
];
4073 IncMax(FAmmo
[A_ROCKETS
], 2, FMaxAmmo
[A_ROCKETS
]);
4074 FWeapon
[WEAPON_ROCKETLAUNCHER
] := 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');
4081 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_PLASMA
] then
4083 if a
and FWeapon
[WEAPON_PLASMA
] then Exit
;
4084 switchWeapon
:= WEAPON_PLASMA
;
4085 hadWeapon
:= FWeapon
[WEAPON_PLASMA
];
4086 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
4087 FWeapon
[WEAPON_PLASMA
] := 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_BFG
] then
4096 if a
and FWeapon
[WEAPON_BFG
] then Exit
;
4097 switchWeapon
:= WEAPON_BFG
;
4098 hadWeapon
:= FWeapon
[WEAPON_BFG
];
4099 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
4100 FWeapon
[WEAPON_BFG
] := 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');
4106 ITEM_WEAPON_SUPERPULEMET
:
4107 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SUPERPULEMET
] then
4109 if a
and FWeapon
[WEAPON_SUPERPULEMET
] then Exit
;
4110 switchWeapon
:= WEAPON_SUPERPULEMET
;
4111 hadWeapon
:= FWeapon
[WEAPON_SUPERPULEMET
];
4112 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4113 FWeapon
[WEAPON_SUPERPULEMET
] := 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_FLAMETHROWER
:
4120 if (FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
]) or not FWeapon
[WEAPON_FLAMETHROWER
] then
4122 if a
and FWeapon
[WEAPON_FLAMETHROWER
] then Exit
;
4123 switchWeapon
:= WEAPON_FLAMETHROWER
;
4124 hadWeapon
:= FWeapon
[WEAPON_FLAMETHROWER
];
4125 IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
4126 FWeapon
[WEAPON_FLAMETHROWER
] := 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');
4133 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
4135 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
4138 if gFlash
= 2 then Inc(FPickup
, 5);
4141 ITEM_AMMO_BULLETS_BOX
:
4142 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
4144 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
4147 if gFlash
= 2 then Inc(FPickup
, 5);
4151 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
4153 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4156 if gFlash
= 2 then Inc(FPickup
, 5);
4159 ITEM_AMMO_SHELLS_BOX
:
4160 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
4162 IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
4165 if gFlash
= 2 then Inc(FPickup
, 5);
4169 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
4171 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
4174 if gFlash
= 2 then Inc(FPickup
, 5);
4177 ITEM_AMMO_ROCKET_BOX
:
4178 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
4180 IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
4183 if gFlash
= 2 then Inc(FPickup
, 5);
4187 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
4189 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
4192 if gFlash
= 2 then Inc(FPickup
, 5);
4196 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
4198 IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
4201 if gFlash
= 2 then Inc(FPickup
, 5);
4205 if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then
4207 IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
4210 if gFlash
= 2 then Inc(FPickup
, 5);
4214 if not(R_ITEM_BACKPACK
in FRulez
) or
4215 (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
4216 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
4217 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
4218 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or
4219 (FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
]) then
4221 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[1, A_BULLETS
];
4222 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[1, A_SHELLS
];
4223 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[1, A_ROCKETS
];
4224 FMaxAmmo
[A_CELLS
] := AmmoLimits
[1, A_CELLS
];
4225 FMaxAmmo
[A_FUEL
] := AmmoLimits
[1, A_FUEL
];
4227 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
4228 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
4229 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
4230 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4231 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
4232 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
4233 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
4234 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
4235 if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then
4236 IncMax(FAmmo
[A_FUEL
], 50, FMaxAmmo
[A_FUEL
]);
4238 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
4241 if gFlash
= 2 then Inc(FPickup
, 5);
4245 if not(R_KEY_RED
in FRulez
) then
4247 Include(FRulez
, R_KEY_RED
);
4249 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
4250 if gFlash
= 2 then Inc(FPickup
, 5);
4251 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
4255 if not(R_KEY_GREEN
in FRulez
) then
4257 Include(FRulez
, R_KEY_GREEN
);
4259 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
4260 if gFlash
= 2 then Inc(FPickup
, 5);
4261 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
4265 if not(R_KEY_BLUE
in FRulez
) then
4267 Include(FRulez
, R_KEY_BLUE
);
4269 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
4270 if gFlash
= 2 then Inc(FPickup
, 5);
4271 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
4275 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
4277 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
4281 if gFlash
= 2 then Inc(FPickup
, 5);
4285 if FAir
< AIR_MAX
then
4290 if gFlash
= 2 then Inc(FPickup
, 5);
4295 if not (R_BERSERK
in FRulez
) then
4297 Include(FRulez
, R_BERSERK
);
4298 if (shouldSwitch(WP_LAST
+ 1, false)) then
4299 QueueWeaponSwitch(WEAPON_KASTET
);
4303 if gFlash
= 2 then Inc(FPickup
, 5);
4305 FBerserk
:= gTime
+30000;
4310 if (FHealth
< PLAYER_HP_SOFT
) or (FFireTime
> 0) then
4312 if FHealth
< PLAYER_HP_SOFT
then FHealth
:= PLAYER_HP_SOFT
;
4313 FBerserk
:= gTime
+30000;
4321 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
4323 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
4327 if gFlash
= 2 then Inc(FPickup
, 5);
4331 if (FHealth
< PLAYER_HP_LIMIT
) or (FFireTime
> 0) then
4333 if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
4337 if gFlash
= 2 then Inc(FPickup
, 5);
4341 if FArmor
< PLAYER_AP_LIMIT
then
4343 IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
4346 if gFlash
= 2 then Inc(FPickup
, 5);
4350 if FJetFuel
< JET_MAX
then
4352 FJetFuel
:= JET_MAX
;
4355 if gFlash
= 2 then Inc(FPickup
, 5);
4359 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
4361 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
4364 if gFlash
= 2 then Inc(FPickup
, 5);
4368 if (shouldSwitch(switchWeapon
, hadWeapon
)) then
4369 QueueWeaponSwitch(switchWeapon
);
4372 procedure TPlayer
.Touch();
4376 //FModel.PlaySound(MODELSOUND_PAIN, 1, FObj.X, FObj.Y);
4379 // Áðîñèòü ôëàã òîâàðèùó:
4380 if gGameSettings
.GameMode
= GM_CTF
then
4385 procedure TPlayer
.Push(vx
, vy
: Integer);
4387 if (not FPhysics
) and FGhost
then
4389 FObj
.Accel
.X
:= FObj
.Accel
.X
+ vx
;
4390 FObj
.Accel
.Y
:= FObj
.Accel
.Y
+ vy
;
4391 if g_Game_IsNet
and g_Game_IsServer
then
4392 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
4395 procedure TPlayer
.Reset(Force
: Boolean);
4401 FTime
[T_RESPAWN
] := 0;
4402 FTime
[T_FLAGCAP
] := 0;
4418 FSpectator
:= False;
4421 FSpectatePlayer
:= -1;
4422 FNoRespawn
:= False;
4424 FLives
:= gGameSettings
.MaxLives
;
4429 procedure TPlayer
.SoftReset();
4437 FBFGFireCounter
:= -1;
4445 SetAction(A_STAND
, True);
4448 function TPlayer
.GetRespawnPoint(): Byte;
4453 // Íà áóäóùåå: FSpawn - èãðîê óæå èãðàë è ïåðåðîæäàåòñÿ
4455 // Îäèíî÷íàÿ èãðà/êîîïåðàòèâ
4456 if gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
] then
4458 if Self
= gPlayer1
then
4460 // player 1 should try to spawn on the player 1 point
4461 if g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) > 0 then
4462 Exit(RESPAWNPOINT_PLAYER1
)
4463 else if g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) > 0 then
4464 Exit(RESPAWNPOINT_PLAYER2
);
4466 else if Self
= gPlayer2
then
4468 // player 2 should try to spawn on the player 2 point
4469 if g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) > 0 then
4470 Exit(RESPAWNPOINT_PLAYER2
)
4471 else if g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) > 0 then
4472 Exit(RESPAWNPOINT_PLAYER1
);
4476 // other players randomly pick either the first or the second point
4477 c
:= IfThen((Random(2) = 0), RESPAWNPOINT_PLAYER1
, RESPAWNPOINT_PLAYER2
);
4478 if g_Map_GetPointCount(c
) > 0 then
4480 // try the other one
4481 c
:= IfThen((c
= RESPAWNPOINT_PLAYER1
), RESPAWNPOINT_PLAYER2
, RESPAWNPOINT_PLAYER1
);
4482 if g_Map_GetPointCount(c
) > 0 then
4488 if gGameSettings
.GameMode
= GM_DM
then
4490 // try DM points first
4491 if g_Map_GetPointCount(RESPAWNPOINT_DM
) > 0 then
4492 Exit(RESPAWNPOINT_DM
);
4496 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
4498 // try team points first
4499 c
:= RESPAWNPOINT_DM
;
4500 if FTeam
= TEAM_RED
then
4501 c
:= RESPAWNPOINT_RED
4502 else if FTeam
= TEAM_BLUE
then
4503 c
:= RESPAWNPOINT_BLUE
;
4504 if g_Map_GetPointCount(c
) > 0 then
4508 // still haven't found a spawnpoint, try random shit
4509 Result
:= g_Map_GetRandomPointType();
4512 procedure TPlayer
.Respawn(Silent
: Boolean; Force
: Boolean = False);
4514 RespawnPoint
: TRespawnPoint
;
4522 FBFGFireCounter
:= -1;
4529 if not g_Game_IsServer
then
4533 FWantsInGame
:= True;
4534 FJustTeleported
:= True;
4537 FTime
[T_RESPAWN
] := 0;
4541 // if server changes MaxLives we gotta be ready
4542 if gGameSettings
.MaxLives
= 0 then FNoRespawn
:= False;
4544 // Åùå íåëüçÿ âîçðîäèòüñÿ:
4545 if FTime
[T_RESPAWN
] > gTime
then
4548 // Ïðîñðàë âñå æèçíè:
4551 if not FSpectator
then Spectate(True);
4552 FWantsInGame
:= True;
4556 if (gGameSettings
.GameType
<> GT_SINGLE
) and (gGameSettings
.GameMode
<> GM_COOP
) then
4557 begin // "Ñâîÿ èãðà"
4558 // Áåðñåðê íå ñîõðàíÿåòñÿ ìåæäó óðîâíÿìè:
4559 FRulez
:= FRulez
-[R_BERSERK
];
4561 else // "Îäèíî÷íàÿ èãðà"/"Êîîï"
4563 // Áåðñåðê è êëþ÷è íå ñîõðàíÿþòñÿ ìåæäó óðîâíÿìè:
4564 FRulez
:= FRulez
-[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
, R_BERSERK
];
4567 // Ïîëó÷àåì òî÷êó ñïàóíà èãðîêà:
4568 c
:= GetRespawnPoint();
4573 // Âîñêðåøåíèå áåç îðóæèÿ:
4576 FHealth
:= Round(PLAYER_HP_SOFT
* (FHandicap
/ 100));
4582 for a
:= WP_FIRST
to WP_LAST
do
4584 FWeapon
[a
] := False;
4588 FWeapon
[WEAPON_PISTOL
] := True;
4589 FWeapon
[WEAPON_KASTET
] := True;
4590 FCurrWeap
:= WEAPON_PISTOL
;
4593 FModel
.SetWeapon(FCurrWeap
);
4595 for b
:= A_BULLETS
to A_HIGH
do
4598 FAmmo
[A_BULLETS
] := 50;
4600 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[0, A_BULLETS
];
4601 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[0, A_SHELLS
];
4602 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[0, A_SHELLS
];
4603 FMaxAmmo
[A_CELLS
] := AmmoLimits
[0, A_CELLS
];
4604 FMaxAmmo
[A_FUEL
] := AmmoLimits
[0, A_FUEL
];
4606 if (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
]) and
4607 LongBool(gGameSettings
.Options
and GAME_OPTION_DMKEYS
) then
4608 FRulez
:= [R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
]
4613 // Ïîëó÷àåì êîîðäèíàòû òî÷êè âîçðîæäåíèÿ:
4614 if not g_Map_GetPoint(c
, RespawnPoint
) then
4616 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
4620 // Óñòàíîâêà êîîðäèíàò è ñáðîñ âñåõ ïàðàìåòðîâ:
4621 FObj
.X
:= RespawnPoint
.X
-PLAYER_RECT
.X
;
4622 FObj
.Y
:= RespawnPoint
.Y
-PLAYER_RECT
.Y
;
4623 FObj
.oldX
:= FObj
.X
; // don't interpolate after respawn
4624 FObj
.oldY
:= FObj
.Y
;
4630 FDirection
:= RespawnPoint
.Direction
;
4631 if FDirection
= TDirection
.D_LEFT
then
4636 SetAction(A_STAND
, True);
4637 FModel
.Direction
:= FDirection
;
4639 for a
:= Low(FTime
) to High(FTime
) do
4642 for a
:= Low(FMegaRulez
) to High(FMegaRulez
) do
4645 // Respawn invulnerability
4646 if (gGameSettings
.GameType
<> GT_SINGLE
) and (gGameSettings
.SpawnInvul
> 0) then
4648 FMegaRulez
[MR_INVUL
] := gTime
+ gGameSettings
.SpawnInvul
* 1000;
4649 FSpawnInvul
:= FMegaRulez
[MR_INVUL
];
4654 FCanJetpack
:= False;
4660 // Àíèìàöèÿ âîçðîæäåíèÿ:
4661 if (not gLoadGameMode
) and (not Silent
) then
4662 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
4664 Anim
:= TAnimation
.Create(ID
, False, 3);
4665 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4666 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4670 FSpectator
:= False;
4673 FSpectatePlayer
:= -1;
4676 if (gPlayer1
= nil) and (gSpectLatchPID1
= FUID
) then
4678 if (gPlayer2
= nil) and (gSpectLatchPID2
= FUID
) then
4681 if g_Game_IsNet
then
4683 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
4684 MH_SEND_PlayerStats(FUID
, NET_EVERYONE
);
4686 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4687 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32,
4692 procedure TPlayer
.Spectate(NoMove
: Boolean = False);
4695 Kill(K_EXTRAHARDKILL
, FUID
, HIT_SOME
)
4696 else if (not NoMove
) then
4698 GameX
:= gMapInfo
.Width
div 2;
4699 GameY
:= gMapInfo
.Height
div 2;
4708 FWantsInGame
:= False;
4714 if Self
= gPlayer1
then
4716 gSpectLatchPID1
:= FUID
;
4719 else if Self
= gPlayer2
then
4721 gSpectLatchPID2
:= FUID
;
4726 if g_Game_IsNet
then
4727 MH_SEND_PlayerStats(FUID
);
4730 procedure TPlayer
.SwitchNoClip
;
4734 FGhost
:= not FGhost
;
4735 FPhysics
:= not FGhost
;
4747 procedure TPlayer
.Run(Direction
: TDirection
);
4751 if MAX_RUNVEL
> 8 then
4755 if Direction
= TDirection
.D_LEFT
then
4757 if FObj
.Vel
.X
> -MAX_RUNVEL
then
4758 FObj
.Vel
.X
:= FObj
.Vel
.X
- (MAX_RUNVEL
shr 3);
4761 if FObj
.Vel
.X
< MAX_RUNVEL
then
4762 FObj
.Vel
.X
:= FObj
.Vel
.X
+ (MAX_RUNVEL
shr 3);
4764 // Âîçìîæíî, ïèíàåì êóñêè:
4765 if (FObj
.Vel
.X
<> 0) and (gGibs
<> nil) then
4767 b
:= Abs(FObj
.Vel
.X
);
4768 if b
> 1 then b
:= b
* (Random(8 div b
) + 1);
4769 for a
:= 0 to High(gGibs
) do
4771 if gGibs
[a
].alive
and
4772 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
+FObj
.Rect
.Height
-4,
4773 FObj
.Rect
.Width
, 8, @gGibs
[a
].Obj
) and (Random(3) = 0) then
4776 if FObj
.Vel
.X
< 0 then
4778 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)+120) // íàëåâî
4782 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)); // íàïðàâî
4784 gGibs
[a
].positionChanged(); // this updates spatial accelerators
4792 procedure TPlayer
.SeeDown();
4794 SetAction(A_SEEDOWN
);
4796 if FDirection
= TDirection
.D_LEFT
then FAngle
:= ANGLE_LEFTDOWN
else FAngle
:= ANGLE_RIGHTDOWN
;
4798 if FIncCam
> -120 then DecMin(FIncCam
, 5, -120);
4801 procedure TPlayer
.SeeUp();
4805 if FDirection
= TDirection
.D_LEFT
then FAngle
:= ANGLE_LEFTUP
else FAngle
:= ANGLE_RIGHTUP
;
4807 if FIncCam
< 120 then IncMax(FIncCam
, 5, 120);
4810 procedure TPlayer
.SetAction(Action
: Byte; Force
: Boolean = False);
4818 A_ATTACK
: Prior
:= 2;
4819 A_SEEUP
: Prior
:= 1;
4820 A_SEEDOWN
: Prior
:= 1;
4821 A_ATTACKUP
: Prior
:= 2;
4822 A_ATTACKDOWN
: Prior
:= 2;
4827 if (Prior
> FActionPrior
) or Force
then
4828 if not ((Prior
= 2) and (FCurrWeap
= WEAPON_SAW
)) then
4830 FActionPrior
:= Prior
;
4831 FActionAnim
:= Action
;
4832 FActionForce
:= Force
;
4833 FActionChanged
:= True;
4836 if Action
in [A_ATTACK
, A_ATTACKUP
, A_ATTACKDOWN
] then FModel
.SetFire(True);
4839 function TPlayer
.StayOnStep(XInc
, YInc
: Integer): Boolean;
4841 Result
:= not g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
-1,
4842 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False)
4843 and g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
,
4844 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False);
4847 function TPlayer
.TeleportTo(X
, Y
: Integer; silent
: Boolean; dir
: Byte): Boolean;
4854 if g_CollideLevel(X
, Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
) then
4856 g_Sound_PlayExAt('SOUND_GAME_NOTELEPORT', FObj
.X
, FObj
.Y
);
4857 if g_Game_IsServer
and g_Game_IsNet
then
4858 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_GAME_NOTELEPORT');
4862 FJustTeleported
:= True;
4867 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
4869 Anim
:= TAnimation
.Create(ID
, False, 3);
4872 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', FObj
.X
, FObj
.Y
);
4873 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4874 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4875 if g_Game_IsServer
and g_Game_IsNet
then
4876 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4877 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 1,
4881 FObj
.X
:= X
-PLAYER_RECT
.X
;
4882 FObj
.Y
:= Y
-PLAYER_RECT
.Y
;
4883 FObj
.oldX
:= FObj
.X
; // don't interpolate after respawn
4884 FObj
.oldY
:= FObj
.Y
;
4885 if FAlive
and FGhost
then
4891 if not g_Game_IsNet
then
4895 SetDirection(TDirection
.D_LEFT
);
4901 SetDirection(TDirection
.D_RIGHT
);
4907 if FDirection
= TDirection
.D_RIGHT
then
4909 SetDirection(TDirection
.D_LEFT
);
4914 SetDirection(TDirection
.D_RIGHT
);
4920 if not silent
and (Anim
<> nil) then
4922 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4923 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4926 if g_Game_IsServer
and g_Game_IsNet
then
4927 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4928 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 0,
4935 function nonz(a
: Single): Single;
4943 function TPlayer
.refreshCorpse(): Boolean;
4949 if FAlive
or FSpectator
then
4951 if (gCorpses
= nil) or (Length(gCorpses
) = 0) then
4953 for i
:= 0 to High(gCorpses
) do
4954 if gCorpses
[i
] <> nil then
4955 if gCorpses
[i
].FPlayerUID
= FUID
then
4963 function TPlayer
.getCameraObj(): TObj
;
4965 if (not FAlive
) and (not FSpectator
) and
4966 (FCorpse
>= 0) and (FCorpse
< Length(gCorpses
)) and
4967 (gCorpses
[FCorpse
] <> nil) and (gCorpses
[FCorpse
].FPlayerUID
= FUID
) then
4969 gCorpses
[FCorpse
].FObj
.slopeUpLeft
:= FObj
.slopeUpLeft
;
4970 Result
:= gCorpses
[FCorpse
].FObj
;
4978 procedure TPlayer
.PreUpdate();
4980 FSlopeOld
:= FObj
.slopeUpLeft
;
4981 FIncCamOld
:= FIncCam
;
4982 FObj
.oldX
:= FObj
.X
;
4983 FObj
.oldY
:= FObj
.Y
;
4986 procedure TPlayer
.Update();
4989 i
, ii
, wx
, wy
, xd
, yd
, k
: Integer;
4990 blockmon
, headwater
, dospawn
: Boolean;
4995 NetServer
:= g_Game_IsNet
and g_Game_IsServer
;
4996 AnyServer
:= g_Game_IsServer
;
4998 if g_Game_IsClient
and (NetInterpLevel
> 0) then
4999 DoLerp(NetInterpLevel
+ 1)
5005 if (FClientID
>= 0) and (NetClients
[FClientID
].Peer
<> nil) then
5007 FPing
:= NetClients
[FClientID
].Peer
^.lastRoundTripTime
;
5008 if NetClients
[FClientID
].Peer
^.packetsSent
> 0 then
5009 FLoss
:= Round(100*NetClients
[FClientID
].Peer
^.packetsLost
/NetClients
[FClientID
].Peer
^.packetsSent
)
5018 if FAlive
and (FPunchAnim
<> nil) then
5019 FPunchAnim
.Update();
5021 if FAlive
and (gFly
or FJetpack
) then
5024 if FDirection
= TDirection
.D_LEFT
then
5029 if FAlive
and (not FGhost
) then
5031 if FKeys
[KEY_UP
].Pressed
then
5033 if FKeys
[KEY_DOWN
].Pressed
then
5037 if (not (FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_DOWN
].Pressed
)) and
5040 i
:= g_basic
.Sign(FIncCam
);
5041 FIncCam
:= Abs(FIncCam
);
5042 DecMin(FIncCam
, 5, 0);
5043 FIncCam
:= FIncCam
*i
;
5046 if gTime
mod (GAME_TICK
*2) <> 0 then
5048 if (FObj
.Vel
.X
= 0) and FAlive
then
5050 if FKeys
[KEY_LEFT
].Pressed
then
5051 Run(TDirection
.D_LEFT
);
5052 if FKeys
[KEY_RIGHT
].Pressed
then
5053 Run(TDirection
.D_RIGHT
);
5058 g_Obj_Move(@FObj
, True, True, True);
5059 positionChanged(); // this updates spatial accelerators
5065 FActionChanged
:= False;
5069 // Let alive player do some actions
5070 if FKeys
[KEY_LEFT
].Pressed
then Run(TDirection
.D_LEFT
);
5071 if FKeys
[KEY_RIGHT
].Pressed
then Run(TDirection
.D_RIGHT
);
5072 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then Fire()
5078 if NetServer
then MH_SEND_PlayerStats(FUID
);
5081 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Use();
5082 if FKeys
[KEY_JUMP
].Pressed
then Jump()
5085 if AnyServer
and FJetpack
then
5089 if NetServer
then MH_SEND_PlayerStats(FUID
);
5091 FCanJetpack
:= True;
5098 for k
:= Low(FKeys
) to KEY_CHAT
-1 do
5100 if FKeys
[k
].Pressed
then
5108 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
5111 if (FTime
[T_RESPAWN
] <= gTime
) and
5112 gGameOn
and (not FAlive
) then
5114 if (g_Player_GetCount() > 1) then
5118 gExit
:= EXIT_RESTART
;
5123 // Dead spectator actions
5126 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Fire();
5127 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then
5131 if (FSpectatePlayer
>= High(gPlayers
)) then
5132 FSpectatePlayer
:= -1
5136 for I
:= FSpectatePlayer
+ 1 to High(gPlayers
) do
5137 if gPlayers
[I
] <> nil then
5138 if gPlayers
[I
].alive
then
5139 if gPlayers
[I
].UID
<> FUID
then
5141 FSpectatePlayer
:= I
;
5146 if not SetSpect
then FSpectatePlayer
:= -1;
5157 if FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_JUMP
].Pressed
then
5159 FYTo
:= FObj
.Y
- 32;
5160 FSpectatePlayer
:= -1;
5162 if FKeys
[KEY_DOWN
].Pressed
then
5164 FYTo
:= FObj
.Y
+ 32;
5165 FSpectatePlayer
:= -1;
5167 if FKeys
[KEY_LEFT
].Pressed
then
5169 FXTo
:= FObj
.X
- 32;
5170 FSpectatePlayer
:= -1;
5172 if FKeys
[KEY_RIGHT
].Pressed
then
5174 FXTo
:= FObj
.X
+ 32;
5175 FSpectatePlayer
:= -1;
5178 if (FXTo
< -64) then
5180 else if (FXTo
> gMapInfo
.Width
+ 32) then
5181 FXTo
:= gMapInfo
.Width
+ 32;
5182 if (FYTo
< -72) then
5184 else if (FYTo
> gMapInfo
.Height
+ 32) then
5185 FYTo
:= gMapInfo
.Height
+ 32;
5190 g_Obj_Move(@FObj
, True, True, True);
5191 positionChanged(); // this updates spatial accelerators
5198 if (FSpectatePlayer
<= High(gPlayers
)) and (FSpectatePlayer
>= 0) then
5199 if gPlayers
[FSpectatePlayer
] <> nil then
5200 if gPlayers
[FSpectatePlayer
].alive
then
5202 FXTo
:= gPlayers
[FSpectatePlayer
].GameX
;
5203 FYTo
:= gPlayers
[FSpectatePlayer
].GameY
;
5207 blockmon
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
, FObj
.Y
+PLAYER_HEADRECT
.Y
,
5208 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
5209 PANEL_BLOCKMON
, True);
5210 headwater
:= HeadInLiquid(0, 0);
5212 // Ñîïðîòèâëåíèå âîçäóõà:
5213 if (not FAlive
) or not (FKeys
[KEY_LEFT
].Pressed
or FKeys
[KEY_RIGHT
].Pressed
) then
5214 if FObj
.Vel
.X
<> 0 then
5215 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
5217 if (FLastHit
= HIT_TRAP
) and (FPain
> 90) then FPain
:= 90;
5218 DecMin(FPain
, 5, 0);
5219 DecMin(FPickup
, 1, 0);
5221 if FAlive
and (FObj
.Y
> Integer(gMapInfo
.Height
)+128) and AnyServer
then
5223 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
5224 FMegaRulez
[MR_SUIT
] := 0;
5225 FMegaRulez
[MR_INVUL
] := 0;
5226 FMegaRulez
[MR_INVIS
] := 0;
5227 Kill(K_FALLKILL
, 0, HIT_FALL
);
5234 if FCurrWeap
= WEAPON_SAW
then
5235 if not (FSawSound
.IsPlaying() or FSawSoundHit
.IsPlaying() or
5236 FSawSoundSelect
.IsPlaying()) then
5237 FSawSoundIdle
.PlayAt(FObj
.X
, FObj
.Y
);
5240 if (not FJetSoundFly
.IsPlaying()) and (not FJetSoundOn
.IsPlaying()) and
5241 (not FJetSoundOff
.IsPlaying()) then
5243 FJetSoundFly
.SetPosition(0);
5244 FJetSoundFly
.PlayAt(FObj
.X
, FObj
.Y
);
5247 for b
:= WP_FIRST
to WP_LAST
do
5248 if FReloading
[b
] > 0 then
5254 if FShellTimer
> -1 then
5255 if FShellTimer
= 0 then
5257 if FShellType
= SHELL_SHELL
then
5258 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5259 GameVelX
, GameVelY
-2, SHELL_SHELL
)
5260 else if FShellType
= SHELL_DBLSHELL
then
5262 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5263 GameVelX
+1, GameVelY
-2, SHELL_SHELL
);
5264 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5265 GameVelX
-1, GameVelY
-2, SHELL_SHELL
);
5268 end else Dec(FShellTimer
);
5270 if (FBFGFireCounter
> -1) then
5271 if FBFGFireCounter
= 0 then
5275 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
5276 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
5277 xd
:= wx
+IfThen(FDirection
= TDirection
.D_LEFT
, -30, 30);
5278 yd
:= wy
+firediry();
5279 g_Weapon_bfgshot(wx
, wy
, xd
, yd
, FUID
);
5280 if NetServer
then MH_SEND_PlayerFire(FUID
, WEAPON_BFG
, wx
, wy
, xd
, yd
);
5281 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
5282 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
5283 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
5286 FReloading
[WEAPON_BFG
] := WEAPON_RELOAD
[WEAPON_BFG
];
5287 FBFGFireCounter
:= -1;
5290 FBFGFireCounter
:= 0
5292 Dec(FBFGFireCounter
);
5294 if (FMegaRulez
[MR_SUIT
] < gTime
) and AnyServer
then
5296 b
:= g_GetAcidHit(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
);
5298 if (b
> 0) and (gTime
mod (15*GAME_TICK
) = 0) then Damage(b
, 0, 0, 0, HIT_ACID
);
5301 if (headwater
or blockmon
) then
5307 if AnyServer
then Damage(10, 0, 0, 0, HIT_WATER
);
5310 else if (FAir
mod 31 = 0) and not blockmon
then
5312 g_GFX_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2), FObj
.Y
+PLAYER_RECT
.Y
-4, 5+Random(6), 8, 4);
5313 if Random(2) = 0 then
5314 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
5316 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
5318 end else if FAir
< AIR_DEF
then
5321 if FFireTime
> 0 then
5323 if BodyInLiquid(0, 0) then
5328 else if FMegaRulez
[MR_SUIT
] >= gTime
then
5330 if FMegaRulez
[MR_SUIT
] = gTime
then
5337 if FFirePainTime
<= 0 then
5339 if g_Game_IsServer
then
5340 Damage(2, FFireAttacker
, 0, 0, HIT_FLAME
);
5341 FFirePainTime
:= 12 - FFireTime
div 12;
5343 FFirePainTime
:= FFirePainTime
- 1;
5344 FFireTime
:= FFireTime
- 1;
5345 if ((FFireTime
mod 33) = 0) and (FMegaRulez
[MR_INVUL
] < gTime
) then
5346 FModel
.PlaySound(MODELSOUND_PAIN
, 1, FObj
.X
, FObj
.Y
);
5347 if (FFireTime
= 0) and g_Game_IsNet
and g_Game_IsServer
then
5348 MH_SEND_PlayerStats(FUID
);
5352 if FDamageBuffer
> 0 then
5354 if FDamageBuffer
>= 9 then
5358 if FDamageBuffer
< 30 then i
:= 9
5359 else if FDamageBuffer
< 100 then i
:= 18
5363 ii
:= Round(FDamageBuffer
*FHealth
/ nonz(FArmor
*(3/4)+FHealth
));
5364 FArmor
:= FArmor
-(FDamageBuffer
-ii
);
5365 FHealth
:= FHealth
-ii
;
5368 FHealth
:= FHealth
+FArmor
;
5373 if FHealth
<= 0 then
5374 if FHealth
> -30 then Kill(K_SIMPLEKILL
, FLastSpawnerUID
, FLastHit
)
5375 else if FHealth
> -50 then Kill(K_HARDKILL
, FLastSpawnerUID
, FLastHit
)
5376 else Kill(K_EXTRAHARDKILL
, FLastSpawnerUID
, FLastHit
);
5378 if FAlive
and ((FLastHit
<> HIT_FLAME
) or (FFireTime
<= 0)) then
5380 if FDamageBuffer
<= 20 then FModel
.PlaySound(MODELSOUND_PAIN
, 1, FObj
.X
, FObj
.Y
)
5381 else if FDamageBuffer
<= 55 then FModel
.PlaySound(MODELSOUND_PAIN
, 2, FObj
.X
, FObj
.Y
)
5382 else if FDamageBuffer
<= 120 then FModel
.PlaySound(MODELSOUND_PAIN
, 3, FObj
.X
, FObj
.Y
)
5383 else FModel
.PlaySound(MODELSOUND_PAIN
, 4, FObj
.X
, FObj
.Y
);
5390 end; // if FAlive then ...
5392 if (FActionAnim
= A_PAIN
) and (FModel
.Animation
<> A_PAIN
) then
5394 FModel
.ChangeAnimation(FActionAnim
, FActionForce
);
5395 FModel
.GetCurrentAnimation
.MinLength
:= i
;
5396 FModel
.GetCurrentAnimationMask
.MinLength
:= i
;
5397 end else FModel
.ChangeAnimation(FActionAnim
, FActionForce
and (FModel
.Animation
<> A_STAND
));
5399 if (FModel
.GetCurrentAnimation
.Played
or ((not FActionChanged
) and (FModel
.Animation
= A_WALK
)))
5400 then SetAction(A_STAND
, True);
5402 if not ((FModel
.Animation
= A_WALK
) and (Abs(FObj
.Vel
.X
) < 4) and not FModel
.Fire
) then FModel
.Update
;
5404 for b
:= Low(FKeys
) to High(FKeys
) do
5405 if FKeys
[b
].Time
= 0 then FKeys
[b
].Pressed
:= False else Dec(FKeys
[b
].Time
);
5409 procedure TPlayer
.getMapBox (out x
, y
, w
, h
: Integer); inline;
5411 x
:= FObj
.X
+PLAYER_RECT
.X
;
5412 y
:= FObj
.Y
+PLAYER_RECT
.Y
;
5413 w
:= PLAYER_RECT
.Width
;
5414 h
:= PLAYER_RECT
.Height
;
5418 procedure TPlayer
.moveBy (dx
, dy
: Integer); inline;
5420 if (dx
<> 0) or (dy
<> 0) then
5429 function TPlayer
.Collide(X
, Y
: Integer; Width
, Height
: Word): Boolean;
5431 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
5432 FObj
.Y
+PLAYER_RECT
.Y
,
5439 function TPlayer
.Collide(Panel
: TPanel
): Boolean;
5441 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
5442 FObj
.Y
+PLAYER_RECT
.Y
,
5446 Panel
.Width
, Panel
.Height
);
5449 function TPlayer
.Collide(X
, Y
: Integer): Boolean;
5451 X
:= X
-FObj
.X
-PLAYER_RECT
.X
;
5452 Y
:= Y
-FObj
.Y
-PLAYER_RECT
.Y
;
5453 Result
:= (x
>= 0) and (x
<= PLAYER_RECT
.Width
) and
5454 (y
>= 0) and (y
<= PLAYER_RECT
.Height
);
5457 function g_Player_ValidName(Name
: string): Boolean;
5463 if gPlayers
= nil then Exit
;
5465 for a
:= 0 to High(gPlayers
) do
5466 if gPlayers
[a
] <> nil then
5467 if LowerCase(Name
) = LowerCase(gPlayers
[a
].FName
) then
5474 procedure TPlayer
.SetDirection(Direction
: TDirection
);
5478 d
:= FModel
.Direction
;
5480 FModel
.Direction
:= Direction
;
5481 if d
<> Direction
then FModel
.ChangeAnimation(FModel
.Animation
, True);
5483 FDirection
:= Direction
;
5486 function TPlayer
.GetKeys(): Byte;
5490 if R_KEY_RED
in FRulez
then Result
:= KEY_RED
;
5491 if R_KEY_GREEN
in FRulez
then Result
:= Result
or KEY_GREEN
;
5492 if R_KEY_BLUE
in FRulez
then Result
:= Result
or KEY_BLUE
;
5494 if FTeam
= TEAM_RED
then Result
:= Result
or KEY_REDTEAM
;
5495 if FTeam
= TEAM_BLUE
then Result
:= Result
or KEY_BLUETEAM
;
5498 procedure TPlayer
.Use();
5502 if FTime
[T_USE
] > gTime
then Exit
;
5504 g_Triggers_PressR(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
,
5505 PLAYER_RECT
.Height
, FUID
, ACTIVATE_PLAYERPRESS
);
5507 for a
:= 0 to High(gPlayers
) do
5508 if (gPlayers
[a
] <> nil) and (gPlayers
[a
] <> Self
) and
5509 gPlayers
[a
].alive
and SameTeam(FUID
, gPlayers
[a
].FUID
) and
5510 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
5511 FObj
.Rect
.Width
, FObj
.Rect
.Height
, @gPlayers
[a
].FObj
) then
5513 gPlayers
[a
].Touch();
5514 if g_Game_IsNet
and g_Game_IsServer
then
5515 MH_SEND_GameEvent(NET_EV_PLAYER_TOUCH
, gPlayers
[a
].FUID
);
5518 FTime
[T_USE
] := gTime
+120;
5521 procedure TPlayer
.NetFire(Wpn
: Byte; X
, Y
, AX
, AY
: Integer; WID
: Integer = -1);
5525 WX
, WY
, XD
, YD
: Integer;
5537 if R_BERSERK
in FRulez
then
5539 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
5540 locobj
.X
:= FObj
.X
+FObj
.Rect
.X
;
5541 locobj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
5544 locobj
.rect
.Width
:= 39;
5545 locobj
.rect
.Height
:= 52;
5546 locobj
.Vel
.X
:= (xd
-wx
) div 2;
5547 locobj
.Vel
.Y
:= (yd
-wy
) div 2;
5548 locobj
.Accel
.X
:= xd
-wx
;
5549 locobj
.Accel
.y
:= yd
-wy
;
5551 if g_Weapon_Hit(@locobj
, 50, FUID
, HIT_SOME
) <> 0 then
5552 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
5554 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
5558 FPain
:= min(FPain
+ 25, 50);
5560 g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
5565 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
5566 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
5568 FSawSoundSelect
.Stop();
5570 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
5572 else if not FSawSoundHit
.IsPlaying() then
5574 FSawSoundSelect
.Stop();
5575 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
5582 g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', GameX
, Gamey
);
5583 FFireAngle
:= FAngle
;
5585 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5586 GameVelX
, GameVelY
-2, SHELL_BULLET
);
5591 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
5592 FFireAngle
:= FAngle
;
5595 FShellType
:= SHELL_SHELL
;
5600 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN2', Gamex
, Gamey
);
5601 FFireAngle
:= FAngle
;
5604 FShellType
:= SHELL_DBLSHELL
;
5609 g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', Gamex
, Gamey
);
5610 FFireAngle
:= FAngle
;
5612 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5613 GameVelX
, GameVelY
-2, SHELL_BULLET
);
5616 WEAPON_ROCKETLAUNCHER
:
5618 g_Weapon_Rocket(wx
, wy
, xd
, yd
, FUID
, WID
);
5619 FFireAngle
:= FAngle
;
5625 g_Weapon_Plasma(wx
, wy
, xd
, yd
, FUID
, WID
);
5626 FFireAngle
:= FAngle
;
5632 g_Weapon_BFGShot(wx
, wy
, xd
, yd
, FUID
, WID
);
5633 FFireAngle
:= FAngle
;
5637 WEAPON_SUPERPULEMET
:
5639 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
5640 FFireAngle
:= FAngle
;
5642 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5643 GameVelX
, GameVelY
-2, SHELL_SHELL
);
5646 WEAPON_FLAMETHROWER
:
5648 g_Weapon_flame(wx
, wy
, xd
, yd
, FUID
, WID
);
5650 FFireAngle
:= FAngle
;
5657 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
5658 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
5659 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
5662 procedure TPlayer
.DoLerp(Level
: Integer = 2);
5664 if FObj
.X
<> FXTo
then FObj
.X
:= Lerp(FObj
.X
, FXTo
, Level
);
5665 if FObj
.Y
<> FYTo
then FObj
.Y
:= Lerp(FObj
.Y
, FYTo
, Level
);
5668 procedure TPlayer
.SetLerp(XTo
, YTo
: Integer);
5674 if FJustTeleported
or (NetInterpLevel
< 1) then
5678 if FJustTeleported
then
5680 FObj
.oldX
:= FObj
.X
;
5681 FObj
.oldY
:= FObj
.Y
;
5686 AX
:= Abs(FXTo
- FObj
.X
);
5687 AY
:= Abs(FYTo
- FObj
.Y
);
5688 if (AX
> 32) or (AX
<= NetInterpLevel
) then
5690 if (AY
> 32) or (AY
<= NetInterpLevel
) then
5695 function TPlayer
.FullInLift(XInc
, YInc
: Integer): Integer;
5697 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5698 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5699 PANEL_LIFTUP
, False) then Result
:= -1
5701 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5702 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5703 PANEL_LIFTDOWN
, False) then Result
:= 1
5707 function TPlayer
.GetFlag(Flag
: Byte): Boolean;
5714 if Flag
= FLAG_NONE
then
5717 if not g_Game_IsServer
then Exit
;
5719 // Ïðèíåñ ÷óæîé ôëàã íà ñâîþ áàçó:
5720 if (Flag
= FTeam
) and
5721 (gFlags
[Flag
].State
= FLAG_STATE_NORMAL
) and
5722 (FFlag
<> FLAG_NONE
) then
5724 if FFlag
= FLAG_RED
then
5725 s
:= _lc
[I_PLAYER_FLAG_RED
]
5727 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5729 evtype
:= FLAG_STATE_SCORED
;
5731 ts
:= Format('%.4d', [gFlags
[FFlag
].CaptureTime
]);
5732 Insert('.', ts
, Length(ts
) + 1 - 3);
5733 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_CAPTURE
], [FName
, s
, ts
]), True);
5735 g_Map_ResetFlag(FFlag
);
5736 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_CAPTURE
], [AnsiUpperCase(s
)]), 144);
5738 if ((Self
= gPlayer1
) or (Self
= gPlayer2
)
5739 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= FTeam
))
5740 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= FTeam
))) then
5745 if not sound_cap_flag
[a
].IsPlaying() then
5746 sound_cap_flag
[a
].Play();
5748 gTeamStat
[FTeam
].Goals
:= gTeamStat
[FTeam
].Goals
+ 1;
5751 if g_Game_IsNet
then
5753 MH_SEND_FlagEvent(evtype
, FFlag
, FUID
, False);
5757 gFlags
[FFlag
].CaptureTime
:= 0;
5762 // Ïîäîáðàë ñâîé ôëàã - âåðíóë åãî íà áàçó:
5763 if (Flag
= FTeam
) and
5764 (gFlags
[Flag
].State
= FLAG_STATE_DROPPED
) then
5766 if Flag
= FLAG_RED
then
5767 s
:= _lc
[I_PLAYER_FLAG_RED
]
5769 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5771 evtype
:= FLAG_STATE_RETURNED
;
5772 gFlags
[Flag
].CaptureTime
:= 0;
5774 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_RETURN
], [FName
, s
]), True);
5776 g_Map_ResetFlag(Flag
);
5777 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
5779 if ((Self
= gPlayer1
) or (Self
= gPlayer2
)
5780 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= FTeam
))
5781 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= FTeam
))) then
5786 if not sound_ret_flag
[a
].IsPlaying() then
5787 sound_ret_flag
[a
].Play();
5790 if g_Game_IsNet
then
5792 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5798 // Ïîäîáðàë ÷óæîé ôëàã:
5799 if (Flag
<> FTeam
) and (FTime
[T_FLAGCAP
] <= gTime
) then
5803 if Flag
= FLAG_RED
then
5804 s
:= _lc
[I_PLAYER_FLAG_RED
]
5806 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5808 evtype
:= FLAG_STATE_CAPTURED
;
5810 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_GET
], [FName
, s
]), True);
5812 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_GET
], [AnsiUpperCase(s
)]), 144);
5814 gFlags
[Flag
].State
:= FLAG_STATE_CAPTURED
;
5816 if ((Self
= gPlayer1
) or (Self
= gPlayer2
)
5817 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= FTeam
))
5818 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= FTeam
))) then
5823 if not sound_get_flag
[a
].IsPlaying() then
5824 sound_get_flag
[a
].Play();
5827 if g_Game_IsNet
then
5829 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5835 procedure TPlayer
.SetFlag(Flag
: Byte);
5838 if FModel
<> nil then
5839 FModel
.SetFlag(FFlag
);
5842 function TPlayer
.TryDropFlag(): Boolean;
5844 if LongBool(gGameSettings
.Options
and GAME_OPTION_ALLOWDROPFLAG
) then
5845 Result
:= DropFlag(False, LongBool(gGameSettings
.Options
and GAME_OPTION_THROWFLAG
))
5850 function TPlayer
.DropFlag(Silent
: Boolean = True; DoThrow
: Boolean = False): Boolean;
5857 if (not g_Game_IsServer
) or (FFlag
= FLAG_NONE
) then
5859 FTime
[T_FLAGCAP
] := gTime
+ 2000;
5860 with gFlags
[FFlag
] do
5864 Direction
:= FDirection
;
5865 State
:= FLAG_STATE_DROPPED
;
5869 xv
:= FObj
.Vel
.X
+ IfThen(Direction
= TDirection
.D_RIGHT
, 10, -10);
5870 yv
:= FObj
.Vel
.Y
- 2;
5874 xv
:= (FObj
.Vel
.X
div 2);
5875 yv
:= (FObj
.Vel
.Y
div 2) - 2;
5877 g_Obj_Push(@Obj
, xv
, yv
);
5879 positionChanged(); // this updates spatial accelerators
5881 if FFlag
= FLAG_RED
then
5882 s
:= _lc
[I_PLAYER_FLAG_RED
]
5884 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5886 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_DROP
], [FName
, s
]), True);
5887 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_DROP
], [AnsiUpperCase(s
)]), 144);
5889 if ((Self
= gPlayer1
) or (Self
= gPlayer2
)
5890 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= FTeam
))
5891 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= FTeam
))) then
5896 if (not Silent
) and (not sound_lost_flag
[a
].IsPlaying()) then
5897 sound_lost_flag
[a
].Play();
5899 if g_Game_IsNet
then
5900 MH_SEND_FlagEvent(FLAG_STATE_DROPPED
, Flag
, FUID
, False);
5906 procedure TPlayer
.GetSecret();
5908 if (self
= gPlayer1
) or (self
= gPlayer2
) then
5910 g_Console_Add(Format(_lc
[I_PLAYER_SECRET
], [FName
]), True);
5911 g_Sound_PlayEx('SOUND_GAME_SECRET');
5916 procedure TPlayer
.PressKey(Key
: Byte; Time
: Word = 1);
5918 Assert(Key
<= High(FKeys
));
5920 FKeys
[Key
].Pressed
:= True;
5921 FKeys
[Key
].Time
:= Time
;
5924 function TPlayer
.IsKeyPressed(K
: Byte): Boolean;
5926 Result
:= FKeys
[K
].Pressed
;
5929 procedure TPlayer
.ReleaseKeys();
5933 for a
:= Low(FKeys
) to High(FKeys
) do
5935 FKeys
[a
].Pressed
:= False;
5940 procedure TPlayer
.OnDamage(Angle
: SmallInt);
5944 function TPlayer
.firediry(): Integer;
5946 if FKeys
[KEY_UP
].Pressed
then Result
:= -42
5947 else if FKeys
[KEY_DOWN
].Pressed
then Result
:= 19
5951 procedure TPlayer
.RememberState();
5954 SavedState
: TPlayerSavedState
;
5956 SavedState
.Health
:= FHealth
;
5957 SavedState
.Armor
:= FArmor
;
5958 SavedState
.Air
:= FAir
;
5959 SavedState
.JetFuel
:= FJetFuel
;
5960 SavedState
.CurrWeap
:= FCurrWeap
;
5961 SavedState
.NextWeap
:= FNextWeap
;
5962 SavedState
.NextWeapDelay
:= FNextWeapDelay
;
5963 for i
:= Low(FWeapon
) to High(FWeapon
) do
5964 SavedState
.Weapon
[i
] := FWeapon
[i
];
5965 for i
:= Low(FAmmo
) to High(FAmmo
) do
5966 SavedState
.Ammo
[i
] := FAmmo
[i
];
5967 for i
:= Low(FMaxAmmo
) to High(FMaxAmmo
) do
5968 SavedState
.MaxAmmo
[i
] := FMaxAmmo
[i
];
5969 SavedState
.Rulez
:= FRulez
- [R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
];
5971 FSavedStateNum
:= -1;
5972 for i
:= Low(SavedStates
) to High(SavedStates
) do
5973 if not SavedStates
[i
].Used
then
5975 FSavedStateNum
:= i
;
5978 if FSavedStateNum
< 0 then
5980 SetLength(SavedStates
, Length(SavedStates
) + 1);
5981 FSavedStateNum
:= High(SavedStates
);
5984 SavedState
.Used
:= True;
5985 SavedStates
[FSavedStateNum
] := SavedState
;
5988 procedure TPlayer
.RecallState();
5991 SavedState
: TPlayerSavedState
;
5993 if(FSavedStateNum
< 0) or (FSavedStateNum
> High(SavedStates
)) then
5996 SavedState
:= SavedStates
[FSavedStateNum
];
5997 SavedStates
[FSavedStateNum
].Used
:= False;
5998 FSavedStateNum
:= -1;
6000 FHealth
:= SavedState
.Health
;
6001 FArmor
:= SavedState
.Armor
;
6002 FAir
:= SavedState
.Air
;
6003 FJetFuel
:= SavedState
.JetFuel
;
6004 FCurrWeap
:= SavedState
.CurrWeap
;
6005 FNextWeap
:= SavedState
.NextWeap
;
6006 FNextWeapDelay
:= SavedState
.NextWeapDelay
;
6007 for i
:= Low(FWeapon
) to High(FWeapon
) do
6008 FWeapon
[i
] := SavedState
.Weapon
[i
];
6009 for i
:= Low(FAmmo
) to High(FAmmo
) do
6010 FAmmo
[i
] := SavedState
.Ammo
[i
];
6011 for i
:= Low(FMaxAmmo
) to High(FMaxAmmo
) do
6012 FMaxAmmo
[i
] := SavedState
.MaxAmmo
[i
];
6013 FRulez
:= SavedState
.Rulez
;
6015 if gGameSettings
.GameType
= GT_SERVER
then
6016 MH_SEND_PlayerStats(FUID
);
6019 procedure TPlayer
.SaveState (st
: TStream
);
6025 utils
.writeSign(st
, 'PLYR');
6026 utils
.writeInt(st
, Byte(PLR_SAVE_VERSION
)); // version
6028 utils
.writeBool(st
, FIamBot
);
6030 utils
.writeInt(st
, Word(FUID
));
6032 utils
.writeStr(st
, FName
);
6034 utils
.writeInt(st
, Byte(FTeam
));
6036 utils
.writeBool(st
, FAlive
);
6037 // Èçðàñõîäîâàë ëè âñå æèçíè
6038 utils
.writeBool(st
, FNoRespawn
);
6040 if FDirection
= TDirection
.D_LEFT
then b
:= 1 else b
:= 2; // D_RIGHT
6041 utils
.writeInt(st
, Byte(b
));
6043 utils
.writeInt(st
, LongInt(FHealth
));
6044 // Êîýôôèöèåíò èíâàëèäíîñòè
6045 utils
.writeInt(st
, LongInt(FHandicap
));
6047 utils
.writeInt(st
, Byte(FLives
));
6049 utils
.writeInt(st
, LongInt(FArmor
));
6051 utils
.writeInt(st
, LongInt(FAir
));
6053 utils
.writeInt(st
, LongInt(FJetFuel
));
6055 utils
.writeInt(st
, LongInt(FPain
));
6057 utils
.writeInt(st
, LongInt(FKills
));
6059 utils
.writeInt(st
, LongInt(FMonsterKills
));
6061 utils
.writeInt(st
, LongInt(FFrags
));
6063 utils
.writeInt(st
, Byte(FFragCombo
));
6064 // Âðåìÿ ïîñëåäíåãî ôðàãà
6065 utils
.writeInt(st
, LongWord(FLastFrag
));
6067 utils
.writeInt(st
, LongInt(FDeath
));
6069 utils
.writeInt(st
, Byte(FFlag
));
6071 utils
.writeInt(st
, LongInt(FSecrets
));
6073 utils
.writeInt(st
, Byte(FCurrWeap
));
6075 utils
.writeInt(st
, Word(FNextWeap
));
6077 utils
.writeInt(st
, Byte(FNextWeapDelay
));
6078 // Âðåìÿ çàðÿäêè BFG
6079 utils
.writeInt(st
, SmallInt(FBFGFireCounter
));
6081 utils
.writeInt(st
, LongInt(FDamageBuffer
));
6082 // Ïîñëåäíèé óäàðèâøèé
6083 utils
.writeInt(st
, Word(FLastSpawnerUID
));
6084 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà
6085 utils
.writeInt(st
, Byte(FLastHit
));
6087 Obj_SaveState(st
, @FObj
);
6088 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ
6089 for i
:= A_BULLETS
to A_HIGH
do utils
.writeInt(st
, Word(FAmmo
[i
]));
6090 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ
6091 for i
:= A_BULLETS
to A_HIGH
do utils
.writeInt(st
, Word(FMaxAmmo
[i
]));
6093 for i
:= WP_FIRST
to WP_LAST
do utils
.writeBool(st
, FWeapon
[i
]);
6094 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ
6095 for i
:= WP_FIRST
to WP_LAST
do utils
.writeInt(st
, Word(FReloading
[i
]));
6097 utils
.writeBool(st
, (R_ITEM_BACKPACK
in FRulez
));
6098 // Íàëè÷èå êðàñíîãî êëþ÷à
6099 utils
.writeBool(st
, (R_KEY_RED
in FRulez
));
6100 // Íàëè÷èå çåëåíîãî êëþ÷à
6101 utils
.writeBool(st
, (R_KEY_GREEN
in FRulez
));
6102 // Íàëè÷èå ñèíåãî êëþ÷à
6103 utils
.writeBool(st
, (R_KEY_BLUE
in FRulez
));
6105 utils
.writeBool(st
, (R_BERSERK
in FRulez
));
6106 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ
6107 for i
:= MR_SUIT
to MR_MAX
do utils
.writeInt(st
, LongWord(FMegaRulez
[i
]));
6108 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà
6109 for i
:= T_RESPAWN
to T_FLAGCAP
do utils
.writeInt(st
, LongWord(FTime
[i
]));
6111 utils
.writeStr(st
, FModel
.Name
);
6113 utils
.writeInt(st
, Byte(FColor
.R
));
6114 utils
.writeInt(st
, Byte(FColor
.G
));
6115 utils
.writeInt(st
, Byte(FColor
.B
));
6119 procedure TPlayer
.LoadState (st
: TStream
);
6128 if not utils
.checkSign(st
, 'PLYR') then raise XStreamError
.Create('invalid player signature');
6129 if (utils
.readByte(st
) <> PLR_SAVE_VERSION
) then raise XStreamError
.Create('invalid player version');
6131 FIamBot
:= utils
.readBool(st
);
6133 FUID
:= utils
.readWord(st
);
6135 str
:= utils
.readStr(st
);
6136 if (self
<> gPlayer1
) and (self
<> gPlayer2
) then FName
:= str
;
6138 FTeam
:= utils
.readByte(st
);
6140 FAlive
:= utils
.readBool(st
);
6141 // Èçðàñõîäîâàë ëè âñå æèçíè
6142 FNoRespawn
:= utils
.readBool(st
);
6144 b
:= utils
.readByte(st
);
6145 if b
= 1 then FDirection
:= TDirection
.D_LEFT
else FDirection
:= TDirection
.D_RIGHT
; // b = 2
6147 FHealth
:= utils
.readLongInt(st
);
6148 // Êîýôôèöèåíò èíâàëèäíîñòè
6149 FHandicap
:= utils
.readLongInt(st
);
6151 FLives
:= utils
.readByte(st
);
6153 FArmor
:= utils
.readLongInt(st
);
6155 FAir
:= utils
.readLongInt(st
);
6157 FJetFuel
:= utils
.readLongInt(st
);
6159 FPain
:= utils
.readLongInt(st
);
6161 FKills
:= utils
.readLongInt(st
);
6163 FMonsterKills
:= utils
.readLongInt(st
);
6165 FFrags
:= utils
.readLongInt(st
);
6167 FFragCombo
:= utils
.readByte(st
);
6168 // Âðåìÿ ïîñëåäíåãî ôðàãà
6169 FLastFrag
:= utils
.readLongWord(st
);
6171 FDeath
:= utils
.readLongInt(st
);
6173 FFlag
:= utils
.readByte(st
);
6175 FSecrets
:= utils
.readLongInt(st
);
6177 FCurrWeap
:= utils
.readByte(st
);
6179 FNextWeap
:= utils
.readWord(st
);
6181 FNextWeapDelay
:= utils
.readByte(st
);
6182 // Âðåìÿ çàðÿäêè BFG
6183 FBFGFireCounter
:= utils
.readSmallInt(st
);
6185 FDamageBuffer
:= utils
.readLongInt(st
);
6186 // Ïîñëåäíèé óäàðèâøèé
6187 FLastSpawnerUID
:= utils
.readWord(st
);
6188 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà
6189 FLastHit
:= utils
.readByte(st
);
6191 Obj_LoadState(@FObj
, st
);
6192 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ
6193 for i
:= A_BULLETS
to A_HIGH
do FAmmo
[i
] := utils
.readWord(st
);
6194 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ
6195 for i
:= A_BULLETS
to A_HIGH
do FMaxAmmo
[i
] := utils
.readWord(st
);
6197 for i
:= WP_FIRST
to WP_LAST
do FWeapon
[i
] := utils
.readBool(st
);
6198 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ
6199 for i
:= WP_FIRST
to WP_LAST
do FReloading
[i
] := utils
.readWord(st
);
6201 if utils
.readBool(st
) then Include(FRulez
, R_ITEM_BACKPACK
);
6202 // Íàëè÷èå êðàñíîãî êëþ÷à
6203 if utils
.readBool(st
) then Include(FRulez
, R_KEY_RED
);
6204 // Íàëè÷èå çåëåíîãî êëþ÷à
6205 if utils
.readBool(st
) then Include(FRulez
, R_KEY_GREEN
);
6206 // Íàëè÷èå ñèíåãî êëþ÷à
6207 if utils
.readBool(st
) then Include(FRulez
, R_KEY_BLUE
);
6209 if utils
.readBool(st
) then Include(FRulez
, R_BERSERK
);
6210 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ
6211 for i
:= MR_SUIT
to MR_MAX
do FMegaRulez
[i
] := utils
.readLongWord(st
);
6212 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà
6213 for i
:= T_RESPAWN
to T_FLAGCAP
do FTime
[i
] := utils
.readLongWord(st
);
6215 str
:= utils
.readStr(st
);
6217 FColor
.R
:= utils
.readByte(st
);
6218 FColor
.G
:= utils
.readByte(st
);
6219 FColor
.B
:= utils
.readByte(st
);
6220 if (self
= gPlayer1
) then
6222 str
:= gPlayer1Settings
.Model
;
6223 FColor
:= gPlayer1Settings
.Color
;
6225 else if (self
= gPlayer2
) then
6227 str
:= gPlayer2Settings
.Model
;
6228 FColor
:= gPlayer2Settings
.Color
;
6230 // Îáíîâëÿåì ìîäåëü èãðîêà
6232 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
6233 FModel
.Color
:= TEAMCOLOR
[FTeam
]
6235 FModel
.Color
:= FColor
;
6239 procedure TPlayer
.AllRulez(Health
: Boolean);
6245 FHealth
:= PLAYER_HP_LIMIT
;
6246 FArmor
:= PLAYER_AP_LIMIT
;
6250 for a
:= WP_FIRST
to WP_LAST
do FWeapon
[a
] := True;
6251 for a
:= A_BULLETS
to A_HIGH
do FAmmo
[a
] := 30000;
6252 FRulez
:= FRulez
+[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
];
6255 procedure TPlayer
.RestoreHealthArmor();
6257 FHealth
:= PLAYER_HP_LIMIT
;
6258 FArmor
:= PLAYER_AP_LIMIT
;
6261 procedure TPlayer
.FragCombo();
6265 if (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) or g_Game_IsClient
then
6267 if gTime
- FLastFrag
< FRAG_COMBO_TIME
then
6269 if FFragCombo
< 5 then
6271 Param
:= FUID
or (FFragCombo
shl 16);
6272 if (FComboEvnt
>= Low(gDelayedEvents
)) and
6273 (FComboEvnt
<= High(gDelayedEvents
)) and
6274 gDelayedEvents
[FComboEvnt
].Pending
and
6275 (gDelayedEvents
[FComboEvnt
].DEType
= DE_KILLCOMBO
) and
6276 (gDelayedEvents
[FComboEvnt
].DENum
and $FFFF = FUID
) then
6278 gDelayedEvents
[FComboEvnt
].Time
:= gTime
+ 500;
6279 gDelayedEvents
[FComboEvnt
].DENum
:= Param
;
6282 FComboEvnt
:= g_Game_DelayEvent(DE_KILLCOMBO
, 500, Param
);
6290 procedure TPlayer
.GiveItem(ItemType
: Byte);
6294 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
6296 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
6300 if FAir
< AIR_MAX
then
6307 if not (R_BERSERK
in FRulez
) then
6309 Include(FRulez
, R_BERSERK
);
6310 if FBFGFireCounter
< 1 then
6312 FCurrWeap
:= WEAPON_KASTET
;
6314 FModel
.SetWeapon(WEAPON_KASTET
);
6318 FBerserk
:= gTime
+30000;
6320 if FHealth
< PLAYER_HP_SOFT
then
6322 FHealth
:= PLAYER_HP_SOFT
;
6323 FBerserk
:= gTime
+30000;
6328 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
6330 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
6335 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
6337 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
6341 if FJetFuel
< JET_MAX
then
6343 FJetFuel
:= JET_MAX
;
6346 ITEM_MEDKIT_SMALL
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
6347 ITEM_MEDKIT_LARGE
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
6349 ITEM_ARMOR_GREEN
: if FArmor
< PLAYER_AP_SOFT
then FArmor
:= PLAYER_AP_SOFT
;
6350 ITEM_ARMOR_BLUE
: if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
6352 ITEM_SPHERE_BLUE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
6354 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) then
6356 if FHealth
< PLAYER_HP_LIMIT
then FHealth
:= PLAYER_HP_LIMIT
;
6357 if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
6360 ITEM_WEAPON_SAW
: FWeapon
[WEAPON_SAW
] := True;
6361 ITEM_WEAPON_SHOTGUN1
: FWeapon
[WEAPON_SHOTGUN1
] := True;
6362 ITEM_WEAPON_SHOTGUN2
: FWeapon
[WEAPON_SHOTGUN2
] := True;
6363 ITEM_WEAPON_CHAINGUN
: FWeapon
[WEAPON_CHAINGUN
] := True;
6364 ITEM_WEAPON_ROCKETLAUNCHER
: FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
6365 ITEM_WEAPON_PLASMA
: FWeapon
[WEAPON_PLASMA
] := True;
6366 ITEM_WEAPON_BFG
: FWeapon
[WEAPON_BFG
] := True;
6367 ITEM_WEAPON_SUPERPULEMET
: FWeapon
[WEAPON_SUPERPULEMET
] := True;
6368 ITEM_WEAPON_FLAMETHROWER
: FWeapon
[WEAPON_FLAMETHROWER
] := True;
6370 ITEM_AMMO_BULLETS
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
6371 ITEM_AMMO_BULLETS_BOX
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
6372 ITEM_AMMO_SHELLS
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
6373 ITEM_AMMO_SHELLS_BOX
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
6374 ITEM_AMMO_ROCKET
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
6375 ITEM_AMMO_ROCKET_BOX
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
6376 ITEM_AMMO_CELL
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
6377 ITEM_AMMO_CELL_BIG
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
6378 ITEM_AMMO_FUELCAN
: if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
6381 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
6382 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
6383 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
6384 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or
6385 (FMaxAmmo
[A_FUEL
] < AmmoLimits
[1, A_FUEL
]) then
6387 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[1, A_BULLETS
];
6388 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[1, A_SHELLS
];
6389 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[1, A_ROCKETS
];
6390 FMaxAmmo
[A_CELLS
] := AmmoLimits
[1, A_CELLS
];
6391 FMaxAmmo
[A_FUEL
] := AmmoLimits
[1, A_FUEL
];
6393 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
6394 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
6395 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
6396 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
6398 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
6401 ITEM_KEY_RED
: if not (R_KEY_RED
in FRulez
) then Include(FRulez
, R_KEY_RED
);
6402 ITEM_KEY_GREEN
: if not (R_KEY_GREEN
in FRulez
) then Include(FRulez
, R_KEY_GREEN
);
6403 ITEM_KEY_BLUE
: if not (R_KEY_BLUE
in FRulez
) then Include(FRulez
, R_KEY_BLUE
);
6405 ITEM_BOTTLE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
6406 ITEM_HELMET
: if FArmor
< PLAYER_AP_LIMIT
then IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
6411 if g_Game_IsNet
and g_Game_IsServer
then
6412 MH_SEND_PlayerStats(FUID
);
6415 procedure TPlayer
.FlySmoke(Times
: DWORD
= 1);
6420 if (Random(5) = 1) and (Times
= 1) then
6423 if BodyInLiquid(0, 0) then
6425 g_GFX_Bubbles(Obj
.X
+Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2)+Random(3)-1,
6426 Obj
.Y
+Obj
.Rect
.Height
+8, 1, 8, 4);
6427 if Random(2) = 0 then
6428 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
6430 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
6434 if g_Frames_Get(id
, 'FRAMES_SMOKE') then
6436 for i
:= 1 to Times
do
6438 Anim
:= TAnimation
.Create(id
, False, 3);
6440 g_GFX_OnceAnim(Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(Anim
.Width
div 2),
6441 Obj
.Y
+Obj
.Rect
.Height
-4+Random(8+Times
*2), Anim
, ONCEANIM_SMOKE
);
6447 procedure TPlayer
.OnFireFlame(Times
: DWORD
= 1);
6452 if (Random(10) = 1) and (Times
= 1) then
6455 if g_Frames_Get(id
, 'FRAMES_FLAME') then
6457 for i
:= 1 to Times
do
6459 Anim
:= TAnimation
.Create(id
, False, 3);
6461 g_GFX_OnceAnim(Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(Anim
.Width
div 2),
6462 Obj
.Y
+8+Random(8+Times
*2), Anim
, ONCEANIM_SMOKE
);
6468 procedure TPlayer
.PauseSounds(Enable
: Boolean);
6470 FSawSound
.Pause(Enable
);
6471 FSawSoundIdle
.Pause(Enable
);
6472 FSawSoundHit
.Pause(Enable
);
6473 FSawSoundSelect
.Pause(Enable
);
6474 FFlameSoundOn
.Pause(Enable
);
6475 FFlameSoundOff
.Pause(Enable
);
6476 FFlameSoundWork
.Pause(Enable
);
6477 FJetSoundFly
.Pause(Enable
);
6478 FJetSoundOn
.Pause(Enable
);
6479 FJetSoundOff
.Pause(Enable
);
6484 constructor TCorpse
.Create(X
, Y
: Integer; ModelName
: String; aMess
: Boolean);
6489 FObj
.Rect
:= PLAYER_CORPSERECT
;
6490 FModelName
:= ModelName
;
6495 FState
:= CORPSE_STATE_MESS
;
6496 g_PlayerModel_GetAnim(ModelName
, A_DIE2
, FAnimation
, FAnimationMask
);
6500 FState
:= CORPSE_STATE_NORMAL
;
6501 g_PlayerModel_GetAnim(ModelName
, A_DIE1
, FAnimation
, FAnimationMask
);
6505 destructor TCorpse
.Destroy();
6512 function TCorpse
.ObjPtr (): PObj
; inline; begin result
:= @FObj
; end;
6514 procedure TCorpse
.positionChanged (); inline; begin end;
6516 procedure TCorpse
.moveBy (dx
, dy
: Integer); inline;
6518 if (dx
<> 0) or (dy
<> 0) then
6527 procedure TCorpse
.getMapBox (out x
, y
, w
, h
: Integer); inline;
6529 x
:= FObj
.X
+PLAYER_CORPSERECT
.X
;
6530 y
:= FObj
.Y
+PLAYER_CORPSERECT
.Y
;
6531 w
:= PLAYER_CORPSERECT
.Width
;
6532 h
:= PLAYER_CORPSERECT
.Height
;
6536 procedure TCorpse
.Damage(Value
: Word; SpawnerUID
: Word; vx
, vy
: Integer);
6541 if FState
= CORPSE_STATE_REMOVEME
then
6544 FDamage
:= FDamage
+ Value
;
6546 if FDamage
> 150 then
6548 if FAnimation
<> nil then
6553 FState
:= CORPSE_STATE_REMOVEME
;
6555 g_Player_CreateGibs(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
6556 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2),
6557 FModelName
, FColor
);
6558 // Çâóê ìÿñà îò òðóïà:
6559 pm
:= g_PlayerModel_Get(FModelName
);
6560 pm
.PlaySound(MODELSOUND_DIE
, 5, FObj
.X
, FObj
.Y
);
6564 if (gBodyKillEvent
<> -1)
6565 and gDelayedEvents
[gBodyKillEvent
].Pending
then
6566 gDelayedEvents
[gBodyKillEvent
].Pending
:= False;
6567 gBodyKillEvent
:= g_Game_DelayEvent(DE_BODYKILL
, 1050, SpawnerUID
);
6572 Blood
:= g_PlayerModel_GetBlood(FModelName
);
6573 FObj
.Vel
.X
:= FObj
.Vel
.X
+ vx
;
6574 FObj
.Vel
.Y
:= FObj
.Vel
.Y
+ vy
;
6575 g_GFX_Blood(FObj
.X
+PLAYER_CORPSERECT
.X
+(PLAYER_CORPSERECT
.Width
div 2),
6576 FObj
.Y
+PLAYER_CORPSERECT
.Y
+(PLAYER_CORPSERECT
.Height
div 2),
6577 Value
, vx
, vy
, 16, (PLAYER_CORPSERECT
.Height
*2) div 3,
6578 Blood
.R
, Blood
.G
, Blood
.B
, Blood
.Kind
);
6582 procedure TCorpse
.Draw();
6586 if FState
= CORPSE_STATE_REMOVEME
then
6589 FObj
.lerp(gLerpFactor
, fX
, fY
);
6591 if FAnimation
<> nil then
6592 FAnimation
.Draw(fX
, fY
, TMirrorType
.None
);
6594 if FAnimationMask
<> nil then
6597 FAnimationMask
.Draw(fX
, fY
, TMirrorType
.None
);
6604 procedure TCorpse
.Update();
6608 if FState
= CORPSE_STATE_REMOVEME
then
6611 FObj
.oldX
:= FObj
.X
;
6612 FObj
.oldY
:= FObj
.Y
;
6614 if gTime
mod (GAME_TICK
*2) <> 0 then
6616 g_Obj_Move(@FObj
, True, True, True);
6617 positionChanged(); // this updates spatial accelerators
6621 // Ñîïðîòèâëåíèå âîçäóõà äëÿ òðóïà:
6622 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
6624 st
:= g_Obj_Move(@FObj
, True, True, True);
6625 positionChanged(); // this updates spatial accelerators
6627 if WordBool(st
and MOVE_FALLOUT
) then
6629 FState
:= CORPSE_STATE_REMOVEME
;
6633 if FAnimation
<> nil then
6634 FAnimation
.Update();
6635 if FAnimationMask
<> nil then
6636 FAnimationMask
.Update();
6640 procedure TCorpse
.SaveState (st
: TStream
);
6647 utils
.writeSign(st
, 'CORP');
6648 utils
.writeInt(st
, Byte(0));
6650 utils
.writeInt(st
, Byte(FState
));
6652 utils
.writeInt(st
, Byte(FDamage
));
6654 utils
.writeInt(st
, Byte(FColor
.R
));
6655 utils
.writeInt(st
, Byte(FColor
.G
));
6656 utils
.writeInt(st
, Byte(FColor
.B
));
6658 Obj_SaveState(st
, @FObj
);
6659 utils
.writeInt(st
, Word(FPlayerUID
));
6661 anim
:= (FAnimation
<> nil);
6662 utils
.writeBool(st
, anim
);
6663 // Åñëè åñòü - ñîõðàíÿåì
6664 if anim
then FAnimation
.SaveState(st
);
6665 // Åñòü ëè ìàñêà àíèìàöèè
6666 anim
:= (FAnimationMask
<> nil);
6667 utils
.writeBool(st
, anim
);
6668 // Åñëè åñòü - ñîõðàíÿåì
6669 if anim
then FAnimationMask
.SaveState(st
);
6673 procedure TCorpse
.LoadState (st
: TStream
);
6680 if not utils
.checkSign(st
, 'CORP') then raise XStreamError
.Create('invalid corpse signature');
6681 if (utils
.readByte(st
) <> 0) then raise XStreamError
.Create('invalid corpse version');
6683 FState
:= utils
.readByte(st
);
6685 FDamage
:= utils
.readByte(st
);
6687 FColor
.R
:= utils
.readByte(st
);
6688 FColor
.G
:= utils
.readByte(st
);
6689 FColor
.B
:= utils
.readByte(st
);
6691 Obj_LoadState(@FObj
, st
);
6692 FPlayerUID
:= utils
.readWord(st
);
6694 anim
:= utils
.readBool(st
);
6695 // Åñëè åñòü - çàãðóæàåì
6698 Assert(FAnimation
<> nil, 'TCorpse.LoadState: no FAnimation');
6699 FAnimation
.LoadState(st
);
6701 // Åñòü ëè ìàñêà àíèìàöèè
6702 anim
:= utils
.readBool(st
);
6703 // Åñëè åñòü - çàãðóæàåì
6706 Assert(FAnimationMask
<> nil, 'TCorpse.LoadState: no FAnimationMask');
6707 FAnimationMask
.LoadState(st
);
6713 constructor TBot
.Create();
6720 FSpectator
:= False;
6727 for a
:= WP_FIRST
to WP_LAST
do
6729 FDifficult
.WeaponPrior
[a
] := WEAPON_PRIOR1
[a
];
6730 FDifficult
.CloseWeaponPrior
[a
] := WEAPON_PRIOR2
[a
];
6731 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
6735 destructor TBot
.Destroy();
6738 inherited Destroy();
6741 procedure TBot
.Draw();
6745 //if FTargetUID <> 0 then e_DrawLine(1, FObj.X, FObj.Y, g_Player_Get(FTargetUID).FObj.X,
6746 // g_Player_Get(FTargetUID).FObj.Y, 255, 0, 0);
6749 procedure TBot
.Respawn(Silent
: Boolean; Force
: Boolean = False);
6751 inherited Respawn(Silent
, Force
);
6754 FSelectedWeapon
:= FCurrWeap
;
6759 procedure TBot
.UpdateCombat();
6772 TTargetRecord
= array of TTarget
;
6774 function Compare(a
, b
: TTarget
): Integer;
6776 if a
.Line
and not b
.Line
then // A íà ëèíèè îãíÿ
6779 if not a
.Line
and b
.Line
then // B íà ëèíèè îãíÿ
6781 else // È A, è B íà ëèíèè èëè íå íà ëèíèè îãíÿ
6782 if (a
.Line
and b
.Line
) or ((not a
.Line
) and (not b
.Line
)) then
6784 if a
.Dist
> b
.Dist
then // B áëèæå
6786 else // A áëèæå èëè ðàâíîóäàëåííî ñ B
6789 else // Ñòðàííî -> A
6794 a
, x1
, y1
, x2
, y2
: Integer;
6795 targets
: TTargetRecord
;
6797 Target
, BestTarget
: TTarget
;
6798 firew
, fireh
: Integer;
6802 vsPlayer
, vsMonster
, ok
: Boolean;
6805 function monsUpdate (mon
: TMonster
): Boolean;
6807 result
:= false; // don't stop
6808 if mon
.alive
and (mon
.MonsterType
<> MONSTER_BARREL
) then
6810 if not TargetOnScreen(mon
.Obj
.X
+mon
.Obj
.Rect
.X
, mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
) then exit
;
6812 x2
:= mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2);
6813 y2
:= mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+(mon
.Obj
.Rect
.Height
div 2);
6815 // Åñëè ìîíñòð íà ýêðàíå è íå ïðèêðûò ñòåíîé
6816 if g_TraceVector(x1
, y1
, x2
, y2
) then
6818 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé
6819 SetLength(targets
, Length(targets
)+1);
6820 with targets
[High(targets
)] do
6827 Rect
:= mon
.Obj
.Rect
;
6828 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6829 Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6830 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6839 vsPlayer
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
);
6840 vsMonster
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
);
6842 // Åñëè òåêóùåå îðóæèå íå òî, ÷òî íóæíî, òî ìåíÿåì:
6843 if FCurrWeap
<> FSelectedWeapon
then
6846 // Åñëè íóæíî ñòðåëÿòü è íóæíîå îðóæèå, òî íàæàòü "Ñòðåëÿòü":
6847 if (GetAIFlag('NEEDFIRE') <> '') and (FCurrWeap
= FSelectedWeapon
) then
6849 RemoveAIFlag('NEEDFIRE');
6852 WEAPON_PLASMA
, WEAPON_SUPERPULEMET
, WEAPON_CHAINGUN
: PressKey(KEY_FIRE
, 20);
6853 WEAPON_SAW
, WEAPON_KASTET
, WEAPON_FLAMETHROWER
: PressKey(KEY_FIRE
, 40);
6854 else PressKey(KEY_FIRE
);
6858 // Êîîðäèíàòû ñòâîëà:
6859 x1
:= FObj
.X
+ WEAPONPOINT
[FDirection
].X
;
6860 y1
:= FObj
.Y
+ WEAPONPOINT
[FDirection
].Y
;
6862 Target
.UID
:= FTargetUID
;
6865 if Target
.UID
<> 0 then
6866 begin // Öåëü åñòü - íàñòðàèâàåì
6867 if (g_GetUIDType(Target
.UID
) = UID_PLAYER
) and
6870 tpla
:= g_Player_Get(Target
.UID
);
6874 if (@FObj
) <> nil then
6881 Target
.cX
:= Target
.X
+ PLAYER_RECT_CX
;
6882 Target
.cY
:= Target
.Y
+ PLAYER_RECT_CY
;
6883 Target
.Rect
:= PLAYER_RECT
;
6884 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6885 Target
.Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6886 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6887 Target
.IsPlayer
:= True;
6891 if (g_GetUIDType(Target
.UID
) = UID_MONSTER
) and
6894 mon
:= g_Monsters_ByUID(Target
.UID
);
6897 Target
.X
:= mon
.Obj
.X
;
6898 Target
.Y
:= mon
.Obj
.Y
;
6900 Target
.cX
:= Target
.X
+ mon
.Obj
.Rect
.X
+ (mon
.Obj
.Rect
.Width
div 2);
6901 Target
.cY
:= Target
.Y
+ mon
.Obj
.Rect
.Y
+ (mon
.Obj
.Rect
.Height
div 2);
6902 Target
.Rect
:= mon
.Obj
.Rect
;
6903 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6904 Target
.Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6905 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6906 Target
.IsPlayer
:= False;
6913 begin // Öåëè íåò - îáíóëÿåì
6918 Target
.Visible
:= False;
6919 Target
.Line
:= False;
6920 Target
.IsPlayer
:= False;
6925 // Åñëè öåëü íå âèäèìà èëè íå íà ëèíèè îãíÿ, òî èùåì âñå âîçìîæíûå öåëè:
6926 if (not Target
.Line
) or (not Target
.Visible
) then
6930 for a
:= 0 to High(gPlayers
) do
6931 if (gPlayers
[a
] <> nil) and (gPlayers
[a
].alive
) and
6932 (gPlayers
[a
].FUID
<> FUID
) and
6933 (not SameTeam(FUID
, gPlayers
[a
].FUID
)) and
6934 (not gPlayers
[a
].NoTarget
) and
6935 (gPlayers
[a
].FMegaRulez
[MR_INVIS
] < gTime
) then
6937 if not TargetOnScreen(gPlayers
[a
].FObj
.X
+ PLAYER_RECT
.X
,
6938 gPlayers
[a
].FObj
.Y
+ PLAYER_RECT
.Y
) then
6941 x2
:= gPlayers
[a
].FObj
.X
+ PLAYER_RECT_CX
;
6942 y2
:= gPlayers
[a
].FObj
.Y
+ PLAYER_RECT_CY
;
6944 // Åñëè èãðîê íà ýêðàíå è íå ïðèêðûò ñòåíîé:
6945 if g_TraceVector(x1
, y1
, x2
, y2
) then
6947 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé:
6948 SetLength(targets
, Length(targets
)+1);
6949 with targets
[High(targets
)] do
6951 UID
:= gPlayers
[a
].FUID
;
6952 X
:= gPlayers
[a
].FObj
.X
;
6953 Y
:= gPlayers
[a
].FObj
.Y
;
6956 Rect
:= PLAYER_RECT
;
6957 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6958 Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6959 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6967 if vsMonster
then g_Mons_ForEach(monsUpdate
);
6970 // Åñëè åñòü âîçìîæíûå öåëè:
6971 // (Âûáèðàåì ëó÷øóþ, ìåíÿåì îðóæèå è áåæèì ê íåé/îò íåå)
6972 if targets
<> nil then
6974 // Âûáèðàåì íàèëó÷øóþ öåëü:
6975 BestTarget
:= targets
[0];
6976 if Length(targets
) > 1 then
6977 for a
:= 1 to High(targets
) do
6978 if Compare(BestTarget
, targets
[a
]) = 1 then
6979 BestTarget
:= targets
[a
];
6981 // Åñëè ëó÷øàÿ öåëü "âèäíåå" òåêóùåé, òî òåêóùàÿ := ëó÷øàÿ:
6982 if ((not Target
.Visible
) and BestTarget
.Visible
and (Target
.UID
<> BestTarget
.UID
)) or
6983 ((not Target
.Line
) and BestTarget
.Line
and BestTarget
.Visible
) then
6985 Target
:= BestTarget
;
6987 if (Healthy() = 3) or ((Healthy() = 2)) then
6988 begin // Åñëè çäîðîâû - äîãîíÿåì
6989 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
6990 SetAIFlag('GORIGHT', '1');
6991 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6992 SetAIFlag('GOLEFT', '1');
6995 begin // Åñëè ïîáèòû - óáåãàåì
6996 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) then
6997 SetAIFlag('GORIGHT', '1');
6998 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6999 SetAIFlag('GOLEFT', '1');
7002 // Âûáèðàåì îðóæèå íà îñíîâå ðàññòîÿíèÿ è ïðèîðèòåòîâ:
7003 SelectWeapon(Abs(x1
-Target
.cX
));
7008 // (Äîãîíÿåì/óáåãàåì, ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëè)
7009 // (Åñëè öåëü äàëåêî, òî õâàòèò ñëåäèòü çà íåé)
7010 if Target
.UID
<> 0 then
7012 if not TargetOnScreen(Target
.X
+ Target
.Rect
.X
,
7013 Target
.Y
+ Target
.Rect
.Y
) then
7014 begin // Öåëü ñáåæàëà ñ "ýêðàíà"
7015 if (Healthy() = 3) or ((Healthy() = 2)) then
7016 begin // Åñëè çäîðîâû - äîãîíÿåì
7017 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
7018 SetAIFlag('GORIGHT', '1');
7019 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
7020 SetAIFlag('GOLEFT', '1');
7023 begin // Åñëè ïîáèòû - çàáûâàåì î öåëè è óáåãàåì
7025 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) then
7026 SetAIFlag('GORIGHT', '1');
7027 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
7028 SetAIFlag('GOLEFT', '1');
7032 begin // Öåëü ïîêà íà "ýêðàíå"
7033 // Åñëè öåëü íå çàãîðîæåíà ñòåíîé, òî îòìå÷àåì, êîãäà åå âèäåëè:
7034 if g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
7035 FLastVisible
:= gTime
;
7036 // Åñëè ðàçíèöà âûñîò íå âåëèêà, òî äîãîíÿåì:
7037 if (Abs(FObj
.Y
-Target
.Y
) <= 128) then
7039 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
7040 SetAIFlag('GORIGHT', '1');
7041 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
7042 SetAIFlag('GOLEFT', '1');
7046 // Âûáèðàåì óãîë ââåðõ:
7047 if FDirection
= TDirection
.D_LEFT
then
7048 angle
:= ANGLE_LEFTUP
7050 angle
:= ANGLE_RIGHTUP
;
7052 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7053 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7055 // Åñëè ïðè óãëå ââåðõ ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
7056 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
7057 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128), //96
7058 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
7059 Target
.Rect
.Width
, Target
.Rect
.Height
) and
7060 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
7061 begin // òî íóæíî ñòðåëÿòü ââåðõ
7062 SetAIFlag('NEEDFIRE', '1');
7063 SetAIFlag('NEEDSEEUP', '1');
7066 // Âûáèðàåì óãîë âíèç:
7067 if FDirection
= TDirection
.D_LEFT
then
7068 angle
:= ANGLE_LEFTDOWN
7070 angle
:= ANGLE_RIGHTDOWN
;
7072 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7073 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7075 // Åñëè ïðè óãëå âíèç ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
7076 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
7077 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
7078 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
7079 Target
.Rect
.Width
, Target
.Rect
.Height
) and
7080 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
7081 begin // òî íóæíî ñòðåëÿòü âíèç
7082 SetAIFlag('NEEDFIRE', '1');
7083 SetAIFlag('NEEDSEEDOWN', '1');
7086 // Åñëè öåëü âèäíî è îíà íà òàêîé æå âûñîòå:
7087 if Target
.Visible
and
7088 (y1
+4 < Target
.Y
+Target
.Rect
.Y
+Target
.Rect
.Height
) and
7089 (y1
-4 > Target
.Y
+Target
.Rect
.Y
) then
7091 // Åñëè èäåì â ñòîðîíó öåëè, òî íàäî ñòðåëÿòü:
7092 if ((FDirection
= TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) or
7093 ((FDirection
= TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
7094 begin // òî íóæíî ñòðåëÿòü âïåðåä
7095 SetAIFlag('NEEDFIRE', '1');
7096 SetAIFlag('NEEDSEEDOWN', '');
7097 SetAIFlag('NEEDSEEUP', '');
7099 // Åñëè öåëü â ïðåäåëàõ "ýêðàíà" è ñëîæíîñòü ïîçâîëÿåò ïðûæêè ñáëèæåíèÿ:
7100 if Abs(FObj
.X
-Target
.X
) < Trunc(gPlayerScreenSize
.X
*0.75) then
7101 if GetRnd(FDifficult
.CloseJump
) then
7102 begin // òî åñëè ïîâåçåò - ïðûãàåì (îñîáåííî, åñëè áëèçêî)
7103 if Abs(FObj
.X
-Target
.X
) < 128 then
7107 if Random(a
) = 0 then
7108 SetAIFlag('NEEDJUMP', '1');
7112 // Åñëè öåëü âñå åùå åñòü:
7113 if Target
.UID
<> 0 then
7114 if gTime
-FLastVisible
> 2000 then // Åñëè âèäåëè äàâíî
7115 Target
.UID
:= 0 // òî çàáûòü öåëü
7116 else // Åñëè âèäåëè íåäàâíî
7117 begin // íî öåëü óáèëè
7118 if Target
.IsPlayer
then
7119 begin // Öåëü - èãðîê
7120 pla
:= g_Player_Get(Target
.UID
);
7121 if (pla
= nil) or (not pla
.alive
) or pla
.NoTarget
or
7122 (pla
.FMegaRulez
[MR_INVIS
] >= gTime
) then
7123 Target
.UID
:= 0; // òî çàáûòü öåëü
7126 begin // Öåëü - ìîíñòð
7127 mon
:= g_Monsters_ByUID(Target
.UID
);
7128 if (mon
= nil) or (not mon
.alive
) then
7129 Target
.UID
:= 0; // òî çàáûòü öåëü
7132 end; // if Target.UID <> 0
7134 FTargetUID
:= Target
.UID
;
7136 // Åñëè âîçìîæíûõ öåëåé íåò:
7137 // (Àòàêà ÷åãî-íèáóäü ñëåâà èëè ñïðàâà)
7138 if targets
= nil then
7139 if GetAIFlag('ATTACKLEFT') <> '' then
7140 begin // Åñëè íóæíî àòàêîâàòü íàëåâî
7141 RemoveAIFlag('ATTACKLEFT');
7143 SetAIFlag('NEEDJUMP', '1');
7145 if RunDirection() = TDirection
.D_RIGHT
then
7146 begin // Èäåì íå â òó ñòîðîíó
7147 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
7148 begin // Åñëè çäîðîâû, òî, âîçìîæíî, ñòðåëÿåì áåæèì âëåâî è ñòðåëÿåì
7149 SetAIFlag('NEEDFIRE', '1');
7150 SetAIFlag('GOLEFT', '1');
7154 begin // Èäåì â íóæíóþ ñòîðîíó
7155 if GetRnd(FDifficult
.InvisFire
) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
7156 SetAIFlag('NEEDFIRE', '1');
7157 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
7158 SetAIFlag('GORIGHT', '1');
7162 if GetAIFlag('ATTACKRIGHT') <> '' then
7163 begin // Åñëè íóæíî àòàêîâàòü íàïðàâî
7164 RemoveAIFlag('ATTACKRIGHT');
7166 SetAIFlag('NEEDJUMP', '1');
7168 if RunDirection() = TDirection
.D_LEFT
then
7169 begin // Èäåì íå â òó ñòîðîíó
7170 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
7171 begin // Åñëè çäîðîâû, òî, âîçìîæíî, áåæèì âïðàâî è ñòðåëÿåì
7172 SetAIFlag('NEEDFIRE', '1');
7173 SetAIFlag('GORIGHT', '1');
7178 if GetRnd(FDifficult
.InvisFire
) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
7179 SetAIFlag('NEEDFIRE', '1');
7180 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
7181 SetAIFlag('GOLEFT', '1');
7185 //HACK! (does it belongs there?)
7186 RealizeCurrentWeapon();
7188 // Åñëè åñòü âîçìîæíûå öåëè:
7189 // (Ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëÿì)
7190 if (targets
<> nil) and (GetAIFlag('NEEDFIRE') <> '') then
7191 for a
:= 0 to High(targets
) do
7193 // Åñëè ìîæåì ñòðåëÿòü ïî äèàãîíàëè:
7194 if GetRnd(FDifficult
.DiagFire
) then
7196 // Èùåì öåëü ñâåðõó è ñòðåëÿåì, åñëè åñòü:
7197 if FDirection
= TDirection
.D_LEFT
then
7198 angle
:= ANGLE_LEFTUP
7200 angle
:= ANGLE_RIGHTUP
;
7202 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7203 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7205 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
7206 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
7207 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
7208 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
7209 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
7211 SetAIFlag('NEEDFIRE', '1');
7212 SetAIFlag('NEEDSEEUP', '1');
7215 // Èùåì öåëü ñíèçó è ñòðåëÿåì, åñëè åñòü:
7216 if FDirection
= TDirection
.D_LEFT
then
7217 angle
:= ANGLE_LEFTDOWN
7219 angle
:= ANGLE_RIGHTDOWN
;
7221 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7222 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7224 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
7225 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
7226 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
7227 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
7228 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
7230 SetAIFlag('NEEDFIRE', '1');
7231 SetAIFlag('NEEDSEEDOWN', '1');
7235 // Åñëè öåëü "ïåðåä íîñîì", òî ñòðåëÿåì:
7236 if targets
[a
].Line
and targets
[a
].Visible
and
7237 (((FDirection
= TDirection
.D_LEFT
) and (targets
[a
].X
< FObj
.X
)) or
7238 ((FDirection
= TDirection
.D_RIGHT
) and (targets
[a
].X
> FObj
.X
))) then
7240 SetAIFlag('NEEDFIRE', '1');
7245 // Åñëè ëåòèò ïóëÿ, òî, âîçìîæíî, ïîäïðûãèâàåì:
7246 if g_Weapon_Danger(FUID
, FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
,
7247 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
,
7248 40+GetInterval(FDifficult
.Cover
, 40)) then
7249 SetAIFlag('NEEDJUMP', '1');
7251 // Åñëè êîí÷èëèñü ïàòîðíû, òî íóæíî ñìåíèòü îðóæèå:
7252 ammo
:= GetAmmoByWeapon(FCurrWeap
);
7253 if ((FCurrWeap
= WEAPON_SHOTGUN2
) and (ammo
< 2)) or
7254 ((FCurrWeap
= WEAPON_BFG
) and (ammo
< 40)) or
7256 SetAIFlag('SELECTWEAPON', '1');
7258 // Åñëè íóæíî ñìåíèòü îðóæèå, òî âûáèðàåì íóæíîå:
7259 if GetAIFlag('SELECTWEAPON') = '1' then
7262 RemoveAIFlag('SELECTWEAPON');
7266 procedure TBot
.Update();
7279 // Ïðîâåðÿåì, îòêëþ÷¸í ëè AI áîòîâ
7280 if (g_debug_BotAIOff
= 1) and (Team
= TEAM_RED
) then
7282 if (g_debug_BotAIOff
= 2) and (Team
= TEAM_BLUE
) then
7284 if g_debug_BotAIOff
= 3 then
7294 RealizeCurrentWeapon();
7301 procedure TBot
.ReleaseKey(Key
: Byte);
7310 function TBot
.KeyPressed(Key
: Word): Boolean;
7312 Result
:= FKeys
[Key
].Pressed
;
7315 function TBot
.GetAIFlag(aName
: String20
): String20
;
7321 aName
:= LowerCase(aName
);
7323 if FAIFlags
<> nil then
7324 for a
:= 0 to High(FAIFlags
) do
7325 if LowerCase(FAIFlags
[a
].Name
) = aName
then
7327 Result
:= FAIFlags
[a
].Value
;
7332 procedure TBot
.RemoveAIFlag(aName
: String20
);
7336 if FAIFlags
= nil then Exit
;
7338 aName
:= LowerCase(aName
);
7340 for a
:= 0 to High(FAIFlags
) do
7341 if LowerCase(FAIFlags
[a
].Name
) = aName
then
7343 if a
<> High(FAIFlags
) then
7344 for b
:= a
to High(FAIFlags
)-1 do
7345 FAIFlags
[b
] := FAIFlags
[b
+1];
7347 SetLength(FAIFlags
, Length(FAIFlags
)-1);
7352 procedure TBot
.SetAIFlag(aName
, fValue
: String20
);
7360 aName
:= LowerCase(aName
);
7362 if FAIFlags
<> nil then
7363 for a
:= 0 to High(FAIFlags
) do
7364 if LowerCase(FAIFlags
[a
].Name
) = aName
then
7370 if ok
then FAIFlags
[a
].Value
:= fValue
7373 SetLength(FAIFlags
, Length(FAIFlags
)+1);
7374 with FAIFlags
[High(FAIFlags
)] do
7382 procedure TBot
.UpdateMove
;
7384 procedure GoLeft(Time
: Word = 1);
7386 ReleaseKey(KEY_LEFT
);
7387 ReleaseKey(KEY_RIGHT
);
7388 PressKey(KEY_LEFT
, Time
);
7389 SetDirection(TDirection
.D_LEFT
);
7392 procedure GoRight(Time
: Word = 1);
7394 ReleaseKey(KEY_LEFT
);
7395 ReleaseKey(KEY_RIGHT
);
7396 PressKey(KEY_RIGHT
, Time
);
7397 SetDirection(TDirection
.D_RIGHT
);
7400 function Rnd(a
: Word): Boolean;
7402 Result
:= Random(a
) = 0;
7405 procedure Turn(Time
: Word = 1200);
7407 if RunDirection() = TDirection
.D_LEFT
then GoRight(Time
) else GoLeft(Time
);
7412 ReleaseKey(KEY_LEFT
);
7413 ReleaseKey(KEY_RIGHT
);
7416 function CanRunLeft(): Boolean;
7418 Result
:= not CollideLevel(-1, 0);
7421 function CanRunRight(): Boolean;
7423 Result
:= not CollideLevel(1, 0);
7426 function CanRun(): Boolean;
7428 if RunDirection() = TDirection
.D_LEFT
then Result
:= CanRunLeft() else Result
:= CanRunRight();
7431 procedure Jump(Time
: Word = 30);
7433 PressKey(KEY_JUMP
, Time
);
7436 function NearHole(): Boolean;
7440 { TODO 5 : Ëåñòíèöû }
7441 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7442 for x
:= 1 to PLAYER_RECT
.Width
do
7443 if (not StayOnStep(x
*sx
, 0)) and
7444 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7445 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7454 function BorderHole(): Boolean;
7458 { TODO 5 : Ëåñòíèöû }
7459 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7460 for x
:= 1 to PLAYER_RECT
.Width
do
7461 if (not StayOnStep(x
*sx
, 0)) and
7462 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7463 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7465 for xx
:= x
to x
+32 do
7466 if CollideLevel(xx
*sx
, PLAYER_RECT
.Height
) then
7476 function NearDeepHole(): Boolean;
7482 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7485 for x
:= 1 to PLAYER_RECT
.Width
do
7486 if (not StayOnStep(x
*sx
, 0)) and
7487 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7488 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7490 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
7492 if CollideLevel(x
*sx
, PLAYER_RECT
.Height
*y
) then Exit
;
7497 end else Result
:= False;
7500 function OverDeepHole(): Boolean;
7507 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
7509 if CollideLevel(0, PLAYER_RECT
.Height
*y
) then Exit
;
7516 function OnGround(): Boolean;
7518 Result
:= StayOnStep(0, 0) or CollideLevel(0, 1);
7521 function OnLadder(): Boolean;
7523 Result
:= FullInStep(0, 0);
7526 function BelowLadder(): Boolean;
7528 Result
:= (FullInStep(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) and
7529 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
7530 (FullInStep(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) and
7531 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
7534 function BelowLiftUp(): Boolean;
7536 Result
:= ((FullInLift(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) = -1) and
7537 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
7538 ((FullInLift(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) = -1) and
7539 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
7542 function OnTopLift(): Boolean;
7544 Result
:= (FullInLift(0, 0) = -1) and (FullInLift(0, -32) = 0);
7547 function CanJumpOver(): Boolean;
7551 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7555 if not CollideLevel(sx
, 0) then Exit
;
7557 for y
:= 1 to BOT_MAXJUMP
do
7558 if CollideLevel(0, -y
) then Exit
else
7559 if not CollideLevel(sx
, -y
) then
7566 function CanJumpUp(Dist
: ShortInt): Boolean;
7573 if CollideLevel(Dist
, 0) then Exit
;
7576 for y
:= 0 to BOT_MAXJUMP
do
7577 if CollideLevel(Dist
, -y
) then
7586 for yy
:= y
+1 to BOT_MAXJUMP
do
7587 if not CollideLevel(Dist
, -yy
) then
7596 for y
:= 0 to BOT_MAXJUMP
do
7597 if CollideLevel(0, -y
) then
7605 if y
< yy
then Exit
;
7610 function IsSafeTrigger(): Boolean;
7615 if gTriggers
= nil then
7617 for a
:= 0 to High(gTriggers
) do
7618 if Collide(gTriggers
[a
].X
,
7621 gTriggers
[a
].Height
) and
7622 (gTriggers
[a
].TriggerType
in [TRIGGER_EXIT
, TRIGGER_CLOSEDOOR
,
7623 TRIGGER_CLOSETRAP
, TRIGGER_TRAP
,
7624 TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
,
7625 TRIGGER_ONOFF
, TRIGGER_SPAWNMONSTER
,
7626 TRIGGER_DAMAGE
, TRIGGER_SHOT
]) then
7631 // Âîçìîæíî, íàæèìàåì êíîïêó:
7632 if Rnd(16) and IsSafeTrigger() then
7635 // Åñëè ïîä ëèôòîì èëè ñòóïåíüêàìè, òî, âîçìîæíî, ïðûãàåì:
7636 if OnLadder() or ((BelowLadder() or BelowLiftUp()) and Rnd(8)) then
7638 ReleaseKey(KEY_LEFT
);
7639 ReleaseKey(KEY_RIGHT
);
7643 // Èäåì âëåâî, åñëè íàäî áûëî:
7644 if GetAIFlag('GOLEFT') <> '' then
7646 RemoveAIFlag('GOLEFT');
7647 if CanRunLeft() then
7651 // Èäåì âïðàâî, åñëè íàäî áûëî:
7652 if GetAIFlag('GORIGHT') <> '' then
7654 RemoveAIFlag('GORIGHT');
7655 if CanRunRight() then
7659 // Åñëè âûëåòåëè çà êàðòó, òî ïðîáóåì âåðíóòüñÿ:
7660 if FObj
.X
< -32 then
7663 if FObj
.X
+32 > gMapInfo
.Width
then
7666 // Ïðûãàåì, åñëè íàäî áûëî:
7667 if GetAIFlag('NEEDJUMP') <> '' then
7670 RemoveAIFlag('NEEDJUMP');
7673 // Ñìîòðèì ââåðõ, åñëè íàäî áûëî:
7674 if GetAIFlag('NEEDSEEUP') <> '' then
7677 ReleaseKey(KEY_DOWN
);
7678 PressKey(KEY_UP
, 20);
7679 RemoveAIFlag('NEEDSEEUP');
7682 // Ñìîòðèì âíèç, åñëè íàäî áûëî:
7683 if GetAIFlag('NEEDSEEDOWN') <> '' then
7686 ReleaseKey(KEY_DOWN
);
7687 PressKey(KEY_DOWN
, 20);
7688 RemoveAIFlag('NEEDSEEDOWN');
7691 // Åñëè íóæíî áûëî â äûðó è ìû íå íà çåìëå, òî ïîêîðíî ëåòèì:
7692 if GetAIFlag('GOINHOLE') <> '' then
7693 if not OnGround() then
7695 ReleaseKey(KEY_LEFT
);
7696 ReleaseKey(KEY_RIGHT
);
7697 RemoveAIFlag('GOINHOLE');
7698 SetAIFlag('FALLINHOLE', '1');
7701 // Åñëè ïàäàëè è äîñòèãëè çåìëè, òî õâàòèò ïàäàòü:
7702 if GetAIFlag('FALLINHOLE') <> '' then
7704 RemoveAIFlag('FALLINHOLE');
7706 // Åñëè ëåòåëè ïðÿìî è ñåé÷àñ íå íà ëåñòíèöå èëè íà âåðøèíå ëèôòà, òî îòõîäèì â ñòîðîíó:
7707 if not (KeyPressed(KEY_LEFT
) or KeyPressed(KEY_RIGHT
)) then
7708 if GetAIFlag('FALLINHOLE') = '' then
7709 if (not OnLadder()) or (FObj
.Vel
.Y
>= 0) or (OnTopLift()) then
7715 // Åñëè íà çåìëå è ìîæíî ïîäïðûãíóòü, òî, âîçìîæíî, ïðûãàåì:
7717 CanJumpUp(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*32) and
7721 // Åñëè íà çåìëå è âîçëå äûðû (ãëóáèíà > 2 ðîñòîâ èãðîêà):
7722 if OnGround() and NearHole() then
7723 if NearDeepHole() then // Åñëè ýòî áåçäíà
7725 0..3: Turn(); // Áåæèì îáðàòíî
7726 4: Jump(); // Ïðûãàåì
7727 5: begin // Ïðûãàåì îáðàòíî
7732 else // Ýòî íå áåçäíà è ìû åùå íå ëåòèì òóäà
7733 if GetAIFlag('GOINHOLE') = '' then
7735 0: Turn(); // Íå íóæíî òóäà
7736 1: Jump(); // Âäðóã ïîâåçåò - ïðûãàåì
7737 else // Åñëè ÿìà ñ ãðàíèöåé, òî ïðè ñëó÷àå ìîæíî òóäà ïðûãíóòü
7738 if BorderHole() then
7739 SetAIFlag('GOINHOLE', '1');
7742 // Åñëè íà çåìëå, íî íåêóäà èäòè:
7743 if (not CanRun()) and OnGround() then
7745 // Åñëè ìû íà ëåñòíèöå èëè ìîæíî ïåðåïðûãíóòü, òî ïðûãàåì:
7746 if CanJumpOver() or OnLadder() then
7748 else // èíà÷å ïîïûòàåìñÿ â äðóãóþ ñòîðîíó
7749 if Random(2) = 0 then
7751 if IsSafeTrigger() then
7757 // Îñòàëîñü ìàëî âîçäóõà:
7758 if FAir
< 36 * 2 then
7761 // Âûáèðàåìñÿ èç êèñëîòû, åñëè íåò êîñòþìà, îáîæãëèñü, èëè ìàëî çäîðîâüÿ:
7762 if (FMegaRulez
[MR_SUIT
] < gTime
) and ((FLastHit
= HIT_ACID
) or (Healthy() <= 1)) then
7763 if BodyInAcid(0, 0) then
7767 function TBot
.FullInStep(XInc
, YInc
: Integer): Boolean;
7769 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
7770 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_STEP
, False);
7773 {function TBot.NeedItem(Item: Byte): Byte;
7778 procedure TBot
.SelectWeapon(Dist
: Integer);
7782 function HaveAmmo(weapon
: Byte): Boolean;
7785 WEAPON_PISTOL
: Result
:= FAmmo
[A_BULLETS
] >= 1;
7786 WEAPON_SHOTGUN1
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7787 WEAPON_SHOTGUN2
: Result
:= FAmmo
[A_SHELLS
] >= 2;
7788 WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
] >= 10;
7789 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
] >= 1;
7790 WEAPON_PLASMA
: Result
:= FAmmo
[A_CELLS
] >= 10;
7791 WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
] >= 40;
7792 WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7793 WEAPON_FLAMETHROWER
: Result
:= FAmmo
[A_FUEL
] >= 1;
7794 else Result
:= True;
7799 if Dist
= -1 then Dist
:= BOT_LONGDIST
;
7801 if Dist
> BOT_LONGDIST
then
7802 begin // Äàëüíèé áîé
7804 if FWeapon
[FDifficult
.WeaponPrior
[a
]] and HaveAmmo(FDifficult
.WeaponPrior
[a
]) then
7806 FSelectedWeapon
:= FDifficult
.WeaponPrior
[a
];
7810 else //if Dist > BOT_UNSAFEDIST then
7811 begin // Áëèæíèé áîé
7813 if FWeapon
[FDifficult
.CloseWeaponPrior
[a
]] and HaveAmmo(FDifficult
.CloseWeaponPrior
[a
]) then
7815 FSelectedWeapon
:= FDifficult
.CloseWeaponPrior
[a
];
7822 if FWeapon[FDifficult.SafeWeaponPrior[a]] and HaveAmmo(FDifficult.SafeWeaponPrior[a]) then
7824 FSelectedWeapon := FDifficult.SafeWeaponPrior[a];
7830 function TBot
.PickItem(ItemType
: Byte; force
: Boolean; var remove
: Boolean): Boolean;
7832 Result
:= inherited PickItem(ItemType
, force
, remove
);
7834 if Result
then SetAIFlag('SELECTWEAPON', '1');
7837 function TBot
.Heal(value
: Word; Soft
: Boolean): Boolean;
7839 Result
:= inherited Heal(value
, Soft
);
7842 function TBot
.Healthy(): Byte;
7844 if FMegaRulez
[MR_INVUL
] >= gTime
then Result
:= 3
7845 else if (FHealth
> 80) or ((FHealth
> 50) and (FArmor
> 20)) then Result
:= 3
7846 else if (FHealth
> 50) then Result
:= 2
7847 else if (FHealth
> 20) then Result
:= 1
7851 function TBot
.TargetOnScreen(TX
, TY
: Integer): Boolean;
7853 Result
:= (Abs(FObj
.X
-TX
) <= Trunc(gPlayerScreenSize
.X
*0.6)) and
7854 (Abs(FObj
.Y
-TY
) <= Trunc(gPlayerScreenSize
.Y
*0.6));
7857 procedure TBot
.OnDamage(Angle
: SmallInt);
7865 if (Angle
= 0) or (Angle
= 180) then
7868 if (g_GetUIDType(FLastSpawnerUID
) = UID_PLAYER
) and
7869 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
) then
7871 pla
:= g_Player_Get(FLastSpawnerUID
);
7872 ok
:= not TargetOnScreen(pla
.FObj
.X
+ PLAYER_RECT
.X
,
7873 pla
.FObj
.Y
+ PLAYER_RECT
.Y
);
7876 if (g_GetUIDType(FLastSpawnerUID
) = UID_MONSTER
) and
7877 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
) then
7879 mon
:= g_Monsters_ByUID(FLastSpawnerUID
);
7880 ok
:= not TargetOnScreen(mon
.Obj
.X
+ mon
.Obj
.Rect
.X
,
7881 mon
.Obj
.Y
+ mon
.Obj
.Rect
.Y
);
7886 SetAIFlag('ATTACKLEFT', '1')
7888 SetAIFlag('ATTACKRIGHT', '1');
7892 function TBot
.RunDirection(): TDirection
;
7894 if Abs(Vel
.X
) >= 1 then
7896 if Vel
.X
> 0 then Result
:= TDirection
.D_RIGHT
else Result
:= TDirection
.D_LEFT
;
7898 Result
:= FDirection
;
7901 function TBot
.GetRnd(a
: Byte): Boolean;
7903 if a
= 0 then Result
:= False
7904 else if a
= 255 then Result
:= True
7905 else Result
:= Random(256) > 255-a
;
7908 function TBot
.GetInterval(a
: Byte; radius
: SmallInt): SmallInt;
7910 Result
:= Round((255-a
)/255*radius
*(Random(2)-1));
7914 procedure TDifficult
.save (st
: TStream
);
7916 utils
.writeInt(st
, Byte(DiagFire
));
7917 utils
.writeInt(st
, Byte(InvisFire
));
7918 utils
.writeInt(st
, Byte(DiagPrecision
));
7919 utils
.writeInt(st
, Byte(FlyPrecision
));
7920 utils
.writeInt(st
, Byte(Cover
));
7921 utils
.writeInt(st
, Byte(CloseJump
));
7922 st
.WriteBuffer(WeaponPrior
[Low(WeaponPrior
)], sizeof(WeaponPrior
));
7923 st
.WriteBuffer(CloseWeaponPrior
[Low(CloseWeaponPrior
)], sizeof(CloseWeaponPrior
));
7926 procedure TDifficult
.load (st
: TStream
);
7928 DiagFire
:= utils
.readByte(st
);
7929 InvisFire
:= utils
.readByte(st
);
7930 DiagPrecision
:= utils
.readByte(st
);
7931 FlyPrecision
:= utils
.readByte(st
);
7932 Cover
:= utils
.readByte(st
);
7933 CloseJump
:= utils
.readByte(st
);
7934 st
.ReadBuffer(WeaponPrior
[Low(WeaponPrior
)], sizeof(WeaponPrior
));
7935 st
.ReadBuffer(CloseWeaponPrior
[Low(CloseWeaponPrior
)], sizeof(CloseWeaponPrior
));
7939 procedure TBot
.SaveState (st
: TStream
);
7944 inherited SaveState(st
);
7945 utils
.writeSign(st
, 'BOT0');
7947 utils
.writeInt(st
, Byte(FSelectedWeapon
));
7949 utils
.writeInt(st
, Word(FTargetUID
));
7950 // Âðåìÿ ïîòåðè öåëè
7951 utils
.writeInt(st
, LongWord(FLastVisible
));
7952 // Êîëè÷åñòâî ôëàãîâ ÈÈ
7953 dw
:= Length(FAIFlags
);
7954 utils
.writeInt(st
, LongInt(dw
));
7956 for i
:= 0 to dw
-1 do
7958 utils
.writeStr(st
, FAIFlags
[i
].Name
, 20);
7959 utils
.writeStr(st
, FAIFlags
[i
].Value
, 20);
7961 // Íàñòðîéêè ñëîæíîñòè
7962 FDifficult
.save(st
);
7966 procedure TBot
.LoadState (st
: TStream
);
7971 inherited LoadState(st
);
7972 if not utils
.checkSign(st
, 'BOT0') then raise XStreamError
.Create('invalid bot signature');
7974 FSelectedWeapon
:= utils
.readByte(st
);
7976 FTargetUID
:= utils
.readWord(st
);
7977 // Âðåìÿ ïîòåðè öåëè
7978 FLastVisible
:= utils
.readLongWord(st
);
7979 // Êîëè÷åñòâî ôëàãîâ ÈÈ
7980 dw
:= utils
.readLongInt(st
);
7981 if (dw
< 0) or (dw
> 16384) then raise XStreamError
.Create('invalid number of bot AI flags');
7982 SetLength(FAIFlags
, dw
);
7984 for i
:= 0 to dw
-1 do
7986 FAIFlags
[i
].Name
:= utils
.readStr(st
, 20);
7987 FAIFlags
[i
].Value
:= utils
.readStr(st
, 20);
7989 // Íàñòðîéêè ñëîæíîñòè
7990 FDifficult
.load(st
);
7995 conRegVar('cheat_berserk_autoswitch', @gBerserkAutoswitch
, 'autoswitch to fist when berserk pack taken', '', true, true);
7996 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');
7997 conRegVar('player_indicator_style', @gPlayerIndicatorStyle
, 'Visual appearance of indicator', 'Visual appearance of indicator');