1 (* Copyright (C) DooM 2D:Forever Developers
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 3 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22 e_graphics
, g_playermodel
, g_basic
, g_textures
,
23 g_weapons
, g_phys
, g_sound
, g_saveload
, MAPSTRUCT
,
73 ANGLE_NONE
= Low(SmallInt);
75 CORPSE_STATE_REMOVEME
= 0;
76 CORPSE_STATE_NORMAL
= 1;
77 CORPSE_STATE_MESS
= 2;
79 PLAYER_RECT
: TRectWH
= (X
:15; Y
:12; Width
:34; Height
:52);
80 PLAYER_RECT_CX
= 15+(34 div 2);
81 PLAYER_RECT_CY
= 12+(52 div 2);
82 PLAYER_CORPSERECT
: TRectWH
= (X
:15; Y
:48; Width
:34; Height
:16);
85 PLAYER_HP_LIMIT
= 200;
87 PLAYER_AP_LIMIT
= 200;
90 PLAYER1_DEF_COLOR
: TRGB
= (R
:64; G
:175; B
:48);
91 PLAYER2_DEF_COLOR
: TRGB
= (R
:96; G
:96; B
:96);
107 TPlayerStatArray
= Array of TPlayerStat
;
109 TPlayerSavedState
= record
117 Ammo
: Array [A_BULLETS
..A_CELLS
] of Word;
118 MaxAmmo
: Array [A_BULLETS
..A_CELLS
] of Word;
119 Weapon
: Array [WEAPON_KASTET
..WEAPON_SUPERPULEMET
] of Boolean;
120 Rulez
: Set of R_ITEM_BACKPACK
..R_BERSERK
;
129 TPlayer
= class (TObject
)
137 FDirection
: TDirection
;
145 FMonsterKills
: Integer;
151 FCanJetpack
: Boolean;
157 FNextWeapDelay
: Byte; // frames
158 FBFGFireCounter
: SmallInt;
159 FLastSpawnerUID
: Word;
163 FSpectatePlayer
: Integer;
165 FSavedState
: TPlayerSavedState
;
167 FModel
: TPlayerModel
;
170 FActionForce
: Boolean;
171 FActionChanged
: Boolean;
173 FFireAngle
: SmallInt;
175 FShellTimer
: Integer;
177 FSawSound
: TPlayableSound
;
178 FSawSoundIdle
: TPlayableSound
;
179 FSawSoundHit
: TPlayableSound
;
180 FSawSoundSelect
: TPlayableSound
;
181 FJetSoundOn
: TPlayableSound
;
182 FJetSoundOff
: TPlayableSound
;
183 FJetSoundFly
: TPlayableSound
;
187 FJustTeleported
: Boolean;
190 function CollideLevel(XInc
, YInc
: Integer): Boolean;
191 function StayOnStep(XInc
, YInc
: Integer): Boolean;
192 function HeadInLiquid(XInc
, YInc
: Integer): Boolean;
193 function BodyInLiquid(XInc
, YInc
: Integer): Boolean;
194 function BodyInAcid(XInc
, YInc
: Integer): Boolean;
195 function FullInLift(XInc
, YInc
: Integer): Integer;
196 {procedure CollideItem();}
197 procedure FlySmoke(Times
: DWORD
= 1);
198 function GetAmmoByWeapon(Weapon
: Byte): Word;
199 procedure SetAction(Action
: Byte; Force
: Boolean = False);
200 procedure OnDamage(Angle
: SmallInt); virtual;
201 function firediry(): Integer;
203 procedure Run(Direction
: TDirection
);
204 procedure NextWeapon();
205 procedure PrevWeapon();
212 procedure cycleWeapon (dir
: Integer);
213 function getNextWeaponIndex (): Byte; // return 255 for "no switch"
214 procedure resetWeaponQueue ();
215 function hasAmmoForWeapon (weapon
: Byte): Boolean;
218 FDamageBuffer
: Integer;
220 FAmmo
: Array [A_BULLETS
..A_CELLS
] of Word;
221 FMaxAmmo
: Array [A_BULLETS
..A_CELLS
] of Word;
222 FWeapon
: Array [WEAPON_KASTET
..WEAPON_SUPERPULEMET
] of Boolean;
223 FRulez
: Set of R_ITEM_BACKPACK
..R_BERSERK
;
225 FMegaRulez
: Array [MR_SUIT
..MR_MAX
] of DWORD
;
226 FReloading
: Array [WEAPON_KASTET
..WEAPON_SUPERPULEMET
] of Word;
227 FTime
: Array [T_RESPAWN
..T_FLAGCAP
] of DWORD
;
228 FKeys
: Array [KEY_LEFT
..KEY_CHAT
] of TKeyState
;
230 FPreferredTeam
: Byte;
233 FWantsInGame
: Boolean;
237 FActualModelName
: string;
243 constructor Create(); virtual;
244 destructor Destroy(); override;
245 procedure Respawn(Silent
: Boolean; Force
: Boolean = False); virtual;
246 function GetRespawnPoint(): Byte;
247 procedure PressKey(Key
: Byte; Time
: Word = 1);
248 procedure ReleaseKeys();
249 procedure SetModel(ModelName
: String);
250 procedure SetColor(Color
: TRGB
);
251 procedure SetWeapon(W
: Byte);
252 function IsKeyPressed(K
: Byte): Boolean;
253 function GetKeys(): Byte;
254 function PickItem(ItemType
: Byte; respawn
: Boolean; var remove
: Boolean): Boolean; virtual;
255 function Collide(X
, Y
: Integer; Width
, Height
: Word): Boolean; overload
;
256 function Collide(Panel
: TPanel
): Boolean; overload
;
257 function Collide(X
, Y
: Integer): Boolean; overload
;
258 procedure SetDirection(Direction
: TDirection
);
259 procedure GetSecret();
260 function TeleportTo(X
, Y
: Integer; silent
: Boolean; dir
: Byte): Boolean;
262 procedure Push(vx
, vy
: Integer);
263 procedure ChangeModel(ModelName
: String);
264 procedure SwitchTeam
;
265 procedure ChangeTeam(Team
: Byte);
267 function GetFlag(Flag
: Byte): Boolean;
268 procedure SetFlag(Flag
: Byte);
269 function DropFlag(): Boolean;
270 procedure AllRulez(Health
: Boolean);
271 procedure RestoreHealthArmor();
272 procedure FragCombo();
273 procedure GiveItem(ItemType
: Byte);
274 procedure Damage(value
: Word; SpawnerUID
: Word; vx
, vy
: Integer; t
: Byte); virtual;
275 function Heal(value
: Word; Soft
: Boolean): Boolean; virtual;
276 procedure MakeBloodVector(Count
: Word; VelX
, VelY
: Integer);
277 procedure MakeBloodSimple(Count
: Word);
278 procedure Kill(KillType
: Byte; SpawnerUID
: Word; t
: Byte);
279 procedure Reset(Force
: Boolean);
280 procedure Spectate(NoMove
: Boolean = False);
281 procedure SwitchNoClip
;
282 procedure SoftReset();
283 procedure Draw(); virtual;
284 procedure DrawPain();
285 procedure DrawPickup();
286 procedure DrawRulez();
288 procedure DrawBubble();
290 procedure Update(); virtual;
291 procedure RememberState();
292 procedure RecallState();
293 procedure SaveState(var Mem
: TBinMemoryWriter
); virtual;
294 procedure LoadState(var Mem
: TBinMemoryReader
); virtual;
295 procedure PauseSounds(Enable
: Boolean);
296 procedure NetFire(Wpn
: Byte; X
, Y
, AX
, AY
: Integer; WID
: Integer = -1);
297 procedure DoLerp(Level
: Integer = 2);
298 procedure SetLerp(XTo
, YTo
: Integer);
299 procedure QueueWeaponSwitch(Weapon
: Byte);
300 procedure RealizeCurrentWeapon();
302 procedure JetpackOff
;
304 property Name
: String read FName write FName
;
305 property Model
: TPlayerModel read FModel
;
306 property Health
: Integer read FHealth write FHealth
;
307 property Lives
: Byte read FLives write FLives
;
308 property Armor
: Integer read FArmor write FArmor
;
309 property Air
: Integer read FAir write FAir
;
310 property JetFuel
: Integer read FJetFuel write FJetFuel
;
311 property Frags
: Integer read FFrags write FFrags
;
312 property Death
: Integer read FDeath write FDeath
;
313 property Kills
: Integer read FKills write FKills
;
314 property CurrWeap
: Byte read FCurrWeap write FCurrWeap
;
315 property MonsterKills
: Integer read FMonsterKills write FMonsterKills
;
316 property Secrets
: Integer read FSecrets
;
317 property GodMode
: Boolean read FGodMode write FGodMode
;
318 property NoTarget
: Boolean read FNoTarget write FNoTarget
;
319 property NoReload
: Boolean read FNoReload write FNoReload
;
320 property Live
: Boolean read FLive write FLive
;
321 property Flag
: Byte read FFlag
;
322 property Team
: Byte read FTeam write FTeam
;
323 property Direction
: TDirection read FDirection
;
324 property GameX
: Integer read FObj
.X write FObj
.X
;
325 property GameY
: Integer read FObj
.Y write FObj
.Y
;
326 property GameVelX
: Integer read FObj
.Vel
.X write FObj
.Vel
.X
;
327 property GameVelY
: Integer read FObj
.Vel
.Y write FObj
.Vel
.Y
;
328 property GameAccelX
: Integer read FObj
.Accel
.X write FObj
.Accel
.X
;
329 property GameAccelY
: Integer read FObj
.Accel
.Y write FObj
.Accel
.Y
;
330 property Vel
: TPoint2i read FObj
.Vel
;
331 property Obj
: TObj read FObj
;
332 property IncCam
: Integer read FIncCam write FIncCam
;
333 property UID
: Word read FUID write FUID
;
334 property JustTeleported
: Boolean read FJustTeleported write FJustTeleported
;
335 property NetTime
: LongWord read FNetTime write FNetTime
;
345 WeaponPrior
: Array [WEAPON_KASTET
..WEAPON_SUPERPULEMET
] of Byte;
346 CloseWeaponPrior
: Array [WEAPON_KASTET
..WEAPON_SUPERPULEMET
] of Byte;
347 //SafeWeaponPrior: Array [WEAPON_KASTET..WEAPON_SUPERPULEMET] of Byte;
355 TBot
= class (TPlayer
)
357 FSelectedWeapon
: Byte;
360 FAIFlags
: Array of TAIFlag
;
361 FDifficult
: TDifficult
;
363 function GetRnd(a
: Byte): Boolean;
364 function GetInterval(a
: Byte; radius
: SmallInt): SmallInt;
365 function RunDirection(): TDirection
;
366 function FullInStep(XInc
, YInc
: Integer): Boolean;
367 //function NeedItem(Item: Byte): Byte;
368 procedure SelectWeapon(Dist
: Integer);
369 procedure SetAIFlag(fName
, fValue
: String20
);
370 function GetAIFlag(fName
: String20
): String20
;
371 procedure RemoveAIFlag(fName
: String20
);
372 function Healthy(): Byte;
373 procedure UpdateMove();
374 procedure UpdateCombat();
375 function KeyPressed(Key
: Word): Boolean;
376 procedure ReleaseKey(Key
: Byte);
377 function TargetOnScreen(TX
, TY
: Integer): Boolean;
378 procedure OnDamage(Angle
: SmallInt); override;
381 procedure Respawn(Silent
: Boolean; Force
: Boolean = False); override;
382 constructor Create(); override;
383 destructor Destroy(); override;
384 procedure Draw(); override;
385 function PickItem(ItemType
: Byte; force
: Boolean; var remove
: Boolean): Boolean; override;
386 function Heal(value
: Word; Soft
: Boolean): Boolean; override;
387 procedure Update(); override;
388 procedure SaveState(var Mem
: TBinMemoryWriter
); override;
389 procedure LoadState(var Mem
: TBinMemoryReader
); override;
411 TCorpse
= class (TObject
)
419 FAnimation
: TAnimation
;
420 FAnimationMask
: TAnimation
;
423 constructor Create(X
, Y
: Integer; ModelName
: String; aMess
: Boolean);
424 destructor Destroy(); override;
425 procedure Damage(Value
: Word; vx
, vy
: Integer);
428 procedure SaveState(var Mem
: TBinMemoryWriter
);
429 procedure LoadState(var Mem
: TBinMemoryReader
);
431 property Obj
: TObj read FObj
;
432 property State
: Byte read FState
;
433 property Mess
: Boolean read FMess
;
436 TTeamStat
= Array [TEAM_RED
..TEAM_BLUE
] of
442 gPlayers
: Array of TPlayer
;
443 gCorpses
: Array of TCorpse
;
444 gGibs
: Array of TGib
;
445 gShells
: Array of TShell
;
446 gTeamStat
: TTeamStat
;
447 gFly
: Boolean = False;
448 gAimLine
: Boolean = False;
449 gChatBubble
: Byte = 0;
453 MAX_RUNVEL
: Integer = 8;
454 VEL_JUMP
: Integer = 10;
455 SHELL_TIMEOUT
: Cardinal = 60000;
457 function Lerp(X
, Y
, Factor
: Integer): Integer;
459 procedure g_Gibs_SetMax(Count
: Word);
460 function g_Gibs_GetMax(): Word;
461 procedure g_Corpses_SetMax(Count
: Word);
462 function g_Corpses_GetMax(): Word;
463 procedure g_Shells_SetMax(Count
: Word);
464 function g_Shells_GetMax(): Word;
466 procedure g_Player_Init();
467 procedure g_Player_Free();
468 function g_Player_Create(ModelName
: String; Color
: TRGB
; Team
: Byte; Bot
: Boolean): Word;
469 function g_Player_CreateFromState(var Mem
: TBinMemoryReader
): Word;
470 procedure g_Player_Remove(UID
: Word);
471 procedure g_Player_ResetTeams();
472 procedure g_Player_UpdateAll();
473 procedure g_Player_DrawAll();
474 procedure g_Player_DrawDebug(p
: TPlayer
);
475 procedure g_Player_DrawHealth();
476 procedure g_Player_RememberAll();
477 procedure g_Player_ResetAll(Force
, Silent
: Boolean);
478 function g_Player_Get(UID
: Word): TPlayer
;
479 function g_Player_GetCount(): Byte;
480 function g_Player_GetStats(): TPlayerStatArray
;
481 function g_Player_ValidName(Name
: String): Boolean;
482 procedure g_Player_CreateCorpse(Player
: TPlayer
);
483 procedure g_Player_CreateGibs(fX
, fY
: Integer; ModelName
: String; fColor
: TRGB
);
484 procedure g_Player_CreateShell(fX
, fY
, dX
, dY
: Integer; T
: Byte);
485 procedure g_Player_UpdatePhysicalObjects();
486 procedure g_Player_DrawCorpses();
487 procedure g_Player_DrawShells();
488 procedure g_Player_RemoveAllCorpses();
489 procedure g_Player_Corpses_SaveState(var Mem
: TBinMemoryWriter
);
490 procedure g_Player_Corpses_LoadState(var Mem
: TBinMemoryReader
);
491 procedure g_Bot_Add(Team
, Difficult
: Byte);
492 procedure g_Bot_AddList(Team
: Byte; lname
: ShortString; num
: Integer = -1);
493 procedure g_Bot_MixNames();
494 procedure g_Bot_RemoveAll();
499 e_log
, g_map
, g_items
, g_console
, SysUtils
, g_gfx
, Math
,
500 g_options
, g_triggers
, g_menu
, MAPDEF
, g_game
,
501 wadreader
, g_main
, g_monsters
, CONFIG
, g_language
, g_net
, g_netmsg
;
511 diag_precision
: Byte;
515 w_prior1
: Array [WEAPON_KASTET
..WEAPON_SUPERPULEMET
] of Byte;
516 w_prior2
: Array [WEAPON_KASTET
..WEAPON_SUPERPULEMET
] of Byte;
517 w_prior3
: Array [WEAPON_KASTET
..WEAPON_SUPERPULEMET
] of Byte;
521 TIME_RESPAWN1
= 1500;
522 TIME_RESPAWN2
= 2000;
523 TIME_RESPAWN3
= 3000;
526 JET_MAX
= 540; // ~30 sec
527 PLAYER_SUIT_TIME
= 30000;
528 PLAYER_INVUL_TIME
= 30000;
529 PLAYER_INVIS_TIME
= 35000;
530 FRAG_COMBO_TIME
= 3000;
534 ANGLE_RIGHTDOWN
= -35;
536 ANGLE_LEFTDOWN
= -145;
537 PLAYER_HEADRECT
: TRectWH
= (X
:24; Y
:12; Width
:20; Height
:12);
538 WEAPONPOINT
: Array [TDirection
] of TPoint
= ((X
:16; Y
:32), (X
:47; Y
:32));
541 BOT_UNSAFEDIST
= 128;
542 TEAMCOLOR
: Array [TEAM_RED
..TEAM_BLUE
] of TRGB
= ((R
:255; G
:0; B
:0),
544 DIFFICULT_EASY
: TDifficult
= (DiagFire
: 32; InvisFire
: 32; DiagPrecision
: 32;
545 FlyPrecision
: 32; Cover
: 32; CloseJump
: 32;
546 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0));
547 DIFFICULT_MEDIUM
: TDifficult
= (DiagFire
: 127; InvisFire
: 127; DiagPrecision
: 127;
548 FlyPrecision
: 127; Cover
: 127; CloseJump
: 127;
549 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0));
550 DIFFICULT_HARD
: TDifficult
= (DiagFire
: 255; InvisFire
: 255; DiagPrecision
: 255;
551 FlyPrecision
: 255; Cover
: 255; CloseJump
: 255;
552 WeaponPrior
:(0,0,0,0,0,0,0,0,0,0); CloseWeaponPrior
:(0,0,0,0,0,0,0,0,0,0));
553 WEAPON_PRIOR1
: Array [WEAPON_KASTET
..WEAPON_SUPERPULEMET
] of Byte =
554 (WEAPON_SUPERPULEMET
, WEAPON_SHOTGUN2
, WEAPON_SHOTGUN1
,
555 WEAPON_CHAINGUN
, WEAPON_PLASMA
, WEAPON_ROCKETLAUNCHER
,
556 WEAPON_BFG
, WEAPON_PISTOL
, WEAPON_SAW
, WEAPON_KASTET
);
557 WEAPON_PRIOR2
: Array [WEAPON_KASTET
..WEAPON_SUPERPULEMET
] of Byte =
558 (WEAPON_SUPERPULEMET
, WEAPON_BFG
, WEAPON_ROCKETLAUNCHER
,
559 WEAPON_SHOTGUN2
, WEAPON_PLASMA
, WEAPON_SHOTGUN1
,
560 WEAPON_CHAINGUN
, WEAPON_PISTOL
, WEAPON_SAW
, WEAPON_KASTET
);
561 //WEAPON_PRIOR3: Array [WEAPON_KASTET..WEAPON_SUPERPULEMET] of Byte =
562 // (WEAPON_SUPERPULEMET, WEAPON_BFG, WEAPON_PLASMA,
563 // WEAPON_SHOTGUN2, WEAPON_CHAINGUN, WEAPON_SHOTGUN1,
564 // WEAPON_SAW, WEAPON_ROCKETLAUNCHER, WEAPON_PISTOL, WEAPON_KASTET);
565 WEAPON_RELOAD
: Array [WEAPON_KASTET
..WEAPON_SUPERPULEMET
] of Byte =
566 (5, 2, 6, 18, 36, 2, 12, 2, 14, 2);
568 PLAYER_SIGNATURE
= $52594C50; // 'PLYR'
569 CORPSE_SIGNATURE
= $50524F43; // 'CORP'
571 BOTNAMES_FILENAME
= 'botnames.txt';
572 BOTLIST_FILENAME
= 'botlist.txt';
576 MaxCorpses
: Word = 20;
577 MaxShells
: Word = 300;
578 CurrentGib
: Integer = 0;
579 CurrentShell
: Integer = 0;
580 BotNames
: Array of String;
581 BotList
: Array of TBotProfile
;
583 function Lerp(X
, Y
, Factor
: Integer): Integer;
585 Result
:= X
+ ((Y
- X
) div Factor
);
588 function SameTeam(UID1
, UID2
: Word): Boolean;
592 if (UID1
> UID_MAX_PLAYER
) or (UID1
<= UID_MAX_GAME
) or
593 (UID2
> UID_MAX_PLAYER
) or (UID2
<= UID_MAX_GAME
) then Exit
;
595 if (g_Player_Get(UID1
) = nil) or (g_Player_Get(UID2
) = nil) then Exit
;
597 if ((g_Player_Get(UID1
).Team
= TEAM_NONE
) or
598 (g_Player_Get(UID2
).Team
= TEAM_NONE
)) then Exit
;
600 Result
:= g_Player_Get(UID1
).FTeam
= g_Player_Get(UID2
).FTeam
;
603 procedure g_Gibs_SetMax(Count
: Word);
606 SetLength(gGibs
, Count
);
608 if CurrentGib
>= Count
then
612 function g_Gibs_GetMax(): Word;
617 procedure g_Shells_SetMax(Count
: Word);
620 SetLength(gShells
, Count
);
622 if CurrentShell
>= Count
then
626 function g_Shells_GetMax(): Word;
632 procedure g_Corpses_SetMax(Count
: Word);
635 SetLength(gCorpses
, Count
);
638 function g_Corpses_GetMax(): Word;
640 Result
:= MaxCorpses
;
643 function g_Player_Create(ModelName
: String; Color
: TRGB
; Team
: Byte; Bot
: Boolean): Word;
653 // Åñòü ëè ìåñòî â gPlayers:
654 if gPlayers
<> nil then
655 for a
:= 0 to High(gPlayers
) do
656 if gPlayers
[a
] = nil then
662 // Íåò ìåñòà - ðàñøèðÿåì gPlayers:
665 SetLength(gPlayers
, Length(gPlayers
)+1);
669 // Ñîçäàåì îáúåêò èãðîêà:
671 gPlayers
[a
] := TBot
.Create()
673 gPlayers
[a
] := TPlayer
.Create();
676 gPlayers
[a
].FActualModelName
:= ModelName
;
677 gPlayers
[a
].SetModel(ModelName
);
679 // Íåò ìîäåëè - ñîçäàíèå íå âîçìîæíî:
680 if gPlayers
[a
].FModel
= nil then
684 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], [ModelName
]));
688 if not (Team
in [TEAM_RED
, TEAM_BLUE
]) then
689 if Random(2) = 0 then
693 gPlayers
[a
].FPreferredTeam
:= Team
;
695 case gGameSettings
.GameMode
of
696 GM_DM
: gPlayers
[a
].FTeam
:= TEAM_NONE
;
698 GM_CTF
: gPlayers
[a
].FTeam
:= gPlayers
[a
].FPreferredTeam
;
700 GM_COOP
: gPlayers
[a
].FTeam
:= TEAM_COOP
;
703 // Åñëè êîìàíäíàÿ èãðà - êðàñèì ìîäåëü â öâåò êîìàíäû:
704 gPlayers
[a
].FColor
:= Color
;
705 if gPlayers
[a
].FTeam
in [TEAM_RED
, TEAM_BLUE
] then
706 gPlayers
[a
].FModel
.Color
:= TEAMCOLOR
[gPlayers
[a
].FTeam
]
708 gPlayers
[a
].FModel
.Color
:= Color
;
710 gPlayers
[a
].FUID
:= g_CreateUID(UID_PLAYER
);
711 gPlayers
[a
].FLive
:= False;
713 Result
:= gPlayers
[a
].FUID
;
716 function g_Player_CreateFromState(var Mem
: TBinMemoryReader
): Word;
729 if sig
<> PLAYER_SIGNATURE
then // 'PLYR'
731 raise EBinSizeError
.Create('g_Player_CreateFromState: Wrong Player Signature');
735 Mem
.ReadBoolean(Bot
);
740 // Åñòü ëè ìåñòî â gPlayers:
741 if gPlayers
<> nil then
742 for a
:= 0 to High(gPlayers
) do
743 if gPlayers
[a
] = nil then
749 // Íåò ìåñòà - ðàñøèðÿåì gPlayers:
752 SetLength(gPlayers
, Length(gPlayers
)+1);
756 // Ñîçäàåì îáúåêò èãðîêà:
758 gPlayers
[a
] := TBot
.Create()
760 gPlayers
[a
] := TPlayer
.Create();
761 gPlayers
[a
].FIamBot
:= Bot
;
762 gPlayers
[a
].FPhysics
:= True;
765 Mem
.ReadWord(gPlayers
[a
].FUID
);
767 Mem
.ReadString(gPlayers
[a
].FName
);
769 Mem
.ReadByte(gPlayers
[a
].FTeam
);
770 gPlayers
[a
].FPreferredTeam
:= gPlayers
[a
].FTeam
;
772 Mem
.ReadBoolean(gPlayers
[a
].FLive
);
773 // Èçðàñõîäîâàë ëè âñå æèçíè:
774 Mem
.ReadBoolean(gPlayers
[a
].FNoRespawn
);
778 gPlayers
[a
].FDirection
:= D_LEFT
780 gPlayers
[a
].FDirection
:= D_RIGHT
;
782 Mem
.ReadInt(gPlayers
[a
].FHealth
);
784 Mem
.ReadByte(gPlayers
[a
].FLives
);
786 Mem
.ReadInt(gPlayers
[a
].FArmor
);
788 Mem
.ReadInt(gPlayers
[a
].FAir
);
790 Mem
.ReadInt(gPlayers
[a
].FJetFuel
);
792 Mem
.ReadInt(gPlayers
[a
].FPain
);
794 Mem
.ReadInt(gPlayers
[a
].FKills
);
796 Mem
.ReadInt(gPlayers
[a
].FMonsterKills
);
798 Mem
.ReadInt(gPlayers
[a
].FFrags
);
800 Mem
.ReadByte(gPlayers
[a
].FFragCombo
);
801 // Âðåìÿ ïîñëåäíåãî ôðàãà:
802 Mem
.ReadDWORD(gPlayers
[a
].FLastFrag
);
804 Mem
.ReadInt(gPlayers
[a
].FDeath
);
806 Mem
.ReadByte(gPlayers
[a
].FFlag
);
808 Mem
.ReadInt(gPlayers
[a
].FSecrets
);
810 Mem
.ReadByte(gPlayers
[a
].FCurrWeap
);
811 // Ñëåäóþùåå æåëàåìîå îðóæèå:
812 Mem
.ReadWord(gPlayers
[a
].FNextWeap
);
814 Mem
.ReadByte(gPlayers
[a
].FNextWeapDelay
);
815 // Âðåìÿ çàðÿäêè BFG:
816 Mem
.ReadSmallInt(gPlayers
[a
].FBFGFireCounter
);
818 Mem
.ReadInt(gPlayers
[a
].FDamageBuffer
);
819 // Ïîñëåäíèé óäàðèâøèé:
820 Mem
.ReadWord(gPlayers
[a
].FLastSpawnerUID
);
821 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà:
822 Mem
.ReadByte(gPlayers
[a
].FLastHit
);
824 Obj_LoadState(@gPlayers
[a
].FObj
, Mem
);
825 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ:
826 for i
:= A_BULLETS
to A_CELLS
do
827 Mem
.ReadWord(gPlayers
[a
].FAmmo
[i
]);
828 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ:
829 for i
:= A_BULLETS
to A_CELLS
do
830 Mem
.ReadWord(gPlayers
[a
].FMaxAmmo
[i
]);
832 for i
:= WEAPON_KASTET
to WEAPON_SUPERPULEMET
do
833 Mem
.ReadBoolean(gPlayers
[a
].FWeapon
[i
]);
834 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ:
835 for i
:= WEAPON_KASTET
to WEAPON_SUPERPULEMET
do
836 Mem
.ReadWord(gPlayers
[a
].FReloading
[i
]);
840 Include(gPlayers
[a
].FRulez
, R_ITEM_BACKPACK
);
841 // Íàëè÷èå êðàñíîãî êëþ÷à:
844 Include(gPlayers
[a
].FRulez
, R_KEY_RED
);
845 // Íàëè÷èå çåëåíîãî êëþ÷à:
848 Include(gPlayers
[a
].FRulez
, R_KEY_GREEN
);
849 // Íàëè÷èå ñèíåãî êëþ÷à:
852 Include(gPlayers
[a
].FRulez
, R_KEY_BLUE
);
856 Include(gPlayers
[a
].FRulez
, R_BERSERK
);
857 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ:
858 for i
:= MR_SUIT
to MR_MAX
do
859 Mem
.ReadDWORD(gPlayers
[a
].FMegaRulez
[i
]);
860 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà:
861 for i
:= T_RESPAWN
to T_FLAGCAP
do
862 Mem
.ReadDWORD(gPlayers
[a
].FTime
[i
]);
865 Mem
.ReadString(gPlayers
[a
].FActualModelName
);
867 Mem
.ReadByte(gPlayers
[a
].FColor
.R
);
868 Mem
.ReadByte(gPlayers
[a
].FColor
.G
);
869 Mem
.ReadByte(gPlayers
[a
].FColor
.B
);
870 // Îáíîâëÿåì ìîäåëü èãðîêà:
871 gPlayers
[a
].SetModel(gPlayers
[a
].FActualModelName
);
873 // Íåò ìîäåëè - ñîçäàíèå íå âîçìîæíî:
874 if gPlayers
[a
].FModel
= nil then
878 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], [gPlayers
[a
].FActualModelName
]));
882 // Åñëè êîìàíäíàÿ èãðà - êðàñèì ìîäåëü â öâåò êîìàíäû:
883 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
884 gPlayers
[a
].FModel
.Color
:= TEAMCOLOR
[gPlayers
[a
].FTeam
]
886 gPlayers
[a
].FModel
.Color
:= gPlayers
[a
].FColor
;
888 Result
:= gPlayers
[a
].FUID
;
891 procedure g_Player_ResetTeams();
895 if g_Game_IsClient
then
897 if gPlayers
= nil then
899 for a
:= Low(gPlayers
) to High(gPlayers
) do
900 if gPlayers
[a
] <> nil then
901 case gGameSettings
.GameMode
of
903 gPlayers
[a
].ChangeTeam(TEAM_NONE
);
905 if not (gPlayers
[a
].Team
in [TEAM_RED
, TEAM_BLUE
]) then
906 if gPlayers
[a
].FPreferredTeam
in [TEAM_RED
, TEAM_BLUE
] then
907 gPlayers
[a
].ChangeTeam(gPlayers
[a
].FPreferredTeam
)
910 gPlayers
[a
].ChangeTeam(TEAM_RED
)
912 gPlayers
[a
].ChangeTeam(TEAM_BLUE
);
915 gPlayers
[a
].ChangeTeam(TEAM_COOP
);
919 procedure g_Bot_Add(Team
, Difficult
: Byte);
922 _name
, _model
: String;
925 if not g_Game_IsServer
then Exit
;
927 // Ñïèñîê íàçâàíèé ìîäåëåé:
928 m
:= g_PlayerModel_GetNames();
933 if (gGameSettings
.GameType
= GT_SINGLE
) or (gGameSettings
.GameMode
= GM_COOP
) then
934 Team
:= TEAM_COOP
// COOP
936 if gGameSettings
.GameMode
= GM_DM
then
937 Team
:= TEAM_NONE
// DM
939 if Team
= TEAM_NONE
then // CTF / TDM
941 // Àâòîáàëàíñ êîìàíä:
945 for a
:= 0 to High(gPlayers
) do
946 if gPlayers
[a
] <> nil then
948 if gPlayers
[a
].Team
= TEAM_RED
then
951 if gPlayers
[a
].Team
= TEAM_BLUE
then
961 if Random(2) = 0 then
967 // Âûáèðàåì áîòó èìÿ:
969 if BotNames
<> nil then
970 for a
:= 0 to High(BotNames
) do
971 if g_Player_ValidName(BotNames
[a
]) then
973 _name
:= BotNames
[a
];
977 // Èìåíè íåò, çàäàåì ñëó÷àéíîå:
980 _name
:= Format('DFBOT%.2d', [Random(100)]);
981 until g_Player_ValidName(_name
);
983 // Âûáèðàåì ñëó÷àéíóþ ìîäåëü:
984 _model
:= m
[Random(Length(m
))];
987 with g_Player_Get(g_Player_Create(_model
,
988 _RGB(Min(Random(9)*32, 255),
989 Min(Random(9)*32, 255),
990 Min(Random(9)*32, 255)),
991 Team
, True)) as TBot
do
996 1: FDifficult
:= DIFFICULT_EASY
;
997 2: FDifficult
:= DIFFICULT_MEDIUM
;
998 else FDifficult
:= DIFFICULT_HARD
;
1001 for a
:= WEAPON_KASTET
to WEAPON_SUPERPULEMET
do
1003 FDifficult
.WeaponPrior
[a
] := WEAPON_PRIOR1
[a
];
1004 FDifficult
.CloseWeaponPrior
[a
] := WEAPON_PRIOR2
[a
];
1005 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
1008 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [Name
]), True);
1010 if g_Game_IsNet
then MH_SEND_PlayerCreate(UID
);
1011 if g_Game_IsServer
and (gGameSettings
.MaxLives
> 0) then
1016 procedure g_Bot_AddList(Team
: Byte; lName
: ShortString; num
: Integer = -1);
1019 _name
, _model
: String;
1022 if not g_Game_IsServer
then Exit
;
1024 // Ñïèñîê íàçâàíèé ìîäåëåé:
1025 m
:= g_PlayerModel_GetNames();
1030 if (gGameSettings
.GameType
= GT_SINGLE
) or (gGameSettings
.GameMode
= GM_COOP
) then
1031 Team
:= TEAM_COOP
// COOP
1033 if gGameSettings
.GameMode
= GM_DM
then
1034 Team
:= TEAM_NONE
// DM
1036 if Team
= TEAM_NONE
then
1037 Team
:= BotList
[num
].team
; // CTF / TDM
1039 // Âûáèðàåì íàñòðîéêè áîòà èç ñïèñêà ïî íîìåðó èëè èìåíè:
1040 lName
:= AnsiLowerCase(lName
);
1041 if (num
< 0) or (num
> Length(BotList
)-1) then
1043 if (num
= -1) and (lName
<> '') and (BotList
<> nil) then
1044 for a
:= 0 to High(BotList
) do
1045 if AnsiLowerCase(BotList
[a
].name
) = lName
then
1054 _name
:= BotList
[num
].name
;
1055 // Çàíÿòî - âûáèðàåì ñëó÷àéíîå:
1056 if not g_Player_ValidName(_name
) then
1058 _name
:= Format('DFBOT%.2d', [Random(100)]);
1059 until g_Player_ValidName(_name
);
1062 _model
:= BotList
[num
].model
;
1063 // Íåò òàêîé - âûáèðàåì ñëó÷àéíóþ:
1064 if not InSArray(_model
, m
) then
1065 _model
:= m
[Random(Length(m
))];
1068 with g_Player_Get(g_Player_Create(_model
, BotList
[num
].color
, Team
, True)) as TBot
do
1072 FDifficult
.DiagFire
:= BotList
[num
].diag_fire
;
1073 FDifficult
.InvisFire
:= BotList
[num
].invis_fire
;
1074 FDifficult
.DiagPrecision
:= BotList
[num
].diag_precision
;
1075 FDifficult
.FlyPrecision
:= BotList
[num
].fly_precision
;
1076 FDifficult
.Cover
:= BotList
[num
].cover
;
1077 FDifficult
.CloseJump
:= BotList
[num
].close_jump
;
1079 for a
:= WEAPON_KASTET
to WEAPON_SUPERPULEMET
do
1081 FDifficult
.WeaponPrior
[a
] := BotList
[num
].w_prior1
[a
];
1082 FDifficult
.CloseWeaponPrior
[a
] := BotList
[num
].w_prior2
[a
];
1083 //FDifficult.SafeWeaponPrior[a] := BotList[num].w_prior3[a];
1086 g_Console_Add(Format(_lc
[I_PLAYER_JOIN
], [Name
]), True);
1088 if g_Game_IsNet
then MH_SEND_PlayerCreate(UID
);
1092 procedure g_Bot_RemoveAll();
1096 if not g_Game_IsServer
then Exit
;
1097 if gPlayers
= nil then Exit
;
1099 for a
:= 0 to High(gPlayers
) do
1100 if gPlayers
[a
] <> nil then
1101 if gPlayers
[a
] is TBot
then
1103 gPlayers
[a
].Lives
:= 0;
1104 gPlayers
[a
].Kill(K_SIMPLEKILL
, 0, HIT_DISCON
);
1105 g_Console_Add(Format(_lc
[I_PLAYER_LEAVE
], [gPlayers
[a
].Name
]), True);
1106 g_Player_Remove(gPlayers
[a
].FUID
);
1112 procedure g_Bot_MixNames();
1117 if BotNames
<> nil then
1118 for a
:= 0 to High(BotNames
) do
1120 b
:= Random(Length(BotNames
));
1122 Botnames
[a
] := BotNames
[b
];
1127 procedure g_Player_Remove(UID
: Word);
1131 if gPlayers
= nil then Exit
;
1133 if g_Game_IsServer
and g_Game_IsNet
then
1134 MH_SEND_PlayerDelete(UID
);
1136 for i
:= 0 to High(gPlayers
) do
1137 if gPlayers
[i
] <> nil then
1138 if gPlayers
[i
].FUID
= UID
then
1140 if gPlayers
[i
] is TPlayer
then
1141 TPlayer(gPlayers
[i
]).Free()
1143 TBot(gPlayers
[i
]).Free();
1149 procedure g_Player_Init();
1159 if not FileExists(DataDir
+ BOTNAMES_FILENAME
) then
1162 // ×èòàåì âîçìîæíûå èìåíà áîòîâ èç ôàéëà:
1163 AssignFile(F
, DataDir
+ BOTNAMES_FILENAME
);
1174 SetLength(BotNames
, Length(BotNames
)+1);
1175 BotNames
[High(BotNames
)] := s
;
1183 // ×èòàåì ôàéë ñ ïàðàìåòðàìè áîòîâ:
1184 config
:= TConfig
.CreateFile(DataDir
+ BOTLIST_FILENAME
);
1188 while config
.SectionExists(IntToStr(a
)) do
1190 SetLength(BotList
, Length(BotList
)+1);
1192 with BotList
[High(BotList
)] do
1195 name
:= config
.ReadStr(IntToStr(a
), 'name', '');
1197 model
:= config
.ReadStr(IntToStr(a
), 'model', '');
1199 if config
.ReadStr(IntToStr(a
), 'team', 'red') = 'red' then
1204 sa
:= parse(config
.ReadStr(IntToStr(a
), 'color', ''));
1205 color
.R
:= StrToIntDef(sa
[0], 0);
1206 color
.G
:= StrToIntDef(sa
[1], 0);
1207 color
.B
:= StrToIntDef(sa
[2], 0);
1208 // Âåðîÿòíîñòü ñòðåëüáû ïîä óãëîì:
1209 diag_fire
:= config
.ReadInt(IntToStr(a
), 'diag_fire', 0);
1210 // Âåðîÿòíîñòü îòâåòíîãî îãíÿ ïî íåâèäèìîìó ñîïåðíèêó:
1211 invis_fire
:= config
.ReadInt(IntToStr(a
), 'invis_fire', 0);
1212 // Òî÷íîñòü ñòðåëüáû ïîä óãëîì:
1213 diag_precision
:= config
.ReadInt(IntToStr(a
), 'diag_precision', 0);
1214 // Òî÷íîñòü ñòðåëüáû â ïîëåòå:
1215 fly_precision
:= config
.ReadInt(IntToStr(a
), 'fly_precision', 0);
1216 // Òî÷íîñòü óêëîíåíèÿ îò ñíàðÿäîâ:
1217 cover
:= config
.ReadInt(IntToStr(a
), 'cover', 0);
1218 // Âåðîÿòíîñòü ïðûæêà ïðè ïðèáëèæåíèè ñîïåðíèêà:
1219 close_jump
:= config
.ReadInt(IntToStr(a
), 'close_jump', 0);
1220 // Ïðèîðèòåòû îðóæèÿ äëÿ äàëüíåãî áîÿ:
1221 sa
:= parse(config
.ReadStr(IntToStr(a
), 'w_prior1', ''));
1222 if Length(sa
) = 10 then
1224 w_prior1
[b
] := EnsureRange(StrToInt(sa
[b
]), 0, 9);
1225 // Ïðèîðèòåòû îðóæèÿ äëÿ áëèæíåãî áîÿ:
1226 sa
:= parse(config
.ReadStr(IntToStr(a
), 'w_prior2', ''));
1227 if Length(sa
) = 10 then
1229 w_prior2
[b
] := EnsureRange(StrToInt(sa
[b
]), 0, 9);
1231 {sa := parse(config.ReadStr(IntToStr(a), 'w_prior3', ''));
1232 if Length(sa) = 10 then
1234 w_prior3[b] := EnsureRange(StrToInt(sa[b]), 0, 9);}
1243 procedure g_Player_Free();
1247 if gPlayers
<> nil then
1249 for i
:= 0 to High(gPlayers
) do
1250 if gPlayers
[i
] <> nil then
1252 if gPlayers
[i
] is TPlayer
then
1253 TPlayer(gPlayers
[i
]).Free()
1255 TBot(gPlayers
[i
]).Free();
1266 procedure g_Player_UpdateAll();
1270 if gPlayers
= nil then Exit
;
1272 for i
:= 0 to High(gPlayers
) do
1273 if gPlayers
[i
] <> nil then
1274 if gPlayers
[i
] is TPlayer
then gPlayers
[i
].Update()
1275 else TBot(gPlayers
[i
]).Update();
1278 procedure g_Player_DrawAll();
1282 if gPlayers
= nil then Exit
;
1284 for i
:= 0 to High(gPlayers
) do
1285 if gPlayers
[i
] <> nil then
1286 if gPlayers
[i
] is TPlayer
then gPlayers
[i
].Draw()
1287 else TBot(gPlayers
[i
]).Draw();
1290 procedure g_Player_DrawDebug(p
: TPlayer
);
1294 if p
= nil then Exit
;
1295 if (@p
.FObj
) = nil then Exit
;
1297 e_TextureFontGetSize(gStdFont
, fW
, fH
);
1299 e_TextureFontPrint(0, 0 , 'Pos X: ' + IntToStr(p
.FObj
.X
), gStdFont
);
1300 e_TextureFontPrint(0, fH
, 'Pos Y: ' + IntToStr(p
.FObj
.Y
), gStdFont
);
1301 e_TextureFontPrint(0, fH
* 2, 'Vel X: ' + IntToStr(p
.FObj
.Vel
.X
), gStdFont
);
1302 e_TextureFontPrint(0, fH
* 3, 'Vel Y: ' + IntToStr(p
.FObj
.Vel
.Y
), gStdFont
);
1303 e_TextureFontPrint(0, fH
* 4, 'Acc X: ' + IntToStr(p
.FObj
.Accel
.X
), gStdFont
);
1304 e_TextureFontPrint(0, fH
* 5, 'Acc Y: ' + IntToStr(p
.FObj
.Accel
.Y
), gStdFont
);
1307 procedure g_Player_DrawHealth();
1312 if gPlayers
= nil then Exit
;
1313 e_TextureFontGetSize(gStdFont
, fW
, fH
);
1315 for i
:= 0 to High(gPlayers
) do
1316 if gPlayers
[i
] <> nil then
1318 e_TextureFontPrint(gPlayers
[i
].FObj
.X
+ gPlayers
[i
].FObj
.Rect
.X
,
1319 gPlayers
[i
].FObj
.Y
+ gPlayers
[i
].FObj
.Rect
.Y
+ gPlayers
[i
].FObj
.Rect
.Height
- fH
* 2,
1320 IntToStr(gPlayers
[i
].FHealth
), gStdFont
);
1321 e_TextureFontPrint(gPlayers
[i
].FObj
.X
+ gPlayers
[i
].FObj
.Rect
.X
,
1322 gPlayers
[i
].FObj
.Y
+ gPlayers
[i
].FObj
.Rect
.Y
+ gPlayers
[i
].FObj
.Rect
.Height
- fH
,
1323 IntToStr(gPlayers
[i
].FArmor
), gStdFont
);
1327 function g_Player_Get(UID
: Word): TPlayer
;
1333 if gPlayers
= nil then
1336 for a
:= 0 to High(gPlayers
) do
1337 if gPlayers
[a
] <> nil then
1338 if gPlayers
[a
].FUID
= UID
then
1340 Result
:= gPlayers
[a
];
1345 function g_Player_GetCount(): Byte;
1351 if gPlayers
= nil then
1354 for a
:= 0 to High(gPlayers
) do
1355 if gPlayers
[a
] <> nil then
1356 Result
:= Result
+ 1;
1359 function g_Player_GetStats(): TPlayerStatArray
;
1365 if gPlayers
= nil then Exit
;
1367 for a
:= 0 to High(gPlayers
) do
1368 if gPlayers
[a
] <> nil then
1370 SetLength(Result
, Length(Result
)+1);
1371 with Result
[High(Result
)] do
1373 Ping
:= gPlayers
[a
].FPing
;
1374 Loss
:= gPlayers
[a
].FLoss
;
1375 Name
:= gPlayers
[a
].FName
;
1376 Team
:= gPlayers
[a
].FTeam
;
1377 Frags
:= gPlayers
[a
].FFrags
;
1378 Deaths
:= gPlayers
[a
].FDeath
;
1379 Kills
:= gPlayers
[a
].FKills
;
1380 Color
:= gPlayers
[a
].FModel
.Color
;
1381 Lives
:= gPlayers
[a
].FLives
;
1382 Spectator
:= gPlayers
[a
].FSpectator
;
1387 procedure g_Player_RememberAll
;
1391 for i
:= Low(gPlayers
) to High(gPlayers
) do
1392 if (gPlayers
[i
] <> nil) and gPlayers
[i
].Live
then
1393 gPlayers
[i
].RememberState
;
1396 procedure g_Player_ResetAll(Force
, Silent
: Boolean);
1400 gTeamStat
[TEAM_RED
].Goals
:= 0;
1401 gTeamStat
[TEAM_BLUE
].Goals
:= 0;
1403 if gPlayers
<> nil then
1404 for i
:= 0 to High(gPlayers
) do
1405 if gPlayers
[i
] <> nil then
1407 gPlayers
[i
].Reset(Force
);
1409 if gPlayers
[i
] is TPlayer
then
1411 if (not gPlayers
[i
].FSpectator
) or gPlayers
[i
].FWantsInGame
then
1412 gPlayers
[i
].Respawn(Silent
)
1414 gPlayers
[i
].Spectate();
1417 TBot(gPlayers
[i
]).Respawn(Silent
);
1421 procedure g_Player_CreateCorpse(Player
: TPlayer
);
1428 if Player
.FObj
.Y
>= gMapInfo
.Height
+128 then
1433 if (FHealth
>= -50) or (gGibsCount
= 0) then
1435 if (gCorpses
= nil) or (Length(gCorpses
) = 0) then
1439 for find_id
:= 0 to High(gCorpses
) do
1440 if gCorpses
[find_id
] = nil then
1447 find_id
:= Random(Length(gCorpses
));
1449 gCorpses
[find_id
] := TCorpse
.Create(FObj
.X
, FObj
.Y
, FModel
.Name
, FHealth
< -20);
1450 gCorpses
[find_id
].FColor
:= FModel
.Color
;
1451 gCorpses
[find_id
].FObj
.Vel
:= FObj
.Vel
;
1452 gCorpses
[find_id
].FObj
.Accel
:= FObj
.Accel
;
1455 g_Player_CreateGibs(FObj
.X
+ PLAYER_RECT_CX
,
1456 FObj
.Y
+ PLAYER_RECT_CY
,
1457 FModel
.Name
, FModel
.Color
);
1461 procedure g_Player_CreateShell(fX
, fY
, dX
, dY
: Integer; T
: Byte);
1465 if (gShells
= nil) or (Length(gShells
) = 0) then
1468 with gShells
[CurrentShell
] do
1474 if T
= SHELL_BULLET
then
1476 if g_Texture_Get('TEXTURE_SHELL_BULLET', SID
) then
1480 Obj
.Rect
.Width
:= 4;
1481 Obj
.Rect
.Height
:= 2;
1485 if g_Texture_Get('TEXTURE_SHELL_SHELL', SID
) then
1489 Obj
.Rect
.Width
:= 7;
1490 Obj
.Rect
.Height
:= 3;
1496 g_Obj_Push(@Obj
, dX
+ Random(4)-Random(4), dY
-Random(4));
1497 RAngle
:= Random(360);
1498 Timeout
:= gTime
+ SHELL_TIMEOUT
;
1500 if CurrentShell
>= High(gShells
) then
1507 procedure g_Player_CreateGibs(fX
, fY
: Integer; ModelName
: string; fColor
: TRGB
);
1510 GibsArray
: TGibsArray
;
1512 if (gGibs
= nil) or (Length(gGibs
) = 0) then
1514 if not g_PlayerModel_GetGibs(ModelName
, GibsArray
) then
1517 for a
:= 0 to High(GibsArray
) do
1518 with gGibs
[CurrentGib
] do
1521 ID
:= GibsArray
[a
].ID
;
1522 MaskID
:= GibsArray
[a
].MaskID
;
1525 Obj
.Rect
:= GibsArray
[a
].Rect
;
1526 Obj
.X
:= fX
-GibsArray
[a
].Rect
.X
-(GibsArray
[a
].Rect
.Width
div 2);
1527 Obj
.Y
:= fY
-GibsArray
[a
].Rect
.Y
-(GibsArray
[a
].Rect
.Height
div 2);
1528 g_Obj_PushA(@Obj
, 25 + Random(10), Random(361));
1529 RAngle
:= Random(360);
1531 if gBloodCount
> 0 then
1532 g_GFX_Blood(fX
, fY
, 16*gBloodCount
+Random(5*gBloodCount
), -16+Random(33), -16+Random(33),
1533 Random(48), Random(48), 150, 0, 0);
1535 if CurrentGib
>= High(gGibs
) then
1542 procedure g_Player_UpdatePhysicalObjects();
1548 procedure ShellSound_Bounce(X
, Y
: Integer; T
: Byte);
1553 if T
= SHELL_BULLET
then
1554 g_Sound_PlayExAt('SOUND_PLAYER_CASING' + IntToStr(k
), X
, Y
)
1556 g_Sound_PlayExAt('SOUND_PLAYER_SHELL' + IntToStr(k
), X
, Y
);
1561 if gGibs
<> nil then
1562 for i
:= 0 to High(gGibs
) do
1563 if gGibs
[i
].Live
then
1567 mr
:= g_Obj_Move(@Obj
, True, False, True);
1569 if WordBool(mr
and MOVE_FALLOUT
) then
1575 // Îòëåòàåò îò óäàðà î ñòåíó/ïîòîëîê/ïîë:
1576 if WordBool(mr
and MOVE_HITWALL
) then
1577 Obj
.Vel
.X
:= -(vel
.X
div 2);
1578 if WordBool(mr
and (MOVE_HITCEIL
or MOVE_HITLAND
)) then
1579 Obj
.Vel
.Y
:= -(vel
.Y
div 2);
1581 if (Obj
.Vel
.X
>= 0) then
1583 RAngle
:= RAngle
+ Abs(Obj
.Vel
.X
)*6 + Abs(Obj
.Vel
.Y
);
1584 if RAngle
>= 360 then
1585 RAngle
:= RAngle
mod 360;
1586 end else begin // Counter-clockwise
1587 RAngle
:= RAngle
- Abs(Obj
.Vel
.X
)*6 - Abs(Obj
.Vel
.Y
);
1589 RAngle
:= (360 - (Abs(RAngle
) mod 360)) mod 360;
1592 // Ñîïðîòèâëåíèå âîçäóõà äëÿ êóñêà òðóïà:
1593 if gTime
mod (GAME_TICK
*3) = 0 then
1594 Obj
.Vel
.X
:= z_dec(Obj
.Vel
.X
, 1);
1598 if gCorpses
<> nil then
1599 for i
:= 0 to High(gCorpses
) do
1600 if gCorpses
[i
] <> nil then
1601 if gCorpses
[i
].State
= CORPSE_STATE_REMOVEME
then
1607 gCorpses
[i
].Update();
1610 if gShells
<> nil then
1611 for i
:= 0 to High(gShells
) do
1612 if gShells
[i
].Live
then
1616 mr
:= g_Obj_Move(@Obj
, True, False, True);
1618 if WordBool(mr
and MOVE_FALLOUT
) or (gShells
[i
].Timeout
< gTime
) then
1624 // Îòëåòàåò îò óäàðà î ñòåíó/ïîòîëîê/ïîë:
1625 if WordBool(mr
and MOVE_HITWALL
) then
1627 Obj
.Vel
.X
:= -(vel
.X
div 2);
1628 if not WordBool(mr
and MOVE_INWATER
) then
1629 ShellSound_Bounce(Obj
.X
, Obj
.Y
, SType
);
1631 if WordBool(mr
and (MOVE_HITCEIL
or MOVE_HITLAND
)) then
1633 Obj
.Vel
.Y
:= -(vel
.Y
div 2);
1634 if Obj
.Vel
.X
<> 0 then Obj
.Vel
.X
:= Obj
.Vel
.X
div 2;
1635 if (Obj
.Vel
.X
= 0) and (Obj
.Vel
.Y
= 0) then
1637 if RAngle
mod 90 <> 0 then
1638 RAngle
:= (RAngle
div 90) * 90;
1640 else if not WordBool(mr
and MOVE_INWATER
) then
1641 ShellSound_Bounce(Obj
.X
, Obj
.Y
, SType
);
1644 if (Obj
.Vel
.X
>= 0) then
1646 RAngle
:= RAngle
+ Abs(Obj
.Vel
.X
)*8 + Abs(Obj
.Vel
.Y
);
1647 if RAngle
>= 360 then
1648 RAngle
:= RAngle
mod 360;
1649 end else begin // Counter-clockwise
1650 RAngle
:= RAngle
- Abs(Obj
.Vel
.X
)*8 - Abs(Obj
.Vel
.Y
);
1652 RAngle
:= (360 - (Abs(RAngle
) mod 360)) mod 360;
1657 procedure g_Player_DrawCorpses();
1662 if gGibs
<> nil then
1663 for i
:= 0 to High(gGibs
) do
1664 if gGibs
[i
].Live
then
1667 if not g_Obj_Collide(sX
, sY
, sWidth
, sHeight
, @Obj
) then
1670 a
.X
:= Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2);
1671 a
.y
:= Obj
.Rect
.Y
+(Obj
.Rect
.Height
div 2);
1673 e_DrawAdv(ID
, Obj
.X
, Obj
.Y
, 0, True, False, RAngle
, @a
, M_NONE
);
1676 e_DrawAdv(MaskID
, Obj
.X
, Obj
.Y
, 0, True, False, RAngle
, @a
, M_NONE
);
1682 if gCorpses
<> nil then
1683 for i
:= 0 to High(gCorpses
) do
1684 if gCorpses
[i
] <> nil then
1688 procedure g_Player_DrawShells();
1693 if gShells
<> nil then
1694 for i
:= 0 to High(gShells
) do
1695 if gShells
[i
].Live
then
1698 if not g_Obj_Collide(sX
, sY
, sWidth
, sHeight
, @Obj
) then
1704 e_DrawAdv(SpriteID
, Obj
.X
, Obj
.Y
, 0, True, False, RAngle
, @a
, M_NONE
);
1708 procedure g_Player_RemoveAllCorpses();
1714 SetLength(gGibs
, MaxGibs
);
1715 SetLength(gShells
, MaxGibs
);
1719 if gCorpses
<> nil then
1720 for i
:= 0 to High(gCorpses
) do
1724 SetLength(gCorpses
, MaxCorpses
);
1727 procedure g_Player_Corpses_SaveState(var Mem
: TBinMemoryWriter
);
1732 // Ñ÷èòàåì êîëè÷åñòâî ñóùåñòâóþùèõ òðóïîâ:
1734 if gCorpses
<> nil then
1735 for i
:= 0 to High(gCorpses
) do
1736 if gCorpses
[i
] <> nil then
1739 Mem
:= TBinMemoryWriter
.Create((count
+1) * 128);
1741 // Êîëè÷åñòâî òðóïîâ:
1742 Mem
.WriteInt(count
);
1748 for i
:= 0 to High(gCorpses
) do
1749 if gCorpses
[i
] <> nil then
1752 Mem
.WriteString(gCorpses
[i
].FModelName
);
1754 b
:= gCorpses
[i
].Mess
;
1755 Mem
.WriteBoolean(b
);
1756 // Ñîõðàíÿåì äàííûå òðóïà:
1757 gCorpses
[i
].SaveState(Mem
);
1761 procedure g_Player_Corpses_LoadState(var Mem
: TBinMemoryReader
);
1770 g_Player_RemoveAllCorpses();
1772 // Êîëè÷åñòâî òðóïîâ:
1775 if count
> Length(gCorpses
) then
1777 raise EBinSizeError
.Create('g_Player_Corpses_LoadState: Too Many Corpses');
1784 for i
:= 0 to count
-1 do
1787 Mem
.ReadString(str
);
1791 gCorpses
[i
] := TCorpse
.Create(0, 0, str
, b
);
1792 // Çàãðóæàåì äàííûå òðóïà:
1793 gCorpses
[i
].LoadState(Mem
);
1799 procedure TPlayer
.BFGHit();
1801 g_Weapon_BFGHit(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
1802 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2));
1803 if g_Game_IsServer
and g_Game_IsNet
then
1804 MH_SEND_Effect(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
1805 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2),
1809 procedure TPlayer
.ChangeModel(ModelName
: string);
1811 Model
: TPlayerModel
;
1813 Model
:= g_PlayerModel_Get(ModelName
);
1814 if Model
= nil then Exit
;
1820 procedure TPlayer
.SetModel(ModelName
: string);
1824 m
:= g_PlayerModel_Get(ModelName
);
1827 g_SimpleError(Format(_lc
[I_GAME_ERROR_MODEL_FALLBACK
], [ModelName
]));
1828 m
:= g_PlayerModel_Get('doomer');
1831 g_FatalError(Format(_lc
[I_GAME_ERROR_MODEL
], ['doomer']));
1836 if FModel
<> nil then
1841 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
1842 FModel
.Color
:= FColor
1844 FModel
.Color
:= TEAMCOLOR
[FTeam
];
1845 FModel
.SetWeapon(FCurrWeap
);
1846 FModel
.SetFlag(FFlag
);
1847 SetDirection(FDirection
);
1850 procedure TPlayer
.SetColor(Color
: TRGB
);
1853 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
1854 if FModel
<> nil then FModel
.Color
:= Color
;
1857 procedure TPlayer
.SwitchTeam
;
1859 if g_Game_IsClient
then
1861 if not (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then Exit
;
1863 if gGameOn
and FLive
then
1864 Kill(K_SIMPLEKILL
, FUID
, HIT_SELF
);
1866 if FTeam
= TEAM_RED
then
1868 ChangeTeam(TEAM_BLUE
);
1869 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_BLUE
], [FName
]), True);
1870 if g_Game_IsNet
then
1871 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM
, TEAM_BLUE
, FName
);
1875 ChangeTeam(TEAM_RED
);
1876 g_Console_Add(Format(_lc
[I_PLAYER_CHTEAM_RED
], [FName
]), True);
1877 if g_Game_IsNet
then
1878 MH_SEND_GameEvent(NET_EV_CHANGE_TEAM
, TEAM_RED
, FName
);
1880 FPreferredTeam
:= FTeam
;
1883 procedure TPlayer
.ChangeTeam(Team
: Byte);
1890 TEAM_RED
, TEAM_BLUE
:
1891 FModel
.Color
:= TEAMCOLOR
[Team
];
1893 FModel
.Color
:= FColor
;
1895 if (FTeam
<> OldTeam
) and g_Game_IsNet
and g_Game_IsServer
then
1896 MH_SEND_PlayerStats(FUID
);
1900 procedure TPlayer.CollideItem();
1905 if gItems = nil then Exit;
1906 if not FLive then Exit;
1908 for i := 0 to High(gItems) do
1911 if (ItemType <> ITEM_NONE) and Live then
1912 if g_Obj_Collide(FObj.X+PLAYER_RECT.X, FObj.Y+PLAYER_RECT.Y, PLAYER_RECT.Width,
1913 PLAYER_RECT.Height, @Obj) then
1915 if not PickItem(ItemType, gItems[i].Respawnable, r) then Continue;
1917 if ItemType in [ITEM_SPHERE_BLUE, ITEM_SPHERE_WHITE, ITEM_INVUL] then
1918 g_Sound_PlayExAt('SOUND_ITEM_GETRULEZ', FObj.X, FObj.Y)
1919 else if ItemType in [ITEM_MEDKIT_SMALL, ITEM_MEDKIT_LARGE, ITEM_MEDKIT_BLACK] then
1920 g_Sound_PlayExAt('SOUND_ITEM_GETMED', FObj.X, FObj.Y)
1921 else g_Sound_PlayExAt('SOUND_ITEM_GETITEM', FObj.X, FObj.Y);
1923 // Íàäî óáðàòü ñ êàðòû, åñëè ýòî íå êëþ÷, êîòîðûì íóæíî ïîäåëèòñÿ ñ äðóãèì èãðîêîì:
1924 if r and not ((ItemType in [ITEM_KEY_RED, ITEM_KEY_GREEN, ITEM_KEY_BLUE]) and
1925 (gGameSettings.GameType = GT_SINGLE) and
1926 (g_Player_GetCount() > 1)) then
1927 if not Respawnable then g_Items_Remove(i) else g_Items_Pick(i);
1933 function TPlayer
.CollideLevel(XInc
, YInc
: Integer): Boolean;
1935 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
1936 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_WALL
,
1940 constructor TPlayer
.Create();
1946 FSawSound
:= TPlayableSound
.Create();
1947 FSawSoundIdle
:= TPlayableSound
.Create();
1948 FSawSoundHit
:= TPlayableSound
.Create();
1949 FSawSoundSelect
:= TPlayableSound
.Create();
1950 FJetSoundFly
:= TPlayableSound
.Create();
1951 FJetSoundOn
:= TPlayableSound
.Create();
1952 FJetSoundOff
:= TPlayableSound
.Create();
1954 FSawSound
.SetByName('SOUND_WEAPON_FIRESAW');
1955 FSawSoundIdle
.SetByName('SOUND_WEAPON_IDLESAW');
1956 FSawSoundHit
.SetByName('SOUND_WEAPON_HITSAW');
1957 FSawSoundSelect
.SetByName('SOUND_WEAPON_SELECTSAW');
1958 FJetSoundFly
.SetByName('SOUND_PLAYER_JETFLY');
1959 FJetSoundOn
.SetByName('SOUND_PLAYER_JETON');
1960 FJetSoundOff
.SetByName('SOUND_PLAYER_JETOFF');
1962 FSpectatePlayer
:= -1;
1966 FSavedState
.WaitRecall
:= False;
1969 FActualModelName
:= 'doomer';
1972 FObj
.Rect
:= PLAYER_RECT
;
1974 FBFGFireCounter
:= -1;
1975 FJustTeleported
:= False;
1981 procedure TPlayer
.Damage(value
: Word; SpawnerUID
: Word; vx
, vy
: Integer; t
: Byte);
1985 if (not g_Game_IsClient
) and (not FLive
) then
1990 // Íåóÿçâèìîñòü íå ñïàñàåò îò ëîâóøåê:
1991 if ((t
= HIT_TRAP
) or (t
= HIT_SELF
)) and (not FGodMode
) then
1993 if not g_Game_IsClient
then
1996 if t
= HIT_TRAP
then
1998 // Ëîâóøêà óáèâàåò ñðàçó:
2000 Kill(K_EXTRAHARDKILL
, SpawnerUID
, t
);
2002 if t
= HIT_SELF
then
2006 Kill(K_SIMPLEKILL
, SpawnerUID
, t
);
2009 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
2010 FMegaRulez
[MR_SUIT
] := 0;
2011 FMegaRulez
[MR_INVUL
] := 0;
2012 FMegaRulez
[MR_INVIS
] := 0;
2016 // Íî îò îñòàëüíîãî ñïàñàåò:
2017 if FMegaRulez
[MR_INVUL
] >= gTime
then
2024 // Åñëè åñòü óðîí ñâîèì, èëè ðàíèë ñàì ñåáÿ, èëè òåáÿ ðàíèë ïðîòèâíèê:
2025 if LongBool(gGameSettings
.Options
and GAME_OPTION_TEAMDAMAGE
) or
2026 (SpawnerUID
= FUID
) or
2027 (not SameTeam(FUID
, SpawnerUID
)) then
2029 FLastSpawnerUID
:= SpawnerUID
;
2031 // Êðîâü (ïóçûðüêè, åñëè â âîäå):
2032 if gBloodCount
> 0 then
2034 c
:= Min(value
, 200)*gBloodCount
+ Random(Min(value
, 200) div 2);
2035 if value
div 4 <= c
then
2036 c
:= c
- (value
div 4)
2040 if (t
= HIT_SOME
) and (vx
= 0) and (vy
= 0) then
2044 HIT_TRAP
, HIT_ACID
, HIT_FLAME
, HIT_SELF
: MakeBloodSimple(c
);
2045 HIT_BFG
, HIT_ROCKET
, HIT_SOME
: MakeBloodVector(c
, vx
, vy
);
2048 if t
= HIT_WATER
then
2049 g_GFX_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
2050 FObj
.Y
+PLAYER_RECT
.Y
-4, value
div 2, 8, 4);
2055 Inc(FDamageBuffer
, value
);
2059 FPain
:= FPain
+ value
;
2062 if g_Game_IsServer
and g_Game_IsNet
then
2064 MH_SEND_PlayerDamage(FUID
, t
, SpawnerUID
, value
, vx
, vy
);
2065 MH_SEND_PlayerStats(FUID
);
2066 MH_SEND_PlayerPos(False, FUID
);
2070 function TPlayer
.Heal(value
: Word; Soft
: Boolean): Boolean;
2073 if g_Game_IsClient
then
2078 if Soft
and (FHealth
< PLAYER_HP_SOFT
) then
2080 IncMax(FHealth
, value
, PLAYER_HP_SOFT
);
2083 if (not Soft
) and (FHealth
< PLAYER_HP_LIMIT
) then
2085 IncMax(FHealth
, value
, PLAYER_HP_LIMIT
);
2089 if Result
and g_Game_IsServer
and g_Game_IsNet
then
2090 MH_SEND_PlayerStats(FUID
);
2093 destructor TPlayer
.Destroy();
2095 if (gPlayer1
<> nil) and (gPlayer1
.FUID
= FUID
) then
2097 if (gPlayer2
<> nil) and (gPlayer2
.FUID
= FUID
) then
2101 FSawSoundIdle
.Free();
2102 FSawSoundHit
.Free();
2103 FJetSoundFly
.Free();
2105 FJetSoundOff
.Free();
2111 procedure TPlayer
.DrawBubble();
2113 bubX
, bubY
: Integer;
2116 Rw
, Gw
, Bw
: SmallInt;
2119 bubX
:= FObj
.X
+FObj
.Rect
.X
+ IfThen(FDirection
= D_LEFT
, -4, 18);
2120 bubY
:= FObj
.Y
+FObj
.Rect
.Y
- 18;
2128 1: // simple textual non-bubble
2130 bubX
:= FObj
.X
+FObj
.Rect
.X
- 11;
2131 bubY
:= FObj
.Y
+FObj
.Rect
.Y
- 17;
2132 e_TextureFontPrint(bubX
, bubY
, '[...]', gStdFont
);
2135 2: // advanced pixel-perfect bubble
2137 if FTeam
= TEAM_RED
then
2140 if FTeam
= TEAM_BLUE
then
2143 3: // colored bubble
2145 Rb
:= FModel
.Color
.R
;
2146 Gb
:= FModel
.Color
.G
;
2147 Bb
:= FModel
.Color
.B
;
2148 Rw
:= Min(Rb
* 2 + 64, 255);
2149 Gw
:= Min(Gb
* 2 + 64, 255);
2150 Bw
:= Min(Bb
* 2 + 64, 255);
2151 if (Abs(Rw
- Rb
) < 32)
2152 or (Abs(Gw
- Gb
) < 32)
2153 or (Abs(Bw
- Bb
) < 32) then
2155 Rb
:= Max(Rw
div 2 - 16, 0);
2156 Gb
:= Max(Gw
div 2 - 16, 0);
2157 Bb
:= Max(Bw
div 2 - 16, 0);
2160 4: // custom textured bubble
2162 if g_Texture_Get('TEXTURE_PLAYER_TALKBUBBLE', ID
) then
2163 if FDirection
= D_RIGHT
then
2164 e_Draw(ID
, bubX
- 6, bubY
- 7, 0, True, False)
2166 e_Draw(ID
, bubX
- 6, bubY
- 7, 0, True, False, M_HORIZONTAL
);
2172 e_DrawQuad(bubX
+ 1, bubY
, bubX
+ 18, bubY
+ 13, Rb
, Gb
, Bb
);
2173 e_DrawQuad(bubX
, bubY
+ 1, bubX
+ 19, bubY
+ 12, Rb
, Gb
, Bb
);
2175 e_DrawFillQuad(bubX
+ 1, bubY
+ 1, bubX
+ 18, bubY
+ 12, Rw
, Gw
, Bw
, 0);
2178 Dot
:= IfThen(FDirection
= D_LEFT
, 14, 5);
2179 e_DrawLine(1, bubX
+ Dot
, bubY
+ 14, bubX
+ Dot
, bubY
+ 16, Rb
, Gb
, Bb
);
2180 e_DrawLine(1, bubX
+ IfThen(FDirection
= D_LEFT
, Dot
- 1, Dot
+ 1), bubY
+ 13, bubX
+ IfThen(FDirection
= D_LEFT
, Dot
- 1, Dot
+ 1), bubY
+ 15, Rw
, Gw
, Bw
);
2181 e_DrawLine(1, bubX
+ IfThen(FDirection
= D_LEFT
, Dot
- 2, Dot
+ 2), bubY
+ 13, bubX
+ IfThen(FDirection
= D_LEFT
, Dot
- 2, Dot
+ 2), bubY
+ 14, Rw
, Gw
, Bw
);
2182 e_DrawLine(1, bubX
+ IfThen(FDirection
= D_LEFT
, Dot
- 3, Dot
+ 3), bubY
+ 13, bubX
+ IfThen(FDirection
= D_LEFT
, Dot
- 3, Dot
+ 3), bubY
+ 13, Rw
, Gw
, Bw
);
2183 e_DrawLine(1, bubX
+ IfThen(FDirection
= D_LEFT
, Dot
- 3, Dot
+ 3), bubY
+ 14, bubX
+ IfThen(FDirection
= D_LEFT
, Dot
- 1, Dot
+ 1), bubY
+ 16, Rb
, Gb
, Bb
);
2187 e_DrawFillQuad(bubX
+ Dot
, bubY
+ 8, bubX
+ Dot
+ 1, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2188 e_DrawFillQuad(bubX
+ Dot
+ 3, bubY
+ 8, bubX
+ Dot
+ 4, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2189 e_DrawFillQuad(bubX
+ Dot
+ 6, bubY
+ 8, bubX
+ Dot
+ 7, bubY
+ 9, Rb
, Gb
, Bb
, 0);
2192 procedure TPlayer
.Draw();
2200 if (FMegaRulez
[MR_INVUL
] > gTime
) and (gPlayerDrawn
<> Self
) then
2201 if g_Texture_Get('TEXTURE_PLAYER_INVULPENTA', ID
) then
2203 e_GetTextureSize(ID
, @w
, @h
);
2204 if FDirection
= D_LEFT
then
2205 e_Draw(ID
, FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2)-(w
div 2)+4,
2206 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2)-(h
div 2)-7, 0, True, False)
2208 e_Draw(ID
, FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2)-(w
div 2)-2,
2209 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2)-(h
div 2)-7, 0, True, False);
2212 if FMegaRulez
[MR_INVIS
] > gTime
then
2214 if (gPlayerDrawn
<> nil) and ((Self
= gPlayerDrawn
) or
2215 ((FTeam
= gPlayerDrawn
.Team
) and (gGameSettings
.GameMode
<> GM_DM
))) then
2217 if (FMegaRulez
[MR_INVIS
] - gTime
) <= 2100 then
2218 dr
:= not Odd((FMegaRulez
[MR_INVIS
] - gTime
) div 300)
2222 FModel
.Draw(FObj
.X
, FObj
.Y
, 200)
2224 FModel
.Draw(FObj
.X
, FObj
.Y
);
2227 FModel
.Draw(FObj
.X
, FObj
.Y
, 254);
2230 FModel
.Draw(FObj
.X
, FObj
.Y
);
2233 if g_debug_Frames
then
2235 e_DrawQuad(FObj
.X
+FObj
.Rect
.X
,
2237 FObj
.X
+FObj
.Rect
.X
+FObj
.Rect
.Width
-1,
2238 FObj
.Y
+FObj
.Rect
.Y
+FObj
.Rect
.Height
-1,
2242 if (gChatBubble
> 0) and (FKeys
[KEY_CHAT
].Pressed
) and not FGhost
then
2244 // e_DrawPoint(5, 335, 288, 255, 0, 0); // DL, UR, DL, UR
2245 if gAimLine
and Live
and
2246 ((Self
= gPlayer1
) or (Self
= gPlayer2
)) then
2250 procedure TPlayer
.DrawAim();
2252 wx
, wy
, xx
, yy
: Integer;
2256 wx
:= FObj
.X
+ WEAPONPOINT
[FDirection
].X
+ IfThen(FDirection
= D_LEFT
, 7, -7);
2257 wy
:= FObj
.Y
+ WEAPONPOINT
[FDirection
].Y
;
2266 1: begin // Chainsaw
2273 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2274 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2275 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2276 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2281 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2282 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2283 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2284 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2286 4: begin // Double Shotgun
2289 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2290 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2291 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2292 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2294 5: begin // Chaingun
2297 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2298 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2299 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2300 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2302 6: begin // Rocket Launcher
2305 if angle
= ANGLE_RIGHTUP
then Inc(angle
, 2);
2306 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2307 if angle
= ANGLE_LEFTUP
then Dec(angle
, 2);
2308 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2310 7: begin // Plasmagun
2313 if angle
= ANGLE_RIGHTUP
then Inc(angle
);
2314 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 3);
2315 if angle
= ANGLE_LEFTUP
then Dec(angle
);
2316 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 3);
2321 if angle
= ANGLE_RIGHTUP
then Inc(angle
, 1);
2322 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 2);
2323 if angle
= ANGLE_LEFTUP
then Dec(angle
, 1);
2324 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 2);
2326 9: begin // Super Chaingun
2329 if angle
= ANGLE_RIGHTUP
then Dec(angle
, 2);
2330 if angle
= ANGLE_RIGHTDOWN
then Inc(angle
, 4);
2331 if angle
= ANGLE_LEFTUP
then Inc(angle
, 2);
2332 if angle
= ANGLE_LEFTDOWN
then Dec(angle
, 4);
2335 xx
:= Trunc(Cos(-DegToRad(angle
)) * len
) + wx
;
2336 yy
:= Trunc(Sin(-DegToRad(angle
)) * len
) + wy
;
2337 e_DrawLine(sz
, wx
, wy
, xx
, yy
, 255, 0, 0, 96);
2340 procedure TPlayer
.DrawGUI();
2343 X
, Y
, SY
, a
, p
, m
: Integer;
2347 stat
: TPlayerStatArray
;
2349 X
:= gPlayerScreenSize
.X
;
2350 SY
:= gPlayerScreenSize
.Y
;
2353 if gShowGoals
and (gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
]) then
2355 if gGameSettings
.GameMode
= GM_CTF
then
2359 if gGameSettings
.GameMode
= GM_CTF
then
2361 s
:= 'TEXTURE_PLAYER_REDFLAG';
2362 if gFlags
[FLAG_RED
].State
= FLAG_STATE_CAPTURED
then
2363 s
:= 'TEXTURE_PLAYER_REDFLAG_S';
2364 if gFlags
[FLAG_RED
].State
= FLAG_STATE_DROPPED
then
2365 s
:= 'TEXTURE_PLAYER_REDFLAG_D';
2366 if g_Texture_Get(s
, ID
) then
2367 e_Draw(ID
, X
-16-32, 240-72-4, 0, True, False);
2370 s
:= IntToStr(gTeamStat
[TEAM_RED
].Goals
);
2371 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2372 e_CharFont_PrintEx(gMenuFont
, X
-16-a
-tw
, 240-72-4, s
, TEAMCOLOR
[TEAM_RED
]);
2374 if gGameSettings
.GameMode
= GM_CTF
then
2376 s
:= 'TEXTURE_PLAYER_BLUEFLAG';
2377 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_CAPTURED
then
2378 s
:= 'TEXTURE_PLAYER_BLUEFLAG_S';
2379 if gFlags
[FLAG_BLUE
].State
= FLAG_STATE_DROPPED
then
2380 s
:= 'TEXTURE_PLAYER_BLUEFLAG_D';
2381 if g_Texture_Get(s
, ID
) then
2382 e_Draw(ID
, X
-16-32, 240-32-4, 0, True, False);
2385 s
:= IntToStr(gTeamStat
[TEAM_BLUE
].Goals
);
2386 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2387 e_CharFont_PrintEx(gMenuFont
, X
-16-a
-tw
, 240-32-4, s
, TEAMCOLOR
[TEAM_BLUE
]);
2390 if g_Texture_Get('TEXTURE_PLAYER_HUDBG', ID
) then
2391 e_DrawFill(ID
, X
, 0, 1, (gPlayerScreenSize
.Y
div 256)+IfThen(gPlayerScreenSize
.Y
mod 256 > 0, 1, 0),
2394 if g_Texture_Get('TEXTURE_PLAYER_HUD', ID
) then
2395 e_Draw(ID
, X
+2, Y
, 0, True, False);
2397 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
2401 s
:= IntToStr(Frags
);
2402 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2403 e_CharFont_PrintEx(gMenuFont
, X
-16-tw
, Y
, s
, _RGB(255, 0, 0));
2408 stat
:= g_Player_GetStats();
2413 for a
:= 0 to High(stat
) do
2414 if stat
[a
].Name
<> Name
then
2416 if stat
[a
].Frags
> m
then m
:= stat
[a
].Frags
;
2417 if stat
[a
].Frags
> Frags
then p
:= p
+1;
2421 s
:= IntToStr(p
)+' / '+IntToStr(Length(stat
))+' ';
2422 if Frags
>= m
then s
:= s
+'+' else s
:= s
+'-';
2423 s
:= s
+IntToStr(Abs(Frags
-m
));
2425 e_CharFont_GetSize(gMenuSmallFont
, s
, tw
, th
);
2426 e_CharFont_PrintEx(gMenuSmallFont
, X
-16-tw
, Y
+32, s
, _RGB(255, 0, 0));
2429 if gShowLives
and (gGameSettings
.MaxLives
> 0) then
2431 s
:= IntToStr(Lives
);
2432 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2433 e_CharFont_PrintEx(gMenuFont
, X
-16-tw
, SY
-32, s
, _RGB(0, 255, 0));
2437 e_CharFont_GetSize(gMenuSmallFont
, FName
, tw
, th
);
2438 e_CharFont_PrintEx(gMenuSmallFont
, X
+98-(tw
div 2), Y
+8, FName
, _RGB(255, 0, 0));
2440 if R_BERSERK
in FRulez
then
2441 e_Draw(gItemsTexturesID
[ITEM_MEDKIT_BLACK
], X
+37, Y
+45, 0, True, False)
2443 e_Draw(gItemsTexturesID
[ITEM_MEDKIT_LARGE
], X
+37, Y
+45, 0, True, False);
2445 if g_Texture_Get('TEXTURE_PLAYER_ARMORHUD', ID
) then
2446 e_Draw(ID
, X
+36, Y
+77, 0, True, False);
2448 s
:= IntToStr(IfThen(FHealth
> 0, FHealth
, 0));
2449 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2450 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+40, s
, _RGB(255, 0, 0));
2452 s
:= IntToStr(FArmor
);
2453 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2454 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+68, s
, _RGB(255, 0, 0));
2456 s
:= IntToStr(GetAmmoByWeapon(FCurrWeap
));
2462 ID
:= gItemsTexturesID
[ITEM_WEAPON_KASTET
];
2467 ID
:= gItemsTexturesID
[ITEM_WEAPON_SAW
];
2469 WEAPON_PISTOL
: ID
:= gItemsTexturesID
[ITEM_WEAPON_PISTOL
];
2470 WEAPON_CHAINGUN
: ID
:= gItemsTexturesID
[ITEM_WEAPON_CHAINGUN
];
2471 WEAPON_SHOTGUN1
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SHOTGUN1
];
2472 WEAPON_SHOTGUN2
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SHOTGUN2
];
2473 WEAPON_SUPERPULEMET
: ID
:= gItemsTexturesID
[ITEM_WEAPON_SUPERPULEMET
];
2474 WEAPON_ROCKETLAUNCHER
: ID
:= gItemsTexturesID
[ITEM_WEAPON_ROCKETLAUNCHER
];
2475 WEAPON_PLASMA
: ID
:= gItemsTexturesID
[ITEM_WEAPON_PLASMA
];
2476 WEAPON_BFG
: ID
:= gItemsTexturesID
[ITEM_WEAPON_BFG
];
2479 e_CharFont_GetSize(gMenuFont
, s
, tw
, th
);
2480 e_CharFont_PrintEx(gMenuFont
, X
+178-tw
, Y
+158, s
, _RGB(255, 0, 0));
2481 e_Draw(ID
, X
+20, Y
+160, 0, True, False);
2483 if R_KEY_RED
in FRulez
then
2484 e_Draw(gItemsTexturesID
[ITEM_KEY_RED
], X
+78, Y
+214, 0, True, False);
2486 if R_KEY_GREEN
in FRulez
then
2487 e_Draw(gItemsTexturesID
[ITEM_KEY_GREEN
], X
+95, Y
+214, 0, True, False);
2489 if R_KEY_BLUE
in FRulez
then
2490 e_Draw(gItemsTexturesID
[ITEM_KEY_BLUE
], X
+112, Y
+214, 0, True, False);
2492 if FJetFuel
> 0 then
2494 if g_Texture_Get('TEXTURE_PLAYER_HUDAIR', ID
) then
2495 e_Draw(ID
, X
+2, Y
+116, 0, True, False);
2496 if g_Texture_Get('TEXTURE_PLAYER_HUDJET', ID
) then
2497 e_Draw(ID
, X
+2, Y
+126, 0, True, False);
2498 e_DrawLine(4, X
+16, Y
+122, X
+16+Trunc(168*IfThen(FAir
> 0, FAir
, 0)/AIR_MAX
), Y
+122, 0, 0, 196);
2499 e_DrawLine(4, X
+16, Y
+132, X
+16+Trunc(168*FJetFuel
/JET_MAX
), Y
+132, 208, 0, 0);
2503 if g_Texture_Get('TEXTURE_PLAYER_HUDAIR', ID
) then
2504 e_Draw(ID
, X
+2, Y
+124, 0, True, False);
2505 e_DrawLine(4, X
+16, Y
+130, X
+16+Trunc(168*IfThen(FAir
> 0, FAir
, 0)/AIR_MAX
), Y
+130, 0, 0, 196);
2508 if gShowPing
and g_Game_IsClient
then
2510 s
:= _lc
[I_GAME_PING_HUD
] + IntToStr(NetPeer
.lastRoundTripTime
) + _lc
[I_NET_SLIST_PING_MS
];
2511 e_TextureFontPrint(X
+ 4, Y
+ 242, s
, gStdFont
);
2517 e_TextureFontPrint(X
+ 4, Y
+ 242, _lc
[I_PLAYER_SPECT
], gStdFont
);
2518 e_TextureFontPrint(X
+ 4, Y
+ 258, _lc
[I_PLAYER_SPECT2
], gStdFont
);
2519 e_TextureFontPrint(X
+ 4, Y
+ 274, _lc
[I_PLAYER_SPECT1
], gStdFont
);
2522 e_TextureFontGetSize(gStdFont
, cw
, ch
);
2523 s
:= _lc
[I_PLAYER_SPECT4
];
2524 e_TextureFontPrintEx(gScreenWidth
div 2 - cw
*(Length(s
) div 2),
2525 gScreenHeight
-4-ch
, s
, gStdFont
, 255, 255, 255, 1, True);
2526 e_TextureFontPrint(X
+ 4, Y
+ 290, _lc
[I_PLAYER_SPECT1S
], gStdFont
);
2532 procedure TPlayer
.DrawRulez();
2536 // Ïðè âçÿòèè íåóÿçâèìîñòè ðèñóåòñÿ èíâåðñèîííûé áåëûé ôîí
2537 if FMegaRulez
[MR_INVUL
] >= gTime
then
2539 if (FMegaRulez
[MR_INVUL
]-gTime
) <= 2100 then
2540 dr
:= not Odd((FMegaRulez
[MR_INVUL
]-gTime
) div 300)
2545 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2546 191, 191, 191, 0, B_INVERT
);
2549 // Ïðè âçÿòèè çàùèòíîãî êîñòþìà ðèñóåòñÿ çåëåíîâàòûé ôîí
2550 if FMegaRulez
[MR_SUIT
] >= gTime
then
2552 if (FMegaRulez
[MR_SUIT
]-gTime
) <= 2100 then
2553 dr
:= not Odd((FMegaRulez
[MR_SUIT
]-gTime
) div 300)
2558 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2559 0, 96, 0, 200, B_NONE
);
2562 // Ïðè âçÿòèè áåðñåðêà ðèñóåòñÿ êðàñíîâàòûé ôîí
2563 if (FBerserk
>= 0) and (LongWord(FBerserk
) >= gTime
) and (gFlash
= 2) then
2565 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1,
2566 255, 0, 0, 200, B_NONE
);
2570 procedure TPlayer
.DrawPain();
2574 if FPain
= 0 then Exit
;
2578 if a
< 15 then h
:= 0
2579 else if a
< 35 then h
:= 1
2580 else if a
< 55 then h
:= 2
2581 else if a
< 75 then h
:= 3
2582 else if a
< 95 then h
:= 4
2585 //if a > 255 then a := 255;
2587 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1, 255, 0, 0, 255-h
*50);
2588 //e_DrawFillQuad(0, 0, gPlayerScreenSize.X-1, gPlayerScreenSize.Y-1, 255-min(128, a), 255-a, 255-a, 0, B_FILTER);
2591 procedure TPlayer
.DrawPickup();
2595 if FPickup
= 0 then Exit
;
2599 if a
< 15 then h
:= 1
2600 else if a
< 35 then h
:= 2
2601 else if a
< 55 then h
:= 3
2602 else if a
< 75 then h
:= 4
2605 e_DrawFillQuad(0, 0, gPlayerScreenSize
.X
-1, gPlayerScreenSize
.Y
-1, 150, 200, 150, 255-h
*50);
2608 procedure TPlayer
.Fire();
2610 f
, DidFire
: Boolean;
2611 wx
, wy
, xd
, yd
: Integer;
2614 if g_Game_IsClient
then Exit
;
2615 // FBFGFireCounter - âðåìÿ ïåðåä âûñòðåëîì (äëÿ BFG)
2616 // FReloading - âðåìÿ ïîñëå âûñòðåëà (äëÿ âñåãî)
2624 if FReloading
[FCurrWeap
] <> 0 then Exit
;
2629 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
2630 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
2631 xd
:= wx
+IfThen(FDirection
= D_LEFT
, -30, 30);
2632 yd
:= wy
+firediry();
2637 if R_BERSERK
in FRulez
then
2639 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
2640 obj
.X
:= FObj
.X
+FObj
.Rect
.X
;
2641 obj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
2644 obj
.rect
.Width
:= 39;
2645 obj
.rect
.Height
:= 52;
2646 obj
.Vel
.X
:= (xd
-wx
) div 2;
2647 obj
.Vel
.Y
:= (yd
-wy
) div 2;
2648 obj
.Accel
.X
:= xd
-wx
;
2649 obj
.Accel
.y
:= yd
-wy
;
2651 if g_Weapon_Hit(@obj
, 50, FUID
, HIT_SOME
) <> 0 then
2652 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
2654 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
2658 FPain
:= min(FPain
+ 25, 50);
2659 end else g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
2662 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2667 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
2668 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
2670 FSawSoundSelect
.Stop();
2672 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
2674 else if not FSawSoundHit
.IsPlaying() then
2676 FSawSoundSelect
.Stop();
2677 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
2680 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2686 if FAmmo
[A_BULLETS
] > 0 then
2688 g_Weapon_pistol(wx
, wy
, xd
, yd
, FUID
);
2689 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2690 Dec(FAmmo
[A_BULLETS
]);
2691 FFireAngle
:= FAngle
;
2694 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
2695 GameVelX
, GameVelY
-2, SHELL_BULLET
);
2699 if FAmmo
[A_SHELLS
] > 0 then
2701 g_Weapon_shotgun(wx
, wy
, xd
, yd
, FUID
);
2702 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', wx
, wy
);
2703 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2704 Dec(FAmmo
[A_SHELLS
]);
2705 FFireAngle
:= FAngle
;
2709 FShellType
:= SHELL_SHELL
;
2713 if FAmmo
[A_SHELLS
] >= 2 then
2715 g_Weapon_dshotgun(wx
, wy
, xd
, yd
, FUID
);
2716 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2717 Dec(FAmmo
[A_SHELLS
], 2);
2718 FFireAngle
:= FAngle
;
2722 FShellType
:= SHELL_DBLSHELL
;
2726 if FAmmo
[A_BULLETS
] > 0 then
2728 g_Weapon_mgun(wx
, wy
, xd
, yd
, FUID
);
2729 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', wx
, wy
);
2730 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2731 Dec(FAmmo
[A_BULLETS
]);
2732 FFireAngle
:= FAngle
;
2735 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
2736 GameVelX
, GameVelY
-2, SHELL_BULLET
);
2739 WEAPON_ROCKETLAUNCHER
:
2740 if FAmmo
[A_ROCKETS
] > 0 then
2742 g_Weapon_rocket(wx
, wy
, xd
, yd
, FUID
);
2743 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2744 Dec(FAmmo
[A_ROCKETS
]);
2745 FFireAngle
:= FAngle
;
2751 if FAmmo
[A_CELLS
] > 0 then
2753 g_Weapon_plasma(wx
, wy
, xd
, yd
, FUID
);
2754 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2755 Dec(FAmmo
[A_CELLS
]);
2756 FFireAngle
:= FAngle
;
2762 if (FAmmo
[A_CELLS
] >= 40) and (FBFGFireCounter
= -1) then
2764 FBFGFireCounter
:= 17;
2765 if not FNoReload
then
2766 g_Sound_PlayExAt('SOUND_WEAPON_STARTFIREBFG', FObj
.X
, FObj
.Y
);
2767 Dec(FAmmo
[A_CELLS
], 40);
2771 WEAPON_SUPERPULEMET
:
2772 if FAmmo
[A_SHELLS
] > 0 then
2774 g_Weapon_shotgun(wx
, wy
, xd
, yd
, FUID
);
2775 if not gSoundEffectsDF
then g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', wx
, wy
);
2776 FReloading
[FCurrWeap
] := WEAPON_RELOAD
[FCurrWeap
];
2777 Dec(FAmmo
[A_SHELLS
]);
2778 FFireAngle
:= FAngle
;
2781 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
2782 GameVelX
, GameVelY
-2, SHELL_SHELL
);
2786 if g_Game_IsNet
then
2790 if FCurrWeap
<> WEAPON_BFG
then
2791 MH_SEND_PlayerFire(FUID
, FCurrWeap
, wx
, wy
, xd
, yd
, LastShotID
)
2793 if not FNoReload
then
2794 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_WEAPON_STARTFIREBFG');
2797 MH_SEND_PlayerStats(FUID
);
2802 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
2803 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
2804 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
2807 function TPlayer
.GetAmmoByWeapon(Weapon
: Byte): Word;
2810 WEAPON_PISTOL
, WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
];
2811 WEAPON_SHOTGUN1
, WEAPON_SHOTGUN2
, WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
];
2812 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
];
2813 WEAPON_PLASMA
, WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
];
2818 function TPlayer
.HeadInLiquid(XInc
, YInc
: Integer): Boolean;
2820 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
+XInc
, FObj
.Y
+PLAYER_HEADRECT
.Y
+YInc
,
2821 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
2822 PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, True);
2825 procedure TPlayer
.JetpackOn
;
2829 FJetSoundOn
.SetPosition(0);
2830 FJetSoundOn
.PlayAt(FObj
.X
, FObj
.Y
);
2834 procedure TPlayer
.JetpackOff
;
2838 FJetSoundOff
.SetPosition(0);
2839 FJetSoundOff
.PlayAt(FObj
.X
, FObj
.Y
);
2842 procedure TPlayer
.Jump();
2844 if gFly
or FJetpack
then
2846 // Ïîëåò (÷èò-êîä èëè äæåòïàê):
2847 if FObj
.Vel
.Y
> -VEL_FLY
then
2848 FObj
.Vel
.Y
:= FObj
.Vel
.Y
- 3;
2851 if FJetFuel
> 0 then
2853 if (FJetFuel
< 1) and g_Game_IsServer
then
2857 if g_Game_IsNet
then
2858 MH_SEND_PlayerStats(FUID
);
2864 // Íå âêëþ÷àòü äæåòïàê â ðåæèìå ïðîõîæäåíèÿ ñêâîçü ñòåíû
2866 FCanJetpack
:= False;
2868 // Ïðûãàåì èëè âñïëûâàåì:
2869 if (CollideLevel(0, 1) or
2870 g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
+36, PLAYER_RECT
.Width
,
2871 PLAYER_RECT
.Height
-33, PANEL_STEP
, False)
2872 ) and (FObj
.Accel
.Y
= 0) then // Íå ïðûãàòü, åñëè åñòü âåðòèêàëüíîå óñêîðåíèå
2874 FObj
.Vel
.Y
:= -VEL_JUMP
;
2875 FCanJetpack
:= False;
2879 if BodyInLiquid(0, 0) then
2880 FObj
.Vel
.Y
:= -VEL_SW
2881 else if (FJetFuel
> 0) and FCanJetpack
and
2882 g_Game_IsServer
and (not g_Obj_CollideLiquid(@FObj
, 0, 0)) then
2886 if g_Game_IsNet
then
2887 MH_SEND_PlayerStats(FUID
);
2892 procedure TPlayer
.Kill(KillType
: Byte; SpawnerUID
: Word; t
: Byte);
2894 a
, i
, k
, ab
, ar
: Byte;
2898 srv
, netsrv
: Boolean;
2903 procedure PushItem(t
: Byte);
2907 id
:= g_Items_Create(FObj
.X
, FObj
.Y
, t
, True, False);
2908 if KillType
= K_EXTRAHARDKILL
then // -7..+7; -8..0
2909 g_Obj_Push(@gItems
[id
].Obj
, (FObj
.Vel
.X
div 2)-7+Random(15),
2910 (FObj
.Vel
.Y
div 2)-Random(9))
2912 if KillType
= K_HARDKILL
then // -5..+5; -5..0
2913 g_Obj_Push(@gItems
[id
].Obj
, (FObj
.Vel
.X
div 2)-5+Random(11),
2914 (FObj
.Vel
.Y
div 2)-Random(6))
2915 else // -3..+3; -3..0
2916 g_Obj_Push(@gItems
[id
].Obj
, (FObj
.Vel
.X
div 2)-3+Random(7),
2917 (FObj
.Vel
.Y
div 2)-Random(4));
2919 if g_Game_IsNet
and g_Game_IsServer
then
2920 MH_SEND_ItemSpawn(True, id
);
2924 DoFrags
:= (gGameSettings
.MaxLives
= 0) or (gGameSettings
.GameMode
= GM_COOP
);
2925 Srv
:= g_Game_IsServer
;
2926 Netsrv
:= g_Game_IsServer
and g_Game_IsNet
;
2927 if Srv
then FDeath
:= FDeath
+ 1;
2932 if not FPhysics
then
2938 if (gGameSettings
.MaxLives
> 0) and Srv
and (gLMSRespawn
= LMS_RESPAWN_NONE
) then
2940 if FLives
> 0 then FLives
:= FLives
- 1;
2941 if FLives
= 0 then FNoRespawn
:= True;
2944 // Íîìåð òèïà ñìåðòè:
2947 K_SIMPLEKILL
: a
:= 1;
2949 K_EXTRAHARDKILL
: a
:= 3;
2954 if not FModel
.PlaySound(MODELSOUND_DIE
, a
, FObj
.X
, FObj
.Y
) then
2956 if FModel
.PlaySound(MODELSOUND_DIE
, i
, FObj
.X
, FObj
.Y
) then
2963 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN1
;
2965 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN2
;
2966 K_EXTRAHARDKILL
, K_FALLKILL
:
2967 FTime
[T_RESPAWN
] := gTime
+ TIME_RESPAWN3
;
2970 // Ïåðåêëþ÷àåì ñîñòîÿíèå:
2974 K_HARDKILL
, K_EXTRAHARDKILL
:
2978 // Ðåàêöèÿ ìîíñòðîâ íà ñìåðòü èãðîêà:
2979 if (KillType
<> K_FALLKILL
) and (Srv
) then
2980 g_Monsters_killedp();
2982 if SpawnerUID
= FUID
then
2984 if Srv
and (DoFrags
or (gGameSettings
.GameMode
= GM_TDM
)) then
2989 g_Console_Add(Format(_lc
[I_PLAYER_KILL_SELF
], [FName
]), True);
2992 if g_GetUIDType(SpawnerUID
) = UID_PLAYER
then
2993 begin // Óáèò äðóãèì èãðîêîì
2994 KP
:= g_Player_Get(SpawnerUID
);
2995 if (KP
<> nil) and Srv
then
2997 if (DoFrags
or (gGameSettings
.GameMode
= GM_TDM
)) then
2998 if SameTeam(FUID
, SpawnerUID
) then
3008 if (gGameSettings
.GameMode
= GM_TDM
) and DoFrags
then
3009 Inc(gTeamStat
[KP
.Team
].Goals
,
3010 IfThen(SameTeam(FUID
, SpawnerUID
), -1, 1));
3012 if netsrv
then MH_SEND_PlayerStats(SpawnerUID
);
3015 plr
:= g_Player_Get(SpawnerUID
);
3023 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_2
],
3027 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_1
],
3031 g_Console_Add(Format(_lc
[I_PLAYER_KILL
],
3036 else if g_GetUIDType(SpawnerUID
) = UID_MONSTER
then
3037 begin // Óáèò ìîíñòðîì
3038 mon
:= g_Monsters_Get(SpawnerUID
);
3042 s
:= g_Monsters_GetKilledBy(mon
.MonsterType
);
3046 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_2
],
3050 g_Console_Add(Format(_lc
[I_PLAYER_KILL_EXTRAHARD_1
],
3054 g_Console_Add(Format(_lc
[I_PLAYER_KILL
],
3059 else // Îñîáûå òèïû ñìåðòè
3062 HIT_SELF
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_SELF
], [FName
]), True);
3063 HIT_FALL
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_FALL
], [FName
]), True);
3064 HIT_WATER
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_WATER
], [FName
]), True);
3065 HIT_ACID
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_ACID
], [FName
]), True);
3066 HIT_TRAP
: g_Console_Add(Format(_lc
[I_PLAYER_KILL_TRAP
], [FName
]), True);
3067 else g_Console_Add(Format(_lc
[I_PLAYER_DIED
], [FName
]), True);
3073 for a
:= WEAPON_KASTET
to WEAPON_SUPERPULEMET
do
3077 WEAPON_SAW
: i
:= ITEM_WEAPON_SAW
;
3078 WEAPON_SHOTGUN1
: i
:= ITEM_WEAPON_SHOTGUN1
;
3079 WEAPON_SHOTGUN2
: i
:= ITEM_WEAPON_SHOTGUN2
;
3080 WEAPON_CHAINGUN
: i
:= ITEM_WEAPON_CHAINGUN
;
3081 WEAPON_ROCKETLAUNCHER
: i
:= ITEM_WEAPON_ROCKETLAUNCHER
;
3082 WEAPON_PLASMA
: i
:= ITEM_WEAPON_PLASMA
;
3083 WEAPON_BFG
: i
:= ITEM_WEAPON_BFG
;
3084 WEAPON_SUPERPULEMET
: i
:= ITEM_WEAPON_SUPERPULEMET
;
3093 if R_ITEM_BACKPACK
in FRulez
then
3094 PushItem(ITEM_AMMO_BACKPACK
);
3096 // Âûáðîñ ðàêåòíîãî ðàíöà:
3097 if FJetFuel
> 0 then
3098 PushItem(ITEM_JETPACK
);
3101 if not (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
]) then
3103 if R_KEY_RED
in FRulez
then
3104 PushItem(ITEM_KEY_RED
);
3106 if R_KEY_GREEN
in FRulez
then
3107 PushItem(ITEM_KEY_GREEN
);
3109 if R_KEY_BLUE
in FRulez
then
3110 PushItem(ITEM_KEY_BLUE
);
3117 g_Player_CreateCorpse(Self
);
3119 if Srv
and (gGameSettings
.MaxLives
> 0) and FNoRespawn
and
3120 (gLMSRespawn
= LMS_RESPAWN_NONE
) then
3126 for i
:= Low(gPlayers
) to High(gPlayers
) do
3128 if gPlayers
[i
] = nil then continue
;
3129 if (not gPlayers
[i
].FNoRespawn
) and (not gPlayers
[i
].FSpectator
) then
3132 if gPlayers
[i
].FTeam
= TEAM_RED
then Inc(ar
)
3133 else if gPlayers
[i
].FTeam
= TEAM_BLUE
then Inc(ab
);
3138 OldLR
:= gLMSRespawn
;
3139 if (gGameSettings
.GameMode
= GM_COOP
) then
3143 // everyone is dead, restart the map
3144 g_Game_Message(_lc
[I_MESSAGE_LMS_LOSE
], 144);
3146 MH_SEND_GameEvent(NET_EV_LMS_LOSE
);
3147 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3148 gLMSRespawnTime
:= gTime
+ 5000;
3150 else if (a
= 1) then
3152 if (gPlayers
[k
] <> nil) and not (gPlayers
[k
] is TBot
) then
3153 if (gPlayers
[k
] = gPlayer1
) or
3154 (gPlayers
[k
] = gPlayer2
) then
3155 g_Console_Add('*** ' + _lc
[I_MESSAGE_LMS_SURVIVOR
] + ' ***', True)
3156 else if Netsrv
and (gPlayers
[k
].FClientID
>= 0) then
3157 MH_SEND_GameEvent(NET_EV_LMS_SURVIVOR
, 0, 'N', gPlayers
[k
].FClientID
);
3160 else if (gGameSettings
.GameMode
= GM_TDM
) then
3162 if (ab
= 0) and (ar
<> 0) then
3165 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_RED
])]), 144);
3167 MH_SEND_GameEvent(NET_EV_TLMS_WIN
, TEAM_RED
);
3168 Inc(gTeamStat
[TEAM_RED
].Goals
);
3169 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3170 gLMSRespawnTime
:= gTime
+ 5000;
3172 else if (ar
= 0) and (ab
<> 0) then
3175 g_Game_Message(Format(_lc
[I_MESSAGE_TLMS_WIN
], [AnsiUpperCase(_lc
[I_GAME_TEAM_BLUE
])]), 144);
3177 MH_SEND_GameEvent(NET_EV_TLMS_WIN
, TEAM_BLUE
);
3178 Inc(gTeamStat
[TEAM_BLUE
].Goals
);
3179 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3180 gLMSRespawnTime
:= gTime
+ 5000;
3182 else if (ar
= 0) and (ab
= 0) then
3185 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
3187 MH_SEND_GameEvent(NET_EV_LMS_DRAW
, 0, FName
);
3188 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3189 gLMSRespawnTime
:= gTime
+ 5000;
3192 else if (gGameSettings
.GameMode
= GM_DM
) then
3196 if gPlayers
[k
] <> nil then
3199 // survivor is the winner
3200 g_Game_Message(Format(_lc
[I_MESSAGE_LMS_WIN
], [AnsiUpperCase(FName
)]), 144);
3202 MH_SEND_GameEvent(NET_EV_LMS_WIN
, 0, FName
);
3205 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3206 gLMSRespawnTime
:= gTime
+ 5000;
3208 else if (a
= 0) then
3210 // everyone is dead, restart the map
3211 g_Game_Message(_lc
[I_GAME_WIN_DRAW
], 144);
3213 MH_SEND_GameEvent(NET_EV_LMS_DRAW
, 0, FName
);
3214 gLMSRespawn
:= LMS_RESPAWN_FINAL
;
3215 gLMSRespawnTime
:= gTime
+ 5000;
3218 if srv
and (OldLR
= LMS_RESPAWN_NONE
) and (gLMSRespawn
> LMS_RESPAWN_NONE
) then
3220 if NetMode
= NET_SERVER
then
3221 MH_SEND_GameEvent(NET_EV_LMS_WARMUP
, (gLMSRespawnTime
- gTime
) div 1000)
3223 g_Console_Add(Format(_lc
[I_MSG_WARMUP_START
], [(gLMSRespawnTime
- gTime
) div 1000]), True);
3229 MH_SEND_PlayerStats(FUID
);
3230 MH_SEND_PlayerDeath(FUID
, KillType
, t
, SpawnerUID
);
3231 if gGameSettings
.GameMode
= GM_TDM
then MH_SEND_GameStats
;
3234 if srv
and FNoRespawn
then Spectate(True);
3235 FWantsInGame
:= True;
3238 function TPlayer
.BodyInLiquid(XInc
, YInc
: Integer): Boolean;
3240 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
, PLAYER_RECT
.Width
,
3241 PLAYER_RECT
.Height
-20, PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, False);
3244 function TPlayer
.BodyInAcid(XInc
, YInc
: Integer): Boolean;
3246 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
, PLAYER_RECT
.Width
,
3247 PLAYER_RECT
.Height
-20, PANEL_ACID1
or PANEL_ACID2
, False);
3250 procedure TPlayer
.MakeBloodSimple(Count
: Word);
3252 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)+8,
3253 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3254 Count
div 2, 3, -1, 16, (PLAYER_RECT
.Height
*2 div 3),
3256 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-8,
3257 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3258 Count
div 2, -3, -1, 16, (PLAYER_RECT
.Height
*2) div 3,
3262 procedure TPlayer
.MakeBloodVector(Count
: Word; VelX
, VelY
: Integer);
3264 g_GFX_Blood(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2),
3265 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2),
3266 Count
, VelX
, VelY
, 16, (PLAYER_RECT
.Height
*2) div 3,
3270 procedure TPlayer
.QueueWeaponSwitch(Weapon
: Byte);
3272 if g_Game_IsClient
then Exit
;
3273 if Weapon
> High(FWeapon
) then Exit
;
3274 FNextWeap
:= FNextWeap
or (1 shl Weapon
);
3277 procedure TPlayer
.resetWeaponQueue ();
3280 FNextWeapDelay
:= 0;
3283 function TPlayer
.hasAmmoForWeapon (weapon
: Byte): Boolean;
3287 WEAPON_KASTET
, WEAPON_SAW
: result
:= true;
3288 WEAPON_SHOTGUN1
, WEAPON_SHOTGUN2
: result
:= (FAmmo
[A_SHELLS
] > 0);
3289 WEAPON_PISTOL
, WEAPON_CHAINGUN
, WEAPON_SUPERPULEMET
: result
:= (FAmmo
[A_BULLETS
] > 0);
3290 WEAPON_ROCKETLAUNCHER
: result
:= (FAmmo
[A_ROCKETS
] > 0);
3291 WEAPON_PLASMA
, WEAPON_BFG
: result
:= (FAmmo
[A_CELLS
] > 0);
3292 else result
:= (weapon
< length(FWeapon
));
3296 // return 255 for "no switch"
3297 function TPlayer
.getNextWeaponIndex (): Byte;
3300 wantThisWeapon
: array[0..64] of Boolean;
3301 wwc
: Integer = 0; //HACK!
3303 result
:= 255; // default result: "no switch"
3304 for i
:= 0 to High(wantThisWeapon
) do wantThisWeapon
[i
] := false;
3305 for i
:= 0 to High(FWeapon
) do if (FNextWeap
and (1 shl i
)) <> 0 then begin wantThisWeapon
[i
] := true; Inc(wwc
); end;
3306 if wantThisWeapon
[FCurrWeap
] then
3308 // these hacks implements alternating between SG and SSG; sorry
3309 if FCurrWeap
= WEAPON_SHOTGUN1
then begin wantThisWeapon
[WEAPON_SHOTGUN2
] := true; Inc(wwc
); end;
3310 if FCurrWeap
= WEAPON_SHOTGUN2
then begin wantThisWeapon
[WEAPON_SHOTGUN1
] := true; Inc(wwc
); end;
3311 // these hacks implements alternating between knuckles and chainsaw; sorry
3312 if FCurrWeap
= WEAPON_KASTET
then begin wantThisWeapon
[WEAPON_SAW
] := true; Inc(wwc
); end;
3313 if FCurrWeap
= WEAPON_SAW
then begin wantThisWeapon
[WEAPON_KASTET
] := true; Inc(wwc
); end;
3315 // exclude currently selected weapon from the set
3316 wantThisWeapon
[FCurrWeap
] := false;
3317 // slow down alterations a little
3320 // more than one weapon requested, assume "alteration" and check alteration delay
3321 if FNextWeapDelay
> 0 then begin FNextWeap
:= 0; exit
; end; // yeah
3323 // do not reset weapon queue, it will be done in `RealizeCurrentWeapon()`
3324 // try weapons in descending order
3325 for i
:= High(FWeapon
) downto 0 do
3327 if wantThisWeapon
[i
] and FWeapon
[i
] and ((wwc
= 1) or hasAmmoForWeapon(i
)) then
3336 procedure TPlayer
.RealizeCurrentWeapon();
3340 nw
:= getNextWeaponIndex();
3341 if FNextWeapDelay
> 0 then Dec(FNextWeapDelay
); // "alteration delay"
3342 if nw
= 255 then exit
; // don't reset anything here
3343 if nw
> High(FWeapon
) then begin resetWeaponQueue(); exit
; end; // don't forget to reset queue here!
3345 if FBFGFireCounter
<> -1 then exit
;
3346 if FTime
[T_SWITCH
] > gTime
then exit
;
3348 for i
:= WEAPON_KASTET
to WEAPON_SUPERPULEMET
do if FReloading
[i
] > 0 then exit
;
3353 FTime
[T_SWITCH
] := gTime
+156;
3354 if FCurrWeap
= WEAPON_SAW
then FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3355 FModel
.SetWeapon(FCurrWeap
);
3356 if g_Game_IsNet
then MH_SEND_PlayerStats(FUID
);
3358 // reset weapon queue; `getNextWeaponIndex()` guarantees to not select a weapon player don't have
3360 FNextWeapDelay
:= 10; // anyway, 'cause why not
3363 procedure TPlayer
.cycleWeapon (dir
: Integer);
3367 if dir
< 0 then dir
:= 1 else if dir
> 0 then dir
:= 1 else exit
;
3369 for i
:= 0 to High(FWeapon
) do
3372 if cwi
< 0 then cwi
+= length(FWeapon
)
3373 else if cwi
> High(FWeapon
) then cwi
:= cwi
-length(FWeapon
);
3374 if FWeapon
[cwi
] then
3376 QueueWeaponSwitch(Byte(cwi
));
3382 procedure TPlayer
.NextWeapon();
3384 if g_Game_IsClient
then Exit
;
3388 procedure TPlayer
.PrevWeapon();
3390 if g_Game_IsClient
then Exit
;
3394 procedure TPlayer
.SetWeapon(W
: Byte);
3396 if FCurrWeap
<> W
then
3397 if W
= WEAPON_SAW
then
3398 FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3401 FModel
.SetWeapon(CurrWeap
);
3405 function TPlayer
.PickItem(ItemType
: Byte; respawn
: Boolean; var remove
: Boolean): Boolean;
3410 if g_Game_IsClient
then Exit
;
3412 // a = true - ìåñòî ñïàâíà ïðåäìåòà:
3413 a
:= LongBool(gGameSettings
.Options
and GAME_OPTION_WEAPONSTAY
) and respawn
;
3418 if FHealth
< PLAYER_HP_SOFT
then
3420 IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
3423 if gFlash
= 2 then Inc(FPickup
, 5);
3427 if FHealth
< PLAYER_HP_SOFT
then
3429 IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
3432 if gFlash
= 2 then Inc(FPickup
, 5);
3436 if FArmor
< PLAYER_AP_SOFT
then
3438 FArmor
:= PLAYER_AP_SOFT
;
3441 if gFlash
= 2 then Inc(FPickup
, 5);
3445 if FArmor
< PLAYER_AP_LIMIT
then
3447 FArmor
:= PLAYER_AP_LIMIT
;
3450 if gFlash
= 2 then Inc(FPickup
, 5);
3454 if FHealth
< PLAYER_HP_LIMIT
then
3456 IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
3459 if gFlash
= 2 then Inc(FPickup
, 5);
3463 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) then
3465 if FHealth
< PLAYER_HP_LIMIT
then
3466 FHealth
:= PLAYER_HP_LIMIT
;
3467 if FArmor
< PLAYER_AP_LIMIT
then
3468 FArmor
:= PLAYER_AP_LIMIT
;
3471 if gFlash
= 2 then Inc(FPickup
, 5);
3475 if (not FWeapon
[WEAPON_SAW
]) or ((not respawn
) and (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
])) then
3477 FWeapon
[WEAPON_SAW
] := True;
3479 if gFlash
= 2 then Inc(FPickup
, 5);
3480 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3483 ITEM_WEAPON_SHOTGUN1
:
3484 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN1
] then
3486 // Íóæíî, ÷òîáû íå âçÿòü âñå ïóëè ñðàçó:
3487 if a
and FWeapon
[WEAPON_SHOTGUN1
] then Exit
;
3489 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3490 FWeapon
[WEAPON_SHOTGUN1
] := True;
3492 if gFlash
= 2 then Inc(FPickup
, 5);
3493 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3496 ITEM_WEAPON_SHOTGUN2
:
3497 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN2
] then
3499 if a
and FWeapon
[WEAPON_SHOTGUN2
] then Exit
;
3501 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3502 FWeapon
[WEAPON_SHOTGUN2
] := True;
3504 if gFlash
= 2 then Inc(FPickup
, 5);
3505 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3508 ITEM_WEAPON_CHAINGUN
:
3509 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or not FWeapon
[WEAPON_CHAINGUN
] then
3511 if a
and FWeapon
[WEAPON_CHAINGUN
] then Exit
;
3513 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
3514 FWeapon
[WEAPON_CHAINGUN
] := True;
3516 if gFlash
= 2 then Inc(FPickup
, 5);
3517 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3520 ITEM_WEAPON_ROCKETLAUNCHER
:
3521 if (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or not FWeapon
[WEAPON_ROCKETLAUNCHER
] then
3523 if a
and FWeapon
[WEAPON_ROCKETLAUNCHER
] then Exit
;
3525 IncMax(FAmmo
[A_ROCKETS
], 2, FMaxAmmo
[A_ROCKETS
]);
3526 FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
3528 if gFlash
= 2 then Inc(FPickup
, 5);
3529 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3533 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_PLASMA
] then
3535 if a
and FWeapon
[WEAPON_PLASMA
] then Exit
;
3537 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3538 FWeapon
[WEAPON_PLASMA
] := True;
3540 if gFlash
= 2 then Inc(FPickup
, 5);
3541 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3545 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_BFG
] then
3547 if a
and FWeapon
[WEAPON_BFG
] then Exit
;
3549 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3550 FWeapon
[WEAPON_BFG
] := True;
3552 if gFlash
= 2 then Inc(FPickup
, 5);
3553 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3556 ITEM_WEAPON_SUPERPULEMET
:
3557 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SUPERPULEMET
] then
3559 if a
and FWeapon
[WEAPON_SUPERPULEMET
] then Exit
;
3561 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3562 FWeapon
[WEAPON_SUPERPULEMET
] := True;
3564 if gFlash
= 2 then Inc(FPickup
, 5);
3565 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3569 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
3571 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
3574 if gFlash
= 2 then Inc(FPickup
, 5);
3577 ITEM_AMMO_BULLETS_BOX
:
3578 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
3580 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
3583 if gFlash
= 2 then Inc(FPickup
, 5);
3587 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
3589 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3592 if gFlash
= 2 then Inc(FPickup
, 5);
3595 ITEM_AMMO_SHELLS_BOX
:
3596 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
3598 IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
3601 if gFlash
= 2 then Inc(FPickup
, 5);
3605 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
3607 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
3610 if gFlash
= 2 then Inc(FPickup
, 5);
3613 ITEM_AMMO_ROCKET_BOX
:
3614 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
3616 IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
3619 if gFlash
= 2 then Inc(FPickup
, 5);
3623 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
3625 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3628 if gFlash
= 2 then Inc(FPickup
, 5);
3632 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
3634 IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
3637 if gFlash
= 2 then Inc(FPickup
, 5);
3641 if not(R_ITEM_BACKPACK
in FRulez
) or
3642 (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
3643 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
3644 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
3645 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) then
3647 FMaxAmmo
[A_BULLETS
] := 400;
3648 FMaxAmmo
[A_SHELLS
] := 100;
3649 FMaxAmmo
[A_ROCKETS
] := 100;
3650 FMaxAmmo
[A_CELLS
] := 600;
3652 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
3653 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
3654 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
3655 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3656 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
3657 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
3658 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
3659 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3661 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
3664 if gFlash
= 2 then Inc(FPickup
, 5);
3668 if not(R_KEY_RED
in FRulez
) then
3670 Include(FRulez
, R_KEY_RED
);
3672 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
3673 if gFlash
= 2 then Inc(FPickup
, 5);
3674 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
3678 if not(R_KEY_GREEN
in FRulez
) then
3680 Include(FRulez
, R_KEY_GREEN
);
3682 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
3683 if gFlash
= 2 then Inc(FPickup
, 5);
3684 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
3688 if not(R_KEY_BLUE
in FRulez
) then
3690 Include(FRulez
, R_KEY_BLUE
);
3692 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
3693 if gFlash
= 2 then Inc(FPickup
, 5);
3694 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
3698 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
3700 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
3703 if gFlash
= 2 then Inc(FPickup
, 5);
3707 if FAir
< AIR_MAX
then
3712 if gFlash
= 2 then Inc(FPickup
, 5);
3717 if not (R_BERSERK
in FRulez
) then
3719 Include(FRulez
, R_BERSERK
);
3720 if FBFGFireCounter
= -1 then
3722 FCurrWeap
:= WEAPON_KASTET
;
3724 FModel
.SetWeapon(WEAPON_KASTET
);
3728 if gFlash
= 2 then Inc(FPickup
, 5);
3729 FBerserk
:= gTime
+30000;
3733 if FHealth
< PLAYER_HP_SOFT
then
3735 FHealth
:= PLAYER_HP_SOFT
;
3736 FBerserk
:= gTime
+30000;
3743 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
3745 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
3748 if gFlash
= 2 then Inc(FPickup
, 5);
3752 if FHealth
< PLAYER_HP_LIMIT
then
3754 IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
3757 if gFlash
= 2 then Inc(FPickup
, 5);
3761 if FArmor
< PLAYER_AP_LIMIT
then
3763 IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
3766 if gFlash
= 2 then Inc(FPickup
, 5);
3770 if FJetFuel
< JET_MAX
then
3772 FJetFuel
:= JET_MAX
;
3775 if gFlash
= 2 then Inc(FPickup
, 5);
3779 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
3781 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
3784 if gFlash
= 2 then Inc(FPickup
, 5);
3789 procedure TPlayer
.Touch();
3793 //FModel.PlaySound(MODELSOUND_PAIN, 1, FObj.X, FObj.Y);
3796 // Áðîñèòü ôëàã òîâàðèùó:
3797 if gGameSettings
.GameMode
= GM_CTF
then
3802 procedure TPlayer
.Push(vx
, vy
: Integer);
3804 if (not FPhysics
) and FGhost
then
3806 FObj
.Accel
.X
:= FObj
.Accel
.X
+ vx
;
3807 FObj
.Accel
.Y
:= FObj
.Accel
.Y
+ vy
;
3808 if g_Game_IsNet
and g_Game_IsServer
then
3809 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
3812 procedure TPlayer
.Reset(Force
: Boolean);
3818 FTime
[T_RESPAWN
] := 0;
3819 FTime
[T_FLAGCAP
] := 0;
3832 FSpectator
:= False;
3835 FSpectatePlayer
:= -1;
3836 FNoRespawn
:= False;
3838 FLives
:= gGameSettings
.MaxLives
;
3843 procedure TPlayer
.SoftReset();
3849 FBFGFireCounter
:= -1;
3857 SetAction(A_STAND
, True);
3860 function TPlayer
.GetRespawnPoint(): Byte;
3865 // Íà áóäóùåå: FSpawn - èãðîê óæå èãðàë è ïåðåðîæäàåòñÿ
3867 // Îäèíî÷íàÿ èãðà/êîîïåðàòèâ
3868 if gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
] then
3870 if (Self
= gPlayer1
) or (Self
= gPlayer2
) then
3872 // Òî÷êà ïîÿâëåíèÿ ñâîåãî èãðîêà
3873 if Self
= gPlayer1
then
3874 c
:= RESPAWNPOINT_PLAYER1
3876 c
:= RESPAWNPOINT_PLAYER2
;
3877 if g_Map_GetPointCount(c
) > 0 then
3883 // Òî÷êà ïîÿâëåíèÿ äðóãîãî èãðîêà
3884 if Self
= gPlayer1
then
3885 c
:= RESPAWNPOINT_PLAYER2
3887 c
:= RESPAWNPOINT_PLAYER1
;
3888 if g_Map_GetPointCount(c
) > 0 then
3895 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà (áîòà)
3896 if Random(2) = 0 then
3897 c
:= RESPAWNPOINT_PLAYER1
3899 c
:= RESPAWNPOINT_PLAYER2
;
3900 if g_Map_GetPointCount(c
) > 0 then
3907 // Òî÷êà ëþáîé èç êîìàíä
3908 if Random(2) = 0 then
3909 c
:= RESPAWNPOINT_RED
3911 c
:= RESPAWNPOINT_BLUE
;
3912 if g_Map_GetPointCount(c
) > 0 then
3919 c
:= RESPAWNPOINT_DM
;
3920 if g_Map_GetPointCount(c
) > 0 then
3928 if gGameSettings
.GameMode
= GM_DM
then
3931 c
:= RESPAWNPOINT_DM
;
3932 if g_Map_GetPointCount(c
) > 0 then
3938 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà
3939 if Random(2) = 0 then
3940 c
:= RESPAWNPOINT_PLAYER1
3942 c
:= RESPAWNPOINT_PLAYER2
;
3943 if g_Map_GetPointCount(c
) > 0 then
3949 // Òî÷êà ëþáîé èç êîìàíä
3950 if Random(2) = 0 then
3951 c
:= RESPAWNPOINT_RED
3953 c
:= RESPAWNPOINT_BLUE
;
3954 if g_Map_GetPointCount(c
) > 0 then
3962 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
3964 // Òî÷êà ñâîåé êîìàíäû
3965 c
:= RESPAWNPOINT_DM
;
3966 if FTeam
= TEAM_RED
then
3967 c
:= RESPAWNPOINT_RED
;
3968 if FTeam
= TEAM_BLUE
then
3969 c
:= RESPAWNPOINT_BLUE
;
3970 if g_Map_GetPointCount(c
) > 0 then
3977 c
:= RESPAWNPOINT_DM
;
3978 if g_Map_GetPointCount(c
) > 0 then
3984 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà
3985 if Random(2) = 0 then
3986 c
:= RESPAWNPOINT_PLAYER1
3988 c
:= RESPAWNPOINT_PLAYER2
;
3989 if g_Map_GetPointCount(c
) > 0 then
3995 // Òî÷êà äðóãîé êîìàíäû
3996 c
:= RESPAWNPOINT_DM
;
3997 if FTeam
= TEAM_RED
then
3998 c
:= RESPAWNPOINT_BLUE
;
3999 if FTeam
= TEAM_BLUE
then
4000 c
:= RESPAWNPOINT_RED
;
4001 if g_Map_GetPointCount(c
) > 0 then
4009 procedure TPlayer
.Respawn(Silent
: Boolean; Force
: Boolean = False);
4011 RespawnPoint
: TRespawnPoint
;
4016 if not g_Game_IsServer
then
4020 FWantsInGame
:= True;
4021 FJustTeleported
:= True;
4024 FTime
[T_RESPAWN
] := 0;
4028 // if server changes MaxLives we gotta be ready
4029 if gGameSettings
.MaxLives
= 0 then FNoRespawn
:= False;
4031 // Åùå íåëüçÿ âîçðîäèòüñÿ:
4032 if FTime
[T_RESPAWN
] > gTime
then
4035 // Ïðîñðàë âñå æèçíè:
4038 if not FSpectator
then Spectate(True);
4039 FWantsInGame
:= True;
4043 if (gGameSettings
.GameType
<> GT_SINGLE
) and (gGameSettings
.GameMode
<> GM_COOP
) then
4044 begin // "Ñâîÿ èãðà"
4045 // Áåðñåðê íå ñîõðàíÿåòñÿ ìåæäó óðîâíÿìè:
4046 FRulez
:= FRulez
-[R_BERSERK
];
4048 else // "Îäèíî÷íàÿ èãðà"/"Êîîï"
4050 // Áåðñåðê è êëþ÷è íå ñîõðàíÿþòñÿ ìåæäó óðîâíÿìè:
4051 FRulez
:= FRulez
-[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
, R_BERSERK
];
4054 // Ïîëó÷àåì òî÷êó ñïàóíà èãðîêà:
4055 c
:= GetRespawnPoint();
4060 // Âîñêðåøåíèå áåç îðóæèÿ:
4063 FHealth
:= PLAYER_HP_SOFT
;
4069 for a
:= WEAPON_KASTET
to WEAPON_SUPERPULEMET
do
4071 FWeapon
[a
] := False;
4075 FWeapon
[WEAPON_PISTOL
] := True;
4076 FWeapon
[WEAPON_KASTET
] := True;
4077 FCurrWeap
:= WEAPON_PISTOL
;
4080 FModel
.SetWeapon(FCurrWeap
);
4082 for b
:= A_BULLETS
to A_CELLS
do
4085 FAmmo
[A_BULLETS
] := 50;
4087 FMaxAmmo
[A_BULLETS
] := 200;
4088 FMaxAmmo
[A_SHELLS
] := 50;
4089 FMaxAmmo
[A_ROCKETS
] := 50;
4090 FMaxAmmo
[A_CELLS
] := 300;
4092 if gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
] then
4093 FRulez
:= [R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
]
4098 // Ïîëó÷àåì êîîðäèíàòû òî÷êè âîçðîæäåíèÿ:
4099 if not g_Map_GetPoint(c
, RespawnPoint
) then
4101 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
4105 // Óñòàíîâêà êîîðäèíàò è ñáðîñ âñåõ ïàðàìåòðîâ:
4106 FObj
.X
:= RespawnPoint
.X
-PLAYER_RECT
.X
;
4107 FObj
.Y
:= RespawnPoint
.Y
-PLAYER_RECT
.Y
;
4113 FDirection
:= RespawnPoint
.Direction
;
4114 if FDirection
= D_LEFT
then
4120 FBFGFireCounter
:= -1;
4125 SetAction(A_STAND
, True);
4126 FModel
.Direction
:= FDirection
;
4128 for a
:= Low(FTime
) to High(FTime
) do
4131 for a
:= Low(FMegaRulez
) to High(FMegaRulez
) do
4136 FCanJetpack
:= False;
4138 // Àíèìàöèÿ âîçðîæäåíèÿ:
4139 if (not gLoadGameMode
) and (not Silent
) then
4140 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
4142 Anim
:= TAnimation
.Create(ID
, False, 3);
4143 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4144 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4148 FSpectator
:= False;
4151 FSpectatePlayer
:= -1;
4154 if g_Game_IsNet
then
4156 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
4157 MH_SEND_PlayerStats(FUID
, NET_EVERYONE
);
4159 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4160 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32,
4165 procedure TPlayer
.Spectate(NoMove
: Boolean = False);
4168 Kill(K_EXTRAHARDKILL
, FUID
, HIT_SOME
)
4169 else if (not NoMove
) then
4171 GameX
:= gMapInfo
.Width
div 2;
4172 GameY
:= gMapInfo
.Height
div 2;
4181 FWantsInGame
:= False;
4186 if Self
= gPlayer1
then
4191 if Self
= gPlayer2
then
4198 if g_Game_IsNet
then
4199 MH_SEND_PlayerStats(FUID
);
4202 procedure TPlayer
.SwitchNoClip
;
4206 FGhost
:= not FGhost
;
4207 FPhysics
:= not FGhost
;
4219 procedure TPlayer
.Run(Direction
: TDirection
);
4223 if MAX_RUNVEL
> 8 then
4227 if Direction
= D_LEFT
then
4229 if FObj
.Vel
.X
> -MAX_RUNVEL
then
4230 FObj
.Vel
.X
:= FObj
.Vel
.X
- (MAX_RUNVEL
shr 3);
4233 if FObj
.Vel
.X
< MAX_RUNVEL
then
4234 FObj
.Vel
.X
:= FObj
.Vel
.X
+ (MAX_RUNVEL
shr 3);
4236 // Âîçìîæíî, ïèíàåì êóñêè:
4237 if (FObj
.Vel
.X
<> 0) and (gGibs
<> nil) then
4239 b
:= Abs(FObj
.Vel
.X
);
4240 if b
> 1 then b
:= b
* (Random(8 div b
) + 1);
4241 for a
:= 0 to High(gGibs
) do
4242 if gGibs
[a
].Live
and
4243 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
+FObj
.Rect
.Height
-4,
4244 FObj
.Rect
.Width
, 8, @gGibs
[a
].Obj
) and (Random(3) = 0) then
4246 if FObj
.Vel
.X
< 0 then
4247 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)+120) // íàëåâî
4249 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)); // íàïðàâî
4255 procedure TPlayer
.SeeDown();
4257 SetAction(A_SEEDOWN
);
4259 if FDirection
= D_LEFT
then FAngle
:= ANGLE_LEFTDOWN
else FAngle
:= ANGLE_RIGHTDOWN
;
4261 if FIncCam
> -120 then DecMin(FIncCam
, 5, -120);
4264 procedure TPlayer
.SeeUp();
4268 if FDirection
= D_LEFT
then FAngle
:= ANGLE_LEFTUP
else FAngle
:= ANGLE_RIGHTUP
;
4270 if FIncCam
< 120 then IncMax(FIncCam
, 5, 120);
4273 procedure TPlayer
.SetAction(Action
: Byte; Force
: Boolean = False);
4281 A_ATTACK
: Prior
:= 2;
4282 A_SEEUP
: Prior
:= 1;
4283 A_SEEDOWN
: Prior
:= 1;
4284 A_ATTACKUP
: Prior
:= 2;
4285 A_ATTACKDOWN
: Prior
:= 2;
4290 if (Prior
> FActionPrior
) or Force
then
4291 if not ((Prior
= 2) and (FCurrWeap
= WEAPON_SAW
)) then
4293 FActionPrior
:= Prior
;
4294 FActionAnim
:= Action
;
4295 FActionForce
:= Force
;
4296 FActionChanged
:= True;
4299 if Action
in [A_ATTACK
, A_ATTACKUP
, A_ATTACKDOWN
] then FModel
.SetFire(True);
4302 function TPlayer
.StayOnStep(XInc
, YInc
: Integer): Boolean;
4304 Result
:= not g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
-1,
4305 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False)
4306 and g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
,
4307 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False);
4310 function TPlayer
.TeleportTo(X
, Y
: Integer; silent
: Boolean; dir
: Byte): Boolean;
4317 if g_CollideLevel(X
, Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
) then
4319 g_Sound_PlayExAt('SOUND_GAME_NOTELEPORT', FObj
.X
, FObj
.Y
);
4320 if g_Game_IsServer
and g_Game_IsNet
then
4321 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_GAME_NOTELEPORT');
4325 FJustTeleported
:= True;
4330 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
4332 Anim
:= TAnimation
.Create(ID
, False, 3);
4335 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', FObj
.X
, FObj
.Y
);
4336 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4337 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4338 if g_Game_IsServer
and g_Game_IsNet
then
4339 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4340 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 1,
4344 FObj
.X
:= X
-PLAYER_RECT
.X
;
4345 FObj
.Y
:= Y
-PLAYER_RECT
.Y
;
4346 if FLive
and FGhost
then
4352 if not g_Game_IsNet
then
4356 SetDirection(D_LEFT
);
4362 SetDirection(D_RIGHT
);
4368 if FDirection
= D_RIGHT
then
4370 SetDirection(D_LEFT
);
4375 SetDirection(D_RIGHT
);
4381 if not silent
and (Anim
<> nil) then
4383 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4384 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4387 if g_Game_IsServer
and g_Game_IsNet
then
4388 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4389 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 0,
4396 function nonz(a
: Single): Single;
4404 procedure TPlayer
.Update();
4407 i
, ii
, wx
, wy
, xd
, yd
, k
: Integer;
4408 blockmon
, headwater
, dospawn
: Boolean;
4413 NetServer
:= g_Game_IsNet
and g_Game_IsServer
;
4414 AnyServer
:= g_Game_IsServer
;
4416 if g_Game_IsClient
and (NetInterpLevel
> 0) then
4417 DoLerp(NetInterpLevel
+ 1)
4423 if FClientID
>= 0 then
4425 FPing
:= NetClients
[FClientID
].Peer
^.lastRoundTripTime
;
4426 if NetClients
[FClientID
].Peer
^.packetsSent
> 0 then
4427 FLoss
:= Round(100*NetClients
[FClientID
].Peer
^.packetsLost
/NetClients
[FClientID
].Peer
^.packetsSent
)
4436 if FLive
and (gFly
or FJetpack
) then
4439 if FDirection
= D_LEFT
then
4444 if FLive
and (not FGhost
) then
4446 if FKeys
[KEY_UP
].Pressed
then
4448 if FKeys
[KEY_DOWN
].Pressed
then
4452 if (not (FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_DOWN
].Pressed
)) and
4455 i
:= g_basic
.Sign(FIncCam
);
4456 FIncCam
:= Abs(FIncCam
);
4457 DecMin(FIncCam
, 5, 0);
4458 FIncCam
:= FIncCam
*i
;
4461 if gTime
mod (GAME_TICK
*2) <> 0 then
4463 if (FObj
.Vel
.X
= 0) and FLive
then
4465 if FKeys
[KEY_LEFT
].Pressed
then
4467 if FKeys
[KEY_RIGHT
].Pressed
then
4472 g_Obj_Move(@FObj
, True, True, True);
4477 FActionChanged
:= False;
4481 // Let alive player do some actions
4482 if FKeys
[KEY_LEFT
].Pressed
then Run(D_LEFT
);
4483 if FKeys
[KEY_RIGHT
].Pressed
then Run(D_RIGHT
);
4484 if FKeys
[KEY_NEXTWEAPON
].Pressed
and AnyServer
then NextWeapon();
4485 if FKeys
[KEY_PREVWEAPON
].Pressed
and AnyServer
then PrevWeapon();
4486 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then Fire();
4487 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Use();
4488 if FKeys
[KEY_JUMP
].Pressed
then Jump()
4491 if AnyServer
and FJetpack
then
4495 if NetServer
then MH_SEND_PlayerStats(FUID
);
4497 FCanJetpack
:= True;
4504 for k
:= Low(FKeys
) to KEY_CHAT
-1 do
4506 if FKeys
[k
].Pressed
then
4514 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
4517 if (FTime
[T_RESPAWN
] <= gTime
) and
4518 gGameOn
and (not FLive
) then
4520 if (g_Player_GetCount() > 1) then
4524 gExit
:= EXIT_RESTART
;
4529 // Dead spectator actions
4532 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Fire();
4533 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then
4537 if (FSpectatePlayer
>= High(gPlayers
)) then
4538 FSpectatePlayer
:= -1
4542 for I
:= FSpectatePlayer
+ 1 to High(gPlayers
) do
4543 if gPlayers
[I
] <> nil then
4544 if gPlayers
[I
].Live
then
4545 if gPlayers
[I
].UID
<> FUID
then
4547 FSpectatePlayer
:= I
;
4552 if not SetSpect
then FSpectatePlayer
:= -1;
4563 if FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_JUMP
].Pressed
then
4565 FYTo
:= FObj
.Y
- 32;
4566 FSpectatePlayer
:= -1;
4568 if FKeys
[KEY_DOWN
].Pressed
then
4570 FYTo
:= FObj
.Y
+ 32;
4571 FSpectatePlayer
:= -1;
4573 if FKeys
[KEY_LEFT
].Pressed
then
4575 FXTo
:= FObj
.X
- 32;
4576 FSpectatePlayer
:= -1;
4578 if FKeys
[KEY_RIGHT
].Pressed
then
4580 FXTo
:= FObj
.X
+ 32;
4581 FSpectatePlayer
:= -1;
4584 if (FXTo
< -64) then
4586 else if (FXTo
> gMapInfo
.Width
+ 32) then
4587 FXTo
:= gMapInfo
.Width
+ 32;
4588 if (FYTo
< -72) then
4590 else if (FYTo
> gMapInfo
.Height
+ 32) then
4591 FYTo
:= gMapInfo
.Height
+ 32;
4595 g_Obj_Move(@FObj
, True, True, True)
4601 if (FSpectatePlayer
<= High(gPlayers
)) and (FSpectatePlayer
>= 0) then
4602 if gPlayers
[FSpectatePlayer
] <> nil then
4603 if gPlayers
[FSpectatePlayer
].Live
then
4605 FXTo
:= gPlayers
[FSpectatePlayer
].GameX
;
4606 FYTo
:= gPlayers
[FSpectatePlayer
].GameY
;
4610 blockmon
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
, FObj
.Y
+PLAYER_HEADRECT
.Y
,
4611 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
4612 PANEL_BLOCKMON
, True);
4613 headwater
:= HeadInLiquid(0, 0);
4615 // Ñîïðîòèâëåíèå âîçäóõà:
4616 if (not FLive
) or not (FKeys
[KEY_LEFT
].Pressed
or FKeys
[KEY_RIGHT
].Pressed
) then
4617 if FObj
.Vel
.X
<> 0 then
4618 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
4620 if (FLastHit
= HIT_TRAP
) and (FPain
> 90) then FPain
:= 90;
4621 DecMin(FPain
, 5, 0);
4622 DecMin(FPickup
, 1, 0);
4624 if FLive
and (FObj
.Y
> gMapInfo
.Height
+128) and AnyServer
then
4626 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
4627 FMegaRulez
[MR_SUIT
] := 0;
4628 FMegaRulez
[MR_INVUL
] := 0;
4629 FMegaRulez
[MR_INVIS
] := 0;
4630 Kill(K_FALLKILL
, 0, HIT_FALL
);
4637 if FCurrWeap
= WEAPON_SAW
then
4638 if not (FSawSound
.IsPlaying() or FSawSoundHit
.IsPlaying() or
4639 FSawSoundSelect
.IsPlaying()) then
4640 FSawSoundIdle
.PlayAt(FObj
.X
, FObj
.Y
);
4643 if (not FJetSoundFly
.IsPlaying()) and (not FJetSoundOn
.IsPlaying()) and
4644 (not FJetSoundOff
.IsPlaying()) then
4646 FJetSoundFly
.SetPosition(0);
4647 FJetSoundFly
.PlayAt(FObj
.X
, FObj
.Y
);
4650 for b
:= WEAPON_KASTET
to WEAPON_SUPERPULEMET
do
4651 if FReloading
[b
] > 0 then
4657 if FShellTimer
> -1 then
4658 if FShellTimer
= 0 then
4660 if FShellType
= SHELL_SHELL
then
4661 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
4662 GameVelX
, GameVelY
-2, SHELL_SHELL
)
4663 else if FShellType
= SHELL_DBLSHELL
then
4665 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
4666 GameVelX
+1, GameVelY
-2, SHELL_SHELL
);
4667 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
4668 GameVelX
-1, GameVelY
-2, SHELL_SHELL
);
4671 end else Dec(FShellTimer
);
4673 if (FBFGFireCounter
> -1) then
4674 if FBFGFireCounter
= 0 then
4678 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
4679 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
4680 xd
:= wx
+IfThen(FDirection
= D_LEFT
, -30, 30);
4681 yd
:= wy
+firediry();
4682 g_Weapon_bfgshot(wx
, wy
, xd
, yd
, FUID
);
4683 if NetServer
then MH_SEND_PlayerFire(FUID
, WEAPON_BFG
, wx
, wy
, xd
, yd
);
4684 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
4685 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
4686 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
4689 FReloading
[WEAPON_BFG
] := WEAPON_RELOAD
[WEAPON_BFG
];
4690 FBFGFireCounter
:= -1;
4693 FBFGFireCounter
:= 0
4695 Dec(FBFGFireCounter
);
4697 if (FMegaRulez
[MR_SUIT
] < gTime
) and AnyServer
then
4699 b
:= g_GetAcidHit(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
);
4701 if (b
> 0) and (gTime
mod (15*GAME_TICK
) = 0) then Damage(b
, 0, 0, 0, HIT_ACID
);
4704 if (headwater
or blockmon
) then
4710 if AnyServer
then Damage(10, 0, 0, 0, HIT_WATER
);
4713 else if (FAir
mod 31 = 0) and not blockmon
then
4715 g_GFX_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2), FObj
.Y
+PLAYER_RECT
.Y
-4, 5+Random(6), 8, 4);
4716 if Random(2) = 0 then
4717 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
4719 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
4721 end else if FAir
< AIR_DEF
then
4724 if FDamageBuffer
> 0 then
4726 if FDamageBuffer
>= 9 then
4730 if FDamageBuffer
< 30 then i
:= 9
4731 else if FDamageBuffer
< 100 then i
:= 18
4735 ii
:= Round(FDamageBuffer
*FHealth
/ nonz(FArmor
*(3/4)+FHealth
));
4736 FArmor
:= FArmor
-(FDamageBuffer
-ii
);
4737 FHealth
:= FHealth
-ii
;
4740 FHealth
:= FHealth
+FArmor
;
4745 if FHealth
<= 0 then
4746 if FHealth
> -30 then Kill(K_SIMPLEKILL
, FLastSpawnerUID
, FLastHit
)
4747 else if FHealth
> -50 then Kill(K_HARDKILL
, FLastSpawnerUID
, FLastHit
)
4748 else Kill(K_EXTRAHARDKILL
, FLastSpawnerUID
, FLastHit
);
4752 if FDamageBuffer
<= 20 then FModel
.PlaySound(MODELSOUND_PAIN
, 1, FObj
.X
, FObj
.Y
)
4753 else if FDamageBuffer
<= 55 then FModel
.PlaySound(MODELSOUND_PAIN
, 2, FObj
.X
, FObj
.Y
)
4754 else if FDamageBuffer
<= 120 then FModel
.PlaySound(MODELSOUND_PAIN
, 3, FObj
.X
, FObj
.Y
)
4755 else FModel
.PlaySound(MODELSOUND_PAIN
, 4, FObj
.X
, FObj
.Y
);
4762 end; // if FLive then ...
4764 if (FActionAnim
= A_PAIN
) and (FModel
.Animation
<> A_PAIN
) then
4766 FModel
.ChangeAnimation(FActionAnim
, FActionForce
);
4767 FModel
.GetCurrentAnimation
.MinLength
:= i
;
4768 FModel
.GetCurrentAnimationMask
.MinLength
:= i
;
4769 end else FModel
.ChangeAnimation(FActionAnim
, FActionForce
and (FModel
.Animation
<> A_STAND
));
4771 if (FModel
.GetCurrentAnimation
.Played
or ((not FActionChanged
) and (FModel
.Animation
= A_WALK
)))
4772 then SetAction(A_STAND
, True);
4774 if not ((FModel
.Animation
= A_WALK
) and (Abs(FObj
.Vel
.X
) < 4) and not FModel
.Fire
) then FModel
.Update
;
4776 for b
:= Low(FKeys
) to High(FKeys
) do
4777 if FKeys
[b
].Time
= 0 then FKeys
[b
].Pressed
:= False else Dec(FKeys
[b
].Time
);
4780 function TPlayer
.Collide(X
, Y
: Integer; Width
, Height
: Word): Boolean;
4782 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
4783 FObj
.Y
+PLAYER_RECT
.Y
,
4790 function TPlayer
.Collide(Panel
: TPanel
): Boolean;
4792 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
4793 FObj
.Y
+PLAYER_RECT
.Y
,
4797 Panel
.Width
, Panel
.Height
);
4800 function TPlayer
.Collide(X
, Y
: Integer): Boolean;
4802 X
:= X
-FObj
.X
-PLAYER_RECT
.X
;
4803 Y
:= Y
-FObj
.Y
-PLAYER_RECT
.Y
;
4804 Result
:= (x
>= 0) and (x
<= PLAYER_RECT
.Width
) and
4805 (y
>= 0) and (y
<= PLAYER_RECT
.Height
);
4808 function g_Player_ValidName(Name
: string): Boolean;
4814 if gPlayers
= nil then Exit
;
4816 for a
:= 0 to High(gPlayers
) do
4817 if gPlayers
[a
] <> nil then
4818 if LowerCase(Name
) = LowerCase(gPlayers
[a
].FName
) then
4825 procedure TPlayer
.SetDirection(Direction
: TDirection
);
4829 d
:= FModel
.Direction
;
4831 FModel
.Direction
:= Direction
;
4832 if d
<> Direction
then FModel
.ChangeAnimation(FModel
.Animation
, True);
4834 FDirection
:= Direction
;
4837 function TPlayer
.GetKeys(): Byte;
4841 if R_KEY_RED
in FRulez
then Result
:= KEY_RED
;
4842 if R_KEY_GREEN
in FRulez
then Result
:= Result
or KEY_GREEN
;
4843 if R_KEY_BLUE
in FRulez
then Result
:= Result
or KEY_BLUE
;
4845 if FTeam
= TEAM_RED
then Result
:= Result
or KEY_REDTEAM
;
4846 if FTeam
= TEAM_BLUE
then Result
:= Result
or KEY_BLUETEAM
;
4849 procedure TPlayer
.Use();
4853 if FTime
[T_USE
] > gTime
then Exit
;
4855 g_Triggers_PressR(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
,
4856 PLAYER_RECT
.Height
, FUID
, ACTIVATE_PLAYERPRESS
);
4858 for a
:= 0 to High(gPlayers
) do
4859 if (gPlayers
[a
] <> nil) and (gPlayers
[a
] <> Self
) and
4860 gPlayers
[a
].Live
and SameTeam(FUID
, gPlayers
[a
].FUID
) and
4861 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
4862 FObj
.Rect
.Width
, FObj
.Rect
.Height
, @gPlayers
[a
].FObj
) then
4864 gPlayers
[a
].Touch();
4865 if g_Game_IsNet
and g_Game_IsServer
then
4866 MH_SEND_GameEvent(NET_EV_PLAYER_TOUCH
, gPlayers
[a
].FUID
);
4869 FTime
[T_USE
] := gTime
+120;
4872 procedure TPlayer
.NetFire(Wpn
: Byte; X
, Y
, AX
, AY
: Integer; WID
: Integer = -1);
4876 WX
, WY
, XD
, YD
: Integer;
4887 if R_BERSERK
in FRulez
then
4889 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
4890 obj
.X
:= FObj
.X
+FObj
.Rect
.X
;
4891 obj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
4894 obj
.rect
.Width
:= 39;
4895 obj
.rect
.Height
:= 52;
4896 obj
.Vel
.X
:= (xd
-wx
) div 2;
4897 obj
.Vel
.Y
:= (yd
-wy
) div 2;
4898 obj
.Accel
.X
:= xd
-wx
;
4899 obj
.Accel
.y
:= yd
-wy
;
4901 if g_Weapon_Hit(@obj
, 50, FUID
, HIT_SOME
) <> 0 then
4902 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
4904 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
4908 FPain
:= min(FPain
+ 25, 50);
4910 g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
4915 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
4916 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
4918 FSawSoundSelect
.Stop();
4920 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
4922 else if not FSawSoundHit
.IsPlaying() then
4924 FSawSoundSelect
.Stop();
4925 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
4932 g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', GameX
, Gamey
);
4933 FFireAngle
:= FAngle
;
4935 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
4936 GameVelX
, GameVelY
-2, SHELL_BULLET
);
4941 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
4942 FFireAngle
:= FAngle
;
4945 FShellType
:= SHELL_SHELL
;
4950 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN2', Gamex
, Gamey
);
4951 FFireAngle
:= FAngle
;
4954 FShellType
:= SHELL_DBLSHELL
;
4959 g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', Gamex
, Gamey
);
4960 FFireAngle
:= FAngle
;
4962 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
4963 GameVelX
, GameVelY
-2, SHELL_BULLET
);
4966 WEAPON_ROCKETLAUNCHER
:
4968 g_Weapon_Rocket(wx
, wy
, xd
, yd
, FUID
, WID
);
4969 FFireAngle
:= FAngle
;
4975 g_Weapon_Plasma(wx
, wy
, xd
, yd
, FUID
, WID
);
4976 FFireAngle
:= FAngle
;
4982 g_Weapon_BFGShot(wx
, wy
, xd
, yd
, FUID
, WID
);
4983 FFireAngle
:= FAngle
;
4987 WEAPON_SUPERPULEMET
:
4989 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
4990 FFireAngle
:= FAngle
;
4992 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
4993 GameVelX
, GameVelY
-2, SHELL_SHELL
);
4999 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
5000 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
5001 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
5004 procedure TPlayer
.DoLerp(Level
: Integer = 2);
5006 if FObj
.X
<> FXTo
then FObj
.X
:= Lerp(FObj
.X
, FXTo
, Level
);
5007 if FObj
.Y
<> FYTo
then FObj
.Y
:= Lerp(FObj
.Y
, FYTo
, Level
);
5010 procedure TPlayer
.SetLerp(XTo
, YTo
: Integer);
5014 if NetInterpLevel
< 1 then
5024 AX
:= Abs(FXTo
- FObj
.X
);
5025 AY
:= Abs(FYTo
- FObj
.Y
);
5026 if (AX
> 32) or (AX
<= NetInterpLevel
) then
5028 if (AY
> 32) or (AY
<= NetInterpLevel
) then
5033 function TPlayer
.FullInLift(XInc
, YInc
: Integer): Integer;
5035 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5036 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5037 PANEL_LIFTUP
, False) then Result
:= -1
5039 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5040 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5041 PANEL_LIFTDOWN
, False) then Result
:= 1
5045 function TPlayer
.GetFlag(Flag
: Byte): Boolean;
5052 if Flag
= FLAG_NONE
then
5055 if not g_Game_IsServer
then Exit
;
5057 // Ïðèíåñ ÷óæîé ôëàã íà ñâîþ áàçó:
5058 if (Flag
= FTeam
) and
5059 (gFlags
[Flag
].State
= FLAG_STATE_NORMAL
) and
5060 (FFlag
<> FLAG_NONE
) then
5062 if FFlag
= FLAG_RED
then
5063 s
:= _lc
[I_PLAYER_FLAG_RED
]
5065 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5067 evtype
:= FLAG_STATE_SCORED
;
5069 ts
:= Format('%.4d', [gFlags
[FFlag
].CaptureTime
]);
5070 Insert('.', ts
, Length(ts
) + 1 - 3);
5071 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_CAPTURE
], [FName
, s
, ts
]), True);
5073 g_Map_ResetFlag(FFlag
);
5074 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_CAPTURE
], [AnsiUpperCase(s
)]), 144);
5076 gTeamStat
[FTeam
].Goals
:= gTeamStat
[FTeam
].Goals
+ 1;
5079 if g_Game_IsNet
then
5081 MH_SEND_FlagEvent(evtype
, FFlag
, FUID
, False);
5085 gFlags
[FFlag
].CaptureTime
:= 0;
5090 // Ïîäîáðàë ñâîé ôëàã - âåðíóë åãî íà áàçó:
5091 if (Flag
= FTeam
) and
5092 (gFlags
[Flag
].State
= FLAG_STATE_DROPPED
) then
5094 if Flag
= FLAG_RED
then
5095 s
:= _lc
[I_PLAYER_FLAG_RED
]
5097 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5099 evtype
:= FLAG_STATE_RETURNED
;
5100 gFlags
[Flag
].CaptureTime
:= 0;
5102 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_RETURN
], [FName
, s
]), True);
5104 g_Map_ResetFlag(Flag
);
5105 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
5108 if g_Game_IsNet
then
5110 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5116 // Ïîäîáðàë ÷óæîé ôëàã:
5117 if (Flag
<> FTeam
) and (FTime
[T_FLAGCAP
] <= gTime
) then
5121 if Flag
= FLAG_RED
then
5122 s
:= _lc
[I_PLAYER_FLAG_RED
]
5124 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5126 evtype
:= FLAG_STATE_CAPTURED
;
5128 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_GET
], [FName
, s
]), True);
5130 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_GET
], [AnsiUpperCase(s
)]), 144);
5132 gFlags
[Flag
].State
:= FLAG_STATE_CAPTURED
;
5135 if g_Game_IsNet
then
5137 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5143 procedure TPlayer
.SetFlag(Flag
: Byte);
5146 if FModel
<> nil then
5147 FModel
.SetFlag(FFlag
);
5150 function TPlayer
.DropFlag(): Boolean;
5155 if (not g_Game_IsServer
) or (FFlag
= FLAG_NONE
) then
5157 FTime
[T_FLAGCAP
] := gTime
+ 2000;
5158 with gFlags
[FFlag
] do
5162 Direction
:= FDirection
;
5163 State
:= FLAG_STATE_DROPPED
;
5165 g_Obj_Push(@Obj
, (FObj
.Vel
.X
div 2)-2+Random(5),
5166 (FObj
.Vel
.Y
div 2)-2+Random(5));
5168 if FFlag
= FLAG_RED
then
5169 s
:= _lc
[I_PLAYER_FLAG_RED
]
5171 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5173 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_DROP
], [FName
, s
]), True);
5174 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_DROP
], [AnsiUpperCase(s
)]), 144);
5176 if g_Game_IsNet
then
5177 MH_SEND_FlagEvent(FLAG_STATE_DROPPED
, Flag
, FUID
, False);
5183 procedure TPlayer
.GetSecret();
5188 procedure TPlayer
.PressKey(Key
: Byte; Time
: Word = 1);
5190 Assert(Key
<= High(FKeys
));
5192 FKeys
[Key
].Pressed
:= True;
5193 FKeys
[Key
].Time
:= Time
;
5196 function TPlayer
.IsKeyPressed(K
: Byte): Boolean;
5198 Result
:= FKeys
[K
].Pressed
;
5201 procedure TPlayer
.ReleaseKeys();
5205 for a
:= Low(FKeys
) to High(FKeys
) do
5207 FKeys
[a
].Pressed
:= False;
5212 procedure TPlayer
.OnDamage(Angle
: SmallInt);
5216 function TPlayer
.firediry(): Integer;
5218 if FKeys
[KEY_UP
].Pressed
then Result
:= -42
5219 else if FKeys
[KEY_DOWN
].Pressed
then Result
:= 19
5223 procedure TPlayer
.RememberState();
5227 FSavedState
.Health
:= FHealth
;
5228 FSavedState
.Armor
:= FArmor
;
5229 FSavedState
.Air
:= FAir
;
5230 FSavedState
.JetFuel
:= FJetFuel
;
5231 FSavedState
.CurrWeap
:= FCurrWeap
;
5232 FSavedState
.NextWeap
:= FNextWeap
;
5233 FSavedState
.NextWeapDelay
:= FNextWeapDelay
;
5236 FSavedState
.Ammo
[i
] := FAmmo
[i
];
5238 FSavedState
.MaxAmmo
[i
] := FMaxAmmo
[i
];
5240 FSavedState
.Rulez
:= FRulez
;
5241 FSavedState
.WaitRecall
:= True;
5244 procedure TPlayer
.RecallState();
5248 if not FSavedState
.WaitRecall
then Exit
;
5250 FHealth
:= FSavedState
.Health
;
5251 FArmor
:= FSavedState
.Armor
;
5252 FAir
:= FSavedState
.Air
;
5253 FJetFuel
:= FSavedState
.JetFuel
;
5254 FCurrWeap
:= FSavedState
.CurrWeap
;
5255 FNextWeap
:= FSavedState
.NextWeap
;
5256 FNextWeapDelay
:= FSavedState
.NextWeapDelay
;
5259 FAmmo
[i
] := FSavedState
.Ammo
[i
];
5261 FMaxAmmo
[i
] := FSavedState
.MaxAmmo
[i
];
5263 FRulez
:= FSavedState
.Rulez
;
5264 FSavedState
.WaitRecall
:= False;
5266 if gGameSettings
.GameType
= GT_SERVER
then
5267 MH_SEND_PlayerStats(FUID
);
5270 procedure TPlayer
.SaveState(var Mem
: TBinMemoryWriter
);
5282 Mem
:= TBinMemoryWriter
.Create(i
);
5284 // Ñèãíàòóðà èãðîêà:
5285 sig
:= PLAYER_SIGNATURE
; // 'PLYR'
5286 Mem
.WriteDWORD(sig
);
5288 Mem
.WriteBoolean(FIamBot
);
5290 Mem
.WriteWord(FUID
);
5292 Mem
.WriteString(FName
, 32);
5294 Mem
.WriteByte(FTeam
);
5296 Mem
.WriteBoolean(FLive
);
5297 // Èçðàñõîäîâàë ëè âñå æèçíè:
5298 Mem
.WriteBoolean(FNoRespawn
);
5300 if FDirection
= D_LEFT
then
5306 Mem
.WriteInt(FHealth
);
5308 Mem
.WriteByte(FLives
);
5310 Mem
.WriteInt(FArmor
);
5314 Mem
.WriteInt(FJetFuel
);
5316 Mem
.WriteInt(FPain
);
5318 Mem
.WriteInt(FKills
);
5320 Mem
.WriteInt(FMonsterKills
);
5322 Mem
.WriteInt(FFrags
);
5324 Mem
.WriteByte(FFragCombo
);
5325 // Âðåìÿ ïîñëåäíåãî ôðàãà:
5326 Mem
.WriteDWORD(FLastFrag
);
5328 Mem
.WriteInt(FDeath
);
5329 // Êàêîé ôëàã íåñåò:
5330 Mem
.WriteByte(FFlag
);
5332 Mem
.WriteInt(FSecrets
);
5334 Mem
.WriteByte(FCurrWeap
);
5336 Mem
.WriteWord(FNextWeap
);
5338 Mem
.WriteByte(FNextWeapDelay
);
5339 // Âðåìÿ çàðÿäêè BFG:
5340 Mem
.WriteSmallInt(FBFGFireCounter
);
5342 Mem
.WriteInt(FDamageBuffer
);
5343 // Ïîñëåäíèé óäàðèâøèé:
5344 Mem
.WriteWord(FLastSpawnerUID
);
5345 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà:
5346 Mem
.WriteByte(FLastHit
);
5348 Obj_SaveState(@FObj
, Mem
);
5349 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ:
5350 for i
:= A_BULLETS
to A_CELLS
do
5351 Mem
.WriteWord(FAmmo
[i
]);
5352 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ:
5353 for i
:= A_BULLETS
to A_CELLS
do
5354 Mem
.WriteWord(FMaxAmmo
[i
]);
5356 for i
:= WEAPON_KASTET
to WEAPON_SUPERPULEMET
do
5357 Mem
.WriteBoolean(FWeapon
[i
]);
5358 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ:
5359 for i
:= WEAPON_KASTET
to WEAPON_SUPERPULEMET
do
5360 Mem
.WriteWord(FReloading
[i
]);
5362 if R_ITEM_BACKPACK
in FRulez
then
5367 // Íàëè÷èå êðàñíîãî êëþ÷à:
5368 if R_KEY_RED
in FRulez
then
5373 // Íàëè÷èå çåëåíîãî êëþ÷à:
5374 if R_KEY_GREEN
in FRulez
then
5379 // Íàëè÷èå ñèíåãî êëþ÷à:
5380 if R_KEY_BLUE
in FRulez
then
5385 // Íàëè÷èå áåðñåðêà:
5386 if R_BERSERK
in FRulez
then
5391 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ:
5392 for i
:= MR_SUIT
to MR_MAX
do
5393 Mem
.WriteDWORD(FMegaRulez
[i
]);
5394 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà:
5395 for i
:= T_RESPAWN
to T_FLAGCAP
do
5396 Mem
.WriteDWORD(FTime
[i
]);
5399 Mem
.WriteString(str
);
5409 procedure TPlayer
.LoadState(var Mem
: TBinMemoryReader
);
5419 // Ñèãíàòóðà èãðîêà:
5421 if sig
<> PLAYER_SIGNATURE
then // 'PLYR'
5423 raise EBinSizeError
.Create('TPlayer.LoadState: Wrong Player Signature');
5426 Mem
.ReadBoolean(FIamBot
);
5430 Mem
.ReadString(str
);
5431 if (Self
<> gPlayer1
) and (Self
<> gPlayer2
) then
5434 Mem
.ReadByte(FTeam
);
5436 Mem
.ReadBoolean(FLive
);
5437 // Èçðàñõîäîâàë ëè âñå æèçíè:
5438 Mem
.ReadBoolean(FNoRespawn
);
5442 FDirection
:= D_LEFT
5444 FDirection
:= D_RIGHT
;
5446 Mem
.ReadInt(FHealth
);
5448 Mem
.ReadByte(FLives
);
5450 Mem
.ReadInt(FArmor
);
5454 Mem
.ReadInt(FJetFuel
);
5458 Mem
.ReadInt(FKills
);
5460 Mem
.ReadInt(FMonsterKills
);
5462 Mem
.ReadInt(FFrags
);
5464 Mem
.ReadByte(FFragCombo
);
5465 // Âðåìÿ ïîñëåäíåãî ôðàãà:
5466 Mem
.ReadDWORD(FLastFrag
);
5468 Mem
.ReadInt(FDeath
);
5469 // Êàêîé ôëàã íåñåò:
5470 Mem
.ReadByte(FFlag
);
5472 Mem
.ReadInt(FSecrets
);
5474 Mem
.ReadByte(FCurrWeap
);
5476 Mem
.ReadWord(FNextWeap
);
5478 Mem
.ReadByte(FNextWeapDelay
);
5479 // Âðåìÿ çàðÿäêè BFG:
5480 Mem
.ReadSmallInt(FBFGFireCounter
);
5482 Mem
.ReadInt(FDamageBuffer
);
5483 // Ïîñëåäíèé óäàðèâøèé:
5484 Mem
.ReadWord(FLastSpawnerUID
);
5485 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà:
5486 Mem
.ReadByte(FLastHit
);
5488 Obj_LoadState(@FObj
, Mem
);
5489 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ:
5490 for i
:= A_BULLETS
to A_CELLS
do
5491 Mem
.ReadWord(FAmmo
[i
]);
5492 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ:
5493 for i
:= A_BULLETS
to A_CELLS
do
5494 Mem
.ReadWord(FMaxAmmo
[i
]);
5496 for i
:= WEAPON_KASTET
to WEAPON_SUPERPULEMET
do
5497 Mem
.ReadBoolean(FWeapon
[i
]);
5498 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ:
5499 for i
:= WEAPON_KASTET
to WEAPON_SUPERPULEMET
do
5500 Mem
.ReadWord(FReloading
[i
]);
5504 Include(FRulez
, R_ITEM_BACKPACK
);
5505 // Íàëè÷èå êðàñíîãî êëþ÷à:
5508 Include(FRulez
, R_KEY_RED
);
5509 // Íàëè÷èå çåëåíîãî êëþ÷à:
5512 Include(FRulez
, R_KEY_GREEN
);
5513 // Íàëè÷èå ñèíåãî êëþ÷à:
5516 Include(FRulez
, R_KEY_BLUE
);
5517 // Íàëè÷èå áåðñåðêà:
5520 Include(FRulez
, R_BERSERK
);
5521 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ:
5522 for i
:= MR_SUIT
to MR_MAX
do
5523 Mem
.ReadDWORD(FMegaRulez
[i
]);
5524 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà:
5525 for i
:= T_RESPAWN
to T_FLAGCAP
do
5526 Mem
.ReadDWORD(FTime
[i
]);
5528 Mem
.ReadString(str
);
5530 Mem
.ReadByte(FColor
.R
);
5531 Mem
.ReadByte(FColor
.G
);
5532 Mem
.ReadByte(FColor
.B
);
5533 if Self
= gPlayer1
then
5535 str
:= gPlayer1Settings
.Model
;
5536 FColor
:= gPlayer1Settings
.Color
;
5538 if Self
= gPlayer2
then
5540 str
:= gPlayer2Settings
.Model
;
5541 FColor
:= gPlayer2Settings
.Color
;
5543 // Îáíîâëÿåì ìîäåëü èãðîêà:
5545 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
5546 FModel
.Color
:= TEAMCOLOR
[FTeam
]
5548 FModel
.Color
:= FColor
;
5551 procedure TPlayer
.AllRulez(Health
: Boolean);
5557 FHealth
:= PLAYER_HP_LIMIT
;
5558 FArmor
:= PLAYER_AP_LIMIT
;
5562 for a
:= WEAPON_KASTET
to WEAPON_SUPERPULEMET
do FWeapon
[a
] := True;
5563 for a
:= A_BULLETS
to A_CELLS
do FAmmo
[a
] := 30000;
5564 FRulez
:= FRulez
+[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
];
5567 procedure TPlayer
.RestoreHealthArmor();
5569 FHealth
:= PLAYER_HP_LIMIT
;
5570 FArmor
:= PLAYER_AP_LIMIT
;
5573 procedure TPlayer
.FragCombo();
5577 if (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) or g_Game_IsClient
then
5579 if gTime
- FLastFrag
< FRAG_COMBO_TIME
then
5581 if FFragCombo
< 5 then
5583 Param
:= FUID
or (FFragCombo
shl 16);
5584 if (FComboEvnt
>= Low(gDelayedEvents
)) and
5585 (FComboEvnt
<= High(gDelayedEvents
)) and
5586 gDelayedEvents
[FComboEvnt
].Pending
and
5587 (gDelayedEvents
[FComboEvnt
].DEType
= DE_KILLCOMBO
) and
5588 (gDelayedEvents
[FComboEvnt
].DENum
and $FFFF = FUID
) then
5590 gDelayedEvents
[FComboEvnt
].Time
:= gTime
+ 500;
5591 gDelayedEvents
[FComboEvnt
].DENum
:= Param
;
5594 FComboEvnt
:= g_Game_DelayEvent(DE_KILLCOMBO
, 500, Param
);
5602 procedure TPlayer
.GiveItem(ItemType
: Byte);
5606 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
5608 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
5612 if FAir
< AIR_MAX
then
5619 if not (R_BERSERK
in FRulez
) then
5621 Include(FRulez
, R_BERSERK
);
5622 if FBFGFireCounter
< 1 then
5624 FCurrWeap
:= WEAPON_KASTET
;
5626 FModel
.SetWeapon(WEAPON_KASTET
);
5630 FBerserk
:= gTime
+30000;
5632 if FHealth
< PLAYER_HP_SOFT
then
5634 FHealth
:= PLAYER_HP_SOFT
;
5635 FBerserk
:= gTime
+30000;
5640 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
5642 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
5646 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
5648 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
5652 if FJetFuel
< JET_MAX
then
5654 FJetFuel
:= JET_MAX
;
5657 ITEM_WEAPON_SAW
: FWeapon
[WEAPON_SAW
] := True;
5658 ITEM_WEAPON_SHOTGUN1
: FWeapon
[WEAPON_SHOTGUN1
] := True;
5659 ITEM_WEAPON_SHOTGUN2
: FWeapon
[WEAPON_SHOTGUN2
] := True;
5660 ITEM_WEAPON_CHAINGUN
: FWeapon
[WEAPON_CHAINGUN
] := True;
5661 ITEM_WEAPON_ROCKETLAUNCHER
: FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
5662 ITEM_WEAPON_PLASMA
: FWeapon
[WEAPON_PLASMA
] := True;
5663 ITEM_WEAPON_BFG
: FWeapon
[WEAPON_BFG
] := True;
5664 ITEM_WEAPON_SUPERPULEMET
: FWeapon
[WEAPON_SUPERPULEMET
] := True;
5666 ITEM_AMMO_BULLETS
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
5667 ITEM_AMMO_BULLETS_BOX
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
5668 ITEM_AMMO_SHELLS
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
5669 ITEM_AMMO_SHELLS_BOX
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
5670 ITEM_AMMO_ROCKET
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
5671 ITEM_AMMO_ROCKET_BOX
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
5672 ITEM_AMMO_CELL
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
5673 ITEM_AMMO_CELL_BIG
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
5676 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
5677 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
5678 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
5679 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) then
5681 FMaxAmmo
[A_BULLETS
] := 400;
5682 FMaxAmmo
[A_SHELLS
] := 100;
5683 FMaxAmmo
[A_ROCKETS
] := 100;
5684 FMaxAmmo
[A_CELLS
] := 600;
5686 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
5687 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
5688 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
5689 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
5691 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
5694 ITEM_KEY_RED
: if not (R_KEY_RED
in FRulez
) then Include(FRulez
, R_KEY_RED
);
5695 ITEM_KEY_GREEN
: if not (R_KEY_GREEN
in FRulez
) then Include(FRulez
, R_KEY_GREEN
);
5696 ITEM_KEY_BLUE
: if not (R_KEY_BLUE
in FRulez
) then Include(FRulez
, R_KEY_BLUE
);
5698 ITEM_BOTTLE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
5699 ITEM_HELMET
: if FArmor
< PLAYER_AP_LIMIT
then IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
5704 if g_Game_IsNet
and g_Game_IsServer
then
5705 MH_SEND_PlayerStats(FUID
);
5708 procedure TPlayer
.FlySmoke(Times
: DWORD
= 1);
5713 if (Random(5) = 1) and (Times
= 1) then
5716 if BodyInLiquid(0, 0) then
5718 g_GFX_Bubbles(Obj
.X
+Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2)+Random(3)-1,
5719 Obj
.Y
+Obj
.Rect
.Height
+8, 1, 8, 4);
5720 if Random(2) = 0 then
5721 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
5723 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
5727 if g_Frames_Get(id
, 'FRAMES_SMOKE') then
5729 for i
:= 1 to Times
do
5731 Anim
:= TAnimation
.Create(id
, False, 3);
5733 g_GFX_OnceAnim(Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(Anim
.Width
div 2),
5734 Obj
.Y
+Obj
.Rect
.Height
-4+Random(8+Times
*2), Anim
, ONCEANIM_SMOKE
);
5740 procedure TPlayer
.PauseSounds(Enable
: Boolean);
5742 FSawSound
.Pause(Enable
);
5743 FSawSoundIdle
.Pause(Enable
);
5744 FSawSoundHit
.Pause(Enable
);
5745 FSawSoundSelect
.Pause(Enable
);
5750 constructor TCorpse
.Create(X
, Y
: Integer; ModelName
: String; aMess
: Boolean);
5755 FObj
.Rect
:= PLAYER_CORPSERECT
;
5756 FModelName
:= ModelName
;
5761 FState
:= CORPSE_STATE_MESS
;
5762 g_PlayerModel_GetAnim(ModelName
, A_DIE2
, FAnimation
, FAnimationMask
);
5766 FState
:= CORPSE_STATE_NORMAL
;
5767 g_PlayerModel_GetAnim(ModelName
, A_DIE1
, FAnimation
, FAnimationMask
);
5771 destructor TCorpse
.Destroy();
5778 procedure TCorpse
.Damage(Value
: Word; vx
, vy
: Integer);
5782 if FState
= CORPSE_STATE_REMOVEME
then
5785 FDamage
:= FDamage
+ Value
;
5787 if FDamage
> 150 then
5789 if FAnimation
<> nil then
5794 FState
:= CORPSE_STATE_REMOVEME
;
5796 g_Player_CreateGibs(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
5797 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2),
5798 FModelName
, FColor
);
5799 // Çâóê ìÿñà îò òðóïà:
5800 pm
:= g_PlayerModel_Get(FModelName
);
5801 pm
.PlaySound(MODELSOUND_DIE
, 5, FObj
.X
, FObj
.Y
);
5807 FObj
.Vel
.X
:= FObj
.Vel
.X
+ vx
;
5808 FObj
.Vel
.Y
:= FObj
.Vel
.Y
+ vy
;
5809 g_GFX_Blood(FObj
.X
+PLAYER_CORPSERECT
.X
+(PLAYER_CORPSERECT
.Width
div 2),
5810 FObj
.Y
+PLAYER_CORPSERECT
.Y
+(PLAYER_CORPSERECT
.Height
div 2),
5811 Value
, vx
, vy
, 16, (PLAYER_CORPSERECT
.Height
*2) div 3,
5816 procedure TCorpse
.Draw();
5818 if FState
= CORPSE_STATE_REMOVEME
then
5821 if FAnimation
<> nil then
5822 FAnimation
.Draw(FObj
.X
, FObj
.Y
, M_NONE
);
5824 if FAnimationMask
<> nil then
5827 FAnimationMask
.Draw(FObj
.X
, FObj
.Y
, M_NONE
);
5834 procedure TCorpse
.Update();
5838 if FState
= CORPSE_STATE_REMOVEME
then
5841 if gTime
mod (GAME_TICK
*2) <> 0 then
5843 g_Obj_Move(@FObj
, True, True, True);
5848 // Ñîïðîòèâëåíèå âîçäóõà äëÿ òðóïà:
5849 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
5851 st
:= g_Obj_Move(@FObj
, True, True, True);
5853 if WordBool(st
and MOVE_FALLOUT
) then
5855 FState
:= CORPSE_STATE_REMOVEME
;
5859 if FAnimation
<> nil then
5860 FAnimation
.Update();
5861 if FAnimationMask
<> nil then
5862 FAnimationMask
.Update();
5865 procedure TCorpse
.SaveState(var Mem
: TBinMemoryWriter
);
5874 sig
:= CORPSE_SIGNATURE
; // 'CORP'
5875 Mem
.WriteDWORD(sig
);
5877 Mem
.WriteByte(FState
);
5878 // Íàêîïëåííûé óðîí:
5879 Mem
.WriteByte(FDamage
);
5881 Mem
.WriteByte(FColor
.R
);
5882 Mem
.WriteByte(FColor
.G
);
5883 Mem
.WriteByte(FColor
.B
);
5885 Obj_SaveState(@FObj
, Mem
);
5886 // Åñòü ëè àíèìàöèÿ:
5887 anim
:= FAnimation
<> nil;
5888 Mem
.WriteBoolean(anim
);
5889 // Åñëè åñòü - ñîõðàíÿåì:
5891 FAnimation
.SaveState(Mem
);
5892 // Åñòü ëè ìàñêà àíèìàöèè:
5893 anim
:= FAnimationMask
<> nil;
5894 Mem
.WriteBoolean(anim
);
5895 // Åñëè åñòü - ñîõðàíÿåì:
5897 FAnimationMask
.SaveState(Mem
);
5900 procedure TCorpse
.LoadState(var Mem
: TBinMemoryReader
);
5910 if sig
<> CORPSE_SIGNATURE
then // 'CORP'
5912 raise EBinSizeError
.Create('TCorpse.LoadState: Wrong Corpse Signature');
5915 Mem
.ReadByte(FState
);
5916 // Íàêîïëåííûé óðîí:
5917 Mem
.ReadByte(FDamage
);
5919 Mem
.ReadByte(FColor
.R
);
5920 Mem
.ReadByte(FColor
.G
);
5921 Mem
.ReadByte(FColor
.B
);
5923 Obj_LoadState(@FObj
, Mem
);
5924 // Åñòü ëè àíèìàöèÿ:
5925 Mem
.ReadBoolean(anim
);
5926 // Åñëè åñòü - çàãðóæàåì:
5929 Assert(FAnimation
<> nil, 'TCorpse.LoadState: no FAnimation');
5930 FAnimation
.LoadState(Mem
);
5932 // Åñòü ëè ìàñêà àíèìàöèè:
5933 Mem
.ReadBoolean(anim
);
5934 // Åñëè åñòü - çàãðóæàåì:
5937 Assert(FAnimationMask
<> nil, 'TCorpse.LoadState: no FAnimationMask');
5938 FAnimationMask
.LoadState(Mem
);
5944 constructor TBot
.Create();
5951 FSpectator
:= False;
5958 for a
:= WEAPON_KASTET
to WEAPON_SUPERPULEMET
do
5960 FDifficult
.WeaponPrior
[a
] := WEAPON_PRIOR1
[a
];
5961 FDifficult
.CloseWeaponPrior
[a
] := WEAPON_PRIOR2
[a
];
5962 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
5966 destructor TBot
.Destroy();
5969 inherited Destroy();
5972 procedure TBot
.Draw();
5976 //if FTargetUID <> 0 then e_DrawLine(1, FObj.X, FObj.Y, g_Player_Get(FTargetUID).FObj.X,
5977 // g_Player_Get(FTargetUID).FObj.Y, 255, 0, 0);
5980 procedure TBot
.Respawn(Silent
: Boolean; Force
: Boolean = False);
5982 inherited Respawn(Silent
, Force
);
5985 FSelectedWeapon
:= FCurrWeap
;
5990 procedure TBot
.UpdateCombat();
6003 TTargetRecord
= array of TTarget
;
6005 function Compare(a
, b
: TTarget
): Integer;
6007 if a
.Line
and not b
.Line
then // A íà ëèíèè îãíÿ
6010 if not a
.Line
and b
.Line
then // B íà ëèíèè îãíÿ
6012 else // È A, è B íà ëèíèè èëè íå íà ëèíèè îãíÿ
6013 if (a
.Line
and b
.Line
) or ((not a
.Line
) and (not b
.Line
)) then
6015 if a
.Dist
> b
.Dist
then // B áëèæå
6017 else // A áëèæå èëè ðàâíîóäàëåííî ñ B
6020 else // Ñòðàííî -> A
6025 a
, x1
, y1
, x2
, y2
: Integer;
6026 targets
: TTargetRecord
;
6028 Target
, BestTarget
: TTarget
;
6029 firew
, fireh
: Integer;
6033 vsPlayer
, vsMonster
, ok
: Boolean;
6035 vsPlayer
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
);
6036 vsMonster
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
);
6038 // Åñëè òåêóùåå îðóæèå íå òî, ÷òî íóæíî, òî ìåíÿåì:
6039 if FCurrWeap
<> FSelectedWeapon
then
6042 // Åñëè íóæíî ñòðåëÿòü è íóæíîå îðóæèå, òî íàæàòü "Ñòðåëÿòü":
6043 if (GetAIFlag('NEEDFIRE') <> '') and (FCurrWeap
= FSelectedWeapon
) then
6045 RemoveAIFlag('NEEDFIRE');
6048 WEAPON_PLASMA
, WEAPON_SUPERPULEMET
, WEAPON_CHAINGUN
: PressKey(KEY_FIRE
, 20);
6049 WEAPON_SAW
, WEAPON_KASTET
, WEAPON_MEGAKASTET
: PressKey(KEY_FIRE
, 40);
6050 else PressKey(KEY_FIRE
);
6054 // Êîîðäèíàòû ñòâîëà:
6055 x1
:= FObj
.X
+ WEAPONPOINT
[FDirection
].X
;
6056 y1
:= FObj
.Y
+ WEAPONPOINT
[FDirection
].Y
;
6058 Target
.UID
:= FTargetUID
;
6061 if Target
.UID
<> 0 then
6062 begin // Öåëü åñòü - íàñòðàèâàåì
6063 if (g_GetUIDType(Target
.UID
) = UID_PLAYER
) and
6066 with g_Player_Get(Target
.UID
) do
6068 if (@FObj
) <> nil then
6075 Target
.cX
:= Target
.X
+ PLAYER_RECT_CX
;
6076 Target
.cY
:= Target
.Y
+ PLAYER_RECT_CY
;
6077 Target
.Rect
:= PLAYER_RECT
;
6078 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6079 Target
.Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6080 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6081 Target
.IsPlayer
:= True;
6085 if (g_GetUIDType(Target
.UID
) = UID_MONSTER
) and
6088 mon
:= g_Monsters_Get(Target
.UID
);
6091 Target
.X
:= mon
.Obj
.X
;
6092 Target
.Y
:= mon
.Obj
.Y
;
6094 Target
.cX
:= Target
.X
+ mon
.Obj
.Rect
.X
+ (mon
.Obj
.Rect
.Width
div 2);
6095 Target
.cY
:= Target
.Y
+ mon
.Obj
.Rect
.Y
+ (mon
.Obj
.Rect
.Height
div 2);
6096 Target
.Rect
:= mon
.Obj
.Rect
;
6097 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6098 Target
.Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6099 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6100 Target
.IsPlayer
:= False;
6107 begin // Öåëè íåò - îáíóëÿåì
6112 Target
.Visible
:= False;
6113 Target
.Line
:= False;
6114 Target
.IsPlayer
:= False;
6119 // Åñëè öåëü íå âèäèìà èëè íå íà ëèíèè îãíÿ, òî èùåì âñå âîçìîæíûå öåëè:
6120 if (not Target
.Line
) or (not Target
.Visible
) then
6124 for a
:= 0 to High(gPlayers
) do
6125 if (gPlayers
[a
] <> nil) and (gPlayers
[a
].Live
) and
6126 (gPlayers
[a
].FUID
<> FUID
) and
6127 (not SameTeam(FUID
, gPlayers
[a
].FUID
)) and
6128 (not gPlayers
[a
].NoTarget
) and
6129 (gPlayers
[a
].FMegaRulez
[MR_INVIS
] < gTime
) then
6131 if not TargetOnScreen(gPlayers
[a
].FObj
.X
+ PLAYER_RECT
.X
,
6132 gPlayers
[a
].FObj
.Y
+ PLAYER_RECT
.Y
) then
6135 x2
:= gPlayers
[a
].FObj
.X
+ PLAYER_RECT_CX
;
6136 y2
:= gPlayers
[a
].FObj
.Y
+ PLAYER_RECT_CY
;
6138 // Åñëè èãðîê íà ýêðàíå è íå ïðèêðûò ñòåíîé:
6139 if g_TraceVector(x1
, y1
, x2
, y2
) then
6141 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé:
6142 SetLength(targets
, Length(targets
)+1);
6143 with targets
[High(targets
)] do
6145 UID
:= gPlayers
[a
].FUID
;
6146 X
:= gPlayers
[a
].FObj
.X
;
6147 Y
:= gPlayers
[a
].FObj
.Y
;
6150 Rect
:= PLAYER_RECT
;
6151 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6152 Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6153 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6161 if vsMonster
and (gMonsters
<> nil) then
6162 for a
:= 0 to High(gMonsters
) do
6163 if (gMonsters
[a
] <> nil) and (gMonsters
[a
].Live
) and
6164 (gMonsters
[a
].MonsterType
<> MONSTER_BARREL
) then
6166 mon
:= gMonsters
[a
];
6168 if not TargetOnScreen(mon
.Obj
.X
+ mon
.Obj
.Rect
.X
,
6169 mon
.Obj
.Y
+ mon
.Obj
.Rect
.Y
) then
6172 x2
:= mon
.Obj
.X
+ mon
.Obj
.Rect
.X
+ (mon
.Obj
.Rect
.Width
div 2);
6173 y2
:= mon
.Obj
.Y
+ mon
.Obj
.Rect
.Y
+ (mon
.Obj
.Rect
.Height
div 2);
6175 // Åñëè ìîíñòð íà ýêðàíå è íå ïðèêðûò ñòåíîé:
6176 if g_TraceVector(x1
, y1
, x2
, y2
) then
6178 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé:
6179 SetLength(targets
, Length(targets
)+1);
6180 with targets
[High(targets
)] do
6187 Rect
:= mon
.Obj
.Rect
;
6188 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6189 Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6190 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6198 // Åñëè åñòü âîçìîæíûå öåëè:
6199 // (Âûáèðàåì ëó÷øóþ, ìåíÿåì îðóæèå è áåæèì ê íåé/îò íåå)
6200 if targets
<> nil then
6202 // Âûáèðàåì íàèëó÷øóþ öåëü:
6203 BestTarget
:= targets
[0];
6204 if Length(targets
) > 1 then
6205 for a
:= 1 to High(targets
) do
6206 if Compare(BestTarget
, targets
[a
]) = 1 then
6207 BestTarget
:= targets
[a
];
6209 // Åñëè ëó÷øàÿ öåëü "âèäíåå" òåêóùåé, òî òåêóùàÿ := ëó÷øàÿ:
6210 if ((not Target
.Visible
) and BestTarget
.Visible
and (Target
.UID
<> BestTarget
.UID
)) or
6211 ((not Target
.Line
) and BestTarget
.Line
and BestTarget
.Visible
) then
6213 Target
:= BestTarget
;
6215 if (Healthy() = 3) or ((Healthy() = 2)) then
6216 begin // Åñëè çäîðîâû - äîãîíÿåì
6217 if ((RunDirection() = D_LEFT
) and (Target
.X
> FObj
.X
)) then
6218 SetAIFlag('GORIGHT', '1');
6219 if ((RunDirection() = D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6220 SetAIFlag('GOLEFT', '1');
6223 begin // Åñëè ïîáèòû - óáåãàåì
6224 if ((RunDirection() = D_LEFT
) and (Target
.X
< FObj
.X
)) then
6225 SetAIFlag('GORIGHT', '1');
6226 if ((RunDirection() = D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6227 SetAIFlag('GOLEFT', '1');
6230 // Âûáèðàåì îðóæèå íà îñíîâå ðàññòîÿíèÿ è ïðèîðèòåòîâ:
6231 SelectWeapon(Abs(x1
-Target
.cX
));
6236 // (Äîãîíÿåì/óáåãàåì, ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëè)
6237 // (Åñëè öåëü äàëåêî, òî õâàòèò ñëåäèòü çà íåé)
6238 if Target
.UID
<> 0 then
6240 if not TargetOnScreen(Target
.X
+ Target
.Rect
.X
,
6241 Target
.Y
+ Target
.Rect
.Y
) then
6242 begin // Öåëü ñáåæàëà ñ "ýêðàíà"
6243 if (Healthy() = 3) or ((Healthy() = 2)) then
6244 begin // Åñëè çäîðîâû - äîãîíÿåì
6245 if ((RunDirection() = D_LEFT
) and (Target
.X
> FObj
.X
)) then
6246 SetAIFlag('GORIGHT', '1');
6247 if ((RunDirection() = D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6248 SetAIFlag('GOLEFT', '1');
6251 begin // Åñëè ïîáèòû - çàáûâàåì î öåëè è óáåãàåì
6253 if ((RunDirection() = D_LEFT
) and (Target
.X
< FObj
.X
)) then
6254 SetAIFlag('GORIGHT', '1');
6255 if ((RunDirection() = D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6256 SetAIFlag('GOLEFT', '1');
6260 begin // Öåëü ïîêà íà "ýêðàíå"
6261 // Åñëè öåëü íå çàãîðîæåíà ñòåíîé, òî îòìå÷àåì, êîãäà åå âèäåëè:
6262 if g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6263 FLastVisible
:= gTime
;
6264 // Åñëè ðàçíèöà âûñîò íå âåëèêà, òî äîãîíÿåì:
6265 if (Abs(FObj
.Y
-Target
.Y
) <= 128) then
6267 if ((RunDirection() = D_LEFT
) and (Target
.X
> FObj
.X
)) then
6268 SetAIFlag('GORIGHT', '1');
6269 if ((RunDirection() = D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6270 SetAIFlag('GOLEFT', '1');
6274 // Âûáèðàåì óãîë ââåðõ:
6275 if FDirection
= D_LEFT
then
6276 angle
:= ANGLE_LEFTUP
6278 angle
:= ANGLE_RIGHTUP
;
6280 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6281 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6283 // Åñëè ïðè óãëå ââåðõ ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
6284 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6285 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128), //96
6286 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6287 Target
.Rect
.Width
, Target
.Rect
.Height
) and
6288 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6289 begin // òî íóæíî ñòðåëÿòü ââåðõ
6290 SetAIFlag('NEEDFIRE', '1');
6291 SetAIFlag('NEEDSEEUP', '1');
6294 // Âûáèðàåì óãîë âíèç:
6295 if FDirection
= D_LEFT
then
6296 angle
:= ANGLE_LEFTDOWN
6298 angle
:= ANGLE_RIGHTDOWN
;
6300 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6301 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6303 // Åñëè ïðè óãëå âíèç ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
6304 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6305 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
6306 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6307 Target
.Rect
.Width
, Target
.Rect
.Height
) and
6308 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6309 begin // òî íóæíî ñòðåëÿòü âíèç
6310 SetAIFlag('NEEDFIRE', '1');
6311 SetAIFlag('NEEDSEEDOWN', '1');
6314 // Åñëè öåëü âèäíî è îíà íà òàêîé æå âûñîòå:
6315 if Target
.Visible
and
6316 (y1
+4 < Target
.Y
+Target
.Rect
.Y
+Target
.Rect
.Height
) and
6317 (y1
-4 > Target
.Y
+Target
.Rect
.Y
) then
6319 // Åñëè èäåì â ñòîðîíó öåëè, òî íàäî ñòðåëÿòü:
6320 if ((FDirection
= D_LEFT
) and (Target
.X
< FObj
.X
)) or
6321 ((FDirection
= D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6322 begin // òî íóæíî ñòðåëÿòü âïåðåä
6323 SetAIFlag('NEEDFIRE', '1');
6324 SetAIFlag('NEEDSEEDOWN', '');
6325 SetAIFlag('NEEDSEEUP', '');
6327 // Åñëè öåëü â ïðåäåëàõ "ýêðàíà" è ñëîæíîñòü ïîçâîëÿåò ïðûæêè ñáëèæåíèÿ:
6328 if Abs(FObj
.X
-Target
.X
) < Trunc(gPlayerScreenSize
.X
*0.75) then
6329 if GetRnd(FDifficult
.CloseJump
) then
6330 begin // òî åñëè ïîâåçåò - ïðûãàåì (îñîáåííî, åñëè áëèçêî)
6331 if Abs(FObj
.X
-Target
.X
) < 128 then
6335 if Random(a
) = 0 then
6336 SetAIFlag('NEEDJUMP', '1');
6340 // Åñëè öåëü âñå åùå åñòü:
6341 if Target
.UID
<> 0 then
6342 if gTime
-FLastVisible
> 2000 then // Åñëè âèäåëè äàâíî
6343 Target
.UID
:= 0 // òî çàáûòü öåëü
6344 else // Åñëè âèäåëè íåäàâíî
6345 begin // íî öåëü óáèëè
6346 if Target
.IsPlayer
then
6347 begin // Öåëü - èãðîê
6348 pla
:= g_Player_Get(Target
.UID
);
6349 if (pla
= nil) or (not pla
.Live
) or pla
.NoTarget
or
6350 (pla
.FMegaRulez
[MR_INVIS
] >= gTime
) then
6351 Target
.UID
:= 0; // òî çàáûòü öåëü
6354 begin // Öåëü - ìîíñòð
6355 mon
:= g_Monsters_Get(Target
.UID
);
6356 if (mon
= nil) or (not mon
.Live
) then
6357 Target
.UID
:= 0; // òî çàáûòü öåëü
6360 end; // if Target.UID <> 0
6362 FTargetUID
:= Target
.UID
;
6364 // Åñëè âîçìîæíûõ öåëåé íåò:
6365 // (Àòàêà ÷åãî-íèáóäü ñëåâà èëè ñïðàâà)
6366 if targets
= nil then
6367 if GetAIFlag('ATTACKLEFT') <> '' then
6368 begin // Åñëè íóæíî àòàêîâàòü íàëåâî
6369 RemoveAIFlag('ATTACKLEFT');
6371 SetAIFlag('NEEDJUMP', '1');
6373 if RunDirection() = D_RIGHT
then
6374 begin // Èäåì íå â òó ñòîðîíó
6375 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
6376 begin // Åñëè çäîðîâû, òî, âîçìîæíî, ñòðåëÿåì áåæèì âëåâî è ñòðåëÿåì
6377 SetAIFlag('NEEDFIRE', '1');
6378 SetAIFlag('GOLEFT', '1');
6382 begin // Èäåì â íóæíóþ ñòîðîíó
6383 if GetRnd(FDifficult
.InvisFire
) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
6384 SetAIFlag('NEEDFIRE', '1');
6385 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
6386 SetAIFlag('GORIGHT', '1');
6390 if GetAIFlag('ATTACKRIGHT') <> '' then
6391 begin // Åñëè íóæíî àòàêîâàòü íàïðàâî
6392 RemoveAIFlag('ATTACKRIGHT');
6394 SetAIFlag('NEEDJUMP', '1');
6396 if RunDirection() = D_LEFT
then
6397 begin // Èäåì íå â òó ñòîðîíó
6398 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
6399 begin // Åñëè çäîðîâû, òî, âîçìîæíî, áåæèì âïðàâî è ñòðåëÿåì
6400 SetAIFlag('NEEDFIRE', '1');
6401 SetAIFlag('GORIGHT', '1');
6406 if GetRnd(FDifficult
.InvisFire
) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
6407 SetAIFlag('NEEDFIRE', '1');
6408 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
6409 SetAIFlag('GOLEFT', '1');
6413 //HACK! (does it belongs there?)
6414 RealizeCurrentWeapon();
6416 // Åñëè åñòü âîçìîæíûå öåëè:
6417 // (Ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëÿì)
6418 if (targets
<> nil) and (GetAIFlag('NEEDFIRE') <> '') then
6419 for a
:= 0 to High(targets
) do
6421 // Åñëè ìîæåì ñòðåëÿòü ïî äèàãîíàëè:
6422 if GetRnd(FDifficult
.DiagFire
) then
6424 // Èùåì öåëü ñâåðõó è ñòðåëÿåì, åñëè åñòü:
6425 if FDirection
= D_LEFT
then
6426 angle
:= ANGLE_LEFTUP
6428 angle
:= ANGLE_RIGHTUP
;
6430 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6431 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6433 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6434 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
6435 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6436 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
6437 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
6439 SetAIFlag('NEEDFIRE', '1');
6440 SetAIFlag('NEEDSEEUP', '1');
6443 // Èùåì öåëü ñíèçó è ñòðåëÿåì, åñëè åñòü:
6444 if FDirection
= D_LEFT
then
6445 angle
:= ANGLE_LEFTDOWN
6447 angle
:= ANGLE_RIGHTDOWN
;
6449 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6450 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6452 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6453 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
6454 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6455 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
6456 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
6458 SetAIFlag('NEEDFIRE', '1');
6459 SetAIFlag('NEEDSEEDOWN', '1');
6463 // Åñëè öåëü "ïåðåä íîñîì", òî ñòðåëÿåì:
6464 if targets
[a
].Line
and targets
[a
].Visible
and
6465 (((FDirection
= D_LEFT
) and (targets
[a
].X
< FObj
.X
)) or
6466 ((FDirection
= D_RIGHT
) and (targets
[a
].X
> FObj
.X
))) then
6468 SetAIFlag('NEEDFIRE', '1');
6473 // Åñëè ëåòèò ïóëÿ, òî, âîçìîæíî, ïîäïðûãèâàåì:
6474 if g_Weapon_Danger(FUID
, FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
,
6475 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
,
6476 40+GetInterval(FDifficult
.Cover
, 40)) then
6477 SetAIFlag('NEEDJUMP', '1');
6479 // Åñëè êîí÷èëèñü ïàòîðíû, òî íóæíî ñìåíèòü îðóæèå:
6480 ammo
:= GetAmmoByWeapon(FCurrWeap
);
6481 if ((FCurrWeap
= WEAPON_SHOTGUN2
) and (ammo
< 2)) or
6482 ((FCurrWeap
= WEAPON_BFG
) and (ammo
< 40)) or
6484 SetAIFlag('SELECTWEAPON', '1');
6486 // Åñëè íóæíî ñìåíèòü îðóæèå, òî âûáèðàåì íóæíîå:
6487 if GetAIFlag('SELECTWEAPON') = '1' then
6490 RemoveAIFlag('SELECTWEAPON');
6494 procedure TBot
.Update();
6507 // Ïðîâåðÿåì, îòêëþ÷¸í ëè AI áîòîâ
6508 if (g_debug_BotAIOff
= 1) and (Team
= TEAM_RED
) then
6510 if (g_debug_BotAIOff
= 2) and (Team
= TEAM_BLUE
) then
6512 if g_debug_BotAIOff
= 3 then
6525 procedure TBot
.ReleaseKey(Key
: Byte);
6534 function TBot
.KeyPressed(Key
: Word): Boolean;
6536 Result
:= FKeys
[Key
].Pressed
;
6539 function TBot
.GetAIFlag(fName
: String20
): String20
;
6545 fName
:= LowerCase(fName
);
6547 if FAIFlags
<> nil then
6548 for a
:= 0 to High(FAIFlags
) do
6549 if LowerCase(FAIFlags
[a
].Name
) = fName
then
6551 Result
:= FAIFlags
[a
].Value
;
6556 procedure TBot
.RemoveAIFlag(fName
: String20
);
6560 if FAIFlags
= nil then Exit
;
6562 fName
:= LowerCase(fName
);
6564 for a
:= 0 to High(FAIFlags
) do
6565 if LowerCase(FAIFlags
[a
].Name
) = fName
then
6567 if a
<> High(FAIFlags
) then
6568 for b
:= a
to High(FAIFlags
)-1 do
6569 FAIFlags
[b
] := FAIFlags
[b
+1];
6571 SetLength(FAIFlags
, Length(FAIFlags
)-1);
6576 procedure TBot
.SetAIFlag(fName
, fValue
: String20
);
6584 fName
:= LowerCase(fName
);
6586 if FAIFlags
<> nil then
6587 for a
:= 0 to High(FAIFlags
) do
6588 if LowerCase(FAIFlags
[a
].Name
) = fName
then
6594 if ok
then FAIFlags
[a
].Value
:= fValue
6597 SetLength(FAIFlags
, Length(FAIFlags
)+1);
6598 with FAIFlags
[High(FAIFlags
)] do
6606 procedure TBot
.UpdateMove
;
6608 procedure GoLeft(Time
: Word = 1);
6610 ReleaseKey(KEY_LEFT
);
6611 ReleaseKey(KEY_RIGHT
);
6612 PressKey(KEY_LEFT
, Time
);
6613 SetDirection(D_LEFT
);
6616 procedure GoRight(Time
: Word = 1);
6618 ReleaseKey(KEY_LEFT
);
6619 ReleaseKey(KEY_RIGHT
);
6620 PressKey(KEY_RIGHT
, Time
);
6621 SetDirection(D_RIGHT
);
6624 function Rnd(a
: Word): Boolean;
6626 Result
:= Random(a
) = 0;
6629 procedure Turn(Time
: Word = 1200);
6631 if RunDirection() = D_LEFT
then GoRight(Time
) else GoLeft(Time
);
6636 ReleaseKey(KEY_LEFT
);
6637 ReleaseKey(KEY_RIGHT
);
6640 function CanRunLeft(): Boolean;
6642 Result
:= not CollideLevel(-1, 0);
6645 function CanRunRight(): Boolean;
6647 Result
:= not CollideLevel(1, 0);
6650 function CanRun(): Boolean;
6652 if RunDirection() = D_LEFT
then Result
:= CanRunLeft() else Result
:= CanRunRight();
6655 procedure Jump(Time
: Word = 30);
6657 PressKey(KEY_JUMP
, Time
);
6660 function NearHole(): Boolean;
6664 { TODO 5 : Ëåñòíèöû }
6665 sx
:= IfThen(RunDirection() = D_LEFT
, -1, 1);
6666 for x
:= 1 to PLAYER_RECT
.Width
do
6667 if (not StayOnStep(x
*sx
, 0)) and
6668 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
6669 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
6678 function BorderHole(): Boolean;
6682 { TODO 5 : Ëåñòíèöû }
6683 sx
:= IfThen(RunDirection() = D_LEFT
, -1, 1);
6684 for x
:= 1 to PLAYER_RECT
.Width
do
6685 if (not StayOnStep(x
*sx
, 0)) and
6686 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
6687 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
6689 for xx
:= x
to x
+32 do
6690 if CollideLevel(xx
*sx
, PLAYER_RECT
.Height
) then
6700 function NearDeepHole(): Boolean;
6706 sx
:= IfThen(RunDirection() = D_LEFT
, -1, 1);
6709 for x
:= 1 to PLAYER_RECT
.Width
do
6710 if (not StayOnStep(x
*sx
, 0)) and
6711 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
6712 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
6714 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
6716 if CollideLevel(x
*sx
, PLAYER_RECT
.Height
*y
) then Exit
;
6721 end else Result
:= False;
6724 function OverDeepHole(): Boolean;
6731 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
6733 if CollideLevel(0, PLAYER_RECT
.Height
*y
) then Exit
;
6740 function OnGround(): Boolean;
6742 Result
:= StayOnStep(0, 0) or CollideLevel(0, 1);
6745 function OnLadder(): Boolean;
6747 Result
:= FullInStep(0, 0);
6750 function BelowLadder(): Boolean;
6752 Result
:= (FullInStep(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) and
6753 not CollideLevel(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
6754 (FullInStep(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) and
6755 not CollideLevel(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
6758 function BelowLiftUp(): Boolean;
6760 Result
:= ((FullInLift(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) = -1) and
6761 not CollideLevel(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
6762 ((FullInLift(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) = -1) and
6763 not CollideLevel(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
6766 function OnTopLift(): Boolean;
6768 Result
:= (FullInLift(0, 0) = -1) and (FullInLift(0, -32) = 0);
6771 function CanJumpOver(): Boolean;
6775 sx
:= IfThen(RunDirection() = D_LEFT
, -1, 1);
6779 if not CollideLevel(sx
, 0) then Exit
;
6781 for y
:= 1 to BOT_MAXJUMP
do
6782 if CollideLevel(0, -y
) then Exit
else
6783 if not CollideLevel(sx
, -y
) then
6790 function CanJumpUp(Dist
: ShortInt): Boolean;
6797 if CollideLevel(Dist
, 0) then Exit
;
6800 for y
:= 0 to BOT_MAXJUMP
do
6801 if CollideLevel(Dist
, -y
) then
6810 for yy
:= y
+1 to BOT_MAXJUMP
do
6811 if not CollideLevel(Dist
, -yy
) then
6820 for y
:= 0 to BOT_MAXJUMP
do
6821 if CollideLevel(0, -y
) then
6829 if y
< yy
then Exit
;
6834 function IsSafeTrigger(): Boolean;
6839 if gTriggers
= nil then
6841 for a
:= 0 to High(gTriggers
) do
6842 if Collide(gTriggers
[a
].X
,
6845 gTriggers
[a
].Height
) and
6846 (gTriggers
[a
].TriggerType
in [TRIGGER_EXIT
, TRIGGER_CLOSEDOOR
,
6847 TRIGGER_CLOSETRAP
, TRIGGER_TRAP
,
6848 TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
,
6849 TRIGGER_ONOFF
, TRIGGER_SPAWNMONSTER
,
6850 TRIGGER_DAMAGE
, TRIGGER_SHOT
]) then
6855 // Âîçìîæíî, íàæèìàåì êíîïêó:
6856 if Rnd(16) and IsSafeTrigger() then
6859 // Åñëè ïîä ëèôòîì èëè ñòóïåíüêàìè, òî, âîçìîæíî, ïðûãàåì:
6860 if OnLadder() or ((BelowLadder() or BelowLiftUp()) and Rnd(8)) then
6862 ReleaseKey(KEY_LEFT
);
6863 ReleaseKey(KEY_RIGHT
);
6867 // Èäåì âëåâî, åñëè íàäî áûëî:
6868 if GetAIFlag('GOLEFT') <> '' then
6870 RemoveAIFlag('GOLEFT');
6871 if CanRunLeft() then
6875 // Èäåì âïðàâî, åñëè íàäî áûëî:
6876 if GetAIFlag('GORIGHT') <> '' then
6878 RemoveAIFlag('GORIGHT');
6879 if CanRunRight() then
6883 // Åñëè âûëåòåëè çà êàðòó, òî ïðîáóåì âåðíóòüñÿ:
6884 if FObj
.X
< -32 then
6887 if FObj
.X
+32 > gMapInfo
.Width
then
6890 // Ïðûãàåì, åñëè íàäî áûëî:
6891 if GetAIFlag('NEEDJUMP') <> '' then
6894 RemoveAIFlag('NEEDJUMP');
6897 // Ñìîòðèì ââåðõ, åñëè íàäî áûëî:
6898 if GetAIFlag('NEEDSEEUP') <> '' then
6901 ReleaseKey(KEY_DOWN
);
6902 PressKey(KEY_UP
, 20);
6903 RemoveAIFlag('NEEDSEEUP');
6906 // Ñìîòðèì âíèç, åñëè íàäî áûëî:
6907 if GetAIFlag('NEEDSEEDOWN') <> '' then
6910 ReleaseKey(KEY_DOWN
);
6911 PressKey(KEY_DOWN
, 20);
6912 RemoveAIFlag('NEEDSEEDOWN');
6915 // Åñëè íóæíî áûëî â äûðó è ìû íå íà çåìëå, òî ïîêîðíî ëåòèì:
6916 if GetAIFlag('GOINHOLE') <> '' then
6917 if not OnGround() then
6919 ReleaseKey(KEY_LEFT
);
6920 ReleaseKey(KEY_RIGHT
);
6921 RemoveAIFlag('GOINHOLE');
6922 SetAIFlag('FALLINHOLE', '1');
6925 // Åñëè ïàäàëè è äîñòèãëè çåìëè, òî õâàòèò ïàäàòü:
6926 if GetAIFlag('FALLINHOLE') <> '' then
6928 RemoveAIFlag('FALLINHOLE');
6930 // Åñëè ëåòåëè ïðÿìî è ñåé÷àñ íå íà ëåñòíèöå èëè íà âåðøèíå ëèôòà, òî îòõîäèì â ñòîðîíó:
6931 if not (KeyPressed(KEY_LEFT
) or KeyPressed(KEY_RIGHT
)) then
6932 if GetAIFlag('FALLINHOLE') = '' then
6933 if (not OnLadder()) or (FObj
.Vel
.Y
>= 0) or (OnTopLift()) then
6939 // Åñëè íà çåìëå è ìîæíî ïîäïðûãíóòü, òî, âîçìîæíî, ïðûãàåì:
6941 CanJumpUp(IfThen(RunDirection() = D_LEFT
, -1, 1)*32) and
6945 // Åñëè íà çåìëå è âîçëå äûðû (ãëóáèíà > 2 ðîñòîâ èãðîêà):
6946 if OnGround() and NearHole() then
6947 if NearDeepHole() then // Åñëè ýòî áåçäíà
6949 0..3: Turn(); // Áåæèì îáðàòíî
6950 4: Jump(); // Ïðûãàåì
6951 5: begin // Ïðûãàåì îáðàòíî
6956 else // Ýòî íå áåçäíà è ìû åùå íå ëåòèì òóäà
6957 if GetAIFlag('GOINHOLE') = '' then
6959 0: Turn(); // Íå íóæíî òóäà
6960 1: Jump(); // Âäðóã ïîâåçåò - ïðûãàåì
6961 else // Åñëè ÿìà ñ ãðàíèöåé, òî ïðè ñëó÷àå ìîæíî òóäà ïðûãíóòü
6962 if BorderHole() then
6963 SetAIFlag('GOINHOLE', '1');
6966 // Åñëè íà çåìëå, íî íåêóäà èäòè:
6967 if (not CanRun()) and OnGround() then
6969 // Åñëè ìû íà ëåñòíèöå èëè ìîæíî ïåðåïðûãíóòü, òî ïðûãàåì:
6970 if CanJumpOver() or OnLadder() then
6972 else // èíà÷å ïîïûòàåìñÿ â äðóãóþ ñòîðîíó
6973 if Random(2) = 0 then
6975 if IsSafeTrigger() then
6981 // Îñòàëîñü ìàëî âîçäóõà:
6982 if FAir
< 36 * 2 then
6985 // Âûáèðàåìñÿ èç êèñëîòû, åñëè íåò êîñòþìà, îáîæãëèñü, èëè ìàëî çäîðîâüÿ:
6986 if (FMegaRulez
[MR_SUIT
] < gTime
) and ((FLastHit
= HIT_ACID
) or (Healthy() <= 1)) then
6987 if BodyInAcid(0, 0) then
6991 function TBot
.FullInStep(XInc
, YInc
: Integer): Boolean;
6993 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
6994 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_STEP
, False);
6997 {function TBot.NeedItem(Item: Byte): Byte;
7002 procedure TBot
.SelectWeapon(Dist
: Integer);
7006 function HaveAmmo(weapon
: Byte): Boolean;
7009 WEAPON_PISTOL
: Result
:= FAmmo
[A_BULLETS
] >= 1;
7010 WEAPON_SHOTGUN1
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7011 WEAPON_SHOTGUN2
: Result
:= FAmmo
[A_SHELLS
] >= 2;
7012 WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
] >= 10;
7013 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
] >= 1;
7014 WEAPON_PLASMA
: Result
:= FAmmo
[A_CELLS
] >= 10;
7015 WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
] >= 40;
7016 WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7017 else Result
:= True;
7022 if Dist
= -1 then Dist
:= BOT_LONGDIST
;
7024 if Dist
> BOT_LONGDIST
then
7025 begin // Äàëüíèé áîé
7027 if FWeapon
[FDifficult
.WeaponPrior
[a
]] and HaveAmmo(FDifficult
.WeaponPrior
[a
]) then
7029 FSelectedWeapon
:= FDifficult
.WeaponPrior
[a
];
7033 else //if Dist > BOT_UNSAFEDIST then
7034 begin // Áëèæíèé áîé
7036 if FWeapon
[FDifficult
.CloseWeaponPrior
[a
]] and HaveAmmo(FDifficult
.CloseWeaponPrior
[a
]) then
7038 FSelectedWeapon
:= FDifficult
.CloseWeaponPrior
[a
];
7045 if FWeapon[FDifficult.SafeWeaponPrior[a]] and HaveAmmo(FDifficult.SafeWeaponPrior[a]) then
7047 FSelectedWeapon := FDifficult.SafeWeaponPrior[a];
7053 function TBot
.PickItem(ItemType
: Byte; force
: Boolean; var remove
: Boolean): Boolean;
7055 Result
:= inherited PickItem(ItemType
, force
, remove
);
7057 if Result
then SetAIFlag('SELECTWEAPON', '1');
7060 function TBot
.Heal(value
: Word; Soft
: Boolean): Boolean;
7062 Result
:= inherited Heal(value
, Soft
);
7065 function TBot
.Healthy(): Byte;
7067 if FMegaRulez
[MR_INVUL
] >= gTime
then Result
:= 3
7068 else if (FHealth
> 80) or ((FHealth
> 50) and (FArmor
> 20)) then Result
:= 3
7069 else if (FHealth
> 50) then Result
:= 2
7070 else if (FHealth
> 20) then Result
:= 1
7074 function TBot
.TargetOnScreen(TX
, TY
: Integer): Boolean;
7076 Result
:= (Abs(FObj
.X
-TX
) <= Trunc(gPlayerScreenSize
.X
*0.6)) and
7077 (Abs(FObj
.Y
-TY
) <= Trunc(gPlayerScreenSize
.Y
*0.6));
7080 procedure TBot
.OnDamage(Angle
: SmallInt);
7088 if (Angle
= 0) or (Angle
= 180) then
7091 if (g_GetUIDType(FLastSpawnerUID
) = UID_PLAYER
) and
7092 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
) then
7094 pla
:= g_Player_Get(FLastSpawnerUID
);
7095 ok
:= not TargetOnScreen(pla
.FObj
.X
+ PLAYER_RECT
.X
,
7096 pla
.FObj
.Y
+ PLAYER_RECT
.Y
);
7099 if (g_GetUIDType(FLastSpawnerUID
) = UID_MONSTER
) and
7100 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
) then
7102 mon
:= g_Monsters_Get(FLastSpawnerUID
);
7103 ok
:= not TargetOnScreen(mon
.Obj
.X
+ mon
.Obj
.Rect
.X
,
7104 mon
.Obj
.Y
+ mon
.Obj
.Rect
.Y
);
7109 SetAIFlag('ATTACKLEFT', '1')
7111 SetAIFlag('ATTACKRIGHT', '1');
7115 function TBot
.RunDirection(): TDirection
;
7117 if Abs(Vel
.X
) >= 1 then
7119 if Vel
.X
> 0 then Result
:= D_RIGHT
else Result
:= D_LEFT
;
7121 Result
:= FDirection
;
7124 function TBot
.GetRnd(a
: Byte): Boolean;
7126 if a
= 0 then Result
:= False
7127 else if a
= 255 then Result
:= True
7128 else Result
:= Random(256) > 255-a
;
7131 function TBot
.GetInterval(a
: Byte; radius
: SmallInt): SmallInt;
7133 Result
:= Round((255-a
)/255*radius
*(Random(2)-1));
7136 procedure TBot
.SaveState(var Mem
: TBinMemoryWriter
);
7142 inherited SaveState(Mem
);
7144 // Âûáðàííîå îðóæèå:
7145 Mem
.WriteByte(FSelectedWeapon
);
7147 Mem
.WriteWord(FTargetUID
);
7148 // Âðåìÿ ïîòåðè öåëè:
7149 Mem
.WriteDWORD(FLastVisible
);
7150 // Êîëè÷åñòâî ôëàãîâ ÈÈ:
7151 dw
:= Length(FAIFlags
);
7154 for i
:= 0 to Integer(dw
)-1 do
7156 Mem
.WriteString(FAIFlags
[i
].Name
, 20);
7157 Mem
.WriteString(FAIFlags
[i
].Value
, 20);
7159 // Íàñòðîéêè ñëîæíîñòè:
7161 Mem
.WriteMemory(p
, SizeOf(TDifficult
));
7164 procedure TBot
.LoadState(var Mem
: TBinMemoryReader
);
7170 inherited LoadState(Mem
);
7172 // Âûáðàííîå îðóæèå:
7173 Mem
.ReadByte(FSelectedWeapon
);
7175 Mem
.ReadWord(FTargetUID
);
7176 // Âðåìÿ ïîòåðè öåëè:
7177 Mem
.ReadDWORD(FLastVisible
);
7178 // Êîëè÷åñòâî ôëàãîâ ÈÈ:
7180 SetLength(FAIFlags
, dw
);
7182 for i
:= 0 to Integer(dw
)-1 do
7184 Mem
.ReadString(FAIFlags
[i
].Name
);
7185 Mem
.ReadString(FAIFlags
[i
].Value
);
7187 // Íàñòðîéêè ñëîæíîñòè:
7188 Mem
.ReadMemory(p
, dw
);
7189 if dw
<> SizeOf(TDifficult
) then
7191 raise EBinSizeError
.Create('TBot.LoadState: Wrong FDifficult Size');
7193 FDifficult
:= TDifficult(p
^);