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
1275 if gPlayers
[i
] is TPlayer
then
1277 gPlayers
[i
].Update();
1278 gPlayers
[i
].RealizeCurrentWeapon(); // WARNING! DO NOT MOVE THIS INTO `Update()`!
1282 // bot updates weapons in `UpdateCombat()`
1283 TBot(gPlayers
[i
]).Update();
1288 procedure g_Player_DrawAll();
1292 if gPlayers
= nil then Exit
;
1294 for i
:= 0 to High(gPlayers
) do
1295 if gPlayers
[i
] <> nil then
1296 if gPlayers
[i
] is TPlayer
then gPlayers
[i
].Draw()
1297 else TBot(gPlayers
[i
]).Draw();
1300 procedure g_Player_DrawDebug(p
: TPlayer
);
1304 if p
= nil then Exit
;
1305 if (@p
.FObj
) = nil then Exit
;
1307 e_TextureFontGetSize(gStdFont
, fW
, fH
);
1309 e_TextureFontPrint(0, 0 , 'Pos X: ' + IntToStr(p
.FObj
.X
), gStdFont
);
1310 e_TextureFontPrint(0, fH
, 'Pos Y: ' + IntToStr(p
.FObj
.Y
), gStdFont
);
1311 e_TextureFontPrint(0, fH
* 2, 'Vel X: ' + IntToStr(p
.FObj
.Vel
.X
), gStdFont
);
1312 e_TextureFontPrint(0, fH
* 3, 'Vel Y: ' + IntToStr(p
.FObj
.Vel
.Y
), gStdFont
);
1313 e_TextureFontPrint(0, fH
* 4, 'Acc X: ' + IntToStr(p
.FObj
.Accel
.X
), gStdFont
);
1314 e_TextureFontPrint(0, fH
* 5, 'Acc Y: ' + IntToStr(p
.FObj
.Accel
.Y
), gStdFont
);
1317 procedure g_Player_DrawHealth();
1322 if gPlayers
= nil then Exit
;
1323 e_TextureFontGetSize(gStdFont
, fW
, fH
);
1325 for i
:= 0 to High(gPlayers
) do
1326 if gPlayers
[i
] <> nil then
1328 e_TextureFontPrint(gPlayers
[i
].FObj
.X
+ gPlayers
[i
].FObj
.Rect
.X
,
1329 gPlayers
[i
].FObj
.Y
+ gPlayers
[i
].FObj
.Rect
.Y
+ gPlayers
[i
].FObj
.Rect
.Height
- fH
* 2,
1330 IntToStr(gPlayers
[i
].FHealth
), gStdFont
);
1331 e_TextureFontPrint(gPlayers
[i
].FObj
.X
+ gPlayers
[i
].FObj
.Rect
.X
,
1332 gPlayers
[i
].FObj
.Y
+ gPlayers
[i
].FObj
.Rect
.Y
+ gPlayers
[i
].FObj
.Rect
.Height
- fH
,
1333 IntToStr(gPlayers
[i
].FArmor
), gStdFont
);
1337 function g_Player_Get(UID
: Word): TPlayer
;
1343 if gPlayers
= nil then
1346 for a
:= 0 to High(gPlayers
) do
1347 if gPlayers
[a
] <> nil then
1348 if gPlayers
[a
].FUID
= UID
then
1350 Result
:= gPlayers
[a
];
1355 function g_Player_GetCount(): Byte;
1361 if gPlayers
= nil then
1364 for a
:= 0 to High(gPlayers
) do
1365 if gPlayers
[a
] <> nil then
1366 Result
:= Result
+ 1;
1369 function g_Player_GetStats(): TPlayerStatArray
;
1375 if gPlayers
= nil then Exit
;
1377 for a
:= 0 to High(gPlayers
) do
1378 if gPlayers
[a
] <> nil then
1380 SetLength(Result
, Length(Result
)+1);
1381 with Result
[High(Result
)] do
1383 Ping
:= gPlayers
[a
].FPing
;
1384 Loss
:= gPlayers
[a
].FLoss
;
1385 Name
:= gPlayers
[a
].FName
;
1386 Team
:= gPlayers
[a
].FTeam
;
1387 Frags
:= gPlayers
[a
].FFrags
;
1388 Deaths
:= gPlayers
[a
].FDeath
;
1389 Kills
:= gPlayers
[a
].FKills
;
1390 Color
:= gPlayers
[a
].FModel
.Color
;
1391 Lives
:= gPlayers
[a
].FLives
;
1392 Spectator
:= gPlayers
[a
].FSpectator
;
1397 procedure g_Player_RememberAll
;
1401 for i
:= Low(gPlayers
) to High(gPlayers
) do
1402 if (gPlayers
[i
] <> nil) and gPlayers
[i
].Live
then
1403 gPlayers
[i
].RememberState
;
1406 procedure g_Player_ResetAll(Force
, Silent
: Boolean);
1410 gTeamStat
[TEAM_RED
].Goals
:= 0;
1411 gTeamStat
[TEAM_BLUE
].Goals
:= 0;
1413 if gPlayers
<> nil then
1414 for i
:= 0 to High(gPlayers
) do
1415 if gPlayers
[i
] <> nil then
1417 gPlayers
[i
].Reset(Force
);
1419 if gPlayers
[i
] is TPlayer
then
1421 if (not gPlayers
[i
].FSpectator
) or gPlayers
[i
].FWantsInGame
then
1422 gPlayers
[i
].Respawn(Silent
)
1424 gPlayers
[i
].Spectate();
1427 TBot(gPlayers
[i
]).Respawn(Silent
);
1431 procedure g_Player_CreateCorpse(Player
: TPlayer
);
1438 if Player
.FObj
.Y
>= gMapInfo
.Height
+128 then
1443 if (FHealth
>= -50) or (gGibsCount
= 0) then
1445 if (gCorpses
= nil) or (Length(gCorpses
) = 0) then
1449 for find_id
:= 0 to High(gCorpses
) do
1450 if gCorpses
[find_id
] = nil then
1457 find_id
:= Random(Length(gCorpses
));
1459 gCorpses
[find_id
] := TCorpse
.Create(FObj
.X
, FObj
.Y
, FModel
.Name
, FHealth
< -20);
1460 gCorpses
[find_id
].FColor
:= FModel
.Color
;
1461 gCorpses
[find_id
].FObj
.Vel
:= FObj
.Vel
;
1462 gCorpses
[find_id
].FObj
.Accel
:= FObj
.Accel
;
1465 g_Player_CreateGibs(FObj
.X
+ PLAYER_RECT_CX
,
1466 FObj
.Y
+ PLAYER_RECT_CY
,
1467 FModel
.Name
, FModel
.Color
);
1471 procedure g_Player_CreateShell(fX
, fY
, dX
, dY
: Integer; T
: Byte);
1475 if (gShells
= nil) or (Length(gShells
) = 0) then
1478 with gShells
[CurrentShell
] do
1484 if T
= SHELL_BULLET
then
1486 if g_Texture_Get('TEXTURE_SHELL_BULLET', SID
) then
1490 Obj
.Rect
.Width
:= 4;
1491 Obj
.Rect
.Height
:= 2;
1495 if g_Texture_Get('TEXTURE_SHELL_SHELL', SID
) then
1499 Obj
.Rect
.Width
:= 7;
1500 Obj
.Rect
.Height
:= 3;
1506 g_Obj_Push(@Obj
, dX
+ Random(4)-Random(4), dY
-Random(4));
1507 RAngle
:= Random(360);
1508 Timeout
:= gTime
+ SHELL_TIMEOUT
;
1510 if CurrentShell
>= High(gShells
) then
1517 procedure g_Player_CreateGibs(fX
, fY
: Integer; ModelName
: string; fColor
: TRGB
);
1520 GibsArray
: TGibsArray
;
1522 if (gGibs
= nil) or (Length(gGibs
) = 0) then
1524 if not g_PlayerModel_GetGibs(ModelName
, GibsArray
) then
1527 for a
:= 0 to High(GibsArray
) do
1528 with gGibs
[CurrentGib
] do
1531 ID
:= GibsArray
[a
].ID
;
1532 MaskID
:= GibsArray
[a
].MaskID
;
1535 Obj
.Rect
:= GibsArray
[a
].Rect
;
1536 Obj
.X
:= fX
-GibsArray
[a
].Rect
.X
-(GibsArray
[a
].Rect
.Width
div 2);
1537 Obj
.Y
:= fY
-GibsArray
[a
].Rect
.Y
-(GibsArray
[a
].Rect
.Height
div 2);
1538 g_Obj_PushA(@Obj
, 25 + Random(10), Random(361));
1539 RAngle
:= Random(360);
1541 if gBloodCount
> 0 then
1542 g_GFX_Blood(fX
, fY
, 16*gBloodCount
+Random(5*gBloodCount
), -16+Random(33), -16+Random(33),
1543 Random(48), Random(48), 150, 0, 0);
1545 if CurrentGib
>= High(gGibs
) then
1552 procedure g_Player_UpdatePhysicalObjects();
1558 procedure ShellSound_Bounce(X
, Y
: Integer; T
: Byte);
1563 if T
= SHELL_BULLET
then
1564 g_Sound_PlayExAt('SOUND_PLAYER_CASING' + IntToStr(k
), X
, Y
)
1566 g_Sound_PlayExAt('SOUND_PLAYER_SHELL' + IntToStr(k
), X
, Y
);
1571 if gGibs
<> nil then
1572 for i
:= 0 to High(gGibs
) do
1573 if gGibs
[i
].Live
then
1577 mr
:= g_Obj_Move(@Obj
, True, False, True);
1579 if WordBool(mr
and MOVE_FALLOUT
) then
1585 // Îòëåòàåò îò óäàðà î ñòåíó/ïîòîëîê/ïîë:
1586 if WordBool(mr
and MOVE_HITWALL
) then
1587 Obj
.Vel
.X
:= -(vel
.X
div 2);
1588 if WordBool(mr
and (MOVE_HITCEIL
or MOVE_HITLAND
)) then
1589 Obj
.Vel
.Y
:= -(vel
.Y
div 2);
1591 if (Obj
.Vel
.X
>= 0) then
1593 RAngle
:= RAngle
+ Abs(Obj
.Vel
.X
)*6 + Abs(Obj
.Vel
.Y
);
1594 if RAngle
>= 360 then
1595 RAngle
:= RAngle
mod 360;
1596 end else begin // Counter-clockwise
1597 RAngle
:= RAngle
- Abs(Obj
.Vel
.X
)*6 - Abs(Obj
.Vel
.Y
);
1599 RAngle
:= (360 - (Abs(RAngle
) mod 360)) mod 360;
1602 // Ñîïðîòèâëåíèå âîçäóõà äëÿ êóñêà òðóïà:
1603 if gTime
mod (GAME_TICK
*3) = 0 then
1604 Obj
.Vel
.X
:= z_dec(Obj
.Vel
.X
, 1);
1608 if gCorpses
<> nil then
1609 for i
:= 0 to High(gCorpses
) do
1610 if gCorpses
[i
] <> nil then
1611 if gCorpses
[i
].State
= CORPSE_STATE_REMOVEME
then
1617 gCorpses
[i
].Update();
1620 if gShells
<> nil then
1621 for i
:= 0 to High(gShells
) do
1622 if gShells
[i
].Live
then
1626 mr
:= g_Obj_Move(@Obj
, True, False, True);
1628 if WordBool(mr
and MOVE_FALLOUT
) or (gShells
[i
].Timeout
< gTime
) then
1634 // Îòëåòàåò îò óäàðà î ñòåíó/ïîòîëîê/ïîë:
1635 if WordBool(mr
and MOVE_HITWALL
) then
1637 Obj
.Vel
.X
:= -(vel
.X
div 2);
1638 if not WordBool(mr
and MOVE_INWATER
) then
1639 ShellSound_Bounce(Obj
.X
, Obj
.Y
, SType
);
1641 if WordBool(mr
and (MOVE_HITCEIL
or MOVE_HITLAND
)) then
1643 Obj
.Vel
.Y
:= -(vel
.Y
div 2);
1644 if Obj
.Vel
.X
<> 0 then Obj
.Vel
.X
:= Obj
.Vel
.X
div 2;
1645 if (Obj
.Vel
.X
= 0) and (Obj
.Vel
.Y
= 0) then
1647 if RAngle
mod 90 <> 0 then
1648 RAngle
:= (RAngle
div 90) * 90;
1650 else if not WordBool(mr
and MOVE_INWATER
) then
1651 ShellSound_Bounce(Obj
.X
, Obj
.Y
, SType
);
1654 if (Obj
.Vel
.X
>= 0) then
1656 RAngle
:= RAngle
+ Abs(Obj
.Vel
.X
)*8 + Abs(Obj
.Vel
.Y
);
1657 if RAngle
>= 360 then
1658 RAngle
:= RAngle
mod 360;
1659 end else begin // Counter-clockwise
1660 RAngle
:= RAngle
- Abs(Obj
.Vel
.X
)*8 - Abs(Obj
.Vel
.Y
);
1662 RAngle
:= (360 - (Abs(RAngle
) mod 360)) mod 360;
1667 procedure g_Player_DrawCorpses();
1672 if gGibs
<> nil then
1673 for i
:= 0 to High(gGibs
) do
1674 if gGibs
[i
].Live
then
1677 if not g_Obj_Collide(sX
, sY
, sWidth
, sHeight
, @Obj
) then
1680 a
.X
:= Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2);
1681 a
.y
:= Obj
.Rect
.Y
+(Obj
.Rect
.Height
div 2);
1683 e_DrawAdv(ID
, Obj
.X
, Obj
.Y
, 0, True, False, RAngle
, @a
, M_NONE
);
1686 e_DrawAdv(MaskID
, Obj
.X
, Obj
.Y
, 0, True, False, RAngle
, @a
, M_NONE
);
1692 if gCorpses
<> nil then
1693 for i
:= 0 to High(gCorpses
) do
1694 if gCorpses
[i
] <> nil then
1698 procedure g_Player_DrawShells();
1703 if gShells
<> nil then
1704 for i
:= 0 to High(gShells
) do
1705 if gShells
[i
].Live
then
1708 if not g_Obj_Collide(sX
, sY
, sWidth
, sHeight
, @Obj
) then
1714 e_DrawAdv(SpriteID
, Obj
.X
, Obj
.Y
, 0, True, False, RAngle
, @a
, M_NONE
);
1718 procedure g_Player_RemoveAllCorpses();
1724 SetLength(gGibs
, MaxGibs
);
1725 SetLength(gShells
, MaxGibs
);
1729 if gCorpses
<> nil then
1730 for i
:= 0 to High(gCorpses
) do
1734 SetLength(gCorpses
, MaxCorpses
);
1737 procedure g_Player_Corpses_SaveState(var Mem
: TBinMemoryWriter
);
1742 // Ñ÷èòàåì êîëè÷åñòâî ñóùåñòâóþùèõ òðóïîâ:
1744 if gCorpses
<> nil then
1745 for i
:= 0 to High(gCorpses
) do
1746 if gCorpses
[i
] <> nil then
1749 Mem
:= TBinMemoryWriter
.Create((count
+1) * 128);
1751 // Êîëè÷åñòâî òðóïîâ:
1752 Mem
.WriteInt(count
);
1758 for i
:= 0 to High(gCorpses
) do
1759 if gCorpses
[i
] <> nil then
1762 Mem
.WriteString(gCorpses
[i
].FModelName
);
1764 b
:= gCorpses
[i
].Mess
;
1765 Mem
.WriteBoolean(b
);
1766 // Ñîõðàíÿåì äàííûå òðóïà:
1767 gCorpses
[i
].SaveState(Mem
);
1771 procedure g_Player_Corpses_LoadState(var Mem
: TBinMemoryReader
);
1780 g_Player_RemoveAllCorpses();
1782 // Êîëè÷åñòâî òðóïîâ:
1785 if count
> Length(gCorpses
) then
1787 raise EBinSizeError
.Create('g_Player_Corpses_LoadState: Too Many Corpses');
1794 for i
:= 0 to count
-1 do
1797 Mem
.ReadString(str
);
1801 gCorpses
[i
] := TCorpse
.Create(0, 0, str
, b
);
1802 // Çàãðóæàåì äàííûå òðóïà:
1803 gCorpses
[i
].LoadState(Mem
);
1809 procedure TPlayer
.BFGHit();
1811 g_Weapon_BFGHit(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
1812 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2));
1813 if g_Game_IsServer
and g_Game_IsNet
then
1814 MH_SEND_Effect(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
1815 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2),
1819 procedure TPlayer
.ChangeModel(ModelName
: string);
1821 Model
: TPlayerModel
;
1823 Model
:= g_PlayerModel_Get(ModelName
);
1824 if Model
= nil then Exit
;
1830 procedure TPlayer
.SetModel(ModelName
: string);
1834 m
:= g_PlayerModel_Get(ModelName
);
1837 g_SimpleError(Format(_lc
[I_GAME_ERROR_MODEL_FALLBACK
], [ModelName
]));
1838 m
:= g_PlayerModel_Get('doomer');
1841 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], ['doomer']));
1846 if FModel
<> nil then
1851 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
1852 FModel
.Color
:= FColor
1854 FModel
.Color
:= TEAMCOLOR
[FTeam
];
1855 FModel
.SetWeapon(FCurrWeap
);
1856 FModel
.SetFlag(FFlag
);
1857 SetDirection(FDirection
);
1860 procedure TPlayer
.SetColor(Color
: TRGB
);
1863 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
1864 if FModel
<> nil then FModel
.Color
:= Color
;
1867 procedure TPlayer
.SwitchTeam
;
1869 if g_Game_IsClient
then
1871 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then Exit
;
1873 if gGameOn
and FLive
then
1874 Kill(K_SIMPLEKILL
, FUID
, HIT_SELF
);
1876 if FTeam
= TEAM_RED
then
1878 ChangeTeam(TEAM_BLUE
);
1879 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_BLUE
], [FName
]), True);
1880 if g_Game_IsNet
then
1881 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM
, TEAM_BLUE
, FName
);
1885 ChangeTeam(TEAM_RED
);
1886 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_RED
], [FName
]), True);
1887 if g_Game_IsNet
then
1888 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM
, TEAM_RED
, FName
);
1890 FPreferredTeam
:= FTeam
;
1893 procedure TPlayer
.ChangeTeam(Team
: Byte);
1900 TEAM_RED
, TEAM_BLUE
:
1901 FModel
.Color
:= TEAMCOLOR
[Team
];
1903 FModel
.Color
:= FColor
;
1905 if (FTeam
<> OldTeam
) and g_Game_IsNet
and g_Game_IsServer
then
1906 MH_SEND_PlayerStats(FUID
);
1910 procedure TPlayer.CollideItem();
1915 if gItems = nil then Exit;
1916 if not FLive then Exit;
1918 for i := 0 to High(gItems) do
1921 if (ItemType <> ITEM_NONE) and Live then
1922 if g_Obj_Collide(FObj.X+PLAYER_RECT.X, FObj.Y+PLAYER_RECT.Y, PLAYER_RECT.Width,
1923 PLAYER_RECT.Height, @Obj) then
1925 if not PickItem(ItemType, gItems[i].Respawnable, r) then Continue;
1927 if ItemType in [ITEM_SPHERE_BLUE, ITEM_SPHERE_WHITE, ITEM_INVUL] then
1928 g_Sound_PlayExAt('SOUND_ITEM_GETRULEZ', FObj.X, FObj.Y)
1929 else if ItemType in [ITEM_MEDKIT_SMALL, ITEM_MEDKIT_LARGE, ITEM_MEDKIT_BLACK] then
1930 g_Sound_PlayExAt('SOUND_ITEM_GETMED', FObj.X, FObj.Y)
1931 else g_Sound_PlayExAt('SOUND_ITEM_GETITEM', FObj.X, FObj.Y);
1933 // Íàäî óáðàòü ñ êàðòû, åñëè ýòî íå êëþ÷, êîòîðûì íóæíî ïîäåëèòñÿ ñ äðóãèì èãðîêîì:
1934 if r and not ((ItemType in [ITEM_KEY_RED, ITEM_KEY_GREEN, ITEM_KEY_BLUE]) and
1935 (gGameSettings.GameType = GT_SINGLE) and
1936 (g_Player_GetCount() > 1)) then
1937 if not Respawnable then g_Items_Remove(i) else g_Items_Pick(i);
1943 function TPlayer
.CollideLevel(XInc
, YInc
: Integer): Boolean;
1945 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
1946 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_WALL
,
1950 constructor TPlayer
.Create();
1956 FSawSound
:= TPlayableSound
.Create();
1957 FSawSoundIdle
:= TPlayableSound
.Create();
1958 FSawSoundHit
:= TPlayableSound
.Create();
1959 FSawSoundSelect
:= TPlayableSound
.Create();
1960 FJetSoundFly
:= TPlayableSound
.Create();
1961 FJetSoundOn
:= TPlayableSound
.Create();
1962 FJetSoundOff
:= TPlayableSound
.Create();
1964 FSawSound
.SetByName('SOUND_WEAPON_FIRESAW');
1965 FSawSoundIdle
.SetByName('SOUND_WEAPON_IDLESAW');
1966 FSawSoundHit
.SetByName('SOUND_WEAPON_HITSAW');
1967 FSawSoundSelect
.SetByName('SOUND_WEAPON_SELECTSAW');
1968 FJetSoundFly
.SetByName('SOUND_PLAYER_JETFLY');
1969 FJetSoundOn
.SetByName('SOUND_PLAYER_JETON');
1970 FJetSoundOff
.SetByName('SOUND_PLAYER_JETOFF');
1972 FSpectatePlayer
:= -1;
1976 FSavedState
.WaitRecall
:= False;
1979 FActualModelName
:= 'doomer';
1982 FObj
.Rect
:= PLAYER_RECT
;
1984 FBFGFireCounter
:= -1;
1985 FJustTeleported
:= False;
1991 procedure TPlayer
.Damage(value
: Word; SpawnerUID
: Word; vx
, vy
: Integer; t
: Byte);
1995 if (not g_Game_IsClient
) and (not FLive
) then
2000 // Íåóÿçâèìîñòü íå ñïàñàåò îò ëîâóøåê:
2001 if ((t
= HIT_TRAP
) or (t
= HIT_SELF
)) and (not FGodMode
) then
2003 if not g_Game_IsClient
then
2006 if t
= HIT_TRAP
then
2008 // Ëîâóøêà óáèâàåò ñðàçó:
2010 Kill(K_EXTRAHARDKILL
, SpawnerUID
, t
);
2012 if t
= HIT_SELF
then
2016 Kill(K_SIMPLEKILL
, SpawnerUID
, t
);
2019 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
2020 FMegaRulez
[MR_SUIT
] := 0;
2021 FMegaRulez
[MR_INVUL
] := 0;
2022 FMegaRulez
[MR_INVIS
] := 0;
2026 // Íî îò îñòàëüíîãî ñïàñàåò:
2027 if FMegaRulez
[MR_INVUL
] >= gTime
then
2034 // Åñëè åñòü óðîí ñâîèì, èëè ðàíèë ñàì ñåáÿ, èëè òåáÿ ðàíèë ïðîòèâíèê:
2035 if LongBool(gGameSettings
.Options
and GAME_OPTION_TEAMDAMAGE
) or
2036 (SpawnerUID
= FUID
) or
2037 (not SameTeam(FUID
, SpawnerUID
)) then
2039 FLastSpawnerUID
:= SpawnerUID
;
2041 // Êðîâü (ïóçûðüêè, åñëè â âîäå):
2042 if gBloodCount
> 0 then
2044 c
:= Min(value
, 200)*gBloodCount
+ Random(Min(value
, 200) div 2);
2045 if value
div 4 <= c
then
2046 c
:= c
- (value
div 4)
2050 if (t
= HIT_SOME
) and (vx
= 0) and (vy
= 0) then
2054 HIT_TRAP
, HIT_ACID
, HIT_FLAME
, HIT_SELF
: MakeBloodSimple(c
);
2055 HIT_BFG
, HIT_ROCKET
, HIT_SOME
: MakeBloodVector(c
, vx
, vy
);
2058 if t
= HIT_WATER
then
2059 g_GFX_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
2060 FObj
.Y
+PLAYER_RECT
.Y
-4, value
div 2, 8, 4);
2065 Inc(FDamageBuffer
, value
);
2069 FPain
:= FPain
+ value
;
2072 if g_Game_IsServer
and g_Game_IsNet
then
2074 MH_SEND_PlayerDamage(FUID
, t
, SpawnerUID
, value
, vx
, vy
);
2075 MH_SEND_PlayerStats(FUID
);
2076 MH_SEND_PlayerPos(False, FUID
);
2080 function TPlayer
.Heal(value
: Word; Soft
: Boolean): Boolean;
2083 if g_Game_IsClient
then
2088 if Soft
and (FHealth
< PLAYER_HP_SOFT
) then
2090 IncMax(FHealth
, value
, PLAYER_HP_SOFT
);
2093 if (not Soft
) and (FHealth
< PLAYER_HP_LIMIT
) then
2095 IncMax(FHealth
, value
, PLAYER_HP_LIMIT
);
2099 if Result
and g_Game_IsServer
and g_Game_IsNet
then
2100 MH_SEND_PlayerStats(FUID
);
2103 destructor TPlayer
.Destroy();
2105 if (gPlayer1
<> nil) and (gPlayer1
.FUID
= FUID
) then
2107 if (gPlayer2
<> nil) and (gPlayer2
.FUID
= FUID
) then
2111 FSawSoundIdle
.Free();
2112 FSawSoundHit
.Free();
2113 FJetSoundFly
.Free();
2115 FJetSoundOff
.Free();
2121 procedure TPlayer
.DrawBubble();
2123 bubX
, bubY
: Integer;
2126 Rw
, Gw
, Bw
: SmallInt;
2129 bubX
:= FObj
.X
+FObj
.Rect
.X
+ IfThen(FDirection
= D_LEFT
, -4, 18);
2130 bubY
:= FObj
.Y
+FObj
.Rect
.Y
- 18;
2138 1: // simple textual non-bubble
2140 bubX
:= FObj
.X
+FObj
.Rect
.X
- 11;
2141 bubY
:= FObj
.Y
+FObj
.Rect
.Y
- 17;
2142 e_TextureFontPrint(bubX
, bubY
, '[...]', gStdFont
);
2145 2: // advanced pixel-perfect bubble
2147 if FTeam
= TEAM_RED
then
2150 if FTeam
= TEAM_BLUE
then
2153 3: // colored bubble
2155 Rb
:= FModel
.Color
.R
;
2156 Gb
:= FModel
.Color
.G
;
2157 Bb
:= FModel
.Color
.B
;
2158 Rw
:= Min(Rb
* 2 + 64, 255);
2159 Gw
:= Min(Gb
* 2 + 64, 255);
2160 Bw
:= Min(Bb
* 2 + 64, 255);
2161 if (Abs(Rw
- Rb
) < 32)
2162 or (Abs(Gw
- Gb
) < 32)
2163 or (Abs(Bw
- Bb
) < 32) then
2165 Rb
:= Max(Rw
div 2 - 16, 0);
2166 Gb
:= Max(Gw
div 2 - 16, 0);
2167 Bb
:= Max(Bw
div 2 - 16, 0);
2170 4: // custom textured bubble
2172 if g_Texture_Get('TEXTURE_PLAYER_TALKBUBBLE', ID
) then
2173 if FDirection
= D_RIGHT
then
2174 e_Draw(ID
, bubX
- 6, bubY
- 7, 0, True, False)
2176 e_Draw(ID
, bubX
- 6, bubY
- 7, 0, True, False, M_HORIZONTAL
);
2182 e_DrawQuad(bubX
+ 1, bubY
, bubX
+ 18, bubY
+ 13, Rb
, Gb
, Bb
);
2183 e_DrawQuad(bubX
, bubY
+ 1, bubX
+ 19, bubY
+ 12, Rb
, Gb
, Bb
);
2185 e_DrawFillQuad(bubX
+ 1, bubY
+ 1, bubX
+ 18, bubY
+ 12, Rw
, Gw
, Bw
, 0);
2188 Dot
:= IfThen(FDirection
= D_LEFT
, 14, 5);
2189 e_DrawLine(1, bubX
+ Dot
, bubY
+ 14, bubX
+ Dot
, bubY
+ 16, Rb
, Gb
, Bb
);
2190 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
);
2191 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
);
2192 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
);
2193 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
);
2197 e_DrawFillQuad(bubX
+ Dot
, bubY
+ 8, bubX
+ Dot
+ 1, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2198 e_DrawFillQuad(bubX
+ Dot
+ 3, bubY
+ 8, bubX
+ Dot
+ 4, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2199 e_DrawFillQuad(bubX
+ Dot
+ 6, bubY
+ 8, bubX
+ Dot
+ 7, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2202 procedure TPlayer
.Draw();
2210 if (FMegaRulez
[MR_INVUL
] > gTime
) and (gPlayerDrawn
<> Self
) then
2211 if g_Texture_Get('TEXTURE_PLAYER_INVULPENTA', ID
) then
2213 e_GetTextureSize(ID
, @w
, @h
);
2214 if FDirection
= D_LEFT
then
2215 e_Draw(ID
, FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2)-(w
div 2)+4,
2216 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2)-(h
div 2)-7, 0, True, False)
2218 e_Draw(ID
, FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2)-(w
div 2)-2,
2219 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2)-(h
div 2)-7, 0, True, False);
2222 if FMegaRulez
[MR_INVIS
] > gTime
then
2224 if (gPlayerDrawn
<> nil) and ((Self
= gPlayerDrawn
) or
2225 ((FTeam
= gPlayerDrawn
.Team
) and (gGameSettings
.GameMode
<> GM_DM
))) then
2227 if (FMegaRulez
[MR_INVIS
] - gTime
) <= 2100 then
2228 dr
:= not Odd((FMegaRulez
[MR_INVIS
] - gTime
) div 300)
2232 FModel
.Draw(FObj
.X
, FObj
.Y
, 200)
2234 FModel
.Draw(FObj
.X
, FObj
.Y
);
2237 FModel
.Draw(FObj
.X
, FObj
.Y
, 254);
2240 FModel
.Draw(FObj
.X
, FObj
.Y
);
2243 if g_debug_Frames
then
2245 e_DrawQuad(FObj
.X
+FObj
.Rect
.X
,
2247 FObj
.X
+FObj
.Rect
.X
+FObj
.Rect
.Width
-1,
2248 FObj
.Y
+FObj
.Rect
.Y
+FObj
.Rect
.Height
-1,
2252 if (gChatBubble
> 0) and (FKeys
[KEY_CHAT
].Pressed
) and not FGhost
then
2254 // e_DrawPoint(5, 335, 288, 255, 0, 0); // DL, UR, DL, UR
2255 if gAimLine
and Live
and
2256 ((Self
= gPlayer1
) or (Self
= gPlayer2
)) then
2260 procedure TPlayer
.DrawAim();
2262 wx
, wy
, xx
, yy
: Integer;
2266 wx
:= FObj
.X
+ WEAPONPOINT
[FDirection
].X
+ IfThen(FDirection
= D_LEFT
, 7, -7);
2267 wy
:= FObj
.Y
+ WEAPONPOINT
[FDirection
].Y
;
2276 1: begin // Chainsaw
2283 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2284 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2285 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2286 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2291 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2292 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2293 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2294 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2296 4: begin // Double Shotgun
2299 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2300 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2301 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2302 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2304 5: begin // Chaingun
2307 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2308 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2309 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2310 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2312 6: begin // Rocket Launcher
2315 if angle
= ANGLE_RIGHTUP
then Inc(angle
, 2);
2316 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2317 if angle
= ANGLE_LEFTUP
then Dec(angle
, 2);
2318 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2320 7: begin // Plasmagun
2323 if angle
= ANGLE_RIGHTUP
then Inc(angle
);
2324 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 3);
2325 if angle
= ANGLE_LEFTUP
then Dec(angle
);
2326 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 3);
2331 if angle
= ANGLE_RIGHTUP
then Inc(angle
, 1);
2332 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 2);
2333 if angle
= ANGLE_LEFTUP
then Dec(angle
, 1);
2334 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 2);
2336 9: begin // Super Chaingun
2339 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2340 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2341 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2342 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2345 xx
:= Trunc(Cos(-DegToRad(angle
)) * len
) + wx
;
2346 yy
:= Trunc(Sin(-DegToRad(angle
)) * len
) + wy
;
2347 e_DrawLine(sz
, wx
, wy
, xx
, yy
, 255, 0, 0, 96);
2350 procedure TPlayer
.DrawGUI();
2353 X
, Y
, SY
, a
, p
, m
: Integer;
2357 stat
: TPlayerStatArray
;
2359 X
:= gPlayerScreenSize
.X
;
2360 SY
:= gPlayerScreenSize
.Y
;
2363 if gShowGoals
and (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
2365 if gGameSettings
.GameMode
= GM_CTF
then
2369 if gGameSettings
.GameMode
= GM_CTF
then
2371 s
:= 'TEXTURE_PLAYER_REDFLAG';
2372 if gFlags
[FLAG_RED
].State
= FLAG_STATE_CAPTURED
then
2373 s
:= 'TEXTURE_PLAYER_REDFLAG_S';
2374 if gFlags
[FLAG_RED
].State
= FLAG_STATE_DROPPED
then
2375 s
:= 'TEXTURE_PLAYER_REDFLAG_D';
2376 if g_Texture_Get(s
, ID
) then
2377 e_Draw(ID
, X
-16-32, 240-72-4, 0, True, False);
2380 s
:= IntToStr(gTeamStat
[TEAM_RED
].Goals
);
2381 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2382 e_CharFont_PrintEx(gMenuFont
, X
-16-a
-tw
, 240-72-4, s
, TEAMCOLOR
[TEAM_RED
]);
2384 if gGameSettings
.GameMode
= GM_CTF
then
2386 s
:= 'TEXTURE_PLAYER_BLUEFLAG';
2387 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_CAPTURED
then
2388 s
:= 'TEXTURE_PLAYER_BLUEFLAG_S';
2389 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_DROPPED
then
2390 s
:= 'TEXTURE_PLAYER_BLUEFLAG_D';
2391 if g_Texture_Get(s
, ID
) then
2392 e_Draw(ID
, X
-16-32, 240-32-4, 0, True, False);
2395 s
:= IntToStr(gTeamStat
[TEAM_BLUE
].Goals
);
2396 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2397 e_CharFont_PrintEx(gMenuFont
, X
-16-a
-tw
, 240-32-4, s
, TEAMCOLOR
[TEAM_BLUE
]);
2400 if g_Texture_Get('TEXTURE_PLAYER_HUDBG', ID
) then
2401 e_DrawFill(ID
, X
, 0, 1, (gPlayerScreenSize
.Y
div 256)+IfThen(gPlayerScreenSize
.Y
mod 256 > 0, 1, 0),
2404 if g_Texture_Get('TEXTURE_PLAYER_HUD', ID
) then
2405 e_Draw(ID
, X
+2, Y
, 0, True, False);
2407 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
2411 s
:= IntToStr(Frags
);
2412 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2413 e_CharFont_PrintEx(gMenuFont
, X
-16-tw
, Y
, s
, _RGB(255, 0, 0));
2418 stat
:= g_Player_GetStats();
2423 for a
:= 0 to High(stat
) do
2424 if stat
[a
].Name
<> Name
then
2426 if stat
[a
].Frags
> m
then m
:= stat
[a
].Frags
;
2427 if stat
[a
].Frags
> Frags
then p
:= p
+1;
2431 s
:= IntToStr(p
)+' / '+IntToStr(Length(stat
))+' ';
2432 if Frags
>= m
then s
:= s
+'+' else s
:= s
+'-';
2433 s
:= s
+IntToStr(Abs(Frags
-m
));
2435 e_CharFont_GetSize(gMenuSmallFont
, s
, tw
, th
);
2436 e_CharFont_PrintEx(gMenuSmallFont
, X
-16-tw
, Y
+32, s
, _RGB(255, 0, 0));
2439 if gShowLives
and (gGameSettings
.MaxLives
> 0) then
2441 s
:= IntToStr(Lives
);
2442 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2443 e_CharFont_PrintEx(gMenuFont
, X
-16-tw
, SY
-32, s
, _RGB(0, 255, 0));
2447 e_CharFont_GetSize(gMenuSmallFont
, FName
, tw
, th
);
2448 e_CharFont_PrintEx(gMenuSmallFont
, X
+98-(tw
div 2), Y
+8, FName
, _RGB(255, 0, 0));
2450 if R_BERSERK
in FRulez
then
2451 e_Draw(gItemsTexturesID
[ITEM_MEDKIT_BLACK
], X
+37, Y
+45, 0, True, False)
2453 e_Draw(gItemsTexturesID
[ITEM_MEDKIT_LARGE
], X
+37, Y
+45, 0, True, False);
2455 if g_Texture_Get('TEXTURE_PLAYER_ARMORHUD', ID
) then
2456 e_Draw(ID
, X
+36, Y
+77, 0, True, False);
2458 s
:= IntToStr(IfThen(FHealth
> 0, FHealth
, 0));
2459 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2460 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+40, s
, _RGB(255, 0, 0));
2462 s
:= IntToStr(FArmor
);
2463 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2464 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+68, s
, _RGB(255, 0, 0));
2466 s
:= IntToStr(GetAmmoByWeapon(FCurrWeap
));
2472 ID
:= gItemsTexturesID
[ITEM_WEAPON_KASTET
];
2477 ID
:= gItemsTexturesID
[ITEM_WEAPON_SAW
];
2479 WEAPON_PISTOL
: ID
:= gItemsTexturesID
[ITEM_WEAPON_PISTOL
];
2480 WEAPON_CHAINGUN
: ID
:= gItemsTexturesID
[ITEM_WEAPON_CHAINGUN
];
2481 WEAPON_SHOTGUN1
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SHOTGUN1
];
2482 WEAPON_SHOTGUN2
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SHOTGUN2
];
2483 WEAPON_SUPERPULEMET
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SUPERPULEMET
];
2484 WEAPON_ROCKETLAUNCHER
: ID
:= gItemsTexturesID
[ITEM_WEAPON_ROCKETLAUNCHER
];
2485 WEAPON_PLASMA
: ID
:= gItemsTexturesID
[ITEM_WEAPON_PLASMA
];
2486 WEAPON_BFG
: ID
:= gItemsTexturesID
[ITEM_WEAPON_BFG
];
2489 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2490 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+158, s
, _RGB(255, 0, 0));
2491 e_Draw(ID
, X
+20, Y
+160, 0, True, False);
2493 if R_KEY_RED
in FRulez
then
2494 e_Draw(gItemsTexturesID
[ITEM_KEY_RED
], X
+78, Y
+214, 0, True, False);
2496 if R_KEY_GREEN
in FRulez
then
2497 e_Draw(gItemsTexturesID
[ITEM_KEY_GREEN
], X
+95, Y
+214, 0, True, False);
2499 if R_KEY_BLUE
in FRulez
then
2500 e_Draw(gItemsTexturesID
[ITEM_KEY_BLUE
], X
+112, Y
+214, 0, True, False);
2502 if FJetFuel
> 0 then
2504 if g_Texture_Get('TEXTURE_PLAYER_HUDAIR', ID
) then
2505 e_Draw(ID
, X
+2, Y
+116, 0, True, False);
2506 if g_Texture_Get('TEXTURE_PLAYER_HUDJET', ID
) then
2507 e_Draw(ID
, X
+2, Y
+126, 0, True, False);
2508 e_DrawLine(4, X
+16, Y
+122, X
+16+Trunc(168*IfThen(FAir
> 0, FAir
, 0)/AIR_MAX
), Y
+122, 0, 0, 196);
2509 e_DrawLine(4, X
+16, Y
+132, X
+16+Trunc(168*FJetFuel
/JET_MAX
), Y
+132, 208, 0, 0);
2513 if g_Texture_Get('TEXTURE_PLAYER_HUDAIR', ID
) then
2514 e_Draw(ID
, X
+2, Y
+124, 0, True, False);
2515 e_DrawLine(4, X
+16, Y
+130, X
+16+Trunc(168*IfThen(FAir
> 0, FAir
, 0)/AIR_MAX
), Y
+130, 0, 0, 196);
2518 if gShowPing
and g_Game_IsClient
then
2520 s
:= _lc
[I_GAME_PING_HUD
] + IntToStr(NetPeer
.lastRoundTripTime
) + _lc
[I_NET_SLIST_PING_MS
];
2521 e_TextureFontPrint(X
+ 4, Y
+ 242, s
, gStdFont
);
2527 e_TextureFontPrint(X
+ 4, Y
+ 242, _lc
[I_PLAYER_SPECT
], gStdFont
);
2528 e_TextureFontPrint(X
+ 4, Y
+ 258, _lc
[I_PLAYER_SPECT2
], gStdFont
);
2529 e_TextureFontPrint(X
+ 4, Y
+ 274, _lc
[I_PLAYER_SPECT1
], gStdFont
);
2532 e_TextureFontGetSize(gStdFont
, cw
, ch
);
2533 s
:= _lc
[I_PLAYER_SPECT4
];
2534 e_TextureFontPrintEx(gScreenWidth
div 2 - cw
*(Length(s
) div 2),
2535 gScreenHeight
-4-ch
, s
, gStdFont
, 255, 255, 255, 1, True);
2536 e_TextureFontPrint(X
+ 4, Y
+ 290, _lc
[I_PLAYER_SPECT1S
], gStdFont
);
2542 procedure TPlayer
.DrawRulez();
2546 // Ïðè âçÿòèè íåóÿçâèìîñòè ðèñóåòñÿ èíâåðñèîííûé áåëûé ôîí
2547 if FMegaRulez
[MR_INVUL
] >= gTime
then
2549 if (FMegaRulez
[MR_INVUL
]-gTime
) <= 2100 then
2550 dr
:= not Odd((FMegaRulez
[MR_INVUL
]-gTime
) div 300)
2555 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2556 191, 191, 191, 0, B_INVERT
);
2559 // Ïðè âçÿòèè çàùèòíîãî êîñòþìà ðèñóåòñÿ çåëåíîâàòûé ôîí
2560 if FMegaRulez
[MR_SUIT
] >= gTime
then
2562 if (FMegaRulez
[MR_SUIT
]-gTime
) <= 2100 then
2563 dr
:= not Odd((FMegaRulez
[MR_SUIT
]-gTime
) div 300)
2568 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2569 0, 96, 0, 200, B_NONE
);
2572 // Ïðè âçÿòèè áåðñåðêà ðèñóåòñÿ êðàñíîâàòûé ôîí
2573 if (FBerserk
>= 0) and (LongWord(FBerserk
) >= gTime
) and (gFlash
= 2) then
2575 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2576 255, 0, 0, 200, B_NONE
);
2580 procedure TPlayer
.DrawPain();
2584 if FPain
= 0 then Exit
;
2588 if a
< 15 then h
:= 0
2589 else if a
< 35 then h
:= 1
2590 else if a
< 55 then h
:= 2
2591 else if a
< 75 then h
:= 3
2592 else if a
< 95 then h
:= 4
2595 //if a > 255 then a := 255;
2597 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1, 255, 0, 0, 255-h
*50);
2598 //e_DrawFillQuad(0, 0, gPlayerScreenSize.X-1, gPlayerScreenSize.Y-1, 255-min(128, a), 255-a, 255-a, 0, B_FILTER);
2601 procedure TPlayer
.DrawPickup();
2605 if FPickup
= 0 then Exit
;
2609 if a
< 15 then h
:= 1
2610 else if a
< 35 then h
:= 2
2611 else if a
< 55 then h
:= 3
2612 else if a
< 75 then h
:= 4
2615 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1, 150, 200, 150, 255-h
*50);
2618 procedure TPlayer
.Fire();
2620 f
, DidFire
: Boolean;
2621 wx
, wy
, xd
, yd
: Integer;
2624 if g_Game_IsClient
then Exit
;
2625 // FBFGFireCounter - âðåìÿ ïåðåä âûñòðåëîì (äëÿ BFG)
2626 // FReloading - âðåìÿ ïîñëå âûñòðåëà (äëÿ âñåãî)
2634 if FReloading
[FCurrWeap
] <> 0 then Exit
;
2639 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
2640 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
2641 xd
:= wx
+IfThen(FDirection
= D_LEFT
, -30, 30);
2642 yd
:= wy
+firediry();
2647 if R_BERSERK
in FRulez
then
2649 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
2650 obj
.X
:= FObj
.X
+FObj
.Rect
.X
;
2651 obj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
2654 obj
.rect
.Width
:= 39;
2655 obj
.rect
.Height
:= 52;
2656 obj
.Vel
.X
:= (xd
-wx
) div 2;
2657 obj
.Vel
.Y
:= (yd
-wy
) div 2;
2658 obj
.Accel
.X
:= xd
-wx
;
2659 obj
.Accel
.y
:= yd
-wy
;
2661 if g_Weapon_Hit(@obj
, 50, FUID
, HIT_SOME
) <> 0 then
2662 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
2664 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
2668 FPain
:= min(FPain
+ 25, 50);
2669 end else g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
2672 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2677 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
2678 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
2680 FSawSoundSelect
.Stop();
2682 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
2684 else if not FSawSoundHit
.IsPlaying() then
2686 FSawSoundSelect
.Stop();
2687 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
2690 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2696 if FAmmo
[A_BULLETS
] > 0 then
2698 g_Weapon_pistol(wx
, wy
, xd
, yd
, FUID
);
2699 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2700 Dec(FAmmo
[A_BULLETS
]);
2701 FFireAngle
:= FAngle
;
2704 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
2705 GameVelX
, GameVelY
-2, SHELL_BULLET
);
2709 if FAmmo
[A_SHELLS
] > 0 then
2711 g_Weapon_shotgun(wx
, wy
, xd
, yd
, FUID
);
2712 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', wx
, wy
);
2713 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2714 Dec(FAmmo
[A_SHELLS
]);
2715 FFireAngle
:= FAngle
;
2719 FShellType
:= SHELL_SHELL
;
2723 if FAmmo
[A_SHELLS
] >= 2 then
2725 g_Weapon_dshotgun(wx
, wy
, xd
, yd
, FUID
);
2726 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2727 Dec(FAmmo
[A_SHELLS
], 2);
2728 FFireAngle
:= FAngle
;
2732 FShellType
:= SHELL_DBLSHELL
;
2736 if FAmmo
[A_BULLETS
] > 0 then
2738 g_Weapon_mgun(wx
, wy
, xd
, yd
, FUID
);
2739 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', wx
, wy
);
2740 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2741 Dec(FAmmo
[A_BULLETS
]);
2742 FFireAngle
:= FAngle
;
2745 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
2746 GameVelX
, GameVelY
-2, SHELL_BULLET
);
2749 WEAPON_ROCKETLAUNCHER
:
2750 if FAmmo
[A_ROCKETS
] > 0 then
2752 g_Weapon_rocket(wx
, wy
, xd
, yd
, FUID
);
2753 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2754 Dec(FAmmo
[A_ROCKETS
]);
2755 FFireAngle
:= FAngle
;
2761 if FAmmo
[A_CELLS
] > 0 then
2763 g_Weapon_plasma(wx
, wy
, xd
, yd
, FUID
);
2764 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2765 Dec(FAmmo
[A_CELLS
]);
2766 FFireAngle
:= FAngle
;
2772 if (FAmmo
[A_CELLS
] >= 40) and (FBFGFireCounter
= -1) then
2774 FBFGFireCounter
:= 17;
2775 if not FNoReload
then
2776 g_Sound_PlayExAt('SOUND_WEAPON_STARTFIREBFG', FObj
.X
, FObj
.Y
);
2777 Dec(FAmmo
[A_CELLS
], 40);
2781 WEAPON_SUPERPULEMET
:
2782 if FAmmo
[A_SHELLS
] > 0 then
2784 g_Weapon_shotgun(wx
, wy
, xd
, yd
, FUID
);
2785 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', wx
, wy
);
2786 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2787 Dec(FAmmo
[A_SHELLS
]);
2788 FFireAngle
:= FAngle
;
2791 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
2792 GameVelX
, GameVelY
-2, SHELL_SHELL
);
2796 if g_Game_IsNet
then
2800 if FCurrWeap
<> WEAPON_BFG
then
2801 MH_SEND_PlayerFire(FUID
, FCurrWeap
, wx
, wy
, xd
, yd
, LastShotID
)
2803 if not FNoReload
then
2804 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_WEAPON_STARTFIREBFG');
2807 MH_SEND_PlayerStats(FUID
);
2812 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
2813 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
2814 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
2817 function TPlayer
.GetAmmoByWeapon(Weapon
: Byte): Word;
2820 WEAPON_PISTOL
, WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
];
2821 WEAPON_SHOTGUN1
, WEAPON_SHOTGUN2
, WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
];
2822 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
];
2823 WEAPON_PLASMA
, WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
];
2828 function TPlayer
.HeadInLiquid(XInc
, YInc
: Integer): Boolean;
2830 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
+XInc
, FObj
.Y
+PLAYER_HEADRECT
.Y
+YInc
,
2831 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
2832 PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, True);
2835 procedure TPlayer
.JetpackOn
;
2839 FJetSoundOn
.SetPosition(0);
2840 FJetSoundOn
.PlayAt(FObj
.X
, FObj
.Y
);
2844 procedure TPlayer
.JetpackOff
;
2848 FJetSoundOff
.SetPosition(0);
2849 FJetSoundOff
.PlayAt(FObj
.X
, FObj
.Y
);
2852 procedure TPlayer
.Jump();
2854 if gFly
or FJetpack
then
2856 // Ïîëåò (÷èò-êîä èëè äæåòïàê):
2857 if FObj
.Vel
.Y
> -VEL_FLY
then
2858 FObj
.Vel
.Y
:= FObj
.Vel
.Y
- 3;
2861 if FJetFuel
> 0 then
2863 if (FJetFuel
< 1) and g_Game_IsServer
then
2867 if g_Game_IsNet
then
2868 MH_SEND_PlayerStats(FUID
);
2874 // Íå âêëþ÷àòü äæåòïàê â ðåæèìå ïðîõîæäåíèÿ ñêâîçü ñòåíû
2876 FCanJetpack
:= False;
2878 // Ïðûãàåì èëè âñïëûâàåì:
2879 if (CollideLevel(0, 1) or
2880 g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
+36, PLAYER_RECT
.Width
,
2881 PLAYER_RECT
.Height
-33, PANEL_STEP
, False)
2882 ) and (FObj
.Accel
.Y
= 0) then // Íå ïðûãàòü, åñëè åñòü âåðòèêàëüíîå óñêîðåíèå
2884 FObj
.Vel
.Y
:= -VEL_JUMP
;
2885 FCanJetpack
:= False;
2889 if BodyInLiquid(0, 0) then
2890 FObj
.Vel
.Y
:= -VEL_SW
2891 else if (FJetFuel
> 0) and FCanJetpack
and
2892 g_Game_IsServer
and (not g_Obj_CollideLiquid(@FObj
, 0, 0)) then
2896 if g_Game_IsNet
then
2897 MH_SEND_PlayerStats(FUID
);
2902 procedure TPlayer
.Kill(KillType
: Byte; SpawnerUID
: Word; t
: Byte);
2904 a
, i
, k
, ab
, ar
: Byte;
2908 srv
, netsrv
: Boolean;
2913 procedure PushItem(t
: Byte);
2917 id
:= g_Items_Create(FObj
.X
, FObj
.Y
, t
, True, False);
2918 if KillType
= K_EXTRAHARDKILL
then // -7..+7; -8..0
2919 g_Obj_Push(@gItems
[id
].Obj
, (FObj
.Vel
.X
div 2)-7+Random(15),
2920 (FObj
.Vel
.Y
div 2)-Random(9))
2922 if KillType
= K_HARDKILL
then // -5..+5; -5..0
2923 g_Obj_Push(@gItems
[id
].Obj
, (FObj
.Vel
.X
div 2)-5+Random(11),
2924 (FObj
.Vel
.Y
div 2)-Random(6))
2925 else // -3..+3; -3..0
2926 g_Obj_Push(@gItems
[id
].Obj
, (FObj
.Vel
.X
div 2)-3+Random(7),
2927 (FObj
.Vel
.Y
div 2)-Random(4));
2929 if g_Game_IsNet
and g_Game_IsServer
then
2930 MH_SEND_ItemSpawn(True, id
);
2934 DoFrags
:= (gGameSettings
.MaxLives
= 0) or (gGameSettings
.GameMode
= GM_COOP
);
2935 Srv
:= g_Game_IsServer
;
2936 Netsrv
:= g_Game_IsServer
and g_Game_IsNet
;
2937 if Srv
then FDeath
:= FDeath
+ 1;
2942 if not FPhysics
then
2948 if (gGameSettings
.MaxLives
> 0) and Srv
and (gLMSRespawn
= LMS_RESPAWN_NONE
) then
2950 if FLives
> 0 then FLives
:= FLives
- 1;
2951 if FLives
= 0 then FNoRespawn
:= True;
2954 // Íîìåð òèïà ñìåðòè:
2957 K_SIMPLEKILL
: a
:= 1;
2959 K_EXTRAHARDKILL
: a
:= 3;
2964 if not FModel
.PlaySound(MODELSOUND_DIE
, a
, FObj
.X
, FObj
.Y
) then
2966 if FModel
.PlaySound(MODELSOUND_DIE
, i
, FObj
.X
, FObj
.Y
) then
2973 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN1
;
2975 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN2
;
2976 K_EXTRAHARDKILL
, K_FALLKILL
:
2977 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN3
;
2980 // Ïåðåêëþ÷àåì ñîñòîÿíèå:
2984 K_HARDKILL
, K_EXTRAHARDKILL
:
2988 // Ðåàêöèÿ ìîíñòðîâ íà ñìåðòü èãðîêà:
2989 if (KillType
<> K_FALLKILL
) and (Srv
) then
2990 g_Monsters_killedp();
2992 if SpawnerUID
= FUID
then
2994 if Srv
and (DoFrags
or (gGameSettings
.GameMode
= GM_TDM
)) then
2999 g_Console_Add(Format(_lc
[I_PLAYER_KILL_SELF
], [FName
]), True);
3002 if g_GetUIDType(SpawnerUID
) = UID_PLAYER
then
3003 begin // Óáèò äðóãèì èãðîêîì
3004 KP
:= g_Player_Get(SpawnerUID
);
3005 if (KP
<> nil) and Srv
then
3007 if (DoFrags
or (gGameSettings
.GameMode
= GM_TDM
)) then
3008 if SameTeam(FUID
, SpawnerUID
) then
3018 if (gGameSettings
.GameMode
= GM_TDM
) and DoFrags
then
3019 Inc(gTeamStat
[KP
.Team
].Goals
,
3020 IfThen(SameTeam(FUID
, SpawnerUID
), -1, 1));
3022 if netsrv
then MH_SEND_PlayerStats(SpawnerUID
);
3025 plr
:= g_Player_Get(SpawnerUID
);
3033 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_2
],
3037 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_1
],
3041 g_Console_Add(Format(_lc
[I_PLAYER_KILL
],
3046 else if g_GetUIDType(SpawnerUID
) = UID_MONSTER
then
3047 begin // Óáèò ìîíñòðîì
3048 mon
:= g_Monsters_Get(SpawnerUID
);
3052 s
:= g_Monsters_GetKilledBy(mon
.MonsterType
);
3056 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_2
],
3060 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_1
],
3064 g_Console_Add(Format(_lc
[I_PLAYER_KILL
],
3069 else // Îñîáûå òèïû ñìåðòè
3072 HIT_SELF
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_SELF
], [FName
]), True);
3073 HIT_FALL
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_FALL
], [FName
]), True);
3074 HIT_WATER
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_WATER
], [FName
]), True);
3075 HIT_ACID
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_ACID
], [FName
]), True);
3076 HIT_TRAP
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_TRAP
], [FName
]), True);
3077 else g_Console_Add(Format(_lc
[I_PLAYER_DIED
], [FName
]), True);
3083 for a
:= WEAPON_KASTET
to WEAPON_SUPERPULEMET
do
3087 WEAPON_SAW
: i
:= ITEM_WEAPON_SAW
;
3088 WEAPON_SHOTGUN1
: i
:= ITEM_WEAPON_SHOTGUN1
;
3089 WEAPON_SHOTGUN2
: i
:= ITEM_WEAPON_SHOTGUN2
;
3090 WEAPON_CHAINGUN
: i
:= ITEM_WEAPON_CHAINGUN
;
3091 WEAPON_ROCKETLAUNCHER
: i
:= ITEM_WEAPON_ROCKETLAUNCHER
;
3092 WEAPON_PLASMA
: i
:= ITEM_WEAPON_PLASMA
;
3093 WEAPON_BFG
: i
:= ITEM_WEAPON_BFG
;
3094 WEAPON_SUPERPULEMET
: i
:= ITEM_WEAPON_SUPERPULEMET
;
3103 if R_ITEM_BACKPACK
in FRulez
then
3104 PushItem(ITEM_AMMO_BACKPACK
);
3106 // Âûáðîñ ðàêåòíîãî ðàíöà:
3107 if FJetFuel
> 0 then
3108 PushItem(ITEM_JETPACK
);
3111 if not (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
]) then
3113 if R_KEY_RED
in FRulez
then
3114 PushItem(ITEM_KEY_RED
);
3116 if R_KEY_GREEN
in FRulez
then
3117 PushItem(ITEM_KEY_GREEN
);
3119 if R_KEY_BLUE
in FRulez
then
3120 PushItem(ITEM_KEY_BLUE
);
3127 g_Player_CreateCorpse(Self
);
3129 if Srv
and (gGameSettings
.MaxLives
> 0) and FNoRespawn
and
3130 (gLMSRespawn
= LMS_RESPAWN_NONE
) then
3136 for i
:= Low(gPlayers
) to High(gPlayers
) do
3138 if gPlayers
[i
] = nil then continue
;
3139 if (not gPlayers
[i
].FNoRespawn
) and (not gPlayers
[i
].FSpectator
) then
3142 if gPlayers
[i
].FTeam
= TEAM_RED
then Inc(ar
)
3143 else if gPlayers
[i
].FTeam
= TEAM_BLUE
then Inc(ab
);
3148 OldLR
:= gLMSRespawn
;
3149 if (gGameSettings
.GameMode
= GM_COOP
) then
3153 // everyone is dead, restart the map
3154 g_Game_Message(_lc
[I_MESSAGE_LMS_LOSE
], 144);
3156 MH_SEND_GameEvent(NET_EV_LMS_LOSE
);
3157 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3158 gLMSRespawnTime
:= gTime
+ 5000;
3160 else if (a
= 1) then
3162 if (gPlayers
[k
] <> nil) and not (gPlayers
[k
] is TBot
) then
3163 if (gPlayers
[k
] = gPlayer1
) or
3164 (gPlayers
[k
] = gPlayer2
) then
3165 g_Console_Add('*** ' + _lc
[I_MESSAGE_LMS_SURVIVOR
] + ' ***', True)
3166 else if Netsrv
and (gPlayers
[k
].FClientID
>= 0) then
3167 MH_SEND_GameEvent(NET_EV_LMS_SURVIVOR
, 0, 'N', gPlayers
[k
].FClientID
);
3170 else if (gGameSettings
.GameMode
= GM_TDM
) then
3172 if (ab
= 0) and (ar
<> 0) then
3175 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 144);
3177 MH_SEND_GameEvent(NET_EV_TLMS_WIN
, TEAM_RED
);
3178 Inc(gTeamStat
[TEAM_RED
].Goals
);
3179 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3180 gLMSRespawnTime
:= gTime
+ 5000;
3182 else if (ar
= 0) and (ab
<> 0) then
3185 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 144);
3187 MH_SEND_GameEvent(NET_EV_TLMS_WIN
, TEAM_BLUE
);
3188 Inc(gTeamStat
[TEAM_BLUE
].Goals
);
3189 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3190 gLMSRespawnTime
:= gTime
+ 5000;
3192 else if (ar
= 0) and (ab
= 0) then
3195 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
3197 MH_SEND_GameEvent(NET_EV_LMS_DRAW
, 0, FName
);
3198 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3199 gLMSRespawnTime
:= gTime
+ 5000;
3202 else if (gGameSettings
.GameMode
= GM_DM
) then
3206 if gPlayers
[k
] <> nil then
3209 // survivor is the winner
3210 g_Game_Message(Format(_lc
[I_MESSAGE_LMS_WIN
], [AnsiUpperCase(FName
)]), 144);
3212 MH_SEND_GameEvent(NET_EV_LMS_WIN
, 0, FName
);
3215 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3216 gLMSRespawnTime
:= gTime
+ 5000;
3218 else if (a
= 0) then
3220 // everyone is dead, restart the map
3221 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
3223 MH_SEND_GameEvent(NET_EV_LMS_DRAW
, 0, FName
);
3224 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3225 gLMSRespawnTime
:= gTime
+ 5000;
3228 if srv
and (OldLR
= LMS_RESPAWN_NONE
) and (gLMSRespawn
> LMS_RESPAWN_NONE
) then
3230 if NetMode
= NET_SERVER
then
3231 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, (gLMSRespawnTime
- gTime
) div 1000)
3233 g_Console_Add(Format(_lc
[I_MSG_WARMUP_START
], [(gLMSRespawnTime
- gTime
) div 1000]), True);
3239 MH_SEND_PlayerStats(FUID
);
3240 MH_SEND_PlayerDeath(FUID
, KillType
, t
, SpawnerUID
);
3241 if gGameSettings
.GameMode
= GM_TDM
then MH_SEND_GameStats
;
3244 if srv
and FNoRespawn
then Spectate(True);
3245 FWantsInGame
:= True;
3248 function TPlayer
.BodyInLiquid(XInc
, YInc
: Integer): Boolean;
3250 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
, PLAYER_RECT
.Width
,
3251 PLAYER_RECT
.Height
-20, PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, False);
3254 function TPlayer
.BodyInAcid(XInc
, YInc
: Integer): Boolean;
3256 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
, PLAYER_RECT
.Width
,
3257 PLAYER_RECT
.Height
-20, PANEL_ACID1
or PANEL_ACID2
, False);
3260 procedure TPlayer
.MakeBloodSimple(Count
: Word);
3262 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)+8,
3263 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3264 Count
div 2, 3, -1, 16, (PLAYER_RECT
.Height
*2 div 3),
3266 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-8,
3267 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3268 Count
div 2, -3, -1, 16, (PLAYER_RECT
.Height
*2) div 3,
3272 procedure TPlayer
.MakeBloodVector(Count
: Word; VelX
, VelY
: Integer);
3274 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
3275 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3276 Count
, VelX
, VelY
, 16, (PLAYER_RECT
.Height
*2) div 3,
3280 procedure TPlayer
.QueueWeaponSwitch(Weapon
: Byte);
3282 if g_Game_IsClient
then Exit
;
3283 if Weapon
> High(FWeapon
) then Exit
;
3284 FNextWeap
:= FNextWeap
or (1 shl Weapon
);
3287 procedure TPlayer
.resetWeaponQueue ();
3290 FNextWeapDelay
:= 0;
3293 function TPlayer
.hasAmmoForWeapon (weapon
: Byte): Boolean;
3297 WEAPON_KASTET
, WEAPON_SAW
: result
:= true;
3298 WEAPON_SHOTGUN1
, WEAPON_SHOTGUN2
: result
:= (FAmmo
[A_SHELLS
] > 0);
3299 WEAPON_PISTOL
, WEAPON_CHAINGUN
, WEAPON_SUPERPULEMET
: result
:= (FAmmo
[A_BULLETS
] > 0);
3300 WEAPON_ROCKETLAUNCHER
: result
:= (FAmmo
[A_ROCKETS
] > 0);
3301 WEAPON_PLASMA
, WEAPON_BFG
: result
:= (FAmmo
[A_CELLS
] > 0);
3302 else result
:= (weapon
< length(FWeapon
));
3306 // return 255 for "no switch"
3307 function TPlayer
.getNextWeaponIndex (): Byte;
3310 wantThisWeapon
: array[0..64] of Boolean;
3311 wwc
: Integer = 0; //HACK!
3313 result
:= 255; // default result: "no switch"
3314 for i
:= 0 to High(wantThisWeapon
) do wantThisWeapon
[i
] := false;
3315 for i
:= 0 to High(FWeapon
) do if (FNextWeap
and (1 shl i
)) <> 0 then begin wantThisWeapon
[i
] := true; Inc(wwc
); end;
3316 // exclude currently selected weapon from the set
3317 wantThisWeapon
[FCurrWeap
] := false;
3318 // slow down alterations a little
3321 // more than one weapon requested, assume "alteration" and check alteration delay
3322 if FNextWeapDelay
> 0 then begin FNextWeap
:= 0; exit
; end; // yeah
3324 // do not reset weapon queue, it will be done in `RealizeCurrentWeapon()`
3325 if wwc
< 1 then begin resetWeaponQueue(); exit
; end;
3326 //e_WriteLog(Format('wwc=%d', [wwc]), MSG_WARNING);
3327 // try weapons in descending order
3328 for i
:= High(FWeapon
) downto 0 do
3330 if wantThisWeapon
[i
] and FWeapon
[i
] and ((wwc
= 1) or hasAmmoForWeapon(i
)) then
3337 // no suitable weapon found, so reset the queue, to avoid accidental "queuing" of weapon w/o ammo
3341 procedure TPlayer
.RealizeCurrentWeapon();
3345 nw
:= getNextWeaponIndex();
3346 if FNextWeapDelay
> 0 then Dec(FNextWeapDelay
); // "alteration delay"
3347 if nw
= 255 then exit
; // don't reset anything here
3348 if nw
> High(FWeapon
) then begin resetWeaponQueue(); exit
; end; // don't forget to reset queue here!
3350 if FBFGFireCounter
<> -1 then exit
;
3351 if FTime
[T_SWITCH
] > gTime
then exit
;
3353 for i
:= WEAPON_KASTET
to WEAPON_SUPERPULEMET
do if FReloading
[i
] > 0 then exit
;
3358 FTime
[T_SWITCH
] := gTime
+156;
3359 if FCurrWeap
= WEAPON_SAW
then FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3360 FModel
.SetWeapon(FCurrWeap
);
3361 if g_Game_IsNet
then MH_SEND_PlayerStats(FUID
);
3363 // reset weapon queue; `getNextWeaponIndex()` guarantees to not select a weapon player don't have
3365 FNextWeapDelay
:= 10; // anyway, 'cause why not
3368 procedure TPlayer
.cycleWeapon (dir
: Integer);
3372 if dir
< 0 then dir
:= -1 else if dir
> 0 then dir
:= 1 else exit
;
3374 for i
:= 0 to High(FWeapon
) do
3376 cwi
:= (cwi
+length(FWeapon
)+dir
) mod length(FWeapon
);
3377 if FWeapon
[cwi
] then
3379 QueueWeaponSwitch(Byte(cwi
));
3385 procedure TPlayer
.NextWeapon();
3387 if g_Game_IsClient
then Exit
;
3391 procedure TPlayer
.PrevWeapon();
3393 if g_Game_IsClient
then Exit
;
3397 procedure TPlayer
.SetWeapon(W
: Byte);
3399 if FCurrWeap
<> W
then
3400 if W
= WEAPON_SAW
then
3401 FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3404 FModel
.SetWeapon(CurrWeap
);
3408 function TPlayer
.PickItem(ItemType
: Byte; respawn
: Boolean; var remove
: Boolean): Boolean;
3413 if g_Game_IsClient
then Exit
;
3415 // a = true - ìåñòî ñïàâíà ïðåäìåòà:
3416 a
:= LongBool(gGameSettings
.Options
and GAME_OPTION_WEAPONSTAY
) and respawn
;
3421 if FHealth
< PLAYER_HP_SOFT
then
3423 IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
3426 if gFlash
= 2 then Inc(FPickup
, 5);
3430 if FHealth
< PLAYER_HP_SOFT
then
3432 IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
3435 if gFlash
= 2 then Inc(FPickup
, 5);
3439 if FArmor
< PLAYER_AP_SOFT
then
3441 FArmor
:= PLAYER_AP_SOFT
;
3444 if gFlash
= 2 then Inc(FPickup
, 5);
3448 if FArmor
< PLAYER_AP_LIMIT
then
3450 FArmor
:= PLAYER_AP_LIMIT
;
3453 if gFlash
= 2 then Inc(FPickup
, 5);
3457 if FHealth
< PLAYER_HP_LIMIT
then
3459 IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
3462 if gFlash
= 2 then Inc(FPickup
, 5);
3466 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) then
3468 if FHealth
< PLAYER_HP_LIMIT
then
3469 FHealth
:= PLAYER_HP_LIMIT
;
3470 if FArmor
< PLAYER_AP_LIMIT
then
3471 FArmor
:= PLAYER_AP_LIMIT
;
3474 if gFlash
= 2 then Inc(FPickup
, 5);
3478 if (not FWeapon
[WEAPON_SAW
]) or ((not respawn
) and (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
])) then
3480 FWeapon
[WEAPON_SAW
] := True;
3482 if gFlash
= 2 then Inc(FPickup
, 5);
3483 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3486 ITEM_WEAPON_SHOTGUN1
:
3487 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN1
] then
3489 // Íóæíî, ÷òîáû íå âçÿòü âñå ïóëè ñðàçó:
3490 if a
and FWeapon
[WEAPON_SHOTGUN1
] then Exit
;
3492 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3493 FWeapon
[WEAPON_SHOTGUN1
] := True;
3495 if gFlash
= 2 then Inc(FPickup
, 5);
3496 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3499 ITEM_WEAPON_SHOTGUN2
:
3500 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN2
] then
3502 if a
and FWeapon
[WEAPON_SHOTGUN2
] then Exit
;
3504 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3505 FWeapon
[WEAPON_SHOTGUN2
] := True;
3507 if gFlash
= 2 then Inc(FPickup
, 5);
3508 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3511 ITEM_WEAPON_CHAINGUN
:
3512 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or not FWeapon
[WEAPON_CHAINGUN
] then
3514 if a
and FWeapon
[WEAPON_CHAINGUN
] then Exit
;
3516 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
3517 FWeapon
[WEAPON_CHAINGUN
] := True;
3519 if gFlash
= 2 then Inc(FPickup
, 5);
3520 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3523 ITEM_WEAPON_ROCKETLAUNCHER
:
3524 if (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or not FWeapon
[WEAPON_ROCKETLAUNCHER
] then
3526 if a
and FWeapon
[WEAPON_ROCKETLAUNCHER
] then Exit
;
3528 IncMax(FAmmo
[A_ROCKETS
], 2, FMaxAmmo
[A_ROCKETS
]);
3529 FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
3531 if gFlash
= 2 then Inc(FPickup
, 5);
3532 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3536 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_PLASMA
] then
3538 if a
and FWeapon
[WEAPON_PLASMA
] then Exit
;
3540 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3541 FWeapon
[WEAPON_PLASMA
] := True;
3543 if gFlash
= 2 then Inc(FPickup
, 5);
3544 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3548 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_BFG
] then
3550 if a
and FWeapon
[WEAPON_BFG
] then Exit
;
3552 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3553 FWeapon
[WEAPON_BFG
] := True;
3555 if gFlash
= 2 then Inc(FPickup
, 5);
3556 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3559 ITEM_WEAPON_SUPERPULEMET
:
3560 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SUPERPULEMET
] then
3562 if a
and FWeapon
[WEAPON_SUPERPULEMET
] then Exit
;
3564 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3565 FWeapon
[WEAPON_SUPERPULEMET
] := True;
3567 if gFlash
= 2 then Inc(FPickup
, 5);
3568 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3572 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
3574 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
3577 if gFlash
= 2 then Inc(FPickup
, 5);
3580 ITEM_AMMO_BULLETS_BOX
:
3581 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
3583 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
3586 if gFlash
= 2 then Inc(FPickup
, 5);
3590 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
3592 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3595 if gFlash
= 2 then Inc(FPickup
, 5);
3598 ITEM_AMMO_SHELLS_BOX
:
3599 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
3601 IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
3604 if gFlash
= 2 then Inc(FPickup
, 5);
3608 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
3610 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
3613 if gFlash
= 2 then Inc(FPickup
, 5);
3616 ITEM_AMMO_ROCKET_BOX
:
3617 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
3619 IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
3622 if gFlash
= 2 then Inc(FPickup
, 5);
3626 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
3628 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3631 if gFlash
= 2 then Inc(FPickup
, 5);
3635 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
3637 IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
3640 if gFlash
= 2 then Inc(FPickup
, 5);
3644 if not(R_ITEM_BACKPACK
in FRulez
) or
3645 (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
3646 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
3647 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
3648 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) then
3650 FMaxAmmo
[A_BULLETS
] := 400;
3651 FMaxAmmo
[A_SHELLS
] := 100;
3652 FMaxAmmo
[A_ROCKETS
] := 100;
3653 FMaxAmmo
[A_CELLS
] := 600;
3655 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
3656 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
3657 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
3658 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3659 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
3660 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
3661 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
3662 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3664 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
3667 if gFlash
= 2 then Inc(FPickup
, 5);
3671 if not(R_KEY_RED
in FRulez
) then
3673 Include(FRulez
, R_KEY_RED
);
3675 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
3676 if gFlash
= 2 then Inc(FPickup
, 5);
3677 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
3681 if not(R_KEY_GREEN
in FRulez
) then
3683 Include(FRulez
, R_KEY_GREEN
);
3685 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
3686 if gFlash
= 2 then Inc(FPickup
, 5);
3687 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
3691 if not(R_KEY_BLUE
in FRulez
) then
3693 Include(FRulez
, R_KEY_BLUE
);
3695 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
3696 if gFlash
= 2 then Inc(FPickup
, 5);
3697 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
3701 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
3703 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
3706 if gFlash
= 2 then Inc(FPickup
, 5);
3710 if FAir
< AIR_MAX
then
3715 if gFlash
= 2 then Inc(FPickup
, 5);
3720 if not (R_BERSERK
in FRulez
) then
3722 Include(FRulez
, R_BERSERK
);
3723 if FBFGFireCounter
= -1 then
3725 FCurrWeap
:= WEAPON_KASTET
;
3727 FModel
.SetWeapon(WEAPON_KASTET
);
3731 if gFlash
= 2 then Inc(FPickup
, 5);
3732 FBerserk
:= gTime
+30000;
3736 if FHealth
< PLAYER_HP_SOFT
then
3738 FHealth
:= PLAYER_HP_SOFT
;
3739 FBerserk
:= gTime
+30000;
3746 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
3748 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
3751 if gFlash
= 2 then Inc(FPickup
, 5);
3755 if FHealth
< PLAYER_HP_LIMIT
then
3757 IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
3760 if gFlash
= 2 then Inc(FPickup
, 5);
3764 if FArmor
< PLAYER_AP_LIMIT
then
3766 IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
3769 if gFlash
= 2 then Inc(FPickup
, 5);
3773 if FJetFuel
< JET_MAX
then
3775 FJetFuel
:= JET_MAX
;
3778 if gFlash
= 2 then Inc(FPickup
, 5);
3782 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
3784 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
3787 if gFlash
= 2 then Inc(FPickup
, 5);
3792 procedure TPlayer
.Touch();
3796 //FModel.PlaySound(MODELSOUND_PAIN, 1, FObj.X, FObj.Y);
3799 // Áðîñèòü ôëàã òîâàðèùó:
3800 if gGameSettings
.GameMode
= GM_CTF
then
3805 procedure TPlayer
.Push(vx
, vy
: Integer);
3807 if (not FPhysics
) and FGhost
then
3809 FObj
.Accel
.X
:= FObj
.Accel
.X
+ vx
;
3810 FObj
.Accel
.Y
:= FObj
.Accel
.Y
+ vy
;
3811 if g_Game_IsNet
and g_Game_IsServer
then
3812 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
3815 procedure TPlayer
.Reset(Force
: Boolean);
3821 FTime
[T_RESPAWN
] := 0;
3822 FTime
[T_FLAGCAP
] := 0;
3835 FSpectator
:= False;
3838 FSpectatePlayer
:= -1;
3839 FNoRespawn
:= False;
3841 FLives
:= gGameSettings
.MaxLives
;
3846 procedure TPlayer
.SoftReset();
3852 FBFGFireCounter
:= -1;
3860 SetAction(A_STAND
, True);
3863 function TPlayer
.GetRespawnPoint(): Byte;
3868 // Íà áóäóùåå: FSpawn - èãðîê óæå èãðàë è ïåðåðîæäàåòñÿ
3870 // Îäèíî÷íàÿ èãðà/êîîïåðàòèâ
3871 if gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
] then
3873 if (Self
= gPlayer1
) or (Self
= gPlayer2
) then
3875 // Òî÷êà ïîÿâëåíèÿ ñâîåãî èãðîêà
3876 if Self
= gPlayer1
then
3877 c
:= RESPAWNPOINT_PLAYER1
3879 c
:= RESPAWNPOINT_PLAYER2
;
3880 if g_Map_GetPointCount(c
) > 0 then
3886 // Òî÷êà ïîÿâëåíèÿ äðóãîãî èãðîêà
3887 if Self
= gPlayer1
then
3888 c
:= RESPAWNPOINT_PLAYER2
3890 c
:= RESPAWNPOINT_PLAYER1
;
3891 if g_Map_GetPointCount(c
) > 0 then
3898 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà (áîòà)
3899 if Random(2) = 0 then
3900 c
:= RESPAWNPOINT_PLAYER1
3902 c
:= RESPAWNPOINT_PLAYER2
;
3903 if g_Map_GetPointCount(c
) > 0 then
3910 // Òî÷êà ëþáîé èç êîìàíä
3911 if Random(2) = 0 then
3912 c
:= RESPAWNPOINT_RED
3914 c
:= RESPAWNPOINT_BLUE
;
3915 if g_Map_GetPointCount(c
) > 0 then
3922 c
:= RESPAWNPOINT_DM
;
3923 if g_Map_GetPointCount(c
) > 0 then
3931 if gGameSettings
.GameMode
= GM_DM
then
3934 c
:= RESPAWNPOINT_DM
;
3935 if g_Map_GetPointCount(c
) > 0 then
3941 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà
3942 if Random(2) = 0 then
3943 c
:= RESPAWNPOINT_PLAYER1
3945 c
:= RESPAWNPOINT_PLAYER2
;
3946 if g_Map_GetPointCount(c
) > 0 then
3952 // Òî÷êà ëþáîé èç êîìàíä
3953 if Random(2) = 0 then
3954 c
:= RESPAWNPOINT_RED
3956 c
:= RESPAWNPOINT_BLUE
;
3957 if g_Map_GetPointCount(c
) > 0 then
3965 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
3967 // Òî÷êà ñâîåé êîìàíäû
3968 c
:= RESPAWNPOINT_DM
;
3969 if FTeam
= TEAM_RED
then
3970 c
:= RESPAWNPOINT_RED
;
3971 if FTeam
= TEAM_BLUE
then
3972 c
:= RESPAWNPOINT_BLUE
;
3973 if g_Map_GetPointCount(c
) > 0 then
3980 c
:= RESPAWNPOINT_DM
;
3981 if g_Map_GetPointCount(c
) > 0 then
3987 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà
3988 if Random(2) = 0 then
3989 c
:= RESPAWNPOINT_PLAYER1
3991 c
:= RESPAWNPOINT_PLAYER2
;
3992 if g_Map_GetPointCount(c
) > 0 then
3998 // Òî÷êà äðóãîé êîìàíäû
3999 c
:= RESPAWNPOINT_DM
;
4000 if FTeam
= TEAM_RED
then
4001 c
:= RESPAWNPOINT_BLUE
;
4002 if FTeam
= TEAM_BLUE
then
4003 c
:= RESPAWNPOINT_RED
;
4004 if g_Map_GetPointCount(c
) > 0 then
4012 procedure TPlayer
.Respawn(Silent
: Boolean; Force
: Boolean = False);
4014 RespawnPoint
: TRespawnPoint
;
4019 if not g_Game_IsServer
then
4023 FWantsInGame
:= True;
4024 FJustTeleported
:= True;
4027 FTime
[T_RESPAWN
] := 0;
4031 // if server changes MaxLives we gotta be ready
4032 if gGameSettings
.MaxLives
= 0 then FNoRespawn
:= False;
4034 // Åùå íåëüçÿ âîçðîäèòüñÿ:
4035 if FTime
[T_RESPAWN
] > gTime
then
4038 // Ïðîñðàë âñå æèçíè:
4041 if not FSpectator
then Spectate(True);
4042 FWantsInGame
:= True;
4046 if (gGameSettings
.GameType
<> GT_SINGLE
) and (gGameSettings
.GameMode
<> GM_COOP
) then
4047 begin // "Ñâîÿ èãðà"
4048 // Áåðñåðê íå ñîõðàíÿåòñÿ ìåæäó óðîâíÿìè:
4049 FRulez
:= FRulez
-[R_BERSERK
];
4051 else // "Îäèíî÷íàÿ èãðà"/"Êîîï"
4053 // Áåðñåðê è êëþ÷è íå ñîõðàíÿþòñÿ ìåæäó óðîâíÿìè:
4054 FRulez
:= FRulez
-[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
, R_BERSERK
];
4057 // Ïîëó÷àåì òî÷êó ñïàóíà èãðîêà:
4058 c
:= GetRespawnPoint();
4063 // Âîñêðåøåíèå áåç îðóæèÿ:
4066 FHealth
:= PLAYER_HP_SOFT
;
4072 for a
:= WEAPON_KASTET
to WEAPON_SUPERPULEMET
do
4074 FWeapon
[a
] := False;
4078 FWeapon
[WEAPON_PISTOL
] := True;
4079 FWeapon
[WEAPON_KASTET
] := True;
4080 FCurrWeap
:= WEAPON_PISTOL
;
4083 FModel
.SetWeapon(FCurrWeap
);
4085 for b
:= A_BULLETS
to A_CELLS
do
4088 FAmmo
[A_BULLETS
] := 50;
4090 FMaxAmmo
[A_BULLETS
] := 200;
4091 FMaxAmmo
[A_SHELLS
] := 50;
4092 FMaxAmmo
[A_ROCKETS
] := 50;
4093 FMaxAmmo
[A_CELLS
] := 300;
4095 if gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
] then
4096 FRulez
:= [R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
]
4101 // Ïîëó÷àåì êîîðäèíàòû òî÷êè âîçðîæäåíèÿ:
4102 if not g_Map_GetPoint(c
, RespawnPoint
) then
4104 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
4108 // Óñòàíîâêà êîîðäèíàò è ñáðîñ âñåõ ïàðàìåòðîâ:
4109 FObj
.X
:= RespawnPoint
.X
-PLAYER_RECT
.X
;
4110 FObj
.Y
:= RespawnPoint
.Y
-PLAYER_RECT
.Y
;
4116 FDirection
:= RespawnPoint
.Direction
;
4117 if FDirection
= D_LEFT
then
4123 FBFGFireCounter
:= -1;
4128 SetAction(A_STAND
, True);
4129 FModel
.Direction
:= FDirection
;
4131 for a
:= Low(FTime
) to High(FTime
) do
4134 for a
:= Low(FMegaRulez
) to High(FMegaRulez
) do
4139 FCanJetpack
:= False;
4141 // Àíèìàöèÿ âîçðîæäåíèÿ:
4142 if (not gLoadGameMode
) and (not Silent
) then
4143 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
4145 Anim
:= TAnimation
.Create(ID
, False, 3);
4146 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4147 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4151 FSpectator
:= False;
4154 FSpectatePlayer
:= -1;
4157 if g_Game_IsNet
then
4159 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
4160 MH_SEND_PlayerStats(FUID
, NET_EVERYONE
);
4162 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4163 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32,
4168 procedure TPlayer
.Spectate(NoMove
: Boolean = False);
4171 Kill(K_EXTRAHARDKILL
, FUID
, HIT_SOME
)
4172 else if (not NoMove
) then
4174 GameX
:= gMapInfo
.Width
div 2;
4175 GameY
:= gMapInfo
.Height
div 2;
4184 FWantsInGame
:= False;
4189 if Self
= gPlayer1
then
4194 if Self
= gPlayer2
then
4201 if g_Game_IsNet
then
4202 MH_SEND_PlayerStats(FUID
);
4205 procedure TPlayer
.SwitchNoClip
;
4209 FGhost
:= not FGhost
;
4210 FPhysics
:= not FGhost
;
4222 procedure TPlayer
.Run(Direction
: TDirection
);
4226 if MAX_RUNVEL
> 8 then
4230 if Direction
= D_LEFT
then
4232 if FObj
.Vel
.X
> -MAX_RUNVEL
then
4233 FObj
.Vel
.X
:= FObj
.Vel
.X
- (MAX_RUNVEL
shr 3);
4236 if FObj
.Vel
.X
< MAX_RUNVEL
then
4237 FObj
.Vel
.X
:= FObj
.Vel
.X
+ (MAX_RUNVEL
shr 3);
4239 // Âîçìîæíî, ïèíàåì êóñêè:
4240 if (FObj
.Vel
.X
<> 0) and (gGibs
<> nil) then
4242 b
:= Abs(FObj
.Vel
.X
);
4243 if b
> 1 then b
:= b
* (Random(8 div b
) + 1);
4244 for a
:= 0 to High(gGibs
) do
4245 if gGibs
[a
].Live
and
4246 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
+FObj
.Rect
.Height
-4,
4247 FObj
.Rect
.Width
, 8, @gGibs
[a
].Obj
) and (Random(3) = 0) then
4249 if FObj
.Vel
.X
< 0 then
4250 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)+120) // íàëåâî
4252 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)); // íàïðàâî
4258 procedure TPlayer
.SeeDown();
4260 SetAction(A_SEEDOWN
);
4262 if FDirection
= D_LEFT
then FAngle
:= ANGLE_LEFTDOWN
else FAngle
:= ANGLE_RIGHTDOWN
;
4264 if FIncCam
> -120 then DecMin(FIncCam
, 5, -120);
4267 procedure TPlayer
.SeeUp();
4271 if FDirection
= D_LEFT
then FAngle
:= ANGLE_LEFTUP
else FAngle
:= ANGLE_RIGHTUP
;
4273 if FIncCam
< 120 then IncMax(FIncCam
, 5, 120);
4276 procedure TPlayer
.SetAction(Action
: Byte; Force
: Boolean = False);
4284 A_ATTACK
: Prior
:= 2;
4285 A_SEEUP
: Prior
:= 1;
4286 A_SEEDOWN
: Prior
:= 1;
4287 A_ATTACKUP
: Prior
:= 2;
4288 A_ATTACKDOWN
: Prior
:= 2;
4293 if (Prior
> FActionPrior
) or Force
then
4294 if not ((Prior
= 2) and (FCurrWeap
= WEAPON_SAW
)) then
4296 FActionPrior
:= Prior
;
4297 FActionAnim
:= Action
;
4298 FActionForce
:= Force
;
4299 FActionChanged
:= True;
4302 if Action
in [A_ATTACK
, A_ATTACKUP
, A_ATTACKDOWN
] then FModel
.SetFire(True);
4305 function TPlayer
.StayOnStep(XInc
, YInc
: Integer): Boolean;
4307 Result
:= not g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
-1,
4308 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False)
4309 and g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
,
4310 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False);
4313 function TPlayer
.TeleportTo(X
, Y
: Integer; silent
: Boolean; dir
: Byte): Boolean;
4320 if g_CollideLevel(X
, Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
) then
4322 g_Sound_PlayExAt('SOUND_GAME_NOTELEPORT', FObj
.X
, FObj
.Y
);
4323 if g_Game_IsServer
and g_Game_IsNet
then
4324 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_GAME_NOTELEPORT');
4328 FJustTeleported
:= True;
4333 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
4335 Anim
:= TAnimation
.Create(ID
, False, 3);
4338 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', FObj
.X
, FObj
.Y
);
4339 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4340 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4341 if g_Game_IsServer
and g_Game_IsNet
then
4342 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4343 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 1,
4347 FObj
.X
:= X
-PLAYER_RECT
.X
;
4348 FObj
.Y
:= Y
-PLAYER_RECT
.Y
;
4349 if FLive
and FGhost
then
4355 if not g_Game_IsNet
then
4359 SetDirection(D_LEFT
);
4365 SetDirection(D_RIGHT
);
4371 if FDirection
= D_RIGHT
then
4373 SetDirection(D_LEFT
);
4378 SetDirection(D_RIGHT
);
4384 if not silent
and (Anim
<> nil) then
4386 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4387 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4390 if g_Game_IsServer
and g_Game_IsNet
then
4391 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4392 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 0,
4399 function nonz(a
: Single): Single;
4407 procedure TPlayer
.Update();
4410 i
, ii
, wx
, wy
, xd
, yd
, k
: Integer;
4411 blockmon
, headwater
, dospawn
: Boolean;
4416 NetServer
:= g_Game_IsNet
and g_Game_IsServer
;
4417 AnyServer
:= g_Game_IsServer
;
4419 if g_Game_IsClient
and (NetInterpLevel
> 0) then
4420 DoLerp(NetInterpLevel
+ 1)
4426 if FClientID
>= 0 then
4428 FPing
:= NetClients
[FClientID
].Peer
^.lastRoundTripTime
;
4429 if NetClients
[FClientID
].Peer
^.packetsSent
> 0 then
4430 FLoss
:= Round(100*NetClients
[FClientID
].Peer
^.packetsLost
/NetClients
[FClientID
].Peer
^.packetsSent
)
4439 if FLive
and (gFly
or FJetpack
) then
4442 if FDirection
= D_LEFT
then
4447 if FLive
and (not FGhost
) then
4449 if FKeys
[KEY_UP
].Pressed
then
4451 if FKeys
[KEY_DOWN
].Pressed
then
4455 if (not (FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_DOWN
].Pressed
)) and
4458 i
:= g_basic
.Sign(FIncCam
);
4459 FIncCam
:= Abs(FIncCam
);
4460 DecMin(FIncCam
, 5, 0);
4461 FIncCam
:= FIncCam
*i
;
4464 if gTime
mod (GAME_TICK
*2) <> 0 then
4466 if (FObj
.Vel
.X
= 0) and FLive
then
4468 if FKeys
[KEY_LEFT
].Pressed
then
4470 if FKeys
[KEY_RIGHT
].Pressed
then
4475 g_Obj_Move(@FObj
, True, True, True);
4480 FActionChanged
:= False;
4484 // Let alive player do some actions
4485 if FKeys
[KEY_LEFT
].Pressed
then Run(D_LEFT
);
4486 if FKeys
[KEY_RIGHT
].Pressed
then Run(D_RIGHT
);
4487 if FKeys
[KEY_NEXTWEAPON
].Pressed
and AnyServer
then NextWeapon();
4488 if FKeys
[KEY_PREVWEAPON
].Pressed
and AnyServer
then PrevWeapon();
4489 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then Fire();
4490 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Use();
4491 if FKeys
[KEY_JUMP
].Pressed
then Jump()
4494 if AnyServer
and FJetpack
then
4498 if NetServer
then MH_SEND_PlayerStats(FUID
);
4500 FCanJetpack
:= True;
4507 for k
:= Low(FKeys
) to KEY_CHAT
-1 do
4509 if FKeys
[k
].Pressed
then
4517 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
4520 if (FTime
[T_RESPAWN
] <= gTime
) and
4521 gGameOn
and (not FLive
) then
4523 if (g_Player_GetCount() > 1) then
4527 gExit
:= EXIT_RESTART
;
4532 // Dead spectator actions
4535 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Fire();
4536 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then
4540 if (FSpectatePlayer
>= High(gPlayers
)) then
4541 FSpectatePlayer
:= -1
4545 for I
:= FSpectatePlayer
+ 1 to High(gPlayers
) do
4546 if gPlayers
[I
] <> nil then
4547 if gPlayers
[I
].Live
then
4548 if gPlayers
[I
].UID
<> FUID
then
4550 FSpectatePlayer
:= I
;
4555 if not SetSpect
then FSpectatePlayer
:= -1;
4566 if FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_JUMP
].Pressed
then
4568 FYTo
:= FObj
.Y
- 32;
4569 FSpectatePlayer
:= -1;
4571 if FKeys
[KEY_DOWN
].Pressed
then
4573 FYTo
:= FObj
.Y
+ 32;
4574 FSpectatePlayer
:= -1;
4576 if FKeys
[KEY_LEFT
].Pressed
then
4578 FXTo
:= FObj
.X
- 32;
4579 FSpectatePlayer
:= -1;
4581 if FKeys
[KEY_RIGHT
].Pressed
then
4583 FXTo
:= FObj
.X
+ 32;
4584 FSpectatePlayer
:= -1;
4587 if (FXTo
< -64) then
4589 else if (FXTo
> gMapInfo
.Width
+ 32) then
4590 FXTo
:= gMapInfo
.Width
+ 32;
4591 if (FYTo
< -72) then
4593 else if (FYTo
> gMapInfo
.Height
+ 32) then
4594 FYTo
:= gMapInfo
.Height
+ 32;
4598 g_Obj_Move(@FObj
, True, True, True)
4604 if (FSpectatePlayer
<= High(gPlayers
)) and (FSpectatePlayer
>= 0) then
4605 if gPlayers
[FSpectatePlayer
] <> nil then
4606 if gPlayers
[FSpectatePlayer
].Live
then
4608 FXTo
:= gPlayers
[FSpectatePlayer
].GameX
;
4609 FYTo
:= gPlayers
[FSpectatePlayer
].GameY
;
4613 blockmon
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
, FObj
.Y
+PLAYER_HEADRECT
.Y
,
4614 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
4615 PANEL_BLOCKMON
, True);
4616 headwater
:= HeadInLiquid(0, 0);
4618 // Ñîïðîòèâëåíèå âîçäóõà:
4619 if (not FLive
) or not (FKeys
[KEY_LEFT
].Pressed
or FKeys
[KEY_RIGHT
].Pressed
) then
4620 if FObj
.Vel
.X
<> 0 then
4621 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
4623 if (FLastHit
= HIT_TRAP
) and (FPain
> 90) then FPain
:= 90;
4624 DecMin(FPain
, 5, 0);
4625 DecMin(FPickup
, 1, 0);
4627 if FLive
and (FObj
.Y
> gMapInfo
.Height
+128) and AnyServer
then
4629 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
4630 FMegaRulez
[MR_SUIT
] := 0;
4631 FMegaRulez
[MR_INVUL
] := 0;
4632 FMegaRulez
[MR_INVIS
] := 0;
4633 Kill(K_FALLKILL
, 0, HIT_FALL
);
4640 if FCurrWeap
= WEAPON_SAW
then
4641 if not (FSawSound
.IsPlaying() or FSawSoundHit
.IsPlaying() or
4642 FSawSoundSelect
.IsPlaying()) then
4643 FSawSoundIdle
.PlayAt(FObj
.X
, FObj
.Y
);
4646 if (not FJetSoundFly
.IsPlaying()) and (not FJetSoundOn
.IsPlaying()) and
4647 (not FJetSoundOff
.IsPlaying()) then
4649 FJetSoundFly
.SetPosition(0);
4650 FJetSoundFly
.PlayAt(FObj
.X
, FObj
.Y
);
4653 for b
:= WEAPON_KASTET
to WEAPON_SUPERPULEMET
do
4654 if FReloading
[b
] > 0 then
4660 if FShellTimer
> -1 then
4661 if FShellTimer
= 0 then
4663 if FShellType
= SHELL_SHELL
then
4664 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
4665 GameVelX
, GameVelY
-2, SHELL_SHELL
)
4666 else if FShellType
= SHELL_DBLSHELL
then
4668 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
4669 GameVelX
+1, GameVelY
-2, SHELL_SHELL
);
4670 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
4671 GameVelX
-1, GameVelY
-2, SHELL_SHELL
);
4674 end else Dec(FShellTimer
);
4676 if (FBFGFireCounter
> -1) then
4677 if FBFGFireCounter
= 0 then
4681 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
4682 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
4683 xd
:= wx
+IfThen(FDirection
= D_LEFT
, -30, 30);
4684 yd
:= wy
+firediry();
4685 g_Weapon_bfgshot(wx
, wy
, xd
, yd
, FUID
);
4686 if NetServer
then MH_SEND_PlayerFire(FUID
, WEAPON_BFG
, wx
, wy
, xd
, yd
);
4687 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
4688 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
4689 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
4692 FReloading
[WEAPON_BFG
] := WEAPON_RELOAD
[WEAPON_BFG
];
4693 FBFGFireCounter
:= -1;
4696 FBFGFireCounter
:= 0
4698 Dec(FBFGFireCounter
);
4700 if (FMegaRulez
[MR_SUIT
] < gTime
) and AnyServer
then
4702 b
:= g_GetAcidHit(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
);
4704 if (b
> 0) and (gTime
mod (15*GAME_TICK
) = 0) then Damage(b
, 0, 0, 0, HIT_ACID
);
4707 if (headwater
or blockmon
) then
4713 if AnyServer
then Damage(10, 0, 0, 0, HIT_WATER
);
4716 else if (FAir
mod 31 = 0) and not blockmon
then
4718 g_GFX_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2), FObj
.Y
+PLAYER_RECT
.Y
-4, 5+Random(6), 8, 4);
4719 if Random(2) = 0 then
4720 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
4722 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
4724 end else if FAir
< AIR_DEF
then
4727 if FDamageBuffer
> 0 then
4729 if FDamageBuffer
>= 9 then
4733 if FDamageBuffer
< 30 then i
:= 9
4734 else if FDamageBuffer
< 100 then i
:= 18
4738 ii
:= Round(FDamageBuffer
*FHealth
/ nonz(FArmor
*(3/4)+FHealth
));
4739 FArmor
:= FArmor
-(FDamageBuffer
-ii
);
4740 FHealth
:= FHealth
-ii
;
4743 FHealth
:= FHealth
+FArmor
;
4748 if FHealth
<= 0 then
4749 if FHealth
> -30 then Kill(K_SIMPLEKILL
, FLastSpawnerUID
, FLastHit
)
4750 else if FHealth
> -50 then Kill(K_HARDKILL
, FLastSpawnerUID
, FLastHit
)
4751 else Kill(K_EXTRAHARDKILL
, FLastSpawnerUID
, FLastHit
);
4755 if FDamageBuffer
<= 20 then FModel
.PlaySound(MODELSOUND_PAIN
, 1, FObj
.X
, FObj
.Y
)
4756 else if FDamageBuffer
<= 55 then FModel
.PlaySound(MODELSOUND_PAIN
, 2, FObj
.X
, FObj
.Y
)
4757 else if FDamageBuffer
<= 120 then FModel
.PlaySound(MODELSOUND_PAIN
, 3, FObj
.X
, FObj
.Y
)
4758 else FModel
.PlaySound(MODELSOUND_PAIN
, 4, FObj
.X
, FObj
.Y
);
4765 end; // if FLive then ...
4767 if (FActionAnim
= A_PAIN
) and (FModel
.Animation
<> A_PAIN
) then
4769 FModel
.ChangeAnimation(FActionAnim
, FActionForce
);
4770 FModel
.GetCurrentAnimation
.MinLength
:= i
;
4771 FModel
.GetCurrentAnimationMask
.MinLength
:= i
;
4772 end else FModel
.ChangeAnimation(FActionAnim
, FActionForce
and (FModel
.Animation
<> A_STAND
));
4774 if (FModel
.GetCurrentAnimation
.Played
or ((not FActionChanged
) and (FModel
.Animation
= A_WALK
)))
4775 then SetAction(A_STAND
, True);
4777 if not ((FModel
.Animation
= A_WALK
) and (Abs(FObj
.Vel
.X
) < 4) and not FModel
.Fire
) then FModel
.Update
;
4779 for b
:= Low(FKeys
) to High(FKeys
) do
4780 if FKeys
[b
].Time
= 0 then FKeys
[b
].Pressed
:= False else Dec(FKeys
[b
].Time
);
4783 function TPlayer
.Collide(X
, Y
: Integer; Width
, Height
: Word): Boolean;
4785 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
4786 FObj
.Y
+PLAYER_RECT
.Y
,
4793 function TPlayer
.Collide(Panel
: TPanel
): Boolean;
4795 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
4796 FObj
.Y
+PLAYER_RECT
.Y
,
4800 Panel
.Width
, Panel
.Height
);
4803 function TPlayer
.Collide(X
, Y
: Integer): Boolean;
4805 X
:= X
-FObj
.X
-PLAYER_RECT
.X
;
4806 Y
:= Y
-FObj
.Y
-PLAYER_RECT
.Y
;
4807 Result
:= (x
>= 0) and (x
<= PLAYER_RECT
.Width
) and
4808 (y
>= 0) and (y
<= PLAYER_RECT
.Height
);
4811 function g_Player_ValidName(Name
: string): Boolean;
4817 if gPlayers
= nil then Exit
;
4819 for a
:= 0 to High(gPlayers
) do
4820 if gPlayers
[a
] <> nil then
4821 if LowerCase(Name
) = LowerCase(gPlayers
[a
].FName
) then
4828 procedure TPlayer
.SetDirection(Direction
: TDirection
);
4832 d
:= FModel
.Direction
;
4834 FModel
.Direction
:= Direction
;
4835 if d
<> Direction
then FModel
.ChangeAnimation(FModel
.Animation
, True);
4837 FDirection
:= Direction
;
4840 function TPlayer
.GetKeys(): Byte;
4844 if R_KEY_RED
in FRulez
then Result
:= KEY_RED
;
4845 if R_KEY_GREEN
in FRulez
then Result
:= Result
or KEY_GREEN
;
4846 if R_KEY_BLUE
in FRulez
then Result
:= Result
or KEY_BLUE
;
4848 if FTeam
= TEAM_RED
then Result
:= Result
or KEY_REDTEAM
;
4849 if FTeam
= TEAM_BLUE
then Result
:= Result
or KEY_BLUETEAM
;
4852 procedure TPlayer
.Use();
4856 if FTime
[T_USE
] > gTime
then Exit
;
4858 g_Triggers_PressR(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
,
4859 PLAYER_RECT
.Height
, FUID
, ACTIVATE_PLAYERPRESS
);
4861 for a
:= 0 to High(gPlayers
) do
4862 if (gPlayers
[a
] <> nil) and (gPlayers
[a
] <> Self
) and
4863 gPlayers
[a
].Live
and SameTeam(FUID
, gPlayers
[a
].FUID
) and
4864 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
4865 FObj
.Rect
.Width
, FObj
.Rect
.Height
, @gPlayers
[a
].FObj
) then
4867 gPlayers
[a
].Touch();
4868 if g_Game_IsNet
and g_Game_IsServer
then
4869 MH_SEND_GameEvent(NET_EV_PLAYER_TOUCH
, gPlayers
[a
].FUID
);
4872 FTime
[T_USE
] := gTime
+120;
4875 procedure TPlayer
.NetFire(Wpn
: Byte; X
, Y
, AX
, AY
: Integer; WID
: Integer = -1);
4879 WX
, WY
, XD
, YD
: Integer;
4890 if R_BERSERK
in FRulez
then
4892 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
4893 obj
.X
:= FObj
.X
+FObj
.Rect
.X
;
4894 obj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
4897 obj
.rect
.Width
:= 39;
4898 obj
.rect
.Height
:= 52;
4899 obj
.Vel
.X
:= (xd
-wx
) div 2;
4900 obj
.Vel
.Y
:= (yd
-wy
) div 2;
4901 obj
.Accel
.X
:= xd
-wx
;
4902 obj
.Accel
.y
:= yd
-wy
;
4904 if g_Weapon_Hit(@obj
, 50, FUID
, HIT_SOME
) <> 0 then
4905 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
4907 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
4911 FPain
:= min(FPain
+ 25, 50);
4913 g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
4918 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
4919 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
4921 FSawSoundSelect
.Stop();
4923 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
4925 else if not FSawSoundHit
.IsPlaying() then
4927 FSawSoundSelect
.Stop();
4928 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
4935 g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', GameX
, Gamey
);
4936 FFireAngle
:= FAngle
;
4938 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
4939 GameVelX
, GameVelY
-2, SHELL_BULLET
);
4944 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
4945 FFireAngle
:= FAngle
;
4948 FShellType
:= SHELL_SHELL
;
4953 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN2', Gamex
, Gamey
);
4954 FFireAngle
:= FAngle
;
4957 FShellType
:= SHELL_DBLSHELL
;
4962 g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', Gamex
, Gamey
);
4963 FFireAngle
:= FAngle
;
4965 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
4966 GameVelX
, GameVelY
-2, SHELL_BULLET
);
4969 WEAPON_ROCKETLAUNCHER
:
4971 g_Weapon_Rocket(wx
, wy
, xd
, yd
, FUID
, WID
);
4972 FFireAngle
:= FAngle
;
4978 g_Weapon_Plasma(wx
, wy
, xd
, yd
, FUID
, WID
);
4979 FFireAngle
:= FAngle
;
4985 g_Weapon_BFGShot(wx
, wy
, xd
, yd
, FUID
, WID
);
4986 FFireAngle
:= FAngle
;
4990 WEAPON_SUPERPULEMET
:
4992 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
4993 FFireAngle
:= FAngle
;
4995 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
4996 GameVelX
, GameVelY
-2, SHELL_SHELL
);
5002 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
5003 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
5004 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
5007 procedure TPlayer
.DoLerp(Level
: Integer = 2);
5009 if FObj
.X
<> FXTo
then FObj
.X
:= Lerp(FObj
.X
, FXTo
, Level
);
5010 if FObj
.Y
<> FYTo
then FObj
.Y
:= Lerp(FObj
.Y
, FYTo
, Level
);
5013 procedure TPlayer
.SetLerp(XTo
, YTo
: Integer);
5017 if NetInterpLevel
< 1 then
5027 AX
:= Abs(FXTo
- FObj
.X
);
5028 AY
:= Abs(FYTo
- FObj
.Y
);
5029 if (AX
> 32) or (AX
<= NetInterpLevel
) then
5031 if (AY
> 32) or (AY
<= NetInterpLevel
) then
5036 function TPlayer
.FullInLift(XInc
, YInc
: Integer): Integer;
5038 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5039 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5040 PANEL_LIFTUP
, False) then Result
:= -1
5042 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5043 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5044 PANEL_LIFTDOWN
, False) then Result
:= 1
5048 function TPlayer
.GetFlag(Flag
: Byte): Boolean;
5055 if Flag
= FLAG_NONE
then
5058 if not g_Game_IsServer
then Exit
;
5060 // Ïðèíåñ ÷óæîé ôëàã íà ñâîþ áàçó:
5061 if (Flag
= FTeam
) and
5062 (gFlags
[Flag
].State
= FLAG_STATE_NORMAL
) and
5063 (FFlag
<> FLAG_NONE
) then
5065 if FFlag
= FLAG_RED
then
5066 s
:= _lc
[I_PLAYER_FLAG_RED
]
5068 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5070 evtype
:= FLAG_STATE_SCORED
;
5072 ts
:= Format('%.4d', [gFlags
[FFlag
].CaptureTime
]);
5073 Insert('.', ts
, Length(ts
) + 1 - 3);
5074 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_CAPTURE
], [FName
, s
, ts
]), True);
5076 g_Map_ResetFlag(FFlag
);
5077 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_CAPTURE
], [AnsiUpperCase(s
)]), 144);
5079 gTeamStat
[FTeam
].Goals
:= gTeamStat
[FTeam
].Goals
+ 1;
5082 if g_Game_IsNet
then
5084 MH_SEND_FlagEvent(evtype
, FFlag
, FUID
, False);
5088 gFlags
[FFlag
].CaptureTime
:= 0;
5093 // Ïîäîáðàë ñâîé ôëàã - âåðíóë åãî íà áàçó:
5094 if (Flag
= FTeam
) and
5095 (gFlags
[Flag
].State
= FLAG_STATE_DROPPED
) then
5097 if Flag
= FLAG_RED
then
5098 s
:= _lc
[I_PLAYER_FLAG_RED
]
5100 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5102 evtype
:= FLAG_STATE_RETURNED
;
5103 gFlags
[Flag
].CaptureTime
:= 0;
5105 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_RETURN
], [FName
, s
]), True);
5107 g_Map_ResetFlag(Flag
);
5108 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
5111 if g_Game_IsNet
then
5113 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5119 // Ïîäîáðàë ÷óæîé ôëàã:
5120 if (Flag
<> FTeam
) and (FTime
[T_FLAGCAP
] <= gTime
) then
5124 if Flag
= FLAG_RED
then
5125 s
:= _lc
[I_PLAYER_FLAG_RED
]
5127 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5129 evtype
:= FLAG_STATE_CAPTURED
;
5131 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_GET
], [FName
, s
]), True);
5133 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_GET
], [AnsiUpperCase(s
)]), 144);
5135 gFlags
[Flag
].State
:= FLAG_STATE_CAPTURED
;
5138 if g_Game_IsNet
then
5140 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5146 procedure TPlayer
.SetFlag(Flag
: Byte);
5149 if FModel
<> nil then
5150 FModel
.SetFlag(FFlag
);
5153 function TPlayer
.DropFlag(): Boolean;
5158 if (not g_Game_IsServer
) or (FFlag
= FLAG_NONE
) then
5160 FTime
[T_FLAGCAP
] := gTime
+ 2000;
5161 with gFlags
[FFlag
] do
5165 Direction
:= FDirection
;
5166 State
:= FLAG_STATE_DROPPED
;
5168 g_Obj_Push(@Obj
, (FObj
.Vel
.X
div 2)-2+Random(5),
5169 (FObj
.Vel
.Y
div 2)-2+Random(5));
5171 if FFlag
= FLAG_RED
then
5172 s
:= _lc
[I_PLAYER_FLAG_RED
]
5174 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5176 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_DROP
], [FName
, s
]), True);
5177 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_DROP
], [AnsiUpperCase(s
)]), 144);
5179 if g_Game_IsNet
then
5180 MH_SEND_FlagEvent(FLAG_STATE_DROPPED
, Flag
, FUID
, False);
5186 procedure TPlayer
.GetSecret();
5191 procedure TPlayer
.PressKey(Key
: Byte; Time
: Word = 1);
5193 Assert(Key
<= High(FKeys
));
5195 FKeys
[Key
].Pressed
:= True;
5196 FKeys
[Key
].Time
:= Time
;
5199 function TPlayer
.IsKeyPressed(K
: Byte): Boolean;
5201 Result
:= FKeys
[K
].Pressed
;
5204 procedure TPlayer
.ReleaseKeys();
5208 for a
:= Low(FKeys
) to High(FKeys
) do
5210 FKeys
[a
].Pressed
:= False;
5215 procedure TPlayer
.OnDamage(Angle
: SmallInt);
5219 function TPlayer
.firediry(): Integer;
5221 if FKeys
[KEY_UP
].Pressed
then Result
:= -42
5222 else if FKeys
[KEY_DOWN
].Pressed
then Result
:= 19
5226 procedure TPlayer
.RememberState();
5230 FSavedState
.Health
:= FHealth
;
5231 FSavedState
.Armor
:= FArmor
;
5232 FSavedState
.Air
:= FAir
;
5233 FSavedState
.JetFuel
:= FJetFuel
;
5234 FSavedState
.CurrWeap
:= FCurrWeap
;
5235 FSavedState
.NextWeap
:= FNextWeap
;
5236 FSavedState
.NextWeapDelay
:= FNextWeapDelay
;
5239 FSavedState
.Ammo
[i
] := FAmmo
[i
];
5241 FSavedState
.MaxAmmo
[i
] := FMaxAmmo
[i
];
5243 FSavedState
.Rulez
:= FRulez
;
5244 FSavedState
.WaitRecall
:= True;
5247 procedure TPlayer
.RecallState();
5251 if not FSavedState
.WaitRecall
then Exit
;
5253 FHealth
:= FSavedState
.Health
;
5254 FArmor
:= FSavedState
.Armor
;
5255 FAir
:= FSavedState
.Air
;
5256 FJetFuel
:= FSavedState
.JetFuel
;
5257 FCurrWeap
:= FSavedState
.CurrWeap
;
5258 FNextWeap
:= FSavedState
.NextWeap
;
5259 FNextWeapDelay
:= FSavedState
.NextWeapDelay
;
5262 FAmmo
[i
] := FSavedState
.Ammo
[i
];
5264 FMaxAmmo
[i
] := FSavedState
.MaxAmmo
[i
];
5266 FRulez
:= FSavedState
.Rulez
;
5267 FSavedState
.WaitRecall
:= False;
5269 if gGameSettings
.GameType
= GT_SERVER
then
5270 MH_SEND_PlayerStats(FUID
);
5273 procedure TPlayer
.SaveState(var Mem
: TBinMemoryWriter
);
5285 Mem
:= TBinMemoryWriter
.Create(i
);
5287 // Ñèãíàòóðà èãðîêà:
5288 sig
:= PLAYER_SIGNATURE
; // 'PLYR'
5289 Mem
.WriteDWORD(sig
);
5291 Mem
.WriteBoolean(FIamBot
);
5293 Mem
.WriteWord(FUID
);
5295 Mem
.WriteString(FName
, 32);
5297 Mem
.WriteByte(FTeam
);
5299 Mem
.WriteBoolean(FLive
);
5300 // Èçðàñõîäîâàë ëè âñå æèçíè:
5301 Mem
.WriteBoolean(FNoRespawn
);
5303 if FDirection
= D_LEFT
then
5309 Mem
.WriteInt(FHealth
);
5311 Mem
.WriteByte(FLives
);
5313 Mem
.WriteInt(FArmor
);
5317 Mem
.WriteInt(FJetFuel
);
5319 Mem
.WriteInt(FPain
);
5321 Mem
.WriteInt(FKills
);
5323 Mem
.WriteInt(FMonsterKills
);
5325 Mem
.WriteInt(FFrags
);
5327 Mem
.WriteByte(FFragCombo
);
5328 // Âðåìÿ ïîñëåäíåãî ôðàãà:
5329 Mem
.WriteDWORD(FLastFrag
);
5331 Mem
.WriteInt(FDeath
);
5332 // Êàêîé ôëàã íåñåò:
5333 Mem
.WriteByte(FFlag
);
5335 Mem
.WriteInt(FSecrets
);
5337 Mem
.WriteByte(FCurrWeap
);
5339 Mem
.WriteWord(FNextWeap
);
5341 Mem
.WriteByte(FNextWeapDelay
);
5342 // Âðåìÿ çàðÿäêè BFG:
5343 Mem
.WriteSmallInt(FBFGFireCounter
);
5345 Mem
.WriteInt(FDamageBuffer
);
5346 // Ïîñëåäíèé óäàðèâøèé:
5347 Mem
.WriteWord(FLastSpawnerUID
);
5348 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà:
5349 Mem
.WriteByte(FLastHit
);
5351 Obj_SaveState(@FObj
, Mem
);
5352 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ:
5353 for i
:= A_BULLETS
to A_CELLS
do
5354 Mem
.WriteWord(FAmmo
[i
]);
5355 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ:
5356 for i
:= A_BULLETS
to A_CELLS
do
5357 Mem
.WriteWord(FMaxAmmo
[i
]);
5359 for i
:= WEAPON_KASTET
to WEAPON_SUPERPULEMET
do
5360 Mem
.WriteBoolean(FWeapon
[i
]);
5361 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ:
5362 for i
:= WEAPON_KASTET
to WEAPON_SUPERPULEMET
do
5363 Mem
.WriteWord(FReloading
[i
]);
5365 if R_ITEM_BACKPACK
in FRulez
then
5370 // Íàëè÷èå êðàñíîãî êëþ÷à:
5371 if R_KEY_RED
in FRulez
then
5376 // Íàëè÷èå çåëåíîãî êëþ÷à:
5377 if R_KEY_GREEN
in FRulez
then
5382 // Íàëè÷èå ñèíåãî êëþ÷à:
5383 if R_KEY_BLUE
in FRulez
then
5388 // Íàëè÷èå áåðñåðêà:
5389 if R_BERSERK
in FRulez
then
5394 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ:
5395 for i
:= MR_SUIT
to MR_MAX
do
5396 Mem
.WriteDWORD(FMegaRulez
[i
]);
5397 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà:
5398 for i
:= T_RESPAWN
to T_FLAGCAP
do
5399 Mem
.WriteDWORD(FTime
[i
]);
5402 Mem
.WriteString(str
);
5412 procedure TPlayer
.LoadState(var Mem
: TBinMemoryReader
);
5422 // Ñèãíàòóðà èãðîêà:
5424 if sig
<> PLAYER_SIGNATURE
then // 'PLYR'
5426 raise EBinSizeError
.Create('TPlayer.LoadState: Wrong Player Signature');
5429 Mem
.ReadBoolean(FIamBot
);
5433 Mem
.ReadString(str
);
5434 if (Self
<> gPlayer1
) and (Self
<> gPlayer2
) then
5437 Mem
.ReadByte(FTeam
);
5439 Mem
.ReadBoolean(FLive
);
5440 // Èçðàñõîäîâàë ëè âñå æèçíè:
5441 Mem
.ReadBoolean(FNoRespawn
);
5445 FDirection
:= D_LEFT
5447 FDirection
:= D_RIGHT
;
5449 Mem
.ReadInt(FHealth
);
5451 Mem
.ReadByte(FLives
);
5453 Mem
.ReadInt(FArmor
);
5457 Mem
.ReadInt(FJetFuel
);
5461 Mem
.ReadInt(FKills
);
5463 Mem
.ReadInt(FMonsterKills
);
5465 Mem
.ReadInt(FFrags
);
5467 Mem
.ReadByte(FFragCombo
);
5468 // Âðåìÿ ïîñëåäíåãî ôðàãà:
5469 Mem
.ReadDWORD(FLastFrag
);
5471 Mem
.ReadInt(FDeath
);
5472 // Êàêîé ôëàã íåñåò:
5473 Mem
.ReadByte(FFlag
);
5475 Mem
.ReadInt(FSecrets
);
5477 Mem
.ReadByte(FCurrWeap
);
5479 Mem
.ReadWord(FNextWeap
);
5481 Mem
.ReadByte(FNextWeapDelay
);
5482 // Âðåìÿ çàðÿäêè BFG:
5483 Mem
.ReadSmallInt(FBFGFireCounter
);
5485 Mem
.ReadInt(FDamageBuffer
);
5486 // Ïîñëåäíèé óäàðèâøèé:
5487 Mem
.ReadWord(FLastSpawnerUID
);
5488 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà:
5489 Mem
.ReadByte(FLastHit
);
5491 Obj_LoadState(@FObj
, Mem
);
5492 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ:
5493 for i
:= A_BULLETS
to A_CELLS
do
5494 Mem
.ReadWord(FAmmo
[i
]);
5495 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ:
5496 for i
:= A_BULLETS
to A_CELLS
do
5497 Mem
.ReadWord(FMaxAmmo
[i
]);
5499 for i
:= WEAPON_KASTET
to WEAPON_SUPERPULEMET
do
5500 Mem
.ReadBoolean(FWeapon
[i
]);
5501 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ:
5502 for i
:= WEAPON_KASTET
to WEAPON_SUPERPULEMET
do
5503 Mem
.ReadWord(FReloading
[i
]);
5507 Include(FRulez
, R_ITEM_BACKPACK
);
5508 // Íàëè÷èå êðàñíîãî êëþ÷à:
5511 Include(FRulez
, R_KEY_RED
);
5512 // Íàëè÷èå çåëåíîãî êëþ÷à:
5515 Include(FRulez
, R_KEY_GREEN
);
5516 // Íàëè÷èå ñèíåãî êëþ÷à:
5519 Include(FRulez
, R_KEY_BLUE
);
5520 // Íàëè÷èå áåðñåðêà:
5523 Include(FRulez
, R_BERSERK
);
5524 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ:
5525 for i
:= MR_SUIT
to MR_MAX
do
5526 Mem
.ReadDWORD(FMegaRulez
[i
]);
5527 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà:
5528 for i
:= T_RESPAWN
to T_FLAGCAP
do
5529 Mem
.ReadDWORD(FTime
[i
]);
5531 Mem
.ReadString(str
);
5533 Mem
.ReadByte(FColor
.R
);
5534 Mem
.ReadByte(FColor
.G
);
5535 Mem
.ReadByte(FColor
.B
);
5536 if Self
= gPlayer1
then
5538 str
:= gPlayer1Settings
.Model
;
5539 FColor
:= gPlayer1Settings
.Color
;
5541 if Self
= gPlayer2
then
5543 str
:= gPlayer2Settings
.Model
;
5544 FColor
:= gPlayer2Settings
.Color
;
5546 // Îáíîâëÿåì ìîäåëü èãðîêà:
5548 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
5549 FModel
.Color
:= TEAMCOLOR
[FTeam
]
5551 FModel
.Color
:= FColor
;
5554 procedure TPlayer
.AllRulez(Health
: Boolean);
5560 FHealth
:= PLAYER_HP_LIMIT
;
5561 FArmor
:= PLAYER_AP_LIMIT
;
5565 for a
:= WEAPON_KASTET
to WEAPON_SUPERPULEMET
do FWeapon
[a
] := True;
5566 for a
:= A_BULLETS
to A_CELLS
do FAmmo
[a
] := 30000;
5567 FRulez
:= FRulez
+[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
];
5570 procedure TPlayer
.RestoreHealthArmor();
5572 FHealth
:= PLAYER_HP_LIMIT
;
5573 FArmor
:= PLAYER_AP_LIMIT
;
5576 procedure TPlayer
.FragCombo();
5580 if (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) or g_Game_IsClient
then
5582 if gTime
- FLastFrag
< FRAG_COMBO_TIME
then
5584 if FFragCombo
< 5 then
5586 Param
:= FUID
or (FFragCombo
shl 16);
5587 if (FComboEvnt
>= Low(gDelayedEvents
)) and
5588 (FComboEvnt
<= High(gDelayedEvents
)) and
5589 gDelayedEvents
[FComboEvnt
].Pending
and
5590 (gDelayedEvents
[FComboEvnt
].DEType
= DE_KILLCOMBO
) and
5591 (gDelayedEvents
[FComboEvnt
].DENum
and $FFFF = FUID
) then
5593 gDelayedEvents
[FComboEvnt
].Time
:= gTime
+ 500;
5594 gDelayedEvents
[FComboEvnt
].DENum
:= Param
;
5597 FComboEvnt
:= g_Game_DelayEvent(DE_KILLCOMBO
, 500, Param
);
5605 procedure TPlayer
.GiveItem(ItemType
: Byte);
5609 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
5611 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
5615 if FAir
< AIR_MAX
then
5622 if not (R_BERSERK
in FRulez
) then
5624 Include(FRulez
, R_BERSERK
);
5625 if FBFGFireCounter
< 1 then
5627 FCurrWeap
:= WEAPON_KASTET
;
5629 FModel
.SetWeapon(WEAPON_KASTET
);
5633 FBerserk
:= gTime
+30000;
5635 if FHealth
< PLAYER_HP_SOFT
then
5637 FHealth
:= PLAYER_HP_SOFT
;
5638 FBerserk
:= gTime
+30000;
5643 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
5645 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
5649 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
5651 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
5655 if FJetFuel
< JET_MAX
then
5657 FJetFuel
:= JET_MAX
;
5660 ITEM_MEDKIT_SMALL
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
5661 ITEM_MEDKIT_LARGE
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
5663 ITEM_ARMOR_GREEN
: if FArmor
< PLAYER_AP_SOFT
then FArmor
:= PLAYER_AP_SOFT
;
5664 ITEM_ARMOR_BLUE
: if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
5666 ITEM_SPHERE_BLUE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
5668 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) then
5670 if FHealth
< PLAYER_HP_LIMIT
then FHealth
:= PLAYER_HP_LIMIT
;
5671 if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
5674 ITEM_WEAPON_SAW
: FWeapon
[WEAPON_SAW
] := True;
5675 ITEM_WEAPON_SHOTGUN1
: FWeapon
[WEAPON_SHOTGUN1
] := True;
5676 ITEM_WEAPON_SHOTGUN2
: FWeapon
[WEAPON_SHOTGUN2
] := True;
5677 ITEM_WEAPON_CHAINGUN
: FWeapon
[WEAPON_CHAINGUN
] := True;
5678 ITEM_WEAPON_ROCKETLAUNCHER
: FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
5679 ITEM_WEAPON_PLASMA
: FWeapon
[WEAPON_PLASMA
] := True;
5680 ITEM_WEAPON_BFG
: FWeapon
[WEAPON_BFG
] := True;
5681 ITEM_WEAPON_SUPERPULEMET
: FWeapon
[WEAPON_SUPERPULEMET
] := True;
5683 ITEM_AMMO_BULLETS
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
5684 ITEM_AMMO_BULLETS_BOX
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
5685 ITEM_AMMO_SHELLS
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
5686 ITEM_AMMO_SHELLS_BOX
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
5687 ITEM_AMMO_ROCKET
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
5688 ITEM_AMMO_ROCKET_BOX
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
5689 ITEM_AMMO_CELL
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
5690 ITEM_AMMO_CELL_BIG
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
5693 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
5694 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
5695 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
5696 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) then
5698 FMaxAmmo
[A_BULLETS
] := 400;
5699 FMaxAmmo
[A_SHELLS
] := 100;
5700 FMaxAmmo
[A_ROCKETS
] := 100;
5701 FMaxAmmo
[A_CELLS
] := 600;
5703 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
5704 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
5705 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
5706 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
5708 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
5711 ITEM_KEY_RED
: if not (R_KEY_RED
in FRulez
) then Include(FRulez
, R_KEY_RED
);
5712 ITEM_KEY_GREEN
: if not (R_KEY_GREEN
in FRulez
) then Include(FRulez
, R_KEY_GREEN
);
5713 ITEM_KEY_BLUE
: if not (R_KEY_BLUE
in FRulez
) then Include(FRulez
, R_KEY_BLUE
);
5715 ITEM_BOTTLE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
5716 ITEM_HELMET
: if FArmor
< PLAYER_AP_LIMIT
then IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
5721 if g_Game_IsNet
and g_Game_IsServer
then
5722 MH_SEND_PlayerStats(FUID
);
5725 procedure TPlayer
.FlySmoke(Times
: DWORD
= 1);
5730 if (Random(5) = 1) and (Times
= 1) then
5733 if BodyInLiquid(0, 0) then
5735 g_GFX_Bubbles(Obj
.X
+Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2)+Random(3)-1,
5736 Obj
.Y
+Obj
.Rect
.Height
+8, 1, 8, 4);
5737 if Random(2) = 0 then
5738 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
5740 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
5744 if g_Frames_Get(id
, 'FRAMES_SMOKE') then
5746 for i
:= 1 to Times
do
5748 Anim
:= TAnimation
.Create(id
, False, 3);
5750 g_GFX_OnceAnim(Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(Anim
.Width
div 2),
5751 Obj
.Y
+Obj
.Rect
.Height
-4+Random(8+Times
*2), Anim
, ONCEANIM_SMOKE
);
5757 procedure TPlayer
.PauseSounds(Enable
: Boolean);
5759 FSawSound
.Pause(Enable
);
5760 FSawSoundIdle
.Pause(Enable
);
5761 FSawSoundHit
.Pause(Enable
);
5762 FSawSoundSelect
.Pause(Enable
);
5767 constructor TCorpse
.Create(X
, Y
: Integer; ModelName
: String; aMess
: Boolean);
5772 FObj
.Rect
:= PLAYER_CORPSERECT
;
5773 FModelName
:= ModelName
;
5778 FState
:= CORPSE_STATE_MESS
;
5779 g_PlayerModel_GetAnim(ModelName
, A_DIE2
, FAnimation
, FAnimationMask
);
5783 FState
:= CORPSE_STATE_NORMAL
;
5784 g_PlayerModel_GetAnim(ModelName
, A_DIE1
, FAnimation
, FAnimationMask
);
5788 destructor TCorpse
.Destroy();
5795 procedure TCorpse
.Damage(Value
: Word; vx
, vy
: Integer);
5799 if FState
= CORPSE_STATE_REMOVEME
then
5802 FDamage
:= FDamage
+ Value
;
5804 if FDamage
> 150 then
5806 if FAnimation
<> nil then
5811 FState
:= CORPSE_STATE_REMOVEME
;
5813 g_Player_CreateGibs(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
5814 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2),
5815 FModelName
, FColor
);
5816 // Çâóê ìÿñà îò òðóïà:
5817 pm
:= g_PlayerModel_Get(FModelName
);
5818 pm
.PlaySound(MODELSOUND_DIE
, 5, FObj
.X
, FObj
.Y
);
5824 FObj
.Vel
.X
:= FObj
.Vel
.X
+ vx
;
5825 FObj
.Vel
.Y
:= FObj
.Vel
.Y
+ vy
;
5826 g_GFX_Blood(FObj
.X
+PLAYER_CORPSERECT
.X
+(PLAYER_CORPSERECT
.Width
div 2),
5827 FObj
.Y
+PLAYER_CORPSERECT
.Y
+(PLAYER_CORPSERECT
.Height
div 2),
5828 Value
, vx
, vy
, 16, (PLAYER_CORPSERECT
.Height
*2) div 3,
5833 procedure TCorpse
.Draw();
5835 if FState
= CORPSE_STATE_REMOVEME
then
5838 if FAnimation
<> nil then
5839 FAnimation
.Draw(FObj
.X
, FObj
.Y
, M_NONE
);
5841 if FAnimationMask
<> nil then
5844 FAnimationMask
.Draw(FObj
.X
, FObj
.Y
, M_NONE
);
5851 procedure TCorpse
.Update();
5855 if FState
= CORPSE_STATE_REMOVEME
then
5858 if gTime
mod (GAME_TICK
*2) <> 0 then
5860 g_Obj_Move(@FObj
, True, True, True);
5865 // Ñîïðîòèâëåíèå âîçäóõà äëÿ òðóïà:
5866 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
5868 st
:= g_Obj_Move(@FObj
, True, True, True);
5870 if WordBool(st
and MOVE_FALLOUT
) then
5872 FState
:= CORPSE_STATE_REMOVEME
;
5876 if FAnimation
<> nil then
5877 FAnimation
.Update();
5878 if FAnimationMask
<> nil then
5879 FAnimationMask
.Update();
5882 procedure TCorpse
.SaveState(var Mem
: TBinMemoryWriter
);
5891 sig
:= CORPSE_SIGNATURE
; // 'CORP'
5892 Mem
.WriteDWORD(sig
);
5894 Mem
.WriteByte(FState
);
5895 // Íàêîïëåííûé óðîí:
5896 Mem
.WriteByte(FDamage
);
5898 Mem
.WriteByte(FColor
.R
);
5899 Mem
.WriteByte(FColor
.G
);
5900 Mem
.WriteByte(FColor
.B
);
5902 Obj_SaveState(@FObj
, Mem
);
5903 // Åñòü ëè àíèìàöèÿ:
5904 anim
:= FAnimation
<> nil;
5905 Mem
.WriteBoolean(anim
);
5906 // Åñëè åñòü - ñîõðàíÿåì:
5908 FAnimation
.SaveState(Mem
);
5909 // Åñòü ëè ìàñêà àíèìàöèè:
5910 anim
:= FAnimationMask
<> nil;
5911 Mem
.WriteBoolean(anim
);
5912 // Åñëè åñòü - ñîõðàíÿåì:
5914 FAnimationMask
.SaveState(Mem
);
5917 procedure TCorpse
.LoadState(var Mem
: TBinMemoryReader
);
5927 if sig
<> CORPSE_SIGNATURE
then // 'CORP'
5929 raise EBinSizeError
.Create('TCorpse.LoadState: Wrong Corpse Signature');
5932 Mem
.ReadByte(FState
);
5933 // Íàêîïëåííûé óðîí:
5934 Mem
.ReadByte(FDamage
);
5936 Mem
.ReadByte(FColor
.R
);
5937 Mem
.ReadByte(FColor
.G
);
5938 Mem
.ReadByte(FColor
.B
);
5940 Obj_LoadState(@FObj
, Mem
);
5941 // Åñòü ëè àíèìàöèÿ:
5942 Mem
.ReadBoolean(anim
);
5943 // Åñëè åñòü - çàãðóæàåì:
5946 Assert(FAnimation
<> nil, 'TCorpse.LoadState: no FAnimation');
5947 FAnimation
.LoadState(Mem
);
5949 // Åñòü ëè ìàñêà àíèìàöèè:
5950 Mem
.ReadBoolean(anim
);
5951 // Åñëè åñòü - çàãðóæàåì:
5954 Assert(FAnimationMask
<> nil, 'TCorpse.LoadState: no FAnimationMask');
5955 FAnimationMask
.LoadState(Mem
);
5961 constructor TBot
.Create();
5968 FSpectator
:= False;
5975 for a
:= WEAPON_KASTET
to WEAPON_SUPERPULEMET
do
5977 FDifficult
.WeaponPrior
[a
] := WEAPON_PRIOR1
[a
];
5978 FDifficult
.CloseWeaponPrior
[a
] := WEAPON_PRIOR2
[a
];
5979 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
5983 destructor TBot
.Destroy();
5986 inherited Destroy();
5989 procedure TBot
.Draw();
5993 //if FTargetUID <> 0 then e_DrawLine(1, FObj.X, FObj.Y, g_Player_Get(FTargetUID).FObj.X,
5994 // g_Player_Get(FTargetUID).FObj.Y, 255, 0, 0);
5997 procedure TBot
.Respawn(Silent
: Boolean; Force
: Boolean = False);
5999 inherited Respawn(Silent
, Force
);
6002 FSelectedWeapon
:= FCurrWeap
;
6007 procedure TBot
.UpdateCombat();
6020 TTargetRecord
= array of TTarget
;
6022 function Compare(a
, b
: TTarget
): Integer;
6024 if a
.Line
and not b
.Line
then // A íà ëèíèè îãíÿ
6027 if not a
.Line
and b
.Line
then // B íà ëèíèè îãíÿ
6029 else // È A, è B íà ëèíèè èëè íå íà ëèíèè îãíÿ
6030 if (a
.Line
and b
.Line
) or ((not a
.Line
) and (not b
.Line
)) then
6032 if a
.Dist
> b
.Dist
then // B áëèæå
6034 else // A áëèæå èëè ðàâíîóäàëåííî ñ B
6037 else // Ñòðàííî -> A
6042 a
, x1
, y1
, x2
, y2
: Integer;
6043 targets
: TTargetRecord
;
6045 Target
, BestTarget
: TTarget
;
6046 firew
, fireh
: Integer;
6050 vsPlayer
, vsMonster
, ok
: Boolean;
6052 vsPlayer
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
);
6053 vsMonster
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
);
6055 // Åñëè òåêóùåå îðóæèå íå òî, ÷òî íóæíî, òî ìåíÿåì:
6056 if FCurrWeap
<> FSelectedWeapon
then
6059 // Åñëè íóæíî ñòðåëÿòü è íóæíîå îðóæèå, òî íàæàòü "Ñòðåëÿòü":
6060 if (GetAIFlag('NEEDFIRE') <> '') and (FCurrWeap
= FSelectedWeapon
) then
6062 RemoveAIFlag('NEEDFIRE');
6065 WEAPON_PLASMA
, WEAPON_SUPERPULEMET
, WEAPON_CHAINGUN
: PressKey(KEY_FIRE
, 20);
6066 WEAPON_SAW
, WEAPON_KASTET
, WEAPON_MEGAKASTET
: PressKey(KEY_FIRE
, 40);
6067 else PressKey(KEY_FIRE
);
6071 // Êîîðäèíàòû ñòâîëà:
6072 x1
:= FObj
.X
+ WEAPONPOINT
[FDirection
].X
;
6073 y1
:= FObj
.Y
+ WEAPONPOINT
[FDirection
].Y
;
6075 Target
.UID
:= FTargetUID
;
6078 if Target
.UID
<> 0 then
6079 begin // Öåëü åñòü - íàñòðàèâàåì
6080 if (g_GetUIDType(Target
.UID
) = UID_PLAYER
) and
6083 with g_Player_Get(Target
.UID
) do
6085 if (@FObj
) <> nil then
6092 Target
.cX
:= Target
.X
+ PLAYER_RECT_CX
;
6093 Target
.cY
:= Target
.Y
+ PLAYER_RECT_CY
;
6094 Target
.Rect
:= PLAYER_RECT
;
6095 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6096 Target
.Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6097 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6098 Target
.IsPlayer
:= True;
6102 if (g_GetUIDType(Target
.UID
) = UID_MONSTER
) and
6105 mon
:= g_Monsters_Get(Target
.UID
);
6108 Target
.X
:= mon
.Obj
.X
;
6109 Target
.Y
:= mon
.Obj
.Y
;
6111 Target
.cX
:= Target
.X
+ mon
.Obj
.Rect
.X
+ (mon
.Obj
.Rect
.Width
div 2);
6112 Target
.cY
:= Target
.Y
+ mon
.Obj
.Rect
.Y
+ (mon
.Obj
.Rect
.Height
div 2);
6113 Target
.Rect
:= mon
.Obj
.Rect
;
6114 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6115 Target
.Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6116 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6117 Target
.IsPlayer
:= False;
6124 begin // Öåëè íåò - îáíóëÿåì
6129 Target
.Visible
:= False;
6130 Target
.Line
:= False;
6131 Target
.IsPlayer
:= False;
6136 // Åñëè öåëü íå âèäèìà èëè íå íà ëèíèè îãíÿ, òî èùåì âñå âîçìîæíûå öåëè:
6137 if (not Target
.Line
) or (not Target
.Visible
) then
6141 for a
:= 0 to High(gPlayers
) do
6142 if (gPlayers
[a
] <> nil) and (gPlayers
[a
].Live
) and
6143 (gPlayers
[a
].FUID
<> FUID
) and
6144 (not SameTeam(FUID
, gPlayers
[a
].FUID
)) and
6145 (not gPlayers
[a
].NoTarget
) and
6146 (gPlayers
[a
].FMegaRulez
[MR_INVIS
] < gTime
) then
6148 if not TargetOnScreen(gPlayers
[a
].FObj
.X
+ PLAYER_RECT
.X
,
6149 gPlayers
[a
].FObj
.Y
+ PLAYER_RECT
.Y
) then
6152 x2
:= gPlayers
[a
].FObj
.X
+ PLAYER_RECT_CX
;
6153 y2
:= gPlayers
[a
].FObj
.Y
+ PLAYER_RECT_CY
;
6155 // Åñëè èãðîê íà ýêðàíå è íå ïðèêðûò ñòåíîé:
6156 if g_TraceVector(x1
, y1
, x2
, y2
) then
6158 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé:
6159 SetLength(targets
, Length(targets
)+1);
6160 with targets
[High(targets
)] do
6162 UID
:= gPlayers
[a
].FUID
;
6163 X
:= gPlayers
[a
].FObj
.X
;
6164 Y
:= gPlayers
[a
].FObj
.Y
;
6167 Rect
:= PLAYER_RECT
;
6168 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6169 Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6170 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6178 if vsMonster
and (gMonsters
<> nil) then
6179 for a
:= 0 to High(gMonsters
) do
6180 if (gMonsters
[a
] <> nil) and (gMonsters
[a
].Live
) and
6181 (gMonsters
[a
].MonsterType
<> MONSTER_BARREL
) then
6183 mon
:= gMonsters
[a
];
6185 if not TargetOnScreen(mon
.Obj
.X
+ mon
.Obj
.Rect
.X
,
6186 mon
.Obj
.Y
+ mon
.Obj
.Rect
.Y
) then
6189 x2
:= mon
.Obj
.X
+ mon
.Obj
.Rect
.X
+ (mon
.Obj
.Rect
.Width
div 2);
6190 y2
:= mon
.Obj
.Y
+ mon
.Obj
.Rect
.Y
+ (mon
.Obj
.Rect
.Height
div 2);
6192 // Åñëè ìîíñòð íà ýêðàíå è íå ïðèêðûò ñòåíîé:
6193 if g_TraceVector(x1
, y1
, x2
, y2
) then
6195 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé:
6196 SetLength(targets
, Length(targets
)+1);
6197 with targets
[High(targets
)] do
6204 Rect
:= mon
.Obj
.Rect
;
6205 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6206 Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6207 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6215 // Åñëè åñòü âîçìîæíûå öåëè:
6216 // (Âûáèðàåì ëó÷øóþ, ìåíÿåì îðóæèå è áåæèì ê íåé/îò íåå)
6217 if targets
<> nil then
6219 // Âûáèðàåì íàèëó÷øóþ öåëü:
6220 BestTarget
:= targets
[0];
6221 if Length(targets
) > 1 then
6222 for a
:= 1 to High(targets
) do
6223 if Compare(BestTarget
, targets
[a
]) = 1 then
6224 BestTarget
:= targets
[a
];
6226 // Åñëè ëó÷øàÿ öåëü "âèäíåå" òåêóùåé, òî òåêóùàÿ := ëó÷øàÿ:
6227 if ((not Target
.Visible
) and BestTarget
.Visible
and (Target
.UID
<> BestTarget
.UID
)) or
6228 ((not Target
.Line
) and BestTarget
.Line
and BestTarget
.Visible
) then
6230 Target
:= BestTarget
;
6232 if (Healthy() = 3) or ((Healthy() = 2)) then
6233 begin // Åñëè çäîðîâû - äîãîíÿåì
6234 if ((RunDirection() = D_LEFT
) and (Target
.X
> FObj
.X
)) then
6235 SetAIFlag('GORIGHT', '1');
6236 if ((RunDirection() = D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6237 SetAIFlag('GOLEFT', '1');
6240 begin // Åñëè ïîáèòû - óáåãàåì
6241 if ((RunDirection() = D_LEFT
) and (Target
.X
< FObj
.X
)) then
6242 SetAIFlag('GORIGHT', '1');
6243 if ((RunDirection() = D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6244 SetAIFlag('GOLEFT', '1');
6247 // Âûáèðàåì îðóæèå íà îñíîâå ðàññòîÿíèÿ è ïðèîðèòåòîâ:
6248 SelectWeapon(Abs(x1
-Target
.cX
));
6253 // (Äîãîíÿåì/óáåãàåì, ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëè)
6254 // (Åñëè öåëü äàëåêî, òî õâàòèò ñëåäèòü çà íåé)
6255 if Target
.UID
<> 0 then
6257 if not TargetOnScreen(Target
.X
+ Target
.Rect
.X
,
6258 Target
.Y
+ Target
.Rect
.Y
) then
6259 begin // Öåëü ñáåæàëà ñ "ýêðàíà"
6260 if (Healthy() = 3) or ((Healthy() = 2)) then
6261 begin // Åñëè çäîðîâû - äîãîíÿåì
6262 if ((RunDirection() = D_LEFT
) and (Target
.X
> FObj
.X
)) then
6263 SetAIFlag('GORIGHT', '1');
6264 if ((RunDirection() = D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6265 SetAIFlag('GOLEFT', '1');
6268 begin // Åñëè ïîáèòû - çàáûâàåì î öåëè è óáåãàåì
6270 if ((RunDirection() = D_LEFT
) and (Target
.X
< FObj
.X
)) then
6271 SetAIFlag('GORIGHT', '1');
6272 if ((RunDirection() = D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6273 SetAIFlag('GOLEFT', '1');
6277 begin // Öåëü ïîêà íà "ýêðàíå"
6278 // Åñëè öåëü íå çàãîðîæåíà ñòåíîé, òî îòìå÷àåì, êîãäà åå âèäåëè:
6279 if g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6280 FLastVisible
:= gTime
;
6281 // Åñëè ðàçíèöà âûñîò íå âåëèêà, òî äîãîíÿåì:
6282 if (Abs(FObj
.Y
-Target
.Y
) <= 128) then
6284 if ((RunDirection() = D_LEFT
) and (Target
.X
> FObj
.X
)) then
6285 SetAIFlag('GORIGHT', '1');
6286 if ((RunDirection() = D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6287 SetAIFlag('GOLEFT', '1');
6291 // Âûáèðàåì óãîë ââåðõ:
6292 if FDirection
= D_LEFT
then
6293 angle
:= ANGLE_LEFTUP
6295 angle
:= ANGLE_RIGHTUP
;
6297 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6298 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6300 // Åñëè ïðè óãëå ââåðõ ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
6301 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6302 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128), //96
6303 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6304 Target
.Rect
.Width
, Target
.Rect
.Height
) and
6305 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6306 begin // òî íóæíî ñòðåëÿòü ââåðõ
6307 SetAIFlag('NEEDFIRE', '1');
6308 SetAIFlag('NEEDSEEUP', '1');
6311 // Âûáèðàåì óãîë âíèç:
6312 if FDirection
= D_LEFT
then
6313 angle
:= ANGLE_LEFTDOWN
6315 angle
:= ANGLE_RIGHTDOWN
;
6317 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6318 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6320 // Åñëè ïðè óãëå âíèç ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
6321 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6322 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
6323 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6324 Target
.Rect
.Width
, Target
.Rect
.Height
) and
6325 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6326 begin // òî íóæíî ñòðåëÿòü âíèç
6327 SetAIFlag('NEEDFIRE', '1');
6328 SetAIFlag('NEEDSEEDOWN', '1');
6331 // Åñëè öåëü âèäíî è îíà íà òàêîé æå âûñîòå:
6332 if Target
.Visible
and
6333 (y1
+4 < Target
.Y
+Target
.Rect
.Y
+Target
.Rect
.Height
) and
6334 (y1
-4 > Target
.Y
+Target
.Rect
.Y
) then
6336 // Åñëè èäåì â ñòîðîíó öåëè, òî íàäî ñòðåëÿòü:
6337 if ((FDirection
= D_LEFT
) and (Target
.X
< FObj
.X
)) or
6338 ((FDirection
= D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6339 begin // òî íóæíî ñòðåëÿòü âïåðåä
6340 SetAIFlag('NEEDFIRE', '1');
6341 SetAIFlag('NEEDSEEDOWN', '');
6342 SetAIFlag('NEEDSEEUP', '');
6344 // Åñëè öåëü â ïðåäåëàõ "ýêðàíà" è ñëîæíîñòü ïîçâîëÿåò ïðûæêè ñáëèæåíèÿ:
6345 if Abs(FObj
.X
-Target
.X
) < Trunc(gPlayerScreenSize
.X
*0.75) then
6346 if GetRnd(FDifficult
.CloseJump
) then
6347 begin // òî åñëè ïîâåçåò - ïðûãàåì (îñîáåííî, åñëè áëèçêî)
6348 if Abs(FObj
.X
-Target
.X
) < 128 then
6352 if Random(a
) = 0 then
6353 SetAIFlag('NEEDJUMP', '1');
6357 // Åñëè öåëü âñå åùå åñòü:
6358 if Target
.UID
<> 0 then
6359 if gTime
-FLastVisible
> 2000 then // Åñëè âèäåëè äàâíî
6360 Target
.UID
:= 0 // òî çàáûòü öåëü
6361 else // Åñëè âèäåëè íåäàâíî
6362 begin // íî öåëü óáèëè
6363 if Target
.IsPlayer
then
6364 begin // Öåëü - èãðîê
6365 pla
:= g_Player_Get(Target
.UID
);
6366 if (pla
= nil) or (not pla
.Live
) or pla
.NoTarget
or
6367 (pla
.FMegaRulez
[MR_INVIS
] >= gTime
) then
6368 Target
.UID
:= 0; // òî çàáûòü öåëü
6371 begin // Öåëü - ìîíñòð
6372 mon
:= g_Monsters_Get(Target
.UID
);
6373 if (mon
= nil) or (not mon
.Live
) then
6374 Target
.UID
:= 0; // òî çàáûòü öåëü
6377 end; // if Target.UID <> 0
6379 FTargetUID
:= Target
.UID
;
6381 // Åñëè âîçìîæíûõ öåëåé íåò:
6382 // (Àòàêà ÷åãî-íèáóäü ñëåâà èëè ñïðàâà)
6383 if targets
= nil then
6384 if GetAIFlag('ATTACKLEFT') <> '' then
6385 begin // Åñëè íóæíî àòàêîâàòü íàëåâî
6386 RemoveAIFlag('ATTACKLEFT');
6388 SetAIFlag('NEEDJUMP', '1');
6390 if RunDirection() = D_RIGHT
then
6391 begin // Èäåì íå â òó ñòîðîíó
6392 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
6393 begin // Åñëè çäîðîâû, òî, âîçìîæíî, ñòðåëÿåì áåæèì âëåâî è ñòðåëÿåì
6394 SetAIFlag('NEEDFIRE', '1');
6395 SetAIFlag('GOLEFT', '1');
6399 begin // Èäåì â íóæíóþ ñòîðîíó
6400 if GetRnd(FDifficult
.InvisFire
) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
6401 SetAIFlag('NEEDFIRE', '1');
6402 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
6403 SetAIFlag('GORIGHT', '1');
6407 if GetAIFlag('ATTACKRIGHT') <> '' then
6408 begin // Åñëè íóæíî àòàêîâàòü íàïðàâî
6409 RemoveAIFlag('ATTACKRIGHT');
6411 SetAIFlag('NEEDJUMP', '1');
6413 if RunDirection() = D_LEFT
then
6414 begin // Èäåì íå â òó ñòîðîíó
6415 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
6416 begin // Åñëè çäîðîâû, òî, âîçìîæíî, áåæèì âïðàâî è ñòðåëÿåì
6417 SetAIFlag('NEEDFIRE', '1');
6418 SetAIFlag('GORIGHT', '1');
6423 if GetRnd(FDifficult
.InvisFire
) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
6424 SetAIFlag('NEEDFIRE', '1');
6425 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
6426 SetAIFlag('GOLEFT', '1');
6430 //HACK! (does it belongs there?)
6431 RealizeCurrentWeapon();
6433 // Åñëè åñòü âîçìîæíûå öåëè:
6434 // (Ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëÿì)
6435 if (targets
<> nil) and (GetAIFlag('NEEDFIRE') <> '') then
6436 for a
:= 0 to High(targets
) do
6438 // Åñëè ìîæåì ñòðåëÿòü ïî äèàãîíàëè:
6439 if GetRnd(FDifficult
.DiagFire
) then
6441 // Èùåì öåëü ñâåðõó è ñòðåëÿåì, åñëè åñòü:
6442 if FDirection
= D_LEFT
then
6443 angle
:= ANGLE_LEFTUP
6445 angle
:= ANGLE_RIGHTUP
;
6447 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6448 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6450 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6451 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
6452 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6453 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
6454 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
6456 SetAIFlag('NEEDFIRE', '1');
6457 SetAIFlag('NEEDSEEUP', '1');
6460 // Èùåì öåëü ñíèçó è ñòðåëÿåì, åñëè åñòü:
6461 if FDirection
= D_LEFT
then
6462 angle
:= ANGLE_LEFTDOWN
6464 angle
:= ANGLE_RIGHTDOWN
;
6466 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6467 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6469 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6470 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
6471 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6472 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
6473 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
6475 SetAIFlag('NEEDFIRE', '1');
6476 SetAIFlag('NEEDSEEDOWN', '1');
6480 // Åñëè öåëü "ïåðåä íîñîì", òî ñòðåëÿåì:
6481 if targets
[a
].Line
and targets
[a
].Visible
and
6482 (((FDirection
= D_LEFT
) and (targets
[a
].X
< FObj
.X
)) or
6483 ((FDirection
= D_RIGHT
) and (targets
[a
].X
> FObj
.X
))) then
6485 SetAIFlag('NEEDFIRE', '1');
6490 // Åñëè ëåòèò ïóëÿ, òî, âîçìîæíî, ïîäïðûãèâàåì:
6491 if g_Weapon_Danger(FUID
, FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
,
6492 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
,
6493 40+GetInterval(FDifficult
.Cover
, 40)) then
6494 SetAIFlag('NEEDJUMP', '1');
6496 // Åñëè êîí÷èëèñü ïàòîðíû, òî íóæíî ñìåíèòü îðóæèå:
6497 ammo
:= GetAmmoByWeapon(FCurrWeap
);
6498 if ((FCurrWeap
= WEAPON_SHOTGUN2
) and (ammo
< 2)) or
6499 ((FCurrWeap
= WEAPON_BFG
) and (ammo
< 40)) or
6501 SetAIFlag('SELECTWEAPON', '1');
6503 // Åñëè íóæíî ñìåíèòü îðóæèå, òî âûáèðàåì íóæíîå:
6504 if GetAIFlag('SELECTWEAPON') = '1' then
6507 RemoveAIFlag('SELECTWEAPON');
6511 procedure TBot
.Update();
6524 // Ïðîâåðÿåì, îòêëþ÷¸í ëè AI áîòîâ
6525 if (g_debug_BotAIOff
= 1) and (Team
= TEAM_RED
) then
6527 if (g_debug_BotAIOff
= 2) and (Team
= TEAM_BLUE
) then
6529 if g_debug_BotAIOff
= 3 then
6539 RealizeCurrentWeapon();
6546 procedure TBot
.ReleaseKey(Key
: Byte);
6555 function TBot
.KeyPressed(Key
: Word): Boolean;
6557 Result
:= FKeys
[Key
].Pressed
;
6560 function TBot
.GetAIFlag(fName
: String20
): String20
;
6566 fName
:= LowerCase(fName
);
6568 if FAIFlags
<> nil then
6569 for a
:= 0 to High(FAIFlags
) do
6570 if LowerCase(FAIFlags
[a
].Name
) = fName
then
6572 Result
:= FAIFlags
[a
].Value
;
6577 procedure TBot
.RemoveAIFlag(fName
: String20
);
6581 if FAIFlags
= nil then Exit
;
6583 fName
:= LowerCase(fName
);
6585 for a
:= 0 to High(FAIFlags
) do
6586 if LowerCase(FAIFlags
[a
].Name
) = fName
then
6588 if a
<> High(FAIFlags
) then
6589 for b
:= a
to High(FAIFlags
)-1 do
6590 FAIFlags
[b
] := FAIFlags
[b
+1];
6592 SetLength(FAIFlags
, Length(FAIFlags
)-1);
6597 procedure TBot
.SetAIFlag(fName
, fValue
: String20
);
6605 fName
:= LowerCase(fName
);
6607 if FAIFlags
<> nil then
6608 for a
:= 0 to High(FAIFlags
) do
6609 if LowerCase(FAIFlags
[a
].Name
) = fName
then
6615 if ok
then FAIFlags
[a
].Value
:= fValue
6618 SetLength(FAIFlags
, Length(FAIFlags
)+1);
6619 with FAIFlags
[High(FAIFlags
)] do
6627 procedure TBot
.UpdateMove
;
6629 procedure GoLeft(Time
: Word = 1);
6631 ReleaseKey(KEY_LEFT
);
6632 ReleaseKey(KEY_RIGHT
);
6633 PressKey(KEY_LEFT
, Time
);
6634 SetDirection(D_LEFT
);
6637 procedure GoRight(Time
: Word = 1);
6639 ReleaseKey(KEY_LEFT
);
6640 ReleaseKey(KEY_RIGHT
);
6641 PressKey(KEY_RIGHT
, Time
);
6642 SetDirection(D_RIGHT
);
6645 function Rnd(a
: Word): Boolean;
6647 Result
:= Random(a
) = 0;
6650 procedure Turn(Time
: Word = 1200);
6652 if RunDirection() = D_LEFT
then GoRight(Time
) else GoLeft(Time
);
6657 ReleaseKey(KEY_LEFT
);
6658 ReleaseKey(KEY_RIGHT
);
6661 function CanRunLeft(): Boolean;
6663 Result
:= not CollideLevel(-1, 0);
6666 function CanRunRight(): Boolean;
6668 Result
:= not CollideLevel(1, 0);
6671 function CanRun(): Boolean;
6673 if RunDirection() = D_LEFT
then Result
:= CanRunLeft() else Result
:= CanRunRight();
6676 procedure Jump(Time
: Word = 30);
6678 PressKey(KEY_JUMP
, Time
);
6681 function NearHole(): Boolean;
6685 { TODO 5 : Ëåñòíèöû }
6686 sx
:= IfThen(RunDirection() = D_LEFT
, -1, 1);
6687 for x
:= 1 to PLAYER_RECT
.Width
do
6688 if (not StayOnStep(x
*sx
, 0)) and
6689 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
6690 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
6699 function BorderHole(): Boolean;
6703 { TODO 5 : Ëåñòíèöû }
6704 sx
:= IfThen(RunDirection() = D_LEFT
, -1, 1);
6705 for x
:= 1 to PLAYER_RECT
.Width
do
6706 if (not StayOnStep(x
*sx
, 0)) and
6707 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
6708 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
6710 for xx
:= x
to x
+32 do
6711 if CollideLevel(xx
*sx
, PLAYER_RECT
.Height
) then
6721 function NearDeepHole(): Boolean;
6727 sx
:= IfThen(RunDirection() = D_LEFT
, -1, 1);
6730 for x
:= 1 to PLAYER_RECT
.Width
do
6731 if (not StayOnStep(x
*sx
, 0)) and
6732 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
6733 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
6735 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
6737 if CollideLevel(x
*sx
, PLAYER_RECT
.Height
*y
) then Exit
;
6742 end else Result
:= False;
6745 function OverDeepHole(): Boolean;
6752 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
6754 if CollideLevel(0, PLAYER_RECT
.Height
*y
) then Exit
;
6761 function OnGround(): Boolean;
6763 Result
:= StayOnStep(0, 0) or CollideLevel(0, 1);
6766 function OnLadder(): Boolean;
6768 Result
:= FullInStep(0, 0);
6771 function BelowLadder(): Boolean;
6773 Result
:= (FullInStep(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) and
6774 not CollideLevel(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
6775 (FullInStep(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) and
6776 not CollideLevel(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
6779 function BelowLiftUp(): Boolean;
6781 Result
:= ((FullInLift(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) = -1) and
6782 not CollideLevel(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
6783 ((FullInLift(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) = -1) and
6784 not CollideLevel(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
6787 function OnTopLift(): Boolean;
6789 Result
:= (FullInLift(0, 0) = -1) and (FullInLift(0, -32) = 0);
6792 function CanJumpOver(): Boolean;
6796 sx
:= IfThen(RunDirection() = D_LEFT
, -1, 1);
6800 if not CollideLevel(sx
, 0) then Exit
;
6802 for y
:= 1 to BOT_MAXJUMP
do
6803 if CollideLevel(0, -y
) then Exit
else
6804 if not CollideLevel(sx
, -y
) then
6811 function CanJumpUp(Dist
: ShortInt): Boolean;
6818 if CollideLevel(Dist
, 0) then Exit
;
6821 for y
:= 0 to BOT_MAXJUMP
do
6822 if CollideLevel(Dist
, -y
) then
6831 for yy
:= y
+1 to BOT_MAXJUMP
do
6832 if not CollideLevel(Dist
, -yy
) then
6841 for y
:= 0 to BOT_MAXJUMP
do
6842 if CollideLevel(0, -y
) then
6850 if y
< yy
then Exit
;
6855 function IsSafeTrigger(): Boolean;
6860 if gTriggers
= nil then
6862 for a
:= 0 to High(gTriggers
) do
6863 if Collide(gTriggers
[a
].X
,
6866 gTriggers
[a
].Height
) and
6867 (gTriggers
[a
].TriggerType
in [TRIGGER_EXIT
, TRIGGER_CLOSEDOOR
,
6868 TRIGGER_CLOSETRAP
, TRIGGER_TRAP
,
6869 TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
,
6870 TRIGGER_ONOFF
, TRIGGER_SPAWNMONSTER
,
6871 TRIGGER_DAMAGE
, TRIGGER_SHOT
]) then
6876 // Âîçìîæíî, íàæèìàåì êíîïêó:
6877 if Rnd(16) and IsSafeTrigger() then
6880 // Åñëè ïîä ëèôòîì èëè ñòóïåíüêàìè, òî, âîçìîæíî, ïðûãàåì:
6881 if OnLadder() or ((BelowLadder() or BelowLiftUp()) and Rnd(8)) then
6883 ReleaseKey(KEY_LEFT
);
6884 ReleaseKey(KEY_RIGHT
);
6888 // Èäåì âëåâî, åñëè íàäî áûëî:
6889 if GetAIFlag('GOLEFT') <> '' then
6891 RemoveAIFlag('GOLEFT');
6892 if CanRunLeft() then
6896 // Èäåì âïðàâî, åñëè íàäî áûëî:
6897 if GetAIFlag('GORIGHT') <> '' then
6899 RemoveAIFlag('GORIGHT');
6900 if CanRunRight() then
6904 // Åñëè âûëåòåëè çà êàðòó, òî ïðîáóåì âåðíóòüñÿ:
6905 if FObj
.X
< -32 then
6908 if FObj
.X
+32 > gMapInfo
.Width
then
6911 // Ïðûãàåì, åñëè íàäî áûëî:
6912 if GetAIFlag('NEEDJUMP') <> '' then
6915 RemoveAIFlag('NEEDJUMP');
6918 // Ñìîòðèì ââåðõ, åñëè íàäî áûëî:
6919 if GetAIFlag('NEEDSEEUP') <> '' then
6922 ReleaseKey(KEY_DOWN
);
6923 PressKey(KEY_UP
, 20);
6924 RemoveAIFlag('NEEDSEEUP');
6927 // Ñìîòðèì âíèç, åñëè íàäî áûëî:
6928 if GetAIFlag('NEEDSEEDOWN') <> '' then
6931 ReleaseKey(KEY_DOWN
);
6932 PressKey(KEY_DOWN
, 20);
6933 RemoveAIFlag('NEEDSEEDOWN');
6936 // Åñëè íóæíî áûëî â äûðó è ìû íå íà çåìëå, òî ïîêîðíî ëåòèì:
6937 if GetAIFlag('GOINHOLE') <> '' then
6938 if not OnGround() then
6940 ReleaseKey(KEY_LEFT
);
6941 ReleaseKey(KEY_RIGHT
);
6942 RemoveAIFlag('GOINHOLE');
6943 SetAIFlag('FALLINHOLE', '1');
6946 // Åñëè ïàäàëè è äîñòèãëè çåìëè, òî õâàòèò ïàäàòü:
6947 if GetAIFlag('FALLINHOLE') <> '' then
6949 RemoveAIFlag('FALLINHOLE');
6951 // Åñëè ëåòåëè ïðÿìî è ñåé÷àñ íå íà ëåñòíèöå èëè íà âåðøèíå ëèôòà, òî îòõîäèì â ñòîðîíó:
6952 if not (KeyPressed(KEY_LEFT
) or KeyPressed(KEY_RIGHT
)) then
6953 if GetAIFlag('FALLINHOLE') = '' then
6954 if (not OnLadder()) or (FObj
.Vel
.Y
>= 0) or (OnTopLift()) then
6960 // Åñëè íà çåìëå è ìîæíî ïîäïðûãíóòü, òî, âîçìîæíî, ïðûãàåì:
6962 CanJumpUp(IfThen(RunDirection() = D_LEFT
, -1, 1)*32) and
6966 // Åñëè íà çåìëå è âîçëå äûðû (ãëóáèíà > 2 ðîñòîâ èãðîêà):
6967 if OnGround() and NearHole() then
6968 if NearDeepHole() then // Åñëè ýòî áåçäíà
6970 0..3: Turn(); // Áåæèì îáðàòíî
6971 4: Jump(); // Ïðûãàåì
6972 5: begin // Ïðûãàåì îáðàòíî
6977 else // Ýòî íå áåçäíà è ìû åùå íå ëåòèì òóäà
6978 if GetAIFlag('GOINHOLE') = '' then
6980 0: Turn(); // Íå íóæíî òóäà
6981 1: Jump(); // Âäðóã ïîâåçåò - ïðûãàåì
6982 else // Åñëè ÿìà ñ ãðàíèöåé, òî ïðè ñëó÷àå ìîæíî òóäà ïðûãíóòü
6983 if BorderHole() then
6984 SetAIFlag('GOINHOLE', '1');
6987 // Åñëè íà çåìëå, íî íåêóäà èäòè:
6988 if (not CanRun()) and OnGround() then
6990 // Åñëè ìû íà ëåñòíèöå èëè ìîæíî ïåðåïðûãíóòü, òî ïðûãàåì:
6991 if CanJumpOver() or OnLadder() then
6993 else // èíà÷å ïîïûòàåìñÿ â äðóãóþ ñòîðîíó
6994 if Random(2) = 0 then
6996 if IsSafeTrigger() then
7002 // Îñòàëîñü ìàëî âîçäóõà:
7003 if FAir
< 36 * 2 then
7006 // Âûáèðàåìñÿ èç êèñëîòû, åñëè íåò êîñòþìà, îáîæãëèñü, èëè ìàëî çäîðîâüÿ:
7007 if (FMegaRulez
[MR_SUIT
] < gTime
) and ((FLastHit
= HIT_ACID
) or (Healthy() <= 1)) then
7008 if BodyInAcid(0, 0) then
7012 function TBot
.FullInStep(XInc
, YInc
: Integer): Boolean;
7014 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
7015 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_STEP
, False);
7018 {function TBot.NeedItem(Item: Byte): Byte;
7023 procedure TBot
.SelectWeapon(Dist
: Integer);
7027 function HaveAmmo(weapon
: Byte): Boolean;
7030 WEAPON_PISTOL
: Result
:= FAmmo
[A_BULLETS
] >= 1;
7031 WEAPON_SHOTGUN1
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7032 WEAPON_SHOTGUN2
: Result
:= FAmmo
[A_SHELLS
] >= 2;
7033 WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
] >= 10;
7034 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
] >= 1;
7035 WEAPON_PLASMA
: Result
:= FAmmo
[A_CELLS
] >= 10;
7036 WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
] >= 40;
7037 WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7038 else Result
:= True;
7043 if Dist
= -1 then Dist
:= BOT_LONGDIST
;
7045 if Dist
> BOT_LONGDIST
then
7046 begin // Äàëüíèé áîé
7048 if FWeapon
[FDifficult
.WeaponPrior
[a
]] and HaveAmmo(FDifficult
.WeaponPrior
[a
]) then
7050 FSelectedWeapon
:= FDifficult
.WeaponPrior
[a
];
7054 else //if Dist > BOT_UNSAFEDIST then
7055 begin // Áëèæíèé áîé
7057 if FWeapon
[FDifficult
.CloseWeaponPrior
[a
]] and HaveAmmo(FDifficult
.CloseWeaponPrior
[a
]) then
7059 FSelectedWeapon
:= FDifficult
.CloseWeaponPrior
[a
];
7066 if FWeapon[FDifficult.SafeWeaponPrior[a]] and HaveAmmo(FDifficult.SafeWeaponPrior[a]) then
7068 FSelectedWeapon := FDifficult.SafeWeaponPrior[a];
7074 function TBot
.PickItem(ItemType
: Byte; force
: Boolean; var remove
: Boolean): Boolean;
7076 Result
:= inherited PickItem(ItemType
, force
, remove
);
7078 if Result
then SetAIFlag('SELECTWEAPON', '1');
7081 function TBot
.Heal(value
: Word; Soft
: Boolean): Boolean;
7083 Result
:= inherited Heal(value
, Soft
);
7086 function TBot
.Healthy(): Byte;
7088 if FMegaRulez
[MR_INVUL
] >= gTime
then Result
:= 3
7089 else if (FHealth
> 80) or ((FHealth
> 50) and (FArmor
> 20)) then Result
:= 3
7090 else if (FHealth
> 50) then Result
:= 2
7091 else if (FHealth
> 20) then Result
:= 1
7095 function TBot
.TargetOnScreen(TX
, TY
: Integer): Boolean;
7097 Result
:= (Abs(FObj
.X
-TX
) <= Trunc(gPlayerScreenSize
.X
*0.6)) and
7098 (Abs(FObj
.Y
-TY
) <= Trunc(gPlayerScreenSize
.Y
*0.6));
7101 procedure TBot
.OnDamage(Angle
: SmallInt);
7109 if (Angle
= 0) or (Angle
= 180) then
7112 if (g_GetUIDType(FLastSpawnerUID
) = UID_PLAYER
) and
7113 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
) then
7115 pla
:= g_Player_Get(FLastSpawnerUID
);
7116 ok
:= not TargetOnScreen(pla
.FObj
.X
+ PLAYER_RECT
.X
,
7117 pla
.FObj
.Y
+ PLAYER_RECT
.Y
);
7120 if (g_GetUIDType(FLastSpawnerUID
) = UID_MONSTER
) and
7121 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
) then
7123 mon
:= g_Monsters_Get(FLastSpawnerUID
);
7124 ok
:= not TargetOnScreen(mon
.Obj
.X
+ mon
.Obj
.Rect
.X
,
7125 mon
.Obj
.Y
+ mon
.Obj
.Rect
.Y
);
7130 SetAIFlag('ATTACKLEFT', '1')
7132 SetAIFlag('ATTACKRIGHT', '1');
7136 function TBot
.RunDirection(): TDirection
;
7138 if Abs(Vel
.X
) >= 1 then
7140 if Vel
.X
> 0 then Result
:= D_RIGHT
else Result
:= D_LEFT
;
7142 Result
:= FDirection
;
7145 function TBot
.GetRnd(a
: Byte): Boolean;
7147 if a
= 0 then Result
:= False
7148 else if a
= 255 then Result
:= True
7149 else Result
:= Random(256) > 255-a
;
7152 function TBot
.GetInterval(a
: Byte; radius
: SmallInt): SmallInt;
7154 Result
:= Round((255-a
)/255*radius
*(Random(2)-1));
7157 procedure TBot
.SaveState(var Mem
: TBinMemoryWriter
);
7163 inherited SaveState(Mem
);
7165 // Âûáðàííîå îðóæèå:
7166 Mem
.WriteByte(FSelectedWeapon
);
7168 Mem
.WriteWord(FTargetUID
);
7169 // Âðåìÿ ïîòåðè öåëè:
7170 Mem
.WriteDWORD(FLastVisible
);
7171 // Êîëè÷åñòâî ôëàãîâ ÈÈ:
7172 dw
:= Length(FAIFlags
);
7175 for i
:= 0 to Integer(dw
)-1 do
7177 Mem
.WriteString(FAIFlags
[i
].Name
, 20);
7178 Mem
.WriteString(FAIFlags
[i
].Value
, 20);
7180 // Íàñòðîéêè ñëîæíîñòè:
7182 Mem
.WriteMemory(p
, SizeOf(TDifficult
));
7185 procedure TBot
.LoadState(var Mem
: TBinMemoryReader
);
7191 inherited LoadState(Mem
);
7193 // Âûáðàííîå îðóæèå:
7194 Mem
.ReadByte(FSelectedWeapon
);
7196 Mem
.ReadWord(FTargetUID
);
7197 // Âðåìÿ ïîòåðè öåëè:
7198 Mem
.ReadDWORD(FLastVisible
);
7199 // Êîëè÷åñòâî ôëàãîâ ÈÈ:
7201 SetLength(FAIFlags
, dw
);
7203 for i
:= 0 to Integer(dw
)-1 do
7205 Mem
.ReadString(FAIFlags
[i
].Name
);
7206 Mem
.ReadString(FAIFlags
[i
].Value
);
7208 // Íàñòðîéêè ñëîæíîñòè:
7209 Mem
.ReadMemory(p
, dw
);
7210 if dw
<> SizeOf(TDifficult
) then
7212 raise EBinSizeError
.Create('TBot.LoadState: Wrong FDifficult Size');
7214 FDifficult
:= TDifficult(p
^);