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; DoThrow
: Boolean = False): Boolean;
314 function TryDropFlag(): Boolean;
315 procedure AllRulez(Health
: Boolean);
316 procedure RestoreHealthArmor();
317 procedure FragCombo();
318 procedure GiveItem(ItemType
: Byte);
319 procedure Damage(value
: Word; SpawnerUID
: Word; vx
, vy
: Integer; t
: Byte); virtual;
320 function Heal(value
: Word; Soft
: Boolean): Boolean; virtual;
321 procedure MakeBloodVector(Count
: Word; VelX
, VelY
: Integer);
322 procedure MakeBloodSimple(Count
: Word);
323 procedure Kill(KillType
: Byte; SpawnerUID
: Word; t
: Byte);
324 procedure Reset(Force
: Boolean);
325 procedure Spectate(NoMove
: Boolean = False);
326 procedure SwitchNoClip
;
327 procedure SoftReset();
328 procedure Draw(); virtual;
329 procedure DrawPain();
330 procedure DrawPickup();
331 procedure DrawRulez();
333 procedure DrawIndicator(Color
: TRGB
);
334 procedure DrawBubble();
336 procedure PreUpdate();
337 procedure Update(); virtual;
338 procedure RememberState();
339 procedure RecallState();
340 procedure SaveState (st
: TStream
); virtual;
341 procedure LoadState (st
: TStream
); virtual;
342 procedure PauseSounds(Enable
: Boolean);
343 procedure NetFire(Wpn
: Byte; X
, Y
, AX
, AY
: Integer; WID
: Integer = -1);
344 procedure DoLerp(Level
: Integer = 2);
345 procedure SetLerp(XTo
, YTo
: Integer);
346 procedure ProcessWeaponAction(Action
: Byte);
347 procedure QueueWeaponSwitch(Weapon
: Byte);
348 procedure RealizeCurrentWeapon();
352 procedure JetpackOff
;
353 procedure CatchFire(Attacker
: Word; Timeout
: Integer = PLAYER_BURN_TIME
);
355 //WARNING! this does nothing for now, but still call it!
356 procedure positionChanged (); //WARNING! call this after entity position was changed, or coldet will not work right!
358 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
359 procedure moveBy (dx
, dy
: Integer); inline;
361 function getCameraObj(): TObj
;
364 property Vel
: TPoint2i read FObj
.Vel
;
365 property Obj
: TObj read FObj
;
367 property Name
: String read FName write FName
;
368 property Model
: TPlayerModel read FModel
;
369 property Health
: Integer read FHealth write FHealth
;
370 property Lives
: Byte read FLives write FLives
;
371 property Armor
: Integer read FArmor write FArmor
;
372 property Air
: Integer read FAir write FAir
;
373 property JetFuel
: Integer read FJetFuel write FJetFuel
;
374 property Frags
: Integer read FFrags write FFrags
;
375 property Death
: Integer read FDeath write FDeath
;
376 property Kills
: Integer read FKills write FKills
;
377 property CurrWeap
: Byte read FCurrWeap write FCurrWeap
;
378 property MonsterKills
: Integer read FMonsterKills write FMonsterKills
;
379 property Secrets
: Integer read FSecrets
;
380 property GodMode
: Boolean read FGodMode write FGodMode
;
381 property NoTarget
: Boolean read FNoTarget write FNoTarget
;
382 property NoReload
: Boolean read FNoReload write FNoReload
;
383 property alive
: Boolean read FAlive write FAlive
;
384 property Flag
: Byte read FFlag
;
385 property Team
: Byte read FTeam write FTeam
;
386 property Direction
: TDirection read FDirection
;
387 property GameX
: Integer read FObj
.X write FObj
.X
;
388 property GameY
: Integer read FObj
.Y write FObj
.Y
;
389 property GameVelX
: Integer read FObj
.Vel
.X write FObj
.Vel
.X
;
390 property GameVelY
: Integer read FObj
.Vel
.Y write FObj
.Vel
.Y
;
391 property GameAccelX
: Integer read FObj
.Accel
.X write FObj
.Accel
.X
;
392 property GameAccelY
: Integer read FObj
.Accel
.Y write FObj
.Accel
.Y
;
393 property IncCam
: Integer read FIncCam write FIncCam
;
394 property IncCamOld
: Integer read FIncCamOld write FIncCamOld
;
395 property SlopeOld
: Integer read FSlopeOld write FSlopeOld
;
396 property UID
: Word read FUID write FUID
;
397 property JustTeleported
: Boolean read FJustTeleported write FJustTeleported
;
398 property NetTime
: LongWord read FNetTime write FNetTime
;
401 property eName
: String read FName write FName
;
402 property eHealth
: Integer read FHealth write FHealth
;
403 property eLives
: Byte read FLives write FLives
;
404 property eArmor
: Integer read FArmor write FArmor
;
405 property eAir
: Integer read FAir write FAir
;
406 property eJetFuel
: Integer read FJetFuel write FJetFuel
;
407 property eFrags
: Integer read FFrags write FFrags
;
408 property eDeath
: Integer read FDeath write FDeath
;
409 property eKills
: Integer read FKills write FKills
;
410 property eCurrWeap
: Byte read FCurrWeap write FCurrWeap
;
411 property eMonsterKills
: Integer read FMonsterKills write FMonsterKills
;
412 property eSecrets
: Integer read FSecrets write FSecrets
;
413 property eGodMode
: Boolean read FGodMode write FGodMode
;
414 property eNoTarget
: Boolean read FNoTarget write FNoTarget
;
415 property eNoReload
: Boolean read FNoReload write FNoReload
;
416 property eAlive
: Boolean read FAlive write FAlive
;
417 property eFlag
: Byte read FFlag
;
418 property eTeam
: Byte read FTeam write FTeam
;
419 property eDirection
: TDirection read FDirection
;
420 property eGameX
: Integer read FObj
.X write FObj
.X
;
421 property eGameY
: Integer read FObj
.Y write FObj
.Y
;
422 property eGameVelX
: Integer read FObj
.Vel
.X write FObj
.Vel
.X
;
423 property eGameVelY
: Integer read FObj
.Vel
.Y write FObj
.Vel
.Y
;
424 property eGameAccelX
: Integer read FObj
.Accel
.X write FObj
.Accel
.X
;
425 property eGameAccelY
: Integer read FObj
.Accel
.Y write FObj
.Accel
.Y
;
426 property eIncCam
: Integer read FIncCam write FIncCam
;
427 property eUID
: Word read FUID
;
428 property eJustTeleported
: Boolean read FJustTeleported
;
429 property eNetTime
: LongWord read FNetTime
;
431 // set this before assigning something to `eDamage`
432 property eDamageType
: Integer read mEDamageType write mEDamageType
;
433 property eDamage
: Integer write doDamage
;
444 WeaponPrior
: packed array [WP_FIRST
..WP_LAST
] of Byte;
445 CloseWeaponPrior
: packed array [WP_FIRST
..WP_LAST
] of Byte;
446 //SafeWeaponPrior: Array [WP_FIRST..WP_LAST] of Byte;
449 procedure save (st
: TStream
);
450 procedure load (st
: TStream
);
458 TBot
= class(TPlayer
)
460 FSelectedWeapon
: Byte;
463 FAIFlags
: Array of TAIFlag
;
464 FDifficult
: TDifficult
;
466 function GetRnd(a
: Byte): Boolean;
467 function GetInterval(a
: Byte; radius
: SmallInt): SmallInt;
468 function RunDirection(): TDirection
;
469 function FullInStep(XInc
, YInc
: Integer): Boolean;
470 //function NeedItem(Item: Byte): Byte;
471 procedure SelectWeapon(Dist
: Integer);
472 procedure SetAIFlag(aName
, fValue
: String20
);
473 function GetAIFlag(aName
: String20
): String20
;
474 procedure RemoveAIFlag(aName
: String20
);
475 function Healthy(): Byte;
476 procedure UpdateMove();
477 procedure UpdateCombat();
478 function KeyPressed(Key
: Word): Boolean;
479 procedure ReleaseKey(Key
: Byte);
480 function TargetOnScreen(TX
, TY
: Integer): Boolean;
481 procedure OnDamage(Angle
: SmallInt); override;
484 procedure Respawn(Silent
: Boolean; Force
: Boolean = False); override;
485 constructor Create(); override;
486 destructor Destroy(); override;
487 procedure Draw(); override;
488 function PickItem(ItemType
: Byte; force
: Boolean; var remove
: Boolean): Boolean; override;
489 function Heal(value
: Word; Soft
: Boolean): Boolean; override;
490 procedure Update(); override;
491 procedure SaveState (st
: TStream
); override;
492 procedure LoadState (st
: TStream
); override;
504 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
505 procedure moveBy (dx
, dy
: Integer); inline;
507 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
521 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
522 procedure moveBy (dx
, dy
: Integer); inline;
524 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
527 TCorpse
= class{$IFDEF USE_MEMPOOL}(TPoolObject
){$ENDIF}
536 FAnimation
: TAnimation
;
537 FAnimationMask
: TAnimation
;
540 constructor Create(X
, Y
: Integer; ModelName
: String; aMess
: Boolean);
541 destructor Destroy(); override;
542 procedure Damage(Value
: Word; SpawnerUID
: Word; vx
, vy
: Integer);
545 procedure SaveState (st
: TStream
);
546 procedure LoadState (st
: TStream
);
548 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
549 procedure moveBy (dx
, dy
: Integer); inline;
551 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
553 function ObjPtr (): PObj
; inline;
555 property Obj
: TObj read FObj
; // copies object
556 property State
: Byte read FState
;
557 property Mess
: Boolean read FMess
;
560 TTeamStat
= Array [TEAM_RED
..TEAM_BLUE
] of
566 gPlayers
: Array of TPlayer
;
567 gCorpses
: Array of TCorpse
;
568 gGibs
: Array of TGib
;
569 gShells
: Array of TShell
;
570 gTeamStat
: TTeamStat
;
571 gFly
: Boolean = False;
572 gAimLine
: Boolean = False;
573 gChatBubble
: Integer = 0;
574 gPlayerIndicator
: Integer = 1;
575 gPlayerIndicatorStyle
: Integer = 0;
577 gSpectLatchPID1
: Word = 0;
578 gSpectLatchPID2
: Word = 0;
579 MAX_RUNVEL
: Integer = 8;
580 VEL_JUMP
: Integer = 10;
581 SHELL_TIMEOUT
: Cardinal = 60000;
583 function Lerp(X
, Y
, Factor
: Integer): Integer;
585 procedure g_Gibs_SetMax(Count
: Word);
586 function g_Gibs_GetMax(): Word;
587 procedure g_Corpses_SetMax(Count
: Word);
588 function g_Corpses_GetMax(): Word;
589 procedure g_Shells_SetMax(Count
: Word);
590 function g_Shells_GetMax(): Word;
592 procedure g_Player_Init();
593 procedure g_Player_Free();
594 function g_Player_Create(ModelName
: String; Color
: TRGB
; Team
: Byte; Bot
: Boolean): Word;
595 function g_Player_CreateFromState (st
: TStream
): Word;
596 procedure g_Player_Remove(UID
: Word);
597 procedure g_Player_ResetTeams();
598 procedure g_Player_PreUpdate();
599 procedure g_Player_UpdateAll();
600 procedure g_Player_DrawAll();
601 procedure g_Player_DrawDebug(p
: TPlayer
);
602 procedure g_Player_DrawHealth();
603 procedure g_Player_RememberAll();
604 procedure g_Player_ResetAll(Force
, Silent
: Boolean);
605 function g_Player_Get(UID
: Word): TPlayer
;
606 function g_Player_GetCount(): Byte;
607 function g_Player_GetStats(): TPlayerStatArray
;
608 function g_Player_ValidName(Name
: String): Boolean;
609 function g_Player_CreateCorpse(Player
: TPlayer
): Integer;
610 procedure g_Player_CreateGibs(fX
, fY
: Integer; ModelName
: String; fColor
: TRGB
);
611 procedure g_Player_CreateShell(fX
, fY
, dX
, dY
: Integer; T
: Byte);
612 procedure g_Player_UpdatePhysicalObjects();
613 procedure g_Player_DrawCorpses();
614 procedure g_Player_DrawShells();
615 procedure g_Player_RemoveAllCorpses();
616 procedure g_Player_Corpses_SaveState (st
: TStream
);
617 procedure g_Player_Corpses_LoadState (st
: TStream
);
618 procedure g_Player_ResetReady();
619 procedure g_Bot_Add(Team
, Difficult
: Byte; Handicap
: Integer = 100);
620 procedure g_Bot_AddList(Team
: Byte; lname
: ShortString; num
: Integer = -1; Handicap
: Integer = 100);
621 procedure g_Bot_MixNames();
622 procedure g_Bot_RemoveAll();
627 {$INCLUDE ../nogl/noGLuses.inc}
628 {$IFDEF ENABLE_HOLMES}
631 e_log
, g_map
, g_items
, g_console
, g_gfx
, Math
,
632 g_options
, g_triggers
, g_menu
, g_game
, g_grid
, e_res
,
633 wadreader
, g_main
, g_monsters
, CONFIG
, g_language
,
634 g_net
, g_netmsg
, g_window
,
637 const PLR_SAVE_VERSION
= 0;
647 diag_precision
: Byte;
651 w_prior1
: Array [WP_FIRST
..WP_LAST
] of Byte;
652 w_prior2
: Array [WP_FIRST
..WP_LAST
] of Byte;
653 w_prior3
: Array [WP_FIRST
..WP_LAST
] of Byte;
657 TIME_RESPAWN1
= 1500;
658 TIME_RESPAWN2
= 2000;
659 TIME_RESPAWN3
= 3000;
662 JET_MAX
= 540; // ~30 sec
663 PLAYER_SUIT_TIME
= 30000;
664 PLAYER_INVUL_TIME
= 30000;
665 PLAYER_INVIS_TIME
= 35000;
666 FRAG_COMBO_TIME
= 3000;
670 ANGLE_RIGHTDOWN
= -35;
672 ANGLE_LEFTDOWN
= -145;
673 PLAYER_HEADRECT
: TRectWH
= (X
:24; Y
:12; Width
:20; Height
:12);
674 WEAPONPOINT
: Array [TDirection
] of TDFPoint
= ((X
:16; Y
:32), (X
:47; Y
:32));
677 BOT_UNSAFEDIST
= 128;
678 TEAMCOLOR
: Array [TEAM_RED
..TEAM_BLUE
] of TRGB
= ((R
:255; G
:0; B
:0),
680 DIFFICULT_EASY
: TDifficult
= (DiagFire
: 32; InvisFire
: 32; DiagPrecision
: 32;
681 FlyPrecision
: 32; Cover
: 32; CloseJump
: 32;
682 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
683 DIFFICULT_MEDIUM
: TDifficult
= (DiagFire
: 127; InvisFire
: 127; DiagPrecision
: 127;
684 FlyPrecision
: 127; Cover
: 127; CloseJump
: 127;
685 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
686 DIFFICULT_HARD
: TDifficult
= (DiagFire
: 255; InvisFire
: 255; DiagPrecision
: 255;
687 FlyPrecision
: 255; Cover
: 255; CloseJump
: 255;
688 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
689 WEAPON_PRIOR1
: Array [WP_FIRST
..WP_LAST
] of Byte =
690 (WEAPON_FLAMETHROWER
, WEAPON_SUPERPULEMET
,
691 WEAPON_SHOTGUN2
, WEAPON_SHOTGUN1
,
692 WEAPON_CHAINGUN
, WEAPON_PLASMA
, WEAPON_ROCKETLAUNCHER
,
693 WEAPON_BFG
, WEAPON_PISTOL
, WEAPON_SAW
, WEAPON_KASTET
);
694 WEAPON_PRIOR2
: Array [WP_FIRST
..WP_LAST
] of Byte =
695 (WEAPON_FLAMETHROWER
, WEAPON_SUPERPULEMET
,
696 WEAPON_BFG
, WEAPON_ROCKETLAUNCHER
,
697 WEAPON_SHOTGUN2
, WEAPON_PLASMA
, WEAPON_SHOTGUN1
,
698 WEAPON_CHAINGUN
, WEAPON_PISTOL
, WEAPON_SAW
, WEAPON_KASTET
);
699 //WEAPON_PRIOR3: Array [WP_FIRST..WP_LAST] of Byte =
700 // (WEAPON_FLAMETHROWER, WEAPON_SUPERPULEMET,
701 // WEAPON_BFG, WEAPON_PLASMA, WEAPON_SHOTGUN2,
702 // WEAPON_CHAINGUN, WEAPON_SHOTGUN1, WEAPON_SAW,
703 // WEAPON_ROCKETLAUNCHER, WEAPON_PISTOL, WEAPON_KASTET);
704 WEAPON_RELOAD
: Array [WP_FIRST
..WP_LAST
] of Byte =
705 (5, 2, 6, 18, 36, 2, 12, 2, 14, 2, 2);
707 PLAYER_SIGNATURE
= $52594C50; // 'PLYR'
708 CORPSE_SIGNATURE
= $50524F43; // 'CORP'
710 BOTNAMES_FILENAME
= 'botnames.txt';
711 BOTLIST_FILENAME
= 'botlist.txt';
715 MaxCorpses
: Word = 20;
716 MaxShells
: Word = 300;
717 CurrentGib
: Integer = 0;
718 CurrentShell
: Integer = 0;
719 BotNames
: Array of String;
720 BotList
: Array of TBotProfile
;
721 SavedStates
: Array of TPlayerSavedState
;
724 function Lerp(X
, Y
, Factor
: Integer): Integer;
726 Result
:= X
+ ((Y
- X
) div Factor
);
729 function SameTeam(UID1
, UID2
: Word): Boolean;
733 if (UID1
> UID_MAX_PLAYER
) or (UID1
<= UID_MAX_GAME
) or
734 (UID2
> UID_MAX_PLAYER
) or (UID2
<= UID_MAX_GAME
) then Exit
;
736 if (g_Player_Get(UID1
) = nil) or (g_Player_Get(UID2
) = nil) then Exit
;
738 if ((g_Player_Get(UID1
).Team
= TEAM_NONE
) or
739 (g_Player_Get(UID2
).Team
= TEAM_NONE
)) then Exit
;
741 Result
:= g_Player_Get(UID1
).FTeam
= g_Player_Get(UID2
).FTeam
;
744 procedure g_Gibs_SetMax(Count
: Word);
747 SetLength(gGibs
, Count
);
749 if CurrentGib
>= Count
then
753 function g_Gibs_GetMax(): Word;
758 procedure g_Shells_SetMax(Count
: Word);
761 SetLength(gShells
, Count
);
763 if CurrentShell
>= Count
then
767 function g_Shells_GetMax(): Word;
773 procedure g_Corpses_SetMax(Count
: Word);
776 SetLength(gCorpses
, Count
);
779 function g_Corpses_GetMax(): Word;
781 Result
:= MaxCorpses
;
784 function g_Player_Create(ModelName
: String; Color
: TRGB
; Team
: Byte; Bot
: Boolean): Word;
794 // Åñòü ëè ìåñòî â gPlayers:
795 if gPlayers
<> nil then
796 for a
:= 0 to High(gPlayers
) do
797 if gPlayers
[a
] = nil then
803 // Íåò ìåñòà - ðàñøèðÿåì gPlayers:
806 SetLength(gPlayers
, Length(gPlayers
)+1);
810 // Ñîçäàåì îáúåêò èãðîêà:
812 gPlayers
[a
] := TBot
.Create()
814 gPlayers
[a
] := TPlayer
.Create();
817 gPlayers
[a
].FActualModelName
:= ModelName
;
818 gPlayers
[a
].SetModel(ModelName
);
820 // Íåò ìîäåëè - ñîçäàíèå íå âîçìîæíî:
821 if gPlayers
[a
].FModel
= nil then
825 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], [ModelName
]));
829 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
830 if Random(2) = 0 then
834 gPlayers
[a
].FPreferredTeam
:= Team
;
836 case gGameSettings
.GameMode
of
837 GM_DM
: gPlayers
[a
].FTeam
:= TEAM_NONE
;
839 GM_CTF
: gPlayers
[a
].FTeam
:= gPlayers
[a
].FPreferredTeam
;
841 GM_COOP
: gPlayers
[a
].FTeam
:= TEAM_COOP
;
844 // Åñëè êîìàíäíàÿ èãðà - êðàñèì ìîäåëü â öâåò êîìàíäû:
845 gPlayers
[a
].FColor
:= Color
;
846 if gPlayers
[a
].FTeam
in [TEAM_RED
, TEAM_BLUE
] then
847 gPlayers
[a
].FModel
.Color
:= TEAMCOLOR
[gPlayers
[a
].FTeam
]
849 gPlayers
[a
].FModel
.Color
:= Color
;
851 gPlayers
[a
].FUID
:= g_CreateUID(UID_PLAYER
);
852 gPlayers
[a
].FAlive
:= False;
854 Result
:= gPlayers
[a
].FUID
;
857 function g_Player_CreateFromState (st
: TStream
): Word;
858 var a
: Integer; ok
, Bot
: Boolean; pos
: Int64;
862 // check signature and entity type
864 if not utils
.checkSign(st
, 'PLYR') then raise XStreamError
.Create('invalid player signature');
865 if (utils
.readByte(st
) <> PLR_SAVE_VERSION
) then raise XStreamError
.Create('invalid player version');
866 Bot
:= utils
.readBool(st
);
869 // find free player slot
871 for a
:= 0 to High(gPlayers
) do
872 if gPlayers
[a
] = nil then
878 // allocate player slot
881 SetLength(gPlayers
, Length(gPlayers
)+1);
885 // create entity and load state
887 gPlayers
[a
] := TBot
.Create()
889 gPlayers
[a
] := TPlayer
.Create();
890 gPlayers
[a
].FPhysics
:= True; // ???
891 gPlayers
[a
].LoadState(st
);
893 result
:= gPlayers
[a
].FUID
;
897 procedure g_Player_ResetTeams();
901 if g_Game_IsClient
then
903 if gPlayers
= nil then
905 for a
:= Low(gPlayers
) to High(gPlayers
) do
906 if gPlayers
[a
] <> nil then
907 case gGameSettings
.GameMode
of
909 gPlayers
[a
].ChangeTeam(TEAM_NONE
);
911 if not (gPlayers
[a
].Team
in [TEAM_RED
, TEAM_BLUE
]) then
912 if gPlayers
[a
].FPreferredTeam
in [TEAM_RED
, TEAM_BLUE
] then
913 gPlayers
[a
].ChangeTeam(gPlayers
[a
].FPreferredTeam
)
916 gPlayers
[a
].ChangeTeam(TEAM_RED
)
918 gPlayers
[a
].ChangeTeam(TEAM_BLUE
);
921 gPlayers
[a
].ChangeTeam(TEAM_COOP
);
925 procedure g_Bot_Add(Team
, Difficult
: Byte; Handicap
: Integer = 100);
928 _name
, _model
: String;
931 if not g_Game_IsServer
then Exit
;
933 // Ñïèñîê íàçâàíèé ìîäåëåé:
934 m
:= g_PlayerModel_GetNames();
939 if (gGameSettings
.GameType
= GT_SINGLE
) or (gGameSettings
.GameMode
= GM_COOP
) then
940 Team
:= TEAM_COOP
// COOP
942 if gGameSettings
.GameMode
= GM_DM
then
943 Team
:= TEAM_NONE
// DM
945 if Team
= TEAM_NONE
then // CTF / TDM
947 // Àâòîáàëàíñ êîìàíä:
951 for a
:= 0 to High(gPlayers
) do
952 if gPlayers
[a
] <> nil then
954 if gPlayers
[a
].Team
= TEAM_RED
then
957 if gPlayers
[a
].Team
= TEAM_BLUE
then
967 if Random(2) = 0 then
973 // Âûáèðàåì áîòó èìÿ:
975 if BotNames
<> nil then
976 for a
:= 0 to High(BotNames
) do
977 if g_Player_ValidName(BotNames
[a
]) then
979 _name
:= BotNames
[a
];
983 // Âûáèðàåì ñëó÷àéíóþ ìîäåëü:
984 _model
:= m
[Random(Length(m
))];
987 with g_Player_Get(g_Player_Create(_model
,
988 _RGB(Min(Random(9)*32, 255),
989 Min(Random(9)*32, 255),
990 Min(Random(9)*32, 255)),
991 Team
, True)) as TBot
do
993 // Åñëè èìåíè íåò, äåëàåì åãî èç UID áîòà
995 Name
:= Format('DFBOT%.5d', [UID
])
1000 1: FDifficult
:= DIFFICULT_EASY
;
1001 2: FDifficult
:= DIFFICULT_MEDIUM
;
1002 else FDifficult
:= DIFFICULT_HARD
;
1005 for a
:= WP_FIRST
to WP_LAST
do
1007 FDifficult
.WeaponPrior
[a
] := WEAPON_PRIOR1
[a
];
1008 FDifficult
.CloseWeaponPrior
[a
] := WEAPON_PRIOR2
[a
];
1009 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
1012 FHandicap
:= Handicap
;
1014 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [Name
]), True);
1016 if g_Game_IsNet
then MH_SEND_PlayerCreate(UID
);
1017 if g_Game_IsServer
and (gGameSettings
.MaxLives
> 0) then
1022 procedure g_Bot_AddList(Team
: Byte; lName
: ShortString; num
: Integer = -1; Handicap
: Integer = 100);
1025 _name
, _model
: String;
1028 if not g_Game_IsServer
then Exit
;
1030 // Ñïèñîê íàçâàíèé ìîäåëåé:
1031 m
:= g_PlayerModel_GetNames();
1036 if (gGameSettings
.GameType
= GT_SINGLE
) or (gGameSettings
.GameMode
= GM_COOP
) then
1037 Team
:= TEAM_COOP
// COOP
1039 if gGameSettings
.GameMode
= GM_DM
then
1040 Team
:= TEAM_NONE
// DM
1042 if Team
= TEAM_NONE
then
1043 Team
:= BotList
[num
].team
; // CTF / TDM
1045 // Âûáèðàåì íàñòðîéêè áîòà èç ñïèñêà ïî íîìåðó èëè èìåíè:
1046 lName
:= AnsiLowerCase(lName
);
1047 if (num
< 0) or (num
> Length(BotList
)-1) then
1049 if (num
= -1) and (lName
<> '') and (BotList
<> nil) then
1050 for a
:= 0 to High(BotList
) do
1051 if AnsiLowerCase(BotList
[a
].name
) = lName
then
1060 _name
:= BotList
[num
].name
;
1061 // Çàíÿòî - âûáèðàåì ñëó÷àéíîå:
1062 if not g_Player_ValidName(_name
) then
1064 _name
:= Format('DFBOT%.2d', [Random(100)]);
1065 until g_Player_ValidName(_name
);
1068 _model
:= BotList
[num
].model
;
1069 // Íåò òàêîé - âûáèðàåì ñëó÷àéíóþ:
1070 if not InSArray(_model
, m
) then
1071 _model
:= m
[Random(Length(m
))];
1074 with g_Player_Get(g_Player_Create(_model
, BotList
[num
].color
, Team
, True)) as TBot
do
1078 FDifficult
.DiagFire
:= BotList
[num
].diag_fire
;
1079 FDifficult
.InvisFire
:= BotList
[num
].invis_fire
;
1080 FDifficult
.DiagPrecision
:= BotList
[num
].diag_precision
;
1081 FDifficult
.FlyPrecision
:= BotList
[num
].fly_precision
;
1082 FDifficult
.Cover
:= BotList
[num
].cover
;
1083 FDifficult
.CloseJump
:= BotList
[num
].close_jump
;
1085 FHandicap
:= Handicap
;
1087 for a
:= WP_FIRST
to WP_LAST
do
1089 FDifficult
.WeaponPrior
[a
] := BotList
[num
].w_prior1
[a
];
1090 FDifficult
.CloseWeaponPrior
[a
] := BotList
[num
].w_prior2
[a
];
1091 //FDifficult.SafeWeaponPrior[a] := BotList[num].w_prior3[a];
1094 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [Name
]), True);
1096 if g_Game_IsNet
then MH_SEND_PlayerCreate(UID
);
1100 procedure g_Bot_RemoveAll();
1104 if not g_Game_IsServer
then Exit
;
1105 if gPlayers
= nil then Exit
;
1107 for a
:= 0 to High(gPlayers
) do
1108 if gPlayers
[a
] <> nil then
1109 if gPlayers
[a
] is TBot
then
1111 gPlayers
[a
].Lives
:= 0;
1112 gPlayers
[a
].Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
1113 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [gPlayers
[a
].Name
]), True);
1114 g_Player_Remove(gPlayers
[a
].FUID
);
1120 procedure g_Bot_MixNames();
1125 if BotNames
<> nil then
1126 for a
:= 0 to High(BotNames
) do
1128 b
:= Random(Length(BotNames
));
1130 Botnames
[a
] := BotNames
[b
];
1135 procedure g_Player_Remove(UID
: Word);
1139 if gPlayers
= nil then Exit
;
1141 if g_Game_IsServer
and g_Game_IsNet
then
1142 MH_SEND_PlayerDelete(UID
);
1144 for i
:= 0 to High(gPlayers
) do
1145 if gPlayers
[i
] <> nil then
1146 if gPlayers
[i
].FUID
= UID
then
1148 if gPlayers
[i
] is TPlayer
then
1149 TPlayer(gPlayers
[i
]).Free()
1151 TBot(gPlayers
[i
]).Free();
1157 procedure g_Player_Init();
1168 path
:= BOTNAMES_FILENAME
;
1169 if e_FindResource(DataDirs
, path
) = false then
1172 // ×èòàåì âîçìîæíûå èìåíà áîòîâ èç ôàéëà:
1173 AssignFile(F
, path
);
1184 SetLength(BotNames
, Length(BotNames
)+1);
1185 BotNames
[High(BotNames
)] := s
;
1193 // ×èòàåì ôàéë ñ ïàðàìåòðàìè áîòîâ:
1194 config
:= TConfig
.CreateFile(path
);
1198 while config
.SectionExists(IntToStr(a
)) do
1200 SetLength(BotList
, Length(BotList
)+1);
1202 with BotList
[High(BotList
)] do
1205 name
:= config
.ReadStr(IntToStr(a
), 'name', '');
1207 model
:= config
.ReadStr(IntToStr(a
), 'model', '');
1209 if config
.ReadStr(IntToStr(a
), 'team', 'red') = 'red' then
1214 sa
:= parse(config
.ReadStr(IntToStr(a
), 'color', ''));
1215 color
.R
:= StrToIntDef(sa
[0], 0);
1216 color
.G
:= StrToIntDef(sa
[1], 0);
1217 color
.B
:= StrToIntDef(sa
[2], 0);
1218 // Âåðîÿòíîñòü ñòðåëüáû ïîä óãëîì:
1219 diag_fire
:= config
.ReadInt(IntToStr(a
), 'diag_fire', 0);
1220 // Âåðîÿòíîñòü îòâåòíîãî îãíÿ ïî íåâèäèìîìó ñîïåðíèêó:
1221 invis_fire
:= config
.ReadInt(IntToStr(a
), 'invis_fire', 0);
1222 // Òî÷íîñòü ñòðåëüáû ïîä óãëîì:
1223 diag_precision
:= config
.ReadInt(IntToStr(a
), 'diag_precision', 0);
1224 // Òî÷íîñòü ñòðåëüáû â ïîëåòå:
1225 fly_precision
:= config
.ReadInt(IntToStr(a
), 'fly_precision', 0);
1226 // Òî÷íîñòü óêëîíåíèÿ îò ñíàðÿäîâ:
1227 cover
:= config
.ReadInt(IntToStr(a
), 'cover', 0);
1228 // Âåðîÿòíîñòü ïðûæêà ïðè ïðèáëèæåíèè ñîïåðíèêà:
1229 close_jump
:= config
.ReadInt(IntToStr(a
), 'close_jump', 0);
1230 // Ïðèîðèòåòû îðóæèÿ äëÿ äàëüíåãî áîÿ:
1231 sa
:= parse(config
.ReadStr(IntToStr(a
), 'w_prior1', ''));
1232 if Length(sa
) = 10 then
1234 w_prior1
[b
] := EnsureRange(StrToInt(sa
[b
]), 0, 9);
1235 // Ïðèîðèòåòû îðóæèÿ äëÿ áëèæíåãî áîÿ:
1236 sa
:= parse(config
.ReadStr(IntToStr(a
), 'w_prior2', ''));
1237 if Length(sa
) = 10 then
1239 w_prior2
[b
] := EnsureRange(StrToInt(sa
[b
]), 0, 9);
1241 {sa := parse(config.ReadStr(IntToStr(a), 'w_prior3', ''));
1242 if Length(sa) = 10 then
1244 w_prior3[b] := EnsureRange(StrToInt(sa[b]), 0, 9);}
1251 SetLength(SavedStates
, 0);
1254 procedure g_Player_Free();
1258 if gPlayers
<> nil then
1260 for i
:= 0 to High(gPlayers
) do
1261 if gPlayers
[i
] <> nil then
1263 if gPlayers
[i
] is TPlayer
then
1264 TPlayer(gPlayers
[i
]).Free()
1266 TBot(gPlayers
[i
]).Free();
1275 SetLength(SavedStates
, 0);
1278 procedure g_Player_PreUpdate();
1282 if gPlayers
= nil then Exit
;
1283 for i
:= 0 to High(gPlayers
) do
1284 if gPlayers
[i
] <> nil then
1285 gPlayers
[i
].PreUpdate();
1288 procedure g_Player_UpdateAll();
1292 if gPlayers
= nil then Exit
;
1294 //e_WriteLog('***g_Player_UpdateAll: ENTER', MSG_WARNING);
1295 for i
:= 0 to High(gPlayers
) do
1297 if gPlayers
[i
] <> nil then
1299 if gPlayers
[i
] is TPlayer
then
1301 gPlayers
[i
].Update();
1302 gPlayers
[i
].RealizeCurrentWeapon(); // WARNING! DO NOT MOVE THIS INTO `Update()`!
1306 // bot updates weapons in `UpdateCombat()`
1307 TBot(gPlayers
[i
]).Update();
1311 //e_WriteLog('***g_Player_UpdateAll: EXIT', MSG_WARNING);
1314 procedure g_Player_DrawAll();
1318 if gPlayers
= nil then Exit
;
1320 for i
:= 0 to High(gPlayers
) do
1321 if gPlayers
[i
] <> nil then
1322 if gPlayers
[i
] is TPlayer
then gPlayers
[i
].Draw()
1323 else TBot(gPlayers
[i
]).Draw();
1326 procedure g_Player_DrawDebug(p
: TPlayer
);
1330 if p
= nil then Exit
;
1331 if (@p
.FObj
) = nil then Exit
;
1333 e_TextureFontGetSize(gStdFont
, fW
, fH
);
1335 e_TextureFontPrint(0, 0 , 'Pos X: ' + IntToStr(p
.FObj
.X
), gStdFont
);
1336 e_TextureFontPrint(0, fH
, 'Pos Y: ' + IntToStr(p
.FObj
.Y
), gStdFont
);
1337 e_TextureFontPrint(0, fH
* 2, 'Vel X: ' + IntToStr(p
.FObj
.Vel
.X
), gStdFont
);
1338 e_TextureFontPrint(0, fH
* 3, 'Vel Y: ' + IntToStr(p
.FObj
.Vel
.Y
), gStdFont
);
1339 e_TextureFontPrint(0, fH
* 4, 'Acc X: ' + IntToStr(p
.FObj
.Accel
.X
), gStdFont
);
1340 e_TextureFontPrint(0, fH
* 5, 'Acc Y: ' + IntToStr(p
.FObj
.Accel
.Y
), gStdFont
);
1341 e_TextureFontPrint(0, fH
* 6, 'Old X: ' + IntToStr(p
.FObj
.oldX
), gStdFont
);
1342 e_TextureFontPrint(0, fH
* 7, 'Old Y: ' + IntToStr(p
.FObj
.oldY
), gStdFont
);
1345 procedure g_Player_DrawHealth();
1350 if gPlayers
= nil then Exit
;
1351 e_TextureFontGetSize(gStdFont
, fW
, fH
);
1353 for i
:= 0 to High(gPlayers
) do
1354 if gPlayers
[i
] <> nil then
1356 e_TextureFontPrint(gPlayers
[i
].FObj
.X
+ gPlayers
[i
].FObj
.Rect
.X
,
1357 gPlayers
[i
].FObj
.Y
+ gPlayers
[i
].FObj
.Rect
.Y
+ gPlayers
[i
].FObj
.Rect
.Height
- fH
* 2,
1358 IntToStr(gPlayers
[i
].FHealth
), gStdFont
);
1359 e_TextureFontPrint(gPlayers
[i
].FObj
.X
+ gPlayers
[i
].FObj
.Rect
.X
,
1360 gPlayers
[i
].FObj
.Y
+ gPlayers
[i
].FObj
.Rect
.Y
+ gPlayers
[i
].FObj
.Rect
.Height
- fH
,
1361 IntToStr(gPlayers
[i
].FArmor
), gStdFont
);
1365 function g_Player_Get(UID
: Word): TPlayer
;
1371 if gPlayers
= nil then
1374 for a
:= 0 to High(gPlayers
) do
1375 if gPlayers
[a
] <> nil then
1376 if gPlayers
[a
].FUID
= UID
then
1378 Result
:= gPlayers
[a
];
1383 function g_Player_GetCount(): Byte;
1389 if gPlayers
= nil then
1392 for a
:= 0 to High(gPlayers
) do
1393 if gPlayers
[a
] <> nil then
1394 Result
:= Result
+ 1;
1397 function g_Player_GetStats(): TPlayerStatArray
;
1403 if gPlayers
= nil then Exit
;
1405 for a
:= 0 to High(gPlayers
) do
1406 if gPlayers
[a
] <> nil then
1408 SetLength(Result
, Length(Result
)+1);
1409 with Result
[High(Result
)] do
1412 Ping
:= gPlayers
[a
].FPing
;
1413 Loss
:= gPlayers
[a
].FLoss
;
1414 Name
:= gPlayers
[a
].FName
;
1415 Team
:= gPlayers
[a
].FTeam
;
1416 Frags
:= gPlayers
[a
].FFrags
;
1417 Deaths
:= gPlayers
[a
].FDeath
;
1418 Kills
:= gPlayers
[a
].FKills
;
1419 Color
:= gPlayers
[a
].FModel
.Color
;
1420 Lives
:= gPlayers
[a
].FLives
;
1421 Spectator
:= gPlayers
[a
].FSpectator
;
1422 UID
:= gPlayers
[a
].FUID
;
1427 procedure g_Player_ResetReady();
1431 if not g_Game_IsServer
then Exit
;
1432 if gPlayers
= nil then Exit
;
1434 for a
:= 0 to High(gPlayers
) do
1435 if gPlayers
[a
] <> nil then
1437 gPlayers
[a
].FReady
:= False;
1438 if g_Game_IsNet
then
1439 MH_SEND_GameEvent(NET_EV_INTER_READY
, gPlayers
[a
].UID
, 'N');
1443 procedure g_Player_RememberAll
;
1447 for i
:= Low(gPlayers
) to High(gPlayers
) do
1448 if (gPlayers
[i
] <> nil) and gPlayers
[i
].alive
then
1449 gPlayers
[i
].RememberState
;
1452 procedure g_Player_ResetAll(Force
, Silent
: Boolean);
1456 gTeamStat
[TEAM_RED
].Goals
:= 0;
1457 gTeamStat
[TEAM_BLUE
].Goals
:= 0;
1459 if gPlayers
<> nil then
1460 for i
:= 0 to High(gPlayers
) do
1461 if gPlayers
[i
] <> nil then
1463 gPlayers
[i
].Reset(Force
);
1465 if gPlayers
[i
] is TPlayer
then
1467 if (not gPlayers
[i
].FSpectator
) or gPlayers
[i
].FWantsInGame
then
1468 gPlayers
[i
].Respawn(Silent
)
1470 gPlayers
[i
].Spectate();
1473 TBot(gPlayers
[i
]).Respawn(Silent
);
1477 function g_Player_CreateCorpse(Player
: TPlayer
): Integer;
1485 if Player
.alive
then
1488 // Ðàçðûâàåì ñâÿçü ñ ïðåæíèì òðóïîì:
1489 i
:= Player
.FCorpse
;
1490 if (i
>= 0) and (i
< Length(gCorpses
)) then
1492 if (gCorpses
[i
] <> nil) and (gCorpses
[i
].FPlayerUID
= Player
.FUID
) then
1493 gCorpses
[i
].FPlayerUID
:= 0;
1496 if Player
.FObj
.Y
>= gMapInfo
.Height
+128 then
1501 if (FHealth
>= -50) or (gGibsCount
= 0) then
1503 if (gCorpses
= nil) or (Length(gCorpses
) = 0) then
1507 for find_id
:= 0 to High(gCorpses
) do
1508 if gCorpses
[find_id
] = nil then
1515 find_id
:= Random(Length(gCorpses
));
1517 gCorpses
[find_id
] := TCorpse
.Create(FObj
.X
, FObj
.Y
, FModel
.Name
, FHealth
< -20);
1518 gCorpses
[find_id
].FColor
:= FModel
.Color
;
1519 gCorpses
[find_id
].FObj
.Vel
:= FObj
.Vel
;
1520 gCorpses
[find_id
].FObj
.Accel
:= FObj
.Accel
;
1521 gCorpses
[find_id
].FPlayerUID
:= FUID
;
1526 g_Player_CreateGibs(FObj
.X
+ PLAYER_RECT_CX
,
1527 FObj
.Y
+ PLAYER_RECT_CY
,
1528 FModel
.Name
, FModel
.Color
);
1532 procedure g_Player_CreateShell(fX
, fY
, dX
, dY
: Integer; T
: Byte);
1536 if (gShells
= nil) or (Length(gShells
) = 0) then
1539 with gShells
[CurrentShell
] do
1545 if T
= SHELL_BULLET
then
1547 if g_Texture_Get('TEXTURE_SHELL_BULLET', SID
) then
1551 Obj
.Rect
.Width
:= 4;
1552 Obj
.Rect
.Height
:= 2;
1556 if g_Texture_Get('TEXTURE_SHELL_SHELL', SID
) then
1560 Obj
.Rect
.Width
:= 7;
1561 Obj
.Rect
.Height
:= 3;
1567 g_Obj_Push(@Obj
, dX
+ Random(4)-Random(4), dY
-Random(4));
1568 positionChanged(); // this updates spatial accelerators
1569 RAngle
:= Random(360);
1570 Timeout
:= gTime
+ SHELL_TIMEOUT
;
1572 if CurrentShell
>= High(gShells
) then
1579 procedure g_Player_CreateGibs(fX
, fY
: Integer; ModelName
: string; fColor
: TRGB
);
1582 GibsArray
: TGibsArray
;
1585 if (gGibs
= nil) or (Length(gGibs
) = 0) then
1587 if not g_PlayerModel_GetGibs(ModelName
, GibsArray
) then
1589 Blood
:= g_PlayerModel_GetBlood(ModelName
);
1591 for a
:= 0 to High(GibsArray
) do
1592 with gGibs
[CurrentGib
] do
1595 ID
:= GibsArray
[a
].ID
;
1596 MaskID
:= GibsArray
[a
].MaskID
;
1599 Obj
.Rect
:= GibsArray
[a
].Rect
;
1600 Obj
.X
:= fX
-GibsArray
[a
].Rect
.X
-(GibsArray
[a
].Rect
.Width
div 2);
1601 Obj
.Y
:= fY
-GibsArray
[a
].Rect
.Y
-(GibsArray
[a
].Rect
.Height
div 2);
1602 g_Obj_PushA(@Obj
, 25 + Random(10), Random(361));
1603 positionChanged(); // this updates spatial accelerators
1604 RAngle
:= Random(360);
1606 if gBloodCount
> 0 then
1607 g_GFX_Blood(fX
, fY
, 16*gBloodCount
+Random(5*gBloodCount
), -16+Random(33), -16+Random(33),
1608 Random(48), Random(48), Blood
.R
, Blood
.G
, Blood
.B
, Blood
.Kind
);
1610 if CurrentGib
>= High(gGibs
) then
1617 procedure g_Player_UpdatePhysicalObjects();
1623 procedure ShellSound_Bounce(X
, Y
: Integer; T
: Byte);
1628 if T
= SHELL_BULLET
then
1629 g_Sound_PlayExAt('SOUND_PLAYER_CASING' + IntToStr(k
), X
, Y
)
1631 g_Sound_PlayExAt('SOUND_PLAYER_SHELL' + IntToStr(k
), X
, Y
);
1636 if gGibs
<> nil then
1637 for i
:= 0 to High(gGibs
) do
1638 if gGibs
[i
].alive
then
1645 mr
:= g_Obj_Move(@Obj
, True, False, True);
1646 positionChanged(); // this updates spatial accelerators
1648 if WordBool(mr
and MOVE_FALLOUT
) then
1654 // Îòëåòàåò îò óäàðà î ñòåíó/ïîòîëîê/ïîë:
1655 if WordBool(mr
and MOVE_HITWALL
) then
1656 Obj
.Vel
.X
:= -(vel
.X
div 2);
1657 if WordBool(mr
and (MOVE_HITCEIL
or MOVE_HITLAND
)) then
1658 Obj
.Vel
.Y
:= -(vel
.Y
div 2);
1660 if (Obj
.Vel
.X
>= 0) then
1662 RAngle
:= RAngle
+ Abs(Obj
.Vel
.X
)*6 + Abs(Obj
.Vel
.Y
);
1663 if RAngle
>= 360 then
1664 RAngle
:= RAngle
mod 360;
1665 end else begin // Counter-clockwise
1666 RAngle
:= RAngle
- Abs(Obj
.Vel
.X
)*6 - Abs(Obj
.Vel
.Y
);
1668 RAngle
:= (360 - (Abs(RAngle
) mod 360)) mod 360;
1671 // Ñîïðîòèâëåíèå âîçäóõà äëÿ êóñêà òðóïà:
1672 if gTime
mod (GAME_TICK
*3) = 0 then
1673 Obj
.Vel
.X
:= z_dec(Obj
.Vel
.X
, 1);
1677 if gCorpses
<> nil then
1678 for i
:= 0 to High(gCorpses
) do
1679 if gCorpses
[i
] <> nil then
1680 if gCorpses
[i
].State
= CORPSE_STATE_REMOVEME
then
1686 gCorpses
[i
].Update();
1689 if gShells
<> nil then
1690 for i
:= 0 to High(gShells
) do
1691 if gShells
[i
].alive
then
1698 mr
:= g_Obj_Move(@Obj
, True, False, True);
1699 positionChanged(); // this updates spatial accelerators
1701 if WordBool(mr
and MOVE_FALLOUT
) or (gShells
[i
].Timeout
< gTime
) then
1707 // Îòëåòàåò îò óäàðà î ñòåíó/ïîòîëîê/ïîë:
1708 if WordBool(mr
and MOVE_HITWALL
) then
1710 Obj
.Vel
.X
:= -(vel
.X
div 2);
1711 if not WordBool(mr
and MOVE_INWATER
) then
1712 ShellSound_Bounce(Obj
.X
, Obj
.Y
, SType
);
1714 if WordBool(mr
and (MOVE_HITCEIL
or MOVE_HITLAND
)) then
1716 Obj
.Vel
.Y
:= -(vel
.Y
div 2);
1717 if Obj
.Vel
.X
<> 0 then Obj
.Vel
.X
:= Obj
.Vel
.X
div 2;
1718 if (Obj
.Vel
.X
= 0) and (Obj
.Vel
.Y
= 0) then
1720 if RAngle
mod 90 <> 0 then
1721 RAngle
:= (RAngle
div 90) * 90;
1723 else if not WordBool(mr
and MOVE_INWATER
) then
1724 ShellSound_Bounce(Obj
.X
, Obj
.Y
, SType
);
1727 if (Obj
.Vel
.X
>= 0) then
1729 RAngle
:= RAngle
+ Abs(Obj
.Vel
.X
)*8 + Abs(Obj
.Vel
.Y
);
1730 if RAngle
>= 360 then
1731 RAngle
:= RAngle
mod 360;
1732 end else begin // Counter-clockwise
1733 RAngle
:= RAngle
- Abs(Obj
.Vel
.X
)*8 - Abs(Obj
.Vel
.Y
);
1735 RAngle
:= (360 - (Abs(RAngle
) mod 360)) mod 360;
1741 procedure TGib
.getMapBox (out x
, y
, w
, h
: Integer); inline;
1743 x
:= Obj
.X
+Obj
.Rect
.X
;
1744 y
:= Obj
.Y
+Obj
.Rect
.Y
;
1745 w
:= Obj
.Rect
.Width
;
1746 h
:= Obj
.Rect
.Height
;
1749 procedure TGib
.moveBy (dx
, dy
: Integer); inline;
1751 if (dx
<> 0) or (dy
<> 0) then
1760 procedure TShell
.getMapBox (out x
, y
, w
, h
: Integer); inline;
1764 w
:= Obj
.Rect
.Width
;
1765 h
:= Obj
.Rect
.Height
;
1768 procedure TShell
.moveBy (dx
, dy
: Integer); inline;
1770 if (dx
<> 0) or (dy
<> 0) then
1779 procedure TGib
.positionChanged (); inline; begin end;
1780 procedure TShell
.positionChanged (); inline; begin end;
1783 procedure g_Player_DrawCorpses();
1788 if gGibs
<> nil then
1789 for i
:= 0 to High(gGibs
) do
1790 if gGibs
[i
].alive
then
1793 if not g_Obj_Collide(sX
, sY
, sWidth
, sHeight
, @Obj
) then
1796 Obj
.lerp(gLerpFactor
, fX
, fY
);
1798 a
.X
:= Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2);
1799 a
.y
:= Obj
.Rect
.Y
+(Obj
.Rect
.Height
div 2);
1801 e_DrawAdv(ID
, fX
, fY
, 0, True, False, RAngle
, @a
, TMirrorType
.None
);
1804 e_DrawAdv(MaskID
, fX
, fY
, 0, True, False, RAngle
, @a
, TMirrorType
.None
);
1810 if gCorpses
<> nil then
1811 for i
:= 0 to High(gCorpses
) do
1812 if gCorpses
[i
] <> nil then
1816 procedure g_Player_DrawShells();
1821 if gShells
<> nil then
1822 for i
:= 0 to High(gShells
) do
1823 if gShells
[i
].alive
then
1826 if not g_Obj_Collide(sX
, sY
, sWidth
, sHeight
, @Obj
) then
1829 Obj
.lerp(gLerpFactor
, fX
, fY
);
1834 e_DrawAdv(SpriteID
, fX
, fY
, 0, True, False, RAngle
, @a
, TMirrorType
.None
);
1838 procedure g_Player_RemoveAllCorpses();
1844 SetLength(gGibs
, MaxGibs
);
1845 SetLength(gShells
, MaxGibs
);
1849 if gCorpses
<> nil then
1850 for i
:= 0 to High(gCorpses
) do
1854 SetLength(gCorpses
, MaxCorpses
);
1857 procedure g_Player_Corpses_SaveState (st
: TStream
);
1861 // Ñ÷èòàåì êîëè÷åñòâî ñóùåñòâóþùèõ òðóïîâ
1863 for i
:= 0 to High(gCorpses
) do if (gCorpses
[i
] <> nil) then Inc(count
);
1865 // Êîëè÷åñòâî òðóïîâ
1866 utils
.writeInt(st
, LongInt(count
));
1868 if (count
= 0) then exit
;
1871 for i
:= 0 to High(gCorpses
) do
1873 if gCorpses
[i
] <> nil then
1876 utils
.writeStr(st
, gCorpses
[i
].FModelName
);
1878 utils
.writeBool(st
, gCorpses
[i
].Mess
);
1879 // Ñîõðàíÿåì äàííûå òðóïà:
1880 gCorpses
[i
].SaveState(st
);
1886 procedure g_Player_Corpses_LoadState (st
: TStream
);
1894 g_Player_RemoveAllCorpses();
1896 // Êîëè÷åñòâî òðóïîâ:
1897 count
:= utils
.readLongInt(st
);
1898 if (count
< 0) or (count
> Length(gCorpses
)) then raise XStreamError
.Create('invalid number of corpses');
1900 if (count
= 0) then exit
;
1903 for i
:= 0 to count
-1 do
1906 str
:= utils
.readStr(st
);
1908 b
:= utils
.readBool(st
);
1910 gCorpses
[i
] := TCorpse
.Create(0, 0, str
, b
);
1911 // Çàãðóæàåì äàííûå òðóïà
1912 gCorpses
[i
].LoadState(st
);
1919 function TPlayer
.isValidViewPort (): Boolean; inline; begin result
:= (viewPortW
> 0) and (viewPortH
> 0); end;
1921 procedure TPlayer
.BFGHit();
1923 g_Weapon_BFGHit(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
1924 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2));
1925 if g_Game_IsServer
and g_Game_IsNet
then
1926 MH_SEND_Effect(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
1927 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2),
1931 procedure TPlayer
.ChangeModel(ModelName
: string);
1933 locModel
: TPlayerModel
;
1935 locModel
:= g_PlayerModel_Get(ModelName
);
1936 if locModel
= nil then Exit
;
1942 procedure TPlayer
.SetModel(ModelName
: string);
1946 m
:= g_PlayerModel_Get(ModelName
);
1949 g_SimpleError(Format(_lc
[I_GAME_ERROR_MODEL_FALLBACK
], [ModelName
]));
1950 m
:= g_PlayerModel_Get('doomer');
1953 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], ['doomer']));
1958 if FModel
<> nil then
1963 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
1964 FModel
.Color
:= FColor
1966 FModel
.Color
:= TEAMCOLOR
[FTeam
];
1967 FModel
.SetWeapon(FCurrWeap
);
1968 FModel
.SetFlag(FFlag
);
1969 SetDirection(FDirection
);
1972 procedure TPlayer
.SetColor(Color
: TRGB
);
1975 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
1976 if FModel
<> nil then FModel
.Color
:= Color
;
1979 function TPlayer
.GetColor(): TRGB
;
1981 result
:= FModel
.Color
;
1984 procedure TPlayer
.SwitchTeam
;
1986 if g_Game_IsClient
then
1988 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then Exit
;
1990 if gGameOn
and FAlive
then
1991 Kill(K_SIMPLEKILL
, FUID
, HIT_SELF
);
1993 if FTeam
= TEAM_RED
then
1995 ChangeTeam(TEAM_BLUE
);
1996 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_BLUE
], [FName
]), True);
1997 if g_Game_IsNet
then
1998 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM
, TEAM_BLUE
, FName
);
2002 ChangeTeam(TEAM_RED
);
2003 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_RED
], [FName
]), True);
2004 if g_Game_IsNet
then
2005 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM
, TEAM_RED
, FName
);
2007 FPreferredTeam
:= FTeam
;
2010 procedure TPlayer
.ChangeTeam(Team
: Byte);
2017 TEAM_RED
, TEAM_BLUE
:
2018 FModel
.Color
:= TEAMCOLOR
[Team
];
2020 FModel
.Color
:= FColor
;
2022 if (FTeam
<> OldTeam
) and g_Game_IsNet
and g_Game_IsServer
then
2023 MH_SEND_PlayerStats(FUID
);
2027 procedure TPlayer.CollideItem();
2032 if gItems = nil then Exit;
2033 if not FAlive then Exit;
2035 for i := 0 to High(gItems) do
2038 if (ItemType <> ITEM_NONE) and alive then
2039 if g_Obj_Collide(FObj.X+PLAYER_RECT.X, FObj.Y+PLAYER_RECT.Y, PLAYER_RECT.Width,
2040 PLAYER_RECT.Height, @Obj) then
2042 if not PickItem(ItemType, gItems[i].Respawnable, r) then Continue;
2044 if ItemType in [ITEM_SPHERE_BLUE, ITEM_SPHERE_WHITE, ITEM_INVUL] then
2045 g_Sound_PlayExAt('SOUND_ITEM_GETRULEZ', FObj.X, FObj.Y)
2046 else if ItemType in [ITEM_MEDKIT_SMALL, ITEM_MEDKIT_LARGE, ITEM_MEDKIT_BLACK] then
2047 g_Sound_PlayExAt('SOUND_ITEM_GETMED', FObj.X, FObj.Y)
2048 else g_Sound_PlayExAt('SOUND_ITEM_GETITEM', FObj.X, FObj.Y);
2050 // Íàäî óáðàòü ñ êàðòû, åñëè ýòî íå êëþ÷, êîòîðûì íóæíî ïîäåëèòñÿ ñ äðóãèì èãðîêîì:
2051 if r and not ((ItemType in [ITEM_KEY_RED, ITEM_KEY_GREEN, ITEM_KEY_BLUE]) and
2052 (gGameSettings.GameType = GT_SINGLE) and
2053 (g_Player_GetCount() > 1)) then
2054 if not Respawnable then g_Items_Remove(i) else g_Items_Pick(i);
2060 function TPlayer
.CollideLevel(XInc
, YInc
: Integer): Boolean;
2062 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
2063 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_WALL
,
2067 constructor TPlayer
.Create();
2073 mEDamageType
:= HIT_SOME
;
2079 FSawSound
:= TPlayableSound
.Create();
2080 FSawSoundIdle
:= TPlayableSound
.Create();
2081 FSawSoundHit
:= TPlayableSound
.Create();
2082 FSawSoundSelect
:= TPlayableSound
.Create();
2083 FFlameSoundOn
:= TPlayableSound
.Create();
2084 FFlameSoundOff
:= TPlayableSound
.Create();
2085 FFlameSoundWork
:= TPlayableSound
.Create();
2086 FJetSoundFly
:= TPlayableSound
.Create();
2087 FJetSoundOn
:= TPlayableSound
.Create();
2088 FJetSoundOff
:= TPlayableSound
.Create();
2090 FSawSound
.SetByName('SOUND_WEAPON_FIRESAW');
2091 FSawSoundIdle
.SetByName('SOUND_WEAPON_IDLESAW');
2092 FSawSoundHit
.SetByName('SOUND_WEAPON_HITSAW');
2093 FSawSoundSelect
.SetByName('SOUND_WEAPON_SELECTSAW');
2094 FFlameSoundOn
.SetByName('SOUND_WEAPON_FLAMEON');
2095 FFlameSoundOff
.SetByName('SOUND_WEAPON_FLAMEOFF');
2096 FFlameSoundWork
.SetByName('SOUND_WEAPON_FLAMEWORK');
2097 FJetSoundFly
.SetByName('SOUND_PLAYER_JETFLY');
2098 FJetSoundOn
.SetByName('SOUND_PLAYER_JETON');
2099 FJetSoundOff
.SetByName('SOUND_PLAYER_JETOFF');
2101 FSpectatePlayer
:= -1;
2105 FSavedStateNum
:= -1;
2113 FActualModelName
:= 'doomer';
2116 FObj
.Rect
:= PLAYER_RECT
;
2118 FBFGFireCounter
:= -1;
2119 FJustTeleported
:= False;
2122 FWaitForFirstSpawn
:= false;
2127 procedure TPlayer
.positionChanged (); inline;
2131 procedure TPlayer
.doDamage (v
: Integer);
2133 if (v
<= 0) then exit
;
2134 if (v
> 32767) then v
:= 32767;
2135 Damage(v
, 0, 0, 0, mEDamageType
);
2138 procedure TPlayer
.Damage(value
: Word; SpawnerUID
: Word; vx
, vy
: Integer; t
: Byte);
2142 if (not g_Game_IsClient
) and (not FAlive
) then
2147 // Íåóÿçâèìîñòü íå ñïàñàåò îò ëîâóøåê:
2148 if ((t
= HIT_TRAP
) or (t
= HIT_SELF
)) and (not FGodMode
) then
2150 if not g_Game_IsClient
then
2153 if t
= HIT_TRAP
then
2155 // Ëîâóøêà óáèâàåò ñðàçó:
2157 Kill(K_EXTRAHARDKILL
, SpawnerUID
, t
);
2159 if t
= HIT_SELF
then
2163 Kill(K_SIMPLEKILL
, SpawnerUID
, t
);
2166 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
2167 FMegaRulez
[MR_SUIT
] := 0;
2168 FMegaRulez
[MR_INVUL
] := 0;
2169 FMegaRulez
[MR_INVIS
] := 0;
2174 // Íî îò îñòàëüíîãî ñïàñàåò:
2175 if FMegaRulez
[MR_INVUL
] >= gTime
then
2182 // Åñëè åñòü óðîí ñâîèì, èëè ðàíèë ñàì ñåáÿ, èëè òåáÿ ðàíèë ïðîòèâíèê:
2183 if LongBool(gGameSettings
.Options
and GAME_OPTION_TEAMDAMAGE
) or
2184 (SpawnerUID
= FUID
) or
2185 (not SameTeam(FUID
, SpawnerUID
)) then
2187 FLastSpawnerUID
:= SpawnerUID
;
2189 // Êðîâü (ïóçûðüêè, åñëè â âîäå):
2190 if gBloodCount
> 0 then
2192 c
:= Min(value
, 200)*gBloodCount
+ Random(Min(value
, 200) div 2);
2193 if value
div 4 <= c
then
2194 c
:= c
- (value
div 4)
2198 if (t
= HIT_SOME
) and (vx
= 0) and (vy
= 0) then
2202 HIT_TRAP
, HIT_ACID
, HIT_FLAME
, HIT_SELF
: MakeBloodSimple(c
);
2203 HIT_BFG
, HIT_ROCKET
, HIT_SOME
: MakeBloodVector(c
, vx
, vy
);
2206 if t
= HIT_WATER
then
2207 g_GFX_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
2208 FObj
.Y
+PLAYER_RECT
.Y
-4, value
div 2, 8, 4);
2213 Inc(FDamageBuffer
, value
);
2217 FPain
:= FPain
+ value
;
2220 if g_Game_IsServer
and g_Game_IsNet
then
2222 MH_SEND_PlayerDamage(FUID
, t
, SpawnerUID
, value
, vx
, vy
);
2223 MH_SEND_PlayerStats(FUID
);
2224 MH_SEND_PlayerPos(False, FUID
);
2228 function TPlayer
.Heal(value
: Word; Soft
: Boolean): Boolean;
2231 if g_Game_IsClient
then
2236 if Soft
and (FHealth
< PLAYER_HP_SOFT
) then
2238 IncMax(FHealth
, value
, PLAYER_HP_SOFT
);
2241 if (not Soft
) and (FHealth
< PLAYER_HP_LIMIT
) then
2243 IncMax(FHealth
, value
, PLAYER_HP_LIMIT
);
2247 if Result
and g_Game_IsServer
and g_Game_IsNet
then
2248 MH_SEND_PlayerStats(FUID
);
2251 destructor TPlayer
.Destroy();
2253 if (gPlayer1
<> nil) and (gPlayer1
.FUID
= FUID
) then
2255 if (gPlayer2
<> nil) and (gPlayer2
.FUID
= FUID
) then
2259 FSawSoundIdle
.Free();
2260 FSawSoundHit
.Free();
2261 FSawSoundSelect
.Free();
2262 FFlameSoundOn
.Free();
2263 FFlameSoundOff
.Free();
2264 FFlameSoundWork
.Free();
2265 FJetSoundFly
.Free();
2267 FJetSoundOff
.Free();
2269 if FPunchAnim
<> nil then
2275 procedure TPlayer
.DrawIndicator(Color
: TRGB
);
2277 indX
, indY
, fX
, fY
, fSlope
: Integer;
2287 FObj
.lerp(gLerpFactor
, fX
, fY
);
2288 fSlope
:= nlerp(FSlopeOld
, FObj
.slopeUpLeft
, gLerpFactor
);
2290 case gPlayerIndicatorStyle
of
2293 if g_Texture_Get('TEXTURE_PLAYER_INDICATOR', ID
) then
2295 e_GetTextureSize(ID
, @indW
, @indH
);
2299 if (FObj
.X
+ FObj
.Rect
.X
) < 0 then
2302 indX
:= fX
+ FObj
.Rect
.X
+ FObj
.Rect
.Width
;
2303 indY
:= fY
+ FObj
.Rect
.Y
+ (FObj
.Rect
.Height
- indW
) div 2;
2306 else if (FObj
.X
+ FObj
.Rect
.X
+ FObj
.Rect
.Width
) > Max(gMapInfo
.Width
, gPlayerScreenSize
.X
) then
2309 indX
:= fX
+ FObj
.Rect
.X
- indH
;
2310 indY
:= fY
+ FObj
.Rect
.Y
+ (FObj
.Rect
.Height
- indW
) div 2;
2313 else if (FObj
.Y
- indH
) < 0 then
2316 indX
:= fX
+ FObj
.Rect
.X
+ (FObj
.Rect
.Width
- indW
) div 2;
2317 indY
:= fY
+ FObj
.Rect
.Y
+ FObj
.Rect
.Height
;
2323 indX
:= fX
+ FObj
.Rect
.X
+ (FObj
.Rect
.Width
- indW
) div 2;
2327 indY
:= indY
+ fSlope
;
2328 indX
:= EnsureRange(indX
, 0, Max(gMapInfo
.Width
, gPlayerScreenSize
.X
) - indW
);
2329 indY
:= EnsureRange(indY
, 0, Max(gMapInfo
.Height
, gPlayerScreenSize
.Y
) - indH
);
2333 e_DrawAdv(ID
, indX
, indY
, 0, True, False, indA
, @a
);
2340 e_TextureFontGetSize(gStdFont
, nW
, nH
);
2341 indX
:= fX
+ FObj
.Rect
.X
+ (FObj
.Rect
.Width
- Length(FName
) * nW
) div 2;
2342 indY
:= fY
- nH
+ fSlope
;
2343 e_TextureFontPrintEx(indX
, indY
, FName
, gStdFont
, Color
.R
, Color
.G
, Color
.B
, 1.0, True);
2349 procedure TPlayer
.DrawBubble();
2351 bubX
, bubY
, fX
, fY
: Integer;
2354 Rw
, Gw
, Bw
: SmallInt;
2358 CObj
:= getCameraObj();
2359 CObj
.lerp(gLerpFactor
, fX
, fY
);
2360 // NB: _F_Obj.Rect is used to keep the bubble higher; this is not a mistake
2361 bubX
:= fX
+FObj
.Rect
.X
+ IfThen(FDirection
= TDirection
.D_LEFT
, -4, 18);
2362 bubY
:= fY
+FObj
.Rect
.Y
- 18;
2370 1: // simple textual non-bubble
2372 bubX
:= fX
+FObj
.Rect
.X
- 11;
2373 bubY
:= fY
+FObj
.Rect
.Y
- 17;
2374 e_TextureFontPrint(bubX
, bubY
, '[...]', gStdFont
);
2377 2: // advanced pixel-perfect bubble
2379 if FTeam
= TEAM_RED
then
2382 if FTeam
= TEAM_BLUE
then
2385 3: // colored bubble
2387 Rb
:= FModel
.Color
.R
;
2388 Gb
:= FModel
.Color
.G
;
2389 Bb
:= FModel
.Color
.B
;
2390 Rw
:= Min(Rb
* 2 + 64, 255);
2391 Gw
:= Min(Gb
* 2 + 64, 255);
2392 Bw
:= Min(Bb
* 2 + 64, 255);
2393 if (Abs(Rw
- Rb
) < 32)
2394 or (Abs(Gw
- Gb
) < 32)
2395 or (Abs(Bw
- Bb
) < 32) then
2397 Rb
:= Max(Rw
div 2 - 16, 0);
2398 Gb
:= Max(Gw
div 2 - 16, 0);
2399 Bb
:= Max(Bw
div 2 - 16, 0);
2402 4: // custom textured bubble
2404 if g_Texture_Get('TEXTURE_PLAYER_TALKBUBBLE', ID
) then
2405 if FDirection
= TDirection
.D_RIGHT
then
2406 e_Draw(ID
, bubX
- 6, bubY
- 7, 0, True, False)
2408 e_Draw(ID
, bubX
- 6, bubY
- 7, 0, True, False, TMirrorType
.Horizontal
);
2414 e_DrawQuad(bubX
+ 1, bubY
, bubX
+ 18, bubY
+ 13, Rb
, Gb
, Bb
);
2415 e_DrawQuad(bubX
, bubY
+ 1, bubX
+ 19, bubY
+ 12, Rb
, Gb
, Bb
);
2417 e_DrawFillQuad(bubX
+ 1, bubY
+ 1, bubX
+ 18, bubY
+ 12, Rw
, Gw
, Bw
, 0);
2420 Dot
:= IfThen(FDirection
= TDirection
.D_LEFT
, 14, 5);
2421 e_DrawLine(1, bubX
+ Dot
, bubY
+ 14, bubX
+ Dot
, bubY
+ 16, Rb
, Gb
, Bb
);
2422 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
);
2423 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
);
2424 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
);
2425 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
);
2429 e_DrawFillQuad(bubX
+ Dot
, bubY
+ 8, bubX
+ Dot
+ 1, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2430 e_DrawFillQuad(bubX
+ Dot
+ 3, bubY
+ 8, bubX
+ Dot
+ 4, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2431 e_DrawFillQuad(bubX
+ Dot
+ 6, bubY
+ 8, bubX
+ Dot
+ 7, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2434 procedure TPlayer
.Draw();
2439 Mirror
: TMirrorType
;
2440 fX
, fY
, fSlope
: Integer;
2442 FObj
.lerp(gLerpFactor
, fX
, fY
);
2443 fSlope
:= nlerp(FSlopeOld
, FObj
.slopeUpLeft
, gLerpFactor
);
2447 if Direction
= TDirection
.D_RIGHT
then
2448 Mirror
:= TMirrorType
.None
2450 Mirror
:= TMirrorType
.Horizontal
;
2452 if FPunchAnim
<> nil then
2454 FPunchAnim
.Draw(fX
+IfThen(Direction
= TDirection
.D_LEFT
, 15-FObj
.Rect
.X
, FObj
.Rect
.X
-15),
2455 fY
+fSlope
+FObj
.Rect
.Y
-11, Mirror
);
2456 if FPunchAnim
.played
then
2463 if (FMegaRulez
[MR_INVUL
] > gTime
) and ((gPlayerDrawn
<> Self
) or (FSpawnInvul
>= gTime
)) then
2464 if g_Texture_Get('TEXTURE_PLAYER_INVULPENTA', ID
) then
2466 e_GetTextureSize(ID
, @w
, @h
);
2467 if FDirection
= TDirection
.D_LEFT
then
2468 e_Draw(ID
, fX
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2)-(w
div 2)+4,
2469 fY
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2)-(h
div 2)-7+fSlope
, 0, True, False)
2471 e_Draw(ID
, fX
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2)-(w
div 2)-2,
2472 fY
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2)-(h
div 2)-7+fSlope
, 0, True, False);
2475 if FMegaRulez
[MR_INVIS
] > gTime
then
2477 if (gPlayerDrawn
<> nil) and ((Self
= gPlayerDrawn
) or
2478 ((FTeam
= gPlayerDrawn
.Team
) and (gGameSettings
.GameMode
<> GM_DM
))) then
2480 if (FMegaRulez
[MR_INVIS
] - gTime
) <= 2100 then
2481 dr
:= not Odd((FMegaRulez
[MR_INVIS
] - gTime
) div 300)
2485 FModel
.Draw(fX
, fY
+fSlope
, 200)
2487 FModel
.Draw(fX
, fY
+fSlope
);
2490 FModel
.Draw(fX
, fY
+fSlope
, 254);
2493 FModel
.Draw(fX
, fY
+fSlope
);
2496 if g_debug_Frames
then
2498 e_DrawQuad(FObj
.X
+FObj
.Rect
.X
,
2500 FObj
.X
+FObj
.Rect
.X
+FObj
.Rect
.Width
-1,
2501 FObj
.Y
+FObj
.Rect
.Y
+FObj
.Rect
.Height
-1,
2505 if (gChatBubble
> 0) and (FKeys
[KEY_CHAT
].Pressed
) and not FGhost
then
2506 if (FMegaRulez
[MR_INVIS
] <= gTime
) or ((gPlayerDrawn
<> nil) and ((Self
= gPlayerDrawn
) or
2507 ((FTeam
= gPlayerDrawn
.Team
) and (gGameSettings
.GameMode
<> GM_DM
)))) then
2509 // e_DrawPoint(5, 335, 288, 255, 0, 0); // DL, UR, DL, UR
2510 if gAimLine
and alive
and
2511 ((Self
= gPlayer1
) or (Self
= gPlayer2
)) then
2516 procedure TPlayer
.DrawAim();
2517 procedure drawCast (sz
: Integer; ax0
, ay0
, ax1
, ay1
: Integer);
2522 {$IFDEF ENABLE_HOLMES}
2523 if isValidViewPort
and (self
= gPlayer1
) then
2525 g_Holmes_plrLaser(ax0
, ay0
, ax1
, ay1
);
2529 e_DrawLine(sz
, ax0
, ay0
, ax1
, ay1
, 255, 0, 0, 96);
2530 if (g_Map_traceToNearestWall(ax0
, ay0
, ax1
, ay1
, @ex
, @ey
) <> nil) then
2532 e_DrawLine(sz
, ax0
, ay0
, ex
, ey
, 0, 255, 0, 96);
2536 e_DrawLine(sz
, ax0
, ay0
, ex
, ey
, 0, 0, 255, 96);
2541 wx
, wy
, xx
, yy
: Integer;
2545 wx
:= FObj
.X
+ WEAPONPOINT
[FDirection
].X
+ IfThen(FDirection
= TDirection
.D_LEFT
, 7, -7);
2546 wy
:= FObj
.Y
+ WEAPONPOINT
[FDirection
].Y
;
2555 1: begin // Chainsaw
2562 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2563 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2564 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2565 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2570 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2571 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2572 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2573 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2575 4: begin // Double Shotgun
2578 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2579 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2580 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2581 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2583 5: begin // Chaingun
2586 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2587 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2588 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2589 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2591 6: begin // Rocket Launcher
2594 if angle
= ANGLE_RIGHTUP
then Inc(angle
, 2);
2595 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2596 if angle
= ANGLE_LEFTUP
then Dec(angle
, 2);
2597 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2599 7: begin // Plasmagun
2602 if angle
= ANGLE_RIGHTUP
then Inc(angle
);
2603 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 3);
2604 if angle
= ANGLE_LEFTUP
then Dec(angle
);
2605 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 3);
2610 if angle
= ANGLE_RIGHTUP
then Inc(angle
, 1);
2611 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 2);
2612 if angle
= ANGLE_LEFTUP
then Dec(angle
, 1);
2613 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 2);
2615 9: begin // Super Chaingun
2618 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2619 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2620 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2621 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2624 xx
:= Trunc(Cos(-DegToRad(angle
)) * len
) + wx
;
2625 yy
:= Trunc(Sin(-DegToRad(angle
)) * len
) + wy
;
2626 {$IF DEFINED(D2F_DEBUG)}
2627 drawCast(sz
, wx
, wy
, xx
, yy
);
2629 e_DrawLine(sz
, wx
, wy
, xx
, yy
, 255, 0, 0, 96);
2633 procedure TPlayer
.DrawGUI();
2636 X
, Y
, SY
, a
, p
, m
: Integer;
2640 stat
: TPlayerStatArray
;
2642 X
:= gPlayerScreenSize
.X
;
2643 SY
:= gPlayerScreenSize
.Y
;
2646 if gShowGoals
and (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
2648 if gGameSettings
.GameMode
= GM_CTF
then
2652 if gGameSettings
.GameMode
= GM_CTF
then
2654 s
:= 'TEXTURE_PLAYER_REDFLAG';
2655 if gFlags
[FLAG_RED
].State
= FLAG_STATE_CAPTURED
then
2656 s
:= 'TEXTURE_PLAYER_REDFLAG_S';
2657 if gFlags
[FLAG_RED
].State
= FLAG_STATE_DROPPED
then
2658 s
:= 'TEXTURE_PLAYER_REDFLAG_D';
2659 if g_Texture_Get(s
, ID
) then
2660 e_Draw(ID
, X
-16-32, 240-72-4, 0, True, False);
2663 s
:= IntToStr(gTeamStat
[TEAM_RED
].Goals
);
2664 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2665 e_CharFont_PrintEx(gMenuFont
, X
-16-a
-tw
, 240-72-4, s
, TEAMCOLOR
[TEAM_RED
]);
2667 if gGameSettings
.GameMode
= GM_CTF
then
2669 s
:= 'TEXTURE_PLAYER_BLUEFLAG';
2670 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_CAPTURED
then
2671 s
:= 'TEXTURE_PLAYER_BLUEFLAG_S';
2672 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_DROPPED
then
2673 s
:= 'TEXTURE_PLAYER_BLUEFLAG_D';
2674 if g_Texture_Get(s
, ID
) then
2675 e_Draw(ID
, X
-16-32, 240-32-4, 0, True, False);
2678 s
:= IntToStr(gTeamStat
[TEAM_BLUE
].Goals
);
2679 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2680 e_CharFont_PrintEx(gMenuFont
, X
-16-a
-tw
, 240-32-4, s
, TEAMCOLOR
[TEAM_BLUE
]);
2683 if g_Texture_Get('TEXTURE_PLAYER_HUDBG', ID
) then
2684 e_DrawFill(ID
, X
, 0, 1, (gPlayerScreenSize
.Y
div 256)+IfThen(gPlayerScreenSize
.Y
mod 256 > 0, 1, 0),
2687 if g_Texture_Get('TEXTURE_PLAYER_HUD', ID
) then
2688 e_Draw(ID
, X
+2, Y
, 0, True, False);
2690 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
2694 s
:= IntToStr(Frags
);
2695 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2696 e_CharFont_PrintEx(gMenuFont
, X
-16-tw
, Y
, s
, _RGB(255, 0, 0));
2701 stat
:= g_Player_GetStats();
2706 for a
:= 0 to High(stat
) do
2707 if stat
[a
].Name
<> Name
then
2709 if stat
[a
].Frags
> m
then m
:= stat
[a
].Frags
;
2710 if stat
[a
].Frags
> Frags
then p
:= p
+1;
2714 s
:= IntToStr(p
)+' / '+IntToStr(Length(stat
))+' ';
2715 if Frags
>= m
then s
:= s
+'+' else s
:= s
+'-';
2716 s
:= s
+IntToStr(Abs(Frags
-m
));
2718 e_CharFont_GetSize(gMenuSmallFont
, s
, tw
, th
);
2719 e_CharFont_PrintEx(gMenuSmallFont
, X
-16-tw
, Y
+32, s
, _RGB(255, 0, 0));
2722 if gLMSRespawn
> LMS_RESPAWN_NONE
then
2724 s
:= _lc
[I_GAME_WARMUP
];
2725 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2726 s
:= s
+ ': ' + IntToStr((gLMSRespawnTime
- gTime
) div 1000);
2727 e_CharFont_PrintEx(gMenuFont
, X
-64-tw
, SY
-32, s
, _RGB(0, 255, 0));
2729 else if gShowLives
and (gGameSettings
.MaxLives
> 0) then
2731 s
:= IntToStr(Lives
);
2732 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2733 e_CharFont_PrintEx(gMenuFont
, X
-16-tw
, SY
-32, s
, _RGB(0, 255, 0));
2737 e_CharFont_GetSize(gMenuSmallFont
, FName
, tw
, th
);
2738 e_CharFont_PrintEx(gMenuSmallFont
, X
+98-(tw
div 2), Y
+8, FName
, _RGB(255, 0, 0));
2740 if R_BERSERK
in FRulez
then
2741 e_Draw(gItemsTexturesID
[ITEM_MEDKIT_BLACK
], X
+37, Y
+45, 0, True, False)
2743 e_Draw(gItemsTexturesID
[ITEM_MEDKIT_LARGE
], X
+37, Y
+45, 0, True, False);
2745 if g_Texture_Get('TEXTURE_PLAYER_ARMORHUD', ID
) then
2746 e_Draw(ID
, X
+36, Y
+77, 0, True, False);
2748 s
:= IntToStr(IfThen(FHealth
> 0, FHealth
, 0));
2749 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2750 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+40, s
, _RGB(255, 0, 0));
2752 s
:= IntToStr(FArmor
);
2753 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2754 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+68, s
, _RGB(255, 0, 0));
2756 s
:= IntToStr(GetAmmoByWeapon(FCurrWeap
));
2762 ID
:= gItemsTexturesID
[ITEM_WEAPON_KASTET
];
2767 ID
:= gItemsTexturesID
[ITEM_WEAPON_SAW
];
2769 WEAPON_PISTOL
: ID
:= gItemsTexturesID
[ITEM_WEAPON_PISTOL
];
2770 WEAPON_CHAINGUN
: ID
:= gItemsTexturesID
[ITEM_WEAPON_CHAINGUN
];
2771 WEAPON_SHOTGUN1
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SHOTGUN1
];
2772 WEAPON_SHOTGUN2
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SHOTGUN2
];
2773 WEAPON_SUPERPULEMET
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SUPERPULEMET
];
2774 WEAPON_ROCKETLAUNCHER
: ID
:= gItemsTexturesID
[ITEM_WEAPON_ROCKETLAUNCHER
];
2775 WEAPON_PLASMA
: ID
:= gItemsTexturesID
[ITEM_WEAPON_PLASMA
];
2776 WEAPON_BFG
: ID
:= gItemsTexturesID
[ITEM_WEAPON_BFG
];
2777 WEAPON_FLAMETHROWER
: ID
:= gItemsTexturesID
[ITEM_WEAPON_FLAMETHROWER
];
2780 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2781 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+158, s
, _RGB(255, 0, 0));
2782 e_Draw(ID
, X
+20, Y
+160, 0, True, False);
2784 if R_KEY_RED
in FRulez
then
2785 e_Draw(gItemsTexturesID
[ITEM_KEY_RED
], X
+78, Y
+214, 0, True, False);
2787 if R_KEY_GREEN
in FRulez
then
2788 e_Draw(gItemsTexturesID
[ITEM_KEY_GREEN
], X
+95, Y
+214, 0, True, False);
2790 if R_KEY_BLUE
in FRulez
then
2791 e_Draw(gItemsTexturesID
[ITEM_KEY_BLUE
], X
+112, Y
+214, 0, True, False);
2793 if FJetFuel
> 0 then
2795 if g_Texture_Get('TEXTURE_PLAYER_HUDAIR', ID
) then
2796 e_Draw(ID
, X
+2, Y
+116, 0, True, False);
2797 if g_Texture_Get('TEXTURE_PLAYER_HUDJET', ID
) then
2798 e_Draw(ID
, X
+2, Y
+126, 0, True, False);
2799 e_DrawLine(4, X
+16, Y
+122, X
+16+Trunc(168*IfThen(FAir
> 0, FAir
, 0)/AIR_MAX
), Y
+122, 0, 0, 196);
2800 e_DrawLine(4, X
+16, Y
+132, X
+16+Trunc(168*FJetFuel
/JET_MAX
), Y
+132, 208, 0, 0);
2804 if g_Texture_Get('TEXTURE_PLAYER_HUDAIR', ID
) then
2805 e_Draw(ID
, X
+2, Y
+124, 0, True, False);
2806 e_DrawLine(4, X
+16, Y
+130, X
+16+Trunc(168*IfThen(FAir
> 0, FAir
, 0)/AIR_MAX
), Y
+130, 0, 0, 196);
2809 if gShowPing
and g_Game_IsClient
then
2811 s
:= _lc
[I_GAME_PING_HUD
] + IntToStr(NetPeer
.lastRoundTripTime
) + _lc
[I_NET_SLIST_PING_MS
];
2812 e_TextureFontPrint(X
+ 4, Y
+ 242, s
, gStdFont
);
2818 e_TextureFontPrint(X
+ 4, Y
+ 242, _lc
[I_PLAYER_SPECT
], gStdFont
);
2819 e_TextureFontPrint(X
+ 4, Y
+ 258, _lc
[I_PLAYER_SPECT2
], gStdFont
);
2820 e_TextureFontPrint(X
+ 4, Y
+ 274, _lc
[I_PLAYER_SPECT1
], gStdFont
);
2823 e_TextureFontGetSize(gStdFont
, cw
, ch
);
2824 s
:= _lc
[I_PLAYER_SPECT4
];
2825 e_TextureFontPrintEx(gScreenWidth
div 2 - cw
*(Length(s
) div 2),
2826 gScreenHeight
-4-ch
, s
, gStdFont
, 255, 255, 255, 1, True);
2827 e_TextureFontPrint(X
+ 4, Y
+ 290, _lc
[I_PLAYER_SPECT1S
], gStdFont
);
2833 procedure TPlayer
.DrawRulez();
2837 // Ïðè âçÿòèè íåóÿçâèìîñòè ðèñóåòñÿ èíâåðñèîííûé áåëûé ôîí
2838 if (FMegaRulez
[MR_INVUL
] >= gTime
) and (FSpawnInvul
< gTime
) then
2840 if (FMegaRulez
[MR_INVUL
]-gTime
) <= 2100 then
2841 dr
:= not Odd((FMegaRulez
[MR_INVUL
]-gTime
) div 300)
2846 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2847 191, 191, 191, 0, TBlending
.Invert
);
2850 // Ïðè âçÿòèè çàùèòíîãî êîñòþìà ðèñóåòñÿ çåëåíîâàòûé ôîí
2851 if FMegaRulez
[MR_SUIT
] >= gTime
then
2853 if (FMegaRulez
[MR_SUIT
]-gTime
) <= 2100 then
2854 dr
:= not Odd((FMegaRulez
[MR_SUIT
]-gTime
) div 300)
2859 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2860 0, 96, 0, 200, TBlending
.None
);
2863 // Ïðè âçÿòèè áåðñåðêà ðèñóåòñÿ êðàñíîâàòûé ôîí
2864 if (FBerserk
>= 0) and (LongWord(FBerserk
) >= gTime
) and (gFlash
= 2) then
2866 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2867 255, 0, 0, 200, TBlending
.None
);
2871 procedure TPlayer
.DrawPain();
2875 if FPain
= 0 then Exit
;
2879 if a
< 15 then h
:= 0
2880 else if a
< 35 then h
:= 1
2881 else if a
< 55 then h
:= 2
2882 else if a
< 75 then h
:= 3
2883 else if a
< 95 then h
:= 4
2886 //if a > 255 then a := 255;
2888 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1, 255, 0, 0, 255-h
*50);
2889 //e_DrawFillQuad(0, 0, gPlayerScreenSize.X-1, gPlayerScreenSize.Y-1, 255-min(128, a), 255-a, 255-a, 0, B_FILTER);
2892 procedure TPlayer
.DrawPickup();
2896 if FPickup
= 0 then Exit
;
2900 if a
< 15 then h
:= 1
2901 else if a
< 35 then h
:= 2
2902 else if a
< 55 then h
:= 3
2903 else if a
< 75 then h
:= 4
2906 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1, 150, 200, 150, 255-h
*50);
2909 procedure TPlayer
.DoPunch();
2914 if FPunchAnim
<> nil then begin
2919 st
:= 'FRAMES_PUNCH';
2920 if R_BERSERK
in FRulez
then
2921 st
:= st
+ '_BERSERK';
2922 if FKeys
[KEY_UP
].Pressed
then
2924 else if FKeys
[KEY_DOWN
].Pressed
then
2926 g_Frames_Get(id
, st
);
2927 FPunchAnim
:= TAnimation
.Create(id
, False, 1);
2930 procedure TPlayer
.Fire();
2932 f
, DidFire
: Boolean;
2933 wx
, wy
, xd
, yd
: Integer;
2936 if g_Game_IsClient
then Exit
;
2937 // FBFGFireCounter - âðåìÿ ïåðåä âûñòðåëîì (äëÿ BFG)
2938 // FReloading - âðåìÿ ïîñëå âûñòðåëà (äëÿ âñåãî)
2946 if FReloading
[FCurrWeap
] <> 0 then Exit
;
2951 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
2952 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
2953 xd
:= wx
+IfThen(FDirection
= TDirection
.D_LEFT
, -30, 30);
2954 yd
:= wy
+firediry();
2960 if R_BERSERK
in FRulez
then
2962 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
2963 locobj
.X
:= FObj
.X
+FObj
.Rect
.X
;
2964 locobj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
2967 locobj
.rect
.Width
:= 39;
2968 locobj
.rect
.Height
:= 52;
2969 locobj
.Vel
.X
:= (xd
-wx
) div 2;
2970 locobj
.Vel
.Y
:= (yd
-wy
) div 2;
2971 locobj
.Accel
.X
:= xd
-wx
;
2972 locobj
.Accel
.y
:= yd
-wy
;
2974 if g_Weapon_Hit(@locobj
, 50, FUID
, HIT_SOME
) <> 0 then
2975 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
2977 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
2979 if (gFlash
= 1) and (FPain
< 50) then FPain
:= min(FPain
+ 25, 50);
2983 g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
2987 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2992 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
2993 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
2995 FSawSoundSelect
.Stop();
2997 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
2999 else if not FSawSoundHit
.IsPlaying() then
3001 FSawSoundSelect
.Stop();
3002 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
3005 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3011 if FAmmo
[A_BULLETS
] > 0 then
3013 g_Weapon_pistol(wx
, wy
, xd
, yd
, FUID
);
3014 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3015 Dec(FAmmo
[A_BULLETS
]);
3016 FFireAngle
:= FAngle
;
3019 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
3020 GameVelX
, GameVelY
-2, SHELL_BULLET
);
3024 if FAmmo
[A_SHELLS
] > 0 then
3026 g_Weapon_shotgun(wx
, wy
, xd
, yd
, FUID
);
3027 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', wx
, wy
);
3028 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3029 Dec(FAmmo
[A_SHELLS
]);
3030 FFireAngle
:= FAngle
;
3034 FShellType
:= SHELL_SHELL
;
3038 if FAmmo
[A_SHELLS
] >= 2 then
3040 g_Weapon_dshotgun(wx
, wy
, xd
, yd
, FUID
);
3041 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3042 Dec(FAmmo
[A_SHELLS
], 2);
3043 FFireAngle
:= FAngle
;
3047 FShellType
:= SHELL_DBLSHELL
;
3051 if FAmmo
[A_BULLETS
] > 0 then
3053 g_Weapon_mgun(wx
, wy
, xd
, yd
, FUID
);
3054 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', wx
, wy
);
3055 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3056 Dec(FAmmo
[A_BULLETS
]);
3057 FFireAngle
:= FAngle
;
3060 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
3061 GameVelX
, GameVelY
-2, SHELL_BULLET
);
3064 WEAPON_ROCKETLAUNCHER
:
3065 if FAmmo
[A_ROCKETS
] > 0 then
3067 g_Weapon_rocket(wx
, wy
, xd
, yd
, FUID
);
3068 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3069 Dec(FAmmo
[A_ROCKETS
]);
3070 FFireAngle
:= FAngle
;
3076 if FAmmo
[A_CELLS
] > 0 then
3078 g_Weapon_plasma(wx
, wy
, xd
, yd
, FUID
);
3079 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3080 Dec(FAmmo
[A_CELLS
]);
3081 FFireAngle
:= FAngle
;
3087 if (FAmmo
[A_CELLS
] >= 40) and (FBFGFireCounter
= -1) then
3089 FBFGFireCounter
:= 17;
3090 if not FNoReload
then
3091 g_Sound_PlayExAt('SOUND_WEAPON_STARTFIREBFG', FObj
.X
, FObj
.Y
);
3092 Dec(FAmmo
[A_CELLS
], 40);
3096 WEAPON_SUPERPULEMET
:
3097 if FAmmo
[A_SHELLS
] > 0 then
3099 g_Weapon_shotgun(wx
, wy
, xd
, yd
, FUID
);
3100 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', wx
, wy
);
3101 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3102 Dec(FAmmo
[A_SHELLS
]);
3103 FFireAngle
:= FAngle
;
3106 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
3107 GameVelX
, GameVelY
-2, SHELL_SHELL
);
3110 WEAPON_FLAMETHROWER
:
3111 if FAmmo
[A_FUEL
] > 0 then
3113 g_Weapon_flame(wx
, wy
, xd
, yd
, FUID
);
3115 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3117 FFireAngle
:= FAngle
;
3124 if g_Game_IsNet
and g_Game_IsServer
then MH_SEND_PlayerStats(FUID
);
3128 if g_Game_IsNet
then
3132 if FCurrWeap
<> WEAPON_BFG
then
3133 MH_SEND_PlayerFire(FUID
, FCurrWeap
, wx
, wy
, xd
, yd
, LastShotID
)
3135 if not FNoReload
then
3136 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_WEAPON_STARTFIREBFG');
3139 MH_SEND_PlayerStats(FUID
);
3144 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
3145 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
3146 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
3149 function TPlayer
.GetAmmoByWeapon(Weapon
: Byte): Word;
3152 WEAPON_PISTOL
, WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
];
3153 WEAPON_SHOTGUN1
, WEAPON_SHOTGUN2
, WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
];
3154 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
];
3155 WEAPON_PLASMA
, WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
];
3156 WEAPON_FLAMETHROWER
: Result
:= FAmmo
[A_FUEL
];
3161 function TPlayer
.HeadInLiquid(XInc
, YInc
: Integer): Boolean;
3163 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
+XInc
, FObj
.Y
+PLAYER_HEADRECT
.Y
+YInc
,
3164 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
3165 PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, True);
3168 procedure TPlayer
.FlamerOn
;
3170 FFlameSoundOff
.Stop();
3171 FFlameSoundOff
.SetPosition(0);
3174 if (not FFlameSoundOn
.IsPlaying()) and (not FFlameSoundWork
.IsPlaying()) then
3175 FFlameSoundWork
.PlayAt(FObj
.X
, FObj
.Y
);
3179 FFlameSoundOn
.PlayAt(FObj
.X
, FObj
.Y
);
3184 procedure TPlayer
.FlamerOff
;
3188 FFlameSoundOn
.Stop();
3189 FFlameSoundOn
.SetPosition(0);
3190 FFlameSoundWork
.Stop();
3191 FFlameSoundWork
.SetPosition(0);
3192 FFlameSoundOff
.PlayAt(FObj
.X
, FObj
.Y
);
3197 procedure TPlayer
.JetpackOn
;
3201 FJetSoundOn
.SetPosition(0);
3202 FJetSoundOn
.PlayAt(FObj
.X
, FObj
.Y
);
3206 procedure TPlayer
.JetpackOff
;
3210 FJetSoundOff
.SetPosition(0);
3211 FJetSoundOff
.PlayAt(FObj
.X
, FObj
.Y
);
3214 procedure TPlayer
.CatchFire(Attacker
: Word; Timeout
: Integer = PLAYER_BURN_TIME
);
3216 if Timeout
<= 0 then
3218 if (FMegaRulez
[MR_SUIT
] > gTime
) or (FMegaRulez
[MR_INVUL
] > gTime
) then
3219 exit
; // Íå çàãîðàåìñÿ êîãäà åñòü çàùèòà
3220 if g_Obj_CollidePanel(@FObj
, 0, 0, PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
) then
3221 exit
; // Íå ïîäãîðàåì â âîäå íà âñÿêèé ñëó÷àé
3222 if FFireTime
<= 0 then
3223 g_Sound_PlayExAt('SOUND_IGNITE', FObj
.X
, FObj
.Y
);
3224 FFireTime
:= Timeout
;
3225 FFireAttacker
:= Attacker
;
3226 if g_Game_IsNet
and g_Game_IsServer
then
3227 MH_SEND_PlayerStats(FUID
);
3230 procedure TPlayer
.Jump();
3232 if gFly
or FJetpack
then
3234 // Ïîëåò (÷èò-êîä èëè äæåòïàê):
3235 if FObj
.Vel
.Y
> -VEL_FLY
then
3236 FObj
.Vel
.Y
:= FObj
.Vel
.Y
- 3;
3239 if FJetFuel
> 0 then
3241 if (FJetFuel
< 1) and g_Game_IsServer
then
3245 if g_Game_IsNet
then
3246 MH_SEND_PlayerStats(FUID
);
3252 // Íå âêëþ÷àòü äæåòïàê â ðåæèìå ïðîõîæäåíèÿ ñêâîçü ñòåíû
3254 FCanJetpack
:= False;
3256 // Ïðûãàåì èëè âñïëûâàåì:
3257 if (CollideLevel(0, 1) or
3258 g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
+36, PLAYER_RECT
.Width
,
3259 PLAYER_RECT
.Height
-33, PANEL_STEP
, False)
3260 ) and (FObj
.Accel
.Y
= 0) then // Íå ïðûãàòü, åñëè åñòü âåðòèêàëüíîå óñêîðåíèå
3262 FObj
.Vel
.Y
:= -VEL_JUMP
;
3263 FCanJetpack
:= False;
3267 if BodyInLiquid(0, 0) then
3268 FObj
.Vel
.Y
:= -VEL_SW
3269 else if (FJetFuel
> 0) and FCanJetpack
and
3270 g_Game_IsServer
and (not g_Obj_CollideLiquid(@FObj
, 0, 0)) then
3274 if g_Game_IsNet
then
3275 MH_SEND_PlayerStats(FUID
);
3280 procedure TPlayer
.Kill(KillType
: Byte; SpawnerUID
: Word; t
: Byte);
3282 a
, i
, k
, ab
, ar
: Byte;
3286 srv
, netsrv
: Boolean;
3292 procedure PushItem(t
: Byte);
3296 id
:= g_Items_Create(FObj
.X
, FObj
.Y
, t
, True, False);
3297 it
:= g_Items_ByIdx(id
);
3298 if KillType
= K_EXTRAHARDKILL
then // -7..+7; -8..0
3300 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-7+Random(15),
3301 (FObj
.Vel
.Y
div 2)-Random(9));
3302 it
.positionChanged(); // this updates spatial accelerators
3306 if KillType
= K_HARDKILL
then // -5..+5; -5..0
3308 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-5+Random(11),
3309 (FObj
.Vel
.Y
div 2)-Random(6));
3311 else // -3..+3; -3..0
3313 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-3+Random(7),
3314 (FObj
.Vel
.Y
div 2)-Random(4));
3316 it
.positionChanged(); // this updates spatial accelerators
3319 if g_Game_IsNet
and g_Game_IsServer
then
3320 MH_SEND_ItemSpawn(True, id
);
3324 DoFrags
:= (gGameSettings
.MaxLives
= 0) or (gGameSettings
.GameMode
= GM_COOP
);
3325 Srv
:= g_Game_IsServer
;
3326 Netsrv
:= g_Game_IsServer
and g_Game_IsNet
;
3327 if Srv
then FDeath
:= FDeath
+ 1;
3332 if not FPhysics
then
3338 if (gGameSettings
.MaxLives
> 0) and Srv
and (gLMSRespawn
= LMS_RESPAWN_NONE
) then
3340 if FLives
> 0 then FLives
:= FLives
- 1;
3341 if FLives
= 0 then FNoRespawn
:= True;
3344 // Íîìåð òèïà ñìåðòè:
3347 K_SIMPLEKILL
: a
:= 1;
3349 K_EXTRAHARDKILL
: a
:= 3;
3354 if not FModel
.PlaySound(MODELSOUND_DIE
, a
, FObj
.X
, FObj
.Y
) then
3356 if FModel
.PlaySound(MODELSOUND_DIE
, i
, FObj
.X
, FObj
.Y
) then
3363 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN1
;
3365 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN2
;
3366 K_EXTRAHARDKILL
, K_FALLKILL
:
3367 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN3
;
3370 // Ïåðåêëþ÷àåì ñîñòîÿíèå:
3374 K_HARDKILL
, K_EXTRAHARDKILL
:
3378 // Ðåàêöèÿ ìîíñòðîâ íà ñìåðòü èãðîêà:
3379 if (KillType
<> K_FALLKILL
) and (Srv
) then
3380 g_Monsters_killedp();
3382 if SpawnerUID
= FUID
then
3384 if Srv
and (DoFrags
or (gGameSettings
.GameMode
= GM_TDM
)) then
3389 g_Console_Add(Format(_lc
[I_PLAYER_KILL_SELF
], [FName
]), True);
3392 if g_GetUIDType(SpawnerUID
) = UID_PLAYER
then
3393 begin // Óáèò äðóãèì èãðîêîì
3394 KP
:= g_Player_Get(SpawnerUID
);
3395 if (KP
<> nil) and Srv
then
3397 if (DoFrags
or (gGameSettings
.GameMode
= GM_TDM
)) then
3398 if SameTeam(FUID
, SpawnerUID
) then
3408 if (gGameSettings
.GameMode
= GM_TDM
) and DoFrags
then
3409 Inc(gTeamStat
[KP
.Team
].Goals
,
3410 IfThen(SameTeam(FUID
, SpawnerUID
), -1, 1));
3412 if netsrv
then MH_SEND_PlayerStats(SpawnerUID
);
3415 plr
:= g_Player_Get(SpawnerUID
);
3423 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_2
],
3427 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_1
],
3431 g_Console_Add(Format(_lc
[I_PLAYER_KILL
],
3436 else if g_GetUIDType(SpawnerUID
) = UID_MONSTER
then
3437 begin // Óáèò ìîíñòðîì
3438 mon
:= g_Monsters_ByUID(SpawnerUID
);
3442 s
:= g_Mons_GetKilledByTypeId(mon
.MonsterType
);
3446 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_2
],
3450 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_1
],
3454 g_Console_Add(Format(_lc
[I_PLAYER_KILL
],
3459 else // Îñîáûå òèïû ñìåðòè
3462 HIT_SELF
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_SELF
], [FName
]), True);
3463 HIT_FALL
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_FALL
], [FName
]), True);
3464 HIT_WATER
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_WATER
], [FName
]), True);
3465 HIT_ACID
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_ACID
], [FName
]), True);
3466 HIT_TRAP
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_TRAP
], [FName
]), True);
3467 else g_Console_Add(Format(_lc
[I_PLAYER_DIED
], [FName
]), True);
3473 for a
:= WP_FIRST
to WP_LAST
do
3477 WEAPON_SAW
: i
:= ITEM_WEAPON_SAW
;
3478 WEAPON_SHOTGUN1
: i
:= ITEM_WEAPON_SHOTGUN1
;
3479 WEAPON_SHOTGUN2
: i
:= ITEM_WEAPON_SHOTGUN2
;
3480 WEAPON_CHAINGUN
: i
:= ITEM_WEAPON_CHAINGUN
;
3481 WEAPON_ROCKETLAUNCHER
: i
:= ITEM_WEAPON_ROCKETLAUNCHER
;
3482 WEAPON_PLASMA
: i
:= ITEM_WEAPON_PLASMA
;
3483 WEAPON_BFG
: i
:= ITEM_WEAPON_BFG
;
3484 WEAPON_SUPERPULEMET
: i
:= ITEM_WEAPON_SUPERPULEMET
;
3485 WEAPON_FLAMETHROWER
: i
:= ITEM_WEAPON_FLAMETHROWER
;
3494 if R_ITEM_BACKPACK
in FRulez
then
3495 PushItem(ITEM_AMMO_BACKPACK
);
3497 // Âûáðîñ ðàêåòíîãî ðàíöà:
3498 if FJetFuel
> 0 then
3499 PushItem(ITEM_JETPACK
);
3502 if (not (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
])) or
3503 (not LongBool(gGameSettings
.Options
and GAME_OPTION_DMKEYS
)) then
3505 if R_KEY_RED
in FRulez
then
3506 PushItem(ITEM_KEY_RED
);
3508 if R_KEY_GREEN
in FRulez
then
3509 PushItem(ITEM_KEY_GREEN
);
3511 if R_KEY_BLUE
in FRulez
then
3512 PushItem(ITEM_KEY_BLUE
);
3516 DropFlag(KillType
= K_FALLKILL
);
3519 FCorpse
:= g_Player_CreateCorpse(Self
);
3521 if Srv
and (gGameSettings
.MaxLives
> 0) and FNoRespawn
and
3522 (gLMSRespawn
= LMS_RESPAWN_NONE
) then
3528 for i
:= Low(gPlayers
) to High(gPlayers
) do
3530 if gPlayers
[i
] = nil then continue
;
3531 if (not gPlayers
[i
].FNoRespawn
) and (not gPlayers
[i
].FSpectator
) then
3534 if gPlayers
[i
].FTeam
= TEAM_RED
then Inc(ar
)
3535 else if gPlayers
[i
].FTeam
= TEAM_BLUE
then Inc(ab
);
3540 OldLR
:= gLMSRespawn
;
3541 if (gGameSettings
.GameMode
= GM_COOP
) then
3545 // everyone is dead, restart the map
3546 g_Game_Message(_lc
[I_MESSAGE_LMS_LOSE
], 144);
3548 MH_SEND_GameEvent(NET_EV_LMS_LOSE
);
3549 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3550 gLMSRespawnTime
:= gTime
+ 5000;
3552 else if (a
= 1) then
3554 if (gPlayers
[k
] <> nil) and not (gPlayers
[k
] is TBot
) then
3555 if (gPlayers
[k
] = gPlayer1
) or
3556 (gPlayers
[k
] = gPlayer2
) then
3557 g_Console_Add('*** ' + _lc
[I_MESSAGE_LMS_SURVIVOR
] + ' ***', True)
3558 else if Netsrv
and (gPlayers
[k
].FClientID
>= 0) then
3559 MH_SEND_GameEvent(NET_EV_LMS_SURVIVOR
, 0, 'N', gPlayers
[k
].FClientID
);
3562 else if (gGameSettings
.GameMode
= GM_TDM
) then
3564 if (ab
= 0) and (ar
<> 0) then
3567 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 144);
3569 MH_SEND_GameEvent(NET_EV_TLMS_WIN
, TEAM_RED
);
3570 Inc(gTeamStat
[TEAM_RED
].Goals
);
3571 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3572 gLMSRespawnTime
:= gTime
+ 5000;
3574 else if (ar
= 0) and (ab
<> 0) then
3577 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 144);
3579 MH_SEND_GameEvent(NET_EV_TLMS_WIN
, TEAM_BLUE
);
3580 Inc(gTeamStat
[TEAM_BLUE
].Goals
);
3581 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3582 gLMSRespawnTime
:= gTime
+ 5000;
3584 else if (ar
= 0) and (ab
= 0) then
3587 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
3589 MH_SEND_GameEvent(NET_EV_LMS_DRAW
, 0, FName
);
3590 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3591 gLMSRespawnTime
:= gTime
+ 5000;
3594 else if (gGameSettings
.GameMode
= GM_DM
) then
3598 if gPlayers
[k
] <> nil then
3601 // survivor is the winner
3602 g_Game_Message(Format(_lc
[I_MESSAGE_LMS_WIN
], [AnsiUpperCase(FName
)]), 144);
3604 MH_SEND_GameEvent(NET_EV_LMS_WIN
, 0, FName
);
3607 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3608 gLMSRespawnTime
:= gTime
+ 5000;
3610 else if (a
= 0) then
3612 // everyone is dead, restart the map
3613 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
3615 MH_SEND_GameEvent(NET_EV_LMS_DRAW
, 0, FName
);
3616 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3617 gLMSRespawnTime
:= gTime
+ 5000;
3620 if srv
and (OldLR
= LMS_RESPAWN_NONE
) and (gLMSRespawn
> LMS_RESPAWN_NONE
) then
3622 if NetMode
= NET_SERVER
then
3623 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, gLMSRespawnTime
- gTime
)
3625 g_Console_Add(Format(_lc
[I_MSG_WARMUP_START
], [(gLMSRespawnTime
- gTime
) div 1000]), True);
3631 MH_SEND_PlayerStats(FUID
);
3632 MH_SEND_PlayerDeath(FUID
, KillType
, t
, SpawnerUID
);
3633 if gGameSettings
.GameMode
= GM_TDM
then MH_SEND_GameStats
;
3636 if srv
and FNoRespawn
then Spectate(True);
3637 FWantsInGame
:= True;
3640 function TPlayer
.BodyInLiquid(XInc
, YInc
: Integer): Boolean;
3642 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
, PLAYER_RECT
.Width
,
3643 PLAYER_RECT
.Height
-20, PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, False);
3646 function TPlayer
.BodyInAcid(XInc
, YInc
: Integer): Boolean;
3648 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
, PLAYER_RECT
.Width
,
3649 PLAYER_RECT
.Height
-20, PANEL_ACID1
or PANEL_ACID2
, False);
3652 procedure TPlayer
.MakeBloodSimple(Count
: Word);
3654 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)+8,
3655 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3656 Count
div 2, 3, -1, 16, (PLAYER_RECT
.Height
*2 div 3),
3657 FModel
.Blood
.R
, FModel
.Blood
.G
, FModel
.Blood
.B
, FModel
.Blood
.Kind
);
3658 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-8,
3659 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3660 Count
div 2, -3, -1, 16, (PLAYER_RECT
.Height
*2) div 3,
3661 FModel
.Blood
.R
, FModel
.Blood
.G
, FModel
.Blood
.B
, FModel
.Blood
.Kind
);
3664 procedure TPlayer
.MakeBloodVector(Count
: Word; VelX
, VelY
: Integer);
3666 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
3667 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3668 Count
, VelX
, VelY
, 16, (PLAYER_RECT
.Height
*2) div 3,
3669 FModel
.Blood
.R
, FModel
.Blood
.G
, FModel
.Blood
.B
, FModel
.Blood
.Kind
);
3672 procedure TPlayer
.ProcessWeaponAction(Action
: Byte);
3674 if g_Game_IsClient
then Exit
;
3676 WP_PREV
: PrevWeapon();
3677 WP_NEXT
: NextWeapon();
3681 procedure TPlayer
.QueueWeaponSwitch(Weapon
: Byte);
3683 if g_Game_IsClient
then Exit
;
3684 if Weapon
> High(FWeapon
) then Exit
;
3685 FNextWeap
:= FNextWeap
or (1 shl Weapon
);
3688 procedure TPlayer
.resetWeaponQueue ();
3691 FNextWeapDelay
:= 0;
3694 function TPlayer
.hasAmmoForWeapon (weapon
: Byte): Boolean;
3698 WEAPON_KASTET
, WEAPON_SAW
: result
:= true;
3699 WEAPON_SHOTGUN1
, WEAPON_SHOTGUN2
, WEAPON_SUPERPULEMET
: result
:= (FAmmo
[A_SHELLS
] > 0);
3700 WEAPON_PISTOL
, WEAPON_CHAINGUN
: result
:= (FAmmo
[A_BULLETS
] > 0);
3701 WEAPON_ROCKETLAUNCHER
: result
:= (FAmmo
[A_ROCKETS
] > 0);
3702 WEAPON_PLASMA
, WEAPON_BFG
: result
:= (FAmmo
[A_CELLS
] > 0);
3703 WEAPON_FLAMETHROWER
: result
:= (FAmmo
[A_FUEL
] > 0);
3704 else result
:= (weapon
< length(FWeapon
));
3708 // return 255 for "no switch"
3709 function TPlayer
.getNextWeaponIndex (): Byte;
3712 wantThisWeapon
: array[0..64] of Boolean;
3713 wwc
: Integer = 0; //HACK!
3716 result
:= 255; // default result: "no switch"
3717 // had weapon cycling on previous frame? remove that flag
3718 if (FNextWeap
and $2000) <> 0 then
3720 FNextWeap
:= FNextWeap
and $1FFF;
3721 FNextWeapDelay
:= 0;
3723 // cycling has priority
3724 if (FNextWeap
and $C000) <> 0 then
3726 if (FNextWeap
and $8000) <> 0 then
3730 FNextWeap
:= FNextWeap
or $2000; // we need this
3731 if FNextWeapDelay
> 0 then
3732 exit
; // cooldown time
3734 for i
:= 0 to High(FWeapon
) do
3736 cwi
:= (cwi
+length(FWeapon
)+dir
) mod length(FWeapon
);
3737 if FWeapon
[cwi
] then
3739 //e_WriteLog(Format(' SWITCH: cur=%d; new=%d', [FCurrWeap, cwi]), MSG_WARNING);
3740 result
:= Byte(cwi
);
3741 FNextWeapDelay
:= WEAPON_DELAY
;
3749 for i
:= 0 to High(wantThisWeapon
) do
3750 wantThisWeapon
[i
] := false;
3751 for i
:= 0 to High(FWeapon
) do
3752 if (FNextWeap
and (1 shl i
)) <> 0 then
3754 wantThisWeapon
[i
] := true;
3757 // exclude currently selected weapon from the set
3758 wantThisWeapon
[FCurrWeap
] := false;
3759 // slow down alterations a little
3762 //e_WriteLog(Format(' FNextWeap=%x; delay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
3763 // more than one weapon requested, assume "alteration" and check alteration delay
3764 if FNextWeapDelay
> 0 then
3770 // do not reset weapon queue, it will be done in `RealizeCurrentWeapon()`
3771 // but clear all counters if no weapon should be switched
3777 //e_WriteLog(Format('wwc=%d', [wwc]), MSG_WARNING);
3778 // try weapons in descending order
3779 for i
:= High(FWeapon
) downto 0 do
3781 if wantThisWeapon
[i
] and FWeapon
[i
] and ((wwc
= 1) or hasAmmoForWeapon(i
)) then
3786 FNextWeapDelay
:= WEAPON_DELAY
* 2; // anyway, 'cause why not
3790 // no suitable weapon found, so reset the queue, to avoid accidental "queuing" of weapon w/o ammo
3794 procedure TPlayer
.RealizeCurrentWeapon();
3795 function switchAllowed (): Boolean;
3800 if FBFGFireCounter
<> -1 then
3802 if FTime
[T_SWITCH
] > gTime
then
3804 for i
:= WP_FIRST
to WP_LAST
do
3805 if FReloading
[i
] > 0 then
3813 //e_WriteLog(Format('***RealizeCurrentWeapon: FNextWeap=%x; FNextWeapDelay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
3814 //FNextWeap := FNextWeap and $1FFF;
3815 if FNextWeapDelay
> 0 then Dec(FNextWeapDelay
); // "alteration delay"
3817 if not switchAllowed
then
3819 //HACK for weapon cycling
3820 if (FNextWeap
and $E000) <> 0 then FNextWeap
:= 0;
3824 nw
:= getNextWeaponIndex();
3825 if nw
= 255 then exit
; // don't reset anything here
3826 if nw
> High(FWeapon
) then
3828 // don't forget to reset queue here!
3829 //e_WriteLog(' RealizeCurrentWeapon: WUTAFUUUU', MSG_WARNING);
3837 FTime
[T_SWITCH
] := gTime
+156;
3838 if FCurrWeap
= WEAPON_SAW
then FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3839 FModel
.SetWeapon(FCurrWeap
);
3840 if g_Game_IsNet
then MH_SEND_PlayerStats(FUID
);
3844 procedure TPlayer
.NextWeapon();
3846 if g_Game_IsClient
then Exit
;
3850 procedure TPlayer
.PrevWeapon();
3852 if g_Game_IsClient
then Exit
;
3856 procedure TPlayer
.SetWeapon(W
: Byte);
3858 if FCurrWeap
<> W
then
3859 if W
= WEAPON_SAW
then
3860 FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3863 FModel
.SetWeapon(CurrWeap
);
3867 function TPlayer
.PickItem(ItemType
: Byte; arespawn
: Boolean; var remove
: Boolean): Boolean;
3869 function allowBerserkSwitching (): Boolean;
3871 if (FBFGFireCounter
<> -1) then begin result
:= false; exit
; end;
3873 if gBerserkAutoswitch
then exit
;
3874 if not conIsCheatsEnabled
then exit
;
3883 if g_Game_IsClient
then Exit
;
3885 // a = true - ìåñòî ñïàâíà ïðåäìåòà:
3886 a
:= LongBool(gGameSettings
.Options
and GAME_OPTION_WEAPONSTAY
) and arespawn
;
3891 if (FHealth
< PLAYER_HP_SOFT
) or (FFireTime
> 0) then
3893 if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
3897 if gFlash
= 2 then Inc(FPickup
, 5);
3901 if (FHealth
< PLAYER_HP_SOFT
) or (FFireTime
> 0) then
3903 if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
3907 if gFlash
= 2 then Inc(FPickup
, 5);
3911 if FArmor
< PLAYER_AP_SOFT
then
3913 FArmor
:= PLAYER_AP_SOFT
;
3916 if gFlash
= 2 then Inc(FPickup
, 5);
3920 if FArmor
< PLAYER_AP_LIMIT
then
3922 FArmor
:= PLAYER_AP_LIMIT
;
3925 if gFlash
= 2 then Inc(FPickup
, 5);
3929 if (FHealth
< PLAYER_HP_LIMIT
) or (FFireTime
> 0) then
3931 if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
3935 if gFlash
= 2 then Inc(FPickup
, 5);
3939 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) or (FFireTime
> 0) then
3941 if FHealth
< PLAYER_HP_LIMIT
then
3942 FHealth
:= PLAYER_HP_LIMIT
;
3943 if FArmor
< PLAYER_AP_LIMIT
then
3944 FArmor
:= PLAYER_AP_LIMIT
;
3948 if gFlash
= 2 then Inc(FPickup
, 5);
3952 if (not FWeapon
[WEAPON_SAW
]) or ((not arespawn
) and (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
])) then
3954 if ( (gWeaponAutoswitch
= True) and ((g_Game_IsNet
= False or (NetMode
= NET_SERVER
)) and ((Self
= gPlayer1
) or (Self
= gPlayer2
)))) then
3956 hadWeapon
:= FWeapon
[WEAPON_SAW
];
3957 FWeapon
[WEAPON_SAW
] := True;
3958 if (hadWeapon
= False) then
3960 FCurrWeap
:= WEAPON_SAW
;
3962 FModel
.SetWeapon(WEAPON_SAW
);
3965 else FWeapon
[WEAPON_SAW
] := 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_SHOTGUN1
:
3972 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN1
] then
3974 // Íóæíî, ÷òîáû íå âçÿòü âñå ïóëè ñðàçó:
3975 if a
and FWeapon
[WEAPON_SHOTGUN1
] then Exit
;
3976 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3977 if ( (gWeaponAutoswitch
= True) and ((g_Game_IsNet
= False or (NetMode
= NET_SERVER
)) and ((Self
= gPlayer1
) or (Self
= gPlayer2
)))) then
3979 hadWeapon
:= FWeapon
[WEAPON_SHOTGUN1
];
3980 FWeapon
[WEAPON_SHOTGUN1
] := True;
3981 if (hadWeapon
= False) then
3983 FCurrWeap
:= WEAPON_SHOTGUN1
;
3985 FModel
.SetWeapon(WEAPON_SHOTGUN1
);
3988 else FWeapon
[WEAPON_SHOTGUN1
] := True;
3990 if gFlash
= 2 then Inc(FPickup
, 5);
3991 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3994 ITEM_WEAPON_SHOTGUN2
:
3995 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN2
] then
3997 if a
and FWeapon
[WEAPON_SHOTGUN2
] then Exit
;
3998 if ( (gWeaponAutoswitch
= True) and ((g_Game_IsNet
= False or (NetMode
= NET_SERVER
)) and ((Self
= gPlayer1
) or (Self
= gPlayer2
)))) then
4000 hadWeapon
:= FWeapon
[WEAPON_SHOTGUN2
];
4001 FWeapon
[WEAPON_SHOTGUN2
] := True;
4002 if (hadWeapon
= False) then
4004 FCurrWeap
:= WEAPON_SHOTGUN2
;
4006 FModel
.SetWeapon(WEAPON_SHOTGUN2
);
4009 else FWeapon
[WEAPON_SHOTGUN2
] := True;
4010 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4012 if gFlash
= 2 then Inc(FPickup
, 5);
4013 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4016 ITEM_WEAPON_CHAINGUN
:
4017 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or not FWeapon
[WEAPON_CHAINGUN
] then
4019 if a
and FWeapon
[WEAPON_CHAINGUN
] then Exit
;
4020 if ( (gWeaponAutoswitch
= True) and ((g_Game_IsNet
= False or (NetMode
= NET_SERVER
)) and ((Self
= gPlayer1
) or (Self
= gPlayer2
)))) then
4022 hadWeapon
:= FWeapon
[WEAPON_CHAINGUN
];
4023 FWeapon
[WEAPON_CHAINGUN
] := True;
4024 if (hadWeapon
= False) then
4026 FCurrWeap
:= WEAPON_CHAINGUN
;
4028 FModel
.SetWeapon(WEAPON_CHAINGUN
);
4031 else FWeapon
[WEAPON_CHAINGUN
] := True;
4032 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
4034 if gFlash
= 2 then Inc(FPickup
, 5);
4035 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4038 ITEM_WEAPON_ROCKETLAUNCHER
:
4039 if (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or not FWeapon
[WEAPON_ROCKETLAUNCHER
] then
4041 if a
and FWeapon
[WEAPON_ROCKETLAUNCHER
] then Exit
;
4042 if ( (gWeaponAutoswitch
= True) and ((g_Game_IsNet
= False or (NetMode
= NET_SERVER
)) and ((Self
= gPlayer1
) or (Self
= gPlayer2
)))) then
4044 hadWeapon
:= FWeapon
[WEAPON_ROCKETLAUNCHER
];
4045 FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
4046 if (hadWeapon
= False) then
4048 FCurrWeap
:= WEAPON_ROCKETLAUNCHER
;
4050 FModel
.SetWeapon(WEAPON_ROCKETLAUNCHER
);
4053 else FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
4054 IncMax(FAmmo
[A_ROCKETS
], 2, FMaxAmmo
[A_ROCKETS
]);
4056 if gFlash
= 2 then Inc(FPickup
, 5);
4057 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4061 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_PLASMA
] then
4063 if a
and FWeapon
[WEAPON_PLASMA
] then Exit
;
4064 if ( (gWeaponAutoswitch
= True) and ((g_Game_IsNet
= False or (NetMode
= NET_SERVER
)) and ((Self
= gPlayer1
) or (Self
= gPlayer2
)))) then
4066 hadWeapon
:= FWeapon
[WEAPON_PLASMA
];
4067 FWeapon
[WEAPON_PLASMA
] := True;
4068 if (hadWeapon
= False) then
4070 FCurrWeap
:= WEAPON_PLASMA
;
4072 FModel
.SetWeapon(WEAPON_PLASMA
);
4075 else FWeapon
[WEAPON_PLASMA
] := True;
4076 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
4078 if gFlash
= 2 then Inc(FPickup
, 5);
4079 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4083 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_BFG
] then
4085 if a
and FWeapon
[WEAPON_BFG
] then Exit
;
4086 if ( (gWeaponAutoswitch
= True) and ((g_Game_IsNet
= False or (NetMode
= NET_SERVER
)) and ((Self
= gPlayer1
) or (Self
= gPlayer2
)))) then
4088 hadWeapon
:= FWeapon
[WEAPON_BFG
];
4089 FWeapon
[WEAPON_BFG
] := True;
4090 if (hadWeapon
= False) then
4092 FCurrWeap
:= WEAPON_BFG
;
4094 FModel
.SetWeapon(WEAPON_BFG
);
4097 else FWeapon
[WEAPON_BFG
] := True;
4098 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
4100 if gFlash
= 2 then Inc(FPickup
, 5);
4101 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4104 ITEM_WEAPON_SUPERPULEMET
:
4105 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SUPERPULEMET
] then
4107 if a
and FWeapon
[WEAPON_SUPERPULEMET
] then Exit
;
4108 if ( (gWeaponAutoswitch
= True) and ((g_Game_IsNet
= False or (NetMode
= NET_SERVER
)) and ((Self
= gPlayer1
) or (Self
= gPlayer2
)))) then
4110 hadWeapon
:= FWeapon
[WEAPON_SUPERPULEMET
];
4111 FWeapon
[WEAPON_SUPERPULEMET
] := True;
4112 if (hadWeapon
= False) then
4114 FCurrWeap
:= WEAPON_SUPERPULEMET
;
4116 FModel
.SetWeapon(WEAPON_SUPERPULEMET
);
4119 else FWeapon
[WEAPON_SUPERPULEMET
] := True;
4120 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4122 if gFlash
= 2 then Inc(FPickup
, 5);
4123 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4126 ITEM_WEAPON_FLAMETHROWER
:
4127 if (FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
]) or not FWeapon
[WEAPON_FLAMETHROWER
] then
4129 if a
and FWeapon
[WEAPON_FLAMETHROWER
] then Exit
;
4130 if ( (gWeaponAutoswitch
= True) and ((g_Game_IsNet
= False or (NetMode
= NET_SERVER
)) and ((Self
= gPlayer1
) or (Self
= gPlayer2
)))) then
4132 hadWeapon
:= FWeapon
[WEAPON_FLAMETHROWER
];
4133 FWeapon
[WEAPON_FLAMETHROWER
] := True;
4134 if (hadWeapon
= False) then
4136 FCurrWeap
:= WEAPON_FLAMETHROWER
;
4138 FModel
.SetWeapon(WEAPON_FLAMETHROWER
);
4141 else FWeapon
[WEAPON_FLAMETHROWER
] := True;
4142 IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
4144 if gFlash
= 2 then Inc(FPickup
, 5);
4145 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4149 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
4151 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
4154 if gFlash
= 2 then Inc(FPickup
, 5);
4157 ITEM_AMMO_BULLETS_BOX
:
4158 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
4160 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
4163 if gFlash
= 2 then Inc(FPickup
, 5);
4167 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
4169 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4172 if gFlash
= 2 then Inc(FPickup
, 5);
4175 ITEM_AMMO_SHELLS_BOX
:
4176 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
4178 IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
4181 if gFlash
= 2 then Inc(FPickup
, 5);
4185 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
4187 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
4190 if gFlash
= 2 then Inc(FPickup
, 5);
4193 ITEM_AMMO_ROCKET_BOX
:
4194 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
4196 IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
4199 if gFlash
= 2 then Inc(FPickup
, 5);
4203 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
4205 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
4208 if gFlash
= 2 then Inc(FPickup
, 5);
4212 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
4214 IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
4217 if gFlash
= 2 then Inc(FPickup
, 5);
4221 if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then
4223 IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
4226 if gFlash
= 2 then Inc(FPickup
, 5);
4230 if not(R_ITEM_BACKPACK
in FRulez
) or
4231 (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
4232 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
4233 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
4234 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or
4235 (FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
]) then
4237 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[1, A_BULLETS
];
4238 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[1, A_SHELLS
];
4239 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[1, A_ROCKETS
];
4240 FMaxAmmo
[A_CELLS
] := AmmoLimits
[1, A_CELLS
];
4241 FMaxAmmo
[A_FUEL
] := AmmoLimits
[1, A_FUEL
];
4243 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
4244 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
4245 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
4246 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4247 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
4248 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
4249 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
4250 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
4251 if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then
4252 IncMax(FAmmo
[A_FUEL
], 50, FMaxAmmo
[A_FUEL
]);
4254 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
4257 if gFlash
= 2 then Inc(FPickup
, 5);
4261 if not(R_KEY_RED
in FRulez
) then
4263 Include(FRulez
, R_KEY_RED
);
4265 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
4266 if gFlash
= 2 then Inc(FPickup
, 5);
4267 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
4271 if not(R_KEY_GREEN
in FRulez
) then
4273 Include(FRulez
, R_KEY_GREEN
);
4275 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
4276 if gFlash
= 2 then Inc(FPickup
, 5);
4277 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
4281 if not(R_KEY_BLUE
in FRulez
) then
4283 Include(FRulez
, R_KEY_BLUE
);
4285 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
4286 if gFlash
= 2 then Inc(FPickup
, 5);
4287 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
4291 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
4293 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
4297 if gFlash
= 2 then Inc(FPickup
, 5);
4301 if FAir
< AIR_MAX
then
4306 if gFlash
= 2 then Inc(FPickup
, 5);
4311 if not (R_BERSERK
in FRulez
) then
4313 Include(FRulez
, R_BERSERK
);
4314 if allowBerserkSwitching
then
4316 FCurrWeap
:= WEAPON_KASTET
;
4318 FModel
.SetWeapon(WEAPON_KASTET
);
4323 if gFlash
= 2 then Inc(FPickup
, 5);
4325 FBerserk
:= gTime
+30000;
4330 if (FHealth
< PLAYER_HP_SOFT
) or (FFireTime
> 0) then
4332 if FHealth
< PLAYER_HP_SOFT
then FHealth
:= PLAYER_HP_SOFT
;
4333 FBerserk
:= gTime
+30000;
4341 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
4343 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
4347 if gFlash
= 2 then Inc(FPickup
, 5);
4351 if (FHealth
< PLAYER_HP_LIMIT
) or (FFireTime
> 0) then
4353 if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
4357 if gFlash
= 2 then Inc(FPickup
, 5);
4361 if FArmor
< PLAYER_AP_LIMIT
then
4363 IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
4366 if gFlash
= 2 then Inc(FPickup
, 5);
4370 if FJetFuel
< JET_MAX
then
4372 FJetFuel
:= JET_MAX
;
4375 if gFlash
= 2 then Inc(FPickup
, 5);
4379 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
4381 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
4384 if gFlash
= 2 then Inc(FPickup
, 5);
4389 procedure TPlayer
.Touch();
4393 //FModel.PlaySound(MODELSOUND_PAIN, 1, FObj.X, FObj.Y);
4396 // Áðîñèòü ôëàã òîâàðèùó:
4397 if gGameSettings
.GameMode
= GM_CTF
then
4402 procedure TPlayer
.Push(vx
, vy
: Integer);
4404 if (not FPhysics
) and FGhost
then
4406 FObj
.Accel
.X
:= FObj
.Accel
.X
+ vx
;
4407 FObj
.Accel
.Y
:= FObj
.Accel
.Y
+ vy
;
4408 if g_Game_IsNet
and g_Game_IsServer
then
4409 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
4412 procedure TPlayer
.Reset(Force
: Boolean);
4418 FTime
[T_RESPAWN
] := 0;
4419 FTime
[T_FLAGCAP
] := 0;
4435 FSpectator
:= False;
4438 FSpectatePlayer
:= -1;
4439 FNoRespawn
:= False;
4441 FLives
:= gGameSettings
.MaxLives
;
4446 procedure TPlayer
.SoftReset();
4454 FBFGFireCounter
:= -1;
4462 SetAction(A_STAND
, True);
4465 function TPlayer
.GetRespawnPoint(): Byte;
4470 // Íà áóäóùåå: FSpawn - èãðîê óæå èãðàë è ïåðåðîæäàåòñÿ
4472 // Îäèíî÷íàÿ èãðà/êîîïåðàòèâ
4473 if gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
] then
4475 if Self
= gPlayer1
then
4477 // player 1 should try to spawn on the player 1 point
4478 if g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) > 0 then
4479 Exit(RESPAWNPOINT_PLAYER1
)
4480 else if g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) > 0 then
4481 Exit(RESPAWNPOINT_PLAYER2
);
4483 else if Self
= gPlayer2
then
4485 // player 2 should try to spawn on the player 2 point
4486 if g_Map_GetPointCount(RESPAWNPOINT_PLAYER2
) > 0 then
4487 Exit(RESPAWNPOINT_PLAYER2
)
4488 else if g_Map_GetPointCount(RESPAWNPOINT_PLAYER1
) > 0 then
4489 Exit(RESPAWNPOINT_PLAYER1
);
4493 // other players randomly pick either the first or the second point
4494 c
:= IfThen((Random(2) = 0), RESPAWNPOINT_PLAYER1
, RESPAWNPOINT_PLAYER2
);
4495 if g_Map_GetPointCount(c
) > 0 then
4497 // try the other one
4498 c
:= IfThen((c
= RESPAWNPOINT_PLAYER1
), RESPAWNPOINT_PLAYER2
, RESPAWNPOINT_PLAYER1
);
4499 if g_Map_GetPointCount(c
) > 0 then
4505 if gGameSettings
.GameMode
= GM_DM
then
4507 // try DM points first
4508 if g_Map_GetPointCount(RESPAWNPOINT_DM
) > 0 then
4509 Exit(RESPAWNPOINT_DM
);
4513 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
4515 // try team points first
4516 c
:= RESPAWNPOINT_DM
;
4517 if FTeam
= TEAM_RED
then
4518 c
:= RESPAWNPOINT_RED
4519 else if FTeam
= TEAM_BLUE
then
4520 c
:= RESPAWNPOINT_BLUE
;
4521 if g_Map_GetPointCount(c
) > 0 then
4525 // still haven't found a spawnpoint, try random shit
4526 Result
:= g_Map_GetRandomPointType();
4529 procedure TPlayer
.Respawn(Silent
: Boolean; Force
: Boolean = False);
4531 RespawnPoint
: TRespawnPoint
;
4539 FBFGFireCounter
:= -1;
4546 if not g_Game_IsServer
then
4550 FWantsInGame
:= True;
4551 FJustTeleported
:= True;
4554 FTime
[T_RESPAWN
] := 0;
4558 // if server changes MaxLives we gotta be ready
4559 if gGameSettings
.MaxLives
= 0 then FNoRespawn
:= False;
4561 // Åùå íåëüçÿ âîçðîäèòüñÿ:
4562 if FTime
[T_RESPAWN
] > gTime
then
4565 // Ïðîñðàë âñå æèçíè:
4568 if not FSpectator
then Spectate(True);
4569 FWantsInGame
:= True;
4573 if (gGameSettings
.GameType
<> GT_SINGLE
) and (gGameSettings
.GameMode
<> GM_COOP
) then
4574 begin // "Ñâîÿ èãðà"
4575 // Áåðñåðê íå ñîõðàíÿåòñÿ ìåæäó óðîâíÿìè:
4576 FRulez
:= FRulez
-[R_BERSERK
];
4578 else // "Îäèíî÷íàÿ èãðà"/"Êîîï"
4580 // Áåðñåðê è êëþ÷è íå ñîõðàíÿþòñÿ ìåæäó óðîâíÿìè:
4581 FRulez
:= FRulez
-[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
, R_BERSERK
];
4584 // Ïîëó÷àåì òî÷êó ñïàóíà èãðîêà:
4585 c
:= GetRespawnPoint();
4590 // Âîñêðåøåíèå áåç îðóæèÿ:
4593 FHealth
:= Round(PLAYER_HP_SOFT
* (FHandicap
/ 100));
4599 for a
:= WP_FIRST
to WP_LAST
do
4601 FWeapon
[a
] := False;
4605 FWeapon
[WEAPON_PISTOL
] := True;
4606 FWeapon
[WEAPON_KASTET
] := True;
4607 FCurrWeap
:= WEAPON_PISTOL
;
4610 FModel
.SetWeapon(FCurrWeap
);
4612 for b
:= A_BULLETS
to A_HIGH
do
4615 FAmmo
[A_BULLETS
] := 50;
4617 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[0, A_BULLETS
];
4618 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[0, A_SHELLS
];
4619 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[0, A_SHELLS
];
4620 FMaxAmmo
[A_CELLS
] := AmmoLimits
[0, A_CELLS
];
4621 FMaxAmmo
[A_FUEL
] := AmmoLimits
[0, A_FUEL
];
4623 if (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
]) and
4624 LongBool(gGameSettings
.Options
and GAME_OPTION_DMKEYS
) then
4625 FRulez
:= [R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
]
4630 // Ïîëó÷àåì êîîðäèíàòû òî÷êè âîçðîæäåíèÿ:
4631 if not g_Map_GetPoint(c
, RespawnPoint
) then
4633 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
4637 // Óñòàíîâêà êîîðäèíàò è ñáðîñ âñåõ ïàðàìåòðîâ:
4638 FObj
.X
:= RespawnPoint
.X
-PLAYER_RECT
.X
;
4639 FObj
.Y
:= RespawnPoint
.Y
-PLAYER_RECT
.Y
;
4640 FObj
.oldX
:= FObj
.X
; // don't interpolate after respawn
4641 FObj
.oldY
:= FObj
.Y
;
4647 FDirection
:= RespawnPoint
.Direction
;
4648 if FDirection
= TDirection
.D_LEFT
then
4653 SetAction(A_STAND
, True);
4654 FModel
.Direction
:= FDirection
;
4656 for a
:= Low(FTime
) to High(FTime
) do
4659 for a
:= Low(FMegaRulez
) to High(FMegaRulez
) do
4662 // Respawn invulnerability
4663 if (gGameSettings
.GameType
<> GT_SINGLE
) and (gGameSettings
.SpawnInvul
> 0) then
4665 FMegaRulez
[MR_INVUL
] := gTime
+ gGameSettings
.SpawnInvul
* 1000;
4666 FSpawnInvul
:= FMegaRulez
[MR_INVUL
];
4671 FCanJetpack
:= False;
4677 // Àíèìàöèÿ âîçðîæäåíèÿ:
4678 if (not gLoadGameMode
) and (not Silent
) then
4679 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
4681 Anim
:= TAnimation
.Create(ID
, False, 3);
4682 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4683 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4687 FSpectator
:= False;
4690 FSpectatePlayer
:= -1;
4693 if (gPlayer1
= nil) and (gSpectLatchPID1
= FUID
) then
4695 if (gPlayer2
= nil) and (gSpectLatchPID2
= FUID
) then
4698 if g_Game_IsNet
then
4700 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
4701 MH_SEND_PlayerStats(FUID
, NET_EVERYONE
);
4703 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4704 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32,
4709 procedure TPlayer
.Spectate(NoMove
: Boolean = False);
4712 Kill(K_EXTRAHARDKILL
, FUID
, HIT_SOME
)
4713 else if (not NoMove
) then
4715 GameX
:= gMapInfo
.Width
div 2;
4716 GameY
:= gMapInfo
.Height
div 2;
4725 FWantsInGame
:= False;
4731 if Self
= gPlayer1
then
4733 gSpectLatchPID1
:= FUID
;
4736 else if Self
= gPlayer2
then
4738 gSpectLatchPID2
:= FUID
;
4743 if g_Game_IsNet
then
4744 MH_SEND_PlayerStats(FUID
);
4747 procedure TPlayer
.SwitchNoClip
;
4751 FGhost
:= not FGhost
;
4752 FPhysics
:= not FGhost
;
4764 procedure TPlayer
.Run(Direction
: TDirection
);
4768 if MAX_RUNVEL
> 8 then
4772 if Direction
= TDirection
.D_LEFT
then
4774 if FObj
.Vel
.X
> -MAX_RUNVEL
then
4775 FObj
.Vel
.X
:= FObj
.Vel
.X
- (MAX_RUNVEL
shr 3);
4778 if FObj
.Vel
.X
< MAX_RUNVEL
then
4779 FObj
.Vel
.X
:= FObj
.Vel
.X
+ (MAX_RUNVEL
shr 3);
4781 // Âîçìîæíî, ïèíàåì êóñêè:
4782 if (FObj
.Vel
.X
<> 0) and (gGibs
<> nil) then
4784 b
:= Abs(FObj
.Vel
.X
);
4785 if b
> 1 then b
:= b
* (Random(8 div b
) + 1);
4786 for a
:= 0 to High(gGibs
) do
4788 if gGibs
[a
].alive
and
4789 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
+FObj
.Rect
.Height
-4,
4790 FObj
.Rect
.Width
, 8, @gGibs
[a
].Obj
) and (Random(3) = 0) then
4793 if FObj
.Vel
.X
< 0 then
4795 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)+120) // íàëåâî
4799 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)); // íàïðàâî
4801 gGibs
[a
].positionChanged(); // this updates spatial accelerators
4809 procedure TPlayer
.SeeDown();
4811 SetAction(A_SEEDOWN
);
4813 if FDirection
= TDirection
.D_LEFT
then FAngle
:= ANGLE_LEFTDOWN
else FAngle
:= ANGLE_RIGHTDOWN
;
4815 if FIncCam
> -120 then DecMin(FIncCam
, 5, -120);
4818 procedure TPlayer
.SeeUp();
4822 if FDirection
= TDirection
.D_LEFT
then FAngle
:= ANGLE_LEFTUP
else FAngle
:= ANGLE_RIGHTUP
;
4824 if FIncCam
< 120 then IncMax(FIncCam
, 5, 120);
4827 procedure TPlayer
.SetAction(Action
: Byte; Force
: Boolean = False);
4835 A_ATTACK
: Prior
:= 2;
4836 A_SEEUP
: Prior
:= 1;
4837 A_SEEDOWN
: Prior
:= 1;
4838 A_ATTACKUP
: Prior
:= 2;
4839 A_ATTACKDOWN
: Prior
:= 2;
4844 if (Prior
> FActionPrior
) or Force
then
4845 if not ((Prior
= 2) and (FCurrWeap
= WEAPON_SAW
)) then
4847 FActionPrior
:= Prior
;
4848 FActionAnim
:= Action
;
4849 FActionForce
:= Force
;
4850 FActionChanged
:= True;
4853 if Action
in [A_ATTACK
, A_ATTACKUP
, A_ATTACKDOWN
] then FModel
.SetFire(True);
4856 function TPlayer
.StayOnStep(XInc
, YInc
: Integer): Boolean;
4858 Result
:= not g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
-1,
4859 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False)
4860 and g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
,
4861 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False);
4864 function TPlayer
.TeleportTo(X
, Y
: Integer; silent
: Boolean; dir
: Byte): Boolean;
4871 if g_CollideLevel(X
, Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
) then
4873 g_Sound_PlayExAt('SOUND_GAME_NOTELEPORT', FObj
.X
, FObj
.Y
);
4874 if g_Game_IsServer
and g_Game_IsNet
then
4875 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_GAME_NOTELEPORT');
4879 FJustTeleported
:= True;
4884 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
4886 Anim
:= TAnimation
.Create(ID
, False, 3);
4889 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', FObj
.X
, FObj
.Y
);
4890 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4891 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4892 if g_Game_IsServer
and g_Game_IsNet
then
4893 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4894 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 1,
4898 FObj
.X
:= X
-PLAYER_RECT
.X
;
4899 FObj
.Y
:= Y
-PLAYER_RECT
.Y
;
4900 FObj
.oldX
:= FObj
.X
; // don't interpolate after respawn
4901 FObj
.oldY
:= FObj
.Y
;
4902 if FAlive
and FGhost
then
4908 if not g_Game_IsNet
then
4912 SetDirection(TDirection
.D_LEFT
);
4918 SetDirection(TDirection
.D_RIGHT
);
4924 if FDirection
= TDirection
.D_RIGHT
then
4926 SetDirection(TDirection
.D_LEFT
);
4931 SetDirection(TDirection
.D_RIGHT
);
4937 if not silent
and (Anim
<> nil) then
4939 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4940 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4943 if g_Game_IsServer
and g_Game_IsNet
then
4944 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4945 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 0,
4952 function nonz(a
: Single): Single;
4960 function TPlayer
.refreshCorpse(): Boolean;
4966 if FAlive
or FSpectator
then
4968 if (gCorpses
= nil) or (Length(gCorpses
) = 0) then
4970 for i
:= 0 to High(gCorpses
) do
4971 if gCorpses
[i
] <> nil then
4972 if gCorpses
[i
].FPlayerUID
= FUID
then
4980 function TPlayer
.getCameraObj(): TObj
;
4982 if (not FAlive
) and (not FSpectator
) and
4983 (FCorpse
>= 0) and (FCorpse
< Length(gCorpses
)) and
4984 (gCorpses
[FCorpse
] <> nil) and (gCorpses
[FCorpse
].FPlayerUID
= FUID
) then
4986 gCorpses
[FCorpse
].FObj
.slopeUpLeft
:= FObj
.slopeUpLeft
;
4987 Result
:= gCorpses
[FCorpse
].FObj
;
4995 procedure TPlayer
.PreUpdate();
4997 FSlopeOld
:= FObj
.slopeUpLeft
;
4998 FIncCamOld
:= FIncCam
;
4999 FObj
.oldX
:= FObj
.X
;
5000 FObj
.oldY
:= FObj
.Y
;
5003 procedure TPlayer
.Update();
5006 i
, ii
, wx
, wy
, xd
, yd
, k
: Integer;
5007 blockmon
, headwater
, dospawn
: Boolean;
5012 NetServer
:= g_Game_IsNet
and g_Game_IsServer
;
5013 AnyServer
:= g_Game_IsServer
;
5015 if g_Game_IsClient
and (NetInterpLevel
> 0) then
5016 DoLerp(NetInterpLevel
+ 1)
5022 if (FClientID
>= 0) and (NetClients
[FClientID
].Peer
<> nil) then
5024 FPing
:= NetClients
[FClientID
].Peer
^.lastRoundTripTime
;
5025 if NetClients
[FClientID
].Peer
^.packetsSent
> 0 then
5026 FLoss
:= Round(100*NetClients
[FClientID
].Peer
^.packetsLost
/NetClients
[FClientID
].Peer
^.packetsSent
)
5035 if FAlive
and (FPunchAnim
<> nil) then
5036 FPunchAnim
.Update();
5038 if FAlive
and (gFly
or FJetpack
) then
5041 if FDirection
= TDirection
.D_LEFT
then
5046 if FAlive
and (not FGhost
) then
5048 if FKeys
[KEY_UP
].Pressed
then
5050 if FKeys
[KEY_DOWN
].Pressed
then
5054 if (not (FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_DOWN
].Pressed
)) and
5057 i
:= g_basic
.Sign(FIncCam
);
5058 FIncCam
:= Abs(FIncCam
);
5059 DecMin(FIncCam
, 5, 0);
5060 FIncCam
:= FIncCam
*i
;
5063 if gTime
mod (GAME_TICK
*2) <> 0 then
5065 if (FObj
.Vel
.X
= 0) and FAlive
then
5067 if FKeys
[KEY_LEFT
].Pressed
then
5068 Run(TDirection
.D_LEFT
);
5069 if FKeys
[KEY_RIGHT
].Pressed
then
5070 Run(TDirection
.D_RIGHT
);
5075 g_Obj_Move(@FObj
, True, True, True);
5076 positionChanged(); // this updates spatial accelerators
5082 FActionChanged
:= False;
5086 // Let alive player do some actions
5087 if FKeys
[KEY_LEFT
].Pressed
then Run(TDirection
.D_LEFT
);
5088 if FKeys
[KEY_RIGHT
].Pressed
then Run(TDirection
.D_RIGHT
);
5089 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then Fire()
5095 if NetServer
then MH_SEND_PlayerStats(FUID
);
5098 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Use();
5099 if FKeys
[KEY_JUMP
].Pressed
then Jump()
5102 if AnyServer
and FJetpack
then
5106 if NetServer
then MH_SEND_PlayerStats(FUID
);
5108 FCanJetpack
:= True;
5115 for k
:= Low(FKeys
) to KEY_CHAT
-1 do
5117 if FKeys
[k
].Pressed
then
5125 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
5128 if (FTime
[T_RESPAWN
] <= gTime
) and
5129 gGameOn
and (not FAlive
) then
5131 if (g_Player_GetCount() > 1) then
5135 gExit
:= EXIT_RESTART
;
5140 // Dead spectator actions
5143 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Fire();
5144 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then
5148 if (FSpectatePlayer
>= High(gPlayers
)) then
5149 FSpectatePlayer
:= -1
5153 for I
:= FSpectatePlayer
+ 1 to High(gPlayers
) do
5154 if gPlayers
[I
] <> nil then
5155 if gPlayers
[I
].alive
then
5156 if gPlayers
[I
].UID
<> FUID
then
5158 FSpectatePlayer
:= I
;
5163 if not SetSpect
then FSpectatePlayer
:= -1;
5174 if FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_JUMP
].Pressed
then
5176 FYTo
:= FObj
.Y
- 32;
5177 FSpectatePlayer
:= -1;
5179 if FKeys
[KEY_DOWN
].Pressed
then
5181 FYTo
:= FObj
.Y
+ 32;
5182 FSpectatePlayer
:= -1;
5184 if FKeys
[KEY_LEFT
].Pressed
then
5186 FXTo
:= FObj
.X
- 32;
5187 FSpectatePlayer
:= -1;
5189 if FKeys
[KEY_RIGHT
].Pressed
then
5191 FXTo
:= FObj
.X
+ 32;
5192 FSpectatePlayer
:= -1;
5195 if (FXTo
< -64) then
5197 else if (FXTo
> gMapInfo
.Width
+ 32) then
5198 FXTo
:= gMapInfo
.Width
+ 32;
5199 if (FYTo
< -72) then
5201 else if (FYTo
> gMapInfo
.Height
+ 32) then
5202 FYTo
:= gMapInfo
.Height
+ 32;
5207 g_Obj_Move(@FObj
, True, True, True);
5208 positionChanged(); // this updates spatial accelerators
5215 if (FSpectatePlayer
<= High(gPlayers
)) and (FSpectatePlayer
>= 0) then
5216 if gPlayers
[FSpectatePlayer
] <> nil then
5217 if gPlayers
[FSpectatePlayer
].alive
then
5219 FXTo
:= gPlayers
[FSpectatePlayer
].GameX
;
5220 FYTo
:= gPlayers
[FSpectatePlayer
].GameY
;
5224 blockmon
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
, FObj
.Y
+PLAYER_HEADRECT
.Y
,
5225 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
5226 PANEL_BLOCKMON
, True);
5227 headwater
:= HeadInLiquid(0, 0);
5229 // Ñîïðîòèâëåíèå âîçäóõà:
5230 if (not FAlive
) or not (FKeys
[KEY_LEFT
].Pressed
or FKeys
[KEY_RIGHT
].Pressed
) then
5231 if FObj
.Vel
.X
<> 0 then
5232 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
5234 if (FLastHit
= HIT_TRAP
) and (FPain
> 90) then FPain
:= 90;
5235 DecMin(FPain
, 5, 0);
5236 DecMin(FPickup
, 1, 0);
5238 if FAlive
and (FObj
.Y
> Integer(gMapInfo
.Height
)+128) and AnyServer
then
5240 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
5241 FMegaRulez
[MR_SUIT
] := 0;
5242 FMegaRulez
[MR_INVUL
] := 0;
5243 FMegaRulez
[MR_INVIS
] := 0;
5244 Kill(K_FALLKILL
, 0, HIT_FALL
);
5251 if FCurrWeap
= WEAPON_SAW
then
5252 if not (FSawSound
.IsPlaying() or FSawSoundHit
.IsPlaying() or
5253 FSawSoundSelect
.IsPlaying()) then
5254 FSawSoundIdle
.PlayAt(FObj
.X
, FObj
.Y
);
5257 if (not FJetSoundFly
.IsPlaying()) and (not FJetSoundOn
.IsPlaying()) and
5258 (not FJetSoundOff
.IsPlaying()) then
5260 FJetSoundFly
.SetPosition(0);
5261 FJetSoundFly
.PlayAt(FObj
.X
, FObj
.Y
);
5264 for b
:= WP_FIRST
to WP_LAST
do
5265 if FReloading
[b
] > 0 then
5271 if FShellTimer
> -1 then
5272 if FShellTimer
= 0 then
5274 if FShellType
= SHELL_SHELL
then
5275 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5276 GameVelX
, GameVelY
-2, SHELL_SHELL
)
5277 else if FShellType
= SHELL_DBLSHELL
then
5279 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5280 GameVelX
+1, GameVelY
-2, SHELL_SHELL
);
5281 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5282 GameVelX
-1, GameVelY
-2, SHELL_SHELL
);
5285 end else Dec(FShellTimer
);
5287 if (FBFGFireCounter
> -1) then
5288 if FBFGFireCounter
= 0 then
5292 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
5293 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
5294 xd
:= wx
+IfThen(FDirection
= TDirection
.D_LEFT
, -30, 30);
5295 yd
:= wy
+firediry();
5296 g_Weapon_bfgshot(wx
, wy
, xd
, yd
, FUID
);
5297 if NetServer
then MH_SEND_PlayerFire(FUID
, WEAPON_BFG
, wx
, wy
, xd
, yd
);
5298 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
5299 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
5300 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
5303 FReloading
[WEAPON_BFG
] := WEAPON_RELOAD
[WEAPON_BFG
];
5304 FBFGFireCounter
:= -1;
5307 FBFGFireCounter
:= 0
5309 Dec(FBFGFireCounter
);
5311 if (FMegaRulez
[MR_SUIT
] < gTime
) and AnyServer
then
5313 b
:= g_GetAcidHit(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
);
5315 if (b
> 0) and (gTime
mod (15*GAME_TICK
) = 0) then Damage(b
, 0, 0, 0, HIT_ACID
);
5318 if (headwater
or blockmon
) then
5324 if AnyServer
then Damage(10, 0, 0, 0, HIT_WATER
);
5327 else if (FAir
mod 31 = 0) and not blockmon
then
5329 g_GFX_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2), FObj
.Y
+PLAYER_RECT
.Y
-4, 5+Random(6), 8, 4);
5330 if Random(2) = 0 then
5331 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
5333 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
5335 end else if FAir
< AIR_DEF
then
5338 if FFireTime
> 0 then
5340 if BodyInLiquid(0, 0) then
5345 else if FMegaRulez
[MR_SUIT
] >= gTime
then
5347 if FMegaRulez
[MR_SUIT
] = gTime
then
5354 if FFirePainTime
<= 0 then
5356 if g_Game_IsServer
then
5357 Damage(2, FFireAttacker
, 0, 0, HIT_FLAME
);
5358 FFirePainTime
:= 12 - FFireTime
div 12;
5360 FFirePainTime
:= FFirePainTime
- 1;
5361 FFireTime
:= FFireTime
- 1;
5362 if ((FFireTime
mod 33) = 0) and (FMegaRulez
[MR_INVUL
] < gTime
) then
5363 FModel
.PlaySound(MODELSOUND_PAIN
, 1, FObj
.X
, FObj
.Y
);
5364 if (FFireTime
= 0) and g_Game_IsNet
and g_Game_IsServer
then
5365 MH_SEND_PlayerStats(FUID
);
5369 if FDamageBuffer
> 0 then
5371 if FDamageBuffer
>= 9 then
5375 if FDamageBuffer
< 30 then i
:= 9
5376 else if FDamageBuffer
< 100 then i
:= 18
5380 ii
:= Round(FDamageBuffer
*FHealth
/ nonz(FArmor
*(3/4)+FHealth
));
5381 FArmor
:= FArmor
-(FDamageBuffer
-ii
);
5382 FHealth
:= FHealth
-ii
;
5385 FHealth
:= FHealth
+FArmor
;
5390 if FHealth
<= 0 then
5391 if FHealth
> -30 then Kill(K_SIMPLEKILL
, FLastSpawnerUID
, FLastHit
)
5392 else if FHealth
> -50 then Kill(K_HARDKILL
, FLastSpawnerUID
, FLastHit
)
5393 else Kill(K_EXTRAHARDKILL
, FLastSpawnerUID
, FLastHit
);
5395 if FAlive
and ((FLastHit
<> HIT_FLAME
) or (FFireTime
<= 0)) then
5397 if FDamageBuffer
<= 20 then FModel
.PlaySound(MODELSOUND_PAIN
, 1, FObj
.X
, FObj
.Y
)
5398 else if FDamageBuffer
<= 55 then FModel
.PlaySound(MODELSOUND_PAIN
, 2, FObj
.X
, FObj
.Y
)
5399 else if FDamageBuffer
<= 120 then FModel
.PlaySound(MODELSOUND_PAIN
, 3, FObj
.X
, FObj
.Y
)
5400 else FModel
.PlaySound(MODELSOUND_PAIN
, 4, FObj
.X
, FObj
.Y
);
5407 end; // if FAlive then ...
5409 if (FActionAnim
= A_PAIN
) and (FModel
.Animation
<> A_PAIN
) then
5411 FModel
.ChangeAnimation(FActionAnim
, FActionForce
);
5412 FModel
.GetCurrentAnimation
.MinLength
:= i
;
5413 FModel
.GetCurrentAnimationMask
.MinLength
:= i
;
5414 end else FModel
.ChangeAnimation(FActionAnim
, FActionForce
and (FModel
.Animation
<> A_STAND
));
5416 if (FModel
.GetCurrentAnimation
.Played
or ((not FActionChanged
) and (FModel
.Animation
= A_WALK
)))
5417 then SetAction(A_STAND
, True);
5419 if not ((FModel
.Animation
= A_WALK
) and (Abs(FObj
.Vel
.X
) < 4) and not FModel
.Fire
) then FModel
.Update
;
5421 for b
:= Low(FKeys
) to High(FKeys
) do
5422 if FKeys
[b
].Time
= 0 then FKeys
[b
].Pressed
:= False else Dec(FKeys
[b
].Time
);
5426 procedure TPlayer
.getMapBox (out x
, y
, w
, h
: Integer); inline;
5428 x
:= FObj
.X
+PLAYER_RECT
.X
;
5429 y
:= FObj
.Y
+PLAYER_RECT
.Y
;
5430 w
:= PLAYER_RECT
.Width
;
5431 h
:= PLAYER_RECT
.Height
;
5435 procedure TPlayer
.moveBy (dx
, dy
: Integer); inline;
5437 if (dx
<> 0) or (dy
<> 0) then
5446 function TPlayer
.Collide(X
, Y
: Integer; Width
, Height
: Word): Boolean;
5448 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
5449 FObj
.Y
+PLAYER_RECT
.Y
,
5456 function TPlayer
.Collide(Panel
: TPanel
): Boolean;
5458 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
5459 FObj
.Y
+PLAYER_RECT
.Y
,
5463 Panel
.Width
, Panel
.Height
);
5466 function TPlayer
.Collide(X
, Y
: Integer): Boolean;
5468 X
:= X
-FObj
.X
-PLAYER_RECT
.X
;
5469 Y
:= Y
-FObj
.Y
-PLAYER_RECT
.Y
;
5470 Result
:= (x
>= 0) and (x
<= PLAYER_RECT
.Width
) and
5471 (y
>= 0) and (y
<= PLAYER_RECT
.Height
);
5474 function g_Player_ValidName(Name
: string): Boolean;
5480 if gPlayers
= nil then Exit
;
5482 for a
:= 0 to High(gPlayers
) do
5483 if gPlayers
[a
] <> nil then
5484 if LowerCase(Name
) = LowerCase(gPlayers
[a
].FName
) then
5491 procedure TPlayer
.SetDirection(Direction
: TDirection
);
5495 d
:= FModel
.Direction
;
5497 FModel
.Direction
:= Direction
;
5498 if d
<> Direction
then FModel
.ChangeAnimation(FModel
.Animation
, True);
5500 FDirection
:= Direction
;
5503 function TPlayer
.GetKeys(): Byte;
5507 if R_KEY_RED
in FRulez
then Result
:= KEY_RED
;
5508 if R_KEY_GREEN
in FRulez
then Result
:= Result
or KEY_GREEN
;
5509 if R_KEY_BLUE
in FRulez
then Result
:= Result
or KEY_BLUE
;
5511 if FTeam
= TEAM_RED
then Result
:= Result
or KEY_REDTEAM
;
5512 if FTeam
= TEAM_BLUE
then Result
:= Result
or KEY_BLUETEAM
;
5515 procedure TPlayer
.Use();
5519 if FTime
[T_USE
] > gTime
then Exit
;
5521 g_Triggers_PressR(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
,
5522 PLAYER_RECT
.Height
, FUID
, ACTIVATE_PLAYERPRESS
);
5524 for a
:= 0 to High(gPlayers
) do
5525 if (gPlayers
[a
] <> nil) and (gPlayers
[a
] <> Self
) and
5526 gPlayers
[a
].alive
and SameTeam(FUID
, gPlayers
[a
].FUID
) and
5527 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
5528 FObj
.Rect
.Width
, FObj
.Rect
.Height
, @gPlayers
[a
].FObj
) then
5530 gPlayers
[a
].Touch();
5531 if g_Game_IsNet
and g_Game_IsServer
then
5532 MH_SEND_GameEvent(NET_EV_PLAYER_TOUCH
, gPlayers
[a
].FUID
);
5535 FTime
[T_USE
] := gTime
+120;
5538 procedure TPlayer
.NetFire(Wpn
: Byte; X
, Y
, AX
, AY
: Integer; WID
: Integer = -1);
5542 WX
, WY
, XD
, YD
: Integer;
5554 if R_BERSERK
in FRulez
then
5556 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
5557 locobj
.X
:= FObj
.X
+FObj
.Rect
.X
;
5558 locobj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
5561 locobj
.rect
.Width
:= 39;
5562 locobj
.rect
.Height
:= 52;
5563 locobj
.Vel
.X
:= (xd
-wx
) div 2;
5564 locobj
.Vel
.Y
:= (yd
-wy
) div 2;
5565 locobj
.Accel
.X
:= xd
-wx
;
5566 locobj
.Accel
.y
:= yd
-wy
;
5568 if g_Weapon_Hit(@locobj
, 50, FUID
, HIT_SOME
) <> 0 then
5569 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
5571 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
5575 FPain
:= min(FPain
+ 25, 50);
5577 g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
5582 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
5583 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
5585 FSawSoundSelect
.Stop();
5587 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
5589 else if not FSawSoundHit
.IsPlaying() then
5591 FSawSoundSelect
.Stop();
5592 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
5599 g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', GameX
, Gamey
);
5600 FFireAngle
:= FAngle
;
5602 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5603 GameVelX
, GameVelY
-2, SHELL_BULLET
);
5608 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
5609 FFireAngle
:= FAngle
;
5612 FShellType
:= SHELL_SHELL
;
5617 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN2', Gamex
, Gamey
);
5618 FFireAngle
:= FAngle
;
5621 FShellType
:= SHELL_DBLSHELL
;
5626 g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', Gamex
, Gamey
);
5627 FFireAngle
:= FAngle
;
5629 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5630 GameVelX
, GameVelY
-2, SHELL_BULLET
);
5633 WEAPON_ROCKETLAUNCHER
:
5635 g_Weapon_Rocket(wx
, wy
, xd
, yd
, FUID
, WID
);
5636 FFireAngle
:= FAngle
;
5642 g_Weapon_Plasma(wx
, wy
, xd
, yd
, FUID
, WID
);
5643 FFireAngle
:= FAngle
;
5649 g_Weapon_BFGShot(wx
, wy
, xd
, yd
, FUID
, WID
);
5650 FFireAngle
:= FAngle
;
5654 WEAPON_SUPERPULEMET
:
5656 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
5657 FFireAngle
:= FAngle
;
5659 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5660 GameVelX
, GameVelY
-2, SHELL_SHELL
);
5663 WEAPON_FLAMETHROWER
:
5665 g_Weapon_flame(wx
, wy
, xd
, yd
, FUID
, WID
);
5667 FFireAngle
:= FAngle
;
5674 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
5675 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
5676 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
5679 procedure TPlayer
.DoLerp(Level
: Integer = 2);
5681 if FObj
.X
<> FXTo
then FObj
.X
:= Lerp(FObj
.X
, FXTo
, Level
);
5682 if FObj
.Y
<> FYTo
then FObj
.Y
:= Lerp(FObj
.Y
, FYTo
, Level
);
5685 procedure TPlayer
.SetLerp(XTo
, YTo
: Integer);
5691 if FJustTeleported
or (NetInterpLevel
< 1) then
5695 if FJustTeleported
then
5697 FObj
.oldX
:= FObj
.X
;
5698 FObj
.oldY
:= FObj
.Y
;
5703 AX
:= Abs(FXTo
- FObj
.X
);
5704 AY
:= Abs(FYTo
- FObj
.Y
);
5705 if (AX
> 32) or (AX
<= NetInterpLevel
) then
5707 if (AY
> 32) or (AY
<= NetInterpLevel
) then
5712 function TPlayer
.FullInLift(XInc
, YInc
: Integer): Integer;
5714 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5715 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5716 PANEL_LIFTUP
, False) then Result
:= -1
5718 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5719 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5720 PANEL_LIFTDOWN
, False) then Result
:= 1
5724 function TPlayer
.GetFlag(Flag
: Byte): Boolean;
5731 if Flag
= FLAG_NONE
then
5734 if not g_Game_IsServer
then Exit
;
5736 // Ïðèíåñ ÷óæîé ôëàã íà ñâîþ áàçó:
5737 if (Flag
= FTeam
) and
5738 (gFlags
[Flag
].State
= FLAG_STATE_NORMAL
) and
5739 (FFlag
<> FLAG_NONE
) then
5741 if FFlag
= FLAG_RED
then
5742 s
:= _lc
[I_PLAYER_FLAG_RED
]
5744 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5746 evtype
:= FLAG_STATE_SCORED
;
5748 ts
:= Format('%.4d', [gFlags
[FFlag
].CaptureTime
]);
5749 Insert('.', ts
, Length(ts
) + 1 - 3);
5750 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_CAPTURE
], [FName
, s
, ts
]), True);
5752 g_Map_ResetFlag(FFlag
);
5753 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_CAPTURE
], [AnsiUpperCase(s
)]), 144);
5755 if ((Self
= gPlayer1
) or (Self
= gPlayer2
)
5756 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= FTeam
))
5757 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= FTeam
))) then
5762 if not sound_cap_flag
[a
].IsPlaying() then
5763 sound_cap_flag
[a
].Play();
5765 gTeamStat
[FTeam
].Goals
:= gTeamStat
[FTeam
].Goals
+ 1;
5768 if g_Game_IsNet
then
5770 MH_SEND_FlagEvent(evtype
, FFlag
, FUID
, False);
5774 gFlags
[FFlag
].CaptureTime
:= 0;
5779 // Ïîäîáðàë ñâîé ôëàã - âåðíóë åãî íà áàçó:
5780 if (Flag
= FTeam
) and
5781 (gFlags
[Flag
].State
= FLAG_STATE_DROPPED
) then
5783 if Flag
= FLAG_RED
then
5784 s
:= _lc
[I_PLAYER_FLAG_RED
]
5786 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5788 evtype
:= FLAG_STATE_RETURNED
;
5789 gFlags
[Flag
].CaptureTime
:= 0;
5791 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_RETURN
], [FName
, s
]), True);
5793 g_Map_ResetFlag(Flag
);
5794 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
5796 if ((Self
= gPlayer1
) or (Self
= gPlayer2
)
5797 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= FTeam
))
5798 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= FTeam
))) then
5803 if not sound_ret_flag
[a
].IsPlaying() then
5804 sound_ret_flag
[a
].Play();
5807 if g_Game_IsNet
then
5809 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5815 // Ïîäîáðàë ÷óæîé ôëàã:
5816 if (Flag
<> FTeam
) and (FTime
[T_FLAGCAP
] <= gTime
) then
5820 if Flag
= FLAG_RED
then
5821 s
:= _lc
[I_PLAYER_FLAG_RED
]
5823 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5825 evtype
:= FLAG_STATE_CAPTURED
;
5827 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_GET
], [FName
, s
]), True);
5829 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_GET
], [AnsiUpperCase(s
)]), 144);
5831 gFlags
[Flag
].State
:= FLAG_STATE_CAPTURED
;
5833 if ((Self
= gPlayer1
) or (Self
= gPlayer2
)
5834 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= FTeam
))
5835 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= FTeam
))) then
5840 if not sound_get_flag
[a
].IsPlaying() then
5841 sound_get_flag
[a
].Play();
5844 if g_Game_IsNet
then
5846 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5852 procedure TPlayer
.SetFlag(Flag
: Byte);
5855 if FModel
<> nil then
5856 FModel
.SetFlag(FFlag
);
5859 function TPlayer
.TryDropFlag(): Boolean;
5861 if LongBool(gGameSettings
.Options
and GAME_OPTION_ALLOWDROPFLAG
) then
5862 Result
:= DropFlag(False, LongBool(gGameSettings
.Options
and GAME_OPTION_THROWFLAG
))
5867 function TPlayer
.DropFlag(Silent
: Boolean = True; DoThrow
: Boolean = False): Boolean;
5874 if (not g_Game_IsServer
) or (FFlag
= FLAG_NONE
) then
5876 FTime
[T_FLAGCAP
] := gTime
+ 2000;
5877 with gFlags
[FFlag
] do
5881 Direction
:= FDirection
;
5882 State
:= FLAG_STATE_DROPPED
;
5886 xv
:= FObj
.Vel
.X
+ IfThen(Direction
= TDirection
.D_RIGHT
, 10, -10);
5887 yv
:= FObj
.Vel
.Y
- 2;
5891 xv
:= (FObj
.Vel
.X
div 2);
5892 yv
:= (FObj
.Vel
.Y
div 2) - 2;
5894 g_Obj_Push(@Obj
, xv
, yv
);
5896 positionChanged(); // this updates spatial accelerators
5898 if FFlag
= FLAG_RED
then
5899 s
:= _lc
[I_PLAYER_FLAG_RED
]
5901 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5903 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_DROP
], [FName
, s
]), True);
5904 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_DROP
], [AnsiUpperCase(s
)]), 144);
5906 if ((Self
= gPlayer1
) or (Self
= gPlayer2
)
5907 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= FTeam
))
5908 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= FTeam
))) then
5913 if (not Silent
) and (not sound_lost_flag
[a
].IsPlaying()) then
5914 sound_lost_flag
[a
].Play();
5916 if g_Game_IsNet
then
5917 MH_SEND_FlagEvent(FLAG_STATE_DROPPED
, Flag
, FUID
, False);
5923 procedure TPlayer
.GetSecret();
5925 if (self
= gPlayer1
) or (self
= gPlayer2
) then
5927 g_Console_Add(Format(_lc
[I_PLAYER_SECRET
], [FName
]), True);
5928 g_Sound_PlayEx('SOUND_GAME_SECRET');
5933 procedure TPlayer
.PressKey(Key
: Byte; Time
: Word = 1);
5935 Assert(Key
<= High(FKeys
));
5937 FKeys
[Key
].Pressed
:= True;
5938 FKeys
[Key
].Time
:= Time
;
5941 function TPlayer
.IsKeyPressed(K
: Byte): Boolean;
5943 Result
:= FKeys
[K
].Pressed
;
5946 procedure TPlayer
.ReleaseKeys();
5950 for a
:= Low(FKeys
) to High(FKeys
) do
5952 FKeys
[a
].Pressed
:= False;
5957 procedure TPlayer
.OnDamage(Angle
: SmallInt);
5961 function TPlayer
.firediry(): Integer;
5963 if FKeys
[KEY_UP
].Pressed
then Result
:= -42
5964 else if FKeys
[KEY_DOWN
].Pressed
then Result
:= 19
5968 procedure TPlayer
.RememberState();
5971 SavedState
: TPlayerSavedState
;
5973 SavedState
.Health
:= FHealth
;
5974 SavedState
.Armor
:= FArmor
;
5975 SavedState
.Air
:= FAir
;
5976 SavedState
.JetFuel
:= FJetFuel
;
5977 SavedState
.CurrWeap
:= FCurrWeap
;
5978 SavedState
.NextWeap
:= FNextWeap
;
5979 SavedState
.NextWeapDelay
:= FNextWeapDelay
;
5980 for i
:= Low(FWeapon
) to High(FWeapon
) do
5981 SavedState
.Weapon
[i
] := FWeapon
[i
];
5982 for i
:= Low(FAmmo
) to High(FAmmo
) do
5983 SavedState
.Ammo
[i
] := FAmmo
[i
];
5984 for i
:= Low(FMaxAmmo
) to High(FMaxAmmo
) do
5985 SavedState
.MaxAmmo
[i
] := FMaxAmmo
[i
];
5986 SavedState
.Rulez
:= FRulez
- [R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
];
5988 FSavedStateNum
:= -1;
5989 for i
:= Low(SavedStates
) to High(SavedStates
) do
5990 if not SavedStates
[i
].Used
then
5992 FSavedStateNum
:= i
;
5995 if FSavedStateNum
< 0 then
5997 SetLength(SavedStates
, Length(SavedStates
) + 1);
5998 FSavedStateNum
:= High(SavedStates
);
6001 SavedState
.Used
:= True;
6002 SavedStates
[FSavedStateNum
] := SavedState
;
6005 procedure TPlayer
.RecallState();
6008 SavedState
: TPlayerSavedState
;
6010 if(FSavedStateNum
< 0) or (FSavedStateNum
> High(SavedStates
)) then
6013 SavedState
:= SavedStates
[FSavedStateNum
];
6014 SavedStates
[FSavedStateNum
].Used
:= False;
6015 FSavedStateNum
:= -1;
6017 FHealth
:= SavedState
.Health
;
6018 FArmor
:= SavedState
.Armor
;
6019 FAir
:= SavedState
.Air
;
6020 FJetFuel
:= SavedState
.JetFuel
;
6021 FCurrWeap
:= SavedState
.CurrWeap
;
6022 FNextWeap
:= SavedState
.NextWeap
;
6023 FNextWeapDelay
:= SavedState
.NextWeapDelay
;
6024 for i
:= Low(FWeapon
) to High(FWeapon
) do
6025 FWeapon
[i
] := SavedState
.Weapon
[i
];
6026 for i
:= Low(FAmmo
) to High(FAmmo
) do
6027 FAmmo
[i
] := SavedState
.Ammo
[i
];
6028 for i
:= Low(FMaxAmmo
) to High(FMaxAmmo
) do
6029 FMaxAmmo
[i
] := SavedState
.MaxAmmo
[i
];
6030 FRulez
:= SavedState
.Rulez
;
6032 if gGameSettings
.GameType
= GT_SERVER
then
6033 MH_SEND_PlayerStats(FUID
);
6036 procedure TPlayer
.SaveState (st
: TStream
);
6042 utils
.writeSign(st
, 'PLYR');
6043 utils
.writeInt(st
, Byte(PLR_SAVE_VERSION
)); // version
6045 utils
.writeBool(st
, FIamBot
);
6047 utils
.writeInt(st
, Word(FUID
));
6049 utils
.writeStr(st
, FName
);
6051 utils
.writeInt(st
, Byte(FTeam
));
6053 utils
.writeBool(st
, FAlive
);
6054 // Èçðàñõîäîâàë ëè âñå æèçíè
6055 utils
.writeBool(st
, FNoRespawn
);
6057 if FDirection
= TDirection
.D_LEFT
then b
:= 1 else b
:= 2; // D_RIGHT
6058 utils
.writeInt(st
, Byte(b
));
6060 utils
.writeInt(st
, LongInt(FHealth
));
6061 // Êîýôôèöèåíò èíâàëèäíîñòè
6062 utils
.writeInt(st
, LongInt(FHandicap
));
6064 utils
.writeInt(st
, Byte(FLives
));
6066 utils
.writeInt(st
, LongInt(FArmor
));
6068 utils
.writeInt(st
, LongInt(FAir
));
6070 utils
.writeInt(st
, LongInt(FJetFuel
));
6072 utils
.writeInt(st
, LongInt(FPain
));
6074 utils
.writeInt(st
, LongInt(FKills
));
6076 utils
.writeInt(st
, LongInt(FMonsterKills
));
6078 utils
.writeInt(st
, LongInt(FFrags
));
6080 utils
.writeInt(st
, Byte(FFragCombo
));
6081 // Âðåìÿ ïîñëåäíåãî ôðàãà
6082 utils
.writeInt(st
, LongWord(FLastFrag
));
6084 utils
.writeInt(st
, LongInt(FDeath
));
6086 utils
.writeInt(st
, Byte(FFlag
));
6088 utils
.writeInt(st
, LongInt(FSecrets
));
6090 utils
.writeInt(st
, Byte(FCurrWeap
));
6092 utils
.writeInt(st
, Word(FNextWeap
));
6094 utils
.writeInt(st
, Byte(FNextWeapDelay
));
6095 // Âðåìÿ çàðÿäêè BFG
6096 utils
.writeInt(st
, SmallInt(FBFGFireCounter
));
6098 utils
.writeInt(st
, LongInt(FDamageBuffer
));
6099 // Ïîñëåäíèé óäàðèâøèé
6100 utils
.writeInt(st
, Word(FLastSpawnerUID
));
6101 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà
6102 utils
.writeInt(st
, Byte(FLastHit
));
6104 Obj_SaveState(st
, @FObj
);
6105 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ
6106 for i
:= A_BULLETS
to A_HIGH
do utils
.writeInt(st
, Word(FAmmo
[i
]));
6107 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ
6108 for i
:= A_BULLETS
to A_HIGH
do utils
.writeInt(st
, Word(FMaxAmmo
[i
]));
6110 for i
:= WP_FIRST
to WP_LAST
do utils
.writeBool(st
, FWeapon
[i
]);
6111 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ
6112 for i
:= WP_FIRST
to WP_LAST
do utils
.writeInt(st
, Word(FReloading
[i
]));
6114 utils
.writeBool(st
, (R_ITEM_BACKPACK
in FRulez
));
6115 // Íàëè÷èå êðàñíîãî êëþ÷à
6116 utils
.writeBool(st
, (R_KEY_RED
in FRulez
));
6117 // Íàëè÷èå çåëåíîãî êëþ÷à
6118 utils
.writeBool(st
, (R_KEY_GREEN
in FRulez
));
6119 // Íàëè÷èå ñèíåãî êëþ÷à
6120 utils
.writeBool(st
, (R_KEY_BLUE
in FRulez
));
6122 utils
.writeBool(st
, (R_BERSERK
in FRulez
));
6123 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ
6124 for i
:= MR_SUIT
to MR_MAX
do utils
.writeInt(st
, LongWord(FMegaRulez
[i
]));
6125 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà
6126 for i
:= T_RESPAWN
to T_FLAGCAP
do utils
.writeInt(st
, LongWord(FTime
[i
]));
6128 utils
.writeStr(st
, FModel
.Name
);
6130 utils
.writeInt(st
, Byte(FColor
.R
));
6131 utils
.writeInt(st
, Byte(FColor
.G
));
6132 utils
.writeInt(st
, Byte(FColor
.B
));
6136 procedure TPlayer
.LoadState (st
: TStream
);
6145 if not utils
.checkSign(st
, 'PLYR') then raise XStreamError
.Create('invalid player signature');
6146 if (utils
.readByte(st
) <> PLR_SAVE_VERSION
) then raise XStreamError
.Create('invalid player version');
6148 FIamBot
:= utils
.readBool(st
);
6150 FUID
:= utils
.readWord(st
);
6152 str
:= utils
.readStr(st
);
6153 if (self
<> gPlayer1
) and (self
<> gPlayer2
) then FName
:= str
;
6155 FTeam
:= utils
.readByte(st
);
6157 FAlive
:= utils
.readBool(st
);
6158 // Èçðàñõîäîâàë ëè âñå æèçíè
6159 FNoRespawn
:= utils
.readBool(st
);
6161 b
:= utils
.readByte(st
);
6162 if b
= 1 then FDirection
:= TDirection
.D_LEFT
else FDirection
:= TDirection
.D_RIGHT
; // b = 2
6164 FHealth
:= utils
.readLongInt(st
);
6165 // Êîýôôèöèåíò èíâàëèäíîñòè
6166 FHandicap
:= utils
.readLongInt(st
);
6168 FLives
:= utils
.readByte(st
);
6170 FArmor
:= utils
.readLongInt(st
);
6172 FAir
:= utils
.readLongInt(st
);
6174 FJetFuel
:= utils
.readLongInt(st
);
6176 FPain
:= utils
.readLongInt(st
);
6178 FKills
:= utils
.readLongInt(st
);
6180 FMonsterKills
:= utils
.readLongInt(st
);
6182 FFrags
:= utils
.readLongInt(st
);
6184 FFragCombo
:= utils
.readByte(st
);
6185 // Âðåìÿ ïîñëåäíåãî ôðàãà
6186 FLastFrag
:= utils
.readLongWord(st
);
6188 FDeath
:= utils
.readLongInt(st
);
6190 FFlag
:= utils
.readByte(st
);
6192 FSecrets
:= utils
.readLongInt(st
);
6194 FCurrWeap
:= utils
.readByte(st
);
6196 FNextWeap
:= utils
.readWord(st
);
6198 FNextWeapDelay
:= utils
.readByte(st
);
6199 // Âðåìÿ çàðÿäêè BFG
6200 FBFGFireCounter
:= utils
.readSmallInt(st
);
6202 FDamageBuffer
:= utils
.readLongInt(st
);
6203 // Ïîñëåäíèé óäàðèâøèé
6204 FLastSpawnerUID
:= utils
.readWord(st
);
6205 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà
6206 FLastHit
:= utils
.readByte(st
);
6208 Obj_LoadState(@FObj
, st
);
6209 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ
6210 for i
:= A_BULLETS
to A_HIGH
do FAmmo
[i
] := utils
.readWord(st
);
6211 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ
6212 for i
:= A_BULLETS
to A_HIGH
do FMaxAmmo
[i
] := utils
.readWord(st
);
6214 for i
:= WP_FIRST
to WP_LAST
do FWeapon
[i
] := utils
.readBool(st
);
6215 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ
6216 for i
:= WP_FIRST
to WP_LAST
do FReloading
[i
] := utils
.readWord(st
);
6218 if utils
.readBool(st
) then Include(FRulez
, R_ITEM_BACKPACK
);
6219 // Íàëè÷èå êðàñíîãî êëþ÷à
6220 if utils
.readBool(st
) then Include(FRulez
, R_KEY_RED
);
6221 // Íàëè÷èå çåëåíîãî êëþ÷à
6222 if utils
.readBool(st
) then Include(FRulez
, R_KEY_GREEN
);
6223 // Íàëè÷èå ñèíåãî êëþ÷à
6224 if utils
.readBool(st
) then Include(FRulez
, R_KEY_BLUE
);
6226 if utils
.readBool(st
) then Include(FRulez
, R_BERSERK
);
6227 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ
6228 for i
:= MR_SUIT
to MR_MAX
do FMegaRulez
[i
] := utils
.readLongWord(st
);
6229 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà
6230 for i
:= T_RESPAWN
to T_FLAGCAP
do FTime
[i
] := utils
.readLongWord(st
);
6232 str
:= utils
.readStr(st
);
6234 FColor
.R
:= utils
.readByte(st
);
6235 FColor
.G
:= utils
.readByte(st
);
6236 FColor
.B
:= utils
.readByte(st
);
6237 if (self
= gPlayer1
) then
6239 str
:= gPlayer1Settings
.Model
;
6240 FColor
:= gPlayer1Settings
.Color
;
6242 else if (self
= gPlayer2
) then
6244 str
:= gPlayer2Settings
.Model
;
6245 FColor
:= gPlayer2Settings
.Color
;
6247 // Îáíîâëÿåì ìîäåëü èãðîêà
6249 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
6250 FModel
.Color
:= TEAMCOLOR
[FTeam
]
6252 FModel
.Color
:= FColor
;
6256 procedure TPlayer
.AllRulez(Health
: Boolean);
6262 FHealth
:= PLAYER_HP_LIMIT
;
6263 FArmor
:= PLAYER_AP_LIMIT
;
6267 for a
:= WP_FIRST
to WP_LAST
do FWeapon
[a
] := True;
6268 for a
:= A_BULLETS
to A_HIGH
do FAmmo
[a
] := 30000;
6269 FRulez
:= FRulez
+[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
];
6272 procedure TPlayer
.RestoreHealthArmor();
6274 FHealth
:= PLAYER_HP_LIMIT
;
6275 FArmor
:= PLAYER_AP_LIMIT
;
6278 procedure TPlayer
.FragCombo();
6282 if (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) or g_Game_IsClient
then
6284 if gTime
- FLastFrag
< FRAG_COMBO_TIME
then
6286 if FFragCombo
< 5 then
6288 Param
:= FUID
or (FFragCombo
shl 16);
6289 if (FComboEvnt
>= Low(gDelayedEvents
)) and
6290 (FComboEvnt
<= High(gDelayedEvents
)) and
6291 gDelayedEvents
[FComboEvnt
].Pending
and
6292 (gDelayedEvents
[FComboEvnt
].DEType
= DE_KILLCOMBO
) and
6293 (gDelayedEvents
[FComboEvnt
].DENum
and $FFFF = FUID
) then
6295 gDelayedEvents
[FComboEvnt
].Time
:= gTime
+ 500;
6296 gDelayedEvents
[FComboEvnt
].DENum
:= Param
;
6299 FComboEvnt
:= g_Game_DelayEvent(DE_KILLCOMBO
, 500, Param
);
6307 procedure TPlayer
.GiveItem(ItemType
: Byte);
6311 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
6313 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
6317 if FAir
< AIR_MAX
then
6324 if not (R_BERSERK
in FRulez
) then
6326 Include(FRulez
, R_BERSERK
);
6327 if FBFGFireCounter
< 1 then
6329 FCurrWeap
:= WEAPON_KASTET
;
6331 FModel
.SetWeapon(WEAPON_KASTET
);
6335 FBerserk
:= gTime
+30000;
6337 if FHealth
< PLAYER_HP_SOFT
then
6339 FHealth
:= PLAYER_HP_SOFT
;
6340 FBerserk
:= gTime
+30000;
6345 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
6347 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
6352 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
6354 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
6358 if FJetFuel
< JET_MAX
then
6360 FJetFuel
:= JET_MAX
;
6363 ITEM_MEDKIT_SMALL
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
6364 ITEM_MEDKIT_LARGE
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
6366 ITEM_ARMOR_GREEN
: if FArmor
< PLAYER_AP_SOFT
then FArmor
:= PLAYER_AP_SOFT
;
6367 ITEM_ARMOR_BLUE
: if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
6369 ITEM_SPHERE_BLUE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
6371 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) then
6373 if FHealth
< PLAYER_HP_LIMIT
then FHealth
:= PLAYER_HP_LIMIT
;
6374 if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
6377 ITEM_WEAPON_SAW
: FWeapon
[WEAPON_SAW
] := True;
6378 ITEM_WEAPON_SHOTGUN1
: FWeapon
[WEAPON_SHOTGUN1
] := True;
6379 ITEM_WEAPON_SHOTGUN2
: FWeapon
[WEAPON_SHOTGUN2
] := True;
6380 ITEM_WEAPON_CHAINGUN
: FWeapon
[WEAPON_CHAINGUN
] := True;
6381 ITEM_WEAPON_ROCKETLAUNCHER
: FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
6382 ITEM_WEAPON_PLASMA
: FWeapon
[WEAPON_PLASMA
] := True;
6383 ITEM_WEAPON_BFG
: FWeapon
[WEAPON_BFG
] := True;
6384 ITEM_WEAPON_SUPERPULEMET
: FWeapon
[WEAPON_SUPERPULEMET
] := True;
6385 ITEM_WEAPON_FLAMETHROWER
: FWeapon
[WEAPON_FLAMETHROWER
] := True;
6387 ITEM_AMMO_BULLETS
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
6388 ITEM_AMMO_BULLETS_BOX
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
6389 ITEM_AMMO_SHELLS
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
6390 ITEM_AMMO_SHELLS_BOX
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
6391 ITEM_AMMO_ROCKET
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
6392 ITEM_AMMO_ROCKET_BOX
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
6393 ITEM_AMMO_CELL
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
6394 ITEM_AMMO_CELL_BIG
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
6395 ITEM_AMMO_FUELCAN
: if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
6398 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
6399 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
6400 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
6401 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or
6402 (FMaxAmmo
[A_FUEL
] < AmmoLimits
[1, A_FUEL
]) then
6404 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[1, A_BULLETS
];
6405 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[1, A_SHELLS
];
6406 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[1, A_ROCKETS
];
6407 FMaxAmmo
[A_CELLS
] := AmmoLimits
[1, A_CELLS
];
6408 FMaxAmmo
[A_FUEL
] := AmmoLimits
[1, A_FUEL
];
6410 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
6411 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
6412 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
6413 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
6415 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
6418 ITEM_KEY_RED
: if not (R_KEY_RED
in FRulez
) then Include(FRulez
, R_KEY_RED
);
6419 ITEM_KEY_GREEN
: if not (R_KEY_GREEN
in FRulez
) then Include(FRulez
, R_KEY_GREEN
);
6420 ITEM_KEY_BLUE
: if not (R_KEY_BLUE
in FRulez
) then Include(FRulez
, R_KEY_BLUE
);
6422 ITEM_BOTTLE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
6423 ITEM_HELMET
: if FArmor
< PLAYER_AP_LIMIT
then IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
6428 if g_Game_IsNet
and g_Game_IsServer
then
6429 MH_SEND_PlayerStats(FUID
);
6432 procedure TPlayer
.FlySmoke(Times
: DWORD
= 1);
6437 if (Random(5) = 1) and (Times
= 1) then
6440 if BodyInLiquid(0, 0) then
6442 g_GFX_Bubbles(Obj
.X
+Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2)+Random(3)-1,
6443 Obj
.Y
+Obj
.Rect
.Height
+8, 1, 8, 4);
6444 if Random(2) = 0 then
6445 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
6447 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
6451 if g_Frames_Get(id
, 'FRAMES_SMOKE') then
6453 for i
:= 1 to Times
do
6455 Anim
:= TAnimation
.Create(id
, False, 3);
6457 g_GFX_OnceAnim(Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(Anim
.Width
div 2),
6458 Obj
.Y
+Obj
.Rect
.Height
-4+Random(8+Times
*2), Anim
, ONCEANIM_SMOKE
);
6464 procedure TPlayer
.OnFireFlame(Times
: DWORD
= 1);
6469 if (Random(10) = 1) and (Times
= 1) then
6472 if g_Frames_Get(id
, 'FRAMES_FLAME') then
6474 for i
:= 1 to Times
do
6476 Anim
:= TAnimation
.Create(id
, False, 3);
6478 g_GFX_OnceAnim(Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(Anim
.Width
div 2),
6479 Obj
.Y
+8+Random(8+Times
*2), Anim
, ONCEANIM_SMOKE
);
6485 procedure TPlayer
.PauseSounds(Enable
: Boolean);
6487 FSawSound
.Pause(Enable
);
6488 FSawSoundIdle
.Pause(Enable
);
6489 FSawSoundHit
.Pause(Enable
);
6490 FSawSoundSelect
.Pause(Enable
);
6491 FFlameSoundOn
.Pause(Enable
);
6492 FFlameSoundOff
.Pause(Enable
);
6493 FFlameSoundWork
.Pause(Enable
);
6494 FJetSoundFly
.Pause(Enable
);
6495 FJetSoundOn
.Pause(Enable
);
6496 FJetSoundOff
.Pause(Enable
);
6501 constructor TCorpse
.Create(X
, Y
: Integer; ModelName
: String; aMess
: Boolean);
6506 FObj
.Rect
:= PLAYER_CORPSERECT
;
6507 FModelName
:= ModelName
;
6512 FState
:= CORPSE_STATE_MESS
;
6513 g_PlayerModel_GetAnim(ModelName
, A_DIE2
, FAnimation
, FAnimationMask
);
6517 FState
:= CORPSE_STATE_NORMAL
;
6518 g_PlayerModel_GetAnim(ModelName
, A_DIE1
, FAnimation
, FAnimationMask
);
6522 destructor TCorpse
.Destroy();
6529 function TCorpse
.ObjPtr (): PObj
; inline; begin result
:= @FObj
; end;
6531 procedure TCorpse
.positionChanged (); inline; begin end;
6533 procedure TCorpse
.moveBy (dx
, dy
: Integer); inline;
6535 if (dx
<> 0) or (dy
<> 0) then
6544 procedure TCorpse
.getMapBox (out x
, y
, w
, h
: Integer); inline;
6546 x
:= FObj
.X
+PLAYER_CORPSERECT
.X
;
6547 y
:= FObj
.Y
+PLAYER_CORPSERECT
.Y
;
6548 w
:= PLAYER_CORPSERECT
.Width
;
6549 h
:= PLAYER_CORPSERECT
.Height
;
6553 procedure TCorpse
.Damage(Value
: Word; SpawnerUID
: Word; vx
, vy
: Integer);
6558 if FState
= CORPSE_STATE_REMOVEME
then
6561 FDamage
:= FDamage
+ Value
;
6563 if FDamage
> 150 then
6565 if FAnimation
<> nil then
6570 FState
:= CORPSE_STATE_REMOVEME
;
6572 g_Player_CreateGibs(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
6573 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2),
6574 FModelName
, FColor
);
6575 // Çâóê ìÿñà îò òðóïà:
6576 pm
:= g_PlayerModel_Get(FModelName
);
6577 pm
.PlaySound(MODELSOUND_DIE
, 5, FObj
.X
, FObj
.Y
);
6581 if (gBodyKillEvent
<> -1)
6582 and gDelayedEvents
[gBodyKillEvent
].Pending
then
6583 gDelayedEvents
[gBodyKillEvent
].Pending
:= False;
6584 gBodyKillEvent
:= g_Game_DelayEvent(DE_BODYKILL
, 1050, SpawnerUID
);
6589 Blood
:= g_PlayerModel_GetBlood(FModelName
);
6590 FObj
.Vel
.X
:= FObj
.Vel
.X
+ vx
;
6591 FObj
.Vel
.Y
:= FObj
.Vel
.Y
+ vy
;
6592 g_GFX_Blood(FObj
.X
+PLAYER_CORPSERECT
.X
+(PLAYER_CORPSERECT
.Width
div 2),
6593 FObj
.Y
+PLAYER_CORPSERECT
.Y
+(PLAYER_CORPSERECT
.Height
div 2),
6594 Value
, vx
, vy
, 16, (PLAYER_CORPSERECT
.Height
*2) div 3,
6595 Blood
.R
, Blood
.G
, Blood
.B
, Blood
.Kind
);
6599 procedure TCorpse
.Draw();
6603 if FState
= CORPSE_STATE_REMOVEME
then
6606 FObj
.lerp(gLerpFactor
, fX
, fY
);
6608 if FAnimation
<> nil then
6609 FAnimation
.Draw(fX
, fY
, TMirrorType
.None
);
6611 if FAnimationMask
<> nil then
6614 FAnimationMask
.Draw(fX
, fY
, TMirrorType
.None
);
6621 procedure TCorpse
.Update();
6625 if FState
= CORPSE_STATE_REMOVEME
then
6628 FObj
.oldX
:= FObj
.X
;
6629 FObj
.oldY
:= FObj
.Y
;
6631 if gTime
mod (GAME_TICK
*2) <> 0 then
6633 g_Obj_Move(@FObj
, True, True, True);
6634 positionChanged(); // this updates spatial accelerators
6638 // Ñîïðîòèâëåíèå âîçäóõà äëÿ òðóïà:
6639 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
6641 st
:= g_Obj_Move(@FObj
, True, True, True);
6642 positionChanged(); // this updates spatial accelerators
6644 if WordBool(st
and MOVE_FALLOUT
) then
6646 FState
:= CORPSE_STATE_REMOVEME
;
6650 if FAnimation
<> nil then
6651 FAnimation
.Update();
6652 if FAnimationMask
<> nil then
6653 FAnimationMask
.Update();
6657 procedure TCorpse
.SaveState (st
: TStream
);
6664 utils
.writeSign(st
, 'CORP');
6665 utils
.writeInt(st
, Byte(0));
6667 utils
.writeInt(st
, Byte(FState
));
6669 utils
.writeInt(st
, Byte(FDamage
));
6671 utils
.writeInt(st
, Byte(FColor
.R
));
6672 utils
.writeInt(st
, Byte(FColor
.G
));
6673 utils
.writeInt(st
, Byte(FColor
.B
));
6675 Obj_SaveState(st
, @FObj
);
6676 utils
.writeInt(st
, Word(FPlayerUID
));
6678 anim
:= (FAnimation
<> nil);
6679 utils
.writeBool(st
, anim
);
6680 // Åñëè åñòü - ñîõðàíÿåì
6681 if anim
then FAnimation
.SaveState(st
);
6682 // Åñòü ëè ìàñêà àíèìàöèè
6683 anim
:= (FAnimationMask
<> nil);
6684 utils
.writeBool(st
, anim
);
6685 // Åñëè åñòü - ñîõðàíÿåì
6686 if anim
then FAnimationMask
.SaveState(st
);
6690 procedure TCorpse
.LoadState (st
: TStream
);
6697 if not utils
.checkSign(st
, 'CORP') then raise XStreamError
.Create('invalid corpse signature');
6698 if (utils
.readByte(st
) <> 0) then raise XStreamError
.Create('invalid corpse version');
6700 FState
:= utils
.readByte(st
);
6702 FDamage
:= utils
.readByte(st
);
6704 FColor
.R
:= utils
.readByte(st
);
6705 FColor
.G
:= utils
.readByte(st
);
6706 FColor
.B
:= utils
.readByte(st
);
6708 Obj_LoadState(@FObj
, st
);
6709 FPlayerUID
:= utils
.readWord(st
);
6711 anim
:= utils
.readBool(st
);
6712 // Åñëè åñòü - çàãðóæàåì
6715 Assert(FAnimation
<> nil, 'TCorpse.LoadState: no FAnimation');
6716 FAnimation
.LoadState(st
);
6718 // Åñòü ëè ìàñêà àíèìàöèè
6719 anim
:= utils
.readBool(st
);
6720 // Åñëè åñòü - çàãðóæàåì
6723 Assert(FAnimationMask
<> nil, 'TCorpse.LoadState: no FAnimationMask');
6724 FAnimationMask
.LoadState(st
);
6730 constructor TBot
.Create();
6737 FSpectator
:= False;
6744 for a
:= WP_FIRST
to WP_LAST
do
6746 FDifficult
.WeaponPrior
[a
] := WEAPON_PRIOR1
[a
];
6747 FDifficult
.CloseWeaponPrior
[a
] := WEAPON_PRIOR2
[a
];
6748 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
6752 destructor TBot
.Destroy();
6755 inherited Destroy();
6758 procedure TBot
.Draw();
6762 //if FTargetUID <> 0 then e_DrawLine(1, FObj.X, FObj.Y, g_Player_Get(FTargetUID).FObj.X,
6763 // g_Player_Get(FTargetUID).FObj.Y, 255, 0, 0);
6766 procedure TBot
.Respawn(Silent
: Boolean; Force
: Boolean = False);
6768 inherited Respawn(Silent
, Force
);
6771 FSelectedWeapon
:= FCurrWeap
;
6776 procedure TBot
.UpdateCombat();
6789 TTargetRecord
= array of TTarget
;
6791 function Compare(a
, b
: TTarget
): Integer;
6793 if a
.Line
and not b
.Line
then // A íà ëèíèè îãíÿ
6796 if not a
.Line
and b
.Line
then // B íà ëèíèè îãíÿ
6798 else // È A, è B íà ëèíèè èëè íå íà ëèíèè îãíÿ
6799 if (a
.Line
and b
.Line
) or ((not a
.Line
) and (not b
.Line
)) then
6801 if a
.Dist
> b
.Dist
then // B áëèæå
6803 else // A áëèæå èëè ðàâíîóäàëåííî ñ B
6806 else // Ñòðàííî -> A
6811 a
, x1
, y1
, x2
, y2
: Integer;
6812 targets
: TTargetRecord
;
6814 Target
, BestTarget
: TTarget
;
6815 firew
, fireh
: Integer;
6819 vsPlayer
, vsMonster
, ok
: Boolean;
6822 function monsUpdate (mon
: TMonster
): Boolean;
6824 result
:= false; // don't stop
6825 if mon
.alive
and (mon
.MonsterType
<> MONSTER_BARREL
) then
6827 if not TargetOnScreen(mon
.Obj
.X
+mon
.Obj
.Rect
.X
, mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
) then exit
;
6829 x2
:= mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2);
6830 y2
:= mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+(mon
.Obj
.Rect
.Height
div 2);
6832 // Åñëè ìîíñòð íà ýêðàíå è íå ïðèêðûò ñòåíîé
6833 if g_TraceVector(x1
, y1
, x2
, y2
) then
6835 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé
6836 SetLength(targets
, Length(targets
)+1);
6837 with targets
[High(targets
)] do
6844 Rect
:= mon
.Obj
.Rect
;
6845 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6846 Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6847 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6856 vsPlayer
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
);
6857 vsMonster
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
);
6859 // Åñëè òåêóùåå îðóæèå íå òî, ÷òî íóæíî, òî ìåíÿåì:
6860 if FCurrWeap
<> FSelectedWeapon
then
6863 // Åñëè íóæíî ñòðåëÿòü è íóæíîå îðóæèå, òî íàæàòü "Ñòðåëÿòü":
6864 if (GetAIFlag('NEEDFIRE') <> '') and (FCurrWeap
= FSelectedWeapon
) then
6866 RemoveAIFlag('NEEDFIRE');
6869 WEAPON_PLASMA
, WEAPON_SUPERPULEMET
, WEAPON_CHAINGUN
: PressKey(KEY_FIRE
, 20);
6870 WEAPON_SAW
, WEAPON_KASTET
, WEAPON_FLAMETHROWER
: PressKey(KEY_FIRE
, 40);
6871 else PressKey(KEY_FIRE
);
6875 // Êîîðäèíàòû ñòâîëà:
6876 x1
:= FObj
.X
+ WEAPONPOINT
[FDirection
].X
;
6877 y1
:= FObj
.Y
+ WEAPONPOINT
[FDirection
].Y
;
6879 Target
.UID
:= FTargetUID
;
6882 if Target
.UID
<> 0 then
6883 begin // Öåëü åñòü - íàñòðàèâàåì
6884 if (g_GetUIDType(Target
.UID
) = UID_PLAYER
) and
6887 tpla
:= g_Player_Get(Target
.UID
);
6891 if (@FObj
) <> nil then
6898 Target
.cX
:= Target
.X
+ PLAYER_RECT_CX
;
6899 Target
.cY
:= Target
.Y
+ PLAYER_RECT_CY
;
6900 Target
.Rect
:= PLAYER_RECT
;
6901 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6902 Target
.Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6903 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6904 Target
.IsPlayer
:= True;
6908 if (g_GetUIDType(Target
.UID
) = UID_MONSTER
) and
6911 mon
:= g_Monsters_ByUID(Target
.UID
);
6914 Target
.X
:= mon
.Obj
.X
;
6915 Target
.Y
:= mon
.Obj
.Y
;
6917 Target
.cX
:= Target
.X
+ mon
.Obj
.Rect
.X
+ (mon
.Obj
.Rect
.Width
div 2);
6918 Target
.cY
:= Target
.Y
+ mon
.Obj
.Rect
.Y
+ (mon
.Obj
.Rect
.Height
div 2);
6919 Target
.Rect
:= mon
.Obj
.Rect
;
6920 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6921 Target
.Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6922 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6923 Target
.IsPlayer
:= False;
6930 begin // Öåëè íåò - îáíóëÿåì
6935 Target
.Visible
:= False;
6936 Target
.Line
:= False;
6937 Target
.IsPlayer
:= False;
6942 // Åñëè öåëü íå âèäèìà èëè íå íà ëèíèè îãíÿ, òî èùåì âñå âîçìîæíûå öåëè:
6943 if (not Target
.Line
) or (not Target
.Visible
) then
6947 for a
:= 0 to High(gPlayers
) do
6948 if (gPlayers
[a
] <> nil) and (gPlayers
[a
].alive
) and
6949 (gPlayers
[a
].FUID
<> FUID
) and
6950 (not SameTeam(FUID
, gPlayers
[a
].FUID
)) and
6951 (not gPlayers
[a
].NoTarget
) and
6952 (gPlayers
[a
].FMegaRulez
[MR_INVIS
] < gTime
) then
6954 if not TargetOnScreen(gPlayers
[a
].FObj
.X
+ PLAYER_RECT
.X
,
6955 gPlayers
[a
].FObj
.Y
+ PLAYER_RECT
.Y
) then
6958 x2
:= gPlayers
[a
].FObj
.X
+ PLAYER_RECT_CX
;
6959 y2
:= gPlayers
[a
].FObj
.Y
+ PLAYER_RECT_CY
;
6961 // Åñëè èãðîê íà ýêðàíå è íå ïðèêðûò ñòåíîé:
6962 if g_TraceVector(x1
, y1
, x2
, y2
) then
6964 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé:
6965 SetLength(targets
, Length(targets
)+1);
6966 with targets
[High(targets
)] do
6968 UID
:= gPlayers
[a
].FUID
;
6969 X
:= gPlayers
[a
].FObj
.X
;
6970 Y
:= gPlayers
[a
].FObj
.Y
;
6973 Rect
:= PLAYER_RECT
;
6974 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6975 Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6976 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6984 if vsMonster
then g_Mons_ForEach(monsUpdate
);
6987 // Åñëè åñòü âîçìîæíûå öåëè:
6988 // (Âûáèðàåì ëó÷øóþ, ìåíÿåì îðóæèå è áåæèì ê íåé/îò íåå)
6989 if targets
<> nil then
6991 // Âûáèðàåì íàèëó÷øóþ öåëü:
6992 BestTarget
:= targets
[0];
6993 if Length(targets
) > 1 then
6994 for a
:= 1 to High(targets
) do
6995 if Compare(BestTarget
, targets
[a
]) = 1 then
6996 BestTarget
:= targets
[a
];
6998 // Åñëè ëó÷øàÿ öåëü "âèäíåå" òåêóùåé, òî òåêóùàÿ := ëó÷øàÿ:
6999 if ((not Target
.Visible
) and BestTarget
.Visible
and (Target
.UID
<> BestTarget
.UID
)) or
7000 ((not Target
.Line
) and BestTarget
.Line
and BestTarget
.Visible
) then
7002 Target
:= BestTarget
;
7004 if (Healthy() = 3) or ((Healthy() = 2)) then
7005 begin // Åñëè çäîðîâû - äîãîíÿåì
7006 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
7007 SetAIFlag('GORIGHT', '1');
7008 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
7009 SetAIFlag('GOLEFT', '1');
7012 begin // Åñëè ïîáèòû - óáåãàåì
7013 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) then
7014 SetAIFlag('GORIGHT', '1');
7015 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
7016 SetAIFlag('GOLEFT', '1');
7019 // Âûáèðàåì îðóæèå íà îñíîâå ðàññòîÿíèÿ è ïðèîðèòåòîâ:
7020 SelectWeapon(Abs(x1
-Target
.cX
));
7025 // (Äîãîíÿåì/óáåãàåì, ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëè)
7026 // (Åñëè öåëü äàëåêî, òî õâàòèò ñëåäèòü çà íåé)
7027 if Target
.UID
<> 0 then
7029 if not TargetOnScreen(Target
.X
+ Target
.Rect
.X
,
7030 Target
.Y
+ Target
.Rect
.Y
) then
7031 begin // Öåëü ñáåæàëà ñ "ýêðàíà"
7032 if (Healthy() = 3) or ((Healthy() = 2)) then
7033 begin // Åñëè çäîðîâû - äîãîíÿåì
7034 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
7035 SetAIFlag('GORIGHT', '1');
7036 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
7037 SetAIFlag('GOLEFT', '1');
7040 begin // Åñëè ïîáèòû - çàáûâàåì î öåëè è óáåãàåì
7042 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) then
7043 SetAIFlag('GORIGHT', '1');
7044 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
7045 SetAIFlag('GOLEFT', '1');
7049 begin // Öåëü ïîêà íà "ýêðàíå"
7050 // Åñëè öåëü íå çàãîðîæåíà ñòåíîé, òî îòìå÷àåì, êîãäà åå âèäåëè:
7051 if g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
7052 FLastVisible
:= gTime
;
7053 // Åñëè ðàçíèöà âûñîò íå âåëèêà, òî äîãîíÿåì:
7054 if (Abs(FObj
.Y
-Target
.Y
) <= 128) then
7056 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
7057 SetAIFlag('GORIGHT', '1');
7058 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
7059 SetAIFlag('GOLEFT', '1');
7063 // Âûáèðàåì óãîë ââåðõ:
7064 if FDirection
= TDirection
.D_LEFT
then
7065 angle
:= ANGLE_LEFTUP
7067 angle
:= ANGLE_RIGHTUP
;
7069 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7070 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7072 // Åñëè ïðè óãëå ââåðõ ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
7073 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
7074 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128), //96
7075 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
7076 Target
.Rect
.Width
, Target
.Rect
.Height
) and
7077 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
7078 begin // òî íóæíî ñòðåëÿòü ââåðõ
7079 SetAIFlag('NEEDFIRE', '1');
7080 SetAIFlag('NEEDSEEUP', '1');
7083 // Âûáèðàåì óãîë âíèç:
7084 if FDirection
= TDirection
.D_LEFT
then
7085 angle
:= ANGLE_LEFTDOWN
7087 angle
:= ANGLE_RIGHTDOWN
;
7089 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7090 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7092 // Åñëè ïðè óãëå âíèç ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
7093 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
7094 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
7095 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
7096 Target
.Rect
.Width
, Target
.Rect
.Height
) and
7097 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
7098 begin // òî íóæíî ñòðåëÿòü âíèç
7099 SetAIFlag('NEEDFIRE', '1');
7100 SetAIFlag('NEEDSEEDOWN', '1');
7103 // Åñëè öåëü âèäíî è îíà íà òàêîé æå âûñîòå:
7104 if Target
.Visible
and
7105 (y1
+4 < Target
.Y
+Target
.Rect
.Y
+Target
.Rect
.Height
) and
7106 (y1
-4 > Target
.Y
+Target
.Rect
.Y
) then
7108 // Åñëè èäåì â ñòîðîíó öåëè, òî íàäî ñòðåëÿòü:
7109 if ((FDirection
= TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) or
7110 ((FDirection
= TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
7111 begin // òî íóæíî ñòðåëÿòü âïåðåä
7112 SetAIFlag('NEEDFIRE', '1');
7113 SetAIFlag('NEEDSEEDOWN', '');
7114 SetAIFlag('NEEDSEEUP', '');
7116 // Åñëè öåëü â ïðåäåëàõ "ýêðàíà" è ñëîæíîñòü ïîçâîëÿåò ïðûæêè ñáëèæåíèÿ:
7117 if Abs(FObj
.X
-Target
.X
) < Trunc(gPlayerScreenSize
.X
*0.75) then
7118 if GetRnd(FDifficult
.CloseJump
) then
7119 begin // òî åñëè ïîâåçåò - ïðûãàåì (îñîáåííî, åñëè áëèçêî)
7120 if Abs(FObj
.X
-Target
.X
) < 128 then
7124 if Random(a
) = 0 then
7125 SetAIFlag('NEEDJUMP', '1');
7129 // Åñëè öåëü âñå åùå åñòü:
7130 if Target
.UID
<> 0 then
7131 if gTime
-FLastVisible
> 2000 then // Åñëè âèäåëè äàâíî
7132 Target
.UID
:= 0 // òî çàáûòü öåëü
7133 else // Åñëè âèäåëè íåäàâíî
7134 begin // íî öåëü óáèëè
7135 if Target
.IsPlayer
then
7136 begin // Öåëü - èãðîê
7137 pla
:= g_Player_Get(Target
.UID
);
7138 if (pla
= nil) or (not pla
.alive
) or pla
.NoTarget
or
7139 (pla
.FMegaRulez
[MR_INVIS
] >= gTime
) then
7140 Target
.UID
:= 0; // òî çàáûòü öåëü
7143 begin // Öåëü - ìîíñòð
7144 mon
:= g_Monsters_ByUID(Target
.UID
);
7145 if (mon
= nil) or (not mon
.alive
) then
7146 Target
.UID
:= 0; // òî çàáûòü öåëü
7149 end; // if Target.UID <> 0
7151 FTargetUID
:= Target
.UID
;
7153 // Åñëè âîçìîæíûõ öåëåé íåò:
7154 // (Àòàêà ÷åãî-íèáóäü ñëåâà èëè ñïðàâà)
7155 if targets
= nil then
7156 if GetAIFlag('ATTACKLEFT') <> '' then
7157 begin // Åñëè íóæíî àòàêîâàòü íàëåâî
7158 RemoveAIFlag('ATTACKLEFT');
7160 SetAIFlag('NEEDJUMP', '1');
7162 if RunDirection() = TDirection
.D_RIGHT
then
7163 begin // Èäåì íå â òó ñòîðîíó
7164 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
7165 begin // Åñëè çäîðîâû, òî, âîçìîæíî, ñòðåëÿåì áåæèì âëåâî è ñòðåëÿåì
7166 SetAIFlag('NEEDFIRE', '1');
7167 SetAIFlag('GOLEFT', '1');
7171 begin // Èäåì â íóæíóþ ñòîðîíó
7172 if GetRnd(FDifficult
.InvisFire
) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
7173 SetAIFlag('NEEDFIRE', '1');
7174 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
7175 SetAIFlag('GORIGHT', '1');
7179 if GetAIFlag('ATTACKRIGHT') <> '' then
7180 begin // Åñëè íóæíî àòàêîâàòü íàïðàâî
7181 RemoveAIFlag('ATTACKRIGHT');
7183 SetAIFlag('NEEDJUMP', '1');
7185 if RunDirection() = TDirection
.D_LEFT
then
7186 begin // Èäåì íå â òó ñòîðîíó
7187 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
7188 begin // Åñëè çäîðîâû, òî, âîçìîæíî, áåæèì âïðàâî è ñòðåëÿåì
7189 SetAIFlag('NEEDFIRE', '1');
7190 SetAIFlag('GORIGHT', '1');
7195 if GetRnd(FDifficult
.InvisFire
) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
7196 SetAIFlag('NEEDFIRE', '1');
7197 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
7198 SetAIFlag('GOLEFT', '1');
7202 //HACK! (does it belongs there?)
7203 RealizeCurrentWeapon();
7205 // Åñëè åñòü âîçìîæíûå öåëè:
7206 // (Ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëÿì)
7207 if (targets
<> nil) and (GetAIFlag('NEEDFIRE') <> '') then
7208 for a
:= 0 to High(targets
) do
7210 // Åñëè ìîæåì ñòðåëÿòü ïî äèàãîíàëè:
7211 if GetRnd(FDifficult
.DiagFire
) then
7213 // Èùåì öåëü ñâåðõó è ñòðåëÿåì, åñëè åñòü:
7214 if FDirection
= TDirection
.D_LEFT
then
7215 angle
:= ANGLE_LEFTUP
7217 angle
:= ANGLE_RIGHTUP
;
7219 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7220 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7222 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
7223 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
7224 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
7225 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
7226 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
7228 SetAIFlag('NEEDFIRE', '1');
7229 SetAIFlag('NEEDSEEUP', '1');
7232 // Èùåì öåëü ñíèçó è ñòðåëÿåì, åñëè åñòü:
7233 if FDirection
= TDirection
.D_LEFT
then
7234 angle
:= ANGLE_LEFTDOWN
7236 angle
:= ANGLE_RIGHTDOWN
;
7238 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7239 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7241 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
7242 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
7243 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
7244 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
7245 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
7247 SetAIFlag('NEEDFIRE', '1');
7248 SetAIFlag('NEEDSEEDOWN', '1');
7252 // Åñëè öåëü "ïåðåä íîñîì", òî ñòðåëÿåì:
7253 if targets
[a
].Line
and targets
[a
].Visible
and
7254 (((FDirection
= TDirection
.D_LEFT
) and (targets
[a
].X
< FObj
.X
)) or
7255 ((FDirection
= TDirection
.D_RIGHT
) and (targets
[a
].X
> FObj
.X
))) then
7257 SetAIFlag('NEEDFIRE', '1');
7262 // Åñëè ëåòèò ïóëÿ, òî, âîçìîæíî, ïîäïðûãèâàåì:
7263 if g_Weapon_Danger(FUID
, FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
,
7264 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
,
7265 40+GetInterval(FDifficult
.Cover
, 40)) then
7266 SetAIFlag('NEEDJUMP', '1');
7268 // Åñëè êîí÷èëèñü ïàòîðíû, òî íóæíî ñìåíèòü îðóæèå:
7269 ammo
:= GetAmmoByWeapon(FCurrWeap
);
7270 if ((FCurrWeap
= WEAPON_SHOTGUN2
) and (ammo
< 2)) or
7271 ((FCurrWeap
= WEAPON_BFG
) and (ammo
< 40)) or
7273 SetAIFlag('SELECTWEAPON', '1');
7275 // Åñëè íóæíî ñìåíèòü îðóæèå, òî âûáèðàåì íóæíîå:
7276 if GetAIFlag('SELECTWEAPON') = '1' then
7279 RemoveAIFlag('SELECTWEAPON');
7283 procedure TBot
.Update();
7296 // Ïðîâåðÿåì, îòêëþ÷¸í ëè AI áîòîâ
7297 if (g_debug_BotAIOff
= 1) and (Team
= TEAM_RED
) then
7299 if (g_debug_BotAIOff
= 2) and (Team
= TEAM_BLUE
) then
7301 if g_debug_BotAIOff
= 3 then
7311 RealizeCurrentWeapon();
7318 procedure TBot
.ReleaseKey(Key
: Byte);
7327 function TBot
.KeyPressed(Key
: Word): Boolean;
7329 Result
:= FKeys
[Key
].Pressed
;
7332 function TBot
.GetAIFlag(aName
: String20
): String20
;
7338 aName
:= LowerCase(aName
);
7340 if FAIFlags
<> nil then
7341 for a
:= 0 to High(FAIFlags
) do
7342 if LowerCase(FAIFlags
[a
].Name
) = aName
then
7344 Result
:= FAIFlags
[a
].Value
;
7349 procedure TBot
.RemoveAIFlag(aName
: String20
);
7353 if FAIFlags
= nil then Exit
;
7355 aName
:= LowerCase(aName
);
7357 for a
:= 0 to High(FAIFlags
) do
7358 if LowerCase(FAIFlags
[a
].Name
) = aName
then
7360 if a
<> High(FAIFlags
) then
7361 for b
:= a
to High(FAIFlags
)-1 do
7362 FAIFlags
[b
] := FAIFlags
[b
+1];
7364 SetLength(FAIFlags
, Length(FAIFlags
)-1);
7369 procedure TBot
.SetAIFlag(aName
, fValue
: String20
);
7377 aName
:= LowerCase(aName
);
7379 if FAIFlags
<> nil then
7380 for a
:= 0 to High(FAIFlags
) do
7381 if LowerCase(FAIFlags
[a
].Name
) = aName
then
7387 if ok
then FAIFlags
[a
].Value
:= fValue
7390 SetLength(FAIFlags
, Length(FAIFlags
)+1);
7391 with FAIFlags
[High(FAIFlags
)] do
7399 procedure TBot
.UpdateMove
;
7401 procedure GoLeft(Time
: Word = 1);
7403 ReleaseKey(KEY_LEFT
);
7404 ReleaseKey(KEY_RIGHT
);
7405 PressKey(KEY_LEFT
, Time
);
7406 SetDirection(TDirection
.D_LEFT
);
7409 procedure GoRight(Time
: Word = 1);
7411 ReleaseKey(KEY_LEFT
);
7412 ReleaseKey(KEY_RIGHT
);
7413 PressKey(KEY_RIGHT
, Time
);
7414 SetDirection(TDirection
.D_RIGHT
);
7417 function Rnd(a
: Word): Boolean;
7419 Result
:= Random(a
) = 0;
7422 procedure Turn(Time
: Word = 1200);
7424 if RunDirection() = TDirection
.D_LEFT
then GoRight(Time
) else GoLeft(Time
);
7429 ReleaseKey(KEY_LEFT
);
7430 ReleaseKey(KEY_RIGHT
);
7433 function CanRunLeft(): Boolean;
7435 Result
:= not CollideLevel(-1, 0);
7438 function CanRunRight(): Boolean;
7440 Result
:= not CollideLevel(1, 0);
7443 function CanRun(): Boolean;
7445 if RunDirection() = TDirection
.D_LEFT
then Result
:= CanRunLeft() else Result
:= CanRunRight();
7448 procedure Jump(Time
: Word = 30);
7450 PressKey(KEY_JUMP
, Time
);
7453 function NearHole(): Boolean;
7457 { TODO 5 : Ëåñòíèöû }
7458 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7459 for x
:= 1 to PLAYER_RECT
.Width
do
7460 if (not StayOnStep(x
*sx
, 0)) and
7461 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7462 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7471 function BorderHole(): Boolean;
7475 { TODO 5 : Ëåñòíèöû }
7476 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7477 for x
:= 1 to PLAYER_RECT
.Width
do
7478 if (not StayOnStep(x
*sx
, 0)) and
7479 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7480 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7482 for xx
:= x
to x
+32 do
7483 if CollideLevel(xx
*sx
, PLAYER_RECT
.Height
) then
7493 function NearDeepHole(): Boolean;
7499 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7502 for x
:= 1 to PLAYER_RECT
.Width
do
7503 if (not StayOnStep(x
*sx
, 0)) and
7504 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7505 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7507 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
7509 if CollideLevel(x
*sx
, PLAYER_RECT
.Height
*y
) then Exit
;
7514 end else Result
:= False;
7517 function OverDeepHole(): Boolean;
7524 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
7526 if CollideLevel(0, PLAYER_RECT
.Height
*y
) then Exit
;
7533 function OnGround(): Boolean;
7535 Result
:= StayOnStep(0, 0) or CollideLevel(0, 1);
7538 function OnLadder(): Boolean;
7540 Result
:= FullInStep(0, 0);
7543 function BelowLadder(): Boolean;
7545 Result
:= (FullInStep(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) and
7546 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
7547 (FullInStep(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) and
7548 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
7551 function BelowLiftUp(): Boolean;
7553 Result
:= ((FullInLift(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) = -1) and
7554 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
7555 ((FullInLift(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) = -1) and
7556 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
7559 function OnTopLift(): Boolean;
7561 Result
:= (FullInLift(0, 0) = -1) and (FullInLift(0, -32) = 0);
7564 function CanJumpOver(): Boolean;
7568 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7572 if not CollideLevel(sx
, 0) then Exit
;
7574 for y
:= 1 to BOT_MAXJUMP
do
7575 if CollideLevel(0, -y
) then Exit
else
7576 if not CollideLevel(sx
, -y
) then
7583 function CanJumpUp(Dist
: ShortInt): Boolean;
7590 if CollideLevel(Dist
, 0) then Exit
;
7593 for y
:= 0 to BOT_MAXJUMP
do
7594 if CollideLevel(Dist
, -y
) then
7603 for yy
:= y
+1 to BOT_MAXJUMP
do
7604 if not CollideLevel(Dist
, -yy
) then
7613 for y
:= 0 to BOT_MAXJUMP
do
7614 if CollideLevel(0, -y
) then
7622 if y
< yy
then Exit
;
7627 function IsSafeTrigger(): Boolean;
7632 if gTriggers
= nil then
7634 for a
:= 0 to High(gTriggers
) do
7635 if Collide(gTriggers
[a
].X
,
7638 gTriggers
[a
].Height
) and
7639 (gTriggers
[a
].TriggerType
in [TRIGGER_EXIT
, TRIGGER_CLOSEDOOR
,
7640 TRIGGER_CLOSETRAP
, TRIGGER_TRAP
,
7641 TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
,
7642 TRIGGER_ONOFF
, TRIGGER_SPAWNMONSTER
,
7643 TRIGGER_DAMAGE
, TRIGGER_SHOT
]) then
7648 // Âîçìîæíî, íàæèìàåì êíîïêó:
7649 if Rnd(16) and IsSafeTrigger() then
7652 // Åñëè ïîä ëèôòîì èëè ñòóïåíüêàìè, òî, âîçìîæíî, ïðûãàåì:
7653 if OnLadder() or ((BelowLadder() or BelowLiftUp()) and Rnd(8)) then
7655 ReleaseKey(KEY_LEFT
);
7656 ReleaseKey(KEY_RIGHT
);
7660 // Èäåì âëåâî, åñëè íàäî áûëî:
7661 if GetAIFlag('GOLEFT') <> '' then
7663 RemoveAIFlag('GOLEFT');
7664 if CanRunLeft() then
7668 // Èäåì âïðàâî, åñëè íàäî áûëî:
7669 if GetAIFlag('GORIGHT') <> '' then
7671 RemoveAIFlag('GORIGHT');
7672 if CanRunRight() then
7676 // Åñëè âûëåòåëè çà êàðòó, òî ïðîáóåì âåðíóòüñÿ:
7677 if FObj
.X
< -32 then
7680 if FObj
.X
+32 > gMapInfo
.Width
then
7683 // Ïðûãàåì, åñëè íàäî áûëî:
7684 if GetAIFlag('NEEDJUMP') <> '' then
7687 RemoveAIFlag('NEEDJUMP');
7690 // Ñìîòðèì ââåðõ, åñëè íàäî áûëî:
7691 if GetAIFlag('NEEDSEEUP') <> '' then
7694 ReleaseKey(KEY_DOWN
);
7695 PressKey(KEY_UP
, 20);
7696 RemoveAIFlag('NEEDSEEUP');
7699 // Ñìîòðèì âíèç, åñëè íàäî áûëî:
7700 if GetAIFlag('NEEDSEEDOWN') <> '' then
7703 ReleaseKey(KEY_DOWN
);
7704 PressKey(KEY_DOWN
, 20);
7705 RemoveAIFlag('NEEDSEEDOWN');
7708 // Åñëè íóæíî áûëî â äûðó è ìû íå íà çåìëå, òî ïîêîðíî ëåòèì:
7709 if GetAIFlag('GOINHOLE') <> '' then
7710 if not OnGround() then
7712 ReleaseKey(KEY_LEFT
);
7713 ReleaseKey(KEY_RIGHT
);
7714 RemoveAIFlag('GOINHOLE');
7715 SetAIFlag('FALLINHOLE', '1');
7718 // Åñëè ïàäàëè è äîñòèãëè çåìëè, òî õâàòèò ïàäàòü:
7719 if GetAIFlag('FALLINHOLE') <> '' then
7721 RemoveAIFlag('FALLINHOLE');
7723 // Åñëè ëåòåëè ïðÿìî è ñåé÷àñ íå íà ëåñòíèöå èëè íà âåðøèíå ëèôòà, òî îòõîäèì â ñòîðîíó:
7724 if not (KeyPressed(KEY_LEFT
) or KeyPressed(KEY_RIGHT
)) then
7725 if GetAIFlag('FALLINHOLE') = '' then
7726 if (not OnLadder()) or (FObj
.Vel
.Y
>= 0) or (OnTopLift()) then
7732 // Åñëè íà çåìëå è ìîæíî ïîäïðûãíóòü, òî, âîçìîæíî, ïðûãàåì:
7734 CanJumpUp(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*32) and
7738 // Åñëè íà çåìëå è âîçëå äûðû (ãëóáèíà > 2 ðîñòîâ èãðîêà):
7739 if OnGround() and NearHole() then
7740 if NearDeepHole() then // Åñëè ýòî áåçäíà
7742 0..3: Turn(); // Áåæèì îáðàòíî
7743 4: Jump(); // Ïðûãàåì
7744 5: begin // Ïðûãàåì îáðàòíî
7749 else // Ýòî íå áåçäíà è ìû åùå íå ëåòèì òóäà
7750 if GetAIFlag('GOINHOLE') = '' then
7752 0: Turn(); // Íå íóæíî òóäà
7753 1: Jump(); // Âäðóã ïîâåçåò - ïðûãàåì
7754 else // Åñëè ÿìà ñ ãðàíèöåé, òî ïðè ñëó÷àå ìîæíî òóäà ïðûãíóòü
7755 if BorderHole() then
7756 SetAIFlag('GOINHOLE', '1');
7759 // Åñëè íà çåìëå, íî íåêóäà èäòè:
7760 if (not CanRun()) and OnGround() then
7762 // Åñëè ìû íà ëåñòíèöå èëè ìîæíî ïåðåïðûãíóòü, òî ïðûãàåì:
7763 if CanJumpOver() or OnLadder() then
7765 else // èíà÷å ïîïûòàåìñÿ â äðóãóþ ñòîðîíó
7766 if Random(2) = 0 then
7768 if IsSafeTrigger() then
7774 // Îñòàëîñü ìàëî âîçäóõà:
7775 if FAir
< 36 * 2 then
7778 // Âûáèðàåìñÿ èç êèñëîòû, åñëè íåò êîñòþìà, îáîæãëèñü, èëè ìàëî çäîðîâüÿ:
7779 if (FMegaRulez
[MR_SUIT
] < gTime
) and ((FLastHit
= HIT_ACID
) or (Healthy() <= 1)) then
7780 if BodyInAcid(0, 0) then
7784 function TBot
.FullInStep(XInc
, YInc
: Integer): Boolean;
7786 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
7787 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_STEP
, False);
7790 {function TBot.NeedItem(Item: Byte): Byte;
7795 procedure TBot
.SelectWeapon(Dist
: Integer);
7799 function HaveAmmo(weapon
: Byte): Boolean;
7802 WEAPON_PISTOL
: Result
:= FAmmo
[A_BULLETS
] >= 1;
7803 WEAPON_SHOTGUN1
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7804 WEAPON_SHOTGUN2
: Result
:= FAmmo
[A_SHELLS
] >= 2;
7805 WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
] >= 10;
7806 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
] >= 1;
7807 WEAPON_PLASMA
: Result
:= FAmmo
[A_CELLS
] >= 10;
7808 WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
] >= 40;
7809 WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7810 WEAPON_FLAMETHROWER
: Result
:= FAmmo
[A_FUEL
] >= 1;
7811 else Result
:= True;
7816 if Dist
= -1 then Dist
:= BOT_LONGDIST
;
7818 if Dist
> BOT_LONGDIST
then
7819 begin // Äàëüíèé áîé
7821 if FWeapon
[FDifficult
.WeaponPrior
[a
]] and HaveAmmo(FDifficult
.WeaponPrior
[a
]) then
7823 FSelectedWeapon
:= FDifficult
.WeaponPrior
[a
];
7827 else //if Dist > BOT_UNSAFEDIST then
7828 begin // Áëèæíèé áîé
7830 if FWeapon
[FDifficult
.CloseWeaponPrior
[a
]] and HaveAmmo(FDifficult
.CloseWeaponPrior
[a
]) then
7832 FSelectedWeapon
:= FDifficult
.CloseWeaponPrior
[a
];
7839 if FWeapon[FDifficult.SafeWeaponPrior[a]] and HaveAmmo(FDifficult.SafeWeaponPrior[a]) then
7841 FSelectedWeapon := FDifficult.SafeWeaponPrior[a];
7847 function TBot
.PickItem(ItemType
: Byte; force
: Boolean; var remove
: Boolean): Boolean;
7849 Result
:= inherited PickItem(ItemType
, force
, remove
);
7851 if Result
then SetAIFlag('SELECTWEAPON', '1');
7854 function TBot
.Heal(value
: Word; Soft
: Boolean): Boolean;
7856 Result
:= inherited Heal(value
, Soft
);
7859 function TBot
.Healthy(): Byte;
7861 if FMegaRulez
[MR_INVUL
] >= gTime
then Result
:= 3
7862 else if (FHealth
> 80) or ((FHealth
> 50) and (FArmor
> 20)) then Result
:= 3
7863 else if (FHealth
> 50) then Result
:= 2
7864 else if (FHealth
> 20) then Result
:= 1
7868 function TBot
.TargetOnScreen(TX
, TY
: Integer): Boolean;
7870 Result
:= (Abs(FObj
.X
-TX
) <= Trunc(gPlayerScreenSize
.X
*0.6)) and
7871 (Abs(FObj
.Y
-TY
) <= Trunc(gPlayerScreenSize
.Y
*0.6));
7874 procedure TBot
.OnDamage(Angle
: SmallInt);
7882 if (Angle
= 0) or (Angle
= 180) then
7885 if (g_GetUIDType(FLastSpawnerUID
) = UID_PLAYER
) and
7886 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
) then
7888 pla
:= g_Player_Get(FLastSpawnerUID
);
7889 ok
:= not TargetOnScreen(pla
.FObj
.X
+ PLAYER_RECT
.X
,
7890 pla
.FObj
.Y
+ PLAYER_RECT
.Y
);
7893 if (g_GetUIDType(FLastSpawnerUID
) = UID_MONSTER
) and
7894 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
) then
7896 mon
:= g_Monsters_ByUID(FLastSpawnerUID
);
7897 ok
:= not TargetOnScreen(mon
.Obj
.X
+ mon
.Obj
.Rect
.X
,
7898 mon
.Obj
.Y
+ mon
.Obj
.Rect
.Y
);
7903 SetAIFlag('ATTACKLEFT', '1')
7905 SetAIFlag('ATTACKRIGHT', '1');
7909 function TBot
.RunDirection(): TDirection
;
7911 if Abs(Vel
.X
) >= 1 then
7913 if Vel
.X
> 0 then Result
:= TDirection
.D_RIGHT
else Result
:= TDirection
.D_LEFT
;
7915 Result
:= FDirection
;
7918 function TBot
.GetRnd(a
: Byte): Boolean;
7920 if a
= 0 then Result
:= False
7921 else if a
= 255 then Result
:= True
7922 else Result
:= Random(256) > 255-a
;
7925 function TBot
.GetInterval(a
: Byte; radius
: SmallInt): SmallInt;
7927 Result
:= Round((255-a
)/255*radius
*(Random(2)-1));
7931 procedure TDifficult
.save (st
: TStream
);
7933 utils
.writeInt(st
, Byte(DiagFire
));
7934 utils
.writeInt(st
, Byte(InvisFire
));
7935 utils
.writeInt(st
, Byte(DiagPrecision
));
7936 utils
.writeInt(st
, Byte(FlyPrecision
));
7937 utils
.writeInt(st
, Byte(Cover
));
7938 utils
.writeInt(st
, Byte(CloseJump
));
7939 st
.WriteBuffer(WeaponPrior
[Low(WeaponPrior
)], sizeof(WeaponPrior
));
7940 st
.WriteBuffer(CloseWeaponPrior
[Low(CloseWeaponPrior
)], sizeof(CloseWeaponPrior
));
7943 procedure TDifficult
.load (st
: TStream
);
7945 DiagFire
:= utils
.readByte(st
);
7946 InvisFire
:= utils
.readByte(st
);
7947 DiagPrecision
:= utils
.readByte(st
);
7948 FlyPrecision
:= utils
.readByte(st
);
7949 Cover
:= utils
.readByte(st
);
7950 CloseJump
:= utils
.readByte(st
);
7951 st
.ReadBuffer(WeaponPrior
[Low(WeaponPrior
)], sizeof(WeaponPrior
));
7952 st
.ReadBuffer(CloseWeaponPrior
[Low(CloseWeaponPrior
)], sizeof(CloseWeaponPrior
));
7956 procedure TBot
.SaveState (st
: TStream
);
7961 inherited SaveState(st
);
7962 utils
.writeSign(st
, 'BOT0');
7964 utils
.writeInt(st
, Byte(FSelectedWeapon
));
7966 utils
.writeInt(st
, Word(FTargetUID
));
7967 // Âðåìÿ ïîòåðè öåëè
7968 utils
.writeInt(st
, LongWord(FLastVisible
));
7969 // Êîëè÷åñòâî ôëàãîâ ÈÈ
7970 dw
:= Length(FAIFlags
);
7971 utils
.writeInt(st
, LongInt(dw
));
7973 for i
:= 0 to dw
-1 do
7975 utils
.writeStr(st
, FAIFlags
[i
].Name
, 20);
7976 utils
.writeStr(st
, FAIFlags
[i
].Value
, 20);
7978 // Íàñòðîéêè ñëîæíîñòè
7979 FDifficult
.save(st
);
7983 procedure TBot
.LoadState (st
: TStream
);
7988 inherited LoadState(st
);
7989 if not utils
.checkSign(st
, 'BOT0') then raise XStreamError
.Create('invalid bot signature');
7991 FSelectedWeapon
:= utils
.readByte(st
);
7993 FTargetUID
:= utils
.readWord(st
);
7994 // Âðåìÿ ïîòåðè öåëè
7995 FLastVisible
:= utils
.readLongWord(st
);
7996 // Êîëè÷åñòâî ôëàãîâ ÈÈ
7997 dw
:= utils
.readLongInt(st
);
7998 if (dw
< 0) or (dw
> 16384) then raise XStreamError
.Create('invalid number of bot AI flags');
7999 SetLength(FAIFlags
, dw
);
8001 for i
:= 0 to dw
-1 do
8003 FAIFlags
[i
].Name
:= utils
.readStr(st
, 20);
8004 FAIFlags
[i
].Value
:= utils
.readStr(st
, 20);
8006 // Íàñòðîéêè ñëîæíîñòè
8007 FDifficult
.load(st
);
8012 conRegVar('cheat_berserk_autoswitch', @gBerserkAutoswitch
, 'autoswitch to fist when berserk pack taken', '', true, true);
8013 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');
8014 conRegVar('player_indicator_style', @gPlayerIndicatorStyle
, 'Visual appearance of indicator', 'Visual appearance of indicator');
8015 conRegVar('weapon_autoswitch', @gWeaponAutoswitch
, 'Automatically switch to a first time picked up weapon', '');