1 (* Copyright (C) Doom 2D: Forever Developers
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, version 3 of the License ONLY.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 {$INCLUDE ../shared/a_modes.inc}
23 {$IFDEF USE_MEMPOOL}mempool
,{$ENDIF}
24 e_graphics
, g_playermodel
, g_basic
, g_textures
,
25 g_weapons
, g_phys
, g_sound
, g_saveload
, MAPDEF
,
61 AmmoLimits
: Array [0..1] of Array [A_BULLETS
..A_HIGH
] of Word =
62 ((200, 50, 50, 300, 100),
63 (400, 100, 100, 600, 200));
84 ANGLE_NONE
= Low(SmallInt);
86 CORPSE_STATE_REMOVEME
= 0;
87 CORPSE_STATE_NORMAL
= 1;
88 CORPSE_STATE_MESS
= 2;
90 PLAYER_RECT
: TRectWH
= (X
:15; Y
:12; Width
:34; Height
:52);
91 PLAYER_RECT_CX
= 15+(34 div 2);
92 PLAYER_RECT_CY
= 12+(52 div 2);
93 PLAYER_CORPSERECT
: TRectWH
= (X
:15; Y
:48; Width
:34; Height
:16);
96 PLAYER_HP_LIMIT
= 200;
98 PLAYER_AP_LIMIT
= 200;
102 PLAYER_BURN_TIME
= 110;
104 PLAYER1_DEF_COLOR
: TRGB
= (R
:64; G
:175; B
:48);
105 PLAYER2_DEF_COLOR
: TRGB
= (R
:96; G
:96; B
:96);
123 TPlayerStatArray
= Array of TPlayerStat
;
125 TPlayerSavedState
= record
133 Ammo
: Array [A_BULLETS
..A_HIGH
] of Word;
134 MaxAmmo
: Array [A_BULLETS
..A_HIGH
] of Word;
135 Weapon
: Array [WP_FIRST
..WP_LAST
] of Boolean;
136 Rulez
: Set of R_ITEM_BACKPACK
..R_BERSERK
;
145 TPlayer
= class{$IFDEF USE_MEMPOOL}(TPoolObject
){$ENDIF}
153 FDirection
: TDirection
;
161 FMonsterKills
: Integer;
167 FCanJetpack
: Boolean;
173 FNextWeapDelay
: Byte; // frames
174 FBFGFireCounter
: SmallInt;
175 FLastSpawnerUID
: Word;
179 FSpectatePlayer
: Integer;
180 FFirePainTime
: Integer;
183 FSavedStateNum
: Integer;
185 FModel
: TPlayerModel
;
186 FPunchAnim
: TAnimation
;
189 FActionForce
: Boolean;
190 FActionChanged
: Boolean;
192 FFireAngle
: SmallInt;
196 FShellTimer
: Integer;
198 FSawSound
: TPlayableSound
;
199 FSawSoundIdle
: TPlayableSound
;
200 FSawSoundHit
: TPlayableSound
;
201 FSawSoundSelect
: TPlayableSound
;
202 FFlameSoundOn
: TPlayableSound
;
203 FFlameSoundOff
: TPlayableSound
;
204 FFlameSoundWork
: TPlayableSound
;
205 FJetSoundOn
: TPlayableSound
;
206 FJetSoundOff
: TPlayableSound
;
207 FJetSoundFly
: TPlayableSound
;
211 FJustTeleported
: Boolean;
213 mEDamageType
: Integer;
216 function CollideLevel(XInc
, YInc
: Integer): Boolean;
217 function StayOnStep(XInc
, YInc
: Integer): Boolean;
218 function HeadInLiquid(XInc
, YInc
: Integer): Boolean;
219 function BodyInLiquid(XInc
, YInc
: Integer): Boolean;
220 function BodyInAcid(XInc
, YInc
: Integer): Boolean;
221 function FullInLift(XInc
, YInc
: Integer): Integer;
222 {procedure CollideItem();}
223 procedure FlySmoke(Times
: DWORD
= 1);
224 procedure OnFireFlame(Times
: DWORD
= 1);
225 function GetAmmoByWeapon(Weapon
: Byte): Word;
226 procedure SetAction(Action
: Byte; Force
: Boolean = False);
227 procedure OnDamage(Angle
: SmallInt); virtual;
228 function firediry(): Integer;
231 procedure Run(Direction
: TDirection
);
232 procedure NextWeapon();
233 procedure PrevWeapon();
240 function getNextWeaponIndex (): Byte; // return 255 for "no switch"
241 procedure resetWeaponQueue ();
242 function hasAmmoForWeapon (weapon
: Byte): Boolean;
243 function shouldSwitch (weapon
: Byte; hadWeapon
: Boolean) : Boolean;
245 procedure doDamage (v
: Integer);
247 function refreshCorpse(): Boolean;
250 FDamageBuffer
: Integer;
252 FAmmo
: Array [A_BULLETS
..A_HIGH
] of Word;
253 FMaxAmmo
: Array [A_BULLETS
..A_HIGH
] of Word;
254 FWeapon
: Array [WP_FIRST
..WP_LAST
] of Boolean;
255 FRulez
: Set of R_ITEM_BACKPACK
..R_BERSERK
;
257 FMegaRulez
: Array [MR_SUIT
..MR_MAX
] of DWORD
;
258 FReloading
: Array [WP_FIRST
..WP_LAST
] of Word;
259 FTime
: Array [T_RESPAWN
..T_FLAGCAP
] of DWORD
;
260 FKeys
: Array [KEY_LEFT
..KEY_CHAT
] of TKeyState
;
261 FWeapSwitchMode
: Byte;
262 FWeapPreferences
: Array [WP_FIRST
.. WP_LAST
+1] of Byte;
263 FSwitchToEmpty
: Byte;
266 FPreferredTeam
: Byte;
269 FWantsInGame
: Boolean;
274 FActualModelName
: string;
281 FSpawnInvul
: Integer;
283 FWaitForFirstSpawn
: Boolean; // set to `true` in server, used to spawn a player on first full state request
286 // debug: viewport offset
287 viewPortX
, viewPortY
, viewPortW
, viewPortH
: Integer;
289 function isValidViewPort (): Boolean; inline;
291 constructor Create(); virtual;
292 destructor Destroy(); override;
293 procedure Respawn(Silent
: Boolean; Force
: Boolean = False); virtual;
294 function GetRespawnPoint(): Byte;
295 procedure PressKey(Key
: Byte; Time
: Word = 1);
296 procedure ReleaseKeys();
297 procedure SetModel(ModelName
: String);
298 procedure SetColor(Color
: TRGB
);
299 function GetColor(): TRGB
;
300 procedure SetWeapon(W
: Byte);
301 function IsKeyPressed(K
: Byte): Boolean;
302 function GetKeys(): Byte;
303 function PickItem(ItemType
: Byte; arespawn
: Boolean; var remove
: Boolean): Boolean; virtual;
304 procedure SetWeaponPrefs(Prefs
: Array of Byte);
305 procedure SetWeaponPref(Weapon
, Pref
: Byte);
306 function GetWeaponPref(Weapon
: Byte) : Byte;
307 function GetMorePrefered() : Byte;
308 function MaySwitch(Weapon
: Byte) : Boolean;
309 function Collide(X
, Y
: Integer; Width
, Height
: Word): Boolean; overload
;
310 function Collide(Panel
: TPanel
): Boolean; overload
;
311 function Collide(X
, Y
: Integer): Boolean; overload
;
312 procedure SetDirection(Direction
: TDirection
);
313 procedure GetSecret();
314 function TeleportTo(X
, Y
: Integer; silent
: Boolean; dir
: Byte): Boolean;
316 procedure Push(vx
, vy
: Integer);
317 procedure ChangeModel(ModelName
: String);
318 procedure SwitchTeam
;
319 procedure ChangeTeam(Team
: Byte);
321 function GetFlag(Flag
: Byte): Boolean;
322 procedure SetFlag(Flag
: Byte);
323 function DropFlag(Silent
: Boolean = True; DoThrow
: Boolean = False): Boolean;
324 function TryDropFlag(): Boolean;
325 procedure AllRulez(Health
: Boolean);
326 procedure RestoreHealthArmor();
327 procedure FragCombo();
328 procedure GiveItem(ItemType
: Byte);
329 procedure Damage(value
: Word; SpawnerUID
: Word; vx
, vy
: Integer; t
: Byte); virtual;
330 function Heal(value
: Word; Soft
: Boolean): Boolean; virtual;
331 procedure MakeBloodVector(Count
: Word; VelX
, VelY
: Integer);
332 procedure MakeBloodSimple(Count
: Word);
333 procedure Kill(KillType
: Byte; SpawnerUID
: Word; t
: Byte);
334 procedure Reset(Force
: Boolean);
335 procedure Spectate(NoMove
: Boolean = False);
336 procedure SwitchNoClip
;
337 procedure SoftReset();
338 procedure Draw(); virtual;
339 procedure DrawPain();
340 procedure DrawPickup();
341 procedure DrawRulez();
343 procedure DrawIndicator(Color
: TRGB
);
344 procedure DrawBubble();
346 procedure PreUpdate();
347 procedure Update(); virtual;
348 procedure RememberState();
349 procedure RecallState();
350 procedure SaveState (st
: TStream
); virtual;
351 procedure LoadState (st
: TStream
); virtual;
352 procedure PauseSounds(Enable
: Boolean);
353 procedure NetFire(Wpn
: Byte; X
, Y
, AX
, AY
: Integer; WID
: Integer = -1);
354 procedure DoLerp(Level
: Integer = 2);
355 procedure SetLerp(XTo
, YTo
: Integer);
356 procedure ProcessWeaponAction(Action
: Byte);
357 procedure QueueWeaponSwitch(Weapon
: Byte);
358 procedure RealizeCurrentWeapon();
362 procedure JetpackOff
;
363 procedure CatchFire(Attacker
: Word; Timeout
: Integer = PLAYER_BURN_TIME
);
365 //WARNING! this does nothing for now, but still call it!
366 procedure positionChanged (); //WARNING! call this after entity position was changed, or coldet will not work right!
368 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
369 procedure moveBy (dx
, dy
: Integer); inline;
371 function getCameraObj(): TObj
;
374 property Vel
: TPoint2i read FObj
.Vel
;
375 property Obj
: TObj read FObj
;
377 property Name
: String read FName write FName
;
378 property Model
: TPlayerModel read FModel
;
379 property Health
: Integer read FHealth write FHealth
;
380 property Lives
: Byte read FLives write FLives
;
381 property Armor
: Integer read FArmor write FArmor
;
382 property Air
: Integer read FAir write FAir
;
383 property JetFuel
: Integer read FJetFuel write FJetFuel
;
384 property Frags
: Integer read FFrags write FFrags
;
385 property Death
: Integer read FDeath write FDeath
;
386 property Kills
: Integer read FKills write FKills
;
387 property CurrWeap
: Byte read FCurrWeap write FCurrWeap
;
388 property WeapSwitchMode
: Byte read FWeapSwitchMode write FWeapSwitchMode
;
389 property SwitchToEmpty
: Byte read FSwitchToEmpty write FSwitchToEmpty
;
390 property SkipFist
: Byte read FSkipFist write FSkipFist
;
391 property MonsterKills
: Integer read FMonsterKills write FMonsterKills
;
392 property Secrets
: Integer read FSecrets
;
393 property GodMode
: Boolean read FGodMode write FGodMode
;
394 property NoTarget
: Boolean read FNoTarget write FNoTarget
;
395 property NoReload
: Boolean read FNoReload write FNoReload
;
396 property alive
: Boolean read FAlive write FAlive
;
397 property Flag
: Byte read FFlag
;
398 property Team
: Byte read FTeam write FTeam
;
399 property Direction
: TDirection read FDirection
;
400 property GameX
: Integer read FObj
.X write FObj
.X
;
401 property GameY
: Integer read FObj
.Y write FObj
.Y
;
402 property GameVelX
: Integer read FObj
.Vel
.X write FObj
.Vel
.X
;
403 property GameVelY
: Integer read FObj
.Vel
.Y write FObj
.Vel
.Y
;
404 property GameAccelX
: Integer read FObj
.Accel
.X write FObj
.Accel
.X
;
405 property GameAccelY
: Integer read FObj
.Accel
.Y write FObj
.Accel
.Y
;
406 property IncCam
: Integer read FIncCam write FIncCam
;
407 property IncCamOld
: Integer read FIncCamOld write FIncCamOld
;
408 property SlopeOld
: Integer read FSlopeOld write FSlopeOld
;
409 property UID
: Word read FUID write FUID
;
410 property JustTeleported
: Boolean read FJustTeleported write FJustTeleported
;
411 property NetTime
: LongWord read FNetTime write FNetTime
;
414 property eName
: String read FName write FName
;
415 property eHealth
: Integer read FHealth write FHealth
;
416 property eLives
: Byte read FLives write FLives
;
417 property eArmor
: Integer read FArmor write FArmor
;
418 property eAir
: Integer read FAir write FAir
;
419 property eJetFuel
: Integer read FJetFuel write FJetFuel
;
420 property eFrags
: Integer read FFrags write FFrags
;
421 property eDeath
: Integer read FDeath write FDeath
;
422 property eKills
: Integer read FKills write FKills
;
423 property eCurrWeap
: Byte read FCurrWeap write FCurrWeap
;
424 property eMonsterKills
: Integer read FMonsterKills write FMonsterKills
;
425 property eSecrets
: Integer read FSecrets write FSecrets
;
426 property eGodMode
: Boolean read FGodMode write FGodMode
;
427 property eNoTarget
: Boolean read FNoTarget write FNoTarget
;
428 property eNoReload
: Boolean read FNoReload write FNoReload
;
429 property eAlive
: Boolean read FAlive write FAlive
;
430 property eFlag
: Byte read FFlag
;
431 property eTeam
: Byte read FTeam write FTeam
;
432 property eDirection
: TDirection read FDirection
;
433 property eGameX
: Integer read FObj
.X write FObj
.X
;
434 property eGameY
: Integer read FObj
.Y write FObj
.Y
;
435 property eGameVelX
: Integer read FObj
.Vel
.X write FObj
.Vel
.X
;
436 property eGameVelY
: Integer read FObj
.Vel
.Y write FObj
.Vel
.Y
;
437 property eGameAccelX
: Integer read FObj
.Accel
.X write FObj
.Accel
.X
;
438 property eGameAccelY
: Integer read FObj
.Accel
.Y write FObj
.Accel
.Y
;
439 property eIncCam
: Integer read FIncCam write FIncCam
;
440 property eUID
: Word read FUID
;
441 property eJustTeleported
: Boolean read FJustTeleported
;
442 property eNetTime
: LongWord read FNetTime
;
444 // set this before assigning something to `eDamage`
445 property eDamageType
: Integer read mEDamageType write mEDamageType
;
446 property eDamage
: Integer write doDamage
;
457 WeaponPrior
: packed array [WP_FIRST
..WP_LAST
] of Byte;
458 CloseWeaponPrior
: packed array [WP_FIRST
..WP_LAST
] of Byte;
459 //SafeWeaponPrior: Array [WP_FIRST..WP_LAST] of Byte;
462 procedure save (st
: TStream
);
463 procedure load (st
: TStream
);
471 TBot
= class(TPlayer
)
473 FSelectedWeapon
: Byte;
476 FAIFlags
: Array of TAIFlag
;
477 FDifficult
: TDifficult
;
479 function GetRnd(a
: Byte): Boolean;
480 function GetInterval(a
: Byte; radius
: SmallInt): SmallInt;
481 function RunDirection(): TDirection
;
482 function FullInStep(XInc
, YInc
: Integer): Boolean;
483 //function NeedItem(Item: Byte): Byte;
484 procedure SelectWeapon(Dist
: Integer);
485 procedure SetAIFlag(aName
, fValue
: String20
);
486 function GetAIFlag(aName
: String20
): String20
;
487 procedure RemoveAIFlag(aName
: String20
);
488 function Healthy(): Byte;
489 procedure UpdateMove();
490 procedure UpdateCombat();
491 function KeyPressed(Key
: Word): Boolean;
492 procedure ReleaseKey(Key
: Byte);
493 function TargetOnScreen(TX
, TY
: Integer): Boolean;
494 procedure OnDamage(Angle
: SmallInt); override;
497 procedure Respawn(Silent
: Boolean; Force
: Boolean = False); override;
498 constructor Create(); override;
499 destructor Destroy(); override;
500 procedure Draw(); override;
501 function PickItem(ItemType
: Byte; force
: Boolean; var remove
: Boolean): Boolean; override;
502 function Heal(value
: Word; Soft
: Boolean): Boolean; override;
503 procedure Update(); override;
504 procedure SaveState (st
: TStream
); override;
505 procedure LoadState (st
: TStream
); override;
517 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
518 procedure moveBy (dx
, dy
: Integer); inline;
520 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
534 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
535 procedure moveBy (dx
, dy
: Integer); inline;
537 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
540 TCorpse
= class{$IFDEF USE_MEMPOOL}(TPoolObject
){$ENDIF}
549 FAnimation
: TAnimation
;
550 FAnimationMask
: TAnimation
;
553 constructor Create(X
, Y
: Integer; ModelName
: String; aMess
: Boolean);
554 destructor Destroy(); override;
555 procedure Damage(Value
: Word; SpawnerUID
: Word; vx
, vy
: Integer);
558 procedure SaveState (st
: TStream
);
559 procedure LoadState (st
: TStream
);
561 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
562 procedure moveBy (dx
, dy
: Integer); inline;
564 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
566 function ObjPtr (): PObj
; inline;
568 property Obj
: TObj read FObj
; // copies object
569 property State
: Byte read FState
;
570 property Mess
: Boolean read FMess
;
573 TTeamStat
= Array [TEAM_RED
..TEAM_BLUE
] of
579 gPlayers
: Array of TPlayer
;
580 gCorpses
: Array of TCorpse
;
581 gGibs
: Array of TGib
;
582 gShells
: Array of TShell
;
583 gTeamStat
: TTeamStat
;
584 gFly
: Boolean = False;
585 gAimLine
: Boolean = False;
586 gChatBubble
: Integer = 0;
587 gPlayerIndicator
: Integer = 1;
588 gPlayerIndicatorStyle
: Integer = 0;
590 gSpectLatchPID1
: Word = 0;
591 gSpectLatchPID2
: Word = 0;
592 MAX_RUNVEL
: Integer = 8;
593 VEL_JUMP
: Integer = 10;
594 SHELL_TIMEOUT
: Cardinal = 60000;
596 function Lerp(X
, Y
, Factor
: Integer): Integer;
598 procedure g_Gibs_SetMax(Count
: Word);
599 function g_Gibs_GetMax(): Word;
600 procedure g_Corpses_SetMax(Count
: Word);
601 function g_Corpses_GetMax(): Word;
602 procedure g_Shells_SetMax(Count
: Word);
603 function g_Shells_GetMax(): Word;
605 procedure g_Player_Init();
606 procedure g_Player_Free();
607 function g_Player_Create(ModelName
: String; Color
: TRGB
; Team
: Byte; Bot
: Boolean): Word;
608 function g_Player_CreateFromState (st
: TStream
): Word;
609 procedure g_Player_Remove(UID
: Word);
610 procedure g_Player_ResetTeams();
611 procedure g_Player_PreUpdate();
612 procedure g_Player_UpdateAll();
613 procedure g_Player_DrawAll();
614 procedure g_Player_DrawDebug(p
: TPlayer
);
615 procedure g_Player_DrawHealth();
616 procedure g_Player_RememberAll();
617 procedure g_Player_ResetAll(Force
, Silent
: Boolean);
618 function g_Player_Get(UID
: Word): TPlayer
;
619 function g_Player_GetCount(): Byte;
620 function g_Player_GetStats(): TPlayerStatArray
;
621 function g_Player_ValidName(Name
: String): Boolean;
622 function g_Player_CreateCorpse(Player
: TPlayer
): Integer;
623 procedure g_Player_CreateGibs(fX
, fY
: Integer; ModelName
: String; fColor
: TRGB
);
624 procedure g_Player_CreateShell(fX
, fY
, dX
, dY
: Integer; T
: Byte);
625 procedure g_Player_UpdatePhysicalObjects();
626 procedure g_Player_DrawCorpses();
627 procedure g_Player_DrawShells();
628 procedure g_Player_RemoveAllCorpses();
629 procedure g_Player_Corpses_SaveState (st
: TStream
);
630 procedure g_Player_Corpses_LoadState (st
: TStream
);
631 procedure g_Player_ResetReady();
632 procedure g_Bot_Add(Team
, Difficult
: Byte; Handicap
: Integer = 100);
633 procedure g_Bot_AddList(Team
: Byte; lname
: ShortString; num
: Integer = -1; Handicap
: Integer = 100);
634 procedure g_Bot_MixNames();
635 procedure g_Bot_RemoveAll();
640 {$INCLUDE ../nogl/noGLuses.inc}
641 {$IFDEF ENABLE_HOLMES}
644 e_log
, g_map
, g_items
, g_console
, g_gfx
, Math
,
645 g_options
, g_triggers
, g_menu
, g_game
, g_grid
, e_res
,
646 wadreader
, g_main
, g_monsters
, CONFIG
, g_language
,
647 g_net
, g_netmsg
, g_window
,
650 const PLR_SAVE_VERSION
= 0;
660 diag_precision
: Byte;
664 w_prior1
: Array [WP_FIRST
..WP_LAST
] of Byte;
665 w_prior2
: Array [WP_FIRST
..WP_LAST
] of Byte;
666 w_prior3
: Array [WP_FIRST
..WP_LAST
] of Byte;
670 TIME_RESPAWN1
= 1500;
671 TIME_RESPAWN2
= 2000;
672 TIME_RESPAWN3
= 3000;
675 JET_MAX
= 540; // ~30 sec
676 PLAYER_SUIT_TIME
= 30000;
677 PLAYER_INVUL_TIME
= 30000;
678 PLAYER_INVIS_TIME
= 35000;
679 FRAG_COMBO_TIME
= 3000;
683 ANGLE_RIGHTDOWN
= -35;
685 ANGLE_LEFTDOWN
= -145;
686 PLAYER_HEADRECT
: TRectWH
= (X
:24; Y
:12; Width
:20; Height
:12);
687 WEAPONPOINT
: Array [TDirection
] of TDFPoint
= ((X
:16; Y
:32), (X
:47; Y
:32));
690 BOT_UNSAFEDIST
= 128;
691 TEAMCOLOR
: Array [TEAM_RED
..TEAM_BLUE
] of TRGB
= ((R
:255; G
:0; B
:0),
693 DIFFICULT_EASY
: TDifficult
= (DiagFire
: 32; InvisFire
: 32; DiagPrecision
: 32;
694 FlyPrecision
: 32; Cover
: 32; CloseJump
: 32;
695 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
696 DIFFICULT_MEDIUM
: TDifficult
= (DiagFire
: 127; InvisFire
: 127; DiagPrecision
: 127;
697 FlyPrecision
: 127; Cover
: 127; CloseJump
: 127;
698 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
699 DIFFICULT_HARD
: TDifficult
= (DiagFire
: 255; InvisFire
: 255; DiagPrecision
: 255;
700 FlyPrecision
: 255; Cover
: 255; CloseJump
: 255;
701 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
702 WEAPON_PRIOR1
: Array [WP_FIRST
..WP_LAST
] of Byte =
703 (WEAPON_FLAMETHROWER
, WEAPON_SUPERPULEMET
,
704 WEAPON_SHOTGUN2
, WEAPON_SHOTGUN1
,
705 WEAPON_CHAINGUN
, WEAPON_PLASMA
, WEAPON_ROCKETLAUNCHER
,
706 WEAPON_BFG
, WEAPON_PISTOL
, WEAPON_SAW
, WEAPON_KASTET
);
707 WEAPON_PRIOR2
: Array [WP_FIRST
..WP_LAST
] of Byte =
708 (WEAPON_FLAMETHROWER
, WEAPON_SUPERPULEMET
,
709 WEAPON_BFG
, WEAPON_ROCKETLAUNCHER
,
710 WEAPON_SHOTGUN2
, WEAPON_PLASMA
, WEAPON_SHOTGUN1
,
711 WEAPON_CHAINGUN
, WEAPON_PISTOL
, WEAPON_SAW
, WEAPON_KASTET
);
712 //WEAPON_PRIOR3: Array [WP_FIRST..WP_LAST] of Byte =
713 // (WEAPON_FLAMETHROWER, WEAPON_SUPERPULEMET,
714 // WEAPON_BFG, WEAPON_PLASMA, WEAPON_SHOTGUN2,
715 // WEAPON_CHAINGUN, WEAPON_SHOTGUN1, WEAPON_SAW,
716 // WEAPON_ROCKETLAUNCHER, WEAPON_PISTOL, WEAPON_KASTET);
717 WEAPON_RELOAD
: Array [WP_FIRST
..WP_LAST
] of Byte =
718 (5, 2, 6, 18, 36, 2, 12, 2, 14, 2, 2);
720 PLAYER_SIGNATURE
= $52594C50; // 'PLYR'
721 CORPSE_SIGNATURE
= $50524F43; // 'CORP'
723 BOTNAMES_FILENAME
= 'botnames.txt';
724 BOTLIST_FILENAME
= 'botlist.txt';
728 MaxCorpses
: Word = 20;
729 MaxShells
: Word = 300;
730 CurrentGib
: Integer = 0;
731 CurrentShell
: Integer = 0;
732 BotNames
: Array of String;
733 BotList
: Array of TBotProfile
;
734 SavedStates
: Array of TPlayerSavedState
;
737 function Lerp(X
, Y
, Factor
: Integer): Integer;
739 Result
:= X
+ ((Y
- X
) div Factor
);
742 function SameTeam(UID1
, UID2
: Word): Boolean;
746 if (UID1
> UID_MAX_PLAYER
) or (UID1
<= UID_MAX_GAME
) or
747 (UID2
> UID_MAX_PLAYER
) or (UID2
<= UID_MAX_GAME
) then Exit
;
749 if (g_Player_Get(UID1
) = nil) or (g_Player_Get(UID2
) = nil) then Exit
;
751 if ((g_Player_Get(UID1
).Team
= TEAM_NONE
) or
752 (g_Player_Get(UID2
).Team
= TEAM_NONE
)) then Exit
;
754 Result
:= g_Player_Get(UID1
).FTeam
= g_Player_Get(UID2
).FTeam
;
757 procedure g_Gibs_SetMax(Count
: Word);
760 SetLength(gGibs
, Count
);
762 if CurrentGib
>= Count
then
766 function g_Gibs_GetMax(): Word;
771 procedure g_Shells_SetMax(Count
: Word);
774 SetLength(gShells
, Count
);
776 if CurrentShell
>= Count
then
780 function g_Shells_GetMax(): Word;
786 procedure g_Corpses_SetMax(Count
: Word);
789 SetLength(gCorpses
, Count
);
792 function g_Corpses_GetMax(): Word;
794 Result
:= MaxCorpses
;
797 function g_Player_Create(ModelName
: String; Color
: TRGB
; Team
: Byte; Bot
: Boolean): Word;
807 // Åñòü ëè ìåñòî â gPlayers:
808 if gPlayers
<> nil then
809 for a
:= 0 to High(gPlayers
) do
810 if gPlayers
[a
] = nil then
816 // Íåò ìåñòà - ðàñøèðÿåì gPlayers:
819 SetLength(gPlayers
, Length(gPlayers
)+1);
823 // Ñîçäàåì îáúåêò èãðîêà:
825 gPlayers
[a
] := TBot
.Create()
827 gPlayers
[a
] := TPlayer
.Create();
830 gPlayers
[a
].FActualModelName
:= ModelName
;
831 gPlayers
[a
].SetModel(ModelName
);
833 // Íåò ìîäåëè - ñîçäàíèå íå âîçìîæíî:
834 if gPlayers
[a
].FModel
= nil then
838 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], [ModelName
]));
842 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
843 if Random(2) = 0 then
847 gPlayers
[a
].FPreferredTeam
:= Team
;
849 case gGameSettings
.GameMode
of
850 GM_DM
: gPlayers
[a
].FTeam
:= TEAM_NONE
;
852 GM_CTF
: gPlayers
[a
].FTeam
:= gPlayers
[a
].FPreferredTeam
;
854 GM_COOP
: gPlayers
[a
].FTeam
:= TEAM_COOP
;
857 // Åñëè êîìàíäíàÿ èãðà - êðàñèì ìîäåëü â öâåò êîìàíäû:
858 gPlayers
[a
].FColor
:= Color
;
859 if gPlayers
[a
].FTeam
in [TEAM_RED
, TEAM_BLUE
] then
860 gPlayers
[a
].FModel
.Color
:= TEAMCOLOR
[gPlayers
[a
].FTeam
]
862 gPlayers
[a
].FModel
.Color
:= Color
;
864 gPlayers
[a
].FUID
:= g_CreateUID(UID_PLAYER
);
865 gPlayers
[a
].FAlive
:= False;
867 Result
:= gPlayers
[a
].FUID
;
870 function g_Player_CreateFromState (st
: TStream
): Word;
871 var a
: Integer; ok
, Bot
: Boolean; pos
: Int64;
875 // check signature and entity type
877 if not utils
.checkSign(st
, 'PLYR') then raise XStreamError
.Create('invalid player signature');
878 if (utils
.readByte(st
) <> PLR_SAVE_VERSION
) then raise XStreamError
.Create('invalid player version');
879 Bot
:= utils
.readBool(st
);
882 // find free player slot
884 for a
:= 0 to High(gPlayers
) do
885 if gPlayers
[a
] = nil then
891 // allocate player slot
894 SetLength(gPlayers
, Length(gPlayers
)+1);
898 // create entity and load state
900 gPlayers
[a
] := TBot
.Create()
902 gPlayers
[a
] := TPlayer
.Create();
903 gPlayers
[a
].FPhysics
:= True; // ???
904 gPlayers
[a
].LoadState(st
);
906 result
:= gPlayers
[a
].FUID
;
910 procedure g_Player_ResetTeams();
914 if g_Game_IsClient
then
916 if gPlayers
= nil then
918 for a
:= Low(gPlayers
) to High(gPlayers
) do
919 if gPlayers
[a
] <> nil then
920 case gGameSettings
.GameMode
of
922 gPlayers
[a
].ChangeTeam(TEAM_NONE
);
924 if not (gPlayers
[a
].Team
in [TEAM_RED
, TEAM_BLUE
]) then
925 if gPlayers
[a
].FPreferredTeam
in [TEAM_RED
, TEAM_BLUE
] then
926 gPlayers
[a
].ChangeTeam(gPlayers
[a
].FPreferredTeam
)
929 gPlayers
[a
].ChangeTeam(TEAM_RED
)
931 gPlayers
[a
].ChangeTeam(TEAM_BLUE
);
934 gPlayers
[a
].ChangeTeam(TEAM_COOP
);
938 procedure g_Bot_Add(Team
, Difficult
: Byte; Handicap
: Integer = 100);
941 _name
, _model
: String;
944 if not g_Game_IsServer
then Exit
;
946 // Ñïèñîê íàçâàíèé ìîäåëåé:
947 m
:= g_PlayerModel_GetNames();
952 if (gGameSettings
.GameType
= GT_SINGLE
) or (gGameSettings
.GameMode
= GM_COOP
) then
953 Team
:= TEAM_COOP
// COOP
955 if gGameSettings
.GameMode
= GM_DM
then
956 Team
:= TEAM_NONE
// DM
958 if Team
= TEAM_NONE
then // CTF / TDM
960 // Àâòîáàëàíñ êîìàíä:
964 for a
:= 0 to High(gPlayers
) do
965 if gPlayers
[a
] <> nil then
967 if gPlayers
[a
].Team
= TEAM_RED
then
970 if gPlayers
[a
].Team
= TEAM_BLUE
then
980 if Random(2) = 0 then
986 // Âûáèðàåì áîòó èìÿ:
988 if BotNames
<> nil then
989 for a
:= 0 to High(BotNames
) do
990 if g_Player_ValidName(BotNames
[a
]) then
992 _name
:= BotNames
[a
];
996 // Âûáèðàåì ñëó÷àéíóþ ìîäåëü:
997 _model
:= m
[Random(Length(m
))];
1000 with g_Player_Get(g_Player_Create(_model
,
1001 _RGB(Min(Random(9)*32, 255),
1002 Min(Random(9)*32, 255),
1003 Min(Random(9)*32, 255)),
1004 Team
, True)) as TBot
do
1006 // Åñëè èìåíè íåò, äåëàåì åãî èç UID áîòà
1008 Name
:= Format('DFBOT%.5d', [UID
])
1013 1: FDifficult
:= DIFFICULT_EASY
;
1014 2: FDifficult
:= DIFFICULT_MEDIUM
;
1015 else FDifficult
:= DIFFICULT_HARD
;
1018 for a
:= WP_FIRST
to WP_LAST
do
1020 FDifficult
.WeaponPrior
[a
] := WEAPON_PRIOR1
[a
];
1021 FDifficult
.CloseWeaponPrior
[a
] := WEAPON_PRIOR2
[a
];
1022 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
1025 FHandicap
:= Handicap
;
1027 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [Name
]), True);
1029 if g_Game_IsNet
then MH_SEND_PlayerCreate(UID
);
1030 if g_Game_IsServer
and (gGameSettings
.MaxLives
> 0) then
1035 procedure g_Bot_AddList(Team
: Byte; lName
: ShortString; num
: Integer = -1; Handicap
: Integer = 100);
1038 _name
, _model
: String;
1041 if not g_Game_IsServer
then Exit
;
1043 // Ñïèñîê íàçâàíèé ìîäåëåé:
1044 m
:= g_PlayerModel_GetNames();
1049 if (gGameSettings
.GameType
= GT_SINGLE
) or (gGameSettings
.GameMode
= GM_COOP
) then
1050 Team
:= TEAM_COOP
// COOP
1052 if gGameSettings
.GameMode
= GM_DM
then
1053 Team
:= TEAM_NONE
// DM
1055 if Team
= TEAM_NONE
then
1056 Team
:= BotList
[num
].team
; // CTF / TDM
1058 // Âûáèðàåì íàñòðîéêè áîòà èç ñïèñêà ïî íîìåðó èëè èìåíè:
1059 lName
:= AnsiLowerCase(lName
);
1060 if (num
< 0) or (num
> Length(BotList
)-1) then
1062 if (num
= -1) and (lName
<> '') and (BotList
<> nil) then
1063 for a
:= 0 to High(BotList
) do
1064 if AnsiLowerCase(BotList
[a
].name
) = lName
then
1073 _name
:= BotList
[num
].name
;
1074 // Çàíÿòî - âûáèðàåì ñëó÷àéíîå:
1075 if not g_Player_ValidName(_name
) then
1077 _name
:= Format('DFBOT%.2d', [Random(100)]);
1078 until g_Player_ValidName(_name
);
1081 _model
:= BotList
[num
].model
;
1082 // Íåò òàêîé - âûáèðàåì ñëó÷àéíóþ:
1083 if not InSArray(_model
, m
) then
1084 _model
:= m
[Random(Length(m
))];
1087 with g_Player_Get(g_Player_Create(_model
, BotList
[num
].color
, Team
, True)) as TBot
do
1091 FDifficult
.DiagFire
:= BotList
[num
].diag_fire
;
1092 FDifficult
.InvisFire
:= BotList
[num
].invis_fire
;
1093 FDifficult
.DiagPrecision
:= BotList
[num
].diag_precision
;
1094 FDifficult
.FlyPrecision
:= BotList
[num
].fly_precision
;
1095 FDifficult
.Cover
:= BotList
[num
].cover
;
1096 FDifficult
.CloseJump
:= BotList
[num
].close_jump
;
1098 FHandicap
:= Handicap
;
1100 for a
:= WP_FIRST
to WP_LAST
do
1102 FDifficult
.WeaponPrior
[a
] := BotList
[num
].w_prior1
[a
];
1103 FDifficult
.CloseWeaponPrior
[a
] := BotList
[num
].w_prior2
[a
];
1104 //FDifficult.SafeWeaponPrior[a] := BotList[num].w_prior3[a];
1107 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [Name
]), True);
1109 if g_Game_IsNet
then MH_SEND_PlayerCreate(UID
);
1113 procedure g_Bot_RemoveAll();
1117 if not g_Game_IsServer
then Exit
;
1118 if gPlayers
= nil then Exit
;
1120 for a
:= 0 to High(gPlayers
) do
1121 if gPlayers
[a
] <> nil then
1122 if gPlayers
[a
] is TBot
then
1124 gPlayers
[a
].Lives
:= 0;
1125 gPlayers
[a
].Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
1126 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [gPlayers
[a
].Name
]), True);
1127 g_Player_Remove(gPlayers
[a
].FUID
);
1133 procedure g_Bot_MixNames();
1138 if BotNames
<> nil then
1139 for a
:= 0 to High(BotNames
) do
1141 b
:= Random(Length(BotNames
));
1143 Botnames
[a
] := BotNames
[b
];
1148 procedure g_Player_Remove(UID
: Word);
1152 if gPlayers
= nil then Exit
;
1154 if g_Game_IsServer
and g_Game_IsNet
then
1155 MH_SEND_PlayerDelete(UID
);
1157 for i
:= 0 to High(gPlayers
) do
1158 if gPlayers
[i
] <> nil then
1159 if gPlayers
[i
].FUID
= UID
then
1161 if gPlayers
[i
] is TPlayer
then
1162 TPlayer(gPlayers
[i
]).Free()
1164 TBot(gPlayers
[i
]).Free();
1170 procedure g_Player_Init();
1181 path
:= BOTNAMES_FILENAME
;
1182 if e_FindResource(DataDirs
, path
) = false then
1185 // ×èòàåì âîçìîæíûå èìåíà áîòîâ èç ôàéëà:
1186 AssignFile(F
, path
);
1197 SetLength(BotNames
, Length(BotNames
)+1);
1198 BotNames
[High(BotNames
)] := s
;
1206 // ×èòàåì ôàéë ñ ïàðàìåòðàìè áîòîâ:
1207 config
:= TConfig
.CreateFile(path
);
1211 while config
.SectionExists(IntToStr(a
)) do
1213 SetLength(BotList
, Length(BotList
)+1);
1215 with BotList
[High(BotList
)] do
1218 name
:= config
.ReadStr(IntToStr(a
), 'name', '');
1220 model
:= config
.ReadStr(IntToStr(a
), 'model', '');
1222 if config
.ReadStr(IntToStr(a
), 'team', 'red') = 'red' then
1227 sa
:= parse(config
.ReadStr(IntToStr(a
), 'color', ''));
1228 color
.R
:= StrToIntDef(sa
[0], 0);
1229 color
.G
:= StrToIntDef(sa
[1], 0);
1230 color
.B
:= StrToIntDef(sa
[2], 0);
1231 // Âåðîÿòíîñòü ñòðåëüáû ïîä óãëîì:
1232 diag_fire
:= config
.ReadInt(IntToStr(a
), 'diag_fire', 0);
1233 // Âåðîÿòíîñòü îòâåòíîãî îãíÿ ïî íåâèäèìîìó ñîïåðíèêó:
1234 invis_fire
:= config
.ReadInt(IntToStr(a
), 'invis_fire', 0);
1235 // Òî÷íîñòü ñòðåëüáû ïîä óãëîì:
1236 diag_precision
:= config
.ReadInt(IntToStr(a
), 'diag_precision', 0);
1237 // Òî÷íîñòü ñòðåëüáû â ïîëåòå:
1238 fly_precision
:= config
.ReadInt(IntToStr(a
), 'fly_precision', 0);
1239 // Òî÷íîñòü óêëîíåíèÿ îò ñíàðÿäîâ:
1240 cover
:= config
.ReadInt(IntToStr(a
), 'cover', 0);
1241 // Âåðîÿòíîñòü ïðûæêà ïðè ïðèáëèæåíèè ñîïåðíèêà:
1242 close_jump
:= config
.ReadInt(IntToStr(a
), 'close_jump', 0);
1243 // Ïðèîðèòåòû îðóæèÿ äëÿ äàëüíåãî áîÿ:
1244 sa
:= parse(config
.ReadStr(IntToStr(a
), 'w_prior1', ''));
1245 if Length(sa
) = 10 then
1247 w_prior1
[b
] := EnsureRange(StrToInt(sa
[b
]), 0, 9);
1248 // Ïðèîðèòåòû îðóæèÿ äëÿ áëèæíåãî áîÿ:
1249 sa
:= parse(config
.ReadStr(IntToStr(a
), 'w_prior2', ''));
1250 if Length(sa
) = 10 then
1252 w_prior2
[b
] := EnsureRange(StrToInt(sa
[b
]), 0, 9);
1254 {sa := parse(config.ReadStr(IntToStr(a), 'w_prior3', ''));
1255 if Length(sa) = 10 then
1257 w_prior3[b] := EnsureRange(StrToInt(sa[b]), 0, 9);}
1264 SetLength(SavedStates
, 0);
1267 procedure g_Player_Free();
1271 if gPlayers
<> nil then
1273 for i
:= 0 to High(gPlayers
) do
1274 if gPlayers
[i
] <> nil then
1276 if gPlayers
[i
] is TPlayer
then
1277 TPlayer(gPlayers
[i
]).Free()
1279 TBot(gPlayers
[i
]).Free();
1288 SetLength(SavedStates
, 0);
1291 procedure g_Player_PreUpdate();
1295 if gPlayers
= nil then Exit
;
1296 for i
:= 0 to High(gPlayers
) do
1297 if gPlayers
[i
] <> nil then
1298 gPlayers
[i
].PreUpdate();
1301 procedure g_Player_UpdateAll();
1305 if gPlayers
= nil then Exit
;
1307 //e_WriteLog('***g_Player_UpdateAll: ENTER', MSG_WARNING);
1308 for i
:= 0 to High(gPlayers
) do
1310 if gPlayers
[i
] <> nil then
1312 if gPlayers
[i
] is TPlayer
then
1314 gPlayers
[i
].Update();
1315 gPlayers
[i
].RealizeCurrentWeapon(); // WARNING! DO NOT MOVE THIS INTO `Update()`!
1319 // bot updates weapons in `UpdateCombat()`
1320 TBot(gPlayers
[i
]).Update();
1324 //e_WriteLog('***g_Player_UpdateAll: EXIT', MSG_WARNING);
1327 procedure g_Player_DrawAll();
1331 if gPlayers
= nil then Exit
;
1333 for i
:= 0 to High(gPlayers
) do
1334 if gPlayers
[i
] <> nil then
1335 if gPlayers
[i
] is TPlayer
then gPlayers
[i
].Draw()
1336 else TBot(gPlayers
[i
]).Draw();
1339 procedure g_Player_DrawDebug(p
: TPlayer
);
1343 if p
= nil then Exit
;
1344 if (@p
.FObj
) = nil then Exit
;
1346 e_TextureFontGetSize(gStdFont
, fW
, fH
);
1348 e_TextureFontPrint(0, 0 , 'Pos X: ' + IntToStr(p
.FObj
.X
), gStdFont
);
1349 e_TextureFontPrint(0, fH
, 'Pos Y: ' + IntToStr(p
.FObj
.Y
), gStdFont
);
1350 e_TextureFontPrint(0, fH
* 2, 'Vel X: ' + IntToStr(p
.FObj
.Vel
.X
), gStdFont
);
1351 e_TextureFontPrint(0, fH
* 3, 'Vel Y: ' + IntToStr(p
.FObj
.Vel
.Y
), gStdFont
);
1352 e_TextureFontPrint(0, fH
* 4, 'Acc X: ' + IntToStr(p
.FObj
.Accel
.X
), gStdFont
);
1353 e_TextureFontPrint(0, fH
* 5, 'Acc Y: ' + IntToStr(p
.FObj
.Accel
.Y
), gStdFont
);
1354 e_TextureFontPrint(0, fH
* 6, 'Old X: ' + IntToStr(p
.FObj
.oldX
), gStdFont
);
1355 e_TextureFontPrint(0, fH
* 7, 'Old Y: ' + IntToStr(p
.FObj
.oldY
), gStdFont
);
1358 procedure g_Player_DrawHealth();
1363 if gPlayers
= nil then Exit
;
1364 e_TextureFontGetSize(gStdFont
, fW
, fH
);
1366 for i
:= 0 to High(gPlayers
) do
1367 if gPlayers
[i
] <> nil then
1369 e_TextureFontPrint(gPlayers
[i
].FObj
.X
+ gPlayers
[i
].FObj
.Rect
.X
,
1370 gPlayers
[i
].FObj
.Y
+ gPlayers
[i
].FObj
.Rect
.Y
+ gPlayers
[i
].FObj
.Rect
.Height
- fH
* 2,
1371 IntToStr(gPlayers
[i
].FHealth
), gStdFont
);
1372 e_TextureFontPrint(gPlayers
[i
].FObj
.X
+ gPlayers
[i
].FObj
.Rect
.X
,
1373 gPlayers
[i
].FObj
.Y
+ gPlayers
[i
].FObj
.Rect
.Y
+ gPlayers
[i
].FObj
.Rect
.Height
- fH
,
1374 IntToStr(gPlayers
[i
].FArmor
), gStdFont
);
1378 function g_Player_Get(UID
: Word): TPlayer
;
1384 if gPlayers
= nil then
1387 for a
:= 0 to High(gPlayers
) do
1388 if gPlayers
[a
] <> nil then
1389 if gPlayers
[a
].FUID
= UID
then
1391 Result
:= gPlayers
[a
];
1396 function g_Player_GetCount(): Byte;
1402 if gPlayers
= nil then
1405 for a
:= 0 to High(gPlayers
) do
1406 if gPlayers
[a
] <> nil then
1407 Result
:= Result
+ 1;
1410 function g_Player_GetStats(): TPlayerStatArray
;
1416 if gPlayers
= nil then Exit
;
1418 for a
:= 0 to High(gPlayers
) do
1419 if gPlayers
[a
] <> nil then
1421 SetLength(Result
, Length(Result
)+1);
1422 with Result
[High(Result
)] do
1425 Ping
:= gPlayers
[a
].FPing
;
1426 Loss
:= gPlayers
[a
].FLoss
;
1427 Name
:= gPlayers
[a
].FName
;
1428 Team
:= gPlayers
[a
].FTeam
;
1429 Frags
:= gPlayers
[a
].FFrags
;
1430 Deaths
:= gPlayers
[a
].FDeath
;
1431 Kills
:= gPlayers
[a
].FKills
;
1432 Color
:= gPlayers
[a
].FModel
.Color
;
1433 Lives
:= gPlayers
[a
].FLives
;
1434 Spectator
:= gPlayers
[a
].FSpectator
;
1435 UID
:= gPlayers
[a
].FUID
;
1440 procedure g_Player_ResetReady();
1444 if not g_Game_IsServer
then Exit
;
1445 if gPlayers
= nil then Exit
;
1447 for a
:= 0 to High(gPlayers
) do
1448 if gPlayers
[a
] <> nil then
1450 gPlayers
[a
].FReady
:= False;
1451 if g_Game_IsNet
then
1452 MH_SEND_GameEvent(NET_EV_INTER_READY
, gPlayers
[a
].UID
, 'N');
1456 procedure g_Player_RememberAll
;
1460 for i
:= Low(gPlayers
) to High(gPlayers
) do
1461 if (gPlayers
[i
] <> nil) and gPlayers
[i
].alive
then
1462 gPlayers
[i
].RememberState
;
1465 procedure g_Player_ResetAll(Force
, Silent
: Boolean);
1469 gTeamStat
[TEAM_RED
].Goals
:= 0;
1470 gTeamStat
[TEAM_BLUE
].Goals
:= 0;
1472 if gPlayers
<> nil then
1473 for i
:= 0 to High(gPlayers
) do
1474 if gPlayers
[i
] <> nil then
1476 gPlayers
[i
].Reset(Force
);
1478 if gPlayers
[i
] is TPlayer
then
1480 if (not gPlayers
[i
].FSpectator
) or gPlayers
[i
].FWantsInGame
then
1481 gPlayers
[i
].Respawn(Silent
)
1483 gPlayers
[i
].Spectate();
1486 TBot(gPlayers
[i
]).Respawn(Silent
);
1490 function g_Player_CreateCorpse(Player
: TPlayer
): Integer;
1498 if Player
.alive
then
1501 // Ðàçðûâàåì ñâÿçü ñ ïðåæíèì òðóïîì:
1502 i
:= Player
.FCorpse
;
1503 if (i
>= 0) and (i
< Length(gCorpses
)) then
1505 if (gCorpses
[i
] <> nil) and (gCorpses
[i
].FPlayerUID
= Player
.FUID
) then
1506 gCorpses
[i
].FPlayerUID
:= 0;
1509 if Player
.FObj
.Y
>= gMapInfo
.Height
+128 then
1514 if (FHealth
>= -50) or (gGibsCount
= 0) then
1516 if (gCorpses
= nil) or (Length(gCorpses
) = 0) then
1520 for find_id
:= 0 to High(gCorpses
) do
1521 if gCorpses
[find_id
] = nil then
1528 find_id
:= Random(Length(gCorpses
));
1530 gCorpses
[find_id
] := TCorpse
.Create(FObj
.X
, FObj
.Y
, FModel
.Name
, FHealth
< -20);
1531 gCorpses
[find_id
].FColor
:= FModel
.Color
;
1532 gCorpses
[find_id
].FObj
.Vel
:= FObj
.Vel
;
1533 gCorpses
[find_id
].FObj
.Accel
:= FObj
.Accel
;
1534 gCorpses
[find_id
].FPlayerUID
:= FUID
;
1539 g_Player_CreateGibs(FObj
.X
+ PLAYER_RECT_CX
,
1540 FObj
.Y
+ PLAYER_RECT_CY
,
1541 FModel
.Name
, FModel
.Color
);
1545 procedure g_Player_CreateShell(fX
, fY
, dX
, dY
: Integer; T
: Byte);
1549 if (gShells
= nil) or (Length(gShells
) = 0) then
1552 with gShells
[CurrentShell
] do
1558 if T
= SHELL_BULLET
then
1560 if g_Texture_Get('TEXTURE_SHELL_BULLET', SID
) then
1564 Obj
.Rect
.Width
:= 4;
1565 Obj
.Rect
.Height
:= 2;
1569 if g_Texture_Get('TEXTURE_SHELL_SHELL', SID
) then
1573 Obj
.Rect
.Width
:= 7;
1574 Obj
.Rect
.Height
:= 3;
1580 g_Obj_Push(@Obj
, dX
+ Random(4)-Random(4), dY
-Random(4));
1581 positionChanged(); // this updates spatial accelerators
1582 RAngle
:= Random(360);
1583 Timeout
:= gTime
+ SHELL_TIMEOUT
;
1585 if CurrentShell
>= High(gShells
) then
1592 procedure g_Player_CreateGibs(fX
, fY
: Integer; ModelName
: string; fColor
: TRGB
);
1595 GibsArray
: TGibsArray
;
1598 if (gGibs
= nil) or (Length(gGibs
) = 0) then
1600 if not g_PlayerModel_GetGibs(ModelName
, GibsArray
) then
1602 Blood
:= g_PlayerModel_GetBlood(ModelName
);
1604 for a
:= 0 to High(GibsArray
) do
1605 with gGibs
[CurrentGib
] do
1608 ID
:= GibsArray
[a
].ID
;
1609 MaskID
:= GibsArray
[a
].MaskID
;
1612 Obj
.Rect
:= GibsArray
[a
].Rect
;
1613 Obj
.X
:= fX
-GibsArray
[a
].Rect
.X
-(GibsArray
[a
].Rect
.Width
div 2);
1614 Obj
.Y
:= fY
-GibsArray
[a
].Rect
.Y
-(GibsArray
[a
].Rect
.Height
div 2);
1615 g_Obj_PushA(@Obj
, 25 + Random(10), Random(361));
1616 positionChanged(); // this updates spatial accelerators
1617 RAngle
:= Random(360);
1619 if gBloodCount
> 0 then
1620 g_GFX_Blood(fX
, fY
, 16*gBloodCount
+Random(5*gBloodCount
), -16+Random(33), -16+Random(33),
1621 Random(48), Random(48), Blood
.R
, Blood
.G
, Blood
.B
, Blood
.Kind
);
1623 if CurrentGib
>= High(gGibs
) then
1630 procedure g_Player_UpdatePhysicalObjects();
1636 procedure ShellSound_Bounce(X
, Y
: Integer; T
: Byte);
1641 if T
= SHELL_BULLET
then
1642 g_Sound_PlayExAt('SOUND_PLAYER_CASING' + IntToStr(k
), X
, Y
)
1644 g_Sound_PlayExAt('SOUND_PLAYER_SHELL' + IntToStr(k
), X
, Y
);
1649 if gGibs
<> nil then
1650 for i
:= 0 to High(gGibs
) do
1651 if gGibs
[i
].alive
then
1658 mr
:= g_Obj_Move(@Obj
, True, False, True);
1659 positionChanged(); // this updates spatial accelerators
1661 if WordBool(mr
and MOVE_FALLOUT
) then
1667 // Îòëåòàåò îò óäàðà î ñòåíó/ïîòîëîê/ïîë:
1668 if WordBool(mr
and MOVE_HITWALL
) then
1669 Obj
.Vel
.X
:= -(vel
.X
div 2);
1670 if WordBool(mr
and (MOVE_HITCEIL
or MOVE_HITLAND
)) then
1671 Obj
.Vel
.Y
:= -(vel
.Y
div 2);
1673 if (Obj
.Vel
.X
>= 0) then
1675 RAngle
:= RAngle
+ Abs(Obj
.Vel
.X
)*6 + Abs(Obj
.Vel
.Y
);
1676 if RAngle
>= 360 then
1677 RAngle
:= RAngle
mod 360;
1678 end else begin // Counter-clockwise
1679 RAngle
:= RAngle
- Abs(Obj
.Vel
.X
)*6 - Abs(Obj
.Vel
.Y
);
1681 RAngle
:= (360 - (Abs(RAngle
) mod 360)) mod 360;
1684 // Ñîïðîòèâëåíèå âîçäóõà äëÿ êóñêà òðóïà:
1685 if gTime
mod (GAME_TICK
*3) = 0 then
1686 Obj
.Vel
.X
:= z_dec(Obj
.Vel
.X
, 1);
1690 if gCorpses
<> nil then
1691 for i
:= 0 to High(gCorpses
) do
1692 if gCorpses
[i
] <> nil then
1693 if gCorpses
[i
].State
= CORPSE_STATE_REMOVEME
then
1699 gCorpses
[i
].Update();
1702 if gShells
<> nil then
1703 for i
:= 0 to High(gShells
) do
1704 if gShells
[i
].alive
then
1711 mr
:= g_Obj_Move(@Obj
, True, False, True);
1712 positionChanged(); // this updates spatial accelerators
1714 if WordBool(mr
and MOVE_FALLOUT
) or (gShells
[i
].Timeout
< gTime
) then
1720 // Îòëåòàåò îò óäàðà î ñòåíó/ïîòîëîê/ïîë:
1721 if WordBool(mr
and MOVE_HITWALL
) then
1723 Obj
.Vel
.X
:= -(vel
.X
div 2);
1724 if not WordBool(mr
and MOVE_INWATER
) then
1725 ShellSound_Bounce(Obj
.X
, Obj
.Y
, SType
);
1727 if WordBool(mr
and (MOVE_HITCEIL
or MOVE_HITLAND
)) then
1729 Obj
.Vel
.Y
:= -(vel
.Y
div 2);
1730 if Obj
.Vel
.X
<> 0 then Obj
.Vel
.X
:= Obj
.Vel
.X
div 2;
1731 if (Obj
.Vel
.X
= 0) and (Obj
.Vel
.Y
= 0) then
1733 if RAngle
mod 90 <> 0 then
1734 RAngle
:= (RAngle
div 90) * 90;
1736 else if not WordBool(mr
and MOVE_INWATER
) then
1737 ShellSound_Bounce(Obj
.X
, Obj
.Y
, SType
);
1740 if (Obj
.Vel
.X
>= 0) then
1742 RAngle
:= RAngle
+ Abs(Obj
.Vel
.X
)*8 + Abs(Obj
.Vel
.Y
);
1743 if RAngle
>= 360 then
1744 RAngle
:= RAngle
mod 360;
1745 end else begin // Counter-clockwise
1746 RAngle
:= RAngle
- Abs(Obj
.Vel
.X
)*8 - Abs(Obj
.Vel
.Y
);
1748 RAngle
:= (360 - (Abs(RAngle
) mod 360)) mod 360;
1754 procedure TGib
.getMapBox (out x
, y
, w
, h
: Integer); inline;
1756 x
:= Obj
.X
+Obj
.Rect
.X
;
1757 y
:= Obj
.Y
+Obj
.Rect
.Y
;
1758 w
:= Obj
.Rect
.Width
;
1759 h
:= Obj
.Rect
.Height
;
1762 procedure TGib
.moveBy (dx
, dy
: Integer); inline;
1764 if (dx
<> 0) or (dy
<> 0) then
1773 procedure TShell
.getMapBox (out x
, y
, w
, h
: Integer); inline;
1777 w
:= Obj
.Rect
.Width
;
1778 h
:= Obj
.Rect
.Height
;
1781 procedure TShell
.moveBy (dx
, dy
: Integer); inline;
1783 if (dx
<> 0) or (dy
<> 0) then
1792 procedure TGib
.positionChanged (); inline; begin end;
1793 procedure TShell
.positionChanged (); inline; begin end;
1796 procedure g_Player_DrawCorpses();
1801 if gGibs
<> nil then
1802 for i
:= 0 to High(gGibs
) do
1803 if gGibs
[i
].alive
then
1806 if not g_Obj_Collide(sX
, sY
, sWidth
, sHeight
, @Obj
) then
1809 Obj
.lerp(gLerpFactor
, fX
, fY
);
1811 a
.X
:= Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2);
1812 a
.y
:= Obj
.Rect
.Y
+(Obj
.Rect
.Height
div 2);
1814 e_DrawAdv(ID
, fX
, fY
, 0, True, False, RAngle
, @a
, TMirrorType
.None
);
1817 e_DrawAdv(MaskID
, fX
, fY
, 0, True, False, RAngle
, @a
, TMirrorType
.None
);
1823 if gCorpses
<> nil then
1824 for i
:= 0 to High(gCorpses
) do
1825 if gCorpses
[i
] <> nil then
1829 procedure g_Player_DrawShells();
1834 if gShells
<> nil then
1835 for i
:= 0 to High(gShells
) do
1836 if gShells
[i
].alive
then
1839 if not g_Obj_Collide(sX
, sY
, sWidth
, sHeight
, @Obj
) then
1842 Obj
.lerp(gLerpFactor
, fX
, fY
);
1847 e_DrawAdv(SpriteID
, fX
, fY
, 0, True, False, RAngle
, @a
, TMirrorType
.None
);
1851 procedure g_Player_RemoveAllCorpses();
1857 SetLength(gGibs
, MaxGibs
);
1858 SetLength(gShells
, MaxGibs
);
1862 if gCorpses
<> nil then
1863 for i
:= 0 to High(gCorpses
) do
1867 SetLength(gCorpses
, MaxCorpses
);
1870 procedure g_Player_Corpses_SaveState (st
: TStream
);
1874 // Ñ÷èòàåì êîëè÷åñòâî ñóùåñòâóþùèõ òðóïîâ
1876 for i
:= 0 to High(gCorpses
) do if (gCorpses
[i
] <> nil) then Inc(count
);
1878 // Êîëè÷åñòâî òðóïîâ
1879 utils
.writeInt(st
, LongInt(count
));
1881 if (count
= 0) then exit
;
1884 for i
:= 0 to High(gCorpses
) do
1886 if gCorpses
[i
] <> nil then
1889 utils
.writeStr(st
, gCorpses
[i
].FModelName
);
1891 utils
.writeBool(st
, gCorpses
[i
].Mess
);
1892 // Ñîõðàíÿåì äàííûå òðóïà:
1893 gCorpses
[i
].SaveState(st
);
1899 procedure g_Player_Corpses_LoadState (st
: TStream
);
1907 g_Player_RemoveAllCorpses();
1909 // Êîëè÷åñòâî òðóïîâ:
1910 count
:= utils
.readLongInt(st
);
1911 if (count
< 0) or (count
> Length(gCorpses
)) then raise XStreamError
.Create('invalid number of corpses');
1913 if (count
= 0) then exit
;
1916 for i
:= 0 to count
-1 do
1919 str
:= utils
.readStr(st
);
1921 b
:= utils
.readBool(st
);
1923 gCorpses
[i
] := TCorpse
.Create(0, 0, str
, b
);
1924 // Çàãðóæàåì äàííûå òðóïà
1925 gCorpses
[i
].LoadState(st
);
1932 function TPlayer
.isValidViewPort (): Boolean; inline; begin result
:= (viewPortW
> 0) and (viewPortH
> 0); end;
1934 procedure TPlayer
.BFGHit();
1936 g_Weapon_BFGHit(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
1937 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2));
1938 if g_Game_IsServer
and g_Game_IsNet
then
1939 MH_SEND_Effect(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
1940 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2),
1944 procedure TPlayer
.ChangeModel(ModelName
: string);
1946 locModel
: TPlayerModel
;
1948 locModel
:= g_PlayerModel_Get(ModelName
);
1949 if locModel
= nil then Exit
;
1955 procedure TPlayer
.SetModel(ModelName
: string);
1959 m
:= g_PlayerModel_Get(ModelName
);
1962 g_SimpleError(Format(_lc
[I_GAME_ERROR_MODEL_FALLBACK
], [ModelName
]));
1963 m
:= g_PlayerModel_Get('doomer');
1966 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], ['doomer']));
1971 if FModel
<> nil then
1976 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
1977 FModel
.Color
:= FColor
1979 FModel
.Color
:= TEAMCOLOR
[FTeam
];
1980 FModel
.SetWeapon(FCurrWeap
);
1981 FModel
.SetFlag(FFlag
);
1982 SetDirection(FDirection
);
1985 procedure TPlayer
.SetColor(Color
: TRGB
);
1988 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
1989 if FModel
<> nil then FModel
.Color
:= Color
;
1994 function TPlayer
.GetColor(): TRGB
;
1996 result
:= FModel
.Color
;
1999 procedure TPlayer
.SetWeaponPrefs(Prefs
: Array of Byte);
2002 for i
:= WP_FIRST
to WP_LAST
+ 1 do
2004 if (Prefs
[i
] < 0) or (Prefs
[i
] > WP_LAST
+ 1) then
2005 FWeapPreferences
[i
] := 0
2006 else FWeapPreferences
[i
] := Prefs
[i
];
2010 procedure TPlayer
.SetWeaponPref(Weapon
, Pref
: Byte);
2012 if (Weapon
< 0) or (Weapon
> WP_LAST
+ 1) then
2014 else if (Pref
>= 0) and (Pref
<= WP_LAST
+ 1) and (Weapon
>= 0) and (Weapon
<= WP_LAST
+ 1) then
2015 FWeapPreferences
[Weapon
] := Pref
2016 else if (Weapon
>= 0) and (Weapon
<= WP_LAST
+ 1) and ((Pref
< 0) or (Pref
> WP_LAST
+ 1)) then
2017 FWeapPreferences
[Weapon
] := 0;
2020 function TPlayer
.GetWeaponPref(Weapon
: Byte) : Byte;
2022 if (Weapon
< 0) or (Weapon
> WP_LAST
+ 1) then
2024 else if (FWeapPreferences
[Weapon
] < 0) or (FWeapPreferences
[Weapon
] > WP_LAST
+ 1) then
2027 result
:= FWeapPreferences
[Weapon
];
2030 function TPlayer
.GetMorePrefered() : Byte;
2031 var testedWeap
, i
: Byte;
2033 testedWeap
:= FCurrWeap
;
2034 for i
:= WP_FIRST
to WP_LAST
do
2035 if FWeapon
[i
] and (FWeapPreferences
[i
] > FWeapPreferences
[testedWeap
]) then
2037 if (R_BERSERK
in FRulez
) and (FWeapPreferences
[WP_LAST
+ 1] > FWeapPreferences
[testedWeap
]) then
2038 testedWeap
:= WEAPON_KASTET
;
2039 result
:= testedWeap
;
2042 function TPlayer
.maySwitch(Weapon
: Byte) : Boolean;
2045 if (Weapon
= WEAPON_KASTET
) and (FSkipFist
<> 0) then
2046 if (FSkipFist
= 1) and (not (R_BERSERK
in FRulez
)) then
2048 else if (FSwitchToEmpty
= 0) and not hasAmmoForWeapon(Weapon
) then
2052 procedure TPlayer
.SwitchTeam
;
2054 if g_Game_IsClient
then
2056 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then Exit
;
2058 if gGameOn
and FAlive
then
2059 Kill(K_SIMPLEKILL
, FUID
, HIT_SELF
);
2061 if FTeam
= TEAM_RED
then
2063 ChangeTeam(TEAM_BLUE
);
2064 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_BLUE
], [FName
]), True);
2065 if g_Game_IsNet
then
2066 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM
, TEAM_BLUE
, FName
);
2070 ChangeTeam(TEAM_RED
);
2071 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_RED
], [FName
]), True);
2072 if g_Game_IsNet
then
2073 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM
, TEAM_RED
, FName
);
2075 FPreferredTeam
:= FTeam
;
2078 procedure TPlayer
.ChangeTeam(Team
: Byte);
2085 TEAM_RED
, TEAM_BLUE
:
2086 FModel
.Color
:= TEAMCOLOR
[Team
];
2088 FModel
.Color
:= FColor
;
2090 if (FTeam
<> OldTeam
) and g_Game_IsNet
and g_Game_IsServer
then
2091 MH_SEND_PlayerStats(FUID
);
2095 procedure TPlayer.CollideItem();
2100 if gItems = nil then Exit;
2101 if not FAlive then Exit;
2103 for i := 0 to High(gItems) do
2106 if (ItemType <> ITEM_NONE) and alive then
2107 if g_Obj_Collide(FObj.X+PLAYER_RECT.X, FObj.Y+PLAYER_RECT.Y, PLAYER_RECT.Width,
2108 PLAYER_RECT.Height, @Obj) then
2110 if not PickItem(ItemType, gItems[i].Respawnable, r) then Continue;
2112 if ItemType in [ITEM_SPHERE_BLUE, ITEM_SPHERE_WHITE, ITEM_INVUL] then
2113 g_Sound_PlayExAt('SOUND_ITEM_GETRULEZ', FObj.X, FObj.Y)
2114 else if ItemType in [ITEM_MEDKIT_SMALL, ITEM_MEDKIT_LARGE, ITEM_MEDKIT_BLACK] then
2115 g_Sound_PlayExAt('SOUND_ITEM_GETMED', FObj.X, FObj.Y)
2116 else g_Sound_PlayExAt('SOUND_ITEM_GETITEM', FObj.X, FObj.Y);
2118 // Íàäî óáðàòü ñ êàðòû, åñëè ýòî íå êëþ÷, êîòîðûì íóæíî ïîäåëèòñÿ ñ äðóãèì èãðîêîì:
2119 if r and not ((ItemType in [ITEM_KEY_RED, ITEM_KEY_GREEN, ITEM_KEY_BLUE]) and
2120 (gGameSettings.GameType = GT_SINGLE) and
2121 (g_Player_GetCount() > 1)) then
2122 if not Respawnable then g_Items_Remove(i) else g_Items_Pick(i);
2128 function TPlayer
.CollideLevel(XInc
, YInc
: Integer): Boolean;
2130 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
2131 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_WALL
,
2135 constructor TPlayer
.Create();
2141 mEDamageType
:= HIT_SOME
;
2147 FSawSound
:= TPlayableSound
.Create();
2148 FSawSoundIdle
:= TPlayableSound
.Create();
2149 FSawSoundHit
:= TPlayableSound
.Create();
2150 FSawSoundSelect
:= TPlayableSound
.Create();
2151 FFlameSoundOn
:= TPlayableSound
.Create();
2152 FFlameSoundOff
:= TPlayableSound
.Create();
2153 FFlameSoundWork
:= TPlayableSound
.Create();
2154 FJetSoundFly
:= TPlayableSound
.Create();
2155 FJetSoundOn
:= TPlayableSound
.Create();
2156 FJetSoundOff
:= TPlayableSound
.Create();
2158 FSawSound
.SetByName('SOUND_WEAPON_FIRESAW');
2159 FSawSoundIdle
.SetByName('SOUND_WEAPON_IDLESAW');
2160 FSawSoundHit
.SetByName('SOUND_WEAPON_HITSAW');
2161 FSawSoundSelect
.SetByName('SOUND_WEAPON_SELECTSAW');
2162 FFlameSoundOn
.SetByName('SOUND_WEAPON_FLAMEON');
2163 FFlameSoundOff
.SetByName('SOUND_WEAPON_FLAMEOFF');
2164 FFlameSoundWork
.SetByName('SOUND_WEAPON_FLAMEWORK');
2165 FJetSoundFly
.SetByName('SOUND_PLAYER_JETFLY');
2166 FJetSoundOn
.SetByName('SOUND_PLAYER_JETON');
2167 FJetSoundOff
.SetByName('SOUND_PLAYER_JETOFF');
2169 FSpectatePlayer
:= -1;
2173 FSavedStateNum
:= -1;
2181 FActualModelName
:= 'doomer';
2184 FObj
.Rect
:= PLAYER_RECT
;
2186 FBFGFireCounter
:= -1;
2187 FJustTeleported
:= False;
2190 FWaitForFirstSpawn
:= false;
2195 procedure TPlayer
.positionChanged (); inline;
2199 procedure TPlayer
.doDamage (v
: Integer);
2201 if (v
<= 0) then exit
;
2202 if (v
> 32767) then v
:= 32767;
2203 Damage(v
, 0, 0, 0, mEDamageType
);
2206 procedure TPlayer
.Damage(value
: Word; SpawnerUID
: Word; vx
, vy
: Integer; t
: Byte);
2210 if (not g_Game_IsClient
) and (not FAlive
) then
2215 // Íåóÿçâèìîñòü íå ñïàñàåò îò ëîâóøåê:
2216 if ((t
= HIT_TRAP
) or (t
= HIT_SELF
)) and (not FGodMode
) then
2218 if not g_Game_IsClient
then
2221 if t
= HIT_TRAP
then
2223 // Ëîâóøêà óáèâàåò ñðàçó:
2225 Kill(K_EXTRAHARDKILL
, SpawnerUID
, t
);
2227 if t
= HIT_SELF
then
2231 Kill(K_SIMPLEKILL
, SpawnerUID
, t
);
2234 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
2235 FMegaRulez
[MR_SUIT
] := 0;
2236 FMegaRulez
[MR_INVUL
] := 0;
2237 FMegaRulez
[MR_INVIS
] := 0;
2242 // Íî îò îñòàëüíîãî ñïàñàåò:
2243 if FMegaRulez
[MR_INVUL
] >= gTime
then
2250 // Åñëè åñòü óðîí ñâîèì, èëè ðàíèë ñàì ñåáÿ, èëè òåáÿ ðàíèë ïðîòèâíèê:
2251 if LongBool(gGameSettings
.Options
and GAME_OPTION_TEAMDAMAGE
) or
2252 (SpawnerUID
= FUID
) or
2253 (not SameTeam(FUID
, SpawnerUID
)) then
2255 FLastSpawnerUID
:= SpawnerUID
;
2257 // Êðîâü (ïóçûðüêè, åñëè â âîäå):
2258 if gBloodCount
> 0 then
2260 c
:= Min(value
, 200)*gBloodCount
+ Random(Min(value
, 200) div 2);
2261 if value
div 4 <= c
then
2262 c
:= c
- (value
div 4)
2266 if (t
= HIT_SOME
) and (vx
= 0) and (vy
= 0) then
2270 HIT_TRAP
, HIT_ACID
, HIT_FLAME
, HIT_SELF
: MakeBloodSimple(c
);
2271 HIT_BFG
, HIT_ROCKET
, HIT_SOME
: MakeBloodVector(c
, vx
, vy
);
2274 if t
= HIT_WATER
then
2275 g_GFX_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
2276 FObj
.Y
+PLAYER_RECT
.Y
-4, value
div 2, 8, 4);
2281 Inc(FDamageBuffer
, value
);
2285 FPain
:= FPain
+ value
;
2288 if g_Game_IsServer
and g_Game_IsNet
then
2290 MH_SEND_PlayerDamage(FUID
, t
, SpawnerUID
, value
, vx
, vy
);
2291 MH_SEND_PlayerStats(FUID
);
2292 MH_SEND_PlayerPos(False, FUID
);
2296 function TPlayer
.Heal(value
: Word; Soft
: Boolean): Boolean;
2299 if g_Game_IsClient
then
2304 if Soft
and (FHealth
< PLAYER_HP_SOFT
) then
2306 IncMax(FHealth
, value
, PLAYER_HP_SOFT
);
2309 if (not Soft
) and (FHealth
< PLAYER_HP_LIMIT
) then
2311 IncMax(FHealth
, value
, PLAYER_HP_LIMIT
);
2315 if Result
and g_Game_IsServer
and g_Game_IsNet
then
2316 MH_SEND_PlayerStats(FUID
);
2319 destructor TPlayer
.Destroy();
2321 if (gPlayer1
<> nil) and (gPlayer1
.FUID
= FUID
) then
2323 if (gPlayer2
<> nil) and (gPlayer2
.FUID
= FUID
) then
2327 FSawSoundIdle
.Free();
2328 FSawSoundHit
.Free();
2329 FSawSoundSelect
.Free();
2330 FFlameSoundOn
.Free();
2331 FFlameSoundOff
.Free();
2332 FFlameSoundWork
.Free();
2333 FJetSoundFly
.Free();
2335 FJetSoundOff
.Free();
2337 if FPunchAnim
<> nil then
2343 procedure TPlayer
.DrawIndicator(Color
: TRGB
);
2345 indX
, indY
, fX
, fY
, fSlope
: Integer;
2355 FObj
.lerp(gLerpFactor
, fX
, fY
);
2356 fSlope
:= nlerp(FSlopeOld
, FObj
.slopeUpLeft
, gLerpFactor
);
2358 case gPlayerIndicatorStyle
of
2361 if g_Texture_Get('TEXTURE_PLAYER_INDICATOR', ID
) then
2363 e_GetTextureSize(ID
, @indW
, @indH
);
2367 if (FObj
.X
+ FObj
.Rect
.X
) < 0 then
2370 indX
:= fX
+ FObj
.Rect
.X
+ FObj
.Rect
.Width
;
2371 indY
:= fY
+ FObj
.Rect
.Y
+ (FObj
.Rect
.Height
- indW
) div 2;
2374 else if (FObj
.X
+ FObj
.Rect
.X
+ FObj
.Rect
.Width
) > Max(gMapInfo
.Width
, gPlayerScreenSize
.X
) then
2377 indX
:= fX
+ FObj
.Rect
.X
- indH
;
2378 indY
:= fY
+ FObj
.Rect
.Y
+ (FObj
.Rect
.Height
- indW
) div 2;
2381 else if (FObj
.Y
- indH
) < 0 then
2384 indX
:= fX
+ FObj
.Rect
.X
+ (FObj
.Rect
.Width
- indW
) div 2;
2385 indY
:= fY
+ FObj
.Rect
.Y
+ FObj
.Rect
.Height
;
2391 indX
:= fX
+ FObj
.Rect
.X
+ (FObj
.Rect
.Width
- indW
) div 2;
2395 indY
:= indY
+ fSlope
;
2396 indX
:= EnsureRange(indX
, 0, Max(gMapInfo
.Width
, gPlayerScreenSize
.X
) - indW
);
2397 indY
:= EnsureRange(indY
, 0, Max(gMapInfo
.Height
, gPlayerScreenSize
.Y
) - indH
);
2401 e_DrawAdv(ID
, indX
, indY
, 0, True, False, indA
, @a
);
2408 e_TextureFontGetSize(gStdFont
, nW
, nH
);
2409 indX
:= fX
+ FObj
.Rect
.X
+ (FObj
.Rect
.Width
- Length(FName
) * nW
) div 2;
2410 indY
:= fY
- nH
+ fSlope
;
2411 e_TextureFontPrintEx(indX
, indY
, FName
, gStdFont
, Color
.R
, Color
.G
, Color
.B
, 1.0, True);
2417 procedure TPlayer
.DrawBubble();
2419 bubX
, bubY
, fX
, fY
: Integer;
2422 Rw
, Gw
, Bw
: SmallInt;
2426 CObj
:= getCameraObj();
2427 CObj
.lerp(gLerpFactor
, fX
, fY
);
2428 // NB: _F_Obj.Rect is used to keep the bubble higher; this is not a mistake
2429 bubX
:= fX
+FObj
.Rect
.X
+ IfThen(FDirection
= TDirection
.D_LEFT
, -4, 18);
2430 bubY
:= fY
+FObj
.Rect
.Y
- 18;
2438 1: // simple textual non-bubble
2440 bubX
:= fX
+FObj
.Rect
.X
- 11;
2441 bubY
:= fY
+FObj
.Rect
.Y
- 17;
2442 e_TextureFontPrint(bubX
, bubY
, '[...]', gStdFont
);
2445 2: // advanced pixel-perfect bubble
2447 if FTeam
= TEAM_RED
then
2450 if FTeam
= TEAM_BLUE
then
2453 3: // colored bubble
2455 Rb
:= FModel
.Color
.R
;
2456 Gb
:= FModel
.Color
.G
;
2457 Bb
:= FModel
.Color
.B
;
2458 Rw
:= Min(Rb
* 2 + 64, 255);
2459 Gw
:= Min(Gb
* 2 + 64, 255);
2460 Bw
:= Min(Bb
* 2 + 64, 255);
2461 if (Abs(Rw
- Rb
) < 32)
2462 or (Abs(Gw
- Gb
) < 32)
2463 or (Abs(Bw
- Bb
) < 32) then
2465 Rb
:= Max(Rw
div 2 - 16, 0);
2466 Gb
:= Max(Gw
div 2 - 16, 0);
2467 Bb
:= Max(Bw
div 2 - 16, 0);
2470 4: // custom textured bubble
2472 if g_Texture_Get('TEXTURE_PLAYER_TALKBUBBLE', ID
) then
2473 if FDirection
= TDirection
.D_RIGHT
then
2474 e_Draw(ID
, bubX
- 6, bubY
- 7, 0, True, False)
2476 e_Draw(ID
, bubX
- 6, bubY
- 7, 0, True, False, TMirrorType
.Horizontal
);
2482 e_DrawQuad(bubX
+ 1, bubY
, bubX
+ 18, bubY
+ 13, Rb
, Gb
, Bb
);
2483 e_DrawQuad(bubX
, bubY
+ 1, bubX
+ 19, bubY
+ 12, Rb
, Gb
, Bb
);
2485 e_DrawFillQuad(bubX
+ 1, bubY
+ 1, bubX
+ 18, bubY
+ 12, Rw
, Gw
, Bw
, 0);
2488 Dot
:= IfThen(FDirection
= TDirection
.D_LEFT
, 14, 5);
2489 e_DrawLine(1, bubX
+ Dot
, bubY
+ 14, bubX
+ Dot
, bubY
+ 16, Rb
, Gb
, Bb
);
2490 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
);
2491 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
);
2492 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
);
2493 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
);
2497 e_DrawFillQuad(bubX
+ Dot
, bubY
+ 8, bubX
+ Dot
+ 1, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2498 e_DrawFillQuad(bubX
+ Dot
+ 3, bubY
+ 8, bubX
+ Dot
+ 4, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2499 e_DrawFillQuad(bubX
+ Dot
+ 6, bubY
+ 8, bubX
+ Dot
+ 7, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2502 procedure TPlayer
.Draw();
2507 Mirror
: TMirrorType
;
2508 fX
, fY
, fSlope
: Integer;
2510 FObj
.lerp(gLerpFactor
, fX
, fY
);
2511 fSlope
:= nlerp(FSlopeOld
, FObj
.slopeUpLeft
, gLerpFactor
);
2515 if Direction
= TDirection
.D_RIGHT
then
2516 Mirror
:= TMirrorType
.None
2518 Mirror
:= TMirrorType
.Horizontal
;
2520 if FPunchAnim
<> nil then
2522 FPunchAnim
.Draw(fX
+IfThen(Direction
= TDirection
.D_LEFT
, 15-FObj
.Rect
.X
, FObj
.Rect
.X
-15),
2523 fY
+fSlope
+FObj
.Rect
.Y
-11, Mirror
);
2524 if FPunchAnim
.played
then
2531 if (FMegaRulez
[MR_INVUL
] > gTime
) and ((gPlayerDrawn
<> Self
) or (FSpawnInvul
>= gTime
)) then
2532 if g_Texture_Get('TEXTURE_PLAYER_INVULPENTA', ID
) then
2534 e_GetTextureSize(ID
, @w
, @h
);
2535 if FDirection
= TDirection
.D_LEFT
then
2536 e_Draw(ID
, fX
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2)-(w
div 2)+4,
2537 fY
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2)-(h
div 2)-7+fSlope
, 0, True, False)
2539 e_Draw(ID
, fX
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2)-(w
div 2)-2,
2540 fY
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2)-(h
div 2)-7+fSlope
, 0, True, False);
2543 if FMegaRulez
[MR_INVIS
] > gTime
then
2545 if (gPlayerDrawn
<> nil) and ((Self
= gPlayerDrawn
) or
2546 ((FTeam
= gPlayerDrawn
.Team
) and (gGameSettings
.GameMode
<> GM_DM
))) then
2548 if (FMegaRulez
[MR_INVIS
] - gTime
) <= 2100 then
2549 dr
:= not Odd((FMegaRulez
[MR_INVIS
] - gTime
) div 300)
2553 FModel
.Draw(fX
, fY
+fSlope
, 200)
2555 FModel
.Draw(fX
, fY
+fSlope
);
2558 FModel
.Draw(fX
, fY
+fSlope
, 254);
2561 FModel
.Draw(fX
, fY
+fSlope
);
2564 if g_debug_Frames
then
2566 e_DrawQuad(FObj
.X
+FObj
.Rect
.X
,
2568 FObj
.X
+FObj
.Rect
.X
+FObj
.Rect
.Width
-1,
2569 FObj
.Y
+FObj
.Rect
.Y
+FObj
.Rect
.Height
-1,
2573 if (gChatBubble
> 0) and (FKeys
[KEY_CHAT
].Pressed
) and not FGhost
then
2574 if (FMegaRulez
[MR_INVIS
] <= gTime
) or ((gPlayerDrawn
<> nil) and ((Self
= gPlayerDrawn
) or
2575 ((FTeam
= gPlayerDrawn
.Team
) and (gGameSettings
.GameMode
<> GM_DM
)))) then
2577 // e_DrawPoint(5, 335, 288, 255, 0, 0); // DL, UR, DL, UR
2578 if gAimLine
and alive
and
2579 ((Self
= gPlayer1
) or (Self
= gPlayer2
)) then
2584 procedure TPlayer
.DrawAim();
2585 procedure drawCast (sz
: Integer; ax0
, ay0
, ax1
, ay1
: Integer);
2590 {$IFDEF ENABLE_HOLMES}
2591 if isValidViewPort
and (self
= gPlayer1
) then
2593 g_Holmes_plrLaser(ax0
, ay0
, ax1
, ay1
);
2597 e_DrawLine(sz
, ax0
, ay0
, ax1
, ay1
, 255, 0, 0, 96);
2598 if (g_Map_traceToNearestWall(ax0
, ay0
, ax1
, ay1
, @ex
, @ey
) <> nil) then
2600 e_DrawLine(sz
, ax0
, ay0
, ex
, ey
, 0, 255, 0, 96);
2604 e_DrawLine(sz
, ax0
, ay0
, ex
, ey
, 0, 0, 255, 96);
2609 wx
, wy
, xx
, yy
: Integer;
2613 wx
:= FObj
.X
+ WEAPONPOINT
[FDirection
].X
+ IfThen(FDirection
= TDirection
.D_LEFT
, 7, -7);
2614 wy
:= FObj
.Y
+ WEAPONPOINT
[FDirection
].Y
;
2623 1: begin // Chainsaw
2630 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2631 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2632 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2633 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2638 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2639 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2640 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2641 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2643 4: begin // Double Shotgun
2646 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2647 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2648 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2649 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2651 5: begin // Chaingun
2654 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2655 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2656 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2657 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2659 6: begin // Rocket Launcher
2662 if angle
= ANGLE_RIGHTUP
then Inc(angle
, 2);
2663 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2664 if angle
= ANGLE_LEFTUP
then Dec(angle
, 2);
2665 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2667 7: begin // Plasmagun
2670 if angle
= ANGLE_RIGHTUP
then Inc(angle
);
2671 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 3);
2672 if angle
= ANGLE_LEFTUP
then Dec(angle
);
2673 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 3);
2678 if angle
= ANGLE_RIGHTUP
then Inc(angle
, 1);
2679 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 2);
2680 if angle
= ANGLE_LEFTUP
then Dec(angle
, 1);
2681 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 2);
2683 9: begin // Super Chaingun
2686 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2687 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2688 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2689 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2692 xx
:= Trunc(Cos(-DegToRad(angle
)) * len
) + wx
;
2693 yy
:= Trunc(Sin(-DegToRad(angle
)) * len
) + wy
;
2694 {$IF DEFINED(D2F_DEBUG)}
2695 drawCast(sz
, wx
, wy
, xx
, yy
);
2697 e_DrawLine(sz
, wx
, wy
, xx
, yy
, 255, 0, 0, 96);
2701 procedure TPlayer
.DrawGUI();
2704 X
, Y
, SY
, a
, p
, m
: Integer;
2708 stat
: TPlayerStatArray
;
2710 X
:= gPlayerScreenSize
.X
;
2711 SY
:= gPlayerScreenSize
.Y
;
2714 if gShowGoals
and (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
2716 if gGameSettings
.GameMode
= GM_CTF
then
2720 if gGameSettings
.GameMode
= GM_CTF
then
2722 s
:= 'TEXTURE_PLAYER_REDFLAG';
2723 if gFlags
[FLAG_RED
].State
= FLAG_STATE_CAPTURED
then
2724 s
:= 'TEXTURE_PLAYER_REDFLAG_S';
2725 if gFlags
[FLAG_RED
].State
= FLAG_STATE_DROPPED
then
2726 s
:= 'TEXTURE_PLAYER_REDFLAG_D';
2727 if g_Texture_Get(s
, ID
) then
2728 e_Draw(ID
, X
-16-32, 240-72-4, 0, True, False);
2731 s
:= IntToStr(gTeamStat
[TEAM_RED
].Goals
);
2732 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2733 e_CharFont_PrintEx(gMenuFont
, X
-16-a
-tw
, 240-72-4, s
, TEAMCOLOR
[TEAM_RED
]);
2735 if gGameSettings
.GameMode
= GM_CTF
then
2737 s
:= 'TEXTURE_PLAYER_BLUEFLAG';
2738 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_CAPTURED
then
2739 s
:= 'TEXTURE_PLAYER_BLUEFLAG_S';
2740 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_DROPPED
then
2741 s
:= 'TEXTURE_PLAYER_BLUEFLAG_D';
2742 if g_Texture_Get(s
, ID
) then
2743 e_Draw(ID
, X
-16-32, 240-32-4, 0, True, False);
2746 s
:= IntToStr(gTeamStat
[TEAM_BLUE
].Goals
);
2747 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2748 e_CharFont_PrintEx(gMenuFont
, X
-16-a
-tw
, 240-32-4, s
, TEAMCOLOR
[TEAM_BLUE
]);
2751 if g_Texture_Get('TEXTURE_PLAYER_HUDBG', ID
) then
2752 e_DrawFill(ID
, X
, 0, 1, (gPlayerScreenSize
.Y
div 256)+IfThen(gPlayerScreenSize
.Y
mod 256 > 0, 1, 0),
2755 if g_Texture_Get('TEXTURE_PLAYER_HUD', ID
) then
2756 e_Draw(ID
, X
+2, Y
, 0, True, False);
2758 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
2762 s
:= IntToStr(Frags
);
2763 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2764 e_CharFont_PrintEx(gMenuFont
, X
-16-tw
, Y
, s
, _RGB(255, 0, 0));
2769 stat
:= g_Player_GetStats();
2774 for a
:= 0 to High(stat
) do
2775 if stat
[a
].Name
<> Name
then
2777 if stat
[a
].Frags
> m
then m
:= stat
[a
].Frags
;
2778 if stat
[a
].Frags
> Frags
then p
:= p
+1;
2782 s
:= IntToStr(p
)+' / '+IntToStr(Length(stat
))+' ';
2783 if Frags
>= m
then s
:= s
+'+' else s
:= s
+'-';
2784 s
:= s
+IntToStr(Abs(Frags
-m
));
2786 e_CharFont_GetSize(gMenuSmallFont
, s
, tw
, th
);
2787 e_CharFont_PrintEx(gMenuSmallFont
, X
-16-tw
, Y
+32, s
, _RGB(255, 0, 0));
2790 if gLMSRespawn
> LMS_RESPAWN_NONE
then
2792 s
:= _lc
[I_GAME_WARMUP
];
2793 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2794 s
:= s
+ ': ' + IntToStr((gLMSRespawnTime
- gTime
) div 1000);
2795 e_CharFont_PrintEx(gMenuFont
, X
-64-tw
, SY
-32, s
, _RGB(0, 255, 0));
2797 else if gShowLives
and (gGameSettings
.MaxLives
> 0) then
2799 s
:= IntToStr(Lives
);
2800 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2801 e_CharFont_PrintEx(gMenuFont
, X
-16-tw
, SY
-32, s
, _RGB(0, 255, 0));
2805 e_CharFont_GetSize(gMenuSmallFont
, FName
, tw
, th
);
2806 e_CharFont_PrintEx(gMenuSmallFont
, X
+98-(tw
div 2), Y
+8, FName
, _RGB(255, 0, 0));
2808 if R_BERSERK
in FRulez
then
2809 e_Draw(gItemsTexturesID
[ITEM_MEDKIT_BLACK
], X
+37, Y
+45, 0, True, False)
2811 e_Draw(gItemsTexturesID
[ITEM_MEDKIT_LARGE
], X
+37, Y
+45, 0, True, False);
2813 if g_Texture_Get('TEXTURE_PLAYER_ARMORHUD', ID
) then
2814 e_Draw(ID
, X
+36, Y
+77, 0, True, False);
2816 s
:= IntToStr(IfThen(FHealth
> 0, FHealth
, 0));
2817 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2818 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+40, s
, _RGB(255, 0, 0));
2820 s
:= IntToStr(FArmor
);
2821 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2822 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+68, s
, _RGB(255, 0, 0));
2824 s
:= IntToStr(GetAmmoByWeapon(FCurrWeap
));
2830 ID
:= gItemsTexturesID
[ITEM_WEAPON_KASTET
];
2835 ID
:= gItemsTexturesID
[ITEM_WEAPON_SAW
];
2837 WEAPON_PISTOL
: ID
:= gItemsTexturesID
[ITEM_WEAPON_PISTOL
];
2838 WEAPON_CHAINGUN
: ID
:= gItemsTexturesID
[ITEM_WEAPON_CHAINGUN
];
2839 WEAPON_SHOTGUN1
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SHOTGUN1
];
2840 WEAPON_SHOTGUN2
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SHOTGUN2
];
2841 WEAPON_SUPERPULEMET
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SUPERPULEMET
];
2842 WEAPON_ROCKETLAUNCHER
: ID
:= gItemsTexturesID
[ITEM_WEAPON_ROCKETLAUNCHER
];
2843 WEAPON_PLASMA
: ID
:= gItemsTexturesID
[ITEM_WEAPON_PLASMA
];
2844 WEAPON_BFG
: ID
:= gItemsTexturesID
[ITEM_WEAPON_BFG
];
2845 WEAPON_FLAMETHROWER
: ID
:= gItemsTexturesID
[ITEM_WEAPON_FLAMETHROWER
];
2848 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2849 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+158, s
, _RGB(255, 0, 0));
2850 e_Draw(ID
, X
+20, Y
+160, 0, True, False);
2852 if R_KEY_RED
in FRulez
then
2853 e_Draw(gItemsTexturesID
[ITEM_KEY_RED
], X
+78, Y
+214, 0, True, False);
2855 if R_KEY_GREEN
in FRulez
then
2856 e_Draw(gItemsTexturesID
[ITEM_KEY_GREEN
], X
+95, Y
+214, 0, True, False);
2858 if R_KEY_BLUE
in FRulez
then
2859 e_Draw(gItemsTexturesID
[ITEM_KEY_BLUE
], X
+112, Y
+214, 0, True, False);
2861 if FJetFuel
> 0 then
2863 if g_Texture_Get('TEXTURE_PLAYER_HUDAIR', ID
) then
2864 e_Draw(ID
, X
+2, Y
+116, 0, True, False);
2865 if g_Texture_Get('TEXTURE_PLAYER_HUDJET', ID
) then
2866 e_Draw(ID
, X
+2, Y
+126, 0, True, False);
2867 e_DrawLine(4, X
+16, Y
+122, X
+16+Trunc(168*IfThen(FAir
> 0, FAir
, 0)/AIR_MAX
), Y
+122, 0, 0, 196);
2868 e_DrawLine(4, X
+16, Y
+132, X
+16+Trunc(168*FJetFuel
/JET_MAX
), Y
+132, 208, 0, 0);
2872 if g_Texture_Get('TEXTURE_PLAYER_HUDAIR', ID
) then
2873 e_Draw(ID
, X
+2, Y
+124, 0, True, False);
2874 e_DrawLine(4, X
+16, Y
+130, X
+16+Trunc(168*IfThen(FAir
> 0, FAir
, 0)/AIR_MAX
), Y
+130, 0, 0, 196);
2877 if gShowPing
and g_Game_IsClient
then
2879 s
:= _lc
[I_GAME_PING_HUD
] + IntToStr(NetPeer
.lastRoundTripTime
) + _lc
[I_NET_SLIST_PING_MS
];
2880 e_TextureFontPrint(X
+ 4, Y
+ 242, s
, gStdFont
);
2886 e_TextureFontPrint(X
+ 4, Y
+ 242, _lc
[I_PLAYER_SPECT
], gStdFont
);
2887 e_TextureFontPrint(X
+ 4, Y
+ 258, _lc
[I_PLAYER_SPECT2
], gStdFont
);
2888 e_TextureFontPrint(X
+ 4, Y
+ 274, _lc
[I_PLAYER_SPECT1
], gStdFont
);
2891 e_TextureFontGetSize(gStdFont
, cw
, ch
);
2892 s
:= _lc
[I_PLAYER_SPECT4
];
2893 e_TextureFontPrintEx(gScreenWidth
div 2 - cw
*(Length(s
) div 2),
2894 gScreenHeight
-4-ch
, s
, gStdFont
, 255, 255, 255, 1, True);
2895 e_TextureFontPrint(X
+ 4, Y
+ 290, _lc
[I_PLAYER_SPECT1S
], gStdFont
);
2901 procedure TPlayer
.DrawRulez();
2905 // Ïðè âçÿòèè íåóÿçâèìîñòè ðèñóåòñÿ èíâåðñèîííûé áåëûé ôîí
2906 if (FMegaRulez
[MR_INVUL
] >= gTime
) and (FSpawnInvul
< gTime
) then
2908 if (FMegaRulez
[MR_INVUL
]-gTime
) <= 2100 then
2909 dr
:= not Odd((FMegaRulez
[MR_INVUL
]-gTime
) div 300)
2914 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2915 191, 191, 191, 0, TBlending
.Invert
);
2918 // Ïðè âçÿòèè çàùèòíîãî êîñòþìà ðèñóåòñÿ çåëåíîâàòûé ôîí
2919 if FMegaRulez
[MR_SUIT
] >= gTime
then
2921 if (FMegaRulez
[MR_SUIT
]-gTime
) <= 2100 then
2922 dr
:= not Odd((FMegaRulez
[MR_SUIT
]-gTime
) div 300)
2927 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2928 0, 96, 0, 200, TBlending
.None
);
2931 // Ïðè âçÿòèè áåðñåðêà ðèñóåòñÿ êðàñíîâàòûé ôîí
2932 if (FBerserk
>= 0) and (LongWord(FBerserk
) >= gTime
) and (gFlash
= 2) then
2934 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2935 255, 0, 0, 200, TBlending
.None
);
2939 procedure TPlayer
.DrawPain();
2943 if FPain
= 0 then Exit
;
2947 if a
< 15 then h
:= 0
2948 else if a
< 35 then h
:= 1
2949 else if a
< 55 then h
:= 2
2950 else if a
< 75 then h
:= 3
2951 else if a
< 95 then h
:= 4
2954 //if a > 255 then a := 255;
2956 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1, 255, 0, 0, 255-h
*50);
2957 //e_DrawFillQuad(0, 0, gPlayerScreenSize.X-1, gPlayerScreenSize.Y-1, 255-min(128, a), 255-a, 255-a, 0, B_FILTER);
2960 procedure TPlayer
.DrawPickup();
2964 if FPickup
= 0 then Exit
;
2968 if a
< 15 then h
:= 1
2969 else if a
< 35 then h
:= 2
2970 else if a
< 55 then h
:= 3
2971 else if a
< 75 then h
:= 4
2974 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1, 150, 200, 150, 255-h
*50);
2977 procedure TPlayer
.DoPunch();
2982 if FPunchAnim
<> nil then begin
2987 st
:= 'FRAMES_PUNCH';
2988 if R_BERSERK
in FRulez
then
2989 st
:= st
+ '_BERSERK';
2990 if FKeys
[KEY_UP
].Pressed
then
2992 else if FKeys
[KEY_DOWN
].Pressed
then
2994 g_Frames_Get(id
, st
);
2995 FPunchAnim
:= TAnimation
.Create(id
, False, 1);
2998 procedure TPlayer
.Fire();
3000 f
, DidFire
: Boolean;
3001 wx
, wy
, xd
, yd
: Integer;
3004 if g_Game_IsClient
then Exit
;
3005 // FBFGFireCounter - âðåìÿ ïåðåä âûñòðåëîì (äëÿ BFG)
3006 // FReloading - âðåìÿ ïîñëå âûñòðåëà (äëÿ âñåãî)
3014 if FReloading
[FCurrWeap
] <> 0 then Exit
;
3019 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
3020 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
3021 xd
:= wx
+IfThen(FDirection
= TDirection
.D_LEFT
, -30, 30);
3022 yd
:= wy
+firediry();
3028 if R_BERSERK
in FRulez
then
3030 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
3031 locobj
.X
:= FObj
.X
+FObj
.Rect
.X
;
3032 locobj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
3035 locobj
.rect
.Width
:= 39;
3036 locobj
.rect
.Height
:= 52;
3037 locobj
.Vel
.X
:= (xd
-wx
) div 2;
3038 locobj
.Vel
.Y
:= (yd
-wy
) div 2;
3039 locobj
.Accel
.X
:= xd
-wx
;
3040 locobj
.Accel
.y
:= yd
-wy
;
3042 if g_Weapon_Hit(@locobj
, 50, FUID
, HIT_SOME
) <> 0 then
3043 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
3045 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
3047 if (gFlash
= 1) and (FPain
< 50) then FPain
:= min(FPain
+ 25, 50);
3051 g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
3055 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3060 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
3061 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
3063 FSawSoundSelect
.Stop();
3065 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
3067 else if not FSawSoundHit
.IsPlaying() then
3069 FSawSoundSelect
.Stop();
3070 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
3073 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3079 if FAmmo
[A_BULLETS
] > 0 then
3081 g_Weapon_pistol(wx
, wy
, xd
, yd
, FUID
);
3082 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3083 Dec(FAmmo
[A_BULLETS
]);
3084 FFireAngle
:= FAngle
;
3087 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
3088 GameVelX
, GameVelY
-2, SHELL_BULLET
);
3092 if FAmmo
[A_SHELLS
] > 0 then
3094 g_Weapon_shotgun(wx
, wy
, xd
, yd
, FUID
);
3095 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', wx
, wy
);
3096 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3097 Dec(FAmmo
[A_SHELLS
]);
3098 FFireAngle
:= FAngle
;
3102 FShellType
:= SHELL_SHELL
;
3106 if FAmmo
[A_SHELLS
] >= 2 then
3108 g_Weapon_dshotgun(wx
, wy
, xd
, yd
, FUID
);
3109 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3110 Dec(FAmmo
[A_SHELLS
], 2);
3111 FFireAngle
:= FAngle
;
3115 FShellType
:= SHELL_DBLSHELL
;
3119 if FAmmo
[A_BULLETS
] > 0 then
3121 g_Weapon_mgun(wx
, wy
, xd
, yd
, FUID
);
3122 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', wx
, wy
);
3123 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3124 Dec(FAmmo
[A_BULLETS
]);
3125 FFireAngle
:= FAngle
;
3128 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
3129 GameVelX
, GameVelY
-2, SHELL_BULLET
);
3132 WEAPON_ROCKETLAUNCHER
:
3133 if FAmmo
[A_ROCKETS
] > 0 then
3135 g_Weapon_rocket(wx
, wy
, xd
, yd
, FUID
);
3136 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3137 Dec(FAmmo
[A_ROCKETS
]);
3138 FFireAngle
:= FAngle
;
3144 if FAmmo
[A_CELLS
] > 0 then
3146 g_Weapon_plasma(wx
, wy
, xd
, yd
, FUID
);
3147 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3148 Dec(FAmmo
[A_CELLS
]);
3149 FFireAngle
:= FAngle
;
3155 if (FAmmo
[A_CELLS
] >= 40) and (FBFGFireCounter
= -1) then
3157 FBFGFireCounter
:= 17;
3158 if not FNoReload
then
3159 g_Sound_PlayExAt('SOUND_WEAPON_STARTFIREBFG', FObj
.X
, FObj
.Y
);
3160 Dec(FAmmo
[A_CELLS
], 40);
3164 WEAPON_SUPERPULEMET
:
3165 if FAmmo
[A_SHELLS
] > 0 then
3167 g_Weapon_shotgun(wx
, wy
, xd
, yd
, FUID
);
3168 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', wx
, wy
);
3169 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3170 Dec(FAmmo
[A_SHELLS
]);
3171 FFireAngle
:= FAngle
;
3174 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
3175 GameVelX
, GameVelY
-2, SHELL_SHELL
);
3178 WEAPON_FLAMETHROWER
:
3179 if FAmmo
[A_FUEL
] > 0 then
3181 g_Weapon_flame(wx
, wy
, xd
, yd
, FUID
);
3183 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3185 FFireAngle
:= FAngle
;
3192 if g_Game_IsNet
and g_Game_IsServer
then MH_SEND_PlayerStats(FUID
);
3196 if g_Game_IsNet
then
3200 if FCurrWeap
<> WEAPON_BFG
then
3201 MH_SEND_PlayerFire(FUID
, FCurrWeap
, wx
, wy
, xd
, yd
, LastShotID
)
3203 if not FNoReload
then
3204 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_WEAPON_STARTFIREBFG');
3207 MH_SEND_PlayerStats(FUID
);
3212 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
3213 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
3214 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
3217 function TPlayer
.GetAmmoByWeapon(Weapon
: Byte): Word;
3220 WEAPON_PISTOL
, WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
];
3221 WEAPON_SHOTGUN1
, WEAPON_SHOTGUN2
, WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
];
3222 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
];
3223 WEAPON_PLASMA
, WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
];
3224 WEAPON_FLAMETHROWER
: Result
:= FAmmo
[A_FUEL
];
3229 function TPlayer
.HeadInLiquid(XInc
, YInc
: Integer): Boolean;
3231 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
+XInc
, FObj
.Y
+PLAYER_HEADRECT
.Y
+YInc
,
3232 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
3233 PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, True);
3236 procedure TPlayer
.FlamerOn
;
3238 FFlameSoundOff
.Stop();
3239 FFlameSoundOff
.SetPosition(0);
3242 if (not FFlameSoundOn
.IsPlaying()) and (not FFlameSoundWork
.IsPlaying()) then
3243 FFlameSoundWork
.PlayAt(FObj
.X
, FObj
.Y
);
3247 FFlameSoundOn
.PlayAt(FObj
.X
, FObj
.Y
);
3252 procedure TPlayer
.FlamerOff
;
3256 FFlameSoundOn
.Stop();
3257 FFlameSoundOn
.SetPosition(0);
3258 FFlameSoundWork
.Stop();
3259 FFlameSoundWork
.SetPosition(0);
3260 FFlameSoundOff
.PlayAt(FObj
.X
, FObj
.Y
);
3265 procedure TPlayer
.JetpackOn
;
3269 FJetSoundOn
.SetPosition(0);
3270 FJetSoundOn
.PlayAt(FObj
.X
, FObj
.Y
);
3274 procedure TPlayer
.JetpackOff
;
3278 FJetSoundOff
.SetPosition(0);
3279 FJetSoundOff
.PlayAt(FObj
.X
, FObj
.Y
);
3282 procedure TPlayer
.CatchFire(Attacker
: Word; Timeout
: Integer = PLAYER_BURN_TIME
);
3284 if Timeout
<= 0 then
3286 if (FMegaRulez
[MR_SUIT
] > gTime
) or (FMegaRulez
[MR_INVUL
] > gTime
) then
3287 exit
; // Íå çàãîðàåìñÿ êîãäà åñòü çàùèòà
3288 if g_Obj_CollidePanel(@FObj
, 0, 0, PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
) then
3289 exit
; // Íå ïîäãîðàåì â âîäå íà âñÿêèé ñëó÷àé
3290 if FFireTime
<= 0 then
3291 g_Sound_PlayExAt('SOUND_IGNITE', FObj
.X
, FObj
.Y
);
3292 FFireTime
:= Timeout
;
3293 FFireAttacker
:= Attacker
;
3294 if g_Game_IsNet
and g_Game_IsServer
then
3295 MH_SEND_PlayerStats(FUID
);
3298 procedure TPlayer
.Jump();
3300 if gFly
or FJetpack
then
3302 // Ïîëåò (÷èò-êîä èëè äæåòïàê):
3303 if FObj
.Vel
.Y
> -VEL_FLY
then
3304 FObj
.Vel
.Y
:= FObj
.Vel
.Y
- 3;
3307 if FJetFuel
> 0 then
3309 if (FJetFuel
< 1) and g_Game_IsServer
then
3313 if g_Game_IsNet
then
3314 MH_SEND_PlayerStats(FUID
);
3320 // Íå âêëþ÷àòü äæåòïàê â ðåæèìå ïðîõîæäåíèÿ ñêâîçü ñòåíû
3322 FCanJetpack
:= False;
3324 // Ïðûãàåì èëè âñïëûâàåì:
3325 if (CollideLevel(0, 1) or
3326 g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
+36, PLAYER_RECT
.Width
,
3327 PLAYER_RECT
.Height
-33, PANEL_STEP
, False)
3328 ) and (FObj
.Accel
.Y
= 0) then // Íå ïðûãàòü, åñëè åñòü âåðòèêàëüíîå óñêîðåíèå
3330 FObj
.Vel
.Y
:= -VEL_JUMP
;
3331 FCanJetpack
:= False;
3335 if BodyInLiquid(0, 0) then
3336 FObj
.Vel
.Y
:= -VEL_SW
3337 else if (FJetFuel
> 0) and FCanJetpack
and
3338 g_Game_IsServer
and (not g_Obj_CollideLiquid(@FObj
, 0, 0)) then
3342 if g_Game_IsNet
then
3343 MH_SEND_PlayerStats(FUID
);
3348 procedure TPlayer
.Kill(KillType
: Byte; SpawnerUID
: Word; t
: Byte);
3350 a
, i
, k
, ab
, ar
: Byte;
3354 srv
, netsrv
: Boolean;
3360 procedure PushItem(t
: Byte);
3364 id
:= g_Items_Create(FObj
.X
, FObj
.Y
, t
, True, False);
3365 it
:= g_Items_ByIdx(id
);
3366 if KillType
= K_EXTRAHARDKILL
then // -7..+7; -8..0
3368 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-7+Random(15),
3369 (FObj
.Vel
.Y
div 2)-Random(9));
3370 it
.positionChanged(); // this updates spatial accelerators
3374 if KillType
= K_HARDKILL
then // -5..+5; -5..0
3376 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-5+Random(11),
3377 (FObj
.Vel
.Y
div 2)-Random(6));
3379 else // -3..+3; -3..0
3381 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-3+Random(7),
3382 (FObj
.Vel
.Y
div 2)-Random(4));
3384 it
.positionChanged(); // this updates spatial accelerators
3387 if g_Game_IsNet
and g_Game_IsServer
then
3388 MH_SEND_ItemSpawn(True, id
);
3392 DoFrags
:= (gGameSettings
.MaxLives
= 0) or (gGameSettings
.GameMode
= GM_COOP
);
3393 Srv
:= g_Game_IsServer
;
3394 Netsrv
:= g_Game_IsServer
and g_Game_IsNet
;
3395 if Srv
then FDeath
:= FDeath
+ 1;
3400 if not FPhysics
then
3406 if (gGameSettings
.MaxLives
> 0) and Srv
and (gLMSRespawn
= LMS_RESPAWN_NONE
) then
3408 if FLives
> 0 then FLives
:= FLives
- 1;
3409 if FLives
= 0 then FNoRespawn
:= True;
3412 // Íîìåð òèïà ñìåðòè:
3415 K_SIMPLEKILL
: a
:= 1;
3417 K_EXTRAHARDKILL
: a
:= 3;
3422 if not FModel
.PlaySound(MODELSOUND_DIE
, a
, FObj
.X
, FObj
.Y
) then
3424 if FModel
.PlaySound(MODELSOUND_DIE
, i
, FObj
.X
, FObj
.Y
) then
3431 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN1
;
3433 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN2
;
3434 K_EXTRAHARDKILL
, K_FALLKILL
:
3435 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN3
;
3438 // Ïåðåêëþ÷àåì ñîñòîÿíèå:
3442 K_HARDKILL
, K_EXTRAHARDKILL
:
3446 // Ðåàêöèÿ ìîíñòðîâ íà ñìåðòü èãðîêà:
3447 if (KillType
<> K_FALLKILL
) and (Srv
) then
3448 g_Monsters_killedp();
3450 if SpawnerUID
= FUID
then
3454 if gGameSettings
.GameMode
= GM_TDM
then
3455 Dec(gTeamStat
[FTeam
].Goals
);
3456 if DoFrags
or (gGameSettings
.GameMode
= GM_TDM
) then
3462 g_Console_Add(Format(_lc
[I_PLAYER_KILL_SELF
], [FName
]), True);
3465 if g_GetUIDType(SpawnerUID
) = UID_PLAYER
then
3466 begin // Óáèò äðóãèì èãðîêîì
3467 KP
:= g_Player_Get(SpawnerUID
);
3468 if (KP
<> nil) and Srv
then
3470 if (DoFrags
or (gGameSettings
.GameMode
= GM_TDM
)) then
3471 if SameTeam(FUID
, SpawnerUID
) then
3481 if (gGameSettings
.GameMode
= GM_TDM
) and DoFrags
then
3482 Inc(gTeamStat
[KP
.Team
].Goals
,
3483 IfThen(SameTeam(FUID
, SpawnerUID
), -1, 1));
3485 if netsrv
then MH_SEND_PlayerStats(SpawnerUID
);
3488 plr
:= g_Player_Get(SpawnerUID
);
3496 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_2
],
3500 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_1
],
3504 g_Console_Add(Format(_lc
[I_PLAYER_KILL
],
3509 else if g_GetUIDType(SpawnerUID
) = UID_MONSTER
then
3510 begin // Óáèò ìîíñòðîì
3511 mon
:= g_Monsters_ByUID(SpawnerUID
);
3515 s
:= g_Mons_GetKilledByTypeId(mon
.MonsterType
);
3519 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_2
],
3523 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_1
],
3527 g_Console_Add(Format(_lc
[I_PLAYER_KILL
],
3532 else // Îñîáûå òèïû ñìåðòè
3535 HIT_SELF
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_SELF
], [FName
]), True);
3536 HIT_FALL
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_FALL
], [FName
]), True);
3537 HIT_WATER
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_WATER
], [FName
]), True);
3538 HIT_ACID
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_ACID
], [FName
]), True);
3539 HIT_TRAP
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_TRAP
], [FName
]), True);
3540 else g_Console_Add(Format(_lc
[I_PLAYER_DIED
], [FName
]), True);
3546 for a
:= WP_FIRST
to WP_LAST
do
3550 WEAPON_SAW
: i
:= ITEM_WEAPON_SAW
;
3551 WEAPON_SHOTGUN1
: i
:= ITEM_WEAPON_SHOTGUN1
;
3552 WEAPON_SHOTGUN2
: i
:= ITEM_WEAPON_SHOTGUN2
;
3553 WEAPON_CHAINGUN
: i
:= ITEM_WEAPON_CHAINGUN
;
3554 WEAPON_ROCKETLAUNCHER
: i
:= ITEM_WEAPON_ROCKETLAUNCHER
;
3555 WEAPON_PLASMA
: i
:= ITEM_WEAPON_PLASMA
;
3556 WEAPON_BFG
: i
:= ITEM_WEAPON_BFG
;
3557 WEAPON_SUPERPULEMET
: i
:= ITEM_WEAPON_SUPERPULEMET
;
3558 WEAPON_FLAMETHROWER
: i
:= ITEM_WEAPON_FLAMETHROWER
;
3567 if R_ITEM_BACKPACK
in FRulez
then
3568 PushItem(ITEM_AMMO_BACKPACK
);
3570 // Âûáðîñ ðàêåòíîãî ðàíöà:
3571 if FJetFuel
> 0 then
3572 PushItem(ITEM_JETPACK
);
3575 if (not (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
])) or
3576 (not LongBool(gGameSettings
.Options
and GAME_OPTION_DMKEYS
)) then
3578 if R_KEY_RED
in FRulez
then
3579 PushItem(ITEM_KEY_RED
);
3581 if R_KEY_GREEN
in FRulez
then
3582 PushItem(ITEM_KEY_GREEN
);
3584 if R_KEY_BLUE
in FRulez
then
3585 PushItem(ITEM_KEY_BLUE
);
3589 DropFlag(KillType
= K_FALLKILL
);
3592 FCorpse
:= g_Player_CreateCorpse(Self
);
3594 if Srv
and (gGameSettings
.MaxLives
> 0) and FNoRespawn
and
3595 (gLMSRespawn
= LMS_RESPAWN_NONE
) then
3601 for i
:= Low(gPlayers
) to High(gPlayers
) do
3603 if gPlayers
[i
] = nil then continue
;
3604 if (not gPlayers
[i
].FNoRespawn
) and (not gPlayers
[i
].FSpectator
) then
3607 if gPlayers
[i
].FTeam
= TEAM_RED
then Inc(ar
)
3608 else if gPlayers
[i
].FTeam
= TEAM_BLUE
then Inc(ab
);
3613 OldLR
:= gLMSRespawn
;
3614 if (gGameSettings
.GameMode
= GM_COOP
) then
3618 // everyone is dead, restart the map
3619 g_Game_Message(_lc
[I_MESSAGE_LMS_LOSE
], 144);
3621 MH_SEND_GameEvent(NET_EV_LMS_LOSE
);
3622 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3623 gLMSRespawnTime
:= gTime
+ 5000;
3625 else if (a
= 1) then
3627 if (gPlayers
[k
] <> nil) and not (gPlayers
[k
] is TBot
) then
3628 if (gPlayers
[k
] = gPlayer1
) or
3629 (gPlayers
[k
] = gPlayer2
) then
3630 g_Console_Add('*** ' + _lc
[I_MESSAGE_LMS_SURVIVOR
] + ' ***', True)
3631 else if Netsrv
and (gPlayers
[k
].FClientID
>= 0) then
3632 MH_SEND_GameEvent(NET_EV_LMS_SURVIVOR
, 0, 'N', gPlayers
[k
].FClientID
);
3635 else if (gGameSettings
.GameMode
= GM_TDM
) then
3637 if (ab
= 0) and (ar
<> 0) then
3640 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 144);
3642 MH_SEND_GameEvent(NET_EV_TLMS_WIN
, TEAM_RED
);
3643 Inc(gTeamStat
[TEAM_RED
].Goals
);
3644 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3645 gLMSRespawnTime
:= gTime
+ 5000;
3647 else if (ar
= 0) and (ab
<> 0) then
3650 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 144);
3652 MH_SEND_GameEvent(NET_EV_TLMS_WIN
, TEAM_BLUE
);
3653 Inc(gTeamStat
[TEAM_BLUE
].Goals
);
3654 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3655 gLMSRespawnTime
:= gTime
+ 5000;
3657 else if (ar
= 0) and (ab
= 0) then
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 else if (gGameSettings
.GameMode
= GM_DM
) then
3671 if gPlayers
[k
] <> nil then
3674 // survivor is the winner
3675 g_Game_Message(Format(_lc
[I_MESSAGE_LMS_WIN
], [AnsiUpperCase(FName
)]), 144);
3677 MH_SEND_GameEvent(NET_EV_LMS_WIN
, 0, FName
);
3680 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3681 gLMSRespawnTime
:= gTime
+ 5000;
3683 else if (a
= 0) then
3685 // everyone is dead, restart the map
3686 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
3688 MH_SEND_GameEvent(NET_EV_LMS_DRAW
, 0, FName
);
3689 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3690 gLMSRespawnTime
:= gTime
+ 5000;
3693 if srv
and (OldLR
= LMS_RESPAWN_NONE
) and (gLMSRespawn
> LMS_RESPAWN_NONE
) then
3695 if NetMode
= NET_SERVER
then
3696 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
)
3698 g_Console_Add(Format(_lc
[I_MSG_WARMUP_START
], [(gLMSRespawnTime
- gTime
) div 1000]), True);
3704 MH_SEND_PlayerStats(FUID
);
3705 MH_SEND_PlayerDeath(FUID
, KillType
, t
, SpawnerUID
);
3706 if gGameSettings
.GameMode
= GM_TDM
then MH_SEND_GameStats
;
3709 if srv
and FNoRespawn
then Spectate(True);
3710 FWantsInGame
:= True;
3713 function TPlayer
.BodyInLiquid(XInc
, YInc
: Integer): Boolean;
3715 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
, PLAYER_RECT
.Width
,
3716 PLAYER_RECT
.Height
-20, PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, False);
3719 function TPlayer
.BodyInAcid(XInc
, YInc
: Integer): Boolean;
3721 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
, PLAYER_RECT
.Width
,
3722 PLAYER_RECT
.Height
-20, PANEL_ACID1
or PANEL_ACID2
, False);
3725 procedure TPlayer
.MakeBloodSimple(Count
: Word);
3727 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)+8,
3728 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3729 Count
div 2, 3, -1, 16, (PLAYER_RECT
.Height
*2 div 3),
3730 FModel
.Blood
.R
, FModel
.Blood
.G
, FModel
.Blood
.B
, FModel
.Blood
.Kind
);
3731 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-8,
3732 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3733 Count
div 2, -3, -1, 16, (PLAYER_RECT
.Height
*2) div 3,
3734 FModel
.Blood
.R
, FModel
.Blood
.G
, FModel
.Blood
.B
, FModel
.Blood
.Kind
);
3737 procedure TPlayer
.MakeBloodVector(Count
: Word; VelX
, VelY
: Integer);
3739 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
3740 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3741 Count
, VelX
, VelY
, 16, (PLAYER_RECT
.Height
*2) div 3,
3742 FModel
.Blood
.R
, FModel
.Blood
.G
, FModel
.Blood
.B
, FModel
.Blood
.Kind
);
3745 procedure TPlayer
.ProcessWeaponAction(Action
: Byte);
3747 if g_Game_IsClient
then Exit
;
3749 WP_PREV
: PrevWeapon();
3750 WP_NEXT
: NextWeapon();
3754 procedure TPlayer
.QueueWeaponSwitch(Weapon
: Byte);
3756 if g_Game_IsClient
then Exit
;
3757 if Weapon
> High(FWeapon
) then Exit
;
3758 FNextWeap
:= FNextWeap
or (1 shl Weapon
);
3761 procedure TPlayer
.resetWeaponQueue ();
3764 FNextWeapDelay
:= 0;
3767 function TPlayer
.hasAmmoForWeapon (weapon
: Byte): Boolean;
3771 WEAPON_KASTET
, WEAPON_SAW
: result
:= true;
3772 WEAPON_SHOTGUN1
, WEAPON_SHOTGUN2
, WEAPON_SUPERPULEMET
: result
:= (FAmmo
[A_SHELLS
] > 0);
3773 WEAPON_PISTOL
, WEAPON_CHAINGUN
: result
:= (FAmmo
[A_BULLETS
] > 0);
3774 WEAPON_ROCKETLAUNCHER
: result
:= (FAmmo
[A_ROCKETS
] > 0);
3775 WEAPON_PLASMA
, WEAPON_BFG
: result
:= (FAmmo
[A_CELLS
] > 0);
3776 WEAPON_FLAMETHROWER
: result
:= (FAmmo
[A_FUEL
] > 0);
3777 else result
:= (weapon
< length(FWeapon
));
3781 function TPlayer
.shouldSwitch (weapon
: Byte; hadWeapon
: Boolean): Boolean;
3784 if (weapon
< 0) or (weapon
> WP_LAST
+ 1) then
3789 if (FWeapSwitchMode
= 1) and not hadWeapon
then
3791 else if (FWeapSwitchMode
= 2) then
3792 result
:= (FWeapPreferences
[weapon
] > FWeapPreferences
[FCurrWeap
]);
3795 // return 255 for "no switch"
3796 function TPlayer
.getNextWeaponIndex (): Byte;
3799 wantThisWeapon
: array[0..64] of Boolean;
3800 wwc
: Integer = 0; //HACK!
3803 result
:= 255; // default result: "no switch"
3804 //e_LogWriteFln('FSWITCHTOEMPTY: %s', [FSwitchToEmpty], TMsgType.Notify);
3805 // had weapon cycling on previous frame? remove that flag
3806 if (FNextWeap
and $2000) <> 0 then
3808 FNextWeap
:= FNextWeap
and $1FFF;
3809 FNextWeapDelay
:= 0;
3811 // cycling has priority
3812 if (FNextWeap
and $C000) <> 0 then
3814 if (FNextWeap
and $8000) <> 0 then
3818 FNextWeap
:= FNextWeap
or $2000; // we need this
3819 if FNextWeapDelay
> 0 then
3820 exit
; // cooldown time
3822 for i
:= 0 to High(FWeapon
) do
3824 cwi
:= (cwi
+length(FWeapon
)+dir
) mod length(FWeapon
);
3825 if FWeapon
[cwi
] and maySwitch(cwi
) then
3827 //e_LogWriteFln(' SWITCH: cur=%d; new=%d %s %s', [FCurrWeap, cwi, FSwitchToEmpty, hasAmmoForWeapon(cwi)], TMsgType.Notify);
3828 result
:= Byte(cwi
);
3829 FNextWeapDelay
:= WEAPON_DELAY
;
3837 for i
:= 0 to High(wantThisWeapon
) do
3838 wantThisWeapon
[i
] := false;
3839 for i
:= 0 to High(FWeapon
) do
3840 if (FNextWeap
and (1 shl i
)) <> 0 then
3842 wantThisWeapon
[i
] := true;
3846 // exclude currently selected weapon from the set
3847 wantThisWeapon
[FCurrWeap
] := false;
3848 // slow down alterations a little
3851 //e_WriteLog(Format(' FNextWeap=%x; delay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
3852 // more than one weapon requested, assume "alteration" and check alteration delay
3853 if FNextWeapDelay
> 0 then
3859 // do not reset weapon queue, it will be done in `RealizeCurrentWeapon()`
3860 // but clear all counters if no weapon should be switched
3866 //e_WriteLog(Format('wwc=%d', [wwc]), MSG_WARNING);
3867 // try weapons in descending order
3868 for i
:= High(FWeapon
) downto 0 do
3870 if wantThisWeapon
[i
] and FWeapon
[i
] and ((wwc
= 1) or hasAmmoForWeapon(i
)) then
3875 FNextWeapDelay
:= WEAPON_DELAY
* 2; // anyway, 'cause why not
3876 //e_LogWriteFln('FOUND %s %s %s', [result, FSwitchToEmpty, hasAmmoForWeapon(i)], TMsgType.Notify);
3880 // no suitable weapon found, so reset the queue, to avoid accidental "queuing" of weapon w/o ammo
3884 procedure TPlayer
.RealizeCurrentWeapon();
3885 function switchAllowed (): Boolean;
3890 if FBFGFireCounter
<> -1 then
3892 if FTime
[T_SWITCH
] > gTime
then
3894 for i
:= WP_FIRST
to WP_LAST
do
3895 if FReloading
[i
] > 0 then
3903 //e_WriteLog(Format('***RealizeCurrentWeapon: FNextWeap=%x; FNextWeapDelay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
3904 //FNextWeap := FNextWeap and $1FFF;
3905 if FNextWeapDelay
> 0 then Dec(FNextWeapDelay
); // "alteration delay"
3907 if not switchAllowed
then
3909 //HACK for weapon cycling
3910 if (FNextWeap
and $E000) <> 0 then FNextWeap
:= 0;
3914 nw
:= getNextWeaponIndex();
3916 if nw
= 255 then exit
; // don't reset anything here
3917 if nw
> High(FWeapon
) then
3919 // don't forget to reset queue here!
3920 //e_WriteLog(' RealizeCurrentWeapon: WUTAFUUUU', MSG_WARNING);
3928 FTime
[T_SWITCH
] := gTime
+156;
3929 if FCurrWeap
= WEAPON_SAW
then FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3930 FModel
.SetWeapon(FCurrWeap
);
3931 if g_Game_IsNet
then MH_SEND_PlayerStats(FUID
);
3935 procedure TPlayer
.NextWeapon();
3937 if g_Game_IsClient
then Exit
;
3941 procedure TPlayer
.PrevWeapon();
3943 if g_Game_IsClient
then Exit
;
3947 procedure TPlayer
.SetWeapon(W
: Byte);
3949 if FCurrWeap
<> W
then
3950 if W
= WEAPON_SAW
then
3951 FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3954 FModel
.SetWeapon(CurrWeap
);
3958 function TPlayer
.PickItem(ItemType
: Byte; arespawn
: Boolean; var remove
: Boolean): Boolean;
3960 function allowBerserkSwitching (): Boolean;
3962 if (FBFGFireCounter
<> -1) then begin result
:= false; exit
; end;
3964 if gBerserkAutoswitch
then exit
;
3965 if not conIsCheatsEnabled
then exit
;
3971 switchWeapon
: Byte = -1;
3972 hadWeapon
: Boolean = False;
3975 if g_Game_IsClient
then Exit
;
3977 // a = true - ìåñòî ñïàâíà ïðåäìåòà:
3978 a
:= LongBool(gGameSettings
.Options
and GAME_OPTION_WEAPONSTAY
) and arespawn
;
3982 if (FHealth
< PLAYER_HP_SOFT
) or (FFireTime
> 0) then
3984 if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
3988 if gFlash
= 2 then Inc(FPickup
, 5);
3992 if (FHealth
< PLAYER_HP_SOFT
) or (FFireTime
> 0) then
3994 if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
3998 if gFlash
= 2 then Inc(FPickup
, 5);
4002 if FArmor
< PLAYER_AP_SOFT
then
4004 FArmor
:= PLAYER_AP_SOFT
;
4007 if gFlash
= 2 then Inc(FPickup
, 5);
4011 if FArmor
< PLAYER_AP_LIMIT
then
4013 FArmor
:= PLAYER_AP_LIMIT
;
4016 if gFlash
= 2 then Inc(FPickup
, 5);
4020 if (FHealth
< PLAYER_HP_LIMIT
) or (FFireTime
> 0) then
4022 if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
4026 if gFlash
= 2 then Inc(FPickup
, 5);
4030 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) or (FFireTime
> 0) then
4032 if FHealth
< PLAYER_HP_LIMIT
then
4033 FHealth
:= PLAYER_HP_LIMIT
;
4034 if FArmor
< PLAYER_AP_LIMIT
then
4035 FArmor
:= PLAYER_AP_LIMIT
;
4039 if gFlash
= 2 then Inc(FPickup
, 5);
4043 if (not FWeapon
[WEAPON_SAW
]) or ((not arespawn
) and (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
])) then
4045 hadWeapon
:= FWeapon
[WEAPON_SAW
];
4046 switchWeapon
:= WEAPON_SAW
;
4047 FWeapon
[WEAPON_SAW
] := True;
4049 if gFlash
= 2 then Inc(FPickup
, 5);
4050 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4053 ITEM_WEAPON_SHOTGUN1
:
4054 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN1
] then
4056 // Íóæíî, ÷òîáû íå âçÿòü âñå ïóëè ñðàçó:
4057 if a
and FWeapon
[WEAPON_SHOTGUN1
] then Exit
;
4058 hadWeapon
:= FWeapon
[WEAPON_SHOTGUN1
];
4059 switchWeapon
:= WEAPON_SHOTGUN1
;
4060 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4061 FWeapon
[WEAPON_SHOTGUN1
] := 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_SHOTGUN2
:
4068 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN2
] then
4070 if a
and FWeapon
[WEAPON_SHOTGUN2
] then Exit
;
4071 hadWeapon
:= FWeapon
[WEAPON_SHOTGUN2
];
4072 switchWeapon
:= WEAPON_SHOTGUN2
;
4073 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4074 FWeapon
[WEAPON_SHOTGUN2
] := True;
4076 if gFlash
= 2 then Inc(FPickup
, 5);
4077 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4080 ITEM_WEAPON_CHAINGUN
:
4081 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or not FWeapon
[WEAPON_CHAINGUN
] then
4083 if a
and FWeapon
[WEAPON_CHAINGUN
] then Exit
;
4084 hadWeapon
:= FWeapon
[WEAPON_CHAINGUN
];
4085 switchWeapon
:= WEAPON_CHAINGUN
;
4086 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
4087 FWeapon
[WEAPON_CHAINGUN
] := 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');
4093 ITEM_WEAPON_ROCKETLAUNCHER
:
4094 if (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or not FWeapon
[WEAPON_ROCKETLAUNCHER
] then
4096 if a
and FWeapon
[WEAPON_ROCKETLAUNCHER
] then Exit
;
4097 switchWeapon
:= WEAPON_ROCKETLAUNCHER
;
4098 hadWeapon
:= FWeapon
[WEAPON_ROCKETLAUNCHER
];
4099 IncMax(FAmmo
[A_ROCKETS
], 2, FMaxAmmo
[A_ROCKETS
]);
4100 FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
4102 if gFlash
= 2 then Inc(FPickup
, 5);
4103 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4107 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_PLASMA
] then
4109 if a
and FWeapon
[WEAPON_PLASMA
] then Exit
;
4110 switchWeapon
:= WEAPON_PLASMA
;
4111 hadWeapon
:= FWeapon
[WEAPON_PLASMA
];
4112 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
4113 FWeapon
[WEAPON_PLASMA
] := 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');
4120 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_BFG
] then
4122 if a
and FWeapon
[WEAPON_BFG
] then Exit
;
4123 switchWeapon
:= WEAPON_BFG
;
4124 hadWeapon
:= FWeapon
[WEAPON_BFG
];
4125 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
4126 FWeapon
[WEAPON_BFG
] := True;
4128 if gFlash
= 2 then Inc(FPickup
, 5);
4129 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4132 ITEM_WEAPON_SUPERPULEMET
:
4133 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SUPERPULEMET
] then
4135 if a
and FWeapon
[WEAPON_SUPERPULEMET
] then Exit
;
4136 switchWeapon
:= WEAPON_SUPERPULEMET
;
4137 hadWeapon
:= FWeapon
[WEAPON_SUPERPULEMET
];
4138 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4139 FWeapon
[WEAPON_SUPERPULEMET
] := True;
4141 if gFlash
= 2 then Inc(FPickup
, 5);
4142 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4145 ITEM_WEAPON_FLAMETHROWER
:
4146 if (FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
]) or not FWeapon
[WEAPON_FLAMETHROWER
] then
4148 if a
and FWeapon
[WEAPON_FLAMETHROWER
] then Exit
;
4149 switchWeapon
:= WEAPON_FLAMETHROWER
;
4150 hadWeapon
:= FWeapon
[WEAPON_FLAMETHROWER
];
4151 IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
4152 FWeapon
[WEAPON_FLAMETHROWER
] := True;
4154 if gFlash
= 2 then Inc(FPickup
, 5);
4155 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4159 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
4161 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
4164 if gFlash
= 2 then Inc(FPickup
, 5);
4167 ITEM_AMMO_BULLETS_BOX
:
4168 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
4170 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
4173 if gFlash
= 2 then Inc(FPickup
, 5);
4177 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
4179 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4182 if gFlash
= 2 then Inc(FPickup
, 5);
4185 ITEM_AMMO_SHELLS_BOX
:
4186 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
4188 IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
4191 if gFlash
= 2 then Inc(FPickup
, 5);
4195 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
4197 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
4200 if gFlash
= 2 then Inc(FPickup
, 5);
4203 ITEM_AMMO_ROCKET_BOX
:
4204 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
4206 IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
4209 if gFlash
= 2 then Inc(FPickup
, 5);
4213 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
4215 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
4218 if gFlash
= 2 then Inc(FPickup
, 5);
4222 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
4224 IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
4227 if gFlash
= 2 then Inc(FPickup
, 5);
4231 if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then
4233 IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
4236 if gFlash
= 2 then Inc(FPickup
, 5);
4240 if not(R_ITEM_BACKPACK
in FRulez
) or
4241 (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
4242 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
4243 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
4244 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or
4245 (FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
]) then
4247 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[1, A_BULLETS
];
4248 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[1, A_SHELLS
];
4249 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[1, A_ROCKETS
];
4250 FMaxAmmo
[A_CELLS
] := AmmoLimits
[1, A_CELLS
];
4251 FMaxAmmo
[A_FUEL
] := AmmoLimits
[1, A_FUEL
];
4253 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
4254 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
4255 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
4256 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4257 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
4258 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
4259 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
4260 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
4261 if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then
4262 IncMax(FAmmo
[A_FUEL
], 50, FMaxAmmo
[A_FUEL
]);
4264 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
4267 if gFlash
= 2 then Inc(FPickup
, 5);
4271 if not(R_KEY_RED
in FRulez
) then
4273 Include(FRulez
, R_KEY_RED
);
4275 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
4276 if gFlash
= 2 then Inc(FPickup
, 5);
4277 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
4281 if not(R_KEY_GREEN
in FRulez
) then
4283 Include(FRulez
, R_KEY_GREEN
);
4285 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
4286 if gFlash
= 2 then Inc(FPickup
, 5);
4287 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
4291 if not(R_KEY_BLUE
in FRulez
) then
4293 Include(FRulez
, R_KEY_BLUE
);
4295 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
4296 if gFlash
= 2 then Inc(FPickup
, 5);
4297 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
4301 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
4303 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
4307 if gFlash
= 2 then Inc(FPickup
, 5);
4311 if FAir
< AIR_MAX
then
4316 if gFlash
= 2 then Inc(FPickup
, 5);
4321 if not (R_BERSERK
in FRulez
) then
4323 Include(FRulez
, R_BERSERK
);
4324 if (shouldSwitch(WP_LAST
+ 1, false)) then
4325 QueueWeaponSwitch(WEAPON_KASTET
);
4329 if gFlash
= 2 then Inc(FPickup
, 5);
4331 FBerserk
:= gTime
+30000;
4336 if (FHealth
< PLAYER_HP_SOFT
) or (FFireTime
> 0) then
4338 if FHealth
< PLAYER_HP_SOFT
then FHealth
:= PLAYER_HP_SOFT
;
4339 FBerserk
:= gTime
+30000;
4347 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
4349 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
4353 if gFlash
= 2 then Inc(FPickup
, 5);
4357 if (FHealth
< PLAYER_HP_LIMIT
) or (FFireTime
> 0) then
4359 if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
4363 if gFlash
= 2 then Inc(FPickup
, 5);
4367 if FArmor
< PLAYER_AP_LIMIT
then
4369 IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
4372 if gFlash
= 2 then Inc(FPickup
, 5);
4376 if FJetFuel
< JET_MAX
then
4378 FJetFuel
:= JET_MAX
;
4381 if gFlash
= 2 then Inc(FPickup
, 5);
4385 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
4387 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
4390 if gFlash
= 2 then Inc(FPickup
, 5);
4394 if (shouldSwitch(switchWeapon
, hadWeapon
)) then
4395 QueueWeaponSwitch(switchWeapon
);
4398 procedure TPlayer
.Touch();
4402 //FModel.PlaySound(MODELSOUND_PAIN, 1, FObj.X, FObj.Y);
4405 // Áðîñèòü ôëàã òîâàðèùó:
4406 if gGameSettings
.GameMode
= GM_CTF
then
4411 procedure TPlayer
.Push(vx
, vy
: Integer);
4413 if (not FPhysics
) and FGhost
then
4415 FObj
.Accel
.X
:= FObj
.Accel
.X
+ vx
;
4416 FObj
.Accel
.Y
:= FObj
.Accel
.Y
+ vy
;
4417 if g_Game_IsNet
and g_Game_IsServer
then
4418 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
4421 procedure TPlayer
.Reset(Force
: Boolean);
4427 FTime
[T_RESPAWN
] := 0;
4428 FTime
[T_FLAGCAP
] := 0;
4444 FSpectator
:= False;
4447 FSpectatePlayer
:= -1;
4448 FNoRespawn
:= False;
4450 FLives
:= gGameSettings
.MaxLives
;
4455 procedure TPlayer
.SoftReset();
4463 FBFGFireCounter
:= -1;
4471 SetAction(A_STAND
, True);
4474 function TPlayer
.GetRespawnPoint(): Byte;
4479 // Íà áóäóùåå: FSpawn - èãðîê óæå èãðàë è ïåðåðîæäàåòñÿ
4481 // Îäèíî÷íàÿ èãðà/êîîïåðàòèâ
4482 if gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
] then
4484 if Self
= gPlayer1
then
4486 // player 1 should try to spawn on the player 1 point
4487 if g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) > 0 then
4488 Exit(RESPAWNPOINT_PLAYER1
)
4489 else if g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) > 0 then
4490 Exit(RESPAWNPOINT_PLAYER2
);
4492 else if Self
= gPlayer2
then
4494 // player 2 should try to spawn on the player 2 point
4495 if g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) > 0 then
4496 Exit(RESPAWNPOINT_PLAYER2
)
4497 else if g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) > 0 then
4498 Exit(RESPAWNPOINT_PLAYER1
);
4502 // other players randomly pick either the first or the second point
4503 c
:= IfThen((Random(2) = 0), RESPAWNPOINT_PLAYER1
, RESPAWNPOINT_PLAYER2
);
4504 if g_Map_GetPointCount(c
) > 0 then
4506 // try the other one
4507 c
:= IfThen((c
= RESPAWNPOINT_PLAYER1
), RESPAWNPOINT_PLAYER2
, RESPAWNPOINT_PLAYER1
);
4508 if g_Map_GetPointCount(c
) > 0 then
4514 if gGameSettings
.GameMode
= GM_DM
then
4516 // try DM points first
4517 if g_Map_GetPointCount(RESPAWNPOINT_DM
) > 0 then
4518 Exit(RESPAWNPOINT_DM
);
4522 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
4524 // try team points first
4525 c
:= RESPAWNPOINT_DM
;
4526 if FTeam
= TEAM_RED
then
4527 c
:= RESPAWNPOINT_RED
4528 else if FTeam
= TEAM_BLUE
then
4529 c
:= RESPAWNPOINT_BLUE
;
4530 if g_Map_GetPointCount(c
) > 0 then
4534 // still haven't found a spawnpoint, try random shit
4535 Result
:= g_Map_GetRandomPointType();
4538 procedure TPlayer
.Respawn(Silent
: Boolean; Force
: Boolean = False);
4540 RespawnPoint
: TRespawnPoint
;
4548 FBFGFireCounter
:= -1;
4555 if not g_Game_IsServer
then
4559 FWantsInGame
:= True;
4560 FJustTeleported
:= True;
4563 FTime
[T_RESPAWN
] := 0;
4567 // if server changes MaxLives we gotta be ready
4568 if gGameSettings
.MaxLives
= 0 then FNoRespawn
:= False;
4570 // Åùå íåëüçÿ âîçðîäèòüñÿ:
4571 if FTime
[T_RESPAWN
] > gTime
then
4574 // Ïðîñðàë âñå æèçíè:
4577 if not FSpectator
then Spectate(True);
4578 FWantsInGame
:= True;
4582 if (gGameSettings
.GameType
<> GT_SINGLE
) and (gGameSettings
.GameMode
<> GM_COOP
) then
4583 begin // "Ñâîÿ èãðà"
4584 // Áåðñåðê íå ñîõðàíÿåòñÿ ìåæäó óðîâíÿìè:
4585 FRulez
:= FRulez
-[R_BERSERK
];
4587 else // "Îäèíî÷íàÿ èãðà"/"Êîîï"
4589 // Áåðñåðê è êëþ÷è íå ñîõðàíÿþòñÿ ìåæäó óðîâíÿìè:
4590 FRulez
:= FRulez
-[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
, R_BERSERK
];
4593 // Ïîëó÷àåì òî÷êó ñïàóíà èãðîêà:
4594 c
:= GetRespawnPoint();
4599 // Âîñêðåøåíèå áåç îðóæèÿ:
4602 FHealth
:= Round(PLAYER_HP_SOFT
* (FHandicap
/ 100));
4608 for a
:= WP_FIRST
to WP_LAST
do
4610 FWeapon
[a
] := False;
4614 FWeapon
[WEAPON_PISTOL
] := True;
4615 FWeapon
[WEAPON_KASTET
] := True;
4616 FCurrWeap
:= WEAPON_PISTOL
;
4619 FModel
.SetWeapon(FCurrWeap
);
4621 for b
:= A_BULLETS
to A_HIGH
do
4624 FAmmo
[A_BULLETS
] := 50;
4626 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[0, A_BULLETS
];
4627 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[0, A_SHELLS
];
4628 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[0, A_SHELLS
];
4629 FMaxAmmo
[A_CELLS
] := AmmoLimits
[0, A_CELLS
];
4630 FMaxAmmo
[A_FUEL
] := AmmoLimits
[0, A_FUEL
];
4632 if (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
]) and
4633 LongBool(gGameSettings
.Options
and GAME_OPTION_DMKEYS
) then
4634 FRulez
:= [R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
]
4639 // Ïîëó÷àåì êîîðäèíàòû òî÷êè âîçðîæäåíèÿ:
4640 if not g_Map_GetPoint(c
, RespawnPoint
) then
4642 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
4646 // Óñòàíîâêà êîîðäèíàò è ñáðîñ âñåõ ïàðàìåòðîâ:
4647 FObj
.X
:= RespawnPoint
.X
-PLAYER_RECT
.X
;
4648 FObj
.Y
:= RespawnPoint
.Y
-PLAYER_RECT
.Y
;
4649 FObj
.oldX
:= FObj
.X
; // don't interpolate after respawn
4650 FObj
.oldY
:= FObj
.Y
;
4656 FDirection
:= RespawnPoint
.Direction
;
4657 if FDirection
= TDirection
.D_LEFT
then
4662 SetAction(A_STAND
, True);
4663 FModel
.Direction
:= FDirection
;
4665 for a
:= Low(FTime
) to High(FTime
) do
4668 for a
:= Low(FMegaRulez
) to High(FMegaRulez
) do
4671 // Respawn invulnerability
4672 if (gGameSettings
.GameType
<> GT_SINGLE
) and (gGameSettings
.SpawnInvul
> 0) then
4674 FMegaRulez
[MR_INVUL
] := gTime
+ gGameSettings
.SpawnInvul
* 1000;
4675 FSpawnInvul
:= FMegaRulez
[MR_INVUL
];
4680 FCanJetpack
:= False;
4686 // Àíèìàöèÿ âîçðîæäåíèÿ:
4687 if (not gLoadGameMode
) and (not Silent
) then
4688 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
4690 Anim
:= TAnimation
.Create(ID
, False, 3);
4691 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4692 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4696 FSpectator
:= False;
4699 FSpectatePlayer
:= -1;
4702 if (gPlayer1
= nil) and (gSpectLatchPID1
= FUID
) then
4704 if (gPlayer2
= nil) and (gSpectLatchPID2
= FUID
) then
4707 if g_Game_IsNet
then
4709 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
4710 MH_SEND_PlayerStats(FUID
, NET_EVERYONE
);
4712 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4713 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32,
4718 procedure TPlayer
.Spectate(NoMove
: Boolean = False);
4721 Kill(K_EXTRAHARDKILL
, FUID
, HIT_SOME
)
4722 else if (not NoMove
) then
4724 GameX
:= gMapInfo
.Width
div 2;
4725 GameY
:= gMapInfo
.Height
div 2;
4734 FWantsInGame
:= False;
4740 if Self
= gPlayer1
then
4742 gSpectLatchPID1
:= FUID
;
4745 else if Self
= gPlayer2
then
4747 gSpectLatchPID2
:= FUID
;
4752 if g_Game_IsNet
then
4753 MH_SEND_PlayerStats(FUID
);
4756 procedure TPlayer
.SwitchNoClip
;
4760 FGhost
:= not FGhost
;
4761 FPhysics
:= not FGhost
;
4773 procedure TPlayer
.Run(Direction
: TDirection
);
4777 if MAX_RUNVEL
> 8 then
4781 if Direction
= TDirection
.D_LEFT
then
4783 if FObj
.Vel
.X
> -MAX_RUNVEL
then
4784 FObj
.Vel
.X
:= FObj
.Vel
.X
- (MAX_RUNVEL
shr 3);
4787 if FObj
.Vel
.X
< MAX_RUNVEL
then
4788 FObj
.Vel
.X
:= FObj
.Vel
.X
+ (MAX_RUNVEL
shr 3);
4790 // Âîçìîæíî, ïèíàåì êóñêè:
4791 if (FObj
.Vel
.X
<> 0) and (gGibs
<> nil) then
4793 b
:= Abs(FObj
.Vel
.X
);
4794 if b
> 1 then b
:= b
* (Random(8 div b
) + 1);
4795 for a
:= 0 to High(gGibs
) do
4797 if gGibs
[a
].alive
and
4798 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
+FObj
.Rect
.Height
-4,
4799 FObj
.Rect
.Width
, 8, @gGibs
[a
].Obj
) and (Random(3) = 0) then
4802 if FObj
.Vel
.X
< 0 then
4804 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)+120) // íàëåâî
4808 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)); // íàïðàâî
4810 gGibs
[a
].positionChanged(); // this updates spatial accelerators
4818 procedure TPlayer
.SeeDown();
4820 SetAction(A_SEEDOWN
);
4822 if FDirection
= TDirection
.D_LEFT
then FAngle
:= ANGLE_LEFTDOWN
else FAngle
:= ANGLE_RIGHTDOWN
;
4824 if FIncCam
> -120 then DecMin(FIncCam
, 5, -120);
4827 procedure TPlayer
.SeeUp();
4831 if FDirection
= TDirection
.D_LEFT
then FAngle
:= ANGLE_LEFTUP
else FAngle
:= ANGLE_RIGHTUP
;
4833 if FIncCam
< 120 then IncMax(FIncCam
, 5, 120);
4836 procedure TPlayer
.SetAction(Action
: Byte; Force
: Boolean = False);
4844 A_ATTACK
: Prior
:= 2;
4845 A_SEEUP
: Prior
:= 1;
4846 A_SEEDOWN
: Prior
:= 1;
4847 A_ATTACKUP
: Prior
:= 2;
4848 A_ATTACKDOWN
: Prior
:= 2;
4853 if (Prior
> FActionPrior
) or Force
then
4854 if not ((Prior
= 2) and (FCurrWeap
= WEAPON_SAW
)) then
4856 FActionPrior
:= Prior
;
4857 FActionAnim
:= Action
;
4858 FActionForce
:= Force
;
4859 FActionChanged
:= True;
4862 if Action
in [A_ATTACK
, A_ATTACKUP
, A_ATTACKDOWN
] then FModel
.SetFire(True);
4865 function TPlayer
.StayOnStep(XInc
, YInc
: Integer): Boolean;
4867 Result
:= not g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
-1,
4868 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False)
4869 and g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
,
4870 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False);
4873 function TPlayer
.TeleportTo(X
, Y
: Integer; silent
: Boolean; dir
: Byte): Boolean;
4880 if g_CollideLevel(X
, Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
) then
4882 g_Sound_PlayExAt('SOUND_GAME_NOTELEPORT', FObj
.X
, FObj
.Y
);
4883 if g_Game_IsServer
and g_Game_IsNet
then
4884 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_GAME_NOTELEPORT');
4888 FJustTeleported
:= True;
4893 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
4895 Anim
:= TAnimation
.Create(ID
, False, 3);
4898 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', FObj
.X
, FObj
.Y
);
4899 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4900 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4901 if g_Game_IsServer
and g_Game_IsNet
then
4902 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4903 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 1,
4907 FObj
.X
:= X
-PLAYER_RECT
.X
;
4908 FObj
.Y
:= Y
-PLAYER_RECT
.Y
;
4909 FObj
.oldX
:= FObj
.X
; // don't interpolate after respawn
4910 FObj
.oldY
:= FObj
.Y
;
4911 if FAlive
and FGhost
then
4917 if not g_Game_IsNet
then
4921 SetDirection(TDirection
.D_LEFT
);
4927 SetDirection(TDirection
.D_RIGHT
);
4933 if FDirection
= TDirection
.D_RIGHT
then
4935 SetDirection(TDirection
.D_LEFT
);
4940 SetDirection(TDirection
.D_RIGHT
);
4946 if not silent
and (Anim
<> nil) then
4948 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4949 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4952 if g_Game_IsServer
and g_Game_IsNet
then
4953 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4954 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 0,
4961 function nonz(a
: Single): Single;
4969 function TPlayer
.refreshCorpse(): Boolean;
4975 if FAlive
or FSpectator
then
4977 if (gCorpses
= nil) or (Length(gCorpses
) = 0) then
4979 for i
:= 0 to High(gCorpses
) do
4980 if gCorpses
[i
] <> nil then
4981 if gCorpses
[i
].FPlayerUID
= FUID
then
4989 function TPlayer
.getCameraObj(): TObj
;
4991 if (not FAlive
) and (not FSpectator
) and
4992 (FCorpse
>= 0) and (FCorpse
< Length(gCorpses
)) and
4993 (gCorpses
[FCorpse
] <> nil) and (gCorpses
[FCorpse
].FPlayerUID
= FUID
) then
4995 gCorpses
[FCorpse
].FObj
.slopeUpLeft
:= FObj
.slopeUpLeft
;
4996 Result
:= gCorpses
[FCorpse
].FObj
;
5004 procedure TPlayer
.PreUpdate();
5006 FSlopeOld
:= FObj
.slopeUpLeft
;
5007 FIncCamOld
:= FIncCam
;
5008 FObj
.oldX
:= FObj
.X
;
5009 FObj
.oldY
:= FObj
.Y
;
5012 procedure TPlayer
.Update();
5015 i
, ii
, wx
, wy
, xd
, yd
, k
: Integer;
5016 blockmon
, headwater
, dospawn
: Boolean;
5021 NetServer
:= g_Game_IsNet
and g_Game_IsServer
;
5022 AnyServer
:= g_Game_IsServer
;
5024 if g_Game_IsClient
and (NetInterpLevel
> 0) then
5025 DoLerp(NetInterpLevel
+ 1)
5031 if (FClientID
>= 0) and (NetClients
[FClientID
].Peer
<> nil) then
5033 FPing
:= NetClients
[FClientID
].Peer
^.lastRoundTripTime
;
5034 if NetClients
[FClientID
].Peer
^.packetsSent
> 0 then
5035 FLoss
:= Round(100*NetClients
[FClientID
].Peer
^.packetsLost
/NetClients
[FClientID
].Peer
^.packetsSent
)
5044 if FAlive
and (FPunchAnim
<> nil) then
5045 FPunchAnim
.Update();
5047 if FAlive
and (gFly
or FJetpack
) then
5050 if FDirection
= TDirection
.D_LEFT
then
5055 if FAlive
and (not FGhost
) then
5057 if FKeys
[KEY_UP
].Pressed
then
5059 if FKeys
[KEY_DOWN
].Pressed
then
5063 if (not (FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_DOWN
].Pressed
)) and
5066 i
:= g_basic
.Sign(FIncCam
);
5067 FIncCam
:= Abs(FIncCam
);
5068 DecMin(FIncCam
, 5, 0);
5069 FIncCam
:= FIncCam
*i
;
5072 if gTime
mod (GAME_TICK
*2) <> 0 then
5074 if (FObj
.Vel
.X
= 0) and FAlive
then
5076 if FKeys
[KEY_LEFT
].Pressed
then
5077 Run(TDirection
.D_LEFT
);
5078 if FKeys
[KEY_RIGHT
].Pressed
then
5079 Run(TDirection
.D_RIGHT
);
5084 g_Obj_Move(@FObj
, True, True, True);
5085 positionChanged(); // this updates spatial accelerators
5091 FActionChanged
:= False;
5095 // Let alive player do some actions
5096 if FKeys
[KEY_LEFT
].Pressed
then Run(TDirection
.D_LEFT
);
5097 if FKeys
[KEY_RIGHT
].Pressed
then Run(TDirection
.D_RIGHT
);
5098 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then Fire()
5104 if NetServer
then MH_SEND_PlayerStats(FUID
);
5107 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Use();
5108 if FKeys
[KEY_JUMP
].Pressed
then Jump()
5111 if AnyServer
and FJetpack
then
5115 if NetServer
then MH_SEND_PlayerStats(FUID
);
5117 FCanJetpack
:= True;
5124 for k
:= Low(FKeys
) to KEY_CHAT
-1 do
5126 if FKeys
[k
].Pressed
then
5134 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
5137 if (FTime
[T_RESPAWN
] <= gTime
) and
5138 gGameOn
and (not FAlive
) then
5140 if (g_Player_GetCount() > 1) then
5144 gExit
:= EXIT_RESTART
;
5149 // Dead spectator actions
5152 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Fire();
5153 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then
5157 if (FSpectatePlayer
>= High(gPlayers
)) then
5158 FSpectatePlayer
:= -1
5162 for I
:= FSpectatePlayer
+ 1 to High(gPlayers
) do
5163 if gPlayers
[I
] <> nil then
5164 if gPlayers
[I
].alive
then
5165 if gPlayers
[I
].UID
<> FUID
then
5167 FSpectatePlayer
:= I
;
5172 if not SetSpect
then FSpectatePlayer
:= -1;
5183 if FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_JUMP
].Pressed
then
5185 FYTo
:= FObj
.Y
- 32;
5186 FSpectatePlayer
:= -1;
5188 if FKeys
[KEY_DOWN
].Pressed
then
5190 FYTo
:= FObj
.Y
+ 32;
5191 FSpectatePlayer
:= -1;
5193 if FKeys
[KEY_LEFT
].Pressed
then
5195 FXTo
:= FObj
.X
- 32;
5196 FSpectatePlayer
:= -1;
5198 if FKeys
[KEY_RIGHT
].Pressed
then
5200 FXTo
:= FObj
.X
+ 32;
5201 FSpectatePlayer
:= -1;
5204 if (FXTo
< -64) then
5206 else if (FXTo
> gMapInfo
.Width
+ 32) then
5207 FXTo
:= gMapInfo
.Width
+ 32;
5208 if (FYTo
< -72) then
5210 else if (FYTo
> gMapInfo
.Height
+ 32) then
5211 FYTo
:= gMapInfo
.Height
+ 32;
5216 g_Obj_Move(@FObj
, True, True, True);
5217 positionChanged(); // this updates spatial accelerators
5224 if (FSpectatePlayer
<= High(gPlayers
)) and (FSpectatePlayer
>= 0) then
5225 if gPlayers
[FSpectatePlayer
] <> nil then
5226 if gPlayers
[FSpectatePlayer
].alive
then
5228 FXTo
:= gPlayers
[FSpectatePlayer
].GameX
;
5229 FYTo
:= gPlayers
[FSpectatePlayer
].GameY
;
5233 blockmon
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
, FObj
.Y
+PLAYER_HEADRECT
.Y
,
5234 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
5235 PANEL_BLOCKMON
, True);
5236 headwater
:= HeadInLiquid(0, 0);
5238 // Ñîïðîòèâëåíèå âîçäóõà:
5239 if (not FAlive
) or not (FKeys
[KEY_LEFT
].Pressed
or FKeys
[KEY_RIGHT
].Pressed
) then
5240 if FObj
.Vel
.X
<> 0 then
5241 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
5243 if (FLastHit
= HIT_TRAP
) and (FPain
> 90) then FPain
:= 90;
5244 DecMin(FPain
, 5, 0);
5245 DecMin(FPickup
, 1, 0);
5247 if FAlive
and (FObj
.Y
> Integer(gMapInfo
.Height
)+128) and AnyServer
then
5249 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
5250 FMegaRulez
[MR_SUIT
] := 0;
5251 FMegaRulez
[MR_INVUL
] := 0;
5252 FMegaRulez
[MR_INVIS
] := 0;
5253 Kill(K_FALLKILL
, 0, HIT_FALL
);
5260 if FCurrWeap
= WEAPON_SAW
then
5261 if not (FSawSound
.IsPlaying() or FSawSoundHit
.IsPlaying() or
5262 FSawSoundSelect
.IsPlaying()) then
5263 FSawSoundIdle
.PlayAt(FObj
.X
, FObj
.Y
);
5266 if (not FJetSoundFly
.IsPlaying()) and (not FJetSoundOn
.IsPlaying()) and
5267 (not FJetSoundOff
.IsPlaying()) then
5269 FJetSoundFly
.SetPosition(0);
5270 FJetSoundFly
.PlayAt(FObj
.X
, FObj
.Y
);
5273 for b
:= WP_FIRST
to WP_LAST
do
5274 if FReloading
[b
] > 0 then
5280 if FShellTimer
> -1 then
5281 if FShellTimer
= 0 then
5283 if FShellType
= SHELL_SHELL
then
5284 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5285 GameVelX
, GameVelY
-2, SHELL_SHELL
)
5286 else if FShellType
= SHELL_DBLSHELL
then
5288 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5289 GameVelX
+1, GameVelY
-2, SHELL_SHELL
);
5290 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5291 GameVelX
-1, GameVelY
-2, SHELL_SHELL
);
5294 end else Dec(FShellTimer
);
5296 if (FBFGFireCounter
> -1) then
5297 if FBFGFireCounter
= 0 then
5301 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
5302 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
5303 xd
:= wx
+IfThen(FDirection
= TDirection
.D_LEFT
, -30, 30);
5304 yd
:= wy
+firediry();
5305 g_Weapon_bfgshot(wx
, wy
, xd
, yd
, FUID
);
5306 if NetServer
then MH_SEND_PlayerFire(FUID
, WEAPON_BFG
, wx
, wy
, xd
, yd
);
5307 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
5308 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
5309 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
5312 FReloading
[WEAPON_BFG
] := WEAPON_RELOAD
[WEAPON_BFG
];
5313 FBFGFireCounter
:= -1;
5316 FBFGFireCounter
:= 0
5318 Dec(FBFGFireCounter
);
5320 if (FMegaRulez
[MR_SUIT
] < gTime
) and AnyServer
then
5322 b
:= g_GetAcidHit(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
);
5324 if (b
> 0) and (gTime
mod (15*GAME_TICK
) = 0) then Damage(b
, 0, 0, 0, HIT_ACID
);
5327 if (headwater
or blockmon
) then
5333 if AnyServer
then Damage(10, 0, 0, 0, HIT_WATER
);
5336 else if (FAir
mod 31 = 0) and not blockmon
then
5338 g_GFX_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2), FObj
.Y
+PLAYER_RECT
.Y
-4, 5+Random(6), 8, 4);
5339 if Random(2) = 0 then
5340 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
5342 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
5344 end else if FAir
< AIR_DEF
then
5347 if FFireTime
> 0 then
5349 if BodyInLiquid(0, 0) then
5354 else if FMegaRulez
[MR_SUIT
] >= gTime
then
5356 if FMegaRulez
[MR_SUIT
] = gTime
then
5363 if FFirePainTime
<= 0 then
5365 if g_Game_IsServer
then
5366 Damage(2, FFireAttacker
, 0, 0, HIT_FLAME
);
5367 FFirePainTime
:= 12 - FFireTime
div 12;
5369 FFirePainTime
:= FFirePainTime
- 1;
5370 FFireTime
:= FFireTime
- 1;
5371 if ((FFireTime
mod 33) = 0) and (FMegaRulez
[MR_INVUL
] < gTime
) then
5372 FModel
.PlaySound(MODELSOUND_PAIN
, 1, FObj
.X
, FObj
.Y
);
5373 if (FFireTime
= 0) and g_Game_IsNet
and g_Game_IsServer
then
5374 MH_SEND_PlayerStats(FUID
);
5378 if FDamageBuffer
> 0 then
5380 if FDamageBuffer
>= 9 then
5384 if FDamageBuffer
< 30 then i
:= 9
5385 else if FDamageBuffer
< 100 then i
:= 18
5389 ii
:= Round(FDamageBuffer
*FHealth
/ nonz(FArmor
*(3/4)+FHealth
));
5390 FArmor
:= FArmor
-(FDamageBuffer
-ii
);
5391 FHealth
:= FHealth
-ii
;
5394 FHealth
:= FHealth
+FArmor
;
5399 if FHealth
<= 0 then
5400 if FHealth
> -30 then Kill(K_SIMPLEKILL
, FLastSpawnerUID
, FLastHit
)
5401 else if FHealth
> -50 then Kill(K_HARDKILL
, FLastSpawnerUID
, FLastHit
)
5402 else Kill(K_EXTRAHARDKILL
, FLastSpawnerUID
, FLastHit
);
5404 if FAlive
and ((FLastHit
<> HIT_FLAME
) or (FFireTime
<= 0)) then
5406 if FDamageBuffer
<= 20 then FModel
.PlaySound(MODELSOUND_PAIN
, 1, FObj
.X
, FObj
.Y
)
5407 else if FDamageBuffer
<= 55 then FModel
.PlaySound(MODELSOUND_PAIN
, 2, FObj
.X
, FObj
.Y
)
5408 else if FDamageBuffer
<= 120 then FModel
.PlaySound(MODELSOUND_PAIN
, 3, FObj
.X
, FObj
.Y
)
5409 else FModel
.PlaySound(MODELSOUND_PAIN
, 4, FObj
.X
, FObj
.Y
);
5416 end; // if FAlive then ...
5418 if (FActionAnim
= A_PAIN
) and (FModel
.Animation
<> A_PAIN
) then
5420 FModel
.ChangeAnimation(FActionAnim
, FActionForce
);
5421 FModel
.GetCurrentAnimation
.MinLength
:= i
;
5422 FModel
.GetCurrentAnimationMask
.MinLength
:= i
;
5423 end else FModel
.ChangeAnimation(FActionAnim
, FActionForce
and (FModel
.Animation
<> A_STAND
));
5425 if (FModel
.GetCurrentAnimation
.Played
or ((not FActionChanged
) and (FModel
.Animation
= A_WALK
)))
5426 then SetAction(A_STAND
, True);
5428 if not ((FModel
.Animation
= A_WALK
) and (Abs(FObj
.Vel
.X
) < 4) and not FModel
.Fire
) then FModel
.Update
;
5430 for b
:= Low(FKeys
) to High(FKeys
) do
5431 if FKeys
[b
].Time
= 0 then FKeys
[b
].Pressed
:= False else Dec(FKeys
[b
].Time
);
5435 procedure TPlayer
.getMapBox (out x
, y
, w
, h
: Integer); inline;
5437 x
:= FObj
.X
+PLAYER_RECT
.X
;
5438 y
:= FObj
.Y
+PLAYER_RECT
.Y
;
5439 w
:= PLAYER_RECT
.Width
;
5440 h
:= PLAYER_RECT
.Height
;
5444 procedure TPlayer
.moveBy (dx
, dy
: Integer); inline;
5446 if (dx
<> 0) or (dy
<> 0) then
5455 function TPlayer
.Collide(X
, Y
: Integer; Width
, Height
: Word): Boolean;
5457 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
5458 FObj
.Y
+PLAYER_RECT
.Y
,
5465 function TPlayer
.Collide(Panel
: TPanel
): Boolean;
5467 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
5468 FObj
.Y
+PLAYER_RECT
.Y
,
5472 Panel
.Width
, Panel
.Height
);
5475 function TPlayer
.Collide(X
, Y
: Integer): Boolean;
5477 X
:= X
-FObj
.X
-PLAYER_RECT
.X
;
5478 Y
:= Y
-FObj
.Y
-PLAYER_RECT
.Y
;
5479 Result
:= (x
>= 0) and (x
<= PLAYER_RECT
.Width
) and
5480 (y
>= 0) and (y
<= PLAYER_RECT
.Height
);
5483 function g_Player_ValidName(Name
: string): Boolean;
5489 if gPlayers
= nil then Exit
;
5491 for a
:= 0 to High(gPlayers
) do
5492 if gPlayers
[a
] <> nil then
5493 if LowerCase(Name
) = LowerCase(gPlayers
[a
].FName
) then
5500 procedure TPlayer
.SetDirection(Direction
: TDirection
);
5504 d
:= FModel
.Direction
;
5506 FModel
.Direction
:= Direction
;
5507 if d
<> Direction
then FModel
.ChangeAnimation(FModel
.Animation
, True);
5509 FDirection
:= Direction
;
5512 function TPlayer
.GetKeys(): Byte;
5516 if R_KEY_RED
in FRulez
then Result
:= KEY_RED
;
5517 if R_KEY_GREEN
in FRulez
then Result
:= Result
or KEY_GREEN
;
5518 if R_KEY_BLUE
in FRulez
then Result
:= Result
or KEY_BLUE
;
5520 if FTeam
= TEAM_RED
then Result
:= Result
or KEY_REDTEAM
;
5521 if FTeam
= TEAM_BLUE
then Result
:= Result
or KEY_BLUETEAM
;
5524 procedure TPlayer
.Use();
5528 if FTime
[T_USE
] > gTime
then Exit
;
5530 g_Triggers_PressR(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
,
5531 PLAYER_RECT
.Height
, FUID
, ACTIVATE_PLAYERPRESS
);
5533 for a
:= 0 to High(gPlayers
) do
5534 if (gPlayers
[a
] <> nil) and (gPlayers
[a
] <> Self
) and
5535 gPlayers
[a
].alive
and SameTeam(FUID
, gPlayers
[a
].FUID
) and
5536 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
5537 FObj
.Rect
.Width
, FObj
.Rect
.Height
, @gPlayers
[a
].FObj
) then
5539 gPlayers
[a
].Touch();
5540 if g_Game_IsNet
and g_Game_IsServer
then
5541 MH_SEND_GameEvent(NET_EV_PLAYER_TOUCH
, gPlayers
[a
].FUID
);
5544 FTime
[T_USE
] := gTime
+120;
5547 procedure TPlayer
.NetFire(Wpn
: Byte; X
, Y
, AX
, AY
: Integer; WID
: Integer = -1);
5551 WX
, WY
, XD
, YD
: Integer;
5563 if R_BERSERK
in FRulez
then
5565 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
5566 locobj
.X
:= FObj
.X
+FObj
.Rect
.X
;
5567 locobj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
5570 locobj
.rect
.Width
:= 39;
5571 locobj
.rect
.Height
:= 52;
5572 locobj
.Vel
.X
:= (xd
-wx
) div 2;
5573 locobj
.Vel
.Y
:= (yd
-wy
) div 2;
5574 locobj
.Accel
.X
:= xd
-wx
;
5575 locobj
.Accel
.y
:= yd
-wy
;
5577 if g_Weapon_Hit(@locobj
, 50, FUID
, HIT_SOME
) <> 0 then
5578 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
5580 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
5584 FPain
:= min(FPain
+ 25, 50);
5586 g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
5591 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
5592 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
5594 FSawSoundSelect
.Stop();
5596 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
5598 else if not FSawSoundHit
.IsPlaying() then
5600 FSawSoundSelect
.Stop();
5601 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
5608 g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', GameX
, Gamey
);
5609 FFireAngle
:= FAngle
;
5611 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5612 GameVelX
, GameVelY
-2, SHELL_BULLET
);
5617 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
5618 FFireAngle
:= FAngle
;
5621 FShellType
:= SHELL_SHELL
;
5626 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN2', Gamex
, Gamey
);
5627 FFireAngle
:= FAngle
;
5630 FShellType
:= SHELL_DBLSHELL
;
5635 g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', Gamex
, Gamey
);
5636 FFireAngle
:= FAngle
;
5638 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5639 GameVelX
, GameVelY
-2, SHELL_BULLET
);
5642 WEAPON_ROCKETLAUNCHER
:
5644 g_Weapon_Rocket(wx
, wy
, xd
, yd
, FUID
, WID
);
5645 FFireAngle
:= FAngle
;
5651 g_Weapon_Plasma(wx
, wy
, xd
, yd
, FUID
, WID
);
5652 FFireAngle
:= FAngle
;
5658 g_Weapon_BFGShot(wx
, wy
, xd
, yd
, FUID
, WID
);
5659 FFireAngle
:= FAngle
;
5663 WEAPON_SUPERPULEMET
:
5665 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
5666 FFireAngle
:= FAngle
;
5668 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5669 GameVelX
, GameVelY
-2, SHELL_SHELL
);
5672 WEAPON_FLAMETHROWER
:
5674 g_Weapon_flame(wx
, wy
, xd
, yd
, FUID
, WID
);
5676 FFireAngle
:= FAngle
;
5683 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
5684 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
5685 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
5688 procedure TPlayer
.DoLerp(Level
: Integer = 2);
5690 if FObj
.X
<> FXTo
then FObj
.X
:= Lerp(FObj
.X
, FXTo
, Level
);
5691 if FObj
.Y
<> FYTo
then FObj
.Y
:= Lerp(FObj
.Y
, FYTo
, Level
);
5694 procedure TPlayer
.SetLerp(XTo
, YTo
: Integer);
5700 if FJustTeleported
or (NetInterpLevel
< 1) then
5704 if FJustTeleported
then
5706 FObj
.oldX
:= FObj
.X
;
5707 FObj
.oldY
:= FObj
.Y
;
5712 AX
:= Abs(FXTo
- FObj
.X
);
5713 AY
:= Abs(FYTo
- FObj
.Y
);
5714 if (AX
> 32) or (AX
<= NetInterpLevel
) then
5716 if (AY
> 32) or (AY
<= NetInterpLevel
) then
5721 function TPlayer
.FullInLift(XInc
, YInc
: Integer): Integer;
5723 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5724 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5725 PANEL_LIFTUP
, False) then Result
:= -1
5727 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5728 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5729 PANEL_LIFTDOWN
, False) then Result
:= 1
5733 function TPlayer
.GetFlag(Flag
: Byte): Boolean;
5740 if Flag
= FLAG_NONE
then
5743 if not g_Game_IsServer
then Exit
;
5745 // Ïðèíåñ ÷óæîé ôëàã íà ñâîþ áàçó:
5746 if (Flag
= FTeam
) and
5747 (gFlags
[Flag
].State
= FLAG_STATE_NORMAL
) and
5748 (FFlag
<> FLAG_NONE
) then
5750 if FFlag
= FLAG_RED
then
5751 s
:= _lc
[I_PLAYER_FLAG_RED
]
5753 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5755 evtype
:= FLAG_STATE_SCORED
;
5757 ts
:= Format('%.4d', [gFlags
[FFlag
].CaptureTime
]);
5758 Insert('.', ts
, Length(ts
) + 1 - 3);
5759 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_CAPTURE
], [FName
, s
, ts
]), True);
5761 g_Map_ResetFlag(FFlag
);
5762 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_CAPTURE
], [AnsiUpperCase(s
)]), 144);
5764 if ((Self
= gPlayer1
) or (Self
= gPlayer2
)
5765 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= FTeam
))
5766 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= FTeam
))) then
5771 if not sound_cap_flag
[a
].IsPlaying() then
5772 sound_cap_flag
[a
].Play();
5774 gTeamStat
[FTeam
].Goals
:= gTeamStat
[FTeam
].Goals
+ 1;
5777 if g_Game_IsNet
then
5779 MH_SEND_FlagEvent(evtype
, FFlag
, FUID
, False);
5783 gFlags
[FFlag
].CaptureTime
:= 0;
5788 // Ïîäîáðàë ñâîé ôëàã - âåðíóë åãî íà áàçó:
5789 if (Flag
= FTeam
) and
5790 (gFlags
[Flag
].State
= FLAG_STATE_DROPPED
) then
5792 if Flag
= FLAG_RED
then
5793 s
:= _lc
[I_PLAYER_FLAG_RED
]
5795 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5797 evtype
:= FLAG_STATE_RETURNED
;
5798 gFlags
[Flag
].CaptureTime
:= 0;
5800 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_RETURN
], [FName
, s
]), True);
5802 g_Map_ResetFlag(Flag
);
5803 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
5805 if ((Self
= gPlayer1
) or (Self
= gPlayer2
)
5806 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= FTeam
))
5807 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= FTeam
))) then
5812 if not sound_ret_flag
[a
].IsPlaying() then
5813 sound_ret_flag
[a
].Play();
5816 if g_Game_IsNet
then
5818 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5824 // Ïîäîáðàë ÷óæîé ôëàã:
5825 if (Flag
<> FTeam
) and (FTime
[T_FLAGCAP
] <= gTime
) then
5829 if Flag
= FLAG_RED
then
5830 s
:= _lc
[I_PLAYER_FLAG_RED
]
5832 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5834 evtype
:= FLAG_STATE_CAPTURED
;
5836 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_GET
], [FName
, s
]), True);
5838 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_GET
], [AnsiUpperCase(s
)]), 144);
5840 gFlags
[Flag
].State
:= FLAG_STATE_CAPTURED
;
5842 if ((Self
= gPlayer1
) or (Self
= gPlayer2
)
5843 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= FTeam
))
5844 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= FTeam
))) then
5849 if not sound_get_flag
[a
].IsPlaying() then
5850 sound_get_flag
[a
].Play();
5853 if g_Game_IsNet
then
5855 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5861 procedure TPlayer
.SetFlag(Flag
: Byte);
5864 if FModel
<> nil then
5865 FModel
.SetFlag(FFlag
);
5868 function TPlayer
.TryDropFlag(): Boolean;
5870 if LongBool(gGameSettings
.Options
and GAME_OPTION_ALLOWDROPFLAG
) then
5871 Result
:= DropFlag(False, LongBool(gGameSettings
.Options
and GAME_OPTION_THROWFLAG
))
5876 function TPlayer
.DropFlag(Silent
: Boolean = True; DoThrow
: Boolean = False): Boolean;
5883 if (not g_Game_IsServer
) or (FFlag
= FLAG_NONE
) then
5885 FTime
[T_FLAGCAP
] := gTime
+ 2000;
5886 with gFlags
[FFlag
] do
5890 Direction
:= FDirection
;
5891 State
:= FLAG_STATE_DROPPED
;
5895 xv
:= FObj
.Vel
.X
+ IfThen(Direction
= TDirection
.D_RIGHT
, 10, -10);
5896 yv
:= FObj
.Vel
.Y
- 2;
5900 xv
:= (FObj
.Vel
.X
div 2);
5901 yv
:= (FObj
.Vel
.Y
div 2) - 2;
5903 g_Obj_Push(@Obj
, xv
, yv
);
5905 positionChanged(); // this updates spatial accelerators
5907 if FFlag
= FLAG_RED
then
5908 s
:= _lc
[I_PLAYER_FLAG_RED
]
5910 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5912 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_DROP
], [FName
, s
]), True);
5913 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_DROP
], [AnsiUpperCase(s
)]), 144);
5915 if ((Self
= gPlayer1
) or (Self
= gPlayer2
)
5916 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= FTeam
))
5917 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= FTeam
))) then
5922 if (not Silent
) and (not sound_lost_flag
[a
].IsPlaying()) then
5923 sound_lost_flag
[a
].Play();
5925 if g_Game_IsNet
then
5926 MH_SEND_FlagEvent(FLAG_STATE_DROPPED
, Flag
, FUID
, False);
5932 procedure TPlayer
.GetSecret();
5934 if (self
= gPlayer1
) or (self
= gPlayer2
) then
5936 g_Console_Add(Format(_lc
[I_PLAYER_SECRET
], [FName
]), True);
5937 g_Sound_PlayEx('SOUND_GAME_SECRET');
5942 procedure TPlayer
.PressKey(Key
: Byte; Time
: Word = 1);
5944 Assert(Key
<= High(FKeys
));
5946 FKeys
[Key
].Pressed
:= True;
5947 FKeys
[Key
].Time
:= Time
;
5950 function TPlayer
.IsKeyPressed(K
: Byte): Boolean;
5952 Result
:= FKeys
[K
].Pressed
;
5955 procedure TPlayer
.ReleaseKeys();
5959 for a
:= Low(FKeys
) to High(FKeys
) do
5961 FKeys
[a
].Pressed
:= False;
5966 procedure TPlayer
.OnDamage(Angle
: SmallInt);
5970 function TPlayer
.firediry(): Integer;
5972 if FKeys
[KEY_UP
].Pressed
then Result
:= -42
5973 else if FKeys
[KEY_DOWN
].Pressed
then Result
:= 19
5977 procedure TPlayer
.RememberState();
5980 SavedState
: TPlayerSavedState
;
5982 SavedState
.Health
:= FHealth
;
5983 SavedState
.Armor
:= FArmor
;
5984 SavedState
.Air
:= FAir
;
5985 SavedState
.JetFuel
:= FJetFuel
;
5986 SavedState
.CurrWeap
:= FCurrWeap
;
5987 SavedState
.NextWeap
:= FNextWeap
;
5988 SavedState
.NextWeapDelay
:= FNextWeapDelay
;
5989 for i
:= Low(FWeapon
) to High(FWeapon
) do
5990 SavedState
.Weapon
[i
] := FWeapon
[i
];
5991 for i
:= Low(FAmmo
) to High(FAmmo
) do
5992 SavedState
.Ammo
[i
] := FAmmo
[i
];
5993 for i
:= Low(FMaxAmmo
) to High(FMaxAmmo
) do
5994 SavedState
.MaxAmmo
[i
] := FMaxAmmo
[i
];
5995 SavedState
.Rulez
:= FRulez
- [R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
];
5997 FSavedStateNum
:= -1;
5998 for i
:= Low(SavedStates
) to High(SavedStates
) do
5999 if not SavedStates
[i
].Used
then
6001 FSavedStateNum
:= i
;
6004 if FSavedStateNum
< 0 then
6006 SetLength(SavedStates
, Length(SavedStates
) + 1);
6007 FSavedStateNum
:= High(SavedStates
);
6010 SavedState
.Used
:= True;
6011 SavedStates
[FSavedStateNum
] := SavedState
;
6014 procedure TPlayer
.RecallState();
6017 SavedState
: TPlayerSavedState
;
6019 if(FSavedStateNum
< 0) or (FSavedStateNum
> High(SavedStates
)) then
6022 SavedState
:= SavedStates
[FSavedStateNum
];
6023 SavedStates
[FSavedStateNum
].Used
:= False;
6024 FSavedStateNum
:= -1;
6026 FHealth
:= SavedState
.Health
;
6027 FArmor
:= SavedState
.Armor
;
6028 FAir
:= SavedState
.Air
;
6029 FJetFuel
:= SavedState
.JetFuel
;
6030 FCurrWeap
:= SavedState
.CurrWeap
;
6031 FNextWeap
:= SavedState
.NextWeap
;
6032 FNextWeapDelay
:= SavedState
.NextWeapDelay
;
6033 for i
:= Low(FWeapon
) to High(FWeapon
) do
6034 FWeapon
[i
] := SavedState
.Weapon
[i
];
6035 for i
:= Low(FAmmo
) to High(FAmmo
) do
6036 FAmmo
[i
] := SavedState
.Ammo
[i
];
6037 for i
:= Low(FMaxAmmo
) to High(FMaxAmmo
) do
6038 FMaxAmmo
[i
] := SavedState
.MaxAmmo
[i
];
6039 FRulez
:= SavedState
.Rulez
;
6041 if gGameSettings
.GameType
= GT_SERVER
then
6042 MH_SEND_PlayerStats(FUID
);
6045 procedure TPlayer
.SaveState (st
: TStream
);
6051 utils
.writeSign(st
, 'PLYR');
6052 utils
.writeInt(st
, Byte(PLR_SAVE_VERSION
)); // version
6054 utils
.writeBool(st
, FIamBot
);
6056 utils
.writeInt(st
, Word(FUID
));
6058 utils
.writeStr(st
, FName
);
6060 utils
.writeInt(st
, Byte(FTeam
));
6062 utils
.writeBool(st
, FAlive
);
6063 // Èçðàñõîäîâàë ëè âñå æèçíè
6064 utils
.writeBool(st
, FNoRespawn
);
6066 if FDirection
= TDirection
.D_LEFT
then b
:= 1 else b
:= 2; // D_RIGHT
6067 utils
.writeInt(st
, Byte(b
));
6069 utils
.writeInt(st
, LongInt(FHealth
));
6070 // Êîýôôèöèåíò èíâàëèäíîñòè
6071 utils
.writeInt(st
, LongInt(FHandicap
));
6073 utils
.writeInt(st
, Byte(FLives
));
6075 utils
.writeInt(st
, LongInt(FArmor
));
6077 utils
.writeInt(st
, LongInt(FAir
));
6079 utils
.writeInt(st
, LongInt(FJetFuel
));
6081 utils
.writeInt(st
, LongInt(FPain
));
6083 utils
.writeInt(st
, LongInt(FKills
));
6085 utils
.writeInt(st
, LongInt(FMonsterKills
));
6087 utils
.writeInt(st
, LongInt(FFrags
));
6089 utils
.writeInt(st
, Byte(FFragCombo
));
6090 // Âðåìÿ ïîñëåäíåãî ôðàãà
6091 utils
.writeInt(st
, LongWord(FLastFrag
));
6093 utils
.writeInt(st
, LongInt(FDeath
));
6095 utils
.writeInt(st
, Byte(FFlag
));
6097 utils
.writeInt(st
, LongInt(FSecrets
));
6099 utils
.writeInt(st
, Byte(FCurrWeap
));
6101 utils
.writeInt(st
, Word(FNextWeap
));
6103 utils
.writeInt(st
, Byte(FNextWeapDelay
));
6104 // Âðåìÿ çàðÿäêè BFG
6105 utils
.writeInt(st
, SmallInt(FBFGFireCounter
));
6107 utils
.writeInt(st
, LongInt(FDamageBuffer
));
6108 // Ïîñëåäíèé óäàðèâøèé
6109 utils
.writeInt(st
, Word(FLastSpawnerUID
));
6110 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà
6111 utils
.writeInt(st
, Byte(FLastHit
));
6113 Obj_SaveState(st
, @FObj
);
6114 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ
6115 for i
:= A_BULLETS
to A_HIGH
do utils
.writeInt(st
, Word(FAmmo
[i
]));
6116 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ
6117 for i
:= A_BULLETS
to A_HIGH
do utils
.writeInt(st
, Word(FMaxAmmo
[i
]));
6119 for i
:= WP_FIRST
to WP_LAST
do utils
.writeBool(st
, FWeapon
[i
]);
6120 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ
6121 for i
:= WP_FIRST
to WP_LAST
do utils
.writeInt(st
, Word(FReloading
[i
]));
6123 utils
.writeBool(st
, (R_ITEM_BACKPACK
in FRulez
));
6124 // Íàëè÷èå êðàñíîãî êëþ÷à
6125 utils
.writeBool(st
, (R_KEY_RED
in FRulez
));
6126 // Íàëè÷èå çåëåíîãî êëþ÷à
6127 utils
.writeBool(st
, (R_KEY_GREEN
in FRulez
));
6128 // Íàëè÷èå ñèíåãî êëþ÷à
6129 utils
.writeBool(st
, (R_KEY_BLUE
in FRulez
));
6131 utils
.writeBool(st
, (R_BERSERK
in FRulez
));
6132 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ
6133 for i
:= MR_SUIT
to MR_MAX
do utils
.writeInt(st
, LongWord(FMegaRulez
[i
]));
6134 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà
6135 for i
:= T_RESPAWN
to T_FLAGCAP
do utils
.writeInt(st
, LongWord(FTime
[i
]));
6137 utils
.writeStr(st
, FModel
.Name
);
6139 utils
.writeInt(st
, Byte(FColor
.R
));
6140 utils
.writeInt(st
, Byte(FColor
.G
));
6141 utils
.writeInt(st
, Byte(FColor
.B
));
6145 procedure TPlayer
.LoadState (st
: TStream
);
6154 if not utils
.checkSign(st
, 'PLYR') then raise XStreamError
.Create('invalid player signature');
6155 if (utils
.readByte(st
) <> PLR_SAVE_VERSION
) then raise XStreamError
.Create('invalid player version');
6157 FIamBot
:= utils
.readBool(st
);
6159 FUID
:= utils
.readWord(st
);
6161 str
:= utils
.readStr(st
);
6162 if (self
<> gPlayer1
) and (self
<> gPlayer2
) then FName
:= str
;
6164 FTeam
:= utils
.readByte(st
);
6166 FAlive
:= utils
.readBool(st
);
6167 // Èçðàñõîäîâàë ëè âñå æèçíè
6168 FNoRespawn
:= utils
.readBool(st
);
6170 b
:= utils
.readByte(st
);
6171 if b
= 1 then FDirection
:= TDirection
.D_LEFT
else FDirection
:= TDirection
.D_RIGHT
; // b = 2
6173 FHealth
:= utils
.readLongInt(st
);
6174 // Êîýôôèöèåíò èíâàëèäíîñòè
6175 FHandicap
:= utils
.readLongInt(st
);
6177 FLives
:= utils
.readByte(st
);
6179 FArmor
:= utils
.readLongInt(st
);
6181 FAir
:= utils
.readLongInt(st
);
6183 FJetFuel
:= utils
.readLongInt(st
);
6185 FPain
:= utils
.readLongInt(st
);
6187 FKills
:= utils
.readLongInt(st
);
6189 FMonsterKills
:= utils
.readLongInt(st
);
6191 FFrags
:= utils
.readLongInt(st
);
6193 FFragCombo
:= utils
.readByte(st
);
6194 // Âðåìÿ ïîñëåäíåãî ôðàãà
6195 FLastFrag
:= utils
.readLongWord(st
);
6197 FDeath
:= utils
.readLongInt(st
);
6199 FFlag
:= utils
.readByte(st
);
6201 FSecrets
:= utils
.readLongInt(st
);
6203 FCurrWeap
:= utils
.readByte(st
);
6205 FNextWeap
:= utils
.readWord(st
);
6207 FNextWeapDelay
:= utils
.readByte(st
);
6208 // Âðåìÿ çàðÿäêè BFG
6209 FBFGFireCounter
:= utils
.readSmallInt(st
);
6211 FDamageBuffer
:= utils
.readLongInt(st
);
6212 // Ïîñëåäíèé óäàðèâøèé
6213 FLastSpawnerUID
:= utils
.readWord(st
);
6214 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà
6215 FLastHit
:= utils
.readByte(st
);
6217 Obj_LoadState(@FObj
, st
);
6218 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ
6219 for i
:= A_BULLETS
to A_HIGH
do FAmmo
[i
] := utils
.readWord(st
);
6220 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ
6221 for i
:= A_BULLETS
to A_HIGH
do FMaxAmmo
[i
] := utils
.readWord(st
);
6223 for i
:= WP_FIRST
to WP_LAST
do FWeapon
[i
] := utils
.readBool(st
);
6224 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ
6225 for i
:= WP_FIRST
to WP_LAST
do FReloading
[i
] := utils
.readWord(st
);
6227 if utils
.readBool(st
) then Include(FRulez
, R_ITEM_BACKPACK
);
6228 // Íàëè÷èå êðàñíîãî êëþ÷à
6229 if utils
.readBool(st
) then Include(FRulez
, R_KEY_RED
);
6230 // Íàëè÷èå çåëåíîãî êëþ÷à
6231 if utils
.readBool(st
) then Include(FRulez
, R_KEY_GREEN
);
6232 // Íàëè÷èå ñèíåãî êëþ÷à
6233 if utils
.readBool(st
) then Include(FRulez
, R_KEY_BLUE
);
6235 if utils
.readBool(st
) then Include(FRulez
, R_BERSERK
);
6236 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ
6237 for i
:= MR_SUIT
to MR_MAX
do FMegaRulez
[i
] := utils
.readLongWord(st
);
6238 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà
6239 for i
:= T_RESPAWN
to T_FLAGCAP
do FTime
[i
] := utils
.readLongWord(st
);
6241 str
:= utils
.readStr(st
);
6243 FColor
.R
:= utils
.readByte(st
);
6244 FColor
.G
:= utils
.readByte(st
);
6245 FColor
.B
:= utils
.readByte(st
);
6246 if (self
= gPlayer1
) then
6248 str
:= gPlayer1Settings
.Model
;
6249 FColor
:= gPlayer1Settings
.Color
;
6251 else if (self
= gPlayer2
) then
6253 str
:= gPlayer2Settings
.Model
;
6254 FColor
:= gPlayer2Settings
.Color
;
6256 // Îáíîâëÿåì ìîäåëü èãðîêà
6258 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
6259 FModel
.Color
:= TEAMCOLOR
[FTeam
]
6261 FModel
.Color
:= FColor
;
6265 procedure TPlayer
.AllRulez(Health
: Boolean);
6271 FHealth
:= PLAYER_HP_LIMIT
;
6272 FArmor
:= PLAYER_AP_LIMIT
;
6276 for a
:= WP_FIRST
to WP_LAST
do FWeapon
[a
] := True;
6277 for a
:= A_BULLETS
to A_HIGH
do FAmmo
[a
] := 30000;
6278 FRulez
:= FRulez
+[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
];
6281 procedure TPlayer
.RestoreHealthArmor();
6283 FHealth
:= PLAYER_HP_LIMIT
;
6284 FArmor
:= PLAYER_AP_LIMIT
;
6287 procedure TPlayer
.FragCombo();
6291 if (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) or g_Game_IsClient
then
6293 if gTime
- FLastFrag
< FRAG_COMBO_TIME
then
6295 if FFragCombo
< 5 then
6297 Param
:= FUID
or (FFragCombo
shl 16);
6298 if (FComboEvnt
>= Low(gDelayedEvents
)) and
6299 (FComboEvnt
<= High(gDelayedEvents
)) and
6300 gDelayedEvents
[FComboEvnt
].Pending
and
6301 (gDelayedEvents
[FComboEvnt
].DEType
= DE_KILLCOMBO
) and
6302 (gDelayedEvents
[FComboEvnt
].DENum
and $FFFF = FUID
) then
6304 gDelayedEvents
[FComboEvnt
].Time
:= gTime
+ 500;
6305 gDelayedEvents
[FComboEvnt
].DENum
:= Param
;
6308 FComboEvnt
:= g_Game_DelayEvent(DE_KILLCOMBO
, 500, Param
);
6316 procedure TPlayer
.GiveItem(ItemType
: Byte);
6320 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
6322 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
6326 if FAir
< AIR_MAX
then
6333 if not (R_BERSERK
in FRulez
) then
6335 Include(FRulez
, R_BERSERK
);
6336 if FBFGFireCounter
< 1 then
6338 FCurrWeap
:= WEAPON_KASTET
;
6340 FModel
.SetWeapon(WEAPON_KASTET
);
6344 FBerserk
:= gTime
+30000;
6346 if FHealth
< PLAYER_HP_SOFT
then
6348 FHealth
:= PLAYER_HP_SOFT
;
6349 FBerserk
:= gTime
+30000;
6354 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
6356 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
6361 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
6363 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
6367 if FJetFuel
< JET_MAX
then
6369 FJetFuel
:= JET_MAX
;
6372 ITEM_MEDKIT_SMALL
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
6373 ITEM_MEDKIT_LARGE
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
6375 ITEM_ARMOR_GREEN
: if FArmor
< PLAYER_AP_SOFT
then FArmor
:= PLAYER_AP_SOFT
;
6376 ITEM_ARMOR_BLUE
: if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
6378 ITEM_SPHERE_BLUE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
6380 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) then
6382 if FHealth
< PLAYER_HP_LIMIT
then FHealth
:= PLAYER_HP_LIMIT
;
6383 if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
6386 ITEM_WEAPON_SAW
: FWeapon
[WEAPON_SAW
] := True;
6387 ITEM_WEAPON_SHOTGUN1
: FWeapon
[WEAPON_SHOTGUN1
] := True;
6388 ITEM_WEAPON_SHOTGUN2
: FWeapon
[WEAPON_SHOTGUN2
] := True;
6389 ITEM_WEAPON_CHAINGUN
: FWeapon
[WEAPON_CHAINGUN
] := True;
6390 ITEM_WEAPON_ROCKETLAUNCHER
: FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
6391 ITEM_WEAPON_PLASMA
: FWeapon
[WEAPON_PLASMA
] := True;
6392 ITEM_WEAPON_BFG
: FWeapon
[WEAPON_BFG
] := True;
6393 ITEM_WEAPON_SUPERPULEMET
: FWeapon
[WEAPON_SUPERPULEMET
] := True;
6394 ITEM_WEAPON_FLAMETHROWER
: FWeapon
[WEAPON_FLAMETHROWER
] := True;
6396 ITEM_AMMO_BULLETS
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
6397 ITEM_AMMO_BULLETS_BOX
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
6398 ITEM_AMMO_SHELLS
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
6399 ITEM_AMMO_SHELLS_BOX
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
6400 ITEM_AMMO_ROCKET
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
6401 ITEM_AMMO_ROCKET_BOX
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
6402 ITEM_AMMO_CELL
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
6403 ITEM_AMMO_CELL_BIG
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
6404 ITEM_AMMO_FUELCAN
: if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
6407 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
6408 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
6409 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
6410 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or
6411 (FMaxAmmo
[A_FUEL
] < AmmoLimits
[1, A_FUEL
]) then
6413 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[1, A_BULLETS
];
6414 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[1, A_SHELLS
];
6415 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[1, A_ROCKETS
];
6416 FMaxAmmo
[A_CELLS
] := AmmoLimits
[1, A_CELLS
];
6417 FMaxAmmo
[A_FUEL
] := AmmoLimits
[1, A_FUEL
];
6419 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
6420 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
6421 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
6422 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
6424 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
6427 ITEM_KEY_RED
: if not (R_KEY_RED
in FRulez
) then Include(FRulez
, R_KEY_RED
);
6428 ITEM_KEY_GREEN
: if not (R_KEY_GREEN
in FRulez
) then Include(FRulez
, R_KEY_GREEN
);
6429 ITEM_KEY_BLUE
: if not (R_KEY_BLUE
in FRulez
) then Include(FRulez
, R_KEY_BLUE
);
6431 ITEM_BOTTLE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
6432 ITEM_HELMET
: if FArmor
< PLAYER_AP_LIMIT
then IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
6437 if g_Game_IsNet
and g_Game_IsServer
then
6438 MH_SEND_PlayerStats(FUID
);
6441 procedure TPlayer
.FlySmoke(Times
: DWORD
= 1);
6446 if (Random(5) = 1) and (Times
= 1) then
6449 if BodyInLiquid(0, 0) then
6451 g_GFX_Bubbles(Obj
.X
+Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2)+Random(3)-1,
6452 Obj
.Y
+Obj
.Rect
.Height
+8, 1, 8, 4);
6453 if Random(2) = 0 then
6454 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
6456 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
6460 if g_Frames_Get(id
, 'FRAMES_SMOKE') then
6462 for i
:= 1 to Times
do
6464 Anim
:= TAnimation
.Create(id
, False, 3);
6466 g_GFX_OnceAnim(Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(Anim
.Width
div 2),
6467 Obj
.Y
+Obj
.Rect
.Height
-4+Random(8+Times
*2), Anim
, ONCEANIM_SMOKE
);
6473 procedure TPlayer
.OnFireFlame(Times
: DWORD
= 1);
6478 if (Random(10) = 1) and (Times
= 1) then
6481 if g_Frames_Get(id
, 'FRAMES_FLAME') then
6483 for i
:= 1 to Times
do
6485 Anim
:= TAnimation
.Create(id
, False, 3);
6487 g_GFX_OnceAnim(Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(Anim
.Width
div 2),
6488 Obj
.Y
+8+Random(8+Times
*2), Anim
, ONCEANIM_SMOKE
);
6494 procedure TPlayer
.PauseSounds(Enable
: Boolean);
6496 FSawSound
.Pause(Enable
);
6497 FSawSoundIdle
.Pause(Enable
);
6498 FSawSoundHit
.Pause(Enable
);
6499 FSawSoundSelect
.Pause(Enable
);
6500 FFlameSoundOn
.Pause(Enable
);
6501 FFlameSoundOff
.Pause(Enable
);
6502 FFlameSoundWork
.Pause(Enable
);
6503 FJetSoundFly
.Pause(Enable
);
6504 FJetSoundOn
.Pause(Enable
);
6505 FJetSoundOff
.Pause(Enable
);
6510 constructor TCorpse
.Create(X
, Y
: Integer; ModelName
: String; aMess
: Boolean);
6515 FObj
.Rect
:= PLAYER_CORPSERECT
;
6516 FModelName
:= ModelName
;
6521 FState
:= CORPSE_STATE_MESS
;
6522 g_PlayerModel_GetAnim(ModelName
, A_DIE2
, FAnimation
, FAnimationMask
);
6526 FState
:= CORPSE_STATE_NORMAL
;
6527 g_PlayerModel_GetAnim(ModelName
, A_DIE1
, FAnimation
, FAnimationMask
);
6531 destructor TCorpse
.Destroy();
6538 function TCorpse
.ObjPtr (): PObj
; inline; begin result
:= @FObj
; end;
6540 procedure TCorpse
.positionChanged (); inline; begin end;
6542 procedure TCorpse
.moveBy (dx
, dy
: Integer); inline;
6544 if (dx
<> 0) or (dy
<> 0) then
6553 procedure TCorpse
.getMapBox (out x
, y
, w
, h
: Integer); inline;
6555 x
:= FObj
.X
+PLAYER_CORPSERECT
.X
;
6556 y
:= FObj
.Y
+PLAYER_CORPSERECT
.Y
;
6557 w
:= PLAYER_CORPSERECT
.Width
;
6558 h
:= PLAYER_CORPSERECT
.Height
;
6562 procedure TCorpse
.Damage(Value
: Word; SpawnerUID
: Word; vx
, vy
: Integer);
6567 if FState
= CORPSE_STATE_REMOVEME
then
6570 FDamage
:= FDamage
+ Value
;
6572 if FDamage
> 150 then
6574 if FAnimation
<> nil then
6579 FState
:= CORPSE_STATE_REMOVEME
;
6581 g_Player_CreateGibs(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
6582 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2),
6583 FModelName
, FColor
);
6584 // Çâóê ìÿñà îò òðóïà:
6585 pm
:= g_PlayerModel_Get(FModelName
);
6586 pm
.PlaySound(MODELSOUND_DIE
, 5, FObj
.X
, FObj
.Y
);
6590 if (gBodyKillEvent
<> -1)
6591 and gDelayedEvents
[gBodyKillEvent
].Pending
then
6592 gDelayedEvents
[gBodyKillEvent
].Pending
:= False;
6593 gBodyKillEvent
:= g_Game_DelayEvent(DE_BODYKILL
, 1050, SpawnerUID
);
6598 Blood
:= g_PlayerModel_GetBlood(FModelName
);
6599 FObj
.Vel
.X
:= FObj
.Vel
.X
+ vx
;
6600 FObj
.Vel
.Y
:= FObj
.Vel
.Y
+ vy
;
6601 g_GFX_Blood(FObj
.X
+PLAYER_CORPSERECT
.X
+(PLAYER_CORPSERECT
.Width
div 2),
6602 FObj
.Y
+PLAYER_CORPSERECT
.Y
+(PLAYER_CORPSERECT
.Height
div 2),
6603 Value
, vx
, vy
, 16, (PLAYER_CORPSERECT
.Height
*2) div 3,
6604 Blood
.R
, Blood
.G
, Blood
.B
, Blood
.Kind
);
6608 procedure TCorpse
.Draw();
6612 if FState
= CORPSE_STATE_REMOVEME
then
6615 FObj
.lerp(gLerpFactor
, fX
, fY
);
6617 if FAnimation
<> nil then
6618 FAnimation
.Draw(fX
, fY
, TMirrorType
.None
);
6620 if FAnimationMask
<> nil then
6623 FAnimationMask
.Draw(fX
, fY
, TMirrorType
.None
);
6630 procedure TCorpse
.Update();
6634 if FState
= CORPSE_STATE_REMOVEME
then
6637 FObj
.oldX
:= FObj
.X
;
6638 FObj
.oldY
:= FObj
.Y
;
6640 if gTime
mod (GAME_TICK
*2) <> 0 then
6642 g_Obj_Move(@FObj
, True, True, True);
6643 positionChanged(); // this updates spatial accelerators
6647 // Ñîïðîòèâëåíèå âîçäóõà äëÿ òðóïà:
6648 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
6650 st
:= g_Obj_Move(@FObj
, True, True, True);
6651 positionChanged(); // this updates spatial accelerators
6653 if WordBool(st
and MOVE_FALLOUT
) then
6655 FState
:= CORPSE_STATE_REMOVEME
;
6659 if FAnimation
<> nil then
6660 FAnimation
.Update();
6661 if FAnimationMask
<> nil then
6662 FAnimationMask
.Update();
6666 procedure TCorpse
.SaveState (st
: TStream
);
6673 utils
.writeSign(st
, 'CORP');
6674 utils
.writeInt(st
, Byte(0));
6676 utils
.writeInt(st
, Byte(FState
));
6678 utils
.writeInt(st
, Byte(FDamage
));
6680 utils
.writeInt(st
, Byte(FColor
.R
));
6681 utils
.writeInt(st
, Byte(FColor
.G
));
6682 utils
.writeInt(st
, Byte(FColor
.B
));
6684 Obj_SaveState(st
, @FObj
);
6685 utils
.writeInt(st
, Word(FPlayerUID
));
6687 anim
:= (FAnimation
<> nil);
6688 utils
.writeBool(st
, anim
);
6689 // Åñëè åñòü - ñîõðàíÿåì
6690 if anim
then FAnimation
.SaveState(st
);
6691 // Åñòü ëè ìàñêà àíèìàöèè
6692 anim
:= (FAnimationMask
<> nil);
6693 utils
.writeBool(st
, anim
);
6694 // Åñëè åñòü - ñîõðàíÿåì
6695 if anim
then FAnimationMask
.SaveState(st
);
6699 procedure TCorpse
.LoadState (st
: TStream
);
6706 if not utils
.checkSign(st
, 'CORP') then raise XStreamError
.Create('invalid corpse signature');
6707 if (utils
.readByte(st
) <> 0) then raise XStreamError
.Create('invalid corpse version');
6709 FState
:= utils
.readByte(st
);
6711 FDamage
:= utils
.readByte(st
);
6713 FColor
.R
:= utils
.readByte(st
);
6714 FColor
.G
:= utils
.readByte(st
);
6715 FColor
.B
:= utils
.readByte(st
);
6717 Obj_LoadState(@FObj
, st
);
6718 FPlayerUID
:= utils
.readWord(st
);
6720 anim
:= utils
.readBool(st
);
6721 // Åñëè åñòü - çàãðóæàåì
6724 Assert(FAnimation
<> nil, 'TCorpse.LoadState: no FAnimation');
6725 FAnimation
.LoadState(st
);
6727 // Åñòü ëè ìàñêà àíèìàöèè
6728 anim
:= utils
.readBool(st
);
6729 // Åñëè åñòü - çàãðóæàåì
6732 Assert(FAnimationMask
<> nil, 'TCorpse.LoadState: no FAnimationMask');
6733 FAnimationMask
.LoadState(st
);
6739 constructor TBot
.Create();
6746 FSpectator
:= False;
6753 for a
:= WP_FIRST
to WP_LAST
do
6755 FDifficult
.WeaponPrior
[a
] := WEAPON_PRIOR1
[a
];
6756 FDifficult
.CloseWeaponPrior
[a
] := WEAPON_PRIOR2
[a
];
6757 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
6761 destructor TBot
.Destroy();
6764 inherited Destroy();
6767 procedure TBot
.Draw();
6771 //if FTargetUID <> 0 then e_DrawLine(1, FObj.X, FObj.Y, g_Player_Get(FTargetUID).FObj.X,
6772 // g_Player_Get(FTargetUID).FObj.Y, 255, 0, 0);
6775 procedure TBot
.Respawn(Silent
: Boolean; Force
: Boolean = False);
6777 inherited Respawn(Silent
, Force
);
6780 FSelectedWeapon
:= FCurrWeap
;
6785 procedure TBot
.UpdateCombat();
6798 TTargetRecord
= array of TTarget
;
6800 function Compare(a
, b
: TTarget
): Integer;
6802 if a
.Line
and not b
.Line
then // A íà ëèíèè îãíÿ
6805 if not a
.Line
and b
.Line
then // B íà ëèíèè îãíÿ
6807 else // È A, è B íà ëèíèè èëè íå íà ëèíèè îãíÿ
6808 if (a
.Line
and b
.Line
) or ((not a
.Line
) and (not b
.Line
)) then
6810 if a
.Dist
> b
.Dist
then // B áëèæå
6812 else // A áëèæå èëè ðàâíîóäàëåííî ñ B
6815 else // Ñòðàííî -> A
6820 a
, x1
, y1
, x2
, y2
: Integer;
6821 targets
: TTargetRecord
;
6823 Target
, BestTarget
: TTarget
;
6824 firew
, fireh
: Integer;
6828 vsPlayer
, vsMonster
, ok
: Boolean;
6831 function monsUpdate (mon
: TMonster
): Boolean;
6833 result
:= false; // don't stop
6834 if mon
.alive
and (mon
.MonsterType
<> MONSTER_BARREL
) then
6836 if not TargetOnScreen(mon
.Obj
.X
+mon
.Obj
.Rect
.X
, mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
) then exit
;
6838 x2
:= mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2);
6839 y2
:= mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+(mon
.Obj
.Rect
.Height
div 2);
6841 // Åñëè ìîíñòð íà ýêðàíå è íå ïðèêðûò ñòåíîé
6842 if g_TraceVector(x1
, y1
, x2
, y2
) then
6844 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé
6845 SetLength(targets
, Length(targets
)+1);
6846 with targets
[High(targets
)] do
6853 Rect
:= mon
.Obj
.Rect
;
6854 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6855 Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6856 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6865 vsPlayer
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
);
6866 vsMonster
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
);
6868 // Åñëè òåêóùåå îðóæèå íå òî, ÷òî íóæíî, òî ìåíÿåì:
6869 if FCurrWeap
<> FSelectedWeapon
then
6872 // Åñëè íóæíî ñòðåëÿòü è íóæíîå îðóæèå, òî íàæàòü "Ñòðåëÿòü":
6873 if (GetAIFlag('NEEDFIRE') <> '') and (FCurrWeap
= FSelectedWeapon
) then
6875 RemoveAIFlag('NEEDFIRE');
6878 WEAPON_PLASMA
, WEAPON_SUPERPULEMET
, WEAPON_CHAINGUN
: PressKey(KEY_FIRE
, 20);
6879 WEAPON_SAW
, WEAPON_KASTET
, WEAPON_FLAMETHROWER
: PressKey(KEY_FIRE
, 40);
6880 else PressKey(KEY_FIRE
);
6884 // Êîîðäèíàòû ñòâîëà:
6885 x1
:= FObj
.X
+ WEAPONPOINT
[FDirection
].X
;
6886 y1
:= FObj
.Y
+ WEAPONPOINT
[FDirection
].Y
;
6888 Target
.UID
:= FTargetUID
;
6891 if Target
.UID
<> 0 then
6892 begin // Öåëü åñòü - íàñòðàèâàåì
6893 if (g_GetUIDType(Target
.UID
) = UID_PLAYER
) and
6896 tpla
:= g_Player_Get(Target
.UID
);
6900 if (@FObj
) <> nil then
6907 Target
.cX
:= Target
.X
+ PLAYER_RECT_CX
;
6908 Target
.cY
:= Target
.Y
+ PLAYER_RECT_CY
;
6909 Target
.Rect
:= PLAYER_RECT
;
6910 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6911 Target
.Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6912 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6913 Target
.IsPlayer
:= True;
6917 if (g_GetUIDType(Target
.UID
) = UID_MONSTER
) and
6920 mon
:= g_Monsters_ByUID(Target
.UID
);
6923 Target
.X
:= mon
.Obj
.X
;
6924 Target
.Y
:= mon
.Obj
.Y
;
6926 Target
.cX
:= Target
.X
+ mon
.Obj
.Rect
.X
+ (mon
.Obj
.Rect
.Width
div 2);
6927 Target
.cY
:= Target
.Y
+ mon
.Obj
.Rect
.Y
+ (mon
.Obj
.Rect
.Height
div 2);
6928 Target
.Rect
:= mon
.Obj
.Rect
;
6929 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6930 Target
.Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6931 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6932 Target
.IsPlayer
:= False;
6939 begin // Öåëè íåò - îáíóëÿåì
6944 Target
.Visible
:= False;
6945 Target
.Line
:= False;
6946 Target
.IsPlayer
:= False;
6951 // Åñëè öåëü íå âèäèìà èëè íå íà ëèíèè îãíÿ, òî èùåì âñå âîçìîæíûå öåëè:
6952 if (not Target
.Line
) or (not Target
.Visible
) then
6956 for a
:= 0 to High(gPlayers
) do
6957 if (gPlayers
[a
] <> nil) and (gPlayers
[a
].alive
) and
6958 (gPlayers
[a
].FUID
<> FUID
) and
6959 (not SameTeam(FUID
, gPlayers
[a
].FUID
)) and
6960 (not gPlayers
[a
].NoTarget
) and
6961 (gPlayers
[a
].FMegaRulez
[MR_INVIS
] < gTime
) then
6963 if not TargetOnScreen(gPlayers
[a
].FObj
.X
+ PLAYER_RECT
.X
,
6964 gPlayers
[a
].FObj
.Y
+ PLAYER_RECT
.Y
) then
6967 x2
:= gPlayers
[a
].FObj
.X
+ PLAYER_RECT_CX
;
6968 y2
:= gPlayers
[a
].FObj
.Y
+ PLAYER_RECT_CY
;
6970 // Åñëè èãðîê íà ýêðàíå è íå ïðèêðûò ñòåíîé:
6971 if g_TraceVector(x1
, y1
, x2
, y2
) then
6973 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé:
6974 SetLength(targets
, Length(targets
)+1);
6975 with targets
[High(targets
)] do
6977 UID
:= gPlayers
[a
].FUID
;
6978 X
:= gPlayers
[a
].FObj
.X
;
6979 Y
:= gPlayers
[a
].FObj
.Y
;
6982 Rect
:= PLAYER_RECT
;
6983 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6984 Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6985 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6993 if vsMonster
then g_Mons_ForEach(monsUpdate
);
6996 // Åñëè åñòü âîçìîæíûå öåëè:
6997 // (Âûáèðàåì ëó÷øóþ, ìåíÿåì îðóæèå è áåæèì ê íåé/îò íåå)
6998 if targets
<> nil then
7000 // Âûáèðàåì íàèëó÷øóþ öåëü:
7001 BestTarget
:= targets
[0];
7002 if Length(targets
) > 1 then
7003 for a
:= 1 to High(targets
) do
7004 if Compare(BestTarget
, targets
[a
]) = 1 then
7005 BestTarget
:= targets
[a
];
7007 // Åñëè ëó÷øàÿ öåëü "âèäíåå" òåêóùåé, òî òåêóùàÿ := ëó÷øàÿ:
7008 if ((not Target
.Visible
) and BestTarget
.Visible
and (Target
.UID
<> BestTarget
.UID
)) or
7009 ((not Target
.Line
) and BestTarget
.Line
and BestTarget
.Visible
) then
7011 Target
:= BestTarget
;
7013 if (Healthy() = 3) or ((Healthy() = 2)) then
7014 begin // Åñëè çäîðîâû - äîãîíÿåì
7015 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
7016 SetAIFlag('GORIGHT', '1');
7017 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
7018 SetAIFlag('GOLEFT', '1');
7021 begin // Åñëè ïîáèòû - óáåãàåì
7022 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) then
7023 SetAIFlag('GORIGHT', '1');
7024 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
7025 SetAIFlag('GOLEFT', '1');
7028 // Âûáèðàåì îðóæèå íà îñíîâå ðàññòîÿíèÿ è ïðèîðèòåòîâ:
7029 SelectWeapon(Abs(x1
-Target
.cX
));
7034 // (Äîãîíÿåì/óáåãàåì, ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëè)
7035 // (Åñëè öåëü äàëåêî, òî õâàòèò ñëåäèòü çà íåé)
7036 if Target
.UID
<> 0 then
7038 if not TargetOnScreen(Target
.X
+ Target
.Rect
.X
,
7039 Target
.Y
+ Target
.Rect
.Y
) then
7040 begin // Öåëü ñáåæàëà ñ "ýêðàíà"
7041 if (Healthy() = 3) or ((Healthy() = 2)) then
7042 begin // Åñëè çäîðîâû - äîãîíÿåì
7043 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
7044 SetAIFlag('GORIGHT', '1');
7045 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
7046 SetAIFlag('GOLEFT', '1');
7049 begin // Åñëè ïîáèòû - çàáûâàåì î öåëè è óáåãàåì
7051 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) then
7052 SetAIFlag('GORIGHT', '1');
7053 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
7054 SetAIFlag('GOLEFT', '1');
7058 begin // Öåëü ïîêà íà "ýêðàíå"
7059 // Åñëè öåëü íå çàãîðîæåíà ñòåíîé, òî îòìå÷àåì, êîãäà åå âèäåëè:
7060 if g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
7061 FLastVisible
:= gTime
;
7062 // Åñëè ðàçíèöà âûñîò íå âåëèêà, òî äîãîíÿåì:
7063 if (Abs(FObj
.Y
-Target
.Y
) <= 128) then
7065 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
7066 SetAIFlag('GORIGHT', '1');
7067 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
7068 SetAIFlag('GOLEFT', '1');
7072 // Âûáèðàåì óãîë ââåðõ:
7073 if FDirection
= TDirection
.D_LEFT
then
7074 angle
:= ANGLE_LEFTUP
7076 angle
:= ANGLE_RIGHTUP
;
7078 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7079 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7081 // Åñëè ïðè óãëå ââåðõ ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
7082 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
7083 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128), //96
7084 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
7085 Target
.Rect
.Width
, Target
.Rect
.Height
) and
7086 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
7087 begin // òî íóæíî ñòðåëÿòü ââåðõ
7088 SetAIFlag('NEEDFIRE', '1');
7089 SetAIFlag('NEEDSEEUP', '1');
7092 // Âûáèðàåì óãîë âíèç:
7093 if FDirection
= TDirection
.D_LEFT
then
7094 angle
:= ANGLE_LEFTDOWN
7096 angle
:= ANGLE_RIGHTDOWN
;
7098 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7099 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7101 // Åñëè ïðè óãëå âíèç ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
7102 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
7103 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
7104 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
7105 Target
.Rect
.Width
, Target
.Rect
.Height
) and
7106 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
7107 begin // òî íóæíî ñòðåëÿòü âíèç
7108 SetAIFlag('NEEDFIRE', '1');
7109 SetAIFlag('NEEDSEEDOWN', '1');
7112 // Åñëè öåëü âèäíî è îíà íà òàêîé æå âûñîòå:
7113 if Target
.Visible
and
7114 (y1
+4 < Target
.Y
+Target
.Rect
.Y
+Target
.Rect
.Height
) and
7115 (y1
-4 > Target
.Y
+Target
.Rect
.Y
) then
7117 // Åñëè èäåì â ñòîðîíó öåëè, òî íàäî ñòðåëÿòü:
7118 if ((FDirection
= TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) or
7119 ((FDirection
= TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
7120 begin // òî íóæíî ñòðåëÿòü âïåðåä
7121 SetAIFlag('NEEDFIRE', '1');
7122 SetAIFlag('NEEDSEEDOWN', '');
7123 SetAIFlag('NEEDSEEUP', '');
7125 // Åñëè öåëü â ïðåäåëàõ "ýêðàíà" è ñëîæíîñòü ïîçâîëÿåò ïðûæêè ñáëèæåíèÿ:
7126 if Abs(FObj
.X
-Target
.X
) < Trunc(gPlayerScreenSize
.X
*0.75) then
7127 if GetRnd(FDifficult
.CloseJump
) then
7128 begin // òî åñëè ïîâåçåò - ïðûãàåì (îñîáåííî, åñëè áëèçêî)
7129 if Abs(FObj
.X
-Target
.X
) < 128 then
7133 if Random(a
) = 0 then
7134 SetAIFlag('NEEDJUMP', '1');
7138 // Åñëè öåëü âñå åùå åñòü:
7139 if Target
.UID
<> 0 then
7140 if gTime
-FLastVisible
> 2000 then // Åñëè âèäåëè äàâíî
7141 Target
.UID
:= 0 // òî çàáûòü öåëü
7142 else // Åñëè âèäåëè íåäàâíî
7143 begin // íî öåëü óáèëè
7144 if Target
.IsPlayer
then
7145 begin // Öåëü - èãðîê
7146 pla
:= g_Player_Get(Target
.UID
);
7147 if (pla
= nil) or (not pla
.alive
) or pla
.NoTarget
or
7148 (pla
.FMegaRulez
[MR_INVIS
] >= gTime
) then
7149 Target
.UID
:= 0; // òî çàáûòü öåëü
7152 begin // Öåëü - ìîíñòð
7153 mon
:= g_Monsters_ByUID(Target
.UID
);
7154 if (mon
= nil) or (not mon
.alive
) then
7155 Target
.UID
:= 0; // òî çàáûòü öåëü
7158 end; // if Target.UID <> 0
7160 FTargetUID
:= Target
.UID
;
7162 // Åñëè âîçìîæíûõ öåëåé íåò:
7163 // (Àòàêà ÷åãî-íèáóäü ñëåâà èëè ñïðàâà)
7164 if targets
= nil then
7165 if GetAIFlag('ATTACKLEFT') <> '' then
7166 begin // Åñëè íóæíî àòàêîâàòü íàëåâî
7167 RemoveAIFlag('ATTACKLEFT');
7169 SetAIFlag('NEEDJUMP', '1');
7171 if RunDirection() = TDirection
.D_RIGHT
then
7172 begin // Èäåì íå â òó ñòîðîíó
7173 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
7174 begin // Åñëè çäîðîâû, òî, âîçìîæíî, ñòðåëÿåì áåæèì âëåâî è ñòðåëÿåì
7175 SetAIFlag('NEEDFIRE', '1');
7176 SetAIFlag('GOLEFT', '1');
7180 begin // Èäåì â íóæíóþ ñòîðîíó
7181 if GetRnd(FDifficult
.InvisFire
) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
7182 SetAIFlag('NEEDFIRE', '1');
7183 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
7184 SetAIFlag('GORIGHT', '1');
7188 if GetAIFlag('ATTACKRIGHT') <> '' then
7189 begin // Åñëè íóæíî àòàêîâàòü íàïðàâî
7190 RemoveAIFlag('ATTACKRIGHT');
7192 SetAIFlag('NEEDJUMP', '1');
7194 if RunDirection() = TDirection
.D_LEFT
then
7195 begin // Èäåì íå â òó ñòîðîíó
7196 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
7197 begin // Åñëè çäîðîâû, òî, âîçìîæíî, áåæèì âïðàâî è ñòðåëÿåì
7198 SetAIFlag('NEEDFIRE', '1');
7199 SetAIFlag('GORIGHT', '1');
7204 if GetRnd(FDifficult
.InvisFire
) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
7205 SetAIFlag('NEEDFIRE', '1');
7206 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
7207 SetAIFlag('GOLEFT', '1');
7211 //HACK! (does it belongs there?)
7212 RealizeCurrentWeapon();
7214 // Åñëè åñòü âîçìîæíûå öåëè:
7215 // (Ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëÿì)
7216 if (targets
<> nil) and (GetAIFlag('NEEDFIRE') <> '') then
7217 for a
:= 0 to High(targets
) do
7219 // Åñëè ìîæåì ñòðåëÿòü ïî äèàãîíàëè:
7220 if GetRnd(FDifficult
.DiagFire
) then
7222 // Èùåì öåëü ñâåðõó è ñòðåëÿåì, åñëè åñòü:
7223 if FDirection
= TDirection
.D_LEFT
then
7224 angle
:= ANGLE_LEFTUP
7226 angle
:= ANGLE_RIGHTUP
;
7228 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7229 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7231 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
7232 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
7233 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
7234 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
7235 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
7237 SetAIFlag('NEEDFIRE', '1');
7238 SetAIFlag('NEEDSEEUP', '1');
7241 // Èùåì öåëü ñíèçó è ñòðåëÿåì, åñëè åñòü:
7242 if FDirection
= TDirection
.D_LEFT
then
7243 angle
:= ANGLE_LEFTDOWN
7245 angle
:= ANGLE_RIGHTDOWN
;
7247 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7248 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7250 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
7251 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
7252 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
7253 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
7254 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
7256 SetAIFlag('NEEDFIRE', '1');
7257 SetAIFlag('NEEDSEEDOWN', '1');
7261 // Åñëè öåëü "ïåðåä íîñîì", òî ñòðåëÿåì:
7262 if targets
[a
].Line
and targets
[a
].Visible
and
7263 (((FDirection
= TDirection
.D_LEFT
) and (targets
[a
].X
< FObj
.X
)) or
7264 ((FDirection
= TDirection
.D_RIGHT
) and (targets
[a
].X
> FObj
.X
))) then
7266 SetAIFlag('NEEDFIRE', '1');
7271 // Åñëè ëåòèò ïóëÿ, òî, âîçìîæíî, ïîäïðûãèâàåì:
7272 if g_Weapon_Danger(FUID
, FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
,
7273 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
,
7274 40+GetInterval(FDifficult
.Cover
, 40)) then
7275 SetAIFlag('NEEDJUMP', '1');
7277 // Åñëè êîí÷èëèñü ïàòîðíû, òî íóæíî ñìåíèòü îðóæèå:
7278 ammo
:= GetAmmoByWeapon(FCurrWeap
);
7279 if ((FCurrWeap
= WEAPON_SHOTGUN2
) and (ammo
< 2)) or
7280 ((FCurrWeap
= WEAPON_BFG
) and (ammo
< 40)) or
7282 SetAIFlag('SELECTWEAPON', '1');
7284 // Åñëè íóæíî ñìåíèòü îðóæèå, òî âûáèðàåì íóæíîå:
7285 if GetAIFlag('SELECTWEAPON') = '1' then
7288 RemoveAIFlag('SELECTWEAPON');
7292 procedure TBot
.Update();
7305 // Ïðîâåðÿåì, îòêëþ÷¸í ëè AI áîòîâ
7306 if (g_debug_BotAIOff
= 1) and (Team
= TEAM_RED
) then
7308 if (g_debug_BotAIOff
= 2) and (Team
= TEAM_BLUE
) then
7310 if g_debug_BotAIOff
= 3 then
7320 RealizeCurrentWeapon();
7327 procedure TBot
.ReleaseKey(Key
: Byte);
7336 function TBot
.KeyPressed(Key
: Word): Boolean;
7338 Result
:= FKeys
[Key
].Pressed
;
7341 function TBot
.GetAIFlag(aName
: String20
): String20
;
7347 aName
:= LowerCase(aName
);
7349 if FAIFlags
<> nil then
7350 for a
:= 0 to High(FAIFlags
) do
7351 if LowerCase(FAIFlags
[a
].Name
) = aName
then
7353 Result
:= FAIFlags
[a
].Value
;
7358 procedure TBot
.RemoveAIFlag(aName
: String20
);
7362 if FAIFlags
= nil then Exit
;
7364 aName
:= LowerCase(aName
);
7366 for a
:= 0 to High(FAIFlags
) do
7367 if LowerCase(FAIFlags
[a
].Name
) = aName
then
7369 if a
<> High(FAIFlags
) then
7370 for b
:= a
to High(FAIFlags
)-1 do
7371 FAIFlags
[b
] := FAIFlags
[b
+1];
7373 SetLength(FAIFlags
, Length(FAIFlags
)-1);
7378 procedure TBot
.SetAIFlag(aName
, fValue
: String20
);
7386 aName
:= LowerCase(aName
);
7388 if FAIFlags
<> nil then
7389 for a
:= 0 to High(FAIFlags
) do
7390 if LowerCase(FAIFlags
[a
].Name
) = aName
then
7396 if ok
then FAIFlags
[a
].Value
:= fValue
7399 SetLength(FAIFlags
, Length(FAIFlags
)+1);
7400 with FAIFlags
[High(FAIFlags
)] do
7408 procedure TBot
.UpdateMove
;
7410 procedure GoLeft(Time
: Word = 1);
7412 ReleaseKey(KEY_LEFT
);
7413 ReleaseKey(KEY_RIGHT
);
7414 PressKey(KEY_LEFT
, Time
);
7415 SetDirection(TDirection
.D_LEFT
);
7418 procedure GoRight(Time
: Word = 1);
7420 ReleaseKey(KEY_LEFT
);
7421 ReleaseKey(KEY_RIGHT
);
7422 PressKey(KEY_RIGHT
, Time
);
7423 SetDirection(TDirection
.D_RIGHT
);
7426 function Rnd(a
: Word): Boolean;
7428 Result
:= Random(a
) = 0;
7431 procedure Turn(Time
: Word = 1200);
7433 if RunDirection() = TDirection
.D_LEFT
then GoRight(Time
) else GoLeft(Time
);
7438 ReleaseKey(KEY_LEFT
);
7439 ReleaseKey(KEY_RIGHT
);
7442 function CanRunLeft(): Boolean;
7444 Result
:= not CollideLevel(-1, 0);
7447 function CanRunRight(): Boolean;
7449 Result
:= not CollideLevel(1, 0);
7452 function CanRun(): Boolean;
7454 if RunDirection() = TDirection
.D_LEFT
then Result
:= CanRunLeft() else Result
:= CanRunRight();
7457 procedure Jump(Time
: Word = 30);
7459 PressKey(KEY_JUMP
, Time
);
7462 function NearHole(): Boolean;
7466 { TODO 5 : Ëåñòíèöû }
7467 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7468 for x
:= 1 to PLAYER_RECT
.Width
do
7469 if (not StayOnStep(x
*sx
, 0)) and
7470 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7471 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7480 function BorderHole(): Boolean;
7484 { TODO 5 : Ëåñòíèöû }
7485 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7486 for x
:= 1 to PLAYER_RECT
.Width
do
7487 if (not StayOnStep(x
*sx
, 0)) and
7488 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7489 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7491 for xx
:= x
to x
+32 do
7492 if CollideLevel(xx
*sx
, PLAYER_RECT
.Height
) then
7502 function NearDeepHole(): Boolean;
7508 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7511 for x
:= 1 to PLAYER_RECT
.Width
do
7512 if (not StayOnStep(x
*sx
, 0)) and
7513 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7514 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7516 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
7518 if CollideLevel(x
*sx
, PLAYER_RECT
.Height
*y
) then Exit
;
7523 end else Result
:= False;
7526 function OverDeepHole(): Boolean;
7533 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
7535 if CollideLevel(0, PLAYER_RECT
.Height
*y
) then Exit
;
7542 function OnGround(): Boolean;
7544 Result
:= StayOnStep(0, 0) or CollideLevel(0, 1);
7547 function OnLadder(): Boolean;
7549 Result
:= FullInStep(0, 0);
7552 function BelowLadder(): Boolean;
7554 Result
:= (FullInStep(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) and
7555 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
7556 (FullInStep(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) and
7557 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
7560 function BelowLiftUp(): Boolean;
7562 Result
:= ((FullInLift(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) = -1) and
7563 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
7564 ((FullInLift(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) = -1) and
7565 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
7568 function OnTopLift(): Boolean;
7570 Result
:= (FullInLift(0, 0) = -1) and (FullInLift(0, -32) = 0);
7573 function CanJumpOver(): Boolean;
7577 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7581 if not CollideLevel(sx
, 0) then Exit
;
7583 for y
:= 1 to BOT_MAXJUMP
do
7584 if CollideLevel(0, -y
) then Exit
else
7585 if not CollideLevel(sx
, -y
) then
7592 function CanJumpUp(Dist
: ShortInt): Boolean;
7599 if CollideLevel(Dist
, 0) then Exit
;
7602 for y
:= 0 to BOT_MAXJUMP
do
7603 if CollideLevel(Dist
, -y
) then
7612 for yy
:= y
+1 to BOT_MAXJUMP
do
7613 if not CollideLevel(Dist
, -yy
) then
7622 for y
:= 0 to BOT_MAXJUMP
do
7623 if CollideLevel(0, -y
) then
7631 if y
< yy
then Exit
;
7636 function IsSafeTrigger(): Boolean;
7641 if gTriggers
= nil then
7643 for a
:= 0 to High(gTriggers
) do
7644 if Collide(gTriggers
[a
].X
,
7647 gTriggers
[a
].Height
) and
7648 (gTriggers
[a
].TriggerType
in [TRIGGER_EXIT
, TRIGGER_CLOSEDOOR
,
7649 TRIGGER_CLOSETRAP
, TRIGGER_TRAP
,
7650 TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
,
7651 TRIGGER_ONOFF
, TRIGGER_SPAWNMONSTER
,
7652 TRIGGER_DAMAGE
, TRIGGER_SHOT
]) then
7657 // Âîçìîæíî, íàæèìàåì êíîïêó:
7658 if Rnd(16) and IsSafeTrigger() then
7661 // Åñëè ïîä ëèôòîì èëè ñòóïåíüêàìè, òî, âîçìîæíî, ïðûãàåì:
7662 if OnLadder() or ((BelowLadder() or BelowLiftUp()) and Rnd(8)) then
7664 ReleaseKey(KEY_LEFT
);
7665 ReleaseKey(KEY_RIGHT
);
7669 // Èäåì âëåâî, åñëè íàäî áûëî:
7670 if GetAIFlag('GOLEFT') <> '' then
7672 RemoveAIFlag('GOLEFT');
7673 if CanRunLeft() then
7677 // Èäåì âïðàâî, åñëè íàäî áûëî:
7678 if GetAIFlag('GORIGHT') <> '' then
7680 RemoveAIFlag('GORIGHT');
7681 if CanRunRight() then
7685 // Åñëè âûëåòåëè çà êàðòó, òî ïðîáóåì âåðíóòüñÿ:
7686 if FObj
.X
< -32 then
7689 if FObj
.X
+32 > gMapInfo
.Width
then
7692 // Ïðûãàåì, åñëè íàäî áûëî:
7693 if GetAIFlag('NEEDJUMP') <> '' then
7696 RemoveAIFlag('NEEDJUMP');
7699 // Ñìîòðèì ââåðõ, åñëè íàäî áûëî:
7700 if GetAIFlag('NEEDSEEUP') <> '' then
7703 ReleaseKey(KEY_DOWN
);
7704 PressKey(KEY_UP
, 20);
7705 RemoveAIFlag('NEEDSEEUP');
7708 // Ñìîòðèì âíèç, åñëè íàäî áûëî:
7709 if GetAIFlag('NEEDSEEDOWN') <> '' then
7712 ReleaseKey(KEY_DOWN
);
7713 PressKey(KEY_DOWN
, 20);
7714 RemoveAIFlag('NEEDSEEDOWN');
7717 // Åñëè íóæíî áûëî â äûðó è ìû íå íà çåìëå, òî ïîêîðíî ëåòèì:
7718 if GetAIFlag('GOINHOLE') <> '' then
7719 if not OnGround() then
7721 ReleaseKey(KEY_LEFT
);
7722 ReleaseKey(KEY_RIGHT
);
7723 RemoveAIFlag('GOINHOLE');
7724 SetAIFlag('FALLINHOLE', '1');
7727 // Åñëè ïàäàëè è äîñòèãëè çåìëè, òî õâàòèò ïàäàòü:
7728 if GetAIFlag('FALLINHOLE') <> '' then
7730 RemoveAIFlag('FALLINHOLE');
7732 // Åñëè ëåòåëè ïðÿìî è ñåé÷àñ íå íà ëåñòíèöå èëè íà âåðøèíå ëèôòà, òî îòõîäèì â ñòîðîíó:
7733 if not (KeyPressed(KEY_LEFT
) or KeyPressed(KEY_RIGHT
)) then
7734 if GetAIFlag('FALLINHOLE') = '' then
7735 if (not OnLadder()) or (FObj
.Vel
.Y
>= 0) or (OnTopLift()) then
7741 // Åñëè íà çåìëå è ìîæíî ïîäïðûãíóòü, òî, âîçìîæíî, ïðûãàåì:
7743 CanJumpUp(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*32) and
7747 // Åñëè íà çåìëå è âîçëå äûðû (ãëóáèíà > 2 ðîñòîâ èãðîêà):
7748 if OnGround() and NearHole() then
7749 if NearDeepHole() then // Åñëè ýòî áåçäíà
7751 0..3: Turn(); // Áåæèì îáðàòíî
7752 4: Jump(); // Ïðûãàåì
7753 5: begin // Ïðûãàåì îáðàòíî
7758 else // Ýòî íå áåçäíà è ìû åùå íå ëåòèì òóäà
7759 if GetAIFlag('GOINHOLE') = '' then
7761 0: Turn(); // Íå íóæíî òóäà
7762 1: Jump(); // Âäðóã ïîâåçåò - ïðûãàåì
7763 else // Åñëè ÿìà ñ ãðàíèöåé, òî ïðè ñëó÷àå ìîæíî òóäà ïðûãíóòü
7764 if BorderHole() then
7765 SetAIFlag('GOINHOLE', '1');
7768 // Åñëè íà çåìëå, íî íåêóäà èäòè:
7769 if (not CanRun()) and OnGround() then
7771 // Åñëè ìû íà ëåñòíèöå èëè ìîæíî ïåðåïðûãíóòü, òî ïðûãàåì:
7772 if CanJumpOver() or OnLadder() then
7774 else // èíà÷å ïîïûòàåìñÿ â äðóãóþ ñòîðîíó
7775 if Random(2) = 0 then
7777 if IsSafeTrigger() then
7783 // Îñòàëîñü ìàëî âîçäóõà:
7784 if FAir
< 36 * 2 then
7787 // Âûáèðàåìñÿ èç êèñëîòû, åñëè íåò êîñòþìà, îáîæãëèñü, èëè ìàëî çäîðîâüÿ:
7788 if (FMegaRulez
[MR_SUIT
] < gTime
) and ((FLastHit
= HIT_ACID
) or (Healthy() <= 1)) then
7789 if BodyInAcid(0, 0) then
7793 function TBot
.FullInStep(XInc
, YInc
: Integer): Boolean;
7795 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
7796 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_STEP
, False);
7799 {function TBot.NeedItem(Item: Byte): Byte;
7804 procedure TBot
.SelectWeapon(Dist
: Integer);
7808 function HaveAmmo(weapon
: Byte): Boolean;
7811 WEAPON_PISTOL
: Result
:= FAmmo
[A_BULLETS
] >= 1;
7812 WEAPON_SHOTGUN1
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7813 WEAPON_SHOTGUN2
: Result
:= FAmmo
[A_SHELLS
] >= 2;
7814 WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
] >= 10;
7815 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
] >= 1;
7816 WEAPON_PLASMA
: Result
:= FAmmo
[A_CELLS
] >= 10;
7817 WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
] >= 40;
7818 WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7819 WEAPON_FLAMETHROWER
: Result
:= FAmmo
[A_FUEL
] >= 1;
7820 else Result
:= True;
7825 if Dist
= -1 then Dist
:= BOT_LONGDIST
;
7827 if Dist
> BOT_LONGDIST
then
7828 begin // Äàëüíèé áîé
7830 if FWeapon
[FDifficult
.WeaponPrior
[a
]] and HaveAmmo(FDifficult
.WeaponPrior
[a
]) then
7832 FSelectedWeapon
:= FDifficult
.WeaponPrior
[a
];
7836 else //if Dist > BOT_UNSAFEDIST then
7837 begin // Áëèæíèé áîé
7839 if FWeapon
[FDifficult
.CloseWeaponPrior
[a
]] and HaveAmmo(FDifficult
.CloseWeaponPrior
[a
]) then
7841 FSelectedWeapon
:= FDifficult
.CloseWeaponPrior
[a
];
7848 if FWeapon[FDifficult.SafeWeaponPrior[a]] and HaveAmmo(FDifficult.SafeWeaponPrior[a]) then
7850 FSelectedWeapon := FDifficult.SafeWeaponPrior[a];
7856 function TBot
.PickItem(ItemType
: Byte; force
: Boolean; var remove
: Boolean): Boolean;
7858 Result
:= inherited PickItem(ItemType
, force
, remove
);
7860 if Result
then SetAIFlag('SELECTWEAPON', '1');
7863 function TBot
.Heal(value
: Word; Soft
: Boolean): Boolean;
7865 Result
:= inherited Heal(value
, Soft
);
7868 function TBot
.Healthy(): Byte;
7870 if FMegaRulez
[MR_INVUL
] >= gTime
then Result
:= 3
7871 else if (FHealth
> 80) or ((FHealth
> 50) and (FArmor
> 20)) then Result
:= 3
7872 else if (FHealth
> 50) then Result
:= 2
7873 else if (FHealth
> 20) then Result
:= 1
7877 function TBot
.TargetOnScreen(TX
, TY
: Integer): Boolean;
7879 Result
:= (Abs(FObj
.X
-TX
) <= Trunc(gPlayerScreenSize
.X
*0.6)) and
7880 (Abs(FObj
.Y
-TY
) <= Trunc(gPlayerScreenSize
.Y
*0.6));
7883 procedure TBot
.OnDamage(Angle
: SmallInt);
7891 if (Angle
= 0) or (Angle
= 180) then
7894 if (g_GetUIDType(FLastSpawnerUID
) = UID_PLAYER
) and
7895 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
) then
7897 pla
:= g_Player_Get(FLastSpawnerUID
);
7898 ok
:= not TargetOnScreen(pla
.FObj
.X
+ PLAYER_RECT
.X
,
7899 pla
.FObj
.Y
+ PLAYER_RECT
.Y
);
7902 if (g_GetUIDType(FLastSpawnerUID
) = UID_MONSTER
) and
7903 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
) then
7905 mon
:= g_Monsters_ByUID(FLastSpawnerUID
);
7906 ok
:= not TargetOnScreen(mon
.Obj
.X
+ mon
.Obj
.Rect
.X
,
7907 mon
.Obj
.Y
+ mon
.Obj
.Rect
.Y
);
7912 SetAIFlag('ATTACKLEFT', '1')
7914 SetAIFlag('ATTACKRIGHT', '1');
7918 function TBot
.RunDirection(): TDirection
;
7920 if Abs(Vel
.X
) >= 1 then
7922 if Vel
.X
> 0 then Result
:= TDirection
.D_RIGHT
else Result
:= TDirection
.D_LEFT
;
7924 Result
:= FDirection
;
7927 function TBot
.GetRnd(a
: Byte): Boolean;
7929 if a
= 0 then Result
:= False
7930 else if a
= 255 then Result
:= True
7931 else Result
:= Random(256) > 255-a
;
7934 function TBot
.GetInterval(a
: Byte; radius
: SmallInt): SmallInt;
7936 Result
:= Round((255-a
)/255*radius
*(Random(2)-1));
7940 procedure TDifficult
.save (st
: TStream
);
7942 utils
.writeInt(st
, Byte(DiagFire
));
7943 utils
.writeInt(st
, Byte(InvisFire
));
7944 utils
.writeInt(st
, Byte(DiagPrecision
));
7945 utils
.writeInt(st
, Byte(FlyPrecision
));
7946 utils
.writeInt(st
, Byte(Cover
));
7947 utils
.writeInt(st
, Byte(CloseJump
));
7948 st
.WriteBuffer(WeaponPrior
[Low(WeaponPrior
)], sizeof(WeaponPrior
));
7949 st
.WriteBuffer(CloseWeaponPrior
[Low(CloseWeaponPrior
)], sizeof(CloseWeaponPrior
));
7952 procedure TDifficult
.load (st
: TStream
);
7954 DiagFire
:= utils
.readByte(st
);
7955 InvisFire
:= utils
.readByte(st
);
7956 DiagPrecision
:= utils
.readByte(st
);
7957 FlyPrecision
:= utils
.readByte(st
);
7958 Cover
:= utils
.readByte(st
);
7959 CloseJump
:= utils
.readByte(st
);
7960 st
.ReadBuffer(WeaponPrior
[Low(WeaponPrior
)], sizeof(WeaponPrior
));
7961 st
.ReadBuffer(CloseWeaponPrior
[Low(CloseWeaponPrior
)], sizeof(CloseWeaponPrior
));
7965 procedure TBot
.SaveState (st
: TStream
);
7970 inherited SaveState(st
);
7971 utils
.writeSign(st
, 'BOT0');
7973 utils
.writeInt(st
, Byte(FSelectedWeapon
));
7975 utils
.writeInt(st
, Word(FTargetUID
));
7976 // Âðåìÿ ïîòåðè öåëè
7977 utils
.writeInt(st
, LongWord(FLastVisible
));
7978 // Êîëè÷åñòâî ôëàãîâ ÈÈ
7979 dw
:= Length(FAIFlags
);
7980 utils
.writeInt(st
, LongInt(dw
));
7982 for i
:= 0 to dw
-1 do
7984 utils
.writeStr(st
, FAIFlags
[i
].Name
, 20);
7985 utils
.writeStr(st
, FAIFlags
[i
].Value
, 20);
7987 // Íàñòðîéêè ñëîæíîñòè
7988 FDifficult
.save(st
);
7992 procedure TBot
.LoadState (st
: TStream
);
7997 inherited LoadState(st
);
7998 if not utils
.checkSign(st
, 'BOT0') then raise XStreamError
.Create('invalid bot signature');
8000 FSelectedWeapon
:= utils
.readByte(st
);
8002 FTargetUID
:= utils
.readWord(st
);
8003 // Âðåìÿ ïîòåðè öåëè
8004 FLastVisible
:= utils
.readLongWord(st
);
8005 // Êîëè÷åñòâî ôëàãîâ ÈÈ
8006 dw
:= utils
.readLongInt(st
);
8007 if (dw
< 0) or (dw
> 16384) then raise XStreamError
.Create('invalid number of bot AI flags');
8008 SetLength(FAIFlags
, dw
);
8010 for i
:= 0 to dw
-1 do
8012 FAIFlags
[i
].Name
:= utils
.readStr(st
, 20);
8013 FAIFlags
[i
].Value
:= utils
.readStr(st
, 20);
8015 // Íàñòðîéêè ñëîæíîñòè
8016 FDifficult
.load(st
);
8021 conRegVar('cheat_berserk_autoswitch', @gBerserkAutoswitch
, 'autoswitch to fist when berserk pack taken', '', true, true);
8022 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');
8023 conRegVar('player_indicator_style', @gPlayerIndicatorStyle
, 'Visual appearance of indicator', 'Visual appearance of indicator');