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);
118 TPlayerStatArray
= Array of TPlayerStat
;
120 TPlayerSavedState
= record
128 Ammo
: Array [A_BULLETS
..A_HIGH
] of Word;
129 MaxAmmo
: Array [A_BULLETS
..A_HIGH
] of Word;
130 Weapon
: Array [WP_FIRST
..WP_LAST
] of Boolean;
131 Rulez
: Set of R_ITEM_BACKPACK
..R_BERSERK
;
140 TPlayer
= class{$IFDEF USE_MEMPOOL}(TPoolObject
){$ENDIF}
148 FDirection
: TDirection
;
156 FMonsterKills
: Integer;
162 FCanJetpack
: Boolean;
168 FNextWeapDelay
: Byte; // frames
169 FBFGFireCounter
: SmallInt;
170 FLastSpawnerUID
: Word;
174 FSpectatePlayer
: Integer;
175 FFirePainTime
: Integer;
178 FSavedState
: TPlayerSavedState
;
180 FModel
: TPlayerModel
;
181 FPunchAnim
: TAnimation
;
184 FActionForce
: Boolean;
185 FActionChanged
: Boolean;
187 FFireAngle
: SmallInt;
189 FShellTimer
: Integer;
191 FSawSound
: TPlayableSound
;
192 FSawSoundIdle
: TPlayableSound
;
193 FSawSoundHit
: TPlayableSound
;
194 FSawSoundSelect
: TPlayableSound
;
195 FFlameSoundOn
: TPlayableSound
;
196 FFlameSoundOff
: TPlayableSound
;
197 FFlameSoundWork
: TPlayableSound
;
198 FJetSoundOn
: TPlayableSound
;
199 FJetSoundOff
: TPlayableSound
;
200 FJetSoundFly
: TPlayableSound
;
204 FJustTeleported
: Boolean;
206 mEDamageType
: Integer;
209 function CollideLevel(XInc
, YInc
: Integer): Boolean;
210 function StayOnStep(XInc
, YInc
: Integer): Boolean;
211 function HeadInLiquid(XInc
, YInc
: Integer): Boolean;
212 function BodyInLiquid(XInc
, YInc
: Integer): Boolean;
213 function BodyInAcid(XInc
, YInc
: Integer): Boolean;
214 function FullInLift(XInc
, YInc
: Integer): Integer;
215 {procedure CollideItem();}
216 procedure FlySmoke(Times
: DWORD
= 1);
217 procedure OnFireFlame(Times
: DWORD
= 1);
218 function GetAmmoByWeapon(Weapon
: Byte): Word;
219 procedure SetAction(Action
: Byte; Force
: Boolean = False);
220 procedure OnDamage(Angle
: SmallInt); virtual;
221 function firediry(): Integer;
224 procedure Run(Direction
: TDirection
);
225 procedure NextWeapon();
226 procedure PrevWeapon();
233 function getNextWeaponIndex (): Byte; // return 255 for "no switch"
234 procedure resetWeaponQueue ();
235 function hasAmmoForWeapon (weapon
: Byte): Boolean;
237 procedure doDamage (v
: Integer);
239 function followCorpse(): Boolean;
242 FDamageBuffer
: Integer;
244 FAmmo
: Array [A_BULLETS
..A_HIGH
] of Word;
245 FMaxAmmo
: Array [A_BULLETS
..A_HIGH
] of Word;
246 FWeapon
: Array [WP_FIRST
..WP_LAST
] of Boolean;
247 FRulez
: Set of R_ITEM_BACKPACK
..R_BERSERK
;
249 FMegaRulez
: Array [MR_SUIT
..MR_MAX
] of DWORD
;
250 FReloading
: Array [WP_FIRST
..WP_LAST
] of Word;
251 FTime
: Array [T_RESPAWN
..T_FLAGCAP
] of DWORD
;
252 FKeys
: Array [KEY_LEFT
..KEY_CHAT
] of TKeyState
;
254 FPreferredTeam
: Byte;
257 FWantsInGame
: Boolean;
262 FActualModelName
: string;
271 // debug: viewport offset
272 viewPortX
, viewPortY
, viewPortW
, viewPortH
: Integer;
274 function isValidViewPort (): Boolean; inline;
276 constructor Create(); virtual;
277 destructor Destroy(); override;
278 procedure Respawn(Silent
: Boolean; Force
: Boolean = False); virtual;
279 function GetRespawnPoint(): Byte;
280 procedure PressKey(Key
: Byte; Time
: Word = 1);
281 procedure ReleaseKeys();
282 procedure SetModel(ModelName
: String);
283 procedure SetColor(Color
: TRGB
);
284 procedure SetWeapon(W
: Byte);
285 function IsKeyPressed(K
: Byte): Boolean;
286 function GetKeys(): Byte;
287 function PickItem(ItemType
: Byte; arespawn
: Boolean; var remove
: Boolean): Boolean; virtual;
288 function Collide(X
, Y
: Integer; Width
, Height
: Word): Boolean; overload
;
289 function Collide(Panel
: TPanel
): Boolean; overload
;
290 function Collide(X
, Y
: Integer): Boolean; overload
;
291 procedure SetDirection(Direction
: TDirection
);
292 procedure GetSecret();
293 function TeleportTo(X
, Y
: Integer; silent
: Boolean; dir
: Byte): Boolean;
295 procedure Push(vx
, vy
: Integer);
296 procedure ChangeModel(ModelName
: String);
297 procedure SwitchTeam
;
298 procedure ChangeTeam(Team
: Byte);
300 function GetFlag(Flag
: Byte): Boolean;
301 procedure SetFlag(Flag
: Byte);
302 function DropFlag(Silent
: Boolean = True): Boolean;
303 procedure AllRulez(Health
: Boolean);
304 procedure RestoreHealthArmor();
305 procedure FragCombo();
306 procedure GiveItem(ItemType
: Byte);
307 procedure Damage(value
: Word; SpawnerUID
: Word; vx
, vy
: Integer; t
: Byte); virtual;
308 function Heal(value
: Word; Soft
: Boolean): Boolean; virtual;
309 procedure MakeBloodVector(Count
: Word; VelX
, VelY
: Integer);
310 procedure MakeBloodSimple(Count
: Word);
311 procedure Kill(KillType
: Byte; SpawnerUID
: Word; t
: Byte);
312 procedure Reset(Force
: Boolean);
313 procedure Spectate(NoMove
: Boolean = False);
314 procedure SwitchNoClip
;
315 procedure SoftReset();
316 procedure Draw(); virtual;
317 procedure DrawPain();
318 procedure DrawPickup();
319 procedure DrawRulez();
321 procedure DrawIndicator();
322 procedure DrawBubble();
324 procedure Update(); virtual;
325 procedure RememberState();
326 procedure RecallState();
327 procedure SaveState (st
: TStream
); virtual;
328 procedure LoadState (st
: TStream
); virtual;
329 procedure PauseSounds(Enable
: Boolean);
330 procedure NetFire(Wpn
: Byte; X
, Y
, AX
, AY
: Integer; WID
: Integer = -1);
331 procedure DoLerp(Level
: Integer = 2);
332 procedure SetLerp(XTo
, YTo
: Integer);
333 procedure QueueWeaponSwitch(Weapon
: Byte);
334 procedure RealizeCurrentWeapon();
338 procedure JetpackOff
;
339 procedure CatchFire(Attacker
: Word);
341 //WARNING! this does nothing for now, but still call it!
342 procedure positionChanged (); //WARNING! call this after entity position was changed, or coldet will not work right!
344 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
345 procedure moveBy (dx
, dy
: Integer); inline;
348 property Vel
: TPoint2i read FObj
.Vel
;
349 property Obj
: TObj read FObj
;
351 property Name
: String read FName write FName
;
352 property Model
: TPlayerModel read FModel
;
353 property Health
: Integer read FHealth write FHealth
;
354 property Lives
: Byte read FLives write FLives
;
355 property Armor
: Integer read FArmor write FArmor
;
356 property Air
: Integer read FAir write FAir
;
357 property JetFuel
: Integer read FJetFuel write FJetFuel
;
358 property Frags
: Integer read FFrags write FFrags
;
359 property Death
: Integer read FDeath write FDeath
;
360 property Kills
: Integer read FKills write FKills
;
361 property CurrWeap
: Byte read FCurrWeap write FCurrWeap
;
362 property MonsterKills
: Integer read FMonsterKills write FMonsterKills
;
363 property Secrets
: Integer read FSecrets
;
364 property GodMode
: Boolean read FGodMode write FGodMode
;
365 property NoTarget
: Boolean read FNoTarget write FNoTarget
;
366 property NoReload
: Boolean read FNoReload write FNoReload
;
367 property alive
: Boolean read FAlive write FAlive
;
368 property Flag
: Byte read FFlag
;
369 property Team
: Byte read FTeam write FTeam
;
370 property Direction
: TDirection read FDirection
;
371 property GameX
: Integer read FObj
.X write FObj
.X
;
372 property GameY
: Integer read FObj
.Y write FObj
.Y
;
373 property GameVelX
: Integer read FObj
.Vel
.X write FObj
.Vel
.X
;
374 property GameVelY
: Integer read FObj
.Vel
.Y write FObj
.Vel
.Y
;
375 property GameAccelX
: Integer read FObj
.Accel
.X write FObj
.Accel
.X
;
376 property GameAccelY
: Integer read FObj
.Accel
.Y write FObj
.Accel
.Y
;
377 property IncCam
: Integer read FIncCam write FIncCam
;
378 property UID
: Word read FUID write FUID
;
379 property JustTeleported
: Boolean read FJustTeleported write FJustTeleported
;
380 property NetTime
: LongWord read FNetTime write FNetTime
;
383 property eName
: String read FName write FName
;
384 property eHealth
: Integer read FHealth write FHealth
;
385 property eLives
: Byte read FLives write FLives
;
386 property eArmor
: Integer read FArmor write FArmor
;
387 property eAir
: Integer read FAir write FAir
;
388 property eJetFuel
: Integer read FJetFuel write FJetFuel
;
389 property eFrags
: Integer read FFrags write FFrags
;
390 property eDeath
: Integer read FDeath write FDeath
;
391 property eKills
: Integer read FKills write FKills
;
392 property eCurrWeap
: Byte read FCurrWeap write FCurrWeap
;
393 property eMonsterKills
: Integer read FMonsterKills write FMonsterKills
;
394 property eSecrets
: Integer read FSecrets write FSecrets
;
395 property eGodMode
: Boolean read FGodMode write FGodMode
;
396 property eNoTarget
: Boolean read FNoTarget write FNoTarget
;
397 property eNoReload
: Boolean read FNoReload write FNoReload
;
398 property eAlive
: Boolean read FAlive write FAlive
;
399 property eFlag
: Byte read FFlag
;
400 property eTeam
: Byte read FTeam write FTeam
;
401 property eDirection
: TDirection read FDirection
;
402 property eGameX
: Integer read FObj
.X write FObj
.X
;
403 property eGameY
: Integer read FObj
.Y write FObj
.Y
;
404 property eGameVelX
: Integer read FObj
.Vel
.X write FObj
.Vel
.X
;
405 property eGameVelY
: Integer read FObj
.Vel
.Y write FObj
.Vel
.Y
;
406 property eGameAccelX
: Integer read FObj
.Accel
.X write FObj
.Accel
.X
;
407 property eGameAccelY
: Integer read FObj
.Accel
.Y write FObj
.Accel
.Y
;
408 property eIncCam
: Integer read FIncCam write FIncCam
;
409 property eUID
: Word read FUID
;
410 property eJustTeleported
: Boolean read FJustTeleported
;
411 property eNetTime
: LongWord read FNetTime
;
413 // set this before assigning something to `eDamage`
414 property eDamageType
: Integer read mEDamageType write mEDamageType
;
415 property eDamage
: Integer write doDamage
;
426 WeaponPrior
: packed array [WP_FIRST
..WP_LAST
] of Byte;
427 CloseWeaponPrior
: packed array [WP_FIRST
..WP_LAST
] of Byte;
428 //SafeWeaponPrior: Array [WP_FIRST..WP_LAST] of Byte;
431 procedure save (st
: TStream
);
432 procedure load (st
: TStream
);
440 TBot
= class(TPlayer
)
442 FSelectedWeapon
: Byte;
445 FAIFlags
: Array of TAIFlag
;
446 FDifficult
: TDifficult
;
448 function GetRnd(a
: Byte): Boolean;
449 function GetInterval(a
: Byte; radius
: SmallInt): SmallInt;
450 function RunDirection(): TDirection
;
451 function FullInStep(XInc
, YInc
: Integer): Boolean;
452 //function NeedItem(Item: Byte): Byte;
453 procedure SelectWeapon(Dist
: Integer);
454 procedure SetAIFlag(aName
, fValue
: String20
);
455 function GetAIFlag(aName
: String20
): String20
;
456 procedure RemoveAIFlag(aName
: String20
);
457 function Healthy(): Byte;
458 procedure UpdateMove();
459 procedure UpdateCombat();
460 function KeyPressed(Key
: Word): Boolean;
461 procedure ReleaseKey(Key
: Byte);
462 function TargetOnScreen(TX
, TY
: Integer): Boolean;
463 procedure OnDamage(Angle
: SmallInt); override;
466 procedure Respawn(Silent
: Boolean; Force
: Boolean = False); override;
467 constructor Create(); override;
468 destructor Destroy(); override;
469 procedure Draw(); override;
470 function PickItem(ItemType
: Byte; force
: Boolean; var remove
: Boolean): Boolean; override;
471 function Heal(value
: Word; Soft
: Boolean): Boolean; override;
472 procedure Update(); override;
473 procedure SaveState (st
: TStream
); override;
474 procedure LoadState (st
: TStream
); override;
486 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
487 procedure moveBy (dx
, dy
: Integer); inline;
489 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
503 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
504 procedure moveBy (dx
, dy
: Integer); inline;
506 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
509 TCorpse
= class{$IFDEF USE_MEMPOOL}(TPoolObject
){$ENDIF}
518 FAnimation
: TAnimation
;
519 FAnimationMask
: TAnimation
;
522 constructor Create(X
, Y
: Integer; ModelName
: String; aMess
: Boolean);
523 destructor Destroy(); override;
524 procedure Damage(Value
: Word; vx
, vy
: Integer);
527 procedure SaveState (st
: TStream
);
528 procedure LoadState (st
: TStream
);
530 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
531 procedure moveBy (dx
, dy
: Integer); inline;
533 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
535 function ObjPtr (): PObj
; inline;
537 property Obj
: TObj read FObj
; // copies object
538 property State
: Byte read FState
;
539 property Mess
: Boolean read FMess
;
542 TTeamStat
= Array [TEAM_RED
..TEAM_BLUE
] of
548 gPlayers
: Array of TPlayer
;
549 gCorpses
: Array of TCorpse
;
550 gGibs
: Array of TGib
;
551 gShells
: Array of TShell
;
552 gTeamStat
: TTeamStat
;
553 gFly
: Boolean = False;
554 gAimLine
: Boolean = False;
555 gChatBubble
: Byte = 0;
556 gPlayerIndicator
: Boolean = True;
560 MAX_RUNVEL
: Integer = 8;
561 VEL_JUMP
: Integer = 10;
562 SHELL_TIMEOUT
: Cardinal = 60000;
564 function Lerp(X
, Y
, Factor
: Integer): Integer;
566 procedure g_Gibs_SetMax(Count
: Word);
567 function g_Gibs_GetMax(): Word;
568 procedure g_Corpses_SetMax(Count
: Word);
569 function g_Corpses_GetMax(): Word;
570 procedure g_Shells_SetMax(Count
: Word);
571 function g_Shells_GetMax(): Word;
573 procedure g_Player_Init();
574 procedure g_Player_Free();
575 function g_Player_Create(ModelName
: String; Color
: TRGB
; Team
: Byte; Bot
: Boolean): Word;
576 function g_Player_CreateFromState (st
: TStream
): Word;
577 procedure g_Player_Remove(UID
: Word);
578 procedure g_Player_ResetTeams();
579 procedure g_Player_UpdateAll();
580 procedure g_Player_DrawAll();
581 procedure g_Player_DrawDebug(p
: TPlayer
);
582 procedure g_Player_DrawHealth();
583 procedure g_Player_RememberAll();
584 procedure g_Player_ResetAll(Force
, Silent
: Boolean);
585 function g_Player_Get(UID
: Word): TPlayer
;
586 function g_Player_GetCount(): Byte;
587 function g_Player_GetStats(): TPlayerStatArray
;
588 function g_Player_ValidName(Name
: String): Boolean;
589 procedure g_Player_CreateCorpse(Player
: TPlayer
);
590 procedure g_Player_CreateGibs(fX
, fY
: Integer; ModelName
: String; fColor
: TRGB
);
591 procedure g_Player_CreateShell(fX
, fY
, dX
, dY
: Integer; T
: Byte);
592 procedure g_Player_UpdatePhysicalObjects();
593 procedure g_Player_DrawCorpses();
594 procedure g_Player_DrawShells();
595 procedure g_Player_RemoveAllCorpses();
596 procedure g_Player_Corpses_SaveState (st
: TStream
);
597 procedure g_Player_Corpses_LoadState (st
: TStream
);
598 procedure g_Player_ResetReady();
599 procedure g_Bot_Add(Team
, Difficult
: Byte; Handicap
: Integer = 100);
600 procedure g_Bot_AddList(Team
: Byte; lname
: ShortString; num
: Integer = -1; Handicap
: Integer = 100);
601 procedure g_Bot_MixNames();
602 procedure g_Bot_RemoveAll();
607 {$INCLUDE ../nogl/noGLuses.inc}
608 {$IFDEF ENABLE_HOLMES}
611 e_log
, g_map
, g_items
, g_console
, g_gfx
, Math
,
612 g_options
, g_triggers
, g_menu
, g_game
, g_grid
,
613 wadreader
, g_main
, g_monsters
, CONFIG
, g_language
,
614 g_net
, g_netmsg
, g_window
,
617 const PLR_SAVE_VERSION
= 0;
627 diag_precision
: Byte;
631 w_prior1
: Array [WP_FIRST
..WP_LAST
] of Byte;
632 w_prior2
: Array [WP_FIRST
..WP_LAST
] of Byte;
633 w_prior3
: Array [WP_FIRST
..WP_LAST
] of Byte;
637 TIME_RESPAWN1
= 1500;
638 TIME_RESPAWN2
= 2000;
639 TIME_RESPAWN3
= 3000;
642 JET_MAX
= 540; // ~30 sec
643 PLAYER_SUIT_TIME
= 30000;
644 PLAYER_INVUL_TIME
= 30000;
645 PLAYER_INVIS_TIME
= 35000;
646 FRAG_COMBO_TIME
= 3000;
650 ANGLE_RIGHTDOWN
= -35;
652 ANGLE_LEFTDOWN
= -145;
653 PLAYER_HEADRECT
: TRectWH
= (X
:24; Y
:12; Width
:20; Height
:12);
654 WEAPONPOINT
: Array [TDirection
] of TDFPoint
= ((X
:16; Y
:32), (X
:47; Y
:32));
657 BOT_UNSAFEDIST
= 128;
658 TEAMCOLOR
: Array [TEAM_RED
..TEAM_BLUE
] of TRGB
= ((R
:255; G
:0; B
:0),
660 DIFFICULT_EASY
: TDifficult
= (DiagFire
: 32; InvisFire
: 32; DiagPrecision
: 32;
661 FlyPrecision
: 32; Cover
: 32; CloseJump
: 32;
662 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
663 DIFFICULT_MEDIUM
: TDifficult
= (DiagFire
: 127; InvisFire
: 127; DiagPrecision
: 127;
664 FlyPrecision
: 127; Cover
: 127; CloseJump
: 127;
665 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
666 DIFFICULT_HARD
: TDifficult
= (DiagFire
: 255; InvisFire
: 255; DiagPrecision
: 255;
667 FlyPrecision
: 255; Cover
: 255; CloseJump
: 255;
668 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
669 WEAPON_PRIOR1
: Array [WP_FIRST
..WP_LAST
] of Byte =
670 (WEAPON_FLAMETHROWER
, WEAPON_SUPERPULEMET
,
671 WEAPON_SHOTGUN2
, WEAPON_SHOTGUN1
,
672 WEAPON_CHAINGUN
, WEAPON_PLASMA
, WEAPON_ROCKETLAUNCHER
,
673 WEAPON_BFG
, WEAPON_PISTOL
, WEAPON_SAW
, WEAPON_KASTET
);
674 WEAPON_PRIOR2
: Array [WP_FIRST
..WP_LAST
] of Byte =
675 (WEAPON_FLAMETHROWER
, WEAPON_SUPERPULEMET
,
676 WEAPON_BFG
, WEAPON_ROCKETLAUNCHER
,
677 WEAPON_SHOTGUN2
, WEAPON_PLASMA
, WEAPON_SHOTGUN1
,
678 WEAPON_CHAINGUN
, WEAPON_PISTOL
, WEAPON_SAW
, WEAPON_KASTET
);
679 //WEAPON_PRIOR3: Array [WP_FIRST..WP_LAST] of Byte =
680 // (WEAPON_FLAMETHROWER, WEAPON_SUPERPULEMET,
681 // WEAPON_BFG, WEAPON_PLASMA, WEAPON_SHOTGUN2,
682 // WEAPON_CHAINGUN, WEAPON_SHOTGUN1, WEAPON_SAW,
683 // WEAPON_ROCKETLAUNCHER, WEAPON_PISTOL, WEAPON_KASTET);
684 WEAPON_RELOAD
: Array [WP_FIRST
..WP_LAST
] of Byte =
685 (5, 2, 6, 18, 36, 2, 12, 2, 14, 2, 2);
687 PLAYER_SIGNATURE
= $52594C50; // 'PLYR'
688 CORPSE_SIGNATURE
= $50524F43; // 'CORP'
690 BOTNAMES_FILENAME
= 'botnames.txt';
691 BOTLIST_FILENAME
= 'botlist.txt';
695 MaxCorpses
: Word = 20;
696 MaxShells
: Word = 300;
697 CurrentGib
: Integer = 0;
698 CurrentShell
: Integer = 0;
699 BotNames
: Array of String;
700 BotList
: Array of TBotProfile
;
703 function Lerp(X
, Y
, Factor
: Integer): Integer;
705 Result
:= X
+ ((Y
- X
) div Factor
);
708 function SameTeam(UID1
, UID2
: Word): Boolean;
712 if (UID1
> UID_MAX_PLAYER
) or (UID1
<= UID_MAX_GAME
) or
713 (UID2
> UID_MAX_PLAYER
) or (UID2
<= UID_MAX_GAME
) then Exit
;
715 if (g_Player_Get(UID1
) = nil) or (g_Player_Get(UID2
) = nil) then Exit
;
717 if ((g_Player_Get(UID1
).Team
= TEAM_NONE
) or
718 (g_Player_Get(UID2
).Team
= TEAM_NONE
)) then Exit
;
720 Result
:= g_Player_Get(UID1
).FTeam
= g_Player_Get(UID2
).FTeam
;
723 procedure g_Gibs_SetMax(Count
: Word);
726 SetLength(gGibs
, Count
);
728 if CurrentGib
>= Count
then
732 function g_Gibs_GetMax(): Word;
737 procedure g_Shells_SetMax(Count
: Word);
740 SetLength(gShells
, Count
);
742 if CurrentShell
>= Count
then
746 function g_Shells_GetMax(): Word;
752 procedure g_Corpses_SetMax(Count
: Word);
755 SetLength(gCorpses
, Count
);
758 function g_Corpses_GetMax(): Word;
760 Result
:= MaxCorpses
;
763 function g_Player_Create(ModelName
: String; Color
: TRGB
; Team
: Byte; Bot
: Boolean): Word;
773 // Åñòü ëè ìåñòî â gPlayers:
774 if gPlayers
<> nil then
775 for a
:= 0 to High(gPlayers
) do
776 if gPlayers
[a
] = nil then
782 // Íåò ìåñòà - ðàñøèðÿåì gPlayers:
785 SetLength(gPlayers
, Length(gPlayers
)+1);
789 // Ñîçäàåì îáúåêò èãðîêà:
791 gPlayers
[a
] := TBot
.Create()
793 gPlayers
[a
] := TPlayer
.Create();
796 gPlayers
[a
].FActualModelName
:= ModelName
;
797 gPlayers
[a
].SetModel(ModelName
);
799 // Íåò ìîäåëè - ñîçäàíèå íå âîçìîæíî:
800 if gPlayers
[a
].FModel
= nil then
804 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], [ModelName
]));
808 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
809 if Random(2) = 0 then
813 gPlayers
[a
].FPreferredTeam
:= Team
;
815 case gGameSettings
.GameMode
of
816 GM_DM
: gPlayers
[a
].FTeam
:= TEAM_NONE
;
818 GM_CTF
: gPlayers
[a
].FTeam
:= gPlayers
[a
].FPreferredTeam
;
820 GM_COOP
: gPlayers
[a
].FTeam
:= TEAM_COOP
;
823 // Åñëè êîìàíäíàÿ èãðà - êðàñèì ìîäåëü â öâåò êîìàíäû:
824 gPlayers
[a
].FColor
:= Color
;
825 if gPlayers
[a
].FTeam
in [TEAM_RED
, TEAM_BLUE
] then
826 gPlayers
[a
].FModel
.Color
:= TEAMCOLOR
[gPlayers
[a
].FTeam
]
828 gPlayers
[a
].FModel
.Color
:= Color
;
830 gPlayers
[a
].FUID
:= g_CreateUID(UID_PLAYER
);
831 gPlayers
[a
].FAlive
:= False;
833 Result
:= gPlayers
[a
].FUID
;
836 function g_Player_CreateFromState (st
: TStream
): Word;
843 if (st
= nil) then exit
; //???
846 if not utils
.checkSign(st
, 'PLYR') then raise XStreamError
.Create('invalid player signature');
847 if (utils
.readByte(st
) <> PLR_SAVE_VERSION
) then raise XStreamError
.Create('invalid player version');
850 Bot
:= utils
.readBool(st
);
855 // Åñòü ëè ìåñòî â gPlayers:
856 for a
:= 0 to High(gPlayers
) do if (gPlayers
[a
] = nil) then begin ok
:= true; break
; end;
858 // Íåò ìåñòà - ðàñøèðÿåì gPlayers
861 SetLength(gPlayers
, Length(gPlayers
)+1);
865 // Ñîçäàåì îáúåêò èãðîêà
867 gPlayers
[a
] := TBot
.Create()
869 gPlayers
[a
] := TPlayer
.Create();
870 gPlayers
[a
].FIamBot
:= Bot
;
871 gPlayers
[a
].FPhysics
:= True;
874 gPlayers
[a
].FUID
:= utils
.readWord(st
);
876 gPlayers
[a
].FName
:= utils
.readStr(st
);
878 gPlayers
[a
].FTeam
:= utils
.readByte(st
);
879 gPlayers
[a
].FPreferredTeam
:= gPlayers
[a
].FTeam
;
881 gPlayers
[a
].FAlive
:= utils
.readBool(st
);
882 // Èçðàñõîäîâàë ëè âñå æèçíè
883 gPlayers
[a
].FNoRespawn
:= utils
.readBool(st
);
885 b
:= utils
.readByte(st
);
886 if b
= 1 then gPlayers
[a
].FDirection
:= TDirection
.D_LEFT
else gPlayers
[a
].FDirection
:= TDirection
.D_RIGHT
; // b = 2
888 gPlayers
[a
].FHealth
:= utils
.readLongInt(st
);
890 gPlayers
[a
].FHandicap
:= utils
.readLongInt(st
);
892 gPlayers
[a
].FLives
:= utils
.readByte(st
);
894 gPlayers
[a
].FArmor
:= utils
.readLongInt(st
);
896 gPlayers
[a
].FAir
:= utils
.readLongInt(st
);
898 gPlayers
[a
].FJetFuel
:= utils
.readLongInt(st
);
900 gPlayers
[a
].FPain
:= utils
.readLongInt(st
);
902 gPlayers
[a
].FKills
:= utils
.readLongInt(st
);
904 gPlayers
[a
].FMonsterKills
:= utils
.readLongInt(st
);
906 gPlayers
[a
].FFrags
:= utils
.readLongInt(st
);
908 gPlayers
[a
].FFragCombo
:= utils
.readByte(st
);
909 // Âðåìÿ ïîñëåäíåãî ôðàãà
910 gPlayers
[a
].FLastFrag
:= utils
.readLongWord(st
);
912 gPlayers
[a
].FDeath
:= utils
.readLongInt(st
);
914 gPlayers
[a
].FFlag
:= utils
.readByte(st
);
916 gPlayers
[a
].FSecrets
:= utils
.readLongInt(st
);
918 gPlayers
[a
].FCurrWeap
:= utils
.readByte(st
);
919 // Ñëåäóþùåå æåëàåìîå îðóæèå
920 gPlayers
[a
].FNextWeap
:= utils
.readWord(st
);
922 gPlayers
[a
].FNextWeapDelay
:= utils
.readByte(st
);
924 gPlayers
[a
].FBFGFireCounter
:= utils
.readSmallInt(st
);
926 gPlayers
[a
].FDamageBuffer
:= utils
.readLongInt(st
);
927 // Ïîñëåäíèé óäàðèâøèé
928 gPlayers
[a
].FLastSpawnerUID
:= utils
.readWord(st
);
929 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà
930 gPlayers
[a
].FLastHit
:= utils
.readByte(st
);
932 Obj_LoadState(@gPlayers
[a
].FObj
, st
);
933 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ
934 for i
:= A_BULLETS
to A_HIGH
do gPlayers
[a
].FAmmo
[i
] := utils
.readWord(st
);
935 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ
936 for i
:= A_BULLETS
to A_HIGH
do gPlayers
[a
].FMaxAmmo
[i
] := utils
.readWord(st
);
938 for i
:= WP_FIRST
to WP_LAST
do gPlayers
[a
].FWeapon
[i
] := utils
.readBool(st
);
939 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ
940 for i
:= WP_FIRST
to WP_LAST
do gPlayers
[a
].FReloading
[i
] := utils
.readWord(st
);
942 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_ITEM_BACKPACK
);
943 // Íàëè÷èå êðàñíîãî êëþ÷à
944 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_KEY_RED
);
945 // Íàëè÷èå çåëåíîãî êëþ÷à
946 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_KEY_GREEN
);
947 // Íàëè÷èå ñèíåãî êëþ÷à
948 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_KEY_BLUE
);
950 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_BERSERK
);
951 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ
952 for i
:= MR_SUIT
to MR_MAX
do gPlayers
[a
].FMegaRulez
[i
] := utils
.readLongWord(st
);
953 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà
954 for i
:= T_RESPAWN
to T_FLAGCAP
do gPlayers
[a
].FTime
[i
] := utils
.readLongWord(st
);
957 gPlayers
[a
].FActualModelName
:= utils
.readStr(st
);
959 gPlayers
[a
].FColor
.R
:= utils
.readByte(st
);
960 gPlayers
[a
].FColor
.G
:= utils
.readByte(st
);
961 gPlayers
[a
].FColor
.B
:= utils
.readByte(st
);
962 // Îáíîâëÿåì ìîäåëü èãðîêà
963 gPlayers
[a
].SetModel(gPlayers
[a
].FActualModelName
);
965 // Íåò ìîäåëè - ñîçäàíèå íåâîçìîæíî
966 if (gPlayers
[a
].FModel
= nil) then
970 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], [gPlayers
[a
].FActualModelName
]));
974 // Åñëè êîìàíäíàÿ èãðà - êðàñèì ìîäåëü â öâåò êîìàíäû
975 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
976 gPlayers
[a
].FModel
.Color
:= TEAMCOLOR
[gPlayers
[a
].FTeam
]
978 gPlayers
[a
].FModel
.Color
:= gPlayers
[a
].FColor
;
980 result
:= gPlayers
[a
].FUID
;
984 procedure g_Player_ResetTeams();
988 if g_Game_IsClient
then
990 if gPlayers
= nil then
992 for a
:= Low(gPlayers
) to High(gPlayers
) do
993 if gPlayers
[a
] <> nil then
994 case gGameSettings
.GameMode
of
996 gPlayers
[a
].ChangeTeam(TEAM_NONE
);
998 if not (gPlayers
[a
].Team
in [TEAM_RED
, TEAM_BLUE
]) then
999 if gPlayers
[a
].FPreferredTeam
in [TEAM_RED
, TEAM_BLUE
] then
1000 gPlayers
[a
].ChangeTeam(gPlayers
[a
].FPreferredTeam
)
1003 gPlayers
[a
].ChangeTeam(TEAM_RED
)
1005 gPlayers
[a
].ChangeTeam(TEAM_BLUE
);
1008 gPlayers
[a
].ChangeTeam(TEAM_COOP
);
1012 procedure g_Bot_Add(Team
, Difficult
: Byte; Handicap
: Integer = 100);
1015 _name
, _model
: String;
1018 if not g_Game_IsServer
then Exit
;
1020 // Ñïèñîê íàçâàíèé ìîäåëåé:
1021 m
:= g_PlayerModel_GetNames();
1026 if (gGameSettings
.GameType
= GT_SINGLE
) or (gGameSettings
.GameMode
= GM_COOP
) then
1027 Team
:= TEAM_COOP
// COOP
1029 if gGameSettings
.GameMode
= GM_DM
then
1030 Team
:= TEAM_NONE
// DM
1032 if Team
= TEAM_NONE
then // CTF / TDM
1034 // Àâòîáàëàíñ êîìàíä:
1038 for a
:= 0 to High(gPlayers
) do
1039 if gPlayers
[a
] <> nil then
1041 if gPlayers
[a
].Team
= TEAM_RED
then
1044 if gPlayers
[a
].Team
= TEAM_BLUE
then
1054 if Random(2) = 0 then
1060 // Âûáèðàåì áîòó èìÿ:
1062 if BotNames
<> nil then
1063 for a
:= 0 to High(BotNames
) do
1064 if g_Player_ValidName(BotNames
[a
]) then
1066 _name
:= BotNames
[a
];
1070 // Èìåíè íåò, çàäàåì ñëó÷àéíîå:
1073 _name
:= Format('DFBOT%.2d', [Random(100)]);
1074 until g_Player_ValidName(_name
);
1076 // Âûáèðàåì ñëó÷àéíóþ ìîäåëü:
1077 _model
:= m
[Random(Length(m
))];
1080 with g_Player_Get(g_Player_Create(_model
,
1081 _RGB(Min(Random(9)*32, 255),
1082 Min(Random(9)*32, 255),
1083 Min(Random(9)*32, 255)),
1084 Team
, True)) as TBot
do
1089 1: FDifficult
:= DIFFICULT_EASY
;
1090 2: FDifficult
:= DIFFICULT_MEDIUM
;
1091 else FDifficult
:= DIFFICULT_HARD
;
1094 for a
:= WP_FIRST
to WP_LAST
do
1096 FDifficult
.WeaponPrior
[a
] := WEAPON_PRIOR1
[a
];
1097 FDifficult
.CloseWeaponPrior
[a
] := WEAPON_PRIOR2
[a
];
1098 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
1101 FHandicap
:= Handicap
;
1103 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [Name
]), True);
1105 if g_Game_IsNet
then MH_SEND_PlayerCreate(UID
);
1106 if g_Game_IsServer
and (gGameSettings
.MaxLives
> 0) then
1111 procedure g_Bot_AddList(Team
: Byte; lName
: ShortString; num
: Integer = -1; Handicap
: Integer = 100);
1114 _name
, _model
: String;
1117 if not g_Game_IsServer
then Exit
;
1119 // Ñïèñîê íàçâàíèé ìîäåëåé:
1120 m
:= g_PlayerModel_GetNames();
1125 if (gGameSettings
.GameType
= GT_SINGLE
) or (gGameSettings
.GameMode
= GM_COOP
) then
1126 Team
:= TEAM_COOP
// COOP
1128 if gGameSettings
.GameMode
= GM_DM
then
1129 Team
:= TEAM_NONE
// DM
1131 if Team
= TEAM_NONE
then
1132 Team
:= BotList
[num
].team
; // CTF / TDM
1134 // Âûáèðàåì íàñòðîéêè áîòà èç ñïèñêà ïî íîìåðó èëè èìåíè:
1135 lName
:= AnsiLowerCase(lName
);
1136 if (num
< 0) or (num
> Length(BotList
)-1) then
1138 if (num
= -1) and (lName
<> '') and (BotList
<> nil) then
1139 for a
:= 0 to High(BotList
) do
1140 if AnsiLowerCase(BotList
[a
].name
) = lName
then
1149 _name
:= BotList
[num
].name
;
1150 // Çàíÿòî - âûáèðàåì ñëó÷àéíîå:
1151 if not g_Player_ValidName(_name
) then
1153 _name
:= Format('DFBOT%.2d', [Random(100)]);
1154 until g_Player_ValidName(_name
);
1157 _model
:= BotList
[num
].model
;
1158 // Íåò òàêîé - âûáèðàåì ñëó÷àéíóþ:
1159 if not InSArray(_model
, m
) then
1160 _model
:= m
[Random(Length(m
))];
1163 with g_Player_Get(g_Player_Create(_model
, BotList
[num
].color
, Team
, True)) as TBot
do
1167 FDifficult
.DiagFire
:= BotList
[num
].diag_fire
;
1168 FDifficult
.InvisFire
:= BotList
[num
].invis_fire
;
1169 FDifficult
.DiagPrecision
:= BotList
[num
].diag_precision
;
1170 FDifficult
.FlyPrecision
:= BotList
[num
].fly_precision
;
1171 FDifficult
.Cover
:= BotList
[num
].cover
;
1172 FDifficult
.CloseJump
:= BotList
[num
].close_jump
;
1174 FHandicap
:= Handicap
;
1176 for a
:= WP_FIRST
to WP_LAST
do
1178 FDifficult
.WeaponPrior
[a
] := BotList
[num
].w_prior1
[a
];
1179 FDifficult
.CloseWeaponPrior
[a
] := BotList
[num
].w_prior2
[a
];
1180 //FDifficult.SafeWeaponPrior[a] := BotList[num].w_prior3[a];
1183 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [Name
]), True);
1185 if g_Game_IsNet
then MH_SEND_PlayerCreate(UID
);
1189 procedure g_Bot_RemoveAll();
1193 if not g_Game_IsServer
then Exit
;
1194 if gPlayers
= nil then Exit
;
1196 for a
:= 0 to High(gPlayers
) do
1197 if gPlayers
[a
] <> nil then
1198 if gPlayers
[a
] is TBot
then
1200 gPlayers
[a
].Lives
:= 0;
1201 gPlayers
[a
].Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
1202 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [gPlayers
[a
].Name
]), True);
1203 g_Player_Remove(gPlayers
[a
].FUID
);
1209 procedure g_Bot_MixNames();
1214 if BotNames
<> nil then
1215 for a
:= 0 to High(BotNames
) do
1217 b
:= Random(Length(BotNames
));
1219 Botnames
[a
] := BotNames
[b
];
1224 procedure g_Player_Remove(UID
: Word);
1228 if gPlayers
= nil then Exit
;
1230 if g_Game_IsServer
and g_Game_IsNet
then
1231 MH_SEND_PlayerDelete(UID
);
1233 for i
:= 0 to High(gPlayers
) do
1234 if gPlayers
[i
] <> nil then
1235 if gPlayers
[i
].FUID
= UID
then
1237 if gPlayers
[i
] is TPlayer
then
1238 TPlayer(gPlayers
[i
]).Free()
1240 TBot(gPlayers
[i
]).Free();
1246 procedure g_Player_Init();
1256 if not FileExists(DataDir
+ BOTNAMES_FILENAME
) then
1259 // ×èòàåì âîçìîæíûå èìåíà áîòîâ èç ôàéëà:
1260 AssignFile(F
, DataDir
+ BOTNAMES_FILENAME
);
1271 SetLength(BotNames
, Length(BotNames
)+1);
1272 BotNames
[High(BotNames
)] := s
;
1280 // ×èòàåì ôàéë ñ ïàðàìåòðàìè áîòîâ:
1281 config
:= TConfig
.CreateFile(DataDir
+ BOTLIST_FILENAME
);
1285 while config
.SectionExists(IntToStr(a
)) do
1287 SetLength(BotList
, Length(BotList
)+1);
1289 with BotList
[High(BotList
)] do
1292 name
:= config
.ReadStr(IntToStr(a
), 'name', '');
1294 model
:= config
.ReadStr(IntToStr(a
), 'model', '');
1296 if config
.ReadStr(IntToStr(a
), 'team', 'red') = 'red' then
1301 sa
:= parse(config
.ReadStr(IntToStr(a
), 'color', ''));
1302 color
.R
:= StrToIntDef(sa
[0], 0);
1303 color
.G
:= StrToIntDef(sa
[1], 0);
1304 color
.B
:= StrToIntDef(sa
[2], 0);
1305 // Âåðîÿòíîñòü ñòðåëüáû ïîä óãëîì:
1306 diag_fire
:= config
.ReadInt(IntToStr(a
), 'diag_fire', 0);
1307 // Âåðîÿòíîñòü îòâåòíîãî îãíÿ ïî íåâèäèìîìó ñîïåðíèêó:
1308 invis_fire
:= config
.ReadInt(IntToStr(a
), 'invis_fire', 0);
1309 // Òî÷íîñòü ñòðåëüáû ïîä óãëîì:
1310 diag_precision
:= config
.ReadInt(IntToStr(a
), 'diag_precision', 0);
1311 // Òî÷íîñòü ñòðåëüáû â ïîëåòå:
1312 fly_precision
:= config
.ReadInt(IntToStr(a
), 'fly_precision', 0);
1313 // Òî÷íîñòü óêëîíåíèÿ îò ñíàðÿäîâ:
1314 cover
:= config
.ReadInt(IntToStr(a
), 'cover', 0);
1315 // Âåðîÿòíîñòü ïðûæêà ïðè ïðèáëèæåíèè ñîïåðíèêà:
1316 close_jump
:= config
.ReadInt(IntToStr(a
), 'close_jump', 0);
1317 // Ïðèîðèòåòû îðóæèÿ äëÿ äàëüíåãî áîÿ:
1318 sa
:= parse(config
.ReadStr(IntToStr(a
), 'w_prior1', ''));
1319 if Length(sa
) = 10 then
1321 w_prior1
[b
] := EnsureRange(StrToInt(sa
[b
]), 0, 9);
1322 // Ïðèîðèòåòû îðóæèÿ äëÿ áëèæíåãî áîÿ:
1323 sa
:= parse(config
.ReadStr(IntToStr(a
), 'w_prior2', ''));
1324 if Length(sa
) = 10 then
1326 w_prior2
[b
] := EnsureRange(StrToInt(sa
[b
]), 0, 9);
1328 {sa := parse(config.ReadStr(IntToStr(a), 'w_prior3', ''));
1329 if Length(sa) = 10 then
1331 w_prior3[b] := EnsureRange(StrToInt(sa[b]), 0, 9);}
1340 procedure g_Player_Free();
1344 if gPlayers
<> nil then
1346 for i
:= 0 to High(gPlayers
) do
1347 if gPlayers
[i
] <> nil then
1349 if gPlayers
[i
] is TPlayer
then
1350 TPlayer(gPlayers
[i
]).Free()
1352 TBot(gPlayers
[i
]).Free();
1363 procedure g_Player_UpdateAll();
1367 if gPlayers
= nil then Exit
;
1369 //e_WriteLog('***g_Player_UpdateAll: ENTER', MSG_WARNING);
1370 for i
:= 0 to High(gPlayers
) do
1372 if gPlayers
[i
] <> nil then
1374 if gPlayers
[i
] is TPlayer
then
1376 gPlayers
[i
].Update();
1377 gPlayers
[i
].RealizeCurrentWeapon(); // WARNING! DO NOT MOVE THIS INTO `Update()`!
1381 // bot updates weapons in `UpdateCombat()`
1382 TBot(gPlayers
[i
]).Update();
1386 //e_WriteLog('***g_Player_UpdateAll: EXIT', MSG_WARNING);
1389 procedure g_Player_DrawAll();
1393 if gPlayers
= nil then Exit
;
1395 for i
:= 0 to High(gPlayers
) do
1396 if gPlayers
[i
] <> nil then
1397 if gPlayers
[i
] is TPlayer
then gPlayers
[i
].Draw()
1398 else TBot(gPlayers
[i
]).Draw();
1401 procedure g_Player_DrawDebug(p
: TPlayer
);
1405 if p
= nil then Exit
;
1406 if (@p
.FObj
) = nil then Exit
;
1408 e_TextureFontGetSize(gStdFont
, fW
, fH
);
1410 e_TextureFontPrint(0, 0 , 'Pos X: ' + IntToStr(p
.FObj
.X
), gStdFont
);
1411 e_TextureFontPrint(0, fH
, 'Pos Y: ' + IntToStr(p
.FObj
.Y
), gStdFont
);
1412 e_TextureFontPrint(0, fH
* 2, 'Vel X: ' + IntToStr(p
.FObj
.Vel
.X
), gStdFont
);
1413 e_TextureFontPrint(0, fH
* 3, 'Vel Y: ' + IntToStr(p
.FObj
.Vel
.Y
), gStdFont
);
1414 e_TextureFontPrint(0, fH
* 4, 'Acc X: ' + IntToStr(p
.FObj
.Accel
.X
), gStdFont
);
1415 e_TextureFontPrint(0, fH
* 5, 'Acc Y: ' + IntToStr(p
.FObj
.Accel
.Y
), gStdFont
);
1418 procedure g_Player_DrawHealth();
1423 if gPlayers
= nil then Exit
;
1424 e_TextureFontGetSize(gStdFont
, fW
, fH
);
1426 for i
:= 0 to High(gPlayers
) do
1427 if gPlayers
[i
] <> nil then
1429 e_TextureFontPrint(gPlayers
[i
].FObj
.X
+ gPlayers
[i
].FObj
.Rect
.X
,
1430 gPlayers
[i
].FObj
.Y
+ gPlayers
[i
].FObj
.Rect
.Y
+ gPlayers
[i
].FObj
.Rect
.Height
- fH
* 2,
1431 IntToStr(gPlayers
[i
].FHealth
), gStdFont
);
1432 e_TextureFontPrint(gPlayers
[i
].FObj
.X
+ gPlayers
[i
].FObj
.Rect
.X
,
1433 gPlayers
[i
].FObj
.Y
+ gPlayers
[i
].FObj
.Rect
.Y
+ gPlayers
[i
].FObj
.Rect
.Height
- fH
,
1434 IntToStr(gPlayers
[i
].FArmor
), gStdFont
);
1438 function g_Player_Get(UID
: Word): TPlayer
;
1444 if gPlayers
= nil then
1447 for a
:= 0 to High(gPlayers
) do
1448 if gPlayers
[a
] <> nil then
1449 if gPlayers
[a
].FUID
= UID
then
1451 Result
:= gPlayers
[a
];
1456 function g_Player_GetCount(): Byte;
1462 if gPlayers
= nil then
1465 for a
:= 0 to High(gPlayers
) do
1466 if gPlayers
[a
] <> nil then
1467 Result
:= Result
+ 1;
1470 function g_Player_GetStats(): TPlayerStatArray
;
1476 if gPlayers
= nil then Exit
;
1478 for a
:= 0 to High(gPlayers
) do
1479 if gPlayers
[a
] <> nil then
1481 SetLength(Result
, Length(Result
)+1);
1482 with Result
[High(Result
)] do
1485 Ping
:= gPlayers
[a
].FPing
;
1486 Loss
:= gPlayers
[a
].FLoss
;
1487 Name
:= gPlayers
[a
].FName
;
1488 Team
:= gPlayers
[a
].FTeam
;
1489 Frags
:= gPlayers
[a
].FFrags
;
1490 Deaths
:= gPlayers
[a
].FDeath
;
1491 Kills
:= gPlayers
[a
].FKills
;
1492 Color
:= gPlayers
[a
].FModel
.Color
;
1493 Lives
:= gPlayers
[a
].FLives
;
1494 Spectator
:= gPlayers
[a
].FSpectator
;
1499 procedure g_Player_ResetReady();
1503 if not g_Game_IsServer
then Exit
;
1504 if gPlayers
= nil then Exit
;
1506 for a
:= 0 to High(gPlayers
) do
1507 if gPlayers
[a
] <> nil then
1509 gPlayers
[a
].FReady
:= False;
1510 if g_Game_IsNet
then
1511 MH_SEND_GameEvent(NET_EV_INTER_READY
, gPlayers
[a
].UID
, 'N');
1515 procedure g_Player_RememberAll
;
1519 for i
:= Low(gPlayers
) to High(gPlayers
) do
1520 if (gPlayers
[i
] <> nil) and gPlayers
[i
].alive
then
1521 gPlayers
[i
].RememberState
;
1524 procedure g_Player_ResetAll(Force
, Silent
: Boolean);
1528 gTeamStat
[TEAM_RED
].Goals
:= 0;
1529 gTeamStat
[TEAM_BLUE
].Goals
:= 0;
1531 if gPlayers
<> nil then
1532 for i
:= 0 to High(gPlayers
) do
1533 if gPlayers
[i
] <> nil then
1535 gPlayers
[i
].Reset(Force
);
1537 if gPlayers
[i
] is TPlayer
then
1539 if (not gPlayers
[i
].FSpectator
) or gPlayers
[i
].FWantsInGame
then
1540 gPlayers
[i
].Respawn(Silent
)
1542 gPlayers
[i
].Spectate();
1545 TBot(gPlayers
[i
]).Respawn(Silent
);
1549 procedure g_Player_CreateCorpse(Player
: TPlayer
);
1555 if Player
.alive
then
1558 // Ðàçðûâàåì ñâÿçü ñ ïðåæíèì òðóïîì:
1559 if gCorpses
<> nil then
1560 for i
:= 0 to High(gCorpses
) do
1561 if gCorpses
[i
] <> nil then
1562 if gCorpses
[i
].FPlayerUID
= Player
.FUID
then
1563 gCorpses
[i
].FPlayerUID
:= 0;
1565 if Player
.FObj
.Y
>= gMapInfo
.Height
+128 then
1570 if (FHealth
>= -50) or (gGibsCount
= 0) then
1572 if (gCorpses
= nil) or (Length(gCorpses
) = 0) then
1576 for find_id
:= 0 to High(gCorpses
) do
1577 if gCorpses
[find_id
] = nil then
1584 find_id
:= Random(Length(gCorpses
));
1586 gCorpses
[find_id
] := TCorpse
.Create(FObj
.X
, FObj
.Y
, FModel
.Name
, FHealth
< -20);
1587 gCorpses
[find_id
].FColor
:= FModel
.Color
;
1588 gCorpses
[find_id
].FObj
.Vel
:= FObj
.Vel
;
1589 gCorpses
[find_id
].FObj
.Accel
:= FObj
.Accel
;
1590 gCorpses
[find_id
].FPlayerUID
:= FUID
;
1593 g_Player_CreateGibs(FObj
.X
+ PLAYER_RECT_CX
,
1594 FObj
.Y
+ PLAYER_RECT_CY
,
1595 FModel
.Name
, FModel
.Color
);
1599 procedure g_Player_CreateShell(fX
, fY
, dX
, dY
: Integer; T
: Byte);
1603 if (gShells
= nil) or (Length(gShells
) = 0) then
1606 with gShells
[CurrentShell
] do
1612 if T
= SHELL_BULLET
then
1614 if g_Texture_Get('TEXTURE_SHELL_BULLET', SID
) then
1618 Obj
.Rect
.Width
:= 4;
1619 Obj
.Rect
.Height
:= 2;
1623 if g_Texture_Get('TEXTURE_SHELL_SHELL', SID
) then
1627 Obj
.Rect
.Width
:= 7;
1628 Obj
.Rect
.Height
:= 3;
1634 g_Obj_Push(@Obj
, dX
+ Random(4)-Random(4), dY
-Random(4));
1635 positionChanged(); // this updates spatial accelerators
1636 RAngle
:= Random(360);
1637 Timeout
:= gTime
+ SHELL_TIMEOUT
;
1639 if CurrentShell
>= High(gShells
) then
1646 procedure g_Player_CreateGibs(fX
, fY
: Integer; ModelName
: string; fColor
: TRGB
);
1649 GibsArray
: TGibsArray
;
1652 if (gGibs
= nil) or (Length(gGibs
) = 0) then
1654 if not g_PlayerModel_GetGibs(ModelName
, GibsArray
) then
1656 Blood
:= g_PlayerModel_GetBlood(ModelName
);
1658 for a
:= 0 to High(GibsArray
) do
1659 with gGibs
[CurrentGib
] do
1662 ID
:= GibsArray
[a
].ID
;
1663 MaskID
:= GibsArray
[a
].MaskID
;
1666 Obj
.Rect
:= GibsArray
[a
].Rect
;
1667 Obj
.X
:= fX
-GibsArray
[a
].Rect
.X
-(GibsArray
[a
].Rect
.Width
div 2);
1668 Obj
.Y
:= fY
-GibsArray
[a
].Rect
.Y
-(GibsArray
[a
].Rect
.Height
div 2);
1669 g_Obj_PushA(@Obj
, 25 + Random(10), Random(361));
1670 positionChanged(); // this updates spatial accelerators
1671 RAngle
:= Random(360);
1673 if gBloodCount
> 0 then
1674 g_GFX_Blood(fX
, fY
, 16*gBloodCount
+Random(5*gBloodCount
), -16+Random(33), -16+Random(33),
1675 Random(48), Random(48), Blood
.R
, Blood
.G
, Blood
.B
, Blood
.Kind
);
1677 if CurrentGib
>= High(gGibs
) then
1684 procedure g_Player_UpdatePhysicalObjects();
1690 procedure ShellSound_Bounce(X
, Y
: Integer; T
: Byte);
1695 if T
= SHELL_BULLET
then
1696 g_Sound_PlayExAt('SOUND_PLAYER_CASING' + IntToStr(k
), X
, Y
)
1698 g_Sound_PlayExAt('SOUND_PLAYER_SHELL' + IntToStr(k
), X
, Y
);
1703 if gGibs
<> nil then
1704 for i
:= 0 to High(gGibs
) do
1705 if gGibs
[i
].alive
then
1709 mr
:= g_Obj_Move(@Obj
, True, False, True);
1710 positionChanged(); // this updates spatial accelerators
1712 if WordBool(mr
and MOVE_FALLOUT
) then
1718 // Îòëåòàåò îò óäàðà î ñòåíó/ïîòîëîê/ïîë:
1719 if WordBool(mr
and MOVE_HITWALL
) then
1720 Obj
.Vel
.X
:= -(vel
.X
div 2);
1721 if WordBool(mr
and (MOVE_HITCEIL
or MOVE_HITLAND
)) then
1722 Obj
.Vel
.Y
:= -(vel
.Y
div 2);
1724 if (Obj
.Vel
.X
>= 0) then
1726 RAngle
:= RAngle
+ Abs(Obj
.Vel
.X
)*6 + Abs(Obj
.Vel
.Y
);
1727 if RAngle
>= 360 then
1728 RAngle
:= RAngle
mod 360;
1729 end else begin // Counter-clockwise
1730 RAngle
:= RAngle
- Abs(Obj
.Vel
.X
)*6 - Abs(Obj
.Vel
.Y
);
1732 RAngle
:= (360 - (Abs(RAngle
) mod 360)) mod 360;
1735 // Ñîïðîòèâëåíèå âîçäóõà äëÿ êóñêà òðóïà:
1736 if gTime
mod (GAME_TICK
*3) = 0 then
1737 Obj
.Vel
.X
:= z_dec(Obj
.Vel
.X
, 1);
1741 if gCorpses
<> nil then
1742 for i
:= 0 to High(gCorpses
) do
1743 if gCorpses
[i
] <> nil then
1744 if gCorpses
[i
].State
= CORPSE_STATE_REMOVEME
then
1750 gCorpses
[i
].Update();
1753 if gShells
<> nil then
1754 for i
:= 0 to High(gShells
) do
1755 if gShells
[i
].alive
then
1759 mr
:= g_Obj_Move(@Obj
, True, False, True);
1760 positionChanged(); // this updates spatial accelerators
1762 if WordBool(mr
and MOVE_FALLOUT
) or (gShells
[i
].Timeout
< gTime
) then
1768 // Îòëåòàåò îò óäàðà î ñòåíó/ïîòîëîê/ïîë:
1769 if WordBool(mr
and MOVE_HITWALL
) then
1771 Obj
.Vel
.X
:= -(vel
.X
div 2);
1772 if not WordBool(mr
and MOVE_INWATER
) then
1773 ShellSound_Bounce(Obj
.X
, Obj
.Y
, SType
);
1775 if WordBool(mr
and (MOVE_HITCEIL
or MOVE_HITLAND
)) then
1777 Obj
.Vel
.Y
:= -(vel
.Y
div 2);
1778 if Obj
.Vel
.X
<> 0 then Obj
.Vel
.X
:= Obj
.Vel
.X
div 2;
1779 if (Obj
.Vel
.X
= 0) and (Obj
.Vel
.Y
= 0) then
1781 if RAngle
mod 90 <> 0 then
1782 RAngle
:= (RAngle
div 90) * 90;
1784 else if not WordBool(mr
and MOVE_INWATER
) then
1785 ShellSound_Bounce(Obj
.X
, Obj
.Y
, SType
);
1788 if (Obj
.Vel
.X
>= 0) then
1790 RAngle
:= RAngle
+ Abs(Obj
.Vel
.X
)*8 + Abs(Obj
.Vel
.Y
);
1791 if RAngle
>= 360 then
1792 RAngle
:= RAngle
mod 360;
1793 end else begin // Counter-clockwise
1794 RAngle
:= RAngle
- Abs(Obj
.Vel
.X
)*8 - Abs(Obj
.Vel
.Y
);
1796 RAngle
:= (360 - (Abs(RAngle
) mod 360)) mod 360;
1802 procedure TGib
.getMapBox (out x
, y
, w
, h
: Integer); inline;
1804 x
:= Obj
.X
+Obj
.Rect
.X
;
1805 y
:= Obj
.Y
+Obj
.Rect
.Y
;
1806 w
:= Obj
.Rect
.Width
;
1807 h
:= Obj
.Rect
.Height
;
1810 procedure TGib
.moveBy (dx
, dy
: Integer); inline;
1812 if (dx
<> 0) or (dy
<> 0) then
1821 procedure TShell
.getMapBox (out x
, y
, w
, h
: Integer); inline;
1825 w
:= Obj
.Rect
.Width
;
1826 h
:= Obj
.Rect
.Height
;
1829 procedure TShell
.moveBy (dx
, dy
: Integer); inline;
1831 if (dx
<> 0) or (dy
<> 0) then
1840 procedure TGib
.positionChanged (); inline; begin end;
1841 procedure TShell
.positionChanged (); inline; begin end;
1844 procedure g_Player_DrawCorpses();
1849 if gGibs
<> nil then
1850 for i
:= 0 to High(gGibs
) do
1851 if gGibs
[i
].alive
then
1854 if not g_Obj_Collide(sX
, sY
, sWidth
, sHeight
, @Obj
) then
1857 a
.X
:= Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2);
1858 a
.y
:= Obj
.Rect
.Y
+(Obj
.Rect
.Height
div 2);
1860 e_DrawAdv(ID
, Obj
.X
, Obj
.Y
, 0, True, False, RAngle
, @a
, TMirrorType
.None
);
1863 e_DrawAdv(MaskID
, Obj
.X
, Obj
.Y
, 0, True, False, RAngle
, @a
, TMirrorType
.None
);
1869 if gCorpses
<> nil then
1870 for i
:= 0 to High(gCorpses
) do
1871 if gCorpses
[i
] <> nil then
1875 procedure g_Player_DrawShells();
1880 if gShells
<> nil then
1881 for i
:= 0 to High(gShells
) do
1882 if gShells
[i
].alive
then
1885 if not g_Obj_Collide(sX
, sY
, sWidth
, sHeight
, @Obj
) then
1891 e_DrawAdv(SpriteID
, Obj
.X
, Obj
.Y
, 0, True, False, RAngle
, @a
, TMirrorType
.None
);
1895 procedure g_Player_RemoveAllCorpses();
1901 SetLength(gGibs
, MaxGibs
);
1902 SetLength(gShells
, MaxGibs
);
1906 if gCorpses
<> nil then
1907 for i
:= 0 to High(gCorpses
) do
1911 SetLength(gCorpses
, MaxCorpses
);
1914 procedure g_Player_Corpses_SaveState (st
: TStream
);
1918 // Ñ÷èòàåì êîëè÷åñòâî ñóùåñòâóþùèõ òðóïîâ
1920 for i
:= 0 to High(gCorpses
) do if (gCorpses
[i
] <> nil) then Inc(count
);
1922 // Êîëè÷åñòâî òðóïîâ
1923 utils
.writeInt(st
, LongInt(count
));
1925 if (count
= 0) then exit
;
1928 for i
:= 0 to High(gCorpses
) do
1930 if gCorpses
[i
] <> nil then
1933 utils
.writeStr(st
, gCorpses
[i
].FModelName
);
1935 utils
.writeBool(st
, gCorpses
[i
].Mess
);
1936 // Ñîõðàíÿåì äàííûå òðóïà:
1937 gCorpses
[i
].SaveState(st
);
1943 procedure g_Player_Corpses_LoadState (st
: TStream
);
1951 g_Player_RemoveAllCorpses();
1953 // Êîëè÷åñòâî òðóïîâ:
1954 count
:= utils
.readLongInt(st
);
1955 if (count
< 0) or (count
> Length(gCorpses
)) then raise XStreamError
.Create('invalid number of corpses');
1957 if (count
= 0) then exit
;
1960 for i
:= 0 to count
-1 do
1963 str
:= utils
.readStr(st
);
1965 b
:= utils
.readBool(st
);
1967 gCorpses
[i
] := TCorpse
.Create(0, 0, str
, b
);
1968 // Çàãðóæàåì äàííûå òðóïà
1969 gCorpses
[i
].LoadState(st
);
1976 function TPlayer
.isValidViewPort (): Boolean; inline; begin result
:= (viewPortW
> 0) and (viewPortH
> 0); end;
1978 procedure TPlayer
.BFGHit();
1980 g_Weapon_BFGHit(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
1981 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2));
1982 if g_Game_IsServer
and g_Game_IsNet
then
1983 MH_SEND_Effect(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
1984 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2),
1988 procedure TPlayer
.ChangeModel(ModelName
: string);
1990 locModel
: TPlayerModel
;
1992 locModel
:= g_PlayerModel_Get(ModelName
);
1993 if locModel
= nil then Exit
;
1999 procedure TPlayer
.SetModel(ModelName
: string);
2003 m
:= g_PlayerModel_Get(ModelName
);
2006 g_SimpleError(Format(_lc
[I_GAME_ERROR_MODEL_FALLBACK
], [ModelName
]));
2007 m
:= g_PlayerModel_Get('doomer');
2010 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], ['doomer']));
2015 if FModel
<> nil then
2020 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
2021 FModel
.Color
:= FColor
2023 FModel
.Color
:= TEAMCOLOR
[FTeam
];
2024 FModel
.SetWeapon(FCurrWeap
);
2025 FModel
.SetFlag(FFlag
);
2026 SetDirection(FDirection
);
2029 procedure TPlayer
.SetColor(Color
: TRGB
);
2032 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
2033 if FModel
<> nil then FModel
.Color
:= Color
;
2036 procedure TPlayer
.SwitchTeam
;
2038 if g_Game_IsClient
then
2040 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then Exit
;
2042 if gGameOn
and FAlive
then
2043 Kill(K_SIMPLEKILL
, FUID
, HIT_SELF
);
2045 if FTeam
= TEAM_RED
then
2047 ChangeTeam(TEAM_BLUE
);
2048 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_BLUE
], [FName
]), True);
2049 if g_Game_IsNet
then
2050 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM
, TEAM_BLUE
, FName
);
2054 ChangeTeam(TEAM_RED
);
2055 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_RED
], [FName
]), True);
2056 if g_Game_IsNet
then
2057 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM
, TEAM_RED
, FName
);
2059 FPreferredTeam
:= FTeam
;
2062 procedure TPlayer
.ChangeTeam(Team
: Byte);
2069 TEAM_RED
, TEAM_BLUE
:
2070 FModel
.Color
:= TEAMCOLOR
[Team
];
2072 FModel
.Color
:= FColor
;
2074 if (FTeam
<> OldTeam
) and g_Game_IsNet
and g_Game_IsServer
then
2075 MH_SEND_PlayerStats(FUID
);
2079 procedure TPlayer.CollideItem();
2084 if gItems = nil then Exit;
2085 if not FAlive then Exit;
2087 for i := 0 to High(gItems) do
2090 if (ItemType <> ITEM_NONE) and alive then
2091 if g_Obj_Collide(FObj.X+PLAYER_RECT.X, FObj.Y+PLAYER_RECT.Y, PLAYER_RECT.Width,
2092 PLAYER_RECT.Height, @Obj) then
2094 if not PickItem(ItemType, gItems[i].Respawnable, r) then Continue;
2096 if ItemType in [ITEM_SPHERE_BLUE, ITEM_SPHERE_WHITE, ITEM_INVUL] then
2097 g_Sound_PlayExAt('SOUND_ITEM_GETRULEZ', FObj.X, FObj.Y)
2098 else if ItemType in [ITEM_MEDKIT_SMALL, ITEM_MEDKIT_LARGE, ITEM_MEDKIT_BLACK] then
2099 g_Sound_PlayExAt('SOUND_ITEM_GETMED', FObj.X, FObj.Y)
2100 else g_Sound_PlayExAt('SOUND_ITEM_GETITEM', FObj.X, FObj.Y);
2102 // Íàäî óáðàòü ñ êàðòû, åñëè ýòî íå êëþ÷, êîòîðûì íóæíî ïîäåëèòñÿ ñ äðóãèì èãðîêîì:
2103 if r and not ((ItemType in [ITEM_KEY_RED, ITEM_KEY_GREEN, ITEM_KEY_BLUE]) and
2104 (gGameSettings.GameType = GT_SINGLE) and
2105 (g_Player_GetCount() > 1)) then
2106 if not Respawnable then g_Items_Remove(i) else g_Items_Pick(i);
2112 function TPlayer
.CollideLevel(XInc
, YInc
: Integer): Boolean;
2114 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
2115 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_WALL
,
2119 constructor TPlayer
.Create();
2125 mEDamageType
:= HIT_SOME
;
2131 FSawSound
:= TPlayableSound
.Create();
2132 FSawSoundIdle
:= TPlayableSound
.Create();
2133 FSawSoundHit
:= TPlayableSound
.Create();
2134 FSawSoundSelect
:= TPlayableSound
.Create();
2135 FFlameSoundOn
:= TPlayableSound
.Create();
2136 FFlameSoundOff
:= TPlayableSound
.Create();
2137 FFlameSoundWork
:= TPlayableSound
.Create();
2138 FJetSoundFly
:= TPlayableSound
.Create();
2139 FJetSoundOn
:= TPlayableSound
.Create();
2140 FJetSoundOff
:= TPlayableSound
.Create();
2142 FSawSound
.SetByName('SOUND_WEAPON_FIRESAW');
2143 FSawSoundIdle
.SetByName('SOUND_WEAPON_IDLESAW');
2144 FSawSoundHit
.SetByName('SOUND_WEAPON_HITSAW');
2145 FSawSoundSelect
.SetByName('SOUND_WEAPON_SELECTSAW');
2146 FFlameSoundOn
.SetByName('SOUND_WEAPON_FLAMEON');
2147 FFlameSoundOff
.SetByName('SOUND_WEAPON_FLAMEOFF');
2148 FFlameSoundWork
.SetByName('SOUND_WEAPON_FLAMEWORK');
2149 FJetSoundFly
.SetByName('SOUND_PLAYER_JETFLY');
2150 FJetSoundOn
.SetByName('SOUND_PLAYER_JETON');
2151 FJetSoundOff
.SetByName('SOUND_PLAYER_JETOFF');
2153 FSpectatePlayer
:= -1;
2157 FSavedState
.WaitRecall
:= False;
2164 FActualModelName
:= 'doomer';
2167 FObj
.Rect
:= PLAYER_RECT
;
2169 FBFGFireCounter
:= -1;
2170 FJustTeleported
:= False;
2176 procedure TPlayer
.positionChanged (); inline;
2180 procedure TPlayer
.doDamage (v
: Integer);
2182 if (v
<= 0) then exit
;
2183 if (v
> 32767) then v
:= 32767;
2184 Damage(v
, 0, 0, 0, mEDamageType
);
2187 procedure TPlayer
.Damage(value
: Word; SpawnerUID
: Word; vx
, vy
: Integer; t
: Byte);
2191 if (not g_Game_IsClient
) and (not FAlive
) then
2196 // Íåóÿçâèìîñòü íå ñïàñàåò îò ëîâóøåê:
2197 if ((t
= HIT_TRAP
) or (t
= HIT_SELF
)) and (not FGodMode
) then
2199 if not g_Game_IsClient
then
2202 if t
= HIT_TRAP
then
2204 // Ëîâóøêà óáèâàåò ñðàçó:
2206 Kill(K_EXTRAHARDKILL
, SpawnerUID
, t
);
2208 if t
= HIT_SELF
then
2212 Kill(K_SIMPLEKILL
, SpawnerUID
, t
);
2215 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
2216 FMegaRulez
[MR_SUIT
] := 0;
2217 FMegaRulez
[MR_INVUL
] := 0;
2218 FMegaRulez
[MR_INVIS
] := 0;
2222 // Íî îò îñòàëüíîãî ñïàñàåò:
2223 if FMegaRulez
[MR_INVUL
] >= gTime
then
2230 // Åñëè åñòü óðîí ñâîèì, èëè ðàíèë ñàì ñåáÿ, èëè òåáÿ ðàíèë ïðîòèâíèê:
2231 if LongBool(gGameSettings
.Options
and GAME_OPTION_TEAMDAMAGE
) or
2232 (SpawnerUID
= FUID
) or
2233 (not SameTeam(FUID
, SpawnerUID
)) then
2235 FLastSpawnerUID
:= SpawnerUID
;
2237 // Êðîâü (ïóçûðüêè, åñëè â âîäå):
2238 if gBloodCount
> 0 then
2240 c
:= Min(value
, 200)*gBloodCount
+ Random(Min(value
, 200) div 2);
2241 if value
div 4 <= c
then
2242 c
:= c
- (value
div 4)
2246 if (t
= HIT_SOME
) and (vx
= 0) and (vy
= 0) then
2250 HIT_TRAP
, HIT_ACID
, HIT_FLAME
, HIT_SELF
: MakeBloodSimple(c
);
2251 HIT_BFG
, HIT_ROCKET
, HIT_SOME
: MakeBloodVector(c
, vx
, vy
);
2254 if t
= HIT_WATER
then
2255 g_GFX_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
2256 FObj
.Y
+PLAYER_RECT
.Y
-4, value
div 2, 8, 4);
2261 Inc(FDamageBuffer
, value
);
2265 FPain
:= FPain
+ value
;
2268 if g_Game_IsServer
and g_Game_IsNet
then
2270 MH_SEND_PlayerDamage(FUID
, t
, SpawnerUID
, value
, vx
, vy
);
2271 MH_SEND_PlayerStats(FUID
);
2272 MH_SEND_PlayerPos(False, FUID
);
2276 function TPlayer
.Heal(value
: Word; Soft
: Boolean): Boolean;
2279 if g_Game_IsClient
then
2284 if Soft
and (FHealth
< PLAYER_HP_SOFT
) then
2286 IncMax(FHealth
, value
, PLAYER_HP_SOFT
);
2289 if (not Soft
) and (FHealth
< PLAYER_HP_LIMIT
) then
2291 IncMax(FHealth
, value
, PLAYER_HP_LIMIT
);
2295 if Result
and g_Game_IsServer
and g_Game_IsNet
then
2296 MH_SEND_PlayerStats(FUID
);
2299 destructor TPlayer
.Destroy();
2301 if (gPlayer1
<> nil) and (gPlayer1
.FUID
= FUID
) then
2303 if (gPlayer2
<> nil) and (gPlayer2
.FUID
= FUID
) then
2307 FSawSoundIdle
.Free();
2308 FSawSoundHit
.Free();
2309 FSawSoundSelect
.Free();
2310 FFlameSoundOn
.Free();
2311 FFlameSoundOff
.Free();
2312 FFlameSoundWork
.Free();
2313 FJetSoundFly
.Free();
2315 FJetSoundOff
.Free();
2317 if FPunchAnim
<> nil then
2323 procedure TPlayer
.DrawIndicator();
2325 indX
, indY
: Integer;
2331 indX
:= FObj
.X
+FObj
.Rect
.X
;
2333 if g_Texture_Get('TEXTURE_PLAYER_INDICATOR', ID
) then
2335 e_GetTextureSize(ID
, @indW
, @indH
);
2336 e_Draw(ID
, indX
+ indW
div 2, indY
- indH
, 0, True, False);
2339 //e_TextureFontPrint(indX, indY, FName, gStdFont); // Shows player name overhead
2342 procedure TPlayer
.DrawBubble();
2344 bubX
, bubY
: Integer;
2347 Rw
, Gw
, Bw
: SmallInt;
2350 bubX
:= FObj
.X
+FObj
.Rect
.X
+ IfThen(FDirection
= TDirection
.D_LEFT
, -4, 18);
2351 bubY
:= FObj
.Y
+FObj
.Rect
.Y
- 18;
2359 1: // simple textual non-bubble
2361 bubX
:= FObj
.X
+FObj
.Rect
.X
- 11;
2362 bubY
:= FObj
.Y
+FObj
.Rect
.Y
- 17;
2363 e_TextureFontPrint(bubX
, bubY
, '[...]', gStdFont
);
2366 2: // advanced pixel-perfect bubble
2368 if FTeam
= TEAM_RED
then
2371 if FTeam
= TEAM_BLUE
then
2374 3: // colored bubble
2376 Rb
:= FModel
.Color
.R
;
2377 Gb
:= FModel
.Color
.G
;
2378 Bb
:= FModel
.Color
.B
;
2379 Rw
:= Min(Rb
* 2 + 64, 255);
2380 Gw
:= Min(Gb
* 2 + 64, 255);
2381 Bw
:= Min(Bb
* 2 + 64, 255);
2382 if (Abs(Rw
- Rb
) < 32)
2383 or (Abs(Gw
- Gb
) < 32)
2384 or (Abs(Bw
- Bb
) < 32) then
2386 Rb
:= Max(Rw
div 2 - 16, 0);
2387 Gb
:= Max(Gw
div 2 - 16, 0);
2388 Bb
:= Max(Bw
div 2 - 16, 0);
2391 4: // custom textured bubble
2393 if g_Texture_Get('TEXTURE_PLAYER_TALKBUBBLE', ID
) then
2394 if FDirection
= TDirection
.D_RIGHT
then
2395 e_Draw(ID
, bubX
- 6, bubY
- 7, 0, True, False)
2397 e_Draw(ID
, bubX
- 6, bubY
- 7, 0, True, False, TMirrorType
.Horizontal
);
2403 e_DrawQuad(bubX
+ 1, bubY
, bubX
+ 18, bubY
+ 13, Rb
, Gb
, Bb
);
2404 e_DrawQuad(bubX
, bubY
+ 1, bubX
+ 19, bubY
+ 12, Rb
, Gb
, Bb
);
2406 e_DrawFillQuad(bubX
+ 1, bubY
+ 1, bubX
+ 18, bubY
+ 12, Rw
, Gw
, Bw
, 0);
2409 Dot
:= IfThen(FDirection
= TDirection
.D_LEFT
, 14, 5);
2410 e_DrawLine(1, bubX
+ Dot
, bubY
+ 14, bubX
+ Dot
, bubY
+ 16, Rb
, Gb
, Bb
);
2411 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
);
2412 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
);
2413 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
);
2414 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
);
2418 e_DrawFillQuad(bubX
+ Dot
, bubY
+ 8, bubX
+ Dot
+ 1, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2419 e_DrawFillQuad(bubX
+ Dot
+ 3, bubY
+ 8, bubX
+ Dot
+ 4, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2420 e_DrawFillQuad(bubX
+ Dot
+ 6, bubY
+ 8, bubX
+ Dot
+ 7, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2423 procedure TPlayer
.Draw();
2428 Mirror
: TMirrorType
;
2432 if Direction
= TDirection
.D_RIGHT
then
2433 Mirror
:= TMirrorType
.None
2435 Mirror
:= TMirrorType
.Horizontal
;
2437 if FPunchAnim
<> nil then
2439 FPunchAnim
.Draw(FObj
.X
+IfThen(Direction
= TDirection
.D_LEFT
, 15-FObj
.Rect
.X
, FObj
.Rect
.X
-15),
2440 FObj
.Y
+FObj
.Rect
.Y
-11, Mirror
);
2441 if FPunchAnim
.played
then
2448 if (FMegaRulez
[MR_INVUL
] > gTime
) and (gPlayerDrawn
<> Self
) then
2449 if g_Texture_Get('TEXTURE_PLAYER_INVULPENTA', ID
) then
2451 e_GetTextureSize(ID
, @w
, @h
);
2452 if FDirection
= TDirection
.D_LEFT
then
2453 e_Draw(ID
, FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2)-(w
div 2)+4,
2454 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2)-(h
div 2)-7+FObj
.slopeUpLeft
, 0, True, False)
2456 e_Draw(ID
, FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2)-(w
div 2)-2,
2457 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2)-(h
div 2)-7+FObj
.slopeUpLeft
, 0, True, False);
2460 if FMegaRulez
[MR_INVIS
] > gTime
then
2462 if (gPlayerDrawn
<> nil) and ((Self
= gPlayerDrawn
) or
2463 ((FTeam
= gPlayerDrawn
.Team
) and (gGameSettings
.GameMode
<> GM_DM
))) then
2465 if (FMegaRulez
[MR_INVIS
] - gTime
) <= 2100 then
2466 dr
:= not Odd((FMegaRulez
[MR_INVIS
] - gTime
) div 300)
2470 FModel
.Draw(FObj
.X
, FObj
.Y
+FObj
.slopeUpLeft
, 200)
2472 FModel
.Draw(FObj
.X
, FObj
.Y
+FObj
.slopeUpLeft
);
2475 FModel
.Draw(FObj
.X
, FObj
.Y
+FObj
.slopeUpLeft
, 254);
2478 FModel
.Draw(FObj
.X
, FObj
.Y
+FObj
.slopeUpLeft
);
2481 if g_debug_Frames
then
2483 e_DrawQuad(FObj
.X
+FObj
.Rect
.X
,
2485 FObj
.X
+FObj
.Rect
.X
+FObj
.Rect
.Width
-1,
2486 FObj
.Y
+FObj
.Rect
.Y
+FObj
.Rect
.Height
-1,
2490 if (gChatBubble
> 0) and (FKeys
[KEY_CHAT
].Pressed
) and not FGhost
then
2491 if (FMegaRulez
[MR_INVIS
] <= gTime
) or ((gPlayerDrawn
<> nil) and ((Self
= gPlayerDrawn
) or
2492 ((FTeam
= gPlayerDrawn
.Team
) and (gGameSettings
.GameMode
<> GM_DM
)))) then
2494 // e_DrawPoint(5, 335, 288, 255, 0, 0); // DL, UR, DL, UR
2495 if gAimLine
and alive
and
2496 ((Self
= gPlayer1
) or (Self
= gPlayer2
)) then
2501 procedure TPlayer
.DrawAim();
2502 procedure drawCast (sz
: Integer; ax0
, ay0
, ax1
, ay1
: Integer);
2507 {$IFDEF ENABLE_HOLMES}
2508 if isValidViewPort
and (self
= gPlayer1
) then
2510 g_Holmes_plrLaser(ax0
, ay0
, ax1
, ay1
);
2514 e_DrawLine(sz
, ax0
, ay0
, ax1
, ay1
, 255, 0, 0, 96);
2515 if (g_Map_traceToNearestWall(ax0
, ay0
, ax1
, ay1
, @ex
, @ey
) <> nil) then
2517 e_DrawLine(sz
, ax0
, ay0
, ex
, ey
, 0, 255, 0, 96);
2521 e_DrawLine(sz
, ax0
, ay0
, ex
, ey
, 0, 0, 255, 96);
2526 wx
, wy
, xx
, yy
: Integer;
2530 wx
:= FObj
.X
+ WEAPONPOINT
[FDirection
].X
+ IfThen(FDirection
= TDirection
.D_LEFT
, 7, -7);
2531 wy
:= FObj
.Y
+ WEAPONPOINT
[FDirection
].Y
;
2540 1: begin // Chainsaw
2547 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2548 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2549 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2550 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2555 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2556 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2557 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2558 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2560 4: begin // Double Shotgun
2563 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2564 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2565 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2566 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2568 5: begin // Chaingun
2571 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2572 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2573 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2574 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2576 6: begin // Rocket Launcher
2579 if angle
= ANGLE_RIGHTUP
then Inc(angle
, 2);
2580 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2581 if angle
= ANGLE_LEFTUP
then Dec(angle
, 2);
2582 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2584 7: begin // Plasmagun
2587 if angle
= ANGLE_RIGHTUP
then Inc(angle
);
2588 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 3);
2589 if angle
= ANGLE_LEFTUP
then Dec(angle
);
2590 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 3);
2595 if angle
= ANGLE_RIGHTUP
then Inc(angle
, 1);
2596 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 2);
2597 if angle
= ANGLE_LEFTUP
then Dec(angle
, 1);
2598 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 2);
2600 9: begin // Super Chaingun
2603 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2604 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2605 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2606 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2609 xx
:= Trunc(Cos(-DegToRad(angle
)) * len
) + wx
;
2610 yy
:= Trunc(Sin(-DegToRad(angle
)) * len
) + wy
;
2611 {$IF DEFINED(D2F_DEBUG)}
2612 drawCast(sz
, wx
, wy
, xx
, yy
);
2614 e_DrawLine(sz
, wx
, wy
, xx
, yy
, 255, 0, 0, 96);
2618 procedure TPlayer
.DrawGUI();
2621 X
, Y
, SY
, a
, p
, m
: Integer;
2625 stat
: TPlayerStatArray
;
2627 X
:= gPlayerScreenSize
.X
;
2628 SY
:= gPlayerScreenSize
.Y
;
2631 if gShowGoals
and (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
2633 if gGameSettings
.GameMode
= GM_CTF
then
2637 if gGameSettings
.GameMode
= GM_CTF
then
2639 s
:= 'TEXTURE_PLAYER_REDFLAG';
2640 if gFlags
[FLAG_RED
].State
= FLAG_STATE_CAPTURED
then
2641 s
:= 'TEXTURE_PLAYER_REDFLAG_S';
2642 if gFlags
[FLAG_RED
].State
= FLAG_STATE_DROPPED
then
2643 s
:= 'TEXTURE_PLAYER_REDFLAG_D';
2644 if g_Texture_Get(s
, ID
) then
2645 e_Draw(ID
, X
-16-32, 240-72-4, 0, True, False);
2648 s
:= IntToStr(gTeamStat
[TEAM_RED
].Goals
);
2649 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2650 e_CharFont_PrintEx(gMenuFont
, X
-16-a
-tw
, 240-72-4, s
, TEAMCOLOR
[TEAM_RED
]);
2652 if gGameSettings
.GameMode
= GM_CTF
then
2654 s
:= 'TEXTURE_PLAYER_BLUEFLAG';
2655 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_CAPTURED
then
2656 s
:= 'TEXTURE_PLAYER_BLUEFLAG_S';
2657 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_DROPPED
then
2658 s
:= 'TEXTURE_PLAYER_BLUEFLAG_D';
2659 if g_Texture_Get(s
, ID
) then
2660 e_Draw(ID
, X
-16-32, 240-32-4, 0, True, False);
2663 s
:= IntToStr(gTeamStat
[TEAM_BLUE
].Goals
);
2664 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2665 e_CharFont_PrintEx(gMenuFont
, X
-16-a
-tw
, 240-32-4, s
, TEAMCOLOR
[TEAM_BLUE
]);
2668 if g_Texture_Get('TEXTURE_PLAYER_HUDBG', ID
) then
2669 e_DrawFill(ID
, X
, 0, 1, (gPlayerScreenSize
.Y
div 256)+IfThen(gPlayerScreenSize
.Y
mod 256 > 0, 1, 0),
2672 if g_Texture_Get('TEXTURE_PLAYER_HUD', ID
) then
2673 e_Draw(ID
, X
+2, Y
, 0, True, False);
2675 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
2679 s
:= IntToStr(Frags
);
2680 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2681 e_CharFont_PrintEx(gMenuFont
, X
-16-tw
, Y
, s
, _RGB(255, 0, 0));
2686 stat
:= g_Player_GetStats();
2691 for a
:= 0 to High(stat
) do
2692 if stat
[a
].Name
<> Name
then
2694 if stat
[a
].Frags
> m
then m
:= stat
[a
].Frags
;
2695 if stat
[a
].Frags
> Frags
then p
:= p
+1;
2699 s
:= IntToStr(p
)+' / '+IntToStr(Length(stat
))+' ';
2700 if Frags
>= m
then s
:= s
+'+' else s
:= s
+'-';
2701 s
:= s
+IntToStr(Abs(Frags
-m
));
2703 e_CharFont_GetSize(gMenuSmallFont
, s
, tw
, th
);
2704 e_CharFont_PrintEx(gMenuSmallFont
, X
-16-tw
, Y
+32, s
, _RGB(255, 0, 0));
2707 if gShowLives
and (gGameSettings
.MaxLives
> 0) then
2709 s
:= IntToStr(Lives
);
2710 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2711 e_CharFont_PrintEx(gMenuFont
, X
-16-tw
, SY
-32, s
, _RGB(0, 255, 0));
2715 e_CharFont_GetSize(gMenuSmallFont
, FName
, tw
, th
);
2716 e_CharFont_PrintEx(gMenuSmallFont
, X
+98-(tw
div 2), Y
+8, FName
, _RGB(255, 0, 0));
2718 if R_BERSERK
in FRulez
then
2719 e_Draw(gItemsTexturesID
[ITEM_MEDKIT_BLACK
], X
+37, Y
+45, 0, True, False)
2721 e_Draw(gItemsTexturesID
[ITEM_MEDKIT_LARGE
], X
+37, Y
+45, 0, True, False);
2723 if g_Texture_Get('TEXTURE_PLAYER_ARMORHUD', ID
) then
2724 e_Draw(ID
, X
+36, Y
+77, 0, True, False);
2726 s
:= IntToStr(IfThen(FHealth
> 0, FHealth
, 0));
2727 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2728 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+40, s
, _RGB(255, 0, 0));
2730 s
:= IntToStr(FArmor
);
2731 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2732 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+68, s
, _RGB(255, 0, 0));
2734 s
:= IntToStr(GetAmmoByWeapon(FCurrWeap
));
2740 ID
:= gItemsTexturesID
[ITEM_WEAPON_KASTET
];
2745 ID
:= gItemsTexturesID
[ITEM_WEAPON_SAW
];
2747 WEAPON_PISTOL
: ID
:= gItemsTexturesID
[ITEM_WEAPON_PISTOL
];
2748 WEAPON_CHAINGUN
: ID
:= gItemsTexturesID
[ITEM_WEAPON_CHAINGUN
];
2749 WEAPON_SHOTGUN1
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SHOTGUN1
];
2750 WEAPON_SHOTGUN2
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SHOTGUN2
];
2751 WEAPON_SUPERPULEMET
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SUPERPULEMET
];
2752 WEAPON_ROCKETLAUNCHER
: ID
:= gItemsTexturesID
[ITEM_WEAPON_ROCKETLAUNCHER
];
2753 WEAPON_PLASMA
: ID
:= gItemsTexturesID
[ITEM_WEAPON_PLASMA
];
2754 WEAPON_BFG
: ID
:= gItemsTexturesID
[ITEM_WEAPON_BFG
];
2755 WEAPON_FLAMETHROWER
: ID
:= gItemsTexturesID
[ITEM_WEAPON_FLAMETHROWER
];
2758 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2759 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+158, s
, _RGB(255, 0, 0));
2760 e_Draw(ID
, X
+20, Y
+160, 0, True, False);
2762 if R_KEY_RED
in FRulez
then
2763 e_Draw(gItemsTexturesID
[ITEM_KEY_RED
], X
+78, Y
+214, 0, True, False);
2765 if R_KEY_GREEN
in FRulez
then
2766 e_Draw(gItemsTexturesID
[ITEM_KEY_GREEN
], X
+95, Y
+214, 0, True, False);
2768 if R_KEY_BLUE
in FRulez
then
2769 e_Draw(gItemsTexturesID
[ITEM_KEY_BLUE
], X
+112, Y
+214, 0, True, False);
2771 if FJetFuel
> 0 then
2773 if g_Texture_Get('TEXTURE_PLAYER_HUDAIR', ID
) then
2774 e_Draw(ID
, X
+2, Y
+116, 0, True, False);
2775 if g_Texture_Get('TEXTURE_PLAYER_HUDJET', ID
) then
2776 e_Draw(ID
, X
+2, Y
+126, 0, True, False);
2777 e_DrawLine(4, X
+16, Y
+122, X
+16+Trunc(168*IfThen(FAir
> 0, FAir
, 0)/AIR_MAX
), Y
+122, 0, 0, 196);
2778 e_DrawLine(4, X
+16, Y
+132, X
+16+Trunc(168*FJetFuel
/JET_MAX
), Y
+132, 208, 0, 0);
2782 if g_Texture_Get('TEXTURE_PLAYER_HUDAIR', ID
) then
2783 e_Draw(ID
, X
+2, Y
+124, 0, True, False);
2784 e_DrawLine(4, X
+16, Y
+130, X
+16+Trunc(168*IfThen(FAir
> 0, FAir
, 0)/AIR_MAX
), Y
+130, 0, 0, 196);
2787 if gShowPing
and g_Game_IsClient
then
2789 s
:= _lc
[I_GAME_PING_HUD
] + IntToStr(NetPeer
.lastRoundTripTime
) + _lc
[I_NET_SLIST_PING_MS
];
2790 e_TextureFontPrint(X
+ 4, Y
+ 242, s
, gStdFont
);
2796 e_TextureFontPrint(X
+ 4, Y
+ 242, _lc
[I_PLAYER_SPECT
], gStdFont
);
2797 e_TextureFontPrint(X
+ 4, Y
+ 258, _lc
[I_PLAYER_SPECT2
], gStdFont
);
2798 e_TextureFontPrint(X
+ 4, Y
+ 274, _lc
[I_PLAYER_SPECT1
], gStdFont
);
2801 e_TextureFontGetSize(gStdFont
, cw
, ch
);
2802 s
:= _lc
[I_PLAYER_SPECT4
];
2803 e_TextureFontPrintEx(gScreenWidth
div 2 - cw
*(Length(s
) div 2),
2804 gScreenHeight
-4-ch
, s
, gStdFont
, 255, 255, 255, 1, True);
2805 e_TextureFontPrint(X
+ 4, Y
+ 290, _lc
[I_PLAYER_SPECT1S
], gStdFont
);
2811 procedure TPlayer
.DrawRulez();
2815 // Ïðè âçÿòèè íåóÿçâèìîñòè ðèñóåòñÿ èíâåðñèîííûé áåëûé ôîí
2816 if FMegaRulez
[MR_INVUL
] >= gTime
then
2818 if (FMegaRulez
[MR_INVUL
]-gTime
) <= 2100 then
2819 dr
:= not Odd((FMegaRulez
[MR_INVUL
]-gTime
) div 300)
2824 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2825 191, 191, 191, 0, TBlending
.Invert
);
2828 // Ïðè âçÿòèè çàùèòíîãî êîñòþìà ðèñóåòñÿ çåëåíîâàòûé ôîí
2829 if FMegaRulez
[MR_SUIT
] >= gTime
then
2831 if (FMegaRulez
[MR_SUIT
]-gTime
) <= 2100 then
2832 dr
:= not Odd((FMegaRulez
[MR_SUIT
]-gTime
) div 300)
2837 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2838 0, 96, 0, 200, TBlending
.None
);
2841 // Ïðè âçÿòèè áåðñåðêà ðèñóåòñÿ êðàñíîâàòûé ôîí
2842 if (FBerserk
>= 0) and (LongWord(FBerserk
) >= gTime
) and (gFlash
= 2) then
2844 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2845 255, 0, 0, 200, TBlending
.None
);
2849 procedure TPlayer
.DrawPain();
2853 if FPain
= 0 then Exit
;
2857 if a
< 15 then h
:= 0
2858 else if a
< 35 then h
:= 1
2859 else if a
< 55 then h
:= 2
2860 else if a
< 75 then h
:= 3
2861 else if a
< 95 then h
:= 4
2864 //if a > 255 then a := 255;
2866 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1, 255, 0, 0, 255-h
*50);
2867 //e_DrawFillQuad(0, 0, gPlayerScreenSize.X-1, gPlayerScreenSize.Y-1, 255-min(128, a), 255-a, 255-a, 0, B_FILTER);
2870 procedure TPlayer
.DrawPickup();
2874 if FPickup
= 0 then Exit
;
2878 if a
< 15 then h
:= 1
2879 else if a
< 35 then h
:= 2
2880 else if a
< 55 then h
:= 3
2881 else if a
< 75 then h
:= 4
2884 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1, 150, 200, 150, 255-h
*50);
2887 procedure TPlayer
.DoPunch();
2892 if FPunchAnim
<> nil then begin
2897 st
:= 'FRAMES_PUNCH';
2898 if R_BERSERK
in FRulez
then
2899 st
:= st
+ '_BERSERK';
2900 if FKeys
[KEY_UP
].Pressed
then
2902 else if FKeys
[KEY_DOWN
].Pressed
then
2904 g_Frames_Get(id
, st
);
2905 FPunchAnim
:= TAnimation
.Create(id
, False, 1);
2908 procedure TPlayer
.Fire();
2910 f
, DidFire
: Boolean;
2911 wx
, wy
, xd
, yd
: Integer;
2914 if g_Game_IsClient
then Exit
;
2915 // FBFGFireCounter - âðåìÿ ïåðåä âûñòðåëîì (äëÿ BFG)
2916 // FReloading - âðåìÿ ïîñëå âûñòðåëà (äëÿ âñåãî)
2924 if FReloading
[FCurrWeap
] <> 0 then Exit
;
2929 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
2930 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
2931 xd
:= wx
+IfThen(FDirection
= TDirection
.D_LEFT
, -30, 30);
2932 yd
:= wy
+firediry();
2938 if R_BERSERK
in FRulez
then
2940 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
2941 locobj
.X
:= FObj
.X
+FObj
.Rect
.X
;
2942 locobj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
2945 locobj
.rect
.Width
:= 39;
2946 locobj
.rect
.Height
:= 52;
2947 locobj
.Vel
.X
:= (xd
-wx
) div 2;
2948 locobj
.Vel
.Y
:= (yd
-wy
) div 2;
2949 locobj
.Accel
.X
:= xd
-wx
;
2950 locobj
.Accel
.y
:= yd
-wy
;
2952 if g_Weapon_Hit(@locobj
, 50, FUID
, HIT_SOME
) <> 0 then
2953 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
2955 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
2957 if (gFlash
= 1) and (FPain
< 50) then FPain
:= min(FPain
+ 25, 50);
2961 g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
2965 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2970 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
2971 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
2973 FSawSoundSelect
.Stop();
2975 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
2977 else if not FSawSoundHit
.IsPlaying() then
2979 FSawSoundSelect
.Stop();
2980 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
2983 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2989 if FAmmo
[A_BULLETS
] > 0 then
2991 g_Weapon_pistol(wx
, wy
, xd
, yd
, FUID
);
2992 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2993 Dec(FAmmo
[A_BULLETS
]);
2994 FFireAngle
:= FAngle
;
2997 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
2998 GameVelX
, GameVelY
-2, SHELL_BULLET
);
3002 if FAmmo
[A_SHELLS
] > 0 then
3004 g_Weapon_shotgun(wx
, wy
, xd
, yd
, FUID
);
3005 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', wx
, wy
);
3006 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3007 Dec(FAmmo
[A_SHELLS
]);
3008 FFireAngle
:= FAngle
;
3012 FShellType
:= SHELL_SHELL
;
3016 if FAmmo
[A_SHELLS
] >= 2 then
3018 g_Weapon_dshotgun(wx
, wy
, xd
, yd
, FUID
);
3019 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3020 Dec(FAmmo
[A_SHELLS
], 2);
3021 FFireAngle
:= FAngle
;
3025 FShellType
:= SHELL_DBLSHELL
;
3029 if FAmmo
[A_BULLETS
] > 0 then
3031 g_Weapon_mgun(wx
, wy
, xd
, yd
, FUID
);
3032 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', wx
, wy
);
3033 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3034 Dec(FAmmo
[A_BULLETS
]);
3035 FFireAngle
:= FAngle
;
3038 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
3039 GameVelX
, GameVelY
-2, SHELL_BULLET
);
3042 WEAPON_ROCKETLAUNCHER
:
3043 if FAmmo
[A_ROCKETS
] > 0 then
3045 g_Weapon_rocket(wx
, wy
, xd
, yd
, FUID
);
3046 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3047 Dec(FAmmo
[A_ROCKETS
]);
3048 FFireAngle
:= FAngle
;
3054 if FAmmo
[A_CELLS
] > 0 then
3056 g_Weapon_plasma(wx
, wy
, xd
, yd
, FUID
);
3057 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3058 Dec(FAmmo
[A_CELLS
]);
3059 FFireAngle
:= FAngle
;
3065 if (FAmmo
[A_CELLS
] >= 40) and (FBFGFireCounter
= -1) then
3067 FBFGFireCounter
:= 17;
3068 if not FNoReload
then
3069 g_Sound_PlayExAt('SOUND_WEAPON_STARTFIREBFG', FObj
.X
, FObj
.Y
);
3070 Dec(FAmmo
[A_CELLS
], 40);
3074 WEAPON_SUPERPULEMET
:
3075 if FAmmo
[A_SHELLS
] > 0 then
3077 g_Weapon_shotgun(wx
, wy
, xd
, yd
, FUID
);
3078 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', wx
, wy
);
3079 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3080 Dec(FAmmo
[A_SHELLS
]);
3081 FFireAngle
:= FAngle
;
3084 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
3085 GameVelX
, GameVelY
-2, SHELL_SHELL
);
3088 WEAPON_FLAMETHROWER
:
3089 if FAmmo
[A_FUEL
] > 0 then
3091 g_Weapon_flame(wx
, wy
, xd
, yd
, FUID
);
3093 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3095 FFireAngle
:= FAngle
;
3102 if g_Game_IsNet
and g_Game_IsServer
then MH_SEND_PlayerStats(FUID
);
3106 if g_Game_IsNet
then
3110 if FCurrWeap
<> WEAPON_BFG
then
3111 MH_SEND_PlayerFire(FUID
, FCurrWeap
, wx
, wy
, xd
, yd
, LastShotID
)
3113 if not FNoReload
then
3114 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_WEAPON_STARTFIREBFG');
3117 MH_SEND_PlayerStats(FUID
);
3122 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
3123 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
3124 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
3127 function TPlayer
.GetAmmoByWeapon(Weapon
: Byte): Word;
3130 WEAPON_PISTOL
, WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
];
3131 WEAPON_SHOTGUN1
, WEAPON_SHOTGUN2
, WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
];
3132 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
];
3133 WEAPON_PLASMA
, WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
];
3134 WEAPON_FLAMETHROWER
: Result
:= FAmmo
[A_FUEL
];
3139 function TPlayer
.HeadInLiquid(XInc
, YInc
: Integer): Boolean;
3141 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
+XInc
, FObj
.Y
+PLAYER_HEADRECT
.Y
+YInc
,
3142 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
3143 PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, True);
3146 procedure TPlayer
.FlamerOn
;
3148 FFlameSoundOff
.Stop();
3149 FFlameSoundOff
.SetPosition(0);
3152 if (not FFlameSoundOn
.IsPlaying()) and (not FFlameSoundWork
.IsPlaying()) then
3153 FFlameSoundWork
.PlayAt(FObj
.X
, FObj
.Y
);
3157 FFlameSoundOn
.PlayAt(FObj
.X
, FObj
.Y
);
3162 procedure TPlayer
.FlamerOff
;
3166 FFlameSoundOn
.Stop();
3167 FFlameSoundOn
.SetPosition(0);
3168 FFlameSoundWork
.Stop();
3169 FFlameSoundWork
.SetPosition(0);
3170 FFlameSoundOff
.PlayAt(FObj
.X
, FObj
.Y
);
3175 procedure TPlayer
.JetpackOn
;
3179 FJetSoundOn
.SetPosition(0);
3180 FJetSoundOn
.PlayAt(FObj
.X
, FObj
.Y
);
3184 procedure TPlayer
.JetpackOff
;
3188 FJetSoundOff
.SetPosition(0);
3189 FJetSoundOff
.PlayAt(FObj
.X
, FObj
.Y
);
3192 procedure TPlayer
.CatchFire(Attacker
: Word);
3194 if FFireTime
<= 0 then
3195 g_Sound_PlayExAt('SOUND_IGNITE', FObj
.X
, FObj
.Y
);
3197 FFireAttacker
:= Attacker
;
3198 if g_Game_IsNet
and g_Game_IsServer
then
3199 MH_SEND_PlayerStats(FUID
);
3202 procedure TPlayer
.Jump();
3204 if gFly
or FJetpack
then
3206 // Ïîëåò (÷èò-êîä èëè äæåòïàê):
3207 if FObj
.Vel
.Y
> -VEL_FLY
then
3208 FObj
.Vel
.Y
:= FObj
.Vel
.Y
- 3;
3211 if FJetFuel
> 0 then
3213 if (FJetFuel
< 1) and g_Game_IsServer
then
3217 if g_Game_IsNet
then
3218 MH_SEND_PlayerStats(FUID
);
3224 // Íå âêëþ÷àòü äæåòïàê â ðåæèìå ïðîõîæäåíèÿ ñêâîçü ñòåíû
3226 FCanJetpack
:= False;
3228 // Ïðûãàåì èëè âñïëûâàåì:
3229 if (CollideLevel(0, 1) or
3230 g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
+36, PLAYER_RECT
.Width
,
3231 PLAYER_RECT
.Height
-33, PANEL_STEP
, False)
3232 ) and (FObj
.Accel
.Y
= 0) then // Íå ïðûãàòü, åñëè åñòü âåðòèêàëüíîå óñêîðåíèå
3234 FObj
.Vel
.Y
:= -VEL_JUMP
;
3235 FCanJetpack
:= False;
3239 if BodyInLiquid(0, 0) then
3240 FObj
.Vel
.Y
:= -VEL_SW
3241 else if (FJetFuel
> 0) and FCanJetpack
and
3242 g_Game_IsServer
and (not g_Obj_CollideLiquid(@FObj
, 0, 0)) then
3246 if g_Game_IsNet
then
3247 MH_SEND_PlayerStats(FUID
);
3252 procedure TPlayer
.Kill(KillType
: Byte; SpawnerUID
: Word; t
: Byte);
3254 a
, i
, k
, ab
, ar
: Byte;
3258 srv
, netsrv
: Boolean;
3264 procedure PushItem(t
: Byte);
3268 id
:= g_Items_Create(FObj
.X
, FObj
.Y
, t
, True, False);
3269 it
:= g_Items_ByIdx(id
);
3270 if KillType
= K_EXTRAHARDKILL
then // -7..+7; -8..0
3272 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-7+Random(15),
3273 (FObj
.Vel
.Y
div 2)-Random(9));
3274 it
.positionChanged(); // this updates spatial accelerators
3278 if KillType
= K_HARDKILL
then // -5..+5; -5..0
3280 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-5+Random(11),
3281 (FObj
.Vel
.Y
div 2)-Random(6));
3283 else // -3..+3; -3..0
3285 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-3+Random(7),
3286 (FObj
.Vel
.Y
div 2)-Random(4));
3288 it
.positionChanged(); // this updates spatial accelerators
3291 if g_Game_IsNet
and g_Game_IsServer
then
3292 MH_SEND_ItemSpawn(True, id
);
3296 DoFrags
:= (gGameSettings
.MaxLives
= 0) or (gGameSettings
.GameMode
= GM_COOP
);
3297 Srv
:= g_Game_IsServer
;
3298 Netsrv
:= g_Game_IsServer
and g_Game_IsNet
;
3299 if Srv
then FDeath
:= FDeath
+ 1;
3304 if not FPhysics
then
3310 if (gGameSettings
.MaxLives
> 0) and Srv
and (gLMSRespawn
= LMS_RESPAWN_NONE
) then
3312 if FLives
> 0 then FLives
:= FLives
- 1;
3313 if FLives
= 0 then FNoRespawn
:= True;
3316 // Íîìåð òèïà ñìåðòè:
3319 K_SIMPLEKILL
: a
:= 1;
3321 K_EXTRAHARDKILL
: a
:= 3;
3326 if not FModel
.PlaySound(MODELSOUND_DIE
, a
, FObj
.X
, FObj
.Y
) then
3328 if FModel
.PlaySound(MODELSOUND_DIE
, i
, FObj
.X
, FObj
.Y
) then
3335 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN1
;
3337 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN2
;
3338 K_EXTRAHARDKILL
, K_FALLKILL
:
3339 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN3
;
3342 // Ïåðåêëþ÷àåì ñîñòîÿíèå:
3346 K_HARDKILL
, K_EXTRAHARDKILL
:
3350 // Ðåàêöèÿ ìîíñòðîâ íà ñìåðòü èãðîêà:
3351 if (KillType
<> K_FALLKILL
) and (Srv
) then
3352 g_Monsters_killedp();
3354 if SpawnerUID
= FUID
then
3356 if Srv
and (DoFrags
or (gGameSettings
.GameMode
= GM_TDM
)) then
3361 g_Console_Add(Format(_lc
[I_PLAYER_KILL_SELF
], [FName
]), True);
3364 if g_GetUIDType(SpawnerUID
) = UID_PLAYER
then
3365 begin // Óáèò äðóãèì èãðîêîì
3366 KP
:= g_Player_Get(SpawnerUID
);
3367 if (KP
<> nil) and Srv
then
3369 if (DoFrags
or (gGameSettings
.GameMode
= GM_TDM
)) then
3370 if SameTeam(FUID
, SpawnerUID
) then
3380 if (gGameSettings
.GameMode
= GM_TDM
) and DoFrags
then
3381 Inc(gTeamStat
[KP
.Team
].Goals
,
3382 IfThen(SameTeam(FUID
, SpawnerUID
), -1, 1));
3384 if netsrv
then MH_SEND_PlayerStats(SpawnerUID
);
3387 plr
:= g_Player_Get(SpawnerUID
);
3395 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_2
],
3399 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_1
],
3403 g_Console_Add(Format(_lc
[I_PLAYER_KILL
],
3408 else if g_GetUIDType(SpawnerUID
) = UID_MONSTER
then
3409 begin // Óáèò ìîíñòðîì
3410 mon
:= g_Monsters_ByUID(SpawnerUID
);
3414 s
:= g_Mons_GetKilledByTypeId(mon
.MonsterType
);
3418 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_2
],
3422 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_1
],
3426 g_Console_Add(Format(_lc
[I_PLAYER_KILL
],
3431 else // Îñîáûå òèïû ñìåðòè
3434 HIT_SELF
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_SELF
], [FName
]), True);
3435 HIT_FALL
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_FALL
], [FName
]), True);
3436 HIT_WATER
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_WATER
], [FName
]), True);
3437 HIT_ACID
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_ACID
], [FName
]), True);
3438 HIT_TRAP
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_TRAP
], [FName
]), True);
3439 else g_Console_Add(Format(_lc
[I_PLAYER_DIED
], [FName
]), True);
3445 for a
:= WP_FIRST
to WP_LAST
do
3449 WEAPON_SAW
: i
:= ITEM_WEAPON_SAW
;
3450 WEAPON_SHOTGUN1
: i
:= ITEM_WEAPON_SHOTGUN1
;
3451 WEAPON_SHOTGUN2
: i
:= ITEM_WEAPON_SHOTGUN2
;
3452 WEAPON_CHAINGUN
: i
:= ITEM_WEAPON_CHAINGUN
;
3453 WEAPON_ROCKETLAUNCHER
: i
:= ITEM_WEAPON_ROCKETLAUNCHER
;
3454 WEAPON_PLASMA
: i
:= ITEM_WEAPON_PLASMA
;
3455 WEAPON_BFG
: i
:= ITEM_WEAPON_BFG
;
3456 WEAPON_SUPERPULEMET
: i
:= ITEM_WEAPON_SUPERPULEMET
;
3457 WEAPON_FLAMETHROWER
: i
:= ITEM_WEAPON_FLAMETHROWER
;
3466 if R_ITEM_BACKPACK
in FRulez
then
3467 PushItem(ITEM_AMMO_BACKPACK
);
3469 // Âûáðîñ ðàêåòíîãî ðàíöà:
3470 if FJetFuel
> 0 then
3471 PushItem(ITEM_JETPACK
);
3474 if not (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
]) then
3476 if R_KEY_RED
in FRulez
then
3477 PushItem(ITEM_KEY_RED
);
3479 if R_KEY_GREEN
in FRulez
then
3480 PushItem(ITEM_KEY_GREEN
);
3482 if R_KEY_BLUE
in FRulez
then
3483 PushItem(ITEM_KEY_BLUE
);
3487 DropFlag(KillType
= K_FALLKILL
);
3490 g_Player_CreateCorpse(Self
);
3492 if Srv
and (gGameSettings
.MaxLives
> 0) and FNoRespawn
and
3493 (gLMSRespawn
= LMS_RESPAWN_NONE
) then
3499 for i
:= Low(gPlayers
) to High(gPlayers
) do
3501 if gPlayers
[i
] = nil then continue
;
3502 if (not gPlayers
[i
].FNoRespawn
) and (not gPlayers
[i
].FSpectator
) then
3505 if gPlayers
[i
].FTeam
= TEAM_RED
then Inc(ar
)
3506 else if gPlayers
[i
].FTeam
= TEAM_BLUE
then Inc(ab
);
3511 OldLR
:= gLMSRespawn
;
3512 if (gGameSettings
.GameMode
= GM_COOP
) then
3516 // everyone is dead, restart the map
3517 g_Game_Message(_lc
[I_MESSAGE_LMS_LOSE
], 144);
3519 MH_SEND_GameEvent(NET_EV_LMS_LOSE
);
3520 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3521 gLMSRespawnTime
:= gTime
+ 5000;
3523 else if (a
= 1) then
3525 if (gPlayers
[k
] <> nil) and not (gPlayers
[k
] is TBot
) then
3526 if (gPlayers
[k
] = gPlayer1
) or
3527 (gPlayers
[k
] = gPlayer2
) then
3528 g_Console_Add('*** ' + _lc
[I_MESSAGE_LMS_SURVIVOR
] + ' ***', True)
3529 else if Netsrv
and (gPlayers
[k
].FClientID
>= 0) then
3530 MH_SEND_GameEvent(NET_EV_LMS_SURVIVOR
, 0, 'N', gPlayers
[k
].FClientID
);
3533 else if (gGameSettings
.GameMode
= GM_TDM
) then
3535 if (ab
= 0) and (ar
<> 0) then
3538 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 144);
3540 MH_SEND_GameEvent(NET_EV_TLMS_WIN
, TEAM_RED
);
3541 Inc(gTeamStat
[TEAM_RED
].Goals
);
3542 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3543 gLMSRespawnTime
:= gTime
+ 5000;
3545 else if (ar
= 0) and (ab
<> 0) then
3548 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 144);
3550 MH_SEND_GameEvent(NET_EV_TLMS_WIN
, TEAM_BLUE
);
3551 Inc(gTeamStat
[TEAM_BLUE
].Goals
);
3552 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3553 gLMSRespawnTime
:= gTime
+ 5000;
3555 else if (ar
= 0) and (ab
= 0) then
3558 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
3560 MH_SEND_GameEvent(NET_EV_LMS_DRAW
, 0, FName
);
3561 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3562 gLMSRespawnTime
:= gTime
+ 5000;
3565 else if (gGameSettings
.GameMode
= GM_DM
) then
3569 if gPlayers
[k
] <> nil then
3572 // survivor is the winner
3573 g_Game_Message(Format(_lc
[I_MESSAGE_LMS_WIN
], [AnsiUpperCase(FName
)]), 144);
3575 MH_SEND_GameEvent(NET_EV_LMS_WIN
, 0, FName
);
3578 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3579 gLMSRespawnTime
:= gTime
+ 5000;
3581 else if (a
= 0) then
3583 // everyone is dead, restart the map
3584 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
3586 MH_SEND_GameEvent(NET_EV_LMS_DRAW
, 0, FName
);
3587 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3588 gLMSRespawnTime
:= gTime
+ 5000;
3591 if srv
and (OldLR
= LMS_RESPAWN_NONE
) and (gLMSRespawn
> LMS_RESPAWN_NONE
) then
3593 if NetMode
= NET_SERVER
then
3594 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, (gLMSRespawnTime
- gTime
) div 1000)
3596 g_Console_Add(Format(_lc
[I_MSG_WARMUP_START
], [(gLMSRespawnTime
- gTime
) div 1000]), True);
3602 MH_SEND_PlayerStats(FUID
);
3603 MH_SEND_PlayerDeath(FUID
, KillType
, t
, SpawnerUID
);
3604 if gGameSettings
.GameMode
= GM_TDM
then MH_SEND_GameStats
;
3607 if srv
and FNoRespawn
then Spectate(True);
3608 FWantsInGame
:= True;
3611 function TPlayer
.BodyInLiquid(XInc
, YInc
: Integer): Boolean;
3613 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
, PLAYER_RECT
.Width
,
3614 PLAYER_RECT
.Height
-20, PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, False);
3617 function TPlayer
.BodyInAcid(XInc
, YInc
: Integer): Boolean;
3619 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
, PLAYER_RECT
.Width
,
3620 PLAYER_RECT
.Height
-20, PANEL_ACID1
or PANEL_ACID2
, False);
3623 procedure TPlayer
.MakeBloodSimple(Count
: Word);
3625 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)+8,
3626 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3627 Count
div 2, 3, -1, 16, (PLAYER_RECT
.Height
*2 div 3),
3628 FModel
.Blood
.R
, FModel
.Blood
.G
, FModel
.Blood
.B
, FModel
.Blood
.Kind
);
3629 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-8,
3630 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3631 Count
div 2, -3, -1, 16, (PLAYER_RECT
.Height
*2) div 3,
3632 FModel
.Blood
.R
, FModel
.Blood
.G
, FModel
.Blood
.B
, FModel
.Blood
.Kind
);
3635 procedure TPlayer
.MakeBloodVector(Count
: Word; VelX
, VelY
: Integer);
3637 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
3638 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3639 Count
, VelX
, VelY
, 16, (PLAYER_RECT
.Height
*2) div 3,
3640 FModel
.Blood
.R
, FModel
.Blood
.G
, FModel
.Blood
.B
, FModel
.Blood
.Kind
);
3643 procedure TPlayer
.QueueWeaponSwitch(Weapon
: Byte);
3645 if g_Game_IsClient
then Exit
;
3646 if Weapon
> High(FWeapon
) then Exit
;
3647 FNextWeap
:= FNextWeap
or (1 shl Weapon
);
3650 procedure TPlayer
.resetWeaponQueue ();
3653 FNextWeapDelay
:= 0;
3656 function TPlayer
.hasAmmoForWeapon (weapon
: Byte): Boolean;
3660 WEAPON_KASTET
, WEAPON_SAW
: result
:= true;
3661 WEAPON_SHOTGUN1
, WEAPON_SHOTGUN2
: result
:= (FAmmo
[A_SHELLS
] > 0);
3662 WEAPON_PISTOL
, WEAPON_CHAINGUN
, WEAPON_SUPERPULEMET
: result
:= (FAmmo
[A_BULLETS
] > 0);
3663 WEAPON_ROCKETLAUNCHER
: result
:= (FAmmo
[A_ROCKETS
] > 0);
3664 WEAPON_PLASMA
, WEAPON_BFG
: result
:= (FAmmo
[A_CELLS
] > 0);
3665 WEAPON_FLAMETHROWER
: result
:= (FAmmo
[A_FUEL
] > 0);
3666 else result
:= (weapon
< length(FWeapon
));
3670 // return 255 for "no switch"
3671 function TPlayer
.getNextWeaponIndex (): Byte;
3674 wantThisWeapon
: array[0..64] of Boolean;
3675 wwc
: Integer = 0; //HACK!
3678 result
:= 255; // default result: "no switch"
3679 // had weapon cycling on previous frame? remove that flag
3680 if (FNextWeap
and $2000) <> 0 then
3682 FNextWeap
:= FNextWeap
and $1FFF;
3683 FNextWeapDelay
:= 0;
3685 // cycling has priority
3686 if (FNextWeap
and $C000) <> 0 then
3688 if (FNextWeap
and $8000) <> 0 then
3692 FNextWeap
:= FNextWeap
or $2000; // we need this
3693 if FNextWeapDelay
> 0 then
3694 exit
; // cooldown time
3696 for i
:= 0 to High(FWeapon
) do
3698 cwi
:= (cwi
+length(FWeapon
)+dir
) mod length(FWeapon
);
3699 if FWeapon
[cwi
] then
3701 //e_WriteLog(Format(' SWITCH: cur=%d; new=%d', [FCurrWeap, cwi]), MSG_WARNING);
3702 result
:= Byte(cwi
);
3703 FNextWeapDelay
:= WEAPON_DELAY
;
3711 for i
:= 0 to High(wantThisWeapon
) do
3712 wantThisWeapon
[i
] := false;
3713 for i
:= 0 to High(FWeapon
) do
3714 if (FNextWeap
and (1 shl i
)) <> 0 then
3716 wantThisWeapon
[i
] := true;
3719 // exclude currently selected weapon from the set
3720 wantThisWeapon
[FCurrWeap
] := false;
3721 // slow down alterations a little
3724 //e_WriteLog(Format(' FNextWeap=%x; delay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
3725 // more than one weapon requested, assume "alteration" and check alteration delay
3726 if FNextWeapDelay
> 0 then
3732 // do not reset weapon queue, it will be done in `RealizeCurrentWeapon()`
3733 // but clear all counters if no weapon should be switched
3739 //e_WriteLog(Format('wwc=%d', [wwc]), MSG_WARNING);
3740 // try weapons in descending order
3741 for i
:= High(FWeapon
) downto 0 do
3743 if wantThisWeapon
[i
] and FWeapon
[i
] and ((wwc
= 1) or hasAmmoForWeapon(i
)) then
3748 FNextWeapDelay
:= WEAPON_DELAY
* 2; // anyway, 'cause why not
3752 // no suitable weapon found, so reset the queue, to avoid accidental "queuing" of weapon w/o ammo
3756 procedure TPlayer
.RealizeCurrentWeapon();
3757 function switchAllowed (): Boolean;
3762 if FBFGFireCounter
<> -1 then
3764 if FTime
[T_SWITCH
] > gTime
then
3766 for i
:= WP_FIRST
to WP_LAST
do
3767 if FReloading
[i
] > 0 then
3775 //e_WriteLog(Format('***RealizeCurrentWeapon: FNextWeap=%x; FNextWeapDelay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
3776 //FNextWeap := FNextWeap and $1FFF;
3777 if FNextWeapDelay
> 0 then Dec(FNextWeapDelay
); // "alteration delay"
3779 if not switchAllowed
then
3781 //HACK for weapon cycling
3782 if (FNextWeap
and $E000) <> 0 then FNextWeap
:= 0;
3786 nw
:= getNextWeaponIndex();
3787 if nw
= 255 then exit
; // don't reset anything here
3788 if nw
> High(FWeapon
) then
3790 // don't forget to reset queue here!
3791 //e_WriteLog(' RealizeCurrentWeapon: WUTAFUUUU', MSG_WARNING);
3799 FTime
[T_SWITCH
] := gTime
+156;
3800 if FCurrWeap
= WEAPON_SAW
then FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3801 FModel
.SetWeapon(FCurrWeap
);
3802 if g_Game_IsNet
then MH_SEND_PlayerStats(FUID
);
3806 procedure TPlayer
.NextWeapon();
3808 if g_Game_IsClient
then Exit
;
3812 procedure TPlayer
.PrevWeapon();
3814 if g_Game_IsClient
then Exit
;
3818 procedure TPlayer
.SetWeapon(W
: Byte);
3820 if FCurrWeap
<> W
then
3821 if W
= WEAPON_SAW
then
3822 FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3825 FModel
.SetWeapon(CurrWeap
);
3829 function TPlayer
.PickItem(ItemType
: Byte; arespawn
: Boolean; var remove
: Boolean): Boolean;
3831 function allowBerserkSwitching (): Boolean;
3833 if (FBFGFireCounter
<> -1) then begin result
:= false; exit
; end;
3835 if gBerserkAutoswitch
then exit
;
3836 if not conIsCheatsEnabled
then exit
;
3844 if g_Game_IsClient
then Exit
;
3846 // a = true - ìåñòî ñïàâíà ïðåäìåòà:
3847 a
:= LongBool(gGameSettings
.Options
and GAME_OPTION_WEAPONSTAY
) and arespawn
;
3852 if FHealth
< PLAYER_HP_SOFT
then
3854 IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
3858 if gFlash
= 2 then Inc(FPickup
, 5);
3862 if FHealth
< PLAYER_HP_SOFT
then
3864 IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
3868 if gFlash
= 2 then Inc(FPickup
, 5);
3872 if FArmor
< PLAYER_AP_SOFT
then
3874 FArmor
:= PLAYER_AP_SOFT
;
3877 if gFlash
= 2 then Inc(FPickup
, 5);
3881 if FArmor
< PLAYER_AP_LIMIT
then
3883 FArmor
:= PLAYER_AP_LIMIT
;
3886 if gFlash
= 2 then Inc(FPickup
, 5);
3890 if FHealth
< PLAYER_HP_LIMIT
then
3892 IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
3896 if gFlash
= 2 then Inc(FPickup
, 5);
3900 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) then
3902 if FHealth
< PLAYER_HP_LIMIT
then
3903 FHealth
:= PLAYER_HP_LIMIT
;
3904 if FArmor
< PLAYER_AP_LIMIT
then
3905 FArmor
:= PLAYER_AP_LIMIT
;
3909 if gFlash
= 2 then Inc(FPickup
, 5);
3913 if (not FWeapon
[WEAPON_SAW
]) or ((not arespawn
) and (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
])) then
3915 FWeapon
[WEAPON_SAW
] := True;
3917 if gFlash
= 2 then Inc(FPickup
, 5);
3918 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3921 ITEM_WEAPON_SHOTGUN1
:
3922 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN1
] then
3924 // Íóæíî, ÷òîáû íå âçÿòü âñå ïóëè ñðàçó:
3925 if a
and FWeapon
[WEAPON_SHOTGUN1
] then Exit
;
3927 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3928 FWeapon
[WEAPON_SHOTGUN1
] := True;
3930 if gFlash
= 2 then Inc(FPickup
, 5);
3931 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3934 ITEM_WEAPON_SHOTGUN2
:
3935 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN2
] then
3937 if a
and FWeapon
[WEAPON_SHOTGUN2
] then Exit
;
3939 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3940 FWeapon
[WEAPON_SHOTGUN2
] := True;
3942 if gFlash
= 2 then Inc(FPickup
, 5);
3943 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3946 ITEM_WEAPON_CHAINGUN
:
3947 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or not FWeapon
[WEAPON_CHAINGUN
] then
3949 if a
and FWeapon
[WEAPON_CHAINGUN
] then Exit
;
3951 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
3952 FWeapon
[WEAPON_CHAINGUN
] := True;
3954 if gFlash
= 2 then Inc(FPickup
, 5);
3955 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3958 ITEM_WEAPON_ROCKETLAUNCHER
:
3959 if (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or not FWeapon
[WEAPON_ROCKETLAUNCHER
] then
3961 if a
and FWeapon
[WEAPON_ROCKETLAUNCHER
] then Exit
;
3963 IncMax(FAmmo
[A_ROCKETS
], 2, FMaxAmmo
[A_ROCKETS
]);
3964 FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
3966 if gFlash
= 2 then Inc(FPickup
, 5);
3967 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3971 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_PLASMA
] then
3973 if a
and FWeapon
[WEAPON_PLASMA
] then Exit
;
3975 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3976 FWeapon
[WEAPON_PLASMA
] := True;
3978 if gFlash
= 2 then Inc(FPickup
, 5);
3979 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3983 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_BFG
] then
3985 if a
and FWeapon
[WEAPON_BFG
] then Exit
;
3987 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3988 FWeapon
[WEAPON_BFG
] := True;
3990 if gFlash
= 2 then Inc(FPickup
, 5);
3991 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3994 ITEM_WEAPON_SUPERPULEMET
:
3995 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SUPERPULEMET
] then
3997 if a
and FWeapon
[WEAPON_SUPERPULEMET
] then Exit
;
3999 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4000 FWeapon
[WEAPON_SUPERPULEMET
] := True;
4002 if gFlash
= 2 then Inc(FPickup
, 5);
4003 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4006 ITEM_WEAPON_FLAMETHROWER
:
4007 if (FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
]) or not FWeapon
[WEAPON_FLAMETHROWER
] then
4009 if a
and FWeapon
[WEAPON_FLAMETHROWER
] then Exit
;
4011 IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
4012 FWeapon
[WEAPON_FLAMETHROWER
] := True;
4014 if gFlash
= 2 then Inc(FPickup
, 5);
4015 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4019 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
4021 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
4024 if gFlash
= 2 then Inc(FPickup
, 5);
4027 ITEM_AMMO_BULLETS_BOX
:
4028 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
4030 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
4033 if gFlash
= 2 then Inc(FPickup
, 5);
4037 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
4039 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4042 if gFlash
= 2 then Inc(FPickup
, 5);
4045 ITEM_AMMO_SHELLS_BOX
:
4046 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
4048 IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
4051 if gFlash
= 2 then Inc(FPickup
, 5);
4055 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
4057 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
4060 if gFlash
= 2 then Inc(FPickup
, 5);
4063 ITEM_AMMO_ROCKET_BOX
:
4064 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
4066 IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
4069 if gFlash
= 2 then Inc(FPickup
, 5);
4073 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
4075 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
4078 if gFlash
= 2 then Inc(FPickup
, 5);
4082 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
4084 IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
4087 if gFlash
= 2 then Inc(FPickup
, 5);
4091 if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then
4093 IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
4096 if gFlash
= 2 then Inc(FPickup
, 5);
4100 if not(R_ITEM_BACKPACK
in FRulez
) or
4101 (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
4102 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
4103 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
4104 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or
4105 (FMaxAmmo
[A_FUEL
] < AmmoLimits
[1, A_FUEL
]) then
4107 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[1, A_BULLETS
];
4108 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[1, A_SHELLS
];
4109 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[1, A_ROCKETS
];
4110 FMaxAmmo
[A_CELLS
] := AmmoLimits
[1, A_CELLS
];
4111 FMaxAmmo
[A_FUEL
] := AmmoLimits
[1, A_FUEL
];
4113 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
4114 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
4115 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
4116 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4117 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
4118 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
4119 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
4120 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
4122 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
4125 if gFlash
= 2 then Inc(FPickup
, 5);
4129 if not(R_KEY_RED
in FRulez
) then
4131 Include(FRulez
, R_KEY_RED
);
4133 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
4134 if gFlash
= 2 then Inc(FPickup
, 5);
4135 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
4139 if not(R_KEY_GREEN
in FRulez
) then
4141 Include(FRulez
, R_KEY_GREEN
);
4143 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
4144 if gFlash
= 2 then Inc(FPickup
, 5);
4145 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
4149 if not(R_KEY_BLUE
in FRulez
) then
4151 Include(FRulez
, R_KEY_BLUE
);
4153 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
4154 if gFlash
= 2 then Inc(FPickup
, 5);
4155 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
4159 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
4161 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
4165 if gFlash
= 2 then Inc(FPickup
, 5);
4169 if FAir
< AIR_MAX
then
4174 if gFlash
= 2 then Inc(FPickup
, 5);
4179 if not (R_BERSERK
in FRulez
) then
4181 Include(FRulez
, R_BERSERK
);
4182 if allowBerserkSwitching
then
4184 FCurrWeap
:= WEAPON_KASTET
;
4186 FModel
.SetWeapon(WEAPON_KASTET
);
4191 if gFlash
= 2 then Inc(FPickup
, 5);
4193 FBerserk
:= gTime
+30000;
4198 if FHealth
< PLAYER_HP_SOFT
then
4200 FHealth
:= PLAYER_HP_SOFT
;
4201 FBerserk
:= gTime
+30000;
4209 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
4211 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
4214 if gFlash
= 2 then Inc(FPickup
, 5);
4218 if FHealth
< PLAYER_HP_LIMIT
then
4220 IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
4224 if gFlash
= 2 then Inc(FPickup
, 5);
4228 if FArmor
< PLAYER_AP_LIMIT
then
4230 IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
4233 if gFlash
= 2 then Inc(FPickup
, 5);
4237 if FJetFuel
< JET_MAX
then
4239 FJetFuel
:= JET_MAX
;
4242 if gFlash
= 2 then Inc(FPickup
, 5);
4246 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
4248 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
4251 if gFlash
= 2 then Inc(FPickup
, 5);
4256 procedure TPlayer
.Touch();
4260 //FModel.PlaySound(MODELSOUND_PAIN, 1, FObj.X, FObj.Y);
4263 // Áðîñèòü ôëàã òîâàðèùó:
4264 if gGameSettings
.GameMode
= GM_CTF
then
4269 procedure TPlayer
.Push(vx
, vy
: Integer);
4271 if (not FPhysics
) and FGhost
then
4273 FObj
.Accel
.X
:= FObj
.Accel
.X
+ vx
;
4274 FObj
.Accel
.Y
:= FObj
.Accel
.Y
+ vy
;
4275 if g_Game_IsNet
and g_Game_IsServer
then
4276 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
4279 procedure TPlayer
.Reset(Force
: Boolean);
4285 FTime
[T_RESPAWN
] := 0;
4286 FTime
[T_FLAGCAP
] := 0;
4300 FSpectator
:= False;
4303 FSpectatePlayer
:= -1;
4304 FNoRespawn
:= False;
4306 FLives
:= gGameSettings
.MaxLives
;
4311 procedure TPlayer
.SoftReset();
4317 FBFGFireCounter
:= -1;
4325 SetAction(A_STAND
, True);
4328 function TPlayer
.GetRespawnPoint(): Byte;
4333 // Íà áóäóùåå: FSpawn - èãðîê óæå èãðàë è ïåðåðîæäàåòñÿ
4335 // Îäèíî÷íàÿ èãðà/êîîïåðàòèâ
4336 if gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
] then
4338 if (Self
= gPlayer1
) or (Self
= gPlayer2
) then
4340 // Òî÷êà ïîÿâëåíèÿ ñâîåãî èãðîêà
4341 if Self
= gPlayer1
then
4342 c
:= RESPAWNPOINT_PLAYER1
4344 c
:= RESPAWNPOINT_PLAYER2
;
4345 if g_Map_GetPointCount(c
) > 0 then
4351 // Òî÷êà ïîÿâëåíèÿ äðóãîãî èãðîêà
4352 if Self
= gPlayer1
then
4353 c
:= RESPAWNPOINT_PLAYER2
4355 c
:= RESPAWNPOINT_PLAYER1
;
4356 if g_Map_GetPointCount(c
) > 0 then
4363 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà (áîòà)
4364 if Random(2) = 0 then
4365 c
:= RESPAWNPOINT_PLAYER1
4367 c
:= RESPAWNPOINT_PLAYER2
;
4368 if g_Map_GetPointCount(c
) > 0 then
4375 // Òî÷êà ëþáîé èç êîìàíä
4376 if Random(2) = 0 then
4377 c
:= RESPAWNPOINT_RED
4379 c
:= RESPAWNPOINT_BLUE
;
4380 if g_Map_GetPointCount(c
) > 0 then
4387 c
:= RESPAWNPOINT_DM
;
4388 if g_Map_GetPointCount(c
) > 0 then
4396 if gGameSettings
.GameMode
= GM_DM
then
4399 c
:= RESPAWNPOINT_DM
;
4400 if g_Map_GetPointCount(c
) > 0 then
4406 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà
4407 if Random(2) = 0 then
4408 c
:= RESPAWNPOINT_PLAYER1
4410 c
:= RESPAWNPOINT_PLAYER2
;
4411 if g_Map_GetPointCount(c
) > 0 then
4417 // Òî÷êà ëþáîé èç êîìàíä
4418 if Random(2) = 0 then
4419 c
:= RESPAWNPOINT_RED
4421 c
:= RESPAWNPOINT_BLUE
;
4422 if g_Map_GetPointCount(c
) > 0 then
4430 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
4432 // Òî÷êà ñâîåé êîìàíäû
4433 c
:= RESPAWNPOINT_DM
;
4434 if FTeam
= TEAM_RED
then
4435 c
:= RESPAWNPOINT_RED
;
4436 if FTeam
= TEAM_BLUE
then
4437 c
:= RESPAWNPOINT_BLUE
;
4438 if g_Map_GetPointCount(c
) > 0 then
4445 c
:= RESPAWNPOINT_DM
;
4446 if g_Map_GetPointCount(c
) > 0 then
4452 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà
4453 if Random(2) = 0 then
4454 c
:= RESPAWNPOINT_PLAYER1
4456 c
:= RESPAWNPOINT_PLAYER2
;
4457 if g_Map_GetPointCount(c
) > 0 then
4463 // Òî÷êà äðóãîé êîìàíäû
4464 c
:= RESPAWNPOINT_DM
;
4465 if FTeam
= TEAM_RED
then
4466 c
:= RESPAWNPOINT_BLUE
;
4467 if FTeam
= TEAM_BLUE
then
4468 c
:= RESPAWNPOINT_RED
;
4469 if g_Map_GetPointCount(c
) > 0 then
4477 procedure TPlayer
.Respawn(Silent
: Boolean; Force
: Boolean = False);
4479 RespawnPoint
: TRespawnPoint
;
4485 FBFGFireCounter
:= -1;
4490 if not g_Game_IsServer
then
4494 FWantsInGame
:= True;
4495 FJustTeleported
:= True;
4498 FTime
[T_RESPAWN
] := 0;
4502 // if server changes MaxLives we gotta be ready
4503 if gGameSettings
.MaxLives
= 0 then FNoRespawn
:= False;
4505 // Åùå íåëüçÿ âîçðîäèòüñÿ:
4506 if FTime
[T_RESPAWN
] > gTime
then
4509 // Ïðîñðàë âñå æèçíè:
4512 if not FSpectator
then Spectate(True);
4513 FWantsInGame
:= True;
4517 if (gGameSettings
.GameType
<> GT_SINGLE
) and (gGameSettings
.GameMode
<> GM_COOP
) then
4518 begin // "Ñâîÿ èãðà"
4519 // Áåðñåðê íå ñîõðàíÿåòñÿ ìåæäó óðîâíÿìè:
4520 FRulez
:= FRulez
-[R_BERSERK
];
4522 else // "Îäèíî÷íàÿ èãðà"/"Êîîï"
4524 // Áåðñåðê è êëþ÷è íå ñîõðàíÿþòñÿ ìåæäó óðîâíÿìè:
4525 FRulez
:= FRulez
-[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
, R_BERSERK
];
4528 // Ïîëó÷àåì òî÷êó ñïàóíà èãðîêà:
4529 c
:= GetRespawnPoint();
4534 // Âîñêðåøåíèå áåç îðóæèÿ:
4537 FHealth
:= Round(PLAYER_HP_SOFT
* (FHandicap
/ 100));
4543 for a
:= WP_FIRST
to WP_LAST
do
4545 FWeapon
[a
] := False;
4549 FWeapon
[WEAPON_PISTOL
] := True;
4550 FWeapon
[WEAPON_KASTET
] := True;
4551 FCurrWeap
:= WEAPON_PISTOL
;
4554 FModel
.SetWeapon(FCurrWeap
);
4556 for b
:= A_BULLETS
to A_HIGH
do
4559 FAmmo
[A_BULLETS
] := 50;
4561 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[0, A_BULLETS
];
4562 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[0, A_SHELLS
];
4563 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[0, A_SHELLS
];
4564 FMaxAmmo
[A_CELLS
] := AmmoLimits
[0, A_CELLS
];
4565 FMaxAmmo
[A_FUEL
] := AmmoLimits
[0, A_FUEL
];
4567 if gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
] then
4568 FRulez
:= [R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
]
4573 // Ïîëó÷àåì êîîðäèíàòû òî÷êè âîçðîæäåíèÿ:
4574 if not g_Map_GetPoint(c
, RespawnPoint
) then
4576 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
4580 // Óñòàíîâêà êîîðäèíàò è ñáðîñ âñåõ ïàðàìåòðîâ:
4581 FObj
.X
:= RespawnPoint
.X
-PLAYER_RECT
.X
;
4582 FObj
.Y
:= RespawnPoint
.Y
-PLAYER_RECT
.Y
;
4588 FDirection
:= RespawnPoint
.Direction
;
4589 if FDirection
= TDirection
.D_LEFT
then
4594 SetAction(A_STAND
, True);
4595 FModel
.Direction
:= FDirection
;
4597 for a
:= Low(FTime
) to High(FTime
) do
4600 for a
:= Low(FMegaRulez
) to High(FMegaRulez
) do
4605 FCanJetpack
:= False;
4611 // Àíèìàöèÿ âîçðîæäåíèÿ:
4612 if (not gLoadGameMode
) and (not Silent
) then
4613 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
4615 Anim
:= TAnimation
.Create(ID
, False, 3);
4616 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4617 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4621 FSpectator
:= False;
4624 FSpectatePlayer
:= -1;
4627 if (gPlayer1
= nil) and (gLMSPID1
= FUID
) then
4629 if (gPlayer2
= nil) and (gLMSPID2
= FUID
) then
4632 if g_Game_IsNet
then
4634 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
4635 MH_SEND_PlayerStats(FUID
, NET_EVERYONE
);
4637 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4638 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32,
4643 procedure TPlayer
.Spectate(NoMove
: Boolean = False);
4646 Kill(K_EXTRAHARDKILL
, FUID
, HIT_SOME
)
4647 else if (not NoMove
) then
4649 GameX
:= gMapInfo
.Width
div 2;
4650 GameY
:= gMapInfo
.Height
div 2;
4659 FWantsInGame
:= False;
4664 if Self
= gPlayer1
then
4669 if Self
= gPlayer2
then
4676 if g_Game_IsNet
then
4677 MH_SEND_PlayerStats(FUID
);
4680 procedure TPlayer
.SwitchNoClip
;
4684 FGhost
:= not FGhost
;
4685 FPhysics
:= not FGhost
;
4697 procedure TPlayer
.Run(Direction
: TDirection
);
4701 if MAX_RUNVEL
> 8 then
4705 if Direction
= TDirection
.D_LEFT
then
4707 if FObj
.Vel
.X
> -MAX_RUNVEL
then
4708 FObj
.Vel
.X
:= FObj
.Vel
.X
- (MAX_RUNVEL
shr 3);
4711 if FObj
.Vel
.X
< MAX_RUNVEL
then
4712 FObj
.Vel
.X
:= FObj
.Vel
.X
+ (MAX_RUNVEL
shr 3);
4714 // Âîçìîæíî, ïèíàåì êóñêè:
4715 if (FObj
.Vel
.X
<> 0) and (gGibs
<> nil) then
4717 b
:= Abs(FObj
.Vel
.X
);
4718 if b
> 1 then b
:= b
* (Random(8 div b
) + 1);
4719 for a
:= 0 to High(gGibs
) do
4721 if gGibs
[a
].alive
and
4722 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
+FObj
.Rect
.Height
-4,
4723 FObj
.Rect
.Width
, 8, @gGibs
[a
].Obj
) and (Random(3) = 0) then
4726 if FObj
.Vel
.X
< 0 then
4728 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)+120) // íàëåâî
4732 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)); // íàïðàâî
4734 gGibs
[a
].positionChanged(); // this updates spatial accelerators
4742 procedure TPlayer
.SeeDown();
4744 SetAction(A_SEEDOWN
);
4746 if FDirection
= TDirection
.D_LEFT
then FAngle
:= ANGLE_LEFTDOWN
else FAngle
:= ANGLE_RIGHTDOWN
;
4748 if FIncCam
> -120 then DecMin(FIncCam
, 5, -120);
4751 procedure TPlayer
.SeeUp();
4755 if FDirection
= TDirection
.D_LEFT
then FAngle
:= ANGLE_LEFTUP
else FAngle
:= ANGLE_RIGHTUP
;
4757 if FIncCam
< 120 then IncMax(FIncCam
, 5, 120);
4760 procedure TPlayer
.SetAction(Action
: Byte; Force
: Boolean = False);
4768 A_ATTACK
: Prior
:= 2;
4769 A_SEEUP
: Prior
:= 1;
4770 A_SEEDOWN
: Prior
:= 1;
4771 A_ATTACKUP
: Prior
:= 2;
4772 A_ATTACKDOWN
: Prior
:= 2;
4777 if (Prior
> FActionPrior
) or Force
then
4778 if not ((Prior
= 2) and (FCurrWeap
= WEAPON_SAW
)) then
4780 FActionPrior
:= Prior
;
4781 FActionAnim
:= Action
;
4782 FActionForce
:= Force
;
4783 FActionChanged
:= True;
4786 if Action
in [A_ATTACK
, A_ATTACKUP
, A_ATTACKDOWN
] then FModel
.SetFire(True);
4789 function TPlayer
.StayOnStep(XInc
, YInc
: Integer): Boolean;
4791 Result
:= not g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
-1,
4792 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False)
4793 and g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
,
4794 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False);
4797 function TPlayer
.TeleportTo(X
, Y
: Integer; silent
: Boolean; dir
: Byte): Boolean;
4804 if g_CollideLevel(X
, Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
) then
4806 g_Sound_PlayExAt('SOUND_GAME_NOTELEPORT', FObj
.X
, FObj
.Y
);
4807 if g_Game_IsServer
and g_Game_IsNet
then
4808 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_GAME_NOTELEPORT');
4812 FJustTeleported
:= True;
4817 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
4819 Anim
:= TAnimation
.Create(ID
, False, 3);
4822 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', FObj
.X
, FObj
.Y
);
4823 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4824 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4825 if g_Game_IsServer
and g_Game_IsNet
then
4826 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4827 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 1,
4831 FObj
.X
:= X
-PLAYER_RECT
.X
;
4832 FObj
.Y
:= Y
-PLAYER_RECT
.Y
;
4833 if FAlive
and FGhost
then
4839 if not g_Game_IsNet
then
4843 SetDirection(TDirection
.D_LEFT
);
4849 SetDirection(TDirection
.D_RIGHT
);
4855 if FDirection
= TDirection
.D_RIGHT
then
4857 SetDirection(TDirection
.D_LEFT
);
4862 SetDirection(TDirection
.D_RIGHT
);
4868 if not silent
and (Anim
<> nil) then
4870 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4871 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4874 if g_Game_IsServer
and g_Game_IsNet
then
4875 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4876 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 0,
4883 function nonz(a
: Single): Single;
4891 function TPlayer
.followCorpse(): Boolean;
4896 if FAlive
or FSpectator
then
4898 if (gCorpses
= nil) or (Length(gCorpses
) = 0) then
4900 for i
:= 0 to High(gCorpses
) do
4901 if gCorpses
[i
] <> nil then
4902 if gCorpses
[i
].FPlayerUID
= FUID
then
4905 FObj
.X
:= gCorpses
[i
].FObj
.X
;
4906 FObj
.Y
:= gCorpses
[i
].FObj
.Y
;
4907 FObj
.Vel
.X
:= gCorpses
[i
].FObj
.Vel
.X
;
4908 FObj
.Vel
.Y
:= gCorpses
[i
].FObj
.Vel
.Y
;
4909 FObj
.Accel
.X
:= gCorpses
[i
].FObj
.Accel
.X
;
4910 FObj
.Accel
.Y
:= gCorpses
[i
].FObj
.Accel
.Y
;
4915 procedure TPlayer
.Update();
4918 i
, ii
, wx
, wy
, xd
, yd
, k
: Integer;
4919 blockmon
, headwater
, dospawn
: Boolean;
4924 NetServer
:= g_Game_IsNet
and g_Game_IsServer
;
4925 AnyServer
:= g_Game_IsServer
;
4927 if g_Game_IsClient
and (NetInterpLevel
> 0) then
4928 DoLerp(NetInterpLevel
+ 1)
4934 if FClientID
>= 0 then
4936 FPing
:= NetClients
[FClientID
].Peer
^.lastRoundTripTime
;
4937 if NetClients
[FClientID
].Peer
^.packetsSent
> 0 then
4938 FLoss
:= Round(100*NetClients
[FClientID
].Peer
^.packetsLost
/NetClients
[FClientID
].Peer
^.packetsSent
)
4947 if FAlive
and (FPunchAnim
<> nil) then
4948 FPunchAnim
.Update();
4950 if FAlive
and (gFly
or FJetpack
) then
4953 if FDirection
= TDirection
.D_LEFT
then
4958 if FAlive
and (not FGhost
) then
4960 if FKeys
[KEY_UP
].Pressed
then
4962 if FKeys
[KEY_DOWN
].Pressed
then
4966 if (not (FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_DOWN
].Pressed
)) and
4969 i
:= g_basic
.Sign(FIncCam
);
4970 FIncCam
:= Abs(FIncCam
);
4971 DecMin(FIncCam
, 5, 0);
4972 FIncCam
:= FIncCam
*i
;
4975 // no need to do that each second frame, weapon queue will take care of it
4976 if FAlive
and FKeys
[KEY_NEXTWEAPON
].Pressed
and AnyServer
then NextWeapon();
4977 if FAlive
and FKeys
[KEY_PREVWEAPON
].Pressed
and AnyServer
then PrevWeapon();
4979 if gTime
mod (GAME_TICK
*2) <> 0 then
4981 if (FObj
.Vel
.X
= 0) and FAlive
then
4983 if FKeys
[KEY_LEFT
].Pressed
then
4984 Run(TDirection
.D_LEFT
);
4985 if FKeys
[KEY_RIGHT
].Pressed
then
4986 Run(TDirection
.D_RIGHT
);
4991 if not followCorpse() then
4992 g_Obj_Move(@FObj
, True, True, True);
4993 positionChanged(); // this updates spatial accelerators
4999 FActionChanged
:= False;
5003 // Let alive player do some actions
5004 if FKeys
[KEY_LEFT
].Pressed
then Run(TDirection
.D_LEFT
);
5005 if FKeys
[KEY_RIGHT
].Pressed
then Run(TDirection
.D_RIGHT
);
5006 //if FKeys[KEY_NEXTWEAPON].Pressed and AnyServer then NextWeapon();
5007 //if FKeys[KEY_PREVWEAPON].Pressed and AnyServer then PrevWeapon();
5008 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then Fire()
5014 if NetServer
then MH_SEND_PlayerStats(FUID
);
5017 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Use();
5018 if FKeys
[KEY_JUMP
].Pressed
then Jump()
5021 if AnyServer
and FJetpack
then
5025 if NetServer
then MH_SEND_PlayerStats(FUID
);
5027 FCanJetpack
:= True;
5034 for k
:= Low(FKeys
) to KEY_CHAT
-1 do
5036 if FKeys
[k
].Pressed
then
5044 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
5047 if (FTime
[T_RESPAWN
] <= gTime
) and
5048 gGameOn
and (not FAlive
) then
5050 if (g_Player_GetCount() > 1) then
5054 gExit
:= EXIT_RESTART
;
5059 // Dead spectator actions
5062 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Fire();
5063 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then
5067 if (FSpectatePlayer
>= High(gPlayers
)) then
5068 FSpectatePlayer
:= -1
5072 for I
:= FSpectatePlayer
+ 1 to High(gPlayers
) do
5073 if gPlayers
[I
] <> nil then
5074 if gPlayers
[I
].alive
then
5075 if gPlayers
[I
].UID
<> FUID
then
5077 FSpectatePlayer
:= I
;
5082 if not SetSpect
then FSpectatePlayer
:= -1;
5093 if FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_JUMP
].Pressed
then
5095 FYTo
:= FObj
.Y
- 32;
5096 FSpectatePlayer
:= -1;
5098 if FKeys
[KEY_DOWN
].Pressed
then
5100 FYTo
:= FObj
.Y
+ 32;
5101 FSpectatePlayer
:= -1;
5103 if FKeys
[KEY_LEFT
].Pressed
then
5105 FXTo
:= FObj
.X
- 32;
5106 FSpectatePlayer
:= -1;
5108 if FKeys
[KEY_RIGHT
].Pressed
then
5110 FXTo
:= FObj
.X
+ 32;
5111 FSpectatePlayer
:= -1;
5114 if (FXTo
< -64) then
5116 else if (FXTo
> gMapInfo
.Width
+ 32) then
5117 FXTo
:= gMapInfo
.Width
+ 32;
5118 if (FYTo
< -72) then
5120 else if (FYTo
> gMapInfo
.Height
+ 32) then
5121 FYTo
:= gMapInfo
.Height
+ 32;
5126 if not followCorpse() then
5127 g_Obj_Move(@FObj
, True, True, True);
5128 positionChanged(); // this updates spatial accelerators
5135 if (FSpectatePlayer
<= High(gPlayers
)) and (FSpectatePlayer
>= 0) then
5136 if gPlayers
[FSpectatePlayer
] <> nil then
5137 if gPlayers
[FSpectatePlayer
].alive
then
5139 FXTo
:= gPlayers
[FSpectatePlayer
].GameX
;
5140 FYTo
:= gPlayers
[FSpectatePlayer
].GameY
;
5144 blockmon
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
, FObj
.Y
+PLAYER_HEADRECT
.Y
,
5145 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
5146 PANEL_BLOCKMON
, True);
5147 headwater
:= HeadInLiquid(0, 0);
5149 // Ñîïðîòèâëåíèå âîçäóõà:
5150 if (not FAlive
) or not (FKeys
[KEY_LEFT
].Pressed
or FKeys
[KEY_RIGHT
].Pressed
) then
5151 if FObj
.Vel
.X
<> 0 then
5152 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
5154 if (FLastHit
= HIT_TRAP
) and (FPain
> 90) then FPain
:= 90;
5155 DecMin(FPain
, 5, 0);
5156 DecMin(FPickup
, 1, 0);
5158 if FAlive
and (FObj
.Y
> Integer(gMapInfo
.Height
)+128) and AnyServer
then
5160 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
5161 FMegaRulez
[MR_SUIT
] := 0;
5162 FMegaRulez
[MR_INVUL
] := 0;
5163 FMegaRulez
[MR_INVIS
] := 0;
5164 Kill(K_FALLKILL
, 0, HIT_FALL
);
5171 if FCurrWeap
= WEAPON_SAW
then
5172 if not (FSawSound
.IsPlaying() or FSawSoundHit
.IsPlaying() or
5173 FSawSoundSelect
.IsPlaying()) then
5174 FSawSoundIdle
.PlayAt(FObj
.X
, FObj
.Y
);
5177 if (not FJetSoundFly
.IsPlaying()) and (not FJetSoundOn
.IsPlaying()) and
5178 (not FJetSoundOff
.IsPlaying()) then
5180 FJetSoundFly
.SetPosition(0);
5181 FJetSoundFly
.PlayAt(FObj
.X
, FObj
.Y
);
5184 for b
:= WP_FIRST
to WP_LAST
do
5185 if FReloading
[b
] > 0 then
5191 if FShellTimer
> -1 then
5192 if FShellTimer
= 0 then
5194 if FShellType
= SHELL_SHELL
then
5195 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5196 GameVelX
, GameVelY
-2, SHELL_SHELL
)
5197 else if FShellType
= SHELL_DBLSHELL
then
5199 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5200 GameVelX
+1, GameVelY
-2, SHELL_SHELL
);
5201 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5202 GameVelX
-1, GameVelY
-2, SHELL_SHELL
);
5205 end else Dec(FShellTimer
);
5207 if (FBFGFireCounter
> -1) then
5208 if FBFGFireCounter
= 0 then
5212 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
5213 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
5214 xd
:= wx
+IfThen(FDirection
= TDirection
.D_LEFT
, -30, 30);
5215 yd
:= wy
+firediry();
5216 g_Weapon_bfgshot(wx
, wy
, xd
, yd
, FUID
);
5217 if NetServer
then MH_SEND_PlayerFire(FUID
, WEAPON_BFG
, wx
, wy
, xd
, yd
);
5218 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
5219 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
5220 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
5223 FReloading
[WEAPON_BFG
] := WEAPON_RELOAD
[WEAPON_BFG
];
5224 FBFGFireCounter
:= -1;
5227 FBFGFireCounter
:= 0
5229 Dec(FBFGFireCounter
);
5231 if (FMegaRulez
[MR_SUIT
] < gTime
) and AnyServer
then
5233 b
:= g_GetAcidHit(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
);
5235 if (b
> 0) and (gTime
mod (15*GAME_TICK
) = 0) then Damage(b
, 0, 0, 0, HIT_ACID
);
5238 if (headwater
or blockmon
) then
5244 if AnyServer
then Damage(10, 0, 0, 0, HIT_WATER
);
5247 else if (FAir
mod 31 = 0) and not blockmon
then
5249 g_GFX_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2), FObj
.Y
+PLAYER_RECT
.Y
-4, 5+Random(6), 8, 4);
5250 if Random(2) = 0 then
5251 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
5253 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
5255 end else if FAir
< AIR_DEF
then
5258 if FFireTime
> 0 then
5260 if BodyInLiquid(0, 0) then
5265 else if FMegaRulez
[MR_SUIT
] >= gTime
then
5267 if FMegaRulez
[MR_SUIT
] = gTime
then
5274 if FFirePainTime
<= 0 then
5276 if g_Game_IsServer
then
5277 Damage(5, FFireAttacker
, 0, 0, HIT_FLAME
);
5278 FFirePainTime
:= 18;
5280 FFirePainTime
:= FFirePainTime
- 1;
5281 FFireTime
:= FFireTime
- 1;
5282 if (FFireTime
= 0) and g_Game_IsNet
and g_Game_IsServer
then
5283 MH_SEND_PlayerStats(FUID
);
5287 if FDamageBuffer
> 0 then
5289 if FDamageBuffer
>= 9 then
5293 if FDamageBuffer
< 30 then i
:= 9
5294 else if FDamageBuffer
< 100 then i
:= 18
5298 ii
:= Round(FDamageBuffer
*FHealth
/ nonz(FArmor
*(3/4)+FHealth
));
5299 FArmor
:= FArmor
-(FDamageBuffer
-ii
);
5300 FHealth
:= FHealth
-ii
;
5303 FHealth
:= FHealth
+FArmor
;
5308 if FHealth
<= 0 then
5309 if FHealth
> -30 then Kill(K_SIMPLEKILL
, FLastSpawnerUID
, FLastHit
)
5310 else if FHealth
> -50 then Kill(K_HARDKILL
, FLastSpawnerUID
, FLastHit
)
5311 else Kill(K_EXTRAHARDKILL
, FLastSpawnerUID
, FLastHit
);
5315 if FDamageBuffer
<= 20 then FModel
.PlaySound(MODELSOUND_PAIN
, 1, FObj
.X
, FObj
.Y
)
5316 else if FDamageBuffer
<= 55 then FModel
.PlaySound(MODELSOUND_PAIN
, 2, FObj
.X
, FObj
.Y
)
5317 else if FDamageBuffer
<= 120 then FModel
.PlaySound(MODELSOUND_PAIN
, 3, FObj
.X
, FObj
.Y
)
5318 else FModel
.PlaySound(MODELSOUND_PAIN
, 4, FObj
.X
, FObj
.Y
);
5325 end; // if FAlive then ...
5327 if (FActionAnim
= A_PAIN
) and (FModel
.Animation
<> A_PAIN
) then
5329 FModel
.ChangeAnimation(FActionAnim
, FActionForce
);
5330 FModel
.GetCurrentAnimation
.MinLength
:= i
;
5331 FModel
.GetCurrentAnimationMask
.MinLength
:= i
;
5332 end else FModel
.ChangeAnimation(FActionAnim
, FActionForce
and (FModel
.Animation
<> A_STAND
));
5334 if (FModel
.GetCurrentAnimation
.Played
or ((not FActionChanged
) and (FModel
.Animation
= A_WALK
)))
5335 then SetAction(A_STAND
, True);
5337 if not ((FModel
.Animation
= A_WALK
) and (Abs(FObj
.Vel
.X
) < 4) and not FModel
.Fire
) then FModel
.Update
;
5339 for b
:= Low(FKeys
) to High(FKeys
) do
5340 if FKeys
[b
].Time
= 0 then FKeys
[b
].Pressed
:= False else Dec(FKeys
[b
].Time
);
5344 procedure TPlayer
.getMapBox (out x
, y
, w
, h
: Integer); inline;
5346 x
:= FObj
.X
+PLAYER_RECT
.X
;
5347 y
:= FObj
.Y
+PLAYER_RECT
.Y
;
5348 w
:= PLAYER_RECT
.Width
;
5349 h
:= PLAYER_RECT
.Height
;
5353 procedure TPlayer
.moveBy (dx
, dy
: Integer); inline;
5355 if (dx
<> 0) or (dy
<> 0) then
5364 function TPlayer
.Collide(X
, Y
: Integer; Width
, Height
: Word): Boolean;
5366 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
5367 FObj
.Y
+PLAYER_RECT
.Y
,
5374 function TPlayer
.Collide(Panel
: TPanel
): Boolean;
5376 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
5377 FObj
.Y
+PLAYER_RECT
.Y
,
5381 Panel
.Width
, Panel
.Height
);
5384 function TPlayer
.Collide(X
, Y
: Integer): Boolean;
5386 X
:= X
-FObj
.X
-PLAYER_RECT
.X
;
5387 Y
:= Y
-FObj
.Y
-PLAYER_RECT
.Y
;
5388 Result
:= (x
>= 0) and (x
<= PLAYER_RECT
.Width
) and
5389 (y
>= 0) and (y
<= PLAYER_RECT
.Height
);
5392 function g_Player_ValidName(Name
: string): Boolean;
5398 if gPlayers
= nil then Exit
;
5400 for a
:= 0 to High(gPlayers
) do
5401 if gPlayers
[a
] <> nil then
5402 if LowerCase(Name
) = LowerCase(gPlayers
[a
].FName
) then
5409 procedure TPlayer
.SetDirection(Direction
: TDirection
);
5413 d
:= FModel
.Direction
;
5415 FModel
.Direction
:= Direction
;
5416 if d
<> Direction
then FModel
.ChangeAnimation(FModel
.Animation
, True);
5418 FDirection
:= Direction
;
5421 function TPlayer
.GetKeys(): Byte;
5425 if R_KEY_RED
in FRulez
then Result
:= KEY_RED
;
5426 if R_KEY_GREEN
in FRulez
then Result
:= Result
or KEY_GREEN
;
5427 if R_KEY_BLUE
in FRulez
then Result
:= Result
or KEY_BLUE
;
5429 if FTeam
= TEAM_RED
then Result
:= Result
or KEY_REDTEAM
;
5430 if FTeam
= TEAM_BLUE
then Result
:= Result
or KEY_BLUETEAM
;
5433 procedure TPlayer
.Use();
5437 if FTime
[T_USE
] > gTime
then Exit
;
5439 g_Triggers_PressR(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
,
5440 PLAYER_RECT
.Height
, FUID
, ACTIVATE_PLAYERPRESS
);
5442 for a
:= 0 to High(gPlayers
) do
5443 if (gPlayers
[a
] <> nil) and (gPlayers
[a
] <> Self
) and
5444 gPlayers
[a
].alive
and SameTeam(FUID
, gPlayers
[a
].FUID
) and
5445 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
5446 FObj
.Rect
.Width
, FObj
.Rect
.Height
, @gPlayers
[a
].FObj
) then
5448 gPlayers
[a
].Touch();
5449 if g_Game_IsNet
and g_Game_IsServer
then
5450 MH_SEND_GameEvent(NET_EV_PLAYER_TOUCH
, gPlayers
[a
].FUID
);
5453 FTime
[T_USE
] := gTime
+120;
5456 procedure TPlayer
.NetFire(Wpn
: Byte; X
, Y
, AX
, AY
: Integer; WID
: Integer = -1);
5460 WX
, WY
, XD
, YD
: Integer;
5472 if R_BERSERK
in FRulez
then
5474 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
5475 locobj
.X
:= FObj
.X
+FObj
.Rect
.X
;
5476 locobj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
5479 locobj
.rect
.Width
:= 39;
5480 locobj
.rect
.Height
:= 52;
5481 locobj
.Vel
.X
:= (xd
-wx
) div 2;
5482 locobj
.Vel
.Y
:= (yd
-wy
) div 2;
5483 locobj
.Accel
.X
:= xd
-wx
;
5484 locobj
.Accel
.y
:= yd
-wy
;
5486 if g_Weapon_Hit(@locobj
, 50, FUID
, HIT_SOME
) <> 0 then
5487 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
5489 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
5493 FPain
:= min(FPain
+ 25, 50);
5495 g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
5500 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
5501 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
5503 FSawSoundSelect
.Stop();
5505 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
5507 else if not FSawSoundHit
.IsPlaying() then
5509 FSawSoundSelect
.Stop();
5510 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
5517 g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', GameX
, Gamey
);
5518 FFireAngle
:= FAngle
;
5520 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5521 GameVelX
, GameVelY
-2, SHELL_BULLET
);
5526 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
5527 FFireAngle
:= FAngle
;
5530 FShellType
:= SHELL_SHELL
;
5535 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN2', Gamex
, Gamey
);
5536 FFireAngle
:= FAngle
;
5539 FShellType
:= SHELL_DBLSHELL
;
5544 g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', Gamex
, Gamey
);
5545 FFireAngle
:= FAngle
;
5547 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5548 GameVelX
, GameVelY
-2, SHELL_BULLET
);
5551 WEAPON_ROCKETLAUNCHER
:
5553 g_Weapon_Rocket(wx
, wy
, xd
, yd
, FUID
, WID
);
5554 FFireAngle
:= FAngle
;
5560 g_Weapon_Plasma(wx
, wy
, xd
, yd
, FUID
, WID
);
5561 FFireAngle
:= FAngle
;
5567 g_Weapon_BFGShot(wx
, wy
, xd
, yd
, FUID
, WID
);
5568 FFireAngle
:= FAngle
;
5572 WEAPON_SUPERPULEMET
:
5574 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
5575 FFireAngle
:= FAngle
;
5577 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5578 GameVelX
, GameVelY
-2, SHELL_SHELL
);
5581 WEAPON_FLAMETHROWER
:
5583 g_Weapon_flame(wx
, wy
, xd
, yd
, FUID
, WID
);
5585 FFireAngle
:= FAngle
;
5592 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
5593 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
5594 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
5597 procedure TPlayer
.DoLerp(Level
: Integer = 2);
5599 if FObj
.X
<> FXTo
then FObj
.X
:= Lerp(FObj
.X
, FXTo
, Level
);
5600 if FObj
.Y
<> FYTo
then FObj
.Y
:= Lerp(FObj
.Y
, FYTo
, Level
);
5603 procedure TPlayer
.SetLerp(XTo
, YTo
: Integer);
5607 if NetInterpLevel
< 1 then
5617 AX
:= Abs(FXTo
- FObj
.X
);
5618 AY
:= Abs(FYTo
- FObj
.Y
);
5619 if (AX
> 32) or (AX
<= NetInterpLevel
) then
5621 if (AY
> 32) or (AY
<= NetInterpLevel
) then
5626 function TPlayer
.FullInLift(XInc
, YInc
: Integer): Integer;
5628 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5629 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5630 PANEL_LIFTUP
, False) then Result
:= -1
5632 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5633 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5634 PANEL_LIFTDOWN
, False) then Result
:= 1
5638 function TPlayer
.GetFlag(Flag
: Byte): Boolean;
5645 if Flag
= FLAG_NONE
then
5648 if not g_Game_IsServer
then Exit
;
5650 // Ïðèíåñ ÷óæîé ôëàã íà ñâîþ áàçó:
5651 if (Flag
= FTeam
) and
5652 (gFlags
[Flag
].State
= FLAG_STATE_NORMAL
) and
5653 (FFlag
<> FLAG_NONE
) then
5655 if FFlag
= FLAG_RED
then
5656 s
:= _lc
[I_PLAYER_FLAG_RED
]
5658 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5660 evtype
:= FLAG_STATE_SCORED
;
5662 ts
:= Format('%.4d', [gFlags
[FFlag
].CaptureTime
]);
5663 Insert('.', ts
, Length(ts
) + 1 - 3);
5664 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_CAPTURE
], [FName
, s
, ts
]), True);
5666 g_Map_ResetFlag(FFlag
);
5667 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_CAPTURE
], [AnsiUpperCase(s
)]), 144);
5669 if ((Self
= gPlayer1
) or (Self
= gPlayer2
)
5670 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= FTeam
))
5671 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= FTeam
))) then
5676 if not sound_cap_flag
[a
].IsPlaying() then
5677 sound_cap_flag
[a
].Play();
5679 gTeamStat
[FTeam
].Goals
:= gTeamStat
[FTeam
].Goals
+ 1;
5682 if g_Game_IsNet
then
5684 MH_SEND_FlagEvent(evtype
, FFlag
, FUID
, False);
5688 gFlags
[FFlag
].CaptureTime
:= 0;
5693 // Ïîäîáðàë ñâîé ôëàã - âåðíóë åãî íà áàçó:
5694 if (Flag
= FTeam
) and
5695 (gFlags
[Flag
].State
= FLAG_STATE_DROPPED
) then
5697 if Flag
= FLAG_RED
then
5698 s
:= _lc
[I_PLAYER_FLAG_RED
]
5700 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5702 evtype
:= FLAG_STATE_RETURNED
;
5703 gFlags
[Flag
].CaptureTime
:= 0;
5705 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_RETURN
], [FName
, s
]), True);
5707 g_Map_ResetFlag(Flag
);
5708 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
5710 if ((Self
= gPlayer1
) or (Self
= gPlayer2
)
5711 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= FTeam
))
5712 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= FTeam
))) then
5717 if not sound_ret_flag
[a
].IsPlaying() then
5718 sound_ret_flag
[a
].Play();
5721 if g_Game_IsNet
then
5723 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5729 // Ïîäîáðàë ÷óæîé ôëàã:
5730 if (Flag
<> FTeam
) and (FTime
[T_FLAGCAP
] <= gTime
) then
5734 if Flag
= FLAG_RED
then
5735 s
:= _lc
[I_PLAYER_FLAG_RED
]
5737 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5739 evtype
:= FLAG_STATE_CAPTURED
;
5741 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_GET
], [FName
, s
]), True);
5743 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_GET
], [AnsiUpperCase(s
)]), 144);
5745 gFlags
[Flag
].State
:= FLAG_STATE_CAPTURED
;
5747 if ((Self
= gPlayer1
) or (Self
= gPlayer2
)
5748 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= FTeam
))
5749 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= FTeam
))) then
5754 if not sound_get_flag
[a
].IsPlaying() then
5755 sound_get_flag
[a
].Play();
5758 if g_Game_IsNet
then
5760 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5766 procedure TPlayer
.SetFlag(Flag
: Byte);
5769 if FModel
<> nil then
5770 FModel
.SetFlag(FFlag
);
5773 function TPlayer
.DropFlag(Silent
: Boolean = True): Boolean;
5779 if (not g_Game_IsServer
) or (FFlag
= FLAG_NONE
) then
5781 FTime
[T_FLAGCAP
] := gTime
+ 2000;
5782 with gFlags
[FFlag
] do
5786 Direction
:= FDirection
;
5787 State
:= FLAG_STATE_DROPPED
;
5789 g_Obj_Push(@Obj
, (FObj
.Vel
.X
div 2)-2+Random(5),
5790 (FObj
.Vel
.Y
div 2)-2+Random(5));
5791 positionChanged(); // this updates spatial accelerators
5793 if FFlag
= FLAG_RED
then
5794 s
:= _lc
[I_PLAYER_FLAG_RED
]
5796 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5798 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_DROP
], [FName
, s
]), True);
5799 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_DROP
], [AnsiUpperCase(s
)]), 144);
5801 if ((Self
= gPlayer1
) or (Self
= gPlayer2
)
5802 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= FTeam
))
5803 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= FTeam
))) then
5808 if (not Silent
) and (not sound_lost_flag
[a
].IsPlaying()) then
5809 sound_lost_flag
[a
].Play();
5811 if g_Game_IsNet
then
5812 MH_SEND_FlagEvent(FLAG_STATE_DROPPED
, Flag
, FUID
, False);
5818 procedure TPlayer
.GetSecret();
5820 if (self
= gPlayer1
) or (self
= gPlayer2
) then
5822 g_Console_Add(Format(_lc
[I_PLAYER_SECRET
], [FName
]), True);
5823 g_Sound_PlayEx('SOUND_GAME_SECRET');
5828 procedure TPlayer
.PressKey(Key
: Byte; Time
: Word = 1);
5830 Assert(Key
<= High(FKeys
));
5832 FKeys
[Key
].Pressed
:= True;
5833 FKeys
[Key
].Time
:= Time
;
5836 function TPlayer
.IsKeyPressed(K
: Byte): Boolean;
5838 Result
:= FKeys
[K
].Pressed
;
5841 procedure TPlayer
.ReleaseKeys();
5845 for a
:= Low(FKeys
) to High(FKeys
) do
5847 FKeys
[a
].Pressed
:= False;
5852 procedure TPlayer
.OnDamage(Angle
: SmallInt);
5856 function TPlayer
.firediry(): Integer;
5858 if FKeys
[KEY_UP
].Pressed
then Result
:= -42
5859 else if FKeys
[KEY_DOWN
].Pressed
then Result
:= 19
5863 procedure TPlayer
.RememberState();
5867 FSavedState
.Health
:= FHealth
;
5868 FSavedState
.Armor
:= FArmor
;
5869 FSavedState
.Air
:= FAir
;
5870 FSavedState
.JetFuel
:= FJetFuel
;
5871 FSavedState
.CurrWeap
:= FCurrWeap
;
5872 FSavedState
.NextWeap
:= FNextWeap
;
5873 FSavedState
.NextWeapDelay
:= FNextWeapDelay
;
5876 FSavedState
.Ammo
[i
] := FAmmo
[i
];
5878 FSavedState
.MaxAmmo
[i
] := FMaxAmmo
[i
];
5880 FSavedState
.Rulez
:= FRulez
;
5881 FSavedState
.WaitRecall
:= True;
5884 procedure TPlayer
.RecallState();
5888 if not FSavedState
.WaitRecall
then Exit
;
5890 FHealth
:= FSavedState
.Health
;
5891 FArmor
:= FSavedState
.Armor
;
5892 FAir
:= FSavedState
.Air
;
5893 FJetFuel
:= FSavedState
.JetFuel
;
5894 FCurrWeap
:= FSavedState
.CurrWeap
;
5895 FNextWeap
:= FSavedState
.NextWeap
;
5896 FNextWeapDelay
:= FSavedState
.NextWeapDelay
;
5899 FAmmo
[i
] := FSavedState
.Ammo
[i
];
5901 FMaxAmmo
[i
] := FSavedState
.MaxAmmo
[i
];
5903 FRulez
:= FSavedState
.Rulez
;
5904 FSavedState
.WaitRecall
:= False;
5906 if gGameSettings
.GameType
= GT_SERVER
then
5907 MH_SEND_PlayerStats(FUID
);
5910 procedure TPlayer
.SaveState (st
: TStream
);
5916 utils
.writeSign(st
, 'PLYR');
5917 utils
.writeInt(st
, Byte(PLR_SAVE_VERSION
)); // version
5919 utils
.writeBool(st
, FIamBot
);
5921 utils
.writeInt(st
, Word(FUID
));
5923 utils
.writeStr(st
, FName
);
5925 utils
.writeInt(st
, Byte(FTeam
));
5927 utils
.writeBool(st
, FAlive
);
5928 // Èçðàñõîäîâàë ëè âñå æèçíè
5929 utils
.writeBool(st
, FNoRespawn
);
5931 if FDirection
= TDirection
.D_LEFT
then b
:= 1 else b
:= 2; // D_RIGHT
5932 utils
.writeInt(st
, Byte(b
));
5934 utils
.writeInt(st
, LongInt(FHealth
));
5935 // Êîýôôèöèåíò èíâàëèäíîñòè
5936 utils
.writeInt(st
, LongInt(FHandicap
));
5938 utils
.writeInt(st
, Byte(FLives
));
5940 utils
.writeInt(st
, LongInt(FArmor
));
5942 utils
.writeInt(st
, LongInt(FAir
));
5944 utils
.writeInt(st
, LongInt(FJetFuel
));
5946 utils
.writeInt(st
, LongInt(FPain
));
5948 utils
.writeInt(st
, LongInt(FKills
));
5950 utils
.writeInt(st
, LongInt(FMonsterKills
));
5952 utils
.writeInt(st
, LongInt(FFrags
));
5954 utils
.writeInt(st
, Byte(FFragCombo
));
5955 // Âðåìÿ ïîñëåäíåãî ôðàãà
5956 utils
.writeInt(st
, LongWord(FLastFrag
));
5958 utils
.writeInt(st
, LongInt(FDeath
));
5960 utils
.writeInt(st
, Byte(FFlag
));
5962 utils
.writeInt(st
, LongInt(FSecrets
));
5964 utils
.writeInt(st
, Byte(FCurrWeap
));
5966 utils
.writeInt(st
, Word(FNextWeap
));
5968 utils
.writeInt(st
, Byte(FNextWeapDelay
));
5969 // Âðåìÿ çàðÿäêè BFG
5970 utils
.writeInt(st
, SmallInt(FBFGFireCounter
));
5972 utils
.writeInt(st
, LongInt(FDamageBuffer
));
5973 // Ïîñëåäíèé óäàðèâøèé
5974 utils
.writeInt(st
, Word(FLastSpawnerUID
));
5975 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà
5976 utils
.writeInt(st
, Byte(FLastHit
));
5978 Obj_SaveState(st
, @FObj
);
5979 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ
5980 for i
:= A_BULLETS
to A_HIGH
do utils
.writeInt(st
, Word(FAmmo
[i
]));
5981 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ
5982 for i
:= A_BULLETS
to A_HIGH
do utils
.writeInt(st
, Word(FMaxAmmo
[i
]));
5984 for i
:= WP_FIRST
to WP_LAST
do utils
.writeBool(st
, FWeapon
[i
]);
5985 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ
5986 for i
:= WP_FIRST
to WP_LAST
do utils
.writeInt(st
, Word(FReloading
[i
]));
5988 utils
.writeBool(st
, (R_ITEM_BACKPACK
in FRulez
));
5989 // Íàëè÷èå êðàñíîãî êëþ÷à
5990 utils
.writeBool(st
, (R_KEY_RED
in FRulez
));
5991 // Íàëè÷èå çåëåíîãî êëþ÷à
5992 utils
.writeBool(st
, (R_KEY_GREEN
in FRulez
));
5993 // Íàëè÷èå ñèíåãî êëþ÷à
5994 utils
.writeBool(st
, (R_KEY_BLUE
in FRulez
));
5996 utils
.writeBool(st
, (R_BERSERK
in FRulez
));
5997 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ
5998 for i
:= MR_SUIT
to MR_MAX
do utils
.writeInt(st
, LongWord(FMegaRulez
[i
]));
5999 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà
6000 for i
:= T_RESPAWN
to T_FLAGCAP
do utils
.writeInt(st
, LongWord(FTime
[i
]));
6002 utils
.writeStr(st
, FModel
.Name
);
6004 utils
.writeInt(st
, Byte(FColor
.R
));
6005 utils
.writeInt(st
, Byte(FColor
.G
));
6006 utils
.writeInt(st
, Byte(FColor
.B
));
6010 procedure TPlayer
.LoadState (st
: TStream
);
6019 if not utils
.checkSign(st
, 'PLYR') then raise XStreamError
.Create('invalid player signature');
6020 if (utils
.readByte(st
) <> PLR_SAVE_VERSION
) then raise XStreamError
.Create('invalid player version');
6022 FIamBot
:= utils
.readBool(st
);
6024 FUID
:= utils
.readWord(st
);
6026 str
:= utils
.readStr(st
);
6027 if (self
<> gPlayer1
) and (self
<> gPlayer2
) then FName
:= str
;
6029 FTeam
:= utils
.readByte(st
);
6031 FAlive
:= utils
.readBool(st
);
6032 // Èçðàñõîäîâàë ëè âñå æèçíè
6033 FNoRespawn
:= utils
.readBool(st
);
6035 b
:= utils
.readByte(st
);
6036 if b
= 1 then FDirection
:= TDirection
.D_LEFT
else FDirection
:= TDirection
.D_RIGHT
; // b = 2
6038 FHealth
:= utils
.readLongInt(st
);
6039 // Êîýôôèöèåíò èíâàëèäíîñòè
6040 FHandicap
:= utils
.readLongInt(st
);
6042 FLives
:= utils
.readByte(st
);
6044 FArmor
:= utils
.readLongInt(st
);
6046 FAir
:= utils
.readLongInt(st
);
6048 FJetFuel
:= utils
.readLongInt(st
);
6050 FPain
:= utils
.readLongInt(st
);
6052 FKills
:= utils
.readLongInt(st
);
6054 FMonsterKills
:= utils
.readLongInt(st
);
6056 FFrags
:= utils
.readLongInt(st
);
6058 FFragCombo
:= utils
.readByte(st
);
6059 // Âðåìÿ ïîñëåäíåãî ôðàãà
6060 FLastFrag
:= utils
.readLongWord(st
);
6062 FDeath
:= utils
.readLongInt(st
);
6064 FFlag
:= utils
.readByte(st
);
6066 FSecrets
:= utils
.readLongInt(st
);
6068 FCurrWeap
:= utils
.readByte(st
);
6070 FNextWeap
:= utils
.readWord(st
);
6072 FNextWeapDelay
:= utils
.readByte(st
);
6073 // Âðåìÿ çàðÿäêè BFG
6074 FBFGFireCounter
:= utils
.readSmallInt(st
);
6076 FDamageBuffer
:= utils
.readLongInt(st
);
6077 // Ïîñëåäíèé óäàðèâøèé
6078 FLastSpawnerUID
:= utils
.readWord(st
);
6079 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà
6080 FLastHit
:= utils
.readByte(st
);
6082 Obj_LoadState(@FObj
, st
);
6083 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ
6084 for i
:= A_BULLETS
to A_HIGH
do FAmmo
[i
] := utils
.readWord(st
);
6085 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ
6086 for i
:= A_BULLETS
to A_HIGH
do FMaxAmmo
[i
] := utils
.readWord(st
);
6088 for i
:= WP_FIRST
to WP_LAST
do FWeapon
[i
] := utils
.readBool(st
);
6089 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ
6090 for i
:= WP_FIRST
to WP_LAST
do FReloading
[i
] := utils
.readWord(st
);
6092 if utils
.readBool(st
) then Include(FRulez
, R_ITEM_BACKPACK
);
6093 // Íàëè÷èå êðàñíîãî êëþ÷à
6094 if utils
.readBool(st
) then Include(FRulez
, R_KEY_RED
);
6095 // Íàëè÷èå çåëåíîãî êëþ÷à
6096 if utils
.readBool(st
) then Include(FRulez
, R_KEY_GREEN
);
6097 // Íàëè÷èå ñèíåãî êëþ÷à
6098 if utils
.readBool(st
) then Include(FRulez
, R_KEY_BLUE
);
6100 if utils
.readBool(st
) then Include(FRulez
, R_BERSERK
);
6101 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ
6102 for i
:= MR_SUIT
to MR_MAX
do FMegaRulez
[i
] := utils
.readLongWord(st
);
6103 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà
6104 for i
:= T_RESPAWN
to T_FLAGCAP
do FTime
[i
] := utils
.readLongWord(st
);
6106 str
:= utils
.readStr(st
);
6108 FColor
.R
:= utils
.readByte(st
);
6109 FColor
.G
:= utils
.readByte(st
);
6110 FColor
.B
:= utils
.readByte(st
);
6111 if (self
= gPlayer1
) then
6113 str
:= gPlayer1Settings
.Model
;
6114 FColor
:= gPlayer1Settings
.Color
;
6116 else if (self
= gPlayer2
) then
6118 str
:= gPlayer2Settings
.Model
;
6119 FColor
:= gPlayer2Settings
.Color
;
6121 // Îáíîâëÿåì ìîäåëü èãðîêà
6123 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
6124 FModel
.Color
:= TEAMCOLOR
[FTeam
]
6126 FModel
.Color
:= FColor
;
6130 procedure TPlayer
.AllRulez(Health
: Boolean);
6136 FHealth
:= PLAYER_HP_LIMIT
;
6137 FArmor
:= PLAYER_AP_LIMIT
;
6141 for a
:= WP_FIRST
to WP_LAST
do FWeapon
[a
] := True;
6142 for a
:= A_BULLETS
to A_HIGH
do FAmmo
[a
] := 30000;
6143 FRulez
:= FRulez
+[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
];
6146 procedure TPlayer
.RestoreHealthArmor();
6148 FHealth
:= PLAYER_HP_LIMIT
;
6149 FArmor
:= PLAYER_AP_LIMIT
;
6152 procedure TPlayer
.FragCombo();
6156 if (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) or g_Game_IsClient
then
6158 if gTime
- FLastFrag
< FRAG_COMBO_TIME
then
6160 if FFragCombo
< 5 then
6162 Param
:= FUID
or (FFragCombo
shl 16);
6163 if (FComboEvnt
>= Low(gDelayedEvents
)) and
6164 (FComboEvnt
<= High(gDelayedEvents
)) and
6165 gDelayedEvents
[FComboEvnt
].Pending
and
6166 (gDelayedEvents
[FComboEvnt
].DEType
= DE_KILLCOMBO
) and
6167 (gDelayedEvents
[FComboEvnt
].DENum
and $FFFF = FUID
) then
6169 gDelayedEvents
[FComboEvnt
].Time
:= gTime
+ 500;
6170 gDelayedEvents
[FComboEvnt
].DENum
:= Param
;
6173 FComboEvnt
:= g_Game_DelayEvent(DE_KILLCOMBO
, 500, Param
);
6181 procedure TPlayer
.GiveItem(ItemType
: Byte);
6185 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
6187 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
6191 if FAir
< AIR_MAX
then
6198 if not (R_BERSERK
in FRulez
) then
6200 Include(FRulez
, R_BERSERK
);
6201 if FBFGFireCounter
< 1 then
6203 FCurrWeap
:= WEAPON_KASTET
;
6205 FModel
.SetWeapon(WEAPON_KASTET
);
6209 FBerserk
:= gTime
+30000;
6211 if FHealth
< PLAYER_HP_SOFT
then
6213 FHealth
:= PLAYER_HP_SOFT
;
6214 FBerserk
:= gTime
+30000;
6219 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
6221 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
6225 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
6227 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
6231 if FJetFuel
< JET_MAX
then
6233 FJetFuel
:= JET_MAX
;
6236 ITEM_MEDKIT_SMALL
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
6237 ITEM_MEDKIT_LARGE
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
6239 ITEM_ARMOR_GREEN
: if FArmor
< PLAYER_AP_SOFT
then FArmor
:= PLAYER_AP_SOFT
;
6240 ITEM_ARMOR_BLUE
: if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
6242 ITEM_SPHERE_BLUE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
6244 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) then
6246 if FHealth
< PLAYER_HP_LIMIT
then FHealth
:= PLAYER_HP_LIMIT
;
6247 if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
6250 ITEM_WEAPON_SAW
: FWeapon
[WEAPON_SAW
] := True;
6251 ITEM_WEAPON_SHOTGUN1
: FWeapon
[WEAPON_SHOTGUN1
] := True;
6252 ITEM_WEAPON_SHOTGUN2
: FWeapon
[WEAPON_SHOTGUN2
] := True;
6253 ITEM_WEAPON_CHAINGUN
: FWeapon
[WEAPON_CHAINGUN
] := True;
6254 ITEM_WEAPON_ROCKETLAUNCHER
: FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
6255 ITEM_WEAPON_PLASMA
: FWeapon
[WEAPON_PLASMA
] := True;
6256 ITEM_WEAPON_BFG
: FWeapon
[WEAPON_BFG
] := True;
6257 ITEM_WEAPON_SUPERPULEMET
: FWeapon
[WEAPON_SUPERPULEMET
] := True;
6258 ITEM_WEAPON_FLAMETHROWER
: FWeapon
[WEAPON_FLAMETHROWER
] := True;
6260 ITEM_AMMO_BULLETS
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
6261 ITEM_AMMO_BULLETS_BOX
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
6262 ITEM_AMMO_SHELLS
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
6263 ITEM_AMMO_SHELLS_BOX
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
6264 ITEM_AMMO_ROCKET
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
6265 ITEM_AMMO_ROCKET_BOX
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
6266 ITEM_AMMO_CELL
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
6267 ITEM_AMMO_CELL_BIG
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
6268 ITEM_AMMO_FUELCAN
: if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
6271 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
6272 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
6273 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
6274 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or
6275 (FMaxAmmo
[A_FUEL
] < AmmoLimits
[1, A_FUEL
]) then
6277 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[1, A_BULLETS
];
6278 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[1, A_SHELLS
];
6279 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[1, A_ROCKETS
];
6280 FMaxAmmo
[A_CELLS
] := AmmoLimits
[1, A_CELLS
];
6281 FMaxAmmo
[A_FUEL
] := AmmoLimits
[1, A_FUEL
];
6283 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
6284 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
6285 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
6286 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
6288 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
6291 ITEM_KEY_RED
: if not (R_KEY_RED
in FRulez
) then Include(FRulez
, R_KEY_RED
);
6292 ITEM_KEY_GREEN
: if not (R_KEY_GREEN
in FRulez
) then Include(FRulez
, R_KEY_GREEN
);
6293 ITEM_KEY_BLUE
: if not (R_KEY_BLUE
in FRulez
) then Include(FRulez
, R_KEY_BLUE
);
6295 ITEM_BOTTLE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
6296 ITEM_HELMET
: if FArmor
< PLAYER_AP_LIMIT
then IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
6301 if g_Game_IsNet
and g_Game_IsServer
then
6302 MH_SEND_PlayerStats(FUID
);
6305 procedure TPlayer
.FlySmoke(Times
: DWORD
= 1);
6310 if (Random(5) = 1) and (Times
= 1) then
6313 if BodyInLiquid(0, 0) then
6315 g_GFX_Bubbles(Obj
.X
+Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2)+Random(3)-1,
6316 Obj
.Y
+Obj
.Rect
.Height
+8, 1, 8, 4);
6317 if Random(2) = 0 then
6318 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
6320 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
6324 if g_Frames_Get(id
, 'FRAMES_SMOKE') then
6326 for i
:= 1 to Times
do
6328 Anim
:= TAnimation
.Create(id
, False, 3);
6330 g_GFX_OnceAnim(Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(Anim
.Width
div 2),
6331 Obj
.Y
+Obj
.Rect
.Height
-4+Random(8+Times
*2), Anim
, ONCEANIM_SMOKE
);
6337 procedure TPlayer
.OnFireFlame(Times
: DWORD
= 1);
6342 if (Random(10) = 1) and (Times
= 1) then
6345 if g_Frames_Get(id
, 'FRAMES_FLAME') then
6347 for i
:= 1 to Times
do
6349 Anim
:= TAnimation
.Create(id
, False, 3);
6351 g_GFX_OnceAnim(Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(Anim
.Width
div 2),
6352 Obj
.Y
+8+Random(8+Times
*2), Anim
, ONCEANIM_SMOKE
);
6358 procedure TPlayer
.PauseSounds(Enable
: Boolean);
6360 FSawSound
.Pause(Enable
);
6361 FSawSoundIdle
.Pause(Enable
);
6362 FSawSoundHit
.Pause(Enable
);
6363 FSawSoundSelect
.Pause(Enable
);
6364 FFlameSoundOn
.Pause(Enable
);
6365 FFlameSoundOff
.Pause(Enable
);
6366 FFlameSoundWork
.Pause(Enable
);
6367 FJetSoundFly
.Pause(Enable
);
6368 FJetSoundOn
.Pause(Enable
);
6369 FJetSoundOff
.Pause(Enable
);
6374 constructor TCorpse
.Create(X
, Y
: Integer; ModelName
: String; aMess
: Boolean);
6379 FObj
.Rect
:= PLAYER_CORPSERECT
;
6380 FModelName
:= ModelName
;
6385 FState
:= CORPSE_STATE_MESS
;
6386 g_PlayerModel_GetAnim(ModelName
, A_DIE2
, FAnimation
, FAnimationMask
);
6390 FState
:= CORPSE_STATE_NORMAL
;
6391 g_PlayerModel_GetAnim(ModelName
, A_DIE1
, FAnimation
, FAnimationMask
);
6395 destructor TCorpse
.Destroy();
6402 function TCorpse
.ObjPtr (): PObj
; inline; begin result
:= @FObj
; end;
6404 procedure TCorpse
.positionChanged (); inline; begin end;
6406 procedure TCorpse
.moveBy (dx
, dy
: Integer); inline;
6408 if (dx
<> 0) or (dy
<> 0) then
6417 procedure TCorpse
.getMapBox (out x
, y
, w
, h
: Integer); inline;
6419 x
:= FObj
.X
+PLAYER_CORPSERECT
.X
;
6420 y
:= FObj
.Y
+PLAYER_CORPSERECT
.Y
;
6421 w
:= PLAYER_CORPSERECT
.Width
;
6422 h
:= PLAYER_CORPSERECT
.Height
;
6426 procedure TCorpse
.Damage(Value
: Word; vx
, vy
: Integer);
6431 if FState
= CORPSE_STATE_REMOVEME
then
6434 FDamage
:= FDamage
+ Value
;
6436 if FDamage
> 150 then
6438 if FAnimation
<> nil then
6443 FState
:= CORPSE_STATE_REMOVEME
;
6445 g_Player_CreateGibs(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
6446 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2),
6447 FModelName
, FColor
);
6448 // Çâóê ìÿñà îò òðóïà:
6449 pm
:= g_PlayerModel_Get(FModelName
);
6450 pm
.PlaySound(MODELSOUND_DIE
, 5, FObj
.X
, FObj
.Y
);
6454 if (gBodyKillEvent
<> -1)
6455 and gDelayedEvents
[gBodyKillEvent
].Pending
then
6456 gDelayedEvents
[gBodyKillEvent
].Pending
:= False;
6457 gBodyKillEvent
:= g_Game_DelayEvent(DE_BODYKILL
, 1050, 0);
6462 Blood
:= g_PlayerModel_GetBlood(FModelName
);
6463 FObj
.Vel
.X
:= FObj
.Vel
.X
+ vx
;
6464 FObj
.Vel
.Y
:= FObj
.Vel
.Y
+ vy
;
6465 g_GFX_Blood(FObj
.X
+PLAYER_CORPSERECT
.X
+(PLAYER_CORPSERECT
.Width
div 2),
6466 FObj
.Y
+PLAYER_CORPSERECT
.Y
+(PLAYER_CORPSERECT
.Height
div 2),
6467 Value
, vx
, vy
, 16, (PLAYER_CORPSERECT
.Height
*2) div 3,
6468 Blood
.R
, Blood
.G
, Blood
.B
, Blood
.Kind
);
6472 procedure TCorpse
.Draw();
6474 if FState
= CORPSE_STATE_REMOVEME
then
6477 if FAnimation
<> nil then
6478 FAnimation
.Draw(FObj
.X
, FObj
.Y
, TMirrorType
.None
);
6480 if FAnimationMask
<> nil then
6483 FAnimationMask
.Draw(FObj
.X
, FObj
.Y
, TMirrorType
.None
);
6490 procedure TCorpse
.Update();
6494 if FState
= CORPSE_STATE_REMOVEME
then
6497 if gTime
mod (GAME_TICK
*2) <> 0 then
6499 g_Obj_Move(@FObj
, True, True, True);
6500 positionChanged(); // this updates spatial accelerators
6504 // Ñîïðîòèâëåíèå âîçäóõà äëÿ òðóïà:
6505 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
6507 st
:= g_Obj_Move(@FObj
, True, True, True);
6508 positionChanged(); // this updates spatial accelerators
6510 if WordBool(st
and MOVE_FALLOUT
) then
6512 FState
:= CORPSE_STATE_REMOVEME
;
6516 if FAnimation
<> nil then
6517 FAnimation
.Update();
6518 if FAnimationMask
<> nil then
6519 FAnimationMask
.Update();
6523 procedure TCorpse
.SaveState (st
: TStream
);
6530 utils
.writeSign(st
, 'CORP');
6531 utils
.writeInt(st
, Byte(0));
6533 utils
.writeInt(st
, Byte(FState
));
6535 utils
.writeInt(st
, Byte(FDamage
));
6537 utils
.writeInt(st
, Byte(FColor
.R
));
6538 utils
.writeInt(st
, Byte(FColor
.G
));
6539 utils
.writeInt(st
, Byte(FColor
.B
));
6541 Obj_SaveState(st
, @FObj
);
6542 utils
.writeInt(st
, Word(FPlayerUID
));
6544 anim
:= (FAnimation
<> nil);
6545 utils
.writeBool(st
, anim
);
6546 // Åñëè åñòü - ñîõðàíÿåì
6547 if anim
then FAnimation
.SaveState(st
);
6548 // Åñòü ëè ìàñêà àíèìàöèè
6549 anim
:= (FAnimationMask
<> nil);
6550 utils
.writeBool(st
, anim
);
6551 // Åñëè åñòü - ñîõðàíÿåì
6552 if anim
then FAnimationMask
.SaveState(st
);
6556 procedure TCorpse
.LoadState (st
: TStream
);
6563 if not utils
.checkSign(st
, 'CORP') then raise XStreamError
.Create('invalid corpse signature');
6564 if (utils
.readByte(st
) <> 0) then raise XStreamError
.Create('invalid corpse version');
6566 FState
:= utils
.readByte(st
);
6568 FDamage
:= utils
.readByte(st
);
6570 FColor
.R
:= utils
.readByte(st
);
6571 FColor
.G
:= utils
.readByte(st
);
6572 FColor
.B
:= utils
.readByte(st
);
6574 Obj_LoadState(@FObj
, st
);
6575 FPlayerUID
:= utils
.readWord(st
);
6577 anim
:= utils
.readBool(st
);
6578 // Åñëè åñòü - çàãðóæàåì
6581 Assert(FAnimation
<> nil, 'TCorpse.LoadState: no FAnimation');
6582 FAnimation
.LoadState(st
);
6584 // Åñòü ëè ìàñêà àíèìàöèè
6585 anim
:= utils
.readBool(st
);
6586 // Åñëè åñòü - çàãðóæàåì
6589 Assert(FAnimationMask
<> nil, 'TCorpse.LoadState: no FAnimationMask');
6590 FAnimationMask
.LoadState(st
);
6596 constructor TBot
.Create();
6603 FSpectator
:= False;
6610 for a
:= WP_FIRST
to WP_LAST
do
6612 FDifficult
.WeaponPrior
[a
] := WEAPON_PRIOR1
[a
];
6613 FDifficult
.CloseWeaponPrior
[a
] := WEAPON_PRIOR2
[a
];
6614 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
6618 destructor TBot
.Destroy();
6621 inherited Destroy();
6624 procedure TBot
.Draw();
6628 //if FTargetUID <> 0 then e_DrawLine(1, FObj.X, FObj.Y, g_Player_Get(FTargetUID).FObj.X,
6629 // g_Player_Get(FTargetUID).FObj.Y, 255, 0, 0);
6632 procedure TBot
.Respawn(Silent
: Boolean; Force
: Boolean = False);
6634 inherited Respawn(Silent
, Force
);
6637 FSelectedWeapon
:= FCurrWeap
;
6642 procedure TBot
.UpdateCombat();
6655 TTargetRecord
= array of TTarget
;
6657 function Compare(a
, b
: TTarget
): Integer;
6659 if a
.Line
and not b
.Line
then // A íà ëèíèè îãíÿ
6662 if not a
.Line
and b
.Line
then // B íà ëèíèè îãíÿ
6664 else // È A, è B íà ëèíèè èëè íå íà ëèíèè îãíÿ
6665 if (a
.Line
and b
.Line
) or ((not a
.Line
) and (not b
.Line
)) then
6667 if a
.Dist
> b
.Dist
then // B áëèæå
6669 else // A áëèæå èëè ðàâíîóäàëåííî ñ B
6672 else // Ñòðàííî -> A
6677 a
, x1
, y1
, x2
, y2
: Integer;
6678 targets
: TTargetRecord
;
6680 Target
, BestTarget
: TTarget
;
6681 firew
, fireh
: Integer;
6685 vsPlayer
, vsMonster
, ok
: Boolean;
6688 function monsUpdate (mon
: TMonster
): Boolean;
6690 result
:= false; // don't stop
6691 if mon
.alive
and (mon
.MonsterType
<> MONSTER_BARREL
) then
6693 if not TargetOnScreen(mon
.Obj
.X
+mon
.Obj
.Rect
.X
, mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
) then exit
;
6695 x2
:= mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2);
6696 y2
:= mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+(mon
.Obj
.Rect
.Height
div 2);
6698 // Åñëè ìîíñòð íà ýêðàíå è íå ïðèêðûò ñòåíîé
6699 if g_TraceVector(x1
, y1
, x2
, y2
) then
6701 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé
6702 SetLength(targets
, Length(targets
)+1);
6703 with targets
[High(targets
)] do
6710 Rect
:= mon
.Obj
.Rect
;
6711 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6712 Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6713 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6722 vsPlayer
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
);
6723 vsMonster
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
);
6725 // Åñëè òåêóùåå îðóæèå íå òî, ÷òî íóæíî, òî ìåíÿåì:
6726 if FCurrWeap
<> FSelectedWeapon
then
6729 // Åñëè íóæíî ñòðåëÿòü è íóæíîå îðóæèå, òî íàæàòü "Ñòðåëÿòü":
6730 if (GetAIFlag('NEEDFIRE') <> '') and (FCurrWeap
= FSelectedWeapon
) then
6732 RemoveAIFlag('NEEDFIRE');
6735 WEAPON_PLASMA
, WEAPON_SUPERPULEMET
, WEAPON_CHAINGUN
: PressKey(KEY_FIRE
, 20);
6736 WEAPON_SAW
, WEAPON_KASTET
, WEAPON_FLAMETHROWER
: PressKey(KEY_FIRE
, 40);
6737 else PressKey(KEY_FIRE
);
6741 // Êîîðäèíàòû ñòâîëà:
6742 x1
:= FObj
.X
+ WEAPONPOINT
[FDirection
].X
;
6743 y1
:= FObj
.Y
+ WEAPONPOINT
[FDirection
].Y
;
6745 Target
.UID
:= FTargetUID
;
6748 if Target
.UID
<> 0 then
6749 begin // Öåëü åñòü - íàñòðàèâàåì
6750 if (g_GetUIDType(Target
.UID
) = UID_PLAYER
) and
6753 tpla
:= g_Player_Get(Target
.UID
);
6757 if (@FObj
) <> nil then
6764 Target
.cX
:= Target
.X
+ PLAYER_RECT_CX
;
6765 Target
.cY
:= Target
.Y
+ PLAYER_RECT_CY
;
6766 Target
.Rect
:= PLAYER_RECT
;
6767 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6768 Target
.Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6769 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6770 Target
.IsPlayer
:= True;
6774 if (g_GetUIDType(Target
.UID
) = UID_MONSTER
) and
6777 mon
:= g_Monsters_ByUID(Target
.UID
);
6780 Target
.X
:= mon
.Obj
.X
;
6781 Target
.Y
:= mon
.Obj
.Y
;
6783 Target
.cX
:= Target
.X
+ mon
.Obj
.Rect
.X
+ (mon
.Obj
.Rect
.Width
div 2);
6784 Target
.cY
:= Target
.Y
+ mon
.Obj
.Rect
.Y
+ (mon
.Obj
.Rect
.Height
div 2);
6785 Target
.Rect
:= mon
.Obj
.Rect
;
6786 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6787 Target
.Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6788 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6789 Target
.IsPlayer
:= False;
6796 begin // Öåëè íåò - îáíóëÿåì
6801 Target
.Visible
:= False;
6802 Target
.Line
:= False;
6803 Target
.IsPlayer
:= False;
6808 // Åñëè öåëü íå âèäèìà èëè íå íà ëèíèè îãíÿ, òî èùåì âñå âîçìîæíûå öåëè:
6809 if (not Target
.Line
) or (not Target
.Visible
) then
6813 for a
:= 0 to High(gPlayers
) do
6814 if (gPlayers
[a
] <> nil) and (gPlayers
[a
].alive
) and
6815 (gPlayers
[a
].FUID
<> FUID
) and
6816 (not SameTeam(FUID
, gPlayers
[a
].FUID
)) and
6817 (not gPlayers
[a
].NoTarget
) and
6818 (gPlayers
[a
].FMegaRulez
[MR_INVIS
] < gTime
) then
6820 if not TargetOnScreen(gPlayers
[a
].FObj
.X
+ PLAYER_RECT
.X
,
6821 gPlayers
[a
].FObj
.Y
+ PLAYER_RECT
.Y
) then
6824 x2
:= gPlayers
[a
].FObj
.X
+ PLAYER_RECT_CX
;
6825 y2
:= gPlayers
[a
].FObj
.Y
+ PLAYER_RECT_CY
;
6827 // Åñëè èãðîê íà ýêðàíå è íå ïðèêðûò ñòåíîé:
6828 if g_TraceVector(x1
, y1
, x2
, y2
) then
6830 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé:
6831 SetLength(targets
, Length(targets
)+1);
6832 with targets
[High(targets
)] do
6834 UID
:= gPlayers
[a
].FUID
;
6835 X
:= gPlayers
[a
].FObj
.X
;
6836 Y
:= gPlayers
[a
].FObj
.Y
;
6839 Rect
:= PLAYER_RECT
;
6840 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6841 Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6842 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6850 if vsMonster
then g_Mons_ForEach(monsUpdate
);
6853 // Åñëè åñòü âîçìîæíûå öåëè:
6854 // (Âûáèðàåì ëó÷øóþ, ìåíÿåì îðóæèå è áåæèì ê íåé/îò íåå)
6855 if targets
<> nil then
6857 // Âûáèðàåì íàèëó÷øóþ öåëü:
6858 BestTarget
:= targets
[0];
6859 if Length(targets
) > 1 then
6860 for a
:= 1 to High(targets
) do
6861 if Compare(BestTarget
, targets
[a
]) = 1 then
6862 BestTarget
:= targets
[a
];
6864 // Åñëè ëó÷øàÿ öåëü "âèäíåå" òåêóùåé, òî òåêóùàÿ := ëó÷øàÿ:
6865 if ((not Target
.Visible
) and BestTarget
.Visible
and (Target
.UID
<> BestTarget
.UID
)) or
6866 ((not Target
.Line
) and BestTarget
.Line
and BestTarget
.Visible
) then
6868 Target
:= BestTarget
;
6870 if (Healthy() = 3) or ((Healthy() = 2)) then
6871 begin // Åñëè çäîðîâû - äîãîíÿåì
6872 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
6873 SetAIFlag('GORIGHT', '1');
6874 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6875 SetAIFlag('GOLEFT', '1');
6878 begin // Åñëè ïîáèòû - óáåãàåì
6879 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) then
6880 SetAIFlag('GORIGHT', '1');
6881 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6882 SetAIFlag('GOLEFT', '1');
6885 // Âûáèðàåì îðóæèå íà îñíîâå ðàññòîÿíèÿ è ïðèîðèòåòîâ:
6886 SelectWeapon(Abs(x1
-Target
.cX
));
6891 // (Äîãîíÿåì/óáåãàåì, ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëè)
6892 // (Åñëè öåëü äàëåêî, òî õâàòèò ñëåäèòü çà íåé)
6893 if Target
.UID
<> 0 then
6895 if not TargetOnScreen(Target
.X
+ Target
.Rect
.X
,
6896 Target
.Y
+ Target
.Rect
.Y
) then
6897 begin // Öåëü ñáåæàëà ñ "ýêðàíà"
6898 if (Healthy() = 3) or ((Healthy() = 2)) then
6899 begin // Åñëè çäîðîâû - äîãîíÿåì
6900 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
6901 SetAIFlag('GORIGHT', '1');
6902 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6903 SetAIFlag('GOLEFT', '1');
6906 begin // Åñëè ïîáèòû - çàáûâàåì î öåëè è óáåãàåì
6908 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) then
6909 SetAIFlag('GORIGHT', '1');
6910 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6911 SetAIFlag('GOLEFT', '1');
6915 begin // Öåëü ïîêà íà "ýêðàíå"
6916 // Åñëè öåëü íå çàãîðîæåíà ñòåíîé, òî îòìå÷àåì, êîãäà åå âèäåëè:
6917 if g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6918 FLastVisible
:= gTime
;
6919 // Åñëè ðàçíèöà âûñîò íå âåëèêà, òî äîãîíÿåì:
6920 if (Abs(FObj
.Y
-Target
.Y
) <= 128) then
6922 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
6923 SetAIFlag('GORIGHT', '1');
6924 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6925 SetAIFlag('GOLEFT', '1');
6929 // Âûáèðàåì óãîë ââåðõ:
6930 if FDirection
= TDirection
.D_LEFT
then
6931 angle
:= ANGLE_LEFTUP
6933 angle
:= ANGLE_RIGHTUP
;
6935 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6936 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6938 // Åñëè ïðè óãëå ââåðõ ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
6939 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6940 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128), //96
6941 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6942 Target
.Rect
.Width
, Target
.Rect
.Height
) and
6943 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6944 begin // òî íóæíî ñòðåëÿòü ââåðõ
6945 SetAIFlag('NEEDFIRE', '1');
6946 SetAIFlag('NEEDSEEUP', '1');
6949 // Âûáèðàåì óãîë âíèç:
6950 if FDirection
= TDirection
.D_LEFT
then
6951 angle
:= ANGLE_LEFTDOWN
6953 angle
:= ANGLE_RIGHTDOWN
;
6955 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6956 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6958 // Åñëè ïðè óãëå âíèç ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
6959 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6960 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
6961 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6962 Target
.Rect
.Width
, Target
.Rect
.Height
) and
6963 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6964 begin // òî íóæíî ñòðåëÿòü âíèç
6965 SetAIFlag('NEEDFIRE', '1');
6966 SetAIFlag('NEEDSEEDOWN', '1');
6969 // Åñëè öåëü âèäíî è îíà íà òàêîé æå âûñîòå:
6970 if Target
.Visible
and
6971 (y1
+4 < Target
.Y
+Target
.Rect
.Y
+Target
.Rect
.Height
) and
6972 (y1
-4 > Target
.Y
+Target
.Rect
.Y
) then
6974 // Åñëè èäåì â ñòîðîíó öåëè, òî íàäî ñòðåëÿòü:
6975 if ((FDirection
= TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) or
6976 ((FDirection
= TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6977 begin // òî íóæíî ñòðåëÿòü âïåðåä
6978 SetAIFlag('NEEDFIRE', '1');
6979 SetAIFlag('NEEDSEEDOWN', '');
6980 SetAIFlag('NEEDSEEUP', '');
6982 // Åñëè öåëü â ïðåäåëàõ "ýêðàíà" è ñëîæíîñòü ïîçâîëÿåò ïðûæêè ñáëèæåíèÿ:
6983 if Abs(FObj
.X
-Target
.X
) < Trunc(gPlayerScreenSize
.X
*0.75) then
6984 if GetRnd(FDifficult
.CloseJump
) then
6985 begin // òî åñëè ïîâåçåò - ïðûãàåì (îñîáåííî, åñëè áëèçêî)
6986 if Abs(FObj
.X
-Target
.X
) < 128 then
6990 if Random(a
) = 0 then
6991 SetAIFlag('NEEDJUMP', '1');
6995 // Åñëè öåëü âñå åùå åñòü:
6996 if Target
.UID
<> 0 then
6997 if gTime
-FLastVisible
> 2000 then // Åñëè âèäåëè äàâíî
6998 Target
.UID
:= 0 // òî çàáûòü öåëü
6999 else // Åñëè âèäåëè íåäàâíî
7000 begin // íî öåëü óáèëè
7001 if Target
.IsPlayer
then
7002 begin // Öåëü - èãðîê
7003 pla
:= g_Player_Get(Target
.UID
);
7004 if (pla
= nil) or (not pla
.alive
) or pla
.NoTarget
or
7005 (pla
.FMegaRulez
[MR_INVIS
] >= gTime
) then
7006 Target
.UID
:= 0; // òî çàáûòü öåëü
7009 begin // Öåëü - ìîíñòð
7010 mon
:= g_Monsters_ByUID(Target
.UID
);
7011 if (mon
= nil) or (not mon
.alive
) then
7012 Target
.UID
:= 0; // òî çàáûòü öåëü
7015 end; // if Target.UID <> 0
7017 FTargetUID
:= Target
.UID
;
7019 // Åñëè âîçìîæíûõ öåëåé íåò:
7020 // (Àòàêà ÷åãî-íèáóäü ñëåâà èëè ñïðàâà)
7021 if targets
= nil then
7022 if GetAIFlag('ATTACKLEFT') <> '' then
7023 begin // Åñëè íóæíî àòàêîâàòü íàëåâî
7024 RemoveAIFlag('ATTACKLEFT');
7026 SetAIFlag('NEEDJUMP', '1');
7028 if RunDirection() = TDirection
.D_RIGHT
then
7029 begin // Èäåì íå â òó ñòîðîíó
7030 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
7031 begin // Åñëè çäîðîâû, òî, âîçìîæíî, ñòðåëÿåì áåæèì âëåâî è ñòðåëÿåì
7032 SetAIFlag('NEEDFIRE', '1');
7033 SetAIFlag('GOLEFT', '1');
7037 begin // Èäåì â íóæíóþ ñòîðîíó
7038 if GetRnd(FDifficult
.InvisFire
) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
7039 SetAIFlag('NEEDFIRE', '1');
7040 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
7041 SetAIFlag('GORIGHT', '1');
7045 if GetAIFlag('ATTACKRIGHT') <> '' then
7046 begin // Åñëè íóæíî àòàêîâàòü íàïðàâî
7047 RemoveAIFlag('ATTACKRIGHT');
7049 SetAIFlag('NEEDJUMP', '1');
7051 if RunDirection() = TDirection
.D_LEFT
then
7052 begin // Èäåì íå â òó ñòîðîíó
7053 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
7054 begin // Åñëè çäîðîâû, òî, âîçìîæíî, áåæèì âïðàâî è ñòðåëÿåì
7055 SetAIFlag('NEEDFIRE', '1');
7056 SetAIFlag('GORIGHT', '1');
7061 if GetRnd(FDifficult
.InvisFire
) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
7062 SetAIFlag('NEEDFIRE', '1');
7063 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
7064 SetAIFlag('GOLEFT', '1');
7068 //HACK! (does it belongs there?)
7069 RealizeCurrentWeapon();
7071 // Åñëè åñòü âîçìîæíûå öåëè:
7072 // (Ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëÿì)
7073 if (targets
<> nil) and (GetAIFlag('NEEDFIRE') <> '') then
7074 for a
:= 0 to High(targets
) do
7076 // Åñëè ìîæåì ñòðåëÿòü ïî äèàãîíàëè:
7077 if GetRnd(FDifficult
.DiagFire
) then
7079 // Èùåì öåëü ñâåðõó è ñòðåëÿåì, åñëè åñòü:
7080 if FDirection
= TDirection
.D_LEFT
then
7081 angle
:= ANGLE_LEFTUP
7083 angle
:= ANGLE_RIGHTUP
;
7085 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7086 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7088 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
7089 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
7090 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
7091 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
7092 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
7094 SetAIFlag('NEEDFIRE', '1');
7095 SetAIFlag('NEEDSEEUP', '1');
7098 // Èùåì öåëü ñíèçó è ñòðåëÿåì, åñëè åñòü:
7099 if FDirection
= TDirection
.D_LEFT
then
7100 angle
:= ANGLE_LEFTDOWN
7102 angle
:= ANGLE_RIGHTDOWN
;
7104 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7105 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7107 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
7108 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
7109 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
7110 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
7111 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
7113 SetAIFlag('NEEDFIRE', '1');
7114 SetAIFlag('NEEDSEEDOWN', '1');
7118 // Åñëè öåëü "ïåðåä íîñîì", òî ñòðåëÿåì:
7119 if targets
[a
].Line
and targets
[a
].Visible
and
7120 (((FDirection
= TDirection
.D_LEFT
) and (targets
[a
].X
< FObj
.X
)) or
7121 ((FDirection
= TDirection
.D_RIGHT
) and (targets
[a
].X
> FObj
.X
))) then
7123 SetAIFlag('NEEDFIRE', '1');
7128 // Åñëè ëåòèò ïóëÿ, òî, âîçìîæíî, ïîäïðûãèâàåì:
7129 if g_Weapon_Danger(FUID
, FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
,
7130 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
,
7131 40+GetInterval(FDifficult
.Cover
, 40)) then
7132 SetAIFlag('NEEDJUMP', '1');
7134 // Åñëè êîí÷èëèñü ïàòîðíû, òî íóæíî ñìåíèòü îðóæèå:
7135 ammo
:= GetAmmoByWeapon(FCurrWeap
);
7136 if ((FCurrWeap
= WEAPON_SHOTGUN2
) and (ammo
< 2)) or
7137 ((FCurrWeap
= WEAPON_BFG
) and (ammo
< 40)) or
7139 SetAIFlag('SELECTWEAPON', '1');
7141 // Åñëè íóæíî ñìåíèòü îðóæèå, òî âûáèðàåì íóæíîå:
7142 if GetAIFlag('SELECTWEAPON') = '1' then
7145 RemoveAIFlag('SELECTWEAPON');
7149 procedure TBot
.Update();
7162 // Ïðîâåðÿåì, îòêëþ÷¸í ëè AI áîòîâ
7163 if (g_debug_BotAIOff
= 1) and (Team
= TEAM_RED
) then
7165 if (g_debug_BotAIOff
= 2) and (Team
= TEAM_BLUE
) then
7167 if g_debug_BotAIOff
= 3 then
7177 RealizeCurrentWeapon();
7184 procedure TBot
.ReleaseKey(Key
: Byte);
7193 function TBot
.KeyPressed(Key
: Word): Boolean;
7195 Result
:= FKeys
[Key
].Pressed
;
7198 function TBot
.GetAIFlag(aName
: String20
): String20
;
7204 aName
:= LowerCase(aName
);
7206 if FAIFlags
<> nil then
7207 for a
:= 0 to High(FAIFlags
) do
7208 if LowerCase(FAIFlags
[a
].Name
) = aName
then
7210 Result
:= FAIFlags
[a
].Value
;
7215 procedure TBot
.RemoveAIFlag(aName
: String20
);
7219 if FAIFlags
= nil then Exit
;
7221 aName
:= LowerCase(aName
);
7223 for a
:= 0 to High(FAIFlags
) do
7224 if LowerCase(FAIFlags
[a
].Name
) = aName
then
7226 if a
<> High(FAIFlags
) then
7227 for b
:= a
to High(FAIFlags
)-1 do
7228 FAIFlags
[b
] := FAIFlags
[b
+1];
7230 SetLength(FAIFlags
, Length(FAIFlags
)-1);
7235 procedure TBot
.SetAIFlag(aName
, fValue
: String20
);
7243 aName
:= LowerCase(aName
);
7245 if FAIFlags
<> nil then
7246 for a
:= 0 to High(FAIFlags
) do
7247 if LowerCase(FAIFlags
[a
].Name
) = aName
then
7253 if ok
then FAIFlags
[a
].Value
:= fValue
7256 SetLength(FAIFlags
, Length(FAIFlags
)+1);
7257 with FAIFlags
[High(FAIFlags
)] do
7265 procedure TBot
.UpdateMove
;
7267 procedure GoLeft(Time
: Word = 1);
7269 ReleaseKey(KEY_LEFT
);
7270 ReleaseKey(KEY_RIGHT
);
7271 PressKey(KEY_LEFT
, Time
);
7272 SetDirection(TDirection
.D_LEFT
);
7275 procedure GoRight(Time
: Word = 1);
7277 ReleaseKey(KEY_LEFT
);
7278 ReleaseKey(KEY_RIGHT
);
7279 PressKey(KEY_RIGHT
, Time
);
7280 SetDirection(TDirection
.D_RIGHT
);
7283 function Rnd(a
: Word): Boolean;
7285 Result
:= Random(a
) = 0;
7288 procedure Turn(Time
: Word = 1200);
7290 if RunDirection() = TDirection
.D_LEFT
then GoRight(Time
) else GoLeft(Time
);
7295 ReleaseKey(KEY_LEFT
);
7296 ReleaseKey(KEY_RIGHT
);
7299 function CanRunLeft(): Boolean;
7301 Result
:= not CollideLevel(-1, 0);
7304 function CanRunRight(): Boolean;
7306 Result
:= not CollideLevel(1, 0);
7309 function CanRun(): Boolean;
7311 if RunDirection() = TDirection
.D_LEFT
then Result
:= CanRunLeft() else Result
:= CanRunRight();
7314 procedure Jump(Time
: Word = 30);
7316 PressKey(KEY_JUMP
, Time
);
7319 function NearHole(): Boolean;
7323 { TODO 5 : Ëåñòíèöû }
7324 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7325 for x
:= 1 to PLAYER_RECT
.Width
do
7326 if (not StayOnStep(x
*sx
, 0)) and
7327 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7328 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7337 function BorderHole(): Boolean;
7341 { TODO 5 : Ëåñòíèöû }
7342 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7343 for x
:= 1 to PLAYER_RECT
.Width
do
7344 if (not StayOnStep(x
*sx
, 0)) and
7345 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7346 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7348 for xx
:= x
to x
+32 do
7349 if CollideLevel(xx
*sx
, PLAYER_RECT
.Height
) then
7359 function NearDeepHole(): Boolean;
7365 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7368 for x
:= 1 to PLAYER_RECT
.Width
do
7369 if (not StayOnStep(x
*sx
, 0)) and
7370 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7371 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7373 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
7375 if CollideLevel(x
*sx
, PLAYER_RECT
.Height
*y
) then Exit
;
7380 end else Result
:= False;
7383 function OverDeepHole(): Boolean;
7390 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
7392 if CollideLevel(0, PLAYER_RECT
.Height
*y
) then Exit
;
7399 function OnGround(): Boolean;
7401 Result
:= StayOnStep(0, 0) or CollideLevel(0, 1);
7404 function OnLadder(): Boolean;
7406 Result
:= FullInStep(0, 0);
7409 function BelowLadder(): Boolean;
7411 Result
:= (FullInStep(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) and
7412 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
7413 (FullInStep(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) and
7414 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
7417 function BelowLiftUp(): Boolean;
7419 Result
:= ((FullInLift(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) = -1) and
7420 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
7421 ((FullInLift(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) = -1) and
7422 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
7425 function OnTopLift(): Boolean;
7427 Result
:= (FullInLift(0, 0) = -1) and (FullInLift(0, -32) = 0);
7430 function CanJumpOver(): Boolean;
7434 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7438 if not CollideLevel(sx
, 0) then Exit
;
7440 for y
:= 1 to BOT_MAXJUMP
do
7441 if CollideLevel(0, -y
) then Exit
else
7442 if not CollideLevel(sx
, -y
) then
7449 function CanJumpUp(Dist
: ShortInt): Boolean;
7456 if CollideLevel(Dist
, 0) then Exit
;
7459 for y
:= 0 to BOT_MAXJUMP
do
7460 if CollideLevel(Dist
, -y
) then
7469 for yy
:= y
+1 to BOT_MAXJUMP
do
7470 if not CollideLevel(Dist
, -yy
) then
7479 for y
:= 0 to BOT_MAXJUMP
do
7480 if CollideLevel(0, -y
) then
7488 if y
< yy
then Exit
;
7493 function IsSafeTrigger(): Boolean;
7498 if gTriggers
= nil then
7500 for a
:= 0 to High(gTriggers
) do
7501 if Collide(gTriggers
[a
].X
,
7504 gTriggers
[a
].Height
) and
7505 (gTriggers
[a
].TriggerType
in [TRIGGER_EXIT
, TRIGGER_CLOSEDOOR
,
7506 TRIGGER_CLOSETRAP
, TRIGGER_TRAP
,
7507 TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
,
7508 TRIGGER_ONOFF
, TRIGGER_SPAWNMONSTER
,
7509 TRIGGER_DAMAGE
, TRIGGER_SHOT
]) then
7514 // Âîçìîæíî, íàæèìàåì êíîïêó:
7515 if Rnd(16) and IsSafeTrigger() then
7518 // Åñëè ïîä ëèôòîì èëè ñòóïåíüêàìè, òî, âîçìîæíî, ïðûãàåì:
7519 if OnLadder() or ((BelowLadder() or BelowLiftUp()) and Rnd(8)) then
7521 ReleaseKey(KEY_LEFT
);
7522 ReleaseKey(KEY_RIGHT
);
7526 // Èäåì âëåâî, åñëè íàäî áûëî:
7527 if GetAIFlag('GOLEFT') <> '' then
7529 RemoveAIFlag('GOLEFT');
7530 if CanRunLeft() then
7534 // Èäåì âïðàâî, åñëè íàäî áûëî:
7535 if GetAIFlag('GORIGHT') <> '' then
7537 RemoveAIFlag('GORIGHT');
7538 if CanRunRight() then
7542 // Åñëè âûëåòåëè çà êàðòó, òî ïðîáóåì âåðíóòüñÿ:
7543 if FObj
.X
< -32 then
7546 if FObj
.X
+32 > gMapInfo
.Width
then
7549 // Ïðûãàåì, åñëè íàäî áûëî:
7550 if GetAIFlag('NEEDJUMP') <> '' then
7553 RemoveAIFlag('NEEDJUMP');
7556 // Ñìîòðèì ââåðõ, åñëè íàäî áûëî:
7557 if GetAIFlag('NEEDSEEUP') <> '' then
7560 ReleaseKey(KEY_DOWN
);
7561 PressKey(KEY_UP
, 20);
7562 RemoveAIFlag('NEEDSEEUP');
7565 // Ñìîòðèì âíèç, åñëè íàäî áûëî:
7566 if GetAIFlag('NEEDSEEDOWN') <> '' then
7569 ReleaseKey(KEY_DOWN
);
7570 PressKey(KEY_DOWN
, 20);
7571 RemoveAIFlag('NEEDSEEDOWN');
7574 // Åñëè íóæíî áûëî â äûðó è ìû íå íà çåìëå, òî ïîêîðíî ëåòèì:
7575 if GetAIFlag('GOINHOLE') <> '' then
7576 if not OnGround() then
7578 ReleaseKey(KEY_LEFT
);
7579 ReleaseKey(KEY_RIGHT
);
7580 RemoveAIFlag('GOINHOLE');
7581 SetAIFlag('FALLINHOLE', '1');
7584 // Åñëè ïàäàëè è äîñòèãëè çåìëè, òî õâàòèò ïàäàòü:
7585 if GetAIFlag('FALLINHOLE') <> '' then
7587 RemoveAIFlag('FALLINHOLE');
7589 // Åñëè ëåòåëè ïðÿìî è ñåé÷àñ íå íà ëåñòíèöå èëè íà âåðøèíå ëèôòà, òî îòõîäèì â ñòîðîíó:
7590 if not (KeyPressed(KEY_LEFT
) or KeyPressed(KEY_RIGHT
)) then
7591 if GetAIFlag('FALLINHOLE') = '' then
7592 if (not OnLadder()) or (FObj
.Vel
.Y
>= 0) or (OnTopLift()) then
7598 // Åñëè íà çåìëå è ìîæíî ïîäïðûãíóòü, òî, âîçìîæíî, ïðûãàåì:
7600 CanJumpUp(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*32) and
7604 // Åñëè íà çåìëå è âîçëå äûðû (ãëóáèíà > 2 ðîñòîâ èãðîêà):
7605 if OnGround() and NearHole() then
7606 if NearDeepHole() then // Åñëè ýòî áåçäíà
7608 0..3: Turn(); // Áåæèì îáðàòíî
7609 4: Jump(); // Ïðûãàåì
7610 5: begin // Ïðûãàåì îáðàòíî
7615 else // Ýòî íå áåçäíà è ìû åùå íå ëåòèì òóäà
7616 if GetAIFlag('GOINHOLE') = '' then
7618 0: Turn(); // Íå íóæíî òóäà
7619 1: Jump(); // Âäðóã ïîâåçåò - ïðûãàåì
7620 else // Åñëè ÿìà ñ ãðàíèöåé, òî ïðè ñëó÷àå ìîæíî òóäà ïðûãíóòü
7621 if BorderHole() then
7622 SetAIFlag('GOINHOLE', '1');
7625 // Åñëè íà çåìëå, íî íåêóäà èäòè:
7626 if (not CanRun()) and OnGround() then
7628 // Åñëè ìû íà ëåñòíèöå èëè ìîæíî ïåðåïðûãíóòü, òî ïðûãàåì:
7629 if CanJumpOver() or OnLadder() then
7631 else // èíà÷å ïîïûòàåìñÿ â äðóãóþ ñòîðîíó
7632 if Random(2) = 0 then
7634 if IsSafeTrigger() then
7640 // Îñòàëîñü ìàëî âîçäóõà:
7641 if FAir
< 36 * 2 then
7644 // Âûáèðàåìñÿ èç êèñëîòû, åñëè íåò êîñòþìà, îáîæãëèñü, èëè ìàëî çäîðîâüÿ:
7645 if (FMegaRulez
[MR_SUIT
] < gTime
) and ((FLastHit
= HIT_ACID
) or (Healthy() <= 1)) then
7646 if BodyInAcid(0, 0) then
7650 function TBot
.FullInStep(XInc
, YInc
: Integer): Boolean;
7652 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
7653 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_STEP
, False);
7656 {function TBot.NeedItem(Item: Byte): Byte;
7661 procedure TBot
.SelectWeapon(Dist
: Integer);
7665 function HaveAmmo(weapon
: Byte): Boolean;
7668 WEAPON_PISTOL
: Result
:= FAmmo
[A_BULLETS
] >= 1;
7669 WEAPON_SHOTGUN1
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7670 WEAPON_SHOTGUN2
: Result
:= FAmmo
[A_SHELLS
] >= 2;
7671 WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
] >= 10;
7672 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
] >= 1;
7673 WEAPON_PLASMA
: Result
:= FAmmo
[A_CELLS
] >= 10;
7674 WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
] >= 40;
7675 WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7676 WEAPON_FLAMETHROWER
: Result
:= FAmmo
[A_FUEL
] >= 1;
7677 else Result
:= True;
7682 if Dist
= -1 then Dist
:= BOT_LONGDIST
;
7684 if Dist
> BOT_LONGDIST
then
7685 begin // Äàëüíèé áîé
7687 if FWeapon
[FDifficult
.WeaponPrior
[a
]] and HaveAmmo(FDifficult
.WeaponPrior
[a
]) then
7689 FSelectedWeapon
:= FDifficult
.WeaponPrior
[a
];
7693 else //if Dist > BOT_UNSAFEDIST then
7694 begin // Áëèæíèé áîé
7696 if FWeapon
[FDifficult
.CloseWeaponPrior
[a
]] and HaveAmmo(FDifficult
.CloseWeaponPrior
[a
]) then
7698 FSelectedWeapon
:= FDifficult
.CloseWeaponPrior
[a
];
7705 if FWeapon[FDifficult.SafeWeaponPrior[a]] and HaveAmmo(FDifficult.SafeWeaponPrior[a]) then
7707 FSelectedWeapon := FDifficult.SafeWeaponPrior[a];
7713 function TBot
.PickItem(ItemType
: Byte; force
: Boolean; var remove
: Boolean): Boolean;
7715 Result
:= inherited PickItem(ItemType
, force
, remove
);
7717 if Result
then SetAIFlag('SELECTWEAPON', '1');
7720 function TBot
.Heal(value
: Word; Soft
: Boolean): Boolean;
7722 Result
:= inherited Heal(value
, Soft
);
7725 function TBot
.Healthy(): Byte;
7727 if FMegaRulez
[MR_INVUL
] >= gTime
then Result
:= 3
7728 else if (FHealth
> 80) or ((FHealth
> 50) and (FArmor
> 20)) then Result
:= 3
7729 else if (FHealth
> 50) then Result
:= 2
7730 else if (FHealth
> 20) then Result
:= 1
7734 function TBot
.TargetOnScreen(TX
, TY
: Integer): Boolean;
7736 Result
:= (Abs(FObj
.X
-TX
) <= Trunc(gPlayerScreenSize
.X
*0.6)) and
7737 (Abs(FObj
.Y
-TY
) <= Trunc(gPlayerScreenSize
.Y
*0.6));
7740 procedure TBot
.OnDamage(Angle
: SmallInt);
7748 if (Angle
= 0) or (Angle
= 180) then
7751 if (g_GetUIDType(FLastSpawnerUID
) = UID_PLAYER
) and
7752 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
) then
7754 pla
:= g_Player_Get(FLastSpawnerUID
);
7755 ok
:= not TargetOnScreen(pla
.FObj
.X
+ PLAYER_RECT
.X
,
7756 pla
.FObj
.Y
+ PLAYER_RECT
.Y
);
7759 if (g_GetUIDType(FLastSpawnerUID
) = UID_MONSTER
) and
7760 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
) then
7762 mon
:= g_Monsters_ByUID(FLastSpawnerUID
);
7763 ok
:= not TargetOnScreen(mon
.Obj
.X
+ mon
.Obj
.Rect
.X
,
7764 mon
.Obj
.Y
+ mon
.Obj
.Rect
.Y
);
7769 SetAIFlag('ATTACKLEFT', '1')
7771 SetAIFlag('ATTACKRIGHT', '1');
7775 function TBot
.RunDirection(): TDirection
;
7777 if Abs(Vel
.X
) >= 1 then
7779 if Vel
.X
> 0 then Result
:= TDirection
.D_RIGHT
else Result
:= TDirection
.D_LEFT
;
7781 Result
:= FDirection
;
7784 function TBot
.GetRnd(a
: Byte): Boolean;
7786 if a
= 0 then Result
:= False
7787 else if a
= 255 then Result
:= True
7788 else Result
:= Random(256) > 255-a
;
7791 function TBot
.GetInterval(a
: Byte; radius
: SmallInt): SmallInt;
7793 Result
:= Round((255-a
)/255*radius
*(Random(2)-1));
7797 procedure TDifficult
.save (st
: TStream
);
7799 utils
.writeInt(st
, Byte(DiagFire
));
7800 utils
.writeInt(st
, Byte(InvisFire
));
7801 utils
.writeInt(st
, Byte(DiagPrecision
));
7802 utils
.writeInt(st
, Byte(FlyPrecision
));
7803 utils
.writeInt(st
, Byte(Cover
));
7804 utils
.writeInt(st
, Byte(CloseJump
));
7805 st
.WriteBuffer(WeaponPrior
[Low(WeaponPrior
)], sizeof(WeaponPrior
));
7806 st
.WriteBuffer(CloseWeaponPrior
[Low(CloseWeaponPrior
)], sizeof(CloseWeaponPrior
));
7809 procedure TDifficult
.load (st
: TStream
);
7811 DiagFire
:= utils
.readByte(st
);
7812 InvisFire
:= utils
.readByte(st
);
7813 DiagPrecision
:= utils
.readByte(st
);
7814 FlyPrecision
:= utils
.readByte(st
);
7815 Cover
:= utils
.readByte(st
);
7816 CloseJump
:= utils
.readByte(st
);
7817 st
.ReadBuffer(WeaponPrior
[Low(WeaponPrior
)], sizeof(WeaponPrior
));
7818 st
.ReadBuffer(CloseWeaponPrior
[Low(CloseWeaponPrior
)], sizeof(CloseWeaponPrior
));
7822 procedure TBot
.SaveState (st
: TStream
);
7827 inherited SaveState(st
);
7828 utils
.writeSign(st
, 'BOT0');
7830 utils
.writeInt(st
, Byte(FSelectedWeapon
));
7832 utils
.writeInt(st
, Word(FTargetUID
));
7833 // Âðåìÿ ïîòåðè öåëè
7834 utils
.writeInt(st
, LongWord(FLastVisible
));
7835 // Êîëè÷åñòâî ôëàãîâ ÈÈ
7836 dw
:= Length(FAIFlags
);
7837 utils
.writeInt(st
, LongInt(dw
));
7839 for i
:= 0 to dw
-1 do
7841 utils
.writeStr(st
, FAIFlags
[i
].Name
, 20);
7842 utils
.writeStr(st
, FAIFlags
[i
].Value
, 20);
7844 // Íàñòðîéêè ñëîæíîñòè
7845 FDifficult
.save(st
);
7849 procedure TBot
.LoadState (st
: TStream
);
7854 inherited LoadState(st
);
7855 if not utils
.checkSign(st
, 'BOT0') then raise XStreamError
.Create('invalid bot signature');
7857 FSelectedWeapon
:= utils
.readByte(st
);
7859 FTargetUID
:= utils
.readWord(st
);
7860 // Âðåìÿ ïîòåðè öåëè
7861 FLastVisible
:= utils
.readLongWord(st
);
7862 // Êîëè÷åñòâî ôëàãîâ ÈÈ
7863 dw
:= utils
.readLongInt(st
);
7864 if (dw
< 0) or (dw
> 16384) then raise XStreamError
.Create('invalid number of bot AI flags');
7865 SetLength(FAIFlags
, dw
);
7867 for i
:= 0 to dw
-1 do
7869 FAIFlags
[i
].Name
:= utils
.readStr(st
, 20);
7870 FAIFlags
[i
].Value
:= utils
.readStr(st
, 20);
7872 // Íàñòðîéêè ñëîæíîñòè
7873 FDifficult
.load(st
);
7878 conRegVar('cheat_berserk_autoswitch', @gBerserkAutoswitch
, 'autoswitch to fist when berserk pack taken', '', true, true);