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;
244 procedure doDamage (v
: Integer);
246 function refreshCorpse(): Boolean;
249 FDamageBuffer
: Integer;
251 FAmmo
: Array [A_BULLETS
..A_HIGH
] of Word;
252 FMaxAmmo
: Array [A_BULLETS
..A_HIGH
] of Word;
253 FWeapon
: Array [WP_FIRST
..WP_LAST
] of Boolean;
254 FRulez
: Set of R_ITEM_BACKPACK
..R_BERSERK
;
256 FMegaRulez
: Array [MR_SUIT
..MR_MAX
] of DWORD
;
257 FReloading
: Array [WP_FIRST
..WP_LAST
] of Word;
258 FTime
: Array [T_RESPAWN
..T_FLAGCAP
] of DWORD
;
259 FKeys
: Array [KEY_LEFT
..KEY_CHAT
] of TKeyState
;
261 FPreferredTeam
: Byte;
264 FWantsInGame
: Boolean;
269 FActualModelName
: string;
276 FSpawnInvul
: Integer;
278 FWaitForFirstSpawn
: Boolean; // set to `true` in server, used to spawn a player on first full state request
281 // debug: viewport offset
282 viewPortX
, viewPortY
, viewPortW
, viewPortH
: Integer;
284 function isValidViewPort (): Boolean; inline;
286 constructor Create(); virtual;
287 destructor Destroy(); override;
288 procedure Respawn(Silent
: Boolean; Force
: Boolean = False); virtual;
289 function GetRespawnPoint(): Byte;
290 procedure PressKey(Key
: Byte; Time
: Word = 1);
291 procedure ReleaseKeys();
292 procedure SetModel(ModelName
: String);
293 procedure SetColor(Color
: TRGB
);
294 function GetColor(): TRGB
;
295 procedure SetWeapon(W
: Byte);
296 function IsKeyPressed(K
: Byte): Boolean;
297 function GetKeys(): Byte;
298 function PickItem(ItemType
: Byte; arespawn
: Boolean; var remove
: Boolean): Boolean; virtual;
299 function Collide(X
, Y
: Integer; Width
, Height
: Word): Boolean; overload
;
300 function Collide(Panel
: TPanel
): Boolean; overload
;
301 function Collide(X
, Y
: Integer): Boolean; overload
;
302 procedure SetDirection(Direction
: TDirection
);
303 procedure GetSecret();
304 function TeleportTo(X
, Y
: Integer; silent
: Boolean; dir
: Byte): Boolean;
306 procedure Push(vx
, vy
: Integer);
307 procedure ChangeModel(ModelName
: String);
308 procedure SwitchTeam
;
309 procedure ChangeTeam(Team
: Byte);
311 function GetFlag(Flag
: Byte): Boolean;
312 procedure SetFlag(Flag
: Byte);
313 function DropFlag(Silent
: Boolean = True): Boolean;
314 procedure AllRulez(Health
: Boolean);
315 procedure RestoreHealthArmor();
316 procedure FragCombo();
317 procedure GiveItem(ItemType
: Byte);
318 procedure Damage(value
: Word; SpawnerUID
: Word; vx
, vy
: Integer; t
: Byte); virtual;
319 function Heal(value
: Word; Soft
: Boolean): Boolean; virtual;
320 procedure MakeBloodVector(Count
: Word; VelX
, VelY
: Integer);
321 procedure MakeBloodSimple(Count
: Word);
322 procedure Kill(KillType
: Byte; SpawnerUID
: Word; t
: Byte);
323 procedure Reset(Force
: Boolean);
324 procedure Spectate(NoMove
: Boolean = False);
325 procedure SwitchNoClip
;
326 procedure SoftReset();
327 procedure Draw(); virtual;
328 procedure DrawPain();
329 procedure DrawPickup();
330 procedure DrawRulez();
332 procedure DrawIndicator(Color
: TRGB
);
333 procedure DrawBubble();
335 procedure PreUpdate();
336 procedure Update(); virtual;
337 procedure RememberState();
338 procedure RecallState();
339 procedure SaveState (st
: TStream
); virtual;
340 procedure LoadState (st
: TStream
); virtual;
341 procedure PauseSounds(Enable
: Boolean);
342 procedure NetFire(Wpn
: Byte; X
, Y
, AX
, AY
: Integer; WID
: Integer = -1);
343 procedure DoLerp(Level
: Integer = 2);
344 procedure SetLerp(XTo
, YTo
: Integer);
345 procedure ProcessWeaponAction(Action
: Byte);
346 procedure QueueWeaponSwitch(Weapon
: Byte);
347 procedure RealizeCurrentWeapon();
351 procedure JetpackOff
;
352 procedure CatchFire(Attacker
: Word; Timeout
: Integer = PLAYER_BURN_TIME
);
354 //WARNING! this does nothing for now, but still call it!
355 procedure positionChanged (); //WARNING! call this after entity position was changed, or coldet will not work right!
357 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
358 procedure moveBy (dx
, dy
: Integer); inline;
360 function getCameraObj(): TObj
;
363 property Vel
: TPoint2i read FObj
.Vel
;
364 property Obj
: TObj read FObj
;
366 property Name
: String read FName write FName
;
367 property Model
: TPlayerModel read FModel
;
368 property Health
: Integer read FHealth write FHealth
;
369 property Lives
: Byte read FLives write FLives
;
370 property Armor
: Integer read FArmor write FArmor
;
371 property Air
: Integer read FAir write FAir
;
372 property JetFuel
: Integer read FJetFuel write FJetFuel
;
373 property Frags
: Integer read FFrags write FFrags
;
374 property Death
: Integer read FDeath write FDeath
;
375 property Kills
: Integer read FKills write FKills
;
376 property CurrWeap
: Byte read FCurrWeap write FCurrWeap
;
377 property MonsterKills
: Integer read FMonsterKills write FMonsterKills
;
378 property Secrets
: Integer read FSecrets
;
379 property GodMode
: Boolean read FGodMode write FGodMode
;
380 property NoTarget
: Boolean read FNoTarget write FNoTarget
;
381 property NoReload
: Boolean read FNoReload write FNoReload
;
382 property alive
: Boolean read FAlive write FAlive
;
383 property Flag
: Byte read FFlag
;
384 property Team
: Byte read FTeam write FTeam
;
385 property Direction
: TDirection read FDirection
;
386 property GameX
: Integer read FObj
.X write FObj
.X
;
387 property GameY
: Integer read FObj
.Y write FObj
.Y
;
388 property GameVelX
: Integer read FObj
.Vel
.X write FObj
.Vel
.X
;
389 property GameVelY
: Integer read FObj
.Vel
.Y write FObj
.Vel
.Y
;
390 property GameAccelX
: Integer read FObj
.Accel
.X write FObj
.Accel
.X
;
391 property GameAccelY
: Integer read FObj
.Accel
.Y write FObj
.Accel
.Y
;
392 property IncCam
: Integer read FIncCam write FIncCam
;
393 property IncCamOld
: Integer read FIncCamOld write FIncCamOld
;
394 property SlopeOld
: Integer read FSlopeOld write FSlopeOld
;
395 property UID
: Word read FUID write FUID
;
396 property JustTeleported
: Boolean read FJustTeleported write FJustTeleported
;
397 property NetTime
: LongWord read FNetTime write FNetTime
;
400 property eName
: String read FName write FName
;
401 property eHealth
: Integer read FHealth write FHealth
;
402 property eLives
: Byte read FLives write FLives
;
403 property eArmor
: Integer read FArmor write FArmor
;
404 property eAir
: Integer read FAir write FAir
;
405 property eJetFuel
: Integer read FJetFuel write FJetFuel
;
406 property eFrags
: Integer read FFrags write FFrags
;
407 property eDeath
: Integer read FDeath write FDeath
;
408 property eKills
: Integer read FKills write FKills
;
409 property eCurrWeap
: Byte read FCurrWeap write FCurrWeap
;
410 property eMonsterKills
: Integer read FMonsterKills write FMonsterKills
;
411 property eSecrets
: Integer read FSecrets write FSecrets
;
412 property eGodMode
: Boolean read FGodMode write FGodMode
;
413 property eNoTarget
: Boolean read FNoTarget write FNoTarget
;
414 property eNoReload
: Boolean read FNoReload write FNoReload
;
415 property eAlive
: Boolean read FAlive write FAlive
;
416 property eFlag
: Byte read FFlag
;
417 property eTeam
: Byte read FTeam write FTeam
;
418 property eDirection
: TDirection read FDirection
;
419 property eGameX
: Integer read FObj
.X write FObj
.X
;
420 property eGameY
: Integer read FObj
.Y write FObj
.Y
;
421 property eGameVelX
: Integer read FObj
.Vel
.X write FObj
.Vel
.X
;
422 property eGameVelY
: Integer read FObj
.Vel
.Y write FObj
.Vel
.Y
;
423 property eGameAccelX
: Integer read FObj
.Accel
.X write FObj
.Accel
.X
;
424 property eGameAccelY
: Integer read FObj
.Accel
.Y write FObj
.Accel
.Y
;
425 property eIncCam
: Integer read FIncCam write FIncCam
;
426 property eUID
: Word read FUID
;
427 property eJustTeleported
: Boolean read FJustTeleported
;
428 property eNetTime
: LongWord read FNetTime
;
430 // set this before assigning something to `eDamage`
431 property eDamageType
: Integer read mEDamageType write mEDamageType
;
432 property eDamage
: Integer write doDamage
;
443 WeaponPrior
: packed array [WP_FIRST
..WP_LAST
] of Byte;
444 CloseWeaponPrior
: packed array [WP_FIRST
..WP_LAST
] of Byte;
445 //SafeWeaponPrior: Array [WP_FIRST..WP_LAST] of Byte;
448 procedure save (st
: TStream
);
449 procedure load (st
: TStream
);
457 TBot
= class(TPlayer
)
459 FSelectedWeapon
: Byte;
462 FAIFlags
: Array of TAIFlag
;
463 FDifficult
: TDifficult
;
465 function GetRnd(a
: Byte): Boolean;
466 function GetInterval(a
: Byte; radius
: SmallInt): SmallInt;
467 function RunDirection(): TDirection
;
468 function FullInStep(XInc
, YInc
: Integer): Boolean;
469 //function NeedItem(Item: Byte): Byte;
470 procedure SelectWeapon(Dist
: Integer);
471 procedure SetAIFlag(aName
, fValue
: String20
);
472 function GetAIFlag(aName
: String20
): String20
;
473 procedure RemoveAIFlag(aName
: String20
);
474 function Healthy(): Byte;
475 procedure UpdateMove();
476 procedure UpdateCombat();
477 function KeyPressed(Key
: Word): Boolean;
478 procedure ReleaseKey(Key
: Byte);
479 function TargetOnScreen(TX
, TY
: Integer): Boolean;
480 procedure OnDamage(Angle
: SmallInt); override;
483 procedure Respawn(Silent
: Boolean; Force
: Boolean = False); override;
484 constructor Create(); override;
485 destructor Destroy(); override;
486 procedure Draw(); override;
487 function PickItem(ItemType
: Byte; force
: Boolean; var remove
: Boolean): Boolean; override;
488 function Heal(value
: Word; Soft
: Boolean): Boolean; override;
489 procedure Update(); override;
490 procedure SaveState (st
: TStream
); override;
491 procedure LoadState (st
: TStream
); override;
503 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
504 procedure moveBy (dx
, dy
: Integer); inline;
506 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
520 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
521 procedure moveBy (dx
, dy
: Integer); inline;
523 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
526 TCorpse
= class{$IFDEF USE_MEMPOOL}(TPoolObject
){$ENDIF}
535 FAnimation
: TAnimation
;
536 FAnimationMask
: TAnimation
;
539 constructor Create(X
, Y
: Integer; ModelName
: String; aMess
: Boolean);
540 destructor Destroy(); override;
541 procedure Damage(Value
: Word; SpawnerUID
: Word; vx
, vy
: Integer);
544 procedure SaveState (st
: TStream
);
545 procedure LoadState (st
: TStream
);
547 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
548 procedure moveBy (dx
, dy
: Integer); inline;
550 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
552 function ObjPtr (): PObj
; inline;
554 property Obj
: TObj read FObj
; // copies object
555 property State
: Byte read FState
;
556 property Mess
: Boolean read FMess
;
559 TTeamStat
= Array [TEAM_RED
..TEAM_BLUE
] of
565 gPlayers
: Array of TPlayer
;
566 gCorpses
: Array of TCorpse
;
567 gGibs
: Array of TGib
;
568 gShells
: Array of TShell
;
569 gTeamStat
: TTeamStat
;
570 gFly
: Boolean = False;
571 gAimLine
: Boolean = False;
572 gChatBubble
: Integer = 0;
573 gPlayerIndicator
: Integer = 1;
574 gPlayerIndicatorStyle
: Integer = 0;
576 gSpectLatchPID1
: Word = 0;
577 gSpectLatchPID2
: Word = 0;
578 MAX_RUNVEL
: Integer = 8;
579 VEL_JUMP
: Integer = 10;
580 SHELL_TIMEOUT
: Cardinal = 60000;
582 function Lerp(X
, Y
, Factor
: Integer): Integer;
584 procedure g_Gibs_SetMax(Count
: Word);
585 function g_Gibs_GetMax(): Word;
586 procedure g_Corpses_SetMax(Count
: Word);
587 function g_Corpses_GetMax(): Word;
588 procedure g_Shells_SetMax(Count
: Word);
589 function g_Shells_GetMax(): Word;
591 procedure g_Player_Init();
592 procedure g_Player_Free();
593 function g_Player_Create(ModelName
: String; Color
: TRGB
; Team
: Byte; Bot
: Boolean): Word;
594 function g_Player_CreateFromState (st
: TStream
): Word;
595 procedure g_Player_Remove(UID
: Word);
596 procedure g_Player_ResetTeams();
597 procedure g_Player_PreUpdate();
598 procedure g_Player_UpdateAll();
599 procedure g_Player_DrawAll();
600 procedure g_Player_DrawDebug(p
: TPlayer
);
601 procedure g_Player_DrawHealth();
602 procedure g_Player_RememberAll();
603 procedure g_Player_ResetAll(Force
, Silent
: Boolean);
604 function g_Player_Get(UID
: Word): TPlayer
;
605 function g_Player_GetCount(): Byte;
606 function g_Player_GetStats(): TPlayerStatArray
;
607 function g_Player_ValidName(Name
: String): Boolean;
608 function g_Player_CreateCorpse(Player
: TPlayer
): Integer;
609 procedure g_Player_CreateGibs(fX
, fY
: Integer; ModelName
: String; fColor
: TRGB
);
610 procedure g_Player_CreateShell(fX
, fY
, dX
, dY
: Integer; T
: Byte);
611 procedure g_Player_UpdatePhysicalObjects();
612 procedure g_Player_DrawCorpses();
613 procedure g_Player_DrawShells();
614 procedure g_Player_RemoveAllCorpses();
615 procedure g_Player_Corpses_SaveState (st
: TStream
);
616 procedure g_Player_Corpses_LoadState (st
: TStream
);
617 procedure g_Player_ResetReady();
618 procedure g_Bot_Add(Team
, Difficult
: Byte; Handicap
: Integer = 100);
619 procedure g_Bot_AddList(Team
: Byte; lname
: ShortString; num
: Integer = -1; Handicap
: Integer = 100);
620 procedure g_Bot_MixNames();
621 procedure g_Bot_RemoveAll();
626 {$INCLUDE ../nogl/noGLuses.inc}
627 {$IFDEF ENABLE_HOLMES}
630 e_log
, g_map
, g_items
, g_console
, g_gfx
, Math
,
631 g_options
, g_triggers
, g_menu
, g_game
, g_grid
, e_res
,
632 wadreader
, g_main
, g_monsters
, CONFIG
, g_language
,
633 g_net
, g_netmsg
, g_window
,
636 const PLR_SAVE_VERSION
= 0;
646 diag_precision
: Byte;
650 w_prior1
: Array [WP_FIRST
..WP_LAST
] of Byte;
651 w_prior2
: Array [WP_FIRST
..WP_LAST
] of Byte;
652 w_prior3
: Array [WP_FIRST
..WP_LAST
] of Byte;
656 TIME_RESPAWN1
= 1500;
657 TIME_RESPAWN2
= 2000;
658 TIME_RESPAWN3
= 3000;
661 JET_MAX
= 540; // ~30 sec
662 PLAYER_SUIT_TIME
= 30000;
663 PLAYER_INVUL_TIME
= 30000;
664 PLAYER_INVIS_TIME
= 35000;
665 FRAG_COMBO_TIME
= 3000;
669 ANGLE_RIGHTDOWN
= -35;
671 ANGLE_LEFTDOWN
= -145;
672 PLAYER_HEADRECT
: TRectWH
= (X
:24; Y
:12; Width
:20; Height
:12);
673 WEAPONPOINT
: Array [TDirection
] of TDFPoint
= ((X
:16; Y
:32), (X
:47; Y
:32));
676 BOT_UNSAFEDIST
= 128;
677 TEAMCOLOR
: Array [TEAM_RED
..TEAM_BLUE
] of TRGB
= ((R
:255; G
:0; B
:0),
679 DIFFICULT_EASY
: TDifficult
= (DiagFire
: 32; InvisFire
: 32; DiagPrecision
: 32;
680 FlyPrecision
: 32; Cover
: 32; CloseJump
: 32;
681 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
682 DIFFICULT_MEDIUM
: TDifficult
= (DiagFire
: 127; InvisFire
: 127; DiagPrecision
: 127;
683 FlyPrecision
: 127; Cover
: 127; CloseJump
: 127;
684 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
685 DIFFICULT_HARD
: TDifficult
= (DiagFire
: 255; InvisFire
: 255; DiagPrecision
: 255;
686 FlyPrecision
: 255; Cover
: 255; CloseJump
: 255;
687 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
688 WEAPON_PRIOR1
: Array [WP_FIRST
..WP_LAST
] of Byte =
689 (WEAPON_FLAMETHROWER
, WEAPON_SUPERPULEMET
,
690 WEAPON_SHOTGUN2
, WEAPON_SHOTGUN1
,
691 WEAPON_CHAINGUN
, WEAPON_PLASMA
, WEAPON_ROCKETLAUNCHER
,
692 WEAPON_BFG
, WEAPON_PISTOL
, WEAPON_SAW
, WEAPON_KASTET
);
693 WEAPON_PRIOR2
: Array [WP_FIRST
..WP_LAST
] of Byte =
694 (WEAPON_FLAMETHROWER
, WEAPON_SUPERPULEMET
,
695 WEAPON_BFG
, WEAPON_ROCKETLAUNCHER
,
696 WEAPON_SHOTGUN2
, WEAPON_PLASMA
, WEAPON_SHOTGUN1
,
697 WEAPON_CHAINGUN
, WEAPON_PISTOL
, WEAPON_SAW
, WEAPON_KASTET
);
698 //WEAPON_PRIOR3: Array [WP_FIRST..WP_LAST] of Byte =
699 // (WEAPON_FLAMETHROWER, WEAPON_SUPERPULEMET,
700 // WEAPON_BFG, WEAPON_PLASMA, WEAPON_SHOTGUN2,
701 // WEAPON_CHAINGUN, WEAPON_SHOTGUN1, WEAPON_SAW,
702 // WEAPON_ROCKETLAUNCHER, WEAPON_PISTOL, WEAPON_KASTET);
703 WEAPON_RELOAD
: Array [WP_FIRST
..WP_LAST
] of Byte =
704 (5, 2, 6, 18, 36, 2, 12, 2, 14, 2, 2);
706 PLAYER_SIGNATURE
= $52594C50; // 'PLYR'
707 CORPSE_SIGNATURE
= $50524F43; // 'CORP'
709 BOTNAMES_FILENAME
= 'botnames.txt';
710 BOTLIST_FILENAME
= 'botlist.txt';
714 MaxCorpses
: Word = 20;
715 MaxShells
: Word = 300;
716 CurrentGib
: Integer = 0;
717 CurrentShell
: Integer = 0;
718 BotNames
: Array of String;
719 BotList
: Array of TBotProfile
;
720 SavedStates
: Array of TPlayerSavedState
;
723 function Lerp(X
, Y
, Factor
: Integer): Integer;
725 Result
:= X
+ ((Y
- X
) div Factor
);
728 function SameTeam(UID1
, UID2
: Word): Boolean;
732 if (UID1
> UID_MAX_PLAYER
) or (UID1
<= UID_MAX_GAME
) or
733 (UID2
> UID_MAX_PLAYER
) or (UID2
<= UID_MAX_GAME
) then Exit
;
735 if (g_Player_Get(UID1
) = nil) or (g_Player_Get(UID2
) = nil) then Exit
;
737 if ((g_Player_Get(UID1
).Team
= TEAM_NONE
) or
738 (g_Player_Get(UID2
).Team
= TEAM_NONE
)) then Exit
;
740 Result
:= g_Player_Get(UID1
).FTeam
= g_Player_Get(UID2
).FTeam
;
743 procedure g_Gibs_SetMax(Count
: Word);
746 SetLength(gGibs
, Count
);
748 if CurrentGib
>= Count
then
752 function g_Gibs_GetMax(): Word;
757 procedure g_Shells_SetMax(Count
: Word);
760 SetLength(gShells
, Count
);
762 if CurrentShell
>= Count
then
766 function g_Shells_GetMax(): Word;
772 procedure g_Corpses_SetMax(Count
: Word);
775 SetLength(gCorpses
, Count
);
778 function g_Corpses_GetMax(): Word;
780 Result
:= MaxCorpses
;
783 function g_Player_Create(ModelName
: String; Color
: TRGB
; Team
: Byte; Bot
: Boolean): Word;
793 // Åñòü ëè ìåñòî â gPlayers:
794 if gPlayers
<> nil then
795 for a
:= 0 to High(gPlayers
) do
796 if gPlayers
[a
] = nil then
802 // Íåò ìåñòà - ðàñøèðÿåì gPlayers:
805 SetLength(gPlayers
, Length(gPlayers
)+1);
809 // Ñîçäàåì îáúåêò èãðîêà:
811 gPlayers
[a
] := TBot
.Create()
813 gPlayers
[a
] := TPlayer
.Create();
816 gPlayers
[a
].FActualModelName
:= ModelName
;
817 gPlayers
[a
].SetModel(ModelName
);
819 // Íåò ìîäåëè - ñîçäàíèå íå âîçìîæíî:
820 if gPlayers
[a
].FModel
= nil then
824 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], [ModelName
]));
828 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
829 if Random(2) = 0 then
833 gPlayers
[a
].FPreferredTeam
:= Team
;
835 case gGameSettings
.GameMode
of
836 GM_DM
: gPlayers
[a
].FTeam
:= TEAM_NONE
;
838 GM_CTF
: gPlayers
[a
].FTeam
:= gPlayers
[a
].FPreferredTeam
;
840 GM_COOP
: gPlayers
[a
].FTeam
:= TEAM_COOP
;
843 // Åñëè êîìàíäíàÿ èãðà - êðàñèì ìîäåëü â öâåò êîìàíäû:
844 gPlayers
[a
].FColor
:= Color
;
845 if gPlayers
[a
].FTeam
in [TEAM_RED
, TEAM_BLUE
] then
846 gPlayers
[a
].FModel
.Color
:= TEAMCOLOR
[gPlayers
[a
].FTeam
]
848 gPlayers
[a
].FModel
.Color
:= Color
;
850 gPlayers
[a
].FUID
:= g_CreateUID(UID_PLAYER
);
851 gPlayers
[a
].FAlive
:= False;
853 Result
:= gPlayers
[a
].FUID
;
856 function g_Player_CreateFromState (st
: TStream
): Word;
857 var a
: Integer; ok
, Bot
: Boolean; pos
: Int64;
861 // check signature and entity type
863 if not utils
.checkSign(st
, 'PLYR') then raise XStreamError
.Create('invalid player signature');
864 if (utils
.readByte(st
) <> PLR_SAVE_VERSION
) then raise XStreamError
.Create('invalid player version');
865 Bot
:= utils
.readBool(st
);
868 // find free player slot
870 for a
:= 0 to High(gPlayers
) do
871 if gPlayers
[a
] = nil then
877 // allocate player slot
880 SetLength(gPlayers
, Length(gPlayers
)+1);
884 // create entity and load state
886 gPlayers
[a
] := TBot
.Create()
888 gPlayers
[a
] := TPlayer
.Create();
889 gPlayers
[a
].FPhysics
:= True; // ???
890 gPlayers
[a
].LoadState(st
);
892 result
:= gPlayers
[a
].FUID
;
896 procedure g_Player_ResetTeams();
900 if g_Game_IsClient
then
902 if gPlayers
= nil then
904 for a
:= Low(gPlayers
) to High(gPlayers
) do
905 if gPlayers
[a
] <> nil then
906 case gGameSettings
.GameMode
of
908 gPlayers
[a
].ChangeTeam(TEAM_NONE
);
910 if not (gPlayers
[a
].Team
in [TEAM_RED
, TEAM_BLUE
]) then
911 if gPlayers
[a
].FPreferredTeam
in [TEAM_RED
, TEAM_BLUE
] then
912 gPlayers
[a
].ChangeTeam(gPlayers
[a
].FPreferredTeam
)
915 gPlayers
[a
].ChangeTeam(TEAM_RED
)
917 gPlayers
[a
].ChangeTeam(TEAM_BLUE
);
920 gPlayers
[a
].ChangeTeam(TEAM_COOP
);
924 procedure g_Bot_Add(Team
, Difficult
: Byte; Handicap
: Integer = 100);
927 _name
, _model
: String;
930 if not g_Game_IsServer
then Exit
;
932 // Ñïèñîê íàçâàíèé ìîäåëåé:
933 m
:= g_PlayerModel_GetNames();
938 if (gGameSettings
.GameType
= GT_SINGLE
) or (gGameSettings
.GameMode
= GM_COOP
) then
939 Team
:= TEAM_COOP
// COOP
941 if gGameSettings
.GameMode
= GM_DM
then
942 Team
:= TEAM_NONE
// DM
944 if Team
= TEAM_NONE
then // CTF / TDM
946 // Àâòîáàëàíñ êîìàíä:
950 for a
:= 0 to High(gPlayers
) do
951 if gPlayers
[a
] <> nil then
953 if gPlayers
[a
].Team
= TEAM_RED
then
956 if gPlayers
[a
].Team
= TEAM_BLUE
then
966 if Random(2) = 0 then
972 // Âûáèðàåì áîòó èìÿ:
974 if BotNames
<> nil then
975 for a
:= 0 to High(BotNames
) do
976 if g_Player_ValidName(BotNames
[a
]) then
978 _name
:= BotNames
[a
];
982 // Âûáèðàåì ñëó÷àéíóþ ìîäåëü:
983 _model
:= m
[Random(Length(m
))];
986 with g_Player_Get(g_Player_Create(_model
,
987 _RGB(Min(Random(9)*32, 255),
988 Min(Random(9)*32, 255),
989 Min(Random(9)*32, 255)),
990 Team
, True)) as TBot
do
992 // Åñëè èìåíè íåò, äåëàåì åãî èç UID áîòà
994 Name
:= Format('DFBOT%.5d', [UID
])
999 1: FDifficult
:= DIFFICULT_EASY
;
1000 2: FDifficult
:= DIFFICULT_MEDIUM
;
1001 else FDifficult
:= DIFFICULT_HARD
;
1004 for a
:= WP_FIRST
to WP_LAST
do
1006 FDifficult
.WeaponPrior
[a
] := WEAPON_PRIOR1
[a
];
1007 FDifficult
.CloseWeaponPrior
[a
] := WEAPON_PRIOR2
[a
];
1008 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
1011 FHandicap
:= Handicap
;
1013 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [Name
]), True);
1015 if g_Game_IsNet
then MH_SEND_PlayerCreate(UID
);
1016 if g_Game_IsServer
and (gGameSettings
.MaxLives
> 0) then
1021 procedure g_Bot_AddList(Team
: Byte; lName
: ShortString; num
: Integer = -1; Handicap
: Integer = 100);
1024 _name
, _model
: String;
1027 if not g_Game_IsServer
then Exit
;
1029 // Ñïèñîê íàçâàíèé ìîäåëåé:
1030 m
:= g_PlayerModel_GetNames();
1035 if (gGameSettings
.GameType
= GT_SINGLE
) or (gGameSettings
.GameMode
= GM_COOP
) then
1036 Team
:= TEAM_COOP
// COOP
1038 if gGameSettings
.GameMode
= GM_DM
then
1039 Team
:= TEAM_NONE
// DM
1041 if Team
= TEAM_NONE
then
1042 Team
:= BotList
[num
].team
; // CTF / TDM
1044 // Âûáèðàåì íàñòðîéêè áîòà èç ñïèñêà ïî íîìåðó èëè èìåíè:
1045 lName
:= AnsiLowerCase(lName
);
1046 if (num
< 0) or (num
> Length(BotList
)-1) then
1048 if (num
= -1) and (lName
<> '') and (BotList
<> nil) then
1049 for a
:= 0 to High(BotList
) do
1050 if AnsiLowerCase(BotList
[a
].name
) = lName
then
1059 _name
:= BotList
[num
].name
;
1060 // Çàíÿòî - âûáèðàåì ñëó÷àéíîå:
1061 if not g_Player_ValidName(_name
) then
1063 _name
:= Format('DFBOT%.2d', [Random(100)]);
1064 until g_Player_ValidName(_name
);
1067 _model
:= BotList
[num
].model
;
1068 // Íåò òàêîé - âûáèðàåì ñëó÷àéíóþ:
1069 if not InSArray(_model
, m
) then
1070 _model
:= m
[Random(Length(m
))];
1073 with g_Player_Get(g_Player_Create(_model
, BotList
[num
].color
, Team
, True)) as TBot
do
1077 FDifficult
.DiagFire
:= BotList
[num
].diag_fire
;
1078 FDifficult
.InvisFire
:= BotList
[num
].invis_fire
;
1079 FDifficult
.DiagPrecision
:= BotList
[num
].diag_precision
;
1080 FDifficult
.FlyPrecision
:= BotList
[num
].fly_precision
;
1081 FDifficult
.Cover
:= BotList
[num
].cover
;
1082 FDifficult
.CloseJump
:= BotList
[num
].close_jump
;
1084 FHandicap
:= Handicap
;
1086 for a
:= WP_FIRST
to WP_LAST
do
1088 FDifficult
.WeaponPrior
[a
] := BotList
[num
].w_prior1
[a
];
1089 FDifficult
.CloseWeaponPrior
[a
] := BotList
[num
].w_prior2
[a
];
1090 //FDifficult.SafeWeaponPrior[a] := BotList[num].w_prior3[a];
1093 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [Name
]), True);
1095 if g_Game_IsNet
then MH_SEND_PlayerCreate(UID
);
1099 procedure g_Bot_RemoveAll();
1103 if not g_Game_IsServer
then Exit
;
1104 if gPlayers
= nil then Exit
;
1106 for a
:= 0 to High(gPlayers
) do
1107 if gPlayers
[a
] <> nil then
1108 if gPlayers
[a
] is TBot
then
1110 gPlayers
[a
].Lives
:= 0;
1111 gPlayers
[a
].Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
1112 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [gPlayers
[a
].Name
]), True);
1113 g_Player_Remove(gPlayers
[a
].FUID
);
1119 procedure g_Bot_MixNames();
1124 if BotNames
<> nil then
1125 for a
:= 0 to High(BotNames
) do
1127 b
:= Random(Length(BotNames
));
1129 Botnames
[a
] := BotNames
[b
];
1134 procedure g_Player_Remove(UID
: Word);
1138 if gPlayers
= nil then Exit
;
1140 if g_Game_IsServer
and g_Game_IsNet
then
1141 MH_SEND_PlayerDelete(UID
);
1143 for i
:= 0 to High(gPlayers
) do
1144 if gPlayers
[i
] <> nil then
1145 if gPlayers
[i
].FUID
= UID
then
1147 if gPlayers
[i
] is TPlayer
then
1148 TPlayer(gPlayers
[i
]).Free()
1150 TBot(gPlayers
[i
]).Free();
1156 procedure g_Player_Init();
1167 path
:= BOTNAMES_FILENAME
;
1168 if e_FindResource(DataDirs
, path
) = false then
1171 // ×èòàåì âîçìîæíûå èìåíà áîòîâ èç ôàéëà:
1172 AssignFile(F
, path
);
1183 SetLength(BotNames
, Length(BotNames
)+1);
1184 BotNames
[High(BotNames
)] := s
;
1192 // ×èòàåì ôàéë ñ ïàðàìåòðàìè áîòîâ:
1193 config
:= TConfig
.CreateFile(path
);
1197 while config
.SectionExists(IntToStr(a
)) do
1199 SetLength(BotList
, Length(BotList
)+1);
1201 with BotList
[High(BotList
)] do
1204 name
:= config
.ReadStr(IntToStr(a
), 'name', '');
1206 model
:= config
.ReadStr(IntToStr(a
), 'model', '');
1208 if config
.ReadStr(IntToStr(a
), 'team', 'red') = 'red' then
1213 sa
:= parse(config
.ReadStr(IntToStr(a
), 'color', ''));
1214 color
.R
:= StrToIntDef(sa
[0], 0);
1215 color
.G
:= StrToIntDef(sa
[1], 0);
1216 color
.B
:= StrToIntDef(sa
[2], 0);
1217 // Âåðîÿòíîñòü ñòðåëüáû ïîä óãëîì:
1218 diag_fire
:= config
.ReadInt(IntToStr(a
), 'diag_fire', 0);
1219 // Âåðîÿòíîñòü îòâåòíîãî îãíÿ ïî íåâèäèìîìó ñîïåðíèêó:
1220 invis_fire
:= config
.ReadInt(IntToStr(a
), 'invis_fire', 0);
1221 // Òî÷íîñòü ñòðåëüáû ïîä óãëîì:
1222 diag_precision
:= config
.ReadInt(IntToStr(a
), 'diag_precision', 0);
1223 // Òî÷íîñòü ñòðåëüáû â ïîëåòå:
1224 fly_precision
:= config
.ReadInt(IntToStr(a
), 'fly_precision', 0);
1225 // Òî÷íîñòü óêëîíåíèÿ îò ñíàðÿäîâ:
1226 cover
:= config
.ReadInt(IntToStr(a
), 'cover', 0);
1227 // Âåðîÿòíîñòü ïðûæêà ïðè ïðèáëèæåíèè ñîïåðíèêà:
1228 close_jump
:= config
.ReadInt(IntToStr(a
), 'close_jump', 0);
1229 // Ïðèîðèòåòû îðóæèÿ äëÿ äàëüíåãî áîÿ:
1230 sa
:= parse(config
.ReadStr(IntToStr(a
), 'w_prior1', ''));
1231 if Length(sa
) = 10 then
1233 w_prior1
[b
] := EnsureRange(StrToInt(sa
[b
]), 0, 9);
1234 // Ïðèîðèòåòû îðóæèÿ äëÿ áëèæíåãî áîÿ:
1235 sa
:= parse(config
.ReadStr(IntToStr(a
), 'w_prior2', ''));
1236 if Length(sa
) = 10 then
1238 w_prior2
[b
] := EnsureRange(StrToInt(sa
[b
]), 0, 9);
1240 {sa := parse(config.ReadStr(IntToStr(a), 'w_prior3', ''));
1241 if Length(sa) = 10 then
1243 w_prior3[b] := EnsureRange(StrToInt(sa[b]), 0, 9);}
1250 SetLength(SavedStates
, 0);
1253 procedure g_Player_Free();
1257 if gPlayers
<> nil then
1259 for i
:= 0 to High(gPlayers
) do
1260 if gPlayers
[i
] <> nil then
1262 if gPlayers
[i
] is TPlayer
then
1263 TPlayer(gPlayers
[i
]).Free()
1265 TBot(gPlayers
[i
]).Free();
1274 SetLength(SavedStates
, 0);
1277 procedure g_Player_PreUpdate();
1281 if gPlayers
= nil then Exit
;
1282 for i
:= 0 to High(gPlayers
) do
1283 if gPlayers
[i
] <> nil then
1284 gPlayers
[i
].PreUpdate();
1287 procedure g_Player_UpdateAll();
1291 if gPlayers
= nil then Exit
;
1293 //e_WriteLog('***g_Player_UpdateAll: ENTER', MSG_WARNING);
1294 for i
:= 0 to High(gPlayers
) do
1296 if gPlayers
[i
] <> nil then
1298 if gPlayers
[i
] is TPlayer
then
1300 gPlayers
[i
].Update();
1301 gPlayers
[i
].RealizeCurrentWeapon(); // WARNING! DO NOT MOVE THIS INTO `Update()`!
1305 // bot updates weapons in `UpdateCombat()`
1306 TBot(gPlayers
[i
]).Update();
1310 //e_WriteLog('***g_Player_UpdateAll: EXIT', MSG_WARNING);
1313 procedure g_Player_DrawAll();
1317 if gPlayers
= nil then Exit
;
1319 for i
:= 0 to High(gPlayers
) do
1320 if gPlayers
[i
] <> nil then
1321 if gPlayers
[i
] is TPlayer
then gPlayers
[i
].Draw()
1322 else TBot(gPlayers
[i
]).Draw();
1325 procedure g_Player_DrawDebug(p
: TPlayer
);
1329 if p
= nil then Exit
;
1330 if (@p
.FObj
) = nil then Exit
;
1332 e_TextureFontGetSize(gStdFont
, fW
, fH
);
1334 e_TextureFontPrint(0, 0 , 'Pos X: ' + IntToStr(p
.FObj
.X
), gStdFont
);
1335 e_TextureFontPrint(0, fH
, 'Pos Y: ' + IntToStr(p
.FObj
.Y
), gStdFont
);
1336 e_TextureFontPrint(0, fH
* 2, 'Vel X: ' + IntToStr(p
.FObj
.Vel
.X
), gStdFont
);
1337 e_TextureFontPrint(0, fH
* 3, 'Vel Y: ' + IntToStr(p
.FObj
.Vel
.Y
), gStdFont
);
1338 e_TextureFontPrint(0, fH
* 4, 'Acc X: ' + IntToStr(p
.FObj
.Accel
.X
), gStdFont
);
1339 e_TextureFontPrint(0, fH
* 5, 'Acc Y: ' + IntToStr(p
.FObj
.Accel
.Y
), gStdFont
);
1340 e_TextureFontPrint(0, fH
* 6, 'Old X: ' + IntToStr(p
.FObj
.oldX
), gStdFont
);
1341 e_TextureFontPrint(0, fH
* 7, 'Old Y: ' + IntToStr(p
.FObj
.oldY
), gStdFont
);
1344 procedure g_Player_DrawHealth();
1349 if gPlayers
= nil then Exit
;
1350 e_TextureFontGetSize(gStdFont
, fW
, fH
);
1352 for i
:= 0 to High(gPlayers
) do
1353 if gPlayers
[i
] <> nil then
1355 e_TextureFontPrint(gPlayers
[i
].FObj
.X
+ gPlayers
[i
].FObj
.Rect
.X
,
1356 gPlayers
[i
].FObj
.Y
+ gPlayers
[i
].FObj
.Rect
.Y
+ gPlayers
[i
].FObj
.Rect
.Height
- fH
* 2,
1357 IntToStr(gPlayers
[i
].FHealth
), gStdFont
);
1358 e_TextureFontPrint(gPlayers
[i
].FObj
.X
+ gPlayers
[i
].FObj
.Rect
.X
,
1359 gPlayers
[i
].FObj
.Y
+ gPlayers
[i
].FObj
.Rect
.Y
+ gPlayers
[i
].FObj
.Rect
.Height
- fH
,
1360 IntToStr(gPlayers
[i
].FArmor
), gStdFont
);
1364 function g_Player_Get(UID
: Word): TPlayer
;
1370 if gPlayers
= nil then
1373 for a
:= 0 to High(gPlayers
) do
1374 if gPlayers
[a
] <> nil then
1375 if gPlayers
[a
].FUID
= UID
then
1377 Result
:= gPlayers
[a
];
1382 function g_Player_GetCount(): Byte;
1388 if gPlayers
= nil then
1391 for a
:= 0 to High(gPlayers
) do
1392 if gPlayers
[a
] <> nil then
1393 Result
:= Result
+ 1;
1396 function g_Player_GetStats(): TPlayerStatArray
;
1402 if gPlayers
= nil then Exit
;
1404 for a
:= 0 to High(gPlayers
) do
1405 if gPlayers
[a
] <> nil then
1407 SetLength(Result
, Length(Result
)+1);
1408 with Result
[High(Result
)] do
1411 Ping
:= gPlayers
[a
].FPing
;
1412 Loss
:= gPlayers
[a
].FLoss
;
1413 Name
:= gPlayers
[a
].FName
;
1414 Team
:= gPlayers
[a
].FTeam
;
1415 Frags
:= gPlayers
[a
].FFrags
;
1416 Deaths
:= gPlayers
[a
].FDeath
;
1417 Kills
:= gPlayers
[a
].FKills
;
1418 Color
:= gPlayers
[a
].FModel
.Color
;
1419 Lives
:= gPlayers
[a
].FLives
;
1420 Spectator
:= gPlayers
[a
].FSpectator
;
1421 UID
:= gPlayers
[a
].FUID
;
1426 procedure g_Player_ResetReady();
1430 if not g_Game_IsServer
then Exit
;
1431 if gPlayers
= nil then Exit
;
1433 for a
:= 0 to High(gPlayers
) do
1434 if gPlayers
[a
] <> nil then
1436 gPlayers
[a
].FReady
:= False;
1437 if g_Game_IsNet
then
1438 MH_SEND_GameEvent(NET_EV_INTER_READY
, gPlayers
[a
].UID
, 'N');
1442 procedure g_Player_RememberAll
;
1446 for i
:= Low(gPlayers
) to High(gPlayers
) do
1447 if (gPlayers
[i
] <> nil) and gPlayers
[i
].alive
then
1448 gPlayers
[i
].RememberState
;
1451 procedure g_Player_ResetAll(Force
, Silent
: Boolean);
1455 gTeamStat
[TEAM_RED
].Goals
:= 0;
1456 gTeamStat
[TEAM_BLUE
].Goals
:= 0;
1458 if gPlayers
<> nil then
1459 for i
:= 0 to High(gPlayers
) do
1460 if gPlayers
[i
] <> nil then
1462 gPlayers
[i
].Reset(Force
);
1464 if gPlayers
[i
] is TPlayer
then
1466 if (not gPlayers
[i
].FSpectator
) or gPlayers
[i
].FWantsInGame
then
1467 gPlayers
[i
].Respawn(Silent
)
1469 gPlayers
[i
].Spectate();
1472 TBot(gPlayers
[i
]).Respawn(Silent
);
1476 function g_Player_CreateCorpse(Player
: TPlayer
): Integer;
1484 if Player
.alive
then
1487 // Ðàçðûâàåì ñâÿçü ñ ïðåæíèì òðóïîì:
1488 i
:= Player
.FCorpse
;
1489 if (i
>= 0) and (i
< Length(gCorpses
)) then
1491 if (gCorpses
[i
] <> nil) and (gCorpses
[i
].FPlayerUID
= Player
.FUID
) then
1492 gCorpses
[i
].FPlayerUID
:= 0;
1495 if Player
.FObj
.Y
>= gMapInfo
.Height
+128 then
1500 if (FHealth
>= -50) or (gGibsCount
= 0) then
1502 if (gCorpses
= nil) or (Length(gCorpses
) = 0) then
1506 for find_id
:= 0 to High(gCorpses
) do
1507 if gCorpses
[find_id
] = nil then
1514 find_id
:= Random(Length(gCorpses
));
1516 gCorpses
[find_id
] := TCorpse
.Create(FObj
.X
, FObj
.Y
, FModel
.Name
, FHealth
< -20);
1517 gCorpses
[find_id
].FColor
:= FModel
.Color
;
1518 gCorpses
[find_id
].FObj
.Vel
:= FObj
.Vel
;
1519 gCorpses
[find_id
].FObj
.Accel
:= FObj
.Accel
;
1520 gCorpses
[find_id
].FPlayerUID
:= FUID
;
1525 g_Player_CreateGibs(FObj
.X
+ PLAYER_RECT_CX
,
1526 FObj
.Y
+ PLAYER_RECT_CY
,
1527 FModel
.Name
, FModel
.Color
);
1531 procedure g_Player_CreateShell(fX
, fY
, dX
, dY
: Integer; T
: Byte);
1535 if (gShells
= nil) or (Length(gShells
) = 0) then
1538 with gShells
[CurrentShell
] do
1544 if T
= SHELL_BULLET
then
1546 if g_Texture_Get('TEXTURE_SHELL_BULLET', SID
) then
1550 Obj
.Rect
.Width
:= 4;
1551 Obj
.Rect
.Height
:= 2;
1555 if g_Texture_Get('TEXTURE_SHELL_SHELL', SID
) then
1559 Obj
.Rect
.Width
:= 7;
1560 Obj
.Rect
.Height
:= 3;
1566 g_Obj_Push(@Obj
, dX
+ Random(4)-Random(4), dY
-Random(4));
1567 positionChanged(); // this updates spatial accelerators
1568 RAngle
:= Random(360);
1569 Timeout
:= gTime
+ SHELL_TIMEOUT
;
1571 if CurrentShell
>= High(gShells
) then
1578 procedure g_Player_CreateGibs(fX
, fY
: Integer; ModelName
: string; fColor
: TRGB
);
1581 GibsArray
: TGibsArray
;
1584 if (gGibs
= nil) or (Length(gGibs
) = 0) then
1586 if not g_PlayerModel_GetGibs(ModelName
, GibsArray
) then
1588 Blood
:= g_PlayerModel_GetBlood(ModelName
);
1590 for a
:= 0 to High(GibsArray
) do
1591 with gGibs
[CurrentGib
] do
1594 ID
:= GibsArray
[a
].ID
;
1595 MaskID
:= GibsArray
[a
].MaskID
;
1598 Obj
.Rect
:= GibsArray
[a
].Rect
;
1599 Obj
.X
:= fX
-GibsArray
[a
].Rect
.X
-(GibsArray
[a
].Rect
.Width
div 2);
1600 Obj
.Y
:= fY
-GibsArray
[a
].Rect
.Y
-(GibsArray
[a
].Rect
.Height
div 2);
1601 g_Obj_PushA(@Obj
, 25 + Random(10), Random(361));
1602 positionChanged(); // this updates spatial accelerators
1603 RAngle
:= Random(360);
1605 if gBloodCount
> 0 then
1606 g_GFX_Blood(fX
, fY
, 16*gBloodCount
+Random(5*gBloodCount
), -16+Random(33), -16+Random(33),
1607 Random(48), Random(48), Blood
.R
, Blood
.G
, Blood
.B
, Blood
.Kind
);
1609 if CurrentGib
>= High(gGibs
) then
1616 procedure g_Player_UpdatePhysicalObjects();
1622 procedure ShellSound_Bounce(X
, Y
: Integer; T
: Byte);
1627 if T
= SHELL_BULLET
then
1628 g_Sound_PlayExAt('SOUND_PLAYER_CASING' + IntToStr(k
), X
, Y
)
1630 g_Sound_PlayExAt('SOUND_PLAYER_SHELL' + IntToStr(k
), X
, Y
);
1635 if gGibs
<> nil then
1636 for i
:= 0 to High(gGibs
) do
1637 if gGibs
[i
].alive
then
1644 mr
:= g_Obj_Move(@Obj
, True, False, True);
1645 positionChanged(); // this updates spatial accelerators
1647 if WordBool(mr
and MOVE_FALLOUT
) then
1653 // Îòëåòàåò îò óäàðà î ñòåíó/ïîòîëîê/ïîë:
1654 if WordBool(mr
and MOVE_HITWALL
) then
1655 Obj
.Vel
.X
:= -(vel
.X
div 2);
1656 if WordBool(mr
and (MOVE_HITCEIL
or MOVE_HITLAND
)) then
1657 Obj
.Vel
.Y
:= -(vel
.Y
div 2);
1659 if (Obj
.Vel
.X
>= 0) then
1661 RAngle
:= RAngle
+ Abs(Obj
.Vel
.X
)*6 + Abs(Obj
.Vel
.Y
);
1662 if RAngle
>= 360 then
1663 RAngle
:= RAngle
mod 360;
1664 end else begin // Counter-clockwise
1665 RAngle
:= RAngle
- Abs(Obj
.Vel
.X
)*6 - Abs(Obj
.Vel
.Y
);
1667 RAngle
:= (360 - (Abs(RAngle
) mod 360)) mod 360;
1670 // Ñîïðîòèâëåíèå âîçäóõà äëÿ êóñêà òðóïà:
1671 if gTime
mod (GAME_TICK
*3) = 0 then
1672 Obj
.Vel
.X
:= z_dec(Obj
.Vel
.X
, 1);
1676 if gCorpses
<> nil then
1677 for i
:= 0 to High(gCorpses
) do
1678 if gCorpses
[i
] <> nil then
1679 if gCorpses
[i
].State
= CORPSE_STATE_REMOVEME
then
1685 gCorpses
[i
].Update();
1688 if gShells
<> nil then
1689 for i
:= 0 to High(gShells
) do
1690 if gShells
[i
].alive
then
1697 mr
:= g_Obj_Move(@Obj
, True, False, True);
1698 positionChanged(); // this updates spatial accelerators
1700 if WordBool(mr
and MOVE_FALLOUT
) or (gShells
[i
].Timeout
< gTime
) then
1706 // Îòëåòàåò îò óäàðà î ñòåíó/ïîòîëîê/ïîë:
1707 if WordBool(mr
and MOVE_HITWALL
) then
1709 Obj
.Vel
.X
:= -(vel
.X
div 2);
1710 if not WordBool(mr
and MOVE_INWATER
) then
1711 ShellSound_Bounce(Obj
.X
, Obj
.Y
, SType
);
1713 if WordBool(mr
and (MOVE_HITCEIL
or MOVE_HITLAND
)) then
1715 Obj
.Vel
.Y
:= -(vel
.Y
div 2);
1716 if Obj
.Vel
.X
<> 0 then Obj
.Vel
.X
:= Obj
.Vel
.X
div 2;
1717 if (Obj
.Vel
.X
= 0) and (Obj
.Vel
.Y
= 0) then
1719 if RAngle
mod 90 <> 0 then
1720 RAngle
:= (RAngle
div 90) * 90;
1722 else if not WordBool(mr
and MOVE_INWATER
) then
1723 ShellSound_Bounce(Obj
.X
, Obj
.Y
, SType
);
1726 if (Obj
.Vel
.X
>= 0) then
1728 RAngle
:= RAngle
+ Abs(Obj
.Vel
.X
)*8 + Abs(Obj
.Vel
.Y
);
1729 if RAngle
>= 360 then
1730 RAngle
:= RAngle
mod 360;
1731 end else begin // Counter-clockwise
1732 RAngle
:= RAngle
- Abs(Obj
.Vel
.X
)*8 - Abs(Obj
.Vel
.Y
);
1734 RAngle
:= (360 - (Abs(RAngle
) mod 360)) mod 360;
1740 procedure TGib
.getMapBox (out x
, y
, w
, h
: Integer); inline;
1742 x
:= Obj
.X
+Obj
.Rect
.X
;
1743 y
:= Obj
.Y
+Obj
.Rect
.Y
;
1744 w
:= Obj
.Rect
.Width
;
1745 h
:= Obj
.Rect
.Height
;
1748 procedure TGib
.moveBy (dx
, dy
: Integer); inline;
1750 if (dx
<> 0) or (dy
<> 0) then
1759 procedure TShell
.getMapBox (out x
, y
, w
, h
: Integer); inline;
1763 w
:= Obj
.Rect
.Width
;
1764 h
:= Obj
.Rect
.Height
;
1767 procedure TShell
.moveBy (dx
, dy
: Integer); inline;
1769 if (dx
<> 0) or (dy
<> 0) then
1778 procedure TGib
.positionChanged (); inline; begin end;
1779 procedure TShell
.positionChanged (); inline; begin end;
1782 procedure g_Player_DrawCorpses();
1787 if gGibs
<> nil then
1788 for i
:= 0 to High(gGibs
) do
1789 if gGibs
[i
].alive
then
1792 if not g_Obj_Collide(sX
, sY
, sWidth
, sHeight
, @Obj
) then
1795 Obj
.lerp(gLerpFactor
, fX
, fY
);
1797 a
.X
:= Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2);
1798 a
.y
:= Obj
.Rect
.Y
+(Obj
.Rect
.Height
div 2);
1800 e_DrawAdv(ID
, fX
, fY
, 0, True, False, RAngle
, @a
, TMirrorType
.None
);
1803 e_DrawAdv(MaskID
, fX
, fY
, 0, True, False, RAngle
, @a
, TMirrorType
.None
);
1809 if gCorpses
<> nil then
1810 for i
:= 0 to High(gCorpses
) do
1811 if gCorpses
[i
] <> nil then
1815 procedure g_Player_DrawShells();
1820 if gShells
<> nil then
1821 for i
:= 0 to High(gShells
) do
1822 if gShells
[i
].alive
then
1825 if not g_Obj_Collide(sX
, sY
, sWidth
, sHeight
, @Obj
) then
1828 Obj
.lerp(gLerpFactor
, fX
, fY
);
1833 e_DrawAdv(SpriteID
, fX
, fY
, 0, True, False, RAngle
, @a
, TMirrorType
.None
);
1837 procedure g_Player_RemoveAllCorpses();
1843 SetLength(gGibs
, MaxGibs
);
1844 SetLength(gShells
, MaxGibs
);
1848 if gCorpses
<> nil then
1849 for i
:= 0 to High(gCorpses
) do
1853 SetLength(gCorpses
, MaxCorpses
);
1856 procedure g_Player_Corpses_SaveState (st
: TStream
);
1860 // Ñ÷èòàåì êîëè÷åñòâî ñóùåñòâóþùèõ òðóïîâ
1862 for i
:= 0 to High(gCorpses
) do if (gCorpses
[i
] <> nil) then Inc(count
);
1864 // Êîëè÷åñòâî òðóïîâ
1865 utils
.writeInt(st
, LongInt(count
));
1867 if (count
= 0) then exit
;
1870 for i
:= 0 to High(gCorpses
) do
1872 if gCorpses
[i
] <> nil then
1875 utils
.writeStr(st
, gCorpses
[i
].FModelName
);
1877 utils
.writeBool(st
, gCorpses
[i
].Mess
);
1878 // Ñîõðàíÿåì äàííûå òðóïà:
1879 gCorpses
[i
].SaveState(st
);
1885 procedure g_Player_Corpses_LoadState (st
: TStream
);
1893 g_Player_RemoveAllCorpses();
1895 // Êîëè÷åñòâî òðóïîâ:
1896 count
:= utils
.readLongInt(st
);
1897 if (count
< 0) or (count
> Length(gCorpses
)) then raise XStreamError
.Create('invalid number of corpses');
1899 if (count
= 0) then exit
;
1902 for i
:= 0 to count
-1 do
1905 str
:= utils
.readStr(st
);
1907 b
:= utils
.readBool(st
);
1909 gCorpses
[i
] := TCorpse
.Create(0, 0, str
, b
);
1910 // Çàãðóæàåì äàííûå òðóïà
1911 gCorpses
[i
].LoadState(st
);
1918 function TPlayer
.isValidViewPort (): Boolean; inline; begin result
:= (viewPortW
> 0) and (viewPortH
> 0); end;
1920 procedure TPlayer
.BFGHit();
1922 g_Weapon_BFGHit(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
1923 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2));
1924 if g_Game_IsServer
and g_Game_IsNet
then
1925 MH_SEND_Effect(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
1926 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2),
1930 procedure TPlayer
.ChangeModel(ModelName
: string);
1932 locModel
: TPlayerModel
;
1934 locModel
:= g_PlayerModel_Get(ModelName
);
1935 if locModel
= nil then Exit
;
1941 procedure TPlayer
.SetModel(ModelName
: string);
1945 m
:= g_PlayerModel_Get(ModelName
);
1948 g_SimpleError(Format(_lc
[I_GAME_ERROR_MODEL_FALLBACK
], [ModelName
]));
1949 m
:= g_PlayerModel_Get('doomer');
1952 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], ['doomer']));
1957 if FModel
<> nil then
1962 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
1963 FModel
.Color
:= FColor
1965 FModel
.Color
:= TEAMCOLOR
[FTeam
];
1966 FModel
.SetWeapon(FCurrWeap
);
1967 FModel
.SetFlag(FFlag
);
1968 SetDirection(FDirection
);
1971 procedure TPlayer
.SetColor(Color
: TRGB
);
1974 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
1975 if FModel
<> nil then FModel
.Color
:= Color
;
1978 function TPlayer
.GetColor(): TRGB
;
1980 result
:= FModel
.Color
;
1983 procedure TPlayer
.SwitchTeam
;
1985 if g_Game_IsClient
then
1987 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then Exit
;
1989 if gGameOn
and FAlive
then
1990 Kill(K_SIMPLEKILL
, FUID
, HIT_SELF
);
1992 if FTeam
= TEAM_RED
then
1994 ChangeTeam(TEAM_BLUE
);
1995 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_BLUE
], [FName
]), True);
1996 if g_Game_IsNet
then
1997 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM
, TEAM_BLUE
, FName
);
2001 ChangeTeam(TEAM_RED
);
2002 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_RED
], [FName
]), True);
2003 if g_Game_IsNet
then
2004 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM
, TEAM_RED
, FName
);
2006 FPreferredTeam
:= FTeam
;
2009 procedure TPlayer
.ChangeTeam(Team
: Byte);
2016 TEAM_RED
, TEAM_BLUE
:
2017 FModel
.Color
:= TEAMCOLOR
[Team
];
2019 FModel
.Color
:= FColor
;
2021 if (FTeam
<> OldTeam
) and g_Game_IsNet
and g_Game_IsServer
then
2022 MH_SEND_PlayerStats(FUID
);
2026 procedure TPlayer.CollideItem();
2031 if gItems = nil then Exit;
2032 if not FAlive then Exit;
2034 for i := 0 to High(gItems) do
2037 if (ItemType <> ITEM_NONE) and alive then
2038 if g_Obj_Collide(FObj.X+PLAYER_RECT.X, FObj.Y+PLAYER_RECT.Y, PLAYER_RECT.Width,
2039 PLAYER_RECT.Height, @Obj) then
2041 if not PickItem(ItemType, gItems[i].Respawnable, r) then Continue;
2043 if ItemType in [ITEM_SPHERE_BLUE, ITEM_SPHERE_WHITE, ITEM_INVUL] then
2044 g_Sound_PlayExAt('SOUND_ITEM_GETRULEZ', FObj.X, FObj.Y)
2045 else if ItemType in [ITEM_MEDKIT_SMALL, ITEM_MEDKIT_LARGE, ITEM_MEDKIT_BLACK] then
2046 g_Sound_PlayExAt('SOUND_ITEM_GETMED', FObj.X, FObj.Y)
2047 else g_Sound_PlayExAt('SOUND_ITEM_GETITEM', FObj.X, FObj.Y);
2049 // Íàäî óáðàòü ñ êàðòû, åñëè ýòî íå êëþ÷, êîòîðûì íóæíî ïîäåëèòñÿ ñ äðóãèì èãðîêîì:
2050 if r and not ((ItemType in [ITEM_KEY_RED, ITEM_KEY_GREEN, ITEM_KEY_BLUE]) and
2051 (gGameSettings.GameType = GT_SINGLE) and
2052 (g_Player_GetCount() > 1)) then
2053 if not Respawnable then g_Items_Remove(i) else g_Items_Pick(i);
2059 function TPlayer
.CollideLevel(XInc
, YInc
: Integer): Boolean;
2061 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
2062 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_WALL
,
2066 constructor TPlayer
.Create();
2072 mEDamageType
:= HIT_SOME
;
2078 FSawSound
:= TPlayableSound
.Create();
2079 FSawSoundIdle
:= TPlayableSound
.Create();
2080 FSawSoundHit
:= TPlayableSound
.Create();
2081 FSawSoundSelect
:= TPlayableSound
.Create();
2082 FFlameSoundOn
:= TPlayableSound
.Create();
2083 FFlameSoundOff
:= TPlayableSound
.Create();
2084 FFlameSoundWork
:= TPlayableSound
.Create();
2085 FJetSoundFly
:= TPlayableSound
.Create();
2086 FJetSoundOn
:= TPlayableSound
.Create();
2087 FJetSoundOff
:= TPlayableSound
.Create();
2089 FSawSound
.SetByName('SOUND_WEAPON_FIRESAW');
2090 FSawSoundIdle
.SetByName('SOUND_WEAPON_IDLESAW');
2091 FSawSoundHit
.SetByName('SOUND_WEAPON_HITSAW');
2092 FSawSoundSelect
.SetByName('SOUND_WEAPON_SELECTSAW');
2093 FFlameSoundOn
.SetByName('SOUND_WEAPON_FLAMEON');
2094 FFlameSoundOff
.SetByName('SOUND_WEAPON_FLAMEOFF');
2095 FFlameSoundWork
.SetByName('SOUND_WEAPON_FLAMEWORK');
2096 FJetSoundFly
.SetByName('SOUND_PLAYER_JETFLY');
2097 FJetSoundOn
.SetByName('SOUND_PLAYER_JETON');
2098 FJetSoundOff
.SetByName('SOUND_PLAYER_JETOFF');
2100 FSpectatePlayer
:= -1;
2104 FSavedStateNum
:= -1;
2112 FActualModelName
:= 'doomer';
2115 FObj
.Rect
:= PLAYER_RECT
;
2117 FBFGFireCounter
:= -1;
2118 FJustTeleported
:= False;
2121 FWaitForFirstSpawn
:= false;
2126 procedure TPlayer
.positionChanged (); inline;
2130 procedure TPlayer
.doDamage (v
: Integer);
2132 if (v
<= 0) then exit
;
2133 if (v
> 32767) then v
:= 32767;
2134 Damage(v
, 0, 0, 0, mEDamageType
);
2137 procedure TPlayer
.Damage(value
: Word; SpawnerUID
: Word; vx
, vy
: Integer; t
: Byte);
2141 if (not g_Game_IsClient
) and (not FAlive
) then
2146 // Íåóÿçâèìîñòü íå ñïàñàåò îò ëîâóøåê:
2147 if ((t
= HIT_TRAP
) or (t
= HIT_SELF
)) and (not FGodMode
) then
2149 if not g_Game_IsClient
then
2152 if t
= HIT_TRAP
then
2154 // Ëîâóøêà óáèâàåò ñðàçó:
2156 Kill(K_EXTRAHARDKILL
, SpawnerUID
, t
);
2158 if t
= HIT_SELF
then
2162 Kill(K_SIMPLEKILL
, SpawnerUID
, t
);
2165 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
2166 FMegaRulez
[MR_SUIT
] := 0;
2167 FMegaRulez
[MR_INVUL
] := 0;
2168 FMegaRulez
[MR_INVIS
] := 0;
2173 // Íî îò îñòàëüíîãî ñïàñàåò:
2174 if FMegaRulez
[MR_INVUL
] >= gTime
then
2181 // Åñëè åñòü óðîí ñâîèì, èëè ðàíèë ñàì ñåáÿ, èëè òåáÿ ðàíèë ïðîòèâíèê:
2182 if LongBool(gGameSettings
.Options
and GAME_OPTION_TEAMDAMAGE
) or
2183 (SpawnerUID
= FUID
) or
2184 (not SameTeam(FUID
, SpawnerUID
)) then
2186 FLastSpawnerUID
:= SpawnerUID
;
2188 // Êðîâü (ïóçûðüêè, åñëè â âîäå):
2189 if gBloodCount
> 0 then
2191 c
:= Min(value
, 200)*gBloodCount
+ Random(Min(value
, 200) div 2);
2192 if value
div 4 <= c
then
2193 c
:= c
- (value
div 4)
2197 if (t
= HIT_SOME
) and (vx
= 0) and (vy
= 0) then
2201 HIT_TRAP
, HIT_ACID
, HIT_FLAME
, HIT_SELF
: MakeBloodSimple(c
);
2202 HIT_BFG
, HIT_ROCKET
, HIT_SOME
: MakeBloodVector(c
, vx
, vy
);
2205 if t
= HIT_WATER
then
2206 g_GFX_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
2207 FObj
.Y
+PLAYER_RECT
.Y
-4, value
div 2, 8, 4);
2212 Inc(FDamageBuffer
, value
);
2216 FPain
:= FPain
+ value
;
2219 if g_Game_IsServer
and g_Game_IsNet
then
2221 MH_SEND_PlayerDamage(FUID
, t
, SpawnerUID
, value
, vx
, vy
);
2222 MH_SEND_PlayerStats(FUID
);
2223 MH_SEND_PlayerPos(False, FUID
);
2227 function TPlayer
.Heal(value
: Word; Soft
: Boolean): Boolean;
2230 if g_Game_IsClient
then
2235 if Soft
and (FHealth
< PLAYER_HP_SOFT
) then
2237 IncMax(FHealth
, value
, PLAYER_HP_SOFT
);
2240 if (not Soft
) and (FHealth
< PLAYER_HP_LIMIT
) then
2242 IncMax(FHealth
, value
, PLAYER_HP_LIMIT
);
2246 if Result
and g_Game_IsServer
and g_Game_IsNet
then
2247 MH_SEND_PlayerStats(FUID
);
2250 destructor TPlayer
.Destroy();
2252 if (gPlayer1
<> nil) and (gPlayer1
.FUID
= FUID
) then
2254 if (gPlayer2
<> nil) and (gPlayer2
.FUID
= FUID
) then
2258 FSawSoundIdle
.Free();
2259 FSawSoundHit
.Free();
2260 FSawSoundSelect
.Free();
2261 FFlameSoundOn
.Free();
2262 FFlameSoundOff
.Free();
2263 FFlameSoundWork
.Free();
2264 FJetSoundFly
.Free();
2266 FJetSoundOff
.Free();
2268 if FPunchAnim
<> nil then
2274 procedure TPlayer
.DrawIndicator(Color
: TRGB
);
2276 indX
, indY
, fX
, fY
, fSlope
: Integer;
2286 FObj
.lerp(gLerpFactor
, fX
, fY
);
2287 fSlope
:= nlerp(FSlopeOld
, FObj
.slopeUpLeft
, gLerpFactor
);
2289 case gPlayerIndicatorStyle
of
2292 if g_Texture_Get('TEXTURE_PLAYER_INDICATOR', ID
) then
2294 e_GetTextureSize(ID
, @indW
, @indH
);
2298 if (FObj
.X
+ FObj
.Rect
.X
) < 0 then
2301 indX
:= fX
+ FObj
.Rect
.X
+ FObj
.Rect
.Width
;
2302 indY
:= fY
+ FObj
.Rect
.Y
+ (FObj
.Rect
.Height
- indW
) div 2;
2305 else if (FObj
.X
+ FObj
.Rect
.X
+ FObj
.Rect
.Width
) > Max(gMapInfo
.Width
, gPlayerScreenSize
.X
) then
2308 indX
:= fX
+ FObj
.Rect
.X
- indH
;
2309 indY
:= fY
+ FObj
.Rect
.Y
+ (FObj
.Rect
.Height
- indW
) div 2;
2312 else if (FObj
.Y
- indH
) < 0 then
2315 indX
:= fX
+ FObj
.Rect
.X
+ (FObj
.Rect
.Width
- indW
) div 2;
2316 indY
:= fY
+ FObj
.Rect
.Y
+ FObj
.Rect
.Height
;
2322 indX
:= fX
+ FObj
.Rect
.X
+ (FObj
.Rect
.Width
- indW
) div 2;
2326 indY
:= indY
+ fSlope
;
2327 indX
:= EnsureRange(indX
, 0, Max(gMapInfo
.Width
, gPlayerScreenSize
.X
) - indW
);
2328 indY
:= EnsureRange(indY
, 0, Max(gMapInfo
.Height
, gPlayerScreenSize
.Y
) - indH
);
2332 e_DrawAdv(ID
, indX
, indY
, 0, True, False, indA
, @a
);
2339 e_TextureFontGetSize(gStdFont
, nW
, nH
);
2340 indX
:= fX
+ FObj
.Rect
.X
+ (FObj
.Rect
.Width
- Length(FName
) * nW
) div 2;
2341 indY
:= fY
- nH
+ fSlope
;
2342 e_TextureFontPrintEx(indX
, indY
, FName
, gStdFont
, Color
.R
, Color
.G
, Color
.B
, 1.0, True);
2348 procedure TPlayer
.DrawBubble();
2350 bubX
, bubY
, fX
, fY
: Integer;
2353 Rw
, Gw
, Bw
: SmallInt;
2357 CObj
:= getCameraObj();
2358 CObj
.lerp(gLerpFactor
, fX
, fY
);
2359 // NB: _F_Obj.Rect is used to keep the bubble higher; this is not a mistake
2360 bubX
:= fX
+FObj
.Rect
.X
+ IfThen(FDirection
= TDirection
.D_LEFT
, -4, 18);
2361 bubY
:= fY
+FObj
.Rect
.Y
- 18;
2369 1: // simple textual non-bubble
2371 bubX
:= fX
+FObj
.Rect
.X
- 11;
2372 bubY
:= fY
+FObj
.Rect
.Y
- 17;
2373 e_TextureFontPrint(bubX
, bubY
, '[...]', gStdFont
);
2376 2: // advanced pixel-perfect bubble
2378 if FTeam
= TEAM_RED
then
2381 if FTeam
= TEAM_BLUE
then
2384 3: // colored bubble
2386 Rb
:= FModel
.Color
.R
;
2387 Gb
:= FModel
.Color
.G
;
2388 Bb
:= FModel
.Color
.B
;
2389 Rw
:= Min(Rb
* 2 + 64, 255);
2390 Gw
:= Min(Gb
* 2 + 64, 255);
2391 Bw
:= Min(Bb
* 2 + 64, 255);
2392 if (Abs(Rw
- Rb
) < 32)
2393 or (Abs(Gw
- Gb
) < 32)
2394 or (Abs(Bw
- Bb
) < 32) then
2396 Rb
:= Max(Rw
div 2 - 16, 0);
2397 Gb
:= Max(Gw
div 2 - 16, 0);
2398 Bb
:= Max(Bw
div 2 - 16, 0);
2401 4: // custom textured bubble
2403 if g_Texture_Get('TEXTURE_PLAYER_TALKBUBBLE', ID
) then
2404 if FDirection
= TDirection
.D_RIGHT
then
2405 e_Draw(ID
, bubX
- 6, bubY
- 7, 0, True, False)
2407 e_Draw(ID
, bubX
- 6, bubY
- 7, 0, True, False, TMirrorType
.Horizontal
);
2413 e_DrawQuad(bubX
+ 1, bubY
, bubX
+ 18, bubY
+ 13, Rb
, Gb
, Bb
);
2414 e_DrawQuad(bubX
, bubY
+ 1, bubX
+ 19, bubY
+ 12, Rb
, Gb
, Bb
);
2416 e_DrawFillQuad(bubX
+ 1, bubY
+ 1, bubX
+ 18, bubY
+ 12, Rw
, Gw
, Bw
, 0);
2419 Dot
:= IfThen(FDirection
= TDirection
.D_LEFT
, 14, 5);
2420 e_DrawLine(1, bubX
+ Dot
, bubY
+ 14, bubX
+ Dot
, bubY
+ 16, Rb
, Gb
, Bb
);
2421 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
);
2422 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
);
2423 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
);
2424 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
);
2428 e_DrawFillQuad(bubX
+ Dot
, bubY
+ 8, bubX
+ Dot
+ 1, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2429 e_DrawFillQuad(bubX
+ Dot
+ 3, bubY
+ 8, bubX
+ Dot
+ 4, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2430 e_DrawFillQuad(bubX
+ Dot
+ 6, bubY
+ 8, bubX
+ Dot
+ 7, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2433 procedure TPlayer
.Draw();
2438 Mirror
: TMirrorType
;
2439 fX
, fY
, fSlope
: Integer;
2441 FObj
.lerp(gLerpFactor
, fX
, fY
);
2442 fSlope
:= nlerp(FSlopeOld
, FObj
.slopeUpLeft
, gLerpFactor
);
2446 if Direction
= TDirection
.D_RIGHT
then
2447 Mirror
:= TMirrorType
.None
2449 Mirror
:= TMirrorType
.Horizontal
;
2451 if FPunchAnim
<> nil then
2453 FPunchAnim
.Draw(fX
+IfThen(Direction
= TDirection
.D_LEFT
, 15-FObj
.Rect
.X
, FObj
.Rect
.X
-15),
2454 fY
+fSlope
+FObj
.Rect
.Y
-11, Mirror
);
2455 if FPunchAnim
.played
then
2462 if (FMegaRulez
[MR_INVUL
] > gTime
) and ((gPlayerDrawn
<> Self
) or (FSpawnInvul
>= gTime
)) then
2463 if g_Texture_Get('TEXTURE_PLAYER_INVULPENTA', ID
) then
2465 e_GetTextureSize(ID
, @w
, @h
);
2466 if FDirection
= TDirection
.D_LEFT
then
2467 e_Draw(ID
, fX
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2)-(w
div 2)+4,
2468 fY
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2)-(h
div 2)-7+fSlope
, 0, True, False)
2470 e_Draw(ID
, fX
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2)-(w
div 2)-2,
2471 fY
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2)-(h
div 2)-7+fSlope
, 0, True, False);
2474 if FMegaRulez
[MR_INVIS
] > gTime
then
2476 if (gPlayerDrawn
<> nil) and ((Self
= gPlayerDrawn
) or
2477 ((FTeam
= gPlayerDrawn
.Team
) and (gGameSettings
.GameMode
<> GM_DM
))) then
2479 if (FMegaRulez
[MR_INVIS
] - gTime
) <= 2100 then
2480 dr
:= not Odd((FMegaRulez
[MR_INVIS
] - gTime
) div 300)
2484 FModel
.Draw(fX
, fY
+fSlope
, 200)
2486 FModel
.Draw(fX
, fY
+fSlope
);
2489 FModel
.Draw(fX
, fY
+fSlope
, 254);
2492 FModel
.Draw(fX
, fY
+fSlope
);
2495 if g_debug_Frames
then
2497 e_DrawQuad(FObj
.X
+FObj
.Rect
.X
,
2499 FObj
.X
+FObj
.Rect
.X
+FObj
.Rect
.Width
-1,
2500 FObj
.Y
+FObj
.Rect
.Y
+FObj
.Rect
.Height
-1,
2504 if (gChatBubble
> 0) and (FKeys
[KEY_CHAT
].Pressed
) and not FGhost
then
2505 if (FMegaRulez
[MR_INVIS
] <= gTime
) or ((gPlayerDrawn
<> nil) and ((Self
= gPlayerDrawn
) or
2506 ((FTeam
= gPlayerDrawn
.Team
) and (gGameSettings
.GameMode
<> GM_DM
)))) then
2508 // e_DrawPoint(5, 335, 288, 255, 0, 0); // DL, UR, DL, UR
2509 if gAimLine
and alive
and
2510 ((Self
= gPlayer1
) or (Self
= gPlayer2
)) then
2515 procedure TPlayer
.DrawAim();
2516 procedure drawCast (sz
: Integer; ax0
, ay0
, ax1
, ay1
: Integer);
2521 {$IFDEF ENABLE_HOLMES}
2522 if isValidViewPort
and (self
= gPlayer1
) then
2524 g_Holmes_plrLaser(ax0
, ay0
, ax1
, ay1
);
2528 e_DrawLine(sz
, ax0
, ay0
, ax1
, ay1
, 255, 0, 0, 96);
2529 if (g_Map_traceToNearestWall(ax0
, ay0
, ax1
, ay1
, @ex
, @ey
) <> nil) then
2531 e_DrawLine(sz
, ax0
, ay0
, ex
, ey
, 0, 255, 0, 96);
2535 e_DrawLine(sz
, ax0
, ay0
, ex
, ey
, 0, 0, 255, 96);
2540 wx
, wy
, xx
, yy
: Integer;
2544 wx
:= FObj
.X
+ WEAPONPOINT
[FDirection
].X
+ IfThen(FDirection
= TDirection
.D_LEFT
, 7, -7);
2545 wy
:= FObj
.Y
+ WEAPONPOINT
[FDirection
].Y
;
2554 1: begin // Chainsaw
2561 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2562 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2563 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2564 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2569 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2570 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2571 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2572 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2574 4: begin // Double Shotgun
2577 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2578 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2579 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2580 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2582 5: begin // Chaingun
2585 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2586 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2587 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2588 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2590 6: begin // Rocket Launcher
2593 if angle
= ANGLE_RIGHTUP
then Inc(angle
, 2);
2594 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2595 if angle
= ANGLE_LEFTUP
then Dec(angle
, 2);
2596 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2598 7: begin // Plasmagun
2601 if angle
= ANGLE_RIGHTUP
then Inc(angle
);
2602 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 3);
2603 if angle
= ANGLE_LEFTUP
then Dec(angle
);
2604 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 3);
2609 if angle
= ANGLE_RIGHTUP
then Inc(angle
, 1);
2610 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 2);
2611 if angle
= ANGLE_LEFTUP
then Dec(angle
, 1);
2612 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 2);
2614 9: begin // Super Chaingun
2617 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2618 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2619 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2620 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2623 xx
:= Trunc(Cos(-DegToRad(angle
)) * len
) + wx
;
2624 yy
:= Trunc(Sin(-DegToRad(angle
)) * len
) + wy
;
2625 {$IF DEFINED(D2F_DEBUG)}
2626 drawCast(sz
, wx
, wy
, xx
, yy
);
2628 e_DrawLine(sz
, wx
, wy
, xx
, yy
, 255, 0, 0, 96);
2632 procedure TPlayer
.DrawGUI();
2635 X
, Y
, SY
, a
, p
, m
: Integer;
2639 stat
: TPlayerStatArray
;
2641 X
:= gPlayerScreenSize
.X
;
2642 SY
:= gPlayerScreenSize
.Y
;
2645 if gShowGoals
and (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
2647 if gGameSettings
.GameMode
= GM_CTF
then
2651 if gGameSettings
.GameMode
= GM_CTF
then
2653 s
:= 'TEXTURE_PLAYER_REDFLAG';
2654 if gFlags
[FLAG_RED
].State
= FLAG_STATE_CAPTURED
then
2655 s
:= 'TEXTURE_PLAYER_REDFLAG_S';
2656 if gFlags
[FLAG_RED
].State
= FLAG_STATE_DROPPED
then
2657 s
:= 'TEXTURE_PLAYER_REDFLAG_D';
2658 if g_Texture_Get(s
, ID
) then
2659 e_Draw(ID
, X
-16-32, 240-72-4, 0, True, False);
2662 s
:= IntToStr(gTeamStat
[TEAM_RED
].Goals
);
2663 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2664 e_CharFont_PrintEx(gMenuFont
, X
-16-a
-tw
, 240-72-4, s
, TEAMCOLOR
[TEAM_RED
]);
2666 if gGameSettings
.GameMode
= GM_CTF
then
2668 s
:= 'TEXTURE_PLAYER_BLUEFLAG';
2669 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_CAPTURED
then
2670 s
:= 'TEXTURE_PLAYER_BLUEFLAG_S';
2671 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_DROPPED
then
2672 s
:= 'TEXTURE_PLAYER_BLUEFLAG_D';
2673 if g_Texture_Get(s
, ID
) then
2674 e_Draw(ID
, X
-16-32, 240-32-4, 0, True, False);
2677 s
:= IntToStr(gTeamStat
[TEAM_BLUE
].Goals
);
2678 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2679 e_CharFont_PrintEx(gMenuFont
, X
-16-a
-tw
, 240-32-4, s
, TEAMCOLOR
[TEAM_BLUE
]);
2682 if g_Texture_Get('TEXTURE_PLAYER_HUDBG', ID
) then
2683 e_DrawFill(ID
, X
, 0, 1, (gPlayerScreenSize
.Y
div 256)+IfThen(gPlayerScreenSize
.Y
mod 256 > 0, 1, 0),
2686 if g_Texture_Get('TEXTURE_PLAYER_HUD', ID
) then
2687 e_Draw(ID
, X
+2, Y
, 0, True, False);
2689 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
2693 s
:= IntToStr(Frags
);
2694 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2695 e_CharFont_PrintEx(gMenuFont
, X
-16-tw
, Y
, s
, _RGB(255, 0, 0));
2700 stat
:= g_Player_GetStats();
2705 for a
:= 0 to High(stat
) do
2706 if stat
[a
].Name
<> Name
then
2708 if stat
[a
].Frags
> m
then m
:= stat
[a
].Frags
;
2709 if stat
[a
].Frags
> Frags
then p
:= p
+1;
2713 s
:= IntToStr(p
)+' / '+IntToStr(Length(stat
))+' ';
2714 if Frags
>= m
then s
:= s
+'+' else s
:= s
+'-';
2715 s
:= s
+IntToStr(Abs(Frags
-m
));
2717 e_CharFont_GetSize(gMenuSmallFont
, s
, tw
, th
);
2718 e_CharFont_PrintEx(gMenuSmallFont
, X
-16-tw
, Y
+32, s
, _RGB(255, 0, 0));
2721 if gLMSRespawn
> LMS_RESPAWN_NONE
then
2723 s
:= _lc
[I_GAME_WARMUP
];
2724 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2725 s
:= s
+ ': ' + IntToStr((gLMSRespawnTime
- gTime
) div 1000);
2726 e_CharFont_PrintEx(gMenuFont
, X
-64-tw
, SY
-32, s
, _RGB(0, 255, 0));
2728 else if gShowLives
and (gGameSettings
.MaxLives
> 0) then
2730 s
:= IntToStr(Lives
);
2731 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2732 e_CharFont_PrintEx(gMenuFont
, X
-16-tw
, SY
-32, s
, _RGB(0, 255, 0));
2736 e_CharFont_GetSize(gMenuSmallFont
, FName
, tw
, th
);
2737 e_CharFont_PrintEx(gMenuSmallFont
, X
+98-(tw
div 2), Y
+8, FName
, _RGB(255, 0, 0));
2739 if R_BERSERK
in FRulez
then
2740 e_Draw(gItemsTexturesID
[ITEM_MEDKIT_BLACK
], X
+37, Y
+45, 0, True, False)
2742 e_Draw(gItemsTexturesID
[ITEM_MEDKIT_LARGE
], X
+37, Y
+45, 0, True, False);
2744 if g_Texture_Get('TEXTURE_PLAYER_ARMORHUD', ID
) then
2745 e_Draw(ID
, X
+36, Y
+77, 0, True, False);
2747 s
:= IntToStr(IfThen(FHealth
> 0, FHealth
, 0));
2748 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2749 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+40, s
, _RGB(255, 0, 0));
2751 s
:= IntToStr(FArmor
);
2752 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2753 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+68, s
, _RGB(255, 0, 0));
2755 s
:= IntToStr(GetAmmoByWeapon(FCurrWeap
));
2761 ID
:= gItemsTexturesID
[ITEM_WEAPON_KASTET
];
2766 ID
:= gItemsTexturesID
[ITEM_WEAPON_SAW
];
2768 WEAPON_PISTOL
: ID
:= gItemsTexturesID
[ITEM_WEAPON_PISTOL
];
2769 WEAPON_CHAINGUN
: ID
:= gItemsTexturesID
[ITEM_WEAPON_CHAINGUN
];
2770 WEAPON_SHOTGUN1
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SHOTGUN1
];
2771 WEAPON_SHOTGUN2
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SHOTGUN2
];
2772 WEAPON_SUPERPULEMET
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SUPERPULEMET
];
2773 WEAPON_ROCKETLAUNCHER
: ID
:= gItemsTexturesID
[ITEM_WEAPON_ROCKETLAUNCHER
];
2774 WEAPON_PLASMA
: ID
:= gItemsTexturesID
[ITEM_WEAPON_PLASMA
];
2775 WEAPON_BFG
: ID
:= gItemsTexturesID
[ITEM_WEAPON_BFG
];
2776 WEAPON_FLAMETHROWER
: ID
:= gItemsTexturesID
[ITEM_WEAPON_FLAMETHROWER
];
2779 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2780 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+158, s
, _RGB(255, 0, 0));
2781 e_Draw(ID
, X
+20, Y
+160, 0, True, False);
2783 if R_KEY_RED
in FRulez
then
2784 e_Draw(gItemsTexturesID
[ITEM_KEY_RED
], X
+78, Y
+214, 0, True, False);
2786 if R_KEY_GREEN
in FRulez
then
2787 e_Draw(gItemsTexturesID
[ITEM_KEY_GREEN
], X
+95, Y
+214, 0, True, False);
2789 if R_KEY_BLUE
in FRulez
then
2790 e_Draw(gItemsTexturesID
[ITEM_KEY_BLUE
], X
+112, Y
+214, 0, True, False);
2792 if FJetFuel
> 0 then
2794 if g_Texture_Get('TEXTURE_PLAYER_HUDAIR', ID
) then
2795 e_Draw(ID
, X
+2, Y
+116, 0, True, False);
2796 if g_Texture_Get('TEXTURE_PLAYER_HUDJET', ID
) then
2797 e_Draw(ID
, X
+2, Y
+126, 0, True, False);
2798 e_DrawLine(4, X
+16, Y
+122, X
+16+Trunc(168*IfThen(FAir
> 0, FAir
, 0)/AIR_MAX
), Y
+122, 0, 0, 196);
2799 e_DrawLine(4, X
+16, Y
+132, X
+16+Trunc(168*FJetFuel
/JET_MAX
), Y
+132, 208, 0, 0);
2803 if g_Texture_Get('TEXTURE_PLAYER_HUDAIR', ID
) then
2804 e_Draw(ID
, X
+2, Y
+124, 0, True, False);
2805 e_DrawLine(4, X
+16, Y
+130, X
+16+Trunc(168*IfThen(FAir
> 0, FAir
, 0)/AIR_MAX
), Y
+130, 0, 0, 196);
2808 if gShowPing
and g_Game_IsClient
then
2810 s
:= _lc
[I_GAME_PING_HUD
] + IntToStr(NetPeer
.lastRoundTripTime
) + _lc
[I_NET_SLIST_PING_MS
];
2811 e_TextureFontPrint(X
+ 4, Y
+ 242, s
, gStdFont
);
2817 e_TextureFontPrint(X
+ 4, Y
+ 242, _lc
[I_PLAYER_SPECT
], gStdFont
);
2818 e_TextureFontPrint(X
+ 4, Y
+ 258, _lc
[I_PLAYER_SPECT2
], gStdFont
);
2819 e_TextureFontPrint(X
+ 4, Y
+ 274, _lc
[I_PLAYER_SPECT1
], gStdFont
);
2822 e_TextureFontGetSize(gStdFont
, cw
, ch
);
2823 s
:= _lc
[I_PLAYER_SPECT4
];
2824 e_TextureFontPrintEx(gScreenWidth
div 2 - cw
*(Length(s
) div 2),
2825 gScreenHeight
-4-ch
, s
, gStdFont
, 255, 255, 255, 1, True);
2826 e_TextureFontPrint(X
+ 4, Y
+ 290, _lc
[I_PLAYER_SPECT1S
], gStdFont
);
2832 procedure TPlayer
.DrawRulez();
2836 // Ïðè âçÿòèè íåóÿçâèìîñòè ðèñóåòñÿ èíâåðñèîííûé áåëûé ôîí
2837 if (FMegaRulez
[MR_INVUL
] >= gTime
) and (FSpawnInvul
< gTime
) then
2839 if (FMegaRulez
[MR_INVUL
]-gTime
) <= 2100 then
2840 dr
:= not Odd((FMegaRulez
[MR_INVUL
]-gTime
) div 300)
2845 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2846 191, 191, 191, 0, TBlending
.Invert
);
2849 // Ïðè âçÿòèè çàùèòíîãî êîñòþìà ðèñóåòñÿ çåëåíîâàòûé ôîí
2850 if FMegaRulez
[MR_SUIT
] >= gTime
then
2852 if (FMegaRulez
[MR_SUIT
]-gTime
) <= 2100 then
2853 dr
:= not Odd((FMegaRulez
[MR_SUIT
]-gTime
) div 300)
2858 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2859 0, 96, 0, 200, TBlending
.None
);
2862 // Ïðè âçÿòèè áåðñåðêà ðèñóåòñÿ êðàñíîâàòûé ôîí
2863 if (FBerserk
>= 0) and (LongWord(FBerserk
) >= gTime
) and (gFlash
= 2) then
2865 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2866 255, 0, 0, 200, TBlending
.None
);
2870 procedure TPlayer
.DrawPain();
2874 if FPain
= 0 then Exit
;
2878 if a
< 15 then h
:= 0
2879 else if a
< 35 then h
:= 1
2880 else if a
< 55 then h
:= 2
2881 else if a
< 75 then h
:= 3
2882 else if a
< 95 then h
:= 4
2885 //if a > 255 then a := 255;
2887 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1, 255, 0, 0, 255-h
*50);
2888 //e_DrawFillQuad(0, 0, gPlayerScreenSize.X-1, gPlayerScreenSize.Y-1, 255-min(128, a), 255-a, 255-a, 0, B_FILTER);
2891 procedure TPlayer
.DrawPickup();
2895 if FPickup
= 0 then Exit
;
2899 if a
< 15 then h
:= 1
2900 else if a
< 35 then h
:= 2
2901 else if a
< 55 then h
:= 3
2902 else if a
< 75 then h
:= 4
2905 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1, 150, 200, 150, 255-h
*50);
2908 procedure TPlayer
.DoPunch();
2913 if FPunchAnim
<> nil then begin
2918 st
:= 'FRAMES_PUNCH';
2919 if R_BERSERK
in FRulez
then
2920 st
:= st
+ '_BERSERK';
2921 if FKeys
[KEY_UP
].Pressed
then
2923 else if FKeys
[KEY_DOWN
].Pressed
then
2925 g_Frames_Get(id
, st
);
2926 FPunchAnim
:= TAnimation
.Create(id
, False, 1);
2929 procedure TPlayer
.Fire();
2931 f
, DidFire
: Boolean;
2932 wx
, wy
, xd
, yd
: Integer;
2935 if g_Game_IsClient
then Exit
;
2936 // FBFGFireCounter - âðåìÿ ïåðåä âûñòðåëîì (äëÿ BFG)
2937 // FReloading - âðåìÿ ïîñëå âûñòðåëà (äëÿ âñåãî)
2945 if FReloading
[FCurrWeap
] <> 0 then Exit
;
2950 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
2951 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
2952 xd
:= wx
+IfThen(FDirection
= TDirection
.D_LEFT
, -30, 30);
2953 yd
:= wy
+firediry();
2959 if R_BERSERK
in FRulez
then
2961 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
2962 locobj
.X
:= FObj
.X
+FObj
.Rect
.X
;
2963 locobj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
2966 locobj
.rect
.Width
:= 39;
2967 locobj
.rect
.Height
:= 52;
2968 locobj
.Vel
.X
:= (xd
-wx
) div 2;
2969 locobj
.Vel
.Y
:= (yd
-wy
) div 2;
2970 locobj
.Accel
.X
:= xd
-wx
;
2971 locobj
.Accel
.y
:= yd
-wy
;
2973 if g_Weapon_Hit(@locobj
, 50, FUID
, HIT_SOME
) <> 0 then
2974 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
2976 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
2978 if (gFlash
= 1) and (FPain
< 50) then FPain
:= min(FPain
+ 25, 50);
2982 g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
2986 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2991 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
2992 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
2994 FSawSoundSelect
.Stop();
2996 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
2998 else if not FSawSoundHit
.IsPlaying() then
3000 FSawSoundSelect
.Stop();
3001 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
3004 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3010 if FAmmo
[A_BULLETS
] > 0 then
3012 g_Weapon_pistol(wx
, wy
, xd
, yd
, FUID
);
3013 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3014 Dec(FAmmo
[A_BULLETS
]);
3015 FFireAngle
:= FAngle
;
3018 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
3019 GameVelX
, GameVelY
-2, SHELL_BULLET
);
3023 if FAmmo
[A_SHELLS
] > 0 then
3025 g_Weapon_shotgun(wx
, wy
, xd
, yd
, FUID
);
3026 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', wx
, wy
);
3027 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3028 Dec(FAmmo
[A_SHELLS
]);
3029 FFireAngle
:= FAngle
;
3033 FShellType
:= SHELL_SHELL
;
3037 if FAmmo
[A_SHELLS
] >= 2 then
3039 g_Weapon_dshotgun(wx
, wy
, xd
, yd
, FUID
);
3040 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3041 Dec(FAmmo
[A_SHELLS
], 2);
3042 FFireAngle
:= FAngle
;
3046 FShellType
:= SHELL_DBLSHELL
;
3050 if FAmmo
[A_BULLETS
] > 0 then
3052 g_Weapon_mgun(wx
, wy
, xd
, yd
, FUID
);
3053 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', wx
, wy
);
3054 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3055 Dec(FAmmo
[A_BULLETS
]);
3056 FFireAngle
:= FAngle
;
3059 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
3060 GameVelX
, GameVelY
-2, SHELL_BULLET
);
3063 WEAPON_ROCKETLAUNCHER
:
3064 if FAmmo
[A_ROCKETS
] > 0 then
3066 g_Weapon_rocket(wx
, wy
, xd
, yd
, FUID
);
3067 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3068 Dec(FAmmo
[A_ROCKETS
]);
3069 FFireAngle
:= FAngle
;
3075 if FAmmo
[A_CELLS
] > 0 then
3077 g_Weapon_plasma(wx
, wy
, xd
, yd
, FUID
);
3078 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3079 Dec(FAmmo
[A_CELLS
]);
3080 FFireAngle
:= FAngle
;
3086 if (FAmmo
[A_CELLS
] >= 40) and (FBFGFireCounter
= -1) then
3088 FBFGFireCounter
:= 17;
3089 if not FNoReload
then
3090 g_Sound_PlayExAt('SOUND_WEAPON_STARTFIREBFG', FObj
.X
, FObj
.Y
);
3091 Dec(FAmmo
[A_CELLS
], 40);
3095 WEAPON_SUPERPULEMET
:
3096 if FAmmo
[A_SHELLS
] > 0 then
3098 g_Weapon_shotgun(wx
, wy
, xd
, yd
, FUID
);
3099 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', wx
, wy
);
3100 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3101 Dec(FAmmo
[A_SHELLS
]);
3102 FFireAngle
:= FAngle
;
3105 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
3106 GameVelX
, GameVelY
-2, SHELL_SHELL
);
3109 WEAPON_FLAMETHROWER
:
3110 if FAmmo
[A_FUEL
] > 0 then
3112 g_Weapon_flame(wx
, wy
, xd
, yd
, FUID
);
3114 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3116 FFireAngle
:= FAngle
;
3123 if g_Game_IsNet
and g_Game_IsServer
then MH_SEND_PlayerStats(FUID
);
3127 if g_Game_IsNet
then
3131 if FCurrWeap
<> WEAPON_BFG
then
3132 MH_SEND_PlayerFire(FUID
, FCurrWeap
, wx
, wy
, xd
, yd
, LastShotID
)
3134 if not FNoReload
then
3135 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_WEAPON_STARTFIREBFG');
3138 MH_SEND_PlayerStats(FUID
);
3143 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
3144 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
3145 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
3148 function TPlayer
.GetAmmoByWeapon(Weapon
: Byte): Word;
3151 WEAPON_PISTOL
, WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
];
3152 WEAPON_SHOTGUN1
, WEAPON_SHOTGUN2
, WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
];
3153 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
];
3154 WEAPON_PLASMA
, WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
];
3155 WEAPON_FLAMETHROWER
: Result
:= FAmmo
[A_FUEL
];
3160 function TPlayer
.HeadInLiquid(XInc
, YInc
: Integer): Boolean;
3162 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
+XInc
, FObj
.Y
+PLAYER_HEADRECT
.Y
+YInc
,
3163 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
3164 PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, True);
3167 procedure TPlayer
.FlamerOn
;
3169 FFlameSoundOff
.Stop();
3170 FFlameSoundOff
.SetPosition(0);
3173 if (not FFlameSoundOn
.IsPlaying()) and (not FFlameSoundWork
.IsPlaying()) then
3174 FFlameSoundWork
.PlayAt(FObj
.X
, FObj
.Y
);
3178 FFlameSoundOn
.PlayAt(FObj
.X
, FObj
.Y
);
3183 procedure TPlayer
.FlamerOff
;
3187 FFlameSoundOn
.Stop();
3188 FFlameSoundOn
.SetPosition(0);
3189 FFlameSoundWork
.Stop();
3190 FFlameSoundWork
.SetPosition(0);
3191 FFlameSoundOff
.PlayAt(FObj
.X
, FObj
.Y
);
3196 procedure TPlayer
.JetpackOn
;
3200 FJetSoundOn
.SetPosition(0);
3201 FJetSoundOn
.PlayAt(FObj
.X
, FObj
.Y
);
3205 procedure TPlayer
.JetpackOff
;
3209 FJetSoundOff
.SetPosition(0);
3210 FJetSoundOff
.PlayAt(FObj
.X
, FObj
.Y
);
3213 procedure TPlayer
.CatchFire(Attacker
: Word; Timeout
: Integer = PLAYER_BURN_TIME
);
3215 if Timeout
<= 0 then
3217 if (FMegaRulez
[MR_SUIT
] > gTime
) or (FMegaRulez
[MR_INVUL
] > gTime
) then
3218 exit
; // Íå çàãîðàåìñÿ êîãäà åñòü çàùèòà
3219 if g_Obj_CollidePanel(@FObj
, 0, 0, PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
) then
3220 exit
; // Íå ïîäãîðàåì â âîäå íà âñÿêèé ñëó÷àé
3221 if FFireTime
<= 0 then
3222 g_Sound_PlayExAt('SOUND_IGNITE', FObj
.X
, FObj
.Y
);
3223 FFireTime
:= Timeout
;
3224 FFireAttacker
:= Attacker
;
3225 if g_Game_IsNet
and g_Game_IsServer
then
3226 MH_SEND_PlayerStats(FUID
);
3229 procedure TPlayer
.Jump();
3231 if gFly
or FJetpack
then
3233 // Ïîëåò (÷èò-êîä èëè äæåòïàê):
3234 if FObj
.Vel
.Y
> -VEL_FLY
then
3235 FObj
.Vel
.Y
:= FObj
.Vel
.Y
- 3;
3238 if FJetFuel
> 0 then
3240 if (FJetFuel
< 1) and g_Game_IsServer
then
3244 if g_Game_IsNet
then
3245 MH_SEND_PlayerStats(FUID
);
3251 // Íå âêëþ÷àòü äæåòïàê â ðåæèìå ïðîõîæäåíèÿ ñêâîçü ñòåíû
3253 FCanJetpack
:= False;
3255 // Ïðûãàåì èëè âñïëûâàåì:
3256 if (CollideLevel(0, 1) or
3257 g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
+36, PLAYER_RECT
.Width
,
3258 PLAYER_RECT
.Height
-33, PANEL_STEP
, False)
3259 ) and (FObj
.Accel
.Y
= 0) then // Íå ïðûãàòü, åñëè åñòü âåðòèêàëüíîå óñêîðåíèå
3261 FObj
.Vel
.Y
:= -VEL_JUMP
;
3262 FCanJetpack
:= False;
3266 if BodyInLiquid(0, 0) then
3267 FObj
.Vel
.Y
:= -VEL_SW
3268 else if (FJetFuel
> 0) and FCanJetpack
and
3269 g_Game_IsServer
and (not g_Obj_CollideLiquid(@FObj
, 0, 0)) then
3273 if g_Game_IsNet
then
3274 MH_SEND_PlayerStats(FUID
);
3279 procedure TPlayer
.Kill(KillType
: Byte; SpawnerUID
: Word; t
: Byte);
3281 a
, i
, k
, ab
, ar
: Byte;
3285 srv
, netsrv
: Boolean;
3291 procedure PushItem(t
: Byte);
3295 id
:= g_Items_Create(FObj
.X
, FObj
.Y
, t
, True, False);
3296 it
:= g_Items_ByIdx(id
);
3297 if KillType
= K_EXTRAHARDKILL
then // -7..+7; -8..0
3299 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-7+Random(15),
3300 (FObj
.Vel
.Y
div 2)-Random(9));
3301 it
.positionChanged(); // this updates spatial accelerators
3305 if KillType
= K_HARDKILL
then // -5..+5; -5..0
3307 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-5+Random(11),
3308 (FObj
.Vel
.Y
div 2)-Random(6));
3310 else // -3..+3; -3..0
3312 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-3+Random(7),
3313 (FObj
.Vel
.Y
div 2)-Random(4));
3315 it
.positionChanged(); // this updates spatial accelerators
3318 if g_Game_IsNet
and g_Game_IsServer
then
3319 MH_SEND_ItemSpawn(True, id
);
3323 DoFrags
:= (gGameSettings
.MaxLives
= 0) or (gGameSettings
.GameMode
= GM_COOP
);
3324 Srv
:= g_Game_IsServer
;
3325 Netsrv
:= g_Game_IsServer
and g_Game_IsNet
;
3326 if Srv
then FDeath
:= FDeath
+ 1;
3331 if not FPhysics
then
3337 if (gGameSettings
.MaxLives
> 0) and Srv
and (gLMSRespawn
= LMS_RESPAWN_NONE
) then
3339 if FLives
> 0 then FLives
:= FLives
- 1;
3340 if FLives
= 0 then FNoRespawn
:= True;
3343 // Íîìåð òèïà ñìåðòè:
3346 K_SIMPLEKILL
: a
:= 1;
3348 K_EXTRAHARDKILL
: a
:= 3;
3353 if not FModel
.PlaySound(MODELSOUND_DIE
, a
, FObj
.X
, FObj
.Y
) then
3355 if FModel
.PlaySound(MODELSOUND_DIE
, i
, FObj
.X
, FObj
.Y
) then
3362 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN1
;
3364 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN2
;
3365 K_EXTRAHARDKILL
, K_FALLKILL
:
3366 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN3
;
3369 // Ïåðåêëþ÷àåì ñîñòîÿíèå:
3373 K_HARDKILL
, K_EXTRAHARDKILL
:
3377 // Ðåàêöèÿ ìîíñòðîâ íà ñìåðòü èãðîêà:
3378 if (KillType
<> K_FALLKILL
) and (Srv
) then
3379 g_Monsters_killedp();
3381 if SpawnerUID
= FUID
then
3383 if Srv
and (DoFrags
or (gGameSettings
.GameMode
= GM_TDM
)) then
3388 g_Console_Add(Format(_lc
[I_PLAYER_KILL_SELF
], [FName
]), True);
3391 if g_GetUIDType(SpawnerUID
) = UID_PLAYER
then
3392 begin // Óáèò äðóãèì èãðîêîì
3393 KP
:= g_Player_Get(SpawnerUID
);
3394 if (KP
<> nil) and Srv
then
3396 if (DoFrags
or (gGameSettings
.GameMode
= GM_TDM
)) then
3397 if SameTeam(FUID
, SpawnerUID
) then
3407 if (gGameSettings
.GameMode
= GM_TDM
) and DoFrags
then
3408 Inc(gTeamStat
[KP
.Team
].Goals
,
3409 IfThen(SameTeam(FUID
, SpawnerUID
), -1, 1));
3411 if netsrv
then MH_SEND_PlayerStats(SpawnerUID
);
3414 plr
:= g_Player_Get(SpawnerUID
);
3422 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_2
],
3426 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_1
],
3430 g_Console_Add(Format(_lc
[I_PLAYER_KILL
],
3435 else if g_GetUIDType(SpawnerUID
) = UID_MONSTER
then
3436 begin // Óáèò ìîíñòðîì
3437 mon
:= g_Monsters_ByUID(SpawnerUID
);
3441 s
:= g_Mons_GetKilledByTypeId(mon
.MonsterType
);
3445 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_2
],
3449 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_1
],
3453 g_Console_Add(Format(_lc
[I_PLAYER_KILL
],
3458 else // Îñîáûå òèïû ñìåðòè
3461 HIT_SELF
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_SELF
], [FName
]), True);
3462 HIT_FALL
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_FALL
], [FName
]), True);
3463 HIT_WATER
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_WATER
], [FName
]), True);
3464 HIT_ACID
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_ACID
], [FName
]), True);
3465 HIT_TRAP
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_TRAP
], [FName
]), True);
3466 else g_Console_Add(Format(_lc
[I_PLAYER_DIED
], [FName
]), True);
3472 for a
:= WP_FIRST
to WP_LAST
do
3476 WEAPON_SAW
: i
:= ITEM_WEAPON_SAW
;
3477 WEAPON_SHOTGUN1
: i
:= ITEM_WEAPON_SHOTGUN1
;
3478 WEAPON_SHOTGUN2
: i
:= ITEM_WEAPON_SHOTGUN2
;
3479 WEAPON_CHAINGUN
: i
:= ITEM_WEAPON_CHAINGUN
;
3480 WEAPON_ROCKETLAUNCHER
: i
:= ITEM_WEAPON_ROCKETLAUNCHER
;
3481 WEAPON_PLASMA
: i
:= ITEM_WEAPON_PLASMA
;
3482 WEAPON_BFG
: i
:= ITEM_WEAPON_BFG
;
3483 WEAPON_SUPERPULEMET
: i
:= ITEM_WEAPON_SUPERPULEMET
;
3484 WEAPON_FLAMETHROWER
: i
:= ITEM_WEAPON_FLAMETHROWER
;
3493 if R_ITEM_BACKPACK
in FRulez
then
3494 PushItem(ITEM_AMMO_BACKPACK
);
3496 // Âûáðîñ ðàêåòíîãî ðàíöà:
3497 if FJetFuel
> 0 then
3498 PushItem(ITEM_JETPACK
);
3501 if (not (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
])) or
3502 (not LongBool(gGameSettings
.Options
and GAME_OPTION_DMKEYS
)) then
3504 if R_KEY_RED
in FRulez
then
3505 PushItem(ITEM_KEY_RED
);
3507 if R_KEY_GREEN
in FRulez
then
3508 PushItem(ITEM_KEY_GREEN
);
3510 if R_KEY_BLUE
in FRulez
then
3511 PushItem(ITEM_KEY_BLUE
);
3515 DropFlag(KillType
= K_FALLKILL
);
3518 FCorpse
:= g_Player_CreateCorpse(Self
);
3520 if Srv
and (gGameSettings
.MaxLives
> 0) and FNoRespawn
and
3521 (gLMSRespawn
= LMS_RESPAWN_NONE
) then
3527 for i
:= Low(gPlayers
) to High(gPlayers
) do
3529 if gPlayers
[i
] = nil then continue
;
3530 if (not gPlayers
[i
].FNoRespawn
) and (not gPlayers
[i
].FSpectator
) then
3533 if gPlayers
[i
].FTeam
= TEAM_RED
then Inc(ar
)
3534 else if gPlayers
[i
].FTeam
= TEAM_BLUE
then Inc(ab
);
3539 OldLR
:= gLMSRespawn
;
3540 if (gGameSettings
.GameMode
= GM_COOP
) then
3544 // everyone is dead, restart the map
3545 g_Game_Message(_lc
[I_MESSAGE_LMS_LOSE
], 144);
3547 MH_SEND_GameEvent(NET_EV_LMS_LOSE
);
3548 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3549 gLMSRespawnTime
:= gTime
+ 5000;
3551 else if (a
= 1) then
3553 if (gPlayers
[k
] <> nil) and not (gPlayers
[k
] is TBot
) then
3554 if (gPlayers
[k
] = gPlayer1
) or
3555 (gPlayers
[k
] = gPlayer2
) then
3556 g_Console_Add('*** ' + _lc
[I_MESSAGE_LMS_SURVIVOR
] + ' ***', True)
3557 else if Netsrv
and (gPlayers
[k
].FClientID
>= 0) then
3558 MH_SEND_GameEvent(NET_EV_LMS_SURVIVOR
, 0, 'N', gPlayers
[k
].FClientID
);
3561 else if (gGameSettings
.GameMode
= GM_TDM
) then
3563 if (ab
= 0) and (ar
<> 0) then
3566 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 144);
3568 MH_SEND_GameEvent(NET_EV_TLMS_WIN
, TEAM_RED
);
3569 Inc(gTeamStat
[TEAM_RED
].Goals
);
3570 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3571 gLMSRespawnTime
:= gTime
+ 5000;
3573 else if (ar
= 0) and (ab
<> 0) then
3576 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 144);
3578 MH_SEND_GameEvent(NET_EV_TLMS_WIN
, TEAM_BLUE
);
3579 Inc(gTeamStat
[TEAM_BLUE
].Goals
);
3580 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3581 gLMSRespawnTime
:= gTime
+ 5000;
3583 else if (ar
= 0) and (ab
= 0) then
3586 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
3588 MH_SEND_GameEvent(NET_EV_LMS_DRAW
, 0, FName
);
3589 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3590 gLMSRespawnTime
:= gTime
+ 5000;
3593 else if (gGameSettings
.GameMode
= GM_DM
) then
3597 if gPlayers
[k
] <> nil then
3600 // survivor is the winner
3601 g_Game_Message(Format(_lc
[I_MESSAGE_LMS_WIN
], [AnsiUpperCase(FName
)]), 144);
3603 MH_SEND_GameEvent(NET_EV_LMS_WIN
, 0, FName
);
3606 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3607 gLMSRespawnTime
:= gTime
+ 5000;
3609 else if (a
= 0) then
3611 // everyone is dead, restart the map
3612 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
3614 MH_SEND_GameEvent(NET_EV_LMS_DRAW
, 0, FName
);
3615 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3616 gLMSRespawnTime
:= gTime
+ 5000;
3619 if srv
and (OldLR
= LMS_RESPAWN_NONE
) and (gLMSRespawn
> LMS_RESPAWN_NONE
) then
3621 if NetMode
= NET_SERVER
then
3622 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
)
3624 g_Console_Add(Format(_lc
[I_MSG_WARMUP_START
], [(gLMSRespawnTime
- gTime
) div 1000]), True);
3630 MH_SEND_PlayerStats(FUID
);
3631 MH_SEND_PlayerDeath(FUID
, KillType
, t
, SpawnerUID
);
3632 if gGameSettings
.GameMode
= GM_TDM
then MH_SEND_GameStats
;
3635 if srv
and FNoRespawn
then Spectate(True);
3636 FWantsInGame
:= True;
3639 function TPlayer
.BodyInLiquid(XInc
, YInc
: Integer): Boolean;
3641 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
, PLAYER_RECT
.Width
,
3642 PLAYER_RECT
.Height
-20, PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, False);
3645 function TPlayer
.BodyInAcid(XInc
, YInc
: Integer): Boolean;
3647 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
, PLAYER_RECT
.Width
,
3648 PLAYER_RECT
.Height
-20, PANEL_ACID1
or PANEL_ACID2
, False);
3651 procedure TPlayer
.MakeBloodSimple(Count
: Word);
3653 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)+8,
3654 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3655 Count
div 2, 3, -1, 16, (PLAYER_RECT
.Height
*2 div 3),
3656 FModel
.Blood
.R
, FModel
.Blood
.G
, FModel
.Blood
.B
, FModel
.Blood
.Kind
);
3657 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-8,
3658 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3659 Count
div 2, -3, -1, 16, (PLAYER_RECT
.Height
*2) div 3,
3660 FModel
.Blood
.R
, FModel
.Blood
.G
, FModel
.Blood
.B
, FModel
.Blood
.Kind
);
3663 procedure TPlayer
.MakeBloodVector(Count
: Word; VelX
, VelY
: Integer);
3665 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
3666 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3667 Count
, VelX
, VelY
, 16, (PLAYER_RECT
.Height
*2) div 3,
3668 FModel
.Blood
.R
, FModel
.Blood
.G
, FModel
.Blood
.B
, FModel
.Blood
.Kind
);
3671 procedure TPlayer
.ProcessWeaponAction(Action
: Byte);
3673 if g_Game_IsClient
then Exit
;
3675 WP_PREV
: PrevWeapon();
3676 WP_NEXT
: NextWeapon();
3680 procedure TPlayer
.QueueWeaponSwitch(Weapon
: Byte);
3682 if g_Game_IsClient
then Exit
;
3683 if Weapon
> High(FWeapon
) then Exit
;
3684 FNextWeap
:= FNextWeap
or (1 shl Weapon
);
3687 procedure TPlayer
.resetWeaponQueue ();
3690 FNextWeapDelay
:= 0;
3693 function TPlayer
.hasAmmoForWeapon (weapon
: Byte): Boolean;
3697 WEAPON_KASTET
, WEAPON_SAW
: result
:= true;
3698 WEAPON_SHOTGUN1
, WEAPON_SHOTGUN2
, WEAPON_SUPERPULEMET
: result
:= (FAmmo
[A_SHELLS
] > 0);
3699 WEAPON_PISTOL
, WEAPON_CHAINGUN
: result
:= (FAmmo
[A_BULLETS
] > 0);
3700 WEAPON_ROCKETLAUNCHER
: result
:= (FAmmo
[A_ROCKETS
] > 0);
3701 WEAPON_PLASMA
, WEAPON_BFG
: result
:= (FAmmo
[A_CELLS
] > 0);
3702 WEAPON_FLAMETHROWER
: result
:= (FAmmo
[A_FUEL
] > 0);
3703 else result
:= (weapon
< length(FWeapon
));
3707 // return 255 for "no switch"
3708 function TPlayer
.getNextWeaponIndex (): Byte;
3711 wantThisWeapon
: array[0..64] of Boolean;
3712 wwc
: Integer = 0; //HACK!
3715 result
:= 255; // default result: "no switch"
3716 // had weapon cycling on previous frame? remove that flag
3717 if (FNextWeap
and $2000) <> 0 then
3719 FNextWeap
:= FNextWeap
and $1FFF;
3720 FNextWeapDelay
:= 0;
3722 // cycling has priority
3723 if (FNextWeap
and $C000) <> 0 then
3725 if (FNextWeap
and $8000) <> 0 then
3729 FNextWeap
:= FNextWeap
or $2000; // we need this
3730 if FNextWeapDelay
> 0 then
3731 exit
; // cooldown time
3733 for i
:= 0 to High(FWeapon
) do
3735 cwi
:= (cwi
+length(FWeapon
)+dir
) mod length(FWeapon
);
3736 if FWeapon
[cwi
] then
3738 //e_WriteLog(Format(' SWITCH: cur=%d; new=%d', [FCurrWeap, cwi]), MSG_WARNING);
3739 result
:= Byte(cwi
);
3740 FNextWeapDelay
:= WEAPON_DELAY
;
3748 for i
:= 0 to High(wantThisWeapon
) do
3749 wantThisWeapon
[i
] := false;
3750 for i
:= 0 to High(FWeapon
) do
3751 if (FNextWeap
and (1 shl i
)) <> 0 then
3753 wantThisWeapon
[i
] := true;
3756 // exclude currently selected weapon from the set
3757 wantThisWeapon
[FCurrWeap
] := false;
3758 // slow down alterations a little
3761 //e_WriteLog(Format(' FNextWeap=%x; delay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
3762 // more than one weapon requested, assume "alteration" and check alteration delay
3763 if FNextWeapDelay
> 0 then
3769 // do not reset weapon queue, it will be done in `RealizeCurrentWeapon()`
3770 // but clear all counters if no weapon should be switched
3776 //e_WriteLog(Format('wwc=%d', [wwc]), MSG_WARNING);
3777 // try weapons in descending order
3778 for i
:= High(FWeapon
) downto 0 do
3780 if wantThisWeapon
[i
] and FWeapon
[i
] and ((wwc
= 1) or hasAmmoForWeapon(i
)) then
3785 FNextWeapDelay
:= WEAPON_DELAY
* 2; // anyway, 'cause why not
3789 // no suitable weapon found, so reset the queue, to avoid accidental "queuing" of weapon w/o ammo
3793 procedure TPlayer
.RealizeCurrentWeapon();
3794 function switchAllowed (): Boolean;
3799 if FBFGFireCounter
<> -1 then
3801 if FTime
[T_SWITCH
] > gTime
then
3803 for i
:= WP_FIRST
to WP_LAST
do
3804 if FReloading
[i
] > 0 then
3812 //e_WriteLog(Format('***RealizeCurrentWeapon: FNextWeap=%x; FNextWeapDelay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
3813 //FNextWeap := FNextWeap and $1FFF;
3814 if FNextWeapDelay
> 0 then Dec(FNextWeapDelay
); // "alteration delay"
3816 if not switchAllowed
then
3818 //HACK for weapon cycling
3819 if (FNextWeap
and $E000) <> 0 then FNextWeap
:= 0;
3823 nw
:= getNextWeaponIndex();
3824 if nw
= 255 then exit
; // don't reset anything here
3825 if nw
> High(FWeapon
) then
3827 // don't forget to reset queue here!
3828 //e_WriteLog(' RealizeCurrentWeapon: WUTAFUUUU', MSG_WARNING);
3836 FTime
[T_SWITCH
] := gTime
+156;
3837 if FCurrWeap
= WEAPON_SAW
then FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3838 FModel
.SetWeapon(FCurrWeap
);
3839 if g_Game_IsNet
then MH_SEND_PlayerStats(FUID
);
3843 procedure TPlayer
.NextWeapon();
3845 if g_Game_IsClient
then Exit
;
3849 procedure TPlayer
.PrevWeapon();
3851 if g_Game_IsClient
then Exit
;
3855 procedure TPlayer
.SetWeapon(W
: Byte);
3857 if FCurrWeap
<> W
then
3858 if W
= WEAPON_SAW
then
3859 FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3862 FModel
.SetWeapon(CurrWeap
);
3866 function TPlayer
.PickItem(ItemType
: Byte; arespawn
: Boolean; var remove
: Boolean): Boolean;
3868 function allowBerserkSwitching (): Boolean;
3870 if (FBFGFireCounter
<> -1) then begin result
:= false; exit
; end;
3872 if gBerserkAutoswitch
then exit
;
3873 if not conIsCheatsEnabled
then exit
;
3881 if g_Game_IsClient
then Exit
;
3883 // a = true - ìåñòî ñïàâíà ïðåäìåòà:
3884 a
:= LongBool(gGameSettings
.Options
and GAME_OPTION_WEAPONSTAY
) and arespawn
;
3889 if (FHealth
< PLAYER_HP_SOFT
) or (FFireTime
> 0) then
3891 if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
3895 if gFlash
= 2 then Inc(FPickup
, 5);
3899 if (FHealth
< PLAYER_HP_SOFT
) or (FFireTime
> 0) then
3901 if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
3905 if gFlash
= 2 then Inc(FPickup
, 5);
3909 if FArmor
< PLAYER_AP_SOFT
then
3911 FArmor
:= PLAYER_AP_SOFT
;
3914 if gFlash
= 2 then Inc(FPickup
, 5);
3918 if FArmor
< PLAYER_AP_LIMIT
then
3920 FArmor
:= PLAYER_AP_LIMIT
;
3923 if gFlash
= 2 then Inc(FPickup
, 5);
3927 if (FHealth
< PLAYER_HP_LIMIT
) or (FFireTime
> 0) then
3929 if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
3933 if gFlash
= 2 then Inc(FPickup
, 5);
3937 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) or (FFireTime
> 0) then
3939 if FHealth
< PLAYER_HP_LIMIT
then
3940 FHealth
:= PLAYER_HP_LIMIT
;
3941 if FArmor
< PLAYER_AP_LIMIT
then
3942 FArmor
:= PLAYER_AP_LIMIT
;
3946 if gFlash
= 2 then Inc(FPickup
, 5);
3950 if (not FWeapon
[WEAPON_SAW
]) or ((not arespawn
) and (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
])) then
3952 FWeapon
[WEAPON_SAW
] := True;
3954 if gFlash
= 2 then Inc(FPickup
, 5);
3955 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3958 ITEM_WEAPON_SHOTGUN1
:
3959 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN1
] then
3961 // Íóæíî, ÷òîáû íå âçÿòü âñå ïóëè ñðàçó:
3962 if a
and FWeapon
[WEAPON_SHOTGUN1
] then Exit
;
3964 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3965 FWeapon
[WEAPON_SHOTGUN1
] := True;
3967 if gFlash
= 2 then Inc(FPickup
, 5);
3968 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3971 ITEM_WEAPON_SHOTGUN2
:
3972 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN2
] then
3974 if a
and FWeapon
[WEAPON_SHOTGUN2
] then Exit
;
3976 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3977 FWeapon
[WEAPON_SHOTGUN2
] := True;
3979 if gFlash
= 2 then Inc(FPickup
, 5);
3980 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3983 ITEM_WEAPON_CHAINGUN
:
3984 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or not FWeapon
[WEAPON_CHAINGUN
] then
3986 if a
and FWeapon
[WEAPON_CHAINGUN
] then Exit
;
3988 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
3989 FWeapon
[WEAPON_CHAINGUN
] := True;
3991 if gFlash
= 2 then Inc(FPickup
, 5);
3992 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3995 ITEM_WEAPON_ROCKETLAUNCHER
:
3996 if (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or not FWeapon
[WEAPON_ROCKETLAUNCHER
] then
3998 if a
and FWeapon
[WEAPON_ROCKETLAUNCHER
] then Exit
;
4000 IncMax(FAmmo
[A_ROCKETS
], 2, FMaxAmmo
[A_ROCKETS
]);
4001 FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
4003 if gFlash
= 2 then Inc(FPickup
, 5);
4004 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4008 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_PLASMA
] then
4010 if a
and FWeapon
[WEAPON_PLASMA
] then Exit
;
4012 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
4013 FWeapon
[WEAPON_PLASMA
] := True;
4015 if gFlash
= 2 then Inc(FPickup
, 5);
4016 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4020 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_BFG
] then
4022 if a
and FWeapon
[WEAPON_BFG
] then Exit
;
4024 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
4025 FWeapon
[WEAPON_BFG
] := True;
4027 if gFlash
= 2 then Inc(FPickup
, 5);
4028 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4031 ITEM_WEAPON_SUPERPULEMET
:
4032 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SUPERPULEMET
] then
4034 if a
and FWeapon
[WEAPON_SUPERPULEMET
] then Exit
;
4036 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4037 FWeapon
[WEAPON_SUPERPULEMET
] := True;
4039 if gFlash
= 2 then Inc(FPickup
, 5);
4040 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4043 ITEM_WEAPON_FLAMETHROWER
:
4044 if (FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
]) or not FWeapon
[WEAPON_FLAMETHROWER
] then
4046 if a
and FWeapon
[WEAPON_FLAMETHROWER
] then Exit
;
4048 IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
4049 FWeapon
[WEAPON_FLAMETHROWER
] := True;
4051 if gFlash
= 2 then Inc(FPickup
, 5);
4052 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4056 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
4058 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
4061 if gFlash
= 2 then Inc(FPickup
, 5);
4064 ITEM_AMMO_BULLETS_BOX
:
4065 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
4067 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
4070 if gFlash
= 2 then Inc(FPickup
, 5);
4074 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
4076 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4079 if gFlash
= 2 then Inc(FPickup
, 5);
4082 ITEM_AMMO_SHELLS_BOX
:
4083 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
4085 IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
4088 if gFlash
= 2 then Inc(FPickup
, 5);
4092 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
4094 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
4097 if gFlash
= 2 then Inc(FPickup
, 5);
4100 ITEM_AMMO_ROCKET_BOX
:
4101 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
4103 IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
4106 if gFlash
= 2 then Inc(FPickup
, 5);
4110 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
4112 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
4115 if gFlash
= 2 then Inc(FPickup
, 5);
4119 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
4121 IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
4124 if gFlash
= 2 then Inc(FPickup
, 5);
4128 if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then
4130 IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
4133 if gFlash
= 2 then Inc(FPickup
, 5);
4137 if not(R_ITEM_BACKPACK
in FRulez
) or
4138 (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
4139 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
4140 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
4141 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or
4142 (FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
]) then
4144 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[1, A_BULLETS
];
4145 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[1, A_SHELLS
];
4146 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[1, A_ROCKETS
];
4147 FMaxAmmo
[A_CELLS
] := AmmoLimits
[1, A_CELLS
];
4148 FMaxAmmo
[A_FUEL
] := AmmoLimits
[1, A_FUEL
];
4150 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
4151 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
4152 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
4153 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4154 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
4155 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
4156 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
4157 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
4158 if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then
4159 IncMax(FAmmo
[A_FUEL
], 50, FMaxAmmo
[A_FUEL
]);
4161 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
4164 if gFlash
= 2 then Inc(FPickup
, 5);
4168 if not(R_KEY_RED
in FRulez
) then
4170 Include(FRulez
, R_KEY_RED
);
4172 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
4173 if gFlash
= 2 then Inc(FPickup
, 5);
4174 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
4178 if not(R_KEY_GREEN
in FRulez
) then
4180 Include(FRulez
, R_KEY_GREEN
);
4182 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
4183 if gFlash
= 2 then Inc(FPickup
, 5);
4184 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
4188 if not(R_KEY_BLUE
in FRulez
) then
4190 Include(FRulez
, R_KEY_BLUE
);
4192 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
4193 if gFlash
= 2 then Inc(FPickup
, 5);
4194 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
4198 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
4200 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
4204 if gFlash
= 2 then Inc(FPickup
, 5);
4208 if FAir
< AIR_MAX
then
4213 if gFlash
= 2 then Inc(FPickup
, 5);
4218 if not (R_BERSERK
in FRulez
) then
4220 Include(FRulez
, R_BERSERK
);
4221 if allowBerserkSwitching
then
4223 FCurrWeap
:= WEAPON_KASTET
;
4225 FModel
.SetWeapon(WEAPON_KASTET
);
4230 if gFlash
= 2 then Inc(FPickup
, 5);
4232 FBerserk
:= gTime
+30000;
4237 if (FHealth
< PLAYER_HP_SOFT
) or (FFireTime
> 0) then
4239 if FHealth
< PLAYER_HP_SOFT
then FHealth
:= PLAYER_HP_SOFT
;
4240 FBerserk
:= gTime
+30000;
4248 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
4250 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
4254 if gFlash
= 2 then Inc(FPickup
, 5);
4258 if (FHealth
< PLAYER_HP_LIMIT
) or (FFireTime
> 0) then
4260 if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
4264 if gFlash
= 2 then Inc(FPickup
, 5);
4268 if FArmor
< PLAYER_AP_LIMIT
then
4270 IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
4273 if gFlash
= 2 then Inc(FPickup
, 5);
4277 if FJetFuel
< JET_MAX
then
4279 FJetFuel
:= JET_MAX
;
4282 if gFlash
= 2 then Inc(FPickup
, 5);
4286 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
4288 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
4291 if gFlash
= 2 then Inc(FPickup
, 5);
4296 procedure TPlayer
.Touch();
4300 //FModel.PlaySound(MODELSOUND_PAIN, 1, FObj.X, FObj.Y);
4303 // Áðîñèòü ôëàã òîâàðèùó:
4304 if gGameSettings
.GameMode
= GM_CTF
then
4309 procedure TPlayer
.Push(vx
, vy
: Integer);
4311 if (not FPhysics
) and FGhost
then
4313 FObj
.Accel
.X
:= FObj
.Accel
.X
+ vx
;
4314 FObj
.Accel
.Y
:= FObj
.Accel
.Y
+ vy
;
4315 if g_Game_IsNet
and g_Game_IsServer
then
4316 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
4319 procedure TPlayer
.Reset(Force
: Boolean);
4325 FTime
[T_RESPAWN
] := 0;
4326 FTime
[T_FLAGCAP
] := 0;
4342 FSpectator
:= False;
4345 FSpectatePlayer
:= -1;
4346 FNoRespawn
:= False;
4348 FLives
:= gGameSettings
.MaxLives
;
4353 procedure TPlayer
.SoftReset();
4361 FBFGFireCounter
:= -1;
4369 SetAction(A_STAND
, True);
4372 function TPlayer
.GetRespawnPoint(): Byte;
4377 // Íà áóäóùåå: FSpawn - èãðîê óæå èãðàë è ïåðåðîæäàåòñÿ
4379 // Îäèíî÷íàÿ èãðà/êîîïåðàòèâ
4380 if gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
] then
4382 if Self
= gPlayer1
then
4384 // player 1 should try to spawn on the player 1 point
4385 if g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) > 0 then
4386 Exit(RESPAWNPOINT_PLAYER1
)
4387 else if g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) > 0 then
4388 Exit(RESPAWNPOINT_PLAYER2
);
4390 else if Self
= gPlayer2
then
4392 // player 2 should try to spawn on the player 2 point
4393 if g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) > 0 then
4394 Exit(RESPAWNPOINT_PLAYER2
)
4395 else if g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) > 0 then
4396 Exit(RESPAWNPOINT_PLAYER1
);
4400 // other players randomly pick either the first or the second point
4401 c
:= IfThen((Random(2) = 0), RESPAWNPOINT_PLAYER1
, RESPAWNPOINT_PLAYER2
);
4402 if g_Map_GetPointCount(c
) > 0 then
4404 // try the other one
4405 c
:= IfThen((c
= RESPAWNPOINT_PLAYER1
), RESPAWNPOINT_PLAYER2
, RESPAWNPOINT_PLAYER1
);
4406 if g_Map_GetPointCount(c
) > 0 then
4412 if gGameSettings
.GameMode
= GM_DM
then
4414 // try DM points first
4415 if g_Map_GetPointCount(RESPAWNPOINT_DM
) > 0 then
4416 Exit(RESPAWNPOINT_DM
);
4420 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
4422 // try team points first
4423 c
:= RESPAWNPOINT_DM
;
4424 if FTeam
= TEAM_RED
then
4425 c
:= RESPAWNPOINT_RED
4426 else if FTeam
= TEAM_BLUE
then
4427 c
:= RESPAWNPOINT_BLUE
;
4428 if g_Map_GetPointCount(c
) > 0 then
4432 // still haven't found a spawnpoint, try random shit
4433 Result
:= g_Map_GetRandomPointType();
4436 procedure TPlayer
.Respawn(Silent
: Boolean; Force
: Boolean = False);
4438 RespawnPoint
: TRespawnPoint
;
4446 FBFGFireCounter
:= -1;
4453 if not g_Game_IsServer
then
4457 FWantsInGame
:= True;
4458 FJustTeleported
:= True;
4461 FTime
[T_RESPAWN
] := 0;
4465 // if server changes MaxLives we gotta be ready
4466 if gGameSettings
.MaxLives
= 0 then FNoRespawn
:= False;
4468 // Åùå íåëüçÿ âîçðîäèòüñÿ:
4469 if FTime
[T_RESPAWN
] > gTime
then
4472 // Ïðîñðàë âñå æèçíè:
4475 if not FSpectator
then Spectate(True);
4476 FWantsInGame
:= True;
4480 if (gGameSettings
.GameType
<> GT_SINGLE
) and (gGameSettings
.GameMode
<> GM_COOP
) then
4481 begin // "Ñâîÿ èãðà"
4482 // Áåðñåðê íå ñîõðàíÿåòñÿ ìåæäó óðîâíÿìè:
4483 FRulez
:= FRulez
-[R_BERSERK
];
4485 else // "Îäèíî÷íàÿ èãðà"/"Êîîï"
4487 // Áåðñåðê è êëþ÷è íå ñîõðàíÿþòñÿ ìåæäó óðîâíÿìè:
4488 FRulez
:= FRulez
-[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
, R_BERSERK
];
4491 // Ïîëó÷àåì òî÷êó ñïàóíà èãðîêà:
4492 c
:= GetRespawnPoint();
4497 // Âîñêðåøåíèå áåç îðóæèÿ:
4500 FHealth
:= Round(PLAYER_HP_SOFT
* (FHandicap
/ 100));
4506 for a
:= WP_FIRST
to WP_LAST
do
4508 FWeapon
[a
] := False;
4512 FWeapon
[WEAPON_PISTOL
] := True;
4513 FWeapon
[WEAPON_KASTET
] := True;
4514 FCurrWeap
:= WEAPON_PISTOL
;
4517 FModel
.SetWeapon(FCurrWeap
);
4519 for b
:= A_BULLETS
to A_HIGH
do
4522 FAmmo
[A_BULLETS
] := 50;
4524 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[0, A_BULLETS
];
4525 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[0, A_SHELLS
];
4526 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[0, A_SHELLS
];
4527 FMaxAmmo
[A_CELLS
] := AmmoLimits
[0, A_CELLS
];
4528 FMaxAmmo
[A_FUEL
] := AmmoLimits
[0, A_FUEL
];
4530 if (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
]) and
4531 LongBool(gGameSettings
.Options
and GAME_OPTION_DMKEYS
) then
4532 FRulez
:= [R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
]
4537 // Ïîëó÷àåì êîîðäèíàòû òî÷êè âîçðîæäåíèÿ:
4538 if not g_Map_GetPoint(c
, RespawnPoint
) then
4540 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
4544 // Óñòàíîâêà êîîðäèíàò è ñáðîñ âñåõ ïàðàìåòðîâ:
4545 FObj
.X
:= RespawnPoint
.X
-PLAYER_RECT
.X
;
4546 FObj
.Y
:= RespawnPoint
.Y
-PLAYER_RECT
.Y
;
4547 FObj
.oldX
:= FObj
.X
; // don't interpolate after respawn
4548 FObj
.oldY
:= FObj
.Y
;
4554 FDirection
:= RespawnPoint
.Direction
;
4555 if FDirection
= TDirection
.D_LEFT
then
4560 SetAction(A_STAND
, True);
4561 FModel
.Direction
:= FDirection
;
4563 for a
:= Low(FTime
) to High(FTime
) do
4566 for a
:= Low(FMegaRulez
) to High(FMegaRulez
) do
4569 // Respawn invulnerability
4570 if (gGameSettings
.GameType
<> GT_SINGLE
) and (gGameSettings
.SpawnInvul
> 0) then
4572 FMegaRulez
[MR_INVUL
] := gTime
+ gGameSettings
.SpawnInvul
* 1000;
4573 FSpawnInvul
:= FMegaRulez
[MR_INVUL
];
4578 FCanJetpack
:= False;
4584 // Àíèìàöèÿ âîçðîæäåíèÿ:
4585 if (not gLoadGameMode
) and (not Silent
) then
4586 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
4588 Anim
:= TAnimation
.Create(ID
, False, 3);
4589 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4590 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4594 FSpectator
:= False;
4597 FSpectatePlayer
:= -1;
4600 if (gPlayer1
= nil) and (gSpectLatchPID1
= FUID
) then
4602 if (gPlayer2
= nil) and (gSpectLatchPID2
= FUID
) then
4605 if g_Game_IsNet
then
4607 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
4608 MH_SEND_PlayerStats(FUID
, NET_EVERYONE
);
4610 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4611 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32,
4616 procedure TPlayer
.Spectate(NoMove
: Boolean = False);
4619 Kill(K_EXTRAHARDKILL
, FUID
, HIT_SOME
)
4620 else if (not NoMove
) then
4622 GameX
:= gMapInfo
.Width
div 2;
4623 GameY
:= gMapInfo
.Height
div 2;
4632 FWantsInGame
:= False;
4638 if Self
= gPlayer1
then
4640 gSpectLatchPID1
:= FUID
;
4643 else if Self
= gPlayer2
then
4645 gSpectLatchPID2
:= FUID
;
4650 if g_Game_IsNet
then
4651 MH_SEND_PlayerStats(FUID
);
4654 procedure TPlayer
.SwitchNoClip
;
4658 FGhost
:= not FGhost
;
4659 FPhysics
:= not FGhost
;
4671 procedure TPlayer
.Run(Direction
: TDirection
);
4675 if MAX_RUNVEL
> 8 then
4679 if Direction
= TDirection
.D_LEFT
then
4681 if FObj
.Vel
.X
> -MAX_RUNVEL
then
4682 FObj
.Vel
.X
:= FObj
.Vel
.X
- (MAX_RUNVEL
shr 3);
4685 if FObj
.Vel
.X
< MAX_RUNVEL
then
4686 FObj
.Vel
.X
:= FObj
.Vel
.X
+ (MAX_RUNVEL
shr 3);
4688 // Âîçìîæíî, ïèíàåì êóñêè:
4689 if (FObj
.Vel
.X
<> 0) and (gGibs
<> nil) then
4691 b
:= Abs(FObj
.Vel
.X
);
4692 if b
> 1 then b
:= b
* (Random(8 div b
) + 1);
4693 for a
:= 0 to High(gGibs
) do
4695 if gGibs
[a
].alive
and
4696 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
+FObj
.Rect
.Height
-4,
4697 FObj
.Rect
.Width
, 8, @gGibs
[a
].Obj
) and (Random(3) = 0) then
4700 if FObj
.Vel
.X
< 0 then
4702 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)+120) // íàëåâî
4706 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)); // íàïðàâî
4708 gGibs
[a
].positionChanged(); // this updates spatial accelerators
4716 procedure TPlayer
.SeeDown();
4718 SetAction(A_SEEDOWN
);
4720 if FDirection
= TDirection
.D_LEFT
then FAngle
:= ANGLE_LEFTDOWN
else FAngle
:= ANGLE_RIGHTDOWN
;
4722 if FIncCam
> -120 then DecMin(FIncCam
, 5, -120);
4725 procedure TPlayer
.SeeUp();
4729 if FDirection
= TDirection
.D_LEFT
then FAngle
:= ANGLE_LEFTUP
else FAngle
:= ANGLE_RIGHTUP
;
4731 if FIncCam
< 120 then IncMax(FIncCam
, 5, 120);
4734 procedure TPlayer
.SetAction(Action
: Byte; Force
: Boolean = False);
4742 A_ATTACK
: Prior
:= 2;
4743 A_SEEUP
: Prior
:= 1;
4744 A_SEEDOWN
: Prior
:= 1;
4745 A_ATTACKUP
: Prior
:= 2;
4746 A_ATTACKDOWN
: Prior
:= 2;
4751 if (Prior
> FActionPrior
) or Force
then
4752 if not ((Prior
= 2) and (FCurrWeap
= WEAPON_SAW
)) then
4754 FActionPrior
:= Prior
;
4755 FActionAnim
:= Action
;
4756 FActionForce
:= Force
;
4757 FActionChanged
:= True;
4760 if Action
in [A_ATTACK
, A_ATTACKUP
, A_ATTACKDOWN
] then FModel
.SetFire(True);
4763 function TPlayer
.StayOnStep(XInc
, YInc
: Integer): Boolean;
4765 Result
:= not g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
-1,
4766 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False)
4767 and g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
,
4768 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False);
4771 function TPlayer
.TeleportTo(X
, Y
: Integer; silent
: Boolean; dir
: Byte): Boolean;
4778 if g_CollideLevel(X
, Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
) then
4780 g_Sound_PlayExAt('SOUND_GAME_NOTELEPORT', FObj
.X
, FObj
.Y
);
4781 if g_Game_IsServer
and g_Game_IsNet
then
4782 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_GAME_NOTELEPORT');
4786 FJustTeleported
:= True;
4791 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
4793 Anim
:= TAnimation
.Create(ID
, False, 3);
4796 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', FObj
.X
, FObj
.Y
);
4797 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4798 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4799 if g_Game_IsServer
and g_Game_IsNet
then
4800 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4801 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 1,
4805 FObj
.X
:= X
-PLAYER_RECT
.X
;
4806 FObj
.Y
:= Y
-PLAYER_RECT
.Y
;
4807 FObj
.oldX
:= FObj
.X
; // don't interpolate after respawn
4808 FObj
.oldY
:= FObj
.Y
;
4809 if FAlive
and FGhost
then
4815 if not g_Game_IsNet
then
4819 SetDirection(TDirection
.D_LEFT
);
4825 SetDirection(TDirection
.D_RIGHT
);
4831 if FDirection
= TDirection
.D_RIGHT
then
4833 SetDirection(TDirection
.D_LEFT
);
4838 SetDirection(TDirection
.D_RIGHT
);
4844 if not silent
and (Anim
<> nil) then
4846 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4847 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4850 if g_Game_IsServer
and g_Game_IsNet
then
4851 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4852 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 0,
4859 function nonz(a
: Single): Single;
4867 function TPlayer
.refreshCorpse(): Boolean;
4873 if FAlive
or FSpectator
then
4875 if (gCorpses
= nil) or (Length(gCorpses
) = 0) then
4877 for i
:= 0 to High(gCorpses
) do
4878 if gCorpses
[i
] <> nil then
4879 if gCorpses
[i
].FPlayerUID
= FUID
then
4887 function TPlayer
.getCameraObj(): TObj
;
4889 if (not FAlive
) and (not FSpectator
) and
4890 (FCorpse
>= 0) and (FCorpse
< Length(gCorpses
)) and
4891 (gCorpses
[FCorpse
] <> nil) and (gCorpses
[FCorpse
].FPlayerUID
= FUID
) then
4893 gCorpses
[FCorpse
].FObj
.slopeUpLeft
:= FObj
.slopeUpLeft
;
4894 Result
:= gCorpses
[FCorpse
].FObj
;
4902 procedure TPlayer
.PreUpdate();
4904 FSlopeOld
:= FObj
.slopeUpLeft
;
4905 FIncCamOld
:= FIncCam
;
4906 FObj
.oldX
:= FObj
.X
;
4907 FObj
.oldY
:= FObj
.Y
;
4910 procedure TPlayer
.Update();
4913 i
, ii
, wx
, wy
, xd
, yd
, k
: Integer;
4914 blockmon
, headwater
, dospawn
: Boolean;
4919 NetServer
:= g_Game_IsNet
and g_Game_IsServer
;
4920 AnyServer
:= g_Game_IsServer
;
4922 if g_Game_IsClient
and (NetInterpLevel
> 0) then
4923 DoLerp(NetInterpLevel
+ 1)
4929 if FClientID
>= 0 then
4931 FPing
:= NetClients
[FClientID
].Peer
^.lastRoundTripTime
;
4932 if NetClients
[FClientID
].Peer
^.packetsSent
> 0 then
4933 FLoss
:= Round(100*NetClients
[FClientID
].Peer
^.packetsLost
/NetClients
[FClientID
].Peer
^.packetsSent
)
4942 if FAlive
and (FPunchAnim
<> nil) then
4943 FPunchAnim
.Update();
4945 if FAlive
and (gFly
or FJetpack
) then
4948 if FDirection
= TDirection
.D_LEFT
then
4953 if FAlive
and (not FGhost
) then
4955 if FKeys
[KEY_UP
].Pressed
then
4957 if FKeys
[KEY_DOWN
].Pressed
then
4961 if (not (FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_DOWN
].Pressed
)) and
4964 i
:= g_basic
.Sign(FIncCam
);
4965 FIncCam
:= Abs(FIncCam
);
4966 DecMin(FIncCam
, 5, 0);
4967 FIncCam
:= FIncCam
*i
;
4970 if gTime
mod (GAME_TICK
*2) <> 0 then
4972 if (FObj
.Vel
.X
= 0) and FAlive
then
4974 if FKeys
[KEY_LEFT
].Pressed
then
4975 Run(TDirection
.D_LEFT
);
4976 if FKeys
[KEY_RIGHT
].Pressed
then
4977 Run(TDirection
.D_RIGHT
);
4982 g_Obj_Move(@FObj
, True, True, True);
4983 positionChanged(); // this updates spatial accelerators
4989 FActionChanged
:= False;
4993 // Let alive player do some actions
4994 if FKeys
[KEY_LEFT
].Pressed
then Run(TDirection
.D_LEFT
);
4995 if FKeys
[KEY_RIGHT
].Pressed
then Run(TDirection
.D_RIGHT
);
4996 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then Fire()
5002 if NetServer
then MH_SEND_PlayerStats(FUID
);
5005 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Use();
5006 if FKeys
[KEY_JUMP
].Pressed
then Jump()
5009 if AnyServer
and FJetpack
then
5013 if NetServer
then MH_SEND_PlayerStats(FUID
);
5015 FCanJetpack
:= True;
5022 for k
:= Low(FKeys
) to KEY_CHAT
-1 do
5024 if FKeys
[k
].Pressed
then
5032 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
5035 if (FTime
[T_RESPAWN
] <= gTime
) and
5036 gGameOn
and (not FAlive
) then
5038 if (g_Player_GetCount() > 1) then
5042 gExit
:= EXIT_RESTART
;
5047 // Dead spectator actions
5050 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Fire();
5051 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then
5055 if (FSpectatePlayer
>= High(gPlayers
)) then
5056 FSpectatePlayer
:= -1
5060 for I
:= FSpectatePlayer
+ 1 to High(gPlayers
) do
5061 if gPlayers
[I
] <> nil then
5062 if gPlayers
[I
].alive
then
5063 if gPlayers
[I
].UID
<> FUID
then
5065 FSpectatePlayer
:= I
;
5070 if not SetSpect
then FSpectatePlayer
:= -1;
5081 if FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_JUMP
].Pressed
then
5083 FYTo
:= FObj
.Y
- 32;
5084 FSpectatePlayer
:= -1;
5086 if FKeys
[KEY_DOWN
].Pressed
then
5088 FYTo
:= FObj
.Y
+ 32;
5089 FSpectatePlayer
:= -1;
5091 if FKeys
[KEY_LEFT
].Pressed
then
5093 FXTo
:= FObj
.X
- 32;
5094 FSpectatePlayer
:= -1;
5096 if FKeys
[KEY_RIGHT
].Pressed
then
5098 FXTo
:= FObj
.X
+ 32;
5099 FSpectatePlayer
:= -1;
5102 if (FXTo
< -64) then
5104 else if (FXTo
> gMapInfo
.Width
+ 32) then
5105 FXTo
:= gMapInfo
.Width
+ 32;
5106 if (FYTo
< -72) then
5108 else if (FYTo
> gMapInfo
.Height
+ 32) then
5109 FYTo
:= gMapInfo
.Height
+ 32;
5114 g_Obj_Move(@FObj
, True, True, True);
5115 positionChanged(); // this updates spatial accelerators
5122 if (FSpectatePlayer
<= High(gPlayers
)) and (FSpectatePlayer
>= 0) then
5123 if gPlayers
[FSpectatePlayer
] <> nil then
5124 if gPlayers
[FSpectatePlayer
].alive
then
5126 FXTo
:= gPlayers
[FSpectatePlayer
].GameX
;
5127 FYTo
:= gPlayers
[FSpectatePlayer
].GameY
;
5131 blockmon
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
, FObj
.Y
+PLAYER_HEADRECT
.Y
,
5132 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
5133 PANEL_BLOCKMON
, True);
5134 headwater
:= HeadInLiquid(0, 0);
5136 // Ñîïðîòèâëåíèå âîçäóõà:
5137 if (not FAlive
) or not (FKeys
[KEY_LEFT
].Pressed
or FKeys
[KEY_RIGHT
].Pressed
) then
5138 if FObj
.Vel
.X
<> 0 then
5139 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
5141 if (FLastHit
= HIT_TRAP
) and (FPain
> 90) then FPain
:= 90;
5142 DecMin(FPain
, 5, 0);
5143 DecMin(FPickup
, 1, 0);
5145 if FAlive
and (FObj
.Y
> Integer(gMapInfo
.Height
)+128) and AnyServer
then
5147 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
5148 FMegaRulez
[MR_SUIT
] := 0;
5149 FMegaRulez
[MR_INVUL
] := 0;
5150 FMegaRulez
[MR_INVIS
] := 0;
5151 Kill(K_FALLKILL
, 0, HIT_FALL
);
5158 if FCurrWeap
= WEAPON_SAW
then
5159 if not (FSawSound
.IsPlaying() or FSawSoundHit
.IsPlaying() or
5160 FSawSoundSelect
.IsPlaying()) then
5161 FSawSoundIdle
.PlayAt(FObj
.X
, FObj
.Y
);
5164 if (not FJetSoundFly
.IsPlaying()) and (not FJetSoundOn
.IsPlaying()) and
5165 (not FJetSoundOff
.IsPlaying()) then
5167 FJetSoundFly
.SetPosition(0);
5168 FJetSoundFly
.PlayAt(FObj
.X
, FObj
.Y
);
5171 for b
:= WP_FIRST
to WP_LAST
do
5172 if FReloading
[b
] > 0 then
5178 if FShellTimer
> -1 then
5179 if FShellTimer
= 0 then
5181 if FShellType
= SHELL_SHELL
then
5182 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5183 GameVelX
, GameVelY
-2, SHELL_SHELL
)
5184 else if FShellType
= SHELL_DBLSHELL
then
5186 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5187 GameVelX
+1, GameVelY
-2, SHELL_SHELL
);
5188 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5189 GameVelX
-1, GameVelY
-2, SHELL_SHELL
);
5192 end else Dec(FShellTimer
);
5194 if (FBFGFireCounter
> -1) then
5195 if FBFGFireCounter
= 0 then
5199 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
5200 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
5201 xd
:= wx
+IfThen(FDirection
= TDirection
.D_LEFT
, -30, 30);
5202 yd
:= wy
+firediry();
5203 g_Weapon_bfgshot(wx
, wy
, xd
, yd
, FUID
);
5204 if NetServer
then MH_SEND_PlayerFire(FUID
, WEAPON_BFG
, wx
, wy
, xd
, yd
);
5205 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
5206 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
5207 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
5210 FReloading
[WEAPON_BFG
] := WEAPON_RELOAD
[WEAPON_BFG
];
5211 FBFGFireCounter
:= -1;
5214 FBFGFireCounter
:= 0
5216 Dec(FBFGFireCounter
);
5218 if (FMegaRulez
[MR_SUIT
] < gTime
) and AnyServer
then
5220 b
:= g_GetAcidHit(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
);
5222 if (b
> 0) and (gTime
mod (15*GAME_TICK
) = 0) then Damage(b
, 0, 0, 0, HIT_ACID
);
5225 if (headwater
or blockmon
) then
5231 if AnyServer
then Damage(10, 0, 0, 0, HIT_WATER
);
5234 else if (FAir
mod 31 = 0) and not blockmon
then
5236 g_GFX_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2), FObj
.Y
+PLAYER_RECT
.Y
-4, 5+Random(6), 8, 4);
5237 if Random(2) = 0 then
5238 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
5240 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
5242 end else if FAir
< AIR_DEF
then
5245 if FFireTime
> 0 then
5247 if BodyInLiquid(0, 0) then
5252 else if FMegaRulez
[MR_SUIT
] >= gTime
then
5254 if FMegaRulez
[MR_SUIT
] = gTime
then
5261 if FFirePainTime
<= 0 then
5263 if g_Game_IsServer
then
5264 Damage(2, FFireAttacker
, 0, 0, HIT_FLAME
);
5265 FFirePainTime
:= 12 - FFireTime
div 12;
5267 FFirePainTime
:= FFirePainTime
- 1;
5268 FFireTime
:= FFireTime
- 1;
5269 if ((FFireTime
mod 33) = 0) and (FMegaRulez
[MR_INVUL
] < gTime
) then
5270 FModel
.PlaySound(MODELSOUND_PAIN
, 1, FObj
.X
, FObj
.Y
);
5271 if (FFireTime
= 0) and g_Game_IsNet
and g_Game_IsServer
then
5272 MH_SEND_PlayerStats(FUID
);
5276 if FDamageBuffer
> 0 then
5278 if FDamageBuffer
>= 9 then
5282 if FDamageBuffer
< 30 then i
:= 9
5283 else if FDamageBuffer
< 100 then i
:= 18
5287 ii
:= Round(FDamageBuffer
*FHealth
/ nonz(FArmor
*(3/4)+FHealth
));
5288 FArmor
:= FArmor
-(FDamageBuffer
-ii
);
5289 FHealth
:= FHealth
-ii
;
5292 FHealth
:= FHealth
+FArmor
;
5297 if FHealth
<= 0 then
5298 if FHealth
> -30 then Kill(K_SIMPLEKILL
, FLastSpawnerUID
, FLastHit
)
5299 else if FHealth
> -50 then Kill(K_HARDKILL
, FLastSpawnerUID
, FLastHit
)
5300 else Kill(K_EXTRAHARDKILL
, FLastSpawnerUID
, FLastHit
);
5302 if FAlive
and ((FLastHit
<> HIT_FLAME
) or (FFireTime
<= 0)) then
5304 if FDamageBuffer
<= 20 then FModel
.PlaySound(MODELSOUND_PAIN
, 1, FObj
.X
, FObj
.Y
)
5305 else if FDamageBuffer
<= 55 then FModel
.PlaySound(MODELSOUND_PAIN
, 2, FObj
.X
, FObj
.Y
)
5306 else if FDamageBuffer
<= 120 then FModel
.PlaySound(MODELSOUND_PAIN
, 3, FObj
.X
, FObj
.Y
)
5307 else FModel
.PlaySound(MODELSOUND_PAIN
, 4, FObj
.X
, FObj
.Y
);
5314 end; // if FAlive then ...
5316 if (FActionAnim
= A_PAIN
) and (FModel
.Animation
<> A_PAIN
) then
5318 FModel
.ChangeAnimation(FActionAnim
, FActionForce
);
5319 FModel
.GetCurrentAnimation
.MinLength
:= i
;
5320 FModel
.GetCurrentAnimationMask
.MinLength
:= i
;
5321 end else FModel
.ChangeAnimation(FActionAnim
, FActionForce
and (FModel
.Animation
<> A_STAND
));
5323 if (FModel
.GetCurrentAnimation
.Played
or ((not FActionChanged
) and (FModel
.Animation
= A_WALK
)))
5324 then SetAction(A_STAND
, True);
5326 if not ((FModel
.Animation
= A_WALK
) and (Abs(FObj
.Vel
.X
) < 4) and not FModel
.Fire
) then FModel
.Update
;
5328 for b
:= Low(FKeys
) to High(FKeys
) do
5329 if FKeys
[b
].Time
= 0 then FKeys
[b
].Pressed
:= False else Dec(FKeys
[b
].Time
);
5333 procedure TPlayer
.getMapBox (out x
, y
, w
, h
: Integer); inline;
5335 x
:= FObj
.X
+PLAYER_RECT
.X
;
5336 y
:= FObj
.Y
+PLAYER_RECT
.Y
;
5337 w
:= PLAYER_RECT
.Width
;
5338 h
:= PLAYER_RECT
.Height
;
5342 procedure TPlayer
.moveBy (dx
, dy
: Integer); inline;
5344 if (dx
<> 0) or (dy
<> 0) then
5353 function TPlayer
.Collide(X
, Y
: Integer; Width
, Height
: Word): Boolean;
5355 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
5356 FObj
.Y
+PLAYER_RECT
.Y
,
5363 function TPlayer
.Collide(Panel
: TPanel
): Boolean;
5365 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
5366 FObj
.Y
+PLAYER_RECT
.Y
,
5370 Panel
.Width
, Panel
.Height
);
5373 function TPlayer
.Collide(X
, Y
: Integer): Boolean;
5375 X
:= X
-FObj
.X
-PLAYER_RECT
.X
;
5376 Y
:= Y
-FObj
.Y
-PLAYER_RECT
.Y
;
5377 Result
:= (x
>= 0) and (x
<= PLAYER_RECT
.Width
) and
5378 (y
>= 0) and (y
<= PLAYER_RECT
.Height
);
5381 function g_Player_ValidName(Name
: string): Boolean;
5387 if gPlayers
= nil then Exit
;
5389 for a
:= 0 to High(gPlayers
) do
5390 if gPlayers
[a
] <> nil then
5391 if LowerCase(Name
) = LowerCase(gPlayers
[a
].FName
) then
5398 procedure TPlayer
.SetDirection(Direction
: TDirection
);
5402 d
:= FModel
.Direction
;
5404 FModel
.Direction
:= Direction
;
5405 if d
<> Direction
then FModel
.ChangeAnimation(FModel
.Animation
, True);
5407 FDirection
:= Direction
;
5410 function TPlayer
.GetKeys(): Byte;
5414 if R_KEY_RED
in FRulez
then Result
:= KEY_RED
;
5415 if R_KEY_GREEN
in FRulez
then Result
:= Result
or KEY_GREEN
;
5416 if R_KEY_BLUE
in FRulez
then Result
:= Result
or KEY_BLUE
;
5418 if FTeam
= TEAM_RED
then Result
:= Result
or KEY_REDTEAM
;
5419 if FTeam
= TEAM_BLUE
then Result
:= Result
or KEY_BLUETEAM
;
5422 procedure TPlayer
.Use();
5426 if FTime
[T_USE
] > gTime
then Exit
;
5428 g_Triggers_PressR(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
,
5429 PLAYER_RECT
.Height
, FUID
, ACTIVATE_PLAYERPRESS
);
5431 for a
:= 0 to High(gPlayers
) do
5432 if (gPlayers
[a
] <> nil) and (gPlayers
[a
] <> Self
) and
5433 gPlayers
[a
].alive
and SameTeam(FUID
, gPlayers
[a
].FUID
) and
5434 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
5435 FObj
.Rect
.Width
, FObj
.Rect
.Height
, @gPlayers
[a
].FObj
) then
5437 gPlayers
[a
].Touch();
5438 if g_Game_IsNet
and g_Game_IsServer
then
5439 MH_SEND_GameEvent(NET_EV_PLAYER_TOUCH
, gPlayers
[a
].FUID
);
5442 FTime
[T_USE
] := gTime
+120;
5445 procedure TPlayer
.NetFire(Wpn
: Byte; X
, Y
, AX
, AY
: Integer; WID
: Integer = -1);
5449 WX
, WY
, XD
, YD
: Integer;
5461 if R_BERSERK
in FRulez
then
5463 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
5464 locobj
.X
:= FObj
.X
+FObj
.Rect
.X
;
5465 locobj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
5468 locobj
.rect
.Width
:= 39;
5469 locobj
.rect
.Height
:= 52;
5470 locobj
.Vel
.X
:= (xd
-wx
) div 2;
5471 locobj
.Vel
.Y
:= (yd
-wy
) div 2;
5472 locobj
.Accel
.X
:= xd
-wx
;
5473 locobj
.Accel
.y
:= yd
-wy
;
5475 if g_Weapon_Hit(@locobj
, 50, FUID
, HIT_SOME
) <> 0 then
5476 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
5478 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
5482 FPain
:= min(FPain
+ 25, 50);
5484 g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
5489 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
5490 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
5492 FSawSoundSelect
.Stop();
5494 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
5496 else if not FSawSoundHit
.IsPlaying() then
5498 FSawSoundSelect
.Stop();
5499 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
5506 g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', GameX
, Gamey
);
5507 FFireAngle
:= FAngle
;
5509 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5510 GameVelX
, GameVelY
-2, SHELL_BULLET
);
5515 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
5516 FFireAngle
:= FAngle
;
5519 FShellType
:= SHELL_SHELL
;
5524 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN2', Gamex
, Gamey
);
5525 FFireAngle
:= FAngle
;
5528 FShellType
:= SHELL_DBLSHELL
;
5533 g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', Gamex
, Gamey
);
5534 FFireAngle
:= FAngle
;
5536 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5537 GameVelX
, GameVelY
-2, SHELL_BULLET
);
5540 WEAPON_ROCKETLAUNCHER
:
5542 g_Weapon_Rocket(wx
, wy
, xd
, yd
, FUID
, WID
);
5543 FFireAngle
:= FAngle
;
5549 g_Weapon_Plasma(wx
, wy
, xd
, yd
, FUID
, WID
);
5550 FFireAngle
:= FAngle
;
5556 g_Weapon_BFGShot(wx
, wy
, xd
, yd
, FUID
, WID
);
5557 FFireAngle
:= FAngle
;
5561 WEAPON_SUPERPULEMET
:
5563 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
5564 FFireAngle
:= FAngle
;
5566 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5567 GameVelX
, GameVelY
-2, SHELL_SHELL
);
5570 WEAPON_FLAMETHROWER
:
5572 g_Weapon_flame(wx
, wy
, xd
, yd
, FUID
, WID
);
5574 FFireAngle
:= FAngle
;
5581 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
5582 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
5583 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
5586 procedure TPlayer
.DoLerp(Level
: Integer = 2);
5588 if FObj
.X
<> FXTo
then FObj
.X
:= Lerp(FObj
.X
, FXTo
, Level
);
5589 if FObj
.Y
<> FYTo
then FObj
.Y
:= Lerp(FObj
.Y
, FYTo
, Level
);
5592 procedure TPlayer
.SetLerp(XTo
, YTo
: Integer);
5598 if FJustTeleported
or (NetInterpLevel
< 1) then
5602 if FJustTeleported
then
5604 FObj
.oldX
:= FObj
.X
;
5605 FObj
.oldY
:= FObj
.Y
;
5610 AX
:= Abs(FXTo
- FObj
.X
);
5611 AY
:= Abs(FYTo
- FObj
.Y
);
5612 if (AX
> 32) or (AX
<= NetInterpLevel
) then
5614 if (AY
> 32) or (AY
<= NetInterpLevel
) then
5619 function TPlayer
.FullInLift(XInc
, YInc
: Integer): Integer;
5621 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5622 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5623 PANEL_LIFTUP
, False) then Result
:= -1
5625 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5626 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5627 PANEL_LIFTDOWN
, False) then Result
:= 1
5631 function TPlayer
.GetFlag(Flag
: Byte): Boolean;
5638 if Flag
= FLAG_NONE
then
5641 if not g_Game_IsServer
then Exit
;
5643 // Ïðèíåñ ÷óæîé ôëàã íà ñâîþ áàçó:
5644 if (Flag
= FTeam
) and
5645 (gFlags
[Flag
].State
= FLAG_STATE_NORMAL
) and
5646 (FFlag
<> FLAG_NONE
) then
5648 if FFlag
= FLAG_RED
then
5649 s
:= _lc
[I_PLAYER_FLAG_RED
]
5651 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5653 evtype
:= FLAG_STATE_SCORED
;
5655 ts
:= Format('%.4d', [gFlags
[FFlag
].CaptureTime
]);
5656 Insert('.', ts
, Length(ts
) + 1 - 3);
5657 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_CAPTURE
], [FName
, s
, ts
]), True);
5659 g_Map_ResetFlag(FFlag
);
5660 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_CAPTURE
], [AnsiUpperCase(s
)]), 144);
5662 if ((Self
= gPlayer1
) or (Self
= gPlayer2
)
5663 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= FTeam
))
5664 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= FTeam
))) then
5669 if not sound_cap_flag
[a
].IsPlaying() then
5670 sound_cap_flag
[a
].Play();
5672 gTeamStat
[FTeam
].Goals
:= gTeamStat
[FTeam
].Goals
+ 1;
5675 if g_Game_IsNet
then
5677 MH_SEND_FlagEvent(evtype
, FFlag
, FUID
, False);
5681 gFlags
[FFlag
].CaptureTime
:= 0;
5686 // Ïîäîáðàë ñâîé ôëàã - âåðíóë åãî íà áàçó:
5687 if (Flag
= FTeam
) and
5688 (gFlags
[Flag
].State
= FLAG_STATE_DROPPED
) then
5690 if Flag
= FLAG_RED
then
5691 s
:= _lc
[I_PLAYER_FLAG_RED
]
5693 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5695 evtype
:= FLAG_STATE_RETURNED
;
5696 gFlags
[Flag
].CaptureTime
:= 0;
5698 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_RETURN
], [FName
, s
]), True);
5700 g_Map_ResetFlag(Flag
);
5701 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
5703 if ((Self
= gPlayer1
) or (Self
= gPlayer2
)
5704 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= FTeam
))
5705 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= FTeam
))) then
5710 if not sound_ret_flag
[a
].IsPlaying() then
5711 sound_ret_flag
[a
].Play();
5714 if g_Game_IsNet
then
5716 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5722 // Ïîäîáðàë ÷óæîé ôëàã:
5723 if (Flag
<> FTeam
) and (FTime
[T_FLAGCAP
] <= gTime
) then
5727 if Flag
= FLAG_RED
then
5728 s
:= _lc
[I_PLAYER_FLAG_RED
]
5730 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5732 evtype
:= FLAG_STATE_CAPTURED
;
5734 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_GET
], [FName
, s
]), True);
5736 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_GET
], [AnsiUpperCase(s
)]), 144);
5738 gFlags
[Flag
].State
:= FLAG_STATE_CAPTURED
;
5740 if ((Self
= gPlayer1
) or (Self
= gPlayer2
)
5741 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= FTeam
))
5742 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= FTeam
))) then
5747 if not sound_get_flag
[a
].IsPlaying() then
5748 sound_get_flag
[a
].Play();
5751 if g_Game_IsNet
then
5753 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5759 procedure TPlayer
.SetFlag(Flag
: Byte);
5762 if FModel
<> nil then
5763 FModel
.SetFlag(FFlag
);
5766 function TPlayer
.DropFlag(Silent
: Boolean = True): Boolean;
5772 if (not g_Game_IsServer
) or (FFlag
= FLAG_NONE
) then
5774 FTime
[T_FLAGCAP
] := gTime
+ 2000;
5775 with gFlags
[FFlag
] do
5779 Direction
:= FDirection
;
5780 State
:= FLAG_STATE_DROPPED
;
5782 g_Obj_Push(@Obj
, (FObj
.Vel
.X
div 2)-2+Random(5),
5783 (FObj
.Vel
.Y
div 2)-2+Random(5));
5784 positionChanged(); // this updates spatial accelerators
5786 if FFlag
= FLAG_RED
then
5787 s
:= _lc
[I_PLAYER_FLAG_RED
]
5789 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5791 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_DROP
], [FName
, s
]), True);
5792 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_DROP
], [AnsiUpperCase(s
)]), 144);
5794 if ((Self
= gPlayer1
) or (Self
= gPlayer2
)
5795 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= FTeam
))
5796 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= FTeam
))) then
5801 if (not Silent
) and (not sound_lost_flag
[a
].IsPlaying()) then
5802 sound_lost_flag
[a
].Play();
5804 if g_Game_IsNet
then
5805 MH_SEND_FlagEvent(FLAG_STATE_DROPPED
, Flag
, FUID
, False);
5811 procedure TPlayer
.GetSecret();
5813 if (self
= gPlayer1
) or (self
= gPlayer2
) then
5815 g_Console_Add(Format(_lc
[I_PLAYER_SECRET
], [FName
]), True);
5816 g_Sound_PlayEx('SOUND_GAME_SECRET');
5821 procedure TPlayer
.PressKey(Key
: Byte; Time
: Word = 1);
5823 Assert(Key
<= High(FKeys
));
5825 FKeys
[Key
].Pressed
:= True;
5826 FKeys
[Key
].Time
:= Time
;
5829 function TPlayer
.IsKeyPressed(K
: Byte): Boolean;
5831 Result
:= FKeys
[K
].Pressed
;
5834 procedure TPlayer
.ReleaseKeys();
5838 for a
:= Low(FKeys
) to High(FKeys
) do
5840 FKeys
[a
].Pressed
:= False;
5845 procedure TPlayer
.OnDamage(Angle
: SmallInt);
5849 function TPlayer
.firediry(): Integer;
5851 if FKeys
[KEY_UP
].Pressed
then Result
:= -42
5852 else if FKeys
[KEY_DOWN
].Pressed
then Result
:= 19
5856 procedure TPlayer
.RememberState();
5859 SavedState
: TPlayerSavedState
;
5861 SavedState
.Health
:= FHealth
;
5862 SavedState
.Armor
:= FArmor
;
5863 SavedState
.Air
:= FAir
;
5864 SavedState
.JetFuel
:= FJetFuel
;
5865 SavedState
.CurrWeap
:= FCurrWeap
;
5866 SavedState
.NextWeap
:= FNextWeap
;
5867 SavedState
.NextWeapDelay
:= FNextWeapDelay
;
5868 for i
:= Low(FWeapon
) to High(FWeapon
) do
5869 SavedState
.Weapon
[i
] := FWeapon
[i
];
5870 for i
:= Low(FAmmo
) to High(FAmmo
) do
5871 SavedState
.Ammo
[i
] := FAmmo
[i
];
5872 for i
:= Low(FMaxAmmo
) to High(FMaxAmmo
) do
5873 SavedState
.MaxAmmo
[i
] := FMaxAmmo
[i
];
5874 SavedState
.Rulez
:= FRulez
- [R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
];
5876 FSavedStateNum
:= -1;
5877 for i
:= Low(SavedStates
) to High(SavedStates
) do
5878 if not SavedStates
[i
].Used
then
5880 FSavedStateNum
:= i
;
5883 if FSavedStateNum
< 0 then
5885 SetLength(SavedStates
, Length(SavedStates
) + 1);
5886 FSavedStateNum
:= High(SavedStates
);
5889 SavedState
.Used
:= True;
5890 SavedStates
[FSavedStateNum
] := SavedState
;
5893 procedure TPlayer
.RecallState();
5896 SavedState
: TPlayerSavedState
;
5898 if(FSavedStateNum
< 0) or (FSavedStateNum
> High(SavedStates
)) then
5901 SavedState
:= SavedStates
[FSavedStateNum
];
5902 SavedStates
[FSavedStateNum
].Used
:= False;
5903 FSavedStateNum
:= -1;
5905 FHealth
:= SavedState
.Health
;
5906 FArmor
:= SavedState
.Armor
;
5907 FAir
:= SavedState
.Air
;
5908 FJetFuel
:= SavedState
.JetFuel
;
5909 FCurrWeap
:= SavedState
.CurrWeap
;
5910 FNextWeap
:= SavedState
.NextWeap
;
5911 FNextWeapDelay
:= SavedState
.NextWeapDelay
;
5912 for i
:= Low(FWeapon
) to High(FWeapon
) do
5913 FWeapon
[i
] := SavedState
.Weapon
[i
];
5914 for i
:= Low(FAmmo
) to High(FAmmo
) do
5915 FAmmo
[i
] := SavedState
.Ammo
[i
];
5916 for i
:= Low(FMaxAmmo
) to High(FMaxAmmo
) do
5917 FMaxAmmo
[i
] := SavedState
.MaxAmmo
[i
];
5918 FRulez
:= SavedState
.Rulez
;
5920 if gGameSettings
.GameType
= GT_SERVER
then
5921 MH_SEND_PlayerStats(FUID
);
5924 procedure TPlayer
.SaveState (st
: TStream
);
5930 utils
.writeSign(st
, 'PLYR');
5931 utils
.writeInt(st
, Byte(PLR_SAVE_VERSION
)); // version
5933 utils
.writeBool(st
, FIamBot
);
5935 utils
.writeInt(st
, Word(FUID
));
5937 utils
.writeStr(st
, FName
);
5939 utils
.writeInt(st
, Byte(FTeam
));
5941 utils
.writeBool(st
, FAlive
);
5942 // Èçðàñõîäîâàë ëè âñå æèçíè
5943 utils
.writeBool(st
, FNoRespawn
);
5945 if FDirection
= TDirection
.D_LEFT
then b
:= 1 else b
:= 2; // D_RIGHT
5946 utils
.writeInt(st
, Byte(b
));
5948 utils
.writeInt(st
, LongInt(FHealth
));
5949 // Êîýôôèöèåíò èíâàëèäíîñòè
5950 utils
.writeInt(st
, LongInt(FHandicap
));
5952 utils
.writeInt(st
, Byte(FLives
));
5954 utils
.writeInt(st
, LongInt(FArmor
));
5956 utils
.writeInt(st
, LongInt(FAir
));
5958 utils
.writeInt(st
, LongInt(FJetFuel
));
5960 utils
.writeInt(st
, LongInt(FPain
));
5962 utils
.writeInt(st
, LongInt(FKills
));
5964 utils
.writeInt(st
, LongInt(FMonsterKills
));
5966 utils
.writeInt(st
, LongInt(FFrags
));
5968 utils
.writeInt(st
, Byte(FFragCombo
));
5969 // Âðåìÿ ïîñëåäíåãî ôðàãà
5970 utils
.writeInt(st
, LongWord(FLastFrag
));
5972 utils
.writeInt(st
, LongInt(FDeath
));
5974 utils
.writeInt(st
, Byte(FFlag
));
5976 utils
.writeInt(st
, LongInt(FSecrets
));
5978 utils
.writeInt(st
, Byte(FCurrWeap
));
5980 utils
.writeInt(st
, Word(FNextWeap
));
5982 utils
.writeInt(st
, Byte(FNextWeapDelay
));
5983 // Âðåìÿ çàðÿäêè BFG
5984 utils
.writeInt(st
, SmallInt(FBFGFireCounter
));
5986 utils
.writeInt(st
, LongInt(FDamageBuffer
));
5987 // Ïîñëåäíèé óäàðèâøèé
5988 utils
.writeInt(st
, Word(FLastSpawnerUID
));
5989 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà
5990 utils
.writeInt(st
, Byte(FLastHit
));
5992 Obj_SaveState(st
, @FObj
);
5993 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ
5994 for i
:= A_BULLETS
to A_HIGH
do utils
.writeInt(st
, Word(FAmmo
[i
]));
5995 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ
5996 for i
:= A_BULLETS
to A_HIGH
do utils
.writeInt(st
, Word(FMaxAmmo
[i
]));
5998 for i
:= WP_FIRST
to WP_LAST
do utils
.writeBool(st
, FWeapon
[i
]);
5999 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ
6000 for i
:= WP_FIRST
to WP_LAST
do utils
.writeInt(st
, Word(FReloading
[i
]));
6002 utils
.writeBool(st
, (R_ITEM_BACKPACK
in FRulez
));
6003 // Íàëè÷èå êðàñíîãî êëþ÷à
6004 utils
.writeBool(st
, (R_KEY_RED
in FRulez
));
6005 // Íàëè÷èå çåëåíîãî êëþ÷à
6006 utils
.writeBool(st
, (R_KEY_GREEN
in FRulez
));
6007 // Íàëè÷èå ñèíåãî êëþ÷à
6008 utils
.writeBool(st
, (R_KEY_BLUE
in FRulez
));
6010 utils
.writeBool(st
, (R_BERSERK
in FRulez
));
6011 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ
6012 for i
:= MR_SUIT
to MR_MAX
do utils
.writeInt(st
, LongWord(FMegaRulez
[i
]));
6013 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà
6014 for i
:= T_RESPAWN
to T_FLAGCAP
do utils
.writeInt(st
, LongWord(FTime
[i
]));
6016 utils
.writeStr(st
, FModel
.Name
);
6018 utils
.writeInt(st
, Byte(FColor
.R
));
6019 utils
.writeInt(st
, Byte(FColor
.G
));
6020 utils
.writeInt(st
, Byte(FColor
.B
));
6024 procedure TPlayer
.LoadState (st
: TStream
);
6033 if not utils
.checkSign(st
, 'PLYR') then raise XStreamError
.Create('invalid player signature');
6034 if (utils
.readByte(st
) <> PLR_SAVE_VERSION
) then raise XStreamError
.Create('invalid player version');
6036 FIamBot
:= utils
.readBool(st
);
6038 FUID
:= utils
.readWord(st
);
6040 str
:= utils
.readStr(st
);
6041 if (self
<> gPlayer1
) and (self
<> gPlayer2
) then FName
:= str
;
6043 FTeam
:= utils
.readByte(st
);
6045 FAlive
:= utils
.readBool(st
);
6046 // Èçðàñõîäîâàë ëè âñå æèçíè
6047 FNoRespawn
:= utils
.readBool(st
);
6049 b
:= utils
.readByte(st
);
6050 if b
= 1 then FDirection
:= TDirection
.D_LEFT
else FDirection
:= TDirection
.D_RIGHT
; // b = 2
6052 FHealth
:= utils
.readLongInt(st
);
6053 // Êîýôôèöèåíò èíâàëèäíîñòè
6054 FHandicap
:= utils
.readLongInt(st
);
6056 FLives
:= utils
.readByte(st
);
6058 FArmor
:= utils
.readLongInt(st
);
6060 FAir
:= utils
.readLongInt(st
);
6062 FJetFuel
:= utils
.readLongInt(st
);
6064 FPain
:= utils
.readLongInt(st
);
6066 FKills
:= utils
.readLongInt(st
);
6068 FMonsterKills
:= utils
.readLongInt(st
);
6070 FFrags
:= utils
.readLongInt(st
);
6072 FFragCombo
:= utils
.readByte(st
);
6073 // Âðåìÿ ïîñëåäíåãî ôðàãà
6074 FLastFrag
:= utils
.readLongWord(st
);
6076 FDeath
:= utils
.readLongInt(st
);
6078 FFlag
:= utils
.readByte(st
);
6080 FSecrets
:= utils
.readLongInt(st
);
6082 FCurrWeap
:= utils
.readByte(st
);
6084 FNextWeap
:= utils
.readWord(st
);
6086 FNextWeapDelay
:= utils
.readByte(st
);
6087 // Âðåìÿ çàðÿäêè BFG
6088 FBFGFireCounter
:= utils
.readSmallInt(st
);
6090 FDamageBuffer
:= utils
.readLongInt(st
);
6091 // Ïîñëåäíèé óäàðèâøèé
6092 FLastSpawnerUID
:= utils
.readWord(st
);
6093 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà
6094 FLastHit
:= utils
.readByte(st
);
6096 Obj_LoadState(@FObj
, st
);
6097 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ
6098 for i
:= A_BULLETS
to A_HIGH
do FAmmo
[i
] := utils
.readWord(st
);
6099 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ
6100 for i
:= A_BULLETS
to A_HIGH
do FMaxAmmo
[i
] := utils
.readWord(st
);
6102 for i
:= WP_FIRST
to WP_LAST
do FWeapon
[i
] := utils
.readBool(st
);
6103 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ
6104 for i
:= WP_FIRST
to WP_LAST
do FReloading
[i
] := utils
.readWord(st
);
6106 if utils
.readBool(st
) then Include(FRulez
, R_ITEM_BACKPACK
);
6107 // Íàëè÷èå êðàñíîãî êëþ÷à
6108 if utils
.readBool(st
) then Include(FRulez
, R_KEY_RED
);
6109 // Íàëè÷èå çåëåíîãî êëþ÷à
6110 if utils
.readBool(st
) then Include(FRulez
, R_KEY_GREEN
);
6111 // Íàëè÷èå ñèíåãî êëþ÷à
6112 if utils
.readBool(st
) then Include(FRulez
, R_KEY_BLUE
);
6114 if utils
.readBool(st
) then Include(FRulez
, R_BERSERK
);
6115 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ
6116 for i
:= MR_SUIT
to MR_MAX
do FMegaRulez
[i
] := utils
.readLongWord(st
);
6117 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà
6118 for i
:= T_RESPAWN
to T_FLAGCAP
do FTime
[i
] := utils
.readLongWord(st
);
6120 str
:= utils
.readStr(st
);
6122 FColor
.R
:= utils
.readByte(st
);
6123 FColor
.G
:= utils
.readByte(st
);
6124 FColor
.B
:= utils
.readByte(st
);
6125 if (self
= gPlayer1
) then
6127 str
:= gPlayer1Settings
.Model
;
6128 FColor
:= gPlayer1Settings
.Color
;
6130 else if (self
= gPlayer2
) then
6132 str
:= gPlayer2Settings
.Model
;
6133 FColor
:= gPlayer2Settings
.Color
;
6135 // Îáíîâëÿåì ìîäåëü èãðîêà
6137 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
6138 FModel
.Color
:= TEAMCOLOR
[FTeam
]
6140 FModel
.Color
:= FColor
;
6144 procedure TPlayer
.AllRulez(Health
: Boolean);
6150 FHealth
:= PLAYER_HP_LIMIT
;
6151 FArmor
:= PLAYER_AP_LIMIT
;
6155 for a
:= WP_FIRST
to WP_LAST
do FWeapon
[a
] := True;
6156 for a
:= A_BULLETS
to A_HIGH
do FAmmo
[a
] := 30000;
6157 FRulez
:= FRulez
+[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
];
6160 procedure TPlayer
.RestoreHealthArmor();
6162 FHealth
:= PLAYER_HP_LIMIT
;
6163 FArmor
:= PLAYER_AP_LIMIT
;
6166 procedure TPlayer
.FragCombo();
6170 if (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) or g_Game_IsClient
then
6172 if gTime
- FLastFrag
< FRAG_COMBO_TIME
then
6174 if FFragCombo
< 5 then
6176 Param
:= FUID
or (FFragCombo
shl 16);
6177 if (FComboEvnt
>= Low(gDelayedEvents
)) and
6178 (FComboEvnt
<= High(gDelayedEvents
)) and
6179 gDelayedEvents
[FComboEvnt
].Pending
and
6180 (gDelayedEvents
[FComboEvnt
].DEType
= DE_KILLCOMBO
) and
6181 (gDelayedEvents
[FComboEvnt
].DENum
and $FFFF = FUID
) then
6183 gDelayedEvents
[FComboEvnt
].Time
:= gTime
+ 500;
6184 gDelayedEvents
[FComboEvnt
].DENum
:= Param
;
6187 FComboEvnt
:= g_Game_DelayEvent(DE_KILLCOMBO
, 500, Param
);
6195 procedure TPlayer
.GiveItem(ItemType
: Byte);
6199 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
6201 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
6205 if FAir
< AIR_MAX
then
6212 if not (R_BERSERK
in FRulez
) then
6214 Include(FRulez
, R_BERSERK
);
6215 if FBFGFireCounter
< 1 then
6217 FCurrWeap
:= WEAPON_KASTET
;
6219 FModel
.SetWeapon(WEAPON_KASTET
);
6223 FBerserk
:= gTime
+30000;
6225 if FHealth
< PLAYER_HP_SOFT
then
6227 FHealth
:= PLAYER_HP_SOFT
;
6228 FBerserk
:= gTime
+30000;
6233 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
6235 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
6240 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
6242 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
6246 if FJetFuel
< JET_MAX
then
6248 FJetFuel
:= JET_MAX
;
6251 ITEM_MEDKIT_SMALL
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
6252 ITEM_MEDKIT_LARGE
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
6254 ITEM_ARMOR_GREEN
: if FArmor
< PLAYER_AP_SOFT
then FArmor
:= PLAYER_AP_SOFT
;
6255 ITEM_ARMOR_BLUE
: if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
6257 ITEM_SPHERE_BLUE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
6259 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) then
6261 if FHealth
< PLAYER_HP_LIMIT
then FHealth
:= PLAYER_HP_LIMIT
;
6262 if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
6265 ITEM_WEAPON_SAW
: FWeapon
[WEAPON_SAW
] := True;
6266 ITEM_WEAPON_SHOTGUN1
: FWeapon
[WEAPON_SHOTGUN1
] := True;
6267 ITEM_WEAPON_SHOTGUN2
: FWeapon
[WEAPON_SHOTGUN2
] := True;
6268 ITEM_WEAPON_CHAINGUN
: FWeapon
[WEAPON_CHAINGUN
] := True;
6269 ITEM_WEAPON_ROCKETLAUNCHER
: FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
6270 ITEM_WEAPON_PLASMA
: FWeapon
[WEAPON_PLASMA
] := True;
6271 ITEM_WEAPON_BFG
: FWeapon
[WEAPON_BFG
] := True;
6272 ITEM_WEAPON_SUPERPULEMET
: FWeapon
[WEAPON_SUPERPULEMET
] := True;
6273 ITEM_WEAPON_FLAMETHROWER
: FWeapon
[WEAPON_FLAMETHROWER
] := True;
6275 ITEM_AMMO_BULLETS
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
6276 ITEM_AMMO_BULLETS_BOX
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
6277 ITEM_AMMO_SHELLS
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
6278 ITEM_AMMO_SHELLS_BOX
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
6279 ITEM_AMMO_ROCKET
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
6280 ITEM_AMMO_ROCKET_BOX
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
6281 ITEM_AMMO_CELL
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
6282 ITEM_AMMO_CELL_BIG
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
6283 ITEM_AMMO_FUELCAN
: if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
6286 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
6287 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
6288 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
6289 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or
6290 (FMaxAmmo
[A_FUEL
] < AmmoLimits
[1, A_FUEL
]) then
6292 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[1, A_BULLETS
];
6293 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[1, A_SHELLS
];
6294 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[1, A_ROCKETS
];
6295 FMaxAmmo
[A_CELLS
] := AmmoLimits
[1, A_CELLS
];
6296 FMaxAmmo
[A_FUEL
] := AmmoLimits
[1, A_FUEL
];
6298 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
6299 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
6300 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
6301 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
6303 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
6306 ITEM_KEY_RED
: if not (R_KEY_RED
in FRulez
) then Include(FRulez
, R_KEY_RED
);
6307 ITEM_KEY_GREEN
: if not (R_KEY_GREEN
in FRulez
) then Include(FRulez
, R_KEY_GREEN
);
6308 ITEM_KEY_BLUE
: if not (R_KEY_BLUE
in FRulez
) then Include(FRulez
, R_KEY_BLUE
);
6310 ITEM_BOTTLE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
6311 ITEM_HELMET
: if FArmor
< PLAYER_AP_LIMIT
then IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
6316 if g_Game_IsNet
and g_Game_IsServer
then
6317 MH_SEND_PlayerStats(FUID
);
6320 procedure TPlayer
.FlySmoke(Times
: DWORD
= 1);
6325 if (Random(5) = 1) and (Times
= 1) then
6328 if BodyInLiquid(0, 0) then
6330 g_GFX_Bubbles(Obj
.X
+Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2)+Random(3)-1,
6331 Obj
.Y
+Obj
.Rect
.Height
+8, 1, 8, 4);
6332 if Random(2) = 0 then
6333 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
6335 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
6339 if g_Frames_Get(id
, 'FRAMES_SMOKE') then
6341 for i
:= 1 to Times
do
6343 Anim
:= TAnimation
.Create(id
, False, 3);
6345 g_GFX_OnceAnim(Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(Anim
.Width
div 2),
6346 Obj
.Y
+Obj
.Rect
.Height
-4+Random(8+Times
*2), Anim
, ONCEANIM_SMOKE
);
6352 procedure TPlayer
.OnFireFlame(Times
: DWORD
= 1);
6357 if (Random(10) = 1) and (Times
= 1) then
6360 if g_Frames_Get(id
, 'FRAMES_FLAME') then
6362 for i
:= 1 to Times
do
6364 Anim
:= TAnimation
.Create(id
, False, 3);
6366 g_GFX_OnceAnim(Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(Anim
.Width
div 2),
6367 Obj
.Y
+8+Random(8+Times
*2), Anim
, ONCEANIM_SMOKE
);
6373 procedure TPlayer
.PauseSounds(Enable
: Boolean);
6375 FSawSound
.Pause(Enable
);
6376 FSawSoundIdle
.Pause(Enable
);
6377 FSawSoundHit
.Pause(Enable
);
6378 FSawSoundSelect
.Pause(Enable
);
6379 FFlameSoundOn
.Pause(Enable
);
6380 FFlameSoundOff
.Pause(Enable
);
6381 FFlameSoundWork
.Pause(Enable
);
6382 FJetSoundFly
.Pause(Enable
);
6383 FJetSoundOn
.Pause(Enable
);
6384 FJetSoundOff
.Pause(Enable
);
6389 constructor TCorpse
.Create(X
, Y
: Integer; ModelName
: String; aMess
: Boolean);
6394 FObj
.Rect
:= PLAYER_CORPSERECT
;
6395 FModelName
:= ModelName
;
6400 FState
:= CORPSE_STATE_MESS
;
6401 g_PlayerModel_GetAnim(ModelName
, A_DIE2
, FAnimation
, FAnimationMask
);
6405 FState
:= CORPSE_STATE_NORMAL
;
6406 g_PlayerModel_GetAnim(ModelName
, A_DIE1
, FAnimation
, FAnimationMask
);
6410 destructor TCorpse
.Destroy();
6417 function TCorpse
.ObjPtr (): PObj
; inline; begin result
:= @FObj
; end;
6419 procedure TCorpse
.positionChanged (); inline; begin end;
6421 procedure TCorpse
.moveBy (dx
, dy
: Integer); inline;
6423 if (dx
<> 0) or (dy
<> 0) then
6432 procedure TCorpse
.getMapBox (out x
, y
, w
, h
: Integer); inline;
6434 x
:= FObj
.X
+PLAYER_CORPSERECT
.X
;
6435 y
:= FObj
.Y
+PLAYER_CORPSERECT
.Y
;
6436 w
:= PLAYER_CORPSERECT
.Width
;
6437 h
:= PLAYER_CORPSERECT
.Height
;
6441 procedure TCorpse
.Damage(Value
: Word; SpawnerUID
: Word; vx
, vy
: Integer);
6446 if FState
= CORPSE_STATE_REMOVEME
then
6449 FDamage
:= FDamage
+ Value
;
6451 if FDamage
> 150 then
6453 if FAnimation
<> nil then
6458 FState
:= CORPSE_STATE_REMOVEME
;
6460 g_Player_CreateGibs(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
6461 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2),
6462 FModelName
, FColor
);
6463 // Çâóê ìÿñà îò òðóïà:
6464 pm
:= g_PlayerModel_Get(FModelName
);
6465 pm
.PlaySound(MODELSOUND_DIE
, 5, FObj
.X
, FObj
.Y
);
6469 if (gBodyKillEvent
<> -1)
6470 and gDelayedEvents
[gBodyKillEvent
].Pending
then
6471 gDelayedEvents
[gBodyKillEvent
].Pending
:= False;
6472 gBodyKillEvent
:= g_Game_DelayEvent(DE_BODYKILL
, 1050, SpawnerUID
);
6477 Blood
:= g_PlayerModel_GetBlood(FModelName
);
6478 FObj
.Vel
.X
:= FObj
.Vel
.X
+ vx
;
6479 FObj
.Vel
.Y
:= FObj
.Vel
.Y
+ vy
;
6480 g_GFX_Blood(FObj
.X
+PLAYER_CORPSERECT
.X
+(PLAYER_CORPSERECT
.Width
div 2),
6481 FObj
.Y
+PLAYER_CORPSERECT
.Y
+(PLAYER_CORPSERECT
.Height
div 2),
6482 Value
, vx
, vy
, 16, (PLAYER_CORPSERECT
.Height
*2) div 3,
6483 Blood
.R
, Blood
.G
, Blood
.B
, Blood
.Kind
);
6487 procedure TCorpse
.Draw();
6491 if FState
= CORPSE_STATE_REMOVEME
then
6494 FObj
.lerp(gLerpFactor
, fX
, fY
);
6496 if FAnimation
<> nil then
6497 FAnimation
.Draw(fX
, fY
, TMirrorType
.None
);
6499 if FAnimationMask
<> nil then
6502 FAnimationMask
.Draw(fX
, fY
, TMirrorType
.None
);
6509 procedure TCorpse
.Update();
6513 if FState
= CORPSE_STATE_REMOVEME
then
6516 FObj
.oldX
:= FObj
.X
;
6517 FObj
.oldY
:= FObj
.Y
;
6519 if gTime
mod (GAME_TICK
*2) <> 0 then
6521 g_Obj_Move(@FObj
, True, True, True);
6522 positionChanged(); // this updates spatial accelerators
6526 // Ñîïðîòèâëåíèå âîçäóõà äëÿ òðóïà:
6527 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
6529 st
:= g_Obj_Move(@FObj
, True, True, True);
6530 positionChanged(); // this updates spatial accelerators
6532 if WordBool(st
and MOVE_FALLOUT
) then
6534 FState
:= CORPSE_STATE_REMOVEME
;
6538 if FAnimation
<> nil then
6539 FAnimation
.Update();
6540 if FAnimationMask
<> nil then
6541 FAnimationMask
.Update();
6545 procedure TCorpse
.SaveState (st
: TStream
);
6552 utils
.writeSign(st
, 'CORP');
6553 utils
.writeInt(st
, Byte(0));
6555 utils
.writeInt(st
, Byte(FState
));
6557 utils
.writeInt(st
, Byte(FDamage
));
6559 utils
.writeInt(st
, Byte(FColor
.R
));
6560 utils
.writeInt(st
, Byte(FColor
.G
));
6561 utils
.writeInt(st
, Byte(FColor
.B
));
6563 Obj_SaveState(st
, @FObj
);
6564 utils
.writeInt(st
, Word(FPlayerUID
));
6566 anim
:= (FAnimation
<> nil);
6567 utils
.writeBool(st
, anim
);
6568 // Åñëè åñòü - ñîõðàíÿåì
6569 if anim
then FAnimation
.SaveState(st
);
6570 // Åñòü ëè ìàñêà àíèìàöèè
6571 anim
:= (FAnimationMask
<> nil);
6572 utils
.writeBool(st
, anim
);
6573 // Åñëè åñòü - ñîõðàíÿåì
6574 if anim
then FAnimationMask
.SaveState(st
);
6578 procedure TCorpse
.LoadState (st
: TStream
);
6585 if not utils
.checkSign(st
, 'CORP') then raise XStreamError
.Create('invalid corpse signature');
6586 if (utils
.readByte(st
) <> 0) then raise XStreamError
.Create('invalid corpse version');
6588 FState
:= utils
.readByte(st
);
6590 FDamage
:= utils
.readByte(st
);
6592 FColor
.R
:= utils
.readByte(st
);
6593 FColor
.G
:= utils
.readByte(st
);
6594 FColor
.B
:= utils
.readByte(st
);
6596 Obj_LoadState(@FObj
, st
);
6597 FPlayerUID
:= utils
.readWord(st
);
6599 anim
:= utils
.readBool(st
);
6600 // Åñëè åñòü - çàãðóæàåì
6603 Assert(FAnimation
<> nil, 'TCorpse.LoadState: no FAnimation');
6604 FAnimation
.LoadState(st
);
6606 // Åñòü ëè ìàñêà àíèìàöèè
6607 anim
:= utils
.readBool(st
);
6608 // Åñëè åñòü - çàãðóæàåì
6611 Assert(FAnimationMask
<> nil, 'TCorpse.LoadState: no FAnimationMask');
6612 FAnimationMask
.LoadState(st
);
6618 constructor TBot
.Create();
6625 FSpectator
:= False;
6632 for a
:= WP_FIRST
to WP_LAST
do
6634 FDifficult
.WeaponPrior
[a
] := WEAPON_PRIOR1
[a
];
6635 FDifficult
.CloseWeaponPrior
[a
] := WEAPON_PRIOR2
[a
];
6636 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
6640 destructor TBot
.Destroy();
6643 inherited Destroy();
6646 procedure TBot
.Draw();
6650 //if FTargetUID <> 0 then e_DrawLine(1, FObj.X, FObj.Y, g_Player_Get(FTargetUID).FObj.X,
6651 // g_Player_Get(FTargetUID).FObj.Y, 255, 0, 0);
6654 procedure TBot
.Respawn(Silent
: Boolean; Force
: Boolean = False);
6656 inherited Respawn(Silent
, Force
);
6659 FSelectedWeapon
:= FCurrWeap
;
6664 procedure TBot
.UpdateCombat();
6677 TTargetRecord
= array of TTarget
;
6679 function Compare(a
, b
: TTarget
): Integer;
6681 if a
.Line
and not b
.Line
then // A íà ëèíèè îãíÿ
6684 if not a
.Line
and b
.Line
then // B íà ëèíèè îãíÿ
6686 else // È A, è B íà ëèíèè èëè íå íà ëèíèè îãíÿ
6687 if (a
.Line
and b
.Line
) or ((not a
.Line
) and (not b
.Line
)) then
6689 if a
.Dist
> b
.Dist
then // B áëèæå
6691 else // A áëèæå èëè ðàâíîóäàëåííî ñ B
6694 else // Ñòðàííî -> A
6699 a
, x1
, y1
, x2
, y2
: Integer;
6700 targets
: TTargetRecord
;
6702 Target
, BestTarget
: TTarget
;
6703 firew
, fireh
: Integer;
6707 vsPlayer
, vsMonster
, ok
: Boolean;
6710 function monsUpdate (mon
: TMonster
): Boolean;
6712 result
:= false; // don't stop
6713 if mon
.alive
and (mon
.MonsterType
<> MONSTER_BARREL
) then
6715 if not TargetOnScreen(mon
.Obj
.X
+mon
.Obj
.Rect
.X
, mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
) then exit
;
6717 x2
:= mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2);
6718 y2
:= mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+(mon
.Obj
.Rect
.Height
div 2);
6720 // Åñëè ìîíñòð íà ýêðàíå è íå ïðèêðûò ñòåíîé
6721 if g_TraceVector(x1
, y1
, x2
, y2
) then
6723 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé
6724 SetLength(targets
, Length(targets
)+1);
6725 with targets
[High(targets
)] do
6732 Rect
:= mon
.Obj
.Rect
;
6733 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6734 Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6735 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6744 vsPlayer
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
);
6745 vsMonster
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
);
6747 // Åñëè òåêóùåå îðóæèå íå òî, ÷òî íóæíî, òî ìåíÿåì:
6748 if FCurrWeap
<> FSelectedWeapon
then
6751 // Åñëè íóæíî ñòðåëÿòü è íóæíîå îðóæèå, òî íàæàòü "Ñòðåëÿòü":
6752 if (GetAIFlag('NEEDFIRE') <> '') and (FCurrWeap
= FSelectedWeapon
) then
6754 RemoveAIFlag('NEEDFIRE');
6757 WEAPON_PLASMA
, WEAPON_SUPERPULEMET
, WEAPON_CHAINGUN
: PressKey(KEY_FIRE
, 20);
6758 WEAPON_SAW
, WEAPON_KASTET
, WEAPON_FLAMETHROWER
: PressKey(KEY_FIRE
, 40);
6759 else PressKey(KEY_FIRE
);
6763 // Êîîðäèíàòû ñòâîëà:
6764 x1
:= FObj
.X
+ WEAPONPOINT
[FDirection
].X
;
6765 y1
:= FObj
.Y
+ WEAPONPOINT
[FDirection
].Y
;
6767 Target
.UID
:= FTargetUID
;
6770 if Target
.UID
<> 0 then
6771 begin // Öåëü åñòü - íàñòðàèâàåì
6772 if (g_GetUIDType(Target
.UID
) = UID_PLAYER
) and
6775 tpla
:= g_Player_Get(Target
.UID
);
6779 if (@FObj
) <> nil then
6786 Target
.cX
:= Target
.X
+ PLAYER_RECT_CX
;
6787 Target
.cY
:= Target
.Y
+ PLAYER_RECT_CY
;
6788 Target
.Rect
:= PLAYER_RECT
;
6789 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6790 Target
.Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6791 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6792 Target
.IsPlayer
:= True;
6796 if (g_GetUIDType(Target
.UID
) = UID_MONSTER
) and
6799 mon
:= g_Monsters_ByUID(Target
.UID
);
6802 Target
.X
:= mon
.Obj
.X
;
6803 Target
.Y
:= mon
.Obj
.Y
;
6805 Target
.cX
:= Target
.X
+ mon
.Obj
.Rect
.X
+ (mon
.Obj
.Rect
.Width
div 2);
6806 Target
.cY
:= Target
.Y
+ mon
.Obj
.Rect
.Y
+ (mon
.Obj
.Rect
.Height
div 2);
6807 Target
.Rect
:= mon
.Obj
.Rect
;
6808 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6809 Target
.Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6810 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6811 Target
.IsPlayer
:= False;
6818 begin // Öåëè íåò - îáíóëÿåì
6823 Target
.Visible
:= False;
6824 Target
.Line
:= False;
6825 Target
.IsPlayer
:= False;
6830 // Åñëè öåëü íå âèäèìà èëè íå íà ëèíèè îãíÿ, òî èùåì âñå âîçìîæíûå öåëè:
6831 if (not Target
.Line
) or (not Target
.Visible
) then
6835 for a
:= 0 to High(gPlayers
) do
6836 if (gPlayers
[a
] <> nil) and (gPlayers
[a
].alive
) and
6837 (gPlayers
[a
].FUID
<> FUID
) and
6838 (not SameTeam(FUID
, gPlayers
[a
].FUID
)) and
6839 (not gPlayers
[a
].NoTarget
) and
6840 (gPlayers
[a
].FMegaRulez
[MR_INVIS
] < gTime
) then
6842 if not TargetOnScreen(gPlayers
[a
].FObj
.X
+ PLAYER_RECT
.X
,
6843 gPlayers
[a
].FObj
.Y
+ PLAYER_RECT
.Y
) then
6846 x2
:= gPlayers
[a
].FObj
.X
+ PLAYER_RECT_CX
;
6847 y2
:= gPlayers
[a
].FObj
.Y
+ PLAYER_RECT_CY
;
6849 // Åñëè èãðîê íà ýêðàíå è íå ïðèêðûò ñòåíîé:
6850 if g_TraceVector(x1
, y1
, x2
, y2
) then
6852 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé:
6853 SetLength(targets
, Length(targets
)+1);
6854 with targets
[High(targets
)] do
6856 UID
:= gPlayers
[a
].FUID
;
6857 X
:= gPlayers
[a
].FObj
.X
;
6858 Y
:= gPlayers
[a
].FObj
.Y
;
6861 Rect
:= PLAYER_RECT
;
6862 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6863 Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6864 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6872 if vsMonster
then g_Mons_ForEach(monsUpdate
);
6875 // Åñëè åñòü âîçìîæíûå öåëè:
6876 // (Âûáèðàåì ëó÷øóþ, ìåíÿåì îðóæèå è áåæèì ê íåé/îò íåå)
6877 if targets
<> nil then
6879 // Âûáèðàåì íàèëó÷øóþ öåëü:
6880 BestTarget
:= targets
[0];
6881 if Length(targets
) > 1 then
6882 for a
:= 1 to High(targets
) do
6883 if Compare(BestTarget
, targets
[a
]) = 1 then
6884 BestTarget
:= targets
[a
];
6886 // Åñëè ëó÷øàÿ öåëü "âèäíåå" òåêóùåé, òî òåêóùàÿ := ëó÷øàÿ:
6887 if ((not Target
.Visible
) and BestTarget
.Visible
and (Target
.UID
<> BestTarget
.UID
)) or
6888 ((not Target
.Line
) and BestTarget
.Line
and BestTarget
.Visible
) then
6890 Target
:= BestTarget
;
6892 if (Healthy() = 3) or ((Healthy() = 2)) then
6893 begin // Åñëè çäîðîâû - äîãîíÿåì
6894 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
6895 SetAIFlag('GORIGHT', '1');
6896 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6897 SetAIFlag('GOLEFT', '1');
6900 begin // Åñëè ïîáèòû - óáåãàåì
6901 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) then
6902 SetAIFlag('GORIGHT', '1');
6903 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6904 SetAIFlag('GOLEFT', '1');
6907 // Âûáèðàåì îðóæèå íà îñíîâå ðàññòîÿíèÿ è ïðèîðèòåòîâ:
6908 SelectWeapon(Abs(x1
-Target
.cX
));
6913 // (Äîãîíÿåì/óáåãàåì, ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëè)
6914 // (Åñëè öåëü äàëåêî, òî õâàòèò ñëåäèòü çà íåé)
6915 if Target
.UID
<> 0 then
6917 if not TargetOnScreen(Target
.X
+ Target
.Rect
.X
,
6918 Target
.Y
+ Target
.Rect
.Y
) then
6919 begin // Öåëü ñáåæàëà ñ "ýêðàíà"
6920 if (Healthy() = 3) or ((Healthy() = 2)) then
6921 begin // Åñëè çäîðîâû - äîãîíÿåì
6922 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
6923 SetAIFlag('GORIGHT', '1');
6924 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6925 SetAIFlag('GOLEFT', '1');
6928 begin // Åñëè ïîáèòû - çàáûâàåì î öåëè è óáåãàåì
6930 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) then
6931 SetAIFlag('GORIGHT', '1');
6932 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6933 SetAIFlag('GOLEFT', '1');
6937 begin // Öåëü ïîêà íà "ýêðàíå"
6938 // Åñëè öåëü íå çàãîðîæåíà ñòåíîé, òî îòìå÷àåì, êîãäà åå âèäåëè:
6939 if g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6940 FLastVisible
:= gTime
;
6941 // Åñëè ðàçíèöà âûñîò íå âåëèêà, òî äîãîíÿåì:
6942 if (Abs(FObj
.Y
-Target
.Y
) <= 128) then
6944 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
6945 SetAIFlag('GORIGHT', '1');
6946 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6947 SetAIFlag('GOLEFT', '1');
6951 // Âûáèðàåì óãîë ââåðõ:
6952 if FDirection
= TDirection
.D_LEFT
then
6953 angle
:= ANGLE_LEFTUP
6955 angle
:= ANGLE_RIGHTUP
;
6957 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6958 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6960 // Åñëè ïðè óãëå ââåðõ ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
6961 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6962 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128), //96
6963 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6964 Target
.Rect
.Width
, Target
.Rect
.Height
) and
6965 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6966 begin // òî íóæíî ñòðåëÿòü ââåðõ
6967 SetAIFlag('NEEDFIRE', '1');
6968 SetAIFlag('NEEDSEEUP', '1');
6971 // Âûáèðàåì óãîë âíèç:
6972 if FDirection
= TDirection
.D_LEFT
then
6973 angle
:= ANGLE_LEFTDOWN
6975 angle
:= ANGLE_RIGHTDOWN
;
6977 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6978 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6980 // Åñëè ïðè óãëå âíèç ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
6981 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6982 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
6983 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6984 Target
.Rect
.Width
, Target
.Rect
.Height
) and
6985 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6986 begin // òî íóæíî ñòðåëÿòü âíèç
6987 SetAIFlag('NEEDFIRE', '1');
6988 SetAIFlag('NEEDSEEDOWN', '1');
6991 // Åñëè öåëü âèäíî è îíà íà òàêîé æå âûñîòå:
6992 if Target
.Visible
and
6993 (y1
+4 < Target
.Y
+Target
.Rect
.Y
+Target
.Rect
.Height
) and
6994 (y1
-4 > Target
.Y
+Target
.Rect
.Y
) then
6996 // Åñëè èäåì â ñòîðîíó öåëè, òî íàäî ñòðåëÿòü:
6997 if ((FDirection
= TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) or
6998 ((FDirection
= TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6999 begin // òî íóæíî ñòðåëÿòü âïåðåä
7000 SetAIFlag('NEEDFIRE', '1');
7001 SetAIFlag('NEEDSEEDOWN', '');
7002 SetAIFlag('NEEDSEEUP', '');
7004 // Åñëè öåëü â ïðåäåëàõ "ýêðàíà" è ñëîæíîñòü ïîçâîëÿåò ïðûæêè ñáëèæåíèÿ:
7005 if Abs(FObj
.X
-Target
.X
) < Trunc(gPlayerScreenSize
.X
*0.75) then
7006 if GetRnd(FDifficult
.CloseJump
) then
7007 begin // òî åñëè ïîâåçåò - ïðûãàåì (îñîáåííî, åñëè áëèçêî)
7008 if Abs(FObj
.X
-Target
.X
) < 128 then
7012 if Random(a
) = 0 then
7013 SetAIFlag('NEEDJUMP', '1');
7017 // Åñëè öåëü âñå åùå åñòü:
7018 if Target
.UID
<> 0 then
7019 if gTime
-FLastVisible
> 2000 then // Åñëè âèäåëè äàâíî
7020 Target
.UID
:= 0 // òî çàáûòü öåëü
7021 else // Åñëè âèäåëè íåäàâíî
7022 begin // íî öåëü óáèëè
7023 if Target
.IsPlayer
then
7024 begin // Öåëü - èãðîê
7025 pla
:= g_Player_Get(Target
.UID
);
7026 if (pla
= nil) or (not pla
.alive
) or pla
.NoTarget
or
7027 (pla
.FMegaRulez
[MR_INVIS
] >= gTime
) then
7028 Target
.UID
:= 0; // òî çàáûòü öåëü
7031 begin // Öåëü - ìîíñòð
7032 mon
:= g_Monsters_ByUID(Target
.UID
);
7033 if (mon
= nil) or (not mon
.alive
) then
7034 Target
.UID
:= 0; // òî çàáûòü öåëü
7037 end; // if Target.UID <> 0
7039 FTargetUID
:= Target
.UID
;
7041 // Åñëè âîçìîæíûõ öåëåé íåò:
7042 // (Àòàêà ÷åãî-íèáóäü ñëåâà èëè ñïðàâà)
7043 if targets
= nil then
7044 if GetAIFlag('ATTACKLEFT') <> '' then
7045 begin // Åñëè íóæíî àòàêîâàòü íàëåâî
7046 RemoveAIFlag('ATTACKLEFT');
7048 SetAIFlag('NEEDJUMP', '1');
7050 if RunDirection() = TDirection
.D_RIGHT
then
7051 begin // Èäåì íå â òó ñòîðîíó
7052 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
7053 begin // Åñëè çäîðîâû, òî, âîçìîæíî, ñòðåëÿåì áåæèì âëåâî è ñòðåëÿåì
7054 SetAIFlag('NEEDFIRE', '1');
7055 SetAIFlag('GOLEFT', '1');
7059 begin // Èäåì â íóæíóþ ñòîðîíó
7060 if GetRnd(FDifficult
.InvisFire
) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
7061 SetAIFlag('NEEDFIRE', '1');
7062 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
7063 SetAIFlag('GORIGHT', '1');
7067 if GetAIFlag('ATTACKRIGHT') <> '' then
7068 begin // Åñëè íóæíî àòàêîâàòü íàïðàâî
7069 RemoveAIFlag('ATTACKRIGHT');
7071 SetAIFlag('NEEDJUMP', '1');
7073 if RunDirection() = TDirection
.D_LEFT
then
7074 begin // Èäåì íå â òó ñòîðîíó
7075 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
7076 begin // Åñëè çäîðîâû, òî, âîçìîæíî, áåæèì âïðàâî è ñòðåëÿåì
7077 SetAIFlag('NEEDFIRE', '1');
7078 SetAIFlag('GORIGHT', '1');
7083 if GetRnd(FDifficult
.InvisFire
) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
7084 SetAIFlag('NEEDFIRE', '1');
7085 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
7086 SetAIFlag('GOLEFT', '1');
7090 //HACK! (does it belongs there?)
7091 RealizeCurrentWeapon();
7093 // Åñëè åñòü âîçìîæíûå öåëè:
7094 // (Ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëÿì)
7095 if (targets
<> nil) and (GetAIFlag('NEEDFIRE') <> '') then
7096 for a
:= 0 to High(targets
) do
7098 // Åñëè ìîæåì ñòðåëÿòü ïî äèàãîíàëè:
7099 if GetRnd(FDifficult
.DiagFire
) then
7101 // Èùåì öåëü ñâåðõó è ñòðåëÿåì, åñëè åñòü:
7102 if FDirection
= TDirection
.D_LEFT
then
7103 angle
:= ANGLE_LEFTUP
7105 angle
:= ANGLE_RIGHTUP
;
7107 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7108 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7110 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
7111 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
7112 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
7113 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
7114 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
7116 SetAIFlag('NEEDFIRE', '1');
7117 SetAIFlag('NEEDSEEUP', '1');
7120 // Èùåì öåëü ñíèçó è ñòðåëÿåì, åñëè åñòü:
7121 if FDirection
= TDirection
.D_LEFT
then
7122 angle
:= ANGLE_LEFTDOWN
7124 angle
:= ANGLE_RIGHTDOWN
;
7126 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7127 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7129 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
7130 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
7131 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
7132 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
7133 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
7135 SetAIFlag('NEEDFIRE', '1');
7136 SetAIFlag('NEEDSEEDOWN', '1');
7140 // Åñëè öåëü "ïåðåä íîñîì", òî ñòðåëÿåì:
7141 if targets
[a
].Line
and targets
[a
].Visible
and
7142 (((FDirection
= TDirection
.D_LEFT
) and (targets
[a
].X
< FObj
.X
)) or
7143 ((FDirection
= TDirection
.D_RIGHT
) and (targets
[a
].X
> FObj
.X
))) then
7145 SetAIFlag('NEEDFIRE', '1');
7150 // Åñëè ëåòèò ïóëÿ, òî, âîçìîæíî, ïîäïðûãèâàåì:
7151 if g_Weapon_Danger(FUID
, FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
,
7152 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
,
7153 40+GetInterval(FDifficult
.Cover
, 40)) then
7154 SetAIFlag('NEEDJUMP', '1');
7156 // Åñëè êîí÷èëèñü ïàòîðíû, òî íóæíî ñìåíèòü îðóæèå:
7157 ammo
:= GetAmmoByWeapon(FCurrWeap
);
7158 if ((FCurrWeap
= WEAPON_SHOTGUN2
) and (ammo
< 2)) or
7159 ((FCurrWeap
= WEAPON_BFG
) and (ammo
< 40)) or
7161 SetAIFlag('SELECTWEAPON', '1');
7163 // Åñëè íóæíî ñìåíèòü îðóæèå, òî âûáèðàåì íóæíîå:
7164 if GetAIFlag('SELECTWEAPON') = '1' then
7167 RemoveAIFlag('SELECTWEAPON');
7171 procedure TBot
.Update();
7184 // Ïðîâåðÿåì, îòêëþ÷¸í ëè AI áîòîâ
7185 if (g_debug_BotAIOff
= 1) and (Team
= TEAM_RED
) then
7187 if (g_debug_BotAIOff
= 2) and (Team
= TEAM_BLUE
) then
7189 if g_debug_BotAIOff
= 3 then
7199 RealizeCurrentWeapon();
7206 procedure TBot
.ReleaseKey(Key
: Byte);
7215 function TBot
.KeyPressed(Key
: Word): Boolean;
7217 Result
:= FKeys
[Key
].Pressed
;
7220 function TBot
.GetAIFlag(aName
: String20
): String20
;
7226 aName
:= LowerCase(aName
);
7228 if FAIFlags
<> nil then
7229 for a
:= 0 to High(FAIFlags
) do
7230 if LowerCase(FAIFlags
[a
].Name
) = aName
then
7232 Result
:= FAIFlags
[a
].Value
;
7237 procedure TBot
.RemoveAIFlag(aName
: String20
);
7241 if FAIFlags
= nil then Exit
;
7243 aName
:= LowerCase(aName
);
7245 for a
:= 0 to High(FAIFlags
) do
7246 if LowerCase(FAIFlags
[a
].Name
) = aName
then
7248 if a
<> High(FAIFlags
) then
7249 for b
:= a
to High(FAIFlags
)-1 do
7250 FAIFlags
[b
] := FAIFlags
[b
+1];
7252 SetLength(FAIFlags
, Length(FAIFlags
)-1);
7257 procedure TBot
.SetAIFlag(aName
, fValue
: String20
);
7265 aName
:= LowerCase(aName
);
7267 if FAIFlags
<> nil then
7268 for a
:= 0 to High(FAIFlags
) do
7269 if LowerCase(FAIFlags
[a
].Name
) = aName
then
7275 if ok
then FAIFlags
[a
].Value
:= fValue
7278 SetLength(FAIFlags
, Length(FAIFlags
)+1);
7279 with FAIFlags
[High(FAIFlags
)] do
7287 procedure TBot
.UpdateMove
;
7289 procedure GoLeft(Time
: Word = 1);
7291 ReleaseKey(KEY_LEFT
);
7292 ReleaseKey(KEY_RIGHT
);
7293 PressKey(KEY_LEFT
, Time
);
7294 SetDirection(TDirection
.D_LEFT
);
7297 procedure GoRight(Time
: Word = 1);
7299 ReleaseKey(KEY_LEFT
);
7300 ReleaseKey(KEY_RIGHT
);
7301 PressKey(KEY_RIGHT
, Time
);
7302 SetDirection(TDirection
.D_RIGHT
);
7305 function Rnd(a
: Word): Boolean;
7307 Result
:= Random(a
) = 0;
7310 procedure Turn(Time
: Word = 1200);
7312 if RunDirection() = TDirection
.D_LEFT
then GoRight(Time
) else GoLeft(Time
);
7317 ReleaseKey(KEY_LEFT
);
7318 ReleaseKey(KEY_RIGHT
);
7321 function CanRunLeft(): Boolean;
7323 Result
:= not CollideLevel(-1, 0);
7326 function CanRunRight(): Boolean;
7328 Result
:= not CollideLevel(1, 0);
7331 function CanRun(): Boolean;
7333 if RunDirection() = TDirection
.D_LEFT
then Result
:= CanRunLeft() else Result
:= CanRunRight();
7336 procedure Jump(Time
: Word = 30);
7338 PressKey(KEY_JUMP
, Time
);
7341 function NearHole(): Boolean;
7345 { TODO 5 : Ëåñòíèöû }
7346 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7347 for x
:= 1 to PLAYER_RECT
.Width
do
7348 if (not StayOnStep(x
*sx
, 0)) and
7349 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7350 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7359 function BorderHole(): Boolean;
7363 { TODO 5 : Ëåñòíèöû }
7364 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7365 for x
:= 1 to PLAYER_RECT
.Width
do
7366 if (not StayOnStep(x
*sx
, 0)) and
7367 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7368 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7370 for xx
:= x
to x
+32 do
7371 if CollideLevel(xx
*sx
, PLAYER_RECT
.Height
) then
7381 function NearDeepHole(): Boolean;
7387 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7390 for x
:= 1 to PLAYER_RECT
.Width
do
7391 if (not StayOnStep(x
*sx
, 0)) and
7392 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7393 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7395 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
7397 if CollideLevel(x
*sx
, PLAYER_RECT
.Height
*y
) then Exit
;
7402 end else Result
:= False;
7405 function OverDeepHole(): Boolean;
7412 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
7414 if CollideLevel(0, PLAYER_RECT
.Height
*y
) then Exit
;
7421 function OnGround(): Boolean;
7423 Result
:= StayOnStep(0, 0) or CollideLevel(0, 1);
7426 function OnLadder(): Boolean;
7428 Result
:= FullInStep(0, 0);
7431 function BelowLadder(): Boolean;
7433 Result
:= (FullInStep(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) and
7434 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
7435 (FullInStep(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) and
7436 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
7439 function BelowLiftUp(): Boolean;
7441 Result
:= ((FullInLift(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) = -1) and
7442 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
7443 ((FullInLift(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) = -1) and
7444 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
7447 function OnTopLift(): Boolean;
7449 Result
:= (FullInLift(0, 0) = -1) and (FullInLift(0, -32) = 0);
7452 function CanJumpOver(): Boolean;
7456 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7460 if not CollideLevel(sx
, 0) then Exit
;
7462 for y
:= 1 to BOT_MAXJUMP
do
7463 if CollideLevel(0, -y
) then Exit
else
7464 if not CollideLevel(sx
, -y
) then
7471 function CanJumpUp(Dist
: ShortInt): Boolean;
7478 if CollideLevel(Dist
, 0) then Exit
;
7481 for y
:= 0 to BOT_MAXJUMP
do
7482 if CollideLevel(Dist
, -y
) then
7491 for yy
:= y
+1 to BOT_MAXJUMP
do
7492 if not CollideLevel(Dist
, -yy
) then
7501 for y
:= 0 to BOT_MAXJUMP
do
7502 if CollideLevel(0, -y
) then
7510 if y
< yy
then Exit
;
7515 function IsSafeTrigger(): Boolean;
7520 if gTriggers
= nil then
7522 for a
:= 0 to High(gTriggers
) do
7523 if Collide(gTriggers
[a
].X
,
7526 gTriggers
[a
].Height
) and
7527 (gTriggers
[a
].TriggerType
in [TRIGGER_EXIT
, TRIGGER_CLOSEDOOR
,
7528 TRIGGER_CLOSETRAP
, TRIGGER_TRAP
,
7529 TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
,
7530 TRIGGER_ONOFF
, TRIGGER_SPAWNMONSTER
,
7531 TRIGGER_DAMAGE
, TRIGGER_SHOT
]) then
7536 // Âîçìîæíî, íàæèìàåì êíîïêó:
7537 if Rnd(16) and IsSafeTrigger() then
7540 // Åñëè ïîä ëèôòîì èëè ñòóïåíüêàìè, òî, âîçìîæíî, ïðûãàåì:
7541 if OnLadder() or ((BelowLadder() or BelowLiftUp()) and Rnd(8)) then
7543 ReleaseKey(KEY_LEFT
);
7544 ReleaseKey(KEY_RIGHT
);
7548 // Èäåì âëåâî, åñëè íàäî áûëî:
7549 if GetAIFlag('GOLEFT') <> '' then
7551 RemoveAIFlag('GOLEFT');
7552 if CanRunLeft() then
7556 // Èäåì âïðàâî, åñëè íàäî áûëî:
7557 if GetAIFlag('GORIGHT') <> '' then
7559 RemoveAIFlag('GORIGHT');
7560 if CanRunRight() then
7564 // Åñëè âûëåòåëè çà êàðòó, òî ïðîáóåì âåðíóòüñÿ:
7565 if FObj
.X
< -32 then
7568 if FObj
.X
+32 > gMapInfo
.Width
then
7571 // Ïðûãàåì, åñëè íàäî áûëî:
7572 if GetAIFlag('NEEDJUMP') <> '' then
7575 RemoveAIFlag('NEEDJUMP');
7578 // Ñìîòðèì ââåðõ, åñëè íàäî áûëî:
7579 if GetAIFlag('NEEDSEEUP') <> '' then
7582 ReleaseKey(KEY_DOWN
);
7583 PressKey(KEY_UP
, 20);
7584 RemoveAIFlag('NEEDSEEUP');
7587 // Ñìîòðèì âíèç, åñëè íàäî áûëî:
7588 if GetAIFlag('NEEDSEEDOWN') <> '' then
7591 ReleaseKey(KEY_DOWN
);
7592 PressKey(KEY_DOWN
, 20);
7593 RemoveAIFlag('NEEDSEEDOWN');
7596 // Åñëè íóæíî áûëî â äûðó è ìû íå íà çåìëå, òî ïîêîðíî ëåòèì:
7597 if GetAIFlag('GOINHOLE') <> '' then
7598 if not OnGround() then
7600 ReleaseKey(KEY_LEFT
);
7601 ReleaseKey(KEY_RIGHT
);
7602 RemoveAIFlag('GOINHOLE');
7603 SetAIFlag('FALLINHOLE', '1');
7606 // Åñëè ïàäàëè è äîñòèãëè çåìëè, òî õâàòèò ïàäàòü:
7607 if GetAIFlag('FALLINHOLE') <> '' then
7609 RemoveAIFlag('FALLINHOLE');
7611 // Åñëè ëåòåëè ïðÿìî è ñåé÷àñ íå íà ëåñòíèöå èëè íà âåðøèíå ëèôòà, òî îòõîäèì â ñòîðîíó:
7612 if not (KeyPressed(KEY_LEFT
) or KeyPressed(KEY_RIGHT
)) then
7613 if GetAIFlag('FALLINHOLE') = '' then
7614 if (not OnLadder()) or (FObj
.Vel
.Y
>= 0) or (OnTopLift()) then
7620 // Åñëè íà çåìëå è ìîæíî ïîäïðûãíóòü, òî, âîçìîæíî, ïðûãàåì:
7622 CanJumpUp(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*32) and
7626 // Åñëè íà çåìëå è âîçëå äûðû (ãëóáèíà > 2 ðîñòîâ èãðîêà):
7627 if OnGround() and NearHole() then
7628 if NearDeepHole() then // Åñëè ýòî áåçäíà
7630 0..3: Turn(); // Áåæèì îáðàòíî
7631 4: Jump(); // Ïðûãàåì
7632 5: begin // Ïðûãàåì îáðàòíî
7637 else // Ýòî íå áåçäíà è ìû åùå íå ëåòèì òóäà
7638 if GetAIFlag('GOINHOLE') = '' then
7640 0: Turn(); // Íå íóæíî òóäà
7641 1: Jump(); // Âäðóã ïîâåçåò - ïðûãàåì
7642 else // Åñëè ÿìà ñ ãðàíèöåé, òî ïðè ñëó÷àå ìîæíî òóäà ïðûãíóòü
7643 if BorderHole() then
7644 SetAIFlag('GOINHOLE', '1');
7647 // Åñëè íà çåìëå, íî íåêóäà èäòè:
7648 if (not CanRun()) and OnGround() then
7650 // Åñëè ìû íà ëåñòíèöå èëè ìîæíî ïåðåïðûãíóòü, òî ïðûãàåì:
7651 if CanJumpOver() or OnLadder() then
7653 else // èíà÷å ïîïûòàåìñÿ â äðóãóþ ñòîðîíó
7654 if Random(2) = 0 then
7656 if IsSafeTrigger() then
7662 // Îñòàëîñü ìàëî âîçäóõà:
7663 if FAir
< 36 * 2 then
7666 // Âûáèðàåìñÿ èç êèñëîòû, åñëè íåò êîñòþìà, îáîæãëèñü, èëè ìàëî çäîðîâüÿ:
7667 if (FMegaRulez
[MR_SUIT
] < gTime
) and ((FLastHit
= HIT_ACID
) or (Healthy() <= 1)) then
7668 if BodyInAcid(0, 0) then
7672 function TBot
.FullInStep(XInc
, YInc
: Integer): Boolean;
7674 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
7675 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_STEP
, False);
7678 {function TBot.NeedItem(Item: Byte): Byte;
7683 procedure TBot
.SelectWeapon(Dist
: Integer);
7687 function HaveAmmo(weapon
: Byte): Boolean;
7690 WEAPON_PISTOL
: Result
:= FAmmo
[A_BULLETS
] >= 1;
7691 WEAPON_SHOTGUN1
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7692 WEAPON_SHOTGUN2
: Result
:= FAmmo
[A_SHELLS
] >= 2;
7693 WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
] >= 10;
7694 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
] >= 1;
7695 WEAPON_PLASMA
: Result
:= FAmmo
[A_CELLS
] >= 10;
7696 WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
] >= 40;
7697 WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7698 WEAPON_FLAMETHROWER
: Result
:= FAmmo
[A_FUEL
] >= 1;
7699 else Result
:= True;
7704 if Dist
= -1 then Dist
:= BOT_LONGDIST
;
7706 if Dist
> BOT_LONGDIST
then
7707 begin // Äàëüíèé áîé
7709 if FWeapon
[FDifficult
.WeaponPrior
[a
]] and HaveAmmo(FDifficult
.WeaponPrior
[a
]) then
7711 FSelectedWeapon
:= FDifficult
.WeaponPrior
[a
];
7715 else //if Dist > BOT_UNSAFEDIST then
7716 begin // Áëèæíèé áîé
7718 if FWeapon
[FDifficult
.CloseWeaponPrior
[a
]] and HaveAmmo(FDifficult
.CloseWeaponPrior
[a
]) then
7720 FSelectedWeapon
:= FDifficult
.CloseWeaponPrior
[a
];
7727 if FWeapon[FDifficult.SafeWeaponPrior[a]] and HaveAmmo(FDifficult.SafeWeaponPrior[a]) then
7729 FSelectedWeapon := FDifficult.SafeWeaponPrior[a];
7735 function TBot
.PickItem(ItemType
: Byte; force
: Boolean; var remove
: Boolean): Boolean;
7737 Result
:= inherited PickItem(ItemType
, force
, remove
);
7739 if Result
then SetAIFlag('SELECTWEAPON', '1');
7742 function TBot
.Heal(value
: Word; Soft
: Boolean): Boolean;
7744 Result
:= inherited Heal(value
, Soft
);
7747 function TBot
.Healthy(): Byte;
7749 if FMegaRulez
[MR_INVUL
] >= gTime
then Result
:= 3
7750 else if (FHealth
> 80) or ((FHealth
> 50) and (FArmor
> 20)) then Result
:= 3
7751 else if (FHealth
> 50) then Result
:= 2
7752 else if (FHealth
> 20) then Result
:= 1
7756 function TBot
.TargetOnScreen(TX
, TY
: Integer): Boolean;
7758 Result
:= (Abs(FObj
.X
-TX
) <= Trunc(gPlayerScreenSize
.X
*0.6)) and
7759 (Abs(FObj
.Y
-TY
) <= Trunc(gPlayerScreenSize
.Y
*0.6));
7762 procedure TBot
.OnDamage(Angle
: SmallInt);
7770 if (Angle
= 0) or (Angle
= 180) then
7773 if (g_GetUIDType(FLastSpawnerUID
) = UID_PLAYER
) and
7774 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
) then
7776 pla
:= g_Player_Get(FLastSpawnerUID
);
7777 ok
:= not TargetOnScreen(pla
.FObj
.X
+ PLAYER_RECT
.X
,
7778 pla
.FObj
.Y
+ PLAYER_RECT
.Y
);
7781 if (g_GetUIDType(FLastSpawnerUID
) = UID_MONSTER
) and
7782 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
) then
7784 mon
:= g_Monsters_ByUID(FLastSpawnerUID
);
7785 ok
:= not TargetOnScreen(mon
.Obj
.X
+ mon
.Obj
.Rect
.X
,
7786 mon
.Obj
.Y
+ mon
.Obj
.Rect
.Y
);
7791 SetAIFlag('ATTACKLEFT', '1')
7793 SetAIFlag('ATTACKRIGHT', '1');
7797 function TBot
.RunDirection(): TDirection
;
7799 if Abs(Vel
.X
) >= 1 then
7801 if Vel
.X
> 0 then Result
:= TDirection
.D_RIGHT
else Result
:= TDirection
.D_LEFT
;
7803 Result
:= FDirection
;
7806 function TBot
.GetRnd(a
: Byte): Boolean;
7808 if a
= 0 then Result
:= False
7809 else if a
= 255 then Result
:= True
7810 else Result
:= Random(256) > 255-a
;
7813 function TBot
.GetInterval(a
: Byte; radius
: SmallInt): SmallInt;
7815 Result
:= Round((255-a
)/255*radius
*(Random(2)-1));
7819 procedure TDifficult
.save (st
: TStream
);
7821 utils
.writeInt(st
, Byte(DiagFire
));
7822 utils
.writeInt(st
, Byte(InvisFire
));
7823 utils
.writeInt(st
, Byte(DiagPrecision
));
7824 utils
.writeInt(st
, Byte(FlyPrecision
));
7825 utils
.writeInt(st
, Byte(Cover
));
7826 utils
.writeInt(st
, Byte(CloseJump
));
7827 st
.WriteBuffer(WeaponPrior
[Low(WeaponPrior
)], sizeof(WeaponPrior
));
7828 st
.WriteBuffer(CloseWeaponPrior
[Low(CloseWeaponPrior
)], sizeof(CloseWeaponPrior
));
7831 procedure TDifficult
.load (st
: TStream
);
7833 DiagFire
:= utils
.readByte(st
);
7834 InvisFire
:= utils
.readByte(st
);
7835 DiagPrecision
:= utils
.readByte(st
);
7836 FlyPrecision
:= utils
.readByte(st
);
7837 Cover
:= utils
.readByte(st
);
7838 CloseJump
:= utils
.readByte(st
);
7839 st
.ReadBuffer(WeaponPrior
[Low(WeaponPrior
)], sizeof(WeaponPrior
));
7840 st
.ReadBuffer(CloseWeaponPrior
[Low(CloseWeaponPrior
)], sizeof(CloseWeaponPrior
));
7844 procedure TBot
.SaveState (st
: TStream
);
7849 inherited SaveState(st
);
7850 utils
.writeSign(st
, 'BOT0');
7852 utils
.writeInt(st
, Byte(FSelectedWeapon
));
7854 utils
.writeInt(st
, Word(FTargetUID
));
7855 // Âðåìÿ ïîòåðè öåëè
7856 utils
.writeInt(st
, LongWord(FLastVisible
));
7857 // Êîëè÷åñòâî ôëàãîâ ÈÈ
7858 dw
:= Length(FAIFlags
);
7859 utils
.writeInt(st
, LongInt(dw
));
7861 for i
:= 0 to dw
-1 do
7863 utils
.writeStr(st
, FAIFlags
[i
].Name
, 20);
7864 utils
.writeStr(st
, FAIFlags
[i
].Value
, 20);
7866 // Íàñòðîéêè ñëîæíîñòè
7867 FDifficult
.save(st
);
7871 procedure TBot
.LoadState (st
: TStream
);
7876 inherited LoadState(st
);
7877 if not utils
.checkSign(st
, 'BOT0') then raise XStreamError
.Create('invalid bot signature');
7879 FSelectedWeapon
:= utils
.readByte(st
);
7881 FTargetUID
:= utils
.readWord(st
);
7882 // Âðåìÿ ïîòåðè öåëè
7883 FLastVisible
:= utils
.readLongWord(st
);
7884 // Êîëè÷åñòâî ôëàãîâ ÈÈ
7885 dw
:= utils
.readLongInt(st
);
7886 if (dw
< 0) or (dw
> 16384) then raise XStreamError
.Create('invalid number of bot AI flags');
7887 SetLength(FAIFlags
, dw
);
7889 for i
:= 0 to dw
-1 do
7891 FAIFlags
[i
].Name
:= utils
.readStr(st
, 20);
7892 FAIFlags
[i
].Value
:= utils
.readStr(st
, 20);
7894 // Íàñòðîéêè ñëîæíîñòè
7895 FDifficult
.load(st
);
7900 conRegVar('cheat_berserk_autoswitch', @gBerserkAutoswitch
, 'autoswitch to fist when berserk pack taken', '', true, true);
7901 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');
7902 conRegVar('player_indicator_style', @gPlayerIndicatorStyle
, 'Visual appearance of indicator', 'Visual appearance of indicator');