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 PLAYER_BURN_TIME
= 110;
102 PLAYER1_DEF_COLOR
: TRGB
= (R
:64; G
:175; B
:48);
103 PLAYER2_DEF_COLOR
: TRGB
= (R
:96; G
:96; B
:96);
120 TPlayerStatArray
= Array of TPlayerStat
;
122 TPlayerSavedState
= record
130 Ammo
: Array [A_BULLETS
..A_HIGH
] of Word;
131 MaxAmmo
: Array [A_BULLETS
..A_HIGH
] of Word;
132 Weapon
: Array [WP_FIRST
..WP_LAST
] of Boolean;
133 Rulez
: Set of R_ITEM_BACKPACK
..R_BERSERK
;
142 TPlayer
= class{$IFDEF USE_MEMPOOL}(TPoolObject
){$ENDIF}
150 FDirection
: TDirection
;
158 FMonsterKills
: Integer;
164 FCanJetpack
: Boolean;
170 FNextWeapDelay
: Byte; // frames
171 FBFGFireCounter
: SmallInt;
172 FLastSpawnerUID
: Word;
176 FSpectatePlayer
: Integer;
177 FFirePainTime
: Integer;
180 FSavedState
: TPlayerSavedState
;
182 FModel
: TPlayerModel
;
183 FPunchAnim
: TAnimation
;
186 FActionForce
: Boolean;
187 FActionChanged
: Boolean;
189 FFireAngle
: SmallInt;
191 FShellTimer
: Integer;
193 FSawSound
: TPlayableSound
;
194 FSawSoundIdle
: TPlayableSound
;
195 FSawSoundHit
: TPlayableSound
;
196 FSawSoundSelect
: TPlayableSound
;
197 FFlameSoundOn
: TPlayableSound
;
198 FFlameSoundOff
: TPlayableSound
;
199 FFlameSoundWork
: TPlayableSound
;
200 FJetSoundOn
: TPlayableSound
;
201 FJetSoundOff
: TPlayableSound
;
202 FJetSoundFly
: TPlayableSound
;
206 FJustTeleported
: Boolean;
208 mEDamageType
: Integer;
211 function CollideLevel(XInc
, YInc
: Integer): Boolean;
212 function StayOnStep(XInc
, YInc
: Integer): Boolean;
213 function HeadInLiquid(XInc
, YInc
: Integer): Boolean;
214 function BodyInLiquid(XInc
, YInc
: Integer): Boolean;
215 function BodyInAcid(XInc
, YInc
: Integer): Boolean;
216 function FullInLift(XInc
, YInc
: Integer): Integer;
217 {procedure CollideItem();}
218 procedure FlySmoke(Times
: DWORD
= 1);
219 procedure OnFireFlame(Times
: DWORD
= 1);
220 function GetAmmoByWeapon(Weapon
: Byte): Word;
221 procedure SetAction(Action
: Byte; Force
: Boolean = False);
222 procedure OnDamage(Angle
: SmallInt); virtual;
223 function firediry(): Integer;
226 procedure Run(Direction
: TDirection
);
227 procedure NextWeapon();
228 procedure PrevWeapon();
235 function getNextWeaponIndex (): Byte; // return 255 for "no switch"
236 procedure resetWeaponQueue ();
237 function hasAmmoForWeapon (weapon
: Byte): Boolean;
239 procedure doDamage (v
: Integer);
241 function followCorpse(): Boolean;
244 FDamageBuffer
: Integer;
246 FAmmo
: Array [A_BULLETS
..A_HIGH
] of Word;
247 FMaxAmmo
: Array [A_BULLETS
..A_HIGH
] of Word;
248 FWeapon
: Array [WP_FIRST
..WP_LAST
] of Boolean;
249 FRulez
: Set of R_ITEM_BACKPACK
..R_BERSERK
;
251 FMegaRulez
: Array [MR_SUIT
..MR_MAX
] of DWORD
;
252 FReloading
: Array [WP_FIRST
..WP_LAST
] of Word;
253 FTime
: Array [T_RESPAWN
..T_FLAGCAP
] of DWORD
;
254 FKeys
: Array [KEY_LEFT
..KEY_CHAT
] of TKeyState
;
256 FPreferredTeam
: Byte;
259 FWantsInGame
: Boolean;
264 FActualModelName
: string;
273 // debug: viewport offset
274 viewPortX
, viewPortY
, viewPortW
, viewPortH
: Integer;
276 function isValidViewPort (): Boolean; inline;
278 constructor Create(); virtual;
279 destructor Destroy(); override;
280 procedure Respawn(Silent
: Boolean; Force
: Boolean = False); virtual;
281 function GetRespawnPoint(): Byte;
282 procedure PressKey(Key
: Byte; Time
: Word = 1);
283 procedure ReleaseKeys();
284 procedure SetModel(ModelName
: String);
285 procedure SetColor(Color
: TRGB
);
286 procedure SetWeapon(W
: Byte);
287 function IsKeyPressed(K
: Byte): Boolean;
288 function GetKeys(): Byte;
289 function PickItem(ItemType
: Byte; arespawn
: Boolean; var remove
: Boolean): Boolean; virtual;
290 function Collide(X
, Y
: Integer; Width
, Height
: Word): Boolean; overload
;
291 function Collide(Panel
: TPanel
): Boolean; overload
;
292 function Collide(X
, Y
: Integer): Boolean; overload
;
293 procedure SetDirection(Direction
: TDirection
);
294 procedure GetSecret();
295 function TeleportTo(X
, Y
: Integer; silent
: Boolean; dir
: Byte): Boolean;
297 procedure Push(vx
, vy
: Integer);
298 procedure ChangeModel(ModelName
: String);
299 procedure SwitchTeam
;
300 procedure ChangeTeam(Team
: Byte);
302 function GetFlag(Flag
: Byte): Boolean;
303 procedure SetFlag(Flag
: Byte);
304 function DropFlag(Silent
: Boolean = True): Boolean;
305 procedure AllRulez(Health
: Boolean);
306 procedure RestoreHealthArmor();
307 procedure FragCombo();
308 procedure GiveItem(ItemType
: Byte);
309 procedure Damage(value
: Word; SpawnerUID
: Word; vx
, vy
: Integer; t
: Byte); virtual;
310 function Heal(value
: Word; Soft
: Boolean): Boolean; virtual;
311 procedure MakeBloodVector(Count
: Word; VelX
, VelY
: Integer);
312 procedure MakeBloodSimple(Count
: Word);
313 procedure Kill(KillType
: Byte; SpawnerUID
: Word; t
: Byte);
314 procedure Reset(Force
: Boolean);
315 procedure Spectate(NoMove
: Boolean = False);
316 procedure SwitchNoClip
;
317 procedure SoftReset();
318 procedure Draw(); virtual;
319 procedure DrawPain();
320 procedure DrawPickup();
321 procedure DrawRulez();
323 procedure DrawIndicator();
324 procedure DrawBubble();
326 procedure Update(); virtual;
327 procedure RememberState();
328 procedure RecallState();
329 procedure SaveState (st
: TStream
); virtual;
330 procedure LoadState (st
: TStream
); virtual;
331 procedure PauseSounds(Enable
: Boolean);
332 procedure NetFire(Wpn
: Byte; X
, Y
, AX
, AY
: Integer; WID
: Integer = -1);
333 procedure DoLerp(Level
: Integer = 2);
334 procedure SetLerp(XTo
, YTo
: Integer);
335 procedure QueueWeaponSwitch(Weapon
: Byte);
336 procedure RealizeCurrentWeapon();
340 procedure JetpackOff
;
341 procedure CatchFire(Attacker
: Word; Timeout
: Integer = PLAYER_BURN_TIME
);
343 //WARNING! this does nothing for now, but still call it!
344 procedure positionChanged (); //WARNING! call this after entity position was changed, or coldet will not work right!
346 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
347 procedure moveBy (dx
, dy
: Integer); inline;
350 property Vel
: TPoint2i read FObj
.Vel
;
351 property Obj
: TObj read FObj
;
353 property Name
: String read FName write FName
;
354 property Model
: TPlayerModel read FModel
;
355 property Health
: Integer read FHealth write FHealth
;
356 property Lives
: Byte read FLives write FLives
;
357 property Armor
: Integer read FArmor write FArmor
;
358 property Air
: Integer read FAir write FAir
;
359 property JetFuel
: Integer read FJetFuel write FJetFuel
;
360 property Frags
: Integer read FFrags write FFrags
;
361 property Death
: Integer read FDeath write FDeath
;
362 property Kills
: Integer read FKills write FKills
;
363 property CurrWeap
: Byte read FCurrWeap write FCurrWeap
;
364 property MonsterKills
: Integer read FMonsterKills write FMonsterKills
;
365 property Secrets
: Integer read FSecrets
;
366 property GodMode
: Boolean read FGodMode write FGodMode
;
367 property NoTarget
: Boolean read FNoTarget write FNoTarget
;
368 property NoReload
: Boolean read FNoReload write FNoReload
;
369 property alive
: Boolean read FAlive write FAlive
;
370 property Flag
: Byte read FFlag
;
371 property Team
: Byte read FTeam write FTeam
;
372 property Direction
: TDirection read FDirection
;
373 property GameX
: Integer read FObj
.X write FObj
.X
;
374 property GameY
: Integer read FObj
.Y write FObj
.Y
;
375 property GameVelX
: Integer read FObj
.Vel
.X write FObj
.Vel
.X
;
376 property GameVelY
: Integer read FObj
.Vel
.Y write FObj
.Vel
.Y
;
377 property GameAccelX
: Integer read FObj
.Accel
.X write FObj
.Accel
.X
;
378 property GameAccelY
: Integer read FObj
.Accel
.Y write FObj
.Accel
.Y
;
379 property IncCam
: Integer read FIncCam write FIncCam
;
380 property UID
: Word read FUID write FUID
;
381 property JustTeleported
: Boolean read FJustTeleported write FJustTeleported
;
382 property NetTime
: LongWord read FNetTime write FNetTime
;
385 property eName
: String read FName write FName
;
386 property eHealth
: Integer read FHealth write FHealth
;
387 property eLives
: Byte read FLives write FLives
;
388 property eArmor
: Integer read FArmor write FArmor
;
389 property eAir
: Integer read FAir write FAir
;
390 property eJetFuel
: Integer read FJetFuel write FJetFuel
;
391 property eFrags
: Integer read FFrags write FFrags
;
392 property eDeath
: Integer read FDeath write FDeath
;
393 property eKills
: Integer read FKills write FKills
;
394 property eCurrWeap
: Byte read FCurrWeap write FCurrWeap
;
395 property eMonsterKills
: Integer read FMonsterKills write FMonsterKills
;
396 property eSecrets
: Integer read FSecrets write FSecrets
;
397 property eGodMode
: Boolean read FGodMode write FGodMode
;
398 property eNoTarget
: Boolean read FNoTarget write FNoTarget
;
399 property eNoReload
: Boolean read FNoReload write FNoReload
;
400 property eAlive
: Boolean read FAlive write FAlive
;
401 property eFlag
: Byte read FFlag
;
402 property eTeam
: Byte read FTeam write FTeam
;
403 property eDirection
: TDirection read FDirection
;
404 property eGameX
: Integer read FObj
.X write FObj
.X
;
405 property eGameY
: Integer read FObj
.Y write FObj
.Y
;
406 property eGameVelX
: Integer read FObj
.Vel
.X write FObj
.Vel
.X
;
407 property eGameVelY
: Integer read FObj
.Vel
.Y write FObj
.Vel
.Y
;
408 property eGameAccelX
: Integer read FObj
.Accel
.X write FObj
.Accel
.X
;
409 property eGameAccelY
: Integer read FObj
.Accel
.Y write FObj
.Accel
.Y
;
410 property eIncCam
: Integer read FIncCam write FIncCam
;
411 property eUID
: Word read FUID
;
412 property eJustTeleported
: Boolean read FJustTeleported
;
413 property eNetTime
: LongWord read FNetTime
;
415 // set this before assigning something to `eDamage`
416 property eDamageType
: Integer read mEDamageType write mEDamageType
;
417 property eDamage
: Integer write doDamage
;
428 WeaponPrior
: packed array [WP_FIRST
..WP_LAST
] of Byte;
429 CloseWeaponPrior
: packed array [WP_FIRST
..WP_LAST
] of Byte;
430 //SafeWeaponPrior: Array [WP_FIRST..WP_LAST] of Byte;
433 procedure save (st
: TStream
);
434 procedure load (st
: TStream
);
442 TBot
= class(TPlayer
)
444 FSelectedWeapon
: Byte;
447 FAIFlags
: Array of TAIFlag
;
448 FDifficult
: TDifficult
;
450 function GetRnd(a
: Byte): Boolean;
451 function GetInterval(a
: Byte; radius
: SmallInt): SmallInt;
452 function RunDirection(): TDirection
;
453 function FullInStep(XInc
, YInc
: Integer): Boolean;
454 //function NeedItem(Item: Byte): Byte;
455 procedure SelectWeapon(Dist
: Integer);
456 procedure SetAIFlag(aName
, fValue
: String20
);
457 function GetAIFlag(aName
: String20
): String20
;
458 procedure RemoveAIFlag(aName
: String20
);
459 function Healthy(): Byte;
460 procedure UpdateMove();
461 procedure UpdateCombat();
462 function KeyPressed(Key
: Word): Boolean;
463 procedure ReleaseKey(Key
: Byte);
464 function TargetOnScreen(TX
, TY
: Integer): Boolean;
465 procedure OnDamage(Angle
: SmallInt); override;
468 procedure Respawn(Silent
: Boolean; Force
: Boolean = False); override;
469 constructor Create(); override;
470 destructor Destroy(); override;
471 procedure Draw(); override;
472 function PickItem(ItemType
: Byte; force
: Boolean; var remove
: Boolean): Boolean; override;
473 function Heal(value
: Word; Soft
: Boolean): Boolean; override;
474 procedure Update(); override;
475 procedure SaveState (st
: TStream
); override;
476 procedure LoadState (st
: TStream
); override;
488 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
489 procedure moveBy (dx
, dy
: Integer); inline;
491 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
505 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
506 procedure moveBy (dx
, dy
: Integer); inline;
508 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
511 TCorpse
= class{$IFDEF USE_MEMPOOL}(TPoolObject
){$ENDIF}
520 FAnimation
: TAnimation
;
521 FAnimationMask
: TAnimation
;
524 constructor Create(X
, Y
: Integer; ModelName
: String; aMess
: Boolean);
525 destructor Destroy(); override;
526 procedure Damage(Value
: Word; vx
, vy
: Integer);
529 procedure SaveState (st
: TStream
);
530 procedure LoadState (st
: TStream
);
532 procedure getMapBox (out x
, y
, w
, h
: Integer); inline;
533 procedure moveBy (dx
, dy
: Integer); inline;
535 procedure positionChanged (); inline; //WARNING! call this after entity position was changed, or coldet will not work right!
537 function ObjPtr (): PObj
; inline;
539 property Obj
: TObj read FObj
; // copies object
540 property State
: Byte read FState
;
541 property Mess
: Boolean read FMess
;
544 TTeamStat
= Array [TEAM_RED
..TEAM_BLUE
] of
550 gPlayers
: Array of TPlayer
;
551 gCorpses
: Array of TCorpse
;
552 gGibs
: Array of TGib
;
553 gShells
: Array of TShell
;
554 gTeamStat
: TTeamStat
;
555 gFly
: Boolean = False;
556 gAimLine
: Boolean = False;
557 gChatBubble
: Byte = 0;
558 gPlayerIndicator
: Boolean = True;
562 MAX_RUNVEL
: Integer = 8;
563 VEL_JUMP
: Integer = 10;
564 SHELL_TIMEOUT
: Cardinal = 60000;
566 function Lerp(X
, Y
, Factor
: Integer): Integer;
568 procedure g_Gibs_SetMax(Count
: Word);
569 function g_Gibs_GetMax(): Word;
570 procedure g_Corpses_SetMax(Count
: Word);
571 function g_Corpses_GetMax(): Word;
572 procedure g_Shells_SetMax(Count
: Word);
573 function g_Shells_GetMax(): Word;
575 procedure g_Player_Init();
576 procedure g_Player_Free();
577 function g_Player_Create(ModelName
: String; Color
: TRGB
; Team
: Byte; Bot
: Boolean): Word;
578 function g_Player_CreateFromState (st
: TStream
): Word;
579 procedure g_Player_Remove(UID
: Word);
580 procedure g_Player_ResetTeams();
581 procedure g_Player_UpdateAll();
582 procedure g_Player_DrawAll();
583 procedure g_Player_DrawDebug(p
: TPlayer
);
584 procedure g_Player_DrawHealth();
585 procedure g_Player_RememberAll();
586 procedure g_Player_ResetAll(Force
, Silent
: Boolean);
587 function g_Player_Get(UID
: Word): TPlayer
;
588 function g_Player_GetCount(): Byte;
589 function g_Player_GetStats(): TPlayerStatArray
;
590 function g_Player_ValidName(Name
: String): Boolean;
591 procedure g_Player_CreateCorpse(Player
: TPlayer
);
592 procedure g_Player_CreateGibs(fX
, fY
: Integer; ModelName
: String; fColor
: TRGB
);
593 procedure g_Player_CreateShell(fX
, fY
, dX
, dY
: Integer; T
: Byte);
594 procedure g_Player_UpdatePhysicalObjects();
595 procedure g_Player_DrawCorpses();
596 procedure g_Player_DrawShells();
597 procedure g_Player_RemoveAllCorpses();
598 procedure g_Player_Corpses_SaveState (st
: TStream
);
599 procedure g_Player_Corpses_LoadState (st
: TStream
);
600 procedure g_Player_ResetReady();
601 procedure g_Bot_Add(Team
, Difficult
: Byte; Handicap
: Integer = 100);
602 procedure g_Bot_AddList(Team
: Byte; lname
: ShortString; num
: Integer = -1; Handicap
: Integer = 100);
603 procedure g_Bot_MixNames();
604 procedure g_Bot_RemoveAll();
609 {$INCLUDE ../nogl/noGLuses.inc}
610 {$IFDEF ENABLE_HOLMES}
613 e_log
, g_map
, g_items
, g_console
, g_gfx
, Math
,
614 g_options
, g_triggers
, g_menu
, g_game
, g_grid
,
615 wadreader
, g_main
, g_monsters
, CONFIG
, g_language
,
616 g_net
, g_netmsg
, g_window
,
619 const PLR_SAVE_VERSION
= 0;
629 diag_precision
: Byte;
633 w_prior1
: Array [WP_FIRST
..WP_LAST
] of Byte;
634 w_prior2
: Array [WP_FIRST
..WP_LAST
] of Byte;
635 w_prior3
: Array [WP_FIRST
..WP_LAST
] of Byte;
639 TIME_RESPAWN1
= 1500;
640 TIME_RESPAWN2
= 2000;
641 TIME_RESPAWN3
= 3000;
644 JET_MAX
= 540; // ~30 sec
645 PLAYER_SUIT_TIME
= 30000;
646 PLAYER_INVUL_TIME
= 30000;
647 PLAYER_INVIS_TIME
= 35000;
648 FRAG_COMBO_TIME
= 3000;
652 ANGLE_RIGHTDOWN
= -35;
654 ANGLE_LEFTDOWN
= -145;
655 PLAYER_HEADRECT
: TRectWH
= (X
:24; Y
:12; Width
:20; Height
:12);
656 WEAPONPOINT
: Array [TDirection
] of TDFPoint
= ((X
:16; Y
:32), (X
:47; Y
:32));
659 BOT_UNSAFEDIST
= 128;
660 TEAMCOLOR
: Array [TEAM_RED
..TEAM_BLUE
] of TRGB
= ((R
:255; G
:0; B
:0),
662 DIFFICULT_EASY
: TDifficult
= (DiagFire
: 32; InvisFire
: 32; DiagPrecision
: 32;
663 FlyPrecision
: 32; Cover
: 32; CloseJump
: 32;
664 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
665 DIFFICULT_MEDIUM
: TDifficult
= (DiagFire
: 127; InvisFire
: 127; DiagPrecision
: 127;
666 FlyPrecision
: 127; Cover
: 127; CloseJump
: 127;
667 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
668 DIFFICULT_HARD
: TDifficult
= (DiagFire
: 255; InvisFire
: 255; DiagPrecision
: 255;
669 FlyPrecision
: 255; Cover
: 255; CloseJump
: 255;
670 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
671 WEAPON_PRIOR1
: Array [WP_FIRST
..WP_LAST
] of Byte =
672 (WEAPON_FLAMETHROWER
, WEAPON_SUPERPULEMET
,
673 WEAPON_SHOTGUN2
, WEAPON_SHOTGUN1
,
674 WEAPON_CHAINGUN
, WEAPON_PLASMA
, WEAPON_ROCKETLAUNCHER
,
675 WEAPON_BFG
, WEAPON_PISTOL
, WEAPON_SAW
, WEAPON_KASTET
);
676 WEAPON_PRIOR2
: Array [WP_FIRST
..WP_LAST
] of Byte =
677 (WEAPON_FLAMETHROWER
, WEAPON_SUPERPULEMET
,
678 WEAPON_BFG
, WEAPON_ROCKETLAUNCHER
,
679 WEAPON_SHOTGUN2
, WEAPON_PLASMA
, WEAPON_SHOTGUN1
,
680 WEAPON_CHAINGUN
, WEAPON_PISTOL
, WEAPON_SAW
, WEAPON_KASTET
);
681 //WEAPON_PRIOR3: Array [WP_FIRST..WP_LAST] of Byte =
682 // (WEAPON_FLAMETHROWER, WEAPON_SUPERPULEMET,
683 // WEAPON_BFG, WEAPON_PLASMA, WEAPON_SHOTGUN2,
684 // WEAPON_CHAINGUN, WEAPON_SHOTGUN1, WEAPON_SAW,
685 // WEAPON_ROCKETLAUNCHER, WEAPON_PISTOL, WEAPON_KASTET);
686 WEAPON_RELOAD
: Array [WP_FIRST
..WP_LAST
] of Byte =
687 (5, 2, 6, 18, 36, 2, 12, 2, 14, 2, 2);
689 PLAYER_SIGNATURE
= $52594C50; // 'PLYR'
690 CORPSE_SIGNATURE
= $50524F43; // 'CORP'
692 BOTNAMES_FILENAME
= 'botnames.txt';
693 BOTLIST_FILENAME
= 'botlist.txt';
697 MaxCorpses
: Word = 20;
698 MaxShells
: Word = 300;
699 CurrentGib
: Integer = 0;
700 CurrentShell
: Integer = 0;
701 BotNames
: Array of String;
702 BotList
: Array of TBotProfile
;
705 function Lerp(X
, Y
, Factor
: Integer): Integer;
707 Result
:= X
+ ((Y
- X
) div Factor
);
710 function SameTeam(UID1
, UID2
: Word): Boolean;
714 if (UID1
> UID_MAX_PLAYER
) or (UID1
<= UID_MAX_GAME
) or
715 (UID2
> UID_MAX_PLAYER
) or (UID2
<= UID_MAX_GAME
) then Exit
;
717 if (g_Player_Get(UID1
) = nil) or (g_Player_Get(UID2
) = nil) then Exit
;
719 if ((g_Player_Get(UID1
).Team
= TEAM_NONE
) or
720 (g_Player_Get(UID2
).Team
= TEAM_NONE
)) then Exit
;
722 Result
:= g_Player_Get(UID1
).FTeam
= g_Player_Get(UID2
).FTeam
;
725 procedure g_Gibs_SetMax(Count
: Word);
728 SetLength(gGibs
, Count
);
730 if CurrentGib
>= Count
then
734 function g_Gibs_GetMax(): Word;
739 procedure g_Shells_SetMax(Count
: Word);
742 SetLength(gShells
, Count
);
744 if CurrentShell
>= Count
then
748 function g_Shells_GetMax(): Word;
754 procedure g_Corpses_SetMax(Count
: Word);
757 SetLength(gCorpses
, Count
);
760 function g_Corpses_GetMax(): Word;
762 Result
:= MaxCorpses
;
765 function g_Player_Create(ModelName
: String; Color
: TRGB
; Team
: Byte; Bot
: Boolean): Word;
775 // Åñòü ëè ìåñòî â gPlayers:
776 if gPlayers
<> nil then
777 for a
:= 0 to High(gPlayers
) do
778 if gPlayers
[a
] = nil then
784 // Íåò ìåñòà - ðàñøèðÿåì gPlayers:
787 SetLength(gPlayers
, Length(gPlayers
)+1);
791 // Ñîçäàåì îáúåêò èãðîêà:
793 gPlayers
[a
] := TBot
.Create()
795 gPlayers
[a
] := TPlayer
.Create();
798 gPlayers
[a
].FActualModelName
:= ModelName
;
799 gPlayers
[a
].SetModel(ModelName
);
801 // Íåò ìîäåëè - ñîçäàíèå íå âîçìîæíî:
802 if gPlayers
[a
].FModel
= nil then
806 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], [ModelName
]));
810 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
811 if Random(2) = 0 then
815 gPlayers
[a
].FPreferredTeam
:= Team
;
817 case gGameSettings
.GameMode
of
818 GM_DM
: gPlayers
[a
].FTeam
:= TEAM_NONE
;
820 GM_CTF
: gPlayers
[a
].FTeam
:= gPlayers
[a
].FPreferredTeam
;
822 GM_COOP
: gPlayers
[a
].FTeam
:= TEAM_COOP
;
825 // Åñëè êîìàíäíàÿ èãðà - êðàñèì ìîäåëü â öâåò êîìàíäû:
826 gPlayers
[a
].FColor
:= Color
;
827 if gPlayers
[a
].FTeam
in [TEAM_RED
, TEAM_BLUE
] then
828 gPlayers
[a
].FModel
.Color
:= TEAMCOLOR
[gPlayers
[a
].FTeam
]
830 gPlayers
[a
].FModel
.Color
:= Color
;
832 gPlayers
[a
].FUID
:= g_CreateUID(UID_PLAYER
);
833 gPlayers
[a
].FAlive
:= False;
835 Result
:= gPlayers
[a
].FUID
;
838 function g_Player_CreateFromState (st
: TStream
): Word;
845 if (st
= nil) then exit
; //???
848 if not utils
.checkSign(st
, 'PLYR') then raise XStreamError
.Create('invalid player signature');
849 if (utils
.readByte(st
) <> PLR_SAVE_VERSION
) then raise XStreamError
.Create('invalid player version');
852 Bot
:= utils
.readBool(st
);
857 // Åñòü ëè ìåñòî â gPlayers:
858 for a
:= 0 to High(gPlayers
) do if (gPlayers
[a
] = nil) then begin ok
:= true; break
; end;
860 // Íåò ìåñòà - ðàñøèðÿåì gPlayers
863 SetLength(gPlayers
, Length(gPlayers
)+1);
867 // Ñîçäàåì îáúåêò èãðîêà
869 gPlayers
[a
] := TBot
.Create()
871 gPlayers
[a
] := TPlayer
.Create();
872 gPlayers
[a
].FIamBot
:= Bot
;
873 gPlayers
[a
].FPhysics
:= True;
876 gPlayers
[a
].FUID
:= utils
.readWord(st
);
878 gPlayers
[a
].FName
:= utils
.readStr(st
);
880 gPlayers
[a
].FTeam
:= utils
.readByte(st
);
881 gPlayers
[a
].FPreferredTeam
:= gPlayers
[a
].FTeam
;
883 gPlayers
[a
].FAlive
:= utils
.readBool(st
);
884 // Èçðàñõîäîâàë ëè âñå æèçíè
885 gPlayers
[a
].FNoRespawn
:= utils
.readBool(st
);
887 b
:= utils
.readByte(st
);
888 if b
= 1 then gPlayers
[a
].FDirection
:= TDirection
.D_LEFT
else gPlayers
[a
].FDirection
:= TDirection
.D_RIGHT
; // b = 2
890 gPlayers
[a
].FHealth
:= utils
.readLongInt(st
);
892 gPlayers
[a
].FHandicap
:= utils
.readLongInt(st
);
894 gPlayers
[a
].FLives
:= utils
.readByte(st
);
896 gPlayers
[a
].FArmor
:= utils
.readLongInt(st
);
898 gPlayers
[a
].FAir
:= utils
.readLongInt(st
);
900 gPlayers
[a
].FJetFuel
:= utils
.readLongInt(st
);
902 gPlayers
[a
].FPain
:= utils
.readLongInt(st
);
904 gPlayers
[a
].FKills
:= utils
.readLongInt(st
);
906 gPlayers
[a
].FMonsterKills
:= utils
.readLongInt(st
);
908 gPlayers
[a
].FFrags
:= utils
.readLongInt(st
);
910 gPlayers
[a
].FFragCombo
:= utils
.readByte(st
);
911 // Âðåìÿ ïîñëåäíåãî ôðàãà
912 gPlayers
[a
].FLastFrag
:= utils
.readLongWord(st
);
914 gPlayers
[a
].FDeath
:= utils
.readLongInt(st
);
916 gPlayers
[a
].FFlag
:= utils
.readByte(st
);
918 gPlayers
[a
].FSecrets
:= utils
.readLongInt(st
);
920 gPlayers
[a
].FCurrWeap
:= utils
.readByte(st
);
921 // Ñëåäóþùåå æåëàåìîå îðóæèå
922 gPlayers
[a
].FNextWeap
:= utils
.readWord(st
);
924 gPlayers
[a
].FNextWeapDelay
:= utils
.readByte(st
);
926 gPlayers
[a
].FBFGFireCounter
:= utils
.readSmallInt(st
);
928 gPlayers
[a
].FDamageBuffer
:= utils
.readLongInt(st
);
929 // Ïîñëåäíèé óäàðèâøèé
930 gPlayers
[a
].FLastSpawnerUID
:= utils
.readWord(st
);
931 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà
932 gPlayers
[a
].FLastHit
:= utils
.readByte(st
);
934 Obj_LoadState(@gPlayers
[a
].FObj
, st
);
935 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ
936 for i
:= A_BULLETS
to A_HIGH
do gPlayers
[a
].FAmmo
[i
] := utils
.readWord(st
);
937 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ
938 for i
:= A_BULLETS
to A_HIGH
do gPlayers
[a
].FMaxAmmo
[i
] := utils
.readWord(st
);
940 for i
:= WP_FIRST
to WP_LAST
do gPlayers
[a
].FWeapon
[i
] := utils
.readBool(st
);
941 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ
942 for i
:= WP_FIRST
to WP_LAST
do gPlayers
[a
].FReloading
[i
] := utils
.readWord(st
);
944 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_ITEM_BACKPACK
);
945 // Íàëè÷èå êðàñíîãî êëþ÷à
946 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_KEY_RED
);
947 // Íàëè÷èå çåëåíîãî êëþ÷à
948 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_KEY_GREEN
);
949 // Íàëè÷èå ñèíåãî êëþ÷à
950 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_KEY_BLUE
);
952 if utils
.readBool(st
) then Include(gPlayers
[a
].FRulez
, R_BERSERK
);
953 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ
954 for i
:= MR_SUIT
to MR_MAX
do gPlayers
[a
].FMegaRulez
[i
] := utils
.readLongWord(st
);
955 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà
956 for i
:= T_RESPAWN
to T_FLAGCAP
do gPlayers
[a
].FTime
[i
] := utils
.readLongWord(st
);
959 gPlayers
[a
].FActualModelName
:= utils
.readStr(st
);
961 gPlayers
[a
].FColor
.R
:= utils
.readByte(st
);
962 gPlayers
[a
].FColor
.G
:= utils
.readByte(st
);
963 gPlayers
[a
].FColor
.B
:= utils
.readByte(st
);
964 // Îáíîâëÿåì ìîäåëü èãðîêà
965 gPlayers
[a
].SetModel(gPlayers
[a
].FActualModelName
);
967 // Íåò ìîäåëè - ñîçäàíèå íåâîçìîæíî
968 if (gPlayers
[a
].FModel
= nil) then
972 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], [gPlayers
[a
].FActualModelName
]));
976 // Åñëè êîìàíäíàÿ èãðà - êðàñèì ìîäåëü â öâåò êîìàíäû
977 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
978 gPlayers
[a
].FModel
.Color
:= TEAMCOLOR
[gPlayers
[a
].FTeam
]
980 gPlayers
[a
].FModel
.Color
:= gPlayers
[a
].FColor
;
982 result
:= gPlayers
[a
].FUID
;
986 procedure g_Player_ResetTeams();
990 if g_Game_IsClient
then
992 if gPlayers
= nil then
994 for a
:= Low(gPlayers
) to High(gPlayers
) do
995 if gPlayers
[a
] <> nil then
996 case gGameSettings
.GameMode
of
998 gPlayers
[a
].ChangeTeam(TEAM_NONE
);
1000 if not (gPlayers
[a
].Team
in [TEAM_RED
, TEAM_BLUE
]) then
1001 if gPlayers
[a
].FPreferredTeam
in [TEAM_RED
, TEAM_BLUE
] then
1002 gPlayers
[a
].ChangeTeam(gPlayers
[a
].FPreferredTeam
)
1005 gPlayers
[a
].ChangeTeam(TEAM_RED
)
1007 gPlayers
[a
].ChangeTeam(TEAM_BLUE
);
1010 gPlayers
[a
].ChangeTeam(TEAM_COOP
);
1014 procedure g_Bot_Add(Team
, Difficult
: Byte; Handicap
: Integer = 100);
1017 _name
, _model
: String;
1020 if not g_Game_IsServer
then Exit
;
1022 // Ñïèñîê íàçâàíèé ìîäåëåé:
1023 m
:= g_PlayerModel_GetNames();
1028 if (gGameSettings
.GameType
= GT_SINGLE
) or (gGameSettings
.GameMode
= GM_COOP
) then
1029 Team
:= TEAM_COOP
// COOP
1031 if gGameSettings
.GameMode
= GM_DM
then
1032 Team
:= TEAM_NONE
// DM
1034 if Team
= TEAM_NONE
then // CTF / TDM
1036 // Àâòîáàëàíñ êîìàíä:
1040 for a
:= 0 to High(gPlayers
) do
1041 if gPlayers
[a
] <> nil then
1043 if gPlayers
[a
].Team
= TEAM_RED
then
1046 if gPlayers
[a
].Team
= TEAM_BLUE
then
1056 if Random(2) = 0 then
1062 // Âûáèðàåì áîòó èìÿ:
1064 if BotNames
<> nil then
1065 for a
:= 0 to High(BotNames
) do
1066 if g_Player_ValidName(BotNames
[a
]) then
1068 _name
:= BotNames
[a
];
1072 // Èìåíè íåò, çàäàåì ñëó÷àéíîå:
1075 _name
:= Format('DFBOT%.2d', [Random(100)]);
1076 until g_Player_ValidName(_name
);
1078 // Âûáèðàåì ñëó÷àéíóþ ìîäåëü:
1079 _model
:= m
[Random(Length(m
))];
1082 with g_Player_Get(g_Player_Create(_model
,
1083 _RGB(Min(Random(9)*32, 255),
1084 Min(Random(9)*32, 255),
1085 Min(Random(9)*32, 255)),
1086 Team
, True)) as TBot
do
1091 1: FDifficult
:= DIFFICULT_EASY
;
1092 2: FDifficult
:= DIFFICULT_MEDIUM
;
1093 else FDifficult
:= DIFFICULT_HARD
;
1096 for a
:= WP_FIRST
to WP_LAST
do
1098 FDifficult
.WeaponPrior
[a
] := WEAPON_PRIOR1
[a
];
1099 FDifficult
.CloseWeaponPrior
[a
] := WEAPON_PRIOR2
[a
];
1100 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
1103 FHandicap
:= Handicap
;
1105 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [Name
]), True);
1107 if g_Game_IsNet
then MH_SEND_PlayerCreate(UID
);
1108 if g_Game_IsServer
and (gGameSettings
.MaxLives
> 0) then
1113 procedure g_Bot_AddList(Team
: Byte; lName
: ShortString; num
: Integer = -1; Handicap
: Integer = 100);
1116 _name
, _model
: String;
1119 if not g_Game_IsServer
then Exit
;
1121 // Ñïèñîê íàçâàíèé ìîäåëåé:
1122 m
:= g_PlayerModel_GetNames();
1127 if (gGameSettings
.GameType
= GT_SINGLE
) or (gGameSettings
.GameMode
= GM_COOP
) then
1128 Team
:= TEAM_COOP
// COOP
1130 if gGameSettings
.GameMode
= GM_DM
then
1131 Team
:= TEAM_NONE
// DM
1133 if Team
= TEAM_NONE
then
1134 Team
:= BotList
[num
].team
; // CTF / TDM
1136 // Âûáèðàåì íàñòðîéêè áîòà èç ñïèñêà ïî íîìåðó èëè èìåíè:
1137 lName
:= AnsiLowerCase(lName
);
1138 if (num
< 0) or (num
> Length(BotList
)-1) then
1140 if (num
= -1) and (lName
<> '') and (BotList
<> nil) then
1141 for a
:= 0 to High(BotList
) do
1142 if AnsiLowerCase(BotList
[a
].name
) = lName
then
1151 _name
:= BotList
[num
].name
;
1152 // Çàíÿòî - âûáèðàåì ñëó÷àéíîå:
1153 if not g_Player_ValidName(_name
) then
1155 _name
:= Format('DFBOT%.2d', [Random(100)]);
1156 until g_Player_ValidName(_name
);
1159 _model
:= BotList
[num
].model
;
1160 // Íåò òàêîé - âûáèðàåì ñëó÷àéíóþ:
1161 if not InSArray(_model
, m
) then
1162 _model
:= m
[Random(Length(m
))];
1165 with g_Player_Get(g_Player_Create(_model
, BotList
[num
].color
, Team
, True)) as TBot
do
1169 FDifficult
.DiagFire
:= BotList
[num
].diag_fire
;
1170 FDifficult
.InvisFire
:= BotList
[num
].invis_fire
;
1171 FDifficult
.DiagPrecision
:= BotList
[num
].diag_precision
;
1172 FDifficult
.FlyPrecision
:= BotList
[num
].fly_precision
;
1173 FDifficult
.Cover
:= BotList
[num
].cover
;
1174 FDifficult
.CloseJump
:= BotList
[num
].close_jump
;
1176 FHandicap
:= Handicap
;
1178 for a
:= WP_FIRST
to WP_LAST
do
1180 FDifficult
.WeaponPrior
[a
] := BotList
[num
].w_prior1
[a
];
1181 FDifficult
.CloseWeaponPrior
[a
] := BotList
[num
].w_prior2
[a
];
1182 //FDifficult.SafeWeaponPrior[a] := BotList[num].w_prior3[a];
1185 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [Name
]), True);
1187 if g_Game_IsNet
then MH_SEND_PlayerCreate(UID
);
1191 procedure g_Bot_RemoveAll();
1195 if not g_Game_IsServer
then Exit
;
1196 if gPlayers
= nil then Exit
;
1198 for a
:= 0 to High(gPlayers
) do
1199 if gPlayers
[a
] <> nil then
1200 if gPlayers
[a
] is TBot
then
1202 gPlayers
[a
].Lives
:= 0;
1203 gPlayers
[a
].Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
1204 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [gPlayers
[a
].Name
]), True);
1205 g_Player_Remove(gPlayers
[a
].FUID
);
1211 procedure g_Bot_MixNames();
1216 if BotNames
<> nil then
1217 for a
:= 0 to High(BotNames
) do
1219 b
:= Random(Length(BotNames
));
1221 Botnames
[a
] := BotNames
[b
];
1226 procedure g_Player_Remove(UID
: Word);
1230 if gPlayers
= nil then Exit
;
1232 if g_Game_IsServer
and g_Game_IsNet
then
1233 MH_SEND_PlayerDelete(UID
);
1235 for i
:= 0 to High(gPlayers
) do
1236 if gPlayers
[i
] <> nil then
1237 if gPlayers
[i
].FUID
= UID
then
1239 if gPlayers
[i
] is TPlayer
then
1240 TPlayer(gPlayers
[i
]).Free()
1242 TBot(gPlayers
[i
]).Free();
1248 procedure g_Player_Init();
1258 if not FileExists(DataDir
+ BOTNAMES_FILENAME
) then
1261 // ×èòàåì âîçìîæíûå èìåíà áîòîâ èç ôàéëà:
1262 AssignFile(F
, DataDir
+ BOTNAMES_FILENAME
);
1273 SetLength(BotNames
, Length(BotNames
)+1);
1274 BotNames
[High(BotNames
)] := s
;
1282 // ×èòàåì ôàéë ñ ïàðàìåòðàìè áîòîâ:
1283 config
:= TConfig
.CreateFile(DataDir
+ BOTLIST_FILENAME
);
1287 while config
.SectionExists(IntToStr(a
)) do
1289 SetLength(BotList
, Length(BotList
)+1);
1291 with BotList
[High(BotList
)] do
1294 name
:= config
.ReadStr(IntToStr(a
), 'name', '');
1296 model
:= config
.ReadStr(IntToStr(a
), 'model', '');
1298 if config
.ReadStr(IntToStr(a
), 'team', 'red') = 'red' then
1303 sa
:= parse(config
.ReadStr(IntToStr(a
), 'color', ''));
1304 color
.R
:= StrToIntDef(sa
[0], 0);
1305 color
.G
:= StrToIntDef(sa
[1], 0);
1306 color
.B
:= StrToIntDef(sa
[2], 0);
1307 // Âåðîÿòíîñòü ñòðåëüáû ïîä óãëîì:
1308 diag_fire
:= config
.ReadInt(IntToStr(a
), 'diag_fire', 0);
1309 // Âåðîÿòíîñòü îòâåòíîãî îãíÿ ïî íåâèäèìîìó ñîïåðíèêó:
1310 invis_fire
:= config
.ReadInt(IntToStr(a
), 'invis_fire', 0);
1311 // Òî÷íîñòü ñòðåëüáû ïîä óãëîì:
1312 diag_precision
:= config
.ReadInt(IntToStr(a
), 'diag_precision', 0);
1313 // Òî÷íîñòü ñòðåëüáû â ïîëåòå:
1314 fly_precision
:= config
.ReadInt(IntToStr(a
), 'fly_precision', 0);
1315 // Òî÷íîñòü óêëîíåíèÿ îò ñíàðÿäîâ:
1316 cover
:= config
.ReadInt(IntToStr(a
), 'cover', 0);
1317 // Âåðîÿòíîñòü ïðûæêà ïðè ïðèáëèæåíèè ñîïåðíèêà:
1318 close_jump
:= config
.ReadInt(IntToStr(a
), 'close_jump', 0);
1319 // Ïðèîðèòåòû îðóæèÿ äëÿ äàëüíåãî áîÿ:
1320 sa
:= parse(config
.ReadStr(IntToStr(a
), 'w_prior1', ''));
1321 if Length(sa
) = 10 then
1323 w_prior1
[b
] := EnsureRange(StrToInt(sa
[b
]), 0, 9);
1324 // Ïðèîðèòåòû îðóæèÿ äëÿ áëèæíåãî áîÿ:
1325 sa
:= parse(config
.ReadStr(IntToStr(a
), 'w_prior2', ''));
1326 if Length(sa
) = 10 then
1328 w_prior2
[b
] := EnsureRange(StrToInt(sa
[b
]), 0, 9);
1330 {sa := parse(config.ReadStr(IntToStr(a), 'w_prior3', ''));
1331 if Length(sa) = 10 then
1333 w_prior3[b] := EnsureRange(StrToInt(sa[b]), 0, 9);}
1342 procedure g_Player_Free();
1346 if gPlayers
<> nil then
1348 for i
:= 0 to High(gPlayers
) do
1349 if gPlayers
[i
] <> nil then
1351 if gPlayers
[i
] is TPlayer
then
1352 TPlayer(gPlayers
[i
]).Free()
1354 TBot(gPlayers
[i
]).Free();
1365 procedure g_Player_UpdateAll();
1369 if gPlayers
= nil then Exit
;
1371 //e_WriteLog('***g_Player_UpdateAll: ENTER', MSG_WARNING);
1372 for i
:= 0 to High(gPlayers
) do
1374 if gPlayers
[i
] <> nil then
1376 if gPlayers
[i
] is TPlayer
then
1378 gPlayers
[i
].Update();
1379 gPlayers
[i
].RealizeCurrentWeapon(); // WARNING! DO NOT MOVE THIS INTO `Update()`!
1383 // bot updates weapons in `UpdateCombat()`
1384 TBot(gPlayers
[i
]).Update();
1388 //e_WriteLog('***g_Player_UpdateAll: EXIT', MSG_WARNING);
1391 procedure g_Player_DrawAll();
1395 if gPlayers
= nil then Exit
;
1397 for i
:= 0 to High(gPlayers
) do
1398 if gPlayers
[i
] <> nil then
1399 if gPlayers
[i
] is TPlayer
then gPlayers
[i
].Draw()
1400 else TBot(gPlayers
[i
]).Draw();
1403 procedure g_Player_DrawDebug(p
: TPlayer
);
1407 if p
= nil then Exit
;
1408 if (@p
.FObj
) = nil then Exit
;
1410 e_TextureFontGetSize(gStdFont
, fW
, fH
);
1412 e_TextureFontPrint(0, 0 , 'Pos X: ' + IntToStr(p
.FObj
.X
), gStdFont
);
1413 e_TextureFontPrint(0, fH
, 'Pos Y: ' + IntToStr(p
.FObj
.Y
), gStdFont
);
1414 e_TextureFontPrint(0, fH
* 2, 'Vel X: ' + IntToStr(p
.FObj
.Vel
.X
), gStdFont
);
1415 e_TextureFontPrint(0, fH
* 3, 'Vel Y: ' + IntToStr(p
.FObj
.Vel
.Y
), gStdFont
);
1416 e_TextureFontPrint(0, fH
* 4, 'Acc X: ' + IntToStr(p
.FObj
.Accel
.X
), gStdFont
);
1417 e_TextureFontPrint(0, fH
* 5, 'Acc Y: ' + IntToStr(p
.FObj
.Accel
.Y
), gStdFont
);
1420 procedure g_Player_DrawHealth();
1425 if gPlayers
= nil then Exit
;
1426 e_TextureFontGetSize(gStdFont
, fW
, fH
);
1428 for i
:= 0 to High(gPlayers
) do
1429 if gPlayers
[i
] <> nil then
1431 e_TextureFontPrint(gPlayers
[i
].FObj
.X
+ gPlayers
[i
].FObj
.Rect
.X
,
1432 gPlayers
[i
].FObj
.Y
+ gPlayers
[i
].FObj
.Rect
.Y
+ gPlayers
[i
].FObj
.Rect
.Height
- fH
* 2,
1433 IntToStr(gPlayers
[i
].FHealth
), gStdFont
);
1434 e_TextureFontPrint(gPlayers
[i
].FObj
.X
+ gPlayers
[i
].FObj
.Rect
.X
,
1435 gPlayers
[i
].FObj
.Y
+ gPlayers
[i
].FObj
.Rect
.Y
+ gPlayers
[i
].FObj
.Rect
.Height
- fH
,
1436 IntToStr(gPlayers
[i
].FArmor
), gStdFont
);
1440 function g_Player_Get(UID
: Word): TPlayer
;
1446 if gPlayers
= nil then
1449 for a
:= 0 to High(gPlayers
) do
1450 if gPlayers
[a
] <> nil then
1451 if gPlayers
[a
].FUID
= UID
then
1453 Result
:= gPlayers
[a
];
1458 function g_Player_GetCount(): Byte;
1464 if gPlayers
= nil then
1467 for a
:= 0 to High(gPlayers
) do
1468 if gPlayers
[a
] <> nil then
1469 Result
:= Result
+ 1;
1472 function g_Player_GetStats(): TPlayerStatArray
;
1478 if gPlayers
= nil then Exit
;
1480 for a
:= 0 to High(gPlayers
) do
1481 if gPlayers
[a
] <> nil then
1483 SetLength(Result
, Length(Result
)+1);
1484 with Result
[High(Result
)] do
1487 Ping
:= gPlayers
[a
].FPing
;
1488 Loss
:= gPlayers
[a
].FLoss
;
1489 Name
:= gPlayers
[a
].FName
;
1490 Team
:= gPlayers
[a
].FTeam
;
1491 Frags
:= gPlayers
[a
].FFrags
;
1492 Deaths
:= gPlayers
[a
].FDeath
;
1493 Kills
:= gPlayers
[a
].FKills
;
1494 Color
:= gPlayers
[a
].FModel
.Color
;
1495 Lives
:= gPlayers
[a
].FLives
;
1496 Spectator
:= gPlayers
[a
].FSpectator
;
1501 procedure g_Player_ResetReady();
1505 if not g_Game_IsServer
then Exit
;
1506 if gPlayers
= nil then Exit
;
1508 for a
:= 0 to High(gPlayers
) do
1509 if gPlayers
[a
] <> nil then
1511 gPlayers
[a
].FReady
:= False;
1512 if g_Game_IsNet
then
1513 MH_SEND_GameEvent(NET_EV_INTER_READY
, gPlayers
[a
].UID
, 'N');
1517 procedure g_Player_RememberAll
;
1521 for i
:= Low(gPlayers
) to High(gPlayers
) do
1522 if (gPlayers
[i
] <> nil) and gPlayers
[i
].alive
then
1523 gPlayers
[i
].RememberState
;
1526 procedure g_Player_ResetAll(Force
, Silent
: Boolean);
1530 gTeamStat
[TEAM_RED
].Goals
:= 0;
1531 gTeamStat
[TEAM_BLUE
].Goals
:= 0;
1533 if gPlayers
<> nil then
1534 for i
:= 0 to High(gPlayers
) do
1535 if gPlayers
[i
] <> nil then
1537 gPlayers
[i
].Reset(Force
);
1539 if gPlayers
[i
] is TPlayer
then
1541 if (not gPlayers
[i
].FSpectator
) or gPlayers
[i
].FWantsInGame
then
1542 gPlayers
[i
].Respawn(Silent
)
1544 gPlayers
[i
].Spectate();
1547 TBot(gPlayers
[i
]).Respawn(Silent
);
1551 procedure g_Player_CreateCorpse(Player
: TPlayer
);
1557 if Player
.alive
then
1560 // Ðàçðûâàåì ñâÿçü ñ ïðåæíèì òðóïîì:
1561 if gCorpses
<> nil then
1562 for i
:= 0 to High(gCorpses
) do
1563 if gCorpses
[i
] <> nil then
1564 if gCorpses
[i
].FPlayerUID
= Player
.FUID
then
1565 gCorpses
[i
].FPlayerUID
:= 0;
1567 if Player
.FObj
.Y
>= gMapInfo
.Height
+128 then
1572 if (FHealth
>= -50) or (gGibsCount
= 0) then
1574 if (gCorpses
= nil) or (Length(gCorpses
) = 0) then
1578 for find_id
:= 0 to High(gCorpses
) do
1579 if gCorpses
[find_id
] = nil then
1586 find_id
:= Random(Length(gCorpses
));
1588 gCorpses
[find_id
] := TCorpse
.Create(FObj
.X
, FObj
.Y
, FModel
.Name
, FHealth
< -20);
1589 gCorpses
[find_id
].FColor
:= FModel
.Color
;
1590 gCorpses
[find_id
].FObj
.Vel
:= FObj
.Vel
;
1591 gCorpses
[find_id
].FObj
.Accel
:= FObj
.Accel
;
1592 gCorpses
[find_id
].FPlayerUID
:= FUID
;
1595 g_Player_CreateGibs(FObj
.X
+ PLAYER_RECT_CX
,
1596 FObj
.Y
+ PLAYER_RECT_CY
,
1597 FModel
.Name
, FModel
.Color
);
1601 procedure g_Player_CreateShell(fX
, fY
, dX
, dY
: Integer; T
: Byte);
1605 if (gShells
= nil) or (Length(gShells
) = 0) then
1608 with gShells
[CurrentShell
] do
1614 if T
= SHELL_BULLET
then
1616 if g_Texture_Get('TEXTURE_SHELL_BULLET', SID
) then
1620 Obj
.Rect
.Width
:= 4;
1621 Obj
.Rect
.Height
:= 2;
1625 if g_Texture_Get('TEXTURE_SHELL_SHELL', SID
) then
1629 Obj
.Rect
.Width
:= 7;
1630 Obj
.Rect
.Height
:= 3;
1636 g_Obj_Push(@Obj
, dX
+ Random(4)-Random(4), dY
-Random(4));
1637 positionChanged(); // this updates spatial accelerators
1638 RAngle
:= Random(360);
1639 Timeout
:= gTime
+ SHELL_TIMEOUT
;
1641 if CurrentShell
>= High(gShells
) then
1648 procedure g_Player_CreateGibs(fX
, fY
: Integer; ModelName
: string; fColor
: TRGB
);
1651 GibsArray
: TGibsArray
;
1654 if (gGibs
= nil) or (Length(gGibs
) = 0) then
1656 if not g_PlayerModel_GetGibs(ModelName
, GibsArray
) then
1658 Blood
:= g_PlayerModel_GetBlood(ModelName
);
1660 for a
:= 0 to High(GibsArray
) do
1661 with gGibs
[CurrentGib
] do
1664 ID
:= GibsArray
[a
].ID
;
1665 MaskID
:= GibsArray
[a
].MaskID
;
1668 Obj
.Rect
:= GibsArray
[a
].Rect
;
1669 Obj
.X
:= fX
-GibsArray
[a
].Rect
.X
-(GibsArray
[a
].Rect
.Width
div 2);
1670 Obj
.Y
:= fY
-GibsArray
[a
].Rect
.Y
-(GibsArray
[a
].Rect
.Height
div 2);
1671 g_Obj_PushA(@Obj
, 25 + Random(10), Random(361));
1672 positionChanged(); // this updates spatial accelerators
1673 RAngle
:= Random(360);
1675 if gBloodCount
> 0 then
1676 g_GFX_Blood(fX
, fY
, 16*gBloodCount
+Random(5*gBloodCount
), -16+Random(33), -16+Random(33),
1677 Random(48), Random(48), Blood
.R
, Blood
.G
, Blood
.B
, Blood
.Kind
);
1679 if CurrentGib
>= High(gGibs
) then
1686 procedure g_Player_UpdatePhysicalObjects();
1692 procedure ShellSound_Bounce(X
, Y
: Integer; T
: Byte);
1697 if T
= SHELL_BULLET
then
1698 g_Sound_PlayExAt('SOUND_PLAYER_CASING' + IntToStr(k
), X
, Y
)
1700 g_Sound_PlayExAt('SOUND_PLAYER_SHELL' + IntToStr(k
), X
, Y
);
1705 if gGibs
<> nil then
1706 for i
:= 0 to High(gGibs
) do
1707 if gGibs
[i
].alive
then
1711 mr
:= g_Obj_Move(@Obj
, True, False, True);
1712 positionChanged(); // this updates spatial accelerators
1714 if WordBool(mr
and MOVE_FALLOUT
) then
1720 // Îòëåòàåò îò óäàðà î ñòåíó/ïîòîëîê/ïîë:
1721 if WordBool(mr
and MOVE_HITWALL
) then
1722 Obj
.Vel
.X
:= -(vel
.X
div 2);
1723 if WordBool(mr
and (MOVE_HITCEIL
or MOVE_HITLAND
)) then
1724 Obj
.Vel
.Y
:= -(vel
.Y
div 2);
1726 if (Obj
.Vel
.X
>= 0) then
1728 RAngle
:= RAngle
+ Abs(Obj
.Vel
.X
)*6 + Abs(Obj
.Vel
.Y
);
1729 if RAngle
>= 360 then
1730 RAngle
:= RAngle
mod 360;
1731 end else begin // Counter-clockwise
1732 RAngle
:= RAngle
- Abs(Obj
.Vel
.X
)*6 - Abs(Obj
.Vel
.Y
);
1734 RAngle
:= (360 - (Abs(RAngle
) mod 360)) mod 360;
1737 // Ñîïðîòèâëåíèå âîçäóõà äëÿ êóñêà òðóïà:
1738 if gTime
mod (GAME_TICK
*3) = 0 then
1739 Obj
.Vel
.X
:= z_dec(Obj
.Vel
.X
, 1);
1743 if gCorpses
<> nil then
1744 for i
:= 0 to High(gCorpses
) do
1745 if gCorpses
[i
] <> nil then
1746 if gCorpses
[i
].State
= CORPSE_STATE_REMOVEME
then
1752 gCorpses
[i
].Update();
1755 if gShells
<> nil then
1756 for i
:= 0 to High(gShells
) do
1757 if gShells
[i
].alive
then
1761 mr
:= g_Obj_Move(@Obj
, True, False, True);
1762 positionChanged(); // this updates spatial accelerators
1764 if WordBool(mr
and MOVE_FALLOUT
) or (gShells
[i
].Timeout
< gTime
) then
1770 // Îòëåòàåò îò óäàðà î ñòåíó/ïîòîëîê/ïîë:
1771 if WordBool(mr
and MOVE_HITWALL
) then
1773 Obj
.Vel
.X
:= -(vel
.X
div 2);
1774 if not WordBool(mr
and MOVE_INWATER
) then
1775 ShellSound_Bounce(Obj
.X
, Obj
.Y
, SType
);
1777 if WordBool(mr
and (MOVE_HITCEIL
or MOVE_HITLAND
)) then
1779 Obj
.Vel
.Y
:= -(vel
.Y
div 2);
1780 if Obj
.Vel
.X
<> 0 then Obj
.Vel
.X
:= Obj
.Vel
.X
div 2;
1781 if (Obj
.Vel
.X
= 0) and (Obj
.Vel
.Y
= 0) then
1783 if RAngle
mod 90 <> 0 then
1784 RAngle
:= (RAngle
div 90) * 90;
1786 else if not WordBool(mr
and MOVE_INWATER
) then
1787 ShellSound_Bounce(Obj
.X
, Obj
.Y
, SType
);
1790 if (Obj
.Vel
.X
>= 0) then
1792 RAngle
:= RAngle
+ Abs(Obj
.Vel
.X
)*8 + Abs(Obj
.Vel
.Y
);
1793 if RAngle
>= 360 then
1794 RAngle
:= RAngle
mod 360;
1795 end else begin // Counter-clockwise
1796 RAngle
:= RAngle
- Abs(Obj
.Vel
.X
)*8 - Abs(Obj
.Vel
.Y
);
1798 RAngle
:= (360 - (Abs(RAngle
) mod 360)) mod 360;
1804 procedure TGib
.getMapBox (out x
, y
, w
, h
: Integer); inline;
1806 x
:= Obj
.X
+Obj
.Rect
.X
;
1807 y
:= Obj
.Y
+Obj
.Rect
.Y
;
1808 w
:= Obj
.Rect
.Width
;
1809 h
:= Obj
.Rect
.Height
;
1812 procedure TGib
.moveBy (dx
, dy
: Integer); inline;
1814 if (dx
<> 0) or (dy
<> 0) then
1823 procedure TShell
.getMapBox (out x
, y
, w
, h
: Integer); inline;
1827 w
:= Obj
.Rect
.Width
;
1828 h
:= Obj
.Rect
.Height
;
1831 procedure TShell
.moveBy (dx
, dy
: Integer); inline;
1833 if (dx
<> 0) or (dy
<> 0) then
1842 procedure TGib
.positionChanged (); inline; begin end;
1843 procedure TShell
.positionChanged (); inline; begin end;
1846 procedure g_Player_DrawCorpses();
1851 if gGibs
<> nil then
1852 for i
:= 0 to High(gGibs
) do
1853 if gGibs
[i
].alive
then
1856 if not g_Obj_Collide(sX
, sY
, sWidth
, sHeight
, @Obj
) then
1859 a
.X
:= Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2);
1860 a
.y
:= Obj
.Rect
.Y
+(Obj
.Rect
.Height
div 2);
1862 e_DrawAdv(ID
, Obj
.X
, Obj
.Y
, 0, True, False, RAngle
, @a
, TMirrorType
.None
);
1865 e_DrawAdv(MaskID
, Obj
.X
, Obj
.Y
, 0, True, False, RAngle
, @a
, TMirrorType
.None
);
1871 if gCorpses
<> nil then
1872 for i
:= 0 to High(gCorpses
) do
1873 if gCorpses
[i
] <> nil then
1877 procedure g_Player_DrawShells();
1882 if gShells
<> nil then
1883 for i
:= 0 to High(gShells
) do
1884 if gShells
[i
].alive
then
1887 if not g_Obj_Collide(sX
, sY
, sWidth
, sHeight
, @Obj
) then
1893 e_DrawAdv(SpriteID
, Obj
.X
, Obj
.Y
, 0, True, False, RAngle
, @a
, TMirrorType
.None
);
1897 procedure g_Player_RemoveAllCorpses();
1903 SetLength(gGibs
, MaxGibs
);
1904 SetLength(gShells
, MaxGibs
);
1908 if gCorpses
<> nil then
1909 for i
:= 0 to High(gCorpses
) do
1913 SetLength(gCorpses
, MaxCorpses
);
1916 procedure g_Player_Corpses_SaveState (st
: TStream
);
1920 // Ñ÷èòàåì êîëè÷åñòâî ñóùåñòâóþùèõ òðóïîâ
1922 for i
:= 0 to High(gCorpses
) do if (gCorpses
[i
] <> nil) then Inc(count
);
1924 // Êîëè÷åñòâî òðóïîâ
1925 utils
.writeInt(st
, LongInt(count
));
1927 if (count
= 0) then exit
;
1930 for i
:= 0 to High(gCorpses
) do
1932 if gCorpses
[i
] <> nil then
1935 utils
.writeStr(st
, gCorpses
[i
].FModelName
);
1937 utils
.writeBool(st
, gCorpses
[i
].Mess
);
1938 // Ñîõðàíÿåì äàííûå òðóïà:
1939 gCorpses
[i
].SaveState(st
);
1945 procedure g_Player_Corpses_LoadState (st
: TStream
);
1953 g_Player_RemoveAllCorpses();
1955 // Êîëè÷åñòâî òðóïîâ:
1956 count
:= utils
.readLongInt(st
);
1957 if (count
< 0) or (count
> Length(gCorpses
)) then raise XStreamError
.Create('invalid number of corpses');
1959 if (count
= 0) then exit
;
1962 for i
:= 0 to count
-1 do
1965 str
:= utils
.readStr(st
);
1967 b
:= utils
.readBool(st
);
1969 gCorpses
[i
] := TCorpse
.Create(0, 0, str
, b
);
1970 // Çàãðóæàåì äàííûå òðóïà
1971 gCorpses
[i
].LoadState(st
);
1978 function TPlayer
.isValidViewPort (): Boolean; inline; begin result
:= (viewPortW
> 0) and (viewPortH
> 0); end;
1980 procedure TPlayer
.BFGHit();
1982 g_Weapon_BFGHit(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
1983 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2));
1984 if g_Game_IsServer
and g_Game_IsNet
then
1985 MH_SEND_Effect(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
1986 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2),
1990 procedure TPlayer
.ChangeModel(ModelName
: string);
1992 locModel
: TPlayerModel
;
1994 locModel
:= g_PlayerModel_Get(ModelName
);
1995 if locModel
= nil then Exit
;
2001 procedure TPlayer
.SetModel(ModelName
: string);
2005 m
:= g_PlayerModel_Get(ModelName
);
2008 g_SimpleError(Format(_lc
[I_GAME_ERROR_MODEL_FALLBACK
], [ModelName
]));
2009 m
:= g_PlayerModel_Get('doomer');
2012 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], ['doomer']));
2017 if FModel
<> nil then
2022 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
2023 FModel
.Color
:= FColor
2025 FModel
.Color
:= TEAMCOLOR
[FTeam
];
2026 FModel
.SetWeapon(FCurrWeap
);
2027 FModel
.SetFlag(FFlag
);
2028 SetDirection(FDirection
);
2031 procedure TPlayer
.SetColor(Color
: TRGB
);
2034 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
2035 if FModel
<> nil then FModel
.Color
:= Color
;
2038 procedure TPlayer
.SwitchTeam
;
2040 if g_Game_IsClient
then
2042 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then Exit
;
2044 if gGameOn
and FAlive
then
2045 Kill(K_SIMPLEKILL
, FUID
, HIT_SELF
);
2047 if FTeam
= TEAM_RED
then
2049 ChangeTeam(TEAM_BLUE
);
2050 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_BLUE
], [FName
]), True);
2051 if g_Game_IsNet
then
2052 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM
, TEAM_BLUE
, FName
);
2056 ChangeTeam(TEAM_RED
);
2057 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_RED
], [FName
]), True);
2058 if g_Game_IsNet
then
2059 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM
, TEAM_RED
, FName
);
2061 FPreferredTeam
:= FTeam
;
2064 procedure TPlayer
.ChangeTeam(Team
: Byte);
2071 TEAM_RED
, TEAM_BLUE
:
2072 FModel
.Color
:= TEAMCOLOR
[Team
];
2074 FModel
.Color
:= FColor
;
2076 if (FTeam
<> OldTeam
) and g_Game_IsNet
and g_Game_IsServer
then
2077 MH_SEND_PlayerStats(FUID
);
2081 procedure TPlayer.CollideItem();
2086 if gItems = nil then Exit;
2087 if not FAlive then Exit;
2089 for i := 0 to High(gItems) do
2092 if (ItemType <> ITEM_NONE) and alive then
2093 if g_Obj_Collide(FObj.X+PLAYER_RECT.X, FObj.Y+PLAYER_RECT.Y, PLAYER_RECT.Width,
2094 PLAYER_RECT.Height, @Obj) then
2096 if not PickItem(ItemType, gItems[i].Respawnable, r) then Continue;
2098 if ItemType in [ITEM_SPHERE_BLUE, ITEM_SPHERE_WHITE, ITEM_INVUL] then
2099 g_Sound_PlayExAt('SOUND_ITEM_GETRULEZ', FObj.X, FObj.Y)
2100 else if ItemType in [ITEM_MEDKIT_SMALL, ITEM_MEDKIT_LARGE, ITEM_MEDKIT_BLACK] then
2101 g_Sound_PlayExAt('SOUND_ITEM_GETMED', FObj.X, FObj.Y)
2102 else g_Sound_PlayExAt('SOUND_ITEM_GETITEM', FObj.X, FObj.Y);
2104 // Íàäî óáðàòü ñ êàðòû, åñëè ýòî íå êëþ÷, êîòîðûì íóæíî ïîäåëèòñÿ ñ äðóãèì èãðîêîì:
2105 if r and not ((ItemType in [ITEM_KEY_RED, ITEM_KEY_GREEN, ITEM_KEY_BLUE]) and
2106 (gGameSettings.GameType = GT_SINGLE) and
2107 (g_Player_GetCount() > 1)) then
2108 if not Respawnable then g_Items_Remove(i) else g_Items_Pick(i);
2114 function TPlayer
.CollideLevel(XInc
, YInc
: Integer): Boolean;
2116 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
2117 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_WALL
,
2121 constructor TPlayer
.Create();
2127 mEDamageType
:= HIT_SOME
;
2133 FSawSound
:= TPlayableSound
.Create();
2134 FSawSoundIdle
:= TPlayableSound
.Create();
2135 FSawSoundHit
:= TPlayableSound
.Create();
2136 FSawSoundSelect
:= TPlayableSound
.Create();
2137 FFlameSoundOn
:= TPlayableSound
.Create();
2138 FFlameSoundOff
:= TPlayableSound
.Create();
2139 FFlameSoundWork
:= TPlayableSound
.Create();
2140 FJetSoundFly
:= TPlayableSound
.Create();
2141 FJetSoundOn
:= TPlayableSound
.Create();
2142 FJetSoundOff
:= TPlayableSound
.Create();
2144 FSawSound
.SetByName('SOUND_WEAPON_FIRESAW');
2145 FSawSoundIdle
.SetByName('SOUND_WEAPON_IDLESAW');
2146 FSawSoundHit
.SetByName('SOUND_WEAPON_HITSAW');
2147 FSawSoundSelect
.SetByName('SOUND_WEAPON_SELECTSAW');
2148 FFlameSoundOn
.SetByName('SOUND_WEAPON_FLAMEON');
2149 FFlameSoundOff
.SetByName('SOUND_WEAPON_FLAMEOFF');
2150 FFlameSoundWork
.SetByName('SOUND_WEAPON_FLAMEWORK');
2151 FJetSoundFly
.SetByName('SOUND_PLAYER_JETFLY');
2152 FJetSoundOn
.SetByName('SOUND_PLAYER_JETON');
2153 FJetSoundOff
.SetByName('SOUND_PLAYER_JETOFF');
2155 FSpectatePlayer
:= -1;
2159 FSavedState
.WaitRecall
:= False;
2166 FActualModelName
:= 'doomer';
2169 FObj
.Rect
:= PLAYER_RECT
;
2171 FBFGFireCounter
:= -1;
2172 FJustTeleported
:= False;
2178 procedure TPlayer
.positionChanged (); inline;
2182 procedure TPlayer
.doDamage (v
: Integer);
2184 if (v
<= 0) then exit
;
2185 if (v
> 32767) then v
:= 32767;
2186 Damage(v
, 0, 0, 0, mEDamageType
);
2189 procedure TPlayer
.Damage(value
: Word; SpawnerUID
: Word; vx
, vy
: Integer; t
: Byte);
2193 if (not g_Game_IsClient
) and (not FAlive
) then
2198 // Íåóÿçâèìîñòü íå ñïàñàåò îò ëîâóøåê:
2199 if ((t
= HIT_TRAP
) or (t
= HIT_SELF
)) and (not FGodMode
) then
2201 if not g_Game_IsClient
then
2204 if t
= HIT_TRAP
then
2206 // Ëîâóøêà óáèâàåò ñðàçó:
2208 Kill(K_EXTRAHARDKILL
, SpawnerUID
, t
);
2210 if t
= HIT_SELF
then
2214 Kill(K_SIMPLEKILL
, SpawnerUID
, t
);
2217 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
2218 FMegaRulez
[MR_SUIT
] := 0;
2219 FMegaRulez
[MR_INVUL
] := 0;
2220 FMegaRulez
[MR_INVIS
] := 0;
2224 // Íî îò îñòàëüíîãî ñïàñàåò:
2225 if FMegaRulez
[MR_INVUL
] >= gTime
then
2232 // Åñëè åñòü óðîí ñâîèì, èëè ðàíèë ñàì ñåáÿ, èëè òåáÿ ðàíèë ïðîòèâíèê:
2233 if LongBool(gGameSettings
.Options
and GAME_OPTION_TEAMDAMAGE
) or
2234 (SpawnerUID
= FUID
) or
2235 (not SameTeam(FUID
, SpawnerUID
)) then
2237 FLastSpawnerUID
:= SpawnerUID
;
2239 // Êðîâü (ïóçûðüêè, åñëè â âîäå):
2240 if gBloodCount
> 0 then
2242 c
:= Min(value
, 200)*gBloodCount
+ Random(Min(value
, 200) div 2);
2243 if value
div 4 <= c
then
2244 c
:= c
- (value
div 4)
2248 if (t
= HIT_SOME
) and (vx
= 0) and (vy
= 0) then
2252 HIT_TRAP
, HIT_ACID
, HIT_FLAME
, HIT_SELF
: MakeBloodSimple(c
);
2253 HIT_BFG
, HIT_ROCKET
, HIT_SOME
: MakeBloodVector(c
, vx
, vy
);
2256 if t
= HIT_WATER
then
2257 g_GFX_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
2258 FObj
.Y
+PLAYER_RECT
.Y
-4, value
div 2, 8, 4);
2263 Inc(FDamageBuffer
, value
);
2267 FPain
:= FPain
+ value
;
2270 if g_Game_IsServer
and g_Game_IsNet
then
2272 MH_SEND_PlayerDamage(FUID
, t
, SpawnerUID
, value
, vx
, vy
);
2273 MH_SEND_PlayerStats(FUID
);
2274 MH_SEND_PlayerPos(False, FUID
);
2278 function TPlayer
.Heal(value
: Word; Soft
: Boolean): Boolean;
2281 if g_Game_IsClient
then
2286 if Soft
and (FHealth
< PLAYER_HP_SOFT
) then
2288 IncMax(FHealth
, value
, PLAYER_HP_SOFT
);
2291 if (not Soft
) and (FHealth
< PLAYER_HP_LIMIT
) then
2293 IncMax(FHealth
, value
, PLAYER_HP_LIMIT
);
2297 if Result
and g_Game_IsServer
and g_Game_IsNet
then
2298 MH_SEND_PlayerStats(FUID
);
2301 destructor TPlayer
.Destroy();
2303 if (gPlayer1
<> nil) and (gPlayer1
.FUID
= FUID
) then
2305 if (gPlayer2
<> nil) and (gPlayer2
.FUID
= FUID
) then
2309 FSawSoundIdle
.Free();
2310 FSawSoundHit
.Free();
2311 FSawSoundSelect
.Free();
2312 FFlameSoundOn
.Free();
2313 FFlameSoundOff
.Free();
2314 FFlameSoundWork
.Free();
2315 FJetSoundFly
.Free();
2317 FJetSoundOff
.Free();
2319 if FPunchAnim
<> nil then
2325 procedure TPlayer
.DrawIndicator();
2327 indX
, indY
: Integer;
2333 if g_Texture_Get('TEXTURE_PLAYER_INDICATOR', ID
) then
2335 e_GetTextureSize(ID
, @indW
, @indH
);
2336 indX
:= FObj
.X
+ FObj
.Rect
.X
+ (FObj
.Rect
.Width
- indW
) div 2;
2338 e_Draw(ID
, indX
, indY
- indH
, 0, True, False);
2341 //e_TextureFontPrint(indX, indY, FName, gStdFont); // Shows player name overhead
2344 procedure TPlayer
.DrawBubble();
2346 bubX
, bubY
: Integer;
2349 Rw
, Gw
, Bw
: SmallInt;
2352 bubX
:= FObj
.X
+FObj
.Rect
.X
+ IfThen(FDirection
= TDirection
.D_LEFT
, -4, 18);
2353 bubY
:= FObj
.Y
+FObj
.Rect
.Y
- 18;
2361 1: // simple textual non-bubble
2363 bubX
:= FObj
.X
+FObj
.Rect
.X
- 11;
2364 bubY
:= FObj
.Y
+FObj
.Rect
.Y
- 17;
2365 e_TextureFontPrint(bubX
, bubY
, '[...]', gStdFont
);
2368 2: // advanced pixel-perfect bubble
2370 if FTeam
= TEAM_RED
then
2373 if FTeam
= TEAM_BLUE
then
2376 3: // colored bubble
2378 Rb
:= FModel
.Color
.R
;
2379 Gb
:= FModel
.Color
.G
;
2380 Bb
:= FModel
.Color
.B
;
2381 Rw
:= Min(Rb
* 2 + 64, 255);
2382 Gw
:= Min(Gb
* 2 + 64, 255);
2383 Bw
:= Min(Bb
* 2 + 64, 255);
2384 if (Abs(Rw
- Rb
) < 32)
2385 or (Abs(Gw
- Gb
) < 32)
2386 or (Abs(Bw
- Bb
) < 32) then
2388 Rb
:= Max(Rw
div 2 - 16, 0);
2389 Gb
:= Max(Gw
div 2 - 16, 0);
2390 Bb
:= Max(Bw
div 2 - 16, 0);
2393 4: // custom textured bubble
2395 if g_Texture_Get('TEXTURE_PLAYER_TALKBUBBLE', ID
) then
2396 if FDirection
= TDirection
.D_RIGHT
then
2397 e_Draw(ID
, bubX
- 6, bubY
- 7, 0, True, False)
2399 e_Draw(ID
, bubX
- 6, bubY
- 7, 0, True, False, TMirrorType
.Horizontal
);
2405 e_DrawQuad(bubX
+ 1, bubY
, bubX
+ 18, bubY
+ 13, Rb
, Gb
, Bb
);
2406 e_DrawQuad(bubX
, bubY
+ 1, bubX
+ 19, bubY
+ 12, Rb
, Gb
, Bb
);
2408 e_DrawFillQuad(bubX
+ 1, bubY
+ 1, bubX
+ 18, bubY
+ 12, Rw
, Gw
, Bw
, 0);
2411 Dot
:= IfThen(FDirection
= TDirection
.D_LEFT
, 14, 5);
2412 e_DrawLine(1, bubX
+ Dot
, bubY
+ 14, bubX
+ Dot
, bubY
+ 16, Rb
, Gb
, Bb
);
2413 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
);
2414 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
);
2415 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
);
2416 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
);
2420 e_DrawFillQuad(bubX
+ Dot
, bubY
+ 8, bubX
+ Dot
+ 1, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2421 e_DrawFillQuad(bubX
+ Dot
+ 3, bubY
+ 8, bubX
+ Dot
+ 4, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2422 e_DrawFillQuad(bubX
+ Dot
+ 6, bubY
+ 8, bubX
+ Dot
+ 7, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2425 procedure TPlayer
.Draw();
2430 Mirror
: TMirrorType
;
2434 if Direction
= TDirection
.D_RIGHT
then
2435 Mirror
:= TMirrorType
.None
2437 Mirror
:= TMirrorType
.Horizontal
;
2439 if FPunchAnim
<> nil then
2441 FPunchAnim
.Draw(FObj
.X
+IfThen(Direction
= TDirection
.D_LEFT
, 15-FObj
.Rect
.X
, FObj
.Rect
.X
-15),
2442 FObj
.Y
+FObj
.Rect
.Y
-11, Mirror
);
2443 if FPunchAnim
.played
then
2450 if (FMegaRulez
[MR_INVUL
] > gTime
) and (gPlayerDrawn
<> Self
) then
2451 if g_Texture_Get('TEXTURE_PLAYER_INVULPENTA', ID
) then
2453 e_GetTextureSize(ID
, @w
, @h
);
2454 if FDirection
= TDirection
.D_LEFT
then
2455 e_Draw(ID
, FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2)-(w
div 2)+4,
2456 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2)-(h
div 2)-7+FObj
.slopeUpLeft
, 0, True, False)
2458 e_Draw(ID
, FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2)-(w
div 2)-2,
2459 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2)-(h
div 2)-7+FObj
.slopeUpLeft
, 0, True, False);
2462 if FMegaRulez
[MR_INVIS
] > gTime
then
2464 if (gPlayerDrawn
<> nil) and ((Self
= gPlayerDrawn
) or
2465 ((FTeam
= gPlayerDrawn
.Team
) and (gGameSettings
.GameMode
<> GM_DM
))) then
2467 if (FMegaRulez
[MR_INVIS
] - gTime
) <= 2100 then
2468 dr
:= not Odd((FMegaRulez
[MR_INVIS
] - gTime
) div 300)
2472 FModel
.Draw(FObj
.X
, FObj
.Y
+FObj
.slopeUpLeft
, 200)
2474 FModel
.Draw(FObj
.X
, FObj
.Y
+FObj
.slopeUpLeft
);
2477 FModel
.Draw(FObj
.X
, FObj
.Y
+FObj
.slopeUpLeft
, 254);
2480 FModel
.Draw(FObj
.X
, FObj
.Y
+FObj
.slopeUpLeft
);
2483 if g_debug_Frames
then
2485 e_DrawQuad(FObj
.X
+FObj
.Rect
.X
,
2487 FObj
.X
+FObj
.Rect
.X
+FObj
.Rect
.Width
-1,
2488 FObj
.Y
+FObj
.Rect
.Y
+FObj
.Rect
.Height
-1,
2492 if (gChatBubble
> 0) and (FKeys
[KEY_CHAT
].Pressed
) and not FGhost
then
2493 if (FMegaRulez
[MR_INVIS
] <= gTime
) or ((gPlayerDrawn
<> nil) and ((Self
= gPlayerDrawn
) or
2494 ((FTeam
= gPlayerDrawn
.Team
) and (gGameSettings
.GameMode
<> GM_DM
)))) then
2496 // e_DrawPoint(5, 335, 288, 255, 0, 0); // DL, UR, DL, UR
2497 if gAimLine
and alive
and
2498 ((Self
= gPlayer1
) or (Self
= gPlayer2
)) then
2503 procedure TPlayer
.DrawAim();
2504 procedure drawCast (sz
: Integer; ax0
, ay0
, ax1
, ay1
: Integer);
2509 {$IFDEF ENABLE_HOLMES}
2510 if isValidViewPort
and (self
= gPlayer1
) then
2512 g_Holmes_plrLaser(ax0
, ay0
, ax1
, ay1
);
2516 e_DrawLine(sz
, ax0
, ay0
, ax1
, ay1
, 255, 0, 0, 96);
2517 if (g_Map_traceToNearestWall(ax0
, ay0
, ax1
, ay1
, @ex
, @ey
) <> nil) then
2519 e_DrawLine(sz
, ax0
, ay0
, ex
, ey
, 0, 255, 0, 96);
2523 e_DrawLine(sz
, ax0
, ay0
, ex
, ey
, 0, 0, 255, 96);
2528 wx
, wy
, xx
, yy
: Integer;
2532 wx
:= FObj
.X
+ WEAPONPOINT
[FDirection
].X
+ IfThen(FDirection
= TDirection
.D_LEFT
, 7, -7);
2533 wy
:= FObj
.Y
+ WEAPONPOINT
[FDirection
].Y
;
2542 1: begin // Chainsaw
2549 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2550 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2551 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2552 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2557 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2558 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2559 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2560 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2562 4: begin // Double Shotgun
2565 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2566 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2567 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2568 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2570 5: begin // Chaingun
2573 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2574 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2575 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2576 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2578 6: begin // Rocket Launcher
2581 if angle
= ANGLE_RIGHTUP
then Inc(angle
, 2);
2582 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2583 if angle
= ANGLE_LEFTUP
then Dec(angle
, 2);
2584 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2586 7: begin // Plasmagun
2589 if angle
= ANGLE_RIGHTUP
then Inc(angle
);
2590 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 3);
2591 if angle
= ANGLE_LEFTUP
then Dec(angle
);
2592 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 3);
2597 if angle
= ANGLE_RIGHTUP
then Inc(angle
, 1);
2598 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 2);
2599 if angle
= ANGLE_LEFTUP
then Dec(angle
, 1);
2600 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 2);
2602 9: begin // Super Chaingun
2605 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2606 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2607 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2608 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2611 xx
:= Trunc(Cos(-DegToRad(angle
)) * len
) + wx
;
2612 yy
:= Trunc(Sin(-DegToRad(angle
)) * len
) + wy
;
2613 {$IF DEFINED(D2F_DEBUG)}
2614 drawCast(sz
, wx
, wy
, xx
, yy
);
2616 e_DrawLine(sz
, wx
, wy
, xx
, yy
, 255, 0, 0, 96);
2620 procedure TPlayer
.DrawGUI();
2623 X
, Y
, SY
, a
, p
, m
: Integer;
2627 stat
: TPlayerStatArray
;
2629 X
:= gPlayerScreenSize
.X
;
2630 SY
:= gPlayerScreenSize
.Y
;
2633 if gShowGoals
and (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
2635 if gGameSettings
.GameMode
= GM_CTF
then
2639 if gGameSettings
.GameMode
= GM_CTF
then
2641 s
:= 'TEXTURE_PLAYER_REDFLAG';
2642 if gFlags
[FLAG_RED
].State
= FLAG_STATE_CAPTURED
then
2643 s
:= 'TEXTURE_PLAYER_REDFLAG_S';
2644 if gFlags
[FLAG_RED
].State
= FLAG_STATE_DROPPED
then
2645 s
:= 'TEXTURE_PLAYER_REDFLAG_D';
2646 if g_Texture_Get(s
, ID
) then
2647 e_Draw(ID
, X
-16-32, 240-72-4, 0, True, False);
2650 s
:= IntToStr(gTeamStat
[TEAM_RED
].Goals
);
2651 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2652 e_CharFont_PrintEx(gMenuFont
, X
-16-a
-tw
, 240-72-4, s
, TEAMCOLOR
[TEAM_RED
]);
2654 if gGameSettings
.GameMode
= GM_CTF
then
2656 s
:= 'TEXTURE_PLAYER_BLUEFLAG';
2657 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_CAPTURED
then
2658 s
:= 'TEXTURE_PLAYER_BLUEFLAG_S';
2659 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_DROPPED
then
2660 s
:= 'TEXTURE_PLAYER_BLUEFLAG_D';
2661 if g_Texture_Get(s
, ID
) then
2662 e_Draw(ID
, X
-16-32, 240-32-4, 0, True, False);
2665 s
:= IntToStr(gTeamStat
[TEAM_BLUE
].Goals
);
2666 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2667 e_CharFont_PrintEx(gMenuFont
, X
-16-a
-tw
, 240-32-4, s
, TEAMCOLOR
[TEAM_BLUE
]);
2670 if g_Texture_Get('TEXTURE_PLAYER_HUDBG', ID
) then
2671 e_DrawFill(ID
, X
, 0, 1, (gPlayerScreenSize
.Y
div 256)+IfThen(gPlayerScreenSize
.Y
mod 256 > 0, 1, 0),
2674 if g_Texture_Get('TEXTURE_PLAYER_HUD', ID
) then
2675 e_Draw(ID
, X
+2, Y
, 0, True, False);
2677 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
2681 s
:= IntToStr(Frags
);
2682 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2683 e_CharFont_PrintEx(gMenuFont
, X
-16-tw
, Y
, s
, _RGB(255, 0, 0));
2688 stat
:= g_Player_GetStats();
2693 for a
:= 0 to High(stat
) do
2694 if stat
[a
].Name
<> Name
then
2696 if stat
[a
].Frags
> m
then m
:= stat
[a
].Frags
;
2697 if stat
[a
].Frags
> Frags
then p
:= p
+1;
2701 s
:= IntToStr(p
)+' / '+IntToStr(Length(stat
))+' ';
2702 if Frags
>= m
then s
:= s
+'+' else s
:= s
+'-';
2703 s
:= s
+IntToStr(Abs(Frags
-m
));
2705 e_CharFont_GetSize(gMenuSmallFont
, s
, tw
, th
);
2706 e_CharFont_PrintEx(gMenuSmallFont
, X
-16-tw
, Y
+32, s
, _RGB(255, 0, 0));
2709 if gShowLives
and (gGameSettings
.MaxLives
> 0) then
2711 s
:= IntToStr(Lives
);
2712 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2713 e_CharFont_PrintEx(gMenuFont
, X
-16-tw
, SY
-32, s
, _RGB(0, 255, 0));
2717 e_CharFont_GetSize(gMenuSmallFont
, FName
, tw
, th
);
2718 e_CharFont_PrintEx(gMenuSmallFont
, X
+98-(tw
div 2), Y
+8, FName
, _RGB(255, 0, 0));
2720 if R_BERSERK
in FRulez
then
2721 e_Draw(gItemsTexturesID
[ITEM_MEDKIT_BLACK
], X
+37, Y
+45, 0, True, False)
2723 e_Draw(gItemsTexturesID
[ITEM_MEDKIT_LARGE
], X
+37, Y
+45, 0, True, False);
2725 if g_Texture_Get('TEXTURE_PLAYER_ARMORHUD', ID
) then
2726 e_Draw(ID
, X
+36, Y
+77, 0, True, False);
2728 s
:= IntToStr(IfThen(FHealth
> 0, FHealth
, 0));
2729 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2730 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+40, s
, _RGB(255, 0, 0));
2732 s
:= IntToStr(FArmor
);
2733 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2734 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+68, s
, _RGB(255, 0, 0));
2736 s
:= IntToStr(GetAmmoByWeapon(FCurrWeap
));
2742 ID
:= gItemsTexturesID
[ITEM_WEAPON_KASTET
];
2747 ID
:= gItemsTexturesID
[ITEM_WEAPON_SAW
];
2749 WEAPON_PISTOL
: ID
:= gItemsTexturesID
[ITEM_WEAPON_PISTOL
];
2750 WEAPON_CHAINGUN
: ID
:= gItemsTexturesID
[ITEM_WEAPON_CHAINGUN
];
2751 WEAPON_SHOTGUN1
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SHOTGUN1
];
2752 WEAPON_SHOTGUN2
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SHOTGUN2
];
2753 WEAPON_SUPERPULEMET
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SUPERPULEMET
];
2754 WEAPON_ROCKETLAUNCHER
: ID
:= gItemsTexturesID
[ITEM_WEAPON_ROCKETLAUNCHER
];
2755 WEAPON_PLASMA
: ID
:= gItemsTexturesID
[ITEM_WEAPON_PLASMA
];
2756 WEAPON_BFG
: ID
:= gItemsTexturesID
[ITEM_WEAPON_BFG
];
2757 WEAPON_FLAMETHROWER
: ID
:= gItemsTexturesID
[ITEM_WEAPON_FLAMETHROWER
];
2760 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2761 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+158, s
, _RGB(255, 0, 0));
2762 e_Draw(ID
, X
+20, Y
+160, 0, True, False);
2764 if R_KEY_RED
in FRulez
then
2765 e_Draw(gItemsTexturesID
[ITEM_KEY_RED
], X
+78, Y
+214, 0, True, False);
2767 if R_KEY_GREEN
in FRulez
then
2768 e_Draw(gItemsTexturesID
[ITEM_KEY_GREEN
], X
+95, Y
+214, 0, True, False);
2770 if R_KEY_BLUE
in FRulez
then
2771 e_Draw(gItemsTexturesID
[ITEM_KEY_BLUE
], X
+112, Y
+214, 0, True, False);
2773 if FJetFuel
> 0 then
2775 if g_Texture_Get('TEXTURE_PLAYER_HUDAIR', ID
) then
2776 e_Draw(ID
, X
+2, Y
+116, 0, True, False);
2777 if g_Texture_Get('TEXTURE_PLAYER_HUDJET', ID
) then
2778 e_Draw(ID
, X
+2, Y
+126, 0, True, False);
2779 e_DrawLine(4, X
+16, Y
+122, X
+16+Trunc(168*IfThen(FAir
> 0, FAir
, 0)/AIR_MAX
), Y
+122, 0, 0, 196);
2780 e_DrawLine(4, X
+16, Y
+132, X
+16+Trunc(168*FJetFuel
/JET_MAX
), Y
+132, 208, 0, 0);
2784 if g_Texture_Get('TEXTURE_PLAYER_HUDAIR', ID
) then
2785 e_Draw(ID
, X
+2, Y
+124, 0, True, False);
2786 e_DrawLine(4, X
+16, Y
+130, X
+16+Trunc(168*IfThen(FAir
> 0, FAir
, 0)/AIR_MAX
), Y
+130, 0, 0, 196);
2789 if gShowPing
and g_Game_IsClient
then
2791 s
:= _lc
[I_GAME_PING_HUD
] + IntToStr(NetPeer
.lastRoundTripTime
) + _lc
[I_NET_SLIST_PING_MS
];
2792 e_TextureFontPrint(X
+ 4, Y
+ 242, s
, gStdFont
);
2798 e_TextureFontPrint(X
+ 4, Y
+ 242, _lc
[I_PLAYER_SPECT
], gStdFont
);
2799 e_TextureFontPrint(X
+ 4, Y
+ 258, _lc
[I_PLAYER_SPECT2
], gStdFont
);
2800 e_TextureFontPrint(X
+ 4, Y
+ 274, _lc
[I_PLAYER_SPECT1
], gStdFont
);
2803 e_TextureFontGetSize(gStdFont
, cw
, ch
);
2804 s
:= _lc
[I_PLAYER_SPECT4
];
2805 e_TextureFontPrintEx(gScreenWidth
div 2 - cw
*(Length(s
) div 2),
2806 gScreenHeight
-4-ch
, s
, gStdFont
, 255, 255, 255, 1, True);
2807 e_TextureFontPrint(X
+ 4, Y
+ 290, _lc
[I_PLAYER_SPECT1S
], gStdFont
);
2813 procedure TPlayer
.DrawRulez();
2817 // Ïðè âçÿòèè íåóÿçâèìîñòè ðèñóåòñÿ èíâåðñèîííûé áåëûé ôîí
2818 if FMegaRulez
[MR_INVUL
] >= gTime
then
2820 if (FMegaRulez
[MR_INVUL
]-gTime
) <= 2100 then
2821 dr
:= not Odd((FMegaRulez
[MR_INVUL
]-gTime
) div 300)
2826 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2827 191, 191, 191, 0, TBlending
.Invert
);
2830 // Ïðè âçÿòèè çàùèòíîãî êîñòþìà ðèñóåòñÿ çåëåíîâàòûé ôîí
2831 if FMegaRulez
[MR_SUIT
] >= gTime
then
2833 if (FMegaRulez
[MR_SUIT
]-gTime
) <= 2100 then
2834 dr
:= not Odd((FMegaRulez
[MR_SUIT
]-gTime
) div 300)
2839 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2840 0, 96, 0, 200, TBlending
.None
);
2843 // Ïðè âçÿòèè áåðñåðêà ðèñóåòñÿ êðàñíîâàòûé ôîí
2844 if (FBerserk
>= 0) and (LongWord(FBerserk
) >= gTime
) and (gFlash
= 2) then
2846 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2847 255, 0, 0, 200, TBlending
.None
);
2851 procedure TPlayer
.DrawPain();
2855 if FPain
= 0 then Exit
;
2859 if a
< 15 then h
:= 0
2860 else if a
< 35 then h
:= 1
2861 else if a
< 55 then h
:= 2
2862 else if a
< 75 then h
:= 3
2863 else if a
< 95 then h
:= 4
2866 //if a > 255 then a := 255;
2868 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1, 255, 0, 0, 255-h
*50);
2869 //e_DrawFillQuad(0, 0, gPlayerScreenSize.X-1, gPlayerScreenSize.Y-1, 255-min(128, a), 255-a, 255-a, 0, B_FILTER);
2872 procedure TPlayer
.DrawPickup();
2876 if FPickup
= 0 then Exit
;
2880 if a
< 15 then h
:= 1
2881 else if a
< 35 then h
:= 2
2882 else if a
< 55 then h
:= 3
2883 else if a
< 75 then h
:= 4
2886 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1, 150, 200, 150, 255-h
*50);
2889 procedure TPlayer
.DoPunch();
2894 if FPunchAnim
<> nil then begin
2899 st
:= 'FRAMES_PUNCH';
2900 if R_BERSERK
in FRulez
then
2901 st
:= st
+ '_BERSERK';
2902 if FKeys
[KEY_UP
].Pressed
then
2904 else if FKeys
[KEY_DOWN
].Pressed
then
2906 g_Frames_Get(id
, st
);
2907 FPunchAnim
:= TAnimation
.Create(id
, False, 1);
2910 procedure TPlayer
.Fire();
2912 f
, DidFire
: Boolean;
2913 wx
, wy
, xd
, yd
: Integer;
2916 if g_Game_IsClient
then Exit
;
2917 // FBFGFireCounter - âðåìÿ ïåðåä âûñòðåëîì (äëÿ BFG)
2918 // FReloading - âðåìÿ ïîñëå âûñòðåëà (äëÿ âñåãî)
2926 if FReloading
[FCurrWeap
] <> 0 then Exit
;
2931 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
2932 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
2933 xd
:= wx
+IfThen(FDirection
= TDirection
.D_LEFT
, -30, 30);
2934 yd
:= wy
+firediry();
2940 if R_BERSERK
in FRulez
then
2942 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
2943 locobj
.X
:= FObj
.X
+FObj
.Rect
.X
;
2944 locobj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
2947 locobj
.rect
.Width
:= 39;
2948 locobj
.rect
.Height
:= 52;
2949 locobj
.Vel
.X
:= (xd
-wx
) div 2;
2950 locobj
.Vel
.Y
:= (yd
-wy
) div 2;
2951 locobj
.Accel
.X
:= xd
-wx
;
2952 locobj
.Accel
.y
:= yd
-wy
;
2954 if g_Weapon_Hit(@locobj
, 50, FUID
, HIT_SOME
) <> 0 then
2955 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
2957 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
2959 if (gFlash
= 1) and (FPain
< 50) then FPain
:= min(FPain
+ 25, 50);
2963 g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
2967 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2972 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
2973 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
2975 FSawSoundSelect
.Stop();
2977 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
2979 else if not FSawSoundHit
.IsPlaying() then
2981 FSawSoundSelect
.Stop();
2982 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
2985 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2991 if FAmmo
[A_BULLETS
] > 0 then
2993 g_Weapon_pistol(wx
, wy
, xd
, yd
, FUID
);
2994 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2995 Dec(FAmmo
[A_BULLETS
]);
2996 FFireAngle
:= FAngle
;
2999 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
3000 GameVelX
, GameVelY
-2, SHELL_BULLET
);
3004 if FAmmo
[A_SHELLS
] > 0 then
3006 g_Weapon_shotgun(wx
, wy
, xd
, yd
, FUID
);
3007 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', wx
, wy
);
3008 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3009 Dec(FAmmo
[A_SHELLS
]);
3010 FFireAngle
:= FAngle
;
3014 FShellType
:= SHELL_SHELL
;
3018 if FAmmo
[A_SHELLS
] >= 2 then
3020 g_Weapon_dshotgun(wx
, wy
, xd
, yd
, FUID
);
3021 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3022 Dec(FAmmo
[A_SHELLS
], 2);
3023 FFireAngle
:= FAngle
;
3027 FShellType
:= SHELL_DBLSHELL
;
3031 if FAmmo
[A_BULLETS
] > 0 then
3033 g_Weapon_mgun(wx
, wy
, xd
, yd
, FUID
);
3034 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', wx
, wy
);
3035 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3036 Dec(FAmmo
[A_BULLETS
]);
3037 FFireAngle
:= FAngle
;
3040 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
3041 GameVelX
, GameVelY
-2, SHELL_BULLET
);
3044 WEAPON_ROCKETLAUNCHER
:
3045 if FAmmo
[A_ROCKETS
] > 0 then
3047 g_Weapon_rocket(wx
, wy
, xd
, yd
, FUID
);
3048 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3049 Dec(FAmmo
[A_ROCKETS
]);
3050 FFireAngle
:= FAngle
;
3056 if FAmmo
[A_CELLS
] > 0 then
3058 g_Weapon_plasma(wx
, wy
, xd
, yd
, FUID
);
3059 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3060 Dec(FAmmo
[A_CELLS
]);
3061 FFireAngle
:= FAngle
;
3067 if (FAmmo
[A_CELLS
] >= 40) and (FBFGFireCounter
= -1) then
3069 FBFGFireCounter
:= 17;
3070 if not FNoReload
then
3071 g_Sound_PlayExAt('SOUND_WEAPON_STARTFIREBFG', FObj
.X
, FObj
.Y
);
3072 Dec(FAmmo
[A_CELLS
], 40);
3076 WEAPON_SUPERPULEMET
:
3077 if FAmmo
[A_SHELLS
] > 0 then
3079 g_Weapon_shotgun(wx
, wy
, xd
, yd
, FUID
);
3080 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', wx
, wy
);
3081 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3082 Dec(FAmmo
[A_SHELLS
]);
3083 FFireAngle
:= FAngle
;
3086 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
3087 GameVelX
, GameVelY
-2, SHELL_SHELL
);
3090 WEAPON_FLAMETHROWER
:
3091 if FAmmo
[A_FUEL
] > 0 then
3093 g_Weapon_flame(wx
, wy
, xd
, yd
, FUID
);
3095 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
3097 FFireAngle
:= FAngle
;
3104 if g_Game_IsNet
and g_Game_IsServer
then MH_SEND_PlayerStats(FUID
);
3108 if g_Game_IsNet
then
3112 if FCurrWeap
<> WEAPON_BFG
then
3113 MH_SEND_PlayerFire(FUID
, FCurrWeap
, wx
, wy
, xd
, yd
, LastShotID
)
3115 if not FNoReload
then
3116 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_WEAPON_STARTFIREBFG');
3119 MH_SEND_PlayerStats(FUID
);
3124 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
3125 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
3126 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
3129 function TPlayer
.GetAmmoByWeapon(Weapon
: Byte): Word;
3132 WEAPON_PISTOL
, WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
];
3133 WEAPON_SHOTGUN1
, WEAPON_SHOTGUN2
, WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
];
3134 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
];
3135 WEAPON_PLASMA
, WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
];
3136 WEAPON_FLAMETHROWER
: Result
:= FAmmo
[A_FUEL
];
3141 function TPlayer
.HeadInLiquid(XInc
, YInc
: Integer): Boolean;
3143 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
+XInc
, FObj
.Y
+PLAYER_HEADRECT
.Y
+YInc
,
3144 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
3145 PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, True);
3148 procedure TPlayer
.FlamerOn
;
3150 FFlameSoundOff
.Stop();
3151 FFlameSoundOff
.SetPosition(0);
3154 if (not FFlameSoundOn
.IsPlaying()) and (not FFlameSoundWork
.IsPlaying()) then
3155 FFlameSoundWork
.PlayAt(FObj
.X
, FObj
.Y
);
3159 FFlameSoundOn
.PlayAt(FObj
.X
, FObj
.Y
);
3164 procedure TPlayer
.FlamerOff
;
3168 FFlameSoundOn
.Stop();
3169 FFlameSoundOn
.SetPosition(0);
3170 FFlameSoundWork
.Stop();
3171 FFlameSoundWork
.SetPosition(0);
3172 FFlameSoundOff
.PlayAt(FObj
.X
, FObj
.Y
);
3177 procedure TPlayer
.JetpackOn
;
3181 FJetSoundOn
.SetPosition(0);
3182 FJetSoundOn
.PlayAt(FObj
.X
, FObj
.Y
);
3186 procedure TPlayer
.JetpackOff
;
3190 FJetSoundOff
.SetPosition(0);
3191 FJetSoundOff
.PlayAt(FObj
.X
, FObj
.Y
);
3194 procedure TPlayer
.CatchFire(Attacker
: Word; Timeout
: Integer = PLAYER_BURN_TIME
);
3196 if Timeout
<= 0 then
3198 if (FMegaRulez
[MR_SUIT
] > gTime
) or (FMegaRulez
[MR_INVUL
] > gTime
) then
3199 exit
; // Íå çàãîðàåìñÿ êîãäà åñòü çàùèòà
3200 if FFireTime
<= 0 then
3201 g_Sound_PlayExAt('SOUND_IGNITE', FObj
.X
, FObj
.Y
);
3202 FFireTime
:= Timeout
;
3203 FFireAttacker
:= Attacker
;
3204 if g_Game_IsNet
and g_Game_IsServer
then
3205 MH_SEND_PlayerStats(FUID
);
3208 procedure TPlayer
.Jump();
3210 if gFly
or FJetpack
then
3212 // Ïîëåò (÷èò-êîä èëè äæåòïàê):
3213 if FObj
.Vel
.Y
> -VEL_FLY
then
3214 FObj
.Vel
.Y
:= FObj
.Vel
.Y
- 3;
3217 if FJetFuel
> 0 then
3219 if (FJetFuel
< 1) and g_Game_IsServer
then
3223 if g_Game_IsNet
then
3224 MH_SEND_PlayerStats(FUID
);
3230 // Íå âêëþ÷àòü äæåòïàê â ðåæèìå ïðîõîæäåíèÿ ñêâîçü ñòåíû
3232 FCanJetpack
:= False;
3234 // Ïðûãàåì èëè âñïëûâàåì:
3235 if (CollideLevel(0, 1) or
3236 g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
+36, PLAYER_RECT
.Width
,
3237 PLAYER_RECT
.Height
-33, PANEL_STEP
, False)
3238 ) and (FObj
.Accel
.Y
= 0) then // Íå ïðûãàòü, åñëè åñòü âåðòèêàëüíîå óñêîðåíèå
3240 FObj
.Vel
.Y
:= -VEL_JUMP
;
3241 FCanJetpack
:= False;
3245 if BodyInLiquid(0, 0) then
3246 FObj
.Vel
.Y
:= -VEL_SW
3247 else if (FJetFuel
> 0) and FCanJetpack
and
3248 g_Game_IsServer
and (not g_Obj_CollideLiquid(@FObj
, 0, 0)) then
3252 if g_Game_IsNet
then
3253 MH_SEND_PlayerStats(FUID
);
3258 procedure TPlayer
.Kill(KillType
: Byte; SpawnerUID
: Word; t
: Byte);
3260 a
, i
, k
, ab
, ar
: Byte;
3264 srv
, netsrv
: Boolean;
3270 procedure PushItem(t
: Byte);
3274 id
:= g_Items_Create(FObj
.X
, FObj
.Y
, t
, True, False);
3275 it
:= g_Items_ByIdx(id
);
3276 if KillType
= K_EXTRAHARDKILL
then // -7..+7; -8..0
3278 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-7+Random(15),
3279 (FObj
.Vel
.Y
div 2)-Random(9));
3280 it
.positionChanged(); // this updates spatial accelerators
3284 if KillType
= K_HARDKILL
then // -5..+5; -5..0
3286 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-5+Random(11),
3287 (FObj
.Vel
.Y
div 2)-Random(6));
3289 else // -3..+3; -3..0
3291 g_Obj_Push(@it
.Obj
, (FObj
.Vel
.X
div 2)-3+Random(7),
3292 (FObj
.Vel
.Y
div 2)-Random(4));
3294 it
.positionChanged(); // this updates spatial accelerators
3297 if g_Game_IsNet
and g_Game_IsServer
then
3298 MH_SEND_ItemSpawn(True, id
);
3302 DoFrags
:= (gGameSettings
.MaxLives
= 0) or (gGameSettings
.GameMode
= GM_COOP
);
3303 Srv
:= g_Game_IsServer
;
3304 Netsrv
:= g_Game_IsServer
and g_Game_IsNet
;
3305 if Srv
then FDeath
:= FDeath
+ 1;
3310 if not FPhysics
then
3316 if (gGameSettings
.MaxLives
> 0) and Srv
and (gLMSRespawn
= LMS_RESPAWN_NONE
) then
3318 if FLives
> 0 then FLives
:= FLives
- 1;
3319 if FLives
= 0 then FNoRespawn
:= True;
3322 // Íîìåð òèïà ñìåðòè:
3325 K_SIMPLEKILL
: a
:= 1;
3327 K_EXTRAHARDKILL
: a
:= 3;
3332 if not FModel
.PlaySound(MODELSOUND_DIE
, a
, FObj
.X
, FObj
.Y
) then
3334 if FModel
.PlaySound(MODELSOUND_DIE
, i
, FObj
.X
, FObj
.Y
) then
3341 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN1
;
3343 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN2
;
3344 K_EXTRAHARDKILL
, K_FALLKILL
:
3345 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN3
;
3348 // Ïåðåêëþ÷àåì ñîñòîÿíèå:
3352 K_HARDKILL
, K_EXTRAHARDKILL
:
3356 // Ðåàêöèÿ ìîíñòðîâ íà ñìåðòü èãðîêà:
3357 if (KillType
<> K_FALLKILL
) and (Srv
) then
3358 g_Monsters_killedp();
3360 if SpawnerUID
= FUID
then
3362 if Srv
and (DoFrags
or (gGameSettings
.GameMode
= GM_TDM
)) then
3367 g_Console_Add(Format(_lc
[I_PLAYER_KILL_SELF
], [FName
]), True);
3370 if g_GetUIDType(SpawnerUID
) = UID_PLAYER
then
3371 begin // Óáèò äðóãèì èãðîêîì
3372 KP
:= g_Player_Get(SpawnerUID
);
3373 if (KP
<> nil) and Srv
then
3375 if (DoFrags
or (gGameSettings
.GameMode
= GM_TDM
)) then
3376 if SameTeam(FUID
, SpawnerUID
) then
3386 if (gGameSettings
.GameMode
= GM_TDM
) and DoFrags
then
3387 Inc(gTeamStat
[KP
.Team
].Goals
,
3388 IfThen(SameTeam(FUID
, SpawnerUID
), -1, 1));
3390 if netsrv
then MH_SEND_PlayerStats(SpawnerUID
);
3393 plr
:= g_Player_Get(SpawnerUID
);
3401 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_2
],
3405 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_1
],
3409 g_Console_Add(Format(_lc
[I_PLAYER_KILL
],
3414 else if g_GetUIDType(SpawnerUID
) = UID_MONSTER
then
3415 begin // Óáèò ìîíñòðîì
3416 mon
:= g_Monsters_ByUID(SpawnerUID
);
3420 s
:= g_Mons_GetKilledByTypeId(mon
.MonsterType
);
3424 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_2
],
3428 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_1
],
3432 g_Console_Add(Format(_lc
[I_PLAYER_KILL
],
3437 else // Îñîáûå òèïû ñìåðòè
3440 HIT_SELF
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_SELF
], [FName
]), True);
3441 HIT_FALL
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_FALL
], [FName
]), True);
3442 HIT_WATER
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_WATER
], [FName
]), True);
3443 HIT_ACID
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_ACID
], [FName
]), True);
3444 HIT_TRAP
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_TRAP
], [FName
]), True);
3445 else g_Console_Add(Format(_lc
[I_PLAYER_DIED
], [FName
]), True);
3451 for a
:= WP_FIRST
to WP_LAST
do
3455 WEAPON_SAW
: i
:= ITEM_WEAPON_SAW
;
3456 WEAPON_SHOTGUN1
: i
:= ITEM_WEAPON_SHOTGUN1
;
3457 WEAPON_SHOTGUN2
: i
:= ITEM_WEAPON_SHOTGUN2
;
3458 WEAPON_CHAINGUN
: i
:= ITEM_WEAPON_CHAINGUN
;
3459 WEAPON_ROCKETLAUNCHER
: i
:= ITEM_WEAPON_ROCKETLAUNCHER
;
3460 WEAPON_PLASMA
: i
:= ITEM_WEAPON_PLASMA
;
3461 WEAPON_BFG
: i
:= ITEM_WEAPON_BFG
;
3462 WEAPON_SUPERPULEMET
: i
:= ITEM_WEAPON_SUPERPULEMET
;
3463 WEAPON_FLAMETHROWER
: i
:= ITEM_WEAPON_FLAMETHROWER
;
3472 if R_ITEM_BACKPACK
in FRulez
then
3473 PushItem(ITEM_AMMO_BACKPACK
);
3475 // Âûáðîñ ðàêåòíîãî ðàíöà:
3476 if FJetFuel
> 0 then
3477 PushItem(ITEM_JETPACK
);
3480 if not (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
]) then
3482 if R_KEY_RED
in FRulez
then
3483 PushItem(ITEM_KEY_RED
);
3485 if R_KEY_GREEN
in FRulez
then
3486 PushItem(ITEM_KEY_GREEN
);
3488 if R_KEY_BLUE
in FRulez
then
3489 PushItem(ITEM_KEY_BLUE
);
3493 DropFlag(KillType
= K_FALLKILL
);
3496 g_Player_CreateCorpse(Self
);
3498 if Srv
and (gGameSettings
.MaxLives
> 0) and FNoRespawn
and
3499 (gLMSRespawn
= LMS_RESPAWN_NONE
) then
3505 for i
:= Low(gPlayers
) to High(gPlayers
) do
3507 if gPlayers
[i
] = nil then continue
;
3508 if (not gPlayers
[i
].FNoRespawn
) and (not gPlayers
[i
].FSpectator
) then
3511 if gPlayers
[i
].FTeam
= TEAM_RED
then Inc(ar
)
3512 else if gPlayers
[i
].FTeam
= TEAM_BLUE
then Inc(ab
);
3517 OldLR
:= gLMSRespawn
;
3518 if (gGameSettings
.GameMode
= GM_COOP
) then
3522 // everyone is dead, restart the map
3523 g_Game_Message(_lc
[I_MESSAGE_LMS_LOSE
], 144);
3525 MH_SEND_GameEvent(NET_EV_LMS_LOSE
);
3526 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3527 gLMSRespawnTime
:= gTime
+ 5000;
3529 else if (a
= 1) then
3531 if (gPlayers
[k
] <> nil) and not (gPlayers
[k
] is TBot
) then
3532 if (gPlayers
[k
] = gPlayer1
) or
3533 (gPlayers
[k
] = gPlayer2
) then
3534 g_Console_Add('*** ' + _lc
[I_MESSAGE_LMS_SURVIVOR
] + ' ***', True)
3535 else if Netsrv
and (gPlayers
[k
].FClientID
>= 0) then
3536 MH_SEND_GameEvent(NET_EV_LMS_SURVIVOR
, 0, 'N', gPlayers
[k
].FClientID
);
3539 else if (gGameSettings
.GameMode
= GM_TDM
) then
3541 if (ab
= 0) and (ar
<> 0) then
3544 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 144);
3546 MH_SEND_GameEvent(NET_EV_TLMS_WIN
, TEAM_RED
);
3547 Inc(gTeamStat
[TEAM_RED
].Goals
);
3548 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3549 gLMSRespawnTime
:= gTime
+ 5000;
3551 else if (ar
= 0) and (ab
<> 0) then
3554 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 144);
3556 MH_SEND_GameEvent(NET_EV_TLMS_WIN
, TEAM_BLUE
);
3557 Inc(gTeamStat
[TEAM_BLUE
].Goals
);
3558 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3559 gLMSRespawnTime
:= gTime
+ 5000;
3561 else if (ar
= 0) and (ab
= 0) then
3564 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
3566 MH_SEND_GameEvent(NET_EV_LMS_DRAW
, 0, FName
);
3567 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3568 gLMSRespawnTime
:= gTime
+ 5000;
3571 else if (gGameSettings
.GameMode
= GM_DM
) then
3575 if gPlayers
[k
] <> nil then
3578 // survivor is the winner
3579 g_Game_Message(Format(_lc
[I_MESSAGE_LMS_WIN
], [AnsiUpperCase(FName
)]), 144);
3581 MH_SEND_GameEvent(NET_EV_LMS_WIN
, 0, FName
);
3584 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3585 gLMSRespawnTime
:= gTime
+ 5000;
3587 else if (a
= 0) then
3589 // everyone is dead, restart the map
3590 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
3592 MH_SEND_GameEvent(NET_EV_LMS_DRAW
, 0, FName
);
3593 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3594 gLMSRespawnTime
:= gTime
+ 5000;
3597 if srv
and (OldLR
= LMS_RESPAWN_NONE
) and (gLMSRespawn
> LMS_RESPAWN_NONE
) then
3599 if NetMode
= NET_SERVER
then
3600 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, (gLMSRespawnTime
- gTime
) div 1000)
3602 g_Console_Add(Format(_lc
[I_MSG_WARMUP_START
], [(gLMSRespawnTime
- gTime
) div 1000]), True);
3608 MH_SEND_PlayerStats(FUID
);
3609 MH_SEND_PlayerDeath(FUID
, KillType
, t
, SpawnerUID
);
3610 if gGameSettings
.GameMode
= GM_TDM
then MH_SEND_GameStats
;
3613 if srv
and FNoRespawn
then Spectate(True);
3614 FWantsInGame
:= True;
3617 function TPlayer
.BodyInLiquid(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_WATER
or PANEL_ACID1
or PANEL_ACID2
, False);
3623 function TPlayer
.BodyInAcid(XInc
, YInc
: Integer): Boolean;
3625 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
, PLAYER_RECT
.Width
,
3626 PLAYER_RECT
.Height
-20, PANEL_ACID1
or PANEL_ACID2
, False);
3629 procedure TPlayer
.MakeBloodSimple(Count
: Word);
3631 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)+8,
3632 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3633 Count
div 2, 3, -1, 16, (PLAYER_RECT
.Height
*2 div 3),
3634 FModel
.Blood
.R
, FModel
.Blood
.G
, FModel
.Blood
.B
, FModel
.Blood
.Kind
);
3635 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-8,
3636 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3637 Count
div 2, -3, -1, 16, (PLAYER_RECT
.Height
*2) div 3,
3638 FModel
.Blood
.R
, FModel
.Blood
.G
, FModel
.Blood
.B
, FModel
.Blood
.Kind
);
3641 procedure TPlayer
.MakeBloodVector(Count
: Word; VelX
, VelY
: Integer);
3643 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
3644 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3645 Count
, VelX
, VelY
, 16, (PLAYER_RECT
.Height
*2) div 3,
3646 FModel
.Blood
.R
, FModel
.Blood
.G
, FModel
.Blood
.B
, FModel
.Blood
.Kind
);
3649 procedure TPlayer
.QueueWeaponSwitch(Weapon
: Byte);
3651 if g_Game_IsClient
then Exit
;
3652 if Weapon
> High(FWeapon
) then Exit
;
3653 FNextWeap
:= FNextWeap
or (1 shl Weapon
);
3656 procedure TPlayer
.resetWeaponQueue ();
3659 FNextWeapDelay
:= 0;
3662 function TPlayer
.hasAmmoForWeapon (weapon
: Byte): Boolean;
3666 WEAPON_KASTET
, WEAPON_SAW
: result
:= true;
3667 WEAPON_SHOTGUN1
, WEAPON_SHOTGUN2
: result
:= (FAmmo
[A_SHELLS
] > 0);
3668 WEAPON_PISTOL
, WEAPON_CHAINGUN
, WEAPON_SUPERPULEMET
: result
:= (FAmmo
[A_BULLETS
] > 0);
3669 WEAPON_ROCKETLAUNCHER
: result
:= (FAmmo
[A_ROCKETS
] > 0);
3670 WEAPON_PLASMA
, WEAPON_BFG
: result
:= (FAmmo
[A_CELLS
] > 0);
3671 WEAPON_FLAMETHROWER
: result
:= (FAmmo
[A_FUEL
] > 0);
3672 else result
:= (weapon
< length(FWeapon
));
3676 // return 255 for "no switch"
3677 function TPlayer
.getNextWeaponIndex (): Byte;
3680 wantThisWeapon
: array[0..64] of Boolean;
3681 wwc
: Integer = 0; //HACK!
3684 result
:= 255; // default result: "no switch"
3685 // had weapon cycling on previous frame? remove that flag
3686 if (FNextWeap
and $2000) <> 0 then
3688 FNextWeap
:= FNextWeap
and $1FFF;
3689 FNextWeapDelay
:= 0;
3691 // cycling has priority
3692 if (FNextWeap
and $C000) <> 0 then
3694 if (FNextWeap
and $8000) <> 0 then
3698 FNextWeap
:= FNextWeap
or $2000; // we need this
3699 if FNextWeapDelay
> 0 then
3700 exit
; // cooldown time
3702 for i
:= 0 to High(FWeapon
) do
3704 cwi
:= (cwi
+length(FWeapon
)+dir
) mod length(FWeapon
);
3705 if FWeapon
[cwi
] then
3707 //e_WriteLog(Format(' SWITCH: cur=%d; new=%d', [FCurrWeap, cwi]), MSG_WARNING);
3708 result
:= Byte(cwi
);
3709 FNextWeapDelay
:= WEAPON_DELAY
;
3717 for i
:= 0 to High(wantThisWeapon
) do
3718 wantThisWeapon
[i
] := false;
3719 for i
:= 0 to High(FWeapon
) do
3720 if (FNextWeap
and (1 shl i
)) <> 0 then
3722 wantThisWeapon
[i
] := true;
3725 // exclude currently selected weapon from the set
3726 wantThisWeapon
[FCurrWeap
] := false;
3727 // slow down alterations a little
3730 //e_WriteLog(Format(' FNextWeap=%x; delay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
3731 // more than one weapon requested, assume "alteration" and check alteration delay
3732 if FNextWeapDelay
> 0 then
3738 // do not reset weapon queue, it will be done in `RealizeCurrentWeapon()`
3739 // but clear all counters if no weapon should be switched
3745 //e_WriteLog(Format('wwc=%d', [wwc]), MSG_WARNING);
3746 // try weapons in descending order
3747 for i
:= High(FWeapon
) downto 0 do
3749 if wantThisWeapon
[i
] and FWeapon
[i
] and ((wwc
= 1) or hasAmmoForWeapon(i
)) then
3754 FNextWeapDelay
:= WEAPON_DELAY
* 2; // anyway, 'cause why not
3758 // no suitable weapon found, so reset the queue, to avoid accidental "queuing" of weapon w/o ammo
3762 procedure TPlayer
.RealizeCurrentWeapon();
3763 function switchAllowed (): Boolean;
3768 if FBFGFireCounter
<> -1 then
3770 if FTime
[T_SWITCH
] > gTime
then
3772 for i
:= WP_FIRST
to WP_LAST
do
3773 if FReloading
[i
] > 0 then
3781 //e_WriteLog(Format('***RealizeCurrentWeapon: FNextWeap=%x; FNextWeapDelay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
3782 //FNextWeap := FNextWeap and $1FFF;
3783 if FNextWeapDelay
> 0 then Dec(FNextWeapDelay
); // "alteration delay"
3785 if not switchAllowed
then
3787 //HACK for weapon cycling
3788 if (FNextWeap
and $E000) <> 0 then FNextWeap
:= 0;
3792 nw
:= getNextWeaponIndex();
3793 if nw
= 255 then exit
; // don't reset anything here
3794 if nw
> High(FWeapon
) then
3796 // don't forget to reset queue here!
3797 //e_WriteLog(' RealizeCurrentWeapon: WUTAFUUUU', MSG_WARNING);
3805 FTime
[T_SWITCH
] := gTime
+156;
3806 if FCurrWeap
= WEAPON_SAW
then FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3807 FModel
.SetWeapon(FCurrWeap
);
3808 if g_Game_IsNet
then MH_SEND_PlayerStats(FUID
);
3812 procedure TPlayer
.NextWeapon();
3814 if g_Game_IsClient
then Exit
;
3818 procedure TPlayer
.PrevWeapon();
3820 if g_Game_IsClient
then Exit
;
3824 procedure TPlayer
.SetWeapon(W
: Byte);
3826 if FCurrWeap
<> W
then
3827 if W
= WEAPON_SAW
then
3828 FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3831 FModel
.SetWeapon(CurrWeap
);
3835 function TPlayer
.PickItem(ItemType
: Byte; arespawn
: Boolean; var remove
: Boolean): Boolean;
3837 function allowBerserkSwitching (): Boolean;
3839 if (FBFGFireCounter
<> -1) then begin result
:= false; exit
; end;
3841 if gBerserkAutoswitch
then exit
;
3842 if not conIsCheatsEnabled
then exit
;
3850 if g_Game_IsClient
then Exit
;
3852 // a = true - ìåñòî ñïàâíà ïðåäìåòà:
3853 a
:= LongBool(gGameSettings
.Options
and GAME_OPTION_WEAPONSTAY
) and arespawn
;
3858 if (FHealth
< PLAYER_HP_SOFT
) or (FFireTime
> 0) then
3860 if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
3864 if gFlash
= 2 then Inc(FPickup
, 5);
3868 if (FHealth
< PLAYER_HP_SOFT
) or (FFireTime
> 0) then
3870 if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
3874 if gFlash
= 2 then Inc(FPickup
, 5);
3878 if FArmor
< PLAYER_AP_SOFT
then
3880 FArmor
:= PLAYER_AP_SOFT
;
3883 if gFlash
= 2 then Inc(FPickup
, 5);
3887 if FArmor
< PLAYER_AP_LIMIT
then
3889 FArmor
:= PLAYER_AP_LIMIT
;
3892 if gFlash
= 2 then Inc(FPickup
, 5);
3896 if (FHealth
< PLAYER_HP_LIMIT
) or (FFireTime
> 0) then
3898 if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
3902 if gFlash
= 2 then Inc(FPickup
, 5);
3906 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) or (FFireTime
> 0) then
3908 if FHealth
< PLAYER_HP_LIMIT
then
3909 FHealth
:= PLAYER_HP_LIMIT
;
3910 if FArmor
< PLAYER_AP_LIMIT
then
3911 FArmor
:= PLAYER_AP_LIMIT
;
3915 if gFlash
= 2 then Inc(FPickup
, 5);
3919 if (not FWeapon
[WEAPON_SAW
]) or ((not arespawn
) and (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
])) then
3921 FWeapon
[WEAPON_SAW
] := True;
3923 if gFlash
= 2 then Inc(FPickup
, 5);
3924 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3927 ITEM_WEAPON_SHOTGUN1
:
3928 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN1
] then
3930 // Íóæíî, ÷òîáû íå âçÿòü âñå ïóëè ñðàçó:
3931 if a
and FWeapon
[WEAPON_SHOTGUN1
] then Exit
;
3933 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3934 FWeapon
[WEAPON_SHOTGUN1
] := True;
3936 if gFlash
= 2 then Inc(FPickup
, 5);
3937 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3940 ITEM_WEAPON_SHOTGUN2
:
3941 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN2
] then
3943 if a
and FWeapon
[WEAPON_SHOTGUN2
] then Exit
;
3945 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3946 FWeapon
[WEAPON_SHOTGUN2
] := True;
3948 if gFlash
= 2 then Inc(FPickup
, 5);
3949 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3952 ITEM_WEAPON_CHAINGUN
:
3953 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or not FWeapon
[WEAPON_CHAINGUN
] then
3955 if a
and FWeapon
[WEAPON_CHAINGUN
] then Exit
;
3957 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
3958 FWeapon
[WEAPON_CHAINGUN
] := True;
3960 if gFlash
= 2 then Inc(FPickup
, 5);
3961 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3964 ITEM_WEAPON_ROCKETLAUNCHER
:
3965 if (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or not FWeapon
[WEAPON_ROCKETLAUNCHER
] then
3967 if a
and FWeapon
[WEAPON_ROCKETLAUNCHER
] then Exit
;
3969 IncMax(FAmmo
[A_ROCKETS
], 2, FMaxAmmo
[A_ROCKETS
]);
3970 FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
3972 if gFlash
= 2 then Inc(FPickup
, 5);
3973 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3977 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_PLASMA
] then
3979 if a
and FWeapon
[WEAPON_PLASMA
] then Exit
;
3981 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3982 FWeapon
[WEAPON_PLASMA
] := True;
3984 if gFlash
= 2 then Inc(FPickup
, 5);
3985 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3989 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_BFG
] then
3991 if a
and FWeapon
[WEAPON_BFG
] then Exit
;
3993 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3994 FWeapon
[WEAPON_BFG
] := True;
3996 if gFlash
= 2 then Inc(FPickup
, 5);
3997 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4000 ITEM_WEAPON_SUPERPULEMET
:
4001 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SUPERPULEMET
] then
4003 if a
and FWeapon
[WEAPON_SUPERPULEMET
] then Exit
;
4005 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4006 FWeapon
[WEAPON_SUPERPULEMET
] := True;
4008 if gFlash
= 2 then Inc(FPickup
, 5);
4009 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4012 ITEM_WEAPON_FLAMETHROWER
:
4013 if (FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
]) or not FWeapon
[WEAPON_FLAMETHROWER
] then
4015 if a
and FWeapon
[WEAPON_FLAMETHROWER
] then Exit
;
4017 IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
4018 FWeapon
[WEAPON_FLAMETHROWER
] := True;
4020 if gFlash
= 2 then Inc(FPickup
, 5);
4021 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
4025 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
4027 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
4030 if gFlash
= 2 then Inc(FPickup
, 5);
4033 ITEM_AMMO_BULLETS_BOX
:
4034 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
4036 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
4039 if gFlash
= 2 then Inc(FPickup
, 5);
4043 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
4045 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4048 if gFlash
= 2 then Inc(FPickup
, 5);
4051 ITEM_AMMO_SHELLS_BOX
:
4052 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
4054 IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
4057 if gFlash
= 2 then Inc(FPickup
, 5);
4061 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
4063 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
4066 if gFlash
= 2 then Inc(FPickup
, 5);
4069 ITEM_AMMO_ROCKET_BOX
:
4070 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
4072 IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
4075 if gFlash
= 2 then Inc(FPickup
, 5);
4079 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
4081 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
4084 if gFlash
= 2 then Inc(FPickup
, 5);
4088 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
4090 IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
4093 if gFlash
= 2 then Inc(FPickup
, 5);
4097 if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then
4099 IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
4102 if gFlash
= 2 then Inc(FPickup
, 5);
4106 if not(R_ITEM_BACKPACK
in FRulez
) or
4107 (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
4108 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
4109 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
4110 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or
4111 (FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
]) then
4113 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[1, A_BULLETS
];
4114 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[1, A_SHELLS
];
4115 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[1, A_ROCKETS
];
4116 FMaxAmmo
[A_CELLS
] := AmmoLimits
[1, A_CELLS
];
4117 FMaxAmmo
[A_FUEL
] := AmmoLimits
[1, A_FUEL
];
4119 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
4120 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
4121 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
4122 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
4123 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
4124 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
4125 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
4126 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
4127 if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then
4128 IncMax(FAmmo
[A_FUEL
], 50, FMaxAmmo
[A_FUEL
]);
4130 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
4133 if gFlash
= 2 then Inc(FPickup
, 5);
4137 if not(R_KEY_RED
in FRulez
) then
4139 Include(FRulez
, R_KEY_RED
);
4141 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
4142 if gFlash
= 2 then Inc(FPickup
, 5);
4143 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
4147 if not(R_KEY_GREEN
in FRulez
) then
4149 Include(FRulez
, R_KEY_GREEN
);
4151 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
4152 if gFlash
= 2 then Inc(FPickup
, 5);
4153 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
4157 if not(R_KEY_BLUE
in FRulez
) then
4159 Include(FRulez
, R_KEY_BLUE
);
4161 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
4162 if gFlash
= 2 then Inc(FPickup
, 5);
4163 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
4167 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
4169 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
4173 if gFlash
= 2 then Inc(FPickup
, 5);
4177 if FAir
< AIR_MAX
then
4182 if gFlash
= 2 then Inc(FPickup
, 5);
4187 if not (R_BERSERK
in FRulez
) then
4189 Include(FRulez
, R_BERSERK
);
4190 if allowBerserkSwitching
then
4192 FCurrWeap
:= WEAPON_KASTET
;
4194 FModel
.SetWeapon(WEAPON_KASTET
);
4199 if gFlash
= 2 then Inc(FPickup
, 5);
4201 FBerserk
:= gTime
+30000;
4206 if (FHealth
< PLAYER_HP_SOFT
) or (FFireTime
> 0) then
4208 if FHealth
< PLAYER_HP_SOFT
then FHealth
:= PLAYER_HP_SOFT
;
4209 FBerserk
:= gTime
+30000;
4217 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
4219 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
4222 if gFlash
= 2 then Inc(FPickup
, 5);
4226 if (FHealth
< PLAYER_HP_LIMIT
) or (FFireTime
> 0) then
4228 if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
4232 if gFlash
= 2 then Inc(FPickup
, 5);
4236 if FArmor
< PLAYER_AP_LIMIT
then
4238 IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
4241 if gFlash
= 2 then Inc(FPickup
, 5);
4245 if FJetFuel
< JET_MAX
then
4247 FJetFuel
:= JET_MAX
;
4250 if gFlash
= 2 then Inc(FPickup
, 5);
4254 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
4256 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
4259 if gFlash
= 2 then Inc(FPickup
, 5);
4264 procedure TPlayer
.Touch();
4268 //FModel.PlaySound(MODELSOUND_PAIN, 1, FObj.X, FObj.Y);
4271 // Áðîñèòü ôëàã òîâàðèùó:
4272 if gGameSettings
.GameMode
= GM_CTF
then
4277 procedure TPlayer
.Push(vx
, vy
: Integer);
4279 if (not FPhysics
) and FGhost
then
4281 FObj
.Accel
.X
:= FObj
.Accel
.X
+ vx
;
4282 FObj
.Accel
.Y
:= FObj
.Accel
.Y
+ vy
;
4283 if g_Game_IsNet
and g_Game_IsServer
then
4284 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
4287 procedure TPlayer
.Reset(Force
: Boolean);
4293 FTime
[T_RESPAWN
] := 0;
4294 FTime
[T_FLAGCAP
] := 0;
4308 FSpectator
:= False;
4311 FSpectatePlayer
:= -1;
4312 FNoRespawn
:= False;
4314 FLives
:= gGameSettings
.MaxLives
;
4319 procedure TPlayer
.SoftReset();
4325 FBFGFireCounter
:= -1;
4333 SetAction(A_STAND
, True);
4336 function TPlayer
.GetRespawnPoint(): Byte;
4341 // Íà áóäóùåå: FSpawn - èãðîê óæå èãðàë è ïåðåðîæäàåòñÿ
4343 // Îäèíî÷íàÿ èãðà/êîîïåðàòèâ
4344 if gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
] then
4346 if (Self
= gPlayer1
) or (Self
= gPlayer2
) then
4348 // Òî÷êà ïîÿâëåíèÿ ñâîåãî èãðîêà
4349 if Self
= gPlayer1
then
4350 c
:= RESPAWNPOINT_PLAYER1
4352 c
:= RESPAWNPOINT_PLAYER2
;
4353 if g_Map_GetPointCount(c
) > 0 then
4359 // Òî÷êà ïîÿâëåíèÿ äðóãîãî èãðîêà
4360 if Self
= gPlayer1
then
4361 c
:= RESPAWNPOINT_PLAYER2
4363 c
:= RESPAWNPOINT_PLAYER1
;
4364 if g_Map_GetPointCount(c
) > 0 then
4371 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà (áîòà)
4372 if Random(2) = 0 then
4373 c
:= RESPAWNPOINT_PLAYER1
4375 c
:= RESPAWNPOINT_PLAYER2
;
4376 if g_Map_GetPointCount(c
) > 0 then
4383 // Òî÷êà ëþáîé èç êîìàíä
4384 if Random(2) = 0 then
4385 c
:= RESPAWNPOINT_RED
4387 c
:= RESPAWNPOINT_BLUE
;
4388 if g_Map_GetPointCount(c
) > 0 then
4395 c
:= RESPAWNPOINT_DM
;
4396 if g_Map_GetPointCount(c
) > 0 then
4404 if gGameSettings
.GameMode
= GM_DM
then
4407 c
:= RESPAWNPOINT_DM
;
4408 if g_Map_GetPointCount(c
) > 0 then
4414 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà
4415 if Random(2) = 0 then
4416 c
:= RESPAWNPOINT_PLAYER1
4418 c
:= RESPAWNPOINT_PLAYER2
;
4419 if g_Map_GetPointCount(c
) > 0 then
4425 // Òî÷êà ëþáîé èç êîìàíä
4426 if Random(2) = 0 then
4427 c
:= RESPAWNPOINT_RED
4429 c
:= RESPAWNPOINT_BLUE
;
4430 if g_Map_GetPointCount(c
) > 0 then
4438 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
4440 // Òî÷êà ñâîåé êîìàíäû
4441 c
:= RESPAWNPOINT_DM
;
4442 if FTeam
= TEAM_RED
then
4443 c
:= RESPAWNPOINT_RED
;
4444 if FTeam
= TEAM_BLUE
then
4445 c
:= RESPAWNPOINT_BLUE
;
4446 if g_Map_GetPointCount(c
) > 0 then
4453 c
:= RESPAWNPOINT_DM
;
4454 if g_Map_GetPointCount(c
) > 0 then
4460 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà
4461 if Random(2) = 0 then
4462 c
:= RESPAWNPOINT_PLAYER1
4464 c
:= RESPAWNPOINT_PLAYER2
;
4465 if g_Map_GetPointCount(c
) > 0 then
4471 // Òî÷êà äðóãîé êîìàíäû
4472 c
:= RESPAWNPOINT_DM
;
4473 if FTeam
= TEAM_RED
then
4474 c
:= RESPAWNPOINT_BLUE
;
4475 if FTeam
= TEAM_BLUE
then
4476 c
:= RESPAWNPOINT_RED
;
4477 if g_Map_GetPointCount(c
) > 0 then
4485 procedure TPlayer
.Respawn(Silent
: Boolean; Force
: Boolean = False);
4487 RespawnPoint
: TRespawnPoint
;
4493 FBFGFireCounter
:= -1;
4498 if not g_Game_IsServer
then
4502 FWantsInGame
:= True;
4503 FJustTeleported
:= True;
4506 FTime
[T_RESPAWN
] := 0;
4510 // if server changes MaxLives we gotta be ready
4511 if gGameSettings
.MaxLives
= 0 then FNoRespawn
:= False;
4513 // Åùå íåëüçÿ âîçðîäèòüñÿ:
4514 if FTime
[T_RESPAWN
] > gTime
then
4517 // Ïðîñðàë âñå æèçíè:
4520 if not FSpectator
then Spectate(True);
4521 FWantsInGame
:= True;
4525 if (gGameSettings
.GameType
<> GT_SINGLE
) and (gGameSettings
.GameMode
<> GM_COOP
) then
4526 begin // "Ñâîÿ èãðà"
4527 // Áåðñåðê íå ñîõðàíÿåòñÿ ìåæäó óðîâíÿìè:
4528 FRulez
:= FRulez
-[R_BERSERK
];
4530 else // "Îäèíî÷íàÿ èãðà"/"Êîîï"
4532 // Áåðñåðê è êëþ÷è íå ñîõðàíÿþòñÿ ìåæäó óðîâíÿìè:
4533 FRulez
:= FRulez
-[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
, R_BERSERK
];
4536 // Ïîëó÷àåì òî÷êó ñïàóíà èãðîêà:
4537 c
:= GetRespawnPoint();
4542 // Âîñêðåøåíèå áåç îðóæèÿ:
4545 FHealth
:= Round(PLAYER_HP_SOFT
* (FHandicap
/ 100));
4551 for a
:= WP_FIRST
to WP_LAST
do
4553 FWeapon
[a
] := False;
4557 FWeapon
[WEAPON_PISTOL
] := True;
4558 FWeapon
[WEAPON_KASTET
] := True;
4559 FCurrWeap
:= WEAPON_PISTOL
;
4562 FModel
.SetWeapon(FCurrWeap
);
4564 for b
:= A_BULLETS
to A_HIGH
do
4567 FAmmo
[A_BULLETS
] := 50;
4569 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[0, A_BULLETS
];
4570 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[0, A_SHELLS
];
4571 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[0, A_SHELLS
];
4572 FMaxAmmo
[A_CELLS
] := AmmoLimits
[0, A_CELLS
];
4573 FMaxAmmo
[A_FUEL
] := AmmoLimits
[0, A_FUEL
];
4575 if gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
] then
4576 FRulez
:= [R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
]
4581 // Ïîëó÷àåì êîîðäèíàòû òî÷êè âîçðîæäåíèÿ:
4582 if not g_Map_GetPoint(c
, RespawnPoint
) then
4584 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
4588 // Óñòàíîâêà êîîðäèíàò è ñáðîñ âñåõ ïàðàìåòðîâ:
4589 FObj
.X
:= RespawnPoint
.X
-PLAYER_RECT
.X
;
4590 FObj
.Y
:= RespawnPoint
.Y
-PLAYER_RECT
.Y
;
4596 FDirection
:= RespawnPoint
.Direction
;
4597 if FDirection
= TDirection
.D_LEFT
then
4602 SetAction(A_STAND
, True);
4603 FModel
.Direction
:= FDirection
;
4605 for a
:= Low(FTime
) to High(FTime
) do
4608 for a
:= Low(FMegaRulez
) to High(FMegaRulez
) do
4613 FCanJetpack
:= False;
4619 // Àíèìàöèÿ âîçðîæäåíèÿ:
4620 if (not gLoadGameMode
) and (not Silent
) then
4621 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
4623 Anim
:= TAnimation
.Create(ID
, False, 3);
4624 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4625 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4629 FSpectator
:= False;
4632 FSpectatePlayer
:= -1;
4635 if (gPlayer1
= nil) and (gLMSPID1
= FUID
) then
4637 if (gPlayer2
= nil) and (gLMSPID2
= FUID
) then
4640 if g_Game_IsNet
then
4642 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
4643 MH_SEND_PlayerStats(FUID
, NET_EVERYONE
);
4645 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4646 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32,
4651 procedure TPlayer
.Spectate(NoMove
: Boolean = False);
4654 Kill(K_EXTRAHARDKILL
, FUID
, HIT_SOME
)
4655 else if (not NoMove
) then
4657 GameX
:= gMapInfo
.Width
div 2;
4658 GameY
:= gMapInfo
.Height
div 2;
4667 FWantsInGame
:= False;
4672 if Self
= gPlayer1
then
4677 if Self
= gPlayer2
then
4684 if g_Game_IsNet
then
4685 MH_SEND_PlayerStats(FUID
);
4688 procedure TPlayer
.SwitchNoClip
;
4692 FGhost
:= not FGhost
;
4693 FPhysics
:= not FGhost
;
4705 procedure TPlayer
.Run(Direction
: TDirection
);
4709 if MAX_RUNVEL
> 8 then
4713 if Direction
= TDirection
.D_LEFT
then
4715 if FObj
.Vel
.X
> -MAX_RUNVEL
then
4716 FObj
.Vel
.X
:= FObj
.Vel
.X
- (MAX_RUNVEL
shr 3);
4719 if FObj
.Vel
.X
< MAX_RUNVEL
then
4720 FObj
.Vel
.X
:= FObj
.Vel
.X
+ (MAX_RUNVEL
shr 3);
4722 // Âîçìîæíî, ïèíàåì êóñêè:
4723 if (FObj
.Vel
.X
<> 0) and (gGibs
<> nil) then
4725 b
:= Abs(FObj
.Vel
.X
);
4726 if b
> 1 then b
:= b
* (Random(8 div b
) + 1);
4727 for a
:= 0 to High(gGibs
) do
4729 if gGibs
[a
].alive
and
4730 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
+FObj
.Rect
.Height
-4,
4731 FObj
.Rect
.Width
, 8, @gGibs
[a
].Obj
) and (Random(3) = 0) then
4734 if FObj
.Vel
.X
< 0 then
4736 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)+120) // íàëåâî
4740 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)); // íàïðàâî
4742 gGibs
[a
].positionChanged(); // this updates spatial accelerators
4750 procedure TPlayer
.SeeDown();
4752 SetAction(A_SEEDOWN
);
4754 if FDirection
= TDirection
.D_LEFT
then FAngle
:= ANGLE_LEFTDOWN
else FAngle
:= ANGLE_RIGHTDOWN
;
4756 if FIncCam
> -120 then DecMin(FIncCam
, 5, -120);
4759 procedure TPlayer
.SeeUp();
4763 if FDirection
= TDirection
.D_LEFT
then FAngle
:= ANGLE_LEFTUP
else FAngle
:= ANGLE_RIGHTUP
;
4765 if FIncCam
< 120 then IncMax(FIncCam
, 5, 120);
4768 procedure TPlayer
.SetAction(Action
: Byte; Force
: Boolean = False);
4776 A_ATTACK
: Prior
:= 2;
4777 A_SEEUP
: Prior
:= 1;
4778 A_SEEDOWN
: Prior
:= 1;
4779 A_ATTACKUP
: Prior
:= 2;
4780 A_ATTACKDOWN
: Prior
:= 2;
4785 if (Prior
> FActionPrior
) or Force
then
4786 if not ((Prior
= 2) and (FCurrWeap
= WEAPON_SAW
)) then
4788 FActionPrior
:= Prior
;
4789 FActionAnim
:= Action
;
4790 FActionForce
:= Force
;
4791 FActionChanged
:= True;
4794 if Action
in [A_ATTACK
, A_ATTACKUP
, A_ATTACKDOWN
] then FModel
.SetFire(True);
4797 function TPlayer
.StayOnStep(XInc
, YInc
: Integer): Boolean;
4799 Result
:= not g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
-1,
4800 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False)
4801 and g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
,
4802 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False);
4805 function TPlayer
.TeleportTo(X
, Y
: Integer; silent
: Boolean; dir
: Byte): Boolean;
4812 if g_CollideLevel(X
, Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
) then
4814 g_Sound_PlayExAt('SOUND_GAME_NOTELEPORT', FObj
.X
, FObj
.Y
);
4815 if g_Game_IsServer
and g_Game_IsNet
then
4816 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_GAME_NOTELEPORT');
4820 FJustTeleported
:= True;
4825 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
4827 Anim
:= TAnimation
.Create(ID
, False, 3);
4830 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', FObj
.X
, FObj
.Y
);
4831 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4832 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4833 if g_Game_IsServer
and g_Game_IsNet
then
4834 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4835 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 1,
4839 FObj
.X
:= X
-PLAYER_RECT
.X
;
4840 FObj
.Y
:= Y
-PLAYER_RECT
.Y
;
4841 if FAlive
and FGhost
then
4847 if not g_Game_IsNet
then
4851 SetDirection(TDirection
.D_LEFT
);
4857 SetDirection(TDirection
.D_RIGHT
);
4863 if FDirection
= TDirection
.D_RIGHT
then
4865 SetDirection(TDirection
.D_LEFT
);
4870 SetDirection(TDirection
.D_RIGHT
);
4876 if not silent
and (Anim
<> nil) then
4878 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4879 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4882 if g_Game_IsServer
and g_Game_IsNet
then
4883 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4884 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 0,
4891 function nonz(a
: Single): Single;
4899 function TPlayer
.followCorpse(): Boolean;
4904 if FAlive
or FSpectator
then
4906 if (gCorpses
= nil) or (Length(gCorpses
) = 0) then
4908 for i
:= 0 to High(gCorpses
) do
4909 if gCorpses
[i
] <> nil then
4910 if gCorpses
[i
].FPlayerUID
= FUID
then
4913 FObj
.X
:= gCorpses
[i
].FObj
.X
;
4914 FObj
.Y
:= gCorpses
[i
].FObj
.Y
;
4915 FObj
.Vel
.X
:= gCorpses
[i
].FObj
.Vel
.X
;
4916 FObj
.Vel
.Y
:= gCorpses
[i
].FObj
.Vel
.Y
;
4917 FObj
.Accel
.X
:= gCorpses
[i
].FObj
.Accel
.X
;
4918 FObj
.Accel
.Y
:= gCorpses
[i
].FObj
.Accel
.Y
;
4923 procedure TPlayer
.Update();
4926 i
, ii
, wx
, wy
, xd
, yd
, k
: Integer;
4927 blockmon
, headwater
, dospawn
: Boolean;
4932 NetServer
:= g_Game_IsNet
and g_Game_IsServer
;
4933 AnyServer
:= g_Game_IsServer
;
4935 if g_Game_IsClient
and (NetInterpLevel
> 0) then
4936 DoLerp(NetInterpLevel
+ 1)
4942 if FClientID
>= 0 then
4944 FPing
:= NetClients
[FClientID
].Peer
^.lastRoundTripTime
;
4945 if NetClients
[FClientID
].Peer
^.packetsSent
> 0 then
4946 FLoss
:= Round(100*NetClients
[FClientID
].Peer
^.packetsLost
/NetClients
[FClientID
].Peer
^.packetsSent
)
4955 if FAlive
and (FPunchAnim
<> nil) then
4956 FPunchAnim
.Update();
4958 if FAlive
and (gFly
or FJetpack
) then
4961 if FDirection
= TDirection
.D_LEFT
then
4966 if FAlive
and (not FGhost
) then
4968 if FKeys
[KEY_UP
].Pressed
then
4970 if FKeys
[KEY_DOWN
].Pressed
then
4974 if (not (FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_DOWN
].Pressed
)) and
4977 i
:= g_basic
.Sign(FIncCam
);
4978 FIncCam
:= Abs(FIncCam
);
4979 DecMin(FIncCam
, 5, 0);
4980 FIncCam
:= FIncCam
*i
;
4983 // no need to do that each second frame, weapon queue will take care of it
4984 if FAlive
and FKeys
[KEY_NEXTWEAPON
].Pressed
and AnyServer
then NextWeapon();
4985 if FAlive
and FKeys
[KEY_PREVWEAPON
].Pressed
and AnyServer
then PrevWeapon();
4987 if gTime
mod (GAME_TICK
*2) <> 0 then
4989 if (FObj
.Vel
.X
= 0) and FAlive
then
4991 if FKeys
[KEY_LEFT
].Pressed
then
4992 Run(TDirection
.D_LEFT
);
4993 if FKeys
[KEY_RIGHT
].Pressed
then
4994 Run(TDirection
.D_RIGHT
);
4999 if not followCorpse() then
5000 g_Obj_Move(@FObj
, True, True, True);
5001 positionChanged(); // this updates spatial accelerators
5007 FActionChanged
:= False;
5011 // Let alive player do some actions
5012 if FKeys
[KEY_LEFT
].Pressed
then Run(TDirection
.D_LEFT
);
5013 if FKeys
[KEY_RIGHT
].Pressed
then Run(TDirection
.D_RIGHT
);
5014 //if FKeys[KEY_NEXTWEAPON].Pressed and AnyServer then NextWeapon();
5015 //if FKeys[KEY_PREVWEAPON].Pressed and AnyServer then PrevWeapon();
5016 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then Fire()
5022 if NetServer
then MH_SEND_PlayerStats(FUID
);
5025 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Use();
5026 if FKeys
[KEY_JUMP
].Pressed
then Jump()
5029 if AnyServer
and FJetpack
then
5033 if NetServer
then MH_SEND_PlayerStats(FUID
);
5035 FCanJetpack
:= True;
5042 for k
:= Low(FKeys
) to KEY_CHAT
-1 do
5044 if FKeys
[k
].Pressed
then
5052 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
5055 if (FTime
[T_RESPAWN
] <= gTime
) and
5056 gGameOn
and (not FAlive
) then
5058 if (g_Player_GetCount() > 1) then
5062 gExit
:= EXIT_RESTART
;
5067 // Dead spectator actions
5070 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Fire();
5071 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then
5075 if (FSpectatePlayer
>= High(gPlayers
)) then
5076 FSpectatePlayer
:= -1
5080 for I
:= FSpectatePlayer
+ 1 to High(gPlayers
) do
5081 if gPlayers
[I
] <> nil then
5082 if gPlayers
[I
].alive
then
5083 if gPlayers
[I
].UID
<> FUID
then
5085 FSpectatePlayer
:= I
;
5090 if not SetSpect
then FSpectatePlayer
:= -1;
5101 if FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_JUMP
].Pressed
then
5103 FYTo
:= FObj
.Y
- 32;
5104 FSpectatePlayer
:= -1;
5106 if FKeys
[KEY_DOWN
].Pressed
then
5108 FYTo
:= FObj
.Y
+ 32;
5109 FSpectatePlayer
:= -1;
5111 if FKeys
[KEY_LEFT
].Pressed
then
5113 FXTo
:= FObj
.X
- 32;
5114 FSpectatePlayer
:= -1;
5116 if FKeys
[KEY_RIGHT
].Pressed
then
5118 FXTo
:= FObj
.X
+ 32;
5119 FSpectatePlayer
:= -1;
5122 if (FXTo
< -64) then
5124 else if (FXTo
> gMapInfo
.Width
+ 32) then
5125 FXTo
:= gMapInfo
.Width
+ 32;
5126 if (FYTo
< -72) then
5128 else if (FYTo
> gMapInfo
.Height
+ 32) then
5129 FYTo
:= gMapInfo
.Height
+ 32;
5134 if not followCorpse() then
5135 g_Obj_Move(@FObj
, True, True, True);
5136 positionChanged(); // this updates spatial accelerators
5143 if (FSpectatePlayer
<= High(gPlayers
)) and (FSpectatePlayer
>= 0) then
5144 if gPlayers
[FSpectatePlayer
] <> nil then
5145 if gPlayers
[FSpectatePlayer
].alive
then
5147 FXTo
:= gPlayers
[FSpectatePlayer
].GameX
;
5148 FYTo
:= gPlayers
[FSpectatePlayer
].GameY
;
5152 blockmon
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
, FObj
.Y
+PLAYER_HEADRECT
.Y
,
5153 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
5154 PANEL_BLOCKMON
, True);
5155 headwater
:= HeadInLiquid(0, 0);
5157 // Ñîïðîòèâëåíèå âîçäóõà:
5158 if (not FAlive
) or not (FKeys
[KEY_LEFT
].Pressed
or FKeys
[KEY_RIGHT
].Pressed
) then
5159 if FObj
.Vel
.X
<> 0 then
5160 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
5162 if (FLastHit
= HIT_TRAP
) and (FPain
> 90) then FPain
:= 90;
5163 DecMin(FPain
, 5, 0);
5164 DecMin(FPickup
, 1, 0);
5166 if FAlive
and (FObj
.Y
> Integer(gMapInfo
.Height
)+128) and AnyServer
then
5168 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
5169 FMegaRulez
[MR_SUIT
] := 0;
5170 FMegaRulez
[MR_INVUL
] := 0;
5171 FMegaRulez
[MR_INVIS
] := 0;
5172 Kill(K_FALLKILL
, 0, HIT_FALL
);
5179 if FCurrWeap
= WEAPON_SAW
then
5180 if not (FSawSound
.IsPlaying() or FSawSoundHit
.IsPlaying() or
5181 FSawSoundSelect
.IsPlaying()) then
5182 FSawSoundIdle
.PlayAt(FObj
.X
, FObj
.Y
);
5185 if (not FJetSoundFly
.IsPlaying()) and (not FJetSoundOn
.IsPlaying()) and
5186 (not FJetSoundOff
.IsPlaying()) then
5188 FJetSoundFly
.SetPosition(0);
5189 FJetSoundFly
.PlayAt(FObj
.X
, FObj
.Y
);
5192 for b
:= WP_FIRST
to WP_LAST
do
5193 if FReloading
[b
] > 0 then
5199 if FShellTimer
> -1 then
5200 if FShellTimer
= 0 then
5202 if FShellType
= SHELL_SHELL
then
5203 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5204 GameVelX
, GameVelY
-2, SHELL_SHELL
)
5205 else if FShellType
= SHELL_DBLSHELL
then
5207 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5208 GameVelX
+1, GameVelY
-2, SHELL_SHELL
);
5209 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5210 GameVelX
-1, GameVelY
-2, SHELL_SHELL
);
5213 end else Dec(FShellTimer
);
5215 if (FBFGFireCounter
> -1) then
5216 if FBFGFireCounter
= 0 then
5220 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
5221 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
5222 xd
:= wx
+IfThen(FDirection
= TDirection
.D_LEFT
, -30, 30);
5223 yd
:= wy
+firediry();
5224 g_Weapon_bfgshot(wx
, wy
, xd
, yd
, FUID
);
5225 if NetServer
then MH_SEND_PlayerFire(FUID
, WEAPON_BFG
, wx
, wy
, xd
, yd
);
5226 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
5227 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
5228 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
5231 FReloading
[WEAPON_BFG
] := WEAPON_RELOAD
[WEAPON_BFG
];
5232 FBFGFireCounter
:= -1;
5235 FBFGFireCounter
:= 0
5237 Dec(FBFGFireCounter
);
5239 if (FMegaRulez
[MR_SUIT
] < gTime
) and AnyServer
then
5241 b
:= g_GetAcidHit(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
);
5243 if (b
> 0) and (gTime
mod (15*GAME_TICK
) = 0) then Damage(b
, 0, 0, 0, HIT_ACID
);
5246 if (headwater
or blockmon
) then
5252 if AnyServer
then Damage(10, 0, 0, 0, HIT_WATER
);
5255 else if (FAir
mod 31 = 0) and not blockmon
then
5257 g_GFX_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2), FObj
.Y
+PLAYER_RECT
.Y
-4, 5+Random(6), 8, 4);
5258 if Random(2) = 0 then
5259 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
5261 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
5263 end else if FAir
< AIR_DEF
then
5266 if FFireTime
> 0 then
5268 if BodyInLiquid(0, 0) then
5273 else if FMegaRulez
[MR_SUIT
] >= gTime
then
5275 if FMegaRulez
[MR_SUIT
] = gTime
then
5282 if FFirePainTime
<= 0 then
5284 if g_Game_IsServer
then
5285 Damage(2, FFireAttacker
, 0, 0, HIT_FLAME
);
5286 FFirePainTime
:= 12 - FFireTime
div 12;
5288 FFirePainTime
:= FFirePainTime
- 1;
5289 FFireTime
:= FFireTime
- 1;
5290 if ((FFireTime
mod 33) = 0) and (FMegaRulez
[MR_INVUL
] < gTime
) then
5291 FModel
.PlaySound(MODELSOUND_PAIN
, 1, FObj
.X
, FObj
.Y
);
5292 if (FFireTime
= 0) and g_Game_IsNet
and g_Game_IsServer
then
5293 MH_SEND_PlayerStats(FUID
);
5297 if FDamageBuffer
> 0 then
5299 if FDamageBuffer
>= 9 then
5303 if FDamageBuffer
< 30 then i
:= 9
5304 else if FDamageBuffer
< 100 then i
:= 18
5308 ii
:= Round(FDamageBuffer
*FHealth
/ nonz(FArmor
*(3/4)+FHealth
));
5309 FArmor
:= FArmor
-(FDamageBuffer
-ii
);
5310 FHealth
:= FHealth
-ii
;
5313 FHealth
:= FHealth
+FArmor
;
5318 if FHealth
<= 0 then
5319 if FHealth
> -30 then Kill(K_SIMPLEKILL
, FLastSpawnerUID
, FLastHit
)
5320 else if FHealth
> -50 then Kill(K_HARDKILL
, FLastSpawnerUID
, FLastHit
)
5321 else Kill(K_EXTRAHARDKILL
, FLastSpawnerUID
, FLastHit
);
5323 if FAlive
and ((FLastHit
<> HIT_FLAME
) or (FFireTime
<= 0)) then
5325 if FDamageBuffer
<= 20 then FModel
.PlaySound(MODELSOUND_PAIN
, 1, FObj
.X
, FObj
.Y
)
5326 else if FDamageBuffer
<= 55 then FModel
.PlaySound(MODELSOUND_PAIN
, 2, FObj
.X
, FObj
.Y
)
5327 else if FDamageBuffer
<= 120 then FModel
.PlaySound(MODELSOUND_PAIN
, 3, FObj
.X
, FObj
.Y
)
5328 else FModel
.PlaySound(MODELSOUND_PAIN
, 4, FObj
.X
, FObj
.Y
);
5335 end; // if FAlive then ...
5337 if (FActionAnim
= A_PAIN
) and (FModel
.Animation
<> A_PAIN
) then
5339 FModel
.ChangeAnimation(FActionAnim
, FActionForce
);
5340 FModel
.GetCurrentAnimation
.MinLength
:= i
;
5341 FModel
.GetCurrentAnimationMask
.MinLength
:= i
;
5342 end else FModel
.ChangeAnimation(FActionAnim
, FActionForce
and (FModel
.Animation
<> A_STAND
));
5344 if (FModel
.GetCurrentAnimation
.Played
or ((not FActionChanged
) and (FModel
.Animation
= A_WALK
)))
5345 then SetAction(A_STAND
, True);
5347 if not ((FModel
.Animation
= A_WALK
) and (Abs(FObj
.Vel
.X
) < 4) and not FModel
.Fire
) then FModel
.Update
;
5349 for b
:= Low(FKeys
) to High(FKeys
) do
5350 if FKeys
[b
].Time
= 0 then FKeys
[b
].Pressed
:= False else Dec(FKeys
[b
].Time
);
5354 procedure TPlayer
.getMapBox (out x
, y
, w
, h
: Integer); inline;
5356 x
:= FObj
.X
+PLAYER_RECT
.X
;
5357 y
:= FObj
.Y
+PLAYER_RECT
.Y
;
5358 w
:= PLAYER_RECT
.Width
;
5359 h
:= PLAYER_RECT
.Height
;
5363 procedure TPlayer
.moveBy (dx
, dy
: Integer); inline;
5365 if (dx
<> 0) or (dy
<> 0) then
5374 function TPlayer
.Collide(X
, Y
: Integer; Width
, Height
: Word): Boolean;
5376 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
5377 FObj
.Y
+PLAYER_RECT
.Y
,
5384 function TPlayer
.Collide(Panel
: TPanel
): Boolean;
5386 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
5387 FObj
.Y
+PLAYER_RECT
.Y
,
5391 Panel
.Width
, Panel
.Height
);
5394 function TPlayer
.Collide(X
, Y
: Integer): Boolean;
5396 X
:= X
-FObj
.X
-PLAYER_RECT
.X
;
5397 Y
:= Y
-FObj
.Y
-PLAYER_RECT
.Y
;
5398 Result
:= (x
>= 0) and (x
<= PLAYER_RECT
.Width
) and
5399 (y
>= 0) and (y
<= PLAYER_RECT
.Height
);
5402 function g_Player_ValidName(Name
: string): Boolean;
5408 if gPlayers
= nil then Exit
;
5410 for a
:= 0 to High(gPlayers
) do
5411 if gPlayers
[a
] <> nil then
5412 if LowerCase(Name
) = LowerCase(gPlayers
[a
].FName
) then
5419 procedure TPlayer
.SetDirection(Direction
: TDirection
);
5423 d
:= FModel
.Direction
;
5425 FModel
.Direction
:= Direction
;
5426 if d
<> Direction
then FModel
.ChangeAnimation(FModel
.Animation
, True);
5428 FDirection
:= Direction
;
5431 function TPlayer
.GetKeys(): Byte;
5435 if R_KEY_RED
in FRulez
then Result
:= KEY_RED
;
5436 if R_KEY_GREEN
in FRulez
then Result
:= Result
or KEY_GREEN
;
5437 if R_KEY_BLUE
in FRulez
then Result
:= Result
or KEY_BLUE
;
5439 if FTeam
= TEAM_RED
then Result
:= Result
or KEY_REDTEAM
;
5440 if FTeam
= TEAM_BLUE
then Result
:= Result
or KEY_BLUETEAM
;
5443 procedure TPlayer
.Use();
5447 if FTime
[T_USE
] > gTime
then Exit
;
5449 g_Triggers_PressR(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
,
5450 PLAYER_RECT
.Height
, FUID
, ACTIVATE_PLAYERPRESS
);
5452 for a
:= 0 to High(gPlayers
) do
5453 if (gPlayers
[a
] <> nil) and (gPlayers
[a
] <> Self
) and
5454 gPlayers
[a
].alive
and SameTeam(FUID
, gPlayers
[a
].FUID
) and
5455 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
5456 FObj
.Rect
.Width
, FObj
.Rect
.Height
, @gPlayers
[a
].FObj
) then
5458 gPlayers
[a
].Touch();
5459 if g_Game_IsNet
and g_Game_IsServer
then
5460 MH_SEND_GameEvent(NET_EV_PLAYER_TOUCH
, gPlayers
[a
].FUID
);
5463 FTime
[T_USE
] := gTime
+120;
5466 procedure TPlayer
.NetFire(Wpn
: Byte; X
, Y
, AX
, AY
: Integer; WID
: Integer = -1);
5470 WX
, WY
, XD
, YD
: Integer;
5482 if R_BERSERK
in FRulez
then
5484 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
5485 locobj
.X
:= FObj
.X
+FObj
.Rect
.X
;
5486 locobj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
5489 locobj
.rect
.Width
:= 39;
5490 locobj
.rect
.Height
:= 52;
5491 locobj
.Vel
.X
:= (xd
-wx
) div 2;
5492 locobj
.Vel
.Y
:= (yd
-wy
) div 2;
5493 locobj
.Accel
.X
:= xd
-wx
;
5494 locobj
.Accel
.y
:= yd
-wy
;
5496 if g_Weapon_Hit(@locobj
, 50, FUID
, HIT_SOME
) <> 0 then
5497 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
5499 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
5503 FPain
:= min(FPain
+ 25, 50);
5505 g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
5510 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
5511 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
5513 FSawSoundSelect
.Stop();
5515 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
5517 else if not FSawSoundHit
.IsPlaying() then
5519 FSawSoundSelect
.Stop();
5520 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
5527 g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', GameX
, Gamey
);
5528 FFireAngle
:= FAngle
;
5530 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5531 GameVelX
, GameVelY
-2, SHELL_BULLET
);
5536 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
5537 FFireAngle
:= FAngle
;
5540 FShellType
:= SHELL_SHELL
;
5545 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN2', Gamex
, Gamey
);
5546 FFireAngle
:= FAngle
;
5549 FShellType
:= SHELL_DBLSHELL
;
5554 g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', Gamex
, Gamey
);
5555 FFireAngle
:= FAngle
;
5557 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5558 GameVelX
, GameVelY
-2, SHELL_BULLET
);
5561 WEAPON_ROCKETLAUNCHER
:
5563 g_Weapon_Rocket(wx
, wy
, xd
, yd
, FUID
, WID
);
5564 FFireAngle
:= FAngle
;
5570 g_Weapon_Plasma(wx
, wy
, xd
, yd
, FUID
, WID
);
5571 FFireAngle
:= FAngle
;
5577 g_Weapon_BFGShot(wx
, wy
, xd
, yd
, FUID
, WID
);
5578 FFireAngle
:= FAngle
;
5582 WEAPON_SUPERPULEMET
:
5584 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
5585 FFireAngle
:= FAngle
;
5587 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5588 GameVelX
, GameVelY
-2, SHELL_SHELL
);
5591 WEAPON_FLAMETHROWER
:
5593 g_Weapon_flame(wx
, wy
, xd
, yd
, FUID
, WID
);
5595 FFireAngle
:= FAngle
;
5602 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
5603 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
5604 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
5607 procedure TPlayer
.DoLerp(Level
: Integer = 2);
5609 if FObj
.X
<> FXTo
then FObj
.X
:= Lerp(FObj
.X
, FXTo
, Level
);
5610 if FObj
.Y
<> FYTo
then FObj
.Y
:= Lerp(FObj
.Y
, FYTo
, Level
);
5613 procedure TPlayer
.SetLerp(XTo
, YTo
: Integer);
5617 if NetInterpLevel
< 1 then
5627 AX
:= Abs(FXTo
- FObj
.X
);
5628 AY
:= Abs(FYTo
- FObj
.Y
);
5629 if (AX
> 32) or (AX
<= NetInterpLevel
) then
5631 if (AY
> 32) or (AY
<= NetInterpLevel
) then
5636 function TPlayer
.FullInLift(XInc
, YInc
: Integer): Integer;
5638 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5639 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5640 PANEL_LIFTUP
, False) then Result
:= -1
5642 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5643 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5644 PANEL_LIFTDOWN
, False) then Result
:= 1
5648 function TPlayer
.GetFlag(Flag
: Byte): Boolean;
5655 if Flag
= FLAG_NONE
then
5658 if not g_Game_IsServer
then Exit
;
5660 // Ïðèíåñ ÷óæîé ôëàã íà ñâîþ áàçó:
5661 if (Flag
= FTeam
) and
5662 (gFlags
[Flag
].State
= FLAG_STATE_NORMAL
) and
5663 (FFlag
<> FLAG_NONE
) then
5665 if FFlag
= FLAG_RED
then
5666 s
:= _lc
[I_PLAYER_FLAG_RED
]
5668 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5670 evtype
:= FLAG_STATE_SCORED
;
5672 ts
:= Format('%.4d', [gFlags
[FFlag
].CaptureTime
]);
5673 Insert('.', ts
, Length(ts
) + 1 - 3);
5674 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_CAPTURE
], [FName
, s
, ts
]), True);
5676 g_Map_ResetFlag(FFlag
);
5677 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_CAPTURE
], [AnsiUpperCase(s
)]), 144);
5679 if ((Self
= gPlayer1
) or (Self
= gPlayer2
)
5680 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= FTeam
))
5681 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= FTeam
))) then
5686 if not sound_cap_flag
[a
].IsPlaying() then
5687 sound_cap_flag
[a
].Play();
5689 gTeamStat
[FTeam
].Goals
:= gTeamStat
[FTeam
].Goals
+ 1;
5692 if g_Game_IsNet
then
5694 MH_SEND_FlagEvent(evtype
, FFlag
, FUID
, False);
5698 gFlags
[FFlag
].CaptureTime
:= 0;
5703 // Ïîäîáðàë ñâîé ôëàã - âåðíóë åãî íà áàçó:
5704 if (Flag
= FTeam
) and
5705 (gFlags
[Flag
].State
= FLAG_STATE_DROPPED
) then
5707 if Flag
= FLAG_RED
then
5708 s
:= _lc
[I_PLAYER_FLAG_RED
]
5710 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5712 evtype
:= FLAG_STATE_RETURNED
;
5713 gFlags
[Flag
].CaptureTime
:= 0;
5715 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_RETURN
], [FName
, s
]), True);
5717 g_Map_ResetFlag(Flag
);
5718 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
5720 if ((Self
= gPlayer1
) or (Self
= gPlayer2
)
5721 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= FTeam
))
5722 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= FTeam
))) then
5727 if not sound_ret_flag
[a
].IsPlaying() then
5728 sound_ret_flag
[a
].Play();
5731 if g_Game_IsNet
then
5733 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5739 // Ïîäîáðàë ÷óæîé ôëàã:
5740 if (Flag
<> FTeam
) and (FTime
[T_FLAGCAP
] <= gTime
) then
5744 if Flag
= FLAG_RED
then
5745 s
:= _lc
[I_PLAYER_FLAG_RED
]
5747 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5749 evtype
:= FLAG_STATE_CAPTURED
;
5751 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_GET
], [FName
, s
]), True);
5753 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_GET
], [AnsiUpperCase(s
)]), 144);
5755 gFlags
[Flag
].State
:= FLAG_STATE_CAPTURED
;
5757 if ((Self
= gPlayer1
) or (Self
= gPlayer2
)
5758 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= FTeam
))
5759 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= FTeam
))) then
5764 if not sound_get_flag
[a
].IsPlaying() then
5765 sound_get_flag
[a
].Play();
5768 if g_Game_IsNet
then
5770 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5776 procedure TPlayer
.SetFlag(Flag
: Byte);
5779 if FModel
<> nil then
5780 FModel
.SetFlag(FFlag
);
5783 function TPlayer
.DropFlag(Silent
: Boolean = True): Boolean;
5789 if (not g_Game_IsServer
) or (FFlag
= FLAG_NONE
) then
5791 FTime
[T_FLAGCAP
] := gTime
+ 2000;
5792 with gFlags
[FFlag
] do
5796 Direction
:= FDirection
;
5797 State
:= FLAG_STATE_DROPPED
;
5799 g_Obj_Push(@Obj
, (FObj
.Vel
.X
div 2)-2+Random(5),
5800 (FObj
.Vel
.Y
div 2)-2+Random(5));
5801 positionChanged(); // this updates spatial accelerators
5803 if FFlag
= FLAG_RED
then
5804 s
:= _lc
[I_PLAYER_FLAG_RED
]
5806 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5808 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_DROP
], [FName
, s
]), True);
5809 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_DROP
], [AnsiUpperCase(s
)]), 144);
5811 if ((Self
= gPlayer1
) or (Self
= gPlayer2
)
5812 or ((gPlayer1
<> nil) and (gPlayer1
.Team
= FTeam
))
5813 or ((gPlayer2
<> nil) and (gPlayer2
.Team
= FTeam
))) then
5818 if (not Silent
) and (not sound_lost_flag
[a
].IsPlaying()) then
5819 sound_lost_flag
[a
].Play();
5821 if g_Game_IsNet
then
5822 MH_SEND_FlagEvent(FLAG_STATE_DROPPED
, Flag
, FUID
, False);
5828 procedure TPlayer
.GetSecret();
5830 if (self
= gPlayer1
) or (self
= gPlayer2
) then
5832 g_Console_Add(Format(_lc
[I_PLAYER_SECRET
], [FName
]), True);
5833 g_Sound_PlayEx('SOUND_GAME_SECRET');
5838 procedure TPlayer
.PressKey(Key
: Byte; Time
: Word = 1);
5840 Assert(Key
<= High(FKeys
));
5842 FKeys
[Key
].Pressed
:= True;
5843 FKeys
[Key
].Time
:= Time
;
5846 function TPlayer
.IsKeyPressed(K
: Byte): Boolean;
5848 Result
:= FKeys
[K
].Pressed
;
5851 procedure TPlayer
.ReleaseKeys();
5855 for a
:= Low(FKeys
) to High(FKeys
) do
5857 FKeys
[a
].Pressed
:= False;
5862 procedure TPlayer
.OnDamage(Angle
: SmallInt);
5866 function TPlayer
.firediry(): Integer;
5868 if FKeys
[KEY_UP
].Pressed
then Result
:= -42
5869 else if FKeys
[KEY_DOWN
].Pressed
then Result
:= 19
5873 procedure TPlayer
.RememberState();
5877 FSavedState
.Health
:= FHealth
;
5878 FSavedState
.Armor
:= FArmor
;
5879 FSavedState
.Air
:= FAir
;
5880 FSavedState
.JetFuel
:= FJetFuel
;
5881 FSavedState
.CurrWeap
:= FCurrWeap
;
5882 FSavedState
.NextWeap
:= FNextWeap
;
5883 FSavedState
.NextWeapDelay
:= FNextWeapDelay
;
5886 FSavedState
.Ammo
[i
] := FAmmo
[i
];
5888 FSavedState
.MaxAmmo
[i
] := FMaxAmmo
[i
];
5890 FSavedState
.Rulez
:= FRulez
;
5891 FSavedState
.WaitRecall
:= True;
5894 procedure TPlayer
.RecallState();
5898 if not FSavedState
.WaitRecall
then Exit
;
5900 FHealth
:= FSavedState
.Health
;
5901 FArmor
:= FSavedState
.Armor
;
5902 FAir
:= FSavedState
.Air
;
5903 FJetFuel
:= FSavedState
.JetFuel
;
5904 FCurrWeap
:= FSavedState
.CurrWeap
;
5905 FNextWeap
:= FSavedState
.NextWeap
;
5906 FNextWeapDelay
:= FSavedState
.NextWeapDelay
;
5909 FAmmo
[i
] := FSavedState
.Ammo
[i
];
5911 FMaxAmmo
[i
] := FSavedState
.MaxAmmo
[i
];
5913 FRulez
:= FSavedState
.Rulez
;
5914 FSavedState
.WaitRecall
:= False;
5916 if gGameSettings
.GameType
= GT_SERVER
then
5917 MH_SEND_PlayerStats(FUID
);
5920 procedure TPlayer
.SaveState (st
: TStream
);
5926 utils
.writeSign(st
, 'PLYR');
5927 utils
.writeInt(st
, Byte(PLR_SAVE_VERSION
)); // version
5929 utils
.writeBool(st
, FIamBot
);
5931 utils
.writeInt(st
, Word(FUID
));
5933 utils
.writeStr(st
, FName
);
5935 utils
.writeInt(st
, Byte(FTeam
));
5937 utils
.writeBool(st
, FAlive
);
5938 // Èçðàñõîäîâàë ëè âñå æèçíè
5939 utils
.writeBool(st
, FNoRespawn
);
5941 if FDirection
= TDirection
.D_LEFT
then b
:= 1 else b
:= 2; // D_RIGHT
5942 utils
.writeInt(st
, Byte(b
));
5944 utils
.writeInt(st
, LongInt(FHealth
));
5945 // Êîýôôèöèåíò èíâàëèäíîñòè
5946 utils
.writeInt(st
, LongInt(FHandicap
));
5948 utils
.writeInt(st
, Byte(FLives
));
5950 utils
.writeInt(st
, LongInt(FArmor
));
5952 utils
.writeInt(st
, LongInt(FAir
));
5954 utils
.writeInt(st
, LongInt(FJetFuel
));
5956 utils
.writeInt(st
, LongInt(FPain
));
5958 utils
.writeInt(st
, LongInt(FKills
));
5960 utils
.writeInt(st
, LongInt(FMonsterKills
));
5962 utils
.writeInt(st
, LongInt(FFrags
));
5964 utils
.writeInt(st
, Byte(FFragCombo
));
5965 // Âðåìÿ ïîñëåäíåãî ôðàãà
5966 utils
.writeInt(st
, LongWord(FLastFrag
));
5968 utils
.writeInt(st
, LongInt(FDeath
));
5970 utils
.writeInt(st
, Byte(FFlag
));
5972 utils
.writeInt(st
, LongInt(FSecrets
));
5974 utils
.writeInt(st
, Byte(FCurrWeap
));
5976 utils
.writeInt(st
, Word(FNextWeap
));
5978 utils
.writeInt(st
, Byte(FNextWeapDelay
));
5979 // Âðåìÿ çàðÿäêè BFG
5980 utils
.writeInt(st
, SmallInt(FBFGFireCounter
));
5982 utils
.writeInt(st
, LongInt(FDamageBuffer
));
5983 // Ïîñëåäíèé óäàðèâøèé
5984 utils
.writeInt(st
, Word(FLastSpawnerUID
));
5985 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà
5986 utils
.writeInt(st
, Byte(FLastHit
));
5988 Obj_SaveState(st
, @FObj
);
5989 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ
5990 for i
:= A_BULLETS
to A_HIGH
do utils
.writeInt(st
, Word(FAmmo
[i
]));
5991 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ
5992 for i
:= A_BULLETS
to A_HIGH
do utils
.writeInt(st
, Word(FMaxAmmo
[i
]));
5994 for i
:= WP_FIRST
to WP_LAST
do utils
.writeBool(st
, FWeapon
[i
]);
5995 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ
5996 for i
:= WP_FIRST
to WP_LAST
do utils
.writeInt(st
, Word(FReloading
[i
]));
5998 utils
.writeBool(st
, (R_ITEM_BACKPACK
in FRulez
));
5999 // Íàëè÷èå êðàñíîãî êëþ÷à
6000 utils
.writeBool(st
, (R_KEY_RED
in FRulez
));
6001 // Íàëè÷èå çåëåíîãî êëþ÷à
6002 utils
.writeBool(st
, (R_KEY_GREEN
in FRulez
));
6003 // Íàëè÷èå ñèíåãî êëþ÷à
6004 utils
.writeBool(st
, (R_KEY_BLUE
in FRulez
));
6006 utils
.writeBool(st
, (R_BERSERK
in FRulez
));
6007 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ
6008 for i
:= MR_SUIT
to MR_MAX
do utils
.writeInt(st
, LongWord(FMegaRulez
[i
]));
6009 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà
6010 for i
:= T_RESPAWN
to T_FLAGCAP
do utils
.writeInt(st
, LongWord(FTime
[i
]));
6012 utils
.writeStr(st
, FModel
.Name
);
6014 utils
.writeInt(st
, Byte(FColor
.R
));
6015 utils
.writeInt(st
, Byte(FColor
.G
));
6016 utils
.writeInt(st
, Byte(FColor
.B
));
6020 procedure TPlayer
.LoadState (st
: TStream
);
6029 if not utils
.checkSign(st
, 'PLYR') then raise XStreamError
.Create('invalid player signature');
6030 if (utils
.readByte(st
) <> PLR_SAVE_VERSION
) then raise XStreamError
.Create('invalid player version');
6032 FIamBot
:= utils
.readBool(st
);
6034 FUID
:= utils
.readWord(st
);
6036 str
:= utils
.readStr(st
);
6037 if (self
<> gPlayer1
) and (self
<> gPlayer2
) then FName
:= str
;
6039 FTeam
:= utils
.readByte(st
);
6041 FAlive
:= utils
.readBool(st
);
6042 // Èçðàñõîäîâàë ëè âñå æèçíè
6043 FNoRespawn
:= utils
.readBool(st
);
6045 b
:= utils
.readByte(st
);
6046 if b
= 1 then FDirection
:= TDirection
.D_LEFT
else FDirection
:= TDirection
.D_RIGHT
; // b = 2
6048 FHealth
:= utils
.readLongInt(st
);
6049 // Êîýôôèöèåíò èíâàëèäíîñòè
6050 FHandicap
:= utils
.readLongInt(st
);
6052 FLives
:= utils
.readByte(st
);
6054 FArmor
:= utils
.readLongInt(st
);
6056 FAir
:= utils
.readLongInt(st
);
6058 FJetFuel
:= utils
.readLongInt(st
);
6060 FPain
:= utils
.readLongInt(st
);
6062 FKills
:= utils
.readLongInt(st
);
6064 FMonsterKills
:= utils
.readLongInt(st
);
6066 FFrags
:= utils
.readLongInt(st
);
6068 FFragCombo
:= utils
.readByte(st
);
6069 // Âðåìÿ ïîñëåäíåãî ôðàãà
6070 FLastFrag
:= utils
.readLongWord(st
);
6072 FDeath
:= utils
.readLongInt(st
);
6074 FFlag
:= utils
.readByte(st
);
6076 FSecrets
:= utils
.readLongInt(st
);
6078 FCurrWeap
:= utils
.readByte(st
);
6080 FNextWeap
:= utils
.readWord(st
);
6082 FNextWeapDelay
:= utils
.readByte(st
);
6083 // Âðåìÿ çàðÿäêè BFG
6084 FBFGFireCounter
:= utils
.readSmallInt(st
);
6086 FDamageBuffer
:= utils
.readLongInt(st
);
6087 // Ïîñëåäíèé óäàðèâøèé
6088 FLastSpawnerUID
:= utils
.readWord(st
);
6089 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà
6090 FLastHit
:= utils
.readByte(st
);
6092 Obj_LoadState(@FObj
, st
);
6093 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ
6094 for i
:= A_BULLETS
to A_HIGH
do FAmmo
[i
] := utils
.readWord(st
);
6095 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ
6096 for i
:= A_BULLETS
to A_HIGH
do FMaxAmmo
[i
] := utils
.readWord(st
);
6098 for i
:= WP_FIRST
to WP_LAST
do FWeapon
[i
] := utils
.readBool(st
);
6099 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ
6100 for i
:= WP_FIRST
to WP_LAST
do FReloading
[i
] := utils
.readWord(st
);
6102 if utils
.readBool(st
) then Include(FRulez
, R_ITEM_BACKPACK
);
6103 // Íàëè÷èå êðàñíîãî êëþ÷à
6104 if utils
.readBool(st
) then Include(FRulez
, R_KEY_RED
);
6105 // Íàëè÷èå çåëåíîãî êëþ÷à
6106 if utils
.readBool(st
) then Include(FRulez
, R_KEY_GREEN
);
6107 // Íàëè÷èå ñèíåãî êëþ÷à
6108 if utils
.readBool(st
) then Include(FRulez
, R_KEY_BLUE
);
6110 if utils
.readBool(st
) then Include(FRulez
, R_BERSERK
);
6111 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ
6112 for i
:= MR_SUIT
to MR_MAX
do FMegaRulez
[i
] := utils
.readLongWord(st
);
6113 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà
6114 for i
:= T_RESPAWN
to T_FLAGCAP
do FTime
[i
] := utils
.readLongWord(st
);
6116 str
:= utils
.readStr(st
);
6118 FColor
.R
:= utils
.readByte(st
);
6119 FColor
.G
:= utils
.readByte(st
);
6120 FColor
.B
:= utils
.readByte(st
);
6121 if (self
= gPlayer1
) then
6123 str
:= gPlayer1Settings
.Model
;
6124 FColor
:= gPlayer1Settings
.Color
;
6126 else if (self
= gPlayer2
) then
6128 str
:= gPlayer2Settings
.Model
;
6129 FColor
:= gPlayer2Settings
.Color
;
6131 // Îáíîâëÿåì ìîäåëü èãðîêà
6133 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
6134 FModel
.Color
:= TEAMCOLOR
[FTeam
]
6136 FModel
.Color
:= FColor
;
6140 procedure TPlayer
.AllRulez(Health
: Boolean);
6146 FHealth
:= PLAYER_HP_LIMIT
;
6147 FArmor
:= PLAYER_AP_LIMIT
;
6151 for a
:= WP_FIRST
to WP_LAST
do FWeapon
[a
] := True;
6152 for a
:= A_BULLETS
to A_HIGH
do FAmmo
[a
] := 30000;
6153 FRulez
:= FRulez
+[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
];
6156 procedure TPlayer
.RestoreHealthArmor();
6158 FHealth
:= PLAYER_HP_LIMIT
;
6159 FArmor
:= PLAYER_AP_LIMIT
;
6162 procedure TPlayer
.FragCombo();
6166 if (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) or g_Game_IsClient
then
6168 if gTime
- FLastFrag
< FRAG_COMBO_TIME
then
6170 if FFragCombo
< 5 then
6172 Param
:= FUID
or (FFragCombo
shl 16);
6173 if (FComboEvnt
>= Low(gDelayedEvents
)) and
6174 (FComboEvnt
<= High(gDelayedEvents
)) and
6175 gDelayedEvents
[FComboEvnt
].Pending
and
6176 (gDelayedEvents
[FComboEvnt
].DEType
= DE_KILLCOMBO
) and
6177 (gDelayedEvents
[FComboEvnt
].DENum
and $FFFF = FUID
) then
6179 gDelayedEvents
[FComboEvnt
].Time
:= gTime
+ 500;
6180 gDelayedEvents
[FComboEvnt
].DENum
:= Param
;
6183 FComboEvnt
:= g_Game_DelayEvent(DE_KILLCOMBO
, 500, Param
);
6191 procedure TPlayer
.GiveItem(ItemType
: Byte);
6195 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
6197 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
6201 if FAir
< AIR_MAX
then
6208 if not (R_BERSERK
in FRulez
) then
6210 Include(FRulez
, R_BERSERK
);
6211 if FBFGFireCounter
< 1 then
6213 FCurrWeap
:= WEAPON_KASTET
;
6215 FModel
.SetWeapon(WEAPON_KASTET
);
6219 FBerserk
:= gTime
+30000;
6221 if FHealth
< PLAYER_HP_SOFT
then
6223 FHealth
:= PLAYER_HP_SOFT
;
6224 FBerserk
:= gTime
+30000;
6229 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
6231 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
6235 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
6237 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
6241 if FJetFuel
< JET_MAX
then
6243 FJetFuel
:= JET_MAX
;
6246 ITEM_MEDKIT_SMALL
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
6247 ITEM_MEDKIT_LARGE
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
6249 ITEM_ARMOR_GREEN
: if FArmor
< PLAYER_AP_SOFT
then FArmor
:= PLAYER_AP_SOFT
;
6250 ITEM_ARMOR_BLUE
: if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
6252 ITEM_SPHERE_BLUE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
6254 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) then
6256 if FHealth
< PLAYER_HP_LIMIT
then FHealth
:= PLAYER_HP_LIMIT
;
6257 if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
6260 ITEM_WEAPON_SAW
: FWeapon
[WEAPON_SAW
] := True;
6261 ITEM_WEAPON_SHOTGUN1
: FWeapon
[WEAPON_SHOTGUN1
] := True;
6262 ITEM_WEAPON_SHOTGUN2
: FWeapon
[WEAPON_SHOTGUN2
] := True;
6263 ITEM_WEAPON_CHAINGUN
: FWeapon
[WEAPON_CHAINGUN
] := True;
6264 ITEM_WEAPON_ROCKETLAUNCHER
: FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
6265 ITEM_WEAPON_PLASMA
: FWeapon
[WEAPON_PLASMA
] := True;
6266 ITEM_WEAPON_BFG
: FWeapon
[WEAPON_BFG
] := True;
6267 ITEM_WEAPON_SUPERPULEMET
: FWeapon
[WEAPON_SUPERPULEMET
] := True;
6268 ITEM_WEAPON_FLAMETHROWER
: FWeapon
[WEAPON_FLAMETHROWER
] := True;
6270 ITEM_AMMO_BULLETS
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
6271 ITEM_AMMO_BULLETS_BOX
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
6272 ITEM_AMMO_SHELLS
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
6273 ITEM_AMMO_SHELLS_BOX
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
6274 ITEM_AMMO_ROCKET
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
6275 ITEM_AMMO_ROCKET_BOX
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
6276 ITEM_AMMO_CELL
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
6277 ITEM_AMMO_CELL_BIG
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
6278 ITEM_AMMO_FUELCAN
: if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
6281 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
6282 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
6283 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
6284 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or
6285 (FMaxAmmo
[A_FUEL
] < AmmoLimits
[1, A_FUEL
]) then
6287 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[1, A_BULLETS
];
6288 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[1, A_SHELLS
];
6289 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[1, A_ROCKETS
];
6290 FMaxAmmo
[A_CELLS
] := AmmoLimits
[1, A_CELLS
];
6291 FMaxAmmo
[A_FUEL
] := AmmoLimits
[1, A_FUEL
];
6293 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
6294 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
6295 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
6296 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
6298 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
6301 ITEM_KEY_RED
: if not (R_KEY_RED
in FRulez
) then Include(FRulez
, R_KEY_RED
);
6302 ITEM_KEY_GREEN
: if not (R_KEY_GREEN
in FRulez
) then Include(FRulez
, R_KEY_GREEN
);
6303 ITEM_KEY_BLUE
: if not (R_KEY_BLUE
in FRulez
) then Include(FRulez
, R_KEY_BLUE
);
6305 ITEM_BOTTLE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
6306 ITEM_HELMET
: if FArmor
< PLAYER_AP_LIMIT
then IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
6311 if g_Game_IsNet
and g_Game_IsServer
then
6312 MH_SEND_PlayerStats(FUID
);
6315 procedure TPlayer
.FlySmoke(Times
: DWORD
= 1);
6320 if (Random(5) = 1) and (Times
= 1) then
6323 if BodyInLiquid(0, 0) then
6325 g_GFX_Bubbles(Obj
.X
+Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2)+Random(3)-1,
6326 Obj
.Y
+Obj
.Rect
.Height
+8, 1, 8, 4);
6327 if Random(2) = 0 then
6328 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
6330 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
6334 if g_Frames_Get(id
, 'FRAMES_SMOKE') then
6336 for i
:= 1 to Times
do
6338 Anim
:= TAnimation
.Create(id
, False, 3);
6340 g_GFX_OnceAnim(Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(Anim
.Width
div 2),
6341 Obj
.Y
+Obj
.Rect
.Height
-4+Random(8+Times
*2), Anim
, ONCEANIM_SMOKE
);
6347 procedure TPlayer
.OnFireFlame(Times
: DWORD
= 1);
6352 if (Random(10) = 1) and (Times
= 1) then
6355 if g_Frames_Get(id
, 'FRAMES_FLAME') then
6357 for i
:= 1 to Times
do
6359 Anim
:= TAnimation
.Create(id
, False, 3);
6361 g_GFX_OnceAnim(Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(Anim
.Width
div 2),
6362 Obj
.Y
+8+Random(8+Times
*2), Anim
, ONCEANIM_SMOKE
);
6368 procedure TPlayer
.PauseSounds(Enable
: Boolean);
6370 FSawSound
.Pause(Enable
);
6371 FSawSoundIdle
.Pause(Enable
);
6372 FSawSoundHit
.Pause(Enable
);
6373 FSawSoundSelect
.Pause(Enable
);
6374 FFlameSoundOn
.Pause(Enable
);
6375 FFlameSoundOff
.Pause(Enable
);
6376 FFlameSoundWork
.Pause(Enable
);
6377 FJetSoundFly
.Pause(Enable
);
6378 FJetSoundOn
.Pause(Enable
);
6379 FJetSoundOff
.Pause(Enable
);
6384 constructor TCorpse
.Create(X
, Y
: Integer; ModelName
: String; aMess
: Boolean);
6389 FObj
.Rect
:= PLAYER_CORPSERECT
;
6390 FModelName
:= ModelName
;
6395 FState
:= CORPSE_STATE_MESS
;
6396 g_PlayerModel_GetAnim(ModelName
, A_DIE2
, FAnimation
, FAnimationMask
);
6400 FState
:= CORPSE_STATE_NORMAL
;
6401 g_PlayerModel_GetAnim(ModelName
, A_DIE1
, FAnimation
, FAnimationMask
);
6405 destructor TCorpse
.Destroy();
6412 function TCorpse
.ObjPtr (): PObj
; inline; begin result
:= @FObj
; end;
6414 procedure TCorpse
.positionChanged (); inline; begin end;
6416 procedure TCorpse
.moveBy (dx
, dy
: Integer); inline;
6418 if (dx
<> 0) or (dy
<> 0) then
6427 procedure TCorpse
.getMapBox (out x
, y
, w
, h
: Integer); inline;
6429 x
:= FObj
.X
+PLAYER_CORPSERECT
.X
;
6430 y
:= FObj
.Y
+PLAYER_CORPSERECT
.Y
;
6431 w
:= PLAYER_CORPSERECT
.Width
;
6432 h
:= PLAYER_CORPSERECT
.Height
;
6436 procedure TCorpse
.Damage(Value
: Word; vx
, vy
: Integer);
6441 if FState
= CORPSE_STATE_REMOVEME
then
6444 FDamage
:= FDamage
+ Value
;
6446 if FDamage
> 150 then
6448 if FAnimation
<> nil then
6453 FState
:= CORPSE_STATE_REMOVEME
;
6455 g_Player_CreateGibs(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
6456 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2),
6457 FModelName
, FColor
);
6458 // Çâóê ìÿñà îò òðóïà:
6459 pm
:= g_PlayerModel_Get(FModelName
);
6460 pm
.PlaySound(MODELSOUND_DIE
, 5, FObj
.X
, FObj
.Y
);
6464 if (gBodyKillEvent
<> -1)
6465 and gDelayedEvents
[gBodyKillEvent
].Pending
then
6466 gDelayedEvents
[gBodyKillEvent
].Pending
:= False;
6467 gBodyKillEvent
:= g_Game_DelayEvent(DE_BODYKILL
, 1050, 0);
6472 Blood
:= g_PlayerModel_GetBlood(FModelName
);
6473 FObj
.Vel
.X
:= FObj
.Vel
.X
+ vx
;
6474 FObj
.Vel
.Y
:= FObj
.Vel
.Y
+ vy
;
6475 g_GFX_Blood(FObj
.X
+PLAYER_CORPSERECT
.X
+(PLAYER_CORPSERECT
.Width
div 2),
6476 FObj
.Y
+PLAYER_CORPSERECT
.Y
+(PLAYER_CORPSERECT
.Height
div 2),
6477 Value
, vx
, vy
, 16, (PLAYER_CORPSERECT
.Height
*2) div 3,
6478 Blood
.R
, Blood
.G
, Blood
.B
, Blood
.Kind
);
6482 procedure TCorpse
.Draw();
6484 if FState
= CORPSE_STATE_REMOVEME
then
6487 if FAnimation
<> nil then
6488 FAnimation
.Draw(FObj
.X
, FObj
.Y
, TMirrorType
.None
);
6490 if FAnimationMask
<> nil then
6493 FAnimationMask
.Draw(FObj
.X
, FObj
.Y
, TMirrorType
.None
);
6500 procedure TCorpse
.Update();
6504 if FState
= CORPSE_STATE_REMOVEME
then
6507 if gTime
mod (GAME_TICK
*2) <> 0 then
6509 g_Obj_Move(@FObj
, True, True, True);
6510 positionChanged(); // this updates spatial accelerators
6514 // Ñîïðîòèâëåíèå âîçäóõà äëÿ òðóïà:
6515 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
6517 st
:= g_Obj_Move(@FObj
, True, True, True);
6518 positionChanged(); // this updates spatial accelerators
6520 if WordBool(st
and MOVE_FALLOUT
) then
6522 FState
:= CORPSE_STATE_REMOVEME
;
6526 if FAnimation
<> nil then
6527 FAnimation
.Update();
6528 if FAnimationMask
<> nil then
6529 FAnimationMask
.Update();
6533 procedure TCorpse
.SaveState (st
: TStream
);
6540 utils
.writeSign(st
, 'CORP');
6541 utils
.writeInt(st
, Byte(0));
6543 utils
.writeInt(st
, Byte(FState
));
6545 utils
.writeInt(st
, Byte(FDamage
));
6547 utils
.writeInt(st
, Byte(FColor
.R
));
6548 utils
.writeInt(st
, Byte(FColor
.G
));
6549 utils
.writeInt(st
, Byte(FColor
.B
));
6551 Obj_SaveState(st
, @FObj
);
6552 utils
.writeInt(st
, Word(FPlayerUID
));
6554 anim
:= (FAnimation
<> nil);
6555 utils
.writeBool(st
, anim
);
6556 // Åñëè åñòü - ñîõðàíÿåì
6557 if anim
then FAnimation
.SaveState(st
);
6558 // Åñòü ëè ìàñêà àíèìàöèè
6559 anim
:= (FAnimationMask
<> nil);
6560 utils
.writeBool(st
, anim
);
6561 // Åñëè åñòü - ñîõðàíÿåì
6562 if anim
then FAnimationMask
.SaveState(st
);
6566 procedure TCorpse
.LoadState (st
: TStream
);
6573 if not utils
.checkSign(st
, 'CORP') then raise XStreamError
.Create('invalid corpse signature');
6574 if (utils
.readByte(st
) <> 0) then raise XStreamError
.Create('invalid corpse version');
6576 FState
:= utils
.readByte(st
);
6578 FDamage
:= utils
.readByte(st
);
6580 FColor
.R
:= utils
.readByte(st
);
6581 FColor
.G
:= utils
.readByte(st
);
6582 FColor
.B
:= utils
.readByte(st
);
6584 Obj_LoadState(@FObj
, st
);
6585 FPlayerUID
:= utils
.readWord(st
);
6587 anim
:= utils
.readBool(st
);
6588 // Åñëè åñòü - çàãðóæàåì
6591 Assert(FAnimation
<> nil, 'TCorpse.LoadState: no FAnimation');
6592 FAnimation
.LoadState(st
);
6594 // Åñòü ëè ìàñêà àíèìàöèè
6595 anim
:= utils
.readBool(st
);
6596 // Åñëè åñòü - çàãðóæàåì
6599 Assert(FAnimationMask
<> nil, 'TCorpse.LoadState: no FAnimationMask');
6600 FAnimationMask
.LoadState(st
);
6606 constructor TBot
.Create();
6613 FSpectator
:= False;
6620 for a
:= WP_FIRST
to WP_LAST
do
6622 FDifficult
.WeaponPrior
[a
] := WEAPON_PRIOR1
[a
];
6623 FDifficult
.CloseWeaponPrior
[a
] := WEAPON_PRIOR2
[a
];
6624 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
6628 destructor TBot
.Destroy();
6631 inherited Destroy();
6634 procedure TBot
.Draw();
6638 //if FTargetUID <> 0 then e_DrawLine(1, FObj.X, FObj.Y, g_Player_Get(FTargetUID).FObj.X,
6639 // g_Player_Get(FTargetUID).FObj.Y, 255, 0, 0);
6642 procedure TBot
.Respawn(Silent
: Boolean; Force
: Boolean = False);
6644 inherited Respawn(Silent
, Force
);
6647 FSelectedWeapon
:= FCurrWeap
;
6652 procedure TBot
.UpdateCombat();
6665 TTargetRecord
= array of TTarget
;
6667 function Compare(a
, b
: TTarget
): Integer;
6669 if a
.Line
and not b
.Line
then // A íà ëèíèè îãíÿ
6672 if not a
.Line
and b
.Line
then // B íà ëèíèè îãíÿ
6674 else // È A, è B íà ëèíèè èëè íå íà ëèíèè îãíÿ
6675 if (a
.Line
and b
.Line
) or ((not a
.Line
) and (not b
.Line
)) then
6677 if a
.Dist
> b
.Dist
then // B áëèæå
6679 else // A áëèæå èëè ðàâíîóäàëåííî ñ B
6682 else // Ñòðàííî -> A
6687 a
, x1
, y1
, x2
, y2
: Integer;
6688 targets
: TTargetRecord
;
6690 Target
, BestTarget
: TTarget
;
6691 firew
, fireh
: Integer;
6695 vsPlayer
, vsMonster
, ok
: Boolean;
6698 function monsUpdate (mon
: TMonster
): Boolean;
6700 result
:= false; // don't stop
6701 if mon
.alive
and (mon
.MonsterType
<> MONSTER_BARREL
) then
6703 if not TargetOnScreen(mon
.Obj
.X
+mon
.Obj
.Rect
.X
, mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
) then exit
;
6705 x2
:= mon
.Obj
.X
+mon
.Obj
.Rect
.X
+(mon
.Obj
.Rect
.Width
div 2);
6706 y2
:= mon
.Obj
.Y
+mon
.Obj
.Rect
.Y
+(mon
.Obj
.Rect
.Height
div 2);
6708 // Åñëè ìîíñòð íà ýêðàíå è íå ïðèêðûò ñòåíîé
6709 if g_TraceVector(x1
, y1
, x2
, y2
) then
6711 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé
6712 SetLength(targets
, Length(targets
)+1);
6713 with targets
[High(targets
)] do
6720 Rect
:= mon
.Obj
.Rect
;
6721 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6722 Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6723 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6732 vsPlayer
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
);
6733 vsMonster
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
);
6735 // Åñëè òåêóùåå îðóæèå íå òî, ÷òî íóæíî, òî ìåíÿåì:
6736 if FCurrWeap
<> FSelectedWeapon
then
6739 // Åñëè íóæíî ñòðåëÿòü è íóæíîå îðóæèå, òî íàæàòü "Ñòðåëÿòü":
6740 if (GetAIFlag('NEEDFIRE') <> '') and (FCurrWeap
= FSelectedWeapon
) then
6742 RemoveAIFlag('NEEDFIRE');
6745 WEAPON_PLASMA
, WEAPON_SUPERPULEMET
, WEAPON_CHAINGUN
: PressKey(KEY_FIRE
, 20);
6746 WEAPON_SAW
, WEAPON_KASTET
, WEAPON_FLAMETHROWER
: PressKey(KEY_FIRE
, 40);
6747 else PressKey(KEY_FIRE
);
6751 // Êîîðäèíàòû ñòâîëà:
6752 x1
:= FObj
.X
+ WEAPONPOINT
[FDirection
].X
;
6753 y1
:= FObj
.Y
+ WEAPONPOINT
[FDirection
].Y
;
6755 Target
.UID
:= FTargetUID
;
6758 if Target
.UID
<> 0 then
6759 begin // Öåëü åñòü - íàñòðàèâàåì
6760 if (g_GetUIDType(Target
.UID
) = UID_PLAYER
) and
6763 tpla
:= g_Player_Get(Target
.UID
);
6767 if (@FObj
) <> nil then
6774 Target
.cX
:= Target
.X
+ PLAYER_RECT_CX
;
6775 Target
.cY
:= Target
.Y
+ PLAYER_RECT_CY
;
6776 Target
.Rect
:= PLAYER_RECT
;
6777 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6778 Target
.Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6779 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6780 Target
.IsPlayer
:= True;
6784 if (g_GetUIDType(Target
.UID
) = UID_MONSTER
) and
6787 mon
:= g_Monsters_ByUID(Target
.UID
);
6790 Target
.X
:= mon
.Obj
.X
;
6791 Target
.Y
:= mon
.Obj
.Y
;
6793 Target
.cX
:= Target
.X
+ mon
.Obj
.Rect
.X
+ (mon
.Obj
.Rect
.Width
div 2);
6794 Target
.cY
:= Target
.Y
+ mon
.Obj
.Rect
.Y
+ (mon
.Obj
.Rect
.Height
div 2);
6795 Target
.Rect
:= mon
.Obj
.Rect
;
6796 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6797 Target
.Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6798 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6799 Target
.IsPlayer
:= False;
6806 begin // Öåëè íåò - îáíóëÿåì
6811 Target
.Visible
:= False;
6812 Target
.Line
:= False;
6813 Target
.IsPlayer
:= False;
6818 // Åñëè öåëü íå âèäèìà èëè íå íà ëèíèè îãíÿ, òî èùåì âñå âîçìîæíûå öåëè:
6819 if (not Target
.Line
) or (not Target
.Visible
) then
6823 for a
:= 0 to High(gPlayers
) do
6824 if (gPlayers
[a
] <> nil) and (gPlayers
[a
].alive
) and
6825 (gPlayers
[a
].FUID
<> FUID
) and
6826 (not SameTeam(FUID
, gPlayers
[a
].FUID
)) and
6827 (not gPlayers
[a
].NoTarget
) and
6828 (gPlayers
[a
].FMegaRulez
[MR_INVIS
] < gTime
) then
6830 if not TargetOnScreen(gPlayers
[a
].FObj
.X
+ PLAYER_RECT
.X
,
6831 gPlayers
[a
].FObj
.Y
+ PLAYER_RECT
.Y
) then
6834 x2
:= gPlayers
[a
].FObj
.X
+ PLAYER_RECT_CX
;
6835 y2
:= gPlayers
[a
].FObj
.Y
+ PLAYER_RECT_CY
;
6837 // Åñëè èãðîê íà ýêðàíå è íå ïðèêðûò ñòåíîé:
6838 if g_TraceVector(x1
, y1
, x2
, y2
) then
6840 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé:
6841 SetLength(targets
, Length(targets
)+1);
6842 with targets
[High(targets
)] do
6844 UID
:= gPlayers
[a
].FUID
;
6845 X
:= gPlayers
[a
].FObj
.X
;
6846 Y
:= gPlayers
[a
].FObj
.Y
;
6849 Rect
:= PLAYER_RECT
;
6850 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6851 Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6852 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6860 if vsMonster
then g_Mons_ForEach(monsUpdate
);
6863 // Åñëè åñòü âîçìîæíûå öåëè:
6864 // (Âûáèðàåì ëó÷øóþ, ìåíÿåì îðóæèå è áåæèì ê íåé/îò íåå)
6865 if targets
<> nil then
6867 // Âûáèðàåì íàèëó÷øóþ öåëü:
6868 BestTarget
:= targets
[0];
6869 if Length(targets
) > 1 then
6870 for a
:= 1 to High(targets
) do
6871 if Compare(BestTarget
, targets
[a
]) = 1 then
6872 BestTarget
:= targets
[a
];
6874 // Åñëè ëó÷øàÿ öåëü "âèäíåå" òåêóùåé, òî òåêóùàÿ := ëó÷øàÿ:
6875 if ((not Target
.Visible
) and BestTarget
.Visible
and (Target
.UID
<> BestTarget
.UID
)) or
6876 ((not Target
.Line
) and BestTarget
.Line
and BestTarget
.Visible
) then
6878 Target
:= BestTarget
;
6880 if (Healthy() = 3) or ((Healthy() = 2)) then
6881 begin // Åñëè çäîðîâû - äîãîíÿåì
6882 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
6883 SetAIFlag('GORIGHT', '1');
6884 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6885 SetAIFlag('GOLEFT', '1');
6888 begin // Åñëè ïîáèòû - óáåãàåì
6889 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) then
6890 SetAIFlag('GORIGHT', '1');
6891 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6892 SetAIFlag('GOLEFT', '1');
6895 // Âûáèðàåì îðóæèå íà îñíîâå ðàññòîÿíèÿ è ïðèîðèòåòîâ:
6896 SelectWeapon(Abs(x1
-Target
.cX
));
6901 // (Äîãîíÿåì/óáåãàåì, ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëè)
6902 // (Åñëè öåëü äàëåêî, òî õâàòèò ñëåäèòü çà íåé)
6903 if Target
.UID
<> 0 then
6905 if not TargetOnScreen(Target
.X
+ Target
.Rect
.X
,
6906 Target
.Y
+ Target
.Rect
.Y
) then
6907 begin // Öåëü ñáåæàëà ñ "ýêðàíà"
6908 if (Healthy() = 3) or ((Healthy() = 2)) then
6909 begin // Åñëè çäîðîâû - äîãîíÿåì
6910 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
6911 SetAIFlag('GORIGHT', '1');
6912 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6913 SetAIFlag('GOLEFT', '1');
6916 begin // Åñëè ïîáèòû - çàáûâàåì î öåëè è óáåãàåì
6918 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) then
6919 SetAIFlag('GORIGHT', '1');
6920 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6921 SetAIFlag('GOLEFT', '1');
6925 begin // Öåëü ïîêà íà "ýêðàíå"
6926 // Åñëè öåëü íå çàãîðîæåíà ñòåíîé, òî îòìå÷àåì, êîãäà åå âèäåëè:
6927 if g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6928 FLastVisible
:= gTime
;
6929 // Åñëè ðàçíèöà âûñîò íå âåëèêà, òî äîãîíÿåì:
6930 if (Abs(FObj
.Y
-Target
.Y
) <= 128) then
6932 if ((RunDirection() = TDirection
.D_LEFT
) and (Target
.X
> FObj
.X
)) then
6933 SetAIFlag('GORIGHT', '1');
6934 if ((RunDirection() = TDirection
.D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6935 SetAIFlag('GOLEFT', '1');
6939 // Âûáèðàåì óãîë ââåðõ:
6940 if FDirection
= TDirection
.D_LEFT
then
6941 angle
:= ANGLE_LEFTUP
6943 angle
:= ANGLE_RIGHTUP
;
6945 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6946 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6948 // Åñëè ïðè óãëå ââåðõ ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
6949 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6950 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128), //96
6951 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6952 Target
.Rect
.Width
, Target
.Rect
.Height
) and
6953 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6954 begin // òî íóæíî ñòðåëÿòü ââåðõ
6955 SetAIFlag('NEEDFIRE', '1');
6956 SetAIFlag('NEEDSEEUP', '1');
6959 // Âûáèðàåì óãîë âíèç:
6960 if FDirection
= TDirection
.D_LEFT
then
6961 angle
:= ANGLE_LEFTDOWN
6963 angle
:= ANGLE_RIGHTDOWN
;
6965 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6966 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6968 // Åñëè ïðè óãëå âíèç ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
6969 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6970 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
6971 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6972 Target
.Rect
.Width
, Target
.Rect
.Height
) and
6973 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6974 begin // òî íóæíî ñòðåëÿòü âíèç
6975 SetAIFlag('NEEDFIRE', '1');
6976 SetAIFlag('NEEDSEEDOWN', '1');
6979 // Åñëè öåëü âèäíî è îíà íà òàêîé æå âûñîòå:
6980 if Target
.Visible
and
6981 (y1
+4 < Target
.Y
+Target
.Rect
.Y
+Target
.Rect
.Height
) and
6982 (y1
-4 > Target
.Y
+Target
.Rect
.Y
) then
6984 // Åñëè èäåì â ñòîðîíó öåëè, òî íàäî ñòðåëÿòü:
6985 if ((FDirection
= TDirection
.D_LEFT
) and (Target
.X
< FObj
.X
)) or
6986 ((FDirection
= TDirection
.D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6987 begin // òî íóæíî ñòðåëÿòü âïåðåä
6988 SetAIFlag('NEEDFIRE', '1');
6989 SetAIFlag('NEEDSEEDOWN', '');
6990 SetAIFlag('NEEDSEEUP', '');
6992 // Åñëè öåëü â ïðåäåëàõ "ýêðàíà" è ñëîæíîñòü ïîçâîëÿåò ïðûæêè ñáëèæåíèÿ:
6993 if Abs(FObj
.X
-Target
.X
) < Trunc(gPlayerScreenSize
.X
*0.75) then
6994 if GetRnd(FDifficult
.CloseJump
) then
6995 begin // òî åñëè ïîâåçåò - ïðûãàåì (îñîáåííî, åñëè áëèçêî)
6996 if Abs(FObj
.X
-Target
.X
) < 128 then
7000 if Random(a
) = 0 then
7001 SetAIFlag('NEEDJUMP', '1');
7005 // Åñëè öåëü âñå åùå åñòü:
7006 if Target
.UID
<> 0 then
7007 if gTime
-FLastVisible
> 2000 then // Åñëè âèäåëè äàâíî
7008 Target
.UID
:= 0 // òî çàáûòü öåëü
7009 else // Åñëè âèäåëè íåäàâíî
7010 begin // íî öåëü óáèëè
7011 if Target
.IsPlayer
then
7012 begin // Öåëü - èãðîê
7013 pla
:= g_Player_Get(Target
.UID
);
7014 if (pla
= nil) or (not pla
.alive
) or pla
.NoTarget
or
7015 (pla
.FMegaRulez
[MR_INVIS
] >= gTime
) then
7016 Target
.UID
:= 0; // òî çàáûòü öåëü
7019 begin // Öåëü - ìîíñòð
7020 mon
:= g_Monsters_ByUID(Target
.UID
);
7021 if (mon
= nil) or (not mon
.alive
) then
7022 Target
.UID
:= 0; // òî çàáûòü öåëü
7025 end; // if Target.UID <> 0
7027 FTargetUID
:= Target
.UID
;
7029 // Åñëè âîçìîæíûõ öåëåé íåò:
7030 // (Àòàêà ÷åãî-íèáóäü ñëåâà èëè ñïðàâà)
7031 if targets
= nil then
7032 if GetAIFlag('ATTACKLEFT') <> '' then
7033 begin // Åñëè íóæíî àòàêîâàòü íàëåâî
7034 RemoveAIFlag('ATTACKLEFT');
7036 SetAIFlag('NEEDJUMP', '1');
7038 if RunDirection() = TDirection
.D_RIGHT
then
7039 begin // Èäåì íå â òó ñòîðîíó
7040 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
7041 begin // Åñëè çäîðîâû, òî, âîçìîæíî, ñòðåëÿåì áåæèì âëåâî è ñòðåëÿåì
7042 SetAIFlag('NEEDFIRE', '1');
7043 SetAIFlag('GOLEFT', '1');
7047 begin // Èäåì â íóæíóþ ñòîðîíó
7048 if GetRnd(FDifficult
.InvisFire
) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
7049 SetAIFlag('NEEDFIRE', '1');
7050 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
7051 SetAIFlag('GORIGHT', '1');
7055 if GetAIFlag('ATTACKRIGHT') <> '' then
7056 begin // Åñëè íóæíî àòàêîâàòü íàïðàâî
7057 RemoveAIFlag('ATTACKRIGHT');
7059 SetAIFlag('NEEDJUMP', '1');
7061 if RunDirection() = TDirection
.D_LEFT
then
7062 begin // Èäåì íå â òó ñòîðîíó
7063 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
7064 begin // Åñëè çäîðîâû, òî, âîçìîæíî, áåæèì âïðàâî è ñòðåëÿåì
7065 SetAIFlag('NEEDFIRE', '1');
7066 SetAIFlag('GORIGHT', '1');
7071 if GetRnd(FDifficult
.InvisFire
) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
7072 SetAIFlag('NEEDFIRE', '1');
7073 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
7074 SetAIFlag('GOLEFT', '1');
7078 //HACK! (does it belongs there?)
7079 RealizeCurrentWeapon();
7081 // Åñëè åñòü âîçìîæíûå öåëè:
7082 // (Ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëÿì)
7083 if (targets
<> nil) and (GetAIFlag('NEEDFIRE') <> '') then
7084 for a
:= 0 to High(targets
) do
7086 // Åñëè ìîæåì ñòðåëÿòü ïî äèàãîíàëè:
7087 if GetRnd(FDifficult
.DiagFire
) then
7089 // Èùåì öåëü ñâåðõó è ñòðåëÿåì, åñëè åñòü:
7090 if FDirection
= TDirection
.D_LEFT
then
7091 angle
:= ANGLE_LEFTUP
7093 angle
:= ANGLE_RIGHTUP
;
7095 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7096 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7098 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
7099 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
7100 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
7101 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
7102 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
7104 SetAIFlag('NEEDFIRE', '1');
7105 SetAIFlag('NEEDSEEUP', '1');
7108 // Èùåì öåëü ñíèçó è ñòðåëÿåì, åñëè åñòü:
7109 if FDirection
= TDirection
.D_LEFT
then
7110 angle
:= ANGLE_LEFTDOWN
7112 angle
:= ANGLE_RIGHTDOWN
;
7114 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7115 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
7117 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
7118 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
7119 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
7120 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
7121 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
7123 SetAIFlag('NEEDFIRE', '1');
7124 SetAIFlag('NEEDSEEDOWN', '1');
7128 // Åñëè öåëü "ïåðåä íîñîì", òî ñòðåëÿåì:
7129 if targets
[a
].Line
and targets
[a
].Visible
and
7130 (((FDirection
= TDirection
.D_LEFT
) and (targets
[a
].X
< FObj
.X
)) or
7131 ((FDirection
= TDirection
.D_RIGHT
) and (targets
[a
].X
> FObj
.X
))) then
7133 SetAIFlag('NEEDFIRE', '1');
7138 // Åñëè ëåòèò ïóëÿ, òî, âîçìîæíî, ïîäïðûãèâàåì:
7139 if g_Weapon_Danger(FUID
, FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
,
7140 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
,
7141 40+GetInterval(FDifficult
.Cover
, 40)) then
7142 SetAIFlag('NEEDJUMP', '1');
7144 // Åñëè êîí÷èëèñü ïàòîðíû, òî íóæíî ñìåíèòü îðóæèå:
7145 ammo
:= GetAmmoByWeapon(FCurrWeap
);
7146 if ((FCurrWeap
= WEAPON_SHOTGUN2
) and (ammo
< 2)) or
7147 ((FCurrWeap
= WEAPON_BFG
) and (ammo
< 40)) or
7149 SetAIFlag('SELECTWEAPON', '1');
7151 // Åñëè íóæíî ñìåíèòü îðóæèå, òî âûáèðàåì íóæíîå:
7152 if GetAIFlag('SELECTWEAPON') = '1' then
7155 RemoveAIFlag('SELECTWEAPON');
7159 procedure TBot
.Update();
7172 // Ïðîâåðÿåì, îòêëþ÷¸í ëè AI áîòîâ
7173 if (g_debug_BotAIOff
= 1) and (Team
= TEAM_RED
) then
7175 if (g_debug_BotAIOff
= 2) and (Team
= TEAM_BLUE
) then
7177 if g_debug_BotAIOff
= 3 then
7187 RealizeCurrentWeapon();
7194 procedure TBot
.ReleaseKey(Key
: Byte);
7203 function TBot
.KeyPressed(Key
: Word): Boolean;
7205 Result
:= FKeys
[Key
].Pressed
;
7208 function TBot
.GetAIFlag(aName
: String20
): String20
;
7214 aName
:= LowerCase(aName
);
7216 if FAIFlags
<> nil then
7217 for a
:= 0 to High(FAIFlags
) do
7218 if LowerCase(FAIFlags
[a
].Name
) = aName
then
7220 Result
:= FAIFlags
[a
].Value
;
7225 procedure TBot
.RemoveAIFlag(aName
: String20
);
7229 if FAIFlags
= nil then Exit
;
7231 aName
:= LowerCase(aName
);
7233 for a
:= 0 to High(FAIFlags
) do
7234 if LowerCase(FAIFlags
[a
].Name
) = aName
then
7236 if a
<> High(FAIFlags
) then
7237 for b
:= a
to High(FAIFlags
)-1 do
7238 FAIFlags
[b
] := FAIFlags
[b
+1];
7240 SetLength(FAIFlags
, Length(FAIFlags
)-1);
7245 procedure TBot
.SetAIFlag(aName
, fValue
: String20
);
7253 aName
:= LowerCase(aName
);
7255 if FAIFlags
<> nil then
7256 for a
:= 0 to High(FAIFlags
) do
7257 if LowerCase(FAIFlags
[a
].Name
) = aName
then
7263 if ok
then FAIFlags
[a
].Value
:= fValue
7266 SetLength(FAIFlags
, Length(FAIFlags
)+1);
7267 with FAIFlags
[High(FAIFlags
)] do
7275 procedure TBot
.UpdateMove
;
7277 procedure GoLeft(Time
: Word = 1);
7279 ReleaseKey(KEY_LEFT
);
7280 ReleaseKey(KEY_RIGHT
);
7281 PressKey(KEY_LEFT
, Time
);
7282 SetDirection(TDirection
.D_LEFT
);
7285 procedure GoRight(Time
: Word = 1);
7287 ReleaseKey(KEY_LEFT
);
7288 ReleaseKey(KEY_RIGHT
);
7289 PressKey(KEY_RIGHT
, Time
);
7290 SetDirection(TDirection
.D_RIGHT
);
7293 function Rnd(a
: Word): Boolean;
7295 Result
:= Random(a
) = 0;
7298 procedure Turn(Time
: Word = 1200);
7300 if RunDirection() = TDirection
.D_LEFT
then GoRight(Time
) else GoLeft(Time
);
7305 ReleaseKey(KEY_LEFT
);
7306 ReleaseKey(KEY_RIGHT
);
7309 function CanRunLeft(): Boolean;
7311 Result
:= not CollideLevel(-1, 0);
7314 function CanRunRight(): Boolean;
7316 Result
:= not CollideLevel(1, 0);
7319 function CanRun(): Boolean;
7321 if RunDirection() = TDirection
.D_LEFT
then Result
:= CanRunLeft() else Result
:= CanRunRight();
7324 procedure Jump(Time
: Word = 30);
7326 PressKey(KEY_JUMP
, Time
);
7329 function NearHole(): Boolean;
7333 { TODO 5 : Ëåñòíèöû }
7334 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7335 for x
:= 1 to PLAYER_RECT
.Width
do
7336 if (not StayOnStep(x
*sx
, 0)) and
7337 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7338 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7347 function BorderHole(): Boolean;
7351 { TODO 5 : Ëåñòíèöû }
7352 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7353 for x
:= 1 to PLAYER_RECT
.Width
do
7354 if (not StayOnStep(x
*sx
, 0)) and
7355 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7356 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7358 for xx
:= x
to x
+32 do
7359 if CollideLevel(xx
*sx
, PLAYER_RECT
.Height
) then
7369 function NearDeepHole(): Boolean;
7375 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7378 for x
:= 1 to PLAYER_RECT
.Width
do
7379 if (not StayOnStep(x
*sx
, 0)) and
7380 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
7381 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
7383 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
7385 if CollideLevel(x
*sx
, PLAYER_RECT
.Height
*y
) then Exit
;
7390 end else Result
:= False;
7393 function OverDeepHole(): Boolean;
7400 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
7402 if CollideLevel(0, PLAYER_RECT
.Height
*y
) then Exit
;
7409 function OnGround(): Boolean;
7411 Result
:= StayOnStep(0, 0) or CollideLevel(0, 1);
7414 function OnLadder(): Boolean;
7416 Result
:= FullInStep(0, 0);
7419 function BelowLadder(): Boolean;
7421 Result
:= (FullInStep(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) and
7422 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
7423 (FullInStep(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) and
7424 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
7427 function BelowLiftUp(): Boolean;
7429 Result
:= ((FullInLift(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) = -1) and
7430 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
7431 ((FullInLift(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) = -1) and
7432 not CollideLevel(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
7435 function OnTopLift(): Boolean;
7437 Result
:= (FullInLift(0, 0) = -1) and (FullInLift(0, -32) = 0);
7440 function CanJumpOver(): Boolean;
7444 sx
:= IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1);
7448 if not CollideLevel(sx
, 0) then Exit
;
7450 for y
:= 1 to BOT_MAXJUMP
do
7451 if CollideLevel(0, -y
) then Exit
else
7452 if not CollideLevel(sx
, -y
) then
7459 function CanJumpUp(Dist
: ShortInt): Boolean;
7466 if CollideLevel(Dist
, 0) then Exit
;
7469 for y
:= 0 to BOT_MAXJUMP
do
7470 if CollideLevel(Dist
, -y
) then
7479 for yy
:= y
+1 to BOT_MAXJUMP
do
7480 if not CollideLevel(Dist
, -yy
) then
7489 for y
:= 0 to BOT_MAXJUMP
do
7490 if CollideLevel(0, -y
) then
7498 if y
< yy
then Exit
;
7503 function IsSafeTrigger(): Boolean;
7508 if gTriggers
= nil then
7510 for a
:= 0 to High(gTriggers
) do
7511 if Collide(gTriggers
[a
].X
,
7514 gTriggers
[a
].Height
) and
7515 (gTriggers
[a
].TriggerType
in [TRIGGER_EXIT
, TRIGGER_CLOSEDOOR
,
7516 TRIGGER_CLOSETRAP
, TRIGGER_TRAP
,
7517 TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
,
7518 TRIGGER_ONOFF
, TRIGGER_SPAWNMONSTER
,
7519 TRIGGER_DAMAGE
, TRIGGER_SHOT
]) then
7524 // Âîçìîæíî, íàæèìàåì êíîïêó:
7525 if Rnd(16) and IsSafeTrigger() then
7528 // Åñëè ïîä ëèôòîì èëè ñòóïåíüêàìè, òî, âîçìîæíî, ïðûãàåì:
7529 if OnLadder() or ((BelowLadder() or BelowLiftUp()) and Rnd(8)) then
7531 ReleaseKey(KEY_LEFT
);
7532 ReleaseKey(KEY_RIGHT
);
7536 // Èäåì âëåâî, åñëè íàäî áûëî:
7537 if GetAIFlag('GOLEFT') <> '' then
7539 RemoveAIFlag('GOLEFT');
7540 if CanRunLeft() then
7544 // Èäåì âïðàâî, åñëè íàäî áûëî:
7545 if GetAIFlag('GORIGHT') <> '' then
7547 RemoveAIFlag('GORIGHT');
7548 if CanRunRight() then
7552 // Åñëè âûëåòåëè çà êàðòó, òî ïðîáóåì âåðíóòüñÿ:
7553 if FObj
.X
< -32 then
7556 if FObj
.X
+32 > gMapInfo
.Width
then
7559 // Ïðûãàåì, åñëè íàäî áûëî:
7560 if GetAIFlag('NEEDJUMP') <> '' then
7563 RemoveAIFlag('NEEDJUMP');
7566 // Ñìîòðèì ââåðõ, åñëè íàäî áûëî:
7567 if GetAIFlag('NEEDSEEUP') <> '' then
7570 ReleaseKey(KEY_DOWN
);
7571 PressKey(KEY_UP
, 20);
7572 RemoveAIFlag('NEEDSEEUP');
7575 // Ñìîòðèì âíèç, åñëè íàäî áûëî:
7576 if GetAIFlag('NEEDSEEDOWN') <> '' then
7579 ReleaseKey(KEY_DOWN
);
7580 PressKey(KEY_DOWN
, 20);
7581 RemoveAIFlag('NEEDSEEDOWN');
7584 // Åñëè íóæíî áûëî â äûðó è ìû íå íà çåìëå, òî ïîêîðíî ëåòèì:
7585 if GetAIFlag('GOINHOLE') <> '' then
7586 if not OnGround() then
7588 ReleaseKey(KEY_LEFT
);
7589 ReleaseKey(KEY_RIGHT
);
7590 RemoveAIFlag('GOINHOLE');
7591 SetAIFlag('FALLINHOLE', '1');
7594 // Åñëè ïàäàëè è äîñòèãëè çåìëè, òî õâàòèò ïàäàòü:
7595 if GetAIFlag('FALLINHOLE') <> '' then
7597 RemoveAIFlag('FALLINHOLE');
7599 // Åñëè ëåòåëè ïðÿìî è ñåé÷àñ íå íà ëåñòíèöå èëè íà âåðøèíå ëèôòà, òî îòõîäèì â ñòîðîíó:
7600 if not (KeyPressed(KEY_LEFT
) or KeyPressed(KEY_RIGHT
)) then
7601 if GetAIFlag('FALLINHOLE') = '' then
7602 if (not OnLadder()) or (FObj
.Vel
.Y
>= 0) or (OnTopLift()) then
7608 // Åñëè íà çåìëå è ìîæíî ïîäïðûãíóòü, òî, âîçìîæíî, ïðûãàåì:
7610 CanJumpUp(IfThen(RunDirection() = TDirection
.D_LEFT
, -1, 1)*32) and
7614 // Åñëè íà çåìëå è âîçëå äûðû (ãëóáèíà > 2 ðîñòîâ èãðîêà):
7615 if OnGround() and NearHole() then
7616 if NearDeepHole() then // Åñëè ýòî áåçäíà
7618 0..3: Turn(); // Áåæèì îáðàòíî
7619 4: Jump(); // Ïðûãàåì
7620 5: begin // Ïðûãàåì îáðàòíî
7625 else // Ýòî íå áåçäíà è ìû åùå íå ëåòèì òóäà
7626 if GetAIFlag('GOINHOLE') = '' then
7628 0: Turn(); // Íå íóæíî òóäà
7629 1: Jump(); // Âäðóã ïîâåçåò - ïðûãàåì
7630 else // Åñëè ÿìà ñ ãðàíèöåé, òî ïðè ñëó÷àå ìîæíî òóäà ïðûãíóòü
7631 if BorderHole() then
7632 SetAIFlag('GOINHOLE', '1');
7635 // Åñëè íà çåìëå, íî íåêóäà èäòè:
7636 if (not CanRun()) and OnGround() then
7638 // Åñëè ìû íà ëåñòíèöå èëè ìîæíî ïåðåïðûãíóòü, òî ïðûãàåì:
7639 if CanJumpOver() or OnLadder() then
7641 else // èíà÷å ïîïûòàåìñÿ â äðóãóþ ñòîðîíó
7642 if Random(2) = 0 then
7644 if IsSafeTrigger() then
7650 // Îñòàëîñü ìàëî âîçäóõà:
7651 if FAir
< 36 * 2 then
7654 // Âûáèðàåìñÿ èç êèñëîòû, åñëè íåò êîñòþìà, îáîæãëèñü, èëè ìàëî çäîðîâüÿ:
7655 if (FMegaRulez
[MR_SUIT
] < gTime
) and ((FLastHit
= HIT_ACID
) or (Healthy() <= 1)) then
7656 if BodyInAcid(0, 0) then
7660 function TBot
.FullInStep(XInc
, YInc
: Integer): Boolean;
7662 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
7663 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_STEP
, False);
7666 {function TBot.NeedItem(Item: Byte): Byte;
7671 procedure TBot
.SelectWeapon(Dist
: Integer);
7675 function HaveAmmo(weapon
: Byte): Boolean;
7678 WEAPON_PISTOL
: Result
:= FAmmo
[A_BULLETS
] >= 1;
7679 WEAPON_SHOTGUN1
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7680 WEAPON_SHOTGUN2
: Result
:= FAmmo
[A_SHELLS
] >= 2;
7681 WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
] >= 10;
7682 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
] >= 1;
7683 WEAPON_PLASMA
: Result
:= FAmmo
[A_CELLS
] >= 10;
7684 WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
] >= 40;
7685 WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7686 WEAPON_FLAMETHROWER
: Result
:= FAmmo
[A_FUEL
] >= 1;
7687 else Result
:= True;
7692 if Dist
= -1 then Dist
:= BOT_LONGDIST
;
7694 if Dist
> BOT_LONGDIST
then
7695 begin // Äàëüíèé áîé
7697 if FWeapon
[FDifficult
.WeaponPrior
[a
]] and HaveAmmo(FDifficult
.WeaponPrior
[a
]) then
7699 FSelectedWeapon
:= FDifficult
.WeaponPrior
[a
];
7703 else //if Dist > BOT_UNSAFEDIST then
7704 begin // Áëèæíèé áîé
7706 if FWeapon
[FDifficult
.CloseWeaponPrior
[a
]] and HaveAmmo(FDifficult
.CloseWeaponPrior
[a
]) then
7708 FSelectedWeapon
:= FDifficult
.CloseWeaponPrior
[a
];
7715 if FWeapon[FDifficult.SafeWeaponPrior[a]] and HaveAmmo(FDifficult.SafeWeaponPrior[a]) then
7717 FSelectedWeapon := FDifficult.SafeWeaponPrior[a];
7723 function TBot
.PickItem(ItemType
: Byte; force
: Boolean; var remove
: Boolean): Boolean;
7725 Result
:= inherited PickItem(ItemType
, force
, remove
);
7727 if Result
then SetAIFlag('SELECTWEAPON', '1');
7730 function TBot
.Heal(value
: Word; Soft
: Boolean): Boolean;
7732 Result
:= inherited Heal(value
, Soft
);
7735 function TBot
.Healthy(): Byte;
7737 if FMegaRulez
[MR_INVUL
] >= gTime
then Result
:= 3
7738 else if (FHealth
> 80) or ((FHealth
> 50) and (FArmor
> 20)) then Result
:= 3
7739 else if (FHealth
> 50) then Result
:= 2
7740 else if (FHealth
> 20) then Result
:= 1
7744 function TBot
.TargetOnScreen(TX
, TY
: Integer): Boolean;
7746 Result
:= (Abs(FObj
.X
-TX
) <= Trunc(gPlayerScreenSize
.X
*0.6)) and
7747 (Abs(FObj
.Y
-TY
) <= Trunc(gPlayerScreenSize
.Y
*0.6));
7750 procedure TBot
.OnDamage(Angle
: SmallInt);
7758 if (Angle
= 0) or (Angle
= 180) then
7761 if (g_GetUIDType(FLastSpawnerUID
) = UID_PLAYER
) and
7762 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
) then
7764 pla
:= g_Player_Get(FLastSpawnerUID
);
7765 ok
:= not TargetOnScreen(pla
.FObj
.X
+ PLAYER_RECT
.X
,
7766 pla
.FObj
.Y
+ PLAYER_RECT
.Y
);
7769 if (g_GetUIDType(FLastSpawnerUID
) = UID_MONSTER
) and
7770 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
) then
7772 mon
:= g_Monsters_ByUID(FLastSpawnerUID
);
7773 ok
:= not TargetOnScreen(mon
.Obj
.X
+ mon
.Obj
.Rect
.X
,
7774 mon
.Obj
.Y
+ mon
.Obj
.Rect
.Y
);
7779 SetAIFlag('ATTACKLEFT', '1')
7781 SetAIFlag('ATTACKRIGHT', '1');
7785 function TBot
.RunDirection(): TDirection
;
7787 if Abs(Vel
.X
) >= 1 then
7789 if Vel
.X
> 0 then Result
:= TDirection
.D_RIGHT
else Result
:= TDirection
.D_LEFT
;
7791 Result
:= FDirection
;
7794 function TBot
.GetRnd(a
: Byte): Boolean;
7796 if a
= 0 then Result
:= False
7797 else if a
= 255 then Result
:= True
7798 else Result
:= Random(256) > 255-a
;
7801 function TBot
.GetInterval(a
: Byte; radius
: SmallInt): SmallInt;
7803 Result
:= Round((255-a
)/255*radius
*(Random(2)-1));
7807 procedure TDifficult
.save (st
: TStream
);
7809 utils
.writeInt(st
, Byte(DiagFire
));
7810 utils
.writeInt(st
, Byte(InvisFire
));
7811 utils
.writeInt(st
, Byte(DiagPrecision
));
7812 utils
.writeInt(st
, Byte(FlyPrecision
));
7813 utils
.writeInt(st
, Byte(Cover
));
7814 utils
.writeInt(st
, Byte(CloseJump
));
7815 st
.WriteBuffer(WeaponPrior
[Low(WeaponPrior
)], sizeof(WeaponPrior
));
7816 st
.WriteBuffer(CloseWeaponPrior
[Low(CloseWeaponPrior
)], sizeof(CloseWeaponPrior
));
7819 procedure TDifficult
.load (st
: TStream
);
7821 DiagFire
:= utils
.readByte(st
);
7822 InvisFire
:= utils
.readByte(st
);
7823 DiagPrecision
:= utils
.readByte(st
);
7824 FlyPrecision
:= utils
.readByte(st
);
7825 Cover
:= utils
.readByte(st
);
7826 CloseJump
:= utils
.readByte(st
);
7827 st
.ReadBuffer(WeaponPrior
[Low(WeaponPrior
)], sizeof(WeaponPrior
));
7828 st
.ReadBuffer(CloseWeaponPrior
[Low(CloseWeaponPrior
)], sizeof(CloseWeaponPrior
));
7832 procedure TBot
.SaveState (st
: TStream
);
7837 inherited SaveState(st
);
7838 utils
.writeSign(st
, 'BOT0');
7840 utils
.writeInt(st
, Byte(FSelectedWeapon
));
7842 utils
.writeInt(st
, Word(FTargetUID
));
7843 // Âðåìÿ ïîòåðè öåëè
7844 utils
.writeInt(st
, LongWord(FLastVisible
));
7845 // Êîëè÷åñòâî ôëàãîâ ÈÈ
7846 dw
:= Length(FAIFlags
);
7847 utils
.writeInt(st
, LongInt(dw
));
7849 for i
:= 0 to dw
-1 do
7851 utils
.writeStr(st
, FAIFlags
[i
].Name
, 20);
7852 utils
.writeStr(st
, FAIFlags
[i
].Value
, 20);
7854 // Íàñòðîéêè ñëîæíîñòè
7855 FDifficult
.save(st
);
7859 procedure TBot
.LoadState (st
: TStream
);
7864 inherited LoadState(st
);
7865 if not utils
.checkSign(st
, 'BOT0') then raise XStreamError
.Create('invalid bot signature');
7867 FSelectedWeapon
:= utils
.readByte(st
);
7869 FTargetUID
:= utils
.readWord(st
);
7870 // Âðåìÿ ïîòåðè öåëè
7871 FLastVisible
:= utils
.readLongWord(st
);
7872 // Êîëè÷åñòâî ôëàãîâ ÈÈ
7873 dw
:= utils
.readLongInt(st
);
7874 if (dw
< 0) or (dw
> 16384) then raise XStreamError
.Create('invalid number of bot AI flags');
7875 SetLength(FAIFlags
, dw
);
7877 for i
:= 0 to dw
-1 do
7879 FAIFlags
[i
].Name
:= utils
.readStr(st
, 20);
7880 FAIFlags
[i
].Value
:= utils
.readStr(st
, 20);
7882 // Íàñòðîéêè ñëîæíîñòè
7883 FDifficult
.load(st
);
7888 conRegVar('cheat_berserk_autoswitch', @gBerserkAutoswitch
, 'autoswitch to fist when berserk pack taken', '', true, true);