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/>.
22 e_graphics
, g_playermodel
, g_basic
, g_textures
,
23 g_weapons
, g_phys
, g_sound
, g_saveload
, MAPSTRUCT
,
55 AmmoLimits
: Array [0..1] of Array [A_BULLETS
..A_HIGH
] of Word =
57 (400, 100, 100, 600));
78 ANGLE_NONE
= Low(SmallInt);
80 CORPSE_STATE_REMOVEME
= 0;
81 CORPSE_STATE_NORMAL
= 1;
82 CORPSE_STATE_MESS
= 2;
84 PLAYER_RECT
: TRectWH
= (X
:15; Y
:12; Width
:34; Height
:52);
85 PLAYER_RECT_CX
= 15+(34 div 2);
86 PLAYER_RECT_CY
= 12+(52 div 2);
87 PLAYER_CORPSERECT
: TRectWH
= (X
:15; Y
:48; Width
:34; Height
:16);
90 PLAYER_HP_LIMIT
= 200;
92 PLAYER_AP_LIMIT
= 200;
95 PLAYER1_DEF_COLOR
: TRGB
= (R
:64; G
:175; B
:48);
96 PLAYER2_DEF_COLOR
: TRGB
= (R
:96; G
:96; B
:96);
112 TPlayerStatArray
= Array of TPlayerStat
;
114 TPlayerSavedState
= record
122 Ammo
: Array [A_BULLETS
..A_HIGH
] of Word;
123 MaxAmmo
: Array [A_BULLETS
..A_HIGH
] of Word;
124 Weapon
: Array [WP_FIRST
..WP_LAST
] of Boolean;
125 Rulez
: Set of R_ITEM_BACKPACK
..R_BERSERK
;
134 TPlayer
= class (TObject
)
142 FDirection
: TDirection
;
150 FMonsterKills
: Integer;
156 FCanJetpack
: Boolean;
162 FNextWeapDelay
: Byte; // frames
163 FBFGFireCounter
: SmallInt;
164 FLastSpawnerUID
: Word;
168 FSpectatePlayer
: Integer;
170 FSavedState
: TPlayerSavedState
;
172 FModel
: TPlayerModel
;
175 FActionForce
: Boolean;
176 FActionChanged
: Boolean;
178 FFireAngle
: SmallInt;
180 FShellTimer
: Integer;
182 FSawSound
: TPlayableSound
;
183 FSawSoundIdle
: TPlayableSound
;
184 FSawSoundHit
: TPlayableSound
;
185 FSawSoundSelect
: TPlayableSound
;
186 FJetSoundOn
: TPlayableSound
;
187 FJetSoundOff
: TPlayableSound
;
188 FJetSoundFly
: TPlayableSound
;
192 FJustTeleported
: Boolean;
195 function CollideLevel(XInc
, YInc
: Integer): Boolean;
196 function StayOnStep(XInc
, YInc
: Integer): Boolean;
197 function HeadInLiquid(XInc
, YInc
: Integer): Boolean;
198 function BodyInLiquid(XInc
, YInc
: Integer): Boolean;
199 function BodyInAcid(XInc
, YInc
: Integer): Boolean;
200 function FullInLift(XInc
, YInc
: Integer): Integer;
201 {procedure CollideItem();}
202 procedure FlySmoke(Times
: DWORD
= 1);
203 function GetAmmoByWeapon(Weapon
: Byte): Word;
204 procedure SetAction(Action
: Byte; Force
: Boolean = False);
205 procedure OnDamage(Angle
: SmallInt); virtual;
206 function firediry(): Integer;
208 procedure Run(Direction
: TDirection
);
209 procedure NextWeapon();
210 procedure PrevWeapon();
217 function getNextWeaponIndex (): Byte; // return 255 for "no switch"
218 procedure resetWeaponQueue ();
219 function hasAmmoForWeapon (weapon
: Byte): Boolean;
222 FDamageBuffer
: Integer;
224 FAmmo
: Array [A_BULLETS
..A_HIGH
] of Word;
225 FMaxAmmo
: Array [A_BULLETS
..A_HIGH
] of Word;
226 FWeapon
: Array [WP_FIRST
..WP_LAST
] of Boolean;
227 FRulez
: Set of R_ITEM_BACKPACK
..R_BERSERK
;
229 FMegaRulez
: Array [MR_SUIT
..MR_MAX
] of DWORD
;
230 FReloading
: Array [WP_FIRST
..WP_LAST
] of Word;
231 FTime
: Array [T_RESPAWN
..T_FLAGCAP
] of DWORD
;
232 FKeys
: Array [KEY_LEFT
..KEY_CHAT
] of TKeyState
;
234 FPreferredTeam
: Byte;
237 FWantsInGame
: Boolean;
241 FActualModelName
: string;
247 constructor Create(); virtual;
248 destructor Destroy(); override;
249 procedure Respawn(Silent
: Boolean; Force
: Boolean = False); virtual;
250 function GetRespawnPoint(): Byte;
251 procedure PressKey(Key
: Byte; Time
: Word = 1);
252 procedure ReleaseKeys();
253 procedure SetModel(ModelName
: String);
254 procedure SetColor(Color
: TRGB
);
255 procedure SetWeapon(W
: Byte);
256 function IsKeyPressed(K
: Byte): Boolean;
257 function GetKeys(): Byte;
258 function PickItem(ItemType
: Byte; respawn
: Boolean; var remove
: Boolean): Boolean; virtual;
259 function Collide(X
, Y
: Integer; Width
, Height
: Word): Boolean; overload
;
260 function Collide(Panel
: TPanel
): Boolean; overload
;
261 function Collide(X
, Y
: Integer): Boolean; overload
;
262 procedure SetDirection(Direction
: TDirection
);
263 procedure GetSecret();
264 function TeleportTo(X
, Y
: Integer; silent
: Boolean; dir
: Byte): Boolean;
266 procedure Push(vx
, vy
: Integer);
267 procedure ChangeModel(ModelName
: String);
268 procedure SwitchTeam
;
269 procedure ChangeTeam(Team
: Byte);
271 function GetFlag(Flag
: Byte): Boolean;
272 procedure SetFlag(Flag
: Byte);
273 function DropFlag(): Boolean;
274 procedure AllRulez(Health
: Boolean);
275 procedure RestoreHealthArmor();
276 procedure FragCombo();
277 procedure GiveItem(ItemType
: Byte);
278 procedure Damage(value
: Word; SpawnerUID
: Word; vx
, vy
: Integer; t
: Byte); virtual;
279 function Heal(value
: Word; Soft
: Boolean): Boolean; virtual;
280 procedure MakeBloodVector(Count
: Word; VelX
, VelY
: Integer);
281 procedure MakeBloodSimple(Count
: Word);
282 procedure Kill(KillType
: Byte; SpawnerUID
: Word; t
: Byte);
283 procedure Reset(Force
: Boolean);
284 procedure Spectate(NoMove
: Boolean = False);
285 procedure SwitchNoClip
;
286 procedure SoftReset();
287 procedure Draw(); virtual;
288 procedure DrawPain();
289 procedure DrawPickup();
290 procedure DrawRulez();
292 procedure DrawBubble();
294 procedure Update(); virtual;
295 procedure RememberState();
296 procedure RecallState();
297 procedure SaveState(var Mem
: TBinMemoryWriter
); virtual;
298 procedure LoadState(var Mem
: TBinMemoryReader
); virtual;
299 procedure PauseSounds(Enable
: Boolean);
300 procedure NetFire(Wpn
: Byte; X
, Y
, AX
, AY
: Integer; WID
: Integer = -1);
301 procedure DoLerp(Level
: Integer = 2);
302 procedure SetLerp(XTo
, YTo
: Integer);
303 procedure QueueWeaponSwitch(Weapon
: Byte);
304 procedure RealizeCurrentWeapon();
306 procedure JetpackOff
;
308 property Name
: String read FName write FName
;
309 property Model
: TPlayerModel read FModel
;
310 property Health
: Integer read FHealth write FHealth
;
311 property Lives
: Byte read FLives write FLives
;
312 property Armor
: Integer read FArmor write FArmor
;
313 property Air
: Integer read FAir write FAir
;
314 property JetFuel
: Integer read FJetFuel write FJetFuel
;
315 property Frags
: Integer read FFrags write FFrags
;
316 property Death
: Integer read FDeath write FDeath
;
317 property Kills
: Integer read FKills write FKills
;
318 property CurrWeap
: Byte read FCurrWeap write FCurrWeap
;
319 property MonsterKills
: Integer read FMonsterKills write FMonsterKills
;
320 property Secrets
: Integer read FSecrets
;
321 property GodMode
: Boolean read FGodMode write FGodMode
;
322 property NoTarget
: Boolean read FNoTarget write FNoTarget
;
323 property NoReload
: Boolean read FNoReload write FNoReload
;
324 property Live
: Boolean read FLive write FLive
;
325 property Flag
: Byte read FFlag
;
326 property Team
: Byte read FTeam write FTeam
;
327 property Direction
: TDirection read FDirection
;
328 property GameX
: Integer read FObj
.X write FObj
.X
;
329 property GameY
: Integer read FObj
.Y write FObj
.Y
;
330 property GameVelX
: Integer read FObj
.Vel
.X write FObj
.Vel
.X
;
331 property GameVelY
: Integer read FObj
.Vel
.Y write FObj
.Vel
.Y
;
332 property GameAccelX
: Integer read FObj
.Accel
.X write FObj
.Accel
.X
;
333 property GameAccelY
: Integer read FObj
.Accel
.Y write FObj
.Accel
.Y
;
334 property Vel
: TPoint2i read FObj
.Vel
;
335 property Obj
: TObj read FObj
;
336 property IncCam
: Integer read FIncCam write FIncCam
;
337 property UID
: Word read FUID write FUID
;
338 property JustTeleported
: Boolean read FJustTeleported write FJustTeleported
;
339 property NetTime
: LongWord read FNetTime write FNetTime
;
349 WeaponPrior
: Array [WP_FIRST
..WP_LAST
] of Byte;
350 CloseWeaponPrior
: Array [WP_FIRST
..WP_LAST
] of Byte;
351 //SafeWeaponPrior: Array [WP_FIRST..WP_LAST] of Byte;
359 TBot
= class (TPlayer
)
361 FSelectedWeapon
: Byte;
364 FAIFlags
: Array of TAIFlag
;
365 FDifficult
: TDifficult
;
367 function GetRnd(a
: Byte): Boolean;
368 function GetInterval(a
: Byte; radius
: SmallInt): SmallInt;
369 function RunDirection(): TDirection
;
370 function FullInStep(XInc
, YInc
: Integer): Boolean;
371 //function NeedItem(Item: Byte): Byte;
372 procedure SelectWeapon(Dist
: Integer);
373 procedure SetAIFlag(fName
, fValue
: String20
);
374 function GetAIFlag(fName
: String20
): String20
;
375 procedure RemoveAIFlag(fName
: String20
);
376 function Healthy(): Byte;
377 procedure UpdateMove();
378 procedure UpdateCombat();
379 function KeyPressed(Key
: Word): Boolean;
380 procedure ReleaseKey(Key
: Byte);
381 function TargetOnScreen(TX
, TY
: Integer): Boolean;
382 procedure OnDamage(Angle
: SmallInt); override;
385 procedure Respawn(Silent
: Boolean; Force
: Boolean = False); override;
386 constructor Create(); override;
387 destructor Destroy(); override;
388 procedure Draw(); override;
389 function PickItem(ItemType
: Byte; force
: Boolean; var remove
: Boolean): Boolean; override;
390 function Heal(value
: Word; Soft
: Boolean): Boolean; override;
391 procedure Update(); override;
392 procedure SaveState(var Mem
: TBinMemoryWriter
); override;
393 procedure LoadState(var Mem
: TBinMemoryReader
); override;
415 TCorpse
= class (TObject
)
423 FAnimation
: TAnimation
;
424 FAnimationMask
: TAnimation
;
427 constructor Create(X
, Y
: Integer; ModelName
: String; aMess
: Boolean);
428 destructor Destroy(); override;
429 procedure Damage(Value
: Word; vx
, vy
: Integer);
432 procedure SaveState(var Mem
: TBinMemoryWriter
);
433 procedure LoadState(var Mem
: TBinMemoryReader
);
435 property Obj
: TObj read FObj
;
436 property State
: Byte read FState
;
437 property Mess
: Boolean read FMess
;
440 TTeamStat
= Array [TEAM_RED
..TEAM_BLUE
] of
446 gPlayers
: Array of TPlayer
;
447 gCorpses
: Array of TCorpse
;
448 gGibs
: Array of TGib
;
449 gShells
: Array of TShell
;
450 gTeamStat
: TTeamStat
;
451 gFly
: Boolean = False;
452 gAimLine
: Boolean = False;
453 gChatBubble
: Byte = 0;
457 MAX_RUNVEL
: Integer = 8;
458 VEL_JUMP
: Integer = 10;
459 SHELL_TIMEOUT
: Cardinal = 60000;
461 function Lerp(X
, Y
, Factor
: Integer): Integer;
463 procedure g_Gibs_SetMax(Count
: Word);
464 function g_Gibs_GetMax(): Word;
465 procedure g_Corpses_SetMax(Count
: Word);
466 function g_Corpses_GetMax(): Word;
467 procedure g_Shells_SetMax(Count
: Word);
468 function g_Shells_GetMax(): Word;
470 procedure g_Player_Init();
471 procedure g_Player_Free();
472 function g_Player_Create(ModelName
: String; Color
: TRGB
; Team
: Byte; Bot
: Boolean): Word;
473 function g_Player_CreateFromState(var Mem
: TBinMemoryReader
): Word;
474 procedure g_Player_Remove(UID
: Word);
475 procedure g_Player_ResetTeams();
476 procedure g_Player_UpdateAll();
477 procedure g_Player_DrawAll();
478 procedure g_Player_DrawDebug(p
: TPlayer
);
479 procedure g_Player_DrawHealth();
480 procedure g_Player_RememberAll();
481 procedure g_Player_ResetAll(Force
, Silent
: Boolean);
482 function g_Player_Get(UID
: Word): TPlayer
;
483 function g_Player_GetCount(): Byte;
484 function g_Player_GetStats(): TPlayerStatArray
;
485 function g_Player_ValidName(Name
: String): Boolean;
486 procedure g_Player_CreateCorpse(Player
: TPlayer
);
487 procedure g_Player_CreateGibs(fX
, fY
: Integer; ModelName
: String; fColor
: TRGB
);
488 procedure g_Player_CreateShell(fX
, fY
, dX
, dY
: Integer; T
: Byte);
489 procedure g_Player_UpdatePhysicalObjects();
490 procedure g_Player_DrawCorpses();
491 procedure g_Player_DrawShells();
492 procedure g_Player_RemoveAllCorpses();
493 procedure g_Player_Corpses_SaveState(var Mem
: TBinMemoryWriter
);
494 procedure g_Player_Corpses_LoadState(var Mem
: TBinMemoryReader
);
495 procedure g_Bot_Add(Team
, Difficult
: Byte);
496 procedure g_Bot_AddList(Team
: Byte; lname
: ShortString; num
: Integer = -1);
497 procedure g_Bot_MixNames();
498 procedure g_Bot_RemoveAll();
503 e_log
, g_map
, g_items
, g_console
, SysUtils
, g_gfx
, Math
,
504 g_options
, g_triggers
, g_menu
, MAPDEF
, g_game
,
505 wadreader
, g_main
, g_monsters
, CONFIG
, g_language
, g_net
, g_netmsg
;
515 diag_precision
: Byte;
519 w_prior1
: Array [WP_FIRST
..WP_LAST
] of Byte;
520 w_prior2
: Array [WP_FIRST
..WP_LAST
] of Byte;
521 w_prior3
: Array [WP_FIRST
..WP_LAST
] of Byte;
525 TIME_RESPAWN1
= 1500;
526 TIME_RESPAWN2
= 2000;
527 TIME_RESPAWN3
= 3000;
530 JET_MAX
= 540; // ~30 sec
531 PLAYER_SUIT_TIME
= 30000;
532 PLAYER_INVUL_TIME
= 30000;
533 PLAYER_INVIS_TIME
= 35000;
534 FRAG_COMBO_TIME
= 3000;
538 ANGLE_RIGHTDOWN
= -35;
540 ANGLE_LEFTDOWN
= -145;
541 PLAYER_HEADRECT
: TRectWH
= (X
:24; Y
:12; Width
:20; Height
:12);
542 WEAPONPOINT
: Array [TDirection
] of TPoint
= ((X
:16; Y
:32), (X
:47; Y
:32));
545 BOT_UNSAFEDIST
= 128;
546 TEAMCOLOR
: Array [TEAM_RED
..TEAM_BLUE
] of TRGB
= ((R
:255; G
:0; B
:0),
548 DIFFICULT_EASY
: TDifficult
= (DiagFire
: 32; InvisFire
: 32; DiagPrecision
: 32;
549 FlyPrecision
: 32; Cover
: 32; CloseJump
: 32;
550 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0));
551 DIFFICULT_MEDIUM
: TDifficult
= (DiagFire
: 127; InvisFire
: 127; DiagPrecision
: 127;
552 FlyPrecision
: 127; Cover
: 127; CloseJump
: 127;
553 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0));
554 DIFFICULT_HARD
: TDifficult
= (DiagFire
: 255; InvisFire
: 255; DiagPrecision
: 255;
555 FlyPrecision
: 255; Cover
: 255; CloseJump
: 255;
556 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0));
557 WEAPON_PRIOR1
: Array [WP_FIRST
..WP_LAST
] of Byte =
558 (WEAPON_SUPERPULEMET
, WEAPON_SHOTGUN2
, WEAPON_SHOTGUN1
,
559 WEAPON_CHAINGUN
, WEAPON_PLASMA
, WEAPON_ROCKETLAUNCHER
,
560 WEAPON_BFG
, WEAPON_PISTOL
, WEAPON_SAW
, WEAPON_KASTET
);
561 WEAPON_PRIOR2
: Array [WP_FIRST
..WP_LAST
] of Byte =
562 (WEAPON_SUPERPULEMET
, WEAPON_BFG
, WEAPON_ROCKETLAUNCHER
,
563 WEAPON_SHOTGUN2
, WEAPON_PLASMA
, WEAPON_SHOTGUN1
,
564 WEAPON_CHAINGUN
, WEAPON_PISTOL
, WEAPON_SAW
, WEAPON_KASTET
);
565 //WEAPON_PRIOR3: Array [WP_FIRST..WP_LAST] of Byte =
566 // (WEAPON_SUPERPULEMET, WEAPON_BFG, WEAPON_PLASMA,
567 // WEAPON_SHOTGUN2, WEAPON_CHAINGUN, WEAPON_SHOTGUN1,
568 // WEAPON_SAW, WEAPON_ROCKETLAUNCHER, WEAPON_PISTOL, WEAPON_KASTET);
569 WEAPON_RELOAD
: Array [WP_FIRST
..WP_LAST
] of Byte =
570 (5, 2, 6, 18, 36, 2, 12, 2, 14, 2);
572 PLAYER_SIGNATURE
= $52594C50; // 'PLYR'
573 CORPSE_SIGNATURE
= $50524F43; // 'CORP'
575 BOTNAMES_FILENAME
= 'botnames.txt';
576 BOTLIST_FILENAME
= 'botlist.txt';
580 MaxCorpses
: Word = 20;
581 MaxShells
: Word = 300;
582 CurrentGib
: Integer = 0;
583 CurrentShell
: Integer = 0;
584 BotNames
: Array of String;
585 BotList
: Array of TBotProfile
;
587 function Lerp(X
, Y
, Factor
: Integer): Integer;
589 Result
:= X
+ ((Y
- X
) div Factor
);
592 function SameTeam(UID1
, UID2
: Word): Boolean;
596 if (UID1
> UID_MAX_PLAYER
) or (UID1
<= UID_MAX_GAME
) or
597 (UID2
> UID_MAX_PLAYER
) or (UID2
<= UID_MAX_GAME
) then Exit
;
599 if (g_Player_Get(UID1
) = nil) or (g_Player_Get(UID2
) = nil) then Exit
;
601 if ((g_Player_Get(UID1
).Team
= TEAM_NONE
) or
602 (g_Player_Get(UID2
).Team
= TEAM_NONE
)) then Exit
;
604 Result
:= g_Player_Get(UID1
).FTeam
= g_Player_Get(UID2
).FTeam
;
607 procedure g_Gibs_SetMax(Count
: Word);
610 SetLength(gGibs
, Count
);
612 if CurrentGib
>= Count
then
616 function g_Gibs_GetMax(): Word;
621 procedure g_Shells_SetMax(Count
: Word);
624 SetLength(gShells
, Count
);
626 if CurrentShell
>= Count
then
630 function g_Shells_GetMax(): Word;
636 procedure g_Corpses_SetMax(Count
: Word);
639 SetLength(gCorpses
, Count
);
642 function g_Corpses_GetMax(): Word;
644 Result
:= MaxCorpses
;
647 function g_Player_Create(ModelName
: String; Color
: TRGB
; Team
: Byte; Bot
: Boolean): Word;
657 // Åñòü ëè ìåñòî â gPlayers:
658 if gPlayers
<> nil then
659 for a
:= 0 to High(gPlayers
) do
660 if gPlayers
[a
] = nil then
666 // Íåò ìåñòà - ðàñøèðÿåì gPlayers:
669 SetLength(gPlayers
, Length(gPlayers
)+1);
673 // Ñîçäàåì îáúåêò èãðîêà:
675 gPlayers
[a
] := TBot
.Create()
677 gPlayers
[a
] := TPlayer
.Create();
680 gPlayers
[a
].FActualModelName
:= ModelName
;
681 gPlayers
[a
].SetModel(ModelName
);
683 // Íåò ìîäåëè - ñîçäàíèå íå âîçìîæíî:
684 if gPlayers
[a
].FModel
= nil then
688 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], [ModelName
]));
692 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
693 if Random(2) = 0 then
697 gPlayers
[a
].FPreferredTeam
:= Team
;
699 case gGameSettings
.GameMode
of
700 GM_DM
: gPlayers
[a
].FTeam
:= TEAM_NONE
;
702 GM_CTF
: gPlayers
[a
].FTeam
:= gPlayers
[a
].FPreferredTeam
;
704 GM_COOP
: gPlayers
[a
].FTeam
:= TEAM_COOP
;
707 // Åñëè êîìàíäíàÿ èãðà - êðàñèì ìîäåëü â öâåò êîìàíäû:
708 gPlayers
[a
].FColor
:= Color
;
709 if gPlayers
[a
].FTeam
in [TEAM_RED
, TEAM_BLUE
] then
710 gPlayers
[a
].FModel
.Color
:= TEAMCOLOR
[gPlayers
[a
].FTeam
]
712 gPlayers
[a
].FModel
.Color
:= Color
;
714 gPlayers
[a
].FUID
:= g_CreateUID(UID_PLAYER
);
715 gPlayers
[a
].FLive
:= False;
717 Result
:= gPlayers
[a
].FUID
;
720 function g_Player_CreateFromState(var Mem
: TBinMemoryReader
): Word;
733 if sig
<> PLAYER_SIGNATURE
then // 'PLYR'
735 raise EBinSizeError
.Create('g_Player_CreateFromState: Wrong Player Signature');
739 Mem
.ReadBoolean(Bot
);
744 // Åñòü ëè ìåñòî â gPlayers:
745 if gPlayers
<> nil then
746 for a
:= 0 to High(gPlayers
) do
747 if gPlayers
[a
] = nil then
753 // Íåò ìåñòà - ðàñøèðÿåì gPlayers:
756 SetLength(gPlayers
, Length(gPlayers
)+1);
760 // Ñîçäàåì îáúåêò èãðîêà:
762 gPlayers
[a
] := TBot
.Create()
764 gPlayers
[a
] := TPlayer
.Create();
765 gPlayers
[a
].FIamBot
:= Bot
;
766 gPlayers
[a
].FPhysics
:= True;
769 Mem
.ReadWord(gPlayers
[a
].FUID
);
771 Mem
.ReadString(gPlayers
[a
].FName
);
773 Mem
.ReadByte(gPlayers
[a
].FTeam
);
774 gPlayers
[a
].FPreferredTeam
:= gPlayers
[a
].FTeam
;
776 Mem
.ReadBoolean(gPlayers
[a
].FLive
);
777 // Èçðàñõîäîâàë ëè âñå æèçíè:
778 Mem
.ReadBoolean(gPlayers
[a
].FNoRespawn
);
782 gPlayers
[a
].FDirection
:= D_LEFT
784 gPlayers
[a
].FDirection
:= D_RIGHT
;
786 Mem
.ReadInt(gPlayers
[a
].FHealth
);
788 Mem
.ReadByte(gPlayers
[a
].FLives
);
790 Mem
.ReadInt(gPlayers
[a
].FArmor
);
792 Mem
.ReadInt(gPlayers
[a
].FAir
);
794 Mem
.ReadInt(gPlayers
[a
].FJetFuel
);
796 Mem
.ReadInt(gPlayers
[a
].FPain
);
798 Mem
.ReadInt(gPlayers
[a
].FKills
);
800 Mem
.ReadInt(gPlayers
[a
].FMonsterKills
);
802 Mem
.ReadInt(gPlayers
[a
].FFrags
);
804 Mem
.ReadByte(gPlayers
[a
].FFragCombo
);
805 // Âðåìÿ ïîñëåäíåãî ôðàãà:
806 Mem
.ReadDWORD(gPlayers
[a
].FLastFrag
);
808 Mem
.ReadInt(gPlayers
[a
].FDeath
);
810 Mem
.ReadByte(gPlayers
[a
].FFlag
);
812 Mem
.ReadInt(gPlayers
[a
].FSecrets
);
814 Mem
.ReadByte(gPlayers
[a
].FCurrWeap
);
815 // Ñëåäóþùåå æåëàåìîå îðóæèå:
816 Mem
.ReadWord(gPlayers
[a
].FNextWeap
);
818 Mem
.ReadByte(gPlayers
[a
].FNextWeapDelay
);
819 // Âðåìÿ çàðÿäêè BFG:
820 Mem
.ReadSmallInt(gPlayers
[a
].FBFGFireCounter
);
822 Mem
.ReadInt(gPlayers
[a
].FDamageBuffer
);
823 // Ïîñëåäíèé óäàðèâøèé:
824 Mem
.ReadWord(gPlayers
[a
].FLastSpawnerUID
);
825 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà:
826 Mem
.ReadByte(gPlayers
[a
].FLastHit
);
828 Obj_LoadState(@gPlayers
[a
].FObj
, Mem
);
829 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ:
830 for i
:= A_BULLETS
to A_HIGH
do
831 Mem
.ReadWord(gPlayers
[a
].FAmmo
[i
]);
832 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ:
833 for i
:= A_BULLETS
to A_HIGH
do
834 Mem
.ReadWord(gPlayers
[a
].FMaxAmmo
[i
]);
836 for i
:= WP_FIRST
to WP_LAST
do
837 Mem
.ReadBoolean(gPlayers
[a
].FWeapon
[i
]);
838 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ:
839 for i
:= WP_FIRST
to WP_LAST
do
840 Mem
.ReadWord(gPlayers
[a
].FReloading
[i
]);
844 Include(gPlayers
[a
].FRulez
, R_ITEM_BACKPACK
);
845 // Íàëè÷èå êðàñíîãî êëþ÷à:
848 Include(gPlayers
[a
].FRulez
, R_KEY_RED
);
849 // Íàëè÷èå çåëåíîãî êëþ÷à:
852 Include(gPlayers
[a
].FRulez
, R_KEY_GREEN
);
853 // Íàëè÷èå ñèíåãî êëþ÷à:
856 Include(gPlayers
[a
].FRulez
, R_KEY_BLUE
);
860 Include(gPlayers
[a
].FRulez
, R_BERSERK
);
861 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ:
862 for i
:= MR_SUIT
to MR_MAX
do
863 Mem
.ReadDWORD(gPlayers
[a
].FMegaRulez
[i
]);
864 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà:
865 for i
:= T_RESPAWN
to T_FLAGCAP
do
866 Mem
.ReadDWORD(gPlayers
[a
].FTime
[i
]);
869 Mem
.ReadString(gPlayers
[a
].FActualModelName
);
871 Mem
.ReadByte(gPlayers
[a
].FColor
.R
);
872 Mem
.ReadByte(gPlayers
[a
].FColor
.G
);
873 Mem
.ReadByte(gPlayers
[a
].FColor
.B
);
874 // Îáíîâëÿåì ìîäåëü èãðîêà:
875 gPlayers
[a
].SetModel(gPlayers
[a
].FActualModelName
);
877 // Íåò ìîäåëè - ñîçäàíèå íå âîçìîæíî:
878 if gPlayers
[a
].FModel
= nil then
882 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], [gPlayers
[a
].FActualModelName
]));
886 // Åñëè êîìàíäíàÿ èãðà - êðàñèì ìîäåëü â öâåò êîìàíäû:
887 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
888 gPlayers
[a
].FModel
.Color
:= TEAMCOLOR
[gPlayers
[a
].FTeam
]
890 gPlayers
[a
].FModel
.Color
:= gPlayers
[a
].FColor
;
892 Result
:= gPlayers
[a
].FUID
;
895 procedure g_Player_ResetTeams();
899 if g_Game_IsClient
then
901 if gPlayers
= nil then
903 for a
:= Low(gPlayers
) to High(gPlayers
) do
904 if gPlayers
[a
] <> nil then
905 case gGameSettings
.GameMode
of
907 gPlayers
[a
].ChangeTeam(TEAM_NONE
);
909 if not (gPlayers
[a
].Team
in [TEAM_RED
, TEAM_BLUE
]) then
910 if gPlayers
[a
].FPreferredTeam
in [TEAM_RED
, TEAM_BLUE
] then
911 gPlayers
[a
].ChangeTeam(gPlayers
[a
].FPreferredTeam
)
914 gPlayers
[a
].ChangeTeam(TEAM_RED
)
916 gPlayers
[a
].ChangeTeam(TEAM_BLUE
);
919 gPlayers
[a
].ChangeTeam(TEAM_COOP
);
923 procedure g_Bot_Add(Team
, Difficult
: Byte);
926 _name
, _model
: String;
929 if not g_Game_IsServer
then Exit
;
931 // Ñïèñîê íàçâàíèé ìîäåëåé:
932 m
:= g_PlayerModel_GetNames();
937 if (gGameSettings
.GameType
= GT_SINGLE
) or (gGameSettings
.GameMode
= GM_COOP
) then
938 Team
:= TEAM_COOP
// COOP
940 if gGameSettings
.GameMode
= GM_DM
then
941 Team
:= TEAM_NONE
// DM
943 if Team
= TEAM_NONE
then // CTF / TDM
945 // Àâòîáàëàíñ êîìàíä:
949 for a
:= 0 to High(gPlayers
) do
950 if gPlayers
[a
] <> nil then
952 if gPlayers
[a
].Team
= TEAM_RED
then
955 if gPlayers
[a
].Team
= TEAM_BLUE
then
965 if Random(2) = 0 then
971 // Âûáèðàåì áîòó èìÿ:
973 if BotNames
<> nil then
974 for a
:= 0 to High(BotNames
) do
975 if g_Player_ValidName(BotNames
[a
]) then
977 _name
:= BotNames
[a
];
981 // Èìåíè íåò, çàäàåì ñëó÷àéíîå:
984 _name
:= Format('DFBOT%.2d', [Random(100)]);
985 until g_Player_ValidName(_name
);
987 // Âûáèðàåì ñëó÷àéíóþ ìîäåëü:
988 _model
:= m
[Random(Length(m
))];
991 with g_Player_Get(g_Player_Create(_model
,
992 _RGB(Min(Random(9)*32, 255),
993 Min(Random(9)*32, 255),
994 Min(Random(9)*32, 255)),
995 Team
, True)) as TBot
do
1000 1: FDifficult
:= DIFFICULT_EASY
;
1001 2: FDifficult
:= DIFFICULT_MEDIUM
;
1002 else FDifficult
:= DIFFICULT_HARD
;
1005 for a
:= WP_FIRST
to WP_LAST
do
1007 FDifficult
.WeaponPrior
[a
] := WEAPON_PRIOR1
[a
];
1008 FDifficult
.CloseWeaponPrior
[a
] := WEAPON_PRIOR2
[a
];
1009 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
1012 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [Name
]), True);
1014 if g_Game_IsNet
then MH_SEND_PlayerCreate(UID
);
1015 if g_Game_IsServer
and (gGameSettings
.MaxLives
> 0) then
1020 procedure g_Bot_AddList(Team
: Byte; lName
: ShortString; num
: Integer = -1);
1023 _name
, _model
: String;
1026 if not g_Game_IsServer
then Exit
;
1028 // Ñïèñîê íàçâàíèé ìîäåëåé:
1029 m
:= g_PlayerModel_GetNames();
1034 if (gGameSettings
.GameType
= GT_SINGLE
) or (gGameSettings
.GameMode
= GM_COOP
) then
1035 Team
:= TEAM_COOP
// COOP
1037 if gGameSettings
.GameMode
= GM_DM
then
1038 Team
:= TEAM_NONE
// DM
1040 if Team
= TEAM_NONE
then
1041 Team
:= BotList
[num
].team
; // CTF / TDM
1043 // Âûáèðàåì íàñòðîéêè áîòà èç ñïèñêà ïî íîìåðó èëè èìåíè:
1044 lName
:= AnsiLowerCase(lName
);
1045 if (num
< 0) or (num
> Length(BotList
)-1) then
1047 if (num
= -1) and (lName
<> '') and (BotList
<> nil) then
1048 for a
:= 0 to High(BotList
) do
1049 if AnsiLowerCase(BotList
[a
].name
) = lName
then
1058 _name
:= BotList
[num
].name
;
1059 // Çàíÿòî - âûáèðàåì ñëó÷àéíîå:
1060 if not g_Player_ValidName(_name
) then
1062 _name
:= Format('DFBOT%.2d', [Random(100)]);
1063 until g_Player_ValidName(_name
);
1066 _model
:= BotList
[num
].model
;
1067 // Íåò òàêîé - âûáèðàåì ñëó÷àéíóþ:
1068 if not InSArray(_model
, m
) then
1069 _model
:= m
[Random(Length(m
))];
1072 with g_Player_Get(g_Player_Create(_model
, BotList
[num
].color
, Team
, True)) as TBot
do
1076 FDifficult
.DiagFire
:= BotList
[num
].diag_fire
;
1077 FDifficult
.InvisFire
:= BotList
[num
].invis_fire
;
1078 FDifficult
.DiagPrecision
:= BotList
[num
].diag_precision
;
1079 FDifficult
.FlyPrecision
:= BotList
[num
].fly_precision
;
1080 FDifficult
.Cover
:= BotList
[num
].cover
;
1081 FDifficult
.CloseJump
:= BotList
[num
].close_jump
;
1083 for a
:= WP_FIRST
to WP_LAST
do
1085 FDifficult
.WeaponPrior
[a
] := BotList
[num
].w_prior1
[a
];
1086 FDifficult
.CloseWeaponPrior
[a
] := BotList
[num
].w_prior2
[a
];
1087 //FDifficult.SafeWeaponPrior[a] := BotList[num].w_prior3[a];
1090 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [Name
]), True);
1092 if g_Game_IsNet
then MH_SEND_PlayerCreate(UID
);
1096 procedure g_Bot_RemoveAll();
1100 if not g_Game_IsServer
then Exit
;
1101 if gPlayers
= nil then Exit
;
1103 for a
:= 0 to High(gPlayers
) do
1104 if gPlayers
[a
] <> nil then
1105 if gPlayers
[a
] is TBot
then
1107 gPlayers
[a
].Lives
:= 0;
1108 gPlayers
[a
].Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
1109 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [gPlayers
[a
].Name
]), True);
1110 g_Player_Remove(gPlayers
[a
].FUID
);
1116 procedure g_Bot_MixNames();
1121 if BotNames
<> nil then
1122 for a
:= 0 to High(BotNames
) do
1124 b
:= Random(Length(BotNames
));
1126 Botnames
[a
] := BotNames
[b
];
1131 procedure g_Player_Remove(UID
: Word);
1135 if gPlayers
= nil then Exit
;
1137 if g_Game_IsServer
and g_Game_IsNet
then
1138 MH_SEND_PlayerDelete(UID
);
1140 for i
:= 0 to High(gPlayers
) do
1141 if gPlayers
[i
] <> nil then
1142 if gPlayers
[i
].FUID
= UID
then
1144 if gPlayers
[i
] is TPlayer
then
1145 TPlayer(gPlayers
[i
]).Free()
1147 TBot(gPlayers
[i
]).Free();
1153 procedure g_Player_Init();
1163 if not FileExists(DataDir
+ BOTNAMES_FILENAME
) then
1166 // ×èòàåì âîçìîæíûå èìåíà áîòîâ èç ôàéëà:
1167 AssignFile(F
, DataDir
+ BOTNAMES_FILENAME
);
1178 SetLength(BotNames
, Length(BotNames
)+1);
1179 BotNames
[High(BotNames
)] := s
;
1187 // ×èòàåì ôàéë ñ ïàðàìåòðàìè áîòîâ:
1188 config
:= TConfig
.CreateFile(DataDir
+ BOTLIST_FILENAME
);
1192 while config
.SectionExists(IntToStr(a
)) do
1194 SetLength(BotList
, Length(BotList
)+1);
1196 with BotList
[High(BotList
)] do
1199 name
:= config
.ReadStr(IntToStr(a
), 'name', '');
1201 model
:= config
.ReadStr(IntToStr(a
), 'model', '');
1203 if config
.ReadStr(IntToStr(a
), 'team', 'red') = 'red' then
1208 sa
:= parse(config
.ReadStr(IntToStr(a
), 'color', ''));
1209 color
.R
:= StrToIntDef(sa
[0], 0);
1210 color
.G
:= StrToIntDef(sa
[1], 0);
1211 color
.B
:= StrToIntDef(sa
[2], 0);
1212 // Âåðîÿòíîñòü ñòðåëüáû ïîä óãëîì:
1213 diag_fire
:= config
.ReadInt(IntToStr(a
), 'diag_fire', 0);
1214 // Âåðîÿòíîñòü îòâåòíîãî îãíÿ ïî íåâèäèìîìó ñîïåðíèêó:
1215 invis_fire
:= config
.ReadInt(IntToStr(a
), 'invis_fire', 0);
1216 // Òî÷íîñòü ñòðåëüáû ïîä óãëîì:
1217 diag_precision
:= config
.ReadInt(IntToStr(a
), 'diag_precision', 0);
1218 // Òî÷íîñòü ñòðåëüáû â ïîëåòå:
1219 fly_precision
:= config
.ReadInt(IntToStr(a
), 'fly_precision', 0);
1220 // Òî÷íîñòü óêëîíåíèÿ îò ñíàðÿäîâ:
1221 cover
:= config
.ReadInt(IntToStr(a
), 'cover', 0);
1222 // Âåðîÿòíîñòü ïðûæêà ïðè ïðèáëèæåíèè ñîïåðíèêà:
1223 close_jump
:= config
.ReadInt(IntToStr(a
), 'close_jump', 0);
1224 // Ïðèîðèòåòû îðóæèÿ äëÿ äàëüíåãî áîÿ:
1225 sa
:= parse(config
.ReadStr(IntToStr(a
), 'w_prior1', ''));
1226 if Length(sa
) = 10 then
1228 w_prior1
[b
] := EnsureRange(StrToInt(sa
[b
]), 0, 9);
1229 // Ïðèîðèòåòû îðóæèÿ äëÿ áëèæíåãî áîÿ:
1230 sa
:= parse(config
.ReadStr(IntToStr(a
), 'w_prior2', ''));
1231 if Length(sa
) = 10 then
1233 w_prior2
[b
] := EnsureRange(StrToInt(sa
[b
]), 0, 9);
1235 {sa := parse(config.ReadStr(IntToStr(a), 'w_prior3', ''));
1236 if Length(sa) = 10 then
1238 w_prior3[b] := EnsureRange(StrToInt(sa[b]), 0, 9);}
1247 procedure g_Player_Free();
1251 if gPlayers
<> nil then
1253 for i
:= 0 to High(gPlayers
) do
1254 if gPlayers
[i
] <> nil then
1256 if gPlayers
[i
] is TPlayer
then
1257 TPlayer(gPlayers
[i
]).Free()
1259 TBot(gPlayers
[i
]).Free();
1270 procedure g_Player_UpdateAll();
1274 if gPlayers
= nil then Exit
;
1276 //e_WriteLog('***g_Player_UpdateAll: ENTER', MSG_WARNING);
1277 for i
:= 0 to High(gPlayers
) do
1279 if gPlayers
[i
] <> nil then
1281 if gPlayers
[i
] is TPlayer
then
1283 gPlayers
[i
].Update();
1284 gPlayers
[i
].RealizeCurrentWeapon(); // WARNING! DO NOT MOVE THIS INTO `Update()`!
1288 // bot updates weapons in `UpdateCombat()`
1289 TBot(gPlayers
[i
]).Update();
1293 //e_WriteLog('***g_Player_UpdateAll: EXIT', MSG_WARNING);
1296 procedure g_Player_DrawAll();
1300 if gPlayers
= nil then Exit
;
1302 for i
:= 0 to High(gPlayers
) do
1303 if gPlayers
[i
] <> nil then
1304 if gPlayers
[i
] is TPlayer
then gPlayers
[i
].Draw()
1305 else TBot(gPlayers
[i
]).Draw();
1308 procedure g_Player_DrawDebug(p
: TPlayer
);
1312 if p
= nil then Exit
;
1313 if (@p
.FObj
) = nil then Exit
;
1315 e_TextureFontGetSize(gStdFont
, fW
, fH
);
1317 e_TextureFontPrint(0, 0 , 'Pos X: ' + IntToStr(p
.FObj
.X
), gStdFont
);
1318 e_TextureFontPrint(0, fH
, 'Pos Y: ' + IntToStr(p
.FObj
.Y
), gStdFont
);
1319 e_TextureFontPrint(0, fH
* 2, 'Vel X: ' + IntToStr(p
.FObj
.Vel
.X
), gStdFont
);
1320 e_TextureFontPrint(0, fH
* 3, 'Vel Y: ' + IntToStr(p
.FObj
.Vel
.Y
), gStdFont
);
1321 e_TextureFontPrint(0, fH
* 4, 'Acc X: ' + IntToStr(p
.FObj
.Accel
.X
), gStdFont
);
1322 e_TextureFontPrint(0, fH
* 5, 'Acc Y: ' + IntToStr(p
.FObj
.Accel
.Y
), gStdFont
);
1325 procedure g_Player_DrawHealth();
1330 if gPlayers
= nil then Exit
;
1331 e_TextureFontGetSize(gStdFont
, fW
, fH
);
1333 for i
:= 0 to High(gPlayers
) do
1334 if gPlayers
[i
] <> nil then
1336 e_TextureFontPrint(gPlayers
[i
].FObj
.X
+ gPlayers
[i
].FObj
.Rect
.X
,
1337 gPlayers
[i
].FObj
.Y
+ gPlayers
[i
].FObj
.Rect
.Y
+ gPlayers
[i
].FObj
.Rect
.Height
- fH
* 2,
1338 IntToStr(gPlayers
[i
].FHealth
), gStdFont
);
1339 e_TextureFontPrint(gPlayers
[i
].FObj
.X
+ gPlayers
[i
].FObj
.Rect
.X
,
1340 gPlayers
[i
].FObj
.Y
+ gPlayers
[i
].FObj
.Rect
.Y
+ gPlayers
[i
].FObj
.Rect
.Height
- fH
,
1341 IntToStr(gPlayers
[i
].FArmor
), gStdFont
);
1345 function g_Player_Get(UID
: Word): TPlayer
;
1351 if gPlayers
= nil then
1354 for a
:= 0 to High(gPlayers
) do
1355 if gPlayers
[a
] <> nil then
1356 if gPlayers
[a
].FUID
= UID
then
1358 Result
:= gPlayers
[a
];
1363 function g_Player_GetCount(): Byte;
1369 if gPlayers
= nil then
1372 for a
:= 0 to High(gPlayers
) do
1373 if gPlayers
[a
] <> nil then
1374 Result
:= Result
+ 1;
1377 function g_Player_GetStats(): TPlayerStatArray
;
1383 if gPlayers
= nil then Exit
;
1385 for a
:= 0 to High(gPlayers
) do
1386 if gPlayers
[a
] <> nil then
1388 SetLength(Result
, Length(Result
)+1);
1389 with Result
[High(Result
)] do
1391 Ping
:= gPlayers
[a
].FPing
;
1392 Loss
:= gPlayers
[a
].FLoss
;
1393 Name
:= gPlayers
[a
].FName
;
1394 Team
:= gPlayers
[a
].FTeam
;
1395 Frags
:= gPlayers
[a
].FFrags
;
1396 Deaths
:= gPlayers
[a
].FDeath
;
1397 Kills
:= gPlayers
[a
].FKills
;
1398 Color
:= gPlayers
[a
].FModel
.Color
;
1399 Lives
:= gPlayers
[a
].FLives
;
1400 Spectator
:= gPlayers
[a
].FSpectator
;
1405 procedure g_Player_RememberAll
;
1409 for i
:= Low(gPlayers
) to High(gPlayers
) do
1410 if (gPlayers
[i
] <> nil) and gPlayers
[i
].Live
then
1411 gPlayers
[i
].RememberState
;
1414 procedure g_Player_ResetAll(Force
, Silent
: Boolean);
1418 gTeamStat
[TEAM_RED
].Goals
:= 0;
1419 gTeamStat
[TEAM_BLUE
].Goals
:= 0;
1421 if gPlayers
<> nil then
1422 for i
:= 0 to High(gPlayers
) do
1423 if gPlayers
[i
] <> nil then
1425 gPlayers
[i
].Reset(Force
);
1427 if gPlayers
[i
] is TPlayer
then
1429 if (not gPlayers
[i
].FSpectator
) or gPlayers
[i
].FWantsInGame
then
1430 gPlayers
[i
].Respawn(Silent
)
1432 gPlayers
[i
].Spectate();
1435 TBot(gPlayers
[i
]).Respawn(Silent
);
1439 procedure g_Player_CreateCorpse(Player
: TPlayer
);
1446 if Player
.FObj
.Y
>= gMapInfo
.Height
+128 then
1451 if (FHealth
>= -50) or (gGibsCount
= 0) then
1453 if (gCorpses
= nil) or (Length(gCorpses
) = 0) then
1457 for find_id
:= 0 to High(gCorpses
) do
1458 if gCorpses
[find_id
] = nil then
1465 find_id
:= Random(Length(gCorpses
));
1467 gCorpses
[find_id
] := TCorpse
.Create(FObj
.X
, FObj
.Y
, FModel
.Name
, FHealth
< -20);
1468 gCorpses
[find_id
].FColor
:= FModel
.Color
;
1469 gCorpses
[find_id
].FObj
.Vel
:= FObj
.Vel
;
1470 gCorpses
[find_id
].FObj
.Accel
:= FObj
.Accel
;
1473 g_Player_CreateGibs(FObj
.X
+ PLAYER_RECT_CX
,
1474 FObj
.Y
+ PLAYER_RECT_CY
,
1475 FModel
.Name
, FModel
.Color
);
1479 procedure g_Player_CreateShell(fX
, fY
, dX
, dY
: Integer; T
: Byte);
1483 if (gShells
= nil) or (Length(gShells
) = 0) then
1486 with gShells
[CurrentShell
] do
1492 if T
= SHELL_BULLET
then
1494 if g_Texture_Get('TEXTURE_SHELL_BULLET', SID
) then
1498 Obj
.Rect
.Width
:= 4;
1499 Obj
.Rect
.Height
:= 2;
1503 if g_Texture_Get('TEXTURE_SHELL_SHELL', SID
) then
1507 Obj
.Rect
.Width
:= 7;
1508 Obj
.Rect
.Height
:= 3;
1514 g_Obj_Push(@Obj
, dX
+ Random(4)-Random(4), dY
-Random(4));
1515 RAngle
:= Random(360);
1516 Timeout
:= gTime
+ SHELL_TIMEOUT
;
1518 if CurrentShell
>= High(gShells
) then
1525 procedure g_Player_CreateGibs(fX
, fY
: Integer; ModelName
: string; fColor
: TRGB
);
1528 GibsArray
: TGibsArray
;
1530 if (gGibs
= nil) or (Length(gGibs
) = 0) then
1532 if not g_PlayerModel_GetGibs(ModelName
, GibsArray
) then
1535 for a
:= 0 to High(GibsArray
) do
1536 with gGibs
[CurrentGib
] do
1539 ID
:= GibsArray
[a
].ID
;
1540 MaskID
:= GibsArray
[a
].MaskID
;
1543 Obj
.Rect
:= GibsArray
[a
].Rect
;
1544 Obj
.X
:= fX
-GibsArray
[a
].Rect
.X
-(GibsArray
[a
].Rect
.Width
div 2);
1545 Obj
.Y
:= fY
-GibsArray
[a
].Rect
.Y
-(GibsArray
[a
].Rect
.Height
div 2);
1546 g_Obj_PushA(@Obj
, 25 + Random(10), Random(361));
1547 RAngle
:= Random(360);
1549 if gBloodCount
> 0 then
1550 g_GFX_Blood(fX
, fY
, 16*gBloodCount
+Random(5*gBloodCount
), -16+Random(33), -16+Random(33),
1551 Random(48), Random(48), 150, 0, 0);
1553 if CurrentGib
>= High(gGibs
) then
1560 procedure g_Player_UpdatePhysicalObjects();
1566 procedure ShellSound_Bounce(X
, Y
: Integer; T
: Byte);
1571 if T
= SHELL_BULLET
then
1572 g_Sound_PlayExAt('SOUND_PLAYER_CASING' + IntToStr(k
), X
, Y
)
1574 g_Sound_PlayExAt('SOUND_PLAYER_SHELL' + IntToStr(k
), X
, Y
);
1579 if gGibs
<> nil then
1580 for i
:= 0 to High(gGibs
) do
1581 if gGibs
[i
].Live
then
1585 mr
:= g_Obj_Move(@Obj
, True, False, True);
1587 if WordBool(mr
and MOVE_FALLOUT
) then
1593 // Îòëåòàåò îò óäàðà î ñòåíó/ïîòîëîê/ïîë:
1594 if WordBool(mr
and MOVE_HITWALL
) then
1595 Obj
.Vel
.X
:= -(vel
.X
div 2);
1596 if WordBool(mr
and (MOVE_HITCEIL
or MOVE_HITLAND
)) then
1597 Obj
.Vel
.Y
:= -(vel
.Y
div 2);
1599 if (Obj
.Vel
.X
>= 0) then
1601 RAngle
:= RAngle
+ Abs(Obj
.Vel
.X
)*6 + Abs(Obj
.Vel
.Y
);
1602 if RAngle
>= 360 then
1603 RAngle
:= RAngle
mod 360;
1604 end else begin // Counter-clockwise
1605 RAngle
:= RAngle
- Abs(Obj
.Vel
.X
)*6 - Abs(Obj
.Vel
.Y
);
1607 RAngle
:= (360 - (Abs(RAngle
) mod 360)) mod 360;
1610 // Ñîïðîòèâëåíèå âîçäóõà äëÿ êóñêà òðóïà:
1611 if gTime
mod (GAME_TICK
*3) = 0 then
1612 Obj
.Vel
.X
:= z_dec(Obj
.Vel
.X
, 1);
1616 if gCorpses
<> nil then
1617 for i
:= 0 to High(gCorpses
) do
1618 if gCorpses
[i
] <> nil then
1619 if gCorpses
[i
].State
= CORPSE_STATE_REMOVEME
then
1625 gCorpses
[i
].Update();
1628 if gShells
<> nil then
1629 for i
:= 0 to High(gShells
) do
1630 if gShells
[i
].Live
then
1634 mr
:= g_Obj_Move(@Obj
, True, False, True);
1636 if WordBool(mr
and MOVE_FALLOUT
) or (gShells
[i
].Timeout
< gTime
) then
1642 // Îòëåòàåò îò óäàðà î ñòåíó/ïîòîëîê/ïîë:
1643 if WordBool(mr
and MOVE_HITWALL
) then
1645 Obj
.Vel
.X
:= -(vel
.X
div 2);
1646 if not WordBool(mr
and MOVE_INWATER
) then
1647 ShellSound_Bounce(Obj
.X
, Obj
.Y
, SType
);
1649 if WordBool(mr
and (MOVE_HITCEIL
or MOVE_HITLAND
)) then
1651 Obj
.Vel
.Y
:= -(vel
.Y
div 2);
1652 if Obj
.Vel
.X
<> 0 then Obj
.Vel
.X
:= Obj
.Vel
.X
div 2;
1653 if (Obj
.Vel
.X
= 0) and (Obj
.Vel
.Y
= 0) then
1655 if RAngle
mod 90 <> 0 then
1656 RAngle
:= (RAngle
div 90) * 90;
1658 else if not WordBool(mr
and MOVE_INWATER
) then
1659 ShellSound_Bounce(Obj
.X
, Obj
.Y
, SType
);
1662 if (Obj
.Vel
.X
>= 0) then
1664 RAngle
:= RAngle
+ Abs(Obj
.Vel
.X
)*8 + Abs(Obj
.Vel
.Y
);
1665 if RAngle
>= 360 then
1666 RAngle
:= RAngle
mod 360;
1667 end else begin // Counter-clockwise
1668 RAngle
:= RAngle
- Abs(Obj
.Vel
.X
)*8 - Abs(Obj
.Vel
.Y
);
1670 RAngle
:= (360 - (Abs(RAngle
) mod 360)) mod 360;
1675 procedure g_Player_DrawCorpses();
1680 if gGibs
<> nil then
1681 for i
:= 0 to High(gGibs
) do
1682 if gGibs
[i
].Live
then
1685 if not g_Obj_Collide(sX
, sY
, sWidth
, sHeight
, @Obj
) then
1688 a
.X
:= Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2);
1689 a
.y
:= Obj
.Rect
.Y
+(Obj
.Rect
.Height
div 2);
1691 e_DrawAdv(ID
, Obj
.X
, Obj
.Y
, 0, True, False, RAngle
, @a
, M_NONE
);
1694 e_DrawAdv(MaskID
, Obj
.X
, Obj
.Y
, 0, True, False, RAngle
, @a
, M_NONE
);
1700 if gCorpses
<> nil then
1701 for i
:= 0 to High(gCorpses
) do
1702 if gCorpses
[i
] <> nil then
1706 procedure g_Player_DrawShells();
1711 if gShells
<> nil then
1712 for i
:= 0 to High(gShells
) do
1713 if gShells
[i
].Live
then
1716 if not g_Obj_Collide(sX
, sY
, sWidth
, sHeight
, @Obj
) then
1722 e_DrawAdv(SpriteID
, Obj
.X
, Obj
.Y
, 0, True, False, RAngle
, @a
, M_NONE
);
1726 procedure g_Player_RemoveAllCorpses();
1732 SetLength(gGibs
, MaxGibs
);
1733 SetLength(gShells
, MaxGibs
);
1737 if gCorpses
<> nil then
1738 for i
:= 0 to High(gCorpses
) do
1742 SetLength(gCorpses
, MaxCorpses
);
1745 procedure g_Player_Corpses_SaveState(var Mem
: TBinMemoryWriter
);
1750 // Ñ÷èòàåì êîëè÷åñòâî ñóùåñòâóþùèõ òðóïîâ:
1752 if gCorpses
<> nil then
1753 for i
:= 0 to High(gCorpses
) do
1754 if gCorpses
[i
] <> nil then
1757 Mem
:= TBinMemoryWriter
.Create((count
+1) * 128);
1759 // Êîëè÷åñòâî òðóïîâ:
1760 Mem
.WriteInt(count
);
1766 for i
:= 0 to High(gCorpses
) do
1767 if gCorpses
[i
] <> nil then
1770 Mem
.WriteString(gCorpses
[i
].FModelName
);
1772 b
:= gCorpses
[i
].Mess
;
1773 Mem
.WriteBoolean(b
);
1774 // Ñîõðàíÿåì äàííûå òðóïà:
1775 gCorpses
[i
].SaveState(Mem
);
1779 procedure g_Player_Corpses_LoadState(var Mem
: TBinMemoryReader
);
1788 g_Player_RemoveAllCorpses();
1790 // Êîëè÷åñòâî òðóïîâ:
1793 if count
> Length(gCorpses
) then
1795 raise EBinSizeError
.Create('g_Player_Corpses_LoadState: Too Many Corpses');
1802 for i
:= 0 to count
-1 do
1805 Mem
.ReadString(str
);
1809 gCorpses
[i
] := TCorpse
.Create(0, 0, str
, b
);
1810 // Çàãðóæàåì äàííûå òðóïà:
1811 gCorpses
[i
].LoadState(Mem
);
1817 procedure TPlayer
.BFGHit();
1819 g_Weapon_BFGHit(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
1820 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2));
1821 if g_Game_IsServer
and g_Game_IsNet
then
1822 MH_SEND_Effect(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
1823 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2),
1827 procedure TPlayer
.ChangeModel(ModelName
: string);
1829 Model
: TPlayerModel
;
1831 Model
:= g_PlayerModel_Get(ModelName
);
1832 if Model
= nil then Exit
;
1838 procedure TPlayer
.SetModel(ModelName
: string);
1842 m
:= g_PlayerModel_Get(ModelName
);
1845 g_SimpleError(Format(_lc
[I_GAME_ERROR_MODEL_FALLBACK
], [ModelName
]));
1846 m
:= g_PlayerModel_Get('doomer');
1849 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], ['doomer']));
1854 if FModel
<> nil then
1859 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
1860 FModel
.Color
:= FColor
1862 FModel
.Color
:= TEAMCOLOR
[FTeam
];
1863 FModel
.SetWeapon(FCurrWeap
);
1864 FModel
.SetFlag(FFlag
);
1865 SetDirection(FDirection
);
1868 procedure TPlayer
.SetColor(Color
: TRGB
);
1871 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
1872 if FModel
<> nil then FModel
.Color
:= Color
;
1875 procedure TPlayer
.SwitchTeam
;
1877 if g_Game_IsClient
then
1879 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then Exit
;
1881 if gGameOn
and FLive
then
1882 Kill(K_SIMPLEKILL
, FUID
, HIT_SELF
);
1884 if FTeam
= TEAM_RED
then
1886 ChangeTeam(TEAM_BLUE
);
1887 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_BLUE
], [FName
]), True);
1888 if g_Game_IsNet
then
1889 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM
, TEAM_BLUE
, FName
);
1893 ChangeTeam(TEAM_RED
);
1894 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_RED
], [FName
]), True);
1895 if g_Game_IsNet
then
1896 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM
, TEAM_RED
, FName
);
1898 FPreferredTeam
:= FTeam
;
1901 procedure TPlayer
.ChangeTeam(Team
: Byte);
1908 TEAM_RED
, TEAM_BLUE
:
1909 FModel
.Color
:= TEAMCOLOR
[Team
];
1911 FModel
.Color
:= FColor
;
1913 if (FTeam
<> OldTeam
) and g_Game_IsNet
and g_Game_IsServer
then
1914 MH_SEND_PlayerStats(FUID
);
1918 procedure TPlayer.CollideItem();
1923 if gItems = nil then Exit;
1924 if not FLive then Exit;
1926 for i := 0 to High(gItems) do
1929 if (ItemType <> ITEM_NONE) and Live then
1930 if g_Obj_Collide(FObj.X+PLAYER_RECT.X, FObj.Y+PLAYER_RECT.Y, PLAYER_RECT.Width,
1931 PLAYER_RECT.Height, @Obj) then
1933 if not PickItem(ItemType, gItems[i].Respawnable, r) then Continue;
1935 if ItemType in [ITEM_SPHERE_BLUE, ITEM_SPHERE_WHITE, ITEM_INVUL] then
1936 g_Sound_PlayExAt('SOUND_ITEM_GETRULEZ', FObj.X, FObj.Y)
1937 else if ItemType in [ITEM_MEDKIT_SMALL, ITEM_MEDKIT_LARGE, ITEM_MEDKIT_BLACK] then
1938 g_Sound_PlayExAt('SOUND_ITEM_GETMED', FObj.X, FObj.Y)
1939 else g_Sound_PlayExAt('SOUND_ITEM_GETITEM', FObj.X, FObj.Y);
1941 // Íàäî óáðàòü ñ êàðòû, åñëè ýòî íå êëþ÷, êîòîðûì íóæíî ïîäåëèòñÿ ñ äðóãèì èãðîêîì:
1942 if r and not ((ItemType in [ITEM_KEY_RED, ITEM_KEY_GREEN, ITEM_KEY_BLUE]) and
1943 (gGameSettings.GameType = GT_SINGLE) and
1944 (g_Player_GetCount() > 1)) then
1945 if not Respawnable then g_Items_Remove(i) else g_Items_Pick(i);
1951 function TPlayer
.CollideLevel(XInc
, YInc
: Integer): Boolean;
1953 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
1954 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_WALL
,
1958 constructor TPlayer
.Create();
1964 FSawSound
:= TPlayableSound
.Create();
1965 FSawSoundIdle
:= TPlayableSound
.Create();
1966 FSawSoundHit
:= TPlayableSound
.Create();
1967 FSawSoundSelect
:= TPlayableSound
.Create();
1968 FJetSoundFly
:= TPlayableSound
.Create();
1969 FJetSoundOn
:= TPlayableSound
.Create();
1970 FJetSoundOff
:= TPlayableSound
.Create();
1972 FSawSound
.SetByName('SOUND_WEAPON_FIRESAW');
1973 FSawSoundIdle
.SetByName('SOUND_WEAPON_IDLESAW');
1974 FSawSoundHit
.SetByName('SOUND_WEAPON_HITSAW');
1975 FSawSoundSelect
.SetByName('SOUND_WEAPON_SELECTSAW');
1976 FJetSoundFly
.SetByName('SOUND_PLAYER_JETFLY');
1977 FJetSoundOn
.SetByName('SOUND_PLAYER_JETON');
1978 FJetSoundOff
.SetByName('SOUND_PLAYER_JETOFF');
1980 FSpectatePlayer
:= -1;
1984 FSavedState
.WaitRecall
:= False;
1987 FActualModelName
:= 'doomer';
1990 FObj
.Rect
:= PLAYER_RECT
;
1992 FBFGFireCounter
:= -1;
1993 FJustTeleported
:= False;
1999 procedure TPlayer
.Damage(value
: Word; SpawnerUID
: Word; vx
, vy
: Integer; t
: Byte);
2003 if (not g_Game_IsClient
) and (not FLive
) then
2008 // Íåóÿçâèìîñòü íå ñïàñàåò îò ëîâóøåê:
2009 if ((t
= HIT_TRAP
) or (t
= HIT_SELF
)) and (not FGodMode
) then
2011 if not g_Game_IsClient
then
2014 if t
= HIT_TRAP
then
2016 // Ëîâóøêà óáèâàåò ñðàçó:
2018 Kill(K_EXTRAHARDKILL
, SpawnerUID
, t
);
2020 if t
= HIT_SELF
then
2024 Kill(K_SIMPLEKILL
, SpawnerUID
, t
);
2027 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
2028 FMegaRulez
[MR_SUIT
] := 0;
2029 FMegaRulez
[MR_INVUL
] := 0;
2030 FMegaRulez
[MR_INVIS
] := 0;
2034 // Íî îò îñòàëüíîãî ñïàñàåò:
2035 if FMegaRulez
[MR_INVUL
] >= gTime
then
2042 // Åñëè åñòü óðîí ñâîèì, èëè ðàíèë ñàì ñåáÿ, èëè òåáÿ ðàíèë ïðîòèâíèê:
2043 if LongBool(gGameSettings
.Options
and GAME_OPTION_TEAMDAMAGE
) or
2044 (SpawnerUID
= FUID
) or
2045 (not SameTeam(FUID
, SpawnerUID
)) then
2047 FLastSpawnerUID
:= SpawnerUID
;
2049 // Êðîâü (ïóçûðüêè, åñëè â âîäå):
2050 if gBloodCount
> 0 then
2052 c
:= Min(value
, 200)*gBloodCount
+ Random(Min(value
, 200) div 2);
2053 if value
div 4 <= c
then
2054 c
:= c
- (value
div 4)
2058 if (t
= HIT_SOME
) and (vx
= 0) and (vy
= 0) then
2062 HIT_TRAP
, HIT_ACID
, HIT_FLAME
, HIT_SELF
: MakeBloodSimple(c
);
2063 HIT_BFG
, HIT_ROCKET
, HIT_SOME
: MakeBloodVector(c
, vx
, vy
);
2066 if t
= HIT_WATER
then
2067 g_GFX_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
2068 FObj
.Y
+PLAYER_RECT
.Y
-4, value
div 2, 8, 4);
2073 Inc(FDamageBuffer
, value
);
2077 FPain
:= FPain
+ value
;
2080 if g_Game_IsServer
and g_Game_IsNet
then
2082 MH_SEND_PlayerDamage(FUID
, t
, SpawnerUID
, value
, vx
, vy
);
2083 MH_SEND_PlayerStats(FUID
);
2084 MH_SEND_PlayerPos(False, FUID
);
2088 function TPlayer
.Heal(value
: Word; Soft
: Boolean): Boolean;
2091 if g_Game_IsClient
then
2096 if Soft
and (FHealth
< PLAYER_HP_SOFT
) then
2098 IncMax(FHealth
, value
, PLAYER_HP_SOFT
);
2101 if (not Soft
) and (FHealth
< PLAYER_HP_LIMIT
) then
2103 IncMax(FHealth
, value
, PLAYER_HP_LIMIT
);
2107 if Result
and g_Game_IsServer
and g_Game_IsNet
then
2108 MH_SEND_PlayerStats(FUID
);
2111 destructor TPlayer
.Destroy();
2113 if (gPlayer1
<> nil) and (gPlayer1
.FUID
= FUID
) then
2115 if (gPlayer2
<> nil) and (gPlayer2
.FUID
= FUID
) then
2119 FSawSoundIdle
.Free();
2120 FSawSoundHit
.Free();
2121 FJetSoundFly
.Free();
2123 FJetSoundOff
.Free();
2129 procedure TPlayer
.DrawBubble();
2131 bubX
, bubY
: Integer;
2134 Rw
, Gw
, Bw
: SmallInt;
2137 bubX
:= FObj
.X
+FObj
.Rect
.X
+ IfThen(FDirection
= D_LEFT
, -4, 18);
2138 bubY
:= FObj
.Y
+FObj
.Rect
.Y
- 18;
2146 1: // simple textual non-bubble
2148 bubX
:= FObj
.X
+FObj
.Rect
.X
- 11;
2149 bubY
:= FObj
.Y
+FObj
.Rect
.Y
- 17;
2150 e_TextureFontPrint(bubX
, bubY
, '[...]', gStdFont
);
2153 2: // advanced pixel-perfect bubble
2155 if FTeam
= TEAM_RED
then
2158 if FTeam
= TEAM_BLUE
then
2161 3: // colored bubble
2163 Rb
:= FModel
.Color
.R
;
2164 Gb
:= FModel
.Color
.G
;
2165 Bb
:= FModel
.Color
.B
;
2166 Rw
:= Min(Rb
* 2 + 64, 255);
2167 Gw
:= Min(Gb
* 2 + 64, 255);
2168 Bw
:= Min(Bb
* 2 + 64, 255);
2169 if (Abs(Rw
- Rb
) < 32)
2170 or (Abs(Gw
- Gb
) < 32)
2171 or (Abs(Bw
- Bb
) < 32) then
2173 Rb
:= Max(Rw
div 2 - 16, 0);
2174 Gb
:= Max(Gw
div 2 - 16, 0);
2175 Bb
:= Max(Bw
div 2 - 16, 0);
2178 4: // custom textured bubble
2180 if g_Texture_Get('TEXTURE_PLAYER_TALKBUBBLE', ID
) then
2181 if FDirection
= D_RIGHT
then
2182 e_Draw(ID
, bubX
- 6, bubY
- 7, 0, True, False)
2184 e_Draw(ID
, bubX
- 6, bubY
- 7, 0, True, False, M_HORIZONTAL
);
2190 e_DrawQuad(bubX
+ 1, bubY
, bubX
+ 18, bubY
+ 13, Rb
, Gb
, Bb
);
2191 e_DrawQuad(bubX
, bubY
+ 1, bubX
+ 19, bubY
+ 12, Rb
, Gb
, Bb
);
2193 e_DrawFillQuad(bubX
+ 1, bubY
+ 1, bubX
+ 18, bubY
+ 12, Rw
, Gw
, Bw
, 0);
2196 Dot
:= IfThen(FDirection
= D_LEFT
, 14, 5);
2197 e_DrawLine(1, bubX
+ Dot
, bubY
+ 14, bubX
+ Dot
, bubY
+ 16, Rb
, Gb
, Bb
);
2198 e_DrawLine(1, bubX
+ IfThen(FDirection
= D_LEFT
, Dot
- 1, Dot
+ 1), bubY
+ 13, bubX
+ IfThen(FDirection
= D_LEFT
, Dot
- 1, Dot
+ 1), bubY
+ 15, Rw
, Gw
, Bw
);
2199 e_DrawLine(1, bubX
+ IfThen(FDirection
= D_LEFT
, Dot
- 2, Dot
+ 2), bubY
+ 13, bubX
+ IfThen(FDirection
= D_LEFT
, Dot
- 2, Dot
+ 2), bubY
+ 14, Rw
, Gw
, Bw
);
2200 e_DrawLine(1, bubX
+ IfThen(FDirection
= D_LEFT
, Dot
- 3, Dot
+ 3), bubY
+ 13, bubX
+ IfThen(FDirection
= D_LEFT
, Dot
- 3, Dot
+ 3), bubY
+ 13, Rw
, Gw
, Bw
);
2201 e_DrawLine(1, bubX
+ IfThen(FDirection
= D_LEFT
, Dot
- 3, Dot
+ 3), bubY
+ 14, bubX
+ IfThen(FDirection
= D_LEFT
, Dot
- 1, Dot
+ 1), bubY
+ 16, Rb
, Gb
, Bb
);
2205 e_DrawFillQuad(bubX
+ Dot
, bubY
+ 8, bubX
+ Dot
+ 1, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2206 e_DrawFillQuad(bubX
+ Dot
+ 3, bubY
+ 8, bubX
+ Dot
+ 4, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2207 e_DrawFillQuad(bubX
+ Dot
+ 6, bubY
+ 8, bubX
+ Dot
+ 7, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2210 procedure TPlayer
.Draw();
2218 if (FMegaRulez
[MR_INVUL
] > gTime
) and (gPlayerDrawn
<> Self
) then
2219 if g_Texture_Get('TEXTURE_PLAYER_INVULPENTA', ID
) then
2221 e_GetTextureSize(ID
, @w
, @h
);
2222 if FDirection
= D_LEFT
then
2223 e_Draw(ID
, FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2)-(w
div 2)+4,
2224 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2)-(h
div 2)-7, 0, True, False)
2226 e_Draw(ID
, FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2)-(w
div 2)-2,
2227 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2)-(h
div 2)-7, 0, True, False);
2230 if FMegaRulez
[MR_INVIS
] > gTime
then
2232 if (gPlayerDrawn
<> nil) and ((Self
= gPlayerDrawn
) or
2233 ((FTeam
= gPlayerDrawn
.Team
) and (gGameSettings
.GameMode
<> GM_DM
))) then
2235 if (FMegaRulez
[MR_INVIS
] - gTime
) <= 2100 then
2236 dr
:= not Odd((FMegaRulez
[MR_INVIS
] - gTime
) div 300)
2240 FModel
.Draw(FObj
.X
, FObj
.Y
, 200)
2242 FModel
.Draw(FObj
.X
, FObj
.Y
);
2245 FModel
.Draw(FObj
.X
, FObj
.Y
, 254);
2248 FModel
.Draw(FObj
.X
, FObj
.Y
);
2251 if g_debug_Frames
then
2253 e_DrawQuad(FObj
.X
+FObj
.Rect
.X
,
2255 FObj
.X
+FObj
.Rect
.X
+FObj
.Rect
.Width
-1,
2256 FObj
.Y
+FObj
.Rect
.Y
+FObj
.Rect
.Height
-1,
2260 if (gChatBubble
> 0) and (FKeys
[KEY_CHAT
].Pressed
) and not FGhost
then
2262 // e_DrawPoint(5, 335, 288, 255, 0, 0); // DL, UR, DL, UR
2263 if gAimLine
and Live
and
2264 ((Self
= gPlayer1
) or (Self
= gPlayer2
)) then
2268 procedure TPlayer
.DrawAim();
2270 wx
, wy
, xx
, yy
: Integer;
2274 wx
:= FObj
.X
+ WEAPONPOINT
[FDirection
].X
+ IfThen(FDirection
= D_LEFT
, 7, -7);
2275 wy
:= FObj
.Y
+ WEAPONPOINT
[FDirection
].Y
;
2284 1: begin // Chainsaw
2291 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2292 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2293 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2294 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2299 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2300 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2301 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2302 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2304 4: begin // Double Shotgun
2307 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2308 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2309 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2310 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2312 5: begin // Chaingun
2315 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2316 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2317 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2318 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2320 6: begin // Rocket Launcher
2323 if angle
= ANGLE_RIGHTUP
then Inc(angle
, 2);
2324 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2325 if angle
= ANGLE_LEFTUP
then Dec(angle
, 2);
2326 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2328 7: begin // Plasmagun
2331 if angle
= ANGLE_RIGHTUP
then Inc(angle
);
2332 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 3);
2333 if angle
= ANGLE_LEFTUP
then Dec(angle
);
2334 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 3);
2339 if angle
= ANGLE_RIGHTUP
then Inc(angle
, 1);
2340 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 2);
2341 if angle
= ANGLE_LEFTUP
then Dec(angle
, 1);
2342 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 2);
2344 9: begin // Super Chaingun
2347 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2348 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2349 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2350 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2353 xx
:= Trunc(Cos(-DegToRad(angle
)) * len
) + wx
;
2354 yy
:= Trunc(Sin(-DegToRad(angle
)) * len
) + wy
;
2355 e_DrawLine(sz
, wx
, wy
, xx
, yy
, 255, 0, 0, 96);
2358 procedure TPlayer
.DrawGUI();
2361 X
, Y
, SY
, a
, p
, m
: Integer;
2365 stat
: TPlayerStatArray
;
2367 X
:= gPlayerScreenSize
.X
;
2368 SY
:= gPlayerScreenSize
.Y
;
2371 if gShowGoals
and (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
2373 if gGameSettings
.GameMode
= GM_CTF
then
2377 if gGameSettings
.GameMode
= GM_CTF
then
2379 s
:= 'TEXTURE_PLAYER_REDFLAG';
2380 if gFlags
[FLAG_RED
].State
= FLAG_STATE_CAPTURED
then
2381 s
:= 'TEXTURE_PLAYER_REDFLAG_S';
2382 if gFlags
[FLAG_RED
].State
= FLAG_STATE_DROPPED
then
2383 s
:= 'TEXTURE_PLAYER_REDFLAG_D';
2384 if g_Texture_Get(s
, ID
) then
2385 e_Draw(ID
, X
-16-32, 240-72-4, 0, True, False);
2388 s
:= IntToStr(gTeamStat
[TEAM_RED
].Goals
);
2389 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2390 e_CharFont_PrintEx(gMenuFont
, X
-16-a
-tw
, 240-72-4, s
, TEAMCOLOR
[TEAM_RED
]);
2392 if gGameSettings
.GameMode
= GM_CTF
then
2394 s
:= 'TEXTURE_PLAYER_BLUEFLAG';
2395 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_CAPTURED
then
2396 s
:= 'TEXTURE_PLAYER_BLUEFLAG_S';
2397 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_DROPPED
then
2398 s
:= 'TEXTURE_PLAYER_BLUEFLAG_D';
2399 if g_Texture_Get(s
, ID
) then
2400 e_Draw(ID
, X
-16-32, 240-32-4, 0, True, False);
2403 s
:= IntToStr(gTeamStat
[TEAM_BLUE
].Goals
);
2404 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2405 e_CharFont_PrintEx(gMenuFont
, X
-16-a
-tw
, 240-32-4, s
, TEAMCOLOR
[TEAM_BLUE
]);
2408 if g_Texture_Get('TEXTURE_PLAYER_HUDBG', ID
) then
2409 e_DrawFill(ID
, X
, 0, 1, (gPlayerScreenSize
.Y
div 256)+IfThen(gPlayerScreenSize
.Y
mod 256 > 0, 1, 0),
2412 if g_Texture_Get('TEXTURE_PLAYER_HUD', ID
) then
2413 e_Draw(ID
, X
+2, Y
, 0, True, False);
2415 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
2419 s
:= IntToStr(Frags
);
2420 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2421 e_CharFont_PrintEx(gMenuFont
, X
-16-tw
, Y
, s
, _RGB(255, 0, 0));
2426 stat
:= g_Player_GetStats();
2431 for a
:= 0 to High(stat
) do
2432 if stat
[a
].Name
<> Name
then
2434 if stat
[a
].Frags
> m
then m
:= stat
[a
].Frags
;
2435 if stat
[a
].Frags
> Frags
then p
:= p
+1;
2439 s
:= IntToStr(p
)+' / '+IntToStr(Length(stat
))+' ';
2440 if Frags
>= m
then s
:= s
+'+' else s
:= s
+'-';
2441 s
:= s
+IntToStr(Abs(Frags
-m
));
2443 e_CharFont_GetSize(gMenuSmallFont
, s
, tw
, th
);
2444 e_CharFont_PrintEx(gMenuSmallFont
, X
-16-tw
, Y
+32, s
, _RGB(255, 0, 0));
2447 if gShowLives
and (gGameSettings
.MaxLives
> 0) then
2449 s
:= IntToStr(Lives
);
2450 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2451 e_CharFont_PrintEx(gMenuFont
, X
-16-tw
, SY
-32, s
, _RGB(0, 255, 0));
2455 e_CharFont_GetSize(gMenuSmallFont
, FName
, tw
, th
);
2456 e_CharFont_PrintEx(gMenuSmallFont
, X
+98-(tw
div 2), Y
+8, FName
, _RGB(255, 0, 0));
2458 if R_BERSERK
in FRulez
then
2459 e_Draw(gItemsTexturesID
[ITEM_MEDKIT_BLACK
], X
+37, Y
+45, 0, True, False)
2461 e_Draw(gItemsTexturesID
[ITEM_MEDKIT_LARGE
], X
+37, Y
+45, 0, True, False);
2463 if g_Texture_Get('TEXTURE_PLAYER_ARMORHUD', ID
) then
2464 e_Draw(ID
, X
+36, Y
+77, 0, True, False);
2466 s
:= IntToStr(IfThen(FHealth
> 0, FHealth
, 0));
2467 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2468 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+40, s
, _RGB(255, 0, 0));
2470 s
:= IntToStr(FArmor
);
2471 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2472 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+68, s
, _RGB(255, 0, 0));
2474 s
:= IntToStr(GetAmmoByWeapon(FCurrWeap
));
2480 ID
:= gItemsTexturesID
[ITEM_WEAPON_KASTET
];
2485 ID
:= gItemsTexturesID
[ITEM_WEAPON_SAW
];
2487 WEAPON_PISTOL
: ID
:= gItemsTexturesID
[ITEM_WEAPON_PISTOL
];
2488 WEAPON_CHAINGUN
: ID
:= gItemsTexturesID
[ITEM_WEAPON_CHAINGUN
];
2489 WEAPON_SHOTGUN1
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SHOTGUN1
];
2490 WEAPON_SHOTGUN2
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SHOTGUN2
];
2491 WEAPON_SUPERPULEMET
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SUPERPULEMET
];
2492 WEAPON_ROCKETLAUNCHER
: ID
:= gItemsTexturesID
[ITEM_WEAPON_ROCKETLAUNCHER
];
2493 WEAPON_PLASMA
: ID
:= gItemsTexturesID
[ITEM_WEAPON_PLASMA
];
2494 WEAPON_BFG
: ID
:= gItemsTexturesID
[ITEM_WEAPON_BFG
];
2497 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2498 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+158, s
, _RGB(255, 0, 0));
2499 e_Draw(ID
, X
+20, Y
+160, 0, True, False);
2501 if R_KEY_RED
in FRulez
then
2502 e_Draw(gItemsTexturesID
[ITEM_KEY_RED
], X
+78, Y
+214, 0, True, False);
2504 if R_KEY_GREEN
in FRulez
then
2505 e_Draw(gItemsTexturesID
[ITEM_KEY_GREEN
], X
+95, Y
+214, 0, True, False);
2507 if R_KEY_BLUE
in FRulez
then
2508 e_Draw(gItemsTexturesID
[ITEM_KEY_BLUE
], X
+112, Y
+214, 0, True, False);
2510 if FJetFuel
> 0 then
2512 if g_Texture_Get('TEXTURE_PLAYER_HUDAIR', ID
) then
2513 e_Draw(ID
, X
+2, Y
+116, 0, True, False);
2514 if g_Texture_Get('TEXTURE_PLAYER_HUDJET', ID
) then
2515 e_Draw(ID
, X
+2, Y
+126, 0, True, False);
2516 e_DrawLine(4, X
+16, Y
+122, X
+16+Trunc(168*IfThen(FAir
> 0, FAir
, 0)/AIR_MAX
), Y
+122, 0, 0, 196);
2517 e_DrawLine(4, X
+16, Y
+132, X
+16+Trunc(168*FJetFuel
/JET_MAX
), Y
+132, 208, 0, 0);
2521 if g_Texture_Get('TEXTURE_PLAYER_HUDAIR', ID
) then
2522 e_Draw(ID
, X
+2, Y
+124, 0, True, False);
2523 e_DrawLine(4, X
+16, Y
+130, X
+16+Trunc(168*IfThen(FAir
> 0, FAir
, 0)/AIR_MAX
), Y
+130, 0, 0, 196);
2526 if gShowPing
and g_Game_IsClient
then
2528 s
:= _lc
[I_GAME_PING_HUD
] + IntToStr(NetPeer
.lastRoundTripTime
) + _lc
[I_NET_SLIST_PING_MS
];
2529 e_TextureFontPrint(X
+ 4, Y
+ 242, s
, gStdFont
);
2535 e_TextureFontPrint(X
+ 4, Y
+ 242, _lc
[I_PLAYER_SPECT
], gStdFont
);
2536 e_TextureFontPrint(X
+ 4, Y
+ 258, _lc
[I_PLAYER_SPECT2
], gStdFont
);
2537 e_TextureFontPrint(X
+ 4, Y
+ 274, _lc
[I_PLAYER_SPECT1
], gStdFont
);
2540 e_TextureFontGetSize(gStdFont
, cw
, ch
);
2541 s
:= _lc
[I_PLAYER_SPECT4
];
2542 e_TextureFontPrintEx(gScreenWidth
div 2 - cw
*(Length(s
) div 2),
2543 gScreenHeight
-4-ch
, s
, gStdFont
, 255, 255, 255, 1, True);
2544 e_TextureFontPrint(X
+ 4, Y
+ 290, _lc
[I_PLAYER_SPECT1S
], gStdFont
);
2550 procedure TPlayer
.DrawRulez();
2554 // Ïðè âçÿòèè íåóÿçâèìîñòè ðèñóåòñÿ èíâåðñèîííûé áåëûé ôîí
2555 if FMegaRulez
[MR_INVUL
] >= gTime
then
2557 if (FMegaRulez
[MR_INVUL
]-gTime
) <= 2100 then
2558 dr
:= not Odd((FMegaRulez
[MR_INVUL
]-gTime
) div 300)
2563 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2564 191, 191, 191, 0, B_INVERT
);
2567 // Ïðè âçÿòèè çàùèòíîãî êîñòþìà ðèñóåòñÿ çåëåíîâàòûé ôîí
2568 if FMegaRulez
[MR_SUIT
] >= gTime
then
2570 if (FMegaRulez
[MR_SUIT
]-gTime
) <= 2100 then
2571 dr
:= not Odd((FMegaRulez
[MR_SUIT
]-gTime
) div 300)
2576 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2577 0, 96, 0, 200, B_NONE
);
2580 // Ïðè âçÿòèè áåðñåðêà ðèñóåòñÿ êðàñíîâàòûé ôîí
2581 if (FBerserk
>= 0) and (LongWord(FBerserk
) >= gTime
) and (gFlash
= 2) then
2583 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2584 255, 0, 0, 200, B_NONE
);
2588 procedure TPlayer
.DrawPain();
2592 if FPain
= 0 then Exit
;
2596 if a
< 15 then h
:= 0
2597 else if a
< 35 then h
:= 1
2598 else if a
< 55 then h
:= 2
2599 else if a
< 75 then h
:= 3
2600 else if a
< 95 then h
:= 4
2603 //if a > 255 then a := 255;
2605 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1, 255, 0, 0, 255-h
*50);
2606 //e_DrawFillQuad(0, 0, gPlayerScreenSize.X-1, gPlayerScreenSize.Y-1, 255-min(128, a), 255-a, 255-a, 0, B_FILTER);
2609 procedure TPlayer
.DrawPickup();
2613 if FPickup
= 0 then Exit
;
2617 if a
< 15 then h
:= 1
2618 else if a
< 35 then h
:= 2
2619 else if a
< 55 then h
:= 3
2620 else if a
< 75 then h
:= 4
2623 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1, 150, 200, 150, 255-h
*50);
2626 procedure TPlayer
.Fire();
2628 f
, DidFire
: Boolean;
2629 wx
, wy
, xd
, yd
: Integer;
2632 if g_Game_IsClient
then Exit
;
2633 // FBFGFireCounter - âðåìÿ ïåðåä âûñòðåëîì (äëÿ BFG)
2634 // FReloading - âðåìÿ ïîñëå âûñòðåëà (äëÿ âñåãî)
2642 if FReloading
[FCurrWeap
] <> 0 then Exit
;
2647 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
2648 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
2649 xd
:= wx
+IfThen(FDirection
= D_LEFT
, -30, 30);
2650 yd
:= wy
+firediry();
2655 if R_BERSERK
in FRulez
then
2657 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
2658 obj
.X
:= FObj
.X
+FObj
.Rect
.X
;
2659 obj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
2662 obj
.rect
.Width
:= 39;
2663 obj
.rect
.Height
:= 52;
2664 obj
.Vel
.X
:= (xd
-wx
) div 2;
2665 obj
.Vel
.Y
:= (yd
-wy
) div 2;
2666 obj
.Accel
.X
:= xd
-wx
;
2667 obj
.Accel
.y
:= yd
-wy
;
2669 if g_Weapon_Hit(@obj
, 50, FUID
, HIT_SOME
) <> 0 then
2670 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
2672 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
2676 FPain
:= min(FPain
+ 25, 50);
2677 end else g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
2680 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2685 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
2686 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
2688 FSawSoundSelect
.Stop();
2690 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
2692 else if not FSawSoundHit
.IsPlaying() then
2694 FSawSoundSelect
.Stop();
2695 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
2698 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2704 if FAmmo
[A_BULLETS
] > 0 then
2706 g_Weapon_pistol(wx
, wy
, xd
, yd
, FUID
);
2707 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2708 Dec(FAmmo
[A_BULLETS
]);
2709 FFireAngle
:= FAngle
;
2712 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
2713 GameVelX
, GameVelY
-2, SHELL_BULLET
);
2717 if FAmmo
[A_SHELLS
] > 0 then
2719 g_Weapon_shotgun(wx
, wy
, xd
, yd
, FUID
);
2720 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', wx
, wy
);
2721 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2722 Dec(FAmmo
[A_SHELLS
]);
2723 FFireAngle
:= FAngle
;
2727 FShellType
:= SHELL_SHELL
;
2731 if FAmmo
[A_SHELLS
] >= 2 then
2733 g_Weapon_dshotgun(wx
, wy
, xd
, yd
, FUID
);
2734 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2735 Dec(FAmmo
[A_SHELLS
], 2);
2736 FFireAngle
:= FAngle
;
2740 FShellType
:= SHELL_DBLSHELL
;
2744 if FAmmo
[A_BULLETS
] > 0 then
2746 g_Weapon_mgun(wx
, wy
, xd
, yd
, FUID
);
2747 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', wx
, wy
);
2748 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2749 Dec(FAmmo
[A_BULLETS
]);
2750 FFireAngle
:= FAngle
;
2753 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
2754 GameVelX
, GameVelY
-2, SHELL_BULLET
);
2757 WEAPON_ROCKETLAUNCHER
:
2758 if FAmmo
[A_ROCKETS
] > 0 then
2760 g_Weapon_rocket(wx
, wy
, xd
, yd
, FUID
);
2761 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2762 Dec(FAmmo
[A_ROCKETS
]);
2763 FFireAngle
:= FAngle
;
2769 if FAmmo
[A_CELLS
] > 0 then
2771 g_Weapon_plasma(wx
, wy
, xd
, yd
, FUID
);
2772 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2773 Dec(FAmmo
[A_CELLS
]);
2774 FFireAngle
:= FAngle
;
2780 if (FAmmo
[A_CELLS
] >= 40) and (FBFGFireCounter
= -1) then
2782 FBFGFireCounter
:= 17;
2783 if not FNoReload
then
2784 g_Sound_PlayExAt('SOUND_WEAPON_STARTFIREBFG', FObj
.X
, FObj
.Y
);
2785 Dec(FAmmo
[A_CELLS
], 40);
2789 WEAPON_SUPERPULEMET
:
2790 if FAmmo
[A_SHELLS
] > 0 then
2792 g_Weapon_shotgun(wx
, wy
, xd
, yd
, FUID
);
2793 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', wx
, wy
);
2794 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2795 Dec(FAmmo
[A_SHELLS
]);
2796 FFireAngle
:= FAngle
;
2799 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
2800 GameVelX
, GameVelY
-2, SHELL_SHELL
);
2804 if g_Game_IsNet
then
2808 if FCurrWeap
<> WEAPON_BFG
then
2809 MH_SEND_PlayerFire(FUID
, FCurrWeap
, wx
, wy
, xd
, yd
, LastShotID
)
2811 if not FNoReload
then
2812 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_WEAPON_STARTFIREBFG');
2815 MH_SEND_PlayerStats(FUID
);
2820 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
2821 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
2822 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
2825 function TPlayer
.GetAmmoByWeapon(Weapon
: Byte): Word;
2828 WEAPON_PISTOL
, WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
];
2829 WEAPON_SHOTGUN1
, WEAPON_SHOTGUN2
, WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
];
2830 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
];
2831 WEAPON_PLASMA
, WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
];
2836 function TPlayer
.HeadInLiquid(XInc
, YInc
: Integer): Boolean;
2838 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
+XInc
, FObj
.Y
+PLAYER_HEADRECT
.Y
+YInc
,
2839 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
2840 PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, True);
2843 procedure TPlayer
.JetpackOn
;
2847 FJetSoundOn
.SetPosition(0);
2848 FJetSoundOn
.PlayAt(FObj
.X
, FObj
.Y
);
2852 procedure TPlayer
.JetpackOff
;
2856 FJetSoundOff
.SetPosition(0);
2857 FJetSoundOff
.PlayAt(FObj
.X
, FObj
.Y
);
2860 procedure TPlayer
.Jump();
2862 if gFly
or FJetpack
then
2864 // Ïîëåò (÷èò-êîä èëè äæåòïàê):
2865 if FObj
.Vel
.Y
> -VEL_FLY
then
2866 FObj
.Vel
.Y
:= FObj
.Vel
.Y
- 3;
2869 if FJetFuel
> 0 then
2871 if (FJetFuel
< 1) and g_Game_IsServer
then
2875 if g_Game_IsNet
then
2876 MH_SEND_PlayerStats(FUID
);
2882 // Íå âêëþ÷àòü äæåòïàê â ðåæèìå ïðîõîæäåíèÿ ñêâîçü ñòåíû
2884 FCanJetpack
:= False;
2886 // Ïðûãàåì èëè âñïëûâàåì:
2887 if (CollideLevel(0, 1) or
2888 g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
+36, PLAYER_RECT
.Width
,
2889 PLAYER_RECT
.Height
-33, PANEL_STEP
, False)
2890 ) and (FObj
.Accel
.Y
= 0) then // Íå ïðûãàòü, åñëè åñòü âåðòèêàëüíîå óñêîðåíèå
2892 FObj
.Vel
.Y
:= -VEL_JUMP
;
2893 FCanJetpack
:= False;
2897 if BodyInLiquid(0, 0) then
2898 FObj
.Vel
.Y
:= -VEL_SW
2899 else if (FJetFuel
> 0) and FCanJetpack
and
2900 g_Game_IsServer
and (not g_Obj_CollideLiquid(@FObj
, 0, 0)) then
2904 if g_Game_IsNet
then
2905 MH_SEND_PlayerStats(FUID
);
2910 procedure TPlayer
.Kill(KillType
: Byte; SpawnerUID
: Word; t
: Byte);
2912 a
, i
, k
, ab
, ar
: Byte;
2916 srv
, netsrv
: Boolean;
2921 procedure PushItem(t
: Byte);
2925 id
:= g_Items_Create(FObj
.X
, FObj
.Y
, t
, True, False);
2926 if KillType
= K_EXTRAHARDKILL
then // -7..+7; -8..0
2927 g_Obj_Push(@gItems
[id
].Obj
, (FObj
.Vel
.X
div 2)-7+Random(15),
2928 (FObj
.Vel
.Y
div 2)-Random(9))
2930 if KillType
= K_HARDKILL
then // -5..+5; -5..0
2931 g_Obj_Push(@gItems
[id
].Obj
, (FObj
.Vel
.X
div 2)-5+Random(11),
2932 (FObj
.Vel
.Y
div 2)-Random(6))
2933 else // -3..+3; -3..0
2934 g_Obj_Push(@gItems
[id
].Obj
, (FObj
.Vel
.X
div 2)-3+Random(7),
2935 (FObj
.Vel
.Y
div 2)-Random(4));
2937 if g_Game_IsNet
and g_Game_IsServer
then
2938 MH_SEND_ItemSpawn(True, id
);
2942 DoFrags
:= (gGameSettings
.MaxLives
= 0) or (gGameSettings
.GameMode
= GM_COOP
);
2943 Srv
:= g_Game_IsServer
;
2944 Netsrv
:= g_Game_IsServer
and g_Game_IsNet
;
2945 if Srv
then FDeath
:= FDeath
+ 1;
2950 if not FPhysics
then
2956 if (gGameSettings
.MaxLives
> 0) and Srv
and (gLMSRespawn
= LMS_RESPAWN_NONE
) then
2958 if FLives
> 0 then FLives
:= FLives
- 1;
2959 if FLives
= 0 then FNoRespawn
:= True;
2962 // Íîìåð òèïà ñìåðòè:
2965 K_SIMPLEKILL
: a
:= 1;
2967 K_EXTRAHARDKILL
: a
:= 3;
2972 if not FModel
.PlaySound(MODELSOUND_DIE
, a
, FObj
.X
, FObj
.Y
) then
2974 if FModel
.PlaySound(MODELSOUND_DIE
, i
, FObj
.X
, FObj
.Y
) then
2981 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN1
;
2983 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN2
;
2984 K_EXTRAHARDKILL
, K_FALLKILL
:
2985 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN3
;
2988 // Ïåðåêëþ÷àåì ñîñòîÿíèå:
2992 K_HARDKILL
, K_EXTRAHARDKILL
:
2996 // Ðåàêöèÿ ìîíñòðîâ íà ñìåðòü èãðîêà:
2997 if (KillType
<> K_FALLKILL
) and (Srv
) then
2998 g_Monsters_killedp();
3000 if SpawnerUID
= FUID
then
3002 if Srv
and (DoFrags
or (gGameSettings
.GameMode
= GM_TDM
)) then
3007 g_Console_Add(Format(_lc
[I_PLAYER_KILL_SELF
], [FName
]), True);
3010 if g_GetUIDType(SpawnerUID
) = UID_PLAYER
then
3011 begin // Óáèò äðóãèì èãðîêîì
3012 KP
:= g_Player_Get(SpawnerUID
);
3013 if (KP
<> nil) and Srv
then
3015 if (DoFrags
or (gGameSettings
.GameMode
= GM_TDM
)) then
3016 if SameTeam(FUID
, SpawnerUID
) then
3026 if (gGameSettings
.GameMode
= GM_TDM
) and DoFrags
then
3027 Inc(gTeamStat
[KP
.Team
].Goals
,
3028 IfThen(SameTeam(FUID
, SpawnerUID
), -1, 1));
3030 if netsrv
then MH_SEND_PlayerStats(SpawnerUID
);
3033 plr
:= g_Player_Get(SpawnerUID
);
3041 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_2
],
3045 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_1
],
3049 g_Console_Add(Format(_lc
[I_PLAYER_KILL
],
3054 else if g_GetUIDType(SpawnerUID
) = UID_MONSTER
then
3055 begin // Óáèò ìîíñòðîì
3056 mon
:= g_Monsters_Get(SpawnerUID
);
3060 s
:= g_Monsters_GetKilledBy(mon
.MonsterType
);
3064 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_2
],
3068 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_1
],
3072 g_Console_Add(Format(_lc
[I_PLAYER_KILL
],
3077 else // Îñîáûå òèïû ñìåðòè
3080 HIT_SELF
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_SELF
], [FName
]), True);
3081 HIT_FALL
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_FALL
], [FName
]), True);
3082 HIT_WATER
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_WATER
], [FName
]), True);
3083 HIT_ACID
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_ACID
], [FName
]), True);
3084 HIT_TRAP
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_TRAP
], [FName
]), True);
3085 else g_Console_Add(Format(_lc
[I_PLAYER_DIED
], [FName
]), True);
3091 for a
:= WP_FIRST
to WP_LAST
do
3095 WEAPON_SAW
: i
:= ITEM_WEAPON_SAW
;
3096 WEAPON_SHOTGUN1
: i
:= ITEM_WEAPON_SHOTGUN1
;
3097 WEAPON_SHOTGUN2
: i
:= ITEM_WEAPON_SHOTGUN2
;
3098 WEAPON_CHAINGUN
: i
:= ITEM_WEAPON_CHAINGUN
;
3099 WEAPON_ROCKETLAUNCHER
: i
:= ITEM_WEAPON_ROCKETLAUNCHER
;
3100 WEAPON_PLASMA
: i
:= ITEM_WEAPON_PLASMA
;
3101 WEAPON_BFG
: i
:= ITEM_WEAPON_BFG
;
3102 WEAPON_SUPERPULEMET
: i
:= ITEM_WEAPON_SUPERPULEMET
;
3111 if R_ITEM_BACKPACK
in FRulez
then
3112 PushItem(ITEM_AMMO_BACKPACK
);
3114 // Âûáðîñ ðàêåòíîãî ðàíöà:
3115 if FJetFuel
> 0 then
3116 PushItem(ITEM_JETPACK
);
3119 if not (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
]) then
3121 if R_KEY_RED
in FRulez
then
3122 PushItem(ITEM_KEY_RED
);
3124 if R_KEY_GREEN
in FRulez
then
3125 PushItem(ITEM_KEY_GREEN
);
3127 if R_KEY_BLUE
in FRulez
then
3128 PushItem(ITEM_KEY_BLUE
);
3135 g_Player_CreateCorpse(Self
);
3137 if Srv
and (gGameSettings
.MaxLives
> 0) and FNoRespawn
and
3138 (gLMSRespawn
= LMS_RESPAWN_NONE
) then
3144 for i
:= Low(gPlayers
) to High(gPlayers
) do
3146 if gPlayers
[i
] = nil then continue
;
3147 if (not gPlayers
[i
].FNoRespawn
) and (not gPlayers
[i
].FSpectator
) then
3150 if gPlayers
[i
].FTeam
= TEAM_RED
then Inc(ar
)
3151 else if gPlayers
[i
].FTeam
= TEAM_BLUE
then Inc(ab
);
3156 OldLR
:= gLMSRespawn
;
3157 if (gGameSettings
.GameMode
= GM_COOP
) then
3161 // everyone is dead, restart the map
3162 g_Game_Message(_lc
[I_MESSAGE_LMS_LOSE
], 144);
3164 MH_SEND_GameEvent(NET_EV_LMS_LOSE
);
3165 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3166 gLMSRespawnTime
:= gTime
+ 5000;
3168 else if (a
= 1) then
3170 if (gPlayers
[k
] <> nil) and not (gPlayers
[k
] is TBot
) then
3171 if (gPlayers
[k
] = gPlayer1
) or
3172 (gPlayers
[k
] = gPlayer2
) then
3173 g_Console_Add('*** ' + _lc
[I_MESSAGE_LMS_SURVIVOR
] + ' ***', True)
3174 else if Netsrv
and (gPlayers
[k
].FClientID
>= 0) then
3175 MH_SEND_GameEvent(NET_EV_LMS_SURVIVOR
, 0, 'N', gPlayers
[k
].FClientID
);
3178 else if (gGameSettings
.GameMode
= GM_TDM
) then
3180 if (ab
= 0) and (ar
<> 0) then
3183 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 144);
3185 MH_SEND_GameEvent(NET_EV_TLMS_WIN
, TEAM_RED
);
3186 Inc(gTeamStat
[TEAM_RED
].Goals
);
3187 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3188 gLMSRespawnTime
:= gTime
+ 5000;
3190 else if (ar
= 0) and (ab
<> 0) then
3193 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 144);
3195 MH_SEND_GameEvent(NET_EV_TLMS_WIN
, TEAM_BLUE
);
3196 Inc(gTeamStat
[TEAM_BLUE
].Goals
);
3197 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3198 gLMSRespawnTime
:= gTime
+ 5000;
3200 else if (ar
= 0) and (ab
= 0) then
3203 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
3205 MH_SEND_GameEvent(NET_EV_LMS_DRAW
, 0, FName
);
3206 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3207 gLMSRespawnTime
:= gTime
+ 5000;
3210 else if (gGameSettings
.GameMode
= GM_DM
) then
3214 if gPlayers
[k
] <> nil then
3217 // survivor is the winner
3218 g_Game_Message(Format(_lc
[I_MESSAGE_LMS_WIN
], [AnsiUpperCase(FName
)]), 144);
3220 MH_SEND_GameEvent(NET_EV_LMS_WIN
, 0, FName
);
3223 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3224 gLMSRespawnTime
:= gTime
+ 5000;
3226 else if (a
= 0) then
3228 // everyone is dead, restart the map
3229 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
3231 MH_SEND_GameEvent(NET_EV_LMS_DRAW
, 0, FName
);
3232 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3233 gLMSRespawnTime
:= gTime
+ 5000;
3236 if srv
and (OldLR
= LMS_RESPAWN_NONE
) and (gLMSRespawn
> LMS_RESPAWN_NONE
) then
3238 if NetMode
= NET_SERVER
then
3239 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, (gLMSRespawnTime
- gTime
) div 1000)
3241 g_Console_Add(Format(_lc
[I_MSG_WARMUP_START
], [(gLMSRespawnTime
- gTime
) div 1000]), True);
3247 MH_SEND_PlayerStats(FUID
);
3248 MH_SEND_PlayerDeath(FUID
, KillType
, t
, SpawnerUID
);
3249 if gGameSettings
.GameMode
= GM_TDM
then MH_SEND_GameStats
;
3252 if srv
and FNoRespawn
then Spectate(True);
3253 FWantsInGame
:= True;
3256 function TPlayer
.BodyInLiquid(XInc
, YInc
: Integer): Boolean;
3258 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
, PLAYER_RECT
.Width
,
3259 PLAYER_RECT
.Height
-20, PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, False);
3262 function TPlayer
.BodyInAcid(XInc
, YInc
: Integer): Boolean;
3264 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
, PLAYER_RECT
.Width
,
3265 PLAYER_RECT
.Height
-20, PANEL_ACID1
or PANEL_ACID2
, False);
3268 procedure TPlayer
.MakeBloodSimple(Count
: Word);
3270 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)+8,
3271 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3272 Count
div 2, 3, -1, 16, (PLAYER_RECT
.Height
*2 div 3),
3274 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-8,
3275 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3276 Count
div 2, -3, -1, 16, (PLAYER_RECT
.Height
*2) div 3,
3280 procedure TPlayer
.MakeBloodVector(Count
: Word; VelX
, VelY
: Integer);
3282 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
3283 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3284 Count
, VelX
, VelY
, 16, (PLAYER_RECT
.Height
*2) div 3,
3288 procedure TPlayer
.QueueWeaponSwitch(Weapon
: Byte);
3290 if g_Game_IsClient
then Exit
;
3291 if Weapon
> High(FWeapon
) then Exit
;
3292 FNextWeap
:= FNextWeap
or (1 shl Weapon
);
3295 procedure TPlayer
.resetWeaponQueue ();
3298 FNextWeapDelay
:= 0;
3301 function TPlayer
.hasAmmoForWeapon (weapon
: Byte): Boolean;
3305 WEAPON_KASTET
, WEAPON_SAW
: result
:= true;
3306 WEAPON_SHOTGUN1
, WEAPON_SHOTGUN2
: result
:= (FAmmo
[A_SHELLS
] > 0);
3307 WEAPON_PISTOL
, WEAPON_CHAINGUN
, WEAPON_SUPERPULEMET
: result
:= (FAmmo
[A_BULLETS
] > 0);
3308 WEAPON_ROCKETLAUNCHER
: result
:= (FAmmo
[A_ROCKETS
] > 0);
3309 WEAPON_PLASMA
, WEAPON_BFG
: result
:= (FAmmo
[A_CELLS
] > 0);
3310 else result
:= (weapon
< length(FWeapon
));
3314 // return 255 for "no switch"
3315 function TPlayer
.getNextWeaponIndex (): Byte;
3318 wantThisWeapon
: array[0..64] of Boolean;
3319 wwc
: Integer = 0; //HACK!
3322 result
:= 255; // default result: "no switch"
3323 // had weapon cycling on previous frame? remove that flag
3324 if (FNextWeap
and $2000) <> 0 then begin FNextWeap
:= FNextWeap
and $1FFF; FNextWeapDelay
:= 0; end;
3325 // cycling has priority
3326 if (FNextWeap
and $C000) <> 0 then
3328 if (FNextWeap
and $8000) <> 0 then dir
:= 1 else dir
:= -1;
3329 FNextWeap
:= FNextWeap
or $2000; // we need this
3330 if FNextWeapDelay
> 0 then exit
; // cooldown time
3332 for i
:= 0 to High(FWeapon
) do
3334 cwi
:= (cwi
+length(FWeapon
)+dir
) mod length(FWeapon
);
3335 if FWeapon
[cwi
] then
3337 //e_WriteLog(Format(' SWITCH: cur=%d; new=%d', [FCurrWeap, cwi]), MSG_WARNING);
3338 result
:= Byte(cwi
);
3339 FNextWeapDelay
:= 10;
3347 for i
:= 0 to High(wantThisWeapon
) do wantThisWeapon
[i
] := false;
3348 for i
:= 0 to High(FWeapon
) do if (FNextWeap
and (1 shl i
)) <> 0 then begin wantThisWeapon
[i
] := true; Inc(wwc
); end;
3349 // exclude currently selected weapon from the set
3350 wantThisWeapon
[FCurrWeap
] := false;
3351 // slow down alterations a little
3354 //e_WriteLog(Format(' FNextWeap=%x; delay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
3355 // more than one weapon requested, assume "alteration" and check alteration delay
3356 if FNextWeapDelay
> 0 then begin FNextWeap
:= 0; exit
; end; // yeah
3358 // do not reset weapon queue, it will be done in `RealizeCurrentWeapon()`
3359 // but clear all counters if no weapon should be switched
3360 if wwc
< 1 then begin resetWeaponQueue(); exit
; end;
3361 //e_WriteLog(Format('wwc=%d', [wwc]), MSG_WARNING);
3362 // try weapons in descending order
3363 for i
:= High(FWeapon
) downto 0 do
3365 if wantThisWeapon
[i
] and FWeapon
[i
] and ((wwc
= 1) or hasAmmoForWeapon(i
)) then
3370 FNextWeapDelay
:= 10; // anyway, 'cause why not
3374 // no suitable weapon found, so reset the queue, to avoid accidental "queuing" of weapon w/o ammo
3378 procedure TPlayer
.RealizeCurrentWeapon();
3379 function switchAllowed (): Boolean;
3384 if FBFGFireCounter
<> -1 then
3386 if FTime
[T_SWITCH
] > gTime
then
3388 for i
:= WP_FIRST
to WP_LAST
do
3389 if FReloading
[i
] > 0 then
3397 //e_WriteLog(Format('***RealizeCurrentWeapon: FNextWeap=%x; FNextWeapDelay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
3398 //FNextWeap := FNextWeap and $1FFF;
3399 if FNextWeapDelay
> 0 then Dec(FNextWeapDelay
); // "alteration delay"
3401 if not switchAllowed
then
3403 //HACK for weapon cycling
3404 if (FNextWeap
and $7000) <> 0 then FNextWeap
:= 0;
3408 nw
:= getNextWeaponIndex();
3409 if nw
= 255 then exit
; // don't reset anything here
3410 if nw
> High(FWeapon
) then
3412 // don't forget to reset queue here!
3413 //e_WriteLog(' RealizeCurrentWeapon: WUTAFUUUU', MSG_WARNING);
3421 FTime
[T_SWITCH
] := gTime
+156;
3422 if FCurrWeap
= WEAPON_SAW
then FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3423 FModel
.SetWeapon(FCurrWeap
);
3424 if g_Game_IsNet
then MH_SEND_PlayerStats(FUID
);
3428 procedure TPlayer
.NextWeapon();
3430 if g_Game_IsClient
then Exit
;
3434 procedure TPlayer
.PrevWeapon();
3436 if g_Game_IsClient
then Exit
;
3440 procedure TPlayer
.SetWeapon(W
: Byte);
3442 if FCurrWeap
<> W
then
3443 if W
= WEAPON_SAW
then
3444 FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3447 FModel
.SetWeapon(CurrWeap
);
3451 function TPlayer
.PickItem(ItemType
: Byte; respawn
: Boolean; var remove
: Boolean): Boolean;
3456 if g_Game_IsClient
then Exit
;
3458 // a = true - ìåñòî ñïàâíà ïðåäìåòà:
3459 a
:= LongBool(gGameSettings
.Options
and GAME_OPTION_WEAPONSTAY
) and respawn
;
3464 if FHealth
< PLAYER_HP_SOFT
then
3466 IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
3469 if gFlash
= 2 then Inc(FPickup
, 5);
3473 if FHealth
< PLAYER_HP_SOFT
then
3475 IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
3478 if gFlash
= 2 then Inc(FPickup
, 5);
3482 if FArmor
< PLAYER_AP_SOFT
then
3484 FArmor
:= PLAYER_AP_SOFT
;
3487 if gFlash
= 2 then Inc(FPickup
, 5);
3491 if FArmor
< PLAYER_AP_LIMIT
then
3493 FArmor
:= PLAYER_AP_LIMIT
;
3496 if gFlash
= 2 then Inc(FPickup
, 5);
3500 if FHealth
< PLAYER_HP_LIMIT
then
3502 IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
3505 if gFlash
= 2 then Inc(FPickup
, 5);
3509 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) then
3511 if FHealth
< PLAYER_HP_LIMIT
then
3512 FHealth
:= PLAYER_HP_LIMIT
;
3513 if FArmor
< PLAYER_AP_LIMIT
then
3514 FArmor
:= PLAYER_AP_LIMIT
;
3517 if gFlash
= 2 then Inc(FPickup
, 5);
3521 if (not FWeapon
[WEAPON_SAW
]) or ((not respawn
) and (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
])) then
3523 FWeapon
[WEAPON_SAW
] := True;
3525 if gFlash
= 2 then Inc(FPickup
, 5);
3526 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3529 ITEM_WEAPON_SHOTGUN1
:
3530 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN1
] then
3532 // Íóæíî, ÷òîáû íå âçÿòü âñå ïóëè ñðàçó:
3533 if a
and FWeapon
[WEAPON_SHOTGUN1
] then Exit
;
3535 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3536 FWeapon
[WEAPON_SHOTGUN1
] := True;
3538 if gFlash
= 2 then Inc(FPickup
, 5);
3539 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3542 ITEM_WEAPON_SHOTGUN2
:
3543 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN2
] then
3545 if a
and FWeapon
[WEAPON_SHOTGUN2
] then Exit
;
3547 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3548 FWeapon
[WEAPON_SHOTGUN2
] := True;
3550 if gFlash
= 2 then Inc(FPickup
, 5);
3551 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3554 ITEM_WEAPON_CHAINGUN
:
3555 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or not FWeapon
[WEAPON_CHAINGUN
] then
3557 if a
and FWeapon
[WEAPON_CHAINGUN
] then Exit
;
3559 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
3560 FWeapon
[WEAPON_CHAINGUN
] := True;
3562 if gFlash
= 2 then Inc(FPickup
, 5);
3563 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3566 ITEM_WEAPON_ROCKETLAUNCHER
:
3567 if (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or not FWeapon
[WEAPON_ROCKETLAUNCHER
] then
3569 if a
and FWeapon
[WEAPON_ROCKETLAUNCHER
] then Exit
;
3571 IncMax(FAmmo
[A_ROCKETS
], 2, FMaxAmmo
[A_ROCKETS
]);
3572 FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
3574 if gFlash
= 2 then Inc(FPickup
, 5);
3575 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3579 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_PLASMA
] then
3581 if a
and FWeapon
[WEAPON_PLASMA
] then Exit
;
3583 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3584 FWeapon
[WEAPON_PLASMA
] := True;
3586 if gFlash
= 2 then Inc(FPickup
, 5);
3587 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3591 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_BFG
] then
3593 if a
and FWeapon
[WEAPON_BFG
] then Exit
;
3595 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3596 FWeapon
[WEAPON_BFG
] := True;
3598 if gFlash
= 2 then Inc(FPickup
, 5);
3599 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3602 ITEM_WEAPON_SUPERPULEMET
:
3603 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SUPERPULEMET
] then
3605 if a
and FWeapon
[WEAPON_SUPERPULEMET
] then Exit
;
3607 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3608 FWeapon
[WEAPON_SUPERPULEMET
] := True;
3610 if gFlash
= 2 then Inc(FPickup
, 5);
3611 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3615 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
3617 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
3620 if gFlash
= 2 then Inc(FPickup
, 5);
3623 ITEM_AMMO_BULLETS_BOX
:
3624 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
3626 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
3629 if gFlash
= 2 then Inc(FPickup
, 5);
3633 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
3635 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3638 if gFlash
= 2 then Inc(FPickup
, 5);
3641 ITEM_AMMO_SHELLS_BOX
:
3642 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
3644 IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
3647 if gFlash
= 2 then Inc(FPickup
, 5);
3651 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
3653 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
3656 if gFlash
= 2 then Inc(FPickup
, 5);
3659 ITEM_AMMO_ROCKET_BOX
:
3660 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
3662 IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
3665 if gFlash
= 2 then Inc(FPickup
, 5);
3669 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
3671 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3674 if gFlash
= 2 then Inc(FPickup
, 5);
3678 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
3680 IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
3683 if gFlash
= 2 then Inc(FPickup
, 5);
3687 if not(R_ITEM_BACKPACK
in FRulez
) or
3688 (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
3689 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
3690 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
3691 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) then
3693 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[1, A_BULLETS
];
3694 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[1, A_SHELLS
];
3695 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[1, A_ROCKETS
];
3696 FMaxAmmo
[A_CELLS
] := AmmoLimits
[1, A_CELLS
];
3698 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
3699 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
3700 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
3701 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3702 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
3703 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
3704 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
3705 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3707 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
3710 if gFlash
= 2 then Inc(FPickup
, 5);
3714 if not(R_KEY_RED
in FRulez
) then
3716 Include(FRulez
, R_KEY_RED
);
3718 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
3719 if gFlash
= 2 then Inc(FPickup
, 5);
3720 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
3724 if not(R_KEY_GREEN
in FRulez
) then
3726 Include(FRulez
, R_KEY_GREEN
);
3728 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
3729 if gFlash
= 2 then Inc(FPickup
, 5);
3730 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
3734 if not(R_KEY_BLUE
in FRulez
) then
3736 Include(FRulez
, R_KEY_BLUE
);
3738 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
3739 if gFlash
= 2 then Inc(FPickup
, 5);
3740 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
3744 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
3746 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
3749 if gFlash
= 2 then Inc(FPickup
, 5);
3753 if FAir
< AIR_MAX
then
3758 if gFlash
= 2 then Inc(FPickup
, 5);
3763 if not (R_BERSERK
in FRulez
) then
3765 Include(FRulez
, R_BERSERK
);
3766 if FBFGFireCounter
= -1 then
3768 FCurrWeap
:= WEAPON_KASTET
;
3770 FModel
.SetWeapon(WEAPON_KASTET
);
3774 if gFlash
= 2 then Inc(FPickup
, 5);
3775 FBerserk
:= gTime
+30000;
3779 if FHealth
< PLAYER_HP_SOFT
then
3781 FHealth
:= PLAYER_HP_SOFT
;
3782 FBerserk
:= gTime
+30000;
3789 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
3791 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
3794 if gFlash
= 2 then Inc(FPickup
, 5);
3798 if FHealth
< PLAYER_HP_LIMIT
then
3800 IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
3803 if gFlash
= 2 then Inc(FPickup
, 5);
3807 if FArmor
< PLAYER_AP_LIMIT
then
3809 IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
3812 if gFlash
= 2 then Inc(FPickup
, 5);
3816 if FJetFuel
< JET_MAX
then
3818 FJetFuel
:= JET_MAX
;
3821 if gFlash
= 2 then Inc(FPickup
, 5);
3825 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
3827 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
3830 if gFlash
= 2 then Inc(FPickup
, 5);
3835 procedure TPlayer
.Touch();
3839 //FModel.PlaySound(MODELSOUND_PAIN, 1, FObj.X, FObj.Y);
3842 // Áðîñèòü ôëàã òîâàðèùó:
3843 if gGameSettings
.GameMode
= GM_CTF
then
3848 procedure TPlayer
.Push(vx
, vy
: Integer);
3850 if (not FPhysics
) and FGhost
then
3852 FObj
.Accel
.X
:= FObj
.Accel
.X
+ vx
;
3853 FObj
.Accel
.Y
:= FObj
.Accel
.Y
+ vy
;
3854 if g_Game_IsNet
and g_Game_IsServer
then
3855 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
3858 procedure TPlayer
.Reset(Force
: Boolean);
3864 FTime
[T_RESPAWN
] := 0;
3865 FTime
[T_FLAGCAP
] := 0;
3878 FSpectator
:= False;
3881 FSpectatePlayer
:= -1;
3882 FNoRespawn
:= False;
3884 FLives
:= gGameSettings
.MaxLives
;
3889 procedure TPlayer
.SoftReset();
3895 FBFGFireCounter
:= -1;
3903 SetAction(A_STAND
, True);
3906 function TPlayer
.GetRespawnPoint(): Byte;
3911 // Íà áóäóùåå: FSpawn - èãðîê óæå èãðàë è ïåðåðîæäàåòñÿ
3913 // Îäèíî÷íàÿ èãðà/êîîïåðàòèâ
3914 if gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
] then
3916 if (Self
= gPlayer1
) or (Self
= gPlayer2
) then
3918 // Òî÷êà ïîÿâëåíèÿ ñâîåãî èãðîêà
3919 if Self
= gPlayer1
then
3920 c
:= RESPAWNPOINT_PLAYER1
3922 c
:= RESPAWNPOINT_PLAYER2
;
3923 if g_Map_GetPointCount(c
) > 0 then
3929 // Òî÷êà ïîÿâëåíèÿ äðóãîãî èãðîêà
3930 if Self
= gPlayer1
then
3931 c
:= RESPAWNPOINT_PLAYER2
3933 c
:= RESPAWNPOINT_PLAYER1
;
3934 if g_Map_GetPointCount(c
) > 0 then
3941 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà (áîòà)
3942 if Random(2) = 0 then
3943 c
:= RESPAWNPOINT_PLAYER1
3945 c
:= RESPAWNPOINT_PLAYER2
;
3946 if g_Map_GetPointCount(c
) > 0 then
3953 // Òî÷êà ëþáîé èç êîìàíä
3954 if Random(2) = 0 then
3955 c
:= RESPAWNPOINT_RED
3957 c
:= RESPAWNPOINT_BLUE
;
3958 if g_Map_GetPointCount(c
) > 0 then
3965 c
:= RESPAWNPOINT_DM
;
3966 if g_Map_GetPointCount(c
) > 0 then
3974 if gGameSettings
.GameMode
= GM_DM
then
3977 c
:= RESPAWNPOINT_DM
;
3978 if g_Map_GetPointCount(c
) > 0 then
3984 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà
3985 if Random(2) = 0 then
3986 c
:= RESPAWNPOINT_PLAYER1
3988 c
:= RESPAWNPOINT_PLAYER2
;
3989 if g_Map_GetPointCount(c
) > 0 then
3995 // Òî÷êà ëþáîé èç êîìàíä
3996 if Random(2) = 0 then
3997 c
:= RESPAWNPOINT_RED
3999 c
:= RESPAWNPOINT_BLUE
;
4000 if g_Map_GetPointCount(c
) > 0 then
4008 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
4010 // Òî÷êà ñâîåé êîìàíäû
4011 c
:= RESPAWNPOINT_DM
;
4012 if FTeam
= TEAM_RED
then
4013 c
:= RESPAWNPOINT_RED
;
4014 if FTeam
= TEAM_BLUE
then
4015 c
:= RESPAWNPOINT_BLUE
;
4016 if g_Map_GetPointCount(c
) > 0 then
4023 c
:= RESPAWNPOINT_DM
;
4024 if g_Map_GetPointCount(c
) > 0 then
4030 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà
4031 if Random(2) = 0 then
4032 c
:= RESPAWNPOINT_PLAYER1
4034 c
:= RESPAWNPOINT_PLAYER2
;
4035 if g_Map_GetPointCount(c
) > 0 then
4041 // Òî÷êà äðóãîé êîìàíäû
4042 c
:= RESPAWNPOINT_DM
;
4043 if FTeam
= TEAM_RED
then
4044 c
:= RESPAWNPOINT_BLUE
;
4045 if FTeam
= TEAM_BLUE
then
4046 c
:= RESPAWNPOINT_RED
;
4047 if g_Map_GetPointCount(c
) > 0 then
4055 procedure TPlayer
.Respawn(Silent
: Boolean; Force
: Boolean = False);
4057 RespawnPoint
: TRespawnPoint
;
4062 if not g_Game_IsServer
then
4066 FWantsInGame
:= True;
4067 FJustTeleported
:= True;
4070 FTime
[T_RESPAWN
] := 0;
4074 // if server changes MaxLives we gotta be ready
4075 if gGameSettings
.MaxLives
= 0 then FNoRespawn
:= False;
4077 // Åùå íåëüçÿ âîçðîäèòüñÿ:
4078 if FTime
[T_RESPAWN
] > gTime
then
4081 // Ïðîñðàë âñå æèçíè:
4084 if not FSpectator
then Spectate(True);
4085 FWantsInGame
:= True;
4089 if (gGameSettings
.GameType
<> GT_SINGLE
) and (gGameSettings
.GameMode
<> GM_COOP
) then
4090 begin // "Ñâîÿ èãðà"
4091 // Áåðñåðê íå ñîõðàíÿåòñÿ ìåæäó óðîâíÿìè:
4092 FRulez
:= FRulez
-[R_BERSERK
];
4094 else // "Îäèíî÷íàÿ èãðà"/"Êîîï"
4096 // Áåðñåðê è êëþ÷è íå ñîõðàíÿþòñÿ ìåæäó óðîâíÿìè:
4097 FRulez
:= FRulez
-[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
, R_BERSERK
];
4100 // Ïîëó÷àåì òî÷êó ñïàóíà èãðîêà:
4101 c
:= GetRespawnPoint();
4106 // Âîñêðåøåíèå áåç îðóæèÿ:
4109 FHealth
:= PLAYER_HP_SOFT
;
4115 for a
:= WP_FIRST
to WP_LAST
do
4117 FWeapon
[a
] := False;
4121 FWeapon
[WEAPON_PISTOL
] := True;
4122 FWeapon
[WEAPON_KASTET
] := True;
4123 FCurrWeap
:= WEAPON_PISTOL
;
4126 FModel
.SetWeapon(FCurrWeap
);
4128 for b
:= A_BULLETS
to A_HIGH
do
4131 FAmmo
[A_BULLETS
] := 50;
4133 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[0, A_BULLETS
];
4134 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[0, A_SHELLS
];
4135 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[0, A_SHELLS
];
4136 FMaxAmmo
[A_CELLS
] := AmmoLimits
[0, A_CELLS
];
4138 if gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
] then
4139 FRulez
:= [R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
]
4144 // Ïîëó÷àåì êîîðäèíàòû òî÷êè âîçðîæäåíèÿ:
4145 if not g_Map_GetPoint(c
, RespawnPoint
) then
4147 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
4151 // Óñòàíîâêà êîîðäèíàò è ñáðîñ âñåõ ïàðàìåòðîâ:
4152 FObj
.X
:= RespawnPoint
.X
-PLAYER_RECT
.X
;
4153 FObj
.Y
:= RespawnPoint
.Y
-PLAYER_RECT
.Y
;
4159 FDirection
:= RespawnPoint
.Direction
;
4160 if FDirection
= D_LEFT
then
4166 FBFGFireCounter
:= -1;
4171 SetAction(A_STAND
, True);
4172 FModel
.Direction
:= FDirection
;
4174 for a
:= Low(FTime
) to High(FTime
) do
4177 for a
:= Low(FMegaRulez
) to High(FMegaRulez
) do
4182 FCanJetpack
:= False;
4184 // Àíèìàöèÿ âîçðîæäåíèÿ:
4185 if (not gLoadGameMode
) and (not Silent
) then
4186 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
4188 Anim
:= TAnimation
.Create(ID
, False, 3);
4189 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4190 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4194 FSpectator
:= False;
4197 FSpectatePlayer
:= -1;
4200 if g_Game_IsNet
then
4202 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
4203 MH_SEND_PlayerStats(FUID
, NET_EVERYONE
);
4205 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4206 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32,
4211 procedure TPlayer
.Spectate(NoMove
: Boolean = False);
4214 Kill(K_EXTRAHARDKILL
, FUID
, HIT_SOME
)
4215 else if (not NoMove
) then
4217 GameX
:= gMapInfo
.Width
div 2;
4218 GameY
:= gMapInfo
.Height
div 2;
4227 FWantsInGame
:= False;
4232 if Self
= gPlayer1
then
4237 if Self
= gPlayer2
then
4244 if g_Game_IsNet
then
4245 MH_SEND_PlayerStats(FUID
);
4248 procedure TPlayer
.SwitchNoClip
;
4252 FGhost
:= not FGhost
;
4253 FPhysics
:= not FGhost
;
4265 procedure TPlayer
.Run(Direction
: TDirection
);
4269 if MAX_RUNVEL
> 8 then
4273 if Direction
= D_LEFT
then
4275 if FObj
.Vel
.X
> -MAX_RUNVEL
then
4276 FObj
.Vel
.X
:= FObj
.Vel
.X
- (MAX_RUNVEL
shr 3);
4279 if FObj
.Vel
.X
< MAX_RUNVEL
then
4280 FObj
.Vel
.X
:= FObj
.Vel
.X
+ (MAX_RUNVEL
shr 3);
4282 // Âîçìîæíî, ïèíàåì êóñêè:
4283 if (FObj
.Vel
.X
<> 0) and (gGibs
<> nil) then
4285 b
:= Abs(FObj
.Vel
.X
);
4286 if b
> 1 then b
:= b
* (Random(8 div b
) + 1);
4287 for a
:= 0 to High(gGibs
) do
4288 if gGibs
[a
].Live
and
4289 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
+FObj
.Rect
.Height
-4,
4290 FObj
.Rect
.Width
, 8, @gGibs
[a
].Obj
) and (Random(3) = 0) then
4292 if FObj
.Vel
.X
< 0 then
4293 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)+120) // íàëåâî
4295 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)); // íàïðàâî
4301 procedure TPlayer
.SeeDown();
4303 SetAction(A_SEEDOWN
);
4305 if FDirection
= D_LEFT
then FAngle
:= ANGLE_LEFTDOWN
else FAngle
:= ANGLE_RIGHTDOWN
;
4307 if FIncCam
> -120 then DecMin(FIncCam
, 5, -120);
4310 procedure TPlayer
.SeeUp();
4314 if FDirection
= D_LEFT
then FAngle
:= ANGLE_LEFTUP
else FAngle
:= ANGLE_RIGHTUP
;
4316 if FIncCam
< 120 then IncMax(FIncCam
, 5, 120);
4319 procedure TPlayer
.SetAction(Action
: Byte; Force
: Boolean = False);
4327 A_ATTACK
: Prior
:= 2;
4328 A_SEEUP
: Prior
:= 1;
4329 A_SEEDOWN
: Prior
:= 1;
4330 A_ATTACKUP
: Prior
:= 2;
4331 A_ATTACKDOWN
: Prior
:= 2;
4336 if (Prior
> FActionPrior
) or Force
then
4337 if not ((Prior
= 2) and (FCurrWeap
= WEAPON_SAW
)) then
4339 FActionPrior
:= Prior
;
4340 FActionAnim
:= Action
;
4341 FActionForce
:= Force
;
4342 FActionChanged
:= True;
4345 if Action
in [A_ATTACK
, A_ATTACKUP
, A_ATTACKDOWN
] then FModel
.SetFire(True);
4348 function TPlayer
.StayOnStep(XInc
, YInc
: Integer): Boolean;
4350 Result
:= not g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
-1,
4351 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False)
4352 and g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
,
4353 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False);
4356 function TPlayer
.TeleportTo(X
, Y
: Integer; silent
: Boolean; dir
: Byte): Boolean;
4363 if g_CollideLevel(X
, Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
) then
4365 g_Sound_PlayExAt('SOUND_GAME_NOTELEPORT', FObj
.X
, FObj
.Y
);
4366 if g_Game_IsServer
and g_Game_IsNet
then
4367 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_GAME_NOTELEPORT');
4371 FJustTeleported
:= True;
4376 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
4378 Anim
:= TAnimation
.Create(ID
, False, 3);
4381 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', FObj
.X
, FObj
.Y
);
4382 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4383 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4384 if g_Game_IsServer
and g_Game_IsNet
then
4385 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4386 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 1,
4390 FObj
.X
:= X
-PLAYER_RECT
.X
;
4391 FObj
.Y
:= Y
-PLAYER_RECT
.Y
;
4392 if FLive
and FGhost
then
4398 if not g_Game_IsNet
then
4402 SetDirection(D_LEFT
);
4408 SetDirection(D_RIGHT
);
4414 if FDirection
= D_RIGHT
then
4416 SetDirection(D_LEFT
);
4421 SetDirection(D_RIGHT
);
4427 if not silent
and (Anim
<> nil) then
4429 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4430 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4433 if g_Game_IsServer
and g_Game_IsNet
then
4434 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4435 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 0,
4442 function nonz(a
: Single): Single;
4450 procedure TPlayer
.Update();
4453 i
, ii
, wx
, wy
, xd
, yd
, k
: Integer;
4454 blockmon
, headwater
, dospawn
: Boolean;
4459 NetServer
:= g_Game_IsNet
and g_Game_IsServer
;
4460 AnyServer
:= g_Game_IsServer
;
4462 if g_Game_IsClient
and (NetInterpLevel
> 0) then
4463 DoLerp(NetInterpLevel
+ 1)
4469 if FClientID
>= 0 then
4471 FPing
:= NetClients
[FClientID
].Peer
^.lastRoundTripTime
;
4472 if NetClients
[FClientID
].Peer
^.packetsSent
> 0 then
4473 FLoss
:= Round(100*NetClients
[FClientID
].Peer
^.packetsLost
/NetClients
[FClientID
].Peer
^.packetsSent
)
4482 if FLive
and (gFly
or FJetpack
) then
4485 if FDirection
= D_LEFT
then
4490 if FLive
and (not FGhost
) then
4492 if FKeys
[KEY_UP
].Pressed
then
4494 if FKeys
[KEY_DOWN
].Pressed
then
4498 if (not (FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_DOWN
].Pressed
)) and
4501 i
:= g_basic
.Sign(FIncCam
);
4502 FIncCam
:= Abs(FIncCam
);
4503 DecMin(FIncCam
, 5, 0);
4504 FIncCam
:= FIncCam
*i
;
4507 // no need to do that each second frame, weapon queue will take care of it
4508 if FLive
and FKeys
[KEY_NEXTWEAPON
].Pressed
and AnyServer
then NextWeapon();
4509 if FLive
and FKeys
[KEY_PREVWEAPON
].Pressed
and AnyServer
then PrevWeapon();
4511 if gTime
mod (GAME_TICK
*2) <> 0 then
4513 if (FObj
.Vel
.X
= 0) and FLive
then
4515 if FKeys
[KEY_LEFT
].Pressed
then
4517 if FKeys
[KEY_RIGHT
].Pressed
then
4522 g_Obj_Move(@FObj
, True, True, True);
4527 FActionChanged
:= False;
4531 // Let alive player do some actions
4532 if FKeys
[KEY_LEFT
].Pressed
then Run(D_LEFT
);
4533 if FKeys
[KEY_RIGHT
].Pressed
then Run(D_RIGHT
);
4534 //if FKeys[KEY_NEXTWEAPON].Pressed and AnyServer then NextWeapon();
4535 //if FKeys[KEY_PREVWEAPON].Pressed and AnyServer then PrevWeapon();
4536 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then Fire();
4537 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Use();
4538 if FKeys
[KEY_JUMP
].Pressed
then Jump()
4541 if AnyServer
and FJetpack
then
4545 if NetServer
then MH_SEND_PlayerStats(FUID
);
4547 FCanJetpack
:= True;
4554 for k
:= Low(FKeys
) to KEY_CHAT
-1 do
4556 if FKeys
[k
].Pressed
then
4564 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
4567 if (FTime
[T_RESPAWN
] <= gTime
) and
4568 gGameOn
and (not FLive
) then
4570 if (g_Player_GetCount() > 1) then
4574 gExit
:= EXIT_RESTART
;
4579 // Dead spectator actions
4582 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Fire();
4583 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then
4587 if (FSpectatePlayer
>= High(gPlayers
)) then
4588 FSpectatePlayer
:= -1
4592 for I
:= FSpectatePlayer
+ 1 to High(gPlayers
) do
4593 if gPlayers
[I
] <> nil then
4594 if gPlayers
[I
].Live
then
4595 if gPlayers
[I
].UID
<> FUID
then
4597 FSpectatePlayer
:= I
;
4602 if not SetSpect
then FSpectatePlayer
:= -1;
4613 if FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_JUMP
].Pressed
then
4615 FYTo
:= FObj
.Y
- 32;
4616 FSpectatePlayer
:= -1;
4618 if FKeys
[KEY_DOWN
].Pressed
then
4620 FYTo
:= FObj
.Y
+ 32;
4621 FSpectatePlayer
:= -1;
4623 if FKeys
[KEY_LEFT
].Pressed
then
4625 FXTo
:= FObj
.X
- 32;
4626 FSpectatePlayer
:= -1;
4628 if FKeys
[KEY_RIGHT
].Pressed
then
4630 FXTo
:= FObj
.X
+ 32;
4631 FSpectatePlayer
:= -1;
4634 if (FXTo
< -64) then
4636 else if (FXTo
> gMapInfo
.Width
+ 32) then
4637 FXTo
:= gMapInfo
.Width
+ 32;
4638 if (FYTo
< -72) then
4640 else if (FYTo
> gMapInfo
.Height
+ 32) then
4641 FYTo
:= gMapInfo
.Height
+ 32;
4645 g_Obj_Move(@FObj
, True, True, True)
4651 if (FSpectatePlayer
<= High(gPlayers
)) and (FSpectatePlayer
>= 0) then
4652 if gPlayers
[FSpectatePlayer
] <> nil then
4653 if gPlayers
[FSpectatePlayer
].Live
then
4655 FXTo
:= gPlayers
[FSpectatePlayer
].GameX
;
4656 FYTo
:= gPlayers
[FSpectatePlayer
].GameY
;
4660 blockmon
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
, FObj
.Y
+PLAYER_HEADRECT
.Y
,
4661 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
4662 PANEL_BLOCKMON
, True);
4663 headwater
:= HeadInLiquid(0, 0);
4665 // Ñîïðîòèâëåíèå âîçäóõà:
4666 if (not FLive
) or not (FKeys
[KEY_LEFT
].Pressed
or FKeys
[KEY_RIGHT
].Pressed
) then
4667 if FObj
.Vel
.X
<> 0 then
4668 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
4670 if (FLastHit
= HIT_TRAP
) and (FPain
> 90) then FPain
:= 90;
4671 DecMin(FPain
, 5, 0);
4672 DecMin(FPickup
, 1, 0);
4674 if FLive
and (FObj
.Y
> gMapInfo
.Height
+128) and AnyServer
then
4676 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
4677 FMegaRulez
[MR_SUIT
] := 0;
4678 FMegaRulez
[MR_INVUL
] := 0;
4679 FMegaRulez
[MR_INVIS
] := 0;
4680 Kill(K_FALLKILL
, 0, HIT_FALL
);
4687 if FCurrWeap
= WEAPON_SAW
then
4688 if not (FSawSound
.IsPlaying() or FSawSoundHit
.IsPlaying() or
4689 FSawSoundSelect
.IsPlaying()) then
4690 FSawSoundIdle
.PlayAt(FObj
.X
, FObj
.Y
);
4693 if (not FJetSoundFly
.IsPlaying()) and (not FJetSoundOn
.IsPlaying()) and
4694 (not FJetSoundOff
.IsPlaying()) then
4696 FJetSoundFly
.SetPosition(0);
4697 FJetSoundFly
.PlayAt(FObj
.X
, FObj
.Y
);
4700 for b
:= WP_FIRST
to WP_LAST
do
4701 if FReloading
[b
] > 0 then
4707 if FShellTimer
> -1 then
4708 if FShellTimer
= 0 then
4710 if FShellType
= SHELL_SHELL
then
4711 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
4712 GameVelX
, GameVelY
-2, SHELL_SHELL
)
4713 else if FShellType
= SHELL_DBLSHELL
then
4715 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
4716 GameVelX
+1, GameVelY
-2, SHELL_SHELL
);
4717 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
4718 GameVelX
-1, GameVelY
-2, SHELL_SHELL
);
4721 end else Dec(FShellTimer
);
4723 if (FBFGFireCounter
> -1) then
4724 if FBFGFireCounter
= 0 then
4728 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
4729 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
4730 xd
:= wx
+IfThen(FDirection
= D_LEFT
, -30, 30);
4731 yd
:= wy
+firediry();
4732 g_Weapon_bfgshot(wx
, wy
, xd
, yd
, FUID
);
4733 if NetServer
then MH_SEND_PlayerFire(FUID
, WEAPON_BFG
, wx
, wy
, xd
, yd
);
4734 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
4735 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
4736 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
4739 FReloading
[WEAPON_BFG
] := WEAPON_RELOAD
[WEAPON_BFG
];
4740 FBFGFireCounter
:= -1;
4743 FBFGFireCounter
:= 0
4745 Dec(FBFGFireCounter
);
4747 if (FMegaRulez
[MR_SUIT
] < gTime
) and AnyServer
then
4749 b
:= g_GetAcidHit(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
);
4751 if (b
> 0) and (gTime
mod (15*GAME_TICK
) = 0) then Damage(b
, 0, 0, 0, HIT_ACID
);
4754 if (headwater
or blockmon
) then
4760 if AnyServer
then Damage(10, 0, 0, 0, HIT_WATER
);
4763 else if (FAir
mod 31 = 0) and not blockmon
then
4765 g_GFX_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2), FObj
.Y
+PLAYER_RECT
.Y
-4, 5+Random(6), 8, 4);
4766 if Random(2) = 0 then
4767 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
4769 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
4771 end else if FAir
< AIR_DEF
then
4774 if FDamageBuffer
> 0 then
4776 if FDamageBuffer
>= 9 then
4780 if FDamageBuffer
< 30 then i
:= 9
4781 else if FDamageBuffer
< 100 then i
:= 18
4785 ii
:= Round(FDamageBuffer
*FHealth
/ nonz(FArmor
*(3/4)+FHealth
));
4786 FArmor
:= FArmor
-(FDamageBuffer
-ii
);
4787 FHealth
:= FHealth
-ii
;
4790 FHealth
:= FHealth
+FArmor
;
4795 if FHealth
<= 0 then
4796 if FHealth
> -30 then Kill(K_SIMPLEKILL
, FLastSpawnerUID
, FLastHit
)
4797 else if FHealth
> -50 then Kill(K_HARDKILL
, FLastSpawnerUID
, FLastHit
)
4798 else Kill(K_EXTRAHARDKILL
, FLastSpawnerUID
, FLastHit
);
4802 if FDamageBuffer
<= 20 then FModel
.PlaySound(MODELSOUND_PAIN
, 1, FObj
.X
, FObj
.Y
)
4803 else if FDamageBuffer
<= 55 then FModel
.PlaySound(MODELSOUND_PAIN
, 2, FObj
.X
, FObj
.Y
)
4804 else if FDamageBuffer
<= 120 then FModel
.PlaySound(MODELSOUND_PAIN
, 3, FObj
.X
, FObj
.Y
)
4805 else FModel
.PlaySound(MODELSOUND_PAIN
, 4, FObj
.X
, FObj
.Y
);
4812 end; // if FLive then ...
4814 if (FActionAnim
= A_PAIN
) and (FModel
.Animation
<> A_PAIN
) then
4816 FModel
.ChangeAnimation(FActionAnim
, FActionForce
);
4817 FModel
.GetCurrentAnimation
.MinLength
:= i
;
4818 FModel
.GetCurrentAnimationMask
.MinLength
:= i
;
4819 end else FModel
.ChangeAnimation(FActionAnim
, FActionForce
and (FModel
.Animation
<> A_STAND
));
4821 if (FModel
.GetCurrentAnimation
.Played
or ((not FActionChanged
) and (FModel
.Animation
= A_WALK
)))
4822 then SetAction(A_STAND
, True);
4824 if not ((FModel
.Animation
= A_WALK
) and (Abs(FObj
.Vel
.X
) < 4) and not FModel
.Fire
) then FModel
.Update
;
4826 for b
:= Low(FKeys
) to High(FKeys
) do
4827 if FKeys
[b
].Time
= 0 then FKeys
[b
].Pressed
:= False else Dec(FKeys
[b
].Time
);
4830 function TPlayer
.Collide(X
, Y
: Integer; Width
, Height
: Word): Boolean;
4832 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
4833 FObj
.Y
+PLAYER_RECT
.Y
,
4840 function TPlayer
.Collide(Panel
: TPanel
): Boolean;
4842 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
4843 FObj
.Y
+PLAYER_RECT
.Y
,
4847 Panel
.Width
, Panel
.Height
);
4850 function TPlayer
.Collide(X
, Y
: Integer): Boolean;
4852 X
:= X
-FObj
.X
-PLAYER_RECT
.X
;
4853 Y
:= Y
-FObj
.Y
-PLAYER_RECT
.Y
;
4854 Result
:= (x
>= 0) and (x
<= PLAYER_RECT
.Width
) and
4855 (y
>= 0) and (y
<= PLAYER_RECT
.Height
);
4858 function g_Player_ValidName(Name
: string): Boolean;
4864 if gPlayers
= nil then Exit
;
4866 for a
:= 0 to High(gPlayers
) do
4867 if gPlayers
[a
] <> nil then
4868 if LowerCase(Name
) = LowerCase(gPlayers
[a
].FName
) then
4875 procedure TPlayer
.SetDirection(Direction
: TDirection
);
4879 d
:= FModel
.Direction
;
4881 FModel
.Direction
:= Direction
;
4882 if d
<> Direction
then FModel
.ChangeAnimation(FModel
.Animation
, True);
4884 FDirection
:= Direction
;
4887 function TPlayer
.GetKeys(): Byte;
4891 if R_KEY_RED
in FRulez
then Result
:= KEY_RED
;
4892 if R_KEY_GREEN
in FRulez
then Result
:= Result
or KEY_GREEN
;
4893 if R_KEY_BLUE
in FRulez
then Result
:= Result
or KEY_BLUE
;
4895 if FTeam
= TEAM_RED
then Result
:= Result
or KEY_REDTEAM
;
4896 if FTeam
= TEAM_BLUE
then Result
:= Result
or KEY_BLUETEAM
;
4899 procedure TPlayer
.Use();
4903 if FTime
[T_USE
] > gTime
then Exit
;
4905 g_Triggers_PressR(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
,
4906 PLAYER_RECT
.Height
, FUID
, ACTIVATE_PLAYERPRESS
);
4908 for a
:= 0 to High(gPlayers
) do
4909 if (gPlayers
[a
] <> nil) and (gPlayers
[a
] <> Self
) and
4910 gPlayers
[a
].Live
and SameTeam(FUID
, gPlayers
[a
].FUID
) and
4911 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
4912 FObj
.Rect
.Width
, FObj
.Rect
.Height
, @gPlayers
[a
].FObj
) then
4914 gPlayers
[a
].Touch();
4915 if g_Game_IsNet
and g_Game_IsServer
then
4916 MH_SEND_GameEvent(NET_EV_PLAYER_TOUCH
, gPlayers
[a
].FUID
);
4919 FTime
[T_USE
] := gTime
+120;
4922 procedure TPlayer
.NetFire(Wpn
: Byte; X
, Y
, AX
, AY
: Integer; WID
: Integer = -1);
4926 WX
, WY
, XD
, YD
: Integer;
4937 if R_BERSERK
in FRulez
then
4939 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
4940 obj
.X
:= FObj
.X
+FObj
.Rect
.X
;
4941 obj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
4944 obj
.rect
.Width
:= 39;
4945 obj
.rect
.Height
:= 52;
4946 obj
.Vel
.X
:= (xd
-wx
) div 2;
4947 obj
.Vel
.Y
:= (yd
-wy
) div 2;
4948 obj
.Accel
.X
:= xd
-wx
;
4949 obj
.Accel
.y
:= yd
-wy
;
4951 if g_Weapon_Hit(@obj
, 50, FUID
, HIT_SOME
) <> 0 then
4952 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
4954 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
4958 FPain
:= min(FPain
+ 25, 50);
4960 g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
4965 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
4966 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
4968 FSawSoundSelect
.Stop();
4970 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
4972 else if not FSawSoundHit
.IsPlaying() then
4974 FSawSoundSelect
.Stop();
4975 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
4982 g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', GameX
, Gamey
);
4983 FFireAngle
:= FAngle
;
4985 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
4986 GameVelX
, GameVelY
-2, SHELL_BULLET
);
4991 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
4992 FFireAngle
:= FAngle
;
4995 FShellType
:= SHELL_SHELL
;
5000 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN2', Gamex
, Gamey
);
5001 FFireAngle
:= FAngle
;
5004 FShellType
:= SHELL_DBLSHELL
;
5009 g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', Gamex
, Gamey
);
5010 FFireAngle
:= FAngle
;
5012 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5013 GameVelX
, GameVelY
-2, SHELL_BULLET
);
5016 WEAPON_ROCKETLAUNCHER
:
5018 g_Weapon_Rocket(wx
, wy
, xd
, yd
, FUID
, WID
);
5019 FFireAngle
:= FAngle
;
5025 g_Weapon_Plasma(wx
, wy
, xd
, yd
, FUID
, WID
);
5026 FFireAngle
:= FAngle
;
5032 g_Weapon_BFGShot(wx
, wy
, xd
, yd
, FUID
, WID
);
5033 FFireAngle
:= FAngle
;
5037 WEAPON_SUPERPULEMET
:
5039 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
5040 FFireAngle
:= FAngle
;
5042 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5043 GameVelX
, GameVelY
-2, SHELL_SHELL
);
5049 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
5050 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
5051 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
5054 procedure TPlayer
.DoLerp(Level
: Integer = 2);
5056 if FObj
.X
<> FXTo
then FObj
.X
:= Lerp(FObj
.X
, FXTo
, Level
);
5057 if FObj
.Y
<> FYTo
then FObj
.Y
:= Lerp(FObj
.Y
, FYTo
, Level
);
5060 procedure TPlayer
.SetLerp(XTo
, YTo
: Integer);
5064 if NetInterpLevel
< 1 then
5074 AX
:= Abs(FXTo
- FObj
.X
);
5075 AY
:= Abs(FYTo
- FObj
.Y
);
5076 if (AX
> 32) or (AX
<= NetInterpLevel
) then
5078 if (AY
> 32) or (AY
<= NetInterpLevel
) then
5083 function TPlayer
.FullInLift(XInc
, YInc
: Integer): Integer;
5085 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5086 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5087 PANEL_LIFTUP
, False) then Result
:= -1
5089 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5090 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5091 PANEL_LIFTDOWN
, False) then Result
:= 1
5095 function TPlayer
.GetFlag(Flag
: Byte): Boolean;
5102 if Flag
= FLAG_NONE
then
5105 if not g_Game_IsServer
then Exit
;
5107 // Ïðèíåñ ÷óæîé ôëàã íà ñâîþ áàçó:
5108 if (Flag
= FTeam
) and
5109 (gFlags
[Flag
].State
= FLAG_STATE_NORMAL
) and
5110 (FFlag
<> FLAG_NONE
) then
5112 if FFlag
= FLAG_RED
then
5113 s
:= _lc
[I_PLAYER_FLAG_RED
]
5115 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5117 evtype
:= FLAG_STATE_SCORED
;
5119 ts
:= Format('%.4d', [gFlags
[FFlag
].CaptureTime
]);
5120 Insert('.', ts
, Length(ts
) + 1 - 3);
5121 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_CAPTURE
], [FName
, s
, ts
]), True);
5123 g_Map_ResetFlag(FFlag
);
5124 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_CAPTURE
], [AnsiUpperCase(s
)]), 144);
5126 gTeamStat
[FTeam
].Goals
:= gTeamStat
[FTeam
].Goals
+ 1;
5129 if g_Game_IsNet
then
5131 MH_SEND_FlagEvent(evtype
, FFlag
, FUID
, False);
5135 gFlags
[FFlag
].CaptureTime
:= 0;
5140 // Ïîäîáðàë ñâîé ôëàã - âåðíóë åãî íà áàçó:
5141 if (Flag
= FTeam
) and
5142 (gFlags
[Flag
].State
= FLAG_STATE_DROPPED
) then
5144 if Flag
= FLAG_RED
then
5145 s
:= _lc
[I_PLAYER_FLAG_RED
]
5147 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5149 evtype
:= FLAG_STATE_RETURNED
;
5150 gFlags
[Flag
].CaptureTime
:= 0;
5152 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_RETURN
], [FName
, s
]), True);
5154 g_Map_ResetFlag(Flag
);
5155 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
5158 if g_Game_IsNet
then
5160 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5166 // Ïîäîáðàë ÷óæîé ôëàã:
5167 if (Flag
<> FTeam
) and (FTime
[T_FLAGCAP
] <= gTime
) then
5171 if Flag
= FLAG_RED
then
5172 s
:= _lc
[I_PLAYER_FLAG_RED
]
5174 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5176 evtype
:= FLAG_STATE_CAPTURED
;
5178 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_GET
], [FName
, s
]), True);
5180 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_GET
], [AnsiUpperCase(s
)]), 144);
5182 gFlags
[Flag
].State
:= FLAG_STATE_CAPTURED
;
5185 if g_Game_IsNet
then
5187 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5193 procedure TPlayer
.SetFlag(Flag
: Byte);
5196 if FModel
<> nil then
5197 FModel
.SetFlag(FFlag
);
5200 function TPlayer
.DropFlag(): Boolean;
5205 if (not g_Game_IsServer
) or (FFlag
= FLAG_NONE
) then
5207 FTime
[T_FLAGCAP
] := gTime
+ 2000;
5208 with gFlags
[FFlag
] do
5212 Direction
:= FDirection
;
5213 State
:= FLAG_STATE_DROPPED
;
5215 g_Obj_Push(@Obj
, (FObj
.Vel
.X
div 2)-2+Random(5),
5216 (FObj
.Vel
.Y
div 2)-2+Random(5));
5218 if FFlag
= FLAG_RED
then
5219 s
:= _lc
[I_PLAYER_FLAG_RED
]
5221 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5223 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_DROP
], [FName
, s
]), True);
5224 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_DROP
], [AnsiUpperCase(s
)]), 144);
5226 if g_Game_IsNet
then
5227 MH_SEND_FlagEvent(FLAG_STATE_DROPPED
, Flag
, FUID
, False);
5233 procedure TPlayer
.GetSecret();
5238 procedure TPlayer
.PressKey(Key
: Byte; Time
: Word = 1);
5240 Assert(Key
<= High(FKeys
));
5242 FKeys
[Key
].Pressed
:= True;
5243 FKeys
[Key
].Time
:= Time
;
5246 function TPlayer
.IsKeyPressed(K
: Byte): Boolean;
5248 Result
:= FKeys
[K
].Pressed
;
5251 procedure TPlayer
.ReleaseKeys();
5255 for a
:= Low(FKeys
) to High(FKeys
) do
5257 FKeys
[a
].Pressed
:= False;
5262 procedure TPlayer
.OnDamage(Angle
: SmallInt);
5266 function TPlayer
.firediry(): Integer;
5268 if FKeys
[KEY_UP
].Pressed
then Result
:= -42
5269 else if FKeys
[KEY_DOWN
].Pressed
then Result
:= 19
5273 procedure TPlayer
.RememberState();
5277 FSavedState
.Health
:= FHealth
;
5278 FSavedState
.Armor
:= FArmor
;
5279 FSavedState
.Air
:= FAir
;
5280 FSavedState
.JetFuel
:= FJetFuel
;
5281 FSavedState
.CurrWeap
:= FCurrWeap
;
5282 FSavedState
.NextWeap
:= FNextWeap
;
5283 FSavedState
.NextWeapDelay
:= FNextWeapDelay
;
5286 FSavedState
.Ammo
[i
] := FAmmo
[i
];
5288 FSavedState
.MaxAmmo
[i
] := FMaxAmmo
[i
];
5290 FSavedState
.Rulez
:= FRulez
;
5291 FSavedState
.WaitRecall
:= True;
5294 procedure TPlayer
.RecallState();
5298 if not FSavedState
.WaitRecall
then Exit
;
5300 FHealth
:= FSavedState
.Health
;
5301 FArmor
:= FSavedState
.Armor
;
5302 FAir
:= FSavedState
.Air
;
5303 FJetFuel
:= FSavedState
.JetFuel
;
5304 FCurrWeap
:= FSavedState
.CurrWeap
;
5305 FNextWeap
:= FSavedState
.NextWeap
;
5306 FNextWeapDelay
:= FSavedState
.NextWeapDelay
;
5309 FAmmo
[i
] := FSavedState
.Ammo
[i
];
5311 FMaxAmmo
[i
] := FSavedState
.MaxAmmo
[i
];
5313 FRulez
:= FSavedState
.Rulez
;
5314 FSavedState
.WaitRecall
:= False;
5316 if gGameSettings
.GameType
= GT_SERVER
then
5317 MH_SEND_PlayerStats(FUID
);
5320 procedure TPlayer
.SaveState(var Mem
: TBinMemoryWriter
);
5332 Mem
:= TBinMemoryWriter
.Create(i
);
5334 // Ñèãíàòóðà èãðîêà:
5335 sig
:= PLAYER_SIGNATURE
; // 'PLYR'
5336 Mem
.WriteDWORD(sig
);
5338 Mem
.WriteBoolean(FIamBot
);
5340 Mem
.WriteWord(FUID
);
5342 Mem
.WriteString(FName
, 32);
5344 Mem
.WriteByte(FTeam
);
5346 Mem
.WriteBoolean(FLive
);
5347 // Èçðàñõîäîâàë ëè âñå æèçíè:
5348 Mem
.WriteBoolean(FNoRespawn
);
5350 if FDirection
= D_LEFT
then
5356 Mem
.WriteInt(FHealth
);
5358 Mem
.WriteByte(FLives
);
5360 Mem
.WriteInt(FArmor
);
5364 Mem
.WriteInt(FJetFuel
);
5366 Mem
.WriteInt(FPain
);
5368 Mem
.WriteInt(FKills
);
5370 Mem
.WriteInt(FMonsterKills
);
5372 Mem
.WriteInt(FFrags
);
5374 Mem
.WriteByte(FFragCombo
);
5375 // Âðåìÿ ïîñëåäíåãî ôðàãà:
5376 Mem
.WriteDWORD(FLastFrag
);
5378 Mem
.WriteInt(FDeath
);
5379 // Êàêîé ôëàã íåñåò:
5380 Mem
.WriteByte(FFlag
);
5382 Mem
.WriteInt(FSecrets
);
5384 Mem
.WriteByte(FCurrWeap
);
5386 Mem
.WriteWord(FNextWeap
);
5388 Mem
.WriteByte(FNextWeapDelay
);
5389 // Âðåìÿ çàðÿäêè BFG:
5390 Mem
.WriteSmallInt(FBFGFireCounter
);
5392 Mem
.WriteInt(FDamageBuffer
);
5393 // Ïîñëåäíèé óäàðèâøèé:
5394 Mem
.WriteWord(FLastSpawnerUID
);
5395 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà:
5396 Mem
.WriteByte(FLastHit
);
5398 Obj_SaveState(@FObj
, Mem
);
5399 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ:
5400 for i
:= A_BULLETS
to A_HIGH
do
5401 Mem
.WriteWord(FAmmo
[i
]);
5402 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ:
5403 for i
:= A_BULLETS
to A_HIGH
do
5404 Mem
.WriteWord(FMaxAmmo
[i
]);
5406 for i
:= WP_FIRST
to WP_LAST
do
5407 Mem
.WriteBoolean(FWeapon
[i
]);
5408 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ:
5409 for i
:= WP_FIRST
to WP_LAST
do
5410 Mem
.WriteWord(FReloading
[i
]);
5412 if R_ITEM_BACKPACK
in FRulez
then
5417 // Íàëè÷èå êðàñíîãî êëþ÷à:
5418 if R_KEY_RED
in FRulez
then
5423 // Íàëè÷èå çåëåíîãî êëþ÷à:
5424 if R_KEY_GREEN
in FRulez
then
5429 // Íàëè÷èå ñèíåãî êëþ÷à:
5430 if R_KEY_BLUE
in FRulez
then
5435 // Íàëè÷èå áåðñåðêà:
5436 if R_BERSERK
in FRulez
then
5441 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ:
5442 for i
:= MR_SUIT
to MR_MAX
do
5443 Mem
.WriteDWORD(FMegaRulez
[i
]);
5444 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà:
5445 for i
:= T_RESPAWN
to T_FLAGCAP
do
5446 Mem
.WriteDWORD(FTime
[i
]);
5449 Mem
.WriteString(str
);
5459 procedure TPlayer
.LoadState(var Mem
: TBinMemoryReader
);
5469 // Ñèãíàòóðà èãðîêà:
5471 if sig
<> PLAYER_SIGNATURE
then // 'PLYR'
5473 raise EBinSizeError
.Create('TPlayer.LoadState: Wrong Player Signature');
5476 Mem
.ReadBoolean(FIamBot
);
5480 Mem
.ReadString(str
);
5481 if (Self
<> gPlayer1
) and (Self
<> gPlayer2
) then
5484 Mem
.ReadByte(FTeam
);
5486 Mem
.ReadBoolean(FLive
);
5487 // Èçðàñõîäîâàë ëè âñå æèçíè:
5488 Mem
.ReadBoolean(FNoRespawn
);
5492 FDirection
:= D_LEFT
5494 FDirection
:= D_RIGHT
;
5496 Mem
.ReadInt(FHealth
);
5498 Mem
.ReadByte(FLives
);
5500 Mem
.ReadInt(FArmor
);
5504 Mem
.ReadInt(FJetFuel
);
5508 Mem
.ReadInt(FKills
);
5510 Mem
.ReadInt(FMonsterKills
);
5512 Mem
.ReadInt(FFrags
);
5514 Mem
.ReadByte(FFragCombo
);
5515 // Âðåìÿ ïîñëåäíåãî ôðàãà:
5516 Mem
.ReadDWORD(FLastFrag
);
5518 Mem
.ReadInt(FDeath
);
5519 // Êàêîé ôëàã íåñåò:
5520 Mem
.ReadByte(FFlag
);
5522 Mem
.ReadInt(FSecrets
);
5524 Mem
.ReadByte(FCurrWeap
);
5526 Mem
.ReadWord(FNextWeap
);
5528 Mem
.ReadByte(FNextWeapDelay
);
5529 // Âðåìÿ çàðÿäêè BFG:
5530 Mem
.ReadSmallInt(FBFGFireCounter
);
5532 Mem
.ReadInt(FDamageBuffer
);
5533 // Ïîñëåäíèé óäàðèâøèé:
5534 Mem
.ReadWord(FLastSpawnerUID
);
5535 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà:
5536 Mem
.ReadByte(FLastHit
);
5538 Obj_LoadState(@FObj
, Mem
);
5539 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ:
5540 for i
:= A_BULLETS
to A_HIGH
do
5541 Mem
.ReadWord(FAmmo
[i
]);
5542 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ:
5543 for i
:= A_BULLETS
to A_HIGH
do
5544 Mem
.ReadWord(FMaxAmmo
[i
]);
5546 for i
:= WP_FIRST
to WP_LAST
do
5547 Mem
.ReadBoolean(FWeapon
[i
]);
5548 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ:
5549 for i
:= WP_FIRST
to WP_LAST
do
5550 Mem
.ReadWord(FReloading
[i
]);
5554 Include(FRulez
, R_ITEM_BACKPACK
);
5555 // Íàëè÷èå êðàñíîãî êëþ÷à:
5558 Include(FRulez
, R_KEY_RED
);
5559 // Íàëè÷èå çåëåíîãî êëþ÷à:
5562 Include(FRulez
, R_KEY_GREEN
);
5563 // Íàëè÷èå ñèíåãî êëþ÷à:
5566 Include(FRulez
, R_KEY_BLUE
);
5567 // Íàëè÷èå áåðñåðêà:
5570 Include(FRulez
, R_BERSERK
);
5571 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ:
5572 for i
:= MR_SUIT
to MR_MAX
do
5573 Mem
.ReadDWORD(FMegaRulez
[i
]);
5574 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà:
5575 for i
:= T_RESPAWN
to T_FLAGCAP
do
5576 Mem
.ReadDWORD(FTime
[i
]);
5578 Mem
.ReadString(str
);
5580 Mem
.ReadByte(FColor
.R
);
5581 Mem
.ReadByte(FColor
.G
);
5582 Mem
.ReadByte(FColor
.B
);
5583 if Self
= gPlayer1
then
5585 str
:= gPlayer1Settings
.Model
;
5586 FColor
:= gPlayer1Settings
.Color
;
5588 if Self
= gPlayer2
then
5590 str
:= gPlayer2Settings
.Model
;
5591 FColor
:= gPlayer2Settings
.Color
;
5593 // Îáíîâëÿåì ìîäåëü èãðîêà:
5595 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
5596 FModel
.Color
:= TEAMCOLOR
[FTeam
]
5598 FModel
.Color
:= FColor
;
5601 procedure TPlayer
.AllRulez(Health
: Boolean);
5607 FHealth
:= PLAYER_HP_LIMIT
;
5608 FArmor
:= PLAYER_AP_LIMIT
;
5612 for a
:= WP_FIRST
to WP_LAST
do FWeapon
[a
] := True;
5613 for a
:= A_BULLETS
to A_HIGH
do FAmmo
[a
] := 30000;
5614 FRulez
:= FRulez
+[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
];
5617 procedure TPlayer
.RestoreHealthArmor();
5619 FHealth
:= PLAYER_HP_LIMIT
;
5620 FArmor
:= PLAYER_AP_LIMIT
;
5623 procedure TPlayer
.FragCombo();
5627 if (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) or g_Game_IsClient
then
5629 if gTime
- FLastFrag
< FRAG_COMBO_TIME
then
5631 if FFragCombo
< 5 then
5633 Param
:= FUID
or (FFragCombo
shl 16);
5634 if (FComboEvnt
>= Low(gDelayedEvents
)) and
5635 (FComboEvnt
<= High(gDelayedEvents
)) and
5636 gDelayedEvents
[FComboEvnt
].Pending
and
5637 (gDelayedEvents
[FComboEvnt
].DEType
= DE_KILLCOMBO
) and
5638 (gDelayedEvents
[FComboEvnt
].DENum
and $FFFF = FUID
) then
5640 gDelayedEvents
[FComboEvnt
].Time
:= gTime
+ 500;
5641 gDelayedEvents
[FComboEvnt
].DENum
:= Param
;
5644 FComboEvnt
:= g_Game_DelayEvent(DE_KILLCOMBO
, 500, Param
);
5652 procedure TPlayer
.GiveItem(ItemType
: Byte);
5656 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
5658 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
5662 if FAir
< AIR_MAX
then
5669 if not (R_BERSERK
in FRulez
) then
5671 Include(FRulez
, R_BERSERK
);
5672 if FBFGFireCounter
< 1 then
5674 FCurrWeap
:= WEAPON_KASTET
;
5676 FModel
.SetWeapon(WEAPON_KASTET
);
5680 FBerserk
:= gTime
+30000;
5682 if FHealth
< PLAYER_HP_SOFT
then
5684 FHealth
:= PLAYER_HP_SOFT
;
5685 FBerserk
:= gTime
+30000;
5690 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
5692 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
5696 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
5698 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
5702 if FJetFuel
< JET_MAX
then
5704 FJetFuel
:= JET_MAX
;
5707 ITEM_MEDKIT_SMALL
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
5708 ITEM_MEDKIT_LARGE
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
5710 ITEM_ARMOR_GREEN
: if FArmor
< PLAYER_AP_SOFT
then FArmor
:= PLAYER_AP_SOFT
;
5711 ITEM_ARMOR_BLUE
: if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
5713 ITEM_SPHERE_BLUE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
5715 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) then
5717 if FHealth
< PLAYER_HP_LIMIT
then FHealth
:= PLAYER_HP_LIMIT
;
5718 if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
5721 ITEM_WEAPON_SAW
: FWeapon
[WEAPON_SAW
] := True;
5722 ITEM_WEAPON_SHOTGUN1
: FWeapon
[WEAPON_SHOTGUN1
] := True;
5723 ITEM_WEAPON_SHOTGUN2
: FWeapon
[WEAPON_SHOTGUN2
] := True;
5724 ITEM_WEAPON_CHAINGUN
: FWeapon
[WEAPON_CHAINGUN
] := True;
5725 ITEM_WEAPON_ROCKETLAUNCHER
: FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
5726 ITEM_WEAPON_PLASMA
: FWeapon
[WEAPON_PLASMA
] := True;
5727 ITEM_WEAPON_BFG
: FWeapon
[WEAPON_BFG
] := True;
5728 ITEM_WEAPON_SUPERPULEMET
: FWeapon
[WEAPON_SUPERPULEMET
] := True;
5730 ITEM_AMMO_BULLETS
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
5731 ITEM_AMMO_BULLETS_BOX
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
5732 ITEM_AMMO_SHELLS
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
5733 ITEM_AMMO_SHELLS_BOX
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
5734 ITEM_AMMO_ROCKET
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
5735 ITEM_AMMO_ROCKET_BOX
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
5736 ITEM_AMMO_CELL
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
5737 ITEM_AMMO_CELL_BIG
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
5740 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
5741 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
5742 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
5743 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) then
5745 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[1, A_BULLETS
];
5746 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[1, A_SHELLS
];
5747 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[1, A_ROCKETS
];
5748 FMaxAmmo
[A_CELLS
] := AmmoLimits
[1, A_CELLS
];
5750 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
5751 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
5752 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
5753 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
5755 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
5758 ITEM_KEY_RED
: if not (R_KEY_RED
in FRulez
) then Include(FRulez
, R_KEY_RED
);
5759 ITEM_KEY_GREEN
: if not (R_KEY_GREEN
in FRulez
) then Include(FRulez
, R_KEY_GREEN
);
5760 ITEM_KEY_BLUE
: if not (R_KEY_BLUE
in FRulez
) then Include(FRulez
, R_KEY_BLUE
);
5762 ITEM_BOTTLE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
5763 ITEM_HELMET
: if FArmor
< PLAYER_AP_LIMIT
then IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
5768 if g_Game_IsNet
and g_Game_IsServer
then
5769 MH_SEND_PlayerStats(FUID
);
5772 procedure TPlayer
.FlySmoke(Times
: DWORD
= 1);
5777 if (Random(5) = 1) and (Times
= 1) then
5780 if BodyInLiquid(0, 0) then
5782 g_GFX_Bubbles(Obj
.X
+Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2)+Random(3)-1,
5783 Obj
.Y
+Obj
.Rect
.Height
+8, 1, 8, 4);
5784 if Random(2) = 0 then
5785 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
5787 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
5791 if g_Frames_Get(id
, 'FRAMES_SMOKE') then
5793 for i
:= 1 to Times
do
5795 Anim
:= TAnimation
.Create(id
, False, 3);
5797 g_GFX_OnceAnim(Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(Anim
.Width
div 2),
5798 Obj
.Y
+Obj
.Rect
.Height
-4+Random(8+Times
*2), Anim
, ONCEANIM_SMOKE
);
5804 procedure TPlayer
.PauseSounds(Enable
: Boolean);
5806 FSawSound
.Pause(Enable
);
5807 FSawSoundIdle
.Pause(Enable
);
5808 FSawSoundHit
.Pause(Enable
);
5809 FSawSoundSelect
.Pause(Enable
);
5814 constructor TCorpse
.Create(X
, Y
: Integer; ModelName
: String; aMess
: Boolean);
5819 FObj
.Rect
:= PLAYER_CORPSERECT
;
5820 FModelName
:= ModelName
;
5825 FState
:= CORPSE_STATE_MESS
;
5826 g_PlayerModel_GetAnim(ModelName
, A_DIE2
, FAnimation
, FAnimationMask
);
5830 FState
:= CORPSE_STATE_NORMAL
;
5831 g_PlayerModel_GetAnim(ModelName
, A_DIE1
, FAnimation
, FAnimationMask
);
5835 destructor TCorpse
.Destroy();
5842 procedure TCorpse
.Damage(Value
: Word; vx
, vy
: Integer);
5846 if FState
= CORPSE_STATE_REMOVEME
then
5849 FDamage
:= FDamage
+ Value
;
5851 if FDamage
> 150 then
5853 if FAnimation
<> nil then
5858 FState
:= CORPSE_STATE_REMOVEME
;
5860 g_Player_CreateGibs(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
5861 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2),
5862 FModelName
, FColor
);
5863 // Çâóê ìÿñà îò òðóïà:
5864 pm
:= g_PlayerModel_Get(FModelName
);
5865 pm
.PlaySound(MODELSOUND_DIE
, 5, FObj
.X
, FObj
.Y
);
5871 FObj
.Vel
.X
:= FObj
.Vel
.X
+ vx
;
5872 FObj
.Vel
.Y
:= FObj
.Vel
.Y
+ vy
;
5873 g_GFX_Blood(FObj
.X
+PLAYER_CORPSERECT
.X
+(PLAYER_CORPSERECT
.Width
div 2),
5874 FObj
.Y
+PLAYER_CORPSERECT
.Y
+(PLAYER_CORPSERECT
.Height
div 2),
5875 Value
, vx
, vy
, 16, (PLAYER_CORPSERECT
.Height
*2) div 3,
5880 procedure TCorpse
.Draw();
5882 if FState
= CORPSE_STATE_REMOVEME
then
5885 if FAnimation
<> nil then
5886 FAnimation
.Draw(FObj
.X
, FObj
.Y
, M_NONE
);
5888 if FAnimationMask
<> nil then
5891 FAnimationMask
.Draw(FObj
.X
, FObj
.Y
, M_NONE
);
5898 procedure TCorpse
.Update();
5902 if FState
= CORPSE_STATE_REMOVEME
then
5905 if gTime
mod (GAME_TICK
*2) <> 0 then
5907 g_Obj_Move(@FObj
, True, True, True);
5912 // Ñîïðîòèâëåíèå âîçäóõà äëÿ òðóïà:
5913 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
5915 st
:= g_Obj_Move(@FObj
, True, True, True);
5917 if WordBool(st
and MOVE_FALLOUT
) then
5919 FState
:= CORPSE_STATE_REMOVEME
;
5923 if FAnimation
<> nil then
5924 FAnimation
.Update();
5925 if FAnimationMask
<> nil then
5926 FAnimationMask
.Update();
5929 procedure TCorpse
.SaveState(var Mem
: TBinMemoryWriter
);
5938 sig
:= CORPSE_SIGNATURE
; // 'CORP'
5939 Mem
.WriteDWORD(sig
);
5941 Mem
.WriteByte(FState
);
5942 // Íàêîïëåííûé óðîí:
5943 Mem
.WriteByte(FDamage
);
5945 Mem
.WriteByte(FColor
.R
);
5946 Mem
.WriteByte(FColor
.G
);
5947 Mem
.WriteByte(FColor
.B
);
5949 Obj_SaveState(@FObj
, Mem
);
5950 // Åñòü ëè àíèìàöèÿ:
5951 anim
:= FAnimation
<> nil;
5952 Mem
.WriteBoolean(anim
);
5953 // Åñëè åñòü - ñîõðàíÿåì:
5955 FAnimation
.SaveState(Mem
);
5956 // Åñòü ëè ìàñêà àíèìàöèè:
5957 anim
:= FAnimationMask
<> nil;
5958 Mem
.WriteBoolean(anim
);
5959 // Åñëè åñòü - ñîõðàíÿåì:
5961 FAnimationMask
.SaveState(Mem
);
5964 procedure TCorpse
.LoadState(var Mem
: TBinMemoryReader
);
5974 if sig
<> CORPSE_SIGNATURE
then // 'CORP'
5976 raise EBinSizeError
.Create('TCorpse.LoadState: Wrong Corpse Signature');
5979 Mem
.ReadByte(FState
);
5980 // Íàêîïëåííûé óðîí:
5981 Mem
.ReadByte(FDamage
);
5983 Mem
.ReadByte(FColor
.R
);
5984 Mem
.ReadByte(FColor
.G
);
5985 Mem
.ReadByte(FColor
.B
);
5987 Obj_LoadState(@FObj
, Mem
);
5988 // Åñòü ëè àíèìàöèÿ:
5989 Mem
.ReadBoolean(anim
);
5990 // Åñëè åñòü - çàãðóæàåì:
5993 Assert(FAnimation
<> nil, 'TCorpse.LoadState: no FAnimation');
5994 FAnimation
.LoadState(Mem
);
5996 // Åñòü ëè ìàñêà àíèìàöèè:
5997 Mem
.ReadBoolean(anim
);
5998 // Åñëè åñòü - çàãðóæàåì:
6001 Assert(FAnimationMask
<> nil, 'TCorpse.LoadState: no FAnimationMask');
6002 FAnimationMask
.LoadState(Mem
);
6008 constructor TBot
.Create();
6015 FSpectator
:= False;
6022 for a
:= WP_FIRST
to WP_LAST
do
6024 FDifficult
.WeaponPrior
[a
] := WEAPON_PRIOR1
[a
];
6025 FDifficult
.CloseWeaponPrior
[a
] := WEAPON_PRIOR2
[a
];
6026 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
6030 destructor TBot
.Destroy();
6033 inherited Destroy();
6036 procedure TBot
.Draw();
6040 //if FTargetUID <> 0 then e_DrawLine(1, FObj.X, FObj.Y, g_Player_Get(FTargetUID).FObj.X,
6041 // g_Player_Get(FTargetUID).FObj.Y, 255, 0, 0);
6044 procedure TBot
.Respawn(Silent
: Boolean; Force
: Boolean = False);
6046 inherited Respawn(Silent
, Force
);
6049 FSelectedWeapon
:= FCurrWeap
;
6054 procedure TBot
.UpdateCombat();
6067 TTargetRecord
= array of TTarget
;
6069 function Compare(a
, b
: TTarget
): Integer;
6071 if a
.Line
and not b
.Line
then // A íà ëèíèè îãíÿ
6074 if not a
.Line
and b
.Line
then // B íà ëèíèè îãíÿ
6076 else // È A, è B íà ëèíèè èëè íå íà ëèíèè îãíÿ
6077 if (a
.Line
and b
.Line
) or ((not a
.Line
) and (not b
.Line
)) then
6079 if a
.Dist
> b
.Dist
then // B áëèæå
6081 else // A áëèæå èëè ðàâíîóäàëåííî ñ B
6084 else // Ñòðàííî -> A
6089 a
, x1
, y1
, x2
, y2
: Integer;
6090 targets
: TTargetRecord
;
6092 Target
, BestTarget
: TTarget
;
6093 firew
, fireh
: Integer;
6097 vsPlayer
, vsMonster
, ok
: Boolean;
6099 vsPlayer
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
);
6100 vsMonster
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
);
6102 // Åñëè òåêóùåå îðóæèå íå òî, ÷òî íóæíî, òî ìåíÿåì:
6103 if FCurrWeap
<> FSelectedWeapon
then
6106 // Åñëè íóæíî ñòðåëÿòü è íóæíîå îðóæèå, òî íàæàòü "Ñòðåëÿòü":
6107 if (GetAIFlag('NEEDFIRE') <> '') and (FCurrWeap
= FSelectedWeapon
) then
6109 RemoveAIFlag('NEEDFIRE');
6112 WEAPON_PLASMA
, WEAPON_SUPERPULEMET
, WEAPON_CHAINGUN
: PressKey(KEY_FIRE
, 20);
6113 WEAPON_SAW
, WEAPON_KASTET
, WEAPON_MEGAKASTET
: PressKey(KEY_FIRE
, 40);
6114 else PressKey(KEY_FIRE
);
6118 // Êîîðäèíàòû ñòâîëà:
6119 x1
:= FObj
.X
+ WEAPONPOINT
[FDirection
].X
;
6120 y1
:= FObj
.Y
+ WEAPONPOINT
[FDirection
].Y
;
6122 Target
.UID
:= FTargetUID
;
6125 if Target
.UID
<> 0 then
6126 begin // Öåëü åñòü - íàñòðàèâàåì
6127 if (g_GetUIDType(Target
.UID
) = UID_PLAYER
) and
6130 with g_Player_Get(Target
.UID
) do
6132 if (@FObj
) <> nil then
6139 Target
.cX
:= Target
.X
+ PLAYER_RECT_CX
;
6140 Target
.cY
:= Target
.Y
+ PLAYER_RECT_CY
;
6141 Target
.Rect
:= PLAYER_RECT
;
6142 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6143 Target
.Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6144 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6145 Target
.IsPlayer
:= True;
6149 if (g_GetUIDType(Target
.UID
) = UID_MONSTER
) and
6152 mon
:= g_Monsters_Get(Target
.UID
);
6155 Target
.X
:= mon
.Obj
.X
;
6156 Target
.Y
:= mon
.Obj
.Y
;
6158 Target
.cX
:= Target
.X
+ mon
.Obj
.Rect
.X
+ (mon
.Obj
.Rect
.Width
div 2);
6159 Target
.cY
:= Target
.Y
+ mon
.Obj
.Rect
.Y
+ (mon
.Obj
.Rect
.Height
div 2);
6160 Target
.Rect
:= mon
.Obj
.Rect
;
6161 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6162 Target
.Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6163 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6164 Target
.IsPlayer
:= False;
6171 begin // Öåëè íåò - îáíóëÿåì
6176 Target
.Visible
:= False;
6177 Target
.Line
:= False;
6178 Target
.IsPlayer
:= False;
6183 // Åñëè öåëü íå âèäèìà èëè íå íà ëèíèè îãíÿ, òî èùåì âñå âîçìîæíûå öåëè:
6184 if (not Target
.Line
) or (not Target
.Visible
) then
6188 for a
:= 0 to High(gPlayers
) do
6189 if (gPlayers
[a
] <> nil) and (gPlayers
[a
].Live
) and
6190 (gPlayers
[a
].FUID
<> FUID
) and
6191 (not SameTeam(FUID
, gPlayers
[a
].FUID
)) and
6192 (not gPlayers
[a
].NoTarget
) and
6193 (gPlayers
[a
].FMegaRulez
[MR_INVIS
] < gTime
) then
6195 if not TargetOnScreen(gPlayers
[a
].FObj
.X
+ PLAYER_RECT
.X
,
6196 gPlayers
[a
].FObj
.Y
+ PLAYER_RECT
.Y
) then
6199 x2
:= gPlayers
[a
].FObj
.X
+ PLAYER_RECT_CX
;
6200 y2
:= gPlayers
[a
].FObj
.Y
+ PLAYER_RECT_CY
;
6202 // Åñëè èãðîê íà ýêðàíå è íå ïðèêðûò ñòåíîé:
6203 if g_TraceVector(x1
, y1
, x2
, y2
) then
6205 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé:
6206 SetLength(targets
, Length(targets
)+1);
6207 with targets
[High(targets
)] do
6209 UID
:= gPlayers
[a
].FUID
;
6210 X
:= gPlayers
[a
].FObj
.X
;
6211 Y
:= gPlayers
[a
].FObj
.Y
;
6214 Rect
:= PLAYER_RECT
;
6215 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6216 Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6217 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6225 if vsMonster
and (gMonsters
<> nil) then
6226 for a
:= 0 to High(gMonsters
) do
6227 if (gMonsters
[a
] <> nil) and (gMonsters
[a
].Live
) and
6228 (gMonsters
[a
].MonsterType
<> MONSTER_BARREL
) then
6230 mon
:= gMonsters
[a
];
6232 if not TargetOnScreen(mon
.Obj
.X
+ mon
.Obj
.Rect
.X
,
6233 mon
.Obj
.Y
+ mon
.Obj
.Rect
.Y
) then
6236 x2
:= mon
.Obj
.X
+ mon
.Obj
.Rect
.X
+ (mon
.Obj
.Rect
.Width
div 2);
6237 y2
:= mon
.Obj
.Y
+ mon
.Obj
.Rect
.Y
+ (mon
.Obj
.Rect
.Height
div 2);
6239 // Åñëè ìîíñòð íà ýêðàíå è íå ïðèêðûò ñòåíîé:
6240 if g_TraceVector(x1
, y1
, x2
, y2
) then
6242 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé:
6243 SetLength(targets
, Length(targets
)+1);
6244 with targets
[High(targets
)] do
6251 Rect
:= mon
.Obj
.Rect
;
6252 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6253 Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6254 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6262 // Åñëè åñòü âîçìîæíûå öåëè:
6263 // (Âûáèðàåì ëó÷øóþ, ìåíÿåì îðóæèå è áåæèì ê íåé/îò íåå)
6264 if targets
<> nil then
6266 // Âûáèðàåì íàèëó÷øóþ öåëü:
6267 BestTarget
:= targets
[0];
6268 if Length(targets
) > 1 then
6269 for a
:= 1 to High(targets
) do
6270 if Compare(BestTarget
, targets
[a
]) = 1 then
6271 BestTarget
:= targets
[a
];
6273 // Åñëè ëó÷øàÿ öåëü "âèäíåå" òåêóùåé, òî òåêóùàÿ := ëó÷øàÿ:
6274 if ((not Target
.Visible
) and BestTarget
.Visible
and (Target
.UID
<> BestTarget
.UID
)) or
6275 ((not Target
.Line
) and BestTarget
.Line
and BestTarget
.Visible
) then
6277 Target
:= BestTarget
;
6279 if (Healthy() = 3) or ((Healthy() = 2)) then
6280 begin // Åñëè çäîðîâû - äîãîíÿåì
6281 if ((RunDirection() = D_LEFT
) and (Target
.X
> FObj
.X
)) then
6282 SetAIFlag('GORIGHT', '1');
6283 if ((RunDirection() = D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6284 SetAIFlag('GOLEFT', '1');
6287 begin // Åñëè ïîáèòû - óáåãàåì
6288 if ((RunDirection() = D_LEFT
) and (Target
.X
< FObj
.X
)) then
6289 SetAIFlag('GORIGHT', '1');
6290 if ((RunDirection() = D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6291 SetAIFlag('GOLEFT', '1');
6294 // Âûáèðàåì îðóæèå íà îñíîâå ðàññòîÿíèÿ è ïðèîðèòåòîâ:
6295 SelectWeapon(Abs(x1
-Target
.cX
));
6300 // (Äîãîíÿåì/óáåãàåì, ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëè)
6301 // (Åñëè öåëü äàëåêî, òî õâàòèò ñëåäèòü çà íåé)
6302 if Target
.UID
<> 0 then
6304 if not TargetOnScreen(Target
.X
+ Target
.Rect
.X
,
6305 Target
.Y
+ Target
.Rect
.Y
) then
6306 begin // Öåëü ñáåæàëà ñ "ýêðàíà"
6307 if (Healthy() = 3) or ((Healthy() = 2)) then
6308 begin // Åñëè çäîðîâû - äîãîíÿåì
6309 if ((RunDirection() = D_LEFT
) and (Target
.X
> FObj
.X
)) then
6310 SetAIFlag('GORIGHT', '1');
6311 if ((RunDirection() = D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6312 SetAIFlag('GOLEFT', '1');
6315 begin // Åñëè ïîáèòû - çàáûâàåì î öåëè è óáåãàåì
6317 if ((RunDirection() = D_LEFT
) and (Target
.X
< FObj
.X
)) then
6318 SetAIFlag('GORIGHT', '1');
6319 if ((RunDirection() = D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6320 SetAIFlag('GOLEFT', '1');
6324 begin // Öåëü ïîêà íà "ýêðàíå"
6325 // Åñëè öåëü íå çàãîðîæåíà ñòåíîé, òî îòìå÷àåì, êîãäà åå âèäåëè:
6326 if g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6327 FLastVisible
:= gTime
;
6328 // Åñëè ðàçíèöà âûñîò íå âåëèêà, òî äîãîíÿåì:
6329 if (Abs(FObj
.Y
-Target
.Y
) <= 128) then
6331 if ((RunDirection() = D_LEFT
) and (Target
.X
> FObj
.X
)) then
6332 SetAIFlag('GORIGHT', '1');
6333 if ((RunDirection() = D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6334 SetAIFlag('GOLEFT', '1');
6338 // Âûáèðàåì óãîë ââåðõ:
6339 if FDirection
= D_LEFT
then
6340 angle
:= ANGLE_LEFTUP
6342 angle
:= ANGLE_RIGHTUP
;
6344 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6345 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6347 // Åñëè ïðè óãëå ââåðõ ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
6348 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6349 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128), //96
6350 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6351 Target
.Rect
.Width
, Target
.Rect
.Height
) and
6352 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6353 begin // òî íóæíî ñòðåëÿòü ââåðõ
6354 SetAIFlag('NEEDFIRE', '1');
6355 SetAIFlag('NEEDSEEUP', '1');
6358 // Âûáèðàåì óãîë âíèç:
6359 if FDirection
= D_LEFT
then
6360 angle
:= ANGLE_LEFTDOWN
6362 angle
:= ANGLE_RIGHTDOWN
;
6364 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6365 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6367 // Åñëè ïðè óãëå âíèç ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
6368 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6369 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
6370 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6371 Target
.Rect
.Width
, Target
.Rect
.Height
) and
6372 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6373 begin // òî íóæíî ñòðåëÿòü âíèç
6374 SetAIFlag('NEEDFIRE', '1');
6375 SetAIFlag('NEEDSEEDOWN', '1');
6378 // Åñëè öåëü âèäíî è îíà íà òàêîé æå âûñîòå:
6379 if Target
.Visible
and
6380 (y1
+4 < Target
.Y
+Target
.Rect
.Y
+Target
.Rect
.Height
) and
6381 (y1
-4 > Target
.Y
+Target
.Rect
.Y
) then
6383 // Åñëè èäåì â ñòîðîíó öåëè, òî íàäî ñòðåëÿòü:
6384 if ((FDirection
= D_LEFT
) and (Target
.X
< FObj
.X
)) or
6385 ((FDirection
= D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6386 begin // òî íóæíî ñòðåëÿòü âïåðåä
6387 SetAIFlag('NEEDFIRE', '1');
6388 SetAIFlag('NEEDSEEDOWN', '');
6389 SetAIFlag('NEEDSEEUP', '');
6391 // Åñëè öåëü â ïðåäåëàõ "ýêðàíà" è ñëîæíîñòü ïîçâîëÿåò ïðûæêè ñáëèæåíèÿ:
6392 if Abs(FObj
.X
-Target
.X
) < Trunc(gPlayerScreenSize
.X
*0.75) then
6393 if GetRnd(FDifficult
.CloseJump
) then
6394 begin // òî åñëè ïîâåçåò - ïðûãàåì (îñîáåííî, åñëè áëèçêî)
6395 if Abs(FObj
.X
-Target
.X
) < 128 then
6399 if Random(a
) = 0 then
6400 SetAIFlag('NEEDJUMP', '1');
6404 // Åñëè öåëü âñå åùå åñòü:
6405 if Target
.UID
<> 0 then
6406 if gTime
-FLastVisible
> 2000 then // Åñëè âèäåëè äàâíî
6407 Target
.UID
:= 0 // òî çàáûòü öåëü
6408 else // Åñëè âèäåëè íåäàâíî
6409 begin // íî öåëü óáèëè
6410 if Target
.IsPlayer
then
6411 begin // Öåëü - èãðîê
6412 pla
:= g_Player_Get(Target
.UID
);
6413 if (pla
= nil) or (not pla
.Live
) or pla
.NoTarget
or
6414 (pla
.FMegaRulez
[MR_INVIS
] >= gTime
) then
6415 Target
.UID
:= 0; // òî çàáûòü öåëü
6418 begin // Öåëü - ìîíñòð
6419 mon
:= g_Monsters_Get(Target
.UID
);
6420 if (mon
= nil) or (not mon
.Live
) then
6421 Target
.UID
:= 0; // òî çàáûòü öåëü
6424 end; // if Target.UID <> 0
6426 FTargetUID
:= Target
.UID
;
6428 // Åñëè âîçìîæíûõ öåëåé íåò:
6429 // (Àòàêà ÷åãî-íèáóäü ñëåâà èëè ñïðàâà)
6430 if targets
= nil then
6431 if GetAIFlag('ATTACKLEFT') <> '' then
6432 begin // Åñëè íóæíî àòàêîâàòü íàëåâî
6433 RemoveAIFlag('ATTACKLEFT');
6435 SetAIFlag('NEEDJUMP', '1');
6437 if RunDirection() = D_RIGHT
then
6438 begin // Èäåì íå â òó ñòîðîíó
6439 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
6440 begin // Åñëè çäîðîâû, òî, âîçìîæíî, ñòðåëÿåì áåæèì âëåâî è ñòðåëÿåì
6441 SetAIFlag('NEEDFIRE', '1');
6442 SetAIFlag('GOLEFT', '1');
6446 begin // Èäåì â íóæíóþ ñòîðîíó
6447 if GetRnd(FDifficult
.InvisFire
) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
6448 SetAIFlag('NEEDFIRE', '1');
6449 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
6450 SetAIFlag('GORIGHT', '1');
6454 if GetAIFlag('ATTACKRIGHT') <> '' then
6455 begin // Åñëè íóæíî àòàêîâàòü íàïðàâî
6456 RemoveAIFlag('ATTACKRIGHT');
6458 SetAIFlag('NEEDJUMP', '1');
6460 if RunDirection() = D_LEFT
then
6461 begin // Èäåì íå â òó ñòîðîíó
6462 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
6463 begin // Åñëè çäîðîâû, òî, âîçìîæíî, áåæèì âïðàâî è ñòðåëÿåì
6464 SetAIFlag('NEEDFIRE', '1');
6465 SetAIFlag('GORIGHT', '1');
6470 if GetRnd(FDifficult
.InvisFire
) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
6471 SetAIFlag('NEEDFIRE', '1');
6472 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
6473 SetAIFlag('GOLEFT', '1');
6477 //HACK! (does it belongs there?)
6478 RealizeCurrentWeapon();
6480 // Åñëè åñòü âîçìîæíûå öåëè:
6481 // (Ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëÿì)
6482 if (targets
<> nil) and (GetAIFlag('NEEDFIRE') <> '') then
6483 for a
:= 0 to High(targets
) do
6485 // Åñëè ìîæåì ñòðåëÿòü ïî äèàãîíàëè:
6486 if GetRnd(FDifficult
.DiagFire
) then
6488 // Èùåì öåëü ñâåðõó è ñòðåëÿåì, åñëè åñòü:
6489 if FDirection
= D_LEFT
then
6490 angle
:= ANGLE_LEFTUP
6492 angle
:= ANGLE_RIGHTUP
;
6494 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6495 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6497 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6498 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
6499 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6500 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
6501 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
6503 SetAIFlag('NEEDFIRE', '1');
6504 SetAIFlag('NEEDSEEUP', '1');
6507 // Èùåì öåëü ñíèçó è ñòðåëÿåì, åñëè åñòü:
6508 if FDirection
= D_LEFT
then
6509 angle
:= ANGLE_LEFTDOWN
6511 angle
:= ANGLE_RIGHTDOWN
;
6513 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6514 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6516 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6517 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
6518 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6519 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
6520 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
6522 SetAIFlag('NEEDFIRE', '1');
6523 SetAIFlag('NEEDSEEDOWN', '1');
6527 // Åñëè öåëü "ïåðåä íîñîì", òî ñòðåëÿåì:
6528 if targets
[a
].Line
and targets
[a
].Visible
and
6529 (((FDirection
= D_LEFT
) and (targets
[a
].X
< FObj
.X
)) or
6530 ((FDirection
= D_RIGHT
) and (targets
[a
].X
> FObj
.X
))) then
6532 SetAIFlag('NEEDFIRE', '1');
6537 // Åñëè ëåòèò ïóëÿ, òî, âîçìîæíî, ïîäïðûãèâàåì:
6538 if g_Weapon_Danger(FUID
, FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
,
6539 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
,
6540 40+GetInterval(FDifficult
.Cover
, 40)) then
6541 SetAIFlag('NEEDJUMP', '1');
6543 // Åñëè êîí÷èëèñü ïàòîðíû, òî íóæíî ñìåíèòü îðóæèå:
6544 ammo
:= GetAmmoByWeapon(FCurrWeap
);
6545 if ((FCurrWeap
= WEAPON_SHOTGUN2
) and (ammo
< 2)) or
6546 ((FCurrWeap
= WEAPON_BFG
) and (ammo
< 40)) or
6548 SetAIFlag('SELECTWEAPON', '1');
6550 // Åñëè íóæíî ñìåíèòü îðóæèå, òî âûáèðàåì íóæíîå:
6551 if GetAIFlag('SELECTWEAPON') = '1' then
6554 RemoveAIFlag('SELECTWEAPON');
6558 procedure TBot
.Update();
6571 // Ïðîâåðÿåì, îòêëþ÷¸í ëè AI áîòîâ
6572 if (g_debug_BotAIOff
= 1) and (Team
= TEAM_RED
) then
6574 if (g_debug_BotAIOff
= 2) and (Team
= TEAM_BLUE
) then
6576 if g_debug_BotAIOff
= 3 then
6586 RealizeCurrentWeapon();
6593 procedure TBot
.ReleaseKey(Key
: Byte);
6602 function TBot
.KeyPressed(Key
: Word): Boolean;
6604 Result
:= FKeys
[Key
].Pressed
;
6607 function TBot
.GetAIFlag(fName
: String20
): String20
;
6613 fName
:= LowerCase(fName
);
6615 if FAIFlags
<> nil then
6616 for a
:= 0 to High(FAIFlags
) do
6617 if LowerCase(FAIFlags
[a
].Name
) = fName
then
6619 Result
:= FAIFlags
[a
].Value
;
6624 procedure TBot
.RemoveAIFlag(fName
: String20
);
6628 if FAIFlags
= nil then Exit
;
6630 fName
:= LowerCase(fName
);
6632 for a
:= 0 to High(FAIFlags
) do
6633 if LowerCase(FAIFlags
[a
].Name
) = fName
then
6635 if a
<> High(FAIFlags
) then
6636 for b
:= a
to High(FAIFlags
)-1 do
6637 FAIFlags
[b
] := FAIFlags
[b
+1];
6639 SetLength(FAIFlags
, Length(FAIFlags
)-1);
6644 procedure TBot
.SetAIFlag(fName
, fValue
: String20
);
6652 fName
:= LowerCase(fName
);
6654 if FAIFlags
<> nil then
6655 for a
:= 0 to High(FAIFlags
) do
6656 if LowerCase(FAIFlags
[a
].Name
) = fName
then
6662 if ok
then FAIFlags
[a
].Value
:= fValue
6665 SetLength(FAIFlags
, Length(FAIFlags
)+1);
6666 with FAIFlags
[High(FAIFlags
)] do
6674 procedure TBot
.UpdateMove
;
6676 procedure GoLeft(Time
: Word = 1);
6678 ReleaseKey(KEY_LEFT
);
6679 ReleaseKey(KEY_RIGHT
);
6680 PressKey(KEY_LEFT
, Time
);
6681 SetDirection(D_LEFT
);
6684 procedure GoRight(Time
: Word = 1);
6686 ReleaseKey(KEY_LEFT
);
6687 ReleaseKey(KEY_RIGHT
);
6688 PressKey(KEY_RIGHT
, Time
);
6689 SetDirection(D_RIGHT
);
6692 function Rnd(a
: Word): Boolean;
6694 Result
:= Random(a
) = 0;
6697 procedure Turn(Time
: Word = 1200);
6699 if RunDirection() = D_LEFT
then GoRight(Time
) else GoLeft(Time
);
6704 ReleaseKey(KEY_LEFT
);
6705 ReleaseKey(KEY_RIGHT
);
6708 function CanRunLeft(): Boolean;
6710 Result
:= not CollideLevel(-1, 0);
6713 function CanRunRight(): Boolean;
6715 Result
:= not CollideLevel(1, 0);
6718 function CanRun(): Boolean;
6720 if RunDirection() = D_LEFT
then Result
:= CanRunLeft() else Result
:= CanRunRight();
6723 procedure Jump(Time
: Word = 30);
6725 PressKey(KEY_JUMP
, Time
);
6728 function NearHole(): Boolean;
6732 { TODO 5 : Ëåñòíèöû }
6733 sx
:= IfThen(RunDirection() = D_LEFT
, -1, 1);
6734 for x
:= 1 to PLAYER_RECT
.Width
do
6735 if (not StayOnStep(x
*sx
, 0)) and
6736 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
6737 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
6746 function BorderHole(): Boolean;
6750 { TODO 5 : Ëåñòíèöû }
6751 sx
:= IfThen(RunDirection() = D_LEFT
, -1, 1);
6752 for x
:= 1 to PLAYER_RECT
.Width
do
6753 if (not StayOnStep(x
*sx
, 0)) and
6754 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
6755 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
6757 for xx
:= x
to x
+32 do
6758 if CollideLevel(xx
*sx
, PLAYER_RECT
.Height
) then
6768 function NearDeepHole(): Boolean;
6774 sx
:= IfThen(RunDirection() = D_LEFT
, -1, 1);
6777 for x
:= 1 to PLAYER_RECT
.Width
do
6778 if (not StayOnStep(x
*sx
, 0)) and
6779 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
6780 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
6782 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
6784 if CollideLevel(x
*sx
, PLAYER_RECT
.Height
*y
) then Exit
;
6789 end else Result
:= False;
6792 function OverDeepHole(): Boolean;
6799 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
6801 if CollideLevel(0, PLAYER_RECT
.Height
*y
) then Exit
;
6808 function OnGround(): Boolean;
6810 Result
:= StayOnStep(0, 0) or CollideLevel(0, 1);
6813 function OnLadder(): Boolean;
6815 Result
:= FullInStep(0, 0);
6818 function BelowLadder(): Boolean;
6820 Result
:= (FullInStep(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) and
6821 not CollideLevel(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
6822 (FullInStep(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) and
6823 not CollideLevel(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
6826 function BelowLiftUp(): Boolean;
6828 Result
:= ((FullInLift(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) = -1) and
6829 not CollideLevel(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
6830 ((FullInLift(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) = -1) and
6831 not CollideLevel(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
6834 function OnTopLift(): Boolean;
6836 Result
:= (FullInLift(0, 0) = -1) and (FullInLift(0, -32) = 0);
6839 function CanJumpOver(): Boolean;
6843 sx
:= IfThen(RunDirection() = D_LEFT
, -1, 1);
6847 if not CollideLevel(sx
, 0) then Exit
;
6849 for y
:= 1 to BOT_MAXJUMP
do
6850 if CollideLevel(0, -y
) then Exit
else
6851 if not CollideLevel(sx
, -y
) then
6858 function CanJumpUp(Dist
: ShortInt): Boolean;
6865 if CollideLevel(Dist
, 0) then Exit
;
6868 for y
:= 0 to BOT_MAXJUMP
do
6869 if CollideLevel(Dist
, -y
) then
6878 for yy
:= y
+1 to BOT_MAXJUMP
do
6879 if not CollideLevel(Dist
, -yy
) then
6888 for y
:= 0 to BOT_MAXJUMP
do
6889 if CollideLevel(0, -y
) then
6897 if y
< yy
then Exit
;
6902 function IsSafeTrigger(): Boolean;
6907 if gTriggers
= nil then
6909 for a
:= 0 to High(gTriggers
) do
6910 if Collide(gTriggers
[a
].X
,
6913 gTriggers
[a
].Height
) and
6914 (gTriggers
[a
].TriggerType
in [TRIGGER_EXIT
, TRIGGER_CLOSEDOOR
,
6915 TRIGGER_CLOSETRAP
, TRIGGER_TRAP
,
6916 TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
,
6917 TRIGGER_ONOFF
, TRIGGER_SPAWNMONSTER
,
6918 TRIGGER_DAMAGE
, TRIGGER_SHOT
]) then
6923 // Âîçìîæíî, íàæèìàåì êíîïêó:
6924 if Rnd(16) and IsSafeTrigger() then
6927 // Åñëè ïîä ëèôòîì èëè ñòóïåíüêàìè, òî, âîçìîæíî, ïðûãàåì:
6928 if OnLadder() or ((BelowLadder() or BelowLiftUp()) and Rnd(8)) then
6930 ReleaseKey(KEY_LEFT
);
6931 ReleaseKey(KEY_RIGHT
);
6935 // Èäåì âëåâî, åñëè íàäî áûëî:
6936 if GetAIFlag('GOLEFT') <> '' then
6938 RemoveAIFlag('GOLEFT');
6939 if CanRunLeft() then
6943 // Èäåì âïðàâî, åñëè íàäî áûëî:
6944 if GetAIFlag('GORIGHT') <> '' then
6946 RemoveAIFlag('GORIGHT');
6947 if CanRunRight() then
6951 // Åñëè âûëåòåëè çà êàðòó, òî ïðîáóåì âåðíóòüñÿ:
6952 if FObj
.X
< -32 then
6955 if FObj
.X
+32 > gMapInfo
.Width
then
6958 // Ïðûãàåì, åñëè íàäî áûëî:
6959 if GetAIFlag('NEEDJUMP') <> '' then
6962 RemoveAIFlag('NEEDJUMP');
6965 // Ñìîòðèì ââåðõ, åñëè íàäî áûëî:
6966 if GetAIFlag('NEEDSEEUP') <> '' then
6969 ReleaseKey(KEY_DOWN
);
6970 PressKey(KEY_UP
, 20);
6971 RemoveAIFlag('NEEDSEEUP');
6974 // Ñìîòðèì âíèç, åñëè íàäî áûëî:
6975 if GetAIFlag('NEEDSEEDOWN') <> '' then
6978 ReleaseKey(KEY_DOWN
);
6979 PressKey(KEY_DOWN
, 20);
6980 RemoveAIFlag('NEEDSEEDOWN');
6983 // Åñëè íóæíî áûëî â äûðó è ìû íå íà çåìëå, òî ïîêîðíî ëåòèì:
6984 if GetAIFlag('GOINHOLE') <> '' then
6985 if not OnGround() then
6987 ReleaseKey(KEY_LEFT
);
6988 ReleaseKey(KEY_RIGHT
);
6989 RemoveAIFlag('GOINHOLE');
6990 SetAIFlag('FALLINHOLE', '1');
6993 // Åñëè ïàäàëè è äîñòèãëè çåìëè, òî õâàòèò ïàäàòü:
6994 if GetAIFlag('FALLINHOLE') <> '' then
6996 RemoveAIFlag('FALLINHOLE');
6998 // Åñëè ëåòåëè ïðÿìî è ñåé÷àñ íå íà ëåñòíèöå èëè íà âåðøèíå ëèôòà, òî îòõîäèì â ñòîðîíó:
6999 if not (KeyPressed(KEY_LEFT
) or KeyPressed(KEY_RIGHT
)) then
7000 if GetAIFlag('FALLINHOLE') = '' then
7001 if (not OnLadder()) or (FObj
.Vel
.Y
>= 0) or (OnTopLift()) then
7007 // Åñëè íà çåìëå è ìîæíî ïîäïðûãíóòü, òî, âîçìîæíî, ïðûãàåì:
7009 CanJumpUp(IfThen(RunDirection() = D_LEFT
, -1, 1)*32) and
7013 // Åñëè íà çåìëå è âîçëå äûðû (ãëóáèíà > 2 ðîñòîâ èãðîêà):
7014 if OnGround() and NearHole() then
7015 if NearDeepHole() then // Åñëè ýòî áåçäíà
7017 0..3: Turn(); // Áåæèì îáðàòíî
7018 4: Jump(); // Ïðûãàåì
7019 5: begin // Ïðûãàåì îáðàòíî
7024 else // Ýòî íå áåçäíà è ìû åùå íå ëåòèì òóäà
7025 if GetAIFlag('GOINHOLE') = '' then
7027 0: Turn(); // Íå íóæíî òóäà
7028 1: Jump(); // Âäðóã ïîâåçåò - ïðûãàåì
7029 else // Åñëè ÿìà ñ ãðàíèöåé, òî ïðè ñëó÷àå ìîæíî òóäà ïðûãíóòü
7030 if BorderHole() then
7031 SetAIFlag('GOINHOLE', '1');
7034 // Åñëè íà çåìëå, íî íåêóäà èäòè:
7035 if (not CanRun()) and OnGround() then
7037 // Åñëè ìû íà ëåñòíèöå èëè ìîæíî ïåðåïðûãíóòü, òî ïðûãàåì:
7038 if CanJumpOver() or OnLadder() then
7040 else // èíà÷å ïîïûòàåìñÿ â äðóãóþ ñòîðîíó
7041 if Random(2) = 0 then
7043 if IsSafeTrigger() then
7049 // Îñòàëîñü ìàëî âîçäóõà:
7050 if FAir
< 36 * 2 then
7053 // Âûáèðàåìñÿ èç êèñëîòû, åñëè íåò êîñòþìà, îáîæãëèñü, èëè ìàëî çäîðîâüÿ:
7054 if (FMegaRulez
[MR_SUIT
] < gTime
) and ((FLastHit
= HIT_ACID
) or (Healthy() <= 1)) then
7055 if BodyInAcid(0, 0) then
7059 function TBot
.FullInStep(XInc
, YInc
: Integer): Boolean;
7061 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
7062 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_STEP
, False);
7065 {function TBot.NeedItem(Item: Byte): Byte;
7070 procedure TBot
.SelectWeapon(Dist
: Integer);
7074 function HaveAmmo(weapon
: Byte): Boolean;
7077 WEAPON_PISTOL
: Result
:= FAmmo
[A_BULLETS
] >= 1;
7078 WEAPON_SHOTGUN1
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7079 WEAPON_SHOTGUN2
: Result
:= FAmmo
[A_SHELLS
] >= 2;
7080 WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
] >= 10;
7081 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
] >= 1;
7082 WEAPON_PLASMA
: Result
:= FAmmo
[A_CELLS
] >= 10;
7083 WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
] >= 40;
7084 WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7085 else Result
:= True;
7090 if Dist
= -1 then Dist
:= BOT_LONGDIST
;
7092 if Dist
> BOT_LONGDIST
then
7093 begin // Äàëüíèé áîé
7095 if FWeapon
[FDifficult
.WeaponPrior
[a
]] and HaveAmmo(FDifficult
.WeaponPrior
[a
]) then
7097 FSelectedWeapon
:= FDifficult
.WeaponPrior
[a
];
7101 else //if Dist > BOT_UNSAFEDIST then
7102 begin // Áëèæíèé áîé
7104 if FWeapon
[FDifficult
.CloseWeaponPrior
[a
]] and HaveAmmo(FDifficult
.CloseWeaponPrior
[a
]) then
7106 FSelectedWeapon
:= FDifficult
.CloseWeaponPrior
[a
];
7113 if FWeapon[FDifficult.SafeWeaponPrior[a]] and HaveAmmo(FDifficult.SafeWeaponPrior[a]) then
7115 FSelectedWeapon := FDifficult.SafeWeaponPrior[a];
7121 function TBot
.PickItem(ItemType
: Byte; force
: Boolean; var remove
: Boolean): Boolean;
7123 Result
:= inherited PickItem(ItemType
, force
, remove
);
7125 if Result
then SetAIFlag('SELECTWEAPON', '1');
7128 function TBot
.Heal(value
: Word; Soft
: Boolean): Boolean;
7130 Result
:= inherited Heal(value
, Soft
);
7133 function TBot
.Healthy(): Byte;
7135 if FMegaRulez
[MR_INVUL
] >= gTime
then Result
:= 3
7136 else if (FHealth
> 80) or ((FHealth
> 50) and (FArmor
> 20)) then Result
:= 3
7137 else if (FHealth
> 50) then Result
:= 2
7138 else if (FHealth
> 20) then Result
:= 1
7142 function TBot
.TargetOnScreen(TX
, TY
: Integer): Boolean;
7144 Result
:= (Abs(FObj
.X
-TX
) <= Trunc(gPlayerScreenSize
.X
*0.6)) and
7145 (Abs(FObj
.Y
-TY
) <= Trunc(gPlayerScreenSize
.Y
*0.6));
7148 procedure TBot
.OnDamage(Angle
: SmallInt);
7156 if (Angle
= 0) or (Angle
= 180) then
7159 if (g_GetUIDType(FLastSpawnerUID
) = UID_PLAYER
) and
7160 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
) then
7162 pla
:= g_Player_Get(FLastSpawnerUID
);
7163 ok
:= not TargetOnScreen(pla
.FObj
.X
+ PLAYER_RECT
.X
,
7164 pla
.FObj
.Y
+ PLAYER_RECT
.Y
);
7167 if (g_GetUIDType(FLastSpawnerUID
) = UID_MONSTER
) and
7168 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
) then
7170 mon
:= g_Monsters_Get(FLastSpawnerUID
);
7171 ok
:= not TargetOnScreen(mon
.Obj
.X
+ mon
.Obj
.Rect
.X
,
7172 mon
.Obj
.Y
+ mon
.Obj
.Rect
.Y
);
7177 SetAIFlag('ATTACKLEFT', '1')
7179 SetAIFlag('ATTACKRIGHT', '1');
7183 function TBot
.RunDirection(): TDirection
;
7185 if Abs(Vel
.X
) >= 1 then
7187 if Vel
.X
> 0 then Result
:= D_RIGHT
else Result
:= D_LEFT
;
7189 Result
:= FDirection
;
7192 function TBot
.GetRnd(a
: Byte): Boolean;
7194 if a
= 0 then Result
:= False
7195 else if a
= 255 then Result
:= True
7196 else Result
:= Random(256) > 255-a
;
7199 function TBot
.GetInterval(a
: Byte; radius
: SmallInt): SmallInt;
7201 Result
:= Round((255-a
)/255*radius
*(Random(2)-1));
7204 procedure TBot
.SaveState(var Mem
: TBinMemoryWriter
);
7210 inherited SaveState(Mem
);
7212 // Âûáðàííîå îðóæèå:
7213 Mem
.WriteByte(FSelectedWeapon
);
7215 Mem
.WriteWord(FTargetUID
);
7216 // Âðåìÿ ïîòåðè öåëè:
7217 Mem
.WriteDWORD(FLastVisible
);
7218 // Êîëè÷åñòâî ôëàãîâ ÈÈ:
7219 dw
:= Length(FAIFlags
);
7222 for i
:= 0 to Integer(dw
)-1 do
7224 Mem
.WriteString(FAIFlags
[i
].Name
, 20);
7225 Mem
.WriteString(FAIFlags
[i
].Value
, 20);
7227 // Íàñòðîéêè ñëîæíîñòè:
7229 Mem
.WriteMemory(p
, SizeOf(TDifficult
));
7232 procedure TBot
.LoadState(var Mem
: TBinMemoryReader
);
7238 inherited LoadState(Mem
);
7240 // Âûáðàííîå îðóæèå:
7241 Mem
.ReadByte(FSelectedWeapon
);
7243 Mem
.ReadWord(FTargetUID
);
7244 // Âðåìÿ ïîòåðè öåëè:
7245 Mem
.ReadDWORD(FLastVisible
);
7246 // Êîëè÷åñòâî ôëàãîâ ÈÈ:
7248 SetLength(FAIFlags
, dw
);
7250 for i
:= 0 to Integer(dw
)-1 do
7252 Mem
.ReadString(FAIFlags
[i
].Name
);
7253 Mem
.ReadString(FAIFlags
[i
].Value
);
7255 // Íàñòðîéêè ñëîæíîñòè:
7256 Mem
.ReadMemory(p
, dw
);
7257 if dw
<> SizeOf(TDifficult
) then
7259 raise EBinSizeError
.Create('TBot.LoadState: Wrong FDifficult Size');
7261 FDifficult
:= TDifficult(p
^);