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);
3167 FFireAttacker
:= Attacker
;
3168 if g_Game_IsNet
and g_Game_IsServer
then
3169 MH_SEND_PlayerStats(FUID
);
3172 procedure TPlayer
.Jump();
3174 if gFly
or FJetpack
then
3176 // Ïîëåò (÷èò-êîä èëè äæåòïàê):
3177 if FObj
.Vel
.Y
> -VEL_FLY
then
3178 FObj
.Vel
.Y
:= FObj
.Vel
.Y
- 3;
3181 if FJetFuel
> 0 then
3183 if (FJetFuel
< 1) and g_Game_IsServer
then
3187 if g_Game_IsNet
then
3188 MH_SEND_PlayerStats(FUID
);
3194 // Íå âêëþ÷àòü äæåòïàê â ðåæèìå ïðîõîæäåíèÿ ñêâîçü ñòåíû
3196 FCanJetpack
:= False;
3198 // Ïðûãàåì èëè âñïëûâàåì:
3199 if (CollideLevel(0, 1) or
3200 g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
+36, PLAYER_RECT
.Width
,
3201 PLAYER_RECT
.Height
-33, PANEL_STEP
, False)
3202 ) and (FObj
.Accel
.Y
= 0) then // Íå ïðûãàòü, åñëè åñòü âåðòèêàëüíîå óñêîðåíèå
3204 FObj
.Vel
.Y
:= -VEL_JUMP
;
3205 FCanJetpack
:= False;
3209 if BodyInLiquid(0, 0) then
3210 FObj
.Vel
.Y
:= -VEL_SW
3211 else if (FJetFuel
> 0) and FCanJetpack
and
3212 g_Game_IsServer
and (not g_Obj_CollideLiquid(@FObj
, 0, 0)) then
3216 if g_Game_IsNet
then
3217 MH_SEND_PlayerStats(FUID
);
3222 procedure TPlayer
.Kill(KillType
: Byte; SpawnerUID
: Word; t
: Byte);
3224 a
, i
, k
, ab
, ar
: Byte;
3228 srv
, netsrv
: Boolean;
3234 procedure PushItem(t
: Byte);
3238 id
:= g_Items_Create(FObj
.X
, FObj
.Y
, t
, True, False);
3239 it
:= g_Items_ByIdx(id
);
3240 if KillType
= K_EXTRAHARDKILL
then // -7..+7; -8..0
3242 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-7+Random(15),
3243 (FObj
.Vel
.Y
div 2)-Random(9));
3244 it
.positionChanged(); // this updates spatial accelerators
3248 if KillType
= K_HARDKILL
then // -5..+5; -5..0
3250 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-5+Random(11),
3251 (FObj
.Vel
.Y
div 2)-Random(6));
3253 else // -3..+3; -3..0
3255 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-3+Random(7),
3256 (FObj
.Vel
.Y
div 2)-Random(4));
3258 it
.positionChanged(); // this updates spatial accelerators
3261 if g_Game_IsNet
and g_Game_IsServer
then
3262 MH_SEND_ItemSpawn(True, id
);
3266 DoFrags
:= (gGameSettings
.MaxLives
= 0) or (gGameSettings
.GameMode
= GM_COOP
);
3267 Srv
:= g_Game_IsServer
;
3268 Netsrv
:= g_Game_IsServer
and g_Game_IsNet
;
3269 if Srv
then FDeath
:= FDeath
+ 1;
3274 if not FPhysics
then
3280 if (gGameSettings
.MaxLives
> 0) and Srv
and (gLMSRespawn
= LMS_RESPAWN_NONE
) then
3282 if FLives
> 0 then FLives
:= FLives
- 1;
3283 if FLives
= 0 then FNoRespawn
:= True;
3286 // Íîìåð òèïà ñìåðòè:
3289 K_SIMPLEKILL
: a
:= 1;
3291 K_EXTRAHARDKILL
: a
:= 3;
3296 if not FModel
.PlaySound(MODELSOUND_DIE
, a
, FObj
.X
, FObj
.Y
) then
3298 if FModel
.PlaySound(MODELSOUND_DIE
, i
, FObj
.X
, FObj
.Y
) then
3305 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN1
;
3307 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN2
;
3308 K_EXTRAHARDKILL
, K_FALLKILL
:
3309 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN3
;
3312 // Ïåðåêëþ÷àåì ñîñòîÿíèå:
3316 K_HARDKILL
, K_EXTRAHARDKILL
:
3320 // Ðåàêöèÿ ìîíñòðîâ íà ñìåðòü èãðîêà:
3321 if (KillType
<> K_FALLKILL
) and (Srv
) then
3322 g_Monsters_killedp();
3324 if SpawnerUID
= FUID
then
3326 if Srv
and (DoFrags
or (gGameSettings
.GameMode
= GM_TDM
)) then
3331 g_Console_Add(Format(_lc
[I_PLAYER_KILL_SELF
], [FName
]), True);
3334 if g_GetUIDType(SpawnerUID
) = UID_PLAYER
then
3335 begin // Óáèò äðóãèì èãðîêîì
3336 KP
:= g_Player_Get(SpawnerUID
);
3337 if (KP
<> nil) and Srv
then
3339 if (DoFrags
or (gGameSettings
.GameMode
= GM_TDM
)) then
3340 if SameTeam(FUID
, SpawnerUID
) then
3350 if (gGameSettings
.GameMode
= GM_TDM
) and DoFrags
then
3351 Inc(gTeamStat
[KP
.Team
].Goals
,
3352 IfThen(SameTeam(FUID
, SpawnerUID
), -1, 1));
3354 if netsrv
then MH_SEND_PlayerStats(SpawnerUID
);
3357 plr
:= g_Player_Get(SpawnerUID
);
3365 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_2
],
3369 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_1
],
3373 g_Console_Add(Format(_lc
[I_PLAYER_KILL
],
3378 else if g_GetUIDType(SpawnerUID
) = UID_MONSTER
then
3379 begin // Óáèò ìîíñòðîì
3380 mon
:= g_Monsters_ByUID(SpawnerUID
);
3384 s
:= g_Mons_GetKilledByTypeId(mon
.MonsterType
);
3388 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_2
],
3392 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_1
],
3396 g_Console_Add(Format(_lc
[I_PLAYER_KILL
],
3401 else // Îñîáûå òèïû ñìåðòè
3404 HIT_SELF
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_SELF
], [FName
]), True);
3405 HIT_FALL
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_FALL
], [FName
]), True);
3406 HIT_WATER
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_WATER
], [FName
]), True);
3407 HIT_ACID
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_ACID
], [FName
]), True);
3408 HIT_TRAP
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_TRAP
], [FName
]), True);
3409 else g_Console_Add(Format(_lc
[I_PLAYER_DIED
], [FName
]), True);
3415 for a
:= WP_FIRST
to WP_LAST
do
3419 WEAPON_SAW
: i
:= ITEM_WEAPON_SAW
;
3420 WEAPON_SHOTGUN1
: i
:= ITEM_WEAPON_SHOTGUN1
;
3421 WEAPON_SHOTGUN2
: i
:= ITEM_WEAPON_SHOTGUN2
;
3422 WEAPON_CHAINGUN
: i
:= ITEM_WEAPON_CHAINGUN
;
3423 WEAPON_ROCKETLAUNCHER
: i
:= ITEM_WEAPON_ROCKETLAUNCHER
;
3424 WEAPON_PLASMA
: i
:= ITEM_WEAPON_PLASMA
;
3425 WEAPON_BFG
: i
:= ITEM_WEAPON_BFG
;
3426 WEAPON_SUPERPULEMET
: i
:= ITEM_WEAPON_SUPERPULEMET
;
3427 WEAPON_FLAMETHROWER
: i
:= ITEM_WEAPON_FLAMETHROWER
;
3436 if R_ITEM_BACKPACK
in FRulez
then
3437 PushItem(ITEM_AMMO_BACKPACK
);
3439 // Âûáðîñ ðàêåòíîãî ðàíöà:
3440 if FJetFuel
> 0 then
3441 PushItem(ITEM_JETPACK
);
3444 if not (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
]) then
3446 if R_KEY_RED
in FRulez
then
3447 PushItem(ITEM_KEY_RED
);
3449 if R_KEY_GREEN
in FRulez
then
3450 PushItem(ITEM_KEY_GREEN
);
3452 if R_KEY_BLUE
in FRulez
then
3453 PushItem(ITEM_KEY_BLUE
);
3457 DropFlag(KillType
= K_FALLKILL
);
3460 g_Player_CreateCorpse(Self
);
3462 if Srv
and (gGameSettings
.MaxLives
> 0) and FNoRespawn
and
3463 (gLMSRespawn
= LMS_RESPAWN_NONE
) then
3469 for i
:= Low(gPlayers
) to High(gPlayers
) do
3471 if gPlayers
[i
] = nil then continue
;
3472 if (not gPlayers
[i
].FNoRespawn
) and (not gPlayers
[i
].FSpectator
) then
3475 if gPlayers
[i
].FTeam
= TEAM_RED
then Inc(ar
)
3476 else if gPlayers
[i
].FTeam
= TEAM_BLUE
then Inc(ab
);
3481 OldLR
:= gLMSRespawn
;
3482 if (gGameSettings
.GameMode
= GM_COOP
) then
3486 // everyone is dead, restart the map
3487 g_Game_Message(_lc
[I_MESSAGE_LMS_LOSE
], 144);
3489 MH_SEND_GameEvent(NET_EV_LMS_LOSE
);
3490 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3491 gLMSRespawnTime
:= gTime
+ 5000;
3493 else if (a
= 1) then
3495 if (gPlayers
[k
] <> nil) and not (gPlayers
[k
] is TBot
) then
3496 if (gPlayers
[k
] = gPlayer1
) or
3497 (gPlayers
[k
] = gPlayer2
) then
3498 g_Console_Add('*** ' + _lc
[I_MESSAGE_LMS_SURVIVOR
] + ' ***', True)
3499 else if Netsrv
and (gPlayers
[k
].FClientID
>= 0) then
3500 MH_SEND_GameEvent(NET_EV_LMS_SURVIVOR
, 0, 'N', gPlayers
[k
].FClientID
);
3503 else if (gGameSettings
.GameMode
= GM_TDM
) then
3505 if (ab
= 0) and (ar
<> 0) then
3508 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 144);
3510 MH_SEND_GameEvent(NET_EV_TLMS_WIN
, TEAM_RED
);
3511 Inc(gTeamStat
[TEAM_RED
].Goals
);
3512 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3513 gLMSRespawnTime
:= gTime
+ 5000;
3515 else if (ar
= 0) and (ab
<> 0) then
3518 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 144);
3520 MH_SEND_GameEvent(NET_EV_TLMS_WIN
, TEAM_BLUE
);
3521 Inc(gTeamStat
[TEAM_BLUE
].Goals
);
3522 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3523 gLMSRespawnTime
:= gTime
+ 5000;
3525 else if (ar
= 0) and (ab
= 0) then
3528 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
3530 MH_SEND_GameEvent(NET_EV_LMS_DRAW
, 0, FName
);
3531 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3532 gLMSRespawnTime
:= gTime
+ 5000;
3535 else if (gGameSettings
.GameMode
= GM_DM
) then
3539 if gPlayers
[k
] <> nil then
3542 // survivor is the winner
3543 g_Game_Message(Format(_lc
[I_MESSAGE_LMS_WIN
], [AnsiUpperCase(FName
)]), 144);
3545 MH_SEND_GameEvent(NET_EV_LMS_WIN
, 0, FName
);
3548 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3549 gLMSRespawnTime
:= gTime
+ 5000;
3551 else if (a
= 0) then
3553 // everyone is dead, restart the map
3554 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
3556 MH_SEND_GameEvent(NET_EV_LMS_DRAW
, 0, FName
);
3557 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3558 gLMSRespawnTime
:= gTime
+ 5000;
3561 if srv
and (OldLR
= LMS_RESPAWN_NONE
) and (gLMSRespawn
> LMS_RESPAWN_NONE
) then
3563 if NetMode
= NET_SERVER
then
3564 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, (gLMSRespawnTime
- gTime
) div 1000)
3566 g_Console_Add(Format(_lc
[I_MSG_WARMUP_START
], [(gLMSRespawnTime
- gTime
) div 1000]), True);
3572 MH_SEND_PlayerStats(FUID
);
3573 MH_SEND_PlayerDeath(FUID
, KillType
, t
, SpawnerUID
);
3574 if gGameSettings
.GameMode
= GM_TDM
then MH_SEND_GameStats
;
3577 if srv
and FNoRespawn
then Spectate(True);
3578 FWantsInGame
:= True;
3581 function TPlayer
.BodyInLiquid(XInc
, YInc
: Integer): Boolean;
3583 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
, PLAYER_RECT
.Width
,
3584 PLAYER_RECT
.Height
-20, PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, False);
3587 function TPlayer
.BodyInAcid(XInc
, YInc
: Integer): Boolean;
3589 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
, PLAYER_RECT
.Width
,
3590 PLAYER_RECT
.Height
-20, PANEL_ACID1
or PANEL_ACID2
, False);
3593 procedure TPlayer
.MakeBloodSimple(Count
: Word);
3595 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)+8,
3596 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3597 Count
div 2, 3, -1, 16, (PLAYER_RECT
.Height
*2 div 3),
3598 FModel
.Blood
.R
, FModel
.Blood
.G
, FModel
.Blood
.B
, FModel
.Blood
.Kind
);
3599 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-8,
3600 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3601 Count
div 2, -3, -1, 16, (PLAYER_RECT
.Height
*2) div 3,
3602 FModel
.Blood
.R
, FModel
.Blood
.G
, FModel
.Blood
.B
, FModel
.Blood
.Kind
);
3605 procedure TPlayer
.MakeBloodVector(Count
: Word; VelX
, VelY
: Integer);
3607 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
3608 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3609 Count
, VelX
, VelY
, 16, (PLAYER_RECT
.Height
*2) div 3,
3610 FModel
.Blood
.R
, FModel
.Blood
.G
, FModel
.Blood
.B
, FModel
.Blood
.Kind
);
3613 procedure TPlayer
.QueueWeaponSwitch(Weapon
: Byte);
3615 if g_Game_IsClient
then Exit
;
3616 if Weapon
> High(FWeapon
) then Exit
;
3617 FNextWeap
:= FNextWeap
or (1 shl Weapon
);
3620 procedure TPlayer
.resetWeaponQueue ();
3623 FNextWeapDelay
:= 0;
3626 function TPlayer
.hasAmmoForWeapon (weapon
: Byte): Boolean;
3630 WEAPON_KASTET
, WEAPON_SAW
: result
:= true;
3631 WEAPON_SHOTGUN1
, WEAPON_SHOTGUN2
: result
:= (FAmmo
[A_SHELLS
] > 0);
3632 WEAPON_PISTOL
, WEAPON_CHAINGUN
, WEAPON_SUPERPULEMET
: result
:= (FAmmo
[A_BULLETS
] > 0);
3633 WEAPON_ROCKETLAUNCHER
: result
:= (FAmmo
[A_ROCKETS
] > 0);
3634 WEAPON_PLASMA
, WEAPON_BFG
: result
:= (FAmmo
[A_CELLS
] > 0);
3635 WEAPON_FLAMETHROWER
: result
:= (FAmmo
[A_FUEL
] > 0);
3636 else result
:= (weapon
< length(FWeapon
));
3640 // return 255 for "no switch"
3641 function TPlayer
.getNextWeaponIndex (): Byte;
3644 wantThisWeapon
: array[0..64] of Boolean;
3645 wwc
: Integer = 0; //HACK!
3648 result
:= 255; // default result: "no switch"
3649 // had weapon cycling on previous frame? remove that flag
3650 if (FNextWeap
and $2000) <> 0 then
3652 FNextWeap
:= FNextWeap
and $1FFF;
3653 FNextWeapDelay
:= 0;
3655 // cycling has priority
3656 if (FNextWeap
and $C000) <> 0 then
3658 if (FNextWeap
and $8000) <> 0 then
3662 FNextWeap
:= FNextWeap
or $2000; // we need this
3663 if FNextWeapDelay
> 0 then
3664 exit
; // cooldown time
3666 for i
:= 0 to High(FWeapon
) do
3668 cwi
:= (cwi
+length(FWeapon
)+dir
) mod length(FWeapon
);
3669 if FWeapon
[cwi
] then
3671 //e_WriteLog(Format(' SWITCH: cur=%d; new=%d', [FCurrWeap, cwi]), MSG_WARNING);
3672 result
:= Byte(cwi
);
3673 FNextWeapDelay
:= WEAPON_DELAY
;
3681 for i
:= 0 to High(wantThisWeapon
) do
3682 wantThisWeapon
[i
] := false;
3683 for i
:= 0 to High(FWeapon
) do
3684 if (FNextWeap
and (1 shl i
)) <> 0 then
3686 wantThisWeapon
[i
] := true;
3689 // exclude currently selected weapon from the set
3690 wantThisWeapon
[FCurrWeap
] := false;
3691 // slow down alterations a little
3694 //e_WriteLog(Format(' FNextWeap=%x; delay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
3695 // more than one weapon requested, assume "alteration" and check alteration delay
3696 if FNextWeapDelay
> 0 then
3702 // do not reset weapon queue, it will be done in `RealizeCurrentWeapon()`
3703 // but clear all counters if no weapon should be switched
3709 //e_WriteLog(Format('wwc=%d', [wwc]), MSG_WARNING);
3710 // try weapons in descending order
3711 for i
:= High(FWeapon
) downto 0 do
3713 if wantThisWeapon
[i
] and FWeapon
[i
] and ((wwc
= 1) or hasAmmoForWeapon(i
)) then
3718 FNextWeapDelay
:= WEAPON_DELAY
; // anyway, 'cause why not
3722 // no suitable weapon found, so reset the queue, to avoid accidental "queuing" of weapon w/o ammo
3726 procedure TPlayer
.RealizeCurrentWeapon();
3727 function switchAllowed (): Boolean;
3732 if FBFGFireCounter
<> -1 then
3734 if FTime
[T_SWITCH
] > gTime
then
3736 for i
:= WP_FIRST
to WP_LAST
do
3737 if FReloading
[i
] > 0 then
3745 //e_WriteLog(Format('***RealizeCurrentWeapon: FNextWeap=%x; FNextWeapDelay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
3746 //FNextWeap := FNextWeap and $1FFF;
3747 if FNextWeapDelay
> 0 then Dec(FNextWeapDelay
); // "alteration delay"
3749 if not switchAllowed
then
3751 //HACK for weapon cycling
3752 if (FNextWeap
and $E000) <> 0 then FNextWeap
:= 0;
3756 nw
:= getNextWeaponIndex();
3757 if nw
= 255 then exit
; // don't reset anything here
3758 if nw
> High(FWeapon
) then
3760 // don't forget to reset queue here!
3761 //e_WriteLog(' RealizeCurrentWeapon: WUTAFUUUU', MSG_WARNING);
3769 FTime
[T_SWITCH
] := gTime
+156;
3770 if FCurrWeap
= WEAPON_SAW
then FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3771 FModel
.SetWeapon(FCurrWeap
);
3772 if g_Game_IsNet
then MH_SEND_PlayerStats(FUID
);
3776 procedure TPlayer
.NextWeapon();
3778 if g_Game_IsClient
then Exit
;
3782 procedure TPlayer
.PrevWeapon();
3784 if g_Game_IsClient
then Exit
;
3788 procedure TPlayer
.SetWeapon(W
: Byte);
3790 if FCurrWeap
<> W
then
3791 if W
= WEAPON_SAW
then
3792 FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3795 FModel
.SetWeapon(CurrWeap
);
3799 function TPlayer
.PickItem(ItemType
: Byte; arespawn
: Boolean; var remove
: Boolean): Boolean;
3801 function allowBerserkSwitching (): Boolean;
3803 if (FBFGFireCounter
<> -1) then begin result
:= false; exit
; end;
3805 if gBerserkAutoswitch
then exit
;
3806 if not conIsCheatsEnabled
then exit
;
3814 if g_Game_IsClient
then Exit
;
3816 // a = true - ìåñòî ñïàâíà ïðåäìåòà:
3817 a
:= LongBool(gGameSettings
.Options
and GAME_OPTION_WEAPONSTAY
) and arespawn
;
3822 if FHealth
< PLAYER_HP_SOFT
then
3824 IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
3828 if gFlash
= 2 then Inc(FPickup
, 5);
3832 if FHealth
< PLAYER_HP_SOFT
then
3834 IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
3838 if gFlash
= 2 then Inc(FPickup
, 5);
3842 if FArmor
< PLAYER_AP_SOFT
then
3844 FArmor
:= PLAYER_AP_SOFT
;
3847 if gFlash
= 2 then Inc(FPickup
, 5);
3851 if FArmor
< PLAYER_AP_LIMIT
then
3853 FArmor
:= PLAYER_AP_LIMIT
;
3856 if gFlash
= 2 then Inc(FPickup
, 5);
3860 if FHealth
< PLAYER_HP_LIMIT
then
3862 IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
3866 if gFlash
= 2 then Inc(FPickup
, 5);
3870 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) then
3872 if FHealth
< PLAYER_HP_LIMIT
then
3873 FHealth
:= PLAYER_HP_LIMIT
;
3874 if FArmor
< PLAYER_AP_LIMIT
then
3875 FArmor
:= PLAYER_AP_LIMIT
;
3879 if gFlash
= 2 then Inc(FPickup
, 5);
3883 if (not FWeapon
[WEAPON_SAW
]) or ((not arespawn
) and (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
])) then
3885 FWeapon
[WEAPON_SAW
] := True;
3887 if gFlash
= 2 then Inc(FPickup
, 5);
3888 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3891 ITEM_WEAPON_SHOTGUN1
:
3892 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN1
] then
3894 // Íóæíî, ÷òîáû íå âçÿòü âñå ïóëè ñðàçó:
3895 if a
and FWeapon
[WEAPON_SHOTGUN1
] then Exit
;
3897 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3898 FWeapon
[WEAPON_SHOTGUN1
] := True;
3900 if gFlash
= 2 then Inc(FPickup
, 5);
3901 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3904 ITEM_WEAPON_SHOTGUN2
:
3905 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN2
] then
3907 if a
and FWeapon
[WEAPON_SHOTGUN2
] then Exit
;
3909 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3910 FWeapon
[WEAPON_SHOTGUN2
] := True;
3912 if gFlash
= 2 then Inc(FPickup
, 5);
3913 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3916 ITEM_WEAPON_CHAINGUN
:
3917 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or not FWeapon
[WEAPON_CHAINGUN
] then
3919 if a
and FWeapon
[WEAPON_CHAINGUN
] then Exit
;
3921 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
3922 FWeapon
[WEAPON_CHAINGUN
] := True;
3924 if gFlash
= 2 then Inc(FPickup
, 5);
3925 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3928 ITEM_WEAPON_ROCKETLAUNCHER
:
3929 if (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or not FWeapon
[WEAPON_ROCKETLAUNCHER
] then
3931 if a
and FWeapon
[WEAPON_ROCKETLAUNCHER
] then Exit
;
3933 IncMax(FAmmo
[A_ROCKETS
], 2, FMaxAmmo
[A_ROCKETS
]);
3934 FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
3936 if gFlash
= 2 then Inc(FPickup
, 5);
3937 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3941 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_PLASMA
] then
3943 if a
and FWeapon
[WEAPON_PLASMA
] then Exit
;
3945 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3946 FWeapon
[WEAPON_PLASMA
] := True;
3948 if gFlash
= 2 then Inc(FPickup
, 5);
3949 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3953 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_BFG
] then
3955 if a
and FWeapon
[WEAPON_BFG
] then Exit
;
3957 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3958 FWeapon
[WEAPON_BFG
] := True;
3960 if gFlash
= 2 then Inc(FPickup
, 5);
3961 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3964 ITEM_WEAPON_SUPERPULEMET
:
3965 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SUPERPULEMET
] then
3967 if a
and FWeapon
[WEAPON_SUPERPULEMET
] then Exit
;
3969 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3970 FWeapon
[WEAPON_SUPERPULEMET
] := True;
3972 if gFlash
= 2 then Inc(FPickup
, 5);
3973 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3976 ITEM_WEAPON_FLAMETHROWER
:
3977 if (FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
]) or not FWeapon
[WEAPON_FLAMETHROWER
] then
3979 if a
and FWeapon
[WEAPON_FLAMETHROWER
] then Exit
;
3981 IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
3982 FWeapon
[WEAPON_FLAMETHROWER
] := True;
3984 if gFlash
= 2 then Inc(FPickup
, 5);
3985 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3989 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
3991 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
3994 if gFlash
= 2 then Inc(FPickup
, 5);
3997 ITEM_AMMO_BULLETS_BOX
:
3998 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
4000 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
4003 if gFlash
= 2 then Inc(FPickup
, 5);
4007 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
4009 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4012 if gFlash
= 2 then Inc(FPickup
, 5);
4015 ITEM_AMMO_SHELLS_BOX
:
4016 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
4018 IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
4021 if gFlash
= 2 then Inc(FPickup
, 5);
4025 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
4027 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
4030 if gFlash
= 2 then Inc(FPickup
, 5);
4033 ITEM_AMMO_ROCKET_BOX
:
4034 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
4036 IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
4039 if gFlash
= 2 then Inc(FPickup
, 5);
4043 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
4045 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
4048 if gFlash
= 2 then Inc(FPickup
, 5);
4052 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
4054 IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
4057 if gFlash
= 2 then Inc(FPickup
, 5);
4061 if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then
4063 IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
4066 if gFlash
= 2 then Inc(FPickup
, 5);
4070 if not(R_ITEM_BACKPACK
in FRulez
) or
4071 (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
4072 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
4073 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
4074 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or
4075 (FMaxAmmo
[A_FUEL
] < AmmoLimits
[1, A_FUEL
]) then
4077 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[1, A_BULLETS
];
4078 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[1, A_SHELLS
];
4079 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[1, A_ROCKETS
];
4080 FMaxAmmo
[A_CELLS
] := AmmoLimits
[1, A_CELLS
];
4081 FMaxAmmo
[A_FUEL
] := AmmoLimits
[1, A_FUEL
];
4083 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
4084 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
4085 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
4086 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4087 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
4088 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
4089 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
4090 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
4092 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
4095 if gFlash
= 2 then Inc(FPickup
, 5);
4099 if not(R_KEY_RED
in FRulez
) then
4101 Include(FRulez
, R_KEY_RED
);
4103 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
4104 if gFlash
= 2 then Inc(FPickup
, 5);
4105 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
4109 if not(R_KEY_GREEN
in FRulez
) then
4111 Include(FRulez
, R_KEY_GREEN
);
4113 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
4114 if gFlash
= 2 then Inc(FPickup
, 5);
4115 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
4119 if not(R_KEY_BLUE
in FRulez
) then
4121 Include(FRulez
, R_KEY_BLUE
);
4123 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
4124 if gFlash
= 2 then Inc(FPickup
, 5);
4125 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
4129 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
4131 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
4135 if gFlash
= 2 then Inc(FPickup
, 5);
4139 if FAir
< AIR_MAX
then
4144 if gFlash
= 2 then Inc(FPickup
, 5);
4149 if not (R_BERSERK
in FRulez
) then
4151 Include(FRulez
, R_BERSERK
);
4152 if allowBerserkSwitching
then
4154 FCurrWeap
:= WEAPON_KASTET
;
4156 FModel
.SetWeapon(WEAPON_KASTET
);
4161 if gFlash
= 2 then Inc(FPickup
, 5);
4163 FBerserk
:= gTime
+30000;
4168 if FHealth
< PLAYER_HP_SOFT
then
4170 FHealth
:= PLAYER_HP_SOFT
;
4171 FBerserk
:= gTime
+30000;
4179 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
4181 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
4184 if gFlash
= 2 then Inc(FPickup
, 5);
4188 if FHealth
< PLAYER_HP_LIMIT
then
4190 IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
4194 if gFlash
= 2 then Inc(FPickup
, 5);
4198 if FArmor
< PLAYER_AP_LIMIT
then
4200 IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
4203 if gFlash
= 2 then Inc(FPickup
, 5);
4207 if FJetFuel
< JET_MAX
then
4209 FJetFuel
:= JET_MAX
;
4212 if gFlash
= 2 then Inc(FPickup
, 5);
4216 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
4218 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
4221 if gFlash
= 2 then Inc(FPickup
, 5);
4226 procedure TPlayer
.Touch();
4230 //FModel.PlaySound(MODELSOUND_PAIN, 1, FObj.X, FObj.Y);
4233 // Áðîñèòü ôëàã òîâàðèùó:
4234 if gGameSettings
.GameMode
= GM_CTF
then
4239 procedure TPlayer
.Push(vx
, vy
: Integer);
4241 if (not FPhysics
) and FGhost
then
4243 FObj
.Accel
.X
:= FObj
.Accel
.X
+ vx
;
4244 FObj
.Accel
.Y
:= FObj
.Accel
.Y
+ vy
;
4245 if g_Game_IsNet
and g_Game_IsServer
then
4246 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
4249 procedure TPlayer
.Reset(Force
: Boolean);
4255 FTime
[T_RESPAWN
] := 0;
4256 FTime
[T_FLAGCAP
] := 0;
4269 FSpectator
:= False;
4272 FSpectatePlayer
:= -1;
4273 FNoRespawn
:= False;
4275 FLives
:= gGameSettings
.MaxLives
;
4280 procedure TPlayer
.SoftReset();
4286 FBFGFireCounter
:= -1;
4294 SetAction(A_STAND
, True);
4297 function TPlayer
.GetRespawnPoint(): Byte;
4302 // Íà áóäóùåå: FSpawn - èãðîê óæå èãðàë è ïåðåðîæäàåòñÿ
4304 // Îäèíî÷íàÿ èãðà/êîîïåðàòèâ
4305 if gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
] then
4307 if (Self
= gPlayer1
) or (Self
= gPlayer2
) then
4309 // Òî÷êà ïîÿâëåíèÿ ñâîåãî èãðîêà
4310 if Self
= gPlayer1
then
4311 c
:= RESPAWNPOINT_PLAYER1
4313 c
:= RESPAWNPOINT_PLAYER2
;
4314 if g_Map_GetPointCount(c
) > 0 then
4320 // Òî÷êà ïîÿâëåíèÿ äðóãîãî èãðîêà
4321 if Self
= gPlayer1
then
4322 c
:= RESPAWNPOINT_PLAYER2
4324 c
:= RESPAWNPOINT_PLAYER1
;
4325 if g_Map_GetPointCount(c
) > 0 then
4332 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà (áîòà)
4333 if Random(2) = 0 then
4334 c
:= RESPAWNPOINT_PLAYER1
4336 c
:= RESPAWNPOINT_PLAYER2
;
4337 if g_Map_GetPointCount(c
) > 0 then
4344 // Òî÷êà ëþáîé èç êîìàíä
4345 if Random(2) = 0 then
4346 c
:= RESPAWNPOINT_RED
4348 c
:= RESPAWNPOINT_BLUE
;
4349 if g_Map_GetPointCount(c
) > 0 then
4356 c
:= RESPAWNPOINT_DM
;
4357 if g_Map_GetPointCount(c
) > 0 then
4365 if gGameSettings
.GameMode
= GM_DM
then
4368 c
:= RESPAWNPOINT_DM
;
4369 if g_Map_GetPointCount(c
) > 0 then
4375 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà
4376 if Random(2) = 0 then
4377 c
:= RESPAWNPOINT_PLAYER1
4379 c
:= RESPAWNPOINT_PLAYER2
;
4380 if g_Map_GetPointCount(c
) > 0 then
4386 // Òî÷êà ëþáîé èç êîìàíä
4387 if Random(2) = 0 then
4388 c
:= RESPAWNPOINT_RED
4390 c
:= RESPAWNPOINT_BLUE
;
4391 if g_Map_GetPointCount(c
) > 0 then
4399 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
4401 // Òî÷êà ñâîåé êîìàíäû
4402 c
:= RESPAWNPOINT_DM
;
4403 if FTeam
= TEAM_RED
then
4404 c
:= RESPAWNPOINT_RED
;
4405 if FTeam
= TEAM_BLUE
then
4406 c
:= RESPAWNPOINT_BLUE
;
4407 if g_Map_GetPointCount(c
) > 0 then
4414 c
:= RESPAWNPOINT_DM
;
4415 if g_Map_GetPointCount(c
) > 0 then
4421 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà
4422 if Random(2) = 0 then
4423 c
:= RESPAWNPOINT_PLAYER1
4425 c
:= RESPAWNPOINT_PLAYER2
;
4426 if g_Map_GetPointCount(c
) > 0 then
4432 // Òî÷êà äðóãîé êîìàíäû
4433 c
:= RESPAWNPOINT_DM
;
4434 if FTeam
= TEAM_RED
then
4435 c
:= RESPAWNPOINT_BLUE
;
4436 if FTeam
= TEAM_BLUE
then
4437 c
:= RESPAWNPOINT_RED
;
4438 if g_Map_GetPointCount(c
) > 0 then
4446 procedure TPlayer
.Respawn(Silent
: Boolean; Force
: Boolean = False);
4448 RespawnPoint
: TRespawnPoint
;
4454 FBFGFireCounter
:= -1;
4459 if not g_Game_IsServer
then
4463 FWantsInGame
:= True;
4464 FJustTeleported
:= True;
4467 FTime
[T_RESPAWN
] := 0;
4471 // if server changes MaxLives we gotta be ready
4472 if gGameSettings
.MaxLives
= 0 then FNoRespawn
:= False;
4474 // Åùå íåëüçÿ âîçðîäèòüñÿ:
4475 if FTime
[T_RESPAWN
] > gTime
then
4478 // Ïðîñðàë âñå æèçíè:
4481 if not FSpectator
then Spectate(True);
4482 FWantsInGame
:= True;
4486 if (gGameSettings
.GameType
<> GT_SINGLE
) and (gGameSettings
.GameMode
<> GM_COOP
) then
4487 begin // "Ñâîÿ èãðà"
4488 // Áåðñåðê íå ñîõðàíÿåòñÿ ìåæäó óðîâíÿìè:
4489 FRulez
:= FRulez
-[R_BERSERK
];
4491 else // "Îäèíî÷íàÿ èãðà"/"Êîîï"
4493 // Áåðñåðê è êëþ÷è íå ñîõðàíÿþòñÿ ìåæäó óðîâíÿìè:
4494 FRulez
:= FRulez
-[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
, R_BERSERK
];
4497 // Ïîëó÷àåì òî÷êó ñïàóíà èãðîêà:
4498 c
:= GetRespawnPoint();
4503 // Âîñêðåøåíèå áåç îðóæèÿ:
4506 FHealth
:= PLAYER_HP_SOFT
;
4512 for a
:= WP_FIRST
to WP_LAST
do
4514 FWeapon
[a
] := False;
4518 FWeapon
[WEAPON_PISTOL
] := True;
4519 FWeapon
[WEAPON_KASTET
] := True;
4520 FCurrWeap
:= WEAPON_PISTOL
;
4523 FModel
.SetWeapon(FCurrWeap
);
4525 for b
:= A_BULLETS
to A_HIGH
do
4528 FAmmo
[A_BULLETS
] := 50;
4530 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[0, A_BULLETS
];
4531 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[0, A_SHELLS
];
4532 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[0, A_SHELLS
];
4533 FMaxAmmo
[A_CELLS
] := AmmoLimits
[0, A_CELLS
];
4534 FMaxAmmo
[A_FUEL
] := AmmoLimits
[0, A_FUEL
];
4536 if gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
] then
4537 FRulez
:= [R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
]
4542 // Ïîëó÷àåì êîîðäèíàòû òî÷êè âîçðîæäåíèÿ:
4543 if not g_Map_GetPoint(c
, RespawnPoint
) then
4545 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
4549 // Óñòàíîâêà êîîðäèíàò è ñáðîñ âñåõ ïàðàìåòðîâ:
4550 FObj
.X
:= RespawnPoint
.X
-PLAYER_RECT
.X
;
4551 FObj
.Y
:= RespawnPoint
.Y
-PLAYER_RECT
.Y
;
4557 FDirection
:= RespawnPoint
.Direction
;
4558 if FDirection
= TDirection
.D_LEFT
then
4563 SetAction(A_STAND
, True);
4564 FModel
.Direction
:= FDirection
;
4566 for a
:= Low(FTime
) to High(FTime
) do
4569 for a
:= Low(FMegaRulez
) to High(FMegaRulez
) do
4574 FCanJetpack
:= False;
4580 // Àíèìàöèÿ âîçðîæäåíèÿ:
4581 if (not gLoadGameMode
) and (not Silent
) then
4582 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
4584 Anim
:= TAnimation
.Create(ID
, False, 3);
4585 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4586 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4590 FSpectator
:= False;
4593 FSpectatePlayer
:= -1;
4596 if (gPlayer1
= nil) and (gLMSPID1
= FUID
) then
4598 if (gPlayer2
= nil) and (gLMSPID2
= FUID
) then
4601 if g_Game_IsNet
then
4603 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
4604 MH_SEND_PlayerStats(FUID
, NET_EVERYONE
);
4606 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4607 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32,
4612 procedure TPlayer
.Spectate(NoMove
: Boolean = False);
4615 Kill(K_EXTRAHARDKILL
, FUID
, HIT_SOME
)
4616 else if (not NoMove
) then
4618 GameX
:= gMapInfo
.Width
div 2;
4619 GameY
:= gMapInfo
.Height
div 2;
4628 FWantsInGame
:= False;
4633 if Self
= gPlayer1
then
4638 if Self
= gPlayer2
then
4645 if g_Game_IsNet
then
4646 MH_SEND_PlayerStats(FUID
);
4649 procedure TPlayer
.SwitchNoClip
;
4653 FGhost
:= not FGhost
;
4654 FPhysics
:= not FGhost
;
4666 procedure TPlayer
.Run(Direction
: TDirection
);
4670 if MAX_RUNVEL
> 8 then
4674 if Direction
= TDirection
.D_LEFT
then
4676 if FObj
.Vel
.X
> -MAX_RUNVEL
then
4677 FObj
.Vel
.X
:= FObj
.Vel
.X
- (MAX_RUNVEL
shr 3);
4680 if FObj
.Vel
.X
< MAX_RUNVEL
then
4681 FObj
.Vel
.X
:= FObj
.Vel
.X
+ (MAX_RUNVEL
shr 3);
4683 // Âîçìîæíî, ïèíàåì êóñêè:
4684 if (FObj
.Vel
.X
<> 0) and (gGibs
<> nil) then
4686 b
:= Abs(FObj
.Vel
.X
);
4687 if b
> 1 then b
:= b
* (Random(8 div b
) + 1);
4688 for a
:= 0 to High(gGibs
) do
4690 if gGibs
[a
].alive
and
4691 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
+FObj
.Rect
.Height
-4,
4692 FObj
.Rect
.Width
, 8, @gGibs
[a
].Obj
) and (Random(3) = 0) then
4695 if FObj
.Vel
.X
< 0 then
4697 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)+120) // íàëåâî
4701 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)); // íàïðàâî
4703 gGibs
[a
].positionChanged(); // this updates spatial accelerators
4711 procedure TPlayer
.SeeDown();
4713 SetAction(A_SEEDOWN
);
4715 if FDirection
= TDirection
.D_LEFT
then FAngle
:= ANGLE_LEFTDOWN
else FAngle
:= ANGLE_RIGHTDOWN
;
4717 if FIncCam
> -120 then DecMin(FIncCam
, 5, -120);
4720 procedure TPlayer
.SeeUp();
4724 if FDirection
= TDirection
.D_LEFT
then FAngle
:= ANGLE_LEFTUP
else FAngle
:= ANGLE_RIGHTUP
;
4726 if FIncCam
< 120 then IncMax(FIncCam
, 5, 120);
4729 procedure TPlayer
.SetAction(Action
: Byte; Force
: Boolean = False);
4737 A_ATTACK
: Prior
:= 2;
4738 A_SEEUP
: Prior
:= 1;
4739 A_SEEDOWN
: Prior
:= 1;
4740 A_ATTACKUP
: Prior
:= 2;
4741 A_ATTACKDOWN
: Prior
:= 2;
4746 if (Prior
> FActionPrior
) or Force
then
4747 if not ((Prior
= 2) and (FCurrWeap
= WEAPON_SAW
)) then
4749 FActionPrior
:= Prior
;
4750 FActionAnim
:= Action
;
4751 FActionForce
:= Force
;
4752 FActionChanged
:= True;
4755 if Action
in [A_ATTACK
, A_ATTACKUP
, A_ATTACKDOWN
] then FModel
.SetFire(True);
4758 function TPlayer
.StayOnStep(XInc
, YInc
: Integer): Boolean;
4760 Result
:= not g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
-1,
4761 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False)
4762 and g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
,
4763 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False);
4766 function TPlayer
.TeleportTo(X
, Y
: Integer; silent
: Boolean; dir
: Byte): Boolean;
4773 if g_CollideLevel(X
, Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
) then
4775 g_Sound_PlayExAt('SOUND_GAME_NOTELEPORT', FObj
.X
, FObj
.Y
);
4776 if g_Game_IsServer
and g_Game_IsNet
then
4777 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_GAME_NOTELEPORT');
4781 FJustTeleported
:= True;
4786 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
4788 Anim
:= TAnimation
.Create(ID
, False, 3);
4791 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', FObj
.X
, FObj
.Y
);
4792 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4793 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4794 if g_Game_IsServer
and g_Game_IsNet
then
4795 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4796 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 1,
4800 FObj
.X
:= X
-PLAYER_RECT
.X
;
4801 FObj
.Y
:= Y
-PLAYER_RECT
.Y
;
4802 if FAlive
and FGhost
then
4808 if not g_Game_IsNet
then
4812 SetDirection(TDirection
.D_LEFT
);
4818 SetDirection(TDirection
.D_RIGHT
);
4824 if FDirection
= TDirection
.D_RIGHT
then
4826 SetDirection(TDirection
.D_LEFT
);
4831 SetDirection(TDirection
.D_RIGHT
);
4837 if not silent
and (Anim
<> nil) then
4839 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4840 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4843 if g_Game_IsServer
and g_Game_IsNet
then
4844 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4845 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 0,
4852 function nonz(a
: Single): Single;
4860 function TPlayer
.followCorpse(): Boolean;
4865 if FAlive
or FSpectator
then
4867 if (gCorpses
= nil) or (Length(gCorpses
) = 0) then
4869 for i
:= 0 to High(gCorpses
) do
4870 if gCorpses
[i
] <> nil then
4871 if gCorpses
[i
].FPlayerUID
= FUID
then
4874 FObj
.X
:= gCorpses
[i
].FObj
.X
;
4875 FObj
.Y
:= gCorpses
[i
].FObj
.Y
;
4876 FObj
.Vel
.X
:= gCorpses
[i
].FObj
.Vel
.X
;
4877 FObj
.Vel
.Y
:= gCorpses
[i
].FObj
.Vel
.Y
;
4878 FObj
.Accel
.X
:= gCorpses
[i
].FObj
.Accel
.X
;
4879 FObj
.Accel
.Y
:= gCorpses
[i
].FObj
.Accel
.Y
;
4884 procedure TPlayer
.Update();
4887 i
, ii
, wx
, wy
, xd
, yd
, k
: Integer;
4888 blockmon
, headwater
, dospawn
: Boolean;
4893 NetServer
:= g_Game_IsNet
and g_Game_IsServer
;
4894 AnyServer
:= g_Game_IsServer
;
4896 if g_Game_IsClient
and (NetInterpLevel
> 0) then
4897 DoLerp(NetInterpLevel
+ 1)
4903 if FClientID
>= 0 then
4905 FPing
:= NetClients
[FClientID
].Peer
^.lastRoundTripTime
;
4906 if NetClients
[FClientID
].Peer
^.packetsSent
> 0 then
4907 FLoss
:= Round(100*NetClients
[FClientID
].Peer
^.packetsLost
/NetClients
[FClientID
].Peer
^.packetsSent
)
4916 if FAlive
and (FPunchAnim
<> nil) then
4917 FPunchAnim
.Update();
4919 if FAlive
and (gFly
or FJetpack
) then
4922 if FDirection
= TDirection
.D_LEFT
then
4927 if FAlive
and (not FGhost
) then
4929 if FKeys
[KEY_UP
].Pressed
then
4931 if FKeys
[KEY_DOWN
].Pressed
then
4935 if (not (FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_DOWN
].Pressed
)) and
4938 i
:= g_basic
.Sign(FIncCam
);
4939 FIncCam
:= Abs(FIncCam
);
4940 DecMin(FIncCam
, 5, 0);
4941 FIncCam
:= FIncCam
*i
;
4944 // no need to do that each second frame, weapon queue will take care of it
4945 if FAlive
and FKeys
[KEY_NEXTWEAPON
].Pressed
and AnyServer
then NextWeapon();
4946 if FAlive
and FKeys
[KEY_PREVWEAPON
].Pressed
and AnyServer
then PrevWeapon();
4948 if gTime
mod (GAME_TICK
*2) <> 0 then
4950 if (FObj
.Vel
.X
= 0) and FAlive
then
4952 if FKeys
[KEY_LEFT
].Pressed
then
4953 Run(TDirection
.D_LEFT
);
4954 if FKeys
[KEY_RIGHT
].Pressed
then
4955 Run(TDirection
.D_RIGHT
);
4960 if not followCorpse() then
4961 g_Obj_Move(@FObj
, True, True, True);
4962 positionChanged(); // this updates spatial accelerators
4968 FActionChanged
:= False;
4972 // Let alive player do some actions
4973 if FKeys
[KEY_LEFT
].Pressed
then Run(TDirection
.D_LEFT
);
4974 if FKeys
[KEY_RIGHT
].Pressed
then Run(TDirection
.D_RIGHT
);
4975 //if FKeys[KEY_NEXTWEAPON].Pressed and AnyServer then NextWeapon();
4976 //if FKeys[KEY_PREVWEAPON].Pressed and AnyServer then PrevWeapon();
4977 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then Fire()
4983 if NetServer
then MH_SEND_PlayerStats(FUID
);
4986 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Use();
4987 if FKeys
[KEY_JUMP
].Pressed
then Jump()
4990 if AnyServer
and FJetpack
then
4994 if NetServer
then MH_SEND_PlayerStats(FUID
);
4996 FCanJetpack
:= True;
5003 for k
:= Low(FKeys
) to KEY_CHAT
-1 do
5005 if FKeys
[k
].Pressed
then
5013 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
5016 if (FTime
[T_RESPAWN
] <= gTime
) and
5017 gGameOn
and (not FAlive
) then
5019 if (g_Player_GetCount() > 1) then
5023 gExit
:= EXIT_RESTART
;
5028 // Dead spectator actions
5031 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Fire();
5032 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then
5036 if (FSpectatePlayer
>= High(gPlayers
)) then
5037 FSpectatePlayer
:= -1
5041 for I
:= FSpectatePlayer
+ 1 to High(gPlayers
) do
5042 if gPlayers
[I
] <> nil then
5043 if gPlayers
[I
].alive
then
5044 if gPlayers
[I
].UID
<> FUID
then
5046 FSpectatePlayer
:= I
;
5051 if not SetSpect
then FSpectatePlayer
:= -1;
5062 if FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_JUMP
].Pressed
then
5064 FYTo
:= FObj
.Y
- 32;
5065 FSpectatePlayer
:= -1;
5067 if FKeys
[KEY_DOWN
].Pressed
then
5069 FYTo
:= FObj
.Y
+ 32;
5070 FSpectatePlayer
:= -1;
5072 if FKeys
[KEY_LEFT
].Pressed
then
5074 FXTo
:= FObj
.X
- 32;
5075 FSpectatePlayer
:= -1;
5077 if FKeys
[KEY_RIGHT
].Pressed
then
5079 FXTo
:= FObj
.X
+ 32;
5080 FSpectatePlayer
:= -1;
5083 if (FXTo
< -64) then
5085 else if (FXTo
> gMapInfo
.Width
+ 32) then
5086 FXTo
:= gMapInfo
.Width
+ 32;
5087 if (FYTo
< -72) then
5089 else if (FYTo
> gMapInfo
.Height
+ 32) then
5090 FYTo
:= gMapInfo
.Height
+ 32;
5095 if not followCorpse() then
5096 g_Obj_Move(@FObj
, True, True, True);
5097 positionChanged(); // this updates spatial accelerators
5104 if (FSpectatePlayer
<= High(gPlayers
)) and (FSpectatePlayer
>= 0) then
5105 if gPlayers
[FSpectatePlayer
] <> nil then
5106 if gPlayers
[FSpectatePlayer
].alive
then
5108 FXTo
:= gPlayers
[FSpectatePlayer
].GameX
;
5109 FYTo
:= gPlayers
[FSpectatePlayer
].GameY
;
5113 blockmon
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
, FObj
.Y
+PLAYER_HEADRECT
.Y
,
5114 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
5115 PANEL_BLOCKMON
, True);
5116 headwater
:= HeadInLiquid(0, 0);
5118 // Ñîïðîòèâëåíèå âîçäóõà:
5119 if (not FAlive
) or not (FKeys
[KEY_LEFT
].Pressed
or FKeys
[KEY_RIGHT
].Pressed
) then
5120 if FObj
.Vel
.X
<> 0 then
5121 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
5123 if (FLastHit
= HIT_TRAP
) and (FPain
> 90) then FPain
:= 90;
5124 DecMin(FPain
, 5, 0);
5125 DecMin(FPickup
, 1, 0);
5127 if FAlive
and (FObj
.Y
> Integer(gMapInfo
.Height
)+128) and AnyServer
then
5129 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
5130 FMegaRulez
[MR_SUIT
] := 0;
5131 FMegaRulez
[MR_INVUL
] := 0;
5132 FMegaRulez
[MR_INVIS
] := 0;
5133 Kill(K_FALLKILL
, 0, HIT_FALL
);
5140 if FCurrWeap
= WEAPON_SAW
then
5141 if not (FSawSound
.IsPlaying() or FSawSoundHit
.IsPlaying() or
5142 FSawSoundSelect
.IsPlaying()) then
5143 FSawSoundIdle
.PlayAt(FObj
.X
, FObj
.Y
);
5146 if (not FJetSoundFly
.IsPlaying()) and (not FJetSoundOn
.IsPlaying()) and
5147 (not FJetSoundOff
.IsPlaying()) then
5149 FJetSoundFly
.SetPosition(0);
5150 FJetSoundFly
.PlayAt(FObj
.X
, FObj
.Y
);
5153 for b
:= WP_FIRST
to WP_LAST
do
5154 if FReloading
[b
] > 0 then
5160 if FShellTimer
> -1 then
5161 if FShellTimer
= 0 then
5163 if FShellType
= SHELL_SHELL
then
5164 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5165 GameVelX
, GameVelY
-2, SHELL_SHELL
)
5166 else if FShellType
= SHELL_DBLSHELL
then
5168 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5169 GameVelX
+1, GameVelY
-2, SHELL_SHELL
);
5170 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5171 GameVelX
-1, GameVelY
-2, SHELL_SHELL
);
5174 end else Dec(FShellTimer
);
5176 if (FBFGFireCounter
> -1) then
5177 if FBFGFireCounter
= 0 then
5181 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
5182 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
5183 xd
:= wx
+IfThen(FDirection
= TDirection
.D_LEFT
, -30, 30);
5184 yd
:= wy
+firediry();
5185 g_Weapon_bfgshot(wx
, wy
, xd
, yd
, FUID
);
5186 if NetServer
then MH_SEND_PlayerFire(FUID
, WEAPON_BFG
, wx
, wy
, xd
, yd
);
5187 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
5188 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
5189 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
5192 FReloading
[WEAPON_BFG
] := WEAPON_RELOAD
[WEAPON_BFG
];
5193 FBFGFireCounter
:= -1;
5196 FBFGFireCounter
:= 0
5198 Dec(FBFGFireCounter
);
5200 if (FMegaRulez
[MR_SUIT
] < gTime
) and AnyServer
then
5202 b
:= g_GetAcidHit(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
);
5204 if (b
> 0) and (gTime
mod (15*GAME_TICK
) = 0) then Damage(b
, 0, 0, 0, HIT_ACID
);
5207 if (headwater
or blockmon
) then
5213 if AnyServer
then Damage(10, 0, 0, 0, HIT_WATER
);
5216 else if (FAir
mod 31 = 0) and not blockmon
then
5218 g_GFX_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2), FObj
.Y
+PLAYER_RECT
.Y
-4, 5+Random(6), 8, 4);
5219 if Random(2) = 0 then
5220 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
5222 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
5224 end else if FAir
< AIR_DEF
then
5227 if FFireTime
> 0 then
5229 if BodyInLiquid(0, 0) then
5234 else if FMegaRulez
[MR_SUIT
] >= gTime
then
5236 if FMegaRulez
[MR_SUIT
] = gTime
then
5243 if FFirePainTime
<= 0 then
5245 if g_Game_IsServer
then
5246 Damage(5, FFireAttacker
, 0, 0, HIT_FLAME
);
5247 FFirePainTime
:= 18;
5249 FFirePainTime
:= FFirePainTime
- 1;
5250 FFireTime
:= FFireTime
- 1;
5251 if (FFireTime
= 0) and g_Game_IsNet
and g_Game_IsServer
then
5252 MH_SEND_PlayerStats(FUID
);
5256 if FDamageBuffer
> 0 then
5258 if FDamageBuffer
>= 9 then
5262 if FDamageBuffer
< 30 then i
:= 9
5263 else if FDamageBuffer
< 100 then i
:= 18
5267 ii
:= Round(FDamageBuffer
*FHealth
/ nonz(FArmor
*(3/4)+FHealth
));
5268 FArmor
:= FArmor
-(FDamageBuffer
-ii
);
5269 FHealth
:= FHealth
-ii
;
5272 FHealth
:= FHealth
+FArmor
;
5277 if FHealth
<= 0 then
5278 if FHealth
> -30 then Kill(K_SIMPLEKILL
, FLastSpawnerUID
, FLastHit
)
5279 else if FHealth
> -50 then Kill(K_HARDKILL
, FLastSpawnerUID
, FLastHit
)
5280 else Kill(K_EXTRAHARDKILL
, FLastSpawnerUID
, FLastHit
);
5284 if FDamageBuffer
<= 20 then FModel
.PlaySound(MODELSOUND_PAIN
, 1, FObj
.X
, FObj
.Y
)
5285 else if FDamageBuffer
<= 55 then FModel
.PlaySound(MODELSOUND_PAIN
, 2, FObj
.X
, FObj
.Y
)
5286 else if FDamageBuffer
<= 120 then FModel
.PlaySound(MODELSOUND_PAIN
, 3, FObj
.X
, FObj
.Y
)
5287 else FModel
.PlaySound(MODELSOUND_PAIN
, 4, FObj
.X
, FObj
.Y
);
5294 end; // if FAlive then ...
5296 if (FActionAnim
= A_PAIN
) and (FModel
.Animation
<> A_PAIN
) then
5298 FModel
.ChangeAnimation(FActionAnim
, FActionForce
);
5299 FModel
.GetCurrentAnimation
.MinLength
:= i
;
5300 FModel
.GetCurrentAnimationMask
.MinLength
:= i
;
5301 end else FModel
.ChangeAnimation(FActionAnim
, FActionForce
and (FModel
.Animation
<> A_STAND
));
5303 if (FModel
.GetCurrentAnimation
.Played
or ((not FActionChanged
) and (FModel
.Animation
= A_WALK
)))
5304 then SetAction(A_STAND
, True);
5306 if not ((FModel
.Animation
= A_WALK
) and (Abs(FObj
.Vel
.X
) < 4) and not FModel
.Fire
) then FModel
.Update
;
5308 for b
:= Low(FKeys
) to High(FKeys
) do
5309 if FKeys
[b
].Time
= 0 then FKeys
[b
].Pressed
:= False else Dec(FKeys
[b
].Time
);
5313 procedure TPlayer
.getMapBox (out x
, y
, w
, h
: Integer); inline;
5315 x
:= FObj
.X
+PLAYER_RECT
.X
;
5316 y
:= FObj
.Y
+PLAYER_RECT
.Y
;
5317 w
:= PLAYER_RECT
.Width
;
5318 h
:= PLAYER_RECT
.Height
;
5322 procedure TPlayer
.moveBy (dx
, dy
: Integer); inline;
5324 if (dx
<> 0) or (dy
<> 0) then
5333 function TPlayer
.Collide(X
, Y
: Integer; Width
, Height
: Word): Boolean;
5335 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
5336 FObj
.Y
+PLAYER_RECT
.Y
,
5343 function TPlayer
.Collide(Panel
: TPanel
): Boolean;
5345 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
5346 FObj
.Y
+PLAYER_RECT
.Y
,
5350 Panel
.Width
, Panel
.Height
);
5353 function TPlayer
.Collide(X
, Y
: Integer): Boolean;
5355 X
:= X
-FObj
.X
-PLAYER_RECT
.X
;
5356 Y
:= Y
-FObj
.Y
-PLAYER_RECT
.Y
;
5357 Result
:= (x
>= 0) and (x
<= PLAYER_RECT
.Width
) and
5358 (y
>= 0) and (y
<= PLAYER_RECT
.Height
);
5361 function g_Player_ValidName(Name
: string): Boolean;
5367 if gPlayers
= nil then Exit
;
5369 for a
:= 0 to High(gPlayers
) do
5370 if gPlayers
[a
] <> nil then
5371 if LowerCase(Name
) = LowerCase(gPlayers
[a
].FName
) then
5378 procedure TPlayer
.SetDirection(Direction
: TDirection
);
5382 d
:= FModel
.Direction
;
5384 FModel
.Direction
:= Direction
;
5385 if d
<> Direction
then FModel
.ChangeAnimation(FModel
.Animation
, True);
5387 FDirection
:= Direction
;
5390 function TPlayer
.GetKeys(): Byte;
5394 if R_KEY_RED
in FRulez
then Result
:= KEY_RED
;
5395 if R_KEY_GREEN
in FRulez
then Result
:= Result
or KEY_GREEN
;
5396 if R_KEY_BLUE
in FRulez
then Result
:= Result
or KEY_BLUE
;
5398 if FTeam
= TEAM_RED
then Result
:= Result
or KEY_REDTEAM
;
5399 if FTeam
= TEAM_BLUE
then Result
:= Result
or KEY_BLUETEAM
;
5402 procedure TPlayer
.Use();
5406 if FTime
[T_USE
] > gTime
then Exit
;
5408 g_Triggers_PressR(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
,
5409 PLAYER_RECT
.Height
, FUID
, ACTIVATE_PLAYERPRESS
);
5411 for a
:= 0 to High(gPlayers
) do
5412 if (gPlayers
[a
] <> nil) and (gPlayers
[a
] <> Self
) and
5413 gPlayers
[a
].alive
and SameTeam(FUID
, gPlayers
[a
].FUID
) and
5414 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
5415 FObj
.Rect
.Width
, FObj
.Rect
.Height
, @gPlayers
[a
].FObj
) then
5417 gPlayers
[a
].Touch();
5418 if g_Game_IsNet
and g_Game_IsServer
then
5419 MH_SEND_GameEvent(NET_EV_PLAYER_TOUCH
, gPlayers
[a
].FUID
);
5422 FTime
[T_USE
] := gTime
+120;
5425 procedure TPlayer
.NetFire(Wpn
: Byte; X
, Y
, AX
, AY
: Integer; WID
: Integer = -1);
5429 WX
, WY
, XD
, YD
: Integer;
5441 if R_BERSERK
in FRulez
then
5443 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
5444 locobj
.X
:= FObj
.X
+FObj
.Rect
.X
;
5445 locobj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
5448 locobj
.rect
.Width
:= 39;
5449 locobj
.rect
.Height
:= 52;
5450 locobj
.Vel
.X
:= (xd
-wx
) div 2;
5451 locobj
.Vel
.Y
:= (yd
-wy
) div 2;
5452 locobj
.Accel
.X
:= xd
-wx
;
5453 locobj
.Accel
.y
:= yd
-wy
;
5455 if g_Weapon_Hit(@locobj
, 50, FUID
, HIT_SOME
) <> 0 then
5456 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
5458 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
5462 FPain
:= min(FPain
+ 25, 50);
5464 g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
5469 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
5470 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
5472 FSawSoundSelect
.Stop();
5474 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
5476 else if not FSawSoundHit
.IsPlaying() then
5478 FSawSoundSelect
.Stop();
5479 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
5486 g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', GameX
, Gamey
);
5487 FFireAngle
:= FAngle
;
5489 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5490 GameVelX
, GameVelY
-2, SHELL_BULLET
);
5495 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
5496 FFireAngle
:= FAngle
;
5499 FShellType
:= SHELL_SHELL
;
5504 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN2', Gamex
, Gamey
);
5505 FFireAngle
:= FAngle
;
5508 FShellType
:= SHELL_DBLSHELL
;
5513 g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', Gamex
, Gamey
);
5514 FFireAngle
:= FAngle
;
5516 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5517 GameVelX
, GameVelY
-2, SHELL_BULLET
);
5520 WEAPON_ROCKETLAUNCHER
:
5522 g_Weapon_Rocket(wx
, wy
, xd
, yd
, FUID
, WID
);
5523 FFireAngle
:= FAngle
;
5529 g_Weapon_Plasma(wx
, wy
, xd
, yd
, FUID
, WID
);
5530 FFireAngle
:= FAngle
;
5536 g_Weapon_BFGShot(wx
, wy
, xd
, yd
, FUID
, WID
);
5537 FFireAngle
:= FAngle
;
5541 WEAPON_SUPERPULEMET
:
5543 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
5544 FFireAngle
:= FAngle
;
5546 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5547 GameVelX
, GameVelY
-2, SHELL_SHELL
);
5550 WEAPON_FLAMETHROWER
:
5552 g_Weapon_flame(wx
, wy
, xd
, yd
, FUID
, WID
);
5554 FFireAngle
:= FAngle
;
5561 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
5562 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
5563 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
5566 procedure TPlayer
.DoLerp(Level
: Integer = 2);
5568 if FObj
.X
<> FXTo
then FObj
.X
:= Lerp(FObj
.X
, FXTo
, Level
);
5569 if FObj
.Y
<> FYTo
then FObj
.Y
:= Lerp(FObj
.Y
, FYTo
, Level
);
5572 procedure TPlayer
.SetLerp(XTo
, YTo
: Integer);
5576 if NetInterpLevel
< 1 then
5586 AX
:= Abs(FXTo
- FObj
.X
);
5587 AY
:= Abs(FYTo
- FObj
.Y
);
5588 if (AX
> 32) or (AX
<= NetInterpLevel
) then
5590 if (AY
> 32) or (AY
<= NetInterpLevel
) then
5595 function TPlayer
.FullInLift(XInc
, YInc
: Integer): Integer;
5597 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5598 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5599 PANEL_LIFTUP
, False) then Result
:= -1
5601 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5602 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5603 PANEL_LIFTDOWN
, False) then Result
:= 1
5607 function TPlayer
.GetFlag(Flag
: Byte): Boolean;
5614 if Flag
= FLAG_NONE
then
5617 if not g_Game_IsServer
then Exit
;
5619 // Ïðèíåñ ÷óæîé ôëàã íà ñâîþ áàçó:
5620 if (Flag
= FTeam
) and
5621 (gFlags
[Flag
].State
= FLAG_STATE_NORMAL
) and
5622 (FFlag
<> FLAG_NONE
) then
5624 if FFlag
= FLAG_RED
then
5625 s
:= _lc
[I_PLAYER_FLAG_RED
]
5627 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5629 evtype
:= FLAG_STATE_SCORED
;
5631 ts
:= Format('%.4d', [gFlags
[FFlag
].CaptureTime
]);
5632 Insert('.', ts
, Length(ts
) + 1 - 3);
5633 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_CAPTURE
], [FName
, s
, ts
]), True);
5635 g_Map_ResetFlag(FFlag
);
5636 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_CAPTURE
], [AnsiUpperCase(s
)]), 144);
5638 if ((Self
= gPlayer1
) or (Self
= gPlayer2
)
5639 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= FTeam
))
5640 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= FTeam
))) then
5645 if not sound_cap_flag
[a
].IsPlaying() then
5646 sound_cap_flag
[a
].Play();
5648 gTeamStat
[FTeam
].Goals
:= gTeamStat
[FTeam
].Goals
+ 1;
5651 if g_Game_IsNet
then
5653 MH_SEND_FlagEvent(evtype
, FFlag
, FUID
, False);
5657 gFlags
[FFlag
].CaptureTime
:= 0;
5662 // Ïîäîáðàë ñâîé ôëàã - âåðíóë åãî íà áàçó:
5663 if (Flag
= FTeam
) and
5664 (gFlags
[Flag
].State
= FLAG_STATE_DROPPED
) then
5666 if Flag
= FLAG_RED
then
5667 s
:= _lc
[I_PLAYER_FLAG_RED
]
5669 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5671 evtype
:= FLAG_STATE_RETURNED
;
5672 gFlags
[Flag
].CaptureTime
:= 0;
5674 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_RETURN
], [FName
, s
]), True);
5676 g_Map_ResetFlag(Flag
);
5677 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
5679 if ((Self
= gPlayer1
) or (Self
= gPlayer2
)
5680 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= FTeam
))
5681 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= FTeam
))) then
5686 if not sound_ret_flag
[a
].IsPlaying() then
5687 sound_ret_flag
[a
].Play();
5690 if g_Game_IsNet
then
5692 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5698 // Ïîäîáðàë ÷óæîé ôëàã:
5699 if (Flag
<> FTeam
) and (FTime
[T_FLAGCAP
] <= gTime
) then
5703 if Flag
= FLAG_RED
then
5704 s
:= _lc
[I_PLAYER_FLAG_RED
]
5706 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5708 evtype
:= FLAG_STATE_CAPTURED
;
5710 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_GET
], [FName
, s
]), True);
5712 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_GET
], [AnsiUpperCase(s
)]), 144);
5714 gFlags
[Flag
].State
:= FLAG_STATE_CAPTURED
;
5716 if ((Self
= gPlayer1
) or (Self
= gPlayer2
)
5717 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= FTeam
))
5718 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= FTeam
))) then
5723 if not sound_get_flag
[a
].IsPlaying() then
5724 sound_get_flag
[a
].Play();
5727 if g_Game_IsNet
then
5729 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5735 procedure TPlayer
.SetFlag(Flag
: Byte);
5738 if FModel
<> nil then
5739 FModel
.SetFlag(FFlag
);
5742 function TPlayer
.DropFlag(Silent
: Boolean = True): Boolean;
5748 if (not g_Game_IsServer
) or (FFlag
= FLAG_NONE
) then
5750 FTime
[T_FLAGCAP
] := gTime
+ 2000;
5751 with gFlags
[FFlag
] do
5755 Direction
:= FDirection
;
5756 State
:= FLAG_STATE_DROPPED
;
5758 g_Obj_Push(@Obj
, (FObj
.Vel
.X
div 2)-2+Random(5),
5759 (FObj
.Vel
.Y
div 2)-2+Random(5));
5760 positionChanged(); // this updates spatial accelerators
5762 if FFlag
= FLAG_RED
then
5763 s
:= _lc
[I_PLAYER_FLAG_RED
]
5765 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5767 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_DROP
], [FName
, s
]), True);
5768 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_DROP
], [AnsiUpperCase(s
)]), 144);
5770 if ((Self
= gPlayer1
) or (Self
= gPlayer2
)
5771 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= FTeam
))
5772 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= FTeam
))) then
5777 if (not Silent
) and (not sound_lost_flag
[a
].IsPlaying()) then
5778 sound_lost_flag
[a
].Play();
5780 if g_Game_IsNet
then
5781 MH_SEND_FlagEvent(FLAG_STATE_DROPPED
, Flag
, FUID
, False);
5787 procedure TPlayer
.GetSecret();
5792 procedure TPlayer
.PressKey(Key
: Byte; Time
: Word = 1);
5794 Assert(Key
<= High(FKeys
));
5796 FKeys
[Key
].Pressed
:= True;
5797 FKeys
[Key
].Time
:= Time
;
5800 function TPlayer
.IsKeyPressed(K
: Byte): Boolean;
5802 Result
:= FKeys
[K
].Pressed
;
5805 procedure TPlayer
.ReleaseKeys();
5809 for a
:= Low(FKeys
) to High(FKeys
) do
5811 FKeys
[a
].Pressed
:= False;
5816 procedure TPlayer
.OnDamage(Angle
: SmallInt);
5820 function TPlayer
.firediry(): Integer;
5822 if FKeys
[KEY_UP
].Pressed
then Result
:= -42
5823 else if FKeys
[KEY_DOWN
].Pressed
then Result
:= 19
5827 procedure TPlayer
.RememberState();
5831 FSavedState
.Health
:= FHealth
;
5832 FSavedState
.Armor
:= FArmor
;
5833 FSavedState
.Air
:= FAir
;
5834 FSavedState
.JetFuel
:= FJetFuel
;
5835 FSavedState
.CurrWeap
:= FCurrWeap
;
5836 FSavedState
.NextWeap
:= FNextWeap
;
5837 FSavedState
.NextWeapDelay
:= FNextWeapDelay
;
5840 FSavedState
.Ammo
[i
] := FAmmo
[i
];
5842 FSavedState
.MaxAmmo
[i
] := FMaxAmmo
[i
];
5844 FSavedState
.Rulez
:= FRulez
;
5845 FSavedState
.WaitRecall
:= True;
5848 procedure TPlayer
.RecallState();
5852 if not FSavedState
.WaitRecall
then Exit
;
5854 FHealth
:= FSavedState
.Health
;
5855 FArmor
:= FSavedState
.Armor
;
5856 FAir
:= FSavedState
.Air
;
5857 FJetFuel
:= FSavedState
.JetFuel
;
5858 FCurrWeap
:= FSavedState
.CurrWeap
;
5859 FNextWeap
:= FSavedState
.NextWeap
;
5860 FNextWeapDelay
:= FSavedState
.NextWeapDelay
;
5863 FAmmo
[i
] := FSavedState
.Ammo
[i
];
5865 FMaxAmmo
[i
] := FSavedState
.MaxAmmo
[i
];
5867 FRulez
:= FSavedState
.Rulez
;
5868 FSavedState
.WaitRecall
:= False;
5870 if gGameSettings
.GameType
= GT_SERVER
then
5871 MH_SEND_PlayerStats(FUID
);
5874 procedure TPlayer
.SaveState (st
: TStream
);
5880 utils
.writeSign(st
, 'PLYR');
5881 utils
.writeInt(st
, Byte(PLR_SAVE_VERSION
)); // version
5883 utils
.writeBool(st
, FIamBot
);
5885 utils
.writeInt(st
, Word(FUID
));
5887 utils
.writeStr(st
, FName
);
5889 utils
.writeInt(st
, Byte(FTeam
));
5891 utils
.writeBool(st
, FAlive
);
5892 // Èçðàñõîäîâàë ëè âñå æèçíè
5893 utils
.writeBool(st
, FNoRespawn
);
5895 if FDirection
= TDirection
.D_LEFT
then b
:= 1 else b
:= 2; // D_RIGHT
5896 utils
.writeInt(st
, Byte(b
));
5898 utils
.writeInt(st
, LongInt(FHealth
));
5900 utils
.writeInt(st
, Byte(FLives
));
5902 utils
.writeInt(st
, LongInt(FArmor
));
5904 utils
.writeInt(st
, LongInt(FAir
));
5906 utils
.writeInt(st
, LongInt(FJetFuel
));
5908 utils
.writeInt(st
, LongInt(FPain
));
5910 utils
.writeInt(st
, LongInt(FKills
));
5912 utils
.writeInt(st
, LongInt(FMonsterKills
));
5914 utils
.writeInt(st
, LongInt(FFrags
));
5916 utils
.writeInt(st
, Byte(FFragCombo
));
5917 // Âðåìÿ ïîñëåäíåãî ôðàãà
5918 utils
.writeInt(st
, LongWord(FLastFrag
));
5920 utils
.writeInt(st
, LongInt(FDeath
));
5922 utils
.writeInt(st
, Byte(FFlag
));
5924 utils
.writeInt(st
, LongInt(FSecrets
));
5926 utils
.writeInt(st
, Byte(FCurrWeap
));
5928 utils
.writeInt(st
, Word(FNextWeap
));
5930 utils
.writeInt(st
, Byte(FNextWeapDelay
));
5931 // Âðåìÿ çàðÿäêè BFG
5932 utils
.writeInt(st
, SmallInt(FBFGFireCounter
));
5934 utils
.writeInt(st
, LongInt(FDamageBuffer
));
5935 // Ïîñëåäíèé óäàðèâøèé
5936 utils
.writeInt(st
, Word(FLastSpawnerUID
));
5937 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà
5938 utils
.writeInt(st
, Byte(FLastHit
));
5940 Obj_SaveState(st
, @FObj
);
5941 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ
5942 for i
:= A_BULLETS
to A_HIGH
do utils
.writeInt(st
, Word(FAmmo
[i
]));
5943 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ
5944 for i
:= A_BULLETS
to A_HIGH
do utils
.writeInt(st
, Word(FMaxAmmo
[i
]));
5946 for i
:= WP_FIRST
to WP_LAST
do utils
.writeBool(st
, FWeapon
[i
]);
5947 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ
5948 for i
:= WP_FIRST
to WP_LAST
do utils
.writeInt(st
, Word(FReloading
[i
]));
5950 utils
.writeBool(st
, (R_ITEM_BACKPACK
in FRulez
));
5951 // Íàëè÷èå êðàñíîãî êëþ÷à
5952 utils
.writeBool(st
, (R_KEY_RED
in FRulez
));
5953 // Íàëè÷èå çåëåíîãî êëþ÷à
5954 utils
.writeBool(st
, (R_KEY_GREEN
in FRulez
));
5955 // Íàëè÷èå ñèíåãî êëþ÷à
5956 utils
.writeBool(st
, (R_KEY_BLUE
in FRulez
));
5958 utils
.writeBool(st
, (R_BERSERK
in FRulez
));
5959 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ
5960 for i
:= MR_SUIT
to MR_MAX
do utils
.writeInt(st
, LongWord(FMegaRulez
[i
]));
5961 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà
5962 for i
:= T_RESPAWN
to T_FLAGCAP
do utils
.writeInt(st
, LongWord(FTime
[i
]));
5964 utils
.writeStr(st
, FModel
.Name
);
5966 utils
.writeInt(st
, Byte(FColor
.R
));
5967 utils
.writeInt(st
, Byte(FColor
.G
));
5968 utils
.writeInt(st
, Byte(FColor
.B
));
5972 procedure TPlayer
.LoadState (st
: TStream
);
5981 if not utils
.checkSign(st
, 'PLYR') then raise XStreamError
.Create('invalid player signature');
5982 if (utils
.readByte(st
) <> PLR_SAVE_VERSION
) then raise XStreamError
.Create('invalid player version');
5984 FIamBot
:= utils
.readBool(st
);
5986 FUID
:= utils
.readWord(st
);
5988 str
:= utils
.readStr(st
);
5989 if (self
<> gPlayer1
) and (self
<> gPlayer2
) then FName
:= str
;
5991 FTeam
:= utils
.readByte(st
);
5993 FAlive
:= utils
.readBool(st
);
5994 // Èçðàñõîäîâàë ëè âñå æèçíè
5995 FNoRespawn
:= utils
.readBool(st
);
5997 b
:= utils
.readByte(st
);
5998 if b
= 1 then FDirection
:= TDirection
.D_LEFT
else FDirection
:= TDirection
.D_RIGHT
; // b = 2
6000 FHealth
:= utils
.readLongInt(st
);
6002 FLives
:= utils
.readByte(st
);
6004 FArmor
:= utils
.readLongInt(st
);
6006 FAir
:= utils
.readLongInt(st
);
6008 FJetFuel
:= utils
.readLongInt(st
);
6010 FPain
:= utils
.readLongInt(st
);
6012 FKills
:= utils
.readLongInt(st
);
6014 FMonsterKills
:= utils
.readLongInt(st
);
6016 FFrags
:= utils
.readLongInt(st
);
6018 FFragCombo
:= utils
.readByte(st
);
6019 // Âðåìÿ ïîñëåäíåãî ôðàãà
6020 FLastFrag
:= utils
.readLongWord(st
);
6022 FDeath
:= utils
.readLongInt(st
);
6024 FFlag
:= utils
.readByte(st
);
6026 FSecrets
:= utils
.readLongInt(st
);
6028 FCurrWeap
:= utils
.readByte(st
);
6030 FNextWeap
:= utils
.readWord(st
);
6032 FNextWeapDelay
:= utils
.readByte(st
);
6033 // Âðåìÿ çàðÿäêè BFG
6034 FBFGFireCounter
:= utils
.readSmallInt(st
);
6036 FDamageBuffer
:= utils
.readLongInt(st
);
6037 // Ïîñëåäíèé óäàðèâøèé
6038 FLastSpawnerUID
:= utils
.readWord(st
);
6039 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà
6040 FLastHit
:= utils
.readByte(st
);
6042 Obj_LoadState(@FObj
, st
);
6043 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ
6044 for i
:= A_BULLETS
to A_HIGH
do FAmmo
[i
] := utils
.readWord(st
);
6045 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ
6046 for i
:= A_BULLETS
to A_HIGH
do FMaxAmmo
[i
] := utils
.readWord(st
);
6048 for i
:= WP_FIRST
to WP_LAST
do FWeapon
[i
] := utils
.readBool(st
);
6049 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ
6050 for i
:= WP_FIRST
to WP_LAST
do FReloading
[i
] := utils
.readWord(st
);
6052 if utils
.readBool(st
) then Include(FRulez
, R_ITEM_BACKPACK
);
6053 // Íàëè÷èå êðàñíîãî êëþ÷à
6054 if utils
.readBool(st
) then Include(FRulez
, R_KEY_RED
);
6055 // Íàëè÷èå çåëåíîãî êëþ÷à
6056 if utils
.readBool(st
) then Include(FRulez
, R_KEY_GREEN
);
6057 // Íàëè÷èå ñèíåãî êëþ÷à
6058 if utils
.readBool(st
) then Include(FRulez
, R_KEY_BLUE
);
6060 if utils
.readBool(st
) then Include(FRulez
, R_BERSERK
);
6061 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ
6062 for i
:= MR_SUIT
to MR_MAX
do FMegaRulez
[i
] := utils
.readLongWord(st
);
6063 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà
6064 for i
:= T_RESPAWN
to T_FLAGCAP
do FTime
[i
] := utils
.readLongWord(st
);
6066 str
:= utils
.readStr(st
);
6068 FColor
.R
:= utils
.readByte(st
);
6069 FColor
.G
:= utils
.readByte(st
);
6070 FColor
.B
:= utils
.readByte(st
);
6071 if (self
= gPlayer1
) then
6073 str
:= gPlayer1Settings
.Model
;
6074 FColor
:= gPlayer1Settings
.Color
;
6076 else if (self
= gPlayer2
) then
6078 str
:= gPlayer2Settings
.Model
;
6079 FColor
:= gPlayer2Settings
.Color
;
6081 // Îáíîâëÿåì ìîäåëü èãðîêà
6083 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
6084 FModel
.Color
:= TEAMCOLOR
[FTeam
]
6086 FModel
.Color
:= FColor
;
6090 procedure TPlayer
.AllRulez(Health
: Boolean);
6096 FHealth
:= PLAYER_HP_LIMIT
;
6097 FArmor
:= PLAYER_AP_LIMIT
;
6101 for a
:= WP_FIRST
to WP_LAST
do FWeapon
[a
] := True;
6102 for a
:= A_BULLETS
to A_HIGH
do FAmmo
[a
] := 30000;
6103 FRulez
:= FRulez
+[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
];
6106 procedure TPlayer
.RestoreHealthArmor();
6108 FHealth
:= PLAYER_HP_LIMIT
;
6109 FArmor
:= PLAYER_AP_LIMIT
;
6112 procedure TPlayer
.FragCombo();
6116 if (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) or g_Game_IsClient
then
6118 if gTime
- FLastFrag
< FRAG_COMBO_TIME
then
6120 if FFragCombo
< 5 then
6122 Param
:= FUID
or (FFragCombo
shl 16);
6123 if (FComboEvnt
>= Low(gDelayedEvents
)) and
6124 (FComboEvnt
<= High(gDelayedEvents
)) and
6125 gDelayedEvents
[FComboEvnt
].Pending
and
6126 (gDelayedEvents
[FComboEvnt
].DEType
= DE_KILLCOMBO
) and
6127 (gDelayedEvents
[FComboEvnt
].DENum
and $FFFF = FUID
) then
6129 gDelayedEvents
[FComboEvnt
].Time
:= gTime
+ 500;
6130 gDelayedEvents
[FComboEvnt
].DENum
:= Param
;
6133 FComboEvnt
:= g_Game_DelayEvent(DE_KILLCOMBO
, 500, Param
);
6141 procedure TPlayer
.GiveItem(ItemType
: Byte);
6145 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
6147 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
6151 if FAir
< AIR_MAX
then
6158 if not (R_BERSERK
in FRulez
) then
6160 Include(FRulez
, R_BERSERK
);
6161 if FBFGFireCounter
< 1 then
6163 FCurrWeap
:= WEAPON_KASTET
;
6165 FModel
.SetWeapon(WEAPON_KASTET
);
6169 FBerserk
:= gTime
+30000;
6171 if FHealth
< PLAYER_HP_SOFT
then
6173 FHealth
:= PLAYER_HP_SOFT
;
6174 FBerserk
:= gTime
+30000;
6179 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
6181 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
6185 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
6187 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
6191 if FJetFuel
< JET_MAX
then
6193 FJetFuel
:= JET_MAX
;
6196 ITEM_MEDKIT_SMALL
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
6197 ITEM_MEDKIT_LARGE
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
6199 ITEM_ARMOR_GREEN
: if FArmor
< PLAYER_AP_SOFT
then FArmor
:= PLAYER_AP_SOFT
;
6200 ITEM_ARMOR_BLUE
: if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
6202 ITEM_SPHERE_BLUE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
6204 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) then
6206 if FHealth
< PLAYER_HP_LIMIT
then FHealth
:= PLAYER_HP_LIMIT
;
6207 if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
6210 ITEM_WEAPON_SAW
: FWeapon
[WEAPON_SAW
] := True;
6211 ITEM_WEAPON_SHOTGUN1
: FWeapon
[WEAPON_SHOTGUN1
] := True;
6212 ITEM_WEAPON_SHOTGUN2
: FWeapon
[WEAPON_SHOTGUN2
] := True;
6213 ITEM_WEAPON_CHAINGUN
: FWeapon
[WEAPON_CHAINGUN
] := True;
6214 ITEM_WEAPON_ROCKETLAUNCHER
: FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
6215 ITEM_WEAPON_PLASMA
: FWeapon
[WEAPON_PLASMA
] := True;
6216 ITEM_WEAPON_BFG
: FWeapon
[WEAPON_BFG
] := True;
6217 ITEM_WEAPON_SUPERPULEMET
: FWeapon
[WEAPON_SUPERPULEMET
] := True;
6218 ITEM_WEAPON_FLAMETHROWER
: FWeapon
[WEAPON_FLAMETHROWER
] := True;
6220 ITEM_AMMO_BULLETS
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
6221 ITEM_AMMO_BULLETS_BOX
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
6222 ITEM_AMMO_SHELLS
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
6223 ITEM_AMMO_SHELLS_BOX
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
6224 ITEM_AMMO_ROCKET
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
6225 ITEM_AMMO_ROCKET_BOX
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
6226 ITEM_AMMO_CELL
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
6227 ITEM_AMMO_CELL_BIG
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
6228 ITEM_AMMO_FUELCAN
: if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
6231 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
6232 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
6233 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
6234 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or
6235 (FMaxAmmo
[A_FUEL
] < AmmoLimits
[1, A_FUEL
]) then
6237 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[1, A_BULLETS
];
6238 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[1, A_SHELLS
];
6239 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[1, A_ROCKETS
];
6240 FMaxAmmo
[A_CELLS
] := AmmoLimits
[1, A_CELLS
];
6241 FMaxAmmo
[A_FUEL
] := AmmoLimits
[1, A_FUEL
];
6243 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
6244 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
6245 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
6246 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
6248 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
6251 ITEM_KEY_RED
: if not (R_KEY_RED
in FRulez
) then Include(FRulez
, R_KEY_RED
);
6252 ITEM_KEY_GREEN
: if not (R_KEY_GREEN
in FRulez
) then Include(FRulez
, R_KEY_GREEN
);
6253 ITEM_KEY_BLUE
: if not (R_KEY_BLUE
in FRulez
) then Include(FRulez
, R_KEY_BLUE
);
6255 ITEM_BOTTLE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
6256 ITEM_HELMET
: if FArmor
< PLAYER_AP_LIMIT
then IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
6261 if g_Game_IsNet
and g_Game_IsServer
then
6262 MH_SEND_PlayerStats(FUID
);
6265 procedure TPlayer
.FlySmoke(Times
: DWORD
= 1);
6270 if (Random(5) = 1) and (Times
= 1) then
6273 if BodyInLiquid(0, 0) then
6275 g_GFX_Bubbles(Obj
.X
+Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2)+Random(3)-1,
6276 Obj
.Y
+Obj
.Rect
.Height
+8, 1, 8, 4);
6277 if Random(2) = 0 then
6278 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
6280 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
6284 if g_Frames_Get(id
, 'FRAMES_SMOKE') then
6286 for i
:= 1 to Times
do
6288 Anim
:= TAnimation
.Create(id
, False, 3);
6290 g_GFX_OnceAnim(Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(Anim
.Width
div 2),
6291 Obj
.Y
+Obj
.Rect
.Height
-4+Random(8+Times
*2), Anim
, ONCEANIM_SMOKE
);
6297 procedure TPlayer
.OnFireFlame(Times
: DWORD
= 1);
6302 if (Random(10) = 1) and (Times
= 1) then
6305 if g_Frames_Get(id
, 'FRAMES_FLAME') then
6307 for i
:= 1 to Times
do
6309 Anim
:= TAnimation
.Create(id
, False, 3);
6311 g_GFX_OnceAnim(Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(Anim
.Width
div 2),
6312 Obj
.Y
+8+Random(8+Times
*2), Anim
, ONCEANIM_SMOKE
);
6318 procedure TPlayer
.PauseSounds(Enable
: Boolean);
6320 FSawSound
.Pause(Enable
);
6321 FSawSoundIdle
.Pause(Enable
);
6322 FSawSoundHit
.Pause(Enable
);
6323 FSawSoundSelect
.Pause(Enable
);
6324 FFlameSoundOn
.Pause(Enable
);
6325 FFlameSoundOff
.Pause(Enable
);
6326 FFlameSoundWork
.Pause(Enable
);
6327 FJetSoundFly
.Pause(Enable
);
6328 FJetSoundOn
.Pause(Enable
);
6329 FJetSoundOff
.Pause(Enable
);
6334 constructor TCorpse
.Create(X
, Y
: Integer; ModelName
: String; aMess
: Boolean);
6339 FObj
.Rect
:= PLAYER_CORPSERECT
;
6340 FModelName
:= ModelName
;
6345 FState
:= CORPSE_STATE_MESS
;
6346 g_PlayerModel_GetAnim(ModelName
, A_DIE2
, FAnimation
, FAnimationMask
);
6350 FState
:= CORPSE_STATE_NORMAL
;
6351 g_PlayerModel_GetAnim(ModelName
, A_DIE1
, FAnimation
, FAnimationMask
);
6355 destructor TCorpse
.Destroy();
6362 function TCorpse
.ObjPtr (): PObj
; inline; begin result
:= @FObj
; end;
6364 procedure TCorpse
.positionChanged (); inline; begin end;
6366 procedure TCorpse
.moveBy (dx
, dy
: Integer); inline;
6368 if (dx
<> 0) or (dy
<> 0) then
6377 procedure TCorpse
.getMapBox (out x
, y
, w
, h
: Integer); inline;
6379 x
:= FObj
.X
+PLAYER_CORPSERECT
.X
;
6380 y
:= FObj
.Y
+PLAYER_CORPSERECT
.Y
;
6381 w
:= PLAYER_CORPSERECT
.Width
;
6382 h
:= PLAYER_CORPSERECT
.Height
;
6386 procedure TCorpse
.Damage(Value
: Word; vx
, vy
: Integer);
6391 if FState
= CORPSE_STATE_REMOVEME
then
6394 FDamage
:= FDamage
+ Value
;
6396 if FDamage
> 150 then
6398 if FAnimation
<> nil then
6403 FState
:= CORPSE_STATE_REMOVEME
;
6405 g_Player_CreateGibs(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
6406 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2),
6407 FModelName
, FColor
);
6408 // Çâóê ìÿñà îò òðóïà:
6409 pm
:= g_PlayerModel_Get(FModelName
);
6410 pm
.PlaySound(MODELSOUND_DIE
, 5, FObj
.X
, FObj
.Y
);
6414 if (gBodyKillEvent
<> -1)
6415 and gDelayedEvents
[gBodyKillEvent
].Pending
then
6416 gDelayedEvents
[gBodyKillEvent
].Pending
:= False;
6417 gBodyKillEvent
:= g_Game_DelayEvent(DE_BODYKILL
, 1050, 0);
6422 Blood
:= g_PlayerModel_GetBlood(FModelName
);
6423 FObj
.Vel
.X
:= FObj
.Vel
.X
+ vx
;
6424 FObj
.Vel
.Y
:= FObj
.Vel
.Y
+ vy
;
6425 g_GFX_Blood(FObj
.X
+PLAYER_CORPSERECT
.X
+(PLAYER_CORPSERECT
.Width
div 2),
6426 FObj
.Y
+PLAYER_CORPSERECT
.Y
+(PLAYER_CORPSERECT
.Height
div 2),
6427 Value
, vx
, vy
, 16, (PLAYER_CORPSERECT
.Height
*2) div 3,
6428 Blood
.R
, Blood
.G
, Blood
.B
, Blood
.Kind
);
6432 procedure TCorpse
.Draw();
6434 if FState
= CORPSE_STATE_REMOVEME
then
6437 if FAnimation
<> nil then
6438 FAnimation
.Draw(FObj
.X
, FObj
.Y
, TMirrorType
.None
);
6440 if FAnimationMask
<> nil then
6443 FAnimationMask
.Draw(FObj
.X
, FObj
.Y
, TMirrorType
.None
);
6450 procedure TCorpse
.Update();
6454 if FState
= CORPSE_STATE_REMOVEME
then
6457 if gTime
mod (GAME_TICK
*2) <> 0 then
6459 g_Obj_Move(@FObj
, True, True, True);
6460 positionChanged(); // this updates spatial accelerators
6464 // Ñîïðîòèâëåíèå âîçäóõà äëÿ òðóïà:
6465 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
6467 st
:= g_Obj_Move(@FObj
, True, True, True);
6468 positionChanged(); // this updates spatial accelerators
6470 if WordBool(st
and MOVE_FALLOUT
) then
6472 FState
:= CORPSE_STATE_REMOVEME
;
6476 if FAnimation
<> nil then
6477 FAnimation
.Update();
6478 if FAnimationMask
<> nil then
6479 FAnimationMask
.Update();
6483 procedure TCorpse
.SaveState (st
: TStream
);
6490 utils
.writeSign(st
, 'CORP');
6491 utils
.writeInt(st
, Byte(0));
6493 utils
.writeInt(st
, Byte(FState
));
6495 utils
.writeInt(st
, Byte(FDamage
));
6497 utils
.writeInt(st
, Byte(FColor
.R
));
6498 utils
.writeInt(st
, Byte(FColor
.G
));
6499 utils
.writeInt(st
, Byte(FColor
.B
));
6501 Obj_SaveState(st
, @FObj
);
6502 utils
.writeInt(st
, Word(FPlayerUID
));
6504 anim
:= (FAnimation
<> nil);
6505 utils
.writeBool(st
, anim
);
6506 // Åñëè åñòü - ñîõðàíÿåì
6507 if anim
then FAnimation
.SaveState(st
);
6508 // Åñòü ëè ìàñêà àíèìàöèè
6509 anim
:= (FAnimationMask
<> nil);
6510 utils
.writeBool(st
, anim
);
6511 // Åñëè åñòü - ñîõðàíÿåì
6512 if anim
then FAnimationMask
.SaveState(st
);
6516 procedure TCorpse
.LoadState (st
: TStream
);
6523 if not utils
.checkSign(st
, 'CORP') then raise XStreamError
.Create('invalid corpse signature');
6524 if (utils
.readByte(st
) <> 0) then raise XStreamError
.Create('invalid corpse version');
6526 FState
:= utils
.readByte(st
);
6528 FDamage
:= utils
.readByte(st
);
6530 FColor
.R
:= utils
.readByte(st
);
6531 FColor
.G
:= utils
.readByte(st
);
6532 FColor
.B
:= utils
.readByte(st
);
6534 Obj_LoadState(@FObj
, st
);
6535 FPlayerUID
:= utils
.readWord(st
);
6537 anim
:= utils
.readBool(st
);
6538 // Åñëè åñòü - çàãðóæàåì
6541 Assert(FAnimation
<> nil, 'TCorpse.LoadState: no FAnimation');
6542 FAnimation
.LoadState(st
);
6544 // Åñòü ëè ìàñêà àíèìàöèè
6545 anim
:= utils
.readBool(st
);
6546 // Åñëè åñòü - çàãðóæàåì
6549 Assert(FAnimationMask
<> nil, 'TCorpse.LoadState: no FAnimationMask');
6550 FAnimationMask
.LoadState(st
);
6556 constructor TBot
.Create();
6563 FSpectator
:= False;
6570 for a
:= WP_FIRST
to WP_LAST
do
6572 FDifficult
.WeaponPrior
[a
] := WEAPON_PRIOR1
[a
];
6573 FDifficult
.CloseWeaponPrior
[a
] := WEAPON_PRIOR2
[a
];
6574 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
6578 destructor TBot
.Destroy();
6581 inherited Destroy();
6584 procedure TBot
.Draw();
6588 //if FTargetUID <> 0 then e_DrawLine(1, FObj.X, FObj.Y, g_Player_Get(FTargetUID).FObj.X,
6589 // g_Player_Get(FTargetUID).FObj.Y, 255, 0, 0);
6592 procedure TBot
.Respawn(Silent
: Boolean; Force
: Boolean = False);
6594 inherited Respawn(Silent
, Force
);
6597 FSelectedWeapon
:= FCurrWeap
;
6602 procedure TBot
.UpdateCombat();
6615 TTargetRecord
= array of TTarget
;
6617 function Compare(a
, b
: TTarget
): Integer;
6619 if a
.Line
and not b
.Line
then // A íà ëèíèè îãíÿ
6622 if not a
.Line
and b
.Line
then // B íà ëèíèè îãíÿ
6624 else // È A, è B íà ëèíèè èëè íå íà ëèíèè îãíÿ
6625 if (a
.Line
and b
.Line
) or ((not a
.Line
) and (not b
.Line
)) then
6627 if a
.Dist
> b
.Dist
then // B áëèæå
6629 else // A áëèæå èëè ðàâíîóäàëåííî ñ B
6632 else // Ñòðàííî -> A
6637 a
, x1
, y1
, x2
, y2
: Integer;
6638 targets
: TTargetRecord
;
6640 Target
, BestTarget
: TTarget
;
6641 firew
, fireh
: Integer;
6645 vsPlayer
, vsMonster
, ok
: Boolean;
6648 function monsUpdate (mon
: TMonster
): Boolean;
6650 result
:= false; // don't stop
6651 if mon
.alive
and (mon
.MonsterType
<> MONSTER_BARREL
) then
6653 if not TargetOnScreen(mon
.Obj
.X
+mon
.Obj
.Rect
.X
, mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
) then exit
;
6655 x2
:= mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2);
6656 y2
:= mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+(mon
.Obj
.Rect
.Height
div 2);
6658 // Åñëè ìîíñòð íà ýêðàíå è íå ïðèêðûò ñòåíîé
6659 if g_TraceVector(x1
, y1
, x2
, y2
) then
6661 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé
6662 SetLength(targets
, Length(targets
)+1);
6663 with targets
[High(targets
)] do
6670 Rect
:= mon
.Obj
.Rect
;
6671 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6672 Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6673 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6682 vsPlayer
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
);
6683 vsMonster
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
);
6685 // Åñëè òåêóùåå îðóæèå íå òî, ÷òî íóæíî, òî ìåíÿåì:
6686 if FCurrWeap
<> FSelectedWeapon
then
6689 // Åñëè íóæíî ñòðåëÿòü è íóæíîå îðóæèå, òî íàæàòü "Ñòðåëÿòü":
6690 if (GetAIFlag('NEEDFIRE') <> '') and (FCurrWeap
= FSelectedWeapon
) then
6692 RemoveAIFlag('NEEDFIRE');
6695 WEAPON_PLASMA
, WEAPON_SUPERPULEMET
, WEAPON_CHAINGUN
: PressKey(KEY_FIRE
, 20);
6696 WEAPON_SAW
, WEAPON_KASTET
, WEAPON_FLAMETHROWER
: PressKey(KEY_FIRE
, 40);
6697 else PressKey(KEY_FIRE
);
6701 // Êîîðäèíàòû ñòâîëà:
6702 x1
:= FObj
.X
+ WEAPONPOINT
[FDirection
].X
;
6703 y1
:= FObj
.Y
+ WEAPONPOINT
[FDirection
].Y
;
6705 Target
.UID
:= FTargetUID
;
6708 if Target
.UID
<> 0 then
6709 begin // Öåëü åñòü - íàñòðàèâàåì
6710 if (g_GetUIDType(Target
.UID
) = UID_PLAYER
) and
6713 tpla
:= g_Player_Get(Target
.UID
);
6717 if (@FObj
) <> nil then
6724 Target
.cX
:= Target
.X
+ PLAYER_RECT_CX
;
6725 Target
.cY
:= Target
.Y
+ PLAYER_RECT_CY
;
6726 Target
.Rect
:= PLAYER_RECT
;
6727 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6728 Target
.Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6729 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6730 Target
.IsPlayer
:= True;
6734 if (g_GetUIDType(Target
.UID
) = UID_MONSTER
) and
6737 mon
:= g_Monsters_ByUID(Target
.UID
);
6740 Target
.X
:= mon
.Obj
.X
;
6741 Target
.Y
:= mon
.Obj
.Y
;
6743 Target
.cX
:= Target
.X
+ mon
.Obj
.Rect
.X
+ (mon
.Obj
.Rect
.Width
div 2);
6744 Target
.cY
:= Target
.Y
+ mon
.Obj
.Rect
.Y
+ (mon
.Obj
.Rect
.Height
div 2);
6745 Target
.Rect
:= mon
.Obj
.Rect
;
6746 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6747 Target
.Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6748 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6749 Target
.IsPlayer
:= False;
6756 begin // Öåëè íåò - îáíóëÿåì
6761 Target
.Visible
:= False;
6762 Target
.Line
:= False;
6763 Target
.IsPlayer
:= False;
6768 // Åñëè öåëü íå âèäèìà èëè íå íà ëèíèè îãíÿ, òî èùåì âñå âîçìîæíûå öåëè:
6769 if (not Target
.Line
) or (not Target
.Visible
) then
6773 for a
:= 0 to High(gPlayers
) do
6774 if (gPlayers
[a
] <> nil) and (gPlayers
[a
].alive
) and
6775 (gPlayers
[a
].FUID
<> FUID
) and
6776 (not SameTeam(FUID
, gPlayers
[a
].FUID
)) and
6777 (not gPlayers
[a
].NoTarget
) and
6778 (gPlayers
[a
].FMegaRulez
[MR_INVIS
] < gTime
) then
6780 if not TargetOnScreen(gPlayers
[a
].FObj
.X
+ PLAYER_RECT
.X
,
6781 gPlayers
[a
].FObj
.Y
+ PLAYER_RECT
.Y
) then
6784 x2
:= gPlayers
[a
].FObj
.X
+ PLAYER_RECT_CX
;
6785 y2
:= gPlayers
[a
].FObj
.Y
+ PLAYER_RECT_CY
;
6787 // Åñëè èãðîê íà ýêðàíå è íå ïðèêðûò ñòåíîé:
6788 if g_TraceVector(x1
, y1
, x2
, y2
) then
6790 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé:
6791 SetLength(targets
, Length(targets
)+1);
6792 with targets
[High(targets
)] do
6794 UID
:= gPlayers
[a
].FUID
;
6795 X
:= gPlayers
[a
].FObj
.X
;
6796 Y
:= gPlayers
[a
].FObj
.Y
;
6799 Rect
:= PLAYER_RECT
;
6800 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6801 Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6802 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6810 if vsMonster
then g_Mons_ForEach(monsUpdate
);
6813 // Åñëè åñòü âîçìîæíûå öåëè:
6814 // (Âûáèðàåì ëó÷øóþ, ìåíÿåì îðóæèå è áåæèì ê íåé/îò íåå)
6815 if targets
<> nil then
6817 // Âûáèðàåì íàèëó÷øóþ öåëü:
6818 BestTarget
:= targets
[0];
6819 if Length(targets
) > 1 then
6820 for a
:= 1 to High(targets
) do
6821 if Compare(BestTarget
, targets
[a
]) = 1 then
6822 BestTarget
:= targets
[a
];
6824 // Åñëè ëó÷øàÿ öåëü "âèäíåå" òåêóùåé, òî òåêóùàÿ := ëó÷øàÿ:
6825 if ((not Target
.Visible
) and BestTarget
.Visible
and (Target
.UID
<> BestTarget
.UID
)) or
6826 ((not Target
.Line
) and BestTarget
.Line
and BestTarget
.Visible
) then
6828 Target
:= BestTarget
;
6830 if (Healthy() = 3) or ((Healthy() = 2)) then
6831 begin // Åñëè çäîðîâû - äîãîíÿåì
6832 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
6833 SetAIFlag('GORIGHT', '1');
6834 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6835 SetAIFlag('GOLEFT', '1');
6838 begin // Åñëè ïîáèòû - óáåãàåì
6839 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) then
6840 SetAIFlag('GORIGHT', '1');
6841 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6842 SetAIFlag('GOLEFT', '1');
6845 // Âûáèðàåì îðóæèå íà îñíîâå ðàññòîÿíèÿ è ïðèîðèòåòîâ:
6846 SelectWeapon(Abs(x1
-Target
.cX
));
6851 // (Äîãîíÿåì/óáåãàåì, ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëè)
6852 // (Åñëè öåëü äàëåêî, òî õâàòèò ñëåäèòü çà íåé)
6853 if Target
.UID
<> 0 then
6855 if not TargetOnScreen(Target
.X
+ Target
.Rect
.X
,
6856 Target
.Y
+ Target
.Rect
.Y
) then
6857 begin // Öåëü ñáåæàëà ñ "ýêðàíà"
6858 if (Healthy() = 3) or ((Healthy() = 2)) then
6859 begin // Åñëè çäîðîâû - äîãîíÿåì
6860 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
6861 SetAIFlag('GORIGHT', '1');
6862 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6863 SetAIFlag('GOLEFT', '1');
6866 begin // Åñëè ïîáèòû - çàáûâàåì î öåëè è óáåãàåì
6868 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) then
6869 SetAIFlag('GORIGHT', '1');
6870 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6871 SetAIFlag('GOLEFT', '1');
6875 begin // Öåëü ïîêà íà "ýêðàíå"
6876 // Åñëè öåëü íå çàãîðîæåíà ñòåíîé, òî îòìå÷àåì, êîãäà åå âèäåëè:
6877 if g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6878 FLastVisible
:= gTime
;
6879 // Åñëè ðàçíèöà âûñîò íå âåëèêà, òî äîãîíÿåì:
6880 if (Abs(FObj
.Y
-Target
.Y
) <= 128) then
6882 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
6883 SetAIFlag('GORIGHT', '1');
6884 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6885 SetAIFlag('GOLEFT', '1');
6889 // Âûáèðàåì óãîë ââåðõ:
6890 if FDirection
= TDirection
.D_LEFT
then
6891 angle
:= ANGLE_LEFTUP
6893 angle
:= ANGLE_RIGHTUP
;
6895 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6896 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6898 // Åñëè ïðè óãëå ââåðõ ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
6899 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6900 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128), //96
6901 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6902 Target
.Rect
.Width
, Target
.Rect
.Height
) and
6903 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6904 begin // òî íóæíî ñòðåëÿòü ââåðõ
6905 SetAIFlag('NEEDFIRE', '1');
6906 SetAIFlag('NEEDSEEUP', '1');
6909 // Âûáèðàåì óãîë âíèç:
6910 if FDirection
= TDirection
.D_LEFT
then
6911 angle
:= ANGLE_LEFTDOWN
6913 angle
:= ANGLE_RIGHTDOWN
;
6915 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6916 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6918 // Åñëè ïðè óãëå âíèç ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
6919 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6920 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
6921 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6922 Target
.Rect
.Width
, Target
.Rect
.Height
) and
6923 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6924 begin // òî íóæíî ñòðåëÿòü âíèç
6925 SetAIFlag('NEEDFIRE', '1');
6926 SetAIFlag('NEEDSEEDOWN', '1');
6929 // Åñëè öåëü âèäíî è îíà íà òàêîé æå âûñîòå:
6930 if Target
.Visible
and
6931 (y1
+4 < Target
.Y
+Target
.Rect
.Y
+Target
.Rect
.Height
) and
6932 (y1
-4 > Target
.Y
+Target
.Rect
.Y
) then
6934 // Åñëè èäåì â ñòîðîíó öåëè, òî íàäî ñòðåëÿòü:
6935 if ((FDirection
= TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) or
6936 ((FDirection
= TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6937 begin // òî íóæíî ñòðåëÿòü âïåðåä
6938 SetAIFlag('NEEDFIRE', '1');
6939 SetAIFlag('NEEDSEEDOWN', '');
6940 SetAIFlag('NEEDSEEUP', '');
6942 // Åñëè öåëü â ïðåäåëàõ "ýêðàíà" è ñëîæíîñòü ïîçâîëÿåò ïðûæêè ñáëèæåíèÿ:
6943 if Abs(FObj
.X
-Target
.X
) < Trunc(gPlayerScreenSize
.X
*0.75) then
6944 if GetRnd(FDifficult
.CloseJump
) then
6945 begin // òî åñëè ïîâåçåò - ïðûãàåì (îñîáåííî, åñëè áëèçêî)
6946 if Abs(FObj
.X
-Target
.X
) < 128 then
6950 if Random(a
) = 0 then
6951 SetAIFlag('NEEDJUMP', '1');
6955 // Åñëè öåëü âñå åùå åñòü:
6956 if Target
.UID
<> 0 then
6957 if gTime
-FLastVisible
> 2000 then // Åñëè âèäåëè äàâíî
6958 Target
.UID
:= 0 // òî çàáûòü öåëü
6959 else // Åñëè âèäåëè íåäàâíî
6960 begin // íî öåëü óáèëè
6961 if Target
.IsPlayer
then
6962 begin // Öåëü - èãðîê
6963 pla
:= g_Player_Get(Target
.UID
);
6964 if (pla
= nil) or (not pla
.alive
) or pla
.NoTarget
or
6965 (pla
.FMegaRulez
[MR_INVIS
] >= gTime
) then
6966 Target
.UID
:= 0; // òî çàáûòü öåëü
6969 begin // Öåëü - ìîíñòð
6970 mon
:= g_Monsters_ByUID(Target
.UID
);
6971 if (mon
= nil) or (not mon
.alive
) then
6972 Target
.UID
:= 0; // òî çàáûòü öåëü
6975 end; // if Target.UID <> 0
6977 FTargetUID
:= Target
.UID
;
6979 // Åñëè âîçìîæíûõ öåëåé íåò:
6980 // (Àòàêà ÷åãî-íèáóäü ñëåâà èëè ñïðàâà)
6981 if targets
= nil then
6982 if GetAIFlag('ATTACKLEFT') <> '' then
6983 begin // Åñëè íóæíî àòàêîâàòü íàëåâî
6984 RemoveAIFlag('ATTACKLEFT');
6986 SetAIFlag('NEEDJUMP', '1');
6988 if RunDirection() = TDirection
.D_RIGHT
then
6989 begin // Èäåì íå â òó ñòîðîíó
6990 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
6991 begin // Åñëè çäîðîâû, òî, âîçìîæíî, ñòðåëÿåì áåæèì âëåâî è ñòðåëÿåì
6992 SetAIFlag('NEEDFIRE', '1');
6993 SetAIFlag('GOLEFT', '1');
6997 begin // Èäåì â íóæíóþ ñòîðîíó
6998 if GetRnd(FDifficult
.InvisFire
) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
6999 SetAIFlag('NEEDFIRE', '1');
7000 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
7001 SetAIFlag('GORIGHT', '1');
7005 if GetAIFlag('ATTACKRIGHT') <> '' then
7006 begin // Åñëè íóæíî àòàêîâàòü íàïðàâî
7007 RemoveAIFlag('ATTACKRIGHT');
7009 SetAIFlag('NEEDJUMP', '1');
7011 if RunDirection() = TDirection
.D_LEFT
then
7012 begin // Èäåì íå â òó ñòîðîíó
7013 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
7014 begin // Åñëè çäîðîâû, òî, âîçìîæíî, áåæèì âïðàâî è ñòðåëÿåì
7015 SetAIFlag('NEEDFIRE', '1');
7016 SetAIFlag('GORIGHT', '1');
7021 if GetRnd(FDifficult
.InvisFire
) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
7022 SetAIFlag('NEEDFIRE', '1');
7023 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
7024 SetAIFlag('GOLEFT', '1');
7028 //HACK! (does it belongs there?)
7029 RealizeCurrentWeapon();
7031 // Åñëè åñòü âîçìîæíûå öåëè:
7032 // (Ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëÿì)
7033 if (targets
<> nil) and (GetAIFlag('NEEDFIRE') <> '') then
7034 for a
:= 0 to High(targets
) do
7036 // Åñëè ìîæåì ñòðåëÿòü ïî äèàãîíàëè:
7037 if GetRnd(FDifficult
.DiagFire
) then
7039 // Èùåì öåëü ñâåðõó è ñòðåëÿåì, åñëè åñòü:
7040 if FDirection
= TDirection
.D_LEFT
then
7041 angle
:= ANGLE_LEFTUP
7043 angle
:= ANGLE_RIGHTUP
;
7045 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7046 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7048 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
7049 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
7050 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
7051 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
7052 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
7054 SetAIFlag('NEEDFIRE', '1');
7055 SetAIFlag('NEEDSEEUP', '1');
7058 // Èùåì öåëü ñíèçó è ñòðåëÿåì, åñëè åñòü:
7059 if FDirection
= TDirection
.D_LEFT
then
7060 angle
:= ANGLE_LEFTDOWN
7062 angle
:= ANGLE_RIGHTDOWN
;
7064 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7065 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7067 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
7068 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
7069 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
7070 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
7071 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
7073 SetAIFlag('NEEDFIRE', '1');
7074 SetAIFlag('NEEDSEEDOWN', '1');
7078 // Åñëè öåëü "ïåðåä íîñîì", òî ñòðåëÿåì:
7079 if targets
[a
].Line
and targets
[a
].Visible
and
7080 (((FDirection
= TDirection
.D_LEFT
) and (targets
[a
].X
< FObj
.X
)) or
7081 ((FDirection
= TDirection
.D_RIGHT
) and (targets
[a
].X
> FObj
.X
))) then
7083 SetAIFlag('NEEDFIRE', '1');
7088 // Åñëè ëåòèò ïóëÿ, òî, âîçìîæíî, ïîäïðûãèâàåì:
7089 if g_Weapon_Danger(FUID
, FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
,
7090 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
,
7091 40+GetInterval(FDifficult
.Cover
, 40)) then
7092 SetAIFlag('NEEDJUMP', '1');
7094 // Åñëè êîí÷èëèñü ïàòîðíû, òî íóæíî ñìåíèòü îðóæèå:
7095 ammo
:= GetAmmoByWeapon(FCurrWeap
);
7096 if ((FCurrWeap
= WEAPON_SHOTGUN2
) and (ammo
< 2)) or
7097 ((FCurrWeap
= WEAPON_BFG
) and (ammo
< 40)) or
7099 SetAIFlag('SELECTWEAPON', '1');
7101 // Åñëè íóæíî ñìåíèòü îðóæèå, òî âûáèðàåì íóæíîå:
7102 if GetAIFlag('SELECTWEAPON') = '1' then
7105 RemoveAIFlag('SELECTWEAPON');
7109 procedure TBot
.Update();
7122 // Ïðîâåðÿåì, îòêëþ÷¸í ëè AI áîòîâ
7123 if (g_debug_BotAIOff
= 1) and (Team
= TEAM_RED
) then
7125 if (g_debug_BotAIOff
= 2) and (Team
= TEAM_BLUE
) then
7127 if g_debug_BotAIOff
= 3 then
7137 RealizeCurrentWeapon();
7144 procedure TBot
.ReleaseKey(Key
: Byte);
7153 function TBot
.KeyPressed(Key
: Word): Boolean;
7155 Result
:= FKeys
[Key
].Pressed
;
7158 function TBot
.GetAIFlag(aName
: String20
): String20
;
7164 aName
:= LowerCase(aName
);
7166 if FAIFlags
<> nil then
7167 for a
:= 0 to High(FAIFlags
) do
7168 if LowerCase(FAIFlags
[a
].Name
) = aName
then
7170 Result
:= FAIFlags
[a
].Value
;
7175 procedure TBot
.RemoveAIFlag(aName
: String20
);
7179 if FAIFlags
= nil then Exit
;
7181 aName
:= LowerCase(aName
);
7183 for a
:= 0 to High(FAIFlags
) do
7184 if LowerCase(FAIFlags
[a
].Name
) = aName
then
7186 if a
<> High(FAIFlags
) then
7187 for b
:= a
to High(FAIFlags
)-1 do
7188 FAIFlags
[b
] := FAIFlags
[b
+1];
7190 SetLength(FAIFlags
, Length(FAIFlags
)-1);
7195 procedure TBot
.SetAIFlag(aName
, fValue
: String20
);
7203 aName
:= LowerCase(aName
);
7205 if FAIFlags
<> nil then
7206 for a
:= 0 to High(FAIFlags
) do
7207 if LowerCase(FAIFlags
[a
].Name
) = aName
then
7213 if ok
then FAIFlags
[a
].Value
:= fValue
7216 SetLength(FAIFlags
, Length(FAIFlags
)+1);
7217 with FAIFlags
[High(FAIFlags
)] do
7225 procedure TBot
.UpdateMove
;
7227 procedure GoLeft(Time
: Word = 1);
7229 ReleaseKey(KEY_LEFT
);
7230 ReleaseKey(KEY_RIGHT
);
7231 PressKey(KEY_LEFT
, Time
);
7232 SetDirection(TDirection
.D_LEFT
);
7235 procedure GoRight(Time
: Word = 1);
7237 ReleaseKey(KEY_LEFT
);
7238 ReleaseKey(KEY_RIGHT
);
7239 PressKey(KEY_RIGHT
, Time
);
7240 SetDirection(TDirection
.D_RIGHT
);
7243 function Rnd(a
: Word): Boolean;
7245 Result
:= Random(a
) = 0;
7248 procedure Turn(Time
: Word = 1200);
7250 if RunDirection() = TDirection
.D_LEFT
then GoRight(Time
) else GoLeft(Time
);
7255 ReleaseKey(KEY_LEFT
);
7256 ReleaseKey(KEY_RIGHT
);
7259 function CanRunLeft(): Boolean;
7261 Result
:= not CollideLevel(-1, 0);
7264 function CanRunRight(): Boolean;
7266 Result
:= not CollideLevel(1, 0);
7269 function CanRun(): Boolean;
7271 if RunDirection() = TDirection
.D_LEFT
then Result
:= CanRunLeft() else Result
:= CanRunRight();
7274 procedure Jump(Time
: Word = 30);
7276 PressKey(KEY_JUMP
, Time
);
7279 function NearHole(): Boolean;
7283 { TODO 5 : Ëåñòíèöû }
7284 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7285 for x
:= 1 to PLAYER_RECT
.Width
do
7286 if (not StayOnStep(x
*sx
, 0)) and
7287 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7288 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7297 function BorderHole(): Boolean;
7301 { TODO 5 : Ëåñòíèöû }
7302 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7303 for x
:= 1 to PLAYER_RECT
.Width
do
7304 if (not StayOnStep(x
*sx
, 0)) and
7305 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7306 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7308 for xx
:= x
to x
+32 do
7309 if CollideLevel(xx
*sx
, PLAYER_RECT
.Height
) then
7319 function NearDeepHole(): Boolean;
7325 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7328 for x
:= 1 to PLAYER_RECT
.Width
do
7329 if (not StayOnStep(x
*sx
, 0)) and
7330 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7331 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7333 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
7335 if CollideLevel(x
*sx
, PLAYER_RECT
.Height
*y
) then Exit
;
7340 end else Result
:= False;
7343 function OverDeepHole(): Boolean;
7350 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
7352 if CollideLevel(0, PLAYER_RECT
.Height
*y
) then Exit
;
7359 function OnGround(): Boolean;
7361 Result
:= StayOnStep(0, 0) or CollideLevel(0, 1);
7364 function OnLadder(): Boolean;
7366 Result
:= FullInStep(0, 0);
7369 function BelowLadder(): Boolean;
7371 Result
:= (FullInStep(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) and
7372 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
7373 (FullInStep(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) and
7374 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
7377 function BelowLiftUp(): Boolean;
7379 Result
:= ((FullInLift(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) = -1) and
7380 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
7381 ((FullInLift(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) = -1) and
7382 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
7385 function OnTopLift(): Boolean;
7387 Result
:= (FullInLift(0, 0) = -1) and (FullInLift(0, -32) = 0);
7390 function CanJumpOver(): Boolean;
7394 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7398 if not CollideLevel(sx
, 0) then Exit
;
7400 for y
:= 1 to BOT_MAXJUMP
do
7401 if CollideLevel(0, -y
) then Exit
else
7402 if not CollideLevel(sx
, -y
) then
7409 function CanJumpUp(Dist
: ShortInt): Boolean;
7416 if CollideLevel(Dist
, 0) then Exit
;
7419 for y
:= 0 to BOT_MAXJUMP
do
7420 if CollideLevel(Dist
, -y
) then
7429 for yy
:= y
+1 to BOT_MAXJUMP
do
7430 if not CollideLevel(Dist
, -yy
) then
7439 for y
:= 0 to BOT_MAXJUMP
do
7440 if CollideLevel(0, -y
) then
7448 if y
< yy
then Exit
;
7453 function IsSafeTrigger(): Boolean;
7458 if gTriggers
= nil then
7460 for a
:= 0 to High(gTriggers
) do
7461 if Collide(gTriggers
[a
].X
,
7464 gTriggers
[a
].Height
) and
7465 (gTriggers
[a
].TriggerType
in [TRIGGER_EXIT
, TRIGGER_CLOSEDOOR
,
7466 TRIGGER_CLOSETRAP
, TRIGGER_TRAP
,
7467 TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
,
7468 TRIGGER_ONOFF
, TRIGGER_SPAWNMONSTER
,
7469 TRIGGER_DAMAGE
, TRIGGER_SHOT
]) then
7474 // Âîçìîæíî, íàæèìàåì êíîïêó:
7475 if Rnd(16) and IsSafeTrigger() then
7478 // Åñëè ïîä ëèôòîì èëè ñòóïåíüêàìè, òî, âîçìîæíî, ïðûãàåì:
7479 if OnLadder() or ((BelowLadder() or BelowLiftUp()) and Rnd(8)) then
7481 ReleaseKey(KEY_LEFT
);
7482 ReleaseKey(KEY_RIGHT
);
7486 // Èäåì âëåâî, åñëè íàäî áûëî:
7487 if GetAIFlag('GOLEFT') <> '' then
7489 RemoveAIFlag('GOLEFT');
7490 if CanRunLeft() then
7494 // Èäåì âïðàâî, åñëè íàäî áûëî:
7495 if GetAIFlag('GORIGHT') <> '' then
7497 RemoveAIFlag('GORIGHT');
7498 if CanRunRight() then
7502 // Åñëè âûëåòåëè çà êàðòó, òî ïðîáóåì âåðíóòüñÿ:
7503 if FObj
.X
< -32 then
7506 if FObj
.X
+32 > gMapInfo
.Width
then
7509 // Ïðûãàåì, åñëè íàäî áûëî:
7510 if GetAIFlag('NEEDJUMP') <> '' then
7513 RemoveAIFlag('NEEDJUMP');
7516 // Ñìîòðèì ââåðõ, åñëè íàäî áûëî:
7517 if GetAIFlag('NEEDSEEUP') <> '' then
7520 ReleaseKey(KEY_DOWN
);
7521 PressKey(KEY_UP
, 20);
7522 RemoveAIFlag('NEEDSEEUP');
7525 // Ñìîòðèì âíèç, åñëè íàäî áûëî:
7526 if GetAIFlag('NEEDSEEDOWN') <> '' then
7529 ReleaseKey(KEY_DOWN
);
7530 PressKey(KEY_DOWN
, 20);
7531 RemoveAIFlag('NEEDSEEDOWN');
7534 // Åñëè íóæíî áûëî â äûðó è ìû íå íà çåìëå, òî ïîêîðíî ëåòèì:
7535 if GetAIFlag('GOINHOLE') <> '' then
7536 if not OnGround() then
7538 ReleaseKey(KEY_LEFT
);
7539 ReleaseKey(KEY_RIGHT
);
7540 RemoveAIFlag('GOINHOLE');
7541 SetAIFlag('FALLINHOLE', '1');
7544 // Åñëè ïàäàëè è äîñòèãëè çåìëè, òî õâàòèò ïàäàòü:
7545 if GetAIFlag('FALLINHOLE') <> '' then
7547 RemoveAIFlag('FALLINHOLE');
7549 // Åñëè ëåòåëè ïðÿìî è ñåé÷àñ íå íà ëåñòíèöå èëè íà âåðøèíå ëèôòà, òî îòõîäèì â ñòîðîíó:
7550 if not (KeyPressed(KEY_LEFT
) or KeyPressed(KEY_RIGHT
)) then
7551 if GetAIFlag('FALLINHOLE') = '' then
7552 if (not OnLadder()) or (FObj
.Vel
.Y
>= 0) or (OnTopLift()) then
7558 // Åñëè íà çåìëå è ìîæíî ïîäïðûãíóòü, òî, âîçìîæíî, ïðûãàåì:
7560 CanJumpUp(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*32) and
7564 // Åñëè íà çåìëå è âîçëå äûðû (ãëóáèíà > 2 ðîñòîâ èãðîêà):
7565 if OnGround() and NearHole() then
7566 if NearDeepHole() then // Åñëè ýòî áåçäíà
7568 0..3: Turn(); // Áåæèì îáðàòíî
7569 4: Jump(); // Ïðûãàåì
7570 5: begin // Ïðûãàåì îáðàòíî
7575 else // Ýòî íå áåçäíà è ìû åùå íå ëåòèì òóäà
7576 if GetAIFlag('GOINHOLE') = '' then
7578 0: Turn(); // Íå íóæíî òóäà
7579 1: Jump(); // Âäðóã ïîâåçåò - ïðûãàåì
7580 else // Åñëè ÿìà ñ ãðàíèöåé, òî ïðè ñëó÷àå ìîæíî òóäà ïðûãíóòü
7581 if BorderHole() then
7582 SetAIFlag('GOINHOLE', '1');
7585 // Åñëè íà çåìëå, íî íåêóäà èäòè:
7586 if (not CanRun()) and OnGround() then
7588 // Åñëè ìû íà ëåñòíèöå èëè ìîæíî ïåðåïðûãíóòü, òî ïðûãàåì:
7589 if CanJumpOver() or OnLadder() then
7591 else // èíà÷å ïîïûòàåìñÿ â äðóãóþ ñòîðîíó
7592 if Random(2) = 0 then
7594 if IsSafeTrigger() then
7600 // Îñòàëîñü ìàëî âîçäóõà:
7601 if FAir
< 36 * 2 then
7604 // Âûáèðàåìñÿ èç êèñëîòû, åñëè íåò êîñòþìà, îáîæãëèñü, èëè ìàëî çäîðîâüÿ:
7605 if (FMegaRulez
[MR_SUIT
] < gTime
) and ((FLastHit
= HIT_ACID
) or (Healthy() <= 1)) then
7606 if BodyInAcid(0, 0) then
7610 function TBot
.FullInStep(XInc
, YInc
: Integer): Boolean;
7612 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
7613 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_STEP
, False);
7616 {function TBot.NeedItem(Item: Byte): Byte;
7621 procedure TBot
.SelectWeapon(Dist
: Integer);
7625 function HaveAmmo(weapon
: Byte): Boolean;
7628 WEAPON_PISTOL
: Result
:= FAmmo
[A_BULLETS
] >= 1;
7629 WEAPON_SHOTGUN1
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7630 WEAPON_SHOTGUN2
: Result
:= FAmmo
[A_SHELLS
] >= 2;
7631 WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
] >= 10;
7632 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
] >= 1;
7633 WEAPON_PLASMA
: Result
:= FAmmo
[A_CELLS
] >= 10;
7634 WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
] >= 40;
7635 WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7636 WEAPON_FLAMETHROWER
: Result
:= FAmmo
[A_FUEL
] >= 1;
7637 else Result
:= True;
7642 if Dist
= -1 then Dist
:= BOT_LONGDIST
;
7644 if Dist
> BOT_LONGDIST
then
7645 begin // Äàëüíèé áîé
7647 if FWeapon
[FDifficult
.WeaponPrior
[a
]] and HaveAmmo(FDifficult
.WeaponPrior
[a
]) then
7649 FSelectedWeapon
:= FDifficult
.WeaponPrior
[a
];
7653 else //if Dist > BOT_UNSAFEDIST then
7654 begin // Áëèæíèé áîé
7656 if FWeapon
[FDifficult
.CloseWeaponPrior
[a
]] and HaveAmmo(FDifficult
.CloseWeaponPrior
[a
]) then
7658 FSelectedWeapon
:= FDifficult
.CloseWeaponPrior
[a
];
7665 if FWeapon[FDifficult.SafeWeaponPrior[a]] and HaveAmmo(FDifficult.SafeWeaponPrior[a]) then
7667 FSelectedWeapon := FDifficult.SafeWeaponPrior[a];
7673 function TBot
.PickItem(ItemType
: Byte; force
: Boolean; var remove
: Boolean): Boolean;
7675 Result
:= inherited PickItem(ItemType
, force
, remove
);
7677 if Result
then SetAIFlag('SELECTWEAPON', '1');
7680 function TBot
.Heal(value
: Word; Soft
: Boolean): Boolean;
7682 Result
:= inherited Heal(value
, Soft
);
7685 function TBot
.Healthy(): Byte;
7687 if FMegaRulez
[MR_INVUL
] >= gTime
then Result
:= 3
7688 else if (FHealth
> 80) or ((FHealth
> 50) and (FArmor
> 20)) then Result
:= 3
7689 else if (FHealth
> 50) then Result
:= 2
7690 else if (FHealth
> 20) then Result
:= 1
7694 function TBot
.TargetOnScreen(TX
, TY
: Integer): Boolean;
7696 Result
:= (Abs(FObj
.X
-TX
) <= Trunc(gPlayerScreenSize
.X
*0.6)) and
7697 (Abs(FObj
.Y
-TY
) <= Trunc(gPlayerScreenSize
.Y
*0.6));
7700 procedure TBot
.OnDamage(Angle
: SmallInt);
7708 if (Angle
= 0) or (Angle
= 180) then
7711 if (g_GetUIDType(FLastSpawnerUID
) = UID_PLAYER
) and
7712 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
) then
7714 pla
:= g_Player_Get(FLastSpawnerUID
);
7715 ok
:= not TargetOnScreen(pla
.FObj
.X
+ PLAYER_RECT
.X
,
7716 pla
.FObj
.Y
+ PLAYER_RECT
.Y
);
7719 if (g_GetUIDType(FLastSpawnerUID
) = UID_MONSTER
) and
7720 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
) then
7722 mon
:= g_Monsters_ByUID(FLastSpawnerUID
);
7723 ok
:= not TargetOnScreen(mon
.Obj
.X
+ mon
.Obj
.Rect
.X
,
7724 mon
.Obj
.Y
+ mon
.Obj
.Rect
.Y
);
7729 SetAIFlag('ATTACKLEFT', '1')
7731 SetAIFlag('ATTACKRIGHT', '1');
7735 function TBot
.RunDirection(): TDirection
;
7737 if Abs(Vel
.X
) >= 1 then
7739 if Vel
.X
> 0 then Result
:= TDirection
.D_RIGHT
else Result
:= TDirection
.D_LEFT
;
7741 Result
:= FDirection
;
7744 function TBot
.GetRnd(a
: Byte): Boolean;
7746 if a
= 0 then Result
:= False
7747 else if a
= 255 then Result
:= True
7748 else Result
:= Random(256) > 255-a
;
7751 function TBot
.GetInterval(a
: Byte; radius
: SmallInt): SmallInt;
7753 Result
:= Round((255-a
)/255*radius
*(Random(2)-1));
7757 procedure TDifficult
.save (st
: TStream
);
7759 utils
.writeInt(st
, Byte(DiagFire
));
7760 utils
.writeInt(st
, Byte(InvisFire
));
7761 utils
.writeInt(st
, Byte(DiagPrecision
));
7762 utils
.writeInt(st
, Byte(FlyPrecision
));
7763 utils
.writeInt(st
, Byte(Cover
));
7764 utils
.writeInt(st
, Byte(CloseJump
));
7765 st
.WriteBuffer(WeaponPrior
[Low(WeaponPrior
)], sizeof(WeaponPrior
));
7766 st
.WriteBuffer(CloseWeaponPrior
[Low(CloseWeaponPrior
)], sizeof(CloseWeaponPrior
));
7769 procedure TDifficult
.load (st
: TStream
);
7771 DiagFire
:= utils
.readByte(st
);
7772 InvisFire
:= utils
.readByte(st
);
7773 DiagPrecision
:= utils
.readByte(st
);
7774 FlyPrecision
:= utils
.readByte(st
);
7775 Cover
:= utils
.readByte(st
);
7776 CloseJump
:= utils
.readByte(st
);
7777 st
.ReadBuffer(WeaponPrior
[Low(WeaponPrior
)], sizeof(WeaponPrior
));
7778 st
.ReadBuffer(CloseWeaponPrior
[Low(CloseWeaponPrior
)], sizeof(CloseWeaponPrior
));
7782 procedure TBot
.SaveState (st
: TStream
);
7787 inherited SaveState(st
);
7788 utils
.writeSign(st
, 'BOT0');
7790 utils
.writeInt(st
, Byte(FSelectedWeapon
));
7792 utils
.writeInt(st
, Word(FTargetUID
));
7793 // Âðåìÿ ïîòåðè öåëè
7794 utils
.writeInt(st
, LongWord(FLastVisible
));
7795 // Êîëè÷åñòâî ôëàãîâ ÈÈ
7796 dw
:= Length(FAIFlags
);
7797 utils
.writeInt(st
, LongInt(dw
));
7799 for i
:= 0 to dw
-1 do
7801 utils
.writeStr(st
, FAIFlags
[i
].Name
, 20);
7802 utils
.writeStr(st
, FAIFlags
[i
].Value
, 20);
7804 // Íàñòðîéêè ñëîæíîñòè
7805 FDifficult
.save(st
);
7809 procedure TBot
.LoadState (st
: TStream
);
7814 inherited LoadState(st
);
7815 if not utils
.checkSign(st
, 'BOT0') then raise XStreamError
.Create('invalid bot signature');
7817 FSelectedWeapon
:= utils
.readByte(st
);
7819 FTargetUID
:= utils
.readWord(st
);
7820 // Âðåìÿ ïîòåðè öåëè
7821 FLastVisible
:= utils
.readLongWord(st
);
7822 // Êîëè÷åñòâî ôëàãîâ ÈÈ
7823 dw
:= utils
.readLongInt(st
);
7824 if (dw
< 0) or (dw
> 16384) then raise XStreamError
.Create('invalid number of bot AI flags');
7825 SetLength(FAIFlags
, dw
);
7827 for i
:= 0 to dw
-1 do
7829 FAIFlags
[i
].Name
:= utils
.readStr(st
, 20);
7830 FAIFlags
[i
].Value
:= utils
.readStr(st
, 20);
7832 // Íàñòðîéêè ñëîæíîñòè
7833 FDifficult
.load(st
);
7838 conRegVar('cheat_berserk_autoswitch', @gBerserkAutoswitch
, 'autoswitch to fist when berserk pack taken', '', true, true);