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
,
56 AmmoLimits
: Array [0..1] of Array [A_BULLETS
..A_HIGH
] of Word =
57 ((200, 50, 50, 300, 100),
58 (400, 100, 100, 600, 200));
79 ANGLE_NONE
= Low(SmallInt);
81 CORPSE_STATE_REMOVEME
= 0;
82 CORPSE_STATE_NORMAL
= 1;
83 CORPSE_STATE_MESS
= 2;
85 PLAYER_RECT
: TRectWH
= (X
:15; Y
:12; Width
:34; Height
:52);
86 PLAYER_RECT_CX
= 15+(34 div 2);
87 PLAYER_RECT_CY
= 12+(52 div 2);
88 PLAYER_CORPSERECT
: TRectWH
= (X
:15; Y
:48; Width
:34; Height
:16);
91 PLAYER_HP_LIMIT
= 200;
93 PLAYER_AP_LIMIT
= 200;
96 PLAYER1_DEF_COLOR
: TRGB
= (R
:64; G
:175; B
:48);
97 PLAYER2_DEF_COLOR
: TRGB
= (R
:96; G
:96; B
:96);
113 TPlayerStatArray
= Array of TPlayerStat
;
115 TPlayerSavedState
= record
123 Ammo
: Array [A_BULLETS
..A_HIGH
] of Word;
124 MaxAmmo
: Array [A_BULLETS
..A_HIGH
] of Word;
125 Weapon
: Array [WP_FIRST
..WP_LAST
] of Boolean;
126 Rulez
: Set of R_ITEM_BACKPACK
..R_BERSERK
;
135 TPlayer
= class (TObject
)
143 FDirection
: TDirection
;
151 FMonsterKills
: Integer;
157 FCanJetpack
: Boolean;
163 FNextWeapDelay
: Byte; // frames
164 FBFGFireCounter
: SmallInt;
165 FLastSpawnerUID
: Word;
169 FSpectatePlayer
: Integer;
170 FFirePainTime
: Integer;
173 FSavedState
: TPlayerSavedState
;
175 FModel
: TPlayerModel
;
178 FActionForce
: Boolean;
179 FActionChanged
: Boolean;
181 FFireAngle
: SmallInt;
183 FShellTimer
: Integer;
185 FSawSound
: TPlayableSound
;
186 FSawSoundIdle
: TPlayableSound
;
187 FSawSoundHit
: TPlayableSound
;
188 FSawSoundSelect
: TPlayableSound
;
189 FJetSoundOn
: TPlayableSound
;
190 FJetSoundOff
: TPlayableSound
;
191 FJetSoundFly
: TPlayableSound
;
195 FJustTeleported
: Boolean;
198 function CollideLevel(XInc
, YInc
: Integer): Boolean;
199 function StayOnStep(XInc
, YInc
: Integer): Boolean;
200 function HeadInLiquid(XInc
, YInc
: Integer): Boolean;
201 function BodyInLiquid(XInc
, YInc
: Integer): Boolean;
202 function BodyInAcid(XInc
, YInc
: Integer): Boolean;
203 function FullInLift(XInc
, YInc
: Integer): Integer;
204 {procedure CollideItem();}
205 procedure FlySmoke(Times
: DWORD
= 1);
206 procedure OnFireFlame(Times
: DWORD
= 1);
207 function GetAmmoByWeapon(Weapon
: Byte): Word;
208 procedure SetAction(Action
: Byte; Force
: Boolean = False);
209 procedure OnDamage(Angle
: SmallInt); virtual;
210 function firediry(): Integer;
212 procedure Run(Direction
: TDirection
);
213 procedure NextWeapon();
214 procedure PrevWeapon();
221 function getNextWeaponIndex (): Byte; // return 255 for "no switch"
222 procedure resetWeaponQueue ();
223 function hasAmmoForWeapon (weapon
: Byte): Boolean;
226 FDamageBuffer
: Integer;
228 FAmmo
: Array [A_BULLETS
..A_HIGH
] of Word;
229 FMaxAmmo
: Array [A_BULLETS
..A_HIGH
] of Word;
230 FWeapon
: Array [WP_FIRST
..WP_LAST
] of Boolean;
231 FRulez
: Set of R_ITEM_BACKPACK
..R_BERSERK
;
233 FMegaRulez
: Array [MR_SUIT
..MR_MAX
] of DWORD
;
234 FReloading
: Array [WP_FIRST
..WP_LAST
] of Word;
235 FTime
: Array [T_RESPAWN
..T_FLAGCAP
] of DWORD
;
236 FKeys
: Array [KEY_LEFT
..KEY_CHAT
] of TKeyState
;
238 FPreferredTeam
: Byte;
241 FWantsInGame
: Boolean;
245 FActualModelName
: string;
252 constructor Create(); virtual;
253 destructor Destroy(); override;
254 procedure Respawn(Silent
: Boolean; Force
: Boolean = False); virtual;
255 function GetRespawnPoint(): Byte;
256 procedure PressKey(Key
: Byte; Time
: Word = 1);
257 procedure ReleaseKeys();
258 procedure SetModel(ModelName
: String);
259 procedure SetColor(Color
: TRGB
);
260 procedure SetWeapon(W
: Byte);
261 function IsKeyPressed(K
: Byte): Boolean;
262 function GetKeys(): Byte;
263 function PickItem(ItemType
: Byte; respawn
: Boolean; var remove
: Boolean): Boolean; virtual;
264 function Collide(X
, Y
: Integer; Width
, Height
: Word): Boolean; overload
;
265 function Collide(Panel
: TPanel
): Boolean; overload
;
266 function Collide(X
, Y
: Integer): Boolean; overload
;
267 procedure SetDirection(Direction
: TDirection
);
268 procedure GetSecret();
269 function TeleportTo(X
, Y
: Integer; silent
: Boolean; dir
: Byte): Boolean;
271 procedure Push(vx
, vy
: Integer);
272 procedure ChangeModel(ModelName
: String);
273 procedure SwitchTeam
;
274 procedure ChangeTeam(Team
: Byte);
276 function GetFlag(Flag
: Byte): Boolean;
277 procedure SetFlag(Flag
: Byte);
278 function DropFlag(): Boolean;
279 procedure AllRulez(Health
: Boolean);
280 procedure RestoreHealthArmor();
281 procedure FragCombo();
282 procedure GiveItem(ItemType
: Byte);
283 procedure Damage(value
: Word; SpawnerUID
: Word; vx
, vy
: Integer; t
: Byte); virtual;
284 function Heal(value
: Word; Soft
: Boolean): Boolean; virtual;
285 procedure MakeBloodVector(Count
: Word; VelX
, VelY
: Integer);
286 procedure MakeBloodSimple(Count
: Word);
287 procedure Kill(KillType
: Byte; SpawnerUID
: Word; t
: Byte);
288 procedure Reset(Force
: Boolean);
289 procedure Spectate(NoMove
: Boolean = False);
290 procedure SwitchNoClip
;
291 procedure SoftReset();
292 procedure Draw(); virtual;
293 procedure DrawPain();
294 procedure DrawPickup();
295 procedure DrawRulez();
297 procedure DrawBubble();
299 procedure Update(); virtual;
300 procedure RememberState();
301 procedure RecallState();
302 procedure SaveState(var Mem
: TBinMemoryWriter
); virtual;
303 procedure LoadState(var Mem
: TBinMemoryReader
); virtual;
304 procedure PauseSounds(Enable
: Boolean);
305 procedure NetFire(Wpn
: Byte; X
, Y
, AX
, AY
: Integer; WID
: Integer = -1);
306 procedure DoLerp(Level
: Integer = 2);
307 procedure SetLerp(XTo
, YTo
: Integer);
308 procedure QueueWeaponSwitch(Weapon
: Byte);
309 procedure RealizeCurrentWeapon();
311 procedure JetpackOff
;
312 procedure CatchFire(Attacker
: Word);
314 property Name
: String read FName write FName
;
315 property Model
: TPlayerModel read FModel
;
316 property Health
: Integer read FHealth write FHealth
;
317 property Lives
: Byte read FLives write FLives
;
318 property Armor
: Integer read FArmor write FArmor
;
319 property Air
: Integer read FAir write FAir
;
320 property JetFuel
: Integer read FJetFuel write FJetFuel
;
321 property Frags
: Integer read FFrags write FFrags
;
322 property Death
: Integer read FDeath write FDeath
;
323 property Kills
: Integer read FKills write FKills
;
324 property CurrWeap
: Byte read FCurrWeap write FCurrWeap
;
325 property MonsterKills
: Integer read FMonsterKills write FMonsterKills
;
326 property Secrets
: Integer read FSecrets
;
327 property GodMode
: Boolean read FGodMode write FGodMode
;
328 property NoTarget
: Boolean read FNoTarget write FNoTarget
;
329 property NoReload
: Boolean read FNoReload write FNoReload
;
330 property Live
: Boolean read FLive write FLive
;
331 property Flag
: Byte read FFlag
;
332 property Team
: Byte read FTeam write FTeam
;
333 property Direction
: TDirection read FDirection
;
334 property GameX
: Integer read FObj
.X write FObj
.X
;
335 property GameY
: Integer read FObj
.Y write FObj
.Y
;
336 property GameVelX
: Integer read FObj
.Vel
.X write FObj
.Vel
.X
;
337 property GameVelY
: Integer read FObj
.Vel
.Y write FObj
.Vel
.Y
;
338 property GameAccelX
: Integer read FObj
.Accel
.X write FObj
.Accel
.X
;
339 property GameAccelY
: Integer read FObj
.Accel
.Y write FObj
.Accel
.Y
;
340 property Vel
: TPoint2i read FObj
.Vel
;
341 property Obj
: TObj read FObj
;
342 property IncCam
: Integer read FIncCam write FIncCam
;
343 property UID
: Word read FUID write FUID
;
344 property JustTeleported
: Boolean read FJustTeleported write FJustTeleported
;
345 property NetTime
: LongWord read FNetTime write FNetTime
;
355 WeaponPrior
: Array [WP_FIRST
..WP_LAST
] of Byte;
356 CloseWeaponPrior
: Array [WP_FIRST
..WP_LAST
] of Byte;
357 //SafeWeaponPrior: Array [WP_FIRST..WP_LAST] of Byte;
365 TBot
= class (TPlayer
)
367 FSelectedWeapon
: Byte;
370 FAIFlags
: Array of TAIFlag
;
371 FDifficult
: TDifficult
;
373 function GetRnd(a
: Byte): Boolean;
374 function GetInterval(a
: Byte; radius
: SmallInt): SmallInt;
375 function RunDirection(): TDirection
;
376 function FullInStep(XInc
, YInc
: Integer): Boolean;
377 //function NeedItem(Item: Byte): Byte;
378 procedure SelectWeapon(Dist
: Integer);
379 procedure SetAIFlag(fName
, fValue
: String20
);
380 function GetAIFlag(fName
: String20
): String20
;
381 procedure RemoveAIFlag(fName
: String20
);
382 function Healthy(): Byte;
383 procedure UpdateMove();
384 procedure UpdateCombat();
385 function KeyPressed(Key
: Word): Boolean;
386 procedure ReleaseKey(Key
: Byte);
387 function TargetOnScreen(TX
, TY
: Integer): Boolean;
388 procedure OnDamage(Angle
: SmallInt); override;
391 procedure Respawn(Silent
: Boolean; Force
: Boolean = False); override;
392 constructor Create(); override;
393 destructor Destroy(); override;
394 procedure Draw(); override;
395 function PickItem(ItemType
: Byte; force
: Boolean; var remove
: Boolean): Boolean; override;
396 function Heal(value
: Word; Soft
: Boolean): Boolean; override;
397 procedure Update(); override;
398 procedure SaveState(var Mem
: TBinMemoryWriter
); override;
399 procedure LoadState(var Mem
: TBinMemoryReader
); override;
421 TCorpse
= class (TObject
)
429 FAnimation
: TAnimation
;
430 FAnimationMask
: TAnimation
;
433 constructor Create(X
, Y
: Integer; ModelName
: String; aMess
: Boolean);
434 destructor Destroy(); override;
435 procedure Damage(Value
: Word; vx
, vy
: Integer);
438 procedure SaveState(var Mem
: TBinMemoryWriter
);
439 procedure LoadState(var Mem
: TBinMemoryReader
);
441 property Obj
: TObj read FObj
;
442 property State
: Byte read FState
;
443 property Mess
: Boolean read FMess
;
446 TTeamStat
= Array [TEAM_RED
..TEAM_BLUE
] of
452 gPlayers
: Array of TPlayer
;
453 gCorpses
: Array of TCorpse
;
454 gGibs
: Array of TGib
;
455 gShells
: Array of TShell
;
456 gTeamStat
: TTeamStat
;
457 gFly
: Boolean = False;
458 gAimLine
: Boolean = False;
459 gChatBubble
: Byte = 0;
463 MAX_RUNVEL
: Integer = 8;
464 VEL_JUMP
: Integer = 10;
465 SHELL_TIMEOUT
: Cardinal = 60000;
467 function Lerp(X
, Y
, Factor
: Integer): Integer;
469 procedure g_Gibs_SetMax(Count
: Word);
470 function g_Gibs_GetMax(): Word;
471 procedure g_Corpses_SetMax(Count
: Word);
472 function g_Corpses_GetMax(): Word;
473 procedure g_Shells_SetMax(Count
: Word);
474 function g_Shells_GetMax(): Word;
476 procedure g_Player_Init();
477 procedure g_Player_Free();
478 function g_Player_Create(ModelName
: String; Color
: TRGB
; Team
: Byte; Bot
: Boolean): Word;
479 function g_Player_CreateFromState(var Mem
: TBinMemoryReader
): Word;
480 procedure g_Player_Remove(UID
: Word);
481 procedure g_Player_ResetTeams();
482 procedure g_Player_UpdateAll();
483 procedure g_Player_DrawAll();
484 procedure g_Player_DrawDebug(p
: TPlayer
);
485 procedure g_Player_DrawHealth();
486 procedure g_Player_RememberAll();
487 procedure g_Player_ResetAll(Force
, Silent
: Boolean);
488 function g_Player_Get(UID
: Word): TPlayer
;
489 function g_Player_GetCount(): Byte;
490 function g_Player_GetStats(): TPlayerStatArray
;
491 function g_Player_ValidName(Name
: String): Boolean;
492 procedure g_Player_CreateCorpse(Player
: TPlayer
);
493 procedure g_Player_CreateGibs(fX
, fY
: Integer; ModelName
: String; fColor
: TRGB
);
494 procedure g_Player_CreateShell(fX
, fY
, dX
, dY
: Integer; T
: Byte);
495 procedure g_Player_UpdatePhysicalObjects();
496 procedure g_Player_DrawCorpses();
497 procedure g_Player_DrawShells();
498 procedure g_Player_RemoveAllCorpses();
499 procedure g_Player_Corpses_SaveState(var Mem
: TBinMemoryWriter
);
500 procedure g_Player_Corpses_LoadState(var Mem
: TBinMemoryReader
);
501 procedure g_Bot_Add(Team
, Difficult
: Byte);
502 procedure g_Bot_AddList(Team
: Byte; lname
: ShortString; num
: Integer = -1);
503 procedure g_Bot_MixNames();
504 procedure g_Bot_RemoveAll();
509 e_log
, g_map
, g_items
, g_console
, SysUtils
, g_gfx
, Math
,
510 g_options
, g_triggers
, g_menu
, MAPDEF
, g_game
,
511 wadreader
, g_main
, g_monsters
, CONFIG
, g_language
, g_net
, g_netmsg
;
521 diag_precision
: Byte;
525 w_prior1
: Array [WP_FIRST
..WP_LAST
] of Byte;
526 w_prior2
: Array [WP_FIRST
..WP_LAST
] of Byte;
527 w_prior3
: Array [WP_FIRST
..WP_LAST
] of Byte;
531 TIME_RESPAWN1
= 1500;
532 TIME_RESPAWN2
= 2000;
533 TIME_RESPAWN3
= 3000;
536 JET_MAX
= 540; // ~30 sec
537 PLAYER_SUIT_TIME
= 30000;
538 PLAYER_INVUL_TIME
= 30000;
539 PLAYER_INVIS_TIME
= 35000;
540 FRAG_COMBO_TIME
= 3000;
544 ANGLE_RIGHTDOWN
= -35;
546 ANGLE_LEFTDOWN
= -145;
547 PLAYER_HEADRECT
: TRectWH
= (X
:24; Y
:12; Width
:20; Height
:12);
548 WEAPONPOINT
: Array [TDirection
] of TPoint
= ((X
:16; Y
:32), (X
:47; Y
:32));
551 BOT_UNSAFEDIST
= 128;
552 TEAMCOLOR
: Array [TEAM_RED
..TEAM_BLUE
] of TRGB
= ((R
:255; G
:0; B
:0),
554 DIFFICULT_EASY
: TDifficult
= (DiagFire
: 32; InvisFire
: 32; DiagPrecision
: 32;
555 FlyPrecision
: 32; Cover
: 32; CloseJump
: 32;
556 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
557 DIFFICULT_MEDIUM
: TDifficult
= (DiagFire
: 127; InvisFire
: 127; DiagPrecision
: 127;
558 FlyPrecision
: 127; Cover
: 127; CloseJump
: 127;
559 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
560 DIFFICULT_HARD
: TDifficult
= (DiagFire
: 255; InvisFire
: 255; DiagPrecision
: 255;
561 FlyPrecision
: 255; Cover
: 255; CloseJump
: 255;
562 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0,0));
563 WEAPON_PRIOR1
: Array [WP_FIRST
..WP_LAST
] of Byte =
564 (WEAPON_FLAMETHROWER
, WEAPON_SUPERPULEMET
,
565 WEAPON_SHOTGUN2
, WEAPON_SHOTGUN1
,
566 WEAPON_CHAINGUN
, WEAPON_PLASMA
, WEAPON_ROCKETLAUNCHER
,
567 WEAPON_BFG
, WEAPON_PISTOL
, WEAPON_SAW
, WEAPON_KASTET
);
568 WEAPON_PRIOR2
: Array [WP_FIRST
..WP_LAST
] of Byte =
569 (WEAPON_FLAMETHROWER
, WEAPON_SUPERPULEMET
,
570 WEAPON_BFG
, WEAPON_ROCKETLAUNCHER
,
571 WEAPON_SHOTGUN2
, WEAPON_PLASMA
, WEAPON_SHOTGUN1
,
572 WEAPON_CHAINGUN
, WEAPON_PISTOL
, WEAPON_SAW
, WEAPON_KASTET
);
573 //WEAPON_PRIOR3: Array [WP_FIRST..WP_LAST] of Byte =
574 // (WEAPON_FLAMETHROWER, WEAPON_SUPERPULEMET,
575 // WEAPON_BFG, WEAPON_PLASMA, WEAPON_SHOTGUN2,
576 // WEAPON_CHAINGUN, WEAPON_SHOTGUN1, WEAPON_SAW,
577 // WEAPON_ROCKETLAUNCHER, WEAPON_PISTOL, WEAPON_KASTET);
578 WEAPON_RELOAD
: Array [WP_FIRST
..WP_LAST
] of Byte =
579 (5, 2, 6, 18, 36, 2, 12, 2, 14, 2, 2);
581 PLAYER_SIGNATURE
= $52594C50; // 'PLYR'
582 CORPSE_SIGNATURE
= $50524F43; // 'CORP'
584 BOTNAMES_FILENAME
= 'botnames.txt';
585 BOTLIST_FILENAME
= 'botlist.txt';
589 MaxCorpses
: Word = 20;
590 MaxShells
: Word = 300;
591 CurrentGib
: Integer = 0;
592 CurrentShell
: Integer = 0;
593 BotNames
: Array of String;
594 BotList
: Array of TBotProfile
;
596 function Lerp(X
, Y
, Factor
: Integer): Integer;
598 Result
:= X
+ ((Y
- X
) div Factor
);
601 function SameTeam(UID1
, UID2
: Word): Boolean;
605 if (UID1
> UID_MAX_PLAYER
) or (UID1
<= UID_MAX_GAME
) or
606 (UID2
> UID_MAX_PLAYER
) or (UID2
<= UID_MAX_GAME
) then Exit
;
608 if (g_Player_Get(UID1
) = nil) or (g_Player_Get(UID2
) = nil) then Exit
;
610 if ((g_Player_Get(UID1
).Team
= TEAM_NONE
) or
611 (g_Player_Get(UID2
).Team
= TEAM_NONE
)) then Exit
;
613 Result
:= g_Player_Get(UID1
).FTeam
= g_Player_Get(UID2
).FTeam
;
616 procedure g_Gibs_SetMax(Count
: Word);
619 SetLength(gGibs
, Count
);
621 if CurrentGib
>= Count
then
625 function g_Gibs_GetMax(): Word;
630 procedure g_Shells_SetMax(Count
: Word);
633 SetLength(gShells
, Count
);
635 if CurrentShell
>= Count
then
639 function g_Shells_GetMax(): Word;
645 procedure g_Corpses_SetMax(Count
: Word);
648 SetLength(gCorpses
, Count
);
651 function g_Corpses_GetMax(): Word;
653 Result
:= MaxCorpses
;
656 function g_Player_Create(ModelName
: String; Color
: TRGB
; Team
: Byte; Bot
: Boolean): Word;
666 // Åñòü ëè ìåñòî â gPlayers:
667 if gPlayers
<> nil then
668 for a
:= 0 to High(gPlayers
) do
669 if gPlayers
[a
] = nil then
675 // Íåò ìåñòà - ðàñøèðÿåì gPlayers:
678 SetLength(gPlayers
, Length(gPlayers
)+1);
682 // Ñîçäàåì îáúåêò èãðîêà:
684 gPlayers
[a
] := TBot
.Create()
686 gPlayers
[a
] := TPlayer
.Create();
689 gPlayers
[a
].FActualModelName
:= ModelName
;
690 gPlayers
[a
].SetModel(ModelName
);
692 // Íåò ìîäåëè - ñîçäàíèå íå âîçìîæíî:
693 if gPlayers
[a
].FModel
= nil then
697 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], [ModelName
]));
701 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
702 if Random(2) = 0 then
706 gPlayers
[a
].FPreferredTeam
:= Team
;
708 case gGameSettings
.GameMode
of
709 GM_DM
: gPlayers
[a
].FTeam
:= TEAM_NONE
;
711 GM_CTF
: gPlayers
[a
].FTeam
:= gPlayers
[a
].FPreferredTeam
;
713 GM_COOP
: gPlayers
[a
].FTeam
:= TEAM_COOP
;
716 // Åñëè êîìàíäíàÿ èãðà - êðàñèì ìîäåëü â öâåò êîìàíäû:
717 gPlayers
[a
].FColor
:= Color
;
718 if gPlayers
[a
].FTeam
in [TEAM_RED
, TEAM_BLUE
] then
719 gPlayers
[a
].FModel
.Color
:= TEAMCOLOR
[gPlayers
[a
].FTeam
]
721 gPlayers
[a
].FModel
.Color
:= Color
;
723 gPlayers
[a
].FUID
:= g_CreateUID(UID_PLAYER
);
724 gPlayers
[a
].FLive
:= False;
726 Result
:= gPlayers
[a
].FUID
;
729 function g_Player_CreateFromState(var Mem
: TBinMemoryReader
): Word;
742 if sig
<> PLAYER_SIGNATURE
then // 'PLYR'
744 raise EBinSizeError
.Create('g_Player_CreateFromState: Wrong Player Signature');
748 Mem
.ReadBoolean(Bot
);
753 // Åñòü ëè ìåñòî â gPlayers:
754 if gPlayers
<> nil then
755 for a
:= 0 to High(gPlayers
) do
756 if gPlayers
[a
] = nil then
762 // Íåò ìåñòà - ðàñøèðÿåì gPlayers:
765 SetLength(gPlayers
, Length(gPlayers
)+1);
769 // Ñîçäàåì îáúåêò èãðîêà:
771 gPlayers
[a
] := TBot
.Create()
773 gPlayers
[a
] := TPlayer
.Create();
774 gPlayers
[a
].FIamBot
:= Bot
;
775 gPlayers
[a
].FPhysics
:= True;
778 Mem
.ReadWord(gPlayers
[a
].FUID
);
780 Mem
.ReadString(gPlayers
[a
].FName
);
782 Mem
.ReadByte(gPlayers
[a
].FTeam
);
783 gPlayers
[a
].FPreferredTeam
:= gPlayers
[a
].FTeam
;
785 Mem
.ReadBoolean(gPlayers
[a
].FLive
);
786 // Èçðàñõîäîâàë ëè âñå æèçíè:
787 Mem
.ReadBoolean(gPlayers
[a
].FNoRespawn
);
791 gPlayers
[a
].FDirection
:= D_LEFT
793 gPlayers
[a
].FDirection
:= D_RIGHT
;
795 Mem
.ReadInt(gPlayers
[a
].FHealth
);
797 Mem
.ReadByte(gPlayers
[a
].FLives
);
799 Mem
.ReadInt(gPlayers
[a
].FArmor
);
801 Mem
.ReadInt(gPlayers
[a
].FAir
);
803 Mem
.ReadInt(gPlayers
[a
].FJetFuel
);
805 Mem
.ReadInt(gPlayers
[a
].FPain
);
807 Mem
.ReadInt(gPlayers
[a
].FKills
);
809 Mem
.ReadInt(gPlayers
[a
].FMonsterKills
);
811 Mem
.ReadInt(gPlayers
[a
].FFrags
);
813 Mem
.ReadByte(gPlayers
[a
].FFragCombo
);
814 // Âðåìÿ ïîñëåäíåãî ôðàãà:
815 Mem
.ReadDWORD(gPlayers
[a
].FLastFrag
);
817 Mem
.ReadInt(gPlayers
[a
].FDeath
);
819 Mem
.ReadByte(gPlayers
[a
].FFlag
);
821 Mem
.ReadInt(gPlayers
[a
].FSecrets
);
823 Mem
.ReadByte(gPlayers
[a
].FCurrWeap
);
824 // Ñëåäóþùåå æåëàåìîå îðóæèå:
825 Mem
.ReadWord(gPlayers
[a
].FNextWeap
);
827 Mem
.ReadByte(gPlayers
[a
].FNextWeapDelay
);
828 // Âðåìÿ çàðÿäêè BFG:
829 Mem
.ReadSmallInt(gPlayers
[a
].FBFGFireCounter
);
831 Mem
.ReadInt(gPlayers
[a
].FDamageBuffer
);
832 // Ïîñëåäíèé óäàðèâøèé:
833 Mem
.ReadWord(gPlayers
[a
].FLastSpawnerUID
);
834 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà:
835 Mem
.ReadByte(gPlayers
[a
].FLastHit
);
837 Obj_LoadState(@gPlayers
[a
].FObj
, Mem
);
838 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ:
839 for i
:= A_BULLETS
to A_HIGH
do
840 Mem
.ReadWord(gPlayers
[a
].FAmmo
[i
]);
841 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ:
842 for i
:= A_BULLETS
to A_HIGH
do
843 Mem
.ReadWord(gPlayers
[a
].FMaxAmmo
[i
]);
845 for i
:= WP_FIRST
to WP_LAST
do
846 Mem
.ReadBoolean(gPlayers
[a
].FWeapon
[i
]);
847 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ:
848 for i
:= WP_FIRST
to WP_LAST
do
849 Mem
.ReadWord(gPlayers
[a
].FReloading
[i
]);
853 Include(gPlayers
[a
].FRulez
, R_ITEM_BACKPACK
);
854 // Íàëè÷èå êðàñíîãî êëþ÷à:
857 Include(gPlayers
[a
].FRulez
, R_KEY_RED
);
858 // Íàëè÷èå çåëåíîãî êëþ÷à:
861 Include(gPlayers
[a
].FRulez
, R_KEY_GREEN
);
862 // Íàëè÷èå ñèíåãî êëþ÷à:
865 Include(gPlayers
[a
].FRulez
, R_KEY_BLUE
);
869 Include(gPlayers
[a
].FRulez
, R_BERSERK
);
870 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ:
871 for i
:= MR_SUIT
to MR_MAX
do
872 Mem
.ReadDWORD(gPlayers
[a
].FMegaRulez
[i
]);
873 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà:
874 for i
:= T_RESPAWN
to T_FLAGCAP
do
875 Mem
.ReadDWORD(gPlayers
[a
].FTime
[i
]);
878 Mem
.ReadString(gPlayers
[a
].FActualModelName
);
880 Mem
.ReadByte(gPlayers
[a
].FColor
.R
);
881 Mem
.ReadByte(gPlayers
[a
].FColor
.G
);
882 Mem
.ReadByte(gPlayers
[a
].FColor
.B
);
883 // Îáíîâëÿåì ìîäåëü èãðîêà:
884 gPlayers
[a
].SetModel(gPlayers
[a
].FActualModelName
);
886 // Íåò ìîäåëè - ñîçäàíèå íå âîçìîæíî:
887 if gPlayers
[a
].FModel
= nil then
891 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], [gPlayers
[a
].FActualModelName
]));
895 // Åñëè êîìàíäíàÿ èãðà - êðàñèì ìîäåëü â öâåò êîìàíäû:
896 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
897 gPlayers
[a
].FModel
.Color
:= TEAMCOLOR
[gPlayers
[a
].FTeam
]
899 gPlayers
[a
].FModel
.Color
:= gPlayers
[a
].FColor
;
901 Result
:= gPlayers
[a
].FUID
;
904 procedure g_Player_ResetTeams();
908 if g_Game_IsClient
then
910 if gPlayers
= nil then
912 for a
:= Low(gPlayers
) to High(gPlayers
) do
913 if gPlayers
[a
] <> nil then
914 case gGameSettings
.GameMode
of
916 gPlayers
[a
].ChangeTeam(TEAM_NONE
);
918 if not (gPlayers
[a
].Team
in [TEAM_RED
, TEAM_BLUE
]) then
919 if gPlayers
[a
].FPreferredTeam
in [TEAM_RED
, TEAM_BLUE
] then
920 gPlayers
[a
].ChangeTeam(gPlayers
[a
].FPreferredTeam
)
923 gPlayers
[a
].ChangeTeam(TEAM_RED
)
925 gPlayers
[a
].ChangeTeam(TEAM_BLUE
);
928 gPlayers
[a
].ChangeTeam(TEAM_COOP
);
932 procedure g_Bot_Add(Team
, Difficult
: Byte);
935 _name
, _model
: String;
938 if not g_Game_IsServer
then Exit
;
940 // Ñïèñîê íàçâàíèé ìîäåëåé:
941 m
:= g_PlayerModel_GetNames();
946 if (gGameSettings
.GameType
= GT_SINGLE
) or (gGameSettings
.GameMode
= GM_COOP
) then
947 Team
:= TEAM_COOP
// COOP
949 if gGameSettings
.GameMode
= GM_DM
then
950 Team
:= TEAM_NONE
// DM
952 if Team
= TEAM_NONE
then // CTF / TDM
954 // Àâòîáàëàíñ êîìàíä:
958 for a
:= 0 to High(gPlayers
) do
959 if gPlayers
[a
] <> nil then
961 if gPlayers
[a
].Team
= TEAM_RED
then
964 if gPlayers
[a
].Team
= TEAM_BLUE
then
974 if Random(2) = 0 then
980 // Âûáèðàåì áîòó èìÿ:
982 if BotNames
<> nil then
983 for a
:= 0 to High(BotNames
) do
984 if g_Player_ValidName(BotNames
[a
]) then
986 _name
:= BotNames
[a
];
990 // Èìåíè íåò, çàäàåì ñëó÷àéíîå:
993 _name
:= Format('DFBOT%.2d', [Random(100)]);
994 until g_Player_ValidName(_name
);
996 // Âûáèðàåì ñëó÷àéíóþ ìîäåëü:
997 _model
:= m
[Random(Length(m
))];
1000 with g_Player_Get(g_Player_Create(_model
,
1001 _RGB(Min(Random(9)*32, 255),
1002 Min(Random(9)*32, 255),
1003 Min(Random(9)*32, 255)),
1004 Team
, True)) as TBot
do
1009 1: FDifficult
:= DIFFICULT_EASY
;
1010 2: FDifficult
:= DIFFICULT_MEDIUM
;
1011 else FDifficult
:= DIFFICULT_HARD
;
1014 for a
:= WP_FIRST
to WP_LAST
do
1016 FDifficult
.WeaponPrior
[a
] := WEAPON_PRIOR1
[a
];
1017 FDifficult
.CloseWeaponPrior
[a
] := WEAPON_PRIOR2
[a
];
1018 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
1021 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [Name
]), True);
1023 if g_Game_IsNet
then MH_SEND_PlayerCreate(UID
);
1024 if g_Game_IsServer
and (gGameSettings
.MaxLives
> 0) then
1029 procedure g_Bot_AddList(Team
: Byte; lName
: ShortString; num
: Integer = -1);
1032 _name
, _model
: String;
1035 if not g_Game_IsServer
then Exit
;
1037 // Ñïèñîê íàçâàíèé ìîäåëåé:
1038 m
:= g_PlayerModel_GetNames();
1043 if (gGameSettings
.GameType
= GT_SINGLE
) or (gGameSettings
.GameMode
= GM_COOP
) then
1044 Team
:= TEAM_COOP
// COOP
1046 if gGameSettings
.GameMode
= GM_DM
then
1047 Team
:= TEAM_NONE
// DM
1049 if Team
= TEAM_NONE
then
1050 Team
:= BotList
[num
].team
; // CTF / TDM
1052 // Âûáèðàåì íàñòðîéêè áîòà èç ñïèñêà ïî íîìåðó èëè èìåíè:
1053 lName
:= AnsiLowerCase(lName
);
1054 if (num
< 0) or (num
> Length(BotList
)-1) then
1056 if (num
= -1) and (lName
<> '') and (BotList
<> nil) then
1057 for a
:= 0 to High(BotList
) do
1058 if AnsiLowerCase(BotList
[a
].name
) = lName
then
1067 _name
:= BotList
[num
].name
;
1068 // Çàíÿòî - âûáèðàåì ñëó÷àéíîå:
1069 if not g_Player_ValidName(_name
) then
1071 _name
:= Format('DFBOT%.2d', [Random(100)]);
1072 until g_Player_ValidName(_name
);
1075 _model
:= BotList
[num
].model
;
1076 // Íåò òàêîé - âûáèðàåì ñëó÷àéíóþ:
1077 if not InSArray(_model
, m
) then
1078 _model
:= m
[Random(Length(m
))];
1081 with g_Player_Get(g_Player_Create(_model
, BotList
[num
].color
, Team
, True)) as TBot
do
1085 FDifficult
.DiagFire
:= BotList
[num
].diag_fire
;
1086 FDifficult
.InvisFire
:= BotList
[num
].invis_fire
;
1087 FDifficult
.DiagPrecision
:= BotList
[num
].diag_precision
;
1088 FDifficult
.FlyPrecision
:= BotList
[num
].fly_precision
;
1089 FDifficult
.Cover
:= BotList
[num
].cover
;
1090 FDifficult
.CloseJump
:= BotList
[num
].close_jump
;
1092 for a
:= WP_FIRST
to WP_LAST
do
1094 FDifficult
.WeaponPrior
[a
] := BotList
[num
].w_prior1
[a
];
1095 FDifficult
.CloseWeaponPrior
[a
] := BotList
[num
].w_prior2
[a
];
1096 //FDifficult.SafeWeaponPrior[a] := BotList[num].w_prior3[a];
1099 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [Name
]), True);
1101 if g_Game_IsNet
then MH_SEND_PlayerCreate(UID
);
1105 procedure g_Bot_RemoveAll();
1109 if not g_Game_IsServer
then Exit
;
1110 if gPlayers
= nil then Exit
;
1112 for a
:= 0 to High(gPlayers
) do
1113 if gPlayers
[a
] <> nil then
1114 if gPlayers
[a
] is TBot
then
1116 gPlayers
[a
].Lives
:= 0;
1117 gPlayers
[a
].Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
1118 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [gPlayers
[a
].Name
]), True);
1119 g_Player_Remove(gPlayers
[a
].FUID
);
1125 procedure g_Bot_MixNames();
1130 if BotNames
<> nil then
1131 for a
:= 0 to High(BotNames
) do
1133 b
:= Random(Length(BotNames
));
1135 Botnames
[a
] := BotNames
[b
];
1140 procedure g_Player_Remove(UID
: Word);
1144 if gPlayers
= nil then Exit
;
1146 if g_Game_IsServer
and g_Game_IsNet
then
1147 MH_SEND_PlayerDelete(UID
);
1149 for i
:= 0 to High(gPlayers
) do
1150 if gPlayers
[i
] <> nil then
1151 if gPlayers
[i
].FUID
= UID
then
1153 if gPlayers
[i
] is TPlayer
then
1154 TPlayer(gPlayers
[i
]).Free()
1156 TBot(gPlayers
[i
]).Free();
1162 procedure g_Player_Init();
1172 if not FileExists(DataDir
+ BOTNAMES_FILENAME
) then
1175 // ×èòàåì âîçìîæíûå èìåíà áîòîâ èç ôàéëà:
1176 AssignFile(F
, DataDir
+ BOTNAMES_FILENAME
);
1187 SetLength(BotNames
, Length(BotNames
)+1);
1188 BotNames
[High(BotNames
)] := s
;
1196 // ×èòàåì ôàéë ñ ïàðàìåòðàìè áîòîâ:
1197 config
:= TConfig
.CreateFile(DataDir
+ BOTLIST_FILENAME
);
1201 while config
.SectionExists(IntToStr(a
)) do
1203 SetLength(BotList
, Length(BotList
)+1);
1205 with BotList
[High(BotList
)] do
1208 name
:= config
.ReadStr(IntToStr(a
), 'name', '');
1210 model
:= config
.ReadStr(IntToStr(a
), 'model', '');
1212 if config
.ReadStr(IntToStr(a
), 'team', 'red') = 'red' then
1217 sa
:= parse(config
.ReadStr(IntToStr(a
), 'color', ''));
1218 color
.R
:= StrToIntDef(sa
[0], 0);
1219 color
.G
:= StrToIntDef(sa
[1], 0);
1220 color
.B
:= StrToIntDef(sa
[2], 0);
1221 // Âåðîÿòíîñòü ñòðåëüáû ïîä óãëîì:
1222 diag_fire
:= config
.ReadInt(IntToStr(a
), 'diag_fire', 0);
1223 // Âåðîÿòíîñòü îòâåòíîãî îãíÿ ïî íåâèäèìîìó ñîïåðíèêó:
1224 invis_fire
:= config
.ReadInt(IntToStr(a
), 'invis_fire', 0);
1225 // Òî÷íîñòü ñòðåëüáû ïîä óãëîì:
1226 diag_precision
:= config
.ReadInt(IntToStr(a
), 'diag_precision', 0);
1227 // Òî÷íîñòü ñòðåëüáû â ïîëåòå:
1228 fly_precision
:= config
.ReadInt(IntToStr(a
), 'fly_precision', 0);
1229 // Òî÷íîñòü óêëîíåíèÿ îò ñíàðÿäîâ:
1230 cover
:= config
.ReadInt(IntToStr(a
), 'cover', 0);
1231 // Âåðîÿòíîñòü ïðûæêà ïðè ïðèáëèæåíèè ñîïåðíèêà:
1232 close_jump
:= config
.ReadInt(IntToStr(a
), 'close_jump', 0);
1233 // Ïðèîðèòåòû îðóæèÿ äëÿ äàëüíåãî áîÿ:
1234 sa
:= parse(config
.ReadStr(IntToStr(a
), 'w_prior1', ''));
1235 if Length(sa
) = 10 then
1237 w_prior1
[b
] := EnsureRange(StrToInt(sa
[b
]), 0, 9);
1238 // Ïðèîðèòåòû îðóæèÿ äëÿ áëèæíåãî áîÿ:
1239 sa
:= parse(config
.ReadStr(IntToStr(a
), 'w_prior2', ''));
1240 if Length(sa
) = 10 then
1242 w_prior2
[b
] := EnsureRange(StrToInt(sa
[b
]), 0, 9);
1244 {sa := parse(config.ReadStr(IntToStr(a), 'w_prior3', ''));
1245 if Length(sa) = 10 then
1247 w_prior3[b] := EnsureRange(StrToInt(sa[b]), 0, 9);}
1256 procedure g_Player_Free();
1260 if gPlayers
<> nil then
1262 for i
:= 0 to High(gPlayers
) do
1263 if gPlayers
[i
] <> nil then
1265 if gPlayers
[i
] is TPlayer
then
1266 TPlayer(gPlayers
[i
]).Free()
1268 TBot(gPlayers
[i
]).Free();
1279 procedure g_Player_UpdateAll();
1283 if gPlayers
= nil then Exit
;
1285 //e_WriteLog('***g_Player_UpdateAll: ENTER', MSG_WARNING);
1286 for i
:= 0 to High(gPlayers
) do
1288 if gPlayers
[i
] <> nil then
1290 if gPlayers
[i
] is TPlayer
then
1292 gPlayers
[i
].Update();
1293 gPlayers
[i
].RealizeCurrentWeapon(); // WARNING! DO NOT MOVE THIS INTO `Update()`!
1297 // bot updates weapons in `UpdateCombat()`
1298 TBot(gPlayers
[i
]).Update();
1302 //e_WriteLog('***g_Player_UpdateAll: EXIT', MSG_WARNING);
1305 procedure g_Player_DrawAll();
1309 if gPlayers
= nil then Exit
;
1311 for i
:= 0 to High(gPlayers
) do
1312 if gPlayers
[i
] <> nil then
1313 if gPlayers
[i
] is TPlayer
then gPlayers
[i
].Draw()
1314 else TBot(gPlayers
[i
]).Draw();
1317 procedure g_Player_DrawDebug(p
: TPlayer
);
1321 if p
= nil then Exit
;
1322 if (@p
.FObj
) = nil then Exit
;
1324 e_TextureFontGetSize(gStdFont
, fW
, fH
);
1326 e_TextureFontPrint(0, 0 , 'Pos X: ' + IntToStr(p
.FObj
.X
), gStdFont
);
1327 e_TextureFontPrint(0, fH
, 'Pos Y: ' + IntToStr(p
.FObj
.Y
), gStdFont
);
1328 e_TextureFontPrint(0, fH
* 2, 'Vel X: ' + IntToStr(p
.FObj
.Vel
.X
), gStdFont
);
1329 e_TextureFontPrint(0, fH
* 3, 'Vel Y: ' + IntToStr(p
.FObj
.Vel
.Y
), gStdFont
);
1330 e_TextureFontPrint(0, fH
* 4, 'Acc X: ' + IntToStr(p
.FObj
.Accel
.X
), gStdFont
);
1331 e_TextureFontPrint(0, fH
* 5, 'Acc Y: ' + IntToStr(p
.FObj
.Accel
.Y
), gStdFont
);
1334 procedure g_Player_DrawHealth();
1339 if gPlayers
= nil then Exit
;
1340 e_TextureFontGetSize(gStdFont
, fW
, fH
);
1342 for i
:= 0 to High(gPlayers
) do
1343 if gPlayers
[i
] <> nil then
1345 e_TextureFontPrint(gPlayers
[i
].FObj
.X
+ gPlayers
[i
].FObj
.Rect
.X
,
1346 gPlayers
[i
].FObj
.Y
+ gPlayers
[i
].FObj
.Rect
.Y
+ gPlayers
[i
].FObj
.Rect
.Height
- fH
* 2,
1347 IntToStr(gPlayers
[i
].FHealth
), gStdFont
);
1348 e_TextureFontPrint(gPlayers
[i
].FObj
.X
+ gPlayers
[i
].FObj
.Rect
.X
,
1349 gPlayers
[i
].FObj
.Y
+ gPlayers
[i
].FObj
.Rect
.Y
+ gPlayers
[i
].FObj
.Rect
.Height
- fH
,
1350 IntToStr(gPlayers
[i
].FArmor
), gStdFont
);
1354 function g_Player_Get(UID
: Word): TPlayer
;
1360 if gPlayers
= nil then
1363 for a
:= 0 to High(gPlayers
) do
1364 if gPlayers
[a
] <> nil then
1365 if gPlayers
[a
].FUID
= UID
then
1367 Result
:= gPlayers
[a
];
1372 function g_Player_GetCount(): Byte;
1378 if gPlayers
= nil then
1381 for a
:= 0 to High(gPlayers
) do
1382 if gPlayers
[a
] <> nil then
1383 Result
:= Result
+ 1;
1386 function g_Player_GetStats(): TPlayerStatArray
;
1392 if gPlayers
= nil then Exit
;
1394 for a
:= 0 to High(gPlayers
) do
1395 if gPlayers
[a
] <> nil then
1397 SetLength(Result
, Length(Result
)+1);
1398 with Result
[High(Result
)] do
1400 Ping
:= gPlayers
[a
].FPing
;
1401 Loss
:= gPlayers
[a
].FLoss
;
1402 Name
:= gPlayers
[a
].FName
;
1403 Team
:= gPlayers
[a
].FTeam
;
1404 Frags
:= gPlayers
[a
].FFrags
;
1405 Deaths
:= gPlayers
[a
].FDeath
;
1406 Kills
:= gPlayers
[a
].FKills
;
1407 Color
:= gPlayers
[a
].FModel
.Color
;
1408 Lives
:= gPlayers
[a
].FLives
;
1409 Spectator
:= gPlayers
[a
].FSpectator
;
1414 procedure g_Player_RememberAll
;
1418 for i
:= Low(gPlayers
) to High(gPlayers
) do
1419 if (gPlayers
[i
] <> nil) and gPlayers
[i
].Live
then
1420 gPlayers
[i
].RememberState
;
1423 procedure g_Player_ResetAll(Force
, Silent
: Boolean);
1427 gTeamStat
[TEAM_RED
].Goals
:= 0;
1428 gTeamStat
[TEAM_BLUE
].Goals
:= 0;
1430 if gPlayers
<> nil then
1431 for i
:= 0 to High(gPlayers
) do
1432 if gPlayers
[i
] <> nil then
1434 gPlayers
[i
].Reset(Force
);
1436 if gPlayers
[i
] is TPlayer
then
1438 if (not gPlayers
[i
].FSpectator
) or gPlayers
[i
].FWantsInGame
then
1439 gPlayers
[i
].Respawn(Silent
)
1441 gPlayers
[i
].Spectate();
1444 TBot(gPlayers
[i
]).Respawn(Silent
);
1448 procedure g_Player_CreateCorpse(Player
: TPlayer
);
1455 if Player
.FObj
.Y
>= gMapInfo
.Height
+128 then
1460 if (FHealth
>= -50) or (gGibsCount
= 0) then
1462 if (gCorpses
= nil) or (Length(gCorpses
) = 0) then
1466 for find_id
:= 0 to High(gCorpses
) do
1467 if gCorpses
[find_id
] = nil then
1474 find_id
:= Random(Length(gCorpses
));
1476 gCorpses
[find_id
] := TCorpse
.Create(FObj
.X
, FObj
.Y
, FModel
.Name
, FHealth
< -20);
1477 gCorpses
[find_id
].FColor
:= FModel
.Color
;
1478 gCorpses
[find_id
].FObj
.Vel
:= FObj
.Vel
;
1479 gCorpses
[find_id
].FObj
.Accel
:= FObj
.Accel
;
1482 g_Player_CreateGibs(FObj
.X
+ PLAYER_RECT_CX
,
1483 FObj
.Y
+ PLAYER_RECT_CY
,
1484 FModel
.Name
, FModel
.Color
);
1488 procedure g_Player_CreateShell(fX
, fY
, dX
, dY
: Integer; T
: Byte);
1492 if (gShells
= nil) or (Length(gShells
) = 0) then
1495 with gShells
[CurrentShell
] do
1501 if T
= SHELL_BULLET
then
1503 if g_Texture_Get('TEXTURE_SHELL_BULLET', SID
) then
1507 Obj
.Rect
.Width
:= 4;
1508 Obj
.Rect
.Height
:= 2;
1512 if g_Texture_Get('TEXTURE_SHELL_SHELL', SID
) then
1516 Obj
.Rect
.Width
:= 7;
1517 Obj
.Rect
.Height
:= 3;
1523 g_Obj_Push(@Obj
, dX
+ Random(4)-Random(4), dY
-Random(4));
1524 RAngle
:= Random(360);
1525 Timeout
:= gTime
+ SHELL_TIMEOUT
;
1527 if CurrentShell
>= High(gShells
) then
1534 procedure g_Player_CreateGibs(fX
, fY
: Integer; ModelName
: string; fColor
: TRGB
);
1537 GibsArray
: TGibsArray
;
1539 if (gGibs
= nil) or (Length(gGibs
) = 0) then
1541 if not g_PlayerModel_GetGibs(ModelName
, GibsArray
) then
1544 for a
:= 0 to High(GibsArray
) do
1545 with gGibs
[CurrentGib
] do
1548 ID
:= GibsArray
[a
].ID
;
1549 MaskID
:= GibsArray
[a
].MaskID
;
1552 Obj
.Rect
:= GibsArray
[a
].Rect
;
1553 Obj
.X
:= fX
-GibsArray
[a
].Rect
.X
-(GibsArray
[a
].Rect
.Width
div 2);
1554 Obj
.Y
:= fY
-GibsArray
[a
].Rect
.Y
-(GibsArray
[a
].Rect
.Height
div 2);
1555 g_Obj_PushA(@Obj
, 25 + Random(10), Random(361));
1556 RAngle
:= Random(360);
1558 if gBloodCount
> 0 then
1559 g_GFX_Blood(fX
, fY
, 16*gBloodCount
+Random(5*gBloodCount
), -16+Random(33), -16+Random(33),
1560 Random(48), Random(48), 150, 0, 0);
1562 if CurrentGib
>= High(gGibs
) then
1569 procedure g_Player_UpdatePhysicalObjects();
1575 procedure ShellSound_Bounce(X
, Y
: Integer; T
: Byte);
1580 if T
= SHELL_BULLET
then
1581 g_Sound_PlayExAt('SOUND_PLAYER_CASING' + IntToStr(k
), X
, Y
)
1583 g_Sound_PlayExAt('SOUND_PLAYER_SHELL' + IntToStr(k
), X
, Y
);
1588 if gGibs
<> nil then
1589 for i
:= 0 to High(gGibs
) do
1590 if gGibs
[i
].Live
then
1594 mr
:= g_Obj_Move(@Obj
, True, False, True);
1596 if WordBool(mr
and MOVE_FALLOUT
) then
1602 // Îòëåòàåò îò óäàðà î ñòåíó/ïîòîëîê/ïîë:
1603 if WordBool(mr
and MOVE_HITWALL
) then
1604 Obj
.Vel
.X
:= -(vel
.X
div 2);
1605 if WordBool(mr
and (MOVE_HITCEIL
or MOVE_HITLAND
)) then
1606 Obj
.Vel
.Y
:= -(vel
.Y
div 2);
1608 if (Obj
.Vel
.X
>= 0) then
1610 RAngle
:= RAngle
+ Abs(Obj
.Vel
.X
)*6 + Abs(Obj
.Vel
.Y
);
1611 if RAngle
>= 360 then
1612 RAngle
:= RAngle
mod 360;
1613 end else begin // Counter-clockwise
1614 RAngle
:= RAngle
- Abs(Obj
.Vel
.X
)*6 - Abs(Obj
.Vel
.Y
);
1616 RAngle
:= (360 - (Abs(RAngle
) mod 360)) mod 360;
1619 // Ñîïðîòèâëåíèå âîçäóõà äëÿ êóñêà òðóïà:
1620 if gTime
mod (GAME_TICK
*3) = 0 then
1621 Obj
.Vel
.X
:= z_dec(Obj
.Vel
.X
, 1);
1625 if gCorpses
<> nil then
1626 for i
:= 0 to High(gCorpses
) do
1627 if gCorpses
[i
] <> nil then
1628 if gCorpses
[i
].State
= CORPSE_STATE_REMOVEME
then
1634 gCorpses
[i
].Update();
1637 if gShells
<> nil then
1638 for i
:= 0 to High(gShells
) do
1639 if gShells
[i
].Live
then
1643 mr
:= g_Obj_Move(@Obj
, True, False, True);
1645 if WordBool(mr
and MOVE_FALLOUT
) or (gShells
[i
].Timeout
< gTime
) then
1651 // Îòëåòàåò îò óäàðà î ñòåíó/ïîòîëîê/ïîë:
1652 if WordBool(mr
and MOVE_HITWALL
) then
1654 Obj
.Vel
.X
:= -(vel
.X
div 2);
1655 if not WordBool(mr
and MOVE_INWATER
) then
1656 ShellSound_Bounce(Obj
.X
, Obj
.Y
, SType
);
1658 if WordBool(mr
and (MOVE_HITCEIL
or MOVE_HITLAND
)) then
1660 Obj
.Vel
.Y
:= -(vel
.Y
div 2);
1661 if Obj
.Vel
.X
<> 0 then Obj
.Vel
.X
:= Obj
.Vel
.X
div 2;
1662 if (Obj
.Vel
.X
= 0) and (Obj
.Vel
.Y
= 0) then
1664 if RAngle
mod 90 <> 0 then
1665 RAngle
:= (RAngle
div 90) * 90;
1667 else if not WordBool(mr
and MOVE_INWATER
) then
1668 ShellSound_Bounce(Obj
.X
, Obj
.Y
, SType
);
1671 if (Obj
.Vel
.X
>= 0) then
1673 RAngle
:= RAngle
+ Abs(Obj
.Vel
.X
)*8 + Abs(Obj
.Vel
.Y
);
1674 if RAngle
>= 360 then
1675 RAngle
:= RAngle
mod 360;
1676 end else begin // Counter-clockwise
1677 RAngle
:= RAngle
- Abs(Obj
.Vel
.X
)*8 - Abs(Obj
.Vel
.Y
);
1679 RAngle
:= (360 - (Abs(RAngle
) mod 360)) mod 360;
1684 procedure g_Player_DrawCorpses();
1689 if gGibs
<> nil then
1690 for i
:= 0 to High(gGibs
) do
1691 if gGibs
[i
].Live
then
1694 if not g_Obj_Collide(sX
, sY
, sWidth
, sHeight
, @Obj
) then
1697 a
.X
:= Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2);
1698 a
.y
:= Obj
.Rect
.Y
+(Obj
.Rect
.Height
div 2);
1700 e_DrawAdv(ID
, Obj
.X
, Obj
.Y
, 0, True, False, RAngle
, @a
, M_NONE
);
1703 e_DrawAdv(MaskID
, Obj
.X
, Obj
.Y
, 0, True, False, RAngle
, @a
, M_NONE
);
1709 if gCorpses
<> nil then
1710 for i
:= 0 to High(gCorpses
) do
1711 if gCorpses
[i
] <> nil then
1715 procedure g_Player_DrawShells();
1720 if gShells
<> nil then
1721 for i
:= 0 to High(gShells
) do
1722 if gShells
[i
].Live
then
1725 if not g_Obj_Collide(sX
, sY
, sWidth
, sHeight
, @Obj
) then
1731 e_DrawAdv(SpriteID
, Obj
.X
, Obj
.Y
, 0, True, False, RAngle
, @a
, M_NONE
);
1735 procedure g_Player_RemoveAllCorpses();
1741 SetLength(gGibs
, MaxGibs
);
1742 SetLength(gShells
, MaxGibs
);
1746 if gCorpses
<> nil then
1747 for i
:= 0 to High(gCorpses
) do
1751 SetLength(gCorpses
, MaxCorpses
);
1754 procedure g_Player_Corpses_SaveState(var Mem
: TBinMemoryWriter
);
1759 // Ñ÷èòàåì êîëè÷åñòâî ñóùåñòâóþùèõ òðóïîâ:
1761 if gCorpses
<> nil then
1762 for i
:= 0 to High(gCorpses
) do
1763 if gCorpses
[i
] <> nil then
1766 Mem
:= TBinMemoryWriter
.Create((count
+1) * 128);
1768 // Êîëè÷åñòâî òðóïîâ:
1769 Mem
.WriteInt(count
);
1775 for i
:= 0 to High(gCorpses
) do
1776 if gCorpses
[i
] <> nil then
1779 Mem
.WriteString(gCorpses
[i
].FModelName
);
1781 b
:= gCorpses
[i
].Mess
;
1782 Mem
.WriteBoolean(b
);
1783 // Ñîõðàíÿåì äàííûå òðóïà:
1784 gCorpses
[i
].SaveState(Mem
);
1788 procedure g_Player_Corpses_LoadState(var Mem
: TBinMemoryReader
);
1797 g_Player_RemoveAllCorpses();
1799 // Êîëè÷åñòâî òðóïîâ:
1802 if count
> Length(gCorpses
) then
1804 raise EBinSizeError
.Create('g_Player_Corpses_LoadState: Too Many Corpses');
1811 for i
:= 0 to count
-1 do
1814 Mem
.ReadString(str
);
1818 gCorpses
[i
] := TCorpse
.Create(0, 0, str
, b
);
1819 // Çàãðóæàåì äàííûå òðóïà:
1820 gCorpses
[i
].LoadState(Mem
);
1826 procedure TPlayer
.BFGHit();
1828 g_Weapon_BFGHit(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
1829 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2));
1830 if g_Game_IsServer
and g_Game_IsNet
then
1831 MH_SEND_Effect(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
1832 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2),
1836 procedure TPlayer
.ChangeModel(ModelName
: string);
1838 Model
: TPlayerModel
;
1840 Model
:= g_PlayerModel_Get(ModelName
);
1841 if Model
= nil then Exit
;
1847 procedure TPlayer
.SetModel(ModelName
: string);
1851 m
:= g_PlayerModel_Get(ModelName
);
1854 g_SimpleError(Format(_lc
[I_GAME_ERROR_MODEL_FALLBACK
], [ModelName
]));
1855 m
:= g_PlayerModel_Get('doomer');
1858 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], ['doomer']));
1863 if FModel
<> nil then
1868 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
1869 FModel
.Color
:= FColor
1871 FModel
.Color
:= TEAMCOLOR
[FTeam
];
1872 FModel
.SetWeapon(FCurrWeap
);
1873 FModel
.SetFlag(FFlag
);
1874 SetDirection(FDirection
);
1877 procedure TPlayer
.SetColor(Color
: TRGB
);
1880 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
1881 if FModel
<> nil then FModel
.Color
:= Color
;
1884 procedure TPlayer
.SwitchTeam
;
1886 if g_Game_IsClient
then
1888 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then Exit
;
1890 if gGameOn
and FLive
then
1891 Kill(K_SIMPLEKILL
, FUID
, HIT_SELF
);
1893 if FTeam
= TEAM_RED
then
1895 ChangeTeam(TEAM_BLUE
);
1896 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_BLUE
], [FName
]), True);
1897 if g_Game_IsNet
then
1898 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM
, TEAM_BLUE
, FName
);
1902 ChangeTeam(TEAM_RED
);
1903 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_RED
], [FName
]), True);
1904 if g_Game_IsNet
then
1905 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM
, TEAM_RED
, FName
);
1907 FPreferredTeam
:= FTeam
;
1910 procedure TPlayer
.ChangeTeam(Team
: Byte);
1917 TEAM_RED
, TEAM_BLUE
:
1918 FModel
.Color
:= TEAMCOLOR
[Team
];
1920 FModel
.Color
:= FColor
;
1922 if (FTeam
<> OldTeam
) and g_Game_IsNet
and g_Game_IsServer
then
1923 MH_SEND_PlayerStats(FUID
);
1927 procedure TPlayer.CollideItem();
1932 if gItems = nil then Exit;
1933 if not FLive then Exit;
1935 for i := 0 to High(gItems) do
1938 if (ItemType <> ITEM_NONE) and Live then
1939 if g_Obj_Collide(FObj.X+PLAYER_RECT.X, FObj.Y+PLAYER_RECT.Y, PLAYER_RECT.Width,
1940 PLAYER_RECT.Height, @Obj) then
1942 if not PickItem(ItemType, gItems[i].Respawnable, r) then Continue;
1944 if ItemType in [ITEM_SPHERE_BLUE, ITEM_SPHERE_WHITE, ITEM_INVUL] then
1945 g_Sound_PlayExAt('SOUND_ITEM_GETRULEZ', FObj.X, FObj.Y)
1946 else if ItemType in [ITEM_MEDKIT_SMALL, ITEM_MEDKIT_LARGE, ITEM_MEDKIT_BLACK] then
1947 g_Sound_PlayExAt('SOUND_ITEM_GETMED', FObj.X, FObj.Y)
1948 else g_Sound_PlayExAt('SOUND_ITEM_GETITEM', FObj.X, FObj.Y);
1950 // Íàäî óáðàòü ñ êàðòû, åñëè ýòî íå êëþ÷, êîòîðûì íóæíî ïîäåëèòñÿ ñ äðóãèì èãðîêîì:
1951 if r and not ((ItemType in [ITEM_KEY_RED, ITEM_KEY_GREEN, ITEM_KEY_BLUE]) and
1952 (gGameSettings.GameType = GT_SINGLE) and
1953 (g_Player_GetCount() > 1)) then
1954 if not Respawnable then g_Items_Remove(i) else g_Items_Pick(i);
1960 function TPlayer
.CollideLevel(XInc
, YInc
: Integer): Boolean;
1962 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
1963 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_WALL
,
1967 constructor TPlayer
.Create();
1973 FSawSound
:= TPlayableSound
.Create();
1974 FSawSoundIdle
:= TPlayableSound
.Create();
1975 FSawSoundHit
:= TPlayableSound
.Create();
1976 FSawSoundSelect
:= TPlayableSound
.Create();
1977 FJetSoundFly
:= TPlayableSound
.Create();
1978 FJetSoundOn
:= TPlayableSound
.Create();
1979 FJetSoundOff
:= TPlayableSound
.Create();
1981 FSawSound
.SetByName('SOUND_WEAPON_FIRESAW');
1982 FSawSoundIdle
.SetByName('SOUND_WEAPON_IDLESAW');
1983 FSawSoundHit
.SetByName('SOUND_WEAPON_HITSAW');
1984 FSawSoundSelect
.SetByName('SOUND_WEAPON_SELECTSAW');
1985 FJetSoundFly
.SetByName('SOUND_PLAYER_JETFLY');
1986 FJetSoundOn
.SetByName('SOUND_PLAYER_JETON');
1987 FJetSoundOff
.SetByName('SOUND_PLAYER_JETOFF');
1989 FSpectatePlayer
:= -1;
1993 FSavedState
.WaitRecall
:= False;
1999 FActualModelName
:= 'doomer';
2002 FObj
.Rect
:= PLAYER_RECT
;
2004 FBFGFireCounter
:= -1;
2005 FJustTeleported
:= False;
2011 procedure TPlayer
.Damage(value
: Word; SpawnerUID
: Word; vx
, vy
: Integer; t
: Byte);
2015 if (not g_Game_IsClient
) and (not FLive
) then
2020 // Íåóÿçâèìîñòü íå ñïàñàåò îò ëîâóøåê:
2021 if ((t
= HIT_TRAP
) or (t
= HIT_SELF
)) and (not FGodMode
) then
2023 if not g_Game_IsClient
then
2026 if t
= HIT_TRAP
then
2028 // Ëîâóøêà óáèâàåò ñðàçó:
2030 Kill(K_EXTRAHARDKILL
, SpawnerUID
, t
);
2032 if t
= HIT_SELF
then
2036 Kill(K_SIMPLEKILL
, SpawnerUID
, t
);
2039 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
2040 FMegaRulez
[MR_SUIT
] := 0;
2041 FMegaRulez
[MR_INVUL
] := 0;
2042 FMegaRulez
[MR_INVIS
] := 0;
2046 // Íî îò îñòàëüíîãî ñïàñàåò:
2047 if FMegaRulez
[MR_INVUL
] >= gTime
then
2054 // Åñëè åñòü óðîí ñâîèì, èëè ðàíèë ñàì ñåáÿ, èëè òåáÿ ðàíèë ïðîòèâíèê:
2055 if LongBool(gGameSettings
.Options
and GAME_OPTION_TEAMDAMAGE
) or
2056 (SpawnerUID
= FUID
) or
2057 (not SameTeam(FUID
, SpawnerUID
)) then
2059 FLastSpawnerUID
:= SpawnerUID
;
2061 // Êðîâü (ïóçûðüêè, åñëè â âîäå):
2062 if gBloodCount
> 0 then
2064 c
:= Min(value
, 200)*gBloodCount
+ Random(Min(value
, 200) div 2);
2065 if value
div 4 <= c
then
2066 c
:= c
- (value
div 4)
2070 if (t
= HIT_SOME
) and (vx
= 0) and (vy
= 0) then
2074 HIT_TRAP
, HIT_ACID
, HIT_FLAME
, HIT_SELF
: MakeBloodSimple(c
);
2075 HIT_BFG
, HIT_ROCKET
, HIT_SOME
: MakeBloodVector(c
, vx
, vy
);
2078 if t
= HIT_WATER
then
2079 g_GFX_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
2080 FObj
.Y
+PLAYER_RECT
.Y
-4, value
div 2, 8, 4);
2085 Inc(FDamageBuffer
, value
);
2089 FPain
:= FPain
+ value
;
2092 if g_Game_IsServer
and g_Game_IsNet
then
2094 MH_SEND_PlayerDamage(FUID
, t
, SpawnerUID
, value
, vx
, vy
);
2095 MH_SEND_PlayerStats(FUID
);
2096 MH_SEND_PlayerPos(False, FUID
);
2100 function TPlayer
.Heal(value
: Word; Soft
: Boolean): Boolean;
2103 if g_Game_IsClient
then
2108 if Soft
and (FHealth
< PLAYER_HP_SOFT
) then
2110 IncMax(FHealth
, value
, PLAYER_HP_SOFT
);
2113 if (not Soft
) and (FHealth
< PLAYER_HP_LIMIT
) then
2115 IncMax(FHealth
, value
, PLAYER_HP_LIMIT
);
2119 if Result
and g_Game_IsServer
and g_Game_IsNet
then
2120 MH_SEND_PlayerStats(FUID
);
2123 destructor TPlayer
.Destroy();
2125 if (gPlayer1
<> nil) and (gPlayer1
.FUID
= FUID
) then
2127 if (gPlayer2
<> nil) and (gPlayer2
.FUID
= FUID
) then
2131 FSawSoundIdle
.Free();
2132 FSawSoundHit
.Free();
2133 FJetSoundFly
.Free();
2135 FJetSoundOff
.Free();
2141 procedure TPlayer
.DrawBubble();
2143 bubX
, bubY
: Integer;
2146 Rw
, Gw
, Bw
: SmallInt;
2149 bubX
:= FObj
.X
+FObj
.Rect
.X
+ IfThen(FDirection
= D_LEFT
, -4, 18);
2150 bubY
:= FObj
.Y
+FObj
.Rect
.Y
- 18;
2158 1: // simple textual non-bubble
2160 bubX
:= FObj
.X
+FObj
.Rect
.X
- 11;
2161 bubY
:= FObj
.Y
+FObj
.Rect
.Y
- 17;
2162 e_TextureFontPrint(bubX
, bubY
, '[...]', gStdFont
);
2165 2: // advanced pixel-perfect bubble
2167 if FTeam
= TEAM_RED
then
2170 if FTeam
= TEAM_BLUE
then
2173 3: // colored bubble
2175 Rb
:= FModel
.Color
.R
;
2176 Gb
:= FModel
.Color
.G
;
2177 Bb
:= FModel
.Color
.B
;
2178 Rw
:= Min(Rb
* 2 + 64, 255);
2179 Gw
:= Min(Gb
* 2 + 64, 255);
2180 Bw
:= Min(Bb
* 2 + 64, 255);
2181 if (Abs(Rw
- Rb
) < 32)
2182 or (Abs(Gw
- Gb
) < 32)
2183 or (Abs(Bw
- Bb
) < 32) then
2185 Rb
:= Max(Rw
div 2 - 16, 0);
2186 Gb
:= Max(Gw
div 2 - 16, 0);
2187 Bb
:= Max(Bw
div 2 - 16, 0);
2190 4: // custom textured bubble
2192 if g_Texture_Get('TEXTURE_PLAYER_TALKBUBBLE', ID
) then
2193 if FDirection
= D_RIGHT
then
2194 e_Draw(ID
, bubX
- 6, bubY
- 7, 0, True, False)
2196 e_Draw(ID
, bubX
- 6, bubY
- 7, 0, True, False, M_HORIZONTAL
);
2202 e_DrawQuad(bubX
+ 1, bubY
, bubX
+ 18, bubY
+ 13, Rb
, Gb
, Bb
);
2203 e_DrawQuad(bubX
, bubY
+ 1, bubX
+ 19, bubY
+ 12, Rb
, Gb
, Bb
);
2205 e_DrawFillQuad(bubX
+ 1, bubY
+ 1, bubX
+ 18, bubY
+ 12, Rw
, Gw
, Bw
, 0);
2208 Dot
:= IfThen(FDirection
= D_LEFT
, 14, 5);
2209 e_DrawLine(1, bubX
+ Dot
, bubY
+ 14, bubX
+ Dot
, bubY
+ 16, Rb
, Gb
, Bb
);
2210 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
);
2211 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
);
2212 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
);
2213 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
);
2217 e_DrawFillQuad(bubX
+ Dot
, bubY
+ 8, bubX
+ Dot
+ 1, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2218 e_DrawFillQuad(bubX
+ Dot
+ 3, bubY
+ 8, bubX
+ Dot
+ 4, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2219 e_DrawFillQuad(bubX
+ Dot
+ 6, bubY
+ 8, bubX
+ Dot
+ 7, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2222 procedure TPlayer
.Draw();
2230 if (FMegaRulez
[MR_INVUL
] > gTime
) and (gPlayerDrawn
<> Self
) then
2231 if g_Texture_Get('TEXTURE_PLAYER_INVULPENTA', ID
) then
2233 e_GetTextureSize(ID
, @w
, @h
);
2234 if FDirection
= D_LEFT
then
2235 e_Draw(ID
, FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2)-(w
div 2)+4,
2236 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2)-(h
div 2)-7, 0, True, False)
2238 e_Draw(ID
, FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2)-(w
div 2)-2,
2239 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2)-(h
div 2)-7, 0, True, False);
2242 if FMegaRulez
[MR_INVIS
] > gTime
then
2244 if (gPlayerDrawn
<> nil) and ((Self
= gPlayerDrawn
) or
2245 ((FTeam
= gPlayerDrawn
.Team
) and (gGameSettings
.GameMode
<> GM_DM
))) then
2247 if (FMegaRulez
[MR_INVIS
] - gTime
) <= 2100 then
2248 dr
:= not Odd((FMegaRulez
[MR_INVIS
] - gTime
) div 300)
2252 FModel
.Draw(FObj
.X
, FObj
.Y
, 200)
2254 FModel
.Draw(FObj
.X
, FObj
.Y
);
2257 FModel
.Draw(FObj
.X
, FObj
.Y
, 254);
2260 FModel
.Draw(FObj
.X
, FObj
.Y
);
2263 if g_debug_Frames
then
2265 e_DrawQuad(FObj
.X
+FObj
.Rect
.X
,
2267 FObj
.X
+FObj
.Rect
.X
+FObj
.Rect
.Width
-1,
2268 FObj
.Y
+FObj
.Rect
.Y
+FObj
.Rect
.Height
-1,
2272 if (gChatBubble
> 0) and (FKeys
[KEY_CHAT
].Pressed
) and not FGhost
then
2274 // e_DrawPoint(5, 335, 288, 255, 0, 0); // DL, UR, DL, UR
2275 if gAimLine
and Live
and
2276 ((Self
= gPlayer1
) or (Self
= gPlayer2
)) then
2280 procedure TPlayer
.DrawAim();
2282 wx
, wy
, xx
, yy
: Integer;
2286 wx
:= FObj
.X
+ WEAPONPOINT
[FDirection
].X
+ IfThen(FDirection
= D_LEFT
, 7, -7);
2287 wy
:= FObj
.Y
+ WEAPONPOINT
[FDirection
].Y
;
2296 1: begin // Chainsaw
2303 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2304 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2305 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2306 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2311 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2312 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2313 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2314 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2316 4: begin // Double Shotgun
2319 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2320 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2321 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2322 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2324 5: begin // Chaingun
2327 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2328 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2329 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2330 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2332 6: begin // Rocket Launcher
2335 if angle
= ANGLE_RIGHTUP
then Inc(angle
, 2);
2336 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2337 if angle
= ANGLE_LEFTUP
then Dec(angle
, 2);
2338 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2340 7: begin // Plasmagun
2343 if angle
= ANGLE_RIGHTUP
then Inc(angle
);
2344 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 3);
2345 if angle
= ANGLE_LEFTUP
then Dec(angle
);
2346 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 3);
2351 if angle
= ANGLE_RIGHTUP
then Inc(angle
, 1);
2352 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 2);
2353 if angle
= ANGLE_LEFTUP
then Dec(angle
, 1);
2354 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 2);
2356 9: begin // Super Chaingun
2359 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2360 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2361 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2362 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2365 xx
:= Trunc(Cos(-DegToRad(angle
)) * len
) + wx
;
2366 yy
:= Trunc(Sin(-DegToRad(angle
)) * len
) + wy
;
2367 e_DrawLine(sz
, wx
, wy
, xx
, yy
, 255, 0, 0, 96);
2370 procedure TPlayer
.DrawGUI();
2373 X
, Y
, SY
, a
, p
, m
: Integer;
2377 stat
: TPlayerStatArray
;
2379 X
:= gPlayerScreenSize
.X
;
2380 SY
:= gPlayerScreenSize
.Y
;
2383 if gShowGoals
and (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
2385 if gGameSettings
.GameMode
= GM_CTF
then
2389 if gGameSettings
.GameMode
= GM_CTF
then
2391 s
:= 'TEXTURE_PLAYER_REDFLAG';
2392 if gFlags
[FLAG_RED
].State
= FLAG_STATE_CAPTURED
then
2393 s
:= 'TEXTURE_PLAYER_REDFLAG_S';
2394 if gFlags
[FLAG_RED
].State
= FLAG_STATE_DROPPED
then
2395 s
:= 'TEXTURE_PLAYER_REDFLAG_D';
2396 if g_Texture_Get(s
, ID
) then
2397 e_Draw(ID
, X
-16-32, 240-72-4, 0, True, False);
2400 s
:= IntToStr(gTeamStat
[TEAM_RED
].Goals
);
2401 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2402 e_CharFont_PrintEx(gMenuFont
, X
-16-a
-tw
, 240-72-4, s
, TEAMCOLOR
[TEAM_RED
]);
2404 if gGameSettings
.GameMode
= GM_CTF
then
2406 s
:= 'TEXTURE_PLAYER_BLUEFLAG';
2407 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_CAPTURED
then
2408 s
:= 'TEXTURE_PLAYER_BLUEFLAG_S';
2409 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_DROPPED
then
2410 s
:= 'TEXTURE_PLAYER_BLUEFLAG_D';
2411 if g_Texture_Get(s
, ID
) then
2412 e_Draw(ID
, X
-16-32, 240-32-4, 0, True, False);
2415 s
:= IntToStr(gTeamStat
[TEAM_BLUE
].Goals
);
2416 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2417 e_CharFont_PrintEx(gMenuFont
, X
-16-a
-tw
, 240-32-4, s
, TEAMCOLOR
[TEAM_BLUE
]);
2420 if g_Texture_Get('TEXTURE_PLAYER_HUDBG', ID
) then
2421 e_DrawFill(ID
, X
, 0, 1, (gPlayerScreenSize
.Y
div 256)+IfThen(gPlayerScreenSize
.Y
mod 256 > 0, 1, 0),
2424 if g_Texture_Get('TEXTURE_PLAYER_HUD', ID
) then
2425 e_Draw(ID
, X
+2, Y
, 0, True, False);
2427 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
2431 s
:= IntToStr(Frags
);
2432 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2433 e_CharFont_PrintEx(gMenuFont
, X
-16-tw
, Y
, s
, _RGB(255, 0, 0));
2438 stat
:= g_Player_GetStats();
2443 for a
:= 0 to High(stat
) do
2444 if stat
[a
].Name
<> Name
then
2446 if stat
[a
].Frags
> m
then m
:= stat
[a
].Frags
;
2447 if stat
[a
].Frags
> Frags
then p
:= p
+1;
2451 s
:= IntToStr(p
)+' / '+IntToStr(Length(stat
))+' ';
2452 if Frags
>= m
then s
:= s
+'+' else s
:= s
+'-';
2453 s
:= s
+IntToStr(Abs(Frags
-m
));
2455 e_CharFont_GetSize(gMenuSmallFont
, s
, tw
, th
);
2456 e_CharFont_PrintEx(gMenuSmallFont
, X
-16-tw
, Y
+32, s
, _RGB(255, 0, 0));
2459 if gShowLives
and (gGameSettings
.MaxLives
> 0) then
2461 s
:= IntToStr(Lives
);
2462 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2463 e_CharFont_PrintEx(gMenuFont
, X
-16-tw
, SY
-32, s
, _RGB(0, 255, 0));
2467 e_CharFont_GetSize(gMenuSmallFont
, FName
, tw
, th
);
2468 e_CharFont_PrintEx(gMenuSmallFont
, X
+98-(tw
div 2), Y
+8, FName
, _RGB(255, 0, 0));
2470 if R_BERSERK
in FRulez
then
2471 e_Draw(gItemsTexturesID
[ITEM_MEDKIT_BLACK
], X
+37, Y
+45, 0, True, False)
2473 e_Draw(gItemsTexturesID
[ITEM_MEDKIT_LARGE
], X
+37, Y
+45, 0, True, False);
2475 if g_Texture_Get('TEXTURE_PLAYER_ARMORHUD', ID
) then
2476 e_Draw(ID
, X
+36, Y
+77, 0, True, False);
2478 s
:= IntToStr(IfThen(FHealth
> 0, FHealth
, 0));
2479 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2480 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+40, s
, _RGB(255, 0, 0));
2482 s
:= IntToStr(FArmor
);
2483 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2484 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+68, s
, _RGB(255, 0, 0));
2486 s
:= IntToStr(GetAmmoByWeapon(FCurrWeap
));
2492 ID
:= gItemsTexturesID
[ITEM_WEAPON_KASTET
];
2497 ID
:= gItemsTexturesID
[ITEM_WEAPON_SAW
];
2499 WEAPON_PISTOL
: ID
:= gItemsTexturesID
[ITEM_WEAPON_PISTOL
];
2500 WEAPON_CHAINGUN
: ID
:= gItemsTexturesID
[ITEM_WEAPON_CHAINGUN
];
2501 WEAPON_SHOTGUN1
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SHOTGUN1
];
2502 WEAPON_SHOTGUN2
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SHOTGUN2
];
2503 WEAPON_SUPERPULEMET
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SUPERPULEMET
];
2504 WEAPON_ROCKETLAUNCHER
: ID
:= gItemsTexturesID
[ITEM_WEAPON_ROCKETLAUNCHER
];
2505 WEAPON_PLASMA
: ID
:= gItemsTexturesID
[ITEM_WEAPON_PLASMA
];
2506 WEAPON_BFG
: ID
:= gItemsTexturesID
[ITEM_WEAPON_BFG
];
2507 WEAPON_FLAMETHROWER
: ID
:= gItemsTexturesID
[ITEM_WEAPON_FLAMETHROWER
];
2510 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2511 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+158, s
, _RGB(255, 0, 0));
2512 e_Draw(ID
, X
+20, Y
+160, 0, True, False);
2514 if R_KEY_RED
in FRulez
then
2515 e_Draw(gItemsTexturesID
[ITEM_KEY_RED
], X
+78, Y
+214, 0, True, False);
2517 if R_KEY_GREEN
in FRulez
then
2518 e_Draw(gItemsTexturesID
[ITEM_KEY_GREEN
], X
+95, Y
+214, 0, True, False);
2520 if R_KEY_BLUE
in FRulez
then
2521 e_Draw(gItemsTexturesID
[ITEM_KEY_BLUE
], X
+112, Y
+214, 0, True, False);
2523 if FJetFuel
> 0 then
2525 if g_Texture_Get('TEXTURE_PLAYER_HUDAIR', ID
) then
2526 e_Draw(ID
, X
+2, Y
+116, 0, True, False);
2527 if g_Texture_Get('TEXTURE_PLAYER_HUDJET', ID
) then
2528 e_Draw(ID
, X
+2, Y
+126, 0, True, False);
2529 e_DrawLine(4, X
+16, Y
+122, X
+16+Trunc(168*IfThen(FAir
> 0, FAir
, 0)/AIR_MAX
), Y
+122, 0, 0, 196);
2530 e_DrawLine(4, X
+16, Y
+132, X
+16+Trunc(168*FJetFuel
/JET_MAX
), Y
+132, 208, 0, 0);
2534 if g_Texture_Get('TEXTURE_PLAYER_HUDAIR', ID
) then
2535 e_Draw(ID
, X
+2, Y
+124, 0, True, False);
2536 e_DrawLine(4, X
+16, Y
+130, X
+16+Trunc(168*IfThen(FAir
> 0, FAir
, 0)/AIR_MAX
), Y
+130, 0, 0, 196);
2539 if gShowPing
and g_Game_IsClient
then
2541 s
:= _lc
[I_GAME_PING_HUD
] + IntToStr(NetPeer
.lastRoundTripTime
) + _lc
[I_NET_SLIST_PING_MS
];
2542 e_TextureFontPrint(X
+ 4, Y
+ 242, s
, gStdFont
);
2548 e_TextureFontPrint(X
+ 4, Y
+ 242, _lc
[I_PLAYER_SPECT
], gStdFont
);
2549 e_TextureFontPrint(X
+ 4, Y
+ 258, _lc
[I_PLAYER_SPECT2
], gStdFont
);
2550 e_TextureFontPrint(X
+ 4, Y
+ 274, _lc
[I_PLAYER_SPECT1
], gStdFont
);
2553 e_TextureFontGetSize(gStdFont
, cw
, ch
);
2554 s
:= _lc
[I_PLAYER_SPECT4
];
2555 e_TextureFontPrintEx(gScreenWidth
div 2 - cw
*(Length(s
) div 2),
2556 gScreenHeight
-4-ch
, s
, gStdFont
, 255, 255, 255, 1, True);
2557 e_TextureFontPrint(X
+ 4, Y
+ 290, _lc
[I_PLAYER_SPECT1S
], gStdFont
);
2563 procedure TPlayer
.DrawRulez();
2567 // Ïðè âçÿòèè íåóÿçâèìîñòè ðèñóåòñÿ èíâåðñèîííûé áåëûé ôîí
2568 if FMegaRulez
[MR_INVUL
] >= gTime
then
2570 if (FMegaRulez
[MR_INVUL
]-gTime
) <= 2100 then
2571 dr
:= not Odd((FMegaRulez
[MR_INVUL
]-gTime
) div 300)
2576 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2577 191, 191, 191, 0, B_INVERT
);
2580 // Ïðè âçÿòèè çàùèòíîãî êîñòþìà ðèñóåòñÿ çåëåíîâàòûé ôîí
2581 if FMegaRulez
[MR_SUIT
] >= gTime
then
2583 if (FMegaRulez
[MR_SUIT
]-gTime
) <= 2100 then
2584 dr
:= not Odd((FMegaRulez
[MR_SUIT
]-gTime
) div 300)
2589 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2590 0, 96, 0, 200, B_NONE
);
2593 // Ïðè âçÿòèè áåðñåðêà ðèñóåòñÿ êðàñíîâàòûé ôîí
2594 if (FBerserk
>= 0) and (LongWord(FBerserk
) >= gTime
) and (gFlash
= 2) then
2596 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2597 255, 0, 0, 200, B_NONE
);
2601 procedure TPlayer
.DrawPain();
2605 if FPain
= 0 then Exit
;
2609 if a
< 15 then h
:= 0
2610 else if a
< 35 then h
:= 1
2611 else if a
< 55 then h
:= 2
2612 else if a
< 75 then h
:= 3
2613 else if a
< 95 then h
:= 4
2616 //if a > 255 then a := 255;
2618 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1, 255, 0, 0, 255-h
*50);
2619 //e_DrawFillQuad(0, 0, gPlayerScreenSize.X-1, gPlayerScreenSize.Y-1, 255-min(128, a), 255-a, 255-a, 0, B_FILTER);
2622 procedure TPlayer
.DrawPickup();
2626 if FPickup
= 0 then Exit
;
2630 if a
< 15 then h
:= 1
2631 else if a
< 35 then h
:= 2
2632 else if a
< 55 then h
:= 3
2633 else if a
< 75 then h
:= 4
2636 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1, 150, 200, 150, 255-h
*50);
2639 procedure TPlayer
.Fire();
2641 f
, DidFire
: Boolean;
2642 wx
, wy
, xd
, yd
: Integer;
2645 if g_Game_IsClient
then Exit
;
2646 // FBFGFireCounter - âðåìÿ ïåðåä âûñòðåëîì (äëÿ BFG)
2647 // FReloading - âðåìÿ ïîñëå âûñòðåëà (äëÿ âñåãî)
2655 if FReloading
[FCurrWeap
] <> 0 then Exit
;
2660 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
2661 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
2662 xd
:= wx
+IfThen(FDirection
= D_LEFT
, -30, 30);
2663 yd
:= wy
+firediry();
2668 if R_BERSERK
in FRulez
then
2670 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
2671 obj
.X
:= FObj
.X
+FObj
.Rect
.X
;
2672 obj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
2675 obj
.rect
.Width
:= 39;
2676 obj
.rect
.Height
:= 52;
2677 obj
.Vel
.X
:= (xd
-wx
) div 2;
2678 obj
.Vel
.Y
:= (yd
-wy
) div 2;
2679 obj
.Accel
.X
:= xd
-wx
;
2680 obj
.Accel
.y
:= yd
-wy
;
2682 if g_Weapon_Hit(@obj
, 50, FUID
, HIT_SOME
) <> 0 then
2683 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
2685 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
2689 FPain
:= min(FPain
+ 25, 50);
2690 end else g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
2693 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2698 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
2699 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
2701 FSawSoundSelect
.Stop();
2703 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
2705 else if not FSawSoundHit
.IsPlaying() then
2707 FSawSoundSelect
.Stop();
2708 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
2711 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2717 if FAmmo
[A_BULLETS
] > 0 then
2719 g_Weapon_pistol(wx
, wy
, xd
, yd
, FUID
);
2720 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2721 Dec(FAmmo
[A_BULLETS
]);
2722 FFireAngle
:= FAngle
;
2725 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
2726 GameVelX
, GameVelY
-2, SHELL_BULLET
);
2730 if FAmmo
[A_SHELLS
] > 0 then
2732 g_Weapon_shotgun(wx
, wy
, xd
, yd
, FUID
);
2733 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', wx
, wy
);
2734 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2735 Dec(FAmmo
[A_SHELLS
]);
2736 FFireAngle
:= FAngle
;
2740 FShellType
:= SHELL_SHELL
;
2744 if FAmmo
[A_SHELLS
] >= 2 then
2746 g_Weapon_dshotgun(wx
, wy
, xd
, yd
, FUID
);
2747 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2748 Dec(FAmmo
[A_SHELLS
], 2);
2749 FFireAngle
:= FAngle
;
2753 FShellType
:= SHELL_DBLSHELL
;
2757 if FAmmo
[A_BULLETS
] > 0 then
2759 g_Weapon_mgun(wx
, wy
, xd
, yd
, FUID
);
2760 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', wx
, wy
);
2761 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2762 Dec(FAmmo
[A_BULLETS
]);
2763 FFireAngle
:= FAngle
;
2766 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
2767 GameVelX
, GameVelY
-2, SHELL_BULLET
);
2770 WEAPON_ROCKETLAUNCHER
:
2771 if FAmmo
[A_ROCKETS
] > 0 then
2773 g_Weapon_rocket(wx
, wy
, xd
, yd
, FUID
);
2774 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2775 Dec(FAmmo
[A_ROCKETS
]);
2776 FFireAngle
:= FAngle
;
2782 if FAmmo
[A_CELLS
] > 0 then
2784 g_Weapon_plasma(wx
, wy
, xd
, yd
, FUID
);
2785 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2786 Dec(FAmmo
[A_CELLS
]);
2787 FFireAngle
:= FAngle
;
2793 if (FAmmo
[A_CELLS
] >= 40) and (FBFGFireCounter
= -1) then
2795 FBFGFireCounter
:= 17;
2796 if not FNoReload
then
2797 g_Sound_PlayExAt('SOUND_WEAPON_STARTFIREBFG', FObj
.X
, FObj
.Y
);
2798 Dec(FAmmo
[A_CELLS
], 40);
2802 WEAPON_SUPERPULEMET
:
2803 if FAmmo
[A_SHELLS
] > 0 then
2805 g_Weapon_shotgun(wx
, wy
, xd
, yd
, FUID
);
2806 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', wx
, wy
);
2807 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2808 Dec(FAmmo
[A_SHELLS
]);
2809 FFireAngle
:= FAngle
;
2812 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
2813 GameVelX
, GameVelY
-2, SHELL_SHELL
);
2816 WEAPON_FLAMETHROWER
:
2817 if FAmmo
[A_FUEL
] > 0 then
2819 g_Weapon_flame(wx
, wy
, xd
, yd
, FUID
);
2820 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2822 FFireAngle
:= FAngle
;
2828 if g_Game_IsNet
then
2832 if FCurrWeap
<> WEAPON_BFG
then
2833 MH_SEND_PlayerFire(FUID
, FCurrWeap
, wx
, wy
, xd
, yd
, LastShotID
)
2835 if not FNoReload
then
2836 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_WEAPON_STARTFIREBFG');
2839 MH_SEND_PlayerStats(FUID
);
2844 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
2845 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
2846 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
2849 function TPlayer
.GetAmmoByWeapon(Weapon
: Byte): Word;
2852 WEAPON_PISTOL
, WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
];
2853 WEAPON_SHOTGUN1
, WEAPON_SHOTGUN2
, WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
];
2854 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
];
2855 WEAPON_PLASMA
, WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
];
2856 WEAPON_FLAMETHROWER
: Result
:= FAmmo
[A_FUEL
];
2861 function TPlayer
.HeadInLiquid(XInc
, YInc
: Integer): Boolean;
2863 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
+XInc
, FObj
.Y
+PLAYER_HEADRECT
.Y
+YInc
,
2864 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
2865 PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, True);
2868 procedure TPlayer
.JetpackOn
;
2872 FJetSoundOn
.SetPosition(0);
2873 FJetSoundOn
.PlayAt(FObj
.X
, FObj
.Y
);
2877 procedure TPlayer
.JetpackOff
;
2881 FJetSoundOff
.SetPosition(0);
2882 FJetSoundOff
.PlayAt(FObj
.X
, FObj
.Y
);
2885 procedure TPlayer
.CatchFire(Attacker
: Word);
2888 FFireAttacker
:= Attacker
;
2889 if g_Game_IsNet
and g_Game_IsServer
then
2890 MH_SEND_PlayerStats(FUID
);
2893 procedure TPlayer
.Jump();
2895 if gFly
or FJetpack
then
2897 // Ïîëåò (÷èò-êîä èëè äæåòïàê):
2898 if FObj
.Vel
.Y
> -VEL_FLY
then
2899 FObj
.Vel
.Y
:= FObj
.Vel
.Y
- 3;
2902 if FJetFuel
> 0 then
2904 if (FJetFuel
< 1) and g_Game_IsServer
then
2908 if g_Game_IsNet
then
2909 MH_SEND_PlayerStats(FUID
);
2915 // Íå âêëþ÷àòü äæåòïàê â ðåæèìå ïðîõîæäåíèÿ ñêâîçü ñòåíû
2917 FCanJetpack
:= False;
2919 // Ïðûãàåì èëè âñïëûâàåì:
2920 if (CollideLevel(0, 1) or
2921 g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
+36, PLAYER_RECT
.Width
,
2922 PLAYER_RECT
.Height
-33, PANEL_STEP
, False)
2923 ) and (FObj
.Accel
.Y
= 0) then // Íå ïðûãàòü, åñëè åñòü âåðòèêàëüíîå óñêîðåíèå
2925 FObj
.Vel
.Y
:= -VEL_JUMP
;
2926 FCanJetpack
:= False;
2930 if BodyInLiquid(0, 0) then
2931 FObj
.Vel
.Y
:= -VEL_SW
2932 else if (FJetFuel
> 0) and FCanJetpack
and
2933 g_Game_IsServer
and (not g_Obj_CollideLiquid(@FObj
, 0, 0)) then
2937 if g_Game_IsNet
then
2938 MH_SEND_PlayerStats(FUID
);
2943 procedure TPlayer
.Kill(KillType
: Byte; SpawnerUID
: Word; t
: Byte);
2945 a
, i
, k
, ab
, ar
: Byte;
2949 srv
, netsrv
: Boolean;
2954 procedure PushItem(t
: Byte);
2958 id
:= g_Items_Create(FObj
.X
, FObj
.Y
, t
, True, False);
2959 if KillType
= K_EXTRAHARDKILL
then // -7..+7; -8..0
2960 g_Obj_Push(@gItems
[id
].Obj
, (FObj
.Vel
.X
div 2)-7+Random(15),
2961 (FObj
.Vel
.Y
div 2)-Random(9))
2963 if KillType
= K_HARDKILL
then // -5..+5; -5..0
2964 g_Obj_Push(@gItems
[id
].Obj
, (FObj
.Vel
.X
div 2)-5+Random(11),
2965 (FObj
.Vel
.Y
div 2)-Random(6))
2966 else // -3..+3; -3..0
2967 g_Obj_Push(@gItems
[id
].Obj
, (FObj
.Vel
.X
div 2)-3+Random(7),
2968 (FObj
.Vel
.Y
div 2)-Random(4));
2970 if g_Game_IsNet
and g_Game_IsServer
then
2971 MH_SEND_ItemSpawn(True, id
);
2975 DoFrags
:= (gGameSettings
.MaxLives
= 0) or (gGameSettings
.GameMode
= GM_COOP
);
2976 Srv
:= g_Game_IsServer
;
2977 Netsrv
:= g_Game_IsServer
and g_Game_IsNet
;
2978 if Srv
then FDeath
:= FDeath
+ 1;
2983 if not FPhysics
then
2989 if (gGameSettings
.MaxLives
> 0) and Srv
and (gLMSRespawn
= LMS_RESPAWN_NONE
) then
2991 if FLives
> 0 then FLives
:= FLives
- 1;
2992 if FLives
= 0 then FNoRespawn
:= True;
2995 // Íîìåð òèïà ñìåðòè:
2998 K_SIMPLEKILL
: a
:= 1;
3000 K_EXTRAHARDKILL
: a
:= 3;
3005 if not FModel
.PlaySound(MODELSOUND_DIE
, a
, FObj
.X
, FObj
.Y
) then
3007 if FModel
.PlaySound(MODELSOUND_DIE
, i
, FObj
.X
, FObj
.Y
) then
3014 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN1
;
3016 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN2
;
3017 K_EXTRAHARDKILL
, K_FALLKILL
:
3018 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN3
;
3021 // Ïåðåêëþ÷àåì ñîñòîÿíèå:
3025 K_HARDKILL
, K_EXTRAHARDKILL
:
3029 // Ðåàêöèÿ ìîíñòðîâ íà ñìåðòü èãðîêà:
3030 if (KillType
<> K_FALLKILL
) and (Srv
) then
3031 g_Monsters_killedp();
3033 if SpawnerUID
= FUID
then
3035 if Srv
and (DoFrags
or (gGameSettings
.GameMode
= GM_TDM
)) then
3040 g_Console_Add(Format(_lc
[I_PLAYER_KILL_SELF
], [FName
]), True);
3043 if g_GetUIDType(SpawnerUID
) = UID_PLAYER
then
3044 begin // Óáèò äðóãèì èãðîêîì
3045 KP
:= g_Player_Get(SpawnerUID
);
3046 if (KP
<> nil) and Srv
then
3048 if (DoFrags
or (gGameSettings
.GameMode
= GM_TDM
)) then
3049 if SameTeam(FUID
, SpawnerUID
) then
3059 if (gGameSettings
.GameMode
= GM_TDM
) and DoFrags
then
3060 Inc(gTeamStat
[KP
.Team
].Goals
,
3061 IfThen(SameTeam(FUID
, SpawnerUID
), -1, 1));
3063 if netsrv
then MH_SEND_PlayerStats(SpawnerUID
);
3066 plr
:= g_Player_Get(SpawnerUID
);
3074 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_2
],
3078 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_1
],
3082 g_Console_Add(Format(_lc
[I_PLAYER_KILL
],
3087 else if g_GetUIDType(SpawnerUID
) = UID_MONSTER
then
3088 begin // Óáèò ìîíñòðîì
3089 mon
:= g_Monsters_Get(SpawnerUID
);
3093 s
:= g_Monsters_GetKilledBy(mon
.MonsterType
);
3097 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_2
],
3101 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_1
],
3105 g_Console_Add(Format(_lc
[I_PLAYER_KILL
],
3110 else // Îñîáûå òèïû ñìåðòè
3113 HIT_SELF
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_SELF
], [FName
]), True);
3114 HIT_FALL
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_FALL
], [FName
]), True);
3115 HIT_WATER
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_WATER
], [FName
]), True);
3116 HIT_ACID
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_ACID
], [FName
]), True);
3117 HIT_TRAP
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_TRAP
], [FName
]), True);
3118 else g_Console_Add(Format(_lc
[I_PLAYER_DIED
], [FName
]), True);
3124 for a
:= WP_FIRST
to WP_LAST
do
3128 WEAPON_SAW
: i
:= ITEM_WEAPON_SAW
;
3129 WEAPON_SHOTGUN1
: i
:= ITEM_WEAPON_SHOTGUN1
;
3130 WEAPON_SHOTGUN2
: i
:= ITEM_WEAPON_SHOTGUN2
;
3131 WEAPON_CHAINGUN
: i
:= ITEM_WEAPON_CHAINGUN
;
3132 WEAPON_ROCKETLAUNCHER
: i
:= ITEM_WEAPON_ROCKETLAUNCHER
;
3133 WEAPON_PLASMA
: i
:= ITEM_WEAPON_PLASMA
;
3134 WEAPON_BFG
: i
:= ITEM_WEAPON_BFG
;
3135 WEAPON_SUPERPULEMET
: i
:= ITEM_WEAPON_SUPERPULEMET
;
3136 WEAPON_FLAMETHROWER
: i
:= ITEM_WEAPON_FLAMETHROWER
;
3145 if R_ITEM_BACKPACK
in FRulez
then
3146 PushItem(ITEM_AMMO_BACKPACK
);
3148 // Âûáðîñ ðàêåòíîãî ðàíöà:
3149 if FJetFuel
> 0 then
3150 PushItem(ITEM_JETPACK
);
3153 if not (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
]) then
3155 if R_KEY_RED
in FRulez
then
3156 PushItem(ITEM_KEY_RED
);
3158 if R_KEY_GREEN
in FRulez
then
3159 PushItem(ITEM_KEY_GREEN
);
3161 if R_KEY_BLUE
in FRulez
then
3162 PushItem(ITEM_KEY_BLUE
);
3169 g_Player_CreateCorpse(Self
);
3171 if Srv
and (gGameSettings
.MaxLives
> 0) and FNoRespawn
and
3172 (gLMSRespawn
= LMS_RESPAWN_NONE
) then
3178 for i
:= Low(gPlayers
) to High(gPlayers
) do
3180 if gPlayers
[i
] = nil then continue
;
3181 if (not gPlayers
[i
].FNoRespawn
) and (not gPlayers
[i
].FSpectator
) then
3184 if gPlayers
[i
].FTeam
= TEAM_RED
then Inc(ar
)
3185 else if gPlayers
[i
].FTeam
= TEAM_BLUE
then Inc(ab
);
3190 OldLR
:= gLMSRespawn
;
3191 if (gGameSettings
.GameMode
= GM_COOP
) then
3195 // everyone is dead, restart the map
3196 g_Game_Message(_lc
[I_MESSAGE_LMS_LOSE
], 144);
3198 MH_SEND_GameEvent(NET_EV_LMS_LOSE
);
3199 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3200 gLMSRespawnTime
:= gTime
+ 5000;
3202 else if (a
= 1) then
3204 if (gPlayers
[k
] <> nil) and not (gPlayers
[k
] is TBot
) then
3205 if (gPlayers
[k
] = gPlayer1
) or
3206 (gPlayers
[k
] = gPlayer2
) then
3207 g_Console_Add('*** ' + _lc
[I_MESSAGE_LMS_SURVIVOR
] + ' ***', True)
3208 else if Netsrv
and (gPlayers
[k
].FClientID
>= 0) then
3209 MH_SEND_GameEvent(NET_EV_LMS_SURVIVOR
, 0, 'N', gPlayers
[k
].FClientID
);
3212 else if (gGameSettings
.GameMode
= GM_TDM
) then
3214 if (ab
= 0) and (ar
<> 0) then
3217 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 144);
3219 MH_SEND_GameEvent(NET_EV_TLMS_WIN
, TEAM_RED
);
3220 Inc(gTeamStat
[TEAM_RED
].Goals
);
3221 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3222 gLMSRespawnTime
:= gTime
+ 5000;
3224 else if (ar
= 0) and (ab
<> 0) then
3227 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 144);
3229 MH_SEND_GameEvent(NET_EV_TLMS_WIN
, TEAM_BLUE
);
3230 Inc(gTeamStat
[TEAM_BLUE
].Goals
);
3231 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3232 gLMSRespawnTime
:= gTime
+ 5000;
3234 else if (ar
= 0) and (ab
= 0) then
3237 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
3239 MH_SEND_GameEvent(NET_EV_LMS_DRAW
, 0, FName
);
3240 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3241 gLMSRespawnTime
:= gTime
+ 5000;
3244 else if (gGameSettings
.GameMode
= GM_DM
) then
3248 if gPlayers
[k
] <> nil then
3251 // survivor is the winner
3252 g_Game_Message(Format(_lc
[I_MESSAGE_LMS_WIN
], [AnsiUpperCase(FName
)]), 144);
3254 MH_SEND_GameEvent(NET_EV_LMS_WIN
, 0, FName
);
3257 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3258 gLMSRespawnTime
:= gTime
+ 5000;
3260 else if (a
= 0) then
3262 // everyone is dead, restart the map
3263 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
3265 MH_SEND_GameEvent(NET_EV_LMS_DRAW
, 0, FName
);
3266 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3267 gLMSRespawnTime
:= gTime
+ 5000;
3270 if srv
and (OldLR
= LMS_RESPAWN_NONE
) and (gLMSRespawn
> LMS_RESPAWN_NONE
) then
3272 if NetMode
= NET_SERVER
then
3273 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, (gLMSRespawnTime
- gTime
) div 1000)
3275 g_Console_Add(Format(_lc
[I_MSG_WARMUP_START
], [(gLMSRespawnTime
- gTime
) div 1000]), True);
3281 MH_SEND_PlayerStats(FUID
);
3282 MH_SEND_PlayerDeath(FUID
, KillType
, t
, SpawnerUID
);
3283 if gGameSettings
.GameMode
= GM_TDM
then MH_SEND_GameStats
;
3286 if srv
and FNoRespawn
then Spectate(True);
3287 FWantsInGame
:= True;
3290 function TPlayer
.BodyInLiquid(XInc
, YInc
: Integer): Boolean;
3292 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
, PLAYER_RECT
.Width
,
3293 PLAYER_RECT
.Height
-20, PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, False);
3296 function TPlayer
.BodyInAcid(XInc
, YInc
: Integer): Boolean;
3298 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
, PLAYER_RECT
.Width
,
3299 PLAYER_RECT
.Height
-20, PANEL_ACID1
or PANEL_ACID2
, False);
3302 procedure TPlayer
.MakeBloodSimple(Count
: Word);
3304 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)+8,
3305 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3306 Count
div 2, 3, -1, 16, (PLAYER_RECT
.Height
*2 div 3),
3308 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-8,
3309 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3310 Count
div 2, -3, -1, 16, (PLAYER_RECT
.Height
*2) div 3,
3314 procedure TPlayer
.MakeBloodVector(Count
: Word; VelX
, VelY
: Integer);
3316 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
3317 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3318 Count
, VelX
, VelY
, 16, (PLAYER_RECT
.Height
*2) div 3,
3322 procedure TPlayer
.QueueWeaponSwitch(Weapon
: Byte);
3324 if g_Game_IsClient
then Exit
;
3325 if Weapon
> High(FWeapon
) then Exit
;
3326 FNextWeap
:= FNextWeap
or (1 shl Weapon
);
3329 procedure TPlayer
.resetWeaponQueue ();
3332 FNextWeapDelay
:= 0;
3335 function TPlayer
.hasAmmoForWeapon (weapon
: Byte): Boolean;
3339 WEAPON_KASTET
, WEAPON_SAW
: result
:= true;
3340 WEAPON_SHOTGUN1
, WEAPON_SHOTGUN2
: result
:= (FAmmo
[A_SHELLS
] > 0);
3341 WEAPON_PISTOL
, WEAPON_CHAINGUN
, WEAPON_SUPERPULEMET
: result
:= (FAmmo
[A_BULLETS
] > 0);
3342 WEAPON_ROCKETLAUNCHER
: result
:= (FAmmo
[A_ROCKETS
] > 0);
3343 WEAPON_PLASMA
, WEAPON_BFG
: result
:= (FAmmo
[A_CELLS
] > 0);
3344 WEAPON_FLAMETHROWER
: result
:= (FAmmo
[A_FUEL
] > 0);
3345 else result
:= (weapon
< length(FWeapon
));
3349 // return 255 for "no switch"
3350 function TPlayer
.getNextWeaponIndex (): Byte;
3353 wantThisWeapon
: array[0..64] of Boolean;
3354 wwc
: Integer = 0; //HACK!
3357 result
:= 255; // default result: "no switch"
3358 // had weapon cycling on previous frame? remove that flag
3359 if (FNextWeap
and $2000) <> 0 then
3361 FNextWeap
:= FNextWeap
and $1FFF;
3362 FNextWeapDelay
:= 0;
3364 // cycling has priority
3365 if (FNextWeap
and $C000) <> 0 then
3367 if (FNextWeap
and $8000) <> 0 then
3371 FNextWeap
:= FNextWeap
or $2000; // we need this
3372 if FNextWeapDelay
> 0 then
3373 exit
; // cooldown time
3375 for i
:= 0 to High(FWeapon
) do
3377 cwi
:= (cwi
+length(FWeapon
)+dir
) mod length(FWeapon
);
3378 if FWeapon
[cwi
] then
3380 //e_WriteLog(Format(' SWITCH: cur=%d; new=%d', [FCurrWeap, cwi]), MSG_WARNING);
3381 result
:= Byte(cwi
);
3382 FNextWeapDelay
:= 10;
3390 for i
:= 0 to High(wantThisWeapon
) do
3391 wantThisWeapon
[i
] := false;
3392 for i
:= 0 to High(FWeapon
) do
3393 if (FNextWeap
and (1 shl i
)) <> 0 then
3395 wantThisWeapon
[i
] := true;
3398 // exclude currently selected weapon from the set
3399 wantThisWeapon
[FCurrWeap
] := false;
3400 // slow down alterations a little
3403 //e_WriteLog(Format(' FNextWeap=%x; delay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
3404 // more than one weapon requested, assume "alteration" and check alteration delay
3405 if FNextWeapDelay
> 0 then
3411 // do not reset weapon queue, it will be done in `RealizeCurrentWeapon()`
3412 // but clear all counters if no weapon should be switched
3418 //e_WriteLog(Format('wwc=%d', [wwc]), MSG_WARNING);
3419 // try weapons in descending order
3420 for i
:= High(FWeapon
) downto 0 do
3422 if wantThisWeapon
[i
] and FWeapon
[i
] and ((wwc
= 1) or hasAmmoForWeapon(i
)) then
3427 FNextWeapDelay
:= 10; // anyway, 'cause why not
3431 // no suitable weapon found, so reset the queue, to avoid accidental "queuing" of weapon w/o ammo
3435 procedure TPlayer
.RealizeCurrentWeapon();
3436 function switchAllowed (): Boolean;
3441 if FBFGFireCounter
<> -1 then
3443 if FTime
[T_SWITCH
] > gTime
then
3445 for i
:= WP_FIRST
to WP_LAST
do
3446 if FReloading
[i
] > 0 then
3454 //e_WriteLog(Format('***RealizeCurrentWeapon: FNextWeap=%x; FNextWeapDelay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
3455 //FNextWeap := FNextWeap and $1FFF;
3456 if FNextWeapDelay
> 0 then Dec(FNextWeapDelay
); // "alteration delay"
3458 if not switchAllowed
then
3460 //HACK for weapon cycling
3461 if (FNextWeap
and $7000) <> 0 then FNextWeap
:= 0;
3465 nw
:= getNextWeaponIndex();
3466 if nw
= 255 then exit
; // don't reset anything here
3467 if nw
> High(FWeapon
) then
3469 // don't forget to reset queue here!
3470 //e_WriteLog(' RealizeCurrentWeapon: WUTAFUUUU', MSG_WARNING);
3478 FTime
[T_SWITCH
] := gTime
+156;
3479 if FCurrWeap
= WEAPON_SAW
then FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3480 FModel
.SetWeapon(FCurrWeap
);
3481 if g_Game_IsNet
then MH_SEND_PlayerStats(FUID
);
3485 procedure TPlayer
.NextWeapon();
3487 if g_Game_IsClient
then Exit
;
3491 procedure TPlayer
.PrevWeapon();
3493 if g_Game_IsClient
then Exit
;
3497 procedure TPlayer
.SetWeapon(W
: Byte);
3499 if FCurrWeap
<> W
then
3500 if W
= WEAPON_SAW
then
3501 FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3504 FModel
.SetWeapon(CurrWeap
);
3508 function TPlayer
.PickItem(ItemType
: Byte; respawn
: Boolean; var remove
: Boolean): Boolean;
3513 if g_Game_IsClient
then Exit
;
3515 // a = true - ìåñòî ñïàâíà ïðåäìåòà:
3516 a
:= LongBool(gGameSettings
.Options
and GAME_OPTION_WEAPONSTAY
) and respawn
;
3521 if FHealth
< PLAYER_HP_SOFT
then
3523 IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
3527 if gFlash
= 2 then Inc(FPickup
, 5);
3531 if FHealth
< PLAYER_HP_SOFT
then
3533 IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
3537 if gFlash
= 2 then Inc(FPickup
, 5);
3541 if FArmor
< PLAYER_AP_SOFT
then
3543 FArmor
:= PLAYER_AP_SOFT
;
3546 if gFlash
= 2 then Inc(FPickup
, 5);
3550 if FArmor
< PLAYER_AP_LIMIT
then
3552 FArmor
:= PLAYER_AP_LIMIT
;
3555 if gFlash
= 2 then Inc(FPickup
, 5);
3559 if FHealth
< PLAYER_HP_LIMIT
then
3561 IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
3565 if gFlash
= 2 then Inc(FPickup
, 5);
3569 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) then
3571 if FHealth
< PLAYER_HP_LIMIT
then
3572 FHealth
:= PLAYER_HP_LIMIT
;
3573 if FArmor
< PLAYER_AP_LIMIT
then
3574 FArmor
:= PLAYER_AP_LIMIT
;
3578 if gFlash
= 2 then Inc(FPickup
, 5);
3582 if (not FWeapon
[WEAPON_SAW
]) or ((not respawn
) and (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
])) then
3584 FWeapon
[WEAPON_SAW
] := 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');
3590 ITEM_WEAPON_SHOTGUN1
:
3591 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN1
] then
3593 // Íóæíî, ÷òîáû íå âçÿòü âñå ïóëè ñðàçó:
3594 if a
and FWeapon
[WEAPON_SHOTGUN1
] then Exit
;
3596 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3597 FWeapon
[WEAPON_SHOTGUN1
] := True;
3599 if gFlash
= 2 then Inc(FPickup
, 5);
3600 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3603 ITEM_WEAPON_SHOTGUN2
:
3604 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN2
] then
3606 if a
and FWeapon
[WEAPON_SHOTGUN2
] then Exit
;
3608 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3609 FWeapon
[WEAPON_SHOTGUN2
] := True;
3611 if gFlash
= 2 then Inc(FPickup
, 5);
3612 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3615 ITEM_WEAPON_CHAINGUN
:
3616 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or not FWeapon
[WEAPON_CHAINGUN
] then
3618 if a
and FWeapon
[WEAPON_CHAINGUN
] then Exit
;
3620 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
3621 FWeapon
[WEAPON_CHAINGUN
] := True;
3623 if gFlash
= 2 then Inc(FPickup
, 5);
3624 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3627 ITEM_WEAPON_ROCKETLAUNCHER
:
3628 if (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or not FWeapon
[WEAPON_ROCKETLAUNCHER
] then
3630 if a
and FWeapon
[WEAPON_ROCKETLAUNCHER
] then Exit
;
3632 IncMax(FAmmo
[A_ROCKETS
], 2, FMaxAmmo
[A_ROCKETS
]);
3633 FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
3635 if gFlash
= 2 then Inc(FPickup
, 5);
3636 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3640 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_PLASMA
] then
3642 if a
and FWeapon
[WEAPON_PLASMA
] then Exit
;
3644 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3645 FWeapon
[WEAPON_PLASMA
] := True;
3647 if gFlash
= 2 then Inc(FPickup
, 5);
3648 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3652 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_BFG
] then
3654 if a
and FWeapon
[WEAPON_BFG
] then Exit
;
3656 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3657 FWeapon
[WEAPON_BFG
] := True;
3659 if gFlash
= 2 then Inc(FPickup
, 5);
3660 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3663 ITEM_WEAPON_SUPERPULEMET
:
3664 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SUPERPULEMET
] then
3666 if a
and FWeapon
[WEAPON_SUPERPULEMET
] then Exit
;
3668 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3669 FWeapon
[WEAPON_SUPERPULEMET
] := True;
3671 if gFlash
= 2 then Inc(FPickup
, 5);
3672 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3675 ITEM_WEAPON_FLAMETHROWER
:
3676 if (FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
]) or not FWeapon
[WEAPON_FLAMETHROWER
] then
3678 if a
and FWeapon
[WEAPON_FLAMETHROWER
] then Exit
;
3680 IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
3681 FWeapon
[WEAPON_FLAMETHROWER
] := True;
3683 if gFlash
= 2 then Inc(FPickup
, 5);
3684 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3688 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
3690 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
3693 if gFlash
= 2 then Inc(FPickup
, 5);
3696 ITEM_AMMO_BULLETS_BOX
:
3697 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
3699 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
3702 if gFlash
= 2 then Inc(FPickup
, 5);
3706 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
3708 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3711 if gFlash
= 2 then Inc(FPickup
, 5);
3714 ITEM_AMMO_SHELLS_BOX
:
3715 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
3717 IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
3720 if gFlash
= 2 then Inc(FPickup
, 5);
3724 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
3726 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
3729 if gFlash
= 2 then Inc(FPickup
, 5);
3732 ITEM_AMMO_ROCKET_BOX
:
3733 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
3735 IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
3738 if gFlash
= 2 then Inc(FPickup
, 5);
3742 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
3744 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3747 if gFlash
= 2 then Inc(FPickup
, 5);
3751 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
3753 IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
3756 if gFlash
= 2 then Inc(FPickup
, 5);
3760 if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then
3762 IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
3765 if gFlash
= 2 then Inc(FPickup
, 5);
3769 if not(R_ITEM_BACKPACK
in FRulez
) or
3770 (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
3771 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
3772 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
3773 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or
3774 (FMaxAmmo
[A_FUEL
] < AmmoLimits
[1, A_FUEL
]) then
3776 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[1, A_BULLETS
];
3777 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[1, A_SHELLS
];
3778 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[1, A_ROCKETS
];
3779 FMaxAmmo
[A_CELLS
] := AmmoLimits
[1, A_CELLS
];
3780 FMaxAmmo
[A_FUEL
] := AmmoLimits
[1, A_FUEL
];
3782 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
3783 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
3784 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
3785 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3786 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
3787 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
3788 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
3789 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3791 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
3794 if gFlash
= 2 then Inc(FPickup
, 5);
3798 if not(R_KEY_RED
in FRulez
) then
3800 Include(FRulez
, R_KEY_RED
);
3802 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
3803 if gFlash
= 2 then Inc(FPickup
, 5);
3804 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
3808 if not(R_KEY_GREEN
in FRulez
) then
3810 Include(FRulez
, R_KEY_GREEN
);
3812 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
3813 if gFlash
= 2 then Inc(FPickup
, 5);
3814 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
3818 if not(R_KEY_BLUE
in FRulez
) then
3820 Include(FRulez
, R_KEY_BLUE
);
3822 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
3823 if gFlash
= 2 then Inc(FPickup
, 5);
3824 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
3828 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
3830 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
3834 if gFlash
= 2 then Inc(FPickup
, 5);
3838 if FAir
< AIR_MAX
then
3843 if gFlash
= 2 then Inc(FPickup
, 5);
3848 if not (R_BERSERK
in FRulez
) then
3850 Include(FRulez
, R_BERSERK
);
3851 if FBFGFireCounter
= -1 then
3853 FCurrWeap
:= WEAPON_KASTET
;
3855 FModel
.SetWeapon(WEAPON_KASTET
);
3859 if gFlash
= 2 then Inc(FPickup
, 5);
3860 FBerserk
:= gTime
+30000;
3865 if FHealth
< PLAYER_HP_SOFT
then
3867 FHealth
:= PLAYER_HP_SOFT
;
3868 FBerserk
:= gTime
+30000;
3876 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
3878 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
3881 if gFlash
= 2 then Inc(FPickup
, 5);
3885 if FHealth
< PLAYER_HP_LIMIT
then
3887 IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
3891 if gFlash
= 2 then Inc(FPickup
, 5);
3895 if FArmor
< PLAYER_AP_LIMIT
then
3897 IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
3900 if gFlash
= 2 then Inc(FPickup
, 5);
3904 if FJetFuel
< JET_MAX
then
3906 FJetFuel
:= JET_MAX
;
3909 if gFlash
= 2 then Inc(FPickup
, 5);
3913 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
3915 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
3918 if gFlash
= 2 then Inc(FPickup
, 5);
3923 procedure TPlayer
.Touch();
3927 //FModel.PlaySound(MODELSOUND_PAIN, 1, FObj.X, FObj.Y);
3930 // Áðîñèòü ôëàã òîâàðèùó:
3931 if gGameSettings
.GameMode
= GM_CTF
then
3936 procedure TPlayer
.Push(vx
, vy
: Integer);
3938 if (not FPhysics
) and FGhost
then
3940 FObj
.Accel
.X
:= FObj
.Accel
.X
+ vx
;
3941 FObj
.Accel
.Y
:= FObj
.Accel
.Y
+ vy
;
3942 if g_Game_IsNet
and g_Game_IsServer
then
3943 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
3946 procedure TPlayer
.Reset(Force
: Boolean);
3952 FTime
[T_RESPAWN
] := 0;
3953 FTime
[T_FLAGCAP
] := 0;
3966 FSpectator
:= False;
3969 FSpectatePlayer
:= -1;
3970 FNoRespawn
:= False;
3972 FLives
:= gGameSettings
.MaxLives
;
3977 procedure TPlayer
.SoftReset();
3983 FBFGFireCounter
:= -1;
3991 SetAction(A_STAND
, True);
3994 function TPlayer
.GetRespawnPoint(): Byte;
3999 // Íà áóäóùåå: FSpawn - èãðîê óæå èãðàë è ïåðåðîæäàåòñÿ
4001 // Îäèíî÷íàÿ èãðà/êîîïåðàòèâ
4002 if gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
] then
4004 if (Self
= gPlayer1
) or (Self
= gPlayer2
) then
4006 // Òî÷êà ïîÿâëåíèÿ ñâîåãî èãðîêà
4007 if Self
= gPlayer1
then
4008 c
:= RESPAWNPOINT_PLAYER1
4010 c
:= RESPAWNPOINT_PLAYER2
;
4011 if g_Map_GetPointCount(c
) > 0 then
4017 // Òî÷êà ïîÿâëåíèÿ äðóãîãî èãðîêà
4018 if Self
= gPlayer1
then
4019 c
:= RESPAWNPOINT_PLAYER2
4021 c
:= RESPAWNPOINT_PLAYER1
;
4022 if g_Map_GetPointCount(c
) > 0 then
4029 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà (áîòà)
4030 if Random(2) = 0 then
4031 c
:= RESPAWNPOINT_PLAYER1
4033 c
:= RESPAWNPOINT_PLAYER2
;
4034 if g_Map_GetPointCount(c
) > 0 then
4041 // Òî÷êà ëþáîé èç êîìàíä
4042 if Random(2) = 0 then
4043 c
:= RESPAWNPOINT_RED
4045 c
:= RESPAWNPOINT_BLUE
;
4046 if g_Map_GetPointCount(c
) > 0 then
4053 c
:= RESPAWNPOINT_DM
;
4054 if g_Map_GetPointCount(c
) > 0 then
4062 if gGameSettings
.GameMode
= GM_DM
then
4065 c
:= RESPAWNPOINT_DM
;
4066 if g_Map_GetPointCount(c
) > 0 then
4072 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà
4073 if Random(2) = 0 then
4074 c
:= RESPAWNPOINT_PLAYER1
4076 c
:= RESPAWNPOINT_PLAYER2
;
4077 if g_Map_GetPointCount(c
) > 0 then
4083 // Òî÷êà ëþáîé èç êîìàíä
4084 if Random(2) = 0 then
4085 c
:= RESPAWNPOINT_RED
4087 c
:= RESPAWNPOINT_BLUE
;
4088 if g_Map_GetPointCount(c
) > 0 then
4096 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
4098 // Òî÷êà ñâîåé êîìàíäû
4099 c
:= RESPAWNPOINT_DM
;
4100 if FTeam
= TEAM_RED
then
4101 c
:= RESPAWNPOINT_RED
;
4102 if FTeam
= TEAM_BLUE
then
4103 c
:= RESPAWNPOINT_BLUE
;
4104 if g_Map_GetPointCount(c
) > 0 then
4111 c
:= RESPAWNPOINT_DM
;
4112 if g_Map_GetPointCount(c
) > 0 then
4118 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà
4119 if Random(2) = 0 then
4120 c
:= RESPAWNPOINT_PLAYER1
4122 c
:= RESPAWNPOINT_PLAYER2
;
4123 if g_Map_GetPointCount(c
) > 0 then
4129 // Òî÷êà äðóãîé êîìàíäû
4130 c
:= RESPAWNPOINT_DM
;
4131 if FTeam
= TEAM_RED
then
4132 c
:= RESPAWNPOINT_BLUE
;
4133 if FTeam
= TEAM_BLUE
then
4134 c
:= RESPAWNPOINT_RED
;
4135 if g_Map_GetPointCount(c
) > 0 then
4143 procedure TPlayer
.Respawn(Silent
: Boolean; Force
: Boolean = False);
4145 RespawnPoint
: TRespawnPoint
;
4150 if not g_Game_IsServer
then
4154 FWantsInGame
:= True;
4155 FJustTeleported
:= True;
4158 FTime
[T_RESPAWN
] := 0;
4162 // if server changes MaxLives we gotta be ready
4163 if gGameSettings
.MaxLives
= 0 then FNoRespawn
:= False;
4165 // Åùå íåëüçÿ âîçðîäèòüñÿ:
4166 if FTime
[T_RESPAWN
] > gTime
then
4169 // Ïðîñðàë âñå æèçíè:
4172 if not FSpectator
then Spectate(True);
4173 FWantsInGame
:= True;
4177 if (gGameSettings
.GameType
<> GT_SINGLE
) and (gGameSettings
.GameMode
<> GM_COOP
) then
4178 begin // "Ñâîÿ èãðà"
4179 // Áåðñåðê íå ñîõðàíÿåòñÿ ìåæäó óðîâíÿìè:
4180 FRulez
:= FRulez
-[R_BERSERK
];
4182 else // "Îäèíî÷íàÿ èãðà"/"Êîîï"
4184 // Áåðñåðê è êëþ÷è íå ñîõðàíÿþòñÿ ìåæäó óðîâíÿìè:
4185 FRulez
:= FRulez
-[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
, R_BERSERK
];
4188 // Ïîëó÷àåì òî÷êó ñïàóíà èãðîêà:
4189 c
:= GetRespawnPoint();
4194 // Âîñêðåøåíèå áåç îðóæèÿ:
4197 FHealth
:= PLAYER_HP_SOFT
;
4203 for a
:= WP_FIRST
to WP_LAST
do
4205 FWeapon
[a
] := False;
4209 FWeapon
[WEAPON_PISTOL
] := True;
4210 FWeapon
[WEAPON_KASTET
] := True;
4211 FCurrWeap
:= WEAPON_PISTOL
;
4214 FModel
.SetWeapon(FCurrWeap
);
4216 for b
:= A_BULLETS
to A_HIGH
do
4219 FAmmo
[A_BULLETS
] := 50;
4221 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[0, A_BULLETS
];
4222 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[0, A_SHELLS
];
4223 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[0, A_SHELLS
];
4224 FMaxAmmo
[A_CELLS
] := AmmoLimits
[0, A_CELLS
];
4225 FMaxAmmo
[A_FUEL
] := AmmoLimits
[0, A_FUEL
];
4227 if gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
] then
4228 FRulez
:= [R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
]
4233 // Ïîëó÷àåì êîîðäèíàòû òî÷êè âîçðîæäåíèÿ:
4234 if not g_Map_GetPoint(c
, RespawnPoint
) then
4236 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
4240 // Óñòàíîâêà êîîðäèíàò è ñáðîñ âñåõ ïàðàìåòðîâ:
4241 FObj
.X
:= RespawnPoint
.X
-PLAYER_RECT
.X
;
4242 FObj
.Y
:= RespawnPoint
.Y
-PLAYER_RECT
.Y
;
4248 FDirection
:= RespawnPoint
.Direction
;
4249 if FDirection
= D_LEFT
then
4255 FBFGFireCounter
:= -1;
4260 SetAction(A_STAND
, True);
4261 FModel
.Direction
:= FDirection
;
4263 for a
:= Low(FTime
) to High(FTime
) do
4266 for a
:= Low(FMegaRulez
) to High(FMegaRulez
) do
4271 FCanJetpack
:= False;
4276 // Àíèìàöèÿ âîçðîæäåíèÿ:
4277 if (not gLoadGameMode
) and (not Silent
) then
4278 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
4280 Anim
:= TAnimation
.Create(ID
, False, 3);
4281 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4282 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4286 FSpectator
:= False;
4289 FSpectatePlayer
:= -1;
4292 if g_Game_IsNet
then
4294 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
4295 MH_SEND_PlayerStats(FUID
, NET_EVERYONE
);
4297 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4298 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32,
4303 procedure TPlayer
.Spectate(NoMove
: Boolean = False);
4306 Kill(K_EXTRAHARDKILL
, FUID
, HIT_SOME
)
4307 else if (not NoMove
) then
4309 GameX
:= gMapInfo
.Width
div 2;
4310 GameY
:= gMapInfo
.Height
div 2;
4319 FWantsInGame
:= False;
4324 if Self
= gPlayer1
then
4329 if Self
= gPlayer2
then
4336 if g_Game_IsNet
then
4337 MH_SEND_PlayerStats(FUID
);
4340 procedure TPlayer
.SwitchNoClip
;
4344 FGhost
:= not FGhost
;
4345 FPhysics
:= not FGhost
;
4357 procedure TPlayer
.Run(Direction
: TDirection
);
4361 if MAX_RUNVEL
> 8 then
4365 if Direction
= D_LEFT
then
4367 if FObj
.Vel
.X
> -MAX_RUNVEL
then
4368 FObj
.Vel
.X
:= FObj
.Vel
.X
- (MAX_RUNVEL
shr 3);
4371 if FObj
.Vel
.X
< MAX_RUNVEL
then
4372 FObj
.Vel
.X
:= FObj
.Vel
.X
+ (MAX_RUNVEL
shr 3);
4374 // Âîçìîæíî, ïèíàåì êóñêè:
4375 if (FObj
.Vel
.X
<> 0) and (gGibs
<> nil) then
4377 b
:= Abs(FObj
.Vel
.X
);
4378 if b
> 1 then b
:= b
* (Random(8 div b
) + 1);
4379 for a
:= 0 to High(gGibs
) do
4380 if gGibs
[a
].Live
and
4381 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
+FObj
.Rect
.Height
-4,
4382 FObj
.Rect
.Width
, 8, @gGibs
[a
].Obj
) and (Random(3) = 0) then
4384 if FObj
.Vel
.X
< 0 then
4385 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)+120) // íàëåâî
4387 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)); // íàïðàâî
4393 procedure TPlayer
.SeeDown();
4395 SetAction(A_SEEDOWN
);
4397 if FDirection
= D_LEFT
then FAngle
:= ANGLE_LEFTDOWN
else FAngle
:= ANGLE_RIGHTDOWN
;
4399 if FIncCam
> -120 then DecMin(FIncCam
, 5, -120);
4402 procedure TPlayer
.SeeUp();
4406 if FDirection
= D_LEFT
then FAngle
:= ANGLE_LEFTUP
else FAngle
:= ANGLE_RIGHTUP
;
4408 if FIncCam
< 120 then IncMax(FIncCam
, 5, 120);
4411 procedure TPlayer
.SetAction(Action
: Byte; Force
: Boolean = False);
4419 A_ATTACK
: Prior
:= 2;
4420 A_SEEUP
: Prior
:= 1;
4421 A_SEEDOWN
: Prior
:= 1;
4422 A_ATTACKUP
: Prior
:= 2;
4423 A_ATTACKDOWN
: Prior
:= 2;
4428 if (Prior
> FActionPrior
) or Force
then
4429 if not ((Prior
= 2) and (FCurrWeap
= WEAPON_SAW
)) then
4431 FActionPrior
:= Prior
;
4432 FActionAnim
:= Action
;
4433 FActionForce
:= Force
;
4434 FActionChanged
:= True;
4437 if Action
in [A_ATTACK
, A_ATTACKUP
, A_ATTACKDOWN
] then FModel
.SetFire(True);
4440 function TPlayer
.StayOnStep(XInc
, YInc
: Integer): Boolean;
4442 Result
:= not g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
-1,
4443 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False)
4444 and g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
,
4445 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False);
4448 function TPlayer
.TeleportTo(X
, Y
: Integer; silent
: Boolean; dir
: Byte): Boolean;
4455 if g_CollideLevel(X
, Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
) then
4457 g_Sound_PlayExAt('SOUND_GAME_NOTELEPORT', FObj
.X
, FObj
.Y
);
4458 if g_Game_IsServer
and g_Game_IsNet
then
4459 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_GAME_NOTELEPORT');
4463 FJustTeleported
:= True;
4468 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
4470 Anim
:= TAnimation
.Create(ID
, False, 3);
4473 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', FObj
.X
, FObj
.Y
);
4474 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4475 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4476 if g_Game_IsServer
and g_Game_IsNet
then
4477 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4478 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 1,
4482 FObj
.X
:= X
-PLAYER_RECT
.X
;
4483 FObj
.Y
:= Y
-PLAYER_RECT
.Y
;
4484 if FLive
and FGhost
then
4490 if not g_Game_IsNet
then
4494 SetDirection(D_LEFT
);
4500 SetDirection(D_RIGHT
);
4506 if FDirection
= D_RIGHT
then
4508 SetDirection(D_LEFT
);
4513 SetDirection(D_RIGHT
);
4519 if not silent
and (Anim
<> nil) then
4521 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4522 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4525 if g_Game_IsServer
and g_Game_IsNet
then
4526 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4527 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 0,
4534 function nonz(a
: Single): Single;
4542 procedure TPlayer
.Update();
4545 i
, ii
, wx
, wy
, xd
, yd
, k
: Integer;
4546 blockmon
, headwater
, dospawn
: Boolean;
4551 NetServer
:= g_Game_IsNet
and g_Game_IsServer
;
4552 AnyServer
:= g_Game_IsServer
;
4554 if g_Game_IsClient
and (NetInterpLevel
> 0) then
4555 DoLerp(NetInterpLevel
+ 1)
4561 if FClientID
>= 0 then
4563 FPing
:= NetClients
[FClientID
].Peer
^.lastRoundTripTime
;
4564 if NetClients
[FClientID
].Peer
^.packetsSent
> 0 then
4565 FLoss
:= Round(100*NetClients
[FClientID
].Peer
^.packetsLost
/NetClients
[FClientID
].Peer
^.packetsSent
)
4574 if FLive
and (gFly
or FJetpack
) then
4577 if FDirection
= D_LEFT
then
4582 if FLive
and (not FGhost
) then
4584 if FKeys
[KEY_UP
].Pressed
then
4586 if FKeys
[KEY_DOWN
].Pressed
then
4590 if (not (FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_DOWN
].Pressed
)) and
4593 i
:= g_basic
.Sign(FIncCam
);
4594 FIncCam
:= Abs(FIncCam
);
4595 DecMin(FIncCam
, 5, 0);
4596 FIncCam
:= FIncCam
*i
;
4599 // no need to do that each second frame, weapon queue will take care of it
4600 if FLive
and FKeys
[KEY_NEXTWEAPON
].Pressed
and AnyServer
then NextWeapon();
4601 if FLive
and FKeys
[KEY_PREVWEAPON
].Pressed
and AnyServer
then PrevWeapon();
4603 if gTime
mod (GAME_TICK
*2) <> 0 then
4605 if (FObj
.Vel
.X
= 0) and FLive
then
4607 if FKeys
[KEY_LEFT
].Pressed
then
4609 if FKeys
[KEY_RIGHT
].Pressed
then
4614 g_Obj_Move(@FObj
, True, True, True);
4619 FActionChanged
:= False;
4623 // Let alive player do some actions
4624 if FKeys
[KEY_LEFT
].Pressed
then Run(D_LEFT
);
4625 if FKeys
[KEY_RIGHT
].Pressed
then Run(D_RIGHT
);
4626 //if FKeys[KEY_NEXTWEAPON].Pressed and AnyServer then NextWeapon();
4627 //if FKeys[KEY_PREVWEAPON].Pressed and AnyServer then PrevWeapon();
4628 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then Fire();
4629 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Use();
4630 if FKeys
[KEY_JUMP
].Pressed
then Jump()
4633 if AnyServer
and FJetpack
then
4637 if NetServer
then MH_SEND_PlayerStats(FUID
);
4639 FCanJetpack
:= True;
4646 for k
:= Low(FKeys
) to KEY_CHAT
-1 do
4648 if FKeys
[k
].Pressed
then
4656 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
4659 if (FTime
[T_RESPAWN
] <= gTime
) and
4660 gGameOn
and (not FLive
) then
4662 if (g_Player_GetCount() > 1) then
4666 gExit
:= EXIT_RESTART
;
4671 // Dead spectator actions
4674 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Fire();
4675 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then
4679 if (FSpectatePlayer
>= High(gPlayers
)) then
4680 FSpectatePlayer
:= -1
4684 for I
:= FSpectatePlayer
+ 1 to High(gPlayers
) do
4685 if gPlayers
[I
] <> nil then
4686 if gPlayers
[I
].Live
then
4687 if gPlayers
[I
].UID
<> FUID
then
4689 FSpectatePlayer
:= I
;
4694 if not SetSpect
then FSpectatePlayer
:= -1;
4705 if FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_JUMP
].Pressed
then
4707 FYTo
:= FObj
.Y
- 32;
4708 FSpectatePlayer
:= -1;
4710 if FKeys
[KEY_DOWN
].Pressed
then
4712 FYTo
:= FObj
.Y
+ 32;
4713 FSpectatePlayer
:= -1;
4715 if FKeys
[KEY_LEFT
].Pressed
then
4717 FXTo
:= FObj
.X
- 32;
4718 FSpectatePlayer
:= -1;
4720 if FKeys
[KEY_RIGHT
].Pressed
then
4722 FXTo
:= FObj
.X
+ 32;
4723 FSpectatePlayer
:= -1;
4726 if (FXTo
< -64) then
4728 else if (FXTo
> gMapInfo
.Width
+ 32) then
4729 FXTo
:= gMapInfo
.Width
+ 32;
4730 if (FYTo
< -72) then
4732 else if (FYTo
> gMapInfo
.Height
+ 32) then
4733 FYTo
:= gMapInfo
.Height
+ 32;
4737 g_Obj_Move(@FObj
, True, True, True)
4743 if (FSpectatePlayer
<= High(gPlayers
)) and (FSpectatePlayer
>= 0) then
4744 if gPlayers
[FSpectatePlayer
] <> nil then
4745 if gPlayers
[FSpectatePlayer
].Live
then
4747 FXTo
:= gPlayers
[FSpectatePlayer
].GameX
;
4748 FYTo
:= gPlayers
[FSpectatePlayer
].GameY
;
4752 blockmon
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
, FObj
.Y
+PLAYER_HEADRECT
.Y
,
4753 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
4754 PANEL_BLOCKMON
, True);
4755 headwater
:= HeadInLiquid(0, 0);
4757 // Ñîïðîòèâëåíèå âîçäóõà:
4758 if (not FLive
) or not (FKeys
[KEY_LEFT
].Pressed
or FKeys
[KEY_RIGHT
].Pressed
) then
4759 if FObj
.Vel
.X
<> 0 then
4760 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
4762 if (FLastHit
= HIT_TRAP
) and (FPain
> 90) then FPain
:= 90;
4763 DecMin(FPain
, 5, 0);
4764 DecMin(FPickup
, 1, 0);
4766 if FLive
and (FObj
.Y
> gMapInfo
.Height
+128) and AnyServer
then
4768 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
4769 FMegaRulez
[MR_SUIT
] := 0;
4770 FMegaRulez
[MR_INVUL
] := 0;
4771 FMegaRulez
[MR_INVIS
] := 0;
4772 Kill(K_FALLKILL
, 0, HIT_FALL
);
4779 if FCurrWeap
= WEAPON_SAW
then
4780 if not (FSawSound
.IsPlaying() or FSawSoundHit
.IsPlaying() or
4781 FSawSoundSelect
.IsPlaying()) then
4782 FSawSoundIdle
.PlayAt(FObj
.X
, FObj
.Y
);
4785 if (not FJetSoundFly
.IsPlaying()) and (not FJetSoundOn
.IsPlaying()) and
4786 (not FJetSoundOff
.IsPlaying()) then
4788 FJetSoundFly
.SetPosition(0);
4789 FJetSoundFly
.PlayAt(FObj
.X
, FObj
.Y
);
4792 for b
:= WP_FIRST
to WP_LAST
do
4793 if FReloading
[b
] > 0 then
4799 if FShellTimer
> -1 then
4800 if FShellTimer
= 0 then
4802 if FShellType
= SHELL_SHELL
then
4803 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
4804 GameVelX
, GameVelY
-2, SHELL_SHELL
)
4805 else if FShellType
= SHELL_DBLSHELL
then
4807 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
4808 GameVelX
+1, GameVelY
-2, SHELL_SHELL
);
4809 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
4810 GameVelX
-1, GameVelY
-2, SHELL_SHELL
);
4813 end else Dec(FShellTimer
);
4815 if (FBFGFireCounter
> -1) then
4816 if FBFGFireCounter
= 0 then
4820 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
4821 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
4822 xd
:= wx
+IfThen(FDirection
= D_LEFT
, -30, 30);
4823 yd
:= wy
+firediry();
4824 g_Weapon_bfgshot(wx
, wy
, xd
, yd
, FUID
);
4825 if NetServer
then MH_SEND_PlayerFire(FUID
, WEAPON_BFG
, wx
, wy
, xd
, yd
);
4826 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
4827 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
4828 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
4831 FReloading
[WEAPON_BFG
] := WEAPON_RELOAD
[WEAPON_BFG
];
4832 FBFGFireCounter
:= -1;
4835 FBFGFireCounter
:= 0
4837 Dec(FBFGFireCounter
);
4839 if (FMegaRulez
[MR_SUIT
] < gTime
) and AnyServer
then
4841 b
:= g_GetAcidHit(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
);
4843 if (b
> 0) and (gTime
mod (15*GAME_TICK
) = 0) then Damage(b
, 0, 0, 0, HIT_ACID
);
4846 if (headwater
or blockmon
) then
4852 if AnyServer
then Damage(10, 0, 0, 0, HIT_WATER
);
4855 else if (FAir
mod 31 = 0) and not blockmon
then
4857 g_GFX_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2), FObj
.Y
+PLAYER_RECT
.Y
-4, 5+Random(6), 8, 4);
4858 if Random(2) = 0 then
4859 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
4861 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
4863 end else if FAir
< AIR_DEF
then
4866 if FFireTime
> 0 then
4868 if BodyInLiquid(0, 0) then
4873 else if FMegaRulez
[MR_SUIT
] >= gTime
then
4875 if FMegaRulez
[MR_SUIT
] = gTime
then
4882 if FFirePainTime
<= 0 then
4884 if g_Game_IsServer
then
4885 Damage(5, FFireAttacker
, 0, 0, HIT_FLAME
);
4886 FFirePainTime
:= 18;
4888 FFirePainTime
:= FFirePainTime
- 1;
4889 FFireTime
:= FFireTime
- 1;
4890 if (FFireTime
= 0) and g_Game_IsNet
and g_Game_IsServer
then
4891 MH_SEND_PlayerStats(FUID
);
4895 if FDamageBuffer
> 0 then
4897 if FDamageBuffer
>= 9 then
4901 if FDamageBuffer
< 30 then i
:= 9
4902 else if FDamageBuffer
< 100 then i
:= 18
4906 ii
:= Round(FDamageBuffer
*FHealth
/ nonz(FArmor
*(3/4)+FHealth
));
4907 FArmor
:= FArmor
-(FDamageBuffer
-ii
);
4908 FHealth
:= FHealth
-ii
;
4911 FHealth
:= FHealth
+FArmor
;
4916 if FHealth
<= 0 then
4917 if FHealth
> -30 then Kill(K_SIMPLEKILL
, FLastSpawnerUID
, FLastHit
)
4918 else if FHealth
> -50 then Kill(K_HARDKILL
, FLastSpawnerUID
, FLastHit
)
4919 else Kill(K_EXTRAHARDKILL
, FLastSpawnerUID
, FLastHit
);
4923 if FDamageBuffer
<= 20 then FModel
.PlaySound(MODELSOUND_PAIN
, 1, FObj
.X
, FObj
.Y
)
4924 else if FDamageBuffer
<= 55 then FModel
.PlaySound(MODELSOUND_PAIN
, 2, FObj
.X
, FObj
.Y
)
4925 else if FDamageBuffer
<= 120 then FModel
.PlaySound(MODELSOUND_PAIN
, 3, FObj
.X
, FObj
.Y
)
4926 else FModel
.PlaySound(MODELSOUND_PAIN
, 4, FObj
.X
, FObj
.Y
);
4933 end; // if FLive then ...
4935 if (FActionAnim
= A_PAIN
) and (FModel
.Animation
<> A_PAIN
) then
4937 FModel
.ChangeAnimation(FActionAnim
, FActionForce
);
4938 FModel
.GetCurrentAnimation
.MinLength
:= i
;
4939 FModel
.GetCurrentAnimationMask
.MinLength
:= i
;
4940 end else FModel
.ChangeAnimation(FActionAnim
, FActionForce
and (FModel
.Animation
<> A_STAND
));
4942 if (FModel
.GetCurrentAnimation
.Played
or ((not FActionChanged
) and (FModel
.Animation
= A_WALK
)))
4943 then SetAction(A_STAND
, True);
4945 if not ((FModel
.Animation
= A_WALK
) and (Abs(FObj
.Vel
.X
) < 4) and not FModel
.Fire
) then FModel
.Update
;
4947 for b
:= Low(FKeys
) to High(FKeys
) do
4948 if FKeys
[b
].Time
= 0 then FKeys
[b
].Pressed
:= False else Dec(FKeys
[b
].Time
);
4951 function TPlayer
.Collide(X
, Y
: Integer; Width
, Height
: Word): Boolean;
4953 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
4954 FObj
.Y
+PLAYER_RECT
.Y
,
4961 function TPlayer
.Collide(Panel
: TPanel
): Boolean;
4963 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
4964 FObj
.Y
+PLAYER_RECT
.Y
,
4968 Panel
.Width
, Panel
.Height
);
4971 function TPlayer
.Collide(X
, Y
: Integer): Boolean;
4973 X
:= X
-FObj
.X
-PLAYER_RECT
.X
;
4974 Y
:= Y
-FObj
.Y
-PLAYER_RECT
.Y
;
4975 Result
:= (x
>= 0) and (x
<= PLAYER_RECT
.Width
) and
4976 (y
>= 0) and (y
<= PLAYER_RECT
.Height
);
4979 function g_Player_ValidName(Name
: string): Boolean;
4985 if gPlayers
= nil then Exit
;
4987 for a
:= 0 to High(gPlayers
) do
4988 if gPlayers
[a
] <> nil then
4989 if LowerCase(Name
) = LowerCase(gPlayers
[a
].FName
) then
4996 procedure TPlayer
.SetDirection(Direction
: TDirection
);
5000 d
:= FModel
.Direction
;
5002 FModel
.Direction
:= Direction
;
5003 if d
<> Direction
then FModel
.ChangeAnimation(FModel
.Animation
, True);
5005 FDirection
:= Direction
;
5008 function TPlayer
.GetKeys(): Byte;
5012 if R_KEY_RED
in FRulez
then Result
:= KEY_RED
;
5013 if R_KEY_GREEN
in FRulez
then Result
:= Result
or KEY_GREEN
;
5014 if R_KEY_BLUE
in FRulez
then Result
:= Result
or KEY_BLUE
;
5016 if FTeam
= TEAM_RED
then Result
:= Result
or KEY_REDTEAM
;
5017 if FTeam
= TEAM_BLUE
then Result
:= Result
or KEY_BLUETEAM
;
5020 procedure TPlayer
.Use();
5024 if FTime
[T_USE
] > gTime
then Exit
;
5026 g_Triggers_PressR(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
,
5027 PLAYER_RECT
.Height
, FUID
, ACTIVATE_PLAYERPRESS
);
5029 for a
:= 0 to High(gPlayers
) do
5030 if (gPlayers
[a
] <> nil) and (gPlayers
[a
] <> Self
) and
5031 gPlayers
[a
].Live
and SameTeam(FUID
, gPlayers
[a
].FUID
) and
5032 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
5033 FObj
.Rect
.Width
, FObj
.Rect
.Height
, @gPlayers
[a
].FObj
) then
5035 gPlayers
[a
].Touch();
5036 if g_Game_IsNet
and g_Game_IsServer
then
5037 MH_SEND_GameEvent(NET_EV_PLAYER_TOUCH
, gPlayers
[a
].FUID
);
5040 FTime
[T_USE
] := gTime
+120;
5043 procedure TPlayer
.NetFire(Wpn
: Byte; X
, Y
, AX
, AY
: Integer; WID
: Integer = -1);
5047 WX
, WY
, XD
, YD
: Integer;
5058 if R_BERSERK
in FRulez
then
5060 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
5061 obj
.X
:= FObj
.X
+FObj
.Rect
.X
;
5062 obj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
5065 obj
.rect
.Width
:= 39;
5066 obj
.rect
.Height
:= 52;
5067 obj
.Vel
.X
:= (xd
-wx
) div 2;
5068 obj
.Vel
.Y
:= (yd
-wy
) div 2;
5069 obj
.Accel
.X
:= xd
-wx
;
5070 obj
.Accel
.y
:= yd
-wy
;
5072 if g_Weapon_Hit(@obj
, 50, FUID
, HIT_SOME
) <> 0 then
5073 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
5075 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
5079 FPain
:= min(FPain
+ 25, 50);
5081 g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
5086 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
5087 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
5089 FSawSoundSelect
.Stop();
5091 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
5093 else if not FSawSoundHit
.IsPlaying() then
5095 FSawSoundSelect
.Stop();
5096 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
5103 g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', GameX
, Gamey
);
5104 FFireAngle
:= FAngle
;
5106 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5107 GameVelX
, GameVelY
-2, SHELL_BULLET
);
5112 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
5113 FFireAngle
:= FAngle
;
5116 FShellType
:= SHELL_SHELL
;
5121 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN2', Gamex
, Gamey
);
5122 FFireAngle
:= FAngle
;
5125 FShellType
:= SHELL_DBLSHELL
;
5130 g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', Gamex
, Gamey
);
5131 FFireAngle
:= FAngle
;
5133 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5134 GameVelX
, GameVelY
-2, SHELL_BULLET
);
5137 WEAPON_ROCKETLAUNCHER
:
5139 g_Weapon_Rocket(wx
, wy
, xd
, yd
, FUID
, WID
);
5140 FFireAngle
:= FAngle
;
5146 g_Weapon_Plasma(wx
, wy
, xd
, yd
, FUID
, WID
);
5147 FFireAngle
:= FAngle
;
5153 g_Weapon_BFGShot(wx
, wy
, xd
, yd
, FUID
, WID
);
5154 FFireAngle
:= FAngle
;
5158 WEAPON_SUPERPULEMET
:
5160 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
5161 FFireAngle
:= FAngle
;
5163 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5164 GameVelX
, GameVelY
-2, SHELL_SHELL
);
5167 WEAPON_FLAMETHROWER
:
5169 g_Weapon_flame(wx
, wy
, xd
, yd
, FUID
, WID
);
5170 FFireAngle
:= FAngle
;
5177 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
5178 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
5179 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
5182 procedure TPlayer
.DoLerp(Level
: Integer = 2);
5184 if FObj
.X
<> FXTo
then FObj
.X
:= Lerp(FObj
.X
, FXTo
, Level
);
5185 if FObj
.Y
<> FYTo
then FObj
.Y
:= Lerp(FObj
.Y
, FYTo
, Level
);
5188 procedure TPlayer
.SetLerp(XTo
, YTo
: Integer);
5192 if NetInterpLevel
< 1 then
5202 AX
:= Abs(FXTo
- FObj
.X
);
5203 AY
:= Abs(FYTo
- FObj
.Y
);
5204 if (AX
> 32) or (AX
<= NetInterpLevel
) then
5206 if (AY
> 32) or (AY
<= NetInterpLevel
) then
5211 function TPlayer
.FullInLift(XInc
, YInc
: Integer): Integer;
5213 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5214 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5215 PANEL_LIFTUP
, False) then Result
:= -1
5217 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5218 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5219 PANEL_LIFTDOWN
, False) then Result
:= 1
5223 function TPlayer
.GetFlag(Flag
: Byte): Boolean;
5230 if Flag
= FLAG_NONE
then
5233 if not g_Game_IsServer
then Exit
;
5235 // Ïðèíåñ ÷óæîé ôëàã íà ñâîþ áàçó:
5236 if (Flag
= FTeam
) and
5237 (gFlags
[Flag
].State
= FLAG_STATE_NORMAL
) and
5238 (FFlag
<> FLAG_NONE
) then
5240 if FFlag
= FLAG_RED
then
5241 s
:= _lc
[I_PLAYER_FLAG_RED
]
5243 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5245 evtype
:= FLAG_STATE_SCORED
;
5247 ts
:= Format('%.4d', [gFlags
[FFlag
].CaptureTime
]);
5248 Insert('.', ts
, Length(ts
) + 1 - 3);
5249 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_CAPTURE
], [FName
, s
, ts
]), True);
5251 g_Map_ResetFlag(FFlag
);
5252 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_CAPTURE
], [AnsiUpperCase(s
)]), 144);
5254 gTeamStat
[FTeam
].Goals
:= gTeamStat
[FTeam
].Goals
+ 1;
5257 if g_Game_IsNet
then
5259 MH_SEND_FlagEvent(evtype
, FFlag
, FUID
, False);
5263 gFlags
[FFlag
].CaptureTime
:= 0;
5268 // Ïîäîáðàë ñâîé ôëàã - âåðíóë åãî íà áàçó:
5269 if (Flag
= FTeam
) and
5270 (gFlags
[Flag
].State
= FLAG_STATE_DROPPED
) then
5272 if Flag
= FLAG_RED
then
5273 s
:= _lc
[I_PLAYER_FLAG_RED
]
5275 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5277 evtype
:= FLAG_STATE_RETURNED
;
5278 gFlags
[Flag
].CaptureTime
:= 0;
5280 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_RETURN
], [FName
, s
]), True);
5282 g_Map_ResetFlag(Flag
);
5283 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
5286 if g_Game_IsNet
then
5288 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5294 // Ïîäîáðàë ÷óæîé ôëàã:
5295 if (Flag
<> FTeam
) and (FTime
[T_FLAGCAP
] <= gTime
) then
5299 if Flag
= FLAG_RED
then
5300 s
:= _lc
[I_PLAYER_FLAG_RED
]
5302 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5304 evtype
:= FLAG_STATE_CAPTURED
;
5306 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_GET
], [FName
, s
]), True);
5308 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_GET
], [AnsiUpperCase(s
)]), 144);
5310 gFlags
[Flag
].State
:= FLAG_STATE_CAPTURED
;
5313 if g_Game_IsNet
then
5315 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5321 procedure TPlayer
.SetFlag(Flag
: Byte);
5324 if FModel
<> nil then
5325 FModel
.SetFlag(FFlag
);
5328 function TPlayer
.DropFlag(): Boolean;
5333 if (not g_Game_IsServer
) or (FFlag
= FLAG_NONE
) then
5335 FTime
[T_FLAGCAP
] := gTime
+ 2000;
5336 with gFlags
[FFlag
] do
5340 Direction
:= FDirection
;
5341 State
:= FLAG_STATE_DROPPED
;
5343 g_Obj_Push(@Obj
, (FObj
.Vel
.X
div 2)-2+Random(5),
5344 (FObj
.Vel
.Y
div 2)-2+Random(5));
5346 if FFlag
= FLAG_RED
then
5347 s
:= _lc
[I_PLAYER_FLAG_RED
]
5349 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5351 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_DROP
], [FName
, s
]), True);
5352 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_DROP
], [AnsiUpperCase(s
)]), 144);
5354 if g_Game_IsNet
then
5355 MH_SEND_FlagEvent(FLAG_STATE_DROPPED
, Flag
, FUID
, False);
5361 procedure TPlayer
.GetSecret();
5366 procedure TPlayer
.PressKey(Key
: Byte; Time
: Word = 1);
5368 Assert(Key
<= High(FKeys
));
5370 FKeys
[Key
].Pressed
:= True;
5371 FKeys
[Key
].Time
:= Time
;
5374 function TPlayer
.IsKeyPressed(K
: Byte): Boolean;
5376 Result
:= FKeys
[K
].Pressed
;
5379 procedure TPlayer
.ReleaseKeys();
5383 for a
:= Low(FKeys
) to High(FKeys
) do
5385 FKeys
[a
].Pressed
:= False;
5390 procedure TPlayer
.OnDamage(Angle
: SmallInt);
5394 function TPlayer
.firediry(): Integer;
5396 if FKeys
[KEY_UP
].Pressed
then Result
:= -42
5397 else if FKeys
[KEY_DOWN
].Pressed
then Result
:= 19
5401 procedure TPlayer
.RememberState();
5405 FSavedState
.Health
:= FHealth
;
5406 FSavedState
.Armor
:= FArmor
;
5407 FSavedState
.Air
:= FAir
;
5408 FSavedState
.JetFuel
:= FJetFuel
;
5409 FSavedState
.CurrWeap
:= FCurrWeap
;
5410 FSavedState
.NextWeap
:= FNextWeap
;
5411 FSavedState
.NextWeapDelay
:= FNextWeapDelay
;
5414 FSavedState
.Ammo
[i
] := FAmmo
[i
];
5416 FSavedState
.MaxAmmo
[i
] := FMaxAmmo
[i
];
5418 FSavedState
.Rulez
:= FRulez
;
5419 FSavedState
.WaitRecall
:= True;
5422 procedure TPlayer
.RecallState();
5426 if not FSavedState
.WaitRecall
then Exit
;
5428 FHealth
:= FSavedState
.Health
;
5429 FArmor
:= FSavedState
.Armor
;
5430 FAir
:= FSavedState
.Air
;
5431 FJetFuel
:= FSavedState
.JetFuel
;
5432 FCurrWeap
:= FSavedState
.CurrWeap
;
5433 FNextWeap
:= FSavedState
.NextWeap
;
5434 FNextWeapDelay
:= FSavedState
.NextWeapDelay
;
5437 FAmmo
[i
] := FSavedState
.Ammo
[i
];
5439 FMaxAmmo
[i
] := FSavedState
.MaxAmmo
[i
];
5441 FRulez
:= FSavedState
.Rulez
;
5442 FSavedState
.WaitRecall
:= False;
5444 if gGameSettings
.GameType
= GT_SERVER
then
5445 MH_SEND_PlayerStats(FUID
);
5448 procedure TPlayer
.SaveState(var Mem
: TBinMemoryWriter
);
5460 Mem
:= TBinMemoryWriter
.Create(i
);
5462 // Ñèãíàòóðà èãðîêà:
5463 sig
:= PLAYER_SIGNATURE
; // 'PLYR'
5464 Mem
.WriteDWORD(sig
);
5466 Mem
.WriteBoolean(FIamBot
);
5468 Mem
.WriteWord(FUID
);
5470 Mem
.WriteString(FName
, 32);
5472 Mem
.WriteByte(FTeam
);
5474 Mem
.WriteBoolean(FLive
);
5475 // Èçðàñõîäîâàë ëè âñå æèçíè:
5476 Mem
.WriteBoolean(FNoRespawn
);
5478 if FDirection
= D_LEFT
then
5484 Mem
.WriteInt(FHealth
);
5486 Mem
.WriteByte(FLives
);
5488 Mem
.WriteInt(FArmor
);
5492 Mem
.WriteInt(FJetFuel
);
5494 Mem
.WriteInt(FPain
);
5496 Mem
.WriteInt(FKills
);
5498 Mem
.WriteInt(FMonsterKills
);
5500 Mem
.WriteInt(FFrags
);
5502 Mem
.WriteByte(FFragCombo
);
5503 // Âðåìÿ ïîñëåäíåãî ôðàãà:
5504 Mem
.WriteDWORD(FLastFrag
);
5506 Mem
.WriteInt(FDeath
);
5507 // Êàêîé ôëàã íåñåò:
5508 Mem
.WriteByte(FFlag
);
5510 Mem
.WriteInt(FSecrets
);
5512 Mem
.WriteByte(FCurrWeap
);
5514 Mem
.WriteWord(FNextWeap
);
5516 Mem
.WriteByte(FNextWeapDelay
);
5517 // Âðåìÿ çàðÿäêè BFG:
5518 Mem
.WriteSmallInt(FBFGFireCounter
);
5520 Mem
.WriteInt(FDamageBuffer
);
5521 // Ïîñëåäíèé óäàðèâøèé:
5522 Mem
.WriteWord(FLastSpawnerUID
);
5523 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà:
5524 Mem
.WriteByte(FLastHit
);
5526 Obj_SaveState(@FObj
, Mem
);
5527 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ:
5528 for i
:= A_BULLETS
to A_HIGH
do
5529 Mem
.WriteWord(FAmmo
[i
]);
5530 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ:
5531 for i
:= A_BULLETS
to A_HIGH
do
5532 Mem
.WriteWord(FMaxAmmo
[i
]);
5534 for i
:= WP_FIRST
to WP_LAST
do
5535 Mem
.WriteBoolean(FWeapon
[i
]);
5536 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ:
5537 for i
:= WP_FIRST
to WP_LAST
do
5538 Mem
.WriteWord(FReloading
[i
]);
5540 if R_ITEM_BACKPACK
in FRulez
then
5545 // Íàëè÷èå êðàñíîãî êëþ÷à:
5546 if R_KEY_RED
in FRulez
then
5551 // Íàëè÷èå çåëåíîãî êëþ÷à:
5552 if R_KEY_GREEN
in FRulez
then
5557 // Íàëè÷èå ñèíåãî êëþ÷à:
5558 if R_KEY_BLUE
in FRulez
then
5563 // Íàëè÷èå áåðñåðêà:
5564 if R_BERSERK
in FRulez
then
5569 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ:
5570 for i
:= MR_SUIT
to MR_MAX
do
5571 Mem
.WriteDWORD(FMegaRulez
[i
]);
5572 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà:
5573 for i
:= T_RESPAWN
to T_FLAGCAP
do
5574 Mem
.WriteDWORD(FTime
[i
]);
5577 Mem
.WriteString(str
);
5587 procedure TPlayer
.LoadState(var Mem
: TBinMemoryReader
);
5597 // Ñèãíàòóðà èãðîêà:
5599 if sig
<> PLAYER_SIGNATURE
then // 'PLYR'
5601 raise EBinSizeError
.Create('TPlayer.LoadState: Wrong Player Signature');
5604 Mem
.ReadBoolean(FIamBot
);
5608 Mem
.ReadString(str
);
5609 if (Self
<> gPlayer1
) and (Self
<> gPlayer2
) then
5612 Mem
.ReadByte(FTeam
);
5614 Mem
.ReadBoolean(FLive
);
5615 // Èçðàñõîäîâàë ëè âñå æèçíè:
5616 Mem
.ReadBoolean(FNoRespawn
);
5620 FDirection
:= D_LEFT
5622 FDirection
:= D_RIGHT
;
5624 Mem
.ReadInt(FHealth
);
5626 Mem
.ReadByte(FLives
);
5628 Mem
.ReadInt(FArmor
);
5632 Mem
.ReadInt(FJetFuel
);
5636 Mem
.ReadInt(FKills
);
5638 Mem
.ReadInt(FMonsterKills
);
5640 Mem
.ReadInt(FFrags
);
5642 Mem
.ReadByte(FFragCombo
);
5643 // Âðåìÿ ïîñëåäíåãî ôðàãà:
5644 Mem
.ReadDWORD(FLastFrag
);
5646 Mem
.ReadInt(FDeath
);
5647 // Êàêîé ôëàã íåñåò:
5648 Mem
.ReadByte(FFlag
);
5650 Mem
.ReadInt(FSecrets
);
5652 Mem
.ReadByte(FCurrWeap
);
5654 Mem
.ReadWord(FNextWeap
);
5656 Mem
.ReadByte(FNextWeapDelay
);
5657 // Âðåìÿ çàðÿäêè BFG:
5658 Mem
.ReadSmallInt(FBFGFireCounter
);
5660 Mem
.ReadInt(FDamageBuffer
);
5661 // Ïîñëåäíèé óäàðèâøèé:
5662 Mem
.ReadWord(FLastSpawnerUID
);
5663 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà:
5664 Mem
.ReadByte(FLastHit
);
5666 Obj_LoadState(@FObj
, Mem
);
5667 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ:
5668 for i
:= A_BULLETS
to A_HIGH
do
5669 Mem
.ReadWord(FAmmo
[i
]);
5670 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ:
5671 for i
:= A_BULLETS
to A_HIGH
do
5672 Mem
.ReadWord(FMaxAmmo
[i
]);
5674 for i
:= WP_FIRST
to WP_LAST
do
5675 Mem
.ReadBoolean(FWeapon
[i
]);
5676 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ:
5677 for i
:= WP_FIRST
to WP_LAST
do
5678 Mem
.ReadWord(FReloading
[i
]);
5682 Include(FRulez
, R_ITEM_BACKPACK
);
5683 // Íàëè÷èå êðàñíîãî êëþ÷à:
5686 Include(FRulez
, R_KEY_RED
);
5687 // Íàëè÷èå çåëåíîãî êëþ÷à:
5690 Include(FRulez
, R_KEY_GREEN
);
5691 // Íàëè÷èå ñèíåãî êëþ÷à:
5694 Include(FRulez
, R_KEY_BLUE
);
5695 // Íàëè÷èå áåðñåðêà:
5698 Include(FRulez
, R_BERSERK
);
5699 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ:
5700 for i
:= MR_SUIT
to MR_MAX
do
5701 Mem
.ReadDWORD(FMegaRulez
[i
]);
5702 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà:
5703 for i
:= T_RESPAWN
to T_FLAGCAP
do
5704 Mem
.ReadDWORD(FTime
[i
]);
5706 Mem
.ReadString(str
);
5708 Mem
.ReadByte(FColor
.R
);
5709 Mem
.ReadByte(FColor
.G
);
5710 Mem
.ReadByte(FColor
.B
);
5711 if Self
= gPlayer1
then
5713 str
:= gPlayer1Settings
.Model
;
5714 FColor
:= gPlayer1Settings
.Color
;
5716 if Self
= gPlayer2
then
5718 str
:= gPlayer2Settings
.Model
;
5719 FColor
:= gPlayer2Settings
.Color
;
5721 // Îáíîâëÿåì ìîäåëü èãðîêà:
5723 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
5724 FModel
.Color
:= TEAMCOLOR
[FTeam
]
5726 FModel
.Color
:= FColor
;
5729 procedure TPlayer
.AllRulez(Health
: Boolean);
5735 FHealth
:= PLAYER_HP_LIMIT
;
5736 FArmor
:= PLAYER_AP_LIMIT
;
5740 for a
:= WP_FIRST
to WP_LAST
do FWeapon
[a
] := True;
5741 for a
:= A_BULLETS
to A_HIGH
do FAmmo
[a
] := 30000;
5742 FRulez
:= FRulez
+[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
];
5745 procedure TPlayer
.RestoreHealthArmor();
5747 FHealth
:= PLAYER_HP_LIMIT
;
5748 FArmor
:= PLAYER_AP_LIMIT
;
5751 procedure TPlayer
.FragCombo();
5755 if (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) or g_Game_IsClient
then
5757 if gTime
- FLastFrag
< FRAG_COMBO_TIME
then
5759 if FFragCombo
< 5 then
5761 Param
:= FUID
or (FFragCombo
shl 16);
5762 if (FComboEvnt
>= Low(gDelayedEvents
)) and
5763 (FComboEvnt
<= High(gDelayedEvents
)) and
5764 gDelayedEvents
[FComboEvnt
].Pending
and
5765 (gDelayedEvents
[FComboEvnt
].DEType
= DE_KILLCOMBO
) and
5766 (gDelayedEvents
[FComboEvnt
].DENum
and $FFFF = FUID
) then
5768 gDelayedEvents
[FComboEvnt
].Time
:= gTime
+ 500;
5769 gDelayedEvents
[FComboEvnt
].DENum
:= Param
;
5772 FComboEvnt
:= g_Game_DelayEvent(DE_KILLCOMBO
, 500, Param
);
5780 procedure TPlayer
.GiveItem(ItemType
: Byte);
5784 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
5786 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
5790 if FAir
< AIR_MAX
then
5797 if not (R_BERSERK
in FRulez
) then
5799 Include(FRulez
, R_BERSERK
);
5800 if FBFGFireCounter
< 1 then
5802 FCurrWeap
:= WEAPON_KASTET
;
5804 FModel
.SetWeapon(WEAPON_KASTET
);
5808 FBerserk
:= gTime
+30000;
5810 if FHealth
< PLAYER_HP_SOFT
then
5812 FHealth
:= PLAYER_HP_SOFT
;
5813 FBerserk
:= gTime
+30000;
5818 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
5820 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
5824 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
5826 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
5830 if FJetFuel
< JET_MAX
then
5832 FJetFuel
:= JET_MAX
;
5835 ITEM_MEDKIT_SMALL
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
5836 ITEM_MEDKIT_LARGE
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
5838 ITEM_ARMOR_GREEN
: if FArmor
< PLAYER_AP_SOFT
then FArmor
:= PLAYER_AP_SOFT
;
5839 ITEM_ARMOR_BLUE
: if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
5841 ITEM_SPHERE_BLUE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
5843 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) then
5845 if FHealth
< PLAYER_HP_LIMIT
then FHealth
:= PLAYER_HP_LIMIT
;
5846 if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
5849 ITEM_WEAPON_SAW
: FWeapon
[WEAPON_SAW
] := True;
5850 ITEM_WEAPON_SHOTGUN1
: FWeapon
[WEAPON_SHOTGUN1
] := True;
5851 ITEM_WEAPON_SHOTGUN2
: FWeapon
[WEAPON_SHOTGUN2
] := True;
5852 ITEM_WEAPON_CHAINGUN
: FWeapon
[WEAPON_CHAINGUN
] := True;
5853 ITEM_WEAPON_ROCKETLAUNCHER
: FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
5854 ITEM_WEAPON_PLASMA
: FWeapon
[WEAPON_PLASMA
] := True;
5855 ITEM_WEAPON_BFG
: FWeapon
[WEAPON_BFG
] := True;
5856 ITEM_WEAPON_SUPERPULEMET
: FWeapon
[WEAPON_SUPERPULEMET
] := True;
5857 ITEM_WEAPON_FLAMETHROWER
: FWeapon
[WEAPON_FLAMETHROWER
] := True;
5859 ITEM_AMMO_BULLETS
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
5860 ITEM_AMMO_BULLETS_BOX
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
5861 ITEM_AMMO_SHELLS
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
5862 ITEM_AMMO_SHELLS_BOX
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
5863 ITEM_AMMO_ROCKET
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
5864 ITEM_AMMO_ROCKET_BOX
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
5865 ITEM_AMMO_CELL
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
5866 ITEM_AMMO_CELL_BIG
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
5867 ITEM_AMMO_FUELCAN
: if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
5870 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
5871 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
5872 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
5873 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or
5874 (FMaxAmmo
[A_FUEL
] < AmmoLimits
[1, A_FUEL
]) then
5876 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[1, A_BULLETS
];
5877 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[1, A_SHELLS
];
5878 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[1, A_ROCKETS
];
5879 FMaxAmmo
[A_CELLS
] := AmmoLimits
[1, A_CELLS
];
5880 FMaxAmmo
[A_FUEL
] := AmmoLimits
[1, A_FUEL
];
5882 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
5883 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
5884 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
5885 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
5887 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
5890 ITEM_KEY_RED
: if not (R_KEY_RED
in FRulez
) then Include(FRulez
, R_KEY_RED
);
5891 ITEM_KEY_GREEN
: if not (R_KEY_GREEN
in FRulez
) then Include(FRulez
, R_KEY_GREEN
);
5892 ITEM_KEY_BLUE
: if not (R_KEY_BLUE
in FRulez
) then Include(FRulez
, R_KEY_BLUE
);
5894 ITEM_BOTTLE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
5895 ITEM_HELMET
: if FArmor
< PLAYER_AP_LIMIT
then IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
5900 if g_Game_IsNet
and g_Game_IsServer
then
5901 MH_SEND_PlayerStats(FUID
);
5904 procedure TPlayer
.FlySmoke(Times
: DWORD
= 1);
5909 if (Random(5) = 1) and (Times
= 1) then
5912 if BodyInLiquid(0, 0) then
5914 g_GFX_Bubbles(Obj
.X
+Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2)+Random(3)-1,
5915 Obj
.Y
+Obj
.Rect
.Height
+8, 1, 8, 4);
5916 if Random(2) = 0 then
5917 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
5919 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
5923 if g_Frames_Get(id
, 'FRAMES_SMOKE') then
5925 for i
:= 1 to Times
do
5927 Anim
:= TAnimation
.Create(id
, False, 3);
5929 g_GFX_OnceAnim(Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(Anim
.Width
div 2),
5930 Obj
.Y
+Obj
.Rect
.Height
-4+Random(8+Times
*2), Anim
, ONCEANIM_SMOKE
);
5936 procedure TPlayer
.OnFireFlame(Times
: DWORD
= 1);
5941 if (Random(10) = 1) and (Times
= 1) then
5944 if g_Frames_Get(id
, 'FRAMES_FLAME') then
5946 for i
:= 1 to Times
do
5948 Anim
:= TAnimation
.Create(id
, False, 3);
5950 g_GFX_OnceAnim(Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(Anim
.Width
div 2),
5951 Obj
.Y
+8+Random(8+Times
*2), Anim
, ONCEANIM_SMOKE
);
5957 procedure TPlayer
.PauseSounds(Enable
: Boolean);
5959 FSawSound
.Pause(Enable
);
5960 FSawSoundIdle
.Pause(Enable
);
5961 FSawSoundHit
.Pause(Enable
);
5962 FSawSoundSelect
.Pause(Enable
);
5967 constructor TCorpse
.Create(X
, Y
: Integer; ModelName
: String; aMess
: Boolean);
5972 FObj
.Rect
:= PLAYER_CORPSERECT
;
5973 FModelName
:= ModelName
;
5978 FState
:= CORPSE_STATE_MESS
;
5979 g_PlayerModel_GetAnim(ModelName
, A_DIE2
, FAnimation
, FAnimationMask
);
5983 FState
:= CORPSE_STATE_NORMAL
;
5984 g_PlayerModel_GetAnim(ModelName
, A_DIE1
, FAnimation
, FAnimationMask
);
5988 destructor TCorpse
.Destroy();
5995 procedure TCorpse
.Damage(Value
: Word; vx
, vy
: Integer);
5999 if FState
= CORPSE_STATE_REMOVEME
then
6002 FDamage
:= FDamage
+ Value
;
6004 if FDamage
> 150 then
6006 if FAnimation
<> nil then
6011 FState
:= CORPSE_STATE_REMOVEME
;
6013 g_Player_CreateGibs(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
6014 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2),
6015 FModelName
, FColor
);
6016 // Çâóê ìÿñà îò òðóïà:
6017 pm
:= g_PlayerModel_Get(FModelName
);
6018 pm
.PlaySound(MODELSOUND_DIE
, 5, FObj
.X
, FObj
.Y
);
6024 FObj
.Vel
.X
:= FObj
.Vel
.X
+ vx
;
6025 FObj
.Vel
.Y
:= FObj
.Vel
.Y
+ vy
;
6026 g_GFX_Blood(FObj
.X
+PLAYER_CORPSERECT
.X
+(PLAYER_CORPSERECT
.Width
div 2),
6027 FObj
.Y
+PLAYER_CORPSERECT
.Y
+(PLAYER_CORPSERECT
.Height
div 2),
6028 Value
, vx
, vy
, 16, (PLAYER_CORPSERECT
.Height
*2) div 3,
6033 procedure TCorpse
.Draw();
6035 if FState
= CORPSE_STATE_REMOVEME
then
6038 if FAnimation
<> nil then
6039 FAnimation
.Draw(FObj
.X
, FObj
.Y
, M_NONE
);
6041 if FAnimationMask
<> nil then
6044 FAnimationMask
.Draw(FObj
.X
, FObj
.Y
, M_NONE
);
6051 procedure TCorpse
.Update();
6055 if FState
= CORPSE_STATE_REMOVEME
then
6058 if gTime
mod (GAME_TICK
*2) <> 0 then
6060 g_Obj_Move(@FObj
, True, True, True);
6065 // Ñîïðîòèâëåíèå âîçäóõà äëÿ òðóïà:
6066 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
6068 st
:= g_Obj_Move(@FObj
, True, True, True);
6070 if WordBool(st
and MOVE_FALLOUT
) then
6072 FState
:= CORPSE_STATE_REMOVEME
;
6076 if FAnimation
<> nil then
6077 FAnimation
.Update();
6078 if FAnimationMask
<> nil then
6079 FAnimationMask
.Update();
6082 procedure TCorpse
.SaveState(var Mem
: TBinMemoryWriter
);
6091 sig
:= CORPSE_SIGNATURE
; // 'CORP'
6092 Mem
.WriteDWORD(sig
);
6094 Mem
.WriteByte(FState
);
6095 // Íàêîïëåííûé óðîí:
6096 Mem
.WriteByte(FDamage
);
6098 Mem
.WriteByte(FColor
.R
);
6099 Mem
.WriteByte(FColor
.G
);
6100 Mem
.WriteByte(FColor
.B
);
6102 Obj_SaveState(@FObj
, Mem
);
6103 // Åñòü ëè àíèìàöèÿ:
6104 anim
:= FAnimation
<> nil;
6105 Mem
.WriteBoolean(anim
);
6106 // Åñëè åñòü - ñîõðàíÿåì:
6108 FAnimation
.SaveState(Mem
);
6109 // Åñòü ëè ìàñêà àíèìàöèè:
6110 anim
:= FAnimationMask
<> nil;
6111 Mem
.WriteBoolean(anim
);
6112 // Åñëè åñòü - ñîõðàíÿåì:
6114 FAnimationMask
.SaveState(Mem
);
6117 procedure TCorpse
.LoadState(var Mem
: TBinMemoryReader
);
6127 if sig
<> CORPSE_SIGNATURE
then // 'CORP'
6129 raise EBinSizeError
.Create('TCorpse.LoadState: Wrong Corpse Signature');
6132 Mem
.ReadByte(FState
);
6133 // Íàêîïëåííûé óðîí:
6134 Mem
.ReadByte(FDamage
);
6136 Mem
.ReadByte(FColor
.R
);
6137 Mem
.ReadByte(FColor
.G
);
6138 Mem
.ReadByte(FColor
.B
);
6140 Obj_LoadState(@FObj
, Mem
);
6141 // Åñòü ëè àíèìàöèÿ:
6142 Mem
.ReadBoolean(anim
);
6143 // Åñëè åñòü - çàãðóæàåì:
6146 Assert(FAnimation
<> nil, 'TCorpse.LoadState: no FAnimation');
6147 FAnimation
.LoadState(Mem
);
6149 // Åñòü ëè ìàñêà àíèìàöèè:
6150 Mem
.ReadBoolean(anim
);
6151 // Åñëè åñòü - çàãðóæàåì:
6154 Assert(FAnimationMask
<> nil, 'TCorpse.LoadState: no FAnimationMask');
6155 FAnimationMask
.LoadState(Mem
);
6161 constructor TBot
.Create();
6168 FSpectator
:= False;
6175 for a
:= WP_FIRST
to WP_LAST
do
6177 FDifficult
.WeaponPrior
[a
] := WEAPON_PRIOR1
[a
];
6178 FDifficult
.CloseWeaponPrior
[a
] := WEAPON_PRIOR2
[a
];
6179 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
6183 destructor TBot
.Destroy();
6186 inherited Destroy();
6189 procedure TBot
.Draw();
6193 //if FTargetUID <> 0 then e_DrawLine(1, FObj.X, FObj.Y, g_Player_Get(FTargetUID).FObj.X,
6194 // g_Player_Get(FTargetUID).FObj.Y, 255, 0, 0);
6197 procedure TBot
.Respawn(Silent
: Boolean; Force
: Boolean = False);
6199 inherited Respawn(Silent
, Force
);
6202 FSelectedWeapon
:= FCurrWeap
;
6207 procedure TBot
.UpdateCombat();
6220 TTargetRecord
= array of TTarget
;
6222 function Compare(a
, b
: TTarget
): Integer;
6224 if a
.Line
and not b
.Line
then // A íà ëèíèè îãíÿ
6227 if not a
.Line
and b
.Line
then // B íà ëèíèè îãíÿ
6229 else // È A, è B íà ëèíèè èëè íå íà ëèíèè îãíÿ
6230 if (a
.Line
and b
.Line
) or ((not a
.Line
) and (not b
.Line
)) then
6232 if a
.Dist
> b
.Dist
then // B áëèæå
6234 else // A áëèæå èëè ðàâíîóäàëåííî ñ B
6237 else // Ñòðàííî -> A
6242 a
, x1
, y1
, x2
, y2
: Integer;
6243 targets
: TTargetRecord
;
6245 Target
, BestTarget
: TTarget
;
6246 firew
, fireh
: Integer;
6250 vsPlayer
, vsMonster
, ok
: Boolean;
6252 vsPlayer
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
);
6253 vsMonster
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
);
6255 // Åñëè òåêóùåå îðóæèå íå òî, ÷òî íóæíî, òî ìåíÿåì:
6256 if FCurrWeap
<> FSelectedWeapon
then
6259 // Åñëè íóæíî ñòðåëÿòü è íóæíîå îðóæèå, òî íàæàòü "Ñòðåëÿòü":
6260 if (GetAIFlag('NEEDFIRE') <> '') and (FCurrWeap
= FSelectedWeapon
) then
6262 RemoveAIFlag('NEEDFIRE');
6265 WEAPON_PLASMA
, WEAPON_SUPERPULEMET
, WEAPON_CHAINGUN
: PressKey(KEY_FIRE
, 20);
6266 WEAPON_SAW
, WEAPON_KASTET
, WEAPON_FLAMETHROWER
: PressKey(KEY_FIRE
, 40);
6267 else PressKey(KEY_FIRE
);
6271 // Êîîðäèíàòû ñòâîëà:
6272 x1
:= FObj
.X
+ WEAPONPOINT
[FDirection
].X
;
6273 y1
:= FObj
.Y
+ WEAPONPOINT
[FDirection
].Y
;
6275 Target
.UID
:= FTargetUID
;
6278 if Target
.UID
<> 0 then
6279 begin // Öåëü åñòü - íàñòðàèâàåì
6280 if (g_GetUIDType(Target
.UID
) = UID_PLAYER
) and
6283 tpla
:= g_Player_Get(Target
.UID
);
6287 if (@FObj
) <> nil then
6294 Target
.cX
:= Target
.X
+ PLAYER_RECT_CX
;
6295 Target
.cY
:= Target
.Y
+ PLAYER_RECT_CY
;
6296 Target
.Rect
:= PLAYER_RECT
;
6297 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6298 Target
.Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6299 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6300 Target
.IsPlayer
:= True;
6304 if (g_GetUIDType(Target
.UID
) = UID_MONSTER
) and
6307 mon
:= g_Monsters_Get(Target
.UID
);
6310 Target
.X
:= mon
.Obj
.X
;
6311 Target
.Y
:= mon
.Obj
.Y
;
6313 Target
.cX
:= Target
.X
+ mon
.Obj
.Rect
.X
+ (mon
.Obj
.Rect
.Width
div 2);
6314 Target
.cY
:= Target
.Y
+ mon
.Obj
.Rect
.Y
+ (mon
.Obj
.Rect
.Height
div 2);
6315 Target
.Rect
:= mon
.Obj
.Rect
;
6316 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6317 Target
.Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6318 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6319 Target
.IsPlayer
:= False;
6326 begin // Öåëè íåò - îáíóëÿåì
6331 Target
.Visible
:= False;
6332 Target
.Line
:= False;
6333 Target
.IsPlayer
:= False;
6338 // Åñëè öåëü íå âèäèìà èëè íå íà ëèíèè îãíÿ, òî èùåì âñå âîçìîæíûå öåëè:
6339 if (not Target
.Line
) or (not Target
.Visible
) then
6343 for a
:= 0 to High(gPlayers
) do
6344 if (gPlayers
[a
] <> nil) and (gPlayers
[a
].Live
) and
6345 (gPlayers
[a
].FUID
<> FUID
) and
6346 (not SameTeam(FUID
, gPlayers
[a
].FUID
)) and
6347 (not gPlayers
[a
].NoTarget
) and
6348 (gPlayers
[a
].FMegaRulez
[MR_INVIS
] < gTime
) then
6350 if not TargetOnScreen(gPlayers
[a
].FObj
.X
+ PLAYER_RECT
.X
,
6351 gPlayers
[a
].FObj
.Y
+ PLAYER_RECT
.Y
) then
6354 x2
:= gPlayers
[a
].FObj
.X
+ PLAYER_RECT_CX
;
6355 y2
:= gPlayers
[a
].FObj
.Y
+ PLAYER_RECT_CY
;
6357 // Åñëè èãðîê íà ýêðàíå è íå ïðèêðûò ñòåíîé:
6358 if g_TraceVector(x1
, y1
, x2
, y2
) then
6360 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé:
6361 SetLength(targets
, Length(targets
)+1);
6362 with targets
[High(targets
)] do
6364 UID
:= gPlayers
[a
].FUID
;
6365 X
:= gPlayers
[a
].FObj
.X
;
6366 Y
:= gPlayers
[a
].FObj
.Y
;
6369 Rect
:= PLAYER_RECT
;
6370 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6371 Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6372 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6380 if vsMonster
and (gMonsters
<> nil) then
6381 for a
:= 0 to High(gMonsters
) do
6382 if (gMonsters
[a
] <> nil) and (gMonsters
[a
].Live
) and
6383 (gMonsters
[a
].MonsterType
<> MONSTER_BARREL
) then
6385 mon
:= gMonsters
[a
];
6387 if not TargetOnScreen(mon
.Obj
.X
+ mon
.Obj
.Rect
.X
,
6388 mon
.Obj
.Y
+ mon
.Obj
.Rect
.Y
) then
6391 x2
:= mon
.Obj
.X
+ mon
.Obj
.Rect
.X
+ (mon
.Obj
.Rect
.Width
div 2);
6392 y2
:= mon
.Obj
.Y
+ mon
.Obj
.Rect
.Y
+ (mon
.Obj
.Rect
.Height
div 2);
6394 // Åñëè ìîíñòð íà ýêðàíå è íå ïðèêðûò ñòåíîé:
6395 if g_TraceVector(x1
, y1
, x2
, y2
) then
6397 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé:
6398 SetLength(targets
, Length(targets
)+1);
6399 with targets
[High(targets
)] do
6406 Rect
:= mon
.Obj
.Rect
;
6407 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6408 Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6409 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6417 // Åñëè åñòü âîçìîæíûå öåëè:
6418 // (Âûáèðàåì ëó÷øóþ, ìåíÿåì îðóæèå è áåæèì ê íåé/îò íåå)
6419 if targets
<> nil then
6421 // Âûáèðàåì íàèëó÷øóþ öåëü:
6422 BestTarget
:= targets
[0];
6423 if Length(targets
) > 1 then
6424 for a
:= 1 to High(targets
) do
6425 if Compare(BestTarget
, targets
[a
]) = 1 then
6426 BestTarget
:= targets
[a
];
6428 // Åñëè ëó÷øàÿ öåëü "âèäíåå" òåêóùåé, òî òåêóùàÿ := ëó÷øàÿ:
6429 if ((not Target
.Visible
) and BestTarget
.Visible
and (Target
.UID
<> BestTarget
.UID
)) or
6430 ((not Target
.Line
) and BestTarget
.Line
and BestTarget
.Visible
) then
6432 Target
:= BestTarget
;
6434 if (Healthy() = 3) or ((Healthy() = 2)) then
6435 begin // Åñëè çäîðîâû - äîãîíÿåì
6436 if ((RunDirection() = D_LEFT
) and (Target
.X
> FObj
.X
)) then
6437 SetAIFlag('GORIGHT', '1');
6438 if ((RunDirection() = D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6439 SetAIFlag('GOLEFT', '1');
6442 begin // Åñëè ïîáèòû - óáåãàåì
6443 if ((RunDirection() = D_LEFT
) and (Target
.X
< FObj
.X
)) then
6444 SetAIFlag('GORIGHT', '1');
6445 if ((RunDirection() = D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6446 SetAIFlag('GOLEFT', '1');
6449 // Âûáèðàåì îðóæèå íà îñíîâå ðàññòîÿíèÿ è ïðèîðèòåòîâ:
6450 SelectWeapon(Abs(x1
-Target
.cX
));
6455 // (Äîãîíÿåì/óáåãàåì, ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëè)
6456 // (Åñëè öåëü äàëåêî, òî õâàòèò ñëåäèòü çà íåé)
6457 if Target
.UID
<> 0 then
6459 if not TargetOnScreen(Target
.X
+ Target
.Rect
.X
,
6460 Target
.Y
+ Target
.Rect
.Y
) then
6461 begin // Öåëü ñáåæàëà ñ "ýêðàíà"
6462 if (Healthy() = 3) or ((Healthy() = 2)) then
6463 begin // Åñëè çäîðîâû - äîãîíÿåì
6464 if ((RunDirection() = D_LEFT
) and (Target
.X
> FObj
.X
)) then
6465 SetAIFlag('GORIGHT', '1');
6466 if ((RunDirection() = D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6467 SetAIFlag('GOLEFT', '1');
6470 begin // Åñëè ïîáèòû - çàáûâàåì î öåëè è óáåãàåì
6472 if ((RunDirection() = D_LEFT
) and (Target
.X
< FObj
.X
)) then
6473 SetAIFlag('GORIGHT', '1');
6474 if ((RunDirection() = D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6475 SetAIFlag('GOLEFT', '1');
6479 begin // Öåëü ïîêà íà "ýêðàíå"
6480 // Åñëè öåëü íå çàãîðîæåíà ñòåíîé, òî îòìå÷àåì, êîãäà åå âèäåëè:
6481 if g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6482 FLastVisible
:= gTime
;
6483 // Åñëè ðàçíèöà âûñîò íå âåëèêà, òî äîãîíÿåì:
6484 if (Abs(FObj
.Y
-Target
.Y
) <= 128) then
6486 if ((RunDirection() = D_LEFT
) and (Target
.X
> FObj
.X
)) then
6487 SetAIFlag('GORIGHT', '1');
6488 if ((RunDirection() = D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6489 SetAIFlag('GOLEFT', '1');
6493 // Âûáèðàåì óãîë ââåðõ:
6494 if FDirection
= D_LEFT
then
6495 angle
:= ANGLE_LEFTUP
6497 angle
:= ANGLE_RIGHTUP
;
6499 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6500 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6502 // Åñëè ïðè óãëå ââåðõ ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
6503 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6504 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128), //96
6505 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6506 Target
.Rect
.Width
, Target
.Rect
.Height
) and
6507 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6508 begin // òî íóæíî ñòðåëÿòü ââåðõ
6509 SetAIFlag('NEEDFIRE', '1');
6510 SetAIFlag('NEEDSEEUP', '1');
6513 // Âûáèðàåì óãîë âíèç:
6514 if FDirection
= D_LEFT
then
6515 angle
:= ANGLE_LEFTDOWN
6517 angle
:= ANGLE_RIGHTDOWN
;
6519 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6520 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6522 // Åñëè ïðè óãëå âíèç ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
6523 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6524 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
6525 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6526 Target
.Rect
.Width
, Target
.Rect
.Height
) and
6527 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6528 begin // òî íóæíî ñòðåëÿòü âíèç
6529 SetAIFlag('NEEDFIRE', '1');
6530 SetAIFlag('NEEDSEEDOWN', '1');
6533 // Åñëè öåëü âèäíî è îíà íà òàêîé æå âûñîòå:
6534 if Target
.Visible
and
6535 (y1
+4 < Target
.Y
+Target
.Rect
.Y
+Target
.Rect
.Height
) and
6536 (y1
-4 > Target
.Y
+Target
.Rect
.Y
) then
6538 // Åñëè èäåì â ñòîðîíó öåëè, òî íàäî ñòðåëÿòü:
6539 if ((FDirection
= D_LEFT
) and (Target
.X
< FObj
.X
)) or
6540 ((FDirection
= D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6541 begin // òî íóæíî ñòðåëÿòü âïåðåä
6542 SetAIFlag('NEEDFIRE', '1');
6543 SetAIFlag('NEEDSEEDOWN', '');
6544 SetAIFlag('NEEDSEEUP', '');
6546 // Åñëè öåëü â ïðåäåëàõ "ýêðàíà" è ñëîæíîñòü ïîçâîëÿåò ïðûæêè ñáëèæåíèÿ:
6547 if Abs(FObj
.X
-Target
.X
) < Trunc(gPlayerScreenSize
.X
*0.75) then
6548 if GetRnd(FDifficult
.CloseJump
) then
6549 begin // òî åñëè ïîâåçåò - ïðûãàåì (îñîáåííî, åñëè áëèçêî)
6550 if Abs(FObj
.X
-Target
.X
) < 128 then
6554 if Random(a
) = 0 then
6555 SetAIFlag('NEEDJUMP', '1');
6559 // Åñëè öåëü âñå åùå åñòü:
6560 if Target
.UID
<> 0 then
6561 if gTime
-FLastVisible
> 2000 then // Åñëè âèäåëè äàâíî
6562 Target
.UID
:= 0 // òî çàáûòü öåëü
6563 else // Åñëè âèäåëè íåäàâíî
6564 begin // íî öåëü óáèëè
6565 if Target
.IsPlayer
then
6566 begin // Öåëü - èãðîê
6567 pla
:= g_Player_Get(Target
.UID
);
6568 if (pla
= nil) or (not pla
.Live
) or pla
.NoTarget
or
6569 (pla
.FMegaRulez
[MR_INVIS
] >= gTime
) then
6570 Target
.UID
:= 0; // òî çàáûòü öåëü
6573 begin // Öåëü - ìîíñòð
6574 mon
:= g_Monsters_Get(Target
.UID
);
6575 if (mon
= nil) or (not mon
.Live
) then
6576 Target
.UID
:= 0; // òî çàáûòü öåëü
6579 end; // if Target.UID <> 0
6581 FTargetUID
:= Target
.UID
;
6583 // Åñëè âîçìîæíûõ öåëåé íåò:
6584 // (Àòàêà ÷åãî-íèáóäü ñëåâà èëè ñïðàâà)
6585 if targets
= nil then
6586 if GetAIFlag('ATTACKLEFT') <> '' then
6587 begin // Åñëè íóæíî àòàêîâàòü íàëåâî
6588 RemoveAIFlag('ATTACKLEFT');
6590 SetAIFlag('NEEDJUMP', '1');
6592 if RunDirection() = D_RIGHT
then
6593 begin // Èäåì íå â òó ñòîðîíó
6594 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
6595 begin // Åñëè çäîðîâû, òî, âîçìîæíî, ñòðåëÿåì áåæèì âëåâî è ñòðåëÿåì
6596 SetAIFlag('NEEDFIRE', '1');
6597 SetAIFlag('GOLEFT', '1');
6601 begin // Èäåì â íóæíóþ ñòîðîíó
6602 if GetRnd(FDifficult
.InvisFire
) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
6603 SetAIFlag('NEEDFIRE', '1');
6604 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
6605 SetAIFlag('GORIGHT', '1');
6609 if GetAIFlag('ATTACKRIGHT') <> '' then
6610 begin // Åñëè íóæíî àòàêîâàòü íàïðàâî
6611 RemoveAIFlag('ATTACKRIGHT');
6613 SetAIFlag('NEEDJUMP', '1');
6615 if RunDirection() = D_LEFT
then
6616 begin // Èäåì íå â òó ñòîðîíó
6617 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
6618 begin // Åñëè çäîðîâû, òî, âîçìîæíî, áåæèì âïðàâî è ñòðåëÿåì
6619 SetAIFlag('NEEDFIRE', '1');
6620 SetAIFlag('GORIGHT', '1');
6625 if GetRnd(FDifficult
.InvisFire
) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
6626 SetAIFlag('NEEDFIRE', '1');
6627 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
6628 SetAIFlag('GOLEFT', '1');
6632 //HACK! (does it belongs there?)
6633 RealizeCurrentWeapon();
6635 // Åñëè åñòü âîçìîæíûå öåëè:
6636 // (Ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëÿì)
6637 if (targets
<> nil) and (GetAIFlag('NEEDFIRE') <> '') then
6638 for a
:= 0 to High(targets
) do
6640 // Åñëè ìîæåì ñòðåëÿòü ïî äèàãîíàëè:
6641 if GetRnd(FDifficult
.DiagFire
) then
6643 // Èùåì öåëü ñâåðõó è ñòðåëÿåì, åñëè åñòü:
6644 if FDirection
= D_LEFT
then
6645 angle
:= ANGLE_LEFTUP
6647 angle
:= ANGLE_RIGHTUP
;
6649 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6650 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6652 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6653 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
6654 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6655 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
6656 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
6658 SetAIFlag('NEEDFIRE', '1');
6659 SetAIFlag('NEEDSEEUP', '1');
6662 // Èùåì öåëü ñíèçó è ñòðåëÿåì, åñëè åñòü:
6663 if FDirection
= D_LEFT
then
6664 angle
:= ANGLE_LEFTDOWN
6666 angle
:= ANGLE_RIGHTDOWN
;
6668 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6669 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6671 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6672 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
6673 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6674 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
6675 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
6677 SetAIFlag('NEEDFIRE', '1');
6678 SetAIFlag('NEEDSEEDOWN', '1');
6682 // Åñëè öåëü "ïåðåä íîñîì", òî ñòðåëÿåì:
6683 if targets
[a
].Line
and targets
[a
].Visible
and
6684 (((FDirection
= D_LEFT
) and (targets
[a
].X
< FObj
.X
)) or
6685 ((FDirection
= D_RIGHT
) and (targets
[a
].X
> FObj
.X
))) then
6687 SetAIFlag('NEEDFIRE', '1');
6692 // Åñëè ëåòèò ïóëÿ, òî, âîçìîæíî, ïîäïðûãèâàåì:
6693 if g_Weapon_Danger(FUID
, FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
,
6694 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
,
6695 40+GetInterval(FDifficult
.Cover
, 40)) then
6696 SetAIFlag('NEEDJUMP', '1');
6698 // Åñëè êîí÷èëèñü ïàòîðíû, òî íóæíî ñìåíèòü îðóæèå:
6699 ammo
:= GetAmmoByWeapon(FCurrWeap
);
6700 if ((FCurrWeap
= WEAPON_SHOTGUN2
) and (ammo
< 2)) or
6701 ((FCurrWeap
= WEAPON_BFG
) and (ammo
< 40)) or
6703 SetAIFlag('SELECTWEAPON', '1');
6705 // Åñëè íóæíî ñìåíèòü îðóæèå, òî âûáèðàåì íóæíîå:
6706 if GetAIFlag('SELECTWEAPON') = '1' then
6709 RemoveAIFlag('SELECTWEAPON');
6713 procedure TBot
.Update();
6726 // Ïðîâåðÿåì, îòêëþ÷¸í ëè AI áîòîâ
6727 if (g_debug_BotAIOff
= 1) and (Team
= TEAM_RED
) then
6729 if (g_debug_BotAIOff
= 2) and (Team
= TEAM_BLUE
) then
6731 if g_debug_BotAIOff
= 3 then
6741 RealizeCurrentWeapon();
6748 procedure TBot
.ReleaseKey(Key
: Byte);
6757 function TBot
.KeyPressed(Key
: Word): Boolean;
6759 Result
:= FKeys
[Key
].Pressed
;
6762 function TBot
.GetAIFlag(fName
: String20
): String20
;
6768 fName
:= LowerCase(fName
);
6770 if FAIFlags
<> nil then
6771 for a
:= 0 to High(FAIFlags
) do
6772 if LowerCase(FAIFlags
[a
].Name
) = fName
then
6774 Result
:= FAIFlags
[a
].Value
;
6779 procedure TBot
.RemoveAIFlag(fName
: String20
);
6783 if FAIFlags
= nil then Exit
;
6785 fName
:= LowerCase(fName
);
6787 for a
:= 0 to High(FAIFlags
) do
6788 if LowerCase(FAIFlags
[a
].Name
) = fName
then
6790 if a
<> High(FAIFlags
) then
6791 for b
:= a
to High(FAIFlags
)-1 do
6792 FAIFlags
[b
] := FAIFlags
[b
+1];
6794 SetLength(FAIFlags
, Length(FAIFlags
)-1);
6799 procedure TBot
.SetAIFlag(fName
, fValue
: String20
);
6807 fName
:= LowerCase(fName
);
6809 if FAIFlags
<> nil then
6810 for a
:= 0 to High(FAIFlags
) do
6811 if LowerCase(FAIFlags
[a
].Name
) = fName
then
6817 if ok
then FAIFlags
[a
].Value
:= fValue
6820 SetLength(FAIFlags
, Length(FAIFlags
)+1);
6821 with FAIFlags
[High(FAIFlags
)] do
6829 procedure TBot
.UpdateMove
;
6831 procedure GoLeft(Time
: Word = 1);
6833 ReleaseKey(KEY_LEFT
);
6834 ReleaseKey(KEY_RIGHT
);
6835 PressKey(KEY_LEFT
, Time
);
6836 SetDirection(D_LEFT
);
6839 procedure GoRight(Time
: Word = 1);
6841 ReleaseKey(KEY_LEFT
);
6842 ReleaseKey(KEY_RIGHT
);
6843 PressKey(KEY_RIGHT
, Time
);
6844 SetDirection(D_RIGHT
);
6847 function Rnd(a
: Word): Boolean;
6849 Result
:= Random(a
) = 0;
6852 procedure Turn(Time
: Word = 1200);
6854 if RunDirection() = D_LEFT
then GoRight(Time
) else GoLeft(Time
);
6859 ReleaseKey(KEY_LEFT
);
6860 ReleaseKey(KEY_RIGHT
);
6863 function CanRunLeft(): Boolean;
6865 Result
:= not CollideLevel(-1, 0);
6868 function CanRunRight(): Boolean;
6870 Result
:= not CollideLevel(1, 0);
6873 function CanRun(): Boolean;
6875 if RunDirection() = D_LEFT
then Result
:= CanRunLeft() else Result
:= CanRunRight();
6878 procedure Jump(Time
: Word = 30);
6880 PressKey(KEY_JUMP
, Time
);
6883 function NearHole(): Boolean;
6887 { TODO 5 : Ëåñòíèöû }
6888 sx
:= IfThen(RunDirection() = D_LEFT
, -1, 1);
6889 for x
:= 1 to PLAYER_RECT
.Width
do
6890 if (not StayOnStep(x
*sx
, 0)) and
6891 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
6892 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
6901 function BorderHole(): Boolean;
6905 { TODO 5 : Ëåñòíèöû }
6906 sx
:= IfThen(RunDirection() = D_LEFT
, -1, 1);
6907 for x
:= 1 to PLAYER_RECT
.Width
do
6908 if (not StayOnStep(x
*sx
, 0)) and
6909 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
6910 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
6912 for xx
:= x
to x
+32 do
6913 if CollideLevel(xx
*sx
, PLAYER_RECT
.Height
) then
6923 function NearDeepHole(): Boolean;
6929 sx
:= IfThen(RunDirection() = D_LEFT
, -1, 1);
6932 for x
:= 1 to PLAYER_RECT
.Width
do
6933 if (not StayOnStep(x
*sx
, 0)) and
6934 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
6935 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
6937 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
6939 if CollideLevel(x
*sx
, PLAYER_RECT
.Height
*y
) then Exit
;
6944 end else Result
:= False;
6947 function OverDeepHole(): Boolean;
6954 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
6956 if CollideLevel(0, PLAYER_RECT
.Height
*y
) then Exit
;
6963 function OnGround(): Boolean;
6965 Result
:= StayOnStep(0, 0) or CollideLevel(0, 1);
6968 function OnLadder(): Boolean;
6970 Result
:= FullInStep(0, 0);
6973 function BelowLadder(): Boolean;
6975 Result
:= (FullInStep(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) and
6976 not CollideLevel(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
6977 (FullInStep(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) and
6978 not CollideLevel(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
6981 function BelowLiftUp(): Boolean;
6983 Result
:= ((FullInLift(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) = -1) and
6984 not CollideLevel(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
6985 ((FullInLift(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) = -1) and
6986 not CollideLevel(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
6989 function OnTopLift(): Boolean;
6991 Result
:= (FullInLift(0, 0) = -1) and (FullInLift(0, -32) = 0);
6994 function CanJumpOver(): Boolean;
6998 sx
:= IfThen(RunDirection() = D_LEFT
, -1, 1);
7002 if not CollideLevel(sx
, 0) then Exit
;
7004 for y
:= 1 to BOT_MAXJUMP
do
7005 if CollideLevel(0, -y
) then Exit
else
7006 if not CollideLevel(sx
, -y
) then
7013 function CanJumpUp(Dist
: ShortInt): Boolean;
7020 if CollideLevel(Dist
, 0) then Exit
;
7023 for y
:= 0 to BOT_MAXJUMP
do
7024 if CollideLevel(Dist
, -y
) then
7033 for yy
:= y
+1 to BOT_MAXJUMP
do
7034 if not CollideLevel(Dist
, -yy
) then
7043 for y
:= 0 to BOT_MAXJUMP
do
7044 if CollideLevel(0, -y
) then
7052 if y
< yy
then Exit
;
7057 function IsSafeTrigger(): Boolean;
7062 if gTriggers
= nil then
7064 for a
:= 0 to High(gTriggers
) do
7065 if Collide(gTriggers
[a
].X
,
7068 gTriggers
[a
].Height
) and
7069 (gTriggers
[a
].TriggerType
in [TRIGGER_EXIT
, TRIGGER_CLOSEDOOR
,
7070 TRIGGER_CLOSETRAP
, TRIGGER_TRAP
,
7071 TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
,
7072 TRIGGER_ONOFF
, TRIGGER_SPAWNMONSTER
,
7073 TRIGGER_DAMAGE
, TRIGGER_SHOT
]) then
7078 // Âîçìîæíî, íàæèìàåì êíîïêó:
7079 if Rnd(16) and IsSafeTrigger() then
7082 // Åñëè ïîä ëèôòîì èëè ñòóïåíüêàìè, òî, âîçìîæíî, ïðûãàåì:
7083 if OnLadder() or ((BelowLadder() or BelowLiftUp()) and Rnd(8)) then
7085 ReleaseKey(KEY_LEFT
);
7086 ReleaseKey(KEY_RIGHT
);
7090 // Èäåì âëåâî, åñëè íàäî áûëî:
7091 if GetAIFlag('GOLEFT') <> '' then
7093 RemoveAIFlag('GOLEFT');
7094 if CanRunLeft() then
7098 // Èäåì âïðàâî, åñëè íàäî áûëî:
7099 if GetAIFlag('GORIGHT') <> '' then
7101 RemoveAIFlag('GORIGHT');
7102 if CanRunRight() then
7106 // Åñëè âûëåòåëè çà êàðòó, òî ïðîáóåì âåðíóòüñÿ:
7107 if FObj
.X
< -32 then
7110 if FObj
.X
+32 > gMapInfo
.Width
then
7113 // Ïðûãàåì, åñëè íàäî áûëî:
7114 if GetAIFlag('NEEDJUMP') <> '' then
7117 RemoveAIFlag('NEEDJUMP');
7120 // Ñìîòðèì ââåðõ, åñëè íàäî áûëî:
7121 if GetAIFlag('NEEDSEEUP') <> '' then
7124 ReleaseKey(KEY_DOWN
);
7125 PressKey(KEY_UP
, 20);
7126 RemoveAIFlag('NEEDSEEUP');
7129 // Ñìîòðèì âíèç, åñëè íàäî áûëî:
7130 if GetAIFlag('NEEDSEEDOWN') <> '' then
7133 ReleaseKey(KEY_DOWN
);
7134 PressKey(KEY_DOWN
, 20);
7135 RemoveAIFlag('NEEDSEEDOWN');
7138 // Åñëè íóæíî áûëî â äûðó è ìû íå íà çåìëå, òî ïîêîðíî ëåòèì:
7139 if GetAIFlag('GOINHOLE') <> '' then
7140 if not OnGround() then
7142 ReleaseKey(KEY_LEFT
);
7143 ReleaseKey(KEY_RIGHT
);
7144 RemoveAIFlag('GOINHOLE');
7145 SetAIFlag('FALLINHOLE', '1');
7148 // Åñëè ïàäàëè è äîñòèãëè çåìëè, òî õâàòèò ïàäàòü:
7149 if GetAIFlag('FALLINHOLE') <> '' then
7151 RemoveAIFlag('FALLINHOLE');
7153 // Åñëè ëåòåëè ïðÿìî è ñåé÷àñ íå íà ëåñòíèöå èëè íà âåðøèíå ëèôòà, òî îòõîäèì â ñòîðîíó:
7154 if not (KeyPressed(KEY_LEFT
) or KeyPressed(KEY_RIGHT
)) then
7155 if GetAIFlag('FALLINHOLE') = '' then
7156 if (not OnLadder()) or (FObj
.Vel
.Y
>= 0) or (OnTopLift()) then
7162 // Åñëè íà çåìëå è ìîæíî ïîäïðûãíóòü, òî, âîçìîæíî, ïðûãàåì:
7164 CanJumpUp(IfThen(RunDirection() = D_LEFT
, -1, 1)*32) and
7168 // Åñëè íà çåìëå è âîçëå äûðû (ãëóáèíà > 2 ðîñòîâ èãðîêà):
7169 if OnGround() and NearHole() then
7170 if NearDeepHole() then // Åñëè ýòî áåçäíà
7172 0..3: Turn(); // Áåæèì îáðàòíî
7173 4: Jump(); // Ïðûãàåì
7174 5: begin // Ïðûãàåì îáðàòíî
7179 else // Ýòî íå áåçäíà è ìû åùå íå ëåòèì òóäà
7180 if GetAIFlag('GOINHOLE') = '' then
7182 0: Turn(); // Íå íóæíî òóäà
7183 1: Jump(); // Âäðóã ïîâåçåò - ïðûãàåì
7184 else // Åñëè ÿìà ñ ãðàíèöåé, òî ïðè ñëó÷àå ìîæíî òóäà ïðûãíóòü
7185 if BorderHole() then
7186 SetAIFlag('GOINHOLE', '1');
7189 // Åñëè íà çåìëå, íî íåêóäà èäòè:
7190 if (not CanRun()) and OnGround() then
7192 // Åñëè ìû íà ëåñòíèöå èëè ìîæíî ïåðåïðûãíóòü, òî ïðûãàåì:
7193 if CanJumpOver() or OnLadder() then
7195 else // èíà÷å ïîïûòàåìñÿ â äðóãóþ ñòîðîíó
7196 if Random(2) = 0 then
7198 if IsSafeTrigger() then
7204 // Îñòàëîñü ìàëî âîçäóõà:
7205 if FAir
< 36 * 2 then
7208 // Âûáèðàåìñÿ èç êèñëîòû, åñëè íåò êîñòþìà, îáîæãëèñü, èëè ìàëî çäîðîâüÿ:
7209 if (FMegaRulez
[MR_SUIT
] < gTime
) and ((FLastHit
= HIT_ACID
) or (Healthy() <= 1)) then
7210 if BodyInAcid(0, 0) then
7214 function TBot
.FullInStep(XInc
, YInc
: Integer): Boolean;
7216 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
7217 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_STEP
, False);
7220 {function TBot.NeedItem(Item: Byte): Byte;
7225 procedure TBot
.SelectWeapon(Dist
: Integer);
7229 function HaveAmmo(weapon
: Byte): Boolean;
7232 WEAPON_PISTOL
: Result
:= FAmmo
[A_BULLETS
] >= 1;
7233 WEAPON_SHOTGUN1
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7234 WEAPON_SHOTGUN2
: Result
:= FAmmo
[A_SHELLS
] >= 2;
7235 WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
] >= 10;
7236 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
] >= 1;
7237 WEAPON_PLASMA
: Result
:= FAmmo
[A_CELLS
] >= 10;
7238 WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
] >= 40;
7239 WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7240 WEAPON_FLAMETHROWER
: Result
:= FAmmo
[A_FUEL
] >= 1;
7241 else Result
:= True;
7246 if Dist
= -1 then Dist
:= BOT_LONGDIST
;
7248 if Dist
> BOT_LONGDIST
then
7249 begin // Äàëüíèé áîé
7251 if FWeapon
[FDifficult
.WeaponPrior
[a
]] and HaveAmmo(FDifficult
.WeaponPrior
[a
]) then
7253 FSelectedWeapon
:= FDifficult
.WeaponPrior
[a
];
7257 else //if Dist > BOT_UNSAFEDIST then
7258 begin // Áëèæíèé áîé
7260 if FWeapon
[FDifficult
.CloseWeaponPrior
[a
]] and HaveAmmo(FDifficult
.CloseWeaponPrior
[a
]) then
7262 FSelectedWeapon
:= FDifficult
.CloseWeaponPrior
[a
];
7269 if FWeapon[FDifficult.SafeWeaponPrior[a]] and HaveAmmo(FDifficult.SafeWeaponPrior[a]) then
7271 FSelectedWeapon := FDifficult.SafeWeaponPrior[a];
7277 function TBot
.PickItem(ItemType
: Byte; force
: Boolean; var remove
: Boolean): Boolean;
7279 Result
:= inherited PickItem(ItemType
, force
, remove
);
7281 if Result
then SetAIFlag('SELECTWEAPON', '1');
7284 function TBot
.Heal(value
: Word; Soft
: Boolean): Boolean;
7286 Result
:= inherited Heal(value
, Soft
);
7289 function TBot
.Healthy(): Byte;
7291 if FMegaRulez
[MR_INVUL
] >= gTime
then Result
:= 3
7292 else if (FHealth
> 80) or ((FHealth
> 50) and (FArmor
> 20)) then Result
:= 3
7293 else if (FHealth
> 50) then Result
:= 2
7294 else if (FHealth
> 20) then Result
:= 1
7298 function TBot
.TargetOnScreen(TX
, TY
: Integer): Boolean;
7300 Result
:= (Abs(FObj
.X
-TX
) <= Trunc(gPlayerScreenSize
.X
*0.6)) and
7301 (Abs(FObj
.Y
-TY
) <= Trunc(gPlayerScreenSize
.Y
*0.6));
7304 procedure TBot
.OnDamage(Angle
: SmallInt);
7312 if (Angle
= 0) or (Angle
= 180) then
7315 if (g_GetUIDType(FLastSpawnerUID
) = UID_PLAYER
) and
7316 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
) then
7318 pla
:= g_Player_Get(FLastSpawnerUID
);
7319 ok
:= not TargetOnScreen(pla
.FObj
.X
+ PLAYER_RECT
.X
,
7320 pla
.FObj
.Y
+ PLAYER_RECT
.Y
);
7323 if (g_GetUIDType(FLastSpawnerUID
) = UID_MONSTER
) and
7324 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
) then
7326 mon
:= g_Monsters_Get(FLastSpawnerUID
);
7327 ok
:= not TargetOnScreen(mon
.Obj
.X
+ mon
.Obj
.Rect
.X
,
7328 mon
.Obj
.Y
+ mon
.Obj
.Rect
.Y
);
7333 SetAIFlag('ATTACKLEFT', '1')
7335 SetAIFlag('ATTACKRIGHT', '1');
7339 function TBot
.RunDirection(): TDirection
;
7341 if Abs(Vel
.X
) >= 1 then
7343 if Vel
.X
> 0 then Result
:= D_RIGHT
else Result
:= D_LEFT
;
7345 Result
:= FDirection
;
7348 function TBot
.GetRnd(a
: Byte): Boolean;
7350 if a
= 0 then Result
:= False
7351 else if a
= 255 then Result
:= True
7352 else Result
:= Random(256) > 255-a
;
7355 function TBot
.GetInterval(a
: Byte; radius
: SmallInt): SmallInt;
7357 Result
:= Round((255-a
)/255*radius
*(Random(2)-1));
7360 procedure TBot
.SaveState(var Mem
: TBinMemoryWriter
);
7366 inherited SaveState(Mem
);
7368 // Âûáðàííîå îðóæèå:
7369 Mem
.WriteByte(FSelectedWeapon
);
7371 Mem
.WriteWord(FTargetUID
);
7372 // Âðåìÿ ïîòåðè öåëè:
7373 Mem
.WriteDWORD(FLastVisible
);
7374 // Êîëè÷åñòâî ôëàãîâ ÈÈ:
7375 dw
:= Length(FAIFlags
);
7378 for i
:= 0 to Integer(dw
)-1 do
7380 Mem
.WriteString(FAIFlags
[i
].Name
, 20);
7381 Mem
.WriteString(FAIFlags
[i
].Value
, 20);
7383 // Íàñòðîéêè ñëîæíîñòè:
7385 Mem
.WriteMemory(p
, SizeOf(TDifficult
));
7388 procedure TBot
.LoadState(var Mem
: TBinMemoryReader
);
7394 inherited LoadState(Mem
);
7396 // Âûáðàííîå îðóæèå:
7397 Mem
.ReadByte(FSelectedWeapon
);
7399 Mem
.ReadWord(FTargetUID
);
7400 // Âðåìÿ ïîòåðè öåëè:
7401 Mem
.ReadDWORD(FLastVisible
);
7402 // Êîëè÷åñòâî ôëàãîâ ÈÈ:
7404 SetLength(FAIFlags
, dw
);
7406 for i
:= 0 to Integer(dw
)-1 do
7408 Mem
.ReadString(FAIFlags
[i
].Name
);
7409 Mem
.ReadString(FAIFlags
[i
].Value
);
7411 // Íàñòðîéêè ñëîæíîñòè:
7412 Mem
.ReadMemory(p
, dw
);
7413 if dw
<> SizeOf(TDifficult
) then
7415 raise EBinSizeError
.Create('TBot.LoadState: Wrong FDifficult Size');
7417 FDifficult
:= TDifficult(p
^);