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 // exclude currently selected weapon from the set
3307 wantThisWeapon
[FCurrWeap
] := false;
3308 // slow down alterations a little
3311 // more than one weapon requested, assume "alteration" and check alteration delay
3312 if FNextWeapDelay
> 0 then begin FNextWeap
:= 0; exit
; end; // yeah
3314 // do not reset weapon queue, it will be done in `RealizeCurrentWeapon()`
3315 if wwc
< 1 then begin resetWeaponQueue(); exit
; end;
3316 //e_WriteLog(Format('wwc=%d', [wwc]), MSG_WARNING);
3317 // try weapons in descending order
3318 for i
:= High(FWeapon
) downto 0 do
3320 if wantThisWeapon
[i
] and FWeapon
[i
] and ((wwc
= 1) or hasAmmoForWeapon(i
)) then
3327 // no suitable weapon found, so reset the queue, to avoid accidental "queuing" of weapon w/o ammo
3331 procedure TPlayer
.RealizeCurrentWeapon();
3335 nw
:= getNextWeaponIndex();
3336 if FNextWeapDelay
> 0 then Dec(FNextWeapDelay
); // "alteration delay"
3337 if nw
= 255 then exit
; // don't reset anything here
3338 if nw
> High(FWeapon
) then begin resetWeaponQueue(); exit
; end; // don't forget to reset queue here!
3340 if FBFGFireCounter
<> -1 then exit
;
3341 if FTime
[T_SWITCH
] > gTime
then exit
;
3343 for i
:= WEAPON_KASTET
to WEAPON_SUPERPULEMET
do if FReloading
[i
] > 0 then exit
;
3348 FTime
[T_SWITCH
] := gTime
+156;
3349 if FCurrWeap
= WEAPON_SAW
then FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3350 FModel
.SetWeapon(FCurrWeap
);
3351 if g_Game_IsNet
then MH_SEND_PlayerStats(FUID
);
3353 // reset weapon queue; `getNextWeaponIndex()` guarantees to not select a weapon player don't have
3355 FNextWeapDelay
:= 10; // anyway, 'cause why not
3358 procedure TPlayer
.cycleWeapon (dir
: Integer);
3362 if dir
< 0 then dir
:= 1 else if dir
> 0 then dir
:= 1 else exit
;
3364 for i
:= 0 to High(FWeapon
) do
3367 if cwi
< 0 then cwi
+= length(FWeapon
)
3368 else if cwi
> High(FWeapon
) then cwi
:= cwi
-length(FWeapon
);
3369 if FWeapon
[cwi
] then
3371 QueueWeaponSwitch(Byte(cwi
));
3377 procedure TPlayer
.NextWeapon();
3379 if g_Game_IsClient
then Exit
;
3383 procedure TPlayer
.PrevWeapon();
3385 if g_Game_IsClient
then Exit
;
3389 procedure TPlayer
.SetWeapon(W
: Byte);
3391 if FCurrWeap
<> W
then
3392 if W
= WEAPON_SAW
then
3393 FSawSoundSelect
.PlayAt(FObj
.X
, FObj
.Y
);
3396 FModel
.SetWeapon(CurrWeap
);
3400 function TPlayer
.PickItem(ItemType
: Byte; respawn
: Boolean; var remove
: Boolean): Boolean;
3405 if g_Game_IsClient
then Exit
;
3407 // a = true - ìåñòî ñïàâíà ïðåäìåòà:
3408 a
:= LongBool(gGameSettings
.Options
and GAME_OPTION_WEAPONSTAY
) and respawn
;
3413 if FHealth
< PLAYER_HP_SOFT
then
3415 IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
3418 if gFlash
= 2 then Inc(FPickup
, 5);
3422 if FHealth
< PLAYER_HP_SOFT
then
3424 IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
3427 if gFlash
= 2 then Inc(FPickup
, 5);
3431 if FArmor
< PLAYER_AP_SOFT
then
3433 FArmor
:= PLAYER_AP_SOFT
;
3436 if gFlash
= 2 then Inc(FPickup
, 5);
3440 if FArmor
< PLAYER_AP_LIMIT
then
3442 FArmor
:= PLAYER_AP_LIMIT
;
3445 if gFlash
= 2 then Inc(FPickup
, 5);
3449 if FHealth
< PLAYER_HP_LIMIT
then
3451 IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
3454 if gFlash
= 2 then Inc(FPickup
, 5);
3458 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) then
3460 if FHealth
< PLAYER_HP_LIMIT
then
3461 FHealth
:= PLAYER_HP_LIMIT
;
3462 if FArmor
< PLAYER_AP_LIMIT
then
3463 FArmor
:= PLAYER_AP_LIMIT
;
3466 if gFlash
= 2 then Inc(FPickup
, 5);
3470 if (not FWeapon
[WEAPON_SAW
]) or ((not respawn
) and (gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
])) then
3472 FWeapon
[WEAPON_SAW
] := True;
3474 if gFlash
= 2 then Inc(FPickup
, 5);
3475 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3478 ITEM_WEAPON_SHOTGUN1
:
3479 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN1
] then
3481 // Íóæíî, ÷òîáû íå âçÿòü âñå ïóëè ñðàçó:
3482 if a
and FWeapon
[WEAPON_SHOTGUN1
] then Exit
;
3484 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3485 FWeapon
[WEAPON_SHOTGUN1
] := True;
3487 if gFlash
= 2 then Inc(FPickup
, 5);
3488 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3491 ITEM_WEAPON_SHOTGUN2
:
3492 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SHOTGUN2
] then
3494 if a
and FWeapon
[WEAPON_SHOTGUN2
] then Exit
;
3496 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3497 FWeapon
[WEAPON_SHOTGUN2
] := True;
3499 if gFlash
= 2 then Inc(FPickup
, 5);
3500 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3503 ITEM_WEAPON_CHAINGUN
:
3504 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or not FWeapon
[WEAPON_CHAINGUN
] then
3506 if a
and FWeapon
[WEAPON_CHAINGUN
] then Exit
;
3508 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
3509 FWeapon
[WEAPON_CHAINGUN
] := True;
3511 if gFlash
= 2 then Inc(FPickup
, 5);
3512 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3515 ITEM_WEAPON_ROCKETLAUNCHER
:
3516 if (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or not FWeapon
[WEAPON_ROCKETLAUNCHER
] then
3518 if a
and FWeapon
[WEAPON_ROCKETLAUNCHER
] then Exit
;
3520 IncMax(FAmmo
[A_ROCKETS
], 2, FMaxAmmo
[A_ROCKETS
]);
3521 FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
3523 if gFlash
= 2 then Inc(FPickup
, 5);
3524 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3528 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_PLASMA
] then
3530 if a
and FWeapon
[WEAPON_PLASMA
] then Exit
;
3532 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3533 FWeapon
[WEAPON_PLASMA
] := True;
3535 if gFlash
= 2 then Inc(FPickup
, 5);
3536 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3540 if (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) or not FWeapon
[WEAPON_BFG
] then
3542 if a
and FWeapon
[WEAPON_BFG
] then Exit
;
3544 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3545 FWeapon
[WEAPON_BFG
] := True;
3547 if gFlash
= 2 then Inc(FPickup
, 5);
3548 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3551 ITEM_WEAPON_SUPERPULEMET
:
3552 if (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or not FWeapon
[WEAPON_SUPERPULEMET
] then
3554 if a
and FWeapon
[WEAPON_SUPERPULEMET
] then Exit
;
3556 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3557 FWeapon
[WEAPON_SUPERPULEMET
] := True;
3559 if gFlash
= 2 then Inc(FPickup
, 5);
3560 if a
and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETWEAPON');
3564 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
3566 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
3569 if gFlash
= 2 then Inc(FPickup
, 5);
3572 ITEM_AMMO_BULLETS_BOX
:
3573 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
3575 IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
3578 if gFlash
= 2 then Inc(FPickup
, 5);
3582 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
3584 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3587 if gFlash
= 2 then Inc(FPickup
, 5);
3590 ITEM_AMMO_SHELLS_BOX
:
3591 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
3593 IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
3596 if gFlash
= 2 then Inc(FPickup
, 5);
3600 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
3602 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
3605 if gFlash
= 2 then Inc(FPickup
, 5);
3608 ITEM_AMMO_ROCKET_BOX
:
3609 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
3611 IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
3614 if gFlash
= 2 then Inc(FPickup
, 5);
3618 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
3620 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3623 if gFlash
= 2 then Inc(FPickup
, 5);
3627 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
3629 IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
3632 if gFlash
= 2 then Inc(FPickup
, 5);
3636 if not(R_ITEM_BACKPACK
in FRulez
) or
3637 (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
3638 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
3639 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
3640 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) then
3642 FMaxAmmo
[A_BULLETS
] := 400;
3643 FMaxAmmo
[A_SHELLS
] := 100;
3644 FMaxAmmo
[A_ROCKETS
] := 100;
3645 FMaxAmmo
[A_CELLS
] := 600;
3647 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then
3648 IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
3649 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then
3650 IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
3651 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then
3652 IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
3653 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then
3654 IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
3656 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
3659 if gFlash
= 2 then Inc(FPickup
, 5);
3663 if not(R_KEY_RED
in FRulez
) then
3665 Include(FRulez
, R_KEY_RED
);
3667 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
3668 if gFlash
= 2 then Inc(FPickup
, 5);
3669 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
3673 if not(R_KEY_GREEN
in FRulez
) then
3675 Include(FRulez
, R_KEY_GREEN
);
3677 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
3678 if gFlash
= 2 then Inc(FPickup
, 5);
3679 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
3683 if not(R_KEY_BLUE
in FRulez
) then
3685 Include(FRulez
, R_KEY_BLUE
);
3687 remove
:= (gGameSettings
.GameMode
<> GM_COOP
) and (g_Player_GetCount() < 2);
3688 if gFlash
= 2 then Inc(FPickup
, 5);
3689 if (not remove
) and g_Game_IsNet
then MH_SEND_Sound(GameX
, GameY
, 'SOUND_ITEM_GETITEM');
3693 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
3695 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
3698 if gFlash
= 2 then Inc(FPickup
, 5);
3702 if FAir
< AIR_MAX
then
3707 if gFlash
= 2 then Inc(FPickup
, 5);
3712 if not (R_BERSERK
in FRulez
) then
3714 Include(FRulez
, R_BERSERK
);
3715 if FBFGFireCounter
= -1 then
3717 FCurrWeap
:= WEAPON_KASTET
;
3719 FModel
.SetWeapon(WEAPON_KASTET
);
3723 if gFlash
= 2 then Inc(FPickup
, 5);
3724 FBerserk
:= gTime
+30000;
3728 if FHealth
< PLAYER_HP_SOFT
then
3730 FHealth
:= PLAYER_HP_SOFT
;
3731 FBerserk
:= gTime
+30000;
3738 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
3740 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
3743 if gFlash
= 2 then Inc(FPickup
, 5);
3747 if FHealth
< PLAYER_HP_LIMIT
then
3749 IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
3752 if gFlash
= 2 then Inc(FPickup
, 5);
3756 if FArmor
< PLAYER_AP_LIMIT
then
3758 IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
3761 if gFlash
= 2 then Inc(FPickup
, 5);
3765 if FJetFuel
< JET_MAX
then
3767 FJetFuel
:= JET_MAX
;
3770 if gFlash
= 2 then Inc(FPickup
, 5);
3774 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
3776 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
3779 if gFlash
= 2 then Inc(FPickup
, 5);
3784 procedure TPlayer
.Touch();
3788 //FModel.PlaySound(MODELSOUND_PAIN, 1, FObj.X, FObj.Y);
3791 // Áðîñèòü ôëàã òîâàðèùó:
3792 if gGameSettings
.GameMode
= GM_CTF
then
3797 procedure TPlayer
.Push(vx
, vy
: Integer);
3799 if (not FPhysics
) and FGhost
then
3801 FObj
.Accel
.X
:= FObj
.Accel
.X
+ vx
;
3802 FObj
.Accel
.Y
:= FObj
.Accel
.Y
+ vy
;
3803 if g_Game_IsNet
and g_Game_IsServer
then
3804 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
3807 procedure TPlayer
.Reset(Force
: Boolean);
3813 FTime
[T_RESPAWN
] := 0;
3814 FTime
[T_FLAGCAP
] := 0;
3827 FSpectator
:= False;
3830 FSpectatePlayer
:= -1;
3831 FNoRespawn
:= False;
3833 FLives
:= gGameSettings
.MaxLives
;
3838 procedure TPlayer
.SoftReset();
3844 FBFGFireCounter
:= -1;
3852 SetAction(A_STAND
, True);
3855 function TPlayer
.GetRespawnPoint(): Byte;
3860 // Íà áóäóùåå: FSpawn - èãðîê óæå èãðàë è ïåðåðîæäàåòñÿ
3862 // Îäèíî÷íàÿ èãðà/êîîïåðàòèâ
3863 if gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
] then
3865 if (Self
= gPlayer1
) or (Self
= gPlayer2
) then
3867 // Òî÷êà ïîÿâëåíèÿ ñâîåãî èãðîêà
3868 if Self
= gPlayer1
then
3869 c
:= RESPAWNPOINT_PLAYER1
3871 c
:= RESPAWNPOINT_PLAYER2
;
3872 if g_Map_GetPointCount(c
) > 0 then
3878 // Òî÷êà ïîÿâëåíèÿ äðóãîãî èãðîêà
3879 if Self
= gPlayer1
then
3880 c
:= RESPAWNPOINT_PLAYER2
3882 c
:= RESPAWNPOINT_PLAYER1
;
3883 if g_Map_GetPointCount(c
) > 0 then
3890 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà (áîòà)
3891 if Random(2) = 0 then
3892 c
:= RESPAWNPOINT_PLAYER1
3894 c
:= RESPAWNPOINT_PLAYER2
;
3895 if g_Map_GetPointCount(c
) > 0 then
3902 // Òî÷êà ëþáîé èç êîìàíä
3903 if Random(2) = 0 then
3904 c
:= RESPAWNPOINT_RED
3906 c
:= RESPAWNPOINT_BLUE
;
3907 if g_Map_GetPointCount(c
) > 0 then
3914 c
:= RESPAWNPOINT_DM
;
3915 if g_Map_GetPointCount(c
) > 0 then
3923 if gGameSettings
.GameMode
= GM_DM
then
3926 c
:= RESPAWNPOINT_DM
;
3927 if g_Map_GetPointCount(c
) > 0 then
3933 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà
3934 if Random(2) = 0 then
3935 c
:= RESPAWNPOINT_PLAYER1
3937 c
:= RESPAWNPOINT_PLAYER2
;
3938 if g_Map_GetPointCount(c
) > 0 then
3944 // Òî÷êà ëþáîé èç êîìàíä
3945 if Random(2) = 0 then
3946 c
:= RESPAWNPOINT_RED
3948 c
:= RESPAWNPOINT_BLUE
;
3949 if g_Map_GetPointCount(c
) > 0 then
3957 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
3959 // Òî÷êà ñâîåé êîìàíäû
3960 c
:= RESPAWNPOINT_DM
;
3961 if FTeam
= TEAM_RED
then
3962 c
:= RESPAWNPOINT_RED
;
3963 if FTeam
= TEAM_BLUE
then
3964 c
:= RESPAWNPOINT_BLUE
;
3965 if g_Map_GetPointCount(c
) > 0 then
3972 c
:= RESPAWNPOINT_DM
;
3973 if g_Map_GetPointCount(c
) > 0 then
3979 // Òî÷êà ïîÿâëåíèÿ ëþáîãî èãðîêà
3980 if Random(2) = 0 then
3981 c
:= RESPAWNPOINT_PLAYER1
3983 c
:= RESPAWNPOINT_PLAYER2
;
3984 if g_Map_GetPointCount(c
) > 0 then
3990 // Òî÷êà äðóãîé êîìàíäû
3991 c
:= RESPAWNPOINT_DM
;
3992 if FTeam
= TEAM_RED
then
3993 c
:= RESPAWNPOINT_BLUE
;
3994 if FTeam
= TEAM_BLUE
then
3995 c
:= RESPAWNPOINT_RED
;
3996 if g_Map_GetPointCount(c
) > 0 then
4004 procedure TPlayer
.Respawn(Silent
: Boolean; Force
: Boolean = False);
4006 RespawnPoint
: TRespawnPoint
;
4011 if not g_Game_IsServer
then
4015 FWantsInGame
:= True;
4016 FJustTeleported
:= True;
4019 FTime
[T_RESPAWN
] := 0;
4023 // if server changes MaxLives we gotta be ready
4024 if gGameSettings
.MaxLives
= 0 then FNoRespawn
:= False;
4026 // Åùå íåëüçÿ âîçðîäèòüñÿ:
4027 if FTime
[T_RESPAWN
] > gTime
then
4030 // Ïðîñðàë âñå æèçíè:
4033 if not FSpectator
then Spectate(True);
4034 FWantsInGame
:= True;
4038 if (gGameSettings
.GameType
<> GT_SINGLE
) and (gGameSettings
.GameMode
<> GM_COOP
) then
4039 begin // "Ñâîÿ èãðà"
4040 // Áåðñåðê íå ñîõðàíÿåòñÿ ìåæäó óðîâíÿìè:
4041 FRulez
:= FRulez
-[R_BERSERK
];
4043 else // "Îäèíî÷íàÿ èãðà"/"Êîîï"
4045 // Áåðñåðê è êëþ÷è íå ñîõðàíÿþòñÿ ìåæäó óðîâíÿìè:
4046 FRulez
:= FRulez
-[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
, R_BERSERK
];
4049 // Ïîëó÷àåì òî÷êó ñïàóíà èãðîêà:
4050 c
:= GetRespawnPoint();
4055 // Âîñêðåøåíèå áåç îðóæèÿ:
4058 FHealth
:= PLAYER_HP_SOFT
;
4064 for a
:= WEAPON_KASTET
to WEAPON_SUPERPULEMET
do
4066 FWeapon
[a
] := False;
4070 FWeapon
[WEAPON_PISTOL
] := True;
4071 FWeapon
[WEAPON_KASTET
] := True;
4072 FCurrWeap
:= WEAPON_PISTOL
;
4075 FModel
.SetWeapon(FCurrWeap
);
4077 for b
:= A_BULLETS
to A_CELLS
do
4080 FAmmo
[A_BULLETS
] := 50;
4082 FMaxAmmo
[A_BULLETS
] := 200;
4083 FMaxAmmo
[A_SHELLS
] := 50;
4084 FMaxAmmo
[A_ROCKETS
] := 50;
4085 FMaxAmmo
[A_CELLS
] := 300;
4087 if gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
] then
4088 FRulez
:= [R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
]
4093 // Ïîëó÷àåì êîîðäèíàòû òî÷êè âîçðîæäåíèÿ:
4094 if not g_Map_GetPoint(c
, RespawnPoint
) then
4096 g_FatalError(_lc
[I_GAME_ERROR_GET_SPAWN
]);
4100 // Óñòàíîâêà êîîðäèíàò è ñáðîñ âñåõ ïàðàìåòðîâ:
4101 FObj
.X
:= RespawnPoint
.X
-PLAYER_RECT
.X
;
4102 FObj
.Y
:= RespawnPoint
.Y
-PLAYER_RECT
.Y
;
4108 FDirection
:= RespawnPoint
.Direction
;
4109 if FDirection
= D_LEFT
then
4115 FBFGFireCounter
:= -1;
4120 SetAction(A_STAND
, True);
4121 FModel
.Direction
:= FDirection
;
4123 for a
:= Low(FTime
) to High(FTime
) do
4126 for a
:= Low(FMegaRulez
) to High(FMegaRulez
) do
4131 FCanJetpack
:= False;
4133 // Àíèìàöèÿ âîçðîæäåíèÿ:
4134 if (not gLoadGameMode
) and (not Silent
) then
4135 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
4137 Anim
:= TAnimation
.Create(ID
, False, 3);
4138 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4139 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4143 FSpectator
:= False;
4146 FSpectatePlayer
:= -1;
4149 if g_Game_IsNet
then
4151 MH_SEND_PlayerPos(True, FUID
, NET_EVERYONE
);
4152 MH_SEND_PlayerStats(FUID
, NET_EVERYONE
);
4154 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4155 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32,
4160 procedure TPlayer
.Spectate(NoMove
: Boolean = False);
4163 Kill(K_EXTRAHARDKILL
, FUID
, HIT_SOME
)
4164 else if (not NoMove
) then
4166 GameX
:= gMapInfo
.Width
div 2;
4167 GameY
:= gMapInfo
.Height
div 2;
4176 FWantsInGame
:= False;
4181 if Self
= gPlayer1
then
4186 if Self
= gPlayer2
then
4193 if g_Game_IsNet
then
4194 MH_SEND_PlayerStats(FUID
);
4197 procedure TPlayer
.SwitchNoClip
;
4201 FGhost
:= not FGhost
;
4202 FPhysics
:= not FGhost
;
4214 procedure TPlayer
.Run(Direction
: TDirection
);
4218 if MAX_RUNVEL
> 8 then
4222 if Direction
= D_LEFT
then
4224 if FObj
.Vel
.X
> -MAX_RUNVEL
then
4225 FObj
.Vel
.X
:= FObj
.Vel
.X
- (MAX_RUNVEL
shr 3);
4228 if FObj
.Vel
.X
< MAX_RUNVEL
then
4229 FObj
.Vel
.X
:= FObj
.Vel
.X
+ (MAX_RUNVEL
shr 3);
4231 // Âîçìîæíî, ïèíàåì êóñêè:
4232 if (FObj
.Vel
.X
<> 0) and (gGibs
<> nil) then
4234 b
:= Abs(FObj
.Vel
.X
);
4235 if b
> 1 then b
:= b
* (Random(8 div b
) + 1);
4236 for a
:= 0 to High(gGibs
) do
4237 if gGibs
[a
].Live
and
4238 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
+FObj
.Rect
.Height
-4,
4239 FObj
.Rect
.Width
, 8, @gGibs
[a
].Obj
) and (Random(3) = 0) then
4241 if FObj
.Vel
.X
< 0 then
4242 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)+120) // íàëåâî
4244 g_Obj_PushA(@gGibs
[a
].Obj
, b
, Random(61)); // íàïðàâî
4250 procedure TPlayer
.SeeDown();
4252 SetAction(A_SEEDOWN
);
4254 if FDirection
= D_LEFT
then FAngle
:= ANGLE_LEFTDOWN
else FAngle
:= ANGLE_RIGHTDOWN
;
4256 if FIncCam
> -120 then DecMin(FIncCam
, 5, -120);
4259 procedure TPlayer
.SeeUp();
4263 if FDirection
= D_LEFT
then FAngle
:= ANGLE_LEFTUP
else FAngle
:= ANGLE_RIGHTUP
;
4265 if FIncCam
< 120 then IncMax(FIncCam
, 5, 120);
4268 procedure TPlayer
.SetAction(Action
: Byte; Force
: Boolean = False);
4276 A_ATTACK
: Prior
:= 2;
4277 A_SEEUP
: Prior
:= 1;
4278 A_SEEDOWN
: Prior
:= 1;
4279 A_ATTACKUP
: Prior
:= 2;
4280 A_ATTACKDOWN
: Prior
:= 2;
4285 if (Prior
> FActionPrior
) or Force
then
4286 if not ((Prior
= 2) and (FCurrWeap
= WEAPON_SAW
)) then
4288 FActionPrior
:= Prior
;
4289 FActionAnim
:= Action
;
4290 FActionForce
:= Force
;
4291 FActionChanged
:= True;
4294 if Action
in [A_ATTACK
, A_ATTACKUP
, A_ATTACKDOWN
] then FModel
.SetFire(True);
4297 function TPlayer
.StayOnStep(XInc
, YInc
: Integer): Boolean;
4299 Result
:= not g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
-1,
4300 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False)
4301 and g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+YInc
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
,
4302 PLAYER_RECT
.Width
, 1, PANEL_STEP
, False);
4305 function TPlayer
.TeleportTo(X
, Y
: Integer; silent
: Boolean; dir
: Byte): Boolean;
4312 if g_CollideLevel(X
, Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
) then
4314 g_Sound_PlayExAt('SOUND_GAME_NOTELEPORT', FObj
.X
, FObj
.Y
);
4315 if g_Game_IsServer
and g_Game_IsNet
then
4316 MH_SEND_Sound(FObj
.X
, FObj
.Y
, 'SOUND_GAME_NOTELEPORT');
4320 FJustTeleported
:= True;
4325 if g_Frames_Get(ID
, 'FRAMES_TELEPORT') then
4327 Anim
:= TAnimation
.Create(ID
, False, 3);
4330 g_Sound_PlayExAt('SOUND_GAME_TELEPORT', FObj
.X
, FObj
.Y
);
4331 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4332 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4333 if g_Game_IsServer
and g_Game_IsNet
then
4334 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4335 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 1,
4339 FObj
.X
:= X
-PLAYER_RECT
.X
;
4340 FObj
.Y
:= Y
-PLAYER_RECT
.Y
;
4341 if FLive
and FGhost
then
4347 if not g_Game_IsNet
then
4351 SetDirection(D_LEFT
);
4357 SetDirection(D_RIGHT
);
4363 if FDirection
= D_RIGHT
then
4365 SetDirection(D_LEFT
);
4370 SetDirection(D_RIGHT
);
4376 if not silent
and (Anim
<> nil) then
4378 g_GFX_OnceAnim(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4379 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, Anim
);
4382 if g_Game_IsServer
and g_Game_IsNet
then
4383 MH_SEND_Effect(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2)-32,
4384 FObj
.Y
+PLAYER_RECT
.Y
+(PLAYER_RECT
.Height
div 2)-32, 0,
4391 function nonz(a
: Single): Single;
4399 procedure TPlayer
.Update();
4402 i
, ii
, wx
, wy
, xd
, yd
, k
: Integer;
4403 blockmon
, headwater
, dospawn
: Boolean;
4408 NetServer
:= g_Game_IsNet
and g_Game_IsServer
;
4409 AnyServer
:= g_Game_IsServer
;
4411 if g_Game_IsClient
and (NetInterpLevel
> 0) then
4412 DoLerp(NetInterpLevel
+ 1)
4418 if FClientID
>= 0 then
4420 FPing
:= NetClients
[FClientID
].Peer
^.lastRoundTripTime
;
4421 if NetClients
[FClientID
].Peer
^.packetsSent
> 0 then
4422 FLoss
:= Round(100*NetClients
[FClientID
].Peer
^.packetsLost
/NetClients
[FClientID
].Peer
^.packetsSent
)
4431 if FLive
and (gFly
or FJetpack
) then
4434 if FDirection
= D_LEFT
then
4439 if FLive
and (not FGhost
) then
4441 if FKeys
[KEY_UP
].Pressed
then
4443 if FKeys
[KEY_DOWN
].Pressed
then
4447 if (not (FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_DOWN
].Pressed
)) and
4450 i
:= g_basic
.Sign(FIncCam
);
4451 FIncCam
:= Abs(FIncCam
);
4452 DecMin(FIncCam
, 5, 0);
4453 FIncCam
:= FIncCam
*i
;
4456 if gTime
mod (GAME_TICK
*2) <> 0 then
4458 if (FObj
.Vel
.X
= 0) and FLive
then
4460 if FKeys
[KEY_LEFT
].Pressed
then
4462 if FKeys
[KEY_RIGHT
].Pressed
then
4467 g_Obj_Move(@FObj
, True, True, True);
4472 FActionChanged
:= False;
4476 // Let alive player do some actions
4477 if FKeys
[KEY_LEFT
].Pressed
then Run(D_LEFT
);
4478 if FKeys
[KEY_RIGHT
].Pressed
then Run(D_RIGHT
);
4479 if FKeys
[KEY_NEXTWEAPON
].Pressed
and AnyServer
then NextWeapon();
4480 if FKeys
[KEY_PREVWEAPON
].Pressed
and AnyServer
then PrevWeapon();
4481 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then Fire();
4482 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Use();
4483 if FKeys
[KEY_JUMP
].Pressed
then Jump()
4486 if AnyServer
and FJetpack
then
4490 if NetServer
then MH_SEND_PlayerStats(FUID
);
4492 FCanJetpack
:= True;
4499 for k
:= Low(FKeys
) to KEY_CHAT
-1 do
4501 if FKeys
[k
].Pressed
then
4509 if gGameSettings
.GameType
in [GT_CUSTOM
, GT_SERVER
, GT_CLIENT
] then
4512 if (FTime
[T_RESPAWN
] <= gTime
) and
4513 gGameOn
and (not FLive
) then
4515 if (g_Player_GetCount() > 1) then
4519 gExit
:= EXIT_RESTART
;
4524 // Dead spectator actions
4527 if FKeys
[KEY_OPEN
].Pressed
and AnyServer
then Fire();
4528 if FKeys
[KEY_FIRE
].Pressed
and AnyServer
then
4532 if (FSpectatePlayer
>= High(gPlayers
)) then
4533 FSpectatePlayer
:= -1
4537 for I
:= FSpectatePlayer
+ 1 to High(gPlayers
) do
4538 if gPlayers
[I
] <> nil then
4539 if gPlayers
[I
].Live
then
4540 if gPlayers
[I
].UID
<> FUID
then
4542 FSpectatePlayer
:= I
;
4547 if not SetSpect
then FSpectatePlayer
:= -1;
4558 if FKeys
[KEY_UP
].Pressed
or FKeys
[KEY_JUMP
].Pressed
then
4560 FYTo
:= FObj
.Y
- 32;
4561 FSpectatePlayer
:= -1;
4563 if FKeys
[KEY_DOWN
].Pressed
then
4565 FYTo
:= FObj
.Y
+ 32;
4566 FSpectatePlayer
:= -1;
4568 if FKeys
[KEY_LEFT
].Pressed
then
4570 FXTo
:= FObj
.X
- 32;
4571 FSpectatePlayer
:= -1;
4573 if FKeys
[KEY_RIGHT
].Pressed
then
4575 FXTo
:= FObj
.X
+ 32;
4576 FSpectatePlayer
:= -1;
4579 if (FXTo
< -64) then
4581 else if (FXTo
> gMapInfo
.Width
+ 32) then
4582 FXTo
:= gMapInfo
.Width
+ 32;
4583 if (FYTo
< -72) then
4585 else if (FYTo
> gMapInfo
.Height
+ 32) then
4586 FYTo
:= gMapInfo
.Height
+ 32;
4590 g_Obj_Move(@FObj
, True, True, True)
4596 if (FSpectatePlayer
<= High(gPlayers
)) and (FSpectatePlayer
>= 0) then
4597 if gPlayers
[FSpectatePlayer
] <> nil then
4598 if gPlayers
[FSpectatePlayer
].Live
then
4600 FXTo
:= gPlayers
[FSpectatePlayer
].GameX
;
4601 FYTo
:= gPlayers
[FSpectatePlayer
].GameY
;
4605 blockmon
:= g_Map_CollidePanel(FObj
.X
+PLAYER_HEADRECT
.X
, FObj
.Y
+PLAYER_HEADRECT
.Y
,
4606 PLAYER_HEADRECT
.Width
, PLAYER_HEADRECT
.Height
,
4607 PANEL_BLOCKMON
, True);
4608 headwater
:= HeadInLiquid(0, 0);
4610 // Ñîïðîòèâëåíèå âîçäóõà:
4611 if (not FLive
) or not (FKeys
[KEY_LEFT
].Pressed
or FKeys
[KEY_RIGHT
].Pressed
) then
4612 if FObj
.Vel
.X
<> 0 then
4613 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
4615 if (FLastHit
= HIT_TRAP
) and (FPain
> 90) then FPain
:= 90;
4616 DecMin(FPain
, 5, 0);
4617 DecMin(FPickup
, 1, 0);
4619 if FLive
and (FObj
.Y
> gMapInfo
.Height
+128) and AnyServer
then
4621 // Îáíóëèòü äåéñòâèÿ ïðèìî÷åê, ÷òîáû ôîí ïðîïàë
4622 FMegaRulez
[MR_SUIT
] := 0;
4623 FMegaRulez
[MR_INVUL
] := 0;
4624 FMegaRulez
[MR_INVIS
] := 0;
4625 Kill(K_FALLKILL
, 0, HIT_FALL
);
4632 if FCurrWeap
= WEAPON_SAW
then
4633 if not (FSawSound
.IsPlaying() or FSawSoundHit
.IsPlaying() or
4634 FSawSoundSelect
.IsPlaying()) then
4635 FSawSoundIdle
.PlayAt(FObj
.X
, FObj
.Y
);
4638 if (not FJetSoundFly
.IsPlaying()) and (not FJetSoundOn
.IsPlaying()) and
4639 (not FJetSoundOff
.IsPlaying()) then
4641 FJetSoundFly
.SetPosition(0);
4642 FJetSoundFly
.PlayAt(FObj
.X
, FObj
.Y
);
4645 for b
:= WEAPON_KASTET
to WEAPON_SUPERPULEMET
do
4646 if FReloading
[b
] > 0 then
4652 if FShellTimer
> -1 then
4653 if FShellTimer
= 0 then
4655 if FShellType
= SHELL_SHELL
then
4656 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
4657 GameVelX
, GameVelY
-2, SHELL_SHELL
)
4658 else if FShellType
= SHELL_DBLSHELL
then
4660 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
4661 GameVelX
+1, GameVelY
-2, SHELL_SHELL
);
4662 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
4663 GameVelX
-1, GameVelY
-2, SHELL_SHELL
);
4666 end else Dec(FShellTimer
);
4668 if (FBFGFireCounter
> -1) then
4669 if FBFGFireCounter
= 0 then
4673 wx
:= FObj
.X
+WEAPONPOINT
[FDirection
].X
;
4674 wy
:= FObj
.Y
+WEAPONPOINT
[FDirection
].Y
;
4675 xd
:= wx
+IfThen(FDirection
= D_LEFT
, -30, 30);
4676 yd
:= wy
+firediry();
4677 g_Weapon_bfgshot(wx
, wy
, xd
, yd
, FUID
);
4678 if NetServer
then MH_SEND_PlayerFire(FUID
, WEAPON_BFG
, wx
, wy
, xd
, yd
);
4679 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
4680 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
4681 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
4684 FReloading
[WEAPON_BFG
] := WEAPON_RELOAD
[WEAPON_BFG
];
4685 FBFGFireCounter
:= -1;
4688 FBFGFireCounter
:= 0
4690 Dec(FBFGFireCounter
);
4692 if (FMegaRulez
[MR_SUIT
] < gTime
) and AnyServer
then
4694 b
:= g_GetAcidHit(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
, PLAYER_RECT
.Height
);
4696 if (b
> 0) and (gTime
mod (15*GAME_TICK
) = 0) then Damage(b
, 0, 0, 0, HIT_ACID
);
4699 if (headwater
or blockmon
) then
4705 if AnyServer
then Damage(10, 0, 0, 0, HIT_WATER
);
4708 else if (FAir
mod 31 = 0) and not blockmon
then
4710 g_GFX_Bubbles(FObj
.X
+PLAYER_RECT
.X
+(PLAYER_RECT
.Width
div 2), FObj
.Y
+PLAYER_RECT
.Y
-4, 5+Random(6), 8, 4);
4711 if Random(2) = 0 then
4712 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
4714 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
4716 end else if FAir
< AIR_DEF
then
4719 if FDamageBuffer
> 0 then
4721 if FDamageBuffer
>= 9 then
4725 if FDamageBuffer
< 30 then i
:= 9
4726 else if FDamageBuffer
< 100 then i
:= 18
4730 ii
:= Round(FDamageBuffer
*FHealth
/ nonz(FArmor
*(3/4)+FHealth
));
4731 FArmor
:= FArmor
-(FDamageBuffer
-ii
);
4732 FHealth
:= FHealth
-ii
;
4735 FHealth
:= FHealth
+FArmor
;
4740 if FHealth
<= 0 then
4741 if FHealth
> -30 then Kill(K_SIMPLEKILL
, FLastSpawnerUID
, FLastHit
)
4742 else if FHealth
> -50 then Kill(K_HARDKILL
, FLastSpawnerUID
, FLastHit
)
4743 else Kill(K_EXTRAHARDKILL
, FLastSpawnerUID
, FLastHit
);
4747 if FDamageBuffer
<= 20 then FModel
.PlaySound(MODELSOUND_PAIN
, 1, FObj
.X
, FObj
.Y
)
4748 else if FDamageBuffer
<= 55 then FModel
.PlaySound(MODELSOUND_PAIN
, 2, FObj
.X
, FObj
.Y
)
4749 else if FDamageBuffer
<= 120 then FModel
.PlaySound(MODELSOUND_PAIN
, 3, FObj
.X
, FObj
.Y
)
4750 else FModel
.PlaySound(MODELSOUND_PAIN
, 4, FObj
.X
, FObj
.Y
);
4757 end; // if FLive then ...
4759 if (FActionAnim
= A_PAIN
) and (FModel
.Animation
<> A_PAIN
) then
4761 FModel
.ChangeAnimation(FActionAnim
, FActionForce
);
4762 FModel
.GetCurrentAnimation
.MinLength
:= i
;
4763 FModel
.GetCurrentAnimationMask
.MinLength
:= i
;
4764 end else FModel
.ChangeAnimation(FActionAnim
, FActionForce
and (FModel
.Animation
<> A_STAND
));
4766 if (FModel
.GetCurrentAnimation
.Played
or ((not FActionChanged
) and (FModel
.Animation
= A_WALK
)))
4767 then SetAction(A_STAND
, True);
4769 if not ((FModel
.Animation
= A_WALK
) and (Abs(FObj
.Vel
.X
) < 4) and not FModel
.Fire
) then FModel
.Update
;
4771 for b
:= Low(FKeys
) to High(FKeys
) do
4772 if FKeys
[b
].Time
= 0 then FKeys
[b
].Pressed
:= False else Dec(FKeys
[b
].Time
);
4775 function TPlayer
.Collide(X
, Y
: Integer; Width
, Height
: Word): Boolean;
4777 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
4778 FObj
.Y
+PLAYER_RECT
.Y
,
4785 function TPlayer
.Collide(Panel
: TPanel
): Boolean;
4787 Result
:= g_Collide(FObj
.X
+PLAYER_RECT
.X
,
4788 FObj
.Y
+PLAYER_RECT
.Y
,
4792 Panel
.Width
, Panel
.Height
);
4795 function TPlayer
.Collide(X
, Y
: Integer): Boolean;
4797 X
:= X
-FObj
.X
-PLAYER_RECT
.X
;
4798 Y
:= Y
-FObj
.Y
-PLAYER_RECT
.Y
;
4799 Result
:= (x
>= 0) and (x
<= PLAYER_RECT
.Width
) and
4800 (y
>= 0) and (y
<= PLAYER_RECT
.Height
);
4803 function g_Player_ValidName(Name
: string): Boolean;
4809 if gPlayers
= nil then Exit
;
4811 for a
:= 0 to High(gPlayers
) do
4812 if gPlayers
[a
] <> nil then
4813 if LowerCase(Name
) = LowerCase(gPlayers
[a
].FName
) then
4820 procedure TPlayer
.SetDirection(Direction
: TDirection
);
4824 d
:= FModel
.Direction
;
4826 FModel
.Direction
:= Direction
;
4827 if d
<> Direction
then FModel
.ChangeAnimation(FModel
.Animation
, True);
4829 FDirection
:= Direction
;
4832 function TPlayer
.GetKeys(): Byte;
4836 if R_KEY_RED
in FRulez
then Result
:= KEY_RED
;
4837 if R_KEY_GREEN
in FRulez
then Result
:= Result
or KEY_GREEN
;
4838 if R_KEY_BLUE
in FRulez
then Result
:= Result
or KEY_BLUE
;
4840 if FTeam
= TEAM_RED
then Result
:= Result
or KEY_REDTEAM
;
4841 if FTeam
= TEAM_BLUE
then Result
:= Result
or KEY_BLUETEAM
;
4844 procedure TPlayer
.Use();
4848 if FTime
[T_USE
] > gTime
then Exit
;
4850 g_Triggers_PressR(FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
, PLAYER_RECT
.Width
,
4851 PLAYER_RECT
.Height
, FUID
, ACTIVATE_PLAYERPRESS
);
4853 for a
:= 0 to High(gPlayers
) do
4854 if (gPlayers
[a
] <> nil) and (gPlayers
[a
] <> Self
) and
4855 gPlayers
[a
].Live
and SameTeam(FUID
, gPlayers
[a
].FUID
) and
4856 g_Obj_Collide(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
4857 FObj
.Rect
.Width
, FObj
.Rect
.Height
, @gPlayers
[a
].FObj
) then
4859 gPlayers
[a
].Touch();
4860 if g_Game_IsNet
and g_Game_IsServer
then
4861 MH_SEND_GameEvent(NET_EV_PLAYER_TOUCH
, gPlayers
[a
].FUID
);
4864 FTime
[T_USE
] := gTime
+120;
4867 procedure TPlayer
.NetFire(Wpn
: Byte; X
, Y
, AX
, AY
: Integer; WID
: Integer = -1);
4871 WX
, WY
, XD
, YD
: Integer;
4882 if R_BERSERK
in FRulez
then
4884 //g_Weapon_punch(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, 75, FUID);
4885 obj
.X
:= FObj
.X
+FObj
.Rect
.X
;
4886 obj
.Y
:= FObj
.Y
+FObj
.Rect
.Y
;
4889 obj
.rect
.Width
:= 39;
4890 obj
.rect
.Height
:= 52;
4891 obj
.Vel
.X
:= (xd
-wx
) div 2;
4892 obj
.Vel
.Y
:= (yd
-wy
) div 2;
4893 obj
.Accel
.X
:= xd
-wx
;
4894 obj
.Accel
.y
:= yd
-wy
;
4896 if g_Weapon_Hit(@obj
, 50, FUID
, HIT_SOME
) <> 0 then
4897 g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj
.X
, FObj
.Y
)
4899 g_Sound_PlayExAt('SOUND_WEAPON_MISSBERSERK', FObj
.X
, FObj
.Y
);
4903 FPain
:= min(FPain
+ 25, 50);
4905 g_Weapon_punch(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
, 3, FUID
);
4910 if g_Weapon_chainsaw(FObj
.X
+FObj
.Rect
.X
, FObj
.Y
+FObj
.Rect
.Y
,
4911 IfThen(gGameSettings
.GameMode
in [GM_DM
, GM_TDM
, GM_CTF
], 9, 3), FUID
) <> 0 then
4913 FSawSoundSelect
.Stop();
4915 FSawSoundHit
.PlayAt(FObj
.X
, FObj
.Y
);
4917 else if not FSawSoundHit
.IsPlaying() then
4919 FSawSoundSelect
.Stop();
4920 FSawSound
.PlayAt(FObj
.X
, FObj
.Y
);
4927 g_Sound_PlayExAt('SOUND_WEAPON_FIREPISTOL', GameX
, Gamey
);
4928 FFireAngle
:= FAngle
;
4930 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
4931 GameVelX
, GameVelY
-2, SHELL_BULLET
);
4936 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
4937 FFireAngle
:= FAngle
;
4940 FShellType
:= SHELL_SHELL
;
4945 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN2', Gamex
, Gamey
);
4946 FFireAngle
:= FAngle
;
4949 FShellType
:= SHELL_DBLSHELL
;
4954 g_Sound_PlayExAt('SOUND_WEAPON_FIRECGUN', Gamex
, Gamey
);
4955 FFireAngle
:= FAngle
;
4957 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
4958 GameVelX
, GameVelY
-2, SHELL_BULLET
);
4961 WEAPON_ROCKETLAUNCHER
:
4963 g_Weapon_Rocket(wx
, wy
, xd
, yd
, FUID
, WID
);
4964 FFireAngle
:= FAngle
;
4970 g_Weapon_Plasma(wx
, wy
, xd
, yd
, FUID
, WID
);
4971 FFireAngle
:= FAngle
;
4977 g_Weapon_BFGShot(wx
, wy
, xd
, yd
, FUID
, WID
);
4978 FFireAngle
:= FAngle
;
4982 WEAPON_SUPERPULEMET
:
4984 g_Sound_PlayExAt('SOUND_WEAPON_FIRESHOTGUN', Gamex
, Gamey
);
4985 FFireAngle
:= FAngle
;
4987 g_Player_CreateShell(GameX
+PLAYER_RECT_CX
, GameY
+PLAYER_RECT_CX
,
4988 GameVelX
, GameVelY
-2, SHELL_SHELL
);
4994 if (FAngle
= 0) or (FAngle
= 180) then SetAction(A_ATTACK
)
4995 else if (FAngle
= ANGLE_LEFTDOWN
) or (FAngle
= ANGLE_RIGHTDOWN
) then SetAction(A_ATTACKDOWN
)
4996 else if (FAngle
= ANGLE_LEFTUP
) or (FAngle
= ANGLE_RIGHTUP
) then SetAction(A_ATTACKUP
);
4999 procedure TPlayer
.DoLerp(Level
: Integer = 2);
5001 if FObj
.X
<> FXTo
then FObj
.X
:= Lerp(FObj
.X
, FXTo
, Level
);
5002 if FObj
.Y
<> FYTo
then FObj
.Y
:= Lerp(FObj
.Y
, FYTo
, Level
);
5005 procedure TPlayer
.SetLerp(XTo
, YTo
: Integer);
5009 if NetInterpLevel
< 1 then
5019 AX
:= Abs(FXTo
- FObj
.X
);
5020 AY
:= Abs(FYTo
- FObj
.Y
);
5021 if (AX
> 32) or (AX
<= NetInterpLevel
) then
5023 if (AY
> 32) or (AY
<= NetInterpLevel
) then
5028 function TPlayer
.FullInLift(XInc
, YInc
: Integer): Integer;
5030 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5031 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5032 PANEL_LIFTUP
, False) then Result
:= -1
5034 if g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
5035 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
-8,
5036 PANEL_LIFTDOWN
, False) then Result
:= 1
5040 function TPlayer
.GetFlag(Flag
: Byte): Boolean;
5047 if Flag
= FLAG_NONE
then
5050 if not g_Game_IsServer
then Exit
;
5052 // Ïðèíåñ ÷óæîé ôëàã íà ñâîþ áàçó:
5053 if (Flag
= FTeam
) and
5054 (gFlags
[Flag
].State
= FLAG_STATE_NORMAL
) and
5055 (FFlag
<> FLAG_NONE
) then
5057 if FFlag
= FLAG_RED
then
5058 s
:= _lc
[I_PLAYER_FLAG_RED
]
5060 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5062 evtype
:= FLAG_STATE_SCORED
;
5064 ts
:= Format('%.4d', [gFlags
[FFlag
].CaptureTime
]);
5065 Insert('.', ts
, Length(ts
) + 1 - 3);
5066 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_CAPTURE
], [FName
, s
, ts
]), True);
5068 g_Map_ResetFlag(FFlag
);
5069 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_CAPTURE
], [AnsiUpperCase(s
)]), 144);
5071 gTeamStat
[FTeam
].Goals
:= gTeamStat
[FTeam
].Goals
+ 1;
5074 if g_Game_IsNet
then
5076 MH_SEND_FlagEvent(evtype
, FFlag
, FUID
, False);
5080 gFlags
[FFlag
].CaptureTime
:= 0;
5085 // Ïîäîáðàë ñâîé ôëàã - âåðíóë åãî íà áàçó:
5086 if (Flag
= FTeam
) and
5087 (gFlags
[Flag
].State
= FLAG_STATE_DROPPED
) then
5089 if Flag
= FLAG_RED
then
5090 s
:= _lc
[I_PLAYER_FLAG_RED
]
5092 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5094 evtype
:= FLAG_STATE_RETURNED
;
5095 gFlags
[Flag
].CaptureTime
:= 0;
5097 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_RETURN
], [FName
, s
]), True);
5099 g_Map_ResetFlag(Flag
);
5100 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_RETURN
], [AnsiUpperCase(s
)]), 144);
5103 if g_Game_IsNet
then
5105 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5111 // Ïîäîáðàë ÷óæîé ôëàã:
5112 if (Flag
<> FTeam
) and (FTime
[T_FLAGCAP
] <= gTime
) then
5116 if Flag
= FLAG_RED
then
5117 s
:= _lc
[I_PLAYER_FLAG_RED
]
5119 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5121 evtype
:= FLAG_STATE_CAPTURED
;
5123 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_GET
], [FName
, s
]), True);
5125 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_GET
], [AnsiUpperCase(s
)]), 144);
5127 gFlags
[Flag
].State
:= FLAG_STATE_CAPTURED
;
5130 if g_Game_IsNet
then
5132 MH_SEND_FlagEvent(evtype
, Flag
, FUID
, False);
5138 procedure TPlayer
.SetFlag(Flag
: Byte);
5141 if FModel
<> nil then
5142 FModel
.SetFlag(FFlag
);
5145 function TPlayer
.DropFlag(): Boolean;
5150 if (not g_Game_IsServer
) or (FFlag
= FLAG_NONE
) then
5152 FTime
[T_FLAGCAP
] := gTime
+ 2000;
5153 with gFlags
[FFlag
] do
5157 Direction
:= FDirection
;
5158 State
:= FLAG_STATE_DROPPED
;
5160 g_Obj_Push(@Obj
, (FObj
.Vel
.X
div 2)-2+Random(5),
5161 (FObj
.Vel
.Y
div 2)-2+Random(5));
5163 if FFlag
= FLAG_RED
then
5164 s
:= _lc
[I_PLAYER_FLAG_RED
]
5166 s
:= _lc
[I_PLAYER_FLAG_BLUE
];
5168 g_Console_Add(Format(_lc
[I_PLAYER_FLAG_DROP
], [FName
, s
]), True);
5169 g_Game_Message(Format(_lc
[I_MESSAGE_FLAG_DROP
], [AnsiUpperCase(s
)]), 144);
5171 if g_Game_IsNet
then
5172 MH_SEND_FlagEvent(FLAG_STATE_DROPPED
, Flag
, FUID
, False);
5178 procedure TPlayer
.GetSecret();
5183 procedure TPlayer
.PressKey(Key
: Byte; Time
: Word = 1);
5185 Assert(Key
<= High(FKeys
));
5187 FKeys
[Key
].Pressed
:= True;
5188 FKeys
[Key
].Time
:= Time
;
5191 function TPlayer
.IsKeyPressed(K
: Byte): Boolean;
5193 Result
:= FKeys
[K
].Pressed
;
5196 procedure TPlayer
.ReleaseKeys();
5200 for a
:= Low(FKeys
) to High(FKeys
) do
5202 FKeys
[a
].Pressed
:= False;
5207 procedure TPlayer
.OnDamage(Angle
: SmallInt);
5211 function TPlayer
.firediry(): Integer;
5213 if FKeys
[KEY_UP
].Pressed
then Result
:= -42
5214 else if FKeys
[KEY_DOWN
].Pressed
then Result
:= 19
5218 procedure TPlayer
.RememberState();
5222 FSavedState
.Health
:= FHealth
;
5223 FSavedState
.Armor
:= FArmor
;
5224 FSavedState
.Air
:= FAir
;
5225 FSavedState
.JetFuel
:= FJetFuel
;
5226 FSavedState
.CurrWeap
:= FCurrWeap
;
5227 FSavedState
.NextWeap
:= FNextWeap
;
5228 FSavedState
.NextWeapDelay
:= FNextWeapDelay
;
5231 FSavedState
.Ammo
[i
] := FAmmo
[i
];
5233 FSavedState
.MaxAmmo
[i
] := FMaxAmmo
[i
];
5235 FSavedState
.Rulez
:= FRulez
;
5236 FSavedState
.WaitRecall
:= True;
5239 procedure TPlayer
.RecallState();
5243 if not FSavedState
.WaitRecall
then Exit
;
5245 FHealth
:= FSavedState
.Health
;
5246 FArmor
:= FSavedState
.Armor
;
5247 FAir
:= FSavedState
.Air
;
5248 FJetFuel
:= FSavedState
.JetFuel
;
5249 FCurrWeap
:= FSavedState
.CurrWeap
;
5250 FNextWeap
:= FSavedState
.NextWeap
;
5251 FNextWeapDelay
:= FSavedState
.NextWeapDelay
;
5254 FAmmo
[i
] := FSavedState
.Ammo
[i
];
5256 FMaxAmmo
[i
] := FSavedState
.MaxAmmo
[i
];
5258 FRulez
:= FSavedState
.Rulez
;
5259 FSavedState
.WaitRecall
:= False;
5261 if gGameSettings
.GameType
= GT_SERVER
then
5262 MH_SEND_PlayerStats(FUID
);
5265 procedure TPlayer
.SaveState(var Mem
: TBinMemoryWriter
);
5277 Mem
:= TBinMemoryWriter
.Create(i
);
5279 // Ñèãíàòóðà èãðîêà:
5280 sig
:= PLAYER_SIGNATURE
; // 'PLYR'
5281 Mem
.WriteDWORD(sig
);
5283 Mem
.WriteBoolean(FIamBot
);
5285 Mem
.WriteWord(FUID
);
5287 Mem
.WriteString(FName
, 32);
5289 Mem
.WriteByte(FTeam
);
5291 Mem
.WriteBoolean(FLive
);
5292 // Èçðàñõîäîâàë ëè âñå æèçíè:
5293 Mem
.WriteBoolean(FNoRespawn
);
5295 if FDirection
= D_LEFT
then
5301 Mem
.WriteInt(FHealth
);
5303 Mem
.WriteByte(FLives
);
5305 Mem
.WriteInt(FArmor
);
5309 Mem
.WriteInt(FJetFuel
);
5311 Mem
.WriteInt(FPain
);
5313 Mem
.WriteInt(FKills
);
5315 Mem
.WriteInt(FMonsterKills
);
5317 Mem
.WriteInt(FFrags
);
5319 Mem
.WriteByte(FFragCombo
);
5320 // Âðåìÿ ïîñëåäíåãî ôðàãà:
5321 Mem
.WriteDWORD(FLastFrag
);
5323 Mem
.WriteInt(FDeath
);
5324 // Êàêîé ôëàã íåñåò:
5325 Mem
.WriteByte(FFlag
);
5327 Mem
.WriteInt(FSecrets
);
5329 Mem
.WriteByte(FCurrWeap
);
5331 Mem
.WriteWord(FNextWeap
);
5333 Mem
.WriteByte(FNextWeapDelay
);
5334 // Âðåìÿ çàðÿäêè BFG:
5335 Mem
.WriteSmallInt(FBFGFireCounter
);
5337 Mem
.WriteInt(FDamageBuffer
);
5338 // Ïîñëåäíèé óäàðèâøèé:
5339 Mem
.WriteWord(FLastSpawnerUID
);
5340 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà:
5341 Mem
.WriteByte(FLastHit
);
5343 Obj_SaveState(@FObj
, Mem
);
5344 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ:
5345 for i
:= A_BULLETS
to A_CELLS
do
5346 Mem
.WriteWord(FAmmo
[i
]);
5347 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ:
5348 for i
:= A_BULLETS
to A_CELLS
do
5349 Mem
.WriteWord(FMaxAmmo
[i
]);
5351 for i
:= WEAPON_KASTET
to WEAPON_SUPERPULEMET
do
5352 Mem
.WriteBoolean(FWeapon
[i
]);
5353 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ:
5354 for i
:= WEAPON_KASTET
to WEAPON_SUPERPULEMET
do
5355 Mem
.WriteWord(FReloading
[i
]);
5357 if R_ITEM_BACKPACK
in FRulez
then
5362 // Íàëè÷èå êðàñíîãî êëþ÷à:
5363 if R_KEY_RED
in FRulez
then
5368 // Íàëè÷èå çåëåíîãî êëþ÷à:
5369 if R_KEY_GREEN
in FRulez
then
5374 // Íàëè÷èå ñèíåãî êëþ÷à:
5375 if R_KEY_BLUE
in FRulez
then
5380 // Íàëè÷èå áåðñåðêà:
5381 if R_BERSERK
in FRulez
then
5386 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ:
5387 for i
:= MR_SUIT
to MR_MAX
do
5388 Mem
.WriteDWORD(FMegaRulez
[i
]);
5389 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà:
5390 for i
:= T_RESPAWN
to T_FLAGCAP
do
5391 Mem
.WriteDWORD(FTime
[i
]);
5394 Mem
.WriteString(str
);
5404 procedure TPlayer
.LoadState(var Mem
: TBinMemoryReader
);
5414 // Ñèãíàòóðà èãðîêà:
5416 if sig
<> PLAYER_SIGNATURE
then // 'PLYR'
5418 raise EBinSizeError
.Create('TPlayer.LoadState: Wrong Player Signature');
5421 Mem
.ReadBoolean(FIamBot
);
5425 Mem
.ReadString(str
);
5426 if (Self
<> gPlayer1
) and (Self
<> gPlayer2
) then
5429 Mem
.ReadByte(FTeam
);
5431 Mem
.ReadBoolean(FLive
);
5432 // Èçðàñõîäîâàë ëè âñå æèçíè:
5433 Mem
.ReadBoolean(FNoRespawn
);
5437 FDirection
:= D_LEFT
5439 FDirection
:= D_RIGHT
;
5441 Mem
.ReadInt(FHealth
);
5443 Mem
.ReadByte(FLives
);
5445 Mem
.ReadInt(FArmor
);
5449 Mem
.ReadInt(FJetFuel
);
5453 Mem
.ReadInt(FKills
);
5455 Mem
.ReadInt(FMonsterKills
);
5457 Mem
.ReadInt(FFrags
);
5459 Mem
.ReadByte(FFragCombo
);
5460 // Âðåìÿ ïîñëåäíåãî ôðàãà:
5461 Mem
.ReadDWORD(FLastFrag
);
5463 Mem
.ReadInt(FDeath
);
5464 // Êàêîé ôëàã íåñåò:
5465 Mem
.ReadByte(FFlag
);
5467 Mem
.ReadInt(FSecrets
);
5469 Mem
.ReadByte(FCurrWeap
);
5471 Mem
.ReadWord(FNextWeap
);
5473 Mem
.ReadByte(FNextWeapDelay
);
5474 // Âðåìÿ çàðÿäêè BFG:
5475 Mem
.ReadSmallInt(FBFGFireCounter
);
5477 Mem
.ReadInt(FDamageBuffer
);
5478 // Ïîñëåäíèé óäàðèâøèé:
5479 Mem
.ReadWord(FLastSpawnerUID
);
5480 // Òèï ïîñëåäíåãî ïîëó÷åííîãî óðîíà:
5481 Mem
.ReadByte(FLastHit
);
5483 Obj_LoadState(@FObj
, Mem
);
5484 // Òåêóùåå êîëè÷åñòâî ïàòðîíîâ:
5485 for i
:= A_BULLETS
to A_CELLS
do
5486 Mem
.ReadWord(FAmmo
[i
]);
5487 // Ìàêñèìàëüíîå êîëè÷åñòâî ïàòðîíîâ:
5488 for i
:= A_BULLETS
to A_CELLS
do
5489 Mem
.ReadWord(FMaxAmmo
[i
]);
5491 for i
:= WEAPON_KASTET
to WEAPON_SUPERPULEMET
do
5492 Mem
.ReadBoolean(FWeapon
[i
]);
5493 // Âðåìÿ ïåðåçàðÿäêè îðóæèÿ:
5494 for i
:= WEAPON_KASTET
to WEAPON_SUPERPULEMET
do
5495 Mem
.ReadWord(FReloading
[i
]);
5499 Include(FRulez
, R_ITEM_BACKPACK
);
5500 // Íàëè÷èå êðàñíîãî êëþ÷à:
5503 Include(FRulez
, R_KEY_RED
);
5504 // Íàëè÷èå çåëåíîãî êëþ÷à:
5507 Include(FRulez
, R_KEY_GREEN
);
5508 // Íàëè÷èå ñèíåãî êëþ÷à:
5511 Include(FRulez
, R_KEY_BLUE
);
5512 // Íàëè÷èå áåðñåðêà:
5515 Include(FRulez
, R_BERSERK
);
5516 // Âðåìÿ äåéñòâèÿ ñïåöèàëüíûõ ïðåäìåòîâ:
5517 for i
:= MR_SUIT
to MR_MAX
do
5518 Mem
.ReadDWORD(FMegaRulez
[i
]);
5519 // Âðåìÿ äî ïîâòîðíîãî ðåñïàóíà, ñìåíû îðóæèÿ, èñîëüçîâàíèÿ, çàõâàòà ôëàãà:
5520 for i
:= T_RESPAWN
to T_FLAGCAP
do
5521 Mem
.ReadDWORD(FTime
[i
]);
5523 Mem
.ReadString(str
);
5525 Mem
.ReadByte(FColor
.R
);
5526 Mem
.ReadByte(FColor
.G
);
5527 Mem
.ReadByte(FColor
.B
);
5528 if Self
= gPlayer1
then
5530 str
:= gPlayer1Settings
.Model
;
5531 FColor
:= gPlayer1Settings
.Color
;
5533 if Self
= gPlayer2
then
5535 str
:= gPlayer2Settings
.Model
;
5536 FColor
:= gPlayer2Settings
.Color
;
5538 // Îáíîâëÿåì ìîäåëü èãðîêà:
5540 if gGameSettings
.GameMode
in [GM_TDM
, GM_CTF
] then
5541 FModel
.Color
:= TEAMCOLOR
[FTeam
]
5543 FModel
.Color
:= FColor
;
5546 procedure TPlayer
.AllRulez(Health
: Boolean);
5552 FHealth
:= PLAYER_HP_LIMIT
;
5553 FArmor
:= PLAYER_AP_LIMIT
;
5557 for a
:= WEAPON_KASTET
to WEAPON_SUPERPULEMET
do FWeapon
[a
] := True;
5558 for a
:= A_BULLETS
to A_CELLS
do FAmmo
[a
] := 30000;
5559 FRulez
:= FRulez
+[R_KEY_RED
, R_KEY_GREEN
, R_KEY_BLUE
];
5562 procedure TPlayer
.RestoreHealthArmor();
5564 FHealth
:= PLAYER_HP_LIMIT
;
5565 FArmor
:= PLAYER_AP_LIMIT
;
5568 procedure TPlayer
.FragCombo();
5572 if (gGameSettings
.GameMode
in [GM_COOP
, GM_SINGLE
]) or g_Game_IsClient
then
5574 if gTime
- FLastFrag
< FRAG_COMBO_TIME
then
5576 if FFragCombo
< 5 then
5578 Param
:= FUID
or (FFragCombo
shl 16);
5579 if (FComboEvnt
>= Low(gDelayedEvents
)) and
5580 (FComboEvnt
<= High(gDelayedEvents
)) and
5581 gDelayedEvents
[FComboEvnt
].Pending
and
5582 (gDelayedEvents
[FComboEvnt
].DEType
= DE_KILLCOMBO
) and
5583 (gDelayedEvents
[FComboEvnt
].DENum
and $FFFF = FUID
) then
5585 gDelayedEvents
[FComboEvnt
].Time
:= gTime
+ 500;
5586 gDelayedEvents
[FComboEvnt
].DENum
:= Param
;
5589 FComboEvnt
:= g_Game_DelayEvent(DE_KILLCOMBO
, 500, Param
);
5597 procedure TPlayer
.GiveItem(ItemType
: Byte);
5601 if FMegaRulez
[MR_SUIT
] < gTime
+PLAYER_SUIT_TIME
then
5603 FMegaRulez
[MR_SUIT
] := gTime
+PLAYER_SUIT_TIME
;
5607 if FAir
< AIR_MAX
then
5614 if not (R_BERSERK
in FRulez
) then
5616 Include(FRulez
, R_BERSERK
);
5617 if FBFGFireCounter
< 1 then
5619 FCurrWeap
:= WEAPON_KASTET
;
5621 FModel
.SetWeapon(WEAPON_KASTET
);
5625 FBerserk
:= gTime
+30000;
5627 if FHealth
< PLAYER_HP_SOFT
then
5629 FHealth
:= PLAYER_HP_SOFT
;
5630 FBerserk
:= gTime
+30000;
5635 if FMegaRulez
[MR_INVUL
] < gTime
+PLAYER_INVUL_TIME
then
5637 FMegaRulez
[MR_INVUL
] := gTime
+PLAYER_INVUL_TIME
;
5641 if FMegaRulez
[MR_INVIS
] < gTime
+PLAYER_INVIS_TIME
then
5643 FMegaRulez
[MR_INVIS
] := gTime
+PLAYER_INVIS_TIME
;
5647 if FJetFuel
< JET_MAX
then
5649 FJetFuel
:= JET_MAX
;
5652 ITEM_MEDKIT_SMALL
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 10, PLAYER_HP_SOFT
);
5653 ITEM_MEDKIT_LARGE
: if FHealth
< PLAYER_HP_SOFT
then IncMax(FHealth
, 25, PLAYER_HP_SOFT
);
5655 ITEM_ARMOR_GREEN
: if FArmor
< PLAYER_AP_SOFT
then FArmor
:= PLAYER_AP_SOFT
;
5656 ITEM_ARMOR_BLUE
: if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
5658 ITEM_SPHERE_BLUE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 100, PLAYER_HP_LIMIT
);
5660 if (FHealth
< PLAYER_HP_LIMIT
) or (FArmor
< PLAYER_AP_LIMIT
) then
5662 if FHealth
< PLAYER_HP_LIMIT
then FHealth
:= PLAYER_HP_LIMIT
;
5663 if FArmor
< PLAYER_AP_LIMIT
then FArmor
:= PLAYER_AP_LIMIT
;
5666 ITEM_WEAPON_SAW
: FWeapon
[WEAPON_SAW
] := True;
5667 ITEM_WEAPON_SHOTGUN1
: FWeapon
[WEAPON_SHOTGUN1
] := True;
5668 ITEM_WEAPON_SHOTGUN2
: FWeapon
[WEAPON_SHOTGUN2
] := True;
5669 ITEM_WEAPON_CHAINGUN
: FWeapon
[WEAPON_CHAINGUN
] := True;
5670 ITEM_WEAPON_ROCKETLAUNCHER
: FWeapon
[WEAPON_ROCKETLAUNCHER
] := True;
5671 ITEM_WEAPON_PLASMA
: FWeapon
[WEAPON_PLASMA
] := True;
5672 ITEM_WEAPON_BFG
: FWeapon
[WEAPON_BFG
] := True;
5673 ITEM_WEAPON_SUPERPULEMET
: FWeapon
[WEAPON_SUPERPULEMET
] := True;
5675 ITEM_AMMO_BULLETS
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
5676 ITEM_AMMO_BULLETS_BOX
: if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 50, FMaxAmmo
[A_BULLETS
]);
5677 ITEM_AMMO_SHELLS
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
5678 ITEM_AMMO_SHELLS_BOX
: if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 25, FMaxAmmo
[A_SHELLS
]);
5679 ITEM_AMMO_ROCKET
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
5680 ITEM_AMMO_ROCKET_BOX
: if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 5, FMaxAmmo
[A_ROCKETS
]);
5681 ITEM_AMMO_CELL
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
5682 ITEM_AMMO_CELL_BIG
: if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 100, FMaxAmmo
[A_CELLS
]);
5685 if (FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
]) or
5686 (FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
]) or
5687 (FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
]) or
5688 (FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
]) then
5690 FMaxAmmo
[A_BULLETS
] := 400;
5691 FMaxAmmo
[A_SHELLS
] := 100;
5692 FMaxAmmo
[A_ROCKETS
] := 100;
5693 FMaxAmmo
[A_CELLS
] := 600;
5695 if FAmmo
[A_BULLETS
] < FMaxAmmo
[A_BULLETS
] then IncMax(FAmmo
[A_BULLETS
], 10, FMaxAmmo
[A_BULLETS
]);
5696 if FAmmo
[A_SHELLS
] < FMaxAmmo
[A_SHELLS
] then IncMax(FAmmo
[A_SHELLS
], 4, FMaxAmmo
[A_SHELLS
]);
5697 if FAmmo
[A_ROCKETS
] < FMaxAmmo
[A_ROCKETS
] then IncMax(FAmmo
[A_ROCKETS
], 1, FMaxAmmo
[A_ROCKETS
]);
5698 if FAmmo
[A_CELLS
] < FMaxAmmo
[A_CELLS
] then IncMax(FAmmo
[A_CELLS
], 40, FMaxAmmo
[A_CELLS
]);
5700 FRulez
:= FRulez
+ [R_ITEM_BACKPACK
];
5703 ITEM_KEY_RED
: if not (R_KEY_RED
in FRulez
) then Include(FRulez
, R_KEY_RED
);
5704 ITEM_KEY_GREEN
: if not (R_KEY_GREEN
in FRulez
) then Include(FRulez
, R_KEY_GREEN
);
5705 ITEM_KEY_BLUE
: if not (R_KEY_BLUE
in FRulez
) then Include(FRulez
, R_KEY_BLUE
);
5707 ITEM_BOTTLE
: if FHealth
< PLAYER_HP_LIMIT
then IncMax(FHealth
, 4, PLAYER_HP_LIMIT
);
5708 ITEM_HELMET
: if FArmor
< PLAYER_AP_LIMIT
then IncMax(FArmor
, 5, PLAYER_AP_LIMIT
);
5713 if g_Game_IsNet
and g_Game_IsServer
then
5714 MH_SEND_PlayerStats(FUID
);
5717 procedure TPlayer
.FlySmoke(Times
: DWORD
= 1);
5722 if (Random(5) = 1) and (Times
= 1) then
5725 if BodyInLiquid(0, 0) then
5727 g_GFX_Bubbles(Obj
.X
+Obj
.Rect
.X
+(Obj
.Rect
.Width
div 2)+Random(3)-1,
5728 Obj
.Y
+Obj
.Rect
.Height
+8, 1, 8, 4);
5729 if Random(2) = 0 then
5730 g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj
.X
, FObj
.Y
)
5732 g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj
.X
, FObj
.Y
);
5736 if g_Frames_Get(id
, 'FRAMES_SMOKE') then
5738 for i
:= 1 to Times
do
5740 Anim
:= TAnimation
.Create(id
, False, 3);
5742 g_GFX_OnceAnim(Obj
.X
+Obj
.Rect
.X
+Random(Obj
.Rect
.Width
+Times
*2)-(Anim
.Width
div 2),
5743 Obj
.Y
+Obj
.Rect
.Height
-4+Random(8+Times
*2), Anim
, ONCEANIM_SMOKE
);
5749 procedure TPlayer
.PauseSounds(Enable
: Boolean);
5751 FSawSound
.Pause(Enable
);
5752 FSawSoundIdle
.Pause(Enable
);
5753 FSawSoundHit
.Pause(Enable
);
5754 FSawSoundSelect
.Pause(Enable
);
5759 constructor TCorpse
.Create(X
, Y
: Integer; ModelName
: String; aMess
: Boolean);
5764 FObj
.Rect
:= PLAYER_CORPSERECT
;
5765 FModelName
:= ModelName
;
5770 FState
:= CORPSE_STATE_MESS
;
5771 g_PlayerModel_GetAnim(ModelName
, A_DIE2
, FAnimation
, FAnimationMask
);
5775 FState
:= CORPSE_STATE_NORMAL
;
5776 g_PlayerModel_GetAnim(ModelName
, A_DIE1
, FAnimation
, FAnimationMask
);
5780 destructor TCorpse
.Destroy();
5787 procedure TCorpse
.Damage(Value
: Word; vx
, vy
: Integer);
5791 if FState
= CORPSE_STATE_REMOVEME
then
5794 FDamage
:= FDamage
+ Value
;
5796 if FDamage
> 150 then
5798 if FAnimation
<> nil then
5803 FState
:= CORPSE_STATE_REMOVEME
;
5805 g_Player_CreateGibs(FObj
.X
+FObj
.Rect
.X
+(FObj
.Rect
.Width
div 2),
5806 FObj
.Y
+FObj
.Rect
.Y
+(FObj
.Rect
.Height
div 2),
5807 FModelName
, FColor
);
5808 // Çâóê ìÿñà îò òðóïà:
5809 pm
:= g_PlayerModel_Get(FModelName
);
5810 pm
.PlaySound(MODELSOUND_DIE
, 5, FObj
.X
, FObj
.Y
);
5816 FObj
.Vel
.X
:= FObj
.Vel
.X
+ vx
;
5817 FObj
.Vel
.Y
:= FObj
.Vel
.Y
+ vy
;
5818 g_GFX_Blood(FObj
.X
+PLAYER_CORPSERECT
.X
+(PLAYER_CORPSERECT
.Width
div 2),
5819 FObj
.Y
+PLAYER_CORPSERECT
.Y
+(PLAYER_CORPSERECT
.Height
div 2),
5820 Value
, vx
, vy
, 16, (PLAYER_CORPSERECT
.Height
*2) div 3,
5825 procedure TCorpse
.Draw();
5827 if FState
= CORPSE_STATE_REMOVEME
then
5830 if FAnimation
<> nil then
5831 FAnimation
.Draw(FObj
.X
, FObj
.Y
, M_NONE
);
5833 if FAnimationMask
<> nil then
5836 FAnimationMask
.Draw(FObj
.X
, FObj
.Y
, M_NONE
);
5843 procedure TCorpse
.Update();
5847 if FState
= CORPSE_STATE_REMOVEME
then
5850 if gTime
mod (GAME_TICK
*2) <> 0 then
5852 g_Obj_Move(@FObj
, True, True, True);
5857 // Ñîïðîòèâëåíèå âîçäóõà äëÿ òðóïà:
5858 FObj
.Vel
.X
:= z_dec(FObj
.Vel
.X
, 1);
5860 st
:= g_Obj_Move(@FObj
, True, True, True);
5862 if WordBool(st
and MOVE_FALLOUT
) then
5864 FState
:= CORPSE_STATE_REMOVEME
;
5868 if FAnimation
<> nil then
5869 FAnimation
.Update();
5870 if FAnimationMask
<> nil then
5871 FAnimationMask
.Update();
5874 procedure TCorpse
.SaveState(var Mem
: TBinMemoryWriter
);
5883 sig
:= CORPSE_SIGNATURE
; // 'CORP'
5884 Mem
.WriteDWORD(sig
);
5886 Mem
.WriteByte(FState
);
5887 // Íàêîïëåííûé óðîí:
5888 Mem
.WriteByte(FDamage
);
5890 Mem
.WriteByte(FColor
.R
);
5891 Mem
.WriteByte(FColor
.G
);
5892 Mem
.WriteByte(FColor
.B
);
5894 Obj_SaveState(@FObj
, Mem
);
5895 // Åñòü ëè àíèìàöèÿ:
5896 anim
:= FAnimation
<> nil;
5897 Mem
.WriteBoolean(anim
);
5898 // Åñëè åñòü - ñîõðàíÿåì:
5900 FAnimation
.SaveState(Mem
);
5901 // Åñòü ëè ìàñêà àíèìàöèè:
5902 anim
:= FAnimationMask
<> nil;
5903 Mem
.WriteBoolean(anim
);
5904 // Åñëè åñòü - ñîõðàíÿåì:
5906 FAnimationMask
.SaveState(Mem
);
5909 procedure TCorpse
.LoadState(var Mem
: TBinMemoryReader
);
5919 if sig
<> CORPSE_SIGNATURE
then // 'CORP'
5921 raise EBinSizeError
.Create('TCorpse.LoadState: Wrong Corpse Signature');
5924 Mem
.ReadByte(FState
);
5925 // Íàêîïëåííûé óðîí:
5926 Mem
.ReadByte(FDamage
);
5928 Mem
.ReadByte(FColor
.R
);
5929 Mem
.ReadByte(FColor
.G
);
5930 Mem
.ReadByte(FColor
.B
);
5932 Obj_LoadState(@FObj
, Mem
);
5933 // Åñòü ëè àíèìàöèÿ:
5934 Mem
.ReadBoolean(anim
);
5935 // Åñëè åñòü - çàãðóæàåì:
5938 Assert(FAnimation
<> nil, 'TCorpse.LoadState: no FAnimation');
5939 FAnimation
.LoadState(Mem
);
5941 // Åñòü ëè ìàñêà àíèìàöèè:
5942 Mem
.ReadBoolean(anim
);
5943 // Åñëè åñòü - çàãðóæàåì:
5946 Assert(FAnimationMask
<> nil, 'TCorpse.LoadState: no FAnimationMask');
5947 FAnimationMask
.LoadState(Mem
);
5953 constructor TBot
.Create();
5960 FSpectator
:= False;
5967 for a
:= WEAPON_KASTET
to WEAPON_SUPERPULEMET
do
5969 FDifficult
.WeaponPrior
[a
] := WEAPON_PRIOR1
[a
];
5970 FDifficult
.CloseWeaponPrior
[a
] := WEAPON_PRIOR2
[a
];
5971 //FDifficult.SafeWeaponPrior[a] := WEAPON_PRIOR3[a];
5975 destructor TBot
.Destroy();
5978 inherited Destroy();
5981 procedure TBot
.Draw();
5985 //if FTargetUID <> 0 then e_DrawLine(1, FObj.X, FObj.Y, g_Player_Get(FTargetUID).FObj.X,
5986 // g_Player_Get(FTargetUID).FObj.Y, 255, 0, 0);
5989 procedure TBot
.Respawn(Silent
: Boolean; Force
: Boolean = False);
5991 inherited Respawn(Silent
, Force
);
5994 FSelectedWeapon
:= FCurrWeap
;
5999 procedure TBot
.UpdateCombat();
6012 TTargetRecord
= array of TTarget
;
6014 function Compare(a
, b
: TTarget
): Integer;
6016 if a
.Line
and not b
.Line
then // A íà ëèíèè îãíÿ
6019 if not a
.Line
and b
.Line
then // B íà ëèíèè îãíÿ
6021 else // È A, è B íà ëèíèè èëè íå íà ëèíèè îãíÿ
6022 if (a
.Line
and b
.Line
) or ((not a
.Line
) and (not b
.Line
)) then
6024 if a
.Dist
> b
.Dist
then // B áëèæå
6026 else // A áëèæå èëè ðàâíîóäàëåííî ñ B
6029 else // Ñòðàííî -> A
6034 a
, x1
, y1
, x2
, y2
: Integer;
6035 targets
: TTargetRecord
;
6037 Target
, BestTarget
: TTarget
;
6038 firew
, fireh
: Integer;
6042 vsPlayer
, vsMonster
, ok
: Boolean;
6044 vsPlayer
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
);
6045 vsMonster
:= LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
);
6047 // Åñëè òåêóùåå îðóæèå íå òî, ÷òî íóæíî, òî ìåíÿåì:
6048 if FCurrWeap
<> FSelectedWeapon
then
6051 // Åñëè íóæíî ñòðåëÿòü è íóæíîå îðóæèå, òî íàæàòü "Ñòðåëÿòü":
6052 if (GetAIFlag('NEEDFIRE') <> '') and (FCurrWeap
= FSelectedWeapon
) then
6054 RemoveAIFlag('NEEDFIRE');
6057 WEAPON_PLASMA
, WEAPON_SUPERPULEMET
, WEAPON_CHAINGUN
: PressKey(KEY_FIRE
, 20);
6058 WEAPON_SAW
, WEAPON_KASTET
, WEAPON_MEGAKASTET
: PressKey(KEY_FIRE
, 40);
6059 else PressKey(KEY_FIRE
);
6063 // Êîîðäèíàòû ñòâîëà:
6064 x1
:= FObj
.X
+ WEAPONPOINT
[FDirection
].X
;
6065 y1
:= FObj
.Y
+ WEAPONPOINT
[FDirection
].Y
;
6067 Target
.UID
:= FTargetUID
;
6070 if Target
.UID
<> 0 then
6071 begin // Öåëü åñòü - íàñòðàèâàåì
6072 if (g_GetUIDType(Target
.UID
) = UID_PLAYER
) and
6075 with g_Player_Get(Target
.UID
) do
6077 if (@FObj
) <> nil then
6084 Target
.cX
:= Target
.X
+ PLAYER_RECT_CX
;
6085 Target
.cY
:= Target
.Y
+ PLAYER_RECT_CY
;
6086 Target
.Rect
:= PLAYER_RECT
;
6087 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6088 Target
.Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6089 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6090 Target
.IsPlayer
:= True;
6094 if (g_GetUIDType(Target
.UID
) = UID_MONSTER
) and
6097 mon
:= g_Monsters_Get(Target
.UID
);
6100 Target
.X
:= mon
.Obj
.X
;
6101 Target
.Y
:= mon
.Obj
.Y
;
6103 Target
.cX
:= Target
.X
+ mon
.Obj
.Rect
.X
+ (mon
.Obj
.Rect
.Width
div 2);
6104 Target
.cY
:= Target
.Y
+ mon
.Obj
.Rect
.Y
+ (mon
.Obj
.Rect
.Height
div 2);
6105 Target
.Rect
:= mon
.Obj
.Rect
;
6106 Target
.Visible
:= g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
);
6107 Target
.Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6108 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6109 Target
.IsPlayer
:= False;
6116 begin // Öåëè íåò - îáíóëÿåì
6121 Target
.Visible
:= False;
6122 Target
.Line
:= False;
6123 Target
.IsPlayer
:= False;
6128 // Åñëè öåëü íå âèäèìà èëè íå íà ëèíèè îãíÿ, òî èùåì âñå âîçìîæíûå öåëè:
6129 if (not Target
.Line
) or (not Target
.Visible
) then
6133 for a
:= 0 to High(gPlayers
) do
6134 if (gPlayers
[a
] <> nil) and (gPlayers
[a
].Live
) and
6135 (gPlayers
[a
].FUID
<> FUID
) and
6136 (not SameTeam(FUID
, gPlayers
[a
].FUID
)) and
6137 (not gPlayers
[a
].NoTarget
) and
6138 (gPlayers
[a
].FMegaRulez
[MR_INVIS
] < gTime
) then
6140 if not TargetOnScreen(gPlayers
[a
].FObj
.X
+ PLAYER_RECT
.X
,
6141 gPlayers
[a
].FObj
.Y
+ PLAYER_RECT
.Y
) then
6144 x2
:= gPlayers
[a
].FObj
.X
+ PLAYER_RECT_CX
;
6145 y2
:= gPlayers
[a
].FObj
.Y
+ PLAYER_RECT_CY
;
6147 // Åñëè èãðîê íà ýêðàíå è íå ïðèêðûò ñòåíîé:
6148 if g_TraceVector(x1
, y1
, x2
, y2
) then
6150 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé:
6151 SetLength(targets
, Length(targets
)+1);
6152 with targets
[High(targets
)] do
6154 UID
:= gPlayers
[a
].FUID
;
6155 X
:= gPlayers
[a
].FObj
.X
;
6156 Y
:= gPlayers
[a
].FObj
.Y
;
6159 Rect
:= PLAYER_RECT
;
6160 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6161 Line
:= (y1
+4 < Target
.Y
+PLAYER_RECT
.Y
+PLAYER_RECT
.Height
) and
6162 (y1
-4 > Target
.Y
+PLAYER_RECT
.Y
);
6170 if vsMonster
and (gMonsters
<> nil) then
6171 for a
:= 0 to High(gMonsters
) do
6172 if (gMonsters
[a
] <> nil) and (gMonsters
[a
].Live
) and
6173 (gMonsters
[a
].MonsterType
<> MONSTER_BARREL
) then
6175 mon
:= gMonsters
[a
];
6177 if not TargetOnScreen(mon
.Obj
.X
+ mon
.Obj
.Rect
.X
,
6178 mon
.Obj
.Y
+ mon
.Obj
.Rect
.Y
) then
6181 x2
:= mon
.Obj
.X
+ mon
.Obj
.Rect
.X
+ (mon
.Obj
.Rect
.Width
div 2);
6182 y2
:= mon
.Obj
.Y
+ mon
.Obj
.Rect
.Y
+ (mon
.Obj
.Rect
.Height
div 2);
6184 // Åñëè ìîíñòð íà ýêðàíå è íå ïðèêðûò ñòåíîé:
6185 if g_TraceVector(x1
, y1
, x2
, y2
) then
6187 // Äîáàâëÿåì ê ñïèñêó âîçìîæíûõ öåëåé:
6188 SetLength(targets
, Length(targets
)+1);
6189 with targets
[High(targets
)] do
6196 Rect
:= mon
.Obj
.Rect
;
6197 Dist
:= g_PatchLength(x1
, y1
, x2
, y2
);
6198 Line
:= (y1
+4 < Target
.Y
+ mon
.Obj
.Rect
.Y
+ mon
.Obj
.Rect
.Height
) and
6199 (y1
-4 > Target
.Y
+ mon
.Obj
.Rect
.Y
);
6207 // Åñëè åñòü âîçìîæíûå öåëè:
6208 // (Âûáèðàåì ëó÷øóþ, ìåíÿåì îðóæèå è áåæèì ê íåé/îò íåå)
6209 if targets
<> nil then
6211 // Âûáèðàåì íàèëó÷øóþ öåëü:
6212 BestTarget
:= targets
[0];
6213 if Length(targets
) > 1 then
6214 for a
:= 1 to High(targets
) do
6215 if Compare(BestTarget
, targets
[a
]) = 1 then
6216 BestTarget
:= targets
[a
];
6218 // Åñëè ëó÷øàÿ öåëü "âèäíåå" òåêóùåé, òî òåêóùàÿ := ëó÷øàÿ:
6219 if ((not Target
.Visible
) and BestTarget
.Visible
and (Target
.UID
<> BestTarget
.UID
)) or
6220 ((not Target
.Line
) and BestTarget
.Line
and BestTarget
.Visible
) then
6222 Target
:= BestTarget
;
6224 if (Healthy() = 3) or ((Healthy() = 2)) then
6225 begin // Åñëè çäîðîâû - äîãîíÿåì
6226 if ((RunDirection() = D_LEFT
) and (Target
.X
> FObj
.X
)) then
6227 SetAIFlag('GORIGHT', '1');
6228 if ((RunDirection() = D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6229 SetAIFlag('GOLEFT', '1');
6232 begin // Åñëè ïîáèòû - óáåãàåì
6233 if ((RunDirection() = D_LEFT
) and (Target
.X
< FObj
.X
)) then
6234 SetAIFlag('GORIGHT', '1');
6235 if ((RunDirection() = D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6236 SetAIFlag('GOLEFT', '1');
6239 // Âûáèðàåì îðóæèå íà îñíîâå ðàññòîÿíèÿ è ïðèîðèòåòîâ:
6240 SelectWeapon(Abs(x1
-Target
.cX
));
6245 // (Äîãîíÿåì/óáåãàåì, ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëè)
6246 // (Åñëè öåëü äàëåêî, òî õâàòèò ñëåäèòü çà íåé)
6247 if Target
.UID
<> 0 then
6249 if not TargetOnScreen(Target
.X
+ Target
.Rect
.X
,
6250 Target
.Y
+ Target
.Rect
.Y
) then
6251 begin // Öåëü ñáåæàëà ñ "ýêðàíà"
6252 if (Healthy() = 3) or ((Healthy() = 2)) then
6253 begin // Åñëè çäîðîâû - äîãîíÿåì
6254 if ((RunDirection() = D_LEFT
) and (Target
.X
> FObj
.X
)) then
6255 SetAIFlag('GORIGHT', '1');
6256 if ((RunDirection() = D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6257 SetAIFlag('GOLEFT', '1');
6260 begin // Åñëè ïîáèòû - çàáûâàåì î öåëè è óáåãàåì
6262 if ((RunDirection() = D_LEFT
) and (Target
.X
< FObj
.X
)) then
6263 SetAIFlag('GORIGHT', '1');
6264 if ((RunDirection() = D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6265 SetAIFlag('GOLEFT', '1');
6269 begin // Öåëü ïîêà íà "ýêðàíå"
6270 // Åñëè öåëü íå çàãîðîæåíà ñòåíîé, òî îòìå÷àåì, êîãäà åå âèäåëè:
6271 if g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6272 FLastVisible
:= gTime
;
6273 // Åñëè ðàçíèöà âûñîò íå âåëèêà, òî äîãîíÿåì:
6274 if (Abs(FObj
.Y
-Target
.Y
) <= 128) then
6276 if ((RunDirection() = D_LEFT
) and (Target
.X
> FObj
.X
)) then
6277 SetAIFlag('GORIGHT', '1');
6278 if ((RunDirection() = D_RIGHT
) and (Target
.X
< FObj
.X
)) then
6279 SetAIFlag('GOLEFT', '1');
6283 // Âûáèðàåì óãîë ââåðõ:
6284 if FDirection
= D_LEFT
then
6285 angle
:= ANGLE_LEFTUP
6287 angle
:= ANGLE_RIGHTUP
;
6289 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6290 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6292 // Åñëè ïðè óãëå ââåðõ ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
6293 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6294 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128), //96
6295 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6296 Target
.Rect
.Width
, Target
.Rect
.Height
) and
6297 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6298 begin // òî íóæíî ñòðåëÿòü ââåðõ
6299 SetAIFlag('NEEDFIRE', '1');
6300 SetAIFlag('NEEDSEEUP', '1');
6303 // Âûáèðàåì óãîë âíèç:
6304 if FDirection
= D_LEFT
then
6305 angle
:= ANGLE_LEFTDOWN
6307 angle
:= ANGLE_RIGHTDOWN
;
6309 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6310 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6312 // Åñëè ïðè óãëå âíèç ìîæíî ïîïàñòü â ïðèáëèçèòåëüíîå ïîëîæåíèå öåëè:
6313 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6314 Target
.X
+Target
.Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
6315 Target
.Y
+Target
.Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6316 Target
.Rect
.Width
, Target
.Rect
.Height
) and
6317 g_TraceVector(x1
, y1
, Target
.cX
, Target
.cY
) then
6318 begin // òî íóæíî ñòðåëÿòü âíèç
6319 SetAIFlag('NEEDFIRE', '1');
6320 SetAIFlag('NEEDSEEDOWN', '1');
6323 // Åñëè öåëü âèäíî è îíà íà òàêîé æå âûñîòå:
6324 if Target
.Visible
and
6325 (y1
+4 < Target
.Y
+Target
.Rect
.Y
+Target
.Rect
.Height
) and
6326 (y1
-4 > Target
.Y
+Target
.Rect
.Y
) then
6328 // Åñëè èäåì â ñòîðîíó öåëè, òî íàäî ñòðåëÿòü:
6329 if ((FDirection
= D_LEFT
) and (Target
.X
< FObj
.X
)) or
6330 ((FDirection
= D_RIGHT
) and (Target
.X
> FObj
.X
)) then
6331 begin // òî íóæíî ñòðåëÿòü âïåðåä
6332 SetAIFlag('NEEDFIRE', '1');
6333 SetAIFlag('NEEDSEEDOWN', '');
6334 SetAIFlag('NEEDSEEUP', '');
6336 // Åñëè öåëü â ïðåäåëàõ "ýêðàíà" è ñëîæíîñòü ïîçâîëÿåò ïðûæêè ñáëèæåíèÿ:
6337 if Abs(FObj
.X
-Target
.X
) < Trunc(gPlayerScreenSize
.X
*0.75) then
6338 if GetRnd(FDifficult
.CloseJump
) then
6339 begin // òî åñëè ïîâåçåò - ïðûãàåì (îñîáåííî, åñëè áëèçêî)
6340 if Abs(FObj
.X
-Target
.X
) < 128 then
6344 if Random(a
) = 0 then
6345 SetAIFlag('NEEDJUMP', '1');
6349 // Åñëè öåëü âñå åùå åñòü:
6350 if Target
.UID
<> 0 then
6351 if gTime
-FLastVisible
> 2000 then // Åñëè âèäåëè äàâíî
6352 Target
.UID
:= 0 // òî çàáûòü öåëü
6353 else // Åñëè âèäåëè íåäàâíî
6354 begin // íî öåëü óáèëè
6355 if Target
.IsPlayer
then
6356 begin // Öåëü - èãðîê
6357 pla
:= g_Player_Get(Target
.UID
);
6358 if (pla
= nil) or (not pla
.Live
) or pla
.NoTarget
or
6359 (pla
.FMegaRulez
[MR_INVIS
] >= gTime
) then
6360 Target
.UID
:= 0; // òî çàáûòü öåëü
6363 begin // Öåëü - ìîíñòð
6364 mon
:= g_Monsters_Get(Target
.UID
);
6365 if (mon
= nil) or (not mon
.Live
) then
6366 Target
.UID
:= 0; // òî çàáûòü öåëü
6369 end; // if Target.UID <> 0
6371 FTargetUID
:= Target
.UID
;
6373 // Åñëè âîçìîæíûõ öåëåé íåò:
6374 // (Àòàêà ÷åãî-íèáóäü ñëåâà èëè ñïðàâà)
6375 if targets
= nil then
6376 if GetAIFlag('ATTACKLEFT') <> '' then
6377 begin // Åñëè íóæíî àòàêîâàòü íàëåâî
6378 RemoveAIFlag('ATTACKLEFT');
6380 SetAIFlag('NEEDJUMP', '1');
6382 if RunDirection() = D_RIGHT
then
6383 begin // Èäåì íå â òó ñòîðîíó
6384 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
6385 begin // Åñëè çäîðîâû, òî, âîçìîæíî, ñòðåëÿåì áåæèì âëåâî è ñòðåëÿåì
6386 SetAIFlag('NEEDFIRE', '1');
6387 SetAIFlag('GOLEFT', '1');
6391 begin // Èäåì â íóæíóþ ñòîðîíó
6392 if GetRnd(FDifficult
.InvisFire
) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
6393 SetAIFlag('NEEDFIRE', '1');
6394 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
6395 SetAIFlag('GORIGHT', '1');
6399 if GetAIFlag('ATTACKRIGHT') <> '' then
6400 begin // Åñëè íóæíî àòàêîâàòü íàïðàâî
6401 RemoveAIFlag('ATTACKRIGHT');
6403 SetAIFlag('NEEDJUMP', '1');
6405 if RunDirection() = D_LEFT
then
6406 begin // Èäåì íå â òó ñòîðîíó
6407 if (Healthy() > 1) and GetRnd(FDifficult
.InvisFire
) then
6408 begin // Åñëè çäîðîâû, òî, âîçìîæíî, áåæèì âïðàâî è ñòðåëÿåì
6409 SetAIFlag('NEEDFIRE', '1');
6410 SetAIFlag('GORIGHT', '1');
6415 if GetRnd(FDifficult
.InvisFire
) then // Âîçìîæíî, ñòðåëÿåì âñëåïóþ
6416 SetAIFlag('NEEDFIRE', '1');
6417 if Healthy() <= 1 then // Ïîáèòû - óáåãàåì
6418 SetAIFlag('GOLEFT', '1');
6422 //HACK! (does it belongs there?)
6423 RealizeCurrentWeapon();
6425 // Åñëè åñòü âîçìîæíûå öåëè:
6426 // (Ñòðåëÿåì ïî íàïðàâëåíèþ ê öåëÿì)
6427 if (targets
<> nil) and (GetAIFlag('NEEDFIRE') <> '') then
6428 for a
:= 0 to High(targets
) do
6430 // Åñëè ìîæåì ñòðåëÿòü ïî äèàãîíàëè:
6431 if GetRnd(FDifficult
.DiagFire
) then
6433 // Èùåì öåëü ñâåðõó è ñòðåëÿåì, åñëè åñòü:
6434 if FDirection
= D_LEFT
then
6435 angle
:= ANGLE_LEFTUP
6437 angle
:= ANGLE_RIGHTUP
;
6439 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6440 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6442 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6443 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
6444 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6445 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
6446 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
6448 SetAIFlag('NEEDFIRE', '1');
6449 SetAIFlag('NEEDSEEUP', '1');
6452 // Èùåì öåëü ñíèçó è ñòðåëÿåì, åñëè åñòü:
6453 if FDirection
= D_LEFT
then
6454 angle
:= ANGLE_LEFTDOWN
6456 angle
:= ANGLE_RIGHTDOWN
;
6458 firew
:= Trunc(Cos(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6459 fireh
:= Trunc(Sin(DegToRad(-angle
))*gPlayerScreenSize
.X
*0.6);
6461 if g_CollideLine(x1
, y1
, x1
+firew
, y1
+fireh
,
6462 targets
[a
].X
+targets
[a
].Rect
.X
+GetInterval(FDifficult
.DiagPrecision
, 128),
6463 targets
[a
].Y
+targets
[a
].Rect
.Y
+GetInterval(FDifficult
.DiagPrecision
, 128),
6464 targets
[a
].Rect
.Width
, targets
[a
].Rect
.Height
) and
6465 g_TraceVector(x1
, y1
, targets
[a
].cX
, targets
[a
].cY
) then
6467 SetAIFlag('NEEDFIRE', '1');
6468 SetAIFlag('NEEDSEEDOWN', '1');
6472 // Åñëè öåëü "ïåðåä íîñîì", òî ñòðåëÿåì:
6473 if targets
[a
].Line
and targets
[a
].Visible
and
6474 (((FDirection
= D_LEFT
) and (targets
[a
].X
< FObj
.X
)) or
6475 ((FDirection
= D_RIGHT
) and (targets
[a
].X
> FObj
.X
))) then
6477 SetAIFlag('NEEDFIRE', '1');
6482 // Åñëè ëåòèò ïóëÿ, òî, âîçìîæíî, ïîäïðûãèâàåì:
6483 if g_Weapon_Danger(FUID
, FObj
.X
+PLAYER_RECT
.X
, FObj
.Y
+PLAYER_RECT
.Y
,
6484 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
,
6485 40+GetInterval(FDifficult
.Cover
, 40)) then
6486 SetAIFlag('NEEDJUMP', '1');
6488 // Åñëè êîí÷èëèñü ïàòîðíû, òî íóæíî ñìåíèòü îðóæèå:
6489 ammo
:= GetAmmoByWeapon(FCurrWeap
);
6490 if ((FCurrWeap
= WEAPON_SHOTGUN2
) and (ammo
< 2)) or
6491 ((FCurrWeap
= WEAPON_BFG
) and (ammo
< 40)) or
6493 SetAIFlag('SELECTWEAPON', '1');
6495 // Åñëè íóæíî ñìåíèòü îðóæèå, òî âûáèðàåì íóæíîå:
6496 if GetAIFlag('SELECTWEAPON') = '1' then
6499 RemoveAIFlag('SELECTWEAPON');
6503 procedure TBot
.Update();
6516 // Ïðîâåðÿåì, îòêëþ÷¸í ëè AI áîòîâ
6517 if (g_debug_BotAIOff
= 1) and (Team
= TEAM_RED
) then
6519 if (g_debug_BotAIOff
= 2) and (Team
= TEAM_BLUE
) then
6521 if g_debug_BotAIOff
= 3 then
6534 procedure TBot
.ReleaseKey(Key
: Byte);
6543 function TBot
.KeyPressed(Key
: Word): Boolean;
6545 Result
:= FKeys
[Key
].Pressed
;
6548 function TBot
.GetAIFlag(fName
: String20
): String20
;
6554 fName
:= LowerCase(fName
);
6556 if FAIFlags
<> nil then
6557 for a
:= 0 to High(FAIFlags
) do
6558 if LowerCase(FAIFlags
[a
].Name
) = fName
then
6560 Result
:= FAIFlags
[a
].Value
;
6565 procedure TBot
.RemoveAIFlag(fName
: String20
);
6569 if FAIFlags
= nil then Exit
;
6571 fName
:= LowerCase(fName
);
6573 for a
:= 0 to High(FAIFlags
) do
6574 if LowerCase(FAIFlags
[a
].Name
) = fName
then
6576 if a
<> High(FAIFlags
) then
6577 for b
:= a
to High(FAIFlags
)-1 do
6578 FAIFlags
[b
] := FAIFlags
[b
+1];
6580 SetLength(FAIFlags
, Length(FAIFlags
)-1);
6585 procedure TBot
.SetAIFlag(fName
, fValue
: String20
);
6593 fName
:= LowerCase(fName
);
6595 if FAIFlags
<> nil then
6596 for a
:= 0 to High(FAIFlags
) do
6597 if LowerCase(FAIFlags
[a
].Name
) = fName
then
6603 if ok
then FAIFlags
[a
].Value
:= fValue
6606 SetLength(FAIFlags
, Length(FAIFlags
)+1);
6607 with FAIFlags
[High(FAIFlags
)] do
6615 procedure TBot
.UpdateMove
;
6617 procedure GoLeft(Time
: Word = 1);
6619 ReleaseKey(KEY_LEFT
);
6620 ReleaseKey(KEY_RIGHT
);
6621 PressKey(KEY_LEFT
, Time
);
6622 SetDirection(D_LEFT
);
6625 procedure GoRight(Time
: Word = 1);
6627 ReleaseKey(KEY_LEFT
);
6628 ReleaseKey(KEY_RIGHT
);
6629 PressKey(KEY_RIGHT
, Time
);
6630 SetDirection(D_RIGHT
);
6633 function Rnd(a
: Word): Boolean;
6635 Result
:= Random(a
) = 0;
6638 procedure Turn(Time
: Word = 1200);
6640 if RunDirection() = D_LEFT
then GoRight(Time
) else GoLeft(Time
);
6645 ReleaseKey(KEY_LEFT
);
6646 ReleaseKey(KEY_RIGHT
);
6649 function CanRunLeft(): Boolean;
6651 Result
:= not CollideLevel(-1, 0);
6654 function CanRunRight(): Boolean;
6656 Result
:= not CollideLevel(1, 0);
6659 function CanRun(): Boolean;
6661 if RunDirection() = D_LEFT
then Result
:= CanRunLeft() else Result
:= CanRunRight();
6664 procedure Jump(Time
: Word = 30);
6666 PressKey(KEY_JUMP
, Time
);
6669 function NearHole(): Boolean;
6673 { TODO 5 : Ëåñòíèöû }
6674 sx
:= IfThen(RunDirection() = D_LEFT
, -1, 1);
6675 for x
:= 1 to PLAYER_RECT
.Width
do
6676 if (not StayOnStep(x
*sx
, 0)) and
6677 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
6678 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
6687 function BorderHole(): Boolean;
6691 { TODO 5 : Ëåñòíèöû }
6692 sx
:= IfThen(RunDirection() = D_LEFT
, -1, 1);
6693 for x
:= 1 to PLAYER_RECT
.Width
do
6694 if (not StayOnStep(x
*sx
, 0)) and
6695 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
6696 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
6698 for xx
:= x
to x
+32 do
6699 if CollideLevel(xx
*sx
, PLAYER_RECT
.Height
) then
6709 function NearDeepHole(): Boolean;
6715 sx
:= IfThen(RunDirection() = D_LEFT
, -1, 1);
6718 for x
:= 1 to PLAYER_RECT
.Width
do
6719 if (not StayOnStep(x
*sx
, 0)) and
6720 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
)) and
6721 (not CollideLevel(x
*sx
, PLAYER_RECT
.Height
*2)) then
6723 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
6725 if CollideLevel(x
*sx
, PLAYER_RECT
.Height
*y
) then Exit
;
6730 end else Result
:= False;
6733 function OverDeepHole(): Boolean;
6740 while FObj
.Y
+y
*PLAYER_RECT
.Height
< gMapInfo
.Height
do
6742 if CollideLevel(0, PLAYER_RECT
.Height
*y
) then Exit
;
6749 function OnGround(): Boolean;
6751 Result
:= StayOnStep(0, 0) or CollideLevel(0, 1);
6754 function OnLadder(): Boolean;
6756 Result
:= FullInStep(0, 0);
6759 function BelowLadder(): Boolean;
6761 Result
:= (FullInStep(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) and
6762 not CollideLevel(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
6763 (FullInStep(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) and
6764 not CollideLevel(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
6767 function BelowLiftUp(): Boolean;
6769 Result
:= ((FullInLift(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
) = -1) and
6770 not CollideLevel(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -PLAYER_RECT
.Height
)) or
6771 ((FullInLift(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
) = -1) and
6772 not CollideLevel(IfThen(RunDirection() = D_LEFT
, -1, 1)*(PLAYER_RECT
.Width
div 2), -BOT_MAXJUMP
));
6775 function OnTopLift(): Boolean;
6777 Result
:= (FullInLift(0, 0) = -1) and (FullInLift(0, -32) = 0);
6780 function CanJumpOver(): Boolean;
6784 sx
:= IfThen(RunDirection() = D_LEFT
, -1, 1);
6788 if not CollideLevel(sx
, 0) then Exit
;
6790 for y
:= 1 to BOT_MAXJUMP
do
6791 if CollideLevel(0, -y
) then Exit
else
6792 if not CollideLevel(sx
, -y
) then
6799 function CanJumpUp(Dist
: ShortInt): Boolean;
6806 if CollideLevel(Dist
, 0) then Exit
;
6809 for y
:= 0 to BOT_MAXJUMP
do
6810 if CollideLevel(Dist
, -y
) then
6819 for yy
:= y
+1 to BOT_MAXJUMP
do
6820 if not CollideLevel(Dist
, -yy
) then
6829 for y
:= 0 to BOT_MAXJUMP
do
6830 if CollideLevel(0, -y
) then
6838 if y
< yy
then Exit
;
6843 function IsSafeTrigger(): Boolean;
6848 if gTriggers
= nil then
6850 for a
:= 0 to High(gTriggers
) do
6851 if Collide(gTriggers
[a
].X
,
6854 gTriggers
[a
].Height
) and
6855 (gTriggers
[a
].TriggerType
in [TRIGGER_EXIT
, TRIGGER_CLOSEDOOR
,
6856 TRIGGER_CLOSETRAP
, TRIGGER_TRAP
,
6857 TRIGGER_PRESS
, TRIGGER_ON
, TRIGGER_OFF
,
6858 TRIGGER_ONOFF
, TRIGGER_SPAWNMONSTER
,
6859 TRIGGER_DAMAGE
, TRIGGER_SHOT
]) then
6864 // Âîçìîæíî, íàæèìàåì êíîïêó:
6865 if Rnd(16) and IsSafeTrigger() then
6868 // Åñëè ïîä ëèôòîì èëè ñòóïåíüêàìè, òî, âîçìîæíî, ïðûãàåì:
6869 if OnLadder() or ((BelowLadder() or BelowLiftUp()) and Rnd(8)) then
6871 ReleaseKey(KEY_LEFT
);
6872 ReleaseKey(KEY_RIGHT
);
6876 // Èäåì âëåâî, åñëè íàäî áûëî:
6877 if GetAIFlag('GOLEFT') <> '' then
6879 RemoveAIFlag('GOLEFT');
6880 if CanRunLeft() then
6884 // Èäåì âïðàâî, åñëè íàäî áûëî:
6885 if GetAIFlag('GORIGHT') <> '' then
6887 RemoveAIFlag('GORIGHT');
6888 if CanRunRight() then
6892 // Åñëè âûëåòåëè çà êàðòó, òî ïðîáóåì âåðíóòüñÿ:
6893 if FObj
.X
< -32 then
6896 if FObj
.X
+32 > gMapInfo
.Width
then
6899 // Ïðûãàåì, åñëè íàäî áûëî:
6900 if GetAIFlag('NEEDJUMP') <> '' then
6903 RemoveAIFlag('NEEDJUMP');
6906 // Ñìîòðèì ââåðõ, åñëè íàäî áûëî:
6907 if GetAIFlag('NEEDSEEUP') <> '' then
6910 ReleaseKey(KEY_DOWN
);
6911 PressKey(KEY_UP
, 20);
6912 RemoveAIFlag('NEEDSEEUP');
6915 // Ñìîòðèì âíèç, åñëè íàäî áûëî:
6916 if GetAIFlag('NEEDSEEDOWN') <> '' then
6919 ReleaseKey(KEY_DOWN
);
6920 PressKey(KEY_DOWN
, 20);
6921 RemoveAIFlag('NEEDSEEDOWN');
6924 // Åñëè íóæíî áûëî â äûðó è ìû íå íà çåìëå, òî ïîêîðíî ëåòèì:
6925 if GetAIFlag('GOINHOLE') <> '' then
6926 if not OnGround() then
6928 ReleaseKey(KEY_LEFT
);
6929 ReleaseKey(KEY_RIGHT
);
6930 RemoveAIFlag('GOINHOLE');
6931 SetAIFlag('FALLINHOLE', '1');
6934 // Åñëè ïàäàëè è äîñòèãëè çåìëè, òî õâàòèò ïàäàòü:
6935 if GetAIFlag('FALLINHOLE') <> '' then
6937 RemoveAIFlag('FALLINHOLE');
6939 // Åñëè ëåòåëè ïðÿìî è ñåé÷àñ íå íà ëåñòíèöå èëè íà âåðøèíå ëèôòà, òî îòõîäèì â ñòîðîíó:
6940 if not (KeyPressed(KEY_LEFT
) or KeyPressed(KEY_RIGHT
)) then
6941 if GetAIFlag('FALLINHOLE') = '' then
6942 if (not OnLadder()) or (FObj
.Vel
.Y
>= 0) or (OnTopLift()) then
6948 // Åñëè íà çåìëå è ìîæíî ïîäïðûãíóòü, òî, âîçìîæíî, ïðûãàåì:
6950 CanJumpUp(IfThen(RunDirection() = D_LEFT
, -1, 1)*32) and
6954 // Åñëè íà çåìëå è âîçëå äûðû (ãëóáèíà > 2 ðîñòîâ èãðîêà):
6955 if OnGround() and NearHole() then
6956 if NearDeepHole() then // Åñëè ýòî áåçäíà
6958 0..3: Turn(); // Áåæèì îáðàòíî
6959 4: Jump(); // Ïðûãàåì
6960 5: begin // Ïðûãàåì îáðàòíî
6965 else // Ýòî íå áåçäíà è ìû åùå íå ëåòèì òóäà
6966 if GetAIFlag('GOINHOLE') = '' then
6968 0: Turn(); // Íå íóæíî òóäà
6969 1: Jump(); // Âäðóã ïîâåçåò - ïðûãàåì
6970 else // Åñëè ÿìà ñ ãðàíèöåé, òî ïðè ñëó÷àå ìîæíî òóäà ïðûãíóòü
6971 if BorderHole() then
6972 SetAIFlag('GOINHOLE', '1');
6975 // Åñëè íà çåìëå, íî íåêóäà èäòè:
6976 if (not CanRun()) and OnGround() then
6978 // Åñëè ìû íà ëåñòíèöå èëè ìîæíî ïåðåïðûãíóòü, òî ïðûãàåì:
6979 if CanJumpOver() or OnLadder() then
6981 else // èíà÷å ïîïûòàåìñÿ â äðóãóþ ñòîðîíó
6982 if Random(2) = 0 then
6984 if IsSafeTrigger() then
6990 // Îñòàëîñü ìàëî âîçäóõà:
6991 if FAir
< 36 * 2 then
6994 // Âûáèðàåìñÿ èç êèñëîòû, åñëè íåò êîñòþìà, îáîæãëèñü, èëè ìàëî çäîðîâüÿ:
6995 if (FMegaRulez
[MR_SUIT
] < gTime
) and ((FLastHit
= HIT_ACID
) or (Healthy() <= 1)) then
6996 if BodyInAcid(0, 0) then
7000 function TBot
.FullInStep(XInc
, YInc
: Integer): Boolean;
7002 Result
:= g_Map_CollidePanel(FObj
.X
+PLAYER_RECT
.X
+XInc
, FObj
.Y
+PLAYER_RECT
.Y
+YInc
,
7003 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
, PANEL_STEP
, False);
7006 {function TBot.NeedItem(Item: Byte): Byte;
7011 procedure TBot
.SelectWeapon(Dist
: Integer);
7015 function HaveAmmo(weapon
: Byte): Boolean;
7018 WEAPON_PISTOL
: Result
:= FAmmo
[A_BULLETS
] >= 1;
7019 WEAPON_SHOTGUN1
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7020 WEAPON_SHOTGUN2
: Result
:= FAmmo
[A_SHELLS
] >= 2;
7021 WEAPON_CHAINGUN
: Result
:= FAmmo
[A_BULLETS
] >= 10;
7022 WEAPON_ROCKETLAUNCHER
: Result
:= FAmmo
[A_ROCKETS
] >= 1;
7023 WEAPON_PLASMA
: Result
:= FAmmo
[A_CELLS
] >= 10;
7024 WEAPON_BFG
: Result
:= FAmmo
[A_CELLS
] >= 40;
7025 WEAPON_SUPERPULEMET
: Result
:= FAmmo
[A_SHELLS
] >= 1;
7026 else Result
:= True;
7031 if Dist
= -1 then Dist
:= BOT_LONGDIST
;
7033 if Dist
> BOT_LONGDIST
then
7034 begin // Äàëüíèé áîé
7036 if FWeapon
[FDifficult
.WeaponPrior
[a
]] and HaveAmmo(FDifficult
.WeaponPrior
[a
]) then
7038 FSelectedWeapon
:= FDifficult
.WeaponPrior
[a
];
7042 else //if Dist > BOT_UNSAFEDIST then
7043 begin // Áëèæíèé áîé
7045 if FWeapon
[FDifficult
.CloseWeaponPrior
[a
]] and HaveAmmo(FDifficult
.CloseWeaponPrior
[a
]) then
7047 FSelectedWeapon
:= FDifficult
.CloseWeaponPrior
[a
];
7054 if FWeapon[FDifficult.SafeWeaponPrior[a]] and HaveAmmo(FDifficult.SafeWeaponPrior[a]) then
7056 FSelectedWeapon := FDifficult.SafeWeaponPrior[a];
7062 function TBot
.PickItem(ItemType
: Byte; force
: Boolean; var remove
: Boolean): Boolean;
7064 Result
:= inherited PickItem(ItemType
, force
, remove
);
7066 if Result
then SetAIFlag('SELECTWEAPON', '1');
7069 function TBot
.Heal(value
: Word; Soft
: Boolean): Boolean;
7071 Result
:= inherited Heal(value
, Soft
);
7074 function TBot
.Healthy(): Byte;
7076 if FMegaRulez
[MR_INVUL
] >= gTime
then Result
:= 3
7077 else if (FHealth
> 80) or ((FHealth
> 50) and (FArmor
> 20)) then Result
:= 3
7078 else if (FHealth
> 50) then Result
:= 2
7079 else if (FHealth
> 20) then Result
:= 1
7083 function TBot
.TargetOnScreen(TX
, TY
: Integer): Boolean;
7085 Result
:= (Abs(FObj
.X
-TX
) <= Trunc(gPlayerScreenSize
.X
*0.6)) and
7086 (Abs(FObj
.Y
-TY
) <= Trunc(gPlayerScreenSize
.Y
*0.6));
7089 procedure TBot
.OnDamage(Angle
: SmallInt);
7097 if (Angle
= 0) or (Angle
= 180) then
7100 if (g_GetUIDType(FLastSpawnerUID
) = UID_PLAYER
) and
7101 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSPLAYER
) then
7103 pla
:= g_Player_Get(FLastSpawnerUID
);
7104 ok
:= not TargetOnScreen(pla
.FObj
.X
+ PLAYER_RECT
.X
,
7105 pla
.FObj
.Y
+ PLAYER_RECT
.Y
);
7108 if (g_GetUIDType(FLastSpawnerUID
) = UID_MONSTER
) and
7109 LongBool(gGameSettings
.Options
and GAME_OPTION_BOTVSMONSTER
) then
7111 mon
:= g_Monsters_Get(FLastSpawnerUID
);
7112 ok
:= not TargetOnScreen(mon
.Obj
.X
+ mon
.Obj
.Rect
.X
,
7113 mon
.Obj
.Y
+ mon
.Obj
.Rect
.Y
);
7118 SetAIFlag('ATTACKLEFT', '1')
7120 SetAIFlag('ATTACKRIGHT', '1');
7124 function TBot
.RunDirection(): TDirection
;
7126 if Abs(Vel
.X
) >= 1 then
7128 if Vel
.X
> 0 then Result
:= D_RIGHT
else Result
:= D_LEFT
;
7130 Result
:= FDirection
;
7133 function TBot
.GetRnd(a
: Byte): Boolean;
7135 if a
= 0 then Result
:= False
7136 else if a
= 255 then Result
:= True
7137 else Result
:= Random(256) > 255-a
;
7140 function TBot
.GetInterval(a
: Byte; radius
: SmallInt): SmallInt;
7142 Result
:= Round((255-a
)/255*radius
*(Random(2)-1));
7145 procedure TBot
.SaveState(var Mem
: TBinMemoryWriter
);
7151 inherited SaveState(Mem
);
7153 // Âûáðàííîå îðóæèå:
7154 Mem
.WriteByte(FSelectedWeapon
);
7156 Mem
.WriteWord(FTargetUID
);
7157 // Âðåìÿ ïîòåðè öåëè:
7158 Mem
.WriteDWORD(FLastVisible
);
7159 // Êîëè÷åñòâî ôëàãîâ ÈÈ:
7160 dw
:= Length(FAIFlags
);
7163 for i
:= 0 to Integer(dw
)-1 do
7165 Mem
.WriteString(FAIFlags
[i
].Name
, 20);
7166 Mem
.WriteString(FAIFlags
[i
].Value
, 20);
7168 // Íàñòðîéêè ñëîæíîñòè:
7170 Mem
.WriteMemory(p
, SizeOf(TDifficult
));
7173 procedure TBot
.LoadState(var Mem
: TBinMemoryReader
);
7179 inherited LoadState(Mem
);
7181 // Âûáðàííîå îðóæèå:
7182 Mem
.ReadByte(FSelectedWeapon
);
7184 Mem
.ReadWord(FTargetUID
);
7185 // Âðåìÿ ïîòåðè öåëè:
7186 Mem
.ReadDWORD(FLastVisible
);
7187 // Êîëè÷åñòâî ôëàãîâ ÈÈ:
7189 SetLength(FAIFlags
, dw
);
7191 for i
:= 0 to Integer(dw
)-1 do
7193 Mem
.ReadString(FAIFlags
[i
].Name
);
7194 Mem
.ReadString(FAIFlags
[i
].Value
);
7196 // Íàñòðîéêè ñëîæíîñòè:
7197 Mem
.ReadMemory(p
, dw
);
7198 if dw
<> SizeOf(TDifficult
) then
7200 raise EBinSizeError
.Create('TBot.LoadState: Wrong FDifficult Size');
7202 FDifficult
:= TDifficult(p
^);