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, either version 3 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 {$INCLUDE ../shared/a_modes.inc}
24 {$IFDEF USE_MEMPOOL}mempool
,{$ENDIF}
25 e_graphics
, g_playermodel
, g_basic
, g_textures
,
26 g_weapons
, g_phys
, g_sound
, g_saveload
, MAPDEF
,
59 AmmoLimits
: Array [0..1] of Array [A_BULLETS
..A_HIGH
] of Word =
60 ((200, 50, 50, 300, 100),
61 (400, 100, 100, 600, 200));
82 ANGLE_NONE
= Low(SmallInt);
84 CORPSE_STATE_REMOVEME
= 0;
85 CORPSE_STATE_NORMAL
= 1;
86 CORPSE_STATE_MESS
= 2;
88 PLAYER_RECT
: TRectWH
= (X
:15; Y
:12; Width
:34; Height
:52);
89 PLAYER_RECT_CX
= 15+(34 div 2);
90 PLAYER_RECT_CY
= 12+(52 div 2);
91 PLAYER_CORPSERECT
: TRectWH
= (X
:15; Y
:48; Width
:34; Height
:16);
94 PLAYER_HP_LIMIT
= 200;
96 PLAYER_AP_LIMIT
= 200;
100 PLAYER1_DEF_COLOR
: TRGB
= (R
:64; G
:175; B
:48);
101 PLAYER2_DEF_COLOR
: TRGB
= (R
:96; G
:96; B
:96);
117 TPlayerStatArray
= Array of TPlayerStat
;
119 TPlayerSavedState
= record
127 Ammo
: Array [A_BULLETS
..A_HIGH
] of Word;
128 MaxAmmo
: Array [A_BULLETS
..A_HIGH
] of Word;
129 Weapon
: Array [WP_FIRST
..WP_LAST
] of Boolean;
130 Rulez
: Set of R_ITEM_BACKPACK
..R_BERSERK
;
139 TPlayer
= class{$IFDEF USE_MEMPOOL}(TPoolObject
){$ENDIF}
147 FDirection
: TDirection
;
155 FMonsterKills
: Integer;
161 FCanJetpack
: Boolean;
167 FNextWeapDelay
: Byte; // frames
168 FBFGFireCounter
: SmallInt;
169 FLastSpawnerUID
: Word;
173 FSpectatePlayer
: Integer;
174 FFirePainTime
: Integer;
177 FSavedState
: TPlayerSavedState
;
179 FModel
: TPlayerModel
;
180 FPunchAnim
: TAnimation
;
183 FActionForce
: Boolean;
184 FActionChanged
: Boolean;
186 FFireAngle
: SmallInt;
188 FShellTimer
: Integer;
190 FSawSound
: TPlayableSound
;
191 FSawSoundIdle
: TPlayableSound
;
192 FSawSoundHit
: TPlayableSound
;
193 FSawSoundSelect
: TPlayableSound
;
194 FFlameSoundOn
: TPlayableSound
;
195 FFlameSoundOff
: TPlayableSound
;
196 FFlameSoundWork
: TPlayableSound
;
197 FJetSoundOn
: TPlayableSound
;
198 FJetSoundOff
: TPlayableSound
;
199 FJetSoundFly
: TPlayableSound
;
203 FJustTeleported
: Boolean;
205 mEDamageType
: Integer;
208 function CollideLevel(XInc
, YInc
: Integer): Boolean;
209 function StayOnStep(XInc
, YInc
: Integer): Boolean;
210 function HeadInLiquid(XInc
, YInc
: Integer): Boolean;
211 function BodyInLiquid(XInc
, YInc
: Integer): Boolean;
212 function BodyInAcid(XInc
, YInc
: Integer): Boolean;
213 function FullInLift(XInc
, YInc
: Integer): Integer;
214 {procedure CollideItem();}
215 procedure FlySmoke(Times
: DWORD
= 1);
216 procedure OnFireFlame(Times
: DWORD
= 1);
217 function GetAmmoByWeapon(Weapon
: Byte): Word;
218 procedure SetAction(Action
: Byte; Force
: Boolean = False);
219 procedure OnDamage(Angle
: SmallInt); virtual;
220 function firediry(): Integer;
223 procedure Run(Direction
: TDirection
);
224 procedure NextWeapon();
225 procedure PrevWeapon();
232 function getNextWeaponIndex (): Byte; // return 255 for "no switch"
233 procedure resetWeaponQueue ();
234 function hasAmmoForWeapon (weapon
: Byte): Boolean;
236 procedure doDamage (v
: Integer);
238 function followCorpse(): Boolean;
241 FDamageBuffer
: Integer;
243 FAmmo
: Array [A_BULLETS
..A_HIGH
] of Word;
244 FMaxAmmo
: Array [A_BULLETS
..A_HIGH
] of Word;
245 FWeapon
: Array [WP_FIRST
..WP_LAST
] of Boolean;
246 FRulez
: Set of R_ITEM_BACKPACK
..R_BERSERK
;
248 FMegaRulez
: Array [MR_SUIT
..MR_MAX
] of DWORD
;
249 FReloading
: Array [WP_FIRST
..WP_LAST
] of Word;
250 FTime
: Array [T_RESPAWN
..T_FLAGCAP
] of DWORD
;
251 FKeys
: Array [KEY_LEFT
..KEY_CHAT
] of TKeyState
;
253 FPreferredTeam
: Byte;
256 FWantsInGame
: Boolean;
261 FActualModelName
: string;
268 // debug: viewport offset
269 viewPortX
, viewPortY
, viewPortW
, viewPortH
: Integer;
271 function isValidViewPort (): Boolean; inline;
273 constructor Create(); virtual;
274 destructor Destroy(); override;
275 procedure Respawn(Silent
: Boolean; Force
: Boolean = False); virtual;
276 function GetRespawnPoint(): Byte;
277 procedure PressKey(Key
: Byte; Time
: Word = 1);
278 procedure ReleaseKeys();
279 procedure SetModel(ModelName
: String);
280 procedure SetColor(Color
: TRGB
);
281 procedure SetWeapon(W
: Byte);
282 function IsKeyPressed(K
: Byte): Boolean;
283 function GetKeys(): Byte;
284 function PickItem(ItemType
: Byte; arespawn
: Boolean; var remove
: Boolean): Boolean; virtual;
285 function Collide(X
, Y
: Integer; Width
, Height
: Word): Boolean; overload
;
286 function Collide(Panel
: TPanel
): Boolean; overload
;
287 function Collide(X
, Y
: Integer): Boolean; overload
;
288 procedure SetDirection(Direction
: TDirection
);
289 procedure GetSecret();
290 function TeleportTo(X
, Y
: Integer; silent
: Boolean; dir
: Byte): Boolean;
292 procedure Push(vx
, vy
: Integer);
293 procedure ChangeModel(ModelName
: String);
294 procedure SwitchTeam
;
295 procedure ChangeTeam(Team
: Byte);
297 function GetFlag(Flag
: Byte): Boolean;
298 procedure SetFlag(Flag
: Byte);
299 function DropFlag(Silent
: Boolean = True): Boolean;
300 procedure AllRulez(Health
: Boolean);
301 procedure RestoreHealthArmor();
302 procedure FragCombo();
303 procedure GiveItem(ItemType
: Byte);
304 procedure Damage(value
: Word; SpawnerUID
: Word; vx
, vy
: Integer; t
: Byte); virtual;
305 function Heal(value
: Word; Soft
: Boolean): Boolean; virtual;
306 procedure MakeBloodVector(Count
: Word; VelX
, VelY
: Integer);
307 procedure MakeBloodSimple(Count
: Word);
308 procedure Kill(KillType
: Byte; SpawnerUID
: Word; t
: Byte);
309 procedure Reset(Force
: Boolean);
310 procedure Spectate(NoMove
: Boolean = False);
311 procedure SwitchNoClip
;
312 procedure SoftReset();
313 procedure Draw(); virtual;
314 procedure DrawPain();
315 procedure DrawPickup();
316 procedure DrawRulez();
318 procedure DrawIndicator();
319 procedure DrawBubble();
321 procedure Update(); virtual;
322 procedure RememberState();
323 procedure RecallState();
324 procedure SaveState (st
: TStream
); virtual;
325 procedure LoadState (st
: TStream
); virtual;
326 procedure PauseSounds(Enable
: Boolean);
327 procedure NetFire(Wpn
: Byte; X
, Y
, AX
, AY
: Integer; WID
: Integer = -1);
328 procedure DoLerp(Level
: Integer = 2);
329 procedure SetLerp(XTo
, YTo
: Integer);
330 procedure QueueWeaponSwitch(Weapon
: Byte);
331 procedure RealizeCurrentWeapon();
335 procedure JetpackOff
;
336 procedure CatchFire(Attacker
: Word);
338 //WARNING! this does nothing for now, but still call it!
339 procedure positionChanged (); //WARNING! call this after entity position was changed, or coldet will not work right!
341 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
342 procedure moveBy (dx
, dy
: Integer); inline;
345 property Vel
: TPoint2i read FObj
.Vel
;
346 property Obj
: TObj read FObj
;
348 property Name
: String read FName write FName
;
349 property Model
: TPlayerModel read FModel
;
350 property Health
: Integer read FHealth write FHealth
;
351 property Lives
: Byte read FLives write FLives
;
352 property Armor
: Integer read FArmor write FArmor
;
353 property Air
: Integer read FAir write FAir
;
354 property JetFuel
: Integer read FJetFuel write FJetFuel
;
355 property Frags
: Integer read FFrags write FFrags
;
356 property Death
: Integer read FDeath write FDeath
;
357 property Kills
: Integer read FKills write FKills
;
358 property CurrWeap
: Byte read FCurrWeap write FCurrWeap
;
359 property MonsterKills
: Integer read FMonsterKills write FMonsterKills
;
360 property Secrets
: Integer read FSecrets
;
361 property GodMode
: Boolean read FGodMode write FGodMode
;
362 property NoTarget
: Boolean read FNoTarget write FNoTarget
;
363 property NoReload
: Boolean read FNoReload write FNoReload
;
364 property alive
: Boolean read FAlive write FAlive
;
365 property Flag
: Byte read FFlag
;
366 property Team
: Byte read FTeam write FTeam
;
367 property Direction
: TDirection read FDirection
;
368 property GameX
: Integer read FObj
.X write FObj
.X
;
369 property GameY
: Integer read FObj
.Y write FObj
.Y
;
370 property GameVelX
: Integer read FObj
.Vel
.X write FObj
.Vel
.X
;
371 property GameVelY
: Integer read FObj
.Vel
.Y write FObj
.Vel
.Y
;
372 property GameAccelX
: Integer read FObj
.Accel
.X write FObj
.Accel
.X
;
373 property GameAccelY
: Integer read FObj
.Accel
.Y write FObj
.Accel
.Y
;
374 property IncCam
: Integer read FIncCam write FIncCam
;
375 property UID
: Word read FUID write FUID
;
376 property JustTeleported
: Boolean read FJustTeleported write FJustTeleported
;
377 property NetTime
: LongWord read FNetTime write FNetTime
;
380 property eName
: String read FName write FName
;
381 property eHealth
: Integer read FHealth write FHealth
;
382 property eLives
: Byte read FLives write FLives
;
383 property eArmor
: Integer read FArmor write FArmor
;
384 property eAir
: Integer read FAir write FAir
;
385 property eJetFuel
: Integer read FJetFuel write FJetFuel
;
386 property eFrags
: Integer read FFrags write FFrags
;
387 property eDeath
: Integer read FDeath write FDeath
;
388 property eKills
: Integer read FKills write FKills
;
389 property eCurrWeap
: Byte read FCurrWeap write FCurrWeap
;
390 property eMonsterKills
: Integer read FMonsterKills write FMonsterKills
;
391 property eSecrets
: Integer read FSecrets write FSecrets
;
392 property eGodMode
: Boolean read FGodMode write FGodMode
;
393 property eNoTarget
: Boolean read FNoTarget write FNoTarget
;
394 property eNoReload
: Boolean read FNoReload write FNoReload
;
395 property eAlive
: Boolean read FAlive write FAlive
;
396 property eFlag
: Byte read FFlag
;
397 property eTeam
: Byte read FTeam write FTeam
;
398 property eDirection
: TDirection read FDirection
;
399 property eGameX
: Integer read FObj
.X write FObj
.X
;
400 property eGameY
: Integer read FObj
.Y write FObj
.Y
;
401 property eGameVelX
: Integer read FObj
.Vel
.X write FObj
.Vel
.X
;
402 property eGameVelY
: Integer read FObj
.Vel
.Y write FObj
.Vel
.Y
;
403 property eGameAccelX
: Integer read FObj
.Accel
.X write FObj
.Accel
.X
;
404 property eGameAccelY
: Integer read FObj
.Accel
.Y write FObj
.Accel
.Y
;
405 property eIncCam
: Integer read FIncCam write FIncCam
;
406 property eUID
: Word read FUID
;
407 property eJustTeleported
: Boolean read FJustTeleported
;
408 property eNetTime
: LongWord read FNetTime
;
410 // set this before assigning something to `eDamage`
411 property eDamageType
: Integer read mEDamageType write mEDamageType
;
412 property eDamage
: Integer write doDamage
;
423 WeaponPrior
: packed array [WP_FIRST
..WP_LAST
] of Byte;
424 CloseWeaponPrior
: packed array [WP_FIRST
..WP_LAST
] of Byte;
425 //SafeWeaponPrior: Array [WP_FIRST..WP_LAST] of Byte;
428 procedure save (st
: TStream
);
429 procedure load (st
: TStream
);
437 TBot
= class(TPlayer
)
439 FSelectedWeapon
: Byte;
442 FAIFlags
: Array of TAIFlag
;
443 FDifficult
: TDifficult
;
445 function GetRnd(a
: Byte): Boolean;
446 function GetInterval(a
: Byte; radius
: SmallInt): SmallInt;
447 function RunDirection(): TDirection
;
448 function FullInStep(XInc
, YInc
: Integer): Boolean;
449 //function NeedItem(Item: Byte): Byte;
450 procedure SelectWeapon(Dist
: Integer);
451 procedure SetAIFlag(aName
, fValue
: String20
);
452 function GetAIFlag(aName
: String20
): String20
;
453 procedure RemoveAIFlag(aName
: String20
);
454 function Healthy(): Byte;
455 procedure UpdateMove();
456 procedure UpdateCombat();
457 function KeyPressed(Key
: Word): Boolean;
458 procedure ReleaseKey(Key
: Byte);
459 function TargetOnScreen(TX
, TY
: Integer): Boolean;
460 procedure OnDamage(Angle
: SmallInt); override;
463 procedure Respawn(Silent
: Boolean; Force
: Boolean = False); override;
464 constructor Create(); override;
465 destructor Destroy(); override;
466 procedure Draw(); override;
467 function PickItem(ItemType
: Byte; force
: Boolean; var remove
: Boolean): Boolean; override;
468 function Heal(value
: Word; Soft
: Boolean): Boolean; override;
469 procedure Update(); override;
470 procedure SaveState (st
: TStream
); override;
471 procedure LoadState (st
: TStream
); override;
483 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
484 procedure moveBy (dx
, dy
: Integer); inline;
486 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
500 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
501 procedure moveBy (dx
, dy
: Integer); inline;
503 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
506 TCorpse
= class{$IFDEF USE_MEMPOOL}(TPoolObject
){$ENDIF}
515 FAnimation
: TAnimation
;
516 FAnimationMask
: TAnimation
;
519 constructor Create(X
, Y
: Integer; ModelName
: String; aMess
: Boolean);
520 destructor Destroy(); override;
521 procedure Damage(Value
: Word; vx
, vy
: Integer);
524 procedure SaveState (st
: TStream
);
525 procedure LoadState (st
: TStream
);
527 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
528 procedure moveBy (dx
, dy
: Integer); inline;
530 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
532 function ObjPtr (): PObj
; inline;
534 property Obj
: TObj read FObj
; // copies object
535 property State
: Byte read FState
;
536 property Mess
: Boolean read FMess
;
539 TTeamStat
= Array [TEAM_RED
..TEAM_BLUE
] of
545 gPlayers
: Array of TPlayer
;
546 gCorpses
: Array of TCorpse
;
547 gGibs
: Array of TGib
;
548 gShells
: Array of TShell
;
549 gTeamStat
: TTeamStat
;
550 gFly
: Boolean = False;
551 gAimLine
: Boolean = False;
552 gChatBubble
: Byte = 0;
553 gPlayerIndicator
: Boolean = True;
557 MAX_RUNVEL
: Integer = 8;
558 VEL_JUMP
: Integer = 10;
559 SHELL_TIMEOUT
: Cardinal = 60000;
561 function Lerp(X
, Y
, Factor
: Integer): Integer;
563 procedure g_Gibs_SetMax(Count
: Word);
564 function g_Gibs_GetMax(): Word;
565 procedure g_Corpses_SetMax(Count
: Word);
566 function g_Corpses_GetMax(): Word;
567 procedure g_Shells_SetMax(Count
: Word);
568 function g_Shells_GetMax(): Word;
570 procedure g_Player_Init();
571 procedure g_Player_Free();
572 function g_Player_Create(ModelName
: String; Color
: TRGB
; Team
: Byte; Bot
: Boolean): Word;
573 function g_Player_CreateFromState (st
: TStream
): Word;
574 procedure g_Player_Remove(UID
: Word);
575 procedure g_Player_ResetTeams();
576 procedure g_Player_UpdateAll();
577 procedure g_Player_DrawAll();
578 procedure g_Player_DrawDebug(p
: TPlayer
);
579 procedure g_Player_DrawHealth();
580 procedure g_Player_RememberAll();
581 procedure g_Player_ResetAll(Force
, Silent
: Boolean);
582 function g_Player_Get(UID
: Word): TPlayer
;
583 function g_Player_GetCount(): Byte;
584 function g_Player_GetStats(): TPlayerStatArray
;
585 function g_Player_ValidName(Name
: String): Boolean;
586 procedure g_Player_CreateCorpse(Player
: TPlayer
);
587 procedure g_Player_CreateGibs(fX
, fY
: Integer; ModelName
: String; fColor
: TRGB
);
588 procedure g_Player_CreateShell(fX
, fY
, dX
, dY
: Integer; T
: Byte);
589 procedure g_Player_UpdatePhysicalObjects();
590 procedure g_Player_DrawCorpses();
591 procedure g_Player_DrawShells();
592 procedure g_Player_RemoveAllCorpses();
593 procedure g_Player_Corpses_SaveState (st
: TStream
);
594 procedure g_Player_Corpses_LoadState (st
: TStream
);
595 procedure g_Bot_Add(Team
, Difficult
: Byte);
596 procedure g_Bot_AddList(Team
: Byte; lname
: ShortString; num
: Integer = -1);
597 procedure g_Bot_MixNames();
598 procedure g_Bot_RemoveAll();
603 {$INCLUDE ../nogl/noGLuses.inc}
604 {$IFDEF ENABLE_HOLMES}
607 e_log
, g_map
, g_items
, g_console
, g_gfx
, Math
,
608 g_options
, g_triggers
, g_menu
, g_game
, g_grid
,
609 wadreader
, g_main
, g_monsters
, CONFIG
, g_language
,
610 g_net
, g_netmsg
, g_window
,
613 const PLR_SAVE_VERSION
= 0;
623 diag_precision
: Byte;
627 w_prior1
: Array [WP_FIRST
..WP_LAST
] of Byte;
628 w_prior2
: Array [WP_FIRST
..WP_LAST
] of Byte;
629 w_prior3
: Array [WP_FIRST
..WP_LAST
] of Byte;
633 TIME_RESPAWN1
= 1500;
634 TIME_RESPAWN2
= 2000;
635 TIME_RESPAWN3
= 3000;
638 JET_MAX
= 540; // ~30 sec
639 PLAYER_SUIT_TIME
= 30000;
640 PLAYER_INVUL_TIME
= 30000;
641 PLAYER_INVIS_TIME
= 35000;
642 FRAG_COMBO_TIME
= 3000;
646 ANGLE_RIGHTDOWN
= -35;
648 ANGLE_LEFTDOWN
= -145;
649 PLAYER_HEADRECT
: TRectWH
= (X
:24; Y
:12; Width
:20; Height
:12);
650 WEAPONPOINT
: Array [TDirection
] of TDFPoint
= ((X
:16; Y
:32), (X
:47; Y
:32));
653 BOT_UNSAFEDIST
= 128;
654 TEAMCOLOR
: Array [TEAM_RED
..TEAM_BLUE
] of TRGB
= ((R
:255; G
:0; B
:0),
656 DIFFICULT_EASY
: TDifficult
= (DiagFire
: 32; InvisFire
: 32; DiagPrecision
: 32;
657 FlyPrecision
: 32; Cover
: 32; CloseJump
: 32;
658 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
659 DIFFICULT_MEDIUM
: TDifficult
= (DiagFire
: 127; InvisFire
: 127; DiagPrecision
: 127;
660 FlyPrecision
: 127; Cover
: 127; CloseJump
: 127;
661 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
662 DIFFICULT_HARD
: TDifficult
= (DiagFire
: 255; InvisFire
: 255; DiagPrecision
: 255;
663 FlyPrecision
: 255; Cover
: 255; CloseJump
: 255;
664 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
665 WEAPON_PRIOR1
: Array [WP_FIRST
..WP_LAST
] of Byte =
666 (WEAPON_FLAMETHROWER
, WEAPON_SUPERPULEMET
,
667 WEAPON_SHOTGUN2
, WEAPON_SHOTGUN1
,
668 WEAPON_CHAINGUN
, WEAPON_PLASMA
, WEAPON_ROCKETLAUNCHER
,
669 WEAPON_BFG
, WEAPON_PISTOL
, WEAPON_SAW
, WEAPON_KASTET
);
670 WEAPON_PRIOR2
: Array [WP_FIRST
..WP_LAST
] of Byte =
671 (WEAPON_FLAMETHROWER
, WEAPON_SUPERPULEMET
,
672 WEAPON_BFG
, WEAPON_ROCKETLAUNCHER
,
673 WEAPON_SHOTGUN2
, WEAPON_PLASMA
, WEAPON_SHOTGUN1
,
674 WEAPON_CHAINGUN
, WEAPON_PISTOL
, WEAPON_SAW
, WEAPON_KASTET
);
675 //WEAPON_PRIOR3: Array [WP_FIRST..WP_LAST] of Byte =
676 // (WEAPON_FLAMETHROWER, WEAPON_SUPERPULEMET,
677 // WEAPON_BFG, WEAPON_PLASMA, WEAPON_SHOTGUN2,
678 // WEAPON_CHAINGUN, WEAPON_SHOTGUN1, WEAPON_SAW,
679 // WEAPON_ROCKETLAUNCHER, WEAPON_PISTOL, WEAPON_KASTET);
680 WEAPON_RELOAD
: Array [WP_FIRST
..WP_LAST
] of Byte =
681 (5, 2, 6, 18, 36, 2, 12, 2, 14, 2, 2);
683 PLAYER_SIGNATURE
= $52594C50; // 'PLYR'
684 CORPSE_SIGNATURE
= $50524F43; // 'CORP'
686 BOTNAMES_FILENAME
= 'botnames.txt';
687 BOTLIST_FILENAME
= 'botlist.txt';
691 MaxCorpses
: Word = 20;
692 MaxShells
: Word = 300;
693 CurrentGib
: Integer = 0;
694 CurrentShell
: Integer = 0;
695 BotNames
: Array of String;
696 BotList
: Array of TBotProfile
;
699 function Lerp(X
, Y
, Factor
: Integer): Integer;
701 Result
:= X
+ ((Y
- X
) div Factor
);
704 function SameTeam(UID1
, UID2
: Word): Boolean;
708 if (UID1
> UID_MAX_PLAYER
) or (UID1
<= UID_MAX_GAME
) or
709 (UID2
> UID_MAX_PLAYER
) or (UID2
<= UID_MAX_GAME
) then Exit
;
711 if (g_Player_Get(UID1
) = nil) or (g_Player_Get(UID2
) = nil) then Exit
;
713 if ((g_Player_Get(UID1
).Team
= TEAM_NONE
) or
714 (g_Player_Get(UID2
).Team
= TEAM_NONE
)) then Exit
;
716 Result
:= g_Player_Get(UID1
).FTeam
= g_Player_Get(UID2
).FTeam
;
719 procedure g_Gibs_SetMax(Count
: Word);
722 SetLength(gGibs
, Count
);
724 if CurrentGib
>= Count
then
728 function g_Gibs_GetMax(): Word;
733 procedure g_Shells_SetMax(Count
: Word);
736 SetLength(gShells
, Count
);
738 if CurrentShell
>= Count
then
742 function g_Shells_GetMax(): Word;
748 procedure g_Corpses_SetMax(Count
: Word);
751 SetLength(gCorpses
, Count
);
754 function g_Corpses_GetMax(): Word;
756 Result
:= MaxCorpses
;
759 function g_Player_Create(ModelName
: String; Color
: TRGB
; Team
: Byte; Bot
: Boolean): Word;
769 // Åñòü ëè ìåñòî â gPlayers:
770 if gPlayers
<> nil then
771 for a
:= 0 to High(gPlayers
) do
772 if gPlayers
[a
] = nil then
778 // Íåò ìåñòà - ðàñøèðÿåì gPlayers:
781 SetLength(gPlayers
, Length(gPlayers
)+1);
785 // Ñîçäàåì îáúåêò èãðîêà:
787 gPlayers
[a
] := TBot
.Create()
789 gPlayers
[a
] := TPlayer
.Create();
792 gPlayers
[a
].FActualModelName
:= ModelName
;
793 gPlayers
[a
].SetModel(ModelName
);
795 // Íåò ìîäåëè - ñîçäàíèå íå âîçìîæíî:
796 if gPlayers
[a
].FModel
= nil then
800 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], [ModelName
]));
804 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
805 if Random(2) = 0 then
809 gPlayers
[a
].FPreferredTeam
:= Team
;
811 case gGameSettings
.GameMode
of
812 GM_DM
: gPlayers
[a
].FTeam
:= TEAM_NONE
;
814 GM_CTF
: gPlayers
[a
].FTeam
:= gPlayers
[a
].FPreferredTeam
;
816 GM_COOP
: gPlayers
[a
].FTeam
:= TEAM_COOP
;
819 // Åñëè êîìàíäíàÿ èãðà - êðàñèì ìîäåëü â öâåò êîìàíäû:
820 gPlayers
[a
].FColor
:= Color
;
821 if gPlayers
[a
].FTeam
in [TEAM_RED
, TEAM_BLUE
] then
822 gPlayers
[a
].FModel
.Color
:= TEAMCOLOR
[gPlayers
[a
].FTeam
]
824 gPlayers
[a
].FModel
.Color
:= Color
;
826 gPlayers
[a
].FUID
:= g_CreateUID(UID_PLAYER
);
827 gPlayers
[a
].FAlive
:= False;
829 Result
:= gPlayers
[a
].FUID
;
832 function g_Player_CreateFromState (st
: TStream
): Word;
839 if (st
= nil) then exit
; //???
842 if not utils
.checkSign(st
, 'PLYR') then raise XStreamError
.Create('invalid player signature');
843 if (utils
.readByte(st
) <> PLR_SAVE_VERSION
) then raise XStreamError
.Create('invalid player version');
846 Bot
:= utils
.readBool(st
);
851 // Åñòü ëè ìåñòî â gPlayers:
852 for a
:= 0 to High(gPlayers
) do if (gPlayers
[a
] = nil) then begin ok
:= true; break
; end;
854 // Íåò ìåñòà - ðàñøèðÿåì gPlayers
857 SetLength(gPlayers
, Length(gPlayers
)+1);
861 // Ñîçäàåì îáúåêò èãðîêà
863 gPlayers
[a
] := TBot
.Create()
865 gPlayers
[a
] := TPlayer
.Create();
866 gPlayers
[a
].FIamBot
:= Bot
;
867 gPlayers
[a
].FPhysics
:= True;
870 gPlayers
[a
].FUID
:= utils
.readWord(st
);
872 gPlayers
[a
].FName
:= utils
.readStr(st
);
874 gPlayers
[a
].FTeam
:= utils
.readByte(st
);
875 gPlayers
[a
].FPreferredTeam
:= gPlayers
[a
].FTeam
;
877 gPlayers
[a
].FAlive
:= utils
.readBool(st
);
878 // Èçðàñõîäîâàë ëè âñå æèçíè
879 gPlayers
[a
].FNoRespawn
:= utils
.readBool(st
);
881 b
:= utils
.readByte(st
);
882 if b
= 1 then gPlayers
[a
].FDirection
:= TDirection
.D_LEFT
else gPlayers
[a
].FDirection
:= TDirection
.D_RIGHT
; // b = 2
884 gPlayers
[a
].FHealth
:= utils
.readLongInt(st
);
886 gPlayers
[a
].FLives
:= utils
.readByte(st
);
888 gPlayers
[a
].FArmor
:= utils
.readLongInt(st
);
890 gPlayers
[a
].FAir
:= utils
.readLongInt(st
);
892 gPlayers
[a
].FJetFuel
:= utils
.readLongInt(st
);
894 gPlayers
[a
].FPain
:= utils
.readLongInt(st
);
896 gPlayers
[a
].FKills
:= utils
.readLongInt(st
);
898 gPlayers
[a
].FMonsterKills
:= utils
.readLongInt(st
);
900 gPlayers
[a
].FFrags
:= utils
.readLongInt(st
);
902 gPlayers
[a
].FFragCombo
:= utils
.readByte(st
);
903 // Âðåìÿ ïîñëåäíåãî ôðàãà
904 gPlayers
[a
].FLastFrag
:= utils
.readLongWord(st
);
906 gPlayers
[a
].FDeath
:= utils
.readLongInt(st
);
908 gPlayers
[a
].FFlag
:= utils
.readByte(st
);
910 gPlayers
[a
].FSecrets
:= utils
.readLongInt(st
);
912 gPlayers
[a
].FCurrWeap
:= utils
.readByte(st
);
913 // Ñëåäóþùåå æåëàåìîå îðóæèå
914 gPlayers
[a
].FNextWeap
:= utils
.readWord(st
);
916 gPlayers
[a
].FNextWeapDelay
:= utils
.readByte(st
);
918 gPlayers
[a
].FBFGFireCounter
:= utils
.readSmallInt(st
);
920 gPlayers
[a
].FDamageBuffer
:= utils
.readLongInt(st
);
921 // Ïîñëåäíèé óäàðèâøèé
922 gPlayers
[a
].FLastSpawnerUID
:= utils
.readWord(st
);
923 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà
924 gPlayers
[a
].FLastHit
:= utils
.readByte(st
);
926 Obj_LoadState(@gPlayers
[a
].FObj
, st
);
927 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ
928 for i
:= A_BULLETS
to A_HIGH
do gPlayers
[a
].FAmmo
[i
] := utils
.readWord(st
);
929 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ
930 for i
:= A_BULLETS
to A_HIGH
do gPlayers
[a
].FMaxAmmo
[i
] := utils
.readWord(st
);
932 for i
:= WP_FIRST
to WP_LAST
do gPlayers
[a
].FWeapon
[i
] := utils
.readBool(st
);
933 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ
934 for i
:= WP_FIRST
to WP_LAST
do gPlayers
[a
].FReloading
[i
] := utils
.readWord(st
);
936 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_ITEM_BACKPACK
);
937 // Íàëè÷èå êðàñíîãî êëþ÷à
938 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_KEY_RED
);
939 // Íàëè÷èå çåëåíîãî êëþ÷à
940 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_KEY_GREEN
);
941 // Íàëè÷èå ñèíåãî êëþ÷à
942 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_KEY_BLUE
);
944 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_BERSERK
);
945 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ
946 for i
:= MR_SUIT
to MR_MAX
do gPlayers
[a
].FMegaRulez
[i
] := utils
.readLongWord(st
);
947 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà
948 for i
:= T_RESPAWN
to T_FLAGCAP
do gPlayers
[a
].FTime
[i
] := utils
.readLongWord(st
);
951 gPlayers
[a
].FActualModelName
:= utils
.readStr(st
);
953 gPlayers
[a
].FColor
.R
:= utils
.readByte(st
);
954 gPlayers
[a
].FColor
.G
:= utils
.readByte(st
);
955 gPlayers
[a
].FColor
.B
:= utils
.readByte(st
);
956 // Îáíîâëÿåì ìîäåëü èãðîêà
957 gPlayers
[a
].SetModel(gPlayers
[a
].FActualModelName
);
959 // Íåò ìîäåëè - ñîçäàíèå íåâîçìîæíî
960 if (gPlayers
[a
].FModel
= nil) then
964 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], [gPlayers
[a
].FActualModelName
]));
968 // Åñëè êîìàíäíàÿ èãðà - êðàñèì ìîäåëü â öâåò êîìàíäû
969 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
970 gPlayers
[a
].FModel
.Color
:= TEAMCOLOR
[gPlayers
[a
].FTeam
]
972 gPlayers
[a
].FModel
.Color
:= gPlayers
[a
].FColor
;
974 result
:= gPlayers
[a
].FUID
;
978 procedure g_Player_ResetTeams();
982 if g_Game_IsClient
then
984 if gPlayers
= nil then
986 for a
:= Low(gPlayers
) to High(gPlayers
) do
987 if gPlayers
[a
] <> nil then
988 case gGameSettings
.GameMode
of
990 gPlayers
[a
].ChangeTeam(TEAM_NONE
);
992 if not (gPlayers
[a
].Team
in [TEAM_RED
, TEAM_BLUE
]) then
993 if gPlayers
[a
].FPreferredTeam
in [TEAM_RED
, TEAM_BLUE
] then
994 gPlayers
[a
].ChangeTeam(gPlayers
[a
].FPreferredTeam
)
997 gPlayers
[a
].ChangeTeam(TEAM_RED
)
999 gPlayers
[a
].ChangeTeam(TEAM_BLUE
);
1002 gPlayers
[a
].ChangeTeam(TEAM_COOP
);
1006 procedure g_Bot_Add(Team
, Difficult
: Byte);
1009 _name
, _model
: String;
1012 if not g_Game_IsServer
then Exit
;
1014 // Ñïèñîê íàçâàíèé ìîäåëåé:
1015 m
:= g_PlayerModel_GetNames();
1020 if (gGameSettings
.GameType
= GT_SINGLE
) or (gGameSettings
.GameMode
= GM_COOP
) then
1021 Team
:= TEAM_COOP
// COOP
1023 if gGameSettings
.GameMode
= GM_DM
then
1024 Team
:= TEAM_NONE
// DM
1026 if Team
= TEAM_NONE
then // CTF / TDM
1028 // Àâòîáàëàíñ êîìàíä:
1032 for a
:= 0 to High(gPlayers
) do
1033 if gPlayers
[a
] <> nil then
1035 if gPlayers
[a
].Team
= TEAM_RED
then
1038 if gPlayers
[a
].Team
= TEAM_BLUE
then
1048 if Random(2) = 0 then
1054 // Âûáèðàåì áîòó èìÿ:
1056 if BotNames
<> nil then
1057 for a
:= 0 to High(BotNames
) do
1058 if g_Player_ValidName(BotNames
[a
]) then
1060 _name
:= BotNames
[a
];
1064 // Èìåíè íåò, çàäàåì ñëó÷àéíîå:
1067 _name
:= Format('DFBOT%.2d', [Random(100)]);
1068 until g_Player_ValidName(_name
);
1070 // Âûáèðàåì ñëó÷àéíóþ ìîäåëü:
1071 _model
:= m
[Random(Length(m
))];
1074 with g_Player_Get(g_Player_Create(_model
,
1075 _RGB(Min(Random(9)*32, 255),
1076 Min(Random(9)*32, 255),
1077 Min(Random(9)*32, 255)),
1078 Team
, True)) as TBot
do
1083 1: FDifficult
:= DIFFICULT_EASY
;
1084 2: FDifficult
:= DIFFICULT_MEDIUM
;
1085 else FDifficult
:= DIFFICULT_HARD
;
1088 for a
:= WP_FIRST
to WP_LAST
do
1090 FDifficult
.WeaponPrior
[a
] := WEAPON_PRIOR1
[a
];
1091 FDifficult
.CloseWeaponPrior
[a
] := WEAPON_PRIOR2
[a
];
1092 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
1095 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [Name
]), True);
1097 if g_Game_IsNet
then MH_SEND_PlayerCreate(UID
);
1098 if g_Game_IsServer
and (gGameSettings
.MaxLives
> 0) then
1103 procedure g_Bot_AddList(Team
: Byte; lName
: ShortString; num
: Integer = -1);
1106 _name
, _model
: String;
1109 if not g_Game_IsServer
then Exit
;
1111 // Ñïèñîê íàçâàíèé ìîäåëåé:
1112 m
:= g_PlayerModel_GetNames();
1117 if (gGameSettings
.GameType
= GT_SINGLE
) or (gGameSettings
.GameMode
= GM_COOP
) then
1118 Team
:= TEAM_COOP
// COOP
1120 if gGameSettings
.GameMode
= GM_DM
then
1121 Team
:= TEAM_NONE
// DM
1123 if Team
= TEAM_NONE
then
1124 Team
:= BotList
[num
].team
; // CTF / TDM
1126 // Âûáèðàåì íàñòðîéêè áîòà èç ñïèñêà ïî íîìåðó èëè èìåíè:
1127 lName
:= AnsiLowerCase(lName
);
1128 if (num
< 0) or (num
> Length(BotList
)-1) then
1130 if (num
= -1) and (lName
<> '') and (BotList
<> nil) then
1131 for a
:= 0 to High(BotList
) do
1132 if AnsiLowerCase(BotList
[a
].name
) = lName
then
1141 _name
:= BotList
[num
].name
;
1142 // Çàíÿòî - âûáèðàåì ñëó÷àéíîå:
1143 if not g_Player_ValidName(_name
) then
1145 _name
:= Format('DFBOT%.2d', [Random(100)]);
1146 until g_Player_ValidName(_name
);
1149 _model
:= BotList
[num
].model
;
1150 // Íåò òàêîé - âûáèðàåì ñëó÷àéíóþ:
1151 if not InSArray(_model
, m
) then
1152 _model
:= m
[Random(Length(m
))];
1155 with g_Player_Get(g_Player_Create(_model
, BotList
[num
].color
, Team
, True)) as TBot
do
1159 FDifficult
.DiagFire
:= BotList
[num
].diag_fire
;
1160 FDifficult
.InvisFire
:= BotList
[num
].invis_fire
;
1161 FDifficult
.DiagPrecision
:= BotList
[num
].diag_precision
;
1162 FDifficult
.FlyPrecision
:= BotList
[num
].fly_precision
;
1163 FDifficult
.Cover
:= BotList
[num
].cover
;
1164 FDifficult
.CloseJump
:= BotList
[num
].close_jump
;
1166 for a
:= WP_FIRST
to WP_LAST
do
1168 FDifficult
.WeaponPrior
[a
] := BotList
[num
].w_prior1
[a
];
1169 FDifficult
.CloseWeaponPrior
[a
] := BotList
[num
].w_prior2
[a
];
1170 //FDifficult.SafeWeaponPrior[a] := BotList[num].w_prior3[a];
1173 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [Name
]), True);
1175 if g_Game_IsNet
then MH_SEND_PlayerCreate(UID
);
1179 procedure g_Bot_RemoveAll();
1183 if not g_Game_IsServer
then Exit
;
1184 if gPlayers
= nil then Exit
;
1186 for a
:= 0 to High(gPlayers
) do
1187 if gPlayers
[a
] <> nil then
1188 if gPlayers
[a
] is TBot
then
1190 gPlayers
[a
].Lives
:= 0;
1191 gPlayers
[a
].Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
1192 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [gPlayers
[a
].Name
]), True);
1193 g_Player_Remove(gPlayers
[a
].FUID
);
1199 procedure g_Bot_MixNames();
1204 if BotNames
<> nil then
1205 for a
:= 0 to High(BotNames
) do
1207 b
:= Random(Length(BotNames
));
1209 Botnames
[a
] := BotNames
[b
];
1214 procedure g_Player_Remove(UID
: Word);
1218 if gPlayers
= nil then Exit
;
1220 if g_Game_IsServer
and g_Game_IsNet
then
1221 MH_SEND_PlayerDelete(UID
);
1223 for i
:= 0 to High(gPlayers
) do
1224 if gPlayers
[i
] <> nil then
1225 if gPlayers
[i
].FUID
= UID
then
1227 if gPlayers
[i
] is TPlayer
then
1228 TPlayer(gPlayers
[i
]).Free()
1230 TBot(gPlayers
[i
]).Free();
1236 procedure g_Player_Init();
1246 if not FileExists(DataDir
+ BOTNAMES_FILENAME
) then
1249 // ×èòàåì âîçìîæíûå èìåíà áîòîâ èç ôàéëà:
1250 AssignFile(F
, DataDir
+ BOTNAMES_FILENAME
);
1261 SetLength(BotNames
, Length(BotNames
)+1);
1262 BotNames
[High(BotNames
)] := s
;
1270 // ×èòàåì ôàéë ñ ïàðàìåòðàìè áîòîâ:
1271 config
:= TConfig
.CreateFile(DataDir
+ BOTLIST_FILENAME
);
1275 while config
.SectionExists(IntToStr(a
)) do
1277 SetLength(BotList
, Length(BotList
)+1);
1279 with BotList
[High(BotList
)] do
1282 name
:= config
.ReadStr(IntToStr(a
), 'name', '');
1284 model
:= config
.ReadStr(IntToStr(a
), 'model', '');
1286 if config
.ReadStr(IntToStr(a
), 'team', 'red') = 'red' then
1291 sa
:= parse(config
.ReadStr(IntToStr(a
), 'color', ''));
1292 color
.R
:= StrToIntDef(sa
[0], 0);
1293 color
.G
:= StrToIntDef(sa
[1], 0);
1294 color
.B
:= StrToIntDef(sa
[2], 0);
1295 // Âåðîÿòíîñòü ñòðåëüáû ïîä óãëîì:
1296 diag_fire
:= config
.ReadInt(IntToStr(a
), 'diag_fire', 0);
1297 // Âåðîÿòíîñòü îòâåòíîãî îãíÿ ïî íåâèäèìîìó ñîïåðíèêó:
1298 invis_fire
:= config
.ReadInt(IntToStr(a
), 'invis_fire', 0);
1299 // Òî÷íîñòü ñòðåëüáû ïîä óãëîì:
1300 diag_precision
:= config
.ReadInt(IntToStr(a
), 'diag_precision', 0);
1301 // Òî÷íîñòü ñòðåëüáû â ïîëåòå:
1302 fly_precision
:= config
.ReadInt(IntToStr(a
), 'fly_precision', 0);
1303 // Òî÷íîñòü óêëîíåíèÿ îò ñíàðÿäîâ:
1304 cover
:= config
.ReadInt(IntToStr(a
), 'cover', 0);
1305 // Âåðîÿòíîñòü ïðûæêà ïðè ïðèáëèæåíèè ñîïåðíèêà:
1306 close_jump
:= config
.ReadInt(IntToStr(a
), 'close_jump', 0);
1307 // Ïðèîðèòåòû îðóæèÿ äëÿ äàëüíåãî áîÿ:
1308 sa
:= parse(config
.ReadStr(IntToStr(a
), 'w_prior1', ''));
1309 if Length(sa
) = 10 then
1311 w_prior1
[b
] := EnsureRange(StrToInt(sa
[b
]), 0, 9);
1312 // Ïðèîðèòåòû îðóæèÿ äëÿ áëèæíåãî áîÿ:
1313 sa
:= parse(config
.ReadStr(IntToStr(a
), 'w_prior2', ''));
1314 if Length(sa
) = 10 then
1316 w_prior2
[b
] := EnsureRange(StrToInt(sa
[b
]), 0, 9);
1318 {sa := parse(config.ReadStr(IntToStr(a), 'w_prior3', ''));
1319 if Length(sa) = 10 then
1321 w_prior3[b] := EnsureRange(StrToInt(sa[b]), 0, 9);}
1330 procedure g_Player_Free();
1334 if gPlayers
<> nil then
1336 for i
:= 0 to High(gPlayers
) do
1337 if gPlayers
[i
] <> nil then
1339 if gPlayers
[i
] is TPlayer
then
1340 TPlayer(gPlayers
[i
]).Free()
1342 TBot(gPlayers
[i
]).Free();
1353 procedure g_Player_UpdateAll();
1357 if gPlayers
= nil then Exit
;
1359 //e_WriteLog('***g_Player_UpdateAll: ENTER', MSG_WARNING);
1360 for i
:= 0 to High(gPlayers
) do
1362 if gPlayers
[i
] <> nil then
1364 if gPlayers
[i
] is TPlayer
then
1366 gPlayers
[i
].Update();
1367 gPlayers
[i
].RealizeCurrentWeapon(); // WARNING! DO NOT MOVE THIS INTO `Update()`!
1371 // bot updates weapons in `UpdateCombat()`
1372 TBot(gPlayers
[i
]).Update();
1376 //e_WriteLog('***g_Player_UpdateAll: EXIT', MSG_WARNING);
1379 procedure g_Player_DrawAll();
1383 if gPlayers
= nil then Exit
;
1385 for i
:= 0 to High(gPlayers
) do
1386 if gPlayers
[i
] <> nil then
1387 if gPlayers
[i
] is TPlayer
then gPlayers
[i
].Draw()
1388 else TBot(gPlayers
[i
]).Draw();
1391 procedure g_Player_DrawDebug(p
: TPlayer
);
1395 if p
= nil then Exit
;
1396 if (@p
.FObj
) = nil then Exit
;
1398 e_TextureFontGetSize(gStdFont
, fW
, fH
);
1400 e_TextureFontPrint(0, 0 , 'Pos X: ' + IntToStr(p
.FObj
.X
), gStdFont
);
1401 e_TextureFontPrint(0, fH
, 'Pos Y: ' + IntToStr(p
.FObj
.Y
), gStdFont
);
1402 e_TextureFontPrint(0, fH
* 2, 'Vel X: ' + IntToStr(p
.FObj
.Vel
.X
), gStdFont
);
1403 e_TextureFontPrint(0, fH
* 3, 'Vel Y: ' + IntToStr(p
.FObj
.Vel
.Y
), gStdFont
);
1404 e_TextureFontPrint(0, fH
* 4, 'Acc X: ' + IntToStr(p
.FObj
.Accel
.X
), gStdFont
);
1405 e_TextureFontPrint(0, fH
* 5, 'Acc Y: ' + IntToStr(p
.FObj
.Accel
.Y
), gStdFont
);
1408 procedure g_Player_DrawHealth();
1413 if gPlayers
= nil then Exit
;
1414 e_TextureFontGetSize(gStdFont
, fW
, fH
);
1416 for i
:= 0 to High(gPlayers
) do
1417 if gPlayers
[i
] <> nil then
1419 e_TextureFontPrint(gPlayers
[i
].FObj
.X
+ gPlayers
[i
].FObj
.Rect
.X
,
1420 gPlayers
[i
].FObj
.Y
+ gPlayers
[i
].FObj
.Rect
.Y
+ gPlayers
[i
].FObj
.Rect
.Height
- fH
* 2,
1421 IntToStr(gPlayers
[i
].FHealth
), gStdFont
);
1422 e_TextureFontPrint(gPlayers
[i
].FObj
.X
+ gPlayers
[i
].FObj
.Rect
.X
,
1423 gPlayers
[i
].FObj
.Y
+ gPlayers
[i
].FObj
.Rect
.Y
+ gPlayers
[i
].FObj
.Rect
.Height
- fH
,
1424 IntToStr(gPlayers
[i
].FArmor
), gStdFont
);
1428 function g_Player_Get(UID
: Word): TPlayer
;
1434 if gPlayers
= nil then
1437 for a
:= 0 to High(gPlayers
) do
1438 if gPlayers
[a
] <> nil then
1439 if gPlayers
[a
].FUID
= UID
then
1441 Result
:= gPlayers
[a
];
1446 function g_Player_GetCount(): Byte;
1452 if gPlayers
= nil then
1455 for a
:= 0 to High(gPlayers
) do
1456 if gPlayers
[a
] <> nil then
1457 Result
:= Result
+ 1;
1460 function g_Player_GetStats(): TPlayerStatArray
;
1466 if gPlayers
= nil then Exit
;
1468 for a
:= 0 to High(gPlayers
) do
1469 if gPlayers
[a
] <> nil then
1471 SetLength(Result
, Length(Result
)+1);
1472 with Result
[High(Result
)] do
1474 Ping
:= gPlayers
[a
].FPing
;
1475 Loss
:= gPlayers
[a
].FLoss
;
1476 Name
:= gPlayers
[a
].FName
;
1477 Team
:= gPlayers
[a
].FTeam
;
1478 Frags
:= gPlayers
[a
].FFrags
;
1479 Deaths
:= gPlayers
[a
].FDeath
;
1480 Kills
:= gPlayers
[a
].FKills
;
1481 Color
:= gPlayers
[a
].FModel
.Color
;
1482 Lives
:= gPlayers
[a
].FLives
;
1483 Spectator
:= gPlayers
[a
].FSpectator
;
1488 procedure g_Player_RememberAll
;
1492 for i
:= Low(gPlayers
) to High(gPlayers
) do
1493 if (gPlayers
[i
] <> nil) and gPlayers
[i
].alive
then
1494 gPlayers
[i
].RememberState
;
1497 procedure g_Player_ResetAll(Force
, Silent
: Boolean);
1501 gTeamStat
[TEAM_RED
].Goals
:= 0;
1502 gTeamStat
[TEAM_BLUE
].Goals
:= 0;
1504 if gPlayers
<> nil then
1505 for i
:= 0 to High(gPlayers
) do
1506 if gPlayers
[i
] <> nil then
1508 gPlayers
[i
].Reset(Force
);
1510 if gPlayers
[i
] is TPlayer
then
1512 if (not gPlayers
[i
].FSpectator
) or gPlayers
[i
].FWantsInGame
then
1513 gPlayers
[i
].Respawn(Silent
)
1515 gPlayers
[i
].Spectate();
1518 TBot(gPlayers
[i
]).Respawn(Silent
);
1522 procedure g_Player_CreateCorpse(Player
: TPlayer
);
1528 if Player
.alive
then
1531 // Ðàçðûâàåì ñâÿçü ñ ïðåæíèì òðóïîì:
1532 if gCorpses
<> nil then
1533 for i
:= 0 to High(gCorpses
) do
1534 if gCorpses
[i
] <> nil then
1535 if gCorpses
[i
].FPlayerUID
= Player
.FUID
then
1536 gCorpses
[i
].FPlayerUID
:= 0;
1538 if Player
.FObj
.Y
>= gMapInfo
.Height
+128 then
1543 if (FHealth
>= -50) or (gGibsCount
= 0) then
1545 if (gCorpses
= nil) or (Length(gCorpses
) = 0) then
1549 for find_id
:= 0 to High(gCorpses
) do
1550 if gCorpses
[find_id
] = nil then
1557 find_id
:= Random(Length(gCorpses
));
1559 gCorpses
[find_id
] := TCorpse
.Create(FObj
.X
, FObj
.Y
, FModel
.Name
, FHealth
< -20);
1560 gCorpses
[find_id
].FColor
:= FModel
.Color
;
1561 gCorpses
[find_id
].FObj
.Vel
:= FObj
.Vel
;
1562 gCorpses
[find_id
].FObj
.Accel
:= FObj
.Accel
;
1563 gCorpses
[find_id
].FPlayerUID
:= FUID
;
1566 g_Player_CreateGibs(FObj
.X
+ PLAYER_RECT_CX
,
1567 FObj
.Y
+ PLAYER_RECT_CY
,
1568 FModel
.Name
, FModel
.Color
);
1572 procedure g_Player_CreateShell(fX
, fY
, dX
, dY
: Integer; T
: Byte);
1576 if (gShells
= nil) or (Length(gShells
) = 0) then
1579 with gShells
[CurrentShell
] do
1585 if T
= SHELL_BULLET
then
1587 if g_Texture_Get('TEXTURE_SHELL_BULLET', SID
) then
1591 Obj
.Rect
.Width
:= 4;
1592 Obj
.Rect
.Height
:= 2;
1596 if g_Texture_Get('TEXTURE_SHELL_SHELL', SID
) then
1600 Obj
.Rect
.Width
:= 7;
1601 Obj
.Rect
.Height
:= 3;
1607 g_Obj_Push(@Obj
, dX
+ Random(4)-Random(4), dY
-Random(4));
1608 positionChanged(); // this updates spatial accelerators
1609 RAngle
:= Random(360);
1610 Timeout
:= gTime
+ SHELL_TIMEOUT
;
1612 if CurrentShell
>= High(gShells
) then
1619 procedure g_Player_CreateGibs(fX
, fY
: Integer; ModelName
: string; fColor
: TRGB
);
1622 GibsArray
: TGibsArray
;
1625 if (gGibs
= nil) or (Length(gGibs
) = 0) then
1627 if not g_PlayerModel_GetGibs(ModelName
, GibsArray
) then
1629 Blood
:= g_PlayerModel_GetBlood(ModelName
);
1631 for a
:= 0 to High(GibsArray
) do
1632 with gGibs
[CurrentGib
] do
1635 ID
:= GibsArray
[a
].ID
;
1636 MaskID
:= GibsArray
[a
].MaskID
;
1639 Obj
.Rect
:= GibsArray
[a
].Rect
;
1640 Obj
.X
:= fX
-GibsArray
[a
].Rect
.X
-(GibsArray
[a
].Rect
.Width
div 2);
1641 Obj
.Y
:= fY
-GibsArray
[a
].Rect
.Y
-(GibsArray
[a
].Rect
.Height
div 2);
1642 g_Obj_PushA(@Obj
, 25 + Random(10), Random(361));
1643 positionChanged(); // this updates spatial accelerators
1644 RAngle
:= Random(360);
1646 if gBloodCount
> 0 then
1647 g_GFX_Blood(fX
, fY
, 16*gBloodCount
+Random(5*gBloodCount
), -16+Random(33), -16+Random(33),
1648 Random(48), Random(48), Blood
.R
, Blood
.G
, Blood
.B
, Blood
.Kind
);
1650 if CurrentGib
>= High(gGibs
) then
1657 procedure g_Player_UpdatePhysicalObjects();
1663 procedure ShellSound_Bounce(X
, Y
: Integer; T
: Byte);
1668 if T
= SHELL_BULLET
then
1669 g_Sound_PlayExAt('SOUND_PLAYER_CASING' + IntToStr(k
), X
, Y
)
1671 g_Sound_PlayExAt('SOUND_PLAYER_SHELL' + IntToStr(k
), X
, Y
);
1676 if gGibs
<> nil then
1677 for i
:= 0 to High(gGibs
) do
1678 if gGibs
[i
].alive
then
1682 mr
:= g_Obj_Move(@Obj
, True, False, True);
1683 positionChanged(); // this updates spatial accelerators
1685 if WordBool(mr
and MOVE_FALLOUT
) then
1691 // Îòëåòàåò îò óäàðà î ñòåíó/ïîòîëîê/ïîë:
1692 if WordBool(mr
and MOVE_HITWALL
) then
1693 Obj
.Vel
.X
:= -(vel
.X
div 2);
1694 if WordBool(mr
and (MOVE_HITCEIL
or MOVE_HITLAND
)) then
1695 Obj
.Vel
.Y
:= -(vel
.Y
div 2);
1697 if (Obj
.Vel
.X
>= 0) then
1699 RAngle
:= RAngle
+ Abs(Obj
.Vel
.X
)*6 + Abs(Obj
.Vel
.Y
);
1700 if RAngle
>= 360 then
1701 RAngle
:= RAngle
mod 360;
1702 end else begin // Counter-clockwise
1703 RAngle
:= RAngle
- Abs(Obj
.Vel
.X
)*6 - Abs(Obj
.Vel
.Y
);
1705 RAngle
:= (360 - (Abs(RAngle
) mod 360)) mod 360;
1708 // Ñîïðîòèâëåíèå âîçäóõà äëÿ êóñêà òðóïà:
1709 if gTime
mod (GAME_TICK
*3) = 0 then
1710 Obj
.Vel
.X
:= z_dec(Obj
.Vel
.X
, 1);
1714 if gCorpses
<> nil then
1715 for i
:= 0 to High(gCorpses
) do
1716 if gCorpses
[i
] <> nil then
1717 if gCorpses
[i
].State
= CORPSE_STATE_REMOVEME
then
1723 gCorpses
[i
].Update();
1726 if gShells
<> nil then
1727 for i
:= 0 to High(gShells
) do
1728 if gShells
[i
].alive
then
1732 mr
:= g_Obj_Move(@Obj
, True, False, True);
1733 positionChanged(); // this updates spatial accelerators
1735 if WordBool(mr
and MOVE_FALLOUT
) or (gShells
[i
].Timeout
< gTime
) then
1741 // Îòëåòàåò îò óäàðà î ñòåíó/ïîòîëîê/ïîë:
1742 if WordBool(mr
and MOVE_HITWALL
) then
1744 Obj
.Vel
.X
:= -(vel
.X
div 2);
1745 if not WordBool(mr
and MOVE_INWATER
) then
1746 ShellSound_Bounce(Obj
.X
, Obj
.Y
, SType
);
1748 if WordBool(mr
and (MOVE_HITCEIL
or MOVE_HITLAND
)) then
1750 Obj
.Vel
.Y
:= -(vel
.Y
div 2);
1751 if Obj
.Vel
.X
<> 0 then Obj
.Vel
.X
:= Obj
.Vel
.X
div 2;
1752 if (Obj
.Vel
.X
= 0) and (Obj
.Vel
.Y
= 0) then
1754 if RAngle
mod 90 <> 0 then
1755 RAngle
:= (RAngle
div 90) * 90;
1757 else if not WordBool(mr
and MOVE_INWATER
) then
1758 ShellSound_Bounce(Obj
.X
, Obj
.Y
, SType
);
1761 if (Obj
.Vel
.X
>= 0) then
1763 RAngle
:= RAngle
+ Abs(Obj
.Vel
.X
)*8 + Abs(Obj
.Vel
.Y
);
1764 if RAngle
>= 360 then
1765 RAngle
:= RAngle
mod 360;
1766 end else begin // Counter-clockwise
1767 RAngle
:= RAngle
- Abs(Obj
.Vel
.X
)*8 - Abs(Obj
.Vel
.Y
);
1769 RAngle
:= (360 - (Abs(RAngle
) mod 360)) mod 360;
1775 procedure TGib
.getMapBox (out x
, y
, w
, h
: Integer); inline;
1777 x
:= Obj
.X
+Obj
.Rect
.X
;
1778 y
:= Obj
.Y
+Obj
.Rect
.Y
;
1779 w
:= Obj
.Rect
.Width
;
1780 h
:= Obj
.Rect
.Height
;
1783 procedure TGib
.moveBy (dx
, dy
: Integer); inline;
1785 if (dx
<> 0) or (dy
<> 0) then
1794 procedure TShell
.getMapBox (out x
, y
, w
, h
: Integer); inline;
1798 w
:= Obj
.Rect
.Width
;
1799 h
:= Obj
.Rect
.Height
;
1802 procedure TShell
.moveBy (dx
, dy
: Integer); inline;
1804 if (dx
<> 0) or (dy
<> 0) then
1813 procedure TGib
.positionChanged (); inline; begin end;
1814 procedure TShell
.positionChanged (); inline; begin end;
1817 procedure g_Player_DrawCorpses();
1822 if gGibs
<> nil then
1823 for i
:= 0 to High(gGibs
) do
1824 if gGibs
[i
].alive
then
1827 if not g_Obj_Collide(sX
, sY
, sWidth
, sHeight
, @Obj
) then
1830 a
.X
:= Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2);
1831 a
.y
:= Obj
.Rect
.Y
+(Obj
.Rect
.Height
div 2);
1833 e_DrawAdv(ID
, Obj
.X
, Obj
.Y
, 0, True, False, RAngle
, @a
, TMirrorType
.None
);
1836 e_DrawAdv(MaskID
, Obj
.X
, Obj
.Y
, 0, True, False, RAngle
, @a
, TMirrorType
.None
);
1842 if gCorpses
<> nil then
1843 for i
:= 0 to High(gCorpses
) do
1844 if gCorpses
[i
] <> nil then
1848 procedure g_Player_DrawShells();
1853 if gShells
<> nil then
1854 for i
:= 0 to High(gShells
) do
1855 if gShells
[i
].alive
then
1858 if not g_Obj_Collide(sX
, sY
, sWidth
, sHeight
, @Obj
) then
1864 e_DrawAdv(SpriteID
, Obj
.X
, Obj
.Y
, 0, True, False, RAngle
, @a
, TMirrorType
.None
);
1868 procedure g_Player_RemoveAllCorpses();
1874 SetLength(gGibs
, MaxGibs
);
1875 SetLength(gShells
, MaxGibs
);
1879 if gCorpses
<> nil then
1880 for i
:= 0 to High(gCorpses
) do
1884 SetLength(gCorpses
, MaxCorpses
);
1887 procedure g_Player_Corpses_SaveState (st
: TStream
);
1891 // Ñ÷èòàåì êîëè÷åñòâî ñóùåñòâóþùèõ òðóïîâ
1893 for i
:= 0 to High(gCorpses
) do if (gCorpses
[i
] <> nil) then Inc(count
);
1895 // Êîëè÷åñòâî òðóïîâ
1896 utils
.writeInt(st
, LongInt(count
));
1898 if (count
= 0) then exit
;
1901 for i
:= 0 to High(gCorpses
) do
1903 if gCorpses
[i
] <> nil then
1906 utils
.writeStr(st
, gCorpses
[i
].FModelName
);
1908 utils
.writeBool(st
, gCorpses
[i
].Mess
);
1909 // Ñîõðàíÿåì äàííûå òðóïà:
1910 gCorpses
[i
].SaveState(st
);
1916 procedure g_Player_Corpses_LoadState (st
: TStream
);
1924 g_Player_RemoveAllCorpses();
1926 // Êîëè÷åñòâî òðóïîâ:
1927 count
:= utils
.readLongInt(st
);
1928 if (count
< 0) or (count
> Length(gCorpses
)) then raise XStreamError
.Create('invalid number of corpses');
1930 if (count
= 0) then exit
;
1933 for i
:= 0 to count
-1 do
1936 str
:= utils
.readStr(st
);
1938 b
:= utils
.readBool(st
);
1940 gCorpses
[i
] := TCorpse
.Create(0, 0, str
, b
);
1941 // Çàãðóæàåì äàííûå òðóïà
1942 gCorpses
[i
].LoadState(st
);
1949 function TPlayer
.isValidViewPort (): Boolean; inline; begin result
:= (viewPortW
> 0) and (viewPortH
> 0); end;
1951 procedure TPlayer
.BFGHit();
1953 g_Weapon_BFGHit(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
1954 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2));
1955 if g_Game_IsServer
and g_Game_IsNet
then
1956 MH_SEND_Effect(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
1957 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2),
1961 procedure TPlayer
.ChangeModel(ModelName
: string);
1963 locModel
: TPlayerModel
;
1965 locModel
:= g_PlayerModel_Get(ModelName
);
1966 if locModel
= nil then Exit
;
1972 procedure TPlayer
.SetModel(ModelName
: string);
1976 m
:= g_PlayerModel_Get(ModelName
);
1979 g_SimpleError(Format(_lc
[I_GAME_ERROR_MODEL_FALLBACK
], [ModelName
]));
1980 m
:= g_PlayerModel_Get('doomer');
1983 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], ['doomer']));
1988 if FModel
<> nil then
1993 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
1994 FModel
.Color
:= FColor
1996 FModel
.Color
:= TEAMCOLOR
[FTeam
];
1997 FModel
.SetWeapon(FCurrWeap
);
1998 FModel
.SetFlag(FFlag
);
1999 SetDirection(FDirection
);
2002 procedure TPlayer
.SetColor(Color
: TRGB
);
2005 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
2006 if FModel
<> nil then FModel
.Color
:= Color
;
2009 procedure TPlayer
.SwitchTeam
;
2011 if g_Game_IsClient
then
2013 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then Exit
;
2015 if gGameOn
and FAlive
then
2016 Kill(K_SIMPLEKILL
, FUID
, HIT_SELF
);
2018 if FTeam
= TEAM_RED
then
2020 ChangeTeam(TEAM_BLUE
);
2021 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_BLUE
], [FName
]), True);
2022 if g_Game_IsNet
then
2023 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM
, TEAM_BLUE
, FName
);
2027 ChangeTeam(TEAM_RED
);
2028 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_RED
], [FName
]), True);
2029 if g_Game_IsNet
then
2030 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM
, TEAM_RED
, FName
);
2032 FPreferredTeam
:= FTeam
;
2035 procedure TPlayer
.ChangeTeam(Team
: Byte);
2042 TEAM_RED
, TEAM_BLUE
:
2043 FModel
.Color
:= TEAMCOLOR
[Team
];
2045 FModel
.Color
:= FColor
;
2047 if (FTeam
<> OldTeam
) and g_Game_IsNet
and g_Game_IsServer
then
2048 MH_SEND_PlayerStats(FUID
);
2052 procedure TPlayer.CollideItem();
2057 if gItems = nil then Exit;
2058 if not FAlive then Exit;
2060 for i := 0 to High(gItems) do
2063 if (ItemType <> ITEM_NONE) and alive then
2064 if g_Obj_Collide(FObj.X+PLAYER_RECT.X, FObj.Y+PLAYER_RECT.Y, PLAYER_RECT.Width,
2065 PLAYER_RECT.Height, @Obj) then
2067 if not PickItem(ItemType, gItems[i].Respawnable, r) then Continue;
2069 if ItemType in [ITEM_SPHERE_BLUE, ITEM_SPHERE_WHITE, ITEM_INVUL] then
2070 g_Sound_PlayExAt('SOUND_ITEM_GETRULEZ', FObj.X, FObj.Y)
2071 else if ItemType in [ITEM_MEDKIT_SMALL, ITEM_MEDKIT_LARGE, ITEM_MEDKIT_BLACK] then
2072 g_Sound_PlayExAt('SOUND_ITEM_GETMED', FObj.X, FObj.Y)
2073 else g_Sound_PlayExAt('SOUND_ITEM_GETITEM', FObj.X, FObj.Y);
2075 // Íàäî óáðàòü ñ êàðòû, åñëè ýòî íå êëþ÷, êîòîðûì íóæíî ïîäåëèòñÿ ñ äðóãèì èãðîêîì:
2076 if r and not ((ItemType in [ITEM_KEY_RED, ITEM_KEY_GREEN, ITEM_KEY_BLUE]) and
2077 (gGameSettings.GameType = GT_SINGLE) and
2078 (g_Player_GetCount() > 1)) then
2079 if not Respawnable then g_Items_Remove(i) else g_Items_Pick(i);
2085 function TPlayer
.CollideLevel(XInc
, YInc
: Integer): Boolean;
2087 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
2088 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_WALL
,
2092 constructor TPlayer
.Create();
2098 mEDamageType
:= HIT_SOME
;
2104 FSawSound
:= TPlayableSound
.Create();
2105 FSawSoundIdle
:= TPlayableSound
.Create();
2106 FSawSoundHit
:= TPlayableSound
.Create();
2107 FSawSoundSelect
:= TPlayableSound
.Create();
2108 FFlameSoundOn
:= TPlayableSound
.Create();
2109 FFlameSoundOff
:= TPlayableSound
.Create();
2110 FFlameSoundWork
:= TPlayableSound
.Create();
2111 FJetSoundFly
:= TPlayableSound
.Create();
2112 FJetSoundOn
:= TPlayableSound
.Create();
2113 FJetSoundOff
:= TPlayableSound
.Create();
2115 FSawSound
.SetByName('SOUND_WEAPON_FIRESAW');
2116 FSawSoundIdle
.SetByName('SOUND_WEAPON_IDLESAW');
2117 FSawSoundHit
.SetByName('SOUND_WEAPON_HITSAW');
2118 FSawSoundSelect
.SetByName('SOUND_WEAPON_SELECTSAW');
2119 FFlameSoundOn
.SetByName('SOUND_WEAPON_FLAMEON');
2120 FFlameSoundOff
.SetByName('SOUND_WEAPON_FLAMEOFF');
2121 FFlameSoundWork
.SetByName('SOUND_WEAPON_FLAMEWORK');
2122 FJetSoundFly
.SetByName('SOUND_PLAYER_JETFLY');
2123 FJetSoundOn
.SetByName('SOUND_PLAYER_JETON');
2124 FJetSoundOff
.SetByName('SOUND_PLAYER_JETOFF');
2126 FSpectatePlayer
:= -1;
2130 FSavedState
.WaitRecall
:= False;
2136 FActualModelName
:= 'doomer';
2139 FObj
.Rect
:= PLAYER_RECT
;
2141 FBFGFireCounter
:= -1;
2142 FJustTeleported
:= False;
2148 procedure TPlayer
.positionChanged (); inline;
2152 procedure TPlayer
.doDamage (v
: Integer);
2154 if (v
<= 0) then exit
;
2155 if (v
> 32767) then v
:= 32767;
2156 Damage(v
, 0, 0, 0, mEDamageType
);
2159 procedure TPlayer
.Damage(value
: Word; SpawnerUID
: Word; vx
, vy
: Integer; t
: Byte);
2163 if (not g_Game_IsClient
) and (not FAlive
) then
2168 // Íåóÿçâèìîñòü íå ñïàñàåò îò ëîâóøåê:
2169 if ((t
= HIT_TRAP
) or (t
= HIT_SELF
)) and (not FGodMode
) then
2171 if not g_Game_IsClient
then
2174 if t
= HIT_TRAP
then
2176 // Ëîâóøêà óáèâàåò ñðàçó:
2178 Kill(K_EXTRAHARDKILL
, SpawnerUID
, t
);
2180 if t
= HIT_SELF
then
2184 Kill(K_SIMPLEKILL
, SpawnerUID
, t
);
2187 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
2188 FMegaRulez
[MR_SUIT
] := 0;
2189 FMegaRulez
[MR_INVUL
] := 0;
2190 FMegaRulez
[MR_INVIS
] := 0;
2194 // Íî îò îñòàëüíîãî ñïàñàåò:
2195 if FMegaRulez
[MR_INVUL
] >= gTime
then
2202 // Åñëè åñòü óðîí ñâîèì, èëè ðàíèë ñàì ñåáÿ, èëè òåáÿ ðàíèë ïðîòèâíèê:
2203 if LongBool(gGameSettings
.Options
and GAME_OPTION_TEAMDAMAGE
) or
2204 (SpawnerUID
= FUID
) or
2205 (not SameTeam(FUID
, SpawnerUID
)) then
2207 FLastSpawnerUID
:= SpawnerUID
;
2209 // Êðîâü (ïóçûðüêè, åñëè â âîäå):
2210 if gBloodCount
> 0 then
2212 c
:= Min(value
, 200)*gBloodCount
+ Random(Min(value
, 200) div 2);
2213 if value
div 4 <= c
then
2214 c
:= c
- (value
div 4)
2218 if (t
= HIT_SOME
) and (vx
= 0) and (vy
= 0) then
2222 HIT_TRAP
, HIT_ACID
, HIT_FLAME
, HIT_SELF
: MakeBloodSimple(c
);
2223 HIT_BFG
, HIT_ROCKET
, HIT_SOME
: MakeBloodVector(c
, vx
, vy
);
2226 if t
= HIT_WATER
then
2227 g_GFX_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
2228 FObj
.Y
+PLAYER_RECT
.Y
-4, value
div 2, 8, 4);
2233 Inc(FDamageBuffer
, value
);
2237 FPain
:= FPain
+ value
;
2240 if g_Game_IsServer
and g_Game_IsNet
then
2242 MH_SEND_PlayerDamage(FUID
, t
, SpawnerUID
, value
, vx
, vy
);
2243 MH_SEND_PlayerStats(FUID
);
2244 MH_SEND_PlayerPos(False, FUID
);
2248 function TPlayer
.Heal(value
: Word; Soft
: Boolean): Boolean;
2251 if g_Game_IsClient
then
2256 if Soft
and (FHealth
< PLAYER_HP_SOFT
) then
2258 IncMax(FHealth
, value
, PLAYER_HP_SOFT
);
2261 if (not Soft
) and (FHealth
< PLAYER_HP_LIMIT
) then
2263 IncMax(FHealth
, value
, PLAYER_HP_LIMIT
);
2267 if Result
and g_Game_IsServer
and g_Game_IsNet
then
2268 MH_SEND_PlayerStats(FUID
);
2271 destructor TPlayer
.Destroy();
2273 if (gPlayer1
<> nil) and (gPlayer1
.FUID
= FUID
) then
2275 if (gPlayer2
<> nil) and (gPlayer2
.FUID
= FUID
) then
2279 FSawSoundIdle
.Free();
2280 FSawSoundHit
.Free();
2281 FSawSoundSelect
.Free();
2282 FFlameSoundOn
.Free();
2283 FFlameSoundOff
.Free();
2284 FFlameSoundWork
.Free();
2285 FJetSoundFly
.Free();
2287 FJetSoundOff
.Free();
2289 if FPunchAnim
<> nil then
2295 procedure TPlayer
.DrawIndicator();
2297 indX
, indY
: Integer;
2303 indX
:= FObj
.X
+FObj
.Rect
.X
;
2305 if g_Texture_Get('TEXTURE_PLAYER_INDICATOR', ID
) then
2307 e_GetTextureSize(ID
, @indW
, @indH
);
2308 e_Draw(ID
, indX
+ indW
div 2, indY
- indH
, 0, True, False);
2311 //e_TextureFontPrint(indX, indY, FName, gStdFont); // Shows player name overhead
2314 procedure TPlayer
.DrawBubble();
2316 bubX
, bubY
: Integer;
2319 Rw
, Gw
, Bw
: SmallInt;
2322 bubX
:= FObj
.X
+FObj
.Rect
.X
+ IfThen(FDirection
= TDirection
.D_LEFT
, -4, 18);
2323 bubY
:= FObj
.Y
+FObj
.Rect
.Y
- 18;
2331 1: // simple textual non-bubble
2333 bubX
:= FObj
.X
+FObj
.Rect
.X
- 11;
2334 bubY
:= FObj
.Y
+FObj
.Rect
.Y
- 17;
2335 e_TextureFontPrint(bubX
, bubY
, '[...]', gStdFont
);
2338 2: // advanced pixel-perfect bubble
2340 if FTeam
= TEAM_RED
then
2343 if FTeam
= TEAM_BLUE
then
2346 3: // colored bubble
2348 Rb
:= FModel
.Color
.R
;
2349 Gb
:= FModel
.Color
.G
;
2350 Bb
:= FModel
.Color
.B
;
2351 Rw
:= Min(Rb
* 2 + 64, 255);
2352 Gw
:= Min(Gb
* 2 + 64, 255);
2353 Bw
:= Min(Bb
* 2 + 64, 255);
2354 if (Abs(Rw
- Rb
) < 32)
2355 or (Abs(Gw
- Gb
) < 32)
2356 or (Abs(Bw
- Bb
) < 32) then
2358 Rb
:= Max(Rw
div 2 - 16, 0);
2359 Gb
:= Max(Gw
div 2 - 16, 0);
2360 Bb
:= Max(Bw
div 2 - 16, 0);
2363 4: // custom textured bubble
2365 if g_Texture_Get('TEXTURE_PLAYER_TALKBUBBLE', ID
) then
2366 if FDirection
= TDirection
.D_RIGHT
then
2367 e_Draw(ID
, bubX
- 6, bubY
- 7, 0, True, False)
2369 e_Draw(ID
, bubX
- 6, bubY
- 7, 0, True, False, TMirrorType
.Horizontal
);
2375 e_DrawQuad(bubX
+ 1, bubY
, bubX
+ 18, bubY
+ 13, Rb
, Gb
, Bb
);
2376 e_DrawQuad(bubX
, bubY
+ 1, bubX
+ 19, bubY
+ 12, Rb
, Gb
, Bb
);
2378 e_DrawFillQuad(bubX
+ 1, bubY
+ 1, bubX
+ 18, bubY
+ 12, Rw
, Gw
, Bw
, 0);
2381 Dot
:= IfThen(FDirection
= TDirection
.D_LEFT
, 14, 5);
2382 e_DrawLine(1, bubX
+ Dot
, bubY
+ 14, bubX
+ Dot
, bubY
+ 16, Rb
, Gb
, Bb
);
2383 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
);
2384 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
);
2385 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
);
2386 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
);
2390 e_DrawFillQuad(bubX
+ Dot
, bubY
+ 8, bubX
+ Dot
+ 1, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2391 e_DrawFillQuad(bubX
+ Dot
+ 3, bubY
+ 8, bubX
+ Dot
+ 4, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2392 e_DrawFillQuad(bubX
+ Dot
+ 6, bubY
+ 8, bubX
+ Dot
+ 7, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2395 procedure TPlayer
.Draw();
2400 Mirror
: TMirrorType
;
2404 if Direction
= TDirection
.D_RIGHT
then
2405 Mirror
:= TMirrorType
.None
2407 Mirror
:= TMirrorType
.Horizontal
;
2409 if FPunchAnim
<> nil then
2411 FPunchAnim
.Draw(FObj
.X
+IfThen(Direction
= TDirection
.D_LEFT
, 15-FObj
.Rect
.X
, FObj
.Rect
.X
-15),
2412 FObj
.Y
+FObj
.Rect
.Y
-11, Mirror
);
2413 if FPunchAnim
.played
then
2420 if (FMegaRulez
[MR_INVUL
] > gTime
) and (gPlayerDrawn
<> Self
) then
2421 if g_Texture_Get('TEXTURE_PLAYER_INVULPENTA', ID
) then
2423 e_GetTextureSize(ID
, @w
, @h
);
2424 if FDirection
= TDirection
.D_LEFT
then
2425 e_Draw(ID
, FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2)-(w
div 2)+4,
2426 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2)-(h
div 2)-7+FObj
.slopeUpLeft
, 0, True, False)
2428 e_Draw(ID
, FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2)-(w
div 2)-2,
2429 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2)-(h
div 2)-7+FObj
.slopeUpLeft
, 0, True, False);
2432 if FMegaRulez
[MR_INVIS
] > gTime
then
2434 if (gPlayerDrawn
<> nil) and ((Self
= gPlayerDrawn
) or
2435 ((FTeam
= gPlayerDrawn
.Team
) and (gGameSettings
.GameMode
<> GM_DM
))) then
2437 if (FMegaRulez
[MR_INVIS
] - gTime
) <= 2100 then
2438 dr
:= not Odd((FMegaRulez
[MR_INVIS
] - gTime
) div 300)
2442 FModel
.Draw(FObj
.X
, FObj
.Y
+FObj
.slopeUpLeft
, 200)
2444 FModel
.Draw(FObj
.X
, FObj
.Y
+FObj
.slopeUpLeft
);
2447 FModel
.Draw(FObj
.X
, FObj
.Y
+FObj
.slopeUpLeft
, 254);
2450 FModel
.Draw(FObj
.X
, FObj
.Y
+FObj
.slopeUpLeft
);
2453 if g_debug_Frames
then
2455 e_DrawQuad(FObj
.X
+FObj
.Rect
.X
,
2457 FObj
.X
+FObj
.Rect
.X
+FObj
.Rect
.Width
-1,
2458 FObj
.Y
+FObj
.Rect
.Y
+FObj
.Rect
.Height
-1,
2462 if (gChatBubble
> 0) and (FKeys
[KEY_CHAT
].Pressed
) and not FGhost
then
2463 if (FMegaRulez
[MR_INVIS
] <= gTime
) or ((gPlayerDrawn
<> nil) and ((Self
= gPlayerDrawn
) or
2464 ((FTeam
= gPlayerDrawn
.Team
) and (gGameSettings
.GameMode
<> GM_DM
)))) then
2466 // e_DrawPoint(5, 335, 288, 255, 0, 0); // DL, UR, DL, UR
2467 if gAimLine
and alive
and
2468 ((Self
= gPlayer1
) or (Self
= gPlayer2
)) then
2473 procedure TPlayer
.DrawAim();
2474 procedure drawCast (sz
: Integer; ax0
, ay0
, ax1
, ay1
: Integer);
2479 {$IFDEF ENABLE_HOLMES}
2480 if isValidViewPort
and (self
= gPlayer1
) then
2482 g_Holmes_plrLaser(ax0
, ay0
, ax1
, ay1
);
2486 e_DrawLine(sz
, ax0
, ay0
, ax1
, ay1
, 255, 0, 0, 96);
2487 if (g_Map_traceToNearestWall(ax0
, ay0
, ax1
, ay1
, @ex
, @ey
) <> nil) then
2489 e_DrawLine(sz
, ax0
, ay0
, ex
, ey
, 0, 255, 0, 96);
2493 e_DrawLine(sz
, ax0
, ay0
, ex
, ey
, 0, 0, 255, 96);
2498 wx
, wy
, xx
, yy
: Integer;
2502 wx
:= FObj
.X
+ WEAPONPOINT
[FDirection
].X
+ IfThen(FDirection
= TDirection
.D_LEFT
, 7, -7);
2503 wy
:= FObj
.Y
+ WEAPONPOINT
[FDirection
].Y
;
2512 1: begin // Chainsaw
2519 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2520 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2521 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2522 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2527 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2528 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2529 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2530 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2532 4: begin // Double Shotgun
2535 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2536 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2537 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2538 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2540 5: begin // Chaingun
2543 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2544 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2545 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2546 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2548 6: begin // Rocket Launcher
2551 if angle
= ANGLE_RIGHTUP
then Inc(angle
, 2);
2552 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2553 if angle
= ANGLE_LEFTUP
then Dec(angle
, 2);
2554 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2556 7: begin // Plasmagun
2559 if angle
= ANGLE_RIGHTUP
then Inc(angle
);
2560 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 3);
2561 if angle
= ANGLE_LEFTUP
then Dec(angle
);
2562 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 3);
2567 if angle
= ANGLE_RIGHTUP
then Inc(angle
, 1);
2568 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 2);
2569 if angle
= ANGLE_LEFTUP
then Dec(angle
, 1);
2570 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 2);
2572 9: begin // Super Chaingun
2575 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2576 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2577 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2578 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2581 xx
:= Trunc(Cos(-DegToRad(angle
)) * len
) + wx
;
2582 yy
:= Trunc(Sin(-DegToRad(angle
)) * len
) + wy
;
2583 {$IF DEFINED(D2F_DEBUG)}
2584 drawCast(sz
, wx
, wy
, xx
, yy
);
2586 e_DrawLine(sz
, wx
, wy
, xx
, yy
, 255, 0, 0, 96);
2590 procedure TPlayer
.DrawGUI();
2593 X
, Y
, SY
, a
, p
, m
: Integer;
2597 stat
: TPlayerStatArray
;
2599 X
:= gPlayerScreenSize
.X
;
2600 SY
:= gPlayerScreenSize
.Y
;
2603 if gShowGoals
and (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
2605 if gGameSettings
.GameMode
= GM_CTF
then
2609 if gGameSettings
.GameMode
= GM_CTF
then
2611 s
:= 'TEXTURE_PLAYER_REDFLAG';
2612 if gFlags
[FLAG_RED
].State
= FLAG_STATE_CAPTURED
then
2613 s
:= 'TEXTURE_PLAYER_REDFLAG_S';
2614 if gFlags
[FLAG_RED
].State
= FLAG_STATE_DROPPED
then
2615 s
:= 'TEXTURE_PLAYER_REDFLAG_D';
2616 if g_Texture_Get(s
, ID
) then
2617 e_Draw(ID
, X
-16-32, 240-72-4, 0, True, False);
2620 s
:= IntToStr(gTeamStat
[TEAM_RED
].Goals
);
2621 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2622 e_CharFont_PrintEx(gMenuFont
, X
-16-a
-tw
, 240-72-4, s
, TEAMCOLOR
[TEAM_RED
]);
2624 if gGameSettings
.GameMode
= GM_CTF
then
2626 s
:= 'TEXTURE_PLAYER_BLUEFLAG';
2627 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_CAPTURED
then
2628 s
:= 'TEXTURE_PLAYER_BLUEFLAG_S';
2629 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_DROPPED
then
2630 s
:= 'TEXTURE_PLAYER_BLUEFLAG_D';
2631 if g_Texture_Get(s
, ID
) then
2632 e_Draw(ID
, X
-16-32, 240-32-4, 0, True, False);
2635 s
:= IntToStr(gTeamStat
[TEAM_BLUE
].Goals
);
2636 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2637 e_CharFont_PrintEx(gMenuFont
, X
-16-a
-tw
, 240-32-4, s
, TEAMCOLOR
[TEAM_BLUE
]);
2640 if g_Texture_Get('TEXTURE_PLAYER_HUDBG', ID
) then
2641 e_DrawFill(ID
, X
, 0, 1, (gPlayerScreenSize
.Y
div 256)+IfThen(gPlayerScreenSize
.Y
mod 256 > 0, 1, 0),
2644 if g_Texture_Get('TEXTURE_PLAYER_HUD', ID
) then
2645 e_Draw(ID
, X
+2, Y
, 0, True, False);
2647 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
2651 s
:= IntToStr(Frags
);
2652 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2653 e_CharFont_PrintEx(gMenuFont
, X
-16-tw
, Y
, s
, _RGB(255, 0, 0));
2658 stat
:= g_Player_GetStats();
2663 for a
:= 0 to High(stat
) do
2664 if stat
[a
].Name
<> Name
then
2666 if stat
[a
].Frags
> m
then m
:= stat
[a
].Frags
;
2667 if stat
[a
].Frags
> Frags
then p
:= p
+1;
2671 s
:= IntToStr(p
)+' / '+IntToStr(Length(stat
))+' ';
2672 if Frags
>= m
then s
:= s
+'+' else s
:= s
+'-';
2673 s
:= s
+IntToStr(Abs(Frags
-m
));
2675 e_CharFont_GetSize(gMenuSmallFont
, s
, tw
, th
);
2676 e_CharFont_PrintEx(gMenuSmallFont
, X
-16-tw
, Y
+32, s
, _RGB(255, 0, 0));
2679 if gShowLives
and (gGameSettings
.MaxLives
> 0) then
2681 s
:= IntToStr(Lives
);
2682 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2683 e_CharFont_PrintEx(gMenuFont
, X
-16-tw
, SY
-32, s
, _RGB(0, 255, 0));
2687 e_CharFont_GetSize(gMenuSmallFont
, FName
, tw
, th
);
2688 e_CharFont_PrintEx(gMenuSmallFont
, X
+98-(tw
div 2), Y
+8, FName
, _RGB(255, 0, 0));
2690 if R_BERSERK
in FRulez
then
2691 e_Draw(gItemsTexturesID
[ITEM_MEDKIT_BLACK
], X
+37, Y
+45, 0, True, False)
2693 e_Draw(gItemsTexturesID
[ITEM_MEDKIT_LARGE
], X
+37, Y
+45, 0, True, False);
2695 if g_Texture_Get('TEXTURE_PLAYER_ARMORHUD', ID
) then
2696 e_Draw(ID
, X
+36, Y
+77, 0, True, False);
2698 s
:= IntToStr(IfThen(FHealth
> 0, FHealth
, 0));
2699 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2700 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+40, s
, _RGB(255, 0, 0));
2702 s
:= IntToStr(FArmor
);
2703 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2704 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+68, s
, _RGB(255, 0, 0));
2706 s
:= IntToStr(GetAmmoByWeapon(FCurrWeap
));
2712 ID
:= gItemsTexturesID
[ITEM_WEAPON_KASTET
];
2717 ID
:= gItemsTexturesID
[ITEM_WEAPON_SAW
];
2719 WEAPON_PISTOL
: ID
:= gItemsTexturesID
[ITEM_WEAPON_PISTOL
];
2720 WEAPON_CHAINGUN
: ID
:= gItemsTexturesID
[ITEM_WEAPON_CHAINGUN
];
2721 WEAPON_SHOTGUN1
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SHOTGUN1
];
2722 WEAPON_SHOTGUN2
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SHOTGUN2
];
2723 WEAPON_SUPERPULEMET
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SUPERPULEMET
];
2724 WEAPON_ROCKETLAUNCHER
: ID
:= gItemsTexturesID
[ITEM_WEAPON_ROCKETLAUNCHER
];
2725 WEAPON_PLASMA
: ID
:= gItemsTexturesID
[ITEM_WEAPON_PLASMA
];
2726 WEAPON_BFG
: ID
:= gItemsTexturesID
[ITEM_WEAPON_BFG
];
2727 WEAPON_FLAMETHROWER
: ID
:= gItemsTexturesID
[ITEM_WEAPON_FLAMETHROWER
];
2730 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2731 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+158, s
, _RGB(255, 0, 0));
2732 e_Draw(ID
, X
+20, Y
+160, 0, True, False);
2734 if R_KEY_RED
in FRulez
then
2735 e_Draw(gItemsTexturesID
[ITEM_KEY_RED
], X
+78, Y
+214, 0, True, False);
2737 if R_KEY_GREEN
in FRulez
then
2738 e_Draw(gItemsTexturesID
[ITEM_KEY_GREEN
], X
+95, Y
+214, 0, True, False);
2740 if R_KEY_BLUE
in FRulez
then
2741 e_Draw(gItemsTexturesID
[ITEM_KEY_BLUE
], X
+112, Y
+214, 0, True, False);
2743 if FJetFuel
> 0 then
2745 if g_Texture_Get('TEXTURE_PLAYER_HUDAIR', ID
) then
2746 e_Draw(ID
, X
+2, Y
+116, 0, True, False);
2747 if g_Texture_Get('TEXTURE_PLAYER_HUDJET', ID
) then
2748 e_Draw(ID
, X
+2, Y
+126, 0, True, False);
2749 e_DrawLine(4, X
+16, Y
+122, X
+16+Trunc(168*IfThen(FAir
> 0, FAir
, 0)/AIR_MAX
), Y
+122, 0, 0, 196);
2750 e_DrawLine(4, X
+16, Y
+132, X
+16+Trunc(168*FJetFuel
/JET_MAX
), Y
+132, 208, 0, 0);
2754 if g_Texture_Get('TEXTURE_PLAYER_HUDAIR', ID
) then
2755 e_Draw(ID
, X
+2, Y
+124, 0, True, False);
2756 e_DrawLine(4, X
+16, Y
+130, X
+16+Trunc(168*IfThen(FAir
> 0, FAir
, 0)/AIR_MAX
), Y
+130, 0, 0, 196);
2759 if gShowPing
and g_Game_IsClient
then
2761 s
:= _lc
[I_GAME_PING_HUD
] + IntToStr(NetPeer
.lastRoundTripTime
) + _lc
[I_NET_SLIST_PING_MS
];
2762 e_TextureFontPrint(X
+ 4, Y
+ 242, s
, gStdFont
);
2768 e_TextureFontPrint(X
+ 4, Y
+ 242, _lc
[I_PLAYER_SPECT
], gStdFont
);
2769 e_TextureFontPrint(X
+ 4, Y
+ 258, _lc
[I_PLAYER_SPECT2
], gStdFont
);
2770 e_TextureFontPrint(X
+ 4, Y
+ 274, _lc
[I_PLAYER_SPECT1
], gStdFont
);
2773 e_TextureFontGetSize(gStdFont
, cw
, ch
);
2774 s
:= _lc
[I_PLAYER_SPECT4
];
2775 e_TextureFontPrintEx(gScreenWidth
div 2 - cw
*(Length(s
) div 2),
2776 gScreenHeight
-4-ch
, s
, gStdFont
, 255, 255, 255, 1, True);
2777 e_TextureFontPrint(X
+ 4, Y
+ 290, _lc
[I_PLAYER_SPECT1S
], gStdFont
);
2783 procedure TPlayer
.DrawRulez();
2787 // Ïðè âçÿòèè íåóÿçâèìîñòè ðèñóåòñÿ èíâåðñèîííûé áåëûé ôîí
2788 if FMegaRulez
[MR_INVUL
] >= gTime
then
2790 if (FMegaRulez
[MR_INVUL
]-gTime
) <= 2100 then
2791 dr
:= not Odd((FMegaRulez
[MR_INVUL
]-gTime
) div 300)
2796 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2797 191, 191, 191, 0, TBlending
.Invert
);
2800 // Ïðè âçÿòèè çàùèòíîãî êîñòþìà ðèñóåòñÿ çåëåíîâàòûé ôîí
2801 if FMegaRulez
[MR_SUIT
] >= gTime
then
2803 if (FMegaRulez
[MR_SUIT
]-gTime
) <= 2100 then
2804 dr
:= not Odd((FMegaRulez
[MR_SUIT
]-gTime
) div 300)
2809 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2810 0, 96, 0, 200, TBlending
.None
);
2813 // Ïðè âçÿòèè áåðñåðêà ðèñóåòñÿ êðàñíîâàòûé ôîí
2814 if (FBerserk
>= 0) and (LongWord(FBerserk
) >= gTime
) and (gFlash
= 2) then
2816 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2817 255, 0, 0, 200, TBlending
.None
);
2821 procedure TPlayer
.DrawPain();
2825 if FPain
= 0 then Exit
;
2829 if a
< 15 then h
:= 0
2830 else if a
< 35 then h
:= 1
2831 else if a
< 55 then h
:= 2
2832 else if a
< 75 then h
:= 3
2833 else if a
< 95 then h
:= 4
2836 //if a > 255 then a := 255;
2838 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1, 255, 0, 0, 255-h
*50);
2839 //e_DrawFillQuad(0, 0, gPlayerScreenSize.X-1, gPlayerScreenSize.Y-1, 255-min(128, a), 255-a, 255-a, 0, B_FILTER);
2842 procedure TPlayer
.DrawPickup();
2846 if FPickup
= 0 then Exit
;
2850 if a
< 15 then h
:= 1
2851 else if a
< 35 then h
:= 2
2852 else if a
< 55 then h
:= 3
2853 else if a
< 75 then h
:= 4
2856 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1, 150, 200, 150, 255-h
*50);
2859 procedure TPlayer
.DoPunch();
2864 if FPunchAnim
<> nil then begin
2869 st
:= 'FRAMES_PUNCH';
2870 if R_BERSERK
in FRulez
then
2871 st
:= st
+ '_BERSERK';
2872 if FKeys
[KEY_UP
].Pressed
then
2874 else if FKeys
[KEY_DOWN
].Pressed
then
2876 g_Frames_Get(id
, st
);
2877 FPunchAnim
:= TAnimation
.Create(id
, False, 1);
2880 procedure TPlayer
.Fire();
2882 f
, DidFire
: Boolean;
2883 wx
, wy
, xd
, yd
: Integer;
2886 if g_Game_IsClient
then Exit
;
2887 // FBFGFireCounter - âðåìÿ ïåðåä âûñòðåëîì (äëÿ BFG)
2888 // FReloading - âðåìÿ ïîñëå âûñòðåëà (äëÿ âñåãî)
2896 if FReloading
[FCurrWeap
] <> 0 then Exit
;
2901 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
2902 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
2903 xd
:= wx
+IfThen(FDirection
= TDirection
.D_LEFT
, -30, 30);
2904 yd
:= wy
+firediry();
2910 if R_BERSERK
in FRulez
then
2912 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
2913 locobj
.X
:= FObj
.X
+FObj
.Rect
.X
;
2914 locobj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
2917 locobj
.rect
.Width
:= 39;
2918 locobj
.rect
.Height
:= 52;
2919 locobj
.Vel
.X
:= (xd
-wx
) div 2;
2920 locobj
.Vel
.Y
:= (yd
-wy
) div 2;
2921 locobj
.Accel
.X
:= xd
-wx
;
2922 locobj
.Accel
.y
:= yd
-wy
;
2924 if g_Weapon_Hit(@locobj
, 50, FUID
, HIT_SOME
) <> 0 then
2925 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
2927 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
2929 if (gFlash
= 1) and (FPain
< 50) then FPain
:= min(FPain
+ 25, 50);
2933 g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
2937 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2942 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
2943 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
2945 FSawSoundSelect
.Stop();
2947 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
2949 else if not FSawSoundHit
.IsPlaying() then
2951 FSawSoundSelect
.Stop();
2952 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
2955 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2961 if FAmmo
[A_BULLETS
] > 0 then
2963 g_Weapon_pistol(wx
, wy
, xd
, yd
, FUID
);
2964 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2965 Dec(FAmmo
[A_BULLETS
]);
2966 FFireAngle
:= FAngle
;
2969 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
2970 GameVelX
, GameVelY
-2, SHELL_BULLET
);
2974 if FAmmo
[A_SHELLS
] > 0 then
2976 g_Weapon_shotgun(wx
, wy
, xd
, yd
, FUID
);
2977 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', wx
, wy
);
2978 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2979 Dec(FAmmo
[A_SHELLS
]);
2980 FFireAngle
:= FAngle
;
2984 FShellType
:= SHELL_SHELL
;
2988 if FAmmo
[A_SHELLS
] >= 2 then
2990 g_Weapon_dshotgun(wx
, wy
, xd
, yd
, FUID
);
2991 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2992 Dec(FAmmo
[A_SHELLS
], 2);
2993 FFireAngle
:= FAngle
;
2997 FShellType
:= SHELL_DBLSHELL
;
3001 if FAmmo
[A_BULLETS
] > 0 then
3003 g_Weapon_mgun(wx
, wy
, xd
, yd
, FUID
);
3004 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', wx
, wy
);
3005 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3006 Dec(FAmmo
[A_BULLETS
]);
3007 FFireAngle
:= FAngle
;
3010 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
3011 GameVelX
, GameVelY
-2, SHELL_BULLET
);
3014 WEAPON_ROCKETLAUNCHER
:
3015 if FAmmo
[A_ROCKETS
] > 0 then
3017 g_Weapon_rocket(wx
, wy
, xd
, yd
, FUID
);
3018 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3019 Dec(FAmmo
[A_ROCKETS
]);
3020 FFireAngle
:= FAngle
;
3026 if FAmmo
[A_CELLS
] > 0 then
3028 g_Weapon_plasma(wx
, wy
, xd
, yd
, FUID
);
3029 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3030 Dec(FAmmo
[A_CELLS
]);
3031 FFireAngle
:= FAngle
;
3037 if (FAmmo
[A_CELLS
] >= 40) and (FBFGFireCounter
= -1) then
3039 FBFGFireCounter
:= 17;
3040 if not FNoReload
then
3041 g_Sound_PlayExAt('SOUND_WEAPON_STARTFIREBFG', FObj
.X
, FObj
.Y
);
3042 Dec(FAmmo
[A_CELLS
], 40);
3046 WEAPON_SUPERPULEMET
:
3047 if FAmmo
[A_SHELLS
] > 0 then
3049 g_Weapon_shotgun(wx
, wy
, xd
, yd
, FUID
);
3050 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', wx
, wy
);
3051 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3052 Dec(FAmmo
[A_SHELLS
]);
3053 FFireAngle
:= FAngle
;
3056 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
3057 GameVelX
, GameVelY
-2, SHELL_SHELL
);
3060 WEAPON_FLAMETHROWER
:
3061 if FAmmo
[A_FUEL
] > 0 then
3063 g_Weapon_flame(wx
, wy
, xd
, yd
, FUID
);
3065 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3067 FFireAngle
:= FAngle
;
3074 if g_Game_IsNet
and g_Game_IsServer
then MH_SEND_PlayerStats(FUID
);
3078 if g_Game_IsNet
then
3082 if FCurrWeap
<> WEAPON_BFG
then
3083 MH_SEND_PlayerFire(FUID
, FCurrWeap
, wx
, wy
, xd
, yd
, LastShotID
)
3085 if not FNoReload
then
3086 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_WEAPON_STARTFIREBFG');
3089 MH_SEND_PlayerStats(FUID
);
3094 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
3095 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
3096 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
3099 function TPlayer
.GetAmmoByWeapon(Weapon
: Byte): Word;
3102 WEAPON_PISTOL
, WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
];
3103 WEAPON_SHOTGUN1
, WEAPON_SHOTGUN2
, WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
];
3104 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
];
3105 WEAPON_PLASMA
, WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
];
3106 WEAPON_FLAMETHROWER
: Result
:= FAmmo
[A_FUEL
];
3111 function TPlayer
.HeadInLiquid(XInc
, YInc
: Integer): Boolean;
3113 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
+XInc
, FObj
.Y
+PLAYER_HEADRECT
.Y
+YInc
,
3114 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
3115 PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, True);
3118 procedure TPlayer
.FlamerOn
;
3120 FFlameSoundOff
.Stop();
3121 FFlameSoundOff
.SetPosition(0);
3124 if (not FFlameSoundOn
.IsPlaying()) and (not FFlameSoundWork
.IsPlaying()) then
3125 FFlameSoundWork
.PlayAt(FObj
.X
, FObj
.Y
);
3129 FFlameSoundOn
.PlayAt(FObj
.X
, FObj
.Y
);
3134 procedure TPlayer
.FlamerOff
;
3138 FFlameSoundOn
.Stop();
3139 FFlameSoundOn
.SetPosition(0);
3140 FFlameSoundWork
.Stop();
3141 FFlameSoundWork
.SetPosition(0);
3142 FFlameSoundOff
.PlayAt(FObj
.X
, FObj
.Y
);
3147 procedure TPlayer
.JetpackOn
;
3151 FJetSoundOn
.SetPosition(0);
3152 FJetSoundOn
.PlayAt(FObj
.X
, FObj
.Y
);
3156 procedure TPlayer
.JetpackOff
;
3160 FJetSoundOff
.SetPosition(0);
3161 FJetSoundOff
.PlayAt(FObj
.X
, FObj
.Y
);
3164 procedure TPlayer
.CatchFire(Attacker
: Word);
3166 if FFireTime
<= 0 then
3167 g_Sound_PlayExAt('SOUND_IGNITE', FObj
.X
, FObj
.Y
);
3169 FFireAttacker
:= Attacker
;
3170 if g_Game_IsNet
and g_Game_IsServer
then
3171 MH_SEND_PlayerStats(FUID
);
3174 procedure TPlayer
.Jump();
3176 if gFly
or FJetpack
then
3178 // Ïîëåò (÷èò-êîä èëè äæåòïàê):
3179 if FObj
.Vel
.Y
> -VEL_FLY
then
3180 FObj
.Vel
.Y
:= FObj
.Vel
.Y
- 3;
3183 if FJetFuel
> 0 then
3185 if (FJetFuel
< 1) and g_Game_IsServer
then
3189 if g_Game_IsNet
then
3190 MH_SEND_PlayerStats(FUID
);
3196 // Íå âêëþ÷àòü äæåòïàê â ðåæèìå ïðîõîæäåíèÿ ñêâîçü ñòåíû
3198 FCanJetpack
:= False;
3200 // Ïðûãàåì èëè âñïëûâàåì:
3201 if (CollideLevel(0, 1) or
3202 g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
+36, PLAYER_RECT
.Width
,
3203 PLAYER_RECT
.Height
-33, PANEL_STEP
, False)
3204 ) and (FObj
.Accel
.Y
= 0) then // Íå ïðûãàòü, åñëè åñòü âåðòèêàëüíîå óñêîðåíèå
3206 FObj
.Vel
.Y
:= -VEL_JUMP
;
3207 FCanJetpack
:= False;
3211 if BodyInLiquid(0, 0) then
3212 FObj
.Vel
.Y
:= -VEL_SW
3213 else if (FJetFuel
> 0) and FCanJetpack
and
3214 g_Game_IsServer
and (not g_Obj_CollideLiquid(@FObj
, 0, 0)) then
3218 if g_Game_IsNet
then
3219 MH_SEND_PlayerStats(FUID
);
3224 procedure TPlayer
.Kill(KillType
: Byte; SpawnerUID
: Word; t
: Byte);
3226 a
, i
, k
, ab
, ar
: Byte;
3230 srv
, netsrv
: Boolean;
3236 procedure PushItem(t
: Byte);
3240 id
:= g_Items_Create(FObj
.X
, FObj
.Y
, t
, True, False);
3241 it
:= g_Items_ByIdx(id
);
3242 if KillType
= K_EXTRAHARDKILL
then // -7..+7; -8..0
3244 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-7+Random(15),
3245 (FObj
.Vel
.Y
div 2)-Random(9));
3246 it
.positionChanged(); // this updates spatial accelerators
3250 if KillType
= K_HARDKILL
then // -5..+5; -5..0
3252 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-5+Random(11),
3253 (FObj
.Vel
.Y
div 2)-Random(6));
3255 else // -3..+3; -3..0
3257 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-3+Random(7),
3258 (FObj
.Vel
.Y
div 2)-Random(4));
3260 it
.positionChanged(); // this updates spatial accelerators
3263 if g_Game_IsNet
and g_Game_IsServer
then
3264 MH_SEND_ItemSpawn(True, id
);
3268 DoFrags
:= (gGameSettings
.MaxLives
= 0) or (gGameSettings
.GameMode
= GM_COOP
);
3269 Srv
:= g_Game_IsServer
;
3270 Netsrv
:= g_Game_IsServer
and g_Game_IsNet
;
3271 if Srv
then FDeath
:= FDeath
+ 1;
3276 if not FPhysics
then
3282 if (gGameSettings
.MaxLives
> 0) and Srv
and (gLMSRespawn
= LMS_RESPAWN_NONE
) then
3284 if FLives
> 0 then FLives
:= FLives
- 1;
3285 if FLives
= 0 then FNoRespawn
:= True;
3288 // Íîìåð òèïà ñìåðòè:
3291 K_SIMPLEKILL
: a
:= 1;
3293 K_EXTRAHARDKILL
: a
:= 3;
3298 if not FModel
.PlaySound(MODELSOUND_DIE
, a
, FObj
.X
, FObj
.Y
) then
3300 if FModel
.PlaySound(MODELSOUND_DIE
, i
, FObj
.X
, FObj
.Y
) then
3307 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN1
;
3309 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN2
;
3310 K_EXTRAHARDKILL
, K_FALLKILL
:
3311 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN3
;
3314 // Ïåðåêëþ÷àåì ñîñòîÿíèå:
3318 K_HARDKILL
, K_EXTRAHARDKILL
:
3322 // Ðåàêöèÿ ìîíñòðîâ íà ñìåðòü èãðîêà:
3323 if (KillType
<> K_FALLKILL
) and (Srv
) then
3324 g_Monsters_killedp();
3326 if SpawnerUID
= FUID
then
3328 if Srv
and (DoFrags
or (gGameSettings
.GameMode
= GM_TDM
)) then
3333 g_Console_Add(Format(_lc
[I_PLAYER_KILL_SELF
], [FName
]), True);
3336 if g_GetUIDType(SpawnerUID
) = UID_PLAYER
then
3337 begin // Óáèò äðóãèì èãðîêîì
3338 KP
:= g_Player_Get(SpawnerUID
);
3339 if (KP
<> nil) and Srv
then
3341 if (DoFrags
or (gGameSettings
.GameMode
= GM_TDM
)) then
3342 if SameTeam(FUID
, SpawnerUID
) then
3352 if (gGameSettings
.GameMode
= GM_TDM
) and DoFrags
then
3353 Inc(gTeamStat
[KP
.Team
].Goals
,
3354 IfThen(SameTeam(FUID
, SpawnerUID
), -1, 1));
3356 if netsrv
then MH_SEND_PlayerStats(SpawnerUID
);
3359 plr
:= g_Player_Get(SpawnerUID
);
3367 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_2
],
3371 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_1
],
3375 g_Console_Add(Format(_lc
[I_PLAYER_KILL
],
3380 else if g_GetUIDType(SpawnerUID
) = UID_MONSTER
then
3381 begin // Óáèò ìîíñòðîì
3382 mon
:= g_Monsters_ByUID(SpawnerUID
);
3386 s
:= g_Mons_GetKilledByTypeId(mon
.MonsterType
);
3390 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_2
],
3394 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_1
],
3398 g_Console_Add(Format(_lc
[I_PLAYER_KILL
],
3403 else // Îñîáûå òèïû ñìåðòè
3406 HIT_SELF
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_SELF
], [FName
]), True);
3407 HIT_FALL
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_FALL
], [FName
]), True);
3408 HIT_WATER
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_WATER
], [FName
]), True);
3409 HIT_ACID
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_ACID
], [FName
]), True);
3410 HIT_TRAP
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_TRAP
], [FName
]), True);
3411 else g_Console_Add(Format(_lc
[I_PLAYER_DIED
], [FName
]), True);
3417 for a
:= WP_FIRST
to WP_LAST
do
3421 WEAPON_SAW
: i
:= ITEM_WEAPON_SAW
;
3422 WEAPON_SHOTGUN1
: i
:= ITEM_WEAPON_SHOTGUN1
;
3423 WEAPON_SHOTGUN2
: i
:= ITEM_WEAPON_SHOTGUN2
;
3424 WEAPON_CHAINGUN
: i
:= ITEM_WEAPON_CHAINGUN
;
3425 WEAPON_ROCKETLAUNCHER
: i
:= ITEM_WEAPON_ROCKETLAUNCHER
;
3426 WEAPON_PLASMA
: i
:= ITEM_WEAPON_PLASMA
;
3427 WEAPON_BFG
: i
:= ITEM_WEAPON_BFG
;
3428 WEAPON_SUPERPULEMET
: i
:= ITEM_WEAPON_SUPERPULEMET
;
3429 WEAPON_FLAMETHROWER
: i
:= ITEM_WEAPON_FLAMETHROWER
;
3438 if R_ITEM_BACKPACK
in FRulez
then
3439 PushItem(ITEM_AMMO_BACKPACK
);
3441 // Âûáðîñ ðàêåòíîãî ðàíöà:
3442 if FJetFuel
> 0 then
3443 PushItem(ITEM_JETPACK
);
3446 if not (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
]) then
3448 if R_KEY_RED
in FRulez
then
3449 PushItem(ITEM_KEY_RED
);
3451 if R_KEY_GREEN
in FRulez
then
3452 PushItem(ITEM_KEY_GREEN
);
3454 if R_KEY_BLUE
in FRulez
then
3455 PushItem(ITEM_KEY_BLUE
);
3459 DropFlag(KillType
= K_FALLKILL
);
3462 g_Player_CreateCorpse(Self
);
3464 if Srv
and (gGameSettings
.MaxLives
> 0) and FNoRespawn
and
3465 (gLMSRespawn
= LMS_RESPAWN_NONE
) then
3471 for i
:= Low(gPlayers
) to High(gPlayers
) do
3473 if gPlayers
[i
] = nil then continue
;
3474 if (not gPlayers
[i
].FNoRespawn
) and (not gPlayers
[i
].FSpectator
) then
3477 if gPlayers
[i
].FTeam
= TEAM_RED
then Inc(ar
)
3478 else if gPlayers
[i
].FTeam
= TEAM_BLUE
then Inc(ab
);
3483 OldLR
:= gLMSRespawn
;
3484 if (gGameSettings
.GameMode
= GM_COOP
) then
3488 // everyone is dead, restart the map
3489 g_Game_Message(_lc
[I_MESSAGE_LMS_LOSE
], 144);
3491 MH_SEND_GameEvent(NET_EV_LMS_LOSE
);
3492 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3493 gLMSRespawnTime
:= gTime
+ 5000;
3495 else if (a
= 1) then
3497 if (gPlayers
[k
] <> nil) and not (gPlayers
[k
] is TBot
) then
3498 if (gPlayers
[k
] = gPlayer1
) or
3499 (gPlayers
[k
] = gPlayer2
) then
3500 g_Console_Add('*** ' + _lc
[I_MESSAGE_LMS_SURVIVOR
] + ' ***', True)
3501 else if Netsrv
and (gPlayers
[k
].FClientID
>= 0) then
3502 MH_SEND_GameEvent(NET_EV_LMS_SURVIVOR
, 0, 'N', gPlayers
[k
].FClientID
);
3505 else if (gGameSettings
.GameMode
= GM_TDM
) then
3507 if (ab
= 0) and (ar
<> 0) then
3510 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 144);
3512 MH_SEND_GameEvent(NET_EV_TLMS_WIN
, TEAM_RED
);
3513 Inc(gTeamStat
[TEAM_RED
].Goals
);
3514 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3515 gLMSRespawnTime
:= gTime
+ 5000;
3517 else if (ar
= 0) and (ab
<> 0) then
3520 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 144);
3522 MH_SEND_GameEvent(NET_EV_TLMS_WIN
, TEAM_BLUE
);
3523 Inc(gTeamStat
[TEAM_BLUE
].Goals
);
3524 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3525 gLMSRespawnTime
:= gTime
+ 5000;
3527 else if (ar
= 0) and (ab
= 0) then
3530 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
3532 MH_SEND_GameEvent(NET_EV_LMS_DRAW
, 0, FName
);
3533 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3534 gLMSRespawnTime
:= gTime
+ 5000;
3537 else if (gGameSettings
.GameMode
= GM_DM
) then
3541 if gPlayers
[k
] <> nil then
3544 // survivor is the winner
3545 g_Game_Message(Format(_lc
[I_MESSAGE_LMS_WIN
], [AnsiUpperCase(FName
)]), 144);
3547 MH_SEND_GameEvent(NET_EV_LMS_WIN
, 0, FName
);
3550 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3551 gLMSRespawnTime
:= gTime
+ 5000;
3553 else if (a
= 0) then
3555 // everyone is dead, restart the map
3556 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
3558 MH_SEND_GameEvent(NET_EV_LMS_DRAW
, 0, FName
);
3559 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3560 gLMSRespawnTime
:= gTime
+ 5000;
3563 if srv
and (OldLR
= LMS_RESPAWN_NONE
) and (gLMSRespawn
> LMS_RESPAWN_NONE
) then
3565 if NetMode
= NET_SERVER
then
3566 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, (gLMSRespawnTime
- gTime
) div 1000)
3568 g_Console_Add(Format(_lc
[I_MSG_WARMUP_START
], [(gLMSRespawnTime
- gTime
) div 1000]), True);
3574 MH_SEND_PlayerStats(FUID
);
3575 MH_SEND_PlayerDeath(FUID
, KillType
, t
, SpawnerUID
);
3576 if gGameSettings
.GameMode
= GM_TDM
then MH_SEND_GameStats
;
3579 if srv
and FNoRespawn
then Spectate(True);
3580 FWantsInGame
:= True;
3583 function TPlayer
.BodyInLiquid(XInc
, YInc
: Integer): Boolean;
3585 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
, PLAYER_RECT
.Width
,
3586 PLAYER_RECT
.Height
-20, PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, False);
3589 function TPlayer
.BodyInAcid(XInc
, YInc
: Integer): Boolean;
3591 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
, PLAYER_RECT
.Width
,
3592 PLAYER_RECT
.Height
-20, PANEL_ACID1
or PANEL_ACID2
, False);
3595 procedure TPlayer
.MakeBloodSimple(Count
: Word);
3597 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)+8,
3598 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3599 Count
div 2, 3, -1, 16, (PLAYER_RECT
.Height
*2 div 3),
3600 FModel
.Blood
.R
, FModel
.Blood
.G
, FModel
.Blood
.B
, FModel
.Blood
.Kind
);
3601 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-8,
3602 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3603 Count
div 2, -3, -1, 16, (PLAYER_RECT
.Height
*2) div 3,
3604 FModel
.Blood
.R
, FModel
.Blood
.G
, FModel
.Blood
.B
, FModel
.Blood
.Kind
);
3607 procedure TPlayer
.MakeBloodVector(Count
: Word; VelX
, VelY
: Integer);
3609 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
3610 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3611 Count
, VelX
, VelY
, 16, (PLAYER_RECT
.Height
*2) div 3,
3612 FModel
.Blood
.R
, FModel
.Blood
.G
, FModel
.Blood
.B
, FModel
.Blood
.Kind
);
3615 procedure TPlayer
.QueueWeaponSwitch(Weapon
: Byte);
3617 if g_Game_IsClient
then Exit
;
3618 if Weapon
> High(FWeapon
) then Exit
;
3619 FNextWeap
:= FNextWeap
or (1 shl Weapon
);
3622 procedure TPlayer
.resetWeaponQueue ();
3625 FNextWeapDelay
:= 0;
3628 function TPlayer
.hasAmmoForWeapon (weapon
: Byte): Boolean;
3632 WEAPON_KASTET
, WEAPON_SAW
: result
:= true;
3633 WEAPON_SHOTGUN1
, WEAPON_SHOTGUN2
: result
:= (FAmmo
[A_SHELLS
] > 0);
3634 WEAPON_PISTOL
, WEAPON_CHAINGUN
, WEAPON_SUPERPULEMET
: result
:= (FAmmo
[A_BULLETS
] > 0);
3635 WEAPON_ROCKETLAUNCHER
: result
:= (FAmmo
[A_ROCKETS
] > 0);
3636 WEAPON_PLASMA
, WEAPON_BFG
: result
:= (FAmmo
[A_CELLS
] > 0);
3637 WEAPON_FLAMETHROWER
: result
:= (FAmmo
[A_FUEL
] > 0);
3638 else result
:= (weapon
< length(FWeapon
));
3642 // return 255 for "no switch"
3643 function TPlayer
.getNextWeaponIndex (): Byte;
3646 wantThisWeapon
: array[0..64] of Boolean;
3647 wwc
: Integer = 0; //HACK!
3650 result
:= 255; // default result: "no switch"
3651 // had weapon cycling on previous frame? remove that flag
3652 if (FNextWeap
and $2000) <> 0 then
3654 FNextWeap
:= FNextWeap
and $1FFF;
3655 FNextWeapDelay
:= 0;
3657 // cycling has priority
3658 if (FNextWeap
and $C000) <> 0 then
3660 if (FNextWeap
and $8000) <> 0 then
3664 FNextWeap
:= FNextWeap
or $2000; // we need this
3665 if FNextWeapDelay
> 0 then
3666 exit
; // cooldown time
3668 for i
:= 0 to High(FWeapon
) do
3670 cwi
:= (cwi
+length(FWeapon
)+dir
) mod length(FWeapon
);
3671 if FWeapon
[cwi
] then
3673 //e_WriteLog(Format(' SWITCH: cur=%d; new=%d', [FCurrWeap, cwi]), MSG_WARNING);
3674 result
:= Byte(cwi
);
3675 FNextWeapDelay
:= WEAPON_DELAY
;
3683 for i
:= 0 to High(wantThisWeapon
) do
3684 wantThisWeapon
[i
] := false;
3685 for i
:= 0 to High(FWeapon
) do
3686 if (FNextWeap
and (1 shl i
)) <> 0 then
3688 wantThisWeapon
[i
] := true;
3691 // exclude currently selected weapon from the set
3692 wantThisWeapon
[FCurrWeap
] := false;
3693 // slow down alterations a little
3696 //e_WriteLog(Format(' FNextWeap=%x; delay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
3697 // more than one weapon requested, assume "alteration" and check alteration delay
3698 if FNextWeapDelay
> 0 then
3704 // do not reset weapon queue, it will be done in `RealizeCurrentWeapon()`
3705 // but clear all counters if no weapon should be switched
3711 //e_WriteLog(Format('wwc=%d', [wwc]), MSG_WARNING);
3712 // try weapons in descending order
3713 for i
:= High(FWeapon
) downto 0 do
3715 if wantThisWeapon
[i
] and FWeapon
[i
] and ((wwc
= 1) or hasAmmoForWeapon(i
)) then
3720 FNextWeapDelay
:= WEAPON_DELAY
* 2; // anyway, 'cause why not
3724 // no suitable weapon found, so reset the queue, to avoid accidental "queuing" of weapon w/o ammo
3728 procedure TPlayer
.RealizeCurrentWeapon();
3729 function switchAllowed (): Boolean;
3734 if FBFGFireCounter
<> -1 then
3736 if FTime
[T_SWITCH
] > gTime
then
3738 for i
:= WP_FIRST
to WP_LAST
do
3739 if FReloading
[i
] > 0 then
3747 //e_WriteLog(Format('***RealizeCurrentWeapon: FNextWeap=%x; FNextWeapDelay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
3748 //FNextWeap := FNextWeap and $1FFF;
3749 if FNextWeapDelay
> 0 then Dec(FNextWeapDelay
); // "alteration delay"
3751 if not switchAllowed
then
3753 //HACK for weapon cycling
3754 if (FNextWeap
and $E000) <> 0 then FNextWeap
:= 0;
3758 nw
:= getNextWeaponIndex();
3759 if nw
= 255 then exit
; // don't reset anything here
3760 if nw
> High(FWeapon
) then
3762 // don't forget to reset queue here!
3763 //e_WriteLog(' RealizeCurrentWeapon: WUTAFUUUU', MSG_WARNING);
3771 FTime
[T_SWITCH
] := gTime
+156;
3772 if FCurrWeap
= WEAPON_SAW
then FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3773 FModel
.SetWeapon(FCurrWeap
);
3774 if g_Game_IsNet
then MH_SEND_PlayerStats(FUID
);
3778 procedure TPlayer
.NextWeapon();
3780 if g_Game_IsClient
then Exit
;
3784 procedure TPlayer
.PrevWeapon();
3786 if g_Game_IsClient
then Exit
;
3790 procedure TPlayer
.SetWeapon(W
: Byte);
3792 if FCurrWeap
<> W
then
3793 if W
= WEAPON_SAW
then
3794 FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3797 FModel
.SetWeapon(CurrWeap
);
3801 function TPlayer
.PickItem(ItemType
: Byte; arespawn
: Boolean; var remove
: Boolean): Boolean;
3803 function allowBerserkSwitching (): Boolean;
3805 if (FBFGFireCounter
<> -1) then begin result
:= false; exit
; end;
3807 if gBerserkAutoswitch
then exit
;
3808 if not conIsCheatsEnabled
then exit
;
3816 if g_Game_IsClient
then Exit
;
3818 // a = true - ìåñòî ñïàâíà ïðåäìåòà:
3819 a
:= LongBool(gGameSettings
.Options
and GAME_OPTION_WEAPONSTAY
) and arespawn
;
3824 if FHealth
< PLAYER_HP_SOFT
then
3826 IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
3830 if gFlash
= 2 then Inc(FPickup
, 5);
3834 if FHealth
< PLAYER_HP_SOFT
then
3836 IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
3840 if gFlash
= 2 then Inc(FPickup
, 5);
3844 if FArmor
< PLAYER_AP_SOFT
then
3846 FArmor
:= PLAYER_AP_SOFT
;
3849 if gFlash
= 2 then Inc(FPickup
, 5);
3853 if FArmor
< PLAYER_AP_LIMIT
then
3855 FArmor
:= PLAYER_AP_LIMIT
;
3858 if gFlash
= 2 then Inc(FPickup
, 5);
3862 if FHealth
< PLAYER_HP_LIMIT
then
3864 IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
3868 if gFlash
= 2 then Inc(FPickup
, 5);
3872 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) then
3874 if FHealth
< PLAYER_HP_LIMIT
then
3875 FHealth
:= PLAYER_HP_LIMIT
;
3876 if FArmor
< PLAYER_AP_LIMIT
then
3877 FArmor
:= PLAYER_AP_LIMIT
;
3881 if gFlash
= 2 then Inc(FPickup
, 5);
3885 if (not FWeapon
[WEAPON_SAW
]) or ((not arespawn
) and (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
])) then
3887 FWeapon
[WEAPON_SAW
] := True;
3889 if gFlash
= 2 then Inc(FPickup
, 5);
3890 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3893 ITEM_WEAPON_SHOTGUN1
:
3894 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN1
] then
3896 // Íóæíî, ÷òîáû íå âçÿòü âñå ïóëè ñðàçó:
3897 if a
and FWeapon
[WEAPON_SHOTGUN1
] then Exit
;
3899 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3900 FWeapon
[WEAPON_SHOTGUN1
] := True;
3902 if gFlash
= 2 then Inc(FPickup
, 5);
3903 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3906 ITEM_WEAPON_SHOTGUN2
:
3907 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN2
] then
3909 if a
and FWeapon
[WEAPON_SHOTGUN2
] then Exit
;
3911 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3912 FWeapon
[WEAPON_SHOTGUN2
] := True;
3914 if gFlash
= 2 then Inc(FPickup
, 5);
3915 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3918 ITEM_WEAPON_CHAINGUN
:
3919 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or not FWeapon
[WEAPON_CHAINGUN
] then
3921 if a
and FWeapon
[WEAPON_CHAINGUN
] then Exit
;
3923 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
3924 FWeapon
[WEAPON_CHAINGUN
] := True;
3926 if gFlash
= 2 then Inc(FPickup
, 5);
3927 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3930 ITEM_WEAPON_ROCKETLAUNCHER
:
3931 if (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or not FWeapon
[WEAPON_ROCKETLAUNCHER
] then
3933 if a
and FWeapon
[WEAPON_ROCKETLAUNCHER
] then Exit
;
3935 IncMax(FAmmo
[A_ROCKETS
], 2, FMaxAmmo
[A_ROCKETS
]);
3936 FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
3938 if gFlash
= 2 then Inc(FPickup
, 5);
3939 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3943 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_PLASMA
] then
3945 if a
and FWeapon
[WEAPON_PLASMA
] then Exit
;
3947 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3948 FWeapon
[WEAPON_PLASMA
] := True;
3950 if gFlash
= 2 then Inc(FPickup
, 5);
3951 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3955 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_BFG
] then
3957 if a
and FWeapon
[WEAPON_BFG
] then Exit
;
3959 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3960 FWeapon
[WEAPON_BFG
] := True;
3962 if gFlash
= 2 then Inc(FPickup
, 5);
3963 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3966 ITEM_WEAPON_SUPERPULEMET
:
3967 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SUPERPULEMET
] then
3969 if a
and FWeapon
[WEAPON_SUPERPULEMET
] then Exit
;
3971 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3972 FWeapon
[WEAPON_SUPERPULEMET
] := True;
3974 if gFlash
= 2 then Inc(FPickup
, 5);
3975 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3978 ITEM_WEAPON_FLAMETHROWER
:
3979 if (FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
]) or not FWeapon
[WEAPON_FLAMETHROWER
] then
3981 if a
and FWeapon
[WEAPON_FLAMETHROWER
] then Exit
;
3983 IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
3984 FWeapon
[WEAPON_FLAMETHROWER
] := True;
3986 if gFlash
= 2 then Inc(FPickup
, 5);
3987 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3991 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
3993 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
3996 if gFlash
= 2 then Inc(FPickup
, 5);
3999 ITEM_AMMO_BULLETS_BOX
:
4000 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
4002 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
4005 if gFlash
= 2 then Inc(FPickup
, 5);
4009 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
4011 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4014 if gFlash
= 2 then Inc(FPickup
, 5);
4017 ITEM_AMMO_SHELLS_BOX
:
4018 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
4020 IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
4023 if gFlash
= 2 then Inc(FPickup
, 5);
4027 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
4029 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
4032 if gFlash
= 2 then Inc(FPickup
, 5);
4035 ITEM_AMMO_ROCKET_BOX
:
4036 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
4038 IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
4041 if gFlash
= 2 then Inc(FPickup
, 5);
4045 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
4047 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
4050 if gFlash
= 2 then Inc(FPickup
, 5);
4054 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
4056 IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
4059 if gFlash
= 2 then Inc(FPickup
, 5);
4063 if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then
4065 IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
4068 if gFlash
= 2 then Inc(FPickup
, 5);
4072 if not(R_ITEM_BACKPACK
in FRulez
) or
4073 (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
4074 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
4075 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
4076 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or
4077 (FMaxAmmo
[A_FUEL
] < AmmoLimits
[1, A_FUEL
]) then
4079 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[1, A_BULLETS
];
4080 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[1, A_SHELLS
];
4081 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[1, A_ROCKETS
];
4082 FMaxAmmo
[A_CELLS
] := AmmoLimits
[1, A_CELLS
];
4083 FMaxAmmo
[A_FUEL
] := AmmoLimits
[1, A_FUEL
];
4085 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
4086 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
4087 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
4088 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4089 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
4090 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
4091 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
4092 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
4094 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
4097 if gFlash
= 2 then Inc(FPickup
, 5);
4101 if not(R_KEY_RED
in FRulez
) then
4103 Include(FRulez
, R_KEY_RED
);
4105 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
4106 if gFlash
= 2 then Inc(FPickup
, 5);
4107 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
4111 if not(R_KEY_GREEN
in FRulez
) then
4113 Include(FRulez
, R_KEY_GREEN
);
4115 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
4116 if gFlash
= 2 then Inc(FPickup
, 5);
4117 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
4121 if not(R_KEY_BLUE
in FRulez
) then
4123 Include(FRulez
, R_KEY_BLUE
);
4125 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
4126 if gFlash
= 2 then Inc(FPickup
, 5);
4127 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
4131 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
4133 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
4137 if gFlash
= 2 then Inc(FPickup
, 5);
4141 if FAir
< AIR_MAX
then
4146 if gFlash
= 2 then Inc(FPickup
, 5);
4151 if not (R_BERSERK
in FRulez
) then
4153 Include(FRulez
, R_BERSERK
);
4154 if allowBerserkSwitching
then
4156 FCurrWeap
:= WEAPON_KASTET
;
4158 FModel
.SetWeapon(WEAPON_KASTET
);
4163 if gFlash
= 2 then Inc(FPickup
, 5);
4165 FBerserk
:= gTime
+30000;
4170 if FHealth
< PLAYER_HP_SOFT
then
4172 FHealth
:= PLAYER_HP_SOFT
;
4173 FBerserk
:= gTime
+30000;
4181 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
4183 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
4186 if gFlash
= 2 then Inc(FPickup
, 5);
4190 if FHealth
< PLAYER_HP_LIMIT
then
4192 IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
4196 if gFlash
= 2 then Inc(FPickup
, 5);
4200 if FArmor
< PLAYER_AP_LIMIT
then
4202 IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
4205 if gFlash
= 2 then Inc(FPickup
, 5);
4209 if FJetFuel
< JET_MAX
then
4211 FJetFuel
:= JET_MAX
;
4214 if gFlash
= 2 then Inc(FPickup
, 5);
4218 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
4220 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
4223 if gFlash
= 2 then Inc(FPickup
, 5);
4228 procedure TPlayer
.Touch();
4232 //FModel.PlaySound(MODELSOUND_PAIN, 1, FObj.X, FObj.Y);
4235 // Áðîñèòü ôëàã òîâàðèùó:
4236 if gGameSettings
.GameMode
= GM_CTF
then
4241 procedure TPlayer
.Push(vx
, vy
: Integer);
4243 if (not FPhysics
) and FGhost
then
4245 FObj
.Accel
.X
:= FObj
.Accel
.X
+ vx
;
4246 FObj
.Accel
.Y
:= FObj
.Accel
.Y
+ vy
;
4247 if g_Game_IsNet
and g_Game_IsServer
then
4248 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
4251 procedure TPlayer
.Reset(Force
: Boolean);
4257 FTime
[T_RESPAWN
] := 0;
4258 FTime
[T_FLAGCAP
] := 0;
4271 FSpectator
:= False;
4274 FSpectatePlayer
:= -1;
4275 FNoRespawn
:= False;
4277 FLives
:= gGameSettings
.MaxLives
;
4282 procedure TPlayer
.SoftReset();
4288 FBFGFireCounter
:= -1;
4296 SetAction(A_STAND
, True);
4299 function TPlayer
.GetRespawnPoint(): Byte;
4304 // Íà áóäóùåå: FSpawn - èãðîê óæå èãðàë è ïåðåðîæäàåòñÿ
4306 // Îäèíî÷íàÿ èãðà/êîîïåðàòèâ
4307 if gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
] then
4309 if (Self
= gPlayer1
) or (Self
= gPlayer2
) then
4311 // Òî÷êà ïîÿâëåíèÿ ñâîåãî èãðîêà
4312 if Self
= gPlayer1
then
4313 c
:= RESPAWNPOINT_PLAYER1
4315 c
:= RESPAWNPOINT_PLAYER2
;
4316 if g_Map_GetPointCount(c
) > 0 then
4322 // Òî÷êà ïîÿâëåíèÿ äðóãîãî èãðîêà
4323 if Self
= gPlayer1
then
4324 c
:= RESPAWNPOINT_PLAYER2
4326 c
:= RESPAWNPOINT_PLAYER1
;
4327 if g_Map_GetPointCount(c
) > 0 then
4334 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà (áîòà)
4335 if Random(2) = 0 then
4336 c
:= RESPAWNPOINT_PLAYER1
4338 c
:= RESPAWNPOINT_PLAYER2
;
4339 if g_Map_GetPointCount(c
) > 0 then
4346 // Òî÷êà ëþáîé èç êîìàíä
4347 if Random(2) = 0 then
4348 c
:= RESPAWNPOINT_RED
4350 c
:= RESPAWNPOINT_BLUE
;
4351 if g_Map_GetPointCount(c
) > 0 then
4358 c
:= RESPAWNPOINT_DM
;
4359 if g_Map_GetPointCount(c
) > 0 then
4367 if gGameSettings
.GameMode
= GM_DM
then
4370 c
:= RESPAWNPOINT_DM
;
4371 if g_Map_GetPointCount(c
) > 0 then
4377 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà
4378 if Random(2) = 0 then
4379 c
:= RESPAWNPOINT_PLAYER1
4381 c
:= RESPAWNPOINT_PLAYER2
;
4382 if g_Map_GetPointCount(c
) > 0 then
4388 // Òî÷êà ëþáîé èç êîìàíä
4389 if Random(2) = 0 then
4390 c
:= RESPAWNPOINT_RED
4392 c
:= RESPAWNPOINT_BLUE
;
4393 if g_Map_GetPointCount(c
) > 0 then
4401 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
4403 // Òî÷êà ñâîåé êîìàíäû
4404 c
:= RESPAWNPOINT_DM
;
4405 if FTeam
= TEAM_RED
then
4406 c
:= RESPAWNPOINT_RED
;
4407 if FTeam
= TEAM_BLUE
then
4408 c
:= RESPAWNPOINT_BLUE
;
4409 if g_Map_GetPointCount(c
) > 0 then
4416 c
:= RESPAWNPOINT_DM
;
4417 if g_Map_GetPointCount(c
) > 0 then
4423 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà
4424 if Random(2) = 0 then
4425 c
:= RESPAWNPOINT_PLAYER1
4427 c
:= RESPAWNPOINT_PLAYER2
;
4428 if g_Map_GetPointCount(c
) > 0 then
4434 // Òî÷êà äðóãîé êîìàíäû
4435 c
:= RESPAWNPOINT_DM
;
4436 if FTeam
= TEAM_RED
then
4437 c
:= RESPAWNPOINT_BLUE
;
4438 if FTeam
= TEAM_BLUE
then
4439 c
:= RESPAWNPOINT_RED
;
4440 if g_Map_GetPointCount(c
) > 0 then
4448 procedure TPlayer
.Respawn(Silent
: Boolean; Force
: Boolean = False);
4450 RespawnPoint
: TRespawnPoint
;
4456 FBFGFireCounter
:= -1;
4461 if not g_Game_IsServer
then
4465 FWantsInGame
:= True;
4466 FJustTeleported
:= True;
4469 FTime
[T_RESPAWN
] := 0;
4473 // if server changes MaxLives we gotta be ready
4474 if gGameSettings
.MaxLives
= 0 then FNoRespawn
:= False;
4476 // Åùå íåëüçÿ âîçðîäèòüñÿ:
4477 if FTime
[T_RESPAWN
] > gTime
then
4480 // Ïðîñðàë âñå æèçíè:
4483 if not FSpectator
then Spectate(True);
4484 FWantsInGame
:= True;
4488 if (gGameSettings
.GameType
<> GT_SINGLE
) and (gGameSettings
.GameMode
<> GM_COOP
) then
4489 begin // "Ñâîÿ èãðà"
4490 // Áåðñåðê íå ñîõðàíÿåòñÿ ìåæäó óðîâíÿìè:
4491 FRulez
:= FRulez
-[R_BERSERK
];
4493 else // "Îäèíî÷íàÿ èãðà"/"Êîîï"
4495 // Áåðñåðê è êëþ÷è íå ñîõðàíÿþòñÿ ìåæäó óðîâíÿìè:
4496 FRulez
:= FRulez
-[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
, R_BERSERK
];
4499 // Ïîëó÷àåì òî÷êó ñïàóíà èãðîêà:
4500 c
:= GetRespawnPoint();
4505 // Âîñêðåøåíèå áåç îðóæèÿ:
4508 FHealth
:= PLAYER_HP_SOFT
;
4514 for a
:= WP_FIRST
to WP_LAST
do
4516 FWeapon
[a
] := False;
4520 FWeapon
[WEAPON_PISTOL
] := True;
4521 FWeapon
[WEAPON_KASTET
] := True;
4522 FCurrWeap
:= WEAPON_PISTOL
;
4525 FModel
.SetWeapon(FCurrWeap
);
4527 for b
:= A_BULLETS
to A_HIGH
do
4530 FAmmo
[A_BULLETS
] := 50;
4532 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[0, A_BULLETS
];
4533 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[0, A_SHELLS
];
4534 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[0, A_SHELLS
];
4535 FMaxAmmo
[A_CELLS
] := AmmoLimits
[0, A_CELLS
];
4536 FMaxAmmo
[A_FUEL
] := AmmoLimits
[0, A_FUEL
];
4538 if gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
] then
4539 FRulez
:= [R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
]
4544 // Ïîëó÷àåì êîîðäèíàòû òî÷êè âîçðîæäåíèÿ:
4545 if not g_Map_GetPoint(c
, RespawnPoint
) then
4547 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
4551 // Óñòàíîâêà êîîðäèíàò è ñáðîñ âñåõ ïàðàìåòðîâ:
4552 FObj
.X
:= RespawnPoint
.X
-PLAYER_RECT
.X
;
4553 FObj
.Y
:= RespawnPoint
.Y
-PLAYER_RECT
.Y
;
4559 FDirection
:= RespawnPoint
.Direction
;
4560 if FDirection
= TDirection
.D_LEFT
then
4565 SetAction(A_STAND
, True);
4566 FModel
.Direction
:= FDirection
;
4568 for a
:= Low(FTime
) to High(FTime
) do
4571 for a
:= Low(FMegaRulez
) to High(FMegaRulez
) do
4576 FCanJetpack
:= False;
4582 // Àíèìàöèÿ âîçðîæäåíèÿ:
4583 if (not gLoadGameMode
) and (not Silent
) then
4584 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
4586 Anim
:= TAnimation
.Create(ID
, False, 3);
4587 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4588 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4592 FSpectator
:= False;
4595 FSpectatePlayer
:= -1;
4598 if (gPlayer1
= nil) and (gLMSPID1
= FUID
) then
4600 if (gPlayer2
= nil) and (gLMSPID2
= FUID
) then
4603 if g_Game_IsNet
then
4605 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
4606 MH_SEND_PlayerStats(FUID
, NET_EVERYONE
);
4608 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4609 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32,
4614 procedure TPlayer
.Spectate(NoMove
: Boolean = False);
4617 Kill(K_EXTRAHARDKILL
, FUID
, HIT_SOME
)
4618 else if (not NoMove
) then
4620 GameX
:= gMapInfo
.Width
div 2;
4621 GameY
:= gMapInfo
.Height
div 2;
4630 FWantsInGame
:= False;
4635 if Self
= gPlayer1
then
4640 if Self
= gPlayer2
then
4647 if g_Game_IsNet
then
4648 MH_SEND_PlayerStats(FUID
);
4651 procedure TPlayer
.SwitchNoClip
;
4655 FGhost
:= not FGhost
;
4656 FPhysics
:= not FGhost
;
4668 procedure TPlayer
.Run(Direction
: TDirection
);
4672 if MAX_RUNVEL
> 8 then
4676 if Direction
= TDirection
.D_LEFT
then
4678 if FObj
.Vel
.X
> -MAX_RUNVEL
then
4679 FObj
.Vel
.X
:= FObj
.Vel
.X
- (MAX_RUNVEL
shr 3);
4682 if FObj
.Vel
.X
< MAX_RUNVEL
then
4683 FObj
.Vel
.X
:= FObj
.Vel
.X
+ (MAX_RUNVEL
shr 3);
4685 // Âîçìîæíî, ïèíàåì êóñêè:
4686 if (FObj
.Vel
.X
<> 0) and (gGibs
<> nil) then
4688 b
:= Abs(FObj
.Vel
.X
);
4689 if b
> 1 then b
:= b
* (Random(8 div b
) + 1);
4690 for a
:= 0 to High(gGibs
) do
4692 if gGibs
[a
].alive
and
4693 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
+FObj
.Rect
.Height
-4,
4694 FObj
.Rect
.Width
, 8, @gGibs
[a
].Obj
) and (Random(3) = 0) then
4697 if FObj
.Vel
.X
< 0 then
4699 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)+120) // íàëåâî
4703 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)); // íàïðàâî
4705 gGibs
[a
].positionChanged(); // this updates spatial accelerators
4713 procedure TPlayer
.SeeDown();
4715 SetAction(A_SEEDOWN
);
4717 if FDirection
= TDirection
.D_LEFT
then FAngle
:= ANGLE_LEFTDOWN
else FAngle
:= ANGLE_RIGHTDOWN
;
4719 if FIncCam
> -120 then DecMin(FIncCam
, 5, -120);
4722 procedure TPlayer
.SeeUp();
4726 if FDirection
= TDirection
.D_LEFT
then FAngle
:= ANGLE_LEFTUP
else FAngle
:= ANGLE_RIGHTUP
;
4728 if FIncCam
< 120 then IncMax(FIncCam
, 5, 120);
4731 procedure TPlayer
.SetAction(Action
: Byte; Force
: Boolean = False);
4739 A_ATTACK
: Prior
:= 2;
4740 A_SEEUP
: Prior
:= 1;
4741 A_SEEDOWN
: Prior
:= 1;
4742 A_ATTACKUP
: Prior
:= 2;
4743 A_ATTACKDOWN
: Prior
:= 2;
4748 if (Prior
> FActionPrior
) or Force
then
4749 if not ((Prior
= 2) and (FCurrWeap
= WEAPON_SAW
)) then
4751 FActionPrior
:= Prior
;
4752 FActionAnim
:= Action
;
4753 FActionForce
:= Force
;
4754 FActionChanged
:= True;
4757 if Action
in [A_ATTACK
, A_ATTACKUP
, A_ATTACKDOWN
] then FModel
.SetFire(True);
4760 function TPlayer
.StayOnStep(XInc
, YInc
: Integer): Boolean;
4762 Result
:= not g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
-1,
4763 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False)
4764 and g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
,
4765 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False);
4768 function TPlayer
.TeleportTo(X
, Y
: Integer; silent
: Boolean; dir
: Byte): Boolean;
4775 if g_CollideLevel(X
, Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
) then
4777 g_Sound_PlayExAt('SOUND_GAME_NOTELEPORT', FObj
.X
, FObj
.Y
);
4778 if g_Game_IsServer
and g_Game_IsNet
then
4779 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_GAME_NOTELEPORT');
4783 FJustTeleported
:= True;
4788 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
4790 Anim
:= TAnimation
.Create(ID
, False, 3);
4793 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', FObj
.X
, FObj
.Y
);
4794 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4795 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4796 if g_Game_IsServer
and g_Game_IsNet
then
4797 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4798 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 1,
4802 FObj
.X
:= X
-PLAYER_RECT
.X
;
4803 FObj
.Y
:= Y
-PLAYER_RECT
.Y
;
4804 if FAlive
and FGhost
then
4810 if not g_Game_IsNet
then
4814 SetDirection(TDirection
.D_LEFT
);
4820 SetDirection(TDirection
.D_RIGHT
);
4826 if FDirection
= TDirection
.D_RIGHT
then
4828 SetDirection(TDirection
.D_LEFT
);
4833 SetDirection(TDirection
.D_RIGHT
);
4839 if not silent
and (Anim
<> nil) then
4841 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4842 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4845 if g_Game_IsServer
and g_Game_IsNet
then
4846 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4847 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 0,
4854 function nonz(a
: Single): Single;
4862 function TPlayer
.followCorpse(): Boolean;
4867 if FAlive
or FSpectator
then
4869 if (gCorpses
= nil) or (Length(gCorpses
) = 0) then
4871 for i
:= 0 to High(gCorpses
) do
4872 if gCorpses
[i
] <> nil then
4873 if gCorpses
[i
].FPlayerUID
= FUID
then
4876 FObj
.X
:= gCorpses
[i
].FObj
.X
;
4877 FObj
.Y
:= gCorpses
[i
].FObj
.Y
;
4878 FObj
.Vel
.X
:= gCorpses
[i
].FObj
.Vel
.X
;
4879 FObj
.Vel
.Y
:= gCorpses
[i
].FObj
.Vel
.Y
;
4880 FObj
.Accel
.X
:= gCorpses
[i
].FObj
.Accel
.X
;
4881 FObj
.Accel
.Y
:= gCorpses
[i
].FObj
.Accel
.Y
;
4886 procedure TPlayer
.Update();
4889 i
, ii
, wx
, wy
, xd
, yd
, k
: Integer;
4890 blockmon
, headwater
, dospawn
: Boolean;
4895 NetServer
:= g_Game_IsNet
and g_Game_IsServer
;
4896 AnyServer
:= g_Game_IsServer
;
4898 if g_Game_IsClient
and (NetInterpLevel
> 0) then
4899 DoLerp(NetInterpLevel
+ 1)
4905 if FClientID
>= 0 then
4907 FPing
:= NetClients
[FClientID
].Peer
^.lastRoundTripTime
;
4908 if NetClients
[FClientID
].Peer
^.packetsSent
> 0 then
4909 FLoss
:= Round(100*NetClients
[FClientID
].Peer
^.packetsLost
/NetClients
[FClientID
].Peer
^.packetsSent
)
4918 if FAlive
and (FPunchAnim
<> nil) then
4919 FPunchAnim
.Update();
4921 if FAlive
and (gFly
or FJetpack
) then
4924 if FDirection
= TDirection
.D_LEFT
then
4929 if FAlive
and (not FGhost
) then
4931 if FKeys
[KEY_UP
].Pressed
then
4933 if FKeys
[KEY_DOWN
].Pressed
then
4937 if (not (FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_DOWN
].Pressed
)) and
4940 i
:= g_basic
.Sign(FIncCam
);
4941 FIncCam
:= Abs(FIncCam
);
4942 DecMin(FIncCam
, 5, 0);
4943 FIncCam
:= FIncCam
*i
;
4946 // no need to do that each second frame, weapon queue will take care of it
4947 if FAlive
and FKeys
[KEY_NEXTWEAPON
].Pressed
and AnyServer
then NextWeapon();
4948 if FAlive
and FKeys
[KEY_PREVWEAPON
].Pressed
and AnyServer
then PrevWeapon();
4950 if gTime
mod (GAME_TICK
*2) <> 0 then
4952 if (FObj
.Vel
.X
= 0) and FAlive
then
4954 if FKeys
[KEY_LEFT
].Pressed
then
4955 Run(TDirection
.D_LEFT
);
4956 if FKeys
[KEY_RIGHT
].Pressed
then
4957 Run(TDirection
.D_RIGHT
);
4962 if not followCorpse() then
4963 g_Obj_Move(@FObj
, True, True, True);
4964 positionChanged(); // this updates spatial accelerators
4970 FActionChanged
:= False;
4974 // Let alive player do some actions
4975 if FKeys
[KEY_LEFT
].Pressed
then Run(TDirection
.D_LEFT
);
4976 if FKeys
[KEY_RIGHT
].Pressed
then Run(TDirection
.D_RIGHT
);
4977 //if FKeys[KEY_NEXTWEAPON].Pressed and AnyServer then NextWeapon();
4978 //if FKeys[KEY_PREVWEAPON].Pressed and AnyServer then PrevWeapon();
4979 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then Fire()
4985 if NetServer
then MH_SEND_PlayerStats(FUID
);
4988 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Use();
4989 if FKeys
[KEY_JUMP
].Pressed
then Jump()
4992 if AnyServer
and FJetpack
then
4996 if NetServer
then MH_SEND_PlayerStats(FUID
);
4998 FCanJetpack
:= True;
5005 for k
:= Low(FKeys
) to KEY_CHAT
-1 do
5007 if FKeys
[k
].Pressed
then
5015 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
5018 if (FTime
[T_RESPAWN
] <= gTime
) and
5019 gGameOn
and (not FAlive
) then
5021 if (g_Player_GetCount() > 1) then
5025 gExit
:= EXIT_RESTART
;
5030 // Dead spectator actions
5033 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Fire();
5034 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then
5038 if (FSpectatePlayer
>= High(gPlayers
)) then
5039 FSpectatePlayer
:= -1
5043 for I
:= FSpectatePlayer
+ 1 to High(gPlayers
) do
5044 if gPlayers
[I
] <> nil then
5045 if gPlayers
[I
].alive
then
5046 if gPlayers
[I
].UID
<> FUID
then
5048 FSpectatePlayer
:= I
;
5053 if not SetSpect
then FSpectatePlayer
:= -1;
5064 if FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_JUMP
].Pressed
then
5066 FYTo
:= FObj
.Y
- 32;
5067 FSpectatePlayer
:= -1;
5069 if FKeys
[KEY_DOWN
].Pressed
then
5071 FYTo
:= FObj
.Y
+ 32;
5072 FSpectatePlayer
:= -1;
5074 if FKeys
[KEY_LEFT
].Pressed
then
5076 FXTo
:= FObj
.X
- 32;
5077 FSpectatePlayer
:= -1;
5079 if FKeys
[KEY_RIGHT
].Pressed
then
5081 FXTo
:= FObj
.X
+ 32;
5082 FSpectatePlayer
:= -1;
5085 if (FXTo
< -64) then
5087 else if (FXTo
> gMapInfo
.Width
+ 32) then
5088 FXTo
:= gMapInfo
.Width
+ 32;
5089 if (FYTo
< -72) then
5091 else if (FYTo
> gMapInfo
.Height
+ 32) then
5092 FYTo
:= gMapInfo
.Height
+ 32;
5097 if not followCorpse() then
5098 g_Obj_Move(@FObj
, True, True, True);
5099 positionChanged(); // this updates spatial accelerators
5106 if (FSpectatePlayer
<= High(gPlayers
)) and (FSpectatePlayer
>= 0) then
5107 if gPlayers
[FSpectatePlayer
] <> nil then
5108 if gPlayers
[FSpectatePlayer
].alive
then
5110 FXTo
:= gPlayers
[FSpectatePlayer
].GameX
;
5111 FYTo
:= gPlayers
[FSpectatePlayer
].GameY
;
5115 blockmon
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
, FObj
.Y
+PLAYER_HEADRECT
.Y
,
5116 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
5117 PANEL_BLOCKMON
, True);
5118 headwater
:= HeadInLiquid(0, 0);
5120 // Ñîïðîòèâëåíèå âîçäóõà:
5121 if (not FAlive
) or not (FKeys
[KEY_LEFT
].Pressed
or FKeys
[KEY_RIGHT
].Pressed
) then
5122 if FObj
.Vel
.X
<> 0 then
5123 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
5125 if (FLastHit
= HIT_TRAP
) and (FPain
> 90) then FPain
:= 90;
5126 DecMin(FPain
, 5, 0);
5127 DecMin(FPickup
, 1, 0);
5129 if FAlive
and (FObj
.Y
> Integer(gMapInfo
.Height
)+128) and AnyServer
then
5131 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
5132 FMegaRulez
[MR_SUIT
] := 0;
5133 FMegaRulez
[MR_INVUL
] := 0;
5134 FMegaRulez
[MR_INVIS
] := 0;
5135 Kill(K_FALLKILL
, 0, HIT_FALL
);
5142 if FCurrWeap
= WEAPON_SAW
then
5143 if not (FSawSound
.IsPlaying() or FSawSoundHit
.IsPlaying() or
5144 FSawSoundSelect
.IsPlaying()) then
5145 FSawSoundIdle
.PlayAt(FObj
.X
, FObj
.Y
);
5148 if (not FJetSoundFly
.IsPlaying()) and (not FJetSoundOn
.IsPlaying()) and
5149 (not FJetSoundOff
.IsPlaying()) then
5151 FJetSoundFly
.SetPosition(0);
5152 FJetSoundFly
.PlayAt(FObj
.X
, FObj
.Y
);
5155 for b
:= WP_FIRST
to WP_LAST
do
5156 if FReloading
[b
] > 0 then
5162 if FShellTimer
> -1 then
5163 if FShellTimer
= 0 then
5165 if FShellType
= SHELL_SHELL
then
5166 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5167 GameVelX
, GameVelY
-2, SHELL_SHELL
)
5168 else if FShellType
= SHELL_DBLSHELL
then
5170 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5171 GameVelX
+1, GameVelY
-2, SHELL_SHELL
);
5172 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5173 GameVelX
-1, GameVelY
-2, SHELL_SHELL
);
5176 end else Dec(FShellTimer
);
5178 if (FBFGFireCounter
> -1) then
5179 if FBFGFireCounter
= 0 then
5183 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
5184 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
5185 xd
:= wx
+IfThen(FDirection
= TDirection
.D_LEFT
, -30, 30);
5186 yd
:= wy
+firediry();
5187 g_Weapon_bfgshot(wx
, wy
, xd
, yd
, FUID
);
5188 if NetServer
then MH_SEND_PlayerFire(FUID
, WEAPON_BFG
, wx
, wy
, xd
, yd
);
5189 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
5190 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
5191 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
5194 FReloading
[WEAPON_BFG
] := WEAPON_RELOAD
[WEAPON_BFG
];
5195 FBFGFireCounter
:= -1;
5198 FBFGFireCounter
:= 0
5200 Dec(FBFGFireCounter
);
5202 if (FMegaRulez
[MR_SUIT
] < gTime
) and AnyServer
then
5204 b
:= g_GetAcidHit(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
);
5206 if (b
> 0) and (gTime
mod (15*GAME_TICK
) = 0) then Damage(b
, 0, 0, 0, HIT_ACID
);
5209 if (headwater
or blockmon
) then
5215 if AnyServer
then Damage(10, 0, 0, 0, HIT_WATER
);
5218 else if (FAir
mod 31 = 0) and not blockmon
then
5220 g_GFX_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2), FObj
.Y
+PLAYER_RECT
.Y
-4, 5+Random(6), 8, 4);
5221 if Random(2) = 0 then
5222 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
5224 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
5226 end else if FAir
< AIR_DEF
then
5229 if FFireTime
> 0 then
5231 if BodyInLiquid(0, 0) then
5236 else if FMegaRulez
[MR_SUIT
] >= gTime
then
5238 if FMegaRulez
[MR_SUIT
] = gTime
then
5245 if FFirePainTime
<= 0 then
5247 if g_Game_IsServer
then
5248 Damage(5, FFireAttacker
, 0, 0, HIT_FLAME
);
5249 FFirePainTime
:= 18;
5251 FFirePainTime
:= FFirePainTime
- 1;
5252 FFireTime
:= FFireTime
- 1;
5253 if (FFireTime
= 0) and g_Game_IsNet
and g_Game_IsServer
then
5254 MH_SEND_PlayerStats(FUID
);
5258 if FDamageBuffer
> 0 then
5260 if FDamageBuffer
>= 9 then
5264 if FDamageBuffer
< 30 then i
:= 9
5265 else if FDamageBuffer
< 100 then i
:= 18
5269 ii
:= Round(FDamageBuffer
*FHealth
/ nonz(FArmor
*(3/4)+FHealth
));
5270 FArmor
:= FArmor
-(FDamageBuffer
-ii
);
5271 FHealth
:= FHealth
-ii
;
5274 FHealth
:= FHealth
+FArmor
;
5279 if FHealth
<= 0 then
5280 if FHealth
> -30 then Kill(K_SIMPLEKILL
, FLastSpawnerUID
, FLastHit
)
5281 else if FHealth
> -50 then Kill(K_HARDKILL
, FLastSpawnerUID
, FLastHit
)
5282 else Kill(K_EXTRAHARDKILL
, FLastSpawnerUID
, FLastHit
);
5286 if FDamageBuffer
<= 20 then FModel
.PlaySound(MODELSOUND_PAIN
, 1, FObj
.X
, FObj
.Y
)
5287 else if FDamageBuffer
<= 55 then FModel
.PlaySound(MODELSOUND_PAIN
, 2, FObj
.X
, FObj
.Y
)
5288 else if FDamageBuffer
<= 120 then FModel
.PlaySound(MODELSOUND_PAIN
, 3, FObj
.X
, FObj
.Y
)
5289 else FModel
.PlaySound(MODELSOUND_PAIN
, 4, FObj
.X
, FObj
.Y
);
5296 end; // if FAlive then ...
5298 if (FActionAnim
= A_PAIN
) and (FModel
.Animation
<> A_PAIN
) then
5300 FModel
.ChangeAnimation(FActionAnim
, FActionForce
);
5301 FModel
.GetCurrentAnimation
.MinLength
:= i
;
5302 FModel
.GetCurrentAnimationMask
.MinLength
:= i
;
5303 end else FModel
.ChangeAnimation(FActionAnim
, FActionForce
and (FModel
.Animation
<> A_STAND
));
5305 if (FModel
.GetCurrentAnimation
.Played
or ((not FActionChanged
) and (FModel
.Animation
= A_WALK
)))
5306 then SetAction(A_STAND
, True);
5308 if not ((FModel
.Animation
= A_WALK
) and (Abs(FObj
.Vel
.X
) < 4) and not FModel
.Fire
) then FModel
.Update
;
5310 for b
:= Low(FKeys
) to High(FKeys
) do
5311 if FKeys
[b
].Time
= 0 then FKeys
[b
].Pressed
:= False else Dec(FKeys
[b
].Time
);
5315 procedure TPlayer
.getMapBox (out x
, y
, w
, h
: Integer); inline;
5317 x
:= FObj
.X
+PLAYER_RECT
.X
;
5318 y
:= FObj
.Y
+PLAYER_RECT
.Y
;
5319 w
:= PLAYER_RECT
.Width
;
5320 h
:= PLAYER_RECT
.Height
;
5324 procedure TPlayer
.moveBy (dx
, dy
: Integer); inline;
5326 if (dx
<> 0) or (dy
<> 0) then
5335 function TPlayer
.Collide(X
, Y
: Integer; Width
, Height
: Word): Boolean;
5337 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
5338 FObj
.Y
+PLAYER_RECT
.Y
,
5345 function TPlayer
.Collide(Panel
: TPanel
): Boolean;
5347 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
5348 FObj
.Y
+PLAYER_RECT
.Y
,
5352 Panel
.Width
, Panel
.Height
);
5355 function TPlayer
.Collide(X
, Y
: Integer): Boolean;
5357 X
:= X
-FObj
.X
-PLAYER_RECT
.X
;
5358 Y
:= Y
-FObj
.Y
-PLAYER_RECT
.Y
;
5359 Result
:= (x
>= 0) and (x
<= PLAYER_RECT
.Width
) and
5360 (y
>= 0) and (y
<= PLAYER_RECT
.Height
);
5363 function g_Player_ValidName(Name
: string): Boolean;
5369 if gPlayers
= nil then Exit
;
5371 for a
:= 0 to High(gPlayers
) do
5372 if gPlayers
[a
] <> nil then
5373 if LowerCase(Name
) = LowerCase(gPlayers
[a
].FName
) then
5380 procedure TPlayer
.SetDirection(Direction
: TDirection
);
5384 d
:= FModel
.Direction
;
5386 FModel
.Direction
:= Direction
;
5387 if d
<> Direction
then FModel
.ChangeAnimation(FModel
.Animation
, True);
5389 FDirection
:= Direction
;
5392 function TPlayer
.GetKeys(): Byte;
5396 if R_KEY_RED
in FRulez
then Result
:= KEY_RED
;
5397 if R_KEY_GREEN
in FRulez
then Result
:= Result
or KEY_GREEN
;
5398 if R_KEY_BLUE
in FRulez
then Result
:= Result
or KEY_BLUE
;
5400 if FTeam
= TEAM_RED
then Result
:= Result
or KEY_REDTEAM
;
5401 if FTeam
= TEAM_BLUE
then Result
:= Result
or KEY_BLUETEAM
;
5404 procedure TPlayer
.Use();
5408 if FTime
[T_USE
] > gTime
then Exit
;
5410 g_Triggers_PressR(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
,
5411 PLAYER_RECT
.Height
, FUID
, ACTIVATE_PLAYERPRESS
);
5413 for a
:= 0 to High(gPlayers
) do
5414 if (gPlayers
[a
] <> nil) and (gPlayers
[a
] <> Self
) and
5415 gPlayers
[a
].alive
and SameTeam(FUID
, gPlayers
[a
].FUID
) and
5416 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
5417 FObj
.Rect
.Width
, FObj
.Rect
.Height
, @gPlayers
[a
].FObj
) then
5419 gPlayers
[a
].Touch();
5420 if g_Game_IsNet
and g_Game_IsServer
then
5421 MH_SEND_GameEvent(NET_EV_PLAYER_TOUCH
, gPlayers
[a
].FUID
);
5424 FTime
[T_USE
] := gTime
+120;
5427 procedure TPlayer
.NetFire(Wpn
: Byte; X
, Y
, AX
, AY
: Integer; WID
: Integer = -1);
5431 WX
, WY
, XD
, YD
: Integer;
5443 if R_BERSERK
in FRulez
then
5445 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
5446 locobj
.X
:= FObj
.X
+FObj
.Rect
.X
;
5447 locobj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
5450 locobj
.rect
.Width
:= 39;
5451 locobj
.rect
.Height
:= 52;
5452 locobj
.Vel
.X
:= (xd
-wx
) div 2;
5453 locobj
.Vel
.Y
:= (yd
-wy
) div 2;
5454 locobj
.Accel
.X
:= xd
-wx
;
5455 locobj
.Accel
.y
:= yd
-wy
;
5457 if g_Weapon_Hit(@locobj
, 50, FUID
, HIT_SOME
) <> 0 then
5458 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
5460 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
5464 FPain
:= min(FPain
+ 25, 50);
5466 g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
5471 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
5472 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
5474 FSawSoundSelect
.Stop();
5476 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
5478 else if not FSawSoundHit
.IsPlaying() then
5480 FSawSoundSelect
.Stop();
5481 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
5488 g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', GameX
, Gamey
);
5489 FFireAngle
:= FAngle
;
5491 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5492 GameVelX
, GameVelY
-2, SHELL_BULLET
);
5497 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
5498 FFireAngle
:= FAngle
;
5501 FShellType
:= SHELL_SHELL
;
5506 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN2', Gamex
, Gamey
);
5507 FFireAngle
:= FAngle
;
5510 FShellType
:= SHELL_DBLSHELL
;
5515 g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', Gamex
, Gamey
);
5516 FFireAngle
:= FAngle
;
5518 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5519 GameVelX
, GameVelY
-2, SHELL_BULLET
);
5522 WEAPON_ROCKETLAUNCHER
:
5524 g_Weapon_Rocket(wx
, wy
, xd
, yd
, FUID
, WID
);
5525 FFireAngle
:= FAngle
;
5531 g_Weapon_Plasma(wx
, wy
, xd
, yd
, FUID
, WID
);
5532 FFireAngle
:= FAngle
;
5538 g_Weapon_BFGShot(wx
, wy
, xd
, yd
, FUID
, WID
);
5539 FFireAngle
:= FAngle
;
5543 WEAPON_SUPERPULEMET
:
5545 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
5546 FFireAngle
:= FAngle
;
5548 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5549 GameVelX
, GameVelY
-2, SHELL_SHELL
);
5552 WEAPON_FLAMETHROWER
:
5554 g_Weapon_flame(wx
, wy
, xd
, yd
, FUID
, WID
);
5556 FFireAngle
:= FAngle
;
5563 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
5564 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
5565 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
5568 procedure TPlayer
.DoLerp(Level
: Integer = 2);
5570 if FObj
.X
<> FXTo
then FObj
.X
:= Lerp(FObj
.X
, FXTo
, Level
);
5571 if FObj
.Y
<> FYTo
then FObj
.Y
:= Lerp(FObj
.Y
, FYTo
, Level
);
5574 procedure TPlayer
.SetLerp(XTo
, YTo
: Integer);
5578 if NetInterpLevel
< 1 then
5588 AX
:= Abs(FXTo
- FObj
.X
);
5589 AY
:= Abs(FYTo
- FObj
.Y
);
5590 if (AX
> 32) or (AX
<= NetInterpLevel
) then
5592 if (AY
> 32) or (AY
<= NetInterpLevel
) then
5597 function TPlayer
.FullInLift(XInc
, YInc
: Integer): Integer;
5599 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5600 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5601 PANEL_LIFTUP
, False) then Result
:= -1
5603 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5604 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5605 PANEL_LIFTDOWN
, False) then Result
:= 1
5609 function TPlayer
.GetFlag(Flag
: Byte): Boolean;
5616 if Flag
= FLAG_NONE
then
5619 if not g_Game_IsServer
then Exit
;
5621 // Ïðèíåñ ÷óæîé ôëàã íà ñâîþ áàçó:
5622 if (Flag
= FTeam
) and
5623 (gFlags
[Flag
].State
= FLAG_STATE_NORMAL
) and
5624 (FFlag
<> FLAG_NONE
) then
5626 if FFlag
= FLAG_RED
then
5627 s
:= _lc
[I_PLAYER_FLAG_RED
]
5629 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5631 evtype
:= FLAG_STATE_SCORED
;
5633 ts
:= Format('%.4d', [gFlags
[FFlag
].CaptureTime
]);
5634 Insert('.', ts
, Length(ts
) + 1 - 3);
5635 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_CAPTURE
], [FName
, s
, ts
]), True);
5637 g_Map_ResetFlag(FFlag
);
5638 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_CAPTURE
], [AnsiUpperCase(s
)]), 144);
5640 if ((Self
= gPlayer1
) or (Self
= gPlayer2
)
5641 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= FTeam
))
5642 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= FTeam
))) then
5647 if not sound_cap_flag
[a
].IsPlaying() then
5648 sound_cap_flag
[a
].Play();
5650 gTeamStat
[FTeam
].Goals
:= gTeamStat
[FTeam
].Goals
+ 1;
5653 if g_Game_IsNet
then
5655 MH_SEND_FlagEvent(evtype
, FFlag
, FUID
, False);
5659 gFlags
[FFlag
].CaptureTime
:= 0;
5664 // Ïîäîáðàë ñâîé ôëàã - âåðíóë åãî íà áàçó:
5665 if (Flag
= FTeam
) and
5666 (gFlags
[Flag
].State
= FLAG_STATE_DROPPED
) then
5668 if Flag
= FLAG_RED
then
5669 s
:= _lc
[I_PLAYER_FLAG_RED
]
5671 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5673 evtype
:= FLAG_STATE_RETURNED
;
5674 gFlags
[Flag
].CaptureTime
:= 0;
5676 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_RETURN
], [FName
, s
]), True);
5678 g_Map_ResetFlag(Flag
);
5679 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
5681 if ((Self
= gPlayer1
) or (Self
= gPlayer2
)
5682 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= FTeam
))
5683 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= FTeam
))) then
5688 if not sound_ret_flag
[a
].IsPlaying() then
5689 sound_ret_flag
[a
].Play();
5692 if g_Game_IsNet
then
5694 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5700 // Ïîäîáðàë ÷óæîé ôëàã:
5701 if (Flag
<> FTeam
) and (FTime
[T_FLAGCAP
] <= gTime
) then
5705 if Flag
= FLAG_RED
then
5706 s
:= _lc
[I_PLAYER_FLAG_RED
]
5708 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5710 evtype
:= FLAG_STATE_CAPTURED
;
5712 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_GET
], [FName
, s
]), True);
5714 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_GET
], [AnsiUpperCase(s
)]), 144);
5716 gFlags
[Flag
].State
:= FLAG_STATE_CAPTURED
;
5718 if ((Self
= gPlayer1
) or (Self
= gPlayer2
)
5719 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= FTeam
))
5720 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= FTeam
))) then
5725 if not sound_get_flag
[a
].IsPlaying() then
5726 sound_get_flag
[a
].Play();
5729 if g_Game_IsNet
then
5731 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5737 procedure TPlayer
.SetFlag(Flag
: Byte);
5740 if FModel
<> nil then
5741 FModel
.SetFlag(FFlag
);
5744 function TPlayer
.DropFlag(Silent
: Boolean = True): Boolean;
5750 if (not g_Game_IsServer
) or (FFlag
= FLAG_NONE
) then
5752 FTime
[T_FLAGCAP
] := gTime
+ 2000;
5753 with gFlags
[FFlag
] do
5757 Direction
:= FDirection
;
5758 State
:= FLAG_STATE_DROPPED
;
5760 g_Obj_Push(@Obj
, (FObj
.Vel
.X
div 2)-2+Random(5),
5761 (FObj
.Vel
.Y
div 2)-2+Random(5));
5762 positionChanged(); // this updates spatial accelerators
5764 if FFlag
= FLAG_RED
then
5765 s
:= _lc
[I_PLAYER_FLAG_RED
]
5767 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5769 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_DROP
], [FName
, s
]), True);
5770 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_DROP
], [AnsiUpperCase(s
)]), 144);
5772 if ((Self
= gPlayer1
) or (Self
= gPlayer2
)
5773 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= FTeam
))
5774 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= FTeam
))) then
5779 if (not Silent
) and (not sound_lost_flag
[a
].IsPlaying()) then
5780 sound_lost_flag
[a
].Play();
5782 if g_Game_IsNet
then
5783 MH_SEND_FlagEvent(FLAG_STATE_DROPPED
, Flag
, FUID
, False);
5789 procedure TPlayer
.GetSecret();
5794 procedure TPlayer
.PressKey(Key
: Byte; Time
: Word = 1);
5796 Assert(Key
<= High(FKeys
));
5798 FKeys
[Key
].Pressed
:= True;
5799 FKeys
[Key
].Time
:= Time
;
5802 function TPlayer
.IsKeyPressed(K
: Byte): Boolean;
5804 Result
:= FKeys
[K
].Pressed
;
5807 procedure TPlayer
.ReleaseKeys();
5811 for a
:= Low(FKeys
) to High(FKeys
) do
5813 FKeys
[a
].Pressed
:= False;
5818 procedure TPlayer
.OnDamage(Angle
: SmallInt);
5822 function TPlayer
.firediry(): Integer;
5824 if FKeys
[KEY_UP
].Pressed
then Result
:= -42
5825 else if FKeys
[KEY_DOWN
].Pressed
then Result
:= 19
5829 procedure TPlayer
.RememberState();
5833 FSavedState
.Health
:= FHealth
;
5834 FSavedState
.Armor
:= FArmor
;
5835 FSavedState
.Air
:= FAir
;
5836 FSavedState
.JetFuel
:= FJetFuel
;
5837 FSavedState
.CurrWeap
:= FCurrWeap
;
5838 FSavedState
.NextWeap
:= FNextWeap
;
5839 FSavedState
.NextWeapDelay
:= FNextWeapDelay
;
5842 FSavedState
.Ammo
[i
] := FAmmo
[i
];
5844 FSavedState
.MaxAmmo
[i
] := FMaxAmmo
[i
];
5846 FSavedState
.Rulez
:= FRulez
;
5847 FSavedState
.WaitRecall
:= True;
5850 procedure TPlayer
.RecallState();
5854 if not FSavedState
.WaitRecall
then Exit
;
5856 FHealth
:= FSavedState
.Health
;
5857 FArmor
:= FSavedState
.Armor
;
5858 FAir
:= FSavedState
.Air
;
5859 FJetFuel
:= FSavedState
.JetFuel
;
5860 FCurrWeap
:= FSavedState
.CurrWeap
;
5861 FNextWeap
:= FSavedState
.NextWeap
;
5862 FNextWeapDelay
:= FSavedState
.NextWeapDelay
;
5865 FAmmo
[i
] := FSavedState
.Ammo
[i
];
5867 FMaxAmmo
[i
] := FSavedState
.MaxAmmo
[i
];
5869 FRulez
:= FSavedState
.Rulez
;
5870 FSavedState
.WaitRecall
:= False;
5872 if gGameSettings
.GameType
= GT_SERVER
then
5873 MH_SEND_PlayerStats(FUID
);
5876 procedure TPlayer
.SaveState (st
: TStream
);
5882 utils
.writeSign(st
, 'PLYR');
5883 utils
.writeInt(st
, Byte(PLR_SAVE_VERSION
)); // version
5885 utils
.writeBool(st
, FIamBot
);
5887 utils
.writeInt(st
, Word(FUID
));
5889 utils
.writeStr(st
, FName
);
5891 utils
.writeInt(st
, Byte(FTeam
));
5893 utils
.writeBool(st
, FAlive
);
5894 // Èçðàñõîäîâàë ëè âñå æèçíè
5895 utils
.writeBool(st
, FNoRespawn
);
5897 if FDirection
= TDirection
.D_LEFT
then b
:= 1 else b
:= 2; // D_RIGHT
5898 utils
.writeInt(st
, Byte(b
));
5900 utils
.writeInt(st
, LongInt(FHealth
));
5902 utils
.writeInt(st
, Byte(FLives
));
5904 utils
.writeInt(st
, LongInt(FArmor
));
5906 utils
.writeInt(st
, LongInt(FAir
));
5908 utils
.writeInt(st
, LongInt(FJetFuel
));
5910 utils
.writeInt(st
, LongInt(FPain
));
5912 utils
.writeInt(st
, LongInt(FKills
));
5914 utils
.writeInt(st
, LongInt(FMonsterKills
));
5916 utils
.writeInt(st
, LongInt(FFrags
));
5918 utils
.writeInt(st
, Byte(FFragCombo
));
5919 // Âðåìÿ ïîñëåäíåãî ôðàãà
5920 utils
.writeInt(st
, LongWord(FLastFrag
));
5922 utils
.writeInt(st
, LongInt(FDeath
));
5924 utils
.writeInt(st
, Byte(FFlag
));
5926 utils
.writeInt(st
, LongInt(FSecrets
));
5928 utils
.writeInt(st
, Byte(FCurrWeap
));
5930 utils
.writeInt(st
, Word(FNextWeap
));
5932 utils
.writeInt(st
, Byte(FNextWeapDelay
));
5933 // Âðåìÿ çàðÿäêè BFG
5934 utils
.writeInt(st
, SmallInt(FBFGFireCounter
));
5936 utils
.writeInt(st
, LongInt(FDamageBuffer
));
5937 // Ïîñëåäíèé óäàðèâøèé
5938 utils
.writeInt(st
, Word(FLastSpawnerUID
));
5939 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà
5940 utils
.writeInt(st
, Byte(FLastHit
));
5942 Obj_SaveState(st
, @FObj
);
5943 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ
5944 for i
:= A_BULLETS
to A_HIGH
do utils
.writeInt(st
, Word(FAmmo
[i
]));
5945 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ
5946 for i
:= A_BULLETS
to A_HIGH
do utils
.writeInt(st
, Word(FMaxAmmo
[i
]));
5948 for i
:= WP_FIRST
to WP_LAST
do utils
.writeBool(st
, FWeapon
[i
]);
5949 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ
5950 for i
:= WP_FIRST
to WP_LAST
do utils
.writeInt(st
, Word(FReloading
[i
]));
5952 utils
.writeBool(st
, (R_ITEM_BACKPACK
in FRulez
));
5953 // Íàëè÷èå êðàñíîãî êëþ÷à
5954 utils
.writeBool(st
, (R_KEY_RED
in FRulez
));
5955 // Íàëè÷èå çåëåíîãî êëþ÷à
5956 utils
.writeBool(st
, (R_KEY_GREEN
in FRulez
));
5957 // Íàëè÷èå ñèíåãî êëþ÷à
5958 utils
.writeBool(st
, (R_KEY_BLUE
in FRulez
));
5960 utils
.writeBool(st
, (R_BERSERK
in FRulez
));
5961 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ
5962 for i
:= MR_SUIT
to MR_MAX
do utils
.writeInt(st
, LongWord(FMegaRulez
[i
]));
5963 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà
5964 for i
:= T_RESPAWN
to T_FLAGCAP
do utils
.writeInt(st
, LongWord(FTime
[i
]));
5966 utils
.writeStr(st
, FModel
.Name
);
5968 utils
.writeInt(st
, Byte(FColor
.R
));
5969 utils
.writeInt(st
, Byte(FColor
.G
));
5970 utils
.writeInt(st
, Byte(FColor
.B
));
5974 procedure TPlayer
.LoadState (st
: TStream
);
5983 if not utils
.checkSign(st
, 'PLYR') then raise XStreamError
.Create('invalid player signature');
5984 if (utils
.readByte(st
) <> PLR_SAVE_VERSION
) then raise XStreamError
.Create('invalid player version');
5986 FIamBot
:= utils
.readBool(st
);
5988 FUID
:= utils
.readWord(st
);
5990 str
:= utils
.readStr(st
);
5991 if (self
<> gPlayer1
) and (self
<> gPlayer2
) then FName
:= str
;
5993 FTeam
:= utils
.readByte(st
);
5995 FAlive
:= utils
.readBool(st
);
5996 // Èçðàñõîäîâàë ëè âñå æèçíè
5997 FNoRespawn
:= utils
.readBool(st
);
5999 b
:= utils
.readByte(st
);
6000 if b
= 1 then FDirection
:= TDirection
.D_LEFT
else FDirection
:= TDirection
.D_RIGHT
; // b = 2
6002 FHealth
:= utils
.readLongInt(st
);
6004 FLives
:= utils
.readByte(st
);
6006 FArmor
:= utils
.readLongInt(st
);
6008 FAir
:= utils
.readLongInt(st
);
6010 FJetFuel
:= utils
.readLongInt(st
);
6012 FPain
:= utils
.readLongInt(st
);
6014 FKills
:= utils
.readLongInt(st
);
6016 FMonsterKills
:= utils
.readLongInt(st
);
6018 FFrags
:= utils
.readLongInt(st
);
6020 FFragCombo
:= utils
.readByte(st
);
6021 // Âðåìÿ ïîñëåäíåãî ôðàãà
6022 FLastFrag
:= utils
.readLongWord(st
);
6024 FDeath
:= utils
.readLongInt(st
);
6026 FFlag
:= utils
.readByte(st
);
6028 FSecrets
:= utils
.readLongInt(st
);
6030 FCurrWeap
:= utils
.readByte(st
);
6032 FNextWeap
:= utils
.readWord(st
);
6034 FNextWeapDelay
:= utils
.readByte(st
);
6035 // Âðåìÿ çàðÿäêè BFG
6036 FBFGFireCounter
:= utils
.readSmallInt(st
);
6038 FDamageBuffer
:= utils
.readLongInt(st
);
6039 // Ïîñëåäíèé óäàðèâøèé
6040 FLastSpawnerUID
:= utils
.readWord(st
);
6041 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà
6042 FLastHit
:= utils
.readByte(st
);
6044 Obj_LoadState(@FObj
, st
);
6045 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ
6046 for i
:= A_BULLETS
to A_HIGH
do FAmmo
[i
] := utils
.readWord(st
);
6047 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ
6048 for i
:= A_BULLETS
to A_HIGH
do FMaxAmmo
[i
] := utils
.readWord(st
);
6050 for i
:= WP_FIRST
to WP_LAST
do FWeapon
[i
] := utils
.readBool(st
);
6051 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ
6052 for i
:= WP_FIRST
to WP_LAST
do FReloading
[i
] := utils
.readWord(st
);
6054 if utils
.readBool(st
) then Include(FRulez
, R_ITEM_BACKPACK
);
6055 // Íàëè÷èå êðàñíîãî êëþ÷à
6056 if utils
.readBool(st
) then Include(FRulez
, R_KEY_RED
);
6057 // Íàëè÷èå çåëåíîãî êëþ÷à
6058 if utils
.readBool(st
) then Include(FRulez
, R_KEY_GREEN
);
6059 // Íàëè÷èå ñèíåãî êëþ÷à
6060 if utils
.readBool(st
) then Include(FRulez
, R_KEY_BLUE
);
6062 if utils
.readBool(st
) then Include(FRulez
, R_BERSERK
);
6063 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ
6064 for i
:= MR_SUIT
to MR_MAX
do FMegaRulez
[i
] := utils
.readLongWord(st
);
6065 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà
6066 for i
:= T_RESPAWN
to T_FLAGCAP
do FTime
[i
] := utils
.readLongWord(st
);
6068 str
:= utils
.readStr(st
);
6070 FColor
.R
:= utils
.readByte(st
);
6071 FColor
.G
:= utils
.readByte(st
);
6072 FColor
.B
:= utils
.readByte(st
);
6073 if (self
= gPlayer1
) then
6075 str
:= gPlayer1Settings
.Model
;
6076 FColor
:= gPlayer1Settings
.Color
;
6078 else if (self
= gPlayer2
) then
6080 str
:= gPlayer2Settings
.Model
;
6081 FColor
:= gPlayer2Settings
.Color
;
6083 // Îáíîâëÿåì ìîäåëü èãðîêà
6085 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
6086 FModel
.Color
:= TEAMCOLOR
[FTeam
]
6088 FModel
.Color
:= FColor
;
6092 procedure TPlayer
.AllRulez(Health
: Boolean);
6098 FHealth
:= PLAYER_HP_LIMIT
;
6099 FArmor
:= PLAYER_AP_LIMIT
;
6103 for a
:= WP_FIRST
to WP_LAST
do FWeapon
[a
] := True;
6104 for a
:= A_BULLETS
to A_HIGH
do FAmmo
[a
] := 30000;
6105 FRulez
:= FRulez
+[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
];
6108 procedure TPlayer
.RestoreHealthArmor();
6110 FHealth
:= PLAYER_HP_LIMIT
;
6111 FArmor
:= PLAYER_AP_LIMIT
;
6114 procedure TPlayer
.FragCombo();
6118 if (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) or g_Game_IsClient
then
6120 if gTime
- FLastFrag
< FRAG_COMBO_TIME
then
6122 if FFragCombo
< 5 then
6124 Param
:= FUID
or (FFragCombo
shl 16);
6125 if (FComboEvnt
>= Low(gDelayedEvents
)) and
6126 (FComboEvnt
<= High(gDelayedEvents
)) and
6127 gDelayedEvents
[FComboEvnt
].Pending
and
6128 (gDelayedEvents
[FComboEvnt
].DEType
= DE_KILLCOMBO
) and
6129 (gDelayedEvents
[FComboEvnt
].DENum
and $FFFF = FUID
) then
6131 gDelayedEvents
[FComboEvnt
].Time
:= gTime
+ 500;
6132 gDelayedEvents
[FComboEvnt
].DENum
:= Param
;
6135 FComboEvnt
:= g_Game_DelayEvent(DE_KILLCOMBO
, 500, Param
);
6143 procedure TPlayer
.GiveItem(ItemType
: Byte);
6147 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
6149 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
6153 if FAir
< AIR_MAX
then
6160 if not (R_BERSERK
in FRulez
) then
6162 Include(FRulez
, R_BERSERK
);
6163 if FBFGFireCounter
< 1 then
6165 FCurrWeap
:= WEAPON_KASTET
;
6167 FModel
.SetWeapon(WEAPON_KASTET
);
6171 FBerserk
:= gTime
+30000;
6173 if FHealth
< PLAYER_HP_SOFT
then
6175 FHealth
:= PLAYER_HP_SOFT
;
6176 FBerserk
:= gTime
+30000;
6181 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
6183 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
6187 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
6189 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
6193 if FJetFuel
< JET_MAX
then
6195 FJetFuel
:= JET_MAX
;
6198 ITEM_MEDKIT_SMALL
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
6199 ITEM_MEDKIT_LARGE
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
6201 ITEM_ARMOR_GREEN
: if FArmor
< PLAYER_AP_SOFT
then FArmor
:= PLAYER_AP_SOFT
;
6202 ITEM_ARMOR_BLUE
: if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
6204 ITEM_SPHERE_BLUE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
6206 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) then
6208 if FHealth
< PLAYER_HP_LIMIT
then FHealth
:= PLAYER_HP_LIMIT
;
6209 if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
6212 ITEM_WEAPON_SAW
: FWeapon
[WEAPON_SAW
] := True;
6213 ITEM_WEAPON_SHOTGUN1
: FWeapon
[WEAPON_SHOTGUN1
] := True;
6214 ITEM_WEAPON_SHOTGUN2
: FWeapon
[WEAPON_SHOTGUN2
] := True;
6215 ITEM_WEAPON_CHAINGUN
: FWeapon
[WEAPON_CHAINGUN
] := True;
6216 ITEM_WEAPON_ROCKETLAUNCHER
: FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
6217 ITEM_WEAPON_PLASMA
: FWeapon
[WEAPON_PLASMA
] := True;
6218 ITEM_WEAPON_BFG
: FWeapon
[WEAPON_BFG
] := True;
6219 ITEM_WEAPON_SUPERPULEMET
: FWeapon
[WEAPON_SUPERPULEMET
] := True;
6220 ITEM_WEAPON_FLAMETHROWER
: FWeapon
[WEAPON_FLAMETHROWER
] := True;
6222 ITEM_AMMO_BULLETS
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
6223 ITEM_AMMO_BULLETS_BOX
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
6224 ITEM_AMMO_SHELLS
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
6225 ITEM_AMMO_SHELLS_BOX
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
6226 ITEM_AMMO_ROCKET
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
6227 ITEM_AMMO_ROCKET_BOX
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
6228 ITEM_AMMO_CELL
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
6229 ITEM_AMMO_CELL_BIG
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
6230 ITEM_AMMO_FUELCAN
: if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
6233 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
6234 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
6235 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
6236 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or
6237 (FMaxAmmo
[A_FUEL
] < AmmoLimits
[1, A_FUEL
]) then
6239 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[1, A_BULLETS
];
6240 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[1, A_SHELLS
];
6241 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[1, A_ROCKETS
];
6242 FMaxAmmo
[A_CELLS
] := AmmoLimits
[1, A_CELLS
];
6243 FMaxAmmo
[A_FUEL
] := AmmoLimits
[1, A_FUEL
];
6245 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
6246 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
6247 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
6248 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
6250 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
6253 ITEM_KEY_RED
: if not (R_KEY_RED
in FRulez
) then Include(FRulez
, R_KEY_RED
);
6254 ITEM_KEY_GREEN
: if not (R_KEY_GREEN
in FRulez
) then Include(FRulez
, R_KEY_GREEN
);
6255 ITEM_KEY_BLUE
: if not (R_KEY_BLUE
in FRulez
) then Include(FRulez
, R_KEY_BLUE
);
6257 ITEM_BOTTLE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
6258 ITEM_HELMET
: if FArmor
< PLAYER_AP_LIMIT
then IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
6263 if g_Game_IsNet
and g_Game_IsServer
then
6264 MH_SEND_PlayerStats(FUID
);
6267 procedure TPlayer
.FlySmoke(Times
: DWORD
= 1);
6272 if (Random(5) = 1) and (Times
= 1) then
6275 if BodyInLiquid(0, 0) then
6277 g_GFX_Bubbles(Obj
.X
+Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2)+Random(3)-1,
6278 Obj
.Y
+Obj
.Rect
.Height
+8, 1, 8, 4);
6279 if Random(2) = 0 then
6280 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
6282 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
6286 if g_Frames_Get(id
, 'FRAMES_SMOKE') then
6288 for i
:= 1 to Times
do
6290 Anim
:= TAnimation
.Create(id
, False, 3);
6292 g_GFX_OnceAnim(Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(Anim
.Width
div 2),
6293 Obj
.Y
+Obj
.Rect
.Height
-4+Random(8+Times
*2), Anim
, ONCEANIM_SMOKE
);
6299 procedure TPlayer
.OnFireFlame(Times
: DWORD
= 1);
6304 if (Random(10) = 1) and (Times
= 1) then
6307 if g_Frames_Get(id
, 'FRAMES_FLAME') then
6309 for i
:= 1 to Times
do
6311 Anim
:= TAnimation
.Create(id
, False, 3);
6313 g_GFX_OnceAnim(Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(Anim
.Width
div 2),
6314 Obj
.Y
+8+Random(8+Times
*2), Anim
, ONCEANIM_SMOKE
);
6320 procedure TPlayer
.PauseSounds(Enable
: Boolean);
6322 FSawSound
.Pause(Enable
);
6323 FSawSoundIdle
.Pause(Enable
);
6324 FSawSoundHit
.Pause(Enable
);
6325 FSawSoundSelect
.Pause(Enable
);
6326 FFlameSoundOn
.Pause(Enable
);
6327 FFlameSoundOff
.Pause(Enable
);
6328 FFlameSoundWork
.Pause(Enable
);
6329 FJetSoundFly
.Pause(Enable
);
6330 FJetSoundOn
.Pause(Enable
);
6331 FJetSoundOff
.Pause(Enable
);
6336 constructor TCorpse
.Create(X
, Y
: Integer; ModelName
: String; aMess
: Boolean);
6341 FObj
.Rect
:= PLAYER_CORPSERECT
;
6342 FModelName
:= ModelName
;
6347 FState
:= CORPSE_STATE_MESS
;
6348 g_PlayerModel_GetAnim(ModelName
, A_DIE2
, FAnimation
, FAnimationMask
);
6352 FState
:= CORPSE_STATE_NORMAL
;
6353 g_PlayerModel_GetAnim(ModelName
, A_DIE1
, FAnimation
, FAnimationMask
);
6357 destructor TCorpse
.Destroy();
6364 function TCorpse
.ObjPtr (): PObj
; inline; begin result
:= @FObj
; end;
6366 procedure TCorpse
.positionChanged (); inline; begin end;
6368 procedure TCorpse
.moveBy (dx
, dy
: Integer); inline;
6370 if (dx
<> 0) or (dy
<> 0) then
6379 procedure TCorpse
.getMapBox (out x
, y
, w
, h
: Integer); inline;
6381 x
:= FObj
.X
+PLAYER_CORPSERECT
.X
;
6382 y
:= FObj
.Y
+PLAYER_CORPSERECT
.Y
;
6383 w
:= PLAYER_CORPSERECT
.Width
;
6384 h
:= PLAYER_CORPSERECT
.Height
;
6388 procedure TCorpse
.Damage(Value
: Word; vx
, vy
: Integer);
6393 if FState
= CORPSE_STATE_REMOVEME
then
6396 FDamage
:= FDamage
+ Value
;
6398 if FDamage
> 150 then
6400 if FAnimation
<> nil then
6405 FState
:= CORPSE_STATE_REMOVEME
;
6407 g_Player_CreateGibs(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
6408 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2),
6409 FModelName
, FColor
);
6410 // Çâóê ìÿñà îò òðóïà:
6411 pm
:= g_PlayerModel_Get(FModelName
);
6412 pm
.PlaySound(MODELSOUND_DIE
, 5, FObj
.X
, FObj
.Y
);
6416 if (gBodyKillEvent
<> -1)
6417 and gDelayedEvents
[gBodyKillEvent
].Pending
then
6418 gDelayedEvents
[gBodyKillEvent
].Pending
:= False;
6419 gBodyKillEvent
:= g_Game_DelayEvent(DE_BODYKILL
, 1050, 0);
6424 Blood
:= g_PlayerModel_GetBlood(FModelName
);
6425 FObj
.Vel
.X
:= FObj
.Vel
.X
+ vx
;
6426 FObj
.Vel
.Y
:= FObj
.Vel
.Y
+ vy
;
6427 g_GFX_Blood(FObj
.X
+PLAYER_CORPSERECT
.X
+(PLAYER_CORPSERECT
.Width
div 2),
6428 FObj
.Y
+PLAYER_CORPSERECT
.Y
+(PLAYER_CORPSERECT
.Height
div 2),
6429 Value
, vx
, vy
, 16, (PLAYER_CORPSERECT
.Height
*2) div 3,
6430 Blood
.R
, Blood
.G
, Blood
.B
, Blood
.Kind
);
6434 procedure TCorpse
.Draw();
6436 if FState
= CORPSE_STATE_REMOVEME
then
6439 if FAnimation
<> nil then
6440 FAnimation
.Draw(FObj
.X
, FObj
.Y
, TMirrorType
.None
);
6442 if FAnimationMask
<> nil then
6445 FAnimationMask
.Draw(FObj
.X
, FObj
.Y
, TMirrorType
.None
);
6452 procedure TCorpse
.Update();
6456 if FState
= CORPSE_STATE_REMOVEME
then
6459 if gTime
mod (GAME_TICK
*2) <> 0 then
6461 g_Obj_Move(@FObj
, True, True, True);
6462 positionChanged(); // this updates spatial accelerators
6466 // Ñîïðîòèâëåíèå âîçäóõà äëÿ òðóïà:
6467 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
6469 st
:= g_Obj_Move(@FObj
, True, True, True);
6470 positionChanged(); // this updates spatial accelerators
6472 if WordBool(st
and MOVE_FALLOUT
) then
6474 FState
:= CORPSE_STATE_REMOVEME
;
6478 if FAnimation
<> nil then
6479 FAnimation
.Update();
6480 if FAnimationMask
<> nil then
6481 FAnimationMask
.Update();
6485 procedure TCorpse
.SaveState (st
: TStream
);
6492 utils
.writeSign(st
, 'CORP');
6493 utils
.writeInt(st
, Byte(0));
6495 utils
.writeInt(st
, Byte(FState
));
6497 utils
.writeInt(st
, Byte(FDamage
));
6499 utils
.writeInt(st
, Byte(FColor
.R
));
6500 utils
.writeInt(st
, Byte(FColor
.G
));
6501 utils
.writeInt(st
, Byte(FColor
.B
));
6503 Obj_SaveState(st
, @FObj
);
6504 utils
.writeInt(st
, Word(FPlayerUID
));
6506 anim
:= (FAnimation
<> nil);
6507 utils
.writeBool(st
, anim
);
6508 // Åñëè åñòü - ñîõðàíÿåì
6509 if anim
then FAnimation
.SaveState(st
);
6510 // Åñòü ëè ìàñêà àíèìàöèè
6511 anim
:= (FAnimationMask
<> nil);
6512 utils
.writeBool(st
, anim
);
6513 // Åñëè åñòü - ñîõðàíÿåì
6514 if anim
then FAnimationMask
.SaveState(st
);
6518 procedure TCorpse
.LoadState (st
: TStream
);
6525 if not utils
.checkSign(st
, 'CORP') then raise XStreamError
.Create('invalid corpse signature');
6526 if (utils
.readByte(st
) <> 0) then raise XStreamError
.Create('invalid corpse version');
6528 FState
:= utils
.readByte(st
);
6530 FDamage
:= utils
.readByte(st
);
6532 FColor
.R
:= utils
.readByte(st
);
6533 FColor
.G
:= utils
.readByte(st
);
6534 FColor
.B
:= utils
.readByte(st
);
6536 Obj_LoadState(@FObj
, st
);
6537 FPlayerUID
:= utils
.readWord(st
);
6539 anim
:= utils
.readBool(st
);
6540 // Åñëè åñòü - çàãðóæàåì
6543 Assert(FAnimation
<> nil, 'TCorpse.LoadState: no FAnimation');
6544 FAnimation
.LoadState(st
);
6546 // Åñòü ëè ìàñêà àíèìàöèè
6547 anim
:= utils
.readBool(st
);
6548 // Åñëè åñòü - çàãðóæàåì
6551 Assert(FAnimationMask
<> nil, 'TCorpse.LoadState: no FAnimationMask');
6552 FAnimationMask
.LoadState(st
);
6558 constructor TBot
.Create();
6565 FSpectator
:= False;
6572 for a
:= WP_FIRST
to WP_LAST
do
6574 FDifficult
.WeaponPrior
[a
] := WEAPON_PRIOR1
[a
];
6575 FDifficult
.CloseWeaponPrior
[a
] := WEAPON_PRIOR2
[a
];
6576 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
6580 destructor TBot
.Destroy();
6583 inherited Destroy();
6586 procedure TBot
.Draw();
6590 //if FTargetUID <> 0 then e_DrawLine(1, FObj.X, FObj.Y, g_Player_Get(FTargetUID).FObj.X,
6591 // g_Player_Get(FTargetUID).FObj.Y, 255, 0, 0);
6594 procedure TBot
.Respawn(Silent
: Boolean; Force
: Boolean = False);
6596 inherited Respawn(Silent
, Force
);
6599 FSelectedWeapon
:= FCurrWeap
;
6604 procedure TBot
.UpdateCombat();
6617 TTargetRecord
= array of TTarget
;
6619 function Compare(a
, b
: TTarget
): Integer;
6621 if a
.Line
and not b
.Line
then // A íà ëèíèè îãíÿ
6624 if not a
.Line
and b
.Line
then // B íà ëèíèè îãíÿ
6626 else // È A, è B íà ëèíèè èëè íå íà ëèíèè îãíÿ
6627 if (a
.Line
and b
.Line
) or ((not a
.Line
) and (not b
.Line
)) then
6629 if a
.Dist
> b
.Dist
then // B áëèæå
6631 else // A áëèæå èëè ðàâíîóäàëåííî ñ B
6634 else // Ñòðàííî -> A
6639 a
, x1
, y1
, x2
, y2
: Integer;
6640 targets
: TTargetRecord
;
6642 Target
, BestTarget
: TTarget
;
6643 firew
, fireh
: Integer;
6647 vsPlayer
, vsMonster
, ok
: Boolean;
6650 function monsUpdate (mon
: TMonster
): Boolean;
6652 result
:= false; // don't stop
6653 if mon
.alive
and (mon
.MonsterType
<> MONSTER_BARREL
) then
6655 if not TargetOnScreen(mon
.Obj
.X
+mon
.Obj
.Rect
.X
, mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
) then exit
;
6657 x2
:= mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2);
6658 y2
:= mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+(mon
.Obj
.Rect
.Height
div 2);
6660 // Åñëè ìîíñòð íà ýêðàíå è íå ïðèêðûò ñòåíîé
6661 if g_TraceVector(x1
, y1
, x2
, y2
) then
6663 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé
6664 SetLength(targets
, Length(targets
)+1);
6665 with targets
[High(targets
)] do
6672 Rect
:= mon
.Obj
.Rect
;
6673 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6674 Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6675 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6684 vsPlayer
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
);
6685 vsMonster
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
);
6687 // Åñëè òåêóùåå îðóæèå íå òî, ÷òî íóæíî, òî ìåíÿåì:
6688 if FCurrWeap
<> FSelectedWeapon
then
6691 // Åñëè íóæíî ñòðåëÿòü è íóæíîå îðóæèå, òî íàæàòü "Ñòðåëÿòü":
6692 if (GetAIFlag('NEEDFIRE') <> '') and (FCurrWeap
= FSelectedWeapon
) then
6694 RemoveAIFlag('NEEDFIRE');
6697 WEAPON_PLASMA
, WEAPON_SUPERPULEMET
, WEAPON_CHAINGUN
: PressKey(KEY_FIRE
, 20);
6698 WEAPON_SAW
, WEAPON_KASTET
, WEAPON_FLAMETHROWER
: PressKey(KEY_FIRE
, 40);
6699 else PressKey(KEY_FIRE
);
6703 // Êîîðäèíàòû ñòâîëà:
6704 x1
:= FObj
.X
+ WEAPONPOINT
[FDirection
].X
;
6705 y1
:= FObj
.Y
+ WEAPONPOINT
[FDirection
].Y
;
6707 Target
.UID
:= FTargetUID
;
6710 if Target
.UID
<> 0 then
6711 begin // Öåëü åñòü - íàñòðàèâàåì
6712 if (g_GetUIDType(Target
.UID
) = UID_PLAYER
) and
6715 tpla
:= g_Player_Get(Target
.UID
);
6719 if (@FObj
) <> nil then
6726 Target
.cX
:= Target
.X
+ PLAYER_RECT_CX
;
6727 Target
.cY
:= Target
.Y
+ PLAYER_RECT_CY
;
6728 Target
.Rect
:= PLAYER_RECT
;
6729 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6730 Target
.Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6731 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6732 Target
.IsPlayer
:= True;
6736 if (g_GetUIDType(Target
.UID
) = UID_MONSTER
) and
6739 mon
:= g_Monsters_ByUID(Target
.UID
);
6742 Target
.X
:= mon
.Obj
.X
;
6743 Target
.Y
:= mon
.Obj
.Y
;
6745 Target
.cX
:= Target
.X
+ mon
.Obj
.Rect
.X
+ (mon
.Obj
.Rect
.Width
div 2);
6746 Target
.cY
:= Target
.Y
+ mon
.Obj
.Rect
.Y
+ (mon
.Obj
.Rect
.Height
div 2);
6747 Target
.Rect
:= mon
.Obj
.Rect
;
6748 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6749 Target
.Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6750 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6751 Target
.IsPlayer
:= False;
6758 begin // Öåëè íåò - îáíóëÿåì
6763 Target
.Visible
:= False;
6764 Target
.Line
:= False;
6765 Target
.IsPlayer
:= False;
6770 // Åñëè öåëü íå âèäèìà èëè íå íà ëèíèè îãíÿ, òî èùåì âñå âîçìîæíûå öåëè:
6771 if (not Target
.Line
) or (not Target
.Visible
) then
6775 for a
:= 0 to High(gPlayers
) do
6776 if (gPlayers
[a
] <> nil) and (gPlayers
[a
].alive
) and
6777 (gPlayers
[a
].FUID
<> FUID
) and
6778 (not SameTeam(FUID
, gPlayers
[a
].FUID
)) and
6779 (not gPlayers
[a
].NoTarget
) and
6780 (gPlayers
[a
].FMegaRulez
[MR_INVIS
] < gTime
) then
6782 if not TargetOnScreen(gPlayers
[a
].FObj
.X
+ PLAYER_RECT
.X
,
6783 gPlayers
[a
].FObj
.Y
+ PLAYER_RECT
.Y
) then
6786 x2
:= gPlayers
[a
].FObj
.X
+ PLAYER_RECT_CX
;
6787 y2
:= gPlayers
[a
].FObj
.Y
+ PLAYER_RECT_CY
;
6789 // Åñëè èãðîê íà ýêðàíå è íå ïðèêðûò ñòåíîé:
6790 if g_TraceVector(x1
, y1
, x2
, y2
) then
6792 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé:
6793 SetLength(targets
, Length(targets
)+1);
6794 with targets
[High(targets
)] do
6796 UID
:= gPlayers
[a
].FUID
;
6797 X
:= gPlayers
[a
].FObj
.X
;
6798 Y
:= gPlayers
[a
].FObj
.Y
;
6801 Rect
:= PLAYER_RECT
;
6802 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6803 Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6804 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6812 if vsMonster
then g_Mons_ForEach(monsUpdate
);
6815 // Åñëè åñòü âîçìîæíûå öåëè:
6816 // (Âûáèðàåì ëó÷øóþ, ìåíÿåì îðóæèå è áåæèì ê íåé/îò íåå)
6817 if targets
<> nil then
6819 // Âûáèðàåì íàèëó÷øóþ öåëü:
6820 BestTarget
:= targets
[0];
6821 if Length(targets
) > 1 then
6822 for a
:= 1 to High(targets
) do
6823 if Compare(BestTarget
, targets
[a
]) = 1 then
6824 BestTarget
:= targets
[a
];
6826 // Åñëè ëó÷øàÿ öåëü "âèäíåå" òåêóùåé, òî òåêóùàÿ := ëó÷øàÿ:
6827 if ((not Target
.Visible
) and BestTarget
.Visible
and (Target
.UID
<> BestTarget
.UID
)) or
6828 ((not Target
.Line
) and BestTarget
.Line
and BestTarget
.Visible
) then
6830 Target
:= BestTarget
;
6832 if (Healthy() = 3) or ((Healthy() = 2)) then
6833 begin // Åñëè çäîðîâû - äîãîíÿåì
6834 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
6835 SetAIFlag('GORIGHT', '1');
6836 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6837 SetAIFlag('GOLEFT', '1');
6840 begin // Åñëè ïîáèòû - óáåãàåì
6841 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) then
6842 SetAIFlag('GORIGHT', '1');
6843 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6844 SetAIFlag('GOLEFT', '1');
6847 // Âûáèðàåì îðóæèå íà îñíîâå ðàññòîÿíèÿ è ïðèîðèòåòîâ:
6848 SelectWeapon(Abs(x1
-Target
.cX
));
6853 // (Äîãîíÿåì/óáåãàåì, ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëè)
6854 // (Åñëè öåëü äàëåêî, òî õâàòèò ñëåäèòü çà íåé)
6855 if Target
.UID
<> 0 then
6857 if not TargetOnScreen(Target
.X
+ Target
.Rect
.X
,
6858 Target
.Y
+ Target
.Rect
.Y
) then
6859 begin // Öåëü ñáåæàëà ñ "ýêðàíà"
6860 if (Healthy() = 3) or ((Healthy() = 2)) then
6861 begin // Åñëè çäîðîâû - äîãîíÿåì
6862 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
6863 SetAIFlag('GORIGHT', '1');
6864 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6865 SetAIFlag('GOLEFT', '1');
6868 begin // Åñëè ïîáèòû - çàáûâàåì î öåëè è óáåãàåì
6870 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) then
6871 SetAIFlag('GORIGHT', '1');
6872 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6873 SetAIFlag('GOLEFT', '1');
6877 begin // Öåëü ïîêà íà "ýêðàíå"
6878 // Åñëè öåëü íå çàãîðîæåíà ñòåíîé, òî îòìå÷àåì, êîãäà åå âèäåëè:
6879 if g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6880 FLastVisible
:= gTime
;
6881 // Åñëè ðàçíèöà âûñîò íå âåëèêà, òî äîãîíÿåì:
6882 if (Abs(FObj
.Y
-Target
.Y
) <= 128) then
6884 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
6885 SetAIFlag('GORIGHT', '1');
6886 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6887 SetAIFlag('GOLEFT', '1');
6891 // Âûáèðàåì óãîë ââåðõ:
6892 if FDirection
= TDirection
.D_LEFT
then
6893 angle
:= ANGLE_LEFTUP
6895 angle
:= ANGLE_RIGHTUP
;
6897 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6898 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6900 // Åñëè ïðè óãëå ââåðõ ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
6901 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6902 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128), //96
6903 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6904 Target
.Rect
.Width
, Target
.Rect
.Height
) and
6905 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6906 begin // òî íóæíî ñòðåëÿòü ââåðõ
6907 SetAIFlag('NEEDFIRE', '1');
6908 SetAIFlag('NEEDSEEUP', '1');
6911 // Âûáèðàåì óãîë âíèç:
6912 if FDirection
= TDirection
.D_LEFT
then
6913 angle
:= ANGLE_LEFTDOWN
6915 angle
:= ANGLE_RIGHTDOWN
;
6917 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6918 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6920 // Åñëè ïðè óãëå âíèç ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
6921 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6922 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
6923 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6924 Target
.Rect
.Width
, Target
.Rect
.Height
) and
6925 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6926 begin // òî íóæíî ñòðåëÿòü âíèç
6927 SetAIFlag('NEEDFIRE', '1');
6928 SetAIFlag('NEEDSEEDOWN', '1');
6931 // Åñëè öåëü âèäíî è îíà íà òàêîé æå âûñîòå:
6932 if Target
.Visible
and
6933 (y1
+4 < Target
.Y
+Target
.Rect
.Y
+Target
.Rect
.Height
) and
6934 (y1
-4 > Target
.Y
+Target
.Rect
.Y
) then
6936 // Åñëè èäåì â ñòîðîíó öåëè, òî íàäî ñòðåëÿòü:
6937 if ((FDirection
= TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) or
6938 ((FDirection
= TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6939 begin // òî íóæíî ñòðåëÿòü âïåðåä
6940 SetAIFlag('NEEDFIRE', '1');
6941 SetAIFlag('NEEDSEEDOWN', '');
6942 SetAIFlag('NEEDSEEUP', '');
6944 // Åñëè öåëü â ïðåäåëàõ "ýêðàíà" è ñëîæíîñòü ïîçâîëÿåò ïðûæêè ñáëèæåíèÿ:
6945 if Abs(FObj
.X
-Target
.X
) < Trunc(gPlayerScreenSize
.X
*0.75) then
6946 if GetRnd(FDifficult
.CloseJump
) then
6947 begin // òî åñëè ïîâåçåò - ïðûãàåì (îñîáåííî, åñëè áëèçêî)
6948 if Abs(FObj
.X
-Target
.X
) < 128 then
6952 if Random(a
) = 0 then
6953 SetAIFlag('NEEDJUMP', '1');
6957 // Åñëè öåëü âñå åùå åñòü:
6958 if Target
.UID
<> 0 then
6959 if gTime
-FLastVisible
> 2000 then // Åñëè âèäåëè äàâíî
6960 Target
.UID
:= 0 // òî çàáûòü öåëü
6961 else // Åñëè âèäåëè íåäàâíî
6962 begin // íî öåëü óáèëè
6963 if Target
.IsPlayer
then
6964 begin // Öåëü - èãðîê
6965 pla
:= g_Player_Get(Target
.UID
);
6966 if (pla
= nil) or (not pla
.alive
) or pla
.NoTarget
or
6967 (pla
.FMegaRulez
[MR_INVIS
] >= gTime
) then
6968 Target
.UID
:= 0; // òî çàáûòü öåëü
6971 begin // Öåëü - ìîíñòð
6972 mon
:= g_Monsters_ByUID(Target
.UID
);
6973 if (mon
= nil) or (not mon
.alive
) then
6974 Target
.UID
:= 0; // òî çàáûòü öåëü
6977 end; // if Target.UID <> 0
6979 FTargetUID
:= Target
.UID
;
6981 // Åñëè âîçìîæíûõ öåëåé íåò:
6982 // (Àòàêà ÷åãî-íèáóäü ñëåâà èëè ñïðàâà)
6983 if targets
= nil then
6984 if GetAIFlag('ATTACKLEFT') <> '' then
6985 begin // Åñëè íóæíî àòàêîâàòü íàëåâî
6986 RemoveAIFlag('ATTACKLEFT');
6988 SetAIFlag('NEEDJUMP', '1');
6990 if RunDirection() = TDirection
.D_RIGHT
then
6991 begin // Èäåì íå â òó ñòîðîíó
6992 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
6993 begin // Åñëè çäîðîâû, òî, âîçìîæíî, ñòðåëÿåì áåæèì âëåâî è ñòðåëÿåì
6994 SetAIFlag('NEEDFIRE', '1');
6995 SetAIFlag('GOLEFT', '1');
6999 begin // Èäåì â íóæíóþ ñòîðîíó
7000 if GetRnd(FDifficult
.InvisFire
) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
7001 SetAIFlag('NEEDFIRE', '1');
7002 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
7003 SetAIFlag('GORIGHT', '1');
7007 if GetAIFlag('ATTACKRIGHT') <> '' then
7008 begin // Åñëè íóæíî àòàêîâàòü íàïðàâî
7009 RemoveAIFlag('ATTACKRIGHT');
7011 SetAIFlag('NEEDJUMP', '1');
7013 if RunDirection() = TDirection
.D_LEFT
then
7014 begin // Èäåì íå â òó ñòîðîíó
7015 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
7016 begin // Åñëè çäîðîâû, òî, âîçìîæíî, áåæèì âïðàâî è ñòðåëÿåì
7017 SetAIFlag('NEEDFIRE', '1');
7018 SetAIFlag('GORIGHT', '1');
7023 if GetRnd(FDifficult
.InvisFire
) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
7024 SetAIFlag('NEEDFIRE', '1');
7025 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
7026 SetAIFlag('GOLEFT', '1');
7030 //HACK! (does it belongs there?)
7031 RealizeCurrentWeapon();
7033 // Åñëè åñòü âîçìîæíûå öåëè:
7034 // (Ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëÿì)
7035 if (targets
<> nil) and (GetAIFlag('NEEDFIRE') <> '') then
7036 for a
:= 0 to High(targets
) do
7038 // Åñëè ìîæåì ñòðåëÿòü ïî äèàãîíàëè:
7039 if GetRnd(FDifficult
.DiagFire
) then
7041 // Èùåì öåëü ñâåðõó è ñòðåëÿåì, åñëè åñòü:
7042 if FDirection
= TDirection
.D_LEFT
then
7043 angle
:= ANGLE_LEFTUP
7045 angle
:= ANGLE_RIGHTUP
;
7047 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7048 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7050 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
7051 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
7052 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
7053 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
7054 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
7056 SetAIFlag('NEEDFIRE', '1');
7057 SetAIFlag('NEEDSEEUP', '1');
7060 // Èùåì öåëü ñíèçó è ñòðåëÿåì, åñëè åñòü:
7061 if FDirection
= TDirection
.D_LEFT
then
7062 angle
:= ANGLE_LEFTDOWN
7064 angle
:= ANGLE_RIGHTDOWN
;
7066 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7067 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7069 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
7070 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
7071 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
7072 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
7073 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
7075 SetAIFlag('NEEDFIRE', '1');
7076 SetAIFlag('NEEDSEEDOWN', '1');
7080 // Åñëè öåëü "ïåðåä íîñîì", òî ñòðåëÿåì:
7081 if targets
[a
].Line
and targets
[a
].Visible
and
7082 (((FDirection
= TDirection
.D_LEFT
) and (targets
[a
].X
< FObj
.X
)) or
7083 ((FDirection
= TDirection
.D_RIGHT
) and (targets
[a
].X
> FObj
.X
))) then
7085 SetAIFlag('NEEDFIRE', '1');
7090 // Åñëè ëåòèò ïóëÿ, òî, âîçìîæíî, ïîäïðûãèâàåì:
7091 if g_Weapon_Danger(FUID
, FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
,
7092 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
,
7093 40+GetInterval(FDifficult
.Cover
, 40)) then
7094 SetAIFlag('NEEDJUMP', '1');
7096 // Åñëè êîí÷èëèñü ïàòîðíû, òî íóæíî ñìåíèòü îðóæèå:
7097 ammo
:= GetAmmoByWeapon(FCurrWeap
);
7098 if ((FCurrWeap
= WEAPON_SHOTGUN2
) and (ammo
< 2)) or
7099 ((FCurrWeap
= WEAPON_BFG
) and (ammo
< 40)) or
7101 SetAIFlag('SELECTWEAPON', '1');
7103 // Åñëè íóæíî ñìåíèòü îðóæèå, òî âûáèðàåì íóæíîå:
7104 if GetAIFlag('SELECTWEAPON') = '1' then
7107 RemoveAIFlag('SELECTWEAPON');
7111 procedure TBot
.Update();
7124 // Ïðîâåðÿåì, îòêëþ÷¸í ëè AI áîòîâ
7125 if (g_debug_BotAIOff
= 1) and (Team
= TEAM_RED
) then
7127 if (g_debug_BotAIOff
= 2) and (Team
= TEAM_BLUE
) then
7129 if g_debug_BotAIOff
= 3 then
7139 RealizeCurrentWeapon();
7146 procedure TBot
.ReleaseKey(Key
: Byte);
7155 function TBot
.KeyPressed(Key
: Word): Boolean;
7157 Result
:= FKeys
[Key
].Pressed
;
7160 function TBot
.GetAIFlag(aName
: String20
): String20
;
7166 aName
:= LowerCase(aName
);
7168 if FAIFlags
<> nil then
7169 for a
:= 0 to High(FAIFlags
) do
7170 if LowerCase(FAIFlags
[a
].Name
) = aName
then
7172 Result
:= FAIFlags
[a
].Value
;
7177 procedure TBot
.RemoveAIFlag(aName
: String20
);
7181 if FAIFlags
= nil then Exit
;
7183 aName
:= LowerCase(aName
);
7185 for a
:= 0 to High(FAIFlags
) do
7186 if LowerCase(FAIFlags
[a
].Name
) = aName
then
7188 if a
<> High(FAIFlags
) then
7189 for b
:= a
to High(FAIFlags
)-1 do
7190 FAIFlags
[b
] := FAIFlags
[b
+1];
7192 SetLength(FAIFlags
, Length(FAIFlags
)-1);
7197 procedure TBot
.SetAIFlag(aName
, fValue
: String20
);
7205 aName
:= LowerCase(aName
);
7207 if FAIFlags
<> nil then
7208 for a
:= 0 to High(FAIFlags
) do
7209 if LowerCase(FAIFlags
[a
].Name
) = aName
then
7215 if ok
then FAIFlags
[a
].Value
:= fValue
7218 SetLength(FAIFlags
, Length(FAIFlags
)+1);
7219 with FAIFlags
[High(FAIFlags
)] do
7227 procedure TBot
.UpdateMove
;
7229 procedure GoLeft(Time
: Word = 1);
7231 ReleaseKey(KEY_LEFT
);
7232 ReleaseKey(KEY_RIGHT
);
7233 PressKey(KEY_LEFT
, Time
);
7234 SetDirection(TDirection
.D_LEFT
);
7237 procedure GoRight(Time
: Word = 1);
7239 ReleaseKey(KEY_LEFT
);
7240 ReleaseKey(KEY_RIGHT
);
7241 PressKey(KEY_RIGHT
, Time
);
7242 SetDirection(TDirection
.D_RIGHT
);
7245 function Rnd(a
: Word): Boolean;
7247 Result
:= Random(a
) = 0;
7250 procedure Turn(Time
: Word = 1200);
7252 if RunDirection() = TDirection
.D_LEFT
then GoRight(Time
) else GoLeft(Time
);
7257 ReleaseKey(KEY_LEFT
);
7258 ReleaseKey(KEY_RIGHT
);
7261 function CanRunLeft(): Boolean;
7263 Result
:= not CollideLevel(-1, 0);
7266 function CanRunRight(): Boolean;
7268 Result
:= not CollideLevel(1, 0);
7271 function CanRun(): Boolean;
7273 if RunDirection() = TDirection
.D_LEFT
then Result
:= CanRunLeft() else Result
:= CanRunRight();
7276 procedure Jump(Time
: Word = 30);
7278 PressKey(KEY_JUMP
, Time
);
7281 function NearHole(): Boolean;
7285 { TODO 5 : Ëåñòíèöû }
7286 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7287 for x
:= 1 to PLAYER_RECT
.Width
do
7288 if (not StayOnStep(x
*sx
, 0)) and
7289 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7290 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7299 function BorderHole(): Boolean;
7303 { TODO 5 : Ëåñòíèöû }
7304 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7305 for x
:= 1 to PLAYER_RECT
.Width
do
7306 if (not StayOnStep(x
*sx
, 0)) and
7307 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7308 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7310 for xx
:= x
to x
+32 do
7311 if CollideLevel(xx
*sx
, PLAYER_RECT
.Height
) then
7321 function NearDeepHole(): Boolean;
7327 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7330 for x
:= 1 to PLAYER_RECT
.Width
do
7331 if (not StayOnStep(x
*sx
, 0)) and
7332 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7333 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7335 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
7337 if CollideLevel(x
*sx
, PLAYER_RECT
.Height
*y
) then Exit
;
7342 end else Result
:= False;
7345 function OverDeepHole(): Boolean;
7352 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
7354 if CollideLevel(0, PLAYER_RECT
.Height
*y
) then Exit
;
7361 function OnGround(): Boolean;
7363 Result
:= StayOnStep(0, 0) or CollideLevel(0, 1);
7366 function OnLadder(): Boolean;
7368 Result
:= FullInStep(0, 0);
7371 function BelowLadder(): Boolean;
7373 Result
:= (FullInStep(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) and
7374 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
7375 (FullInStep(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) and
7376 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
7379 function BelowLiftUp(): Boolean;
7381 Result
:= ((FullInLift(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) = -1) and
7382 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
7383 ((FullInLift(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) = -1) and
7384 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
7387 function OnTopLift(): Boolean;
7389 Result
:= (FullInLift(0, 0) = -1) and (FullInLift(0, -32) = 0);
7392 function CanJumpOver(): Boolean;
7396 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7400 if not CollideLevel(sx
, 0) then Exit
;
7402 for y
:= 1 to BOT_MAXJUMP
do
7403 if CollideLevel(0, -y
) then Exit
else
7404 if not CollideLevel(sx
, -y
) then
7411 function CanJumpUp(Dist
: ShortInt): Boolean;
7418 if CollideLevel(Dist
, 0) then Exit
;
7421 for y
:= 0 to BOT_MAXJUMP
do
7422 if CollideLevel(Dist
, -y
) then
7431 for yy
:= y
+1 to BOT_MAXJUMP
do
7432 if not CollideLevel(Dist
, -yy
) then
7441 for y
:= 0 to BOT_MAXJUMP
do
7442 if CollideLevel(0, -y
) then
7450 if y
< yy
then Exit
;
7455 function IsSafeTrigger(): Boolean;
7460 if gTriggers
= nil then
7462 for a
:= 0 to High(gTriggers
) do
7463 if Collide(gTriggers
[a
].X
,
7466 gTriggers
[a
].Height
) and
7467 (gTriggers
[a
].TriggerType
in [TRIGGER_EXIT
, TRIGGER_CLOSEDOOR
,
7468 TRIGGER_CLOSETRAP
, TRIGGER_TRAP
,
7469 TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
,
7470 TRIGGER_ONOFF
, TRIGGER_SPAWNMONSTER
,
7471 TRIGGER_DAMAGE
, TRIGGER_SHOT
]) then
7476 // Âîçìîæíî, íàæèìàåì êíîïêó:
7477 if Rnd(16) and IsSafeTrigger() then
7480 // Åñëè ïîä ëèôòîì èëè ñòóïåíüêàìè, òî, âîçìîæíî, ïðûãàåì:
7481 if OnLadder() or ((BelowLadder() or BelowLiftUp()) and Rnd(8)) then
7483 ReleaseKey(KEY_LEFT
);
7484 ReleaseKey(KEY_RIGHT
);
7488 // Èäåì âëåâî, åñëè íàäî áûëî:
7489 if GetAIFlag('GOLEFT') <> '' then
7491 RemoveAIFlag('GOLEFT');
7492 if CanRunLeft() then
7496 // Èäåì âïðàâî, åñëè íàäî áûëî:
7497 if GetAIFlag('GORIGHT') <> '' then
7499 RemoveAIFlag('GORIGHT');
7500 if CanRunRight() then
7504 // Åñëè âûëåòåëè çà êàðòó, òî ïðîáóåì âåðíóòüñÿ:
7505 if FObj
.X
< -32 then
7508 if FObj
.X
+32 > gMapInfo
.Width
then
7511 // Ïðûãàåì, åñëè íàäî áûëî:
7512 if GetAIFlag('NEEDJUMP') <> '' then
7515 RemoveAIFlag('NEEDJUMP');
7518 // Ñìîòðèì ââåðõ, åñëè íàäî áûëî:
7519 if GetAIFlag('NEEDSEEUP') <> '' then
7522 ReleaseKey(KEY_DOWN
);
7523 PressKey(KEY_UP
, 20);
7524 RemoveAIFlag('NEEDSEEUP');
7527 // Ñìîòðèì âíèç, åñëè íàäî áûëî:
7528 if GetAIFlag('NEEDSEEDOWN') <> '' then
7531 ReleaseKey(KEY_DOWN
);
7532 PressKey(KEY_DOWN
, 20);
7533 RemoveAIFlag('NEEDSEEDOWN');
7536 // Åñëè íóæíî áûëî â äûðó è ìû íå íà çåìëå, òî ïîêîðíî ëåòèì:
7537 if GetAIFlag('GOINHOLE') <> '' then
7538 if not OnGround() then
7540 ReleaseKey(KEY_LEFT
);
7541 ReleaseKey(KEY_RIGHT
);
7542 RemoveAIFlag('GOINHOLE');
7543 SetAIFlag('FALLINHOLE', '1');
7546 // Åñëè ïàäàëè è äîñòèãëè çåìëè, òî õâàòèò ïàäàòü:
7547 if GetAIFlag('FALLINHOLE') <> '' then
7549 RemoveAIFlag('FALLINHOLE');
7551 // Åñëè ëåòåëè ïðÿìî è ñåé÷àñ íå íà ëåñòíèöå èëè íà âåðøèíå ëèôòà, òî îòõîäèì â ñòîðîíó:
7552 if not (KeyPressed(KEY_LEFT
) or KeyPressed(KEY_RIGHT
)) then
7553 if GetAIFlag('FALLINHOLE') = '' then
7554 if (not OnLadder()) or (FObj
.Vel
.Y
>= 0) or (OnTopLift()) then
7560 // Åñëè íà çåìëå è ìîæíî ïîäïðûãíóòü, òî, âîçìîæíî, ïðûãàåì:
7562 CanJumpUp(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*32) and
7566 // Åñëè íà çåìëå è âîçëå äûðû (ãëóáèíà > 2 ðîñòîâ èãðîêà):
7567 if OnGround() and NearHole() then
7568 if NearDeepHole() then // Åñëè ýòî áåçäíà
7570 0..3: Turn(); // Áåæèì îáðàòíî
7571 4: Jump(); // Ïðûãàåì
7572 5: begin // Ïðûãàåì îáðàòíî
7577 else // Ýòî íå áåçäíà è ìû åùå íå ëåòèì òóäà
7578 if GetAIFlag('GOINHOLE') = '' then
7580 0: Turn(); // Íå íóæíî òóäà
7581 1: Jump(); // Âäðóã ïîâåçåò - ïðûãàåì
7582 else // Åñëè ÿìà ñ ãðàíèöåé, òî ïðè ñëó÷àå ìîæíî òóäà ïðûãíóòü
7583 if BorderHole() then
7584 SetAIFlag('GOINHOLE', '1');
7587 // Åñëè íà çåìëå, íî íåêóäà èäòè:
7588 if (not CanRun()) and OnGround() then
7590 // Åñëè ìû íà ëåñòíèöå èëè ìîæíî ïåðåïðûãíóòü, òî ïðûãàåì:
7591 if CanJumpOver() or OnLadder() then
7593 else // èíà÷å ïîïûòàåìñÿ â äðóãóþ ñòîðîíó
7594 if Random(2) = 0 then
7596 if IsSafeTrigger() then
7602 // Îñòàëîñü ìàëî âîçäóõà:
7603 if FAir
< 36 * 2 then
7606 // Âûáèðàåìñÿ èç êèñëîòû, åñëè íåò êîñòþìà, îáîæãëèñü, èëè ìàëî çäîðîâüÿ:
7607 if (FMegaRulez
[MR_SUIT
] < gTime
) and ((FLastHit
= HIT_ACID
) or (Healthy() <= 1)) then
7608 if BodyInAcid(0, 0) then
7612 function TBot
.FullInStep(XInc
, YInc
: Integer): Boolean;
7614 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
7615 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_STEP
, False);
7618 {function TBot.NeedItem(Item: Byte): Byte;
7623 procedure TBot
.SelectWeapon(Dist
: Integer);
7627 function HaveAmmo(weapon
: Byte): Boolean;
7630 WEAPON_PISTOL
: Result
:= FAmmo
[A_BULLETS
] >= 1;
7631 WEAPON_SHOTGUN1
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7632 WEAPON_SHOTGUN2
: Result
:= FAmmo
[A_SHELLS
] >= 2;
7633 WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
] >= 10;
7634 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
] >= 1;
7635 WEAPON_PLASMA
: Result
:= FAmmo
[A_CELLS
] >= 10;
7636 WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
] >= 40;
7637 WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7638 WEAPON_FLAMETHROWER
: Result
:= FAmmo
[A_FUEL
] >= 1;
7639 else Result
:= True;
7644 if Dist
= -1 then Dist
:= BOT_LONGDIST
;
7646 if Dist
> BOT_LONGDIST
then
7647 begin // Äàëüíèé áîé
7649 if FWeapon
[FDifficult
.WeaponPrior
[a
]] and HaveAmmo(FDifficult
.WeaponPrior
[a
]) then
7651 FSelectedWeapon
:= FDifficult
.WeaponPrior
[a
];
7655 else //if Dist > BOT_UNSAFEDIST then
7656 begin // Áëèæíèé áîé
7658 if FWeapon
[FDifficult
.CloseWeaponPrior
[a
]] and HaveAmmo(FDifficult
.CloseWeaponPrior
[a
]) then
7660 FSelectedWeapon
:= FDifficult
.CloseWeaponPrior
[a
];
7667 if FWeapon[FDifficult.SafeWeaponPrior[a]] and HaveAmmo(FDifficult.SafeWeaponPrior[a]) then
7669 FSelectedWeapon := FDifficult.SafeWeaponPrior[a];
7675 function TBot
.PickItem(ItemType
: Byte; force
: Boolean; var remove
: Boolean): Boolean;
7677 Result
:= inherited PickItem(ItemType
, force
, remove
);
7679 if Result
then SetAIFlag('SELECTWEAPON', '1');
7682 function TBot
.Heal(value
: Word; Soft
: Boolean): Boolean;
7684 Result
:= inherited Heal(value
, Soft
);
7687 function TBot
.Healthy(): Byte;
7689 if FMegaRulez
[MR_INVUL
] >= gTime
then Result
:= 3
7690 else if (FHealth
> 80) or ((FHealth
> 50) and (FArmor
> 20)) then Result
:= 3
7691 else if (FHealth
> 50) then Result
:= 2
7692 else if (FHealth
> 20) then Result
:= 1
7696 function TBot
.TargetOnScreen(TX
, TY
: Integer): Boolean;
7698 Result
:= (Abs(FObj
.X
-TX
) <= Trunc(gPlayerScreenSize
.X
*0.6)) and
7699 (Abs(FObj
.Y
-TY
) <= Trunc(gPlayerScreenSize
.Y
*0.6));
7702 procedure TBot
.OnDamage(Angle
: SmallInt);
7710 if (Angle
= 0) or (Angle
= 180) then
7713 if (g_GetUIDType(FLastSpawnerUID
) = UID_PLAYER
) and
7714 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
) then
7716 pla
:= g_Player_Get(FLastSpawnerUID
);
7717 ok
:= not TargetOnScreen(pla
.FObj
.X
+ PLAYER_RECT
.X
,
7718 pla
.FObj
.Y
+ PLAYER_RECT
.Y
);
7721 if (g_GetUIDType(FLastSpawnerUID
) = UID_MONSTER
) and
7722 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
) then
7724 mon
:= g_Monsters_ByUID(FLastSpawnerUID
);
7725 ok
:= not TargetOnScreen(mon
.Obj
.X
+ mon
.Obj
.Rect
.X
,
7726 mon
.Obj
.Y
+ mon
.Obj
.Rect
.Y
);
7731 SetAIFlag('ATTACKLEFT', '1')
7733 SetAIFlag('ATTACKRIGHT', '1');
7737 function TBot
.RunDirection(): TDirection
;
7739 if Abs(Vel
.X
) >= 1 then
7741 if Vel
.X
> 0 then Result
:= TDirection
.D_RIGHT
else Result
:= TDirection
.D_LEFT
;
7743 Result
:= FDirection
;
7746 function TBot
.GetRnd(a
: Byte): Boolean;
7748 if a
= 0 then Result
:= False
7749 else if a
= 255 then Result
:= True
7750 else Result
:= Random(256) > 255-a
;
7753 function TBot
.GetInterval(a
: Byte; radius
: SmallInt): SmallInt;
7755 Result
:= Round((255-a
)/255*radius
*(Random(2)-1));
7759 procedure TDifficult
.save (st
: TStream
);
7761 utils
.writeInt(st
, Byte(DiagFire
));
7762 utils
.writeInt(st
, Byte(InvisFire
));
7763 utils
.writeInt(st
, Byte(DiagPrecision
));
7764 utils
.writeInt(st
, Byte(FlyPrecision
));
7765 utils
.writeInt(st
, Byte(Cover
));
7766 utils
.writeInt(st
, Byte(CloseJump
));
7767 st
.WriteBuffer(WeaponPrior
[Low(WeaponPrior
)], sizeof(WeaponPrior
));
7768 st
.WriteBuffer(CloseWeaponPrior
[Low(CloseWeaponPrior
)], sizeof(CloseWeaponPrior
));
7771 procedure TDifficult
.load (st
: TStream
);
7773 DiagFire
:= utils
.readByte(st
);
7774 InvisFire
:= utils
.readByte(st
);
7775 DiagPrecision
:= utils
.readByte(st
);
7776 FlyPrecision
:= utils
.readByte(st
);
7777 Cover
:= utils
.readByte(st
);
7778 CloseJump
:= utils
.readByte(st
);
7779 st
.ReadBuffer(WeaponPrior
[Low(WeaponPrior
)], sizeof(WeaponPrior
));
7780 st
.ReadBuffer(CloseWeaponPrior
[Low(CloseWeaponPrior
)], sizeof(CloseWeaponPrior
));
7784 procedure TBot
.SaveState (st
: TStream
);
7789 inherited SaveState(st
);
7790 utils
.writeSign(st
, 'BOT0');
7792 utils
.writeInt(st
, Byte(FSelectedWeapon
));
7794 utils
.writeInt(st
, Word(FTargetUID
));
7795 // Âðåìÿ ïîòåðè öåëè
7796 utils
.writeInt(st
, LongWord(FLastVisible
));
7797 // Êîëè÷åñòâî ôëàãîâ ÈÈ
7798 dw
:= Length(FAIFlags
);
7799 utils
.writeInt(st
, LongInt(dw
));
7801 for i
:= 0 to dw
-1 do
7803 utils
.writeStr(st
, FAIFlags
[i
].Name
, 20);
7804 utils
.writeStr(st
, FAIFlags
[i
].Value
, 20);
7806 // Íàñòðîéêè ñëîæíîñòè
7807 FDifficult
.save(st
);
7811 procedure TBot
.LoadState (st
: TStream
);
7816 inherited LoadState(st
);
7817 if not utils
.checkSign(st
, 'BOT0') then raise XStreamError
.Create('invalid bot signature');
7819 FSelectedWeapon
:= utils
.readByte(st
);
7821 FTargetUID
:= utils
.readWord(st
);
7822 // Âðåìÿ ïîòåðè öåëè
7823 FLastVisible
:= utils
.readLongWord(st
);
7824 // Êîëè÷åñòâî ôëàãîâ ÈÈ
7825 dw
:= utils
.readLongInt(st
);
7826 if (dw
< 0) or (dw
> 16384) then raise XStreamError
.Create('invalid number of bot AI flags');
7827 SetLength(FAIFlags
, dw
);
7829 for i
:= 0 to dw
-1 do
7831 FAIFlags
[i
].Name
:= utils
.readStr(st
, 20);
7832 FAIFlags
[i
].Value
:= utils
.readStr(st
, 20);
7834 // Íàñòðîéêè ñëîæíîñòè
7835 FDifficult
.load(st
);
7840 conRegVar('cheat_berserk_autoswitch', @gBerserkAutoswitch
, 'autoswitch to fist when berserk pack taken', '', true, true);