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
,
73 ANGLE_NONE
= Low(SmallInt);
75 CORPSE_STATE_REMOVEME
= 0;
76 CORPSE_STATE_NORMAL
= 1;
77 CORPSE_STATE_MESS
= 2;
79 PLAYER_RECT
: TRectWH
= (X
:15; Y
:12; Width
:34; Height
:52);
80 PLAYER_RECT_CX
= 15+(34 div 2);
81 PLAYER_RECT_CY
= 12+(52 div 2);
82 PLAYER_CORPSERECT
: TRectWH
= (X
:15; Y
:48; Width
:34; Height
:16);
85 PLAYER_HP_LIMIT
= 200;
87 PLAYER_AP_LIMIT
= 200;
90 PLAYER1_DEF_COLOR
: TRGB
= (R
:64; G
:175; B
:48);
91 PLAYER2_DEF_COLOR
: TRGB
= (R
:96; G
:96; B
:96);
107 TPlayerStatArray
= Array of TPlayerStat
;
109 TPlayerSavedState
= record
117 Ammo
: Array [A_BULLETS
..A_CELLS
] of Word;
118 MaxAmmo
: Array [A_BULLETS
..A_CELLS
] of Word;
119 Weapon
: Array [WEAPON_KASTET
..WEAPON_SUPERPULEMET
] of Boolean;
120 Rulez
: Set of R_ITEM_BACKPACK
..R_BERSERK
;
129 TPlayer
= class (TObject
)
137 FDirection
: TDirection
;
145 FMonsterKills
: Integer;
151 FCanJetpack
: Boolean;
157 FNextWeapDelay
: Byte; // frames
158 FBFGFireCounter
: SmallInt;
159 FLastSpawnerUID
: Word;
163 FSpectatePlayer
: Integer;
165 FSavedState
: TPlayerSavedState
;
167 FModel
: TPlayerModel
;
170 FActionForce
: Boolean;
171 FActionChanged
: Boolean;
173 FFireAngle
: SmallInt;
175 FShellTimer
: Integer;
177 FSawSound
: TPlayableSound
;
178 FSawSoundIdle
: TPlayableSound
;
179 FSawSoundHit
: TPlayableSound
;
180 FSawSoundSelect
: TPlayableSound
;
181 FJetSoundOn
: TPlayableSound
;
182 FJetSoundOff
: TPlayableSound
;
183 FJetSoundFly
: TPlayableSound
;
187 FJustTeleported
: Boolean;
190 function CollideLevel(XInc
, YInc
: Integer): Boolean;
191 function StayOnStep(XInc
, YInc
: Integer): Boolean;
192 function HeadInLiquid(XInc
, YInc
: Integer): Boolean;
193 function BodyInLiquid(XInc
, YInc
: Integer): Boolean;
194 function BodyInAcid(XInc
, YInc
: Integer): Boolean;
195 function FullInLift(XInc
, YInc
: Integer): Integer;
196 {procedure CollideItem();}
197 procedure FlySmoke(Times
: DWORD
= 1);
198 function GetAmmoByWeapon(Weapon
: Byte): Word;
199 procedure SetAction(Action
: Byte; Force
: Boolean = False);
200 procedure OnDamage(Angle
: SmallInt); virtual;
201 function firediry(): Integer;
203 procedure Run(Direction
: TDirection
);
204 procedure NextWeapon();
205 procedure PrevWeapon();
212 procedure cycleWeapon (dir
: Integer);
213 function getNextWeaponIndex (): Byte; // return 255 for "no switch"
214 procedure resetWeaponQueue ();
215 function hasAmmoForWeapon (weapon
: Byte): Boolean;
218 FDamageBuffer
: Integer;
220 FAmmo
: Array [A_BULLETS
..A_CELLS
] of Word;
221 FMaxAmmo
: Array [A_BULLETS
..A_CELLS
] of Word;
222 FWeapon
: Array [WEAPON_KASTET
..WEAPON_SUPERPULEMET
] of Boolean;
223 FRulez
: Set of R_ITEM_BACKPACK
..R_BERSERK
;
225 FMegaRulez
: Array [MR_SUIT
..MR_MAX
] of DWORD
;
226 FReloading
: Array [WEAPON_KASTET
..WEAPON_SUPERPULEMET
] of Word;
227 FTime
: Array [T_RESPAWN
..T_FLAGCAP
] of DWORD
;
228 FKeys
: Array [KEY_LEFT
..KEY_CHAT
] of TKeyState
;
230 FPreferredTeam
: Byte;
233 FWantsInGame
: Boolean;
237 FActualModelName
: string;
243 constructor Create(); virtual;
244 destructor Destroy(); override;
245 procedure Respawn(Silent
: Boolean; Force
: Boolean = False); virtual;
246 function GetRespawnPoint(): Byte;
247 procedure PressKey(Key
: Byte; Time
: Word = 1);
248 procedure ReleaseKeys();
249 procedure SetModel(ModelName
: String);
250 procedure SetColor(Color
: TRGB
);
251 procedure SetWeapon(W
: Byte);
252 function IsKeyPressed(K
: Byte): Boolean;
253 function GetKeys(): Byte;
254 function PickItem(ItemType
: Byte; respawn
: Boolean; var remove
: Boolean): Boolean; virtual;
255 function Collide(X
, Y
: Integer; Width
, Height
: Word): Boolean; overload
;
256 function Collide(Panel
: TPanel
): Boolean; overload
;
257 function Collide(X
, Y
: Integer): Boolean; overload
;
258 procedure SetDirection(Direction
: TDirection
);
259 procedure GetSecret();
260 function TeleportTo(X
, Y
: Integer; silent
: Boolean; dir
: Byte): Boolean;
262 procedure Push(vx
, vy
: Integer);
263 procedure ChangeModel(ModelName
: String);
264 procedure SwitchTeam
;
265 procedure ChangeTeam(Team
: Byte);
267 function GetFlag(Flag
: Byte): Boolean;
268 procedure SetFlag(Flag
: Byte);
269 function DropFlag(): Boolean;
270 procedure AllRulez(Health
: Boolean);
271 procedure RestoreHealthArmor();
272 procedure FragCombo();
273 procedure GiveItem(ItemType
: Byte);
274 procedure Damage(value
: Word; SpawnerUID
: Word; vx
, vy
: Integer; t
: Byte); virtual;
275 function Heal(value
: Word; Soft
: Boolean): Boolean; virtual;
276 procedure MakeBloodVector(Count
: Word; VelX
, VelY
: Integer);
277 procedure MakeBloodSimple(Count
: Word);
278 procedure Kill(KillType
: Byte; SpawnerUID
: Word; t
: Byte);
279 procedure Reset(Force
: Boolean);
280 procedure Spectate(NoMove
: Boolean = False);
281 procedure SwitchNoClip
;
282 procedure SoftReset();
283 procedure Draw(); virtual;
284 procedure DrawPain();
285 procedure DrawPickup();
286 procedure DrawRulez();
288 procedure DrawBubble();
290 procedure Update(); virtual;
291 procedure RememberState();
292 procedure RecallState();
293 procedure SaveState(var Mem
: TBinMemoryWriter
); virtual;
294 procedure LoadState(var Mem
: TBinMemoryReader
); virtual;
295 procedure PauseSounds(Enable
: Boolean);
296 procedure NetFire(Wpn
: Byte; X
, Y
, AX
, AY
: Integer; WID
: Integer = -1);
297 procedure DoLerp(Level
: Integer = 2);
298 procedure SetLerp(XTo
, YTo
: Integer);
299 procedure QueueWeaponSwitch(Weapon
: Byte);
300 procedure RealizeCurrentWeapon();
302 procedure JetpackOff
;
304 property Name
: String read FName write FName
;
305 property Model
: TPlayerModel read FModel
;
306 property Health
: Integer read FHealth write FHealth
;
307 property Lives
: Byte read FLives write FLives
;
308 property Armor
: Integer read FArmor write FArmor
;
309 property Air
: Integer read FAir write FAir
;
310 property JetFuel
: Integer read FJetFuel write FJetFuel
;
311 property Frags
: Integer read FFrags write FFrags
;
312 property Death
: Integer read FDeath write FDeath
;
313 property Kills
: Integer read FKills write FKills
;
314 property CurrWeap
: Byte read FCurrWeap write FCurrWeap
;
315 property MonsterKills
: Integer read FMonsterKills write FMonsterKills
;
316 property Secrets
: Integer read FSecrets
;
317 property GodMode
: Boolean read FGodMode write FGodMode
;
318 property NoTarget
: Boolean read FNoTarget write FNoTarget
;
319 property NoReload
: Boolean read FNoReload write FNoReload
;
320 property Live
: Boolean read FLive write FLive
;
321 property Flag
: Byte read FFlag
;
322 property Team
: Byte read FTeam write FTeam
;
323 property Direction
: TDirection read FDirection
;
324 property GameX
: Integer read FObj
.X write FObj
.X
;
325 property GameY
: Integer read FObj
.Y write FObj
.Y
;
326 property GameVelX
: Integer read FObj
.Vel
.X write FObj
.Vel
.X
;
327 property GameVelY
: Integer read FObj
.Vel
.Y write FObj
.Vel
.Y
;
328 property GameAccelX
: Integer read FObj
.Accel
.X write FObj
.Accel
.X
;
329 property GameAccelY
: Integer read FObj
.Accel
.Y write FObj
.Accel
.Y
;
330 property Vel
: TPoint2i read FObj
.Vel
;
331 property Obj
: TObj read FObj
;
332 property IncCam
: Integer read FIncCam write FIncCam
;
333 property UID
: Word read FUID write FUID
;
334 property JustTeleported
: Boolean read FJustTeleported write FJustTeleported
;
335 property NetTime
: LongWord read FNetTime write FNetTime
;
345 WeaponPrior
: Array [WEAPON_KASTET
..WEAPON_SUPERPULEMET
] of Byte;
346 CloseWeaponPrior
: Array [WEAPON_KASTET
..WEAPON_SUPERPULEMET
] of Byte;
347 //SafeWeaponPrior: Array [WEAPON_KASTET..WEAPON_SUPERPULEMET] of Byte;
355 TBot
= class (TPlayer
)
357 FSelectedWeapon
: Byte;
360 FAIFlags
: Array of TAIFlag
;
361 FDifficult
: TDifficult
;
363 function GetRnd(a
: Byte): Boolean;
364 function GetInterval(a
: Byte; radius
: SmallInt): SmallInt;
365 function RunDirection(): TDirection
;
366 function FullInStep(XInc
, YInc
: Integer): Boolean;
367 //function NeedItem(Item: Byte): Byte;
368 procedure SelectWeapon(Dist
: Integer);
369 procedure SetAIFlag(fName
, fValue
: String20
);
370 function GetAIFlag(fName
: String20
): String20
;
371 procedure RemoveAIFlag(fName
: String20
);
372 function Healthy(): Byte;
373 procedure UpdateMove();
374 procedure UpdateCombat();
375 function KeyPressed(Key
: Word): Boolean;
376 procedure ReleaseKey(Key
: Byte);
377 function TargetOnScreen(TX
, TY
: Integer): Boolean;
378 procedure OnDamage(Angle
: SmallInt); override;
381 procedure Respawn(Silent
: Boolean; Force
: Boolean = False); override;
382 constructor Create(); override;
383 destructor Destroy(); override;
384 procedure Draw(); override;
385 function PickItem(ItemType
: Byte; force
: Boolean; var remove
: Boolean): Boolean; override;
386 function Heal(value
: Word; Soft
: Boolean): Boolean; override;
387 procedure Update(); override;
388 procedure SaveState(var Mem
: TBinMemoryWriter
); override;
389 procedure LoadState(var Mem
: TBinMemoryReader
); override;
411 TCorpse
= class (TObject
)
419 FAnimation
: TAnimation
;
420 FAnimationMask
: TAnimation
;
423 constructor Create(X
, Y
: Integer; ModelName
: String; aMess
: Boolean);
424 destructor Destroy(); override;
425 procedure Damage(Value
: Word; vx
, vy
: Integer);
428 procedure SaveState(var Mem
: TBinMemoryWriter
);
429 procedure LoadState(var Mem
: TBinMemoryReader
);
431 property Obj
: TObj read FObj
;
432 property State
: Byte read FState
;
433 property Mess
: Boolean read FMess
;
436 TTeamStat
= Array [TEAM_RED
..TEAM_BLUE
] of
442 gPlayers
: Array of TPlayer
;
443 gCorpses
: Array of TCorpse
;
444 gGibs
: Array of TGib
;
445 gShells
: Array of TShell
;
446 gTeamStat
: TTeamStat
;
447 gFly
: Boolean = False;
448 gAimLine
: Boolean = False;
449 gChatBubble
: Byte = 0;
453 MAX_RUNVEL
: Integer = 8;
454 VEL_JUMP
: Integer = 10;
455 SHELL_TIMEOUT
: Cardinal = 60000;
457 function Lerp(X
, Y
, Factor
: Integer): Integer;
459 procedure g_Gibs_SetMax(Count
: Word);
460 function g_Gibs_GetMax(): Word;
461 procedure g_Corpses_SetMax(Count
: Word);
462 function g_Corpses_GetMax(): Word;
463 procedure g_Shells_SetMax(Count
: Word);
464 function g_Shells_GetMax(): Word;
466 procedure g_Player_Init();
467 procedure g_Player_Free();
468 function g_Player_Create(ModelName
: String; Color
: TRGB
; Team
: Byte; Bot
: Boolean): Word;
469 function g_Player_CreateFromState(var Mem
: TBinMemoryReader
): Word;
470 procedure g_Player_Remove(UID
: Word);
471 procedure g_Player_ResetTeams();
472 procedure g_Player_UpdateAll();
473 procedure g_Player_DrawAll();
474 procedure g_Player_DrawDebug(p
: TPlayer
);
475 procedure g_Player_DrawHealth();
476 procedure g_Player_RememberAll();
477 procedure g_Player_ResetAll(Force
, Silent
: Boolean);
478 function g_Player_Get(UID
: Word): TPlayer
;
479 function g_Player_GetCount(): Byte;
480 function g_Player_GetStats(): TPlayerStatArray
;
481 function g_Player_ValidName(Name
: String): Boolean;
482 procedure g_Player_CreateCorpse(Player
: TPlayer
);
483 procedure g_Player_CreateGibs(fX
, fY
: Integer; ModelName
: String; fColor
: TRGB
);
484 procedure g_Player_CreateShell(fX
, fY
, dX
, dY
: Integer; T
: Byte);
485 procedure g_Player_UpdatePhysicalObjects();
486 procedure g_Player_DrawCorpses();
487 procedure g_Player_DrawShells();
488 procedure g_Player_RemoveAllCorpses();
489 procedure g_Player_Corpses_SaveState(var Mem
: TBinMemoryWriter
);
490 procedure g_Player_Corpses_LoadState(var Mem
: TBinMemoryReader
);
491 procedure g_Bot_Add(Team
, Difficult
: Byte);
492 procedure g_Bot_AddList(Team
: Byte; lname
: ShortString; num
: Integer = -1);
493 procedure g_Bot_MixNames();
494 procedure g_Bot_RemoveAll();
499 e_log
, g_map
, g_items
, g_console
, SysUtils
, g_gfx
, Math
,
500 g_options
, g_triggers
, g_menu
, MAPDEF
, g_game
,
501 wadreader
, g_main
, g_monsters
, CONFIG
, g_language
, g_net
, g_netmsg
;
511 diag_precision
: Byte;
515 w_prior1
: Array [WEAPON_KASTET
..WEAPON_SUPERPULEMET
] of Byte;
516 w_prior2
: Array [WEAPON_KASTET
..WEAPON_SUPERPULEMET
] of Byte;
517 w_prior3
: Array [WEAPON_KASTET
..WEAPON_SUPERPULEMET
] of Byte;
521 TIME_RESPAWN1
= 1500;
522 TIME_RESPAWN2
= 2000;
523 TIME_RESPAWN3
= 3000;
526 JET_MAX
= 540; // ~30 sec
527 PLAYER_SUIT_TIME
= 30000;
528 PLAYER_INVUL_TIME
= 30000;
529 PLAYER_INVIS_TIME
= 35000;
530 FRAG_COMBO_TIME
= 3000;
534 ANGLE_RIGHTDOWN
= -35;
536 ANGLE_LEFTDOWN
= -145;
537 PLAYER_HEADRECT
: TRectWH
= (X
:24; Y
:12; Width
:20; Height
:12);
538 WEAPONPOINT
: Array [TDirection
] of TPoint
= ((X
:16; Y
:32), (X
:47; Y
:32));
541 BOT_UNSAFEDIST
= 128;
542 TEAMCOLOR
: Array [TEAM_RED
..TEAM_BLUE
] of TRGB
= ((R
:255; G
:0; B
:0),
544 DIFFICULT_EASY
: TDifficult
= (DiagFire
: 32; InvisFire
: 32; DiagPrecision
: 32;
545 FlyPrecision
: 32; Cover
: 32; CloseJump
: 32;
546 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0));
547 DIFFICULT_MEDIUM
: TDifficult
= (DiagFire
: 127; InvisFire
: 127; DiagPrecision
: 127;
548 FlyPrecision
: 127; Cover
: 127; CloseJump
: 127;
549 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0));
550 DIFFICULT_HARD
: TDifficult
= (DiagFire
: 255; InvisFire
: 255; DiagPrecision
: 255;
551 FlyPrecision
: 255; Cover
: 255; CloseJump
: 255;
552 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0));
553 WEAPON_PRIOR1
: Array [WEAPON_KASTET
..WEAPON_SUPERPULEMET
] of Byte =
554 (WEAPON_SUPERPULEMET
, WEAPON_SHOTGUN2
, WEAPON_SHOTGUN1
,
555 WEAPON_CHAINGUN
, WEAPON_PLASMA
, WEAPON_ROCKETLAUNCHER
,
556 WEAPON_BFG
, WEAPON_PISTOL
, WEAPON_SAW
, WEAPON_KASTET
);
557 WEAPON_PRIOR2
: Array [WEAPON_KASTET
..WEAPON_SUPERPULEMET
] of Byte =
558 (WEAPON_SUPERPULEMET
, WEAPON_BFG
, WEAPON_ROCKETLAUNCHER
,
559 WEAPON_SHOTGUN2
, WEAPON_PLASMA
, WEAPON_SHOTGUN1
,
560 WEAPON_CHAINGUN
, WEAPON_PISTOL
, WEAPON_SAW
, WEAPON_KASTET
);
561 //WEAPON_PRIOR3: Array [WEAPON_KASTET..WEAPON_SUPERPULEMET] of Byte =
562 // (WEAPON_SUPERPULEMET, WEAPON_BFG, WEAPON_PLASMA,
563 // WEAPON_SHOTGUN2, WEAPON_CHAINGUN, WEAPON_SHOTGUN1,
564 // WEAPON_SAW, WEAPON_ROCKETLAUNCHER, WEAPON_PISTOL, WEAPON_KASTET);
565 WEAPON_RELOAD
: Array [WEAPON_KASTET
..WEAPON_SUPERPULEMET
] of Byte =
566 (5, 2, 6, 18, 36, 2, 12, 2, 14, 2);
568 PLAYER_SIGNATURE
= $52594C50; // 'PLYR'
569 CORPSE_SIGNATURE
= $50524F43; // 'CORP'
571 BOTNAMES_FILENAME
= 'botnames.txt';
572 BOTLIST_FILENAME
= 'botlist.txt';
576 MaxCorpses
: Word = 20;
577 MaxShells
: Word = 300;
578 CurrentGib
: Integer = 0;
579 CurrentShell
: Integer = 0;
580 BotNames
: Array of String;
581 BotList
: Array of TBotProfile
;
583 function Lerp(X
, Y
, Factor
: Integer): Integer;
585 Result
:= X
+ ((Y
- X
) div Factor
);
588 function SameTeam(UID1
, UID2
: Word): Boolean;
592 if (UID1
> UID_MAX_PLAYER
) or (UID1
<= UID_MAX_GAME
) or
593 (UID2
> UID_MAX_PLAYER
) or (UID2
<= UID_MAX_GAME
) then Exit
;
595 if (g_Player_Get(UID1
) = nil) or (g_Player_Get(UID2
) = nil) then Exit
;
597 if ((g_Player_Get(UID1
).Team
= TEAM_NONE
) or
598 (g_Player_Get(UID2
).Team
= TEAM_NONE
)) then Exit
;
600 Result
:= g_Player_Get(UID1
).FTeam
= g_Player_Get(UID2
).FTeam
;
603 procedure g_Gibs_SetMax(Count
: Word);
606 SetLength(gGibs
, Count
);
608 if CurrentGib
>= Count
then
612 function g_Gibs_GetMax(): Word;
617 procedure g_Shells_SetMax(Count
: Word);
620 SetLength(gShells
, Count
);
622 if CurrentShell
>= Count
then
626 function g_Shells_GetMax(): Word;
632 procedure g_Corpses_SetMax(Count
: Word);
635 SetLength(gCorpses
, Count
);
638 function g_Corpses_GetMax(): Word;
640 Result
:= MaxCorpses
;
643 function g_Player_Create(ModelName
: String; Color
: TRGB
; Team
: Byte; Bot
: Boolean): Word;
653 // Åñòü ëè ìåñòî â gPlayers:
654 if gPlayers
<> nil then
655 for a
:= 0 to High(gPlayers
) do
656 if gPlayers
[a
] = nil then
662 // Íåò ìåñòà - ðàñøèðÿåì gPlayers:
665 SetLength(gPlayers
, Length(gPlayers
)+1);
669 // Ñîçäàåì îáúåêò èãðîêà:
671 gPlayers
[a
] := TBot
.Create()
673 gPlayers
[a
] := TPlayer
.Create();
676 gPlayers
[a
].FActualModelName
:= ModelName
;
677 gPlayers
[a
].SetModel(ModelName
);
679 // Íåò ìîäåëè - ñîçäàíèå íå âîçìîæíî:
680 if gPlayers
[a
].FModel
= nil then
684 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], [ModelName
]));
688 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
689 if Random(2) = 0 then
693 gPlayers
[a
].FPreferredTeam
:= Team
;
695 case gGameSettings
.GameMode
of
696 GM_DM
: gPlayers
[a
].FTeam
:= TEAM_NONE
;
698 GM_CTF
: gPlayers
[a
].FTeam
:= gPlayers
[a
].FPreferredTeam
;
700 GM_COOP
: gPlayers
[a
].FTeam
:= TEAM_COOP
;
703 // Åñëè êîìàíäíàÿ èãðà - êðàñèì ìîäåëü â öâåò êîìàíäû:
704 gPlayers
[a
].FColor
:= Color
;
705 if gPlayers
[a
].FTeam
in [TEAM_RED
, TEAM_BLUE
] then
706 gPlayers
[a
].FModel
.Color
:= TEAMCOLOR
[gPlayers
[a
].FTeam
]
708 gPlayers
[a
].FModel
.Color
:= Color
;
710 gPlayers
[a
].FUID
:= g_CreateUID(UID_PLAYER
);
711 gPlayers
[a
].FLive
:= False;
713 Result
:= gPlayers
[a
].FUID
;
716 function g_Player_CreateFromState(var Mem
: TBinMemoryReader
): Word;
729 if sig
<> PLAYER_SIGNATURE
then // 'PLYR'
731 raise EBinSizeError
.Create('g_Player_CreateFromState: Wrong Player Signature');
735 Mem
.ReadBoolean(Bot
);
740 // Åñòü ëè ìåñòî â gPlayers:
741 if gPlayers
<> nil then
742 for a
:= 0 to High(gPlayers
) do
743 if gPlayers
[a
] = nil then
749 // Íåò ìåñòà - ðàñøèðÿåì gPlayers:
752 SetLength(gPlayers
, Length(gPlayers
)+1);
756 // Ñîçäàåì îáúåêò èãðîêà:
758 gPlayers
[a
] := TBot
.Create()
760 gPlayers
[a
] := TPlayer
.Create();
761 gPlayers
[a
].FIamBot
:= Bot
;
762 gPlayers
[a
].FPhysics
:= True;
765 Mem
.ReadWord(gPlayers
[a
].FUID
);
767 Mem
.ReadString(gPlayers
[a
].FName
);
769 Mem
.ReadByte(gPlayers
[a
].FTeam
);
770 gPlayers
[a
].FPreferredTeam
:= gPlayers
[a
].FTeam
;
772 Mem
.ReadBoolean(gPlayers
[a
].FLive
);
773 // Èçðàñõîäîâàë ëè âñå æèçíè:
774 Mem
.ReadBoolean(gPlayers
[a
].FNoRespawn
);
778 gPlayers
[a
].FDirection
:= D_LEFT
780 gPlayers
[a
].FDirection
:= D_RIGHT
;
782 Mem
.ReadInt(gPlayers
[a
].FHealth
);
784 Mem
.ReadByte(gPlayers
[a
].FLives
);
786 Mem
.ReadInt(gPlayers
[a
].FArmor
);
788 Mem
.ReadInt(gPlayers
[a
].FAir
);
790 Mem
.ReadInt(gPlayers
[a
].FJetFuel
);
792 Mem
.ReadInt(gPlayers
[a
].FPain
);
794 Mem
.ReadInt(gPlayers
[a
].FKills
);
796 Mem
.ReadInt(gPlayers
[a
].FMonsterKills
);
798 Mem
.ReadInt(gPlayers
[a
].FFrags
);
800 Mem
.ReadByte(gPlayers
[a
].FFragCombo
);
801 // Âðåìÿ ïîñëåäíåãî ôðàãà:
802 Mem
.ReadDWORD(gPlayers
[a
].FLastFrag
);
804 Mem
.ReadInt(gPlayers
[a
].FDeath
);
806 Mem
.ReadByte(gPlayers
[a
].FFlag
);
808 Mem
.ReadInt(gPlayers
[a
].FSecrets
);
810 Mem
.ReadByte(gPlayers
[a
].FCurrWeap
);
811 // Ñëåäóþùåå æåëàåìîå îðóæèå:
812 Mem
.ReadWord(gPlayers
[a
].FNextWeap
);
814 Mem
.ReadByte(gPlayers
[a
].FNextWeapDelay
);
815 // Âðåìÿ çàðÿäêè BFG:
816 Mem
.ReadSmallInt(gPlayers
[a
].FBFGFireCounter
);
818 Mem
.ReadInt(gPlayers
[a
].FDamageBuffer
);
819 // Ïîñëåäíèé óäàðèâøèé:
820 Mem
.ReadWord(gPlayers
[a
].FLastSpawnerUID
);
821 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà:
822 Mem
.ReadByte(gPlayers
[a
].FLastHit
);
824 Obj_LoadState(@gPlayers
[a
].FObj
, Mem
);
825 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ:
826 for i
:= A_BULLETS
to A_CELLS
do
827 Mem
.ReadWord(gPlayers
[a
].FAmmo
[i
]);
828 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ:
829 for i
:= A_BULLETS
to A_CELLS
do
830 Mem
.ReadWord(gPlayers
[a
].FMaxAmmo
[i
]);
832 for i
:= WEAPON_KASTET
to WEAPON_SUPERPULEMET
do
833 Mem
.ReadBoolean(gPlayers
[a
].FWeapon
[i
]);
834 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ:
835 for i
:= WEAPON_KASTET
to WEAPON_SUPERPULEMET
do
836 Mem
.ReadWord(gPlayers
[a
].FReloading
[i
]);
840 Include(gPlayers
[a
].FRulez
, R_ITEM_BACKPACK
);
841 // Íàëè÷èå êðàñíîãî êëþ÷à:
844 Include(gPlayers
[a
].FRulez
, R_KEY_RED
);
845 // Íàëè÷èå çåëåíîãî êëþ÷à:
848 Include(gPlayers
[a
].FRulez
, R_KEY_GREEN
);
849 // Íàëè÷èå ñèíåãî êëþ÷à:
852 Include(gPlayers
[a
].FRulez
, R_KEY_BLUE
);
856 Include(gPlayers
[a
].FRulez
, R_BERSERK
);
857 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ:
858 for i
:= MR_SUIT
to MR_MAX
do
859 Mem
.ReadDWORD(gPlayers
[a
].FMegaRulez
[i
]);
860 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà:
861 for i
:= T_RESPAWN
to T_FLAGCAP
do
862 Mem
.ReadDWORD(gPlayers
[a
].FTime
[i
]);
865 Mem
.ReadString(gPlayers
[a
].FActualModelName
);
867 Mem
.ReadByte(gPlayers
[a
].FColor
.R
);
868 Mem
.ReadByte(gPlayers
[a
].FColor
.G
);
869 Mem
.ReadByte(gPlayers
[a
].FColor
.B
);
870 // Îáíîâëÿåì ìîäåëü èãðîêà:
871 gPlayers
[a
].SetModel(gPlayers
[a
].FActualModelName
);
873 // Íåò ìîäåëè - ñîçäàíèå íå âîçìîæíî:
874 if gPlayers
[a
].FModel
= nil then
878 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], [gPlayers
[a
].FActualModelName
]));
882 // Åñëè êîìàíäíàÿ èãðà - êðàñèì ìîäåëü â öâåò êîìàíäû:
883 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
884 gPlayers
[a
].FModel
.Color
:= TEAMCOLOR
[gPlayers
[a
].FTeam
]
886 gPlayers
[a
].FModel
.Color
:= gPlayers
[a
].FColor
;
888 Result
:= gPlayers
[a
].FUID
;
891 procedure g_Player_ResetTeams();
895 if g_Game_IsClient
then
897 if gPlayers
= nil then
899 for a
:= Low(gPlayers
) to High(gPlayers
) do
900 if gPlayers
[a
] <> nil then
901 case gGameSettings
.GameMode
of
903 gPlayers
[a
].ChangeTeam(TEAM_NONE
);
905 if not (gPlayers
[a
].Team
in [TEAM_RED
, TEAM_BLUE
]) then
906 if gPlayers
[a
].FPreferredTeam
in [TEAM_RED
, TEAM_BLUE
] then
907 gPlayers
[a
].ChangeTeam(gPlayers
[a
].FPreferredTeam
)
910 gPlayers
[a
].ChangeTeam(TEAM_RED
)
912 gPlayers
[a
].ChangeTeam(TEAM_BLUE
);
915 gPlayers
[a
].ChangeTeam(TEAM_COOP
);
919 procedure g_Bot_Add(Team
, Difficult
: Byte);
922 _name
, _model
: String;
925 if not g_Game_IsServer
then Exit
;
927 // Ñïèñîê íàçâàíèé ìîäåëåé:
928 m
:= g_PlayerModel_GetNames();
933 if (gGameSettings
.GameType
= GT_SINGLE
) or (gGameSettings
.GameMode
= GM_COOP
) then
934 Team
:= TEAM_COOP
// COOP
936 if gGameSettings
.GameMode
= GM_DM
then
937 Team
:= TEAM_NONE
// DM
939 if Team
= TEAM_NONE
then // CTF / TDM
941 // Àâòîáàëàíñ êîìàíä:
945 for a
:= 0 to High(gPlayers
) do
946 if gPlayers
[a
] <> nil then
948 if gPlayers
[a
].Team
= TEAM_RED
then
951 if gPlayers
[a
].Team
= TEAM_BLUE
then
961 if Random(2) = 0 then
967 // Âûáèðàåì áîòó èìÿ:
969 if BotNames
<> nil then
970 for a
:= 0 to High(BotNames
) do
971 if g_Player_ValidName(BotNames
[a
]) then
973 _name
:= BotNames
[a
];
977 // Èìåíè íåò, çàäàåì ñëó÷àéíîå:
980 _name
:= Format('DFBOT%.2d', [Random(100)]);
981 until g_Player_ValidName(_name
);
983 // Âûáèðàåì ñëó÷àéíóþ ìîäåëü:
984 _model
:= m
[Random(Length(m
))];
987 with g_Player_Get(g_Player_Create(_model
,
988 _RGB(Min(Random(9)*32, 255),
989 Min(Random(9)*32, 255),
990 Min(Random(9)*32, 255)),
991 Team
, True)) as TBot
do
996 1: FDifficult
:= DIFFICULT_EASY
;
997 2: FDifficult
:= DIFFICULT_MEDIUM
;
998 else FDifficult
:= DIFFICULT_HARD
;
1001 for a
:= WEAPON_KASTET
to WEAPON_SUPERPULEMET
do
1003 FDifficult
.WeaponPrior
[a
] := WEAPON_PRIOR1
[a
];
1004 FDifficult
.CloseWeaponPrior
[a
] := WEAPON_PRIOR2
[a
];
1005 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
1008 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [Name
]), True);
1010 if g_Game_IsNet
then MH_SEND_PlayerCreate(UID
);
1011 if g_Game_IsServer
and (gGameSettings
.MaxLives
> 0) then
1016 procedure g_Bot_AddList(Team
: Byte; lName
: ShortString; num
: Integer = -1);
1019 _name
, _model
: String;
1022 if not g_Game_IsServer
then Exit
;
1024 // Ñïèñîê íàçâàíèé ìîäåëåé:
1025 m
:= g_PlayerModel_GetNames();
1030 if (gGameSettings
.GameType
= GT_SINGLE
) or (gGameSettings
.GameMode
= GM_COOP
) then
1031 Team
:= TEAM_COOP
// COOP
1033 if gGameSettings
.GameMode
= GM_DM
then
1034 Team
:= TEAM_NONE
// DM
1036 if Team
= TEAM_NONE
then
1037 Team
:= BotList
[num
].team
; // CTF / TDM
1039 // Âûáèðàåì íàñòðîéêè áîòà èç ñïèñêà ïî íîìåðó èëè èìåíè:
1040 lName
:= AnsiLowerCase(lName
);
1041 if (num
< 0) or (num
> Length(BotList
)-1) then
1043 if (num
= -1) and (lName
<> '') and (BotList
<> nil) then
1044 for a
:= 0 to High(BotList
) do
1045 if AnsiLowerCase(BotList
[a
].name
) = lName
then
1054 _name
:= BotList
[num
].name
;
1055 // Çàíÿòî - âûáèðàåì ñëó÷àéíîå:
1056 if not g_Player_ValidName(_name
) then
1058 _name
:= Format('DFBOT%.2d', [Random(100)]);
1059 until g_Player_ValidName(_name
);
1062 _model
:= BotList
[num
].model
;
1063 // Íåò òàêîé - âûáèðàåì ñëó÷àéíóþ:
1064 if not InSArray(_model
, m
) then
1065 _model
:= m
[Random(Length(m
))];
1068 with g_Player_Get(g_Player_Create(_model
, BotList
[num
].color
, Team
, True)) as TBot
do
1072 FDifficult
.DiagFire
:= BotList
[num
].diag_fire
;
1073 FDifficult
.InvisFire
:= BotList
[num
].invis_fire
;
1074 FDifficult
.DiagPrecision
:= BotList
[num
].diag_precision
;
1075 FDifficult
.FlyPrecision
:= BotList
[num
].fly_precision
;
1076 FDifficult
.Cover
:= BotList
[num
].cover
;
1077 FDifficult
.CloseJump
:= BotList
[num
].close_jump
;
1079 for a
:= WEAPON_KASTET
to WEAPON_SUPERPULEMET
do
1081 FDifficult
.WeaponPrior
[a
] := BotList
[num
].w_prior1
[a
];
1082 FDifficult
.CloseWeaponPrior
[a
] := BotList
[num
].w_prior2
[a
];
1083 //FDifficult.SafeWeaponPrior[a] := BotList[num].w_prior3[a];
1086 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [Name
]), True);
1088 if g_Game_IsNet
then MH_SEND_PlayerCreate(UID
);
1092 procedure g_Bot_RemoveAll();
1096 if not g_Game_IsServer
then Exit
;
1097 if gPlayers
= nil then Exit
;
1099 for a
:= 0 to High(gPlayers
) do
1100 if gPlayers
[a
] <> nil then
1101 if gPlayers
[a
] is TBot
then
1103 gPlayers
[a
].Lives
:= 0;
1104 gPlayers
[a
].Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
1105 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [gPlayers
[a
].Name
]), True);
1106 g_Player_Remove(gPlayers
[a
].FUID
);
1112 procedure g_Bot_MixNames();
1117 if BotNames
<> nil then
1118 for a
:= 0 to High(BotNames
) do
1120 b
:= Random(Length(BotNames
));
1122 Botnames
[a
] := BotNames
[b
];
1127 procedure g_Player_Remove(UID
: Word);
1131 if gPlayers
= nil then Exit
;
1133 if g_Game_IsServer
and g_Game_IsNet
then
1134 MH_SEND_PlayerDelete(UID
);
1136 for i
:= 0 to High(gPlayers
) do
1137 if gPlayers
[i
] <> nil then
1138 if gPlayers
[i
].FUID
= UID
then
1140 if gPlayers
[i
] is TPlayer
then
1141 TPlayer(gPlayers
[i
]).Free()
1143 TBot(gPlayers
[i
]).Free();
1149 procedure g_Player_Init();
1159 if not FileExists(DataDir
+ BOTNAMES_FILENAME
) then
1162 // ×èòàåì âîçìîæíûå èìåíà áîòîâ èç ôàéëà:
1163 AssignFile(F
, DataDir
+ BOTNAMES_FILENAME
);
1174 SetLength(BotNames
, Length(BotNames
)+1);
1175 BotNames
[High(BotNames
)] := s
;
1183 // ×èòàåì ôàéë ñ ïàðàìåòðàìè áîòîâ:
1184 config
:= TConfig
.CreateFile(DataDir
+ BOTLIST_FILENAME
);
1188 while config
.SectionExists(IntToStr(a
)) do
1190 SetLength(BotList
, Length(BotList
)+1);
1192 with BotList
[High(BotList
)] do
1195 name
:= config
.ReadStr(IntToStr(a
), 'name', '');
1197 model
:= config
.ReadStr(IntToStr(a
), 'model', '');
1199 if config
.ReadStr(IntToStr(a
), 'team', 'red') = 'red' then
1204 sa
:= parse(config
.ReadStr(IntToStr(a
), 'color', ''));
1205 color
.R
:= StrToIntDef(sa
[0], 0);
1206 color
.G
:= StrToIntDef(sa
[1], 0);
1207 color
.B
:= StrToIntDef(sa
[2], 0);
1208 // Âåðîÿòíîñòü ñòðåëüáû ïîä óãëîì:
1209 diag_fire
:= config
.ReadInt(IntToStr(a
), 'diag_fire', 0);
1210 // Âåðîÿòíîñòü îòâåòíîãî îãíÿ ïî íåâèäèìîìó ñîïåðíèêó:
1211 invis_fire
:= config
.ReadInt(IntToStr(a
), 'invis_fire', 0);
1212 // Òî÷íîñòü ñòðåëüáû ïîä óãëîì:
1213 diag_precision
:= config
.ReadInt(IntToStr(a
), 'diag_precision', 0);
1214 // Òî÷íîñòü ñòðåëüáû â ïîëåòå:
1215 fly_precision
:= config
.ReadInt(IntToStr(a
), 'fly_precision', 0);
1216 // Òî÷íîñòü óêëîíåíèÿ îò ñíàðÿäîâ:
1217 cover
:= config
.ReadInt(IntToStr(a
), 'cover', 0);
1218 // Âåðîÿòíîñòü ïðûæêà ïðè ïðèáëèæåíèè ñîïåðíèêà:
1219 close_jump
:= config
.ReadInt(IntToStr(a
), 'close_jump', 0);
1220 // Ïðèîðèòåòû îðóæèÿ äëÿ äàëüíåãî áîÿ:
1221 sa
:= parse(config
.ReadStr(IntToStr(a
), 'w_prior1', ''));
1222 if Length(sa
) = 10 then
1224 w_prior1
[b
] := EnsureRange(StrToInt(sa
[b
]), 0, 9);
1225 // Ïðèîðèòåòû îðóæèÿ äëÿ áëèæíåãî áîÿ:
1226 sa
:= parse(config
.ReadStr(IntToStr(a
), 'w_prior2', ''));
1227 if Length(sa
) = 10 then
1229 w_prior2
[b
] := EnsureRange(StrToInt(sa
[b
]), 0, 9);
1231 {sa := parse(config.ReadStr(IntToStr(a), 'w_prior3', ''));
1232 if Length(sa) = 10 then
1234 w_prior3[b] := EnsureRange(StrToInt(sa[b]), 0, 9);}
1243 procedure g_Player_Free();
1247 if gPlayers
<> nil then
1249 for i
:= 0 to High(gPlayers
) do
1250 if gPlayers
[i
] <> nil then
1252 if gPlayers
[i
] is TPlayer
then
1253 TPlayer(gPlayers
[i
]).Free()
1255 TBot(gPlayers
[i
]).Free();
1266 procedure g_Player_UpdateAll();
1270 if gPlayers
= nil then Exit
;
1272 for i
:= 0 to High(gPlayers
) do
1273 if gPlayers
[i
] <> nil then
1274 if gPlayers
[i
] is TPlayer
then gPlayers
[i
].Update()
1275 else TBot(gPlayers
[i
]).Update();
1278 procedure g_Player_DrawAll();
1282 if gPlayers
= nil then Exit
;
1284 for i
:= 0 to High(gPlayers
) do
1285 if gPlayers
[i
] <> nil then
1286 if gPlayers
[i
] is TPlayer
then gPlayers
[i
].Draw()
1287 else TBot(gPlayers
[i
]).Draw();
1290 procedure g_Player_DrawDebug(p
: TPlayer
);
1294 if p
= nil then Exit
;
1295 if (@p
.FObj
) = nil then Exit
;
1297 e_TextureFontGetSize(gStdFont
, fW
, fH
);
1299 e_TextureFontPrint(0, 0 , 'Pos X: ' + IntToStr(p
.FObj
.X
), gStdFont
);
1300 e_TextureFontPrint(0, fH
, 'Pos Y: ' + IntToStr(p
.FObj
.Y
), gStdFont
);
1301 e_TextureFontPrint(0, fH
* 2, 'Vel X: ' + IntToStr(p
.FObj
.Vel
.X
), gStdFont
);
1302 e_TextureFontPrint(0, fH
* 3, 'Vel Y: ' + IntToStr(p
.FObj
.Vel
.Y
), gStdFont
);
1303 e_TextureFontPrint(0, fH
* 4, 'Acc X: ' + IntToStr(p
.FObj
.Accel
.X
), gStdFont
);
1304 e_TextureFontPrint(0, fH
* 5, 'Acc Y: ' + IntToStr(p
.FObj
.Accel
.Y
), gStdFont
);
1307 procedure g_Player_DrawHealth();
1312 if gPlayers
= nil then Exit
;
1313 e_TextureFontGetSize(gStdFont
, fW
, fH
);
1315 for i
:= 0 to High(gPlayers
) do
1316 if gPlayers
[i
] <> nil then
1318 e_TextureFontPrint(gPlayers
[i
].FObj
.X
+ gPlayers
[i
].FObj
.Rect
.X
,
1319 gPlayers
[i
].FObj
.Y
+ gPlayers
[i
].FObj
.Rect
.Y
+ gPlayers
[i
].FObj
.Rect
.Height
- fH
* 2,
1320 IntToStr(gPlayers
[i
].FHealth
), gStdFont
);
1321 e_TextureFontPrint(gPlayers
[i
].FObj
.X
+ gPlayers
[i
].FObj
.Rect
.X
,
1322 gPlayers
[i
].FObj
.Y
+ gPlayers
[i
].FObj
.Rect
.Y
+ gPlayers
[i
].FObj
.Rect
.Height
- fH
,
1323 IntToStr(gPlayers
[i
].FArmor
), gStdFont
);
1327 function g_Player_Get(UID
: Word): TPlayer
;
1333 if gPlayers
= nil then
1336 for a
:= 0 to High(gPlayers
) do
1337 if gPlayers
[a
] <> nil then
1338 if gPlayers
[a
].FUID
= UID
then
1340 Result
:= gPlayers
[a
];
1345 function g_Player_GetCount(): Byte;
1351 if gPlayers
= nil then
1354 for a
:= 0 to High(gPlayers
) do
1355 if gPlayers
[a
] <> nil then
1356 Result
:= Result
+ 1;
1359 function g_Player_GetStats(): TPlayerStatArray
;
1365 if gPlayers
= nil then Exit
;
1367 for a
:= 0 to High(gPlayers
) do
1368 if gPlayers
[a
] <> nil then
1370 SetLength(Result
, Length(Result
)+1);
1371 with Result
[High(Result
)] do
1373 Ping
:= gPlayers
[a
].FPing
;
1374 Loss
:= gPlayers
[a
].FLoss
;
1375 Name
:= gPlayers
[a
].FName
;
1376 Team
:= gPlayers
[a
].FTeam
;
1377 Frags
:= gPlayers
[a
].FFrags
;
1378 Deaths
:= gPlayers
[a
].FDeath
;
1379 Kills
:= gPlayers
[a
].FKills
;
1380 Color
:= gPlayers
[a
].FModel
.Color
;
1381 Lives
:= gPlayers
[a
].FLives
;
1382 Spectator
:= gPlayers
[a
].FSpectator
;
1387 procedure g_Player_RememberAll
;
1391 for i
:= Low(gPlayers
) to High(gPlayers
) do
1392 if (gPlayers
[i
] <> nil) and gPlayers
[i
].Live
then
1393 gPlayers
[i
].RememberState
;
1396 procedure g_Player_ResetAll(Force
, Silent
: Boolean);
1400 gTeamStat
[TEAM_RED
].Goals
:= 0;
1401 gTeamStat
[TEAM_BLUE
].Goals
:= 0;
1403 if gPlayers
<> nil then
1404 for i
:= 0 to High(gPlayers
) do
1405 if gPlayers
[i
] <> nil then
1407 gPlayers
[i
].Reset(Force
);
1409 if gPlayers
[i
] is TPlayer
then
1411 if (not gPlayers
[i
].FSpectator
) or gPlayers
[i
].FWantsInGame
then
1412 gPlayers
[i
].Respawn(Silent
)
1414 gPlayers
[i
].Spectate();
1417 TBot(gPlayers
[i
]).Respawn(Silent
);
1421 procedure g_Player_CreateCorpse(Player
: TPlayer
);
1428 if Player
.FObj
.Y
>= gMapInfo
.Height
+128 then
1433 if (FHealth
>= -50) or (gGibsCount
= 0) then
1435 if (gCorpses
= nil) or (Length(gCorpses
) = 0) then
1439 for find_id
:= 0 to High(gCorpses
) do
1440 if gCorpses
[find_id
] = nil then
1447 find_id
:= Random(Length(gCorpses
));
1449 gCorpses
[find_id
] := TCorpse
.Create(FObj
.X
, FObj
.Y
, FModel
.Name
, FHealth
< -20);
1450 gCorpses
[find_id
].FColor
:= FModel
.Color
;
1451 gCorpses
[find_id
].FObj
.Vel
:= FObj
.Vel
;
1452 gCorpses
[find_id
].FObj
.Accel
:= FObj
.Accel
;
1455 g_Player_CreateGibs(FObj
.X
+ PLAYER_RECT_CX
,
1456 FObj
.Y
+ PLAYER_RECT_CY
,
1457 FModel
.Name
, FModel
.Color
);
1461 procedure g_Player_CreateShell(fX
, fY
, dX
, dY
: Integer; T
: Byte);
1465 if (gShells
= nil) or (Length(gShells
) = 0) then
1468 with gShells
[CurrentShell
] do
1474 if T
= SHELL_BULLET
then
1476 if g_Texture_Get('TEXTURE_SHELL_BULLET', SID
) then
1480 Obj
.Rect
.Width
:= 4;
1481 Obj
.Rect
.Height
:= 2;
1485 if g_Texture_Get('TEXTURE_SHELL_SHELL', SID
) then
1489 Obj
.Rect
.Width
:= 7;
1490 Obj
.Rect
.Height
:= 3;
1496 g_Obj_Push(@Obj
, dX
+ Random(4)-Random(4), dY
-Random(4));
1497 RAngle
:= Random(360);
1498 Timeout
:= gTime
+ SHELL_TIMEOUT
;
1500 if CurrentShell
>= High(gShells
) then
1507 procedure g_Player_CreateGibs(fX
, fY
: Integer; ModelName
: string; fColor
: TRGB
);
1510 GibsArray
: TGibsArray
;
1512 if (gGibs
= nil) or (Length(gGibs
) = 0) then
1514 if not g_PlayerModel_GetGibs(ModelName
, GibsArray
) then
1517 for a
:= 0 to High(GibsArray
) do
1518 with gGibs
[CurrentGib
] do
1521 ID
:= GibsArray
[a
].ID
;
1522 MaskID
:= GibsArray
[a
].MaskID
;
1525 Obj
.Rect
:= GibsArray
[a
].Rect
;
1526 Obj
.X
:= fX
-GibsArray
[a
].Rect
.X
-(GibsArray
[a
].Rect
.Width
div 2);
1527 Obj
.Y
:= fY
-GibsArray
[a
].Rect
.Y
-(GibsArray
[a
].Rect
.Height
div 2);
1528 g_Obj_PushA(@Obj
, 25 + Random(10), Random(361));
1529 RAngle
:= Random(360);
1531 if gBloodCount
> 0 then
1532 g_GFX_Blood(fX
, fY
, 16*gBloodCount
+Random(5*gBloodCount
), -16+Random(33), -16+Random(33),
1533 Random(48), Random(48), 150, 0, 0);
1535 if CurrentGib
>= High(gGibs
) then
1542 procedure g_Player_UpdatePhysicalObjects();
1548 procedure ShellSound_Bounce(X
, Y
: Integer; T
: Byte);
1553 if T
= SHELL_BULLET
then
1554 g_Sound_PlayExAt('SOUND_PLAYER_CASING' + IntToStr(k
), X
, Y
)
1556 g_Sound_PlayExAt('SOUND_PLAYER_SHELL' + IntToStr(k
), X
, Y
);
1561 if gGibs
<> nil then
1562 for i
:= 0 to High(gGibs
) do
1563 if gGibs
[i
].Live
then
1567 mr
:= g_Obj_Move(@Obj
, True, False, True);
1569 if WordBool(mr
and MOVE_FALLOUT
) then
1575 // Îòëåòàåò îò óäàðà î ñòåíó/ïîòîëîê/ïîë:
1576 if WordBool(mr
and MOVE_HITWALL
) then
1577 Obj
.Vel
.X
:= -(vel
.X
div 2);
1578 if WordBool(mr
and (MOVE_HITCEIL
or MOVE_HITLAND
)) then
1579 Obj
.Vel
.Y
:= -(vel
.Y
div 2);
1581 if (Obj
.Vel
.X
>= 0) then
1583 RAngle
:= RAngle
+ Abs(Obj
.Vel
.X
)*6 + Abs(Obj
.Vel
.Y
);
1584 if RAngle
>= 360 then
1585 RAngle
:= RAngle
mod 360;
1586 end else begin // Counter-clockwise
1587 RAngle
:= RAngle
- Abs(Obj
.Vel
.X
)*6 - Abs(Obj
.Vel
.Y
);
1589 RAngle
:= (360 - (Abs(RAngle
) mod 360)) mod 360;
1592 // Ñîïðîòèâëåíèå âîçäóõà äëÿ êóñêà òðóïà:
1593 if gTime
mod (GAME_TICK
*3) = 0 then
1594 Obj
.Vel
.X
:= z_dec(Obj
.Vel
.X
, 1);
1598 if gCorpses
<> nil then
1599 for i
:= 0 to High(gCorpses
) do
1600 if gCorpses
[i
] <> nil then
1601 if gCorpses
[i
].State
= CORPSE_STATE_REMOVEME
then
1607 gCorpses
[i
].Update();
1610 if gShells
<> nil then
1611 for i
:= 0 to High(gShells
) do
1612 if gShells
[i
].Live
then
1616 mr
:= g_Obj_Move(@Obj
, True, False, True);
1618 if WordBool(mr
and MOVE_FALLOUT
) or (gShells
[i
].Timeout
< gTime
) then
1624 // Îòëåòàåò îò óäàðà î ñòåíó/ïîòîëîê/ïîë:
1625 if WordBool(mr
and MOVE_HITWALL
) then
1627 Obj
.Vel
.X
:= -(vel
.X
div 2);
1628 if not WordBool(mr
and MOVE_INWATER
) then
1629 ShellSound_Bounce(Obj
.X
, Obj
.Y
, SType
);
1631 if WordBool(mr
and (MOVE_HITCEIL
or MOVE_HITLAND
)) then
1633 Obj
.Vel
.Y
:= -(vel
.Y
div 2);
1634 if Obj
.Vel
.X
<> 0 then Obj
.Vel
.X
:= Obj
.Vel
.X
div 2;
1635 if (Obj
.Vel
.X
= 0) and (Obj
.Vel
.Y
= 0) then
1637 if RAngle
mod 90 <> 0 then
1638 RAngle
:= (RAngle
div 90) * 90;
1640 else if not WordBool(mr
and MOVE_INWATER
) then
1641 ShellSound_Bounce(Obj
.X
, Obj
.Y
, SType
);
1644 if (Obj
.Vel
.X
>= 0) then
1646 RAngle
:= RAngle
+ Abs(Obj
.Vel
.X
)*8 + Abs(Obj
.Vel
.Y
);
1647 if RAngle
>= 360 then
1648 RAngle
:= RAngle
mod 360;
1649 end else begin // Counter-clockwise
1650 RAngle
:= RAngle
- Abs(Obj
.Vel
.X
)*8 - Abs(Obj
.Vel
.Y
);
1652 RAngle
:= (360 - (Abs(RAngle
) mod 360)) mod 360;
1657 procedure g_Player_DrawCorpses();
1662 if gGibs
<> nil then
1663 for i
:= 0 to High(gGibs
) do
1664 if gGibs
[i
].Live
then
1667 if not g_Obj_Collide(sX
, sY
, sWidth
, sHeight
, @Obj
) then
1670 a
.X
:= Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2);
1671 a
.y
:= Obj
.Rect
.Y
+(Obj
.Rect
.Height
div 2);
1673 e_DrawAdv(ID
, Obj
.X
, Obj
.Y
, 0, True, False, RAngle
, @a
, M_NONE
);
1676 e_DrawAdv(MaskID
, Obj
.X
, Obj
.Y
, 0, True, False, RAngle
, @a
, M_NONE
);
1682 if gCorpses
<> nil then
1683 for i
:= 0 to High(gCorpses
) do
1684 if gCorpses
[i
] <> nil then
1688 procedure g_Player_DrawShells();
1693 if gShells
<> nil then
1694 for i
:= 0 to High(gShells
) do
1695 if gShells
[i
].Live
then
1698 if not g_Obj_Collide(sX
, sY
, sWidth
, sHeight
, @Obj
) then
1704 e_DrawAdv(SpriteID
, Obj
.X
, Obj
.Y
, 0, True, False, RAngle
, @a
, M_NONE
);
1708 procedure g_Player_RemoveAllCorpses();
1714 SetLength(gGibs
, MaxGibs
);
1715 SetLength(gShells
, MaxGibs
);
1719 if gCorpses
<> nil then
1720 for i
:= 0 to High(gCorpses
) do
1724 SetLength(gCorpses
, MaxCorpses
);
1727 procedure g_Player_Corpses_SaveState(var Mem
: TBinMemoryWriter
);
1732 // Ñ÷èòàåì êîëè÷åñòâî ñóùåñòâóþùèõ òðóïîâ:
1734 if gCorpses
<> nil then
1735 for i
:= 0 to High(gCorpses
) do
1736 if gCorpses
[i
] <> nil then
1739 Mem
:= TBinMemoryWriter
.Create((count
+1) * 128);
1741 // Êîëè÷åñòâî òðóïîâ:
1742 Mem
.WriteInt(count
);
1748 for i
:= 0 to High(gCorpses
) do
1749 if gCorpses
[i
] <> nil then
1752 Mem
.WriteString(gCorpses
[i
].FModelName
);
1754 b
:= gCorpses
[i
].Mess
;
1755 Mem
.WriteBoolean(b
);
1756 // Ñîõðàíÿåì äàííûå òðóïà:
1757 gCorpses
[i
].SaveState(Mem
);
1761 procedure g_Player_Corpses_LoadState(var Mem
: TBinMemoryReader
);
1770 g_Player_RemoveAllCorpses();
1772 // Êîëè÷åñòâî òðóïîâ:
1775 if count
> Length(gCorpses
) then
1777 raise EBinSizeError
.Create('g_Player_Corpses_LoadState: Too Many Corpses');
1784 for i
:= 0 to count
-1 do
1787 Mem
.ReadString(str
);
1791 gCorpses
[i
] := TCorpse
.Create(0, 0, str
, b
);
1792 // Çàãðóæàåì äàííûå òðóïà:
1793 gCorpses
[i
].LoadState(Mem
);
1799 procedure TPlayer
.BFGHit();
1801 g_Weapon_BFGHit(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
1802 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2));
1803 if g_Game_IsServer
and g_Game_IsNet
then
1804 MH_SEND_Effect(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
1805 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2),
1809 procedure TPlayer
.ChangeModel(ModelName
: string);
1811 Model
: TPlayerModel
;
1813 Model
:= g_PlayerModel_Get(ModelName
);
1814 if Model
= nil then Exit
;
1820 procedure TPlayer
.SetModel(ModelName
: string);
1824 m
:= g_PlayerModel_Get(ModelName
);
1827 g_SimpleError(Format(_lc
[I_GAME_ERROR_MODEL_FALLBACK
], [ModelName
]));
1828 m
:= g_PlayerModel_Get('doomer');
1831 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], ['doomer']));
1836 if FModel
<> nil then
1841 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
1842 FModel
.Color
:= FColor
1844 FModel
.Color
:= TEAMCOLOR
[FTeam
];
1845 FModel
.SetWeapon(FCurrWeap
);
1846 FModel
.SetFlag(FFlag
);
1847 SetDirection(FDirection
);
1850 procedure TPlayer
.SetColor(Color
: TRGB
);
1853 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
1854 if FModel
<> nil then FModel
.Color
:= Color
;
1857 procedure TPlayer
.SwitchTeam
;
1859 if g_Game_IsClient
then
1861 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then Exit
;
1863 if gGameOn
and FLive
then
1864 Kill(K_SIMPLEKILL
, FUID
, HIT_SELF
);
1866 if FTeam
= TEAM_RED
then
1868 ChangeTeam(TEAM_BLUE
);
1869 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_BLUE
], [FName
]), True);
1870 if g_Game_IsNet
then
1871 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM
, TEAM_BLUE
, FName
);
1875 ChangeTeam(TEAM_RED
);
1876 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_RED
], [FName
]), True);
1877 if g_Game_IsNet
then
1878 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM
, TEAM_RED
, FName
);
1880 FPreferredTeam
:= FTeam
;
1883 procedure TPlayer
.ChangeTeam(Team
: Byte);
1890 TEAM_RED
, TEAM_BLUE
:
1891 FModel
.Color
:= TEAMCOLOR
[Team
];
1893 FModel
.Color
:= FColor
;
1895 if (FTeam
<> OldTeam
) and g_Game_IsNet
and g_Game_IsServer
then
1896 MH_SEND_PlayerStats(FUID
);
1900 procedure TPlayer.CollideItem();
1905 if gItems = nil then Exit;
1906 if not FLive then Exit;
1908 for i := 0 to High(gItems) do
1911 if (ItemType <> ITEM_NONE) and Live then
1912 if g_Obj_Collide(FObj.X+PLAYER_RECT.X, FObj.Y+PLAYER_RECT.Y, PLAYER_RECT.Width,
1913 PLAYER_RECT.Height, @Obj) then
1915 if not PickItem(ItemType, gItems[i].Respawnable, r) then Continue;
1917 if ItemType in [ITEM_SPHERE_BLUE, ITEM_SPHERE_WHITE, ITEM_INVUL] then
1918 g_Sound_PlayExAt('SOUND_ITEM_GETRULEZ', FObj.X, FObj.Y)
1919 else if ItemType in [ITEM_MEDKIT_SMALL, ITEM_MEDKIT_LARGE, ITEM_MEDKIT_BLACK] then
1920 g_Sound_PlayExAt('SOUND_ITEM_GETMED', FObj.X, FObj.Y)
1921 else g_Sound_PlayExAt('SOUND_ITEM_GETITEM', FObj.X, FObj.Y);
1923 // Íàäî óáðàòü ñ êàðòû, åñëè ýòî íå êëþ÷, êîòîðûì íóæíî ïîäåëèòñÿ ñ äðóãèì èãðîêîì:
1924 if r and not ((ItemType in [ITEM_KEY_RED, ITEM_KEY_GREEN, ITEM_KEY_BLUE]) and
1925 (gGameSettings.GameType = GT_SINGLE) and
1926 (g_Player_GetCount() > 1)) then
1927 if not Respawnable then g_Items_Remove(i) else g_Items_Pick(i);
1933 function TPlayer
.CollideLevel(XInc
, YInc
: Integer): Boolean;
1935 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
1936 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_WALL
,
1940 constructor TPlayer
.Create();
1946 FSawSound
:= TPlayableSound
.Create();
1947 FSawSoundIdle
:= TPlayableSound
.Create();
1948 FSawSoundHit
:= TPlayableSound
.Create();
1949 FSawSoundSelect
:= TPlayableSound
.Create();
1950 FJetSoundFly
:= TPlayableSound
.Create();
1951 FJetSoundOn
:= TPlayableSound
.Create();
1952 FJetSoundOff
:= TPlayableSound
.Create();
1954 FSawSound
.SetByName('SOUND_WEAPON_FIRESAW');
1955 FSawSoundIdle
.SetByName('SOUND_WEAPON_IDLESAW');
1956 FSawSoundHit
.SetByName('SOUND_WEAPON_HITSAW');
1957 FSawSoundSelect
.SetByName('SOUND_WEAPON_SELECTSAW');
1958 FJetSoundFly
.SetByName('SOUND_PLAYER_JETFLY');
1959 FJetSoundOn
.SetByName('SOUND_PLAYER_JETON');
1960 FJetSoundOff
.SetByName('SOUND_PLAYER_JETOFF');
1962 FSpectatePlayer
:= -1;
1966 FSavedState
.WaitRecall
:= False;
1969 FActualModelName
:= 'doomer';
1972 FObj
.Rect
:= PLAYER_RECT
;
1974 FBFGFireCounter
:= -1;
1975 FJustTeleported
:= False;
1981 procedure TPlayer
.Damage(value
: Word; SpawnerUID
: Word; vx
, vy
: Integer; t
: Byte);
1985 if (not g_Game_IsClient
) and (not FLive
) then
1990 // Íåóÿçâèìîñòü íå ñïàñàåò îò ëîâóøåê:
1991 if ((t
= HIT_TRAP
) or (t
= HIT_SELF
)) and (not FGodMode
) then
1993 if not g_Game_IsClient
then
1996 if t
= HIT_TRAP
then
1998 // Ëîâóøêà óáèâàåò ñðàçó:
2000 Kill(K_EXTRAHARDKILL
, SpawnerUID
, t
);
2002 if t
= HIT_SELF
then
2006 Kill(K_SIMPLEKILL
, SpawnerUID
, t
);
2009 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
2010 FMegaRulez
[MR_SUIT
] := 0;
2011 FMegaRulez
[MR_INVUL
] := 0;
2012 FMegaRulez
[MR_INVIS
] := 0;
2016 // Íî îò îñòàëüíîãî ñïàñàåò:
2017 if FMegaRulez
[MR_INVUL
] >= gTime
then
2024 // Åñëè åñòü óðîí ñâîèì, èëè ðàíèë ñàì ñåáÿ, èëè òåáÿ ðàíèë ïðîòèâíèê:
2025 if LongBool(gGameSettings
.Options
and GAME_OPTION_TEAMDAMAGE
) or
2026 (SpawnerUID
= FUID
) or
2027 (not SameTeam(FUID
, SpawnerUID
)) then
2029 FLastSpawnerUID
:= SpawnerUID
;
2031 // Êðîâü (ïóçûðüêè, åñëè â âîäå):
2032 if gBloodCount
> 0 then
2034 c
:= Min(value
, 200)*gBloodCount
+ Random(Min(value
, 200) div 2);
2035 if value
div 4 <= c
then
2036 c
:= c
- (value
div 4)
2040 if (t
= HIT_SOME
) and (vx
= 0) and (vy
= 0) then
2044 HIT_TRAP
, HIT_ACID
, HIT_FLAME
, HIT_SELF
: MakeBloodSimple(c
);
2045 HIT_BFG
, HIT_ROCKET
, HIT_SOME
: MakeBloodVector(c
, vx
, vy
);
2048 if t
= HIT_WATER
then
2049 g_GFX_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
2050 FObj
.Y
+PLAYER_RECT
.Y
-4, value
div 2, 8, 4);
2055 Inc(FDamageBuffer
, value
);
2059 FPain
:= FPain
+ value
;
2062 if g_Game_IsServer
and g_Game_IsNet
then
2064 MH_SEND_PlayerDamage(FUID
, t
, SpawnerUID
, value
, vx
, vy
);
2065 MH_SEND_PlayerStats(FUID
);
2066 MH_SEND_PlayerPos(False, FUID
);
2070 function TPlayer
.Heal(value
: Word; Soft
: Boolean): Boolean;
2073 if g_Game_IsClient
then
2078 if Soft
and (FHealth
< PLAYER_HP_SOFT
) then
2080 IncMax(FHealth
, value
, PLAYER_HP_SOFT
);
2083 if (not Soft
) and (FHealth
< PLAYER_HP_LIMIT
) then
2085 IncMax(FHealth
, value
, PLAYER_HP_LIMIT
);
2089 if Result
and g_Game_IsServer
and g_Game_IsNet
then
2090 MH_SEND_PlayerStats(FUID
);
2093 destructor TPlayer
.Destroy();
2095 if (gPlayer1
<> nil) and (gPlayer1
.FUID
= FUID
) then
2097 if (gPlayer2
<> nil) and (gPlayer2
.FUID
= FUID
) then
2101 FSawSoundIdle
.Free();
2102 FSawSoundHit
.Free();
2103 FJetSoundFly
.Free();
2105 FJetSoundOff
.Free();
2111 procedure TPlayer
.DrawBubble();
2113 bubX
, bubY
: Integer;
2116 Rw
, Gw
, Bw
: SmallInt;
2119 bubX
:= FObj
.X
+FObj
.Rect
.X
+ IfThen(FDirection
= D_LEFT
, -4, 18);
2120 bubY
:= FObj
.Y
+FObj
.Rect
.Y
- 18;
2128 1: // simple textual non-bubble
2130 bubX
:= FObj
.X
+FObj
.Rect
.X
- 11;
2131 bubY
:= FObj
.Y
+FObj
.Rect
.Y
- 17;
2132 e_TextureFontPrint(bubX
, bubY
, '[...]', gStdFont
);
2135 2: // advanced pixel-perfect bubble
2137 if FTeam
= TEAM_RED
then
2140 if FTeam
= TEAM_BLUE
then
2143 3: // colored bubble
2145 Rb
:= FModel
.Color
.R
;
2146 Gb
:= FModel
.Color
.G
;
2147 Bb
:= FModel
.Color
.B
;
2148 Rw
:= Min(Rb
* 2 + 64, 255);
2149 Gw
:= Min(Gb
* 2 + 64, 255);
2150 Bw
:= Min(Bb
* 2 + 64, 255);
2151 if (Abs(Rw
- Rb
) < 32)
2152 or (Abs(Gw
- Gb
) < 32)
2153 or (Abs(Bw
- Bb
) < 32) then
2155 Rb
:= Max(Rw
div 2 - 16, 0);
2156 Gb
:= Max(Gw
div 2 - 16, 0);
2157 Bb
:= Max(Bw
div 2 - 16, 0);
2160 4: // custom textured bubble
2162 if g_Texture_Get('TEXTURE_PLAYER_TALKBUBBLE', ID
) then
2163 if FDirection
= D_RIGHT
then
2164 e_Draw(ID
, bubX
- 6, bubY
- 7, 0, True, False)
2166 e_Draw(ID
, bubX
- 6, bubY
- 7, 0, True, False, M_HORIZONTAL
);
2172 e_DrawQuad(bubX
+ 1, bubY
, bubX
+ 18, bubY
+ 13, Rb
, Gb
, Bb
);
2173 e_DrawQuad(bubX
, bubY
+ 1, bubX
+ 19, bubY
+ 12, Rb
, Gb
, Bb
);
2175 e_DrawFillQuad(bubX
+ 1, bubY
+ 1, bubX
+ 18, bubY
+ 12, Rw
, Gw
, Bw
, 0);
2178 Dot
:= IfThen(FDirection
= D_LEFT
, 14, 5);
2179 e_DrawLine(1, bubX
+ Dot
, bubY
+ 14, bubX
+ Dot
, bubY
+ 16, Rb
, Gb
, Bb
);
2180 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
);
2181 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
);
2182 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
);
2183 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
);
2187 e_DrawFillQuad(bubX
+ Dot
, bubY
+ 8, bubX
+ Dot
+ 1, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2188 e_DrawFillQuad(bubX
+ Dot
+ 3, bubY
+ 8, bubX
+ Dot
+ 4, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2189 e_DrawFillQuad(bubX
+ Dot
+ 6, bubY
+ 8, bubX
+ Dot
+ 7, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2192 procedure TPlayer
.Draw();
2200 if (FMegaRulez
[MR_INVUL
] > gTime
) and (gPlayerDrawn
<> Self
) then
2201 if g_Texture_Get('TEXTURE_PLAYER_INVULPENTA', ID
) then
2203 e_GetTextureSize(ID
, @w
, @h
);
2204 if FDirection
= D_LEFT
then
2205 e_Draw(ID
, FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2)-(w
div 2)+4,
2206 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2)-(h
div 2)-7, 0, True, False)
2208 e_Draw(ID
, FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2)-(w
div 2)-2,
2209 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2)-(h
div 2)-7, 0, True, False);
2212 if FMegaRulez
[MR_INVIS
] > gTime
then
2214 if (gPlayerDrawn
<> nil) and ((Self
= gPlayerDrawn
) or
2215 ((FTeam
= gPlayerDrawn
.Team
) and (gGameSettings
.GameMode
<> GM_DM
))) then
2217 if (FMegaRulez
[MR_INVIS
] - gTime
) <= 2100 then
2218 dr
:= not Odd((FMegaRulez
[MR_INVIS
] - gTime
) div 300)
2222 FModel
.Draw(FObj
.X
, FObj
.Y
, 200)
2224 FModel
.Draw(FObj
.X
, FObj
.Y
);
2227 FModel
.Draw(FObj
.X
, FObj
.Y
, 254);
2230 FModel
.Draw(FObj
.X
, FObj
.Y
);
2233 if g_debug_Frames
then
2235 e_DrawQuad(FObj
.X
+FObj
.Rect
.X
,
2237 FObj
.X
+FObj
.Rect
.X
+FObj
.Rect
.Width
-1,
2238 FObj
.Y
+FObj
.Rect
.Y
+FObj
.Rect
.Height
-1,
2242 if (gChatBubble
> 0) and (FKeys
[KEY_CHAT
].Pressed
) and not FGhost
then
2244 // e_DrawPoint(5, 335, 288, 255, 0, 0); // DL, UR, DL, UR
2245 if gAimLine
and Live
and
2246 ((Self
= gPlayer1
) or (Self
= gPlayer2
)) then
2250 procedure TPlayer
.DrawAim();
2252 wx
, wy
, xx
, yy
: Integer;
2256 wx
:= FObj
.X
+ WEAPONPOINT
[FDirection
].X
+ IfThen(FDirection
= D_LEFT
, 7, -7);
2257 wy
:= FObj
.Y
+ WEAPONPOINT
[FDirection
].Y
;
2266 1: begin // Chainsaw
2273 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2274 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2275 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2276 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2281 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2282 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2283 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2284 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2286 4: begin // Double Shotgun
2289 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2290 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2291 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2292 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2294 5: begin // Chaingun
2297 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2298 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2299 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2300 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2302 6: begin // Rocket Launcher
2305 if angle
= ANGLE_RIGHTUP
then Inc(angle
, 2);
2306 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2307 if angle
= ANGLE_LEFTUP
then Dec(angle
, 2);
2308 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2310 7: begin // Plasmagun
2313 if angle
= ANGLE_RIGHTUP
then Inc(angle
);
2314 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 3);
2315 if angle
= ANGLE_LEFTUP
then Dec(angle
);
2316 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 3);
2321 if angle
= ANGLE_RIGHTUP
then Inc(angle
, 1);
2322 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 2);
2323 if angle
= ANGLE_LEFTUP
then Dec(angle
, 1);
2324 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 2);
2326 9: begin // Super Chaingun
2329 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2330 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2331 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2332 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2335 xx
:= Trunc(Cos(-DegToRad(angle
)) * len
) + wx
;
2336 yy
:= Trunc(Sin(-DegToRad(angle
)) * len
) + wy
;
2337 e_DrawLine(sz
, wx
, wy
, xx
, yy
, 255, 0, 0, 96);
2340 procedure TPlayer
.DrawGUI();
2343 X
, Y
, SY
, a
, p
, m
: Integer;
2347 stat
: TPlayerStatArray
;
2349 X
:= gPlayerScreenSize
.X
;
2350 SY
:= gPlayerScreenSize
.Y
;
2353 if gShowGoals
and (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
2355 if gGameSettings
.GameMode
= GM_CTF
then
2359 if gGameSettings
.GameMode
= GM_CTF
then
2361 s
:= 'TEXTURE_PLAYER_REDFLAG';
2362 if gFlags
[FLAG_RED
].State
= FLAG_STATE_CAPTURED
then
2363 s
:= 'TEXTURE_PLAYER_REDFLAG_S';
2364 if gFlags
[FLAG_RED
].State
= FLAG_STATE_DROPPED
then
2365 s
:= 'TEXTURE_PLAYER_REDFLAG_D';
2366 if g_Texture_Get(s
, ID
) then
2367 e_Draw(ID
, X
-16-32, 240-72-4, 0, True, False);
2370 s
:= IntToStr(gTeamStat
[TEAM_RED
].Goals
);
2371 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2372 e_CharFont_PrintEx(gMenuFont
, X
-16-a
-tw
, 240-72-4, s
, TEAMCOLOR
[TEAM_RED
]);
2374 if gGameSettings
.GameMode
= GM_CTF
then
2376 s
:= 'TEXTURE_PLAYER_BLUEFLAG';
2377 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_CAPTURED
then
2378 s
:= 'TEXTURE_PLAYER_BLUEFLAG_S';
2379 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_DROPPED
then
2380 s
:= 'TEXTURE_PLAYER_BLUEFLAG_D';
2381 if g_Texture_Get(s
, ID
) then
2382 e_Draw(ID
, X
-16-32, 240-32-4, 0, True, False);
2385 s
:= IntToStr(gTeamStat
[TEAM_BLUE
].Goals
);
2386 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2387 e_CharFont_PrintEx(gMenuFont
, X
-16-a
-tw
, 240-32-4, s
, TEAMCOLOR
[TEAM_BLUE
]);
2390 if g_Texture_Get('TEXTURE_PLAYER_HUDBG', ID
) then
2391 e_DrawFill(ID
, X
, 0, 1, (gPlayerScreenSize
.Y
div 256)+IfThen(gPlayerScreenSize
.Y
mod 256 > 0, 1, 0),
2394 if g_Texture_Get('TEXTURE_PLAYER_HUD', ID
) then
2395 e_Draw(ID
, X
+2, Y
, 0, True, False);
2397 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
2401 s
:= IntToStr(Frags
);
2402 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2403 e_CharFont_PrintEx(gMenuFont
, X
-16-tw
, Y
, s
, _RGB(255, 0, 0));
2408 stat
:= g_Player_GetStats();
2413 for a
:= 0 to High(stat
) do
2414 if stat
[a
].Name
<> Name
then
2416 if stat
[a
].Frags
> m
then m
:= stat
[a
].Frags
;
2417 if stat
[a
].Frags
> Frags
then p
:= p
+1;
2421 s
:= IntToStr(p
)+' / '+IntToStr(Length(stat
))+' ';
2422 if Frags
>= m
then s
:= s
+'+' else s
:= s
+'-';
2423 s
:= s
+IntToStr(Abs(Frags
-m
));
2425 e_CharFont_GetSize(gMenuSmallFont
, s
, tw
, th
);
2426 e_CharFont_PrintEx(gMenuSmallFont
, X
-16-tw
, Y
+32, s
, _RGB(255, 0, 0));
2429 if gShowLives
and (gGameSettings
.MaxLives
> 0) then
2431 s
:= IntToStr(Lives
);
2432 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2433 e_CharFont_PrintEx(gMenuFont
, X
-16-tw
, SY
-32, s
, _RGB(0, 255, 0));
2437 e_CharFont_GetSize(gMenuSmallFont
, FName
, tw
, th
);
2438 e_CharFont_PrintEx(gMenuSmallFont
, X
+98-(tw
div 2), Y
+8, FName
, _RGB(255, 0, 0));
2440 if R_BERSERK
in FRulez
then
2441 e_Draw(gItemsTexturesID
[ITEM_MEDKIT_BLACK
], X
+37, Y
+45, 0, True, False)
2443 e_Draw(gItemsTexturesID
[ITEM_MEDKIT_LARGE
], X
+37, Y
+45, 0, True, False);
2445 if g_Texture_Get('TEXTURE_PLAYER_ARMORHUD', ID
) then
2446 e_Draw(ID
, X
+36, Y
+77, 0, True, False);
2448 s
:= IntToStr(IfThen(FHealth
> 0, FHealth
, 0));
2449 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2450 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+40, s
, _RGB(255, 0, 0));
2452 s
:= IntToStr(FArmor
);
2453 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2454 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+68, s
, _RGB(255, 0, 0));
2456 s
:= IntToStr(GetAmmoByWeapon(FCurrWeap
));
2462 ID
:= gItemsTexturesID
[ITEM_WEAPON_KASTET
];
2467 ID
:= gItemsTexturesID
[ITEM_WEAPON_SAW
];
2469 WEAPON_PISTOL
: ID
:= gItemsTexturesID
[ITEM_WEAPON_PISTOL
];
2470 WEAPON_CHAINGUN
: ID
:= gItemsTexturesID
[ITEM_WEAPON_CHAINGUN
];
2471 WEAPON_SHOTGUN1
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SHOTGUN1
];
2472 WEAPON_SHOTGUN2
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SHOTGUN2
];
2473 WEAPON_SUPERPULEMET
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SUPERPULEMET
];
2474 WEAPON_ROCKETLAUNCHER
: ID
:= gItemsTexturesID
[ITEM_WEAPON_ROCKETLAUNCHER
];
2475 WEAPON_PLASMA
: ID
:= gItemsTexturesID
[ITEM_WEAPON_PLASMA
];
2476 WEAPON_BFG
: ID
:= gItemsTexturesID
[ITEM_WEAPON_BFG
];
2479 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2480 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+158, s
, _RGB(255, 0, 0));
2481 e_Draw(ID
, X
+20, Y
+160, 0, True, False);
2483 if R_KEY_RED
in FRulez
then
2484 e_Draw(gItemsTexturesID
[ITEM_KEY_RED
], X
+78, Y
+214, 0, True, False);
2486 if R_KEY_GREEN
in FRulez
then
2487 e_Draw(gItemsTexturesID
[ITEM_KEY_GREEN
], X
+95, Y
+214, 0, True, False);
2489 if R_KEY_BLUE
in FRulez
then
2490 e_Draw(gItemsTexturesID
[ITEM_KEY_BLUE
], X
+112, Y
+214, 0, True, False);
2492 if FJetFuel
> 0 then
2494 if g_Texture_Get('TEXTURE_PLAYER_HUDAIR', ID
) then
2495 e_Draw(ID
, X
+2, Y
+116, 0, True, False);
2496 if g_Texture_Get('TEXTURE_PLAYER_HUDJET', ID
) then
2497 e_Draw(ID
, X
+2, Y
+126, 0, True, False);
2498 e_DrawLine(4, X
+16, Y
+122, X
+16+Trunc(168*IfThen(FAir
> 0, FAir
, 0)/AIR_MAX
), Y
+122, 0, 0, 196);
2499 e_DrawLine(4, X
+16, Y
+132, X
+16+Trunc(168*FJetFuel
/JET_MAX
), Y
+132, 208, 0, 0);
2503 if g_Texture_Get('TEXTURE_PLAYER_HUDAIR', ID
) then
2504 e_Draw(ID
, X
+2, Y
+124, 0, True, False);
2505 e_DrawLine(4, X
+16, Y
+130, X
+16+Trunc(168*IfThen(FAir
> 0, FAir
, 0)/AIR_MAX
), Y
+130, 0, 0, 196);
2508 if gShowPing
and g_Game_IsClient
then
2510 s
:= _lc
[I_GAME_PING_HUD
] + IntToStr(NetPeer
.lastRoundTripTime
) + _lc
[I_NET_SLIST_PING_MS
];
2511 e_TextureFontPrint(X
+ 4, Y
+ 242, s
, gStdFont
);
2517 e_TextureFontPrint(X
+ 4, Y
+ 242, _lc
[I_PLAYER_SPECT
], gStdFont
);
2518 e_TextureFontPrint(X
+ 4, Y
+ 258, _lc
[I_PLAYER_SPECT2
], gStdFont
);
2519 e_TextureFontPrint(X
+ 4, Y
+ 274, _lc
[I_PLAYER_SPECT1
], gStdFont
);
2522 e_TextureFontGetSize(gStdFont
, cw
, ch
);
2523 s
:= _lc
[I_PLAYER_SPECT4
];
2524 e_TextureFontPrintEx(gScreenWidth
div 2 - cw
*(Length(s
) div 2),
2525 gScreenHeight
-4-ch
, s
, gStdFont
, 255, 255, 255, 1, True);
2526 e_TextureFontPrint(X
+ 4, Y
+ 290, _lc
[I_PLAYER_SPECT1S
], gStdFont
);
2532 procedure TPlayer
.DrawRulez();
2536 // Ïðè âçÿòèè íåóÿçâèìîñòè ðèñóåòñÿ èíâåðñèîííûé áåëûé ôîí
2537 if FMegaRulez
[MR_INVUL
] >= gTime
then
2539 if (FMegaRulez
[MR_INVUL
]-gTime
) <= 2100 then
2540 dr
:= not Odd((FMegaRulez
[MR_INVUL
]-gTime
) div 300)
2545 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2546 191, 191, 191, 0, B_INVERT
);
2549 // Ïðè âçÿòèè çàùèòíîãî êîñòþìà ðèñóåòñÿ çåëåíîâàòûé ôîí
2550 if FMegaRulez
[MR_SUIT
] >= gTime
then
2552 if (FMegaRulez
[MR_SUIT
]-gTime
) <= 2100 then
2553 dr
:= not Odd((FMegaRulez
[MR_SUIT
]-gTime
) div 300)
2558 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2559 0, 96, 0, 200, B_NONE
);
2562 // Ïðè âçÿòèè áåðñåðêà ðèñóåòñÿ êðàñíîâàòûé ôîí
2563 if (FBerserk
>= 0) and (LongWord(FBerserk
) >= gTime
) and (gFlash
= 2) then
2565 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2566 255, 0, 0, 200, B_NONE
);
2570 procedure TPlayer
.DrawPain();
2574 if FPain
= 0 then Exit
;
2578 if a
< 15 then h
:= 0
2579 else if a
< 35 then h
:= 1
2580 else if a
< 55 then h
:= 2
2581 else if a
< 75 then h
:= 3
2582 else if a
< 95 then h
:= 4
2585 //if a > 255 then a := 255;
2587 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1, 255, 0, 0, 255-h
*50);
2588 //e_DrawFillQuad(0, 0, gPlayerScreenSize.X-1, gPlayerScreenSize.Y-1, 255-min(128, a), 255-a, 255-a, 0, B_FILTER);
2591 procedure TPlayer
.DrawPickup();
2595 if FPickup
= 0 then Exit
;
2599 if a
< 15 then h
:= 1
2600 else if a
< 35 then h
:= 2
2601 else if a
< 55 then h
:= 3
2602 else if a
< 75 then h
:= 4
2605 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1, 150, 200, 150, 255-h
*50);
2608 procedure TPlayer
.Fire();
2610 f
, DidFire
: Boolean;
2611 wx
, wy
, xd
, yd
: Integer;
2614 if g_Game_IsClient
then Exit
;
2615 // FBFGFireCounter - âðåìÿ ïåðåä âûñòðåëîì (äëÿ BFG)
2616 // FReloading - âðåìÿ ïîñëå âûñòðåëà (äëÿ âñåãî)
2624 if FReloading
[FCurrWeap
] <> 0 then Exit
;
2629 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
2630 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
2631 xd
:= wx
+IfThen(FDirection
= D_LEFT
, -30, 30);
2632 yd
:= wy
+firediry();
2637 if R_BERSERK
in FRulez
then
2639 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
2640 obj
.X
:= FObj
.X
+FObj
.Rect
.X
;
2641 obj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
2644 obj
.rect
.Width
:= 39;
2645 obj
.rect
.Height
:= 52;
2646 obj
.Vel
.X
:= (xd
-wx
) div 2;
2647 obj
.Vel
.Y
:= (yd
-wy
) div 2;
2648 obj
.Accel
.X
:= xd
-wx
;
2649 obj
.Accel
.y
:= yd
-wy
;
2651 if g_Weapon_Hit(@obj
, 50, FUID
, HIT_SOME
) <> 0 then
2652 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
2654 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
2658 FPain
:= min(FPain
+ 25, 50);
2659 end else g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
2662 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2667 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
2668 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
2670 FSawSoundSelect
.Stop();
2672 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
2674 else if not FSawSoundHit
.IsPlaying() then
2676 FSawSoundSelect
.Stop();
2677 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
2680 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2686 if FAmmo
[A_BULLETS
] > 0 then
2688 g_Weapon_pistol(wx
, wy
, xd
, yd
, FUID
);
2689 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2690 Dec(FAmmo
[A_BULLETS
]);
2691 FFireAngle
:= FAngle
;
2694 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
2695 GameVelX
, GameVelY
-2, SHELL_BULLET
);
2699 if FAmmo
[A_SHELLS
] > 0 then
2701 g_Weapon_shotgun(wx
, wy
, xd
, yd
, FUID
);
2702 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', wx
, wy
);
2703 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2704 Dec(FAmmo
[A_SHELLS
]);
2705 FFireAngle
:= FAngle
;
2709 FShellType
:= SHELL_SHELL
;
2713 if FAmmo
[A_SHELLS
] >= 2 then
2715 g_Weapon_dshotgun(wx
, wy
, xd
, yd
, FUID
);
2716 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2717 Dec(FAmmo
[A_SHELLS
], 2);
2718 FFireAngle
:= FAngle
;
2722 FShellType
:= SHELL_DBLSHELL
;
2726 if FAmmo
[A_BULLETS
] > 0 then
2728 g_Weapon_mgun(wx
, wy
, xd
, yd
, FUID
);
2729 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', wx
, wy
);
2730 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2731 Dec(FAmmo
[A_BULLETS
]);
2732 FFireAngle
:= FAngle
;
2735 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
2736 GameVelX
, GameVelY
-2, SHELL_BULLET
);
2739 WEAPON_ROCKETLAUNCHER
:
2740 if FAmmo
[A_ROCKETS
] > 0 then
2742 g_Weapon_rocket(wx
, wy
, xd
, yd
, FUID
);
2743 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2744 Dec(FAmmo
[A_ROCKETS
]);
2745 FFireAngle
:= FAngle
;
2751 if FAmmo
[A_CELLS
] > 0 then
2753 g_Weapon_plasma(wx
, wy
, xd
, yd
, FUID
);
2754 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2755 Dec(FAmmo
[A_CELLS
]);
2756 FFireAngle
:= FAngle
;
2762 if (FAmmo
[A_CELLS
] >= 40) and (FBFGFireCounter
= -1) then
2764 FBFGFireCounter
:= 17;
2765 if not FNoReload
then
2766 g_Sound_PlayExAt('SOUND_WEAPON_STARTFIREBFG', FObj
.X
, FObj
.Y
);
2767 Dec(FAmmo
[A_CELLS
], 40);
2771 WEAPON_SUPERPULEMET
:
2772 if FAmmo
[A_SHELLS
] > 0 then
2774 g_Weapon_shotgun(wx
, wy
, xd
, yd
, FUID
);
2775 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', wx
, wy
);
2776 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2777 Dec(FAmmo
[A_SHELLS
]);
2778 FFireAngle
:= FAngle
;
2781 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
2782 GameVelX
, GameVelY
-2, SHELL_SHELL
);
2786 if g_Game_IsNet
then
2790 if FCurrWeap
<> WEAPON_BFG
then
2791 MH_SEND_PlayerFire(FUID
, FCurrWeap
, wx
, wy
, xd
, yd
, LastShotID
)
2793 if not FNoReload
then
2794 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_WEAPON_STARTFIREBFG');
2797 MH_SEND_PlayerStats(FUID
);
2802 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
2803 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
2804 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
2807 function TPlayer
.GetAmmoByWeapon(Weapon
: Byte): Word;
2810 WEAPON_PISTOL
, WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
];
2811 WEAPON_SHOTGUN1
, WEAPON_SHOTGUN2
, WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
];
2812 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
];
2813 WEAPON_PLASMA
, WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
];
2818 function TPlayer
.HeadInLiquid(XInc
, YInc
: Integer): Boolean;
2820 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
+XInc
, FObj
.Y
+PLAYER_HEADRECT
.Y
+YInc
,
2821 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
2822 PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, True);
2825 procedure TPlayer
.JetpackOn
;
2829 FJetSoundOn
.SetPosition(0);
2830 FJetSoundOn
.PlayAt(FObj
.X
, FObj
.Y
);
2834 procedure TPlayer
.JetpackOff
;
2838 FJetSoundOff
.SetPosition(0);
2839 FJetSoundOff
.PlayAt(FObj
.X
, FObj
.Y
);
2842 procedure TPlayer
.Jump();
2844 if gFly
or FJetpack
then
2846 // Ïîëåò (÷èò-êîä èëè äæåòïàê):
2847 if FObj
.Vel
.Y
> -VEL_FLY
then
2848 FObj
.Vel
.Y
:= FObj
.Vel
.Y
- 3;
2851 if FJetFuel
> 0 then
2853 if (FJetFuel
< 1) and g_Game_IsServer
then
2857 if g_Game_IsNet
then
2858 MH_SEND_PlayerStats(FUID
);
2864 // Íå âêëþ÷àòü äæåòïàê â ðåæèìå ïðîõîæäåíèÿ ñêâîçü ñòåíû
2866 FCanJetpack
:= False;
2868 // Ïðûãàåì èëè âñïëûâàåì:
2869 if (CollideLevel(0, 1) or
2870 g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
+36, PLAYER_RECT
.Width
,
2871 PLAYER_RECT
.Height
-33, PANEL_STEP
, False)
2872 ) and (FObj
.Accel
.Y
= 0) then // Íå ïðûãàòü, åñëè åñòü âåðòèêàëüíîå óñêîðåíèå
2874 FObj
.Vel
.Y
:= -VEL_JUMP
;
2875 FCanJetpack
:= False;
2879 if BodyInLiquid(0, 0) then
2880 FObj
.Vel
.Y
:= -VEL_SW
2881 else if (FJetFuel
> 0) and FCanJetpack
and
2882 g_Game_IsServer
and (not g_Obj_CollideLiquid(@FObj
, 0, 0)) then
2886 if g_Game_IsNet
then
2887 MH_SEND_PlayerStats(FUID
);
2892 procedure TPlayer
.Kill(KillType
: Byte; SpawnerUID
: Word; t
: Byte);
2894 a
, i
, k
, ab
, ar
: Byte;
2898 srv
, netsrv
: Boolean;
2903 procedure PushItem(t
: Byte);
2907 id
:= g_Items_Create(FObj
.X
, FObj
.Y
, t
, True, False);
2908 if KillType
= K_EXTRAHARDKILL
then // -7..+7; -8..0
2909 g_Obj_Push(@gItems
[id
].Obj
, (FObj
.Vel
.X
div 2)-7+Random(15),
2910 (FObj
.Vel
.Y
div 2)-Random(9))
2912 if KillType
= K_HARDKILL
then // -5..+5; -5..0
2913 g_Obj_Push(@gItems
[id
].Obj
, (FObj
.Vel
.X
div 2)-5+Random(11),
2914 (FObj
.Vel
.Y
div 2)-Random(6))
2915 else // -3..+3; -3..0
2916 g_Obj_Push(@gItems
[id
].Obj
, (FObj
.Vel
.X
div 2)-3+Random(7),
2917 (FObj
.Vel
.Y
div 2)-Random(4));
2919 if g_Game_IsNet
and g_Game_IsServer
then
2920 MH_SEND_ItemSpawn(True, id
);
2924 DoFrags
:= (gGameSettings
.MaxLives
= 0) or (gGameSettings
.GameMode
= GM_COOP
);
2925 Srv
:= g_Game_IsServer
;
2926 Netsrv
:= g_Game_IsServer
and g_Game_IsNet
;
2927 if Srv
then FDeath
:= FDeath
+ 1;
2932 if not FPhysics
then
2938 if (gGameSettings
.MaxLives
> 0) and Srv
and (gLMSRespawn
= LMS_RESPAWN_NONE
) then
2940 if FLives
> 0 then FLives
:= FLives
- 1;
2941 if FLives
= 0 then FNoRespawn
:= True;
2944 // Íîìåð òèïà ñìåðòè:
2947 K_SIMPLEKILL
: a
:= 1;
2949 K_EXTRAHARDKILL
: a
:= 3;
2954 if not FModel
.PlaySound(MODELSOUND_DIE
, a
, FObj
.X
, FObj
.Y
) then
2956 if FModel
.PlaySound(MODELSOUND_DIE
, i
, FObj
.X
, FObj
.Y
) then
2963 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN1
;
2965 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN2
;
2966 K_EXTRAHARDKILL
, K_FALLKILL
:
2967 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN3
;
2970 // Ïåðåêëþ÷àåì ñîñòîÿíèå:
2974 K_HARDKILL
, K_EXTRAHARDKILL
:
2978 // Ðåàêöèÿ ìîíñòðîâ íà ñìåðòü èãðîêà:
2979 if (KillType
<> K_FALLKILL
) and (Srv
) then
2980 g_Monsters_killedp();
2982 if SpawnerUID
= FUID
then
2984 if Srv
and (DoFrags
or (gGameSettings
.GameMode
= GM_TDM
)) then
2989 g_Console_Add(Format(_lc
[I_PLAYER_KILL_SELF
], [FName
]), True);
2992 if g_GetUIDType(SpawnerUID
) = UID_PLAYER
then
2993 begin // Óáèò äðóãèì èãðîêîì
2994 KP
:= g_Player_Get(SpawnerUID
);
2995 if (KP
<> nil) and Srv
then
2997 if (DoFrags
or (gGameSettings
.GameMode
= GM_TDM
)) then
2998 if SameTeam(FUID
, SpawnerUID
) then
3008 if (gGameSettings
.GameMode
= GM_TDM
) and DoFrags
then
3009 Inc(gTeamStat
[KP
.Team
].Goals
,
3010 IfThen(SameTeam(FUID
, SpawnerUID
), -1, 1));
3012 if netsrv
then MH_SEND_PlayerStats(SpawnerUID
);
3015 plr
:= g_Player_Get(SpawnerUID
);
3023 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_2
],
3027 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_1
],
3031 g_Console_Add(Format(_lc
[I_PLAYER_KILL
],
3036 else if g_GetUIDType(SpawnerUID
) = UID_MONSTER
then
3037 begin // Óáèò ìîíñòðîì
3038 mon
:= g_Monsters_Get(SpawnerUID
);
3042 s
:= g_Monsters_GetKilledBy(mon
.MonsterType
);
3046 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_2
],
3050 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_1
],
3054 g_Console_Add(Format(_lc
[I_PLAYER_KILL
],
3059 else // Îñîáûå òèïû ñìåðòè
3062 HIT_SELF
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_SELF
], [FName
]), True);
3063 HIT_FALL
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_FALL
], [FName
]), True);
3064 HIT_WATER
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_WATER
], [FName
]), True);
3065 HIT_ACID
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_ACID
], [FName
]), True);
3066 HIT_TRAP
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_TRAP
], [FName
]), True);
3067 else g_Console_Add(Format(_lc
[I_PLAYER_DIED
], [FName
]), True);
3073 for a
:= WEAPON_KASTET
to WEAPON_SUPERPULEMET
do
3077 WEAPON_SAW
: i
:= ITEM_WEAPON_SAW
;
3078 WEAPON_SHOTGUN1
: i
:= ITEM_WEAPON_SHOTGUN1
;
3079 WEAPON_SHOTGUN2
: i
:= ITEM_WEAPON_SHOTGUN2
;
3080 WEAPON_CHAINGUN
: i
:= ITEM_WEAPON_CHAINGUN
;
3081 WEAPON_ROCKETLAUNCHER
: i
:= ITEM_WEAPON_ROCKETLAUNCHER
;
3082 WEAPON_PLASMA
: i
:= ITEM_WEAPON_PLASMA
;
3083 WEAPON_BFG
: i
:= ITEM_WEAPON_BFG
;
3084 WEAPON_SUPERPULEMET
: i
:= ITEM_WEAPON_SUPERPULEMET
;
3093 if R_ITEM_BACKPACK
in FRulez
then
3094 PushItem(ITEM_AMMO_BACKPACK
);
3096 // Âûáðîñ ðàêåòíîãî ðàíöà:
3097 if FJetFuel
> 0 then
3098 PushItem(ITEM_JETPACK
);
3101 if not (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
]) then
3103 if R_KEY_RED
in FRulez
then
3104 PushItem(ITEM_KEY_RED
);
3106 if R_KEY_GREEN
in FRulez
then
3107 PushItem(ITEM_KEY_GREEN
);
3109 if R_KEY_BLUE
in FRulez
then
3110 PushItem(ITEM_KEY_BLUE
);
3117 g_Player_CreateCorpse(Self
);
3119 if Srv
and (gGameSettings
.MaxLives
> 0) and FNoRespawn
and
3120 (gLMSRespawn
= LMS_RESPAWN_NONE
) then
3126 for i
:= Low(gPlayers
) to High(gPlayers
) do
3128 if gPlayers
[i
] = nil then continue
;
3129 if (not gPlayers
[i
].FNoRespawn
) and (not gPlayers
[i
].FSpectator
) then
3132 if gPlayers
[i
].FTeam
= TEAM_RED
then Inc(ar
)
3133 else if gPlayers
[i
].FTeam
= TEAM_BLUE
then Inc(ab
);
3138 OldLR
:= gLMSRespawn
;
3139 if (gGameSettings
.GameMode
= GM_COOP
) then
3143 // everyone is dead, restart the map
3144 g_Game_Message(_lc
[I_MESSAGE_LMS_LOSE
], 144);
3146 MH_SEND_GameEvent(NET_EV_LMS_LOSE
);
3147 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3148 gLMSRespawnTime
:= gTime
+ 5000;
3150 else if (a
= 1) then
3152 if (gPlayers
[k
] <> nil) and not (gPlayers
[k
] is TBot
) then
3153 if (gPlayers
[k
] = gPlayer1
) or
3154 (gPlayers
[k
] = gPlayer2
) then
3155 g_Console_Add('*** ' + _lc
[I_MESSAGE_LMS_SURVIVOR
] + ' ***', True)
3156 else if Netsrv
and (gPlayers
[k
].FClientID
>= 0) then
3157 MH_SEND_GameEvent(NET_EV_LMS_SURVIVOR
, 0, 'N', gPlayers
[k
].FClientID
);
3160 else if (gGameSettings
.GameMode
= GM_TDM
) then
3162 if (ab
= 0) and (ar
<> 0) then
3165 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 144);
3167 MH_SEND_GameEvent(NET_EV_TLMS_WIN
, TEAM_RED
);
3168 Inc(gTeamStat
[TEAM_RED
].Goals
);
3169 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3170 gLMSRespawnTime
:= gTime
+ 5000;
3172 else if (ar
= 0) and (ab
<> 0) then
3175 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 144);
3177 MH_SEND_GameEvent(NET_EV_TLMS_WIN
, TEAM_BLUE
);
3178 Inc(gTeamStat
[TEAM_BLUE
].Goals
);
3179 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3180 gLMSRespawnTime
:= gTime
+ 5000;
3182 else if (ar
= 0) and (ab
= 0) then
3185 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
3187 MH_SEND_GameEvent(NET_EV_LMS_DRAW
, 0, FName
);
3188 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3189 gLMSRespawnTime
:= gTime
+ 5000;
3192 else if (gGameSettings
.GameMode
= GM_DM
) then
3196 if gPlayers
[k
] <> nil then
3199 // survivor is the winner
3200 g_Game_Message(Format(_lc
[I_MESSAGE_LMS_WIN
], [AnsiUpperCase(FName
)]), 144);
3202 MH_SEND_GameEvent(NET_EV_LMS_WIN
, 0, FName
);
3205 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3206 gLMSRespawnTime
:= gTime
+ 5000;
3208 else if (a
= 0) then
3210 // everyone is dead, restart the map
3211 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
3213 MH_SEND_GameEvent(NET_EV_LMS_DRAW
, 0, FName
);
3214 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3215 gLMSRespawnTime
:= gTime
+ 5000;
3218 if srv
and (OldLR
= LMS_RESPAWN_NONE
) and (gLMSRespawn
> LMS_RESPAWN_NONE
) then
3220 if NetMode
= NET_SERVER
then
3221 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, (gLMSRespawnTime
- gTime
) div 1000)
3223 g_Console_Add(Format(_lc
[I_MSG_WARMUP_START
], [(gLMSRespawnTime
- gTime
) div 1000]), True);
3229 MH_SEND_PlayerStats(FUID
);
3230 MH_SEND_PlayerDeath(FUID
, KillType
, t
, SpawnerUID
);
3231 if gGameSettings
.GameMode
= GM_TDM
then MH_SEND_GameStats
;
3234 if srv
and FNoRespawn
then Spectate(True);
3235 FWantsInGame
:= True;
3238 function TPlayer
.BodyInLiquid(XInc
, YInc
: Integer): Boolean;
3240 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
, PLAYER_RECT
.Width
,
3241 PLAYER_RECT
.Height
-20, PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, False);
3244 function TPlayer
.BodyInAcid(XInc
, YInc
: Integer): Boolean;
3246 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
, PLAYER_RECT
.Width
,
3247 PLAYER_RECT
.Height
-20, PANEL_ACID1
or PANEL_ACID2
, False);
3250 procedure TPlayer
.MakeBloodSimple(Count
: Word);
3252 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)+8,
3253 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3254 Count
div 2, 3, -1, 16, (PLAYER_RECT
.Height
*2 div 3),
3256 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-8,
3257 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3258 Count
div 2, -3, -1, 16, (PLAYER_RECT
.Height
*2) div 3,
3262 procedure TPlayer
.MakeBloodVector(Count
: Word; VelX
, VelY
: Integer);
3264 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
3265 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3266 Count
, VelX
, VelY
, 16, (PLAYER_RECT
.Height
*2) div 3,
3270 procedure TPlayer
.QueueWeaponSwitch(Weapon
: Byte);
3272 if g_Game_IsClient
then Exit
;
3273 if Weapon
> High(FWeapon
) then Exit
;
3274 FNextWeap
:= FNextWeap
or (1 shl Weapon
);
3277 procedure TPlayer
.resetWeaponQueue ();
3280 FNextWeapDelay
:= 0;
3283 function TPlayer
.hasAmmoForWeapon (weapon
: Byte): Boolean;
3287 WEAPON_KASTET
, WEAPON_SAW
: result
:= true;
3288 WEAPON_SHOTGUN1
, WEAPON_SHOTGUN2
: result
:= (FAmmo
[A_SHELLS
] > 0);
3289 WEAPON_PISTOL
, WEAPON_CHAINGUN
, WEAPON_SUPERPULEMET
: result
:= (FAmmo
[A_BULLETS
] > 0);
3290 WEAPON_ROCKETLAUNCHER
: result
:= (FAmmo
[A_ROCKETS
] > 0);
3291 WEAPON_PLASMA
, WEAPON_BFG
: result
:= (FAmmo
[A_CELLS
] > 0);
3292 else result
:= (weapon
< length(FWeapon
));
3296 // return 255 for "no switch"
3297 function TPlayer
.getNextWeaponIndex (): Byte;
3300 wantThisWeapon
: array[0..64] of Boolean;
3301 wwc
: Integer = 0; //HACK!
3303 result
:= 255; // default result: "no switch"
3304 for i
:= 0 to High(wantThisWeapon
) do wantThisWeapon
[i
] := false;
3305 for i
:= 0 to High(FWeapon
) do if (FNextWeap
and (1 shl i
)) <> 0 then begin wantThisWeapon
[i
] := true; Inc(wwc
); end;
3307 if wantThisWeapon[FCurrWeap] then
3309 // these hacks implements alternating between SG and SSG; sorry
3310 if FCurrWeap = WEAPON_SHOTGUN1 then begin wantThisWeapon[WEAPON_SHOTGUN2] := true; Inc(wwc); end;
3311 if FCurrWeap = WEAPON_SHOTGUN2 then begin wantThisWeapon[WEAPON_SHOTGUN1] := true; Inc(wwc); end;
3312 // these hacks implements alternating between knuckles and chainsaw; sorry
3313 if FCurrWeap = WEAPON_KASTET then begin wantThisWeapon[WEAPON_SAW] := true; Inc(wwc); end;
3314 if FCurrWeap = WEAPON_SAW then begin wantThisWeapon[WEAPON_KASTET] := true; Inc(wwc); end;
3317 // exclude currently selected weapon from the set
3318 wantThisWeapon
[FCurrWeap
] := false;
3319 // slow down alterations a little
3322 // more than one weapon requested, assume "alteration" and check alteration delay
3323 if FNextWeapDelay
> 0 then begin FNextWeap
:= 0; exit
; end; // yeah
3325 // do not reset weapon queue, it will be done in `RealizeCurrentWeapon()`
3326 // try weapons in descending order
3327 for i
:= High(FWeapon
) downto 0 do
3329 if wantThisWeapon
[i
] and FWeapon
[i
] and ((wwc
= 1) or hasAmmoForWeapon(i
)) then
3338 procedure TPlayer
.RealizeCurrentWeapon();
3342 nw
:= getNextWeaponIndex();
3343 if FNextWeapDelay
> 0 then Dec(FNextWeapDelay
); // "alteration delay"
3344 if nw
= 255 then exit
; // don't reset anything here
3345 if nw
> High(FWeapon
) then begin resetWeaponQueue(); exit
; end; // don't forget to reset queue here!
3347 if FBFGFireCounter
<> -1 then exit
;
3348 if FTime
[T_SWITCH
] > gTime
then exit
;
3350 for i
:= WEAPON_KASTET
to WEAPON_SUPERPULEMET
do if FReloading
[i
] > 0 then exit
;
3355 FTime
[T_SWITCH
] := gTime
+156;
3356 if FCurrWeap
= WEAPON_SAW
then FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3357 FModel
.SetWeapon(FCurrWeap
);
3358 if g_Game_IsNet
then MH_SEND_PlayerStats(FUID
);
3360 // reset weapon queue; `getNextWeaponIndex()` guarantees to not select a weapon player don't have
3362 FNextWeapDelay
:= 10; // anyway, 'cause why not
3365 procedure TPlayer
.cycleWeapon (dir
: Integer);
3369 if dir
< 0 then dir
:= 1 else if dir
> 0 then dir
:= 1 else exit
;
3371 for i
:= 0 to High(FWeapon
) do
3374 if cwi
< 0 then cwi
+= length(FWeapon
)
3375 else if cwi
> High(FWeapon
) then cwi
:= cwi
-length(FWeapon
);
3376 if FWeapon
[cwi
] then
3378 QueueWeaponSwitch(Byte(cwi
));
3384 procedure TPlayer
.NextWeapon();
3386 if g_Game_IsClient
then Exit
;
3390 procedure TPlayer
.PrevWeapon();
3392 if g_Game_IsClient
then Exit
;
3396 procedure TPlayer
.SetWeapon(W
: Byte);
3398 if FCurrWeap
<> W
then
3399 if W
= WEAPON_SAW
then
3400 FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3403 FModel
.SetWeapon(CurrWeap
);
3407 function TPlayer
.PickItem(ItemType
: Byte; respawn
: Boolean; var remove
: Boolean): Boolean;
3412 if g_Game_IsClient
then Exit
;
3414 // a = true - ìåñòî ñïàâíà ïðåäìåòà:
3415 a
:= LongBool(gGameSettings
.Options
and GAME_OPTION_WEAPONSTAY
) and respawn
;
3420 if FHealth
< PLAYER_HP_SOFT
then
3422 IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
3425 if gFlash
= 2 then Inc(FPickup
, 5);
3429 if FHealth
< PLAYER_HP_SOFT
then
3431 IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
3434 if gFlash
= 2 then Inc(FPickup
, 5);
3438 if FArmor
< PLAYER_AP_SOFT
then
3440 FArmor
:= PLAYER_AP_SOFT
;
3443 if gFlash
= 2 then Inc(FPickup
, 5);
3447 if FArmor
< PLAYER_AP_LIMIT
then
3449 FArmor
:= PLAYER_AP_LIMIT
;
3452 if gFlash
= 2 then Inc(FPickup
, 5);
3456 if FHealth
< PLAYER_HP_LIMIT
then
3458 IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
3461 if gFlash
= 2 then Inc(FPickup
, 5);
3465 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) then
3467 if FHealth
< PLAYER_HP_LIMIT
then
3468 FHealth
:= PLAYER_HP_LIMIT
;
3469 if FArmor
< PLAYER_AP_LIMIT
then
3470 FArmor
:= PLAYER_AP_LIMIT
;
3473 if gFlash
= 2 then Inc(FPickup
, 5);
3477 if (not FWeapon
[WEAPON_SAW
]) or ((not respawn
) and (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
])) then
3479 FWeapon
[WEAPON_SAW
] := True;
3481 if gFlash
= 2 then Inc(FPickup
, 5);
3482 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3485 ITEM_WEAPON_SHOTGUN1
:
3486 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN1
] then
3488 // Íóæíî, ÷òîáû íå âçÿòü âñå ïóëè ñðàçó:
3489 if a
and FWeapon
[WEAPON_SHOTGUN1
] then Exit
;
3491 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3492 FWeapon
[WEAPON_SHOTGUN1
] := True;
3494 if gFlash
= 2 then Inc(FPickup
, 5);
3495 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3498 ITEM_WEAPON_SHOTGUN2
:
3499 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN2
] then
3501 if a
and FWeapon
[WEAPON_SHOTGUN2
] then Exit
;
3503 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3504 FWeapon
[WEAPON_SHOTGUN2
] := True;
3506 if gFlash
= 2 then Inc(FPickup
, 5);
3507 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3510 ITEM_WEAPON_CHAINGUN
:
3511 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or not FWeapon
[WEAPON_CHAINGUN
] then
3513 if a
and FWeapon
[WEAPON_CHAINGUN
] then Exit
;
3515 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
3516 FWeapon
[WEAPON_CHAINGUN
] := True;
3518 if gFlash
= 2 then Inc(FPickup
, 5);
3519 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3522 ITEM_WEAPON_ROCKETLAUNCHER
:
3523 if (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or not FWeapon
[WEAPON_ROCKETLAUNCHER
] then
3525 if a
and FWeapon
[WEAPON_ROCKETLAUNCHER
] then Exit
;
3527 IncMax(FAmmo
[A_ROCKETS
], 2, FMaxAmmo
[A_ROCKETS
]);
3528 FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
3530 if gFlash
= 2 then Inc(FPickup
, 5);
3531 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3535 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_PLASMA
] then
3537 if a
and FWeapon
[WEAPON_PLASMA
] then Exit
;
3539 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3540 FWeapon
[WEAPON_PLASMA
] := True;
3542 if gFlash
= 2 then Inc(FPickup
, 5);
3543 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3547 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_BFG
] then
3549 if a
and FWeapon
[WEAPON_BFG
] then Exit
;
3551 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3552 FWeapon
[WEAPON_BFG
] := True;
3554 if gFlash
= 2 then Inc(FPickup
, 5);
3555 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3558 ITEM_WEAPON_SUPERPULEMET
:
3559 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SUPERPULEMET
] then
3561 if a
and FWeapon
[WEAPON_SUPERPULEMET
] then Exit
;
3563 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3564 FWeapon
[WEAPON_SUPERPULEMET
] := True;
3566 if gFlash
= 2 then Inc(FPickup
, 5);
3567 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3571 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
3573 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
3576 if gFlash
= 2 then Inc(FPickup
, 5);
3579 ITEM_AMMO_BULLETS_BOX
:
3580 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
3582 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
3585 if gFlash
= 2 then Inc(FPickup
, 5);
3589 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
3591 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3594 if gFlash
= 2 then Inc(FPickup
, 5);
3597 ITEM_AMMO_SHELLS_BOX
:
3598 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
3600 IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
3603 if gFlash
= 2 then Inc(FPickup
, 5);
3607 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
3609 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
3612 if gFlash
= 2 then Inc(FPickup
, 5);
3615 ITEM_AMMO_ROCKET_BOX
:
3616 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
3618 IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
3621 if gFlash
= 2 then Inc(FPickup
, 5);
3625 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
3627 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3630 if gFlash
= 2 then Inc(FPickup
, 5);
3634 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
3636 IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
3639 if gFlash
= 2 then Inc(FPickup
, 5);
3643 if not(R_ITEM_BACKPACK
in FRulez
) or
3644 (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
3645 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
3646 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
3647 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) then
3649 FMaxAmmo
[A_BULLETS
] := 400;
3650 FMaxAmmo
[A_SHELLS
] := 100;
3651 FMaxAmmo
[A_ROCKETS
] := 100;
3652 FMaxAmmo
[A_CELLS
] := 600;
3654 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
3655 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
3656 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
3657 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3658 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
3659 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
3660 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
3661 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3663 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
3666 if gFlash
= 2 then Inc(FPickup
, 5);
3670 if not(R_KEY_RED
in FRulez
) then
3672 Include(FRulez
, R_KEY_RED
);
3674 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
3675 if gFlash
= 2 then Inc(FPickup
, 5);
3676 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
3680 if not(R_KEY_GREEN
in FRulez
) then
3682 Include(FRulez
, R_KEY_GREEN
);
3684 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
3685 if gFlash
= 2 then Inc(FPickup
, 5);
3686 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
3690 if not(R_KEY_BLUE
in FRulez
) then
3692 Include(FRulez
, R_KEY_BLUE
);
3694 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
3695 if gFlash
= 2 then Inc(FPickup
, 5);
3696 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
3700 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
3702 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
3705 if gFlash
= 2 then Inc(FPickup
, 5);
3709 if FAir
< AIR_MAX
then
3714 if gFlash
= 2 then Inc(FPickup
, 5);
3719 if not (R_BERSERK
in FRulez
) then
3721 Include(FRulez
, R_BERSERK
);
3722 if FBFGFireCounter
= -1 then
3724 FCurrWeap
:= WEAPON_KASTET
;
3726 FModel
.SetWeapon(WEAPON_KASTET
);
3730 if gFlash
= 2 then Inc(FPickup
, 5);
3731 FBerserk
:= gTime
+30000;
3735 if FHealth
< PLAYER_HP_SOFT
then
3737 FHealth
:= PLAYER_HP_SOFT
;
3738 FBerserk
:= gTime
+30000;
3745 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
3747 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
3750 if gFlash
= 2 then Inc(FPickup
, 5);
3754 if FHealth
< PLAYER_HP_LIMIT
then
3756 IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
3759 if gFlash
= 2 then Inc(FPickup
, 5);
3763 if FArmor
< PLAYER_AP_LIMIT
then
3765 IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
3768 if gFlash
= 2 then Inc(FPickup
, 5);
3772 if FJetFuel
< JET_MAX
then
3774 FJetFuel
:= JET_MAX
;
3777 if gFlash
= 2 then Inc(FPickup
, 5);
3781 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
3783 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
3786 if gFlash
= 2 then Inc(FPickup
, 5);
3791 procedure TPlayer
.Touch();
3795 //FModel.PlaySound(MODELSOUND_PAIN, 1, FObj.X, FObj.Y);
3798 // Áðîñèòü ôëàã òîâàðèùó:
3799 if gGameSettings
.GameMode
= GM_CTF
then
3804 procedure TPlayer
.Push(vx
, vy
: Integer);
3806 if (not FPhysics
) and FGhost
then
3808 FObj
.Accel
.X
:= FObj
.Accel
.X
+ vx
;
3809 FObj
.Accel
.Y
:= FObj
.Accel
.Y
+ vy
;
3810 if g_Game_IsNet
and g_Game_IsServer
then
3811 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
3814 procedure TPlayer
.Reset(Force
: Boolean);
3820 FTime
[T_RESPAWN
] := 0;
3821 FTime
[T_FLAGCAP
] := 0;
3834 FSpectator
:= False;
3837 FSpectatePlayer
:= -1;
3838 FNoRespawn
:= False;
3840 FLives
:= gGameSettings
.MaxLives
;
3845 procedure TPlayer
.SoftReset();
3851 FBFGFireCounter
:= -1;
3859 SetAction(A_STAND
, True);
3862 function TPlayer
.GetRespawnPoint(): Byte;
3867 // Íà áóäóùåå: FSpawn - èãðîê óæå èãðàë è ïåðåðîæäàåòñÿ
3869 // Îäèíî÷íàÿ èãðà/êîîïåðàòèâ
3870 if gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
] then
3872 if (Self
= gPlayer1
) or (Self
= gPlayer2
) then
3874 // Òî÷êà ïîÿâëåíèÿ ñâîåãî èãðîêà
3875 if Self
= gPlayer1
then
3876 c
:= RESPAWNPOINT_PLAYER1
3878 c
:= RESPAWNPOINT_PLAYER2
;
3879 if g_Map_GetPointCount(c
) > 0 then
3885 // Òî÷êà ïîÿâëåíèÿ äðóãîãî èãðîêà
3886 if Self
= gPlayer1
then
3887 c
:= RESPAWNPOINT_PLAYER2
3889 c
:= RESPAWNPOINT_PLAYER1
;
3890 if g_Map_GetPointCount(c
) > 0 then
3897 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà (áîòà)
3898 if Random(2) = 0 then
3899 c
:= RESPAWNPOINT_PLAYER1
3901 c
:= RESPAWNPOINT_PLAYER2
;
3902 if g_Map_GetPointCount(c
) > 0 then
3909 // Òî÷êà ëþáîé èç êîìàíä
3910 if Random(2) = 0 then
3911 c
:= RESPAWNPOINT_RED
3913 c
:= RESPAWNPOINT_BLUE
;
3914 if g_Map_GetPointCount(c
) > 0 then
3921 c
:= RESPAWNPOINT_DM
;
3922 if g_Map_GetPointCount(c
) > 0 then
3930 if gGameSettings
.GameMode
= GM_DM
then
3933 c
:= RESPAWNPOINT_DM
;
3934 if g_Map_GetPointCount(c
) > 0 then
3940 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà
3941 if Random(2) = 0 then
3942 c
:= RESPAWNPOINT_PLAYER1
3944 c
:= RESPAWNPOINT_PLAYER2
;
3945 if g_Map_GetPointCount(c
) > 0 then
3951 // Òî÷êà ëþáîé èç êîìàíä
3952 if Random(2) = 0 then
3953 c
:= RESPAWNPOINT_RED
3955 c
:= RESPAWNPOINT_BLUE
;
3956 if g_Map_GetPointCount(c
) > 0 then
3964 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
3966 // Òî÷êà ñâîåé êîìàíäû
3967 c
:= RESPAWNPOINT_DM
;
3968 if FTeam
= TEAM_RED
then
3969 c
:= RESPAWNPOINT_RED
;
3970 if FTeam
= TEAM_BLUE
then
3971 c
:= RESPAWNPOINT_BLUE
;
3972 if g_Map_GetPointCount(c
) > 0 then
3979 c
:= RESPAWNPOINT_DM
;
3980 if g_Map_GetPointCount(c
) > 0 then
3986 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà
3987 if Random(2) = 0 then
3988 c
:= RESPAWNPOINT_PLAYER1
3990 c
:= RESPAWNPOINT_PLAYER2
;
3991 if g_Map_GetPointCount(c
) > 0 then
3997 // Òî÷êà äðóãîé êîìàíäû
3998 c
:= RESPAWNPOINT_DM
;
3999 if FTeam
= TEAM_RED
then
4000 c
:= RESPAWNPOINT_BLUE
;
4001 if FTeam
= TEAM_BLUE
then
4002 c
:= RESPAWNPOINT_RED
;
4003 if g_Map_GetPointCount(c
) > 0 then
4011 procedure TPlayer
.Respawn(Silent
: Boolean; Force
: Boolean = False);
4013 RespawnPoint
: TRespawnPoint
;
4018 if not g_Game_IsServer
then
4022 FWantsInGame
:= True;
4023 FJustTeleported
:= True;
4026 FTime
[T_RESPAWN
] := 0;
4030 // if server changes MaxLives we gotta be ready
4031 if gGameSettings
.MaxLives
= 0 then FNoRespawn
:= False;
4033 // Åùå íåëüçÿ âîçðîäèòüñÿ:
4034 if FTime
[T_RESPAWN
] > gTime
then
4037 // Ïðîñðàë âñå æèçíè:
4040 if not FSpectator
then Spectate(True);
4041 FWantsInGame
:= True;
4045 if (gGameSettings
.GameType
<> GT_SINGLE
) and (gGameSettings
.GameMode
<> GM_COOP
) then
4046 begin // "Ñâîÿ èãðà"
4047 // Áåðñåðê íå ñîõðàíÿåòñÿ ìåæäó óðîâíÿìè:
4048 FRulez
:= FRulez
-[R_BERSERK
];
4050 else // "Îäèíî÷íàÿ èãðà"/"Êîîï"
4052 // Áåðñåðê è êëþ÷è íå ñîõðàíÿþòñÿ ìåæäó óðîâíÿìè:
4053 FRulez
:= FRulez
-[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
, R_BERSERK
];
4056 // Ïîëó÷àåì òî÷êó ñïàóíà èãðîêà:
4057 c
:= GetRespawnPoint();
4062 // Âîñêðåøåíèå áåç îðóæèÿ:
4065 FHealth
:= PLAYER_HP_SOFT
;
4071 for a
:= WEAPON_KASTET
to WEAPON_SUPERPULEMET
do
4073 FWeapon
[a
] := False;
4077 FWeapon
[WEAPON_PISTOL
] := True;
4078 FWeapon
[WEAPON_KASTET
] := True;
4079 FCurrWeap
:= WEAPON_PISTOL
;
4082 FModel
.SetWeapon(FCurrWeap
);
4084 for b
:= A_BULLETS
to A_CELLS
do
4087 FAmmo
[A_BULLETS
] := 50;
4089 FMaxAmmo
[A_BULLETS
] := 200;
4090 FMaxAmmo
[A_SHELLS
] := 50;
4091 FMaxAmmo
[A_ROCKETS
] := 50;
4092 FMaxAmmo
[A_CELLS
] := 300;
4094 if gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
] then
4095 FRulez
:= [R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
]
4100 // Ïîëó÷àåì êîîðäèíàòû òî÷êè âîçðîæäåíèÿ:
4101 if not g_Map_GetPoint(c
, RespawnPoint
) then
4103 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
4107 // Óñòàíîâêà êîîðäèíàò è ñáðîñ âñåõ ïàðàìåòðîâ:
4108 FObj
.X
:= RespawnPoint
.X
-PLAYER_RECT
.X
;
4109 FObj
.Y
:= RespawnPoint
.Y
-PLAYER_RECT
.Y
;
4115 FDirection
:= RespawnPoint
.Direction
;
4116 if FDirection
= D_LEFT
then
4122 FBFGFireCounter
:= -1;
4127 SetAction(A_STAND
, True);
4128 FModel
.Direction
:= FDirection
;
4130 for a
:= Low(FTime
) to High(FTime
) do
4133 for a
:= Low(FMegaRulez
) to High(FMegaRulez
) do
4138 FCanJetpack
:= False;
4140 // Àíèìàöèÿ âîçðîæäåíèÿ:
4141 if (not gLoadGameMode
) and (not Silent
) then
4142 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
4144 Anim
:= TAnimation
.Create(ID
, False, 3);
4145 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4146 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4150 FSpectator
:= False;
4153 FSpectatePlayer
:= -1;
4156 if g_Game_IsNet
then
4158 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
4159 MH_SEND_PlayerStats(FUID
, NET_EVERYONE
);
4161 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4162 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32,
4167 procedure TPlayer
.Spectate(NoMove
: Boolean = False);
4170 Kill(K_EXTRAHARDKILL
, FUID
, HIT_SOME
)
4171 else if (not NoMove
) then
4173 GameX
:= gMapInfo
.Width
div 2;
4174 GameY
:= gMapInfo
.Height
div 2;
4183 FWantsInGame
:= False;
4188 if Self
= gPlayer1
then
4193 if Self
= gPlayer2
then
4200 if g_Game_IsNet
then
4201 MH_SEND_PlayerStats(FUID
);
4204 procedure TPlayer
.SwitchNoClip
;
4208 FGhost
:= not FGhost
;
4209 FPhysics
:= not FGhost
;
4221 procedure TPlayer
.Run(Direction
: TDirection
);
4225 if MAX_RUNVEL
> 8 then
4229 if Direction
= D_LEFT
then
4231 if FObj
.Vel
.X
> -MAX_RUNVEL
then
4232 FObj
.Vel
.X
:= FObj
.Vel
.X
- (MAX_RUNVEL
shr 3);
4235 if FObj
.Vel
.X
< MAX_RUNVEL
then
4236 FObj
.Vel
.X
:= FObj
.Vel
.X
+ (MAX_RUNVEL
shr 3);
4238 // Âîçìîæíî, ïèíàåì êóñêè:
4239 if (FObj
.Vel
.X
<> 0) and (gGibs
<> nil) then
4241 b
:= Abs(FObj
.Vel
.X
);
4242 if b
> 1 then b
:= b
* (Random(8 div b
) + 1);
4243 for a
:= 0 to High(gGibs
) do
4244 if gGibs
[a
].Live
and
4245 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
+FObj
.Rect
.Height
-4,
4246 FObj
.Rect
.Width
, 8, @gGibs
[a
].Obj
) and (Random(3) = 0) then
4248 if FObj
.Vel
.X
< 0 then
4249 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)+120) // íàëåâî
4251 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)); // íàïðàâî
4257 procedure TPlayer
.SeeDown();
4259 SetAction(A_SEEDOWN
);
4261 if FDirection
= D_LEFT
then FAngle
:= ANGLE_LEFTDOWN
else FAngle
:= ANGLE_RIGHTDOWN
;
4263 if FIncCam
> -120 then DecMin(FIncCam
, 5, -120);
4266 procedure TPlayer
.SeeUp();
4270 if FDirection
= D_LEFT
then FAngle
:= ANGLE_LEFTUP
else FAngle
:= ANGLE_RIGHTUP
;
4272 if FIncCam
< 120 then IncMax(FIncCam
, 5, 120);
4275 procedure TPlayer
.SetAction(Action
: Byte; Force
: Boolean = False);
4283 A_ATTACK
: Prior
:= 2;
4284 A_SEEUP
: Prior
:= 1;
4285 A_SEEDOWN
: Prior
:= 1;
4286 A_ATTACKUP
: Prior
:= 2;
4287 A_ATTACKDOWN
: Prior
:= 2;
4292 if (Prior
> FActionPrior
) or Force
then
4293 if not ((Prior
= 2) and (FCurrWeap
= WEAPON_SAW
)) then
4295 FActionPrior
:= Prior
;
4296 FActionAnim
:= Action
;
4297 FActionForce
:= Force
;
4298 FActionChanged
:= True;
4301 if Action
in [A_ATTACK
, A_ATTACKUP
, A_ATTACKDOWN
] then FModel
.SetFire(True);
4304 function TPlayer
.StayOnStep(XInc
, YInc
: Integer): Boolean;
4306 Result
:= not g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
-1,
4307 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False)
4308 and g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
,
4309 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False);
4312 function TPlayer
.TeleportTo(X
, Y
: Integer; silent
: Boolean; dir
: Byte): Boolean;
4319 if g_CollideLevel(X
, Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
) then
4321 g_Sound_PlayExAt('SOUND_GAME_NOTELEPORT', FObj
.X
, FObj
.Y
);
4322 if g_Game_IsServer
and g_Game_IsNet
then
4323 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_GAME_NOTELEPORT');
4327 FJustTeleported
:= True;
4332 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
4334 Anim
:= TAnimation
.Create(ID
, False, 3);
4337 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', FObj
.X
, FObj
.Y
);
4338 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4339 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4340 if g_Game_IsServer
and g_Game_IsNet
then
4341 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4342 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 1,
4346 FObj
.X
:= X
-PLAYER_RECT
.X
;
4347 FObj
.Y
:= Y
-PLAYER_RECT
.Y
;
4348 if FLive
and FGhost
then
4354 if not g_Game_IsNet
then
4358 SetDirection(D_LEFT
);
4364 SetDirection(D_RIGHT
);
4370 if FDirection
= D_RIGHT
then
4372 SetDirection(D_LEFT
);
4377 SetDirection(D_RIGHT
);
4383 if not silent
and (Anim
<> nil) then
4385 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4386 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4389 if g_Game_IsServer
and g_Game_IsNet
then
4390 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4391 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 0,
4398 function nonz(a
: Single): Single;
4406 procedure TPlayer
.Update();
4409 i
, ii
, wx
, wy
, xd
, yd
, k
: Integer;
4410 blockmon
, headwater
, dospawn
: Boolean;
4415 NetServer
:= g_Game_IsNet
and g_Game_IsServer
;
4416 AnyServer
:= g_Game_IsServer
;
4418 if g_Game_IsClient
and (NetInterpLevel
> 0) then
4419 DoLerp(NetInterpLevel
+ 1)
4425 if FClientID
>= 0 then
4427 FPing
:= NetClients
[FClientID
].Peer
^.lastRoundTripTime
;
4428 if NetClients
[FClientID
].Peer
^.packetsSent
> 0 then
4429 FLoss
:= Round(100*NetClients
[FClientID
].Peer
^.packetsLost
/NetClients
[FClientID
].Peer
^.packetsSent
)
4438 if FLive
and (gFly
or FJetpack
) then
4441 if FDirection
= D_LEFT
then
4446 if FLive
and (not FGhost
) then
4448 if FKeys
[KEY_UP
].Pressed
then
4450 if FKeys
[KEY_DOWN
].Pressed
then
4454 if (not (FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_DOWN
].Pressed
)) and
4457 i
:= g_basic
.Sign(FIncCam
);
4458 FIncCam
:= Abs(FIncCam
);
4459 DecMin(FIncCam
, 5, 0);
4460 FIncCam
:= FIncCam
*i
;
4463 if gTime
mod (GAME_TICK
*2) <> 0 then
4465 if (FObj
.Vel
.X
= 0) and FLive
then
4467 if FKeys
[KEY_LEFT
].Pressed
then
4469 if FKeys
[KEY_RIGHT
].Pressed
then
4474 g_Obj_Move(@FObj
, True, True, True);
4479 FActionChanged
:= False;
4483 // Let alive player do some actions
4484 if FKeys
[KEY_LEFT
].Pressed
then Run(D_LEFT
);
4485 if FKeys
[KEY_RIGHT
].Pressed
then Run(D_RIGHT
);
4486 if FKeys
[KEY_NEXTWEAPON
].Pressed
and AnyServer
then NextWeapon();
4487 if FKeys
[KEY_PREVWEAPON
].Pressed
and AnyServer
then PrevWeapon();
4488 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then Fire();
4489 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Use();
4490 if FKeys
[KEY_JUMP
].Pressed
then Jump()
4493 if AnyServer
and FJetpack
then
4497 if NetServer
then MH_SEND_PlayerStats(FUID
);
4499 FCanJetpack
:= True;
4506 for k
:= Low(FKeys
) to KEY_CHAT
-1 do
4508 if FKeys
[k
].Pressed
then
4516 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
4519 if (FTime
[T_RESPAWN
] <= gTime
) and
4520 gGameOn
and (not FLive
) then
4522 if (g_Player_GetCount() > 1) then
4526 gExit
:= EXIT_RESTART
;
4531 // Dead spectator actions
4534 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Fire();
4535 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then
4539 if (FSpectatePlayer
>= High(gPlayers
)) then
4540 FSpectatePlayer
:= -1
4544 for I
:= FSpectatePlayer
+ 1 to High(gPlayers
) do
4545 if gPlayers
[I
] <> nil then
4546 if gPlayers
[I
].Live
then
4547 if gPlayers
[I
].UID
<> FUID
then
4549 FSpectatePlayer
:= I
;
4554 if not SetSpect
then FSpectatePlayer
:= -1;
4565 if FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_JUMP
].Pressed
then
4567 FYTo
:= FObj
.Y
- 32;
4568 FSpectatePlayer
:= -1;
4570 if FKeys
[KEY_DOWN
].Pressed
then
4572 FYTo
:= FObj
.Y
+ 32;
4573 FSpectatePlayer
:= -1;
4575 if FKeys
[KEY_LEFT
].Pressed
then
4577 FXTo
:= FObj
.X
- 32;
4578 FSpectatePlayer
:= -1;
4580 if FKeys
[KEY_RIGHT
].Pressed
then
4582 FXTo
:= FObj
.X
+ 32;
4583 FSpectatePlayer
:= -1;
4586 if (FXTo
< -64) then
4588 else if (FXTo
> gMapInfo
.Width
+ 32) then
4589 FXTo
:= gMapInfo
.Width
+ 32;
4590 if (FYTo
< -72) then
4592 else if (FYTo
> gMapInfo
.Height
+ 32) then
4593 FYTo
:= gMapInfo
.Height
+ 32;
4597 g_Obj_Move(@FObj
, True, True, True)
4603 if (FSpectatePlayer
<= High(gPlayers
)) and (FSpectatePlayer
>= 0) then
4604 if gPlayers
[FSpectatePlayer
] <> nil then
4605 if gPlayers
[FSpectatePlayer
].Live
then
4607 FXTo
:= gPlayers
[FSpectatePlayer
].GameX
;
4608 FYTo
:= gPlayers
[FSpectatePlayer
].GameY
;
4612 blockmon
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
, FObj
.Y
+PLAYER_HEADRECT
.Y
,
4613 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
4614 PANEL_BLOCKMON
, True);
4615 headwater
:= HeadInLiquid(0, 0);
4617 // Ñîïðîòèâëåíèå âîçäóõà:
4618 if (not FLive
) or not (FKeys
[KEY_LEFT
].Pressed
or FKeys
[KEY_RIGHT
].Pressed
) then
4619 if FObj
.Vel
.X
<> 0 then
4620 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
4622 if (FLastHit
= HIT_TRAP
) and (FPain
> 90) then FPain
:= 90;
4623 DecMin(FPain
, 5, 0);
4624 DecMin(FPickup
, 1, 0);
4626 if FLive
and (FObj
.Y
> gMapInfo
.Height
+128) and AnyServer
then
4628 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
4629 FMegaRulez
[MR_SUIT
] := 0;
4630 FMegaRulez
[MR_INVUL
] := 0;
4631 FMegaRulez
[MR_INVIS
] := 0;
4632 Kill(K_FALLKILL
, 0, HIT_FALL
);
4639 if FCurrWeap
= WEAPON_SAW
then
4640 if not (FSawSound
.IsPlaying() or FSawSoundHit
.IsPlaying() or
4641 FSawSoundSelect
.IsPlaying()) then
4642 FSawSoundIdle
.PlayAt(FObj
.X
, FObj
.Y
);
4645 if (not FJetSoundFly
.IsPlaying()) and (not FJetSoundOn
.IsPlaying()) and
4646 (not FJetSoundOff
.IsPlaying()) then
4648 FJetSoundFly
.SetPosition(0);
4649 FJetSoundFly
.PlayAt(FObj
.X
, FObj
.Y
);
4652 for b
:= WEAPON_KASTET
to WEAPON_SUPERPULEMET
do
4653 if FReloading
[b
] > 0 then
4659 if FShellTimer
> -1 then
4660 if FShellTimer
= 0 then
4662 if FShellType
= SHELL_SHELL
then
4663 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
4664 GameVelX
, GameVelY
-2, SHELL_SHELL
)
4665 else if FShellType
= SHELL_DBLSHELL
then
4667 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
4668 GameVelX
+1, GameVelY
-2, SHELL_SHELL
);
4669 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
4670 GameVelX
-1, GameVelY
-2, SHELL_SHELL
);
4673 end else Dec(FShellTimer
);
4675 if (FBFGFireCounter
> -1) then
4676 if FBFGFireCounter
= 0 then
4680 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
4681 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
4682 xd
:= wx
+IfThen(FDirection
= D_LEFT
, -30, 30);
4683 yd
:= wy
+firediry();
4684 g_Weapon_bfgshot(wx
, wy
, xd
, yd
, FUID
);
4685 if NetServer
then MH_SEND_PlayerFire(FUID
, WEAPON_BFG
, wx
, wy
, xd
, yd
);
4686 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
4687 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
4688 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
4691 FReloading
[WEAPON_BFG
] := WEAPON_RELOAD
[WEAPON_BFG
];
4692 FBFGFireCounter
:= -1;
4695 FBFGFireCounter
:= 0
4697 Dec(FBFGFireCounter
);
4699 if (FMegaRulez
[MR_SUIT
] < gTime
) and AnyServer
then
4701 b
:= g_GetAcidHit(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
);
4703 if (b
> 0) and (gTime
mod (15*GAME_TICK
) = 0) then Damage(b
, 0, 0, 0, HIT_ACID
);
4706 if (headwater
or blockmon
) then
4712 if AnyServer
then Damage(10, 0, 0, 0, HIT_WATER
);
4715 else if (FAir
mod 31 = 0) and not blockmon
then
4717 g_GFX_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2), FObj
.Y
+PLAYER_RECT
.Y
-4, 5+Random(6), 8, 4);
4718 if Random(2) = 0 then
4719 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
4721 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
4723 end else if FAir
< AIR_DEF
then
4726 if FDamageBuffer
> 0 then
4728 if FDamageBuffer
>= 9 then
4732 if FDamageBuffer
< 30 then i
:= 9
4733 else if FDamageBuffer
< 100 then i
:= 18
4737 ii
:= Round(FDamageBuffer
*FHealth
/ nonz(FArmor
*(3/4)+FHealth
));
4738 FArmor
:= FArmor
-(FDamageBuffer
-ii
);
4739 FHealth
:= FHealth
-ii
;
4742 FHealth
:= FHealth
+FArmor
;
4747 if FHealth
<= 0 then
4748 if FHealth
> -30 then Kill(K_SIMPLEKILL
, FLastSpawnerUID
, FLastHit
)
4749 else if FHealth
> -50 then Kill(K_HARDKILL
, FLastSpawnerUID
, FLastHit
)
4750 else Kill(K_EXTRAHARDKILL
, FLastSpawnerUID
, FLastHit
);
4754 if FDamageBuffer
<= 20 then FModel
.PlaySound(MODELSOUND_PAIN
, 1, FObj
.X
, FObj
.Y
)
4755 else if FDamageBuffer
<= 55 then FModel
.PlaySound(MODELSOUND_PAIN
, 2, FObj
.X
, FObj
.Y
)
4756 else if FDamageBuffer
<= 120 then FModel
.PlaySound(MODELSOUND_PAIN
, 3, FObj
.X
, FObj
.Y
)
4757 else FModel
.PlaySound(MODELSOUND_PAIN
, 4, FObj
.X
, FObj
.Y
);
4764 end; // if FLive then ...
4766 if (FActionAnim
= A_PAIN
) and (FModel
.Animation
<> A_PAIN
) then
4768 FModel
.ChangeAnimation(FActionAnim
, FActionForce
);
4769 FModel
.GetCurrentAnimation
.MinLength
:= i
;
4770 FModel
.GetCurrentAnimationMask
.MinLength
:= i
;
4771 end else FModel
.ChangeAnimation(FActionAnim
, FActionForce
and (FModel
.Animation
<> A_STAND
));
4773 if (FModel
.GetCurrentAnimation
.Played
or ((not FActionChanged
) and (FModel
.Animation
= A_WALK
)))
4774 then SetAction(A_STAND
, True);
4776 if not ((FModel
.Animation
= A_WALK
) and (Abs(FObj
.Vel
.X
) < 4) and not FModel
.Fire
) then FModel
.Update
;
4778 for b
:= Low(FKeys
) to High(FKeys
) do
4779 if FKeys
[b
].Time
= 0 then FKeys
[b
].Pressed
:= False else Dec(FKeys
[b
].Time
);
4782 function TPlayer
.Collide(X
, Y
: Integer; Width
, Height
: Word): Boolean;
4784 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
4785 FObj
.Y
+PLAYER_RECT
.Y
,
4792 function TPlayer
.Collide(Panel
: TPanel
): Boolean;
4794 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
4795 FObj
.Y
+PLAYER_RECT
.Y
,
4799 Panel
.Width
, Panel
.Height
);
4802 function TPlayer
.Collide(X
, Y
: Integer): Boolean;
4804 X
:= X
-FObj
.X
-PLAYER_RECT
.X
;
4805 Y
:= Y
-FObj
.Y
-PLAYER_RECT
.Y
;
4806 Result
:= (x
>= 0) and (x
<= PLAYER_RECT
.Width
) and
4807 (y
>= 0) and (y
<= PLAYER_RECT
.Height
);
4810 function g_Player_ValidName(Name
: string): Boolean;
4816 if gPlayers
= nil then Exit
;
4818 for a
:= 0 to High(gPlayers
) do
4819 if gPlayers
[a
] <> nil then
4820 if LowerCase(Name
) = LowerCase(gPlayers
[a
].FName
) then
4827 procedure TPlayer
.SetDirection(Direction
: TDirection
);
4831 d
:= FModel
.Direction
;
4833 FModel
.Direction
:= Direction
;
4834 if d
<> Direction
then FModel
.ChangeAnimation(FModel
.Animation
, True);
4836 FDirection
:= Direction
;
4839 function TPlayer
.GetKeys(): Byte;
4843 if R_KEY_RED
in FRulez
then Result
:= KEY_RED
;
4844 if R_KEY_GREEN
in FRulez
then Result
:= Result
or KEY_GREEN
;
4845 if R_KEY_BLUE
in FRulez
then Result
:= Result
or KEY_BLUE
;
4847 if FTeam
= TEAM_RED
then Result
:= Result
or KEY_REDTEAM
;
4848 if FTeam
= TEAM_BLUE
then Result
:= Result
or KEY_BLUETEAM
;
4851 procedure TPlayer
.Use();
4855 if FTime
[T_USE
] > gTime
then Exit
;
4857 g_Triggers_PressR(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
,
4858 PLAYER_RECT
.Height
, FUID
, ACTIVATE_PLAYERPRESS
);
4860 for a
:= 0 to High(gPlayers
) do
4861 if (gPlayers
[a
] <> nil) and (gPlayers
[a
] <> Self
) and
4862 gPlayers
[a
].Live
and SameTeam(FUID
, gPlayers
[a
].FUID
) and
4863 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
4864 FObj
.Rect
.Width
, FObj
.Rect
.Height
, @gPlayers
[a
].FObj
) then
4866 gPlayers
[a
].Touch();
4867 if g_Game_IsNet
and g_Game_IsServer
then
4868 MH_SEND_GameEvent(NET_EV_PLAYER_TOUCH
, gPlayers
[a
].FUID
);
4871 FTime
[T_USE
] := gTime
+120;
4874 procedure TPlayer
.NetFire(Wpn
: Byte; X
, Y
, AX
, AY
: Integer; WID
: Integer = -1);
4878 WX
, WY
, XD
, YD
: Integer;
4889 if R_BERSERK
in FRulez
then
4891 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
4892 obj
.X
:= FObj
.X
+FObj
.Rect
.X
;
4893 obj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
4896 obj
.rect
.Width
:= 39;
4897 obj
.rect
.Height
:= 52;
4898 obj
.Vel
.X
:= (xd
-wx
) div 2;
4899 obj
.Vel
.Y
:= (yd
-wy
) div 2;
4900 obj
.Accel
.X
:= xd
-wx
;
4901 obj
.Accel
.y
:= yd
-wy
;
4903 if g_Weapon_Hit(@obj
, 50, FUID
, HIT_SOME
) <> 0 then
4904 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
4906 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
4910 FPain
:= min(FPain
+ 25, 50);
4912 g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
4917 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
4918 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
4920 FSawSoundSelect
.Stop();
4922 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
4924 else if not FSawSoundHit
.IsPlaying() then
4926 FSawSoundSelect
.Stop();
4927 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
4934 g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', GameX
, Gamey
);
4935 FFireAngle
:= FAngle
;
4937 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
4938 GameVelX
, GameVelY
-2, SHELL_BULLET
);
4943 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
4944 FFireAngle
:= FAngle
;
4947 FShellType
:= SHELL_SHELL
;
4952 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN2', Gamex
, Gamey
);
4953 FFireAngle
:= FAngle
;
4956 FShellType
:= SHELL_DBLSHELL
;
4961 g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', Gamex
, Gamey
);
4962 FFireAngle
:= FAngle
;
4964 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
4965 GameVelX
, GameVelY
-2, SHELL_BULLET
);
4968 WEAPON_ROCKETLAUNCHER
:
4970 g_Weapon_Rocket(wx
, wy
, xd
, yd
, FUID
, WID
);
4971 FFireAngle
:= FAngle
;
4977 g_Weapon_Plasma(wx
, wy
, xd
, yd
, FUID
, WID
);
4978 FFireAngle
:= FAngle
;
4984 g_Weapon_BFGShot(wx
, wy
, xd
, yd
, FUID
, WID
);
4985 FFireAngle
:= FAngle
;
4989 WEAPON_SUPERPULEMET
:
4991 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
4992 FFireAngle
:= FAngle
;
4994 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
4995 GameVelX
, GameVelY
-2, SHELL_SHELL
);
5001 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
5002 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
5003 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
5006 procedure TPlayer
.DoLerp(Level
: Integer = 2);
5008 if FObj
.X
<> FXTo
then FObj
.X
:= Lerp(FObj
.X
, FXTo
, Level
);
5009 if FObj
.Y
<> FYTo
then FObj
.Y
:= Lerp(FObj
.Y
, FYTo
, Level
);
5012 procedure TPlayer
.SetLerp(XTo
, YTo
: Integer);
5016 if NetInterpLevel
< 1 then
5026 AX
:= Abs(FXTo
- FObj
.X
);
5027 AY
:= Abs(FYTo
- FObj
.Y
);
5028 if (AX
> 32) or (AX
<= NetInterpLevel
) then
5030 if (AY
> 32) or (AY
<= NetInterpLevel
) then
5035 function TPlayer
.FullInLift(XInc
, YInc
: Integer): Integer;
5037 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5038 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5039 PANEL_LIFTUP
, False) then Result
:= -1
5041 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5042 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5043 PANEL_LIFTDOWN
, False) then Result
:= 1
5047 function TPlayer
.GetFlag(Flag
: Byte): Boolean;
5054 if Flag
= FLAG_NONE
then
5057 if not g_Game_IsServer
then Exit
;
5059 // Ïðèíåñ ÷óæîé ôëàã íà ñâîþ áàçó:
5060 if (Flag
= FTeam
) and
5061 (gFlags
[Flag
].State
= FLAG_STATE_NORMAL
) and
5062 (FFlag
<> FLAG_NONE
) then
5064 if FFlag
= FLAG_RED
then
5065 s
:= _lc
[I_PLAYER_FLAG_RED
]
5067 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5069 evtype
:= FLAG_STATE_SCORED
;
5071 ts
:= Format('%.4d', [gFlags
[FFlag
].CaptureTime
]);
5072 Insert('.', ts
, Length(ts
) + 1 - 3);
5073 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_CAPTURE
], [FName
, s
, ts
]), True);
5075 g_Map_ResetFlag(FFlag
);
5076 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_CAPTURE
], [AnsiUpperCase(s
)]), 144);
5078 gTeamStat
[FTeam
].Goals
:= gTeamStat
[FTeam
].Goals
+ 1;
5081 if g_Game_IsNet
then
5083 MH_SEND_FlagEvent(evtype
, FFlag
, FUID
, False);
5087 gFlags
[FFlag
].CaptureTime
:= 0;
5092 // Ïîäîáðàë ñâîé ôëàã - âåðíóë åãî íà áàçó:
5093 if (Flag
= FTeam
) and
5094 (gFlags
[Flag
].State
= FLAG_STATE_DROPPED
) then
5096 if Flag
= FLAG_RED
then
5097 s
:= _lc
[I_PLAYER_FLAG_RED
]
5099 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5101 evtype
:= FLAG_STATE_RETURNED
;
5102 gFlags
[Flag
].CaptureTime
:= 0;
5104 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_RETURN
], [FName
, s
]), True);
5106 g_Map_ResetFlag(Flag
);
5107 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
5110 if g_Game_IsNet
then
5112 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5118 // Ïîäîáðàë ÷óæîé ôëàã:
5119 if (Flag
<> FTeam
) and (FTime
[T_FLAGCAP
] <= gTime
) then
5123 if Flag
= FLAG_RED
then
5124 s
:= _lc
[I_PLAYER_FLAG_RED
]
5126 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5128 evtype
:= FLAG_STATE_CAPTURED
;
5130 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_GET
], [FName
, s
]), True);
5132 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_GET
], [AnsiUpperCase(s
)]), 144);
5134 gFlags
[Flag
].State
:= FLAG_STATE_CAPTURED
;
5137 if g_Game_IsNet
then
5139 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5145 procedure TPlayer
.SetFlag(Flag
: Byte);
5148 if FModel
<> nil then
5149 FModel
.SetFlag(FFlag
);
5152 function TPlayer
.DropFlag(): Boolean;
5157 if (not g_Game_IsServer
) or (FFlag
= FLAG_NONE
) then
5159 FTime
[T_FLAGCAP
] := gTime
+ 2000;
5160 with gFlags
[FFlag
] do
5164 Direction
:= FDirection
;
5165 State
:= FLAG_STATE_DROPPED
;
5167 g_Obj_Push(@Obj
, (FObj
.Vel
.X
div 2)-2+Random(5),
5168 (FObj
.Vel
.Y
div 2)-2+Random(5));
5170 if FFlag
= FLAG_RED
then
5171 s
:= _lc
[I_PLAYER_FLAG_RED
]
5173 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5175 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_DROP
], [FName
, s
]), True);
5176 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_DROP
], [AnsiUpperCase(s
)]), 144);
5178 if g_Game_IsNet
then
5179 MH_SEND_FlagEvent(FLAG_STATE_DROPPED
, Flag
, FUID
, False);
5185 procedure TPlayer
.GetSecret();
5190 procedure TPlayer
.PressKey(Key
: Byte; Time
: Word = 1);
5192 Assert(Key
<= High(FKeys
));
5194 FKeys
[Key
].Pressed
:= True;
5195 FKeys
[Key
].Time
:= Time
;
5198 function TPlayer
.IsKeyPressed(K
: Byte): Boolean;
5200 Result
:= FKeys
[K
].Pressed
;
5203 procedure TPlayer
.ReleaseKeys();
5207 for a
:= Low(FKeys
) to High(FKeys
) do
5209 FKeys
[a
].Pressed
:= False;
5214 procedure TPlayer
.OnDamage(Angle
: SmallInt);
5218 function TPlayer
.firediry(): Integer;
5220 if FKeys
[KEY_UP
].Pressed
then Result
:= -42
5221 else if FKeys
[KEY_DOWN
].Pressed
then Result
:= 19
5225 procedure TPlayer
.RememberState();
5229 FSavedState
.Health
:= FHealth
;
5230 FSavedState
.Armor
:= FArmor
;
5231 FSavedState
.Air
:= FAir
;
5232 FSavedState
.JetFuel
:= FJetFuel
;
5233 FSavedState
.CurrWeap
:= FCurrWeap
;
5234 FSavedState
.NextWeap
:= FNextWeap
;
5235 FSavedState
.NextWeapDelay
:= FNextWeapDelay
;
5238 FSavedState
.Ammo
[i
] := FAmmo
[i
];
5240 FSavedState
.MaxAmmo
[i
] := FMaxAmmo
[i
];
5242 FSavedState
.Rulez
:= FRulez
;
5243 FSavedState
.WaitRecall
:= True;
5246 procedure TPlayer
.RecallState();
5250 if not FSavedState
.WaitRecall
then Exit
;
5252 FHealth
:= FSavedState
.Health
;
5253 FArmor
:= FSavedState
.Armor
;
5254 FAir
:= FSavedState
.Air
;
5255 FJetFuel
:= FSavedState
.JetFuel
;
5256 FCurrWeap
:= FSavedState
.CurrWeap
;
5257 FNextWeap
:= FSavedState
.NextWeap
;
5258 FNextWeapDelay
:= FSavedState
.NextWeapDelay
;
5261 FAmmo
[i
] := FSavedState
.Ammo
[i
];
5263 FMaxAmmo
[i
] := FSavedState
.MaxAmmo
[i
];
5265 FRulez
:= FSavedState
.Rulez
;
5266 FSavedState
.WaitRecall
:= False;
5268 if gGameSettings
.GameType
= GT_SERVER
then
5269 MH_SEND_PlayerStats(FUID
);
5272 procedure TPlayer
.SaveState(var Mem
: TBinMemoryWriter
);
5284 Mem
:= TBinMemoryWriter
.Create(i
);
5286 // Ñèãíàòóðà èãðîêà:
5287 sig
:= PLAYER_SIGNATURE
; // 'PLYR'
5288 Mem
.WriteDWORD(sig
);
5290 Mem
.WriteBoolean(FIamBot
);
5292 Mem
.WriteWord(FUID
);
5294 Mem
.WriteString(FName
, 32);
5296 Mem
.WriteByte(FTeam
);
5298 Mem
.WriteBoolean(FLive
);
5299 // Èçðàñõîäîâàë ëè âñå æèçíè:
5300 Mem
.WriteBoolean(FNoRespawn
);
5302 if FDirection
= D_LEFT
then
5308 Mem
.WriteInt(FHealth
);
5310 Mem
.WriteByte(FLives
);
5312 Mem
.WriteInt(FArmor
);
5316 Mem
.WriteInt(FJetFuel
);
5318 Mem
.WriteInt(FPain
);
5320 Mem
.WriteInt(FKills
);
5322 Mem
.WriteInt(FMonsterKills
);
5324 Mem
.WriteInt(FFrags
);
5326 Mem
.WriteByte(FFragCombo
);
5327 // Âðåìÿ ïîñëåäíåãî ôðàãà:
5328 Mem
.WriteDWORD(FLastFrag
);
5330 Mem
.WriteInt(FDeath
);
5331 // Êàêîé ôëàã íåñåò:
5332 Mem
.WriteByte(FFlag
);
5334 Mem
.WriteInt(FSecrets
);
5336 Mem
.WriteByte(FCurrWeap
);
5338 Mem
.WriteWord(FNextWeap
);
5340 Mem
.WriteByte(FNextWeapDelay
);
5341 // Âðåìÿ çàðÿäêè BFG:
5342 Mem
.WriteSmallInt(FBFGFireCounter
);
5344 Mem
.WriteInt(FDamageBuffer
);
5345 // Ïîñëåäíèé óäàðèâøèé:
5346 Mem
.WriteWord(FLastSpawnerUID
);
5347 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà:
5348 Mem
.WriteByte(FLastHit
);
5350 Obj_SaveState(@FObj
, Mem
);
5351 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ:
5352 for i
:= A_BULLETS
to A_CELLS
do
5353 Mem
.WriteWord(FAmmo
[i
]);
5354 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ:
5355 for i
:= A_BULLETS
to A_CELLS
do
5356 Mem
.WriteWord(FMaxAmmo
[i
]);
5358 for i
:= WEAPON_KASTET
to WEAPON_SUPERPULEMET
do
5359 Mem
.WriteBoolean(FWeapon
[i
]);
5360 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ:
5361 for i
:= WEAPON_KASTET
to WEAPON_SUPERPULEMET
do
5362 Mem
.WriteWord(FReloading
[i
]);
5364 if R_ITEM_BACKPACK
in FRulez
then
5369 // Íàëè÷èå êðàñíîãî êëþ÷à:
5370 if R_KEY_RED
in FRulez
then
5375 // Íàëè÷èå çåëåíîãî êëþ÷à:
5376 if R_KEY_GREEN
in FRulez
then
5381 // Íàëè÷èå ñèíåãî êëþ÷à:
5382 if R_KEY_BLUE
in FRulez
then
5387 // Íàëè÷èå áåðñåðêà:
5388 if R_BERSERK
in FRulez
then
5393 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ:
5394 for i
:= MR_SUIT
to MR_MAX
do
5395 Mem
.WriteDWORD(FMegaRulez
[i
]);
5396 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà:
5397 for i
:= T_RESPAWN
to T_FLAGCAP
do
5398 Mem
.WriteDWORD(FTime
[i
]);
5401 Mem
.WriteString(str
);
5411 procedure TPlayer
.LoadState(var Mem
: TBinMemoryReader
);
5421 // Ñèãíàòóðà èãðîêà:
5423 if sig
<> PLAYER_SIGNATURE
then // 'PLYR'
5425 raise EBinSizeError
.Create('TPlayer.LoadState: Wrong Player Signature');
5428 Mem
.ReadBoolean(FIamBot
);
5432 Mem
.ReadString(str
);
5433 if (Self
<> gPlayer1
) and (Self
<> gPlayer2
) then
5436 Mem
.ReadByte(FTeam
);
5438 Mem
.ReadBoolean(FLive
);
5439 // Èçðàñõîäîâàë ëè âñå æèçíè:
5440 Mem
.ReadBoolean(FNoRespawn
);
5444 FDirection
:= D_LEFT
5446 FDirection
:= D_RIGHT
;
5448 Mem
.ReadInt(FHealth
);
5450 Mem
.ReadByte(FLives
);
5452 Mem
.ReadInt(FArmor
);
5456 Mem
.ReadInt(FJetFuel
);
5460 Mem
.ReadInt(FKills
);
5462 Mem
.ReadInt(FMonsterKills
);
5464 Mem
.ReadInt(FFrags
);
5466 Mem
.ReadByte(FFragCombo
);
5467 // Âðåìÿ ïîñëåäíåãî ôðàãà:
5468 Mem
.ReadDWORD(FLastFrag
);
5470 Mem
.ReadInt(FDeath
);
5471 // Êàêîé ôëàã íåñåò:
5472 Mem
.ReadByte(FFlag
);
5474 Mem
.ReadInt(FSecrets
);
5476 Mem
.ReadByte(FCurrWeap
);
5478 Mem
.ReadWord(FNextWeap
);
5480 Mem
.ReadByte(FNextWeapDelay
);
5481 // Âðåìÿ çàðÿäêè BFG:
5482 Mem
.ReadSmallInt(FBFGFireCounter
);
5484 Mem
.ReadInt(FDamageBuffer
);
5485 // Ïîñëåäíèé óäàðèâøèé:
5486 Mem
.ReadWord(FLastSpawnerUID
);
5487 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà:
5488 Mem
.ReadByte(FLastHit
);
5490 Obj_LoadState(@FObj
, Mem
);
5491 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ:
5492 for i
:= A_BULLETS
to A_CELLS
do
5493 Mem
.ReadWord(FAmmo
[i
]);
5494 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ:
5495 for i
:= A_BULLETS
to A_CELLS
do
5496 Mem
.ReadWord(FMaxAmmo
[i
]);
5498 for i
:= WEAPON_KASTET
to WEAPON_SUPERPULEMET
do
5499 Mem
.ReadBoolean(FWeapon
[i
]);
5500 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ:
5501 for i
:= WEAPON_KASTET
to WEAPON_SUPERPULEMET
do
5502 Mem
.ReadWord(FReloading
[i
]);
5506 Include(FRulez
, R_ITEM_BACKPACK
);
5507 // Íàëè÷èå êðàñíîãî êëþ÷à:
5510 Include(FRulez
, R_KEY_RED
);
5511 // Íàëè÷èå çåëåíîãî êëþ÷à:
5514 Include(FRulez
, R_KEY_GREEN
);
5515 // Íàëè÷èå ñèíåãî êëþ÷à:
5518 Include(FRulez
, R_KEY_BLUE
);
5519 // Íàëè÷èå áåðñåðêà:
5522 Include(FRulez
, R_BERSERK
);
5523 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ:
5524 for i
:= MR_SUIT
to MR_MAX
do
5525 Mem
.ReadDWORD(FMegaRulez
[i
]);
5526 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà:
5527 for i
:= T_RESPAWN
to T_FLAGCAP
do
5528 Mem
.ReadDWORD(FTime
[i
]);
5530 Mem
.ReadString(str
);
5532 Mem
.ReadByte(FColor
.R
);
5533 Mem
.ReadByte(FColor
.G
);
5534 Mem
.ReadByte(FColor
.B
);
5535 if Self
= gPlayer1
then
5537 str
:= gPlayer1Settings
.Model
;
5538 FColor
:= gPlayer1Settings
.Color
;
5540 if Self
= gPlayer2
then
5542 str
:= gPlayer2Settings
.Model
;
5543 FColor
:= gPlayer2Settings
.Color
;
5545 // Îáíîâëÿåì ìîäåëü èãðîêà:
5547 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
5548 FModel
.Color
:= TEAMCOLOR
[FTeam
]
5550 FModel
.Color
:= FColor
;
5553 procedure TPlayer
.AllRulez(Health
: Boolean);
5559 FHealth
:= PLAYER_HP_LIMIT
;
5560 FArmor
:= PLAYER_AP_LIMIT
;
5564 for a
:= WEAPON_KASTET
to WEAPON_SUPERPULEMET
do FWeapon
[a
] := True;
5565 for a
:= A_BULLETS
to A_CELLS
do FAmmo
[a
] := 30000;
5566 FRulez
:= FRulez
+[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
];
5569 procedure TPlayer
.RestoreHealthArmor();
5571 FHealth
:= PLAYER_HP_LIMIT
;
5572 FArmor
:= PLAYER_AP_LIMIT
;
5575 procedure TPlayer
.FragCombo();
5579 if (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) or g_Game_IsClient
then
5581 if gTime
- FLastFrag
< FRAG_COMBO_TIME
then
5583 if FFragCombo
< 5 then
5585 Param
:= FUID
or (FFragCombo
shl 16);
5586 if (FComboEvnt
>= Low(gDelayedEvents
)) and
5587 (FComboEvnt
<= High(gDelayedEvents
)) and
5588 gDelayedEvents
[FComboEvnt
].Pending
and
5589 (gDelayedEvents
[FComboEvnt
].DEType
= DE_KILLCOMBO
) and
5590 (gDelayedEvents
[FComboEvnt
].DENum
and $FFFF = FUID
) then
5592 gDelayedEvents
[FComboEvnt
].Time
:= gTime
+ 500;
5593 gDelayedEvents
[FComboEvnt
].DENum
:= Param
;
5596 FComboEvnt
:= g_Game_DelayEvent(DE_KILLCOMBO
, 500, Param
);
5604 procedure TPlayer
.GiveItem(ItemType
: Byte);
5608 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
5610 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
5614 if FAir
< AIR_MAX
then
5621 if not (R_BERSERK
in FRulez
) then
5623 Include(FRulez
, R_BERSERK
);
5624 if FBFGFireCounter
< 1 then
5626 FCurrWeap
:= WEAPON_KASTET
;
5628 FModel
.SetWeapon(WEAPON_KASTET
);
5632 FBerserk
:= gTime
+30000;
5634 if FHealth
< PLAYER_HP_SOFT
then
5636 FHealth
:= PLAYER_HP_SOFT
;
5637 FBerserk
:= gTime
+30000;
5642 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
5644 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
5648 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
5650 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
5654 if FJetFuel
< JET_MAX
then
5656 FJetFuel
:= JET_MAX
;
5659 ITEM_WEAPON_SAW
: FWeapon
[WEAPON_SAW
] := True;
5660 ITEM_WEAPON_SHOTGUN1
: FWeapon
[WEAPON_SHOTGUN1
] := True;
5661 ITEM_WEAPON_SHOTGUN2
: FWeapon
[WEAPON_SHOTGUN2
] := True;
5662 ITEM_WEAPON_CHAINGUN
: FWeapon
[WEAPON_CHAINGUN
] := True;
5663 ITEM_WEAPON_ROCKETLAUNCHER
: FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
5664 ITEM_WEAPON_PLASMA
: FWeapon
[WEAPON_PLASMA
] := True;
5665 ITEM_WEAPON_BFG
: FWeapon
[WEAPON_BFG
] := True;
5666 ITEM_WEAPON_SUPERPULEMET
: FWeapon
[WEAPON_SUPERPULEMET
] := True;
5668 ITEM_AMMO_BULLETS
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
5669 ITEM_AMMO_BULLETS_BOX
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
5670 ITEM_AMMO_SHELLS
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
5671 ITEM_AMMO_SHELLS_BOX
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
5672 ITEM_AMMO_ROCKET
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
5673 ITEM_AMMO_ROCKET_BOX
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
5674 ITEM_AMMO_CELL
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
5675 ITEM_AMMO_CELL_BIG
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
5678 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
5679 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
5680 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
5681 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) then
5683 FMaxAmmo
[A_BULLETS
] := 400;
5684 FMaxAmmo
[A_SHELLS
] := 100;
5685 FMaxAmmo
[A_ROCKETS
] := 100;
5686 FMaxAmmo
[A_CELLS
] := 600;
5688 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
5689 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
5690 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
5691 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
5693 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
5696 ITEM_KEY_RED
: if not (R_KEY_RED
in FRulez
) then Include(FRulez
, R_KEY_RED
);
5697 ITEM_KEY_GREEN
: if not (R_KEY_GREEN
in FRulez
) then Include(FRulez
, R_KEY_GREEN
);
5698 ITEM_KEY_BLUE
: if not (R_KEY_BLUE
in FRulez
) then Include(FRulez
, R_KEY_BLUE
);
5700 ITEM_BOTTLE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
5701 ITEM_HELMET
: if FArmor
< PLAYER_AP_LIMIT
then IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
5706 if g_Game_IsNet
and g_Game_IsServer
then
5707 MH_SEND_PlayerStats(FUID
);
5710 procedure TPlayer
.FlySmoke(Times
: DWORD
= 1);
5715 if (Random(5) = 1) and (Times
= 1) then
5718 if BodyInLiquid(0, 0) then
5720 g_GFX_Bubbles(Obj
.X
+Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2)+Random(3)-1,
5721 Obj
.Y
+Obj
.Rect
.Height
+8, 1, 8, 4);
5722 if Random(2) = 0 then
5723 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
5725 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
5729 if g_Frames_Get(id
, 'FRAMES_SMOKE') then
5731 for i
:= 1 to Times
do
5733 Anim
:= TAnimation
.Create(id
, False, 3);
5735 g_GFX_OnceAnim(Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(Anim
.Width
div 2),
5736 Obj
.Y
+Obj
.Rect
.Height
-4+Random(8+Times
*2), Anim
, ONCEANIM_SMOKE
);
5742 procedure TPlayer
.PauseSounds(Enable
: Boolean);
5744 FSawSound
.Pause(Enable
);
5745 FSawSoundIdle
.Pause(Enable
);
5746 FSawSoundHit
.Pause(Enable
);
5747 FSawSoundSelect
.Pause(Enable
);
5752 constructor TCorpse
.Create(X
, Y
: Integer; ModelName
: String; aMess
: Boolean);
5757 FObj
.Rect
:= PLAYER_CORPSERECT
;
5758 FModelName
:= ModelName
;
5763 FState
:= CORPSE_STATE_MESS
;
5764 g_PlayerModel_GetAnim(ModelName
, A_DIE2
, FAnimation
, FAnimationMask
);
5768 FState
:= CORPSE_STATE_NORMAL
;
5769 g_PlayerModel_GetAnim(ModelName
, A_DIE1
, FAnimation
, FAnimationMask
);
5773 destructor TCorpse
.Destroy();
5780 procedure TCorpse
.Damage(Value
: Word; vx
, vy
: Integer);
5784 if FState
= CORPSE_STATE_REMOVEME
then
5787 FDamage
:= FDamage
+ Value
;
5789 if FDamage
> 150 then
5791 if FAnimation
<> nil then
5796 FState
:= CORPSE_STATE_REMOVEME
;
5798 g_Player_CreateGibs(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
5799 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2),
5800 FModelName
, FColor
);
5801 // Çâóê ìÿñà îò òðóïà:
5802 pm
:= g_PlayerModel_Get(FModelName
);
5803 pm
.PlaySound(MODELSOUND_DIE
, 5, FObj
.X
, FObj
.Y
);
5809 FObj
.Vel
.X
:= FObj
.Vel
.X
+ vx
;
5810 FObj
.Vel
.Y
:= FObj
.Vel
.Y
+ vy
;
5811 g_GFX_Blood(FObj
.X
+PLAYER_CORPSERECT
.X
+(PLAYER_CORPSERECT
.Width
div 2),
5812 FObj
.Y
+PLAYER_CORPSERECT
.Y
+(PLAYER_CORPSERECT
.Height
div 2),
5813 Value
, vx
, vy
, 16, (PLAYER_CORPSERECT
.Height
*2) div 3,
5818 procedure TCorpse
.Draw();
5820 if FState
= CORPSE_STATE_REMOVEME
then
5823 if FAnimation
<> nil then
5824 FAnimation
.Draw(FObj
.X
, FObj
.Y
, M_NONE
);
5826 if FAnimationMask
<> nil then
5829 FAnimationMask
.Draw(FObj
.X
, FObj
.Y
, M_NONE
);
5836 procedure TCorpse
.Update();
5840 if FState
= CORPSE_STATE_REMOVEME
then
5843 if gTime
mod (GAME_TICK
*2) <> 0 then
5845 g_Obj_Move(@FObj
, True, True, True);
5850 // Ñîïðîòèâëåíèå âîçäóõà äëÿ òðóïà:
5851 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
5853 st
:= g_Obj_Move(@FObj
, True, True, True);
5855 if WordBool(st
and MOVE_FALLOUT
) then
5857 FState
:= CORPSE_STATE_REMOVEME
;
5861 if FAnimation
<> nil then
5862 FAnimation
.Update();
5863 if FAnimationMask
<> nil then
5864 FAnimationMask
.Update();
5867 procedure TCorpse
.SaveState(var Mem
: TBinMemoryWriter
);
5876 sig
:= CORPSE_SIGNATURE
; // 'CORP'
5877 Mem
.WriteDWORD(sig
);
5879 Mem
.WriteByte(FState
);
5880 // Íàêîïëåííûé óðîí:
5881 Mem
.WriteByte(FDamage
);
5883 Mem
.WriteByte(FColor
.R
);
5884 Mem
.WriteByte(FColor
.G
);
5885 Mem
.WriteByte(FColor
.B
);
5887 Obj_SaveState(@FObj
, Mem
);
5888 // Åñòü ëè àíèìàöèÿ:
5889 anim
:= FAnimation
<> nil;
5890 Mem
.WriteBoolean(anim
);
5891 // Åñëè åñòü - ñîõðàíÿåì:
5893 FAnimation
.SaveState(Mem
);
5894 // Åñòü ëè ìàñêà àíèìàöèè:
5895 anim
:= FAnimationMask
<> nil;
5896 Mem
.WriteBoolean(anim
);
5897 // Åñëè åñòü - ñîõðàíÿåì:
5899 FAnimationMask
.SaveState(Mem
);
5902 procedure TCorpse
.LoadState(var Mem
: TBinMemoryReader
);
5912 if sig
<> CORPSE_SIGNATURE
then // 'CORP'
5914 raise EBinSizeError
.Create('TCorpse.LoadState: Wrong Corpse Signature');
5917 Mem
.ReadByte(FState
);
5918 // Íàêîïëåííûé óðîí:
5919 Mem
.ReadByte(FDamage
);
5921 Mem
.ReadByte(FColor
.R
);
5922 Mem
.ReadByte(FColor
.G
);
5923 Mem
.ReadByte(FColor
.B
);
5925 Obj_LoadState(@FObj
, Mem
);
5926 // Åñòü ëè àíèìàöèÿ:
5927 Mem
.ReadBoolean(anim
);
5928 // Åñëè åñòü - çàãðóæàåì:
5931 Assert(FAnimation
<> nil, 'TCorpse.LoadState: no FAnimation');
5932 FAnimation
.LoadState(Mem
);
5934 // Åñòü ëè ìàñêà àíèìàöèè:
5935 Mem
.ReadBoolean(anim
);
5936 // Åñëè åñòü - çàãðóæàåì:
5939 Assert(FAnimationMask
<> nil, 'TCorpse.LoadState: no FAnimationMask');
5940 FAnimationMask
.LoadState(Mem
);
5946 constructor TBot
.Create();
5953 FSpectator
:= False;
5960 for a
:= WEAPON_KASTET
to WEAPON_SUPERPULEMET
do
5962 FDifficult
.WeaponPrior
[a
] := WEAPON_PRIOR1
[a
];
5963 FDifficult
.CloseWeaponPrior
[a
] := WEAPON_PRIOR2
[a
];
5964 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
5968 destructor TBot
.Destroy();
5971 inherited Destroy();
5974 procedure TBot
.Draw();
5978 //if FTargetUID <> 0 then e_DrawLine(1, FObj.X, FObj.Y, g_Player_Get(FTargetUID).FObj.X,
5979 // g_Player_Get(FTargetUID).FObj.Y, 255, 0, 0);
5982 procedure TBot
.Respawn(Silent
: Boolean; Force
: Boolean = False);
5984 inherited Respawn(Silent
, Force
);
5987 FSelectedWeapon
:= FCurrWeap
;
5992 procedure TBot
.UpdateCombat();
6005 TTargetRecord
= array of TTarget
;
6007 function Compare(a
, b
: TTarget
): Integer;
6009 if a
.Line
and not b
.Line
then // A íà ëèíèè îãíÿ
6012 if not a
.Line
and b
.Line
then // B íà ëèíèè îãíÿ
6014 else // È A, è B íà ëèíèè èëè íå íà ëèíèè îãíÿ
6015 if (a
.Line
and b
.Line
) or ((not a
.Line
) and (not b
.Line
)) then
6017 if a
.Dist
> b
.Dist
then // B áëèæå
6019 else // A áëèæå èëè ðàâíîóäàëåííî ñ B
6022 else // Ñòðàííî -> A
6027 a
, x1
, y1
, x2
, y2
: Integer;
6028 targets
: TTargetRecord
;
6030 Target
, BestTarget
: TTarget
;
6031 firew
, fireh
: Integer;
6035 vsPlayer
, vsMonster
, ok
: Boolean;
6037 vsPlayer
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
);
6038 vsMonster
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
);
6040 // Åñëè òåêóùåå îðóæèå íå òî, ÷òî íóæíî, òî ìåíÿåì:
6041 if FCurrWeap
<> FSelectedWeapon
then
6044 // Åñëè íóæíî ñòðåëÿòü è íóæíîå îðóæèå, òî íàæàòü "Ñòðåëÿòü":
6045 if (GetAIFlag('NEEDFIRE') <> '') and (FCurrWeap
= FSelectedWeapon
) then
6047 RemoveAIFlag('NEEDFIRE');
6050 WEAPON_PLASMA
, WEAPON_SUPERPULEMET
, WEAPON_CHAINGUN
: PressKey(KEY_FIRE
, 20);
6051 WEAPON_SAW
, WEAPON_KASTET
, WEAPON_MEGAKASTET
: PressKey(KEY_FIRE
, 40);
6052 else PressKey(KEY_FIRE
);
6056 // Êîîðäèíàòû ñòâîëà:
6057 x1
:= FObj
.X
+ WEAPONPOINT
[FDirection
].X
;
6058 y1
:= FObj
.Y
+ WEAPONPOINT
[FDirection
].Y
;
6060 Target
.UID
:= FTargetUID
;
6063 if Target
.UID
<> 0 then
6064 begin // Öåëü åñòü - íàñòðàèâàåì
6065 if (g_GetUIDType(Target
.UID
) = UID_PLAYER
) and
6068 with g_Player_Get(Target
.UID
) do
6070 if (@FObj
) <> nil then
6077 Target
.cX
:= Target
.X
+ PLAYER_RECT_CX
;
6078 Target
.cY
:= Target
.Y
+ PLAYER_RECT_CY
;
6079 Target
.Rect
:= PLAYER_RECT
;
6080 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6081 Target
.Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6082 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6083 Target
.IsPlayer
:= True;
6087 if (g_GetUIDType(Target
.UID
) = UID_MONSTER
) and
6090 mon
:= g_Monsters_Get(Target
.UID
);
6093 Target
.X
:= mon
.Obj
.X
;
6094 Target
.Y
:= mon
.Obj
.Y
;
6096 Target
.cX
:= Target
.X
+ mon
.Obj
.Rect
.X
+ (mon
.Obj
.Rect
.Width
div 2);
6097 Target
.cY
:= Target
.Y
+ mon
.Obj
.Rect
.Y
+ (mon
.Obj
.Rect
.Height
div 2);
6098 Target
.Rect
:= mon
.Obj
.Rect
;
6099 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6100 Target
.Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6101 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6102 Target
.IsPlayer
:= False;
6109 begin // Öåëè íåò - îáíóëÿåì
6114 Target
.Visible
:= False;
6115 Target
.Line
:= False;
6116 Target
.IsPlayer
:= False;
6121 // Åñëè öåëü íå âèäèìà èëè íå íà ëèíèè îãíÿ, òî èùåì âñå âîçìîæíûå öåëè:
6122 if (not Target
.Line
) or (not Target
.Visible
) then
6126 for a
:= 0 to High(gPlayers
) do
6127 if (gPlayers
[a
] <> nil) and (gPlayers
[a
].Live
) and
6128 (gPlayers
[a
].FUID
<> FUID
) and
6129 (not SameTeam(FUID
, gPlayers
[a
].FUID
)) and
6130 (not gPlayers
[a
].NoTarget
) and
6131 (gPlayers
[a
].FMegaRulez
[MR_INVIS
] < gTime
) then
6133 if not TargetOnScreen(gPlayers
[a
].FObj
.X
+ PLAYER_RECT
.X
,
6134 gPlayers
[a
].FObj
.Y
+ PLAYER_RECT
.Y
) then
6137 x2
:= gPlayers
[a
].FObj
.X
+ PLAYER_RECT_CX
;
6138 y2
:= gPlayers
[a
].FObj
.Y
+ PLAYER_RECT_CY
;
6140 // Åñëè èãðîê íà ýêðàíå è íå ïðèêðûò ñòåíîé:
6141 if g_TraceVector(x1
, y1
, x2
, y2
) then
6143 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé:
6144 SetLength(targets
, Length(targets
)+1);
6145 with targets
[High(targets
)] do
6147 UID
:= gPlayers
[a
].FUID
;
6148 X
:= gPlayers
[a
].FObj
.X
;
6149 Y
:= gPlayers
[a
].FObj
.Y
;
6152 Rect
:= PLAYER_RECT
;
6153 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6154 Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6155 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6163 if vsMonster
and (gMonsters
<> nil) then
6164 for a
:= 0 to High(gMonsters
) do
6165 if (gMonsters
[a
] <> nil) and (gMonsters
[a
].Live
) and
6166 (gMonsters
[a
].MonsterType
<> MONSTER_BARREL
) then
6168 mon
:= gMonsters
[a
];
6170 if not TargetOnScreen(mon
.Obj
.X
+ mon
.Obj
.Rect
.X
,
6171 mon
.Obj
.Y
+ mon
.Obj
.Rect
.Y
) then
6174 x2
:= mon
.Obj
.X
+ mon
.Obj
.Rect
.X
+ (mon
.Obj
.Rect
.Width
div 2);
6175 y2
:= mon
.Obj
.Y
+ mon
.Obj
.Rect
.Y
+ (mon
.Obj
.Rect
.Height
div 2);
6177 // Åñëè ìîíñòð íà ýêðàíå è íå ïðèêðûò ñòåíîé:
6178 if g_TraceVector(x1
, y1
, x2
, y2
) then
6180 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé:
6181 SetLength(targets
, Length(targets
)+1);
6182 with targets
[High(targets
)] do
6189 Rect
:= mon
.Obj
.Rect
;
6190 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6191 Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6192 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6200 // Åñëè åñòü âîçìîæíûå öåëè:
6201 // (Âûáèðàåì ëó÷øóþ, ìåíÿåì îðóæèå è áåæèì ê íåé/îò íåå)
6202 if targets
<> nil then
6204 // Âûáèðàåì íàèëó÷øóþ öåëü:
6205 BestTarget
:= targets
[0];
6206 if Length(targets
) > 1 then
6207 for a
:= 1 to High(targets
) do
6208 if Compare(BestTarget
, targets
[a
]) = 1 then
6209 BestTarget
:= targets
[a
];
6211 // Åñëè ëó÷øàÿ öåëü "âèäíåå" òåêóùåé, òî òåêóùàÿ := ëó÷øàÿ:
6212 if ((not Target
.Visible
) and BestTarget
.Visible
and (Target
.UID
<> BestTarget
.UID
)) or
6213 ((not Target
.Line
) and BestTarget
.Line
and BestTarget
.Visible
) then
6215 Target
:= BestTarget
;
6217 if (Healthy() = 3) or ((Healthy() = 2)) then
6218 begin // Åñëè çäîðîâû - äîãîíÿåì
6219 if ((RunDirection() = D_LEFT
) and (Target
.X
> FObj
.X
)) then
6220 SetAIFlag('GORIGHT', '1');
6221 if ((RunDirection() = D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6222 SetAIFlag('GOLEFT', '1');
6225 begin // Åñëè ïîáèòû - óáåãàåì
6226 if ((RunDirection() = D_LEFT
) and (Target
.X
< FObj
.X
)) then
6227 SetAIFlag('GORIGHT', '1');
6228 if ((RunDirection() = D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6229 SetAIFlag('GOLEFT', '1');
6232 // Âûáèðàåì îðóæèå íà îñíîâå ðàññòîÿíèÿ è ïðèîðèòåòîâ:
6233 SelectWeapon(Abs(x1
-Target
.cX
));
6238 // (Äîãîíÿåì/óáåãàåì, ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëè)
6239 // (Åñëè öåëü äàëåêî, òî õâàòèò ñëåäèòü çà íåé)
6240 if Target
.UID
<> 0 then
6242 if not TargetOnScreen(Target
.X
+ Target
.Rect
.X
,
6243 Target
.Y
+ Target
.Rect
.Y
) then
6244 begin // Öåëü ñáåæàëà ñ "ýêðàíà"
6245 if (Healthy() = 3) or ((Healthy() = 2)) then
6246 begin // Åñëè çäîðîâû - äîãîíÿåì
6247 if ((RunDirection() = D_LEFT
) and (Target
.X
> FObj
.X
)) then
6248 SetAIFlag('GORIGHT', '1');
6249 if ((RunDirection() = D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6250 SetAIFlag('GOLEFT', '1');
6253 begin // Åñëè ïîáèòû - çàáûâàåì î öåëè è óáåãàåì
6255 if ((RunDirection() = D_LEFT
) and (Target
.X
< FObj
.X
)) then
6256 SetAIFlag('GORIGHT', '1');
6257 if ((RunDirection() = D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6258 SetAIFlag('GOLEFT', '1');
6262 begin // Öåëü ïîêà íà "ýêðàíå"
6263 // Åñëè öåëü íå çàãîðîæåíà ñòåíîé, òî îòìå÷àåì, êîãäà åå âèäåëè:
6264 if g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6265 FLastVisible
:= gTime
;
6266 // Åñëè ðàçíèöà âûñîò íå âåëèêà, òî äîãîíÿåì:
6267 if (Abs(FObj
.Y
-Target
.Y
) <= 128) then
6269 if ((RunDirection() = D_LEFT
) and (Target
.X
> FObj
.X
)) then
6270 SetAIFlag('GORIGHT', '1');
6271 if ((RunDirection() = D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6272 SetAIFlag('GOLEFT', '1');
6276 // Âûáèðàåì óãîë ââåðõ:
6277 if FDirection
= D_LEFT
then
6278 angle
:= ANGLE_LEFTUP
6280 angle
:= ANGLE_RIGHTUP
;
6282 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6283 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6285 // Åñëè ïðè óãëå ââåðõ ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
6286 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6287 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128), //96
6288 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6289 Target
.Rect
.Width
, Target
.Rect
.Height
) and
6290 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6291 begin // òî íóæíî ñòðåëÿòü ââåðõ
6292 SetAIFlag('NEEDFIRE', '1');
6293 SetAIFlag('NEEDSEEUP', '1');
6296 // Âûáèðàåì óãîë âíèç:
6297 if FDirection
= D_LEFT
then
6298 angle
:= ANGLE_LEFTDOWN
6300 angle
:= ANGLE_RIGHTDOWN
;
6302 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6303 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6305 // Åñëè ïðè óãëå âíèç ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
6306 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6307 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
6308 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6309 Target
.Rect
.Width
, Target
.Rect
.Height
) and
6310 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6311 begin // òî íóæíî ñòðåëÿòü âíèç
6312 SetAIFlag('NEEDFIRE', '1');
6313 SetAIFlag('NEEDSEEDOWN', '1');
6316 // Åñëè öåëü âèäíî è îíà íà òàêîé æå âûñîòå:
6317 if Target
.Visible
and
6318 (y1
+4 < Target
.Y
+Target
.Rect
.Y
+Target
.Rect
.Height
) and
6319 (y1
-4 > Target
.Y
+Target
.Rect
.Y
) then
6321 // Åñëè èäåì â ñòîðîíó öåëè, òî íàäî ñòðåëÿòü:
6322 if ((FDirection
= D_LEFT
) and (Target
.X
< FObj
.X
)) or
6323 ((FDirection
= D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6324 begin // òî íóæíî ñòðåëÿòü âïåðåä
6325 SetAIFlag('NEEDFIRE', '1');
6326 SetAIFlag('NEEDSEEDOWN', '');
6327 SetAIFlag('NEEDSEEUP', '');
6329 // Åñëè öåëü â ïðåäåëàõ "ýêðàíà" è ñëîæíîñòü ïîçâîëÿåò ïðûæêè ñáëèæåíèÿ:
6330 if Abs(FObj
.X
-Target
.X
) < Trunc(gPlayerScreenSize
.X
*0.75) then
6331 if GetRnd(FDifficult
.CloseJump
) then
6332 begin // òî åñëè ïîâåçåò - ïðûãàåì (îñîáåííî, åñëè áëèçêî)
6333 if Abs(FObj
.X
-Target
.X
) < 128 then
6337 if Random(a
) = 0 then
6338 SetAIFlag('NEEDJUMP', '1');
6342 // Åñëè öåëü âñå åùå åñòü:
6343 if Target
.UID
<> 0 then
6344 if gTime
-FLastVisible
> 2000 then // Åñëè âèäåëè äàâíî
6345 Target
.UID
:= 0 // òî çàáûòü öåëü
6346 else // Åñëè âèäåëè íåäàâíî
6347 begin // íî öåëü óáèëè
6348 if Target
.IsPlayer
then
6349 begin // Öåëü - èãðîê
6350 pla
:= g_Player_Get(Target
.UID
);
6351 if (pla
= nil) or (not pla
.Live
) or pla
.NoTarget
or
6352 (pla
.FMegaRulez
[MR_INVIS
] >= gTime
) then
6353 Target
.UID
:= 0; // òî çàáûòü öåëü
6356 begin // Öåëü - ìîíñòð
6357 mon
:= g_Monsters_Get(Target
.UID
);
6358 if (mon
= nil) or (not mon
.Live
) then
6359 Target
.UID
:= 0; // òî çàáûòü öåëü
6362 end; // if Target.UID <> 0
6364 FTargetUID
:= Target
.UID
;
6366 // Åñëè âîçìîæíûõ öåëåé íåò:
6367 // (Àòàêà ÷åãî-íèáóäü ñëåâà èëè ñïðàâà)
6368 if targets
= nil then
6369 if GetAIFlag('ATTACKLEFT') <> '' then
6370 begin // Åñëè íóæíî àòàêîâàòü íàëåâî
6371 RemoveAIFlag('ATTACKLEFT');
6373 SetAIFlag('NEEDJUMP', '1');
6375 if RunDirection() = D_RIGHT
then
6376 begin // Èäåì íå â òó ñòîðîíó
6377 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
6378 begin // Åñëè çäîðîâû, òî, âîçìîæíî, ñòðåëÿåì áåæèì âëåâî è ñòðåëÿåì
6379 SetAIFlag('NEEDFIRE', '1');
6380 SetAIFlag('GOLEFT', '1');
6384 begin // Èäåì â íóæíóþ ñòîðîíó
6385 if GetRnd(FDifficult
.InvisFire
) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
6386 SetAIFlag('NEEDFIRE', '1');
6387 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
6388 SetAIFlag('GORIGHT', '1');
6392 if GetAIFlag('ATTACKRIGHT') <> '' then
6393 begin // Åñëè íóæíî àòàêîâàòü íàïðàâî
6394 RemoveAIFlag('ATTACKRIGHT');
6396 SetAIFlag('NEEDJUMP', '1');
6398 if RunDirection() = D_LEFT
then
6399 begin // Èäåì íå â òó ñòîðîíó
6400 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
6401 begin // Åñëè çäîðîâû, òî, âîçìîæíî, áåæèì âïðàâî è ñòðåëÿåì
6402 SetAIFlag('NEEDFIRE', '1');
6403 SetAIFlag('GORIGHT', '1');
6408 if GetRnd(FDifficult
.InvisFire
) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
6409 SetAIFlag('NEEDFIRE', '1');
6410 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
6411 SetAIFlag('GOLEFT', '1');
6415 //HACK! (does it belongs there?)
6416 RealizeCurrentWeapon();
6418 // Åñëè åñòü âîçìîæíûå öåëè:
6419 // (Ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëÿì)
6420 if (targets
<> nil) and (GetAIFlag('NEEDFIRE') <> '') then
6421 for a
:= 0 to High(targets
) do
6423 // Åñëè ìîæåì ñòðåëÿòü ïî äèàãîíàëè:
6424 if GetRnd(FDifficult
.DiagFire
) then
6426 // Èùåì öåëü ñâåðõó è ñòðåëÿåì, åñëè åñòü:
6427 if FDirection
= D_LEFT
then
6428 angle
:= ANGLE_LEFTUP
6430 angle
:= ANGLE_RIGHTUP
;
6432 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6433 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6435 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6436 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
6437 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6438 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
6439 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
6441 SetAIFlag('NEEDFIRE', '1');
6442 SetAIFlag('NEEDSEEUP', '1');
6445 // Èùåì öåëü ñíèçó è ñòðåëÿåì, åñëè åñòü:
6446 if FDirection
= D_LEFT
then
6447 angle
:= ANGLE_LEFTDOWN
6449 angle
:= ANGLE_RIGHTDOWN
;
6451 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6452 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6454 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6455 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
6456 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6457 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
6458 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
6460 SetAIFlag('NEEDFIRE', '1');
6461 SetAIFlag('NEEDSEEDOWN', '1');
6465 // Åñëè öåëü "ïåðåä íîñîì", òî ñòðåëÿåì:
6466 if targets
[a
].Line
and targets
[a
].Visible
and
6467 (((FDirection
= D_LEFT
) and (targets
[a
].X
< FObj
.X
)) or
6468 ((FDirection
= D_RIGHT
) and (targets
[a
].X
> FObj
.X
))) then
6470 SetAIFlag('NEEDFIRE', '1');
6475 // Åñëè ëåòèò ïóëÿ, òî, âîçìîæíî, ïîäïðûãèâàåì:
6476 if g_Weapon_Danger(FUID
, FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
,
6477 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
,
6478 40+GetInterval(FDifficult
.Cover
, 40)) then
6479 SetAIFlag('NEEDJUMP', '1');
6481 // Åñëè êîí÷èëèñü ïàòîðíû, òî íóæíî ñìåíèòü îðóæèå:
6482 ammo
:= GetAmmoByWeapon(FCurrWeap
);
6483 if ((FCurrWeap
= WEAPON_SHOTGUN2
) and (ammo
< 2)) or
6484 ((FCurrWeap
= WEAPON_BFG
) and (ammo
< 40)) or
6486 SetAIFlag('SELECTWEAPON', '1');
6488 // Åñëè íóæíî ñìåíèòü îðóæèå, òî âûáèðàåì íóæíîå:
6489 if GetAIFlag('SELECTWEAPON') = '1' then
6492 RemoveAIFlag('SELECTWEAPON');
6496 procedure TBot
.Update();
6509 // Ïðîâåðÿåì, îòêëþ÷¸í ëè AI áîòîâ
6510 if (g_debug_BotAIOff
= 1) and (Team
= TEAM_RED
) then
6512 if (g_debug_BotAIOff
= 2) and (Team
= TEAM_BLUE
) then
6514 if g_debug_BotAIOff
= 3 then
6527 procedure TBot
.ReleaseKey(Key
: Byte);
6536 function TBot
.KeyPressed(Key
: Word): Boolean;
6538 Result
:= FKeys
[Key
].Pressed
;
6541 function TBot
.GetAIFlag(fName
: String20
): String20
;
6547 fName
:= LowerCase(fName
);
6549 if FAIFlags
<> nil then
6550 for a
:= 0 to High(FAIFlags
) do
6551 if LowerCase(FAIFlags
[a
].Name
) = fName
then
6553 Result
:= FAIFlags
[a
].Value
;
6558 procedure TBot
.RemoveAIFlag(fName
: String20
);
6562 if FAIFlags
= nil then Exit
;
6564 fName
:= LowerCase(fName
);
6566 for a
:= 0 to High(FAIFlags
) do
6567 if LowerCase(FAIFlags
[a
].Name
) = fName
then
6569 if a
<> High(FAIFlags
) then
6570 for b
:= a
to High(FAIFlags
)-1 do
6571 FAIFlags
[b
] := FAIFlags
[b
+1];
6573 SetLength(FAIFlags
, Length(FAIFlags
)-1);
6578 procedure TBot
.SetAIFlag(fName
, fValue
: String20
);
6586 fName
:= LowerCase(fName
);
6588 if FAIFlags
<> nil then
6589 for a
:= 0 to High(FAIFlags
) do
6590 if LowerCase(FAIFlags
[a
].Name
) = fName
then
6596 if ok
then FAIFlags
[a
].Value
:= fValue
6599 SetLength(FAIFlags
, Length(FAIFlags
)+1);
6600 with FAIFlags
[High(FAIFlags
)] do
6608 procedure TBot
.UpdateMove
;
6610 procedure GoLeft(Time
: Word = 1);
6612 ReleaseKey(KEY_LEFT
);
6613 ReleaseKey(KEY_RIGHT
);
6614 PressKey(KEY_LEFT
, Time
);
6615 SetDirection(D_LEFT
);
6618 procedure GoRight(Time
: Word = 1);
6620 ReleaseKey(KEY_LEFT
);
6621 ReleaseKey(KEY_RIGHT
);
6622 PressKey(KEY_RIGHT
, Time
);
6623 SetDirection(D_RIGHT
);
6626 function Rnd(a
: Word): Boolean;
6628 Result
:= Random(a
) = 0;
6631 procedure Turn(Time
: Word = 1200);
6633 if RunDirection() = D_LEFT
then GoRight(Time
) else GoLeft(Time
);
6638 ReleaseKey(KEY_LEFT
);
6639 ReleaseKey(KEY_RIGHT
);
6642 function CanRunLeft(): Boolean;
6644 Result
:= not CollideLevel(-1, 0);
6647 function CanRunRight(): Boolean;
6649 Result
:= not CollideLevel(1, 0);
6652 function CanRun(): Boolean;
6654 if RunDirection() = D_LEFT
then Result
:= CanRunLeft() else Result
:= CanRunRight();
6657 procedure Jump(Time
: Word = 30);
6659 PressKey(KEY_JUMP
, Time
);
6662 function NearHole(): Boolean;
6666 { TODO 5 : Ëåñòíèöû }
6667 sx
:= IfThen(RunDirection() = D_LEFT
, -1, 1);
6668 for x
:= 1 to PLAYER_RECT
.Width
do
6669 if (not StayOnStep(x
*sx
, 0)) and
6670 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
6671 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
6680 function BorderHole(): Boolean;
6684 { TODO 5 : Ëåñòíèöû }
6685 sx
:= IfThen(RunDirection() = D_LEFT
, -1, 1);
6686 for x
:= 1 to PLAYER_RECT
.Width
do
6687 if (not StayOnStep(x
*sx
, 0)) and
6688 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
6689 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
6691 for xx
:= x
to x
+32 do
6692 if CollideLevel(xx
*sx
, PLAYER_RECT
.Height
) then
6702 function NearDeepHole(): Boolean;
6708 sx
:= IfThen(RunDirection() = D_LEFT
, -1, 1);
6711 for x
:= 1 to PLAYER_RECT
.Width
do
6712 if (not StayOnStep(x
*sx
, 0)) and
6713 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
6714 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
6716 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
6718 if CollideLevel(x
*sx
, PLAYER_RECT
.Height
*y
) then Exit
;
6723 end else Result
:= False;
6726 function OverDeepHole(): Boolean;
6733 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
6735 if CollideLevel(0, PLAYER_RECT
.Height
*y
) then Exit
;
6742 function OnGround(): Boolean;
6744 Result
:= StayOnStep(0, 0) or CollideLevel(0, 1);
6747 function OnLadder(): Boolean;
6749 Result
:= FullInStep(0, 0);
6752 function BelowLadder(): Boolean;
6754 Result
:= (FullInStep(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) and
6755 not CollideLevel(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
6756 (FullInStep(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) and
6757 not CollideLevel(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
6760 function BelowLiftUp(): Boolean;
6762 Result
:= ((FullInLift(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) = -1) and
6763 not CollideLevel(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
6764 ((FullInLift(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) = -1) and
6765 not CollideLevel(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
6768 function OnTopLift(): Boolean;
6770 Result
:= (FullInLift(0, 0) = -1) and (FullInLift(0, -32) = 0);
6773 function CanJumpOver(): Boolean;
6777 sx
:= IfThen(RunDirection() = D_LEFT
, -1, 1);
6781 if not CollideLevel(sx
, 0) then Exit
;
6783 for y
:= 1 to BOT_MAXJUMP
do
6784 if CollideLevel(0, -y
) then Exit
else
6785 if not CollideLevel(sx
, -y
) then
6792 function CanJumpUp(Dist
: ShortInt): Boolean;
6799 if CollideLevel(Dist
, 0) then Exit
;
6802 for y
:= 0 to BOT_MAXJUMP
do
6803 if CollideLevel(Dist
, -y
) then
6812 for yy
:= y
+1 to BOT_MAXJUMP
do
6813 if not CollideLevel(Dist
, -yy
) then
6822 for y
:= 0 to BOT_MAXJUMP
do
6823 if CollideLevel(0, -y
) then
6831 if y
< yy
then Exit
;
6836 function IsSafeTrigger(): Boolean;
6841 if gTriggers
= nil then
6843 for a
:= 0 to High(gTriggers
) do
6844 if Collide(gTriggers
[a
].X
,
6847 gTriggers
[a
].Height
) and
6848 (gTriggers
[a
].TriggerType
in [TRIGGER_EXIT
, TRIGGER_CLOSEDOOR
,
6849 TRIGGER_CLOSETRAP
, TRIGGER_TRAP
,
6850 TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
,
6851 TRIGGER_ONOFF
, TRIGGER_SPAWNMONSTER
,
6852 TRIGGER_DAMAGE
, TRIGGER_SHOT
]) then
6857 // Âîçìîæíî, íàæèìàåì êíîïêó:
6858 if Rnd(16) and IsSafeTrigger() then
6861 // Åñëè ïîä ëèôòîì èëè ñòóïåíüêàìè, òî, âîçìîæíî, ïðûãàåì:
6862 if OnLadder() or ((BelowLadder() or BelowLiftUp()) and Rnd(8)) then
6864 ReleaseKey(KEY_LEFT
);
6865 ReleaseKey(KEY_RIGHT
);
6869 // Èäåì âëåâî, åñëè íàäî áûëî:
6870 if GetAIFlag('GOLEFT') <> '' then
6872 RemoveAIFlag('GOLEFT');
6873 if CanRunLeft() then
6877 // Èäåì âïðàâî, åñëè íàäî áûëî:
6878 if GetAIFlag('GORIGHT') <> '' then
6880 RemoveAIFlag('GORIGHT');
6881 if CanRunRight() then
6885 // Åñëè âûëåòåëè çà êàðòó, òî ïðîáóåì âåðíóòüñÿ:
6886 if FObj
.X
< -32 then
6889 if FObj
.X
+32 > gMapInfo
.Width
then
6892 // Ïðûãàåì, åñëè íàäî áûëî:
6893 if GetAIFlag('NEEDJUMP') <> '' then
6896 RemoveAIFlag('NEEDJUMP');
6899 // Ñìîòðèì ââåðõ, åñëè íàäî áûëî:
6900 if GetAIFlag('NEEDSEEUP') <> '' then
6903 ReleaseKey(KEY_DOWN
);
6904 PressKey(KEY_UP
, 20);
6905 RemoveAIFlag('NEEDSEEUP');
6908 // Ñìîòðèì âíèç, åñëè íàäî áûëî:
6909 if GetAIFlag('NEEDSEEDOWN') <> '' then
6912 ReleaseKey(KEY_DOWN
);
6913 PressKey(KEY_DOWN
, 20);
6914 RemoveAIFlag('NEEDSEEDOWN');
6917 // Åñëè íóæíî áûëî â äûðó è ìû íå íà çåìëå, òî ïîêîðíî ëåòèì:
6918 if GetAIFlag('GOINHOLE') <> '' then
6919 if not OnGround() then
6921 ReleaseKey(KEY_LEFT
);
6922 ReleaseKey(KEY_RIGHT
);
6923 RemoveAIFlag('GOINHOLE');
6924 SetAIFlag('FALLINHOLE', '1');
6927 // Åñëè ïàäàëè è äîñòèãëè çåìëè, òî õâàòèò ïàäàòü:
6928 if GetAIFlag('FALLINHOLE') <> '' then
6930 RemoveAIFlag('FALLINHOLE');
6932 // Åñëè ëåòåëè ïðÿìî è ñåé÷àñ íå íà ëåñòíèöå èëè íà âåðøèíå ëèôòà, òî îòõîäèì â ñòîðîíó:
6933 if not (KeyPressed(KEY_LEFT
) or KeyPressed(KEY_RIGHT
)) then
6934 if GetAIFlag('FALLINHOLE') = '' then
6935 if (not OnLadder()) or (FObj
.Vel
.Y
>= 0) or (OnTopLift()) then
6941 // Åñëè íà çåìëå è ìîæíî ïîäïðûãíóòü, òî, âîçìîæíî, ïðûãàåì:
6943 CanJumpUp(IfThen(RunDirection() = D_LEFT
, -1, 1)*32) and
6947 // Åñëè íà çåìëå è âîçëå äûðû (ãëóáèíà > 2 ðîñòîâ èãðîêà):
6948 if OnGround() and NearHole() then
6949 if NearDeepHole() then // Åñëè ýòî áåçäíà
6951 0..3: Turn(); // Áåæèì îáðàòíî
6952 4: Jump(); // Ïðûãàåì
6953 5: begin // Ïðûãàåì îáðàòíî
6958 else // Ýòî íå áåçäíà è ìû åùå íå ëåòèì òóäà
6959 if GetAIFlag('GOINHOLE') = '' then
6961 0: Turn(); // Íå íóæíî òóäà
6962 1: Jump(); // Âäðóã ïîâåçåò - ïðûãàåì
6963 else // Åñëè ÿìà ñ ãðàíèöåé, òî ïðè ñëó÷àå ìîæíî òóäà ïðûãíóòü
6964 if BorderHole() then
6965 SetAIFlag('GOINHOLE', '1');
6968 // Åñëè íà çåìëå, íî íåêóäà èäòè:
6969 if (not CanRun()) and OnGround() then
6971 // Åñëè ìû íà ëåñòíèöå èëè ìîæíî ïåðåïðûãíóòü, òî ïðûãàåì:
6972 if CanJumpOver() or OnLadder() then
6974 else // èíà÷å ïîïûòàåìñÿ â äðóãóþ ñòîðîíó
6975 if Random(2) = 0 then
6977 if IsSafeTrigger() then
6983 // Îñòàëîñü ìàëî âîçäóõà:
6984 if FAir
< 36 * 2 then
6987 // Âûáèðàåìñÿ èç êèñëîòû, åñëè íåò êîñòþìà, îáîæãëèñü, èëè ìàëî çäîðîâüÿ:
6988 if (FMegaRulez
[MR_SUIT
] < gTime
) and ((FLastHit
= HIT_ACID
) or (Healthy() <= 1)) then
6989 if BodyInAcid(0, 0) then
6993 function TBot
.FullInStep(XInc
, YInc
: Integer): Boolean;
6995 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
6996 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_STEP
, False);
6999 {function TBot.NeedItem(Item: Byte): Byte;
7004 procedure TBot
.SelectWeapon(Dist
: Integer);
7008 function HaveAmmo(weapon
: Byte): Boolean;
7011 WEAPON_PISTOL
: Result
:= FAmmo
[A_BULLETS
] >= 1;
7012 WEAPON_SHOTGUN1
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7013 WEAPON_SHOTGUN2
: Result
:= FAmmo
[A_SHELLS
] >= 2;
7014 WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
] >= 10;
7015 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
] >= 1;
7016 WEAPON_PLASMA
: Result
:= FAmmo
[A_CELLS
] >= 10;
7017 WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
] >= 40;
7018 WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7019 else Result
:= True;
7024 if Dist
= -1 then Dist
:= BOT_LONGDIST
;
7026 if Dist
> BOT_LONGDIST
then
7027 begin // Äàëüíèé áîé
7029 if FWeapon
[FDifficult
.WeaponPrior
[a
]] and HaveAmmo(FDifficult
.WeaponPrior
[a
]) then
7031 FSelectedWeapon
:= FDifficult
.WeaponPrior
[a
];
7035 else //if Dist > BOT_UNSAFEDIST then
7036 begin // Áëèæíèé áîé
7038 if FWeapon
[FDifficult
.CloseWeaponPrior
[a
]] and HaveAmmo(FDifficult
.CloseWeaponPrior
[a
]) then
7040 FSelectedWeapon
:= FDifficult
.CloseWeaponPrior
[a
];
7047 if FWeapon[FDifficult.SafeWeaponPrior[a]] and HaveAmmo(FDifficult.SafeWeaponPrior[a]) then
7049 FSelectedWeapon := FDifficult.SafeWeaponPrior[a];
7055 function TBot
.PickItem(ItemType
: Byte; force
: Boolean; var remove
: Boolean): Boolean;
7057 Result
:= inherited PickItem(ItemType
, force
, remove
);
7059 if Result
then SetAIFlag('SELECTWEAPON', '1');
7062 function TBot
.Heal(value
: Word; Soft
: Boolean): Boolean;
7064 Result
:= inherited Heal(value
, Soft
);
7067 function TBot
.Healthy(): Byte;
7069 if FMegaRulez
[MR_INVUL
] >= gTime
then Result
:= 3
7070 else if (FHealth
> 80) or ((FHealth
> 50) and (FArmor
> 20)) then Result
:= 3
7071 else if (FHealth
> 50) then Result
:= 2
7072 else if (FHealth
> 20) then Result
:= 1
7076 function TBot
.TargetOnScreen(TX
, TY
: Integer): Boolean;
7078 Result
:= (Abs(FObj
.X
-TX
) <= Trunc(gPlayerScreenSize
.X
*0.6)) and
7079 (Abs(FObj
.Y
-TY
) <= Trunc(gPlayerScreenSize
.Y
*0.6));
7082 procedure TBot
.OnDamage(Angle
: SmallInt);
7090 if (Angle
= 0) or (Angle
= 180) then
7093 if (g_GetUIDType(FLastSpawnerUID
) = UID_PLAYER
) and
7094 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
) then
7096 pla
:= g_Player_Get(FLastSpawnerUID
);
7097 ok
:= not TargetOnScreen(pla
.FObj
.X
+ PLAYER_RECT
.X
,
7098 pla
.FObj
.Y
+ PLAYER_RECT
.Y
);
7101 if (g_GetUIDType(FLastSpawnerUID
) = UID_MONSTER
) and
7102 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
) then
7104 mon
:= g_Monsters_Get(FLastSpawnerUID
);
7105 ok
:= not TargetOnScreen(mon
.Obj
.X
+ mon
.Obj
.Rect
.X
,
7106 mon
.Obj
.Y
+ mon
.Obj
.Rect
.Y
);
7111 SetAIFlag('ATTACKLEFT', '1')
7113 SetAIFlag('ATTACKRIGHT', '1');
7117 function TBot
.RunDirection(): TDirection
;
7119 if Abs(Vel
.X
) >= 1 then
7121 if Vel
.X
> 0 then Result
:= D_RIGHT
else Result
:= D_LEFT
;
7123 Result
:= FDirection
;
7126 function TBot
.GetRnd(a
: Byte): Boolean;
7128 if a
= 0 then Result
:= False
7129 else if a
= 255 then Result
:= True
7130 else Result
:= Random(256) > 255-a
;
7133 function TBot
.GetInterval(a
: Byte; radius
: SmallInt): SmallInt;
7135 Result
:= Round((255-a
)/255*radius
*(Random(2)-1));
7138 procedure TBot
.SaveState(var Mem
: TBinMemoryWriter
);
7144 inherited SaveState(Mem
);
7146 // Âûáðàííîå îðóæèå:
7147 Mem
.WriteByte(FSelectedWeapon
);
7149 Mem
.WriteWord(FTargetUID
);
7150 // Âðåìÿ ïîòåðè öåëè:
7151 Mem
.WriteDWORD(FLastVisible
);
7152 // Êîëè÷åñòâî ôëàãîâ ÈÈ:
7153 dw
:= Length(FAIFlags
);
7156 for i
:= 0 to Integer(dw
)-1 do
7158 Mem
.WriteString(FAIFlags
[i
].Name
, 20);
7159 Mem
.WriteString(FAIFlags
[i
].Value
, 20);
7161 // Íàñòðîéêè ñëîæíîñòè:
7163 Mem
.WriteMemory(p
, SizeOf(TDifficult
));
7166 procedure TBot
.LoadState(var Mem
: TBinMemoryReader
);
7172 inherited LoadState(Mem
);
7174 // Âûáðàííîå îðóæèå:
7175 Mem
.ReadByte(FSelectedWeapon
);
7177 Mem
.ReadWord(FTargetUID
);
7178 // Âðåìÿ ïîòåðè öåëè:
7179 Mem
.ReadDWORD(FLastVisible
);
7180 // Êîëè÷åñòâî ôëàãîâ ÈÈ:
7182 SetLength(FAIFlags
, dw
);
7184 for i
:= 0 to Integer(dw
)-1 do
7186 Mem
.ReadString(FAIFlags
[i
].Name
);
7187 Mem
.ReadString(FAIFlags
[i
].Value
);
7189 // Íàñòðîéêè ñëîæíîñòè:
7190 Mem
.ReadMemory(p
, dw
);
7191 if dw
<> SizeOf(TDifficult
) then
7193 raise EBinSizeError
.Create('TBot.LoadState: Wrong FDifficult Size');
7195 FDifficult
:= TDifficult(p
^);