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 begin FNextWeap
:= FNextWeap
and $1FFF; FNextWeapDelay
:= 0; end;
3360 // cycling has priority
3361 if (FNextWeap
and $C000) <> 0 then
3363 if (FNextWeap
and $8000) <> 0 then dir
:= 1 else dir
:= -1;
3364 FNextWeap
:= FNextWeap
or $2000; // we need this
3365 if FNextWeapDelay
> 0 then exit
; // cooldown time
3367 for i
:= 0 to High(FWeapon
) do
3369 cwi
:= (cwi
+length(FWeapon
)+dir
) mod length(FWeapon
);
3370 if FWeapon
[cwi
] then
3372 //e_WriteLog(Format(' SWITCH: cur=%d; new=%d', [FCurrWeap, cwi]), MSG_WARNING);
3373 result
:= Byte(cwi
);
3374 FNextWeapDelay
:= 10;
3382 for i
:= 0 to High(wantThisWeapon
) do wantThisWeapon
[i
] := false;
3383 for i
:= 0 to High(FWeapon
) do if (FNextWeap
and (1 shl i
)) <> 0 then begin wantThisWeapon
[i
] := true; Inc(wwc
); end;
3384 // exclude currently selected weapon from the set
3385 wantThisWeapon
[FCurrWeap
] := false;
3386 // slow down alterations a little
3389 //e_WriteLog(Format(' FNextWeap=%x; delay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
3390 // more than one weapon requested, assume "alteration" and check alteration delay
3391 if FNextWeapDelay
> 0 then begin FNextWeap
:= 0; exit
; end; // yeah
3393 // do not reset weapon queue, it will be done in `RealizeCurrentWeapon()`
3394 // but clear all counters if no weapon should be switched
3395 if wwc
< 1 then begin resetWeaponQueue(); exit
; end;
3396 //e_WriteLog(Format('wwc=%d', [wwc]), MSG_WARNING);
3397 // try weapons in descending order
3398 for i
:= High(FWeapon
) downto 0 do
3400 if wantThisWeapon
[i
] and FWeapon
[i
] and ((wwc
= 1) or hasAmmoForWeapon(i
)) then
3405 FNextWeapDelay
:= 10; // anyway, 'cause why not
3409 // no suitable weapon found, so reset the queue, to avoid accidental "queuing" of weapon w/o ammo
3413 procedure TPlayer
.RealizeCurrentWeapon();
3414 function switchAllowed (): Boolean;
3419 if FBFGFireCounter
<> -1 then
3421 if FTime
[T_SWITCH
] > gTime
then
3423 for i
:= WP_FIRST
to WP_LAST
do
3424 if FReloading
[i
] > 0 then
3432 //e_WriteLog(Format('***RealizeCurrentWeapon: FNextWeap=%x; FNextWeapDelay=%d', [FNextWeap, FNextWeapDelay]), MSG_WARNING);
3433 //FNextWeap := FNextWeap and $1FFF;
3434 if FNextWeapDelay
> 0 then Dec(FNextWeapDelay
); // "alteration delay"
3436 if not switchAllowed
then
3438 //HACK for weapon cycling
3439 if (FNextWeap
and $7000) <> 0 then FNextWeap
:= 0;
3443 nw
:= getNextWeaponIndex();
3444 if nw
= 255 then exit
; // don't reset anything here
3445 if nw
> High(FWeapon
) then
3447 // don't forget to reset queue here!
3448 //e_WriteLog(' RealizeCurrentWeapon: WUTAFUUUU', MSG_WARNING);
3456 FTime
[T_SWITCH
] := gTime
+156;
3457 if FCurrWeap
= WEAPON_SAW
then FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3458 FModel
.SetWeapon(FCurrWeap
);
3459 if g_Game_IsNet
then MH_SEND_PlayerStats(FUID
);
3463 procedure TPlayer
.NextWeapon();
3465 if g_Game_IsClient
then Exit
;
3469 procedure TPlayer
.PrevWeapon();
3471 if g_Game_IsClient
then Exit
;
3475 procedure TPlayer
.SetWeapon(W
: Byte);
3477 if FCurrWeap
<> W
then
3478 if W
= WEAPON_SAW
then
3479 FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3482 FModel
.SetWeapon(CurrWeap
);
3486 function TPlayer
.PickItem(ItemType
: Byte; respawn
: Boolean; var remove
: Boolean): Boolean;
3491 if g_Game_IsClient
then Exit
;
3493 // a = true - ìåñòî ñïàâíà ïðåäìåòà:
3494 a
:= LongBool(gGameSettings
.Options
and GAME_OPTION_WEAPONSTAY
) and respawn
;
3499 if FHealth
< PLAYER_HP_SOFT
then
3501 IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
3505 if gFlash
= 2 then Inc(FPickup
, 5);
3509 if FHealth
< PLAYER_HP_SOFT
then
3511 IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
3515 if gFlash
= 2 then Inc(FPickup
, 5);
3519 if FArmor
< PLAYER_AP_SOFT
then
3521 FArmor
:= PLAYER_AP_SOFT
;
3524 if gFlash
= 2 then Inc(FPickup
, 5);
3528 if FArmor
< PLAYER_AP_LIMIT
then
3530 FArmor
:= PLAYER_AP_LIMIT
;
3533 if gFlash
= 2 then Inc(FPickup
, 5);
3537 if FHealth
< PLAYER_HP_LIMIT
then
3539 IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
3543 if gFlash
= 2 then Inc(FPickup
, 5);
3547 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) then
3549 if FHealth
< PLAYER_HP_LIMIT
then
3550 FHealth
:= PLAYER_HP_LIMIT
;
3551 if FArmor
< PLAYER_AP_LIMIT
then
3552 FArmor
:= PLAYER_AP_LIMIT
;
3556 if gFlash
= 2 then Inc(FPickup
, 5);
3560 if (not FWeapon
[WEAPON_SAW
]) or ((not respawn
) and (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
])) then
3562 FWeapon
[WEAPON_SAW
] := True;
3564 if gFlash
= 2 then Inc(FPickup
, 5);
3565 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3568 ITEM_WEAPON_SHOTGUN1
:
3569 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN1
] then
3571 // Íóæíî, ÷òîáû íå âçÿòü âñå ïóëè ñðàçó:
3572 if a
and FWeapon
[WEAPON_SHOTGUN1
] then Exit
;
3574 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3575 FWeapon
[WEAPON_SHOTGUN1
] := True;
3577 if gFlash
= 2 then Inc(FPickup
, 5);
3578 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3581 ITEM_WEAPON_SHOTGUN2
:
3582 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN2
] then
3584 if a
and FWeapon
[WEAPON_SHOTGUN2
] then Exit
;
3586 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3587 FWeapon
[WEAPON_SHOTGUN2
] := True;
3589 if gFlash
= 2 then Inc(FPickup
, 5);
3590 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3593 ITEM_WEAPON_CHAINGUN
:
3594 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or not FWeapon
[WEAPON_CHAINGUN
] then
3596 if a
and FWeapon
[WEAPON_CHAINGUN
] then Exit
;
3598 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
3599 FWeapon
[WEAPON_CHAINGUN
] := True;
3601 if gFlash
= 2 then Inc(FPickup
, 5);
3602 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3605 ITEM_WEAPON_ROCKETLAUNCHER
:
3606 if (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or not FWeapon
[WEAPON_ROCKETLAUNCHER
] then
3608 if a
and FWeapon
[WEAPON_ROCKETLAUNCHER
] then Exit
;
3610 IncMax(FAmmo
[A_ROCKETS
], 2, FMaxAmmo
[A_ROCKETS
]);
3611 FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
3613 if gFlash
= 2 then Inc(FPickup
, 5);
3614 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3618 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_PLASMA
] then
3620 if a
and FWeapon
[WEAPON_PLASMA
] then Exit
;
3622 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3623 FWeapon
[WEAPON_PLASMA
] := True;
3625 if gFlash
= 2 then Inc(FPickup
, 5);
3626 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3630 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_BFG
] then
3632 if a
and FWeapon
[WEAPON_BFG
] then Exit
;
3634 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3635 FWeapon
[WEAPON_BFG
] := True;
3637 if gFlash
= 2 then Inc(FPickup
, 5);
3638 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3641 ITEM_WEAPON_SUPERPULEMET
:
3642 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SUPERPULEMET
] then
3644 if a
and FWeapon
[WEAPON_SUPERPULEMET
] then Exit
;
3646 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3647 FWeapon
[WEAPON_SUPERPULEMET
] := True;
3649 if gFlash
= 2 then Inc(FPickup
, 5);
3650 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3653 ITEM_WEAPON_FLAMETHROWER
:
3654 if (FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
]) or not FWeapon
[WEAPON_FLAMETHROWER
] then
3656 if a
and FWeapon
[WEAPON_FLAMETHROWER
] then Exit
;
3658 IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
3659 FWeapon
[WEAPON_FLAMETHROWER
] := True;
3661 if gFlash
= 2 then Inc(FPickup
, 5);
3662 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3666 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
3668 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
3671 if gFlash
= 2 then Inc(FPickup
, 5);
3674 ITEM_AMMO_BULLETS_BOX
:
3675 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
3677 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
3680 if gFlash
= 2 then Inc(FPickup
, 5);
3684 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
3686 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3689 if gFlash
= 2 then Inc(FPickup
, 5);
3692 ITEM_AMMO_SHELLS_BOX
:
3693 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
3695 IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
3698 if gFlash
= 2 then Inc(FPickup
, 5);
3702 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
3704 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
3707 if gFlash
= 2 then Inc(FPickup
, 5);
3710 ITEM_AMMO_ROCKET_BOX
:
3711 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
3713 IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
3716 if gFlash
= 2 then Inc(FPickup
, 5);
3720 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
3722 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3725 if gFlash
= 2 then Inc(FPickup
, 5);
3729 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
3731 IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
3734 if gFlash
= 2 then Inc(FPickup
, 5);
3738 if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then
3740 IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
3743 if gFlash
= 2 then Inc(FPickup
, 5);
3747 if not(R_ITEM_BACKPACK
in FRulez
) or
3748 (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
3749 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
3750 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
3751 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or
3752 (FMaxAmmo
[A_FUEL
] < AmmoLimits
[1, A_FUEL
]) then
3754 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[1, A_BULLETS
];
3755 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[1, A_SHELLS
];
3756 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[1, A_ROCKETS
];
3757 FMaxAmmo
[A_CELLS
] := AmmoLimits
[1, A_CELLS
];
3758 FMaxAmmo
[A_FUEL
] := AmmoLimits
[1, A_FUEL
];
3760 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
3761 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
3762 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
3763 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3764 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
3765 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
3766 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
3767 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3769 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
3772 if gFlash
= 2 then Inc(FPickup
, 5);
3776 if not(R_KEY_RED
in FRulez
) then
3778 Include(FRulez
, R_KEY_RED
);
3780 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
3781 if gFlash
= 2 then Inc(FPickup
, 5);
3782 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
3786 if not(R_KEY_GREEN
in FRulez
) then
3788 Include(FRulez
, R_KEY_GREEN
);
3790 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
3791 if gFlash
= 2 then Inc(FPickup
, 5);
3792 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
3796 if not(R_KEY_BLUE
in FRulez
) then
3798 Include(FRulez
, R_KEY_BLUE
);
3800 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
3801 if gFlash
= 2 then Inc(FPickup
, 5);
3802 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
3806 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
3808 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
3812 if gFlash
= 2 then Inc(FPickup
, 5);
3816 if FAir
< AIR_MAX
then
3821 if gFlash
= 2 then Inc(FPickup
, 5);
3826 if not (R_BERSERK
in FRulez
) then
3828 Include(FRulez
, R_BERSERK
);
3829 if FBFGFireCounter
= -1 then
3831 FCurrWeap
:= WEAPON_KASTET
;
3833 FModel
.SetWeapon(WEAPON_KASTET
);
3837 if gFlash
= 2 then Inc(FPickup
, 5);
3838 FBerserk
:= gTime
+30000;
3843 if FHealth
< PLAYER_HP_SOFT
then
3845 FHealth
:= PLAYER_HP_SOFT
;
3846 FBerserk
:= gTime
+30000;
3854 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
3856 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
3859 if gFlash
= 2 then Inc(FPickup
, 5);
3863 if FHealth
< PLAYER_HP_LIMIT
then
3865 IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
3869 if gFlash
= 2 then Inc(FPickup
, 5);
3873 if FArmor
< PLAYER_AP_LIMIT
then
3875 IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
3878 if gFlash
= 2 then Inc(FPickup
, 5);
3882 if FJetFuel
< JET_MAX
then
3884 FJetFuel
:= JET_MAX
;
3887 if gFlash
= 2 then Inc(FPickup
, 5);
3891 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
3893 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
3896 if gFlash
= 2 then Inc(FPickup
, 5);
3901 procedure TPlayer
.Touch();
3905 //FModel.PlaySound(MODELSOUND_PAIN, 1, FObj.X, FObj.Y);
3908 // Áðîñèòü ôëàã òîâàðèùó:
3909 if gGameSettings
.GameMode
= GM_CTF
then
3914 procedure TPlayer
.Push(vx
, vy
: Integer);
3916 if (not FPhysics
) and FGhost
then
3918 FObj
.Accel
.X
:= FObj
.Accel
.X
+ vx
;
3919 FObj
.Accel
.Y
:= FObj
.Accel
.Y
+ vy
;
3920 if g_Game_IsNet
and g_Game_IsServer
then
3921 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
3924 procedure TPlayer
.Reset(Force
: Boolean);
3930 FTime
[T_RESPAWN
] := 0;
3931 FTime
[T_FLAGCAP
] := 0;
3944 FSpectator
:= False;
3947 FSpectatePlayer
:= -1;
3948 FNoRespawn
:= False;
3950 FLives
:= gGameSettings
.MaxLives
;
3955 procedure TPlayer
.SoftReset();
3961 FBFGFireCounter
:= -1;
3969 SetAction(A_STAND
, True);
3972 function TPlayer
.GetRespawnPoint(): Byte;
3977 // Íà áóäóùåå: FSpawn - èãðîê óæå èãðàë è ïåðåðîæäàåòñÿ
3979 // Îäèíî÷íàÿ èãðà/êîîïåðàòèâ
3980 if gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
] then
3982 if (Self
= gPlayer1
) or (Self
= gPlayer2
) then
3984 // Òî÷êà ïîÿâëåíèÿ ñâîåãî èãðîêà
3985 if Self
= gPlayer1
then
3986 c
:= RESPAWNPOINT_PLAYER1
3988 c
:= RESPAWNPOINT_PLAYER2
;
3989 if g_Map_GetPointCount(c
) > 0 then
3995 // Òî÷êà ïîÿâëåíèÿ äðóãîãî èãðîêà
3996 if Self
= gPlayer1
then
3997 c
:= RESPAWNPOINT_PLAYER2
3999 c
:= RESPAWNPOINT_PLAYER1
;
4000 if g_Map_GetPointCount(c
) > 0 then
4007 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà (áîòà)
4008 if Random(2) = 0 then
4009 c
:= RESPAWNPOINT_PLAYER1
4011 c
:= RESPAWNPOINT_PLAYER2
;
4012 if g_Map_GetPointCount(c
) > 0 then
4019 // Òî÷êà ëþáîé èç êîìàíä
4020 if Random(2) = 0 then
4021 c
:= RESPAWNPOINT_RED
4023 c
:= RESPAWNPOINT_BLUE
;
4024 if g_Map_GetPointCount(c
) > 0 then
4031 c
:= RESPAWNPOINT_DM
;
4032 if g_Map_GetPointCount(c
) > 0 then
4040 if gGameSettings
.GameMode
= GM_DM
then
4043 c
:= RESPAWNPOINT_DM
;
4044 if g_Map_GetPointCount(c
) > 0 then
4050 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà
4051 if Random(2) = 0 then
4052 c
:= RESPAWNPOINT_PLAYER1
4054 c
:= RESPAWNPOINT_PLAYER2
;
4055 if g_Map_GetPointCount(c
) > 0 then
4061 // Òî÷êà ëþáîé èç êîìàíä
4062 if Random(2) = 0 then
4063 c
:= RESPAWNPOINT_RED
4065 c
:= RESPAWNPOINT_BLUE
;
4066 if g_Map_GetPointCount(c
) > 0 then
4074 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
4076 // Òî÷êà ñâîåé êîìàíäû
4077 c
:= RESPAWNPOINT_DM
;
4078 if FTeam
= TEAM_RED
then
4079 c
:= RESPAWNPOINT_RED
;
4080 if FTeam
= TEAM_BLUE
then
4081 c
:= RESPAWNPOINT_BLUE
;
4082 if g_Map_GetPointCount(c
) > 0 then
4089 c
:= RESPAWNPOINT_DM
;
4090 if g_Map_GetPointCount(c
) > 0 then
4096 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà
4097 if Random(2) = 0 then
4098 c
:= RESPAWNPOINT_PLAYER1
4100 c
:= RESPAWNPOINT_PLAYER2
;
4101 if g_Map_GetPointCount(c
) > 0 then
4107 // Òî÷êà äðóãîé êîìàíäû
4108 c
:= RESPAWNPOINT_DM
;
4109 if FTeam
= TEAM_RED
then
4110 c
:= RESPAWNPOINT_BLUE
;
4111 if FTeam
= TEAM_BLUE
then
4112 c
:= RESPAWNPOINT_RED
;
4113 if g_Map_GetPointCount(c
) > 0 then
4121 procedure TPlayer
.Respawn(Silent
: Boolean; Force
: Boolean = False);
4123 RespawnPoint
: TRespawnPoint
;
4128 if not g_Game_IsServer
then
4132 FWantsInGame
:= True;
4133 FJustTeleported
:= True;
4136 FTime
[T_RESPAWN
] := 0;
4140 // if server changes MaxLives we gotta be ready
4141 if gGameSettings
.MaxLives
= 0 then FNoRespawn
:= False;
4143 // Åùå íåëüçÿ âîçðîäèòüñÿ:
4144 if FTime
[T_RESPAWN
] > gTime
then
4147 // Ïðîñðàë âñå æèçíè:
4150 if not FSpectator
then Spectate(True);
4151 FWantsInGame
:= True;
4155 if (gGameSettings
.GameType
<> GT_SINGLE
) and (gGameSettings
.GameMode
<> GM_COOP
) then
4156 begin // "Ñâîÿ èãðà"
4157 // Áåðñåðê íå ñîõðàíÿåòñÿ ìåæäó óðîâíÿìè:
4158 FRulez
:= FRulez
-[R_BERSERK
];
4160 else // "Îäèíî÷íàÿ èãðà"/"Êîîï"
4162 // Áåðñåðê è êëþ÷è íå ñîõðàíÿþòñÿ ìåæäó óðîâíÿìè:
4163 FRulez
:= FRulez
-[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
, R_BERSERK
];
4166 // Ïîëó÷àåì òî÷êó ñïàóíà èãðîêà:
4167 c
:= GetRespawnPoint();
4172 // Âîñêðåøåíèå áåç îðóæèÿ:
4175 FHealth
:= PLAYER_HP_SOFT
;
4181 for a
:= WP_FIRST
to WP_LAST
do
4183 FWeapon
[a
] := False;
4187 FWeapon
[WEAPON_PISTOL
] := True;
4188 FWeapon
[WEAPON_KASTET
] := True;
4189 FCurrWeap
:= WEAPON_PISTOL
;
4192 FModel
.SetWeapon(FCurrWeap
);
4194 for b
:= A_BULLETS
to A_HIGH
do
4197 FAmmo
[A_BULLETS
] := 50;
4199 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[0, A_BULLETS
];
4200 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[0, A_SHELLS
];
4201 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[0, A_SHELLS
];
4202 FMaxAmmo
[A_CELLS
] := AmmoLimits
[0, A_CELLS
];
4203 FMaxAmmo
[A_FUEL
] := AmmoLimits
[0, A_FUEL
];
4205 if gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
] then
4206 FRulez
:= [R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
]
4211 // Ïîëó÷àåì êîîðäèíàòû òî÷êè âîçðîæäåíèÿ:
4212 if not g_Map_GetPoint(c
, RespawnPoint
) then
4214 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
4218 // Óñòàíîâêà êîîðäèíàò è ñáðîñ âñåõ ïàðàìåòðîâ:
4219 FObj
.X
:= RespawnPoint
.X
-PLAYER_RECT
.X
;
4220 FObj
.Y
:= RespawnPoint
.Y
-PLAYER_RECT
.Y
;
4226 FDirection
:= RespawnPoint
.Direction
;
4227 if FDirection
= D_LEFT
then
4233 FBFGFireCounter
:= -1;
4238 SetAction(A_STAND
, True);
4239 FModel
.Direction
:= FDirection
;
4241 for a
:= Low(FTime
) to High(FTime
) do
4244 for a
:= Low(FMegaRulez
) to High(FMegaRulez
) do
4249 FCanJetpack
:= False;
4254 // Àíèìàöèÿ âîçðîæäåíèÿ:
4255 if (not gLoadGameMode
) and (not Silent
) then
4256 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
4258 Anim
:= TAnimation
.Create(ID
, False, 3);
4259 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4260 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4264 FSpectator
:= False;
4267 FSpectatePlayer
:= -1;
4270 if g_Game_IsNet
then
4272 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
4273 MH_SEND_PlayerStats(FUID
, NET_EVERYONE
);
4275 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4276 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32,
4281 procedure TPlayer
.Spectate(NoMove
: Boolean = False);
4284 Kill(K_EXTRAHARDKILL
, FUID
, HIT_SOME
)
4285 else if (not NoMove
) then
4287 GameX
:= gMapInfo
.Width
div 2;
4288 GameY
:= gMapInfo
.Height
div 2;
4297 FWantsInGame
:= False;
4302 if Self
= gPlayer1
then
4307 if Self
= gPlayer2
then
4314 if g_Game_IsNet
then
4315 MH_SEND_PlayerStats(FUID
);
4318 procedure TPlayer
.SwitchNoClip
;
4322 FGhost
:= not FGhost
;
4323 FPhysics
:= not FGhost
;
4335 procedure TPlayer
.Run(Direction
: TDirection
);
4339 if MAX_RUNVEL
> 8 then
4343 if Direction
= D_LEFT
then
4345 if FObj
.Vel
.X
> -MAX_RUNVEL
then
4346 FObj
.Vel
.X
:= FObj
.Vel
.X
- (MAX_RUNVEL
shr 3);
4349 if FObj
.Vel
.X
< MAX_RUNVEL
then
4350 FObj
.Vel
.X
:= FObj
.Vel
.X
+ (MAX_RUNVEL
shr 3);
4352 // Âîçìîæíî, ïèíàåì êóñêè:
4353 if (FObj
.Vel
.X
<> 0) and (gGibs
<> nil) then
4355 b
:= Abs(FObj
.Vel
.X
);
4356 if b
> 1 then b
:= b
* (Random(8 div b
) + 1);
4357 for a
:= 0 to High(gGibs
) do
4358 if gGibs
[a
].Live
and
4359 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
+FObj
.Rect
.Height
-4,
4360 FObj
.Rect
.Width
, 8, @gGibs
[a
].Obj
) and (Random(3) = 0) then
4362 if FObj
.Vel
.X
< 0 then
4363 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)+120) // íàëåâî
4365 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)); // íàïðàâî
4371 procedure TPlayer
.SeeDown();
4373 SetAction(A_SEEDOWN
);
4375 if FDirection
= D_LEFT
then FAngle
:= ANGLE_LEFTDOWN
else FAngle
:= ANGLE_RIGHTDOWN
;
4377 if FIncCam
> -120 then DecMin(FIncCam
, 5, -120);
4380 procedure TPlayer
.SeeUp();
4384 if FDirection
= D_LEFT
then FAngle
:= ANGLE_LEFTUP
else FAngle
:= ANGLE_RIGHTUP
;
4386 if FIncCam
< 120 then IncMax(FIncCam
, 5, 120);
4389 procedure TPlayer
.SetAction(Action
: Byte; Force
: Boolean = False);
4397 A_ATTACK
: Prior
:= 2;
4398 A_SEEUP
: Prior
:= 1;
4399 A_SEEDOWN
: Prior
:= 1;
4400 A_ATTACKUP
: Prior
:= 2;
4401 A_ATTACKDOWN
: Prior
:= 2;
4406 if (Prior
> FActionPrior
) or Force
then
4407 if not ((Prior
= 2) and (FCurrWeap
= WEAPON_SAW
)) then
4409 FActionPrior
:= Prior
;
4410 FActionAnim
:= Action
;
4411 FActionForce
:= Force
;
4412 FActionChanged
:= True;
4415 if Action
in [A_ATTACK
, A_ATTACKUP
, A_ATTACKDOWN
] then FModel
.SetFire(True);
4418 function TPlayer
.StayOnStep(XInc
, YInc
: Integer): Boolean;
4420 Result
:= not g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
-1,
4421 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False)
4422 and g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
,
4423 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False);
4426 function TPlayer
.TeleportTo(X
, Y
: Integer; silent
: Boolean; dir
: Byte): Boolean;
4433 if g_CollideLevel(X
, Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
) then
4435 g_Sound_PlayExAt('SOUND_GAME_NOTELEPORT', FObj
.X
, FObj
.Y
);
4436 if g_Game_IsServer
and g_Game_IsNet
then
4437 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_GAME_NOTELEPORT');
4441 FJustTeleported
:= True;
4446 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
4448 Anim
:= TAnimation
.Create(ID
, False, 3);
4451 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', FObj
.X
, FObj
.Y
);
4452 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4453 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4454 if g_Game_IsServer
and g_Game_IsNet
then
4455 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4456 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 1,
4460 FObj
.X
:= X
-PLAYER_RECT
.X
;
4461 FObj
.Y
:= Y
-PLAYER_RECT
.Y
;
4462 if FLive
and FGhost
then
4468 if not g_Game_IsNet
then
4472 SetDirection(D_LEFT
);
4478 SetDirection(D_RIGHT
);
4484 if FDirection
= D_RIGHT
then
4486 SetDirection(D_LEFT
);
4491 SetDirection(D_RIGHT
);
4497 if not silent
and (Anim
<> nil) then
4499 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4500 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4503 if g_Game_IsServer
and g_Game_IsNet
then
4504 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4505 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 0,
4512 function nonz(a
: Single): Single;
4520 procedure TPlayer
.Update();
4523 i
, ii
, wx
, wy
, xd
, yd
, k
: Integer;
4524 blockmon
, headwater
, dospawn
: Boolean;
4529 NetServer
:= g_Game_IsNet
and g_Game_IsServer
;
4530 AnyServer
:= g_Game_IsServer
;
4532 if g_Game_IsClient
and (NetInterpLevel
> 0) then
4533 DoLerp(NetInterpLevel
+ 1)
4539 if FClientID
>= 0 then
4541 FPing
:= NetClients
[FClientID
].Peer
^.lastRoundTripTime
;
4542 if NetClients
[FClientID
].Peer
^.packetsSent
> 0 then
4543 FLoss
:= Round(100*NetClients
[FClientID
].Peer
^.packetsLost
/NetClients
[FClientID
].Peer
^.packetsSent
)
4552 if FLive
and (gFly
or FJetpack
) then
4555 if FDirection
= D_LEFT
then
4560 if FLive
and (not FGhost
) then
4562 if FKeys
[KEY_UP
].Pressed
then
4564 if FKeys
[KEY_DOWN
].Pressed
then
4568 if (not (FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_DOWN
].Pressed
)) and
4571 i
:= g_basic
.Sign(FIncCam
);
4572 FIncCam
:= Abs(FIncCam
);
4573 DecMin(FIncCam
, 5, 0);
4574 FIncCam
:= FIncCam
*i
;
4577 // no need to do that each second frame, weapon queue will take care of it
4578 if FLive
and FKeys
[KEY_NEXTWEAPON
].Pressed
and AnyServer
then NextWeapon();
4579 if FLive
and FKeys
[KEY_PREVWEAPON
].Pressed
and AnyServer
then PrevWeapon();
4581 if gTime
mod (GAME_TICK
*2) <> 0 then
4583 if (FObj
.Vel
.X
= 0) and FLive
then
4585 if FKeys
[KEY_LEFT
].Pressed
then
4587 if FKeys
[KEY_RIGHT
].Pressed
then
4592 g_Obj_Move(@FObj
, True, True, True);
4597 FActionChanged
:= False;
4601 // Let alive player do some actions
4602 if FKeys
[KEY_LEFT
].Pressed
then Run(D_LEFT
);
4603 if FKeys
[KEY_RIGHT
].Pressed
then Run(D_RIGHT
);
4604 //if FKeys[KEY_NEXTWEAPON].Pressed and AnyServer then NextWeapon();
4605 //if FKeys[KEY_PREVWEAPON].Pressed and AnyServer then PrevWeapon();
4606 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then Fire();
4607 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Use();
4608 if FKeys
[KEY_JUMP
].Pressed
then Jump()
4611 if AnyServer
and FJetpack
then
4615 if NetServer
then MH_SEND_PlayerStats(FUID
);
4617 FCanJetpack
:= True;
4624 for k
:= Low(FKeys
) to KEY_CHAT
-1 do
4626 if FKeys
[k
].Pressed
then
4634 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
4637 if (FTime
[T_RESPAWN
] <= gTime
) and
4638 gGameOn
and (not FLive
) then
4640 if (g_Player_GetCount() > 1) then
4644 gExit
:= EXIT_RESTART
;
4649 // Dead spectator actions
4652 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Fire();
4653 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then
4657 if (FSpectatePlayer
>= High(gPlayers
)) then
4658 FSpectatePlayer
:= -1
4662 for I
:= FSpectatePlayer
+ 1 to High(gPlayers
) do
4663 if gPlayers
[I
] <> nil then
4664 if gPlayers
[I
].Live
then
4665 if gPlayers
[I
].UID
<> FUID
then
4667 FSpectatePlayer
:= I
;
4672 if not SetSpect
then FSpectatePlayer
:= -1;
4683 if FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_JUMP
].Pressed
then
4685 FYTo
:= FObj
.Y
- 32;
4686 FSpectatePlayer
:= -1;
4688 if FKeys
[KEY_DOWN
].Pressed
then
4690 FYTo
:= FObj
.Y
+ 32;
4691 FSpectatePlayer
:= -1;
4693 if FKeys
[KEY_LEFT
].Pressed
then
4695 FXTo
:= FObj
.X
- 32;
4696 FSpectatePlayer
:= -1;
4698 if FKeys
[KEY_RIGHT
].Pressed
then
4700 FXTo
:= FObj
.X
+ 32;
4701 FSpectatePlayer
:= -1;
4704 if (FXTo
< -64) then
4706 else if (FXTo
> gMapInfo
.Width
+ 32) then
4707 FXTo
:= gMapInfo
.Width
+ 32;
4708 if (FYTo
< -72) then
4710 else if (FYTo
> gMapInfo
.Height
+ 32) then
4711 FYTo
:= gMapInfo
.Height
+ 32;
4715 g_Obj_Move(@FObj
, True, True, True)
4721 if (FSpectatePlayer
<= High(gPlayers
)) and (FSpectatePlayer
>= 0) then
4722 if gPlayers
[FSpectatePlayer
] <> nil then
4723 if gPlayers
[FSpectatePlayer
].Live
then
4725 FXTo
:= gPlayers
[FSpectatePlayer
].GameX
;
4726 FYTo
:= gPlayers
[FSpectatePlayer
].GameY
;
4730 blockmon
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
, FObj
.Y
+PLAYER_HEADRECT
.Y
,
4731 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
4732 PANEL_BLOCKMON
, True);
4733 headwater
:= HeadInLiquid(0, 0);
4735 // Ñîïðîòèâëåíèå âîçäóõà:
4736 if (not FLive
) or not (FKeys
[KEY_LEFT
].Pressed
or FKeys
[KEY_RIGHT
].Pressed
) then
4737 if FObj
.Vel
.X
<> 0 then
4738 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
4740 if (FLastHit
= HIT_TRAP
) and (FPain
> 90) then FPain
:= 90;
4741 DecMin(FPain
, 5, 0);
4742 DecMin(FPickup
, 1, 0);
4744 if FLive
and (FObj
.Y
> gMapInfo
.Height
+128) and AnyServer
then
4746 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
4747 FMegaRulez
[MR_SUIT
] := 0;
4748 FMegaRulez
[MR_INVUL
] := 0;
4749 FMegaRulez
[MR_INVIS
] := 0;
4750 Kill(K_FALLKILL
, 0, HIT_FALL
);
4757 if FCurrWeap
= WEAPON_SAW
then
4758 if not (FSawSound
.IsPlaying() or FSawSoundHit
.IsPlaying() or
4759 FSawSoundSelect
.IsPlaying()) then
4760 FSawSoundIdle
.PlayAt(FObj
.X
, FObj
.Y
);
4763 if (not FJetSoundFly
.IsPlaying()) and (not FJetSoundOn
.IsPlaying()) and
4764 (not FJetSoundOff
.IsPlaying()) then
4766 FJetSoundFly
.SetPosition(0);
4767 FJetSoundFly
.PlayAt(FObj
.X
, FObj
.Y
);
4770 for b
:= WP_FIRST
to WP_LAST
do
4771 if FReloading
[b
] > 0 then
4777 if FShellTimer
> -1 then
4778 if FShellTimer
= 0 then
4780 if FShellType
= SHELL_SHELL
then
4781 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
4782 GameVelX
, GameVelY
-2, SHELL_SHELL
)
4783 else if FShellType
= SHELL_DBLSHELL
then
4785 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
4786 GameVelX
+1, GameVelY
-2, SHELL_SHELL
);
4787 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
4788 GameVelX
-1, GameVelY
-2, SHELL_SHELL
);
4791 end else Dec(FShellTimer
);
4793 if (FBFGFireCounter
> -1) then
4794 if FBFGFireCounter
= 0 then
4798 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
4799 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
4800 xd
:= wx
+IfThen(FDirection
= D_LEFT
, -30, 30);
4801 yd
:= wy
+firediry();
4802 g_Weapon_bfgshot(wx
, wy
, xd
, yd
, FUID
);
4803 if NetServer
then MH_SEND_PlayerFire(FUID
, WEAPON_BFG
, wx
, wy
, xd
, yd
);
4804 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
4805 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
4806 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
4809 FReloading
[WEAPON_BFG
] := WEAPON_RELOAD
[WEAPON_BFG
];
4810 FBFGFireCounter
:= -1;
4813 FBFGFireCounter
:= 0
4815 Dec(FBFGFireCounter
);
4817 if (FMegaRulez
[MR_SUIT
] < gTime
) and AnyServer
then
4819 b
:= g_GetAcidHit(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
);
4821 if (b
> 0) and (gTime
mod (15*GAME_TICK
) = 0) then Damage(b
, 0, 0, 0, HIT_ACID
);
4824 if (headwater
or blockmon
) then
4830 if AnyServer
then Damage(10, 0, 0, 0, HIT_WATER
);
4833 else if (FAir
mod 31 = 0) and not blockmon
then
4835 g_GFX_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2), FObj
.Y
+PLAYER_RECT
.Y
-4, 5+Random(6), 8, 4);
4836 if Random(2) = 0 then
4837 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
4839 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
4841 end else if FAir
< AIR_DEF
then
4844 if FFireTime
> 0 then
4846 if BodyInLiquid(0, 0) then
4851 else if FMegaRulez
[MR_SUIT
] >= gTime
then
4853 if FMegaRulez
[MR_SUIT
] = gTime
then
4860 if FFirePainTime
<= 0 then
4862 if g_Game_IsServer
then
4863 Damage(5, FFireAttacker
, 0, 0, HIT_FLAME
);
4864 FFirePainTime
:= 18;
4866 FFirePainTime
:= FFirePainTime
- 1;
4867 FFireTime
:= FFireTime
- 1;
4868 if (FFireTime
= 0) and g_Game_IsNet
and g_Game_IsServer
then
4869 MH_SEND_PlayerStats(FUID
);
4873 if FDamageBuffer
> 0 then
4875 if FDamageBuffer
>= 9 then
4879 if FDamageBuffer
< 30 then i
:= 9
4880 else if FDamageBuffer
< 100 then i
:= 18
4884 ii
:= Round(FDamageBuffer
*FHealth
/ nonz(FArmor
*(3/4)+FHealth
));
4885 FArmor
:= FArmor
-(FDamageBuffer
-ii
);
4886 FHealth
:= FHealth
-ii
;
4889 FHealth
:= FHealth
+FArmor
;
4894 if FHealth
<= 0 then
4895 if FHealth
> -30 then Kill(K_SIMPLEKILL
, FLastSpawnerUID
, FLastHit
)
4896 else if FHealth
> -50 then Kill(K_HARDKILL
, FLastSpawnerUID
, FLastHit
)
4897 else Kill(K_EXTRAHARDKILL
, FLastSpawnerUID
, FLastHit
);
4901 if FDamageBuffer
<= 20 then FModel
.PlaySound(MODELSOUND_PAIN
, 1, FObj
.X
, FObj
.Y
)
4902 else if FDamageBuffer
<= 55 then FModel
.PlaySound(MODELSOUND_PAIN
, 2, FObj
.X
, FObj
.Y
)
4903 else if FDamageBuffer
<= 120 then FModel
.PlaySound(MODELSOUND_PAIN
, 3, FObj
.X
, FObj
.Y
)
4904 else FModel
.PlaySound(MODELSOUND_PAIN
, 4, FObj
.X
, FObj
.Y
);
4911 end; // if FLive then ...
4913 if (FActionAnim
= A_PAIN
) and (FModel
.Animation
<> A_PAIN
) then
4915 FModel
.ChangeAnimation(FActionAnim
, FActionForce
);
4916 FModel
.GetCurrentAnimation
.MinLength
:= i
;
4917 FModel
.GetCurrentAnimationMask
.MinLength
:= i
;
4918 end else FModel
.ChangeAnimation(FActionAnim
, FActionForce
and (FModel
.Animation
<> A_STAND
));
4920 if (FModel
.GetCurrentAnimation
.Played
or ((not FActionChanged
) and (FModel
.Animation
= A_WALK
)))
4921 then SetAction(A_STAND
, True);
4923 if not ((FModel
.Animation
= A_WALK
) and (Abs(FObj
.Vel
.X
) < 4) and not FModel
.Fire
) then FModel
.Update
;
4925 for b
:= Low(FKeys
) to High(FKeys
) do
4926 if FKeys
[b
].Time
= 0 then FKeys
[b
].Pressed
:= False else Dec(FKeys
[b
].Time
);
4929 function TPlayer
.Collide(X
, Y
: Integer; Width
, Height
: Word): Boolean;
4931 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
4932 FObj
.Y
+PLAYER_RECT
.Y
,
4939 function TPlayer
.Collide(Panel
: TPanel
): Boolean;
4941 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
4942 FObj
.Y
+PLAYER_RECT
.Y
,
4946 Panel
.Width
, Panel
.Height
);
4949 function TPlayer
.Collide(X
, Y
: Integer): Boolean;
4951 X
:= X
-FObj
.X
-PLAYER_RECT
.X
;
4952 Y
:= Y
-FObj
.Y
-PLAYER_RECT
.Y
;
4953 Result
:= (x
>= 0) and (x
<= PLAYER_RECT
.Width
) and
4954 (y
>= 0) and (y
<= PLAYER_RECT
.Height
);
4957 function g_Player_ValidName(Name
: string): Boolean;
4963 if gPlayers
= nil then Exit
;
4965 for a
:= 0 to High(gPlayers
) do
4966 if gPlayers
[a
] <> nil then
4967 if LowerCase(Name
) = LowerCase(gPlayers
[a
].FName
) then
4974 procedure TPlayer
.SetDirection(Direction
: TDirection
);
4978 d
:= FModel
.Direction
;
4980 FModel
.Direction
:= Direction
;
4981 if d
<> Direction
then FModel
.ChangeAnimation(FModel
.Animation
, True);
4983 FDirection
:= Direction
;
4986 function TPlayer
.GetKeys(): Byte;
4990 if R_KEY_RED
in FRulez
then Result
:= KEY_RED
;
4991 if R_KEY_GREEN
in FRulez
then Result
:= Result
or KEY_GREEN
;
4992 if R_KEY_BLUE
in FRulez
then Result
:= Result
or KEY_BLUE
;
4994 if FTeam
= TEAM_RED
then Result
:= Result
or KEY_REDTEAM
;
4995 if FTeam
= TEAM_BLUE
then Result
:= Result
or KEY_BLUETEAM
;
4998 procedure TPlayer
.Use();
5002 if FTime
[T_USE
] > gTime
then Exit
;
5004 g_Triggers_PressR(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
,
5005 PLAYER_RECT
.Height
, FUID
, ACTIVATE_PLAYERPRESS
);
5007 for a
:= 0 to High(gPlayers
) do
5008 if (gPlayers
[a
] <> nil) and (gPlayers
[a
] <> Self
) and
5009 gPlayers
[a
].Live
and SameTeam(FUID
, gPlayers
[a
].FUID
) and
5010 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
5011 FObj
.Rect
.Width
, FObj
.Rect
.Height
, @gPlayers
[a
].FObj
) then
5013 gPlayers
[a
].Touch();
5014 if g_Game_IsNet
and g_Game_IsServer
then
5015 MH_SEND_GameEvent(NET_EV_PLAYER_TOUCH
, gPlayers
[a
].FUID
);
5018 FTime
[T_USE
] := gTime
+120;
5021 procedure TPlayer
.NetFire(Wpn
: Byte; X
, Y
, AX
, AY
: Integer; WID
: Integer = -1);
5025 WX
, WY
, XD
, YD
: Integer;
5036 if R_BERSERK
in FRulez
then
5038 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
5039 obj
.X
:= FObj
.X
+FObj
.Rect
.X
;
5040 obj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
5043 obj
.rect
.Width
:= 39;
5044 obj
.rect
.Height
:= 52;
5045 obj
.Vel
.X
:= (xd
-wx
) div 2;
5046 obj
.Vel
.Y
:= (yd
-wy
) div 2;
5047 obj
.Accel
.X
:= xd
-wx
;
5048 obj
.Accel
.y
:= yd
-wy
;
5050 if g_Weapon_Hit(@obj
, 50, FUID
, HIT_SOME
) <> 0 then
5051 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
5053 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
5057 FPain
:= min(FPain
+ 25, 50);
5059 g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
5064 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
5065 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
5067 FSawSoundSelect
.Stop();
5069 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
5071 else if not FSawSoundHit
.IsPlaying() then
5073 FSawSoundSelect
.Stop();
5074 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
5081 g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', GameX
, Gamey
);
5082 FFireAngle
:= FAngle
;
5084 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5085 GameVelX
, GameVelY
-2, SHELL_BULLET
);
5090 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
5091 FFireAngle
:= FAngle
;
5094 FShellType
:= SHELL_SHELL
;
5099 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN2', Gamex
, Gamey
);
5100 FFireAngle
:= FAngle
;
5103 FShellType
:= SHELL_DBLSHELL
;
5108 g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', Gamex
, Gamey
);
5109 FFireAngle
:= FAngle
;
5111 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5112 GameVelX
, GameVelY
-2, SHELL_BULLET
);
5115 WEAPON_ROCKETLAUNCHER
:
5117 g_Weapon_Rocket(wx
, wy
, xd
, yd
, FUID
, WID
);
5118 FFireAngle
:= FAngle
;
5124 g_Weapon_Plasma(wx
, wy
, xd
, yd
, FUID
, WID
);
5125 FFireAngle
:= FAngle
;
5131 g_Weapon_BFGShot(wx
, wy
, xd
, yd
, FUID
, WID
);
5132 FFireAngle
:= FAngle
;
5136 WEAPON_SUPERPULEMET
:
5138 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
5139 FFireAngle
:= FAngle
;
5141 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
5142 GameVelX
, GameVelY
-2, SHELL_SHELL
);
5145 WEAPON_FLAMETHROWER
:
5147 g_Weapon_flame(wx
, wy
, xd
, yd
, FUID
, WID
);
5148 FFireAngle
:= FAngle
;
5155 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
5156 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
5157 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
5160 procedure TPlayer
.DoLerp(Level
: Integer = 2);
5162 if FObj
.X
<> FXTo
then FObj
.X
:= Lerp(FObj
.X
, FXTo
, Level
);
5163 if FObj
.Y
<> FYTo
then FObj
.Y
:= Lerp(FObj
.Y
, FYTo
, Level
);
5166 procedure TPlayer
.SetLerp(XTo
, YTo
: Integer);
5170 if NetInterpLevel
< 1 then
5180 AX
:= Abs(FXTo
- FObj
.X
);
5181 AY
:= Abs(FYTo
- FObj
.Y
);
5182 if (AX
> 32) or (AX
<= NetInterpLevel
) then
5184 if (AY
> 32) or (AY
<= NetInterpLevel
) then
5189 function TPlayer
.FullInLift(XInc
, YInc
: Integer): Integer;
5191 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5192 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5193 PANEL_LIFTUP
, False) then Result
:= -1
5195 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5196 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5197 PANEL_LIFTDOWN
, False) then Result
:= 1
5201 function TPlayer
.GetFlag(Flag
: Byte): Boolean;
5208 if Flag
= FLAG_NONE
then
5211 if not g_Game_IsServer
then Exit
;
5213 // Ïðèíåñ ÷óæîé ôëàã íà ñâîþ áàçó:
5214 if (Flag
= FTeam
) and
5215 (gFlags
[Flag
].State
= FLAG_STATE_NORMAL
) and
5216 (FFlag
<> FLAG_NONE
) then
5218 if FFlag
= FLAG_RED
then
5219 s
:= _lc
[I_PLAYER_FLAG_RED
]
5221 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5223 evtype
:= FLAG_STATE_SCORED
;
5225 ts
:= Format('%.4d', [gFlags
[FFlag
].CaptureTime
]);
5226 Insert('.', ts
, Length(ts
) + 1 - 3);
5227 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_CAPTURE
], [FName
, s
, ts
]), True);
5229 g_Map_ResetFlag(FFlag
);
5230 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_CAPTURE
], [AnsiUpperCase(s
)]), 144);
5232 gTeamStat
[FTeam
].Goals
:= gTeamStat
[FTeam
].Goals
+ 1;
5235 if g_Game_IsNet
then
5237 MH_SEND_FlagEvent(evtype
, FFlag
, FUID
, False);
5241 gFlags
[FFlag
].CaptureTime
:= 0;
5246 // Ïîäîáðàë ñâîé ôëàã - âåðíóë åãî íà áàçó:
5247 if (Flag
= FTeam
) and
5248 (gFlags
[Flag
].State
= FLAG_STATE_DROPPED
) then
5250 if Flag
= FLAG_RED
then
5251 s
:= _lc
[I_PLAYER_FLAG_RED
]
5253 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5255 evtype
:= FLAG_STATE_RETURNED
;
5256 gFlags
[Flag
].CaptureTime
:= 0;
5258 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_RETURN
], [FName
, s
]), True);
5260 g_Map_ResetFlag(Flag
);
5261 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
5264 if g_Game_IsNet
then
5266 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5272 // Ïîäîáðàë ÷óæîé ôëàã:
5273 if (Flag
<> FTeam
) and (FTime
[T_FLAGCAP
] <= gTime
) then
5277 if Flag
= FLAG_RED
then
5278 s
:= _lc
[I_PLAYER_FLAG_RED
]
5280 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5282 evtype
:= FLAG_STATE_CAPTURED
;
5284 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_GET
], [FName
, s
]), True);
5286 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_GET
], [AnsiUpperCase(s
)]), 144);
5288 gFlags
[Flag
].State
:= FLAG_STATE_CAPTURED
;
5291 if g_Game_IsNet
then
5293 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5299 procedure TPlayer
.SetFlag(Flag
: Byte);
5302 if FModel
<> nil then
5303 FModel
.SetFlag(FFlag
);
5306 function TPlayer
.DropFlag(): Boolean;
5311 if (not g_Game_IsServer
) or (FFlag
= FLAG_NONE
) then
5313 FTime
[T_FLAGCAP
] := gTime
+ 2000;
5314 with gFlags
[FFlag
] do
5318 Direction
:= FDirection
;
5319 State
:= FLAG_STATE_DROPPED
;
5321 g_Obj_Push(@Obj
, (FObj
.Vel
.X
div 2)-2+Random(5),
5322 (FObj
.Vel
.Y
div 2)-2+Random(5));
5324 if FFlag
= FLAG_RED
then
5325 s
:= _lc
[I_PLAYER_FLAG_RED
]
5327 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5329 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_DROP
], [FName
, s
]), True);
5330 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_DROP
], [AnsiUpperCase(s
)]), 144);
5332 if g_Game_IsNet
then
5333 MH_SEND_FlagEvent(FLAG_STATE_DROPPED
, Flag
, FUID
, False);
5339 procedure TPlayer
.GetSecret();
5344 procedure TPlayer
.PressKey(Key
: Byte; Time
: Word = 1);
5346 Assert(Key
<= High(FKeys
));
5348 FKeys
[Key
].Pressed
:= True;
5349 FKeys
[Key
].Time
:= Time
;
5352 function TPlayer
.IsKeyPressed(K
: Byte): Boolean;
5354 Result
:= FKeys
[K
].Pressed
;
5357 procedure TPlayer
.ReleaseKeys();
5361 for a
:= Low(FKeys
) to High(FKeys
) do
5363 FKeys
[a
].Pressed
:= False;
5368 procedure TPlayer
.OnDamage(Angle
: SmallInt);
5372 function TPlayer
.firediry(): Integer;
5374 if FKeys
[KEY_UP
].Pressed
then Result
:= -42
5375 else if FKeys
[KEY_DOWN
].Pressed
then Result
:= 19
5379 procedure TPlayer
.RememberState();
5383 FSavedState
.Health
:= FHealth
;
5384 FSavedState
.Armor
:= FArmor
;
5385 FSavedState
.Air
:= FAir
;
5386 FSavedState
.JetFuel
:= FJetFuel
;
5387 FSavedState
.CurrWeap
:= FCurrWeap
;
5388 FSavedState
.NextWeap
:= FNextWeap
;
5389 FSavedState
.NextWeapDelay
:= FNextWeapDelay
;
5392 FSavedState
.Ammo
[i
] := FAmmo
[i
];
5394 FSavedState
.MaxAmmo
[i
] := FMaxAmmo
[i
];
5396 FSavedState
.Rulez
:= FRulez
;
5397 FSavedState
.WaitRecall
:= True;
5400 procedure TPlayer
.RecallState();
5404 if not FSavedState
.WaitRecall
then Exit
;
5406 FHealth
:= FSavedState
.Health
;
5407 FArmor
:= FSavedState
.Armor
;
5408 FAir
:= FSavedState
.Air
;
5409 FJetFuel
:= FSavedState
.JetFuel
;
5410 FCurrWeap
:= FSavedState
.CurrWeap
;
5411 FNextWeap
:= FSavedState
.NextWeap
;
5412 FNextWeapDelay
:= FSavedState
.NextWeapDelay
;
5415 FAmmo
[i
] := FSavedState
.Ammo
[i
];
5417 FMaxAmmo
[i
] := FSavedState
.MaxAmmo
[i
];
5419 FRulez
:= FSavedState
.Rulez
;
5420 FSavedState
.WaitRecall
:= False;
5422 if gGameSettings
.GameType
= GT_SERVER
then
5423 MH_SEND_PlayerStats(FUID
);
5426 procedure TPlayer
.SaveState(var Mem
: TBinMemoryWriter
);
5438 Mem
:= TBinMemoryWriter
.Create(i
);
5440 // Ñèãíàòóðà èãðîêà:
5441 sig
:= PLAYER_SIGNATURE
; // 'PLYR'
5442 Mem
.WriteDWORD(sig
);
5444 Mem
.WriteBoolean(FIamBot
);
5446 Mem
.WriteWord(FUID
);
5448 Mem
.WriteString(FName
, 32);
5450 Mem
.WriteByte(FTeam
);
5452 Mem
.WriteBoolean(FLive
);
5453 // Èçðàñõîäîâàë ëè âñå æèçíè:
5454 Mem
.WriteBoolean(FNoRespawn
);
5456 if FDirection
= D_LEFT
then
5462 Mem
.WriteInt(FHealth
);
5464 Mem
.WriteByte(FLives
);
5466 Mem
.WriteInt(FArmor
);
5470 Mem
.WriteInt(FJetFuel
);
5472 Mem
.WriteInt(FPain
);
5474 Mem
.WriteInt(FKills
);
5476 Mem
.WriteInt(FMonsterKills
);
5478 Mem
.WriteInt(FFrags
);
5480 Mem
.WriteByte(FFragCombo
);
5481 // Âðåìÿ ïîñëåäíåãî ôðàãà:
5482 Mem
.WriteDWORD(FLastFrag
);
5484 Mem
.WriteInt(FDeath
);
5485 // Êàêîé ôëàã íåñåò:
5486 Mem
.WriteByte(FFlag
);
5488 Mem
.WriteInt(FSecrets
);
5490 Mem
.WriteByte(FCurrWeap
);
5492 Mem
.WriteWord(FNextWeap
);
5494 Mem
.WriteByte(FNextWeapDelay
);
5495 // Âðåìÿ çàðÿäêè BFG:
5496 Mem
.WriteSmallInt(FBFGFireCounter
);
5498 Mem
.WriteInt(FDamageBuffer
);
5499 // Ïîñëåäíèé óäàðèâøèé:
5500 Mem
.WriteWord(FLastSpawnerUID
);
5501 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà:
5502 Mem
.WriteByte(FLastHit
);
5504 Obj_SaveState(@FObj
, Mem
);
5505 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ:
5506 for i
:= A_BULLETS
to A_HIGH
do
5507 Mem
.WriteWord(FAmmo
[i
]);
5508 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ:
5509 for i
:= A_BULLETS
to A_HIGH
do
5510 Mem
.WriteWord(FMaxAmmo
[i
]);
5512 for i
:= WP_FIRST
to WP_LAST
do
5513 Mem
.WriteBoolean(FWeapon
[i
]);
5514 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ:
5515 for i
:= WP_FIRST
to WP_LAST
do
5516 Mem
.WriteWord(FReloading
[i
]);
5518 if R_ITEM_BACKPACK
in FRulez
then
5523 // Íàëè÷èå êðàñíîãî êëþ÷à:
5524 if R_KEY_RED
in FRulez
then
5529 // Íàëè÷èå çåëåíîãî êëþ÷à:
5530 if R_KEY_GREEN
in FRulez
then
5535 // Íàëè÷èå ñèíåãî êëþ÷à:
5536 if R_KEY_BLUE
in FRulez
then
5541 // Íàëè÷èå áåðñåðêà:
5542 if R_BERSERK
in FRulez
then
5547 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ:
5548 for i
:= MR_SUIT
to MR_MAX
do
5549 Mem
.WriteDWORD(FMegaRulez
[i
]);
5550 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà:
5551 for i
:= T_RESPAWN
to T_FLAGCAP
do
5552 Mem
.WriteDWORD(FTime
[i
]);
5555 Mem
.WriteString(str
);
5565 procedure TPlayer
.LoadState(var Mem
: TBinMemoryReader
);
5575 // Ñèãíàòóðà èãðîêà:
5577 if sig
<> PLAYER_SIGNATURE
then // 'PLYR'
5579 raise EBinSizeError
.Create('TPlayer.LoadState: Wrong Player Signature');
5582 Mem
.ReadBoolean(FIamBot
);
5586 Mem
.ReadString(str
);
5587 if (Self
<> gPlayer1
) and (Self
<> gPlayer2
) then
5590 Mem
.ReadByte(FTeam
);
5592 Mem
.ReadBoolean(FLive
);
5593 // Èçðàñõîäîâàë ëè âñå æèçíè:
5594 Mem
.ReadBoolean(FNoRespawn
);
5598 FDirection
:= D_LEFT
5600 FDirection
:= D_RIGHT
;
5602 Mem
.ReadInt(FHealth
);
5604 Mem
.ReadByte(FLives
);
5606 Mem
.ReadInt(FArmor
);
5610 Mem
.ReadInt(FJetFuel
);
5614 Mem
.ReadInt(FKills
);
5616 Mem
.ReadInt(FMonsterKills
);
5618 Mem
.ReadInt(FFrags
);
5620 Mem
.ReadByte(FFragCombo
);
5621 // Âðåìÿ ïîñëåäíåãî ôðàãà:
5622 Mem
.ReadDWORD(FLastFrag
);
5624 Mem
.ReadInt(FDeath
);
5625 // Êàêîé ôëàã íåñåò:
5626 Mem
.ReadByte(FFlag
);
5628 Mem
.ReadInt(FSecrets
);
5630 Mem
.ReadByte(FCurrWeap
);
5632 Mem
.ReadWord(FNextWeap
);
5634 Mem
.ReadByte(FNextWeapDelay
);
5635 // Âðåìÿ çàðÿäêè BFG:
5636 Mem
.ReadSmallInt(FBFGFireCounter
);
5638 Mem
.ReadInt(FDamageBuffer
);
5639 // Ïîñëåäíèé óäàðèâøèé:
5640 Mem
.ReadWord(FLastSpawnerUID
);
5641 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà:
5642 Mem
.ReadByte(FLastHit
);
5644 Obj_LoadState(@FObj
, Mem
);
5645 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ:
5646 for i
:= A_BULLETS
to A_HIGH
do
5647 Mem
.ReadWord(FAmmo
[i
]);
5648 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ:
5649 for i
:= A_BULLETS
to A_HIGH
do
5650 Mem
.ReadWord(FMaxAmmo
[i
]);
5652 for i
:= WP_FIRST
to WP_LAST
do
5653 Mem
.ReadBoolean(FWeapon
[i
]);
5654 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ:
5655 for i
:= WP_FIRST
to WP_LAST
do
5656 Mem
.ReadWord(FReloading
[i
]);
5660 Include(FRulez
, R_ITEM_BACKPACK
);
5661 // Íàëè÷èå êðàñíîãî êëþ÷à:
5664 Include(FRulez
, R_KEY_RED
);
5665 // Íàëè÷èå çåëåíîãî êëþ÷à:
5668 Include(FRulez
, R_KEY_GREEN
);
5669 // Íàëè÷èå ñèíåãî êëþ÷à:
5672 Include(FRulez
, R_KEY_BLUE
);
5673 // Íàëè÷èå áåðñåðêà:
5676 Include(FRulez
, R_BERSERK
);
5677 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ:
5678 for i
:= MR_SUIT
to MR_MAX
do
5679 Mem
.ReadDWORD(FMegaRulez
[i
]);
5680 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà:
5681 for i
:= T_RESPAWN
to T_FLAGCAP
do
5682 Mem
.ReadDWORD(FTime
[i
]);
5684 Mem
.ReadString(str
);
5686 Mem
.ReadByte(FColor
.R
);
5687 Mem
.ReadByte(FColor
.G
);
5688 Mem
.ReadByte(FColor
.B
);
5689 if Self
= gPlayer1
then
5691 str
:= gPlayer1Settings
.Model
;
5692 FColor
:= gPlayer1Settings
.Color
;
5694 if Self
= gPlayer2
then
5696 str
:= gPlayer2Settings
.Model
;
5697 FColor
:= gPlayer2Settings
.Color
;
5699 // Îáíîâëÿåì ìîäåëü èãðîêà:
5701 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
5702 FModel
.Color
:= TEAMCOLOR
[FTeam
]
5704 FModel
.Color
:= FColor
;
5707 procedure TPlayer
.AllRulez(Health
: Boolean);
5713 FHealth
:= PLAYER_HP_LIMIT
;
5714 FArmor
:= PLAYER_AP_LIMIT
;
5718 for a
:= WP_FIRST
to WP_LAST
do FWeapon
[a
] := True;
5719 for a
:= A_BULLETS
to A_HIGH
do FAmmo
[a
] := 30000;
5720 FRulez
:= FRulez
+[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
];
5723 procedure TPlayer
.RestoreHealthArmor();
5725 FHealth
:= PLAYER_HP_LIMIT
;
5726 FArmor
:= PLAYER_AP_LIMIT
;
5729 procedure TPlayer
.FragCombo();
5733 if (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) or g_Game_IsClient
then
5735 if gTime
- FLastFrag
< FRAG_COMBO_TIME
then
5737 if FFragCombo
< 5 then
5739 Param
:= FUID
or (FFragCombo
shl 16);
5740 if (FComboEvnt
>= Low(gDelayedEvents
)) and
5741 (FComboEvnt
<= High(gDelayedEvents
)) and
5742 gDelayedEvents
[FComboEvnt
].Pending
and
5743 (gDelayedEvents
[FComboEvnt
].DEType
= DE_KILLCOMBO
) and
5744 (gDelayedEvents
[FComboEvnt
].DENum
and $FFFF = FUID
) then
5746 gDelayedEvents
[FComboEvnt
].Time
:= gTime
+ 500;
5747 gDelayedEvents
[FComboEvnt
].DENum
:= Param
;
5750 FComboEvnt
:= g_Game_DelayEvent(DE_KILLCOMBO
, 500, Param
);
5758 procedure TPlayer
.GiveItem(ItemType
: Byte);
5762 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
5764 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
5768 if FAir
< AIR_MAX
then
5775 if not (R_BERSERK
in FRulez
) then
5777 Include(FRulez
, R_BERSERK
);
5778 if FBFGFireCounter
< 1 then
5780 FCurrWeap
:= WEAPON_KASTET
;
5782 FModel
.SetWeapon(WEAPON_KASTET
);
5786 FBerserk
:= gTime
+30000;
5788 if FHealth
< PLAYER_HP_SOFT
then
5790 FHealth
:= PLAYER_HP_SOFT
;
5791 FBerserk
:= gTime
+30000;
5796 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
5798 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
5802 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
5804 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
5808 if FJetFuel
< JET_MAX
then
5810 FJetFuel
:= JET_MAX
;
5813 ITEM_MEDKIT_SMALL
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
5814 ITEM_MEDKIT_LARGE
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
5816 ITEM_ARMOR_GREEN
: if FArmor
< PLAYER_AP_SOFT
then FArmor
:= PLAYER_AP_SOFT
;
5817 ITEM_ARMOR_BLUE
: if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
5819 ITEM_SPHERE_BLUE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
5821 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) then
5823 if FHealth
< PLAYER_HP_LIMIT
then FHealth
:= PLAYER_HP_LIMIT
;
5824 if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
5827 ITEM_WEAPON_SAW
: FWeapon
[WEAPON_SAW
] := True;
5828 ITEM_WEAPON_SHOTGUN1
: FWeapon
[WEAPON_SHOTGUN1
] := True;
5829 ITEM_WEAPON_SHOTGUN2
: FWeapon
[WEAPON_SHOTGUN2
] := True;
5830 ITEM_WEAPON_CHAINGUN
: FWeapon
[WEAPON_CHAINGUN
] := True;
5831 ITEM_WEAPON_ROCKETLAUNCHER
: FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
5832 ITEM_WEAPON_PLASMA
: FWeapon
[WEAPON_PLASMA
] := True;
5833 ITEM_WEAPON_BFG
: FWeapon
[WEAPON_BFG
] := True;
5834 ITEM_WEAPON_SUPERPULEMET
: FWeapon
[WEAPON_SUPERPULEMET
] := True;
5835 ITEM_WEAPON_FLAMETHROWER
: FWeapon
[WEAPON_FLAMETHROWER
] := True;
5837 ITEM_AMMO_BULLETS
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
5838 ITEM_AMMO_BULLETS_BOX
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
5839 ITEM_AMMO_SHELLS
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
5840 ITEM_AMMO_SHELLS_BOX
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
5841 ITEM_AMMO_ROCKET
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
5842 ITEM_AMMO_ROCKET_BOX
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
5843 ITEM_AMMO_CELL
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
5844 ITEM_AMMO_CELL_BIG
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
5845 ITEM_AMMO_FUELCAN
: if FAmmo
[A_FUEL
] < FMaxAmmo
[A_FUEL
] then IncMax(FAmmo
[A_FUEL
], 100, FMaxAmmo
[A_FUEL
]);
5848 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
5849 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
5850 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
5851 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or
5852 (FMaxAmmo
[A_FUEL
] < AmmoLimits
[1, A_FUEL
]) then
5854 FMaxAmmo
[A_BULLETS
] := AmmoLimits
[1, A_BULLETS
];
5855 FMaxAmmo
[A_SHELLS
] := AmmoLimits
[1, A_SHELLS
];
5856 FMaxAmmo
[A_ROCKETS
] := AmmoLimits
[1, A_ROCKETS
];
5857 FMaxAmmo
[A_CELLS
] := AmmoLimits
[1, A_CELLS
];
5858 FMaxAmmo
[A_FUEL
] := AmmoLimits
[1, A_FUEL
];
5860 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
5861 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
5862 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
5863 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
5865 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
5868 ITEM_KEY_RED
: if not (R_KEY_RED
in FRulez
) then Include(FRulez
, R_KEY_RED
);
5869 ITEM_KEY_GREEN
: if not (R_KEY_GREEN
in FRulez
) then Include(FRulez
, R_KEY_GREEN
);
5870 ITEM_KEY_BLUE
: if not (R_KEY_BLUE
in FRulez
) then Include(FRulez
, R_KEY_BLUE
);
5872 ITEM_BOTTLE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
5873 ITEM_HELMET
: if FArmor
< PLAYER_AP_LIMIT
then IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
5878 if g_Game_IsNet
and g_Game_IsServer
then
5879 MH_SEND_PlayerStats(FUID
);
5882 procedure TPlayer
.FlySmoke(Times
: DWORD
= 1);
5887 if (Random(5) = 1) and (Times
= 1) then
5890 if BodyInLiquid(0, 0) then
5892 g_GFX_Bubbles(Obj
.X
+Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2)+Random(3)-1,
5893 Obj
.Y
+Obj
.Rect
.Height
+8, 1, 8, 4);
5894 if Random(2) = 0 then
5895 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
5897 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
5901 if g_Frames_Get(id
, 'FRAMES_SMOKE') then
5903 for i
:= 1 to Times
do
5905 Anim
:= TAnimation
.Create(id
, False, 3);
5907 g_GFX_OnceAnim(Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(Anim
.Width
div 2),
5908 Obj
.Y
+Obj
.Rect
.Height
-4+Random(8+Times
*2), Anim
, ONCEANIM_SMOKE
);
5914 procedure TPlayer
.OnFireFlame(Times
: DWORD
= 1);
5919 if (Random(10) = 1) and (Times
= 1) then
5922 if g_Frames_Get(id
, 'FRAMES_FLAME') then
5924 for i
:= 1 to Times
do
5926 Anim
:= TAnimation
.Create(id
, False, 3);
5928 g_GFX_OnceAnim(Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(Anim
.Width
div 2),
5929 Obj
.Y
+8+Random(8+Times
*2), Anim
, ONCEANIM_SMOKE
);
5935 procedure TPlayer
.PauseSounds(Enable
: Boolean);
5937 FSawSound
.Pause(Enable
);
5938 FSawSoundIdle
.Pause(Enable
);
5939 FSawSoundHit
.Pause(Enable
);
5940 FSawSoundSelect
.Pause(Enable
);
5945 constructor TCorpse
.Create(X
, Y
: Integer; ModelName
: String; aMess
: Boolean);
5950 FObj
.Rect
:= PLAYER_CORPSERECT
;
5951 FModelName
:= ModelName
;
5956 FState
:= CORPSE_STATE_MESS
;
5957 g_PlayerModel_GetAnim(ModelName
, A_DIE2
, FAnimation
, FAnimationMask
);
5961 FState
:= CORPSE_STATE_NORMAL
;
5962 g_PlayerModel_GetAnim(ModelName
, A_DIE1
, FAnimation
, FAnimationMask
);
5966 destructor TCorpse
.Destroy();
5973 procedure TCorpse
.Damage(Value
: Word; vx
, vy
: Integer);
5977 if FState
= CORPSE_STATE_REMOVEME
then
5980 FDamage
:= FDamage
+ Value
;
5982 if FDamage
> 150 then
5984 if FAnimation
<> nil then
5989 FState
:= CORPSE_STATE_REMOVEME
;
5991 g_Player_CreateGibs(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
5992 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2),
5993 FModelName
, FColor
);
5994 // Çâóê ìÿñà îò òðóïà:
5995 pm
:= g_PlayerModel_Get(FModelName
);
5996 pm
.PlaySound(MODELSOUND_DIE
, 5, FObj
.X
, FObj
.Y
);
6002 FObj
.Vel
.X
:= FObj
.Vel
.X
+ vx
;
6003 FObj
.Vel
.Y
:= FObj
.Vel
.Y
+ vy
;
6004 g_GFX_Blood(FObj
.X
+PLAYER_CORPSERECT
.X
+(PLAYER_CORPSERECT
.Width
div 2),
6005 FObj
.Y
+PLAYER_CORPSERECT
.Y
+(PLAYER_CORPSERECT
.Height
div 2),
6006 Value
, vx
, vy
, 16, (PLAYER_CORPSERECT
.Height
*2) div 3,
6011 procedure TCorpse
.Draw();
6013 if FState
= CORPSE_STATE_REMOVEME
then
6016 if FAnimation
<> nil then
6017 FAnimation
.Draw(FObj
.X
, FObj
.Y
, M_NONE
);
6019 if FAnimationMask
<> nil then
6022 FAnimationMask
.Draw(FObj
.X
, FObj
.Y
, M_NONE
);
6029 procedure TCorpse
.Update();
6033 if FState
= CORPSE_STATE_REMOVEME
then
6036 if gTime
mod (GAME_TICK
*2) <> 0 then
6038 g_Obj_Move(@FObj
, True, True, True);
6043 // Ñîïðîòèâëåíèå âîçäóõà äëÿ òðóïà:
6044 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
6046 st
:= g_Obj_Move(@FObj
, True, True, True);
6048 if WordBool(st
and MOVE_FALLOUT
) then
6050 FState
:= CORPSE_STATE_REMOVEME
;
6054 if FAnimation
<> nil then
6055 FAnimation
.Update();
6056 if FAnimationMask
<> nil then
6057 FAnimationMask
.Update();
6060 procedure TCorpse
.SaveState(var Mem
: TBinMemoryWriter
);
6069 sig
:= CORPSE_SIGNATURE
; // 'CORP'
6070 Mem
.WriteDWORD(sig
);
6072 Mem
.WriteByte(FState
);
6073 // Íàêîïëåííûé óðîí:
6074 Mem
.WriteByte(FDamage
);
6076 Mem
.WriteByte(FColor
.R
);
6077 Mem
.WriteByte(FColor
.G
);
6078 Mem
.WriteByte(FColor
.B
);
6080 Obj_SaveState(@FObj
, Mem
);
6081 // Åñòü ëè àíèìàöèÿ:
6082 anim
:= FAnimation
<> nil;
6083 Mem
.WriteBoolean(anim
);
6084 // Åñëè åñòü - ñîõðàíÿåì:
6086 FAnimation
.SaveState(Mem
);
6087 // Åñòü ëè ìàñêà àíèìàöèè:
6088 anim
:= FAnimationMask
<> nil;
6089 Mem
.WriteBoolean(anim
);
6090 // Åñëè åñòü - ñîõðàíÿåì:
6092 FAnimationMask
.SaveState(Mem
);
6095 procedure TCorpse
.LoadState(var Mem
: TBinMemoryReader
);
6105 if sig
<> CORPSE_SIGNATURE
then // 'CORP'
6107 raise EBinSizeError
.Create('TCorpse.LoadState: Wrong Corpse Signature');
6110 Mem
.ReadByte(FState
);
6111 // Íàêîïëåííûé óðîí:
6112 Mem
.ReadByte(FDamage
);
6114 Mem
.ReadByte(FColor
.R
);
6115 Mem
.ReadByte(FColor
.G
);
6116 Mem
.ReadByte(FColor
.B
);
6118 Obj_LoadState(@FObj
, Mem
);
6119 // Åñòü ëè àíèìàöèÿ:
6120 Mem
.ReadBoolean(anim
);
6121 // Åñëè åñòü - çàãðóæàåì:
6124 Assert(FAnimation
<> nil, 'TCorpse.LoadState: no FAnimation');
6125 FAnimation
.LoadState(Mem
);
6127 // Åñòü ëè ìàñêà àíèìàöèè:
6128 Mem
.ReadBoolean(anim
);
6129 // Åñëè åñòü - çàãðóæàåì:
6132 Assert(FAnimationMask
<> nil, 'TCorpse.LoadState: no FAnimationMask');
6133 FAnimationMask
.LoadState(Mem
);
6139 constructor TBot
.Create();
6146 FSpectator
:= False;
6153 for a
:= WP_FIRST
to WP_LAST
do
6155 FDifficult
.WeaponPrior
[a
] := WEAPON_PRIOR1
[a
];
6156 FDifficult
.CloseWeaponPrior
[a
] := WEAPON_PRIOR2
[a
];
6157 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
6161 destructor TBot
.Destroy();
6164 inherited Destroy();
6167 procedure TBot
.Draw();
6171 //if FTargetUID <> 0 then e_DrawLine(1, FObj.X, FObj.Y, g_Player_Get(FTargetUID).FObj.X,
6172 // g_Player_Get(FTargetUID).FObj.Y, 255, 0, 0);
6175 procedure TBot
.Respawn(Silent
: Boolean; Force
: Boolean = False);
6177 inherited Respawn(Silent
, Force
);
6180 FSelectedWeapon
:= FCurrWeap
;
6185 procedure TBot
.UpdateCombat();
6198 TTargetRecord
= array of TTarget
;
6200 function Compare(a
, b
: TTarget
): Integer;
6202 if a
.Line
and not b
.Line
then // A íà ëèíèè îãíÿ
6205 if not a
.Line
and b
.Line
then // B íà ëèíèè îãíÿ
6207 else // È A, è B íà ëèíèè èëè íå íà ëèíèè îãíÿ
6208 if (a
.Line
and b
.Line
) or ((not a
.Line
) and (not b
.Line
)) then
6210 if a
.Dist
> b
.Dist
then // B áëèæå
6212 else // A áëèæå èëè ðàâíîóäàëåííî ñ B
6215 else // Ñòðàííî -> A
6220 a
, x1
, y1
, x2
, y2
: Integer;
6221 targets
: TTargetRecord
;
6223 Target
, BestTarget
: TTarget
;
6224 firew
, fireh
: Integer;
6228 vsPlayer
, vsMonster
, ok
: Boolean;
6230 vsPlayer
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
);
6231 vsMonster
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
);
6233 // Åñëè òåêóùåå îðóæèå íå òî, ÷òî íóæíî, òî ìåíÿåì:
6234 if FCurrWeap
<> FSelectedWeapon
then
6237 // Åñëè íóæíî ñòðåëÿòü è íóæíîå îðóæèå, òî íàæàòü "Ñòðåëÿòü":
6238 if (GetAIFlag('NEEDFIRE') <> '') and (FCurrWeap
= FSelectedWeapon
) then
6240 RemoveAIFlag('NEEDFIRE');
6243 WEAPON_PLASMA
, WEAPON_SUPERPULEMET
, WEAPON_CHAINGUN
: PressKey(KEY_FIRE
, 20);
6244 WEAPON_SAW
, WEAPON_KASTET
, WEAPON_FLAMETHROWER
: PressKey(KEY_FIRE
, 40);
6245 else PressKey(KEY_FIRE
);
6249 // Êîîðäèíàòû ñòâîëà:
6250 x1
:= FObj
.X
+ WEAPONPOINT
[FDirection
].X
;
6251 y1
:= FObj
.Y
+ WEAPONPOINT
[FDirection
].Y
;
6253 Target
.UID
:= FTargetUID
;
6256 if Target
.UID
<> 0 then
6257 begin // Öåëü åñòü - íàñòðàèâàåì
6258 if (g_GetUIDType(Target
.UID
) = UID_PLAYER
) and
6261 with g_Player_Get(Target
.UID
) do
6263 if (@FObj
) <> nil then
6270 Target
.cX
:= Target
.X
+ PLAYER_RECT_CX
;
6271 Target
.cY
:= Target
.Y
+ PLAYER_RECT_CY
;
6272 Target
.Rect
:= PLAYER_RECT
;
6273 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6274 Target
.Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6275 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6276 Target
.IsPlayer
:= True;
6280 if (g_GetUIDType(Target
.UID
) = UID_MONSTER
) and
6283 mon
:= g_Monsters_Get(Target
.UID
);
6286 Target
.X
:= mon
.Obj
.X
;
6287 Target
.Y
:= mon
.Obj
.Y
;
6289 Target
.cX
:= Target
.X
+ mon
.Obj
.Rect
.X
+ (mon
.Obj
.Rect
.Width
div 2);
6290 Target
.cY
:= Target
.Y
+ mon
.Obj
.Rect
.Y
+ (mon
.Obj
.Rect
.Height
div 2);
6291 Target
.Rect
:= mon
.Obj
.Rect
;
6292 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6293 Target
.Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6294 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6295 Target
.IsPlayer
:= False;
6302 begin // Öåëè íåò - îáíóëÿåì
6307 Target
.Visible
:= False;
6308 Target
.Line
:= False;
6309 Target
.IsPlayer
:= False;
6314 // Åñëè öåëü íå âèäèìà èëè íå íà ëèíèè îãíÿ, òî èùåì âñå âîçìîæíûå öåëè:
6315 if (not Target
.Line
) or (not Target
.Visible
) then
6319 for a
:= 0 to High(gPlayers
) do
6320 if (gPlayers
[a
] <> nil) and (gPlayers
[a
].Live
) and
6321 (gPlayers
[a
].FUID
<> FUID
) and
6322 (not SameTeam(FUID
, gPlayers
[a
].FUID
)) and
6323 (not gPlayers
[a
].NoTarget
) and
6324 (gPlayers
[a
].FMegaRulez
[MR_INVIS
] < gTime
) then
6326 if not TargetOnScreen(gPlayers
[a
].FObj
.X
+ PLAYER_RECT
.X
,
6327 gPlayers
[a
].FObj
.Y
+ PLAYER_RECT
.Y
) then
6330 x2
:= gPlayers
[a
].FObj
.X
+ PLAYER_RECT_CX
;
6331 y2
:= gPlayers
[a
].FObj
.Y
+ PLAYER_RECT_CY
;
6333 // Åñëè èãðîê íà ýêðàíå è íå ïðèêðûò ñòåíîé:
6334 if g_TraceVector(x1
, y1
, x2
, y2
) then
6336 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé:
6337 SetLength(targets
, Length(targets
)+1);
6338 with targets
[High(targets
)] do
6340 UID
:= gPlayers
[a
].FUID
;
6341 X
:= gPlayers
[a
].FObj
.X
;
6342 Y
:= gPlayers
[a
].FObj
.Y
;
6345 Rect
:= PLAYER_RECT
;
6346 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6347 Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6348 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6356 if vsMonster
and (gMonsters
<> nil) then
6357 for a
:= 0 to High(gMonsters
) do
6358 if (gMonsters
[a
] <> nil) and (gMonsters
[a
].Live
) and
6359 (gMonsters
[a
].MonsterType
<> MONSTER_BARREL
) then
6361 mon
:= gMonsters
[a
];
6363 if not TargetOnScreen(mon
.Obj
.X
+ mon
.Obj
.Rect
.X
,
6364 mon
.Obj
.Y
+ mon
.Obj
.Rect
.Y
) then
6367 x2
:= mon
.Obj
.X
+ mon
.Obj
.Rect
.X
+ (mon
.Obj
.Rect
.Width
div 2);
6368 y2
:= mon
.Obj
.Y
+ mon
.Obj
.Rect
.Y
+ (mon
.Obj
.Rect
.Height
div 2);
6370 // Åñëè ìîíñòð íà ýêðàíå è íå ïðèêðûò ñòåíîé:
6371 if g_TraceVector(x1
, y1
, x2
, y2
) then
6373 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé:
6374 SetLength(targets
, Length(targets
)+1);
6375 with targets
[High(targets
)] do
6382 Rect
:= mon
.Obj
.Rect
;
6383 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6384 Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6385 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6393 // Åñëè åñòü âîçìîæíûå öåëè:
6394 // (Âûáèðàåì ëó÷øóþ, ìåíÿåì îðóæèå è áåæèì ê íåé/îò íåå)
6395 if targets
<> nil then
6397 // Âûáèðàåì íàèëó÷øóþ öåëü:
6398 BestTarget
:= targets
[0];
6399 if Length(targets
) > 1 then
6400 for a
:= 1 to High(targets
) do
6401 if Compare(BestTarget
, targets
[a
]) = 1 then
6402 BestTarget
:= targets
[a
];
6404 // Åñëè ëó÷øàÿ öåëü "âèäíåå" òåêóùåé, òî òåêóùàÿ := ëó÷øàÿ:
6405 if ((not Target
.Visible
) and BestTarget
.Visible
and (Target
.UID
<> BestTarget
.UID
)) or
6406 ((not Target
.Line
) and BestTarget
.Line
and BestTarget
.Visible
) then
6408 Target
:= BestTarget
;
6410 if (Healthy() = 3) or ((Healthy() = 2)) then
6411 begin // Åñëè çäîðîâû - äîãîíÿåì
6412 if ((RunDirection() = D_LEFT
) and (Target
.X
> FObj
.X
)) then
6413 SetAIFlag('GORIGHT', '1');
6414 if ((RunDirection() = D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6415 SetAIFlag('GOLEFT', '1');
6418 begin // Åñëè ïîáèòû - óáåãàåì
6419 if ((RunDirection() = D_LEFT
) and (Target
.X
< FObj
.X
)) then
6420 SetAIFlag('GORIGHT', '1');
6421 if ((RunDirection() = D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6422 SetAIFlag('GOLEFT', '1');
6425 // Âûáèðàåì îðóæèå íà îñíîâå ðàññòîÿíèÿ è ïðèîðèòåòîâ:
6426 SelectWeapon(Abs(x1
-Target
.cX
));
6431 // (Äîãîíÿåì/óáåãàåì, ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëè)
6432 // (Åñëè öåëü äàëåêî, òî õâàòèò ñëåäèòü çà íåé)
6433 if Target
.UID
<> 0 then
6435 if not TargetOnScreen(Target
.X
+ Target
.Rect
.X
,
6436 Target
.Y
+ Target
.Rect
.Y
) then
6437 begin // Öåëü ñáåæàëà ñ "ýêðàíà"
6438 if (Healthy() = 3) or ((Healthy() = 2)) then
6439 begin // Åñëè çäîðîâû - äîãîíÿåì
6440 if ((RunDirection() = D_LEFT
) and (Target
.X
> FObj
.X
)) then
6441 SetAIFlag('GORIGHT', '1');
6442 if ((RunDirection() = D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6443 SetAIFlag('GOLEFT', '1');
6446 begin // Åñëè ïîáèòû - çàáûâàåì î öåëè è óáåãàåì
6448 if ((RunDirection() = D_LEFT
) and (Target
.X
< FObj
.X
)) then
6449 SetAIFlag('GORIGHT', '1');
6450 if ((RunDirection() = D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6451 SetAIFlag('GOLEFT', '1');
6455 begin // Öåëü ïîêà íà "ýêðàíå"
6456 // Åñëè öåëü íå çàãîðîæåíà ñòåíîé, òî îòìå÷àåì, êîãäà åå âèäåëè:
6457 if g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6458 FLastVisible
:= gTime
;
6459 // Åñëè ðàçíèöà âûñîò íå âåëèêà, òî äîãîíÿåì:
6460 if (Abs(FObj
.Y
-Target
.Y
) <= 128) then
6462 if ((RunDirection() = D_LEFT
) and (Target
.X
> FObj
.X
)) then
6463 SetAIFlag('GORIGHT', '1');
6464 if ((RunDirection() = D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6465 SetAIFlag('GOLEFT', '1');
6469 // Âûáèðàåì óãîë ââåðõ:
6470 if FDirection
= D_LEFT
then
6471 angle
:= ANGLE_LEFTUP
6473 angle
:= ANGLE_RIGHTUP
;
6475 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6476 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6478 // Åñëè ïðè óãëå ââåðõ ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
6479 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6480 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128), //96
6481 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6482 Target
.Rect
.Width
, Target
.Rect
.Height
) and
6483 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6484 begin // òî íóæíî ñòðåëÿòü ââåðõ
6485 SetAIFlag('NEEDFIRE', '1');
6486 SetAIFlag('NEEDSEEUP', '1');
6489 // Âûáèðàåì óãîë âíèç:
6490 if FDirection
= D_LEFT
then
6491 angle
:= ANGLE_LEFTDOWN
6493 angle
:= ANGLE_RIGHTDOWN
;
6495 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6496 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6498 // Åñëè ïðè óãëå âíèç ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
6499 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6500 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
6501 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6502 Target
.Rect
.Width
, Target
.Rect
.Height
) and
6503 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6504 begin // òî íóæíî ñòðåëÿòü âíèç
6505 SetAIFlag('NEEDFIRE', '1');
6506 SetAIFlag('NEEDSEEDOWN', '1');
6509 // Åñëè öåëü âèäíî è îíà íà òàêîé æå âûñîòå:
6510 if Target
.Visible
and
6511 (y1
+4 < Target
.Y
+Target
.Rect
.Y
+Target
.Rect
.Height
) and
6512 (y1
-4 > Target
.Y
+Target
.Rect
.Y
) then
6514 // Åñëè èäåì â ñòîðîíó öåëè, òî íàäî ñòðåëÿòü:
6515 if ((FDirection
= D_LEFT
) and (Target
.X
< FObj
.X
)) or
6516 ((FDirection
= D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6517 begin // òî íóæíî ñòðåëÿòü âïåðåä
6518 SetAIFlag('NEEDFIRE', '1');
6519 SetAIFlag('NEEDSEEDOWN', '');
6520 SetAIFlag('NEEDSEEUP', '');
6522 // Åñëè öåëü â ïðåäåëàõ "ýêðàíà" è ñëîæíîñòü ïîçâîëÿåò ïðûæêè ñáëèæåíèÿ:
6523 if Abs(FObj
.X
-Target
.X
) < Trunc(gPlayerScreenSize
.X
*0.75) then
6524 if GetRnd(FDifficult
.CloseJump
) then
6525 begin // òî åñëè ïîâåçåò - ïðûãàåì (îñîáåííî, åñëè áëèçêî)
6526 if Abs(FObj
.X
-Target
.X
) < 128 then
6530 if Random(a
) = 0 then
6531 SetAIFlag('NEEDJUMP', '1');
6535 // Åñëè öåëü âñå åùå åñòü:
6536 if Target
.UID
<> 0 then
6537 if gTime
-FLastVisible
> 2000 then // Åñëè âèäåëè äàâíî
6538 Target
.UID
:= 0 // òî çàáûòü öåëü
6539 else // Åñëè âèäåëè íåäàâíî
6540 begin // íî öåëü óáèëè
6541 if Target
.IsPlayer
then
6542 begin // Öåëü - èãðîê
6543 pla
:= g_Player_Get(Target
.UID
);
6544 if (pla
= nil) or (not pla
.Live
) or pla
.NoTarget
or
6545 (pla
.FMegaRulez
[MR_INVIS
] >= gTime
) then
6546 Target
.UID
:= 0; // òî çàáûòü öåëü
6549 begin // Öåëü - ìîíñòð
6550 mon
:= g_Monsters_Get(Target
.UID
);
6551 if (mon
= nil) or (not mon
.Live
) then
6552 Target
.UID
:= 0; // òî çàáûòü öåëü
6555 end; // if Target.UID <> 0
6557 FTargetUID
:= Target
.UID
;
6559 // Åñëè âîçìîæíûõ öåëåé íåò:
6560 // (Àòàêà ÷åãî-íèáóäü ñëåâà èëè ñïðàâà)
6561 if targets
= nil then
6562 if GetAIFlag('ATTACKLEFT') <> '' then
6563 begin // Åñëè íóæíî àòàêîâàòü íàëåâî
6564 RemoveAIFlag('ATTACKLEFT');
6566 SetAIFlag('NEEDJUMP', '1');
6568 if RunDirection() = D_RIGHT
then
6569 begin // Èäåì íå â òó ñòîðîíó
6570 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
6571 begin // Åñëè çäîðîâû, òî, âîçìîæíî, ñòðåëÿåì áåæèì âëåâî è ñòðåëÿåì
6572 SetAIFlag('NEEDFIRE', '1');
6573 SetAIFlag('GOLEFT', '1');
6577 begin // Èäåì â íóæíóþ ñòîðîíó
6578 if GetRnd(FDifficult
.InvisFire
) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
6579 SetAIFlag('NEEDFIRE', '1');
6580 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
6581 SetAIFlag('GORIGHT', '1');
6585 if GetAIFlag('ATTACKRIGHT') <> '' then
6586 begin // Åñëè íóæíî àòàêîâàòü íàïðàâî
6587 RemoveAIFlag('ATTACKRIGHT');
6589 SetAIFlag('NEEDJUMP', '1');
6591 if RunDirection() = D_LEFT
then
6592 begin // Èäåì íå â òó ñòîðîíó
6593 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
6594 begin // Åñëè çäîðîâû, òî, âîçìîæíî, áåæèì âïðàâî è ñòðåëÿåì
6595 SetAIFlag('NEEDFIRE', '1');
6596 SetAIFlag('GORIGHT', '1');
6601 if GetRnd(FDifficult
.InvisFire
) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
6602 SetAIFlag('NEEDFIRE', '1');
6603 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
6604 SetAIFlag('GOLEFT', '1');
6608 //HACK! (does it belongs there?)
6609 RealizeCurrentWeapon();
6611 // Åñëè åñòü âîçìîæíûå öåëè:
6612 // (Ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëÿì)
6613 if (targets
<> nil) and (GetAIFlag('NEEDFIRE') <> '') then
6614 for a
:= 0 to High(targets
) do
6616 // Åñëè ìîæåì ñòðåëÿòü ïî äèàãîíàëè:
6617 if GetRnd(FDifficult
.DiagFire
) then
6619 // Èùåì öåëü ñâåðõó è ñòðåëÿåì, åñëè åñòü:
6620 if FDirection
= D_LEFT
then
6621 angle
:= ANGLE_LEFTUP
6623 angle
:= ANGLE_RIGHTUP
;
6625 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6626 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6628 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6629 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
6630 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6631 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
6632 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
6634 SetAIFlag('NEEDFIRE', '1');
6635 SetAIFlag('NEEDSEEUP', '1');
6638 // Èùåì öåëü ñíèçó è ñòðåëÿåì, åñëè åñòü:
6639 if FDirection
= D_LEFT
then
6640 angle
:= ANGLE_LEFTDOWN
6642 angle
:= ANGLE_RIGHTDOWN
;
6644 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6645 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6647 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6648 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
6649 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6650 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
6651 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
6653 SetAIFlag('NEEDFIRE', '1');
6654 SetAIFlag('NEEDSEEDOWN', '1');
6658 // Åñëè öåëü "ïåðåä íîñîì", òî ñòðåëÿåì:
6659 if targets
[a
].Line
and targets
[a
].Visible
and
6660 (((FDirection
= D_LEFT
) and (targets
[a
].X
< FObj
.X
)) or
6661 ((FDirection
= D_RIGHT
) and (targets
[a
].X
> FObj
.X
))) then
6663 SetAIFlag('NEEDFIRE', '1');
6668 // Åñëè ëåòèò ïóëÿ, òî, âîçìîæíî, ïîäïðûãèâàåì:
6669 if g_Weapon_Danger(FUID
, FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
,
6670 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
,
6671 40+GetInterval(FDifficult
.Cover
, 40)) then
6672 SetAIFlag('NEEDJUMP', '1');
6674 // Åñëè êîí÷èëèñü ïàòîðíû, òî íóæíî ñìåíèòü îðóæèå:
6675 ammo
:= GetAmmoByWeapon(FCurrWeap
);
6676 if ((FCurrWeap
= WEAPON_SHOTGUN2
) and (ammo
< 2)) or
6677 ((FCurrWeap
= WEAPON_BFG
) and (ammo
< 40)) or
6679 SetAIFlag('SELECTWEAPON', '1');
6681 // Åñëè íóæíî ñìåíèòü îðóæèå, òî âûáèðàåì íóæíîå:
6682 if GetAIFlag('SELECTWEAPON') = '1' then
6685 RemoveAIFlag('SELECTWEAPON');
6689 procedure TBot
.Update();
6702 // Ïðîâåðÿåì, îòêëþ÷¸í ëè AI áîòîâ
6703 if (g_debug_BotAIOff
= 1) and (Team
= TEAM_RED
) then
6705 if (g_debug_BotAIOff
= 2) and (Team
= TEAM_BLUE
) then
6707 if g_debug_BotAIOff
= 3 then
6717 RealizeCurrentWeapon();
6724 procedure TBot
.ReleaseKey(Key
: Byte);
6733 function TBot
.KeyPressed(Key
: Word): Boolean;
6735 Result
:= FKeys
[Key
].Pressed
;
6738 function TBot
.GetAIFlag(fName
: String20
): String20
;
6744 fName
:= LowerCase(fName
);
6746 if FAIFlags
<> nil then
6747 for a
:= 0 to High(FAIFlags
) do
6748 if LowerCase(FAIFlags
[a
].Name
) = fName
then
6750 Result
:= FAIFlags
[a
].Value
;
6755 procedure TBot
.RemoveAIFlag(fName
: String20
);
6759 if FAIFlags
= nil then Exit
;
6761 fName
:= LowerCase(fName
);
6763 for a
:= 0 to High(FAIFlags
) do
6764 if LowerCase(FAIFlags
[a
].Name
) = fName
then
6766 if a
<> High(FAIFlags
) then
6767 for b
:= a
to High(FAIFlags
)-1 do
6768 FAIFlags
[b
] := FAIFlags
[b
+1];
6770 SetLength(FAIFlags
, Length(FAIFlags
)-1);
6775 procedure TBot
.SetAIFlag(fName
, fValue
: String20
);
6783 fName
:= LowerCase(fName
);
6785 if FAIFlags
<> nil then
6786 for a
:= 0 to High(FAIFlags
) do
6787 if LowerCase(FAIFlags
[a
].Name
) = fName
then
6793 if ok
then FAIFlags
[a
].Value
:= fValue
6796 SetLength(FAIFlags
, Length(FAIFlags
)+1);
6797 with FAIFlags
[High(FAIFlags
)] do
6805 procedure TBot
.UpdateMove
;
6807 procedure GoLeft(Time
: Word = 1);
6809 ReleaseKey(KEY_LEFT
);
6810 ReleaseKey(KEY_RIGHT
);
6811 PressKey(KEY_LEFT
, Time
);
6812 SetDirection(D_LEFT
);
6815 procedure GoRight(Time
: Word = 1);
6817 ReleaseKey(KEY_LEFT
);
6818 ReleaseKey(KEY_RIGHT
);
6819 PressKey(KEY_RIGHT
, Time
);
6820 SetDirection(D_RIGHT
);
6823 function Rnd(a
: Word): Boolean;
6825 Result
:= Random(a
) = 0;
6828 procedure Turn(Time
: Word = 1200);
6830 if RunDirection() = D_LEFT
then GoRight(Time
) else GoLeft(Time
);
6835 ReleaseKey(KEY_LEFT
);
6836 ReleaseKey(KEY_RIGHT
);
6839 function CanRunLeft(): Boolean;
6841 Result
:= not CollideLevel(-1, 0);
6844 function CanRunRight(): Boolean;
6846 Result
:= not CollideLevel(1, 0);
6849 function CanRun(): Boolean;
6851 if RunDirection() = D_LEFT
then Result
:= CanRunLeft() else Result
:= CanRunRight();
6854 procedure Jump(Time
: Word = 30);
6856 PressKey(KEY_JUMP
, Time
);
6859 function NearHole(): Boolean;
6863 { TODO 5 : Ëåñòíèöû }
6864 sx
:= IfThen(RunDirection() = D_LEFT
, -1, 1);
6865 for x
:= 1 to PLAYER_RECT
.Width
do
6866 if (not StayOnStep(x
*sx
, 0)) and
6867 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
6868 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
6877 function BorderHole(): Boolean;
6881 { TODO 5 : Ëåñòíèöû }
6882 sx
:= IfThen(RunDirection() = D_LEFT
, -1, 1);
6883 for x
:= 1 to PLAYER_RECT
.Width
do
6884 if (not StayOnStep(x
*sx
, 0)) and
6885 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
6886 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
6888 for xx
:= x
to x
+32 do
6889 if CollideLevel(xx
*sx
, PLAYER_RECT
.Height
) then
6899 function NearDeepHole(): Boolean;
6905 sx
:= IfThen(RunDirection() = D_LEFT
, -1, 1);
6908 for x
:= 1 to PLAYER_RECT
.Width
do
6909 if (not StayOnStep(x
*sx
, 0)) and
6910 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
6911 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
6913 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
6915 if CollideLevel(x
*sx
, PLAYER_RECT
.Height
*y
) then Exit
;
6920 end else Result
:= False;
6923 function OverDeepHole(): Boolean;
6930 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
6932 if CollideLevel(0, PLAYER_RECT
.Height
*y
) then Exit
;
6939 function OnGround(): Boolean;
6941 Result
:= StayOnStep(0, 0) or CollideLevel(0, 1);
6944 function OnLadder(): Boolean;
6946 Result
:= FullInStep(0, 0);
6949 function BelowLadder(): Boolean;
6951 Result
:= (FullInStep(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) and
6952 not CollideLevel(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
6953 (FullInStep(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) and
6954 not CollideLevel(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
6957 function BelowLiftUp(): Boolean;
6959 Result
:= ((FullInLift(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) = -1) and
6960 not CollideLevel(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
6961 ((FullInLift(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) = -1) and
6962 not CollideLevel(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
6965 function OnTopLift(): Boolean;
6967 Result
:= (FullInLift(0, 0) = -1) and (FullInLift(0, -32) = 0);
6970 function CanJumpOver(): Boolean;
6974 sx
:= IfThen(RunDirection() = D_LEFT
, -1, 1);
6978 if not CollideLevel(sx
, 0) then Exit
;
6980 for y
:= 1 to BOT_MAXJUMP
do
6981 if CollideLevel(0, -y
) then Exit
else
6982 if not CollideLevel(sx
, -y
) then
6989 function CanJumpUp(Dist
: ShortInt): Boolean;
6996 if CollideLevel(Dist
, 0) then Exit
;
6999 for y
:= 0 to BOT_MAXJUMP
do
7000 if CollideLevel(Dist
, -y
) then
7009 for yy
:= y
+1 to BOT_MAXJUMP
do
7010 if not CollideLevel(Dist
, -yy
) then
7019 for y
:= 0 to BOT_MAXJUMP
do
7020 if CollideLevel(0, -y
) then
7028 if y
< yy
then Exit
;
7033 function IsSafeTrigger(): Boolean;
7038 if gTriggers
= nil then
7040 for a
:= 0 to High(gTriggers
) do
7041 if Collide(gTriggers
[a
].X
,
7044 gTriggers
[a
].Height
) and
7045 (gTriggers
[a
].TriggerType
in [TRIGGER_EXIT
, TRIGGER_CLOSEDOOR
,
7046 TRIGGER_CLOSETRAP
, TRIGGER_TRAP
,
7047 TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
,
7048 TRIGGER_ONOFF
, TRIGGER_SPAWNMONSTER
,
7049 TRIGGER_DAMAGE
, TRIGGER_SHOT
]) then
7054 // Âîçìîæíî, íàæèìàåì êíîïêó:
7055 if Rnd(16) and IsSafeTrigger() then
7058 // Åñëè ïîä ëèôòîì èëè ñòóïåíüêàìè, òî, âîçìîæíî, ïðûãàåì:
7059 if OnLadder() or ((BelowLadder() or BelowLiftUp()) and Rnd(8)) then
7061 ReleaseKey(KEY_LEFT
);
7062 ReleaseKey(KEY_RIGHT
);
7066 // Èäåì âëåâî, åñëè íàäî áûëî:
7067 if GetAIFlag('GOLEFT') <> '' then
7069 RemoveAIFlag('GOLEFT');
7070 if CanRunLeft() then
7074 // Èäåì âïðàâî, åñëè íàäî áûëî:
7075 if GetAIFlag('GORIGHT') <> '' then
7077 RemoveAIFlag('GORIGHT');
7078 if CanRunRight() then
7082 // Åñëè âûëåòåëè çà êàðòó, òî ïðîáóåì âåðíóòüñÿ:
7083 if FObj
.X
< -32 then
7086 if FObj
.X
+32 > gMapInfo
.Width
then
7089 // Ïðûãàåì, åñëè íàäî áûëî:
7090 if GetAIFlag('NEEDJUMP') <> '' then
7093 RemoveAIFlag('NEEDJUMP');
7096 // Ñìîòðèì ââåðõ, åñëè íàäî áûëî:
7097 if GetAIFlag('NEEDSEEUP') <> '' then
7100 ReleaseKey(KEY_DOWN
);
7101 PressKey(KEY_UP
, 20);
7102 RemoveAIFlag('NEEDSEEUP');
7105 // Ñìîòðèì âíèç, åñëè íàäî áûëî:
7106 if GetAIFlag('NEEDSEEDOWN') <> '' then
7109 ReleaseKey(KEY_DOWN
);
7110 PressKey(KEY_DOWN
, 20);
7111 RemoveAIFlag('NEEDSEEDOWN');
7114 // Åñëè íóæíî áûëî â äûðó è ìû íå íà çåìëå, òî ïîêîðíî ëåòèì:
7115 if GetAIFlag('GOINHOLE') <> '' then
7116 if not OnGround() then
7118 ReleaseKey(KEY_LEFT
);
7119 ReleaseKey(KEY_RIGHT
);
7120 RemoveAIFlag('GOINHOLE');
7121 SetAIFlag('FALLINHOLE', '1');
7124 // Åñëè ïàäàëè è äîñòèãëè çåìëè, òî õâàòèò ïàäàòü:
7125 if GetAIFlag('FALLINHOLE') <> '' then
7127 RemoveAIFlag('FALLINHOLE');
7129 // Åñëè ëåòåëè ïðÿìî è ñåé÷àñ íå íà ëåñòíèöå èëè íà âåðøèíå ëèôòà, òî îòõîäèì â ñòîðîíó:
7130 if not (KeyPressed(KEY_LEFT
) or KeyPressed(KEY_RIGHT
)) then
7131 if GetAIFlag('FALLINHOLE') = '' then
7132 if (not OnLadder()) or (FObj
.Vel
.Y
>= 0) or (OnTopLift()) then
7138 // Åñëè íà çåìëå è ìîæíî ïîäïðûãíóòü, òî, âîçìîæíî, ïðûãàåì:
7140 CanJumpUp(IfThen(RunDirection() = D_LEFT
, -1, 1)*32) and
7144 // Åñëè íà çåìëå è âîçëå äûðû (ãëóáèíà > 2 ðîñòîâ èãðîêà):
7145 if OnGround() and NearHole() then
7146 if NearDeepHole() then // Åñëè ýòî áåçäíà
7148 0..3: Turn(); // Áåæèì îáðàòíî
7149 4: Jump(); // Ïðûãàåì
7150 5: begin // Ïðûãàåì îáðàòíî
7155 else // Ýòî íå áåçäíà è ìû åùå íå ëåòèì òóäà
7156 if GetAIFlag('GOINHOLE') = '' then
7158 0: Turn(); // Íå íóæíî òóäà
7159 1: Jump(); // Âäðóã ïîâåçåò - ïðûãàåì
7160 else // Åñëè ÿìà ñ ãðàíèöåé, òî ïðè ñëó÷àå ìîæíî òóäà ïðûãíóòü
7161 if BorderHole() then
7162 SetAIFlag('GOINHOLE', '1');
7165 // Åñëè íà çåìëå, íî íåêóäà èäòè:
7166 if (not CanRun()) and OnGround() then
7168 // Åñëè ìû íà ëåñòíèöå èëè ìîæíî ïåðåïðûãíóòü, òî ïðûãàåì:
7169 if CanJumpOver() or OnLadder() then
7171 else // èíà÷å ïîïûòàåìñÿ â äðóãóþ ñòîðîíó
7172 if Random(2) = 0 then
7174 if IsSafeTrigger() then
7180 // Îñòàëîñü ìàëî âîçäóõà:
7181 if FAir
< 36 * 2 then
7184 // Âûáèðàåìñÿ èç êèñëîòû, åñëè íåò êîñòþìà, îáîæãëèñü, èëè ìàëî çäîðîâüÿ:
7185 if (FMegaRulez
[MR_SUIT
] < gTime
) and ((FLastHit
= HIT_ACID
) or (Healthy() <= 1)) then
7186 if BodyInAcid(0, 0) then
7190 function TBot
.FullInStep(XInc
, YInc
: Integer): Boolean;
7192 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
7193 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_STEP
, False);
7196 {function TBot.NeedItem(Item: Byte): Byte;
7201 procedure TBot
.SelectWeapon(Dist
: Integer);
7205 function HaveAmmo(weapon
: Byte): Boolean;
7208 WEAPON_PISTOL
: Result
:= FAmmo
[A_BULLETS
] >= 1;
7209 WEAPON_SHOTGUN1
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7210 WEAPON_SHOTGUN2
: Result
:= FAmmo
[A_SHELLS
] >= 2;
7211 WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
] >= 10;
7212 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
] >= 1;
7213 WEAPON_PLASMA
: Result
:= FAmmo
[A_CELLS
] >= 10;
7214 WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
] >= 40;
7215 WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7216 WEAPON_FLAMETHROWER
: Result
:= FAmmo
[A_FUEL
] >= 1;
7217 else Result
:= True;
7222 if Dist
= -1 then Dist
:= BOT_LONGDIST
;
7224 if Dist
> BOT_LONGDIST
then
7225 begin // Äàëüíèé áîé
7227 if FWeapon
[FDifficult
.WeaponPrior
[a
]] and HaveAmmo(FDifficult
.WeaponPrior
[a
]) then
7229 FSelectedWeapon
:= FDifficult
.WeaponPrior
[a
];
7233 else //if Dist > BOT_UNSAFEDIST then
7234 begin // Áëèæíèé áîé
7236 if FWeapon
[FDifficult
.CloseWeaponPrior
[a
]] and HaveAmmo(FDifficult
.CloseWeaponPrior
[a
]) then
7238 FSelectedWeapon
:= FDifficult
.CloseWeaponPrior
[a
];
7245 if FWeapon[FDifficult.SafeWeaponPrior[a]] and HaveAmmo(FDifficult.SafeWeaponPrior[a]) then
7247 FSelectedWeapon := FDifficult.SafeWeaponPrior[a];
7253 function TBot
.PickItem(ItemType
: Byte; force
: Boolean; var remove
: Boolean): Boolean;
7255 Result
:= inherited PickItem(ItemType
, force
, remove
);
7257 if Result
then SetAIFlag('SELECTWEAPON', '1');
7260 function TBot
.Heal(value
: Word; Soft
: Boolean): Boolean;
7262 Result
:= inherited Heal(value
, Soft
);
7265 function TBot
.Healthy(): Byte;
7267 if FMegaRulez
[MR_INVUL
] >= gTime
then Result
:= 3
7268 else if (FHealth
> 80) or ((FHealth
> 50) and (FArmor
> 20)) then Result
:= 3
7269 else if (FHealth
> 50) then Result
:= 2
7270 else if (FHealth
> 20) then Result
:= 1
7274 function TBot
.TargetOnScreen(TX
, TY
: Integer): Boolean;
7276 Result
:= (Abs(FObj
.X
-TX
) <= Trunc(gPlayerScreenSize
.X
*0.6)) and
7277 (Abs(FObj
.Y
-TY
) <= Trunc(gPlayerScreenSize
.Y
*0.6));
7280 procedure TBot
.OnDamage(Angle
: SmallInt);
7288 if (Angle
= 0) or (Angle
= 180) then
7291 if (g_GetUIDType(FLastSpawnerUID
) = UID_PLAYER
) and
7292 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
) then
7294 pla
:= g_Player_Get(FLastSpawnerUID
);
7295 ok
:= not TargetOnScreen(pla
.FObj
.X
+ PLAYER_RECT
.X
,
7296 pla
.FObj
.Y
+ PLAYER_RECT
.Y
);
7299 if (g_GetUIDType(FLastSpawnerUID
) = UID_MONSTER
) and
7300 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
) then
7302 mon
:= g_Monsters_Get(FLastSpawnerUID
);
7303 ok
:= not TargetOnScreen(mon
.Obj
.X
+ mon
.Obj
.Rect
.X
,
7304 mon
.Obj
.Y
+ mon
.Obj
.Rect
.Y
);
7309 SetAIFlag('ATTACKLEFT', '1')
7311 SetAIFlag('ATTACKRIGHT', '1');
7315 function TBot
.RunDirection(): TDirection
;
7317 if Abs(Vel
.X
) >= 1 then
7319 if Vel
.X
> 0 then Result
:= D_RIGHT
else Result
:= D_LEFT
;
7321 Result
:= FDirection
;
7324 function TBot
.GetRnd(a
: Byte): Boolean;
7326 if a
= 0 then Result
:= False
7327 else if a
= 255 then Result
:= True
7328 else Result
:= Random(256) > 255-a
;
7331 function TBot
.GetInterval(a
: Byte; radius
: SmallInt): SmallInt;
7333 Result
:= Round((255-a
)/255*radius
*(Random(2)-1));
7336 procedure TBot
.SaveState(var Mem
: TBinMemoryWriter
);
7342 inherited SaveState(Mem
);
7344 // Âûáðàííîå îðóæèå:
7345 Mem
.WriteByte(FSelectedWeapon
);
7347 Mem
.WriteWord(FTargetUID
);
7348 // Âðåìÿ ïîòåðè öåëè:
7349 Mem
.WriteDWORD(FLastVisible
);
7350 // Êîëè÷åñòâî ôëàãîâ ÈÈ:
7351 dw
:= Length(FAIFlags
);
7354 for i
:= 0 to Integer(dw
)-1 do
7356 Mem
.WriteString(FAIFlags
[i
].Name
, 20);
7357 Mem
.WriteString(FAIFlags
[i
].Value
, 20);
7359 // Íàñòðîéêè ñëîæíîñòè:
7361 Mem
.WriteMemory(p
, SizeOf(TDifficult
));
7364 procedure TBot
.LoadState(var Mem
: TBinMemoryReader
);
7370 inherited LoadState(Mem
);
7372 // Âûáðàííîå îðóæèå:
7373 Mem
.ReadByte(FSelectedWeapon
);
7375 Mem
.ReadWord(FTargetUID
);
7376 // Âðåìÿ ïîòåðè öåëè:
7377 Mem
.ReadDWORD(FLastVisible
);
7378 // Êîëè÷åñòâî ôëàãîâ ÈÈ:
7380 SetLength(FAIFlags
, dw
);
7382 for i
:= 0 to Integer(dw
)-1 do
7384 Mem
.ReadString(FAIFlags
[i
].Name
);
7385 Mem
.ReadString(FAIFlags
[i
].Value
);
7387 // Íàñòðîéêè ñëîæíîñòè:
7388 Mem
.ReadMemory(p
, dw
);
7389 if dw
<> SizeOf(TDifficult
) then
7391 raise EBinSizeError
.Create('TBot.LoadState: Wrong FDifficult Size');
7393 FDifficult
:= TDifficult(p
^);